@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
|
@@ -1,128 +0,0 @@
|
|
|
1
|
-
import * as path from "node:path";
|
|
2
|
-
import { appendJsonl } from "../../shared/artifacts.ts";
|
|
3
|
-
import { writeAtomicJson } from "../../shared/atomic-json.ts";
|
|
4
|
-
import { writeInitialProgressFile } from "../../shared/settings.ts";
|
|
5
|
-
import { diffWorktrees, formatWorktreeDiffSummary, type WorktreeSetup } from "../shared/worktree.ts";
|
|
6
|
-
import type { ParallelGroup, RunnerStatusPayload, StepResult, SubagentStep } from "./subagent-runner-types.ts";
|
|
7
|
-
|
|
8
|
-
export function markParallelGroupSetupFailure(input: {
|
|
9
|
-
statusPayload: RunnerStatusPayload;
|
|
10
|
-
results: StepResult[];
|
|
11
|
-
group: ParallelGroup;
|
|
12
|
-
groupStartFlatIndex: number;
|
|
13
|
-
setupError: string;
|
|
14
|
-
failedAt: number;
|
|
15
|
-
statusPath: string;
|
|
16
|
-
eventsPath: string;
|
|
17
|
-
asyncDir: string;
|
|
18
|
-
runId: string;
|
|
19
|
-
stepIndex: number;
|
|
20
|
-
}): void {
|
|
21
|
-
for (let taskIndex = 0; taskIndex < input.group.parallel.length; taskIndex++) {
|
|
22
|
-
const flatTaskIndex = input.groupStartFlatIndex + taskIndex;
|
|
23
|
-
input.statusPayload.steps[flatTaskIndex].status = "failed";
|
|
24
|
-
input.statusPayload.steps[flatTaskIndex].startedAt = input.failedAt;
|
|
25
|
-
input.statusPayload.steps[flatTaskIndex].endedAt = input.failedAt;
|
|
26
|
-
input.statusPayload.steps[flatTaskIndex].durationMs = 0;
|
|
27
|
-
input.statusPayload.steps[flatTaskIndex].exitCode = 1;
|
|
28
|
-
input.results.push({
|
|
29
|
-
agent: input.group.parallel[taskIndex].agent,
|
|
30
|
-
output: input.setupError,
|
|
31
|
-
success: false,
|
|
32
|
-
exitCode: 1,
|
|
33
|
-
sessionFile: input.group.parallel[taskIndex].sessionFile,
|
|
34
|
-
});
|
|
35
|
-
}
|
|
36
|
-
input.statusPayload.currentStep = input.groupStartFlatIndex;
|
|
37
|
-
input.statusPayload.lastUpdate = input.failedAt;
|
|
38
|
-
input.statusPayload.outputFile = path.join(input.asyncDir, `output-${input.groupStartFlatIndex}.log`);
|
|
39
|
-
writeAtomicJson(input.statusPath, input.statusPayload);
|
|
40
|
-
appendJsonl(
|
|
41
|
-
input.eventsPath,
|
|
42
|
-
JSON.stringify({
|
|
43
|
-
type: "subagent.parallel.completed",
|
|
44
|
-
ts: input.failedAt,
|
|
45
|
-
runId: input.runId,
|
|
46
|
-
stepIndex: input.stepIndex,
|
|
47
|
-
success: false,
|
|
48
|
-
}),
|
|
49
|
-
);
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
export function markParallelGroupRunning(input: {
|
|
53
|
-
statusPayload: RunnerStatusPayload;
|
|
54
|
-
group: ParallelGroup;
|
|
55
|
-
groupStartFlatIndex: number;
|
|
56
|
-
groupStartTime: number;
|
|
57
|
-
statusPath: string;
|
|
58
|
-
eventsPath: string;
|
|
59
|
-
asyncDir: string;
|
|
60
|
-
runId: string;
|
|
61
|
-
stepIndex: number;
|
|
62
|
-
}): void {
|
|
63
|
-
for (let taskIndex = 0; taskIndex < input.group.parallel.length; taskIndex++) {
|
|
64
|
-
const flatTaskIndex = input.groupStartFlatIndex + taskIndex;
|
|
65
|
-
input.statusPayload.steps[flatTaskIndex].status = "pending";
|
|
66
|
-
input.statusPayload.steps[flatTaskIndex].startedAt = undefined;
|
|
67
|
-
input.statusPayload.steps[flatTaskIndex].endedAt = undefined;
|
|
68
|
-
input.statusPayload.steps[flatTaskIndex].durationMs = undefined;
|
|
69
|
-
input.statusPayload.steps[flatTaskIndex].lastActivityAt = undefined;
|
|
70
|
-
input.statusPayload.steps[flatTaskIndex].activityState = undefined;
|
|
71
|
-
input.statusPayload.steps[flatTaskIndex].error = undefined;
|
|
72
|
-
}
|
|
73
|
-
input.statusPayload.currentStep = input.groupStartFlatIndex;
|
|
74
|
-
input.statusPayload.activityState = undefined;
|
|
75
|
-
input.statusPayload.lastActivityAt = input.groupStartTime;
|
|
76
|
-
input.statusPayload.lastUpdate = input.groupStartTime;
|
|
77
|
-
input.statusPayload.outputFile = path.join(input.asyncDir, `output-${input.groupStartFlatIndex}.log`);
|
|
78
|
-
writeAtomicJson(input.statusPath, input.statusPayload);
|
|
79
|
-
appendJsonl(
|
|
80
|
-
input.eventsPath,
|
|
81
|
-
JSON.stringify({
|
|
82
|
-
type: "subagent.parallel.started",
|
|
83
|
-
ts: input.groupStartTime,
|
|
84
|
-
runId: input.runId,
|
|
85
|
-
stepIndex: input.stepIndex,
|
|
86
|
-
agents: input.group.parallel.map((task) => task.agent),
|
|
87
|
-
count: input.group.parallel.length,
|
|
88
|
-
}),
|
|
89
|
-
);
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
export function prepareParallelTaskRun(
|
|
93
|
-
task: SubagentStep,
|
|
94
|
-
cwd: string,
|
|
95
|
-
worktreeSetup: WorktreeSetup | undefined,
|
|
96
|
-
taskIndex: number,
|
|
97
|
-
): { taskForRun: SubagentStep; taskCwd: string } {
|
|
98
|
-
if (!worktreeSetup) return { taskForRun: task, taskCwd: cwd };
|
|
99
|
-
return {
|
|
100
|
-
taskForRun: { ...task, cwd: undefined },
|
|
101
|
-
taskCwd: worktreeSetup.worktrees[taskIndex]!.agentCwd,
|
|
102
|
-
};
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
export function appendParallelWorktreeSummary(
|
|
106
|
-
previousOutput: string,
|
|
107
|
-
worktreeSetup: WorktreeSetup | undefined,
|
|
108
|
-
asyncDir: string,
|
|
109
|
-
stepIndex: number,
|
|
110
|
-
group: ParallelGroup,
|
|
111
|
-
): string {
|
|
112
|
-
if (!worktreeSetup) return previousOutput;
|
|
113
|
-
const diffsDir = path.join(asyncDir, "worktree-diffs", `step-${stepIndex}`);
|
|
114
|
-
const diffs = diffWorktrees(
|
|
115
|
-
worktreeSetup,
|
|
116
|
-
group.parallel.map((task) => task.agent),
|
|
117
|
-
diffsDir,
|
|
118
|
-
);
|
|
119
|
-
const diffSummary = formatWorktreeDiffSummary(diffs);
|
|
120
|
-
if (!diffSummary) return previousOutput;
|
|
121
|
-
return `${previousOutput}\n\n${diffSummary}`;
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
export function ensureParallelProgressFile(cwd: string, group: ParallelGroup): void {
|
|
125
|
-
const progressPath = path.join(cwd, "progress.md");
|
|
126
|
-
if (!group.parallel.some((task) => task.task.includes(`Update progress at: ${progressPath}`))) return;
|
|
127
|
-
writeInitialProgressFile(cwd);
|
|
128
|
-
}
|
|
@@ -1,309 +0,0 @@
|
|
|
1
|
-
import * as path from "node:path";
|
|
2
|
-
import { appendJsonl } from "../../shared/artifacts.ts";
|
|
3
|
-
import { resolveEffectiveThinking } from "../../shared/model-info.ts";
|
|
4
|
-
import { parseSessionTokens } from "../../shared/session-tokens.ts";
|
|
5
|
-
import { aggregateParallelOutputs, MAX_PARALLEL_CONCURRENCY, mapConcurrent } from "../shared/parallel-utils.ts";
|
|
6
|
-
import {
|
|
7
|
-
cleanupWorktrees,
|
|
8
|
-
createWorktrees,
|
|
9
|
-
findWorktreeTaskCwdConflict,
|
|
10
|
-
formatWorktreeTaskCwdConflict,
|
|
11
|
-
type WorktreeSetup,
|
|
12
|
-
} from "../shared/worktree.ts";
|
|
13
|
-
import {
|
|
14
|
-
appendParallelWorktreeSummary,
|
|
15
|
-
ensureParallelProgressFile,
|
|
16
|
-
markParallelGroupRunning,
|
|
17
|
-
markParallelGroupSetupFailure,
|
|
18
|
-
prepareParallelTaskRun,
|
|
19
|
-
} from "./subagent-runner-parallel-helpers.ts";
|
|
20
|
-
import {
|
|
21
|
-
resetStepLiveDetail,
|
|
22
|
-
updateStepFromChildEvent,
|
|
23
|
-
updateStepModel,
|
|
24
|
-
writeStatusPayload,
|
|
25
|
-
} from "./subagent-runner-state.ts";
|
|
26
|
-
import { outputEntryFromAsyncResult, runSingleStep } from "./subagent-runner-step.ts";
|
|
27
|
-
import type { ParallelGroup, RunnerExecutionState } from "./subagent-runner-types.ts";
|
|
28
|
-
import { tokenUsageFromAttempts } from "./subagent-runner-utils.ts";
|
|
29
|
-
|
|
30
|
-
export async function runParallelGroup(
|
|
31
|
-
state: RunnerExecutionState,
|
|
32
|
-
group: ParallelGroup,
|
|
33
|
-
stepIndex: number,
|
|
34
|
-
): Promise<boolean> {
|
|
35
|
-
const { cwd, asyncDir, id, placeholder, sessionEnabled, outputs, config, artifactsDir, artifactConfig, flatSteps } =
|
|
36
|
-
state;
|
|
37
|
-
const { statusPayload } = state;
|
|
38
|
-
const concurrency = group.concurrency ?? MAX_PARALLEL_CONCURRENCY;
|
|
39
|
-
const failFast = group.failFast ?? false;
|
|
40
|
-
const groupStartFlatIndex = state.flatIndex;
|
|
41
|
-
let aborted = false;
|
|
42
|
-
let worktreeSetup: WorktreeSetup | undefined;
|
|
43
|
-
if (group.worktree) {
|
|
44
|
-
const worktreeTaskCwdConflict = findWorktreeTaskCwdConflict(group.parallel, cwd);
|
|
45
|
-
if (worktreeTaskCwdConflict) {
|
|
46
|
-
const failedAt = Date.now();
|
|
47
|
-
markParallelGroupSetupFailure({
|
|
48
|
-
statusPayload,
|
|
49
|
-
results: state.results,
|
|
50
|
-
group,
|
|
51
|
-
groupStartFlatIndex,
|
|
52
|
-
setupError: formatWorktreeTaskCwdConflict(worktreeTaskCwdConflict, cwd),
|
|
53
|
-
failedAt,
|
|
54
|
-
statusPath: state.statusPath,
|
|
55
|
-
eventsPath: state.eventsPath,
|
|
56
|
-
asyncDir,
|
|
57
|
-
runId: id,
|
|
58
|
-
stepIndex,
|
|
59
|
-
});
|
|
60
|
-
state.flatIndex += group.parallel.length;
|
|
61
|
-
return false;
|
|
62
|
-
}
|
|
63
|
-
try {
|
|
64
|
-
worktreeSetup = createWorktrees(cwd, `${id}-s${stepIndex}`, group.parallel.length, {
|
|
65
|
-
agents: group.parallel.map((task) => task.agent),
|
|
66
|
-
setupHook: config.worktreeSetupHook
|
|
67
|
-
? { hookPath: config.worktreeSetupHook, timeoutMs: config.worktreeSetupHookTimeoutMs }
|
|
68
|
-
: undefined,
|
|
69
|
-
});
|
|
70
|
-
} catch (error) {
|
|
71
|
-
const setupError = error instanceof Error ? error.message : String(error);
|
|
72
|
-
const failedAt = Date.now();
|
|
73
|
-
markParallelGroupSetupFailure({
|
|
74
|
-
statusPayload,
|
|
75
|
-
results: state.results,
|
|
76
|
-
group,
|
|
77
|
-
groupStartFlatIndex,
|
|
78
|
-
setupError,
|
|
79
|
-
failedAt,
|
|
80
|
-
statusPath: state.statusPath,
|
|
81
|
-
eventsPath: state.eventsPath,
|
|
82
|
-
asyncDir,
|
|
83
|
-
runId: id,
|
|
84
|
-
stepIndex,
|
|
85
|
-
});
|
|
86
|
-
state.flatIndex += group.parallel.length;
|
|
87
|
-
return false;
|
|
88
|
-
}
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
try {
|
|
92
|
-
if (group.worktree) ensureParallelProgressFile(cwd, group);
|
|
93
|
-
const groupStartTime = Date.now();
|
|
94
|
-
markParallelGroupRunning({
|
|
95
|
-
statusPayload,
|
|
96
|
-
group,
|
|
97
|
-
groupStartFlatIndex,
|
|
98
|
-
groupStartTime,
|
|
99
|
-
statusPath: state.statusPath,
|
|
100
|
-
eventsPath: state.eventsPath,
|
|
101
|
-
asyncDir,
|
|
102
|
-
runId: id,
|
|
103
|
-
stepIndex,
|
|
104
|
-
});
|
|
105
|
-
const parallelResults = await mapConcurrent(group.parallel, concurrency, async (task, taskIdx) => {
|
|
106
|
-
const fi = groupStartFlatIndex + taskIdx;
|
|
107
|
-
if (aborted && failFast) {
|
|
108
|
-
const skippedAt = Date.now();
|
|
109
|
-
statusPayload.steps[fi].status = "failed";
|
|
110
|
-
statusPayload.steps[fi].error = "Skipped due to fail-fast";
|
|
111
|
-
statusPayload.steps[fi].startedAt = skippedAt;
|
|
112
|
-
statusPayload.steps[fi].endedAt = skippedAt;
|
|
113
|
-
statusPayload.steps[fi].durationMs = 0;
|
|
114
|
-
statusPayload.steps[fi].exitCode = -1;
|
|
115
|
-
statusPayload.steps[fi].activityState = undefined;
|
|
116
|
-
statusPayload.lastUpdate = skippedAt;
|
|
117
|
-
writeStatusPayload(state);
|
|
118
|
-
appendJsonl(
|
|
119
|
-
state.eventsPath,
|
|
120
|
-
JSON.stringify({
|
|
121
|
-
type: "subagent.step.failed",
|
|
122
|
-
ts: skippedAt,
|
|
123
|
-
runId: id,
|
|
124
|
-
stepIndex: fi,
|
|
125
|
-
agent: task.agent,
|
|
126
|
-
exitCode: -1,
|
|
127
|
-
durationMs: 0,
|
|
128
|
-
}),
|
|
129
|
-
);
|
|
130
|
-
return { agent: task.agent, output: "(skipped — fail-fast)", exitCode: -1 as number | null, skipped: true };
|
|
131
|
-
}
|
|
132
|
-
|
|
133
|
-
const taskStartTime = Date.now();
|
|
134
|
-
statusPayload.currentStep = fi;
|
|
135
|
-
statusPayload.steps[fi].status = "running";
|
|
136
|
-
statusPayload.steps[fi].error = undefined;
|
|
137
|
-
statusPayload.steps[fi].activityState = undefined;
|
|
138
|
-
resetStepLiveDetail(statusPayload.steps[fi]);
|
|
139
|
-
statusPayload.steps[fi].startedAt = taskStartTime;
|
|
140
|
-
statusPayload.steps[fi].endedAt = undefined;
|
|
141
|
-
statusPayload.steps[fi].durationMs = undefined;
|
|
142
|
-
statusPayload.steps[fi].lastActivityAt = taskStartTime;
|
|
143
|
-
statusPayload.outputFile = path.join(asyncDir, `output-${fi}.log`);
|
|
144
|
-
statusPayload.lastActivityAt = taskStartTime;
|
|
145
|
-
statusPayload.lastUpdate = taskStartTime;
|
|
146
|
-
writeStatusPayload(state);
|
|
147
|
-
appendJsonl(
|
|
148
|
-
state.eventsPath,
|
|
149
|
-
JSON.stringify({
|
|
150
|
-
type: "subagent.step.started",
|
|
151
|
-
ts: taskStartTime,
|
|
152
|
-
runId: id,
|
|
153
|
-
stepIndex: fi,
|
|
154
|
-
agent: task.agent,
|
|
155
|
-
}),
|
|
156
|
-
);
|
|
157
|
-
|
|
158
|
-
const taskSessionDir = config.sessionDir ? path.join(config.sessionDir, `parallel-${taskIdx}`) : undefined;
|
|
159
|
-
const { taskForRun, taskCwd } = prepareParallelTaskRun(task, cwd, worktreeSetup, taskIdx);
|
|
160
|
-
const singleResult = await runSingleStep(taskForRun, {
|
|
161
|
-
previousOutput: state.previousOutput,
|
|
162
|
-
placeholder,
|
|
163
|
-
cwd: taskCwd,
|
|
164
|
-
sessionEnabled,
|
|
165
|
-
outputs,
|
|
166
|
-
sessionDir: taskSessionDir,
|
|
167
|
-
artifactsDir,
|
|
168
|
-
artifactConfig,
|
|
169
|
-
id,
|
|
170
|
-
flatIndex: fi,
|
|
171
|
-
flatStepCount: flatSteps.length,
|
|
172
|
-
outputFile: path.join(asyncDir, `output-${fi}.log`),
|
|
173
|
-
piPackageRoot: config.piPackageRoot,
|
|
174
|
-
piArgv1: config.piArgv1,
|
|
175
|
-
childIntercomTarget: config.childIntercomTargets?.[fi],
|
|
176
|
-
orchestratorIntercomTarget: config.controlIntercomTarget,
|
|
177
|
-
supervisorAuthorization: config.supervisorAuthorizations?.[fi],
|
|
178
|
-
nestedRoute: config.nestedRoute,
|
|
179
|
-
registerInterrupt: (interrupt) => {
|
|
180
|
-
state.activeChildInterrupt = interrupt;
|
|
181
|
-
},
|
|
182
|
-
onAttemptStart: (attempt) => updateStepModel(state, fi, attempt.model, attempt.thinking, attempt.fastMode),
|
|
183
|
-
onChildEvent: (event) => updateStepFromChildEvent(state, fi, event),
|
|
184
|
-
workflowStageSubagentGuard: config.workflowStageSubagentGuard,
|
|
185
|
-
});
|
|
186
|
-
if (task.sessionFile) state.latestSessionFile = task.sessionFile;
|
|
187
|
-
|
|
188
|
-
const taskEndTime = Date.now();
|
|
189
|
-
const taskDuration = taskEndTime - taskStartTime;
|
|
190
|
-
statusPayload.steps[fi].status = singleResult.exitCode === 0 ? "complete" : "failed";
|
|
191
|
-
statusPayload.steps[fi].endedAt = taskEndTime;
|
|
192
|
-
statusPayload.steps[fi].durationMs = taskDuration;
|
|
193
|
-
statusPayload.steps[fi].exitCode = singleResult.exitCode;
|
|
194
|
-
statusPayload.steps[fi].model = singleResult.model;
|
|
195
|
-
statusPayload.steps[fi].thinking = resolveEffectiveThinking(
|
|
196
|
-
singleResult.model,
|
|
197
|
-
statusPayload.steps[fi].thinking,
|
|
198
|
-
);
|
|
199
|
-
statusPayload.steps[fi].fastMode = singleResult.fastMode ? true : undefined;
|
|
200
|
-
statusPayload.steps[fi].attemptedModels = singleResult.attemptedModels;
|
|
201
|
-
statusPayload.steps[fi].modelAttempts = singleResult.modelAttempts;
|
|
202
|
-
statusPayload.steps[fi].error = singleResult.error;
|
|
203
|
-
statusPayload.steps[fi].structuredOutput = singleResult.structuredOutput;
|
|
204
|
-
statusPayload.steps[fi].structuredOutputPath = singleResult.structuredOutputPath;
|
|
205
|
-
statusPayload.steps[fi].structuredOutputSchemaPath = singleResult.structuredOutputSchemaPath;
|
|
206
|
-
statusPayload.lastUpdate = taskEndTime;
|
|
207
|
-
writeStatusPayload(state);
|
|
208
|
-
appendJsonl(
|
|
209
|
-
state.eventsPath,
|
|
210
|
-
JSON.stringify({
|
|
211
|
-
type: singleResult.exitCode === 0 ? "subagent.step.completed" : "subagent.step.failed",
|
|
212
|
-
ts: taskEndTime,
|
|
213
|
-
runId: id,
|
|
214
|
-
stepIndex: fi,
|
|
215
|
-
agent: task.agent,
|
|
216
|
-
exitCode: singleResult.exitCode,
|
|
217
|
-
durationMs: taskDuration,
|
|
218
|
-
}),
|
|
219
|
-
);
|
|
220
|
-
if (singleResult.exitCode !== 0 && failFast) aborted = true;
|
|
221
|
-
return { ...singleResult, skipped: false };
|
|
222
|
-
});
|
|
223
|
-
|
|
224
|
-
state.flatIndex += group.parallel.length;
|
|
225
|
-
for (let t = 0; t < group.parallel.length; t++) {
|
|
226
|
-
const fi = groupStartFlatIndex + t;
|
|
227
|
-
const sessionTokens = config.sessionDir
|
|
228
|
-
? parseSessionTokens(path.join(config.sessionDir, `parallel-${t}`))
|
|
229
|
-
: null;
|
|
230
|
-
const taskTokens = sessionTokens ?? tokenUsageFromAttempts(parallelResults[t]?.modelAttempts);
|
|
231
|
-
if (!taskTokens) continue;
|
|
232
|
-
statusPayload.steps[fi].tokens = taskTokens;
|
|
233
|
-
state.previousCumulativeTokens = {
|
|
234
|
-
input: state.previousCumulativeTokens.input + taskTokens.input,
|
|
235
|
-
output: state.previousCumulativeTokens.output + taskTokens.output,
|
|
236
|
-
total: state.previousCumulativeTokens.total + taskTokens.total,
|
|
237
|
-
};
|
|
238
|
-
}
|
|
239
|
-
statusPayload.totalTokens = { ...state.previousCumulativeTokens };
|
|
240
|
-
statusPayload.lastUpdate = Date.now();
|
|
241
|
-
writeStatusPayload(state);
|
|
242
|
-
|
|
243
|
-
for (const pr of parallelResults) {
|
|
244
|
-
state.results.push({
|
|
245
|
-
agent: pr.agent,
|
|
246
|
-
output: pr.output,
|
|
247
|
-
error: pr.error,
|
|
248
|
-
success: pr.exitCode === 0,
|
|
249
|
-
exitCode: pr.exitCode,
|
|
250
|
-
skipped: pr.skipped,
|
|
251
|
-
sessionFile: pr.sessionFile,
|
|
252
|
-
intercomTarget: pr.intercomTarget,
|
|
253
|
-
model: pr.model,
|
|
254
|
-
fastMode: pr.fastMode,
|
|
255
|
-
attemptedModels: pr.attemptedModels,
|
|
256
|
-
modelAttempts: pr.modelAttempts,
|
|
257
|
-
artifactPaths: pr.artifactPaths,
|
|
258
|
-
structuredOutput: pr.structuredOutput,
|
|
259
|
-
structuredOutputPath: pr.structuredOutputPath,
|
|
260
|
-
structuredOutputSchemaPath: pr.structuredOutputSchemaPath,
|
|
261
|
-
});
|
|
262
|
-
}
|
|
263
|
-
for (let t = 0; t < group.parallel.length; t++) {
|
|
264
|
-
const outputName = group.parallel[t]?.outputName;
|
|
265
|
-
if (outputName)
|
|
266
|
-
outputs[outputName] = outputEntryFromAsyncResult(
|
|
267
|
-
{
|
|
268
|
-
agent: parallelResults[t]!.agent,
|
|
269
|
-
output: parallelResults[t]!.output,
|
|
270
|
-
structuredOutput: parallelResults[t]!.structuredOutput,
|
|
271
|
-
},
|
|
272
|
-
stepIndex,
|
|
273
|
-
);
|
|
274
|
-
}
|
|
275
|
-
statusPayload.outputs = outputs;
|
|
276
|
-
|
|
277
|
-
state.previousOutput = aggregateParallelOutputs(
|
|
278
|
-
parallelResults.map((r) => ({
|
|
279
|
-
agent: r.agent,
|
|
280
|
-
output: r.output,
|
|
281
|
-
exitCode: r.exitCode,
|
|
282
|
-
error: r.error,
|
|
283
|
-
model: r.model,
|
|
284
|
-
fastMode: r.fastMode,
|
|
285
|
-
attemptedModels: r.attemptedModels,
|
|
286
|
-
})),
|
|
287
|
-
);
|
|
288
|
-
state.previousOutput = appendParallelWorktreeSummary(
|
|
289
|
-
state.previousOutput,
|
|
290
|
-
worktreeSetup,
|
|
291
|
-
asyncDir,
|
|
292
|
-
stepIndex,
|
|
293
|
-
group,
|
|
294
|
-
);
|
|
295
|
-
appendJsonl(
|
|
296
|
-
state.eventsPath,
|
|
297
|
-
JSON.stringify({
|
|
298
|
-
type: "subagent.parallel.completed",
|
|
299
|
-
ts: Date.now(),
|
|
300
|
-
runId: id,
|
|
301
|
-
stepIndex,
|
|
302
|
-
success: parallelResults.every((r) => r.exitCode === 0 || r.exitCode === -1),
|
|
303
|
-
}),
|
|
304
|
-
);
|
|
305
|
-
return !parallelResults.some((r) => r.exitCode !== 0 && r.exitCode !== -1);
|
|
306
|
-
} finally {
|
|
307
|
-
if (worktreeSetup) cleanupWorktrees(worktreeSetup);
|
|
308
|
-
}
|
|
309
|
-
}
|
|
@@ -1,173 +0,0 @@
|
|
|
1
|
-
import * as path from "node:path";
|
|
2
|
-
import { appendJsonl } from "../../shared/artifacts.ts";
|
|
3
|
-
import { resolveEffectiveThinking } from "../../shared/model-info.ts";
|
|
4
|
-
import { parseSessionTokens } from "../../shared/session-tokens.ts";
|
|
5
|
-
import {
|
|
6
|
-
resetStepLiveDetail,
|
|
7
|
-
updateStepFromChildEvent,
|
|
8
|
-
updateStepModel,
|
|
9
|
-
writeStatusPayload,
|
|
10
|
-
} from "./subagent-runner-state.ts";
|
|
11
|
-
import { outputEntryFromAsyncResult, runSingleStep } from "./subagent-runner-step.ts";
|
|
12
|
-
import type { RunnerExecutionState, SubagentStep } from "./subagent-runner-types.ts";
|
|
13
|
-
import { tokenUsageFromAttempts } from "./subagent-runner-utils.ts";
|
|
14
|
-
|
|
15
|
-
export async function runSequentialStep(
|
|
16
|
-
state: RunnerExecutionState,
|
|
17
|
-
seqStep: SubagentStep,
|
|
18
|
-
stepIndex: number,
|
|
19
|
-
): Promise<boolean> {
|
|
20
|
-
const {
|
|
21
|
-
statusPayload,
|
|
22
|
-
asyncDir,
|
|
23
|
-
id,
|
|
24
|
-
cwd,
|
|
25
|
-
placeholder,
|
|
26
|
-
sessionEnabled,
|
|
27
|
-
outputs,
|
|
28
|
-
config,
|
|
29
|
-
artifactsDir,
|
|
30
|
-
artifactConfig,
|
|
31
|
-
flatSteps,
|
|
32
|
-
} = state;
|
|
33
|
-
const flatIndex = state.flatIndex;
|
|
34
|
-
const stepStartTime = Date.now();
|
|
35
|
-
statusPayload.currentStep = flatIndex;
|
|
36
|
-
statusPayload.steps[flatIndex].status = "running";
|
|
37
|
-
statusPayload.steps[flatIndex].activityState = undefined;
|
|
38
|
-
statusPayload.activityState = undefined;
|
|
39
|
-
resetStepLiveDetail(statusPayload.steps[flatIndex]);
|
|
40
|
-
statusPayload.steps[flatIndex].skills = seqStep.skills;
|
|
41
|
-
statusPayload.steps[flatIndex].startedAt = stepStartTime;
|
|
42
|
-
statusPayload.steps[flatIndex].lastActivityAt = stepStartTime;
|
|
43
|
-
statusPayload.lastActivityAt = stepStartTime;
|
|
44
|
-
statusPayload.lastUpdate = stepStartTime;
|
|
45
|
-
statusPayload.outputFile = path.join(asyncDir, `output-${flatIndex}.log`);
|
|
46
|
-
writeStatusPayload(state);
|
|
47
|
-
|
|
48
|
-
appendJsonl(
|
|
49
|
-
state.eventsPath,
|
|
50
|
-
JSON.stringify({
|
|
51
|
-
type: "subagent.step.started",
|
|
52
|
-
ts: stepStartTime,
|
|
53
|
-
runId: id,
|
|
54
|
-
stepIndex: flatIndex,
|
|
55
|
-
agent: seqStep.agent,
|
|
56
|
-
}),
|
|
57
|
-
);
|
|
58
|
-
|
|
59
|
-
const singleResult = await runSingleStep(seqStep, {
|
|
60
|
-
previousOutput: state.previousOutput,
|
|
61
|
-
placeholder,
|
|
62
|
-
cwd,
|
|
63
|
-
sessionEnabled,
|
|
64
|
-
outputs,
|
|
65
|
-
sessionDir: config.sessionDir,
|
|
66
|
-
artifactsDir,
|
|
67
|
-
artifactConfig,
|
|
68
|
-
id,
|
|
69
|
-
flatIndex,
|
|
70
|
-
flatStepCount: flatSteps.length,
|
|
71
|
-
outputFile: path.join(asyncDir, `output-${flatIndex}.log`),
|
|
72
|
-
piPackageRoot: config.piPackageRoot,
|
|
73
|
-
piArgv1: config.piArgv1,
|
|
74
|
-
childIntercomTarget: config.childIntercomTargets?.[flatIndex],
|
|
75
|
-
orchestratorIntercomTarget: config.controlIntercomTarget,
|
|
76
|
-
supervisorAuthorization: config.supervisorAuthorizations?.[flatIndex],
|
|
77
|
-
nestedRoute: config.nestedRoute,
|
|
78
|
-
registerInterrupt: (interrupt) => {
|
|
79
|
-
state.activeChildInterrupt = interrupt;
|
|
80
|
-
},
|
|
81
|
-
onAttemptStart: (attempt) => updateStepModel(state, flatIndex, attempt.model, attempt.thinking, attempt.fastMode),
|
|
82
|
-
onChildEvent: (event) => updateStepFromChildEvent(state, flatIndex, event),
|
|
83
|
-
workflowStageSubagentGuard: config.workflowStageSubagentGuard,
|
|
84
|
-
});
|
|
85
|
-
if (seqStep.sessionFile) state.latestSessionFile = seqStep.sessionFile;
|
|
86
|
-
|
|
87
|
-
state.previousOutput = singleResult.output;
|
|
88
|
-
state.results.push({
|
|
89
|
-
agent: singleResult.agent,
|
|
90
|
-
output: singleResult.output,
|
|
91
|
-
error: singleResult.error,
|
|
92
|
-
success: singleResult.exitCode === 0,
|
|
93
|
-
exitCode: singleResult.exitCode,
|
|
94
|
-
sessionFile: singleResult.sessionFile,
|
|
95
|
-
intercomTarget: singleResult.intercomTarget,
|
|
96
|
-
model: singleResult.model,
|
|
97
|
-
fastMode: singleResult.fastMode,
|
|
98
|
-
attemptedModels: singleResult.attemptedModels,
|
|
99
|
-
modelAttempts: singleResult.modelAttempts,
|
|
100
|
-
artifactPaths: singleResult.artifactPaths,
|
|
101
|
-
structuredOutput: singleResult.structuredOutput,
|
|
102
|
-
structuredOutputPath: singleResult.structuredOutputPath,
|
|
103
|
-
structuredOutputSchemaPath: singleResult.structuredOutputSchemaPath,
|
|
104
|
-
});
|
|
105
|
-
if (seqStep.outputName) {
|
|
106
|
-
outputs[seqStep.outputName] = outputEntryFromAsyncResult(
|
|
107
|
-
{ agent: singleResult.agent, output: singleResult.output, structuredOutput: singleResult.structuredOutput },
|
|
108
|
-
stepIndex,
|
|
109
|
-
);
|
|
110
|
-
}
|
|
111
|
-
statusPayload.outputs = outputs;
|
|
112
|
-
|
|
113
|
-
const cumulativeTokens = config.sessionDir ? parseSessionTokens(config.sessionDir) : null;
|
|
114
|
-
let stepTokens = cumulativeTokens
|
|
115
|
-
? {
|
|
116
|
-
input: cumulativeTokens.input - state.previousCumulativeTokens.input,
|
|
117
|
-
output: cumulativeTokens.output - state.previousCumulativeTokens.output,
|
|
118
|
-
total: cumulativeTokens.total - state.previousCumulativeTokens.total,
|
|
119
|
-
}
|
|
120
|
-
: null;
|
|
121
|
-
if (cumulativeTokens) {
|
|
122
|
-
state.previousCumulativeTokens = cumulativeTokens;
|
|
123
|
-
} else {
|
|
124
|
-
stepTokens = tokenUsageFromAttempts(singleResult.modelAttempts);
|
|
125
|
-
if (stepTokens) {
|
|
126
|
-
state.previousCumulativeTokens = {
|
|
127
|
-
input: state.previousCumulativeTokens.input + stepTokens.input,
|
|
128
|
-
output: state.previousCumulativeTokens.output + stepTokens.output,
|
|
129
|
-
total: state.previousCumulativeTokens.total + stepTokens.total,
|
|
130
|
-
};
|
|
131
|
-
}
|
|
132
|
-
}
|
|
133
|
-
|
|
134
|
-
const stepEndTime = Date.now();
|
|
135
|
-
statusPayload.steps[flatIndex].status = singleResult.exitCode === 0 ? "complete" : "failed";
|
|
136
|
-
statusPayload.steps[flatIndex].endedAt = stepEndTime;
|
|
137
|
-
statusPayload.steps[flatIndex].durationMs = stepEndTime - stepStartTime;
|
|
138
|
-
statusPayload.steps[flatIndex].exitCode = singleResult.exitCode;
|
|
139
|
-
statusPayload.steps[flatIndex].model = singleResult.model;
|
|
140
|
-
statusPayload.steps[flatIndex].thinking = resolveEffectiveThinking(
|
|
141
|
-
singleResult.model,
|
|
142
|
-
statusPayload.steps[flatIndex].thinking,
|
|
143
|
-
);
|
|
144
|
-
statusPayload.steps[flatIndex].fastMode = singleResult.fastMode ? true : undefined;
|
|
145
|
-
statusPayload.steps[flatIndex].attemptedModels = singleResult.attemptedModels;
|
|
146
|
-
statusPayload.steps[flatIndex].modelAttempts = singleResult.modelAttempts;
|
|
147
|
-
statusPayload.steps[flatIndex].error = singleResult.error;
|
|
148
|
-
statusPayload.steps[flatIndex].structuredOutput = singleResult.structuredOutput;
|
|
149
|
-
statusPayload.steps[flatIndex].structuredOutputPath = singleResult.structuredOutputPath;
|
|
150
|
-
statusPayload.steps[flatIndex].structuredOutputSchemaPath = singleResult.structuredOutputSchemaPath;
|
|
151
|
-
if (stepTokens) {
|
|
152
|
-
statusPayload.steps[flatIndex].tokens = stepTokens;
|
|
153
|
-
statusPayload.totalTokens = { ...state.previousCumulativeTokens };
|
|
154
|
-
}
|
|
155
|
-
statusPayload.lastUpdate = stepEndTime;
|
|
156
|
-
writeStatusPayload(state);
|
|
157
|
-
|
|
158
|
-
appendJsonl(
|
|
159
|
-
state.eventsPath,
|
|
160
|
-
JSON.stringify({
|
|
161
|
-
type: singleResult.exitCode === 0 ? "subagent.step.completed" : "subagent.step.failed",
|
|
162
|
-
ts: stepEndTime,
|
|
163
|
-
runId: id,
|
|
164
|
-
stepIndex: flatIndex,
|
|
165
|
-
agent: seqStep.agent,
|
|
166
|
-
exitCode: singleResult.exitCode,
|
|
167
|
-
durationMs: stepEndTime - stepStartTime,
|
|
168
|
-
tokens: stepTokens,
|
|
169
|
-
}),
|
|
170
|
-
);
|
|
171
|
-
state.flatIndex++;
|
|
172
|
-
return singleResult.exitCode === 0;
|
|
173
|
-
}
|