wendkeep 0.58.1 → 0.59.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.
Files changed (78) hide show
  1. package/CHANGELOG.md +120 -0
  2. package/README.en.md +70 -40
  3. package/README.md +70 -40
  4. package/bin/wendkeep.mjs +54 -6
  5. package/docs/en/commands/changes-and-verification.md +85 -0
  6. package/docs/en/commands/costs-and-observability.md +65 -0
  7. package/docs/en/commands/getting-started.md +86 -0
  8. package/docs/en/commands/maintenance-and-diagnostics.md +77 -0
  9. package/docs/en/commands/memory-migration.md +73 -0
  10. package/docs/en/commands/memory.md +102 -0
  11. package/docs/en/commands/notes-and-knowledge.md +70 -0
  12. package/docs/en/commands/operating-profiles.md +173 -0
  13. package/docs/en/commands/retroactive-import.md +67 -0
  14. package/docs/en/commands/sessions-and-import.md +89 -0
  15. package/docs/en/commands/verify.md +92 -0
  16. package/docs/pt-BR/commands/changes-and-verification.md +85 -0
  17. package/docs/pt-BR/commands/costs-and-observability.md +65 -0
  18. package/docs/pt-BR/commands/getting-started.md +87 -0
  19. package/docs/pt-BR/commands/maintenance-and-diagnostics.md +77 -0
  20. package/docs/pt-BR/commands/memory-migration.md +73 -0
  21. package/docs/pt-BR/commands/memory.md +99 -0
  22. package/docs/pt-BR/commands/notes-and-knowledge.md +69 -0
  23. package/docs/pt-BR/commands/operating-profiles.md +171 -0
  24. package/docs/pt-BR/commands/retroactive-import.md +67 -0
  25. package/docs/pt-BR/commands/sessions-and-import.md +89 -0
  26. package/docs/pt-BR/commands/verify.md +93 -0
  27. package/hooks/brain-core.mjs +159 -159
  28. package/hooks/brain-inject.mjs +83 -26
  29. package/hooks/brain-recall.mjs +32 -32
  30. package/hooks/brain-reindex.mjs +13 -13
  31. package/hooks/change-context.mjs +24 -10
  32. package/hooks/change-core.mjs +174 -37
  33. package/hooks/change-guard.mjs +115 -16
  34. package/hooks/change-nag.mjs +20 -5
  35. package/hooks/change-warn.mjs +27 -9
  36. package/hooks/decision-capture.mjs +1 -1
  37. package/hooks/derived-sections.mjs +1 -1
  38. package/hooks/flow-core.mjs +891 -0
  39. package/hooks/flow-protected-policy.mjs +218 -0
  40. package/hooks/frontmatter-repair.mjs +3 -1
  41. package/hooks/git-snapshot.mjs +722 -0
  42. package/hooks/import-sessions.mjs +10 -5
  43. package/hooks/memory-mode.mjs +63 -13
  44. package/hooks/memory-store.mjs +309 -69
  45. package/hooks/obsidian-common.mjs +119 -84
  46. package/hooks/operating-profile-runtime.mjs +157 -0
  47. package/hooks/plan-capture.mjs +14 -3
  48. package/hooks/sensors-core.mjs +15 -3
  49. package/hooks/session-backfill.mjs +7 -2
  50. package/hooks/session-ensure.mjs +21 -12
  51. package/hooks/session-iteration.mjs +65 -0
  52. package/hooks/session-memory-lifecycle.mjs +335 -0
  53. package/hooks/session-note-io.mjs +130 -15
  54. package/hooks/session-observability.mjs +4 -2
  55. package/hooks/session-stop.mjs +181 -59
  56. package/hooks/spec-core.mjs +91 -12
  57. package/hooks/subagent-stop.mjs +4 -1
  58. package/hooks/subagent-usage.mjs +2 -2
  59. package/hooks/task-log.mjs +3 -1
  60. package/hooks/token-usage.mjs +1 -1
  61. package/hooks/vault-health.mjs +268 -25
  62. package/hooks/vault-path-safety.mjs +558 -0
  63. package/hooks/vault-runtime-store.mjs +558 -0
  64. package/package.json +5 -3
  65. package/src/change.mjs +2 -1
  66. package/src/flow.mjs +232 -0
  67. package/src/init.mjs +26 -3
  68. package/src/memory.mjs +785 -35
  69. package/src/operating-profile.mjs +133 -0
  70. package/src/profile.mjs +224 -0
  71. package/src/project-vault.mjs +110 -5
  72. package/src/rebuild-costs.mjs +11 -4
  73. package/src/skills-seed.mjs +38 -16
  74. package/src/sync-defs.mjs +16 -7
  75. package/src/sync.mjs +9 -1
  76. package/src/taxonomy.mjs +9 -0
  77. package/src/validate-memory.mjs +21 -8
  78. package/src/verify.mjs +12 -2
package/bin/wendkeep.mjs CHANGED
@@ -22,12 +22,13 @@ function version() {
22
22
  }
