opencode-self-improvement 0.33.1 → 0.33.3

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 (30) hide show
  1. package/README.md +34 -20
  2. package/docs/README.md +70 -0
  3. package/docs/adr/0002-window-dedup.md +1 -1
  4. package/docs/adr/README.md +16 -0
  5. package/docs/{auto-capture-evidence.md → internals/auto-capture-evidence.md} +4 -4
  6. package/docs/{export-import.md → internals/export-import.md} +2 -2
  7. package/docs/{import-quarantine.md → internals/import-quarantine.md} +1 -1
  8. package/docs/{injection-cost.md → internals/injection-cost.md} +3 -3
  9. package/docs/{pre-release-ritual.md → internals/pre-release-ritual.md} +2 -2
  10. package/docs/{write-latency.md → internals/write-latency.md} +1 -1
  11. package/docs/{flags.md → reference/flags.md} +3 -2
  12. package/docs/{install.md → reference/install.md} +1 -1
  13. package/docs/{options.md → reference/options.md} +8 -5
  14. package/docs/{surfaces.md → reference/surfaces.md} +1 -1
  15. package/docs/{troubleshooting.md → reference/troubleshooting.md} +1 -1
  16. package/package.json +1 -1
  17. package/src/capture/runtime.ts +2 -2
  18. package/src/store/lock.ts +7 -6
  19. package/src/tools/schema.ts +3 -3
  20. package/src/viewer/page.html +1 -1
  21. package/tui.ts +1 -1
  22. package/vendor/opencode-memory/README.md +8 -0
  23. /package/docs/{contradiction-authority.md → internals/contradiction-authority.md} +0 -0
  24. /package/docs/{development.md → internals/development.md} +0 -0
  25. /package/docs/{recall-quality.md → internals/recall-quality.md} +0 -0
  26. /package/docs/{repo-scoping.md → internals/repo-scoping.md} +0 -0
  27. /package/docs/{secret-redaction.md → internals/secret-redaction.md} +0 -0
  28. /package/docs/{store-concurrency.md → internals/store-concurrency.md} +0 -0
  29. /package/docs/{use-ledger.md → internals/use-ledger.md} +0 -0
  30. /package/docs/{write-gates.md → internals/write-gates.md} +0 -0
package/README.md CHANGED
@@ -23,7 +23,7 @@ Every figure here carries a marker: **measured** (read off a live store), **benc
23
23
 
24
24
  After that, memory is just conversation: ask the agent to remember something and it sticks.
25
25
 
26
- Other install routes — `opencode plugin add`, the Bun version floor, how an unpinned entry resolves `@latest`, and pointing the entry at a checkout: [docs/install.md](docs/install.md).
26
+ Other install routes — `opencode plugin add`, the Bun version floor, how an unpinned entry resolves `@latest`, and pointing the entry at a checkout: [docs/reference/install.md](docs/reference/install.md).
27
27
 
28
28
  ## What you get
29
29
 
@@ -36,9 +36,9 @@ Think of it as a lab notebook the agent keeps for your repo, plus a librarian wh
36
36
  - **Memory-aware compaction** — a long session hands its durable facts to the summarizer instead of losing them.
37
37
  - **Safe across concurrent sessions** — a reader sees the previous store file or the new one, never half of either.
38
38
  - **Decay and consolidation** — `memory_decay` retires stale open threads, `memory_consolidate` proposes near-duplicate merges. Both are dry-run-first and write nothing you did not approve.
39
- - **Export / import (JSONL)** — back the store up or move it between machines; every imported row re-enters through the same gates. See [Export and move between machines](docs/export-import.md).
40
- - **Surfaces** — a footer badge, the `/memory` panel, `/memory-report` for chat clients, and a browser admin editor. See [docs/surfaces.md](docs/surfaces.md).
41
- - **Secret redaction** — credential-shaped values become `[redacted]`. See [docs/secret-redaction.md](docs/secret-redaction.md).
39
+ - **Export / import (JSONL)** — back the store up or move it between machines; every imported row re-enters through the same gates. See [Export and move between machines](docs/internals/export-import.md).
40
+ - **Surfaces** — a footer badge, the `/memory` panel, `/memory-report` for chat clients, and a browser admin editor. See [docs/reference/surfaces.md](docs/reference/surfaces.md).
41
+ - **Secret redaction** — credential-shaped values become `[redacted]`. See [docs/internals/secret-redaction.md](docs/internals/secret-redaction.md).
42
42
  - **`memory_*` tools** — `memory_remember`, `memory_recall`, `memory_update`, `memory_forget`, `memory_undo`, `memory_status`, `memory_evidence`, `memory_export`, `memory_import`, `memory_decay`, `memory_consolidate`, `memory_merge_review`, `memory_list`, `memory_init`.
43
43
  - **Auto-capture** — at the end of a turn, and again at compaction, one cheap model pass reads what just happened and proposes facts worth keeping. They face the same write gates as anything you save by hand. On by default, and it inherits your session's model; `autoCapture: false` turns it off. See [Auto-capture](#auto-capture).
44
44
 
@@ -53,7 +53,7 @@ Zero configuration is the default. Two options change what the model sees:
53
53
  | `injectBudget` | `1200` | Character cap on the injected relevance block and each contextual pull. |
54
54
  | `frontierBudget` | `3 × injectBudget` | Character cap on the session-start open-threads block. A thread longer than the budget is not injected and is reported as omitted. |
55
55
 
56
- Everything else goes in the object form of the plugin entry, and is documented once with its invalid-value rule: the capture options, `contradictionSurface`, `notifyBlocked`, and every environment variable in [docs/options.md](docs/options.md). Read [docs/flags.md](docs/flags.md) before flipping `OPENCODE_MEMORY_DEDUP`, `OPENCODE_MEMORY_SYMPTOM` or `OPENCODE_MEMORY_QUERY_GATE` — each switches off behaviour a measurement decided, and each has an invalid-value rule that surprises people.
56
+ Everything else goes in the object form of the plugin entry, and is documented once with its invalid-value rule: the capture options, `contradictionSurface`, `notifyBlocked`, and every environment variable in [docs/reference/options.md](docs/reference/options.md). Read [docs/reference/flags.md](docs/reference/flags.md) before flipping `OPENCODE_MEMORY_DEDUP`, `OPENCODE_MEMORY_SYMPTOM` or `OPENCODE_MEMORY_QUERY_GATE` — each switches off behaviour a measurement decided, and each has an invalid-value rule that surprises people.
57
57
 
58
58
  ## Auto-capture
59
59
 
@@ -71,7 +71,7 @@ It is **on by default** and needs no model name to run. With `captureModel` unse
71
71
 
72
72
  **The honest caveat.** The trigger fires and the write survives on a real host: `e2e/capture.test.ts` drives `opencode run` and a capture pass starts in 12 of 12 runs. What has not been seen is a live store completing a pass — no `auto_capture_*` line exists anywhere in the maintainer's evidence history — and nothing about quality is measured: what auto-capture would write, how often it duplicates a memory you would have written yourself, and what it costs. Because the switch is on by default, that unmeasured pass runs on every install unless you turn it off; `autoCapture: false` is the one-line answer if you would rather wait for the numbers.
73
73
 
74
- What has been established, and by which kind of evidence, is itemised in [docs/auto-capture-evidence.md](docs/auto-capture-evidence.md). Read that file before quoting any figure in it — two of the entries are defects found in the measuring bench itself, and the corrected numbers are the ones recorded there. `bench/capture-trigger-results.md` is a **bench** simulation of trigger *timing* with a scripted extractor; it answers "which moment is worth mining", not "does this earn its keep".
74
+ What has been established, and by which kind of evidence, is itemised in [docs/internals/auto-capture-evidence.md](docs/internals/auto-capture-evidence.md). Read that file before quoting any figure in it — two of the entries are defects found in the measuring bench itself, and the corrected numbers are the ones recorded there. `bench/capture-trigger-results.md` is a **bench** simulation of trigger *timing* with a scripted extractor; it answers "which moment is worth mining", not "does this earn its keep".
75
75
 
76
76
  **Am I armed?** `memory_evidence` answers on the `plugin_load` line: `capture=on` (the default), `capture=off` (`autoCapture: false`), `invalid_model`, `no_capabilities`, or `switch_mismatch`. `capture=on` plus no `auto_capture_*` line after a session means the pass did not complete, not that your configuration is wrong; #404 found that mechanism and its fix is merged. On desktop this needs `opencode service restart` after an edit — relaunching the app keeps the old service and its already-parsed options alive.
