wendkeep 0.85.1 → 0.87.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 (49) hide show
  1. package/.githooks/commit-msg +16 -0
  2. package/.githooks/prepare-commit-msg +16 -0
  3. package/CHANGELOG.md +40 -0
  4. package/README.en.md +4 -1
  5. package/README.md +4 -1
  6. package/docs/en/commands/commit.md +159 -0
  7. package/docs/en/commands/evidence-embeddings.md +243 -0
  8. package/docs/en/commands/mcp.md +67 -7
  9. package/docs/pt-BR/commands/commit.md +159 -0
  10. package/docs/pt-BR/commands/evidence-embeddings.md +244 -0
  11. package/docs/pt-BR/commands/mcp.md +66 -7
  12. package/hooks/evidence-context.mjs +41 -7
  13. package/hooks/evidence-recall.mjs +10 -0
  14. package/package.json +5 -2
  15. package/packages/cli/src/index.mjs +11 -1
  16. package/packages/commit/package.json +6 -0
  17. package/packages/commit/src/cli.mjs +89 -0
  18. package/packages/commit/src/commit-input.mjs +181 -0
  19. package/packages/commit/src/commit-message.mjs +51 -0
  20. package/packages/commit/src/commit-policy.mjs +144 -0
  21. package/packages/commit/src/git-runtime.mjs +428 -0
  22. package/packages/commit/src/index.mjs +28 -0
  23. package/packages/commit/src/proof-validation.mjs +443 -0
  24. package/packages/mcp/src/effects.mjs +3 -2
  25. package/packages/mcp/src/evidence-recall.mjs +130 -0
  26. package/packages/mcp/src/executor.mjs +4 -0
  27. package/packages/mcp/src/server.mjs +31 -1
  28. package/packages/vault/src/evidence-embedding-plugin.mjs +531 -0
  29. package/packages/vault/src/evidence-index-store.mjs +360 -0
  30. package/packages/vault/src/evidence-recall-page.mjs +381 -0
  31. package/packages/vault/src/evidence-search-index.mjs +917 -0
  32. package/packages/vault/src/index.mjs +12 -1
  33. package/packages/vault/src/memory-ledger-view-base.mjs +545 -0
  34. package/packages/vault/src/memory-ledger-view.mjs +41 -0
  35. package/packages/vault/src/memory-rotation-store.mjs +967 -0
  36. package/packages/vault/src/memory-segment-store.mjs +820 -0
  37. package/packages/vault/src/memory-snapshot-store.mjs +1105 -0
  38. package/packages/vault/src/memory-store-base.mjs +1161 -0
  39. package/packages/vault/src/memory-store-core.mjs +2 -0
  40. package/packages/vault/src/memory-store.mjs +46 -1161
  41. package/schema/commit-message-v1.schema.json +75 -0
  42. package/scripts/validate-commit-range.mjs +244 -0
  43. package/src/doctor.mjs +48 -5
  44. package/src/evidence-search-health.mjs +221 -0
  45. package/src/git-commit-hooks.mjs +112 -0
  46. package/src/init.mjs +13 -0
  47. package/src/memory-scale-health.mjs +210 -0
  48. package/src/observer-snapshot.mjs +87 -1
  49. package/src/skills-seed.mjs +79 -0
