@tangle-network/agent-runtime 0.192.5 → 0.194.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/{activation-CsJctnHp.js → activation-BQFIiyUG.js} +3 -3
- package/dist/{activation-CsJctnHp.js.map → activation-BQFIiyUG.js.map} +1 -1
- package/dist/agent.d.ts +1 -1
- package/dist/agent.js +2 -2
- package/dist/candidate-execution/index.js +4 -4
- package/dist/{candidate-execution-BSkZErxD.js → candidate-execution-B6CDW-fp.js} +4 -4
- package/dist/{candidate-execution-BSkZErxD.js.map → candidate-execution-B6CDW-fp.js.map} +1 -1
- package/dist/{conversation-DILnmy84.js → conversation-BXPWMOSd.js} +4 -5
- package/dist/{conversation-DILnmy84.js.map → conversation-BXPWMOSd.js.map} +1 -1
- package/dist/conversation.d.ts +1 -1
- package/dist/conversation.js +1 -1
- package/dist/{coordination-driver-pQobxl2Z.js → coordination-driver-iSN-m3VX.js} +287 -250
- package/dist/coordination-driver-iSN-m3VX.js.map +1 -0
- package/dist/{authoring-D-nXk29K.js → delegate-DCC2muUd.js} +56 -13
- package/dist/delegate-DCC2muUd.js.map +1 -0
- package/dist/delegation-status-BlsbSeOB.js +358 -0
- package/dist/delegation-status-BlsbSeOB.js.map +1 -0
- package/dist/durable.d.ts +2 -2
- package/dist/durable.js +3 -3
- package/dist/{environment-provider-DEwsolvi.js → environment-provider-Dr-wfnHg.js} +422 -8
- package/dist/environment-provider-Dr-wfnHg.js.map +1 -0
- package/dist/{environment-provider-CJ43FJfJ.d.ts → environment-provider-adVa6X7a.d.ts} +2 -2
- package/dist/environment-provider.d.ts +1 -1
- package/dist/environment-provider.js +1 -1
- package/dist/{graph-Ba4ZJ5jU.js → graph-DghidDx5.js} +138 -5
- package/dist/graph-DghidDx5.js.map +1 -0
- package/dist/graph.d.ts +3 -3
- package/dist/graph.js +4 -5
- package/dist/graph.js.map +1 -1
- package/dist/{improve-Cbbt3jE6.d.ts → improve-COGzLCiY.d.ts} +3 -3
- package/dist/{improvement-cycle-D9FWTakR.js → improvement-cycle-DeS1ZC5B.js} +6 -6
- package/dist/{improvement-cycle-D9FWTakR.js.map → improvement-cycle-DeS1ZC5B.js.map} +1 -1
- package/dist/{index-B_fEqr5V.d.ts → index-BEPjOPwH.d.ts} +66 -69
- package/dist/{index-COznK4kB.d.ts → index-CrBgLCIf.d.ts} +4 -4
- package/dist/{index-OSRVFARy.d.ts → index-DO6DHgRP.d.ts} +2 -2
- package/dist/index.d.ts +8 -8
- package/dist/index.js +13 -13
- package/dist/intelligence.d.ts +5 -5
- package/dist/intelligence.js +6 -6
- package/dist/{executable-spec-DxuiDFAU.js → jsonl-file-Bh1Q9nt0.js} +59 -3
- package/dist/jsonl-file-Bh1Q9nt0.js.map +1 -0
- package/dist/kernel.d.ts +6 -6
- package/dist/kernel.js +11 -12
- package/dist/{knowledge-rzv8sBV9.js → knowledge-B5okOzBQ.js} +6 -6
- package/dist/{knowledge-rzv8sBV9.js.map → knowledge-B5okOzBQ.js.map} +1 -1
- package/dist/knowledge.d.ts +1 -1
- package/dist/knowledge.js +1 -1
- package/dist/{loop-runner-bin-DiiZMHw7.d.ts → loop-runner-bin-Clc5IAwu.d.ts} +3 -3
- package/dist/{loop-runner-bin-ClpCHpzR.js → loop-runner-bin-U1J6x_UF.js} +3 -3
- package/dist/{loop-runner-bin-ClpCHpzR.js.map → loop-runner-bin-U1J6x_UF.js.map} +1 -1
- package/dist/loop-runner-bin.d.ts +1 -1
- package/dist/loop-runner-bin.js +1 -1
- package/dist/{materialization-CekWK6OO.js → materialization-vZssF9Nx.js} +28 -3
- package/dist/materialization-vZssF9Nx.js.map +1 -0
- package/dist/mcp/bin.js +3 -3
- package/dist/mcp/index.d.ts +4 -4
- package/dist/mcp/index.js +8 -8
- package/dist/mcp/index.js.map +1 -1
- package/dist/{openai-tools-BNBrKvZr.js → openai-tools-DmvmaG0a.js} +2 -2
- package/dist/{openai-tools-BNBrKvZr.js.map → openai-tools-DmvmaG0a.js.map} +1 -1
- package/dist/{prepare-B5fJ7mLS.js → prepare-C29kNAon.js} +9 -14
- package/dist/prepare-C29kNAon.js.map +1 -0
- package/dist/primeintellect/index.d.ts +1 -1
- package/dist/profiles.js +1 -1
- package/dist/{protected-model-port-B0xFSAjt.js → protected-model-port-CKYND416.js} +2 -2
- package/dist/{protected-model-port-B0xFSAjt.js.map → protected-model-port-CKYND416.js.map} +1 -1
- package/dist/{provision-supervisor-DiHm_bvQ.js → provision-supervisor-CRPbnJiB.js} +12 -14
- package/dist/provision-supervisor-CRPbnJiB.js.map +1 -0
- package/dist/{redact-Ct7s2j86.js → redact-BOU77QfQ.js} +1120 -64
- package/dist/redact-BOU77QfQ.js.map +1 -0
- package/dist/{researcher-hgPa5p9i.js → researcher-Cp4JRbFp.js} +2 -2
- package/dist/researcher-Cp4JRbFp.js.map +1 -0
- package/dist/{runtime-DI4mJNXI.d.ts → runtime-B8x43nGP.d.ts} +5 -4
- package/dist/{runtime-CVdsAHEN.js → runtime-BVrqSu0-.js} +36 -25
- package/dist/{runtime-CVdsAHEN.js.map → runtime-BVrqSu0-.js.map} +1 -1
- package/dist/server-D6XmE1Du.js +1311 -0
- package/dist/server-D6XmE1Du.js.map +1 -0
- package/dist/{stream-agent-turn-_GgUW49y.d.ts → stream-agent-turn-B-gtBlOy.d.ts} +2 -2
- package/dist/{stream-agent-turn-DWWe_7bh.js → stream-agent-turn-DOtEsvCV.js} +3 -3
- package/dist/{stream-agent-turn-DWWe_7bh.js.map → stream-agent-turn-DOtEsvCV.js.map} +1 -1
- package/dist/{structural-rollout-NrtKSgCE.js → structural-rollout-BcPXFzVb.js} +16 -43
- package/dist/structural-rollout-BcPXFzVb.js.map +1 -0
- package/dist/{supervise-Cr6JEoIg.js → supervise-C0V3pZXK.js} +179 -1980
- package/dist/supervise-C0V3pZXK.js.map +1 -0
- package/dist/testing.d.ts +2 -2
- package/dist/testing.js +13 -13
- package/dist/tui/index.d.ts +1 -1
- package/dist/tui/index.js +1 -1
- package/dist/{types-DKA_PDv0.d.ts → types-B_pNTBjK.d.ts} +25 -29
- package/dist/{workspace-archive-yAPDklLV.js → workspace-archive-BCezkeIk.js} +2 -2
- package/dist/{workspace-archive-yAPDklLV.js.map → workspace-archive-BCezkeIk.js.map} +1 -1
- package/package.json +1 -1
- package/skills/codemode/SKILL.md +2 -2
- package/skills/supervise/SKILL.md +93 -26
- package/dist/authoring-D-nXk29K.js.map +0 -1
- package/dist/coordination-driver-pQobxl2Z.js.map +0 -1
- package/dist/environment-provider-DEwsolvi.js.map +0 -1
- package/dist/executable-spec-DxuiDFAU.js.map +0 -1
- package/dist/graph-Ba4ZJ5jU.js.map +0 -1
- package/dist/jsonl-file-CDfsCI5s.js +0 -59
- package/dist/jsonl-file-CDfsCI5s.js.map +0 -1
- package/dist/materialization-CekWK6OO.js.map +0 -1
- package/dist/prepare-B5fJ7mLS.js.map +0 -1
- package/dist/provision-supervisor-DiHm_bvQ.js.map +0 -1
- package/dist/redact-Ct7s2j86.js.map +0 -1
- package/dist/researcher-hgPa5p9i.js.map +0 -1
- package/dist/snapshot-CTAf4uuA.js +0 -26
- package/dist/snapshot-CTAf4uuA.js.map +0 -1
- package/dist/spawn-journal-B9eTmVAn.js +0 -999
- package/dist/spawn-journal-B9eTmVAn.js.map +0 -1
- package/dist/structural-rollout-NrtKSgCE.js.map +0 -1
- package/dist/supervise-Cr6JEoIg.js.map +0 -1
- package/dist/util-mCNUeboW.js +0 -419
- package/dist/util-mCNUeboW.js.map +0 -1
|
@@ -1,16 +1,212 @@
|
|
|
1
|
-
import { d as providerAttemptEvidence } from "./materialization-
|
|
1
|
+
import { E as detachedFrozen, d as providerAttemptEvidence } from "./materialization-vZssF9Nx.js";
|
|
2
2
|
import { f as RuntimeRunStateError, m as ValidationError } from "./errors-CDZ8XsVj.js";
|
|
3
|
-
import { t as
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import { i as writeAllBytes, n as parseCommittedJsonLines, r as prepareJsonlAppend, t as isNoEntError } from "./jsonl-file-CDfsCI5s.js";
|
|
7
|
-
import { Et as createInbox, Ft as isLiveNodeStatus, It as isTerminalNodeStatus, Q as assertValidBudget, Xt as runBrainLoop, b as meterRuntimeOwnedProviderAttempt, d as pickBestDelivered, f as runFinalizer, h as withDriverExecutor, jt as createPeerMailbox, l as bestDelivered, p as runTree, q as freeSlots, r as resolveRedactor, ut as createExecutorRegistry } from "./redact-Ct7s2j86.js";
|
|
3
|
+
import { i as writeAllBytes, n as parseCommittedJsonLines, r as prepareJsonlAppend, t as isNoEntError } from "./jsonl-file-Bh1Q9nt0.js";
|
|
4
|
+
import { $t as workerTraceAnalysisStore, Bt as FileSpawnJournal, Et as createInbox, Ft as isLiveNodeStatus, Ht as InMemorySpawnJournal, It as isTerminalNodeStatus, Q as assertValidBudget, Qt as parseWorkerToolTraceArtifact, Vt as InMemoryResultBlobStore, b as meterRuntimeOwnedProviderAttempt, d as pickBestDelivered, f as runFinalizer, fn as runBrainLoop, h as withDriverExecutor, jt as createPeerMailbox, l as bestDelivered, p as runTree, q as freeSlots, r as resolveRedactor, ut as createExecutorRegistry, zt as FileResultBlobStore } from "./redact-BOU77QfQ.js";
|
|
5
|
+
import { g as promptCacheTokenClasses, l as chargedTokens, w as unmeteredSpend } from "./environment-provider-Dr-wfnHg.js";
|
|
8
6
|
import { A as writeWorkerCancellation, M as writeWorkerSteerAcknowledgement, c as readWorkerCancelRequests, d as readWorkerSteerRequests, k as writeRunCancellation, l as readWorkerCancellation, o as readRunCancelRequest, r as claimWorkerSteerDelivery, s as readRunCancellation, u as readWorkerSteerAcknowledgement } from "./run-layout-B8I_LXN-.js";
|
|
9
7
|
import { agentProfileSchema, canonicalCandidateDigest } from "@tangle-network/agent-interface";
|
|
10
8
|
import { argHash, errorStreakDetector, observeAll, repeatedActionDetector } from "@tangle-network/agent-eval";
|
|
11
9
|
import { randomUUID } from "node:crypto";
|
|
12
10
|
import { readFileSync } from "node:fs";
|
|
13
11
|
import { join } from "node:path";
|
|
12
|
+
//#region src/runtime/supervise/coordination-log.ts
|
|
13
|
+
/**
|
|
14
|
+
* Durable side-log for coordination evidence the spawn journal does not own: questions, analyst
|
|
15
|
+
* findings, answer decisions, authorized continuation receipts, delivery-attempt markers, and
|
|
16
|
+
* delivery outcomes. A durable run
|
|
17
|
+
* (`supervise({ runDir })`) appends them as they publish and loads them on resume, so a restarted
|
|
18
|
+
* coordinator retains the exact evidence produced by prior processes.
|
|
19
|
+
*
|
|
20
|
+
* Answer down-events also fold status on load: a question answered before the crash reloads as
|
|
21
|
+
* `answered`, not as a re-blocking `open`. Settled events are skipped (the spawn journal is their
|
|
22
|
+
* ledger). A receipt followed by an attempt but no outcome proves the process died in the delivery
|
|
23
|
+
* window; that outcome remains unknown and no prior instruction is auto-delivered.
|
|
24
|
+
*
|
|
25
|
+
* JSONL, one fsynced record per event, keyed by `runId` — several runs may share one log file
|
|
26
|
+
* exactly as they share one spawn-journal file.
|
|
27
|
+
*
|
|
28
|
+
* @experimental
|
|
29
|
+
*/
|
|
30
|
+
/** Persist prior context plus exact continuation authorization, attempt, and result evidence.
|
|
31
|
+
* Settlements have their own journal. */
|
|
32
|
+
function persisted(event) {
|
|
33
|
+
return event.type !== "settled";
|
|
34
|
+
}
|
|
35
|
+
/** FS-backed `CoordinationLog`: append-only JSONL, fsynced per record. */
|
|
36
|
+
var FileCoordinationLog = class {
|
|
37
|
+
path;
|
|
38
|
+
appendTail = Promise.resolve();
|
|
39
|
+
constructor(path) {
|
|
40
|
+
this.path = path;
|
|
41
|
+
}
|
|
42
|
+
async append(runId, record, ownerId) {
|
|
43
|
+
if (!persisted(record.event)) return;
|
|
44
|
+
const append = this.appendTail.then(() => this.appendRecord(runId, record, ownerId));
|
|
45
|
+
this.appendTail = append.catch(() => void 0);
|
|
46
|
+
return append;
|
|
47
|
+
}
|
|
48
|
+
async appendRecord(runId, busRecord, ownerId) {
|
|
49
|
+
const fs = await import("node:fs/promises");
|
|
50
|
+
const path = await import("node:path");
|
|
51
|
+
await fs.mkdir(path.dirname(this.path), { recursive: true });
|
|
52
|
+
const record = {
|
|
53
|
+
runId,
|
|
54
|
+
...ownerId !== void 0 ? { ownerId } : {},
|
|
55
|
+
...busRecord
|
|
56
|
+
};
|
|
57
|
+
const needsSeparator = await prepareJsonlAppend(this.path);
|
|
58
|
+
const fh = await fs.open(this.path, "a");
|
|
59
|
+
try {
|
|
60
|
+
await writeAllBytes(fh, `${needsSeparator ? "\n" : ""}${JSON.stringify(record)}\n`);
|
|
61
|
+
await fh.sync();
|
|
62
|
+
} finally {
|
|
63
|
+
await fh.close();
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
async load(runId, ownerId) {
|
|
67
|
+
const fs = await import("node:fs/promises");
|
|
68
|
+
let text;
|
|
69
|
+
try {
|
|
70
|
+
text = await fs.readFile(this.path, "utf8");
|
|
71
|
+
} catch (err) {
|
|
72
|
+
if (isNoEntError(err)) return emptyPriorCoordination(ownerId);
|
|
73
|
+
throw err;
|
|
74
|
+
}
|
|
75
|
+
const byId = /* @__PURE__ */ new Map();
|
|
76
|
+
const findings = [];
|
|
77
|
+
const escalations = [];
|
|
78
|
+
const analystDefinitions = [];
|
|
79
|
+
const continuations = [];
|
|
80
|
+
const deliveryEvidence = [];
|
|
81
|
+
const mail = [];
|
|
82
|
+
const records = [];
|
|
83
|
+
let legacySeq = 0;
|
|
84
|
+
for (const stored of parseCommittedJsonLines(text, this.path)) {
|
|
85
|
+
if (stored.runId !== runId) continue;
|
|
86
|
+
if (ownerId !== void 0 && stored.ownerId !== ownerId) continue;
|
|
87
|
+
const record = "seq" in stored ? {
|
|
88
|
+
seq: stored.seq,
|
|
89
|
+
at: stored.at,
|
|
90
|
+
priority: stored.priority,
|
|
91
|
+
event: stored.event
|
|
92
|
+
} : {
|
|
93
|
+
seq: legacySeq++,
|
|
94
|
+
at: Date.parse(stored.at),
|
|
95
|
+
priority: 0,
|
|
96
|
+
event: stored.event
|
|
97
|
+
};
|
|
98
|
+
records.push(record);
|
|
99
|
+
const ev = record.event;
|
|
100
|
+
if (ev.type === "delivery-attempt" || ev.type === "steer" || ev.type === "answer") deliveryEvidence.push(ev);
|
|
101
|
+
if (ev.type === "question") byId.set(ev.question.id, ev.question);
|
|
102
|
+
else if (ev.type === "finding") findings.push(ev.finding);
|
|
103
|
+
else if (ev.type === "answer") {
|
|
104
|
+
const prior = byId.get(ev.questionId);
|
|
105
|
+
if (prior && ev.down.delivered) byId.set(ev.questionId, {
|
|
106
|
+
...prior,
|
|
107
|
+
status: "answered",
|
|
108
|
+
decision: {
|
|
109
|
+
kind: "answer",
|
|
110
|
+
answer: ev.down.instruction,
|
|
111
|
+
by: "prior-run"
|
|
112
|
+
}
|
|
113
|
+
});
|
|
114
|
+
} else if (ev.type === "instruction") continuations.push(ev.instruction);
|
|
115
|
+
else if (ev.type === "mail") mail.push(ev.mail);
|
|
116
|
+
else if (ev.type === "escalation") escalations.push(ev.escalation);
|
|
117
|
+
else if (ev.type === "analyst-defined") analystDefinitions.push(ev.analyst);
|
|
118
|
+
}
|
|
119
|
+
return {
|
|
120
|
+
...ownerId !== void 0 ? { ownerId } : {},
|
|
121
|
+
questions: [...byId.values()],
|
|
122
|
+
findings,
|
|
123
|
+
escalations,
|
|
124
|
+
analystDefinitions,
|
|
125
|
+
continuations,
|
|
126
|
+
deliveryEvidence,
|
|
127
|
+
mail,
|
|
128
|
+
records
|
|
129
|
+
};
|
|
130
|
+
}
|
|
131
|
+
};
|
|
132
|
+
function emptyPriorCoordination(ownerId) {
|
|
133
|
+
return {
|
|
134
|
+
...ownerId !== void 0 ? { ownerId } : {},
|
|
135
|
+
questions: [],
|
|
136
|
+
findings: [],
|
|
137
|
+
escalations: [],
|
|
138
|
+
analystDefinitions: [],
|
|
139
|
+
continuations: [],
|
|
140
|
+
deliveryEvidence: [],
|
|
141
|
+
mail: [],
|
|
142
|
+
records: []
|
|
143
|
+
};
|
|
144
|
+
}
|
|
145
|
+
//#endregion
|
|
146
|
+
//#region src/runtime/supervise/run-context.ts
|
|
147
|
+
/**
|
|
148
|
+
*
|
|
149
|
+
* `createInMemoryRunContext` — the one-call bundle of the in-memory stores a
|
|
150
|
+
* `createSupervisor().run(root, task, opts)` needs: a fresh `InMemorySpawnJournal`
|
|
151
|
+
* (the event-sourced spawn log), a fresh `InMemoryResultBlobStore` (the
|
|
152
|
+
* content-addressed `outRef` payload store the driver's `observe`/`finalize` reads
|
|
153
|
+
* settled outputs through), and a fresh `createExecutorRegistry()` (the open
|
|
154
|
+
* `AgentSpec → Executor` resolver).
|
|
155
|
+
*
|
|
156
|
+
* It exists to kill the boilerplate every offline/local supervised run repeats by
|
|
157
|
+
* hand — three constructors threaded into `SupervisorOpts` — and to single-source the
|
|
158
|
+
* ONE wiring invariant that is easy to get wrong: when the root is the recursive
|
|
159
|
+
* `driverAgent` LLM-driver brain AND it may spawn nested managed children, the registry MUST be
|
|
160
|
+
* wrapped with `withDriverExecutor` so a child constructed by `driverChild` resolves to the
|
|
161
|
+
* nested-scope executor — and that SAME blob
|
|
162
|
+
* store MUST be the one passed to `driverAgent({ blobs })`, or the driver
|
|
163
|
+
* reads from a different store than the scope writes to. Pass `{ withDriver: true }`
|
|
164
|
+
* and reuse the returned `blobs` for both.
|
|
165
|
+
*
|
|
166
|
+
* The spread shape matches `SupervisorOpts` exactly, so the call site reads:
|
|
167
|
+
* const run = createInMemoryRunContext()
|
|
168
|
+
* await createSupervisor().run(root, task, { budget, runId, ...run })
|
|
169
|
+
*
|
|
170
|
+
* @experimental
|
|
171
|
+
*/
|
|
172
|
+
/**
|
|
173
|
+
* Build a fresh in-memory run context. Every call returns NEW stores (no shared global
|
|
174
|
+
* state between runs), so two runs never cross-contaminate their journals/blobs.
|
|
175
|
+
*/
|
|
176
|
+
function createInMemoryRunContext(opts = {}) {
|
|
177
|
+
const base = createExecutorRegistry();
|
|
178
|
+
return {
|
|
179
|
+
journal: new InMemorySpawnJournal(),
|
|
180
|
+
blobs: new InMemoryResultBlobStore(),
|
|
181
|
+
executors: opts.withDriver ? withDriverExecutor(base) : base
|
|
182
|
+
};
|
|
183
|
+
}
|
|
184
|
+
/**
|
|
185
|
+
* Build a DURABLE run context: the spawn journal and the result blobs are file-backed (fsynced
|
|
186
|
+
* per append/write) under `dir`, and the context carries `resume: true` so spreading it into
|
|
187
|
+
* `SupervisorOpts` makes the supervisor `loadTree`-first. A run that dies mid-flight therefore
|
|
188
|
+
* resumes when it is re-run with the SAME `runId` and the SAME `dir`: the committed children come
|
|
189
|
+
* back on `Scope.resume` (rehydrated by `replaySpawnTree`) instead of being re-executed.
|
|
190
|
+
*
|
|
191
|
+
* Layout: `${dir}/spawn-journal.jsonl` (one JSONL record per event), `${dir}/blobs/` (one
|
|
192
|
+
* content-addressed JSON file per settled result), and `${dir}/coordination-log.jsonl`
|
|
193
|
+
* (questions, findings, answer decisions, and authorized continuation receipts retained as
|
|
194
|
+
* evidence). The directory is created on first write.
|
|
195
|
+
*
|
|
196
|
+
* Opt-in by construction — `createInMemoryRunContext()` is unchanged and stays the default, so no
|
|
197
|
+
* existing consumer writes to disk or resumes unless it asks for this.
|
|
198
|
+
*/
|
|
199
|
+
function createFileRunContext(dir, opts = {}) {
|
|
200
|
+
const base = createExecutorRegistry();
|
|
201
|
+
return {
|
|
202
|
+
journal: new FileSpawnJournal(`${dir}/spawn-journal.jsonl`),
|
|
203
|
+
blobs: new FileResultBlobStore(`${dir}/blobs`),
|
|
204
|
+
executors: opts.withDriver ? withDriverExecutor(base) : base,
|
|
205
|
+
resume: true,
|
|
206
|
+
coordinationLog: new FileCoordinationLog(`${dir}/coordination-log.jsonl`)
|
|
207
|
+
};
|
|
208
|
+
}
|
|
209
|
+
//#endregion
|
|
14
210
|
//#region src/runtime/supervise/detector-monitor.ts
|
|
15
211
|
/**
|
|
16
212
|
*
|
|
@@ -392,6 +588,7 @@ const journalEventKinds = [
|
|
|
392
588
|
"question",
|
|
393
589
|
"settled",
|
|
394
590
|
"finding",
|
|
591
|
+
"submission",
|
|
395
592
|
"steer",
|
|
396
593
|
"answer",
|
|
397
594
|
"instruction",
|
|
@@ -616,10 +813,12 @@ function spawnProfileArg() {
|
|
|
616
813
|
/** Build the driver's MCP tools over a live scope. */
|
|
617
814
|
function createCoordinationTools(opts) {
|
|
618
815
|
const deliverable = opts.deliverable;
|
|
619
|
-
|
|
620
|
-
let
|
|
816
|
+
const priorSubmission = deliverable === void 0 ? void 0 : opts.priorJournal?.find((record) => record.event.type === "submission");
|
|
817
|
+
let stopped = priorSubmission !== void 0;
|
|
818
|
+
let reason = priorSubmission === void 0 ? void 0 : "result-accepted";
|
|
621
819
|
let stopNotified = false;
|
|
622
|
-
let submitted;
|
|
820
|
+
let submitted = priorSubmission === void 0 ? void 0 : detachedFrozen({ result: priorSubmission.event.result });
|
|
821
|
+
let submissionInFlight;
|
|
623
822
|
let questionSeq = 0;
|
|
624
823
|
const ledger = [];
|
|
625
824
|
const questions = [...opts.priorQuestions ?? []];
|
|
@@ -1174,6 +1373,10 @@ function createCoordinationTools(opts) {
|
|
|
1174
1373
|
type: "finding",
|
|
1175
1374
|
...ev.finding
|
|
1176
1375
|
};
|
|
1376
|
+
if (ev.type === "submission") return {
|
|
1377
|
+
type: "submission",
|
|
1378
|
+
result: ev.result
|
|
1379
|
+
};
|
|
1177
1380
|
if (ev.type === "answer") return {
|
|
1178
1381
|
type: "answer",
|
|
1179
1382
|
...ev.down,
|
|
@@ -1586,7 +1789,7 @@ function createCoordinationTools(opts) {
|
|
|
1586
1789
|
const tools = [
|
|
1587
1790
|
{
|
|
1588
1791
|
name: "spawn_worker",
|
|
1589
|
-
description: "Start a worker the driver will drive. `profile` is the worker or another driver; `task` is what it should do. Reserves budget from the conserved pool and fails closed. Pass an optional `budget` (per-field) to give a hard sub-task more than the default — it merges over the per-worker default; the conserved pool is still the hard fence. When a max-live-workers cap is set it also fails closed (`error: \"max-live-workers\"`) while that many workers are still in flight — settle or steer one before spawning another. Pass a `key` naming the assignment to make it run-once ACROSS restarts: a key that already completed returns the finished result (`resumed: \"completed\"` — no work re-runs, nothing is spent), a key whose prior attempt failed
|
|
1792
|
+
description: "Start a worker the driver will drive. `profile` is the worker or another driver; `task` is what it should do. Reserves budget from the conserved pool and fails closed. Pass an optional `budget` (per-field) to give a hard sub-task more than the default — it merges over the per-worker default; the conserved pool is still the hard fence. When a max-live-workers cap is set it also fails closed (`error: \"max-live-workers\"`) while that many workers are still in flight — settle or steer one before spawning another. Pass a `key` naming the assignment to make it run-once ACROSS restarts: a key that already completed returns the finished result (`resumed: \"completed\"` — no work re-runs, nothing is spent), a key whose prior attempt failed (`down`) spawns fresh and says so (`resumed: \"retried\"`), and a key with no terminal receipt is refused (`error: \"in-doubt\"`) until its exact prior execution is recovered. A key still running is refused (`error: \"duplicate-key\"`). Returns `freeSlots`: how many MORE workers you can start right now (`null` = uncapped). While `freeSlots > 0` there is idle capacity — call this again to fill it rather than waiting; parallel workers finish the run sooner than one at a time.",
|
|
1590
1793
|
inputSchema: {
|
|
1591
1794
|
type: "object",
|
|
1592
1795
|
properties: {
|
|
@@ -1736,8 +1939,8 @@ function createCoordinationTools(opts) {
|
|
|
1736
1939
|
...priorHistory
|
|
1737
1940
|
} : {
|
|
1738
1941
|
error: res.reason,
|
|
1739
|
-
reason: res.reason === "usd-unbudgeted" ? "this run's root budget declares no maxUsd, so a child budget naming maxUsd can never be admitted at any amount — spawn with a budget that omits maxUsd" : `the conserved pool refused this spawn (${String(res.reason)}); the run has no allocation left to give this worker`,
|
|
1740
|
-
...res.reason === "usd-unbudgeted" ? { hint: "This run's root budget declares no maxUsd, so a child budget naming maxUsd can never be admitted — at any amount. Retrying with a smaller maxUsd will fail identically. Spawn with a budget that omits maxUsd, or ask the caller to give the run a root maxUsd." } : {},
|
|
1942
|
+
reason: res.reason === "usd-unbudgeted" ? "this run's root budget declares no maxUsd, so a child budget naming maxUsd can never be admitted at any amount — spawn with a budget that omits maxUsd" : res.reason === "in-doubt" ? "this key has a prior worker recorded as started without a terminal receipt; no replacement was started because that remote worker may still be running — inspect or recover the exact prior execution before retrying" : `the conserved pool refused this spawn (${String(res.reason)}); the run has no allocation left to give this worker`,
|
|
1943
|
+
...res.reason === "usd-unbudgeted" ? { hint: "This run's root budget declares no maxUsd, so a child budget naming maxUsd can never be admitted — at any amount. Retrying with a smaller maxUsd will fail identically. Spawn with a budget that omits maxUsd, or ask the caller to give the run a root maxUsd." } : res.reason === "in-doubt" ? { hint: "Do not retry this key. Use the recorded prior worker identity to inspect or recover that exact execution. A terminal receipt or explicit recovery is required before replacement work can start." } : {},
|
|
1741
1944
|
live: liveWorkerCount(),
|
|
1742
1945
|
freeSlots: freeWorkerSlots()
|
|
1743
1946
|
});
|
|
@@ -2042,10 +2245,30 @@ function createCoordinationTools(opts) {
|
|
|
2042
2245
|
retained: "earlier-passing-result",
|
|
2043
2246
|
stop: true
|
|
2044
2247
|
};
|
|
2045
|
-
|
|
2046
|
-
|
|
2047
|
-
|
|
2048
|
-
|
|
2248
|
+
if (submissionInFlight) {
|
|
2249
|
+
await submissionInFlight;
|
|
2250
|
+
return {
|
|
2251
|
+
accepted: true,
|
|
2252
|
+
retained: "earlier-passing-result",
|
|
2253
|
+
stop: true
|
|
2254
|
+
};
|
|
2255
|
+
}
|
|
2256
|
+
const acceptedSubmission = detachedFrozen({ result });
|
|
2257
|
+
const commit = bus.publish({
|
|
2258
|
+
type: "submission",
|
|
2259
|
+
result: acceptedSubmission.result
|
|
2260
|
+
}, { queue: false }).then(() => {
|
|
2261
|
+
submitted = acceptedSubmission;
|
|
2262
|
+
stopped = true;
|
|
2263
|
+
reason = "result-accepted";
|
|
2264
|
+
notifyStop();
|
|
2265
|
+
});
|
|
2266
|
+
submissionInFlight = commit;
|
|
2267
|
+
try {
|
|
2268
|
+
await commit;
|
|
2269
|
+
} finally {
|
|
2270
|
+
if (submissionInFlight === commit) submissionInFlight = void 0;
|
|
2271
|
+
}
|
|
2049
2272
|
return {
|
|
2050
2273
|
accepted: true,
|
|
2051
2274
|
retained: "this-result",
|
|
@@ -2332,204 +2555,6 @@ function safeJsonText(value) {
|
|
|
2332
2555
|
}
|
|
2333
2556
|
}
|
|
2334
2557
|
//#endregion
|
|
2335
|
-
//#region src/runtime/supervise/coordination-log.ts
|
|
2336
|
-
/**
|
|
2337
|
-
* Durable side-log for coordination evidence the spawn journal does not own: questions, analyst
|
|
2338
|
-
* findings, answer decisions, authorized continuation receipts, delivery-attempt markers, and
|
|
2339
|
-
* delivery outcomes. A durable run
|
|
2340
|
-
* (`supervise({ runDir })`) appends them as they publish and loads them on resume, so a restarted
|
|
2341
|
-
* coordinator retains the exact evidence produced by prior processes.
|
|
2342
|
-
*
|
|
2343
|
-
* Answer down-events also fold status on load: a question answered before the crash reloads as
|
|
2344
|
-
* `answered`, not as a re-blocking `open`. Settled events are skipped (the spawn journal is their
|
|
2345
|
-
* ledger). A receipt followed by an attempt but no outcome proves the process died in the delivery
|
|
2346
|
-
* window; that outcome remains unknown and no prior instruction is auto-delivered.
|
|
2347
|
-
*
|
|
2348
|
-
* JSONL, one fsynced record per event, keyed by `runId` — several runs may share one log file
|
|
2349
|
-
* exactly as they share one spawn-journal file.
|
|
2350
|
-
*
|
|
2351
|
-
* @experimental
|
|
2352
|
-
*/
|
|
2353
|
-
/** Persist prior context plus exact continuation authorization, attempt, and result evidence.
|
|
2354
|
-
* Settlements have their own journal. */
|
|
2355
|
-
function persisted(event) {
|
|
2356
|
-
return event.type !== "settled";
|
|
2357
|
-
}
|
|
2358
|
-
/** FS-backed `CoordinationLog`: append-only JSONL, fsynced per record. */
|
|
2359
|
-
var FileCoordinationLog = class {
|
|
2360
|
-
path;
|
|
2361
|
-
appendTail = Promise.resolve();
|
|
2362
|
-
constructor(path) {
|
|
2363
|
-
this.path = path;
|
|
2364
|
-
}
|
|
2365
|
-
async append(runId, record, ownerId) {
|
|
2366
|
-
if (!persisted(record.event)) return;
|
|
2367
|
-
const append = this.appendTail.then(() => this.appendRecord(runId, record, ownerId));
|
|
2368
|
-
this.appendTail = append.catch(() => void 0);
|
|
2369
|
-
return append;
|
|
2370
|
-
}
|
|
2371
|
-
async appendRecord(runId, busRecord, ownerId) {
|
|
2372
|
-
const fs = await import("node:fs/promises");
|
|
2373
|
-
const path = await import("node:path");
|
|
2374
|
-
await fs.mkdir(path.dirname(this.path), { recursive: true });
|
|
2375
|
-
const record = {
|
|
2376
|
-
runId,
|
|
2377
|
-
...ownerId !== void 0 ? { ownerId } : {},
|
|
2378
|
-
...busRecord
|
|
2379
|
-
};
|
|
2380
|
-
const needsSeparator = await prepareJsonlAppend(this.path);
|
|
2381
|
-
const fh = await fs.open(this.path, "a");
|
|
2382
|
-
try {
|
|
2383
|
-
await writeAllBytes(fh, `${needsSeparator ? "\n" : ""}${JSON.stringify(record)}\n`);
|
|
2384
|
-
await fh.sync();
|
|
2385
|
-
} finally {
|
|
2386
|
-
await fh.close();
|
|
2387
|
-
}
|
|
2388
|
-
}
|
|
2389
|
-
async load(runId, ownerId) {
|
|
2390
|
-
const fs = await import("node:fs/promises");
|
|
2391
|
-
let text;
|
|
2392
|
-
try {
|
|
2393
|
-
text = await fs.readFile(this.path, "utf8");
|
|
2394
|
-
} catch (err) {
|
|
2395
|
-
if (isNoEntError(err)) return emptyPriorCoordination(ownerId);
|
|
2396
|
-
throw err;
|
|
2397
|
-
}
|
|
2398
|
-
const byId = /* @__PURE__ */ new Map();
|
|
2399
|
-
const findings = [];
|
|
2400
|
-
const escalations = [];
|
|
2401
|
-
const analystDefinitions = [];
|
|
2402
|
-
const continuations = [];
|
|
2403
|
-
const deliveryEvidence = [];
|
|
2404
|
-
const mail = [];
|
|
2405
|
-
const records = [];
|
|
2406
|
-
let legacySeq = 0;
|
|
2407
|
-
for (const stored of parseCommittedJsonLines(text, this.path)) {
|
|
2408
|
-
if (stored.runId !== runId) continue;
|
|
2409
|
-
if (ownerId !== void 0 && stored.ownerId !== ownerId) continue;
|
|
2410
|
-
const record = "seq" in stored ? {
|
|
2411
|
-
seq: stored.seq,
|
|
2412
|
-
at: stored.at,
|
|
2413
|
-
priority: stored.priority,
|
|
2414
|
-
event: stored.event
|
|
2415
|
-
} : {
|
|
2416
|
-
seq: legacySeq++,
|
|
2417
|
-
at: Date.parse(stored.at),
|
|
2418
|
-
priority: 0,
|
|
2419
|
-
event: stored.event
|
|
2420
|
-
};
|
|
2421
|
-
records.push(record);
|
|
2422
|
-
const ev = record.event;
|
|
2423
|
-
if (ev.type === "delivery-attempt" || ev.type === "steer" || ev.type === "answer") deliveryEvidence.push(ev);
|
|
2424
|
-
if (ev.type === "question") byId.set(ev.question.id, ev.question);
|
|
2425
|
-
else if (ev.type === "finding") findings.push(ev.finding);
|
|
2426
|
-
else if (ev.type === "answer") {
|
|
2427
|
-
const prior = byId.get(ev.questionId);
|
|
2428
|
-
if (prior && ev.down.delivered) byId.set(ev.questionId, {
|
|
2429
|
-
...prior,
|
|
2430
|
-
status: "answered",
|
|
2431
|
-
decision: {
|
|
2432
|
-
kind: "answer",
|
|
2433
|
-
answer: ev.down.instruction,
|
|
2434
|
-
by: "prior-run"
|
|
2435
|
-
}
|
|
2436
|
-
});
|
|
2437
|
-
} else if (ev.type === "instruction") continuations.push(ev.instruction);
|
|
2438
|
-
else if (ev.type === "mail") mail.push(ev.mail);
|
|
2439
|
-
else if (ev.type === "escalation") escalations.push(ev.escalation);
|
|
2440
|
-
else if (ev.type === "analyst-defined") analystDefinitions.push(ev.analyst);
|
|
2441
|
-
}
|
|
2442
|
-
return {
|
|
2443
|
-
...ownerId !== void 0 ? { ownerId } : {},
|
|
2444
|
-
questions: [...byId.values()],
|
|
2445
|
-
findings,
|
|
2446
|
-
escalations,
|
|
2447
|
-
analystDefinitions,
|
|
2448
|
-
continuations,
|
|
2449
|
-
deliveryEvidence,
|
|
2450
|
-
mail,
|
|
2451
|
-
records
|
|
2452
|
-
};
|
|
2453
|
-
}
|
|
2454
|
-
};
|
|
2455
|
-
function emptyPriorCoordination(ownerId) {
|
|
2456
|
-
return {
|
|
2457
|
-
...ownerId !== void 0 ? { ownerId } : {},
|
|
2458
|
-
questions: [],
|
|
2459
|
-
findings: [],
|
|
2460
|
-
escalations: [],
|
|
2461
|
-
analystDefinitions: [],
|
|
2462
|
-
continuations: [],
|
|
2463
|
-
deliveryEvidence: [],
|
|
2464
|
-
mail: [],
|
|
2465
|
-
records: []
|
|
2466
|
-
};
|
|
2467
|
-
}
|
|
2468
|
-
//#endregion
|
|
2469
|
-
//#region src/runtime/supervise/run-context.ts
|
|
2470
|
-
/**
|
|
2471
|
-
*
|
|
2472
|
-
* `createInMemoryRunContext` — the one-call bundle of the in-memory stores a
|
|
2473
|
-
* `createSupervisor().run(root, task, opts)` needs: a fresh `InMemorySpawnJournal`
|
|
2474
|
-
* (the event-sourced spawn log), a fresh `InMemoryResultBlobStore` (the
|
|
2475
|
-
* content-addressed `outRef` payload store the driver's `observe`/`finalize` reads
|
|
2476
|
-
* settled outputs through), and a fresh `createExecutorRegistry()` (the open
|
|
2477
|
-
* `AgentSpec → Executor` resolver).
|
|
2478
|
-
*
|
|
2479
|
-
* It exists to kill the boilerplate every offline/local supervised run repeats by
|
|
2480
|
-
* hand — three constructors threaded into `SupervisorOpts` — and to single-source the
|
|
2481
|
-
* ONE wiring invariant that is easy to get wrong: when the root is the recursive
|
|
2482
|
-
* `driverAgent` LLM-driver brain AND it may spawn DRIVER children (agents
|
|
2483
|
-
* driving agents), the registry MUST be wrapped with `withDriverExecutor` so a
|
|
2484
|
-
* `role: 'driver'` child resolves to the nested-scope executor — and that SAME blob
|
|
2485
|
-
* store MUST be the one passed to `driverAgent({ blobs })`, or the driver
|
|
2486
|
-
* reads from a different store than the scope writes to. Pass `{ withDriver: true }`
|
|
2487
|
-
* and reuse the returned `blobs` for both.
|
|
2488
|
-
*
|
|
2489
|
-
* The spread shape matches `SupervisorOpts` exactly, so the call site reads:
|
|
2490
|
-
* const run = createInMemoryRunContext()
|
|
2491
|
-
* await createSupervisor().run(root, task, { budget, runId, ...run })
|
|
2492
|
-
*
|
|
2493
|
-
* @experimental
|
|
2494
|
-
*/
|
|
2495
|
-
/**
|
|
2496
|
-
* Build a fresh in-memory run context. Every call returns NEW stores (no shared global
|
|
2497
|
-
* state between runs), so two runs never cross-contaminate their journals/blobs.
|
|
2498
|
-
*/
|
|
2499
|
-
function createInMemoryRunContext(opts = {}) {
|
|
2500
|
-
const base = createExecutorRegistry();
|
|
2501
|
-
return {
|
|
2502
|
-
journal: new InMemorySpawnJournal(),
|
|
2503
|
-
blobs: new InMemoryResultBlobStore(),
|
|
2504
|
-
executors: opts.withDriver ? withDriverExecutor(base) : base
|
|
2505
|
-
};
|
|
2506
|
-
}
|
|
2507
|
-
/**
|
|
2508
|
-
* Build a DURABLE run context: the spawn journal and the result blobs are file-backed (fsynced
|
|
2509
|
-
* per append/write) under `dir`, and the context carries `resume: true` so spreading it into
|
|
2510
|
-
* `SupervisorOpts` makes the supervisor `loadTree`-first. A run that dies mid-flight therefore
|
|
2511
|
-
* resumes when it is re-run with the SAME `runId` and the SAME `dir`: the committed children come
|
|
2512
|
-
* back on `Scope.resume` (rehydrated by `replaySpawnTree`) instead of being re-executed.
|
|
2513
|
-
*
|
|
2514
|
-
* Layout: `${dir}/spawn-journal.jsonl` (one JSONL record per event), `${dir}/blobs/` (one
|
|
2515
|
-
* content-addressed JSON file per settled result), and `${dir}/coordination-log.jsonl`
|
|
2516
|
-
* (questions, findings, answer decisions, and authorized continuation receipts retained as
|
|
2517
|
-
* evidence). The directory is created on first write.
|
|
2518
|
-
*
|
|
2519
|
-
* Opt-in by construction — `createInMemoryRunContext()` is unchanged and stays the default, so no
|
|
2520
|
-
* existing consumer writes to disk or resumes unless it asks for this.
|
|
2521
|
-
*/
|
|
2522
|
-
function createFileRunContext(dir, opts = {}) {
|
|
2523
|
-
const base = createExecutorRegistry();
|
|
2524
|
-
return {
|
|
2525
|
-
journal: new FileSpawnJournal(`${dir}/spawn-journal.jsonl`),
|
|
2526
|
-
blobs: new FileResultBlobStore(`${dir}/blobs`),
|
|
2527
|
-
executors: opts.withDriver ? withDriverExecutor(base) : base,
|
|
2528
|
-
resume: true,
|
|
2529
|
-
coordinationLog: new FileCoordinationLog(`${dir}/coordination-log.jsonl`)
|
|
2530
|
-
};
|
|
2531
|
-
}
|
|
2532
|
-
//#endregion
|
|
2533
2558
|
//#region src/runtime/anytime.ts
|
|
2534
2559
|
/**
|
|
2535
2560
|
* The best-so-far fold — the ONE definition of "how good was the run after k results", shared by
|
|
@@ -3346,6 +3371,8 @@ function terminatedDescendants(dir, nodeId, sinceIso) {
|
|
|
3346
3371
|
*/
|
|
3347
3372
|
function driverAgent(opts) {
|
|
3348
3373
|
if (typeof opts.brain !== "function") throw new ValidationError("driverAgent: opts.brain must be a function");
|
|
3374
|
+
if (!Array.isArray(opts.toolNames)) throw new ValidationError("driverAgent: toolNames must name every granted tool explicitly");
|
|
3375
|
+
if (new Set(opts.toolNames).size !== opts.toolNames.length) throw new ValidationError("driverAgent: toolNames contains a duplicate name");
|
|
3349
3376
|
if ((opts.extraTools?.length ?? 0) > 0 && typeof opts.executeExtraTool !== "function") throw new ValidationError("driverAgent: extraTools requires executeExtraTool (how to run a work-tool call)");
|
|
3350
3377
|
if ((opts.analyzeOnSettle ?? []).map(normalizeAnalyzeOnSettle).some((route) => route.agent === void 0) && !opts.analysts) throw new ValidationError("driverAgent: analyzeOnSettle requires analysts (the lens registry the kinds resolve against)");
|
|
3351
3378
|
const reserved = new Set(coordinationVerbNames);
|
|
@@ -3391,7 +3418,25 @@ function driverAgent(opts) {
|
|
|
3391
3418
|
...opts.priorCoordination?.analystDefinitions?.length ? { priorAnalystDefinitions: opts.priorCoordination.analystDefinitions } : {}
|
|
3392
3419
|
});
|
|
3393
3420
|
await coord.ready();
|
|
3394
|
-
|
|
3421
|
+
const availableTools = [...coord.tools, ...opts.nodeTools ?? []];
|
|
3422
|
+
const availableByName = new Map(availableTools.map((tool) => [tool.name, tool]));
|
|
3423
|
+
const extraByName = new Map((opts.extraTools ?? []).map((tool) => [tool.name, tool]));
|
|
3424
|
+
const selectedTools = opts.toolNames.map((name) => {
|
|
3425
|
+
const descriptor = availableByName.get(name);
|
|
3426
|
+
if (descriptor !== void 0) return {
|
|
3427
|
+
kind: "descriptor",
|
|
3428
|
+
descriptor
|
|
3429
|
+
};
|
|
3430
|
+
const extra = extraByName.get(name);
|
|
3431
|
+
if (extra === void 0) throw new ValidationError(`driverAgent: requested tool ${JSON.stringify(name)} is unavailable`);
|
|
3432
|
+
return {
|
|
3433
|
+
kind: "extra",
|
|
3434
|
+
extra
|
|
3435
|
+
};
|
|
3436
|
+
});
|
|
3437
|
+
const modelTools = selectedTools.flatMap((selected) => selected.kind === "descriptor" ? [selected.descriptor] : []);
|
|
3438
|
+
const selectedExtraNames = new Set(selectedTools.flatMap((selected) => selected.kind === "extra" ? [selected.extra.name] : []));
|
|
3439
|
+
opts.onCoordinationTools?.(modelTools);
|
|
3395
3440
|
const acknowledger = opts.controlDir === void 0 ? void 0 : createCancelAcknowledger({
|
|
3396
3441
|
dir: opts.controlDir,
|
|
3397
3442
|
coord,
|
|
@@ -3411,33 +3456,22 @@ function driverAgent(opts) {
|
|
|
3411
3456
|
const rearmed = scope.wait(w.spec, { label: w.label });
|
|
3412
3457
|
if (!rearmed.ok) throw new RuntimeRunStateError(`driverAgent: cannot re-arm resumed wait '${w.label}' (${rearmed.reason})`);
|
|
3413
3458
|
}
|
|
3414
|
-
const byName = new Map(
|
|
3415
|
-
const toolSpecs =
|
|
3416
|
-
|
|
3417
|
-
|
|
3418
|
-
|
|
3419
|
-
|
|
3420
|
-
|
|
3421
|
-
|
|
3422
|
-
|
|
3423
|
-
|
|
3424
|
-
|
|
3425
|
-
|
|
3426
|
-
|
|
3427
|
-
|
|
3428
|
-
|
|
3429
|
-
|
|
3430
|
-
}
|
|
3431
|
-
})),
|
|
3432
|
-
...(opts.extraTools ?? []).map((t) => ({
|
|
3433
|
-
type: "function",
|
|
3434
|
-
function: {
|
|
3435
|
-
name: t.name,
|
|
3436
|
-
description: t.description,
|
|
3437
|
-
parameters: t.parameters
|
|
3438
|
-
}
|
|
3439
|
-
}))
|
|
3440
|
-
];
|
|
3459
|
+
const byName = new Map(modelTools.map((tool) => [tool.name, tool]));
|
|
3460
|
+
const toolSpecs = selectedTools.map((selected) => selected.kind === "descriptor" ? {
|
|
3461
|
+
type: "function",
|
|
3462
|
+
function: {
|
|
3463
|
+
name: selected.descriptor.name,
|
|
3464
|
+
description: selected.descriptor.description,
|
|
3465
|
+
parameters: selected.descriptor.inputSchema
|
|
3466
|
+
}
|
|
3467
|
+
} : {
|
|
3468
|
+
type: "function",
|
|
3469
|
+
function: {
|
|
3470
|
+
name: selected.extra.name,
|
|
3471
|
+
description: selected.extra.description,
|
|
3472
|
+
parameters: selected.extra.parameters
|
|
3473
|
+
}
|
|
3474
|
+
});
|
|
3441
3475
|
const system = typeof opts.systemPrompt === "function" ? opts.systemPrompt(task) : opts.systemPrompt;
|
|
3442
3476
|
const tracker = opts.stopRule ? createProgressTracker({ now }) : void 0;
|
|
3443
3477
|
let progressStopReason;
|
|
@@ -3538,7 +3572,7 @@ function driverAgent(opts) {
|
|
|
3538
3572
|
tools: toolSpecs,
|
|
3539
3573
|
...compaction ? { compaction } : {},
|
|
3540
3574
|
execute: async (name, args) => {
|
|
3541
|
-
if (opts.executeExtraTool) {
|
|
3575
|
+
if (opts.executeExtraTool && selectedExtraNames.has(name)) {
|
|
3542
3576
|
const worked = await runExtraTool(opts.executeExtraTool, name, args);
|
|
3543
3577
|
if (worked !== null && worked !== void 0) return worked;
|
|
3544
3578
|
}
|
|
@@ -3591,7 +3625,10 @@ function driverAgent(opts) {
|
|
|
3591
3625
|
acknowledger?.pass("final");
|
|
3592
3626
|
acknowledger?.finish();
|
|
3593
3627
|
const submitted = coord.submittedResult();
|
|
3594
|
-
if (submitted)
|
|
3628
|
+
if (submitted) {
|
|
3629
|
+
opts.onAcceptedSubmission?.(submitted.result);
|
|
3630
|
+
return submitted.result;
|
|
3631
|
+
}
|
|
3595
3632
|
return runFinalizer(opts.finalizer ?? bestDelivered, {
|
|
3596
3633
|
settled: coord.settled(),
|
|
3597
3634
|
blobs: opts.blobs,
|
|
@@ -3603,7 +3640,7 @@ function driverAgent(opts) {
|
|
|
3603
3640
|
}
|
|
3604
3641
|
/**
|
|
3605
3642
|
* The factual context a resumed driver starts from — everything the durable stores prove about
|
|
3606
|
-
* the prior process(es): committed settlements, per-key states (completed /
|
|
3643
|
+
* the prior process(es): committed settlements, per-key states (completed / in-doubt / failed),
|
|
3607
3644
|
* re-armed waits, carried-over questions/findings/continuation receipts, and spend already paid.
|
|
3608
3645
|
* Injected as the brain's first user-context on a resumed run so it continues from unresolved work;
|
|
3609
3646
|
* old continuation receipts are evidence and are never auto-delivered.
|
|
@@ -3620,10 +3657,10 @@ function resumeBrief(resume, prior) {
|
|
|
3620
3657
|
for (const s of resume.settled) lines.push(s.kind === "done" ? `- ${s.handle.id} (${s.handle.label}): done, score=${s.verdict?.score ?? 0}, valid=${s.verdict?.valid ?? false}, outRef=${s.outRef}` : `- ${s.handle.id} (${s.handle.label}): down, reason=${s.reason}`);
|
|
3621
3658
|
const byState = (state) => [...resume.keys].filter(([, v]) => v.state === state);
|
|
3622
3659
|
const completed = byState("completed");
|
|
3623
|
-
const
|
|
3660
|
+
const inDoubt = byState("in-doubt");
|
|
3624
3661
|
const failed = byState("down");
|
|
3625
3662
|
if (completed.length > 0) lines.push("", "COMPLETED keys — spawn_worker with the same key returns the finished result, spending nothing:", ...completed.map(([k, v]) => `- ${k} → ${v.id} (${v.label})`));
|
|
3626
|
-
if (
|
|
3663
|
+
if (inDoubt.length > 0) lines.push("", "Keys IN DOUBT — a prior process recorded them as started but never recorded a terminal receipt. Do NOT spawn a replacement under these keys; inspect or recover each exact prior execution first:", ...inDoubt.map(([k, v]) => `- ${k} (prior attempt ${v.id}, ${v.label})`));
|
|
3627
3664
|
if (failed.length > 0) lines.push("", "Keys whose prior attempt FAILED (settled down) — spawn_worker with the same key retries:", ...failed.map(([k, v]) => `- ${k} (prior attempt ${v.id}, ${v.label})`));
|
|
3628
3665
|
if (resume.waits.length > 0) lines.push("", "Pending waits RE-ARMED on their original deadlines (they settle through await_event):", ...resume.waits.map((w) => `- ${w.label} (${w.spec.kind})`));
|
|
3629
3666
|
appendPriorCoordination(lines, prior);
|
|
@@ -3632,7 +3669,7 @@ function resumeBrief(resume, prior) {
|
|
|
3632
3669
|
return lines.join("\n");
|
|
3633
3670
|
}
|
|
3634
3671
|
function hasPriorCoordination(prior) {
|
|
3635
|
-
return prior !== void 0 && (prior.questions.length > 0 || prior.findings.length > 0 || prior.continuations.length > 0 || prior.deliveryEvidence.length > 0);
|
|
3672
|
+
return prior !== void 0 && (prior.questions.length > 0 || prior.findings.length > 0 || prior.continuations.length > 0 || prior.deliveryEvidence.length > 0 || prior.records.some((record) => record.event.type === "submission"));
|
|
3636
3673
|
}
|
|
3637
3674
|
function priorCoordinationBrief(prior) {
|
|
3638
3675
|
const lines = [
|
|
@@ -3699,6 +3736,6 @@ function errMessage(e) {
|
|
|
3699
3736
|
return e instanceof Error ? e.message : String(e);
|
|
3700
3737
|
}
|
|
3701
3738
|
//#endregion
|
|
3702
|
-
export {
|
|
3739
|
+
export { watchTrace as A, createCoordinationTools as C, questionEscalationTargets as D, parseAuthoredAnalystDefinition as E, createInMemoryRunContext as M, FileCoordinationLog as N, createEventBus as O, coordinationVerbNames as S, normalizeAnalyzeOnSettle as T, renderAnytimeTable as _, allOf as a, analystToolGroupNames as b, createProgressTracker as c, progressStop as d, sampleFromSettled as f, plateauLength as g, bestSoFar as h, finalizeBestDelivered as i, createFileRunContext as j, defaultToolDetectors as k, noProgressFor as l, areaUnderCurve as m, createSteerAcknowledger as n, allWorkersStalled as o, anytimeReport as p, driverAgent as r, anyOf as s, createCancelAcknowledger as t, plateau as u, ANALYST_DEFINITION_BOUNDS as v, downMessageRefusalReasons as w, canonicalFindingEvent as x, DEFAULT_AWAIT_EVENT_TIMEOUT_MS as y };
|
|
3703
3740
|
|
|
3704
|
-
//# sourceMappingURL=coordination-driver-
|
|
3741
|
+
//# sourceMappingURL=coordination-driver-iSN-m3VX.js.map
|