opencode-self-improvement 0.31.0 → 0.31.1
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 +25 -171
- package/docs/contradiction-authority.md +9 -1
- package/docs/export-import.md +61 -0
- package/docs/flags.md +3 -2
- package/docs/import-quarantine.md +2 -1
- package/docs/injection-cost.md +1 -1
- package/docs/install.md +45 -0
- package/docs/recall-quality.md +4 -0
- package/docs/secret-redaction.md +51 -0
- package/docs/surfaces.md +39 -0
- package/docs/troubleshooting.md +13 -6
- package/docs/use-ledger.md +11 -0
- package/docs/write-latency.md +25 -0
- package/package.json +1 -1
- package/src/capture/runtime.ts +1 -1
- package/src/capture/triggers.ts +1 -1
- package/src/consolidate/propose.ts +1 -1
- package/src/core/config/paths.ts +1 -1
- package/src/events.ts +2 -2
- package/src/gate/gate.ts +1 -1
- package/src/identity/session-context.ts +1 -1
- package/src/index.ts +4 -7
- package/src/init/run.ts +1 -1
- package/src/init/stamp.ts +1 -1
- package/src/inject/digest.ts +1 -1
- package/src/inject/epochs.ts +2 -2
- package/src/recall/gate.ts +30 -4
- package/src/status/store-summary.ts +1 -1
- package/src/store/files/load.ts +1 -1
- package/src/store/lock.ts +1 -1
- package/src/store/prune.ts +1 -1
- package/src/store/tombstones/rejection.ts +1 -1
- package/src/store/tombstones/tombstone.ts +1 -1
- package/src/store/undo.ts +1 -1
- package/src/tools/consolidate.ts +2 -2
- package/src/tools/decay.ts +1 -1
- package/src/tools/deps.ts +1 -1
- package/src/tools/evidence.ts +1 -1
- package/src/tools/merge-review.ts +1 -1
- package/src/tools/recall.ts +15 -6
- package/src/tools/status-tool.ts +1 -1
- package/src/tools/update.ts +1 -1
- package/src/viewer/mutate.ts +1 -1
- /package/src/{command → init}/ensure.ts +0 -0
- /package/src/{hits → telemetry}/ledger.ts +0 -0
- /package/src/{evidence → telemetry}/record.ts +0 -0
package/README.md
CHANGED
|
@@ -23,32 +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
|
-
|
|
27
|
-
<summary>Other ways to install, and the version floor</summary>
|
|
28
|
-
|
|
29
|
-
```sh
|
|
30
|
-
opencode plugin add opencode-self-improvement
|
|
31
|
-
opencode plugin update opencode-self-improvement
|
|
32
|
-
```
|
|
33
|
-
|
|
34
|
-
Needs Bun 1.3.0 or newer in the opencode build (the tested floor); older Bun reports a startup warning.
|
|
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.
|
|
37
|
-
|
|
38
|
-
To work on the plugin instead, clone it and point the entry at the checkout:
|
|
39
|
-
|
|
40
|
-
```sh
|
|
41
|
-
git clone https://github.com/abogartz/opencode-self-improvement.git
|
|
42
|
-
cd opencode-self-improvement && bun install
|
|
43
|
-
```
|
|
44
|
-
|
|
45
|
-
```json
|
|
46
|
-
{ "plugins": ["/full/path/to/opencode-self-improvement/index.ts"] }
|
|
47
|
-
```
|
|
48
|
-
|
|
49
|
-
Then `git pull` and restart opencode to update.
|
|
50
|
-
|
|
51
|
-
</details>
|
|
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).
|
|
52
27
|
|
|
53
28
|
## What you get
|
|
54
29
|
|
|
@@ -61,9 +36,9 @@ Think of it as a lab notebook the agent keeps for your repo, plus a librarian wh
|
|
|
61
36
|
- **Memory-aware compaction** — a long session hands its durable facts to the summarizer instead of losing them.
|
|
62
37
|
- **Safe across concurrent sessions** — a reader sees the previous store file or the new one, never half of either.
|
|
63
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.
|
|
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 [
|
|
66
|
-
- **Secret redaction** — credential-shaped values become `[redacted]`. See [
|
|
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).
|
|
67
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`.
|
|
68
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).
|
|
69
44
|
|
|
@@ -78,23 +53,15 @@ Zero configuration is the default. Two options change what the model sees:
|
|
|
78
53
|
| `injectBudget` | `1200` | Character cap on the injected relevance block and each contextual pull. |
|
|
79
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. |
|
|
80
55
|
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
```json
|
|
84
|
-
{
|
|
85
|
-
"plugins": [{ "package": "opencode-self-improvement", "options": { "injectBudget": 1200, "frontierBudget": 3600 } }]
|
|
86
|
-
}
|
|
87
|
-
```
|
|
88
|
-
|
|
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).
|
|
90
|
-
|
|
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.
|
|
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.
|
|
92
57
|
|
|
93
58
|
## Auto-capture
|
|
94
59
|
|
|
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.
|
|
60
|
+
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 (default 3). 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.
|
|
61
|
+
|
|
62
|
+
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. Name `captureModel` only to pin one model: 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.
|
|
96
63
|
|
|
97
|
-
|
|
64
|
+
**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:
|
|
98
65
|
|
|
99
66
|
```json
|
|
100
67
|
{
|
|
@@ -102,23 +69,11 @@ It is **on by default** and needs no model name to run. With `captureModel` unse
|
|
|
102
69
|
}
|
|
103
70
|
```
|
|
104
71
|
|
|
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.
|
|
106
|
-
|
|
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.
|
|
108
|
-
|
|
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. |
|
|
116
|
-
|
|
117
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.
|
|
118
73
|
|
|
119
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".
|
|
120
75
|
|
|
121
|
-
**Am I armed?** `memory_evidence` answers on the `plugin_load` line: `capture=on` (the default), `capture=off` (`autoCapture: false`), `invalid_model`
|
|
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.
|
|
122
77
|
|
|
123
78
|
## How memory is written
|
|
124
79
|
|
|
@@ -131,25 +86,11 @@ A memory is a claim about your code, so it gets checked like one. Four gates run
|
|
|
131
86
|
|
|
132
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).
|
|
133
88
|
|
|
134
|
-
|
|
135
|
-
|
|
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
|
-
|
|
138
|
-
| Captured statement | Class | Verdict on a detected conflict |
|
|
139
|
-
| --- | --- | --- |
|
|
140
|
-
| User states the required value for a declared constant | `spec` | The user is the authority; change the constant to the stated requirement. |
|
|
141
|
-
| User describes how working code behaves | `behavior` | Code is the authority; keep the constant and raise the mismatch with the user. |
|
|
142
|
-
| Authority is unclear | Omit `klass` | Keep plain guidance and its staleness caveat; emit no CONFLICT verdict. |
|
|
143
|
-
|
|
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).
|
|
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).
|
|
145
90
|
|
|
146
91
|
## Repo scoping
|
|
147
92
|
|
|
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. `
|
|
149
|
-
|
|
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`.
|
|
151
|
-
|
|
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).
|
|
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).
|
|
153
94
|
|
|
154
95
|
## What memory is worth, measured
|
|
155
96
|
|
|
@@ -178,7 +119,7 @@ Two results. Only two are quoted, each with its `n` and the seat it ran on, beca
|
|
|
178
119
|
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.
|
|
179
120
|
|
|
180
121
|
- **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.
|
|
122
|
+
- **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. 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
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.
|
|
183
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.
|
|
184
125
|
|
|
@@ -198,47 +139,25 @@ No vector database, no embedding model, no API key: a keyword matcher. That is a
|
|
|
198
139
|
|
|
199
140
|
- **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
141
|
- **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
|
-
-
|
|
202
|
-
|
|
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`.
|
|
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
|
+
- **`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.
|
|
204
144
|
|
|
205
|
-
|
|
206
|
-
bun run bench:recall
|
|
207
|
-
```
|
|
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`.
|
|
208
146
|
|
|
209
147
|
## Write latency
|
|
210
148
|
|
|
211
|
-
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**
|
|
212
|
-
|
|
213
|
-
| Call forms in the write | Shipped | One scan per form |
|
|
214
|
-
| --- | ---: | ---: |
|
|
215
|
-
| 1 | 17ms | 105ms |
|
|
216
|
-
| 3 | 15ms | 136ms |
|
|
217
|
-
| 5 | 20ms | 169ms |
|
|
218
|
-
|
|
219
|
-
The shipped column is flat: the tree is walked once no matter how many references the write cites.
|
|
220
|
-
|
|
221
|
-
```sh
|
|
222
|
-
bun run bench:write
|
|
223
|
-
```
|
|
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).
|
|
224
150
|
|
|
225
151
|
## The store keeps score
|
|
226
152
|
|
|
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.
|
|
228
|
-
|
|
229
|
-
```
|
|
230
|
-
STORE
|
|
231
|
-
41 active · 12 superseded · 4 open · 6 scopes
|
|
232
|
-
retrieved 33 rows in the last 30d; never retrieved 8 (20%) — reported, not acted on
|
|
233
|
-
24.1 KB total · 604 B per row · 1.3 rows/day (30d)
|
|
234
|
-
```
|
|
153
|
+
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.
|
|
235
154
|
|
|
236
155
|
- **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
156
|
- **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
157
|
- **`never retrieved` is stated, not acted on.** Pruning is your decision.
|
|
239
158
|
- **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
159
|
|
|
241
|
-
|
|
160
|
+
Sample `STORE` output, the credit rule and its throttle, the consolidation tie-break, and capture lag: [docs/use-ledger.md](docs/use-ledger.md).
|
|
242
161
|
|
|
243
162
|
## Consolidation
|
|
244
163
|
|
|
@@ -253,66 +172,15 @@ The rule is: never merge two entries unless every question that used to find eit
|
|
|
253
172
|
|
|
254
173
|
## Secret redaction
|
|
255
174
|
|
|
256
|
-
One best-effort credential rule set (`src/secrets.ts`) replaces recognized values with `[redacted]
|
|
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.
|
|
264
|
-
|
|
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`).
|
|
266
|
-
|
|
267
|
-
Limits worth knowing:
|
|
268
|
-
|
|
269
|
-
- It can miss hex-only secrets, low-diversity passwords, and credentials written in prose without an assignment.
|
|
270
|
-
- Credential-shaped `scope`, `tags` or `issue` metadata is rejected rather than silently rewritten.
|
|
271
|
-
- `memory_remember` still replies `Remembered` when content was redacted, so the stored text can differ from what was sent.
|
|
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).
|
|
175
|
+
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).
|
|
274
176
|
|
|
275
177
|
## Export and move between machines
|
|
276
178
|
|
|
277
|
-
`memory_export` writes the store as JSONL
|
|
278
|
-
|
|
279
|
-
To move a store between machines:
|
|
280
|
-
|
|
281
|
-
```
|
|
282
|
-
Export my memories # -> <memory-root>/exports/<timestamp>-<unique>.jsonl
|
|
283
|
-
# …copy that file to the other machine's <memory-root>/…
|
|
284
|
-
Import <memory-root>/memories.jsonl # memory_import
|
|
285
|
-
```
|
|
286
|
-
|
|
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).
|
|
288
|
-
|
|
289
|
-
The import reply is a tally, not a yes/no:
|
|
290
|
-
|
|
291
|
-
| Outcome | Meaning |
|
|
292
|
-
| --- | --- |
|
|
293
|
-
| `promoted` | passed the gates and was stored |
|
|
294
|
-
| `collapsed` | near-duplicate of an existing memory; nothing written |
|
|
295
|
-
| `blocked` | rejected by a gate; reason in `memory_evidence` |
|
|
296
|
-
| `skipped` | malformed line; never reached the gates |
|
|
297
|
-
| `downgraded` | imported as settled because its `status:"open"` could not be vouched for |
|
|
298
|
-
|
|
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.
|
|
300
|
-
|
|
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).
|
|
179
|
+
`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).
|
|
302
180
|
|
|
303
181
|
## Surfaces
|
|
304
182
|
|
|
305
|
-
Same data behind each one (`memory_status`; no model call).
|
|
306
|
-
|
|
307
|
-
**Terminal (opencode CLI)** — the plugin ships a TUI half (`@opencode/plugin/tui`) that loads automatically:
|
|
308
|
-
|
|
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.
|
|
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.
|
|
311
|
-
- **Block toast** when a write is refused (`"notifyBlocked": false` to silence).
|
|
312
|
-
|
|
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.
|
|
314
|
-
|
|
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.
|
|
183
|
+
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).
|
|
316
184
|
|
|
317
185
|
## Development
|
|
318
186
|
|
|
@@ -326,24 +194,10 @@ bun run format # apply the shared two-space TypeScript/TSX style
|
|
|
326
194
|
|
|
327
195
|
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.
|
|
328
196
|
|
|
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.
|
|
330
|
-
|
|
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`.
|
|
332
|
-
|
|
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.
|
|
197
|
+
**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`.
|
|
334
198
|
|
|
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).
|
|
199
|
+
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).
|
|
336
200
|
|
|
337
201
|
## Troubleshooting
|
|
338
202
|
|
|
339
|
-
|
|
340
|
-
| --- | --- |
|
|
341
|
-
| `memory_*` tools not available | The plugin didn't load. Restart opencode and check the `plugins` entry in your config. |
|
|
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. |
|
|
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 (…)`). |
|
|
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. |
|
|
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. |
|
|
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. |
|
|
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).
|
|
203
|
+
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.
|
|
@@ -5,7 +5,15 @@ takes sides it has to be sure it is reading a real declaration, so the check is
|
|
|
5
5
|
deliberately narrow — and what it refuses to decide is the more useful half of
|
|
6
6
|
this document.
|
|
7
7
|
|
|
8
|
-
|
|
8
|
+
## Who is the authority
|
|
9
|
+
|
|
10
|
+
Capture records the kind of statement, and the verdict follows the class:
|
|
11
|
+
|
|
12
|
+
| Captured statement | Class | Verdict on a detected conflict |
|
|
13
|
+
| --- | --- | --- |
|
|
14
|
+
| User states the required value for a declared constant | `spec` | The user is the authority; change the constant to the stated requirement. |
|
|
15
|
+
| User describes how working code behaves | `behavior` | Code is the authority; keep the constant and raise the mismatch with the user. |
|
|
16
|
+
| Authority is unclear | Omit `klass` | Keep plain guidance and its staleness caveat; emit no CONFLICT verdict. |
|
|
9
17
|
|
|
10
18
|
## What the check will read
|
|
11
19
|
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
# Export, import, and moving a store between machines
|
|
2
|
+
|
|
3
|
+
`memory_export` writes the store as JSONL and `memory_import` reads such a file
|
|
4
|
+
back. The contract worth memorizing: **you get what you can read, and an import
|
|
5
|
+
is not trusted input.**
|
|
6
|
+
|
|
7
|
+
## What each tool exports
|
|
8
|
+
|
|
9
|
+
`memory_export` writes the store **as its caller can read it**: from a plugin
|
|
10
|
+
session that means your repository plus global rows. Full-store breadth belongs
|
|
11
|
+
to a session-less caller outside the plugin — the library route; the viewer has
|
|
12
|
+
no export route. `memory_import` reads such a file back, and every imported row
|
|
13
|
+
re-enters through the same four gates as `memory_remember` (tagged `import`,
|
|
14
|
+
original tags preserved).
|
|
15
|
+
|
|
16
|
+
## The move
|
|
17
|
+
|
|
18
|
+
```
|
|
19
|
+
Export my memories # -> <memory-root>/exports/<timestamp>-<unique>.jsonl
|
|
20
|
+
# …copy that file to the other machine's <memory-root>/…
|
|
21
|
+
Import <memory-root>/memories.jsonl # memory_import
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
Both tools are model-facing, so a path is not a privilege: `file` must stay
|
|
25
|
+
inside the store — exports under `<memory-root>/exports`, imports anywhere under
|
|
26
|
+
`<memory-root>` — and a symbolic link cannot carry a request out of it. Pass
|
|
27
|
+
`scope` to export one scope. An operator running a one-off migration can restore
|
|
28
|
+
the old anywhere-on-disk behaviour with `OPENCODE_MEMORY_ALLOW_OUTSIDE_PATHS=1`,
|
|
29
|
+
which is read from the plugin process's own environment so a model cannot grant
|
|
30
|
+
it to itself.
|
|
31
|
+
|
|
32
|
+
## The reply is a tally, not a yes/no
|
|
33
|
+
|
|
34
|
+
| Outcome | Meaning |
|
|
35
|
+
| --- | --- |
|
|
36
|
+
| `promoted` | passed the gates and was stored |
|
|
37
|
+
| `collapsed` | near-duplicate of an existing memory; nothing written |
|
|
38
|
+
| `blocked` | rejected by a gate; reason in `memory_evidence` |
|
|
39
|
+
| `skipped` | malformed line; never reached the gates |
|
|
40
|
+
| `downgraded` | imported as settled because its `status:"open"` could not be vouched for |
|
|
41
|
+
|
|
42
|
+
## What the format is, and what confinement costs
|
|
43
|
+
|
|
44
|
+
The line format, what an import will believe about `status:"open"`, and the two
|
|
45
|
+
confinement limits no path check closes (a hard link inside `exports/`, and the
|
|
46
|
+
looser check on intermediate components):
|
|
47
|
+
[docs/import-quarantine.md](import-quarantine.md).
|
|
48
|
+
|
|
49
|
+
## Quarantine
|
|
50
|
+
|
|
51
|
+
Import and auto-capture also scan incoming prose for instruction-override,
|
|
52
|
+
role-header and download/execute patterns. A promoted match is tagged `quarantine`
|
|
53
|
+
and withheld from recall, prompt and frontier injection, compaction anchors,
|
|
54
|
+
contextual pull, consolidation and decay. Think of it as a spam folder, not a
|
|
55
|
+
virus scanner: legitimate documentation can match, and several forms evade it.
|
|
56
|
+
Review the queue in the viewer's **quarantined** filter.
|
|
57
|
+
|
|
58
|
+
What the screen covers, what it misses, how an existing store is re-tagged, what
|
|
59
|
+
releasing quarantine does and what it leaves alone, and why direct
|
|
60
|
+
`memory_remember` and viewer edits are not scanned:
|
|
61
|
+
[docs/import-quarantine.md](import-quarantine.md).
|
package/docs/flags.md
CHANGED
|
@@ -2,7 +2,8 @@
|
|
|
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
|
|
5
|
+
does. The README names the three and points here; this file is the whole
|
|
6
|
+
behaviour.
|
|
6
7
|
|
|
7
8
|
`OPENCODE_MEMORY_SYMPTOM` is the clearest case. A lesson saved as "in this
|
|
8
9
|
session we fixed the flaky test" shares no words with the query a future
|
|
@@ -17,4 +18,4 @@ something unrecoverable.
|
|
|
17
18
|
| --- | --- |
|
|
18
19
|
| `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). |
|
|
19
20
|
| `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. |
|
|
20
|
-
| `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 —
|
|
21
|
+
| `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 — except when a complete query term matches an authored keyword unique among the visible candidates after scope and type filters. Automatic injection keeps its two-concept requirement. Set `off` (also `0`, `no`, `n`, `false`, or any zero) to restore the matcher's permissive one-word admission. |
|
|
@@ -5,7 +5,8 @@ store where you can read it, and is withheld from everything the model reads.
|
|
|
5
5
|
|
|
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
|
-
cover. The
|
|
8
|
+
cover. The export contract and the import tally are in
|
|
9
|
+
[docs/export-import.md](export-import.md).
|
|
9
10
|
|
|
10
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.
|
|
11
12
|
|
package/docs/injection-cost.md
CHANGED
|
@@ -12,7 +12,7 @@ claim, and a provider audit reported by its author.
|
|
|
12
12
|
|
|
13
13
|
- **Section-frozen injection.** The whole memory section — standing digest, open-thread frontier, relevance block — is computed once per epoch and delivered byte-identically until something the model actually needs changes. The epoch's authority is the **rendered bytes**, not the store fingerprint: a promoted row that changes nothing visible costs no cache bust.
|
|
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
|
-
- **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`
|
|
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
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
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)).
|
package/docs/install.md
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
# Install variants and the version floor
|
|
2
|
+
|
|
3
|
+
The README keeps the three-step path: add the entry, restart, run `/repo-init`.
|
|
4
|
+
This file holds the other ways to install, how updates are resolved, and what to
|
|
5
|
+
point at when you are working on the plugin itself.
|
|
6
|
+
|
|
7
|
+
## Plugin commands
|
|
8
|
+
|
|
9
|
+
```sh
|
|
10
|
+
opencode plugin add opencode-self-improvement
|
|
11
|
+
opencode plugin update opencode-self-improvement
|
|
12
|
+
```
|
|
13
|
+
|
|
14
|
+
Needs Bun 1.3.0 or newer in the opencode build (the tested floor); older Bun
|
|
15
|
+
reports a startup warning.
|
|
16
|
+
|
|
17
|
+
## How an unpinned entry resolves
|
|
18
|
+
|
|
19
|
+
An unpinned entry resolves `@latest` exactly once and is never re-resolved
|
|
20
|
+
afterwards, so updates are deliberate: run `opencode plugin update` when you want
|
|
21
|
+
one. To pin, append `@<version>` — see [npm](https://www.npmjs.com/package/opencode-self-improvement)
|
|
22
|
+
for what is current.
|
|
23
|
+
|
|
24
|
+
## Running from a checkout
|
|
25
|
+
|
|
26
|
+
To work on the plugin instead, clone it and point the entry at the checkout:
|
|
27
|
+
|
|
28
|
+
```sh
|
|
29
|
+
git clone https://github.com/abogartz/opencode-self-improvement.git
|
|
30
|
+
cd opencode-self-improvement && bun install
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
```json
|
|
34
|
+
{ "plugins": ["/full/path/to/opencode-self-improvement/index.ts"] }
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
Then `git pull` and restart opencode to update.
|
|
38
|
+
|
|
39
|
+
## Restart rules by host
|
|
40
|
+
|
|
41
|
+
A config edit needs a restart to take effect. On the desktop app, relaunching the
|
|
42
|
+
app is not enough: the background service stays alive with the options it already
|
|
43
|
+
parsed, so use `opencode service restart`. That is also why `memory_evidence` can
|
|
44
|
+
report a `capture=` value your config no longer contains. See
|
|
45
|
+
[docs/troubleshooting.md](troubleshooting.md).
|
package/docs/recall-quality.md
CHANGED
|
@@ -32,6 +32,10 @@ force a guess. Wrong top-memory fell to 6%. The cost is silence in cases where
|
|
|
32
32
|
a lucky guess would have been right; `memory_recall` still covers them when you
|
|
33
33
|
ask on purpose.
|
|
34
34
|
|
|
35
|
+
### Explicit exact-keyword lookup
|
|
36
|
+
|
|
37
|
+
See the [transport lookup benchmark](https://github.com/abogartz/opencode-self-improvement/blob/64c494a26866851077ed2d59504c62a4f7809b56/bench/transport-lookup-results.md) for explicit recall and automatic injection on the same queries.
|
|
38
|
+
|
|
35
39
|
## Why the default window is 5 rows
|
|
36
40
|
|
|
37
41
|
A live audit joined 1,090 recall events to their session transcripts. A
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
# Secret redaction: what it covers and what it cannot
|
|
2
|
+
|
|
3
|
+
One best-effort credential rule set (`src/secrets.ts`) replaces recognized values
|
|
4
|
+
with `[redacted]`. Think of it as a metal detector at every door, not a safe: it
|
|
5
|
+
stops the recognized shapes, and it will never promise it saw everything.
|
|
6
|
+
|
|
7
|
+
It runs at every boundary a credential could persist, not one:
|
|
8
|
+
|
|
9
|
+
- over the auto-capture prompt before it leaves the plugin — the complete
|
|
10
|
+
transcript is redacted *before* the character budget crops it, so a credential
|
|
11
|
+
cut in half still matches its pattern;
|
|
12
|
+
- at the write gate, before content is hashed or analysed;
|
|
13
|
+
- again in the final write choke point used by gated writes and by the viewer's
|
|
14
|
+
edit and restore paths;
|
|
15
|
+
- at the durable audit boundaries — every evidence line, every supersede field
|
|
16
|
+
written into a retired row, and every deletion-audit reason.
|
|
17
|
+
|
|
18
|
+
So a recognized credential cannot persist in a new `evidence/` line, in a
|
|
19
|
+
deletion-audit `reason`, or in a supersede field written into a retired row,
|
|
20
|
+
whichever path carried it. It is not scrubbed from everything those paths touch —
|
|
21
|
+
see the limits below.
|
|
22
|
+
|
|
23
|
+
## Covered patterns
|
|
24
|
+
|
|
25
|
+
OpenAI `sk-`, GitHub `ghp_` / `gho_` / `github_pat_`, Slack `xoxb-` / `xoxp-`,
|
|
26
|
+
AWS `AKIA`, Google `AIza`, bearer tokens containing digits, PEM private-key
|
|
27
|
+
blocks, and high-entropy values assigned to names ending in `_KEY`, `_TOKEN`,
|
|
28
|
+
`_SECRET` or `_PASSWORD` (plus `password`).
|
|
29
|
+
|
|
30
|
+
## Limits worth knowing
|
|
31
|
+
|
|
32
|
+
- It can miss hex-only secrets, low-diversity passwords, and credentials written
|
|
33
|
+
in prose without an assignment.
|
|
34
|
+
- Credential-shaped `scope`, `tags` or `issue` metadata is rejected rather than
|
|
35
|
+
silently rewritten.
|
|
36
|
+
- `memory_remember` still replies `Remembered` when content was redacted, so the
|
|
37
|
+
stored text can differ from what was sent.
|
|
38
|
+
- Redaction is forward-only: existing stores are not scrubbed. `memory_export`
|
|
39
|
+
scrubs credentials out of `content`, `issue`, `scope`, `tags` and `kw` as it
|
|
40
|
+
serialises, so the file that leaves the machine carries `[redacted]` where a
|
|
41
|
+
stored row still holds a token; the store itself is untouched, and origin
|
|
42
|
+
stamps (`repo`, `repoPath`) are written as stored. The scrubber is a
|
|
43
|
+
best-effort sweep over known token families and high-entropy credential-shaped
|
|
44
|
+
values — an exotic credential can survive it, so an export is still a file you
|
|
45
|
+
hand out deliberately.
|
|
46
|
+
- Deleting a row copies it, it does not scrub it. `deletions.logfmt` keeps the
|
|
47
|
+
deleted row's `content`, `tags`, `kw` and `issue` exactly as the row held them
|
|
48
|
+
— a restore-entry built from that line has to re-stamp and re-attach precisely
|
|
49
|
+
what was there — and redacts only the `reason`. So deleting a row that predates
|
|
50
|
+
redaction writes its credential into the audit. Snapshots carry whatever a
|
|
51
|
+
stored row holds, for the same reason. That retention is deliberate (#292).
|
package/docs/surfaces.md
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
# Surfaces
|
|
2
|
+
|
|
3
|
+
Four ways to see the same data. All of them read `memory_status`; none of them
|
|
4
|
+
makes a model call.
|
|
5
|
+
|
|
6
|
+
## Terminal (opencode CLI)
|
|
7
|
+
|
|
8
|
+
The plugin ships a TUI half (`@opencode/plugin/tui`) that loads automatically.
|
|
9
|
+
|
|
10
|
+
- **Footer badge** — illustrative `● mem 1157/1200c · cache 96%`: the injected
|
|
11
|
+
block against its budget, plus the measured session prompt-cache hit rate. The
|
|
12
|
+
dot is green (stable and warm), yellow (recent recompute, or 50–90% reads) or
|
|
13
|
+
red (last turn served almost nothing from cache); `—` until the first assistant
|
|
14
|
+
turn, and `—` throughout on a provider that reports no cache usage.
|
|
15
|
+
- **`/memory`** — session panel: **CONTEXT** (what is riding the prompt now and
|
|
16
|
+
how much of the budget it uses), **CACHE** (busts this session and the measured
|
|
17
|
+
cache-served share of prompt tokens), **INJECTED BLOCK** (the verbatim block, or
|
|
18
|
+
an explicit abstention), **RECENT BLOCKED WRITES** (with gate reasons), **STORE**
|
|
19
|
+
(active / superseded / open / scopes, plus `malformed` when a row's `ts` is not
|
|
20
|
+
a valid ISO instant — those rows are skipped by every reader). Keys: `r`
|
|
21
|
+
refresh, `f` fullscreen.
|
|
22
|
+
- **Block toast** when a write is refused (`notifyBlocked: false` to silence).
|
|
23
|
+
|
|
24
|
+
## Desktop / web / IDE
|
|
25
|
+
|
|
26
|
+
The terminal slots do not exist there, so use the self-installed
|
|
27
|
+
**`/memory-report`** chat command: the same sections rendered in the conversation.
|
|
28
|
+
|
|
29
|
+
## Browser editor
|
|
30
|
+
|
|
31
|
+
`bun memory-view`, then http://127.0.0.1:8787. Bound to loopback; requests are
|
|
32
|
+
checked against `Host` and `Origin`, so other hosts must be listed explicitly in
|
|
33
|
+
`OPENCODE_VIEWER_ALLOWED_HOSTS`. Listing a non-loopback host serves the store over
|
|
34
|
+
plain HTTP with no authentication — only do it on a network you control.
|
|
35
|
+
`OPENCODE_VIEWER_HOST` changes the bind interface.
|
|
36
|
+
|
|
37
|
+
The viewer is a trusted admin seat. Its edits and deleted-entry restores skip the
|
|
38
|
+
model-facing grounding and deduplication gates but honor the same value
|
|
39
|
+
rejections: [docs/import-quarantine.md](import-quarantine.md).
|
package/docs/troubleshooting.md
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
# Troubleshooting, full list
|
|
2
2
|
|
|
3
|
-
The
|
|
4
|
-
|
|
3
|
+
The whole list: the problems people actually run into, and the rarer ones. The
|
|
4
|
+
README points here rather than repeating the table.
|
|
5
5
|
|
|
6
6
|
## Rarer problems
|
|
7
7
|
|
|
@@ -16,7 +16,14 @@ rarer ones, and repeats the common ones so one search finds the whole list.
|
|
|
16
16
|
|
|
17
17
|
## Common problems
|
|
18
18
|
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
19
|
+
The seven cases a session actually hits.
|
|
20
|
+
|
|
21
|
+
| Problem | Fix |
|
|
22
|
+
| --- | --- |
|
|
23
|
+
| `memory_*` tools not available | The plugin didn't load. Restart opencode and check the `plugins` entry in your config. |
|
|
24
|
+
| `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. |
|
|
25
|
+
| `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 (…)`). |
|
|
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
|
+
| 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
|
+
| 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. |
|
package/docs/use-ledger.md
CHANGED
|
@@ -7,6 +7,17 @@ earning its place, or has nothing touched it in six months?
|
|
|
7
7
|
The ledger is `<memory-root>/hits.logfmt`: append-only, rotated at 2 MB, never
|
|
8
8
|
ingested as a memory, and reported in `memory_status` and the `/memory` panel.
|
|
9
9
|
|
|
10
|
+
## What it looks like
|
|
11
|
+
|
|
12
|
+
Illustrative output — shape, not a measurement:
|
|
13
|
+
|
|
14
|
+
```
|
|
15
|
+
STORE
|
|
16
|
+
41 active · 12 superseded · 4 open · 6 scopes
|
|
17
|
+
retrieved 33 rows in the last 30d; never retrieved 8 (20%) — reported, not acted on
|
|
18
|
+
24.1 KB total · 604 B per row · 1.3 rows/day (30d)
|
|
19
|
+
```
|
|
20
|
+
|
|
10
21
|
## What counts as use
|
|
11
22
|
|
|
12
23
|
Credit comes from three distinct sources, because "the model asked" and "the
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
# Write latency: one tree walk per write
|
|
2
|
+
|
|
3
|
+
A write that cites code references could scan your source tree once per
|
|
4
|
+
reference. It does not: one recursive walk, shared by GATE-1 and GATE-2, prunes
|
|
5
|
+
`node_modules` and VCS directories, and reads each source file at most once. The
|
|
6
|
+
table below is the difference between "walk the tree" and "walk it five times".
|
|
7
|
+
|
|
8
|
+
**Bench** — measured on a 5,300-file fixture (300 sources + 5,000 `node_modules`
|
|
9
|
+
decoys), scope seeded with 5 embedded call forms:
|
|
10
|
+
|
|
11
|
+
| Call forms in the write | Shipped | One scan per form |
|
|
12
|
+
| --- | ---: | ---: |
|
|
13
|
+
| 1 | 17ms | 105ms |
|
|
14
|
+
| 3 | 15ms | 136ms |
|
|
15
|
+
| 5 | 20ms | 169ms |
|
|
16
|
+
|
|
17
|
+
The shipped column is flat: the tree is walked once no matter how many references
|
|
18
|
+
the write cites.
|
|
19
|
+
|
|
20
|
+
```sh
|
|
21
|
+
bun run bench:write
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
What each gate does with what the walk finds:
|
|
25
|
+
[docs/write-gates.md](write-gates.md).
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "opencode-self-improvement",
|
|
3
|
-
"version": "0.31.
|
|
3
|
+
"version": "0.31.1",
|
|
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": {
|
package/src/capture/runtime.ts
CHANGED
|
@@ -9,7 +9,7 @@ import {
|
|
|
9
9
|
RESTATABLE_TAG,
|
|
10
10
|
USER_GUIDED_TAG,
|
|
11
11
|
} from "../core/tags.ts";
|
|
12
|
-
import { record, recordCaptureLag } from "../
|
|
12
|
+
import { record, recordCaptureLag } from "../telemetry/record.ts";
|
|
13
13
|
import { type GateContext, runWriteGate } from "../gate/gate.ts";
|
|
14
14
|
import { captureSessionID } from "../identity/host-events.ts";
|
|
15
15
|
import { bindSessionProvisional, writeTarget } from "../identity/repokey.ts";
|
package/src/capture/triggers.ts
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
// tool results, never by a model decision. Nothing here injects into chat.
|
|
3
3
|
import { existsSync } from "node:fs";
|
|
4
4
|
import { join } from "node:path";
|
|
5
|
-
import { record } from "../
|
|
5
|
+
import { record } from "../telemetry/record.ts";
|
|
6
6
|
import { evidenceDir } from "../core/config/paths.ts";
|
|
7
7
|
import { parseLine } from "../core/logfmt/format.ts";
|
|
8
8
|
import { readLines } from "../core/logfmt/read.ts";
|
|
@@ -27,7 +27,7 @@
|
|
|
27
27
|
// proposal through memory_merge_review (supersede-not-delete, recoverable).
|
|
28
28
|
// 4. The most recently used member is never a loser (the rule, inherited).
|
|
29
29
|
import type { Memory } from "../store/model/memory.ts";
|
|
30
|
-
import type { UseSignal } from "../
|
|
30
|
+
import type { UseSignal } from "../telemetry/ledger.ts";
|
|
31
31
|
import { cmpTs } from "../core/cmp-ts.ts";
|
|
32
32
|
import { formatMemory } from "../inject/format.ts";
|
|
33
33
|
import { scoreMemories, words } from "../recall/score.ts";
|
package/src/core/config/paths.ts
CHANGED
|
@@ -53,7 +53,7 @@ export function canonicalFile(): string {
|
|
|
53
53
|
return join(memoryRoot(), "canonical.logfmt");
|
|
54
54
|
}
|
|
55
55
|
|
|
56
|
-
// The use ledger (src/
|
|
56
|
+
// The use ledger (src/telemetry/ledger.ts). Lives in the store root beside the day files
|
|
57
57
|
// but is NOT a memory file: memory.ts's RESERVED set keeps it out of loadAll().
|
|
58
58
|
export const HITS_FILENAME = "hits.logfmt";
|
|
59
59
|
|
package/src/events.ts
CHANGED
|
@@ -4,9 +4,9 @@ import type { PluginCtx } from "./core/host.ts";
|
|
|
4
4
|
import type { guarded as Guarded } from "./core/hooks.ts";
|
|
5
5
|
import type { createInjectionEpochs } from "./inject/epochs.ts";
|
|
6
6
|
import type { Measured } from "./status/payload.ts";
|
|
7
|
-
import type { HitSource } from "./
|
|
7
|
+
import type { HitSource } from "./telemetry/ledger.ts";
|
|
8
8
|
import type { Memory } from "./store/model/memory.ts";
|
|
9
|
-
import { useSignals } from "./
|
|
9
|
+
import { useSignals } from "./telemetry/ledger.ts";
|
|
10
10
|
import { setCurrent } from "./core/state.ts";
|
|
11
11
|
import {
|
|
12
12
|
bindSessionProvisional,
|
package/src/gate/gate.ts
CHANGED
|
@@ -25,7 +25,7 @@ import {
|
|
|
25
25
|
contentHash,
|
|
26
26
|
record,
|
|
27
27
|
recordWriteBlocked,
|
|
28
|
-
} from "../
|
|
28
|
+
} from "../telemetry/record.ts";
|
|
29
29
|
import { getCurrent, noteAuthored } from "../core/state.ts";
|
|
30
30
|
import { MAX_WRITE_EVIDENCE_REFS } from "../capture/triggers.ts";
|
|
31
31
|
import { flattenMemoryText } from "../store/sanitize.ts";
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
// Per-setup session binding and caller context. The host object is kept
|
|
2
2
|
// intact so optional API methods retain their receiver and are read at call time.
|
|
3
3
|
import type { GateContext } from "../gate/gate.ts";
|
|
4
|
-
import { captureEvidenceContext, record } from "../
|
|
4
|
+
import { captureEvidenceContext, record } from "../telemetry/record.ts";
|
|
5
5
|
import { unresolvedWriteMessage } from "../store/files/append.ts";
|
|
6
6
|
import { readerFromSid } from "../store/model/visibility.ts";
|
|
7
7
|
import { getCurrent } from "../core/state.ts";
|
package/src/index.ts
CHANGED
|
@@ -37,10 +37,10 @@ import { findStaleOpen } from "./portable/decay.ts";
|
|
|
37
37
|
import { exportMemories } from "./portable/export.ts";
|
|
38
38
|
import { importMemories } from "./portable/import.ts";
|
|
39
39
|
import { listSnapshots, restoreSnapshot } from "./store/undo.ts";
|
|
40
|
-
import { evidenceFileFor, record } from "./
|
|
40
|
+
import { evidenceFileFor, record } from "./telemetry/record.ts";
|
|
41
41
|
import { proposeConsolidations } from "./consolidate/propose.ts";
|
|
42
42
|
import { renderProposals } from "./consolidate/render.ts";
|
|
43
|
-
import { readReads } from "./
|
|
43
|
+
import { readReads } from "./telemetry/ledger.ts";
|
|
44
44
|
import { formatMemory } from "./inject/format.ts";
|
|
45
45
|
import { sharedTerms } from "./recall/shared-terms.ts";
|
|
46
46
|
import {
|
|
@@ -62,13 +62,10 @@ import {
|
|
|
62
62
|
neverRetrieved,
|
|
63
63
|
recordHits,
|
|
64
64
|
type HitSource,
|
|
65
|
-
} from "./
|
|
65
|
+
} from "./telemetry/ledger.ts";
|
|
66
66
|
import { formatInit } from "./init/format.ts";
|
|
67
67
|
import { runInit } from "./init/run.ts";
|
|
68
|
-
import {
|
|
69
|
-
ensureInitCommand,
|
|
70
|
-
ensureMemoryReportCommand,
|
|
71
|
-
} from "./command/ensure.ts";
|
|
68
|
+
import { ensureInitCommand, ensureMemoryReportCommand } from "./init/ensure.ts";
|
|
72
69
|
import { captureLag, captureLagLines, rowsPerDay } from "./status/metrics.ts";
|
|
73
70
|
import { type Measured, type StoreCounts } from "./status/payload.ts";
|
|
74
71
|
import { renderMemoryReport } from "./status/report.ts";
|
package/src/init/run.ts
CHANGED
|
@@ -10,7 +10,7 @@
|
|
|
10
10
|
import { basename } from "node:path";
|
|
11
11
|
import { readerFromSid } from "../store/model/visibility.ts";
|
|
12
12
|
import { runWriteGate, type GateContext } from "../gate/gate.ts";
|
|
13
|
-
import { captureEvidenceContext, record } from "../
|
|
13
|
+
import { captureEvidenceContext, record } from "../telemetry/record.ts";
|
|
14
14
|
import { writeEvidence, hasGateCheck } from "../capture/triggers.ts";
|
|
15
15
|
import { writeTarget } from "../identity/repokey.ts";
|
|
16
16
|
import { quarantineCandidate } from "../store/quarantine/quarantine.ts";
|
package/src/init/stamp.ts
CHANGED
|
@@ -26,7 +26,7 @@ import { INIT_STAMP_TAG } from "../core/tags.ts";
|
|
|
26
26
|
import { preparePrivateFile, tightenDirectory } from "../core/permissions.ts";
|
|
27
27
|
import { parseLine } from "../core/logfmt/format.ts";
|
|
28
28
|
import { readLines } from "../core/logfmt/read.ts";
|
|
29
|
-
import { evidenceFileFor } from "../
|
|
29
|
+
import { evidenceFileFor } from "../telemetry/record.ts";
|
|
30
30
|
import { resolveRepo } from "../identity/repokey.ts";
|
|
31
31
|
import { loadAll } from "../store/files/load.ts";
|
|
32
32
|
import { markSuperseded } from "../store/files/supersede.ts";
|
package/src/inject/digest.ts
CHANGED
|
@@ -3,7 +3,7 @@ import { loadAll } from "../store/files/load.ts";
|
|
|
3
3
|
import { type Memory } from "../store/model/memory.ts";
|
|
4
4
|
import { isInjectable } from "../store/model/predicates.ts";
|
|
5
5
|
import { readerFromSid, visibleTo } from "../store/model/visibility.ts";
|
|
6
|
-
import { captureEvidenceContext, record } from "../
|
|
6
|
+
import { captureEvidenceContext, record } from "../telemetry/record.ts";
|
|
7
7
|
import { frontierBudget } from "../core/config/budgets.ts";
|
|
8
8
|
import { SESSION_CAP, SessionLru } from "../core/lru.ts";
|
|
9
9
|
import { dateStr } from "../core/time.ts";
|
package/src/inject/epochs.ts
CHANGED
|
@@ -5,7 +5,7 @@ import { type Memory } from "../store/model/memory.ts";
|
|
|
5
5
|
import { isInjectable } from "../store/model/predicates.ts";
|
|
6
6
|
import { isVisibleTo, readerFromSid } from "../store/model/visibility.ts";
|
|
7
7
|
import { SESSION_CAP, SessionLru } from "../core/lru.ts";
|
|
8
|
-
import { captureEvidenceContext, record } from "../
|
|
8
|
+
import { captureEvidenceContext, record } from "../telemetry/record.ts";
|
|
9
9
|
import { capToBudget, injectedRows } from "./budget.ts";
|
|
10
10
|
import { systemDigest } from "./digest.ts";
|
|
11
11
|
import { storeVersion } from "./version.ts";
|
|
@@ -15,7 +15,7 @@ import {
|
|
|
15
15
|
deriveMemoryRefs,
|
|
16
16
|
type MemoryRefs,
|
|
17
17
|
} from "./attribution.ts";
|
|
18
|
-
import { readLedger, useSignals } from "../
|
|
18
|
+
import { readLedger, useSignals } from "../telemetry/ledger.ts";
|
|
19
19
|
import { summarizeStore } from "../status/store-summary.ts";
|
|
20
20
|
import {
|
|
21
21
|
emptyStats,
|
package/src/recall/gate.ts
CHANGED
|
@@ -2,10 +2,8 @@
|
|
|
2
2
|
//
|
|
3
3
|
// A query of LONG_QUERY_TOKENS concepts or more is a deliberate search: a row
|
|
4
4
|
// must share two whole-word concepts with it to be returned. Shorter queries
|
|
5
|
-
// keep
|
|
6
|
-
//
|
|
7
|
-
// paths must agree on when nothing is a good enough answer. Admission only:
|
|
8
|
-
// ranking, scoring and window size are untouched.
|
|
5
|
+
// keep one-concept admission. Explicit lookup also accepts a complete authored
|
|
6
|
+
// alias that identifies a single candidate. Automatic injection stays stricter.
|
|
9
7
|
//
|
|
10
8
|
// ON by default. Off only for an explicit negative (see gateEnabled): a
|
|
11
9
|
// quality fix that nobody flips on is not a fix, and a typo must not disable
|
|
@@ -93,6 +91,34 @@ export function rowConcepts(m: Memory): Set<string> {
|
|
|
93
91
|
return out;
|
|
94
92
|
}
|
|
95
93
|
|
|
94
|
+
/** A literal query term may name one visible row by its complete authored alias. */
|
|
95
|
+
export function exactAliasMatches(
|
|
96
|
+
query: string,
|
|
97
|
+
concepts: readonly string[],
|
|
98
|
+
rows: readonly Memory[],
|
|
99
|
+
): Set<Memory> {
|
|
100
|
+
const matches = new Set<Memory>();
|
|
101
|
+
if (concepts.length < LONG_QUERY_TOKENS) return matches;
|
|
102
|
+
const terms = new Set(
|
|
103
|
+
(query.toLowerCase().match(/[a-z0-9_.\-/]+/g) ?? [])
|
|
104
|
+
.map((id) => id.replace(/^[./-]+|[./-]+$/g, ""))
|
|
105
|
+
.filter((id) => id.length > 2 && !QUERY_STOPWORDS.has(id)),
|
|
106
|
+
);
|
|
107
|
+
const owners = new Map<string, Memory>();
|
|
108
|
+
for (const row of rows)
|
|
109
|
+
for (const alias of row.kw ?? [])
|
|
110
|
+
if (terms.has(alias)) owners.set(alias, row);
|
|
111
|
+
if (!owners.size) return matches;
|
|
112
|
+
for (const row of rows) {
|
|
113
|
+
const indexed = rowConcepts(row);
|
|
114
|
+
for (const [alias, owner] of owners)
|
|
115
|
+
if (row !== owner && indexed.has(alias)) owners.delete(alias);
|
|
116
|
+
if (!owners.size) break;
|
|
117
|
+
}
|
|
118
|
+
for (const owner of owners.values()) matches.add(owner);
|
|
119
|
+
return matches;
|
|
120
|
+
}
|
|
121
|
+
|
|
96
122
|
/** How many of `concepts` the row contains as whole words (or identifier segments). */
|
|
97
123
|
export function sharedConcepts(
|
|
98
124
|
m: Memory,
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
// Shared store counts for epoch payloads and the chat report.
|
|
2
2
|
// Callers own I/O and visibility policy; this summarizes exactly their rows.
|
|
3
|
-
import { neverRetrieved, type UseLedger } from "../
|
|
3
|
+
import { neverRetrieved, type UseLedger } from "../telemetry/ledger.ts";
|
|
4
4
|
import type { Memory } from "../store/model/memory.ts";
|
|
5
5
|
import { isActive } from "../store/model/predicates.ts";
|
|
6
6
|
import type { StoreCounts } from "./payload.ts";
|
package/src/store/files/load.ts
CHANGED
|
@@ -29,7 +29,7 @@ const RESERVED = new Set([
|
|
|
29
29
|
// Value-keyed rejection tombstones. Hashes only, never prose — and it
|
|
30
30
|
// must never be ingested as a row, exported, or restored by undo.
|
|
31
31
|
"rejected.logfmt",
|
|
32
|
-
// The use ledger (src/
|
|
32
|
+
// The use ledger (src/telemetry/ledger.ts): telemetry, not memory. A hit line must never
|
|
33
33
|
// be able to become a row — or to be superseded, exported, or injected.
|
|
34
34
|
HITS_FILENAME,
|
|
35
35
|
]);
|
package/src/store/lock.ts
CHANGED
|
@@ -54,7 +54,7 @@ import { chmod, unlink } from "node:fs/promises";
|
|
|
54
54
|
import { basename, dirname, join } from "node:path";
|
|
55
55
|
import { Database } from "bun:sqlite";
|
|
56
56
|
import { ensureDir } from "../core/logfmt/publish.ts";
|
|
57
|
-
import { record } from "../
|
|
57
|
+
import { record } from "../telemetry/record.ts";
|
|
58
58
|
|
|
59
59
|
/**
|
|
60
60
|
* The lock database for ONE store file: `.store-lock.<file>.sqlite`, beside it.
|
package/src/store/prune.ts
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
// reversible (snapshot) and never touches a repo. The `prune` evidence line is
|
|
3
3
|
// emitted after prune() returns so S5 can assert the reason and snapshot.
|
|
4
4
|
import { deletionsFile } from "../core/config/paths.ts";
|
|
5
|
-
import { record } from "../
|
|
5
|
+
import { record } from "../telemetry/record.ts";
|
|
6
6
|
import { type PruneResult, prune } from "./files/prune.ts";
|
|
7
7
|
import { readerFromSid } from "./model/visibility.ts";
|
|
8
8
|
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
// rejection — split from src/tombstones.ts. Declaration bodies are unchanged.
|
|
2
2
|
import { join } from "node:path";
|
|
3
3
|
import { memoryRoot } from "../../core/config/paths.ts";
|
|
4
|
-
import { contentHash } from "../../
|
|
4
|
+
import { contentHash } from "../../telemetry/record.ts";
|
|
5
5
|
import {
|
|
6
6
|
differsIn,
|
|
7
7
|
NEAR_FLOOR,
|
|
@@ -59,7 +59,7 @@ import {
|
|
|
59
59
|
STOPWORDS,
|
|
60
60
|
tokens,
|
|
61
61
|
} from "../../core/tokenize.ts";
|
|
62
|
-
import { contentHash } from "../../
|
|
62
|
+
import { contentHash } from "../../telemetry/record.ts";
|
|
63
63
|
import { LOCK_WRITE, withStoreLock } from "../lock.ts";
|
|
64
64
|
import { redactSecrets } from "../secrets.ts";
|
|
65
65
|
import {
|
package/src/store/undo.ts
CHANGED
|
@@ -36,7 +36,7 @@ import {
|
|
|
36
36
|
writeAtomic,
|
|
37
37
|
} from "../core/logfmt/publish.ts";
|
|
38
38
|
import { readLines } from "../core/logfmt/read.ts";
|
|
39
|
-
import { contentHash } from "../
|
|
39
|
+
import { contentHash } from "../telemetry/record.ts";
|
|
40
40
|
import { isWithin } from "./containment.ts";
|
|
41
41
|
import { snapshotFiles } from "./files/snapshots.ts";
|
|
42
42
|
import { LOCK_RESTORE, withStoreLock } from "./lock.ts";
|
package/src/tools/consolidate.ts
CHANGED
|
@@ -4,8 +4,8 @@
|
|
|
4
4
|
import type { ToolRegister } from "./deps.ts";
|
|
5
5
|
import { proposeConsolidations } from "../consolidate/propose.ts";
|
|
6
6
|
import { renderProposals } from "../consolidate/render.ts";
|
|
7
|
-
import { captureEvidenceContext, record } from "../
|
|
8
|
-
import { readLedger, readReads } from "../
|
|
7
|
+
import { captureEvidenceContext, record } from "../telemetry/record.ts";
|
|
8
|
+
import { readLedger, readReads } from "../telemetry/ledger.ts";
|
|
9
9
|
import { loadAll } from "../store/files/load.ts";
|
|
10
10
|
import { isInjectable } from "../store/model/predicates.ts";
|
|
11
11
|
import { isVisibleTo, readerFromSid } from "../store/model/visibility.ts";
|
package/src/tools/decay.ts
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
// and handler are byte-identical to the pre-split source; closure access arrives
|
|
3
3
|
// through ToolDeps.
|
|
4
4
|
import type { ToolRegister } from "./deps.ts";
|
|
5
|
-
import { captureEvidenceContext, record } from "../
|
|
5
|
+
import { captureEvidenceContext, record } from "../telemetry/record.ts";
|
|
6
6
|
import { snapshotFiles } from "../store/files/snapshots.ts";
|
|
7
7
|
import { markManySuperseded } from "../store/files/supersede.ts";
|
|
8
8
|
import { findStaleOpen } from "../portable/decay.ts";
|
package/src/tools/deps.ts
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
// so a tool file never reaches into the plugin setup closure.
|
|
4
4
|
import type { GateContext } from "../gate/gate.ts";
|
|
5
5
|
import type { createInjectionEpochs } from "../inject/epochs.ts";
|
|
6
|
-
import type { HitSource } from "../
|
|
6
|
+
import type { HitSource } from "../telemetry/ledger.ts";
|
|
7
7
|
import type { Memory } from "../store/model/memory.ts";
|
|
8
8
|
|
|
9
9
|
export interface ToolDeps {
|
package/src/tools/evidence.ts
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
// and handler are byte-identical to the pre-split source; closure access arrives
|
|
3
3
|
// through ToolDeps.
|
|
4
4
|
import type { ToolRegister } from "./deps.ts";
|
|
5
|
-
import { evidenceFileFor } from "../
|
|
5
|
+
import { evidenceFileFor } from "../telemetry/record.ts";
|
|
6
6
|
import { parseLine } from "../core/logfmt/format.ts";
|
|
7
7
|
import { readLines } from "../core/logfmt/read.ts";
|
|
8
8
|
import { evidenceVisibleTo, readerFromSid } from "../store/model/visibility.ts";
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
// Closure access arrives through ToolDeps.
|
|
3
3
|
import type { ToolRegister } from "./deps.ts";
|
|
4
4
|
import { memoryRoot } from "../core/config/paths.ts";
|
|
5
|
-
import { record } from "../
|
|
5
|
+
import { record } from "../telemetry/record.ts";
|
|
6
6
|
import { withStoreBatch } from "../store/lock.ts";
|
|
7
7
|
import { loadAll } from "../store/files/load.ts";
|
|
8
8
|
import { clearSuperseded, markSuperseded } from "../store/files/supersede.ts";
|
package/src/tools/recall.ts
CHANGED
|
@@ -2,10 +2,11 @@
|
|
|
2
2
|
// and handler are byte-identical to the pre-split source; closure access arrives
|
|
3
3
|
// through ToolDeps.
|
|
4
4
|
import type { ToolRegister } from "./deps.ts";
|
|
5
|
-
import { record } from "../
|
|
5
|
+
import { record } from "../telemetry/record.ts";
|
|
6
6
|
import { formatMemory } from "../inject/format.ts";
|
|
7
7
|
import {
|
|
8
8
|
admitsRow,
|
|
9
|
+
exactAliasMatches,
|
|
9
10
|
gateEnabled,
|
|
10
11
|
queryConcepts,
|
|
11
12
|
recallHaystack,
|
|
@@ -51,14 +52,22 @@ export const register: ToolRegister = (editor, deps) => {
|
|
|
51
52
|
results = results.filter((m) => m.scope.includes(args.scope!));
|
|
52
53
|
if (args.type) results = results.filter((m) => m.type === args.type);
|
|
53
54
|
if (args.query) {
|
|
54
|
-
// Default on: a row must share two whole words of the query — the
|
|
55
|
-
// concepts rule, not the scorer's substring test (src/recall/gate.ts,
|
|
56
|
-
//). OPENCODE_MEMORY_QUERY_GATE=off restores the old matcher.
|
|
57
55
|
const gate = gateEnabled();
|
|
58
56
|
const concepts = gate ? queryConcepts(args.query) : [];
|
|
57
|
+
const aliases = exactAliasMatches(args.query, concepts, results);
|
|
59
58
|
results = results
|
|
60
|
-
.map((m) => ({
|
|
61
|
-
|
|
59
|
+
.map((m) => ({
|
|
60
|
+
m,
|
|
61
|
+
score: Math.max(
|
|
62
|
+
scoreMemory(m, args.query!),
|
|
63
|
+
aliases.has(m) ? 1 : 0,
|
|
64
|
+
),
|
|
65
|
+
}))
|
|
66
|
+
.filter(
|
|
67
|
+
(x) =>
|
|
68
|
+
x.score > 0 &&
|
|
69
|
+
(!gate || aliases.has(x.m) || admitsRow(x.m, concepts)),
|
|
70
|
+
)
|
|
62
71
|
.sort((a, b) => b.score - a.score)
|
|
63
72
|
.map((x) => x.m);
|
|
64
73
|
}
|
package/src/tools/status-tool.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
// The memory_status tool, extracted from index.ts.
|
|
2
2
|
// Closure access arrives through ToolDeps.
|
|
3
3
|
import type { ToolRegister } from "./deps.ts";
|
|
4
|
-
import { readLedger } from "../
|
|
4
|
+
import { readLedger } from "../telemetry/ledger.ts";
|
|
5
5
|
import { formatMemory } from "../inject/format.ts";
|
|
6
6
|
import { loadAll, malformedCount } from "../store/files/load.ts";
|
|
7
7
|
import { isVisibleTo, readerFromSid } from "../store/model/visibility.ts";
|
package/src/tools/update.ts
CHANGED
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
import { join } from "node:path";
|
|
6
6
|
import { memoryRoot } from "../core/config/paths.ts";
|
|
7
7
|
import { nonCaptureTags } from "../core/guidance.ts";
|
|
8
|
-
import { record } from "../
|
|
8
|
+
import { record } from "../telemetry/record.ts";
|
|
9
9
|
import { auditCaveat, runWriteGate, sameStrList } from "../gate/gate.ts";
|
|
10
10
|
import { loadAll } from "../store/files/load.ts";
|
|
11
11
|
import { markSuperseded } from "../store/files/supersede.ts";
|
package/src/viewer/mutate.ts
CHANGED
|
@@ -13,7 +13,7 @@ import {
|
|
|
13
13
|
chainId,
|
|
14
14
|
contentHash,
|
|
15
15
|
targetRepoFields,
|
|
16
|
-
} from "../
|
|
16
|
+
} from "../telemetry/record.ts";
|
|
17
17
|
import { removeTombstone, tombstone } from "../store/tombstones/tombstone.ts";
|
|
18
18
|
import { redactSecrets } from "../store/secrets.ts";
|
|
19
19
|
import { formatLine, parseLine } from "../core/logfmt/format.ts";
|
|
File without changes
|
|
File without changes
|
|
File without changes
|