@@ -0,0 +1,16 @@
1
+ #!/bin/sh
2
+ set -eu
3
+
4
+ CLI=${WENDKEEP_COMMIT_CLI:-}
5
+ if [ -z "$CLI" ]; then
6
+ if [ -f "./node_modules/wendkeep/bin/wendkeep.mjs" ]; then
7
+ CLI=./node_modules/wendkeep/bin/wendkeep.mjs
8
+ elif [ -f "./bin/wendkeep.mjs" ]; then
9
+ CLI=./bin/wendkeep.mjs
10
+ else
11
+ echo "WENDKEEP_COMMIT_CLI_MISSING: install wendkeep or run wendkeep doctor" >&2
12
+ exit 2
13
+ fi
14
+ fi
15
+
16
+ exec node "$CLI" commit validate --message-file "$1" --consume-context
@@ -0,0 +1,16 @@
1
+ #!/bin/sh
2
+ set -eu
3
+
4
+ CLI=${WENDKEEP_COMMIT_CLI:-}
5
+ if [ -z "$CLI" ]; then
6
+ if [ -f "./node_modules/wendkeep/bin/wendkeep.mjs" ]; then
7
+ CLI=./node_modules/wendkeep/bin/wendkeep.mjs
8
+ elif [ -f "./bin/wendkeep.mjs" ]; then
9
+ CLI=./bin/wendkeep.mjs
10
+ else
11
+ echo "WENDKEEP_COMMIT_CLI_MISSING: install wendkeep or run wendkeep doctor" >&2
12
+ exit 2
13
+ fi
14
+ fi
15
+
16
+ exec node "$CLI" commit prepare --message-file "$1" --source "${2:-}" --commit "${3:-}"
package/CHANGELOG.md CHANGED
@@ -4,6 +4,46 @@ All notable changes to **wendkeep** are documented here. Format based on
4
4
  [Keep a Changelog](https://keepachangelog.com/en/1.1.0/); this project follows
5
5
  [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
6
6
 
7
+ ## [0.87.0] — 2026-08-29
8
+
9
+ ### Added
10
+
11
+ - **Política universal de commits baseada em evidências.** O novo pacote `wendkeep/commit`, a CLI,
12
+ os hooks Git e o gate de intervalo produzem e validam mensagens determinísticas a partir de
13
+ autoridade, tarefas, spec, escopo e sensores rederiváveis no checkout exato do commit.
14
+
15
+ ### Security
16
+
17
+ - **Prova remota limitada ao que o CI consegue rederivar.** Evidências causais locais permanecem
18
+ não publicadas; alegações remotas indisponíveis, provas circulares, sensores divergentes,
19
+ adulterações de escopo e caminhos privados falham de modo fechado antes da persistência.
20
+
21
+ ## [0.86.0] — 2026-08-28
22
+
23
+ ### Added
24
+
25
+ - **Memory ledger bounded para Vaults longos.** Snapshots determinísticos, replay apenas do tail,
26
+ segmentos imutáveis com manifest encadeado e rotação/compactação transacional preservam a
27
+ autoridade append-only, com dry-run, journal, receipt, recovery e benchmarks sintéticos de
28
+ 100 mil eventos.
29
+ - **Recall incremental, paginado e indexado.** Estado por documento/chunk, cursor vinculado ao
30
+ índice/consulta/filtros/`as_of`, budgets UTF-8 exatos, sidecar lexical bounded e SQLite FTS5
31
+ opcional evitam scans integrais sem transformar artefatos derivados em autoridade; o MCP expõe
32
+ a mesma leitura paginada e bounded.
33
+ - **Contrato opcional de embeddings locais.** `wendkeep/vault` exporta manifest versionado,
34
+ integrity-bound e in-process para reranquear somente um prefixo de candidatos; fica desligado
35
+ por padrão, proíbe rede/retenção, limita batch/bytes, preserva proveniência e degrada para a
36
+ ordem lexical sem incluir modelo, provider ou vector database no Core.
37
+
38
+ ### Changed
39
+
40
+ - **Saúde de escala no `doctor` e Observer.** Snapshots operacionais publicam somente contagens,
41
+ bytes, atualidade, backend e estados sanitizados de memória/recall, sem rebuild, leitura do
42
+ corpus ou vazamento de termos e paths.
43
+ - **Fechamento coordenado da issue #82.** A PR agregadora #124 reconcilia os slices #111–#123,
44
+ mantém documentação PT-BR/EN e tarball em paridade e alinha package/lock/CHANGELOG para a
45
+ entrega minor única.
46
+
7
47
  ## [0.85.1] — 2026-08-25
8
48
 
9
49
  ### Fixed
package/README.en.md CHANGED
@@ -151,6 +151,7 @@ npx wendkeep init --no-companions --no-mcp --yes # zero companions,
151
151
  | `--no-mcp` | Skip **wendkeep's own** vault MCP (`wendkeep-vault`). Companion MCPs still follow `--companions`. |
152
152
  | `--no-colors` | Skip the Obsidian color system (`.obsidian` snippet + graph groups). |
153
153
  | `--vscode-worktree-tasks` | Create a local, Git-excluded `.vscode/tasks.json` for creating/listing/opening/finishing worktrees; never overwrites an existing file. Also accepted by `sync`. |
154
+ | `--git-commit-hooks` | Opt in to copying commit hooks into `.githooks/` and setting local `core.hooksPath`; custom hooks are preserved without `--force`. |
154
155
  | `--yes`, `-y` | Non-interactive; accept defaults (skips the language / vault / companion prompts). |
155
156
  | `--force` | Overwrite existing wendkeep config blocks. |
156
157
 
@@ -250,6 +251,7 @@ The README is the map; the guides provide syntax, options, exit codes, examples,
250
251
  | **Portable state** | `portable status/export/import/diff`, authored/runtime boundary, redaction, and the `active-work` snapshot | [Portable state](https://github.com/rogersialves/wendkeep/blob/main/docs/en/commands/portable.md) |
251
252
  | **Local-first sync** | `sync status/push/pull/conflicts/resolve`, revision/CAS, outbox, leases, and explicit conflicts | [Sync protocol](https://github.com/rogersialves/wendkeep/blob/main/docs/en/commands/sync-protocol.md) |
252
253
  | **Native MCP** | semantic tools, effects/capabilities, stdio, schemas, pagination, budgets, audit, and client configuration | [Native MCP](https://github.com/rogersialves/wendkeep/blob/main/docs/en/commands/mcp.md) |
254
+ | **Evidence recall and embeddings** | cursor/byte budgets, bounded lexical/FTS sidecars, and an optional local plugin contract that is off by default | [Optional embedding plugin](https://github.com/rogersialves/wendkeep/blob/main/docs/en/commands/evidence-embeddings.md) |
253
255
  | **Host capabilities** | versioned lifecycle/effect matrix, degraded mode, human waivers, and evidence/Observer coverage | [Host capabilities](https://github.com/rogersialves/wendkeep/blob/main/docs/en/commands/capabilities.md) |
254
256
  | **Operating profiles** | `profile`, `flow`, always-on Keep Core, and Wend Runtime governance | [Operating profiles](https://github.com/rogersialves/wendkeep/blob/main/docs/en/commands/operating-profiles.md) |
255
257
  | **Changes and verification** | `change`, specs, sensors, TDD, evidence, Task Contracts, and archive | [Changes and verification](https://github.com/rogersialves/wendkeep/blob/main/docs/en/commands/changes-and-verification.md) |
@@ -258,6 +260,7 @@ The README is the map; the guides provide syntax, options, exit codes, examples,
258
260
  | **Notes and knowledge** | BUG/APR/ADR, repairs, renumbering, lessons, and dashboard | [Notes and knowledge](https://github.com/rogersialves/wendkeep/blob/main/docs/en/commands/notes-and-knowledge.md) |
259
261
  | **Costs and observability** | safe dry-run, tri-state, aggregation, trends, and historical rebuild | [Costs and observability](https://github.com/rogersialves/wendkeep/blob/main/docs/en/commands/costs-and-observability.md) |
260
262
  | **Maintenance and diagnostics** | doctor, frontier/manifest freshness, drift, version, and help | [Maintenance and diagnostics](https://github.com/rogersialves/wendkeep/blob/main/docs/en/commands/maintenance-and-diagnostics.md) |
263
+ | **Evidence-based commits** | `wendkeep commit`, tasks derived from contracts, tests only from canonical execution bound to the exact SHA, opt-in Git hooks, privacy, and remote range gate | [Commits](https://github.com/rogersialves/wendkeep/blob/main/docs/en/commands/commit.md) |
261
264
  | **Local Observer** | `observer serve`, registration, incremental publication, `reconcile`, outbox, and multi-project index | [Local Observer](https://github.com/rogersialves/wendkeep/blob/main/docs/en/commands/observer.md) |
262
265
 
263
266
  Operations that deserve step-by-step guidance: [verify and exits 0/1/2](https://github.com/rogersialves/wendkeep/blob/main/docs/en/commands/verify.md),
@@ -665,7 +668,7 @@ The archive **gate** blocks unless: the change scaffold is filled (G0), no task
665
668
  ## Notes & roadmap
666
669
 
667
670
  - **Vault folder names default to Portuguese** (`02-Sessões`, `04-Decisões`, …). Pass `wendkeep init --locale en` for an English vault (`02-Sessions`, `04-Decisions`, English scaffold/skills). The locale is a vault property, locked at init; parsers are bilingual so mixed content never breaks.
668
- - **Search is keyword/frontmatter scoring**, not on‑device embeddings (that's on the roadmap).
671
+ - **Default recall remains local lexical/FTS.** Embeddings require an explicitly supplied trusted local plugin with forbidden network access, budgets, and lexical fallback; Core ships no model or provider.
669
672
  - **Transcript formats are agent‑internal** and can change between agent versions; parsing is isolated but may need updates.
670
673
  - Installer wires **both agents**: `.claude/settings.json` + `.mcp.json` for Claude Code, `.codex/hooks.json` for Codex. **Eight Codex hooks are compatible**; `change-guard` validates the project lease in `PreToolUse` and denies mutations outside it. The four hooks without an equivalent remain Claude-only: `change-warn`, `plan-capture`, `decision-capture`, and `task-log`.
671
674
  - **Codex hooks start untrusted.** They are enumerated but not executed until you approve the “Hooks need review” prompt; `init` cannot pre‑approve them (`--dangerously-bypass-hook-trust` is per‑invocation and stores no trusted hash). Trust is keyed to the hook's identity, so hand‑written wendkeep Codex hooks predating `0.46.0` — which ran at the 600s default because they used `timeout` instead of `timeoutSec` — cost one re‑review after `init` corrects the key. Expected, not a regression. `import --source codex` still backfills past Codex sessions either way.
package/README.md CHANGED
@@ -151,6 +151,7 @@ npx wendkeep init --no-companions --no-mcp --yes # zero companions,
151
151
  | `--no-mcp` | Skip **wendkeep's own** vault MCP (`wendkeep-vault`). Companion MCPs still follow `--companions`. |
152
152
  | `--no-colors` | Skip the Obsidian color system (`.obsidian` snippet + graph groups). |
153
153
  | `--vscode-worktree-tasks` | Create a local, Git-excluded `.vscode/tasks.json` for creating/listing/opening/finishing worktrees; never overwrites an existing file. Also accepted by `sync`. |
154
+ | `--git-commit-hooks` | Opt in to copying commit hooks into `.githooks/` and setting local `core.hooksPath`; custom hooks are preserved without `--force`. |
154
155
  | `--yes`, `-y` | Non-interactive; accept defaults (skips the language / vault / companion prompts). |
155
156
  | `--force` | Overwrite existing wendkeep config blocks. |
156
157
 
@@ -250,6 +251,7 @@ The README is the map; the guides provide syntax, options, exit codes, examples,
250
251
  | **Portable state** | `portable status/export/import/diff`, authored/runtime boundary, redaction, and the `active-work` snapshot | [Portable state](https://github.com/rogersialves/wendkeep/blob/main/docs/en/commands/portable.md) |
251
252
  | **Local-first sync** | `sync status/push/pull/conflicts/resolve`, revision/CAS, outbox, leases, and explicit conflicts | [Sync protocol](https://github.com/rogersialves/wendkeep/blob/main/docs/en/commands/sync-protocol.md) |
252
253
  | **Native MCP** | semantic tools, effects/capabilities, stdio, schemas, pagination, budgets, audit, and client configuration | [Native MCP](https://github.com/rogersialves/wendkeep/blob/main/docs/en/commands/mcp.md) |
254
+ | **Evidence recall and embeddings** | cursor/byte budgets, bounded lexical/FTS sidecars, and an optional local plugin contract that is off by default | [Optional embedding plugin](https://github.com/rogersialves/wendkeep/blob/main/docs/en/commands/evidence-embeddings.md) |
253
255
  | **Host capabilities** | versioned lifecycle/effect matrix, degraded mode, human waivers, and evidence/Observer coverage | [Host capabilities](https://github.com/rogersialves/wendkeep/blob/main/docs/en/commands/capabilities.md) |
254
256
  | **Operating profiles** | `profile`, `flow`, always-on Keep Core, and Wend Runtime governance | [Operating profiles](https://github.com/rogersialves/wendkeep/blob/main/docs/en/commands/operating-profiles.md) |
255
257
  | **Changes and verification** | `change`, specs, sensors, TDD, evidence, Task Contracts, and archive | [Changes and verification](https://github.com/rogersialves/wendkeep/blob/main/docs/en/commands/changes-and-verification.md) |
@@ -258,6 +260,7 @@ The README is the map; the guides provide syntax, options, exit codes, examples,
258
260
  | **Notes and knowledge** | BUG/APR/ADR, repairs, renumbering, lessons, and dashboard | [Notes and knowledge](https://github.com/rogersialves/wendkeep/blob/main/docs/en/commands/notes-and-knowledge.md) |
259
261
  | **Costs and observability** | safe dry-run, tri-state, aggregation, trends, and historical rebuild | [Costs and observability](https://github.com/rogersialves/wendkeep/blob/main/docs/en/commands/costs-and-observability.md) |
260
262
  | **Maintenance and diagnostics** | doctor, frontier/manifest freshness, drift, version, and help | [Maintenance and diagnostics](https://github.com/rogersialves/wendkeep/blob/main/docs/en/commands/maintenance-and-diagnostics.md) |
263
+ | **Evidence-based commits** | `wendkeep commit`, tasks derived from contracts, tests only from canonical execution bound to the exact SHA, opt-in Git hooks, privacy, and remote range gate | [Commits](https://github.com/rogersialves/wendkeep/blob/main/docs/en/commands/commit.md) |
261
264
  | **Local Observer** | `observer serve`, registration, incremental publication, `reconcile`, outbox, and multi-project index | [Local Observer](https://github.com/rogersialves/wendkeep/blob/main/docs/en/commands/observer.md) |
262
265
 
263
266
  Operations that deserve step-by-step guidance: [verify and exits 0/1/2](https://github.com/rogersialves/wendkeep/blob/main/docs/en/commands/verify.md),
@@ -665,7 +668,7 @@ The archive **gate** blocks unless: the change scaffold is filled (G0), no task
665
668
  ## Notes & roadmap
666
669
 
667
670
  - **Vault folder names default to Portuguese** (`02-Sessões`, `04-Decisões`, …). Pass `wendkeep init --locale en` for an English vault (`02-Sessions`, `04-Decisions`, English scaffold/skills). The locale is a vault property, locked at init; parsers are bilingual so mixed content never breaks.
668
- - **Search is keyword/frontmatter scoring**, not on‑device embeddings (that's on the roadmap).
671
+ - **Default recall remains local lexical/FTS.** Embeddings require an explicitly supplied trusted local plugin with forbidden network access, budgets, and lexical fallback; Core ships no model or provider.
669
672
  - **Transcript formats are agent‑internal** and can change between agent versions; parsing is isolated but may need updates.
670
673
  - Installer wires **both agents**: `.claude/settings.json` + `.mcp.json` for Claude Code, `.codex/hooks.json` for Codex. **Eight Codex hooks are compatible**; `change-guard` validates the project lease in `PreToolUse` and denies mutations outside it. The four hooks without an equivalent remain Claude-only: `change-warn`, `plan-capture`, `decision-capture`, and `task-log`.
671
674
  - **Codex hooks start untrusted.** They are enumerated but not executed until you approve the “Hooks need review” prompt; `init` cannot pre‑approve them (`--dangerously-bypass-hook-trust` is per‑invocation and stores no trusted hash). Trust is keyed to the hook's identity, so hand‑written wendkeep Codex hooks predating `0.46.0` — which ran at the 600s default because they used `timeout` instead of `timeoutSec` — cost one re‑review after `init` corrects the key. Expected, not a regression. `import --source codex` still backfills past Codex sessions either way.
@@ -0,0 +1,159 @@
1
+ # Evidence-based commits
2
+
3
+ **English** · [Português](../../pt-BR/commands/commit.md)
4
+
5
+ ## Purpose
6
+
7
+ Produce the same auditable message from Codex, Claude Code, or another Git client using typed input,
8
+ public references, and a staged-index summary only. The deterministic kernel does not read the
9
+ Vault, `.brain`, session registries, or the network.
10
+
11
+ ## When to use
12
+
13
+ Use before `feat`, `fix`, `refactor`, or `perf` implementation commits that must record causal
14
+ authority, tasks, tests, scope, and verifiable evidence consistently across harnesses.
15
+
16
+ ## When not to use
17
+
18
+ Do not use it to invent proof, publish private content, rewrite history, or automate pushes.
19
+ `docs`, `test`, and `chore` commits need no context only when every changed file is objectively
20
+ documentation/test material. Product changes require the governed body regardless of type.
21
+
22
+ ## Prerequisites
23
+
24
+ Run inside a Git repository with WendKeep installed locally and the selected product files already
25
+ present in the staged index.
26
+
27
+ ## Syntax
28
+
29
+ ```bash
30
+ npx --no-install wendkeep commit context --input <json|-> [--json]
31
+ npx --no-install wendkeep commit context --clear [--json]
32
+ npx --no-install wendkeep commit render --input <json|->
33
+ npx --no-install wendkeep commit prepare --message-file <path> [--source <source>]
34
+ npx --no-install wendkeep commit validate --message-file <path> [--json]
35
+ ```
36
+
37
+ ## Options and exit codes
38
+
39
+ - Exit `0`: context written/cleared or message valid.
40
+ - Exit `1`: invalid governed message.
41
+ - Exit `2`: invalid argument, JSON, Git state, privacy boundary, or stale context.
42
+ - `--consume-context` is reserved for the `commit-msg` wrapper and removes context after validation.
43
+
44
+ ## Opt-in installation
45
+
46
+ The default `init` does not enable Git hooks. To copy the portable wrappers and set
47
+ `core.hooksPath=.githooks` for this repository only:
48
+
49
+ ```bash
50
+ npx --no-install wendkeep init --git-commit-hooks --yes
51
+ ```
52
+
53
+ Custom hooks are never overwritten silently. When `init` finds a conflict it preserves the file.
54
+ Review it and rerun with `--force` only when replacement is intended; the previous file is retained
55
+ as `.bak`.
56
+ A custom `core.hooksPath` is also a conflict and remains untouched without `--force`.
57
+
58
+ ## Examples
59
+
60
+ ### Prepare a commit
61
+
62
+ Create JSON matching `schema/commit-message-v1.schema.json`. Declare authority and evidence
63
+ references, but do not provide `tasks`, `tests`, `fresh`, or `verified`. Runtime derives tasks from
64
+ completed canonical Task Contracts. Tests come only from `[sensor:<id>]` sensors executed by the
65
+ collector; `[phase:verify]` alone is never a result. Sensors
66
+ declared in an Envelope must exactly match the canonical reexecution in IDs, configuration,
67
+ command, severity, and result; only that reexecution emits a `Tests` line. The remote gate
68
+ re-executes each sensor in the checkout for that exact commit SHA. Every
69
+ published reference gets a re-derived SHA-256 digest. ADR/design validate artifact ID and path;
70
+ tasks containing `[req:]` require a versioned, sanitized `spec` reference that defines every
71
+ requirement. Evidence Envelope, Verdict, receipt, and TDD attestation may participate in local
72
+ validation, but are omitted from remote Evidence: worktree/session/branch IDs are not published,
73
+ and self-contained consistency is not promoted to proof. A message claiming them as
74
+ `fresh`/`verified` is rejected with `WENDKEEP_COMMIT_REMOTE_PROOF_UNAVAILABLE`. The fixed trailers
75
+ `Remote-Proof-Scope: git,authority,tasks,spec,sensors` and `Local-Causal-Proof: unpublished` make
76
+ that boundary explicit. Range re-derives authority/artifacts, task/spec, Git `Scope`, and
77
+ config/sensors from the SHA, and only canonical reexecution emits `Tests`. `Co-Authored-By` is
78
+ omitted until a trusted identity registry can resolve it.
79
+
80
+ The normal authority is the causal ADR:
81
+
82
+ ```json
83
+ { "authority": { "kind": "adr", "adr": "ADR-1234", "ref": "docs/ADR-1234.md", "issue": "#123" } }
84
+ ```
85
+
86
+ Only when no causal change/ADR exists may the native harness declare the fallback below. `issue`
87
+ must be `#NNN` and `design` must be versioned in the same commit under
88
+ `docs/superpowers/specs/` or `plans/`:
89
+
90
+ ```json
91
+ {
92
+ "authority": {
93
+ "kind": "native",
94
+ "issue": "#40",
95
+ "design": "docs/superpowers/specs/approved-design.md"
96
+ }
97
+ }
98
+ ```
99
+
100
+ Runtime observes effective profile `OFF`, no causal context/change/lease or ADR, and the issue in the
101
+ design. This mode emits unique `Authority: native-no-causal-change`, `Issue`, and `Design` trailers. Free text, unversioned
102
+ design, stale/unverified proof, or a missing body/tests fail closed.
103
+
104
+ ```bash
105
+ git add <product-files>
106
+ npx --no-install wendkeep commit context --input commit-input.json
107
+ git commit -m "feat(scope): draft"
108
+ ```
109
+
110
+ `commit context` calculates the staged diff SHA-256 and stores the sanitized context at
111
+ `.git/wendkeep-commit-input.json`, outside the working tree. `prepare-commit-msg` replaces the draft
112
+ with the canonical message; `commit-msg` validates it and consumes the context. If the index changes,
113
+ the context becomes stale and must be recreated.
114
+ `commit-msg` rereads context, compares the complete message and staged hash/files, and consumes
115
+ context only after success. Merge, squash, and amend clear incompatible context so it cannot leak
116
+ to the next commit. `--message-file` stays inside the repository or Git directory.
117
+
118
+ Other commands:
119
+
120
+ ```bash
121
+ npx --no-install wendkeep commit render --input commit-input.json
122
+ npx --no-install wendkeep commit validate --message-file .git/COMMIT_EDITMSG
123
+ npx --no-install wendkeep commit context --clear
124
+ ```
125
+
126
+ Objectively trivial commits remain unchanged. Implementation
127
+ commits (`feat`, `fix`, `refactor`, and `perf`) require a Conventional Commit subject with an ADR or
128
+ the restricted native fallback above, Capability, Evidence, Tasks, Tests, and Scope sections, the
129
+ staged hash, and a `WendKeep-Commit: v1` trailer. Amend, merge, and squash never receive duplicate or
130
+ invented proof.
131
+
132
+ ## Privacy and fail-closed behavior
133
+
134
+ - Embedded absolute paths, any configured/default Vault, `.brain`, session registries, PII, and secrets are rejected
135
+ before persistence.
136
+ - `reported`, `legacy-unbound`, `stale`, and `unproven` evidence cannot be presented as proof.
137
+ - Context holds sanitized references and diff metadata, never private Vault content.
138
+ - `--no-verify` is not accepted: CI validates every new commit, including merges and novel resolutions.
139
+
140
+ ## Expected result
141
+
142
+ A deterministic, self-contained message with no private material, the hash of the committed index,
143
+ and coherent causal trailers.
144
+
145
+ ## Common errors and diagnosis
146
+
147
+ `wendkeep doctor` reports `[commit-hooks] healthy`, `disabled`, `missing`, or `drift` and remains
148
+ read-only. After review, recover missing or divergent files with:
149
+
150
+ ```bash
151
+ npx --no-install wendkeep init --git-commit-hooks --force --yes
152
+ ```
153
+
154
+ When abandoning a commit, remove only its transient context with
155
+ `wendkeep commit context --clear`. No command rewrites history or pushes automatically.
156
+
157
+ ## Next steps
158
+
159
+ Review the generated message, commit it, and let the PR range gate detect any local bypass.
@@ -0,0 +1,243 @@
1
+ # Optional evidence embedding plugin
2
+
3
+ [Português](../../pt-BR/commands/evidence-embeddings.md)
4
+
5
+ ## Purpose
6
+
7
+ Define a programmatic boundary for local semantic reranking without adding a model, ML runtime,
8
+ vector database, HTTP client, or provider dependency to WendKeep Core.
9
+
10
+ This surface is **not a CLI command**. It is exported by `wendkeep/vault` for local plugins that are
11
+ explicitly supplied by the application's composition root.
12
+
13
+ ## When to use
14
+
15
+ Use this API when a trusted composition root needs to rerank a small candidate set already filtered
16
+ by lexical/FTS recall while keeping the model and adapter outside Core.
17
+
18
+ Embeddings are disabled by default.
19
+
20
+ ```js
21
+ const result = await rerankEvidenceCandidatesWithEmbedding(rows, query);
22
+ // result.metrics.status === 'disabled'
23
+ ```
24
+
25
+ Core does not:
26
+
27
+ - discover plugins in `node_modules`;
28
+ - execute `import()` from Vault configuration;
29
+ - download models;
30
+ - open network connections;
31
+ - persist vectors;
32
+ - hand the full corpus to a plugin.
33
+
34
+ A plugin receives data only when the caller supplies the plugin object and sets `enabled: true`.
35
+
36
+ ## When not to use
37
+
38
+ Do not use the plugin as an authoritative index, a scope-expansion mechanism, a code autoloader, or
39
+ a replacement for lexical filters/recall. Do not use a remote provider either: the contract requires
40
+ local in-process execution with no network and no retention.
41
+
42
+ ### Authority contract
43
+
44
+ Authority remains ordered as follows:
45
+
46
+ ```text
47
+ Vault Markdown/JSONL → incremental index → lexical/FTS candidates → optional reranking
48
+ ```
49
+
50
+ The plugin operates only on a bounded prefix of already-filtered candidates. It cannot:
51
+
52
+ - make its index or cache authoritative;
53
+ - silently broaden project, session, change, or logical-path scope;
54
+ - hide `authority`, `validity`, or provenance;
55
+ - remove unprocessed candidates—they remain at the end in their original order;
56
+ - mutate the source objects returned by Core.
57
+
58
+ ## Prerequisites
59
+
60
+ - a reviewed local plugin explicitly loaded by the application;
61
+ - a model/configuration pinned by SHA-256 fingerprint;
62
+ - explicit batch and byte budgets;
63
+ - candidates already filtered by lexical/FTS recall.
64
+
65
+ ### Versioned manifest
66
+
67
+ Use `buildEvidenceEmbeddingManifest()` to create the manifest and
68
+ `createEvidenceEmbeddingPlugin()` to bind it to the `embed` function.
69
+
70
+ Required fields:
71
+
72
+ | Field | Rule |
73
+ |---|---|
74
+ | `schema_version` | `1` |
75
+ | `protocol_version` | `1` |
76
+ | `plugin_id` | stable local identifier |
77
+ | `plugin_version` | adapter version |
78
+ | `model_id` | model identifier |
79
+ | `model_revision` | immutable revision used by the adapter |
80
+ | `model_fingerprint` | `sha256:<64 hex>` for the effective model/configuration |
81
+ | `dimensions` | 1 through 65536 |
82
+ | `locality` | exactly `local` |
83
+ | `transport` | exactly `in-process` |
84
+ | `network` | exactly `forbidden` |
85
+ | `retention` | exactly `none` |
86
+ | `max_batch_size` | 1 through 512 documents |
87
+ | `max_input_bytes` | 1 through 4 MiB |
88
+ | `integrity` | hash of the canonical manifest payload |
89
+
90
+ The manifest is declarative. Core cannot sandbox arbitrary JavaScript, so install only trusted local
91
+ plugins and review their code. WendKeep prevents automatic loading and validates the contract before
92
+ handing over any evidence, but it does not turn third-party code into trusted code.
93
+
94
+ ## Syntax
95
+
96
+ ```text
97
+ buildEvidenceEmbeddingManifest(options)
98
+ createEvidenceEmbeddingPlugin({ manifest, embed })
99
+ verifyEvidenceEmbeddingPlugin(plugin)
100
+ rerankEvidenceCandidatesWithEmbedding(rows, query, options)
101
+ ```
102
+
103
+ ## Examples
104
+
105
+ ```js
106
+ import {
107
+ buildEvidenceEmbeddingManifest,
108
+ createEvidenceEmbeddingPlugin,
109
+ rerankEvidenceCandidatesWithEmbedding,
110
+ } from 'wendkeep/vault';
111
+
112
+ const manifest = buildEvidenceEmbeddingManifest({
113
+ plugin_id: 'local.my-embedding',
114
+ plugin_version: '1.0.0',
115
+ model_id: 'local.my-model',
116
+ model_revision: '2026.08.27',
117
+ model_fingerprint: 'sha256:<model-and-configuration-hash>',
118
+ dimensions: 384,
119
+ max_batch_size: 64,
120
+ max_input_bytes: 262144,
121
+ });
122
+
123
+ const plugin = createEvidenceEmbeddingPlugin({
124
+ manifest,
125
+ async embed(request, { signal }) {
126
+ // Local adapter: no network access and no text retention.
127
+ // Return exactly one query vector and one vector for every document.id.
128
+ return {
129
+ schema_version: 1,
130
+ model_fingerprint: manifest.model_fingerprint,
131
+ query_vector: await localModel.embed(request.query.text, { signal }),
132
+ document_vectors: await Promise.all(request.documents.map(async (document) => ({
133
+ id: document.id,
134
+ vector: await localModel.embed(document.text, { signal }),
135
+ }))),
136
+ };
137
+ },
138
+ });
139
+
140
+ const reranked = await rerankEvidenceCandidatesWithEmbedding(rows, query, {
141
+ enabled: true,
142
+ plugin,
143
+ maxCandidates: 64,
144
+ maxInputBytes: 262144,
145
+ });
146
+ ```
147
+
148
+ The request contains only:
149
+
150
+ ```json
151
+ {
152
+ "schema_version": 1,
153
+ "model_fingerprint": "sha256:...",
154
+ "query": { "text": "..." },
155
+ "documents": [
156
+ { "id": "<chunk_id>", "text": "<title + heading + content>" }
157
+ ]
158
+ }
159
+ ```
160
+
161
+ `logical_path` is not sent to the plugin. Full provenance remains on the source objects and returns
162
+ with the reranked order.
163
+
164
+ ## Expected result
165
+
166
+ The response is fail-closed and may contain only:
167
+
168
+ ```json
169
+ {
170
+ "schema_version": 1,
171
+ "model_fingerprint": "sha256:...",
172
+ "query_vector": [0.1, 0.2],
173
+ "document_vectors": [
174
+ { "id": "<chunk_id>", "vector": [0.3, 0.4] }
175
+ ]
176
+ }
177
+ ```
178
+
179
+ Core rejects:
180
+
181
+ - dimensions that differ from the manifest;
182
+ - `NaN`, infinity, or zero-norm vectors;
183
+ - a divergent model fingerprint;
184
+ - missing, duplicate, or unknown documents;
185
+ - extra envelope fields;
186
+ - a vector count that differs from the document count.
187
+
188
+ The canonical adapter uses cosine similarity. Ties preserve the original order.
189
+
190
+ ## Options and exit codes
191
+
192
+ The effective limit is always the lower value between caller and plugin manifest.
193
+
194
+ - `maxCandidates`: default 128; maximum 512;
195
+ - `maxInputBytes`: default 256 KiB; maximum 4 MiB;
196
+ - documents that do not fit remain after the reranked prefix;
197
+ - Core never sends a partial document;
198
+ - a query or first document that cannot fit produces
199
+ `EVIDENCE_EMBEDDING_BUDGET_EXCEEDED`.
200
+
201
+ With `required: false`—the default—a contract, budget, response, or execution failure returns the
202
+ original lexical order and `metrics.status: "fallback"`. With `required: true`, the typed error is
203
+ propagated.
204
+
205
+ Main codes:
206
+
207
+ - `EVIDENCE_EMBEDDING_PLUGIN_INVALID`;
208
+ - `EVIDENCE_EMBEDDING_BUDGET_EXCEEDED`;
209
+ - `EVIDENCE_EMBEDDING_RESPONSE_INVALID`;
210
+ - `EVIDENCE_EMBEDDING_EXECUTION_FAILED`.
211
+
212
+ ## Safe operation
213
+
214
+ 1. Keep `enabled: false` until the plugin and model hash are verified.
215
+ 2. Run `verifyEvidenceEmbeddingPlugin(plugin)` before registering the adapter.
216
+ 3. Pin `plugin_version`, `model_revision`, and `model_fingerprint`; do not use mutable aliases such
217
+ as `latest`.
218
+ 4. Start with small budgets and compare the result against lexical/FTS recall.
219
+ 5. Record metrics only—IDs, counts, bytes, and timings—never query, text, or vectors.
220
+ 6. Treat a fingerprint change as a new generation of any plugin-owned cache.
221
+
222
+ ## Common errors and diagnosis
223
+
224
+ When `metrics.status` is `fallback`:
225
+
226
+ 1. disable the plugin; lexical/FTS recall remains the safe route;
227
+ 2. validate the manifest and inspect `metrics.reason`;
228
+ 3. confirm dimensions, fingerprint, and vector count;
229
+ 4. discard only plugin-owned caches and rebuild them from `EVIDENCE_INDEX.jsonl` authority;
230
+ 5. never delete or edit `EVIDENCE_INDEX.jsonl`, Markdown, or Core sidecars to repair an embedding
231
+ provider;
232
+ 6. re-enable with `required: false` and promote to `required: true` only in an environment that
233
+ genuinely requires the provider.
234
+
235
+ ## Next steps
236
+
237
+ This contract does not install a model or automatically add embeddings to MCP, doctor, or Observer.
238
+ It defines the safe, testable boundary for a future sibling adapter. Core remains complete and
239
+ functional without any plugin.
240
+
241
+ Use the [Native MCP](mcp.md) guide for the existing paged/lexical surface and the
242
+ [maintenance and diagnostics](maintenance-and-diagnostics.md) guide to inspect derived-artifact
243
+ health without rebuilding it.
@@ -63,20 +63,71 @@ wendkeep mcp config --client cursor --vault <vault>
63
63
  ```
64
64
 
65
65
  Reads: `wendkeep_project_status`, `wendkeep_context_status`, `wendkeep_memory_recall`,
66
- `wendkeep_memory_conflicts`, `wendkeep_change_list`, `wendkeep_change_show`,
67
- `wendkeep_change_status`, `wendkeep_spec_effective`, `wendkeep_task_show`,
68
- `wendkeep_task_evaluate`, `wendkeep_handoff_current`, `wendkeep_evidence_latest`, and
69
- `wendkeep_observer_query`.
66
+ `wendkeep_evidence_recall`, `wendkeep_memory_conflicts`, `wendkeep_change_list`,
67
+ `wendkeep_change_show`, `wendkeep_change_status`, `wendkeep_spec_effective`,
68
+ `wendkeep_task_show`, `wendkeep_task_evaluate`, `wendkeep_handoff_current`,
69
+ `wendkeep_evidence_latest`, and `wendkeep_observer_query`.
70
70
 
71
71
  Writes: `wendkeep_memory_assert`, `wendkeep_checkpoint_create`, `wendkeep_context_select`,
72
72
  `wendkeep_task_claim`, `wendkeep_task_complete`, and `wendkeep_handoff_publish`.
73
73
 
74
+ ## Paged indexed evidence recall
75
+
76
+ `wendkeep_evidence_recall` is the bounded surface for retrieving Vault evidence. It selects
77
+ candidates through the persistent lexical sidecar or optional SQLite/FTS5, reranks them with the
78
+ canonical scorer, and returns a compact page. `wendkeep_memory_recall` remains available as the
79
+ legacy API and does not silently inherit the new contract.
80
+
81
+ Main input:
82
+
83
+ - `project_root` and `query` are required;
84
+ - `limit` accepts 1 through 100 results per page;
85
+ - `cursor` is opaque and is valid only for the same query, filters, and logical index;
86
+ - `max_bytes` accepts 2 through 524288 and exactly bounds the serialized JSON in `results`; the
87
+ default is 64 KiB;
88
+ - `candidate_limit` accepts 1 through 4096 candidates;
89
+ - `posting_budget` accepts 1 through 1048576 visited postings;
90
+ - `backend` accepts `auto`, `sqlite`, or `lexical`;
91
+ - `filters` supports exact matches for `authority`, `validity`, `entity_type`, `project_id`,
92
+ `change_slug`, `session_id`, `work_session_id`, and `logical_path`, plus
93
+ `logical_path_prefix`. Each filter may be a string or a string list.
94
+
95
+ Example call:
96
+
97
+ ```json
98
+ {
99
+ "name": "wendkeep_evidence_recall",
100
+ "arguments": {
101
+ "project_root": "<project>",
102
+ "query": "authentication contract",
103
+ "limit": 5,
104
+ "max_bytes": 65536,
105
+ "candidate_limit": 512,
106
+ "posting_budget": 65536,
107
+ "backend": "auto",
108
+ "filters": {
109
+ "authority": "verified",
110
+ "validity": "active",
111
+ "logical_path_prefix": "04-Decisions/"
112
+ }
113
+ }
114
+ }
115
+ ```
116
+
117
+ The response contains `results`, `next_cursor`, `has_more`, `as_of`, and page counts/bytes. Each
118
+ result omits `content`, reports `content_bytes`, retains a bounded `excerpt`, and replaces
119
+ `logical_path` with `logical_ref`, a Vault-relative reference—never an absolute path. The
120
+ `candidates` block exposes backend, count, postings, rebuild, and fallback metadata. When the
121
+ candidate budget did not cover every possible match, `complete_candidate_set` is `false`; this
122
+ prevents a consumer from treating a truncated selection as exhaustive.
123
+
74
124
  ## Expected result
75
125
 
76
126
  The handshake and `tools/list` return valid JSON-RPC. Every tool declares a versioned
77
127
  effect/capability and schemas. Known reads skip the mutation gate while retaining explicit
78
- project/worktree binding, cursor pagination, a 1 MiB default budget, redaction, timeout, and
79
- cancellation. Observer is declared unavailable below Node 22.13 without blocking Core on Node 18.
128
+ project/worktree binding, cursor pagination, budgets, redaction, timeout, and cancellation.
129
+ Observer is declared unavailable below Node 22.13 without blocking Core on Node 18. Indexed recall
130
+ also works on Node 18 through the lexical fallback; SQLite/FTS5 remains optional.
80
131
 
81
132
  Writes require `project_root`, `session_id`, `active_context_id`, `actor`, `reason`, the exact
82
133
  capability, and `lease.id`/`lease.expires_at`; the executor revalidates causal authorization and CLI
@@ -89,8 +140,17 @@ outcome, code, and duration—never arguments or payloads.
89
140
  - `MCP_CAPABILITY_REQUIRED` / `MCP_SCOPE_AUTH_REQUIRED`: capability missing or unauthorized.
90
141
  - `MCP_LEASE_EXPIRED`: obtain a new authorization/lease; do not hand-edit its timestamp.
91
142
  - `MCP_PROJECT_SCOPE_MISMATCH`: `project_root` and `worktree_root` use different bindings.
92
- - `MCP_REQUEST_TOO_LARGE` / `MCP_RESPONSE_TOO_LARGE`: use `limit` and the returned cursor.
143
+ - `MCP_REQUEST_TOO_LARGE` / `MCP_RESPONSE_TOO_LARGE`: reduce budgets and continue with the cursor.
93
144
  - `MCP_RUNTIME_UNSUPPORTED`: use Node 22.13+ for Observer; Core remains available.
145
+ - `MCP_EVIDENCE_QUERY_REQUIRED`: provide a non-empty query.
146
+ - `MCP_EVIDENCE_CURSOR_INVALID`: the cursor was altered, became stale, or was reused with a
147
+ different query/filter set.
148
+ - `MCP_EVIDENCE_BUDGET_TOO_SMALL`: even the next result's minimum metadata cannot fit
149
+ `max_bytes`.
150
+ - `MCP_EVIDENCE_BACKEND_UNAVAILABLE`: SQLite was required but FTS5 is unavailable; use `auto` or
151
+ `lexical`.
152
+ - `MCP_EVIDENCE_ARTIFACT_UNSAFE`: a derived artifact violated the Vault's physical boundary.
153
+ - `MCP_EVIDENCE_RECALL_INVALID`: a filter, backend, or limit is outside the contract.
94
154
 
95
155
  ## Next steps
96
156