opencode-self-improvement 0.14.21 → 0.14.23
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 +2 -0
- package/package.json +3 -3
- package/src/blocklist.ts +9 -3
- package/src/hits.ts +9 -3
- package/src/memory.ts +9 -4
- package/src/portable.ts +9 -4
- package/src/state.ts +3 -1
- package/src/status.ts +2 -4
- package/src/triggers.ts +18 -6
- package/src/undo.ts +9 -4
package/README.md
CHANGED
|
@@ -305,6 +305,8 @@ bun run gate # typecheck + lint + unit tests + terminal smoke & BDD
|
|
|
305
305
|
bun run gate:hooks # once per clone: run the gate on `git push`
|
|
306
306
|
```
|
|
307
307
|
|
|
308
|
+
Use Bun **1.4.4** for development checks, matching CI. `bun run test` and `bun run test:e2e` run files across at most four worker processes with Bun's file isolation; cases inside each file stay sequential because fixtures share environment variables and module state. The local gate uses those same scripts. To diagnose order-dependent failures in the original shared-process mode, run `bun test ./test/` or `bun test ./e2e/ --timeout 240000` directly.
|
|
309
|
+
|
|
308
310
|
**Feature order is BDD-first.** A new feature starts by adding or fixing a scenario in `e2e/` that describes the behavior as a user would observe it — before implementation code and before unit tests. Then the unit tests for the pieces, then the code until everything is green. If no scenario turns red first, the feature has no observable contract.
|
|
309
311
|
|
|
310
312
|
`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.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "opencode-self-improvement",
|
|
3
|
-
"version": "0.14.
|
|
3
|
+
"version": "0.14.23",
|
|
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": {
|
|
@@ -60,8 +60,8 @@
|
|
|
60
60
|
"typescript": "^7.0.2"
|
|
61
61
|
},
|
|
62
62
|
"scripts": {
|
|
63
|
-
"test": "bun test ./test/",
|
|
64
|
-
"test:e2e": "bun test ./e2e/ --timeout 240000",
|
|
63
|
+
"test": "bun test ./test/ --parallel=4",
|
|
64
|
+
"test:e2e": "bun test ./e2e/ --parallel=4 --timeout 240000",
|
|
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",
|
package/src/blocklist.ts
CHANGED
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
// path: recall, the injected digest and contextual pull, and the viewer's
|
|
4
4
|
// active list. Blocklist lives at <memoryRoot>/blocklist.logfmt so a recursive
|
|
5
5
|
// memory scan must never pick it up.
|
|
6
|
+
import { readFile } from "node:fs/promises";
|
|
6
7
|
import { join } from "node:path";
|
|
7
8
|
import { memoryRoot } from "./config.ts";
|
|
8
9
|
import { appendLog, fileIdentity, formatLine, parseLine, readLines, writeAtomic } from "./logfmt.ts";
|
|
@@ -57,10 +58,15 @@ export async function removeBlock(ts: string): Promise<boolean> {
|
|
|
57
58
|
return withStoreLock(
|
|
58
59
|
file,
|
|
59
60
|
async () => {
|
|
60
|
-
const store = Bun.file(file);
|
|
61
|
-
if (!(await store.exists())) return false;
|
|
62
61
|
const since = await fileIdentity(file);
|
|
63
|
-
|
|
62
|
+
let text: string;
|
|
63
|
+
try {
|
|
64
|
+
text = await readFile(file, "utf8");
|
|
65
|
+
} catch (err) {
|
|
66
|
+
if ((err as NodeJS.ErrnoException).code === "ENOENT") return false;
|
|
67
|
+
throw err;
|
|
68
|
+
}
|
|
69
|
+
const kept = text.split("\n").filter((l) => {
|
|
64
70
|
const row = parseLine(l);
|
|
65
71
|
return !(row && row.ts === ts);
|
|
66
72
|
});
|
package/src/hits.ts
CHANGED
|
@@ -14,6 +14,7 @@
|
|
|
14
14
|
// is in memory.ts's RESERVED set so loadAll() cannot ingest it), and it logs no
|
|
15
15
|
// prompt text — only the tokens a row and the query shared, each of which
|
|
16
16
|
// already exists inside that row.
|
|
17
|
+
import { readFile, stat } from "node:fs/promises";
|
|
17
18
|
import { join } from "node:path";
|
|
18
19
|
import { memoryRoot, HITS_FILENAME } from "./config.ts";
|
|
19
20
|
import { appendLog, bracketList, fileIdentity, formatLine, parseLine, readLines, writeAtomic } from "./logfmt.ts";
|
|
@@ -63,14 +64,19 @@ export function resetHitThrottle(): void {
|
|
|
63
64
|
}
|
|
64
65
|
|
|
65
66
|
async function rotateIfNeeded(): Promise<void> {
|
|
66
|
-
|
|
67
|
-
|
|
67
|
+
let size: number;
|
|
68
|
+
try {
|
|
69
|
+
size = (await stat(hitsFile())).size;
|
|
70
|
+
} catch (err) {
|
|
71
|
+
if ((err as NodeJS.ErrnoException).code === "ENOENT") return;
|
|
72
|
+
throw err;
|
|
73
|
+
}
|
|
68
74
|
if (size <= MAX_HITS_BYTES) return;
|
|
69
75
|
// #106: anchor the halving like every other whole-file publish (#89) - on
|
|
70
76
|
// Windows the rename can be refused by a reader's handle, and the retry is
|
|
71
77
|
// only safe while nothing else moved this file.
|
|
72
78
|
const since = await fileIdentity(hitsFile());
|
|
73
|
-
const lines = (await
|
|
79
|
+
const lines = (await readFile(hitsFile(), "utf8")).split("\n").filter((l) => l.trim());
|
|
74
80
|
await writeAtomic(hitsFile(), lines.slice(Math.floor(lines.length / 2)).join("\n") + "\n", since);
|
|
75
81
|
}
|
|
76
82
|
|
package/src/memory.ts
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
// vendor/opencode-memory/LICENSE) and extends it with the fields the write-gate
|
|
4
4
|
// needs: supersession markers, snapshots and audited deletion.
|
|
5
5
|
import { existsSync } from "node:fs";
|
|
6
|
-
import { open } from "node:fs/promises";
|
|
6
|
+
import { open, readFile } from "node:fs/promises";
|
|
7
7
|
import { join, basename } from "node:path";
|
|
8
8
|
import { dateStr, memoryRoot, deletionsFile, snapshotDir, HITS_FILENAME } from "./config.ts";
|
|
9
9
|
import { repoScopeFor, sessionScope, writeTarget, type RepoScope } from "./repokey.ts";
|
|
@@ -570,10 +570,15 @@ async function claimSnapshot(file: string): Promise<string> {
|
|
|
570
570
|
export async function snapshotFiles(files: string[]): Promise<string[]> {
|
|
571
571
|
const snaps: string[] = [];
|
|
572
572
|
for (const file of files) {
|
|
573
|
-
|
|
574
|
-
|
|
573
|
+
let contents: Buffer;
|
|
574
|
+
try {
|
|
575
|
+
contents = await readFile(file);
|
|
576
|
+
} catch (err) {
|
|
577
|
+
if ((err as NodeJS.ErrnoException).code === "ENOENT") continue;
|
|
578
|
+
throw err;
|
|
579
|
+
}
|
|
575
580
|
const snap = await claimSnapshot(file);
|
|
576
|
-
await Bun.write(snap,
|
|
581
|
+
await Bun.write(snap, contents);
|
|
577
582
|
snaps.push(snap);
|
|
578
583
|
}
|
|
579
584
|
return snaps;
|
package/src/portable.ts
CHANGED
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
// moat. Decay is supersede-not-delete and snapshot-first, mirroring prune.
|
|
6
6
|
import { constants } from "node:fs";
|
|
7
7
|
import { randomUUID } from "node:crypto";
|
|
8
|
-
import { mkdir, open } from "node:fs/promises";
|
|
8
|
+
import { mkdir, open, readFile } from "node:fs/promises";
|
|
9
9
|
import { dirname, join } from "node:path";
|
|
10
10
|
import { allowOutsideStorePaths, exportsDir, memoryRoot } from "./config.ts";
|
|
11
11
|
import { resolveContained } from "./containment.ts";
|
|
@@ -299,8 +299,13 @@ export async function importMemories(
|
|
|
299
299
|
if (!target.toLowerCase().endsWith(".jsonl")) {
|
|
300
300
|
throw new Error(`memory_import file must be a .jsonl export (got "${path}")`);
|
|
301
301
|
}
|
|
302
|
-
|
|
303
|
-
|
|
302
|
+
let text: string;
|
|
303
|
+
try {
|
|
304
|
+
text = await readFile(target, "utf8");
|
|
305
|
+
} catch (err) {
|
|
306
|
+
if ((err as NodeJS.ErrnoException).code === "ENOENT") throw new Error(`import file not found: ${target}`);
|
|
307
|
+
throw err;
|
|
308
|
+
}
|
|
304
309
|
const tally: ImportTally = { promoted: 0, collapsed: 0, blocked: 0, skipped: 0, downgraded: 0, unaudited: 0 };
|
|
305
310
|
// #152: the importing session's repository is resolved BEFORE the first row,
|
|
306
311
|
// through the writer rule rather than the ambient one. An unresolved named
|
|
@@ -312,7 +317,7 @@ export async function importMemories(
|
|
|
312
317
|
const currentScope = writeAt.scope;
|
|
313
318
|
let allowFrontier = false;
|
|
314
319
|
let first = true;
|
|
315
|
-
for (const line of (
|
|
320
|
+
for (const line of text.replace(/^\uFEFF/, "").split("\n")) {
|
|
316
321
|
if (!line.trim()) continue;
|
|
317
322
|
if (first) {
|
|
318
323
|
first = false;
|
package/src/state.ts
CHANGED
|
@@ -33,7 +33,9 @@ export interface SessionState {
|
|
|
33
33
|
pendingGate: {
|
|
34
34
|
call: string;
|
|
35
35
|
cmd: string;
|
|
36
|
-
chain:
|
|
36
|
+
chain: string[];
|
|
37
|
+
count: number;
|
|
38
|
+
fix?: { call: string; index: number };
|
|
37
39
|
} | null;
|
|
38
40
|
// Bounded provenance for write telemetry (#163), independent of the full
|
|
39
41
|
// calls ledger used by grounding, attribution, and convergence.
|
package/src/status.ts
CHANGED
|
@@ -12,7 +12,7 @@
|
|
|
12
12
|
//
|
|
13
13
|
// Scope of v2: same-machine reads. Against a REMOTE server the terminal panel
|
|
14
14
|
// sees no status files (it says so) — the RPC surface is the planned follow-up.
|
|
15
|
-
import { readdir, rm, stat } from "node:fs/promises";
|
|
15
|
+
import { readFile, readdir, rm, stat } from "node:fs/promises";
|
|
16
16
|
import { join } from "node:path";
|
|
17
17
|
import { dateStr, evidenceDir, memoryRoot } from "./config.ts";
|
|
18
18
|
import { parseLine, readLines } from "./logfmt.ts";
|
|
@@ -247,9 +247,7 @@ export async function writeStatus(p: StatusPayload): Promise<void> {
|
|
|
247
247
|
|
|
248
248
|
async function readJson(path: string): Promise<StatusPayload | null> {
|
|
249
249
|
try {
|
|
250
|
-
const
|
|
251
|
-
if (!(await f.exists())) return null;
|
|
252
|
-
const v: unknown = await f.json();
|
|
250
|
+
const v: unknown = JSON.parse((await readFile(path, "utf8")).replace(/^\uFEFF/, ""));
|
|
253
251
|
if (!v || typeof v !== "object") return null;
|
|
254
252
|
const p = v as Partial<StatusPayload>;
|
|
255
253
|
if (typeof p.at !== "string" || typeof p.block !== "string") return null;
|
package/src/triggers.ts
CHANGED
|
@@ -33,6 +33,17 @@ export interface AfterOutput {
|
|
|
33
33
|
const ENGAGEMENT_TOOLS = new Set(["grep", "glob", "read", "edit", "write", "bash", "shell"]);
|
|
34
34
|
|
|
35
35
|
const RECENT_EVIDENCE_CALLS = 10;
|
|
36
|
+
// Pending recovery stores IDs only; the full attribution ledger stays in calls.
|
|
37
|
+
function trackPending(s: SessionState, rec: ToolResult): void {
|
|
38
|
+
const pending = s.pendingGate;
|
|
39
|
+
if (!pending) return;
|
|
40
|
+
pending.count++;
|
|
41
|
+
if (rec.tool === "edit" || rec.tool === "write") {
|
|
42
|
+
pending.fix = { call: rec.call, index: pending.count };
|
|
43
|
+
}
|
|
44
|
+
pending.chain.push(rec.call);
|
|
45
|
+
if (pending.chain.length > RECENT_EVIDENCE_CALLS) pending.chain.shift();
|
|
46
|
+
}
|
|
36
47
|
// Recent engagement + latest gate check + FAIL/fix/PASS + tool FAIL/PASS.
|
|
37
48
|
export const MAX_WRITE_EVIDENCE_REFS = RECENT_EVIDENCE_CALLS + 1 + 3 + 2;
|
|
38
49
|
|
|
@@ -149,12 +160,12 @@ export async function afterTool(input: AfterInput, out: AfterOutput): Promise<vo
|
|
|
149
160
|
rec.cmd = family;
|
|
150
161
|
await record("gate_check", { cmd: family, status }, true, sid);
|
|
151
162
|
if (status === "FAIL") {
|
|
152
|
-
s.pendingGate = { call, cmd: family, chain: [] };
|
|
163
|
+
s.pendingGate = { call, cmd: family, chain: [], count: 0 };
|
|
153
164
|
} else if (s.pendingGate && s.pendingGate.cmd === family) {
|
|
154
165
|
const pend = s.pendingGate;
|
|
155
|
-
const
|
|
156
|
-
const
|
|
157
|
-
const
|
|
166
|
+
const fix = pend.fix?.call ?? call;
|
|
167
|
+
const oldFix = pend.fix && pend.fix.index <= pend.count - pend.chain.length;
|
|
168
|
+
const chainCalls = [pend.call, ...(oldFix ? [fix] : []), ...pend.chain, call];
|
|
158
169
|
await record(
|
|
159
170
|
"t4_learning",
|
|
160
171
|
{
|
|
@@ -164,6 +175,7 @@ export async function afterTool(input: AfterInput, out: AfterOutput): Promise<vo
|
|
|
164
175
|
to: "PASS",
|
|
165
176
|
gate_couple: true,
|
|
166
177
|
evidence_chain: `[${chainCalls.join(",")}]`,
|
|
178
|
+
evidence_chain_count: pend.count + 2,
|
|
167
179
|
fix_ref: fix,
|
|
168
180
|
},
|
|
169
181
|
false,
|
|
@@ -173,14 +185,14 @@ export async function afterTool(input: AfterInput, out: AfterOutput): Promise<vo
|
|
|
173
185
|
s.writeEvidence.gateRecovery = [pend.call, fix, call];
|
|
174
186
|
s.pendingGate = null;
|
|
175
187
|
} else if (s.pendingGate) {
|
|
176
|
-
s
|
|
188
|
+
trackPending(s, rec);
|
|
177
189
|
}
|
|
178
190
|
trackCall(s, rec);
|
|
179
191
|
return;
|
|
180
192
|
}
|
|
181
193
|
|
|
182
194
|
// Keep the pending gate chain (grep/read/edit between FAIL and PASS).
|
|
183
|
-
|
|
195
|
+
trackPending(s, rec);
|
|
184
196
|
trackCall(s, rec);
|
|
185
197
|
|
|
186
198
|
// ---- Failed -> fixed retry (non-gate tools) -------------------------------
|
package/src/undo.ts
CHANGED
|
@@ -24,7 +24,7 @@
|
|
|
24
24
|
// what you may read", the same rule memory_forget applies to global scope.
|
|
25
25
|
// Admin readers (the viewer, out-of-plugin maintenance) keep the whole-file
|
|
26
26
|
// restore exactly as it was.
|
|
27
|
-
import { lstat, realpath, stat } from "node:fs/promises";
|
|
27
|
+
import { lstat, readFile, realpath, stat } from "node:fs/promises";
|
|
28
28
|
import { basename, isAbsolute, join, relative, resolve } from "node:path";
|
|
29
29
|
import { deletionsFile, snapshotDir } from "./config.ts";
|
|
30
30
|
import { isWithin } from "./containment.ts";
|
|
@@ -213,7 +213,7 @@ export async function restoreSnapshot(
|
|
|
213
213
|
// Checks above ran on real paths; lock and write through the same lexical
|
|
214
214
|
// path every other writer uses, so the in-process lock queue is shared.
|
|
215
215
|
const target = resolve(memoryRootDir, snap.original);
|
|
216
|
-
const rawSnapLines = rows(await
|
|
216
|
+
const rawSnapLines = rows(await readFile(snap.path, "utf8"));
|
|
217
217
|
|
|
218
218
|
// Comparing and publishing happen under the same lock: a divergence check on
|
|
219
219
|
// a stale read would wave through a row that landed after it. A restore waits
|
|
@@ -226,8 +226,13 @@ export async function restoreSnapshot(
|
|
|
226
226
|
// Identity before the first read of `target` here: everything published
|
|
227
227
|
// below derives from what this read sees (logfmt.ts handoverRename).
|
|
228
228
|
const since = await fileIdentity(target);
|
|
229
|
-
|
|
230
|
-
|
|
229
|
+
let current = "";
|
|
230
|
+
try {
|
|
231
|
+
current = await readFile(target, "utf8");
|
|
232
|
+
} catch (err) {
|
|
233
|
+
if ((err as NodeJS.ErrnoException).code !== "ENOENT") throw err;
|
|
234
|
+
}
|
|
235
|
+
const curLines = rows(current);
|
|
231
236
|
// Deliberate deletions are read inside the lock too, so a forget that
|
|
232
237
|
// finished just before this restore is honoured.
|
|
233
238
|
const audited = mode !== "force" ? await auditedDeletions() : new Set<string>();
|