opencode-self-improvement 0.15.1 → 0.15.3

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 CHANGED
@@ -47,6 +47,8 @@ After that, memory is just conversation: ask the agent to remember something and
47
47
  - **Surfaces** — a terminal footer badge and `/memory` panel, `/memory-report` for chat clients, a `memory_status` tool, and a browser admin editor. See [Surfaces](#surfaces).
48
48
  - **Secret redaction** — credential-shaped values in content become `[redacted]`. See [Secret redaction](#secret-redaction).
49
49
 
50
+ Daily memory writes publish a complete replacement file under that lock, so concurrent readers see the previous or new complete file rather than a partially appended record. Appending a row therefore rewrites the day file (in addition to the existing timestamp-uniqueness read). On Windows, a reader handle that prevents replacement can make the write refuse after the replacement retry window; the previous bytes remain intact and the caller can retry once the handle closes. This publication rule applies to daily memory files, not append-only evidence, use, rejection, or audit logs; [#198](https://github.com/abogartz/opencode-self-improvement/issues/198) tracks the broader read boundary.
51
+
50
52
  Memory is stored outside every repository, under `~/.config/opencode/memory` by default (override with `OPENCODE_MEMORY_DIR`). To start over, delete that directory.
51
53
 
52
54
  ## Options
@@ -118,7 +120,7 @@ Rows are stamped with your git origin (an id that survives re-clones and moves b
118
120
 
119
121
  Injection, recall, the frontier block, compaction, `memory_forget` and decay only see the current repo plus global rows, resolved from the calling session's identity at flow entry. A session that reaches a plugin instance is bound to that instance's own workspace on first contact — in a process hosting several workspaces, one session never borrows the repository some other workspace's setup left behind. A session whose repository cannot be resolved at all sees global rows only; "unknown" is never "everything". Writes follow that rule in the stricter direction: a named session with no resolved repository has **no write target**, so `memory_remember`, `memory_update`, `memory_import` and auto-capture refuse it (evidence `write_refused`) and store nothing — the alternatives were stamping your private content into whichever workspace's `setup()` ran last, or publishing it to every project as an unstamped row. A caller that names no session at all (the viewer process, a restore, a script) keeps the process scope, and an explicit `global: true` is a deliberate owner. Evidence lines carry the same stamp, so `memory_evidence` answers from the caller's repo plus global lines; a line a named session wrote while its repository was unresolvable is private to that session, and only an explicitly global (or predating-stamps) line reads as global. Preferences that should follow you everywhere go in with `memory_remember global: true`. Rows written before scoping existed are global, and the viewer (an admin surface over every repo) edits and restores a row with its own repo stamp — the viewer's missing session scope never decides a row's visibility. `memory_merge_review` applies the same rule to its inputs: a session may merge exactly the rows it may read — global rows plus its own repo's, from either seat — and a row id it merely knows is not authority to retire another repo's memory. Upgrading changes nothing.
120
122
 
121
- Gate-authored evidence captures attribution at operation entry: if a session moves repositories while the gate runs, its audit lines remain in the starting repository's partition and can be read with `memory_evidence` from a session bound there. Caller-level init/capture lifecycle events still resolve attribution per event and can land in a different partition; [#199](https://github.com/abogartz/opencode-self-improvement/issues/199) tracks that boundary.
123
+ Gate-authored evidence and its init/capture lifecycle records capture attribution at operation entry: if a session moves repositories while the operation runs, its audit lines remain in the starting repository's partition and can be read with `memory_evidence` from a session bound there. Init start/complete/skip, capture outcomes/refusals, and capture lag share that captured owner. A captured named session with no resolved repository keeps a session-private `sid` label even on lifecycle records that suppress call metadata; otherwise an unstamped line would appear global. Viewer audit attribution and cancellation of in-flight capture are separate boundaries.
122
124
 
123
125
  ## Token cost and caching
124
126
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "opencode-self-improvement",
3
- "version": "0.15.1",
3
+ "version": "0.15.3",
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/evidence.ts CHANGED
@@ -106,7 +106,10 @@ export async function record(
106
106
  const line = formatLine({
107
107
  ev,
108
108
  ts: new Date().toISOString(),
109
- ...(includeContext ? { sid, call } : {}),
109
+ // A captured unresolved owner still needs a privacy label: without sid or
110
+ // repo, evidenceVisibleTo treats a line as legacy/global. Suppress call
111
+ // metadata as requested, but never turn an explicit private owner global.
112
+ ...(includeContext ? { sid, call } : context && !scope && sid && sid !== "?" ? { sid } : {}),
110
113
  ...(scope ? { repo: scope.key, repoPath: scope.path } : {}),
111
114
  ...scrubFields(fields),
112
115
  });
@@ -135,6 +138,7 @@ export async function recordCaptureLag(
135
138
  session: string,
136
139
  lagMs: number | null,
137
140
  outcome: string,
141
+ context?: EvidenceContext,
138
142
  ): Promise<void> {
139
143
  await record(
140
144
  "capture_lag",
@@ -144,6 +148,8 @@ export async function recordCaptureLag(
144
148
  outcome,
145
149
  },
146
150
  false,
151
+ session,
152
+ context,
147
153
  );
148
154
  }
149
155
 
package/src/index.ts CHANGED
@@ -1543,15 +1543,15 @@ const impl = {
1543
1543
  // no-op there). SYNC only: a lookup call here would break the
1544
1544
  // zero-token promise of the capture tests.
1545
1545
  bindSessionProvisional(sid, instanceDir);
1546
+ const captureGate = gateContext(sid);
1546
1547
  // #152: an instance with no workspace cannot say which repository the
1547
1548
  // mined rows belong to, and rows with no owner are exactly what the
1548
1549
  // store refuses. Skip BEFORE the model call — no tokens spent on a
1549
1550
  // capture that cannot be stored — and leave the reason in evidence.
1550
1551
  if (!writeTarget(sid).ok) {
1551
- await record("auto_capture_refused", { session: sid, trigger }, true, sid);
1552
+ await record("auto_capture_refused", { session: sid, trigger }, true, sid, captureGate.evidenceContext);
1552
1553
  return;
1553
1554
  }
1554
- const captureGate = gateContext(sid);
1555
1555
  let transcript = seeded;
1556
1556
  let msgs = seededMsgs;
1557
1557
  if (transcript.length < 200) {
@@ -1595,7 +1595,7 @@ const impl = {
1595
1595
  await record(durable.length ? "auto_capture_partial" : "auto_capture_refused", {
1596
1596
  session: sid, trigger, type: c.type, scope: redactSecrets(c.scope),
1597
1597
  reason: String(err), retired: durable.join(",") || undefined,
1598
- }, false, sid);
1598
+ }, false, sid, captureGate.evidenceContext);
1599
1599
  continue;
1600
1600
  }
1601
1601
  await record(
@@ -1615,9 +1615,11 @@ const impl = {
1615
1615
  audit_error: outcome.evidenceError,
1616
1616
  },
1617
1617
  false,
1618
+ sid,
1619
+ captureGate.evidenceContext,
1618
1620
  );
1619
1621
  }
1620
- await recordCaptureLag(sid, lagMs, candidates.length ? "candidates" : "empty");
1622
+ await recordCaptureLag(sid, lagMs, candidates.length ? "candidates" : "empty", captureGate.evidenceContext);
1621
1623
  }
1622
1624
 
1623
1625
  void (async () => {
package/src/init.ts CHANGED
@@ -232,7 +232,7 @@ export async function runInit(args: InitArgs): Promise<InitSummary> {
232
232
 
233
233
  const prior = await initStamp(scope, args.sessionID, reader);
234
234
  if (prior && !force && prior.head === head) {
235
- await record("init_skip", { scope, head, since: prior.ts }, false);
235
+ await record("init_skip", { scope, head, since: prior.ts }, false, args.sessionID, evidenceContext);
236
236
  return {
237
237
  scope,
238
238
  root,
@@ -247,7 +247,7 @@ export async function runInit(args: InitArgs): Promise<InitSummary> {
247
247
  };
248
248
  }
249
249
 
250
- await record("init_start", { scope, head, force, mode }, false);
250
+ await record("init_start", { scope, head, force, mode }, false, args.sessionID, evidenceContext);
251
251
 
252
252
  const graph = await ensureGraph(root, mode, force);
253
253
  const scripts = await detectScripts(root);
@@ -298,6 +298,8 @@ export async function runInit(args: InitArgs): Promise<InitSummary> {
298
298
  stamp: stampTs ?? "-",
299
299
  },
300
300
  false,
301
+ args.sessionID,
302
+ evidenceContext,
301
303
  );
302
304
 
303
305
  return {
package/src/memory.ts CHANGED
@@ -215,9 +215,9 @@ export interface AppendMemoryInput {
215
215
  // it can collide with are ones this same file received in the same millisecond;
216
216
  // scanning just it keeps the locked section to one read of one file. (A row
217
217
  // hand-placed with today's ts in another day's file is outside this promise.)
218
- async function existingTs(file: string): Promise<Set<string>> {
218
+ function existingTs(text: string): Set<string> {
219
219
  const set = new Set<string>();
220
- for (const line of await readLines(file)) {
220
+ for (const line of text.split("\n")) {
221
221
  const f = parseLine(line);
222
222
  if (f && typeof f.ts === "string") set.add(f.ts);
223
223
  }
@@ -323,28 +323,34 @@ export async function appendMemory(input: AppendMemoryInput): Promise<string> {
323
323
  // two rows with the same identity, and an append that lands inside someone
324
324
  // else's whole-file rewrite is simply not there afterwards.
325
325
  return withStoreLock(file, async () => {
326
- const taken = await existingTs(file);
326
+ const since = await fileIdentity(file);
327
+ let prior = "";
328
+ try { prior = await readFile(file, "utf8"); }
329
+ catch (err) { if ((err as NodeJS.ErrnoException).code !== "ENOENT") throw err; }
330
+ const taken = existingTs(prior);
327
331
  let ts = new Date().toISOString();
328
332
  let guard = 0;
329
333
  while (taken.has(ts) && guard++ < 1000) {
330
334
  ts = new Date(new Date(ts).getTime() + 1).toISOString();
331
335
  }
332
336
  const kw = normalizeKeywords(input.kw);
333
- await appendLog(
334
- file,
335
- formatLine({
336
- ts,
337
- type: input.type,
338
- scope: input.scope,
339
- content,
340
- issue: input.issue,
341
- tags: input.tags?.length ? input.tags.join(",") : undefined,
342
- kw: kw?.join(","),
343
- status: input.status,
344
- repo,
345
- repoPath,
346
- }),
347
- );
337
+ const line = formatLine({
338
+ ts,
339
+ type: input.type,
340
+ scope: input.scope,
341
+ content,
342
+ issue: input.issue,
343
+ tags: input.tags?.length ? input.tags.join(",") : undefined,
344
+ kw: kw?.join(","),
345
+ status: input.status,
346
+ repo,
347
+ repoPath,
348
+ });
349
+ // A lock excludes writers, not readers: an O_APPEND read can end mid-row.
350
+ // Publish the complete day file using the read already needed for IDs.
351
+ // This costs a whole-file write and can refuse on Windows reader handles;
352
+ // the old destination remains intact if publication fails (#198).
353
+ await writeAtomic(file, prior + (prior && !prior.endsWith("\n") ? "\n" : "") + line + "\n", since);
348
354
  return ts;
349
355
  }, LOCK_WRITE);
350
356
  }