opencode-self-improvement 0.14.11 → 0.14.13

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
@@ -34,7 +34,7 @@ After that, memory is just conversation: ask the agent to remember something and
34
34
 
35
35
  - **`memory_*` tools** — `memory_init`, `memory_remember`, `memory_recall`, `memory_update`, `memory_forget`, `memory_list`, `memory_undo`, `memory_status`, `memory_evidence`, `memory_export`, `memory_import`, `memory_decay`, `memory_consolidate`, `memory_merge_review`.
36
36
  - **`/repo-init`** — per-repo setup: code graph index plus build/test commands, keyed to the git head.
37
- - **Write gates** — code references are verified against your actual repo, near-duplicates are collapsed, contradictions with superseded memories are rejected. Blocked writes are logged with a reason in `memory_evidence`.
37
+ - **Write gates** — code references are verified against your actual repo, near-duplicates are collapsed, contradictions with superseded memories are rejected. Blocked writes are logged with a reason in `memory_evidence`, which reads one real calendar day inside `evidence/` at a time — its `date` is a date, never a path.
38
38
  - **Memory-aware compaction** — durable memories are handed to the compaction summarizer, so a long session keeps its facts.
39
39
  - **Auto-capture (opt-in)** — on the idle and compaction triggers, one cheap model pass per trigger proposes candidates, which face the same write gates; a 5-minute cooldown per session and trigger bounds the spend ([per-trigger numbers](bench/capture-trigger-results.md)). Off by default.
40
40
  - **Repo scoping** — rows belong to the repo that wrote them; project A's facts never surface in project B.
@@ -95,7 +95,7 @@ Nothing is deleted: `memory_update` supersedes the previous row, `memory_forget`
95
95
 
96
96
  Rows are stamped with your git origin (an id that survives re-clones and moves between machines) or, without an origin, a hash of the normalized directory path. `repoPath` keeps the human-readable path, so rows written before hashing keep matching.
97
97
 
98
- Injection, recall, the frontier block, compaction, `memory_forget` and decay only see the current repo plus global rows. Preferences that should follow you everywhere go in with `memory_remember global: true`. Rows written before scoping existed, and rows restored through the viewer, are global — upgrading changes nothing.
98
+ 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". 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.
99
99
 
100
100
  ## Token cost and caching
101
101
 
@@ -185,7 +185,7 @@ On the eval dataset the pass takes 200 rows to 52 with **R@3 52 → 53 and R@1 5
185
185
 
186
186
  ## Secret redaction
187
187
 
188
- One best-effort credential rule set (`src/secrets.ts`) runs over the auto-capture prompt before it leaves the plugin, at the write gate before content is hashed or analysed, and again in the final write choke point used by gated writes and the viewer's edit and restore paths.
188
+ One best-effort credential rule set (`src/secrets.ts`) runs over the auto-capture prompt before it leaves the plugin — redacting the complete transcript before the character budget crops it, so a credential cut in half by the window still matches its pattern — at the write gate before content is hashed or analysed, again in the final write choke point used by gated writes and the viewer's edit and restore paths, and at the durable audit boundaries — every evidence line, every supersede field written into a retired row, and every deletion-audit reason — so a recognized credential cannot persist in `evidence/` or `deletions.logfmt` or a tombstoned row regardless of which path carried it.
189
189
 
190
190
  Covered: OpenAI `sk-`, GitHub `ghp_` / `gho_` / `github_pat_`, Slack `xoxb-` / `xoxp-`, AWS `AKIA`, Google `AIza`, bearer tokens containing digits, PEM private-key blocks, and high-entropy values assigned to names ending in `_KEY`, `_TOKEN`, `_SECRET` or `_PASSWORD` (plus `password`).
191
191
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "opencode-self-improvement",
3
- "version": "0.14.11",
3
+ "version": "0.14.13",
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
@@ -1,14 +1,60 @@
1
1
  // Evidence log writer. One logfmt line per event, appended in hook order to
2
2
  // ~/.config/opencode/memory/evidence/<date>.logfmt. Evidence is DATA: never
3
3
  // injected into chat, and stored outside every repo.
4
- import { join } from "node:path";
4
+ import { existsSync, realpathSync } from "node:fs";
5
+ import { dirname, join, resolve } from "node:path";
5
6
  import { createHash } from "node:crypto";
6
7
  import { dateStr, evidenceDir } from "./config.ts";
7
8
  import { appendLog, formatLine } from "./logfmt.ts";
9
+ import { repoScope, sessionScope } from "./repokey.ts";
8
10
  import { getCurrent } from "./state.ts";
11
+ import { redactSecrets } from "./secrets.ts";
9
12
 
10
13
  export type EvidenceEvent = string;
11
14
 
