@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,358 +0,0 @@
|
|
|
1
|
-
import * as fs from "node:fs";
|
|
2
|
-
import * as path from "node:path";
|
|
3
|
-
import { resolveSubagentIntercomTarget } from "../../intercom/intercom-bridge.ts";
|
|
4
|
-
import { formatModelThinking } from "../../shared/formatters.ts";
|
|
5
|
-
import { formatActivityLabel } from "../../shared/status-format.ts";
|
|
6
|
-
import {
|
|
7
|
-
ASYNC_DIR,
|
|
8
|
-
type AsyncStatus,
|
|
9
|
-
type NestedRunSummary,
|
|
10
|
-
RESULTS_DIR,
|
|
11
|
-
type SubagentState,
|
|
12
|
-
type SubagentToolResult,
|
|
13
|
-
} from "../../shared/types.ts";
|
|
14
|
-
import {
|
|
15
|
-
attachRootChildrenToSteps,
|
|
16
|
-
findNestedRouteForRootId,
|
|
17
|
-
type NestedRunResolutionScope,
|
|
18
|
-
projectNestedRegistryForRoot,
|
|
19
|
-
} from "../shared/nested-events.ts";
|
|
20
|
-
import { formatNestedRunStatusLines } from "../shared/nested-render.ts";
|
|
21
|
-
import { resolveAsyncRunLocation } from "./async-resume.ts";
|
|
22
|
-
import {
|
|
23
|
-
formatAsyncRunList,
|
|
24
|
-
formatAsyncRunOutputPath,
|
|
25
|
-
formatAsyncRunProgressLabel,
|
|
26
|
-
listAsyncRuns,
|
|
27
|
-
} from "./async-status.ts";
|
|
28
|
-
import { flatToLogicalStepIndex, normalizeParallelGroups } from "./parallel-groups.ts";
|
|
29
|
-
import { resolveSubagentRunId } from "./run-id-resolver.ts";
|
|
30
|
-
import { reconcileAsyncRun, reconcileNestedAsyncDescendants } from "./stale-run-reconciler.ts";
|
|
31
|
-
|
|
32
|
-
interface RunStatusParams {
|
|
33
|
-
action?: "status";
|
|
34
|
-
id?: string;
|
|
35
|
-
runId?: string;
|
|
36
|
-
dir?: string;
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
interface RunStatusDeps {
|
|
40
|
-
asyncDirRoot?: string;
|
|
41
|
-
resultsDir?: string;
|
|
42
|
-
kill?: (pid: number, signal?: NodeJS.Signals | 0) => boolean;
|
|
43
|
-
now?: () => number;
|
|
44
|
-
state?: SubagentState;
|
|
45
|
-
nested?: NestedRunResolutionScope;
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
function hasExistingSessionFile(value: unknown): value is string {
|
|
49
|
-
return typeof value === "string" && fs.existsSync(value);
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
function formatResumeGuidance(
|
|
53
|
-
runId: string | undefined,
|
|
54
|
-
children: Array<{ agent?: unknown; sessionFile?: unknown }>,
|
|
55
|
-
fallbackSessionFile?: unknown,
|
|
56
|
-
): string {
|
|
57
|
-
const knownChildren = children
|
|
58
|
-
.map((child, index) => ({ child, index }))
|
|
59
|
-
.filter(({ child }) => typeof child.agent === "string");
|
|
60
|
-
if (!runId || knownChildren.length === 0) return "Resume: unavailable; no child session file was persisted.";
|
|
61
|
-
const singleSessionFile = knownChildren[0]?.child.sessionFile ?? fallbackSessionFile;
|
|
62
|
-
if (children.length === 1 && knownChildren.length === 1 && hasExistingSessionFile(singleSessionFile)) {
|
|
63
|
-
return `Revive: subagent({ action: "resume", id: "${runId}", message: "..." })`;
|
|
64
|
-
}
|
|
65
|
-
const childWithSession = knownChildren.find(({ child }) => hasExistingSessionFile(child.sessionFile));
|
|
66
|
-
if (childWithSession) {
|
|
67
|
-
return `Revive child: subagent({ action: "resume", id: "${runId}", index: ${childWithSession.index}, message: "..." })`;
|
|
68
|
-
}
|
|
69
|
-
return "Resume: unavailable; no child session file was persisted.";
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
function stepLineLabel(status: AsyncStatus, index: number): string {
|
|
73
|
-
const steps = status.steps ?? [];
|
|
74
|
-
if (status.mode === "parallel") return `Agent ${index + 1}/${steps.length || 1}`;
|
|
75
|
-
if (status.mode === "chain") {
|
|
76
|
-
const chainStepCount = status.chainStepCount ?? (steps.length || 1);
|
|
77
|
-
const groups = normalizeParallelGroups(status.parallelGroups, steps.length, chainStepCount);
|
|
78
|
-
const group = groups.find((candidate) => index >= candidate.start && index < candidate.start + candidate.count);
|
|
79
|
-
if (group) return `Step ${group.stepIndex + 1}/${chainStepCount} Agent ${index - group.start + 1}/${group.count}`;
|
|
80
|
-
return `Step ${flatToLogicalStepIndex(index, chainStepCount, groups) + 1}/${chainStepCount}`;
|
|
81
|
-
}
|
|
82
|
-
return `Step ${index + 1}`;
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
function nestedRunDisplayName(run: NestedRunSummary): string {
|
|
86
|
-
if (run.agent) return run.agent;
|
|
87
|
-
if (run.agents?.length) return run.agents.join(", ");
|
|
88
|
-
return run.id;
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
function formatNestedExactStatus(rootRunId: string, run: NestedRunSummary): string {
|
|
92
|
-
const lines = [
|
|
93
|
-
`Nested run: ${run.id}`,
|
|
94
|
-
`Root: ${rootRunId}`,
|
|
95
|
-
`Parent: ${run.parentRunId}${run.parentStepIndex !== undefined ? ` step ${run.parentStepIndex + 1}` : ""}`,
|
|
96
|
-
`State: ${run.state}`,
|
|
97
|
-
run.activityState || run.lastActivityAt
|
|
98
|
-
? `Activity: ${formatActivityLabel(run.lastActivityAt, run.activityState)}`
|
|
99
|
-
: undefined,
|
|
100
|
-
run.mode ? `Mode: ${run.mode}` : undefined,
|
|
101
|
-
`Agent: ${nestedRunDisplayName(run)}`,
|
|
102
|
-
run.currentStep !== undefined
|
|
103
|
-
? `Progress: step ${run.currentStep + 1}/${run.chainStepCount ?? run.steps?.length ?? 1}`
|
|
104
|
-
: undefined,
|
|
105
|
-
run.asyncDir ? `Dir: ${run.asyncDir}` : undefined,
|
|
106
|
-
run.sessionFile ? `Session: ${run.sessionFile}` : undefined,
|
|
107
|
-
run.error ? `Error: ${run.error}` : undefined,
|
|
108
|
-
].filter((line): line is string => Boolean(line));
|
|
109
|
-
if (run.path.length) {
|
|
110
|
-
lines.push(
|
|
111
|
-
`Path: ${run.path.map((part) => `${part.runId}${part.stepIndex !== undefined ? `:${part.stepIndex + 1}` : ""}${part.agent ? `:${part.agent}` : ""}`).join(" > ")} > ${run.id}`,
|
|
112
|
-
);
|
|
113
|
-
}
|
|
114
|
-
if (run.steps?.length) {
|
|
115
|
-
lines.push("Steps:");
|
|
116
|
-
for (const [index, step] of run.steps.entries()) {
|
|
117
|
-
const activity =
|
|
118
|
-
step.status === "running" ? formatActivityLabel(step.lastActivityAt, step.activityState) : undefined;
|
|
119
|
-
lines.push(
|
|
120
|
-
` ${index + 1}. ${step.agent} ${step.status}${activity ? `, ${activity}` : ""}${step.error ? `, error: ${step.error}` : ""}`,
|
|
121
|
-
);
|
|
122
|
-
lines.push(...formatNestedRunStatusLines(step.children, { indent: " ", commandHints: true }));
|
|
123
|
-
}
|
|
124
|
-
}
|
|
125
|
-
lines.push(...formatNestedRunStatusLines(run.children, { indent: " ", commandHints: true }));
|
|
126
|
-
lines.push(
|
|
127
|
-
"Commands:",
|
|
128
|
-
` Status: subagent({ action: "status", id: "${run.id}" })`,
|
|
129
|
-
` Interrupt: subagent({ action: "interrupt", id: "${run.id}" })`,
|
|
130
|
-
` Resume: subagent({ action: "resume", id: "${run.id}", message: "..." })`,
|
|
131
|
-
` Root status: subagent({ action: "status", id: "${rootRunId}" })`,
|
|
132
|
-
);
|
|
133
|
-
return lines.join("\n");
|
|
134
|
-
}
|
|
135
|
-
|
|
136
|
-
export function inspectSubagentStatus(params: RunStatusParams, deps: RunStatusDeps = {}): SubagentToolResult {
|
|
137
|
-
const asyncDirRoot = deps.asyncDirRoot ?? ASYNC_DIR;
|
|
138
|
-
const resultsDir = deps.resultsDir ?? RESULTS_DIR;
|
|
139
|
-
if (!params.id && !params.runId && !params.dir) {
|
|
140
|
-
if (deps.nested) {
|
|
141
|
-
return {
|
|
142
|
-
content: [
|
|
143
|
-
{ type: "text", text: "Child-safe subagent status requires an id when no foreground run is active." },
|
|
144
|
-
],
|
|
145
|
-
isError: true,
|
|
146
|
-
details: { mode: "single", results: [] },
|
|
147
|
-
};
|
|
148
|
-
}
|
|
149
|
-
try {
|
|
150
|
-
const runs = listAsyncRuns(asyncDirRoot, {
|
|
151
|
-
states: ["queued", "running"],
|
|
152
|
-
resultsDir,
|
|
153
|
-
kill: deps.kill,
|
|
154
|
-
now: deps.now,
|
|
155
|
-
});
|
|
156
|
-
return {
|
|
157
|
-
content: [{ type: "text", text: formatAsyncRunList(runs) }],
|
|
158
|
-
details: { mode: "single", results: [] },
|
|
159
|
-
};
|
|
160
|
-
} catch (error) {
|
|
161
|
-
const message = error instanceof Error ? error.message : String(error);
|
|
162
|
-
return {
|
|
163
|
-
content: [{ type: "text", text: message }],
|
|
164
|
-
isError: true,
|
|
165
|
-
details: { mode: "single", results: [] },
|
|
166
|
-
};
|
|
167
|
-
}
|
|
168
|
-
}
|
|
169
|
-
|
|
170
|
-
let location: ReturnType<typeof resolveAsyncRunLocation>;
|
|
171
|
-
try {
|
|
172
|
-
const requestedId = params.id ?? params.runId;
|
|
173
|
-
if (!params.dir && requestedId) {
|
|
174
|
-
const resolved = resolveSubagentRunId(requestedId, {
|
|
175
|
-
asyncDirRoot,
|
|
176
|
-
resultsDir,
|
|
177
|
-
state: deps.state,
|
|
178
|
-
nested: deps.nested,
|
|
179
|
-
});
|
|
180
|
-
if (resolved?.kind === "nested") {
|
|
181
|
-
reconcileNestedAsyncDescendants(resolved.match.route, { resultsDir, kill: deps.kill, now: deps.now });
|
|
182
|
-
const refreshed = resolveSubagentRunId(requestedId, {
|
|
183
|
-
asyncDirRoot,
|
|
184
|
-
resultsDir,
|
|
185
|
-
state: deps.state,
|
|
186
|
-
nested: deps.nested,
|
|
187
|
-
});
|
|
188
|
-
const nested = refreshed?.kind === "nested" ? refreshed : resolved;
|
|
189
|
-
return {
|
|
190
|
-
content: [{ type: "text", text: formatNestedExactStatus(nested.match.rootRunId, nested.match.run) }],
|
|
191
|
-
details: { mode: "single", results: [] },
|
|
192
|
-
};
|
|
193
|
-
}
|
|
194
|
-
if (resolved?.kind === "async") location = resolved.location;
|
|
195
|
-
else location = { asyncDir: null, resultPath: null, resolvedId: requestedId };
|
|
196
|
-
} else {
|
|
197
|
-
location = resolveAsyncRunLocation(params, asyncDirRoot, resultsDir);
|
|
198
|
-
}
|
|
199
|
-
} catch (error) {
|
|
200
|
-
const message = error instanceof Error ? error.message : String(error);
|
|
201
|
-
return {
|
|
202
|
-
content: [{ type: "text", text: message }],
|
|
203
|
-
isError: true,
|
|
204
|
-
details: { mode: "single", results: [] },
|
|
205
|
-
};
|
|
206
|
-
}
|
|
207
|
-
const { asyncDir, resultPath, resolvedId } = location;
|
|
208
|
-
|
|
209
|
-
if (!asyncDir && !resultPath) {
|
|
210
|
-
return {
|
|
211
|
-
content: [{ type: "text", text: "Async run not found. Provide id or dir." }],
|
|
212
|
-
isError: true,
|
|
213
|
-
details: { mode: "single", results: [] },
|
|
214
|
-
};
|
|
215
|
-
}
|
|
216
|
-
|
|
217
|
-
if (asyncDir) {
|
|
218
|
-
let reconciliation: ReturnType<typeof reconcileAsyncRun>;
|
|
219
|
-
try {
|
|
220
|
-
reconciliation = reconcileAsyncRun(asyncDir, { resultsDir, kill: deps.kill, now: deps.now });
|
|
221
|
-
} catch (error) {
|
|
222
|
-
const message = error instanceof Error ? error.message : String(error);
|
|
223
|
-
return {
|
|
224
|
-
content: [{ type: "text", text: message }],
|
|
225
|
-
isError: true,
|
|
226
|
-
details: { mode: "single", results: [] },
|
|
227
|
-
};
|
|
228
|
-
}
|
|
229
|
-
const status = reconciliation.status;
|
|
230
|
-
const effectiveRunId = status?.runId ?? resolvedId ?? "unknown";
|
|
231
|
-
const logPath = path.join(asyncDir, `subagent-log-${effectiveRunId}.md`);
|
|
232
|
-
const eventsPath = path.join(asyncDir, "events.jsonl");
|
|
233
|
-
if (status) {
|
|
234
|
-
let nestedChildren: NestedRunSummary[] = [];
|
|
235
|
-
let nestedWarning: string | undefined;
|
|
236
|
-
try {
|
|
237
|
-
const nestedRoute = findNestedRouteForRootId(status.runId);
|
|
238
|
-
if (nestedRoute)
|
|
239
|
-
reconcileNestedAsyncDescendants(nestedRoute, { resultsDir, kill: deps.kill, now: deps.now });
|
|
240
|
-
nestedChildren = projectNestedRegistryForRoot(status.runId)?.children ?? [];
|
|
241
|
-
attachRootChildrenToSteps(status.runId, status.steps, nestedChildren);
|
|
242
|
-
} catch (error) {
|
|
243
|
-
nestedWarning = `Nested status unavailable: ${error instanceof Error ? error.message : String(error)}`;
|
|
244
|
-
}
|
|
245
|
-
const outputPath = formatAsyncRunOutputPath({ asyncDir, outputFile: status.outputFile });
|
|
246
|
-
const progressLabel = formatAsyncRunProgressLabel({
|
|
247
|
-
mode: status.mode,
|
|
248
|
-
state: status.state,
|
|
249
|
-
currentStep: status.currentStep,
|
|
250
|
-
chainStepCount: status.chainStepCount,
|
|
251
|
-
parallelGroups: status.parallelGroups,
|
|
252
|
-
steps: (status.steps ?? []).map((step, index) => ({ index, agent: step.agent, status: step.status })),
|
|
253
|
-
});
|
|
254
|
-
const started = new Date(status.startedAt).toISOString();
|
|
255
|
-
const updated = status.lastUpdate ? new Date(status.lastUpdate).toISOString() : "n/a";
|
|
256
|
-
const statusActivityText =
|
|
257
|
-
status.state === "running" ? formatActivityLabel(status.lastActivityAt, status.activityState) : undefined;
|
|
258
|
-
|
|
259
|
-
const lines = [
|
|
260
|
-
`Run: ${status.runId}`,
|
|
261
|
-
`State: ${status.state}`,
|
|
262
|
-
statusActivityText ? `Activity: ${statusActivityText}` : undefined,
|
|
263
|
-
`Mode: ${status.mode}`,
|
|
264
|
-
`Progress: ${progressLabel}`,
|
|
265
|
-
`Started: ${started}`,
|
|
266
|
-
`Updated: ${updated}`,
|
|
267
|
-
`Dir: ${asyncDir}`,
|
|
268
|
-
outputPath ? `Output: ${outputPath}` : undefined,
|
|
269
|
-
reconciliation.message ? `Diagnosis: ${reconciliation.message}` : undefined,
|
|
270
|
-
reconciliation.resultPath && fs.existsSync(reconciliation.resultPath)
|
|
271
|
-
? `Result: ${reconciliation.resultPath}`
|
|
272
|
-
: undefined,
|
|
273
|
-
].filter((line): line is string => Boolean(line));
|
|
274
|
-
for (const [index, step] of (status.steps ?? []).entries()) {
|
|
275
|
-
const stepActivityText =
|
|
276
|
-
step.status === "running" ? formatActivityLabel(step.lastActivityAt, step.activityState) : undefined;
|
|
277
|
-
const modelThinking = formatModelThinking(step.model, step.thinking, step.fastMode);
|
|
278
|
-
const modelText = modelThinking ? ` (${modelThinking})` : "";
|
|
279
|
-
const errorText = step.error ? `, error: ${step.error}` : "";
|
|
280
|
-
const display = step.label ? `${step.label} (${step.agent})` : step.agent;
|
|
281
|
-
const phase = step.phase ? `[${step.phase}] ` : "";
|
|
282
|
-
lines.push(
|
|
283
|
-
`${stepLineLabel(status, index)}: ${phase}${display} ${step.status}${modelText}${stepActivityText ? `, ${stepActivityText}` : ""}${errorText}`,
|
|
284
|
-
);
|
|
285
|
-
lines.push(
|
|
286
|
-
...formatNestedRunStatusLines(step.children, { indent: " ", commandHints: true, maxLines: 20 }),
|
|
287
|
-
);
|
|
288
|
-
const stepOutputPath = path.join(asyncDir, `output-${index}.log`);
|
|
289
|
-
if (stepOutputPath !== outputPath && fs.existsSync(stepOutputPath))
|
|
290
|
-
lines.push(` Output: ${stepOutputPath}`);
|
|
291
|
-
if (step.status === "running") {
|
|
292
|
-
lines.push(
|
|
293
|
-
` Intercom target: ${resolveSubagentIntercomTarget(status.runId, step.agent, index)} (if registered)`,
|
|
294
|
-
);
|
|
295
|
-
}
|
|
296
|
-
}
|
|
297
|
-
const attached = new Set(
|
|
298
|
-
(status.steps ?? []).flatMap((step) => step.children?.map((child) => child.id) ?? []),
|
|
299
|
-
);
|
|
300
|
-
const unattached = nestedChildren.filter((child) => !attached.has(child.id));
|
|
301
|
-
lines.push(...formatNestedRunStatusLines(unattached, { indent: "", commandHints: true, maxLines: 20 }));
|
|
302
|
-
if (nestedWarning) lines.push(`Warning: ${nestedWarning}`);
|
|
303
|
-
if (status.sessionFile) lines.push(`Session: ${status.sessionFile}`);
|
|
304
|
-
if (status.state !== "running") {
|
|
305
|
-
lines.push(formatResumeGuidance(status.runId, status.steps ?? [], status.sessionFile));
|
|
306
|
-
}
|
|
307
|
-
if (fs.existsSync(logPath)) lines.push(`Log: ${logPath}`);
|
|
308
|
-
if (fs.existsSync(eventsPath)) lines.push(`Events: ${eventsPath}`);
|
|
309
|
-
|
|
310
|
-
return { content: [{ type: "text", text: lines.join("\n") }], details: { mode: "single", results: [] } };
|
|
311
|
-
}
|
|
312
|
-
}
|
|
313
|
-
|
|
314
|
-
if (resultPath) {
|
|
315
|
-
try {
|
|
316
|
-
const raw = fs.readFileSync(resultPath, "utf-8");
|
|
317
|
-
const data = JSON.parse(raw) as {
|
|
318
|
-
id?: string;
|
|
319
|
-
runId?: string;
|
|
320
|
-
agent?: string;
|
|
321
|
-
success?: boolean;
|
|
322
|
-
summary?: string;
|
|
323
|
-
exitCode?: number;
|
|
324
|
-
state?: string;
|
|
325
|
-
sessionFile?: string;
|
|
326
|
-
results?: Array<{ agent?: string; sessionFile?: string }>;
|
|
327
|
-
};
|
|
328
|
-
const status = data.success
|
|
329
|
-
? "complete"
|
|
330
|
-
: data.state === "paused" || data.exitCode === 0
|
|
331
|
-
? "paused"
|
|
332
|
-
: "failed";
|
|
333
|
-
const runId = data.runId ?? data.id ?? resolvedId;
|
|
334
|
-
const lines = [`Run: ${runId}`, `State: ${status}`, `Result: ${resultPath}`];
|
|
335
|
-
const children = Array.isArray(data.results)
|
|
336
|
-
? data.results
|
|
337
|
-
: data.agent
|
|
338
|
-
? [{ agent: data.agent, sessionFile: data.sessionFile }]
|
|
339
|
-
: [];
|
|
340
|
-
lines.push(formatResumeGuidance(runId, children, data.sessionFile));
|
|
341
|
-
if (data.summary) lines.push("", data.summary);
|
|
342
|
-
return { content: [{ type: "text", text: lines.join("\n") }], details: { mode: "single", results: [] } };
|
|
343
|
-
} catch (error) {
|
|
344
|
-
const message = error instanceof Error ? error.message : String(error);
|
|
345
|
-
return {
|
|
346
|
-
content: [{ type: "text", text: `Failed to read async result file: ${message}` }],
|
|
347
|
-
isError: true,
|
|
348
|
-
details: { mode: "single", results: [] },
|
|
349
|
-
};
|
|
350
|
-
}
|
|
351
|
-
}
|
|
352
|
-
|
|
353
|
-
return {
|
|
354
|
-
content: [{ type: "text", text: "Status file not found." }],
|
|
355
|
-
isError: true,
|
|
356
|
-
details: { mode: "single", results: [] },
|
|
357
|
-
};
|
|
358
|
-
}
|