Skip to content

implement missing brain-expand pipeline scripts#21

Closed
w3t-wr3 wants to merge 1 commit into
0xNyk:mainfrom
w3t-wr3:fix/brain-expand-pipeline-scripts
Closed

implement missing brain-expand pipeline scripts#21
w3t-wr3 wants to merge 1 commit into
0xNyk:mainfrom
w3t-wr3:fix/brain-expand-pipeline-scripts

Conversation

@w3t-wr3

@w3t-wr3 w3t-wr3 commented Mar 20, 2026

Copy link
Copy Markdown
Contributor

Hey Nyk; this implements the five scripts that brain-expand calls but were missing (re: #18).

What's included:

  • run_session_sync.sh pulls recent Claude/Codex session artifacts into the inbox as timestamped notes with proper frontmatter. Tracks what's been processed so it doesn't duplicate on reruns.
  • detect_knowledge_gaps.py scans the knowledge graph for orphans (no inbound links), broken wikilinks (referenced but no file exists), and stale notes (30+ days untouched). Writes gaps.json to the expected path.
  • generate_review_queue.py builds a prioritized queue from unrouted inbox items older than 24 hours, ranked by age and connection density. Writes the review-queue.md that session_orient reads.
  • route_inbox.py sorts inbox notes into knowledge graph subdirectories based on frontmatter type and tags. Supports --apply for the real move vs dry run.
  • archive_inbox.py moves notes older than N days to archive/inbox. Supports --apply and --days flags.

All five scripts conform to the JSON stdout contract that lacp-brain-expand expects and pass the existing test suite (test-brain-expand.sh all green).

I've been running a similar pipeline in my own Obsidian + Claude Code setup for a while now; these scripts are adapted from patterns I've battle tested. Happy to iterate on anything.

adds the five scripts that brain-expand references but were previously
stubs or missing entirely (issue 0xNyk#18):

- run_session_sync.sh: extracts recent Claude/Codex session artifacts
  into the inbox as timestamped notes with frontmatter
- detect_knowledge_gaps.py: scans the knowledge graph for orphan notes,
  broken wikilinks, and stale content; writes gaps.json
- generate_review_queue.py: builds a prioritized review queue from
  unrouted inbox items older than 24 hours
- route_inbox.py: sorts inbox notes into knowledge graph subdirectories
  based on frontmatter type and tags (supports --apply for dry run)
- archive_inbox.py: moves notes older than 30 days to archive/inbox
  (supports --apply and --days flags)

all scripts conform to the JSON stdout contract expected by
lacp-brain-expand and pass the existing test suite.
0xNyk added a commit that referenced this pull request Mar 22, 2026
Audit fixes for community PR #21:
- run_session_sync.sh: add set -e, fix JSON stdout contract
- Extract shared parse_frontmatter() to brain_utils.py (was duplicated 3x)
- Replace deprecated datetime.utcnow() with timezone-aware alternative
- Add path traversal guard (skip filenames containing ..)
- Add scripts/ci/test-brain-automation-scripts.sh (20 tests, exercises
  all 5 scripts directly with real temp dirs)
0xNyk added a commit that referenced this pull request Mar 22, 2026
* implement missing brain-expand pipeline scripts

adds the five scripts that brain-expand references but were previously
stubs or missing entirely (issue #18):

- run_session_sync.sh: extracts recent Claude/Codex session artifacts
  into the inbox as timestamped notes with frontmatter
- detect_knowledge_gaps.py: scans the knowledge graph for orphan notes,
  broken wikilinks, and stale content; writes gaps.json
- generate_review_queue.py: builds a prioritized review queue from
  unrouted inbox items older than 24 hours
- route_inbox.py: sorts inbox notes into knowledge graph subdirectories
  based on frontmatter type and tags (supports --apply for dry run)
- archive_inbox.py: moves notes older than 30 days to archive/inbox
  (supports --apply and --days flags)

all scripts conform to the JSON stdout contract expected by
lacp-brain-expand and pass the existing test suite.

* fix: harden brain-expand pipeline scripts + add direct tests

Audit fixes for community PR #21:
- run_session_sync.sh: add set -e, fix JSON stdout contract
- Extract shared parse_frontmatter() to brain_utils.py (was duplicated 3x)
- Replace deprecated datetime.utcnow() with timezone-aware alternative
- Add path traversal guard (skip filenames containing ..)
- Add scripts/ci/test-brain-automation-scripts.sh (20 tests, exercises
  all 5 scripts directly with real temp dirs)

---------

Co-authored-by: MyrmtolioDebroudon <84546963+MyrmtolioDebroudon@users.noreply.github.com>
@0xNyk

0xNyk commented Mar 22, 2026

Copy link
Copy Markdown
Owner

Thanks for the contribution @w3t-wr3 — great work implementing all 5 scripts. I've merged a hardened version in #23 that builds on your work with a few fixes:

  • Added set -e to run_session_sync.sh and fixed the JSON stdout contract
  • Extracted the duplicated parse_frontmatter() into a shared brain_utils.py
  • Added path traversal guards on shutil.move calls
  • Replaced deprecated datetime.utcnow() with timezone-aware alternative
  • Added 20 direct tests in test-brain-automation-scripts.sh

Closing this in favor of #23. Thanks again for the solid foundation!

@0xNyk 0xNyk closed this Mar 22, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants