@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,575 @@
|
|
|
1
|
+
import assert from "node:assert/strict";
|
|
2
|
+
import * as fs from "node:fs";
|
|
3
|
+
import * as os from "node:os";
|
|
4
|
+
import * as path from "node:path";
|
|
5
|
+
import { describe, it } from "node:test";
|
|
6
|
+
import { visibleWidth, type MarkdownTheme } from "@earendil-works/pi-tui";
|
|
7
|
+
import { collectFleetSnapshot, openSubagentFleet, SubagentFleetComponent } from "../../src/tui/fleet.ts";
|
|
8
|
+
import { FLEET_STATUS_WIDGET_KEY } from "../../src/tui/fleet-status.ts";
|
|
9
|
+
import { getArtifactPaths, getArtifactsDir, getProjectArtifactsDir } from "../../src/shared/artifacts.ts";
|
|
10
|
+
import type { SubagentState } from "../../src/shared/types.ts";
|
|
11
|
+
|
|
12
|
+
function stateForTest(): SubagentState {
|
|
13
|
+
return {
|
|
14
|
+
baseCwd: process.cwd(),
|
|
15
|
+
currentSessionId: "session-current",
|
|
16
|
+
asyncJobs: new Map(),
|
|
17
|
+
foregroundRuns: new Map(),
|
|
18
|
+
foregroundControls: new Map(),
|
|
19
|
+
lastForegroundControlId: null,
|
|
20
|
+
cleanupTimers: new Map(),
|
|
21
|
+
lastUiContext: null,
|
|
22
|
+
poller: null,
|
|
23
|
+
completionSeen: new Map(),
|
|
24
|
+
watcher: null,
|
|
25
|
+
watcherRestartTimer: null,
|
|
26
|
+
resultFileCoalescer: { schedule: () => false, clear: () => {} },
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
function writeAsyncRun(root: string, input: {
|
|
31
|
+
id: string;
|
|
32
|
+
sessionId?: string;
|
|
33
|
+
state?: "running" | "complete";
|
|
34
|
+
agents?: string[];
|
|
35
|
+
contexts?: Array<"fresh" | "fork">;
|
|
36
|
+
output?: string;
|
|
37
|
+
transcript?: Array<Record<string, unknown>>;
|
|
38
|
+
}): string {
|
|
39
|
+
const asyncDir = path.join(root, input.id);
|
|
40
|
+
fs.mkdirSync(asyncDir, { recursive: true });
|
|
41
|
+
const agents = input.agents ?? ["worker"];
|
|
42
|
+
if (input.output !== undefined) fs.writeFileSync(path.join(asyncDir, "output-0.log"), input.output, "utf-8");
|
|
43
|
+
const transcriptPath = input.transcript ? path.join(asyncDir, "transcript-0.jsonl") : undefined;
|
|
44
|
+
if (transcriptPath && input.transcript) fs.writeFileSync(transcriptPath, `${input.transcript.map((record) => JSON.stringify(record)).join("\n")}\n`, "utf-8");
|
|
45
|
+
fs.writeFileSync(path.join(asyncDir, "status.json"), JSON.stringify({
|
|
46
|
+
runId: input.id,
|
|
47
|
+
sessionId: input.sessionId ?? "session-current",
|
|
48
|
+
mode: agents.length > 1 ? "parallel" : "single",
|
|
49
|
+
state: input.state ?? "running",
|
|
50
|
+
startedAt: 100,
|
|
51
|
+
lastUpdate: 200,
|
|
52
|
+
currentStep: 0,
|
|
53
|
+
steps: agents.map((agent, index) => ({
|
|
54
|
+
agent,
|
|
55
|
+
...(input.contexts?.[index] ? { context: input.contexts[index] } : {}),
|
|
56
|
+
status: input.state === "complete" ? "complete" : index === 0 ? "running" : "pending",
|
|
57
|
+
startedAt: 100,
|
|
58
|
+
...(index === 0 ? { sessionFile: path.join(asyncDir, `${agent}.jsonl`), ...(transcriptPath ? { transcriptPath } : {}) } : {}),
|
|
59
|
+
})),
|
|
60
|
+
...(input.output !== undefined ? { outputFile: "output-0.log" } : {}),
|
|
61
|
+
}, null, 2));
|
|
62
|
+
return asyncDir;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
const theme = {
|
|
66
|
+
fg: (_name: string, text: string) => text,
|
|
67
|
+
bold: (text: string) => text,
|
|
68
|
+
};
|
|
69
|
+
|
|
70
|
+
const markdownTheme: MarkdownTheme = {
|
|
71
|
+
heading: (text) => text,
|
|
72
|
+
link: (text) => text,
|
|
73
|
+
linkUrl: (text) => text,
|
|
74
|
+
code: (text) => text,
|
|
75
|
+
codeBlock: (text) => text,
|
|
76
|
+
codeBlockBorder: (text) => text,
|
|
77
|
+
quote: (text) => text,
|
|
78
|
+
quoteBorder: (text) => text,
|
|
79
|
+
hr: (text) => text,
|
|
80
|
+
listBullet: (text) => text,
|
|
81
|
+
bold: (text) => text,
|
|
82
|
+
italic: (text) => text,
|
|
83
|
+
strikethrough: (text) => text,
|
|
84
|
+
underline: (text) => text,
|
|
85
|
+
};
|
|
86
|
+
|
|
87
|
+
describe("native subagent fleet", () => {
|
|
88
|
+
it("collects current-session foreground and flattened async children", () => {
|
|
89
|
+
const root = fs.mkdtempSync(path.join(os.tmpdir(), "pi-fleet-collect-"));
|
|
90
|
+
try {
|
|
91
|
+
writeAsyncRun(root, { id: "async-current", agents: ["worker", "reviewer"], output: "CURRENT OUTPUT" });
|
|
92
|
+
writeAsyncRun(root, { id: "async-other", sessionId: "session-other", output: "OTHER OUTPUT" });
|
|
93
|
+
const state = stateForTest();
|
|
94
|
+
state.foregroundControls.set("foreground-live", {
|
|
95
|
+
runId: "foreground-live",
|
|
96
|
+
mode: "chain",
|
|
97
|
+
startedAt: 10,
|
|
98
|
+
updatedAt: 30,
|
|
99
|
+
currentAgent: "scout",
|
|
100
|
+
currentIndex: 1,
|
|
101
|
+
});
|
|
102
|
+
state.foregroundRuns!.set("foreground-recent", {
|
|
103
|
+
runId: "foreground-recent",
|
|
104
|
+
mode: "single",
|
|
105
|
+
cwd: root,
|
|
106
|
+
sessionId: "session-current",
|
|
107
|
+
updatedAt: 20,
|
|
108
|
+
children: [{ agent: "planner", index: 0, status: "completed", finalOutput: "PLAN COMPLETE" }],
|
|
109
|
+
});
|
|
110
|
+
state.foregroundRuns!.set("foreground-other", {
|
|
111
|
+
runId: "foreground-other",
|
|
112
|
+
mode: "single",
|
|
113
|
+
cwd: root,
|
|
114
|
+
sessionId: "session-other",
|
|
115
|
+
updatedAt: 20,
|
|
116
|
+
children: [{ agent: "outsider", index: 0, status: "completed" }],
|
|
117
|
+
});
|
|
118
|
+
|
|
119
|
+
const snapshot = collectFleetSnapshot(state, { asyncDirRoot: root, resultsDir: path.join(root, "results") });
|
|
120
|
+
assert.deepEqual(snapshot.items.map((item) => item.key), [
|
|
121
|
+
"foreground-active:foreground-live:1",
|
|
122
|
+
"async:async-current:0",
|
|
123
|
+
"async:async-current:1",
|
|
124
|
+
"foreground-recent:foreground-recent:0",
|
|
125
|
+
]);
|
|
126
|
+
assert.equal(snapshot.error, undefined);
|
|
127
|
+
} finally {
|
|
128
|
+
fs.rmSync(root, { recursive: true, force: true });
|
|
129
|
+
}
|
|
130
|
+
});
|
|
131
|
+
|
|
132
|
+
it("keeps every active async run ahead of the bounded recent-completion window", () => {
|
|
133
|
+
const state = stateForTest();
|
|
134
|
+
for (let index = 0; index < 22; index++) {
|
|
135
|
+
state.fleetJobs ??= new Map();
|
|
136
|
+
state.fleetJobs.set(`terminal-${index}`, {
|
|
137
|
+
asyncId: `terminal-${index}`,
|
|
138
|
+
asyncDir: path.join(os.tmpdir(), `missing-terminal-${index}`),
|
|
139
|
+
sessionId: "session-current",
|
|
140
|
+
status: "complete",
|
|
141
|
+
mode: "single",
|
|
142
|
+
agents: ["worker"],
|
|
143
|
+
startedAt: index,
|
|
144
|
+
updatedAt: index,
|
|
145
|
+
});
|
|
146
|
+
}
|
|
147
|
+
state.fleetJobs!.set("active-old", {
|
|
148
|
+
asyncId: "active-old",
|
|
149
|
+
asyncDir: path.join(os.tmpdir(), "missing-active-old"),
|
|
150
|
+
sessionId: "session-current",
|
|
151
|
+
status: "running",
|
|
152
|
+
mode: "single",
|
|
153
|
+
agents: ["scout"],
|
|
154
|
+
startedAt: 0,
|
|
155
|
+
updatedAt: 0,
|
|
156
|
+
});
|
|
157
|
+
|
|
158
|
+
const snapshot = collectFleetSnapshot(state);
|
|
159
|
+
assert.equal(snapshot.items.length, 21);
|
|
160
|
+
assert.equal(snapshot.items[0]?.runId, "active-old");
|
|
161
|
+
assert.equal(snapshot.items.find((item) => item.runId === "terminal-21")?.state, "complete");
|
|
162
|
+
assert.ok(!snapshot.items.some((item) => item.runId === "terminal-0"));
|
|
163
|
+
});
|
|
164
|
+
|
|
165
|
+
it("renders selectable transcript detail and completed artifact paths within terminal width", () => {
|
|
166
|
+
const root = fs.mkdtempSync(path.join(os.tmpdir(), "pi-fleet-render-"));
|
|
167
|
+
try {
|
|
168
|
+
const asyncDir = writeAsyncRun(root, { id: "async-finished", state: "complete", contexts: ["fork"], output: "FINAL ASYNC OUTPUT" });
|
|
169
|
+
const state = stateForTest();
|
|
170
|
+
let closed = false;
|
|
171
|
+
let renderRequests = 0;
|
|
172
|
+
const tui = { terminal: { rows: 32, columns: 100 }, requestRender: () => { renderRequests++; } };
|
|
173
|
+
const component = new SubagentFleetComponent(
|
|
174
|
+
tui as never,
|
|
175
|
+
theme as never,
|
|
176
|
+
state,
|
|
177
|
+
() => { closed = true; },
|
|
178
|
+
{ asyncDirRoot: root, resultsDir: path.join(root, "results"), refreshMs: 60_000 },
|
|
179
|
+
);
|
|
180
|
+
try {
|
|
181
|
+
const lines = component.render(100);
|
|
182
|
+
assert.ok(lines.some((line) => line.includes("FINAL ASYNC OUTPUT")));
|
|
183
|
+
assert.ok(lines.some((line) => line.includes("output-0.log")));
|
|
184
|
+
assert.ok(lines.some((line) => line.includes("worker") && line.includes("[fork]")));
|
|
185
|
+
assert.ok(lines.some((line) => line.includes("worker.jsonl")));
|
|
186
|
+
for (const line of lines) assert.ok(visibleWidth(line) <= 100, `line exceeded width: ${line}`);
|
|
187
|
+
tui.terminal.rows = 10;
|
|
188
|
+
assert.ok(component.render(100).length <= 8, "short-terminal render should fit the overlay's 85% height cap");
|
|
189
|
+
component.handleInput("\x1b[6~");
|
|
190
|
+
component.handleInput("r");
|
|
191
|
+
assert.ok(renderRequests >= 2);
|
|
192
|
+
component.handleInput("\x1b");
|
|
193
|
+
assert.equal(closed, true);
|
|
194
|
+
} finally {
|
|
195
|
+
component.dispose();
|
|
196
|
+
}
|
|
197
|
+
} finally {
|
|
198
|
+
fs.rmSync(root, { recursive: true, force: true });
|
|
199
|
+
}
|
|
200
|
+
});
|
|
201
|
+
|
|
202
|
+
it("renders structured tool activity and assistant Markdown when a child transcript is available", () => {
|
|
203
|
+
const root = fs.mkdtempSync(path.join(os.tmpdir(), "pi-fleet-structured-"));
|
|
204
|
+
try {
|
|
205
|
+
const longResponse = `## Finding\n\n${Array.from({ length: 40 }, (_, index) => `detail ${index}`).join("\n")}\n\n\`\`\`ts\nconst fleet = true;\n\`\`\``;
|
|
206
|
+
writeAsyncRun(root, {
|
|
207
|
+
id: "async-structured",
|
|
208
|
+
state: "complete",
|
|
209
|
+
output: "RAW FALLBACK SHOULD NOT RENDER",
|
|
210
|
+
transcript: [
|
|
211
|
+
{ recordType: "message", sourceEventType: "initial_prompt", role: "user", text: "injected task" },
|
|
212
|
+
{ recordType: "tool_start", toolName: "read", argsPreview: "src/tui/fleet.ts" },
|
|
213
|
+
{ recordType: "tool_end", toolName: "read" },
|
|
214
|
+
{ recordType: "message", role: "toolResult", text: "very large tool payload", message: { toolName: "read", isError: false } },
|
|
215
|
+
{ recordType: "message", role: "assistant", model: "test-model", text: longResponse },
|
|
216
|
+
],
|
|
217
|
+
});
|
|
218
|
+
const state = stateForTest();
|
|
219
|
+
state.baseCwd = root;
|
|
220
|
+
const component = new SubagentFleetComponent(
|
|
221
|
+
{ terminal: { rows: 32, columns: 100 }, requestRender() {} } as never,
|
|
222
|
+
theme as never,
|
|
223
|
+
state,
|
|
224
|
+
() => {},
|
|
225
|
+
{ asyncDirRoot: root, resultsDir: path.join(root, "results"), refreshMs: 60_000, markdownTheme },
|
|
226
|
+
);
|
|
227
|
+
try {
|
|
228
|
+
let lines = component.render(100);
|
|
229
|
+
assert.ok(lines.some((line) => line.includes("Conversation") && line.includes("assistant response")));
|
|
230
|
+
assert.ok(lines.some((line) => line.includes("const fleet = true;")));
|
|
231
|
+
assert.ok(!lines.some((line) => line.includes("very large tool payload")));
|
|
232
|
+
assert.ok(!lines.some((line) => line.includes("RAW FALLBACK SHOULD NOT RENDER")));
|
|
233
|
+
const bottomLines = lines;
|
|
234
|
+
const realDateNow = Date.now;
|
|
235
|
+
const laterNow = realDateNow() + 2_000;
|
|
236
|
+
Date.now = () => laterNow;
|
|
237
|
+
try {
|
|
238
|
+
component.handleInput("K");
|
|
239
|
+
lines = component.render(100);
|
|
240
|
+
assert.notDeepEqual(lines, bottomLines, "Shift+K should scroll the conversation up by one line");
|
|
241
|
+
component.handleInput("J");
|
|
242
|
+
lines = component.render(100);
|
|
243
|
+
assert.deepEqual(lines, bottomLines, "Shift+J should scroll the conversation back down by one line");
|
|
244
|
+
} finally {
|
|
245
|
+
Date.now = realDateNow;
|
|
246
|
+
}
|
|
247
|
+
for (let page = 0; page < 4; page++) component.handleInput("\x1b[5~");
|
|
248
|
+
lines = component.render(100);
|
|
249
|
+
assert.ok(lines.some((line) => line.includes("Conversation") && line.includes("assistant response")), "the conversation header should remain pinned while scrolling");
|
|
250
|
+
assert.ok(lines.some((line) => line.includes("✓ read") && line.includes("src/tui/fleet.ts")), "page up should reveal compact tool activity");
|
|
251
|
+
assert.ok(lines.some((line) => line.includes("Assistant") && line.includes("test-model")), "page up should reveal the rendered assistant message header");
|
|
252
|
+
for (const renderWidth of [60, 80, 100]) {
|
|
253
|
+
for (const line of component.render(renderWidth)) {
|
|
254
|
+
assert.ok(visibleWidth(line) <= renderWidth, `line exceeded ${renderWidth} columns: ${line}`);
|
|
255
|
+
}
|
|
256
|
+
}
|
|
257
|
+
} finally {
|
|
258
|
+
component.dispose();
|
|
259
|
+
}
|
|
260
|
+
} finally {
|
|
261
|
+
fs.rmSync(root, { recursive: true, force: true });
|
|
262
|
+
}
|
|
263
|
+
});
|
|
264
|
+
|
|
265
|
+
it("uses parent-tracked async state and cwd without rescanning status", () => {
|
|
266
|
+
const root = fs.mkdtempSync(path.join(os.tmpdir(), "pi-fleet-async-cwd-"));
|
|
267
|
+
try {
|
|
268
|
+
const asyncDir = path.join(root, "async-custom-cwd");
|
|
269
|
+
const customCwd = path.join(root, "custom-cwd");
|
|
270
|
+
const artifactsRoot = getProjectArtifactsDir(customCwd);
|
|
271
|
+
fs.mkdirSync(asyncDir, { recursive: true });
|
|
272
|
+
fs.mkdirSync(artifactsRoot, { recursive: true });
|
|
273
|
+
const transcriptPath = path.join(artifactsRoot, "async-custom-cwd_worker_transcript.jsonl");
|
|
274
|
+
fs.writeFileSync(transcriptPath, `${JSON.stringify({ recordType: "message", role: "assistant", text: "Custom cwd async result" })}\n`, "utf-8");
|
|
275
|
+
fs.writeFileSync(path.join(asyncDir, "status.json"), "{in-flight status", "utf-8");
|
|
276
|
+
const state = stateForTest();
|
|
277
|
+
state.baseCwd = path.join(root, "parent-cwd");
|
|
278
|
+
state.asyncJobs.set("async-custom-cwd", {
|
|
279
|
+
asyncId: "async-custom-cwd",
|
|
280
|
+
asyncDir,
|
|
281
|
+
cwd: customCwd,
|
|
282
|
+
sessionId: "session-current",
|
|
283
|
+
status: "running",
|
|
284
|
+
mode: "single",
|
|
285
|
+
startedAt: 100,
|
|
286
|
+
updatedAt: 200,
|
|
287
|
+
steps: [{ agent: "worker", index: 0, status: "running", transcriptPath }],
|
|
288
|
+
});
|
|
289
|
+
const component = new SubagentFleetComponent(
|
|
290
|
+
{ terminal: { rows: 28, columns: 100 }, requestRender() {} } as never,
|
|
291
|
+
theme as never,
|
|
292
|
+
state,
|
|
293
|
+
() => {},
|
|
294
|
+
{ refreshMs: 60_000, markdownTheme },
|
|
295
|
+
);
|
|
296
|
+
try {
|
|
297
|
+
assert.ok(component.render(100).some((line) => line.includes("Custom cwd async result")));
|
|
298
|
+
} finally {
|
|
299
|
+
component.dispose();
|
|
300
|
+
}
|
|
301
|
+
} finally {
|
|
302
|
+
fs.rmSync(root, { recursive: true, force: true });
|
|
303
|
+
}
|
|
304
|
+
});
|
|
305
|
+
|
|
306
|
+
it("toggles bounded tool output expansion with x and Ctrl+O", () => {
|
|
307
|
+
const root = fs.mkdtempSync(path.join(os.tmpdir(), "pi-fleet-tool-toggle-"));
|
|
308
|
+
try {
|
|
309
|
+
writeAsyncRun(root, {
|
|
310
|
+
id: "async-tools",
|
|
311
|
+
state: "complete",
|
|
312
|
+
transcript: [
|
|
313
|
+
{ recordType: "tool_start", toolCallId: "read-1", toolName: "read", argsPreview: "src/a.ts", argsPayload: JSON.stringify({ path: "src/a.ts" }), ts: 1 },
|
|
314
|
+
{ recordType: "tool_end", toolCallId: "read-1", toolName: "read", ts: 2 },
|
|
315
|
+
{ recordType: "message", role: "toolResult", toolCallId: "read-1", toolName: "read", text: "alpha\nbeta\ngamma", isError: false, ts: 3 },
|
|
316
|
+
],
|
|
317
|
+
});
|
|
318
|
+
const state = stateForTest();
|
|
319
|
+
state.baseCwd = root;
|
|
320
|
+
let renderRequests = 0;
|
|
321
|
+
const component = new SubagentFleetComponent(
|
|
322
|
+
{ terminal: { rows: 32, columns: 100 }, requestRender() { renderRequests++; } } as never,
|
|
323
|
+
theme as never,
|
|
324
|
+
state,
|
|
325
|
+
() => {},
|
|
326
|
+
{ asyncDirRoot: root, resultsDir: path.join(root, "results"), refreshMs: 60_000, markdownTheme },
|
|
327
|
+
);
|
|
328
|
+
try {
|
|
329
|
+
let lines = component.render(100);
|
|
330
|
+
assert.ok(lines.some((line) => line.includes("alpha beta gamma") && line.includes("x to expand")));
|
|
331
|
+
component.handleInput("x");
|
|
332
|
+
lines = component.render(100);
|
|
333
|
+
assert.ok(lines.some((line) => line.includes("alpha") && !line.includes("beta")));
|
|
334
|
+
assert.ok(lines.some((line) => line.includes("x to collapse")));
|
|
335
|
+
component.handleInput("\x0f");
|
|
336
|
+
lines = component.render(100);
|
|
337
|
+
assert.ok(lines.some((line) => line.includes("alpha beta gamma") && line.includes("x to expand")));
|
|
338
|
+
fs.appendFileSync(
|
|
339
|
+
path.join(root, "async-tools", "transcript-0.jsonl"),
|
|
340
|
+
`${JSON.stringify({ recordType: "message", role: "assistant", text: "Cache refreshed after append", ts: 4 })}\n`,
|
|
341
|
+
"utf-8",
|
|
342
|
+
);
|
|
343
|
+
lines = component.render(100);
|
|
344
|
+
assert.ok(lines.some((line) => line.includes("Cache refreshed after append")));
|
|
345
|
+
assert.equal(renderRequests, 2);
|
|
346
|
+
} finally {
|
|
347
|
+
component.dispose();
|
|
348
|
+
}
|
|
349
|
+
} finally {
|
|
350
|
+
fs.rmSync(root, { recursive: true, force: true });
|
|
351
|
+
}
|
|
352
|
+
});
|
|
353
|
+
|
|
354
|
+
it("renders the selected foreground parallel child's structured transcript", () => {
|
|
355
|
+
const root = fs.mkdtempSync(path.join(os.tmpdir(), "pi-fleet-foreground-"));
|
|
356
|
+
try {
|
|
357
|
+
const state = stateForTest();
|
|
358
|
+
state.baseCwd = path.join(root, "parent-cwd");
|
|
359
|
+
const effectiveCwd = path.join(root, "effective-cwd");
|
|
360
|
+
const now = Date.now();
|
|
361
|
+
state.foregroundControls.set("foreground-live", {
|
|
362
|
+
runId: "foreground-live",
|
|
363
|
+
mode: "parallel",
|
|
364
|
+
startedAt: now - 1_000,
|
|
365
|
+
updatedAt: now,
|
|
366
|
+
cwd: effectiveCwd,
|
|
367
|
+
currentAgent: "reviewer",
|
|
368
|
+
currentIndex: 1,
|
|
369
|
+
description: "Review the active task",
|
|
370
|
+
activeChildren: new Map([
|
|
371
|
+
[0, { index: 0, agent: "worker", description: "Implement the active task", startedAt: now - 900, updatedAt: now - 100, tokens: 120 }],
|
|
372
|
+
[1, { index: 1, agent: "reviewer", description: "Review the active task", startedAt: now - 800, updatedAt: now, tokens: 240 }],
|
|
373
|
+
]),
|
|
374
|
+
});
|
|
375
|
+
const artifactsRoot = getProjectArtifactsDir(effectiveCwd);
|
|
376
|
+
fs.mkdirSync(artifactsRoot, { recursive: true });
|
|
377
|
+
const transcriptPath = getArtifactPaths(artifactsRoot, "foreground-live", "worker", 0).transcriptPath;
|
|
378
|
+
fs.writeFileSync(transcriptPath, `${JSON.stringify({ recordType: "message", role: "assistant", model: "test-model", text: "**Worker live result**" })}\n`, "utf-8");
|
|
379
|
+
const component = new SubagentFleetComponent(
|
|
380
|
+
{ terminal: { rows: 28, columns: 90 }, requestRender() {} } as never,
|
|
381
|
+
theme as never,
|
|
382
|
+
state,
|
|
383
|
+
() => {},
|
|
384
|
+
{ initialKey: "foreground-active:foreground-live:0", refreshMs: 60_000, markdownTheme },
|
|
385
|
+
);
|
|
386
|
+
try {
|
|
387
|
+
const lines = component.render(90);
|
|
388
|
+
assert.ok(lines.some((line) => line.includes("worker")));
|
|
389
|
+
assert.ok(lines.some((line) => line.includes("reviewer")));
|
|
390
|
+
assert.ok(lines.some((line) => line.includes("foreground · live")));
|
|
391
|
+
assert.ok(lines.some((line) => line.includes("Task") && line.includes("Implement the active task")));
|
|
392
|
+
assert.ok(lines.some((line) => line.includes("Conversation") && line.includes("assistant response")));
|
|
393
|
+
assert.ok(lines.some((line) => line.includes("Worker live result")));
|
|
394
|
+
} finally {
|
|
395
|
+
component.dispose();
|
|
396
|
+
}
|
|
397
|
+
} finally {
|
|
398
|
+
fs.rmSync(root, { recursive: true, force: true });
|
|
399
|
+
}
|
|
400
|
+
});
|
|
401
|
+
|
|
402
|
+
it("renders configured session and temp transcripts for active foreground, completed foreground, and async children", () => {
|
|
403
|
+
const root = fs.mkdtempSync(path.join(os.tmpdir(), "pi-fleet-artifact-roots-"));
|
|
404
|
+
const createdTranscriptPaths: string[] = [];
|
|
405
|
+
try {
|
|
406
|
+
for (const preference of ["session", "temp"] as const) {
|
|
407
|
+
const baseCwd = path.join(root, `${preference}-cwd`);
|
|
408
|
+
const sessionFile = path.join(root, `${preference}-session`, "session.jsonl");
|
|
409
|
+
const artifactsRoot = getArtifactsDir(sessionFile, baseCwd, preference);
|
|
410
|
+
const prefix = `${path.basename(root)}-${preference}`;
|
|
411
|
+
fs.mkdirSync(artifactsRoot, { recursive: true });
|
|
412
|
+
const transcript = (runId: string, agent: string, index: number, text: string) => {
|
|
413
|
+
const transcriptPath = getArtifactPaths(artifactsRoot, runId, agent, index).transcriptPath;
|
|
414
|
+
fs.writeFileSync(transcriptPath, `${JSON.stringify({ recordType: "message", role: "assistant", text })}\n`, "utf-8");
|
|
415
|
+
createdTranscriptPaths.push(transcriptPath);
|
|
416
|
+
return transcriptPath;
|
|
417
|
+
};
|
|
418
|
+
|
|
419
|
+
const activeId = `${prefix}-active`;
|
|
420
|
+
const recentId = `${prefix}-recent`;
|
|
421
|
+
const asyncId = `${prefix}-async`;
|
|
422
|
+
transcript(activeId, "worker", 0, `${preference} active foreground transcript`);
|
|
423
|
+
const recentTranscript = transcript(recentId, "reviewer", 0, `${preference} completed foreground transcript`);
|
|
424
|
+
const asyncTranscript = transcript(asyncId, "scout", 0, `${preference} async transcript`);
|
|
425
|
+
|
|
426
|
+
const state = stateForTest();
|
|
427
|
+
state.baseCwd = baseCwd;
|
|
428
|
+
state.artifactDirPreference = preference;
|
|
429
|
+
state.parentSessionFile = sessionFile;
|
|
430
|
+
state.foregroundControls.set(activeId, {
|
|
431
|
+
runId: activeId,
|
|
432
|
+
mode: "single",
|
|
433
|
+
cwd: baseCwd,
|
|
434
|
+
startedAt: 100,
|
|
435
|
+
updatedAt: 300,
|
|
436
|
+
currentAgent: "worker",
|
|
437
|
+
currentIndex: 0,
|
|
438
|
+
});
|
|
439
|
+
state.foregroundRuns!.set(recentId, {
|
|
440
|
+
runId: recentId,
|
|
441
|
+
mode: "single",
|
|
442
|
+
cwd: baseCwd,
|
|
443
|
+
sessionId: "session-current",
|
|
444
|
+
updatedAt: 200,
|
|
445
|
+
children: [{ agent: "reviewer", index: 0, status: "completed", transcriptPath: recentTranscript }],
|
|
446
|
+
});
|
|
447
|
+
state.asyncJobs.set(asyncId, {
|
|
448
|
+
asyncId,
|
|
449
|
+
asyncDir: path.join(root, `${preference}-async-run`),
|
|
450
|
+
cwd: baseCwd,
|
|
451
|
+
sessionId: "session-current",
|
|
452
|
+
status: "complete",
|
|
453
|
+
mode: "single",
|
|
454
|
+
startedAt: 100,
|
|
455
|
+
updatedAt: 250,
|
|
456
|
+
steps: [{ agent: "scout", index: 0, status: "complete", transcriptPath: asyncTranscript }],
|
|
457
|
+
});
|
|
458
|
+
|
|
459
|
+
for (const [initialKey, expected] of [
|
|
460
|
+
[`foreground-active:${activeId}:0`, `${preference} active foreground transcript`],
|
|
461
|
+
[`foreground-recent:${recentId}:0`, `${preference} completed foreground transcript`],
|
|
462
|
+
[`async:${asyncId}:0`, `${preference} async transcript`],
|
|
463
|
+
] as const) {
|
|
464
|
+
const component = new SubagentFleetComponent(
|
|
465
|
+
{ terminal: { rows: 28, columns: 100 }, requestRender() {} } as never,
|
|
466
|
+
theme as never,
|
|
467
|
+
state,
|
|
468
|
+
() => {},
|
|
469
|
+
{ initialKey, refreshMs: 60_000, markdownTheme },
|
|
470
|
+
);
|
|
471
|
+
try {
|
|
472
|
+
assert.ok(component.render(100).some((line) => line.includes(expected)), `missing ${expected}`);
|
|
473
|
+
} finally {
|
|
474
|
+
component.dispose();
|
|
475
|
+
}
|
|
476
|
+
}
|
|
477
|
+
}
|
|
478
|
+
} finally {
|
|
479
|
+
for (const transcriptPath of createdTranscriptPaths) fs.rmSync(transcriptPath, { force: true });
|
|
480
|
+
fs.rmSync(root, { recursive: true, force: true });
|
|
481
|
+
}
|
|
482
|
+
});
|
|
483
|
+
|
|
484
|
+
it("suppresses the status widget for the full inspector lifecycle", async () => {
|
|
485
|
+
const state = stateForTest();
|
|
486
|
+
let hidden = 0;
|
|
487
|
+
let observedOpen = false;
|
|
488
|
+
const ctx = {
|
|
489
|
+
hasUI: true,
|
|
490
|
+
ui: {
|
|
491
|
+
setWidget(key: string, content: unknown) {
|
|
492
|
+
assert.equal(key, FLEET_STATUS_WIDGET_KEY);
|
|
493
|
+
assert.equal(content, undefined);
|
|
494
|
+
hidden++;
|
|
495
|
+
},
|
|
496
|
+
async custom() {
|
|
497
|
+
observedOpen = state.fleetInspectorOpen === true;
|
|
498
|
+
throw new Error("overlay closed");
|
|
499
|
+
},
|
|
500
|
+
},
|
|
501
|
+
};
|
|
502
|
+
|
|
503
|
+
await assert.rejects(openSubagentFleet(ctx as never, state), /overlay closed/);
|
|
504
|
+
assert.equal(hidden, 1);
|
|
505
|
+
assert.equal(observedOpen, true);
|
|
506
|
+
assert.equal(state.fleetInspectorOpen, false);
|
|
507
|
+
});
|
|
508
|
+
|
|
509
|
+
it("opens the inspector with the FleetView-selected child focused", () => {
|
|
510
|
+
const state = stateForTest();
|
|
511
|
+
state.foregroundControls.set("run-worker", {
|
|
512
|
+
runId: "run-worker",
|
|
513
|
+
mode: "single",
|
|
514
|
+
startedAt: 10,
|
|
515
|
+
updatedAt: 20,
|
|
516
|
+
currentAgent: "worker",
|
|
517
|
+
currentIndex: 0,
|
|
518
|
+
});
|
|
519
|
+
state.foregroundControls.set("run-reviewer", {
|
|
520
|
+
runId: "run-reviewer",
|
|
521
|
+
mode: "single",
|
|
522
|
+
startedAt: 11,
|
|
523
|
+
updatedAt: 21,
|
|
524
|
+
currentAgent: "reviewer",
|
|
525
|
+
currentIndex: 0,
|
|
526
|
+
});
|
|
527
|
+
const component = new SubagentFleetComponent(
|
|
528
|
+
{ terminal: { rows: 28, columns: 90 }, requestRender() {} } as never,
|
|
529
|
+
theme as never,
|
|
530
|
+
state,
|
|
531
|
+
() => {},
|
|
532
|
+
{ initialKey: "foreground-active:run-worker:0", refreshMs: 60_000 },
|
|
533
|
+
);
|
|
534
|
+
try {
|
|
535
|
+
const selectedLine = component.render(90).find((line) => line.includes("›"));
|
|
536
|
+
assert.ok(selectedLine?.includes("run-work"), `unexpected selected row: ${selectedLine}`);
|
|
537
|
+
} finally {
|
|
538
|
+
component.dispose();
|
|
539
|
+
}
|
|
540
|
+
});
|
|
541
|
+
|
|
542
|
+
it("refreshes the roster while the overlay remains open", async () => {
|
|
543
|
+
const root = fs.mkdtempSync(path.join(os.tmpdir(), "pi-fleet-refresh-"));
|
|
544
|
+
try {
|
|
545
|
+
const state = stateForTest();
|
|
546
|
+
let renderRequests = 0;
|
|
547
|
+
const tui = { terminal: { rows: 28, columns: 90 }, requestRender: () => { renderRequests++; } };
|
|
548
|
+
const component = new SubagentFleetComponent(
|
|
549
|
+
tui as never,
|
|
550
|
+
theme as never,
|
|
551
|
+
state,
|
|
552
|
+
() => {},
|
|
553
|
+
{ asyncDirRoot: root, resultsDir: path.join(root, "results"), refreshMs: 10 },
|
|
554
|
+
);
|
|
555
|
+
try {
|
|
556
|
+
assert.ok(component.render(90).some((line) => line.includes("No tracked children")));
|
|
557
|
+
const initialOutput = Array.from({ length: 40 }, (_, index) => `output line ${index}`).join("\n");
|
|
558
|
+
const asyncDir = writeAsyncRun(root, { id: "appeared-live", output: initialOutput });
|
|
559
|
+
await new Promise((resolve) => setTimeout(resolve, 35));
|
|
560
|
+
let lines = component.render(90);
|
|
561
|
+
assert.ok(lines.some((line) => line.includes("appeared")));
|
|
562
|
+
assert.ok(lines.some((line) => line.includes("output line 39")));
|
|
563
|
+
fs.appendFileSync(path.join(asyncDir, "output-0.log"), "\nLATEST LIVE OUTPUT", "utf-8");
|
|
564
|
+
await new Promise((resolve) => setTimeout(resolve, 35));
|
|
565
|
+
lines = component.render(90);
|
|
566
|
+
assert.ok(lines.some((line) => line.includes("LATEST LIVE OUTPUT")), "live transcript should keep following new output");
|
|
567
|
+
assert.ok(renderRequests > 0);
|
|
568
|
+
} finally {
|
|
569
|
+
component.dispose();
|
|
570
|
+
}
|
|
571
|
+
} finally {
|
|
572
|
+
fs.rmSync(root, { recursive: true, force: true });
|
|
573
|
+
}
|
|
574
|
+
});
|
|
575
|
+
});
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import assert from "node:assert/strict";
|
|
2
|
+
import { describe, it } from "node:test";
|
|
3
|
+
import type { AgentProgress, ForegroundRunControl } from "../../src/shared/types.ts";
|
|
4
|
+
import { beginForegroundChild, finishForegroundChild, updateForegroundChild } from "../../src/runs/foreground/foreground-control.ts";
|
|
5
|
+
|
|
6
|
+
function progress(index: number, agent: string, tokens: number): AgentProgress {
|
|
7
|
+
return {
|
|
8
|
+
index,
|
|
9
|
+
agent,
|
|
10
|
+
status: "running",
|
|
11
|
+
task: `${agent} task`,
|
|
12
|
+
recentTools: [],
|
|
13
|
+
recentOutput: [],
|
|
14
|
+
toolCount: index + 1,
|
|
15
|
+
tokens,
|
|
16
|
+
durationMs: 10,
|
|
17
|
+
};
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
describe("foreground child control", () => {
|
|
21
|
+
it("tracks concurrent children independently and promotes the latest active child", () => {
|
|
22
|
+
const control: ForegroundRunControl = {
|
|
23
|
+
runId: "parallel-run",
|
|
24
|
+
mode: "parallel",
|
|
25
|
+
startedAt: 1,
|
|
26
|
+
updatedAt: 1,
|
|
27
|
+
activeChildren: new Map(),
|
|
28
|
+
};
|
|
29
|
+
let firstInterrupts = 0;
|
|
30
|
+
let secondInterrupts = 0;
|
|
31
|
+
beginForegroundChild(control, {
|
|
32
|
+
index: 0,
|
|
33
|
+
agent: "reviewer",
|
|
34
|
+
description: "Review correctness",
|
|
35
|
+
interrupt: () => { firstInterrupts++; return true; },
|
|
36
|
+
});
|
|
37
|
+
beginForegroundChild(control, {
|
|
38
|
+
index: 1,
|
|
39
|
+
agent: "reviewer",
|
|
40
|
+
description: "Review quality",
|
|
41
|
+
interrupt: () => { secondInterrupts++; return true; },
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
assert.equal(control.activeChildren?.size, 2);
|
|
45
|
+
assert.equal(control.currentIndex, 1);
|
|
46
|
+
updateForegroundChild(control, 0, progress(0, "reviewer", 120));
|
|
47
|
+
assert.equal(control.currentIndex, 0);
|
|
48
|
+
assert.equal(control.tokens, 120);
|
|
49
|
+
assert.equal(control.activeChildren?.get(1)?.tokens, undefined);
|
|
50
|
+
assert.equal(control.interrupt?.(), true);
|
|
51
|
+
assert.equal(firstInterrupts, 1);
|
|
52
|
+
assert.equal(secondInterrupts, 0);
|
|
53
|
+
|
|
54
|
+
updateForegroundChild(control, 1, progress(1, "reviewer", 240));
|
|
55
|
+
finishForegroundChild(control, 1);
|
|
56
|
+
assert.equal(control.currentIndex, 0);
|
|
57
|
+
assert.equal(control.tokens, 120);
|
|
58
|
+
assert.deepEqual([...control.activeChildren!.keys()], [0]);
|
|
59
|
+
|
|
60
|
+
finishForegroundChild(control, 0);
|
|
61
|
+
assert.equal(control.activeChildren?.size, 0);
|
|
62
|
+
assert.equal(control.currentIndex, undefined);
|
|
63
|
+
assert.equal(control.interrupt, undefined);
|
|
64
|
+
});
|
|
65
|
+
});
|