23
23
  }
24
24
 
25
- const HELP = `wendkeep ${version()} — capture AI coding agent sessions into your Obsidian vault.
25
+ const HELP = `wendkeep ${version()} — keep durable AI sessions in an Obsidian vault, with optional governance.
26
26
 
27
27
  Usage:
28
28
  wendkeep init [options] Set up wendkeep in a project (cross-platform).
29
29
  --vault <path> Obsidian vault folder (default: <project>/.<project-name>-vault).
30
30
  --project <path> Project root to wire (default: current directory).
31
+ --profile <name> Operating profile: OFF, FLOW, GUIDE, GOVERN (default), or ASSURE.
31
32
  --no-mcp Do not add the mcpvault MCP server to .mcp.json.
32
33
  --companions <csv> Companion plugins/MCP to pin: context-mode,caveman,understand-anything
33
34
  (default: none — opt in explicitly). dotcontext is legacy — the native a2 loop replaces it.
@@ -46,7 +47,7 @@ Usage:
46
47
  command — the three steps that repeat identically after every
47
48
  package update. Stops at the first failing step. Install the
48
49
  package first (npm i -D wendkeep@latest); a running process
49
- cannot replace itself. · --vault P · --yes.
50
+ cannot replace itself. · --vault P · --profile <name> · --yes.
50
51
 
51
52
  wendkeep doctor [--vault P] Run a vault health check.
52
53
  wendkeep change <sub> Change lifecycle: new [--simple] | use | bind <slug> --session <id> | continue | list | show |
@@ -56,6 +57,11 @@ Usage:
56
57
  wendkeep theme sync Re-aplica o color system (snippet CSS + graph color groups) num vault
57
58
  existente — recupera o grafo cinza sem re-init. --vault P.
58
59
  wendkeep session <sub> Session registry: list | show <id> | use <id>.
60
+ wendkeep profile <sub> Operating profile: status | use <OFF|FLOW|GUIDE|GOVERN|ASSURE>.
61
+ --session <id> sets an audited session override; otherwise changes
62
+ the project default. The Vault/session/memory core is always active.
63
+ wendkeep flow <sub> Low-ceremony E -> V contract: start | status | show | finish | promote.
64
+ FLOW records scope, sensors and a receipt without creating a change.
59
65
  wendkeep spec <sub> Specs: list | show | effective [--change] [--json] | migrate | rebase.
60
66
  wendkeep sensors <sub> list | add <id> "<command>" [--severity --type --report].
61
67
  wendkeep cost [opts] Aggregate AI-coding spend across the vault's sessions.
@@ -95,7 +101,9 @@ Usage:
95
101
  behind the closing block. Dry-run by default · --apply · --json.
96
102
  wendkeep lesson add "t" "l" Record a project-local lesson (injected at SessionStart).
97
103
  wendkeep memory <sub> Shared memory v2: status | migrate [--apply] | repair |
104
+ reconcile <session> --by-session <session> --reason <text> [--apply] |
98
105
  promote <candidate> | reject <candidate>. --vault P.
106
+ Reconcile is dry-run by default; the original attempt remains audited.
99
107
  wendkeep validate-memory [path] Validate .brain/CORE.md against the compaction
100
108
  protocol (cap 25, 3 sections, no secrets/PII).
101
109
  --vault <path> validates the complete v2 bundle.
@@ -142,11 +150,25 @@ async function preferProjectVault(argv) {
142
150
  if (optionValue(argv, '--vault')) return;
143
151
  try {
144
152
  const { resolveProjectVault } = await import('../src/project-vault.mjs');
153
+ // A sensor may itself invoke WendKeep. `verify`/`flow finish` already selected the
154
+ // authoritative Vault explicitly, so preserve that choice across the child process
155
+ // instead of letting the sensor cwd's project binding redirect it.
156
+ const sensorVault = process.env.WENDKEEP_SENSOR_VAULT;
157
+ if (sensorVault) {
158
+ const selected = resolveProjectVault({
159
+ startDir: optionValue(argv, '--project') || process.cwd(),
160
+ explicitVault: sensorVault,
161
+ });
162
+ process.env.OBSIDIAN_VAULT_PATH = selected.base;
163
+ return;
164
+ }
145
165
  const resolved = resolveProjectVault({ startDir: optionValue(argv, '--project') || process.cwd() });
146
166
  process.env.OBSIDIAN_VAULT_PATH = resolved.base;
147
- } catch {
167
+ } catch (error) {
148
168
  // Backward-compatible manual CLI behavior: individual commands still explain
149
- // --vault / legacy env when no project binding exists. Hooks do not use this path.
169
+ // --vault / legacy env only when no project binding exists. A configured but
170
+ // corrupt/missing/mismatched binding must abort before dispatch to another Vault.
171
+ if (error?.code !== 'WENDKEEP_VAULT_UNCONFIGURED') throw error;
150
172
  }
151
173
  }
152
174
 
