opencode-self-improvement 0.14.22 → 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/package.json +1 -1
- 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/status.ts +2 -4
- package/src/undo.ts +9 -4
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": {
|
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/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/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>();
|