opencode-self-improvement 0.31.0 → 0.32.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 +31 -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 +44 -3
- package/docs/write-latency.md +25 -0
- package/package.json +1 -1
- package/src/capture/runtime.ts +1 -1
- package/src/capture/triggers.ts +16 -1
- package/src/consolidate/propose.ts +1 -1
- package/src/core/config/paths.ts +1 -1
- package/src/core/state.ts +11 -0
- 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 +18 -9
- 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/payload.ts +17 -0
- package/src/status/report.ts +17 -0
- package/src/status/store-summary.ts +81 -13
- 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/{hits → telemetry}/ledger.ts +221 -0
- 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 +21 -2
- package/src/tools/update.ts +1 -1
- package/src/viewer/mutate.ts +1 -1
- /package/src/{command → init}/ensure.ts +0 -0
- /package/src/{evidence → telemetry}/record.ts +0 -0
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,21 @@ 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
|
+
outcome-linked 7 rides over 3 rows: 3 clean row/turns, 2 failed row/turns (store-wide)
|
|
19
|
+
1 candidate at ≥5 rides with no clean turn — best-effort counts are floors since 2026-11-01T10:00:00.000Z; correlation on the ride's own turn, reported, never acted on
|
|
20
|
+
outcome writes dropped for this store by this process: 0
|
|
21
|
+
2026-10-31T14:05:00.000Z used=5 clean=0 fail_after=2 unknown=2 (eviction candidate)
|
|
22
|
+
24.1 KB total · 604 B per row · 1.3 rows/day (30d)
|
|
23
|
+
```
|
|
24
|
+
|
|
10
25
|
## What counts as use
|
|
11
26
|
|
|
12
27
|
Credit comes from three distinct sources, because "the model asked" and "the
|
|
@@ -16,13 +31,35 @@ harness offered" are different facts:
|
|
|
16
31
|
2. `memory_recall` returned it;
|
|
17
32
|
3. a grep/read pull appended it.
|
|
18
33
|
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
row's standing.
|
|
34
|
+
The writer throttles identical sets of retrieved rows to one successful line
|
|
35
|
+
per session and source per hour. A row can appear in multiple sets.
|
|
22
36
|
|
|
23
37
|
**No prompt content is stored.** The ledger keeps a scan-truncated string from
|
|
24
38
|
the *memory* side, never your message.
|
|
25
39
|
|
|
40
|
+
## What happens after retrieval
|
|
41
|
+
|
|
42
|
+
Each `memory_used` line records the turn number and turn key when available.
|
|
43
|
+
Each classified gate check appends a separate `ev=gate_outcome` line with
|
|
44
|
+
the session, turn, key, timestamp, command family and `outcome=clean|fail`.
|
|
45
|
+
The chat report aggregates those observations on read. On each row, `used`
|
|
46
|
+
counts recorded rides. `clean` and `fail_after` count distinct turns with
|
|
47
|
+
a classified gate after a ride. A later failure takes precedence over passes.
|
|
48
|
+
`unknown` counts rides without a usable later gate on that turn, including
|
|
49
|
+
legacy rides without a turn key when no compatible outcome exists.
|
|
50
|
+
Multiple rides on one turn can therefore contribute one measured turn.
|
|
51
|
+
|
|
52
|
+
The ledger drops old lines at rotation and can miss writes under contention.
|
|
53
|
+
The counts describe the retained observations. The dropped-outcome counter
|
|
54
|
+
covers failed writes in the reporting process for this store. It resets on
|
|
55
|
+
restart and excludes failures in other processes. A zero cannot establish
|
|
56
|
+
complete history.
|
|
57
|
+
|
|
58
|
+
A row becomes an eviction candidate after five recorded rides if at least
|
|
59
|
+
one ride has a measured outcome and none has a clean turn. A subsequent
|
|
60
|
+
failure can be unrelated to the row. Inspect the row and its use before
|
|
61
|
+
deciding whether to retire it. The report makes no store changes.
|
|
62
|
+
|
|
26
63
|
## What use is allowed to do
|
|
27
64
|
|
|
28
65
|
Reinforcement is a tie-break only (`useBoost ≤ 1.0`): a recently used row wins a
|
|
@@ -39,6 +76,10 @@ Aggregate STORE counts are machine-wide by decision (#213 B): they count every
|
|
|
39
76
|
repository's rows in the shared store on this machine, never just the reading
|
|
40
77
|
session's repository. The numbers describe the store, not your slice of it.
|
|
41
78
|
|
|
79
|
+
Outcome totals and candidate counts also cover every repository. The chat report
|
|
80
|
+
shows up to 20 reader-visible row IDs, prioritizing candidates. The omitted
|
|
81
|
+
count covers additional visible rows.
|
|
82
|
+
|
|
42
83
|
Privacy applies to the content surfaces instead. `memory_evidence` and the
|
|
43
84
|
recent-blocked-writes list in `memory_status` and `/memory` follow each reader's
|
|
44
85
|
repository visibility (#306).
|
|
@@ -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.
|
|
3
|
+
"version": "0.32.0",
|
|
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,11 +2,12 @@
|
|
|
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";
|
|
9
9
|
import { redactSecrets } from "../store/secrets.ts";
|
|
10
|
+
import { recordOutcome } from "../telemetry/ledger.ts";
|
|
10
11
|
import {
|
|
11
12
|
session,
|
|
12
13
|
setLastSeenSid,
|
|
@@ -173,6 +174,7 @@ export async function afterTool(
|
|
|
173
174
|
const ts = new Date().toISOString();
|
|
174
175
|
|
|
175
176
|
const s = session(sid ?? "?");
|
|
177
|
+
const turnKey = s.turnKey;
|
|
176
178
|
const rec: ToolResult = {
|
|
177
179
|
call,
|
|
178
180
|
tool,
|
|
@@ -208,6 +210,18 @@ export async function afterTool(
|
|
|
208
210
|
rec.gateCheck = true;
|
|
209
211
|
rec.cmd = family;
|
|
210
212
|
await record("gate_check", { cmd: family, status }, true, sid);
|
|
213
|
+
// the same fact in the use ledger, where a ride recorded on this
|
|
214
|
+
// turn can be joined to it. Evidence is the audit trail — pruned and
|
|
215
|
+
// quarantined on its own schedule — so the join cannot live there.
|
|
216
|
+
if (sid && turnKey && rec.turn !== undefined)
|
|
217
|
+
await recordOutcome(
|
|
218
|
+
sid,
|
|
219
|
+
rec.turn,
|
|
220
|
+
status,
|
|
221
|
+
family,
|
|
222
|
+
Date.parse(ts),
|
|
223
|
+
turnKey,
|
|
224
|
+
);
|
|
211
225
|
if (status === "FAIL") {
|
|
212
226
|
s.pendingGate = { call, cmd: family, chain: [], count: 0 };
|
|
213
227
|
} else if (s.pendingGate && s.pendingGate.cmd === family) {
|
|
@@ -336,6 +350,7 @@ export function hasGateCheck(sid: string): boolean {
|
|
|
336
350
|
export function markTurn(sid: string): void {
|
|
337
351
|
const s = session(sid);
|
|
338
352
|
s.turns++;
|
|
353
|
+
s.turnKey = crypto.randomUUID();
|
|
339
354
|
if (!s.firstActivityTs) s.firstActivityTs = new Date().toISOString();
|
|
340
355
|
}
|
|
341
356
|
|
|
@@ -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/core/state.ts
CHANGED
|
@@ -60,6 +60,7 @@ export interface SessionState {
|
|
|
60
60
|
// first activity time, and the first memory_recall that surfaced an open
|
|
61
61
|
// thread. Deterministic: derived only from queued messages and tool results.
|
|
62
62
|
turns: number;
|
|
63
|
+
turnKey?: string;
|
|
63
64
|
firstActivityTs?: string;
|
|
64
65
|
firstTap?: FirstTap;
|
|
65
66
|
finalized: boolean;
|
|
@@ -141,6 +142,16 @@ export function session(sid: string): SessionState {
|
|
|
141
142
|
return s;
|
|
142
143
|
}
|
|
143
144
|
|
|
145
|
+
/**
|
|
146
|
+
* Turn count for a session ALREADY being tracked, or undefined. Unlike
|
|
147
|
+
* `session()` this neither creates state nor touches the LRU, so a telemetry
|
|
148
|
+
* caller can stamp a turn without extending a session's residency.
|
|
149
|
+
*/
|
|
150
|
+
export function peekTurn(sid: string) {
|
|
151
|
+
const s = sessions.get(sid);
|
|
152
|
+
return s?.turnKey ? { turn: s.turns, key: s.turnKey } : undefined;
|
|
153
|
+
}
|
|
154
|
+
|
|
144
155
|
let current: { sid: string; call: string; tool: string } = {
|
|
145
156
|
sid: "?",
|
|
146
157
|
call: "?",
|
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,19 +62,16 @@ 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";
|
|
75
72
|
import { blockedRecent } from "./status/write.ts";
|
|
76
73
|
import { firstFrontierTap, markFrontierTap } from "./capture/triggers.ts";
|
|
77
|
-
import { setCurrent } from "./core/state.ts";
|
|
74
|
+
import { peekTurn, setCurrent } from "./core/state.ts";
|
|
78
75
|
import {
|
|
79
76
|
resolveRepo,
|
|
80
77
|
setRepoScope,
|
|
@@ -197,7 +194,19 @@ const impl = {
|
|
|
197
194
|
for (const m of rows)
|
|
198
195
|
for (const t of sharedTerms(query, m))
|
|
199
196
|
if (!terms.includes(t)) terms.push(t);
|
|
200
|
-
|
|
197
|
+
// the turn is what joins a ride to the outcome of that same turn.
|
|
198
|
+
// Read, never created-for: markTurn has already run for any session that
|
|
199
|
+
// can reach a read path, so this does not seed state.
|
|
200
|
+
const observed = peekTurn(sid);
|
|
201
|
+
await recordHits(
|
|
202
|
+
src,
|
|
203
|
+
sid,
|
|
204
|
+
rows,
|
|
205
|
+
terms,
|
|
206
|
+
Date.now(),
|
|
207
|
+
observed?.turn,
|
|
208
|
+
observed?.key,
|
|
209
|
+
);
|
|
201
210
|
};
|
|
202
211
|
// The host listener owns measured usage; the epoch controller drops it
|
|
203
212
|
// alongside its own maps when the shared session LRU evicts an entry.
|
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,
|
package/src/status/payload.ts
CHANGED
|
@@ -41,6 +41,23 @@ export interface StoreCounts {
|
|
|
41
41
|
* ledger says so instead of inflating "never" (see `ledgerIsYoung`).
|
|
42
42
|
*/
|
|
43
43
|
ledgerSince?: string | null;
|
|
44
|
+
/**
|
|
45
|
+
* Counts cover active rows across all repositories in the store. Only
|
|
46
|
+
* details are reader-scoped. A joined ride has a later classified gate on
|
|
47
|
+
* the same turn; clean and failAfter count distinct row/turn pairs.
|
|
48
|
+
*/
|
|
49
|
+
useOutcome?: {
|
|
50
|
+
/** Active rows with at least one joined ride. */
|
|
51
|
+
rowsMeasured: number;
|
|
52
|
+
details?: string[];
|
|
53
|
+
/** Outcome writes lost by this process for the current store. */
|
|
54
|
+
droppedOutcomeWrites?: number;
|
|
55
|
+
joined: number;
|
|
56
|
+
clean: number;
|
|
57
|
+
failAfter: number;
|
|
58
|
+
/** Rides >= EVICT_MIN_RIDES with zero clean turns. Reported, never acted on. */
|
|
59
|
+
evictCandidates: number;
|
|
60
|
+
};
|
|
44
61
|
/** Bytes of store the active rows occupy (canonical logfmt rendering). */
|
|
45
62
|
bytes?: number;
|
|
46
63
|
/** Per-row average of the same, the "what does a row cost" number. */
|
package/src/status/report.ts
CHANGED
|
@@ -13,6 +13,7 @@ import {
|
|
|
13
13
|
type StoreCounts,
|
|
14
14
|
emptyStats,
|
|
15
15
|
} from "./payload.ts";
|
|
16
|
+
import { EVICT_MIN_RIDES } from "./store-summary.ts";
|
|
16
17
|
|
|
17
18
|
function ago(iso: string): string {
|
|
18
19
|
const ms = Date.now() - new Date(iso).getTime();
|
|
@@ -282,6 +283,22 @@ export function renderMemoryReport(input: {
|
|
|
282
283
|
` retrieved ${used} rows in the last 30d; never retrieved ${store.neverRetrieved} (${share}%)${basis} — reported, not acted on`,
|
|
283
284
|
);
|
|
284
285
|
}
|
|
286
|
+
if (store.useOutcome) {
|
|
287
|
+
const u = store.useOutcome;
|
|
288
|
+
// Every number here is a floor and a correlation. Say it in the line, not
|
|
289
|
+
// in a footnote nobody reads: only rides that landed on a turn which also
|
|
290
|
+
// ran a gate command (build/test/lint/typecheck) can be scored at all.
|
|
291
|
+
out.push(
|
|
292
|
+
` outcome-linked ${u.joined} rides over ${u.rowsMeasured} rows: ${u.clean} clean row/turns, ${u.failAfter} failed row/turns (store-wide)`,
|
|
293
|
+
` ${u.evictCandidates} candidate${u.evictCandidates === 1 ? "" : "s"} at ≥${EVICT_MIN_RIDES} rides with no clean turn — best-effort counts are floors since ${store.ledgerSince ?? "unknown"}; correlation on the ride's own turn, reported, never acted on`,
|
|
294
|
+
...(u.droppedOutcomeWrites === undefined
|
|
295
|
+
? []
|
|
296
|
+
: [
|
|
297
|
+
` outcome writes dropped for this store by this process: ${u.droppedOutcomeWrites}`,
|
|
298
|
+
]),
|
|
299
|
+
);
|
|
300
|
+
for (const detail of u.details ?? []) out.push(detail);
|
|
301
|
+
}
|
|
285
302
|
const sizing: string[] = [];
|
|
286
303
|
if (store.bytes !== undefined) {
|
|
287
304
|
sizing.push(
|
|
@@ -1,26 +1,94 @@
|
|
|
1
1
|
// Shared store counts for epoch payloads and the chat report.
|
|
2
|
-
//
|
|
3
|
-
import {
|
|
2
|
+
// Aggregates cover the supplied store. The caller scopes per-row details.
|
|
3
|
+
import {
|
|
4
|
+
joinUseWithOutcomes,
|
|
5
|
+
neverRetrieved,
|
|
6
|
+
type HitEntry,
|
|
7
|
+
type TurnOutcome,
|
|
8
|
+
type UseLedger,
|
|
9
|
+
} from "../telemetry/ledger.ts";
|
|
4
10
|
import type { Memory } from "../store/model/memory.ts";
|
|
5
11
|
import { isActive } from "../store/model/predicates.ts";
|
|
6
12
|
import type { StoreCounts } from "./payload.ts";
|
|
7
13
|
|
|
14
|
+
/**
|
|
15
|
+
* A row is an eviction CANDIDATE at this many rides with no clean turn. Five,
|
|
16
|
+
* not two: `recordHits` throttles a row-set to one line per hour, so rides
|
|
17
|
+
* accumulate slowly and a low bar would flag a row that simply rode a bad
|
|
18
|
+
* afternoon.
|
|
19
|
+
*/
|
|
20
|
+
export const EVICT_MIN_RIDES = 5;
|
|
21
|
+
|
|
8
22
|
export function summarizeStore(
|
|
9
23
|
rows: Memory[],
|
|
10
24
|
ledger: UseLedger,
|
|
11
25
|
malformed: number,
|
|
26
|
+
/**
|
|
27
|
+
* Rides and gate outcomes for the join. Omitted, the outcome block is
|
|
28
|
+
* absent rather than zero — the caller did not look, which is a different
|
|
29
|
+
* statement from "nothing helped".
|
|
30
|
+
*/
|
|
31
|
+
use?: {
|
|
32
|
+
droppedOutcomeWrites?: number;
|
|
33
|
+
rides: HitEntry[];
|
|
34
|
+
outcomes: TurnOutcome[];
|
|
35
|
+
visible?: (row: Memory) => boolean;
|
|
36
|
+
},
|
|
12
37
|
): { active: Memory[]; counts: StoreCounts } {
|
|
13
38
|
const active = rows.filter(isActive);
|
|
14
|
-
|
|
15
|
-
active,
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
neverRetrieved: neverRetrieved(active, ledger).length,
|
|
23
|
-
ledgerSince: ledger.since,
|
|
24
|
-
},
|
|
39
|
+
const counts: StoreCounts = {
|
|
40
|
+
active: active.length,
|
|
41
|
+
superseded: rows.length - active.length,
|
|
42
|
+
open: active.filter((m) => m.status === "open").length,
|
|
43
|
+
scopes: new Set(active.map((m) => m.scope)).size,
|
|
44
|
+
malformed,
|
|
45
|
+
neverRetrieved: neverRetrieved(active, ledger).length,
|
|
46
|
+
ledgerSince: ledger.since,
|
|
25
47
|
};
|
|
48
|
+
if (use) {
|
|
49
|
+
const live = new Map(active.map((m) => [m.ts, m]));
|
|
50
|
+
const candidates: string[] = [];
|
|
51
|
+
const others: string[] = [];
|
|
52
|
+
let visibleCount = 0;
|
|
53
|
+
const limit = 20;
|
|
54
|
+
const joined = joinUseWithOutcomes(use.rides, use.outcomes);
|
|
55
|
+
let rowsMeasured = 0;
|
|
56
|
+
let sumJoined = 0;
|
|
57
|
+
let clean = 0;
|
|
58
|
+
let failAfter = 0;
|
|
59
|
+
let evictCandidates = 0;
|
|
60
|
+
for (const [row, o] of joined) {
|
|
61
|
+
const memory = live.get(row);
|
|
62
|
+
if (!memory) continue;
|
|
63
|
+
const candidate =
|
|
64
|
+
o.joined > 0 && o.rides >= EVICT_MIN_RIDES && o.clean === 0;
|
|
65
|
+
const details = candidate ? candidates : others;
|
|
66
|
+
if (use.visible?.(memory)) {
|
|
67
|
+
visibleCount++;
|
|
68
|
+
if (details.length < limit)
|
|
69
|
+
details.push(
|
|
70
|
+
` ${row} used=${o.rides} clean=${o.clean} fail_after=${o.failAfter} unknown=${o.rides - o.joined}${candidate ? " (eviction candidate)" : ""}`,
|
|
71
|
+
);
|
|
72
|
+
}
|
|
73
|
+
if (o.joined === 0) continue;
|
|
74
|
+
rowsMeasured++;
|
|
75
|
+
sumJoined += o.joined;
|
|
76
|
+
clean += o.clean;
|
|
77
|
+
failAfter += o.failAfter;
|
|
78
|
+
if (candidate) evictCandidates++;
|
|
79
|
+
}
|
|
80
|
+
const details = [...candidates, ...others].slice(0, limit);
|
|
81
|
+
if (visibleCount > limit)
|
|
82
|
+
details.push(` … ${visibleCount - limit} more visible rows`);
|
|
83
|
+
counts.useOutcome = {
|
|
84
|
+
...(details.length ? { details } : {}),
|
|
85
|
+
droppedOutcomeWrites: use.droppedOutcomeWrites,
|
|
86
|
+
rowsMeasured,
|
|
87
|
+
joined: sumJoined,
|
|
88
|
+
clean,
|
|
89
|
+
failAfter,
|
|
90
|
+
evictCandidates,
|
|
91
|
+
};
|
|
92
|
+
}
|
|
93
|
+
return { active, counts };
|
|
26
94
|
}
|
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 {
|