bmad-plus 0.12.1 → 0.12.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (156) hide show
  1. package/CHANGELOG.md +612 -580
  2. package/README.md +90 -115
  3. package/osint-agent-package/agents/osint-investigator.md +12 -0
  4. package/osint-agent-package/skills/bmad-osint-investigate/osint/SKILL.md +491 -482
  5. package/osint-agent-package/skills/bmad-osint-investigate/osint/assets/dossier-template.md +126 -126
  6. package/osint-agent-package/skills/bmad-osint-investigate/osint/assets/lawful-basis-record.md +48 -48
  7. package/osint-agent-package/skills/bmad-osint-investigate/osint/references/content-extraction.md +100 -100
  8. package/osint-agent-package/skills/bmad-osint-investigate/osint/references/gdpr-osint.md +48 -48
  9. package/osint-agent-package/skills/bmad-osint-investigate/osint/references/platforms.md +130 -130
  10. package/osint-agent-package/skills/bmad-osint-investigate/osint/references/psychoprofile.md +69 -69
  11. package/osint-agent-package/skills/bmad-osint-investigate/osint/references/tools.md +281 -281
  12. package/osint-agent-package/skills/bmad-osint-investigate/osint/scripts/mcp-client.py +136 -136
  13. package/package.json +104 -91
  14. package/readme-international/README.de.md +596 -594
  15. package/readme-international/README.es.md +613 -611
  16. package/readme-international/README.fr.md +611 -609
  17. package/src/bmad-plus/agents/agent-shadow/SKILL.md +18 -0
  18. package/src/bmad-plus/data/role-triggers.yaml +52 -0
  19. package/src/bmad-plus/module.yaml +283 -283
  20. package/src/bmad-plus/packs/pack-animated/animated-website-agent.md +325 -325
  21. package/src/bmad-plus/packs/pack-animated/templates/animated-website-workflow.md +55 -55
  22. package/src/bmad-plus/packs/pack-backup/backup-agent.md +71 -71
  23. package/src/bmad-plus/packs/pack-backup/templates/backup-workflow.md +51 -51
  24. package/src/bmad-plus/packs/pack-dev-studio/README.md +162 -162
  25. package/src/bmad-plus/packs/pack-dev-studio/categories/analysis/analyst-agent.md +73 -73
  26. package/src/bmad-plus/packs/pack-dev-studio/categories/analysis/document-project.md +61 -61
  27. package/src/bmad-plus/packs/pack-dev-studio/categories/analysis/domain-research.md +95 -95
  28. package/src/bmad-plus/packs/pack-dev-studio/categories/analysis/market-research.md +95 -95
  29. package/src/bmad-plus/packs/pack-dev-studio/categories/analysis/prfaq.md +134 -134
  30. package/src/bmad-plus/packs/pack-dev-studio/categories/analysis/product-brief.md +80 -80
  31. package/src/bmad-plus/packs/pack-dev-studio/categories/analysis/tech-writer-agent.md +73 -73
  32. package/src/bmad-plus/packs/pack-dev-studio/categories/analysis/technical-research.md +95 -95
  33. package/src/bmad-plus/packs/pack-dev-studio/categories/architecture/architect-agent.md +73 -73
  34. package/src/bmad-plus/packs/pack-dev-studio/categories/architecture/create-architecture.md +73 -73
  35. package/src/bmad-plus/packs/pack-dev-studio/categories/architecture/create-epics-stories.md +92 -92
  36. package/src/bmad-plus/packs/pack-dev-studio/categories/architecture/generate-project-context.md +80 -80
  37. package/src/bmad-plus/packs/pack-dev-studio/categories/architecture/implementation-readiness.md +90 -90
  38. package/src/bmad-plus/packs/pack-dev-studio/categories/architecture/steps/step-01-init.md +153 -153
  39. package/src/bmad-plus/packs/pack-dev-studio/categories/architecture/steps/step-01b-continue.md +173 -173
  40. package/src/bmad-plus/packs/pack-dev-studio/categories/architecture/steps/step-02-context.md +224 -224
  41. package/src/bmad-plus/packs/pack-dev-studio/categories/architecture/steps/step-03-starter.md +329 -329
  42. package/src/bmad-plus/packs/pack-dev-studio/categories/architecture/steps/step-04-decisions.md +318 -318
  43. package/src/bmad-plus/packs/pack-dev-studio/categories/architecture/steps/step-05-patterns.md +359 -359
  44. package/src/bmad-plus/packs/pack-dev-studio/categories/architecture/steps/step-06-structure.md +379 -379
  45. package/src/bmad-plus/packs/pack-dev-studio/categories/architecture/steps/step-07-validation.md +361 -361
  46. package/src/bmad-plus/packs/pack-dev-studio/categories/architecture/steps/step-08-complete.md +81 -81
  47. package/src/bmad-plus/packs/pack-dev-studio/categories/implementation/checkpoint-preview.md +67 -67
  48. package/src/bmad-plus/packs/pack-dev-studio/categories/implementation/code-review-steps/step-01-gather-context.md +85 -85
  49. package/src/bmad-plus/packs/pack-dev-studio/categories/implementation/code-review-steps/step-02-review.md +35 -35
  50. package/src/bmad-plus/packs/pack-dev-studio/categories/implementation/code-review-steps/step-03-triage.md +49 -49
  51. package/src/bmad-plus/packs/pack-dev-studio/categories/implementation/code-review-steps/step-04-present.md +131 -131
  52. package/src/bmad-plus/packs/pack-dev-studio/categories/implementation/code-review.md +89 -89
  53. package/src/bmad-plus/packs/pack-dev-studio/categories/implementation/correct-course.md +300 -300
  54. package/src/bmad-plus/packs/pack-dev-studio/categories/implementation/create-story.md +428 -428
  55. package/src/bmad-plus/packs/pack-dev-studio/categories/implementation/dev-agent.md +73 -73
  56. package/src/bmad-plus/packs/pack-dev-studio/categories/implementation/dev-story-checklist.md +80 -80
  57. package/src/bmad-plus/packs/pack-dev-studio/categories/implementation/dev-story.md +484 -484
  58. package/src/bmad-plus/packs/pack-dev-studio/categories/implementation/investigate.md +193 -193
  59. package/src/bmad-plus/packs/pack-dev-studio/categories/implementation/qa-e2e-tests.md +175 -175
  60. package/src/bmad-plus/packs/pack-dev-studio/categories/implementation/quick-dev.md +110 -110
  61. package/src/bmad-plus/packs/pack-dev-studio/categories/implementation/retrospective.md +1511 -1511
  62. package/src/bmad-plus/packs/pack-dev-studio/categories/implementation/sprint-planning.md +298 -298
  63. package/src/bmad-plus/packs/pack-dev-studio/categories/implementation/sprint-status.md +296 -296
  64. package/src/bmad-plus/packs/pack-dev-studio/categories/planning/create-prd.md +29 -29
  65. package/src/bmad-plus/packs/pack-dev-studio/categories/planning/create-ux-design.md +74 -74
  66. package/src/bmad-plus/packs/pack-dev-studio/categories/planning/edit-prd.md +29 -29
  67. package/src/bmad-plus/packs/pack-dev-studio/categories/planning/pm-agent.md +73 -73
  68. package/src/bmad-plus/packs/pack-dev-studio/categories/planning/prd.md +89 -89
  69. package/src/bmad-plus/packs/pack-dev-studio/categories/planning/ux-designer-agent.md +73 -73
  70. package/src/bmad-plus/packs/pack-dev-studio/categories/planning/validate-prd.md +29 -29
  71. package/src/bmad-plus/packs/pack-dev-studio/categories/utilities/advanced-elicitation.md +141 -141
  72. package/src/bmad-plus/packs/pack-dev-studio/categories/utilities/adversarial-review.md +37 -37
  73. package/src/bmad-plus/packs/pack-dev-studio/categories/utilities/bmad-help.md +75 -75
  74. package/src/bmad-plus/packs/pack-dev-studio/categories/utilities/brainstorming.md +6 -6
  75. package/src/bmad-plus/packs/pack-dev-studio/categories/utilities/customize.md +110 -110
  76. package/src/bmad-plus/packs/pack-dev-studio/categories/utilities/distillator.md +176 -176
  77. package/src/bmad-plus/packs/pack-dev-studio/categories/utilities/edge-case-hunter.md +67 -67
  78. package/src/bmad-plus/packs/pack-dev-studio/categories/utilities/editorial-review-prose.md +86 -86
  79. package/src/bmad-plus/packs/pack-dev-studio/categories/utilities/editorial-review-structure.md +179 -179
  80. package/src/bmad-plus/packs/pack-dev-studio/categories/utilities/index-docs.md +66 -66
  81. package/src/bmad-plus/packs/pack-dev-studio/categories/utilities/party-mode.md +127 -127
  82. package/src/bmad-plus/packs/pack-dev-studio/categories/utilities/shard-doc.md +105 -105
  83. package/src/bmad-plus/packs/pack-dev-studio/dev-studio-orchestrator.md +120 -120
  84. package/src/bmad-plus/packs/pack-dev-studio/shared/architecture-decision-template.md +12 -12
  85. package/src/bmad-plus/packs/pack-dev-studio/shared/bwml-spec.md +328 -328
  86. package/src/bmad-plus/packs/pack-dev-studio/shared/module-help.csv +32 -32
  87. package/src/bmad-plus/packs/pack-dev-studio/upstream-sync.yaml +81 -81
  88. package/src/bmad-plus/packs/pack-seo/SKILL.md +171 -171
  89. package/src/bmad-plus/packs/pack-seo/checklist.md +140 -140
  90. package/src/bmad-plus/packs/pack-seo/pagespeed-playbook.md +320 -320
  91. package/src/bmad-plus/packs/pack-seo/ref/audit-schema.json +187 -187
  92. package/src/bmad-plus/packs/pack-seo/ref/cwv-thresholds.md +87 -87
  93. package/src/bmad-plus/packs/pack-seo/ref/eeat-criteria.md +123 -123
  94. package/src/bmad-plus/packs/pack-seo/ref/geo-signals.md +167 -167
  95. package/src/bmad-plus/packs/pack-seo/ref/hreflang-rules.md +153 -153
  96. package/src/bmad-plus/packs/pack-seo/ref/quality-gates.md +133 -133
  97. package/src/bmad-plus/packs/pack-seo/ref/schema-catalog.md +91 -91
  98. package/src/bmad-plus/packs/pack-seo/ref/schema-templates.json +356 -356
  99. package/src/bmad-plus/packs/pack-seo/requirements.txt +17 -0
  100. package/src/bmad-plus/packs/pack-seo/scripts/seo_apis.py +456 -0
  101. package/src/bmad-plus/packs/pack-seo/scripts/seo_crawl.py +359 -0
  102. package/src/bmad-plus/packs/pack-seo/scripts/seo_fetch.py +304 -0
  103. package/src/bmad-plus/packs/pack-seo/scripts/seo_parse.py +255 -0
  104. package/src/bmad-plus/packs/pack-seo/scripts/seo_report.py +410 -0
  105. package/src/bmad-plus/packs/pack-seo/scripts/seo_screenshot.py +202 -0
  106. package/src/bmad-plus/packs/pack-seo/seo-chief.md +294 -294
  107. package/src/bmad-plus/packs/pack-seo/seo-judge.md +241 -241
  108. package/src/bmad-plus/packs/pack-seo/seo-scout.md +171 -171
  109. package/src/bmad-plus/packs/pack-seo/templates/seo-audit-workflow.md +241 -241
  110. package/src/bmad-plus/packs/pack-shield/README.md +6 -6
  111. package/src/bmad-plus/packs/pack-shield/SKILL.md +2 -2
  112. package/src/bmad-plus/packs/pack-shield/categories/accessibility-esg/csrd-agent.md +11 -11
  113. package/src/bmad-plus/packs/pack-shield/categories/accessibility-esg/section508-agent.md +11 -11
  114. package/src/bmad-plus/packs/pack-shield/categories/accessibility-esg/wcag-agent.md +11 -11
  115. package/src/bmad-plus/packs/pack-shield/categories/ai-governance/eu-ai-act-agent.md +11 -11
  116. package/src/bmad-plus/packs/pack-shield/categories/ai-governance/iso42001-agent.md +11 -11
  117. package/src/bmad-plus/packs/pack-shield/categories/ai-governance/nist-ai-rmf-agent.md +11 -11
  118. package/src/bmad-plus/packs/pack-shield/categories/cybersecurity/cis-controls-agent.md +11 -11
  119. package/src/bmad-plus/packs/pack-shield/categories/cybersecurity/ism-agent.md +11 -11
  120. package/src/bmad-plus/packs/pack-shield/categories/cybersecurity/iso27001-agent.md +11 -11
  121. package/src/bmad-plus/packs/pack-shield/categories/cybersecurity/nis2-agent.md +11 -11
  122. package/src/bmad-plus/packs/pack-shield/categories/cybersecurity/nist-800-53-agent.md +11 -11
  123. package/src/bmad-plus/packs/pack-shield/categories/cybersecurity/nist-csf-agent.md +11 -11
  124. package/src/bmad-plus/packs/pack-shield/categories/defense-export/cmmc-agent.md +11 -11
  125. package/src/bmad-plus/packs/pack-shield/categories/defense-export/ear-agent.md +11 -11
  126. package/src/bmad-plus/packs/pack-shield/categories/defense-export/itar-agent.md +11 -11
  127. package/src/bmad-plus/packs/pack-shield/categories/defense-export/tsa-agent.md +11 -11
  128. package/src/bmad-plus/packs/pack-shield/categories/industry-compliance/dora-agent.md +11 -11
  129. package/src/bmad-plus/packs/pack-shield/categories/industry-compliance/fedramp-agent.md +11 -11
  130. package/src/bmad-plus/packs/pack-shield/categories/industry-compliance/hipaa-agent.md +11 -11
  131. package/src/bmad-plus/packs/pack-shield/categories/industry-compliance/pci-dss-agent.md +11 -11
  132. package/src/bmad-plus/packs/pack-shield/categories/industry-compliance/soc2-agent.md +11 -11
  133. package/src/bmad-plus/packs/pack-shield/categories/industry-compliance/swift-csp-agent.md +11 -11
  134. package/src/bmad-plus/packs/pack-shield/shield-orchestrator.md +1 -1
  135. package/tools/build/check-counts.js +628 -0
  136. package/tools/build/generated-adapters/.codex/AGENTS.md +1 -1
  137. package/tools/build/generated-adapters/.cursor/rules/bmad-plus.mdc +1 -1
  138. package/tools/build/generated-adapters/.opencode/AGENTS.md +1 -1
  139. package/tools/build/generated-adapters/AGENTS.md +1 -1
  140. package/tools/build/generated-adapters/CLAUDE.md +1 -1
  141. package/tools/build/generated-adapters/CONVENTIONS.md +1 -1
  142. package/tools/build/generated-adapters/GEMINI.md +1 -1
  143. package/tools/cli/commands/autoconfig.js +470 -470
  144. package/tools/cli/commands/doctor.js +233 -233
  145. package/tools/cli/commands/install.js +598 -501
  146. package/tools/cli/commands/memory-journal-cmd.js +311 -311
  147. package/tools/cli/commands/memory.js +195 -195
  148. package/tools/cli/commands/scan.js +348 -348
  149. package/tools/cli/commands/uninstall.js +101 -101
  150. package/tools/cli/commands/update.js +134 -134
  151. package/tools/cli/i18n.js +845 -845
  152. package/tools/cli/lib/README-memory-journal.md +125 -125
  153. package/tools/cli/lib/ide-config.js +267 -259
  154. package/tools/cli/lib/python-provision.js +508 -508
  155. package/tools/cli/lib/stack-detect.js +102 -102
  156. package/tools/cli/lib/validate.js +50 -50
