@bastani/atomic 0.9.12 → 0.9.13-alpha.1
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 +20 -0
- package/dist/builtin/intercom/CHANGELOG.md +6 -0
- package/dist/builtin/intercom/README.md +5 -12
- package/dist/builtin/intercom/broker/client.ts +11 -2
- package/dist/builtin/intercom/contact-supervisor-tool.ts +13 -3
- package/dist/builtin/intercom/index-heavy.ts +13 -3
- package/dist/builtin/intercom/index.ts +43 -19
- package/dist/builtin/intercom/intercom-utils.ts +15 -29
- package/dist/builtin/intercom/package.json +1 -1
- package/dist/builtin/intercom/source-ownership.ts +9 -12
- package/dist/builtin/mcp/CHANGELOG.md +6 -0
- package/dist/builtin/mcp/README.md +3 -1
- package/dist/builtin/mcp/index.ts +10 -16
- package/dist/builtin/mcp/package.json +1 -1
- package/dist/builtin/mcp/startup-warmup.ts +20 -8
- package/dist/builtin/subagents/CHANGELOG.md +30 -0
- package/dist/builtin/subagents/README.md +22 -30
- package/dist/builtin/subagents/package.json +1 -1
- package/dist/builtin/subagents/src/extension/doctor.ts +1 -1
- package/dist/builtin/subagents/src/extension/fanout-child.ts +76 -56
- package/dist/builtin/subagents/src/extension/index.ts +23 -32
- package/dist/builtin/subagents/src/extension/startup-maintenance.ts +25 -44
- package/dist/builtin/subagents/src/intercom/result-intercom.ts +7 -7
- package/dist/builtin/subagents/src/runs/background/async-job-tracker.ts +166 -434
- package/dist/builtin/subagents/src/runs/background/notify.ts +29 -8
- package/dist/builtin/subagents/src/runs/foreground/chain-execution-dynamic-step.ts +2 -2
- package/dist/builtin/subagents/src/runs/foreground/chain-execution-parallel-runner.ts +4 -4
- package/dist/builtin/subagents/src/runs/foreground/chain-execution-parallel-step.ts +2 -2
- package/dist/builtin/subagents/src/runs/foreground/chain-execution-sequential-step.ts +2 -2
- package/dist/builtin/subagents/src/runs/foreground/execution-run-sync.ts +1 -281
- package/dist/builtin/subagents/src/runs/foreground/execution-structured-retries.ts +11 -75
- package/dist/builtin/subagents/src/runs/foreground/inprocess-run-sync.ts +457 -0
- package/dist/builtin/subagents/src/runs/foreground/subagent-executor-async.ts +119 -246
- package/dist/builtin/subagents/src/runs/foreground/subagent-executor-chain.ts +1 -1
- package/dist/builtin/subagents/src/runs/foreground/subagent-executor-context.ts +18 -9
- package/dist/builtin/subagents/src/runs/foreground/subagent-executor-parallel-task.ts +1 -1
- package/dist/builtin/subagents/src/runs/foreground/subagent-executor-parallel.ts +4 -4
- package/dist/builtin/subagents/src/runs/foreground/subagent-executor-resume.ts +1 -646
- package/dist/builtin/subagents/src/runs/foreground/subagent-executor-runtime.ts +2 -7
- package/dist/builtin/subagents/src/runs/foreground/subagent-executor-single.ts +5 -5
- package/dist/builtin/subagents/src/runs/foreground/subagent-executor-status.ts +7 -8
- package/dist/builtin/subagents/src/runs/foreground/subagent-executor-types.ts +14 -5
- package/dist/builtin/subagents/src/runs/foreground/subagent-executor.ts +158 -93
- package/dist/builtin/subagents/src/runs/inprocess/background-single.ts +179 -0
- package/dist/builtin/subagents/src/runs/inprocess/background.ts +89 -0
- package/dist/builtin/subagents/src/runs/inprocess/child-policy.ts +27 -0
- package/dist/builtin/subagents/src/runs/inprocess/control-registry.ts +55 -0
- package/dist/builtin/subagents/src/runs/inprocess/control-status.ts +106 -0
- package/dist/builtin/subagents/src/runs/inprocess/index.ts +50 -0
- package/dist/builtin/subagents/src/runs/inprocess/nested-routing.ts +218 -0
- package/dist/builtin/subagents/src/runs/{shared/subagent-prompt-runtime.ts → inprocess/prompt-behavior.ts} +37 -75
- package/dist/builtin/subagents/src/runs/inprocess/runner.ts +1138 -0
- package/dist/builtin/subagents/src/runs/{shared/nested-events.ts → inprocess/runtime-support/nested-api.ts} +13 -7
- package/dist/builtin/subagents/src/runs/{shared/nested-events-control.ts → inprocess/runtime-support/nested-control.ts} +18 -17
- package/dist/builtin/subagents/src/runs/{shared/nested-events-core.ts → inprocess/runtime-support/nested-core.ts} +14 -61
- package/dist/builtin/subagents/src/runs/{shared/nested-events-projection.ts → inprocess/runtime-support/nested-projection.ts} +4 -10
- package/dist/builtin/subagents/src/runs/{shared/nested-events-registry.ts → inprocess/runtime-support/nested-registry.ts} +19 -4
- package/dist/builtin/subagents/src/runs/{shared/nested-render.ts → inprocess/runtime-support/nested-rendering.ts} +3 -3
- package/dist/builtin/subagents/src/runs/{shared/nested-events-sanitize.ts → inprocess/runtime-support/nested-sanitize.ts} +3 -3
- package/dist/builtin/subagents/src/runs/inprocess.ts +1 -0
- package/dist/builtin/subagents/src/runs/shared/dynamic-fanout.ts +10 -4
- package/dist/builtin/subagents/src/runs/shared/model-candidate-filter.ts +0 -1
- package/dist/builtin/subagents/src/runs/shared/model-fallback.ts +15 -492
- package/dist/builtin/subagents/src/runs/shared/parallel-utils.ts +13 -11
- package/dist/builtin/subagents/src/runs/shared/run-history.ts +3 -5
- package/dist/builtin/subagents/src/runs/shared/single-output.ts +4 -4
- package/dist/builtin/subagents/src/runs/shared/workflow-graph.ts +5 -5
- package/dist/builtin/subagents/src/shared/types-async.ts +0 -1
- package/dist/builtin/subagents/src/shared/types-config.ts +18 -0
- package/dist/builtin/subagents/src/shared/types-results.ts +9 -2
- package/dist/builtin/subagents/src/slash/prompt-template-bridge.ts +2 -3
- package/dist/builtin/subagents/src/slash/slash-live-state.ts +2 -2
- package/dist/builtin/subagents/src/tui/render-chain-graph.ts +10 -4
- package/dist/builtin/subagents/src/tui/render-event-formatting.ts +12 -11
- package/dist/builtin/subagents/src/tui/render-result-compact.ts +49 -12
- package/dist/builtin/subagents/src/tui/render-result.ts +46 -17
- package/dist/builtin/subagents/src/tui/render-stable-output.ts +1 -1
- package/dist/builtin/subagents/src/tui/render-status-progress.ts +8 -5
- package/dist/builtin/subagents/src/tui/render-widget-graph.ts +0 -8
- package/dist/builtin/subagents/src/tui/render-widget.ts +0 -24
- package/dist/builtin/web-access/package.json +1 -1
- package/dist/builtin/workflows/CHANGELOG.md +25 -0
- package/dist/builtin/workflows/README.md +13 -3
- package/dist/builtin/workflows/package.json +1 -1
- package/dist/builtin/workflows/src/durable/backend.ts +7 -0
- package/dist/builtin/workflows/src/durable/dbos-metadata.ts +11 -1
- package/dist/builtin/workflows/src/durable/resume-runtime.ts +1 -0
- package/dist/builtin/workflows/src/durable/tool-primitive.ts +4 -28
- package/dist/builtin/workflows/src/durable/types.ts +5 -0
- package/dist/builtin/workflows/src/engine/run.ts +17 -1
- package/dist/builtin/workflows/src/extension/atomic-stage-session.ts +12 -39
- package/dist/builtin/workflows/src/extension/config-file-loader.ts +10 -1
- package/dist/builtin/workflows/src/extension/config-loader.ts +1 -1
- package/dist/builtin/workflows/src/extension/dispatcher.ts +4 -0
- package/dist/builtin/workflows/src/extension/index.bundle.mjs +1151 -737
- package/dist/builtin/workflows/src/extension/lifecycle-notifications.ts +303 -38
- package/dist/builtin/workflows/src/extension/render-result.ts +4 -0
- package/dist/builtin/workflows/src/extension/runtime-durable-resume.ts +6 -3
- package/dist/builtin/workflows/src/extension/runtime.ts +7 -1
- package/dist/builtin/workflows/src/extension/wiring.ts +53 -11
- package/dist/builtin/workflows/src/extension/workflow-command-registration.ts +12 -3
- package/dist/builtin/workflows/src/extension/workflow-durable-resume-command.ts +5 -2
- package/dist/builtin/workflows/src/extension/workflow-run-control-command.ts +9 -7
- package/dist/builtin/workflows/src/extension/workflow-status-summary.ts +11 -0
- package/dist/builtin/workflows/src/extension/workflow-tool-content.ts +18 -1
- package/dist/builtin/workflows/src/extension/workflow-tool-control.ts +10 -8
- package/dist/builtin/workflows/src/extension/workflow-tool.ts +9 -4
- package/dist/builtin/workflows/src/runs/background/quit.ts +28 -4
- package/dist/builtin/workflows/src/runs/background/resume-acknowledgements.ts +2 -1
- package/dist/builtin/workflows/src/runs/background/status.ts +55 -8
- package/dist/builtin/workflows/src/runs/foreground/executor-direct-helpers.ts +4 -0
- package/dist/builtin/workflows/src/runs/foreground/executor-prompt-nodes.ts +3 -1
- package/dist/builtin/workflows/src/runs/foreground/executor-stage-control.ts +1 -1
- package/dist/builtin/workflows/src/runs/foreground/stage-runner-context.ts +1 -1
- package/dist/builtin/workflows/src/runs/foreground/stage-runner-controller.ts +688 -38
- package/dist/builtin/workflows/src/runs/foreground/stage-runner-types.ts +3 -1
- package/dist/builtin/workflows/src/runs/shared/model-fallback-failures.ts +19 -514
- package/dist/builtin/workflows/src/runs/shared/retry.ts +44 -0
- package/dist/builtin/workflows/src/shared/authoring-contract-stage.d.ts +5 -0
- package/dist/builtin/workflows/src/shared/authoring-contract-stage.ts +6 -0
- package/dist/builtin/workflows/src/shared/authoring-contract-ui.d.ts +5 -1
- package/dist/builtin/workflows/src/shared/authoring-contract-ui.ts +5 -0
- package/dist/builtin/workflows/src/shared/persistence-restore-helpers.ts +5 -0
- package/dist/builtin/workflows/src/shared/persistence-restore.ts +3 -0
- package/dist/builtin/workflows/src/shared/persistence-session-entries.ts +4 -0
- package/dist/builtin/workflows/src/shared/run-indicator-status.ts +75 -0
- package/dist/builtin/workflows/src/shared/store-public-types.ts +43 -7
- package/dist/builtin/workflows/src/shared/store-run-methods.ts +42 -8
- package/dist/builtin/workflows/src/shared/store-stage-methods.ts +31 -8
- package/dist/builtin/workflows/src/shared/store-types.ts +34 -0
- package/dist/builtin/workflows/src/shared/timing.ts +10 -0
- package/dist/builtin/workflows/src/tui/chat-surface-message.ts +22 -2
- package/dist/builtin/workflows/src/tui/session-list.ts +1 -1
- package/dist/builtin/workflows/src/tui/session-overlays.ts +14 -10
- package/dist/builtin/workflows/src/tui/session-picker.ts +20 -4
- package/dist/builtin/workflows/src/tui/status-list.ts +31 -47
- package/dist/builtin/workflows/src/tui/store-widget-installer.ts +9 -1
- package/dist/builtin/workflows/src/tui/widget.ts +16 -46
- package/dist/core/agent-session-auto-compaction.d.ts.map +1 -1
- package/dist/core/agent-session-auto-compaction.js +54 -11
- package/dist/core/agent-session-auto-compaction.js.map +1 -1
- package/dist/core/agent-session-events.d.ts.map +1 -1
- package/dist/core/agent-session-events.js +49 -14
- package/dist/core/agent-session-events.js.map +1 -1
- package/dist/core/agent-session-methods.d.ts +13 -0
- package/dist/core/agent-session-methods.d.ts.map +1 -1
- package/dist/core/agent-session-methods.js.map +1 -1
- package/dist/core/agent-session-models.d.ts.map +1 -1
- package/dist/core/agent-session-models.js +12 -1
- package/dist/core/agent-session-models.js.map +1 -1
- package/dist/core/agent-session-prompt.d.ts.map +1 -1
- package/dist/core/agent-session-prompt.js +4 -0
- package/dist/core/agent-session-prompt.js.map +1 -1
- package/dist/core/agent-session-retry.d.ts +21 -4
- package/dist/core/agent-session-retry.d.ts.map +1 -1
- package/dist/core/agent-session-retry.js +232 -106
- package/dist/core/agent-session-retry.js.map +1 -1
- package/dist/core/agent-session-state.d.ts.map +1 -1
- package/dist/core/agent-session-state.js +2 -1
- package/dist/core/agent-session-state.js.map +1 -1
- package/dist/core/agent-session-tool-hooks.d.ts.map +1 -1
- package/dist/core/agent-session-tool-hooks.js +12 -0
- package/dist/core/agent-session-tool-hooks.js.map +1 -1
- package/dist/core/agent-session-tool-registry.d.ts.map +1 -1
- package/dist/core/agent-session-tool-registry.js +1 -1
- package/dist/core/agent-session-tool-registry.js.map +1 -1
- package/dist/core/agent-session-types.d.ts +3 -1
- package/dist/core/agent-session-types.d.ts.map +1 -1
- package/dist/core/agent-session-types.js.map +1 -1
- package/dist/core/agent-session.d.ts +12 -1
- package/dist/core/agent-session.d.ts.map +1 -1
- package/dist/core/agent-session.js +7 -0
- package/dist/core/agent-session.js.map +1 -1
- package/dist/core/extensions/context-types.d.ts +25 -0
- package/dist/core/extensions/context-types.d.ts.map +1 -1
- package/dist/core/extensions/context-types.js.map +1 -1
- package/dist/core/extensions/index.d.ts +1 -1
- package/dist/core/extensions/index.d.ts.map +1 -1
- package/dist/core/extensions/index.js.map +1 -1
- package/dist/core/extensions/runner-context.d.ts +2 -1
- package/dist/core/extensions/runner-context.d.ts.map +1 -1
- package/dist/core/extensions/runner-context.js +4 -0
- package/dist/core/extensions/runner-context.js.map +1 -1
- package/dist/core/extensions/runner.d.ts +3 -2
- package/dist/core/extensions/runner.d.ts.map +1 -1
- package/dist/core/extensions/runner.js +3 -1
- package/dist/core/extensions/runner.js.map +1 -1
- package/dist/core/model-fallback-failures.d.ts +30 -0
- package/dist/core/model-fallback-failures.d.ts.map +1 -0
- package/dist/core/model-fallback-failures.js +610 -0
- package/dist/core/model-fallback-failures.js.map +1 -0
- package/dist/core/retry-policy.d.ts +30 -0
- package/dist/core/retry-policy.d.ts.map +1 -0
- package/dist/core/retry-policy.js +25 -0
- package/dist/core/retry-policy.js.map +1 -0
- package/dist/core/sdk-types.d.ts +8 -2
- package/dist/core/sdk-types.d.ts.map +1 -1
- package/dist/core/sdk-types.js.map +1 -1
- package/dist/core/sdk.d.ts.map +1 -1
- package/dist/core/sdk.js +6 -1
- package/dist/core/sdk.js.map +1 -1
- package/dist/core/session-manager-core.d.ts +2 -0
- package/dist/core/session-manager-core.d.ts.map +1 -1
- package/dist/core/session-manager-core.js +7 -0
- package/dist/core/session-manager-core.js.map +1 -1
- package/dist/index-extensions.d.ts +1 -1
- package/dist/index-extensions.d.ts.map +1 -1
- package/dist/index-extensions.js.map +1 -1
- package/dist/index.d.ts +3 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -0
- package/dist/index.js.map +1 -1
- package/docs/intercom.md +5 -10
- package/docs/settings.md +7 -1
- package/docs/subagents.md +19 -19
- package/docs/workflows.md +21 -5
- package/examples/extensions/gondolin/package-lock.json +3 -3
- package/npm-shrinkwrap.json +29 -29
- package/package.json +2 -2
- package/dist/builtin/subagents/src/runs/background/async-event-journal.ts +0 -112
- package/dist/builtin/subagents/src/runs/background/async-execution-chain.ts +0 -543
- package/dist/builtin/subagents/src/runs/background/async-execution-common.ts +0 -140
- package/dist/builtin/subagents/src/runs/background/async-execution-single.ts +0 -279
- package/dist/builtin/subagents/src/runs/background/async-execution-types.ts +0 -99
- package/dist/builtin/subagents/src/runs/background/async-execution.ts +0 -17
- package/dist/builtin/subagents/src/runs/background/async-resume.ts +0 -402
- package/dist/builtin/subagents/src/runs/background/async-status.ts +0 -411
- package/dist/builtin/subagents/src/runs/background/completion-claims.ts +0 -196
- package/dist/builtin/subagents/src/runs/background/completion-dedupe.ts +0 -102
- package/dist/builtin/subagents/src/runs/background/parallel-groups.ts +0 -59
- package/dist/builtin/subagents/src/runs/background/result-delivery-processor.ts +0 -300
- package/dist/builtin/subagents/src/runs/background/result-file-claims.ts +0 -166
- package/dist/builtin/subagents/src/runs/background/result-quarantine.ts +0 -77
- package/dist/builtin/subagents/src/runs/background/result-retry-scheduler.ts +0 -48
- package/dist/builtin/subagents/src/runs/background/result-status.ts +0 -87
- package/dist/builtin/subagents/src/runs/background/result-watcher-data.ts +0 -72
- package/dist/builtin/subagents/src/runs/background/result-watcher.ts +0 -320
- package/dist/builtin/subagents/src/runs/background/run-id-resolver.ts +0 -105
- package/dist/builtin/subagents/src/runs/background/run-status.ts +0 -358
- package/dist/builtin/subagents/src/runs/background/stale-run-reconciler.ts +0 -457
- package/dist/builtin/subagents/src/runs/background/subagent-runner-dynamic.ts +0 -376
- package/dist/builtin/subagents/src/runs/background/subagent-runner-finalize.ts +0 -150
- package/dist/builtin/subagents/src/runs/background/subagent-runner-output.ts +0 -109
- package/dist/builtin/subagents/src/runs/background/subagent-runner-parallel-helpers.ts +0 -128
- package/dist/builtin/subagents/src/runs/background/subagent-runner-parallel.ts +0 -309
- package/dist/builtin/subagents/src/runs/background/subagent-runner-sequential.ts +0 -173
- package/dist/builtin/subagents/src/runs/background/subagent-runner-state.ts +0 -578
- package/dist/builtin/subagents/src/runs/background/subagent-runner-step.ts +0 -330
- package/dist/builtin/subagents/src/runs/background/subagent-runner-streaming.ts +0 -330
- package/dist/builtin/subagents/src/runs/background/subagent-runner-types.ts +0 -210
- package/dist/builtin/subagents/src/runs/background/subagent-runner-utils.ts +0 -69
- package/dist/builtin/subagents/src/runs/background/subagent-runner.ts +0 -90
- package/dist/builtin/subagents/src/runs/background/top-level-async.ts +0 -12
- package/dist/builtin/subagents/src/runs/foreground/execution-attempt-control.ts +0 -140
- package/dist/builtin/subagents/src/runs/foreground/execution-attempt-finalize.ts +0 -108
- package/dist/builtin/subagents/src/runs/foreground/execution-attempt-types.ts +0 -17
- package/dist/builtin/subagents/src/runs/foreground/execution-attempt.ts +0 -558
- package/dist/builtin/subagents/src/runs/shared/attempt-watchdog.ts +0 -126
- package/dist/builtin/subagents/src/runs/shared/final-drain.ts +0 -39
- package/dist/builtin/subagents/src/runs/shared/pi-args.ts +0 -339
- package/dist/builtin/subagents/src/runs/shared/pi-spawn.ts +0 -165
- package/dist/builtin/subagents/src/runs/shared/spawn-env.ts +0 -21
- package/dist/builtin/subagents/src/shared/post-exit-stdio-guard.ts +0 -86
- /package/dist/builtin/subagents/src/runs/{shared/nested-path.ts → inprocess/runtime-support/nested-paths.ts} +0 -0
|
@@ -4,14 +4,17 @@
|
|
|
4
4
|
|
|
5
5
|
import type { ExtensionAPI } from "@bastani/atomic";
|
|
6
6
|
import { resolveSubagentIntercomTarget } from "../../intercom/intercom-bridge.ts";
|
|
7
|
-
import {
|
|
8
|
-
|
|
7
|
+
import {
|
|
8
|
+
SUBAGENT_ASYNC_COMPLETE_EVENT,
|
|
9
|
+
SUBAGENT_TERMINAL_ORDERING_BARRIER_EVENT,
|
|
10
|
+
type SubagentAttemptStatus,
|
|
11
|
+
} from "../../shared/types.ts";
|
|
9
12
|
import type { CompletionNotificationEnvelope } from "./completion-notification.ts";
|
|
10
13
|
|
|
11
14
|
interface ChainStepResult {
|
|
12
15
|
agent: string;
|
|
13
16
|
output: string;
|
|
14
|
-
|
|
17
|
+
status: SubagentAttemptStatus;
|
|
15
18
|
intercomTarget?: string;
|
|
16
19
|
index?: number;
|
|
17
20
|
}
|
|
@@ -31,9 +34,8 @@ interface SubagentResult {
|
|
|
31
34
|
runId?: string;
|
|
32
35
|
notificationId?: string;
|
|
33
36
|
agent: string | null;
|
|
34
|
-
|
|
37
|
+
status: SubagentAttemptStatus;
|
|
35
38
|
summary: string;
|
|
36
|
-
exitCode?: number;
|
|
37
39
|
state?: string;
|
|
38
40
|
timestamp: number;
|
|
39
41
|
durationMs?: number;
|
|
@@ -87,6 +89,20 @@ function getNotifySeen(pi: ExtensionAPI): Map<string, number> {
|
|
|
87
89
|
return seen;
|
|
88
90
|
}
|
|
89
91
|
|
|
92
|
+
function buildCompletionKey(data: SubagentResult, fallback: string): string {
|
|
93
|
+
if (data.runId) return `run:${data.runId}`;
|
|
94
|
+
if (data.id) return `id:${data.id}`;
|
|
95
|
+
return `meta:${data.agent ?? "unknown"}:${data.timestamp}:${data.taskIndex ?? "-"}:${fallback}`;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
function hasSeenWithTtl(seen: Map<string, number>, key: string, now: number, ttlMs: number): boolean {
|
|
99
|
+
for (const [seenKey, seenAt] of seen) if (now - seenAt > ttlMs) seen.delete(seenKey);
|
|
100
|
+
return seen.has(key);
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
function recordSeen(seen: Map<string, number>, key: string, now: number): void {
|
|
104
|
+
seen.set(key, now);
|
|
105
|
+
}
|
|
90
106
|
function isPromiseLike(value: unknown): value is PromiseLike<void> {
|
|
91
107
|
return (
|
|
92
108
|
(typeof value === "object" || typeof value === "function") &&
|
|
@@ -192,9 +208,14 @@ export default function registerSubagentNotify(pi: ExtensionAPI): () => void {
|
|
|
192
208
|
const agent = result.agent ?? "unknown";
|
|
193
209
|
const summary = typeof result.summary === "string" ? result.summary : "";
|
|
194
210
|
const paused =
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
211
|
+
result.status === "interrupted" || result.state === "paused" || summary.startsWith("Paused after interrupt.");
|
|
212
|
+
const status = paused
|
|
213
|
+
? "paused"
|
|
214
|
+
: result.status === "ok"
|
|
215
|
+
? "completed"
|
|
216
|
+
: result.status === "continued"
|
|
217
|
+
? "paused"
|
|
218
|
+
: "failed";
|
|
198
219
|
|
|
199
220
|
const taskInfo =
|
|
200
221
|
result.taskIndex !== undefined && result.totalTasks !== undefined
|
|
@@ -222,7 +222,7 @@ export async function runDynamicParallelChainStep(input: {
|
|
|
222
222
|
}
|
|
223
223
|
const failures = parallelResults
|
|
224
224
|
.map((result, originalIndex) => ({ ...result, originalIndex }))
|
|
225
|
-
.filter((result) => result.
|
|
225
|
+
.filter((result) => result.status === "error");
|
|
226
226
|
if (failures.length > 0) {
|
|
227
227
|
const failureSummary = failures
|
|
228
228
|
.map(
|
|
@@ -269,7 +269,7 @@ export async function runDynamicParallelChainStep(input: {
|
|
|
269
269
|
agent: result.agent,
|
|
270
270
|
taskIndex: index,
|
|
271
271
|
output: getSingleResultOutput(result),
|
|
272
|
-
|
|
272
|
+
status: result.status,
|
|
273
273
|
error: result.error,
|
|
274
274
|
}));
|
|
275
275
|
state.prev = aggregateParallelOutputs(
|
|
@@ -53,7 +53,7 @@ export async function runParallelChainTasks(input: ParallelChainRunInput): Promi
|
|
|
53
53
|
return {
|
|
54
54
|
agent: task.agent,
|
|
55
55
|
task: input.parallelTemplates[taskIndex] ?? task.task ?? "{previous}",
|
|
56
|
-
|
|
56
|
+
status: "skipped",
|
|
57
57
|
messages: [],
|
|
58
58
|
usage: { input: 0, output: 0, cacheRead: 0, cacheWrite: 0, cost: 0, turns: 0 },
|
|
59
59
|
error: "Skipped after foreground group detached for intercom coordination",
|
|
@@ -63,7 +63,7 @@ export async function runParallelChainTasks(input: ParallelChainRunInput): Promi
|
|
|
63
63
|
return {
|
|
64
64
|
agent: task.agent,
|
|
65
65
|
task: "(skipped)",
|
|
66
|
-
|
|
66
|
+
status: "skipped",
|
|
67
67
|
messages: [],
|
|
68
68
|
usage: { input: 0, output: 0, cacheRead: 0, cacheWrite: 0, cost: 0, turns: 0 },
|
|
69
69
|
error: "Skipped due to fail-fast",
|
|
@@ -210,8 +210,8 @@ export async function runParallelChainTasks(input: ParallelChainRunInput): Promi
|
|
|
210
210
|
input.foregroundControl.updatedAt = Date.now();
|
|
211
211
|
}
|
|
212
212
|
|
|
213
|
-
if (result.
|
|
214
|
-
recordRun(task.agent, cleanTask, result.
|
|
213
|
+
if (result.status === "error" && failFast) aborted = true;
|
|
214
|
+
recordRun(task.agent, cleanTask, result.status, result.progressSummary?.durationMs ?? 0);
|
|
215
215
|
return result;
|
|
216
216
|
});
|
|
217
217
|
}
|
|
@@ -213,7 +213,7 @@ export async function runStaticParallelChainStep(input: {
|
|
|
213
213
|
|
|
214
214
|
const failures = parallelResults
|
|
215
215
|
.map((result, originalIndex) => ({ ...result, originalIndex }))
|
|
216
|
-
.filter((result) => result.
|
|
216
|
+
.filter((result) => result.status === "error");
|
|
217
217
|
if (failures.length > 0) {
|
|
218
218
|
const failureSummary = failures
|
|
219
219
|
.map((failure) => `- Task ${failure.originalIndex + 1} (${failure.agent}): ${failure.error || "failed"}`)
|
|
@@ -251,7 +251,7 @@ export async function runStaticParallelChainStep(input: {
|
|
|
251
251
|
agent: result.agent,
|
|
252
252
|
taskIndex: index,
|
|
253
253
|
output: getSingleResultOutput(result),
|
|
254
|
-
|
|
254
|
+
status: result.status,
|
|
255
255
|
error: result.error,
|
|
256
256
|
outputTargetPath,
|
|
257
257
|
outputTargetExists: outputTargetPath ? fs.existsSync(outputTargetPath) : undefined,
|
|
@@ -199,7 +199,7 @@ export async function runSequentialChainStep(input: {
|
|
|
199
199
|
context.foregroundControl.interrupt = undefined;
|
|
200
200
|
context.foregroundControl.updatedAt = Date.now();
|
|
201
201
|
}
|
|
202
|
-
recordRun(seqStep.agent, cleanTask, result.
|
|
202
|
+
recordRun(seqStep.agent, cleanTask, result.status, result.progressSummary?.durationMs ?? 0);
|
|
203
203
|
|
|
204
204
|
state.globalTaskIndex++;
|
|
205
205
|
state.results.push(result);
|
|
@@ -232,7 +232,7 @@ export async function runSequentialChainStep(input: {
|
|
|
232
232
|
),
|
|
233
233
|
};
|
|
234
234
|
}
|
|
235
|
-
if (result.
|
|
235
|
+
if (result.status !== "ok") {
|
|
236
236
|
const summary = buildChainSummary(context.chainSteps, state.results, context.chainDir, "failed", {
|
|
237
237
|
index: stepIndex,
|
|
238
238
|
error: result.error || "Chain failed",
|
|
@@ -1,281 +1 @@
|
|
|
1
|
-
|
|
2
|
-
import type { AgentConfig } from "../../agents/agents.ts";
|
|
3
|
-
import { buildSkillInjection, resolveSkillsWithFallback } from "../../agents/skills.ts";
|
|
4
|
-
import { ensureArtifactsDir, getArtifactPaths, writeArtifact, writeMetadata } from "../../shared/artifacts.ts";
|
|
5
|
-
import { getSubagentCodexFastModeSettings, resolveSubagentCodexFastModeScope } from "../../shared/fast-mode.ts";
|
|
6
|
-
import { resolveEffectiveThinking } from "../../shared/model-info.ts";
|
|
7
|
-
import {
|
|
8
|
-
type ArtifactPaths,
|
|
9
|
-
DEFAULT_MAX_OUTPUT,
|
|
10
|
-
type ModelAttempt,
|
|
11
|
-
type RunSyncOptions,
|
|
12
|
-
type SingleResult,
|
|
13
|
-
truncateOutput,
|
|
14
|
-
} from "../../shared/types.ts";
|
|
15
|
-
import { findLatestSessionFile } from "../../shared/utils.ts";
|
|
16
|
-
import { filterSpawnableModelCandidates } from "../shared/model-candidate-filter.ts";
|
|
17
|
-
import { buildModelCandidates, formatModelAttemptNote, isRetryableModelFailure } from "../shared/model-fallback.ts";
|
|
18
|
-
import { applyThinkingSuffix } from "../shared/pi-args.ts";
|
|
19
|
-
import { captureSingleOutputSnapshot, validateFileOnlyOutputMode } from "../shared/single-output.ts";
|
|
20
|
-
import { runSingleAttemptWithStructuredOutputRetries } from "./execution-structured-retries.ts";
|
|
21
|
-
import { shouldSuppressIntermediateRetryableFailureUpdate } from "./execution-updates.ts";
|
|
22
|
-
import { artifactOutputByResult, emptyUsage, modelFailureSignalByResult, sumUsage } from "./execution-utils.ts";
|
|
23
|
-
|
|
24
|
-
/**
|
|
25
|
-
* Run a subagent synchronously (blocking until complete)
|
|
26
|
-
*/
|
|
27
|
-
export async function runSync(
|
|
28
|
-
runtimeCwd: string,
|
|
29
|
-
agents: AgentConfig[],
|
|
30
|
-
agentName: string,
|
|
31
|
-
task: string,
|
|
32
|
-
options: RunSyncOptions,
|
|
33
|
-
): Promise<SingleResult> {
|
|
34
|
-
const agent = agents.find((a) => a.name === agentName);
|
|
35
|
-
if (!agent) {
|
|
36
|
-
return {
|
|
37
|
-
agent: agentName,
|
|
38
|
-
task,
|
|
39
|
-
exitCode: 1,
|
|
40
|
-
messages: [],
|
|
41
|
-
usage: emptyUsage(),
|
|
42
|
-
error: `Unknown agent: ${agentName}`,
|
|
43
|
-
};
|
|
44
|
-
}
|
|
45
|
-
const outputModeValidationError = validateFileOnlyOutputMode(
|
|
46
|
-
options.outputMode,
|
|
47
|
-
options.outputPath,
|
|
48
|
-
`Single run (${agentName})`,
|
|
49
|
-
);
|
|
50
|
-
if (outputModeValidationError) {
|
|
51
|
-
return {
|
|
52
|
-
agent: agentName,
|
|
53
|
-
task,
|
|
54
|
-
exitCode: 1,
|
|
55
|
-
messages: [],
|
|
56
|
-
usage: emptyUsage(),
|
|
57
|
-
outputMode: options.outputMode,
|
|
58
|
-
error: outputModeValidationError,
|
|
59
|
-
};
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
const shareEnabled = options.share === true;
|
|
63
|
-
const sessionEnabled = Boolean(options.sessionFile || options.sessionDir) || shareEnabled;
|
|
64
|
-
const skillNames = options.skills ?? agent.skills ?? [];
|
|
65
|
-
const skillCwd = options.cwd ?? runtimeCwd;
|
|
66
|
-
const { resolved: resolvedSkills, missing: missingSkills } = resolveSkillsWithFallback(
|
|
67
|
-
skillNames,
|
|
68
|
-
skillCwd,
|
|
69
|
-
runtimeCwd,
|
|
70
|
-
);
|
|
71
|
-
if (skillNames.some((skill) => skill.trim() === "subagent") && missingSkills.includes("subagent")) {
|
|
72
|
-
return {
|
|
73
|
-
agent: agentName,
|
|
74
|
-
task,
|
|
75
|
-
exitCode: 1,
|
|
76
|
-
messages: [],
|
|
77
|
-
usage: emptyUsage(),
|
|
78
|
-
error: "Skills not found: subagent",
|
|
79
|
-
};
|
|
80
|
-
}
|
|
81
|
-
let systemPrompt = agent.systemPrompt?.trim() || "";
|
|
82
|
-
if (resolvedSkills.length > 0) {
|
|
83
|
-
const skillInjection = buildSkillInjection(resolvedSkills);
|
|
84
|
-
systemPrompt = systemPrompt ? `${systemPrompt}\n\n${skillInjection}` : skillInjection;
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
const rawCandidates = buildModelCandidates(
|
|
88
|
-
options.modelOverride ?? agent.model,
|
|
89
|
-
agent.fallbackModels,
|
|
90
|
-
options.availableModels,
|
|
91
|
-
options.preferredModelProvider,
|
|
92
|
-
options.currentModel,
|
|
93
|
-
agent.fallbackThinkingLevels,
|
|
94
|
-
);
|
|
95
|
-
const filteredCandidates = filterSpawnableModelCandidates({
|
|
96
|
-
candidates: rawCandidates,
|
|
97
|
-
availableModels: options.availableModels,
|
|
98
|
-
knownModelProviders: options.knownModelProviders,
|
|
99
|
-
currentModel: options.currentModel,
|
|
100
|
-
});
|
|
101
|
-
const candidates = filteredCandidates.candidates;
|
|
102
|
-
const fastModeCwd = options.cwd ?? runtimeCwd;
|
|
103
|
-
const fastModeSettings = getSubagentCodexFastModeSettings(fastModeCwd);
|
|
104
|
-
const fastModeScope = resolveSubagentCodexFastModeScope(options.workflowStageSubagentGuard);
|
|
105
|
-
const attemptedModels: string[] = [];
|
|
106
|
-
const modelAttempts: ModelAttempt[] = [...filteredCandidates.skippedAttempts];
|
|
107
|
-
const aggregateUsage = emptyUsage();
|
|
108
|
-
const attemptNotes: string[] = filteredCandidates.skippedAttempts.map((attempt) => `[fallback] ${attempt.error}`);
|
|
109
|
-
const pendingAttemptNotes: string[] = [];
|
|
110
|
-
let totalToolCount = 0;
|
|
111
|
-
let totalDurationMs = 0;
|
|
112
|
-
|
|
113
|
-
let artifactPathsResult: ArtifactPaths | undefined;
|
|
114
|
-
let jsonlPath: string | undefined;
|
|
115
|
-
if (options.artifactsDir && options.artifactConfig?.enabled !== false) {
|
|
116
|
-
artifactPathsResult = getArtifactPaths(options.artifactsDir, options.runId, agentName, options.index);
|
|
117
|
-
ensureArtifactsDir(options.artifactsDir);
|
|
118
|
-
if (options.artifactConfig?.includeInput !== false) {
|
|
119
|
-
writeArtifact(artifactPathsResult.inputPath, `# Task for ${agentName}\n\n${task}`);
|
|
120
|
-
}
|
|
121
|
-
if (options.artifactConfig?.includeJsonl !== false) jsonlPath = artifactPathsResult.jsonlPath;
|
|
122
|
-
}
|
|
123
|
-
const persistArtifacts = (value: SingleResult): void => {
|
|
124
|
-
if (!artifactPathsResult || options.artifactConfig?.enabled === false) return;
|
|
125
|
-
value.artifactPaths = artifactPathsResult;
|
|
126
|
-
if (options.artifactConfig?.includeOutput !== false) {
|
|
127
|
-
writeArtifact(artifactPathsResult.outputPath, artifactOutputByResult.get(value) ?? value.finalOutput ?? "");
|
|
128
|
-
}
|
|
129
|
-
if (options.artifactConfig?.includeMetadata !== false) {
|
|
130
|
-
writeMetadata(artifactPathsResult.metadataPath, {
|
|
131
|
-
runId: options.runId,
|
|
132
|
-
agent: agentName,
|
|
133
|
-
task,
|
|
134
|
-
exitCode: value.exitCode,
|
|
135
|
-
usage: value.usage,
|
|
136
|
-
model: value.model,
|
|
137
|
-
fastMode: value.fastMode,
|
|
138
|
-
attemptedModels: value.attemptedModels,
|
|
139
|
-
modelAttempts: value.modelAttempts,
|
|
140
|
-
durationMs: value.progressSummary?.durationMs,
|
|
141
|
-
toolCount: value.progressSummary?.toolCount,
|
|
142
|
-
error: value.error,
|
|
143
|
-
skills: value.skills,
|
|
144
|
-
skillsWarning: value.skillsWarning,
|
|
145
|
-
timestamp: Date.now(),
|
|
146
|
-
});
|
|
147
|
-
}
|
|
148
|
-
};
|
|
149
|
-
|
|
150
|
-
let lastResult: SingleResult | undefined;
|
|
151
|
-
const modelsToTry = candidates.length > 0 ? candidates : rawCandidates.length === 0 ? [undefined] : [];
|
|
152
|
-
for (let i = 0; i < modelsToTry.length; i++) {
|
|
153
|
-
const candidate = modelsToTry[i];
|
|
154
|
-
if (candidate) attemptedModels.push(candidate);
|
|
155
|
-
const outputSnapshot = captureSingleOutputSnapshot(options.outputPath);
|
|
156
|
-
const detachedExit = options.onDetachedExit;
|
|
157
|
-
let attemptOptions: RunSyncOptions = {
|
|
158
|
-
...options,
|
|
159
|
-
onDetachedExit: (recovered) => {
|
|
160
|
-
recovered.attemptedModels = attemptedModels.length > 0 ? [...attemptedModels] : undefined;
|
|
161
|
-
const recoveredModel =
|
|
162
|
-
applyThinkingSuffix(candidate, agent.thinking) ?? recovered.model ?? agent.model ?? "default";
|
|
163
|
-
const completedAttempt: ModelAttempt = {
|
|
164
|
-
model: recoveredModel,
|
|
165
|
-
reasoningLevel: resolveEffectiveThinking(recoveredModel, agent.thinking),
|
|
166
|
-
success: recovered.exitCode === 0 && !recovered.error,
|
|
167
|
-
exitCode: recovered.exitCode,
|
|
168
|
-
error: recovered.error,
|
|
169
|
-
usage: { ...recovered.usage },
|
|
170
|
-
};
|
|
171
|
-
recovered.modelAttempts = [...modelAttempts.slice(0, -1), completedAttempt];
|
|
172
|
-
persistArtifacts(recovered);
|
|
173
|
-
detachedExit?.(recovered);
|
|
174
|
-
},
|
|
175
|
-
};
|
|
176
|
-
if (i < modelsToTry.length - 1 && options.onUpdate) {
|
|
177
|
-
const forwardUpdate = options.onUpdate;
|
|
178
|
-
attemptOptions = {
|
|
179
|
-
...attemptOptions,
|
|
180
|
-
onUpdate: (update) => {
|
|
181
|
-
if (shouldSuppressIntermediateRetryableFailureUpdate(update)) return;
|
|
182
|
-
forwardUpdate(update);
|
|
183
|
-
},
|
|
184
|
-
};
|
|
185
|
-
}
|
|
186
|
-
const result = await runSingleAttemptWithStructuredOutputRetries(
|
|
187
|
-
runtimeCwd,
|
|
188
|
-
agent,
|
|
189
|
-
task,
|
|
190
|
-
candidate,
|
|
191
|
-
attemptOptions,
|
|
192
|
-
{
|
|
193
|
-
sessionEnabled,
|
|
194
|
-
systemPrompt,
|
|
195
|
-
resolvedSkillNames: resolvedSkills.length > 0 ? resolvedSkills.map((skill) => skill.name) : undefined,
|
|
196
|
-
skillsWarning: missingSkills.length > 0 ? `Skills not found: ${missingSkills.join(", ")}` : undefined,
|
|
197
|
-
jsonlPath,
|
|
198
|
-
artifactPaths: artifactPathsResult,
|
|
199
|
-
attemptNotes,
|
|
200
|
-
outputSnapshot,
|
|
201
|
-
fastModeSettings,
|
|
202
|
-
fastModeScope,
|
|
203
|
-
originalTask: task,
|
|
204
|
-
},
|
|
205
|
-
);
|
|
206
|
-
lastResult = result;
|
|
207
|
-
sumUsage(aggregateUsage, result.usage);
|
|
208
|
-
totalToolCount += result.progressSummary?.toolCount ?? 0;
|
|
209
|
-
totalDurationMs += result.progressSummary?.durationMs ?? 0;
|
|
210
|
-
const attemptSucceeded = result.exitCode === 0 && !result.error;
|
|
211
|
-
const attemptModel = applyThinkingSuffix(candidate, agent.thinking) ?? result.model ?? agent.model ?? "default";
|
|
212
|
-
const attempt: ModelAttempt = {
|
|
213
|
-
model: attemptModel,
|
|
214
|
-
reasoningLevel: resolveEffectiveThinking(attemptModel, agent.thinking),
|
|
215
|
-
success: attemptSucceeded,
|
|
216
|
-
exitCode: result.exitCode,
|
|
217
|
-
error: result.error,
|
|
218
|
-
usage: { ...result.usage },
|
|
219
|
-
};
|
|
220
|
-
modelAttempts.push(attempt);
|
|
221
|
-
if (attemptSucceeded) break;
|
|
222
|
-
if (result.detached) break;
|
|
223
|
-
const retrySignal = modelFailureSignalByResult.get(result) ?? result.error;
|
|
224
|
-
if (isRetryableModelFailure(retrySignal) && i < modelsToTry.length - 1) {
|
|
225
|
-
pendingAttemptNotes.push(formatModelAttemptNote(attempt, modelsToTry[i + 1]));
|
|
226
|
-
continue;
|
|
227
|
-
}
|
|
228
|
-
attemptNotes.push(...pendingAttemptNotes);
|
|
229
|
-
break;
|
|
230
|
-
}
|
|
231
|
-
|
|
232
|
-
const result =
|
|
233
|
-
lastResult ??
|
|
234
|
-
({
|
|
235
|
-
agent: agentName,
|
|
236
|
-
task,
|
|
237
|
-
exitCode: 1,
|
|
238
|
-
messages: [],
|
|
239
|
-
usage: emptyUsage(),
|
|
240
|
-
error:
|
|
241
|
-
modelAttempts.length > 0
|
|
242
|
-
? "No spawnable subagent model candidates after pre-spawn filtering."
|
|
243
|
-
: "Subagent did not produce a result.",
|
|
244
|
-
} satisfies SingleResult);
|
|
245
|
-
|
|
246
|
-
result.usage = aggregateUsage;
|
|
247
|
-
result.attemptedModels = attemptedModels.length > 0 ? attemptedModels : undefined;
|
|
248
|
-
result.modelAttempts = modelAttempts.length > 0 ? modelAttempts : undefined;
|
|
249
|
-
result.progressSummary = {
|
|
250
|
-
toolCount: totalToolCount,
|
|
251
|
-
tokens: aggregateUsage.input + aggregateUsage.output,
|
|
252
|
-
durationMs: totalDurationMs,
|
|
253
|
-
};
|
|
254
|
-
if (attemptNotes.length > 0 && result.progress) {
|
|
255
|
-
result.progress.recentOutput = [...attemptNotes, ...result.progress.recentOutput];
|
|
256
|
-
if (result.progress.recentOutput.length > 50) result.progress.recentOutput.splice(50);
|
|
257
|
-
}
|
|
258
|
-
|
|
259
|
-
if (artifactPathsResult && options.artifactConfig?.enabled !== false && !result.detached) {
|
|
260
|
-
persistArtifacts(result);
|
|
261
|
-
|
|
262
|
-
if (options.maxOutput) {
|
|
263
|
-
const config = { ...DEFAULT_MAX_OUTPUT, ...options.maxOutput };
|
|
264
|
-
const truncationResult = truncateOutput(result.finalOutput ?? "", config, artifactPathsResult.outputPath);
|
|
265
|
-
if (truncationResult.truncated) result.truncation = truncationResult;
|
|
266
|
-
}
|
|
267
|
-
} else if (options.maxOutput) {
|
|
268
|
-
const config = { ...DEFAULT_MAX_OUTPUT, ...options.maxOutput };
|
|
269
|
-
const truncationResult = truncateOutput(result.finalOutput ?? "", config);
|
|
270
|
-
if (truncationResult.truncated) result.truncation = truncationResult;
|
|
271
|
-
}
|
|
272
|
-
|
|
273
|
-
if (options.sessionFile && (existsSync(options.sessionFile) || result.messages?.length)) {
|
|
274
|
-
result.sessionFile = options.sessionFile;
|
|
275
|
-
} else if (shareEnabled && options.sessionDir) {
|
|
276
|
-
const sessionFile = findLatestSessionFile(options.sessionDir);
|
|
277
|
-
if (sessionFile) result.sessionFile = sessionFile;
|
|
278
|
-
}
|
|
279
|
-
|
|
280
|
-
return result;
|
|
281
|
-
}
|
|
1
|
+
export { runSingleInProcess, runSync } from "./inprocess-run-sync.ts";
|
|
@@ -1,83 +1,19 @@
|
|
|
1
|
-
import type { AgentConfig } from "../../agents/
|
|
1
|
+
import type { AgentConfig } from "../../agents/agent-types.ts";
|
|
2
2
|
import type { RunSyncOptions, SingleResult } from "../../shared/types.ts";
|
|
3
|
-
import {
|
|
4
|
-
formatStructuredOutputCorrectionPrompt,
|
|
5
|
-
isStructuredOutputContractError,
|
|
6
|
-
latestStructuredOutputToolErrorFromMessages,
|
|
7
|
-
STRUCTURED_OUTPUT_MAX_CORRECTIVE_PROMPTS,
|
|
8
|
-
} from "../shared/structured-output.ts";
|
|
9
|
-
import { runSingleAttempt } from "./execution-attempt.ts";
|
|
10
|
-
import type { RunSingleAttemptShared } from "./execution-attempt-types.ts";
|
|
11
|
-
import { type RunSyncUpdate, shouldSuppressIntermediateStructuredOutputFailureUpdate } from "./execution-updates.ts";
|
|
12
|
-
import { emptyUsage, sumUsage } from "./execution-utils.ts";
|
|
3
|
+
import { runSingleInProcess } from "./inprocess-run-sync.ts";
|
|
13
4
|
|
|
14
|
-
|
|
5
|
+
/**
|
|
6
|
+
* Kept as the local foreground seam while callers migrate to the in-process door.
|
|
7
|
+
* Structured output correction is handled by the SDK custom-tool policy in the
|
|
8
|
+
* new runner; no process retry or stdout parser remains here.
|
|
9
|
+
*/
|
|
10
|
+
export function runSingleAttemptWithStructuredOutputRetries(
|
|
15
11
|
runtimeCwd: string,
|
|
16
12
|
agent: AgentConfig,
|
|
17
13
|
task: string,
|
|
18
|
-
|
|
14
|
+
_model: string | undefined,
|
|
19
15
|
options: RunSyncOptions,
|
|
20
|
-
|
|
16
|
+
_shared: object,
|
|
21
17
|
): Promise<SingleResult> {
|
|
22
|
-
|
|
23
|
-
let correctiveAttempts = 0;
|
|
24
|
-
let finalResult: SingleResult | undefined;
|
|
25
|
-
const aggregateUsage = emptyUsage();
|
|
26
|
-
let totalToolCount = 0;
|
|
27
|
-
let totalDurationMs = 0;
|
|
28
|
-
|
|
29
|
-
while (true) {
|
|
30
|
-
const suppressIntermediateStructuredOutputFailure =
|
|
31
|
-
options.structuredOutput !== undefined &&
|
|
32
|
-
correctiveAttempts < STRUCTURED_OUTPUT_MAX_CORRECTIVE_PROMPTS &&
|
|
33
|
-
options.onUpdate !== undefined;
|
|
34
|
-
const attemptOptions = suppressIntermediateStructuredOutputFailure
|
|
35
|
-
? {
|
|
36
|
-
...options,
|
|
37
|
-
onUpdate: (update: RunSyncUpdate) => {
|
|
38
|
-
if (shouldSuppressIntermediateStructuredOutputFailureUpdate(update)) return;
|
|
39
|
-
options.onUpdate?.(update);
|
|
40
|
-
},
|
|
41
|
-
}
|
|
42
|
-
: options;
|
|
43
|
-
const result = await runSingleAttempt(runtimeCwd, agent, nextTask, model, attemptOptions, shared);
|
|
44
|
-
finalResult = result;
|
|
45
|
-
sumUsage(aggregateUsage, result.usage);
|
|
46
|
-
totalToolCount += result.progressSummary?.toolCount ?? 0;
|
|
47
|
-
totalDurationMs += result.progressSummary?.durationMs ?? 0;
|
|
48
|
-
|
|
49
|
-
if (!options.structuredOutput || !isStructuredOutputContractError(result.error)) break;
|
|
50
|
-
const correctionError =
|
|
51
|
-
latestStructuredOutputToolErrorFromMessages(result.messages) ??
|
|
52
|
-
result.error ??
|
|
53
|
-
"Structured output contract failed.";
|
|
54
|
-
if (correctiveAttempts >= STRUCTURED_OUTPUT_MAX_CORRECTIVE_PROMPTS) {
|
|
55
|
-
result.error = correctionError;
|
|
56
|
-
break;
|
|
57
|
-
}
|
|
58
|
-
correctiveAttempts += 1;
|
|
59
|
-
nextTask = formatStructuredOutputCorrectionPrompt({
|
|
60
|
-
originalTask: task,
|
|
61
|
-
error: correctionError,
|
|
62
|
-
attempt: correctiveAttempts,
|
|
63
|
-
});
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
const result =
|
|
67
|
-
finalResult ??
|
|
68
|
-
({
|
|
69
|
-
agent: agent.name,
|
|
70
|
-
task,
|
|
71
|
-
exitCode: 1,
|
|
72
|
-
messages: [],
|
|
73
|
-
usage: emptyUsage(),
|
|
74
|
-
error: "Subagent did not produce a result.",
|
|
75
|
-
} satisfies SingleResult);
|
|
76
|
-
result.usage = aggregateUsage;
|
|
77
|
-
result.progressSummary = {
|
|
78
|
-
toolCount: totalToolCount,
|
|
79
|
-
tokens: aggregateUsage.input + aggregateUsage.output,
|
|
80
|
-
durationMs: totalDurationMs,
|
|
81
|
-
};
|
|
82
|
-
return result;
|
|
18
|
+
return runSingleInProcess(runtimeCwd, agent, task, options);
|
|
83
19
|
}
|