@claudexor/orchestrator 3.20.1 → 3.23.0
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/dist/attemptFinalize.d.ts +14 -101
- package/dist/attemptFinalize.d.ts.map +1 -1
- package/dist/attemptFinalize.js +7 -328
- package/dist/attemptFinalize.js.map +1 -1
- package/dist/candidateEvidence.d.ts +15 -6
- package/dist/candidateEvidence.d.ts.map +1 -1
- package/dist/candidateEvidence.js +1 -1
- package/dist/candidateEvidence.js.map +1 -1
- package/dist/candidateOutputs.d.ts +7 -3
- package/dist/candidateOutputs.d.ts.map +1 -1
- package/dist/candidateOutputs.js +4 -1
- package/dist/candidateOutputs.js.map +1 -1
- package/dist/candidateReview.d.ts.map +1 -1
- package/dist/candidateReview.js +3 -1
- package/dist/candidateReview.js.map +1 -1
- package/dist/candidateTerminals.d.ts +4 -0
- package/dist/candidateTerminals.d.ts.map +1 -1
- package/dist/candidateTerminals.js +18 -7
- package/dist/candidateTerminals.js.map +1 -1
- package/dist/candidateWorkProduct.d.ts.map +1 -1
- package/dist/candidateWorkProduct.js +6 -6
- package/dist/candidateWorkProduct.js.map +1 -1
- package/dist/carrier-planner.d.ts +94 -0
- package/dist/carrier-planner.d.ts.map +1 -0
- package/dist/carrier-planner.js +111 -0
- package/dist/carrier-planner.js.map +1 -0
- package/dist/continuation-custody.d.ts +57 -0
- package/dist/continuation-custody.d.ts.map +1 -0
- package/dist/continuation-custody.js +151 -0
- package/dist/continuation-custody.js.map +1 -0
- package/dist/continuation-evidence-io.d.ts +18 -0
- package/dist/continuation-evidence-io.d.ts.map +1 -0
- package/dist/continuation-evidence-io.js +167 -0
- package/dist/continuation-evidence-io.js.map +1 -0
- package/dist/continuation-evidence.d.ts +81 -0
- package/dist/continuation-evidence.d.ts.map +1 -0
- package/dist/continuation-evidence.js +122 -0
- package/dist/continuation-evidence.js.map +1 -0
- package/dist/continuation-input.d.ts +10 -0
- package/dist/continuation-input.d.ts.map +1 -0
- package/dist/continuation-input.js +69 -0
- package/dist/continuation-input.js.map +1 -0
- package/dist/continue-from.d.ts +41 -0
- package/dist/continue-from.d.ts.map +1 -0
- package/dist/continue-from.js +292 -0
- package/dist/continue-from.js.map +1 -0
- package/dist/continuity-notice.d.ts +42 -0
- package/dist/continuity-notice.d.ts.map +1 -0
- package/dist/continuity-notice.js +42 -0
- package/dist/continuity-notice.js.map +1 -0
- package/dist/continuity-terminal.d.ts +19 -0
- package/dist/continuity-terminal.d.ts.map +1 -0
- package/dist/continuity-terminal.js +34 -0
- package/dist/continuity-terminal.js.map +1 -0
- package/dist/credential-cooldown.d.ts.map +1 -1
- package/dist/credential-cooldown.js +8 -3
- package/dist/credential-cooldown.js.map +1 -1
- package/dist/credential-differential.d.ts +1 -0
- package/dist/credential-differential.d.ts.map +1 -1
- package/dist/credential-differential.js +32 -4
- package/dist/credential-differential.js.map +1 -1
- package/dist/deepScanReducer.d.ts +4 -1
- package/dist/deepScanReducer.d.ts.map +1 -1
- package/dist/deepScanReducer.js +10 -5
- package/dist/deepScanReducer.js.map +1 -1
- package/dist/delegatedHome.d.ts +30 -1
- package/dist/delegatedHome.d.ts.map +1 -1
- package/dist/delegatedHome.js +37 -2
- package/dist/delegatedHome.js.map +1 -1
- package/dist/delegationFailure.d.ts +4 -3
- package/dist/delegationFailure.d.ts.map +1 -1
- package/dist/delegationFailure.js +25 -24
- package/dist/delegationFailure.js.map +1 -1
- package/dist/directoryCandidate.d.ts +2 -3
- package/dist/directoryCandidate.d.ts.map +1 -1
- package/dist/directoryCandidate.js +3 -2
- package/dist/directoryCandidate.js.map +1 -1
- package/dist/inrun-continuity-carrier.d.ts +76 -0
- package/dist/inrun-continuity-carrier.d.ts.map +1 -0
- package/dist/inrun-continuity-carrier.js +218 -0
- package/dist/inrun-continuity-carrier.js.map +1 -0
- package/dist/inrun-continuity-thread.d.ts +8 -0
- package/dist/inrun-continuity-thread.d.ts.map +1 -0
- package/dist/inrun-continuity-thread.js +23 -0
- package/dist/inrun-continuity-thread.js.map +1 -0
- package/dist/inrun-continuity-types.d.ts +105 -0
- package/dist/inrun-continuity-types.d.ts.map +1 -0
- package/dist/inrun-continuity-types.js +2 -0
- package/dist/inrun-continuity-types.js.map +1 -0
- package/dist/inrun-continuity.d.ts +79 -0
- package/dist/inrun-continuity.d.ts.map +1 -0
- package/dist/inrun-continuity.js +465 -0
- package/dist/inrun-continuity.js.map +1 -0
- package/dist/inrun-continuity.test-support.d.ts +374 -0
- package/dist/inrun-continuity.test-support.d.ts.map +1 -0
- package/dist/inrun-continuity.test-support.js +198 -0
- package/dist/inrun-continuity.test-support.js.map +1 -0
- package/dist/inrun-retained-output.d.ts +9 -0
- package/dist/inrun-retained-output.d.ts.map +1 -0
- package/dist/inrun-retained-output.js +16 -0
- package/dist/inrun-retained-output.js.map +1 -0
- package/dist/interaction.d.ts +1 -1
- package/dist/interaction.d.ts.map +1 -1
- package/dist/interaction.js +6 -1
- package/dist/interaction.js.map +1 -1
- package/dist/modelGovernance.d.ts +4 -0
- package/dist/modelGovernance.d.ts.map +1 -1
- package/dist/modelGovernance.js +27 -1
- package/dist/modelGovernance.js.map +1 -1
- package/dist/orchestrator-credentials.d.ts +1 -1
- package/dist/orchestrator-credentials.d.ts.map +1 -1
- package/dist/orchestrator-credentials.js +4 -3
- package/dist/orchestrator-credentials.js.map +1 -1
- package/dist/orchestrator.d.ts +4 -4
- package/dist/orchestrator.d.ts.map +1 -1
- package/dist/orchestrator.js +261 -235
- package/dist/orchestrator.js.map +1 -1
- package/dist/persistedPatch.d.ts +55 -0
- package/dist/persistedPatch.d.ts.map +1 -0
- package/dist/persistedPatch.js +132 -0
- package/dist/persistedPatch.js.map +1 -0
- package/dist/planFinalize.d.ts +37 -0
- package/dist/planFinalize.d.ts.map +1 -0
- package/dist/planFinalize.js +94 -0
- package/dist/planFinalize.js.map +1 -0
- package/dist/planRun.d.ts +2 -28
- package/dist/planRun.d.ts.map +1 -1
- package/dist/planRun.js +5 -88
- package/dist/planRun.js.map +1 -1
- package/dist/plannerAttempt.d.ts +4 -1
- package/dist/plannerAttempt.d.ts.map +1 -1
- package/dist/plannerAttempt.js +9 -4
- package/dist/plannerAttempt.js.map +1 -1
- package/dist/prompt-framing.d.ts +1 -1
- package/dist/prompt-framing.d.ts.map +1 -1
- package/dist/prompt-framing.js.map +1 -1
- package/dist/reviewerEffort.d.ts +41 -0
- package/dist/reviewerEffort.d.ts.map +1 -0
- package/dist/reviewerEffort.js +37 -0
- package/dist/reviewerEffort.js.map +1 -0
- package/dist/reviewerPanel.d.ts +5 -5
- package/dist/reviewerPanel.d.ts.map +1 -1
- package/dist/reviewerPanel.js +22 -50
- package/dist/reviewerPanel.js.map +1 -1
- package/dist/run-input-resolution.d.ts.map +1 -1
- package/dist/run-input-resolution.js +10 -0
- package/dist/run-input-resolution.js.map +1 -1
- package/dist/runAdmission.js +1 -1
- package/dist/runAdmission.js.map +1 -1
- package/dist/runEventLog.d.ts.map +1 -1
- package/dist/runEventLog.js +5 -0
- package/dist/runEventLog.js.map +1 -1
- package/dist/runFactsBuilder.d.ts.map +1 -1
- package/dist/runFactsBuilder.js +11 -2
- package/dist/runFactsBuilder.js.map +1 -1
- package/dist/runSupport.d.ts +2 -1
- package/dist/runSupport.d.ts.map +1 -1
- package/dist/runSupport.js +2 -1
- package/dist/runSupport.js.map +1 -1
- package/dist/runTelemetryWriter.d.ts.map +1 -1
- package/dist/runTelemetryWriter.js +7 -2
- package/dist/runTelemetryWriter.js.map +1 -1
- package/dist/runTerminalResults.d.ts +6 -2
- package/dist/runTerminalResults.d.ts.map +1 -1
- package/dist/runTerminalResults.js +8 -1
- package/dist/runTerminalResults.js.map +1 -1
- package/dist/runTerminals.d.ts.map +1 -1
- package/dist/runTerminals.js +6 -5
- package/dist/runTerminals.js.map +1 -1
- package/dist/secretDiff.d.ts +67 -27
- package/dist/secretDiff.d.ts.map +1 -1
- package/dist/secretDiff.js +143 -113
- package/dist/secretDiff.js.map +1 -1
- package/dist/session-capsule.d.ts +29 -0
- package/dist/session-capsule.d.ts.map +1 -0
- package/dist/session-capsule.js +86 -0
- package/dist/session-capsule.js.map +1 -0
- package/dist/workReportEnvelope.d.ts +123 -0
- package/dist/workReportEnvelope.d.ts.map +1 -0
- package/dist/workReportEnvelope.js +362 -0
- package/dist/workReportEnvelope.js.map +1 -0
- package/package.json +17 -17
- package/dist/effortGovernance.d.ts +0 -13
- package/dist/effortGovernance.d.ts.map +0 -1
- package/dist/effortGovernance.js +0 -7
- package/dist/effortGovernance.js.map +0 -1
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import type { EventLog } from "@claudexor/event-log";
|
|
2
|
+
import { type EnvelopeCustody, type RunOutcomeFacts, type WorkspaceEnvelope } from "@claudexor/schema";
|
|
3
|
+
import { type CreateEnvelopeOptions, type WorkspaceManager } from "@claudexor/workspace";
|
|
4
|
+
import type { CandidateRun } from "./candidateEvidence.js";
|
|
5
|
+
import type { ContinueFromSource } from "./continue-from.js";
|
|
6
|
+
import type { AnnouncedRunContext } from "./runTerminalContext.js";
|
|
7
|
+
/** The per-attempt native session capsule file, written by the in-run
|
|
8
|
+
* continuation loop when `started` reports a native session id. */
|
|
9
|
+
export declare function sessionCapsuleFile(attemptDir: string): string;
|
|
10
|
+
/** What the daemon hands a run about continuation (`RunInput.continuation`). */
|
|
11
|
+
export interface RunContinuation {
|
|
12
|
+
/** Keep this run's stopped work for `continueFrom`. Only a daemon-owned run
|
|
13
|
+
* sets it: only the daemon admits a successor or discards a kept envelope. */
|
|
14
|
+
retain: boolean;
|
|
15
|
+
/** The predecessor's retained envelope this run adopts (`continueFrom`). */
|
|
16
|
+
adopt?: EnvelopeCustody | null;
|
|
17
|
+
/** The predecessor whose work the first candidate attempt continues
|
|
18
|
+
* (`continueFrom`); consumed by that attempt (`continue-from.ts`). */
|
|
19
|
+
from?: ContinueFromSource | null;
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* The custody hooks of one run's candidate slot: `envelope` creates (or, for a
|
|
23
|
+
* `continueFrom` successor, adopts) the candidate's envelope; `settle` keeps or
|
|
24
|
+
* stages it until the final run outcome. Only a daemon-owned, single-candidate,
|
|
25
|
+
* mutating run (`keepable`) records custody; every other run keeps today's
|
|
26
|
+
* create/dispose behaviour.
|
|
27
|
+
*/
|
|
28
|
+
export declare function forRun(input: {
|
|
29
|
+
continuation?: RunContinuation;
|
|
30
|
+
signal?: AbortSignal;
|
|
31
|
+
}, keepable: boolean, runId: string, paths: {
|
|
32
|
+
root: string;
|
|
33
|
+
attemptsDir: string;
|
|
34
|
+
}, log?: EventLog): {
|
|
35
|
+
envelope: (wsm: WorkspaceManager, opts: CreateEnvelopeOptions) => Promise<{
|
|
36
|
+
id: string;
|
|
37
|
+
task_id: string;
|
|
38
|
+
attempt_id: string;
|
|
39
|
+
repo_root: string;
|
|
40
|
+
base_ref: string | null;
|
|
41
|
+
base_sha: string | null;
|
|
42
|
+
worktree_path: string;
|
|
43
|
+
branch_name: string | null;
|
|
44
|
+
workspace_kind?: "directory" | "git" | undefined;
|
|
45
|
+
scope_paths?: string[] | undefined;
|
|
46
|
+
home_dir: string;
|
|
47
|
+
harness_config_dirs: Record<string, string>;
|
|
48
|
+
policy_profile: string;
|
|
49
|
+
dirty_policy: "refuse" | "snapshot";
|
|
50
|
+
created_at: string;
|
|
51
|
+
}>;
|
|
52
|
+
settle: (wsm: WorkspaceManager, env: WorkspaceEnvelope, runs: readonly (CandidateRun | undefined)[]) => Promise<void>;
|
|
53
|
+
finish: (facts: RunOutcomeFacts) => Promise<void>;
|
|
54
|
+
};
|
|
55
|
+
/** Settle custody after the strategy and Delegate budget verdict, before terminal publication. */
|
|
56
|
+
export declare function flushContinuationTerminal(context: AnnouncedRunContext, facts: RunOutcomeFacts): Promise<void>;
|
|
57
|
+
//# sourceMappingURL=continuation-custody.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"continuation-custody.d.ts","sourceRoot":"","sources":["../src/continu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C7C,OAAO,EAAE,mBAAmB,EAC5B,KAAK,EAAE,eAAe,GACrB,OAAO,CAAC,IAAI,CAAC,CAkBf"}
|
|
@@ -0,0 +1,151 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Envelope custody of a single-candidate Agent run (A9, PLAN §2.2).
|
|
3
|
+
*
|
|
4
|
+
* Start: a `continueFrom` successor adopts its predecessor's retained envelope
|
|
5
|
+
* (same path, base and files); any other single-candidate mutating run gets a
|
|
6
|
+
* fresh isolated envelope with `live` custody recorded before the harness runs.
|
|
7
|
+
* End: the envelope is kept (`retained`) when the work stopped unfinished
|
|
8
|
+
* (a non-success run terminal, or a needs_input / incomplete report) AND there is
|
|
9
|
+
* something to continue (a tree that differs from its base, or a native
|
|
10
|
+
* session capsule); otherwise it is disposed as before. Race candidates,
|
|
11
|
+
* synthesis, review and in-place envelopes are untouched.
|
|
12
|
+
*/
|
|
13
|
+
import { existsSync } from "node:fs";
|
|
14
|
+
import { join } from "node:path";
|
|
15
|
+
import { RunResumable, } from "@claudexor/schema";
|
|
16
|
+
import { adoptRetainedEnvelope, envelopeBaseOf, envelopeTreeChanged, readEnvelopeCustody, retainForContinuation, retainedEnvelopeOfRun, } from "@claudexor/workspace";
|
|
17
|
+
/** The per-attempt native session capsule file, written by the in-run
|
|
18
|
+
* continuation loop when `started` reports a native session id. */
|
|
19
|
+
export function sessionCapsuleFile(attemptDir) {
|
|
20
|
+
return join(attemptDir, "session-capsule.json");
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* The custody hooks of one run's candidate slot: `envelope` creates (or, for a
|
|
24
|
+
* `continueFrom` successor, adopts) the candidate's envelope; `settle` keeps or
|
|
25
|
+
* stages it until the final run outcome. Only a daemon-owned, single-candidate,
|
|
26
|
+
* mutating run (`keepable`) records custody; every other run keeps today's
|
|
27
|
+
* create/dispose behaviour.
|
|
28
|
+
*/
|
|
29
|
+
export function forRun(input, keepable, runId, paths, log) {
|
|
30
|
+
const holder = input.continuation?.retain && keepable ? { runId, runDir: paths.root } : null;
|
|
31
|
+
const pending = new Map();
|
|
32
|
+
const finish = async (facts) => {
|
|
33
|
+
for (const { wsm, env, runs } of pending.values()) {
|
|
34
|
+
await settleCandidateEnvelope(wsm, env, {
|
|
35
|
+
runs,
|
|
36
|
+
signal: input.signal,
|
|
37
|
+
attemptsDir: paths.attemptsDir,
|
|
38
|
+
log,
|
|
39
|
+
facts,
|
|
40
|
+
});
|
|
41
|
+
pending.delete(env.id);
|
|
42
|
+
}
|
|
43
|
+
};
|
|
44
|
+
if (holder && log) {
|
|
45
|
+
log.deferTerminal();
|
|
46
|
+
pendingRuns.set(log, finish);
|
|
47
|
+
}
|
|
48
|
+
return {
|
|
49
|
+
envelope: async (wsm, opts) => {
|
|
50
|
+
const env = await candidateEnvelope(wsm, holder, holder ? (input.continuation?.adopt ?? null) : null, opts);
|
|
51
|
+
if (holder && readEnvelopeCustody(envelopeBaseOf(env))?.holder_run_id === holder.runId)
|
|
52
|
+
pending.set(env.id, { wsm, env, runs: [] });
|
|
53
|
+
return env;
|
|
54
|
+
},
|
|
55
|
+
settle: async (wsm, env, runs) => {
|
|
56
|
+
if (pending.has(env.id))
|
|
57
|
+
pending.set(env.id, { wsm, env, runs });
|
|
58
|
+
else
|
|
59
|
+
await wsm.dispose(env);
|
|
60
|
+
},
|
|
61
|
+
finish,
|
|
62
|
+
};
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* The candidate's envelope: the predecessor's retained envelope when `adopt`
|
|
66
|
+
* hands one over (adoption transfers custody, never deletes), else a new one —
|
|
67
|
+
* with `live` custody when `holder` says this run may keep it.
|
|
68
|
+
*/
|
|
69
|
+
async function candidateEnvelope(wsm, holder, adopt, opts) {
|
|
70
|
+
if (!holder || opts.inPlace || opts.workspaceKind === "directory")
|
|
71
|
+
return wsm.create(opts);
|
|
72
|
+
if (adopt)
|
|
73
|
+
return adoptRetainedEnvelope(adopt, holder);
|
|
74
|
+
return wsm.create({ ...opts, custody: holder });
|
|
75
|
+
}
|
|
76
|
+
/** Why the candidate's work is unfinished (null = unfinished, cause not known
|
|
77
|
+
* at this layer), or undefined when it finished. */
|
|
78
|
+
function unfinishedCause(run, signal, facts) {
|
|
79
|
+
if (signal?.aborted)
|
|
80
|
+
return signal.reason === "wall_clock_exceeded" ? "wall_clock" : "cancelled";
|
|
81
|
+
const state = run?.telemetry.outcome?.workState?.state;
|
|
82
|
+
if (state === "needs_input")
|
|
83
|
+
return "input_required";
|
|
84
|
+
if (facts.lifecycle !== "succeeded")
|
|
85
|
+
return facts.reason === "context_capacity_exhausted"
|
|
86
|
+
? "context_exhausted"
|
|
87
|
+
: (run?.resumable?.cause ?? null);
|
|
88
|
+
return state === "incomplete" ? null : undefined;
|
|
89
|
+
}
|
|
90
|
+
async function worthKeeping(env, run, attemptsDir) {
|
|
91
|
+
if (run && run.diff.trim().length > 0)
|
|
92
|
+
return true;
|
|
93
|
+
const attempts = new Set([env.attempt_id, ...(run ? [run.attemptId] : [])]);
|
|
94
|
+
if ([...attempts].some((id) => existsSync(sessionCapsuleFile(join(attemptsDir, id))))) {
|
|
95
|
+
return true;
|
|
96
|
+
}
|
|
97
|
+
return (await envelopeTreeChanged(env)) === true;
|
|
98
|
+
}
|
|
99
|
+
/**
|
|
100
|
+
* End of a candidate: keep or dispose its envelope. Only an envelope under
|
|
101
|
+
* this run's `live` custody can be kept; everything else is disposed exactly
|
|
102
|
+
* as before. Keeping is durable before the run's terminal is reported and is
|
|
103
|
+
* disclosed with a `workspace.retained` event (disk use measured once).
|
|
104
|
+
*/
|
|
105
|
+
async function settleCandidateEnvelope(wsm, env, ctx) {
|
|
106
|
+
const custody = readEnvelopeCustody(envelopeBaseOf(env));
|
|
107
|
+
if (custody?.state !== "live" || custody.envelope.id !== env.id)
|
|
108
|
+
return wsm.dispose(env);
|
|
109
|
+
const run = ctx.runs.find((candidate) => candidate?.reviewCwd === env.worktree_path);
|
|
110
|
+
const cause = unfinishedCause(run, ctx.signal, ctx.facts);
|
|
111
|
+
if (cause === undefined || !(await worthKeeping(env, run, ctx.attemptsDir))) {
|
|
112
|
+
return wsm.dispose(env);
|
|
113
|
+
}
|
|
114
|
+
const holder = { runId: custody.holder_run_id, runDir: custody.holder_run_dir };
|
|
115
|
+
const retained = retainForContinuation(env, holder, cause);
|
|
116
|
+
// The terminal `resumable` block (written after this settle) names the kept tree.
|
|
117
|
+
// Deferred terminal payloads share these workspace objects, including a
|
|
118
|
+
// resumableOnFailure promoted by the final budget verdict.
|
|
119
|
+
for (const resumable of [run?.resumable, run?.resumableOnFailure])
|
|
120
|
+
if (resumable)
|
|
121
|
+
Object.assign(resumable.workspace, { kind: "retained_envelope", root: env.worktree_path });
|
|
122
|
+
ctx.log?.emit("workspace.retained", {
|
|
123
|
+
attempt_id: run?.attemptId ?? env.attempt_id,
|
|
124
|
+
root: env.worktree_path,
|
|
125
|
+
cause,
|
|
126
|
+
bytes: retained.bytes,
|
|
127
|
+
});
|
|
128
|
+
}
|
|
129
|
+
const pendingRuns = new WeakMap();
|
|
130
|
+
/** Settle custody after the strategy and Delegate budget verdict, before terminal publication. */
|
|
131
|
+
export async function flushContinuationTerminal(context, facts) {
|
|
132
|
+
const finish = pendingRuns.get(context.log);
|
|
133
|
+
try {
|
|
134
|
+
if (finish) {
|
|
135
|
+
await finish(facts);
|
|
136
|
+
const kept = retainedEnvelopeOfRun(context.paths.root, context.runId);
|
|
137
|
+
const path = join(context.paths.finalDir, "resumable.yaml");
|
|
138
|
+
const resumable = RunResumable.safeParse(context.store.readYaml(path)).data;
|
|
139
|
+
if (kept && resumable)
|
|
140
|
+
context.store.writeYaml(path, {
|
|
141
|
+
...resumable,
|
|
142
|
+
workspace: { kind: "retained_envelope", root: kept.envelope.worktree_path },
|
|
143
|
+
});
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
finally {
|
|
147
|
+
pendingRuns.delete(context.log);
|
|
148
|
+
context.log.flushDeferredTerminal();
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
//# sourceMappingURL=continuation-custody.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"continuation-custody.js","sourceRoot":"","sources":["../src/continuation-custody.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AACH,OAAO,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AACrC,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AAEjC,OAAO,EACL,YAAY,GAKb,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EACL,qBAAqB,EACrB,cAAc,EACd,mBAAmB,EACnB,mBAAmB,EACnB,qBAAqB,EACrB,qBAAqB,GAGtB,MAAM,sBAAsB,CAAC;AAU9B;mEACmE;AACnE,MAAM,UAAU,kBAAkB,CAAC,UAAkB;IACnD,OAAO,IAAI,CAAC,UAAU,EAAE,sBAAsB,CAAC,CAAC;AAClD,CAAC;AAcD;;;;;;GAMG;AACH,MAAM,UAAU,MAAM,CACpB,KAA+D,EAC/D,QAAiB,EACjB,KAAa,EACb,KAA4C,EAC5C,GAAc;IAEd,MAAM,MAAM,GACV,KAAK,CAAC,YAAY,EAAE,MAAM,IAAI,QAAQ,CAAC,CAAC,CAAC,EAAE,KAAK,EAAE,MAAM,EAAE,KAAK,CAAC,IAAI,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC;IAChF,MAAM,OAAO,GAAG,IAAI,GAAG,EAGpB,CAAC;IACJ,MAAM,MAAM,GAAG,KAAK,EAAE,KAAsB,EAAE,EAAE;QAC9C,KAAK,MAAM,EAAE,GAAG,EAAE,GAAG,EAAE,IAAI,EAAE,IAAI,OAAO,CAAC,MAAM,EAAE,EAAE,CAAC;YAClD,MAAM,uBAAuB,CAAC,GAAG,EAAE,GAAG,EAAE;gBACtC,IAAI;gBACJ,MAAM,EAAE,KAAK,CAAC,MAAM;gBACpB,WAAW,EAAE,KAAK,CAAC,WAAW;gBAC9B,GAAG;gBACH,KAAK;aACN,CAAC,CAAC;YACH,OAAO,C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gBACnB,OAAO,CAAC,KAAK,CAAC,SAAS,CAAC,IAAI,EAAE;oBAC5B,GAAG,SAAS;oBACZ,SAAS,EAAE,EAAE,IAAI,EAAE,mBAAmB,EAAE,IAAI,EAAE,IAAI,CAAC,QAAQ,CAAC,aAAa,EAAE;iBAC5E,CAAC,CAAC;QACP,CAAC;IACH,CAAC;YAAS,CAAC;QACT,WAAW,CAAC,MAAM,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC;QAChC,OAAO,CAAC,GAAG,CAAC,qBAAqB,EAAE,CAAC;IACtC,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import type { ResumableCause } from "@claudexor/schema";
|
|
2
|
+
import type { EvidenceIndexInput, EvidenceIndexSources, EvidenceSteering, EvidenceToolCall } from "./continuation-evidence.js";
|
|
3
|
+
type Row = Record<string, unknown>;
|
|
4
|
+
/** Pair typed use ids within a native try; ambiguous ids remain unresolved. */
|
|
5
|
+
export declare function toolCallIndex(events: readonly Row[]): EvidenceToolCall[];
|
|
6
|
+
/** Admitted steering messages of a run, with delivery status, in admission order. */
|
|
7
|
+
export declare function steeringFromRunLog(runDir: string, attemptId?: string): EvidenceSteering[];
|
|
8
|
+
/** Resolve the pure builder's input from the run dir plus the loop's in-memory facts. */
|
|
9
|
+
export declare function collectEvidenceIndexInput(sources: EvidenceIndexSources, extras: {
|
|
10
|
+
cause: ResumableCause;
|
|
11
|
+
retainedOutput: string;
|
|
12
|
+
diffStat: string | null;
|
|
13
|
+
completed?: boolean;
|
|
14
|
+
}): EvidenceIndexInput;
|
|
15
|
+
/** `git diff`-style file list from a unified diff: one line per changed path. */
|
|
16
|
+
export declare function diffStatFromPatch(diff: string): string | null;
|
|
17
|
+
export {};
|
|
18
|
+
//# sourceMappingURL=continuation-evidence-io.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"continuation-evidence-io.d.ts","sourceRoot":"","sources":["../src/continuation-evidence-io.ts"],"names":[],"mappings":"AAcA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAC;AACxD,OAAO,KAAK,EACV,kBAAkB,EAClB,oBAAoB,EACpB,gBAAgB,EAChB,gBAAgB,EACjB,MAAM,4BAA4B,CAAC;AAEpC,KAAK,GAAG,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;AAqCnC,+EAA+E;AAC/E,wBAAgB,aAAa,CAAC,MAAM,EAAE,SAAS,GAAG,EAAE,GAAG,gBAAgB,EAAE,CAsCxE;AAED,qFAAqF;AACrF,wBAAgB,kBAAkB,CAAC,MAAM,EAAE,MAAM,EAAE,SAAS,CAAC,EAAE,MAAM,GAAG,gBAAgB,EAAE,CAkBzF;AAED,yFAAyF;AACzF,wBAAgB,yBAAyB,CACvC,OAAO,EAAE,oBAAoB,EAC7B,MAAM,EAAE;IACN,KAAK,EAAE,cAAc,CAAC;IACtB,cAAc,EAAE,MAAM,CAAC;IACvB,QAAQ,EAAE,MAAM,GAAG,IAAI,CAAC;IACxB,SAAS,CAAC,EAAE,OAAO,CAAC;CACrB,GACA,kBAAkB,CA8CpB;AAED,iFAAiF;AACjF,wBAAgB,iBAAiB,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CAQ7D"}
|
|
@@ -0,0 +1,167 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Evidence-index collector — the I/O half of `continuation-evidence.ts`.
|
|
3
|
+
*
|
|
4
|
+
* Reads the predecessor's durable record (the run's `events.jsonl` and, for
|
|
5
|
+
* read-only attempts, the attempt's own `events.jsonl`) into the pure
|
|
6
|
+
* builder's input: tool calls paired by try/session and typed use id (legacy
|
|
7
|
+
* results without an id close the oldest open call), and admitted steering
|
|
8
|
+
* messages with their delivery status (`message.delivered` = confirmed; an
|
|
9
|
+
* `accepted` row with no closing = uncertain; refused = not sent), and the
|
|
10
|
+
* absolute artifact paths. Never throws: unreadable evidence yields an empty
|
|
11
|
+
* index section, never a failed continuation.
|
|
12
|
+
*/
|
|
13
|
+
import { existsSync, readFileSync } from "node:fs";
|
|
14
|
+
import { join } from "node:path";
|
|
15
|
+
function readRows(path) {
|
|
16
|
+
if (!existsSync(path))
|
|
17
|
+
return [];
|
|
18
|
+
try {
|
|
19
|
+
return readFileSync(path, "utf8")
|
|
20
|
+
.split("\n")
|
|
21
|
+
.filter((line) => line.trim())
|
|
22
|
+
.flatMap((line) => {
|
|
23
|
+
try {
|
|
24
|
+
const parsed = JSON.parse(line);
|
|
25
|
+
return parsed && typeof parsed === "object" ? [parsed] : [];
|
|
26
|
+
}
|
|
27
|
+
catch {
|
|
28
|
+
return [];
|
|
29
|
+
}
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
catch {
|
|
33
|
+
return [];
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
function asRow(value) {
|
|
37
|
+
return value && typeof value === "object" && !Array.isArray(value) ? value : null;
|
|
38
|
+
}
|
|
39
|
+
/** The attempt's harness events: attempt-local log first, else the run log filtered by attempt. */
|
|
40
|
+
function attemptHarnessEvents(runDir, attemptId) {
|
|
41
|
+
const own = readRows(join(runDir, "attempts", attemptId, "events.jsonl"));
|
|
42
|
+
if (own.length > 0)
|
|
43
|
+
return own;
|
|
44
|
+
return readRows(join(runDir, "events.jsonl")).flatMap((row) => {
|
|
45
|
+
const payload = asRow(row["payload"]);
|
|
46
|
+
return row["type"] === "harness.event" && payload && payload["attempt_id"] === attemptId
|
|
47
|
+
? [payload]
|
|
48
|
+
: [];
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
/** Pair typed use ids within a native try; ambiguous ids remain unresolved. */
|
|
52
|
+
export function toolCallIndex(events) {
|
|
53
|
+
const calls = [];
|
|
54
|
+
for (const ev of events) {
|
|
55
|
+
const tool = asRow(ev["tool"]);
|
|
56
|
+
const id = typeof tool?.["use_id"] === "string" ? tool["use_id"] : null;
|
|
57
|
+
const target = typeof tool?.["target"] === "string" ? tool["target"] : null;
|
|
58
|
+
// A file edit the vendor reports twice (codex: started, then completed) is
|
|
59
|
+
// one call per path; the later frame for the same path is the completion
|
|
60
|
+
// (one codex item may carry several paths under one id).
|
|
61
|
+
const sameEdit = ev["type"] === "file_change" && id !== null
|
|
62
|
+
? calls.filter((entry) => entry.id === id &&
|
|
63
|
+
entry.session === ev["session_id"] &&
|
|
64
|
+
(target === null || entry.call.target === target))
|
|
65
|
+
: [];
|
|
66
|
+
if (sameEdit.length > 0) {
|
|
67
|
+
const open = sameEdit.find((entry) => !entry.call.resolved);
|
|
68
|
+
if (open)
|
|
69
|
+
open.call.resolved = true;
|
|
70
|
+
}
|
|
71
|
+
else if (ev["type"] === "tool_call" || (ev["type"] === "file_change" && tool)) {
|
|
72
|
+
const name = typeof tool?.["name"] === "string" && tool["name"].trim()
|
|
73
|
+
? tool["name"]
|
|
74
|
+
: typeof ev["text"] === "string" && ev["text"].trim()
|
|
75
|
+
? ev["text"].split("\n")[0].slice(0, 80)
|
|
76
|
+
: "tool";
|
|
77
|
+
calls.push({ call: { name, target, resolved: false }, session: ev["session_id"], id });
|
|
78
|
+
}
|
|
79
|
+
else if (ev["type"] === "tool_result") {
|
|
80
|
+
const open = calls.filter((entry) => !entry.call.resolved && entry.session === ev["session_id"]);
|
|
81
|
+
const matched = id === null ? open.slice(0, 1) : open.filter((entry) => entry.id === id);
|
|
82
|
+
if (matched.length === 1)
|
|
83
|
+
matched[0].call.resolved = true;
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
return calls.map((entry) => entry.call);
|
|
87
|
+
}
|
|
88
|
+
/** Admitted steering messages of a run, with delivery status, in admission order. */
|
|
89
|
+
export function steeringFromRunLog(runDir, attemptId) {
|
|
90
|
+
const byId = new Map();
|
|
91
|
+
for (const row of readRows(join(runDir, "events.jsonl"))) {
|
|
92
|
+
const payload = asRow(row["payload"]);
|
|
93
|
+
const rowAttempt = payload?.["attempt_id"] ?? row["attempt_id"];
|
|
94
|
+
if (attemptId !== undefined && typeof rowAttempt === "string" && rowAttempt !== attemptId)
|
|
95
|
+
continue;
|
|
96
|
+
const id = typeof payload?.["message_id"] === "string" ? payload["message_id"] : null;
|
|
97
|
+
const text = typeof payload?.["text"] === "string" ? payload["text"] : null;
|
|
98
|
+
if (!id || text === null)
|
|
99
|
+
continue;
|
|
100
|
+
const entry = byId.get(id) ?? { text, delivery: "uncertain", refused: false };
|
|
101
|
+
if (row["type"] === "message.accepted")
|
|
102
|
+
byId.set(id, entry);
|
|
103
|
+
else if (row["type"] === "message.delivered")
|
|
104
|
+
byId.set(id, { ...entry, delivery: "confirmed" });
|
|
105
|
+
else if (row["type"] === "message.refused")
|
|
106
|
+
byId.set(id, { ...entry, refused: true });
|
|
107
|
+
}
|
|
108
|
+
return [...byId.values()]
|
|
109
|
+
.filter((entry) => !entry.refused)
|
|
110
|
+
.map(({ text, delivery }) => ({ text, delivery }));
|
|
111
|
+
}
|
|
112
|
+
/** Resolve the pure builder's input from the run dir plus the loop's in-memory facts. */
|
|
113
|
+
export function collectEvidenceIndexInput(sources, extras) {
|
|
114
|
+
const attemptDir = join(sources.runDir, "attempts", sources.attemptId);
|
|
115
|
+
const eventsLog = join(sources.runDir, "events.jsonl");
|
|
116
|
+
const attemptPatch = join(attemptDir, "patch.diff");
|
|
117
|
+
const patch = existsSync(attemptPatch)
|
|
118
|
+
? attemptPatch
|
|
119
|
+
: join(sources.runDir, "final", "patch.diff");
|
|
120
|
+
const current = {
|
|
121
|
+
cause: extras.cause,
|
|
122
|
+
...(extras.completed ? { completed: true } : {}),
|
|
123
|
+
workOrder: sources.workOrder,
|
|
124
|
+
steering: sources.steering.length > 0
|
|
125
|
+
? sources.steering
|
|
126
|
+
: steeringFromRunLog(sources.runDir, sources.attemptId),
|
|
127
|
+
retainedOutput: extras.retainedOutput,
|
|
128
|
+
toolCalls: toolCallIndex(attemptHarnessEvents(sources.runDir, sources.attemptId)),
|
|
129
|
+
diffStat: extras.diffStat,
|
|
130
|
+
artifacts: {
|
|
131
|
+
eventsLog: existsSync(eventsLog) ? eventsLog : null,
|
|
132
|
+
attemptDir: existsSync(attemptDir) ? attemptDir : null,
|
|
133
|
+
patch: existsSync(patch) ? patch : null,
|
|
134
|
+
},
|
|
135
|
+
};
|
|
136
|
+
const preceding = sources.predecessors?.map((source) => collectEvidenceIndexInput(source, {
|
|
137
|
+
cause: extras.cause,
|
|
138
|
+
retainedOutput: source.retainedOutput,
|
|
139
|
+
diffStat: source.diffStat,
|
|
140
|
+
})) ?? [];
|
|
141
|
+
if (preceding.length === 0)
|
|
142
|
+
return current;
|
|
143
|
+
const all = [...preceding, current];
|
|
144
|
+
return {
|
|
145
|
+
...current,
|
|
146
|
+
steering: all.flatMap((input) => input.steering),
|
|
147
|
+
retainedOutput: all
|
|
148
|
+
.map((input) => input.retainedOutput)
|
|
149
|
+
.filter(Boolean)
|
|
150
|
+
.join("\n\n"),
|
|
151
|
+
toolCalls: all.flatMap((input) => input.toolCalls),
|
|
152
|
+
diffStat: [...new Set(all.flatMap((input) => input.diffStat?.split("\n") ?? []))].join("\n") || null,
|
|
153
|
+
predecessorArtifacts: preceding.map((input) => input.artifacts),
|
|
154
|
+
};
|
|
155
|
+
}
|
|
156
|
+
/** `git diff`-style file list from a unified diff: one line per changed path. */
|
|
157
|
+
export function diffStatFromPatch(diff) {
|
|
158
|
+
if (!diff.trim())
|
|
159
|
+
return null;
|
|
160
|
+
const files = diff
|
|
161
|
+
.split("\n")
|
|
162
|
+
.filter((line) => line.startsWith("diff --git "))
|
|
163
|
+
.map((line) => line.slice("diff --git ".length).split(" b/").pop() ?? line)
|
|
164
|
+
.filter((path) => path.trim());
|
|
165
|
+
return files.length ? files.map((path) => `- ${path}`).join("\n") : null;
|
|
166
|
+
}
|
|
167
|
+
//# sourceMappingURL=continuation-evidence-io.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"continuation-evidence-io.js","sourceRoot":"","sources":["../src/continuation-evidence-io.ts"],"names":[],"mappings":"AAAA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CAAC,UAAU,CAAC,aAAa,CAAC,CAAC;SAChD,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,KAAK,CAAC,aAAa,CAAC,MAAM,CAAC,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC,GAAG,EAAE,IAAI,IAAI,CAAC;SAC1E,MAAM,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,IAAI,EAAE,CAAC,CAAC;IACjC,OAAO,KAAK,CAAC,MAAM,CAAC,CAAC,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,KAAK,IAAI,EAAE,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC;AAC3E,CAAC"}
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Evidence-index packet builder — PURE (A10).
|
|
3
|
+
*
|
|
4
|
+
* When no native carrier exists (the vendor refused the moved session, the
|
|
5
|
+
* adapter cannot move, the mind asked for a re-brief), the successor is a
|
|
6
|
+
* FRESH vendor session re-grounded by an EVIDENCE INDEX: the original work
|
|
7
|
+
* order, admitted steering (live messages) with their delivery status, the
|
|
8
|
+
* retained assistant output, a tool-call index (name, completed / unresolved),
|
|
9
|
+
* the diff stat and absolute paths to the predecessor's event log and attempt
|
|
10
|
+
* artifacts readable from the new environment. Bounded inline with honest
|
|
11
|
+
* truncation (`summarized` is true also when a single section was cut). No
|
|
12
|
+
* second summarizer, no recap model call.
|
|
13
|
+
*
|
|
14
|
+
* This is NOT the thread continuation packet (`continuity.ts`
|
|
15
|
+
* `buildContinuation`, INV-137): thread turns and the D-16d context-exhaustion
|
|
16
|
+
* continuation keep that packet; the evidence index serves in-run packet hops
|
|
17
|
+
* and `continueFrom`.
|
|
18
|
+
*/
|
|
19
|
+
import type { ResumableCause } from "@claudexor/schema";
|
|
20
|
+
/** Admitted steering message of the predecessor (POST /v2/runs/:id/messages). */
|
|
21
|
+
export interface EvidenceSteering {
|
|
22
|
+
text: string;
|
|
23
|
+
/** confirmed: the vendor echoed it into its history; uncertain: it may not have been delivered. */
|
|
24
|
+
delivery: "confirmed" | "uncertain";
|
|
25
|
+
}
|
|
26
|
+
/** Where the I/O collector reads the predecessor's evidence. */
|
|
27
|
+
export interface EvidenceIndexSources {
|
|
28
|
+
runDir: string;
|
|
29
|
+
attemptId: string;
|
|
30
|
+
workOrder: string;
|
|
31
|
+
steering: EvidenceSteering[];
|
|
32
|
+
/** Earlier runs, oldest first; each keeps its own tool-result pairing boundary. */
|
|
33
|
+
predecessors?: readonly PredecessorEvidenceSource[];
|
|
34
|
+
}
|
|
35
|
+
export type PredecessorEvidenceSource = Omit<EvidenceIndexSources, "predecessors"> & {
|
|
36
|
+
retainedOutput: string;
|
|
37
|
+
diffStat: string | null;
|
|
38
|
+
};
|
|
39
|
+
export interface EvidenceToolCall {
|
|
40
|
+
name: string;
|
|
41
|
+
target: string | null;
|
|
42
|
+
/** False when the call never saw its result (cut off). */
|
|
43
|
+
resolved: boolean;
|
|
44
|
+
}
|
|
45
|
+
/** Fully-resolved inputs of the pure builder (the collector reads them from the run dir). */
|
|
46
|
+
export interface EvidenceIndexInput {
|
|
47
|
+
cause: ResumableCause;
|
|
48
|
+
completed?: boolean;
|
|
49
|
+
workOrder: string;
|
|
50
|
+
steering: EvidenceSteering[];
|
|
51
|
+
/** The retained assistant output (`final/retained-output.md` or the attempt's answer), "" when none. */
|
|
52
|
+
retainedOutput: string;
|
|
53
|
+
toolCalls: EvidenceToolCall[];
|
|
54
|
+
/** `git diff --stat`-style file list of the predecessor's tree, null when unknown. */
|
|
55
|
+
diffStat: string | null;
|
|
56
|
+
/** Absolute paths readable from the new environment; null when absent. */
|
|
57
|
+
artifacts: {
|
|
58
|
+
eventsLog: string | null;
|
|
59
|
+
attemptDir: string | null;
|
|
60
|
+
patch: string | null;
|
|
61
|
+
};
|
|
62
|
+
predecessorArtifacts?: EvidenceIndexInput["artifacts"][];
|
|
63
|
+
}
|
|
64
|
+
export interface EvidenceIndex {
|
|
65
|
+
/** The packet body delivered to the successor (bounded). */
|
|
66
|
+
markdown: string;
|
|
67
|
+
/** True when any section was truncated or collapsed. */
|
|
68
|
+
summarized: boolean;
|
|
69
|
+
toolCalls: number;
|
|
70
|
+
unresolvedToolCalls: number;
|
|
71
|
+
bytes: number;
|
|
72
|
+
}
|
|
73
|
+
/** Per-section verbatim budget. */
|
|
74
|
+
export declare const EVIDENCE_SECTION_BUDGET_BYTES: number;
|
|
75
|
+
/** Whole-index budget; the tool index collapses to counts past it. */
|
|
76
|
+
export declare const EVIDENCE_TOTAL_BUDGET_BYTES: number;
|
|
77
|
+
/** Tool rows kept verbatim before the index collapses to counts. */
|
|
78
|
+
export declare const EVIDENCE_TOOL_ROWS = 60;
|
|
79
|
+
/** Pure: render the bounded evidence index for a packet carrier. */
|
|
80
|
+
export declare function buildEvidenceIndex(input: EvidenceIndexInput): EvidenceIndex;
|
|
81
|
+
//# sourceMappingURL=continuation-evidence.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"continuation-evidence.d.ts","sourceRoot":"","sources":["../src/continuation-evidence.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;GAiBG;AACH,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAC;AAExD,iFAAiF;AACjF,MAAM,WAAW,gBAAgB;IAC/B,IAAI,EAAE,MAAM,CAAC;IACb,mGAAmG;IACnG,QAAQ,EAAE,WAAW,GAAG,WAAW,CAAC;CACrC;AAED,gEAAgE;AAChE,MAAM,WAAW,oBAAoB;IACnC,MAAM,EAAE,MAAM,CAAC;IACf,SAAS,EAAE,MAAM,CAAC;IAClB,SAAS,EAAE,MAAM,CAAC;IAClB,QAAQ,EAAE,gBAAgB,EAAE,CAAC;IAC7B,mFAAmF;IACnF,YAAY,CAAC,EAAE,SAAS,yBAAyB,EAAE,CAAC;CACrD;AAED,MAAM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,CAAC;AAqCrC,oEAAoE;AACpE,wBAAgB,kBAAkB,CAAC,KAAK,EAAE,kBAAkB,GAAG,aAAa,CAgF3E"}
|
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
/** Per-section verbatim budget. */
|
|
2
|
+
export const EVIDENCE_SECTION_BUDGET_BYTES = 8 * 1024;
|
|
3
|
+
/** Whole-index budget; the tool index collapses to counts past it. */
|
|
4
|
+
export const EVIDENCE_TOTAL_BUDGET_BYTES = 24 * 1024;
|
|
5
|
+
/** Tool rows kept verbatim before the index collapses to counts. */
|
|
6
|
+
export const EVIDENCE_TOOL_ROWS = 60;
|
|
7
|
+
function bytes(text) {
|
|
8
|
+
return Buffer.byteLength(text, "utf8");
|
|
9
|
+
}
|
|
10
|
+
/** Truncate to at most `maxBytes` UTF-8 bytes on a safe char boundary. */
|
|
11
|
+
function bound(text, maxBytes) {
|
|
12
|
+
if (bytes(text) <= maxBytes)
|
|
13
|
+
return { text, cut: false };
|
|
14
|
+
const marker = "\n…[truncated]";
|
|
15
|
+
const buf = Buffer.from(text, "utf8").subarray(0, Math.max(0, maxBytes - bytes(marker)));
|
|
16
|
+
for (let trim = 0; trim <= 3 && trim <= buf.length; trim += 1) {
|
|
17
|
+
try {
|
|
18
|
+
const decoded = new TextDecoder("utf-8", { fatal: true }).decode(trim === 0 ? buf : buf.subarray(0, buf.length - trim));
|
|
19
|
+
return { text: `${decoded}${marker}`, cut: true };
|
|
20
|
+
}
|
|
21
|
+
catch {
|
|
22
|
+
/* prefix ended inside a scalar; back off */
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
return { text: `${buf.toString("utf8")}${marker}`, cut: true };
|
|
26
|
+
}
|
|
27
|
+
const CAUSE_LINE = {
|
|
28
|
+
vendor_limit: "a usage limit on its account",
|
|
29
|
+
pool_exhausted: "every account's usage limit",
|
|
30
|
+
pinned_limit: "the pinned account's usage limit",
|
|
31
|
+
transport: "a process death",
|
|
32
|
+
context_exhausted: "context exhaustion",
|
|
33
|
+
wall_clock: "the wall-clock deadline",
|
|
34
|
+
cancelled: "a cancel",
|
|
35
|
+
host_restart: "a host restart",
|
|
36
|
+
input_required: "a request for input",
|
|
37
|
+
other: "an interruption",
|
|
38
|
+
};
|
|
39
|
+
/** Pure: render the bounded evidence index for a packet carrier. */
|
|
40
|
+
export function buildEvidenceIndex(input) {
|
|
41
|
+
let summarized = false;
|
|
42
|
+
const section = (text) => {
|
|
43
|
+
const b = bound(text.trim(), EVIDENCE_SECTION_BUDGET_BYTES);
|
|
44
|
+
summarized ||= b.cut;
|
|
45
|
+
return b.text;
|
|
46
|
+
};
|
|
47
|
+
const unresolved = input.toolCalls.filter((call) => !call.resolved);
|
|
48
|
+
const parts = [
|
|
49
|
+
input.completed
|
|
50
|
+
? "# Evidence index of the previous work"
|
|
51
|
+
: "# Evidence index of the interrupted work",
|
|
52
|
+
"",
|
|
53
|
+
input.completed
|
|
54
|
+
? "This index records the completed predecessor's work order, messages and actions. Check the current workspace before relying on its changes."
|
|
55
|
+
: `The previous process stopped (${CAUSE_LINE[input.cause]}) before finishing. This index is mechanical evidence of what it was asked, told and did; it is not a summary. The workspace is as it was left.`,
|
|
56
|
+
"",
|
|
57
|
+
"## Original work order",
|
|
58
|
+
"",
|
|
59
|
+
section(input.workOrder) || "(empty)",
|
|
60
|
+
"",
|
|
61
|
+
];
|
|
62
|
+
if (input.steering.length > 0) {
|
|
63
|
+
parts.push("## Messages sent while it ran", "");
|
|
64
|
+
for (const [index, message] of input.steering.entries()) {
|
|
65
|
+
const delivery = message.delivery === "confirmed"
|
|
66
|
+
? "delivered"
|
|
67
|
+
: "delivery uncertain — reconcile against the work, do not replay blindly";
|
|
68
|
+
parts.push(`### Message ${index + 1} (${delivery})`, "", section(message.text), "");
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
parts.push("## Retained assistant output", "");
|
|
72
|
+
parts.push(input.retainedOutput.trim() ? section(input.retainedOutput) : "(no output retained)");
|
|
73
|
+
parts.push("", "## Tool calls", "");
|
|
74
|
+
if (input.toolCalls.length === 0) {
|
|
75
|
+
parts.push("(none recorded)");
|
|
76
|
+
}
|
|
77
|
+
else if (input.toolCalls.length > EVIDENCE_TOOL_ROWS) {
|
|
78
|
+
summarized = true;
|
|
79
|
+
parts.push(`${input.toolCalls.length} tool calls recorded, ${unresolved.length} without a recorded result (cut off). The last ${EVIDENCE_TOOL_ROWS} follow:`, "", ...input.toolCalls.slice(-EVIDENCE_TOOL_ROWS).map(toolRow));
|
|
80
|
+
}
|
|
81
|
+
else {
|
|
82
|
+
parts.push(...input.toolCalls.map(toolRow));
|
|
83
|
+
}
|
|
84
|
+
parts.push("", "## Changed files", "");
|
|
85
|
+
parts.push(input.diffStat && input.diffStat.trim() ? section(input.diffStat) : "(no diff stat)");
|
|
86
|
+
const refs = [input.artifacts, ...(input.predecessorArtifacts ?? [])]
|
|
87
|
+
.flatMap((artifacts) => [
|
|
88
|
+
artifacts.eventsLog && `- Event log: ${artifacts.eventsLog}`,
|
|
89
|
+
artifacts.attemptDir && `- Attempt artifacts: ${artifacts.attemptDir}`,
|
|
90
|
+
artifacts.patch && `- Patch so far: ${artifacts.patch}`,
|
|
91
|
+
])
|
|
92
|
+
.filter((line) => typeof line === "string");
|
|
93
|
+
const footer = [
|
|
94
|
+
"",
|
|
95
|
+
"",
|
|
96
|
+
"## Full evidence",
|
|
97
|
+
"",
|
|
98
|
+
refs.length ? section(refs.join("\n")) : "(no artifact paths available)",
|
|
99
|
+
"",
|
|
100
|
+
`Tool calls: ${input.toolCalls.length}; unresolved: ${unresolved.length}.`,
|
|
101
|
+
"",
|
|
102
|
+
].join("\n");
|
|
103
|
+
const prose = parts
|
|
104
|
+
.join("\n")
|
|
105
|
+
.replace(/\n{3,}/g, "\n\n")
|
|
106
|
+
.trimEnd();
|
|
107
|
+
const total = bound(prose, EVIDENCE_TOTAL_BUDGET_BYTES - bytes(footer));
|
|
108
|
+
summarized ||= total.cut;
|
|
109
|
+
const markdown = total.text + footer;
|
|
110
|
+
return {
|
|
111
|
+
markdown,
|
|
112
|
+
summarized,
|
|
113
|
+
toolCalls: input.toolCalls.length,
|
|
114
|
+
unresolvedToolCalls: unresolved.length,
|
|
115
|
+
bytes: bytes(markdown),
|
|
116
|
+
};
|
|
117
|
+
}
|
|
118
|
+
function toolRow(call) {
|
|
119
|
+
const target = call.target ? ` — ${call.target.replace(/\s+/g, " ").slice(0, 160)}` : "";
|
|
120
|
+
return `- ${call.name}${target} (${call.resolved ? "completed" : "unresolved: no result recorded"})`;
|
|
121
|
+
}
|
|
122
|
+
//# sourceMappingURL=continuation-evidence.js.map
|