bmad-plus 0.12.1 → 0.13.0
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.
- package/CHANGELOG.md +637 -580
- package/README.md +123 -120
- package/osint-agent-package/agents/osint-investigator.md +12 -0
- package/osint-agent-package/skills/bmad-osint-investigate/osint/SKILL.md +491 -482
- package/osint-agent-package/skills/bmad-osint-investigate/osint/assets/dossier-template.md +126 -126
- package/osint-agent-package/skills/bmad-osint-investigate/osint/assets/lawful-basis-record.md +48 -48
- package/osint-agent-package/skills/bmad-osint-investigate/osint/references/content-extraction.md +100 -100
- package/osint-agent-package/skills/bmad-osint-investigate/osint/references/gdpr-osint.md +48 -48
- package/osint-agent-package/skills/bmad-osint-investigate/osint/references/platforms.md +130 -130
- package/osint-agent-package/skills/bmad-osint-investigate/osint/references/psychoprofile.md +69 -69
- package/osint-agent-package/skills/bmad-osint-investigate/osint/references/tools.md +281 -281
- package/osint-agent-package/skills/bmad-osint-investigate/osint/scripts/mcp-client.py +136 -136
- package/package.json +106 -91
- package/readme-international/README.de.md +625 -594
- package/readme-international/README.es.md +642 -611
- package/readme-international/README.fr.md +640 -609
- package/src/bmad-plus/agents/agent-orchestrator/SKILL.md +2 -0
- package/src/bmad-plus/agents/agent-shadow/SKILL.md +18 -0
- package/src/bmad-plus/data/role-triggers.yaml +52 -0
- package/src/bmad-plus/module.yaml +333 -283
- package/src/bmad-plus/packs/pack-animated/animated-website-agent.md +325 -325
- package/src/bmad-plus/packs/pack-animated/templates/animated-website-workflow.md +55 -55
- package/src/bmad-plus/packs/pack-backup/backup-agent.md +71 -71
- package/src/bmad-plus/packs/pack-backup/templates/backup-workflow.md +51 -51
- package/src/bmad-plus/packs/pack-dev-studio/README.md +162 -162
- package/src/bmad-plus/packs/pack-dev-studio/categories/analysis/analyst-agent.md +73 -73
- package/src/bmad-plus/packs/pack-dev-studio/categories/analysis/document-project.md +61 -61
- package/src/bmad-plus/packs/pack-dev-studio/categories/analysis/domain-research.md +95 -95
- package/src/bmad-plus/packs/pack-dev-studio/categories/analysis/market-research.md +95 -95
- package/src/bmad-plus/packs/pack-dev-studio/categories/analysis/prfaq.md +134 -134
- package/src/bmad-plus/packs/pack-dev-studio/categories/analysis/product-brief.md +80 -80
- package/src/bmad-plus/packs/pack-dev-studio/categories/analysis/tech-writer-agent.md +73 -73
- package/src/bmad-plus/packs/pack-dev-studio/categories/analysis/technical-research.md +95 -95
- package/src/bmad-plus/packs/pack-dev-studio/categories/architecture/architect-agent.md +73 -73
- package/src/bmad-plus/packs/pack-dev-studio/categories/architecture/create-architecture.md +73 -73
- package/src/bmad-plus/packs/pack-dev-studio/categories/architecture/create-epics-stories.md +92 -92
- package/src/bmad-plus/packs/pack-dev-studio/categories/architecture/generate-project-context.md +80 -80
- package/src/bmad-plus/packs/pack-dev-studio/categories/architecture/implementation-readiness.md +90 -90
- package/src/bmad-plus/packs/pack-dev-studio/categories/architecture/steps/step-01-init.md +153 -153
- package/src/bmad-plus/packs/pack-dev-studio/categories/architecture/steps/step-01b-continue.md +173 -173
- package/src/bmad-plus/packs/pack-dev-studio/categories/architecture/steps/step-02-context.md +224 -224
- package/src/bmad-plus/packs/pack-dev-studio/categories/architecture/steps/step-03-starter.md +329 -329
- package/src/bmad-plus/packs/pack-dev-studio/categories/architecture/steps/step-04-decisions.md +318 -318
- package/src/bmad-plus/packs/pack-dev-studio/categories/architecture/steps/step-05-patterns.md +359 -359
- package/src/bmad-plus/packs/pack-dev-studio/categories/architecture/steps/step-06-structure.md +379 -379
- package/src/bmad-plus/packs/pack-dev-studio/categories/architecture/steps/step-07-validation.md +361 -361
- package/src/bmad-plus/packs/pack-dev-studio/categories/architecture/steps/step-08-complete.md +81 -81
- package/src/bmad-plus/packs/pack-dev-studio/categories/implementation/checkpoint-preview.md +67 -67
- package/src/bmad-plus/packs/pack-dev-studio/categories/implementation/code-review-steps/step-01-gather-context.md +85 -85
- package/src/bmad-plus/packs/pack-dev-studio/categories/implementation/code-review-steps/step-02-review.md +35 -35
- package/src/bmad-plus/packs/pack-dev-studio/categories/implementation/code-review-steps/step-03-triage.md +49 -49
- package/src/bmad-plus/packs/pack-dev-studio/categories/implementation/code-review-steps/step-04-present.md +131 -131
- package/src/bmad-plus/packs/pack-dev-studio/categories/implementation/code-review.md +89 -89
- package/src/bmad-plus/packs/pack-dev-studio/categories/implementation/correct-course.md +300 -300
- package/src/bmad-plus/packs/pack-dev-studio/categories/implementation/create-story.md +428 -428
- package/src/bmad-plus/packs/pack-dev-studio/categories/implementation/dev-agent.md +73 -73
- package/src/bmad-plus/packs/pack-dev-studio/categories/implementation/dev-story-checklist.md +80 -80
- package/src/bmad-plus/packs/pack-dev-studio/categories/implementation/dev-story.md +484 -484
- package/src/bmad-plus/packs/pack-dev-studio/categories/implementation/investigate.md +193 -193
- package/src/bmad-plus/packs/pack-dev-studio/categories/implementation/qa-e2e-tests.md +175 -175
- package/src/bmad-plus/packs/pack-dev-studio/categories/implementation/quick-dev.md +110 -110
- package/src/bmad-plus/packs/pack-dev-studio/categories/implementation/retrospective.md +1511 -1511
- package/src/bmad-plus/packs/pack-dev-studio/categories/implementation/sprint-planning.md +298 -298
- package/src/bmad-plus/packs/pack-dev-studio/categories/implementation/sprint-status.md +296 -296
- package/src/bmad-plus/packs/pack-dev-studio/categories/planning/create-prd.md +29 -29
- package/src/bmad-plus/packs/pack-dev-studio/categories/planning/create-ux-design.md +74 -74
- package/src/bmad-plus/packs/pack-dev-studio/categories/planning/edit-prd.md +29 -29
- package/src/bmad-plus/packs/pack-dev-studio/categories/planning/pm-agent.md +73 -73
- package/src/bmad-plus/packs/pack-dev-studio/categories/planning/prd.md +89 -89
- package/src/bmad-plus/packs/pack-dev-studio/categories/planning/ux-designer-agent.md +73 -73
- package/src/bmad-plus/packs/pack-dev-studio/categories/planning/validate-prd.md +29 -29
- package/src/bmad-plus/packs/pack-dev-studio/categories/utilities/advanced-elicitation.md +141 -141
- package/src/bmad-plus/packs/pack-dev-studio/categories/utilities/adversarial-review.md +37 -37
- package/src/bmad-plus/packs/pack-dev-studio/categories/utilities/bmad-help.md +75 -75
- package/src/bmad-plus/packs/pack-dev-studio/categories/utilities/brainstorming.md +6 -6
- package/src/bmad-plus/packs/pack-dev-studio/categories/utilities/customize.md +110 -110
- package/src/bmad-plus/packs/pack-dev-studio/categories/utilities/distillator.md +176 -176
- package/src/bmad-plus/packs/pack-dev-studio/categories/utilities/edge-case-hunter.md +67 -67
- package/src/bmad-plus/packs/pack-dev-studio/categories/utilities/editorial-review-prose.md +86 -86
- package/src/bmad-plus/packs/pack-dev-studio/categories/utilities/editorial-review-structure.md +179 -179
- package/src/bmad-plus/packs/pack-dev-studio/categories/utilities/index-docs.md +66 -66
- package/src/bmad-plus/packs/pack-dev-studio/categories/utilities/party-mode.md +127 -127
- package/src/bmad-plus/packs/pack-dev-studio/categories/utilities/shard-doc.md +105 -105
- package/src/bmad-plus/packs/pack-dev-studio/dev-studio-orchestrator.md +120 -120
- package/src/bmad-plus/packs/pack-dev-studio/shared/architecture-decision-template.md +12 -12
- package/src/bmad-plus/packs/pack-dev-studio/shared/bwml-spec.md +328 -328
- package/src/bmad-plus/packs/pack-dev-studio/shared/module-help.csv +32 -32
- package/src/bmad-plus/packs/pack-dev-studio/upstream-sync.yaml +81 -81
- package/src/bmad-plus/packs/pack-seo/SKILL.md +171 -171
- package/src/bmad-plus/packs/pack-seo/checklist.md +140 -140
- package/src/bmad-plus/packs/pack-seo/pagespeed-playbook.md +320 -320
- package/src/bmad-plus/packs/pack-seo/ref/audit-schema.json +187 -187
- package/src/bmad-plus/packs/pack-seo/ref/cwv-thresholds.md +87 -87
- package/src/bmad-plus/packs/pack-seo/ref/eeat-criteria.md +123 -123
- package/src/bmad-plus/packs/pack-seo/ref/geo-signals.md +167 -167
- package/src/bmad-plus/packs/pack-seo/ref/hreflang-rules.md +153 -153
- package/src/bmad-plus/packs/pack-seo/ref/quality-gates.md +133 -133
- package/src/bmad-plus/packs/pack-seo/ref/schema-catalog.md +91 -91
- package/src/bmad-plus/packs/pack-seo/ref/schema-templates.json +356 -356
- package/src/bmad-plus/packs/pack-seo/requirements.txt +17 -0
- package/src/bmad-plus/packs/pack-seo/scripts/seo_apis.py +456 -0
- package/src/bmad-plus/packs/pack-seo/scripts/seo_crawl.py +359 -0
- package/src/bmad-plus/packs/pack-seo/scripts/seo_fetch.py +303 -0
- package/src/bmad-plus/packs/pack-seo/scripts/seo_parse.py +255 -0
- package/src/bmad-plus/packs/pack-seo/scripts/seo_report.py +409 -0
- package/src/bmad-plus/packs/pack-seo/scripts/seo_screenshot.py +202 -0
- package/src/bmad-plus/packs/pack-seo/seo-chief.md +294 -294
- package/src/bmad-plus/packs/pack-seo/seo-judge.md +241 -241
- package/src/bmad-plus/packs/pack-seo/seo-scout.md +171 -171
- package/src/bmad-plus/packs/pack-seo/templates/seo-audit-workflow.md +241 -241
- package/src/bmad-plus/packs/pack-shield/README.md +6 -6
- package/src/bmad-plus/packs/pack-shield/SKILL.md +2 -2
- package/src/bmad-plus/packs/pack-shield/categories/accessibility-esg/csrd-agent.md +11 -11
- package/src/bmad-plus/packs/pack-shield/categories/accessibility-esg/section508-agent.md +11 -11
- package/src/bmad-plus/packs/pack-shield/categories/accessibility-esg/wcag-agent.md +11 -11
- package/src/bmad-plus/packs/pack-shield/categories/ai-governance/eu-ai-act-agent.md +11 -11
- package/src/bmad-plus/packs/pack-shield/categories/ai-governance/iso42001-agent.md +11 -11
- package/src/bmad-plus/packs/pack-shield/categories/ai-governance/nist-ai-rmf-agent.md +11 -11
- package/src/bmad-plus/packs/pack-shield/categories/cybersecurity/cis-controls-agent.md +11 -11
- package/src/bmad-plus/packs/pack-shield/categories/cybersecurity/ism-agent.md +11 -11
- package/src/bmad-plus/packs/pack-shield/categories/cybersecurity/iso27001-agent.md +11 -11
- package/src/bmad-plus/packs/pack-shield/categories/cybersecurity/nis2-agent.md +11 -11
- package/src/bmad-plus/packs/pack-shield/categories/cybersecurity/nist-800-53-agent.md +11 -11
- package/src/bmad-plus/packs/pack-shield/categories/cybersecurity/nist-csf-agent.md +11 -11
- package/src/bmad-plus/packs/pack-shield/categories/defense-export/cmmc-agent.md +11 -11
- package/src/bmad-plus/packs/pack-shield/categories/defense-export/ear-agent.md +11 -11
- package/src/bmad-plus/packs/pack-shield/categories/defense-export/itar-agent.md +11 -11
- package/src/bmad-plus/packs/pack-shield/categories/defense-export/tsa-agent.md +11 -11
- package/src/bmad-plus/packs/pack-shield/categories/industry-compliance/dora-agent.md +11 -11
- package/src/bmad-plus/packs/pack-shield/categories/industry-compliance/fedramp-agent.md +11 -11
- package/src/bmad-plus/packs/pack-shield/categories/industry-compliance/hipaa-agent.md +11 -11
- package/src/bmad-plus/packs/pack-shield/categories/industry-compliance/pci-dss-agent.md +11 -11
- package/src/bmad-plus/packs/pack-shield/categories/industry-compliance/soc2-agent.md +11 -11
- package/src/bmad-plus/packs/pack-shield/categories/industry-compliance/swift-csp-agent.md +11 -11
- package/src/bmad-plus/packs/pack-shield/shield-orchestrator.md +1 -1
- package/src/bmad-plus/skills/bmad-plus-autopilot/SKILL.md +1 -1
- package/tools/bmad-plus-npx.js +4 -2
- package/tools/build/adapters.config.js +60 -51
- package/tools/build/check-counts.js +626 -0
- package/tools/build/check-install-contract.js +298 -0
- package/tools/build/generate-adapters.js +252 -56
- package/tools/build/generate.js +187 -10
- package/tools/build/generated-adapters/.codex/AGENTS.md +20 -7
- package/tools/build/generated-adapters/.cursor/rules/bmad-plus.mdc +20 -7
- package/tools/build/generated-adapters/.opencode/AGENTS.md +20 -7
- package/tools/build/generated-adapters/AGENTS.md +20 -7
- package/tools/build/generated-adapters/CLAUDE.md +20 -7
- package/tools/build/generated-adapters/CONVENTIONS.md +20 -7
- package/tools/build/generated-adapters/GEMINI.md +20 -7
- package/tools/build/module.template.yaml +82 -0
- package/tools/cli/bmad-plus-cli.js +16 -1
- package/tools/cli/commands/autoconfig.js +470 -470
- package/tools/cli/commands/doctor.js +205 -233
- package/tools/cli/commands/install.js +543 -501
- package/tools/cli/commands/memory-journal-cmd.js +311 -311
- package/tools/cli/commands/memory.js +195 -195
- package/tools/cli/commands/scan.js +348 -348
- package/tools/cli/commands/uninstall.js +209 -101
- package/tools/cli/commands/update-check.js +31 -0
- package/tools/cli/commands/update-policy.js +39 -0
- package/tools/cli/commands/update.js +123 -134
- package/tools/cli/i18n.js +905 -845
- package/tools/cli/lib/README-memory-journal.md +125 -125
- package/tools/cli/lib/ide-config.js +10 -259
- package/tools/cli/lib/install-manifest.js +17 -0
- package/tools/cli/lib/installed-adapters.js +89 -0
- package/tools/cli/lib/npm-runner.js +177 -0
- package/tools/cli/lib/pack-copy.js +62 -66
- package/tools/cli/lib/packs.js +437 -3
- package/tools/cli/lib/python-provision.js +508 -508
- package/tools/cli/lib/stack-detect.js +102 -102
- package/tools/cli/lib/update-check.js +153 -0
- package/tools/cli/lib/update-dispatch.js +182 -0
- package/tools/cli/lib/update-policy.js +90 -0
- package/tools/cli/lib/update-transaction.js +334 -0
- 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()`.
|
|
@@ -1,259 +1,10 @@
|
|
|
1
|
-
/**
|
|
2
|
-
*
|
|
3
|
-
*
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
const IDE_CONFIGS = {
|
|
12
|
-
'claude-code': {
|
|
13
|
-
name: 'Claude Code',
|
|
14
|
-
detect: ['.claude'],
|
|
15
|
-
configFile: 'CLAUDE.md',
|
|
16
|
-
},
|
|
17
|
-
'gemini-cli': {
|
|
18
|
-
name: 'Gemini CLI',
|
|
19
|
-
detect: ['.gemini'],
|
|
20
|
-
configFile: 'GEMINI.md',
|
|
21
|
-
},
|
|
22
|
-
'codex-cli': {
|
|
23
|
-
name: 'Codex CLI / OpenCode',
|
|
24
|
-
detect: ['.codex', '.opencode'],
|
|
25
|
-
configFile: 'AGENTS.md',
|
|
26
|
-
},
|
|
27
|
-
'antigravity': {
|
|
28
|
-
name: 'Antigravity',
|
|
29
|
-
detect: ['.gemini/antigravity'],
|
|
30
|
-
configFile: 'GEMINI.md',
|
|
31
|
-
},
|
|
32
|
-
};
|
|
33
|
-
|
|
34
|
-
// All 14 BMAD+ agents — always included in templates
|
|
35
|
-
const AGENT_LIST = [
|
|
36
|
-
'- **Atlas** (Strategist) — Business analysis + Product management',
|
|
37
|
-
'- **Forge** (Architect-Dev) — Architecture + Development + Documentation',
|
|
38
|
-
'- **Sentinel** (Quality) — QA + UX review',
|
|
39
|
-
'- **Nexus** (Orchestrator) — Sprint management + Autopilot + Parallel execution',
|
|
40
|
-
'- **Shadow** (OSINT) — Investigation + Scraping + Psychoprofiling',
|
|
41
|
-
'- **Shield** (GRC) — 38 compliance agents (GDPR, ISO 27001, SOC 2, HIPAA, EU AI Act, DORA, NIS2...)',
|
|
42
|
-
'- **Miriam** (מרים) — Business Analyst — Strategic analysis, research, product briefs',
|
|
43
|
-
'- **Huldah** (חולדה) — Technical Writer — Documentation, diagrams, editorial review',
|
|
44
|
-
'- **Yosef** (יוסף) — Product Manager — PRD, requirements, feature prioritization',
|
|
45
|
-
'- **Rachel** (רחל) — UX Designer — User experience, wireframes, empathy mapping',
|
|
46
|
-
'- **Bezalel** (בצלאל) — System Architect — Architecture, ADRs, epics & stories',
|
|
47
|
-
'- **Oholiab** (אהליאב) — Senior Engineer — TDD, sprint, code review, implementation',
|
|
48
|
-
'- **Zecher** (זכר) — Memory Archivist — Consolidation, project scanning, context recall',
|
|
49
|
-
'- **Maker** (Creator) — Custom agent builder — Create new agents from description',
|
|
50
|
-
];
|
|
51
|
-
|
|
52
|
-
/**
|
|
53
|
-
* Filter agents based on installed packs.
|
|
54
|
-
* Core agents are always included; others depend on pack selection.
|
|
55
|
-
*
|
|
56
|
-
* @param {string[]} packs - List of installed pack IDs
|
|
57
|
-
* @returns {string[]} Agent description lines
|
|
58
|
-
*/
|
|
59
|
-
function getAgentsByPacks(packs) {
|
|
60
|
-
const agents = [
|
|
61
|
-
'- **Atlas** (Strategist) — Business analysis + Product management',
|
|
62
|
-
'- **Forge** (Architect-Dev) — Architecture + Development + Documentation',
|
|
63
|
-
'- **Sentinel** (Quality) — QA + UX review',
|
|
64
|
-
'- **Nexus** (Orchestrator) — Sprint management + Autopilot + Parallel execution',
|
|
65
|
-
];
|
|
66
|
-
|
|
67
|
-
if (packs.includes('osint')) {
|
|
68
|
-
agents.push('- **Shadow** (OSINT) — Investigation + Scraping + Psychoprofiling');
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
if (packs.includes('shield')) {
|
|
72
|
-
agents.push('- **Shield** (GRC) — 38 compliance agents (GDPR, ISO 27001, SOC 2, HIPAA, EU AI Act, DORA, NIS2...)');
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
if (packs.includes('maker')) {
|
|
76
|
-
agents.push('- **Maker** (Creator) — Custom agent builder — Create new agents from description');
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
if (packs.includes('dev-studio')) {
|
|
80
|
-
agents.push('- **Miriam** (מרים) — Business Analyst — Strategic analysis, research, product briefs');
|
|
81
|
-
agents.push('- **Huldah** (חולדה) — Technical Writer — Documentation, diagrams, editorial review');
|
|
82
|
-
agents.push('- **Yosef** (יוסף) — Product Manager — PRD, requirements, feature prioritization');
|
|
83
|
-
agents.push('- **Rachel** (רחל) — UX Designer — User experience, wireframes, empathy mapping');
|
|
84
|
-
agents.push('- **Bezalel** (בצלאל) — System Architecture — Architecture, ADRs, epics & stories');
|
|
85
|
-
agents.push('- **Oholiab** (אהליאב) — Senior Engineer — TDD, sprint, code review, implementation');
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
if (packs.includes('memory')) {
|
|
89
|
-
agents.push('- **Zecher** (זכר) — Memory Archivist — Consolidation, project scanning, context recall');
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
return agents;
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
/**
|
|
96
|
-
* Build the Memory Protocol section if the memory pack is installed.
|
|
97
|
-
*
|
|
98
|
-
* @param {string[]} packs - List of installed pack IDs
|
|
99
|
-
* @returns {string} Memory section markdown (empty string if no memory pack)
|
|
100
|
-
*/
|
|
101
|
-
function getMemorySection(packs) {
|
|
102
|
-
if (!packs.includes('memory')) return '';
|
|
103
|
-
return [
|
|
104
|
-
'',
|
|
105
|
-
'## Memory Protocol (Karpathy Guardrails)',
|
|
106
|
-
'',
|
|
107
|
-
'Agents MUST follow these behavioral principles:',
|
|
108
|
-
'',
|
|
109
|
-
'### G1 — Think Before Coding',
|
|
110
|
-
'- State assumptions explicitly. If uncertain, ask.',
|
|
111
|
-
'- Check `.agents/memory/decisions.md` for prior decisions before re-deciding.',
|
|
112
|
-
'',
|
|
113
|
-
'### G2 — Simplicity First',
|
|
114
|
-
'- Minimum code that solves the problem. Nothing speculative.',
|
|
115
|
-
'- Check `.agents/memory/patterns.md` for existing solutions.',
|
|
116
|
-
'',
|
|
117
|
-
'### G3 — Surgical Changes',
|
|
118
|
-
'- Touch only what you must. Match existing style.',
|
|
119
|
-
'- Log surprises in `.agents/memory/lessons.md`.',
|
|
120
|
-
'',
|
|
121
|
-
'### G4 — Goal-Driven Execution',
|
|
122
|
-
'- Define success criteria before implementing.',
|
|
123
|
-
'- Log non-obvious decisions in `.agents/memory/decisions.md`.',
|
|
124
|
-
'',
|
|
125
|
-
'### Memory Files',
|
|
126
|
-
'- `.agents/memory/decisions.md` — Read at session start, write when making decisions',
|
|
127
|
-
'- `.agents/memory/lessons.md` — Write when something unexpected happens',
|
|
128
|
-
'- `.agents/memory/patterns.md` — Write when a reusable pattern is validated',
|
|
129
|
-
'- `.agents/memory/context.md` — Update at session end with project state',
|
|
130
|
-
].join('\n');
|
|
131
|
-
}
|
|
132
|
-
|
|
133
|
-
/**
|
|
134
|
-
* Generate IDE config content with pack-aware agent filtering.
|
|
135
|
-
*
|
|
136
|
-
* @param {string} userName - The user's display name
|
|
137
|
-
* @param {string} language - User-facing communication language
|
|
138
|
-
* @param {string[]} packs - List of installed pack IDs
|
|
139
|
-
* @returns {string} Complete Markdown template
|
|
140
|
-
*/
|
|
141
|
-
function generateIDEConfig(userName, language, packs) {
|
|
142
|
-
const agents = getAgentsByPacks(packs);
|
|
143
|
-
const memorySection = getMemorySection(packs);
|
|
144
|
-
|
|
145
|
-
return `# BMAD+ — AI Agent Configuration
|
|
146
|
-
|
|
147
|
-
## Project Context
|
|
148
|
-
This project uses BMAD+, an augmented AI-driven development framework.
|
|
149
|
-
Based on BMAD-METHOD v6.6.0 with multi-role agents, autopilot mode, and parallel execution.
|
|
150
|
-
|
|
151
|
-
## Agents
|
|
152
|
-
To activate an agent, say its name or persona:
|
|
153
|
-
${agents.join('\n')}
|
|
154
|
-
|
|
155
|
-
## Skills
|
|
156
|
-
- Load skills from \`.agents/skills/\`
|
|
157
|
-
- Each agent has a SKILL.md with capabilities, activation protocol, and role-switching rules
|
|
158
|
-
- Auto-activation triggers: \`.agents/data/role-triggers.yaml\`
|
|
159
|
-
|
|
160
|
-
## Key Commands
|
|
161
|
-
- \`bmad-help\` — Show all available agents and skills
|
|
162
|
-
- \`autopilot\` — Launch Nexus in full pipeline mode
|
|
163
|
-
- \`parallel\` — Enable parallel multi-agent execution
|
|
164
|
-
|
|
165
|
-
## Communication
|
|
166
|
-
- User name: ${userName}
|
|
167
|
-
- Default language: ${language} for user-facing content, English for code and technical docs.
|
|
168
|
-
${memorySection}`;
|
|
169
|
-
}
|
|
170
|
-
|
|
171
|
-
/**
|
|
172
|
-
* Generate a complete CLAUDE.md / GEMINI.md / AGENTS.md config file
|
|
173
|
-
* (all agents, no filtering — backward compatible)
|
|
174
|
-
*
|
|
175
|
-
* @param {string} userName - The user's display name
|
|
176
|
-
* @param {string} language - User-facing communication language
|
|
177
|
-
* @returns {string} Complete Markdown template
|
|
178
|
-
*/
|
|
179
|
-
function generateBaseConfig(userName, language) {
|
|
180
|
-
return `# BMAD+ — AI Agent Configuration
|
|
181
|
-
|
|
182
|
-
## Project Context
|
|
183
|
-
This project uses BMAD+, an augmented AI-driven development framework.
|
|
184
|
-
Based on BMAD-METHOD v6.6.0 with multi-role agents, autopilot mode, and parallel execution.
|
|
185
|
-
|
|
186
|
-
## Agents
|
|
187
|
-
To activate an agent, say its name or persona:
|
|
188
|
-
${AGENT_LIST.join('\n')}
|
|
189
|
-
|
|
190
|
-
## Skills
|
|
191
|
-
- Load skills from \`.agents/skills/\`
|
|
192
|
-
- Each agent has a SKILL.md with capabilities, activation protocol, and role-switching rules
|
|
193
|
-
- Auto-activation triggers: \`.agents/data/role-triggers.yaml\`
|
|
194
|
-
|
|
195
|
-
## Key Commands
|
|
196
|
-
- \`bmad-help\` — Show all available agents and skills
|
|
197
|
-
- \`autopilot\` — Launch Nexus in full pipeline mode
|
|
198
|
-
- \`parallel\` — Enable parallel multi-agent execution
|
|
199
|
-
|
|
200
|
-
## Communication
|
|
201
|
-
- User name: ${userName}
|
|
202
|
-
- Default language: ${language} for user-facing content, English for code and technical docs.
|
|
203
|
-
|
|
204
|
-
## Memory Protocol (Karpathy Guardrails)
|
|
205
|
-
|
|
206
|
-
Agents MUST follow these behavioral principles:
|
|
207
|
-
|
|
208
|
-
### G1 — Think Before Coding
|
|
209
|
-
- State assumptions explicitly. If uncertain, ask.
|
|
210
|
-
- Check \`.agents/memory/decisions.md\` for prior decisions before re-deciding.
|
|
211
|
-
|
|
212
|
-
### G2 — Simplicity First
|
|
213
|
-
- Minimum code that solves the problem. Nothing speculative.
|
|
214
|
-
- Check \`.agents/memory/patterns.md\` for existing solutions.
|
|
215
|
-
|
|
216
|
-
### G3 — Surgical Changes
|
|
217
|
-
- Touch only what you must. Match existing style.
|
|
218
|
-
- Log surprises in \`.agents/memory/lessons.md\`.
|
|
219
|
-
|
|
220
|
-
### G4 — Goal-Driven Execution
|
|
221
|
-
- Define success criteria before implementing.
|
|
222
|
-
- Log non-obvious decisions in \`.agents/memory/decisions.md\`.
|
|
223
|
-
|
|
224
|
-
### Memory Files
|
|
225
|
-
- \`.agents/memory/decisions.md\` — Read at session start, write when making decisions
|
|
226
|
-
- \`.agents/memory/lessons.md\` — Write when something unexpected happens
|
|
227
|
-
- \`.agents/memory/patterns.md\` — Write when a reusable pattern is validated
|
|
228
|
-
- \`.agents/memory/context.md\` — Update at session end with project state`;
|
|
229
|
-
}
|
|
230
|
-
|
|
231
|
-
module.exports = {
|
|
232
|
-
IDE_CONFIGS,
|
|
233
|
-
generateIDEConfig,
|
|
234
|
-
getAgentsByPacks,
|
|
235
|
-
|
|
236
|
-
/**
|
|
237
|
-
* Generate CLAUDE.md config for Claude Code
|
|
238
|
-
* @param {string} userName
|
|
239
|
-
* @param {string} language
|
|
240
|
-
* @returns {string}
|
|
241
|
-
*/
|
|
242
|
-
generateClaudeMD: generateBaseConfig,
|
|
243
|
-
|
|
244
|
-
/**
|
|
245
|
-
* Generate GEMINI.md config for Gemini CLI / Antigravity
|
|
246
|
-
* @param {string} userName
|
|
247
|
-
* @param {string} language
|
|
248
|
-
* @returns {string}
|
|
249
|
-
*/
|
|
250
|
-
generateGeminiMD: generateBaseConfig,
|
|
251
|
-
|
|
252
|
-
/**
|
|
253
|
-
* Generate AGENTS.md config for Codex CLI / OpenCode
|
|
254
|
-
* @param {string} userName
|
|
255
|
-
* @param {string} language
|
|
256
|
-
* @returns {string}
|
|
257
|
-
*/
|
|
258
|
-
generateAgentsMD: generateBaseConfig,
|
|
259
|
-
};
|
|
1
|
+
/**
|
|
2
|
+
* Compatibility entry for IDE metadata. Rendering lives in the registry generator.
|
|
3
|
+
* Author: Laurent Rochetta
|
|
4
|
+
*/
|
|
5
|
+
const adapters = require('../../build/generate-adapters');
|
|
6
|
+
|
|
7
|
+
module.exports = {
|
|
8
|
+
get IDE_CONFIGS() { return adapters.IDE_CONFIGS; },
|
|
9
|
+
buildIDEConfigs: adapters.buildIDEConfigs,
|
|
10
|
+
};
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/** Read the manifest fields used by maintenance commands without unsafe coercion. */
|
|
2
|
+
const fs = require('node:fs');
|
|
3
|
+
|
|
4
|
+
function readInstallManifest(manifestPath) {
|
|
5
|
+
const manifest = JSON.parse(fs.readFileSync(manifestPath, 'utf8'));
|
|
6
|
+
if (!manifest || typeof manifest !== 'object' || Array.isArray(manifest) ||
|
|
7
|
+
typeof manifest.version !== 'string' || !manifest.version.trim() ||
|
|
8
|
+
typeof manifest.installed !== 'string' || !Number.isFinite(Date.parse(manifest.installed)) ||
|
|
9
|
+
!Array.isArray(manifest.packs) || manifest.packs.length === 0 ||
|
|
10
|
+
manifest.packs.some(pack => typeof pack !== 'string' || !/^[a-z0-9-]+$/.test(pack)) ||
|
|
11
|
+
(manifest.uiLanguage !== undefined && typeof manifest.uiLanguage !== 'string')) {
|
|
12
|
+
throw new Error('Expected version, installed date, and a nonempty array of pack IDs.');
|
|
13
|
+
}
|
|
14
|
+
return manifest;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
module.exports = { readInstallManifest };
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
/** Installed adapter ownership shared by install, update, and uninstall. */
|
|
2
|
+
const fs = require('node:fs');
|
|
3
|
+
const path = require('node:path');
|
|
4
|
+
const crypto = require('node:crypto');
|
|
5
|
+
const clack = require('@clack/prompts');
|
|
6
|
+
const { GENERATED_MARKER, USER_CONFIG_MARKER } = require('../../build/generate-adapters');
|
|
7
|
+
|
|
8
|
+
const INSTALLER_MARKER = 'BMAD+ \u2014 AI Agent Configuration';
|
|
9
|
+
const contentHash = content => crypto.createHash('sha256').update(String(content).replace(/\r\n/g, '\n')).digest('hex');
|
|
10
|
+
|
|
11
|
+
function classifyAdapter({ existing, content, previousHash, update = false, yes = false }) {
|
|
12
|
+
if (existing === undefined) return { action: 'write', backup: false };
|
|
13
|
+
const installed = existing.includes(USER_CONFIG_MARKER);
|
|
14
|
+
const adopted = existing.includes(GENERATED_MARKER) && !installed;
|
|
15
|
+
const legacy = existing.includes(INSTALLER_MARKER) && !existing.includes(GENERATED_MARKER);
|
|
16
|
+
if (installed && existing === content) return { action: 'same', backup: false };
|
|
17
|
+
const unchanged = installed && previousHash === contentHash(existing);
|
|
18
|
+
if (adopted || (installed && !unchanged) || (!installed && !legacy && (update || !yes))) {
|
|
19
|
+
return { action: 'preserve', backup: false, adopted, installed, reason: adopted ? 'repository-adopted' : 'local-instructions' };
|
|
20
|
+
}
|
|
21
|
+
return { action: 'write', backup: legacy || (!installed && yes), legacy };
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
// Refuse redirected parent directories as well as linked destination files.
|
|
25
|
+
function safeAdapterPath(projectDir, file) {
|
|
26
|
+
const root = path.resolve(projectDir);
|
|
27
|
+
const target = path.resolve(root, file);
|
|
28
|
+
const relative = path.relative(root, target);
|
|
29
|
+
if (!relative || relative === '..' || relative.startsWith('..' + path.sep) || path.isAbsolute(relative)) {
|
|
30
|
+
throw new Error('Adapter path outside project: ' + file);
|
|
31
|
+
}
|
|
32
|
+
let current = root;
|
|
33
|
+
for (const part of relative.split(path.sep)) {
|
|
34
|
+
current = path.join(current, part);
|
|
35
|
+
try {
|
|
36
|
+
if (fs.lstatSync(current).isSymbolicLink()) throw new Error('Adapter path is a symbolic link or junction: ' + current);
|
|
37
|
+
} catch (err) {
|
|
38
|
+
if (err.code !== 'ENOENT') throw err;
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
return target;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
function writeIDEConfigs({ projectDir, files, yes = false, update = false, adapterHashes = {} }) {
|
|
45
|
+
const outcome = { written: [], skipped: [], backedUp: [], adapterHashes: {} };
|
|
46
|
+
// Preflight the complete set before writing any adapter.
|
|
47
|
+
for (const { file } of files) safeAdapterPath(projectDir, file);
|
|
48
|
+
for (const { file, content } of files) {
|
|
49
|
+
const target = safeAdapterPath(projectDir, file);
|
|
50
|
+
const previousHash = Object.hasOwn(adapterHashes, file) ? adapterHashes[file] : undefined;
|
|
51
|
+
let backup = false;
|
|
52
|
+
if (fs.existsSync(target)) {
|
|
53
|
+
const existing = fs.readFileSync(target, 'utf8');
|
|
54
|
+
const decision = classifyAdapter({ existing, content, previousHash, update, yes });
|
|
55
|
+
if (decision.action === 'same') {
|
|
56
|
+
outcome.adapterHashes[file] = contentHash(content);
|
|
57
|
+
continue;
|
|
58
|
+
}
|
|
59
|
+
if (decision.action === 'preserve') {
|
|
60
|
+
if (previousHash && decision.installed) outcome.adapterHashes[file] = previousHash;
|
|
61
|
+
outcome.skipped.push(file);
|
|
62
|
+
const compare = decision.adopted
|
|
63
|
+
? ` Compare package defaults: node "${require.resolve('../../build/generate-adapters')}" --target "${path.resolve(projectDir)}" --check`
|
|
64
|
+
: '';
|
|
65
|
+
clack.log.warn(`${file}: existing project instructions preserved.${compare}`);
|
|
66
|
+
continue;
|
|
67
|
+
}
|
|
68
|
+
// Older installers did not record hashes. Keep their exact bytes before
|
|
69
|
+
// migration, including any local additions that cannot be distinguished.
|
|
70
|
+
backup = decision.backup;
|
|
71
|
+
}
|
|
72
|
+
if (backup) {
|
|
73
|
+
let suffix = '.bak';
|
|
74
|
+
let index = 1;
|
|
75
|
+
while (fs.existsSync(safeAdapterPath(projectDir, file + suffix))) suffix = `.bak.${index++}`;
|
|
76
|
+
fs.copyFileSync(target, safeAdapterPath(projectDir, file + suffix), fs.constants.COPYFILE_EXCL);
|
|
77
|
+
outcome.backedUp.push(file);
|
|
78
|
+
clack.log.warn(`${file}: backed up to ${file + suffix} before refreshing.`);
|
|
79
|
+
}
|
|
80
|
+
fs.mkdirSync(path.dirname(target), { recursive: true });
|
|
81
|
+
safeAdapterPath(projectDir, file);
|
|
82
|
+
fs.writeFileSync(target, content, 'utf8');
|
|
83
|
+
outcome.written.push(file);
|
|
84
|
+
outcome.adapterHashes[file] = contentHash(content);
|
|
85
|
+
}
|
|
86
|
+
return outcome;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
module.exports = { INSTALLER_MARKER, contentHash, safeAdapterPath, writeIDEConfigs, classifyAdapter };
|