opencode-self-improvement 0.15.23 → 0.15.25

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "opencode-self-improvement",
3
- "version": "0.15.23",
3
+ "version": "0.15.25",
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": {
@@ -65,9 +65,9 @@
65
65
  "gate": "bun scripts/merge-gate.ts",
66
66
  "gate:hooks": "git config core.hooksPath .githooks",
67
67
  "typecheck": "bun x tsc --noEmit -p tsconfig.json",
68
- "bench": "bun bench/inject-cost.ts",
69
- "bench:recall": "bun bench/recall-quality.ts",
70
- "bench:write": "bun bench/write-latency.ts",
68
+ "bench": "bun bench/runners/inject-cost.ts",
69
+ "bench:recall": "bun bench/runners/recall-quality.ts",
70
+ "bench:write": "bun bench/runners/write-latency.ts",
71
71
  "sweep:test": "bun scripts/test-sweep.ts",
72
72
  "memory-view": "bun run src/viewer/server.ts",
73
73
  "format": "biome format --write",
package/src/index.ts CHANGED
@@ -237,7 +237,7 @@ const impl = {
237
237
  // ever writes through the gate. A per-session, per-trigger cooldown bounds
238
238
  // the cost. Compaction-triggered rows carry the CAPTURE_COMPACT_TAG tag and
239
239
  // auto_capture_compaction_* evidence lines, idle rows keep auto_capture_*,
240
- // so decay/status — and bench/capture-trigger-compare.ts — can measure
240
+ // so decay/status — and bench/runners/capture-trigger-compare.ts — can measure
241
241
  // which trigger earns its tokens. Every failure is swallowed: capture must
242
242
  // never be able to break a session.
243
243
  const capture = configureAutoCapture(ctx, {
@@ -46,7 +46,7 @@ const LONG_QUERY_TOKENS = 3;
46
46
  // author-supplied aliases indexed at write time (#40 item 3, the vocabulary
47
47
  // bridge for the bench's strict-paraphrase wall). Keywords are indexed, never
48
48
  // rendered, so they cannot change what a block costs.
49
- // Exported for bench/recall-quality.ts — the benchmark measures the shipped
49
+ // Exported for bench/runners/recall-quality.ts — the benchmark measures the shipped
50
50
  // matcher.
51
51
  //
52
52
  // Superseded rows are dropped HERE, not only by the callers. Every model-facing
@@ -32,45 +32,79 @@ export async function prune(
32
32
  durable: PruneResult = { deleted: [], snapshot: [] },
33
33
  ): Promise<PruneResult> {
34
34
  const { deleted, snapshot } = durable;
35
- for (const file of await memoryFiles()) {
36
- await withStoreLock(
37
- file,
38
- async () => {
39
- const since = await fileIdentity(file);
40
- const lines = await readLines(file);
41
- const kept: string[] = [];
42
- const fileDeleted: DeletedMemory[] = [];
43
- let changed = false;
44
- for (const line of lines) {
45
- const parsed = parseLine(line);
46
- const m = parsed ? toMemory(parsed, file, 0) : null;
47
- // Repo floor: forgetting scope X here must never delete
48
- // another repo's row for scope X — same basename collisions are real
49
- // (a fork next to its upstream).
50
- if (
51
- m &&
52
- m.scope === scope &&
53
- m.type === type &&
54
- isVisibleTo(m, reader)
55
- ) {
56
- fileDeleted.push({ memory: m, reason });
57
- await logDeletion(m, reason);
58
- changed = true;
59
- continue;
35
+ // #206: a later file failing must not undo the bookkeeping an earlier file
36
+ // already earned, and no bookkeeping may claim a row the store never let go
37
+ // of. So the order per file is: publish, then audit; and the tombstone pass
38
+ // runs over everything committed even when the loop itself threw. Errors are
39
+ // collected, never swallowed: the primary (loop) error is rethrown with any
40
+ // secondary (audit/tombstone) failure appended, so pruneMemory's PARTIAL
41
+ // reply names both.
42
+ let loopError: unknown;
43
+ let bookkeepingError: string | undefined;
44
+ const note = (msg: string) => {
45
+ bookkeepingError = bookkeepingError ? `${bookkeepingError}; ${msg}` : msg;
46
+ };
47
+ try {
48
+ for (const file of await memoryFiles()) {
49
+ const fileDeleted: DeletedMemory[] = [];
50
+ await withStoreLock(
51
+ file,
52
+ async () => {
53
+ const since = await fileIdentity(file);
54
+ const lines = await readLines(file);
55
+ const kept: string[] = [];
56
+ let changed = false;
57
+ for (const line of lines) {
58
+ const parsed = parseLine(line);
59
+ const m = parsed ? toMemory(parsed, file, 0) : null;
60
+ // Repo floor: forgetting scope X here must never delete
61
+ // another repo's row for scope X — same basename collisions are real
62
+ // (a fork next to its upstream).
63
+ if (
64
+ m &&
65
+ m.scope === scope &&
66
+ m.type === type &&
67
+ isVisibleTo(m, reader)
68
+ ) {
69
+ fileDeleted.push({ memory: m, reason });
70
+ changed = true;
71
+ continue;
72
+ }
73
+ kept.push(line);
60
74
  }
61
- kept.push(line);
75
+ if (!changed) return;
76
+ snapshot.push(...(await snapshotFiles([file])));
77
+ await writeAtomic(
78
+ file,
79
+ kept.join("\n") + (kept.length ? "\n" : ""),
80
+ since,
81
+ );
82
+ deleted.push(...fileDeleted);
83
+ },
84
+ LOCK_WRITE,
85
+ );
86
+ // #206 STORE-2: the deletion audit FOLLOWS the publish, as in the viewer's
87
+ // delete (mutate.ts audits after its locked handover). Auditing inside the
88
+ // read loop claimed rows as deleted when a snapshot/publish failure left
89
+ // them live: the viewer's Deleted panel listed a still-live row, its
90
+ // restore-entry action would duplicate it, and undo's auditedDeletions()
91
+ // treated the ts as intentionally removed. appendLog needs no store lock
92
+ // (deletions.logfmt is append-only), so this stays outside the day-file
93
+ // lock and keeps the one consistent lock order across the codebase. An
94
+ // audit failure after a committed publish cannot be undone — it is
95
+ // reported as PARTIAL and recoverable by inspecting the store.
96
+ for (const d of fileDeleted) {
97
+ try {
98
+ await logDeletion(d.memory, d.reason);
99
+ } catch (err) {
100
+ note(
101
+ `deletion audit failed for ${d.memory.ts}: ${err instanceof Error ? err.message : String(err)}`,
102
+ );
62
103
  }
63
- if (!changed) return;
64
- snapshot.push(...(await snapshotFiles([file])));
65
- await writeAtomic(
66
- file,
67
- kept.join("\n") + (kept.length ? "\n" : ""),
68
- since,
69
- );
70
- deleted.push(...fileDeleted);
71
- },
72
- LOCK_WRITE,
73
- );
104
+ }
105
+ }
106
+ } catch (err) {
107
+ loopError = err;
74
108
  }
75
109
  // #35: tombstone every forgotten VALUE, keyed on content rather than on the
76
110
  // row's `ts`, so replaying the source cannot store the fact again.
@@ -82,13 +116,37 @@ export async function prune(
82
116
  // loop would nest a second store lock (day file, then rejected.logfmt) inside
83
117
  // the first, and one consistent order across the codebase is what keeps the
84
118
  // lock manager from having to reason about nesting at all.
85
- await tombstoneMany(
86
- deleted.map((d) => ({
87
- content: d.memory.content,
88
- scope: d.memory.scope,
89
- type: d.memory.type,
90
- })),
91
- { reason, source: "forget" },
92
- );
119
+ //
120
+ // #206 STORE-1: this runs even when the loop threw. The committed rows are
121
+ // already out of the store, so a retry of the forget will never see them
122
+ // again — skipping the tombstone here is how a partial forget quietly
123
+ // reopened the rejection hole #35 closed. If THIS write fails too, the
124
+ // PARTIAL reply names it: the committed rows are gone and unprotected, and
125
+ // only a human (the viewer's reject route) can restore the marker — the
126
+ // agreed recoverable partial-result semantics, pinned by test.
127
+ if (deleted.length) {
128
+ try {
129
+ await tombstoneMany(
130
+ deleted.map((d) => ({
131
+ content: d.memory.content,
132
+ scope: d.memory.scope,
133
+ type: d.memory.type,
134
+ })),
135
+ { reason, source: "forget" },
136
+ );
137
+ } catch (err) {
138
+ note(
139
+ `rejection tombstones incomplete: ${err instanceof Error ? err.message : String(err)}`,
140
+ );
141
+ }
142
+ }
143
+ if (loopError) {
144
+ if (bookkeepingError)
145
+ throw new Error(
146
+ `${loopError instanceof Error ? loopError.message : String(loopError)}; ${bookkeepingError}`,
147
+ );
148
+ throw loopError;
149
+ }
150
+ if (bookkeepingError) throw new Error(bookkeepingError);
93
151
  return { deleted, snapshot };
94
152
  }