@caupulican/pi-adaptative 0.90.7 → 0.90.12
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/CHANGELOG.md +56 -0
- package/dist/bundled-resources/skills/tool-call-repair/SKILL.md +5 -4
- package/dist/bundled-resources/skills/tool-call-repair/references/failure-grammar.md +6 -3
- package/dist/bundled-resources/skills/tool-call-repair/references/repair-catalogue.md +1 -0
- package/dist/core/agent-session-contracts.d.ts +2 -0
- package/dist/core/agent-session-contracts.d.ts.map +1 -1
- package/dist/core/agent-session-contracts.js.map +1 -1
- package/dist/core/agent-session.d.ts +8 -7
- package/dist/core/agent-session.d.ts.map +1 -1
- package/dist/core/agent-session.js +84 -197
- package/dist/core/agent-session.js.map +1 -1
- package/dist/core/autonomy/bounded-completion.d.ts +7 -1
- package/dist/core/autonomy/bounded-completion.d.ts.map +1 -1
- package/dist/core/autonomy/bounded-completion.js +8 -2
- package/dist/core/autonomy/bounded-completion.js.map +1 -1
- package/dist/core/autonomy/contracts.d.ts +1 -1
- package/dist/core/autonomy/contracts.d.ts.map +1 -1
- package/dist/core/autonomy/contracts.js.map +1 -1
- package/dist/core/background-lane-controller.d.ts +14 -0
- package/dist/core/background-lane-controller.d.ts.map +1 -1
- package/dist/core/background-lane-controller.js +32 -0
- package/dist/core/background-lane-controller.js.map +1 -1
- package/dist/core/billing-failover-controller.js +1 -1
- package/dist/core/billing-failover-controller.js.map +1 -1
- package/dist/core/context/current-work-memory.d.ts +1 -1
- package/dist/core/context/current-work-memory.d.ts.map +1 -1
- package/dist/core/context/current-work-memory.js +2 -1
- package/dist/core/context/current-work-memory.js.map +1 -1
- package/dist/core/context/long-term-memory-trigger.d.ts +1 -1
- package/dist/core/context/long-term-memory-trigger.d.ts.map +1 -1
- package/dist/core/context/long-term-memory-trigger.js +2 -1
- package/dist/core/context/long-term-memory-trigger.js.map +1 -1
- package/dist/core/delegation/managed-lane-controller.js +2 -2
- package/dist/core/delegation/managed-lane-controller.js.map +1 -1
- package/dist/core/delegation/worker-agent-control-coordinator.d.ts +13 -0
- package/dist/core/delegation/worker-agent-control-coordinator.d.ts.map +1 -1
- package/dist/core/delegation/worker-agent-control-coordinator.js +71 -8
- package/dist/core/delegation/worker-agent-control-coordinator.js.map +1 -1
- package/dist/core/delegation/worker-attempt-executor.d.ts.map +1 -1
- package/dist/core/delegation/worker-attempt-executor.js +13 -8
- package/dist/core/delegation/worker-attempt-executor.js.map +1 -1
- package/dist/core/delegation/worker-claim.d.ts.map +1 -1
- package/dist/core/delegation/worker-claim.js +14 -1
- package/dist/core/delegation/worker-claim.js.map +1 -1
- package/dist/core/delegation/worker-delegation-controller.d.ts +3 -2
- package/dist/core/delegation/worker-delegation-controller.d.ts.map +1 -1
- package/dist/core/delegation/worker-delegation-controller.js +95 -42
- package/dist/core/delegation/worker-delegation-controller.js.map +1 -1
- package/dist/core/delegation/worker-fleet-limits.d.ts.map +1 -1
- package/dist/core/delegation/worker-fleet-limits.js +5 -1
- package/dist/core/delegation/worker-fleet-limits.js.map +1 -1
- package/dist/core/delegation/worker-lane-projection.d.ts.map +1 -1
- package/dist/core/delegation/worker-lane-projection.js +7 -4
- package/dist/core/delegation/worker-lane-projection.js.map +1 -1
- package/dist/core/delegation/worker-lifecycle.d.ts +8 -0
- package/dist/core/delegation/worker-lifecycle.d.ts.map +1 -1
- package/dist/core/delegation/worker-lifecycle.js.map +1 -1
- package/dist/core/delegation/worker-notification-coordinator.d.ts +21 -0
- package/dist/core/delegation/worker-notification-coordinator.d.ts.map +1 -1
- package/dist/core/delegation/worker-notification-coordinator.js +65 -2
- package/dist/core/delegation/worker-notification-coordinator.js.map +1 -1
- package/dist/core/delegation/worker-runner.d.ts +7 -0
- package/dist/core/delegation/worker-runner.d.ts.map +1 -1
- package/dist/core/delegation/worker-runner.js +24 -7
- package/dist/core/delegation/worker-runner.js.map +1 -1
- package/dist/core/delegation/worker-system-prompt.d.ts +54 -0
- package/dist/core/delegation/worker-system-prompt.d.ts.map +1 -0
- package/dist/core/delegation/worker-system-prompt.js +85 -0
- package/dist/core/delegation/worker-system-prompt.js.map +1 -0
- package/dist/core/delegation/worker-tree-budget-coordinator.d.ts.map +1 -1
- package/dist/core/delegation/worker-tree-budget-coordinator.js +4 -0
- package/dist/core/delegation/worker-tree-budget-coordinator.js.map +1 -1
- package/dist/core/delegation/worker-write-reservation-coordinator.d.ts +4 -0
- package/dist/core/delegation/worker-write-reservation-coordinator.d.ts.map +1 -1
- package/dist/core/delegation/worker-write-reservation-coordinator.js +28 -1
- package/dist/core/delegation/worker-write-reservation-coordinator.js.map +1 -1
- package/dist/core/durable-custom-message-turn-controller.d.ts.map +1 -1
- package/dist/core/durable-custom-message-turn-controller.js +14 -3
- package/dist/core/durable-custom-message-turn-controller.js.map +1 -1
- package/dist/core/extension-binding-controller.d.ts +107 -0
- package/dist/core/extension-binding-controller.d.ts.map +1 -0
- package/dist/core/extension-binding-controller.js +224 -0
- package/dist/core/extension-binding-controller.js.map +1 -0
- package/dist/core/extensions/extension-session-scope.d.ts +17 -0
- package/dist/core/extensions/extension-session-scope.d.ts.map +1 -0
- package/dist/core/extensions/extension-session-scope.js +135 -0
- package/dist/core/extensions/extension-session-scope.js.map +1 -0
- package/dist/core/extensions/index.d.ts +1 -0
- package/dist/core/extensions/index.d.ts.map +1 -1
- package/dist/core/extensions/index.js +1 -0
- package/dist/core/extensions/index.js.map +1 -1
- package/dist/core/extensions/types.d.ts +2 -0
- package/dist/core/extensions/types.d.ts.map +1 -1
- package/dist/core/extensions/types.js.map +1 -1
- package/dist/core/extensions/wrapper.d.ts +2 -1
- package/dist/core/extensions/wrapper.d.ts.map +1 -1
- package/dist/core/extensions/wrapper.js +10 -4
- package/dist/core/extensions/wrapper.js.map +1 -1
- package/dist/core/foreground-terminal-handoff-controller.d.ts +9 -0
- package/dist/core/foreground-terminal-handoff-controller.d.ts.map +1 -1
- package/dist/core/foreground-terminal-handoff-controller.js +35 -9
- package/dist/core/foreground-terminal-handoff-controller.js.map +1 -1
- package/dist/core/goal-loop-controller.d.ts.map +1 -1
- package/dist/core/goal-loop-controller.js +10 -1
- package/dist/core/goal-loop-controller.js.map +1 -1
- package/dist/core/goals/compact-goal-context.d.ts +1 -1
- package/dist/core/goals/compact-goal-context.d.ts.map +1 -1
- package/dist/core/goals/compact-goal-context.js +2 -1
- package/dist/core/goals/compact-goal-context.js.map +1 -1
- package/dist/core/goals/goal-execution-errors.d.ts +18 -0
- package/dist/core/goals/goal-execution-errors.d.ts.map +1 -0
- package/dist/core/goals/goal-execution-errors.js +21 -0
- package/dist/core/goals/goal-execution-errors.js.map +1 -0
- package/dist/core/goals/goal-lifecycle.d.ts.map +1 -1
- package/dist/core/goals/goal-lifecycle.js +3 -3
- package/dist/core/goals/goal-lifecycle.js.map +1 -1
- package/dist/core/goals/goal-session-controller.d.ts +11 -0
- package/dist/core/goals/goal-session-controller.d.ts.map +1 -1
- package/dist/core/goals/goal-session-controller.js +74 -14
- package/dist/core/goals/goal-session-controller.js.map +1 -1
- package/dist/core/goals/goal-state.js +1 -1
- package/dist/core/goals/goal-state.js.map +1 -1
- package/dist/core/goals/goal-tool-core.d.ts.map +1 -1
- package/dist/core/goals/goal-tool-core.js +2 -2
- package/dist/core/goals/goal-tool-core.js.map +1 -1
- package/dist/core/goals/natural-language-goal.d.ts +18 -0
- package/dist/core/goals/natural-language-goal.d.ts.map +1 -1
- package/dist/core/goals/natural-language-goal.js +99 -16
- package/dist/core/goals/natural-language-goal.js.map +1 -1
- package/dist/core/model-registry.d.ts +5 -0
- package/dist/core/model-registry.d.ts.map +1 -1
- package/dist/core/model-registry.js +10 -0
- package/dist/core/model-registry.js.map +1 -1
- package/dist/core/model-resolver.d.ts.map +1 -1
- package/dist/core/model-resolver.js +3 -1
- package/dist/core/model-resolver.js.map +1 -1
- package/dist/core/orchestration/capability-gateway.d.ts +1 -1
- package/dist/core/orchestration/capability-gateway.d.ts.map +1 -1
- package/dist/core/orchestration/capability-gateway.js +4 -4
- package/dist/core/orchestration/capability-gateway.js.map +1 -1
- package/dist/core/orchestration/event-store.d.ts +8 -0
- package/dist/core/orchestration/event-store.d.ts.map +1 -1
- package/dist/core/orchestration/event-store.js +9 -7
- package/dist/core/orchestration/event-store.js.map +1 -1
- package/dist/core/orchestration/task-runtime-reducer.js +1 -1
- package/dist/core/orchestration/task-runtime-reducer.js.map +1 -1
- package/dist/core/orchestration/worker-model-pins.d.ts +7 -0
- package/dist/core/orchestration/worker-model-pins.d.ts.map +1 -1
- package/dist/core/orchestration/worker-model-pins.js +17 -1
- package/dist/core/orchestration/worker-model-pins.js.map +1 -1
- package/dist/core/provider-request-runtime-controller.d.ts +9 -0
- package/dist/core/provider-request-runtime-controller.d.ts.map +1 -1
- package/dist/core/provider-request-runtime-controller.js +17 -3
- package/dist/core/provider-request-runtime-controller.js.map +1 -1
- package/dist/core/provider-tool-text.d.ts +15 -1
- package/dist/core/provider-tool-text.d.ts.map +1 -1
- package/dist/core/provider-tool-text.js +42 -10
- package/dist/core/provider-tool-text.js.map +1 -1
- package/dist/core/research/research-lane-controller.d.ts +1 -1
- package/dist/core/research/research-lane-controller.d.ts.map +1 -1
- package/dist/core/research/research-lane-controller.js +2 -1
- package/dist/core/research/research-lane-controller.js.map +1 -1
- package/dist/core/resource-loader.d.ts +3 -0
- package/dist/core/resource-loader.d.ts.map +1 -1
- package/dist/core/resource-loader.js +8 -0
- package/dist/core/resource-loader.js.map +1 -1
- package/dist/core/runtime-builder.d.ts +8 -0
- package/dist/core/runtime-builder.d.ts.map +1 -1
- package/dist/core/runtime-builder.js +6 -0
- package/dist/core/runtime-builder.js.map +1 -1
- package/dist/core/session-supervision-runtime.d.ts.map +1 -1
- package/dist/core/session-supervision-runtime.js +2 -1
- package/dist/core/session-supervision-runtime.js.map +1 -1
- package/dist/core/settings-manager.d.ts +2 -2
- package/dist/core/settings-manager.d.ts.map +1 -1
- package/dist/core/settings-manager.js +7 -2
- package/dist/core/settings-manager.js.map +1 -1
- package/dist/core/tasks/task-state.d.ts +1 -1
- package/dist/core/tasks/task-state.d.ts.map +1 -1
- package/dist/core/tasks/task-state.js +4 -2
- package/dist/core/tasks/task-state.js.map +1 -1
- package/dist/core/tools/delegate.d.ts +13 -0
- package/dist/core/tools/delegate.d.ts.map +1 -1
- package/dist/core/tools/delegate.js +20 -18
- package/dist/core/tools/delegate.js.map +1 -1
- package/dist/core/util/atomic-file.d.ts +7 -0
- package/dist/core/util/atomic-file.d.ts.map +1 -1
- package/dist/core/util/atomic-file.js +8 -6
- package/dist/core/util/atomic-file.js.map +1 -1
- package/dist/core/util/faultable-fs.d.ts +30 -0
- package/dist/core/util/faultable-fs.d.ts.map +1 -0
- package/dist/core/util/faultable-fs.js +30 -0
- package/dist/core/util/faultable-fs.js.map +1 -0
- package/dist/modes/interactive/auth-dialogs-controller.d.ts.map +1 -1
- package/dist/modes/interactive/auth-dialogs-controller.js +1 -0
- package/dist/modes/interactive/auth-dialogs-controller.js.map +1 -1
- package/dist/modes/interactive/components/activity-lane.d.ts.map +1 -1
- package/dist/modes/interactive/components/activity-lane.js +4 -3
- package/dist/modes/interactive/components/activity-lane.js.map +1 -1
- package/dist/modes/interactive/components/footer.js +1 -1
- package/dist/modes/interactive/components/footer.js.map +1 -1
- package/dist/modes/interactive/components/oauth-selector.d.ts +2 -0
- package/dist/modes/interactive/components/oauth-selector.d.ts.map +1 -1
- package/dist/modes/interactive/components/oauth-selector.js +3 -2
- package/dist/modes/interactive/components/oauth-selector.js.map +1 -1
- package/dist/modes/interactive/report-commands.js +1 -1
- package/dist/modes/interactive/report-commands.js.map +1 -1
- package/dist/modes/interactive/session-flow-commands.d.ts +1 -1
- package/dist/modes/interactive/session-flow-commands.d.ts.map +1 -1
- package/dist/modes/interactive/session-flow-commands.js +3 -2
- package/dist/modes/interactive/session-flow-commands.js.map +1 -1
- package/docs/extensions.md +1 -0
- package/docs/providers.md +3 -0
- package/docs/settings.md +4 -2
- package/docs/tool-repair.md +1 -0
- package/examples/extensions/custom-provider-anthropic/package-lock.json +2 -2
- package/examples/extensions/custom-provider-anthropic/package.json +1 -1
- package/examples/extensions/custom-provider-gitlab-duo/package.json +1 -1
- package/examples/extensions/sandbox/package-lock.json +2 -2
- package/examples/extensions/sandbox/package.json +1 -1
- package/examples/extensions/with-deps/package-lock.json +2 -2
- package/examples/extensions/with-deps/package.json +1 -1
- package/npm-shrinkwrap.json +12 -12
- package/package.json +9 -4
|
@@ -1,14 +1,44 @@
|
|
|
1
1
|
const FAILED_TERMINAL_STATUSES = new Set(["failed", "timeout", "budget_exhausted"]);
|
|
2
|
+
/**
|
|
3
|
+
* "partial", "blocked", and "canceled" are neither an outright infra failure nor a clean success —
|
|
4
|
+
* each needs the parent's attention (review a partial/blocked claim, or simply note an explicit
|
|
5
|
+
* stop), but folding them into `failedSinceFlush` would misclassify them as harness failures (the
|
|
6
|
+
* exact bug 78a2158dd fixed in the other direction). Leaving them out of every tally instead made
|
|
7
|
+
* them invisible: a blocked worker previously reported completedSinceFlush:0, failedSinceFlush:0 —
|
|
8
|
+
* counted nowhere. Every LaneTerminalStatus must land in exactly one of the three tallies below.
|
|
9
|
+
*/
|
|
10
|
+
const ATTENTION_TERMINAL_STATUSES = new Set(["partial", "blocked", "canceled"]);
|
|
11
|
+
/**
|
|
12
|
+
* Reuses the former handoff-timeout boundary, now purely as an observation threshold: a re-dispatch
|
|
13
|
+
* on this timer used to create a duplicate consumer of the same handoff, so it was removed. Without
|
|
14
|
+
* any signal in its place, a notify() call that never settles would block deliveryTail (and every
|
|
15
|
+
* subsequent worker terminal) forever with zero visibility. This watchdog only ever warns.
|
|
16
|
+
*/
|
|
17
|
+
const HANDOFF_WATCHDOG_MS = 1_800_000;
|
|
2
18
|
/** Event-driven, bounded terminal outbox. Durable worker events can be replayed into it on resume. */
|
|
3
19
|
export class WorkerNotificationCoordinator {
|
|
4
20
|
constructor(options) {
|
|
5
21
|
this.pending = new Map();
|
|
22
|
+
/**
|
|
23
|
+
* Notifications currently being attempted by notify() — moved here from `pending` the instant
|
|
24
|
+
* delivery starts, never cleared until notify() is CONFIRMED to have settled (success or
|
|
25
|
+
* failure). If notify() never settles, this remains the durable, externally-visible record of
|
|
26
|
+
* what's stuck: a batch must never be reachable ONLY through the one promise closure that may
|
|
27
|
+
* never resolve (that closure is what previously starved every worker queued behind it, with
|
|
28
|
+
* no trace of the lost batch anywhere). getOutstandingRecords() exposes `pending ∪ inFlight` so
|
|
29
|
+
* an owning caller can durably persist and replay them across a process restart.
|
|
30
|
+
*/
|
|
31
|
+
this.inFlight = new Map();
|
|
6
32
|
this.scheduled = false;
|
|
7
33
|
this.disposed = false;
|
|
8
34
|
this.deliveryTail = Promise.resolve();
|
|
9
35
|
this.retryCount = 0;
|
|
10
36
|
this.options = options;
|
|
11
37
|
}
|
|
38
|
+
/** Every notification recorded but not yet confirmed delivered, for durable cross-restart replay. */
|
|
39
|
+
getOutstandingRecords() {
|
|
40
|
+
return [...this.pending.values(), ...this.inFlight.values()].map((notification) => notification.record);
|
|
41
|
+
}
|
|
12
42
|
recordTerminal(record, durableNotificationId) {
|
|
13
43
|
if (record.status === "queued" || record.status === "running")
|
|
14
44
|
return;
|
|
@@ -28,6 +58,7 @@ export class WorkerNotificationCoordinator {
|
|
|
28
58
|
statusChanged() {
|
|
29
59
|
this.schedule();
|
|
30
60
|
}
|
|
61
|
+
/** Callers that want to durably persist outstanding work must read getOutstandingRecords() first. */
|
|
31
62
|
dispose() {
|
|
32
63
|
this.disposed = true;
|
|
33
64
|
this.scheduled = false;
|
|
@@ -35,6 +66,7 @@ export class WorkerNotificationCoordinator {
|
|
|
35
66
|
clearTimeout(this.retryTimer);
|
|
36
67
|
this.retryTimer = undefined;
|
|
37
68
|
this.pending.clear();
|
|
69
|
+
this.inFlight.clear();
|
|
38
70
|
}
|
|
39
71
|
schedule() {
|
|
40
72
|
if (this.disposed || this.scheduled)
|
|
@@ -65,6 +97,19 @@ export class WorkerNotificationCoordinator {
|
|
|
65
97
|
// Diagnostics cannot consume or stop durable notification delivery.
|
|
66
98
|
}
|
|
67
99
|
}
|
|
100
|
+
/**
|
|
101
|
+
* Observe-only: warns once if the in-flight notify() call has not settled after
|
|
102
|
+
* HANDOFF_WATCHDOG_MS. Never re-dispatches and never creates a second notify() consumer —
|
|
103
|
+
* callers must clear() it once the awaited notify() settles, success or failure.
|
|
104
|
+
*/
|
|
105
|
+
startHandoffWatchdog(laneIds) {
|
|
106
|
+
const timer = setTimeout(() => {
|
|
107
|
+
this.warnBestEffort(`Background worker handoff has not settled after ${HANDOFF_WATCHDOG_MS}ms for lane(s): ${laneIds.join(", ")}. Observation only; no redispatch will occur.`);
|
|
108
|
+
}, HANDOFF_WATCHDOG_MS);
|
|
109
|
+
if (typeof timer === "object" && "unref" in timer)
|
|
110
|
+
timer.unref();
|
|
111
|
+
return { clear: () => clearTimeout(timer) };
|
|
112
|
+
}
|
|
68
113
|
flush() {
|
|
69
114
|
this.scheduled = false;
|
|
70
115
|
if (this.disposed)
|
|
@@ -87,6 +132,8 @@ export class WorkerNotificationCoordinator {
|
|
|
87
132
|
running,
|
|
88
133
|
completedSinceFlush: terminalSinceFlush.filter((record) => record.status === "succeeded").length,
|
|
89
134
|
failedSinceFlush: terminalSinceFlush.filter((record) => FAILED_TERMINAL_STATUSES.has(record.status)).length,
|
|
135
|
+
attentionSinceFlush: terminalSinceFlush.filter((record) => ATTENTION_TERMINAL_STATUSES.has(record.status))
|
|
136
|
+
.length,
|
|
90
137
|
terminalSinceFlush,
|
|
91
138
|
};
|
|
92
139
|
try {
|
|
@@ -97,21 +144,37 @@ export class WorkerNotificationCoordinator {
|
|
|
97
144
|
}
|
|
98
145
|
if (batch.length === 0)
|
|
99
146
|
return;
|
|
147
|
+
// Moved into `inFlight`, not merely captured by the closure below: if notify() never
|
|
148
|
+
// settles, this batch stays durably visible via getOutstandingRecords() instead of being
|
|
149
|
+
// reachable ONLY through this one promise, which is exactly what previously starved every
|
|
150
|
+
// worker queued behind it with no trace of the lost batch anywhere.
|
|
151
|
+
for (const notification of batch)
|
|
152
|
+
this.inFlight.set(notification.key, notification);
|
|
100
153
|
const delivery = this.deliveryTail.then(async () => {
|
|
101
154
|
if (this.disposed)
|
|
102
155
|
return;
|
|
103
156
|
// A foreground lease wait is an in-flight side effect, not a failed attempt. Re-dispatching it
|
|
104
157
|
// on a wall-clock timer creates concurrent consumers that later persist the same handoff.
|
|
105
158
|
// Explicit rejection remains retryable; process restart replays the durable pending record.
|
|
106
|
-
|
|
159
|
+
const watchdog = this.startHandoffWatchdog(terminalSinceFlush.map((record) => record.laneId));
|
|
160
|
+
try {
|
|
161
|
+
await this.options.notify(terminalSinceFlush);
|
|
162
|
+
}
|
|
163
|
+
finally {
|
|
164
|
+
watchdog.clear();
|
|
165
|
+
}
|
|
166
|
+
for (const notification of batch)
|
|
167
|
+
this.inFlight.delete(notification.key);
|
|
107
168
|
this.retryCount = 0;
|
|
108
169
|
const durableIds = batch.flatMap((notification) => notification.durableNotificationId ? [notification.durableNotificationId] : []);
|
|
109
170
|
if (durableIds.length > 0)
|
|
110
171
|
this.options.markDurableDelivered(durableIds);
|
|
111
172
|
});
|
|
112
173
|
this.deliveryTail = delivery.catch((error) => {
|
|
113
|
-
for (const notification of batch)
|
|
174
|
+
for (const notification of batch) {
|
|
175
|
+
this.inFlight.delete(notification.key);
|
|
114
176
|
this.pending.set(notification.key, notification);
|
|
177
|
+
}
|
|
115
178
|
this.warnBestEffort(`Background worker handoff failed: ${error instanceof Error ? error.message : String(error)}`);
|
|
116
179
|
this.scheduleRetry();
|
|
117
180
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"worker-notification-coordinator.js","sourceRoot":"","sources":["../../../src/core/delegation/worker-notification-coordinator.ts"],"names":[],"mappings":"AAEA,MAAM,wBAAwB,GAAoC,IAAI,GAAG,CAAC,CAAC,QAAQ,EAAE,SAAS,EAAE,kBAAkB,CAAC,CAAC,CAAC;AAiCrH,sGAAsG;AACtG,MAAM,OAAO,6BA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,OAAO,CAAC,GAAG,CAAC,YAAY,CAAC,GAAG,EAAE,YAAY,CAAC,CAAC;YACnF,IAAI,CAAC,cAAc,CAClB,qCAAqC,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,EAAE,CAC7F,CAAC;YACF,IAAI,CAAC,aAAa,EAAE,CAAC;QACtB,CAAC,CAAC,CAAC;IACJ,CAAC;CACD","sourcesContent":["import type { LaneRecord, LaneTerminalStatus } from \"../autonomy/lane-tracker.ts\";\n\nconst FAILED_TERMINAL_STATUSES: ReadonlySet<LaneTerminalStatus> = new Set([\"failed\", \"timeout\", \"budget_exhausted\"]);\n\nexport interface WorkerTerminalHandoffRecord {\n\tlaneId: string;\n\tstatus: LaneTerminalStatus;\n\treasonCode?: string;\n\t/** Goal ownership retained until delivery so a stopped goal cannot be resurrected by a late terminal. */\n\tgoalId?: string;\n}\n\nexport interface WorkerNotificationStatus {\n\tactive: number;\n\tqueued: number;\n\trunning: number;\n\tcompletedSinceFlush: number;\n\tfailedSinceFlush: number;\n\tterminalSinceFlush: readonly WorkerTerminalHandoffRecord[];\n}\n\ninterface PendingWorkerNotification {\n\tkey: string;\n\trecord: WorkerTerminalHandoffRecord;\n\tdurableNotificationId?: string;\n}\n\nexport interface WorkerNotificationCoordinatorOptions {\n\tgetWorkerRecords(): readonly LaneRecord[];\n\temitStatus(status: WorkerNotificationStatus): void;\n\tnotify(records: readonly WorkerTerminalHandoffRecord[]): Promise<void>;\n\twarn(message: string): void;\n\tmarkDurableDelivered(notificationIds: readonly string[]): void;\n}\n\n/** Event-driven, bounded terminal outbox. Durable worker events can be replayed into it on resume. */\nexport class WorkerNotificationCoordinator {\n\tprivate readonly options: WorkerNotificationCoordinatorOptions;\n\tprivate readonly pending = new Map<string, PendingWorkerNotification>();\n\tprivate scheduled = false;\n\tprivate disposed = false;\n\tprivate deliveryTail = Promise.resolve();\n\tprivate retryTimer: ReturnType<typeof setTimeout> | undefined;\n\tprivate retryCount = 0;\n\n\tconstructor(options: WorkerNotificationCoordinatorOptions) {\n\t\tthis.options = options;\n\t}\n\n\trecordTerminal(record: LaneRecord, durableNotificationId?: string): void {\n\t\tif (record.status === \"queued\" || record.status === \"running\") return;\n\t\tconst key = durableNotificationId ?? `transient:${record.laneId}:${record.completedAt ?? record.status}`;\n\t\tthis.pending.set(key, {\n\t\t\tkey,\n\t\t\trecord: {\n\t\t\t\tlaneId: record.laneId,\n\t\t\t\tstatus: record.status,\n\t\t\t\t...(record.reasonCode ? { reasonCode: record.reasonCode } : {}),\n\t\t\t\t...(record.goalId ? { goalId: record.goalId } : {}),\n\t\t\t},\n\t\t\t...(durableNotificationId ? { durableNotificationId } : {}),\n\t\t});\n\t\tthis.schedule();\n\t}\n\n\tstatusChanged(): void {\n\t\tthis.schedule();\n\t}\n\n\tdispose(): void {\n\t\tthis.disposed = true;\n\t\tthis.scheduled = false;\n\t\tif (this.retryTimer) clearTimeout(this.retryTimer);\n\t\tthis.retryTimer = undefined;\n\t\tthis.pending.clear();\n\t}\n\n\tprivate schedule(): void {\n\t\tif (this.disposed || this.scheduled) return;\n\t\tif (this.retryTimer) clearTimeout(this.retryTimer);\n\t\tthis.retryTimer = undefined;\n\t\tthis.scheduled = true;\n\t\tqueueMicrotask(() => this.flush());\n\t}\n\n\tprivate scheduleRetry(): void {\n\t\tif (this.disposed || this.scheduled || this.retryTimer) return;\n\t\tconst delayMs = Math.min(100 * 2 ** Math.min(this.retryCount, 5), 5_000);\n\t\tthis.retryCount++;\n\t\tthis.retryTimer = setTimeout(() => {\n\t\t\tthis.retryTimer = undefined;\n\t\t\tthis.schedule();\n\t\t}, delayMs);\n\t\tif (typeof this.retryTimer === \"object\" && \"unref\" in this.retryTimer) this.retryTimer.unref();\n\t}\n\n\tprivate warnBestEffort(message: string): void {\n\t\ttry {\n\t\t\tthis.options.warn(message);\n\t\t} catch {\n\t\t\t// Diagnostics cannot consume or stop durable notification delivery.\n\t\t}\n\t}\n\n\tprivate flush(): void {\n\t\tthis.scheduled = false;\n\t\tif (this.disposed) return;\n\t\tconst batch = [...this.pending.values()];\n\t\tthis.pending.clear();\n\t\tlet workerRecords: readonly LaneRecord[] = [];\n\t\ttry {\n\t\t\tworkerRecords = this.options.getWorkerRecords();\n\t\t} catch (error) {\n\t\t\tthis.warnBestEffort(\n\t\t\t\t`Background worker status projection failed: ${error instanceof Error ? error.message : String(error)}`,\n\t\t\t);\n\t\t}\n\t\tconst queued = workerRecords.filter((record) => record.status === \"queued\").length;\n\t\tconst running = workerRecords.filter((record) => record.status === \"running\").length;\n\t\tconst terminalSinceFlush = batch.map((notification) => notification.record);\n\t\tconst status = {\n\t\t\tactive: queued + running,\n\t\t\tqueued,\n\t\t\trunning,\n\t\t\tcompletedSinceFlush: terminalSinceFlush.filter((record) => record.status === \"succeeded\").length,\n\t\t\tfailedSinceFlush: terminalSinceFlush.filter((record) => FAILED_TERMINAL_STATUSES.has(record.status)).length,\n\t\t\tterminalSinceFlush,\n\t\t};\n\t\ttry {\n\t\t\tthis.options.emitStatus(status);\n\t\t} catch (error) {\n\t\t\tthis.warnBestEffort(\n\t\t\t\t`Background worker status observer failed: ${error instanceof Error ? error.message : String(error)}`,\n\t\t\t);\n\t\t}\n\t\tif (batch.length === 0) return;\n\t\tconst delivery = this.deliveryTail.then(async () => {\n\t\t\tif (this.disposed) return;\n\t\t\t// A foreground lease wait is an in-flight side effect, not a failed attempt. Re-dispatching it\n\t\t\t// on a wall-clock timer creates concurrent consumers that later persist the same handoff.\n\t\t\t// Explicit rejection remains retryable; process restart replays the durable pending record.\n\t\t\tawait this.options.notify(terminalSinceFlush);\n\t\t\tthis.retryCount = 0;\n\t\t\tconst durableIds = batch.flatMap((notification) =>\n\t\t\t\tnotification.durableNotificationId ? [notification.durableNotificationId] : [],\n\t\t\t);\n\t\t\tif (durableIds.length > 0) this.options.markDurableDelivered(durableIds);\n\t\t});\n\t\tthis.deliveryTail = delivery.catch((error: unknown) => {\n\t\t\tfor (const notification of batch) this.pending.set(notification.key, notification);\n\t\t\tthis.warnBestEffort(\n\t\t\t\t`Background worker handoff failed: ${error instanceof Error ? error.message : String(error)}`,\n\t\t\t);\n\t\t\tthis.scheduleRetry();\n\t\t});\n\t}\n}\n"]}
|
|
1
|
+
{"version":3,"file":"worker-notification-coordinator.js","sourceRoot":"","sources":["../../../src/core/delegation/worker-notification-coordinator.ts"],"names":[],"mappings":"AAEA,MAAM,wBAAwB,GAAoC,IAAI,GAAG,CAAC,CAAC,QAAQ,EAAE,SAAS,EAAE,kBAAkB,CAAC,CAAC,CAAC;AACrH;;;;;;;GAOG;AACH,MAAM,2BAA2B,GAAoC,IAAI,GAAG,CAAC,CAAC,SAAS,EAAE,SAAS,EAAE,UAAU,CAAC,CAAC,CAAC;AAEjH;;;;;GAKG;AACH,MAAM,mBAAmB,GAAG,SAAS,CAAC;AAmCtC,sGAAsG;AACtG,MAAM,OAAO,6BAA6B;IAmBzC,YAAY,OAA6C;QAjBxC,YAAO,GAAG,IAAI,GAAG,EAAqC,CAAC;QACxE;;;;;;;;WAQG;QACc,aAAQ,GAAG,IAAI,GAAG,EAAqC,CAAC;QACjE,cAAS,GAAG,KAAK,CAAC;QAClB,aAAQ,GAAG,KAAK,CAAC;QACjB,iBAAY,GAAG,OAAO,CAAC,OAAO,EAAE,CAAC;QAEjC,eAAU,GAAG,CAAC,CAAC;QAGtB,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC;IACxB,CAAC;IAED,qGAAqG;IACrG,qBAAqB;QACpB,OAAO,CAAC,GAAG,IAAI,CAAC,OAAO,CAAC,MAAM,EAAE,EAAE,GAAG,IAAI,CAAC,QAAQ,CAAC,MAAM,EAAE,CAAC,CAAC,GAAG,CAAC,CAAC,YAAY,EAAE,EAAE,CAAC,YAAY,CAAC,MAAM,CAAC,CAAC;IACzG,CAAC;IAED,cAAc,CAAC,MAAkB,EAAE,qBAA8B;QAChE,IAAI,MAAM,CAAC,MA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;CACD","sourcesContent":["import type { LaneRecord, LaneTerminalStatus } from \"../autonomy/lane-tracker.ts\";\n\nconst FAILED_TERMINAL_STATUSES: ReadonlySet<LaneTerminalStatus> = new Set([\"failed\", \"timeout\", \"budget_exhausted\"]);\n/**\n * \"partial\", \"blocked\", and \"canceled\" are neither an outright infra failure nor a clean success —\n * each needs the parent's attention (review a partial/blocked claim, or simply note an explicit\n * stop), but folding them into `failedSinceFlush` would misclassify them as harness failures (the\n * exact bug 78a2158dd fixed in the other direction). Leaving them out of every tally instead made\n * them invisible: a blocked worker previously reported completedSinceFlush:0, failedSinceFlush:0 —\n * counted nowhere. Every LaneTerminalStatus must land in exactly one of the three tallies below.\n */\nconst ATTENTION_TERMINAL_STATUSES: ReadonlySet<LaneTerminalStatus> = new Set([\"partial\", \"blocked\", \"canceled\"]);\n\n/**\n * Reuses the former handoff-timeout boundary, now purely as an observation threshold: a re-dispatch\n * on this timer used to create a duplicate consumer of the same handoff, so it was removed. Without\n * any signal in its place, a notify() call that never settles would block deliveryTail (and every\n * subsequent worker terminal) forever with zero visibility. This watchdog only ever warns.\n */\nconst HANDOFF_WATCHDOG_MS = 1_800_000;\n\nexport interface WorkerTerminalHandoffRecord {\n\tlaneId: string;\n\tstatus: LaneTerminalStatus;\n\treasonCode?: string;\n\t/** Goal ownership retained until delivery so a stopped goal cannot be resurrected by a late terminal. */\n\tgoalId?: string;\n}\n\nexport interface WorkerNotificationStatus {\n\tactive: number;\n\tqueued: number;\n\trunning: number;\n\tcompletedSinceFlush: number;\n\tfailedSinceFlush: number;\n\t/** partial, blocked, and canceled terminals — needs parent review, not a harness failure. */\n\tattentionSinceFlush: number;\n\tterminalSinceFlush: readonly WorkerTerminalHandoffRecord[];\n}\n\ninterface PendingWorkerNotification {\n\tkey: string;\n\trecord: WorkerTerminalHandoffRecord;\n\tdurableNotificationId?: string;\n}\n\nexport interface WorkerNotificationCoordinatorOptions {\n\tgetWorkerRecords(): readonly LaneRecord[];\n\temitStatus(status: WorkerNotificationStatus): void;\n\tnotify(records: readonly WorkerTerminalHandoffRecord[]): Promise<void>;\n\twarn(message: string): void;\n\tmarkDurableDelivered(notificationIds: readonly string[]): void;\n}\n\n/** Event-driven, bounded terminal outbox. Durable worker events can be replayed into it on resume. */\nexport class WorkerNotificationCoordinator {\n\tprivate readonly options: WorkerNotificationCoordinatorOptions;\n\tprivate readonly pending = new Map<string, PendingWorkerNotification>();\n\t/**\n\t * Notifications currently being attempted by notify() — moved here from `pending` the instant\n\t * delivery starts, never cleared until notify() is CONFIRMED to have settled (success or\n\t * failure). If notify() never settles, this remains the durable, externally-visible record of\n\t * what's stuck: a batch must never be reachable ONLY through the one promise closure that may\n\t * never resolve (that closure is what previously starved every worker queued behind it, with\n\t * no trace of the lost batch anywhere). getOutstandingRecords() exposes `pending ∪ inFlight` so\n\t * an owning caller can durably persist and replay them across a process restart.\n\t */\n\tprivate readonly inFlight = new Map<string, PendingWorkerNotification>();\n\tprivate scheduled = false;\n\tprivate disposed = false;\n\tprivate deliveryTail = Promise.resolve();\n\tprivate retryTimer: ReturnType<typeof setTimeout> | undefined;\n\tprivate retryCount = 0;\n\n\tconstructor(options: WorkerNotificationCoordinatorOptions) {\n\t\tthis.options = options;\n\t}\n\n\t/** Every notification recorded but not yet confirmed delivered, for durable cross-restart replay. */\n\tgetOutstandingRecords(): readonly WorkerTerminalHandoffRecord[] {\n\t\treturn [...this.pending.values(), ...this.inFlight.values()].map((notification) => notification.record);\n\t}\n\n\trecordTerminal(record: LaneRecord, durableNotificationId?: string): void {\n\t\tif (record.status === \"queued\" || record.status === \"running\") return;\n\t\tconst key = durableNotificationId ?? `transient:${record.laneId}:${record.completedAt ?? record.status}`;\n\t\tthis.pending.set(key, {\n\t\t\tkey,\n\t\t\trecord: {\n\t\t\t\tlaneId: record.laneId,\n\t\t\t\tstatus: record.status,\n\t\t\t\t...(record.reasonCode ? { reasonCode: record.reasonCode } : {}),\n\t\t\t\t...(record.goalId ? { goalId: record.goalId } : {}),\n\t\t\t},\n\t\t\t...(durableNotificationId ? { durableNotificationId } : {}),\n\t\t});\n\t\tthis.schedule();\n\t}\n\n\tstatusChanged(): void {\n\t\tthis.schedule();\n\t}\n\n\t/** Callers that want to durably persist outstanding work must read getOutstandingRecords() first. */\n\tdispose(): void {\n\t\tthis.disposed = true;\n\t\tthis.scheduled = false;\n\t\tif (this.retryTimer) clearTimeout(this.retryTimer);\n\t\tthis.retryTimer = undefined;\n\t\tthis.pending.clear();\n\t\tthis.inFlight.clear();\n\t}\n\n\tprivate schedule(): void {\n\t\tif (this.disposed || this.scheduled) return;\n\t\tif (this.retryTimer) clearTimeout(this.retryTimer);\n\t\tthis.retryTimer = undefined;\n\t\tthis.scheduled = true;\n\t\tqueueMicrotask(() => this.flush());\n\t}\n\n\tprivate scheduleRetry(): void {\n\t\tif (this.disposed || this.scheduled || this.retryTimer) return;\n\t\tconst delayMs = Math.min(100 * 2 ** Math.min(this.retryCount, 5), 5_000);\n\t\tthis.retryCount++;\n\t\tthis.retryTimer = setTimeout(() => {\n\t\t\tthis.retryTimer = undefined;\n\t\t\tthis.schedule();\n\t\t}, delayMs);\n\t\tif (typeof this.retryTimer === \"object\" && \"unref\" in this.retryTimer) this.retryTimer.unref();\n\t}\n\n\tprivate warnBestEffort(message: string): void {\n\t\ttry {\n\t\t\tthis.options.warn(message);\n\t\t} catch {\n\t\t\t// Diagnostics cannot consume or stop durable notification delivery.\n\t\t}\n\t}\n\n\t/**\n\t * Observe-only: warns once if the in-flight notify() call has not settled after\n\t * HANDOFF_WATCHDOG_MS. Never re-dispatches and never creates a second notify() consumer —\n\t * callers must clear() it once the awaited notify() settles, success or failure.\n\t */\n\tprivate startHandoffWatchdog(laneIds: readonly string[]): { clear(): void } {\n\t\tconst timer = setTimeout(() => {\n\t\t\tthis.warnBestEffort(\n\t\t\t\t`Background worker handoff has not settled after ${HANDOFF_WATCHDOG_MS}ms for lane(s): ${laneIds.join(\", \")}. Observation only; no redispatch will occur.`,\n\t\t\t);\n\t\t}, HANDOFF_WATCHDOG_MS);\n\t\tif (typeof timer === \"object\" && \"unref\" in timer) timer.unref();\n\t\treturn { clear: () => clearTimeout(timer) };\n\t}\n\n\tprivate flush(): void {\n\t\tthis.scheduled = false;\n\t\tif (this.disposed) return;\n\t\tconst batch = [...this.pending.values()];\n\t\tthis.pending.clear();\n\t\tlet workerRecords: readonly LaneRecord[] = [];\n\t\ttry {\n\t\t\tworkerRecords = this.options.getWorkerRecords();\n\t\t} catch (error) {\n\t\t\tthis.warnBestEffort(\n\t\t\t\t`Background worker status projection failed: ${error instanceof Error ? error.message : String(error)}`,\n\t\t\t);\n\t\t}\n\t\tconst queued = workerRecords.filter((record) => record.status === \"queued\").length;\n\t\tconst running = workerRecords.filter((record) => record.status === \"running\").length;\n\t\tconst terminalSinceFlush = batch.map((notification) => notification.record);\n\t\tconst status = {\n\t\t\tactive: queued + running,\n\t\t\tqueued,\n\t\t\trunning,\n\t\t\tcompletedSinceFlush: terminalSinceFlush.filter((record) => record.status === \"succeeded\").length,\n\t\t\tfailedSinceFlush: terminalSinceFlush.filter((record) => FAILED_TERMINAL_STATUSES.has(record.status)).length,\n\t\t\tattentionSinceFlush: terminalSinceFlush.filter((record) => ATTENTION_TERMINAL_STATUSES.has(record.status))\n\t\t\t\t.length,\n\t\t\tterminalSinceFlush,\n\t\t};\n\t\ttry {\n\t\t\tthis.options.emitStatus(status);\n\t\t} catch (error) {\n\t\t\tthis.warnBestEffort(\n\t\t\t\t`Background worker status observer failed: ${error instanceof Error ? error.message : String(error)}`,\n\t\t\t);\n\t\t}\n\t\tif (batch.length === 0) return;\n\t\t// Moved into `inFlight`, not merely captured by the closure below: if notify() never\n\t\t// settles, this batch stays durably visible via getOutstandingRecords() instead of being\n\t\t// reachable ONLY through this one promise, which is exactly what previously starved every\n\t\t// worker queued behind it with no trace of the lost batch anywhere.\n\t\tfor (const notification of batch) this.inFlight.set(notification.key, notification);\n\t\tconst delivery = this.deliveryTail.then(async () => {\n\t\t\tif (this.disposed) return;\n\t\t\t// A foreground lease wait is an in-flight side effect, not a failed attempt. Re-dispatching it\n\t\t\t// on a wall-clock timer creates concurrent consumers that later persist the same handoff.\n\t\t\t// Explicit rejection remains retryable; process restart replays the durable pending record.\n\t\t\tconst watchdog = this.startHandoffWatchdog(terminalSinceFlush.map((record) => record.laneId));\n\t\t\ttry {\n\t\t\t\tawait this.options.notify(terminalSinceFlush);\n\t\t\t} finally {\n\t\t\t\twatchdog.clear();\n\t\t\t}\n\t\t\tfor (const notification of batch) this.inFlight.delete(notification.key);\n\t\t\tthis.retryCount = 0;\n\t\t\tconst durableIds = batch.flatMap((notification) =>\n\t\t\t\tnotification.durableNotificationId ? [notification.durableNotificationId] : [],\n\t\t\t);\n\t\t\tif (durableIds.length > 0) this.options.markDurableDelivered(durableIds);\n\t\t});\n\t\tthis.deliveryTail = delivery.catch((error: unknown) => {\n\t\t\tfor (const notification of batch) {\n\t\t\t\tthis.inFlight.delete(notification.key);\n\t\t\t\tthis.pending.set(notification.key, notification);\n\t\t\t}\n\t\t\tthis.warnBestEffort(\n\t\t\t\t`Background worker handoff failed: ${error instanceof Error ? error.message : String(error)}`,\n\t\t\t);\n\t\t\tthis.scheduleRetry();\n\t\t});\n\t}\n}\n"]}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import type { GateOutcome, WorkerClaim, WorkerRequest } from "../autonomy/contracts.ts";
|
|
2
2
|
import { type EvidenceFindingDraft } from "../autonomy/evidence-finding-projection.ts";
|
|
3
3
|
import type { LaneTerminalStatus } from "../autonomy/lane-tracker.ts";
|
|
4
|
+
import type { WorkerRole } from "../orchestration/contracts.ts";
|
|
4
5
|
import { buildVerifierSystemPrompt, buildWorkerSystemPrompt, WORKER_LANE_SYSTEM_PROMPT, WORKER_OPERATOR_LANE_SYSTEM_PROMPT, WORKER_WRITE_LANE_SYSTEM_PROMPT } from "../provider-prompt-contracts.ts";
|
|
5
6
|
import { type AppliedActionsReport, type RejectedWorkerActions, type WorkerAction } from "./worker-actions.ts";
|
|
6
7
|
export { buildVerifierSystemPrompt, buildWorkerSystemPrompt, WORKER_LANE_SYSTEM_PROMPT, WORKER_OPERATOR_LANE_SYSTEM_PROMPT, WORKER_WRITE_LANE_SYSTEM_PROMPT, };
|
|
@@ -65,6 +66,12 @@ export interface WorkerRunOutcome {
|
|
|
65
66
|
/** Underlying executor error for bounded failures; drives the in-process retry decision. */
|
|
66
67
|
reasonDetail?: string;
|
|
67
68
|
costUsd: number;
|
|
69
|
+
/**
|
|
70
|
+
* Set by the caller (worker-delegation-controller.ts admission), never by runWorker itself, when
|
|
71
|
+
* a pin policy is active, the effective role has no pin, and the caller requested an explicit
|
|
72
|
+
* model — i.e. the owner's model pin was evaded, not merely inapplicable. Diagnostics only.
|
|
73
|
+
*/
|
|
74
|
+
modelPinBypass?: WorkerRole;
|
|
68
75
|
}
|
|
69
76
|
export declare function buildWorkerUserPrompt(request: WorkerRequest): string;
|
|
70
77
|
export interface ParsedWorkerOutput {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"worker-runner.d.ts","sourceRoot":"","sources":["../../../src/core/delegation/worker-runner.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAe,WAAW,EAAE,WAAW,EAAE,aAAa,EAAE,MAAM,0BAA0B,CAAC;AACrG,OAAO,EACN,KAAK,oBAAoB,EAGzB,MAAM,4CAA4C,CAAC;AACpD,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,6BAA6B,CAAC;AACtE,OAAO,EACN,yBAAyB,EACzB,uBAAuB,EACvB,yBAAyB,EACzB,kCAAkC,EAClC,+BAA+B,EAC/B,MAAM,iCAAiC,CAAC;AAEzC,OAAO,EACN,KAAK,oBAAoB,EAEzB,KAAK,qBAAqB,EAC1B,KAAK,YAAY,EACjB,MAAM,qBAAqB,CAAC;AAW7B,OAAO,EACN,yBAAyB,EACzB,uBAAuB,EACvB,yBAAyB,EACzB,kCAAkC,EAClC,+BAA+B,GAC/B,CAAC;AA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AAU,EAAE,kBAAkB,CAAC;IAC/B,UAAU,EAAE,MAAM,CAAC;IACnB,4FAA4F;IAC5F,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,OAAO,EAAE,MAAM,CAAC;
|
|
1
|
+
{"version":3,"file":"worker-runner.d.ts","sourceRoot":"","sources":["../../../src/core/delegation/worker-runner.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAe,WAAW,EAAE,WAAW,EAAE,aAAa,EAAE,MAAM,0BAA0B,CAAC;AACrG,OAAO,EACN,KAAK,oBAAoB,EAGzB,MAAM,4CAA4C,CAAC;AACpD,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,6BAA6B,CAAC;AACtE,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,+BAA+B,CAAC;AAChE,OAAO,EACN,yBAAyB,EACzB,uBAAuB,EACvB,yBAAyB,EACzB,kCAAkC,EAClC,+BAA+B,EAC/B,MAAM,iCAAiC,CAAC;AAEzC,OAAO,EACN,KAAK,oBAAoB,EAEzB,KAAK,qBAAqB,EAC1B,KAAK,YAAY,EACjB,MAAM,qBAAqB,CAAC;AAW7B,OAAO,EACN,yBAAyB,EACzB,uBAAuB,EACvB,yBAAyB,EACzB,kCAAkC,EAClC,+BAA+B,GAC/B,CAAC;AAEF;;;;;;;GAOG;AAEH,MAAM,WAAW,gBAAgB;IAChC,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,MAAM,CAAC;IAChB,UAAU,EAAE,MAAM,CAAC;IACnB,2FAA2F;IAC3F,YAAY,CAAC,EAAE,SAAS,MAAM,EAAE,CAAC;IACjC,qFAAqF;IACrF,QAAQ,CAAC,EAAE,SAAS,MAAM,EAAE,CAAC;CAC7B;AAED,MAAM,WAAW,mBAAmB;IACnC,OAAO,EAAE,aAAa,CAAC;IACvB,oGAAoG;IACpG,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,qDAAqD;IACrD,cAAc,EAAE,MAAM,CAAC;IACvB;;;OAGG;IACH,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ACjC,OAAO,EAAE,YAAY,EAAE,CAAC;IACxB,wFAAwF;IACxF,eAAe,CAAC,EAAE,qBAAqB,CAAC;IACxC,OAAO,CAAC,EAAE,UAAU,GAAG,UAAU,CAAC;IAClC,WAAW,EAAE,MAAM,EAAE,CAAC;CACtB;AAkFD,wBAAgB,iBAAiB,CAAC,IAAI,EAAE,MAAM,GAAG,kBAAkB,GAAG,SAAS,CAkD9E;AA8CD,wBAAsB,SAAS,CAAC,OAAO,EAAE,mBAAmB,GAAG,OAAO,CAAC,gBAAgB,CAAC,CA0SvF"}
|
|
@@ -215,19 +215,29 @@ export async function runWorker(options) {
|
|
|
215
215
|
const liveChangedFilesReport = collectBoundedWorkerClaimChangedFiles(options.getChangedFiles?.() ?? []);
|
|
216
216
|
const liveChangedFiles = liveChangedFilesReport.values;
|
|
217
217
|
if (bounded.failure) {
|
|
218
|
+
const isBudgetExhausted = bounded.failure.status === "budget_exhausted" ||
|
|
219
|
+
bounded.failure.reasonCode.includes("budget_exhausted") ||
|
|
220
|
+
bounded.failure.reasonCode.includes("cost_budget_exceeded");
|
|
218
221
|
const cancelled = bounded.failure.status === "canceled" || bounded.failure.status === "timeout";
|
|
219
|
-
const blockers =
|
|
220
|
-
|
|
221
|
-
|
|
222
|
+
const blockers = [
|
|
223
|
+
...(liveChangedFilesReport.overflowed
|
|
224
|
+
? ["worker changed-file report exceeded the durable claim bound; parent review is required"]
|
|
225
|
+
: []),
|
|
226
|
+
...(isBudgetExhausted ? [`budget limit reached: ${bounded.failure.reasonCode}`] : []),
|
|
227
|
+
];
|
|
228
|
+
const status = isBudgetExhausted ? "partial" : cancelled ? "cancelled" : "failed";
|
|
229
|
+
const summary = isBudgetExhausted
|
|
230
|
+
? `Worker paused at budget limit (${bounded.failure.reasonCode})${bounded.failure.detail ? `: ${bounded.failure.detail}` : "."}`
|
|
231
|
+
: `Worker did not complete: ${bounded.failure.reasonCode}${bounded.failure.detail ? ` — ${bounded.failure.detail}` : ""}`;
|
|
222
232
|
return finishOutcome({
|
|
223
233
|
request: options.request,
|
|
224
234
|
cwd: options.cwd,
|
|
225
235
|
claim: {
|
|
226
236
|
...baseClaim,
|
|
227
237
|
changedFiles: liveChangedFiles,
|
|
228
|
-
status
|
|
229
|
-
summary
|
|
230
|
-
...(blockers ? { blockers } : {}),
|
|
238
|
+
status,
|
|
239
|
+
summary,
|
|
240
|
+
...(blockers.length > 0 ? { blockers } : {}),
|
|
231
241
|
},
|
|
232
242
|
laneStatus: bounded.failure.status,
|
|
233
243
|
reasonCode: bounded.failure.reasonCode,
|
|
@@ -432,10 +442,17 @@ export async function runWorker(options) {
|
|
|
432
442
|
});
|
|
433
443
|
}
|
|
434
444
|
const overBudget = options.maxUsd !== undefined && costUsd > options.maxUsd;
|
|
445
|
+
const finalClaim = overBudget
|
|
446
|
+
? {
|
|
447
|
+
...claim,
|
|
448
|
+
status: "partial",
|
|
449
|
+
blockers: [...(claim.blockers ?? []), "cost_budget_exceeded"],
|
|
450
|
+
}
|
|
451
|
+
: claim;
|
|
435
452
|
return finishOutcome({
|
|
436
453
|
request: options.request,
|
|
437
454
|
cwd: options.cwd,
|
|
438
|
-
claim,
|
|
455
|
+
claim: finalClaim,
|
|
439
456
|
laneStatus: overBudget ? "budget_exhausted" : "succeeded",
|
|
440
457
|
reasonCode: overBudget
|
|
441
458
|
? "cost_budget_exceeded"
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"worker-runner.js","sourceRoot":"","sources":["../../../src/core/delegation/worker-runner.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,oBAAoB,EAAE,MAAM,mCAAmC,CAAC;AAEzE,OAAO,EAEN,wBAAwB,EACxB,uBAAuB,GACvB,MAAM,4CAA4C,CAAC;AAEpD,OAAO,EACN,yBAAyB,EACzB,uBAAuB,EACvB,yBAAyB,EACzB,kCAAkC,EAClC,+BAA+B,GAC/B,MAAM,iCAAiC,CAAC;AACzC,OAAO,EAAE,oBAAoB,EAAE,MAAM,gCAAgC,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CAAC,sBAAsB;YACxB,CAAC,CAAC,KAAK,CAAC,YAAY;gBACnB,CAAC,CAAC,KAAK,CAAC,YAAY,CAAC,OAAO,KAAK,UAAU;oBAC1C,CAAC,CAAC,uBAAuB;oBACzB,CAAC,CAAC,uBAAuB;gBAC1B,CAAC,CAAC,kBAAkB;QACtB,OAAO;KACP,CAAC,CAAC;AACJ,CAAC","sourcesContent":["import { runBoundedCompletion } from \"../autonomy/bounded-completion.ts\";\nimport type { EvidenceRef, GateOutcome, WorkerClaim, WorkerRequest } from \"../autonomy/contracts.ts\";\nimport {\n\ttype EvidenceFindingDraft,\n\tnormalizeEvidenceFinding,\n\tprojectEvidenceFindings,\n} from \"../autonomy/evidence-finding-projection.ts\";\nimport type { LaneTerminalStatus } from \"../autonomy/lane-tracker.ts\";\nimport {\n\tbuildVerifierSystemPrompt,\n\tbuildWorkerSystemPrompt,\n\tWORKER_LANE_SYSTEM_PROMPT,\n\tWORKER_OPERATOR_LANE_SYSTEM_PROMPT,\n\tWORKER_WRITE_LANE_SYSTEM_PROMPT,\n} from \"../provider-prompt-contracts.ts\";\nimport { createEvidenceBundle } from \"../research/evidence-bundle.ts\";\nimport {\n\ttype AppliedActionsReport,\n\tparseWorkerActions,\n\ttype RejectedWorkerActions,\n\ttype WorkerAction,\n} from \"./worker-actions.ts\";\nimport {\n\tcollectBoundedWorkerClaimBlockers,\n\tcollectBoundedWorkerClaimChangedFiles,\n\tMAX_WORKER_CLAIM_BLOCKER_CHARS,\n\tMAX_WORKER_CLAIM_BLOCKERS,\n\tMAX_WORKER_CLAIM_SUMMARY_CHARS,\n\tnormalizeWorkerClaimForHost,\n\tvalidateWorkerClaim,\n} from \"./worker-claim.ts\";\n\nexport {\n\tbuildVerifierSystemPrompt,\n\tbuildWorkerSystemPrompt,\n\tWORKER_LANE_SYSTEM_PROMPT,\n\tWORKER_OPERATOR_LANE_SYSTEM_PROMPT,\n\tWORKER_WRITE_LANE_SYSTEM_PROMPT,\n};\n\n/**\n * Pure execution for one bounded specialist delegation: bounded isolated completion ->\n * parse -> untrusted `WorkerClaim` -> parent validation via {@link validateWorkerClaim}.\n *\n * The injected completion may be a bounded child tool loop. Its tool surface is built and gated by\n * the host; this module keeps the structured-output contract and treats every claim as untrusted\n * until parent validation succeeds.\n */\n\nexport interface WorkerCompletion {\n\ttext: string;\n\tcostUsd: number;\n\tstopReason: string;\n\t/** Files successfully changed by the child tool loop before it produced the final JSON. */\n\tchangedFiles?: readonly string[];\n\t/** Capability refusals or execution failures observed inside the child tool loop. */\n\tblockers?: readonly string[];\n}\n\nexport interface WorkerRunnerOptions {\n\trequest: WorkerRequest;\n\t/** Budget for this delegation; undefined disables this bound, while zero permits only free work. */\n\tmaxUsd?: number;\n\t/** Wall-clock budget in milliseconds; 0 disables. */\n\tmaxWallClockMs: number;\n\t/**\n\t * Pre-allocated spawned-usage report id. Always stamped on the claim so parent validation can\n\t * enforce the cost-visibility invariant (a completed claim without a usage report is blocked).\n\t */\n\tusageReportId: string;\n\tcomplete: (args: { systemPrompt: string; userPrompt: string; signal: AbortSignal }) => Promise<WorkerCompletion>;\n\t/** Live successful child-tool mutations, including writes completed before timeout/cancellation. */\n\tgetChangedFiles?: () => readonly string[];\n\tsignal?: AbortSignal;\n\tnow?: () => string;\n\t/** Enables the WRITE lane: only honored when the request envelope grants \"filesystem.write\". The\n\t * runner applies the worker's structured actions through the envelope path scope; refusals\n\t * and failures become blockers, never silent drops. */\n\tapplyActions?: (actions: readonly WorkerAction[]) => AppliedActionsReport;\n\t/** Enables the constrained direct-argv operator role prompt. */\n\tprocessCapable?: boolean;\n\t/** Enables recursive delegation and orchestration-tree coordination guidance. */\n\tdelegationCapable?: boolean;\n\t/** Session cwd — the baseline for relative changed-file and envelope paths in parent\n\t * validation. Defaults to process.cwd(). */\n\tcwd?: string;\n\t/** Turns the child into a read-only semantic verifier for this exact durable task. */\n\tverificationSubjectTaskId?: string;\n}\n\nexport interface WorkerRunOutcome {\n\tclaim: WorkerClaim;\n\t/** Parent-review verdict from {@link validateWorkerClaim}; worker output stays untrusted. */\n\tacceptance: GateOutcome;\n\taccepted: boolean;\n\tlaneStatus: LaneTerminalStatus;\n\treasonCode: string;\n\t/** Underlying executor error for bounded failures; drives the in-process retry decision. */\n\treasonDetail?: string;\n\tcostUsd: number;\n}\n\nexport function buildWorkerUserPrompt(request: WorkerRequest): string {\n\treturn [\n\t\t\"TASK\",\n\t\trequest.instructions,\n\t\t\"END TASK\",\n\t\t'Do not replace the worker claim envelope; put requested detail inside \"summary\" and \"findings\".',\n\t].join(\"\\n\");\n}\n\nexport interface ParsedWorkerOutput {\n\tsummary: string;\n\tstatus: \"completed\" | \"blocked\";\n\tblockers: string[];\n\tfindings: EvidenceFindingDraft[];\n\tactions: WorkerAction[];\n\t/** Present when the model emitted an action list that cannot safely reach execution. */\n\tactionRejection?: RejectedWorkerActions;\n\tverdict?: \"accepted\" | \"rejected\";\n\treasonCodes: string[];\n}\n\nconst MAX_WORKER_OUTPUT_CHARS = 512 * 1024;\nconst MAX_WORKER_JSON_CANDIDATES = 64;\nconst MAX_WORKER_JSON_DEPTH = 256;\nconst MAX_WORKER_FINDINGS = 64;\nconst MAX_WORKER_FINDING_CHARS = 2_000;\nconst MAX_WORKER_REASON_CODES = 32;\nconst MAX_WORKER_REASON_CODE_CHARS = 128;\n\nfunction balancedObjectCandidates(text: string): string[] {\n\tconst ranges: Array<{ start: number; end: number }> = [];\n\tconst starts: number[] = [];\n\tlet inString = false;\n\tlet escaped = false;\n\tfor (let index = 0; index < text.length; index++) {\n\t\tconst character = text[index];\n\t\tif (inString) {\n\t\t\tif (escaped) escaped = false;\n\t\t\telse if (character === \"\\\\\") escaped = true;\n\t\t\telse if (character === '\"') inString = false;\n\t\t\tcontinue;\n\t\t}\n\t\tif (character === '\"') {\n\t\t\tinString = true;\n\t\t\tcontinue;\n\t\t}\n\t\tif (character === \"{\") {\n\t\t\tif (starts.length >= MAX_WORKER_JSON_DEPTH) return ranges.map(({ start, end }) => text.slice(start, end));\n\t\t\tstarts.push(index);\n\t\t\tcontinue;\n\t\t}\n\t\tif (character !== \"}\") continue;\n\t\tconst start = starts.pop();\n\t\tif (start === undefined || ranges.length >= MAX_WORKER_JSON_CANDIDATES) continue;\n\t\tconst end = index + 1;\n\t\tif (end - start <= MAX_WORKER_OUTPUT_CHARS) ranges.push({ start, end });\n\t}\n\treturn ranges.map(({ start, end }) => text.slice(start, end));\n}\n\nfunction workerOutputRecords(text: string): Record<string, unknown>[] {\n\tconst trimmed = text.trim();\n\tif (trimmed.length === 0 || trimmed.length > MAX_WORKER_OUTPUT_CHARS) return [];\n\tconst candidates: string[] = [trimmed];\n\tconst fenced = /```(?:json)?\\s*([\\s\\S]*?)```/.exec(trimmed);\n\tif (fenced?.[1]) candidates.push(fenced[1].trim());\n\tcandidates.push(...balancedObjectCandidates(trimmed));\n\tconst records: Record<string, unknown>[] = [];\n\tfor (const candidate of candidates) {\n\t\ttry {\n\t\t\tconst parsed: unknown = JSON.parse(candidate);\n\t\t\tif (parsed && typeof parsed === \"object\" && !Array.isArray(parsed))\n\t\t\t\trecords.push(parsed as Record<string, unknown>);\n\t\t} catch {\n\t\t\t// Candidate extraction is deliberately best-effort; a later balanced candidate may still be valid.\n\t\t}\n\t}\n\treturn records;\n}\n\nfunction isWorkerStatus(value: unknown): value is ParsedWorkerOutput[\"status\"] {\n\treturn value === \"completed\" || value === \"blocked\";\n}\n\n/**\n * Plain-text fallback is for output that never attempted the worker claim envelope. A JSON object\n * with a claim summary but malformed typed fields is a contract failure, never an implicit success.\n */\nfunction hasMalformedWorkerClaimEnvelope(text: string): boolean {\n\treturn workerOutputRecords(text).some((record) => {\n\t\tif (typeof record.summary !== \"string\" || record.summary.trim().length === 0) return false;\n\t\tif (!isWorkerStatus(record.status)) return true;\n\t\tif (record.verdict !== undefined && record.verdict !== \"accepted\" && record.verdict !== \"rejected\") return true;\n\t\treturn (\n\t\t\trecord.reasonCodes !== undefined &&\n\t\t\t(!Array.isArray(record.reasonCodes) ||\n\t\t\t\trecord.reasonCodes.some((reasonCode) => typeof reasonCode !== \"string\" || reasonCode.trim().length === 0))\n\t\t);\n\t});\n}\n\nexport function parseWorkerOutput(text: string): ParsedWorkerOutput | undefined {\n\tfor (const record of workerOutputRecords(text)) {\n\t\tconst summary = record.summary;\n\t\tif (typeof summary !== \"string\" || summary.trim().length === 0) continue;\n\t\tif (!isWorkerStatus(record.status)) continue;\n\t\tif (record.verdict !== undefined && record.verdict !== \"accepted\" && record.verdict !== \"rejected\") continue;\n\t\tif (\n\t\t\trecord.reasonCodes !== undefined &&\n\t\t\t(!Array.isArray(record.reasonCodes) ||\n\t\t\t\trecord.reasonCodes.some((reasonCode) => typeof reasonCode !== \"string\" || reasonCode.trim().length === 0))\n\t\t) {\n\t\t\tcontinue;\n\t\t}\n\n\t\tconst status = record.status;\n\t\tconst blockers = Array.isArray(record.blockers)\n\t\t\t? record.blockers\n\t\t\t\t\t.filter((blocker): blocker is string => typeof blocker === \"string\" && blocker.trim().length > 0)\n\t\t\t\t\t.slice(0, MAX_WORKER_CLAIM_BLOCKERS)\n\t\t\t\t\t.map((blocker) => blocker.trim().slice(0, MAX_WORKER_CLAIM_BLOCKER_CHARS))\n\t\t\t: [];\n\t\tconst findings: EvidenceFindingDraft[] = [];\n\t\tif (Array.isArray(record.findings)) {\n\t\t\tfor (let index = 0; index < record.findings.length && index < MAX_WORKER_FINDINGS; index++) {\n\t\t\t\tconst finding = normalizeEvidenceFinding(record.findings[index], MAX_WORKER_FINDING_CHARS);\n\t\t\t\tif (finding) findings.push(finding);\n\t\t\t}\n\t\t}\n\t\tconst verdict = record.verdict === \"accepted\" || record.verdict === \"rejected\" ? record.verdict : undefined;\n\t\tconst reasonCodes = Array.isArray(record.reasonCodes)\n\t\t\t? record.reasonCodes\n\t\t\t\t\t.filter(\n\t\t\t\t\t\t(reasonCode): reasonCode is string => typeof reasonCode === \"string\" && reasonCode.trim().length > 0,\n\t\t\t\t\t)\n\t\t\t\t\t.slice(0, MAX_WORKER_REASON_CODES)\n\t\t\t\t\t.map((reasonCode) => reasonCode.trim().slice(0, MAX_WORKER_REASON_CODE_CHARS))\n\t\t\t: [];\n\t\tconst actionOutcome = parseWorkerActions(record.actions);\n\t\treturn {\n\t\t\tsummary: summary.trim().slice(0, MAX_WORKER_CLAIM_SUMMARY_CHARS),\n\t\t\tstatus,\n\t\t\tblockers,\n\t\t\tfindings,\n\t\t\tactions: actionOutcome.kind === \"accepted\" ? actionOutcome.actions : [],\n\t\t\t...(actionOutcome.kind === \"rejected\" ? { actionRejection: actionOutcome } : {}),\n\t\t\t...(verdict ? { verdict } : {}),\n\t\t\treasonCodes,\n\t\t};\n\t}\n\treturn undefined;\n}\n\nfunction buildWorkerEvidence(request: WorkerRequest, findings: ParsedWorkerOutput[\"findings\"]) {\n\tif (findings.length === 0) return undefined;\n\tconst instructionsRef: EvidenceRef = {\n\t\tid: \"src-instructions\",\n\t\tkind: \"user\",\n\t\ttitle: \"Delegated task instructions\",\n\t\ttrusted: true,\n\t\texcerpt: request.instructions.slice(0, 2000),\n\t};\n\tconst synthesisRef: EvidenceRef = {\n\t\tid: \"src-worker\",\n\t\tkind: \"tool\",\n\t\ttitle: \"Delegated worker synthesis\",\n\t\ttrusted: false,\n\t};\n\treturn createEvidenceBundle({\n\t\tquery: `worker:${request.id}`,\n\t\tsources: [instructionsRef, synthesisRef],\n\t\tfindings: projectEvidenceFindings(findings, synthesisRef.id),\n\t});\n}\n\nfunction finishOutcome(args: {\n\trequest: WorkerRequest;\n\tclaim: WorkerClaim;\n\tlaneStatus: LaneTerminalStatus;\n\treasonCode: string;\n\treasonDetail?: string;\n\tcostUsd: number;\n\tcwd?: string;\n}): WorkerRunOutcome {\n\tconst claim = normalizeWorkerClaimForHost(args.claim);\n\tconst acceptance = validateWorkerClaim({ request: args.request, claim, cwd: args.cwd });\n\treturn {\n\t\tclaim,\n\t\tacceptance,\n\t\taccepted: acceptance.outcome === \"allow\",\n\t\tlaneStatus: args.laneStatus,\n\t\treasonCode: args.reasonCode,\n\t\t...(args.reasonDetail ? { reasonDetail: args.reasonDetail } : {}),\n\t\tcostUsd: args.costUsd,\n\t};\n}\n\nexport async function runWorker(options: WorkerRunnerOptions): Promise<WorkerRunOutcome> {\n\tconst now = options.now ?? (() => new Date().toISOString());\n\tconst baseClaim = {\n\t\trequestId: options.request.id,\n\t\tchangedFiles: [] as string[],\n\t\tusageReportId: options.usageReportId,\n\t\tcreatedAt: now(),\n\t};\n\n\t// The write prompt requires BOTH the envelope grant and a caller-supplied applier.\n\tconst writeCapable =\n\t\toptions.request.envelope.capabilities.includes(\"filesystem.write\") && options.applyActions !== undefined;\n\n\tconst bounded = await runBoundedCompletion({\n\t\tmaxWallClockMs: options.maxWallClockMs,\n\t\tsignal: options.signal,\n\t\texecute: (signal) =>\n\t\t\toptions.complete({\n\t\t\t\tsystemPrompt: options.verificationSubjectTaskId\n\t\t\t\t\t? buildVerifierSystemPrompt(options.verificationSubjectTaskId, {\n\t\t\t\t\t\t\tdelegate: options.delegationCapable === true,\n\t\t\t\t\t\t})\n\t\t\t\t\t: buildWorkerSystemPrompt({\n\t\t\t\t\t\t\twrite: writeCapable,\n\t\t\t\t\t\t\tprocess: options.processCapable === true,\n\t\t\t\t\t\t\tdelegate: options.delegationCapable === true,\n\t\t\t\t\t\t}),\n\t\t\t\tuserPrompt: buildWorkerUserPrompt(options.request),\n\t\t\t\tsignal,\n\t\t\t}),\n\t});\n\tconst costUsd = bounded.completion?.costUsd ?? 0;\n\tconst liveChangedFilesReport = collectBoundedWorkerClaimChangedFiles(options.getChangedFiles?.() ?? []);\n\tconst liveChangedFiles = liveChangedFilesReport.values;\n\n\tif (bounded.failure) {\n\t\tconst cancelled = bounded.failure.status === \"canceled\" || bounded.failure.status === \"timeout\";\n\t\tconst blockers = liveChangedFilesReport.overflowed\n\t\t\t? [\"worker changed-file report exceeded the durable claim bound; parent review is required\"]\n\t\t\t: undefined;\n\t\treturn finishOutcome({\n\t\t\trequest: options.request,\n\t\t\tcwd: options.cwd,\n\t\t\tclaim: {\n\t\t\t\t...baseClaim,\n\t\t\t\tchangedFiles: liveChangedFiles,\n\t\t\t\tstatus: cancelled ? \"cancelled\" : \"failed\",\n\t\t\t\tsummary: `Worker did not complete: ${bounded.failure.reasonCode}${\n\t\t\t\t\tbounded.failure.detail ? ` — ${bounded.failure.detail}` : \"\"\n\t\t\t\t}`,\n\t\t\t\t...(blockers ? { blockers } : {}),\n\t\t\t},\n\t\t\tlaneStatus: bounded.failure.status,\n\t\t\treasonCode: bounded.failure.reasonCode,\n\t\t\t...(bounded.failure.detail ? { reasonDetail: bounded.failure.detail } : {}),\n\t\t\tcostUsd,\n\t\t});\n\t}\n\n\tconst completion = bounded.completion as WorkerCompletion | undefined;\n\tconst completionChangedFilesReport = collectBoundedWorkerClaimChangedFiles(completion?.changedFiles ?? []);\n\tconst mergedChangedFilesReport = collectBoundedWorkerClaimChangedFiles([\n\t\t...liveChangedFiles,\n\t\t...completionChangedFilesReport.values,\n\t]);\n\tconst changedFilesOverflowed =\n\t\tliveChangedFilesReport.overflowed ||\n\t\tcompletionChangedFilesReport.overflowed ||\n\t\tmergedChangedFilesReport.overflowed;\n\tconst completionChangedFiles = mergedChangedFilesReport.values;\n\tconst completionBaseClaim = { ...baseClaim, changedFiles: completionChangedFiles };\n\tif (!completion || completion.stopReason === \"error\" || completion.stopReason === \"aborted\") {\n\t\treturn finishOutcome({\n\t\t\trequest: options.request,\n\t\t\tcwd: options.cwd,\n\t\t\tclaim: { ...completionBaseClaim, status: \"failed\", summary: \"Worker model call failed.\" },\n\t\t\tlaneStatus: \"failed\",\n\t\t\treasonCode: \"model_error\",\n\t\t\tcostUsd,\n\t\t});\n\t}\n\n\tconst parsed = parseWorkerOutput(completion.text);\n\tif (!parsed) {\n\t\tif (hasMalformedWorkerClaimEnvelope(completion.text)) {\n\t\t\treturn finishOutcome({\n\t\t\t\trequest: options.request,\n\t\t\t\tcwd: options.cwd,\n\t\t\t\tclaim: {\n\t\t\t\t\t...completionBaseClaim,\n\t\t\t\t\tstatus: \"failed\",\n\t\t\t\t\tsummary: \"Worker output used a malformed structured claim envelope.\",\n\t\t\t\t},\n\t\t\t\tlaneStatus: \"failed\",\n\t\t\t\treasonCode: \"unparseable_output\",\n\t\t\t\tcostUsd,\n\t\t\t});\n\t\t}\n\t\tconst readOnlyPlainText =\n\t\t\t!options.verificationSubjectTaskId &&\n\t\t\t!writeCapable &&\n\t\t\tcompletion.text.trim().length > 0 &&\n\t\t\tcompletionChangedFiles.length === 0 &&\n\t\t\t!changedFilesOverflowed;\n\t\tif (readOnlyPlainText) {\n\t\t\tconst completionBlockersReport = collectBoundedWorkerClaimBlockers(completion.blockers ?? []);\n\t\t\tconst completionBlockers = completionBlockersReport.overflowed\n\t\t\t\t? [\n\t\t\t\t\t\t...completionBlockersReport.values.slice(0, Math.max(0, MAX_WORKER_CLAIM_BLOCKERS - 1)),\n\t\t\t\t\t\t\"worker blocker report exceeded the durable claim bound; parent review is required\",\n\t\t\t\t\t]\n\t\t\t\t: completionBlockersReport.values;\n\t\t\tconst incompleteNote =\n\t\t\t\tcompletion.stopReason === \"stop\"\n\t\t\t\t\t? \"\"\n\t\t\t\t\t: `\\n\\n[Worker output ended with stop reason '${completion.stopReason}'; verify completeness.]`;\n\t\t\tconst summary = `${completion.text.trim().slice(0, Math.max(0, MAX_WORKER_CLAIM_SUMMARY_CHARS - incompleteNote.length))}${incompleteNote}`;\n\t\t\tconst blocked = completionBlockers.length > 0;\n\t\t\treturn finishOutcome({\n\t\t\t\trequest: options.request,\n\t\t\t\tcwd: options.cwd,\n\t\t\t\tclaim: {\n\t\t\t\t\t...completionBaseClaim,\n\t\t\t\t\tstatus: blocked ? \"blocked\" : \"completed\",\n\t\t\t\t\toutputFormat: \"plain_text\",\n\t\t\t\t\tsummary,\n\t\t\t\t\t...(blocked ? { blockers: completionBlockers } : {}),\n\t\t\t\t},\n\t\t\t\tlaneStatus: blocked ? \"blocked\" : \"succeeded\",\n\t\t\t\treasonCode: blocked\n\t\t\t\t\t? \"worker_blocked\"\n\t\t\t\t\t: completion.stopReason === \"stop\"\n\t\t\t\t\t\t? \"worker_completed_plain_text\"\n\t\t\t\t\t\t: \"worker_completed_plain_text_incomplete\",\n\t\t\t\tcostUsd,\n\t\t\t});\n\t\t}\n\t\treturn finishOutcome({\n\t\t\trequest: options.request,\n\t\t\tcwd: options.cwd,\n\t\t\tclaim: {\n\t\t\t\t...completionBaseClaim,\n\t\t\t\tstatus: \"failed\",\n\t\t\t\tsummary: \"Worker output was not valid structured JSON.\",\n\t\t\t\t...(changedFilesOverflowed\n\t\t\t\t\t? {\n\t\t\t\t\t\t\tblockers: [\n\t\t\t\t\t\t\t\t\"worker changed-file report exceeded the durable claim bound; parent review is required\",\n\t\t\t\t\t\t\t],\n\t\t\t\t\t\t}\n\t\t\t\t\t: {}),\n\t\t\t},\n\t\t\tlaneStatus: \"failed\",\n\t\t\treasonCode: \"unparseable_output\",\n\t\t\tcostUsd,\n\t\t});\n\t}\n\n\tconst evidence = buildWorkerEvidence(options.request, parsed.findings);\n\tif (parsed.actionRejection) {\n\t\treturn finishOutcome({\n\t\t\trequest: options.request,\n\t\t\tcwd: options.cwd,\n\t\t\tclaim: {\n\t\t\t\t...completionBaseClaim,\n\t\t\t\tstatus: \"failed\",\n\t\t\t\tsummary: \"Worker output contained invalid structured actions.\",\n\t\t\t\tblockers: [parsed.actionRejection.reasonCode],\n\t\t\t},\n\t\t\tlaneStatus: \"failed\",\n\t\t\treasonCode: \"unparseable_output\",\n\t\t\tcostUsd,\n\t\t});\n\t}\n\tif (options.verificationSubjectTaskId && (!parsed.verdict || parsed.reasonCodes.length === 0)) {\n\t\treturn finishOutcome({\n\t\t\trequest: options.request,\n\t\t\tcwd: options.cwd,\n\t\t\tclaim: {\n\t\t\t\t...completionBaseClaim,\n\t\t\t\tstatus: \"failed\",\n\t\t\t\tsummary: \"Verifier output omitted its typed verdict or reasonCodes.\",\n\t\t\t},\n\t\t\tlaneStatus: \"failed\",\n\t\t\treasonCode: \"invalid_verifier_result\",\n\t\t\tcostUsd,\n\t\t});\n\t}\n\tlet changedFiles: string[] = [...completionChangedFiles];\n\tconst completionBlockersReport = collectBoundedWorkerClaimBlockers(completion.blockers ?? []);\n\tconst actionBlockers: string[] = [...completionBlockersReport.values];\n\tif (changedFilesOverflowed) {\n\t\tactionBlockers.push(\"worker changed-file report exceeded the durable claim bound; parent review is required\");\n\t}\n\tif (completionBlockersReport.overflowed) {\n\t\tactionBlockers.push(\"worker blocker report exceeded the durable claim bound; parent review is required\");\n\t}\n\tif (!writeCapable && completionChangedFiles.length > 0) {\n\t\tactionBlockers.push(\"worker reported file changes without a filesystem.write envelope grant\");\n\t}\n\tif (writeCapable && parsed.status !== \"blocked\" && parsed.actions.length > 0 && options.applyActions) {\n\t\t// Runner-side application through the envelope path scope: refusals and failures are\n\t\t// surfaced as blockers so a partially-applied change can never look like clean success.\n\t\tconst applied = options.applyActions(parsed.actions);\n\t\tconst appliedChangedFilesReport = collectBoundedWorkerClaimChangedFiles(applied.changedFiles);\n\t\tconst mergedAppliedChangedFilesReport = collectBoundedWorkerClaimChangedFiles([\n\t\t\t...changedFiles,\n\t\t\t...appliedChangedFilesReport.values,\n\t\t]);\n\t\tchangedFiles = mergedAppliedChangedFilesReport.values;\n\t\tif (appliedChangedFilesReport.overflowed || mergedAppliedChangedFilesReport.overflowed) {\n\t\t\tactionBlockers.push(\"applied changed-file report exceeded the durable claim bound; parent review is required\");\n\t\t}\n\t\tfor (const refusal of applied.refused) {\n\t\t\tactionBlockers.push(`action refused (${refusal.path}): ${refusal.reason}`);\n\t\t}\n\t\tfor (const failure of applied.failed) {\n\t\t\tactionBlockers.push(`action failed (${failure.path}): ${failure.reason}`);\n\t\t}\n\t\tfor (const inspection of applied.inspectionRequired) {\n\t\t\tactionBlockers.push(\n\t\t\t\t`action requires workspace/evidence inspection (${inspection.path}, ${inspection.state}): ${inspection.reasonCode}`,\n\t\t\t);\n\t\t}\n\t} else if (!writeCapable && parsed.actions.length > 0) {\n\t\tactionBlockers.push(\"worker emitted file actions without a filesystem.write envelope grant; nothing was applied\");\n\t}\n\tconst allBlockersReport = collectBoundedWorkerClaimBlockers([...parsed.blockers, ...actionBlockers]);\n\tconst allBlockers = allBlockersReport.overflowed\n\t\t? [\n\t\t\t\t...allBlockersReport.values.slice(0, Math.max(0, MAX_WORKER_CLAIM_BLOCKERS - 1)),\n\t\t\t\t\"worker blocker report exceeded the durable claim bound; parent review is required\",\n\t\t\t]\n\t\t: allBlockersReport.values;\n\tconst claim: WorkerClaim = {\n\t\t...baseClaim,\n\t\tchangedFiles,\n\t\tstatus: parsed.status === \"blocked\" || allBlockers.length > 0 ? \"blocked\" : \"completed\",\n\t\tsummary: parsed.summary,\n\t\t...(allBlockers.length > 0 ? { blockers: allBlockers } : {}),\n\t\t...(evidence ? { evidence } : {}),\n\t\t...(options.verificationSubjectTaskId && parsed.verdict\n\t\t\t? {\n\t\t\t\t\tverification: {\n\t\t\t\t\t\tsubjectTaskId: options.verificationSubjectTaskId,\n\t\t\t\t\t\tverdict: parsed.verdict,\n\t\t\t\t\t\treasonCodes: parsed.reasonCodes,\n\t\t\t\t\t},\n\t\t\t\t}\n\t\t\t: {}),\n\t};\n\n\tif (claim.status === \"blocked\") {\n\t\treturn finishOutcome({\n\t\t\trequest: options.request,\n\t\t\tcwd: options.cwd,\n\t\t\tclaim,\n\t\t\tlaneStatus: \"blocked\",\n\t\t\treasonCode: \"worker_blocked\",\n\t\t\tcostUsd,\n\t\t});\n\t}\n\n\tconst overBudget = options.maxUsd !== undefined && costUsd > options.maxUsd;\n\treturn finishOutcome({\n\t\trequest: options.request,\n\t\tcwd: options.cwd,\n\t\tclaim,\n\t\tlaneStatus: overBudget ? \"budget_exhausted\" : \"succeeded\",\n\t\treasonCode: overBudget\n\t\t\t? \"cost_budget_exceeded\"\n\t\t\t: claim.verification\n\t\t\t\t? claim.verification.verdict === \"accepted\"\n\t\t\t\t\t? \"verification_accepted\"\n\t\t\t\t\t: \"verification_rejected\"\n\t\t\t\t: \"worker_completed\",\n\t\tcostUsd,\n\t});\n}\n"]}
|
|
1
|
+
{"version":3,"file":"worker-runner.js","sourceRoot":"","sources":["../../../src/core/delegation/worker-runner.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,oBAAoB,EAAE,MAAM,mCAAmC,CAAC;AAEzE,OAAO,EAEN,wBAAwB,EACxB,uBAAuB,GACvB,MAAM,4CAA4C,CAAC;AAGpD,OAAO,EACN,yBAAyB,EACzB,uBAAuB,EACvB,yBAAyB,EACzB,kCAAkC,EAClC,+BAA+B,GAC/B,MAAM,iCAAiC,CAAC;AACzC,OAAO,EAAE,oBAAoB,EAAE,MAAM,gCAAgC,CAAC;AACtE,OAAO,EAEN,kBAAkB,GAGlB,MAAM,qBAAqB,CAAC;AAC7B,OAAO,EACN,iCAAiC,EACjC,qCAAqC,EACrC,8BAA8B,EAC9B,yBAAyB,EACzB,8BAA8B,EAC9B,2BAA2B,EAC3B,mBAAmB,GACnB,MAAM,mBAAmB,CAAC;AAE3B,OAAO,EACN,yBAAyB,EACzB,uBAAuB,EACvB,yBAAyB,EACzB,kCAAkC,EAClC,+BAA+B,GAC/B,CAAC;AAsEF,MAAM,UAAU,qBAAqB,CAAC,OAAsB;IAC3D,OAAO;QACN,MAAM;QACN,OAAO,CAAC,YAAY;QACpB,UAAU;QACV,iGAAiG;KACjG,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;AACd,CAAC;AAcD,MAAM,uBAAuB,GAAG,GAAG,GAAG,IAAI,CAAC;AAC3C,MAAM,0BAA0B,GAAG,EAAE,CAAC;AACtC,MAAM,qBAAqB,GAAG,GAAG,CAAC;AAClC,MAAM,mBAAmB,GAAG,EAAE,CAAC;AAC/B,MAAM,wBAAwB,GAAG,KAAK,CAAC;AACvC,MAAM,uBAAuB,GAAG,EAAE,CAAC;AACnC,MAAM,4BAA4B,GAAG,GAAG,CAAC;AAEzC,SAAS,wBAAw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O;QACxB,GAAG,EAAE,OAAO,CAAC,GAAG;QAChB,KAAK,EAAE,UAAU;QACjB,UAAU,EAAE,UAAU,CAAC,CAAC,CAAC,kBAAkB,CAAC,CAAC,CAAC,WAAW;QACzD,UAAU,EAAE,UAAU;YACrB,CAAC,CAAC,sBAAsB;YACxB,CAAC,CAAC,KAAK,CAAC,YAAY;gBACnB,CAAC,CAAC,KAAK,CAAC,YAAY,CAAC,OAAO,KAAK,UAAU;oBAC1C,CAAC,CAAC,uBAAuB;oBACzB,CAAC,CAAC,uBAAuB;gBAC1B,CAAC,CAAC,kBAAkB;QACtB,OAAO;KACP,CAAC,CAAC;AACJ,CAAC","sourcesContent":["import { runBoundedCompletion } from \"../autonomy/bounded-completion.ts\";\nimport type { EvidenceRef, GateOutcome, WorkerClaim, WorkerRequest } from \"../autonomy/contracts.ts\";\nimport {\n\ttype EvidenceFindingDraft,\n\tnormalizeEvidenceFinding,\n\tprojectEvidenceFindings,\n} from \"../autonomy/evidence-finding-projection.ts\";\nimport type { LaneTerminalStatus } from \"../autonomy/lane-tracker.ts\";\nimport type { WorkerRole } from \"../orchestration/contracts.ts\";\nimport {\n\tbuildVerifierSystemPrompt,\n\tbuildWorkerSystemPrompt,\n\tWORKER_LANE_SYSTEM_PROMPT,\n\tWORKER_OPERATOR_LANE_SYSTEM_PROMPT,\n\tWORKER_WRITE_LANE_SYSTEM_PROMPT,\n} from \"../provider-prompt-contracts.ts\";\nimport { createEvidenceBundle } from \"../research/evidence-bundle.ts\";\nimport {\n\ttype AppliedActionsReport,\n\tparseWorkerActions,\n\ttype RejectedWorkerActions,\n\ttype WorkerAction,\n} from \"./worker-actions.ts\";\nimport {\n\tcollectBoundedWorkerClaimBlockers,\n\tcollectBoundedWorkerClaimChangedFiles,\n\tMAX_WORKER_CLAIM_BLOCKER_CHARS,\n\tMAX_WORKER_CLAIM_BLOCKERS,\n\tMAX_WORKER_CLAIM_SUMMARY_CHARS,\n\tnormalizeWorkerClaimForHost,\n\tvalidateWorkerClaim,\n} from \"./worker-claim.ts\";\n\nexport {\n\tbuildVerifierSystemPrompt,\n\tbuildWorkerSystemPrompt,\n\tWORKER_LANE_SYSTEM_PROMPT,\n\tWORKER_OPERATOR_LANE_SYSTEM_PROMPT,\n\tWORKER_WRITE_LANE_SYSTEM_PROMPT,\n};\n\n/**\n * Pure execution for one bounded specialist delegation: bounded isolated completion ->\n * parse -> untrusted `WorkerClaim` -> parent validation via {@link validateWorkerClaim}.\n *\n * The injected completion may be a bounded child tool loop. Its tool surface is built and gated by\n * the host; this module keeps the structured-output contract and treats every claim as untrusted\n * until parent validation succeeds.\n */\n\nexport interface WorkerCompletion {\n\ttext: string;\n\tcostUsd: number;\n\tstopReason: string;\n\t/** Files successfully changed by the child tool loop before it produced the final JSON. */\n\tchangedFiles?: readonly string[];\n\t/** Capability refusals or execution failures observed inside the child tool loop. */\n\tblockers?: readonly string[];\n}\n\nexport interface WorkerRunnerOptions {\n\trequest: WorkerRequest;\n\t/** Budget for this delegation; undefined disables this bound, while zero permits only free work. */\n\tmaxUsd?: number;\n\t/** Wall-clock budget in milliseconds; 0 disables. */\n\tmaxWallClockMs: number;\n\t/**\n\t * Pre-allocated spawned-usage report id. Always stamped on the claim so parent validation can\n\t * enforce the cost-visibility invariant (a completed claim without a usage report is blocked).\n\t */\n\tusageReportId: string;\n\tcomplete: (args: { systemPrompt: string; userPrompt: string; signal: AbortSignal }) => Promise<WorkerCompletion>;\n\t/** Live successful child-tool mutations, including writes completed before timeout/cancellation. */\n\tgetChangedFiles?: () => readonly string[];\n\tsignal?: AbortSignal;\n\tnow?: () => string;\n\t/** Enables the WRITE lane: only honored when the request envelope grants \"filesystem.write\". The\n\t * runner applies the worker's structured actions through the envelope path scope; refusals\n\t * and failures become blockers, never silent drops. */\n\tapplyActions?: (actions: readonly WorkerAction[]) => AppliedActionsReport;\n\t/** Enables the constrained direct-argv operator role prompt. */\n\tprocessCapable?: boolean;\n\t/** Enables recursive delegation and orchestration-tree coordination guidance. */\n\tdelegationCapable?: boolean;\n\t/** Session cwd — the baseline for relative changed-file and envelope paths in parent\n\t * validation. Defaults to process.cwd(). */\n\tcwd?: string;\n\t/** Turns the child into a read-only semantic verifier for this exact durable task. */\n\tverificationSubjectTaskId?: string;\n}\n\nexport interface WorkerRunOutcome {\n\tclaim: WorkerClaim;\n\t/** Parent-review verdict from {@link validateWorkerClaim}; worker output stays untrusted. */\n\tacceptance: GateOutcome;\n\taccepted: boolean;\n\tlaneStatus: LaneTerminalStatus;\n\treasonCode: string;\n\t/** Underlying executor error for bounded failures; drives the in-process retry decision. */\n\treasonDetail?: string;\n\tcostUsd: number;\n\t/**\n\t * Set by the caller (worker-delegation-controller.ts admission), never by runWorker itself, when\n\t * a pin policy is active, the effective role has no pin, and the caller requested an explicit\n\t * model — i.e. the owner's model pin was evaded, not merely inapplicable. Diagnostics only.\n\t */\n\tmodelPinBypass?: WorkerRole;\n}\n\nexport function buildWorkerUserPrompt(request: WorkerRequest): string {\n\treturn [\n\t\t\"TASK\",\n\t\trequest.instructions,\n\t\t\"END TASK\",\n\t\t'Do not replace the worker claim envelope; put requested detail inside \"summary\" and \"findings\".',\n\t].join(\"\\n\");\n}\n\nexport interface ParsedWorkerOutput {\n\tsummary: string;\n\tstatus: \"completed\" | \"blocked\";\n\tblockers: string[];\n\tfindings: EvidenceFindingDraft[];\n\tactions: WorkerAction[];\n\t/** Present when the model emitted an action list that cannot safely reach execution. */\n\tactionRejection?: RejectedWorkerActions;\n\tverdict?: \"accepted\" | \"rejected\";\n\treasonCodes: string[];\n}\n\nconst MAX_WORKER_OUTPUT_CHARS = 512 * 1024;\nconst MAX_WORKER_JSON_CANDIDATES = 64;\nconst MAX_WORKER_JSON_DEPTH = 256;\nconst MAX_WORKER_FINDINGS = 64;\nconst MAX_WORKER_FINDING_CHARS = 2_000;\nconst MAX_WORKER_REASON_CODES = 32;\nconst MAX_WORKER_REASON_CODE_CHARS = 128;\n\nfunction balancedObjectCandidates(text: string): string[] {\n\tconst ranges: Array<{ start: number; end: number }> = [];\n\tconst starts: number[] = [];\n\tlet inString = false;\n\tlet escaped = false;\n\tfor (let index = 0; index < text.length; index++) {\n\t\tconst character = text[index];\n\t\tif (inString) {\n\t\t\tif (escaped) escaped = false;\n\t\t\telse if (character === \"\\\\\") escaped = true;\n\t\t\telse if (character === '\"') inString = false;\n\t\t\tcontinue;\n\t\t}\n\t\tif (character === '\"') {\n\t\t\tinString = true;\n\t\t\tcontinue;\n\t\t}\n\t\tif (character === \"{\") {\n\t\t\tif (starts.length >= MAX_WORKER_JSON_DEPTH) return ranges.map(({ start, end }) => text.slice(start, end));\n\t\t\tstarts.push(index);\n\t\t\tcontinue;\n\t\t}\n\t\tif (character !== \"}\") continue;\n\t\tconst start = starts.pop();\n\t\tif (start === undefined || ranges.length >= MAX_WORKER_JSON_CANDIDATES) continue;\n\t\tconst end = index + 1;\n\t\tif (end - start <= MAX_WORKER_OUTPUT_CHARS) ranges.push({ start, end });\n\t}\n\treturn ranges.map(({ start, end }) => text.slice(start, end));\n}\n\nfunction workerOutputRecords(text: string): Record<string, unknown>[] {\n\tconst trimmed = text.trim();\n\tif (trimmed.length === 0 || trimmed.length > MAX_WORKER_OUTPUT_CHARS) return [];\n\tconst candidates: string[] = [trimmed];\n\tconst fenced = /```(?:json)?\\s*([\\s\\S]*?)```/.exec(trimmed);\n\tif (fenced?.[1]) candidates.push(fenced[1].trim());\n\tcandidates.push(...balancedObjectCandidates(trimmed));\n\tconst records: Record<string, unknown>[] = [];\n\tfor (const candidate of candidates) {\n\t\ttry {\n\t\t\tconst parsed: unknown = JSON.parse(candidate);\n\t\t\tif (parsed && typeof parsed === \"object\" && !Array.isArray(parsed))\n\t\t\t\trecords.push(parsed as Record<string, unknown>);\n\t\t} catch {\n\t\t\t// Candidate extraction is deliberately best-effort; a later balanced candidate may still be valid.\n\t\t}\n\t}\n\treturn records;\n}\n\nfunction isWorkerStatus(value: unknown): value is ParsedWorkerOutput[\"status\"] {\n\treturn value === \"completed\" || value === \"blocked\";\n}\n\n/**\n * Plain-text fallback is for output that never attempted the worker claim envelope. A JSON object\n * with a claim summary but malformed typed fields is a contract failure, never an implicit success.\n */\nfunction hasMalformedWorkerClaimEnvelope(text: string): boolean {\n\treturn workerOutputRecords(text).some((record) => {\n\t\tif (typeof record.summary !== \"string\" || record.summary.trim().length === 0) return false;\n\t\tif (!isWorkerStatus(record.status)) return true;\n\t\tif (record.verdict !== undefined && record.verdict !== \"accepted\" && record.verdict !== \"rejected\") return true;\n\t\treturn (\n\t\t\trecord.reasonCodes !== undefined &&\n\t\t\t(!Array.isArray(record.reasonCodes) ||\n\t\t\t\trecord.reasonCodes.some((reasonCode) => typeof reasonCode !== \"string\" || reasonCode.trim().length === 0))\n\t\t);\n\t});\n}\n\nexport function parseWorkerOutput(text: string): ParsedWorkerOutput | undefined {\n\tfor (const record of workerOutputRecords(text)) {\n\t\tconst summary = record.summary;\n\t\tif (typeof summary !== \"string\" || summary.trim().length === 0) continue;\n\t\tif (!isWorkerStatus(record.status)) continue;\n\t\tif (record.verdict !== undefined && record.verdict !== \"accepted\" && record.verdict !== \"rejected\") continue;\n\t\tif (\n\t\t\trecord.reasonCodes !== undefined &&\n\t\t\t(!Array.isArray(record.reasonCodes) ||\n\t\t\t\trecord.reasonCodes.some((reasonCode) => typeof reasonCode !== \"string\" || reasonCode.trim().length === 0))\n\t\t) {\n\t\t\tcontinue;\n\t\t}\n\n\t\tconst status = record.status;\n\t\tconst blockers = Array.isArray(record.blockers)\n\t\t\t? record.blockers\n\t\t\t\t\t.filter((blocker): blocker is string => typeof blocker === \"string\" && blocker.trim().length > 0)\n\t\t\t\t\t.slice(0, MAX_WORKER_CLAIM_BLOCKERS)\n\t\t\t\t\t.map((blocker) => blocker.trim().slice(0, MAX_WORKER_CLAIM_BLOCKER_CHARS))\n\t\t\t: [];\n\t\tconst findings: EvidenceFindingDraft[] = [];\n\t\tif (Array.isArray(record.findings)) {\n\t\t\tfor (let index = 0; index < record.findings.length && index < MAX_WORKER_FINDINGS; index++) {\n\t\t\t\tconst finding = normalizeEvidenceFinding(record.findings[index], MAX_WORKER_FINDING_CHARS);\n\t\t\t\tif (finding) findings.push(finding);\n\t\t\t}\n\t\t}\n\t\tconst verdict = record.verdict === \"accepted\" || record.verdict === \"rejected\" ? record.verdict : undefined;\n\t\tconst reasonCodes = Array.isArray(record.reasonCodes)\n\t\t\t? record.reasonCodes\n\t\t\t\t\t.filter(\n\t\t\t\t\t\t(reasonCode): reasonCode is string => typeof reasonCode === \"string\" && reasonCode.trim().length > 0,\n\t\t\t\t\t)\n\t\t\t\t\t.slice(0, MAX_WORKER_REASON_CODES)\n\t\t\t\t\t.map((reasonCode) => reasonCode.trim().slice(0, MAX_WORKER_REASON_CODE_CHARS))\n\t\t\t: [];\n\t\tconst actionOutcome = parseWorkerActions(record.actions);\n\t\treturn {\n\t\t\tsummary: summary.trim().slice(0, MAX_WORKER_CLAIM_SUMMARY_CHARS),\n\t\t\tstatus,\n\t\t\tblockers,\n\t\t\tfindings,\n\t\t\tactions: actionOutcome.kind === \"accepted\" ? actionOutcome.actions : [],\n\t\t\t...(actionOutcome.kind === \"rejected\" ? { actionRejection: actionOutcome } : {}),\n\t\t\t...(verdict ? { verdict } : {}),\n\t\t\treasonCodes,\n\t\t};\n\t}\n\treturn undefined;\n}\n\nfunction buildWorkerEvidence(request: WorkerRequest, findings: ParsedWorkerOutput[\"findings\"]) {\n\tif (findings.length === 0) return undefined;\n\tconst instructionsRef: EvidenceRef = {\n\t\tid: \"src-instructions\",\n\t\tkind: \"user\",\n\t\ttitle: \"Delegated task instructions\",\n\t\ttrusted: true,\n\t\texcerpt: request.instructions.slice(0, 2000),\n\t};\n\tconst synthesisRef: EvidenceRef = {\n\t\tid: \"src-worker\",\n\t\tkind: \"tool\",\n\t\ttitle: \"Delegated worker synthesis\",\n\t\ttrusted: false,\n\t};\n\treturn createEvidenceBundle({\n\t\tquery: `worker:${request.id}`,\n\t\tsources: [instructionsRef, synthesisRef],\n\t\tfindings: projectEvidenceFindings(findings, synthesisRef.id),\n\t});\n}\n\nfunction finishOutcome(args: {\n\trequest: WorkerRequest;\n\tclaim: WorkerClaim;\n\tlaneStatus: LaneTerminalStatus;\n\treasonCode: string;\n\treasonDetail?: string;\n\tcostUsd: number;\n\tcwd?: string;\n}): WorkerRunOutcome {\n\tconst claim = normalizeWorkerClaimForHost(args.claim);\n\tconst acceptance = validateWorkerClaim({ request: args.request, claim, cwd: args.cwd });\n\treturn {\n\t\tclaim,\n\t\tacceptance,\n\t\taccepted: acceptance.outcome === \"allow\",\n\t\tlaneStatus: args.laneStatus,\n\t\treasonCode: args.reasonCode,\n\t\t...(args.reasonDetail ? { reasonDetail: args.reasonDetail } : {}),\n\t\tcostUsd: args.costUsd,\n\t};\n}\n\nexport async function runWorker(options: WorkerRunnerOptions): Promise<WorkerRunOutcome> {\n\tconst now = options.now ?? (() => new Date().toISOString());\n\tconst baseClaim = {\n\t\trequestId: options.request.id,\n\t\tchangedFiles: [] as string[],\n\t\tusageReportId: options.usageReportId,\n\t\tcreatedAt: now(),\n\t};\n\n\t// The write prompt requires BOTH the envelope grant and a caller-supplied applier.\n\tconst writeCapable =\n\t\toptions.request.envelope.capabilities.includes(\"filesystem.write\") && options.applyActions !== undefined;\n\n\tconst bounded = await runBoundedCompletion({\n\t\tmaxWallClockMs: options.maxWallClockMs,\n\t\tsignal: options.signal,\n\t\texecute: (signal) =>\n\t\t\toptions.complete({\n\t\t\t\tsystemPrompt: options.verificationSubjectTaskId\n\t\t\t\t\t? buildVerifierSystemPrompt(options.verificationSubjectTaskId, {\n\t\t\t\t\t\t\tdelegate: options.delegationCapable === true,\n\t\t\t\t\t\t})\n\t\t\t\t\t: buildWorkerSystemPrompt({\n\t\t\t\t\t\t\twrite: writeCapable,\n\t\t\t\t\t\t\tprocess: options.processCapable === true,\n\t\t\t\t\t\t\tdelegate: options.delegationCapable === true,\n\t\t\t\t\t\t}),\n\t\t\t\tuserPrompt: buildWorkerUserPrompt(options.request),\n\t\t\t\tsignal,\n\t\t\t}),\n\t});\n\tconst costUsd = bounded.completion?.costUsd ?? 0;\n\tconst liveChangedFilesReport = collectBoundedWorkerClaimChangedFiles(options.getChangedFiles?.() ?? []);\n\tconst liveChangedFiles = liveChangedFilesReport.values;\n\n\tif (bounded.failure) {\n\t\tconst isBudgetExhausted =\n\t\t\tbounded.failure.status === \"budget_exhausted\" ||\n\t\t\tbounded.failure.reasonCode.includes(\"budget_exhausted\") ||\n\t\t\tbounded.failure.reasonCode.includes(\"cost_budget_exceeded\");\n\t\tconst cancelled = bounded.failure.status === \"canceled\" || bounded.failure.status === \"timeout\";\n\t\tconst blockers = [\n\t\t\t...(liveChangedFilesReport.overflowed\n\t\t\t\t? [\"worker changed-file report exceeded the durable claim bound; parent review is required\"]\n\t\t\t\t: []),\n\t\t\t...(isBudgetExhausted ? [`budget limit reached: ${bounded.failure.reasonCode}`] : []),\n\t\t];\n\t\tconst status = isBudgetExhausted ? \"partial\" : cancelled ? \"cancelled\" : \"failed\";\n\t\tconst summary = isBudgetExhausted\n\t\t\t? `Worker paused at budget limit (${bounded.failure.reasonCode})${\n\t\t\t\t\tbounded.failure.detail ? `: ${bounded.failure.detail}` : \".\"\n\t\t\t\t}`\n\t\t\t: `Worker did not complete: ${bounded.failure.reasonCode}${\n\t\t\t\t\tbounded.failure.detail ? ` — ${bounded.failure.detail}` : \"\"\n\t\t\t\t}`;\n\t\treturn finishOutcome({\n\t\t\trequest: options.request,\n\t\t\tcwd: options.cwd,\n\t\t\tclaim: {\n\t\t\t\t...baseClaim,\n\t\t\t\tchangedFiles: liveChangedFiles,\n\t\t\t\tstatus,\n\t\t\t\tsummary,\n\t\t\t\t...(blockers.length > 0 ? { blockers } : {}),\n\t\t\t},\n\t\t\tlaneStatus: bounded.failure.status,\n\t\t\treasonCode: bounded.failure.reasonCode,\n\t\t\t...(bounded.failure.detail ? { reasonDetail: bounded.failure.detail } : {}),\n\t\t\tcostUsd,\n\t\t});\n\t}\n\n\tconst completion = bounded.completion as WorkerCompletion | undefined;\n\tconst completionChangedFilesReport = collectBoundedWorkerClaimChangedFiles(completion?.changedFiles ?? []);\n\tconst mergedChangedFilesReport = collectBoundedWorkerClaimChangedFiles([\n\t\t...liveChangedFiles,\n\t\t...completionChangedFilesReport.values,\n\t]);\n\tconst changedFilesOverflowed =\n\t\tliveChangedFilesReport.overflowed ||\n\t\tcompletionChangedFilesReport.overflowed ||\n\t\tmergedChangedFilesReport.overflowed;\n\tconst completionChangedFiles = mergedChangedFilesReport.values;\n\tconst completionBaseClaim = { ...baseClaim, changedFiles: completionChangedFiles };\n\tif (!completion || completion.stopReason === \"error\" || completion.stopReason === \"aborted\") {\n\t\treturn finishOutcome({\n\t\t\trequest: options.request,\n\t\t\tcwd: options.cwd,\n\t\t\tclaim: { ...completionBaseClaim, status: \"failed\", summary: \"Worker model call failed.\" },\n\t\t\tlaneStatus: \"failed\",\n\t\t\treasonCode: \"model_error\",\n\t\t\tcostUsd,\n\t\t});\n\t}\n\n\tconst parsed = parseWorkerOutput(completion.text);\n\tif (!parsed) {\n\t\tif (hasMalformedWorkerClaimEnvelope(completion.text)) {\n\t\t\treturn finishOutcome({\n\t\t\t\trequest: options.request,\n\t\t\t\tcwd: options.cwd,\n\t\t\t\tclaim: {\n\t\t\t\t\t...completionBaseClaim,\n\t\t\t\t\tstatus: \"failed\",\n\t\t\t\t\tsummary: \"Worker output used a malformed structured claim envelope.\",\n\t\t\t\t},\n\t\t\t\tlaneStatus: \"failed\",\n\t\t\t\treasonCode: \"unparseable_output\",\n\t\t\t\tcostUsd,\n\t\t\t});\n\t\t}\n\t\tconst readOnlyPlainText =\n\t\t\t!options.verificationSubjectTaskId &&\n\t\t\t!writeCapable &&\n\t\t\tcompletion.text.trim().length > 0 &&\n\t\t\tcompletionChangedFiles.length === 0 &&\n\t\t\t!changedFilesOverflowed;\n\t\tif (readOnlyPlainText) {\n\t\t\tconst completionBlockersReport = collectBoundedWorkerClaimBlockers(completion.blockers ?? []);\n\t\t\tconst completionBlockers = completionBlockersReport.overflowed\n\t\t\t\t? [\n\t\t\t\t\t\t...completionBlockersReport.values.slice(0, Math.max(0, MAX_WORKER_CLAIM_BLOCKERS - 1)),\n\t\t\t\t\t\t\"worker blocker report exceeded the durable claim bound; parent review is required\",\n\t\t\t\t\t]\n\t\t\t\t: completionBlockersReport.values;\n\t\t\tconst incompleteNote =\n\t\t\t\tcompletion.stopReason === \"stop\"\n\t\t\t\t\t? \"\"\n\t\t\t\t\t: `\\n\\n[Worker output ended with stop reason '${completion.stopReason}'; verify completeness.]`;\n\t\t\tconst summary = `${completion.text.trim().slice(0, Math.max(0, MAX_WORKER_CLAIM_SUMMARY_CHARS - incompleteNote.length))}${incompleteNote}`;\n\t\t\tconst blocked = completionBlockers.length > 0;\n\t\t\treturn finishOutcome({\n\t\t\t\trequest: options.request,\n\t\t\t\tcwd: options.cwd,\n\t\t\t\tclaim: {\n\t\t\t\t\t...completionBaseClaim,\n\t\t\t\t\tstatus: blocked ? \"blocked\" : \"completed\",\n\t\t\t\t\toutputFormat: \"plain_text\",\n\t\t\t\t\tsummary,\n\t\t\t\t\t...(blocked ? { blockers: completionBlockers } : {}),\n\t\t\t\t},\n\t\t\t\tlaneStatus: blocked ? \"blocked\" : \"succeeded\",\n\t\t\t\treasonCode: blocked\n\t\t\t\t\t? \"worker_blocked\"\n\t\t\t\t\t: completion.stopReason === \"stop\"\n\t\t\t\t\t\t? \"worker_completed_plain_text\"\n\t\t\t\t\t\t: \"worker_completed_plain_text_incomplete\",\n\t\t\t\tcostUsd,\n\t\t\t});\n\t\t}\n\t\treturn finishOutcome({\n\t\t\trequest: options.request,\n\t\t\tcwd: options.cwd,\n\t\t\tclaim: {\n\t\t\t\t...completionBaseClaim,\n\t\t\t\tstatus: \"failed\",\n\t\t\t\tsummary: \"Worker output was not valid structured JSON.\",\n\t\t\t\t...(changedFilesOverflowed\n\t\t\t\t\t? {\n\t\t\t\t\t\t\tblockers: [\n\t\t\t\t\t\t\t\t\"worker changed-file report exceeded the durable claim bound; parent review is required\",\n\t\t\t\t\t\t\t],\n\t\t\t\t\t\t}\n\t\t\t\t\t: {}),\n\t\t\t},\n\t\t\tlaneStatus: \"failed\",\n\t\t\treasonCode: \"unparseable_output\",\n\t\t\tcostUsd,\n\t\t});\n\t}\n\n\tconst evidence = buildWorkerEvidence(options.request, parsed.findings);\n\tif (parsed.actionRejection) {\n\t\treturn finishOutcome({\n\t\t\trequest: options.request,\n\t\t\tcwd: options.cwd,\n\t\t\tclaim: {\n\t\t\t\t...completionBaseClaim,\n\t\t\t\tstatus: \"failed\",\n\t\t\t\tsummary: \"Worker output contained invalid structured actions.\",\n\t\t\t\tblockers: [parsed.actionRejection.reasonCode],\n\t\t\t},\n\t\t\tlaneStatus: \"failed\",\n\t\t\treasonCode: \"unparseable_output\",\n\t\t\tcostUsd,\n\t\t});\n\t}\n\tif (options.verificationSubjectTaskId && (!parsed.verdict || parsed.reasonCodes.length === 0)) {\n\t\treturn finishOutcome({\n\t\t\trequest: options.request,\n\t\t\tcwd: options.cwd,\n\t\t\tclaim: {\n\t\t\t\t...completionBaseClaim,\n\t\t\t\tstatus: \"failed\",\n\t\t\t\tsummary: \"Verifier output omitted its typed verdict or reasonCodes.\",\n\t\t\t},\n\t\t\tlaneStatus: \"failed\",\n\t\t\treasonCode: \"invalid_verifier_result\",\n\t\t\tcostUsd,\n\t\t});\n\t}\n\tlet changedFiles: string[] = [...completionChangedFiles];\n\tconst completionBlockersReport = collectBoundedWorkerClaimBlockers(completion.blockers ?? []);\n\tconst actionBlockers: string[] = [...completionBlockersReport.values];\n\tif (changedFilesOverflowed) {\n\t\tactionBlockers.push(\"worker changed-file report exceeded the durable claim bound; parent review is required\");\n\t}\n\tif (completionBlockersReport.overflowed) {\n\t\tactionBlockers.push(\"worker blocker report exceeded the durable claim bound; parent review is required\");\n\t}\n\tif (!writeCapable && completionChangedFiles.length > 0) {\n\t\tactionBlockers.push(\"worker reported file changes without a filesystem.write envelope grant\");\n\t}\n\tif (writeCapable && parsed.status !== \"blocked\" && parsed.actions.length > 0 && options.applyActions) {\n\t\t// Runner-side application through the envelope path scope: refusals and failures are\n\t\t// surfaced as blockers so a partially-applied change can never look like clean success.\n\t\tconst applied = options.applyActions(parsed.actions);\n\t\tconst appliedChangedFilesReport = collectBoundedWorkerClaimChangedFiles(applied.changedFiles);\n\t\tconst mergedAppliedChangedFilesReport = collectBoundedWorkerClaimChangedFiles([\n\t\t\t...changedFiles,\n\t\t\t...appliedChangedFilesReport.values,\n\t\t]);\n\t\tchangedFiles = mergedAppliedChangedFilesReport.values;\n\t\tif (appliedChangedFilesReport.overflowed || mergedAppliedChangedFilesReport.overflowed) {\n\t\t\tactionBlockers.push(\"applied changed-file report exceeded the durable claim bound; parent review is required\");\n\t\t}\n\t\tfor (const refusal of applied.refused) {\n\t\t\tactionBlockers.push(`action refused (${refusal.path}): ${refusal.reason}`);\n\t\t}\n\t\tfor (const failure of applied.failed) {\n\t\t\tactionBlockers.push(`action failed (${failure.path}): ${failure.reason}`);\n\t\t}\n\t\tfor (const inspection of applied.inspectionRequired) {\n\t\t\tactionBlockers.push(\n\t\t\t\t`action requires workspace/evidence inspection (${inspection.path}, ${inspection.state}): ${inspection.reasonCode}`,\n\t\t\t);\n\t\t}\n\t} else if (!writeCapable && parsed.actions.length > 0) {\n\t\tactionBlockers.push(\"worker emitted file actions without a filesystem.write envelope grant; nothing was applied\");\n\t}\n\tconst allBlockersReport = collectBoundedWorkerClaimBlockers([...parsed.blockers, ...actionBlockers]);\n\tconst allBlockers = allBlockersReport.overflowed\n\t\t? [\n\t\t\t\t...allBlockersReport.values.slice(0, Math.max(0, MAX_WORKER_CLAIM_BLOCKERS - 1)),\n\t\t\t\t\"worker blocker report exceeded the durable claim bound; parent review is required\",\n\t\t\t]\n\t\t: allBlockersReport.values;\n\tconst claim: WorkerClaim = {\n\t\t...baseClaim,\n\t\tchangedFiles,\n\t\tstatus: parsed.status === \"blocked\" || allBlockers.length > 0 ? \"blocked\" : \"completed\",\n\t\tsummary: parsed.summary,\n\t\t...(allBlockers.length > 0 ? { blockers: allBlockers } : {}),\n\t\t...(evidence ? { evidence } : {}),\n\t\t...(options.verificationSubjectTaskId && parsed.verdict\n\t\t\t? {\n\t\t\t\t\tverification: {\n\t\t\t\t\t\tsubjectTaskId: options.verificationSubjectTaskId,\n\t\t\t\t\t\tverdict: parsed.verdict,\n\t\t\t\t\t\treasonCodes: parsed.reasonCodes,\n\t\t\t\t\t},\n\t\t\t\t}\n\t\t\t: {}),\n\t};\n\n\tif (claim.status === \"blocked\") {\n\t\treturn finishOutcome({\n\t\t\trequest: options.request,\n\t\t\tcwd: options.cwd,\n\t\t\tclaim,\n\t\t\tlaneStatus: \"blocked\",\n\t\t\treasonCode: \"worker_blocked\",\n\t\t\tcostUsd,\n\t\t});\n\t}\n\n\tconst overBudget = options.maxUsd !== undefined && costUsd > options.maxUsd;\n\tconst finalClaim: WorkerClaim = overBudget\n\t\t? {\n\t\t\t\t...claim,\n\t\t\t\tstatus: \"partial\",\n\t\t\t\tblockers: [...(claim.blockers ?? []), \"cost_budget_exceeded\"],\n\t\t\t}\n\t\t: claim;\n\treturn finishOutcome({\n\t\trequest: options.request,\n\t\tcwd: options.cwd,\n\t\tclaim: finalClaim,\n\t\tlaneStatus: overBudget ? \"budget_exhausted\" : \"succeeded\",\n\t\treasonCode: overBudget\n\t\t\t? \"cost_budget_exceeded\"\n\t\t\t: claim.verification\n\t\t\t\t? claim.verification.verdict === \"accepted\"\n\t\t\t\t\t? \"verification_accepted\"\n\t\t\t\t\t: \"verification_rejected\"\n\t\t\t\t: \"worker_completed\",\n\t\tcostUsd,\n\t});\n}\n"]}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import type { Model } from "@caupulican/pi-ai";
|
|
2
|
+
import { type ModelAdaptationRule } from "../models/adaptation-store.ts";
|
|
3
|
+
export interface WorkerModelGuidance {
|
|
4
|
+
rules: ModelAdaptationRule[];
|
|
5
|
+
toolProbeStatus?: string;
|
|
6
|
+
toolProbeGrade?: string;
|
|
7
|
+
toolProbeDiagnostic?: string;
|
|
8
|
+
protocolStatus?: string;
|
|
9
|
+
protocolVariant?: string;
|
|
10
|
+
teachStats?: Record<string, {
|
|
11
|
+
taught: number;
|
|
12
|
+
recurrenceBefore: number;
|
|
13
|
+
recurrenceAfter: number;
|
|
14
|
+
}>;
|
|
15
|
+
}
|
|
16
|
+
export interface BuildWorkerSystemPromptOptions {
|
|
17
|
+
/** Situational soul / identity snippet from shipped profile. */
|
|
18
|
+
soul?: string;
|
|
19
|
+
/** Worker role prompt or execution plan prompt. */
|
|
20
|
+
rolePrompt: string;
|
|
21
|
+
/** Materialized worker resource system prompt (skills/tools). */
|
|
22
|
+
workerResourceSystemPrompt?: string;
|
|
23
|
+
/** Override for all layers above Level-0 subagent core. */
|
|
24
|
+
override?: string;
|
|
25
|
+
/** Session agent directory to resolve ModelAdaptationStore. */
|
|
26
|
+
agentDir?: string;
|
|
27
|
+
/** Provider string (e.g. "anthropic", "openai"). */
|
|
28
|
+
provider?: string;
|
|
29
|
+
/** Model ID string (e.g. "claude-3-5-sonnet-20241022"). */
|
|
30
|
+
modelId?: string;
|
|
31
|
+
/** Target model instance if available. */
|
|
32
|
+
model?: Model<any>;
|
|
33
|
+
}
|
|
34
|
+
/** Formats provider and model ID into standard modelRef key. */
|
|
35
|
+
export declare function formatWorkerModelRef(provider: string, modelId: string): string;
|
|
36
|
+
/**
|
|
37
|
+
* Dynamically loads model-specific adaptation rules and tool-recovery observations
|
|
38
|
+
* from the session's ModelAdaptationStore based on provider and model ID.
|
|
39
|
+
*/
|
|
40
|
+
export declare function loadWorkerModelGuidance(options: {
|
|
41
|
+
agentDir: string;
|
|
42
|
+
provider: string;
|
|
43
|
+
modelId: string;
|
|
44
|
+
}): WorkerModelGuidance;
|
|
45
|
+
/**
|
|
46
|
+
* Formats model adaptation rules and tool-recovery observations into prompt blocks.
|
|
47
|
+
*/
|
|
48
|
+
export declare function formatWorkerModelGuidancePrompt(guidance: WorkerModelGuidance): string | undefined;
|
|
49
|
+
/**
|
|
50
|
+
* Builds worker system prompt with level-0 subagent core, situational soul,
|
|
51
|
+
* role prompt, resource system prompt, and dynamically appended model adaptation guidance.
|
|
52
|
+
*/
|
|
53
|
+
export declare function buildWorkerSystemPrompt(options: BuildWorkerSystemPromptOptions): string;
|
|
54
|
+
//# sourceMappingURL=worker-system-prompt.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"worker-system-prompt.d.ts","sourceRoot":"","sources":["../../../src/core/delegation/worker-system-prompt.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,mBAAmB,CAAC;AAE/C,OAAO,EAEN,KAAK,mBAAmB,EAExB,MAAM,+BAA+B,CAAC;AAEvC,MAAM,WAAW,mBAAmB;IACnC,KAAK,EAAE,mBAAmB,EAAE,CAAC;IAC7B,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,mBAAmB,CAAC,EAAE,MAAM,CAAC;IAC7B,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,UAAU,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE;QAAE,MAAM,EAAE,MAAM,CAAC;QAAC,gBAAgB,EAAE,MAAM,CAAC;QAAC,eAAe,EAAE,MAAM,CAAA;KAAE,CAAC,CAAC;CACnG;AAED,MAAM,WAAW,8BAA8B;IAC9C,gEAAgE;IAChE,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,mDAAmD;IACnD,UAAU,EAAE,MAAM,CAAC;IACnB,iEAAiE;IACjE,0BAA0B,CAAC,EAAE,MAAM,CAAC;IACpC,2DAA2D;IAC3D,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,+DAA+D;IAC/D,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,oDAAoD;IACp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