@@ -1,125 +1,125 @@
1
- # memory-journal.js — Karpathy Learning Layer core (Pillar 3)
2
-
3
- Portable data structures + helpers for the BMAD+ **memory → reward → reinforcement** loop.
4
- Prompt-level learning only: scores steer retrieval and pattern promotion — there is
5
- **no base-model fine-tuning** (see `audit/2026-07-01/north-star/registry.yaml` →
6
- `memory.reward_signal.applies_to`).
7
-
8
- Builds **on top of** the existing `pack-memory` (Zecher, Karpathy guardrails G1–G4,
9
- `decisions/lessons/patterns/context.md` templates). It never modifies those files or
10
- `tools/cli/lib/memory-init.js` — it adds a structured, machine-readable layer beside them.
11
-
12
- ```
13
- .bmad/memory/journal.ndjson ← structured event log (this module, north-star scope)
14
- .bmad/memory/promotions.ndjson ← governance queue (always PROPOSED)
15
- .agents/memory/*.md ← human memory (pack-memory, current layout) — READ ONLY here
16
- .bmad/memory/*.md ← human memory (north-star layout) — READ ONLY here
17
- ```
18
-
19
- ## Hard rules baked into the module
20
-
21
- | Rule | Enforcement |
22
- |---|---|
23
- | No hidden clock / randomness | `ts` is a **required, caller-injected** field; ids are content hashes (sha256). The module never calls `Date.now()` or `Math.random()` — at import or runtime. |
24
- | Node stdlib only | `fs`, `path`, `crypto`. No network, no native deps → runs identically under every CLI. |
25
- | Journal is append-only, corruption-tolerant | `readJournal`/`readPromotions` skip torn lines instead of throwing (concurrent CLIs may write). |
26
- | Promotions are never auto-applied | `proposePromotion()` only emits `status: 'PROPOSED'`; `appendPromotion()` **forces** `PROPOSED` + clears approval fields on disk even for tampered records; `assertPromotionApplicable()` throws unless `status === 'APPROVED'` **and** `approvedBy` names a human/Shield reviewer. |
27
-
28
- ## API
29
-
30
- ### 1. Journal
31
-
32
- ```js
33
- const mj = require('./memory-journal');
34
-
35
- mj.appendEvent(projectDir, {
36
- ts: new Date().toISOString(), // REQUIRED — injected by the caller
37
- agent: 'forge', // REQUIRED
38
- cli: 'claude-code', // claude-code | gemini-cli | antigravity | cursor | codex-cli | opencode | aider
39
- model: 'claude', // model-agnostic by contract (claude/gpt/gemini/local)
40
- task: 'refactor postgres pooling',
41
- outcome: 'success', // success | failure | partial | abandoned
42
- signals: { evalScore: 0.9, acceptance: true, ci: 'pass' },
43
- artifactHashes: ['abc123'], // traceability to produced artifacts
44
- });
45
-
46
- mj.readJournal(projectDir); // → events[], oldest first, corrupt lines skipped
47
- ```
48
-
49
- ### 2. Recall (lexical first cut + vector-backend seam)
50
-
51
- ```js
52
- mj.recall('postgres pooling', {
53
- baseDir: projectDir,
54
- scope: 'project', // or 'portfolio' + portfolioDir: 'D:/travail/DEV/_brain'
55
- limit: 8,
56
- now: new Date().toISOString(), // optional injected clock → recency decay on events
57
- halfLifeDays: 30,
58
- });
59
- // → [{ score, kind: 'event'|'note', source, ref, text, event? }] ranked desc
60
- ```
61
-
62
- Sources merged: `journal.ndjson` events + `### `-sectioned entries from
63
- `decisions.md` / `lessons.md` / `patterns.md` in **both** `.bmad/memory/` (north-star)
64
- and `.agents/memory/` (current pack-memory layout), plus `<portfolioDir>/memory/*.md`
65
- when `scope: 'portfolio'`.
66
-
67
- **ChromaDB seam** — pass `backend: { search(query, opts) }` and ranking is delegated
68
- wholesale to it. The intended production backend is the existing RAG stack
69
- (`mcp-server/rag.py`: ChromaDB + SentenceTransformers — `registry.yaml → memory.index`).
70
- Backends must return the same entry shape as the lexical fallback, so callers never
71
- know which engine served them. The lexical scorer is the zero-dependency fallback for
72
- machines without Python provisioned.
73
-
74
- ### 3. Reward + pattern score
75
-
76
- ```js
77
- const reward = mj.computeReward({ evalScore: 0.8, acceptance: true, ci: 'fail' });
78
- // weights eval 0.5 / acceptance 0.3 / ci 0.2 (registry.yaml → memory.reward_signal.inputs)
79
- // missing signals renormalize the remaining weights; result always in [0, 1]
80
-
81
- let score = mj.INITIAL_PATTERN_SCORE; // { elo: 1200, alpha: 1, beta: 1, mean: 0.5, ... }
82
- score = mj.updatePatternScore(score, reward, { ts: eventTs });
83
- ```
84
-
85
- Two complementary estimators per pattern:
86
-
87
- - **Elo** (`k=32`, baseline 1200): `elo' = elo + K·(reward − expected)` — fast-moving,
88
- ordinal, used to **rank** patterns in recall. Fresh pattern + reward 1 → 1216.
89
- - **Decayed Bayesian (Beta)**: evidence decays multiplicatively toward the uniform
90
- prior (1,1) — per-update (`decay=0.98`) and time-based (`halfLifeDays=90`, only when
91
- `ts` is injected) — so `mean = α/(α+β)` tracks the **recent** success rate, used for
92
- **promotion thresholds** (`candidate → validated → deprecated` in `patterns.md`).
93
-
94
- Pure function: never mutates input, never reads the clock.
95
-
96
- ### 4. Governance guard
97
-
98
- ```js
99
- const p = mj.proposePromotion({ patternId: 'chromadb batch ingestion', ts, reason: 'mean 0.82 / 12 events', evidence: [eventIds] });
100
- mj.appendPromotion(projectDir, p); // persisted as PROPOSED, always
101
- // ... a human / Shield reviewer flips it to APPROVED with approvedBy elsewhere ...
102
- mj.assertPromotionApplicable(approved); // the gate every apply path MUST call
103
- ```
104
-
105
- Governed by **Shield** (`registry.yaml → memory.reward_signal.governed_by`): bounded
106
- self-modification, versioned (append-only ndjson) and reversible (a promotion record
107
- never rewrites history; a rollback is just another proposal).
108
-
109
- ## Testing
110
-
111
- ```
112
- npx jest tests/unit/memory-journal.test.js
113
- ```
114
-
115
- 32 tests: append/recall round-trip on a tmp dir, corrupt-line tolerance, recency decay
116
- with injected clock, portfolio scope, backend-seam delegation, exact Elo/Beta math,
117
- purity, and the anti-tamper governance guard.
118
-
119
- ## Future wiring (done by the orchestrator, not this module)
120
-
121
- - **MCP tools** `memory.write` / `memory.recall` in `mcp-server/` — thin wrappers over
122
- this ndjson contract so every MCP-capable CLI shares one memory (Pillar 5).
123
- - **CLI commands** `bmad-plus memory log|recall|promote` in `tools/cli/commands/memory.js`.
124
- - **Zecher consolidation**: pack-memory's archivist reads `journal.ndjson` during
125
- session consolidation and proposes pattern promotions via `proposePromotion()`.
1
+ # memory-journal.js — Karpathy Learning Layer core (Pillar 3)
2
+
3
+ Portable data structures + helpers for the BMAD+ **memory → reward → reinforcement** loop.
4
+ Prompt-level learning only: scores steer retrieval and pattern promotion — there is
5
+ **no base-model fine-tuning** (see `audit/2026-07-01/north-star/registry.yaml` →
6
+ `memory.reward_signal.applies_to`).
7
+
8
+ Builds **on top of** the existing `pack-memory` (Zecher, Karpathy guardrails G1–G4,
9
+ `decisions/lessons/patterns/context.md` templates). It never modifies those files or
10
+ `tools/cli/lib/memory-init.js` — it adds a structured, machine-readable layer beside them.
11
+
12
+ ```
13
+ .bmad/memory/journal.ndjson ← structured event log (this module, north-star scope)
14
+ .bmad/memory/promotions.ndjson ← governance queue (always PROPOSED)
15
+ .agents/memory/*.md ← human memory (pack-memory, current layout) — READ ONLY here
16
+ .bmad/memory/*.md ← human memory (north-star layout) — READ ONLY here
17
+ ```
18
+
19
+ ## Hard rules baked into the module
20
+
21
+ | Rule | Enforcement |
22
+ |---|---|
23
+ | No hidden clock / randomness | `ts` is a **required, caller-injected** field; ids are content hashes (sha256). The module never calls `Date.now()` or `Math.random()` — at import or runtime. |
24
+ | Node stdlib only | `fs`, `path`, `crypto`. No network, no native deps → runs identically under every CLI. |
25
+ | Journal is append-only, corruption-tolerant | `readJournal`/`readPromotions` skip torn lines instead of throwing (concurrent CLIs may write). |
26
+ | Promotions are never auto-applied | `proposePromotion()` only emits `status: 'PROPOSED'`; `appendPromotion()` **forces** `PROPOSED` + clears approval fields on disk even for tampered records; `assertPromotionApplicable()` throws unless `status === 'APPROVED'` **and** `approvedBy` names a human/Shield reviewer. |
27
+
28
+ ## API
29
+
30
+ ### 1. Journal
31
+
32
+ ```js
33
+ const mj = require('./memory-journal');
34
+
35
+ mj.appendEvent(projectDir, {
36
+ ts: new Date().toISOString(), // REQUIRED — injected by the caller
37
+ agent: 'forge', // REQUIRED
38
+ cli: 'claude-code', // claude-code | gemini-cli | antigravity | cursor | codex-cli | opencode | aider
39
+ model: 'claude', // model-agnostic by contract (claude/gpt/gemini/local)
40
+ task: 'refactor postgres pooling',
41
+ outcome: 'success', // success | failure | partial | abandoned
42
+ signals: { evalScore: 0.9, acceptance: true, ci: 'pass' },
43
+ artifactHashes: ['abc123'], // traceability to produced artifacts
44
+ });
45
+
46
+ mj.readJournal(projectDir); // → events[], oldest first, corrupt lines skipped
47
+ ```
48
+
49
+ ### 2. Recall (lexical first cut + vector-backend seam)
50
+
51
+ ```js
52
+ mj.recall('postgres pooling', {
53
+ baseDir: projectDir,
54
+ scope: 'project', // or 'portfolio' + portfolioDir: 'D:/travail/DEV/_brain'
55
+ limit: 8,
56
+ now: new Date().toISOString(), // optional injected clock → recency decay on events
57
+ halfLifeDays: 30,
58
+ });
59
+ // → [{ score, kind: 'event'|'note', source, ref, text, event? }] ranked desc
60
+ ```
61
+
62
+ Sources merged: `journal.ndjson` events + `### `-sectioned entries from
63
+ `decisions.md` / `lessons.md` / `patterns.md` in **both** `.bmad/memory/` (north-star)
64
+ and `.agents/memory/` (current pack-memory layout), plus `<portfolioDir>/memory/*.md`
65
+ when `scope: 'portfolio'`.
66
+
67
+ **ChromaDB seam** — pass `backend: { search(query, opts) }` and ranking is delegated
68
+ wholesale to it. The intended production backend is the existing RAG stack
69
+ (`mcp-server/rag.py`: ChromaDB + SentenceTransformers — `registry.yaml → memory.index`).
70
+ Backends must return the same entry shape as the lexical fallback, so callers never
71
+ know which engine served them. The lexical scorer is the zero-dependency fallback for
72
+ machines without Python provisioned.
73
+
74
+ ### 3. Reward + pattern score
75
+
76
+ ```js
77
+ const reward = mj.computeReward({ evalScore: 0.8, acceptance: true, ci: 'fail' });
78
+ // weights eval 0.5 / acceptance 0.3 / ci 0.2 (registry.yaml → memory.reward_signal.inputs)
79
+ // missing signals renormalize the remaining weights; result always in [0, 1]
80
+
81
+ let score = mj.INITIAL_PATTERN_SCORE; // { elo: 1200, alpha: 1, beta: 1, mean: 0.5, ... }
82
+ score = mj.updatePatternScore(score, reward, { ts: eventTs });
83
+ ```
84
+
85
+ Two complementary estimators per pattern:
86
+
87
+ - **Elo** (`k=32`, baseline 1200): `elo' = elo + K·(reward − expected)` — fast-moving,
88
+ ordinal, used to **rank** patterns in recall. Fresh pattern + reward 1 → 1216.
89
+ - **Decayed Bayesian (Beta)**: evidence decays multiplicatively toward the uniform
90
+ prior (1,1) — per-update (`decay=0.98`) and time-based (`halfLifeDays=90`, only when
91
+ `ts` is injected) — so `mean = α/(α+β)` tracks the **recent** success rate, used for
92
+ **promotion thresholds** (`candidate → validated → deprecated` in `patterns.md`).
93
+
94
+ Pure function: never mutates input, never reads the clock.
95
+
96
+ ### 4. Governance guard
97
+
98
+ ```js
99
+ const p = mj.proposePromotion({ patternId: 'chromadb batch ingestion', ts, reason: 'mean 0.82 / 12 events', evidence: [eventIds] });
100
+ mj.appendPromotion(projectDir, p); // persisted as PROPOSED, always
101
+ // ... a human / Shield reviewer flips it to APPROVED with approvedBy elsewhere ...
102
+ mj.assertPromotionApplicable(approved); // the gate every apply path MUST call
103
+ ```
104
+
105
+ Governed by **Shield** (`registry.yaml → memory.reward_signal.governed_by`): bounded
106
+ self-modification, versioned (append-only ndjson) and reversible (a promotion record
107
+ never rewrites history; a rollback is just another proposal).
108
+
109
+ ## Testing
110
+
111
+ ```
112
+ npx jest tests/unit/memory-journal.test.js
113
+ ```
114
+
115
+ 32 tests: append/recall round-trip on a tmp dir, corrupt-line tolerance, recency decay
116
+ with injected clock, portfolio scope, backend-seam delegation, exact Elo/Beta math,
117
+ purity, and the anti-tamper governance guard.
118
+
119
+ ## Future wiring (done by the orchestrator, not this module)
120
+
121
+ - **MCP tools** `memory.write` / `memory.recall` in `mcp-server/` — thin wrappers over
122
+ this ndjson contract so every MCP-capable CLI shares one memory (Pillar 5).
123
+ - **CLI commands** `bmad-plus memory log|recall|promote` in `tools/cli/commands/memory.js`.
124
+ - **Zecher consolidation**: pack-memory's archivist reads `journal.ndjson` during
125
+ session consolidation and proposes pattern promotions via `proposePromotion()`.