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
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
# ADR 0001 — Two-concept admission for the recall tool
|
|
2
|
+
|
|
3
|
+
Status: accepted (2026-11). Code: `src/recall/gate.ts`. Flag: `OPENCODE_MEMORY_QUERY_GATE`.
|
|
4
|
+
|
|
5
|
+
## Decision
|
|
6
|
+
|
|
7
|
+
A `memory_recall` query of three or more concepts must share two whole-word concepts with a row for that row to be returned. Shorter queries keep the permissive one-concept admission. ON by default; off only for an explicit negative value.
|
|
8
|
+
|
|
9
|
+
## Why
|
|
10
|
+
|
|
11
|
+
The tool scored rows by counting query words appearing as substrings and returned anything above zero. Measured on 404 real recall queries from 30 days of session transcripts, relevance labelled by two independent readers against a pinned store snapshot: a large share of returned rows was judged irrelevant rather than answering. The injection path already refused single-concept matches for deliberate searches; the two paths disagreeing was the bug.
|
|
12
|
+
|
|
13
|
+
## History
|
|
14
|
+
|
|
15
|
+
- The first implementation reused the tool's own substring test. It was satisfiable by accidents: `on` occurs inside `context` and `decision`, `pr` inside `preference`, `283` inside `build2837` — the motivating query `watermark 283 287 head` still admitted the row it was meant to refuse. The numbers measured with substring counting are void; do not quote them.
|
|
16
|
+
- Default-ON was decided with the rule: a quality fix that nobody flips on is not a fix. The off-list is explicit negatives (`off`, `no`, `n`, `false`, any zero); unset, empty, or a typo means ON.
|
|
17
|
+
- Admission vocabulary carries the scorer tokenizer's identifier granularity plus the underscore- and dot-joined whole forms, so prose queries find identifiers written in any style (`discount tiers` finds `DISCOUNT_TIERS`; `discount` finds `discountTiers`; `db_id` finds `table.db_id`). This closed three reproduced regressions in review; each is pinned by a composed-handler test.
|
|
18
|
+
- Evidence: 404-query case bank (data deliberately never committed; only aggregates were published). See issues #409 and #418 and PR #426 for the measured tables.
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
# ADR 0002 — Near-duplicate suppression inside the recall window
|
|
2
|
+
|
|
3
|
+
Status: accepted (2026-11). Code: `src/recall/dedupe.ts`. Flag: `OPENCODE_MEMORY_DEDUP`.
|
|
4
|
+
|
|
5
|
+
## Decision
|
|
6
|
+
|
|
7
|
+
One deterministic pass after ranking: skip a candidate whose content-token Jaccard against an already-kept row of the same scope reaches the threshold (default 0.8, ON). The newest copy of a clash takes the slot.
|
|
8
|
+
|
|
9
|
+
## Why
|
|
10
|
+
|
|
11
|
+
The live store carries repeated rows — superseded snapshots, cursor rows differing only by a timestamp, the same decision restated after a compaction — and the matcher scores them alike. With a fixed window they crowd out distinct facts, which breaks composition: two memories a later task needs together rarely fit side by side because the first one's copies take the slots. Recency decides because the duplicates are stale by construction.
|
|
12
|
+
|
|
13
|
+
## History
|
|
14
|
+
|
|
15
|
+
- Threshold guidance from the live replay: 0.5–0.7 suppresses rows that are merely related (92% of them at 0.5) and forces the window deep into the ranking; 0.8 suppresses only near-identical copies. Values below 0.5 are a misconfiguration, not an aggressive setting — at Jaccard 1e-9 a single shared fragment suppressed rows.
|
|
16
|
+
- The first version made four mistakes, each now pinned by a test:
|
|
17
|
+
1. It scored `type` and `scope` as tokens, so same-scope rows shared two free tokens and short rows looked like copies of each other.
|
|
18
|
+
2. It compared whole token sets, so a prohibition read as a copy of the permission it denies: "force push main" inside "never force push main" reaches Jaccard 0.833 and the wrong copy survived.
|
|
19
|
+
3. It had no floor. Non-Latin prose tokenises to nothing under `words()`, so two unrelated Chinese rows in one scope both reduced to the empty set; the pre-floor version scored them on type and scope alone at 1.0 and deleted the second row.
|
|
20
|
+
4. It treated differing numeric facts as duplicates: short tokens are dropped, so "DB 3" and "DB 4" share identical token sets and the older row was suppressed even at threshold 1.
|
|
21
|
+
- Default-ON followed the same rule as ADR 0001: a quality fix behind an opt-in flag is not a fix.
|
|
22
|
+
- Evidence: live-store replay published in the #409 record (§17) and PR #426. The replay's off-arm must set `OPENCODE_MEMORY_DEDUP=0` explicitly — with default-ON, an unset arm measures nothing.
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
# ADR 0003 — Identifier-aware tokenizer at two granularities
|
|
2
|
+
|
|
3
|
+
Status: accepted (2026-11). Code: `words()` in `src/recall/score.ts`.
|
|
4
|
+
|
|
5
|
+
## Decision
|
|
6
|
+
|
|
7
|
+
Each identifier (a maximal run of letters, digits, `_`, `.`, `-`, `/`) emits two granularities: the whole identifier lower-cased, and its segments split at camelCase boundaries and separators. The scan is one linear pass with no backtracking.
|
|
8
|
+
|
|
9
|
+
## Why
|
|
10
|
+
|
|
11
|
+
The shipped tokenizer kept `_` inside a token and never touched case, so `getUserAccount`, `get_user_account` and `get-user-account` were three unrelated tokens. Segments make identifier styles match each other: a query typed `getUserAccount` shares `get`, `user`, `account` with a row written `get_user_account`.
|
|
12
|
+
|
|
13
|
+
The whole form is not redundant: it preserves the exact match the shipped tokenizer had — `db_id` and `OPENCODE_MEMORY_DIR` stay single tokens, and an authored keyword stored fused (`memoryrecallthreshold`) still matches the query that cites it.
|
|
14
|
+
|
|
15
|
+
## History
|
|
16
|
+
|
|
17
|
+
- The first version of this change dropped the whole form. It abstained on `db_id` queries and broke the vocabulary bridge for camelCase aliases (#40). Both granularities are load-bearing; the regression tests say so.
|
|
18
|
+
- Measured on the bench fixture at the shipped configuration (`kw` indexed, store 200 and 48): lexical R@1 stays 98% and top-1 noise stays 6%. The fixture's queries never spell the same identifier two ways, so this is a correctness fix the fixture cannot price, not a measured win. The no-keyword arm moves (R@1 98% → 100%), but production indexes keywords.
|
|
19
|
+
- Admission (ADR 0001) reuses this tokenizer plus the underscore/dot-joined whole forms; it must never be narrower than the scorer.
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
# ADR 0004 — Viewer startup token on non-loopback binds
|
|
2
|
+
|
|
3
|
+
Status: accepted (2026-11). Code: `src/viewer/server.ts`.
|
|
4
|
+
|
|
5
|
+
## Decision
|
|
6
|
+
|
|
7
|
+
A non-loopback bind or allowed host mints a startup token (0600, in the store root); every request must present it. Loopback stays open. The Host/Origin layer remains as the CSRF defence it always was, but it is not the only thing between the LAN and the store.
|
|
8
|
+
|
|
9
|
+
## Why
|
|
10
|
+
|
|
11
|
+
Exposure without authentication was the defect: with a non-loopback bind every read and mutation was open HTTP for the whole LAN.
|
|
12
|
+
|
|
13
|
+
## History
|
|
14
|
+
|
|
15
|
+
- Concurrent first starts (same process or separate processes) must agree on ONE token. The claim is an atomic hard-link of a fully-written 0600 temp: `link(2)` refuses an existing target, so exactly one starter's content lands and every loser reads back the winner's complete token.
|
|
16
|
+
- The hard-link claim solves an ABSENT file, not a CORRUPT one. Two starters that both read the same corrupt winner used to replace it unconditionally — disagreeing on Linux, throwing EPERM on Windows. Recovery is now serialized twice over: within one process every mint runs through a promise chain, so the second starter re-reads the repaired file instead of racing the repair; across processes an `O_EXCL` lock file elects one repairman and the others adopt its token. A replacement is never unconditional.
|
|
17
|
+
- The reuse path enforces the 0600 contract too: `preparePrivateFile` tightens an existing file to owner-only (keeping owner bits, refusing a final-component symlink), so a token file left world-readable is repaired before it is accepted.
|
|
18
|
+
- The repair takes the STORE's lock. It used to take its own `O_EXCL` `.recover` file — the same shape as the #407 defect: lock state lived in a directory entry, and on Windows that entry outlives the holder whenever a third-party handle is open without `FILE_SHARE_DELETE`. An age-based steal could not rescue that case either, because the steal is itself an unlink and the same refusal applies — a viewer that hit it could never start again.
|
|
19
|
+
- The cookie is read WITHOUT `decodeURIComponent`: the value is a fixed-hex token we mint and set verbatim, and decoding junk like `osi-viewer=%` throws `URIError` on the auth path — a 500 where a malformed credential must simply be refused. The raw value cannot match, so it falls through to 401.
|
|
20
|
+
- A stale cookie from before a supported rotation is refused as one (F2): the token file is the single truth.
|
|
21
|
+
- Evidence: the review thread on issue #223.
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
# ADR 0005 — Two-phase teardown for capture passes
|
|
2
|
+
|
|
3
|
+
Status: accepted (2026-11). Code: `src/capture/runtime.ts` (`PassPhase`, `DRAIN_LIMIT_MS`).
|
|
4
|
+
|
|
5
|
+
## Decision
|
|
6
|
+
|
|
7
|
+
A capture pass records the instant `generate.text` resolves (`pastModel`). Teardown treats the two phases differently:
|
|
8
|
+
|
|
9
|
+
- A pass PARKED in `generate.text` when the host disposes must never write — the caller may remove the store the moment cleanup resolves.
|
|
10
|
+
- A pass that already HOLDS its model answer drains, bounded by `DRAIN_LIMIT_MS` (1000 ms): the answer exists, the gate is milliseconds of local work.
|
|
11
|
+
|
|
12
|
+
## Why
|
|
13
|
+
|
|
14
|
+
One disposal signal conflated the two situations and the conflation killed the feature on the CLI. Aborting past-model passes is why most real `opencode run` passes recorded `capture_cost` and no row — 9 of 12 in one sample, 6 of 12 in a controlled A/B. The abort fired on the healthy path, in the only window capture is allowed to run. Past-model passes are bounded by the drain instead, which is what the drain is for.
|
|
15
|
+
|
|
16
|
+
## Related
|
|
17
|
+
|
|
18
|
+
- Passes in flight are tracked so teardown can stop them; a disposed-during-model-answer path drops the pass rather than writing into a store the caller may be removing.
|
|
19
|
+
- Reads that are awaited (known-rows list, transcript) are hoisted BEFORE the model call so the disposal check runs before them: each awaited read is its own window into a teardown.
|
|
20
|
+
- Evidence: issues #211 and #404.
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
# ADR 0006 — Capture prompt integrity: redaction order and faithful citation
|
|
2
|
+
|
|
3
|
+
Status: accepted (2026-11). Code: `src/capture/runtime.ts`, `buildCapturePrompt`.
|
|
4
|
+
|
|
5
|
+
## Decisions
|
|
6
|
+
|
|
7
|
+
1. Redact the COMPLETE transcript, THEN apply the character budget. Cropping first can start the window INSIDE a credential: a PEM body whose BEGIN marker fell off, or a token whose prefix fell off, matches no pattern, and the prompt builder's own scrub (kept, defense in depth) cannot recognize a fragment.
|
|
8
|
+
2. Ledger failure entries are redacted AT CONSTRUCTION. Ledger args are raw tool input: a failing `bun test --token=sk-...` put the credential verbatim into the ATTESTED FAILURES block — the transcript scrub does not cover this input. Redacting at construction makes the prompt render the safe string AND the citation check compare against the same representation the model was shown.
|
|
9
|
+
3. A lesson citation must copy a COMPLETE displayed field. Substring presence cannot establish that a cited command ran: `includes("tsc")` accepted a lesson citing `tsc` when the only failure was `bun test --test-name-pattern tsc`. The list renders `cmd — arg`; membership is tested against each whole entry, its cmd, and its arg — never a fragment. The cmd-only citation the prompt's own example uses still passes.
|
|
10
|
+
4. The mined transcript is partitioned so the user's brief is labelled as the brief instead of blending into the evidence; the single un-partitioned block is the fallback when the work lines alone are too thin (a seeded transcript with no message array behind it), which keeps the old prompt shape rather than silently dropping the prose.
|
|
11
|
+
5. The user's turns are decoded from the message array rather than read back out of rendered text. Everything that vouches for "these are the user's own words" goes through that decode.
|
|
12
|
+
|
|
13
|
+
## Evidence
|
|
14
|
+
|
|
15
|
+
Review findings on issues #384 and #364; the credential-cropping window from #132.
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
# ADR 0007 — Symptom-first opening for learning and blocker rows
|
|
2
|
+
|
|
3
|
+
Status: accepted (2026-11). Code: GATE-3 region of `src/gate/gate.ts` (`symptomRuleEnabled`). Flag: `OPENCODE_MEMORY_SYMPTOM`.
|
|
4
|
+
|
|
5
|
+
## Decision
|
|
6
|
+
|
|
7
|
+
A `learning` or `blocker` row must open with the observable trigger a future session will hit: `When <symptom>: ...`. ON by default; `OPENCODE_MEMORY_SYMPTOM=off` is the escape hatch for automation holding a pre-0.28 backlog.
|
|
8
|
+
|
|
9
|
+
## Why
|
|
10
|
+
|
|
11
|
+
The measured gap is the whole argument: the same lesson surfaced 0/8 written as a session diary and ranked 1-7 written symptom-first, because the future searcher is typing the symptom, not the lesson.
|
|
12
|
+
|
|
13
|
+
## Consequences
|
|
14
|
+
|
|
15
|
+
- The backlog is repairable (`scripts/symptom-fixer.ts`); silence is not.
|
|
16
|
+
- New-vs-legacy distinction: a rewrite that carries the supersede target's content byte-identical is a metadata repair, not a new lesson. Retagging quarantined rows and metadata-only `memory_update` on a legacy row re-submit unchanged prose — blocking them would stall quarantine repair forever and make legacy rows uneditable. New prose against a `supersedesTs` is still a new lesson and still blocked.
|
|
17
|
+
- Evidence: issue #419.
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
# ADR 0008 — Availability verdicts tag rows; they never refuse them
|
|
2
|
+
|
|
3
|
+
Status: accepted (2026-11). Code: `src/capture/available.ts`.
|
|
4
|
+
|
|
5
|
+
## Decision
|
|
6
|
+
|
|
7
|
+
When the working tree already states a captured fact, the row is STORED and TAGGED (`available`), never dropped. Retrieval sorts tagged rows last within their score band.
|
|
8
|
+
|
|
9
|
+
## Why
|
|
10
|
+
|
|
11
|
+
Measured on this repo's live store (1,166 real captured rows): the original refusal rule rejected 30 rows and 29 of those were wrong — the note "OpenCode V2 (v2.0.26) does NOT run LSP servers" was refused because it merely contained the string `bun test`. A wrong match therefore costs a tag, not a fact. A silently dropped candidate leaves no trace to recover from.
|
|
12
|
+
|
|
13
|
+
## History
|
|
14
|
+
|
|
15
|
+
Four review rounds on the original rule found the same defect each time — text that was merely short or partly matched was read as already known — and each round patched one instance:
|
|
16
|
+
|
|
17
|
+
- Partial matching refuses new facts riding a restated fragment (a README rule + "; Finance confirmed the supplier rate is 1900"). Both rules used to refuse on one hit.
|
|
18
|
+
- A length cutoff dropped `Never` from `Never \`npm run deploy\`.` (cutoff 16 characters); an empty residual list was then read as proof the whole candidate was restatable. A short fragment is where a prohibition, a window or a number lives. The length test was removed; "states nothing" is the FILLER test, not a length.
|
|
19
|
+
- Command spans stripped after ONE declared gate was found erased undeclared prerequisites from the row before deciding.
|
|
20
|
+
- A bare `indexOf` matches INSIDE the opposite assertion: with `We do not use tabs for indentation.` in the README, the candidate `Use tabs for indentation.` was refused as available — the store would have held the reversal of the rule the gate had just read. A hit must begin and end on a word boundary and agree in POLARITY.
|
|
21
|
+
- The RESTRICTION list the design replaces tried to decide whether a candidate says anything NEW; an open vocabulary can never do that — any word left off the list reopens the class. The replacement is a whitelist for FILLER, the only direction a word list can safely go: a word left off it is read as a claim and the row is kept.
|
|
22
|
+
|
|
23
|
+
Temporal/conditional words and modals are deliberately absent from the reversal list: a manifest declares THAT a command exists, never when it may be run.
|
|
24
|
+
|
|
25
|
+
Evidence: issues #397 and #402.
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
# Auto-capture: what the evidence covers
|
|
2
|
+
|
|
3
|
+
Three different claims get confused constantly, so this file names them
|
|
4
|
+
separately: the event fires, the write survives, and a live store with a live
|
|
5
|
+
model completes a pass. The first two are shown. The third has never been
|
|
6
|
+
observed.
|
|
7
|
+
|
|
8
|
+
What has been established about auto-capture, by what kind of evidence,
|
|
9
|
+
and what remains unverified. The status and the arm/diagnose answer stay
|
|
10
|
+
in the README; this is the record behind them.
|
|
11
|
+
|
|
12
|
+
## What has been established
|
|
13
|
+
|
|
14
|
+
What is established, from tests and fixtures (no live store involved):
|
|
15
|
+
|
|
16
|
+
- **The trigger events are ones the host actually emits.** Capture subscribes to `session.execution.succeeded` and `session.execution.interrupted`, the two turn-end events present in a recording of the desktop service (`test/fixtures/host-events.jsonl`). `session.idle`, `session.status` and `session.execution.failed` are *declared* by the host but absent from that recording, so they deliberately do not trigger capture; `test/event-fidelity.test.ts` refuses a trigger that is only declared. An earlier revision subscribed to `session.idle` and stayed silent for days with no signal — reading a declared event as an emitted one is the failure that fixture exists to prevent.
|
|
17
|
+
- **The path runs under simulated host traffic** — unit tests hand the plugin the recorded envelopes and assert a candidate lands through the write gate, including conservation (a near-duplicate collapses at the gate instead of writing a second row): `test/capture-auto.test.ts`, `test/capture-compaction.test.ts`. No terminal e2e scenario covers the trigger, so the simulated envelope is the strongest evidence that exists — and fabricating the envelope is exactly what passed while this feature was dead.
|
|
18
|
+
- **Identity triggers have their own recording check.** `test/event-fidelity.test.ts` checks `IDENTITY_EVENT_TYPES` against the original 2.1.4 recording plus `test/fixtures/host-session-move.json`, a normalized one-frame extract from a separate 2.2.2 move capture. The extract must declare nonempty provenance and its retained envelopes must round-trip through the lockfile-pinned `@opencode/schema` 2.0.32 decoder. These checks reject missing metadata and malformed envelopes; they do not authenticate the capture. The identity replay uses the plugin subscription, but live plugin rebinding remains unverified. The recording version is distinct from the CI host pin (2.0.26).
|
|
19
|
+
|
|
20
|
+
- **Teardown stops work that is still in flight.** `generate.text` does not take the abort signal, so a capture parked mid-model-call used to wake up after the host disposed the plugin and run the whole write gate against a store its caller had already removed. Cleanup now aborts the subscription, every pass re-checks the signal after the model call and between candidates (a gate already mutating is never cut in half), and cleanup drains the tracked passes under a one-second bound — teardown never waits on the model. `test/capture-dispose-drain.test.ts` parks a capture, disposes, releases, and asserts that no row and no evidence line carries a timestamp after disposal (#211).
|
|
21
|
+
|
|
22
|
+
- **The trigger is live on a real host, and the write now survives it.** An end-to-end scenario drives `opencode run` against a real turn with a scripted provider (`e2e/capture.test.ts`): the turn-end event fires and a capture pass starts, 12 of 12 runs. It used to reach the write gate in only some of them — 3 of 12 in one sample, 6 of 12 in a controlled A/B against the same script, 12 of 12 in two samples after the fix. `opencode run` disposes the plugin as the turn ends, and `captureCleanup` aborted every in-flight pass before its gate ran: the #211 contract, correct for the teardown it was written for and fatal here, because nothing is being torn down and the process simply exits. Cleanup now distinguishes the two cases — a pass still parked in the model call is abandoned, a pass that already holds its answer is drained, because its remaining work is local and milliseconds. All of #211's disposal assertions still pass unchanged. Fixed on this branch, #404.
|
|
23
|
+
|
|
24
|
+
- **The availability policy is measured against its alternatives, and against its own measuring stick.** `bun run bench:availability` (`bench/availability-results.md`) runs one capture pass over a 197-row store five times — no check, tag (as shipped), drop-at-read (the P3 preview), drop-hardened, and the original rule replayed from the pinned `362655c` module — with the byte budget swept over five sizes and the background resampled at 0/30/90/180 rows, because a claim measured at one budget or one store size is a claim about that budget. Tagging keeps all 10 new transport facts and retrieves 14 of 14 retrievable queries at every budget and every store size, where the original rule keeps 6 of 10 and retrieves 7 at every budget: that rule deleted four of ten new facts on a command mention alone, and a deleted fact cannot be retrieved. The ceiling is stated next to every recall figure and measured on the exact rows the arms retrieve: 14 of the 21 curated transport queries retrieve their own gold when that gold is the ONLY row in the store, so the tag arm's 14 is the achievable maximum and 9/21 was never 43% recall. The counterfactual is printed beside it — strip the keywords the capture reply carries and the ceiling falls to 9/21, because five of these pairs are retrievable only through the keyword list. A 25-case bank of every adversarial verdict this matcher has been found guilty of is re-decided on every run, one repo per case, and asserted in `bun test` because CI runs no bench. Writing those controls found two defects in the bench itself — verdicts keyed on `ts`, which is not unique when a pass writes rows in one millisecond, and a byte column summed across 21 queries and labelled per-block — and the corrected numbers are in the file. The report also states what it cannot measure: the check marks 6 of 16 rows a pass writes and 0 of 180 background rows, and that 0 is a fixture artefact rather than a base rate, because no seeded row quotes the tracked tree. It also tests the tag's justification directly: empty the tracked text and all 6 verdicts disappear, which is the property a read-time policy would keep and a delete would not.
|
|
25
|
+
|
|
26
|
+
## What has not been established
|
|
27
|
+
|
|
28
|
+
- That a live host with a live model completes a capture end to end. The event and the pass are no longer in doubt — `e2e/capture.test.ts` shows a real `opencode run` turn firing a real pass — but no `auto_capture_*` line and no `capture_lag` line exists anywhere in the maintainer's evidence history (checked 2026-10-26 through 2026-10-29), and #404 found the mechanism by which a CLI session would produce none even when everything else works — the fix is on this branch, but no live store has been observed completing a pass yet. A live trial armed on 2026-10-26 was stood down on 2026-10-29 without ever firing, so it answered nothing.
|
|
29
|
+
- 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".
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
# Contradiction authority: the code check and its limits
|
|
2
|
+
|
|
3
|
+
You say the retry limit has to be `5`; the code says `3`. Before the plugin
|
|
4
|
+
takes sides it has to be sure it is reading a real declaration, so the check is
|
|
5
|
+
deliberately narrow — and what it refuses to decide is the more useful half of
|
|
6
|
+
this document.
|
|
7
|
+
|
|
8
|
+
The verdict table stays in the README.
|
|
9
|
+
|
|
10
|
+
## What the check will read
|
|
11
|
+
|
|
12
|
+
One thing: a unique top-level `const` with a literal value. Comments, string
|
|
13
|
+
examples, local declarations and computed expressions cannot establish an
|
|
14
|
+
authority verdict. The scan is bounded to 300 source files, 256 KiB per file
|
|
15
|
+
and depth 3, preferring `src/`, and it does not follow source links or resolve
|
|
16
|
+
imports.
|
|
17
|
+
|
|
18
|
+
Anything it cannot settle — an ambiguous declaration, unreadable or invalid
|
|
19
|
+
source, an exhausted budget, a claim outside its reach — keeps the plain
|
|
20
|
+
guidance and its staleness caveat and emits no verdict. The JavaScript/TypeScript
|
|
21
|
+
parser loads only when a row needs a code check; an explicit opt-out never
|
|
22
|
+
loads it. Use attribution keeps the stored row's identity and prose while
|
|
23
|
+
coverage counts only references present in the delivered text.
|
|
24
|
+
|
|
25
|
+
## The residual, accepted
|
|
26
|
+
|
|
27
|
+
A user-stated **wrong spec** still classifies as `spec`, and its verdict
|
|
28
|
+
follows that stated requirement even if it breaks the current tests. The plugin
|
|
29
|
+
does not infer a hidden test suite's authority and does not silently override
|
|
30
|
+
the user's requirement. Asking an oracle or inventing an extra authority class
|
|
31
|
+
is outside this contract.
|
|
32
|
+
|
|
33
|
+
Classification can also simply be wrong: a code comparison verifies a value
|
|
34
|
+
mismatch, not the user's intent.
|
|
35
|
+
|
|
36
|
+
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.
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
# Development internals
|
|
2
|
+
|
|
3
|
+
What the local commands really run, what the smoke suite boots, and how the
|
|
4
|
+
published npm surface is decided. The commands themselves and the BDD-first
|
|
5
|
+
rule stay in the README.
|
|
6
|
+
|
|
7
|
+
## Local command to CI job
|
|
8
|
+
|
|
9
|
+
| Local command | Where it runs in CI | Gates a merge |
|
|
10
|
+
| --- | --- | --- |
|
|
11
|
+
| `bun run typecheck` | inside the job named `lint` | yes, under that name |
|
|
12
|
+
| `bun run lint` | `lint` | yes |
|
|
13
|
+
| `bun run test` | `test`, re-run in `test-windows` | `test` yes; `test-windows` reports only |
|
|
14
|
+
| `bun run test:e2e` | `smoke` | yes |
|
|
15
|
+
|
|
16
|
+
`tsc --noEmit` has no check of its own in CI — it runs inside `lint`, so a green `lint` silently implies a green typecheck.
|
|
17
|
+
|
|
18
|
+
`bun run lint` checks lint rules and TypeScript/TSX formatting, and CI calls the same command. Lint warnings stay advisory; formatting differences fail the check. Markdown commands, prose, JSON data and historical benchmark records are outside the formatter's scope.
|
|
19
|
+
|
|
20
|
+
The test scripts run files across at most four worker processes with Bun's file isolation. To reproduce an order-dependent failure the way it would appear in one shared process, run `bun test ./test/` or `bun test ./e2e/ --timeout 240000` directly.
|
|
21
|
+
|
|
22
|
+
## What the smoke suite boots
|
|
23
|
+
|
|
24
|
+
`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.
|
|
25
|
+
|
|
26
|
+
## The published surface is `package.json`
|
|
27
|
+
|
|
28
|
+
`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.
|
package/docs/flags.md
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
# Research flags
|
|
2
|
+
|
|
3
|
+
The three flags that encode a measured finding rather than a preference:
|
|
4
|
+
what each one enforces, the evidence behind it, and what an invalid value
|
|
5
|
+
does. The README's table gives the default and the effect.
|
|
6
|
+
|
|
7
|
+
`OPENCODE_MEMORY_SYMPTOM` is the clearest case. A lesson saved as "in this
|
|
8
|
+
session we fixed the flaky test" shares no words with the query a future
|
|
9
|
+
session types, so it gets filed and never found: measured, 0 of 8 diary-shaped
|
|
10
|
+
rows surfaced, against ranks 1–7 when the same lesson opens with the symptom.
|
|
11
|
+
The flag therefore refuses the diary form at the write gate instead of storing
|
|
12
|
+
something unrecoverable.
|
|
13
|
+
|
|
14
|
+
## Flag behaviour
|
|
15
|
+
|
|
16
|
+
| Variable | Full behaviour |
|
|
17
|
+
| --- | --- |
|
|
18
|
+
| `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
|
+
| `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 — 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. |
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
# Import, quarantine and the viewer's edit path
|
|
2
|
+
|
|
3
|
+
A quarantined row is a spam-folder row, not a deleted one: it stays in the
|
|
4
|
+
store where you can read it, and is withheld from everything the model reads.
|
|
5
|
+
|
|
6
|
+
What the prose screen catches and misses, how an existing store gets
|
|
7
|
+
re-tagged, what releasing quarantine does, and which writes it does not
|
|
8
|
+
cover. The README keeps the export/import contract and the tally.
|
|
9
|
+
|
|
10
|
+
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
|
+
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.
|
|
13
|
+
|
|
14
|
+
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.
|
|
15
|
+
|
|
16
|
+
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.
|
|
17
|
+
|
|
18
|
+
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).
|
|
19
|
+
|
|
20
|
+
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.
|
|
21
|
+
|
|
22
|
+
Existing stores are not rescanned. A byte-identical import that collapses into an existing row does not retroactively tag that row. Export preserves quarantined rows and their tags to avoid data loss; an exported released row can be quarantined again when re-import promotes it on another machine.
|
|
23
|
+
|
|
24
|
+
## The file format, and what an import will believe
|
|
25
|
+
|
|
26
|
+
A header line (`{_export, version, exportedAt, count}`) followed by one JSON object per line (`{ts,type,scope,content,status,tags,issue}`), active rows only.
|
|
27
|
+
|
|
28
|
+
An open row is exempt from reference grounding, so that status is honored only for files carrying an export header — a hand-written file without one imports such rows as settled. 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.
|
|
29
|
+
|
|
30
|
+
## Keeping a path inside the store
|
|
31
|
+
|
|
32
|
+
Both tools are model-facing, so a path is treated as untrusted input rather than as permission. An export cannot write to `~/.gitconfig` or anywhere else outside the store, and an import cannot read outside it. Symbolic links are resolved before the check — including an `exports/` directory that is itself a link — so a link cannot carry a request out of the store. Exports are written `0600` and opened `O_NOFOLLOW` (both POSIX; on Windows the check before the write is the only guard).
|
|
33
|
+
|
|
34
|
+
The default name is `<memory-root>/exports/<timestamp>-<unique>.jsonl`, created exclusively, so two exports in the same second never replace each other's artifact.
|
|
35
|
+
|
|
36
|
+
Two limits no path check can close. A hard link planted inside `exports/` shares an inode with its target, so writing through it writes the target. And the check covers the final component more tightly than the intermediate path components, leaving a narrow window there. Both are stated rather than fixed because closing them means giving up the feature.
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
# Injection epochs and their measured cost
|
|
2
|
+
|
|
3
|
+
Prompt caching turns a boring question into an expensive one: how often do the
|
|
4
|
+
bytes in front of the model actually change? The plugin's answer is to freeze
|
|
5
|
+
the memory section and re-render only when the frozen bytes would genuinely
|
|
6
|
+
differ — the same reason you cache an HTTP response by its body rather than by
|
|
7
|
+
how many times the database was touched.
|
|
8
|
+
|
|
9
|
+
Every figure here is bytes on a synthetic workload: not tokens, not a bill.
|
|
10
|
+
The epoch mechanism, the deterministic byte workload behind the injection
|
|
11
|
+
claim, and a provider audit reported by its author.
|
|
12
|
+
|
|
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
|
+
- **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` still reaches them on the pull path.
|
|
16
|
+
- **Identifiers split.** `getUserAccount`, `get_user_account`, `get-user-account` and `get.user.account` are one concept to the matcher rather than four, and a memory citing `src/recall/score.ts` answers a session that typed the path ([#409](https://github.com/abogartz/opencode-self-improvement/issues/409)). Measured on the published eval: aggregate recall unchanged, wrong-memory-first at the top falls 6% → 5%. Replayed over 1,091 logged recall queries through this scorer against the live store: 92.3% of top-5 sets are identical and 97.5% keep their top row.
|
|
17
|
+
- **User-stated guidance rides ahead of relevance.** A row auto-capture tagged `user-guided` — something you said outright, like "the correct sales tax rate is 8.25%" — rides the block ahead of the lexical picks: newest-first, at most three, and `injectBudget` still bounds the whole block (`test/hint-channel.test.ts`). The channel exists because ranking cannot bridge vocabulary: a prompt about "the injected bug" shares no word with a row stating a tax rate, and the shipped matcher scored it zero ([#334](https://github.com/abogartz/opencode-self-improvement/issues/334)). `memory_recall` and the contextual pull stay query-driven — the channel changes only what rides the prompt. Because always-riding priority is a poisoning amplifier, the tag is minted by auto-capture alone: `memory_remember`, `memory_update` replacements and JSONL imports strip it, along with the contradiction fields ([#342](https://github.com/abogartz/opencode-self-improvement/issues/342), `test/guidance-provenance.test.ts`).
|
|
18
|
+
- **The block re-scores at every user turn.** An epoch is not frozen at the first request: a later prompt re-scores, and the epoch MOVES only when the rendered bytes move — a prompt change that selects the same rows in the same order costs no cache bust ([#340](https://github.com/abogartz/opencode-self-improvement/issues/340), `test/epoch.test.ts`). Order is part of those bytes on this build: the lexical picks render in score order, so a prompt that keeps the same rows and re-ranks them moves the bytes and pays the bust. Canonical render order, which removes that churn, is still open ([#388](https://github.com/abogartz/opencode-self-improvement/issues/388), [#396](https://github.com/abogartz/opencode-self-improvement/pull/396)).
|
|
19
|
+
- **Hard budgets.** Relevance block and each pull are capped at `injectBudget` characters, the frontier at `frontierBudget`, trimmed at whole-memory boundaries.
|
|
20
|
+
- **Nothing volatile on the cached prefix.** The standing digest carries no row count and no latest timestamp. Both used to ride the very front of the system prompt, so every saved memory rewrote the prefix and made the next request re-bill the whole conversation; the exact numbers now live where they are free — the footer badge, `/memory`, `memory_status`, the viewer.
|
|
21
|
+
- **Evidence is never injected**, and the standing system digest is two lines.
|
|
22
|
+
- **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.
|
|
23
|
+
- **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. That reading is the misleading one — auto-capture is on by default, so the call happens on installs that never set an option. 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.
|
|
24
|
+
|
|
25
|
+
**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:
|
|
26
|
+
|
|
27
|
+
| Policy | Recomputes | Epochs whose bytes moved | Injected chars (20 turns) | Avg/turn | Worst section |
|
|
28
|
+
| --- | ---: | ---: | ---: | ---: | ---: |
|
|
29
|
+
| A — recompute per prompt, uncapped (naive) | 20 | 19 | 60996 | 3049.8 | 3404 |
|
|
30
|
+
| B — block frozen on store fingerprint, digest rebuilt per turn | 4 | 3 | 55478 | 2773.9 | 2867 |
|
|
31
|
+
| C — section frozen on rendered bytes | 4 | 3 | 55258 | 2762.9 | 2856 |
|
|
32
|
+
| D — C + riding bytes (shipped) | 1 | 0 | 53500 | 2675.0 | 2675 |
|
|
33
|
+
|
|
34
|
+
The invalidation counter counts **byte-moving recomputes**: epochs whose memory-section bytes differ from the previous epoch. It is not a provider cache-miss or re-prefill count, and no status surface claims it is. All three synthetic writes change B and C's bytes; D records no change for these self-writes. Corrections, removals and writes by another session can still move D's bytes, as pinned by `test/epoch.test.ts`. The workload re-scores only when the store fingerprint moves, so its 20 prompts never re-rank one shared set — D's `0` is not evidence about the same-set re-ranking above. D also injects 12.3% fewer **characters** than the naive policy, measured over the whole section — bytes on a deterministic workload, not tokens and not a provider bill. Reproduce this deterministic byte workload:
|
|
35
|
+
|
|
36
|
+
```sh
|
|
37
|
+
bun run bench
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
**Author-reported provider audit**, not a new measurement here, and **input tokens only** (on that provider `input` is the uncached remainder, so this is not a total and not a saving): [#346's six-turn local-seat audit](https://github.com/abogartz/opencode-self-improvement/issues/346#issuecomment-6714172764) compared `ee769ef` with frozen `29268ef`. The changed build used 2,065 additional input tokens over six turns (~344/turn), with one 3,257-input-token spike, and 94.4% cache share versus 97.5%. The block rode late in the system prompt, after a stable prefix; a byte-moving epoch did not re-bill the whole conversation. This run included two guided rows, so it does not isolate prompt rescoring from the hint channel or establish a bound for every provider. The status counter remains a byte-change count; provider receipts report actual cache reuse separately.
|
package/docs/options.md
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
# Options and environment variables
|
|
2
|
+
|
|
3
|
+
Every knob, in one place. The README keeps the ones you are likely to set; this
|
|
4
|
+
file is the complete reference, including what an invalid value does.
|
|
5
|
+
|
|
6
|
+
## Plugin options
|
|
7
|
+
|
|
8
|
+
Set them in the object form of the plugin entry in `opencode.json(c)`:
|
|
9
|
+
|
|
10
|
+
```json
|
|
11
|
+
{
|
|
12
|
+
"plugins": [{ "package": "opencode-self-improvement", "options": { "injectBudget": 1200, "frontierBudget": 3600 } }]
|
|
13
|
+
}
|
|
14
|
+
```
|
|
15
|
+
|
|
16
|
+
| Option | Default | What it does |
|
|
17
|
+
| --- | --- | --- |
|
|
18
|
+
| `injectBudget` | `1200` | Character cap on the injected relevance block and each contextual pull; trimmed at whole-memory boundaries. Env fallback: `OPENCODE_MEMORY_INJECT_BUDGET`. |
|
|
19
|
+
| `frontierBudget` | `3 × injectBudget` | Character cap on the session-start open-threads block. A thread longer than the budget is not injected and is reported as omitted. Env fallback: `OPENCODE_MEMORY_FRONTIER_BUDGET`. |
|
|
20
|
+
| `contradictionSurface` | `true` | Experimental: compare guided constant claims with bounded source reads and render a class-specific CONFLICT verdict. Set `false` to skip code checks and retain plain guidance. See [docs/contradiction-authority.md](contradiction-authority.md). |
|
|
21
|
+
| `notifyBlocked` | `true` | Terminal (TUI) only: toast when a write gate blocks a write. Blocks are always in `memory_evidence` either way. |
|
|
22
|
+
| `autoCapture` | `true` | Master switch for auto-capture. On, so a plain install mines turn ends and compactions. Set `false` for no capture model call at all. |
|
|
23
|
+
| `captureModel` | inherits | `"provider/id"` model used for auto-capture. Unset means the model the session is using, else the host default. An explicit value that is not `provider/id` disables capture with a startup warning rather than substituting a model. |
|
|
24
|
+
| `captureMax` | `3` | Maximum candidates proposed per capture pass. |
|
|
25
|
+
| `captureOnCompact` | `true` | When auto-capture is armed, 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 `false` does nothing and reports `switch_mismatch` on the `plugin_load` line. |
|
|
26
|
+
| `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. |
|
|
27
|
+
|
|
28
|
+
## Environment variables
|
|
29
|
+
|
|
30
|
+
| Variable | Purpose |
|
|
31
|
+
| --- | --- |
|
|
32
|
+
| `OPENCODE_MEMORY_DIR` | Store location (default `~/.config/opencode/memory`). |
|
|
33
|
+
| `OPENCODE_MEMORY_ALLOW_OUTSIDE_PATHS` | Operator-only. When truthy, `memory_export`/`memory_import` accept paths anywhere on disk instead of confining themselves to the store. Off by default. It is read from the plugin process's own environment, so a model cannot grant it to itself through a tool argument. See [docs/import-quarantine.md](import-quarantine.md). |
|
|
34
|
+
| `OPENCODE_MEMORY_INJECT_BUDGET` | Fallback for `injectBudget`. |
|
|
35
|
+
| `OPENCODE_MEMORY_FRONTIER_BUDGET` | Fallback for `frontierBudget`. |
|
|
36
|
+
| `OPENCODE_COMMANDS_DIR` | Where the plugin mirrors its slash commands (default `~/.config/opencode/commands`). |
|
|
37
|
+
| `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. |
|
|
38
|
+
| `OPENCODE_VIEWER_PORT` | Admin editor port (default `8787`). |
|
|
39
|
+
| `OPENCODE_VIEWER_ALLOWED_HOSTS` | Comma-separated hosts beyond loopback. |
|
|
40
|
+
|
|
41
|
+
`OPENCODE_MEMORY_DEDUP`, `OPENCODE_MEMORY_SYMPTOM` and `OPENCODE_MEMORY_QUERY_GATE` are documented separately in [docs/flags.md](flags.md): they switch behaviour that a measurement decided, so the evidence behind each one matters more than the default.
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
# Pre-release ritual: mutation sweep and artifact policy
|
|
2
|
+
|
|
3
|
+
A fire drill for the test suite: break one claimed invariant on purpose and
|
|
4
|
+
see whether anything notices. A mutant that no test kills is not a scandal —
|
|
5
|
+
it is a list of what the suite has been claiming without pinning.
|
|
6
|
+
|
|
7
|
+
What `scripts/test-sweep.ts` measures, when a person runs it, and which
|
|
8
|
+
benchmark artifacts stay out of git.
|
|
9
|
+
|
|
10
|
+
```sh
|
|
11
|
+
bun run sweep:test
|
|
12
|
+
```
|
|
13
|
+
|
|
14
|
+
`bun run sweep:test` (`scripts/test-sweep.ts`) audits the test suite rather than testing the plugin. Each mutant breaks exactly one claimed invariant in a detached `git worktree` of HEAD, runs the `test/` suite (unit + scenario) against that mutated tree, and reports whether the suite noticed. A mutant no test kills is an unpinned invariant: the test titles may claim coverage, but nothing died with the invariant. The clean tree is measured first and its failing tests are subtracted from every mutant run, so only new failures count as a kill and a flake never masquerades as one. Mutants are applied only to scratch worktrees beside the checkout, never to the working tree under your feet.
|
|
15
|
+
|
|
16
|
+
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.
|
|
17
|
+
|
|
18
|
+
Run it when you want to know whether the suite still has teeth — after changing tests or coverage, or as a pre-release gate with `bun scripts/test-sweep.ts --fail-on-survivors`, which exits 4 when anything survives. Two lighter checks come first: `bun scripts/test-sweep.ts --validate` confirms every mutation pattern still lands on exactly one source site without running the suite, and `bun scripts/test-sweep.ts --selftest` plants a mutation in a trivially-tested pure function and fails unless the suite kills it — proof the instrument itself can go red.
|
|
19
|
+
|
|
20
|
+
**Pre-release ritual (decided 2026-11-04, #72):** before pushing a release commit, a human runs `--validate`, then `--selftest`, then `--fail-on-survivors`, and records the mutation score and the survivor list in `bench/RESULTS.md` beside the published evidence. Cadence is pre-release only, run by a person: the sweep is a full suite per mutant and never belongs in CI, where it would cost more than it informs. Survivors become entries on the unpinned-invariant list, not red checks.
|
|
21
|
+
|
|
22
|
+
### Bench artifacts stay out of git
|
|
23
|
+
|
|
24
|
+
Raw sweep output is regenerable measurement data, and it was the largest tracked content in the repository. It is not committed (#232). A clone carries the published summaries — `bench/RESULTS.md`, `bench/recall-results.md`, `bench/test-sweep-results.md`, `bench/capture-trigger-results.md` — and the inputs those summaries are rebuilt from. History is not rewritten: the old blobs stay in earlier revisions, so this shrinks new checkouts, not the archive.
|
|
25
|
+
|
|
26
|
+
| Artifact | How to get it back |
|
|
27
|
+
| --- | --- |
|
|
28
|
+
| `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. |
|
|
29
|
+
| A mutation sweep log | `bun scripts/test-sweep.ts --log=<path>`. |
|
|
30
|
+
|
|
31
|
+
A script that needs a missing artifact names the file and the command that produces it instead of throwing a stack trace.
|
|
32
|
+
|
|
33
|
+
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`).
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
# Recall quality: what the keyword matcher gives up
|
|
2
|
+
|
|
3
|
+
A keyword matcher finds a memory when the words overlap. That is its whole
|
|
4
|
+
trick, and its whole weakness: "how we deploy" and "ship to staging" are the
|
|
5
|
+
same fact with no word in common. This file is what that costs, measured, and
|
|
6
|
+
what you can do about it at write time.
|
|
7
|
+
|
|
8
|
+
The headline table stays in the README. Full methodology and all store sizes:
|
|
9
|
+
`bench/recall-results.md`, reproduced with `bun run bench:recall`.
|
|
10
|
+
|
|
11
|
+
## Write-time keywords are the answer to paraphrase
|
|
12
|
+
|
|
13
|
+
`memory_remember` asks each row for 3–5 `kw` aliases: other names for the same
|
|
14
|
+
thing, other verb forms, the literal command. Keywords are indexed and never
|
|
15
|
+
rendered into the prompt, so they cost nothing to store and nothing to inject.
|
|
16
|
+
|
|
17
|
+
**Bench** — the same matcher over the same store, with the only changed
|
|
18
|
+
variable being the index:
|
|
19
|
+
|
|
20
|
+
- strict (zero shared words) R@1 0% → 26%
|
|
21
|
+
- near (one overlap) R@1 28% → 67%
|
|
22
|
+
|
|
23
|
+
A permutation control — every row given someone else's aliases — scores
|
|
24
|
+
29%/35%, so the gain is meaning rather than extra tokens. Auto-capture asks for
|
|
25
|
+
the same list, so these numbers are measured through the tool path rather than
|
|
26
|
+
through capture. The limit is narrowed, not removed.
|
|
27
|
+
|
|
28
|
+
## Abstaining is a feature
|
|
29
|
+
|
|
30
|
+
Free-text prompts that share one concept with a memory abstain rather than
|
|
31
|
+
force a guess. Wrong top-memory fell to 6%. The cost is silence in cases where
|
|
32
|
+
a lucky guess would have been right; `memory_recall` still covers them when you
|
|
33
|
+
ask on purpose.
|
|
34
|
+
|
|
35
|
+
## Why the default window is 5 rows
|
|
36
|
+
|
|
37
|
+
A live audit joined 1,090 recall events to their session transcripts. A
|
|
38
|
+
returned row at rank 1 shows up in a later tool call at 3.4x the rate of a
|
|
39
|
+
random store row, ranks 2–3 at 2.4x, and ranks 11–20 at 1.16x — noise against a
|
|
40
|
+
0.129 null. The old default returned 17.7 rows per call, so most of the window
|
|
41
|
+
was context nobody read.
|
|
42
|
+
|
|
43
|
+
At limit 5, recall@1 and recall@3 are unchanged, precision rises 4.1% → 13.1%,
|
|
44
|
+
and 74% of the returned characters disappear. Every gold row the cut dropped sat
|
|
45
|
+
at ranks 6–20. Pass `limit` for a wider sweep ([#409](https://github.com/abogartz/opencode-self-improvement/issues/409)).
|
|
46
|
+
|
|
47
|
+
## Caveats on the eval
|
|
48
|
+
|
|
49
|
+
The dataset is synthetic — 52 memories and 105 queries about a fictional
|
|
50
|
+
project — its class mix is deliberately adversarial, and scoring is
|
|
51
|
+
single-gold. Read the numbers as a comparison between matchers on one fixed
|
|
52
|
+
set, not as a prediction about your repository.
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
# Repo scoping: identity, visibility and write refusal
|
|
2
|
+
|
|
3
|
+
Every row carries a label saying which repository wrote it. The label is
|
|
4
|
+
checked on the way in as well as the way out, and the two directions are not
|
|
5
|
+
symmetric: reading one extra project's memories is a nuisance, while writing
|
|
6
|
+
your private note into the wrong project is damage. So reads are permissive and
|
|
7
|
+
writes are strict.
|
|
8
|
+
|
|
9
|
+
The README states the rule; this is the boundary detail.
|
|
10
|
+
|
|
11
|
+
## Identity
|
|
12
|
+
|
|
13
|
+
Legacy whole-path-lowercased hashes accompanied by `repoPath` are matched to that directory (including real aliases), so a distinct case-sensitive sibling cannot inherit its memories or evidence. Remote-derived identities still share across clones. Stamps without `repoPath` retain key-only matching; their historical identity source cannot be recovered from the key alone.
|
|
14
|
+
|
|
15
|
+
## Who sees what
|
|
16
|
+
|
|
17
|
+
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".
|
|
18
|
+
|
|
19
|
+
## Why an unresolved session cannot write
|
|
20
|
+
|
|
21
|
+
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.
|
|
22
|
+
|
|
23
|
+
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. Preferences that should follow you everywhere go in with `memory_remember global: true`. Rows written before scoping existed are global. Upgrading changes nothing.
|
|
24
|
+
|
|
25
|
+
`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.
|
|
26
|
+
|
|
27
|
+
## Evidence attribution
|
|
28
|
+
|
|
29
|
+
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.
|
|
30
|
+
|
|
31
|
+
Gate-authored evidence and its init/capture lifecycle records capture attribution at operation entry: if a session moves repositories while the operation runs, its audit lines remain in the starting repository's partition and can be read with `memory_evidence` from a session bound there. Init start/complete/skip, capture outcomes/refusals, and capture lag share that captured owner. A captured named session with no resolved repository keeps a session-private `sid` label even on lifecycle records that suppress call metadata; otherwise an unstamped line would appear global.
|
|
32
|
+
|
|
33
|
+
## The viewer
|
|
34
|
+
|
|
35
|
+
The viewer is an admin surface over every repo: it edits and restores a row with its own repo stamp, and the viewer's missing session scope never decides a row's visibility. Viewer audit attribution and cancellation of in-flight capture are separate boundaries.
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
# Store concurrency, publication and permissions
|
|
2
|
+
|
|
3
|
+
Replacing a store file while other sessions are reading it is the whole
|
|
4
|
+
problem. The answer is a book swap, not a page rewrite: the writer builds the
|
|
5
|
+
complete new file, then swaps it in under a lock. A reader therefore sees the
|
|
6
|
+
old file or the new one, never a half-written record.
|
|
7
|
+
|
|
8
|
+
How a store file is replaced, what the lock covers, and what the plugin
|
|
9
|
+
does and does not do about permissions. The README states the user-visible
|
|
10
|
+
rules and links here.
|
|
11
|
+
|
|
12
|
+
Daily memory writes publish a complete replacement file under that lock, so concurrent readers see the previous or new complete file rather than a partially appended record. Appending a row therefore rewrites the day file (in addition to the existing timestamp-uniqueness read). On Windows, a reader handle that prevents replacement can make the write refuse after the replacement retry window; the previous bytes remain intact and the caller can retry once the handle closes. This publication rule applies to daily memory files, not append-only evidence, use, rejection, or audit logs; [#198](https://github.com/abogartz/opencode-self-improvement/issues/198) tracks the broader read boundary.
|
|
13
|
+
|
|
14
|
+
The lock covers one **file**, not the store directory. Two sessions writing different days of the same store therefore do not wait on each other. A directory-wide lock was tried first and lost writes: a whole-file publish waits up to two seconds on Windows for a reader to let go of the destination, and with one lock for the directory that wait stops every other writer in the store. Per file it stops only the writers of that file, which is what the publish's safety check needs. The cost is a database plus its write-ahead log per locked file; they exist only while a connection is open, and the number of open connections is bounded. A writer never holds two file locks at once, and batches that must serialize a whole read-then-supersede sequence (`memory_update`, `memory_merge_review`) take a separate named lock (`.store-batch.update-order.sqlite`), always before the file locks their steps take — so a batch never holds a file lock across its whole run.
|
|
15
|
+
|
|
16
|
+
Two unsupported placements. The write-ahead log needs mmap'd shared memory, which SQLite does not provide on network filesystems, so a memory root on SMB, NFS or a OneDrive-mounted folder is **not supported**: writes there can report a disk I/O error rather than serialise. Configure `OPENCODE_MEMORY_DIR` on local disk. And during the update that introduced this lock, a session still running the previous release honours `<date>.logfmt.lock` while an updated session honours the SQLite lock, so those two do not exclude each other until every running session has restarted.
|
|
17
|
+
|
|
18
|
+
On POSIX systems, new store directories use owner-only `0700` permissions and new files use `0600` (subject to a more restrictive umask) — including temporary replacements, snapshots, locks, status files and append-only logs. Accessing an existing store removes group/other permissions from its root, and tightens directories and files as they are written. Old descendants are not migrated recursively: a tightened root already stops other users from reaching them.
|
|
19
|
+
|
|
20
|
+
Three limits on that guarantee, stated plainly because they are privacy limits.
|
|
21
|
+
|
|
22
|
+
1. If chmod reports `EPERM`, `EROFS`, `EOPNOTSUPP` or `ENOSYS` — an immutable root, a foreign-owned root, or a mount without chmod support — reads stay available under the existing permissions, so owner-only traversal is **not** guaranteed. Fix ownership, mount support or permissions outside the plugin when that guarantee is required.
|
|
23
|
+
2. The modes do not revoke handles that are already open, and they do not protect copies or hard links made outside the private root.
|
|
24
|
+
3. On Windows the plugin changes no ACLs; privacy there depends entirely on the directory's existing ACL.
|
|
25
|
+
|
|
26
|
+
A store root that is itself a symlink is refused; configure its real directory instead. Ancestors outside the store are left as they are.
|