opencode-self-improvement 0.30.1 → 0.30.2
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/capture/runtime.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
// Opt-in capture configuration and dispatch
|
|
1
|
+
// Opt-in capture configuration and dispatch. Cooldowns remain process-wide;
|
|
2
2
|
// subscriptions and dispatch closures belong to one setup instance.
|
|
3
3
|
import type { Cleanup } from "@opencode/plugin/promise/plugin";
|
|
4
4
|
import { cmpTs } from "../core/cmp-ts.ts";
|
|
@@ -58,7 +58,7 @@ interface CaptureHost {
|
|
|
58
58
|
};
|
|
59
59
|
generate?: { text: (input: unknown) => Promise<{ text?: string } | string> };
|
|
60
60
|
session?: { context?: (input: { sessionID: string }) => Promise<unknown> };
|
|
61
|
-
// Host default model
|
|
61
|
+
// Host default model: the last-resort source for an omitted
|
|
62
62
|
// captureModel. Optional-call everywhere: older/fake hosts expose none.
|
|
63
63
|
model?: {
|
|
64
64
|
default?: {
|
|
@@ -84,7 +84,7 @@ interface CaptureDependencies {
|
|
|
84
84
|
onGuidedPromoted?: (sid: string) => void | Promise<void>;
|
|
85
85
|
}
|
|
86
86
|
|
|
87
|
-
// Tag on store rows captured by the COMPACTION trigger
|
|
87
|
+
// Tag on store rows captured by the COMPACTION trigger. Rows keep
|
|
88
88
|
// the shared "auto-capture" provenance tag (src/inject.ts renders it) and add
|
|
89
89
|
// this one so decay/status can tell which trigger wrote them — the same
|
|
90
90
|
// distinction the auto_capture_compaction_* evidence lines carry.
|
|
@@ -118,7 +118,7 @@ async function knownRowsFor(reader: Reader): Promise<string> {
|
|
|
118
118
|
}
|
|
119
119
|
}
|
|
120
120
|
|
|
121
|
-
// Auto-capture cooldown, shared by EVERY setup() registration
|
|
121
|
+
// Auto-capture cooldown, shared by EVERY setup() registration: setup
|
|
122
122
|
// runs for more than one location, and per-closure cooldown maps made those
|
|
123
123
|
// registrations strangers - one compaction could pay for two model calls on
|
|
124
124
|
// one transcript. Same module-level shape as `turns` in src/lock.ts; the key
|
|
@@ -151,14 +151,14 @@ export function resetCaptureCooldowns(): void {
|
|
|
151
151
|
lastCaptureRun.clear();
|
|
152
152
|
}
|
|
153
153
|
|
|
154
|
-
// ---- capture trigger vocabulary
|
|
154
|
+
// ---- capture trigger vocabulary -------------------------------------
|
|
155
155
|
// Single source of truth for capture subscriptions. Both turn-end events were
|
|
156
156
|
// observed on the desktop service (test/fixtures/host-events.jsonl).
|
|
157
157
|
// test/event-fidelity.test.ts requires every trigger to appear in both that
|
|
158
158
|
// recording and the installed @opencode/schema manifest: a declared event
|
|
159
|
-
// alone is insufficient evidence that the host emits it
|
|
159
|
+
// alone is insufficient evidence that the host emits it.
|
|
160
160
|
// Identity triggers have a separate observed check in that test, combining
|
|
161
|
-
// this recording with the 2.2.2 move extract in host-session-move.json
|
|
161
|
+
// this recording with the 2.2.2 move extract in host-session-move.json.
|
|
162
162
|
export const TURN_END_EVENTS = [
|
|
163
163
|
"session.execution.succeeded",
|
|
164
164
|
"session.execution.interrupted",
|
|
@@ -192,7 +192,7 @@ export function configureAutoCapture(
|
|
|
192
192
|
let captureCleanup: Cleanup | undefined;
|
|
193
193
|
if (ctx.options?.autoCapture === true) {
|
|
194
194
|
const captureModelOpt = ctx.options.captureModel;
|
|
195
|
-
//
|
|
195
|
+
// an OMITTED captureModel no longer disables the subscription. It
|
|
196
196
|
// resolves per capture — the per-session ref last seen on session.context,
|
|
197
197
|
// else the host default — and only when both are missing does the pass
|
|
198
198
|
// skip. autoCapture:true is already the explicit opt-in; a second required
|
|
@@ -206,7 +206,7 @@ export function configureAutoCapture(
|
|
|
206
206
|
// picks the default-on arm (FINDINGS 2026-11-08 §4.4).
|
|
207
207
|
const guidedRules = ctx.options?.captureGuidedRules === true;
|
|
208
208
|
const captureOnCompact = ctx.options?.captureOnCompact !== false;
|
|
209
|
-
//
|
|
209
|
+
// two cost levers, both OFF by default until the benchmark says which
|
|
210
210
|
// way to set them. `captureOnSignal` skips a capture whose turn produced
|
|
211
211
|
// nothing durable; `captureDelta` mines only the turns since the last
|
|
212
212
|
// capture instead of re-reading the whole session every time.
|
|
@@ -229,7 +229,7 @@ export function configureAutoCapture(
|
|
|
229
229
|
);
|
|
230
230
|
} else {
|
|
231
231
|
const controller = new AbortController();
|
|
232
|
-
//
|
|
232
|
+
// passes in flight, tracked so teardown can stop them.
|
|
233
233
|
// Aborting the subscription is not enough on its own: `generate.text`
|
|
234
234
|
// does not take the signal, so a pass parked mid-model-call when the
|
|
235
235
|
// host disposes this instance wakes up afterwards and used to run the
|
|
@@ -248,18 +248,15 @@ export function configureAutoCapture(
|
|
|
248
248
|
// generate that outlives the bound is covered by (2), not by the
|
|
249
249
|
// drain: teardown never waits on the model.
|
|
250
250
|
//
|
|
251
|
-
//
|
|
252
|
-
//
|
|
253
|
-
//
|
|
254
|
-
//
|
|
255
|
-
//
|
|
256
|
-
//
|
|
257
|
-
//
|
|
258
|
-
//
|
|
259
|
-
//
|
|
260
|
-
// controlled A/B (#404): the abort fired on the healthy path, in the only
|
|
261
|
-
// window capture is allowed to run. Past-model passes are bounded by the
|
|
262
|
-
// drain instead, which is what the drain is for.
|
|
251
|
+
// Teardown distinguishes two phases (docs/adr/0005). A pass PARKED in
|
|
252
|
+
// `generate.text` when the host disposes must never write — the caller
|
|
253
|
+
// may remove the store the moment cleanup resolves. A pass that already
|
|
254
|
+
// HOLDS its model answer is different work: the answer exists, the gate
|
|
255
|
+
// is milliseconds of local work, and on `opencode run` nothing is being
|
|
256
|
+
// removed at all — the process simply exits. Aborting past-model passes
|
|
257
|
+
// is why most real CLI passes recorded `capture_cost` and no row (9 of
|
|
258
|
+
// 12 in one sample, 6 of 12 in a controlled A/B). Past-model passes are
|
|
259
|
+
// bounded by the drain instead, which is what the drain is for.
|
|
263
260
|
const DRAIN_LIMIT_MS = 1000;
|
|
264
261
|
type PassPhase = {
|
|
265
262
|
/** Set the instant `generate.text` resolves. */
|
|
@@ -282,28 +279,28 @@ export function configureAutoCapture(
|
|
|
282
279
|
return wrapped;
|
|
283
280
|
}
|
|
284
281
|
/**
|
|
285
|
-
* Teardown, in two phases (
|
|
282
|
+
* Teardown, in two phases (docs/adr/0005).
|
|
286
283
|
*
|
|
287
284
|
* 1. Abandon every pass that has not answered yet, then drain what is
|
|
288
285
|
* left, bounded. A parked `generate.text` can outlive any bound, so
|
|
289
|
-
* abandoning it is what makes the bound mean something:
|
|
286
|
+
* abandoning it is what makes the bound mean something: the caller
|
|
290
287
|
* may remove the store the moment cleanup resolves.
|
|
291
288
|
* 2. A pass that already holds its answer is never abandoned. It is
|
|
292
289
|
* drained instead, because its remaining work is the gate — local,
|
|
293
290
|
* milliseconds — and killing it is what lost most real CLI captures
|
|
294
|
-
* (
|
|
291
|
+
* (9 of 12 in one sample, 6 of 12 in a controlled A/B).
|
|
295
292
|
*
|
|
296
293
|
* The residual risk is a stated constant, not an accident. If the bound
|
|
297
294
|
* expires while a past-model pass is still working, cleanup returns and at
|
|
298
295
|
* most the gate run already in progress can land afterwards — the drain
|
|
299
296
|
* abandons the pass so its remaining candidates stop at the next boundary.
|
|
300
|
-
*
|
|
301
|
-
* that outlived the bound woke up and ran the whole gate
|
|
302
|
-
*
|
|
297
|
+
* Without the phase split the residual was unbounded in a different way:
|
|
298
|
+
* a generate that outlived the bound woke up and ran the whole gate.
|
|
299
|
+
* Neither version ever cuts a gate in half.
|
|
303
300
|
*
|
|
304
|
-
* Nothing here writes.
|
|
301
|
+
* Nothing here writes. The tested contract is that a disposed instance
|
|
305
302
|
* leaves no trace at all after cleanup, and an abandonment receipt would
|
|
306
|
-
* break it in all four of that
|
|
303
|
+
* break it in all four of that contract's cases — `appendLog` calls
|
|
307
304
|
* `ensureDir`, so the receipt resurrects a directory the caller deleted.
|
|
308
305
|
* An abandoned pass is instead identified by the gap it leaves: a
|
|
309
306
|
* `capture_cost` line with no later `capture_lag` for the same session is
|
|
@@ -344,7 +341,7 @@ export function configureAutoCapture(
|
|
|
344
341
|
const contextFn = (input: { sessionID: string }) =>
|
|
345
342
|
ctx.session?.context?.(input);
|
|
346
343
|
|
|
347
|
-
//
|
|
344
|
+
// model resolution: explicit option (captured above) wins; else the
|
|
348
345
|
// ref this session's context hook last carried; else the host default.
|
|
349
346
|
// Warn-once per setup when even the last resort is empty — a per-event
|
|
350
347
|
// warn would spam the log for every turn of a model-less session.
|
|
@@ -375,11 +372,11 @@ export function configureAutoCapture(
|
|
|
375
372
|
// Bind the capturing session for the synchronous stretches of this
|
|
376
373
|
// path - but NOT as a promise: the awaits below let another session
|
|
377
374
|
// move current, so the gate context and the persisted rows thread
|
|
378
|
-
// `sid` explicitly instead of reading it back from the global
|
|
375
|
+
// `sid` explicitly instead of reading it back from the global.
|
|
379
376
|
setCurrent({ sessionID: sid });
|
|
380
377
|
// The capture's dedup reads and the rows it writes partition by the
|
|
381
378
|
// CAPTURED session's repository — an unbound sid would otherwise
|
|
382
|
-
// read global-only and mine duplicates into the store (
|
|
379
|
+
// read global-only and mine duplicates into the store (in
|
|
383
380
|
// production the prompt hook already bound it firmly, so this is a
|
|
384
381
|
// no-op there). SYNC only: a lookup call here would break the
|
|
385
382
|
// zero-token promise of the capture tests.
|
|
@@ -413,13 +410,13 @@ export function configureAutoCapture(
|
|
|
413
410
|
): Promise<void> {
|
|
414
411
|
const captureGate = gate ?? bindCapture(sid);
|
|
415
412
|
const captureReader = captureGate.reader ?? readerFromSid(sid);
|
|
416
|
-
//
|
|
413
|
+
// resolve the model BEFORE any skip so every capture evidence
|
|
417
414
|
// line below can carry model= (cost attributable to a named model —
|
|
418
415
|
// the real answer to the cost-surprise concern that justified the
|
|
419
416
|
// required captureModel). Resolution itself is token-free.
|
|
420
417
|
const model = modelRef ?? sessionModel(sid) ?? hostDefault();
|
|
421
418
|
const modelTag = model ? `${model.providerID}/${model.id}` : undefined;
|
|
422
|
-
//
|
|
419
|
+
// an instance with no workspace cannot say which repository the
|
|
423
420
|
// mined rows belong to, and rows with no owner are exactly what the
|
|
424
421
|
// store refuses. Skip BEFORE the model call — no tokens spent on a
|
|
425
422
|
// capture that cannot be stored — and leave the reason in evidence.
|
|
@@ -450,9 +447,9 @@ export function configureAutoCapture(
|
|
|
450
447
|
);
|
|
451
448
|
return;
|
|
452
449
|
}
|
|
453
|
-
//
|
|
450
|
+
// the signal gate. The PORT moved it AFTER the context read
|
|
454
451
|
// (the POC ran it before): a user-stated spec with no tool activity
|
|
455
|
-
// is exactly the hint channel
|
|
452
|
+
// is exactly the hint channel and must not be skipped, and
|
|
456
453
|
// detecting it needs the messages. The read is a local host call;
|
|
457
454
|
// the expensive artifact the gate saves — the capture model call —
|
|
458
455
|
// is still saved.
|
|
@@ -460,8 +457,7 @@ export function configureAutoCapture(
|
|
|
460
457
|
// The turn this pass DESCRIBES. Completion must advance to this number,
|
|
461
458
|
// not to whatever the session has reached by then: a turn delivered
|
|
462
459
|
// while the model call is in flight was never in the prompt, and
|
|
463
|
-
// consuming it leaves that work unmined with nothing left to ask for it
|
|
464
|
-
// (#366 review).
|
|
460
|
+
// consuming it leaves that work unmined with nothing left to ask for it.
|
|
465
461
|
const turnAtStart = session(sid).turns;
|
|
466
462
|
let transcript = seeded;
|
|
467
463
|
let msgs = seededMsgs;
|
|
@@ -475,12 +471,12 @@ export function configureAutoCapture(
|
|
|
475
471
|
// past it by the old count.
|
|
476
472
|
const minedWhole = seededMsgs !== undefined;
|
|
477
473
|
// True when the context is no longer the array the cursor counted
|
|
478
|
-
//
|
|
474
|
+
// the offset names a transcript that does not exist, so
|
|
479
475
|
// the window below is the whole context, mined from the beginning.
|
|
480
476
|
let deltaRestart = false;
|
|
481
477
|
if (transcript.length < 200) {
|
|
482
478
|
msgs = await contextFn({ sessionID: sid });
|
|
483
|
-
//
|
|
479
|
+
// disposed while the host was answering. The drain in cleanup()
|
|
484
480
|
// waits a bound, not forever, so this is the normal outcome of a
|
|
485
481
|
// teardown during a slow context read — and everything below writes:
|
|
486
482
|
// the thin-transcript receipt below, then the model call. Silent, for
|
|
@@ -546,12 +542,12 @@ export function configureAutoCapture(
|
|
|
546
542
|
);
|
|
547
543
|
return; // too thin to mine reliably
|
|
548
544
|
}
|
|
549
|
-
//
|
|
545
|
+
// how stale is a capture? Distance from the newest message of
|
|
550
546
|
// the mined transcript to this instant - measured on whatever the
|
|
551
547
|
// trigger actually mined (the hook payload for compaction, the
|
|
552
548
|
// session context for idle), so both triggers' lag is comparable.
|
|
553
549
|
const lagMs = lagSince(msgs);
|
|
554
|
-
//
|
|
550
|
+
// partition what was mined, so the user's brief is labelled as
|
|
555
551
|
// the brief instead of blending into the evidence. Falls back to the
|
|
556
552
|
// single un-partitioned block when the work lines alone are too thin
|
|
557
553
|
// (a seeded transcript with no message array behind it), which keeps
|
|
@@ -561,12 +557,12 @@ export function configureAutoCapture(
|
|
|
561
557
|
const work = partitioned ? split.work : transcript;
|
|
562
558
|
const userProse = partitioned ? split.user : "";
|
|
563
559
|
// The user's turns, decoded from the message array rather than read back
|
|
564
|
-
// out of rendered text
|
|
560
|
+
// out of rendered text. Everything that vouches for "these
|
|
565
561
|
// are the user's own words" goes through this.
|
|
566
562
|
const userTurns = userTurnText(msgs);
|
|
567
563
|
// Hoisted out of the prompt literal so the disposal check below runs
|
|
568
564
|
// BEFORE the model call: this read is awaited, so it is its own window
|
|
569
|
-
// into a teardown
|
|
565
|
+
// into a teardown.
|
|
570
566
|
const knownRows = await knownRowsFor(captureReader);
|
|
571
567
|
if (controller.signal.aborted) return;
|
|
572
568
|
// S1: the ledger's unrecovered gate failures, in the same window the
|
|
@@ -578,22 +574,22 @@ export function configureAutoCapture(
|
|
|
578
574
|
// that nothing failed, and the prompt says so.
|
|
579
575
|
const attested = attestedGateFailures(session(sid), cursor.turn).map(
|
|
580
576
|
(f) =>
|
|
581
|
-
//
|
|
577
|
+
// Ledger args are raw tool input. A failing
|
|
582
578
|
// `bun test --token=sk-...` put the credential verbatim into the
|
|
583
579
|
// ATTESTED FAILURES block — the transcript scrub does not cover
|
|
584
580
|
// this input. Redact at construction, so the prompt renders the
|
|
585
581
|
// safe string AND the citation check compares against the same
|
|
586
|
-
// representation the model was shown.
|
|
582
|
+
// representation the model was shown (docs/adr/0006).
|
|
587
583
|
redactSecrets(f.arg ? `${f.cmd} — ${f.arg}` : f.cmd),
|
|
588
584
|
);
|
|
589
|
-
//
|
|
590
|
-
//
|
|
591
|
-
//
|
|
592
|
-
//
|
|
593
|
-
//
|
|
594
|
-
//
|
|
595
|
-
//
|
|
596
|
-
//
|
|
585
|
+
// A lesson citation must copy a COMPLETE displayed field. Substring
|
|
586
|
+
// presence cannot establish that the cited command ran:
|
|
587
|
+
// `includes("tsc")` accepted a lesson citing `tsc` when the only
|
|
588
|
+
// failure was `bun test --test-name-pattern tsc`. The list renders
|
|
589
|
+
// `cmd — arg`; membership is tested against each whole entry, its
|
|
590
|
+
// cmd, and its arg — never a fragment. `tsc` is none of those for
|
|
591
|
+
// that failure and is refused; the cmd-only citation the prompt's own
|
|
592
|
+
// example uses still passes.
|
|
597
593
|
const lessonSet = new Set<string>();
|
|
598
594
|
for (const f of attested) {
|
|
599
595
|
lessonSet.add(normWs(f).toLowerCase());
|
|
@@ -605,7 +601,7 @@ export function configureAutoCapture(
|
|
|
605
601
|
}
|
|
606
602
|
// Hoisted so its length can be billed below.
|
|
607
603
|
// Redact the COMPLETE transcript, THEN apply the character budget
|
|
608
|
-
|
|
604
|
+
//. Cropping first can start the window INSIDE a credential:
|
|
609
605
|
// a PEM body whose BEGIN marker fell off, or a token whose prefix
|
|
610
606
|
// fell off, matches no pattern — buildCapturePrompt's own scrub
|
|
611
607
|
// (kept, defense in depth) cannot recognize a fragment.
|
|
@@ -622,17 +618,17 @@ export function configureAutoCapture(
|
|
|
622
618
|
prompt: capturePrompt,
|
|
623
619
|
});
|
|
624
620
|
// The phase boundary. From here the answer exists, so cleanup stops
|
|
625
|
-
// abandoning this pass and drains it instead
|
|
621
|
+
// abandoning this pass and drains it instead. Set before the next
|
|
626
622
|
// await, so a disposal during anything below cannot be missed.
|
|
627
623
|
phase.pastModel = true;
|
|
628
624
|
const text = typeof out === "string" ? out : (out?.text ?? "");
|
|
629
|
-
//
|
|
625
|
+
// abandoned while the model call was in flight. Stop here — the
|
|
630
626
|
// gate, the rows and the receipts below all write to a store the
|
|
631
627
|
// caller may already have removed. Silent on purpose: a receipt here
|
|
632
628
|
// is the ENOENT teardown noise this check exists to eliminate, and
|
|
633
629
|
// the drain in cleanup means the pass is finished, not lost mid-air.
|
|
634
630
|
if (phase.abandoned) return;
|
|
635
|
-
//
|
|
631
|
+
// bill our own call. `generate.text` resolves to `{ text }` and
|
|
636
632
|
// nothing else — no `usage`, no `tokens` (probed against the running
|
|
637
633
|
// host) — and capture is not part of any session's event stream, so a
|
|
638
634
|
// meter reading the session reports zero for it. chars/4 is an
|
|
@@ -664,7 +660,7 @@ export function configureAutoCapture(
|
|
|
664
660
|
// the model phrases it but cannot veto it, and a quote the user never
|
|
665
661
|
// wrote is refused at the write boundary (retriable, not silent).
|
|
666
662
|
// The scanned text is the structured USER turns and nothing else
|
|
667
|
-
//
|
|
663
|
+
// assistant output never enters the haystack, so a stored
|
|
668
664
|
// quote can only be what the user said. Filtering rendered lines by a
|
|
669
665
|
// `user:` prefix did not do this — it accepted a `user:` label quoted
|
|
670
666
|
// INSIDE an assistant message as provenance.
|
|
@@ -676,7 +672,7 @@ export function configureAutoCapture(
|
|
|
676
672
|
// no roles there is nothing to vouch for, so the lane stays shut
|
|
677
673
|
// rather than minting a row from prose of unknown origin.
|
|
678
674
|
//
|
|
679
|
-
//
|
|
675
|
+
// the receipt alone does not shut it. A guided
|
|
680
676
|
// candidate the MODEL supplied would still have been stored with its
|
|
681
677
|
// unverified quote, so with no user turn nothing is attributable and
|
|
682
678
|
// the guided flag plus the quote come off. The distilled prose stays:
|
|
@@ -727,7 +723,7 @@ export function configureAutoCapture(
|
|
|
727
723
|
// Lenient check (default): a guided "original" must appear in the
|
|
728
724
|
// user's own turns. The prompt asks for a quote "copied VERBATIM from
|
|
729
725
|
// a user: line or the REQUESTS block", so the haystack is exactly that
|
|
730
|
-
// (
|
|
726
|
+
// (review: the mined WORK text used to be in here too, which
|
|
731
727
|
// vouched for a quote lifted out of assistant output). Whitespace is
|
|
732
728
|
// normalised — the model may collapse runs of spaces. A failed check
|
|
733
729
|
// drops the field, never the row: the distilled prose still
|
|
@@ -742,15 +738,15 @@ export function configureAutoCapture(
|
|
|
742
738
|
c.original = undefined;
|
|
743
739
|
}
|
|
744
740
|
}
|
|
745
|
-
//
|
|
741
|
+
// availability before authority. A candidate that restates a
|
|
746
742
|
// tracked file, or names a command the project already declares, is
|
|
747
743
|
// readable by the next session without a row — and capture costs about a
|
|
748
744
|
// third of a session's own generation.
|
|
749
745
|
//
|
|
750
|
-
//
|
|
746
|
+
// Built on FIRST USE, not on every pass. The build is a
|
|
751
747
|
// synchronous `git ls-files` plus a read of every tracked text file —
|
|
752
748
|
// measured here at 108 ms for 218 files and 2.11 MB — and the pass that
|
|
753
|
-
// needs it least is the one that
|
|
749
|
+
// needs it least is the one that would pay for it: a model answer of
|
|
754
750
|
// `[]` still scanned the tree. One build per pass is kept, so the cost is
|
|
755
751
|
// now bounded by the candidates that exist.
|
|
756
752
|
let availableIndex: AvailabilityIndex | undefined;
|
|
@@ -783,9 +779,9 @@ export function configureAutoCapture(
|
|
|
783
779
|
// recall loss here.
|
|
784
780
|
let lessonsKept = 0;
|
|
785
781
|
let lessonsRefused = 0;
|
|
786
|
-
//
|
|
782
|
+
// rows tagged `restatable` this pass. Counted, never dropped.
|
|
787
783
|
// Two numbers, because they are two different facts and one field that
|
|
788
|
-
// silently means "verdicts" reads as "rows"
|
|
784
|
+
// silently means "verdicts" reads as "rows". A
|
|
789
785
|
// verdict lands on candidates the write gate then refuses — a dup, a
|
|
790
786
|
// credential-shaped scope — and a refused row carries no tag, so the
|
|
791
787
|
// verdict count is an upper bound on the tagged count, never equal by
|
|
@@ -821,20 +817,20 @@ export function configureAutoCapture(
|
|
|
821
817
|
// Between candidates, never inside a gate run: a supersession that
|
|
822
818
|
// half-applied is a store the next session cannot trust. The phase
|
|
823
819
|
// flag, not the signal: this loop only runs once the answer exists,
|
|
824
|
-
// and cleanup stops abandoning such a pass
|
|
820
|
+
// and cleanup stops abandoning such a pass.
|
|
825
821
|
if (phase.abandoned) return;
|
|
826
|
-
//
|
|
827
|
-
// past the write
|
|
828
|
-
//
|
|
829
|
-
//
|
|
830
|
-
//
|
|
822
|
+
// the availability verdict TAGS the row. It used to `continue`
|
|
823
|
+
// past the write. A lexical match was never strong enough to delete
|
|
824
|
+
// a fact — 29 of the 30 rows a pure-conflict refusal rejected were
|
|
825
|
+
// new facts, and a silently dropped candidate leaves no trace to
|
|
826
|
+
// recover from.
|
|
831
827
|
//
|
|
832
828
|
// The row now goes through the same write gate as every other row, and
|
|
833
829
|
// the tag is what retrieval acts on: `restatable` rows sort last, so a
|
|
834
830
|
// full injection block gives them up first and a spare one keeps them.
|
|
835
831
|
// A wrong verdict costs one row. A right one saves a slot. That is the
|
|
836
|
-
// first
|
|
837
|
-
//
|
|
832
|
+
// first shape of this where BOTH error directions are survivable:
|
|
833
|
+
// an earlier one lost facts silently instead of expensively.
|
|
838
834
|
const avail = availability().check(c.content);
|
|
839
835
|
if (avail) {
|
|
840
836
|
availVerdicts++;
|
|
@@ -880,7 +876,7 @@ export function configureAutoCapture(
|
|
|
880
876
|
captureGate.evidenceContext,
|
|
881
877
|
);
|
|
882
878
|
}
|
|
883
|
-
//
|
|
879
|
+
// a numeric claim capture INFERRED (the user did not state
|
|
884
880
|
// it) that names a constant the tree also names is checked before it
|
|
885
881
|
// is stored. Only a contradiction refuses; "undecidable" is the
|
|
886
882
|
// transport case and keeps the row, labelled.
|
|
@@ -932,9 +928,9 @@ export function configureAutoCapture(
|
|
|
932
928
|
...(original ? { original } : {}),
|
|
933
929
|
tags: [
|
|
934
930
|
AUTO_CAPTURE_TAG,
|
|
935
|
-
//
|
|
931
|
+
// the tree states this too. Stored anyway, sorted last.
|
|
936
932
|
...(avail ? [RESTATABLE_TAG] : []),
|
|
937
|
-
//
|
|
933
|
+
// the ONE case that earns `[code-checked]` — an inferred
|
|
938
934
|
// numeric claim that agreed with the tree. Absent everywhere
|
|
939
935
|
// else, which is what makes `[unverified]` mean something
|
|
940
936
|
// instead of decorate everything.
|
|
@@ -975,7 +971,7 @@ export function configureAutoCapture(
|
|
|
975
971
|
: `auto_capture_${outcome.action}`,
|
|
976
972
|
// A blocked credential-shaped scope must not reach the evidence log either.
|
|
977
973
|
// The promoted line also carries the audit fault when the
|
|
978
|
-
// write_promoted line fell (
|
|
974
|
+
// write_promoted line fell (review — capture has no
|
|
979
975
|
// reply to caveat, so this line is the trail's only note).
|
|
980
976
|
{
|
|
981
977
|
session: sid,
|
|
@@ -1022,10 +1018,10 @@ export function configureAutoCapture(
|
|
|
1022
1018
|
}
|
|
1023
1019
|
}
|
|
1024
1020
|
}
|
|
1025
|
-
//
|
|
1026
|
-
//
|
|
1027
|
-
//
|
|
1028
|
-
//
|
|
1021
|
+
// The scan is visible in the trail. A synchronous tree read must
|
|
1022
|
+
// never run every pass with no record that it happened: one line per
|
|
1023
|
+
// pass that actually built the index, naming files, bytes and
|
|
1024
|
+
// milliseconds.
|
|
1029
1025
|
if (availableIndex) {
|
|
1030
1026
|
const scan = availableIndex.scanned();
|
|
1031
1027
|
await record(
|
|
@@ -1058,7 +1054,7 @@ export function configureAutoCapture(
|
|
|
1058
1054
|
captureGate.evidenceContext,
|
|
1059
1055
|
modelTag,
|
|
1060
1056
|
);
|
|
1061
|
-
//
|
|
1057
|
+
// the window is consumed. Advance when a capture RAN, whatever it
|
|
1062
1058
|
// found — zero candidates is an answer, and re-mining an answered
|
|
1063
1059
|
// window every turn is precisely the cost this cursor exists to remove.
|
|
1064
1060
|
// A skip returns early and leaves the cursor where it was, so the next
|
|
@@ -1099,7 +1095,7 @@ export function configureAutoCapture(
|
|
|
1099
1095
|
// receipt of repo A's capture as repo B's evidence.
|
|
1100
1096
|
let opGate: GateContext | undefined;
|
|
1101
1097
|
// Created before the first await so cleanup can see this pass in the
|
|
1102
|
-
// window before the model call,
|
|
1098
|
+
// window before the model call, still applies in full.
|
|
1103
1099
|
const phase = newPhase();
|
|
1104
1100
|
try {
|
|
1105
1101
|
opGate = bindCapture(sid);
|
|
@@ -1109,7 +1105,7 @@ export function configureAutoCapture(
|
|
|
1109
1105
|
);
|
|
1110
1106
|
} catch (err) {
|
|
1111
1107
|
// Teardown is not a capture failure: after cleanup the store may
|
|
1112
|
-
// be gone, and a receipt here would be the ENOENT noise
|
|
1108
|
+
// be gone, and a receipt here would be the ENOENT noise
|
|
1113
1109
|
// reports. The abort check inside captureSession is the signal.
|
|
1114
1110
|
if (controller.signal.aborted) return;
|
|
1115
1111
|
// Fail-closed for the SESSION, never silent in the store: the
|
|
@@ -1139,7 +1135,7 @@ export function configureAutoCapture(
|
|
|
1139
1135
|
// The signal stops NEW passes (the subscription checks it before
|
|
1140
1136
|
// dispatch, and the compaction seam checks it before starting). Passes
|
|
1141
1137
|
// already started are handled by drainInFlight in two phases: abandon
|
|
1142
|
-
// the unanswered ones, drain the answered ones
|
|
1138
|
+
// the unanswered ones, drain the answered ones.
|
|
1143
1139
|
controller.abort();
|
|
1144
1140
|
await drainInFlight();
|
|
1145
1141
|
};
|
|
@@ -1149,7 +1145,7 @@ export function configureAutoCapture(
|
|
|
1149
1145
|
// cooldown names the trigger, so measuring a compaction capture is
|
|
1150
1146
|
// not confounded by an idle fire moments before - and lives at
|
|
1151
1147
|
// module level, so a second setup() cannot double-pay one
|
|
1152
|
-
// compaction
|
|
1148
|
+
// compaction.
|
|
1153
1149
|
if (captureOnCompact) {
|
|
1154
1150
|
onCompactCapture = (sid, messages) => {
|
|
1155
1151
|
if (controller.signal.aborted) return;
|
|
@@ -1159,13 +1155,13 @@ export function configureAutoCapture(
|
|
|
1159
1155
|
// before guarded() starts awaiting.
|
|
1160
1156
|
const opGate = bindCapture(sid);
|
|
1161
1157
|
// Tracked, not just fired: cleanup must be able to drain this pass
|
|
1162
|
-
|
|
1158
|
+
//, which is the only reason the seam keeps the promise.
|
|
1163
1159
|
const phase = newPhase();
|
|
1164
1160
|
void track(
|
|
1165
1161
|
// The predicate, not just the checks inside the pass: a rejection
|
|
1166
1162
|
// from the awaited model call skips every abort check that follows
|
|
1167
1163
|
// it and lands in the generic reporter, which would append
|
|
1168
|
-
// `hook_error` to a store cleanup() has already released
|
|
1164
|
+
// `hook_error` to a store cleanup() has already released.
|
|
1169
1165
|
guarded(
|
|
1170
1166
|
"session.compaction (auto-capture)",
|
|
1171
1167
|
() =>
|
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
// Per-session model registry
|
|
1
|
+
// Per-session model registry. The SDK's SessionRequest declares a
|
|
2
2
|
// readonly `model: Model.Ref`, so EVERY session hook the plugin registers
|
|
3
3
|
// already carries the session's actual model — the session.context hook reads
|
|
4
4
|
// event.sessionID and never event.model, and auto-capture required a second
|
|
5
5
|
// config key (captureModel) it could have inherited for free. This module is
|
|
6
6
|
// the seam: events.ts records the ref the host delivered, capture/runtime.ts
|
|
7
7
|
// resolves an omitted captureModel through it before falling back to the host
|
|
8
|
-
// default. Module-level like `lastCaptureRun` in runtime.ts
|
|
8
|
+
// default. Module-level like `lastCaptureRun` in runtime.ts: setup runs
|
|
9
9
|
// for more than one location, and a per-closure map would make those
|
|
10
10
|
// registrations strangers to the model the host just told them.
|
|
11
11
|
export interface SessionModelRef {
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
// transcript — split from src/capture.ts
|
|
1
|
+
// transcript — split from src/capture.ts. Declaration bodies are unchanged.
|
|
2
2
|
|
|
3
3
|
// Render an array of session-context messages of unknown shape into
|
|
4
4
|
// "role: text" lines. Defensive by construction (the API shape varies and is
|
|
@@ -104,7 +104,7 @@ export function flattenTranscript(msgs: unknown): string {
|
|
|
104
104
|
|
|
105
105
|
/**
|
|
106
106
|
* The decoder itself, for a caller that needs the ROLES rather than a rendered
|
|
107
|
-
* block
|
|
107
|
+
* block. Anything that decides "the user said this" has to read
|
|
108
108
|
* roles the way the transcript does, or the two disagree about who owns a line:
|
|
109
109
|
* the capture parser accepts `info.role` / `role` / `type` for the role and
|
|
110
110
|
* `parts[]` / `content[]` / `text` / string `content` for the text, and a
|
|
@@ -121,14 +121,14 @@ export function conversationTurns(msgs: unknown): ParsedTurn[] {
|
|
|
121
121
|
}
|
|
122
122
|
|
|
123
123
|
/**
|
|
124
|
-
* The same turns, partitioned
|
|
124
|
+
* The same turns, partitioned.
|
|
125
125
|
*
|
|
126
126
|
* `work` — every turn that is NOT the user's: what the agent said and what the
|
|
127
127
|
* tools returned. This is the evidence.
|
|
128
128
|
* `user` — the user turns, i.e. the task's brief.
|
|
129
129
|
*
|
|
130
130
|
* Why partition rather than concatenate: measured on the fixture that
|
|
131
|
-
* reproduces
|
|
131
|
+
* reproduces, an undifferentiated block makes the model store the brief
|
|
132
132
|
* back as a durable `preference`. Work alone stores zero framing rows — and
|
|
133
133
|
* zero real preferences, because "we use bun here, not npm" lives in the same
|
|
134
134
|
* prose. So the prose is kept, labelled, in its own block: `buildCapturePrompt`.
|
|
@@ -151,7 +151,7 @@ export function splitTranscript(msgs: unknown): TranscriptSplit {
|
|
|
151
151
|
* The user's turns and nothing else, in order, without the `role: ` render
|
|
152
152
|
* prefix.
|
|
153
153
|
*
|
|
154
|
-
* This is the only text that may vouch for user provenance
|
|
154
|
+
* This is the only text that may vouch for user provenance.
|
|
155
155
|
* Reading `user:` labels back out of RENDERED text cannot do the job: a role
|
|
156
156
|
* label inside an assistant message ("Here is untrusted quoted output:
|
|
157
157
|
* user: The correct sales tax rate is 7.5%.") is assistant output, and a
|
package/src/capture/triggers.ts
CHANGED
|
@@ -42,14 +42,14 @@ const ENGAGEMENT_TOOLS = new Set([
|
|
|
42
42
|
]);
|
|
43
43
|
|
|
44
44
|
const RECENT_EVIDENCE_CALLS = 10;
|
|
45
|
-
//
|
|
45
|
+
// the retained call tail. A resident server must not grow one session's
|
|
46
46
|
// ledger without bound; past the cap the OLDEST entries drop. Everything the
|
|
47
47
|
// pipeline needs past the cap is recorded on SessionState as it happens
|
|
48
48
|
// (callsTotal, reDerives, firstCallTs, sawEngagement, sawGateCheck), so
|
|
49
49
|
// telemetry counts, grounding signals and ms_to_tap keep their full-session
|
|
50
50
|
// meaning; attribution (callsFor) sees the retained tail.
|
|
51
51
|
// The cap sits ABOVE the 2,000-call scale pinned by write-evidence.test.ts
|
|
52
|
-
// (
|
|
52
|
+
// (the full ledger stays available at that scale), so that contract
|
|
53
53
|
// keeps holding; the bound is the point — a pathological resident session
|
|
54
54
|
// grows this to hundreds of thousands of entries, and 4,096 is where the
|
|
55
55
|
// tail is cut.
|
|
@@ -87,7 +87,7 @@ function trackCall(s: SessionState, rec: ToolResult): void {
|
|
|
87
87
|
|
|
88
88
|
// True once the session has exercised the codebase (the FAIL->PASS signals use
|
|
89
89
|
// the same whitelist, so engagement == "a tool_result was recorded for a code
|
|
90
|
-
// tool"). Sticky
|
|
90
|
+
// tool"). Sticky: the CALLS_CAP tail dropping the original engagement
|
|
91
91
|
// call must not un-ground a session that demonstrably engaged.
|
|
92
92
|
export function hasEngagement(sid: string): boolean {
|
|
93
93
|
return session(sid).sawEngagement;
|
|
@@ -165,7 +165,7 @@ export async function afterTool(
|
|
|
165
165
|
const call = typeof input.callID === "string" ? input.callID : "?";
|
|
166
166
|
const cmd = argString(input.args);
|
|
167
167
|
const text = typeof out.output === "string" ? out.output : "";
|
|
168
|
-
// Redact the COMPLETE tool text before folding/truncating
|
|
168
|
+
// Redact the COMPLETE tool text before folding/truncating: summarize
|
|
169
169
|
// first would cut a token at the 80-char boundary or strip a PEM END marker,
|
|
170
170
|
// and the surviving fragment would persist byte-for-byte in evidence.
|
|
171
171
|
const safeText = text ? redactSecrets(text) : "";
|
|
@@ -186,7 +186,7 @@ export async function afterTool(
|
|
|
186
186
|
|
|
187
187
|
// Generic capture (data, not chat). The output_summary is telemetry about
|
|
188
188
|
// the call (tool name + a short, redacted glimpse); the session/repo scoping
|
|
189
|
-
// of evidence reads is tracked separately (
|
|
189
|
+
// of evidence reads is tracked separately ( acceptance,).
|
|
190
190
|
if (
|
|
191
191
|
["grep", "glob", "read", "edit", "write", "bash", "shell"].includes(tool)
|
|
192
192
|
) {
|
|
@@ -289,7 +289,7 @@ export async function onCompacting(input: AfterInput): Promise<void> {
|
|
|
289
289
|
}
|
|
290
290
|
|
|
291
291
|
// IDs for callers that explicitly need the ledger: the retained tail (capped
|
|
292
|
-
// at CALLS_CAP, oldest dropped first —
|
|
292
|
+
// at CALLS_CAP, oldest dropped first —). Production write contexts use
|
|
293
293
|
// writeEvidence so they do not allocate this growing list.
|
|
294
294
|
export function evidenceCalls(sid: string): string[] {
|
|
295
295
|
return session(sid).calls.map((c) => c.call);
|
|
@@ -316,7 +316,7 @@ export function writeEvidence(sid: string): {
|
|
|
316
316
|
|
|
317
317
|
// The per-session tool ledger for memory attribution (src/attribution.ts):
|
|
318
318
|
// the retained tail, capped at CALLS_CAP with the oldest calls dropped first
|
|
319
|
-
|
|
319
|
+
//, so a resident server bounds memory instead of holding every call.
|
|
320
320
|
export function callsFor(sid: string): ToolResult[] {
|
|
321
321
|
return session(sid).calls;
|
|
322
322
|
}
|