opencode-self-improvement 0.30.1 → 0.30.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/package.json +3 -2
- package/src/capture/available.ts +30 -31
- package/src/capture/candidates.ts +2 -2
- package/src/capture/checked.ts +3 -3
- package/src/capture/guided-rules.ts +1 -1
- package/src/capture/lag.ts +2 -2
- package/src/capture/policy.ts +7 -7
- package/src/capture/prompt.ts +4 -4
- package/src/capture/runtime.ts +86 -90
- package/src/capture/session-model.ts +2 -2
- package/src/capture/transcript.ts +5 -5
- package/src/capture/triggers.ts +7 -7
- package/src/consolidate/propose.ts +4 -4
- package/src/consolidate/render.ts +2 -2
- package/src/core/cmp-ts.ts +1 -1
- package/src/core/config/budgets.ts +1 -1
- package/src/core/config/paths.ts +1 -1
- package/src/core/guidance.ts +1 -1
- package/src/core/hooks.ts +4 -4
- package/src/core/host.ts +1 -1
- package/src/core/logfmt/format.ts +1 -1
- package/src/core/logfmt/publish.ts +1 -1
- package/src/core/logfmt/read.ts +1 -1
- package/src/core/lru.ts +1 -1
- package/src/core/state.ts +4 -4
- package/src/core/tags.ts +9 -10
- package/src/core/time.ts +1 -1
- package/src/core/tokenize.ts +1 -1
- package/src/events.ts +8 -8
- package/src/evidence/record.ts +10 -11
- package/src/gate/gate.ts +25 -25
- package/src/gate/value-conflict.ts +7 -8
- package/src/hits/ledger.ts +4 -4
- package/src/identity/host-events.ts +3 -3
- package/src/identity/repokey.ts +7 -7
- package/src/identity/session-context.ts +7 -7
- package/src/index.ts +6 -6
- package/src/init/detect.ts +3 -3
- package/src/init/format.ts +6 -6
- package/src/init/retag.ts +7 -7
- package/src/init/run.ts +18 -18
- package/src/init/stamp.ts +17 -17
- package/src/inject/anchor.ts +1 -1
- package/src/inject/budget.ts +1 -1
- package/src/inject/digest.ts +5 -5
- package/src/inject/epochs.ts +15 -15
- package/src/inject/format.ts +2 -2
- package/src/inject/pull.ts +3 -3
- package/src/inject/version.ts +1 -1
- package/src/portable/decay.ts +1 -1
- package/src/portable/export.ts +7 -7
- package/src/portable/import.ts +5 -5
- package/src/recall/conflicts.ts +1 -1
- package/src/recall/dedupe.ts +31 -55
- package/src/recall/gate.ts +19 -40
- package/src/recall/relevant.ts +11 -11
- package/src/recall/score.ts +14 -23
- package/src/recall/shared-terms.ts +1 -1
- package/src/status/format.ts +1 -1
- package/src/status/metrics.ts +5 -5
- package/src/status/payload.ts +4 -4
- package/src/status/report.ts +5 -5
- package/src/status/store-summary.ts +1 -1
- package/src/status/write.ts +3 -4
- package/src/store/blocklist.ts +1 -1
- package/src/store/files/append.ts +8 -8
- package/src/store/files/deletions.ts +3 -3
- package/src/store/files/load.ts +5 -5
- package/src/store/files/prune.ts +8 -8
- package/src/store/files/snapshots.ts +1 -1
- package/src/store/files/supersede.ts +11 -12
- package/src/store/files/target.ts +1 -1
- package/src/store/lock.ts +12 -12
- package/src/store/model/memory.ts +4 -4
- package/src/store/model/predicates.ts +2 -2
- package/src/store/model/provenance.ts +1 -1
- package/src/store/model/visibility.ts +4 -4
- package/src/store/prune.ts +1 -1
- package/src/store/quarantine/quarantine.ts +2 -2
- package/src/store/quarantine/release.ts +2 -2
- package/src/store/secrets.ts +1 -1
- package/src/store/tombstones/rejection.ts +1 -1
- package/src/store/tombstones/tombstone.ts +5 -5
- package/src/store/undo.ts +12 -12
- package/src/tools/consolidate.ts +1 -1
- package/src/tools/decay.ts +2 -2
- package/src/tools/deps.ts +1 -1
- package/src/tools/evidence.ts +4 -4
- package/src/tools/export.ts +1 -1
- package/src/tools/forget.ts +2 -2
- package/src/tools/import.ts +3 -3
- package/src/tools/init.ts +1 -1
- package/src/tools/list.ts +1 -1
- package/src/tools/merge-review.ts +11 -11
- package/src/tools/recall.ts +5 -5
- package/src/tools/registry.ts +2 -2
- package/src/tools/remember.ts +4 -4
- package/src/tools/schema.ts +4 -4
- package/src/tools/status-tool.ts +5 -5
- package/src/tools/undo.ts +4 -4
- package/src/tools/update.ts +18 -19
- package/src/viewer/mutate.ts +13 -13
- package/src/viewer/rejections.ts +1 -1
- package/src/viewer/server.ts +47 -49
package/src/store/lock.ts
CHANGED
|
@@ -16,7 +16,7 @@
|
|
|
16
16
|
// Windows, fcntl F_SETLK on POSIX — so the lock lives in the kernel's
|
|
17
17
|
// handle table, not in a directory entry.
|
|
18
18
|
//
|
|
19
|
-
// Why this is not a lock file
|
|
19
|
+
// Why this is not a lock file. The previous protocol put the state of
|
|
20
20
|
// the lock in the EXISTENCE of a file and released it with unlink. On Windows
|
|
21
21
|
// that entry's lifetime is not ours to decide: DeleteFile marks a file for
|
|
22
22
|
// deletion on close and the name stays in the directory until the last handle
|
|
@@ -45,7 +45,7 @@
|
|
|
45
45
|
// Supported storage. SQLite's locking is byte-range locks plus a journal it
|
|
46
46
|
// renames into place, and neither is dependable on network filesystems. A
|
|
47
47
|
// memory root on SMB, NFS or a OneDrive-mounted folder is therefore
|
|
48
|
-
// unsupported
|
|
48
|
+
// unsupported: writes there can report a disk I/O error rather than
|
|
49
49
|
// serialise. That is a deliberate cut, not an oversight — the lock is the
|
|
50
50
|
// correctness mechanism for the whole store, so a silently unserialised store
|
|
51
51
|
// on a share was the worse option.
|
|
@@ -99,7 +99,7 @@ const DEFAULT_TIMEOUT_MS = 10_000;
|
|
|
99
99
|
// reported "locked for 5001ms" while the holder was mid-handover-retry, not
|
|
100
100
|
// wedged. 10 s still fails closed and reports, but stops refusing writes that
|
|
101
101
|
// were simply behind two honest retries.
|
|
102
|
-
//
|
|
102
|
+
// the default policy is fail-closed, the policy moved every
|
|
103
103
|
// production writer to. A writer that omits opts must refuse at the deadline,
|
|
104
104
|
// not silently reintroduce the unlocked-proceed row loss the LOCK_WRITE
|
|
105
105
|
// contract retired. "proceed" survives only as an explicit opt-in.
|
|
@@ -110,7 +110,7 @@ const MAX_BACKOFF_MS = 25;
|
|
|
110
110
|
// the hot path, so it gets its own bound rather than the caller's budget.
|
|
111
111
|
const JOURNAL_CONVERT_BUDGET_MS = 5_000;
|
|
112
112
|
|
|
113
|
-
// The one source of the timeout policy
|
|
113
|
+
// The one source of the timeout policy: both give-up paths — the FIFO
|
|
114
114
|
// hand-off and the SQLite wait — resolve through here, so the fail-closed
|
|
115
115
|
// default cannot drift between them.
|
|
116
116
|
function timeoutPolicy(opts: LockOptions): "proceed" | "fail" {
|
|
@@ -128,7 +128,7 @@ export interface LockOptions {
|
|
|
128
128
|
timeoutMs?: number;
|
|
129
129
|
/**
|
|
130
130
|
* What waiting past `timeoutMs` means. The default, "fail", refuses the
|
|
131
|
-
* mutation (
|
|
131
|
+
* mutation (fail-closed is the contract every store writer keeps;
|
|
132
132
|
* LOCK_WRITE and LOCK_RESTORE spell it out). "proceed" runs the write
|
|
133
133
|
* unlocked and can lose acknowledged writes when another caller rewrites
|
|
134
134
|
* the same file — pass it only where that concession is intended.
|
|
@@ -140,7 +140,7 @@ export interface LockOptions {
|
|
|
140
140
|
// Every writer of a shared store file must respect exclusion, INCLUDING
|
|
141
141
|
// appenders: an unlocked append inside a holder's read-modify-write window is
|
|
142
142
|
// overwritten by its publish. Refuse at the deadline so the caller can retry;
|
|
143
|
-
// never acknowledge a mutation performed outside the holder's lock
|
|
143
|
+
// never acknowledge a mutation performed outside the holder's lock.
|
|
144
144
|
export const LOCK_WRITE: LockOptions = {
|
|
145
145
|
onTimeout: "fail",
|
|
146
146
|
onEvent: (event, waitedMs) => {
|
|
@@ -193,7 +193,7 @@ async function timed(prev: Promise<void>, ms: number): Promise<boolean> {
|
|
|
193
193
|
* correctness, because eviction skips anything in use. Closing is also what
|
|
194
194
|
* lets a test delete a store on Windows — a held handle keeps the file alive —
|
|
195
195
|
* and that is exactly why it happens on eviction and teardown, never per
|
|
196
|
-
* acquisition (
|
|
196
|
+
* acquisition ( is about Windows refusing a delete we do not need to
|
|
197
197
|
* attempt).
|
|
198
198
|
*/
|
|
199
199
|
interface Pinned {
|
|
@@ -491,7 +491,7 @@ async function holdLock<T>(
|
|
|
491
491
|
throw new Error(busyMessage(file, now() - started));
|
|
492
492
|
}
|
|
493
493
|
// Proceeding without the lock is the explicit "proceed" opt-in
|
|
494
|
-
// (
|
|
494
|
+
// (no longer the default). heldLocks is deliberately NOT touched
|
|
495
495
|
// here: a writer that never held the lock must not let a nested call
|
|
496
496
|
// believe it did.
|
|
497
497
|
return await fn();
|
|
@@ -551,7 +551,7 @@ async function acquire<T>(
|
|
|
551
551
|
// Same call chain, same lock: the outer section already excludes everyone
|
|
552
552
|
// else, so re-entering neither starts a second transaction nor queues
|
|
553
553
|
// behind the FIFO the outer section owns. The hook still fires — it counts
|
|
554
|
-
// which store files a write path touches
|
|
554
|
+
// which store files a write path touches, and this path touched one.
|
|
555
555
|
acquiredHook?.(file);
|
|
556
556
|
return await fn();
|
|
557
557
|
}
|
|
@@ -594,12 +594,12 @@ async function acquire<T>(
|
|
|
594
594
|
}
|
|
595
595
|
|
|
596
596
|
/**
|
|
597
|
-
* Test seam
|
|
597
|
+
* Test seam: refuse the acquisition of chosen files.
|
|
598
598
|
*
|
|
599
599
|
* The tests that pin "a batch that published file 1 and then lost file 2 must
|
|
600
600
|
* report file 1 as durable" need a refusal at a chosen point in a sequence.
|
|
601
601
|
* Under the lock file a test could hold one day file and let the batch reach
|
|
602
|
-
* the next one. The lock is per file again
|
|
602
|
+
* the next one. The lock is per file again, so that driver
|
|
603
603
|
* exists again; this seam remains for the cases that need a refusal at a chosen
|
|
604
604
|
* step rather than a rival that holds a file.
|
|
605
605
|
*
|
|
@@ -657,7 +657,7 @@ export async function withStoreBatch<T>(
|
|
|
657
657
|
}
|
|
658
658
|
|
|
659
659
|
/**
|
|
660
|
-
* Test seam
|
|
660
|
+
* Test seam: observe how many store files a write path locks.
|
|
661
661
|
*
|
|
662
662
|
* The narrowing this ticket asked for is invisible to a functional test — a
|
|
663
663
|
* supersede that sweeps every day file and one that touches a single file both
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
// memory — split from src/memory.ts
|
|
1
|
+
// memory — split from src/memory.ts. Declaration bodies are unchanged.
|
|
2
2
|
|
|
3
3
|
import { flattenMemoryText } from "../sanitize.ts";
|
|
4
4
|
|
|
@@ -48,7 +48,7 @@ const CONFLICT_REF_RE = /^[A-Za-z_][A-Za-z0-9_]{1,63}$/;
|
|
|
48
48
|
|
|
49
49
|
export const MAX_CLAIM_CHARS = 32;
|
|
50
50
|
|
|
51
|
-
/** Cap on the verbatim user utterance a guided row may carry
|
|
51
|
+
/** Cap on the verbatim user utterance a guided row may carry. */
|
|
52
52
|
export const MAX_ORIGINAL_CHARS = 300;
|
|
53
53
|
|
|
54
54
|
/**
|
|
@@ -96,7 +96,7 @@ export interface Memory {
|
|
|
96
96
|
content: string;
|
|
97
97
|
issue?: string;
|
|
98
98
|
tags?: string[];
|
|
99
|
-
// Retrieval keywords
|
|
99
|
+
// Retrieval keywords: author-supplied aliases, verb forms and synonyms
|
|
100
100
|
// for this row, written at capture time. They widen the scoring haystack
|
|
101
101
|
// ONLY — a row is never rendered through them, so injection bytes and the
|
|
102
102
|
// content cap stay exactly what the prose says. This is the zero-embedding
|
|
@@ -117,7 +117,7 @@ export interface Memory {
|
|
|
117
117
|
// authority (klass). Injection reads the code at render time — deterministically,
|
|
118
118
|
// no model call — and a collision renders one CONFLICT line whose Action is
|
|
119
119
|
// fixed by the class: behavior class trusts the code, spec class fixes it.
|
|
120
|
-
//
|
|
120
|
+
// measured the alternative: a wrong guided row rewrote correct code.
|
|
121
121
|
ref?: string;
|
|
122
122
|
claim?: string;
|
|
123
123
|
klass?: "spec" | "behavior";
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
// predicates — split from src/memory.ts
|
|
1
|
+
// predicates — split from src/memory.ts. Declaration bodies are unchanged.
|
|
2
2
|
import { INIT_STAMP_TAG } from "../../core/tags.ts";
|
|
3
3
|
import { isQuarantined } from "../quarantine/quarantine.ts";
|
|
4
4
|
import type { Memory } from "./memory.ts";
|
|
@@ -8,7 +8,7 @@ export function isActive(m: Memory): boolean {
|
|
|
8
8
|
}
|
|
9
9
|
|
|
10
10
|
// Quarantine remains durable and reviewable; only model-facing reads withhold it.
|
|
11
|
-
// The legacy `init-stamp` tag joins it
|
|
11
|
+
// The legacy `init-stamp` tag joins it. A legacy stamp row is
|
|
12
12
|
// plugin bookkeeping, and migration only retires a row whose `init_complete`
|
|
13
13
|
// audit line survives; in a store where that line is gone the row stays active
|
|
14
14
|
// forever, so the tag itself has to keep it off the prompt. This is the one
|
|
@@ -17,7 +17,7 @@ import type { Memory } from "./memory.ts";
|
|
|
17
17
|
// in that flow. Resolution must NOT be deferred to filter time: the module
|
|
18
18
|
// global current moves whenever another session's hook or tool dispatches, and
|
|
19
19
|
// a store read awaits filesystem I/O — filtering after the await with the
|
|
20
|
-
// ambient identity injects the OTHER session's repo
|
|
20
|
+
// ambient identity injects the OTHER session's repo.
|
|
21
21
|
//
|
|
22
22
|
// repo — the caller's session resolved a repository (its own when
|
|
23
23
|
// bound; the setup location for an unbound session in a
|
|
@@ -41,7 +41,7 @@ export const ADMIN_READER: Reader = { kind: "admin" };
|
|
|
41
41
|
// captured synchronously at flow entry. Bound session → its repo; unbound →
|
|
42
42
|
// global-only. The module scope is NOT a fallback here: in a process that
|
|
43
43
|
// loaded more than one plugin instance it belongs to whoever set up LAST,
|
|
44
|
-
// which is another workspace (
|
|
44
|
+
// which is another workspace (multi-setup gap). Plugin flows bind an
|
|
45
45
|
// unbound caller to their OWN setup location at entry (index.ts), so ordinary
|
|
46
46
|
// single-workspace sessions resolve through the session map, never here.
|
|
47
47
|
export function readerForSession(sid?: unknown): Reader {
|
|
@@ -66,9 +66,9 @@ export function readerFromSid(sid?: unknown): Reader {
|
|
|
66
66
|
: readerForAmbient();
|
|
67
67
|
}
|
|
68
68
|
|
|
69
|
-
// Before
|
|
69
|
+
// Before, path-derived keys on win32/darwin hashed the whole canonical
|
|
70
70
|
// path in lowercase, even on case-sensitive volumes. Such a key can equal a
|
|
71
|
-
// distinct lowercase sibling's current key
|
|
71
|
+
// distinct lowercase sibling's current key. The stored path identifies
|
|
72
72
|
// these legacy stamps without a migration: require the same directory, allowing
|
|
73
73
|
// real symlink/case-insensitive aliases, instead of trusting that key alone.
|
|
74
74
|
// Remote-derived keys still share across clones with different paths. A stamp
|
package/src/store/prune.ts
CHANGED
|
@@ -10,7 +10,7 @@ export async function pruneMemory(
|
|
|
10
10
|
scope: string,
|
|
11
11
|
type: string,
|
|
12
12
|
reason: string,
|
|
13
|
-
// The calling session
|
|
13
|
+
// The calling session: the repo floor on prune must follow the
|
|
14
14
|
// CALLER's identity, captured at tool entry, not the ambient current the
|
|
15
15
|
// locked file walk may outlive. "?" / undefined keep ambient semantics.
|
|
16
16
|
sid?: string,
|
|
@@ -48,8 +48,8 @@ export function quarantineCandidate<
|
|
|
48
48
|
tags?: string[];
|
|
49
49
|
},
|
|
50
50
|
>(candidate: T): T {
|
|
51
|
-
//
|
|
52
|
-
// injected line), so the scanner covers it as well as content.
|
|
51
|
+
// scope renders model-facing (inject/format.ts prints it on every
|
|
52
|
+
// injected line), so the scanner covers it as well as content. review:
|
|
53
53
|
// so does `original`, the verbatim quote the same line prints as
|
|
54
54
|
// `(user said: "...")` — a benign summary carrying an instruction-shaped
|
|
55
55
|
// quote reached the prompt untagged. Hits are merged and deduplicated;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
// release — split from src/memory.ts
|
|
1
|
+
// release — split from src/memory.ts. Declaration bodies are unchanged.
|
|
2
2
|
import { type Fields, formatLine } from "../../core/logfmt/format.ts";
|
|
3
3
|
import { filesHoldingTs, memoryFiles } from "../files/load.ts";
|
|
4
4
|
import { stampRow } from "../files/snapshots.ts";
|
|
@@ -21,7 +21,7 @@ export async function releaseQuarantine(
|
|
|
21
21
|
else delete fields.tags;
|
|
22
22
|
return formatLine(fields);
|
|
23
23
|
};
|
|
24
|
-
|
|
24
|
+
//+ review: release every copy. The day file the ts names is the
|
|
25
25
|
// common case; the previous day's file joins ONLY when a scan finds the same
|
|
26
26
|
// identity in it, which is what an older midnight-boundary append could write.
|
|
27
27
|
// Leaving a duplicate quarantined beside a released copy would keep the row
|
package/src/store/secrets.ts
CHANGED
|
@@ -7,7 +7,7 @@ export const REDACTED_SECRET = "[redacted]";
|
|
|
7
7
|
// PEM redaction is a linear marker-pair scan, not one lazy regex. The old
|
|
8
8
|
// /-----BEGIN...[\s\S]*?-----END.../g re-scanned to end-of-input at every
|
|
9
9
|
// unmatched BEGIN, so a large tool output of repeated BEGIN lines with no END
|
|
10
|
-
// line stalled the hook for seconds per megabyte
|
|
10
|
+
// line stalled the hook for seconds per megabyte. The marker regexes
|
|
11
11
|
// below are anchored (sticky) and never span lines, so each probe is bounded.
|
|
12
12
|
const PRIVATE_KEY_BEGIN = "-----BEGIN";
|
|
13
13
|
const PRIVATE_KEY_END = "-----END";
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
// rejection — split from src/tombstones.ts
|
|
1
|
+
// rejection — split from src/tombstones.ts. Declaration bodies are unchanged.
|
|
2
2
|
import { join } from "node:path";
|
|
3
3
|
import { memoryRoot } from "../../core/config/paths.ts";
|
|
4
4
|
import { contentHash } from "../../evidence/record.ts";
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
// tombstone — split from src/tombstones.ts
|
|
2
|
-
// Value-keyed rejection tombstones
|
|
1
|
+
// tombstone — split from src/tombstones.ts. Declaration bodies are unchanged.
|
|
2
|
+
// Value-keyed rejection tombstones.
|
|
3
3
|
//
|
|
4
4
|
// The blocklist keys on `ts` — ROW identity. memory_forget/prune deletes the
|
|
5
5
|
// row outright. Neither survives re-ingestion: replay the original source (a
|
|
@@ -297,7 +297,7 @@ export async function tombstones(): Promise<Tombstone[]> {
|
|
|
297
297
|
* The heavy concurrent scenario on the Windows runner failed 2/2 with that shape
|
|
298
298
|
* (run 41112466339). At that time, lock-budget expiry let a writer proceed
|
|
299
299
|
* unlocked, losing rows behind a long read-modify-write. LOCK_WRITE now refuses
|
|
300
|
-
* on timeout
|
|
300
|
+
* on timeout; batching still reduces lock contention and its I/O cost.
|
|
301
301
|
*
|
|
302
302
|
* Still idempotent by `ch`, and de-duplicated WITHIN the batch too, so a forget
|
|
303
303
|
* that removes fifty rows carrying the same content records one tombstone.
|
|
@@ -315,7 +315,7 @@ export async function tombstoneMany(
|
|
|
315
315
|
const at = new Date().toISOString();
|
|
316
316
|
// An audit reason is human prose (prune passes the caller's straight through),
|
|
317
317
|
// and this is the boundary where it becomes durable — the same rule the
|
|
318
|
-
// deletion audit and the evidence log apply
|
|
318
|
+
// deletion audit and the evidence log apply. Scrubbing here rather than
|
|
319
319
|
// at each call site is what keeps a future caller from forgetting to.
|
|
320
320
|
const reason = redactSecrets(opts.reason);
|
|
321
321
|
const fresh: string[] = [];
|
|
@@ -395,7 +395,7 @@ export async function removeTombstone(ch: string): Promise<boolean> {
|
|
|
395
395
|
const row = parseLine(l);
|
|
396
396
|
return !(row && row.ch === ch);
|
|
397
397
|
});
|
|
398
|
-
// A no-op must report as a no-op
|
|
398
|
+
// A no-op must report as a no-op: unknown ch lifts nothing, so
|
|
399
399
|
// return false and skip the rewrite rather than republishing the file
|
|
400
400
|
// and reporting a withdrawal that never happened.
|
|
401
401
|
if (kept.length === lines.length) return false;
|
package/src/store/undo.ts
CHANGED
|
@@ -11,10 +11,10 @@
|
|
|
11
11
|
// and additionally snapshots the file it replaces, so the state it drops stays
|
|
12
12
|
// undoable (result.safety). Every mode consults the rejection tombstones: a
|
|
13
13
|
// row whose content was rejected by a human is omitted from what it publishes,
|
|
14
|
-
// never revived
|
|
14
|
+
// never revived.
|
|
15
15
|
//
|
|
16
16
|
// A day file is shared across REPOSITORIES too, and foreign rows are outside
|
|
17
|
-
// a caller's reach in every sense
|
|
17
|
+
// a caller's reach in every sense: no mode revives them from the
|
|
18
18
|
// snapshot, rewinds them to a stale copy, or drops them. Foreign live lines
|
|
19
19
|
// are carried over verbatim in every mode, appended at the end — line content
|
|
20
20
|
// preserved, position in the shared file not — and only the caller's own rows
|
|
@@ -22,7 +22,7 @@
|
|
|
22
22
|
// visibility, not ownership: GLOBAL rows (repo=global, or legacy unstamped)
|
|
23
23
|
// are visible to every reader, so every repository's rollback treats them as
|
|
24
24
|
// its own — a force restore may drop a global line appended after the
|
|
25
|
-
// snapshot (pinned in test/undo-ownership). That is
|
|
25
|
+
// snapshot (pinned in test/undo-ownership). That is "act on exactly
|
|
26
26
|
// what you may read", the same rule memory_forget applies to global scope.
|
|
27
27
|
// Admin readers (the viewer, out-of-plugin maintenance) keep the whole-file
|
|
28
28
|
// restore exactly as it was.
|
|
@@ -109,7 +109,7 @@ export interface RestoreResult {
|
|
|
109
109
|
// ts of rows intentionally deleted after this snapshot. CHECK and MERGE
|
|
110
110
|
// leave them deleted; FORCE is the explicit recovery path — except for rows
|
|
111
111
|
// whose content carries a rejection tombstone, which no mode recovers
|
|
112
|
-
// (rejectedOmitted): a rejection is absolute
|
|
112
|
+
// (rejectedOmitted): a rejection is absolute.
|
|
113
113
|
deletedOmitted: string[];
|
|
114
114
|
// ts of caller-owned rows the restore omitted because their content carries a
|
|
115
115
|
// rejection tombstone. Reporting them separately from deletedOmitted is the
|
|
@@ -120,7 +120,7 @@ export interface RestoreResult {
|
|
|
120
120
|
// different row, which the identity-keyed deletion audit cannot catch.
|
|
121
121
|
rejectedOmitted: string[];
|
|
122
122
|
// Live rows owned by other repositories, whose lines are carried over
|
|
123
|
-
// verbatim (appended at the end) in every mode
|
|
123
|
+
// verbatim (appended at the end) in every mode. Admin restores
|
|
124
124
|
// report 0 — there is no foreign reader.
|
|
125
125
|
foreignPreserved: number;
|
|
126
126
|
}
|
|
@@ -273,8 +273,8 @@ export async function restoreSnapshot(
|
|
|
273
273
|
// finished just before this restore is honoured.
|
|
274
274
|
const audited =
|
|
275
275
|
mode !== "force" ? await auditedDeletions() : new Set<string>();
|
|
276
|
-
// Rejection tombstones are keyed on the VALUE
|
|
277
|
-
// absolute (decision
|
|
276
|
+
// Rejection tombstones are keyed on the VALUE, and a rejection is
|
|
277
|
+
// absolute (decision A): no tool lifts one, so EVERY mode reads them
|
|
278
278
|
// and applies the content-hash floor to the caller-owned rows it publishes
|
|
279
279
|
// (see the floor below), not just FORCE. The identity-keyed deletion audit
|
|
280
280
|
// above cannot catch a rejected value carried by an older snapshot
|
|
@@ -282,7 +282,7 @@ export async function restoreSnapshot(
|
|
|
282
282
|
// lock, like the deletion audit, so a forget that finished just before
|
|
283
283
|
// this restore is honoured.
|
|
284
284
|
const rejected = new Set((await tombstones()).map((t) => t.ch));
|
|
285
|
-
// Ownership before anything else
|
|
285
|
+
// Ownership before anything else: rows a foreign repo owns are
|
|
286
286
|
// excluded from the snapshot side in EVERY mode (never revived, never
|
|
287
287
|
// rewound), excluded from the deletion audit and the divergence
|
|
288
288
|
// bookkeeping (not this caller's to reason about), and carried verbatim
|
|
@@ -315,7 +315,7 @@ export async function restoreSnapshot(
|
|
|
315
315
|
else if (s !== l) concurrentChanged.push(k);
|
|
316
316
|
}
|
|
317
317
|
|
|
318
|
-
// CHECK keeps its documented conservatism (
|
|
318
|
+
// CHECK keeps its documented conservatism ( control): ANY divergence
|
|
319
319
|
// of the shared file — including other repositories' rows, which FORCE
|
|
320
320
|
// and MERGE now provably leave untouched — refuses until the caller picks
|
|
321
321
|
// a mode deliberately. The refusal is a "the file moved, say again on
|
|
@@ -359,7 +359,7 @@ export async function restoreSnapshot(
|
|
|
359
359
|
.concat(curOwn.filter((l) => !snapByKey.has(rowKey(l))));
|
|
360
360
|
}
|
|
361
361
|
|
|
362
|
-
// Rejection is absolute
|
|
362
|
+
// Rejection is absolute: the content-hash floor is
|
|
363
363
|
// the last gate before publishing, applied to the caller-owned rows of
|
|
364
364
|
// EVERY mode. A row whose content carries a tombstone is omitted here and
|
|
365
365
|
// reported in rejectedOmitted, so the store never ends up holding an
|
|
@@ -369,7 +369,7 @@ export async function restoreSnapshot(
|
|
|
369
369
|
// rollback drops the original with no audit, then a later copy is
|
|
370
370
|
// forgotten). The tombstone file itself is read-only to a restore —
|
|
371
371
|
// mis-forget recovery stays human. Foreign rows are carried verbatim and
|
|
372
|
-
// never filtered: they are outside this caller's reach
|
|
372
|
+
// never filtered: they are outside this caller's reach.
|
|
373
373
|
const rejectedOmitted: string[] = [];
|
|
374
374
|
if (rejected.size > 0) {
|
|
375
375
|
pubOwn = pubOwn.filter((line) => {
|
|
@@ -389,7 +389,7 @@ export async function restoreSnapshot(
|
|
|
389
389
|
mode === "force" ? (await snapshotFiles([target]))[0] : undefined;
|
|
390
390
|
|
|
391
391
|
// Foreign live lines are re-admitted verbatim in every mode, appended at
|
|
392
|
-
// the end — line content preserved, position not
|
|
392
|
+
// the end — line content preserved, position not. Under the admin
|
|
393
393
|
// reader curForeign is empty and the write is the historical whole-file
|
|
394
394
|
// restore, byte for byte — modulo the rejected-row omission above, which
|
|
395
395
|
// applies to every reader and every mode: a rejection is absolute, not
|
package/src/tools/consolidate.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
// The memory_consolidate tool, extracted from index.ts
|
|
1
|
+
// The memory_consolidate tool, extracted from index.ts. Schema, description
|
|
2
2
|
// and handler are byte-identical to the pre-split source; closure access arrives
|
|
3
3
|
// through ToolDeps.
|
|
4
4
|
import type { ToolRegister } from "./deps.ts";
|
package/src/tools/decay.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
// The memory_decay tool, extracted from index.ts
|
|
1
|
+
// The memory_decay tool, extracted from index.ts. Schema, description
|
|
2
2
|
// and handler are byte-identical to the pre-split source; closure access arrives
|
|
3
3
|
// through ToolDeps.
|
|
4
4
|
import type { ToolRegister } from "./deps.ts";
|
|
@@ -58,7 +58,7 @@ export const register: ToolRegister = (editor, deps) => {
|
|
|
58
58
|
const snapshot = await snapshotFiles([
|
|
59
59
|
...new Set(stale.map((m) => m.file)),
|
|
60
60
|
]);
|
|
61
|
-
// One lock/read/snapshot/publish per file for the whole decay run
|
|
61
|
+
// One lock/read/snapshot/publish per file for the whole decay run:
|
|
62
62
|
// N retired rows are one undo point, not N. Idempotent (a no-op on rows
|
|
63
63
|
// already superseded, out-of-band ones skipped under the lock).
|
|
64
64
|
const durable: string[] = [];
|
package/src/tools/deps.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
// Shared dependency surface for the memory tools
|
|
1
|
+
// Shared dependency surface for the memory tools. The tools module is
|
|
2
2
|
// a leaf: host wiring stays in index.ts and arrives through this interface,
|
|
3
3
|
// so a tool file never reaches into the plugin setup closure.
|
|
4
4
|
import type { GateContext } from "../gate/gate.ts";
|
package/src/tools/evidence.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
// The memory_evidence tool, extracted from index.ts
|
|
1
|
+
// The memory_evidence tool, extracted from index.ts. Schema, description
|
|
2
2
|
// and handler are byte-identical to the pre-split source; closure access arrives
|
|
3
3
|
// through ToolDeps.
|
|
4
4
|
import type { ToolRegister } from "./deps.ts";
|
|
@@ -19,7 +19,7 @@ export const register: ToolRegister = (editor, deps) => {
|
|
|
19
19
|
async execute(args, context): Promise<{ content: string }> {
|
|
20
20
|
const { sid } = toolIds(context);
|
|
21
21
|
const reader = readerFromSid(sid);
|
|
22
|
-
//
|
|
22
|
+
// the ONE path the schema-validated date can resolve to —
|
|
23
23
|
// a real calendar day inside the evidence dir, never a traversal
|
|
24
24
|
// into the raw store or the filesystem beyond it.
|
|
25
25
|
const file = evidenceFileFor(args.date);
|
|
@@ -30,11 +30,11 @@ export const register: ToolRegister = (editor, deps) => {
|
|
|
30
30
|
};
|
|
31
31
|
}
|
|
32
32
|
let lines = await readLines(file);
|
|
33
|
-
// Data partitions too (
|
|
33
|
+
// Data partitions too (the ownership rule, applied to evidence):
|
|
34
34
|
// a line stamped to another repository is not this session's data,
|
|
35
35
|
// and a line a NAMED session wrote while unresolved is private to
|
|
36
36
|
// that session — the caller's sid is what the private branch
|
|
37
|
-
// matches against
|
|
37
|
+
// matches against.
|
|
38
38
|
if (reader.kind !== "admin") {
|
|
39
39
|
lines = lines.filter((l) => {
|
|
40
40
|
const fields = parseLine(l);
|
package/src/tools/export.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
// The memory_export tool, extracted from index.ts
|
|
1
|
+
// The memory_export tool, extracted from index.ts. Schema, description
|
|
2
2
|
// and handler are byte-identical to the pre-split source; closure access arrives
|
|
3
3
|
// through ToolDeps.
|
|
4
4
|
import type { ToolRegister } from "./deps.ts";
|
package/src/tools/forget.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
// The memory_forget tool, extracted from index.ts
|
|
1
|
+
// The memory_forget tool, extracted from index.ts. Schema, description
|
|
2
2
|
// and handler are byte-identical to the pre-split source; closure access arrives
|
|
3
3
|
// through ToolDeps.
|
|
4
4
|
import type { ToolRegister } from "./deps.ts";
|
|
@@ -15,7 +15,7 @@ export const register: ToolRegister = (editor, deps) => {
|
|
|
15
15
|
options: direct,
|
|
16
16
|
async execute(args, context): Promise<{ content: string }> {
|
|
17
17
|
const { sid } = toolIds(context);
|
|
18
|
-
// Identity before the prune's repo floor
|
|
18
|
+
// Identity before the prune's repo floor: resolve the session
|
|
19
19
|
// from the host (messages, then session row) before pruneMemory
|
|
20
20
|
// captures the Reader, so an unseen serve-host session is partitioned
|
|
21
21
|
// by its own repository, not the instance's provisional binding.
|
package/src/tools/import.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
// The memory_import tool, extracted from index.ts
|
|
1
|
+
// The memory_import tool, extracted from index.ts. Schema, description
|
|
2
2
|
// and handler are byte-identical to the pre-split source; closure access arrives
|
|
3
3
|
// through ToolDeps.
|
|
4
4
|
import type { ToolRegister } from "./deps.ts";
|
|
@@ -25,7 +25,7 @@ export const register: ToolRegister = (editor, deps) => {
|
|
|
25
25
|
const { sid } = toolIds(context);
|
|
26
26
|
// Resolve before touching the file: every imported row is re-stamped
|
|
27
27
|
// with the IMPORTING session's repository, so an unresolved caller
|
|
28
|
-
// would move a whole export into whoever set up last
|
|
28
|
+
// would move a whole export into whoever set up last.
|
|
29
29
|
await bindSessionIdentity(sid);
|
|
30
30
|
const ownerless = ownerlessWriter(sid);
|
|
31
31
|
if (ownerless) return await refuseOwnerlessWrite(ownerless, "import");
|
|
@@ -51,7 +51,7 @@ export const register: ToolRegister = (editor, deps) => {
|
|
|
51
51
|
? ` ${t.downgraded} open rows downgraded to settled (missing eligible memory_export header or verifiable repo scope).`
|
|
52
52
|
: "") +
|
|
53
53
|
// Rows that landed without their write_promoted line are
|
|
54
|
-
// durable but invisible to memory_evidence
|
|
54
|
+
// durable but invisible to memory_evidence —
|
|
55
55
|
// the tally owes the reader the count, not silence.
|
|
56
56
|
(t.unaudited
|
|
57
57
|
? ` ${t.unaudited} promoted rows landed without their write_promoted audit line (${t.auditError}); memory_evidence will miss them.`
|
package/src/tools/init.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
// The memory_init tool, extracted from index.ts
|
|
1
|
+
// The memory_init tool, extracted from index.ts. Schema, description
|
|
2
2
|
// and handler are byte-identical to the pre-split source; closure access arrives
|
|
3
3
|
// through ToolDeps.
|
|
4
4
|
import type { ToolRegister } from "./deps.ts";
|
package/src/tools/list.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
// The memory_list tool, extracted from index.ts
|
|
1
|
+
// The memory_list tool, extracted from index.ts. Schema, description
|
|
2
2
|
// and handler are byte-identical to the pre-split source; closure access arrives
|
|
3
3
|
// through ToolDeps.
|
|
4
4
|
import type { ToolRegister } from "./deps.ts";
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
// The memory_merge_review tool, extracted from index.ts
|
|
1
|
+
// The memory_merge_review tool, extracted from index.ts.
|
|
2
2
|
// Closure access arrives through ToolDeps.
|
|
3
3
|
import type { ToolRegister } from "./deps.ts";
|
|
4
4
|
import { memoryRoot } from "../core/config/paths.ts";
|
|
@@ -21,7 +21,7 @@ export const register: ToolRegister = (editor, deps) => {
|
|
|
21
21
|
options: direct,
|
|
22
22
|
async execute(args, context): Promise<{ content: string }> {
|
|
23
23
|
const { sid } = toolIds(context);
|
|
24
|
-
// Identity before authorization
|
|
24
|
+
// Identity before authorization: the entry binding is only
|
|
25
25
|
// provisional on the INSTANCE's directory. On a serve host the session
|
|
26
26
|
// row is the sole truth, and a tool call can be the first thing this
|
|
27
27
|
// instance sees for a session — resolve it like the write tools do
|
|
@@ -41,11 +41,11 @@ export const register: ToolRegister = (editor, deps) => {
|
|
|
41
41
|
"merge_review blocked: loser and survivor are the same row — nothing to resolve. No evidence written.",
|
|
42
42
|
};
|
|
43
43
|
}
|
|
44
|
-
// A row id is a pointer, not authority
|
|
44
|
+
// A row id is a pointer, not authority: resolving and
|
|
45
45
|
// authorizing BOTH seats happens against the caller's Reader —
|
|
46
|
-
// captured at entry, never re-read after an await
|
|
46
|
+
// captured at entry, never re-read after an await — and the
|
|
47
47
|
// whole resolve/check/mutate runs under the same update-order lock
|
|
48
|
-
// memory_update serializes on
|
|
48
|
+
// memory_update serializes on, so the authorization is
|
|
49
49
|
// revalidated under the mutation lock instead of against a snapshot
|
|
50
50
|
// a concurrent update could have replaced. Acquisition order is
|
|
51
51
|
// always update-order then store-file locks, never the reverse, so
|
|
@@ -53,7 +53,7 @@ export const register: ToolRegister = (editor, deps) => {
|
|
|
53
53
|
// closed with nothing written.
|
|
54
54
|
const reader = readerFromSid(sid);
|
|
55
55
|
// A batch may publish the loser then refuse a later file. The sink
|
|
56
|
-
// records that publish before the overall promise settles
|
|
56
|
+
// records that publish before the overall promise settles.
|
|
57
57
|
const mergeDurable: string[] = [];
|
|
58
58
|
try {
|
|
59
59
|
return await withStoreBatch(
|
|
@@ -75,14 +75,14 @@ export const register: ToolRegister = (editor, deps) => {
|
|
|
75
75
|
const loserRow = all.find((m) => m.ts === args.loser);
|
|
76
76
|
// loadAll omits blocklisted rows. An unresolved id therefore
|
|
77
77
|
// proves neither existence nor ownership; raw mutation helpers
|
|
78
|
-
// must not use it to bypass this read boundary
|
|
78
|
+
// must not use it to bypass this read boundary.
|
|
79
79
|
if (!loserRow) {
|
|
80
80
|
return {
|
|
81
81
|
content:
|
|
82
82
|
"merge_review blocked: loser is missing or unavailable — nothing to resolve. No evidence written.",
|
|
83
83
|
};
|
|
84
84
|
}
|
|
85
|
-
// Visibility is the authorization contract
|
|
85
|
+
// Visibility is the authorization contract: a session
|
|
86
86
|
// may merge exactly the rows it may read. Global and legacy
|
|
87
87
|
// unstamped rows are visible everywhere and therefore
|
|
88
88
|
// mergeable from anywhere — stated here, not granted
|
|
@@ -101,7 +101,7 @@ export const register: ToolRegister = (editor, deps) => {
|
|
|
101
101
|
"merge_review blocked: the survivor belongs to another repository — this session may not promote or revive it. Nothing was done. No evidence written.",
|
|
102
102
|
};
|
|
103
103
|
}
|
|
104
|
-
// Provenance guard
|
|
104
|
+
// Provenance guard: a survivor carrying a supersession
|
|
105
105
|
// written by anything OTHER than this review — its marker points
|
|
106
106
|
// at a later row (a memory_update that retired the survivor
|
|
107
107
|
// after the review was filed), and the marker's reason is not
|
|
@@ -146,7 +146,7 @@ export const register: ToolRegister = (editor, deps) => {
|
|
|
146
146
|
// The survivor may itself have been superseded earlier (e.g. by
|
|
147
147
|
// a row this very call just made the loser). Declaring it
|
|
148
148
|
// canonical has to make it recallable, so clear its own marker —
|
|
149
|
-
// but only the marker this review owns
|
|
149
|
+
// but only the marker this review owns: the guard above
|
|
150
150
|
// already refused anything else, and this re-check runs under the
|
|
151
151
|
// file lock against the line as it is at mutation time.
|
|
152
152
|
const revived = await clearSuperseded(args.survivor, {
|
|
@@ -154,7 +154,7 @@ export const register: ToolRegister = (editor, deps) => {
|
|
|
154
154
|
reason: args.reason,
|
|
155
155
|
});
|
|
156
156
|
// The response has always claimed "Evidence recorded" — now it
|
|
157
|
-
// is true, and it names the session the merge ran FOR (
|
|
157
|
+
// is true, and it names the session the merge ran FOR (
|
|
158
158
|
// residue on this line). The host tool_result hook covers
|
|
159
159
|
// grep/read/edit/shell only, so a merge used to leave zero
|
|
160
160
|
// trace: which reviewer decision, on which reason, reviving
|
package/src/tools/recall.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
// The memory_recall tool, extracted from index.ts
|
|
1
|
+
// The memory_recall tool, extracted from index.ts. Schema, description
|
|
2
2
|
// and handler are byte-identical to the pre-split source; closure access arrives
|
|
3
3
|
// through ToolDeps.
|
|
4
4
|
import type { ToolRegister } from "./deps.ts";
|
|
@@ -19,7 +19,7 @@ import { firstFrontierTap, markFrontierTap } from "../capture/triggers.ts";
|
|
|
19
19
|
import { dedupeThreshold, dedupeWindow } from "../recall/dedupe.ts";
|
|
20
20
|
|
|
21
21
|
function scoreMemory(m: Memory, q: string): number {
|
|
22
|
-
// Same indexed fields as the injection scorer
|
|
22
|
+
// Same indexed fields as the injection scorer: a row recalled by one of
|
|
23
23
|
// its keywords is the same row recalled by the prose that keyword stands for.
|
|
24
24
|
const hay = recallHaystack(m);
|
|
25
25
|
let score = 0;
|
|
@@ -53,7 +53,7 @@ export const register: ToolRegister = (editor, deps) => {
|
|
|
53
53
|
if (args.query) {
|
|
54
54
|
// Default on: a row must share two whole words of the query — the
|
|
55
55
|
// concepts rule, not the scorer's substring test (src/recall/gate.ts,
|
|
56
|
-
//
|
|
56
|
+
//). OPENCODE_MEMORY_QUERY_GATE=off restores the old matcher.
|
|
57
57
|
const gate = gateEnabled();
|
|
58
58
|
const concepts = gate ? queryConcepts(args.query) : [];
|
|
59
59
|
results = results
|
|
@@ -62,7 +62,7 @@ export const register: ToolRegister = (editor, deps) => {
|
|
|
62
62
|
.sort((a, b) => b.score - a.score)
|
|
63
63
|
.map((x) => x.m);
|
|
64
64
|
}
|
|
65
|
-
//
|
|
65
|
+
// the default window was 20. A live audit joined 1,090 recall
|
|
66
66
|
// events to their session transcripts: rank-1 rows go on to be
|
|
67
67
|
// referenced at 3.4x the rate of a random store row, ranks 11-20 at
|
|
68
68
|
// 1.16x — noise. Returning 17.7 rows per call meant most of the window
|
|
@@ -71,7 +71,7 @@ export const register: ToolRegister = (editor, deps) => {
|
|
|
71
71
|
// Non-positive or fractional limits are coerced, never trusted: a
|
|
72
72
|
// negative slice(0, n) / slice(-n) silently returns MORE rows, not fewer.
|
|
73
73
|
const limit = args.limit && args.limit > 0 ? Math.floor(args.limit) : 5;
|
|
74
|
-
//
|
|
74
|
+
// dedup lane (RESULTS §17): default on at 0.8 — near-duplicate
|
|
75
75
|
// copies are skipped so the window fills with distinct rows instead of
|
|
76
76
|
// repeats of the top hit. OPENCODE_MEMORY_DEDUP=0 restores the plain
|
|
77
77
|
// slice.
|
package/src/tools/registry.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
// Memory tool registration
|
|
1
|
+
// Memory tool registration: one module per tool, registered here in
|
|
2
2
|
// the same order index.ts used before the split. Behavior, schemas and result
|
|
3
|
-
// shapes are pinned by the e2e characterization suite
|
|
3
|
+
// shapes are pinned by the e2e characterization suite and the
|
|
4
4
|
// registration coverage gate (e2e/coverage.test.ts).
|
|
5
5
|
import { register as registerRemember } from "./remember.ts";
|
|
6
6
|
import { register as registerConsolidate } from "./consolidate.ts";
|