@selesai/code 0.5.19 → 0.5.21
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/dist/extensions/handoff-new.test.ts +8 -9
- package/dist/extensions/handoff-new.ts +6 -8
- package/dist/extensions/pi-intercom/broker/spawn.test.ts +31 -0
- package/dist/extensions/pi-intercom/broker/spawn.ts +5 -3
- package/dist/extensions/pi-subagents/CHANGELOG.md +1367 -0
- package/dist/extensions/pi-subagents/README.md +602 -220
- package/dist/extensions/pi-subagents/banner.png +0 -0
- package/dist/extensions/pi-subagents/index.ts +1 -0
- package/dist/extensions/pi-subagents/install.mjs +3 -3
- package/dist/extensions/pi-subagents/package-lock.json +3405 -0
- package/dist/extensions/pi-subagents/package.json +26 -14
- package/dist/extensions/pi-subagents/prompts/gather-context-and-clarify.md +1 -1
- package/dist/extensions/pi-subagents/prompts/parallel-cleanup.md +9 -9
- package/dist/extensions/pi-subagents/prompts/parallel-context-build.md +3 -3
- package/dist/extensions/pi-subagents/prompts/parallel-handoff-plan.md +7 -7
- package/dist/extensions/pi-subagents/prompts/parallel-research.md +6 -6
- package/dist/extensions/pi-subagents/prompts/parallel-review.md +8 -8
- package/dist/extensions/pi-subagents/prompts/review-loop.md +13 -11
- package/dist/extensions/pi-subagents/skills/pi-subagents/SKILL.md +267 -176
- package/dist/extensions/pi-subagents/src/agents/agent-management.ts +89 -16
- package/dist/extensions/pi-subagents/src/agents/agent-serializer.ts +19 -0
- package/dist/extensions/pi-subagents/src/agents/agents.ts +218 -120
- package/dist/extensions/pi-subagents/src/agents/frontmatter.ts +67 -13
- package/dist/extensions/pi-subagents/src/agents/proactive-skills.ts +2 -2
- package/dist/extensions/pi-subagents/src/agents/skills.ts +25 -12
- package/dist/extensions/pi-subagents/src/api/background-work.ts +197 -0
- package/dist/extensions/pi-subagents/src/api/capability-ceiling.ts +17 -0
- package/dist/extensions/pi-subagents/src/api/delegation.ts +285 -0
- package/dist/extensions/pi-subagents/src/api/preflight.ts +399 -0
- package/dist/extensions/pi-subagents/src/extension/chain-validation.ts +165 -0
- package/dist/extensions/pi-subagents/src/extension/config.ts +7 -1
- package/dist/extensions/pi-subagents/src/extension/doctor.ts +15 -0
- package/dist/extensions/pi-subagents/src/extension/fanout-child.ts +3 -1
- package/dist/extensions/pi-subagents/src/extension/index.ts +113 -157
- package/dist/extensions/pi-subagents/src/extension/rpc.ts +41 -4
- package/dist/extensions/pi-subagents/src/extension/schemas.ts +45 -15
- package/dist/extensions/pi-subagents/src/extension/steering-notices.ts +35 -0
- package/dist/extensions/pi-subagents/src/extension/tool-description.ts +28 -15
- package/dist/extensions/pi-subagents/src/intercom/intercom-bridge.ts +4 -3
- package/dist/extensions/pi-subagents/src/intercom/native-supervisor-channel.ts +225 -29
- package/dist/extensions/pi-subagents/src/intercom/result-intercom.ts +11 -0
- package/dist/extensions/pi-subagents/src/profiles/profiles.ts +8 -10
- package/dist/extensions/pi-subagents/src/runs/background/async-execution.ts +452 -62
- package/dist/extensions/pi-subagents/src/runs/background/async-job-tracker.ts +60 -9
- package/dist/extensions/pi-subagents/src/runs/background/async-resume.ts +198 -52
- package/dist/extensions/pi-subagents/src/runs/background/async-status.ts +119 -21
- package/dist/extensions/pi-subagents/src/runs/background/auto-drain.ts +67 -0
- package/dist/extensions/pi-subagents/src/runs/background/chain-append.ts +2 -0
- package/dist/extensions/pi-subagents/src/runs/background/chain-root-attachment.ts +16 -8
- package/dist/extensions/pi-subagents/src/runs/background/completion-batcher.ts +6 -4
- package/dist/extensions/pi-subagents/src/runs/background/completion-dedupe.ts +2 -11
- package/dist/extensions/pi-subagents/src/runs/background/control-channel.ts +260 -13
- package/dist/extensions/pi-subagents/src/runs/background/fleet-view.ts +32 -6
- package/dist/extensions/pi-subagents/src/runs/background/notify.ts +171 -90
- package/dist/extensions/pi-subagents/src/runs/background/process-terminal.ts +280 -0
- package/dist/extensions/pi-subagents/src/runs/background/result-watcher.ts +149 -88
- package/dist/extensions/pi-subagents/src/runs/background/run-id-resolver.ts +14 -2
- package/dist/extensions/pi-subagents/src/runs/background/run-status.ts +33 -17
- package/dist/extensions/pi-subagents/src/runs/background/scheduled-runs.ts +9 -1
- package/dist/extensions/pi-subagents/src/runs/background/stale-run-reconciler.ts +38 -10
- package/dist/extensions/pi-subagents/src/runs/background/steering.ts +237 -0
- package/dist/extensions/pi-subagents/src/runs/background/subagent-runner.ts +1297 -307
- package/dist/extensions/pi-subagents/src/runs/background/subagent-wait.ts +610 -0
- package/dist/extensions/pi-subagents/src/runs/background/top-level-async.ts +2 -1
- package/dist/extensions/pi-subagents/src/runs/background/wait-config.ts +36 -0
- package/dist/extensions/pi-subagents/src/runs/background/wait-tool.ts +26 -0
- package/dist/extensions/pi-subagents/src/runs/foreground/async-steering-action.ts +230 -0
- package/dist/extensions/pi-subagents/src/runs/foreground/chain-clarify.ts +22 -6
- package/dist/extensions/pi-subagents/src/runs/foreground/chain-execution.ts +228 -140
- package/dist/extensions/pi-subagents/src/runs/foreground/execution.ts +452 -138
- package/dist/extensions/pi-subagents/src/runs/foreground/foreground-control.ts +90 -0
- package/dist/extensions/pi-subagents/src/runs/foreground/subagent-executor.ts +1001 -416
- package/dist/extensions/pi-subagents/src/runs/shared/acceptance.ts +443 -132
- package/dist/extensions/pi-subagents/src/runs/shared/agent-contract.ts +38 -0
- package/dist/extensions/pi-subagents/src/runs/shared/capability-ceiling.ts +178 -0
- package/dist/extensions/pi-subagents/src/runs/shared/child-protocol.ts +121 -0
- package/dist/extensions/pi-subagents/src/runs/shared/completion-guard.ts +41 -93
- package/dist/extensions/pi-subagents/src/runs/shared/context-mode.ts +44 -0
- package/dist/extensions/pi-subagents/src/runs/shared/dynamic-fanout.ts +11 -9
- package/dist/extensions/pi-subagents/src/runs/shared/long-running-guard.ts +4 -0
- package/dist/extensions/pi-subagents/src/runs/shared/mcp-direct-tool-allowlist.ts +12 -6
- package/dist/extensions/pi-subagents/src/runs/shared/model-fallback.ts +36 -0
- package/dist/extensions/pi-subagents/src/runs/shared/nested-events.ts +44 -7
- package/dist/extensions/pi-subagents/src/runs/shared/nested-render.ts +4 -1
- package/dist/extensions/pi-subagents/src/runs/shared/parallel-handoff.ts +154 -0
- package/dist/extensions/pi-subagents/src/runs/shared/parallel-utils.ts +18 -0
- package/dist/extensions/pi-subagents/src/runs/shared/pi-args.ts +174 -54
- package/dist/extensions/pi-subagents/src/runs/shared/pi-spawn.ts +38 -31
- package/dist/extensions/pi-subagents/src/runs/shared/run-history.ts +90 -5
- package/dist/extensions/pi-subagents/src/runs/shared/session-lease.ts +299 -0
- package/dist/extensions/pi-subagents/src/runs/shared/single-output.ts +61 -6
- package/dist/extensions/pi-subagents/src/runs/shared/spawn-budget.ts +128 -0
- package/dist/extensions/pi-subagents/src/runs/shared/structured-output.ts +112 -7
- package/dist/extensions/pi-subagents/src/runs/shared/subagent-control.ts +14 -6
- package/dist/extensions/pi-subagents/src/runs/shared/subagent-prompt-runtime.ts +149 -36
- package/dist/extensions/pi-subagents/src/runs/shared/task-intent.ts +181 -0
- package/dist/extensions/pi-subagents/src/runs/shared/tool-availability.ts +83 -0
- package/dist/extensions/pi-subagents/src/runs/shared/tool-budget.ts +11 -5
- package/dist/extensions/pi-subagents/src/runs/shared/turn-budget.ts +50 -4
- package/dist/extensions/pi-subagents/src/runs/shared/worktree.ts +63 -14
- package/dist/extensions/pi-subagents/src/shared/accessible-dir.ts +25 -0
- package/dist/extensions/pi-subagents/src/shared/artifacts.ts +37 -7
- package/dist/extensions/pi-subagents/src/shared/atomic-json.ts +18 -43
- package/dist/extensions/pi-subagents/src/shared/child-transcript.ts +52 -0
- package/dist/extensions/pi-subagents/src/shared/env.ts +16 -0
- package/dist/extensions/pi-subagents/src/shared/file-system-retry.ts +47 -0
- package/dist/extensions/pi-subagents/src/shared/fork-context.ts +28 -3
- package/dist/extensions/pi-subagents/src/shared/launch-contract.ts +123 -0
- package/dist/extensions/pi-subagents/src/shared/model-info.ts +8 -5
- package/dist/extensions/pi-subagents/src/shared/settings.ts +9 -1
- package/dist/extensions/pi-subagents/src/shared/status-format.ts +7 -1
- package/dist/extensions/pi-subagents/src/shared/types.ts +522 -51
- package/dist/extensions/pi-subagents/src/shared/utils.ts +59 -53
- package/dist/extensions/pi-subagents/src/slash/delegation-adapters.ts +604 -0
- package/dist/extensions/pi-subagents/src/slash/delegation-json.ts +108 -0
- package/dist/extensions/pi-subagents/src/slash/delegation-request.ts +249 -0
- package/dist/extensions/pi-subagents/src/slash/prompt-template-bridge.ts +353 -345
- package/dist/extensions/pi-subagents/src/slash/prompt-workflows.ts +2 -2
- package/dist/extensions/pi-subagents/src/slash/selector.ts +147 -0
- package/dist/extensions/pi-subagents/src/slash/slash-commands.ts +265 -23
- package/dist/extensions/pi-subagents/src/slash/slash-live-state.ts +2 -2
- package/dist/extensions/pi-subagents/src/slash/subagents-admin.ts +428 -0
- package/dist/extensions/pi-subagents/src/tui/fleet-status.ts +362 -0
- package/dist/extensions/pi-subagents/src/tui/fleet-transcript.ts +472 -0
- package/dist/extensions/pi-subagents/src/tui/fleet.ts +664 -0
- package/dist/extensions/pi-subagents/src/tui/render.ts +115 -31
- package/dist/extensions/pi-subagents/src/watchdog/change-signature.ts +220 -0
- package/dist/extensions/pi-subagents/src/watchdog/child-status.ts +205 -0
- package/dist/extensions/pi-subagents/src/watchdog/emission-guard.ts +123 -0
- package/dist/extensions/pi-subagents/src/watchdog/lsp-diagnostics.ts +532 -0
- package/dist/extensions/pi-subagents/src/watchdog/model-selection.ts +167 -0
- package/dist/extensions/pi-subagents/src/watchdog/register-child.ts +117 -0
- package/dist/extensions/pi-subagents/src/watchdog/register-main.ts +433 -0
- package/dist/extensions/pi-subagents/src/watchdog/render.ts +54 -0
- package/dist/extensions/pi-subagents/src/watchdog/review.ts +298 -0
- package/dist/extensions/pi-subagents/src/watchdog/runtime.ts +714 -0
- package/dist/extensions/pi-subagents/src/watchdog/settings.ts +528 -0
- package/dist/extensions/pi-subagents/src/watchdog/tool-actions.ts +155 -0
- package/dist/extensions/pi-subagents/src/watchdog/turn-delta.ts +161 -0
- package/dist/extensions/pi-subagents/src/watchdog/types.ts +188 -0
- package/dist/extensions/pi-subagents/src/watchdog/warning-format.ts +73 -0
- package/dist/extensions/pi-subagents/test/e2e/real-session-subagent.test.ts +130 -2
- package/dist/extensions/pi-subagents/test/integration/acceptance-file-report.test.ts +439 -0
- package/dist/extensions/pi-subagents/test/integration/async-execution.test.ts +1632 -61
- package/dist/extensions/pi-subagents/test/integration/async-job-tracker.test.ts +54 -1
- package/dist/extensions/pi-subagents/test/integration/async-status.test.ts +112 -0
- package/dist/extensions/pi-subagents/test/integration/chain-clarify.test.ts +98 -1
- package/dist/extensions/pi-subagents/test/integration/chain-execution.test.ts +179 -9
- package/dist/extensions/pi-subagents/test/integration/detect-error.test.ts +16 -9
- package/dist/extensions/pi-subagents/test/integration/error-handling.test.ts +6 -5
- package/dist/extensions/pi-subagents/test/integration/fork-context-execution.test.ts +589 -9
- package/dist/extensions/pi-subagents/test/integration/intercom-result-delivery.test.ts +528 -21
- package/dist/extensions/pi-subagents/test/integration/parallel-execution.test.ts +227 -3
- package/dist/extensions/pi-subagents/test/integration/render-fork-badge.test.ts +235 -7
- package/dist/extensions/pi-subagents/test/integration/render-widget.test.ts +27 -0
- package/dist/extensions/pi-subagents/test/integration/result-watcher.test.ts +172 -2
- package/dist/extensions/pi-subagents/test/integration/single-execution.test.ts +1502 -18
- package/dist/extensions/pi-subagents/test/integration/slash-commands.test.ts +993 -4
- package/dist/extensions/pi-subagents/test/integration/slash-live-state.test.ts +27 -0
- package/dist/extensions/pi-subagents/test/integration/top-level-async.test.ts +7 -1
- package/dist/extensions/pi-subagents/test/support/helpers.ts +32 -0
- package/dist/extensions/pi-subagents/test/support/mock-pi-script.mjs +59 -2
- package/dist/extensions/pi-subagents/test/support/mock-pi.ts +32 -6
- package/dist/extensions/pi-subagents/test/support/real-session-child-cli.mjs +25 -24
- package/dist/extensions/pi-subagents/test/support/real-session-runner.ts +59 -35
- package/dist/extensions/pi-subagents/test/support/session-lease-child.mjs +42 -0
- package/dist/extensions/pi-subagents/test/unit/acceptance.test.ts +703 -69
- package/dist/extensions/pi-subagents/test/unit/accessible-dir.test.ts +82 -0
- package/dist/extensions/pi-subagents/test/unit/agent-disabled.test.ts +15 -15
- package/dist/extensions/pi-subagents/test/unit/agent-eject-disable.test.ts +66 -66
- package/dist/extensions/pi-subagents/test/unit/agent-frontmatter.test.ts +478 -19
- package/dist/extensions/pi-subagents/test/unit/agent-management.test.ts +228 -7
- package/dist/extensions/pi-subagents/test/unit/agent-memory.test.ts +1 -1
- package/dist/extensions/pi-subagents/test/unit/agent-overrides.test.ts +198 -78
- package/dist/extensions/pi-subagents/test/unit/async-execution.test.ts +15 -1
- package/dist/extensions/pi-subagents/test/unit/async-interrupt-action.test.ts +102 -7
- package/dist/extensions/pi-subagents/test/unit/async-resume.test.ts +439 -6
- package/dist/extensions/pi-subagents/test/unit/atomic-json.test.ts +41 -1
- package/dist/extensions/pi-subagents/test/unit/auto-drain.test.ts +79 -0
- package/dist/extensions/pi-subagents/test/unit/background-work.test.ts +285 -0
- package/dist/extensions/pi-subagents/test/unit/capability-ceiling-pi-args.test.ts +84 -0
- package/dist/extensions/pi-subagents/test/unit/capability-ceiling.test.ts +68 -0
- package/dist/extensions/pi-subagents/test/unit/chain-validation.test.ts +326 -0
- package/dist/extensions/pi-subagents/test/unit/child-protocol.test.ts +82 -0
- package/dist/extensions/pi-subagents/test/unit/child-transcript.test.ts +46 -4
- package/dist/extensions/pi-subagents/test/unit/completion-batcher.test.ts +3 -1
- package/dist/extensions/pi-subagents/test/unit/completion-dedupe.test.ts +9 -17
- package/dist/extensions/pi-subagents/test/unit/completion-guard.test.ts +175 -3
- package/dist/extensions/pi-subagents/test/unit/config-dir-runtime.test.ts +10 -5
- package/dist/extensions/pi-subagents/test/unit/control-channel.test.ts +126 -6
- package/dist/extensions/pi-subagents/test/unit/default-extensions.test.ts +219 -0
- package/dist/extensions/pi-subagents/test/unit/delegation-api.test.ts +913 -0
- package/dist/extensions/pi-subagents/test/unit/doctor.test.ts +13 -2
- package/dist/extensions/pi-subagents/test/unit/dynamic-fanout.test.ts +3 -3
- package/dist/extensions/pi-subagents/test/unit/fleet-status.test.ts +351 -0
- package/dist/extensions/pi-subagents/test/unit/fleet-transcript.test.ts +280 -0
- package/dist/extensions/pi-subagents/test/unit/fleet.test.ts +575 -0
- package/dist/extensions/pi-subagents/test/unit/foreground-control.test.ts +65 -0
- package/dist/extensions/pi-subagents/test/unit/fork-context.test.ts +94 -1
- package/dist/extensions/pi-subagents/test/unit/get-final-output.test.ts +23 -0
- package/dist/extensions/pi-subagents/test/unit/host-peer-runtime-imports.test.ts +157 -0
- package/dist/extensions/pi-subagents/test/unit/index-child-registration.test.ts +367 -5
- package/dist/extensions/pi-subagents/test/unit/intercom-bridge.test.ts +11 -0
- package/dist/extensions/pi-subagents/test/unit/model-fallback.test.ts +36 -0
- package/dist/extensions/pi-subagents/test/unit/model-info.test.ts +25 -3
- package/dist/extensions/pi-subagents/test/unit/model-scope.test.ts +1 -1
- package/dist/extensions/pi-subagents/test/unit/native-supervisor-channel.test.ts +341 -10
- package/dist/extensions/pi-subagents/test/unit/nested-control.test.ts +16 -0
- package/dist/extensions/pi-subagents/test/unit/nested-events.test.ts +52 -0
- package/dist/extensions/pi-subagents/test/unit/notify.test.ts +168 -7
- package/dist/extensions/pi-subagents/test/unit/package-manifest.test.ts +85 -7
- package/dist/extensions/pi-subagents/test/unit/parallel-handoff.test.ts +175 -0
- package/dist/extensions/pi-subagents/test/unit/path-resolution.test.ts +1 -1
- package/dist/extensions/pi-subagents/test/unit/pi-args.test.ts +243 -16
- package/dist/extensions/pi-subagents/test/unit/pi-coding-agent-dir.test.ts +79 -36
- package/dist/extensions/pi-subagents/test/unit/pi-spawn.test.ts +174 -56
- package/dist/extensions/pi-subagents/test/unit/preflight.test.ts +322 -0
- package/dist/extensions/pi-subagents/test/unit/process-terminal.test.ts +204 -0
- package/dist/extensions/pi-subagents/test/unit/recursion-guard.test.ts +20 -12
- package/dist/extensions/pi-subagents/test/unit/rpc.test.ts +117 -4
- package/dist/extensions/pi-subagents/test/unit/run-status.test.ts +40 -7
- package/dist/extensions/pi-subagents/test/unit/scheduled-runs.test.ts +48 -1
- package/dist/extensions/pi-subagents/test/unit/schemas.test.ts +21 -3
- package/dist/extensions/pi-subagents/test/unit/selector.test.ts +57 -0
- package/dist/extensions/pi-subagents/test/unit/session-lease.test.ts +326 -0
- package/dist/extensions/pi-subagents/test/unit/single-output.test.ts +101 -2
- package/dist/extensions/pi-subagents/test/unit/skills-fallback.test.ts +111 -1
- package/dist/extensions/pi-subagents/test/unit/spawn-budget.test.ts +124 -0
- package/dist/extensions/pi-subagents/test/unit/stale-run-reconciler.test.ts +6 -4
- package/dist/extensions/pi-subagents/test/unit/status-format.test.ts +7 -0
- package/dist/extensions/pi-subagents/test/unit/steering-action.test.ts +397 -0
- package/dist/extensions/pi-subagents/test/unit/steering-notices.test.ts +58 -0
- package/dist/extensions/pi-subagents/test/unit/steering.test.ts +173 -0
- package/dist/extensions/pi-subagents/test/unit/subagent-control.test.ts +25 -4
- package/dist/extensions/pi-subagents/test/unit/subagent-prompt-runtime.test.ts +390 -25
- package/dist/extensions/pi-subagents/test/unit/subagent-wait.test.ts +837 -0
- package/dist/extensions/pi-subagents/test/unit/task-intent.test.ts +86 -0
- package/dist/extensions/pi-subagents/test/unit/tool-budget.test.ts +15 -0
- package/dist/extensions/pi-subagents/test/unit/tool-description.test.ts +47 -1
- package/dist/extensions/pi-subagents/test/unit/turn-budget.test.ts +56 -10
- package/dist/extensions/pi-subagents/test/unit/watchdog-change-signature.test.ts +387 -0
- package/dist/extensions/pi-subagents/test/unit/watchdog-child-status.test.ts +110 -0
- package/dist/extensions/pi-subagents/test/unit/watchdog-emission-guard.test.ts +62 -0
- package/dist/extensions/pi-subagents/test/unit/watchdog-lsp-diagnostics.test.ts +144 -0
- package/dist/extensions/pi-subagents/test/unit/watchdog-model-selection.test.ts +121 -0
- package/dist/extensions/pi-subagents/test/unit/watchdog-render.test.ts +76 -0
- package/dist/extensions/pi-subagents/test/unit/watchdog-review.test.ts +327 -0
- package/dist/extensions/pi-subagents/test/unit/watchdog-runtime.test.ts +863 -0
- package/dist/extensions/pi-subagents/test/unit/watchdog-settings.test.ts +290 -0
- package/dist/extensions/pi-subagents/test/unit/watchdog-tool-actions.test.ts +91 -0
- package/dist/extensions/pi-subagents/test/unit/watchdog-turn-delta.test.ts +130 -0
- package/dist/extensions/pi-subagents/test/unit/widget-nested-render.test.ts +32 -4
- package/dist/extensions/pi-subagents/test/unit/worktree.test.ts +5 -1
- package/dist/extensions/pi-subagents/test/unit/writer-budget-guidance.test.ts +30 -0
- package/dist/extensions/question/batch.ts +39 -0
- package/dist/extensions/question/dialog-adapter.ts +23 -1
- package/dist/extensions/question/index.ts +237 -7
- package/dist/extensions/question/schemas.ts +28 -15
- package/dist/extensions/question/tests/batch.test.ts +26 -0
- package/dist/extensions/question/tests/ui-protocol.test.ts +23 -3
- package/dist/extensions/question/tui-adapter.ts +2 -3
- package/dist/extensions/question/types.ts +37 -0
- package/dist/extensions/question/ui-protocol.ts +3 -3
- package/dist/skills/batch-grill-me/SKILL.md +3 -1
- package/package.json +2 -1
|
@@ -0,0 +1,664 @@
|
|
|
1
|
+
import * as fs from "node:fs";
|
|
2
|
+
import * as path from "node:path";
|
|
3
|
+
import { getMarkdownTheme, type ExtensionContext } from "@selesai/code";
|
|
4
|
+
import { Key, matchesKey, truncateToWidth, visibleWidth, wrapTextWithAnsi, type Component, type MarkdownTheme } from "@earendil-works/pi-tui";
|
|
5
|
+
import { getArtifactPaths, getArtifactsDir } from "../shared/artifacts.ts";
|
|
6
|
+
import { formatDuration, formatTokens, shortenPath } from "../shared/formatters.ts";
|
|
7
|
+
import { RESULTS_DIR, type AsyncJobState, type ForegroundChildControl, type ForegroundResumeChild, type ForegroundResumeRun, type ForegroundRunControl, type SubagentState } from "../shared/types.ts";
|
|
8
|
+
import { readStatus } from "../shared/utils.ts";
|
|
9
|
+
import { formatAsyncRunTranscript } from "../runs/background/fleet-view.ts";
|
|
10
|
+
import { listAsyncRuns, type AsyncRunSummary } from "../runs/background/async-status.ts";
|
|
11
|
+
import { contextModeBadge, contextModeLabel } from "../runs/shared/context-mode.ts";
|
|
12
|
+
import { FLEET_STATUS_WIDGET_KEY } from "./fleet-status.ts";
|
|
13
|
+
import { readFleetTranscript, renderFleetTranscript, type FleetTranscript } from "./fleet-transcript.ts";
|
|
14
|
+
|
|
15
|
+
const REFRESH_MS = 750;
|
|
16
|
+
const MAX_RECENT_ASYNC_RUNS = 20;
|
|
17
|
+
const TRANSCRIPT_LINES = 200;
|
|
18
|
+
|
|
19
|
+
type Theme = ExtensionContext["ui"]["theme"];
|
|
20
|
+
type FleetTui = {
|
|
21
|
+
terminal?: { rows: number };
|
|
22
|
+
requestRender(): void;
|
|
23
|
+
};
|
|
24
|
+
type AsyncStep = AsyncRunSummary["steps"][number];
|
|
25
|
+
|
|
26
|
+
export type FleetItem = (
|
|
27
|
+
| { key: string; kind: "foreground-active"; runId: string; index?: number; agent: string; state: "running"; updatedAt: number; control: ForegroundRunControl; activeChild?: ForegroundChildControl }
|
|
28
|
+
| { key: string; kind: "foreground-recent"; runId: string; index: number; agent: string; state: ForegroundResumeChild["status"]; updatedAt: number; run: ForegroundResumeRun; child: ForegroundResumeChild }
|
|
29
|
+
| { key: string; kind: "async"; runId: string; index?: number; agent: string; state: string; updatedAt: number; run: AsyncRunSummary; step?: AsyncStep }
|
|
30
|
+
) & { description?: string };
|
|
31
|
+
|
|
32
|
+
export interface FleetSnapshot {
|
|
33
|
+
items: FleetItem[];
|
|
34
|
+
error?: string;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
export interface FleetViewOptions {
|
|
38
|
+
asyncDirRoot?: string;
|
|
39
|
+
resultsDir?: string;
|
|
40
|
+
refreshMs?: number;
|
|
41
|
+
initialKey?: string;
|
|
42
|
+
markdownTheme?: MarkdownTheme;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
function belongsToCurrentSession(sessionId: string | undefined, currentSessionId: string | null): boolean {
|
|
46
|
+
return !currentSessionId || sessionId === currentSessionId;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
function trackedJobSummary(job: AsyncJobState): AsyncRunSummary {
|
|
50
|
+
const startedAt = job.startedAt ?? job.updatedAt ?? Date.now();
|
|
51
|
+
return {
|
|
52
|
+
id: job.asyncId,
|
|
53
|
+
asyncDir: job.asyncDir,
|
|
54
|
+
...(job.sessionId ? { sessionId: job.sessionId } : {}),
|
|
55
|
+
state: job.status,
|
|
56
|
+
activityState: job.activityState,
|
|
57
|
+
lastActivityAt: job.lastActivityAt,
|
|
58
|
+
currentTool: job.currentTool,
|
|
59
|
+
currentToolStartedAt: job.currentToolStartedAt,
|
|
60
|
+
currentPath: job.currentPath,
|
|
61
|
+
turnCount: job.turnCount,
|
|
62
|
+
toolCount: job.toolCount,
|
|
63
|
+
steering: job.steering,
|
|
64
|
+
mode: job.mode ?? "single",
|
|
65
|
+
...(job.context ? { context: job.context } : {}),
|
|
66
|
+
...(job.cwd ? { cwd: job.cwd } : {}),
|
|
67
|
+
startedAt,
|
|
68
|
+
...(job.updatedAt !== undefined ? { lastUpdate: job.updatedAt } : {}),
|
|
69
|
+
...(job.timeoutMs !== undefined ? { timeoutMs: job.timeoutMs } : {}),
|
|
70
|
+
...(job.deadlineAt !== undefined ? { deadlineAt: job.deadlineAt } : {}),
|
|
71
|
+
...(job.timedOut !== undefined ? { timedOut: job.timedOut } : {}),
|
|
72
|
+
...(job.stopped !== undefined ? { stopped: job.stopped } : {}),
|
|
73
|
+
...(job.turnBudget ? { turnBudget: job.turnBudget } : {}),
|
|
74
|
+
...(job.turnBudgetExceeded !== undefined ? { turnBudgetExceeded: job.turnBudgetExceeded } : {}),
|
|
75
|
+
...(job.wrapUpRequested !== undefined ? { wrapUpRequested: job.wrapUpRequested } : {}),
|
|
76
|
+
...(job.currentStep !== undefined ? { currentStep: job.currentStep } : {}),
|
|
77
|
+
...(job.chainStepCount !== undefined ? { chainStepCount: job.chainStepCount } : {}),
|
|
78
|
+
...(job.parallelGroups?.length ? { parallelGroups: job.parallelGroups } : {}),
|
|
79
|
+
steps: (job.steps ?? job.agents?.map((agent, index) => ({ agent, index, status: job.status === "queued" ? "pending" as const : job.status })) ?? []).map((step, index) => ({
|
|
80
|
+
...step,
|
|
81
|
+
index: step.index ?? index,
|
|
82
|
+
})),
|
|
83
|
+
...(job.sessionDir ? { sessionDir: job.sessionDir } : {}),
|
|
84
|
+
...(job.outputFile ? { outputFile: job.outputFile } : {}),
|
|
85
|
+
...(job.totalTokens ? { totalTokens: job.totalTokens } : {}),
|
|
86
|
+
...(job.sessionFile ? { sessionFile: job.sessionFile } : {}),
|
|
87
|
+
...(job.nestedChildren?.length ? { nestedChildren: job.nestedChildren } : {}),
|
|
88
|
+
};
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
function asyncItems(run: AsyncRunSummary, description?: string): FleetItem[] {
|
|
92
|
+
const updatedAt = run.lastUpdate ?? run.endedAt ?? run.startedAt;
|
|
93
|
+
if (run.steps.length === 0) {
|
|
94
|
+
return [{ key: `async:${run.id}`, kind: "async", runId: run.id, agent: run.mode, state: run.state, updatedAt, run, ...(description ? { description } : {}) }];
|
|
95
|
+
}
|
|
96
|
+
return run.steps.map((step) => ({
|
|
97
|
+
key: `async:${run.id}:${step.index}`,
|
|
98
|
+
kind: "async" as const,
|
|
99
|
+
runId: run.id,
|
|
100
|
+
index: step.index,
|
|
101
|
+
agent: step.label ? `${step.label} (${step.agent})` : step.agent,
|
|
102
|
+
state: step.status,
|
|
103
|
+
updatedAt: step.lastActivityAt ?? updatedAt,
|
|
104
|
+
run,
|
|
105
|
+
step,
|
|
106
|
+
...(description ? { description } : {}),
|
|
107
|
+
}));
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
export function collectFleetSnapshot(
|
|
111
|
+
state: SubagentState,
|
|
112
|
+
options: { asyncDirRoot?: string; resultsDir?: string; limit?: number } = {},
|
|
113
|
+
): FleetSnapshot {
|
|
114
|
+
const items: FleetItem[] = [];
|
|
115
|
+
const activeForegroundIds = new Set<string>();
|
|
116
|
+
for (const control of [...state.foregroundControls.values()].sort((left, right) => right.updatedAt - left.updatedAt)) {
|
|
117
|
+
activeForegroundIds.add(control.runId);
|
|
118
|
+
if (control.activeChildren) {
|
|
119
|
+
for (const child of [...control.activeChildren.values()].sort((left, right) => left.index - right.index)) {
|
|
120
|
+
items.push({
|
|
121
|
+
key: `foreground-active:${control.runId}:${child.index}`,
|
|
122
|
+
kind: "foreground-active",
|
|
123
|
+
runId: control.runId,
|
|
124
|
+
index: child.index,
|
|
125
|
+
agent: child.agent,
|
|
126
|
+
state: "running",
|
|
127
|
+
updatedAt: child.updatedAt,
|
|
128
|
+
control,
|
|
129
|
+
activeChild: child,
|
|
130
|
+
...(child.description ? { description: child.description } : {}),
|
|
131
|
+
});
|
|
132
|
+
}
|
|
133
|
+
continue;
|
|
134
|
+
}
|
|
135
|
+
items.push({
|
|
136
|
+
key: `foreground-active:${control.runId}:${control.currentIndex ?? 0}`,
|
|
137
|
+
kind: "foreground-active",
|
|
138
|
+
runId: control.runId,
|
|
139
|
+
...(control.currentIndex !== undefined ? { index: control.currentIndex } : {}),
|
|
140
|
+
agent: control.currentAgent ?? control.mode,
|
|
141
|
+
state: "running",
|
|
142
|
+
updatedAt: control.updatedAt,
|
|
143
|
+
control,
|
|
144
|
+
...(control.description ? { description: control.description } : {}),
|
|
145
|
+
});
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
let error: string | undefined;
|
|
149
|
+
try {
|
|
150
|
+
let runs: AsyncRunSummary[];
|
|
151
|
+
const descriptions = new Map<string, string>();
|
|
152
|
+
if (options.asyncDirRoot !== undefined) {
|
|
153
|
+
runs = listAsyncRuns(options.asyncDirRoot, {
|
|
154
|
+
...(state.currentSessionId ? { sessionId: state.currentSessionId } : {}),
|
|
155
|
+
limit: options.limit ?? MAX_RECENT_ASYNC_RUNS,
|
|
156
|
+
resultsDir: options.resultsDir ?? RESULTS_DIR,
|
|
157
|
+
reconcile: false,
|
|
158
|
+
});
|
|
159
|
+
} else {
|
|
160
|
+
const tracked = [...(state.fleetJobs ?? state.asyncJobs).values()]
|
|
161
|
+
.filter((job) => belongsToCurrentSession(job.sessionId, state.currentSessionId));
|
|
162
|
+
const byUpdate = (left: AsyncJobState, right: AsyncJobState) => (right.updatedAt ?? right.startedAt ?? 0) - (left.updatedAt ?? left.startedAt ?? 0);
|
|
163
|
+
const active = tracked.filter((job) => job.status === "queued" || job.status === "running").sort(byUpdate);
|
|
164
|
+
const recent = tracked.filter((job) => job.status !== "queued" && job.status !== "running").sort(byUpdate).slice(0, options.limit ?? MAX_RECENT_ASYNC_RUNS);
|
|
165
|
+
runs = [];
|
|
166
|
+
for (const job of [...active, ...recent]) {
|
|
167
|
+
try {
|
|
168
|
+
runs.push(trackedJobSummary(job));
|
|
169
|
+
if (job.description) descriptions.set(job.asyncId, job.description);
|
|
170
|
+
} catch (cause) {
|
|
171
|
+
error = `Failed to inspect async run '${job.asyncId}': ${cause instanceof Error ? cause.message : String(cause)}`;
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
for (const run of runs) items.push(...asyncItems(run, descriptions.get(run.id)));
|
|
176
|
+
} catch (cause) {
|
|
177
|
+
error = cause instanceof Error ? cause.message : String(cause);
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
const recentForeground = [...(state.foregroundRuns?.values() ?? [])]
|
|
181
|
+
.filter((run) => belongsToCurrentSession(run.sessionId, state.currentSessionId) && !activeForegroundIds.has(run.runId))
|
|
182
|
+
.sort((left, right) => right.updatedAt - left.updatedAt);
|
|
183
|
+
for (const run of recentForeground) {
|
|
184
|
+
for (const child of run.children) {
|
|
185
|
+
items.push({
|
|
186
|
+
key: `foreground-recent:${run.runId}:${child.index}`,
|
|
187
|
+
kind: "foreground-recent",
|
|
188
|
+
runId: run.runId,
|
|
189
|
+
index: child.index,
|
|
190
|
+
agent: child.agent,
|
|
191
|
+
state: child.status,
|
|
192
|
+
updatedAt: child.updatedAt ?? run.updatedAt,
|
|
193
|
+
run,
|
|
194
|
+
child,
|
|
195
|
+
});
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
return { items, ...(error ? { error } : {}) };
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
function statusGlyph(item: FleetItem, theme: Theme): string {
|
|
202
|
+
if (item.state === "running") return theme.fg("accent", "●");
|
|
203
|
+
if (item.state === "queued" || item.state === "pending") return theme.fg("muted", "◦");
|
|
204
|
+
if (item.state === "complete" || item.state === "completed") return theme.fg("success", "✓");
|
|
205
|
+
if (item.state === "paused" || item.state === "stopped" || item.state === "detached") return theme.fg("warning", "■");
|
|
206
|
+
return theme.fg("error", "✗");
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
function foregroundActiveDetail(item: Extract<FleetItem, { kind: "foreground-active" }>): string[] {
|
|
210
|
+
const { control } = item;
|
|
211
|
+
const live = item.activeChild ?? control;
|
|
212
|
+
const lines = [
|
|
213
|
+
`Run: ${item.runId}`,
|
|
214
|
+
"Source: foreground",
|
|
215
|
+
`State: running`,
|
|
216
|
+
`Mode: ${control.mode}`,
|
|
217
|
+
item.index !== undefined ? `Child: ${item.index} (${item.agent})` : `Agent: ${item.agent}`,
|
|
218
|
+
`Started: ${new Date(live.startedAt).toISOString()}`,
|
|
219
|
+
live.currentTool ? `Current tool: ${live.currentTool}${live.currentPath ? ` · ${shortenPath(live.currentPath)}` : ""}` : undefined,
|
|
220
|
+
live.turnCount !== undefined ? `Turns: ${live.turnCount}` : undefined,
|
|
221
|
+
live.toolCount !== undefined ? `Tools: ${live.toolCount}` : undefined,
|
|
222
|
+
live.tokens !== undefined ? `Tokens: ${formatTokens(live.tokens)}` : undefined,
|
|
223
|
+
"",
|
|
224
|
+
"Transcript",
|
|
225
|
+
"Live foreground output remains in the expanded subagent tool result. Persisted output and session paths appear here after the child settles.",
|
|
226
|
+
];
|
|
227
|
+
return lines.filter((line): line is string => line !== undefined);
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
function foregroundRecentDetail(item: Extract<FleetItem, { kind: "foreground-recent" }>): string[] {
|
|
231
|
+
const { child, run } = item;
|
|
232
|
+
const outputPath = child.artifactPaths?.outputPath ?? child.savedOutputPath;
|
|
233
|
+
const lines = [
|
|
234
|
+
`Run: ${item.runId}`,
|
|
235
|
+
"Source: foreground",
|
|
236
|
+
`State: ${child.status}`,
|
|
237
|
+
`Mode: ${run.mode}`,
|
|
238
|
+
`Child: ${child.index} (${child.agent})${contextModeLabel(child.context) ? ` ${contextModeLabel(child.context)}` : ""}`,
|
|
239
|
+
`Updated: ${new Date(child.updatedAt ?? run.updatedAt).toISOString()}`,
|
|
240
|
+
outputPath ? `Output: ${outputPath}` : undefined,
|
|
241
|
+
child.sessionFile ? `Session: ${child.sessionFile}` : undefined,
|
|
242
|
+
child.transcriptPath ? `Transcript file: ${child.transcriptPath}` : undefined,
|
|
243
|
+
child.error ? `Error: ${child.error}` : undefined,
|
|
244
|
+
child.outputSaveError ? `Output warning: ${child.outputSaveError}` : undefined,
|
|
245
|
+
child.transcriptError ? `Transcript warning: ${child.transcriptError}` : undefined,
|
|
246
|
+
"",
|
|
247
|
+
"Result transcript tail",
|
|
248
|
+
];
|
|
249
|
+
const outputLines = (child.finalOutput ?? "").split(/\r?\n/).filter((line) => line.trim()).slice(-TRANSCRIPT_LINES);
|
|
250
|
+
lines.push(...(outputLines.length ? outputLines : ["(no recovered output available)"]));
|
|
251
|
+
return lines.filter((line): line is string => line !== undefined);
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
function asyncDetail(item: Extract<FleetItem, { kind: "async" }>): string[] {
|
|
255
|
+
const status = readStatus(item.run.asyncDir);
|
|
256
|
+
if (status) {
|
|
257
|
+
return formatAsyncRunTranscript(status, item.run.asyncDir, { index: item.index, lines: TRANSCRIPT_LINES }).split("\n");
|
|
258
|
+
}
|
|
259
|
+
const outputPath = item.index !== undefined ? path.join(item.run.asyncDir, `output-${item.index}.log`) : undefined;
|
|
260
|
+
return [
|
|
261
|
+
`Run: ${item.runId}`,
|
|
262
|
+
"Source: async",
|
|
263
|
+
`State: ${item.state}`,
|
|
264
|
+
`Mode: ${item.run.mode}${contextModeLabel(item.run.context) ? ` ${contextModeLabel(item.run.context)}` : ""}`,
|
|
265
|
+
item.index !== undefined ? `Child: ${item.index} (${item.agent})${contextModeLabel(item.step?.context) ? ` ${contextModeLabel(item.step?.context)}` : ""}` : `Agent: ${item.agent}${contextModeLabel(item.run.context) ? ` ${contextModeLabel(item.run.context)}` : ""}`,
|
|
266
|
+
outputPath ? `Output: ${outputPath}` : undefined,
|
|
267
|
+
item.step?.sessionFile ? `Session: ${item.step.sessionFile}` : item.run.sessionFile ? `Session: ${item.run.sessionFile}` : undefined,
|
|
268
|
+
"",
|
|
269
|
+
"Transcript",
|
|
270
|
+
"(status is no longer available)",
|
|
271
|
+
].filter((line): line is string => line !== undefined);
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
function detailLines(item: FleetItem | undefined, error: string | undefined): string[] {
|
|
275
|
+
if (!item) return [error ? `Fleet scan failed: ${error}` : "No current-session foreground or recent async children.", "", "New runs appear here automatically while this inspector remains open."];
|
|
276
|
+
const lines = item.kind === "foreground-active"
|
|
277
|
+
? foregroundActiveDetail(item)
|
|
278
|
+
: item.kind === "foreground-recent"
|
|
279
|
+
? foregroundRecentDetail(item)
|
|
280
|
+
: asyncDetail(item);
|
|
281
|
+
if (error) lines.unshift(`Fleet scan warning: ${error}`, "");
|
|
282
|
+
return lines;
|
|
283
|
+
}
|
|
284
|
+
|
|
285
|
+
function uniquePaths(values: Array<string | undefined>): string[] {
|
|
286
|
+
return [...new Set(values.filter((value): value is string => Boolean(value)).map((value) => path.resolve(value)))];
|
|
287
|
+
}
|
|
288
|
+
|
|
289
|
+
function fleetArtifactsRoot(state: SubagentState, cwd: string): string {
|
|
290
|
+
return getArtifactsDir(
|
|
291
|
+
state.parentSessionFile ?? null,
|
|
292
|
+
cwd,
|
|
293
|
+
state.artifactDirPreference ?? "project",
|
|
294
|
+
);
|
|
295
|
+
}
|
|
296
|
+
|
|
297
|
+
function transcriptTarget(item: FleetItem, state: SubagentState): { path: string; trustedRoots: string[] } | undefined {
|
|
298
|
+
if (item.kind === "foreground-active") {
|
|
299
|
+
const artifactsRoot = fleetArtifactsRoot(state, item.control.cwd ?? state.baseCwd);
|
|
300
|
+
return {
|
|
301
|
+
path: getArtifactPaths(artifactsRoot, item.runId, item.agent, item.index ?? 0).transcriptPath,
|
|
302
|
+
trustedRoots: [artifactsRoot],
|
|
303
|
+
};
|
|
304
|
+
}
|
|
305
|
+
if (item.kind === "foreground-recent") {
|
|
306
|
+
if (!item.child.transcriptPath) return undefined;
|
|
307
|
+
const transcriptPath = path.isAbsolute(item.child.transcriptPath)
|
|
308
|
+
? item.child.transcriptPath
|
|
309
|
+
: path.resolve(item.run.cwd, item.child.transcriptPath);
|
|
310
|
+
return {
|
|
311
|
+
path: transcriptPath,
|
|
312
|
+
trustedRoots: uniquePaths([
|
|
313
|
+
fleetArtifactsRoot(state, item.run.cwd),
|
|
314
|
+
fleetArtifactsRoot(state, state.baseCwd),
|
|
315
|
+
]),
|
|
316
|
+
};
|
|
317
|
+
}
|
|
318
|
+
const step = item.step ?? (item.run.steps.length === 1 ? item.run.steps[0] : undefined);
|
|
319
|
+
if (!step?.transcriptPath) return undefined;
|
|
320
|
+
const transcriptPath = path.isAbsolute(step.transcriptPath)
|
|
321
|
+
? step.transcriptPath
|
|
322
|
+
: path.resolve(item.run.asyncDir, step.transcriptPath);
|
|
323
|
+
const trackedJob = state.fleetJobs?.get(item.runId) ?? state.asyncJobs.get(item.runId);
|
|
324
|
+
return {
|
|
325
|
+
path: transcriptPath,
|
|
326
|
+
trustedRoots: uniquePaths([
|
|
327
|
+
item.run.asyncDir,
|
|
328
|
+
fleetArtifactsRoot(state, state.baseCwd),
|
|
329
|
+
trackedJob?.cwd ? fleetArtifactsRoot(state, trackedJob.cwd) : undefined,
|
|
330
|
+
]),
|
|
331
|
+
};
|
|
332
|
+
}
|
|
333
|
+
|
|
334
|
+
function itemContext(item: FleetItem): string | undefined {
|
|
335
|
+
if (item.kind === "async") return contextModeLabel(item.step?.context ?? item.run.context);
|
|
336
|
+
if (item.kind === "foreground-recent") return contextModeLabel(item.child.context);
|
|
337
|
+
return undefined;
|
|
338
|
+
}
|
|
339
|
+
|
|
340
|
+
function itemMode(item: FleetItem): string {
|
|
341
|
+
return item.kind === "foreground-active" ? item.control.mode : item.run.mode;
|
|
342
|
+
}
|
|
343
|
+
|
|
344
|
+
function itemSource(item: FleetItem): string {
|
|
345
|
+
if (item.kind === "async") return "background";
|
|
346
|
+
return item.kind === "foreground-active" ? "foreground · live" : "foreground · recent";
|
|
347
|
+
}
|
|
348
|
+
|
|
349
|
+
function itemStats(item: FleetItem): string[] {
|
|
350
|
+
let model: string | undefined;
|
|
351
|
+
let tokens: number | undefined;
|
|
352
|
+
let tools: number | undefined;
|
|
353
|
+
let durationMs: number | undefined;
|
|
354
|
+
if (item.kind === "foreground-active") {
|
|
355
|
+
const live = item.activeChild ?? item.control;
|
|
356
|
+
tokens = live.tokens;
|
|
357
|
+
tools = live.toolCount;
|
|
358
|
+
durationMs = Math.max(0, Date.now() - live.startedAt);
|
|
359
|
+
} else if (item.kind === "foreground-recent") {
|
|
360
|
+
tokens = item.child.tokens;
|
|
361
|
+
tools = item.child.toolCount;
|
|
362
|
+
} else {
|
|
363
|
+
model = item.step?.model;
|
|
364
|
+
tokens = item.step?.tokens?.total ?? (item.index === undefined ? item.run.totalTokens?.total : undefined);
|
|
365
|
+
tools = item.step?.toolCount ?? (item.index === undefined ? item.run.toolCount : undefined);
|
|
366
|
+
const terminalRun = item.state !== "queued" && item.state !== "running" && item.state !== "pending";
|
|
367
|
+
const endTime = item.run.endedAt ?? (terminalRun ? item.run.lastUpdate : undefined) ?? Date.now();
|
|
368
|
+
durationMs = item.step?.durationMs ?? Math.max(0, endTime - item.run.startedAt);
|
|
369
|
+
}
|
|
370
|
+
return [
|
|
371
|
+
model,
|
|
372
|
+
tokens !== undefined ? `${formatTokens(tokens)} tok` : undefined,
|
|
373
|
+
tools !== undefined ? `${tools} tool${tools === 1 ? "" : "s"}` : undefined,
|
|
374
|
+
durationMs !== undefined ? formatDuration(durationMs) : undefined,
|
|
375
|
+
].filter((value): value is string => Boolean(value));
|
|
376
|
+
}
|
|
377
|
+
|
|
378
|
+
function structuredHeader(item: FleetItem, width: number, theme: Theme, conversationState: string): string[] {
|
|
379
|
+
const lines: string[] = [];
|
|
380
|
+
lines.push(rightAligned(` ${statusGlyph(item, theme)} ${theme.bold(item.agent)}`, theme.fg("dim", item.state), width));
|
|
381
|
+
const child = item.index !== undefined ? ` · child ${item.index + 1}` : "";
|
|
382
|
+
const context = itemContext(item);
|
|
383
|
+
const identity = `${itemSource(item)} · ${item.runId.slice(0, 8)}${child} · ${itemMode(item)}${context ? ` ${context}` : ""}`;
|
|
384
|
+
lines.push(` ${theme.fg("dim", identity)}`);
|
|
385
|
+
const stats = itemStats(item);
|
|
386
|
+
if (stats.length) lines.push(` ${theme.fg("muted", stats.join(" · "))}`);
|
|
387
|
+
if (item.description) {
|
|
388
|
+
const task = item.description.replace(/\s+/g, " ").trim();
|
|
389
|
+
lines.push(` ${theme.fg("dim", "Task")} ${task}`);
|
|
390
|
+
}
|
|
391
|
+
lines.push(`${theme.fg("accent", "Conversation")} ${theme.fg("dim", `· ${conversationState}`)}`);
|
|
392
|
+
return lines.map((line) => truncateToWidth(line, width));
|
|
393
|
+
}
|
|
394
|
+
|
|
395
|
+
function fit(text: string, width: number): string {
|
|
396
|
+
const clipped = truncateToWidth(text, Math.max(0, width));
|
|
397
|
+
return clipped + " ".repeat(Math.max(0, width - visibleWidth(clipped)));
|
|
398
|
+
}
|
|
399
|
+
|
|
400
|
+
function rightAligned(left: string, right: string, width: number): string {
|
|
401
|
+
const rightWidth = visibleWidth(right);
|
|
402
|
+
const leftWidth = Math.max(0, width - rightWidth - 1);
|
|
403
|
+
return fit(left, leftWidth) + " ".repeat(Math.max(1, width - leftWidth - rightWidth)) + fit(right, rightWidth);
|
|
404
|
+
}
|
|
405
|
+
|
|
406
|
+
interface FleetDetailSections {
|
|
407
|
+
header: string[];
|
|
408
|
+
body: string[];
|
|
409
|
+
}
|
|
410
|
+
|
|
411
|
+
interface FleetTranscriptCache {
|
|
412
|
+
path: string;
|
|
413
|
+
fingerprint: string;
|
|
414
|
+
width: number;
|
|
415
|
+
expandedTools: boolean;
|
|
416
|
+
transcript: FleetTranscript;
|
|
417
|
+
body: string[];
|
|
418
|
+
}
|
|
419
|
+
|
|
420
|
+
function transcriptFingerprint(filePath: string): string {
|
|
421
|
+
try {
|
|
422
|
+
const stat = fs.statSync(filePath);
|
|
423
|
+
return `${stat.size}:${stat.mtimeMs}`;
|
|
424
|
+
} catch {
|
|
425
|
+
return "missing";
|
|
426
|
+
}
|
|
427
|
+
}
|
|
428
|
+
|
|
429
|
+
export class SubagentFleetComponent implements Component {
|
|
430
|
+
private snapshot: FleetSnapshot = { items: [] };
|
|
431
|
+
private selected = 0;
|
|
432
|
+
private selectedKey: string | undefined;
|
|
433
|
+
private detailScroll = 0;
|
|
434
|
+
private detailAutoFollow = true;
|
|
435
|
+
private detailLineCount = 0;
|
|
436
|
+
private detailViewportHeight = 8;
|
|
437
|
+
private bodyHeight = 8;
|
|
438
|
+
private expandedTools = false;
|
|
439
|
+
private transcriptCache: FleetTranscriptCache | undefined;
|
|
440
|
+
private disposed = false;
|
|
441
|
+
private readonly timer: ReturnType<typeof setInterval>;
|
|
442
|
+
private readonly tui: FleetTui;
|
|
443
|
+
private readonly theme: Theme;
|
|
444
|
+
private readonly markdownTheme: MarkdownTheme;
|
|
445
|
+
private readonly state: SubagentState;
|
|
446
|
+
private readonly done: (result: undefined) => void;
|
|
447
|
+
private readonly options: FleetViewOptions;
|
|
448
|
+
|
|
449
|
+
constructor(
|
|
450
|
+
tui: FleetTui,
|
|
451
|
+
theme: Theme,
|
|
452
|
+
state: SubagentState,
|
|
453
|
+
done: (result: undefined) => void,
|
|
454
|
+
options: FleetViewOptions = {},
|
|
455
|
+
) {
|
|
456
|
+
this.tui = tui;
|
|
457
|
+
this.theme = theme;
|
|
458
|
+
this.markdownTheme = options.markdownTheme ?? getMarkdownTheme();
|
|
459
|
+
this.state = state;
|
|
460
|
+
this.done = done;
|
|
461
|
+
this.options = options;
|
|
462
|
+
this.selectedKey = options.initialKey;
|
|
463
|
+
this.refresh();
|
|
464
|
+
this.timer = setInterval(() => {
|
|
465
|
+
if (this.disposed) return;
|
|
466
|
+
this.refresh();
|
|
467
|
+
this.tui.requestRender();
|
|
468
|
+
}, options.refreshMs ?? REFRESH_MS);
|
|
469
|
+
this.timer.unref?.();
|
|
470
|
+
}
|
|
471
|
+
|
|
472
|
+
private refresh(): void {
|
|
473
|
+
const previousKey = this.snapshot.items[this.selected]?.key ?? this.selectedKey;
|
|
474
|
+
this.snapshot = collectFleetSnapshot(this.state, this.options);
|
|
475
|
+
const preserved = previousKey ? this.snapshot.items.findIndex((item) => item.key === previousKey) : -1;
|
|
476
|
+
this.selected = preserved >= 0 ? preserved : Math.min(this.selected, Math.max(0, this.snapshot.items.length - 1));
|
|
477
|
+
this.selectedKey = this.snapshot.items[this.selected]?.key;
|
|
478
|
+
}
|
|
479
|
+
|
|
480
|
+
private moveSelection(delta: number): void {
|
|
481
|
+
if (this.snapshot.items.length === 0) return;
|
|
482
|
+
this.selected = Math.max(0, Math.min(this.snapshot.items.length - 1, this.selected + delta));
|
|
483
|
+
this.selectedKey = this.snapshot.items[this.selected]?.key;
|
|
484
|
+
this.detailAutoFollow = true;
|
|
485
|
+
this.tui.requestRender();
|
|
486
|
+
}
|
|
487
|
+
|
|
488
|
+
private scrollDetail(delta: number): void {
|
|
489
|
+
const maxScroll = Math.max(0, this.detailLineCount - this.detailViewportHeight);
|
|
490
|
+
this.detailScroll = Math.max(0, Math.min(maxScroll, this.detailScroll + delta));
|
|
491
|
+
this.detailAutoFollow = this.detailScroll >= maxScroll;
|
|
492
|
+
this.tui.requestRender();
|
|
493
|
+
}
|
|
494
|
+
|
|
495
|
+
handleInput(data: string): void {
|
|
496
|
+
if (matchesKey(data, "escape") || matchesKey(data, "ctrl+c") || matchesKey(data, "q")) {
|
|
497
|
+
this.done(undefined);
|
|
498
|
+
return;
|
|
499
|
+
}
|
|
500
|
+
if (matchesKey(data, Key.shift("k"))) return this.scrollDetail(-1);
|
|
501
|
+
if (matchesKey(data, Key.shift("j"))) return this.scrollDetail(1);
|
|
502
|
+
if (matchesKey(data, "up") || matchesKey(data, "k")) return this.moveSelection(-1);
|
|
503
|
+
if (matchesKey(data, "down") || matchesKey(data, "j")) return this.moveSelection(1);
|
|
504
|
+
if (matchesKey(data, "home")) return this.moveSelection(-this.snapshot.items.length);
|
|
505
|
+
if (matchesKey(data, "end")) return this.moveSelection(this.snapshot.items.length);
|
|
506
|
+
if (matchesKey(data, "pageUp")) return this.scrollDetail(-this.detailViewportHeight);
|
|
507
|
+
if (matchesKey(data, "pageDown")) return this.scrollDetail(this.detailViewportHeight);
|
|
508
|
+
if (data.toLowerCase() === "r") {
|
|
509
|
+
this.transcriptCache = undefined;
|
|
510
|
+
this.refresh();
|
|
511
|
+
this.tui.requestRender();
|
|
512
|
+
return;
|
|
513
|
+
}
|
|
514
|
+
if (data.toLowerCase() === "x" || matchesKey(data, "ctrl+o")) {
|
|
515
|
+
this.expandedTools = !this.expandedTools;
|
|
516
|
+
this.transcriptCache = undefined;
|
|
517
|
+
this.tui.requestRender();
|
|
518
|
+
}
|
|
519
|
+
}
|
|
520
|
+
|
|
521
|
+
private rosterLines(width: number): string[] {
|
|
522
|
+
if (this.snapshot.items.length === 0) return [this.theme.fg("dim", "No tracked children")];
|
|
523
|
+
const start = Math.max(0, Math.min(this.selected - this.bodyHeight + 1, Math.max(0, this.snapshot.items.length - this.bodyHeight)));
|
|
524
|
+
return this.snapshot.items.slice(start, start + this.bodyHeight).map((item, offset) => {
|
|
525
|
+
const index = start + offset;
|
|
526
|
+
const marker = index === this.selected ? this.theme.fg("accent", "›") : " ";
|
|
527
|
+
const context = item.kind === "async" ? contextModeBadge(this.theme, item.step?.context ?? item.run.context) : item.kind === "foreground-recent" ? contextModeBadge(this.theme, item.child.context) : "";
|
|
528
|
+
const agent = index === this.selected ? this.theme.bold(item.agent) : item.agent;
|
|
529
|
+
const identity = item.description?.replace(/\s+/g, " ").trim() || item.runId.slice(0, 8);
|
|
530
|
+
const left = `${marker} ${statusGlyph(item, this.theme)} ${agent}${context} ${this.theme.fg("dim", `· ${identity}`)}`;
|
|
531
|
+
return rightAligned(left, this.theme.fg("dim", item.state), width);
|
|
532
|
+
});
|
|
533
|
+
}
|
|
534
|
+
|
|
535
|
+
private renderedTranscript(target: { path: string; trustedRoots: string[] }, width: number): { transcript: FleetTranscript; body: string[] } {
|
|
536
|
+
const fingerprint = `${target.trustedRoots.join("\0")}|${transcriptFingerprint(target.path)}`;
|
|
537
|
+
if (this.transcriptCache
|
|
538
|
+
&& this.transcriptCache.path === target.path
|
|
539
|
+
&& this.transcriptCache.fingerprint === fingerprint
|
|
540
|
+
&& this.transcriptCache.width === width
|
|
541
|
+
&& this.transcriptCache.expandedTools === this.expandedTools) {
|
|
542
|
+
return { transcript: this.transcriptCache.transcript, body: [...this.transcriptCache.body] };
|
|
543
|
+
}
|
|
544
|
+
const transcript = readFleetTranscript(target.path, { trustedRoots: target.trustedRoots });
|
|
545
|
+
const body = transcript.events.length > 0
|
|
546
|
+
? renderFleetTranscript(transcript, width, this.theme, this.markdownTheme, { expandedTools: this.expandedTools })
|
|
547
|
+
: [];
|
|
548
|
+
this.transcriptCache = { path: target.path, fingerprint, width, expandedTools: this.expandedTools, transcript, body };
|
|
549
|
+
return { transcript, body: [...body] };
|
|
550
|
+
}
|
|
551
|
+
|
|
552
|
+
private wrappedDetail(width: number): FleetDetailSections {
|
|
553
|
+
const selected = this.snapshot.items[this.selected];
|
|
554
|
+
let transcriptWarning: string | undefined;
|
|
555
|
+
if (selected) {
|
|
556
|
+
const target = transcriptTarget(selected, this.state);
|
|
557
|
+
if (target) {
|
|
558
|
+
const { transcript, body } = this.renderedTranscript(target, width);
|
|
559
|
+
transcriptWarning = transcript.warning;
|
|
560
|
+
if (transcript.events.length > 0) {
|
|
561
|
+
if (this.snapshot.error) body.unshift(this.theme.fg("warning", `Fleet scan warning: ${this.snapshot.error}`), "");
|
|
562
|
+
const latest = transcript.events.at(-1);
|
|
563
|
+
const conversationState = latest?.kind === "assistant"
|
|
564
|
+
? "assistant response"
|
|
565
|
+
: latest?.kind === "user"
|
|
566
|
+
? "supervisor message"
|
|
567
|
+
: latest?.kind === "tool"
|
|
568
|
+
? `${latest.name} · ${latest.status}`
|
|
569
|
+
: "activity";
|
|
570
|
+
return { header: structuredHeader(selected, width, this.theme, conversationState), body };
|
|
571
|
+
}
|
|
572
|
+
}
|
|
573
|
+
}
|
|
574
|
+
|
|
575
|
+
const raw = detailLines(selected, this.snapshot.error);
|
|
576
|
+
if (transcriptWarning) raw.unshift(`Transcript preview warning: ${transcriptWarning}`, "");
|
|
577
|
+
const lines: string[] = [];
|
|
578
|
+
for (const line of raw) {
|
|
579
|
+
const styled = /^(Run|State|Mode|Source|Child|Agent):/.test(line)
|
|
580
|
+
? this.theme.bold(line)
|
|
581
|
+
: /^(Transcript|Result transcript tail)/.test(line)
|
|
582
|
+
? this.theme.fg("accent", line)
|
|
583
|
+
: /^(Output|Session|Transcript file|Artifacts):/.test(line)
|
|
584
|
+
? this.theme.fg("muted", line)
|
|
585
|
+
: /^Transcript preview warning:/.test(line)
|
|
586
|
+
? this.theme.fg("warning", line)
|
|
587
|
+
: line;
|
|
588
|
+
const wrapped = wrapTextWithAnsi(styled, Math.max(1, width));
|
|
589
|
+
lines.push(...(wrapped.length ? wrapped : [""]));
|
|
590
|
+
}
|
|
591
|
+
return { header: [], body: lines };
|
|
592
|
+
}
|
|
593
|
+
|
|
594
|
+
render(width: number): string[] {
|
|
595
|
+
if (width < 36) return [truncateToWidth("Subagent fleet needs at least 36 columns. Esc closes.", width)];
|
|
596
|
+
const innerWidth = width - 2;
|
|
597
|
+
const rows = this.tui.terminal?.rows ?? 32;
|
|
598
|
+
this.bodyHeight = Math.max(2, Math.min(30, Math.floor(rows * 0.85) - 6));
|
|
599
|
+
const rosterWidth = Math.max(22, Math.min(46, Math.floor((innerWidth - 1) * 0.38)));
|
|
600
|
+
const detailWidth = Math.max(1, innerWidth - rosterWidth - 1);
|
|
601
|
+
const roster = this.rosterLines(rosterWidth);
|
|
602
|
+
const detail = this.wrappedDetail(detailWidth);
|
|
603
|
+
const detailHeader = detail.header.slice(0, Math.max(0, this.bodyHeight - 1));
|
|
604
|
+
this.detailViewportHeight = Math.max(1, this.bodyHeight - detailHeader.length);
|
|
605
|
+
this.detailLineCount = detail.body.length;
|
|
606
|
+
const maxDetailScroll = Math.max(0, detail.body.length - this.detailViewportHeight);
|
|
607
|
+
if (this.detailAutoFollow) this.detailScroll = maxDetailScroll;
|
|
608
|
+
else if (this.detailScroll > maxDetailScroll) this.detailScroll = maxDetailScroll;
|
|
609
|
+
const visibleDetails = [
|
|
610
|
+
...detailHeader,
|
|
611
|
+
...detail.body.slice(this.detailScroll, this.detailScroll + this.detailViewportHeight),
|
|
612
|
+
];
|
|
613
|
+
const lines = [this.theme.fg("border", `╭${"─".repeat(innerWidth)}╮`)];
|
|
614
|
+
const selected = this.snapshot.items[this.selected];
|
|
615
|
+
const title = ` ${this.theme.bold("Subagent fleet inspector")} ${this.theme.fg("dim", "· inspection only · live")}`;
|
|
616
|
+
const selectedStatus = selected
|
|
617
|
+
? `${statusGlyph(selected, this.theme)} ${selected.agent} · ${selected.state} `
|
|
618
|
+
: this.theme.fg("dim", "no children ");
|
|
619
|
+
lines.push(this.theme.fg("border", "│") + rightAligned(title, selectedStatus, innerWidth) + this.theme.fg("border", "│"));
|
|
620
|
+
lines.push(this.theme.fg("border", `├${"─".repeat(rosterWidth)}┬${"─".repeat(detailWidth)}┤`));
|
|
621
|
+
for (let index = 0; index < this.bodyHeight; index++) {
|
|
622
|
+
lines.push(
|
|
623
|
+
this.theme.fg("border", "│")
|
|
624
|
+
+ fit(roster[index] ?? "", rosterWidth)
|
|
625
|
+
+ this.theme.fg("border", "│")
|
|
626
|
+
+ fit(visibleDetails[index] ?? "", detailWidth)
|
|
627
|
+
+ this.theme.fg("border", "│"),
|
|
628
|
+
);
|
|
629
|
+
}
|
|
630
|
+
lines.push(this.theme.fg("border", `├${"─".repeat(rosterWidth)}┴${"─".repeat(detailWidth)}┤`));
|
|
631
|
+
const position = this.snapshot.items.length ? `${this.selected + 1}/${this.snapshot.items.length}` : "0/0";
|
|
632
|
+
const footer = ` ↑↓/jk agent · ⇧k/⇧j scroll · PgUp/PgDn page · x/Ctrl+O tools · r refresh · Esc close · ${position}`;
|
|
633
|
+
lines.push(this.theme.fg("border", "│") + fit(this.theme.fg("dim", footer), innerWidth) + this.theme.fg("border", "│"));
|
|
634
|
+
lines.push(this.theme.fg("border", `╰${"─".repeat(innerWidth)}╯`));
|
|
635
|
+
return lines.map((line) => truncateToWidth(line, width));
|
|
636
|
+
}
|
|
637
|
+
|
|
638
|
+
invalidate(): void {
|
|
639
|
+
this.transcriptCache = undefined;
|
|
640
|
+
this.refresh();
|
|
641
|
+
}
|
|
642
|
+
|
|
643
|
+
dispose(): void {
|
|
644
|
+
this.disposed = true;
|
|
645
|
+
clearInterval(this.timer);
|
|
646
|
+
}
|
|
647
|
+
}
|
|
648
|
+
|
|
649
|
+
export async function openSubagentFleet(ctx: ExtensionContext, state: SubagentState, options: FleetViewOptions = {}): Promise<void> {
|
|
650
|
+
const wasOpen = state.fleetInspectorOpen === true;
|
|
651
|
+
state.fleetInspectorOpen = true;
|
|
652
|
+
if (typeof ctx.ui.setWidget === "function") ctx.ui.setWidget(FLEET_STATUS_WIDGET_KEY, undefined);
|
|
653
|
+
try {
|
|
654
|
+
await ctx.ui.custom<undefined>(
|
|
655
|
+
(tui, theme, _keybindings, done) => new SubagentFleetComponent(tui, theme, state, done, options),
|
|
656
|
+
{
|
|
657
|
+
overlay: true,
|
|
658
|
+
overlayOptions: { anchor: "center", width: "95%", minWidth: 60, maxHeight: "85%", margin: 1 },
|
|
659
|
+
},
|
|
660
|
+
);
|
|
661
|
+
} finally {
|
|
662
|
+
state.fleetInspectorOpen = wasOpen;
|
|
663
|
+
}
|
|
664
|
+
}
|