Skip to content

feat: brain-expand pipeline scripts + hardening (closes #18)#23

Merged
0xNyk merged 2 commits into
mainfrom
fix/brain-expand-pipeline-hardened
Mar 22, 2026
Merged

feat: brain-expand pipeline scripts + hardening (closes #18)#23
0xNyk merged 2 commits into
mainfrom
fix/brain-expand-pipeline-hardened

Conversation

@0xNyk

@0xNyk 0xNyk commented Mar 22, 2026

Copy link
Copy Markdown
Owner

Summary

Implements the 5 missing automation scripts that brain-expand calls, based on @w3t-wr3's community contribution in #21 with security hardening and test coverage.

Scripts added

  • run_session_sync.sh — pulls recent Claude/Codex session artifacts into inbox
  • detect_knowledge_gaps.py — scans knowledge graph for orphans, broken links, stale notes
  • generate_review_queue.py — builds prioritized review queue from unrouted inbox items
  • route_inbox.py — sorts inbox notes into knowledge graph subdirectories
  • archive_inbox.py — archives notes older than N days

Hardening applied (audit of #21)

  • High: Fixed run_session_sync.sh missing set -e — errors now halt execution
  • High: Fixed JSON stdout contract — was plaintext, now proper JSON for brain-expand
  • Medium: Added path traversal guard — filenames with .. are skipped before shutil.move
  • Low: Extracted duplicated parse_frontmatter() to shared scripts/brain_utils.py
  • Low: Replaced deprecated datetime.utcnow() with datetime.now(timezone.utc)

Tests

  • Added scripts/ci/test-brain-automation-scripts.sh20 tests exercising all 5 scripts directly with real temp directories (session sync, gap detection, review queue, routing dry-run + apply, archiving dry-run + apply, path traversal guard)

Closes #18. Based on #21 by @w3t-wr3 — thank you for the contribution.

Test plan

  • bash scripts/ci/test-brain-automation-scripts.sh — 20/20 passing
  • All Python scripts import cleanly
  • Shell script passes bash -n syntax check

🤖 Generated with Claude Code

w3t-wr3 and others added 2 commits March 22, 2026 12:21
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.
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 0xNyk merged commit d6db0b5 into main Mar 22, 2026
@0xNyk 0xNyk deleted the fix/brain-expand-pipeline-hardened branch March 22, 2026 05:56
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.

Missing Automation Scripts Issue

2 participants