@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,257 @@
|
|
|
1
|
+
import { describe, it, beforeEach, afterEach } from "node:test";
|
|
2
|
+
import assert from "node:assert/strict";
|
|
3
|
+
import {
|
|
4
|
+
checkSubagentDepth,
|
|
5
|
+
getSubagentDepthEnv,
|
|
6
|
+
DEFAULT_SUBAGENT_MAX_DEPTH,
|
|
7
|
+
DEFAULT_MAX_SUBAGENT_SPAWNS_PER_SESSION,
|
|
8
|
+
normalizeMaxSubagentDepth,
|
|
9
|
+
normalizeMaxSubagentSpawnsPerSession,
|
|
10
|
+
resolveMaxSubagentSpawnsPerSession,
|
|
11
|
+
resolveTopLevelParallelConcurrency,
|
|
12
|
+
resolveTopLevelParallelMaxTasks,
|
|
13
|
+
resolveChildMaxSubagentDepth,
|
|
14
|
+
resolveCurrentMaxSubagentDepth,
|
|
15
|
+
} from "../../src/shared/types.ts";
|
|
16
|
+
|
|
17
|
+
let savedDepth: string | undefined;
|
|
18
|
+
let savedMaxDepth: string | undefined;
|
|
19
|
+
let savedMaxSpawns: string | undefined;
|
|
20
|
+
|
|
21
|
+
beforeEach(() => {
|
|
22
|
+
savedDepth = process.env.SELESAI_SUBAGENT_DEPTH;
|
|
23
|
+
savedMaxDepth = process.env.SELESAI_SUBAGENT_MAX_DEPTH;
|
|
24
|
+
savedMaxSpawns = process.env.SELESAI_SUBAGENT_MAX_SPAWNS_PER_SESSION;
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
afterEach(() => {
|
|
28
|
+
if (savedDepth === undefined) delete process.env.SELESAI_SUBAGENT_DEPTH;
|
|
29
|
+
else process.env.SELESAI_SUBAGENT_DEPTH = savedDepth;
|
|
30
|
+
if (savedMaxDepth === undefined) delete process.env.SELESAI_SUBAGENT_MAX_DEPTH;
|
|
31
|
+
else process.env.SELESAI_SUBAGENT_MAX_DEPTH = savedMaxDepth;
|
|
32
|
+
if (savedMaxSpawns === undefined) delete process.env.SELESAI_SUBAGENT_MAX_SPAWNS_PER_SESSION;
|
|
33
|
+
else process.env.SELESAI_SUBAGENT_MAX_SPAWNS_PER_SESSION = savedMaxSpawns;
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
describe("DEFAULT_SUBAGENT_MAX_DEPTH", () => {
|
|
37
|
+
it("is 2", () => {
|
|
38
|
+
assert.equal(DEFAULT_SUBAGENT_MAX_DEPTH, 2);
|
|
39
|
+
});
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
describe("DEFAULT_MAX_SUBAGENT_SPAWNS_PER_SESSION", () => {
|
|
43
|
+
it("is 40", () => {
|
|
44
|
+
assert.equal(DEFAULT_MAX_SUBAGENT_SPAWNS_PER_SESSION, 40);
|
|
45
|
+
});
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
describe("normalizeMaxSubagentDepth", () => {
|
|
49
|
+
it("accepts integers >= 0", () => {
|
|
50
|
+
assert.equal(normalizeMaxSubagentDepth(0), 0);
|
|
51
|
+
assert.equal(normalizeMaxSubagentDepth(3), 3);
|
|
52
|
+
assert.equal(normalizeMaxSubagentDepth("4"), 4);
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
it("rejects negatives and non-integers", () => {
|
|
56
|
+
assert.equal(normalizeMaxSubagentDepth(-1), undefined);
|
|
57
|
+
assert.equal(normalizeMaxSubagentDepth(1.5), undefined);
|
|
58
|
+
assert.equal(normalizeMaxSubagentDepth("garbage"), undefined);
|
|
59
|
+
});
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
describe("normalizeMaxSubagentSpawnsPerSession", () => {
|
|
63
|
+
it("accepts integers >= 0", () => {
|
|
64
|
+
assert.equal(normalizeMaxSubagentSpawnsPerSession(0), 0);
|
|
65
|
+
assert.equal(normalizeMaxSubagentSpawnsPerSession(12), 12);
|
|
66
|
+
assert.equal(normalizeMaxSubagentSpawnsPerSession("9"), 9);
|
|
67
|
+
});
|
|
68
|
+
|
|
69
|
+
it("rejects negatives and non-integers", () => {
|
|
70
|
+
assert.equal(normalizeMaxSubagentSpawnsPerSession(-1), undefined);
|
|
71
|
+
assert.equal(normalizeMaxSubagentSpawnsPerSession(1.5), undefined);
|
|
72
|
+
assert.equal(normalizeMaxSubagentSpawnsPerSession("garbage"), undefined);
|
|
73
|
+
});
|
|
74
|
+
});
|
|
75
|
+
|
|
76
|
+
describe("resolveMaxSubagentSpawnsPerSession", () => {
|
|
77
|
+
it("uses env when present", () => {
|
|
78
|
+
process.env.SELESAI_SUBAGENT_MAX_SPAWNS_PER_SESSION = "5";
|
|
79
|
+
assert.equal(resolveMaxSubagentSpawnsPerSession(1), 5);
|
|
80
|
+
});
|
|
81
|
+
|
|
82
|
+
it("falls back to config when env is absent", () => {
|
|
83
|
+
delete process.env.SELESAI_SUBAGENT_MAX_SPAWNS_PER_SESSION;
|
|
84
|
+
assert.equal(resolveMaxSubagentSpawnsPerSession(7), 7);
|
|
85
|
+
});
|
|
86
|
+
|
|
87
|
+
it("falls back to default when neither env nor config is valid", () => {
|
|
88
|
+
delete process.env.SELESAI_SUBAGENT_MAX_SPAWNS_PER_SESSION;
|
|
89
|
+
assert.equal(resolveMaxSubagentSpawnsPerSession(undefined), 40);
|
|
90
|
+
assert.equal(resolveMaxSubagentSpawnsPerSession(-1), 40);
|
|
91
|
+
});
|
|
92
|
+
});
|
|
93
|
+
|
|
94
|
+
describe("resolveCurrentMaxSubagentDepth", () => {
|
|
95
|
+
it("uses env when present", () => {
|
|
96
|
+
process.env.SELESAI_SUBAGENT_MAX_DEPTH = "5";
|
|
97
|
+
assert.equal(resolveCurrentMaxSubagentDepth(1), 5);
|
|
98
|
+
});
|
|
99
|
+
|
|
100
|
+
it("falls back to config when env is absent", () => {
|
|
101
|
+
delete process.env.SELESAI_SUBAGENT_MAX_DEPTH;
|
|
102
|
+
assert.equal(resolveCurrentMaxSubagentDepth(1), 1);
|
|
103
|
+
});
|
|
104
|
+
|
|
105
|
+
it("falls back to default when neither env nor config is valid", () => {
|
|
106
|
+
delete process.env.SELESAI_SUBAGENT_MAX_DEPTH;
|
|
107
|
+
assert.equal(resolveCurrentMaxSubagentDepth(undefined), 2);
|
|
108
|
+
assert.equal(resolveCurrentMaxSubagentDepth(-1), 2);
|
|
109
|
+
});
|
|
110
|
+
});
|
|
111
|
+
|
|
112
|
+
describe("top-level parallel config helpers", () => {
|
|
113
|
+
it("resolves maxTasks from config or falls back to the default", () => {
|
|
114
|
+
assert.equal(resolveTopLevelParallelMaxTasks(12), 12);
|
|
115
|
+
assert.equal(resolveTopLevelParallelMaxTasks(undefined), 8);
|
|
116
|
+
assert.equal(resolveTopLevelParallelMaxTasks(0), 8);
|
|
117
|
+
assert.equal(resolveTopLevelParallelMaxTasks("oops"), 8);
|
|
118
|
+
});
|
|
119
|
+
|
|
120
|
+
it("resolves concurrency from per-call override, config, or default", () => {
|
|
121
|
+
assert.equal(resolveTopLevelParallelConcurrency(2, 6), 2);
|
|
122
|
+
assert.equal(resolveTopLevelParallelConcurrency(undefined, 6), 6);
|
|
123
|
+
assert.equal(resolveTopLevelParallelConcurrency(0, 6), 6);
|
|
124
|
+
assert.equal(resolveTopLevelParallelConcurrency(undefined, 0), 4);
|
|
125
|
+
});
|
|
126
|
+
});
|
|
127
|
+
|
|
128
|
+
describe("resolveChildMaxSubagentDepth", () => {
|
|
129
|
+
it("keeps the inherited max when agent override is absent", () => {
|
|
130
|
+
assert.equal(resolveChildMaxSubagentDepth(3, undefined), 3);
|
|
131
|
+
});
|
|
132
|
+
|
|
133
|
+
it("tightens to the lower per-agent max", () => {
|
|
134
|
+
assert.equal(resolveChildMaxSubagentDepth(3, 1), 1);
|
|
135
|
+
assert.equal(resolveChildMaxSubagentDepth(2, 0), 0);
|
|
136
|
+
});
|
|
137
|
+
|
|
138
|
+
it("does not relax an already stricter inherited max", () => {
|
|
139
|
+
assert.equal(resolveChildMaxSubagentDepth(1, 3), 1);
|
|
140
|
+
});
|
|
141
|
+
});
|
|
142
|
+
|
|
143
|
+
describe("checkSubagentDepth", () => {
|
|
144
|
+
it("not blocked at depth=0, max=2", () => {
|
|
145
|
+
process.env.SELESAI_SUBAGENT_DEPTH = "0";
|
|
146
|
+
process.env.SELESAI_SUBAGENT_MAX_DEPTH = "2";
|
|
147
|
+
const result = checkSubagentDepth();
|
|
148
|
+
assert.equal(result.blocked, false);
|
|
149
|
+
assert.equal(result.depth, 0);
|
|
150
|
+
assert.equal(result.maxDepth, 2);
|
|
151
|
+
});
|
|
152
|
+
|
|
153
|
+
it("uses config max depth when env is absent", () => {
|
|
154
|
+
process.env.SELESAI_SUBAGENT_DEPTH = "1";
|
|
155
|
+
delete process.env.SELESAI_SUBAGENT_MAX_DEPTH;
|
|
156
|
+
const result = checkSubagentDepth(1);
|
|
157
|
+
assert.equal(result.blocked, true);
|
|
158
|
+
assert.equal(result.maxDepth, 1);
|
|
159
|
+
});
|
|
160
|
+
|
|
161
|
+
it("not blocked at depth=1, max=2", () => {
|
|
162
|
+
process.env.SELESAI_SUBAGENT_DEPTH = "1";
|
|
163
|
+
process.env.SELESAI_SUBAGENT_MAX_DEPTH = "2";
|
|
164
|
+
assert.equal(checkSubagentDepth().blocked, false);
|
|
165
|
+
});
|
|
166
|
+
|
|
167
|
+
it("blocks at depth=1, max=1 after one nested level", () => {
|
|
168
|
+
process.env.SELESAI_SUBAGENT_DEPTH = "1";
|
|
169
|
+
process.env.SELESAI_SUBAGENT_MAX_DEPTH = "1";
|
|
170
|
+
assert.equal(checkSubagentDepth().blocked, true);
|
|
171
|
+
});
|
|
172
|
+
|
|
173
|
+
it("blocked at depth=2, max=2", () => {
|
|
174
|
+
process.env.SELESAI_SUBAGENT_DEPTH = "2";
|
|
175
|
+
process.env.SELESAI_SUBAGENT_MAX_DEPTH = "2";
|
|
176
|
+
const result = checkSubagentDepth();
|
|
177
|
+
assert.equal(result.blocked, true);
|
|
178
|
+
assert.equal(result.depth, 2);
|
|
179
|
+
assert.equal(result.maxDepth, 2);
|
|
180
|
+
});
|
|
181
|
+
|
|
182
|
+
it("blocked at depth=3, max=2", () => {
|
|
183
|
+
process.env.SELESAI_SUBAGENT_DEPTH = "3";
|
|
184
|
+
process.env.SELESAI_SUBAGENT_MAX_DEPTH = "2";
|
|
185
|
+
assert.equal(checkSubagentDepth().blocked, true);
|
|
186
|
+
});
|
|
187
|
+
|
|
188
|
+
it("blocked at depth=0, max=0 (disables subagent entirely)", () => {
|
|
189
|
+
process.env.SELESAI_SUBAGENT_DEPTH = "0";
|
|
190
|
+
process.env.SELESAI_SUBAGENT_MAX_DEPTH = "0";
|
|
191
|
+
assert.equal(checkSubagentDepth().blocked, true);
|
|
192
|
+
});
|
|
193
|
+
|
|
194
|
+
it("defaults to depth=0, max=2 when env vars unset", () => {
|
|
195
|
+
delete process.env.SELESAI_SUBAGENT_DEPTH;
|
|
196
|
+
delete process.env.SELESAI_SUBAGENT_MAX_DEPTH;
|
|
197
|
+
const result = checkSubagentDepth();
|
|
198
|
+
assert.equal(result.blocked, false);
|
|
199
|
+
assert.equal(result.depth, 0);
|
|
200
|
+
assert.equal(result.maxDepth, 2);
|
|
201
|
+
});
|
|
202
|
+
|
|
203
|
+
it("not blocked when depth is invalid (NaN)", () => {
|
|
204
|
+
process.env.SELESAI_SUBAGENT_DEPTH = "garbage";
|
|
205
|
+
process.env.SELESAI_SUBAGENT_MAX_DEPTH = "2";
|
|
206
|
+
assert.equal(checkSubagentDepth().blocked, false);
|
|
207
|
+
});
|
|
208
|
+
});
|
|
209
|
+
|
|
210
|
+
describe("getSubagentDepthEnv", () => {
|
|
211
|
+
it("increments from depth=0", () => {
|
|
212
|
+
process.env.SELESAI_SUBAGENT_DEPTH = "0";
|
|
213
|
+
delete process.env.SELESAI_SUBAGENT_MAX_DEPTH;
|
|
214
|
+
const env = getSubagentDepthEnv();
|
|
215
|
+
assert.equal(env.SELESAI_SUBAGENT_DEPTH, "1");
|
|
216
|
+
assert.equal(env.SELESAI_SUBAGENT_MAX_DEPTH, "2");
|
|
217
|
+
});
|
|
218
|
+
|
|
219
|
+
it("increments from depth=1", () => {
|
|
220
|
+
process.env.SELESAI_SUBAGENT_DEPTH = "1";
|
|
221
|
+
delete process.env.SELESAI_SUBAGENT_MAX_DEPTH;
|
|
222
|
+
const env = getSubagentDepthEnv();
|
|
223
|
+
assert.equal(env.SELESAI_SUBAGENT_DEPTH, "2");
|
|
224
|
+
assert.equal(env.SELESAI_SUBAGENT_MAX_DEPTH, "2");
|
|
225
|
+
});
|
|
226
|
+
|
|
227
|
+
it("uses provided max depth override", () => {
|
|
228
|
+
process.env.SELESAI_SUBAGENT_DEPTH = "0";
|
|
229
|
+
delete process.env.SELESAI_SUBAGENT_MAX_DEPTH;
|
|
230
|
+
const env = getSubagentDepthEnv(1);
|
|
231
|
+
assert.equal(env.SELESAI_SUBAGENT_DEPTH, "1");
|
|
232
|
+
assert.equal(env.SELESAI_SUBAGENT_MAX_DEPTH, "1");
|
|
233
|
+
});
|
|
234
|
+
|
|
235
|
+
it("respects inherited SELESAI_SUBAGENT_MAX_DEPTH when override is absent", () => {
|
|
236
|
+
process.env.SELESAI_SUBAGENT_DEPTH = "0";
|
|
237
|
+
process.env.SELESAI_SUBAGENT_MAX_DEPTH = "5";
|
|
238
|
+
const env = getSubagentDepthEnv();
|
|
239
|
+
assert.equal(env.SELESAI_SUBAGENT_DEPTH, "1");
|
|
240
|
+
assert.equal(env.SELESAI_SUBAGENT_MAX_DEPTH, "5");
|
|
241
|
+
});
|
|
242
|
+
|
|
243
|
+
it("uses the explicit child override even when a looser inherited env max exists", () => {
|
|
244
|
+
process.env.SELESAI_SUBAGENT_DEPTH = "0";
|
|
245
|
+
process.env.SELESAI_SUBAGENT_MAX_DEPTH = "5";
|
|
246
|
+
const env = getSubagentDepthEnv(1);
|
|
247
|
+
assert.equal(env.SELESAI_SUBAGENT_DEPTH, "1");
|
|
248
|
+
assert.equal(env.SELESAI_SUBAGENT_MAX_DEPTH, "1");
|
|
249
|
+
});
|
|
250
|
+
|
|
251
|
+
it("falls back to depth=1 when env var is invalid (NaN)", () => {
|
|
252
|
+
process.env.SELESAI_SUBAGENT_DEPTH = "not-a-number";
|
|
253
|
+
delete process.env.SELESAI_SUBAGENT_MAX_DEPTH;
|
|
254
|
+
const env = getSubagentDepthEnv();
|
|
255
|
+
assert.equal(env.SELESAI_SUBAGENT_DEPTH, "1");
|
|
256
|
+
});
|
|
257
|
+
});
|
|
@@ -0,0 +1,209 @@
|
|
|
1
|
+
import test from "node:test";
|
|
2
|
+
import assert from "node:assert/strict";
|
|
3
|
+
|
|
4
|
+
import { visibleWidth } from "@earendil-works/pi-tui";
|
|
5
|
+
import { row } from "../../src/tui/render-helpers.ts";
|
|
6
|
+
import { renderSubagentResult } from "../../src/tui/render.ts";
|
|
7
|
+
|
|
8
|
+
const theme = {
|
|
9
|
+
fg(_name: string, text: string): string {
|
|
10
|
+
return text;
|
|
11
|
+
},
|
|
12
|
+
bold(text: string): string {
|
|
13
|
+
return text;
|
|
14
|
+
},
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
function componentText(component: unknown): string {
|
|
18
|
+
if (typeof component !== "object" || component === null) return "";
|
|
19
|
+
if ("text" in component && typeof component.text === "string") return component.text;
|
|
20
|
+
if ("children" in component && Array.isArray(component.children)) return component.children.map(componentText).filter(Boolean).join("\n");
|
|
21
|
+
return "";
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
function result(agent: string, output: string) {
|
|
25
|
+
return {
|
|
26
|
+
agent,
|
|
27
|
+
task: `${agent} task`,
|
|
28
|
+
exitCode: 0,
|
|
29
|
+
messages: [],
|
|
30
|
+
usage: { input: 0, output: 0, cacheRead: 0, cacheWrite: 0, cost: 0, turns: 0 },
|
|
31
|
+
finalOutput: output,
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
test("row clips content to the available width", () => {
|
|
36
|
+
const rendered = row("abcdef", 6, theme as any);
|
|
37
|
+
assert.equal(visibleWidth(rendered), 6);
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
test("row normalizes multiline content before clipping", () => {
|
|
41
|
+
const rendered = row("bash failed: line 1\nline 2\tvalue", 20, theme as any);
|
|
42
|
+
assert.equal(visibleWidth(rendered), 20);
|
|
43
|
+
assert.doesNotMatch(rendered, /[\r\n\t]/);
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
test("row keeps styled multiline content within the available width", () => {
|
|
47
|
+
const rendered = row("\u001b[31merror line 1\nline 2\tvalue\u001b[39m", 18, theme as any);
|
|
48
|
+
assert.equal(visibleWidth(rendered), 18);
|
|
49
|
+
assert.doesNotMatch(rendered, /[\r\n\t]/);
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
test("compact chain rendering uses workflow graph spans for dynamic fanout results", () => {
|
|
53
|
+
const component = renderSubagentResult({
|
|
54
|
+
content: [{ type: "text", text: "done" }],
|
|
55
|
+
details: {
|
|
56
|
+
mode: "chain",
|
|
57
|
+
chainAgents: ["scout", "expand:reviewer", "writer"],
|
|
58
|
+
totalSteps: 3,
|
|
59
|
+
results: [result("scout", "targets"), result("reviewer", "a"), result("reviewer", "b"), result("writer", "final")],
|
|
60
|
+
workflowGraph: {
|
|
61
|
+
runId: "render-dynamic",
|
|
62
|
+
mode: "chain",
|
|
63
|
+
phases: [],
|
|
64
|
+
nodes: [
|
|
65
|
+
{ id: "step-0", kind: "step", agent: "scout", label: "Scout", status: "completed", flatIndex: 0, stepIndex: 0 },
|
|
66
|
+
{
|
|
67
|
+
id: "step-1",
|
|
68
|
+
kind: "dynamic-parallel-group",
|
|
69
|
+
label: "Review targets",
|
|
70
|
+
status: "completed",
|
|
71
|
+
stepIndex: 1,
|
|
72
|
+
children: [
|
|
73
|
+
{ id: "step-1-item-a", kind: "agent", agent: "reviewer", label: "Review A", status: "completed", flatIndex: 1, stepIndex: 1 },
|
|
74
|
+
{ id: "step-1-item-b", kind: "agent", agent: "reviewer", label: "Review B", status: "completed", flatIndex: 2, stepIndex: 1 },
|
|
75
|
+
],
|
|
76
|
+
dynamic: { sourceOutput: "targets", sourcePath: "/items", itemName: "target", collectAs: "reviews" },
|
|
77
|
+
},
|
|
78
|
+
{ id: "step-2", kind: "step", agent: "writer", label: "Writer", status: "completed", flatIndex: 3, stepIndex: 2 },
|
|
79
|
+
],
|
|
80
|
+
},
|
|
81
|
+
},
|
|
82
|
+
}, { expanded: false }, theme as any);
|
|
83
|
+
|
|
84
|
+
const text = componentText(component);
|
|
85
|
+
assert.match(text, /Step 1: scout/);
|
|
86
|
+
assert.match(text, /Agent 1\/2: reviewer/);
|
|
87
|
+
assert.match(text, /Agent 2\/2: reviewer/);
|
|
88
|
+
assert.match(text, /Step 3: writer/);
|
|
89
|
+
});
|
|
90
|
+
|
|
91
|
+
test("compact chain rendering shows failed zero-child dynamic fanout groups", () => {
|
|
92
|
+
const component = renderSubagentResult({
|
|
93
|
+
content: [{ type: "text", text: "failed" }],
|
|
94
|
+
details: {
|
|
95
|
+
mode: "chain",
|
|
96
|
+
chainAgents: ["scout", "expand:reviewer", "writer"],
|
|
97
|
+
totalSteps: 3,
|
|
98
|
+
results: [result("scout", "targets")],
|
|
99
|
+
workflowGraph: {
|
|
100
|
+
runId: "render-empty-dynamic-failed",
|
|
101
|
+
mode: "chain",
|
|
102
|
+
phases: [],
|
|
103
|
+
nodes: [
|
|
104
|
+
{ id: "step-0", kind: "step", agent: "scout", label: "Scout", status: "completed", flatIndex: 0, stepIndex: 0 },
|
|
105
|
+
{
|
|
106
|
+
id: "step-1",
|
|
107
|
+
kind: "dynamic-parallel-group",
|
|
108
|
+
label: "Review targets",
|
|
109
|
+
status: "failed",
|
|
110
|
+
stepIndex: 1,
|
|
111
|
+
children: [],
|
|
112
|
+
error: "No review targets materialized",
|
|
113
|
+
dynamic: { sourceOutput: "targets", sourcePath: "/items", itemName: "target", collectAs: "reviews" },
|
|
114
|
+
},
|
|
115
|
+
{ id: "step-2", kind: "step", agent: "writer", label: "Writer", status: "pending", stepIndex: 2 },
|
|
116
|
+
],
|
|
117
|
+
},
|
|
118
|
+
},
|
|
119
|
+
}, { expanded: false }, theme as any);
|
|
120
|
+
|
|
121
|
+
const text = componentText(component);
|
|
122
|
+
assert.match(text, /step 1\/3/);
|
|
123
|
+
assert.doesNotMatch(text, /step 3\/3/);
|
|
124
|
+
assert.match(text, /Step 1: scout/);
|
|
125
|
+
assert.match(text, /Step 2: Review targets .* failed/);
|
|
126
|
+
assert.match(text, /No review targets materialized/);
|
|
127
|
+
assert.match(text, /Step 3: writer .* pending/);
|
|
128
|
+
});
|
|
129
|
+
|
|
130
|
+
test("expanded chain rendering uses workflow graph spans for dynamic fanout results", () => {
|
|
131
|
+
const component = renderSubagentResult({
|
|
132
|
+
content: [{ type: "text", text: "done" }],
|
|
133
|
+
details: {
|
|
134
|
+
mode: "chain",
|
|
135
|
+
chainAgents: ["scout", "expand:reviewer", "writer"],
|
|
136
|
+
totalSteps: 3,
|
|
137
|
+
results: [result("scout", "targets"), result("reviewer", "a"), result("reviewer", "b"), result("writer", "final")],
|
|
138
|
+
workflowGraph: {
|
|
139
|
+
runId: "render-dynamic-expanded",
|
|
140
|
+
mode: "chain",
|
|
141
|
+
phases: [],
|
|
142
|
+
nodes: [
|
|
143
|
+
{ id: "step-0", kind: "step", agent: "scout", label: "Scout", status: "completed", flatIndex: 0, stepIndex: 0 },
|
|
144
|
+
{
|
|
145
|
+
id: "step-1",
|
|
146
|
+
kind: "dynamic-parallel-group",
|
|
147
|
+
label: "Review targets",
|
|
148
|
+
status: "completed",
|
|
149
|
+
stepIndex: 1,
|
|
150
|
+
children: [
|
|
151
|
+
{ id: "step-1-item-a", kind: "agent", agent: "reviewer", label: "Review A", status: "completed", flatIndex: 1, stepIndex: 1 },
|
|
152
|
+
{ id: "step-1-item-b", kind: "agent", agent: "reviewer", label: "Review B", status: "completed", flatIndex: 2, stepIndex: 1 },
|
|
153
|
+
],
|
|
154
|
+
dynamic: { sourceOutput: "targets", sourcePath: "/items", itemName: "target", collectAs: "reviews" },
|
|
155
|
+
},
|
|
156
|
+
{ id: "step-2", kind: "step", agent: "writer", label: "Writer", status: "completed", flatIndex: 3, stepIndex: 2 },
|
|
157
|
+
],
|
|
158
|
+
},
|
|
159
|
+
},
|
|
160
|
+
}, { expanded: true }, theme as any);
|
|
161
|
+
|
|
162
|
+
const text = componentText(component);
|
|
163
|
+
assert.match(text, /Step 1: scout/);
|
|
164
|
+
assert.match(text, /Agent 1\/2: reviewer/);
|
|
165
|
+
assert.match(text, /Agent 2\/2: reviewer/);
|
|
166
|
+
assert.match(text, /Step 3: writer/);
|
|
167
|
+
});
|
|
168
|
+
|
|
169
|
+
test("compact multi-result rendering shows total cost in the header", () => {
|
|
170
|
+
const text = componentText(renderSubagentResult({
|
|
171
|
+
content: [{ type: "text", text: "done" }],
|
|
172
|
+
details: {
|
|
173
|
+
mode: "parallel",
|
|
174
|
+
results: [result("scout", "a"), result("reviewer", "b")],
|
|
175
|
+
totalCost: { inputTokens: 30, outputTokens: 12, costUsd: 0.04 },
|
|
176
|
+
},
|
|
177
|
+
}, { expanded: false }, theme as any));
|
|
178
|
+
|
|
179
|
+
assert.match(text, /2\/2 done/);
|
|
180
|
+
assert.match(text, /in:30 out:12 \$0\.0400/);
|
|
181
|
+
});
|
|
182
|
+
|
|
183
|
+
test("static sequential and static parallel chain rendering keep existing labels", () => {
|
|
184
|
+
const sequential = componentText(renderSubagentResult({
|
|
185
|
+
content: [{ type: "text", text: "done" }],
|
|
186
|
+
details: {
|
|
187
|
+
mode: "chain",
|
|
188
|
+
chainAgents: ["scout", "writer"],
|
|
189
|
+
totalSteps: 2,
|
|
190
|
+
results: [result("scout", "a"), result("writer", "b")],
|
|
191
|
+
},
|
|
192
|
+
}, { expanded: false }, theme as any));
|
|
193
|
+
assert.match(sequential, /Step 1: scout/);
|
|
194
|
+
assert.match(sequential, /Step 2: writer/);
|
|
195
|
+
|
|
196
|
+
const parallel = componentText(renderSubagentResult({
|
|
197
|
+
content: [{ type: "text", text: "done" }],
|
|
198
|
+
details: {
|
|
199
|
+
mode: "chain",
|
|
200
|
+
chainAgents: ["scout", "[reviewer+auditor]", "writer"],
|
|
201
|
+
totalSteps: 3,
|
|
202
|
+
results: [result("scout", "a"), result("reviewer", "b"), result("auditor", "c"), result("writer", "d")],
|
|
203
|
+
},
|
|
204
|
+
}, { expanded: false }, theme as any));
|
|
205
|
+
assert.match(parallel, /Step 1: scout/);
|
|
206
|
+
assert.match(parallel, /Agent 1\/2: reviewer/);
|
|
207
|
+
assert.match(parallel, /Agent 2\/2: auditor/);
|
|
208
|
+
assert.match(parallel, /Step 3: writer/);
|
|
209
|
+
});
|
|
@@ -0,0 +1,226 @@
|
|
|
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 {
|
|
7
|
+
attachNestedChildrenToResultChildren,
|
|
8
|
+
buildSubagentResultIntercomPayload,
|
|
9
|
+
formatSubagentResultReceipt,
|
|
10
|
+
resolveSubagentResultStatus,
|
|
11
|
+
stripDetailsOutputsForIntercomReceipt,
|
|
12
|
+
} from "../../src/intercom/result-intercom.ts";
|
|
13
|
+
|
|
14
|
+
describe("result intercom formatter", () => {
|
|
15
|
+
it("builds one grouped intercom payload with status counts and child sections", () => {
|
|
16
|
+
const payload = buildSubagentResultIntercomPayload({
|
|
17
|
+
to: "subagent-chat-main",
|
|
18
|
+
runId: "run-123",
|
|
19
|
+
mode: "chain",
|
|
20
|
+
source: "foreground",
|
|
21
|
+
chainSteps: 4,
|
|
22
|
+
children: [
|
|
23
|
+
{
|
|
24
|
+
agent: "reviewer-a",
|
|
25
|
+
status: "completed",
|
|
26
|
+
summary: "Completed checks",
|
|
27
|
+
artifactPath: "/tmp/a.md",
|
|
28
|
+
sessionPath: "/tmp/a-session.jsonl",
|
|
29
|
+
intercomTarget: "subagent-reviewer-a-run-123-1",
|
|
30
|
+
},
|
|
31
|
+
{
|
|
32
|
+
agent: "reviewer-b",
|
|
33
|
+
status: "failed",
|
|
34
|
+
summary: "Failed checks",
|
|
35
|
+
artifactPath: "/tmp/b.md",
|
|
36
|
+
},
|
|
37
|
+
],
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
assert.equal(payload.status, "failed");
|
|
41
|
+
assert.equal(payload.summary, "1 completed, 1 failed");
|
|
42
|
+
assert.equal(payload.children.length, 2);
|
|
43
|
+
assert.match(payload.message, /^subagent results/m);
|
|
44
|
+
assert.match(payload.message, /Run: run-123/);
|
|
45
|
+
assert.match(payload.message, /Mode: chain/);
|
|
46
|
+
assert.match(payload.message, /Status: failed/);
|
|
47
|
+
assert.match(payload.message, /Children: 1 completed, 1 failed/);
|
|
48
|
+
assert.match(payload.message, /Chain steps: 4/);
|
|
49
|
+
assert.match(payload.message, /Intercom targets below identify child sessions used while they were running/);
|
|
50
|
+
assert.match(payload.message, /1\. reviewer-a — completed/);
|
|
51
|
+
assert.match(payload.message, /Run intercom target: subagent-reviewer-a-run-123-1/);
|
|
52
|
+
assert.match(payload.message, /2\. reviewer-b — failed/);
|
|
53
|
+
assert.match(payload.message, /Output artifact: \/tmp\/a\.md/);
|
|
54
|
+
assert.match(payload.message, /Session: \/tmp\/a-session\.jsonl/);
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
it("advertises async revive only for single-child results with an existing session", () => {
|
|
58
|
+
const root = fs.mkdtempSync(path.join(os.tmpdir(), "pi-result-intercom-"));
|
|
59
|
+
try {
|
|
60
|
+
const sessionPath = path.join(root, "session.jsonl");
|
|
61
|
+
fs.writeFileSync(sessionPath, "", "utf-8");
|
|
62
|
+
const payload = buildSubagentResultIntercomPayload({
|
|
63
|
+
to: "chat",
|
|
64
|
+
runId: "run-single",
|
|
65
|
+
mode: "single",
|
|
66
|
+
source: "async",
|
|
67
|
+
asyncId: "run-single",
|
|
68
|
+
children: [{ agent: "worker", status: "completed", summary: "done", sessionPath }],
|
|
69
|
+
});
|
|
70
|
+
|
|
71
|
+
assert.match(payload.message, /Revive: subagent\(\{ action: "resume", id: "run-single", message: "\.\.\." \}\)/);
|
|
72
|
+
assert.doesNotMatch(payload.message, /unsupported for multi-child/);
|
|
73
|
+
} finally {
|
|
74
|
+
fs.rmSync(root, { recursive: true, force: true });
|
|
75
|
+
}
|
|
76
|
+
});
|
|
77
|
+
|
|
78
|
+
it("advertises indexed revive for multi-child async results with existing child sessions", () => {
|
|
79
|
+
const root = fs.mkdtempSync(path.join(os.tmpdir(), "pi-result-intercom-"));
|
|
80
|
+
try {
|
|
81
|
+
const firstSession = path.join(root, "a.jsonl");
|
|
82
|
+
const secondSession = path.join(root, "b.jsonl");
|
|
83
|
+
fs.writeFileSync(firstSession, "", "utf-8");
|
|
84
|
+
fs.writeFileSync(secondSession, "", "utf-8");
|
|
85
|
+
const payload = buildSubagentResultIntercomPayload({
|
|
86
|
+
to: "chat",
|
|
87
|
+
runId: "run-multi",
|
|
88
|
+
mode: "parallel",
|
|
89
|
+
source: "async",
|
|
90
|
+
asyncId: "run-multi",
|
|
91
|
+
children: [
|
|
92
|
+
{ agent: "a", status: "completed", summary: "done", sessionPath: firstSession },
|
|
93
|
+
{ agent: "b", status: "completed", summary: "done", sessionPath: secondSession },
|
|
94
|
+
],
|
|
95
|
+
});
|
|
96
|
+
|
|
97
|
+
assert.match(payload.message, /Revive child: subagent\(\{ action: "resume", id: "run-multi", index: 0, message: "\.\.\." \}\)/);
|
|
98
|
+
assert.doesNotMatch(payload.message, /unsupported for multi-child/);
|
|
99
|
+
} finally {
|
|
100
|
+
fs.rmSync(root, { recursive: true, force: true });
|
|
101
|
+
}
|
|
102
|
+
});
|
|
103
|
+
|
|
104
|
+
it("does not advertise async revive for missing child session files", () => {
|
|
105
|
+
const payload = buildSubagentResultIntercomPayload({
|
|
106
|
+
to: "chat",
|
|
107
|
+
runId: "run-missing-session",
|
|
108
|
+
mode: "single",
|
|
109
|
+
source: "async",
|
|
110
|
+
asyncId: "run-missing-session",
|
|
111
|
+
children: [{ agent: "worker", status: "failed", summary: "failed", sessionPath: path.join(os.tmpdir(), "missing-pi-session.jsonl") }],
|
|
112
|
+
});
|
|
113
|
+
|
|
114
|
+
assert.match(payload.message, /Resume: unavailable; no child session file was persisted/);
|
|
115
|
+
assert.doesNotMatch(payload.message, /Revive:/);
|
|
116
|
+
});
|
|
117
|
+
|
|
118
|
+
it("attaches compact nested children under their parent result child without route secrets", () => {
|
|
119
|
+
const payload = buildSubagentResultIntercomPayload({
|
|
120
|
+
to: "chat",
|
|
121
|
+
runId: "root-run",
|
|
122
|
+
mode: "parallel",
|
|
123
|
+
source: "foreground",
|
|
124
|
+
children: attachNestedChildrenToResultChildren("root-run", [
|
|
125
|
+
{ agent: "owner-a", status: "completed", summary: "done", index: 0 },
|
|
126
|
+
{ agent: "owner-b", status: "completed", summary: "done", index: 1 },
|
|
127
|
+
], [{
|
|
128
|
+
id: "nested-a",
|
|
129
|
+
parentRunId: "root-run",
|
|
130
|
+
parentStepIndex: 1,
|
|
131
|
+
depth: 1,
|
|
132
|
+
path: [{ runId: "root-run", stepIndex: 1 }],
|
|
133
|
+
state: "complete",
|
|
134
|
+
agent: "reviewer",
|
|
135
|
+
sessionFile: path.join(os.tmpdir(), "nested-a.jsonl"),
|
|
136
|
+
controlInbox: "/tmp/should-not-leak",
|
|
137
|
+
capabilityToken: "secret-token",
|
|
138
|
+
children: [{
|
|
139
|
+
id: "nested-grandchild",
|
|
140
|
+
parentRunId: "nested-a",
|
|
141
|
+
depth: 2,
|
|
142
|
+
path: [{ runId: "root-run", stepIndex: 1 }, { runId: "nested-a" }],
|
|
143
|
+
state: "complete",
|
|
144
|
+
agent: "auditor",
|
|
145
|
+
controlInbox: "/tmp/grandchild-should-not-leak",
|
|
146
|
+
capabilityToken: "grandchild-secret",
|
|
147
|
+
}],
|
|
148
|
+
}]),
|
|
149
|
+
});
|
|
150
|
+
|
|
151
|
+
const nested = payload.children[1]?.children?.[0];
|
|
152
|
+
const grandchild = nested?.children?.[0];
|
|
153
|
+
assert.equal(payload.children[0]?.children, undefined);
|
|
154
|
+
assert.equal(nested?.id, "nested-a");
|
|
155
|
+
assert.equal(Object.hasOwn(nested ?? {}, "controlInbox"), false);
|
|
156
|
+
assert.equal(Object.hasOwn(nested ?? {}, "capabilityToken"), false);
|
|
157
|
+
assert.equal(grandchild?.id, "nested-grandchild");
|
|
158
|
+
assert.equal(Object.hasOwn(grandchild ?? {}, "controlInbox"), false);
|
|
159
|
+
assert.equal(Object.hasOwn(grandchild ?? {}, "capabilityToken"), false);
|
|
160
|
+
assert.match(payload.message, /Nested subagents:/);
|
|
161
|
+
assert.match(payload.message, /↳ reviewer — complete \[nested-a\]/);
|
|
162
|
+
});
|
|
163
|
+
|
|
164
|
+
it("keeps full child summaries inside grouped payloads", () => {
|
|
165
|
+
const longSummary = `${"x".repeat(2000)}\n${"y".repeat(2000)}`;
|
|
166
|
+
const payload = buildSubagentResultIntercomPayload({
|
|
167
|
+
to: "chat",
|
|
168
|
+
runId: "run-bound",
|
|
169
|
+
mode: "single",
|
|
170
|
+
source: "foreground",
|
|
171
|
+
children: [{ agent: "worker", status: "completed", summary: longSummary }],
|
|
172
|
+
});
|
|
173
|
+
assert.equal(payload.children[0]!.summary, longSummary);
|
|
174
|
+
assert.match(payload.message, new RegExp(`${"x".repeat(2000)}\\n${"y".repeat(2000)}`));
|
|
175
|
+
});
|
|
176
|
+
|
|
177
|
+
it("formats compact grouped receipts with artifacts and sessions", () => {
|
|
178
|
+
const payload = buildSubagentResultIntercomPayload({
|
|
179
|
+
to: "chat",
|
|
180
|
+
runId: "run-abc",
|
|
181
|
+
mode: "parallel",
|
|
182
|
+
source: "foreground",
|
|
183
|
+
children: [
|
|
184
|
+
{ agent: "a", status: "completed", summary: "done", artifactPath: "/tmp/a.md", intercomTarget: "subagent-a-run-abc-1" },
|
|
185
|
+
{ agent: "b", status: "failed", summary: "failed", sessionPath: "/tmp/b.jsonl" },
|
|
186
|
+
],
|
|
187
|
+
});
|
|
188
|
+
const receipt = formatSubagentResultReceipt({
|
|
189
|
+
mode: "parallel",
|
|
190
|
+
runId: "run-abc",
|
|
191
|
+
payload,
|
|
192
|
+
});
|
|
193
|
+
|
|
194
|
+
assert.match(receipt, /Delivered parallel subagent results via intercom\./);
|
|
195
|
+
assert.match(receipt, /Children: 1 completed, 1 failed/);
|
|
196
|
+
assert.match(receipt, /Artifacts:\n- a \[completed\]: \/tmp\/a\.md/);
|
|
197
|
+
assert.match(receipt, /Run intercom targets \(may be inactive after completion\):\n- a \[completed\]: subagent-a-run-abc-1/);
|
|
198
|
+
assert.match(receipt, /Sessions:\n- b \[failed\]: \/tmp\/b\.jsonl/);
|
|
199
|
+
assert.match(receipt, /Full grouped output was sent over intercom\./);
|
|
200
|
+
});
|
|
201
|
+
|
|
202
|
+
it("strips heavy output fields from receipt details", () => {
|
|
203
|
+
const stripped = stripDetailsOutputsForIntercomReceipt({
|
|
204
|
+
mode: "single",
|
|
205
|
+
results: [{
|
|
206
|
+
agent: "worker",
|
|
207
|
+
task: "Task",
|
|
208
|
+
exitCode: 0,
|
|
209
|
+
messages: [{ role: "assistant", content: [{ type: "text", text: "full" }] } as never],
|
|
210
|
+
usage: { input: 1, output: 1, cacheRead: 0, cacheWrite: 0, cost: 0, turns: 1 },
|
|
211
|
+
finalOutput: "full output",
|
|
212
|
+
truncation: { text: "truncated", truncated: true },
|
|
213
|
+
}],
|
|
214
|
+
});
|
|
215
|
+
assert.equal(stripped.results[0]?.messages, undefined);
|
|
216
|
+
assert.equal(stripped.results[0]?.finalOutput, undefined);
|
|
217
|
+
assert.equal(stripped.results[0]?.truncation, undefined);
|
|
218
|
+
});
|
|
219
|
+
|
|
220
|
+
it("resolves paused and detached statuses", () => {
|
|
221
|
+
assert.equal(resolveSubagentResultStatus({ interrupted: true }), "paused");
|
|
222
|
+
assert.equal(resolveSubagentResultStatus({ detached: true }), "detached");
|
|
223
|
+
assert.equal(resolveSubagentResultStatus({ success: true }), "completed");
|
|
224
|
+
assert.equal(resolveSubagentResultStatus({ exitCode: 1 }), "failed");
|
|
225
|
+
});
|
|
226
|
+
});
|