opencode-self-improvement 0.15.23 → 0.15.24
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 +1 -1
- package/src/store/files/prune.ts +103 -45
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "opencode-self-improvement",
|
|
3
|
-
"version": "0.15.
|
|
3
|
+
"version": "0.15.24",
|
|
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/store/files/prune.ts
CHANGED
|
@@ -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
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
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
|
-
|
|
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
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
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
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
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
|
}
|