@selesai/code 0.2.1 → 0.3.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/config.d.ts +4 -15
- package/dist/config.d.ts.map +1 -1
- package/dist/config.js +5 -45
- package/dist/config.js.map +1 -1
- package/dist/core/agent-session.d.ts +1 -0
- package/dist/core/agent-session.d.ts.map +1 -1
- package/dist/core/agent-session.js +8 -0
- package/dist/core/agent-session.js.map +1 -1
- package/dist/core/diagnostics.d.ts +1 -0
- package/dist/core/diagnostics.d.ts.map +1 -1
- package/dist/core/diagnostics.js.map +1 -1
- package/dist/core/model-registry.d.ts +4 -1
- package/dist/core/model-registry.d.ts.map +1 -1
- package/dist/core/model-registry.js +101 -51
- package/dist/core/model-registry.js.map +1 -1
- package/dist/core/package-manager.d.ts +10 -0
- package/dist/core/package-manager.d.ts.map +1 -1
- package/dist/core/package-manager.js +93 -8
- package/dist/core/package-manager.js.map +1 -1
- package/dist/core/package-manager.test.d.ts +2 -0
- package/dist/core/package-manager.test.d.ts.map +1 -0
- package/dist/core/package-manager.test.js +20 -0
- package/dist/core/package-manager.test.js.map +1 -0
- package/dist/core/resource-loader.d.ts +3 -0
- package/dist/core/resource-loader.d.ts.map +1 -1
- package/dist/core/resource-loader.js +10 -0
- package/dist/core/resource-loader.js.map +1 -1
- package/dist/core/settings-manager.d.ts +1 -0
- package/dist/core/settings-manager.d.ts.map +1 -1
- package/dist/core/settings-manager.js.map +1 -1
- package/dist/defaults/models.json +64 -113
- package/dist/extensions/caveman/caveman-instructions.cjs +39 -0
- package/dist/extensions/caveman/index.js +116 -0
- package/dist/extensions/caveman/package.json +8 -0
- package/dist/extensions/caveman/test/extension.test.js +185 -0
- package/dist/extensions/caveman/test/helpers.test.js +67 -0
- package/dist/extensions/copy-turn.ts +2 -2
- package/dist/extensions/pi-intercom/broker/broker.ts +2 -3
- package/dist/extensions/pi-intercom/broker/paths.ts +10 -5
- package/dist/extensions/pi-intercom/broker/spawn.ts +2 -3
- package/dist/extensions/pi-intercom/config.ts +2 -2
- package/dist/extensions/pi-intercom/index.ts +2 -2
- package/dist/extensions/pi-intercom/package.json +2 -2
- package/dist/extensions/pi-intercom/ui/compose.ts +3 -3
- package/dist/extensions/pi-intercom/ui/inline-message.ts +3 -3
- package/dist/extensions/pi-intercom/ui/session-list.ts +3 -3
- package/dist/extensions/pi-powerline-footer/bash-mode/editor.ts +2 -2
- package/dist/extensions/pi-powerline-footer/bash-mode/history.ts +2 -1
- package/dist/extensions/pi-powerline-footer/index.ts +40 -47
- package/dist/extensions/pi-powerline-footer/package.json +2 -2
- package/dist/extensions/pi-powerline-footer/tests/bash-mode.test.ts +10 -10
- package/dist/extensions/pi-powerline-footer/tests/jump-shortcuts.test.ts +1 -1
- package/dist/extensions/pi-powerline-footer/tests/working-vibes.test.ts +2 -2
- package/dist/extensions/pi-powerline-footer/theme.ts +6 -6
- package/dist/extensions/pi-powerline-footer/tps.ts +1 -1
- package/dist/extensions/pi-powerline-footer/types.ts +7 -7
- package/dist/extensions/pi-powerline-footer/welcome.ts +23 -16
- package/dist/extensions/pi-powerline-footer/working-vibes.ts +52 -59
- package/dist/extensions/pi-rewind-hook/index.ts +1 -1
- package/dist/extensions/pi-rewind-hook/package.json +1 -1
- package/dist/extensions/pi-subagents/README.md +224 -52
- package/dist/extensions/pi-subagents/agents/architect.md +188 -0
- package/dist/extensions/pi-subagents/agents/builder.md +120 -0
- package/dist/extensions/pi-subagents/agents/commentator.md +131 -0
- package/dist/extensions/pi-subagents/agents/explorer.md +51 -0
- package/dist/extensions/pi-subagents/agents/recapper.md +21 -0
- package/dist/extensions/pi-subagents/install.mjs +93 -0
- package/dist/extensions/pi-subagents/package.json +4 -5
- package/dist/extensions/pi-subagents/prompts/parallel-context-build.md +1 -1
- package/dist/extensions/pi-subagents/prompts/parallel-handoff-plan.md +1 -1
- package/dist/extensions/pi-subagents/skills/pi-subagents/SKILL.md +76 -13
- package/dist/extensions/pi-subagents/src/agents/agent-management.ts +179 -2
- package/dist/extensions/pi-subagents/src/agents/agent-memory.ts +254 -0
- package/dist/extensions/pi-subagents/src/agents/agent-serializer.ts +11 -0
- package/dist/extensions/pi-subagents/src/agents/agents.ts +193 -19
- package/dist/extensions/pi-subagents/src/agents/chain-serializer.ts +27 -2
- package/dist/extensions/pi-subagents/src/extension/config.ts +27 -4
- package/dist/extensions/pi-subagents/src/extension/doctor.ts +1 -7
- package/dist/extensions/pi-subagents/src/extension/fanout-child.ts +3 -2
- package/dist/extensions/pi-subagents/src/extension/index.ts +73 -71
- package/dist/extensions/pi-subagents/src/extension/rpc.ts +369 -0
- package/dist/extensions/pi-subagents/src/extension/schemas.ts +54 -10
- package/dist/extensions/pi-subagents/src/extension/tool-description.ts +200 -0
- package/dist/extensions/pi-subagents/src/intercom/intercom-bridge.ts +21 -253
- package/dist/extensions/pi-subagents/src/intercom/native-supervisor-channel.ts +519 -0
- package/dist/extensions/pi-subagents/src/profiles/profiles.ts +1 -1
- package/dist/extensions/pi-subagents/src/runs/background/async-execution.ts +195 -105
- package/dist/extensions/pi-subagents/src/runs/background/async-job-tracker.ts +88 -2
- package/dist/extensions/pi-subagents/src/runs/background/async-status.ts +67 -10
- package/dist/extensions/pi-subagents/src/runs/background/chain-root-attachment.ts +34 -4
- package/dist/extensions/pi-subagents/src/runs/background/completion-batcher.ts +166 -0
- package/dist/extensions/pi-subagents/src/runs/background/control-channel.ts +156 -1
- package/dist/extensions/pi-subagents/src/runs/background/fleet-view.ts +515 -0
- package/dist/extensions/pi-subagents/src/runs/background/notify.ts +161 -44
- package/dist/extensions/pi-subagents/src/runs/background/result-watcher.ts +1 -2
- package/dist/extensions/pi-subagents/src/runs/background/run-id-resolver.ts +3 -2
- package/dist/extensions/pi-subagents/src/runs/background/run-status.ts +167 -6
- package/dist/extensions/pi-subagents/src/runs/background/scheduled-runs.ts +514 -0
- package/dist/extensions/pi-subagents/src/runs/background/stale-run-reconciler.ts +28 -1
- package/dist/extensions/pi-subagents/src/runs/background/subagent-runner.ts +873 -204
- package/dist/extensions/pi-subagents/src/runs/background/wait.ts +353 -0
- package/dist/extensions/pi-subagents/src/runs/foreground/chain-execution.ts +123 -27
- package/dist/extensions/pi-subagents/src/runs/foreground/execution.ts +174 -70
- package/dist/extensions/pi-subagents/src/runs/foreground/subagent-executor.ts +569 -81
- package/dist/extensions/pi-subagents/src/runs/shared/acceptance.ts +45 -22
- package/dist/extensions/pi-subagents/src/runs/shared/completion-guard.ts +3 -1
- package/dist/extensions/pi-subagents/src/runs/shared/dynamic-fanout.ts +2 -2
- package/dist/extensions/pi-subagents/src/runs/shared/model-fallback.ts +172 -21
- package/dist/extensions/pi-subagents/src/runs/shared/model-scope.ts +128 -0
- package/dist/extensions/pi-subagents/src/runs/shared/nested-events.ts +89 -0
- package/dist/extensions/pi-subagents/src/runs/shared/parallel-utils.ts +50 -1
- package/dist/extensions/pi-subagents/src/runs/shared/pi-args.ts +35 -4
- package/dist/extensions/pi-subagents/src/runs/shared/pi-spawn.ts +63 -45
- package/dist/extensions/pi-subagents/src/runs/shared/single-output.ts +2 -0
- package/dist/extensions/pi-subagents/src/runs/shared/subagent-prompt-runtime.ts +125 -5
- package/dist/extensions/pi-subagents/src/runs/shared/tool-budget.ts +74 -0
- package/dist/extensions/pi-subagents/src/runs/shared/turn-budget.ts +52 -0
- package/dist/extensions/pi-subagents/src/runs/shared/worktree.ts +28 -5
- package/dist/extensions/pi-subagents/src/shared/artifacts.ts +16 -1
- package/dist/extensions/pi-subagents/src/shared/atomic-json.ts +15 -2
- package/dist/extensions/pi-subagents/src/shared/child-transcript.ts +212 -0
- package/dist/extensions/pi-subagents/src/shared/fork-context.ts +133 -22
- package/dist/extensions/pi-subagents/src/shared/settings.ts +3 -1
- package/dist/extensions/pi-subagents/src/shared/types.ts +197 -4
- package/dist/extensions/pi-subagents/src/shared/utils.ts +108 -17
- package/dist/extensions/pi-subagents/src/slash/prompt-workflows.ts +330 -0
- package/dist/extensions/pi-subagents/src/slash/slash-commands.ts +135 -4
- package/dist/extensions/pi-subagents/src/tui/render.ts +32 -12
- package/dist/extensions/pi-subagents/test/e2e/real-session-subagent.test.ts +94 -0
- package/dist/extensions/pi-subagents/test/integration/async-execution.test.ts +2772 -0
- package/dist/extensions/pi-subagents/test/integration/async-job-tracker.test.ts +1107 -0
- package/dist/extensions/pi-subagents/test/integration/async-status.test.ts +463 -0
- package/dist/extensions/pi-subagents/test/integration/chain-clarify.test.ts +274 -0
- package/dist/extensions/pi-subagents/test/integration/chain-execution.test.ts +1535 -0
- package/dist/extensions/pi-subagents/test/integration/detect-error.test.ts +242 -0
- package/dist/extensions/pi-subagents/test/integration/doctor-executor.test.ts +128 -0
- package/dist/extensions/pi-subagents/test/integration/error-handling.test.ts +252 -0
- package/dist/extensions/pi-subagents/test/integration/foreground-result-size.test.ts +188 -0
- package/dist/extensions/pi-subagents/test/integration/fork-context-execution.test.ts +1306 -0
- package/dist/extensions/pi-subagents/test/integration/intercom-result-delivery.test.ts +1033 -0
- package/dist/extensions/pi-subagents/test/integration/parallel-execution.test.ts +397 -0
- package/dist/extensions/pi-subagents/test/integration/render-fork-badge.test.ts +583 -0
- package/dist/extensions/pi-subagents/test/integration/render-widget.test.ts +691 -0
- package/dist/extensions/pi-subagents/test/integration/result-watcher.test.ts +892 -0
- package/dist/extensions/pi-subagents/test/integration/session-tokens.test.ts +62 -0
- package/dist/extensions/pi-subagents/test/integration/single-execution.test.ts +1824 -0
- package/dist/extensions/pi-subagents/test/integration/slash-commands.test.ts +1284 -0
- package/dist/extensions/pi-subagents/test/integration/slash-live-state.test.ts +127 -0
- package/dist/extensions/pi-subagents/test/integration/template-resolution.test.ts +299 -0
- package/dist/extensions/pi-subagents/test/integration/top-level-async.test.ts +37 -0
- package/dist/extensions/pi-subagents/test/support/helpers.ts +189 -0
- package/dist/extensions/pi-subagents/test/support/mock-pi-script.mjs +335 -0
- package/dist/extensions/pi-subagents/test/support/mock-pi.ts +129 -0
- package/dist/extensions/pi-subagents/test/support/real-session-child-cli.mjs +184 -0
- package/dist/extensions/pi-subagents/test/support/real-session-runner.ts +285 -0
- package/dist/extensions/pi-subagents/test/support/register-loader.mjs +15 -0
- package/dist/extensions/pi-subagents/test/support/ts-loader.mjs +108 -0
- package/dist/extensions/pi-subagents/test/unit/acceptance.test.ts +421 -0
- package/dist/extensions/pi-subagents/test/unit/agent-disabled.test.ts +213 -0
- package/dist/extensions/pi-subagents/test/unit/agent-eject-disable.test.ts +343 -0
- package/dist/extensions/pi-subagents/test/unit/agent-frontmatter.test.ts +1199 -0
- package/dist/extensions/pi-subagents/test/unit/agent-management.test.ts +556 -0
- package/dist/extensions/pi-subagents/test/unit/agent-memory.test.ts +420 -0
- package/dist/extensions/pi-subagents/test/unit/agent-overrides.test.ts +579 -0
- package/dist/extensions/pi-subagents/test/unit/agent-scope.test.ts +20 -0
- package/dist/extensions/pi-subagents/test/unit/agent-selection.test.ts +88 -0
- package/dist/extensions/pi-subagents/test/unit/artifacts.test.ts +24 -0
- package/dist/extensions/pi-subagents/test/unit/async-execution.test.ts +86 -0
- package/dist/extensions/pi-subagents/test/unit/async-interrupt-action.test.ts +221 -0
- package/dist/extensions/pi-subagents/test/unit/async-permission-session.test.ts +98 -0
- package/dist/extensions/pi-subagents/test/unit/async-resume.test.ts +285 -0
- package/dist/extensions/pi-subagents/test/unit/atomic-json.test.ts +112 -0
- package/dist/extensions/pi-subagents/test/unit/chain-append.test.ts +206 -0
- package/dist/extensions/pi-subagents/test/unit/chain-root-attachment.test.ts +159 -0
- package/dist/extensions/pi-subagents/test/unit/chain-serializer.test.ts +229 -0
- package/dist/extensions/pi-subagents/test/unit/child-transcript.test.ts +225 -0
- package/dist/extensions/pi-subagents/test/unit/close-grace-timer.test.ts +101 -0
- package/dist/extensions/pi-subagents/test/unit/completion-batcher.test.ts +228 -0
- package/dist/extensions/pi-subagents/test/unit/completion-dedupe.test.ts +36 -0
- package/dist/extensions/pi-subagents/test/unit/completion-guard.test.ts +152 -0
- package/dist/extensions/pi-subagents/test/unit/config-dir-runtime.test.ts +72 -0
- package/dist/extensions/pi-subagents/test/unit/control-channel.test.ts +327 -0
- package/dist/extensions/pi-subagents/test/unit/control-notices.test.ts +161 -0
- package/dist/extensions/pi-subagents/test/unit/doctor.test.ts +159 -0
- package/dist/extensions/pi-subagents/test/unit/dynamic-fanout.test.ts +217 -0
- package/dist/extensions/pi-subagents/test/unit/extra-agent-dirs.test.ts +88 -0
- package/dist/extensions/pi-subagents/test/unit/file-coalescer.test.ts +68 -0
- package/dist/extensions/pi-subagents/test/unit/foreground-tool-call-compaction.test.ts +78 -0
- package/dist/extensions/pi-subagents/test/unit/fork-context.test.ts +415 -0
- package/dist/extensions/pi-subagents/test/unit/get-final-output.test.ts +126 -0
- package/dist/extensions/pi-subagents/test/unit/index-child-registration.test.ts +271 -0
- package/dist/extensions/pi-subagents/test/unit/intercom-bridge.test.ts +173 -0
- package/dist/extensions/pi-subagents/test/unit/jsonl-writer.test.ts +119 -0
- package/dist/extensions/pi-subagents/test/unit/live-async-resume.test.ts +170 -0
- package/dist/extensions/pi-subagents/test/unit/model-fallback.test.ts +346 -0
- package/dist/extensions/pi-subagents/test/unit/model-info.test.ts +62 -0
- package/dist/extensions/pi-subagents/test/unit/model-scope-settings.test.ts +87 -0
- package/dist/extensions/pi-subagents/test/unit/model-scope.test.ts +145 -0
- package/dist/extensions/pi-subagents/test/unit/native-supervisor-channel.test.ts +162 -0
- package/dist/extensions/pi-subagents/test/unit/nested-control.test.ts +470 -0
- package/dist/extensions/pi-subagents/test/unit/nested-events.test.ts +329 -0
- package/dist/extensions/pi-subagents/test/unit/notify.test.ts +319 -0
- package/dist/extensions/pi-subagents/test/unit/package-manifest.test.ts +70 -0
- package/dist/extensions/pi-subagents/test/unit/parallel-utils.test.ts +247 -0
- package/dist/extensions/pi-subagents/test/unit/path-handling.test.ts +113 -0
- package/dist/extensions/pi-subagents/test/unit/path-resolution.test.ts +94 -0
- package/dist/extensions/pi-subagents/test/unit/pi-args.test.ts +803 -0
- package/dist/extensions/pi-subagents/test/unit/pi-coding-agent-dir.test.ts +209 -0
- package/dist/extensions/pi-subagents/test/unit/pi-spawn.test.ts +238 -0
- package/dist/extensions/pi-subagents/test/unit/proactive-skills.test.ts +118 -0
- package/dist/extensions/pi-subagents/test/unit/profiles.test.ts +299 -0
- package/dist/extensions/pi-subagents/test/unit/prompt-template-bridge.test.ts +408 -0
- package/dist/extensions/pi-subagents/test/unit/prompt-workflows.test.ts +134 -0
- package/dist/extensions/pi-subagents/test/unit/recursion-guard.test.ts +257 -0
- package/dist/extensions/pi-subagents/test/unit/render-helpers.test.ts +209 -0
- package/dist/extensions/pi-subagents/test/unit/result-intercom.test.ts +226 -0
- package/dist/extensions/pi-subagents/test/unit/rpc.test.ts +294 -0
- package/dist/extensions/pi-subagents/test/unit/run-id-resolver.test.ts +147 -0
- package/dist/extensions/pi-subagents/test/unit/run-status.test.ts +997 -0
- package/dist/extensions/pi-subagents/test/unit/scheduled-runs.test.ts +478 -0
- package/dist/extensions/pi-subagents/test/unit/schemas.test.ts +562 -0
- package/dist/extensions/pi-subagents/test/unit/single-output.test.ts +213 -0
- package/dist/extensions/pi-subagents/test/unit/skills-fallback.test.ts +438 -0
- package/dist/extensions/pi-subagents/test/unit/slash-bridge.test.ts +54 -0
- package/dist/extensions/pi-subagents/test/unit/slash-chain-groups.test.ts +464 -0
- package/dist/extensions/pi-subagents/test/unit/stale-run-reconciler.test.ts +255 -0
- package/dist/extensions/pi-subagents/test/unit/status-format.test.ts +19 -0
- package/dist/extensions/pi-subagents/test/unit/subagent-control.test.ts +245 -0
- package/dist/extensions/pi-subagents/test/unit/subagent-prompt-runtime.test.ts +517 -0
- package/dist/extensions/pi-subagents/test/unit/temp-paths.test.ts +72 -0
- package/dist/extensions/pi-subagents/test/unit/tool-budget.test.ts +52 -0
- package/dist/extensions/pi-subagents/test/unit/tool-description.test.ts +237 -0
- package/dist/extensions/pi-subagents/test/unit/total-cost.test.ts +60 -0
- package/dist/extensions/pi-subagents/test/unit/ts-loader.test.ts +33 -0
- package/dist/extensions/pi-subagents/test/unit/turn-budget.test.ts +202 -0
- package/dist/extensions/pi-subagents/test/unit/types-fork-preamble.test.ts +23 -0
- package/dist/extensions/pi-subagents/test/unit/wait.test.ts +398 -0
- package/dist/extensions/pi-subagents/test/unit/widget-nested-render.test.ts +88 -0
- package/dist/extensions/pi-subagents/test/unit/windows-hide-spawn.test.ts +26 -0
- package/dist/extensions/pi-subagents/test/unit/workflow-graph.test.ts +134 -0
- package/dist/extensions/pi-subagents/test/unit/worktree.test.ts +479 -0
- package/dist/extensions/pi-web-agent/package.json +2 -2
- package/dist/extensions/pi-web-agent/src/backends/settings-reader.ts +2 -2
- package/dist/extensions/pi-web-agent/src/changelog-notice.ts +5 -2
- package/dist/extensions/pi-web-agent/src/commands/web-agent-config.ts +1 -1
- package/dist/extensions/pi-web-agent/src/extension.ts +1 -1
- package/dist/extensions/pi-web-agent/src/presentation/config-store.ts +6 -4
- package/dist/extensions/question/helpers.ts +3 -3
- package/dist/extensions/question/index.ts +2 -2
- package/dist/extensions/question/navigation.ts +2 -2
- package/dist/extensions/question/package.json +2 -2
- package/dist/extensions/question/question-list.ts +2 -2
- package/dist/extensions/question/tests/question-list.test.ts +2 -2
- package/dist/extensions/question/tui-adapter.ts +2 -2
- package/dist/extensions/question/types.ts +2 -2
- package/dist/extensions/question/ui-protocol.ts +2 -2
- package/dist/extensions/rtk.ts +2 -2
- package/dist/extensions/tokenin-onboarding.ts +2 -2
- package/dist/extensions/undo.ts +1 -1
- package/dist/extensions/web-agent-onboarding.ts +3 -3
- package/dist/extensions/workflow/adapter.ts +16 -8
- package/dist/extensions/workflow/extension.ts +1 -1
- package/dist/extensions/workflow/package.json +1 -1
- package/dist/main.d.ts.map +1 -1
- package/dist/main.js +4 -0
- package/dist/main.js.map +1 -1
- package/dist/modes/interactive/components/assistant-message.d.ts.map +1 -1
- package/dist/modes/interactive/components/assistant-message.js +2 -0
- package/dist/modes/interactive/components/assistant-message.js.map +1 -1
- package/dist/modes/interactive/components/first-time-setup.d.ts +1 -1
- package/dist/modes/interactive/components/first-time-setup.d.ts.map +1 -1
- package/dist/modes/interactive/components/first-time-setup.js +19 -5
- package/dist/modes/interactive/components/first-time-setup.js.map +1 -1
- package/dist/skills/caveman/SKILL.md +49 -0
- package/dist/skills/handoff-text/SKILL.md +13 -0
- package/dist/utils/thinking-tags.d.ts +7 -0
- package/dist/utils/thinking-tags.d.ts.map +1 -0
- package/dist/utils/thinking-tags.js +63 -0
- package/dist/utils/thinking-tags.js.map +1 -0
- package/docs/docs.json +4 -0
- package/docs/extensions.md +2 -0
- package/docs/settings.md +15 -0
- package/docs/shared-host-extensions.md +109 -0
- package/package.json +2 -2
|
@@ -0,0 +1,997 @@
|
|
|
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 { inspectSubagentStatus } from "../../src/runs/background/run-status.ts";
|
|
7
|
+
import { createNestedRoute, writeNestedEvent } from "../../src/runs/shared/nested-events.ts";
|
|
8
|
+
import { TEMP_ROOT_DIR, type SubagentState } from "../../src/shared/types.ts";
|
|
9
|
+
|
|
10
|
+
function errno(code: string): NodeJS.ErrnoException {
|
|
11
|
+
const error = new Error(code) as NodeJS.ErrnoException;
|
|
12
|
+
error.code = code;
|
|
13
|
+
return error;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
function textContent(result: ReturnType<typeof inspectSubagentStatus>): string {
|
|
17
|
+
const first = result.content[0];
|
|
18
|
+
return first?.type === "text" ? first.text : "";
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
describe("async run status inspection", () => {
|
|
22
|
+
it("repairs stale running status and reports diagnosis plus result path", () => {
|
|
23
|
+
const root = fs.mkdtempSync(path.join(os.tmpdir(), "pi-run-status-stale-"));
|
|
24
|
+
try {
|
|
25
|
+
const asyncRoot = path.join(root, "runs");
|
|
26
|
+
const resultsDir = path.join(root, "results");
|
|
27
|
+
const asyncDir = path.join(asyncRoot, "run-stale");
|
|
28
|
+
fs.mkdirSync(asyncDir, { recursive: true });
|
|
29
|
+
const sessionFile = path.join(root, "session.jsonl");
|
|
30
|
+
fs.writeFileSync(sessionFile, "", "utf-8");
|
|
31
|
+
fs.writeFileSync(path.join(asyncDir, "status.json"), JSON.stringify({
|
|
32
|
+
runId: "run-stale",
|
|
33
|
+
mode: "single",
|
|
34
|
+
state: "running",
|
|
35
|
+
pid: 12345,
|
|
36
|
+
startedAt: 100,
|
|
37
|
+
lastUpdate: 100,
|
|
38
|
+
currentStep: 0,
|
|
39
|
+
sessionFile,
|
|
40
|
+
steps: [{ agent: "scout", status: "running", startedAt: 100, sessionFile }],
|
|
41
|
+
}, null, 2), "utf-8");
|
|
42
|
+
|
|
43
|
+
const result = inspectSubagentStatus({ id: "run-stale" }, {
|
|
44
|
+
asyncDirRoot: asyncRoot,
|
|
45
|
+
resultsDir,
|
|
46
|
+
kill: () => { throw errno("ESRCH"); },
|
|
47
|
+
now: () => 200,
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
const text = textContent(result);
|
|
51
|
+
assert.equal(result.isError, undefined);
|
|
52
|
+
assert.match(text, /State: failed/);
|
|
53
|
+
assert.match(text, /Diagnosis: Async runner process 12345 exited or disappeared/);
|
|
54
|
+
assert.match(text, new RegExp(`Result: ${path.join(resultsDir, "run-stale.json").replace(/[.*+?^${}()|[\]\\]/g, "\\$&")}`));
|
|
55
|
+
assert.match(text, /Step 1: scout failed, error: Async runner process 12345 exited or disappeared/);
|
|
56
|
+
assert.match(text, /Revive: subagent\(\{ action: "resume", id: "run-stale", message: "\.\.\." \}\)/);
|
|
57
|
+
const resultJson = JSON.parse(fs.readFileSync(path.join(resultsDir, "run-stale.json"), "utf-8"));
|
|
58
|
+
assert.equal(resultJson.success, false);
|
|
59
|
+
assert.equal(resultJson.results[0].sessionFile, sessionFile);
|
|
60
|
+
} finally {
|
|
61
|
+
fs.rmSync(root, { recursive: true, force: true });
|
|
62
|
+
}
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
it("shows parallel mode and aggregate progress for top-level async parallel runs", () => {
|
|
66
|
+
const root = fs.mkdtempSync(path.join(os.tmpdir(), "pi-run-status-parallel-"));
|
|
67
|
+
try {
|
|
68
|
+
const asyncRoot = path.join(root, "runs");
|
|
69
|
+
const asyncDir = path.join(asyncRoot, "run-parallel");
|
|
70
|
+
fs.mkdirSync(asyncDir, { recursive: true });
|
|
71
|
+
const runOutputPath = path.join(asyncDir, "combined-output.log");
|
|
72
|
+
const firstStepOutputPath = path.join(asyncDir, "output-0.log");
|
|
73
|
+
const secondStepOutputPath = path.join(asyncDir, "output-1.log");
|
|
74
|
+
fs.writeFileSync(firstStepOutputPath, "reviewer one", "utf-8");
|
|
75
|
+
fs.writeFileSync(secondStepOutputPath, "reviewer two", "utf-8");
|
|
76
|
+
fs.writeFileSync(path.join(asyncDir, "status.json"), JSON.stringify({
|
|
77
|
+
runId: "run-parallel",
|
|
78
|
+
mode: "parallel",
|
|
79
|
+
state: "running",
|
|
80
|
+
error: "top-level async status error",
|
|
81
|
+
pid: 12345,
|
|
82
|
+
startedAt: 100,
|
|
83
|
+
lastUpdate: 100,
|
|
84
|
+
currentStep: 0,
|
|
85
|
+
outputFile: runOutputPath,
|
|
86
|
+
chainStepCount: 1,
|
|
87
|
+
parallelGroups: [{ start: 0, count: 3, stepIndex: 0 }],
|
|
88
|
+
steps: [
|
|
89
|
+
{ agent: "reviewer", status: "running", startedAt: 100, model: "openai-codex/gpt-5.5:high" },
|
|
90
|
+
{ agent: "reviewer", status: "running", startedAt: 100, model: "anthropic/claude-haiku-4-5", thinking: "low" },
|
|
91
|
+
{ agent: "reviewer", status: "pending" },
|
|
92
|
+
],
|
|
93
|
+
}, null, 2), "utf-8");
|
|
94
|
+
|
|
95
|
+
const result = inspectSubagentStatus({ id: "run-parallel" }, {
|
|
96
|
+
asyncDirRoot: asyncRoot,
|
|
97
|
+
resultsDir: path.join(root, "results"),
|
|
98
|
+
kill: () => true,
|
|
99
|
+
now: () => 200,
|
|
100
|
+
});
|
|
101
|
+
|
|
102
|
+
const text = textContent(result);
|
|
103
|
+
assert.match(text, /Mode: parallel/);
|
|
104
|
+
assert.match(text, /Error: top-level async status error/);
|
|
105
|
+
assert.match(text, /Progress: 2 agents running · 0\/3 done/);
|
|
106
|
+
assert.match(text, new RegExp(`Output: ${runOutputPath.replace(/[.*+?^${}()|[\]\\]/g, "\\$&")}`));
|
|
107
|
+
assert.match(text, /Agent 1\/3: reviewer running \(gpt-5\.5 · thinking high\)/);
|
|
108
|
+
assert.match(text, /Agent 2\/3: reviewer running \(claude-haiku-4-5 · thinking low\)/);
|
|
109
|
+
assert.match(text, /Agent 3\/3: reviewer pending/);
|
|
110
|
+
assert.doesNotMatch(text, /openai-codex\/gpt-5\.5/);
|
|
111
|
+
assert.match(text, new RegExp(` Output: ${firstStepOutputPath.replace(/[.*+?^${}()|[\]\\]/g, "\\$&")}`));
|
|
112
|
+
assert.match(text, new RegExp(` Output: ${secondStepOutputPath.replace(/[.*+?^${}()|[\]\\]/g, "\\$&")}`));
|
|
113
|
+
assert.doesNotMatch(text, /Step 1: reviewer/);
|
|
114
|
+
} finally {
|
|
115
|
+
fs.rmSync(root, { recursive: true, force: true });
|
|
116
|
+
}
|
|
117
|
+
});
|
|
118
|
+
|
|
119
|
+
it("tails a readable transcript from async output artifacts", () => {
|
|
120
|
+
const root = fs.mkdtempSync(path.join(os.tmpdir(), "pi-run-status-transcript-"));
|
|
121
|
+
try {
|
|
122
|
+
const asyncRoot = path.join(root, "runs");
|
|
123
|
+
const asyncDir = path.join(asyncRoot, "run-transcript");
|
|
124
|
+
fs.mkdirSync(asyncDir, { recursive: true });
|
|
125
|
+
const outputPath = path.join(asyncDir, "output-0.log");
|
|
126
|
+
fs.writeFileSync(outputPath, ["first line", "second line", "third line"].join("\n"), "utf-8");
|
|
127
|
+
fs.writeFileSync(path.join(asyncDir, "status.json"), JSON.stringify({
|
|
128
|
+
runId: "run-transcript",
|
|
129
|
+
mode: "single",
|
|
130
|
+
state: "running",
|
|
131
|
+
startedAt: 100,
|
|
132
|
+
lastUpdate: 200,
|
|
133
|
+
currentStep: 0,
|
|
134
|
+
steps: [{ agent: "worker", status: "running", startedAt: 100 }],
|
|
135
|
+
}, null, 2), "utf-8");
|
|
136
|
+
|
|
137
|
+
const result = inspectSubagentStatus({ id: "run-transcript", view: "transcript", lines: 2 }, {
|
|
138
|
+
asyncDirRoot: asyncRoot,
|
|
139
|
+
resultsDir: path.join(root, "results"),
|
|
140
|
+
kill: () => true,
|
|
141
|
+
now: () => 250,
|
|
142
|
+
});
|
|
143
|
+
|
|
144
|
+
const text = textContent(result);
|
|
145
|
+
assert.equal(result.isError, undefined);
|
|
146
|
+
assert.match(text, /Run: run-transcript/);
|
|
147
|
+
assert.match(text, /Step: 0 \(worker\) \| running/);
|
|
148
|
+
assert.match(text, new RegExp(`Transcript tail from ${outputPath.replace(/[.*+?^${}()|[\]\\]/g, "\\$&")} \\(tail truncated\\):`));
|
|
149
|
+
assert.doesNotMatch(text, /first line/);
|
|
150
|
+
assert.match(text, /second line/);
|
|
151
|
+
assert.match(text, /third line/);
|
|
152
|
+
assert.match(text, new RegExp(`Output: ${outputPath.replace(/[.*+?^${}()|[\]\\]/g, "\\$&")}`));
|
|
153
|
+
} finally {
|
|
154
|
+
fs.rmSync(root, { recursive: true, force: true });
|
|
155
|
+
}
|
|
156
|
+
});
|
|
157
|
+
|
|
158
|
+
it("does not fall back to another child output when an explicit transcript index output is missing", () => {
|
|
159
|
+
const root = fs.mkdtempSync(path.join(os.tmpdir(), "pi-run-status-transcript-index-"));
|
|
160
|
+
try {
|
|
161
|
+
const asyncRoot = path.join(root, "runs");
|
|
162
|
+
const asyncDir = path.join(asyncRoot, "run-indexed-transcript");
|
|
163
|
+
fs.mkdirSync(asyncDir, { recursive: true });
|
|
164
|
+
const wrongOutputPath = path.join(asyncDir, "output-0.log");
|
|
165
|
+
fs.writeFileSync(wrongOutputPath, "WRONG_CHILD_OUTPUT", "utf-8");
|
|
166
|
+
fs.writeFileSync(path.join(asyncDir, "status.json"), JSON.stringify({
|
|
167
|
+
runId: "run-indexed-transcript",
|
|
168
|
+
mode: "parallel",
|
|
169
|
+
state: "running",
|
|
170
|
+
startedAt: 100,
|
|
171
|
+
lastUpdate: 200,
|
|
172
|
+
currentStep: 0,
|
|
173
|
+
outputFile: wrongOutputPath,
|
|
174
|
+
steps: [
|
|
175
|
+
{ agent: "worker", status: "running", startedAt: 100 },
|
|
176
|
+
{ agent: "reviewer", status: "pending", recentOutput: ["RIGHT_CHILD_RECENT"] },
|
|
177
|
+
],
|
|
178
|
+
}, null, 2), "utf-8");
|
|
179
|
+
|
|
180
|
+
const result = inspectSubagentStatus({ id: "run-indexed-transcript", view: "transcript", index: 1 }, {
|
|
181
|
+
asyncDirRoot: asyncRoot,
|
|
182
|
+
resultsDir: path.join(root, "results"),
|
|
183
|
+
kill: () => true,
|
|
184
|
+
now: () => 250,
|
|
185
|
+
});
|
|
186
|
+
|
|
187
|
+
const text = textContent(result);
|
|
188
|
+
assert.equal(result.isError, undefined);
|
|
189
|
+
assert.match(text, /Agent: 1 \(reviewer\) \| pending/);
|
|
190
|
+
assert.match(text, /Recent output from status\.json:/);
|
|
191
|
+
assert.match(text, /RIGHT_CHILD_RECENT/);
|
|
192
|
+
assert.doesNotMatch(text, /WRONG_CHILD_OUTPUT/);
|
|
193
|
+
assert.doesNotMatch(text, new RegExp(`Transcript tail from ${wrongOutputPath.replace(/[.*+?^${}()|[\]\\]/g, "\\$&")}`));
|
|
194
|
+
} finally {
|
|
195
|
+
fs.rmSync(root, { recursive: true, force: true });
|
|
196
|
+
}
|
|
197
|
+
});
|
|
198
|
+
|
|
199
|
+
it("refuses to tail status outputFile paths outside the async directory", () => {
|
|
200
|
+
const root = fs.mkdtempSync(path.join(os.tmpdir(), "pi-run-status-transcript-escape-"));
|
|
201
|
+
try {
|
|
202
|
+
const asyncRoot = path.join(root, "runs");
|
|
203
|
+
const asyncDir = path.join(asyncRoot, "run-escape");
|
|
204
|
+
fs.mkdirSync(asyncDir, { recursive: true });
|
|
205
|
+
const outsideOutput = path.join(root, "outside.log");
|
|
206
|
+
fs.writeFileSync(outsideOutput, "OUTSIDE_SENTINEL", "utf-8");
|
|
207
|
+
fs.writeFileSync(path.join(asyncDir, "status.json"), JSON.stringify({
|
|
208
|
+
runId: "run-escape",
|
|
209
|
+
mode: "single",
|
|
210
|
+
state: "complete",
|
|
211
|
+
startedAt: 100,
|
|
212
|
+
lastUpdate: 200,
|
|
213
|
+
outputFile: path.relative(asyncDir, outsideOutput),
|
|
214
|
+
steps: [],
|
|
215
|
+
}, null, 2), "utf-8");
|
|
216
|
+
|
|
217
|
+
const result = inspectSubagentStatus({ id: "run-escape", view: "transcript" }, {
|
|
218
|
+
asyncDirRoot: asyncRoot,
|
|
219
|
+
resultsDir: path.join(root, "results"),
|
|
220
|
+
});
|
|
221
|
+
|
|
222
|
+
const text = textContent(result);
|
|
223
|
+
assert.equal(result.isError, undefined);
|
|
224
|
+
assert.match(text, /Output read failed .*outside trusted roots/);
|
|
225
|
+
assert.doesNotMatch(text, /OUTSIDE_SENTINEL/);
|
|
226
|
+
} finally {
|
|
227
|
+
fs.rmSync(root, { recursive: true, force: true });
|
|
228
|
+
}
|
|
229
|
+
});
|
|
230
|
+
|
|
231
|
+
it("refuses symlink session transcript paths even under trusted roots", () => {
|
|
232
|
+
const root = fs.mkdtempSync(path.join(os.tmpdir(), "pi-run-status-transcript-session-"));
|
|
233
|
+
try {
|
|
234
|
+
const asyncRoot = path.join(root, "runs");
|
|
235
|
+
const asyncDir = path.join(asyncRoot, "run-session-symlink");
|
|
236
|
+
const sessionRoot = path.join(root, "sessions");
|
|
237
|
+
fs.mkdirSync(asyncDir, { recursive: true });
|
|
238
|
+
fs.mkdirSync(sessionRoot, { recursive: true });
|
|
239
|
+
const outsideSession = path.join(root, "outside-session.jsonl");
|
|
240
|
+
const linkedSession = path.join(sessionRoot, "session.jsonl");
|
|
241
|
+
fs.writeFileSync(outsideSession, `${JSON.stringify({ message: { role: "assistant", content: "OUTSIDE_SESSION_SENTINEL" } })}\n`, "utf-8");
|
|
242
|
+
fs.symlinkSync(outsideSession, linkedSession);
|
|
243
|
+
fs.writeFileSync(path.join(asyncDir, "status.json"), JSON.stringify({
|
|
244
|
+
runId: "run-session-symlink",
|
|
245
|
+
mode: "single",
|
|
246
|
+
state: "complete",
|
|
247
|
+
startedAt: 100,
|
|
248
|
+
lastUpdate: 200,
|
|
249
|
+
steps: [{ agent: "worker", status: "complete", sessionFile: linkedSession }],
|
|
250
|
+
}, null, 2), "utf-8");
|
|
251
|
+
|
|
252
|
+
const result = inspectSubagentStatus({ id: "run-session-symlink", view: "transcript", index: 0 }, {
|
|
253
|
+
asyncDirRoot: asyncRoot,
|
|
254
|
+
resultsDir: path.join(root, "results"),
|
|
255
|
+
sessionRoots: [sessionRoot],
|
|
256
|
+
});
|
|
257
|
+
|
|
258
|
+
const text = textContent(result);
|
|
259
|
+
assert.equal(result.isError, undefined);
|
|
260
|
+
assert.match(text, /Session read failed .*Refusing to read symlink session transcript path/);
|
|
261
|
+
assert.match(text, new RegExp(`Session: ${linkedSession.replace(/[.*+?^${}()|[\]\\]/g, "\\$&")}`));
|
|
262
|
+
assert.doesNotMatch(text, /OUTSIDE_SESSION_SENTINEL/);
|
|
263
|
+
} finally {
|
|
264
|
+
fs.rmSync(root, { recursive: true, force: true });
|
|
265
|
+
}
|
|
266
|
+
});
|
|
267
|
+
|
|
268
|
+
it("shows an active read-only fleet view with transcript commands", () => {
|
|
269
|
+
const root = fs.mkdtempSync(path.join(os.tmpdir(), "pi-run-status-fleet-"));
|
|
270
|
+
try {
|
|
271
|
+
const asyncRoot = path.join(root, "runs");
|
|
272
|
+
const asyncDir = path.join(asyncRoot, "run-fleet");
|
|
273
|
+
fs.mkdirSync(asyncDir, { recursive: true });
|
|
274
|
+
fs.writeFileSync(path.join(asyncDir, "output-0.log"), "worker output", "utf-8");
|
|
275
|
+
fs.writeFileSync(path.join(asyncDir, "status.json"), JSON.stringify({
|
|
276
|
+
runId: "run-fleet",
|
|
277
|
+
mode: "parallel",
|
|
278
|
+
state: "running",
|
|
279
|
+
startedAt: 100,
|
|
280
|
+
lastUpdate: 200,
|
|
281
|
+
currentStep: 0,
|
|
282
|
+
chainStepCount: 1,
|
|
283
|
+
parallelGroups: [{ start: 0, count: 2, stepIndex: 0 }],
|
|
284
|
+
steps: [
|
|
285
|
+
{ agent: "worker", status: "running", startedAt: 100 },
|
|
286
|
+
{ agent: "reviewer", status: "pending" },
|
|
287
|
+
],
|
|
288
|
+
}, null, 2), "utf-8");
|
|
289
|
+
const state = {
|
|
290
|
+
foregroundControls: new Map([["fg-run", {
|
|
291
|
+
runId: "fg-run",
|
|
292
|
+
mode: "single",
|
|
293
|
+
startedAt: 100,
|
|
294
|
+
updatedAt: 250,
|
|
295
|
+
currentAgent: "scout",
|
|
296
|
+
currentIndex: 0,
|
|
297
|
+
lastActivityAt: 240,
|
|
298
|
+
}]]),
|
|
299
|
+
} as unknown as SubagentState;
|
|
300
|
+
|
|
301
|
+
const result = inspectSubagentStatus({ view: "fleet" }, {
|
|
302
|
+
asyncDirRoot: asyncRoot,
|
|
303
|
+
resultsDir: path.join(root, "results"),
|
|
304
|
+
state,
|
|
305
|
+
kill: () => true,
|
|
306
|
+
now: () => 250,
|
|
307
|
+
});
|
|
308
|
+
|
|
309
|
+
const text = textContent(result);
|
|
310
|
+
assert.equal(result.isError, undefined);
|
|
311
|
+
assert.match(text, /Subagent fleet: 2 active/);
|
|
312
|
+
assert.match(text, /Foreground runs:/);
|
|
313
|
+
assert.match(text, /fg-run \| running \| scout/);
|
|
314
|
+
assert.match(text, /Async runs:/);
|
|
315
|
+
assert.match(text, /run-fleet \| running .*\| parallel \| 1 agent running · 0\/2 done/);
|
|
316
|
+
assert.match(text, /transcript: subagent\(\{ action: "status", id: "run-fleet", view: "transcript" \}\)/);
|
|
317
|
+
assert.match(text, /transcript: subagent\(\{ action: "status", id: "run-fleet", index: 0, view: "transcript" \}\)/);
|
|
318
|
+
} finally {
|
|
319
|
+
fs.rmSync(root, { recursive: true, force: true });
|
|
320
|
+
}
|
|
321
|
+
});
|
|
322
|
+
|
|
323
|
+
it("scopes fleet active-run discovery to the current session", () => {
|
|
324
|
+
const root = fs.mkdtempSync(path.join(os.tmpdir(), "pi-run-status-fleet-session-"));
|
|
325
|
+
try {
|
|
326
|
+
const asyncRoot = path.join(root, "runs");
|
|
327
|
+
const currentDir = path.join(asyncRoot, "run-current");
|
|
328
|
+
const otherDir = path.join(asyncRoot, "run-other");
|
|
329
|
+
fs.mkdirSync(currentDir, { recursive: true });
|
|
330
|
+
fs.mkdirSync(otherDir, { recursive: true });
|
|
331
|
+
fs.writeFileSync(path.join(currentDir, "status.json"), JSON.stringify({
|
|
332
|
+
runId: "run-current",
|
|
333
|
+
sessionId: "session-current",
|
|
334
|
+
mode: "single",
|
|
335
|
+
state: "running",
|
|
336
|
+
startedAt: 100,
|
|
337
|
+
lastUpdate: 200,
|
|
338
|
+
steps: [{ agent: "worker", status: "running", startedAt: 100 }],
|
|
339
|
+
}, null, 2), "utf-8");
|
|
340
|
+
fs.writeFileSync(path.join(otherDir, "status.json"), JSON.stringify({
|
|
341
|
+
runId: "run-other",
|
|
342
|
+
sessionId: "session-other",
|
|
343
|
+
mode: "single",
|
|
344
|
+
state: "running",
|
|
345
|
+
startedAt: 100,
|
|
346
|
+
lastUpdate: 200,
|
|
347
|
+
steps: [{ agent: "reviewer", status: "running", startedAt: 100 }],
|
|
348
|
+
}, null, 2), "utf-8");
|
|
349
|
+
const state = {
|
|
350
|
+
currentSessionId: "session-current",
|
|
351
|
+
asyncJobs: new Map(),
|
|
352
|
+
foregroundControls: new Map(),
|
|
353
|
+
} as unknown as SubagentState;
|
|
354
|
+
|
|
355
|
+
const result = inspectSubagentStatus({ view: "fleet" }, {
|
|
356
|
+
asyncDirRoot: asyncRoot,
|
|
357
|
+
resultsDir: path.join(root, "results"),
|
|
358
|
+
state,
|
|
359
|
+
kill: () => true,
|
|
360
|
+
now: () => 250,
|
|
361
|
+
});
|
|
362
|
+
|
|
363
|
+
const text = textContent(result);
|
|
364
|
+
assert.equal(result.isError, undefined);
|
|
365
|
+
assert.match(text, /run-current/);
|
|
366
|
+
assert.doesNotMatch(text, /run-other/);
|
|
367
|
+
} finally {
|
|
368
|
+
fs.rmSync(root, { recursive: true, force: true });
|
|
369
|
+
}
|
|
370
|
+
});
|
|
371
|
+
|
|
372
|
+
it("refuses transcript reads for async runs owned by another session", () => {
|
|
373
|
+
const root = fs.mkdtempSync(path.join(os.tmpdir(), "pi-run-status-transcript-session-scope-"));
|
|
374
|
+
try {
|
|
375
|
+
const asyncRoot = path.join(root, "runs");
|
|
376
|
+
const asyncDir = path.join(asyncRoot, "run-other-session");
|
|
377
|
+
fs.mkdirSync(asyncDir, { recursive: true });
|
|
378
|
+
fs.writeFileSync(path.join(asyncDir, "output-0.log"), "OTHER_SESSION_SENTINEL", "utf-8");
|
|
379
|
+
fs.writeFileSync(path.join(asyncDir, "status.json"), JSON.stringify({
|
|
380
|
+
runId: "run-other-session",
|
|
381
|
+
sessionId: "session-other",
|
|
382
|
+
mode: "single",
|
|
383
|
+
state: "running",
|
|
384
|
+
startedAt: 100,
|
|
385
|
+
lastUpdate: 200,
|
|
386
|
+
currentStep: 0,
|
|
387
|
+
steps: [{ agent: "worker", status: "running", startedAt: 100 }],
|
|
388
|
+
}, null, 2), "utf-8");
|
|
389
|
+
const state = {
|
|
390
|
+
currentSessionId: "session-current",
|
|
391
|
+
asyncJobs: new Map(),
|
|
392
|
+
foregroundControls: new Map(),
|
|
393
|
+
} as unknown as SubagentState;
|
|
394
|
+
|
|
395
|
+
const result = inspectSubagentStatus({ id: "run-other-session", view: "transcript" }, {
|
|
396
|
+
asyncDirRoot: asyncRoot,
|
|
397
|
+
resultsDir: path.join(root, "results"),
|
|
398
|
+
state,
|
|
399
|
+
kill: () => true,
|
|
400
|
+
now: () => 250,
|
|
401
|
+
});
|
|
402
|
+
|
|
403
|
+
const text = textContent(result);
|
|
404
|
+
assert.equal(result.isError, true);
|
|
405
|
+
assert.match(text, /owned by the current session/);
|
|
406
|
+
assert.doesNotMatch(text, /OTHER_SESSION_SENTINEL/);
|
|
407
|
+
} finally {
|
|
408
|
+
fs.rmSync(root, { recursive: true, force: true });
|
|
409
|
+
}
|
|
410
|
+
});
|
|
411
|
+
|
|
412
|
+
it("does not fall back to aggregate result output for an explicit completed child index", () => {
|
|
413
|
+
const root = fs.mkdtempSync(path.join(os.tmpdir(), "pi-run-status-result-index-fallback-"));
|
|
414
|
+
try {
|
|
415
|
+
const asyncRoot = path.join(root, "runs");
|
|
416
|
+
const resultsDir = path.join(root, "results");
|
|
417
|
+
fs.mkdirSync(path.join(asyncRoot, "run-result-index-fallback"), { recursive: true });
|
|
418
|
+
fs.mkdirSync(resultsDir, { recursive: true });
|
|
419
|
+
fs.writeFileSync(path.join(resultsDir, "run-result-index-fallback.json"), JSON.stringify({
|
|
420
|
+
id: "run-result-index-fallback",
|
|
421
|
+
success: true,
|
|
422
|
+
summary: "AGGREGATE_SENTINEL",
|
|
423
|
+
results: [
|
|
424
|
+
{ agent: "worker", output: "first child" },
|
|
425
|
+
{ agent: "reviewer" },
|
|
426
|
+
],
|
|
427
|
+
}, null, 2), "utf-8");
|
|
428
|
+
|
|
429
|
+
const result = inspectSubagentStatus({ id: "run-result-index-fallback", view: "transcript", index: 1 }, {
|
|
430
|
+
asyncDirRoot: asyncRoot,
|
|
431
|
+
resultsDir,
|
|
432
|
+
});
|
|
433
|
+
|
|
434
|
+
const text = textContent(result);
|
|
435
|
+
assert.equal(result.isError, undefined);
|
|
436
|
+
assert.match(text, /Child: 1 \(reviewer\)/);
|
|
437
|
+
assert.match(text, /\(no transcript lines available yet\)/);
|
|
438
|
+
assert.doesNotMatch(text, /AGGREGATE_SENTINEL/);
|
|
439
|
+
assert.doesNotMatch(text, /first child/);
|
|
440
|
+
} finally {
|
|
441
|
+
fs.rmSync(root, { recursive: true, force: true });
|
|
442
|
+
}
|
|
443
|
+
});
|
|
444
|
+
|
|
445
|
+
it("surfaces steering counts and timestamps in exact and list status", () => {
|
|
446
|
+
const root = fs.mkdtempSync(path.join(os.tmpdir(), "pi-run-status-steering-"));
|
|
447
|
+
try {
|
|
448
|
+
const asyncRoot = path.join(root, "runs");
|
|
449
|
+
const asyncDir = path.join(asyncRoot, "run-steered");
|
|
450
|
+
fs.mkdirSync(asyncDir, { recursive: true });
|
|
451
|
+
fs.writeFileSync(path.join(asyncDir, "status.json"), JSON.stringify({
|
|
452
|
+
runId: "run-steered",
|
|
453
|
+
mode: "single",
|
|
454
|
+
state: "running",
|
|
455
|
+
pid: 12345,
|
|
456
|
+
startedAt: 100,
|
|
457
|
+
lastUpdate: 200,
|
|
458
|
+
currentStep: 0,
|
|
459
|
+
steerCount: 2,
|
|
460
|
+
lastSteerAt: 150,
|
|
461
|
+
steps: [{ agent: "worker", status: "running", startedAt: 100, steerCount: 2, lastSteerAt: 150 }],
|
|
462
|
+
}, null, 2), "utf-8");
|
|
463
|
+
|
|
464
|
+
const exact = inspectSubagentStatus({ id: "run-steered" }, {
|
|
465
|
+
asyncDirRoot: asyncRoot,
|
|
466
|
+
resultsDir: path.join(root, "results"),
|
|
467
|
+
kill: () => true,
|
|
468
|
+
now: () => 250,
|
|
469
|
+
});
|
|
470
|
+
const exactText = textContent(exact);
|
|
471
|
+
assert.equal(exact.isError, undefined);
|
|
472
|
+
assert.match(exactText, /Steering: 2 steers, last 1970-01-01T00:00:00\.150Z/);
|
|
473
|
+
assert.match(exactText, /Step 1: worker running, steering: 2 steers, last 1970-01-01T00:00:00\.150Z/);
|
|
474
|
+
|
|
475
|
+
const list = inspectSubagentStatus({}, {
|
|
476
|
+
asyncDirRoot: asyncRoot,
|
|
477
|
+
resultsDir: path.join(root, "results"),
|
|
478
|
+
kill: () => true,
|
|
479
|
+
now: () => 250,
|
|
480
|
+
});
|
|
481
|
+
const listText = textContent(list);
|
|
482
|
+
assert.equal(list.isError, undefined);
|
|
483
|
+
assert.match(listText, /2 steers \| last steer 1970-01-01T00:00:00\.150Z/);
|
|
484
|
+
} finally {
|
|
485
|
+
fs.rmSync(root, { recursive: true, force: true });
|
|
486
|
+
}
|
|
487
|
+
});
|
|
488
|
+
|
|
489
|
+
it("shows nested runs under owning steps with exact status hints", () => {
|
|
490
|
+
const root = fs.mkdtempSync(path.join(os.tmpdir(), "pi-run-status-nested-root-"));
|
|
491
|
+
const route = createNestedRoute("run-nested-root");
|
|
492
|
+
try {
|
|
493
|
+
const asyncRoot = path.join(root, "runs");
|
|
494
|
+
const asyncDir = path.join(asyncRoot, "run-nested-root");
|
|
495
|
+
fs.mkdirSync(asyncDir, { recursive: true });
|
|
496
|
+
fs.writeFileSync(path.join(asyncDir, "status.json"), JSON.stringify({
|
|
497
|
+
runId: "run-nested-root",
|
|
498
|
+
mode: "single",
|
|
499
|
+
state: "running",
|
|
500
|
+
pid: 12345,
|
|
501
|
+
startedAt: 100,
|
|
502
|
+
lastUpdate: 100,
|
|
503
|
+
steps: [{ agent: "orchestrator", status: "running", startedAt: 100 }],
|
|
504
|
+
}, null, 2), "utf-8");
|
|
505
|
+
writeNestedEvent(route, {
|
|
506
|
+
type: "subagent.nested.updated",
|
|
507
|
+
ts: 150,
|
|
508
|
+
parentRunId: "run-nested-root",
|
|
509
|
+
parentStepIndex: 0,
|
|
510
|
+
child: {
|
|
511
|
+
id: "nested-status-child",
|
|
512
|
+
parentRunId: "run-nested-root",
|
|
513
|
+
parentStepIndex: 0,
|
|
514
|
+
depth: 1,
|
|
515
|
+
path: [{ runId: "run-nested-root", stepIndex: 0, agent: "orchestrator" }],
|
|
516
|
+
state: "running",
|
|
517
|
+
agent: "reviewer",
|
|
518
|
+
currentTool: "read",
|
|
519
|
+
lastUpdate: 150,
|
|
520
|
+
},
|
|
521
|
+
});
|
|
522
|
+
|
|
523
|
+
const result = inspectSubagentStatus({ id: "run-nested-root" }, {
|
|
524
|
+
asyncDirRoot: asyncRoot,
|
|
525
|
+
resultsDir: path.join(root, "results"),
|
|
526
|
+
kill: () => true,
|
|
527
|
+
now: () => 200,
|
|
528
|
+
});
|
|
529
|
+
|
|
530
|
+
const text = textContent(result);
|
|
531
|
+
assert.equal(result.isError, undefined);
|
|
532
|
+
assert.match(text, /Step 1: orchestrator running/);
|
|
533
|
+
assert.match(text, /↳ reviewer \[nested-status-child\] running \| tool read/);
|
|
534
|
+
assert.match(text, /Status: subagent\(\{ action: "status", id: "nested-status-child" \}\)/);
|
|
535
|
+
} finally {
|
|
536
|
+
fs.rmSync(root, { recursive: true, force: true });
|
|
537
|
+
fs.rmSync(path.dirname(route.eventSink), { recursive: true, force: true });
|
|
538
|
+
}
|
|
539
|
+
});
|
|
540
|
+
|
|
541
|
+
it("repairs stale nested async descendants before rendering root status", () => {
|
|
542
|
+
const root = fs.mkdtempSync(path.join(os.tmpdir(), "pi-run-status-stale-nested-"));
|
|
543
|
+
const route = createNestedRoute("run-stale-nested-root");
|
|
544
|
+
const nestedAsyncDir = path.join(TEMP_ROOT_DIR, "nested-subagent-runs", "run-stale-nested-root", "nested-stale");
|
|
545
|
+
try {
|
|
546
|
+
const asyncRoot = path.join(root, "runs");
|
|
547
|
+
const resultsDir = path.join(root, "results");
|
|
548
|
+
const asyncDir = path.join(asyncRoot, "run-stale-nested-root");
|
|
549
|
+
fs.mkdirSync(asyncDir, { recursive: true });
|
|
550
|
+
fs.mkdirSync(nestedAsyncDir, { recursive: true });
|
|
551
|
+
fs.writeFileSync(path.join(asyncDir, "status.json"), JSON.stringify({
|
|
552
|
+
runId: "run-stale-nested-root",
|
|
553
|
+
mode: "single",
|
|
554
|
+
state: "complete",
|
|
555
|
+
startedAt: 100,
|
|
556
|
+
lastUpdate: 300,
|
|
557
|
+
steps: [{ agent: "orchestrator", status: "complete", startedAt: 100 }],
|
|
558
|
+
}, null, 2), "utf-8");
|
|
559
|
+
fs.writeFileSync(path.join(nestedAsyncDir, "status.json"), JSON.stringify({
|
|
560
|
+
runId: "nested-stale",
|
|
561
|
+
mode: "single",
|
|
562
|
+
state: "running",
|
|
563
|
+
pid: 54321,
|
|
564
|
+
startedAt: 150,
|
|
565
|
+
lastUpdate: 150,
|
|
566
|
+
steps: [{ agent: "reviewer", status: "running", startedAt: 150 }],
|
|
567
|
+
}, null, 2), "utf-8");
|
|
568
|
+
writeNestedEvent(route, {
|
|
569
|
+
type: "subagent.nested.updated",
|
|
570
|
+
ts: 150,
|
|
571
|
+
parentRunId: "run-stale-nested-root",
|
|
572
|
+
parentStepIndex: 0,
|
|
573
|
+
child: {
|
|
574
|
+
id: "nested-stale",
|
|
575
|
+
parentRunId: "run-stale-nested-root",
|
|
576
|
+
parentStepIndex: 0,
|
|
577
|
+
depth: 1,
|
|
578
|
+
path: [{ runId: "run-stale-nested-root", stepIndex: 0 }],
|
|
579
|
+
asyncDir: nestedAsyncDir,
|
|
580
|
+
pid: 54321,
|
|
581
|
+
state: "running",
|
|
582
|
+
agent: "reviewer",
|
|
583
|
+
lastUpdate: 150,
|
|
584
|
+
},
|
|
585
|
+
});
|
|
586
|
+
|
|
587
|
+
const result = inspectSubagentStatus({ id: "run-stale-nested-root" }, {
|
|
588
|
+
asyncDirRoot: asyncRoot,
|
|
589
|
+
resultsDir,
|
|
590
|
+
kill: () => { throw errno("ESRCH"); },
|
|
591
|
+
now: () => 500,
|
|
592
|
+
});
|
|
593
|
+
|
|
594
|
+
const text = textContent(result);
|
|
595
|
+
assert.equal(result.isError, undefined);
|
|
596
|
+
assert.match(text, /↳ reviewer \[nested-stale\] failed/);
|
|
597
|
+
assert.match(text, /1\. reviewer failed \| error: Async runner process 54321 exited or disappeared/);
|
|
598
|
+
assert.ok(fs.existsSync(path.join(resultsDir, "nested", "run-stale-nested-root", "nested-stale.json")));
|
|
599
|
+
} finally {
|
|
600
|
+
fs.rmSync(root, { recursive: true, force: true });
|
|
601
|
+
fs.rmSync(path.dirname(route.eventSink), { recursive: true, force: true });
|
|
602
|
+
fs.rmSync(nestedAsyncDir, { recursive: true, force: true });
|
|
603
|
+
}
|
|
604
|
+
});
|
|
605
|
+
|
|
606
|
+
it("shows a warning when nested projection fails for detailed status", () => {
|
|
607
|
+
const root = fs.mkdtempSync(path.join(os.tmpdir(), "pi-run-status-nested-warning-"));
|
|
608
|
+
const route = createNestedRoute("run-nested-warning");
|
|
609
|
+
try {
|
|
610
|
+
const asyncRoot = path.join(root, "runs");
|
|
611
|
+
const resultsDir = path.join(root, "results");
|
|
612
|
+
const asyncDir = path.join(asyncRoot, "run-nested-warning");
|
|
613
|
+
fs.mkdirSync(asyncDir, { recursive: true });
|
|
614
|
+
fs.writeFileSync(path.join(path.dirname(route.eventSink), "registry.json"), "{", "utf-8");
|
|
615
|
+
fs.writeFileSync(path.join(asyncDir, "status.json"), JSON.stringify({
|
|
616
|
+
runId: "run-nested-warning",
|
|
617
|
+
mode: "single",
|
|
618
|
+
state: "running",
|
|
619
|
+
pid: 12345,
|
|
620
|
+
startedAt: 100,
|
|
621
|
+
lastUpdate: 100,
|
|
622
|
+
steps: [{ agent: "orchestrator", status: "running", startedAt: 100 }],
|
|
623
|
+
}, null, 2), "utf-8");
|
|
624
|
+
|
|
625
|
+
const result = inspectSubagentStatus({ id: "run-nested-warning" }, { asyncDirRoot: asyncRoot, resultsDir });
|
|
626
|
+
|
|
627
|
+
assert.equal(result.isError, undefined);
|
|
628
|
+
assert.match(textContent(result), /Warning: Nested status unavailable:/);
|
|
629
|
+
} finally {
|
|
630
|
+
fs.rmSync(root, { recursive: true, force: true });
|
|
631
|
+
fs.rmSync(path.dirname(route.eventSink), { recursive: true, force: true });
|
|
632
|
+
}
|
|
633
|
+
});
|
|
634
|
+
|
|
635
|
+
it("shows a warning when nested projection fails for active status lists", () => {
|
|
636
|
+
const root = fs.mkdtempSync(path.join(os.tmpdir(), "pi-run-status-nested-list-warning-"));
|
|
637
|
+
const route = createNestedRoute("run-nested-list-warning");
|
|
638
|
+
try {
|
|
639
|
+
const asyncRoot = path.join(root, "runs");
|
|
640
|
+
const resultsDir = path.join(root, "results");
|
|
641
|
+
const asyncDir = path.join(asyncRoot, "run-nested-list-warning");
|
|
642
|
+
fs.mkdirSync(asyncDir, { recursive: true });
|
|
643
|
+
fs.writeFileSync(path.join(path.dirname(route.eventSink), "registry.json"), "{", "utf-8");
|
|
644
|
+
fs.writeFileSync(path.join(asyncDir, "status.json"), JSON.stringify({
|
|
645
|
+
runId: "run-nested-list-warning",
|
|
646
|
+
mode: "single",
|
|
647
|
+
state: "running",
|
|
648
|
+
pid: 12345,
|
|
649
|
+
startedAt: 100,
|
|
650
|
+
lastUpdate: 100,
|
|
651
|
+
steps: [{ agent: "orchestrator", status: "running", startedAt: 100 }],
|
|
652
|
+
}, null, 2), "utf-8");
|
|
653
|
+
|
|
654
|
+
const result = inspectSubagentStatus({}, { asyncDirRoot: asyncRoot, resultsDir, kill: () => true, now: () => 200 });
|
|
655
|
+
|
|
656
|
+
assert.equal(result.isError, undefined);
|
|
657
|
+
assert.match(textContent(result), /Warning: Nested status unavailable:/);
|
|
658
|
+
} finally {
|
|
659
|
+
fs.rmSync(root, { recursive: true, force: true });
|
|
660
|
+
fs.rmSync(path.dirname(route.eventSink), { recursive: true, force: true });
|
|
661
|
+
}
|
|
662
|
+
});
|
|
663
|
+
|
|
664
|
+
it("resolves exact nested run ids from the nested registry", () => {
|
|
665
|
+
const root = fs.mkdtempSync(path.join(os.tmpdir(), "pi-run-status-nested-exact-"));
|
|
666
|
+
const route = createNestedRoute("run-nested-exact-root");
|
|
667
|
+
try {
|
|
668
|
+
writeNestedEvent(route, {
|
|
669
|
+
type: "subagent.nested.updated",
|
|
670
|
+
ts: 150,
|
|
671
|
+
parentRunId: "run-nested-exact-root",
|
|
672
|
+
parentStepIndex: 0,
|
|
673
|
+
child: {
|
|
674
|
+
id: "nested-exact-child",
|
|
675
|
+
parentRunId: "run-nested-exact-root",
|
|
676
|
+
parentStepIndex: 0,
|
|
677
|
+
depth: 1,
|
|
678
|
+
path: [{ runId: "run-nested-exact-root", stepIndex: 0, agent: "orchestrator" }],
|
|
679
|
+
state: "running",
|
|
680
|
+
mode: "single",
|
|
681
|
+
agent: "validator",
|
|
682
|
+
steps: [{ agent: "leaf", status: "running", currentTool: "grep" }],
|
|
683
|
+
lastUpdate: 150,
|
|
684
|
+
},
|
|
685
|
+
});
|
|
686
|
+
|
|
687
|
+
const result = inspectSubagentStatus({ id: "nested-exact-child" }, {
|
|
688
|
+
asyncDirRoot: path.join(root, "runs"),
|
|
689
|
+
resultsDir: path.join(root, "results"),
|
|
690
|
+
});
|
|
691
|
+
|
|
692
|
+
const text = textContent(result);
|
|
693
|
+
assert.equal(result.isError, undefined);
|
|
694
|
+
assert.match(text, /Nested run: nested-exact-child/);
|
|
695
|
+
assert.match(text, /Root: run-nested-exact-root/);
|
|
696
|
+
assert.match(text, /Agent: validator/);
|
|
697
|
+
assert.match(text, /1\. leaf running/);
|
|
698
|
+
assert.match(text, /Root status: subagent\(\{ action: "status", id: "run-nested-exact-root" \}\)/);
|
|
699
|
+
assert.match(text, /Interrupt: subagent\(\{ action: "interrupt", id: "nested-exact-child" \}\)/);
|
|
700
|
+
assert.match(text, /Resume: subagent\(\{ action: "resume", id: "nested-exact-child", message: "\.\.\." \}\)/);
|
|
701
|
+
} finally {
|
|
702
|
+
fs.rmSync(root, { recursive: true, force: true });
|
|
703
|
+
fs.rmSync(path.dirname(route.eventSink), { recursive: true, force: true });
|
|
704
|
+
}
|
|
705
|
+
});
|
|
706
|
+
|
|
707
|
+
it("shows indexed revive guidance for completed multi-child async runs with child sessions", () => {
|
|
708
|
+
const root = fs.mkdtempSync(path.join(os.tmpdir(), "pi-run-status-multi-resume-"));
|
|
709
|
+
try {
|
|
710
|
+
const asyncRoot = path.join(root, "runs");
|
|
711
|
+
const asyncDir = path.join(asyncRoot, "run-multi");
|
|
712
|
+
const firstSession = path.join(root, "a.jsonl");
|
|
713
|
+
const secondSession = path.join(root, "b.jsonl");
|
|
714
|
+
fs.mkdirSync(asyncDir, { recursive: true });
|
|
715
|
+
fs.writeFileSync(firstSession, "", "utf-8");
|
|
716
|
+
fs.writeFileSync(secondSession, "", "utf-8");
|
|
717
|
+
fs.writeFileSync(path.join(asyncDir, "status.json"), JSON.stringify({
|
|
718
|
+
runId: "run-multi",
|
|
719
|
+
mode: "parallel",
|
|
720
|
+
state: "complete",
|
|
721
|
+
startedAt: 100,
|
|
722
|
+
lastUpdate: 200,
|
|
723
|
+
steps: [
|
|
724
|
+
{ agent: "a", status: "complete", sessionFile: firstSession },
|
|
725
|
+
{ agent: "b", status: "complete", sessionFile: secondSession },
|
|
726
|
+
],
|
|
727
|
+
}, null, 2), "utf-8");
|
|
728
|
+
|
|
729
|
+
const result = inspectSubagentStatus({ id: "run-multi" }, {
|
|
730
|
+
asyncDirRoot: asyncRoot,
|
|
731
|
+
resultsDir: path.join(root, "results"),
|
|
732
|
+
});
|
|
733
|
+
|
|
734
|
+
const text = textContent(result);
|
|
735
|
+
assert.match(text, /Revive child: subagent\(\{ action: "resume", id: "run-multi", index: 0, message: "\.\.\." \}\)/);
|
|
736
|
+
assert.doesNotMatch(text, /unsupported for multi-child/);
|
|
737
|
+
} finally {
|
|
738
|
+
fs.rmSync(root, { recursive: true, force: true });
|
|
739
|
+
}
|
|
740
|
+
});
|
|
741
|
+
|
|
742
|
+
it("uses original child indexes when result metadata contains invalid children", () => {
|
|
743
|
+
const root = fs.mkdtempSync(path.join(os.tmpdir(), "pi-run-status-original-index-"));
|
|
744
|
+
try {
|
|
745
|
+
const asyncRoot = path.join(root, "runs");
|
|
746
|
+
const resultsDir = path.join(root, "results");
|
|
747
|
+
const sessionFile = path.join(root, "b.jsonl");
|
|
748
|
+
fs.mkdirSync(resultsDir, { recursive: true });
|
|
749
|
+
fs.writeFileSync(sessionFile, "", "utf-8");
|
|
750
|
+
fs.writeFileSync(path.join(resultsDir, "run-result-index.json"), JSON.stringify({
|
|
751
|
+
id: "run-result-index",
|
|
752
|
+
success: false,
|
|
753
|
+
state: "failed",
|
|
754
|
+
results: [
|
|
755
|
+
{ output: "missing agent", sessionFile: path.join(root, "a.jsonl") },
|
|
756
|
+
{ agent: "b", success: false, sessionFile },
|
|
757
|
+
],
|
|
758
|
+
}, null, 2), "utf-8");
|
|
759
|
+
|
|
760
|
+
const result = inspectSubagentStatus({ id: "run-result-index" }, { asyncDirRoot: asyncRoot, resultsDir });
|
|
761
|
+
|
|
762
|
+
const text = textContent(result);
|
|
763
|
+
assert.match(text, /Revive child: subagent\(\{ action: "resume", id: "run-result-index", index: 1, message: "\.\.\." \}\)/);
|
|
764
|
+
} finally {
|
|
765
|
+
fs.rmSync(root, { recursive: true, force: true });
|
|
766
|
+
}
|
|
767
|
+
});
|
|
768
|
+
|
|
769
|
+
it("labels chain parallel group children with logical step and agent numbers", () => {
|
|
770
|
+
const root = fs.mkdtempSync(path.join(os.tmpdir(), "pi-run-status-chain-parallel-"));
|
|
771
|
+
try {
|
|
772
|
+
const asyncRoot = path.join(root, "runs");
|
|
773
|
+
const asyncDir = path.join(asyncRoot, "run-chain");
|
|
774
|
+
fs.mkdirSync(asyncDir, { recursive: true });
|
|
775
|
+
fs.writeFileSync(path.join(asyncDir, "status.json"), JSON.stringify({
|
|
776
|
+
runId: "run-chain",
|
|
777
|
+
mode: "chain",
|
|
778
|
+
state: "running",
|
|
779
|
+
pid: 12345,
|
|
780
|
+
startedAt: 100,
|
|
781
|
+
lastUpdate: 100,
|
|
782
|
+
currentStep: 1,
|
|
783
|
+
chainStepCount: 3,
|
|
784
|
+
parallelGroups: [{ start: 1, count: 2, stepIndex: 1 }],
|
|
785
|
+
steps: [
|
|
786
|
+
{ agent: "scout", status: "complete", startedAt: 100 },
|
|
787
|
+
{ agent: "reviewer", status: "running", startedAt: 100 },
|
|
788
|
+
{ agent: "auditor", status: "pending" },
|
|
789
|
+
{ agent: "writer", status: "pending" },
|
|
790
|
+
],
|
|
791
|
+
}, null, 2), "utf-8");
|
|
792
|
+
|
|
793
|
+
const result = inspectSubagentStatus({ id: "run-chain" }, {
|
|
794
|
+
asyncDirRoot: asyncRoot,
|
|
795
|
+
resultsDir: path.join(root, "results"),
|
|
796
|
+
kill: () => true,
|
|
797
|
+
now: () => 200,
|
|
798
|
+
});
|
|
799
|
+
|
|
800
|
+
const text = textContent(result);
|
|
801
|
+
assert.match(text, /Step 1\/3: scout complete/);
|
|
802
|
+
assert.match(text, /Step 2\/3 Agent 1\/2: reviewer running/);
|
|
803
|
+
assert.match(text, /Step 2\/3 Agent 2\/2: auditor pending/);
|
|
804
|
+
assert.match(text, /Step 3\/3: writer pending/);
|
|
805
|
+
} finally {
|
|
806
|
+
fs.rmSync(root, { recursive: true, force: true });
|
|
807
|
+
}
|
|
808
|
+
});
|
|
809
|
+
|
|
810
|
+
it("shows expected intercom target for still-running async steps", () => {
|
|
811
|
+
const root = fs.mkdtempSync(path.join(os.tmpdir(), "pi-run-status-intercom-"));
|
|
812
|
+
try {
|
|
813
|
+
const asyncRoot = path.join(root, "runs");
|
|
814
|
+
const asyncDir = path.join(asyncRoot, "run-live");
|
|
815
|
+
fs.mkdirSync(asyncDir, { recursive: true });
|
|
816
|
+
fs.writeFileSync(path.join(asyncDir, "status.json"), JSON.stringify({
|
|
817
|
+
runId: "run-live",
|
|
818
|
+
mode: "single",
|
|
819
|
+
state: "running",
|
|
820
|
+
pid: 12345,
|
|
821
|
+
startedAt: 100,
|
|
822
|
+
lastUpdate: 100,
|
|
823
|
+
steps: [{ agent: "scout", status: "running", startedAt: 100 }],
|
|
824
|
+
}, null, 2), "utf-8");
|
|
825
|
+
|
|
826
|
+
const result = inspectSubagentStatus({ id: "run-live" }, {
|
|
827
|
+
asyncDirRoot: asyncRoot,
|
|
828
|
+
resultsDir: path.join(root, "results"),
|
|
829
|
+
kill: () => true,
|
|
830
|
+
now: () => 200,
|
|
831
|
+
});
|
|
832
|
+
|
|
833
|
+
const text = textContent(result);
|
|
834
|
+
assert.match(text, /Step 1: scout running/);
|
|
835
|
+
assert.match(text, /Intercom target: subagent-scout-run-live-1 \(if registered\)/);
|
|
836
|
+
} finally {
|
|
837
|
+
fs.rmSync(root, { recursive: true, force: true });
|
|
838
|
+
}
|
|
839
|
+
});
|
|
840
|
+
|
|
841
|
+
it("rejects ambiguous async run id prefixes", () => {
|
|
842
|
+
const root = fs.mkdtempSync(path.join(os.tmpdir(), "pi-run-status-ambiguous-"));
|
|
843
|
+
try {
|
|
844
|
+
const asyncRoot = path.join(root, "runs");
|
|
845
|
+
fs.mkdirSync(path.join(asyncRoot, "run-aa"), { recursive: true });
|
|
846
|
+
fs.mkdirSync(path.join(asyncRoot, "run-ab"), { recursive: true });
|
|
847
|
+
|
|
848
|
+
const result = inspectSubagentStatus({ id: "run-a" }, {
|
|
849
|
+
asyncDirRoot: asyncRoot,
|
|
850
|
+
resultsDir: path.join(root, "results"),
|
|
851
|
+
});
|
|
852
|
+
|
|
853
|
+
assert.equal(result.isError, true);
|
|
854
|
+
assert.match(textContent(result), /Ambiguous subagent run id prefix 'run-a' matched: async:run-aa, async:run-ab/);
|
|
855
|
+
} finally {
|
|
856
|
+
fs.rmSync(root, { recursive: true, force: true });
|
|
857
|
+
}
|
|
858
|
+
});
|
|
859
|
+
|
|
860
|
+
it("rejects path-like async run ids", () => {
|
|
861
|
+
const root = fs.mkdtempSync(path.join(os.tmpdir(), "pi-run-status-paths-"));
|
|
862
|
+
try {
|
|
863
|
+
const result = inspectSubagentStatus({ id: "../run" }, {
|
|
864
|
+
asyncDirRoot: path.join(root, "runs"),
|
|
865
|
+
resultsDir: path.join(root, "results"),
|
|
866
|
+
});
|
|
867
|
+
|
|
868
|
+
assert.equal(result.isError, true);
|
|
869
|
+
assert.match(textContent(result), /id must be a non-empty safe id token/);
|
|
870
|
+
} finally {
|
|
871
|
+
fs.rmSync(root, { recursive: true, force: true });
|
|
872
|
+
}
|
|
873
|
+
});
|
|
874
|
+
|
|
875
|
+
it("does not advertise revive for result fallback with only a top-level session file", () => {
|
|
876
|
+
const root = fs.mkdtempSync(path.join(os.tmpdir(), "pi-run-status-result-no-child-"));
|
|
877
|
+
try {
|
|
878
|
+
const asyncRoot = path.join(root, "runs");
|
|
879
|
+
const resultsDir = path.join(root, "results");
|
|
880
|
+
fs.mkdirSync(path.join(asyncRoot, "run-session-only"), { recursive: true });
|
|
881
|
+
fs.mkdirSync(resultsDir, { recursive: true });
|
|
882
|
+
const sessionFile = path.join(root, "session.jsonl");
|
|
883
|
+
fs.writeFileSync(sessionFile, "", "utf-8");
|
|
884
|
+
fs.writeFileSync(path.join(resultsDir, "run-session-only.json"), JSON.stringify({
|
|
885
|
+
id: "run-session-only",
|
|
886
|
+
success: false,
|
|
887
|
+
state: "failed",
|
|
888
|
+
sessionFile,
|
|
889
|
+
summary: "missing child metadata",
|
|
890
|
+
}, null, 2), "utf-8");
|
|
891
|
+
|
|
892
|
+
const result = inspectSubagentStatus({ id: "run-session-only" }, {
|
|
893
|
+
asyncDirRoot: asyncRoot,
|
|
894
|
+
resultsDir,
|
|
895
|
+
});
|
|
896
|
+
|
|
897
|
+
const text = textContent(result);
|
|
898
|
+
assert.equal(result.isError, undefined);
|
|
899
|
+
assert.match(text, /Resume: unavailable/);
|
|
900
|
+
assert.doesNotMatch(text, /Revive:/);
|
|
901
|
+
} finally {
|
|
902
|
+
fs.rmSync(root, { recursive: true, force: true });
|
|
903
|
+
}
|
|
904
|
+
});
|
|
905
|
+
|
|
906
|
+
it("treats a top-level completed result as one transcript child", () => {
|
|
907
|
+
const root = fs.mkdtempSync(path.join(os.tmpdir(), "pi-run-status-result-transcript-"));
|
|
908
|
+
try {
|
|
909
|
+
const asyncRoot = path.join(root, "runs");
|
|
910
|
+
const resultsDir = path.join(root, "results");
|
|
911
|
+
fs.mkdirSync(path.join(asyncRoot, "run-result-transcript"), { recursive: true });
|
|
912
|
+
fs.mkdirSync(resultsDir, { recursive: true });
|
|
913
|
+
const sessionFile = path.join(root, "session.jsonl");
|
|
914
|
+
fs.writeFileSync(sessionFile, "", "utf-8");
|
|
915
|
+
fs.writeFileSync(path.join(resultsDir, "run-result-transcript.json"), JSON.stringify({
|
|
916
|
+
id: "run-result-transcript",
|
|
917
|
+
agent: "worker",
|
|
918
|
+
success: false,
|
|
919
|
+
state: "failed",
|
|
920
|
+
sessionFile,
|
|
921
|
+
summary: "legacy result transcript",
|
|
922
|
+
}, null, 2), "utf-8");
|
|
923
|
+
|
|
924
|
+
const result = inspectSubagentStatus({ id: "run-result-transcript", view: "transcript", index: 0 }, {
|
|
925
|
+
asyncDirRoot: asyncRoot,
|
|
926
|
+
resultsDir,
|
|
927
|
+
});
|
|
928
|
+
|
|
929
|
+
const text = textContent(result);
|
|
930
|
+
assert.equal(result.isError, undefined);
|
|
931
|
+
assert.match(text, /Child: 0 \(worker\)/);
|
|
932
|
+
assert.match(text, /legacy result transcript/);
|
|
933
|
+
} finally {
|
|
934
|
+
fs.rmSync(root, { recursive: true, force: true });
|
|
935
|
+
}
|
|
936
|
+
});
|
|
937
|
+
|
|
938
|
+
it("validates completed result transcript indexes as integers", () => {
|
|
939
|
+
const root = fs.mkdtempSync(path.join(os.tmpdir(), "pi-run-status-result-transcript-index-"));
|
|
940
|
+
try {
|
|
941
|
+
const asyncRoot = path.join(root, "runs");
|
|
942
|
+
const resultsDir = path.join(root, "results");
|
|
943
|
+
fs.mkdirSync(path.join(asyncRoot, "run-result-index-validation"), { recursive: true });
|
|
944
|
+
fs.mkdirSync(resultsDir, { recursive: true });
|
|
945
|
+
fs.writeFileSync(path.join(resultsDir, "run-result-index-validation.json"), JSON.stringify({
|
|
946
|
+
id: "run-result-index-validation",
|
|
947
|
+
agent: "worker",
|
|
948
|
+
success: true,
|
|
949
|
+
summary: "done",
|
|
950
|
+
}, null, 2), "utf-8");
|
|
951
|
+
|
|
952
|
+
const result = inspectSubagentStatus({ id: "run-result-index-validation", view: "transcript", index: 0.5 }, {
|
|
953
|
+
asyncDirRoot: asyncRoot,
|
|
954
|
+
resultsDir,
|
|
955
|
+
});
|
|
956
|
+
|
|
957
|
+
assert.equal(result.isError, true);
|
|
958
|
+
assert.match(textContent(result), /Transcript index must be an integer/);
|
|
959
|
+
} finally {
|
|
960
|
+
fs.rmSync(root, { recursive: true, force: true });
|
|
961
|
+
}
|
|
962
|
+
});
|
|
963
|
+
|
|
964
|
+
it("falls back to an existing result when async dir has no status file", () => {
|
|
965
|
+
const root = fs.mkdtempSync(path.join(os.tmpdir(), "pi-run-status-result-fallback-"));
|
|
966
|
+
try {
|
|
967
|
+
const asyncRoot = path.join(root, "runs");
|
|
968
|
+
const resultsDir = path.join(root, "results");
|
|
969
|
+
fs.mkdirSync(path.join(asyncRoot, "run-result-only"), { recursive: true });
|
|
970
|
+
fs.mkdirSync(resultsDir, { recursive: true });
|
|
971
|
+
const sessionFile = path.join(root, "session.jsonl");
|
|
972
|
+
fs.writeFileSync(sessionFile, "", "utf-8");
|
|
973
|
+
fs.writeFileSync(path.join(resultsDir, "run-result-only.json"), JSON.stringify({
|
|
974
|
+
id: "run-result-only",
|
|
975
|
+
agent: "worker",
|
|
976
|
+
success: false,
|
|
977
|
+
state: "failed",
|
|
978
|
+
sessionFile,
|
|
979
|
+
summary: "result survived missing status",
|
|
980
|
+
}, null, 2), "utf-8");
|
|
981
|
+
|
|
982
|
+
const result = inspectSubagentStatus({ id: "run-result-only" }, {
|
|
983
|
+
asyncDirRoot: asyncRoot,
|
|
984
|
+
resultsDir,
|
|
985
|
+
});
|
|
986
|
+
|
|
987
|
+
const text = textContent(result);
|
|
988
|
+
assert.equal(result.isError, undefined);
|
|
989
|
+
assert.match(text, /State: failed/);
|
|
990
|
+
assert.match(text, /Result: /);
|
|
991
|
+
assert.match(text, /Revive: subagent\(\{ action: "resume", id: "run-result-only", message: "\.\.\." \}\)/);
|
|
992
|
+
assert.match(text, /result survived missing status/);
|
|
993
|
+
} finally {
|
|
994
|
+
fs.rmSync(root, { recursive: true, force: true });
|
|
995
|
+
}
|
|
996
|
+
});
|
|
997
|
+
});
|