@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,210 +0,0 @@
|
|
|
1
|
-
import type { Message } from "@earendil-works/pi-ai/compat";
|
|
2
|
-
import type { SupervisorAuthorization } from "../../intercom/supervisor-authorization.ts";
|
|
3
|
-
import type {
|
|
4
|
-
ActivityState,
|
|
5
|
-
ArtifactConfig,
|
|
6
|
-
ArtifactPaths,
|
|
7
|
-
AsyncParallelGroupStatus,
|
|
8
|
-
AsyncStatus,
|
|
9
|
-
ChainOutputMap,
|
|
10
|
-
MaxOutputConfig,
|
|
11
|
-
ModelAttempt,
|
|
12
|
-
NestedRouteInfo,
|
|
13
|
-
ResolvedControlConfig,
|
|
14
|
-
SubagentRunMode,
|
|
15
|
-
TokenUsage,
|
|
16
|
-
Usage,
|
|
17
|
-
WorkflowGraphSnapshot,
|
|
18
|
-
} from "../../shared/types.ts";
|
|
19
|
-
import type { RunnerStep, RunnerSubagentStep as SubagentStep } from "../shared/parallel-utils.ts";
|
|
20
|
-
import type { WorktreeSetup } from "../shared/worktree.ts";
|
|
21
|
-
|
|
22
|
-
export interface SubagentRunConfig {
|
|
23
|
-
id: string;
|
|
24
|
-
steps: RunnerStep[];
|
|
25
|
-
resultPath: string;
|
|
26
|
-
cwd: string;
|
|
27
|
-
placeholder: string;
|
|
28
|
-
taskIndex?: number;
|
|
29
|
-
totalTasks?: number;
|
|
30
|
-
maxOutput?: MaxOutputConfig;
|
|
31
|
-
artifactsDir?: string;
|
|
32
|
-
artifactConfig?: Partial<ArtifactConfig>;
|
|
33
|
-
share?: boolean;
|
|
34
|
-
sessionDir?: string;
|
|
35
|
-
asyncDir: string;
|
|
36
|
-
sessionId?: string | null;
|
|
37
|
-
piPackageRoot?: string;
|
|
38
|
-
piArgv1?: string;
|
|
39
|
-
worktreeSetupHook?: string;
|
|
40
|
-
worktreeSetupHookTimeoutMs?: number;
|
|
41
|
-
controlConfig?: ResolvedControlConfig;
|
|
42
|
-
controlIntercomTarget?: string;
|
|
43
|
-
childIntercomTargets?: Array<string | undefined>;
|
|
44
|
-
supervisorAuthorizations?: Array<SupervisorAuthorization | undefined>;
|
|
45
|
-
dynamicSupervisorAuthorizations?: Record<number, SupervisorAuthorization[]>;
|
|
46
|
-
resultMode?: SubagentRunMode;
|
|
47
|
-
dynamicFanoutMaxItems?: number;
|
|
48
|
-
workflowGraph?: WorkflowGraphSnapshot;
|
|
49
|
-
nestedRoute?: NestedRouteInfo;
|
|
50
|
-
workflowStageSubagentGuard?: boolean;
|
|
51
|
-
nestedSelf?: {
|
|
52
|
-
parentRunId: string;
|
|
53
|
-
parentStepIndex?: number;
|
|
54
|
-
depth: number;
|
|
55
|
-
path?: Array<{ runId: string; stepIndex?: number; agent?: string }>;
|
|
56
|
-
};
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
export interface StepResult {
|
|
60
|
-
agent: string;
|
|
61
|
-
output: string;
|
|
62
|
-
error?: string;
|
|
63
|
-
success: boolean;
|
|
64
|
-
exitCode?: number | null;
|
|
65
|
-
skipped?: boolean;
|
|
66
|
-
sessionFile?: string;
|
|
67
|
-
intercomTarget?: string;
|
|
68
|
-
model?: string;
|
|
69
|
-
fastMode?: boolean;
|
|
70
|
-
attemptedModels?: string[];
|
|
71
|
-
modelAttempts?: ModelAttempt[];
|
|
72
|
-
artifactPaths?: ArtifactPaths;
|
|
73
|
-
truncated?: boolean;
|
|
74
|
-
structuredOutput?: unknown;
|
|
75
|
-
structuredOutputPath?: string;
|
|
76
|
-
structuredOutputSchemaPath?: string;
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
export interface ChildEventContext {
|
|
80
|
-
eventsPath: string;
|
|
81
|
-
runId: string;
|
|
82
|
-
stepIndex: number;
|
|
83
|
-
agent: string;
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
export interface ChildUsage {
|
|
87
|
-
input?: number;
|
|
88
|
-
inputTokens?: number;
|
|
89
|
-
output?: number;
|
|
90
|
-
outputTokens?: number;
|
|
91
|
-
cacheRead?: number;
|
|
92
|
-
cacheWrite?: number;
|
|
93
|
-
cost?: { total?: number };
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
export type ChildMessage = Message & {
|
|
97
|
-
model?: string;
|
|
98
|
-
errorMessage?: string;
|
|
99
|
-
usage?: ChildUsage;
|
|
100
|
-
};
|
|
101
|
-
|
|
102
|
-
export interface ChildEvent {
|
|
103
|
-
type?: string;
|
|
104
|
-
message?: ChildMessage;
|
|
105
|
-
toolName?: string;
|
|
106
|
-
args?: Record<string, unknown>;
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
export interface RunPiStreamingResult {
|
|
110
|
-
stderr: string;
|
|
111
|
-
exitCode: number | null;
|
|
112
|
-
messages: Message[];
|
|
113
|
-
usage: Usage;
|
|
114
|
-
model?: string;
|
|
115
|
-
error?: string;
|
|
116
|
-
finalOutput: string;
|
|
117
|
-
interrupted?: boolean;
|
|
118
|
-
modelFailureSignal?: unknown;
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
export interface SingleStepContext {
|
|
122
|
-
previousOutput: string;
|
|
123
|
-
outputs?: ChainOutputMap;
|
|
124
|
-
placeholder: string;
|
|
125
|
-
cwd: string;
|
|
126
|
-
sessionEnabled: boolean;
|
|
127
|
-
sessionDir?: string;
|
|
128
|
-
artifactsDir?: string;
|
|
129
|
-
artifactConfig?: Partial<ArtifactConfig>;
|
|
130
|
-
id: string;
|
|
131
|
-
flatIndex: number;
|
|
132
|
-
flatStepCount: number;
|
|
133
|
-
outputFile: string;
|
|
134
|
-
piPackageRoot?: string;
|
|
135
|
-
piArgv1?: string;
|
|
136
|
-
registerInterrupt?: (interrupt: (() => void) | undefined) => void;
|
|
137
|
-
childIntercomTarget?: string;
|
|
138
|
-
orchestratorIntercomTarget?: string;
|
|
139
|
-
supervisorAuthorization?: SupervisorAuthorization;
|
|
140
|
-
nestedRoute?: NestedRouteInfo;
|
|
141
|
-
onAttemptStart?: (attempt: { model?: string; thinking?: string; fastMode?: boolean }) => void;
|
|
142
|
-
onChildEvent?: (event: ChildEvent) => void;
|
|
143
|
-
workflowStageSubagentGuard?: boolean;
|
|
144
|
-
}
|
|
145
|
-
|
|
146
|
-
export type RunnerStatusStep = NonNullable<AsyncStatus["steps"]>[number] & {
|
|
147
|
-
exitCode?: number | null;
|
|
148
|
-
};
|
|
149
|
-
|
|
150
|
-
export type RunnerStatusPayload = Omit<
|
|
151
|
-
AsyncStatus,
|
|
152
|
-
"steps" | "parallelGroups" | "pid" | "cwd" | "currentStep" | "chainStepCount" | "lastUpdate"
|
|
153
|
-
> & {
|
|
154
|
-
pid: number;
|
|
155
|
-
cwd: string;
|
|
156
|
-
currentStep: number;
|
|
157
|
-
chainStepCount: number;
|
|
158
|
-
parallelGroups: AsyncParallelGroupStatus[];
|
|
159
|
-
steps: RunnerStatusStep[];
|
|
160
|
-
lastUpdate: number;
|
|
161
|
-
artifactsDir?: string;
|
|
162
|
-
shareUrl?: string;
|
|
163
|
-
gistUrl?: string;
|
|
164
|
-
shareError?: string;
|
|
165
|
-
error?: string;
|
|
166
|
-
};
|
|
167
|
-
|
|
168
|
-
export interface RunnerExecutionState {
|
|
169
|
-
config: SubagentRunConfig;
|
|
170
|
-
id: string;
|
|
171
|
-
steps: RunnerStep[];
|
|
172
|
-
resultPath: string;
|
|
173
|
-
cwd: string;
|
|
174
|
-
placeholder: string;
|
|
175
|
-
taskIndex?: number;
|
|
176
|
-
totalTasks?: number;
|
|
177
|
-
maxOutput?: MaxOutputConfig;
|
|
178
|
-
artifactsDir?: string;
|
|
179
|
-
artifactConfig?: Partial<ArtifactConfig>;
|
|
180
|
-
previousOutput: string;
|
|
181
|
-
outputs: ChainOutputMap;
|
|
182
|
-
results: StepResult[];
|
|
183
|
-
overallStartTime: number;
|
|
184
|
-
shareEnabled: boolean;
|
|
185
|
-
asyncDir: string;
|
|
186
|
-
statusPath: string;
|
|
187
|
-
eventsPath: string;
|
|
188
|
-
logPath: string;
|
|
189
|
-
controlConfig: ResolvedControlConfig;
|
|
190
|
-
activeChildInterrupt?: (() => void) | undefined;
|
|
191
|
-
interrupted: boolean;
|
|
192
|
-
currentActivityState?: ActivityState;
|
|
193
|
-
activityTimer?: NodeJS.Timeout;
|
|
194
|
-
previousCumulativeTokens: TokenUsage;
|
|
195
|
-
latestSessionFile?: string;
|
|
196
|
-
flatSteps: SubagentStep[];
|
|
197
|
-
sessionEnabled: boolean;
|
|
198
|
-
statusPayload: RunnerStatusPayload;
|
|
199
|
-
flatIndex: number;
|
|
200
|
-
mutatingFailureStates: Array<
|
|
201
|
-
ReturnType<typeof import("../shared/long-running-guard.ts").createMutatingFailureState>
|
|
202
|
-
>;
|
|
203
|
-
pendingToolResults: Array<{ tool: string; path?: string; mutates: boolean; startedAt?: number } | undefined>;
|
|
204
|
-
emittedControlEventKeys: Set<string>;
|
|
205
|
-
activeLongRunningSteps: Set<number>;
|
|
206
|
-
}
|
|
207
|
-
|
|
208
|
-
export type ParallelGroup = Extract<RunnerStep, { parallel: SubagentStep[] }>;
|
|
209
|
-
export type DynamicGroup = Extract<RunnerStep, { collect: { as: string } }>;
|
|
210
|
-
export type { RunnerStep, SubagentStep, WorktreeSetup };
|
|
@@ -1,69 +0,0 @@
|
|
|
1
|
-
import * as fs from "node:fs";
|
|
2
|
-
import * as path from "node:path";
|
|
3
|
-
import type { ModelAttempt, TokenUsage, Usage } from "../../shared/types.ts";
|
|
4
|
-
import type { RunnerStatusStep, SubagentStep } from "./subagent-runner-types.ts";
|
|
5
|
-
|
|
6
|
-
export function findLatestSessionFile(sessionDir: string): string | null {
|
|
7
|
-
try {
|
|
8
|
-
const files = fs
|
|
9
|
-
.readdirSync(sessionDir)
|
|
10
|
-
.filter((f) => f.endsWith(".jsonl"))
|
|
11
|
-
.map((f) => path.join(sessionDir, f));
|
|
12
|
-
if (files.length === 0) return null;
|
|
13
|
-
files.sort((a, b) => fs.statSync(b).mtimeMs - fs.statSync(a).mtimeMs);
|
|
14
|
-
return files[0] ?? null;
|
|
15
|
-
} catch {
|
|
16
|
-
return null;
|
|
17
|
-
}
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
export function emptyUsage(): Usage {
|
|
21
|
-
return { input: 0, output: 0, cacheRead: 0, cacheWrite: 0, cost: 0, turns: 0 };
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
export function tokenUsageFromAttempts(attempts: ModelAttempt[] | undefined): TokenUsage | null {
|
|
25
|
-
if (!attempts || attempts.length === 0) return null;
|
|
26
|
-
let input = 0;
|
|
27
|
-
let output = 0;
|
|
28
|
-
for (const attempt of attempts) {
|
|
29
|
-
input += attempt.usage?.input ?? 0;
|
|
30
|
-
output += attempt.usage?.output ?? 0;
|
|
31
|
-
}
|
|
32
|
-
const total = input + output;
|
|
33
|
-
return total > 0 ? { input, output, total } : null;
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
export function appendRecentStepOutput(step: RunnerStatusStep, lines: string[]): void {
|
|
37
|
-
const nonEmpty = lines.filter((line) => line.trim());
|
|
38
|
-
if (nonEmpty.length === 0) return;
|
|
39
|
-
step.recentOutput ??= [];
|
|
40
|
-
step.recentOutput.push(...nonEmpty);
|
|
41
|
-
if (step.recentOutput.length > 50) {
|
|
42
|
-
step.recentOutput.splice(0, step.recentOutput.length - 50);
|
|
43
|
-
}
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
export function resetStepLiveDetail(step: RunnerStatusStep): void {
|
|
47
|
-
step.currentTool = undefined;
|
|
48
|
-
step.currentToolArgs = undefined;
|
|
49
|
-
step.currentToolStartedAt = undefined;
|
|
50
|
-
step.currentPath = undefined;
|
|
51
|
-
step.recentTools = [];
|
|
52
|
-
step.recentOutput = [];
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
export function fastModeForStepAttempt(step: SubagentStep, model: string | undefined): boolean | undefined {
|
|
56
|
-
if (model && step.modelFastModes && Object.hasOwn(step.modelFastModes, model)) {
|
|
57
|
-
return step.modelFastModes[model];
|
|
58
|
-
}
|
|
59
|
-
if (model === undefined || model === step.model) return step.fastMode;
|
|
60
|
-
return undefined;
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
export function formatDuration(ms: number): string {
|
|
64
|
-
if (ms < 1000) return `${ms}ms`;
|
|
65
|
-
if (ms < 60000) return `${(ms / 1000).toFixed(1)}s`;
|
|
66
|
-
const minutes = Math.floor(ms / 60000);
|
|
67
|
-
const seconds = Math.floor((ms % 60000) / 1000);
|
|
68
|
-
return `${minutes}m${seconds}s`;
|
|
69
|
-
}
|
|
@@ -1,90 +0,0 @@
|
|
|
1
|
-
import * as fs from "node:fs";
|
|
2
|
-
import { appendJsonl } from "../../shared/artifacts.ts";
|
|
3
|
-
import { isDynamicRunnerGroup, isParallelGroup } from "../shared/parallel-utils.ts";
|
|
4
|
-
import { runDynamicGroup } from "./subagent-runner-dynamic.ts";
|
|
5
|
-
import { finalizeRun } from "./subagent-runner-finalize.ts";
|
|
6
|
-
import { runParallelGroup } from "./subagent-runner-parallel.ts";
|
|
7
|
-
import { runSequentialStep } from "./subagent-runner-sequential.ts";
|
|
8
|
-
import { createRunnerExecutionState, interruptRunner, startActivityTimer } from "./subagent-runner-state.ts";
|
|
9
|
-
import type { SubagentRunConfig, SubagentStep } from "./subagent-runner-types.ts";
|
|
10
|
-
|
|
11
|
-
const ASYNC_INTERRUPT_SIGNAL: NodeJS.Signals = process.platform === "win32" ? "SIGBREAK" : "SIGUSR2";
|
|
12
|
-
|
|
13
|
-
async function runSubagent(config: SubagentRunConfig): Promise<void> {
|
|
14
|
-
const state = createRunnerExecutionState(config);
|
|
15
|
-
startActivityTimer(state);
|
|
16
|
-
const onInterrupt = () => interruptRunner(state);
|
|
17
|
-
process.on(ASYNC_INTERRUPT_SIGNAL, onInterrupt);
|
|
18
|
-
appendJsonl(
|
|
19
|
-
state.eventsPath,
|
|
20
|
-
JSON.stringify({
|
|
21
|
-
type: "subagent.run.started",
|
|
22
|
-
ts: state.overallStartTime,
|
|
23
|
-
runId: state.id,
|
|
24
|
-
mode: state.statusPayload.mode,
|
|
25
|
-
cwd: state.cwd,
|
|
26
|
-
pid: process.pid,
|
|
27
|
-
}),
|
|
28
|
-
);
|
|
29
|
-
|
|
30
|
-
try {
|
|
31
|
-
for (let stepIndex = 0; stepIndex < state.steps.length; stepIndex++) {
|
|
32
|
-
if (state.interrupted) break;
|
|
33
|
-
const step = state.steps[stepIndex];
|
|
34
|
-
let shouldContinue = true;
|
|
35
|
-
if (isDynamicRunnerGroup(step)) {
|
|
36
|
-
shouldContinue = await runDynamicGroup(state, step, stepIndex);
|
|
37
|
-
} else if (isParallelGroup(step)) {
|
|
38
|
-
shouldContinue = await runParallelGroup(state, step, stepIndex);
|
|
39
|
-
} else {
|
|
40
|
-
shouldContinue = await runSequentialStep(state, step as SubagentStep, stepIndex);
|
|
41
|
-
}
|
|
42
|
-
if (!shouldContinue) break;
|
|
43
|
-
}
|
|
44
|
-
await finalizeRun(state);
|
|
45
|
-
} finally {
|
|
46
|
-
process.off(ASYNC_INTERRUPT_SIGNAL, onInterrupt);
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
function parseConfig(input: string): SubagentRunConfig {
|
|
51
|
-
return JSON.parse(input) as SubagentRunConfig;
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
function runConfig(config: SubagentRunConfig): void {
|
|
55
|
-
runSubagent(config).catch((runErr) => {
|
|
56
|
-
console.error("Subagent runner error:", runErr);
|
|
57
|
-
process.exit(1);
|
|
58
|
-
});
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
const configArg = process.argv[2];
|
|
62
|
-
if (configArg) {
|
|
63
|
-
try {
|
|
64
|
-
const configJson = fs.readFileSync(configArg, "utf-8");
|
|
65
|
-
const config = parseConfig(configJson);
|
|
66
|
-
try {
|
|
67
|
-
fs.unlinkSync(configArg);
|
|
68
|
-
} catch {
|
|
69
|
-
// Temp config cleanup is best effort.
|
|
70
|
-
}
|
|
71
|
-
runConfig(config);
|
|
72
|
-
} catch (err) {
|
|
73
|
-
console.error("Subagent runner error:", err);
|
|
74
|
-
process.exit(1);
|
|
75
|
-
}
|
|
76
|
-
} else {
|
|
77
|
-
let input = "";
|
|
78
|
-
process.stdin.setEncoding("utf-8");
|
|
79
|
-
process.stdin.on("data", (chunk) => {
|
|
80
|
-
input += chunk;
|
|
81
|
-
});
|
|
82
|
-
process.stdin.on("end", () => {
|
|
83
|
-
try {
|
|
84
|
-
runConfig(parseConfig(input));
|
|
85
|
-
} catch (err) {
|
|
86
|
-
console.error("Subagent runner error:", err);
|
|
87
|
-
process.exit(1);
|
|
88
|
-
}
|
|
89
|
-
});
|
|
90
|
-
}
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
interface AsyncOverrideParams {
|
|
2
|
-
async?: boolean;
|
|
3
|
-
}
|
|
4
|
-
|
|
5
|
-
export function applyForceTopLevelAsyncOverride<T extends AsyncOverrideParams>(
|
|
6
|
-
params: T,
|
|
7
|
-
depth: number,
|
|
8
|
-
forceTopLevelAsync: boolean,
|
|
9
|
-
): T {
|
|
10
|
-
if (!(depth === 0 && forceTopLevelAsync)) return params;
|
|
11
|
-
return { ...params, async: true };
|
|
12
|
-
}
|
|
@@ -1,140 +0,0 @@
|
|
|
1
|
-
import type { AgentConfig } from "../../agents/agents.ts";
|
|
2
|
-
import type { AgentProgress, ControlEvent, RunSyncOptions, SingleResult } from "../../shared/types.ts";
|
|
3
|
-
import { nextLongRunningTrigger } from "../shared/long-running-guard.ts";
|
|
4
|
-
import {
|
|
5
|
-
buildControlEvent,
|
|
6
|
-
claimControlNotification,
|
|
7
|
-
DEFAULT_CONTROL_CONFIG,
|
|
8
|
-
deriveActivityState,
|
|
9
|
-
shouldNotifyControlEvent,
|
|
10
|
-
} from "../shared/subagent-control.ts";
|
|
11
|
-
|
|
12
|
-
export type NeedsAttentionInput = {
|
|
13
|
-
message?: string;
|
|
14
|
-
reason?: ControlEvent["reason"];
|
|
15
|
-
recentFailureSummary?: string;
|
|
16
|
-
currentTool?: string;
|
|
17
|
-
currentPath?: string;
|
|
18
|
-
currentToolDurationMs?: number;
|
|
19
|
-
};
|
|
20
|
-
|
|
21
|
-
export type AttemptControlRuntime = {
|
|
22
|
-
config: NonNullable<RunSyncOptions["controlConfig"]>;
|
|
23
|
-
allControlEvents: ControlEvent[];
|
|
24
|
-
drainPendingControlEvents(): ControlEvent[] | undefined;
|
|
25
|
-
emitNeedsAttention(now: number, input?: NeedsAttentionInput): boolean;
|
|
26
|
-
updateActivityState(now: number): boolean;
|
|
27
|
-
};
|
|
28
|
-
|
|
29
|
-
export function createAttemptControlRuntime(input: {
|
|
30
|
-
options: RunSyncOptions;
|
|
31
|
-
agent: AgentConfig;
|
|
32
|
-
result: SingleResult;
|
|
33
|
-
progress: AgentProgress;
|
|
34
|
-
startTime: number;
|
|
35
|
-
}): AttemptControlRuntime {
|
|
36
|
-
const controlConfig = input.options.controlConfig ?? DEFAULT_CONTROL_CONFIG;
|
|
37
|
-
const allControlEvents: ControlEvent[] = [];
|
|
38
|
-
let pendingControlEvents: ControlEvent[] = [];
|
|
39
|
-
const emittedControlEventKeys = new Set<string>();
|
|
40
|
-
let activeLongRunningNotified = false;
|
|
41
|
-
|
|
42
|
-
const currentToolDurationMs = (now: number) =>
|
|
43
|
-
input.progress.currentToolStartedAt ? Math.max(0, now - input.progress.currentToolStartedAt) : undefined;
|
|
44
|
-
|
|
45
|
-
const emitControlEvent = (event: ControlEvent) => {
|
|
46
|
-
if (!shouldNotifyControlEvent(controlConfig, event)) return;
|
|
47
|
-
if (!claimControlNotification(controlConfig, event, emittedControlEventKeys)) return;
|
|
48
|
-
allControlEvents.push(event);
|
|
49
|
-
pendingControlEvents.push(event);
|
|
50
|
-
input.options.onControlEvent?.(event);
|
|
51
|
-
};
|
|
52
|
-
|
|
53
|
-
const emitNeedsAttention = (now: number, details: NeedsAttentionInput = {}): boolean => {
|
|
54
|
-
if (!controlConfig.enabled) return false;
|
|
55
|
-
const previous = input.progress.activityState;
|
|
56
|
-
input.progress.activityState = "needs_attention";
|
|
57
|
-
emitControlEvent(
|
|
58
|
-
buildControlEvent({
|
|
59
|
-
type: "needs_attention",
|
|
60
|
-
from: previous,
|
|
61
|
-
to: "needs_attention",
|
|
62
|
-
runId: input.options.runId,
|
|
63
|
-
agent: input.agent.name,
|
|
64
|
-
index: input.options.index,
|
|
65
|
-
ts: now,
|
|
66
|
-
lastActivityAt: input.progress.lastActivityAt,
|
|
67
|
-
message: details.message,
|
|
68
|
-
reason: details.reason ?? "idle",
|
|
69
|
-
turns: input.result.usage.turns,
|
|
70
|
-
tokens: input.progress.tokens,
|
|
71
|
-
toolCount: input.progress.toolCount,
|
|
72
|
-
currentTool: details.currentTool ?? input.progress.currentTool,
|
|
73
|
-
currentToolDurationMs: details.currentToolDurationMs ?? currentToolDurationMs(now),
|
|
74
|
-
currentPath: details.currentPath ?? input.progress.currentPath,
|
|
75
|
-
recentFailureSummary: details.recentFailureSummary,
|
|
76
|
-
}),
|
|
77
|
-
);
|
|
78
|
-
return previous !== "needs_attention";
|
|
79
|
-
};
|
|
80
|
-
|
|
81
|
-
const emitActiveLongRunning = (now: number, reason: ControlEvent["reason"]): boolean => {
|
|
82
|
-
if (!controlConfig.enabled || activeLongRunningNotified || input.progress.activityState === "needs_attention")
|
|
83
|
-
return false;
|
|
84
|
-
activeLongRunningNotified = true;
|
|
85
|
-
const previous = input.progress.activityState;
|
|
86
|
-
input.progress.activityState = "active_long_running";
|
|
87
|
-
emitControlEvent(
|
|
88
|
-
buildControlEvent({
|
|
89
|
-
type: "active_long_running",
|
|
90
|
-
from: previous,
|
|
91
|
-
to: "active_long_running",
|
|
92
|
-
runId: input.options.runId,
|
|
93
|
-
agent: input.agent.name,
|
|
94
|
-
index: input.options.index,
|
|
95
|
-
ts: now,
|
|
96
|
-
message: `${input.agent.name} is still active but long-running`,
|
|
97
|
-
reason,
|
|
98
|
-
turns: input.result.usage.turns,
|
|
99
|
-
tokens: input.progress.tokens,
|
|
100
|
-
toolCount: input.progress.toolCount,
|
|
101
|
-
currentTool: input.progress.currentTool,
|
|
102
|
-
currentToolDurationMs: currentToolDurationMs(now),
|
|
103
|
-
currentPath: input.progress.currentPath,
|
|
104
|
-
elapsedMs: now - input.startTime,
|
|
105
|
-
}),
|
|
106
|
-
);
|
|
107
|
-
return true;
|
|
108
|
-
};
|
|
109
|
-
|
|
110
|
-
return {
|
|
111
|
-
config: controlConfig,
|
|
112
|
-
allControlEvents,
|
|
113
|
-
drainPendingControlEvents: () => {
|
|
114
|
-
if (pendingControlEvents.length === 0) return undefined;
|
|
115
|
-
const events = pendingControlEvents;
|
|
116
|
-
pendingControlEvents = [];
|
|
117
|
-
return events;
|
|
118
|
-
},
|
|
119
|
-
emitNeedsAttention,
|
|
120
|
-
updateActivityState: (now: number) => {
|
|
121
|
-
if (!controlConfig.enabled) return false;
|
|
122
|
-
const idleState = deriveActivityState({
|
|
123
|
-
config: controlConfig,
|
|
124
|
-
startedAt: input.startTime,
|
|
125
|
-
lastActivityAt: input.progress.lastActivityAt,
|
|
126
|
-
now,
|
|
127
|
-
});
|
|
128
|
-
if (idleState === "needs_attention") {
|
|
129
|
-
return input.progress.activityState === "needs_attention" ? false : emitNeedsAttention(now);
|
|
130
|
-
}
|
|
131
|
-
const activeReason = nextLongRunningTrigger(controlConfig, {
|
|
132
|
-
startedAt: input.startTime,
|
|
133
|
-
now,
|
|
134
|
-
turns: input.result.usage.turns,
|
|
135
|
-
tokens: input.progress.tokens,
|
|
136
|
-
});
|
|
137
|
-
return activeReason ? emitActiveLongRunning(now, activeReason) : false;
|
|
138
|
-
},
|
|
139
|
-
};
|
|
140
|
-
}
|
|
@@ -1,108 +0,0 @@
|
|
|
1
|
-
import type { AgentProgress, ControlEvent, RunSyncOptions, SingleResult } from "../../shared/types.ts";
|
|
2
|
-
import { detectSubagentError, getFinalOutput } from "../../shared/utils.ts";
|
|
3
|
-
import { formatSavedOutputReference, resolveSingleOutput } from "../shared/single-output.ts";
|
|
4
|
-
import { readStructuredOutput } from "../shared/structured-output.ts";
|
|
5
|
-
import type { RunSingleAttemptShared } from "./execution-attempt-types.ts";
|
|
6
|
-
import { artifactOutputByResult, snapshotProgress, snapshotResult } from "./execution-utils.ts";
|
|
7
|
-
|
|
8
|
-
export function finalizeSingleAttempt(input: {
|
|
9
|
-
result: SingleResult;
|
|
10
|
-
progress: AgentProgress;
|
|
11
|
-
exitCode: number;
|
|
12
|
-
interruptedByControl: boolean;
|
|
13
|
-
allControlEvents: ControlEvent[];
|
|
14
|
-
options: RunSyncOptions;
|
|
15
|
-
shared: RunSingleAttemptShared;
|
|
16
|
-
startTime: number;
|
|
17
|
-
}): SingleResult {
|
|
18
|
-
const { result, progress, options, shared, allControlEvents } = input;
|
|
19
|
-
result.exitCode = input.exitCode;
|
|
20
|
-
if (input.interruptedByControl) {
|
|
21
|
-
result.exitCode = 0;
|
|
22
|
-
result.interrupted = true;
|
|
23
|
-
result.error = undefined;
|
|
24
|
-
result.finalOutput = result.finalOutput || "Interrupted. Waiting for explicit next action.";
|
|
25
|
-
result.controlEvents = allControlEvents.length ? allControlEvents : undefined;
|
|
26
|
-
progress.activityState = undefined;
|
|
27
|
-
progress.durationMs = Date.now() - input.startTime;
|
|
28
|
-
result.progressSummary = {
|
|
29
|
-
toolCount: progress.toolCount,
|
|
30
|
-
tokens: progress.tokens,
|
|
31
|
-
durationMs: progress.durationMs,
|
|
32
|
-
};
|
|
33
|
-
return result;
|
|
34
|
-
}
|
|
35
|
-
if (result.detached) {
|
|
36
|
-
result.exitCode = -2;
|
|
37
|
-
result.finalOutput = "Detached for intercom coordination; awaiting the child's eventual result.";
|
|
38
|
-
return result;
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
if (result.error && result.exitCode === 0) result.exitCode = 1;
|
|
42
|
-
if (result.exitCode === 0 && !result.error) {
|
|
43
|
-
const errInfo = detectSubagentError(result.messages ?? []);
|
|
44
|
-
if (errInfo.hasError) {
|
|
45
|
-
result.exitCode = errInfo.exitCode ?? 1;
|
|
46
|
-
result.error = errInfo.details
|
|
47
|
-
? `${errInfo.errorType} failed (exit ${errInfo.exitCode}): ${errInfo.details}`
|
|
48
|
-
: `${errInfo.errorType} failed with exit code ${errInfo.exitCode}`;
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
|
-
if (options.structuredOutput && result.exitCode === 0 && !result.error) {
|
|
52
|
-
const structured = readStructuredOutput(options.structuredOutput);
|
|
53
|
-
result.structuredOutputSchemaPath = options.structuredOutput.schemaPath;
|
|
54
|
-
result.structuredOutputPath = options.structuredOutput.outputPath;
|
|
55
|
-
if (structured.error) {
|
|
56
|
-
result.exitCode = 1;
|
|
57
|
-
result.error = structured.error;
|
|
58
|
-
} else {
|
|
59
|
-
result.structuredOutput = structured.value;
|
|
60
|
-
}
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
progress.status = result.exitCode === 0 ? "completed" : "failed";
|
|
64
|
-
progress.durationMs = Date.now() - input.startTime;
|
|
65
|
-
if (result.error) {
|
|
66
|
-
progress.error = result.error;
|
|
67
|
-
if (progress.currentTool) progress.failedTool = progress.currentTool;
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
result.progressSummary = {
|
|
71
|
-
toolCount: progress.toolCount,
|
|
72
|
-
tokens: progress.tokens,
|
|
73
|
-
durationMs: progress.durationMs,
|
|
74
|
-
};
|
|
75
|
-
|
|
76
|
-
let fullOutput = getFinalOutput(result.messages ?? []);
|
|
77
|
-
if (options.outputPath && result.exitCode === 0) {
|
|
78
|
-
const resolvedOutput = resolveSingleOutput(options.outputPath, fullOutput, shared.outputSnapshot);
|
|
79
|
-
fullOutput = resolvedOutput.fullOutput;
|
|
80
|
-
result.savedOutputPath = resolvedOutput.savedPath;
|
|
81
|
-
result.outputSaveError = resolvedOutput.saveError;
|
|
82
|
-
if (resolvedOutput.savedPath) {
|
|
83
|
-
result.outputReference = formatSavedOutputReference(resolvedOutput.savedPath, fullOutput);
|
|
84
|
-
}
|
|
85
|
-
}
|
|
86
|
-
artifactOutputByResult.set(result, fullOutput);
|
|
87
|
-
result.outputMode = options.outputMode ?? "inline";
|
|
88
|
-
result.finalOutput =
|
|
89
|
-
options.outputMode === "file-only" && result.savedOutputPath && result.outputReference
|
|
90
|
-
? result.outputReference.message
|
|
91
|
-
: fullOutput;
|
|
92
|
-
result.controlEvents = allControlEvents.length ? allControlEvents : undefined;
|
|
93
|
-
if (options.onUpdate) {
|
|
94
|
-
const finalText = result.finalOutput || result.error || "(no output)";
|
|
95
|
-
const progressSnapshot = snapshotProgress(progress);
|
|
96
|
-
const resultSnapshot = snapshotResult(result, progressSnapshot);
|
|
97
|
-
options.onUpdate({
|
|
98
|
-
content: [{ type: "text", text: finalText }],
|
|
99
|
-
details: {
|
|
100
|
-
mode: "single",
|
|
101
|
-
results: [resultSnapshot],
|
|
102
|
-
progress: [progressSnapshot],
|
|
103
|
-
controlEvents: allControlEvents.length ? allControlEvents : undefined,
|
|
104
|
-
},
|
|
105
|
-
});
|
|
106
|
-
}
|
|
107
|
-
return result;
|
|
108
|
-
}
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
import type { CodexFastModeResolvedSettings, CodexFastModeScope } from "@bastani/atomic";
|
|
2
|
-
import type { ArtifactPaths } from "../../shared/types.ts";
|
|
3
|
-
import type { SingleOutputSnapshot } from "../shared/single-output.ts";
|
|
4
|
-
|
|
5
|
-
export type RunSingleAttemptShared = {
|
|
6
|
-
sessionEnabled: boolean;
|
|
7
|
-
systemPrompt: string;
|
|
8
|
-
resolvedSkillNames?: string[];
|
|
9
|
-
skillsWarning?: string;
|
|
10
|
-
jsonlPath?: string;
|
|
11
|
-
artifactPaths?: ArtifactPaths;
|
|
12
|
-
attemptNotes: string[];
|
|
13
|
-
outputSnapshot?: SingleOutputSnapshot;
|
|
14
|
-
fastModeSettings: CodexFastModeResolvedSettings;
|
|
15
|
-
fastModeScope: CodexFastModeScope;
|
|
16
|
-
originalTask?: string;
|
|
17
|
-
};
|