opencode-self-improvement 0.14.26 → 0.14.27
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 +2 -0
- package/package.json +1 -1
- package/src/evidence.ts +29 -9
- package/src/gates.ts +6 -9
- package/src/index.ts +4 -2
- package/src/init.ts +3 -1
package/README.md
CHANGED
|
@@ -117,6 +117,8 @@ Rows are stamped with your git origin (an id that survives re-clones and moves b
|
|
|
117
117
|
|
|
118
118
|
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.
|
|
119
119
|
|
|
120
|
+
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.
|
|
121
|
+
|
|
120
122
|
## Token cost and caching
|
|
121
123
|
|
|
122
124
|
- **Section-frozen injection.** The whole memory section — standing digest, open-thread frontier, relevance block — is computed once per epoch and delivered byte-identically until something the model actually needs changes. The epoch's authority is the **rendered bytes**, not the store fingerprint: a promoted row that changes nothing visible costs no cache bust.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "opencode-self-improvement",
|
|
3
|
-
"version": "0.14.
|
|
3
|
+
"version": "0.14.27",
|
|
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
|
@@ -6,7 +6,7 @@ import { dirname, join, resolve } from "node:path";
|
|
|
6
6
|
import { createHash } from "node:crypto";
|
|
7
7
|
import { dateStr, evidenceDir } from "./config.ts";
|
|
8
8
|
import { appendLog, formatLine } from "./logfmt.ts";
|
|
9
|
-
import { repoScope, sessionScope } from "./repokey.ts";
|
|
9
|
+
import { repoScope, sessionScope, type RepoScope } from "./repokey.ts";
|
|
10
10
|
import { getCurrent } from "./state.ts";
|
|
11
11
|
import { redactSecrets } from "./secrets.ts";
|
|
12
12
|
|
|
@@ -55,20 +55,27 @@ function scrubFields(fields: Record<string, unknown>): Record<string, unknown> {
|
|
|
55
55
|
return out;
|
|
56
56
|
}
|
|
57
57
|
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
58
|
+
// Immutable operation attribution, captured before the caller's first await.
|
|
59
|
+
// Null scope is significant: a named-unresolved session must stay private.
|
|
60
|
+
export interface EvidenceContext {
|
|
61
|
+
readonly sid: string;
|
|
62
|
+
readonly call: string | undefined;
|
|
63
|
+
readonly scope: Readonly<RepoScope> | null;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
export function captureEvidenceContext(sessionID?: string): EvidenceContext {
|
|
64
67
|
const cur = getCurrent();
|
|
65
68
|
// An explicitly threaded session outranks the ambient one: gate-authored
|
|
66
69
|
// lines must name the session the gate runs FOR, not whichever setCurrent
|
|
67
70
|
// fired last during the gate's own awaits (#118 review note 1 — the rows
|
|
68
71
|
// were fixed in #118, these lines were the residue). When the two disagree,
|
|
69
72
|
// the ambient call belongs to the OTHER session's flow, so it is dropped
|
|
70
|
-
// rather than borrowed. With sessionID undefined
|
|
71
|
-
//
|
|
73
|
+
// rather than borrowed. With sessionID undefined this captures the ambient
|
|
74
|
+
// session and call at entry by design (maintenance/direct callers). An
|
|
75
|
+
// explicit "?" keeps the ambient call only when cur.sid is also "?";
|
|
76
|
+
// otherwise it stays absent, even if a later setCurrent supplies a call.
|
|
77
|
+
// Normal tool hooks setCurrent before execute; this snapshot never guesses
|
|
78
|
+
// a missing operation call from a later hook. See #121 for identity context.
|
|
72
79
|
const sid = sessionID ?? cur.sid;
|
|
73
80
|
const call = sessionID !== undefined && sessionID !== cur.sid ? undefined : cur.call;
|
|
74
81
|
// Read-side partitioning of the shared log (#131's rule, applied to
|
|
@@ -85,6 +92,17 @@ export async function record(
|
|
|
85
92
|
// scope-less process) keep their historical global reading.
|
|
86
93
|
const named = typeof sid === "string" && sid !== "" && sid !== "?";
|
|
87
94
|
const scope = named ? sessionScope(sid) : repoScope();
|
|
95
|
+
return Object.freeze({ sid, call, scope: scope ? Object.freeze({ ...scope }) : null });
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
export async function record(
|
|
99
|
+
ev: EvidenceEvent,
|
|
100
|
+
fields: Record<string, unknown> = {},
|
|
101
|
+
includeContext = true,
|
|
102
|
+
sessionID?: string,
|
|
103
|
+
context?: EvidenceContext,
|
|
104
|
+
): Promise<void> {
|
|
105
|
+
const { sid, call, scope } = context ?? captureEvidenceContext(sessionID);
|
|
88
106
|
const line = formatLine({
|
|
89
107
|
ev,
|
|
90
108
|
ts: new Date().toISOString(),
|
|
@@ -135,6 +153,7 @@ export async function recordWriteBlocked(
|
|
|
135
153
|
flags: string[],
|
|
136
154
|
chain?: string,
|
|
137
155
|
sessionID?: string,
|
|
156
|
+
context?: EvidenceContext,
|
|
138
157
|
): Promise<void> {
|
|
139
158
|
await record(
|
|
140
159
|
"write_blocked",
|
|
@@ -146,5 +165,6 @@ export async function recordWriteBlocked(
|
|
|
146
165
|
},
|
|
147
166
|
true,
|
|
148
167
|
sessionID,
|
|
168
|
+
context,
|
|
149
169
|
);
|
|
150
170
|
}
|
package/src/gates.ts
CHANGED
|
@@ -13,7 +13,7 @@ import {
|
|
|
13
13
|
type Memory,
|
|
14
14
|
type SupersedeFields,
|
|
15
15
|
} from "./memory.ts";
|
|
16
|
-
import { chainId, contentHash, record, recordWriteBlocked } from "./evidence.ts";
|
|
16
|
+
import { captureEvidenceContext, type EvidenceContext, chainId, contentHash, record, recordWriteBlocked } from "./evidence.ts";
|
|
17
17
|
import { getCurrent, noteAuthored } from "./state.ts";
|
|
18
18
|
import { MAX_WRITE_EVIDENCE_REFS } from "./triggers.ts";
|
|
19
19
|
import { flattenMemoryText } from "./sanitize.ts";
|
|
@@ -77,6 +77,7 @@ export interface GateContext {
|
|
|
77
77
|
// absent/"?" callers capture ambient authority at entry (not after awaits).
|
|
78
78
|
reader?: Reader;
|
|
79
79
|
writeAt?: WriteTarget;
|
|
80
|
+
evidenceContext?: EvidenceContext;
|
|
80
81
|
evidenceCalls: string[];
|
|
81
82
|
// Total before the telemetry window was selected. Legacy/direct callers
|
|
82
83
|
// may still supply their complete list; the writer bounds that too.
|
|
@@ -249,17 +250,13 @@ export async function runWriteGate(
|
|
|
249
250
|
): Promise<GateOutcome> {
|
|
250
251
|
const reader = ctx.reader ?? readerFromSid(ctx.sessionID);
|
|
251
252
|
const writeAt = ctx.writeAt ?? writeTarget(ctx.sessionID ?? getCurrent().sid);
|
|
253
|
+
const evidenceContext = ctx.evidenceContext ?? captureEvidenceContext(ctx.sessionID);
|
|
252
254
|
const chain = chainId();
|
|
253
|
-
//
|
|
254
|
-
// locked append), and another session's dispatch can move the ambient
|
|
255
|
-
// current mid-gate — ambient-read lines would then name the wrong session
|
|
256
|
-
// (#118 review note 1; the rows were fixed in #118, these were the
|
|
257
|
-
// residue). Where ctx.sessionID is unset (tool paths — issue #121) record()
|
|
258
|
-
// keeps the ambient read, exactly as before.
|
|
255
|
+
// Keep all gate audit lines with entry-time attribution, including refusals.
|
|
259
256
|
const rec = (ev: string, fields: Record<string, unknown> = {}, includeContext = true) =>
|
|
260
|
-
record(ev, fields, includeContext, ctx.sessionID);
|
|
257
|
+
record(ev, fields, includeContext, ctx.sessionID, evidenceContext);
|
|
261
258
|
const recBlocked = (gate: number, reason: string, flags: string[], chain?: string) =>
|
|
262
|
-
recordWriteBlocked(gate, reason, flags, chain, ctx.sessionID);
|
|
259
|
+
recordWriteBlocked(gate, reason, flags, chain, ctx.sessionID, evidenceContext);
|
|
263
260
|
|
|
264
261
|
// Size/type floor BEFORE any scanning: gate analysis regexes
|
|
265
262
|
// over megabyte content backtrack super-linearly and freeze the service
|
package/src/index.ts
CHANGED
|
@@ -31,7 +31,7 @@ import { pruneMemory } from "./prune.ts";
|
|
|
31
31
|
import { exportMemories, findStaleOpen, importMemories } from "./portable.ts";
|
|
32
32
|
import { listSnapshots, restoreSnapshot } from "./undo.ts";
|
|
33
33
|
import { SESSION_CAP, SessionLru } from "./sessions.ts";
|
|
34
|
-
import { evidenceFileFor, record, recordCaptureLag } from "./evidence.ts";
|
|
34
|
+
import { captureEvidenceContext, evidenceFileFor, record, recordCaptureLag } from "./evidence.ts";
|
|
35
35
|
import { proposeConsolidations, renderProposals } from "./consolidate.ts";
|
|
36
36
|
import { readReads } from "./hits.ts";
|
|
37
37
|
import {
|
|
@@ -298,6 +298,7 @@ const impl = {
|
|
|
298
298
|
sessionID: sid,
|
|
299
299
|
reader: readerFromSid(sid),
|
|
300
300
|
writeAt: writeTarget(bound),
|
|
301
|
+
evidenceContext: captureEvidenceContext(sid),
|
|
301
302
|
// NOTE (re-review): this one lookup is intentionally NON-firm — a
|
|
302
303
|
// provisional binding may supply the gate's verification TREE. The
|
|
303
304
|
// tree is where a referenced file is checked to exist, not who the
|
|
@@ -554,6 +555,7 @@ const impl = {
|
|
|
554
555
|
const ownerless = ownerlessWriter(sid);
|
|
555
556
|
if (ownerless) return await refuseOwnerlessWrite(ownerless, "update");
|
|
556
557
|
const reader = readerFromSid(sid);
|
|
558
|
+
const updateGate = gateContext(sid);
|
|
557
559
|
// The whole update — resolve, gate, supersede — runs under one
|
|
558
560
|
// UPDATE-ORDER lock. Without it, two concurrent updates that both
|
|
559
561
|
// resolved the same still-active target both promoted and both
|
|
@@ -689,7 +691,7 @@ const impl = {
|
|
|
689
691
|
repo: requested.repo,
|
|
690
692
|
repoPath: target.repo ? target.repoPath : undefined,
|
|
691
693
|
},
|
|
692
|
-
{ ...
|
|
694
|
+
{ ...updateGate, reader, supersedesTs: target.ts, durable: gateDurable },
|
|
693
695
|
);
|
|
694
696
|
if (outcome.action === "promoted" && outcome.ts && target) {
|
|
695
697
|
mutated = true;
|
package/src/init.ts
CHANGED
|
@@ -10,7 +10,7 @@ import { existsSync } from "node:fs";
|
|
|
10
10
|
import { cbmBin } from "./config.ts";
|
|
11
11
|
import { isVisibleTo, loadAll, markSuperseded, readerFromSid, type Reader } from "./memory.ts";
|
|
12
12
|
import { runWriteGate, type GateContext } from "./gates.ts";
|
|
13
|
-
import { record } from "./evidence.ts";
|
|
13
|
+
import { captureEvidenceContext, record } from "./evidence.ts";
|
|
14
14
|
import { writeEvidence, hasGateCheck } from "./triggers.ts";
|
|
15
15
|
import { writeTarget } from "./repokey.ts";
|
|
16
16
|
import { getCurrent } from "./state.ts";
|
|
@@ -210,6 +210,7 @@ export async function initStamp(scope: string, sid?: string, reader: Reader = re
|
|
|
210
210
|
export async function runInit(args: InitArgs): Promise<InitSummary> {
|
|
211
211
|
const reader = readerFromSid(args.sessionID);
|
|
212
212
|
const writeAt = writeTarget(args.sessionID ?? getCurrent().sid);
|
|
213
|
+
const evidenceContext = captureEvidenceContext(args.sessionID);
|
|
213
214
|
const root = await gitRootOf(args.liveRoot);
|
|
214
215
|
const scope = basename(root) || basename(args.liveRoot);
|
|
215
216
|
const head = await gitHead(root);
|
|
@@ -220,6 +221,7 @@ export async function runInit(args: InitArgs): Promise<InitSummary> {
|
|
|
220
221
|
liveRoot: root,
|
|
221
222
|
reader,
|
|
222
223
|
writeAt,
|
|
224
|
+
evidenceContext,
|
|
223
225
|
...writeEvidence(args.sessionID ?? getCurrent().sid),
|
|
224
226
|
hasGateCheck: hasGateCheck(args.sessionID ?? getCurrent().sid),
|
|
225
227
|
// Stamps land on the caller's session even though runInit awaits git
|