opencode-self-improvement 0.30.4 → 0.31.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +122 -210
- package/docs/adr/0001-two-concept-recall-admission.md +18 -0
- package/docs/adr/0002-window-dedup.md +22 -0
- package/docs/adr/0003-identifier-tokenizer.md +19 -0
- package/docs/adr/0004-viewer-startup-token.md +21 -0
- package/docs/adr/0005-capture-teardown-phases.md +20 -0
- package/docs/adr/0006-capture-prompt-integrity.md +15 -0
- package/docs/adr/0007-symptom-first-capture.md +17 -0
- package/docs/adr/0008-availability-tags-not-refusals.md +25 -0
- package/docs/auto-capture-evidence.md +29 -0
- package/docs/contradiction-authority.md +36 -0
- package/docs/development.md +28 -0
- package/docs/flags.md +20 -0
- package/docs/import-quarantine.md +36 -0
- package/docs/injection-cost.md +40 -0
- package/docs/options.md +41 -0
- package/docs/pre-release-ritual.md +33 -0
- package/docs/recall-quality.md +52 -0
- package/docs/repo-scoping.md +35 -0
- package/docs/store-concurrency.md +26 -0
- package/docs/troubleshooting.md +22 -0
- package/docs/use-ledger.md +50 -0
- package/docs/write-gates.md +21 -0
- package/package.json +2 -1
- package/src/capture/candidates.ts +1 -1
- package/src/capture/prompt.ts +1 -1
- package/src/capture/runtime.ts +18 -16
- package/src/index.ts +14 -11
- package/src/status/report.ts +4 -4
package/README.md
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
# Opencode-Self-Improvement
|
|
2
2
|
|
|
3
|
-
Durable memory for [opencode](https://opencode.ai): the decisions, commands and facts an agent should
|
|
3
|
+
Durable memory for [opencode](https://opencode.ai): the decisions, commands and facts an agent should still know next week, plus a one-command per-repo setup.
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
Say "we use Bun, not npm — npm keeps breaking the lockfile" on Monday. A session you start on Tuesday already knows it, and why. A memory that turns out wrong is superseded, never deleted, and `memory_undo` rolls it back.
|
|
6
6
|
|
|
7
|
-
Every figure
|
|
7
|
+
Every figure here carries a marker: **measured** (read off a live store), **bench** (a deterministic synthetic workload, reproducible with the command printed under the table), or **illustrative** (sample output showing shape, not a measurement). A number without a marker is a claim that has not been checked.
|
|
8
8
|
|
|
9
9
|
## Quick start
|
|
10
10
|
|
|
@@ -17,49 +17,68 @@ Every figure in this README carries a provenance marker: **measured** (read off
|
|
|
17
17
|
}
|
|
18
18
|
```
|
|
19
19
|
|
|
20
|
-
**2. Restart opencode.**
|
|
20
|
+
**2. Restart opencode.** On the desktop app a later config edit needs `opencode service restart`: relaunching the app leaves the background service, and the options it already parsed, alive.
|
|
21
21
|
|
|
22
|
-
**3. Run `/repo-init`** in each repo you work in. It stores
|
|
22
|
+
**3. Run `/repo-init`** in each repo you work in. It stores that repo's test / build / lint / typecheck commands as memories, so the next session does not rediscover them. Rerun `/repo-init force` after a refactor.
|
|
23
23
|
|
|
24
|
-
|
|
24
|
+
After that, memory is just conversation: ask the agent to remember something and it sticks.
|
|
25
25
|
|
|
26
|
-
|
|
26
|
+
<details>
|
|
27
|
+
<summary>Other ways to install, and the version floor</summary>
|
|
27
28
|
|
|
28
29
|
```sh
|
|
29
30
|
opencode plugin add opencode-self-improvement
|
|
30
31
|
opencode plugin update opencode-self-improvement
|
|
31
32
|
```
|
|
32
33
|
|
|
33
|
-
|
|
34
|
+
Needs Bun 1.3.0 or newer in the opencode build (the tested floor); older Bun reports a startup warning.
|
|
34
35
|
|
|
35
|
-
|
|
36
|
+
An unpinned entry resolves `@latest` exactly once and is never re-resolved afterwards, so updates are deliberate: run `opencode plugin update` when you want one. To pin, append `@<version>` — see [npm](https://www.npmjs.com/package/opencode-self-improvement) for what is current.
|
|
36
37
|
|
|
37
|
-
|
|
38
|
-
- **`/repo-init`** — per-repo setup: build/test commands as memories, keyed to the git head.
|
|
39
|
-
- **Write gates** — code references are verified against your actual repo, near-duplicates are collapsed, contradictions with superseded memories are rejected. Blocked writes are logged with a reason in `memory_evidence`, which reads one real calendar day inside `evidence/` at a time — its `date` is a date, never a path.
|
|
40
|
-
- **Memory-aware compaction** — durable memories are handed to the compaction summarizer, so a long session keeps its facts.
|
|
41
|
-
- **Auto-capture (experimental, opt-in)** — in progress and **not working yet**. The design: on the turn-end and compaction triggers, one cheap model pass per trigger proposes candidates, which face the same write gates, with a 5-minute cooldown per session and trigger bounding the spend. What is not true today: it has never been observed firing on a live opencode 2.x store, so enabling it may cost model calls and store nothing. See [Auto-capture is experimental](#auto-capture-is-experimental).
|
|
42
|
-
- **Repo scoping** — rows belong to the repo that wrote them; project A's facts never surface in project B.
|
|
43
|
-
- **Safe across concurrent sessions** — whole-file rewrites hold a lock honored across processes and hand the new file over with an atomic rename. The lock is a SQLite database beside each store file (`.store-lock.<file>.sqlite`), claimed with `BEGIN IMMEDIATE` and released with `ROLLBACK`. It is a kernel record, not a file name, so a process that is killed releases it at once and a normal write creates and deletes nothing ([#407](https://github.com/abogartz/opencode-self-improvement/issues/407)). The connection stays open while the store is in use, so on Windows delete the store only after stopping your sessions.
|
|
44
|
-
- **Decay** — `memory_decay` retires stale open threads. Dry run by default, snapshot-first, undoable.
|
|
45
|
-
- **Consolidation** — `memory_consolidate` proposes near-duplicate merges, and only when replaying the store's own use ledger shows the merged row catches at least as many reads as the best single member. It writes nothing.
|
|
46
|
-
- **Export / import (JSONL)** — back the store up or move it between machines; every imported row re-enters through the write gates.
|
|
47
|
-
- **Surfaces** — a terminal footer badge and `/memory` panel, `/memory-report` for chat clients, a `memory_status` tool, and a browser admin editor. See [Surfaces](#surfaces).
|
|
48
|
-
- **Secret redaction** — credential-shaped values in content become `[redacted]`. See [Secret redaction](#secret-redaction).
|
|
38
|
+
To work on the plugin instead, clone it and point the entry at the checkout:
|
|
49
39
|
|
|
50
|
-
|
|
40
|
+
```sh
|
|
41
|
+
git clone https://github.com/abogartz/opencode-self-improvement.git
|
|
42
|
+
cd opencode-self-improvement && bun install
|
|
43
|
+
```
|
|
51
44
|
|
|
52
|
-
|
|
45
|
+
```json
|
|
46
|
+
{ "plugins": ["/full/path/to/opencode-self-improvement/index.ts"] }
|
|
47
|
+
```
|
|
53
48
|
|
|
54
|
-
|
|
49
|
+
Then `git pull` and restart opencode to update.
|
|
55
50
|
|
|
56
|
-
|
|
51
|
+
</details>
|
|
52
|
+
|
|
53
|
+
## What you get
|
|
54
|
+
|
|
55
|
+
Think of it as a lab notebook the agent keeps for your repo, plus a librarian who checks every entry before filing it.
|
|
56
|
+
|
|
57
|
+
- **Write gates — a CI check for facts.** A memory citing `parseHeader()` in a file you deleted is refused before it is stored, not after a future session trusts it. Near-duplicates collapse, and a contradiction with a retired memory is rejected. Every refusal lands in `memory_evidence` with its reason.
|
|
58
|
+
- **Budgeted injection.** Relevant memories ride the prompt on their own, capped at `injectBudget` characters. The block is cache-stable: a write somewhere else in the store does not cost you a cache miss.
|
|
59
|
+
- **Repo scoping.** Every row carries the repo that wrote it, so project A's facts never surface in project B. A preference you want everywhere goes in with `memory_remember global: true`.
|
|
60
|
+
- **Nothing is deleted.** `memory_update` supersedes the old row, `memory_forget` records a retirement, `memory_undo` restores a snapshot.
|
|
61
|
+
- **Memory-aware compaction** — a long session hands its durable facts to the summarizer instead of losing them.
|
|
62
|
+
- **Safe across concurrent sessions** — a reader sees the previous store file or the new one, never half of either.
|
|
63
|
+
- **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.
|
|
64
|
+
- **Export / import (JSONL)** — back the store up or move it between machines; every imported row re-enters through the same gates.
|
|
65
|
+
- **Surfaces** — a footer badge, the `/memory` panel, `/memory-report` for chat clients, and a browser admin editor. See [Surfaces](#surfaces).
|
|
66
|
+
- **Secret redaction** — credential-shaped values become `[redacted]`. See [Secret redaction](#secret-redaction).
|
|
67
|
+
- **`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`.
|
|
68
|
+
- **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).
|
|
57
69
|
|
|
58
|
-
|
|
70
|
+
Memory is stored outside every repository, under `~/.config/opencode/memory` by default (override with `OPENCODE_MEMORY_DIR`). To start over, delete that directory.
|
|
59
71
|
|
|
60
72
|
## Options
|
|
61
73
|
|
|
62
|
-
Zero configuration is the default.
|
|
74
|
+
Zero configuration is the default. Two options change what the model sees:
|
|
75
|
+
|
|
76
|
+
| Option | Default | What it does |
|
|
77
|
+
| --- | --- | --- |
|
|
78
|
+
| `injectBudget` | `1200` | Character cap on the injected relevance block and each contextual pull. |
|
|
79
|
+
| `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. |
|
|
80
|
+
|
|
81
|
+
Anything else goes in the object form of the plugin entry in `opencode.json(c)`:
|
|
63
82
|
|
|
64
83
|
```json
|
|
65
84
|
{
|
|
@@ -67,73 +86,54 @@ Zero configuration is the default. To tune, use the object form of the plugin en
|
|
|
67
86
|
}
|
|
68
87
|
```
|
|
69
88
|
|
|
70
|
-
|
|
71
|
-
| --- | --- | --- |
|
|
72
|
-
| `injectBudget` | `1200` | Character cap on the injected relevance block and each contextual pull; trimmed at whole-memory boundaries. Env fallback: `OPENCODE_MEMORY_INJECT_BUDGET`. |
|
|
73
|
-
| `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`. |
|
|
74
|
-
| `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 [Contradiction authority policy](#contradiction-authority-policy-experimental-349--351). |
|
|
75
|
-
| `autoCapture` | `false` | Master switch for auto-capture, which is **experimental and has never fired on a verified live store** — see [Auto-capture is experimental](#auto-capture-is-experimental). Off by default, so the install stays zero-token. |
|
|
76
|
-
| `captureModel` | — | `"provider/id"` model used for auto-capture. Required when `autoCapture` is on; missing or invalid disables capture with a startup warning. |
|
|
77
|
-
| `captureMax` | `3` | Maximum candidates proposed per capture pass. |
|
|
78
|
-
| `captureOnCompact` | `true` | When `autoCapture` is on, also mine the transcript at compaction, before the summarizer replaces it. Its 5-minute cooldown is separate from the turn-end one, so the two triggers' hit-rates stay measurable. Setting it while `autoCapture` is off does nothing and reports a startup warning. |
|
|
79
|
-
| `captureGuidedRules` | `false` | POC: deterministic guided-candidate pre-pass. The user's own lines decide which stated values or rules are guided (numbers, rates, currency, explicit rule assertions) and attach the verbatim quote; the capture model may phrase such a row but cannot clear the flag or the quote, and a guided quote the user never wrote is refused at the write boundary instead of silently stripped. Fires alongside the model pass only — no extra model calls. |
|
|
80
|
-
| `notifyBlocked` | `true` | Terminal (TUI) only: toast when a write gate blocks a write. Blocks are always in `memory_evidence` either way. |
|
|
81
|
-
|
|
82
|
-
### Environment variables
|
|
83
|
-
|
|
84
|
-
| Variable | Purpose |
|
|
85
|
-
| --- | --- |
|
|
86
|
-
| `OPENCODE_MEMORY_DIR` | Store location (default `~/.config/opencode/memory`). |
|
|
87
|
-
| `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. See [Export and move between machines](#export-and-move-between-machines). |
|
|
88
|
-
| `OPENCODE_MEMORY_INJECT_BUDGET` | Fallback for `injectBudget`. |
|
|
89
|
-
| `OPENCODE_MEMORY_FRONTIER_BUDGET` | Fallback for `frontierBudget`. |
|
|
90
|
-
| `OPENCODE_MEMORY_DEDUP` | Near-duplicate suppression inside a `memory_recall` window. **ON by default at `0.8`** (content-token Jaccard): a row that is a near-copy (same scope, Jaccard at or above the threshold) of a row already returned is skipped — the newest copy of a clash survives — so the window fills with distinct facts instead of repeats of the top hit. Rows that disagree on a negation word, or carry too little comparable content, are never suppressed. Set `0` for the plain top-`limit` slice, byte-identical to the old behavior; an explicit value below `0.5` or above `1`, or one that is not a number, is a misconfiguration and turns the pass off; see [#409](https://github.com/abogartz/opencode-self-improvement/issues/409). |
|
|
91
|
-
| `OPENCODE_MEMORY_SYMPTOM` | Enforces the capture convention (#419): `learning` and `blocker` rows must open their content with the observable trigger a future session will hit, as `"When <symptom>: <fact>"`. A diary-shaped lesson ("In this session we fixed...") shares no words with the query the future session types — measured: surfaced 0/8 as diary, ranks 1-7 symptom-first — so the write gate blocks it with a rephrase hint instead of storing something that can never be recalled. ON by default; set `off` (or `0`/`false`) for automation holding a pre-convention backlog. A rewrite that keeps the supersede target's content byte-identical (a metadata-only `memory_update`, retag repair) is exempt — the rule shapes new lesson prose, not legacy-row maintenance. Other types (`context`, `decision`, `pattern`, `preference`) are unaffected. `scripts/symptom-fixer.ts` repairs old rows offline, grounding each symptom in the store's own query ledger. |
|
|
92
|
-
| `OPENCODE_MEMORY_QUERY_GATE` | **ON by default**: a `memory_recall` match must share **two** whole words of the query once the query has three content words — the rule the injected relevance block already applies, so both paths agree on when nothing is a good enough answer. Set `off` (also `0`, `no`, `n`, `false`, or any zero) to restore the matcher's permissive one-word admission. |
|
|
93
|
-
| `OPENCODE_COMMANDS_DIR` | Where the plugin mirrors its slash commands (default `~/.config/opencode/commands`). |
|
|
94
|
-
| `OPENCODE_VIEWER_HOST` | Interface the editor binds to (default `127.0.0.1`). A non-loopback bind serves the store over plain HTTP with no authentication — only do it on a network you control. See [Surfaces](#surfaces). |
|
|
95
|
-
| `OPENCODE_VIEWER_PORT` | Admin editor port (default `8787`). |
|
|
96
|
-
| `OPENCODE_VIEWER_ALLOWED_HOSTS` | Comma-separated hosts beyond loopback. See [Surfaces](#surfaces). |
|
|
89
|
+
The capture options (`autoCapture`, `captureModel`, `captureMax`, `captureOnCompact`, `captureGuidedRules`) are described where the feature is: [Auto-capture](#auto-capture). `contradictionSurface` is described with the verdict table in [Contradiction authority policy](#contradiction-authority-policy-experimental-349--351). Every option and environment variable, including what an invalid value does: [docs/options.md](docs/options.md).
|
|
97
90
|
|
|
98
|
-
|
|
91
|
+
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: an out-of-range `DEDUP` turns the suppression pass off rather than clamping to the nearest bound, and a metadata-only `memory_update` is exempt from `SYMPTOM` so legacy rows can still be retagged.
|
|
99
92
|
|
|
100
|
-
|
|
93
|
+
## Auto-capture
|
|
101
94
|
|
|
102
|
-
|
|
95
|
+
Auto-capture is the part that notices facts on its own instead of waiting to be asked. At the end of a turn — and again at compaction, before the summarizer replaces the transcript — one cheap model pass reads what just happened and proposes up to `captureMax` candidates. They face the same four write gates as anything you save by hand, and a 5-minute cooldown per session and trigger bounds the spend.
|
|
103
96
|
|
|
104
|
-
|
|
105
|
-
- **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.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.
|
|
106
|
-
- **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).
|
|
97
|
+
It is **on by default** and needs no model name to run. With `captureModel` unset, each pass uses the model your session is already using, or the host default. Set `autoCapture: false` to stop the plugin reading sessions and calling a model for capture entirely:
|
|
107
98
|
|
|
108
|
-
|
|
99
|
+
```json
|
|
100
|
+
{
|
|
101
|
+
"plugins": [{ "package": "opencode-self-improvement", "options": { "autoCapture": false } }]
|
|
102
|
+
}
|
|
103
|
+
```
|
|
109
104
|
|
|
110
|
-
|
|
105
|
+
Name `captureModel` only to pin one model for the pass. An explicit value that is not `provider/id` turns auto-capture off with a startup warning rather than substituting a model you did not choose.
|
|
111
106
|
|
|
112
|
-
|
|
107
|
+
**What that default means for your data.** Because the switch is on, installing this plugin sends a copy of the conversation to your configured model at every turn-end and every compaction. The copy excludes reasoning content and runs through the credential scrubber first, and anything the pass proposes still faces the same write gates as a manual save — but the read itself is real, and it goes out over your provider. Set `autoCapture: false` if you do not want that.
|
|
113
108
|
|
|
114
|
-
What
|
|
109
|
+
| Option | Default | What it does |
|
|
110
|
+
| --- | --- | --- |
|
|
111
|
+
| `autoCapture` | `true` | Master switch. On, so a plain install mines turn ends. Set `false` for no capture model call at all. |
|
|
112
|
+
| `captureModel` | inherits | `"provider/id"` model for the pass. Unset means the session's own model, else the host default. An explicit malformed value disables capture with a startup warning. |
|
|
113
|
+
| `captureMax` | `3` | Maximum candidates proposed per pass. |
|
|
114
|
+
| `captureOnCompact` | `true` | Also mine the transcript at compaction. Its 5-minute cooldown is separate from the turn-end one, so both triggers' hit-rates stay measurable. Setting it while `autoCapture` is `false` does nothing. |
|
|
115
|
+
| `captureGuidedRules` | `false` | POC: a deterministic pre-pass marks the values and rules you stated outright — numbers, rates, currency, explicit rule assertions — and attaches your verbatim quote. The capture model may rephrase such a row but cannot clear the flag or invent the quote: a quote you never wrote is refused at the write boundary rather than stripped silently. No extra model calls. |
|
|
115
116
|
|
|
116
|
-
|
|
117
|
-
- Anything about quality on a live store. What auto-capture would write, how often it duplicates a memory you would have written yourself, and what it costs remain unmeasured. `bench/capture-trigger-results.md` is a **bench** simulation of trigger *timing* with a scripted extractor — its compaction world captured 0 rows and 4 of its 6 controls report FAIL. It answers "which moment is worth mining", not "does the shipped feature work".
|
|
117
|
+
**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.
|
|
118
118
|
|
|
119
|
-
|
|
119
|
+
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".
|
|
120
120
|
|
|
121
|
-
|
|
121
|
+
**Am I armed?** `memory_evidence` answers on the `plugin_load` line: `capture=on` (the default), `capture=off` (`autoCapture: false`), `invalid_model` (`captureModel` is set but is not `provider/id`), `no_capabilities` (the host did not expose what capture needs), or `switch_mismatch` (`captureOnCompact` is on while `autoCapture` is `false`). The same line carries `subscribed=[…]`, listing the event types that subscription really reacts to. On desktop this needs `opencode service restart` after an edit — relaunching the app keeps the old service and its already-parsed options alive, so `capture=` can report a value your config no longer contains. `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.
|
|
122
122
|
|
|
123
|
-
|
|
123
|
+
## How memory is written
|
|
124
124
|
|
|
125
|
-
Four gates run before anything is stored, and each emits an ordered evidence line:
|
|
125
|
+
A memory is a claim about your code, so it gets checked like one. Four gates run before anything is stored, and each emits an ordered evidence line:
|
|
126
126
|
|
|
127
127
|
1. **GATE-1 — code references resolve.** Call signatures and paths embedded in the memory are checked against your live source tree.
|
|
128
128
|
2. **GATE-2 — no stale memory applies here.** References that drifted out of date are superseded or the write is blocked.
|
|
129
129
|
3. **GATE-3 — no duplicates.** Near-duplicates collapse into the existing row; a contradiction with a superseded memory is rejected.
|
|
130
130
|
4. **GATE-4 — promotion or block.** The row lands, or the call returns the reason.
|
|
131
131
|
|
|
132
|
-
Nothing is deleted
|
|
132
|
+
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).
|
|
133
133
|
|
|
134
134
|
### Contradiction authority policy (experimental, #349 / #351)
|
|
135
135
|
|
|
136
|
-
|
|
136
|
+
You and the code disagree about a constant. Who is right depends on what you said, so capture records the kind of statement:
|
|
137
137
|
|
|
138
138
|
| Captured statement | Class | Verdict on a detected conflict |
|
|
139
139
|
| --- | --- | --- |
|
|
@@ -141,19 +141,15 @@ Nothing is deleted: `memory_update` supersedes the previous row, `memory_forget`
|
|
|
141
141
|
| User describes how working code behaves | `behavior` | Code is the authority; keep the constant and raise the mismatch with the user. |
|
|
142
142
|
| Authority is unclear | Omit `klass` | Keep plain guidance and its staleness caveat; emit no CONFLICT verdict. |
|
|
143
143
|
|
|
144
|
-
The code check accepts a unique top-level `const` with a literal value
|
|
145
|
-
|
|
146
|
-
Accepted residual: a user-stated **wrong spec** still classifies as `spec`. Its verdict follows that stated requirement even if it breaks the current tests. The plugin does not infer hidden-suite authority or silently override the user's requirement. Asking an oracle or inventing an extra authority class is outside this contract. Capture classification can be wrong; a code comparison verifies a value mismatch, not the user's intent. Per the [maintainer's rollout decision](https://github.com/abogartz/opencode-self-improvement/pull/363#pullrequestreview-5819556342), the default is ON for full benchmarking after merge and can be revisited. The seat-model and merged-main confidence runs in #350–#352 remain outstanding; enabling the feature is not a claim that those benchmarks passed.
|
|
144
|
+
The code check accepts only a unique top-level `const` with a literal value, runs inside fixed source budgets, and refuses to decide anything it cannot read. Its limits, and the accepted residual — a user-stated **wrong spec** still classifies as `spec` and its verdict follows that requirement — are in [docs/contradiction-authority.md](docs/contradiction-authority.md).
|
|
147
145
|
|
|
148
146
|
## Repo scoping
|
|
149
147
|
|
|
150
148
|
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. `repoPath` keeps the human-readable path, so rows written before hashing keep matching.
|
|
151
149
|
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
Injection, recall, the frontier block, compaction, `memory_forget` and decay only see the current repo plus global rows, resolved from the calling session's identity at flow entry. A session that reaches a plugin instance is bound to that instance's own workspace on first contact — in a process hosting several workspaces, one session never borrows the repository some other workspace's setup left behind. A session whose repository cannot be resolved at all sees global rows only; "unknown" is never "everything". Writes follow that rule in the stricter direction: a named session with no resolved repository has **no write target**, so `memory_remember`, `memory_update`, `memory_import` and auto-capture refuse it (evidence `write_refused`) and store nothing — the alternatives were stamping your private content into whichever workspace's `setup()` ran last, or publishing it to every project as an unstamped row. A caller that names no session at all (the viewer process, a restore, a script) keeps the process scope, and an explicit `global: true` is a deliberate owner. Evidence lines carry the same stamp, so `memory_evidence` answers from the caller's repo plus global lines; a line a named session wrote while its repository was unresolvable is private to that session, and only an explicitly global (or predating-stamps) line reads as global. Preferences that should follow you everywhere go in with `memory_remember global: true`. Rows written before scoping existed are global, and the viewer (an admin surface over every repo) edits and restores a row with its own repo stamp — the viewer's missing session scope never decides a row's visibility. `memory_merge_review` applies the same rule to its inputs: a session may merge exactly the rows it may read — global rows plus its own repo's, from either seat — and a row id it merely knows is not authority to retire another repo's memory. Upgrading changes nothing.
|
|
150
|
+
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`.
|
|
155
151
|
|
|
156
|
-
|
|
152
|
+
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).
|
|
157
153
|
|
|
158
154
|
## What memory is worth, measured
|
|
159
155
|
|
|
@@ -168,7 +164,7 @@ Two results. Only two are quoted, each with its `n` and the seat it ran on, beca
|
|
|
168
164
|
|
|
169
165
|
**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.
|
|
170
166
|
|
|
171
|
-
**Rules for any cost claim in this repository** —
|
|
167
|
+
**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:
|
|
172
168
|
|
|
173
169
|
- No cost claim below **n=6 pairs per arm**. A ratio at `6 ≤ n < 21` is labelled **"20% resolution"**.
|
|
174
170
|
- A **seat** and a **metric** are named on the same line as the number.
|
|
@@ -179,38 +175,18 @@ Two results. Only two are quoted, each with its `n` and the seat it ran on, beca
|
|
|
179
175
|
|
|
180
176
|
## Token cost and caching
|
|
181
177
|
|
|
182
|
-
|
|
183
|
-
- **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.
|
|
184
|
-
- **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; `memory_recall` still reaches them on the pull path.
|
|
185
|
-
- **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.
|
|
186
|
-
- **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`).
|
|
187
|
-
- **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)).
|
|
188
|
-
- **Hard budgets.** Relevance block and each pull are capped at `injectBudget` characters, the frontier at `frontierBudget`, trimmed at whole-memory boundaries.
|
|
189
|
-
- **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.
|
|
190
|
-
- **Evidence is never injected**, and the standing system digest is two lines.
|
|
191
|
-
- **Measured, not claimed.** The plugin reads each turn's `tokens.cache` accounting and displays the actual hit rate next to the badge. The same receipts now carry what the session generated — `output` and `reasoning`, shown split, because on a reasoning-heavy seat the completion side is where the cost actually goes. A host that reports neither shows nothing, never a zero.
|
|
192
|
-
- **Auto-capture bills separately, and it is an estimate.** Capture is its own model call made after the turn, so it appears in no session's usage: read from session numbers, the plugin's own cost is exactly zero. The host exposes no receipt for it — `ctx.generate` has one member, `text`, resolving to `{ text }` with no `usage` — so `memory_status` reports chars/4 with `receipt=none` and the words "estimate, no provider receipt" on the line. Quote that number as an estimate or not at all. A pass disposed during teardown is not billed: its store is already gone, so the count undercounts by one call there.
|
|
193
|
-
|
|
194
|
-
**Bench** — deterministic workload (50 memories, 20 prompts, 3 mid-session store writes made *by the measured session*) through the plugin's real injection code. Every column is measured on the full memory section — the bytes a request actually sends — because prompt caching is a property of those bytes:
|
|
195
|
-
|
|
196
|
-
| Policy | Recomputes | Epochs whose bytes moved | Injected chars (20 turns) | Avg/turn | Worst section |
|
|
197
|
-
| --- | ---: | ---: | ---: | ---: | ---: |
|
|
198
|
-
| A — recompute per prompt, uncapped (naive) | 20 | 19 | 60996 | 3049.8 | 3404 |
|
|
199
|
-
| B — block frozen on store fingerprint, digest rebuilt per turn | 4 | 3 | 55478 | 2773.9 | 2867 |
|
|
200
|
-
| C — section frozen on rendered bytes | 4 | 3 | 55258 | 2762.9 | 2856 |
|
|
201
|
-
| D — C + riding bytes (shipped) | 1 | 0 | 53500 | 2675.0 | 2675 |
|
|
202
|
-
|
|
203
|
-
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:
|
|
178
|
+
Injecting memory costs prompt bytes, and prompt bytes are what a provider bills against. So the plugin treats the injected block like a cached HTTP response: it is recomputed only when the content the model is actually reading changes, and until then it is delivered byte-identically and served from cache.
|
|
204
179
|
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
180
|
+
- **The frozen bytes are the authority, not the store fingerprint.** A row promoted elsewhere in the store that changes nothing visible costs no cache bust. A memory *you* saved in this session is already in your own transcript, so it does not bust your cache either; a correction of a row you are riding, or anything another session, the viewer or an import wrote, still lands on your next request.
|
|
181
|
+
- **Two concepts, not one.** A free-text prompt must share at least two distinct concepts with a memory to be injected; one- and two-word queries need only one. `memory_recall` still reaches the single-word coincidences when you ask on purpose. Identifier spellings count once: `getUserAccount`, `get_user_account`, `get-user-account` and `get.user.account` are one concept rather than four ([#409](https://github.com/abogartz/opencode-self-improvement/issues/409)).
|
|
182
|
+
- **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.
|
|
183
|
+
- **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.
|
|
208
184
|
|
|
209
|
-
**
|
|
185
|
+
**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`.
|
|
210
186
|
|
|
211
187
|
## Recall quality
|
|
212
188
|
|
|
213
|
-
No vector database, no embedding model, no API key.
|
|
189
|
+
No vector database, no embedding model, no API key: a keyword matcher. That is a trade, and here is the price, measured against classic BM25 on a deterministic eval (store of 200, k=3 — the production injection limit). **Bench**:
|
|
214
190
|
|
|
215
191
|
| Query, vs. the stored memory | share | R@1 | R@3 | with `kw` R@1 | with `kw` R@3 |
|
|
216
192
|
| --- | ---: | ---: | ---: | ---: | ---: |
|
|
@@ -220,13 +196,11 @@ No vector database, no embedding model, no API key. **Bench** — what the keywo
|
|
|
220
196
|
|
|
221
197
|
"with `kw`" is the same matcher over the same store with each row's write-time keywords indexed; the only changed variable is the index.
|
|
222
198
|
|
|
223
|
-
- **
|
|
224
|
-
- **
|
|
225
|
-
-
|
|
226
|
-
- **`memory_recall` returns 5 rows by default, not 20.** A live audit joined 1,090 recall events to their session transcripts: a returned row at rank 1 shows up in a later tool call at 3.4x the rate of a random store row, ranks 2–3 at 2.4x, and ranks 11–20 at 1.16x — noise against a 0.129 null. The old default returned 17.7 rows per call, so most of the window was context nobody read. At limit 5, recall@1 and recall@3 are unchanged, precision rises 4.1% → 13.1%, and 74% of the returned characters disappear; every gold row the cut dropped sat at ranks 6–20. Pass `limit` for a wider sweep ([#409](https://github.com/abogartz/opencode-self-improvement/issues/409)).
|
|
227
|
-
- **Caveats.** The dataset is synthetic (52 memories / 105 queries, a fictional project), its class mix is deliberately adversarial, and scoring is single-gold.
|
|
199
|
+
- **Most in-project prompts are lexical** (`bun test`, "the rate limiter", "staging deploys"): 98–100% R@3, flat from store size 50 to 500.
|
|
200
|
+
- **A zero-overlap paraphrase is the real limit, and write time is where you answer it.** "How we deploy" will not match a session that types "ship to staging" unless you say so: `memory_remember` asks each row for 3–5 `kw` aliases — other names, other verb forms, the literal command — indexed and never rendered. Strict R@1 0% → 26%, near R@1 28% → 67%. Narrowed, not removed.
|
|
201
|
+
- **`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. Cutting the default from 17.7 rows left recall@1 and recall@3 unchanged, raised precision 4.1% → 13.1%, and dropped 74% of the returned characters ([#409](https://github.com/abogartz/opencode-self-improvement/issues/409)). Pass `limit` for a wider sweep.
|
|
228
202
|
|
|
229
|
-
Full methodology and all store sizes: `bench/recall-results.md`.
|
|
203
|
+
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`.
|
|
230
204
|
|
|
231
205
|
```sh
|
|
232
206
|
bun run bench:recall
|
|
@@ -250,7 +224,7 @@ bun run bench:write
|
|
|
250
224
|
|
|
251
225
|
## The store keeps score
|
|
252
226
|
|
|
253
|
-
The plugin keeps a
|
|
227
|
+
The plugin keeps a use ledger — a due-date card for every row: who looked at it, when, and how it reached them. It is append-only, never ingested as a memory, and reported in `memory_status` and the `/memory` panel. Illustrative output — shape, not a measurement:
|
|
254
228
|
|
|
255
229
|
```
|
|
256
230
|
STORE
|
|
@@ -259,17 +233,19 @@ STORE
|
|
|
259
233
|
24.1 KB total · 604 B per row · 1.3 rows/day (30d)
|
|
260
234
|
```
|
|
261
235
|
|
|
262
|
-
- **
|
|
263
|
-
- **
|
|
264
|
-
-
|
|
265
|
-
-
|
|
266
|
-
|
|
267
|
-
|
|
236
|
+
- **Use has three distinct sources** — the row rode the injected block, `memory_recall` returned it, or a grep/read pull appended it — because "the model asked" and "the harness offered" are different facts. No prompt content is stored: the ledger keeps a scan-truncated string from the *memory* side, never your message.
|
|
237
|
+
- **Reinforcement is a tie-break only** (`useBoost ≤ 1.0`): a recently used row wins a tie and can never outrank a real score gap.
|
|
238
|
+
- **`never retrieved` is stated, not acted on.** Pruning is your decision.
|
|
239
|
+
- **Aggregate STORE counts are machine-wide by decision (#213 B)** — they describe the store on this machine, not your slice of it. Privacy applies to the content surfaces instead: `memory_evidence` and the recent-blocked-writes list follow each reader's repository visibility (#306).
|
|
240
|
+
|
|
241
|
+
The credit rule and its throttle, the consolidation tie-break, and capture lag: [docs/use-ledger.md](docs/use-ledger.md).
|
|
268
242
|
|
|
269
243
|
## Consolidation
|
|
270
244
|
|
|
271
245
|
`memory_consolidate` finds near-duplicates and proposes merges. It writes nothing; each proposal prints the exact `memory_merge_review` call that resolves it, and resolving is supersede-not-delete.
|
|
272
246
|
|
|
247
|
+
The rule is: never merge two entries unless every question that used to find either one still finds the merged row.
|
|
248
|
+
|
|
273
249
|
- **Deterministic.** The canonical row is the survivor's prose verbatim plus the absorbed rows' aliases as keywords. No model rewrites anything.
|
|
274
250
|
- **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.
|
|
275
251
|
|
|
@@ -277,7 +253,14 @@ STORE
|
|
|
277
253
|
|
|
278
254
|
## Secret redaction
|
|
279
255
|
|
|
280
|
-
One best-effort credential rule set (`src/secrets.ts`)
|
|
256
|
+
One best-effort credential rule set (`src/secrets.ts`) replaces recognized values with `[redacted]`. It runs at every boundary a credential could persist, not one:
|
|
257
|
+
|
|
258
|
+
- over the auto-capture prompt before it leaves the plugin — the complete transcript is redacted *before* the character budget crops it, so a credential cut in half still matches its pattern;
|
|
259
|
+
- at the write gate, before content is hashed or analysed;
|
|
260
|
+
- again in the final write choke point used by gated writes and by the viewer's edit and restore paths;
|
|
261
|
+
- at the durable audit boundaries — every evidence line, every supersede field written into a retired row, and every deletion-audit reason.
|
|
262
|
+
|
|
263
|
+
So a recognized credential cannot persist in a new `evidence/` line, in a deletion-audit `reason`, or in a supersede field written into a retired row, whichever path carried it. It is not scrubbed from everything those paths touch — see the limits below.
|
|
281
264
|
|
|
282
265
|
Covered: OpenAI `sk-`, GitHub `ghp_` / `gho_` / `github_pat_`, Slack `xoxb-` / `xoxp-`, AWS `AKIA`, Google `AIza`, bearer tokens containing digits, PEM private-key blocks, and high-entropy values assigned to names ending in `_KEY`, `_TOKEN`, `_SECRET` or `_PASSWORD` (plus `password`).
|
|
283
266
|
|
|
@@ -287,12 +270,13 @@ Limits worth knowing:
|
|
|
287
270
|
- Credential-shaped `scope`, `tags` or `issue` metadata is rejected rather than silently rewritten.
|
|
288
271
|
- `memory_remember` still replies `Remembered` when content was redacted, so the stored text can differ from what was sent.
|
|
289
272
|
- Redaction is forward-only: existing stores are not scrubbed. `memory_export` scrubs credentials out of `content`, `issue`, `scope`, `tags` and `kw` as it serialises, so the file that leaves the machine carries `[redacted]` where a stored row still holds a token; the store itself is untouched, and origin stamps (`repo`, `repoPath`) are written as stored. The scrubber is a best-effort sweep over known token families and high-entropy credential-shaped values — an exotic credential can survive it, so an export is still a file you hand out deliberately.
|
|
273
|
+
- Deleting a row copies it, it does not scrub it. `deletions.logfmt` keeps the deleted row's `content`, `tags`, `kw` and `issue` exactly as the row held them — a restore-entry built from that line has to re-stamp and re-attach precisely what was there — and redacts only the `reason`. So deleting a row that predates redaction writes its credential into the audit. Snapshots carry whatever a stored row holds, for the same reason. That retention is deliberate (#292).
|
|
290
274
|
|
|
291
275
|
## Export and move between machines
|
|
292
276
|
|
|
293
|
-
`memory_export` writes the
|
|
277
|
+
`memory_export` writes the store as JSONL, **as its caller can read it**: from a plugin session that means your repository plus global rows. Full-store breadth belongs to a session-less caller outside the plugin — the library route; the viewer has no export route. `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).
|
|
294
278
|
|
|
295
|
-
|
|
279
|
+
To move a store between machines:
|
|
296
280
|
|
|
297
281
|
```
|
|
298
282
|
Export my memories # -> <memory-root>/exports/<timestamp>-<unique>.jsonl
|
|
@@ -300,9 +284,9 @@ Export my memories # -> <memory-root>/exports/<time
|
|
|
300
284
|
Import <memory-root>/memories.jsonl # memory_import
|
|
301
285
|
```
|
|
302
286
|
|
|
303
|
-
An operator running a one-off migration can restore the old anywhere-on-disk
|
|
287
|
+
Both tools are model-facing, so a path is not a privilege: `file` must stay inside the store — exports under `<memory-root>/exports`, imports anywhere under `<memory-root>` — and a symbolic link cannot carry a request out of it. Pass `scope` to export one scope. An operator running a one-off migration can restore the old anywhere-on-disk behaviour with `OPENCODE_MEMORY_ALLOW_OUTSIDE_PATHS=1`, which is read from the plugin process's own environment so a model cannot grant it to itself. The file format and the confinement rules with their known limits: [docs/import-quarantine.md](docs/import-quarantine.md).
|
|
304
288
|
|
|
305
|
-
|
|
289
|
+
The import reply is a tally, not a yes/no:
|
|
306
290
|
|
|
307
291
|
| Outcome | Meaning |
|
|
308
292
|
| --- | --- |
|
|
@@ -312,21 +296,9 @@ Every imported row re-enters through the same four gates as `memory_remember` (t
|
|
|
312
296
|
| `skipped` | malformed line; never reached the gates |
|
|
313
297
|
| `downgraded` | imported as settled because its `status:"open"` could not be vouched for |
|
|
314
298
|
|
|
315
|
-
Import and auto-capture also scan incoming prose for
|
|
316
|
-
|
|
317
|
-
That screen only covers writes made after it shipped. A store that already holds an untagged poisoned row from an earlier `/repo-init` is repaired by the next one (#375): init scans every row the caller can read (this repository plus global) and, for each hit, writes a tagged twin through the normal gated path and retires the original — nothing is deleted, and each replacement emits its own `write_promoted` audit line. Re-running is safe: a row that already carries the tag is not touched. The reply reports `re-tagged=N`; a hit the gate refused is reported as `blocked=N` instead of passing silently, one run re-tags at most 100 rows and says how many remain, and any row GATE-2 retired along the way is named. A promoted replacement whose audit line itself fell is counted as `N without an audit line` rather than passing as a clean repair. This runs even when init skips on its stamp, because a stamped repository is the common case.
|
|
318
|
-
|
|
319
|
-
Review the full row in the memory viewer's **quarantined** filter. **Release quarantine** requires a reason, snapshots the pre-release row, and removes the quarantine flag and known scanner-reason tags; unrelated user labels such as `quarantine:custom`, repository ownership, row identity, blocklist, and supersession remain intact. Missing and already-released rows produce distinct, audited no-op outcomes. Existing prompt blocks refresh before the next delivery or status report when a row becomes quarantined or is released. Undoing a release can restore the quarantine flag.
|
|
320
|
-
|
|
321
|
-
This is a heuristic review queue, not a complete prompt-injection detector: legitimate documentation or quoted code can match. Markdown-bold role headers and download-then-`&&`-execute forms are recognized, but alternate role delimiters such as `[INST]` / `<<SYS>>`, base64-to-shell pipelines, paraphrased instructions, and indirect execution can evade it. Direct `memory_remember` and human viewer edits are explicit writes and are not automatically scanned: a session with that tool still has a prose channel, mitigated by the existing framing and provenance rather than quarantine. Those defenses still apply to released rows.
|
|
322
|
-
|
|
323
|
-
Always-ride guidance priority is reserved to auto-capture provenance. `memory_remember`, `memory_update` replacements, and JSONL imports silently remove `user-guided` (including comma-delimited tag entries) before the write gate; their field allowlists also exclude `ref`, `claim`, and `klass`. Ordinary tags and prose can still promote normally, but a portable file, even with an export header, cannot attest that the local user stated it. The capture path owns guidance metadata; this boundary protection does not authenticate a directly edited store or guarantee that a capture model classified a statement correctly. The reservation applies to guidance priority and contradiction verdicts (#342, #349).
|
|
324
|
-
|
|
325
|
-
The viewer is a trusted admin editor: its edits and deleted-entry restores do not run the model-facing grounding or deduplication gates, but they honor the same exact and near-match value rejections. Rejected edits leave the original row, snapshots and edit audit unchanged; rejected restores append nothing. The refusal names the rejection hash so you can explicitly lift it under **Rejections → un-reject** before retrying. Corrected numeric values and polarity changes retain the rejection check's existing exceptions. This check does not change whole-snapshot rollback policy.
|
|
299
|
+
Import and auto-capture also scan incoming prose for instruction-override, role-header and download/execute patterns. A promoted match is tagged `quarantine` and withheld from recall, prompt and frontier injection, compaction anchors, contextual pull, consolidation and decay. Think of it as a spam folder, not a virus scanner: legitimate documentation can match, and several forms evade it. Review the queue in the viewer's **quarantined** filter.
|
|
326
300
|
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
An open row is exempt from reference grounding, so that status is honored only for files carrying an export header. Even with a header: an open row claiming `repo:"global"` is downgraded, and imported `repo` / `repoPath` stamps are kept only when they match the importing session's current repo — foreign stamps are dropped and the row is stamped for the importing repo. Re-running the same import in the same repo is a no-op.
|
|
301
|
+
What the screen covers, what it misses, how an existing store is re-tagged, what releasing quarantine does and what it leaves alone, and why direct `memory_remember` and viewer edits are not scanned: [docs/import-quarantine.md](docs/import-quarantine.md).
|
|
330
302
|
|
|
331
303
|
## Surfaces
|
|
332
304
|
|
|
@@ -335,38 +307,12 @@ Same data behind each one (`memory_status`; no model call).
|
|
|
335
307
|
**Terminal (opencode CLI)** — the plugin ships a TUI half (`@opencode/plugin/tui`) that loads automatically:
|
|
336
308
|
|
|
337
309
|
- **Footer badge** — illustrative `● mem 1157/1200c · cache 96%`: the injected block against its budget, plus the measured session prompt-cache hit rate. The dot is green (stable and warm), yellow (recent recompute, or 50–90% reads) or red (last turn served almost nothing from cache); `—` until the first assistant turn, and `—` throughout on a provider that reports no cache usage.
|
|
338
|
-
- **`/memory`** — session panel: **CONTEXT** (
|
|
310
|
+
- **`/memory`** — session panel: **CONTEXT** (what is riding the prompt now and how much of the budget it uses), **CACHE** (busts this session and the measured cache-served share of prompt tokens), **INJECTED BLOCK** (the verbatim block, or an explicit abstention), **RECENT BLOCKED WRITES** (with gate reasons), **STORE** (active / superseded / open / scopes, plus `malformed` when a row's `ts` is not a valid ISO instant — those rows are skipped by every reader). Keys: `r` refresh, `f` fullscreen.
|
|
339
311
|
- **Block toast** when a write is refused (`"notifyBlocked": false` to silence).
|
|
340
312
|
|
|
341
313
|
**Desktop / web / IDE** — the terminal slots do not exist there, so use the self-installed **`/memory-report`** chat command: the same sections rendered in the conversation.
|
|
342
314
|
|
|
343
|
-
**Browser editor** — `bun memory-view`, then http://127.0.0.1:8787. Bound to loopback; requests are checked against `Host` and `Origin`, so other hosts must be listed explicitly in `OPENCODE_VIEWER_ALLOWED_HOSTS`. Listing a non-loopback host serves the store over plain HTTP with no authentication — only do it on a network you control.
|
|
344
|
-
|
|
345
|
-
## Installing a specific version
|
|
346
|
-
|
|
347
|
-
An unpinned entry resolves `@latest` exactly once and is never re-resolved afterwards, so updates are deliberate: `opencode plugin update opencode-self-improvement`. To pin, append `@<version>` — see [npm](https://www.npmjs.com/package/opencode-self-improvement) for what is current.
|
|
348
|
-
|
|
349
|
-
<details>
|
|
350
|
-
<summary>Install from a clone (development)</summary>
|
|
351
|
-
|
|
352
|
-
```sh
|
|
353
|
-
git clone https://github.com/abogartz/opencode-self-improvement.git
|
|
354
|
-
cd opencode-self-improvement
|
|
355
|
-
bun install
|
|
356
|
-
```
|
|
357
|
-
|
|
358
|
-
Then point the `plugins` entry at the local file instead:
|
|
359
|
-
|
|
360
|
-
```json
|
|
361
|
-
{
|
|
362
|
-
"$schema": "https://opencode.ai/config.json",
|
|
363
|
-
"plugins": ["/full/path/to/opencode-self-improvement/index.ts"]
|
|
364
|
-
}
|
|
365
|
-
```
|
|
366
|
-
|
|
367
|
-
After changes, `git pull` and restart opencode.
|
|
368
|
-
|
|
369
|
-
</details>
|
|
315
|
+
**Browser editor** — `bun memory-view`, then http://127.0.0.1:8787. Bound to loopback; requests are checked against `Host` and `Origin`, so other hosts must be listed explicitly in `OPENCODE_VIEWER_ALLOWED_HOSTS`. Listing a non-loopback host serves the store over plain HTTP with no authentication — only do it on a network you control. `OPENCODE_VIEWER_HOST` changes the bind interface.
|
|
370
316
|
|
|
371
317
|
## Development
|
|
372
318
|
|
|
@@ -376,47 +322,17 @@ Nothing merges without the full gate; CI runs it as required checks (`lint`, `te
|
|
|
376
322
|
bun run gate # typecheck + lint + unit tests + terminal smoke & BDD
|
|
377
323
|
bun run gate:hooks # once per clone: run the gate on `git push`
|
|
378
324
|
bun run format # apply the shared two-space TypeScript/TSX style
|
|
379
|
-
bun run format:check # check formatting without changing files
|
|
380
|
-
```
|
|
381
|
-
|
|
382
|
-
`bun run typecheck` runs `tsc --noEmit` on its own. In CI it runs inside the job named `lint`, so a green `lint` check silently implies tsc. The rest of the mapping: `bun run test` is the `test` job (re-run in `test-windows`, which reports but cannot gate merges), and `bun run test:e2e` is the `smoke` job.
|
|
383
|
-
|
|
384
|
-
`bun run lint` checks lint rules and TypeScript/TSX formatting; CI calls the same command. Lint warnings remain advisory, while formatting differences fail the check. Markdown commands, prose, JSON data and historical benchmark records are outside the formatter's scope.
|
|
385
|
-
|
|
386
|
-
Use Bun **1.4.4** for development checks, matching CI. `bun run test` and `bun run test:e2e` run files across at most four worker processes with Bun's file isolation; cases inside each file stay sequential because fixtures share environment variables and module state. The local gate uses those same scripts. To diagnose order-dependent failures in the original shared-process mode, run `bun test ./test/` or `bun test ./e2e/ --timeout 240000` directly.
|
|
387
|
-
|
|
388
|
-
**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. Then the unit tests for the pieces, then the code until everything is green. If no scenario turns red first, the feature has no observable contract.
|
|
389
|
-
|
|
390
|
-
`e2e/` boots the **real opencode CLI** against each candidate in a fully isolated instance (fresh config, fresh db, fresh memory store, empty `HOME`) driven by a scripted OpenAI-compatible fake model — no API keys. It covers loading from the source tree and from the packed npm artifact installed runtime-deps-only, plus BDD flows for remember, recall, exact and near duplicates, ungrounded claims, and forget. Needs `opencode` on `PATH` locally, or set `OPENCODE_BIN`. A `test-windows` leg also runs the suite on Windows; it reports without gating merges.
|
|
391
|
-
|
|
392
|
-
**The published surface is defined in `package.json`.** `exports` is the only import surface other code can reach (`.` → `index.ts`, `./tui` → `src/tui/panel.tsx`); `files` is the packaging list. `files` covers `src/`, so anything reachable from an `exports` target ships, but a new top-level file or directory — or anything the plugin reads at runtime outside those paths — must be added to `files` or it works from the checkout and vanishes from the npm artifact. The packed-artifact load in `e2e/` turns that miss red.
|
|
393
|
-
|
|
394
|
-
### Mutation sweep
|
|
395
|
-
|
|
396
|
-
```sh
|
|
397
|
-
bun run sweep:test
|
|
398
325
|
```
|
|
399
326
|
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
The output is a canonical mutation score — killed over total, with equivalent mutants and load errors excluded from the denominator — plus the survivors, the unpinned invariants. Survivors are the audit's output, not a scandal: some mutants are expected to survive and become entries on the unpinned list rather than red CI.
|
|
327
|
+
Use Bun **1.4.4** for development checks, matching CI. `bun run test` and `bun run test:e2e` run files across at most four worker processes; cases inside each file stay sequential because fixtures share environment variables and module state.
|
|
403
328
|
|
|
404
|
-
|
|
329
|
+
**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.
|
|
405
330
|
|
|
406
|
-
|
|
331
|
+
`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`.
|
|
407
332
|
|
|
408
|
-
|
|
333
|
+
**The published surface is `package.json`.** A new top-level file, or anything the plugin reads at runtime outside the packaged paths, must be added to `files` or it works from the checkout and vanishes from the npm artifact.
|
|
409
334
|
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
| Artifact | How to get it back |
|
|
413
|
-
| --- | --- |
|
|
414
|
-
| `bench/append-publication-198/` and its runner | The git history: `git log -- bench/runners/append-cost-198.ts`. The runner measured two pinned checkouts of pre-#168 modules and no longer runs against a current tree. |
|
|
415
|
-
| A mutation sweep log | `bun scripts/test-sweep.ts --log=<path>`. |
|
|
416
|
-
|
|
417
|
-
A script that needs a missing artifact names the file and the command that produces it instead of throwing a stack trace.
|
|
418
|
-
|
|
419
|
-
The `#71` set (`bench/test-integrity-71.json`, `bench/test-integrity-71/{before,after}.jsonl`, `bench/test-integrity-71-verdicts.json`, `bench/test-integrity-71-probes.json`) and its one-shot triage script are retired: the published numbers live in `bench/test-sweep-results.md`, and the raw files stay recoverable from history (`git log -- bench/test-integrity-71.json`).
|
|
335
|
+
How the local commands map to CI job names, what the smoke suite really boots, 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).
|
|
420
336
|
|
|
421
337
|
## Troubleshooting
|
|
422
338
|
|
|
@@ -425,13 +341,9 @@ The `#71` set (`bench/test-integrity-71.json`, `bench/test-integrity-71/{before,
|
|
|
425
341
|
| `memory_*` tools not available | The plugin didn't load. Restart opencode and check the `plugins` entry in your config. |
|
|
426
342
|
| `memory_remember` says blocked | A gate rejected the write: a stale code reference, a cited path that doesn't exist in the repo, overlap with a superseded memory, or an ambiguous claim. The reason is in `memory_evidence`; rephrase against current code and retry. |
|
|
427
343
|
| `invalid arguments to memory_*` | The call didn't match the tool's input schema; nothing was done and the message names the offending fields. Gate blocks look different (`blocked at GATE (…)`). |
|
|
428
|
-
|
|
|
429
|
-
| `memory store is busy` | A store write exhausted its 5s lock-wait budget. Appends, rewrites, and restores refuse that mutation rather than proceed unlocked and risk losing another writer's rows. 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. |
|
|
430
|
-
| Stray `*.logfmt.lock` or `*.tmp` in the store | Write bookkeeping left by an older release; safe to delete while nothing is writing. Current releases leave `.store-lock.<file>.sqlite` beside each store file and `.store-batch.<name>.sqlite`: coordination state, holding no rows, one file per lock, safe to delete while nothing is writing. |
|
|
344
|
+
| `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. |
|
|
431
345
|
| 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. |
|
|
432
|
-
| `/repo-init` missing from the command list | The self-install couldn't write to `~/.config/opencode/commands/`. Create it and restart, or ask the model to "init memory for this repo" — the same tool. |
|
|
433
|
-
| `memory_init` rejects a call naming `mode` | The code-graph integration was removed (#231) and the tool schema refuses unknown arguments — drop `mode` from the call. Stamps written by older versions (their text carries `graph=`/`mode=`) still read fine; no re-init is forced. |
|
|
434
346
|
| 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. |
|
|
435
|
-
|
|
|
436
|
-
|
|
437
|
-
|
|
347
|
+
| 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](#auto-capture). On desktop, changing any of these options needs `opencode service restart`. |
|
|
348
|
+
|
|
349
|
+
`STORE` showing malformed rows, stray lock files in the store, a missing `/repo-init`, a `memory_init` call naming `mode`, `Error: Plugin is not configured` right after `plugin add`, and a clean reset on Windows: [docs/troubleshooting.md](docs/troubleshooting.md).
|