Skip to content

feat: cross-mission memory store and pattern library#94

Merged
harrymunro merged 4 commits intomainfrom
feat/cross-mission-memory
Apr 10, 2026
Merged

feat: cross-mission memory store and pattern library#94
harrymunro merged 4 commits intomainfrom
feat/cross-mission-memory

Conversation

@harrymunro
Copy link
Copy Markdown
Collaborator

Summary

Implements #83 — adds a persistent, structured knowledge base that accumulates learnings across Nelson missions.

  • Memory store (.nelson/memory/): patterns.json accumulates adopt/avoid patterns from every mission; standing-order-stats.json tracks violation frequency and correlations
  • Pattern capture: stand-down now accepts --adopt and --avoid repeatable flags and auto-updates the memory store
  • Intelligence brief (nelson-data.py brief): Pre-mission command that surfaces relevant patterns, win rate, standing order hot spots, and context-matched precedents from past missions
  • Cross-mission analytics (nelson-data.py analytics --metric success-rate|standing-orders|efficiency|all): Focused metric queries with text and JSON output
  • Bug fix: Removed duplicate record-building code in cmd_index() that ran outside the file lock
  • Index sync: Running index now backfills the memory store for missions completed before the feature existed

Test plan

  • All 66 existing tests pass (no regressions)
  • 21 new tests added across 6 test classes (87 total)
  • TestStandDownPatterns--adopt/--avoid args and defaults
  • TestMemoryStore — patterns.json creation, accumulation, stats update, non-fatal failure on read-only dir, violation capture
  • TestBrief — empty state, with missions, JSON output, context matching
  • TestAnalyticsCommand — each metric, all metrics, JSON output, --last flag, missing index error
  • TestIndexMemorySync — backfill from index, incremental sync

Closes #83

Add persistent knowledge base that accumulates learnings across missions.
Surfaces relevant patterns via intelligence brief before new missions.

- Add .nelson/memory/ store with patterns.json and standing-order-stats.json
- Add --adopt/--avoid args to stand-down for capturing reusable patterns
- Add `brief` command for pre-mission intelligence briefs with context matching
- Add `analytics` command with success-rate, standing-orders, efficiency metrics
- Auto-extract patterns and violation stats at stand-down
- Backfill memory store when running `index`
- Fix duplicate code bug in cmd_index() (lines ran outside lock)
- Add 21 new tests (87 total, all passing)
- Update structured-data.md with new schemas and command docs
nelson-data.py (2557 lines) and test_nelson_data.py (1759 lines)
exceeded the 800-line guideline. Split into 5 source modules and
3 test files while preserving backward compatibility:

- nelson-data.py: thin CLI entry point (287 lines)
- nelson_data_utils.py: shared I/O, validation, constants (261 lines)
- nelson_data_memory.py: cross-mission memory store (491 lines)
- nelson_data_lifecycle.py: mission lifecycle commands (825 lines)
- nelson_data_fleet.py: fleet intelligence + analytics (806 lines)
- conftest.py: shared test helpers (171 lines)
- test_nelson_data.py: lifecycle tests (620 lines)
- test_nelson_data_fleet.py: fleet/analytics/brief tests (719 lines)
- test_nelson_data_memory.py: memory store + I/O tests (303 lines)

CI updated to discover all test files via pytest directory discovery.
Replace bare open()+try/finally lock pattern with a _file_lock()
context manager across all 6 lock sites. Fix mid-file import and
replace time.sleep with deterministic mission IDs in tests.
Integrate six PRs merged to main since this branch diverged:
- PR #89: formation consolidation (form, headless commands)
- PR #90: path-scoped auto-discovery
- PR #91: typed handoff packet
- PR #92: hook enforcement layer
- PR #93: deterministic phase engine
- PR #96: task list visibility

Port new commands (form, headless, handoff, recover) into the
modular architecture. Add phase field support to lifecycle commands
for compatibility with the phase engine. All 234 tests pass.
@harrymunro harrymunro merged commit f3d18ec into main Apr 10, 2026
5 of 6 checks passed
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.

Cross-mission memory store and pattern library

1 participant