@duckmind/dm-darwin-x64 0.43.2 → 0.43.8
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/dm +0 -0
- package/extensions/.dm-extensions.json +242 -49
- package/extensions/dm-9router-ext/package.json +2 -19
- package/extensions/dm-9router-ext/src/index.js +5 -0
- package/extensions/dm-ask-user/index.js +10 -0
- package/extensions/dm-ask-user/package.json +1 -21
- package/extensions/dm-cli-anything/package.json +0 -6
- package/extensions/dm-context/package.json +2 -12
- package/extensions/dm-context/src/context.js +1 -0
- package/extensions/dm-context/src/index.js +7 -0
- package/extensions/dm-context/src/utils.js +1 -0
- package/extensions/dm-cua/package.json +0 -7
- package/extensions/dm-fff/package.json +1 -28
- package/extensions/dm-fff/src/index.js +15 -0
- package/extensions/dm-fff/src/query.js +1 -0
- package/extensions/dm-goal/package.json +2 -31
- package/extensions/dm-goal/src/goal.js +43 -0
- package/extensions/dm-grill-me/index.js +174 -0
- package/extensions/dm-grill-me/package.json +1 -26
- package/extensions/dm-image2/package.json +0 -7
- package/extensions/dm-subagents/package.json +1 -32
- package/extensions/dm-subagents/src/agents/agent-management.js +37 -0
- package/extensions/dm-subagents/src/agents/agent-memory.js +6 -0
- package/extensions/dm-subagents/src/agents/agent-scope.js +1 -0
- package/extensions/dm-subagents/src/agents/agent-selection.js +1 -0
- package/extensions/dm-subagents/src/agents/agent-serializer.js +7 -0
- package/extensions/dm-subagents/src/agents/agents.js +11 -0
- package/extensions/dm-subagents/src/agents/chain-serializer.js +12 -0
- package/extensions/dm-subagents/src/agents/frontmatter.js +6 -0
- package/extensions/dm-subagents/src/agents/identity.js +1 -0
- package/extensions/dm-subagents/src/agents/proactive-skills.js +1 -0
- package/extensions/dm-subagents/src/agents/skills.js +6 -0
- package/extensions/dm-subagents/src/extension/config.js +2 -0
- package/extensions/dm-subagents/src/extension/control-notices.js +4 -0
- package/extensions/dm-subagents/src/extension/doctor.js +16 -0
- package/extensions/dm-subagents/src/extension/fanout-child.js +231 -0
- package/extensions/dm-subagents/src/extension/index.js +367 -0
- package/extensions/dm-subagents/src/extension/rpc.js +8 -0
- package/extensions/dm-subagents/src/extension/schemas.js +1 -0
- package/extensions/dm-subagents/src/extension/{tool-description.ts → tool-description.js} +6 -126
- package/extensions/dm-subagents/src/intercom/intercom-bridge.js +13 -0
- package/extensions/dm-subagents/src/intercom/native-supervisor-channel.js +5 -0
- package/extensions/dm-subagents/src/intercom/result-intercom.js +3 -0
- package/extensions/dm-subagents/src/profiles/profiles.js +3 -0
- package/extensions/dm-subagents/src/runs/background/async-execution.js +46 -0
- package/extensions/dm-subagents/src/runs/background/async-job-tracker.js +14 -0
- package/extensions/dm-subagents/src/runs/background/async-resume.js +8 -0
- package/extensions/dm-subagents/src/runs/background/async-status.js +12 -0
- package/extensions/dm-subagents/src/runs/background/chain-append.js +2 -0
- package/extensions/dm-subagents/src/runs/background/chain-root-attachment.js +1 -0
- package/extensions/dm-subagents/src/runs/background/completion-batcher.js +1 -0
- package/extensions/dm-subagents/src/runs/background/completion-dedupe.js +1 -0
- package/extensions/dm-subagents/src/runs/background/control-channel.js +1 -0
- package/extensions/dm-subagents/src/runs/background/fleet-view.js +17 -0
- package/extensions/dm-subagents/src/runs/background/notify.js +3 -0
- package/extensions/dm-subagents/src/runs/background/parallel-groups.js +1 -0
- package/extensions/dm-subagents/src/runs/background/result-watcher.js +8 -0
- package/extensions/dm-subagents/src/runs/background/run-id-resolver.js +4 -0
- package/extensions/dm-subagents/src/runs/background/run-status.js +23 -0
- package/extensions/dm-subagents/src/runs/background/scheduled-runs.js +4 -0
- package/extensions/dm-subagents/src/runs/background/stale-run-reconciler.js +11 -0
- package/extensions/dm-subagents/src/runs/background/subagent-runner.js +78 -0
- package/extensions/dm-subagents/src/runs/background/top-level-async.js +1 -0
- package/extensions/dm-subagents/src/runs/background/wait.js +11 -0
- package/extensions/dm-subagents/src/runs/foreground/chain-clarify.js +12 -0
- package/extensions/dm-subagents/src/runs/foreground/chain-execution.js +102 -0
- package/extensions/dm-subagents/src/runs/foreground/execution.js +51 -0
- package/extensions/dm-subagents/src/runs/foreground/subagent-executor.js +228 -0
- package/extensions/dm-subagents/src/runs/shared/acceptance.js +3 -0
- package/extensions/dm-subagents/src/runs/shared/chain-outputs.js +1 -0
- package/extensions/dm-subagents/src/runs/shared/completion-guard.js +3 -0
- package/extensions/dm-subagents/src/runs/shared/dm-args.js +1 -0
- package/extensions/dm-subagents/src/runs/shared/dm-spawn.js +1 -0
- package/extensions/dm-subagents/src/runs/shared/dynamic-fanout.js +1 -0
- package/extensions/dm-subagents/src/runs/shared/long-running-guard.js +1 -0
- package/extensions/dm-subagents/src/runs/shared/mcp-direct-tool-allowlist.js +1 -0
- package/extensions/dm-subagents/src/runs/shared/model-fallback.js +1 -0
- package/extensions/dm-subagents/src/runs/shared/model-scope.js +1 -0
- package/extensions/dm-subagents/src/runs/shared/nested-events.js +8 -0
- package/extensions/dm-subagents/src/runs/shared/nested-path.js +1 -0
- package/extensions/dm-subagents/src/runs/shared/nested-render.js +1 -0
- package/extensions/dm-subagents/src/runs/shared/parallel-utils.js +5 -0
- package/extensions/dm-subagents/src/runs/shared/run-history.js +5 -0
- package/extensions/dm-subagents/src/runs/shared/single-output.js +14 -0
- package/extensions/dm-subagents/src/runs/shared/structured-output.js +1 -0
- package/extensions/dm-subagents/src/runs/shared/subagent-control.js +5 -0
- package/extensions/dm-subagents/src/runs/shared/subagent-prompt-runtime.js +22 -0
- package/extensions/dm-subagents/src/runs/shared/tool-budget.js +1 -0
- package/extensions/dm-subagents/src/runs/shared/turn-budget.js +7 -0
- package/extensions/dm-subagents/src/runs/shared/workflow-graph.js +1 -0
- package/extensions/dm-subagents/src/runs/shared/worktree.js +3 -0
- package/extensions/dm-subagents/src/shared/artifacts.js +2 -0
- package/extensions/dm-subagents/src/shared/atomic-json.js +1 -0
- package/extensions/dm-subagents/src/shared/child-transcript.js +5 -0
- package/extensions/dm-subagents/src/shared/file-coalescer.js +1 -0
- package/extensions/dm-subagents/src/shared/fork-context.js +6 -0
- package/extensions/dm-subagents/src/shared/formatters.js +9 -0
- package/extensions/dm-subagents/src/shared/jsonl-writer.js +2 -0
- package/extensions/dm-subagents/src/shared/model-info.js +1 -0
- package/extensions/dm-subagents/src/shared/post-exit-stdio-guard.js +1 -0
- package/extensions/dm-subagents/src/shared/session-identity.js +1 -0
- package/extensions/dm-subagents/src/shared/session-tokens.js +2 -0
- package/extensions/dm-subagents/src/shared/settings.js +23 -0
- package/extensions/dm-subagents/src/shared/status-format.js +1 -0
- package/extensions/dm-subagents/src/shared/types.js +8 -0
- package/extensions/dm-subagents/src/shared/utils.js +2 -0
- package/extensions/dm-subagents/src/slash/prompt-template-bridge.js +1 -0
- package/extensions/dm-subagents/src/slash/prompt-workflows.js +7 -0
- package/extensions/dm-subagents/src/slash/slash-bridge.js +1 -0
- package/extensions/dm-subagents/src/slash/slash-commands.js +38 -0
- package/extensions/dm-subagents/src/slash/slash-live-state.js +6 -0
- package/extensions/dm-subagents/src/tui/render-helpers.js +1 -0
- package/extensions/dm-subagents/src/tui/render.js +4 -0
- package/extensions/dm-tasks/package.json +1 -30
- package/extensions/dm-tasks/src/auto-clear.js +1 -0
- package/extensions/dm-tasks/src/index.js +212 -0
- package/extensions/dm-tasks/src/process-tracker.js +1 -0
- package/extensions/dm-tasks/src/task-store.js +1 -0
- package/extensions/dm-tasks/src/tasks-config.js +1 -0
- package/extensions/dm-tasks/src/types.js +0 -0
- package/extensions/dm-tasks/src/ui/settings-menu.js +1 -0
- package/extensions/dm-tasks/src/ui/task-widget.js +1 -0
- package/extensions/dm-usage/index.js +9 -0
- package/extensions/dm-usage/package.json +1 -18
- package/extensions/greedysearch-dm/bin/search.mjs +135 -135
- package/extensions/greedysearch-dm/index.js +20 -0
- package/extensions/greedysearch-dm/package.json +1 -22
- package/extensions/greedysearch-dm/src/formatters/results.js +8 -0
- package/extensions/greedysearch-dm/src/formatters/sources.js +1 -0
- package/extensions/greedysearch-dm/src/formatters/synthesis.js +1 -0
- package/extensions/greedysearch-dm/src/search/engines.mjs +9 -9
- package/extensions/greedysearch-dm/src/search/paths.mjs +1 -0
- package/extensions/greedysearch-dm/src/search/research.mjs +100 -100
- package/extensions/greedysearch-dm/src/search/synthesis-runner.mjs +10 -10
- package/extensions/greedysearch-dm/src/tools/greedy-search-handler.js +20 -0
- package/extensions/greedysearch-dm/src/tools/shared.js +9 -0
- package/extensions/greedysearch-dm/src/types.js +0 -0
- package/extensions/greedysearch-dm/src/utils/helpers.js +1 -0
- package/package.json +1 -1
- package/extensions/dm-9router-ext/src/index.ts +0 -541
- package/extensions/dm-ask-user/index.ts +0 -857
- package/extensions/dm-context/src/context.ts +0 -158
- package/extensions/dm-context/src/index.ts +0 -439
- package/extensions/dm-context/src/utils.ts +0 -6
- package/extensions/dm-fff/src/index.ts +0 -1023
- package/extensions/dm-fff/src/query.ts +0 -87
- package/extensions/dm-goal/src/goal.ts +0 -1073
- package/extensions/dm-grill-me/index.ts +0 -1085
- package/extensions/dm-subagents/src/agents/agent-management.ts +0 -1052
- package/extensions/dm-subagents/src/agents/agent-memory.ts +0 -254
- package/extensions/dm-subagents/src/agents/agent-scope.ts +0 -6
- package/extensions/dm-subagents/src/agents/agent-selection.ts +0 -25
- package/extensions/dm-subagents/src/agents/agent-serializer.ts +0 -121
- package/extensions/dm-subagents/src/agents/agents.ts +0 -1553
- package/extensions/dm-subagents/src/agents/chain-serializer.ts +0 -277
- package/extensions/dm-subagents/src/agents/frontmatter.ts +0 -93
- package/extensions/dm-subagents/src/agents/identity.ts +0 -30
- package/extensions/dm-subagents/src/agents/proactive-skills.ts +0 -191
- package/extensions/dm-subagents/src/agents/skills.ts +0 -729
- package/extensions/dm-subagents/src/extension/config.ts +0 -39
- package/extensions/dm-subagents/src/extension/control-notices.ts +0 -92
- package/extensions/dm-subagents/src/extension/doctor.ts +0 -214
- package/extensions/dm-subagents/src/extension/fanout-child.ts +0 -172
- package/extensions/dm-subagents/src/extension/index.ts +0 -656
- package/extensions/dm-subagents/src/extension/rpc.ts +0 -369
- package/extensions/dm-subagents/src/extension/schemas.ts +0 -309
- package/extensions/dm-subagents/src/intercom/intercom-bridge.ts +0 -180
- package/extensions/dm-subagents/src/intercom/native-supervisor-channel.ts +0 -519
- package/extensions/dm-subagents/src/intercom/result-intercom.ts +0 -377
- package/extensions/dm-subagents/src/profiles/profiles.ts +0 -637
- package/extensions/dm-subagents/src/runs/background/async-execution.ts +0 -1065
- package/extensions/dm-subagents/src/runs/background/async-job-tracker.ts +0 -441
- package/extensions/dm-subagents/src/runs/background/async-resume.ts +0 -391
- package/extensions/dm-subagents/src/runs/background/async-status.ts +0 -395
- package/extensions/dm-subagents/src/runs/background/chain-append.ts +0 -282
- package/extensions/dm-subagents/src/runs/background/chain-root-attachment.ts +0 -191
- package/extensions/dm-subagents/src/runs/background/completion-batcher.ts +0 -166
- package/extensions/dm-subagents/src/runs/background/completion-dedupe.ts +0 -63
- package/extensions/dm-subagents/src/runs/background/control-channel.ts +0 -332
- package/extensions/dm-subagents/src/runs/background/fleet-view.ts +0 -515
- package/extensions/dm-subagents/src/runs/background/notify.ts +0 -225
- package/extensions/dm-subagents/src/runs/background/parallel-groups.ts +0 -45
- package/extensions/dm-subagents/src/runs/background/result-watcher.ts +0 -315
- package/extensions/dm-subagents/src/runs/background/run-id-resolver.ts +0 -84
- package/extensions/dm-subagents/src/runs/background/run-status.ts +0 -434
- package/extensions/dm-subagents/src/runs/background/scheduled-runs.ts +0 -514
- package/extensions/dm-subagents/src/runs/background/stale-run-reconciler.ts +0 -368
- package/extensions/dm-subagents/src/runs/background/subagent-runner.ts +0 -3171
- package/extensions/dm-subagents/src/runs/background/top-level-async.ts +0 -13
- package/extensions/dm-subagents/src/runs/background/wait.ts +0 -353
- package/extensions/dm-subagents/src/runs/foreground/chain-clarify.ts +0 -1333
- package/extensions/dm-subagents/src/runs/foreground/chain-execution.ts +0 -1313
- package/extensions/dm-subagents/src/runs/foreground/execution.ts +0 -1239
- package/extensions/dm-subagents/src/runs/foreground/subagent-executor.ts +0 -3613
- package/extensions/dm-subagents/src/runs/shared/acceptance.ts +0 -879
- package/extensions/dm-subagents/src/runs/shared/chain-outputs.ts +0 -116
- package/extensions/dm-subagents/src/runs/shared/completion-guard.ts +0 -147
- package/extensions/dm-subagents/src/runs/shared/dm-args.ts +0 -271
- package/extensions/dm-subagents/src/runs/shared/dm-spawn.ts +0 -147
- package/extensions/dm-subagents/src/runs/shared/dynamic-fanout.ts +0 -295
- package/extensions/dm-subagents/src/runs/shared/long-running-guard.ts +0 -175
- package/extensions/dm-subagents/src/runs/shared/mcp-direct-tool-allowlist.ts +0 -365
- package/extensions/dm-subagents/src/runs/shared/model-fallback.ts +0 -292
- package/extensions/dm-subagents/src/runs/shared/model-scope.ts +0 -128
- package/extensions/dm-subagents/src/runs/shared/nested-events.ts +0 -908
- package/extensions/dm-subagents/src/runs/shared/nested-path.ts +0 -52
- package/extensions/dm-subagents/src/runs/shared/nested-render.ts +0 -115
- package/extensions/dm-subagents/src/runs/shared/parallel-utils.ts +0 -198
- package/extensions/dm-subagents/src/runs/shared/run-history.ts +0 -60
- package/extensions/dm-subagents/src/runs/shared/single-output.ts +0 -180
- package/extensions/dm-subagents/src/runs/shared/structured-output.ts +0 -77
- package/extensions/dm-subagents/src/runs/shared/subagent-control.ts +0 -223
- package/extensions/dm-subagents/src/runs/shared/subagent-prompt-runtime.ts +0 -342
- package/extensions/dm-subagents/src/runs/shared/tool-budget.ts +0 -74
- package/extensions/dm-subagents/src/runs/shared/turn-budget.ts +0 -52
- package/extensions/dm-subagents/src/runs/shared/workflow-graph.ts +0 -206
- package/extensions/dm-subagents/src/runs/shared/worktree.ts +0 -600
- package/extensions/dm-subagents/src/shared/artifacts.ts +0 -113
- package/extensions/dm-subagents/src/shared/atomic-json.ts +0 -86
- package/extensions/dm-subagents/src/shared/child-transcript.ts +0 -212
- package/extensions/dm-subagents/src/shared/file-coalescer.ts +0 -40
- package/extensions/dm-subagents/src/shared/fork-context.ts +0 -194
- package/extensions/dm-subagents/src/shared/formatters.ts +0 -133
- package/extensions/dm-subagents/src/shared/jsonl-writer.ts +0 -81
- package/extensions/dm-subagents/src/shared/model-info.ts +0 -78
- package/extensions/dm-subagents/src/shared/post-exit-stdio-guard.ts +0 -85
- package/extensions/dm-subagents/src/shared/session-identity.ts +0 -10
- package/extensions/dm-subagents/src/shared/session-tokens.ts +0 -44
- package/extensions/dm-subagents/src/shared/settings.ts +0 -450
- package/extensions/dm-subagents/src/shared/status-format.ts +0 -49
- package/extensions/dm-subagents/src/shared/types.ts +0 -1257
- package/extensions/dm-subagents/src/shared/utils.ts +0 -554
- package/extensions/dm-subagents/src/slash/prompt-template-bridge.ts +0 -420
- package/extensions/dm-subagents/src/slash/prompt-workflows.ts +0 -330
- package/extensions/dm-subagents/src/slash/slash-bridge.ts +0 -176
- package/extensions/dm-subagents/src/slash/slash-commands.ts +0 -1296
- package/extensions/dm-subagents/src/slash/slash-live-state.ts +0 -292
- package/extensions/dm-subagents/src/tui/render-helpers.ts +0 -80
- package/extensions/dm-subagents/src/tui/render.ts +0 -1748
- package/extensions/dm-tasks/src/auto-clear.ts +0 -91
- package/extensions/dm-tasks/src/index.ts +0 -1145
- package/extensions/dm-tasks/src/process-tracker.ts +0 -140
- package/extensions/dm-tasks/src/task-store.ts +0 -305
- package/extensions/dm-tasks/src/tasks-config.ts +0 -23
- package/extensions/dm-tasks/src/types.ts +0 -40
- package/extensions/dm-tasks/src/ui/settings-menu.ts +0 -100
- package/extensions/dm-tasks/src/ui/task-widget.ts +0 -265
- package/extensions/dm-usage/index.ts +0 -1718
- package/extensions/greedysearch-dm/index.ts +0 -177
- package/extensions/greedysearch-dm/src/formatters/results.ts +0 -163
- package/extensions/greedysearch-dm/src/formatters/sources.ts +0 -116
- package/extensions/greedysearch-dm/src/formatters/synthesis.ts +0 -87
- package/extensions/greedysearch-dm/src/tools/greedy-search-handler.ts +0 -370
- package/extensions/greedysearch-dm/src/tools/shared.ts +0 -187
- package/extensions/greedysearch-dm/src/types.ts +0 -110
- package/extensions/greedysearch-dm/src/utils/helpers.ts +0 -40
|
@@ -1,1313 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Chain execution logic for subagent tool
|
|
3
|
-
*/
|
|
4
|
-
|
|
5
|
-
import * as fs from "node:fs";
|
|
6
|
-
import * as path from "node:path";
|
|
7
|
-
import type { AgentToolResult } from "@duckmind/dm-agent-core";
|
|
8
|
-
import type { ExtensionContext } from "@duckmind/dm-coding-agent";
|
|
9
|
-
import type { AgentConfig } from "../../agents/agents.ts";
|
|
10
|
-
import { ChainClarifyComponent, type ChainClarifyResult, type BehaviorOverride } from "./chain-clarify.ts";
|
|
11
|
-
import { toModelInfo, type ModelInfo } from "../../shared/model-info.ts";
|
|
12
|
-
import {
|
|
13
|
-
resolveChainTemplates,
|
|
14
|
-
createChainDir,
|
|
15
|
-
removeChainDir,
|
|
16
|
-
resolveStepBehavior,
|
|
17
|
-
resolveParallelBehaviors,
|
|
18
|
-
buildChainInstructions,
|
|
19
|
-
writeInitialProgressFile,
|
|
20
|
-
createParallelDirs,
|
|
21
|
-
suppressProgressForReadOnlyTask,
|
|
22
|
-
aggregateParallelOutputs,
|
|
23
|
-
isDynamicParallelStep,
|
|
24
|
-
isParallelStep,
|
|
25
|
-
type StepOverrides,
|
|
26
|
-
type ChainStep,
|
|
27
|
-
type ParallelStep,
|
|
28
|
-
type SequentialStep,
|
|
29
|
-
type ParallelTaskResult,
|
|
30
|
-
type ResolvedStepBehavior,
|
|
31
|
-
type ResolvedTemplates,
|
|
32
|
-
} from "../../shared/settings.ts";
|
|
33
|
-
import { discoverAvailableSkills, normalizeSkillInput } from "../../agents/skills.ts";
|
|
34
|
-
import { INTERCOM_BRIDGE_MARKER } from "../../intercom/intercom-bridge.ts";
|
|
35
|
-
import { runSync } from "./execution.ts";
|
|
36
|
-
import { buildChainSummary } from "../../shared/formatters.ts";
|
|
37
|
-
import { compactForegroundDetails, getSingleResultOutput, mapConcurrent, resolveChildCwd, sumResultsCost, sumResultsUsage } from "../../shared/utils.ts";
|
|
38
|
-
import { DEFAULT_GLOBAL_CONCURRENCY_LIMIT, Semaphore } from "../shared/parallel-utils.ts";
|
|
39
|
-
import { recordRun } from "../shared/run-history.ts";
|
|
40
|
-
import {
|
|
41
|
-
cleanupWorktrees,
|
|
42
|
-
createWorktrees,
|
|
43
|
-
diffWorktrees,
|
|
44
|
-
findWorktreeTaskCwdConflict,
|
|
45
|
-
formatWorktreeDiffSummary,
|
|
46
|
-
formatWorktreeTaskCwdConflict,
|
|
47
|
-
type WorktreeSetup,
|
|
48
|
-
} from "../shared/worktree.ts";
|
|
49
|
-
import {
|
|
50
|
-
type ActivityState,
|
|
51
|
-
type AgentProgress,
|
|
52
|
-
type ArtifactConfig,
|
|
53
|
-
type ArtifactPaths,
|
|
54
|
-
type ControlEvent,
|
|
55
|
-
type Details,
|
|
56
|
-
type IntercomEventBus,
|
|
57
|
-
type NestedRouteInfo,
|
|
58
|
-
type ResolvedControlConfig,
|
|
59
|
-
type ResolvedTurnBudget,
|
|
60
|
-
type ResolvedToolBudget,
|
|
61
|
-
type SingleResult,
|
|
62
|
-
type ToolBudgetConfig,
|
|
63
|
-
MAX_CONCURRENCY,
|
|
64
|
-
resolveChildMaxSubagentDepth,
|
|
65
|
-
} from "../../shared/types.ts";
|
|
66
|
-
import { resolveSubagentModelOverride } from "../shared/model-fallback.ts";
|
|
67
|
-
import type { ModelScopeConfig } from "../shared/model-scope.ts";
|
|
68
|
-
import { validateFileOnlyOutputMode } from "../shared/single-output.ts";
|
|
69
|
-
import { buildWorkflowGraphSnapshot } from "../shared/workflow-graph.ts";
|
|
70
|
-
import { ChainOutputValidationError, outputEntryFromResult, resolveOutputReferences, validateChainOutputBindings } from "../shared/chain-outputs.ts";
|
|
71
|
-
import { createStructuredOutputRuntime } from "../shared/structured-output.ts";
|
|
72
|
-
import { collectDynamicResults, DynamicFanoutError, materializeDynamicParallelStep, validateDynamicCollection, type DynamicCollectedResult } from "../shared/dynamic-fanout.ts";
|
|
73
|
-
import { acceptanceFailureMessage, aggregateAcceptanceReport, evaluateAcceptance, resolveEffectiveAcceptance } from "../shared/acceptance.ts";
|
|
74
|
-
import type { ChainOutputMap } from "../../shared/types.ts";
|
|
75
|
-
import { validateToolBudgetConfig } from "../shared/tool-budget.ts";
|
|
76
|
-
|
|
77
|
-
interface ChainExecutionDetailsInput {
|
|
78
|
-
results: SingleResult[];
|
|
79
|
-
includeProgress?: boolean;
|
|
80
|
-
allProgress: AgentProgress[];
|
|
81
|
-
allArtifactPaths: ArtifactPaths[];
|
|
82
|
-
artifactsDir: string;
|
|
83
|
-
chainAgents: string[];
|
|
84
|
-
chainSteps: ChainStep[];
|
|
85
|
-
totalSteps: number;
|
|
86
|
-
currentStepIndex?: number;
|
|
87
|
-
runId: string;
|
|
88
|
-
outputs?: ChainOutputMap;
|
|
89
|
-
currentFlatIndex?: number;
|
|
90
|
-
dynamicChildren?: Record<number, Array<{ agent: string; label?: string; flatIndex: number; itemKey: string; outputName?: string; structured?: boolean; error?: string }>>;
|
|
91
|
-
dynamicGroupStatuses?: Record<number, { status: "pending" | "running" | "completed" | "failed" | "paused" | "detached"; error?: string; acceptance?: SingleResult["acceptance"] }>;
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
interface ParallelChainRunInput {
|
|
95
|
-
step: ParallelStep;
|
|
96
|
-
parallelTemplates: string[];
|
|
97
|
-
parallelBehaviors: ResolvedStepBehavior[];
|
|
98
|
-
agents: AgentConfig[];
|
|
99
|
-
stepIndex: number;
|
|
100
|
-
availableModels: ModelInfo[];
|
|
101
|
-
modelScope?: ModelScopeConfig;
|
|
102
|
-
chainDir: string;
|
|
103
|
-
prev: string;
|
|
104
|
-
originalTask: string;
|
|
105
|
-
ctx: ExtensionContext;
|
|
106
|
-
intercomEvents?: IntercomEventBus;
|
|
107
|
-
cwd?: string;
|
|
108
|
-
runId: string;
|
|
109
|
-
globalTaskIndex: number;
|
|
110
|
-
sessionDirForIndex: (idx?: number) => string | undefined;
|
|
111
|
-
sessionFileForIndex?: (idx?: number) => string | undefined;
|
|
112
|
-
sessionFileForTask?: (agentName: string, idx?: number) => string | undefined;
|
|
113
|
-
thinkingOverrideForTask?: (agentName: string, idx?: number) => AgentConfig["thinking"] | undefined;
|
|
114
|
-
shareEnabled: boolean;
|
|
115
|
-
artifactConfig: ArtifactConfig;
|
|
116
|
-
artifactsDir: string;
|
|
117
|
-
signal?: AbortSignal;
|
|
118
|
-
onUpdate?: (r: AgentToolResult<Details>) => void;
|
|
119
|
-
onControlEvent?: (event: ControlEvent) => void;
|
|
120
|
-
controlConfig: ResolvedControlConfig;
|
|
121
|
-
childIntercomTarget?: (agent: string, index: number) => string | undefined;
|
|
122
|
-
orchestratorIntercomTarget?: string;
|
|
123
|
-
foregroundControl?: {
|
|
124
|
-
updatedAt: number;
|
|
125
|
-
currentAgent?: string;
|
|
126
|
-
currentIndex?: number;
|
|
127
|
-
currentActivityState?: ActivityState;
|
|
128
|
-
lastActivityAt?: number;
|
|
129
|
-
currentTool?: string;
|
|
130
|
-
currentToolStartedAt?: number;
|
|
131
|
-
currentPath?: string;
|
|
132
|
-
turnCount?: number;
|
|
133
|
-
tokens?: number;
|
|
134
|
-
toolCount?: number;
|
|
135
|
-
interrupt?: () => boolean;
|
|
136
|
-
};
|
|
137
|
-
results: SingleResult[];
|
|
138
|
-
allProgress: AgentProgress[];
|
|
139
|
-
outputs: ChainOutputMap;
|
|
140
|
-
chainAgents: string[];
|
|
141
|
-
chainSteps: ChainStep[];
|
|
142
|
-
totalSteps: number;
|
|
143
|
-
dynamicChildren?: ChainExecutionDetailsInput["dynamicChildren"];
|
|
144
|
-
dynamicGroupStatuses?: ChainExecutionDetailsInput["dynamicGroupStatuses"];
|
|
145
|
-
worktreeSetup?: WorktreeSetup;
|
|
146
|
-
maxSubagentDepth: number;
|
|
147
|
-
nestedRoute?: NestedRouteInfo;
|
|
148
|
-
timeoutMs?: number;
|
|
149
|
-
deadlineAt?: number;
|
|
150
|
-
turnBudget?: ResolvedTurnBudget;
|
|
151
|
-
onDetachedExit?: (index: number, result: SingleResult) => void;
|
|
152
|
-
toolBudget?: ResolvedToolBudget;
|
|
153
|
-
configToolBudget?: ToolBudgetConfig;
|
|
154
|
-
globalSemaphore?: Semaphore;
|
|
155
|
-
}
|
|
156
|
-
|
|
157
|
-
function buildChainExecutionDetails(input: ChainExecutionDetailsInput): Details {
|
|
158
|
-
return compactForegroundDetails({
|
|
159
|
-
mode: "chain",
|
|
160
|
-
results: input.results,
|
|
161
|
-
progress: input.includeProgress ? input.allProgress : undefined,
|
|
162
|
-
artifacts: input.allArtifactPaths.length ? { dir: input.artifactsDir, files: input.allArtifactPaths } : undefined,
|
|
163
|
-
chainAgents: input.chainAgents,
|
|
164
|
-
totalSteps: input.totalSteps,
|
|
165
|
-
currentStepIndex: input.currentStepIndex,
|
|
166
|
-
outputs: input.outputs,
|
|
167
|
-
totalChildUsage: sumResultsUsage(input.results),
|
|
168
|
-
totalCost: sumResultsCost(input.results),
|
|
169
|
-
workflowGraph: buildWorkflowGraphSnapshot({
|
|
170
|
-
runId: input.runId,
|
|
171
|
-
mode: "chain",
|
|
172
|
-
steps: input.chainSteps,
|
|
173
|
-
results: input.results,
|
|
174
|
-
currentStepIndex: input.currentStepIndex,
|
|
175
|
-
currentFlatIndex: input.currentFlatIndex,
|
|
176
|
-
dynamicChildren: input.dynamicChildren,
|
|
177
|
-
dynamicGroupStatuses: input.dynamicGroupStatuses,
|
|
178
|
-
}),
|
|
179
|
-
});
|
|
180
|
-
}
|
|
181
|
-
|
|
182
|
-
function buildChainExecutionErrorResult(message: string, input: ChainExecutionDetailsInput): ChainExecutionResult {
|
|
183
|
-
return {
|
|
184
|
-
content: [{ type: "text", text: message }],
|
|
185
|
-
isError: true,
|
|
186
|
-
details: buildChainExecutionDetails(input),
|
|
187
|
-
};
|
|
188
|
-
}
|
|
189
|
-
|
|
190
|
-
function ensureParallelProgressFile(
|
|
191
|
-
chainDir: string,
|
|
192
|
-
progressCreated: boolean,
|
|
193
|
-
parallelBehaviors: ResolvedStepBehavior[],
|
|
194
|
-
): boolean {
|
|
195
|
-
if (progressCreated || !parallelBehaviors.some((behavior) => behavior.progress)) {
|
|
196
|
-
return progressCreated;
|
|
197
|
-
}
|
|
198
|
-
writeInitialProgressFile(chainDir);
|
|
199
|
-
return true;
|
|
200
|
-
}
|
|
201
|
-
|
|
202
|
-
function appendParallelWorktreeSummary(
|
|
203
|
-
output: string,
|
|
204
|
-
worktreeSetup: WorktreeSetup | undefined,
|
|
205
|
-
diffsDir: string,
|
|
206
|
-
agents: string[],
|
|
207
|
-
): string {
|
|
208
|
-
if (!worktreeSetup) return output;
|
|
209
|
-
const diffs = diffWorktrees(worktreeSetup, agents, diffsDir);
|
|
210
|
-
const diffSummary = formatWorktreeDiffSummary(diffs);
|
|
211
|
-
if (!diffSummary) return output;
|
|
212
|
-
return `${output}\n\n${diffSummary}`;
|
|
213
|
-
}
|
|
214
|
-
|
|
215
|
-
function resolveChainToolBudget(input: { stepBudget?: ToolBudgetConfig; runBudget?: ResolvedToolBudget; agentBudget?: ToolBudgetConfig; configBudget?: ToolBudgetConfig }): { toolBudget?: ResolvedToolBudget; error?: string } {
|
|
216
|
-
if (input.stepBudget !== undefined) {
|
|
217
|
-
const resolved = validateToolBudgetConfig(input.stepBudget, "toolBudget");
|
|
218
|
-
return { toolBudget: resolved.budget, error: resolved.error };
|
|
219
|
-
}
|
|
220
|
-
if (input.runBudget !== undefined) return { toolBudget: input.runBudget };
|
|
221
|
-
if (input.agentBudget !== undefined) {
|
|
222
|
-
const resolved = validateToolBudgetConfig(input.agentBudget, "agent.toolBudget");
|
|
223
|
-
return { toolBudget: resolved.budget, error: resolved.error };
|
|
224
|
-
}
|
|
225
|
-
const resolved = validateToolBudgetConfig(input.configBudget, "config.toolBudget");
|
|
226
|
-
return { toolBudget: resolved.budget, error: resolved.error };
|
|
227
|
-
}
|
|
228
|
-
|
|
229
|
-
async function runParallelChainTasks(input: ParallelChainRunInput): Promise<SingleResult[]> {
|
|
230
|
-
const concurrency = input.step.concurrency ?? MAX_CONCURRENCY;
|
|
231
|
-
const failFast = input.step.failFast ?? false;
|
|
232
|
-
let aborted = false;
|
|
233
|
-
|
|
234
|
-
const parallelResults = await mapConcurrent(
|
|
235
|
-
input.step.parallel,
|
|
236
|
-
concurrency,
|
|
237
|
-
async (task, taskIndex) => {
|
|
238
|
-
if (aborted && failFast) {
|
|
239
|
-
return {
|
|
240
|
-
agent: task.agent,
|
|
241
|
-
task: "(skipped)",
|
|
242
|
-
exitCode: -1,
|
|
243
|
-
messages: [],
|
|
244
|
-
usage: { input: 0, output: 0, cacheRead: 0, cacheWrite: 0, cost: 0, turns: 0 },
|
|
245
|
-
error: "Skipped due to fail-fast",
|
|
246
|
-
} as SingleResult;
|
|
247
|
-
}
|
|
248
|
-
|
|
249
|
-
const taskTemplate = input.parallelTemplates[taskIndex] ?? "{previous}";
|
|
250
|
-
const behavior = suppressProgressForReadOnlyTask(input.parallelBehaviors[taskIndex]!, taskTemplate, input.originalTask);
|
|
251
|
-
const templateHasPrevious = taskTemplate.includes("{previous}");
|
|
252
|
-
const { prefix, suffix } = buildChainInstructions(
|
|
253
|
-
behavior,
|
|
254
|
-
input.chainDir,
|
|
255
|
-
false,
|
|
256
|
-
templateHasPrevious ? undefined : input.prev,
|
|
257
|
-
);
|
|
258
|
-
|
|
259
|
-
let taskStr = resolveOutputReferences(taskTemplate, input.outputs);
|
|
260
|
-
taskStr = taskStr.replace(/\{task\}/g, input.originalTask);
|
|
261
|
-
taskStr = taskStr.replace(/\{previous\}/g, input.prev);
|
|
262
|
-
taskStr = taskStr.replace(/\{chain_dir\}/g, input.chainDir);
|
|
263
|
-
const cleanTask = taskStr;
|
|
264
|
-
taskStr = prefix + taskStr + suffix;
|
|
265
|
-
|
|
266
|
-
const taskAgentConfig = input.agents.find((agent) => agent.name === task.agent);
|
|
267
|
-
const effectiveModel = resolveSubagentModelOverride(
|
|
268
|
-
task.model ?? taskAgentConfig?.model,
|
|
269
|
-
input.ctx.model,
|
|
270
|
-
input.availableModels,
|
|
271
|
-
input.ctx.model?.provider,
|
|
272
|
-
{ scope: input.modelScope, source: task.model ? "explicit" : "inherited" },
|
|
273
|
-
);
|
|
274
|
-
const maxSubagentDepth = resolveChildMaxSubagentDepth(input.maxSubagentDepth, taskAgentConfig?.maxSubagentDepth);
|
|
275
|
-
const toolBudget = resolveChainToolBudget({ stepBudget: task.toolBudget, runBudget: input.toolBudget, agentBudget: taskAgentConfig?.toolBudget, configBudget: input.configToolBudget });
|
|
276
|
-
if (toolBudget.error) throw new Error(toolBudget.error);
|
|
277
|
-
|
|
278
|
-
const taskCwd = input.worktreeSetup
|
|
279
|
-
? input.worktreeSetup.worktrees[taskIndex]!.agentCwd
|
|
280
|
-
: resolveChildCwd(input.cwd ?? input.ctx.cwd, task.cwd);
|
|
281
|
-
|
|
282
|
-
const outputPath = typeof behavior.output === "string"
|
|
283
|
-
? (path.isAbsolute(behavior.output) ? behavior.output : path.join(input.chainDir, behavior.output))
|
|
284
|
-
: undefined;
|
|
285
|
-
const interruptController = new AbortController();
|
|
286
|
-
if (input.foregroundControl) {
|
|
287
|
-
input.foregroundControl.currentAgent = task.agent;
|
|
288
|
-
input.foregroundControl.currentIndex = input.globalTaskIndex + taskIndex;
|
|
289
|
-
input.foregroundControl.currentActivityState = undefined;
|
|
290
|
-
input.foregroundControl.updatedAt = Date.now();
|
|
291
|
-
input.foregroundControl.interrupt = () => {
|
|
292
|
-
if (interruptController.signal.aborted) return false;
|
|
293
|
-
interruptController.abort();
|
|
294
|
-
input.foregroundControl!.currentActivityState = undefined;
|
|
295
|
-
input.foregroundControl!.updatedAt = Date.now();
|
|
296
|
-
return true;
|
|
297
|
-
};
|
|
298
|
-
}
|
|
299
|
-
|
|
300
|
-
const structuredRuntime = task.outputSchema
|
|
301
|
-
? createStructuredOutputRuntime(task.outputSchema, path.join(input.chainDir, "structured-output"))
|
|
302
|
-
: undefined;
|
|
303
|
-
const result = await runSync(input.ctx.cwd, input.agents, task.agent, taskStr, {
|
|
304
|
-
parentSessionId: input.ctx.sessionManager.getSessionId() ?? undefined,
|
|
305
|
-
cwd: taskCwd,
|
|
306
|
-
signal: input.signal,
|
|
307
|
-
interruptSignal: interruptController.signal,
|
|
308
|
-
allowIntercomDetach: taskAgentConfig?.systemPrompt?.includes(INTERCOM_BRIDGE_MARKER) === true,
|
|
309
|
-
intercomEvents: input.intercomEvents,
|
|
310
|
-
runId: input.runId,
|
|
311
|
-
index: input.globalTaskIndex + taskIndex,
|
|
312
|
-
sessionDir: input.sessionDirForIndex(input.globalTaskIndex + taskIndex),
|
|
313
|
-
sessionFile: input.sessionFileForTask?.(task.agent, input.globalTaskIndex + taskIndex)
|
|
314
|
-
?? input.sessionFileForIndex?.(input.globalTaskIndex + taskIndex),
|
|
315
|
-
thinkingOverride: input.thinkingOverrideForTask?.(task.agent, input.globalTaskIndex + taskIndex),
|
|
316
|
-
share: input.shareEnabled,
|
|
317
|
-
artifactsDir: input.artifactConfig.enabled ? input.artifactsDir : undefined,
|
|
318
|
-
artifactConfig: input.artifactConfig,
|
|
319
|
-
outputPath,
|
|
320
|
-
outputMode: behavior.outputMode,
|
|
321
|
-
maxSubagentDepth,
|
|
322
|
-
controlConfig: input.controlConfig,
|
|
323
|
-
onControlEvent: input.onControlEvent,
|
|
324
|
-
intercomSessionName: input.childIntercomTarget?.(task.agent, input.globalTaskIndex + taskIndex),
|
|
325
|
-
orchestratorIntercomTarget: input.orchestratorIntercomTarget,
|
|
326
|
-
nestedRoute: input.nestedRoute,
|
|
327
|
-
modelOverride: effectiveModel,
|
|
328
|
-
availableModels: input.availableModels,
|
|
329
|
-
preferredModelProvider: input.ctx.model?.provider,
|
|
330
|
-
modelScope: input.modelScope,
|
|
331
|
-
skills: behavior.skills === false ? [] : behavior.skills,
|
|
332
|
-
structuredOutput: structuredRuntime,
|
|
333
|
-
acceptance: task.acceptance,
|
|
334
|
-
acceptanceContext: { mode: "chain" },
|
|
335
|
-
timeoutMs: input.timeoutMs,
|
|
336
|
-
deadlineAt: input.deadlineAt,
|
|
337
|
-
turnBudget: input.turnBudget,
|
|
338
|
-
onDetachedExit: input.onDetachedExit
|
|
339
|
-
? (result) => input.onDetachedExit?.(input.globalTaskIndex + taskIndex, result)
|
|
340
|
-
: undefined,
|
|
341
|
-
toolBudget: toolBudget.toolBudget,
|
|
342
|
-
onUpdate: input.onUpdate
|
|
343
|
-
? (progressUpdate) => {
|
|
344
|
-
const stepResults = progressUpdate.details?.results || [];
|
|
345
|
-
const stepProgress = progressUpdate.details?.progress || [];
|
|
346
|
-
if (input.foregroundControl && stepProgress.length > 0) {
|
|
347
|
-
const current = stepProgress[0];
|
|
348
|
-
input.foregroundControl.currentAgent = task.agent;
|
|
349
|
-
input.foregroundControl.currentIndex = input.globalTaskIndex + taskIndex;
|
|
350
|
-
input.foregroundControl.currentActivityState = current?.activityState;
|
|
351
|
-
input.foregroundControl.lastActivityAt = current?.lastActivityAt;
|
|
352
|
-
input.foregroundControl.currentTool = current?.currentTool;
|
|
353
|
-
input.foregroundControl.currentToolStartedAt = current?.currentToolStartedAt;
|
|
354
|
-
input.foregroundControl.currentPath = current?.currentPath;
|
|
355
|
-
input.foregroundControl.turnCount = current?.turnCount;
|
|
356
|
-
input.foregroundControl.tokens = current?.tokens;
|
|
357
|
-
input.foregroundControl.toolCount = current?.toolCount;
|
|
358
|
-
input.foregroundControl.updatedAt = Date.now();
|
|
359
|
-
}
|
|
360
|
-
input.onUpdate?.({
|
|
361
|
-
...progressUpdate,
|
|
362
|
-
details: {
|
|
363
|
-
mode: "chain",
|
|
364
|
-
results: input.results.concat(stepResults),
|
|
365
|
-
progress: input.allProgress.concat(stepProgress),
|
|
366
|
-
controlEvents: progressUpdate.details?.controlEvents,
|
|
367
|
-
chainAgents: input.chainAgents,
|
|
368
|
-
totalSteps: input.totalSteps,
|
|
369
|
-
currentStepIndex: input.stepIndex,
|
|
370
|
-
outputs: input.outputs,
|
|
371
|
-
workflowGraph: buildWorkflowGraphSnapshot({
|
|
372
|
-
runId: input.runId,
|
|
373
|
-
mode: "chain",
|
|
374
|
-
steps: input.chainSteps,
|
|
375
|
-
results: input.results.concat(stepResults),
|
|
376
|
-
currentStepIndex: input.stepIndex,
|
|
377
|
-
currentFlatIndex: input.globalTaskIndex + taskIndex,
|
|
378
|
-
dynamicChildren: input.dynamicChildren,
|
|
379
|
-
dynamicGroupStatuses: input.dynamicGroupStatuses,
|
|
380
|
-
}),
|
|
381
|
-
},
|
|
382
|
-
});
|
|
383
|
-
}
|
|
384
|
-
: undefined,
|
|
385
|
-
});
|
|
386
|
-
if (input.foregroundControl?.currentIndex === input.globalTaskIndex + taskIndex) {
|
|
387
|
-
input.foregroundControl.interrupt = undefined;
|
|
388
|
-
input.foregroundControl.updatedAt = Date.now();
|
|
389
|
-
}
|
|
390
|
-
|
|
391
|
-
if (result.exitCode !== 0 && failFast) {
|
|
392
|
-
aborted = true;
|
|
393
|
-
}
|
|
394
|
-
recordRun(task.agent, cleanTask, result.exitCode, result.progressSummary?.durationMs ?? 0);
|
|
395
|
-
return result;
|
|
396
|
-
},
|
|
397
|
-
input.globalSemaphore,
|
|
398
|
-
);
|
|
399
|
-
|
|
400
|
-
return parallelResults;
|
|
401
|
-
}
|
|
402
|
-
|
|
403
|
-
interface ChainExecutionParams {
|
|
404
|
-
chain: ChainStep[];
|
|
405
|
-
task?: string;
|
|
406
|
-
agents: AgentConfig[];
|
|
407
|
-
ctx: ExtensionContext;
|
|
408
|
-
intercomEvents?: IntercomEventBus;
|
|
409
|
-
signal?: AbortSignal;
|
|
410
|
-
runId: string;
|
|
411
|
-
cwd?: string;
|
|
412
|
-
shareEnabled: boolean;
|
|
413
|
-
sessionDirForIndex: (idx?: number) => string | undefined;
|
|
414
|
-
sessionFileForIndex?: (idx?: number) => string | undefined;
|
|
415
|
-
sessionFileForTask?: (agentName: string, idx?: number) => string | undefined;
|
|
416
|
-
thinkingOverrideForTask?: (agentName: string, idx?: number) => AgentConfig["thinking"] | undefined;
|
|
417
|
-
artifactsDir: string;
|
|
418
|
-
artifactConfig: ArtifactConfig;
|
|
419
|
-
includeProgress?: boolean;
|
|
420
|
-
clarify?: boolean;
|
|
421
|
-
onUpdate?: (r: AgentToolResult<Details>) => void;
|
|
422
|
-
onControlEvent?: (event: ControlEvent) => void;
|
|
423
|
-
controlConfig: ResolvedControlConfig;
|
|
424
|
-
childIntercomTarget?: (agent: string, index: number) => string | undefined;
|
|
425
|
-
orchestratorIntercomTarget?: string;
|
|
426
|
-
foregroundControl?: {
|
|
427
|
-
updatedAt: number;
|
|
428
|
-
currentAgent?: string;
|
|
429
|
-
currentIndex?: number;
|
|
430
|
-
currentActivityState?: ActivityState;
|
|
431
|
-
lastActivityAt?: number;
|
|
432
|
-
currentTool?: string;
|
|
433
|
-
currentToolStartedAt?: number;
|
|
434
|
-
currentPath?: string;
|
|
435
|
-
turnCount?: number;
|
|
436
|
-
tokens?: number;
|
|
437
|
-
toolCount?: number;
|
|
438
|
-
interrupt?: () => boolean;
|
|
439
|
-
};
|
|
440
|
-
chainSkills?: string[];
|
|
441
|
-
chainDir?: string;
|
|
442
|
-
dynamicFanoutMaxItems?: number;
|
|
443
|
-
maxSubagentDepth: number;
|
|
444
|
-
nestedRoute?: NestedRouteInfo;
|
|
445
|
-
worktreeSetupHook?: string;
|
|
446
|
-
worktreeSetupHookTimeoutMs?: number;
|
|
447
|
-
worktreeBaseDir?: string;
|
|
448
|
-
timeoutMs?: number;
|
|
449
|
-
deadlineAt?: number;
|
|
450
|
-
turnBudget?: ResolvedTurnBudget;
|
|
451
|
-
onDetachedExit?: (index: number, result: SingleResult) => void;
|
|
452
|
-
toolBudget?: ResolvedToolBudget;
|
|
453
|
-
configToolBudget?: ToolBudgetConfig;
|
|
454
|
-
/** Global cap on simultaneously-running tasks within this chain. Defaults to DEFAULT_GLOBAL_CONCURRENCY_LIMIT. */
|
|
455
|
-
globalConcurrencyLimit?: number;
|
|
456
|
-
}
|
|
457
|
-
|
|
458
|
-
interface ChainExecutionResult {
|
|
459
|
-
content: Array<{ type: "text"; text: string }>;
|
|
460
|
-
details: Details;
|
|
461
|
-
isError?: boolean;
|
|
462
|
-
/** User requested async execution via TUI - caller should dispatch to executeAsyncChain */
|
|
463
|
-
requestedAsync?: {
|
|
464
|
-
chain: ChainStep[];
|
|
465
|
-
chainSkills: string[];
|
|
466
|
-
};
|
|
467
|
-
}
|
|
468
|
-
|
|
469
|
-
/**
|
|
470
|
-
* Execute a chain of subagent steps
|
|
471
|
-
*/
|
|
472
|
-
export async function executeChain(params: ChainExecutionParams): Promise<ChainExecutionResult> {
|
|
473
|
-
const {
|
|
474
|
-
chain: chainSteps,
|
|
475
|
-
agents,
|
|
476
|
-
ctx,
|
|
477
|
-
signal,
|
|
478
|
-
runId,
|
|
479
|
-
cwd,
|
|
480
|
-
shareEnabled,
|
|
481
|
-
sessionDirForIndex,
|
|
482
|
-
sessionFileForIndex,
|
|
483
|
-
sessionFileForTask,
|
|
484
|
-
thinkingOverrideForTask,
|
|
485
|
-
artifactsDir,
|
|
486
|
-
artifactConfig,
|
|
487
|
-
includeProgress,
|
|
488
|
-
clarify,
|
|
489
|
-
onUpdate,
|
|
490
|
-
onControlEvent,
|
|
491
|
-
controlConfig,
|
|
492
|
-
onDetachedExit,
|
|
493
|
-
childIntercomTarget,
|
|
494
|
-
orchestratorIntercomTarget,
|
|
495
|
-
foregroundControl,
|
|
496
|
-
intercomEvents,
|
|
497
|
-
chainSkills: chainSkillsParam,
|
|
498
|
-
chainDir: chainDirBase,
|
|
499
|
-
modelScope,
|
|
500
|
-
} = params;
|
|
501
|
-
const chainSkills = chainSkillsParam ?? [];
|
|
502
|
-
|
|
503
|
-
const results: SingleResult[] = [];
|
|
504
|
-
const outputs: ChainOutputMap = {};
|
|
505
|
-
const dynamicChildren: ChainExecutionDetailsInput["dynamicChildren"] = {};
|
|
506
|
-
const dynamicGroupStatuses: ChainExecutionDetailsInput["dynamicGroupStatuses"] = {};
|
|
507
|
-
const allProgress: AgentProgress[] = [];
|
|
508
|
-
const allArtifactPaths: ArtifactPaths[] = [];
|
|
509
|
-
|
|
510
|
-
const chainAgents: string[] = chainSteps.map((step) =>
|
|
511
|
-
isParallelStep(step)
|
|
512
|
-
? `[${step.parallel.map((t) => t.agent).join("+")}]`
|
|
513
|
-
: isDynamicParallelStep(step)
|
|
514
|
-
? `expand:${step.parallel.agent}`
|
|
515
|
-
: (step as SequentialStep).agent,
|
|
516
|
-
);
|
|
517
|
-
const totalSteps = chainSteps.length;
|
|
518
|
-
|
|
519
|
-
const makeDetailsInput = (overrides: Pick<Partial<ChainExecutionDetailsInput>, "currentStepIndex" | "currentFlatIndex"> = {}): ChainExecutionDetailsInput => ({
|
|
520
|
-
results,
|
|
521
|
-
...(includeProgress !== undefined ? { includeProgress } : {}),
|
|
522
|
-
allProgress,
|
|
523
|
-
allArtifactPaths,
|
|
524
|
-
artifactsDir,
|
|
525
|
-
chainAgents,
|
|
526
|
-
chainSteps,
|
|
527
|
-
totalSteps,
|
|
528
|
-
runId,
|
|
529
|
-
outputs,
|
|
530
|
-
dynamicChildren,
|
|
531
|
-
dynamicGroupStatuses,
|
|
532
|
-
...overrides,
|
|
533
|
-
});
|
|
534
|
-
|
|
535
|
-
const firstStep = chainSteps[0]!;
|
|
536
|
-
const originalTask = params.task
|
|
537
|
-
?? (isParallelStep(firstStep)
|
|
538
|
-
? firstStep.parallel[0]!.task!
|
|
539
|
-
: isDynamicParallelStep(firstStep)
|
|
540
|
-
? firstStep.parallel.task!
|
|
541
|
-
: (firstStep as SequentialStep).task!);
|
|
542
|
-
try {
|
|
543
|
-
validateChainOutputBindings(chainSteps, { maxItems: params.dynamicFanoutMaxItems });
|
|
544
|
-
} catch (error) {
|
|
545
|
-
if (error instanceof ChainOutputValidationError) {
|
|
546
|
-
return {
|
|
547
|
-
content: [{ type: "text", text: error.message }],
|
|
548
|
-
isError: true,
|
|
549
|
-
details: buildChainExecutionDetails(makeDetailsInput()),
|
|
550
|
-
};
|
|
551
|
-
}
|
|
552
|
-
throw error;
|
|
553
|
-
}
|
|
554
|
-
|
|
555
|
-
const chainDir = createChainDir(runId, chainDirBase);
|
|
556
|
-
const hasParallelSteps = chainSteps.some((step) => isParallelStep(step) || isDynamicParallelStep(step));
|
|
557
|
-
let templates: ResolvedTemplates = resolveChainTemplates(chainSteps);
|
|
558
|
-
const shouldClarify = clarify === true && ctx.hasUI && !hasParallelSteps;
|
|
559
|
-
let tuiBehaviorOverrides: (BehaviorOverride | undefined)[] | undefined;
|
|
560
|
-
const availableModels: ModelInfo[] = ctx.modelRegistry.getAvailable().map(toModelInfo);
|
|
561
|
-
const availableSkills = discoverAvailableSkills(cwd ?? ctx.cwd);
|
|
562
|
-
|
|
563
|
-
if (shouldClarify) {
|
|
564
|
-
const seqSteps = chainSteps as SequentialStep[];
|
|
565
|
-
const agentConfigs: AgentConfig[] = [];
|
|
566
|
-
for (const step of seqSteps) {
|
|
567
|
-
const config = agents.find((a) => a.name === step.agent);
|
|
568
|
-
if (!config) {
|
|
569
|
-
removeChainDir(chainDir);
|
|
570
|
-
return {
|
|
571
|
-
content: [{ type: "text", text: `Unknown agent: ${step.agent}` }],
|
|
572
|
-
isError: true,
|
|
573
|
-
details: buildChainExecutionDetails(makeDetailsInput({ currentStepIndex: seqSteps.indexOf(step) })),
|
|
574
|
-
};
|
|
575
|
-
}
|
|
576
|
-
agentConfigs.push(config);
|
|
577
|
-
}
|
|
578
|
-
|
|
579
|
-
const stepOverrides: StepOverrides[] = seqSteps.map((step) => ({
|
|
580
|
-
output: step.output,
|
|
581
|
-
outputMode: step.outputMode,
|
|
582
|
-
reads: step.reads,
|
|
583
|
-
progress: step.progress,
|
|
584
|
-
skills: normalizeSkillInput(step.skill),
|
|
585
|
-
model: step.model,
|
|
586
|
-
}));
|
|
587
|
-
|
|
588
|
-
const resolvedBehaviors = agentConfigs.map((config, i) =>
|
|
589
|
-
resolveStepBehavior(config, stepOverrides[i]!, chainSkills),
|
|
590
|
-
);
|
|
591
|
-
const flatTemplates = templates as string[];
|
|
592
|
-
|
|
593
|
-
const result = await ctx.ui.custom<ChainClarifyResult>(
|
|
594
|
-
(tui, theme, _kb, done) =>
|
|
595
|
-
new ChainClarifyComponent(
|
|
596
|
-
tui,
|
|
597
|
-
theme,
|
|
598
|
-
agentConfigs,
|
|
599
|
-
flatTemplates,
|
|
600
|
-
originalTask,
|
|
601
|
-
chainDir,
|
|
602
|
-
resolvedBehaviors,
|
|
603
|
-
availableModels,
|
|
604
|
-
ctx.model?.provider,
|
|
605
|
-
availableSkills,
|
|
606
|
-
done,
|
|
607
|
-
),
|
|
608
|
-
{
|
|
609
|
-
overlay: true,
|
|
610
|
-
overlayOptions: { anchor: "center", width: 84, maxHeight: "80%" },
|
|
611
|
-
},
|
|
612
|
-
);
|
|
613
|
-
|
|
614
|
-
if (!result || !result.confirmed) {
|
|
615
|
-
removeChainDir(chainDir);
|
|
616
|
-
return {
|
|
617
|
-
content: [{ type: "text", text: "Chain cancelled" }],
|
|
618
|
-
details: buildChainExecutionDetails(makeDetailsInput()),
|
|
619
|
-
};
|
|
620
|
-
}
|
|
621
|
-
|
|
622
|
-
if (result.runInBackground) {
|
|
623
|
-
removeChainDir(chainDir);
|
|
624
|
-
const updatedChain: ChainStep[] = chainSteps.map((step, i) => {
|
|
625
|
-
if (isParallelStep(step)) return step;
|
|
626
|
-
const override = result.behaviorOverrides[i];
|
|
627
|
-
return {
|
|
628
|
-
...step,
|
|
629
|
-
task: result.templates[i]!,
|
|
630
|
-
...(override?.model ? { model: override.model } : {}),
|
|
631
|
-
...(override?.output !== undefined ? { output: override.output } : {}),
|
|
632
|
-
...("outputMode" in step && step.outputMode !== undefined ? { outputMode: step.outputMode } : {}),
|
|
633
|
-
...(override?.reads !== undefined ? { reads: override.reads } : {}),
|
|
634
|
-
...(override?.progress !== undefined ? { progress: override.progress } : {}),
|
|
635
|
-
...(override?.skills !== undefined ? { skill: override.skills } : {}),
|
|
636
|
-
};
|
|
637
|
-
});
|
|
638
|
-
return {
|
|
639
|
-
content: [{ type: "text", text: "Launching in background..." }],
|
|
640
|
-
details: buildChainExecutionDetails(makeDetailsInput()),
|
|
641
|
-
requestedAsync: { chain: updatedChain, chainSkills },
|
|
642
|
-
};
|
|
643
|
-
}
|
|
644
|
-
|
|
645
|
-
templates = result.templates;
|
|
646
|
-
tuiBehaviorOverrides = result.behaviorOverrides;
|
|
647
|
-
}
|
|
648
|
-
|
|
649
|
-
const deadlineAt = params.deadlineAt ?? (params.timeoutMs !== undefined ? Date.now() + params.timeoutMs : undefined);
|
|
650
|
-
const globalSemaphore = new Semaphore(params.globalConcurrencyLimit ?? DEFAULT_GLOBAL_CONCURRENCY_LIMIT);
|
|
651
|
-
let prev = "";
|
|
652
|
-
let globalTaskIndex = 0;
|
|
653
|
-
let progressCreated = false;
|
|
654
|
-
|
|
655
|
-
for (let stepIndex = 0; stepIndex < chainSteps.length; stepIndex++) {
|
|
656
|
-
const step = chainSteps[stepIndex]!;
|
|
657
|
-
const stepTemplates = templates[stepIndex]!;
|
|
658
|
-
|
|
659
|
-
if (isParallelStep(step)) {
|
|
660
|
-
const parallelTemplates = stepTemplates as string[];
|
|
661
|
-
const parallelCwd = resolveChildCwd(cwd ?? ctx.cwd, step.cwd);
|
|
662
|
-
let worktreeSetup: WorktreeSetup | undefined;
|
|
663
|
-
if (step.worktree) {
|
|
664
|
-
const worktreeTaskCwdConflict = findWorktreeTaskCwdConflict(step.parallel, parallelCwd);
|
|
665
|
-
if (worktreeTaskCwdConflict) {
|
|
666
|
-
return buildChainExecutionErrorResult(
|
|
667
|
-
`parallel chain step ${stepIndex + 1}: ${formatWorktreeTaskCwdConflict(worktreeTaskCwdConflict, parallelCwd)}`,
|
|
668
|
-
makeDetailsInput({ currentStepIndex: stepIndex, currentFlatIndex: globalTaskIndex }),
|
|
669
|
-
);
|
|
670
|
-
}
|
|
671
|
-
try {
|
|
672
|
-
worktreeSetup = createWorktrees(parallelCwd, `${runId}-s${stepIndex}`, step.parallel.length, {
|
|
673
|
-
agents: step.parallel.map((task) => task.agent),
|
|
674
|
-
setupHook: params.worktreeSetupHook
|
|
675
|
-
? { hookPath: params.worktreeSetupHook, timeoutMs: params.worktreeSetupHookTimeoutMs }
|
|
676
|
-
: undefined,
|
|
677
|
-
baseDir: params.worktreeBaseDir,
|
|
678
|
-
});
|
|
679
|
-
} catch (error) {
|
|
680
|
-
const message = error instanceof Error ? error.message : String(error);
|
|
681
|
-
return buildChainExecutionErrorResult(message, makeDetailsInput({ currentStepIndex: stepIndex, currentFlatIndex: globalTaskIndex }));
|
|
682
|
-
}
|
|
683
|
-
}
|
|
684
|
-
|
|
685
|
-
try {
|
|
686
|
-
const agentNames = step.parallel.map((task) => task.agent);
|
|
687
|
-
const parallelBehaviors = resolveParallelBehaviors(step.parallel, agents, stepIndex, chainSkills)
|
|
688
|
-
.map((behavior, taskIndex) => suppressProgressForReadOnlyTask(behavior, parallelTemplates[taskIndex] ?? step.parallel[taskIndex]?.task, originalTask));
|
|
689
|
-
for (let taskIndex = 0; taskIndex < step.parallel.length; taskIndex++) {
|
|
690
|
-
const behavior = parallelBehaviors[taskIndex]!;
|
|
691
|
-
const outputPath = typeof behavior.output === "string"
|
|
692
|
-
? (path.isAbsolute(behavior.output) ? behavior.output : path.join(chainDir, behavior.output))
|
|
693
|
-
: undefined;
|
|
694
|
-
const validationError = validateFileOnlyOutputMode(behavior.outputMode, outputPath, `Parallel chain step ${stepIndex + 1} task ${taskIndex + 1} (${step.parallel[taskIndex]!.agent})`);
|
|
695
|
-
if (validationError) return buildChainExecutionErrorResult(validationError, makeDetailsInput({ currentStepIndex: stepIndex, currentFlatIndex: globalTaskIndex + taskIndex }));
|
|
696
|
-
}
|
|
697
|
-
progressCreated = ensureParallelProgressFile(chainDir, progressCreated, parallelBehaviors);
|
|
698
|
-
createParallelDirs(chainDir, stepIndex, step.parallel.length, agentNames);
|
|
699
|
-
|
|
700
|
-
const parallelResults = await runParallelChainTasks({
|
|
701
|
-
step,
|
|
702
|
-
parallelTemplates,
|
|
703
|
-
parallelBehaviors,
|
|
704
|
-
agents,
|
|
705
|
-
stepIndex,
|
|
706
|
-
availableModels,
|
|
707
|
-
modelScope,
|
|
708
|
-
chainDir,
|
|
709
|
-
prev,
|
|
710
|
-
originalTask,
|
|
711
|
-
ctx,
|
|
712
|
-
intercomEvents,
|
|
713
|
-
cwd,
|
|
714
|
-
runId,
|
|
715
|
-
globalTaskIndex,
|
|
716
|
-
sessionDirForIndex,
|
|
717
|
-
sessionFileForIndex,
|
|
718
|
-
sessionFileForTask,
|
|
719
|
-
thinkingOverrideForTask,
|
|
720
|
-
shareEnabled,
|
|
721
|
-
artifactConfig,
|
|
722
|
-
artifactsDir,
|
|
723
|
-
signal,
|
|
724
|
-
onUpdate,
|
|
725
|
-
results,
|
|
726
|
-
allProgress,
|
|
727
|
-
outputs,
|
|
728
|
-
chainAgents,
|
|
729
|
-
chainSteps,
|
|
730
|
-
totalSteps,
|
|
731
|
-
dynamicChildren,
|
|
732
|
-
dynamicGroupStatuses,
|
|
733
|
-
controlConfig,
|
|
734
|
-
onControlEvent,
|
|
735
|
-
childIntercomTarget,
|
|
736
|
-
orchestratorIntercomTarget,
|
|
737
|
-
foregroundControl,
|
|
738
|
-
nestedRoute: params.nestedRoute,
|
|
739
|
-
worktreeSetup,
|
|
740
|
-
maxSubagentDepth: params.maxSubagentDepth,
|
|
741
|
-
timeoutMs: params.timeoutMs,
|
|
742
|
-
deadlineAt,
|
|
743
|
-
turnBudget: params.turnBudget,
|
|
744
|
-
onDetachedExit,
|
|
745
|
-
toolBudget: params.toolBudget,
|
|
746
|
-
configToolBudget: params.configToolBudget,
|
|
747
|
-
globalSemaphore,
|
|
748
|
-
});
|
|
749
|
-
globalTaskIndex += step.parallel.length;
|
|
750
|
-
|
|
751
|
-
for (const result of parallelResults) {
|
|
752
|
-
results.push(result);
|
|
753
|
-
if (result.progress) allProgress.push(result.progress);
|
|
754
|
-
if (result.artifactPaths) allArtifactPaths.push(result.artifactPaths);
|
|
755
|
-
}
|
|
756
|
-
const interruptedIndexInStep = parallelResults.findIndex((result) => result.interrupted);
|
|
757
|
-
const interrupted = interruptedIndexInStep >= 0 ? parallelResults[interruptedIndexInStep] : undefined;
|
|
758
|
-
if (interrupted) {
|
|
759
|
-
return {
|
|
760
|
-
content: [{ type: "text", text: `Chain paused after interrupt at step ${stepIndex + 1} (${interrupted.agent}). Waiting for explicit next action.` }],
|
|
761
|
-
details: buildChainExecutionDetails(makeDetailsInput({
|
|
762
|
-
currentStepIndex: stepIndex,
|
|
763
|
-
currentFlatIndex: globalTaskIndex - step.parallel.length + interruptedIndexInStep,
|
|
764
|
-
})),
|
|
765
|
-
};
|
|
766
|
-
}
|
|
767
|
-
const detachedIndexInStep = parallelResults.findIndex((result) => result.detached);
|
|
768
|
-
const detached = detachedIndexInStep >= 0 ? parallelResults[detachedIndexInStep] : undefined;
|
|
769
|
-
if (detached) {
|
|
770
|
-
return {
|
|
771
|
-
content: [{ type: "text", text: `Chain detached for intercom coordination at step ${stepIndex + 1} (${detached.agent}). Reply to the supervisor request first. After the child exits, start a fresh follow-up if needed.` }],
|
|
772
|
-
details: buildChainExecutionDetails(makeDetailsInput({
|
|
773
|
-
currentStepIndex: stepIndex,
|
|
774
|
-
currentFlatIndex: globalTaskIndex - step.parallel.length + detachedIndexInStep,
|
|
775
|
-
})),
|
|
776
|
-
};
|
|
777
|
-
}
|
|
778
|
-
|
|
779
|
-
const failures = parallelResults
|
|
780
|
-
.map((result, originalIndex) => ({ ...result, originalIndex }))
|
|
781
|
-
.filter((result) => result.exitCode !== 0 && result.exitCode !== -1);
|
|
782
|
-
if (failures.length > 0) {
|
|
783
|
-
const failureSummary = failures
|
|
784
|
-
.map((failure) => `- Task ${failure.originalIndex + 1} (${failure.agent}): ${failure.error || "failed"}`)
|
|
785
|
-
.join("\n");
|
|
786
|
-
const errorMsg = `Parallel step ${stepIndex + 1} failed:\n${failureSummary}`;
|
|
787
|
-
const summary = buildChainSummary(chainSteps, results, chainDir, "failed", {
|
|
788
|
-
index: stepIndex,
|
|
789
|
-
error: errorMsg,
|
|
790
|
-
});
|
|
791
|
-
return {
|
|
792
|
-
content: [{ type: "text", text: summary }],
|
|
793
|
-
isError: true,
|
|
794
|
-
details: buildChainExecutionDetails(makeDetailsInput({
|
|
795
|
-
currentStepIndex: stepIndex,
|
|
796
|
-
currentFlatIndex: globalTaskIndex - step.parallel.length + failures[0]!.originalIndex,
|
|
797
|
-
})),
|
|
798
|
-
};
|
|
799
|
-
}
|
|
800
|
-
|
|
801
|
-
for (let taskIndex = 0; taskIndex < parallelResults.length; taskIndex++) {
|
|
802
|
-
const outputName = step.parallel[taskIndex]?.as;
|
|
803
|
-
if (outputName) outputs[outputName] = outputEntryFromResult(parallelResults[taskIndex]!, stepIndex);
|
|
804
|
-
}
|
|
805
|
-
|
|
806
|
-
const taskResults: ParallelTaskResult[] = parallelResults.map((result, i) => {
|
|
807
|
-
const outputTarget = parallelBehaviors[i]?.output;
|
|
808
|
-
const outputTargetPath = typeof outputTarget === "string"
|
|
809
|
-
? (path.isAbsolute(outputTarget) ? outputTarget : path.join(chainDir, outputTarget))
|
|
810
|
-
: undefined;
|
|
811
|
-
return {
|
|
812
|
-
agent: result.agent,
|
|
813
|
-
taskIndex: i,
|
|
814
|
-
output: getSingleResultOutput(result),
|
|
815
|
-
exitCode: result.exitCode,
|
|
816
|
-
error: result.error,
|
|
817
|
-
timedOut: result.timedOut,
|
|
818
|
-
outputTargetPath,
|
|
819
|
-
outputTargetExists: outputTargetPath ? fs.existsSync(outputTargetPath) : undefined,
|
|
820
|
-
};
|
|
821
|
-
});
|
|
822
|
-
prev = aggregateParallelOutputs(taskResults);
|
|
823
|
-
prev = appendParallelWorktreeSummary(
|
|
824
|
-
prev,
|
|
825
|
-
worktreeSetup,
|
|
826
|
-
path.join(chainDir, "worktree-diffs", `step-${stepIndex}`),
|
|
827
|
-
agentNames,
|
|
828
|
-
);
|
|
829
|
-
} finally {
|
|
830
|
-
if (worktreeSetup) cleanupWorktrees(worktreeSetup);
|
|
831
|
-
}
|
|
832
|
-
} else if (isDynamicParallelStep(step)) {
|
|
833
|
-
const dynamicStartIndex = globalTaskIndex;
|
|
834
|
-
const reservedDynamicItems = step.expand.maxItems ?? params.dynamicFanoutMaxItems ?? 0;
|
|
835
|
-
let materialized: ReturnType<typeof materializeDynamicParallelStep>;
|
|
836
|
-
try {
|
|
837
|
-
materialized = materializeDynamicParallelStep(step, outputs, stepIndex, { maxItems: params.dynamicFanoutMaxItems });
|
|
838
|
-
} catch (error) {
|
|
839
|
-
const message = error instanceof DynamicFanoutError ? error.message : error instanceof Error ? error.message : String(error);
|
|
840
|
-
dynamicGroupStatuses[stepIndex] = { status: "failed", error: message };
|
|
841
|
-
return buildChainExecutionErrorResult(message, makeDetailsInput({ currentStepIndex: stepIndex, currentFlatIndex: globalTaskIndex }));
|
|
842
|
-
}
|
|
843
|
-
|
|
844
|
-
dynamicChildren[stepIndex] = materialized.items.map((item, itemIndex) => ({
|
|
845
|
-
agent: step.parallel.agent,
|
|
846
|
-
label: materialized.parallel[itemIndex]?.label,
|
|
847
|
-
flatIndex: globalTaskIndex + itemIndex,
|
|
848
|
-
itemKey: item.key,
|
|
849
|
-
structured: Boolean(step.parallel.outputSchema),
|
|
850
|
-
}));
|
|
851
|
-
|
|
852
|
-
if (materialized.parallel.length === 0) {
|
|
853
|
-
const collection: DynamicCollectedResult[] = [];
|
|
854
|
-
try {
|
|
855
|
-
validateDynamicCollection(step.collect.outputSchema, collection);
|
|
856
|
-
} catch (error) {
|
|
857
|
-
const message = error instanceof DynamicFanoutError ? error.message : error instanceof Error ? error.message : String(error);
|
|
858
|
-
dynamicGroupStatuses[stepIndex] = { status: "failed", error: message };
|
|
859
|
-
return buildChainExecutionErrorResult(message, makeDetailsInput({ currentStepIndex: stepIndex, currentFlatIndex: globalTaskIndex }));
|
|
860
|
-
}
|
|
861
|
-
outputs[step.collect.as] = {
|
|
862
|
-
text: JSON.stringify(collection),
|
|
863
|
-
structured: collection,
|
|
864
|
-
agent: step.parallel.agent,
|
|
865
|
-
stepIndex,
|
|
866
|
-
};
|
|
867
|
-
dynamicGroupStatuses[stepIndex] = { status: "completed" };
|
|
868
|
-
if (step.acceptance !== undefined) {
|
|
869
|
-
const effectiveGroupAcceptance = resolveEffectiveAcceptance({
|
|
870
|
-
explicit: step.acceptance,
|
|
871
|
-
agentName: step.parallel.agent,
|
|
872
|
-
task: step.parallel.task ?? originalTask,
|
|
873
|
-
mode: "chain",
|
|
874
|
-
dynamicGroup: true,
|
|
875
|
-
});
|
|
876
|
-
const groupAcceptance = await evaluateAcceptance({
|
|
877
|
-
acceptance: effectiveGroupAcceptance,
|
|
878
|
-
output: "",
|
|
879
|
-
report: aggregateAcceptanceReport({
|
|
880
|
-
results: [],
|
|
881
|
-
notes: "Dynamic fanout produced 0 results.",
|
|
882
|
-
}),
|
|
883
|
-
cwd: cwd ?? ctx.cwd,
|
|
884
|
-
});
|
|
885
|
-
dynamicGroupStatuses[stepIndex].acceptance = groupAcceptance;
|
|
886
|
-
const groupAcceptanceFailure = acceptanceFailureMessage(groupAcceptance);
|
|
887
|
-
if (groupAcceptanceFailure) {
|
|
888
|
-
dynamicGroupStatuses[stepIndex] = { status: "failed", error: groupAcceptanceFailure, acceptance: groupAcceptance };
|
|
889
|
-
return buildChainExecutionErrorResult(groupAcceptanceFailure, makeDetailsInput({ currentStepIndex: stepIndex, currentFlatIndex: globalTaskIndex }));
|
|
890
|
-
}
|
|
891
|
-
}
|
|
892
|
-
prev = "Dynamic fanout produced 0 results.";
|
|
893
|
-
globalTaskIndex = dynamicStartIndex + reservedDynamicItems;
|
|
894
|
-
continue;
|
|
895
|
-
}
|
|
896
|
-
|
|
897
|
-
const dynamicParallelStep: ParallelStep = {
|
|
898
|
-
parallel: materialized.parallel,
|
|
899
|
-
concurrency: step.concurrency,
|
|
900
|
-
failFast: step.failFast,
|
|
901
|
-
};
|
|
902
|
-
const parallelTemplates = materialized.parallel.map((task) => task.task ?? "{previous}");
|
|
903
|
-
const parallelBehaviors = resolveParallelBehaviors(dynamicParallelStep.parallel, agents, stepIndex, chainSkills)
|
|
904
|
-
.map((behavior, taskIndex) => suppressProgressForReadOnlyTask(behavior, parallelTemplates[taskIndex] ?? dynamicParallelStep.parallel[taskIndex]?.task, originalTask));
|
|
905
|
-
|
|
906
|
-
for (let taskIndex = 0; taskIndex < dynamicParallelStep.parallel.length; taskIndex++) {
|
|
907
|
-
const behavior = parallelBehaviors[taskIndex]!;
|
|
908
|
-
const outputPath = typeof behavior.output === "string"
|
|
909
|
-
? (path.isAbsolute(behavior.output) ? behavior.output : path.join(chainDir, behavior.output))
|
|
910
|
-
: undefined;
|
|
911
|
-
const validationError = validateFileOnlyOutputMode(behavior.outputMode, outputPath, `Dynamic chain step ${stepIndex + 1} item ${taskIndex + 1} (${dynamicParallelStep.parallel[taskIndex]!.agent})`);
|
|
912
|
-
if (validationError) {
|
|
913
|
-
dynamicGroupStatuses[stepIndex] = { status: "failed", error: validationError };
|
|
914
|
-
return buildChainExecutionErrorResult(validationError, makeDetailsInput({ currentStepIndex: stepIndex, currentFlatIndex: globalTaskIndex + taskIndex }));
|
|
915
|
-
}
|
|
916
|
-
}
|
|
917
|
-
|
|
918
|
-
progressCreated = ensureParallelProgressFile(chainDir, progressCreated, parallelBehaviors);
|
|
919
|
-
createParallelDirs(chainDir, stepIndex, dynamicParallelStep.parallel.length, dynamicParallelStep.parallel.map((task) => task.agent));
|
|
920
|
-
const parallelResults = await runParallelChainTasks({
|
|
921
|
-
step: dynamicParallelStep,
|
|
922
|
-
parallelTemplates,
|
|
923
|
-
parallelBehaviors,
|
|
924
|
-
agents,
|
|
925
|
-
stepIndex,
|
|
926
|
-
availableModels,
|
|
927
|
-
modelScope,
|
|
928
|
-
chainDir,
|
|
929
|
-
prev,
|
|
930
|
-
originalTask,
|
|
931
|
-
ctx,
|
|
932
|
-
intercomEvents,
|
|
933
|
-
cwd,
|
|
934
|
-
runId,
|
|
935
|
-
globalTaskIndex,
|
|
936
|
-
sessionDirForIndex,
|
|
937
|
-
sessionFileForIndex,
|
|
938
|
-
sessionFileForTask,
|
|
939
|
-
thinkingOverrideForTask,
|
|
940
|
-
shareEnabled,
|
|
941
|
-
artifactConfig,
|
|
942
|
-
artifactsDir,
|
|
943
|
-
signal,
|
|
944
|
-
onUpdate,
|
|
945
|
-
results,
|
|
946
|
-
allProgress,
|
|
947
|
-
outputs,
|
|
948
|
-
chainAgents,
|
|
949
|
-
chainSteps,
|
|
950
|
-
totalSteps,
|
|
951
|
-
dynamicChildren,
|
|
952
|
-
dynamicGroupStatuses,
|
|
953
|
-
controlConfig,
|
|
954
|
-
onControlEvent,
|
|
955
|
-
childIntercomTarget,
|
|
956
|
-
orchestratorIntercomTarget,
|
|
957
|
-
foregroundControl,
|
|
958
|
-
nestedRoute: params.nestedRoute,
|
|
959
|
-
maxSubagentDepth: params.maxSubagentDepth,
|
|
960
|
-
timeoutMs: params.timeoutMs,
|
|
961
|
-
deadlineAt,
|
|
962
|
-
turnBudget: params.turnBudget,
|
|
963
|
-
onDetachedExit,
|
|
964
|
-
toolBudget: params.toolBudget,
|
|
965
|
-
configToolBudget: params.configToolBudget,
|
|
966
|
-
globalSemaphore,
|
|
967
|
-
});
|
|
968
|
-
globalTaskIndex = dynamicStartIndex + reservedDynamicItems;
|
|
969
|
-
|
|
970
|
-
for (const result of parallelResults) {
|
|
971
|
-
results.push(result);
|
|
972
|
-
if (result.progress) allProgress.push(result.progress);
|
|
973
|
-
if (result.artifactPaths) allArtifactPaths.push(result.artifactPaths);
|
|
974
|
-
}
|
|
975
|
-
const collected = collectDynamicResults(step, materialized.items, parallelResults);
|
|
976
|
-
const interruptedIndexInStep = parallelResults.findIndex((result) => result.interrupted);
|
|
977
|
-
const interrupted = interruptedIndexInStep >= 0 ? parallelResults[interruptedIndexInStep] : undefined;
|
|
978
|
-
if (interrupted) {
|
|
979
|
-
return {
|
|
980
|
-
content: [{ type: "text", text: `Chain paused after interrupt at step ${stepIndex + 1} (${interrupted.agent}). Waiting for explicit next action.` }],
|
|
981
|
-
details: buildChainExecutionDetails(makeDetailsInput({
|
|
982
|
-
currentStepIndex: stepIndex,
|
|
983
|
-
currentFlatIndex: dynamicStartIndex + interruptedIndexInStep,
|
|
984
|
-
})),
|
|
985
|
-
};
|
|
986
|
-
}
|
|
987
|
-
const detachedIndexInStep = parallelResults.findIndex((result) => result.detached);
|
|
988
|
-
const detached = detachedIndexInStep >= 0 ? parallelResults[detachedIndexInStep] : undefined;
|
|
989
|
-
if (detached) {
|
|
990
|
-
return {
|
|
991
|
-
content: [{ type: "text", text: `Chain detached for intercom coordination at step ${stepIndex + 1} (${detached.agent}). Reply to the supervisor request first. After the child exits, start a fresh follow-up if needed.` }],
|
|
992
|
-
details: buildChainExecutionDetails(makeDetailsInput({
|
|
993
|
-
currentStepIndex: stepIndex,
|
|
994
|
-
currentFlatIndex: dynamicStartIndex + detachedIndexInStep,
|
|
995
|
-
})),
|
|
996
|
-
};
|
|
997
|
-
}
|
|
998
|
-
const failures = parallelResults
|
|
999
|
-
.map((result, originalIndex) => ({ ...result, originalIndex }))
|
|
1000
|
-
.filter((result) => result.exitCode !== 0 && result.exitCode !== -1);
|
|
1001
|
-
if (failures.length > 0) {
|
|
1002
|
-
const failureSummary = failures
|
|
1003
|
-
.map((failure) => `- Item ${failure.originalIndex + 1} (${failure.agent}, key ${materialized.items[failure.originalIndex]?.key ?? failure.originalIndex}): ${failure.error || "failed"}`)
|
|
1004
|
-
.join("\n");
|
|
1005
|
-
const errorMsg = `Dynamic step ${stepIndex + 1} failed:\n${failureSummary}`;
|
|
1006
|
-
dynamicGroupStatuses[stepIndex] = { status: "failed", error: errorMsg };
|
|
1007
|
-
const summary = buildChainSummary(chainSteps, results, chainDir, "failed", {
|
|
1008
|
-
index: stepIndex,
|
|
1009
|
-
error: errorMsg,
|
|
1010
|
-
});
|
|
1011
|
-
return {
|
|
1012
|
-
content: [{ type: "text", text: summary }],
|
|
1013
|
-
isError: true,
|
|
1014
|
-
details: buildChainExecutionDetails(makeDetailsInput({
|
|
1015
|
-
currentStepIndex: stepIndex,
|
|
1016
|
-
currentFlatIndex: dynamicStartIndex + failures[0]!.originalIndex,
|
|
1017
|
-
})),
|
|
1018
|
-
};
|
|
1019
|
-
}
|
|
1020
|
-
try {
|
|
1021
|
-
validateDynamicCollection(step.collect.outputSchema, collected);
|
|
1022
|
-
} catch (error) {
|
|
1023
|
-
const message = error instanceof DynamicFanoutError ? error.message : error instanceof Error ? error.message : String(error);
|
|
1024
|
-
dynamicGroupStatuses[stepIndex] = { status: "failed", error: message };
|
|
1025
|
-
return buildChainExecutionErrorResult(message, makeDetailsInput({ currentStepIndex: stepIndex, currentFlatIndex: dynamicStartIndex }));
|
|
1026
|
-
}
|
|
1027
|
-
outputs[step.collect.as] = {
|
|
1028
|
-
text: JSON.stringify(collected),
|
|
1029
|
-
structured: collected,
|
|
1030
|
-
agent: step.parallel.agent,
|
|
1031
|
-
stepIndex,
|
|
1032
|
-
};
|
|
1033
|
-
dynamicGroupStatuses[stepIndex] = { status: "completed" };
|
|
1034
|
-
const effectiveGroupAcceptance = resolveEffectiveAcceptance({
|
|
1035
|
-
explicit: step.acceptance,
|
|
1036
|
-
agentName: step.parallel.agent,
|
|
1037
|
-
task: step.parallel.task ?? originalTask,
|
|
1038
|
-
mode: "chain",
|
|
1039
|
-
dynamicGroup: true,
|
|
1040
|
-
});
|
|
1041
|
-
const groupAcceptance = await evaluateAcceptance({
|
|
1042
|
-
acceptance: effectiveGroupAcceptance,
|
|
1043
|
-
output: "",
|
|
1044
|
-
report: aggregateAcceptanceReport({
|
|
1045
|
-
results: parallelResults,
|
|
1046
|
-
notes: `Dynamic fanout collected ${collected.length} result(s) into ${step.collect.as}.`,
|
|
1047
|
-
}),
|
|
1048
|
-
cwd: cwd ?? ctx.cwd,
|
|
1049
|
-
});
|
|
1050
|
-
dynamicGroupStatuses[stepIndex].acceptance = groupAcceptance;
|
|
1051
|
-
const groupAcceptanceFailure = acceptanceFailureMessage(groupAcceptance);
|
|
1052
|
-
if (groupAcceptanceFailure) {
|
|
1053
|
-
dynamicGroupStatuses[stepIndex] = { status: "failed", error: groupAcceptanceFailure, acceptance: groupAcceptance };
|
|
1054
|
-
return buildChainExecutionErrorResult(groupAcceptanceFailure, makeDetailsInput({ currentStepIndex: stepIndex, currentFlatIndex: globalTaskIndex - dynamicParallelStep.parallel.length }));
|
|
1055
|
-
}
|
|
1056
|
-
const taskResults: ParallelTaskResult[] = parallelResults.map((result, i) => ({
|
|
1057
|
-
agent: result.agent,
|
|
1058
|
-
taskIndex: i,
|
|
1059
|
-
output: getSingleResultOutput(result),
|
|
1060
|
-
exitCode: result.exitCode,
|
|
1061
|
-
error: result.error,
|
|
1062
|
-
timedOut: result.timedOut,
|
|
1063
|
-
}));
|
|
1064
|
-
prev = aggregateParallelOutputs(taskResults, (i, agent) => `=== Dynamic Item ${i + 1} (${agent}, key ${materialized.items[i]?.key ?? i}) ===`);
|
|
1065
|
-
} else {
|
|
1066
|
-
const seqStep = step as SequentialStep;
|
|
1067
|
-
const stepTemplate = stepTemplates as string;
|
|
1068
|
-
|
|
1069
|
-
const agentConfig = agents.find((a) => a.name === seqStep.agent);
|
|
1070
|
-
if (!agentConfig) {
|
|
1071
|
-
removeChainDir(chainDir);
|
|
1072
|
-
return {
|
|
1073
|
-
content: [{ type: "text", text: `Unknown agent: ${seqStep.agent}` }],
|
|
1074
|
-
isError: true,
|
|
1075
|
-
details: buildChainExecutionDetails(makeDetailsInput({ currentStepIndex: stepIndex, currentFlatIndex: globalTaskIndex })),
|
|
1076
|
-
};
|
|
1077
|
-
}
|
|
1078
|
-
|
|
1079
|
-
const tuiOverride = tuiBehaviorOverrides?.[stepIndex];
|
|
1080
|
-
const stepOverride: StepOverrides = {
|
|
1081
|
-
output: tuiOverride?.output !== undefined ? tuiOverride.output : seqStep.output,
|
|
1082
|
-
outputMode: seqStep.outputMode,
|
|
1083
|
-
reads: tuiOverride?.reads !== undefined ? tuiOverride.reads : seqStep.reads,
|
|
1084
|
-
progress: tuiOverride?.progress !== undefined ? tuiOverride.progress : seqStep.progress,
|
|
1085
|
-
skills:
|
|
1086
|
-
tuiOverride?.skills !== undefined
|
|
1087
|
-
? tuiOverride.skills
|
|
1088
|
-
: normalizeSkillInput(seqStep.skill),
|
|
1089
|
-
};
|
|
1090
|
-
const behavior = suppressProgressForReadOnlyTask(resolveStepBehavior(agentConfig, stepOverride, chainSkills), stepTemplate, originalTask);
|
|
1091
|
-
|
|
1092
|
-
const isFirstProgress = behavior.progress && !progressCreated;
|
|
1093
|
-
if (isFirstProgress) {
|
|
1094
|
-
progressCreated = true;
|
|
1095
|
-
}
|
|
1096
|
-
|
|
1097
|
-
const templateHasPrevious = stepTemplate.includes("{previous}");
|
|
1098
|
-
const { prefix, suffix } = buildChainInstructions(
|
|
1099
|
-
behavior,
|
|
1100
|
-
chainDir,
|
|
1101
|
-
isFirstProgress,
|
|
1102
|
-
templateHasPrevious ? undefined : prev,
|
|
1103
|
-
);
|
|
1104
|
-
|
|
1105
|
-
let stepTask = resolveOutputReferences(stepTemplate, outputs);
|
|
1106
|
-
stepTask = stepTask.replace(/\{task\}/g, originalTask);
|
|
1107
|
-
stepTask = stepTask.replace(/\{previous\}/g, prev);
|
|
1108
|
-
stepTask = stepTask.replace(/\{chain_dir\}/g, chainDir);
|
|
1109
|
-
const cleanTask = stepTask;
|
|
1110
|
-
stepTask = prefix + stepTask + suffix;
|
|
1111
|
-
|
|
1112
|
-
const explicitStepModel = tuiOverride?.model ?? seqStep.model;
|
|
1113
|
-
const effectiveModel = resolveSubagentModelOverride(
|
|
1114
|
-
explicitStepModel ?? agentConfig.model,
|
|
1115
|
-
ctx.model,
|
|
1116
|
-
availableModels,
|
|
1117
|
-
ctx.model?.provider,
|
|
1118
|
-
{ scope: modelScope, source: explicitStepModel ? "explicit" : "inherited" },
|
|
1119
|
-
);
|
|
1120
|
-
|
|
1121
|
-
const outputPath = typeof behavior.output === "string"
|
|
1122
|
-
? (path.isAbsolute(behavior.output) ? behavior.output : path.join(chainDir, behavior.output))
|
|
1123
|
-
: undefined;
|
|
1124
|
-
const validationError = validateFileOnlyOutputMode(behavior.outputMode, outputPath, `Chain step ${stepIndex + 1} (${seqStep.agent})`);
|
|
1125
|
-
if (validationError) {
|
|
1126
|
-
return buildChainExecutionErrorResult(validationError, makeDetailsInput({ currentStepIndex: stepIndex, currentFlatIndex: globalTaskIndex }));
|
|
1127
|
-
}
|
|
1128
|
-
const maxSubagentDepth = resolveChildMaxSubagentDepth(params.maxSubagentDepth, agentConfig.maxSubagentDepth);
|
|
1129
|
-
const childIndex = globalTaskIndex;
|
|
1130
|
-
const interruptController = new AbortController();
|
|
1131
|
-
if (foregroundControl) {
|
|
1132
|
-
foregroundControl.currentAgent = seqStep.agent;
|
|
1133
|
-
foregroundControl.currentIndex = childIndex;
|
|
1134
|
-
foregroundControl.currentActivityState = undefined;
|
|
1135
|
-
foregroundControl.updatedAt = Date.now();
|
|
1136
|
-
foregroundControl.interrupt = () => {
|
|
1137
|
-
if (interruptController.signal.aborted) return false;
|
|
1138
|
-
interruptController.abort();
|
|
1139
|
-
foregroundControl.currentActivityState = undefined;
|
|
1140
|
-
foregroundControl.updatedAt = Date.now();
|
|
1141
|
-
return true;
|
|
1142
|
-
};
|
|
1143
|
-
}
|
|
1144
|
-
|
|
1145
|
-
const structuredRuntime = seqStep.outputSchema
|
|
1146
|
-
? createStructuredOutputRuntime(seqStep.outputSchema, path.join(chainDir, "structured-output"))
|
|
1147
|
-
: undefined;
|
|
1148
|
-
const toolBudget = resolveChainToolBudget({ stepBudget: seqStep.toolBudget, runBudget: params.toolBudget, agentBudget: agentConfig?.toolBudget, configBudget: params.configToolBudget });
|
|
1149
|
-
if (toolBudget.error) return buildChainExecutionErrorResult(toolBudget.error, {
|
|
1150
|
-
results,
|
|
1151
|
-
includeProgress,
|
|
1152
|
-
allProgress,
|
|
1153
|
-
allArtifactPaths,
|
|
1154
|
-
artifactsDir: params.artifactsDir,
|
|
1155
|
-
chainAgents,
|
|
1156
|
-
chainSteps,
|
|
1157
|
-
totalSteps,
|
|
1158
|
-
currentStepIndex: stepIndex,
|
|
1159
|
-
runId: params.runId,
|
|
1160
|
-
outputs,
|
|
1161
|
-
currentFlatIndex: globalTaskIndex,
|
|
1162
|
-
dynamicChildren,
|
|
1163
|
-
dynamicGroupStatuses,
|
|
1164
|
-
});
|
|
1165
|
-
const r = await runSync(ctx.cwd, agents, seqStep.agent, stepTask, {
|
|
1166
|
-
parentSessionId: ctx.sessionManager.getSessionId() ?? undefined,
|
|
1167
|
-
cwd: resolveChildCwd(cwd ?? ctx.cwd, seqStep.cwd),
|
|
1168
|
-
signal,
|
|
1169
|
-
interruptSignal: interruptController.signal,
|
|
1170
|
-
allowIntercomDetach: agentConfig.systemPrompt?.includes(INTERCOM_BRIDGE_MARKER) === true,
|
|
1171
|
-
intercomEvents,
|
|
1172
|
-
runId,
|
|
1173
|
-
index: childIndex,
|
|
1174
|
-
sessionDir: sessionDirForIndex(childIndex),
|
|
1175
|
-
sessionFile: sessionFileForTask?.(seqStep.agent, childIndex)
|
|
1176
|
-
?? sessionFileForIndex?.(childIndex),
|
|
1177
|
-
thinkingOverride: thinkingOverrideForTask?.(seqStep.agent, childIndex),
|
|
1178
|
-
share: shareEnabled,
|
|
1179
|
-
artifactsDir: artifactConfig.enabled ? artifactsDir : undefined,
|
|
1180
|
-
artifactConfig,
|
|
1181
|
-
outputPath,
|
|
1182
|
-
outputMode: behavior.outputMode,
|
|
1183
|
-
maxSubagentDepth,
|
|
1184
|
-
controlConfig,
|
|
1185
|
-
onControlEvent,
|
|
1186
|
-
intercomSessionName: childIntercomTarget?.(seqStep.agent, childIndex),
|
|
1187
|
-
orchestratorIntercomTarget,
|
|
1188
|
-
nestedRoute: params.nestedRoute,
|
|
1189
|
-
modelOverride: effectiveModel,
|
|
1190
|
-
availableModels,
|
|
1191
|
-
preferredModelProvider: ctx.model?.provider,
|
|
1192
|
-
modelScope,
|
|
1193
|
-
skills: behavior.skills === false ? [] : behavior.skills,
|
|
1194
|
-
structuredOutput: structuredRuntime,
|
|
1195
|
-
acceptance: seqStep.acceptance,
|
|
1196
|
-
acceptanceContext: { mode: "chain" },
|
|
1197
|
-
timeoutMs: params.timeoutMs,
|
|
1198
|
-
deadlineAt,
|
|
1199
|
-
turnBudget: params.turnBudget,
|
|
1200
|
-
onDetachedExit: onDetachedExit
|
|
1201
|
-
? (result) => onDetachedExit(childIndex, result)
|
|
1202
|
-
: undefined,
|
|
1203
|
-
toolBudget: toolBudget.toolBudget,
|
|
1204
|
-
onUpdate: onUpdate
|
|
1205
|
-
? (p) => {
|
|
1206
|
-
const stepResults = p.details?.results || [];
|
|
1207
|
-
const stepProgress = p.details?.progress || [];
|
|
1208
|
-
if (foregroundControl && stepProgress.length > 0) {
|
|
1209
|
-
const current = stepProgress[0];
|
|
1210
|
-
foregroundControl.currentAgent = seqStep.agent;
|
|
1211
|
-
foregroundControl.currentIndex = childIndex;
|
|
1212
|
-
foregroundControl.currentActivityState = current?.activityState;
|
|
1213
|
-
foregroundControl.lastActivityAt = current?.lastActivityAt;
|
|
1214
|
-
foregroundControl.currentTool = current?.currentTool;
|
|
1215
|
-
foregroundControl.currentToolStartedAt = current?.currentToolStartedAt;
|
|
1216
|
-
foregroundControl.currentPath = current?.currentPath;
|
|
1217
|
-
foregroundControl.turnCount = current?.turnCount;
|
|
1218
|
-
foregroundControl.tokens = current?.tokens;
|
|
1219
|
-
foregroundControl.toolCount = current?.toolCount;
|
|
1220
|
-
foregroundControl.updatedAt = Date.now();
|
|
1221
|
-
}
|
|
1222
|
-
onUpdate({
|
|
1223
|
-
...p,
|
|
1224
|
-
details: {
|
|
1225
|
-
mode: "chain",
|
|
1226
|
-
results: results.concat(stepResults),
|
|
1227
|
-
progress: allProgress.concat(stepProgress),
|
|
1228
|
-
controlEvents: p.details?.controlEvents,
|
|
1229
|
-
chainAgents,
|
|
1230
|
-
totalSteps,
|
|
1231
|
-
currentStepIndex: stepIndex,
|
|
1232
|
-
outputs,
|
|
1233
|
-
workflowGraph: buildWorkflowGraphSnapshot({
|
|
1234
|
-
runId,
|
|
1235
|
-
mode: "chain",
|
|
1236
|
-
steps: chainSteps,
|
|
1237
|
-
results: results.concat(stepResults),
|
|
1238
|
-
currentStepIndex: stepIndex,
|
|
1239
|
-
currentFlatIndex: childIndex,
|
|
1240
|
-
dynamicChildren,
|
|
1241
|
-
dynamicGroupStatuses,
|
|
1242
|
-
}),
|
|
1243
|
-
},
|
|
1244
|
-
});
|
|
1245
|
-
}
|
|
1246
|
-
: undefined,
|
|
1247
|
-
});
|
|
1248
|
-
if (foregroundControl?.currentIndex === childIndex) {
|
|
1249
|
-
foregroundControl.interrupt = undefined;
|
|
1250
|
-
foregroundControl.updatedAt = Date.now();
|
|
1251
|
-
}
|
|
1252
|
-
recordRun(seqStep.agent, cleanTask, r.exitCode, r.progressSummary?.durationMs ?? 0);
|
|
1253
|
-
|
|
1254
|
-
globalTaskIndex++;
|
|
1255
|
-
results.push(r);
|
|
1256
|
-
if (r.progress) allProgress.push(r.progress);
|
|
1257
|
-
if (r.artifactPaths) allArtifactPaths.push(r.artifactPaths);
|
|
1258
|
-
|
|
1259
|
-
if (r.interrupted) {
|
|
1260
|
-
return {
|
|
1261
|
-
content: [{ type: "text", text: `Chain paused after interrupt at step ${stepIndex + 1} (${r.agent}). Waiting for explicit next action.` }],
|
|
1262
|
-
details: buildChainExecutionDetails(makeDetailsInput({ currentStepIndex: stepIndex, currentFlatIndex: childIndex })),
|
|
1263
|
-
};
|
|
1264
|
-
}
|
|
1265
|
-
if (r.detached) {
|
|
1266
|
-
return {
|
|
1267
|
-
content: [{ type: "text", text: `Chain detached for intercom coordination at step ${stepIndex + 1} (${r.agent}). Reply to the supervisor request first. After the child exits, start a fresh follow-up if needed.` }],
|
|
1268
|
-
details: buildChainExecutionDetails(makeDetailsInput({ currentStepIndex: stepIndex, currentFlatIndex: childIndex })),
|
|
1269
|
-
};
|
|
1270
|
-
}
|
|
1271
|
-
|
|
1272
|
-
if (r.exitCode !== 0) {
|
|
1273
|
-
const summary = buildChainSummary(chainSteps, results, chainDir, "failed", {
|
|
1274
|
-
index: stepIndex,
|
|
1275
|
-
error: r.error || "Chain failed",
|
|
1276
|
-
});
|
|
1277
|
-
return {
|
|
1278
|
-
content: [{ type: "text", text: summary }],
|
|
1279
|
-
details: buildChainExecutionDetails(makeDetailsInput({ currentStepIndex: stepIndex, currentFlatIndex: childIndex })),
|
|
1280
|
-
isError: true,
|
|
1281
|
-
};
|
|
1282
|
-
}
|
|
1283
|
-
|
|
1284
|
-
if (behavior.output) {
|
|
1285
|
-
try {
|
|
1286
|
-
const expectedPath = path.isAbsolute(behavior.output)
|
|
1287
|
-
? behavior.output
|
|
1288
|
-
: path.join(chainDir, behavior.output);
|
|
1289
|
-
if (!fs.existsSync(expectedPath)) {
|
|
1290
|
-
const dirFiles = fs.readdirSync(chainDir);
|
|
1291
|
-
const mdFiles = dirFiles.filter((file) => file.endsWith(".md") && file !== "progress.md");
|
|
1292
|
-
const warning = mdFiles.length > 0
|
|
1293
|
-
? `Agent wrote to different file(s): ${mdFiles.join(", ")} instead of ${behavior.output}`
|
|
1294
|
-
: `Agent did not create expected output file: ${behavior.output}`;
|
|
1295
|
-
r.error = r.error ? `${r.error}\n${warning}` : warning;
|
|
1296
|
-
}
|
|
1297
|
-
} catch {
|
|
1298
|
-
// Ignore validation errors; this diagnostic should not mask successful chain output.
|
|
1299
|
-
}
|
|
1300
|
-
}
|
|
1301
|
-
|
|
1302
|
-
if (seqStep.as) outputs[seqStep.as] = outputEntryFromResult(r, stepIndex);
|
|
1303
|
-
prev = getSingleResultOutput(r);
|
|
1304
|
-
}
|
|
1305
|
-
}
|
|
1306
|
-
|
|
1307
|
-
const summary = buildChainSummary(chainSteps, results, chainDir, "completed");
|
|
1308
|
-
|
|
1309
|
-
return {
|
|
1310
|
-
content: [{ type: "text", text: summary }],
|
|
1311
|
-
details: buildChainExecutionDetails(makeDetailsInput()),
|
|
1312
|
-
};
|
|
1313
|
-
}
|