opencode-self-improvement 0.15.29 → 0.15.31
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 +5 -0
- package/package.json +1 -1
- package/src/store/lock.ts +40 -15
- package/src/tui/panel.tsx +2 -2
- package/src/viewer/server.ts +3 -1
package/README.md
CHANGED
|
@@ -83,6 +83,7 @@ Zero configuration is the default. To tune, use the object form of the plugin en
|
|
|
83
83
|
| `OPENCODE_MEMORY_FRONTIER_BUDGET` | Fallback for `frontierBudget`. |
|
|
84
84
|
| `OPENCODE_COMMANDS_DIR` | Where the plugin mirrors its slash commands (default `~/.config/opencode/commands`). |
|
|
85
85
|
| `OPENCODE_CBM_BIN` | Path to a `codebase-memory-mcp` binary. See [Code graph](#code-graph-optional). |
|
|
86
|
+
| `OPENCODE_VIEWER_HOST` | Interface the editor binds to (default `127.0.0.1`). A non-loopback bind serves the store over plain HTTP with no authentication — only do it on a network you control. See [Surfaces](#surfaces). |
|
|
86
87
|
| `OPENCODE_VIEWER_PORT` | Admin editor port (default `8787`). |
|
|
87
88
|
| `OPENCODE_VIEWER_ALLOWED_HOSTS` | Comma-separated hosts beyond loopback. See [Surfaces](#surfaces). |
|
|
88
89
|
|
|
@@ -326,6 +327,8 @@ bun run format # apply the shared two-space TypeScript/TSX style
|
|
|
326
327
|
bun run format:check # check formatting without changing files
|
|
327
328
|
```
|
|
328
329
|
|
|
330
|
+
`bun run typecheck` runs `tsc --noEmit` on its own. In CI it runs inside the job named `lint`, so a green `lint` check silently implies tsc. The rest of the mapping: `bun run test` is the `test` job (re-run in `test-windows`, which reports but cannot gate merges), and `bun run test:e2e` is the `smoke` job.
|
|
331
|
+
|
|
329
332
|
`bun run lint` checks lint rules and TypeScript/TSX formatting; CI calls the same command. Lint warnings remain advisory, while formatting differences fail the check. Markdown commands, prose, JSON data and historical benchmark records are outside the formatter's scope.
|
|
330
333
|
|
|
331
334
|
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.
|
|
@@ -334,6 +337,8 @@ Use Bun **1.4.4** for development checks, matching CI. `bun run test` and `bun r
|
|
|
334
337
|
|
|
335
338
|
`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.
|
|
336
339
|
|
|
340
|
+
**The published surface is defined in `package.json`.** `exports` is the only import surface other code can reach (`.` → `index.ts`, `./tui` → `src/tui/panel.tsx`); `files` is the packaging list. `files` covers `src/`, so anything reachable from an `exports` target ships, but a new top-level file or directory — or anything the plugin reads at runtime outside those paths — must be added to `files` or it works from the checkout and vanishes from the npm artifact. The packed-artifact load in `e2e/` turns that miss red.
|
|
341
|
+
|
|
337
342
|
### Mutation sweep
|
|
338
343
|
|
|
339
344
|
```sh
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "opencode-self-improvement",
|
|
3
|
-
"version": "0.15.
|
|
3
|
+
"version": "0.15.31",
|
|
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/lock.ts
CHANGED
|
@@ -16,7 +16,7 @@
|
|
|
16
16
|
// - a lock FILE created with O_EXCL, which is atomic across processes (and
|
|
17
17
|
// exclusive against our own tasks too, since the check is in the kernel).
|
|
18
18
|
// A killed holder is recovered by age. A writer that waits past the budget
|
|
19
|
-
// gives up waiting — see onTimeout.
|
|
19
|
+
// gives up waiting — see onTimeout (default: fail closed, #216).
|
|
20
20
|
//
|
|
21
21
|
// Readers take NO lock: publishers hand over the new file with a rename
|
|
22
22
|
// (writeAtomic in logfmt.ts), so a reader always sees a complete store, never
|
|
@@ -30,6 +30,11 @@ const LOCK_SUFFIX = ".lock";
|
|
|
30
30
|
// A lock older than this belongs to a process that died holding it.
|
|
31
31
|
const STALE_MS = 10_000;
|
|
32
32
|
const DEFAULT_TIMEOUT_MS = 5_000;
|
|
33
|
+
// #216: the default policy is fail-closed, the policy #196 moved every
|
|
34
|
+
// production writer to. A writer that omits opts must refuse at the deadline,
|
|
35
|
+
// not silently reintroduce the unlocked-proceed row loss the LOCK_WRITE
|
|
36
|
+
// contract retired. "proceed" survives only as an explicit opt-in.
|
|
37
|
+
const DEFAULT_ON_TIMEOUT = "fail";
|
|
33
38
|
const MIN_BACKOFF_MS = 1;
|
|
34
39
|
const MAX_BACKOFF_MS = 25;
|
|
35
40
|
// How many consecutive create-failures with a proven-absent lock file mean
|
|
@@ -37,6 +42,13 @@ const MAX_BACKOFF_MS = 25;
|
|
|
37
42
|
// race with a live holder". The wait is a fast, bounded spin, not a budget.
|
|
38
43
|
const ABSENT_THROW_STRIKES = 8;
|
|
39
44
|
|
|
45
|
+
// The single source of the timeout policy (#216): both give-up paths — the
|
|
46
|
+
// direct budget and the queue hand-off — resolve through here, so the
|
|
47
|
+
// fail-closed default cannot drift between them.
|
|
48
|
+
function timeoutPolicy(opts: LockOptions): "proceed" | "fail" {
|
|
49
|
+
return opts.onTimeout === "proceed" ? "proceed" : DEFAULT_ON_TIMEOUT;
|
|
50
|
+
}
|
|
51
|
+
|
|
40
52
|
export function lockFileFor(file: string): string {
|
|
41
53
|
return file + LOCK_SUFFIX;
|
|
42
54
|
}
|
|
@@ -47,11 +59,11 @@ export type LockEvent = "steal" | "timeout";
|
|
|
47
59
|
export interface LockOptions {
|
|
48
60
|
timeoutMs?: number;
|
|
49
61
|
/**
|
|
50
|
-
* What waiting past `timeoutMs` means. "fail" refuses the
|
|
51
|
-
*
|
|
52
|
-
*
|
|
53
|
-
* can lose acknowledged writes when another caller rewrites
|
|
54
|
-
*
|
|
62
|
+
* What waiting past `timeoutMs` means. The default, "fail", refuses the
|
|
63
|
+
* mutation (#216: fail-closed is the contract every store writer keeps;
|
|
64
|
+
* LOCK_WRITE and LOCK_RESTORE spell it out). "proceed" runs the write
|
|
65
|
+
* unlocked and can lose acknowledged writes when another caller rewrites
|
|
66
|
+
* the same file — pass it only where that concession is intended.
|
|
55
67
|
*/
|
|
56
68
|
onTimeout?: "proceed" | "fail";
|
|
57
69
|
onEvent?: (event: LockEvent, waitedMs: number) => void;
|
|
@@ -154,7 +166,8 @@ export async function holdFileLock<T>(
|
|
|
154
166
|
// `absentStrikes > 0` only remembers the LAST probe, so a holder that
|
|
155
167
|
// legitimately finished and unlinked just as the budget expired was
|
|
156
168
|
// throwing away ordinary writes instead of taking the contention
|
|
157
|
-
// concession it describes.
|
|
169
|
+
// concession it describes. An EEXIST from a failed create counts as such a
|
|
170
|
+
// sighting too (a create that returns EEXIST saw the file).
|
|
158
171
|
let everSawHolder = false;
|
|
159
172
|
for (;;) {
|
|
160
173
|
try {
|
|
@@ -178,6 +191,16 @@ export async function holdFileLock<T>(
|
|
|
178
191
|
// wait for — our own ability to create files is what is broken, and
|
|
179
192
|
// the original error must surface instead of rotting into a timeout.
|
|
180
193
|
firstErr ??= err;
|
|
194
|
+
// An EEXIST from the create is a sighting in its own right: on POSIX it
|
|
195
|
+
// proves the lock file WAS there at the attempt, even if the probe
|
|
196
|
+
// below then proves the holder unlinked in between (the vanish race).
|
|
197
|
+
// Without this, that race reached the deadline with everSawHolder false
|
|
198
|
+
// and surfaced the stale creation error instead of the busy refusal.
|
|
199
|
+
// Ambiguous labels (the Windows EPERM/EACCES family) stay non-sightings
|
|
200
|
+
// — blindness is blindness (#107) — and a create-yes/stat-no filesystem
|
|
201
|
+
// still dies on the strike rule long before the budget.
|
|
202
|
+
if ((err as NodeJS.ErrnoException).code === "EEXIST")
|
|
203
|
+
everSawHolder = true;
|
|
181
204
|
const seen = await probeLock(lockPath);
|
|
182
205
|
if (seen === "absent") {
|
|
183
206
|
if (++absentStrikes >= ABSENT_THROW_STRIKES) throw firstErr;
|
|
@@ -191,18 +214,20 @@ export async function holdFileLock<T>(
|
|
|
191
214
|
}
|
|
192
215
|
if (now() - started >= budgetMs) {
|
|
193
216
|
opts.onEvent?.("timeout", now() - started);
|
|
194
|
-
|
|
217
|
+
// Blindness outranks policy (#107): a wait that never once saw a lock
|
|
218
|
+
// file has no holder to wait for — our own ability to create files is
|
|
219
|
+
// what is broken, and the original error must surface, never a busy
|
|
220
|
+
// refusal and never an unguarded write.
|
|
221
|
+
if (!everSawHolder) throw firstErr;
|
|
222
|
+
if (timeoutPolicy(opts) === "fail") {
|
|
195
223
|
throw new Error(
|
|
196
224
|
`memory store is busy: ${basename(file)} has been locked for ${now() - started}ms — retry`,
|
|
197
225
|
);
|
|
198
226
|
}
|
|
199
|
-
// Proceeding without the lock is the
|
|
200
|
-
//
|
|
201
|
-
//
|
|
202
|
-
// would just mean writing unguarded. A holder we DID see and then lost
|
|
203
|
-
// is ordinary contention, and belongs to the concession (#107 —
|
|
227
|
+
// Proceeding without the lock is the explicit "proceed" opt-in
|
|
228
|
+
// (#216: no longer the default). A holder we DID see and then lost is
|
|
229
|
+
// ordinary contention, and belongs to the opt-in (#107 —
|
|
204
230
|
// `absentStrikes > 0` remembered only the last probe, not the wait).
|
|
205
|
-
if (!everSawHolder) throw firstErr;
|
|
206
231
|
return fn();
|
|
207
232
|
}
|
|
208
233
|
await sleep(backoff);
|
|
@@ -253,7 +278,7 @@ export async function withStoreLock<T>(
|
|
|
253
278
|
// writer that is not going to finish.
|
|
254
279
|
finish();
|
|
255
280
|
opts.onEvent?.("timeout", Date.now() - started);
|
|
256
|
-
if (opts
|
|
281
|
+
if (timeoutPolicy(opts) === "fail") {
|
|
257
282
|
throw new Error(
|
|
258
283
|
`memory store is busy: ${basename(file)} has been locked for ${Date.now() - started}ms — retry`,
|
|
259
284
|
);
|
package/src/tui/panel.tsx
CHANGED
|
@@ -123,7 +123,7 @@ export default Plugin.define({
|
|
|
123
123
|
w.on("error", () => {
|
|
124
124
|
try {
|
|
125
125
|
w.close();
|
|
126
|
-
} catch {}
|
|
126
|
+
} catch {} // already closed; the null-out below is the real cleanup
|
|
127
127
|
if (rootWatcher === w) rootWatcher = null;
|
|
128
128
|
if (dirWatcher === w) dirWatcher = null;
|
|
129
129
|
if (evWatcher === w) evWatcher = null;
|
|
@@ -230,7 +230,7 @@ export default Plugin.define({
|
|
|
230
230
|
for (const w of [rootWatcher, dirWatcher, evWatcher]) {
|
|
231
231
|
try {
|
|
232
232
|
w?.close();
|
|
233
|
-
} catch {}
|
|
233
|
+
} catch {} // unmount: a watcher already closed or broken has nothing left to release
|
|
234
234
|
}
|
|
235
235
|
};
|
|
236
236
|
},
|
package/src/viewer/server.ts
CHANGED
|
@@ -435,7 +435,9 @@ async function blockedRows(): Promise<Row[]> {
|
|
|
435
435
|
}
|
|
436
436
|
|
|
437
437
|
export interface ViewerServer {
|
|
438
|
-
|
|
438
|
+
// No websocket routes, so the WebSocketData generic is undefined — the
|
|
439
|
+
// default Bun.serve infers here. Was `any`, which hid the real shape.
|
|
440
|
+
server: Server<undefined>;
|
|
439
441
|
url: string;
|
|
440
442
|
/** The minted token when exposure requires auth; null on a loopback-only bind. */
|
|
441
443
|
token: string | null;
|