15
+ // The ONLY path memory_evidence may read (#130): a real calendar date in
16
+ // YYYY-MM-DD form, resolved INSIDE the evidence directory. The schema layer
17
+ // already refuses non-date strings at the boundary; this is the second door —
18
+ // impossible dates (2026-02-30, which Date would silently roll over) and
19
+ // symlinked day files must not hand out files outside the evidence dir.
20
+ // Returns null when the read must be refused; the forced .logfmt suffix is
21
+ // the primitive's residual bound either way.
22
+ export function evidenceFileFor(date?: string): string | null {
23
+ const d = date ?? dateStr();
24
+ const m = /^(\d{4})-(\d{2})-(\d{2})$/.exec(d);
25
+ if (!m) return null;
26
+ const [y, mo, day] = [Number(m[1]), Number(m[2]), Number(m[3])];
27
+ const probe = new Date(Date.UTC(y, mo - 1, day));
28
+ if (probe.getUTCFullYear() !== y || probe.getUTCMonth() !== mo - 1 || probe.getUTCDate() !== day) {
29
+ return null;
30
+ }
31
+ const dir = resolve(evidenceDir());
32
+ const file = resolve(dir, `${d}.logfmt`);
33
+ if (dirname(file) !== dir) return null; // containment, defense in depth
34
+ if (existsSync(file)) {
35
+ // A day file symlinked out of the store still has to land inside it.
36
+ try {
37
+ if (realpathSync(file) !== join(realpathSync(dir), `${d}.logfmt`)) return null;
38
+ } catch {
39
+ return null; // an unreadable link is not a file we will follow
40
+ }
41
+ }
42
+ return file;
43
+ }
44
+
45
+ // Credential scrub at the evidence WRITE boundary. Evidence fields routinely
46
+ // carry caller-authored prose (gate reasons, block reasons, review notes) and
47
+ // tool-derived summaries; a recognized credential must not persist in the
48
+ // durable log no matter which line carried it (#128). redactSecrets is a
49
+ // no-op on ordinary text (ids, hashes, paths, counts).
50
+ function scrubFields(fields: Record<string, unknown>): Record<string, unknown> {
51
+ const out: Record<string, unknown> = {};
52
+ for (const [key, value] of Object.entries(fields)) {
53
+ out[key] = typeof value === "string" ? redactSecrets(value) : value;
54
+ }
55
+ return out;
56
+ }
57
+
12
58
  export async function record(
13
59
  ev: EvidenceEvent,
14
60
  fields: Record<string, unknown> = {},
@@ -25,11 +71,26 @@ export async function record(
25
71
  // this is exactly the old ambient read.
26
72
  const sid = sessionID ?? cur.sid;
27
73
  const call = sessionID !== undefined && sessionID !== cur.sid ? undefined : cur.call;
74
+ // Read-side partitioning of the shared log (#131's rule, applied to
75
+ // evidence; the re-review closed the last two gaps in it). A NAMED session
76
+ // is stamped from its OWN resolved scope only — the module scope is never
77
+ // the fallback here: in a process that loaded several plugin instances it
78
+ // belongs to whoever set up LAST, and A's evidence must not live in B's
79
+ // repository. A named session whose repository is unresolvable writes an
80
+ // UNSTAMPED line that stays private to that session (memory.ts
81
+ // evidenceVisibleTo pairs with this choice): "unknown" is never
82
+ // "everything" (#127), and it is never somebody else's repo either. Only a
83
+ // genuinely session-less line — out-of-plugin maintenance, viewer, CLI —
84
+ // takes the process scope, and unstamped session-less lines (legacy, or a
85
+ // scope-less process) keep their historical global reading.
86
+ const named = typeof sid === "string" && sid !== "" && sid !== "?";
87
+ const scope = named ? sessionScope(sid) : repoScope();
28
88
  const line = formatLine({
29
89
  ev,
30
90
  ts: new Date().toISOString(),
31
91
  ...(includeContext ? { sid, call } : {}),
32
- ...fields,
92
+ ...(scope ? { repo: scope.key, repoPath: scope.path } : {}),
93
+ ...scrubFields(fields),
33
94
  });
34
95
  await appendLog(join(evidenceDir(), `${dateStr()}.logfmt`), line);
35
96
  }
package/src/gates.ts CHANGED
@@ -17,6 +17,7 @@ import {
17
17
  import { chainId, contentHash, record, recordWriteBlocked } from "./evidence.ts";
18
18
  import { flattenMemoryText } from "./sanitize.ts";
19
19
  import { containsSecret, redactSecrets } from "./secrets.ts";
20
+ import { readerForSession } from "./memory.ts";
20
21
  import {
21
22
  displayCall,
22
23
  extractCallForms,
@@ -328,7 +329,18 @@ export async function runWriteGate(
328
329
  ch,
329
330
  });
330
331
 
331
- const scopeMems = candidate.scope ? await loadScope(candidate.scope) : [];
332
+ const scopeMems = candidate.scope
333
+ ? await loadScope(
334
+ candidate.scope,
335
+ // Dedup/stale reads partition on the WRITE's session, captured at
336
+ // flow entry — not the ambient current after this await (#127). An
337
+ // unknown "?" (or absent) caller is the readerFromSid AMBIENT case,
338
+ // exactly as before: readerForSession is for named sessions only.
339
+ ctx.sessionID !== undefined && ctx.sessionID !== "?"
340
+ ? readerForSession(ctx.sessionID)
341
+ : undefined,
342
+ )
343
+ : [];
332
344
  // One tree index per write, shared by gate1 and every gate2 stale scan.
333
345
  const tree = memoTree(ctx.liveRoot);
334
346