@@ -156,10 +178,26 @@ async function main() {
156
178
  // Intercepted BEFORE vault resolution so it works anywhere — help must never depend
157
179
  // on project state, and no command may treat --help as a runnable default.
158
180
  if (cmd && (rest.includes('--help') || rest.includes('-h'))) {
159
- process.stdout.write(HELP);
181
+ if (cmd === 'flow') {
182
+ const { FLOW_HELP } = await import('../src/flow.mjs');
183
+ process.stdout.write(FLOW_HELP);
184
+ } else if (cmd === 'profile') {
185
+ const { PROFILE_HELP } = await import('../src/profile.mjs');
186
+ process.stdout.write(PROFILE_HELP);
187
+ } else {
188
+ process.stdout.write(HELP);
189
+ }
160
190
  process.exit(0);
161
191
  }
162
- if (cmd && !['init', 'hook', '--version', '-v', '--help', '-h', 'help'].includes(cmd)) {
192
+ const validatesStandaloneCore = cmd === 'validate-memory'
193
+ && !rest.includes('--vault')
194
+ && !rest.some((item) => item.startsWith('--vault='));
195
+ if (cmd
196
+ && !validatesStandaloneCore
197
+ // `sync` starts with `init` and resolves the freshly bound Vault itself. Pre-resolving
198
+ // here would prevent that repair step from reporting a corrupt binding as its own
199
+ // first-stage failure (and could never make it as far as the guarded init).
200
+ && !['init', 'sync', 'hook', '--version', '-v', '--help', '-h', 'help'].includes(cmd)) {
163
201
  await preferProjectVault(rest);
164
202
  }
165
203
  switch (cmd) {
@@ -211,6 +249,16 @@ async function main() {
211
249
  runSession(rest);
212
250
  break;
213
251
  }
252
+ case 'profile': {
253
+ const { runProfile } = await import('../src/profile.mjs');
254
+ process.exit(runProfile(rest));
255
+ break;
256
+ }
257
+ case 'flow': {
258
+ const { runFlow } = await import('../src/flow.mjs');
259
+ process.exit(await runFlow(rest));
260
+ break;
261
+ }
214
262
  case 'theme': {
215
263
  const { runTheme } = await import('../src/theme.mjs');
216
264
  runTheme(rest);
@@ -0,0 +1,85 @@
1
+ # Changes, specs, sensors, and archive
2
+
3
+ **English** · [Português](../../pt-BR/commands/changes-and-verification.md)
4
+
5
+ ## Purpose
6
+
7
+ Carry a change from recorded intent to an archived decision, linking requirements, tasks,
8
+ sensors, evidence, and verdict in the vault graph.
9
+
10
+ ## When to use
11
+
12
+ Use for any non-trivial implementation or fix that must leave auditable proof.
13
+
14
+ ## When not to use
15
+
16
+ Do not create a change merely to inspect health, import sessions, or run read-only maintenance.
17
+ For local maintenance eligible for the `FLOW` profile, use the microcontract in
18
+ [Operating profiles](operating-profiles.md); under `OFF`, the lifecycle remains available but is
19
+ not imposed by Wend Runtime.
20
+
21
+ ## Prerequisites
22
+
23
+ Initialize the project, keep the vault healthy, and provide a valid `wendkeep.sensors.json`.
24
+
25
+ ## Syntax
26
+
27
+ ```bash
28
+ npx wendkeep change new <slug>
29
+ npx wendkeep change status [slug]
30
+ npx wendkeep spec effective --change <slug>
31
+ npx wendkeep sensors list
32
+ npx wendkeep verify [--deep] [--change <slug>]
33
+ npx wendkeep change archive <slug>
34
+ ```
35
+
36
+ ## Options and exit codes
37
+
38
+ - `wendkeep change new <slug> [--simple]` creates a change; `--simple` only skips design, is not
39
+ `FLOW`, and preserves the legacy lifecycle/ADR contract.
40
+ - `change use`, `list`, `show`, `status`, `diff`, `done`, and `undone` inspect or update work
41
+ without archiving it.
42
+ - `change continue <archived> <new>` starts follow-up work without inheriting stale proof.
43
+ - `change bind <slug> --session <id>` attaches an existing session.
44
+ - `change relink [--apply]` and `change backlink [--apply]` repair graph links; preview is default.
45
+ - `change abandon <slug>` drops work without an ADR; `archive --force` needs explicit human choice.
46
+ - `wendkeep spec list|show|effective|migrate|rebase` manages living contracts and deltas.
47
+ - `wendkeep sensors list|add` manages executable proof.
48
+ - Exit `0` means completion; gates use exit `1` for red proof and exit `2` for invalid
49
+ context/usage.
50
+
51
+ ## Examples
52
+
53
+ ```bash
54
+ npx wendkeep change new tenant-login
55
+ npx wendkeep spec effective --change tenant-login
56
+ npx wendkeep change done 1.1 --change tenant-login
57
+ npx wendkeep verify --change tenant-login
58
+ npx wendkeep verify --deep --change tenant-login
59
+ npx wendkeep change archive tenant-login
60
+ ```
61
+
62
+ Add a sensor:
63
+
64
+ ```bash
65
+ npx wendkeep sensors add api-contracts "npm run test:contracts" --severity critical
66
+ ```
67
+
68
+ ## Expected result
69
+
70
+ An archived change promotes its delta into the living spec, preserves proposal/design/tasks/proof,
71
+ and mints an ADR. Archive passes only with closed tasks, green required sensors, and a fresh verdict.
72
+
73
+ ## Common errors and diagnosis
74
+
75
+ - `no change`: select one with `change use <slug>` or pass `--change`.
76
+ - `spec_impact: pending`: choose `required` with a delta or `none` with a real reason.
77
+ - Sensor not executed: keep one or more `[sensor:id]` tags on the same checkbox line. Every
78
+ distinct ID on that line is required and runs once, in declaration order.
79
+ - Stale evidence: rerun `verify` and `verify --deep` after task/spec edits.
80
+ - Rebase conflict: resolve the delta or use `--accept-current` only when that is the decision.
81
+
82
+ ## Next steps
83
+
84
+ Read [Operating profiles](operating-profiles.md), the deep [verify guide](verify.md), and
85
+ [maintenance and diagnostics](maintenance-and-diagnostics.md).
@@ -0,0 +1,65 @@
1
+ # Costs and observability
2
+
3
+ **English** · [Português](../../pt-BR/commands/costs-and-observability.md)
4
+
5
+ ## Purpose
6
+
7
+ Measure sessions, prompts, models, and AI spend, and rebuild historical costs from canonical
8
+ transcripts when required.
9
+
10
+ ## When to use
11
+
12
+ Use `stats` for a quick view, `cost` for analysis, and `cost rebuild` when older notes lack
13
+ trustworthy costs.
14
+
15
+ ## When not to use
16
+
17
+ Do not apply rebuild before validating each session's provider and transcript. Do not compare
18
+ projects whose registries are mixed.
19
+
20
+ ## Prerequisites
21
+
22
+ A consistent registry, complete price table, and transcript access for rebuilt sessions.
23
+
24
+ ## Syntax
25
+
26
+ ```bash
27
+ npx wendkeep stats [--vault <vault>] [--json]
28
+ npx wendkeep cost [--since <date>] [--top [N]] [--trend day|week|month] [--write] [--json]
29
+ npx wendkeep cost rebuild [--session <id|file>] [--limit N] [--apply] [--json]
30
+ ```
31
+
32
+ ## Options and exit codes
33
+
34
+ - `wendkeep stats` emits one shareable line or JSON.
35
+ - `wendkeep cost` aggregates total/model/day; `--trend` adds projection and `--write` refreshes
36
+ `00-Custo.md`.
37
+ - `wendkeep cost rebuild` is dry-run by default; `--apply` writes notes and
38
+ `.brain/COST_REBUILD.json`.
39
+ - Exit `0` means a consistent calculation; non-zero reports insufficient registry, price,
40
+ transcript, or parsing state.
41
+
42
+ ## Examples
43
+
44
+ ```bash
45
+ npx wendkeep stats --vault .MyApp-vault
46
+ npx wendkeep cost --since 2026-07-01 --top 10 --trend week
47
+ npx wendkeep cost rebuild --session 019abc --json
48
+ ```
49
+
50
+ ## Expected result
51
+
52
+ Totals retain input/output/cache/reasoning dimensions by model and period. Rebuild shows a preview
53
+ before changing notes and leaves a reproducible report when applied.
54
+
55
+ ## Common errors and diagnosis
56
+
57
+ - Model without a price: update the table before accepting totals.
58
+ - Wrong-provider costs: validate the session identity chain.
59
+ - Missing transcript: do not estimate silently; keep the gap visible.
60
+ - Duplicated parent/subagent/fork totals: verify registry relationships and deduplication.
61
+
62
+ ## Next steps
63
+
64
+ See [sessions and import](sessions-and-import.md), [retroactive import](retroactive-import.md), and
65
+ [maintenance](maintenance-and-diagnostics.md).
@@ -0,0 +1,86 @@
1
+ # Installation and first use
2
+
3
+ **English** · [Português](../../pt-BR/commands/getting-started.md)
4
+
5
+ ## Purpose
6
+
7
+ Install WendKeep, bind the project to the correct vault, and enable capture, memory, and skills
8
+ without overwriting existing configuration.
9
+
10
+ ## When to use
11
+
12
+ Use `wendkeep init` for the first installation and `wendkeep sync` after updating the package.
13
+
14
+ ## When not to use
15
+
16
+ Do not run `init --force` as a generic repair for memory or unreadable configuration. Run
17
+ `wendkeep doctor` first and follow the repair command it reports.
18
+
19
+ ## Prerequisites
20
+
21
+ - Node.js 18 or newer.
22
+ - A local project and write access to the vault.
23
+ - Claude Code or Codex; Obsidian is optional at runtime and recommended for graph navigation.
24
+
25
+ ## Syntax
26
+
27
+ ```bash
28
+ npm install --save-dev wendkeep
29
+ npx wendkeep init [options]
30
+ npx wendkeep sync [--project <root>] [--vault <vault>] [--profile <profile>] [--yes]
31
+ ```
32
+
33
+ ## Options and exit codes
34
+
35
+ - `--vault <path>` selects the vault; otherwise the local `.wendkeep.json` binding wins.
36
+ - `--project <path>` selects the project root.
37
+ - `--profile <OFF|FLOW|GUIDE|GOVERN|ASSURE>` selects the Operating Profile; new installs use
38
+ `GOVERN`, re-init/sync without the flag preserves the existing choice, and `OFF` is never inferred.
39
+ - `--no-mcp`, `--no-colors`, and `--no-companions` disable optional integrations.
40
+ - `--companions <csv>` explicitly enables companion integrations.
41
+ - `--yes` accepts non-interactive defaults; `--force` refreshes managed blocks only.
42
+ - Exit `0` means setup/sync completed. Any other exit identifies the failed stage. `sync` stops at
43
+ `init`, `sync-defs`, or `doctor` instead of hiding the error.
44
+ - `sync` does not pre-resolve the Vault before `init`: an invalid binding fails closed at that first
45
+ stage, and only a validated binding reaches `sync-defs` and `doctor`; no global fallback is used.
46
+
47
+ ## Examples
48
+
49
+ First installation in the current project:
50
+
51
+ ```bash
52
+ npm install --save-dev wendkeep
53
+ npx wendkeep init --profile GOVERN --no-companions
54
+ ```
55
+
56
+ Later update:
57
+
58
+ ```bash
59
+ npm install --save-dev wendkeep@latest
60
+ npx wendkeep sync --yes
61
+ ```
62
+
63
+ With pnpm, pin a concrete version because minimum-release-age policies may keep `latest` silently
64
+ behind:
65
+
66
+ ```bash
67
+ pnpm add -D wendkeep@X.Y.Z --config.minimumReleaseAge=0
68
+ pnpm exec wendkeep sync --yes
69
+ ```
70
+
71
+ ## Expected result
72
+
73
+ The project receives `.wendkeep.json`, managed Claude/Codex hooks, skill definitions, and an
74
+ initialized vault. Existing files are merged or preserved, and the selected vault is printed.
75
+
76
+ ## Common errors and diagnosis
77
+
78
+ - Wrong vault: inspect `.wendkeep.json` and run `wendkeep doctor --vault <path>`.
79
+ - Codex hooks do not run: approve **Hooks need review** on the next startup.
80
+ - `defs stale`: run `wendkeep sync-defs --reseed`, then restart the agents.
81
+ - `sync` stops at doctor: read the failing section; do not retry with `--force` blindly.
82
+
83
+ ## Next steps
84
+
85
+ Continue with [maintenance and diagnostics](maintenance-and-diagnostics.md),
86
+ [sessions and import](sessions-and-import.md), and [shared memory](memory.md).
@@ -0,0 +1,77 @@
1
+ # Maintenance and diagnostics
2
+
3
+ **English** · [Português](../../pt-BR/commands/maintenance-and-diagnostics.md)
4
+
5
+ ## Purpose
6
+
7
+ Inspect vault health and keep definitions, theme, and package version aligned without treating
8
+ change commands as global checks.
9
+
10
+ ## When to use
11
+
12
+ Use after install/update, when hooks emit warnings, or before starting a change.
13
+
14
+ ## When not to use
15
+
16
+ Do not run `wendkeep verify` when no change is active. It proves a change's tasks; it is not a
17
+ replacement for doctor.
18
+
19
+ ## Prerequisites
20
+
21
+ Run from the project root or provide `--project` and `--vault` explicitly.
22
+
23
+ ## Syntax
24
+
25
+ ```bash
26
+ npx wendkeep doctor [--vault <vault>]
27
+ npx wendkeep sync-defs [--check|--reseed] --vault <vault> --project <root>
28
+ npx wendkeep theme sync --vault <vault>
29
+ npx wendkeep --version
30
+ npx wendkeep --help
31
+ ```
32
+
33
+ ## Options and exit codes
34
+
35
+ - `doctor` is read-only; exit `0` accepts recoverable warnings, while non-zero means failure.
36
+ - In v2, `doctor`/`memory status --gate` correlate `last_memory_attempt` (mode, disposition, event
37
+ IDs, and checkpoint) with outbox, ledger, and SHARED; they do not infer health from revision alone.
38
+ - `revision: 0` after a valid migration, with no v2 attempt, is healthy. A `degraded` attempt whose
39
+ events remain durable in the outbox/ledger is a recoverable warning.
40
+ - An ambiguous attempt, a lost event ID (absent from ledger and outbox), `projected` state found
41
+ only in the outbox, or a mismatched checkpoint is blocking.
42
+ - `sync-defs --check` detects drift without writes; `--reseed` restores packaged `wk-*` skills.
43
+ - `theme sync` reapplies the CSS snippet and graph groups without recreating the vault.
44
+ - `wendkeep --version` prints the running version; `wendkeep --help` lists the public interface.
45
+
46
+ ## Examples
47
+
48
+ Post-update checklist:
49
+
50
+ ```bash
51
+ npx wendkeep --version
52
+ npx wendkeep sync-defs --check --vault .MyApp-vault --project .
53
+ npx wendkeep doctor --vault .MyApp-vault
54
+ npx wendkeep memory status --gate --vault .MyApp-vault
55
+ ```
56
+
57
+ ## Expected result
58
+
59
+ Doctor names sessions, registry, links, notes, prices, derived sections, and memory as healthy or
60
+ provides a specific diagnostic/repair command. For memory, it distinguishes a valid initial empty
61
+ state, recoverable pending replay, and lost/divergent lifecycle state. It never repairs implicitly
62
+ or echoes private projector-error content into its report.
63
+
64
+ ## Common errors and diagnosis
65
+
66
+ - `no vault`: run from the bound root or pass `--vault`.
67
+ - `defs stale`: confirm the version and run `sync-defs --reseed`.
68
+ - Legacy vault: this is a non-blocking warning; plan `memory migrate --apply` separately.
69
+ - `degraded` plus an intact outbox: warning; preserve the outbox and allow idempotent replay.
70
+ - `ambiguous`, lost publication, or a mismatched checkpoint: blocking; preserve registry, ledger,
71
+ outbox, and SHARED so `last_memory_attempt` can be correlated before repair.
72
+ - Corrupt bundle: preserve evidence and run `memory status --gate` before `memory repair`.
73
+
74
+ ## Next steps
75
+
76
+ See [installation and first use](getting-started.md), [memory](memory.md), and
77
+ [change verification](verify.md).
@@ -0,0 +1,73 @@
1
+ # Legacy-to-v2 memory migration
2
+
3
+ **English** · [Português](../../pt-BR/commands/memory-migration.md)
4
+
5
+ ## Purpose
6
+
7
+ Convert a legacy `SHARED_MEMORY.md` into an auditable v2 bundle without overwriting CORE or
8
+ silently promoting old reports.
9
+
10
+ ## When to use
11
+
12
+ Use when `memory status` reports `legacy` and the team is ready to curate converted content.
13
+
14
+ ## When not to use
15
+
16
+ Do not migrate automatically during `init`, `sync`, SessionStop, or merely to silence a warning.
17
+ Do not apply until the backup and expected state are understood.
18
+
19
+ ## Prerequisites
20
+
21
+ - Valid CORE and preserved legacy bytes.
22
+ - No partially corrupt v2 bundle.
23
+ - Human review of the candidates that will be created.
24
+
25
+ ## Syntax
26
+
27
+ ```bash
28
+ npx wendkeep memory status --gate --vault <vault>
29
+ npx wendkeep memory migrate --vault <vault>
30
+ npx wendkeep memory migrate --apply --vault <vault>
31
+ ```
32
+
33
+ ## Options and exit codes
34
+
35
+ - Without `--apply`, `wendkeep memory migrate` is a zero-write dry run.
36
+ - `--apply` creates a backup, converts legacy content into candidates, and publishes valid v2.
37
+ - A newly migrated bundle may start healthy at `revision: 0`: no v2 attempt or eligible event has
38
+ happened yet, so zero does not mean the lifecycle is stalled.
39
+ - Exit `0` means a consistent preview/application; non-zero preserves original state and reports
40
+ the failure.
41
+
42
+ ## Examples
43
+
44
+ ```bash
45
+ npx wendkeep memory migrate --vault .MyApp-vault
46
+ # review the preview
47
+ npx wendkeep memory migrate --apply --vault .MyApp-vault
48
+ npx wendkeep memory status --gate --vault .MyApp-vault
49
+ ```
50
+
51
+ ## Expected result
52
+
53
+ The vault receives a coherent v2 ledger/projection, a backup of legacy SHARED, and candidates for
54
+ unsupported facts. CORE is untouched and unverified content is not activated automatically.
55
+ After migration, the next `UserPromptSubmit` opens exactly one recovery activation when the
56
+ legacy registry was closed; the first transcript-proven `Stop` publishes once and advances SHARED
57
+ to revision 1. Replaying that prompt or Stop does not duplicate the event/revision.
58
+
59
+ ## Common errors and diagnosis
60
+
61
+ - Dry run says already v2: do not apply again.
62
+ - `revision: 0` immediately after a valid apply: this is healthy; wait for an eligible prompt and
63
+ Stop instead of repairing or repeating migration.
64
+ - Partial/corrupt v2 bundle: use status and repair; migration is not a corruption tool.
65
+ - First post-migration Stop is `ambiguous`: verify that its `turn_id` belongs to the transcript and
66
+ that `UserPromptSubmit` opened/advanced the recovery activation.
67
+ - Many candidates: curate gradually with `memory promote`/`memory reject`.
68
+ - Legacy warning remains after apply: verify the selected vault and project binding.
69
+
70
+ ## Next steps
71
+
72
+ Return to [memory and curation](memory.md) and run
73
+ [maintenance and diagnostics](maintenance-and-diagnostics.md).
@@ -0,0 +1,102 @@
1
+ # Shared memory and curation
2
+
3
+ **English** · [Português](../../pt-BR/commands/memory.md)
4
+
5
+ ## Purpose
6
+
7
+ Inspect and curate CORE, SHARED, ledger, outbox, attempts, and candidates without confusing
8
+ canonical authorship with generated operational state.
9
+
10
+ ## When to use
11
+
12
+ Use in CI, before verify/archive, after doctor warnings, or when deciding candidates.
13
+
14
+ ## When not to use
15
+
16
+ Do not hand-edit `SHARED_MEMORY.md` or `MEMORY_EVENTS.jsonl`. Do not repair a healthy legacy vault
17
+ that merely awaits migration.
18
+
19
+ ## Prerequisites
20
+
21
+ Pass the vault explicitly in automation. Preserve backups and evidence before repair.
22
+
23
+ ## Syntax
24
+
25
+ ```bash
26
+ npx wendkeep memory status [--gate] --vault <vault>
27
+ npx wendkeep memory repair --vault <vault>
28
+ npx wendkeep memory reconcile <ambiguous-session> --by-session <successor-session> --reason <reason> [--apply] --vault <vault>
29
+ npx wendkeep memory promote <candidate> --vault <vault>
30
+ npx wendkeep memory reject <candidate> --vault <vault>
31
+ npx wendkeep validate-memory [CORE-path]
32
+ npx wendkeep validate-memory --vault <v2-vault>
33
+ ```
34
+
35
+ ## Options and exit codes
36
+
37
+ - `memory status` is read-only; `--gate` exits `1` only for blocking state.
38
+ - `Stop` writes events to the outbox before acknowledging `last_memory_attempt: enqueued`, then the
39
+ projector runs outside the registry lock. Retrying the same attempt reuses its frozen event IDs
40
+ and can project them at most once.
41
+ - A busy/failed projector persists `degraded`, preserves the outbox, and reports replay. A later
42
+ Stop/retry reuses that attempt instead of rebuilding its handoff from new transient data.
43
+ - The outcome updates `memory_status`/checkpoint only while activation, epoch, turn, and attempt
44
+ still match exactly. A stale/superseded result cannot clear or overwrite a newer checkpoint.
45
+ - A valid legacy vault warns and exits `0`. For v2, status correlates `last_memory_attempt`,
46
+ disposition, outbox, ledger, SHARED, and checkpoint: an ambiguous attempt, lost publication, or
47
+ mismatched checkpoint blocks; `degraded` with an intact outbox is a warning.
48
+ - `memory repair` is structural only: it uses PID/token-owned locks, writes a `.bak`, retains
49
+ valid events, and reprojects state. When it recognizes a valid pre-0.59 checkpoint whose cursor
50
+ is causal, it CAS-migrates it to the physical boundary with backup/audit; it never reclassifies
51
+ registry attempts or accepts a tuple that cannot be fully re-derived.
52
+ - `memory reconcile` is a dry run by default. `--apply` requires two named sessions plus a reason,
53
+ CAS-checks the exact attempt, backs up the registry, and limits mutation to the ambiguous attempt
54
+ and its successor. Replay is CORE-aware, checkpoints use the physical ledger cursor, and the
55
+ command neither rewrites ledger/CORE/notes nor consumes the outbox. Retrying the same applied
56
+ decision is idempotent.
57
+ - Every memory path validates the physical topology of `.brain`, ledger, outbox, CORE, SHARED,
58
+ candidates, registry, notes, backups, temporary files, and sidecars before reading or writing.
59
+ Junctions, symlinks, reparse points, or hardlinks fail closed without touching external bytes.
60
+ Locks publish owner and lease atomically, never reap a live PID by age alone, and release only
61
+ the lease they acquired.
62
+ - `promote`/`reject` append auditable decisions and never rewrite the ledger in place.
63
+ - `validate-memory <CORE.md>` checks the 25-line cap, required sections, and secrets.
64
+ - `validate-memory --vault` requires a complete v2 bundle and is not the legacy-vault gate.
65
+
66
+ ## Examples
67
+
68
+ ```bash
69
+ npx wendkeep memory status --gate --vault .MyApp-vault
70
+ npx wendkeep memory reconcile old --by-session current --reason "delivery continued" --vault .MyApp-vault
71
+ npx wendkeep memory reconcile old --by-session current --reason "delivery continued" --apply --vault .MyApp-vault
72
+ npx wendkeep validate-memory .MyApp-vault/.brain/CORE.md
73
+ npx wendkeep memory promote candidate-123 --vault .MyApp-vault
74
+ ```
75
+
76
+ ## Expected result
77
+
78
+ Status prints schema, revision, cursor, hash, events, outbox, candidates, conflicts, and the causal
79
+ state of the last attempt. CORE stays hand-curated and canonical; SHARED stays a verifiable
80
+ operational projection. After successful projection, an attempt checkpoint may be a valid prefix
81
+ of a global projection that has already advanced with concurrent events.
82
+
83
+ ## Common errors and diagnosis
84
+
85
+ - `legacy`: follow the migration guide; this is not corruption.
86
+ - `revision: 0` immediately after a valid migration, with no v2 attempt, is healthy; do not run
87
+ repair merely to manufacture the first event.
88
+ - `degraded` with every event ID present in either the ledger or an intact outbox is recoverable;
89
+ let idempotent replay finish. An event ID absent from both locations means lost publication.
90
+ - An `ambiguous` attempt, an `applied` attempt without event IDs, a `projected` event found only in
91
+ the outbox, or a mismatched checkpoint is blocking: preserve the artifacts and investigate
92
+ before repair. If the ambiguity is demonstrably superseded by a successor session, inspect the
93
+ `memory reconcile` dry run before authorizing `--apply`; the command fails when the ambiguous
94
+ attempt already contains event IDs.
95
+ - Ordinary pending candidate: recoverable warning, requiring human choice when appropriate.
96
+ - Missing `event_cursor` or mismatched v2 hash: preserve the bundle and assess `memory repair`.
97
+ - `validate-memory --vault` fails on legacy: validate CORE only or migrate first.
98
+
99
+ ## Next steps
100
+
101
+ Read [memory migration](memory-migration.md), [maintenance](maintenance-and-diagnostics.md), and
102
+ [verify](verify.md).
@@ -0,0 +1,70 @@
1
+ # Derived notes and knowledge graph
2
+
3
+ **English** · [Português](../../pt-BR/commands/notes-and-knowledge.md)
4
+
5
+ ## Purpose
6
+
7
+ Create, repair, number, and navigate decisions, bugs, and learnings while preserving provenance
8
+ and wikilinks.
9
+
10
+ ## When to use
11
+
12
+ Use to record durable knowledge or repair historical notes diagnosed by doctor.
13
+
14
+ ## When not to use
15
+
16
+ Do not hand-edit numbering or wikilinks in bulk. Do not use `--apply` before reviewing the preview.
17
+
18
+ ## Prerequisites
19
+
20
+ A bound vault, identifiable source session, and backup before broad renumbering.
21
+
22
+ ## Syntax
23
+
24
+ ```bash
25
+ npx wendkeep dashboard [--force]
26
+ npx wendkeep note new --type bug|learning "<title>"
27
+ npx wendkeep note relink [--apply]
28
+ npx wendkeep note repair-frontmatter [--apply]
29
+ npx wendkeep note repair-sections [--apply]
30
+ npx wendkeep renumber-decisions [--apply]
31
+ npx wendkeep renumber-bugs [--apply]
32
+ npx wendkeep renumber-learnings [--apply]
33
+ npx wendkeep lesson add "<title>" "<lesson>"
34
+ ```
35
+
36
+ ## Options and exit codes
37
+
38
+ - `note new` creates a monthly `BUG-NNNN` or `APR-NNNN` and accepts `--date`.
39
+ - `note relink`, `repair-frontmatter`, `repair-sections`, and `renumber-*` default to dry-run;
40
+ `--apply` writes and `--json` supports audit.
41
+ - `dashboard --force` regenerates Bases/MOC when required.
42
+ - `lesson add` accepts `--change <slug>` and `--vault` to bind local learning.
43
+ - Exit `0` means a consistent preview/application; non-zero makes incomplete repair explicit.
44
+
45
+ ## Examples
46
+
47
+ ```bash
48
+ npx wendkeep note new --type bug "refresh expires during upload"
49
+ npx wendkeep note relink --json
50
+ npx wendkeep renumber-decisions --json
51
+ # review before repeating with --apply
52
+ npx wendkeep dashboard --force
53
+ ```
54
+
55
+ ## Expected result
56
+
57
+ Derived notes live in the month folder, use global per-type numbering, and link back to the source
58
+ session. Repairs preserve valid frontmatter and rewrite wikilinks when files move.
59
+
60
+ ## Common errors and diagnosis
61
+
62
+ - Orphan note without a modal source: `note relink` reports it and does not invent provenance.
63
+ - Stacked frontmatter: repair under the same lock used by hooks.
64
+ - Grey links after renumber/archive: preview relink and inspect ambiguities.
65
+ - Sensitive title: remove secrets/PII before persistence.
66
+
67
+ ## Next steps
68
+
69
+ See [sessions and import](sessions-and-import.md), [costs and observability](costs-and-observability.md),
70
+ and [maintenance](maintenance-and-diagnostics.md).