opencode-self-improvement 0.14.12 → 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 +3 -3
- package/package.json +1 -1
- package/src/evidence.ts +32 -1
- package/src/index.ts +130 -44
- package/src/schema.ts +4 -1
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, 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. 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, 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.
|
|
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.
|
|
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,7 +1,8 @@
|
|
|
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 {
|
|
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";
|
|
@@ -11,6 +12,36 @@ import { redactSecrets } from "./secrets.ts";
|
|
|
11
12
|
|
|
12
13
|
export type EvidenceEvent = string;
|
|
13
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
|
+
|
|
14
45
|
// Credential scrub at the evidence WRITE boundary. Evidence fields routinely
|
|
15
46
|
// carry caller-authored prose (gate reasons, block reasons, review notes) and
|
|
16
47
|
// tool-derived summaries; a recognized credential must not persist in the
|
package/src/index.ts
CHANGED
|
@@ -12,7 +12,7 @@
|
|
|
12
12
|
// helper modules.
|
|
13
13
|
import type { Cleanup, Plugin } from "@opencode/plugin/promise/plugin";
|
|
14
14
|
import { basename, join } from "node:path";
|
|
15
|
-
import {
|
|
15
|
+
import { frontierBudget, injectBudget, memoryRoot } from "./config.ts";
|
|
16
16
|
import { STATUSES, TYPES } from "./types.ts";
|
|
17
17
|
import {
|
|
18
18
|
clearSuperseded,
|
|
@@ -36,7 +36,7 @@ import { pruneMemory } from "./prune.ts";
|
|
|
36
36
|
import { exportMemories, findStaleOpen, importMemories } from "./portable.ts";
|
|
37
37
|
import { listSnapshots, restoreSnapshot } from "./undo.ts";
|
|
38
38
|
import { SESSION_CAP, SessionLru } from "./sessions.ts";
|
|
39
|
-
import { record, recordCaptureLag } from "./evidence.ts";
|
|
39
|
+
import { evidenceFileFor, record, recordCaptureLag } from "./evidence.ts";
|
|
40
40
|
import { proposeConsolidations, renderProposals } from "./consolidate.ts";
|
|
41
41
|
import { readReads } from "./hits.ts";
|
|
42
42
|
import {
|
|
@@ -717,7 +717,16 @@ const impl = {
|
|
|
717
717
|
async execute(args, context): Promise<{ content: string }> {
|
|
718
718
|
const { sid } = toolIds(context);
|
|
719
719
|
const reader = readerFromSid(sid);
|
|
720
|
-
|
|
720
|
+
// #130: the ONE path the schema-validated date can resolve to —
|
|
721
|
+
// a real calendar day inside the evidence dir, never a traversal
|
|
722
|
+
// into the raw store or the filesystem beyond it.
|
|
723
|
+
const file = evidenceFileFor(args.date);
|
|
724
|
+
if (!file) {
|
|
725
|
+
return {
|
|
726
|
+
content:
|
|
727
|
+
"memory_evidence blocked: date must be a real YYYY-MM-DD calendar date — nothing was read.",
|
|
728
|
+
};
|
|
729
|
+
}
|
|
721
730
|
let lines = await readLines(file);
|
|
722
731
|
// Data partitions too (#131's ownership rule, applied to evidence):
|
|
723
732
|
// a line stamped to another repository is not this session's data,
|
|
@@ -740,54 +749,126 @@ const impl = {
|
|
|
740
749
|
editor.add(validated(MergeReviewArgs, {
|
|
741
750
|
name: "memory_merge_review",
|
|
742
751
|
description:
|
|
743
|
-
"Resolve an open merge/review gate non-destructively: mark the loser as superseded_by the survivor, and clear any supersession the survivor itself carries so the canonical row stays recallable. Both rows stay active data (the loser is recoverable via memory_undo); nothing is deleted. Fails closed (no partial apply) when the reason or the survivor id is missing, the survivor id names no row in the store,
|
|
752
|
+
"Resolve an open merge/review gate non-destructively: mark the loser as superseded_by the survivor, and clear any supersession the survivor itself carries so the canonical row stays recallable. Both rows stay active data (the loser is recoverable via memory_undo); nothing is deleted. A session may merge exactly the rows it may read: global rows are mergeable from anywhere, but a row belonging to another repository is refused in either seat. Fails closed (no partial apply) when the reason or the survivor id is missing, the survivor id names no row in the store, the loser is already superseded or is the survivor itself, or either seat names a foreign repository's row.",
|
|
744
753
|
options: direct,
|
|
745
|
-
async execute(args): Promise<{ content: string }> {
|
|
754
|
+
async execute(args, context): Promise<{ content: string }> {
|
|
755
|
+
const { sid } = toolIds(context);
|
|
746
756
|
if (!args.loser || !args.survivor || !args.reason) {
|
|
747
757
|
return { content: "merge_review blocked: loser, survivor, and reason are all required (fail-closed)." };
|
|
748
758
|
}
|
|
749
|
-
// Probed: marking with a survivor id that names no row retired the
|
|
750
|
-
// loser toward a pointer to nothing (the scope ended with zero
|
|
751
|
-
// active rows) while the response declared it canonical. Validate
|
|
752
|
-
// BEFORE touching the loser — a resolution must never retire real
|
|
753
|
-
// data for a phantom. (Same-row input would mark and then revive
|
|
754
|
-
// the same row: a silent no-op that reports full success.)
|
|
755
759
|
if (args.loser === args.survivor) {
|
|
760
|
+
// (Same-row input would mark and then revive the same row: a
|
|
761
|
+
// silent no-op that reports full success.)
|
|
756
762
|
return { content: "merge_review blocked: loser and survivor are the same row — nothing to resolve. No evidence written." };
|
|
757
763
|
}
|
|
758
|
-
|
|
759
|
-
|
|
760
|
-
|
|
761
|
-
|
|
762
|
-
|
|
763
|
-
|
|
764
|
-
|
|
765
|
-
|
|
766
|
-
|
|
767
|
-
|
|
768
|
-
|
|
769
|
-
|
|
764
|
+
// A row id is a pointer, not authority (#131): resolving and
|
|
765
|
+
// authorizing BOTH seats happens against the caller's Reader —
|
|
766
|
+
// captured at entry, never re-read after an await (#127) — and the
|
|
767
|
+
// whole resolve/check/mutate runs under the same update-order lock
|
|
768
|
+
// memory_update serializes on (#125), so the authorization is
|
|
769
|
+
// revalidated under the mutation lock instead of against a snapshot
|
|
770
|
+
// a concurrent update could have replaced. Acquisition order is
|
|
771
|
+
// always update-order then store-file locks, never the reverse, so
|
|
772
|
+
// this cannot deadlock against a plain writer; on timeout it fails
|
|
773
|
+
// closed with nothing written.
|
|
774
|
+
const reader = readerFromSid(sid);
|
|
775
|
+
// Where a throw lands decides what is true to say: before the
|
|
776
|
+
// mutation nothing was written (the documented fail-closed
|
|
777
|
+
// contract); AFTER markSuperseded the loser IS retired on disk and
|
|
778
|
+
// claiming "nothing was done" is a lie (review probe 5).
|
|
779
|
+
let mutated = false;
|
|
780
|
+
try {
|
|
781
|
+
return await withStoreLock(
|
|
782
|
+
join(memoryRoot(), "update-order"),
|
|
783
|
+
async () => {
|
|
784
|
+
const all = await loadAll();
|
|
785
|
+
const survivorRow = all.find((m) => m.ts === args.survivor);
|
|
786
|
+
// Probed: marking with a survivor id that names no row retired
|
|
787
|
+
// the loser toward a pointer to nothing (the scope ended with
|
|
788
|
+
// zero active rows) while the response declared it canonical.
|
|
789
|
+
// Validate BEFORE touching the loser — a resolution must never
|
|
790
|
+
// retire real data for a phantom.
|
|
791
|
+
if (!survivorRow) {
|
|
792
|
+
return { content: `merge_review blocked: survivor ${args.survivor} does not exist in the store — nothing to resolve. No evidence written.` };
|
|
793
|
+
}
|
|
794
|
+
const loserRow = all.find((m) => m.ts === args.loser);
|
|
795
|
+
// Visibility is the authorization contract (#131): a session
|
|
796
|
+
// may merge exactly the rows it may read. Global and legacy
|
|
797
|
+
// unstamped rows are visible everywhere and therefore
|
|
798
|
+
// mergeable from anywhere — stated here, not granted
|
|
799
|
+
// implicitly by store-wide reach. A foreign row in EITHER
|
|
800
|
+
// seat — including an attempt to revive another repository's
|
|
801
|
+
// superseded survivor — is refused before any mutation.
|
|
802
|
+
if (loserRow && !isVisibleTo(loserRow, reader)) {
|
|
803
|
+
return { content: "merge_review blocked: the loser belongs to another repository — this session may not retire it. Nothing was done. No evidence written." };
|
|
804
|
+
}
|
|
805
|
+
if (!isVisibleTo(survivorRow, reader)) {
|
|
806
|
+
return { content: "merge_review blocked: the survivor belongs to another repository — this session may not promote or revive it. Nothing was done. No evidence written." };
|
|
807
|
+
}
|
|
808
|
+
const ok = await markSuperseded(args.loser, {
|
|
809
|
+
superseded_by: args.survivor,
|
|
810
|
+
reason: args.reason,
|
|
811
|
+
symbol: args.loser,
|
|
812
|
+
from: args.loser,
|
|
813
|
+
to: args.survivor,
|
|
814
|
+
});
|
|
815
|
+
if (!ok) {
|
|
816
|
+
return { content: "merge_review: loser not found or already superseded — nothing to resolve. No evidence written." };
|
|
817
|
+
}
|
|
818
|
+
mutated = true;
|
|
819
|
+
// The survivor may itself have been superseded earlier (e.g. by
|
|
820
|
+
// a row this very call just made the loser). Declaring it
|
|
821
|
+
// canonical has to make it recallable, so clear its own marker.
|
|
822
|
+
const revived = await clearSuperseded(args.survivor);
|
|
823
|
+
// The response has always claimed "Evidence recorded" — now it
|
|
824
|
+
// is true, and it names the session the merge ran FOR (#121's
|
|
825
|
+
// residue on this line). The host tool_result hook covers
|
|
826
|
+
// grep/read/edit/shell only, so a merge used to leave zero
|
|
827
|
+
// trace: which reviewer decision, on which reason, reviving
|
|
828
|
+
// what — unauditable.
|
|
829
|
+
await record(
|
|
830
|
+
"merge_resolved",
|
|
831
|
+
{
|
|
832
|
+
loser: args.loser,
|
|
833
|
+
survivor: args.survivor,
|
|
834
|
+
revived,
|
|
835
|
+
reason: args.reason,
|
|
836
|
+
},
|
|
837
|
+
true,
|
|
838
|
+
sid,
|
|
839
|
+
);
|
|
840
|
+
return {
|
|
841
|
+
content:
|
|
842
|
+
`Resolved merge: ${args.survivor} is canonical; ${args.loser} superseded (recoverable via memory_undo). ` +
|
|
843
|
+
(revived ? `Survivor's own supersession cleared, it is active again. ` : "") +
|
|
844
|
+
`Evidence recorded for reason='${args.reason}'.`,
|
|
845
|
+
};
|
|
846
|
+
},
|
|
847
|
+
{
|
|
848
|
+
onTimeout: "fail",
|
|
849
|
+
onEvent: (event, waitedMs) => {
|
|
850
|
+
void record("store_lock", { event, waited_ms: waitedMs, op: "merge" });
|
|
851
|
+
},
|
|
852
|
+
},
|
|
853
|
+
);
|
|
854
|
+
} catch (err) {
|
|
855
|
+
// Before mutation this is the fail-closed lock contract: nothing
|
|
856
|
+
// written. After markSuperseded succeeded the loser IS retired —
|
|
857
|
+
// the honest report names the completed mutation and the failed
|
|
858
|
+
// follow-up (evidence/revive), not a blanket "nothing was done".
|
|
859
|
+
if (!mutated) {
|
|
860
|
+
return {
|
|
861
|
+
content: "merge_review blocked: the store was busy past the lock budget — nothing was done. Retry.",
|
|
862
|
+
};
|
|
863
|
+
}
|
|
864
|
+
const why = err instanceof Error ? err.message : String(err);
|
|
865
|
+
return {
|
|
866
|
+
content:
|
|
867
|
+
`merge_review PARTIAL: ${args.loser} IS retired on disk (superseded_by ${args.survivor}; ` +
|
|
868
|
+
`recoverable via memory_undo) but a post-mutation step failed: ${why}. ` +
|
|
869
|
+
`The evidence line may be missing; re-running reports the loser already superseded.`,
|
|
870
|
+
};
|
|
770
871
|
}
|
|
771
|
-
// The survivor may itself have been superseded earlier (e.g. by a row
|
|
772
|
-
// this very call just made the loser). Declaring it canonical has to
|
|
773
|
-
// make it recallable, so clear its own marker too.
|
|
774
|
-
const revived = await clearSuperseded(args.survivor);
|
|
775
|
-
// The response has always claimed "Evidence recorded" — now it is
|
|
776
|
-
// true. The host tool_result hook covers grep/read/edit/shell only,
|
|
777
|
-
// so a merge used to leave zero trace: which reviewer decision, on
|
|
778
|
-
// which reason, reviving what — unauditable.
|
|
779
|
-
await record("merge_resolved", {
|
|
780
|
-
loser: args.loser,
|
|
781
|
-
survivor: args.survivor,
|
|
782
|
-
revived,
|
|
783
|
-
reason: args.reason,
|
|
784
|
-
});
|
|
785
|
-
return {
|
|
786
|
-
content:
|
|
787
|
-
`Resolved merge: ${args.survivor} is canonical; ${args.loser} superseded (recoverable via memory_undo). ` +
|
|
788
|
-
(revived ? `Survivor's own supersession cleared, it is active again. ` : "") +
|
|
789
|
-
`Evidence recorded for reason='${args.reason}'.`,
|
|
790
|
-
};
|
|
791
872
|
},
|
|
792
873
|
}));
|
|
793
874
|
|
|
@@ -1373,7 +1454,12 @@ const impl = {
|
|
|
1373
1454
|
const lagMs = lagSince(msgs);
|
|
1374
1455
|
const out = await generateApi.text({
|
|
1375
1456
|
model: modelRef,
|
|
1376
|
-
|
|
1457
|
+
// Redact the COMPLETE transcript, THEN apply the character budget
|
|
1458
|
+
// (#132). Cropping first can start the window INSIDE a credential:
|
|
1459
|
+
// a PEM body whose BEGIN marker fell off, or a token whose prefix
|
|
1460
|
+
// fell off, matches no pattern — buildCapturePrompt's own scrub
|
|
1461
|
+
// (kept, defense in depth) cannot recognize a fragment.
|
|
1462
|
+
prompt: buildCapturePrompt(redactSecrets(transcript).slice(-8000), captureMax),
|
|
1377
1463
|
});
|
|
1378
1464
|
const text = typeof out === "string" ? out : out?.text ?? "";
|
|
1379
1465
|
const candidates = parseCandidates(text, captureMax);
|
package/src/schema.ts
CHANGED
|
@@ -121,7 +121,10 @@ export const UndoArgs = z.object({
|
|
|
121
121
|
});
|
|
122
122
|
|
|
123
123
|
export const EvidenceArgs = z.object({
|
|
124
|
-
date: z
|
|
124
|
+
date: z
|
|
125
|
+
.string()
|
|
126
|
+
.regex(/^\d{4}-\d{2}-\d{2}$/, "must be a YYYY-MM-DD calendar date (paths are refused)")
|
|
127
|
+
.optional(),
|
|
125
128
|
ev: z.string().optional(),
|
|
126
129
|
limit: z.coerce.number().optional(),
|
|
127
130
|
});
|