77
77
 
@@ -84,13 +84,13 @@ A memory is a claim about your code, so it gets checked like one. Four gates run
84
84
  3. **GATE-3 — no duplicates.** Near-duplicates collapse into the existing row; a contradiction with a superseded memory is rejected.
85
85
  4. **GATE-4 — promotion or block.** The row lands, or the call returns the reason.
86
86
 
87
- Nothing is deleted. `memory_update` supersedes the old row and `memory_forget` records a retirement, so history stays readable, and `memory_undo` restores a snapshot when a change turns out wrong. `memory_update` picks its row by `query` — an id, a clock fragment such as `00:11:22.123`, or a unique substring of its text — and a query that matches nothing, or several rows, writes nothing and says so. What carries over to the new row, what a `PARTIAL` reply means for the rows on disk, and what promotion evidence samples: [docs/write-gates.md](docs/write-gates.md).
87
+ Nothing is deleted. `memory_update` supersedes the old row and `memory_forget` records a retirement, so history stays readable, and `memory_undo` restores a snapshot when a change turns out wrong. `memory_update` picks its row by `query` — an id, a clock fragment such as `00:11:22.123`, or a unique substring of its text — and a query that matches nothing, or several rows, writes nothing and says so. What carries over to the new row, what a `PARTIAL` reply means for the rows on disk, and what promotion evidence samples: [docs/internals/write-gates.md](docs/internals/write-gates.md).
88
88
 
89
- **Guided constants (#349 / #351, experimental).** You and the code disagree about a constant, and who is right depends on what you said: capture records whether you stated the required value (`spec` — you are the authority) or described how working code behaves (`behavior` — code is the authority), and the CONFLICT verdict follows that class. The verdict table, what the code check will read, and the accepted residual: [docs/contradiction-authority.md](docs/contradiction-authority.md).
89
+ **Guided constants (#349 / #351, experimental).** You and the code disagree about a constant, and who is right depends on what you said: capture records whether you stated the required value (`spec` — you are the authority) or described how working code behaves (`behavior` — code is the authority), and the CONFLICT verdict follows that class. The verdict table, what the code check will read, and the accepted residual: [docs/internals/contradiction-authority.md](docs/internals/contradiction-authority.md).
90
90
 
91
91
  ## Repo scoping
92
92
 
93
- Rows are stamped with your git origin (an id that survives re-clones and moves between machines) or, without an origin, a hash of the normalized directory path. Reads — injection, recall, the frontier block, compaction, `memory_forget` and decay — see the current repo plus global rows. Writes follow the stricter direction: a named session whose repository cannot be resolved has **no write target**, so `memory_remember`, `memory_update`, `memory_import` and auto-capture refuse it (evidence `write_refused`) rather than stamp your content into another workspace or publish it as an unstamped row. Preferences that should follow you everywhere go in with `memory_remember global: true`. Identity derivation and legacy hashes, evidence attribution when a session moves repositories mid-operation, and the viewer's separate admin seat: [docs/repo-scoping.md](docs/repo-scoping.md).
93
+ Rows are stamped with your git origin (an id that survives re-clones and moves between machines) or, without an origin, a hash of the normalized directory path. Reads — injection, recall, the frontier block, compaction, `memory_forget` and decay — see the current repo plus global rows. Writes follow the stricter direction: a named session whose repository cannot be resolved has **no write target**, so `memory_remember`, `memory_update`, `memory_import` and auto-capture refuse it (evidence `write_refused`) rather than stamp your content into another workspace or publish it as an unstamped row. Preferences that should follow you everywhere go in with `memory_remember global: true`. Identity derivation and legacy hashes, evidence attribution when a session moves repositories mid-operation, and the viewer's separate admin seat: [docs/internals/repo-scoping.md](docs/internals/repo-scoping.md).
94
94
 
95
95
  ## What memory is worth, measured
96
96
 
@@ -105,7 +105,7 @@ Two results. Only two are quoted, each with its `n` and the seat it ran on, beca
105
105
 
106
106
  **What is not claimed here.** No token saving. No dollar figure. The seat above is a local box with no cache price; on a hosted provider a cache miss costs roughly 0.1× read and 1.25× write, which is a different claim and cannot be quoted from these numbers.
107
107
 
108
- **Rules for any cost claim in this repository** — the published numbers live in `bench/claims.json`, and `test/claims.test.ts` enforces that file and this one in CI:
108
+ **Rules for any cost claim in this repository** — the published numbers live in `bench/claims.json`, and `test/host/claims.test.ts` enforces that file and this one in CI:
109
109
 
110
110
  - No cost claim below **n=6 pairs per arm**. A ratio at `6 ≤ n < 21` is labelled **"20% resolution"**.
111
111
  - A **seat** and a **metric** are named on the same line as the number.
@@ -123,7 +123,7 @@ Injecting memory costs prompt bytes, and prompt bytes are what a provider bills
123
123
  - **Things you said outright ride first.** A row auto-capture tagged `user-guided` — "the correct sales tax rate is 8.25%" — rides ahead of the lexical picks, newest-first, at most three, inside the budget. Only auto-capture mints the tag; `memory_remember`, updates and imports strip it, because always-riding priority is a poisoning amplifier.
124
124
  - **Budgets are hard, receipts are real.** The block and each pull are capped at `injectBudget` characters, the frontier at `frontierBudget`, trimmed at whole-memory boundaries. The badge shows the provider's own `tokens.cache` accounting; a host that reports nothing shows nothing. Auto-capture is the one place with no receipt at all — it is its own call after the turn — so `memory_status` prints it as `receipt=none`, an estimate.
125
125
 
126
- **Bench** — on a deterministic workload the shipped policy injects **12.3% fewer characters** than the naive policy, measured over the whole memory section: bytes on a synthetic run, not tokens and not a provider bill. The four-policy table, what the invalidation counter does and does not count, what the workload cannot show, and an author-reported provider audit (input tokens only, not a total and not a saving): [docs/injection-cost.md](docs/injection-cost.md). Reproduce the byte workload with `bun run bench`.
126
+ **Bench** — on a deterministic workload the shipped policy injects **12.3% fewer characters** than the naive policy, measured over the whole memory section: bytes on a synthetic run, not tokens and not a provider bill. The four-policy table, what the invalidation counter does and does not count, what the workload cannot show, and an author-reported provider audit (input tokens only, not a total and not a saving): [docs/internals/injection-cost.md](docs/internals/injection-cost.md). Reproduce the byte workload with `bun run bench`.
127
127
 
128
128
  ## Recall quality
129
129
 
@@ -142,11 +142,11 @@ No vector database, no embedding model, no API key: a keyword matcher. That is a
142
142
  - **Exact keyword lookup.** In a long `memory_recall` query, one complete authored keyword can identify a single visible candidate. Automatic prompt injection still requires two shared concepts for long queries.
143
143
  - **`memory_recall` returns 5 rows, not 20.** A live audit of 1,090 recall events found a rank-1 row used in a later tool call at 3.4x the rate of a random store row, and ranks 11–20 at 1.16x — noise. Pass `limit` for a wider sweep.
144
144
 
145
- The abstain-by-design rule, the permutation control behind the `kw` numbers, and the eval's caveats — a synthetic dataset, an adversarial class mix, single-gold scoring: [docs/recall-quality.md](docs/recall-quality.md). Full methodology and all store sizes: `bench/recall-results.md`. Reproduce with `bun run bench:recall`.
145
+ The abstain-by-design rule, the permutation control behind the `kw` numbers, and the eval's caveats — a synthetic dataset, an adversarial class mix, single-gold scoring: [docs/internals/recall-quality.md](docs/internals/recall-quality.md). Full methodology and all store sizes: `bench/recall-results.md`. Reproduce with `bun run bench:recall`.
146
146
 
147
147
  ## Write latency
148
148
 
149
- A write that cites code references builds one tree index — a single recursive walk that prunes `node_modules` and VCS directories — shared by GATE-1 and GATE-2, and reads each source file at most once. **Bench** on a 5,300-file fixture: 17ms, 15ms and 20ms for 1, 3 and 5 embedded call forms, against 105ms, 136ms and 169ms for one scan per form. The shipped column is flat because the tree is walked once no matter how many references the write cites. The fixture, the table and `bun run bench:write`: [docs/write-latency.md](docs/write-latency.md).
149
+ A write that cites code references builds one tree index — a single recursive walk that prunes `node_modules` and VCS directories — shared by GATE-1 and GATE-2, and reads each source file at most once. **Bench** on a 5,300-file fixture: 17ms, 15ms and 20ms for 1, 3 and 5 embedded call forms, against 105ms, 136ms and 169ms for one scan per form. The shipped column is flat because the tree is walked once no matter how many references the write cites. The fixture, the table and `bun run bench:write`: [docs/internals/write-latency.md](docs/internals/write-latency.md).
150
150
 
151
151
  ## The store keeps score
152
152
 
@@ -163,7 +163,7 @@ two distinct failing turns and two rides with unknown outcomes. Totals cover
163
163
  the store; individual rows follow repository visibility. Check the underlying
164
164
  memory before acting on a candidate. Gate failures alone cannot establish harm.
165
165
 
166
- Sample `STORE` output, the credit rule and its throttle, the consolidation tie-break, and capture lag: [docs/use-ledger.md](docs/use-ledger.md).
166
+ Sample `STORE` output, the credit rule and its throttle, the consolidation tie-break, and capture lag: [docs/internals/use-ledger.md](docs/internals/use-ledger.md).
167
167
 
168
168
  ## Consolidation
169
169
 
@@ -174,19 +174,23 @@ The rule is: never merge two entries unless every question that used to find eit
174
174
  - **Deterministic.** The canonical row is the survivor's prose verbatim plus the absorbed rows' aliases as keywords. No model rewrites anything.
175
175
  - **Proven by recorded reads.** Every read the ledger recorded for a cluster is replayed against the merged store, and a merge is proposed only when the canonical row catches at least as many of the cluster's own reads as the best single member did alone. A cluster with no recorded reads is reported as *unmeasured* and never merged on resemblance.
176
176
 
177
- **Bench** — on the eval dataset the pass takes 200 rows to 52 with **R@3 52 → 53 and R@1 52 → 50**, and store-wide injected characters 25 945c → 6 933c. Both the regression and the budget swap are bounded in CI (`test/consolidate-bench.test.ts`).
177
+ **Bench** — on the eval dataset the pass takes 200 rows to 52 with **R@3 52 → 53 and R@1 52 → 50**, and store-wide injected characters 25 945c → 6 933c. Both the regression and the budget swap are bounded in CI (`test/consolidate/consolidate-bench.test.ts`).
178
178
 
179
179
  ## Secret redaction
180
180
 
181
- One best-effort credential rule set (`src/secrets.ts`) replaces recognized values with `[redacted]`, and it runs at every boundary a credential could persist: the auto-capture prompt before it leaves the plugin, the write gate before content is hashed or analysed, the final write choke point used by gated writes and the viewer's edit and restore paths, and every durable audit line. Covered patterns, and the limits that matter — hex-only secrets and prose credentials it can miss, forward-only scrubbing, and the fact that deleting a row copies it rather than scrubbing it: [docs/secret-redaction.md](docs/secret-redaction.md).
181
+ One best-effort credential rule set (`src/secrets.ts`) replaces recognized values with `[redacted]`, and it runs at every boundary a credential could persist: the auto-capture prompt before it leaves the plugin, the write gate before content is hashed or analysed, the final write choke point used by gated writes and the viewer's edit and restore paths, and every durable audit line. Covered patterns, and the limits that matter — hex-only secrets and prose credentials it can miss, forward-only scrubbing, and the fact that deleting a row copies it rather than scrubbing it: [docs/internals/secret-redaction.md](docs/internals/secret-redaction.md).
182
182
 
183
183
  ## Export and move between machines
184
184
 
185
- `memory_export` writes the store as JSONL **as its caller can read it**: from a plugin session that means your repository plus global rows. `memory_import` reads such a file back, and every imported row re-enters through the same four gates as `memory_remember` (tagged `import`, original tags preserved). Both tools are model-facing, so a path is not a privilege: it must stay inside the store, and a symbolic link cannot carry a request out of it. The reply is a tally — `promoted`, `collapsed`, `blocked`, `skipped`, `downgraded` — not a yes/no. The move step by step, the file format, the confinement limits and the quarantine screen: [docs/export-import.md](docs/export-import.md).
185
+ `memory_export` writes the store as JSONL **as its caller can read it**: from a plugin session that means your repository plus global rows. `memory_import` reads such a file back, and every imported row re-enters through the same four gates as `memory_remember` (tagged `import`, original tags preserved). Both tools are model-facing, so a path is not a privilege: it must stay inside the store, and a symbolic link cannot carry a request out of it. The reply is a tally — `promoted`, `collapsed`, `blocked`, `skipped`, `downgraded` — not a yes/no. The move step by step, the file format, the confinement limits and the quarantine screen: [docs/internals/export-import.md](docs/internals/export-import.md).
186
186
 
187
187
  ## Surfaces
188
188
 
189
- Same data behind each one (`memory_status`; no model call): the terminal **footer badge** — the injected block against its budget plus the measured session prompt-cache hit rate, with the dot color telling you whether the cache is warm — the **`/memory`** session panel, **`/memory-report`** for chat clients where the terminal slots do not exist, and a loopback-only **browser editor** (`bun memory-view`). What each shows, the badge colors, and what binding the editor to a non-loopback host costs you: [docs/surfaces.md](docs/surfaces.md).
189
+ Same data behind each one (`memory_status`; no model call): the terminal **footer badge** — the injected block against its budget plus the measured session prompt-cache hit rate, with the dot color telling you whether the cache is warm — the **`/memory`** session panel, **`/memory-report`** for chat clients where the terminal slots do not exist, and a loopback-only **browser editor** (`bun memory-view`). What each shows, the badge colors, and what binding the editor to a non-loopback host costs you: [docs/reference/surfaces.md](docs/reference/surfaces.md).
190
+
191
+ ## Documentation
192
+
193
+ Every document under `docs/`, one line each with its audience and summary: [docs/README.md](docs/README.md). The accepted architecture decisions, with status and supersession: [docs/adr/README.md](docs/adr/README.md).
190
194
 
191
195
  ## Development
192
196
 
@@ -202,8 +206,18 @@ Use Bun **1.4.4** for development checks, matching CI. `bun run test` and `bun r
202
206
 
203
207
  **Feature order is BDD-first.** A new feature starts by adding or fixing a scenario in `e2e/` that describes the behavior as a user would observe it — before implementation code and before unit tests. If no scenario turns red first, the feature has no observable contract. `e2e/` boots the **real opencode CLI** in a fully isolated instance against a scripted fake model — no API keys, no shared store. It needs `opencode` on `PATH` locally, or `OPENCODE_BIN`.
204
208
 
205
- How the local commands map to CI job names, what the smoke suite really boots, why the published surface is decided by `package.json` `files`, and the pre-release mutation sweep with its artifact policy: [docs/development.md](docs/development.md) and [docs/pre-release-ritual.md](docs/pre-release-ritual.md).
209
+ How the local commands map to CI job names, what the smoke suite really boots, why the published surface is decided by `package.json` `files`, and the pre-release mutation sweep with its artifact policy: [docs/internals/development.md](docs/internals/development.md) and [docs/internals/pre-release-ritual.md](docs/internals/pre-release-ritual.md).
210
+
211
+ ## Layout
212
+
213
+ Two root files are shims, and both exist because OpenCode finds plugins two
214
+ different ways. **Loose plugin discovery** reads `<config>/plugins/<name>/index.ts`
215
+ and, next to it, a sibling `tui.ts` — so the repository root carries `index.ts`
216
+ (re-exporting `src/index.ts`) and `tui.ts` (re-exporting the default of
217
+ `src/tui/panel.tsx`). **Package installs** resolve through `package.json`
218
+ `exports` instead: `"."` → `./index.ts` and `"./tui"` → `./src/tui/panel.tsx`.
219
+ Real code lives under `src/`, one directory per module.
206
220
 
207
221
  ## Troubleshooting
208
222
 
209
- The whole list, one row per problem with its fix, is in [docs/troubleshooting.md](docs/troubleshooting.md): tools not available, a blocked `memory_remember`, an argument-schema rejection, `memory store is busy`, a store on a network share, a stale plugin after an update, auto-capture doing nothing, malformed rows, stray lock files, a missing `/repo-init`, and a clean reset on Windows.
223
+ The whole list, one row per problem with its fix, is in [docs/reference/troubleshooting.md](docs/reference/troubleshooting.md): tools not available, a blocked `memory_remember`, an argument-schema rejection, `memory store is busy`, a store on a network share, a stale plugin after an update, auto-capture doing nothing, malformed rows, stray lock files, a missing `/repo-init`, and a clean reset on Windows.
package/docs/README.md ADDED
@@ -0,0 +1,70 @@
1
+ # Documentation index
2
+
3
+ Every document under `docs/`, with its audience and a one-sentence summary.
4
+ User-facing material lives in [`reference/`](reference/), maintainer evidence
5
+ and design notes in [`internals/`](internals/), and decision records in
6
+ [`adr/`](adr/). The [README](../README.md) holds the quick start; this file
7
+ is the map. A new document anywhere under `docs/` must gain a line below —
8
+ `test/doc-links.test.ts` fails the build when one does not.
9
+
10
+ ## Using the plugin
11
+
12
+ - [Install variants and the version floor](reference/install.md) — users: the install
13
+ paths beyond the README's three steps, how updates are resolved, and the
14
+ supported version floor.
15
+ - [Options and environment variables](reference/options.md) — users: every knob in one
16
+ place, including what an invalid value does.
17
+ - [Research flags](reference/flags.md) — users who want the why: the three flags that
18
+ encode a measured finding rather than a preference, and the evidence behind
19
+ each.
20
+ - [Surfaces](reference/surfaces.md) — users: the four ways to see the same data, all
21
+ reading `memory_status` with no model call.
22
+ - [Troubleshooting, full list](reference/troubleshooting.md) — users: every problem and
23
+ its fix, the common ones and the rarer ones.
24
+ - [Export, import, and moving a store between machines](internals/export-import.md) —
25
+ users moving a store: the JSONL contract, and why you get what you can read.
26
+
27
+ ## How it works, and what the measurements say
28
+
29
+ - [Auto-capture: what the evidence covers](internals/auto-capture-evidence.md) —
30
+ maintainers: separates the three claims people confuse — the event fires,
31
+ the write survives, the live store agrees.
32
+ - [Contradiction authority: the code check and its limits](internals/contradiction-authority.md) —
33
+ maintainers: how the plugin decides when what you said and what the code
34
+ says disagree.
35
+ - [Write gates and promotion evidence](internals/write-gates.md) — maintainers: how a
36
+ memory claim is checked before it lands, the way a pull request is.
37
+ - [Repo scoping: identity, visibility and write refusal](internals/repo-scoping.md) —
38
+ maintainers: the repository label on every row, checked on the way in and
39
+ the way out.
40
+ - [Store concurrency, publication and permissions](internals/store-concurrency.md) —
41
+ maintainers: replacing a store file while other sessions read it — a book
42
+ swap, not a page rewrite.
43
+ - [Import, quarantine and the viewer's edit path](internals/import-quarantine.md) —
44
+ maintainers: a quarantined row stays in the store, withheld from everything
45
+ the model reads.
46
+ - [Secret redaction: what it covers and what it cannot](internals/secret-redaction.md) —
47
+ maintainers: the best-effort credential rules and the limits of a metal
48
+ detector.
49
+ - [The use ledger](internals/use-ledger.md) — maintainers: who looked at a row, when,
50
+ and how it reached them.
51
+ - [Injection epochs and their measured cost](internals/injection-cost.md) —
52
+ maintainers: how often the bytes in front of the model actually change, and
53
+ what that costs.
54
+ - [Recall quality: what the keyword matcher gives up](internals/recall-quality.md) —
55
+ maintainers: where word-overlap matching finds a memory and where it
56
+ misses.
57
+ - [Write latency: one tree walk per write](internals/write-latency.md) — maintainers:
58
+ why a write that cites code references scans the source tree once, not once
59
+ per reference.
60
+
61
+ ## Developing the plugin
62
+
63
+ - [Development internals](internals/development.md) — contributors: what the local
64
+ commands really run, what the smoke suite boots, and how the published npm
65
+ surface is decided.
66
+ - [Pre-release ritual: mutation sweep and artifact policy](internals/pre-release-ritual.md) —
67
+ release owners: break one claimed invariant on purpose and see whether
68
+ anything notices.
69
+ - [Architecture decisions](adr/README.md) — everyone: the accepted designs,
70
+ with status and supersession.
@@ -22,7 +22,7 @@ The live store carries repeated rows — superseded snapshots, cursor rows diffe
22
22
  - Evidence: live-store replay published in the #409 record (§17) and PR #426. The replay's off-arm must set `OPENCODE_MEMORY_DEDUP=0` explicitly — with default-ON, an unset arm measures nothing.
23
23
  - Re-measured 2026-11-19 over the window a repository actually reads — its own rows plus rows carrying no repository stamp (`bun bench/runners/dedup-live-replay.ts`; written up in the [live dedup replay](https://github.com/abogartz/opencode-self-improvement/blob/main/bench/dedup-live-results.md), whose counts are a dated snapshot because the store drifts). The scan neither confirms nor refutes 0.8: among the repository's own active rows no pair reaches the threshold, and once superseded history is included every candidate has a superseded side. It found two other things, and they are the useful part. Near-identical rows can stay active together: the write gate's duplicate check is exact and keyed by type, while this pass compares across types, so identical prose filed as two types lands twice and stays active. This pass is therefore not redundant with the gate. And the pass is inert on the repository's own rows because of its guards, not because the store is clean: of the pairs the pre-`fc59b84` rule would have suppressed, the dropped-chunk guard stops nearly all and the content floor the rest.
24
24
  - Known limitation, from that same replay: 0.8 suppresses a pair that is not a copy. Two active rows naming two different build commands in one scope score 0.824 and pass every guard. Ranking favors recency and the pass keeps the first-ranked row of a clash, so the survivor is the newer, narrower command and the plain build command is what disappears from the reader's view. The threshold trades that against crowding; where a scope holds parallel short facts, it costs real information.
25
- - Raising the default was evaluated on 2026-11-19 and rejected. The pair worth releasing scores 0.8235; the changed-fact pair pinned in `test/dedupe-tool.test.ts` — the same runbook sentence with `friday` replaced by `monday` — scores 0.8333. Any threshold separating them must sit in a window one hundredth wide, which is a constant fitted to two observations, and 0.9 releases both and removes the recency rule above. The two rows have the same shape: one sentence, one long token swapped out. Whether that swap replaced a fact or added one is not visible in a token overlap, so this is not a threshold problem.
25
+ - Raising the default was evaluated on 2026-11-19 and rejected. The pair worth releasing scores 0.8235; the changed-fact pair pinned in `test/recall/dedupe-tool.test.ts` — the same runbook sentence with `friday` replaced by `monday` — scores 0.8333. Any threshold separating them must sit in a window one hundredth wide, which is a constant fitted to two observations, and 0.9 releases both and removes the recency rule above. The two rows have the same shape: one sentence, one long token swapped out. Whether that swap replaced a fact or added one is not visible in a token overlap, so this is not a threshold problem.
26
26
  - The dropped-chunk guard, not the threshold, decides what this pass ever sees. Two rows differing by a timestamp have different dropped fragments and are never compared, so the cursor rows this record names as the motivation are exempt, while prose carrying no short fragments at all is compared and can be suppressed on shape alone.
27
27
 
28
28
 
@@ -0,0 +1,16 @@
1
+ # Architecture decision records
2
+
3
+ One row per decision. `supersedes` and `superseded by` keep the chain
4
+ readable: a reader can tell an accepted decision from a retired one without
5
+ opening the file.
6
+
7
+ | ID | Title | Status | Supersedes | Superseded by |
8
+ | ---- | ----------------------------------------------------------------------------------------- | ---------------- | ---------- | ------------- |
9
+ | 0001 | [Two-concept admission for the recall tool](0001-two-concept-recall-admission.md) | accepted (2026-11) | — | — |
10
+ | 0002 | [Near-duplicate suppression inside the recall window](0002-window-dedup.md) | accepted (2026-11) | — | — |
11
+ | 0003 | [Identifier-aware tokenizer at two granularities](0003-identifier-tokenizer.md) | accepted (2026-11) | — | — |
12
+ | 0004 | [Viewer startup token on non-loopback binds](0004-viewer-startup-token.md) | accepted (2026-11) | — | — |
13
+ | 0005 | [Two-phase teardown for capture passes](0005-capture-teardown-phases.md) | accepted (2026-11) | — | — |
14
+ | 0006 | [Capture prompt integrity: redaction order and faithful citation](0006-capture-prompt-integrity.md) | accepted (2026-11) | — | — |
15
+ | 0007 | [Symptom-first opening for learning and blocker rows](0007-symptom-first-capture.md) | accepted (2026-11) | — | — |
16
+ | 0008 | [Availability verdicts tag rows; they never refuse them](0008-availability-tags-not-refusals.md) | accepted (2026-11) | — | — |
@@ -13,11 +13,11 @@ in the README; this is the record behind them.
13
13
 
14
14
  What is established, from tests and fixtures (no live store involved):
15
15
 
16
- - **The trigger events are ones the host actually emits.** Capture subscribes to `session.execution.succeeded` and `session.execution.interrupted`, the two turn-end events present in a recording of the desktop service (`test/fixtures/host-events.jsonl`). `session.idle`, `session.status` and `session.execution.failed` are *declared* by the host but absent from that recording, so they deliberately do not trigger capture; `test/event-fidelity.test.ts` refuses a trigger that is only declared. An earlier revision subscribed to `session.idle` and stayed silent for days with no signal — reading a declared event as an emitted one is the failure that fixture exists to prevent.
17
- - **The path runs under simulated host traffic** — unit tests hand the plugin the recorded envelopes and assert a candidate lands through the write gate, including conservation (a near-duplicate collapses at the gate instead of writing a second row): `test/capture-auto.test.ts`, `test/capture-compaction.test.ts`. No terminal e2e scenario covers the trigger, so the simulated envelope is the strongest evidence that exists — and fabricating the envelope is exactly what passed while this feature was dead.
18
- - **Identity triggers have their own recording check.** `test/event-fidelity.test.ts` checks `IDENTITY_EVENT_TYPES` against the original 2.1.4 recording plus `test/fixtures/host-session-move.json`, a normalized one-frame extract from a separate 2.2.2 move capture. The extract must declare nonempty provenance and its retained envelopes must round-trip through the lockfile-pinned `@opencode/schema` 2.0.32 decoder. These checks reject missing metadata and malformed envelopes; they do not authenticate the capture. The identity replay uses the plugin subscription, but live plugin rebinding remains unverified. The recording version is distinct from the CI host pin (2.0.26).
16
+ - **The trigger events are ones the host actually emits.** Capture subscribes to `session.execution.succeeded` and `session.execution.interrupted`, the two turn-end events present in a recording of the desktop service (`test/fixtures/host-events.jsonl`). `session.idle`, `session.status` and `session.execution.failed` are *declared* by the host but absent from that recording, so they deliberately do not trigger capture; `test/identity/event-fidelity.test.ts` refuses a trigger that is only declared. An earlier revision subscribed to `session.idle` and stayed silent for days with no signal — reading a declared event as an emitted one is the failure that fixture exists to prevent.
17
+ - **The path runs under simulated host traffic** — unit tests hand the plugin the recorded envelopes and assert a candidate lands through the write gate, including conservation (a near-duplicate collapses at the gate instead of writing a second row): `test/capture/capture-auto.test.ts`, `test/capture/capture-compaction.test.ts`. No terminal e2e scenario covers the trigger, so the simulated envelope is the strongest evidence that exists — and fabricating the envelope is exactly what passed while this feature was dead.
18
+ - **Identity triggers have their own recording check.** `test/identity/event-fidelity.test.ts` checks `IDENTITY_EVENT_TYPES` against the original 2.1.4 recording plus `test/fixtures/host-session-move.json`, a normalized one-frame extract from a separate 2.2.2 move capture. The extract must declare nonempty provenance and its retained envelopes must round-trip through the lockfile-pinned `@opencode/schema` 2.0.32 decoder. These checks reject missing metadata and malformed envelopes; they do not authenticate the capture. The identity replay uses the plugin subscription, but live plugin rebinding remains unverified. The recording version is distinct from the CI host pin (2.0.26).
19
19
 
20
- - **Teardown stops work that is still in flight.** `generate.text` does not take the abort signal, so a capture parked mid-model-call used to wake up after the host disposed the plugin and run the whole write gate against a store its caller had already removed. Cleanup now aborts the subscription, every pass re-checks the signal after the model call and between candidates (a gate already mutating is never cut in half), and cleanup drains the tracked passes under a one-second bound — teardown never waits on the model. `test/capture-dispose-drain.test.ts` parks a capture, disposes, releases, and asserts that no row and no evidence line carries a timestamp after disposal (#211).
20
+ - **Teardown stops work that is still in flight.** `generate.text` does not take the abort signal, so a capture parked mid-model-call used to wake up after the host disposed the plugin and run the whole write gate against a store its caller had already removed. Cleanup now aborts the subscription, every pass re-checks the signal after the model call and between candidates (a gate already mutating is never cut in half), and cleanup drains the tracked passes under a one-second bound — teardown never waits on the model. `test/capture/capture-dispose-drain.test.ts` parks a capture, disposes, releases, and asserts that no row and no evidence line carries a timestamp after disposal (#211).
21
21
 
22
22
  - **The trigger is live on a real host, and the write now survives it.** An end-to-end scenario drives `opencode run` against a real turn with a scripted provider (`e2e/capture.test.ts`): the turn-end event fires and a capture pass starts, 12 of 12 runs. It used to reach the write gate in only some of them — 3 of 12 in one sample, 6 of 12 in a controlled A/B against the same script, 12 of 12 in two samples after the fix. `opencode run` disposes the plugin as the turn ends, and `captureCleanup` aborted every in-flight pass before its gate ran: the #211 contract, correct for the teardown it was written for and fatal here, because nothing is being torn down and the process simply exits. Cleanup now distinguishes the two cases — a pass still parked in the model call is abandoned, a pass that already holds its answer is drained, because its remaining work is local and milliseconds. All of #211's disposal assertions still pass unchanged. Fixed on this branch, #404.
23
23
 
@@ -44,7 +44,7 @@ it to itself.
44
44
  The line format, what an import will believe about `status:"open"`, and the two
45
45
  confinement limits no path check closes (a hard link inside `exports/`, and the
46
46
  looser check on intermediate components):
47
- [docs/import-quarantine.md](import-quarantine.md).
47
+ [docs/internals/import-quarantine.md](import-quarantine.md).
48
48
 
49
49
  ## Quarantine
50
50
 
@@ -58,4 +58,4 @@ Review the queue in the viewer's **quarantined** filter.
58
58
  What the screen covers, what it misses, how an existing store is re-tagged, what
59
59
  releasing quarantine does and what it leaves alone, and why direct
60
60
  `memory_remember` and viewer edits are not scanned:
61
- [docs/import-quarantine.md](import-quarantine.md).
61
+ [docs/internals/import-quarantine.md](import-quarantine.md).
@@ -6,7 +6,7 @@ store where you can read it, and is withheld from everything the model reads.
6
6
  What the prose screen catches and misses, how an existing store gets
7
7
  re-tagged, what releasing quarantine does, and which writes it does not
8
8
  cover. The export contract and the import tally are in
9
- [docs/export-import.md](export-import.md).
9
+ [docs/internals/export-import.md](export-import.md).
10
10
 
11
11
  Import and auto-capture also scan incoming prose for a small set of instruction-override, role-header, and download/execute patterns. Matching rows still face every write gate; a promoted match is tagged `quarantine` and withheld from recall, prompt/frontier injection, compaction anchors, contextual pull, scope/type listings, consolidation proposals, and decay. Decay previews do not quote these rows, and applied decay leaves them in the human review queue. The import reply counts quarantined promotions, gate evidence records pattern identifiers without copying the matched prose, and `/memory-report` lists review IDs for the caller's repository.
12
12
 
@@ -14,8 +14,8 @@ claim, and a provider audit reported by its author.
14
14
  - **A session never pays for bytes it is not riding.** A memory *you* saved in this session is a fact you already produced — it is in your own transcript — so it never busts your cache. The test is not "did the store change" but "would the frozen bytes still have been produced from the same inputs, minus the rows this session authored since": a correction, blocklisting, redaction or supersession of a row you are riding, and anything another session, the viewer or an import wrote, all still land on your next request.
15
15
  - **Two-concept threshold.** A free-text prompt must share at least two distinct concepts with a memory for it to be injected; keyword-length queries (one or two words) need only one. Silence on single-word coincidences is deliberate; an explicit `memory_recall` search can admit a complete authored keyword unique among its visible candidates.
16
16
  - **Identifiers split.** `getUserAccount`, `get_user_account`, `get-user-account` and `get.user.account` are one concept to the matcher rather than four, and a memory citing `src/recall/score.ts` answers a session that typed the path ([#409](https://github.com/abogartz/opencode-self-improvement/issues/409)). Measured on the published eval: aggregate recall unchanged, wrong-memory-first at the top falls 6% → 5%. Replayed over 1,091 logged recall queries through this scorer against the live store: 92.3% of top-5 sets are identical and 97.5% keep their top row.
17
- - **User-stated guidance rides ahead of relevance.** A row auto-capture tagged `user-guided` — something you said outright, like "the correct sales tax rate is 8.25%" — rides the block ahead of the lexical picks: newest-first, at most three, and `injectBudget` still bounds the whole block (`test/hint-channel.test.ts`). The channel exists because ranking cannot bridge vocabulary: a prompt about "the injected bug" shares no word with a row stating a tax rate, and the shipped matcher scored it zero ([#334](https://github.com/abogartz/opencode-self-improvement/issues/334)). `memory_recall` and the contextual pull stay query-driven — the channel changes only what rides the prompt. Because always-riding priority is a poisoning amplifier, the tag is minted by auto-capture alone: `memory_remember`, `memory_update` replacements and JSONL imports strip it, along with the contradiction fields ([#342](https://github.com/abogartz/opencode-self-improvement/issues/342), `test/guidance-provenance.test.ts`).
18
- - **The block re-scores at every user turn.** An epoch is not frozen at the first request: a later prompt re-scores, and the epoch MOVES only when the rendered bytes move — a prompt change that selects the same rows in the same order costs no cache bust ([#340](https://github.com/abogartz/opencode-self-improvement/issues/340), `test/epoch.test.ts`). Order is part of those bytes on this build: the lexical picks render in score order, so a prompt that keeps the same rows and re-ranks them moves the bytes and pays the bust. Canonical render order, which removes that churn, is still open ([#388](https://github.com/abogartz/opencode-self-improvement/issues/388), [#396](https://github.com/abogartz/opencode-self-improvement/pull/396)).
17
+ - **User-stated guidance rides ahead of relevance.** A row auto-capture tagged `user-guided` — something you said outright, like "the correct sales tax rate is 8.25%" — rides the block ahead of the lexical picks: newest-first, at most three, and `injectBudget` still bounds the whole block (`test/inject/hint-channel.test.ts`). The channel exists because ranking cannot bridge vocabulary: a prompt about "the injected bug" shares no word with a row stating a tax rate, and the shipped matcher scored it zero ([#334](https://github.com/abogartz/opencode-self-improvement/issues/334)). `memory_recall` and the contextual pull stay query-driven — the channel changes only what rides the prompt. Because always-riding priority is a poisoning amplifier, the tag is minted by auto-capture alone: `memory_remember`, `memory_update` replacements and JSONL imports strip it, along with the contradiction fields ([#342](https://github.com/abogartz/opencode-self-improvement/issues/342), `test/gate/guidance-provenance.test.ts`).
18
+ - **The block re-scores at every user turn.** An epoch is not frozen at the first request: a later prompt re-scores, and the epoch MOVES only when the rendered bytes move — a prompt change that selects the same rows in the same order costs no cache bust ([#340](https://github.com/abogartz/opencode-self-improvement/issues/340), `test/inject/epoch.test.ts`). Order is part of those bytes on this build: the lexical picks render in score order, so a prompt that keeps the same rows and re-ranks them moves the bytes and pays the bust. Canonical render order, which removes that churn, is still open ([#388](https://github.com/abogartz/opencode-self-improvement/issues/388), [#396](https://github.com/abogartz/opencode-self-improvement/pull/396)).
19
19
  - **Hard budgets.** Relevance block and each pull are capped at `injectBudget` characters, the frontier at `frontierBudget`, trimmed at whole-memory boundaries.
20
20
  - **Nothing volatile on the cached prefix.** The standing digest carries no row count and no latest timestamp. Both used to ride the very front of the system prompt, so every saved memory rewrote the prefix and made the next request re-bill the whole conversation; the exact numbers now live where they are free — the footer badge, `/memory`, `memory_status`, the viewer.
21
21
  - **Evidence is never injected**, and the standing system digest is two lines.
@@ -31,7 +31,7 @@ claim, and a provider audit reported by its author.
31
31
  | C — section frozen on rendered bytes | 4 | 3 | 55258 | 2762.9 | 2856 |
32
32
  | D — C + riding bytes (shipped) | 1 | 0 | 53500 | 2675.0 | 2675 |
33
33
 
34
- The invalidation counter counts **byte-moving recomputes**: epochs whose memory-section bytes differ from the previous epoch. It is not a provider cache-miss or re-prefill count, and no status surface claims it is. All three synthetic writes change B and C's bytes; D records no change for these self-writes. Corrections, removals and writes by another session can still move D's bytes, as pinned by `test/epoch.test.ts`. The workload re-scores only when the store fingerprint moves, so its 20 prompts never re-rank one shared set — D's `0` is not evidence about the same-set re-ranking above. D also injects 12.3% fewer **characters** than the naive policy, measured over the whole section — bytes on a deterministic workload, not tokens and not a provider bill. Reproduce this deterministic byte workload:
34
+ The invalidation counter counts **byte-moving recomputes**: epochs whose memory-section bytes differ from the previous epoch. It is not a provider cache-miss or re-prefill count, and no status surface claims it is. All three synthetic writes change B and C's bytes; D records no change for these self-writes. Corrections, removals and writes by another session can still move D's bytes, as pinned by `test/inject/epoch.test.ts`. The workload re-scores only when the store fingerprint moves, so its 20 prompts never re-rank one shared set — D's `0` is not evidence about the same-set re-ranking above. D also injects 12.3% fewer **characters** than the naive policy, measured over the whole section — bytes on a deterministic workload, not tokens and not a provider bill. Reproduce this deterministic byte workload:
35
35
 
36
36
  ```sh
37
37
  bun run bench
@@ -17,11 +17,11 @@ The output is a canonical mutation score — killed over total, with equivalent
17
17
 
18
18
  Run it when you want to know whether the suite still has teeth — after changing tests or coverage, or as a pre-release gate with `bun scripts/test-sweep.ts --fail-on-survivors`, which exits 4 when anything survives. Two lighter checks come first: `bun scripts/test-sweep.ts --validate` confirms every mutation pattern still lands on exactly one source site without running the suite, and `bun scripts/test-sweep.ts --selftest` plants a mutation in a trivially-tested pure function and fails unless the suite kills it — proof the instrument itself can go red.
19
19
 
20
- **Pre-release ritual (decided 2026-11-04, #72):** before pushing a release commit, a human runs `--validate`, then `--selftest`, then `--fail-on-survivors`, and records the mutation score and the survivor list in `bench/RESULTS.md` beside the published evidence. Cadence is pre-release only, run by a person: the sweep is a full suite per mutant and never belongs in CI, where it would cost more than it informs. Survivors become entries on the unpinned-invariant list, not red checks.
20
+ **Pre-release ritual (decided 2026-11-04, #72):** before pushing a release commit, a human runs `--validate`, then `--selftest`, then `--fail-on-survivors`, and records the mutation score and the survivor list in `bench/mutation-sweep.md` (its own file, because `bun run bench` regenerates `bench/results.md` in full). Cadence is pre-release only, run by a person: the sweep is a full suite per mutant and never belongs in CI, where it would cost more than it informs. Survivors become entries on the unpinned-invariant list, not red checks.
21
21
 
22
22
  ### Bench artifacts stay out of git
23
23
 
24
- Raw sweep output is regenerable measurement data, and it was the largest tracked content in the repository. It is not committed (#232). A clone carries the published summaries — `bench/RESULTS.md` and the `bench/*-results.md` files — and the inputs those summaries are rebuilt from. History is not rewritten: the old blobs stay in earlier revisions, so this shrinks new checkouts, not the archive.
24
+ Raw sweep output is regenerable measurement data, and it was the largest tracked content in the repository. It is not committed (#232). A clone carries the published summaries — `bench/results.md` and the `bench/*-results.md` files — and the inputs those summaries are rebuilt from. History is not rewritten: the old blobs stay in earlier revisions, so this shrinks new checkouts, not the archive.
25
25
 
26
26
  | Artifact | How to get it back |
27
27
  | --- | --- |
@@ -22,4 +22,4 @@ bun run bench:write
22
22
  ```
23
23
 
24
24
  What each gate does with what the walk finds:
25
- [docs/write-gates.md](write-gates.md).
25
+ [docs/internals/write-gates.md](write-gates.md).
@@ -2,8 +2,9 @@
2
2
 
3
3
  The three flags that encode a measured finding rather than a preference:
4
4
  what each one enforces, the evidence behind it, and what an invalid value
5
- does. The README names the three and points here; this file is the whole
6
- behaviour.
5
+ does. These are not the general option surface — every other knob lives in
6
+ [Options and environment variables](options.md). The README names the three
7
+ and points here; this file is the whole behaviour.
7
8
 
8
9
  `OPENCODE_MEMORY_SYMPTOM` is the clearest case. A lesson saved as "in this
9
10
  session we fixed the flaky test" shares no words with the query a future
@@ -42,4 +42,4 @@ A config edit needs a restart to take effect. On the desktop app, relaunching th
42
42
  app is not enough: the background service stays alive with the options it already
43
43
  parsed, so use `opencode service restart`. That is also why `memory_evidence` can
44
44
  report a `capture=` value your config no longer contains. See
45
- [docs/troubleshooting.md](troubleshooting.md).
45
+ [docs/reference/troubleshooting.md](troubleshooting.md).
@@ -1,7 +1,10 @@
1
1
  # Options and environment variables
2
2
 
3
- Every knob, in one place. The README keeps the ones you are likely to set; this
4
- file is the complete reference, including what an invalid value does.
3
+ Every knob, in one place — the general option surface. The three flags that
4
+ encode a measured finding rather than a preference are documented separately
5
+ in [Research flags](flags.md). The README keeps the ones you are likely to
6
+ set; this file is the complete reference, including what an invalid value
7
+ does.
5
8
 
6
9
  ## Plugin options
7
10
 
@@ -17,7 +20,7 @@ Set them in the object form of the plugin entry in `opencode.json(c)`:
17
20
  | --- | --- | --- |
18
21
  | `injectBudget` | `1200` | Character cap on the injected relevance block and each contextual pull; trimmed at whole-memory boundaries. Env fallback: `OPENCODE_MEMORY_INJECT_BUDGET`. |
19
22
  | `frontierBudget` | `3 × injectBudget` | Character cap on the session-start open-threads block. A thread longer than the budget is not injected and is reported as omitted. Env fallback: `OPENCODE_MEMORY_FRONTIER_BUDGET`. |
20
- | `contradictionSurface` | `true` | Experimental: compare guided constant claims with bounded source reads and render a class-specific CONFLICT verdict. Set `false` to skip code checks and retain plain guidance. See [docs/contradiction-authority.md](contradiction-authority.md). |
23
+ | `contradictionSurface` | `true` | Experimental: compare guided constant claims with bounded source reads and render a class-specific CONFLICT verdict. Set `false` to skip code checks and retain plain guidance. See [docs/internals/contradiction-authority.md](../internals/contradiction-authority.md). |
21
24
  | `notifyBlocked` | `true` | Terminal (TUI) only: toast when a write gate blocks a write. Blocks are always in `memory_evidence` either way. |
22
25
  | `autoCapture` | `true` | Master switch for auto-capture. On, so a plain install mines turn ends and compactions. Set `false` for no capture model call at all. |
23
26
  | `captureModel` | inherits | `"provider/id"` model used for auto-capture. Unset means the model the session is using, else the host default. An explicit value that is not `provider/id` disables capture with a startup warning rather than substituting a model. |
@@ -30,7 +33,7 @@ Set them in the object form of the plugin entry in `opencode.json(c)`:
30
33
  | Variable | Purpose |
31
34
  | --- | --- |
32
35
  | `OPENCODE_MEMORY_DIR` | Store location (default `~/.config/opencode/memory`). |
33
- | `OPENCODE_MEMORY_ALLOW_OUTSIDE_PATHS` | Operator-only. When truthy, `memory_export`/`memory_import` accept paths anywhere on disk instead of confining themselves to the store. Off by default. It is read from the plugin process's own environment, so a model cannot grant it to itself through a tool argument. See [docs/import-quarantine.md](import-quarantine.md). |
36
+ | `OPENCODE_MEMORY_ALLOW_OUTSIDE_PATHS` | Operator-only. When truthy, `memory_export`/`memory_import` accept paths anywhere on disk instead of confining themselves to the store. Off by default. It is read from the plugin process's own environment, so a model cannot grant it to itself through a tool argument. See [docs/internals/import-quarantine.md](../internals/import-quarantine.md). |
34
37
  | `OPENCODE_MEMORY_INJECT_BUDGET` | Fallback for `injectBudget`. |
35
38
  | `OPENCODE_MEMORY_FRONTIER_BUDGET` | Fallback for `frontierBudget`. |
36
39
  | `OPENCODE_COMMANDS_DIR` | Where the plugin mirrors its slash commands (default `~/.config/opencode/commands`). |
@@ -38,4 +41,4 @@ Set them in the object form of the plugin entry in `opencode.json(c)`:
38
41
  | `OPENCODE_VIEWER_PORT` | Admin editor port (default `8787`). |
39
42
  | `OPENCODE_VIEWER_ALLOWED_HOSTS` | Comma-separated hosts beyond loopback. |
40
43
 
41
- `OPENCODE_MEMORY_DEDUP`, `OPENCODE_MEMORY_SYMPTOM` and `OPENCODE_MEMORY_QUERY_GATE` are documented separately in [docs/flags.md](flags.md): they switch behaviour that a measurement decided, so the evidence behind each one matters more than the default.
44
+ `OPENCODE_MEMORY_DEDUP`, `OPENCODE_MEMORY_SYMPTOM` and `OPENCODE_MEMORY_QUERY_GATE` are documented separately in [docs/reference/flags.md](flags.md): they switch behaviour that a measurement decided, so the evidence behind each one matters more than the default.
@@ -36,4 +36,4 @@ plain HTTP with no authentication — only do it on a network you control.
36
36
 
37
37
  The viewer is a trusted admin seat. Its edits and deleted-entry restores skip the
38
38
  model-facing grounding and deduplication gates but honor the same value
39
- rejections: [docs/import-quarantine.md](import-quarantine.md).
39
+ rejections: [docs/internals/import-quarantine.md](../internals/import-quarantine.md).
@@ -26,4 +26,4 @@ The seven cases a session actually hits.
26
26
  | `memory store is busy` | A store write exhausted its 5s lock-wait budget, so the mutation is refused rather than run unlocked. Retry after contention clears. An operation spanning several files or steps may have completed earlier steps; refusal is not a rollback of those steps. If the reply reports `PARTIAL`, inspect the named rows and `memory_evidence` / `memory_undo` before retrying. A process that is killed releases the lock when it dies — there is no stale window to wait out. |
27
27
  | Writes report a disk I/O error and the store is on a share | The lock's write-ahead log needs mmap'd shared memory, which SQLite does not support on network filesystems. SMB, NFS and OneDrive-mounted roots are unsupported — move `OPENCODE_MEMORY_DIR` to local disk. |
28
28
  | Stale plugin after an update | `opencode plugin update opencode-self-improvement` (or bump the pinned `@version` in the `plugins` entry) and restart opencode. On desktop use `opencode service restart`: relaunching the app leaves the background service — and the plugin version and options it already parsed — alive. |
29
- | Auto-capture does nothing | `memory_evidence` says which case you are in from the `plugin_load` line: `capture=on` (the default), `capture=off` (you set `autoCapture: false`), `invalid_model`, `no_capabilities` or `switch_mismatch`. `capture=on` with no `auto_capture_*` line after a session means the pass did not complete, and is not your configuration — see [Auto-capture](../README.md#auto-capture). On desktop, changing any of these options needs `opencode service restart`. The same `plugin_load` line carries `subscribed=[…]`, listing the event types that subscription really reacts to. |
29
+ | Auto-capture does nothing | `memory_evidence` says which case you are in from the `plugin_load` line: `capture=on` (the default), `capture=off` (you set `autoCapture: false`), `invalid_model`, `no_capabilities` or `switch_mismatch`. `capture=on` with no `auto_capture_*` line after a session means the pass did not complete, and is not your configuration — see [Auto-capture](../../README.md#auto-capture). On desktop, changing any of these options needs `opencode service restart`. The same `plugin_load` line carries `subscribed=[…]`, listing the event types that subscription really reacts to. |
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "opencode-self-improvement",
3
- "version": "0.33.1",
3
+ "version": "0.33.3",
4
4
  "description": "Durable memory for opencode: remember facts, decisions, and commands across sessions, plus a one-command per-repo setup (/repo-init).",
5
5
  "main": "index.ts",
6
6
  "exports": {
@@ -9,7 +9,6 @@ import {
9
9
  RESTATABLE_TAG,
10
10
  USER_GUIDED_TAG,
11
11
  } from "../core/tags.ts";
12
- import { record, recordCaptureLag } from "../telemetry/record.ts";
13
12
  import { type GateContext, runWriteGate } from "../gate/gate.ts";
14
13
  import { captureSessionID } from "../identity/host-events.ts";
15
14
  import { bindSessionProvisional, writeTarget } from "../identity/repokey.ts";
@@ -23,6 +22,7 @@ import {
23
22
  import { quarantineCandidate } from "../store/quarantine/quarantine.ts";
24
23
  import { flattenMemoryText } from "../store/sanitize.ts";
25
24
  import { redactSecrets } from "../store/secrets.ts";
25
+ import { record, recordCaptureLag } from "../telemetry/record.ts";
26
26
  import { type AvailabilityIndex, availabilityIndex } from "./available.ts";
27
27
  import { parseCandidates, parseModelRef } from "./candidates.ts";
28
28
  import { claimVerdictFromContent } from "./checked.ts";
@@ -154,7 +154,7 @@ export function resetCaptureCooldowns(): void {
154
154
  // ---- capture trigger vocabulary -------------------------------------
155
155
  // Single source of truth for capture subscriptions. Both turn-end events were
156
156
  // observed on the desktop service (test/fixtures/host-events.jsonl).
157
- // test/event-fidelity.test.ts requires every trigger to appear in both that
157
+ // test/identity/event-fidelity.test.ts requires every trigger to appear in both that
158
158
  // recording and the installed @opencode/schema manifest: a declared event
159
159
  // alone is insufficient evidence that the host emits it.
160
160
  // Identity triggers have a separate observed check in that test, combining
package/src/store/lock.ts CHANGED
@@ -49,10 +49,11 @@
49
49
  // serialise. That is a deliberate cut, not an oversight — the lock is the
50
50
  // correctness mechanism for the whole store, so a silently unserialised store
51
51
  // on a share was the worse option.
52
+
53
+ import { Database } from "bun:sqlite";
52
54
  import { AsyncLocalStorage } from "node:async_hooks";
53
55
  import { chmod, unlink } from "node:fs/promises";
54
56
  import { basename, dirname, join } from "node:path";
55
- import { Database } from "bun:sqlite";
56
57
  import { ensureDir } from "../core/logfmt/publish.ts";
57
58
  import { record } from "../telemetry/record.ts";
58
59
 
@@ -245,7 +246,7 @@ process.on("exit", closeAllLockDatabases);
245
246
  * It has to be an async-context set, not a Map keyed by lock. A Map is
246
247
  * process-wide, so a task that merely happens to run while an UNRELATED task
247
248
  * holds a lock reads "already held" and writes with no lock at all — measured:
248
- * the sibling-holder test in test/lock-narrowing.test.ts resolved instead of
249
+ * the sibling-holder test in test/store/lock-narrowing.test.ts resolved instead of
249
250
  * refusing, which is silent data loss and worse than the bug this module fixes.
250
251
  * AsyncLocalStorage scopes the set to the chain that acquired it, so a nested
251
252
  * call inherits and a sibling does not. Verified on Bun 1.4.3 across deep await
@@ -268,7 +269,7 @@ const heldLocks = new AsyncLocalStorage<ReadonlySet<string>>();
268
269
  * made the one situation this lock is supposed to survive — a wait that names
269
270
  * itself an extension of busy — fatal: a writer got "store lock unavailable:
270
271
  * database is locked" instead of waiting the few hundred microseconds the other
271
- * side needs. Measured on test/scenarios-consistency.test.ts, which kills
272
+ * side needs. Measured on test/host/scenarios-consistency.test.ts, which kills
272
273
  * racers mid-write.
273
274
  *
274
275
  * SQLITE_BUSY is 5 and every extension is 5 | (kind << 8), so the low byte is
@@ -289,7 +290,7 @@ function contention(err: unknown): boolean {
289
290
  * SQLite detects the case exactly: SQLITE_IOERR_VNODE is reported when the inode
290
291
  * behind an open handle changes. It is reachable without a defect — the store
291
292
  * directory is not ours to protect. A user can wipe and rebuild a memory root
292
- * while a session is alive, and test/hits.test.ts does it on purpose. The right
293
+ * while a session is alive, and test/telemetry/hits.test.ts does it on purpose. The right
293
294
  * answer is to throw the stale connection away and open a fresh one, which is
294
295
  * what a handle against a replaced file needs; the wrong answer is to wait, and
295
296
  * the other wrong answer is to keep the poisoned connection and fail every later
@@ -307,7 +308,7 @@ function staleHandle(err: unknown): boolean {
307
308
  }
308
309
 
309
310
  /**
310
- * The classifier above, exposed for its pin in test/lock.test.ts.
311
+ * The classifier above, exposed for its pin in test/store/lock.test.ts.
311
312
  *
312
313
  * Getting this one line wrong is what made a crashed holder fatal, and the
313
314
  * integration test for it is probabilistic: whether a second opener arrives
@@ -315,7 +316,7 @@ function staleHandle(err: unknown): boolean {
315
316
  * itself is not probabilistic, so it gets a table.
316
317
  */
317
318
  export const isLockContention = contention;
318
- /** Test seam for the stale-handle classification in test/lock.test.ts. */
319
+ /** Test seam for the stale-handle classification in test/store/lock.test.ts. */
319
320
  export const isStaleLockHandle = staleHandle;
320
321
 
321
322
  /**
@@ -14,10 +14,10 @@
14
14
  // that is what the 4-gate pipeline is for.
15
15
  // * Store reads deliberately do NOT use zod: they get a plain ISO-instant
16
16
  // check in memory.ts (row identity), where the row schema lives.
17
- import { z, type ZodTypeAny } from "zod";
17
+ import { type ZodTypeAny, z } from "zod";
18
18
  import { STATUSES, TYPES } from "../core/types.ts";
19
- import { flattenMemoryText } from "../store/sanitize.ts";
20
19
  import { MAX_KEYWORDS } from "../store/model/memory.ts";
20
+ import { flattenMemoryText } from "../store/sanitize.ts";
21
21
 
22
22
  type JSONSchema = Record<string, unknown>;
23
23
 
@@ -265,7 +265,7 @@ export const RestoreEntryBody = z.object({
265
265
 
266
266
  /**
267
267
  * Generate the host-facing JSON Schema. Matches the pre-zod hand-written
268
- * builders byte-for-byte modulo key order (test/boundaries.test.ts pins all
268
+ * builders byte-for-byte modulo key order (test/tools/boundaries.test.ts pins all
269
269
  * 13 against a capture from main): $schema stripped, empty `required` kept.
270
270
  */
271
271
  export function wire(schema: ZodTypeAny): JSONSchema {
@@ -147,7 +147,7 @@
147
147
  </div>
148
148
 
149
149
  <script id="viewer-helpers">
150
- // Pure render helpers — DOM-free by contract so test/viewer.test.ts can eval
150
+ // Pure render helpers — DOM-free by contract so test/viewer/viewer.test.ts can eval
151
151
  // THIS block standalone and assert the shipped escaping. Keep it
152
152
  // free of document/window references.
153
153
  // Store values are untrusted by principle, not just by policy: ts and
package/tui.ts CHANGED
@@ -1,4 +1,4 @@
1
1
  // Convenience re-export for the loose plugin-discovery layout
2
2
  // (<config>/plugins/<name>/index.ts + tui.ts). Package installs resolve
3
- // "./tui" through package.json exports to src/tui.tsx directly.
3
+ // "./tui" through package.json exports to src/tui/panel.tsx directly.
4
4
  export { default } from "./src/tui/panel.tsx";
@@ -0,0 +1,8 @@
1
+ # Vendored: opencode-memory license
2
+
3
+ Only the upstream `LICENSE` is vendored here, and deliberately so: this
4
+ repository does not copy opencode-memory source files. It reproduces the
5
+ upstream logfmt store format — see `src/store/files/load.ts` — and extends
6
+ it, so the MIT attribution for the format is what has to ship. The upstream
7
+ project is `github.com/shuans/opencode-memory` (MIT, Copyright (c) 2025
8
+ Kris). Nothing else is missing from this directory.
File without changes