@selesai/code 0.5.20 → 0.5.21
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/extensions/handoff-new.test.ts +8 -9
- package/dist/extensions/handoff-new.ts +6 -8
- package/dist/extensions/pi-subagents/CHANGELOG.md +1367 -0
- package/dist/extensions/pi-subagents/README.md +602 -220
- package/dist/extensions/pi-subagents/banner.png +0 -0
- package/dist/extensions/pi-subagents/index.ts +1 -0
- package/dist/extensions/pi-subagents/install.mjs +3 -3
- package/dist/extensions/pi-subagents/package-lock.json +3405 -0
- package/dist/extensions/pi-subagents/package.json +26 -14
- package/dist/extensions/pi-subagents/prompts/gather-context-and-clarify.md +1 -1
- package/dist/extensions/pi-subagents/prompts/parallel-cleanup.md +9 -9
- package/dist/extensions/pi-subagents/prompts/parallel-context-build.md +3 -3
- package/dist/extensions/pi-subagents/prompts/parallel-handoff-plan.md +7 -7
- package/dist/extensions/pi-subagents/prompts/parallel-research.md +6 -6
- package/dist/extensions/pi-subagents/prompts/parallel-review.md +8 -8
- package/dist/extensions/pi-subagents/prompts/review-loop.md +13 -11
- package/dist/extensions/pi-subagents/skills/pi-subagents/SKILL.md +267 -176
- package/dist/extensions/pi-subagents/src/agents/agent-management.ts +89 -16
- package/dist/extensions/pi-subagents/src/agents/agent-serializer.ts +19 -0
- package/dist/extensions/pi-subagents/src/agents/agents.ts +218 -120
- package/dist/extensions/pi-subagents/src/agents/frontmatter.ts +67 -13
- package/dist/extensions/pi-subagents/src/agents/proactive-skills.ts +2 -2
- package/dist/extensions/pi-subagents/src/agents/skills.ts +25 -12
- package/dist/extensions/pi-subagents/src/api/background-work.ts +197 -0
- package/dist/extensions/pi-subagents/src/api/capability-ceiling.ts +17 -0
- package/dist/extensions/pi-subagents/src/api/delegation.ts +285 -0
- package/dist/extensions/pi-subagents/src/api/preflight.ts +399 -0
- package/dist/extensions/pi-subagents/src/extension/chain-validation.ts +165 -0
- package/dist/extensions/pi-subagents/src/extension/config.ts +7 -1
- package/dist/extensions/pi-subagents/src/extension/doctor.ts +15 -0
- package/dist/extensions/pi-subagents/src/extension/fanout-child.ts +3 -1
- package/dist/extensions/pi-subagents/src/extension/index.ts +113 -157
- package/dist/extensions/pi-subagents/src/extension/rpc.ts +41 -4
- package/dist/extensions/pi-subagents/src/extension/schemas.ts +45 -15
- package/dist/extensions/pi-subagents/src/extension/steering-notices.ts +35 -0
- package/dist/extensions/pi-subagents/src/extension/tool-description.ts +28 -15
- package/dist/extensions/pi-subagents/src/intercom/intercom-bridge.ts +4 -3
- package/dist/extensions/pi-subagents/src/intercom/native-supervisor-channel.ts +225 -29
- package/dist/extensions/pi-subagents/src/intercom/result-intercom.ts +11 -0
- package/dist/extensions/pi-subagents/src/profiles/profiles.ts +8 -10
- package/dist/extensions/pi-subagents/src/runs/background/async-execution.ts +452 -62
- package/dist/extensions/pi-subagents/src/runs/background/async-job-tracker.ts +60 -9
- package/dist/extensions/pi-subagents/src/runs/background/async-resume.ts +198 -52
- package/dist/extensions/pi-subagents/src/runs/background/async-status.ts +119 -21
- package/dist/extensions/pi-subagents/src/runs/background/auto-drain.ts +67 -0
- package/dist/extensions/pi-subagents/src/runs/background/chain-append.ts +2 -0
- package/dist/extensions/pi-subagents/src/runs/background/chain-root-attachment.ts +16 -8
- package/dist/extensions/pi-subagents/src/runs/background/completion-batcher.ts +6 -4
- package/dist/extensions/pi-subagents/src/runs/background/completion-dedupe.ts +2 -11
- package/dist/extensions/pi-subagents/src/runs/background/control-channel.ts +260 -13
- package/dist/extensions/pi-subagents/src/runs/background/fleet-view.ts +32 -6
- package/dist/extensions/pi-subagents/src/runs/background/notify.ts +171 -90
- package/dist/extensions/pi-subagents/src/runs/background/process-terminal.ts +280 -0
- package/dist/extensions/pi-subagents/src/runs/background/result-watcher.ts +149 -88
- package/dist/extensions/pi-subagents/src/runs/background/run-id-resolver.ts +14 -2
- package/dist/extensions/pi-subagents/src/runs/background/run-status.ts +33 -17
- package/dist/extensions/pi-subagents/src/runs/background/scheduled-runs.ts +9 -1
- package/dist/extensions/pi-subagents/src/runs/background/stale-run-reconciler.ts +38 -10
- package/dist/extensions/pi-subagents/src/runs/background/steering.ts +237 -0
- package/dist/extensions/pi-subagents/src/runs/background/subagent-runner.ts +1297 -307
- package/dist/extensions/pi-subagents/src/runs/background/subagent-wait.ts +610 -0
- package/dist/extensions/pi-subagents/src/runs/background/top-level-async.ts +2 -1
- package/dist/extensions/pi-subagents/src/runs/background/wait-config.ts +36 -0
- package/dist/extensions/pi-subagents/src/runs/background/wait-tool.ts +26 -0
- package/dist/extensions/pi-subagents/src/runs/foreground/async-steering-action.ts +230 -0
- package/dist/extensions/pi-subagents/src/runs/foreground/chain-clarify.ts +22 -6
- package/dist/extensions/pi-subagents/src/runs/foreground/chain-execution.ts +228 -140
- package/dist/extensions/pi-subagents/src/runs/foreground/execution.ts +452 -138
- package/dist/extensions/pi-subagents/src/runs/foreground/foreground-control.ts +90 -0
- package/dist/extensions/pi-subagents/src/runs/foreground/subagent-executor.ts +1001 -416
- package/dist/extensions/pi-subagents/src/runs/shared/acceptance.ts +443 -132
- package/dist/extensions/pi-subagents/src/runs/shared/agent-contract.ts +38 -0
- package/dist/extensions/pi-subagents/src/runs/shared/capability-ceiling.ts +178 -0
- package/dist/extensions/pi-subagents/src/runs/shared/child-protocol.ts +121 -0
- package/dist/extensions/pi-subagents/src/runs/shared/completion-guard.ts +41 -93
- package/dist/extensions/pi-subagents/src/runs/shared/context-mode.ts +44 -0
- package/dist/extensions/pi-subagents/src/runs/shared/dynamic-fanout.ts +11 -9
- package/dist/extensions/pi-subagents/src/runs/shared/long-running-guard.ts +4 -0
- package/dist/extensions/pi-subagents/src/runs/shared/mcp-direct-tool-allowlist.ts +12 -6
- package/dist/extensions/pi-subagents/src/runs/shared/model-fallback.ts +36 -0
- package/dist/extensions/pi-subagents/src/runs/shared/nested-events.ts +44 -7
- package/dist/extensions/pi-subagents/src/runs/shared/nested-render.ts +4 -1
- package/dist/extensions/pi-subagents/src/runs/shared/parallel-handoff.ts +154 -0
- package/dist/extensions/pi-subagents/src/runs/shared/parallel-utils.ts +18 -0
- package/dist/extensions/pi-subagents/src/runs/shared/pi-args.ts +174 -54
- package/dist/extensions/pi-subagents/src/runs/shared/pi-spawn.ts +38 -31
- package/dist/extensions/pi-subagents/src/runs/shared/run-history.ts +90 -5
- package/dist/extensions/pi-subagents/src/runs/shared/session-lease.ts +299 -0
- package/dist/extensions/pi-subagents/src/runs/shared/single-output.ts +61 -6
- package/dist/extensions/pi-subagents/src/runs/shared/spawn-budget.ts +128 -0
- package/dist/extensions/pi-subagents/src/runs/shared/structured-output.ts +112 -7
- package/dist/extensions/pi-subagents/src/runs/shared/subagent-control.ts +14 -6
- package/dist/extensions/pi-subagents/src/runs/shared/subagent-prompt-runtime.ts +149 -36
- package/dist/extensions/pi-subagents/src/runs/shared/task-intent.ts +181 -0
- package/dist/extensions/pi-subagents/src/runs/shared/tool-availability.ts +83 -0
- package/dist/extensions/pi-subagents/src/runs/shared/tool-budget.ts +11 -5
- package/dist/extensions/pi-subagents/src/runs/shared/turn-budget.ts +50 -4
- package/dist/extensions/pi-subagents/src/runs/shared/worktree.ts +63 -14
- package/dist/extensions/pi-subagents/src/shared/accessible-dir.ts +25 -0
- package/dist/extensions/pi-subagents/src/shared/artifacts.ts +37 -7
- package/dist/extensions/pi-subagents/src/shared/atomic-json.ts +18 -43
- package/dist/extensions/pi-subagents/src/shared/child-transcript.ts +52 -0
- package/dist/extensions/pi-subagents/src/shared/env.ts +16 -0
- package/dist/extensions/pi-subagents/src/shared/file-system-retry.ts +47 -0
- package/dist/extensions/pi-subagents/src/shared/fork-context.ts +28 -3
- package/dist/extensions/pi-subagents/src/shared/launch-contract.ts +123 -0
- package/dist/extensions/pi-subagents/src/shared/model-info.ts +8 -5
- package/dist/extensions/pi-subagents/src/shared/settings.ts +9 -1
- package/dist/extensions/pi-subagents/src/shared/status-format.ts +7 -1
- package/dist/extensions/pi-subagents/src/shared/types.ts +522 -51
- package/dist/extensions/pi-subagents/src/shared/utils.ts +59 -53
- package/dist/extensions/pi-subagents/src/slash/delegation-adapters.ts +604 -0
- package/dist/extensions/pi-subagents/src/slash/delegation-json.ts +108 -0
- package/dist/extensions/pi-subagents/src/slash/delegation-request.ts +249 -0
- package/dist/extensions/pi-subagents/src/slash/prompt-template-bridge.ts +353 -345
- package/dist/extensions/pi-subagents/src/slash/prompt-workflows.ts +2 -2
- package/dist/extensions/pi-subagents/src/slash/selector.ts +147 -0
- package/dist/extensions/pi-subagents/src/slash/slash-commands.ts +265 -23
- package/dist/extensions/pi-subagents/src/slash/slash-live-state.ts +2 -2
- package/dist/extensions/pi-subagents/src/slash/subagents-admin.ts +428 -0
- package/dist/extensions/pi-subagents/src/tui/fleet-status.ts +362 -0
- package/dist/extensions/pi-subagents/src/tui/fleet-transcript.ts +472 -0
- package/dist/extensions/pi-subagents/src/tui/fleet.ts +664 -0
- package/dist/extensions/pi-subagents/src/tui/render.ts +115 -31
- package/dist/extensions/pi-subagents/src/watchdog/change-signature.ts +220 -0
- package/dist/extensions/pi-subagents/src/watchdog/child-status.ts +205 -0
- package/dist/extensions/pi-subagents/src/watchdog/emission-guard.ts +123 -0
- package/dist/extensions/pi-subagents/src/watchdog/lsp-diagnostics.ts +532 -0
- package/dist/extensions/pi-subagents/src/watchdog/model-selection.ts +167 -0
- package/dist/extensions/pi-subagents/src/watchdog/register-child.ts +117 -0
- package/dist/extensions/pi-subagents/src/watchdog/register-main.ts +433 -0
- package/dist/extensions/pi-subagents/src/watchdog/render.ts +54 -0
- package/dist/extensions/pi-subagents/src/watchdog/review.ts +298 -0
- package/dist/extensions/pi-subagents/src/watchdog/runtime.ts +714 -0
- package/dist/extensions/pi-subagents/src/watchdog/settings.ts +528 -0
- package/dist/extensions/pi-subagents/src/watchdog/tool-actions.ts +155 -0
- package/dist/extensions/pi-subagents/src/watchdog/turn-delta.ts +161 -0
- package/dist/extensions/pi-subagents/src/watchdog/types.ts +188 -0
- package/dist/extensions/pi-subagents/src/watchdog/warning-format.ts +73 -0
- package/dist/extensions/pi-subagents/test/e2e/real-session-subagent.test.ts +130 -2
- package/dist/extensions/pi-subagents/test/integration/acceptance-file-report.test.ts +439 -0
- package/dist/extensions/pi-subagents/test/integration/async-execution.test.ts +1632 -61
- package/dist/extensions/pi-subagents/test/integration/async-job-tracker.test.ts +54 -1
- package/dist/extensions/pi-subagents/test/integration/async-status.test.ts +112 -0
- package/dist/extensions/pi-subagents/test/integration/chain-clarify.test.ts +98 -1
- package/dist/extensions/pi-subagents/test/integration/chain-execution.test.ts +179 -9
- package/dist/extensions/pi-subagents/test/integration/detect-error.test.ts +16 -9
- package/dist/extensions/pi-subagents/test/integration/error-handling.test.ts +6 -5
- package/dist/extensions/pi-subagents/test/integration/fork-context-execution.test.ts +589 -9
- package/dist/extensions/pi-subagents/test/integration/intercom-result-delivery.test.ts +528 -21
- package/dist/extensions/pi-subagents/test/integration/parallel-execution.test.ts +227 -3
- package/dist/extensions/pi-subagents/test/integration/render-fork-badge.test.ts +235 -7
- package/dist/extensions/pi-subagents/test/integration/render-widget.test.ts +27 -0
- package/dist/extensions/pi-subagents/test/integration/result-watcher.test.ts +172 -2
- package/dist/extensions/pi-subagents/test/integration/single-execution.test.ts +1502 -18
- package/dist/extensions/pi-subagents/test/integration/slash-commands.test.ts +993 -4
- package/dist/extensions/pi-subagents/test/integration/slash-live-state.test.ts +27 -0
- package/dist/extensions/pi-subagents/test/integration/top-level-async.test.ts +7 -1
- package/dist/extensions/pi-subagents/test/support/helpers.ts +32 -0
- package/dist/extensions/pi-subagents/test/support/mock-pi-script.mjs +59 -2
- package/dist/extensions/pi-subagents/test/support/mock-pi.ts +32 -6
- package/dist/extensions/pi-subagents/test/support/real-session-child-cli.mjs +25 -24
- package/dist/extensions/pi-subagents/test/support/real-session-runner.ts +59 -35
- package/dist/extensions/pi-subagents/test/support/session-lease-child.mjs +42 -0
- package/dist/extensions/pi-subagents/test/unit/acceptance.test.ts +703 -69
- package/dist/extensions/pi-subagents/test/unit/accessible-dir.test.ts +82 -0
- package/dist/extensions/pi-subagents/test/unit/agent-disabled.test.ts +15 -15
- package/dist/extensions/pi-subagents/test/unit/agent-eject-disable.test.ts +66 -66
- package/dist/extensions/pi-subagents/test/unit/agent-frontmatter.test.ts +478 -19
- package/dist/extensions/pi-subagents/test/unit/agent-management.test.ts +228 -7
- package/dist/extensions/pi-subagents/test/unit/agent-memory.test.ts +1 -1
- package/dist/extensions/pi-subagents/test/unit/agent-overrides.test.ts +198 -78
- package/dist/extensions/pi-subagents/test/unit/async-execution.test.ts +15 -1
- package/dist/extensions/pi-subagents/test/unit/async-interrupt-action.test.ts +102 -7
- package/dist/extensions/pi-subagents/test/unit/async-resume.test.ts +439 -6
- package/dist/extensions/pi-subagents/test/unit/atomic-json.test.ts +41 -1
- package/dist/extensions/pi-subagents/test/unit/auto-drain.test.ts +79 -0
- package/dist/extensions/pi-subagents/test/unit/background-work.test.ts +285 -0
- package/dist/extensions/pi-subagents/test/unit/capability-ceiling-pi-args.test.ts +84 -0
- package/dist/extensions/pi-subagents/test/unit/capability-ceiling.test.ts +68 -0
- package/dist/extensions/pi-subagents/test/unit/chain-validation.test.ts +326 -0
- package/dist/extensions/pi-subagents/test/unit/child-protocol.test.ts +82 -0
- package/dist/extensions/pi-subagents/test/unit/child-transcript.test.ts +46 -4
- package/dist/extensions/pi-subagents/test/unit/completion-batcher.test.ts +3 -1
- package/dist/extensions/pi-subagents/test/unit/completion-dedupe.test.ts +9 -17
- package/dist/extensions/pi-subagents/test/unit/completion-guard.test.ts +175 -3
- package/dist/extensions/pi-subagents/test/unit/config-dir-runtime.test.ts +10 -5
- package/dist/extensions/pi-subagents/test/unit/control-channel.test.ts +126 -6
- package/dist/extensions/pi-subagents/test/unit/default-extensions.test.ts +219 -0
- package/dist/extensions/pi-subagents/test/unit/delegation-api.test.ts +913 -0
- package/dist/extensions/pi-subagents/test/unit/doctor.test.ts +13 -2
- package/dist/extensions/pi-subagents/test/unit/dynamic-fanout.test.ts +3 -3
- package/dist/extensions/pi-subagents/test/unit/fleet-status.test.ts +351 -0
- package/dist/extensions/pi-subagents/test/unit/fleet-transcript.test.ts +280 -0
- package/dist/extensions/pi-subagents/test/unit/fleet.test.ts +575 -0
- package/dist/extensions/pi-subagents/test/unit/foreground-control.test.ts +65 -0
- package/dist/extensions/pi-subagents/test/unit/fork-context.test.ts +94 -1
- package/dist/extensions/pi-subagents/test/unit/get-final-output.test.ts +23 -0
- package/dist/extensions/pi-subagents/test/unit/host-peer-runtime-imports.test.ts +157 -0
- package/dist/extensions/pi-subagents/test/unit/index-child-registration.test.ts +367 -5
- package/dist/extensions/pi-subagents/test/unit/intercom-bridge.test.ts +11 -0
- package/dist/extensions/pi-subagents/test/unit/model-fallback.test.ts +36 -0
- package/dist/extensions/pi-subagents/test/unit/model-info.test.ts +25 -3
- package/dist/extensions/pi-subagents/test/unit/model-scope.test.ts +1 -1
- package/dist/extensions/pi-subagents/test/unit/native-supervisor-channel.test.ts +341 -10
- package/dist/extensions/pi-subagents/test/unit/nested-control.test.ts +16 -0
- package/dist/extensions/pi-subagents/test/unit/nested-events.test.ts +52 -0
- package/dist/extensions/pi-subagents/test/unit/notify.test.ts +168 -7
- package/dist/extensions/pi-subagents/test/unit/package-manifest.test.ts +85 -7
- package/dist/extensions/pi-subagents/test/unit/parallel-handoff.test.ts +175 -0
- package/dist/extensions/pi-subagents/test/unit/path-resolution.test.ts +1 -1
- package/dist/extensions/pi-subagents/test/unit/pi-args.test.ts +243 -16
- package/dist/extensions/pi-subagents/test/unit/pi-coding-agent-dir.test.ts +79 -36
- package/dist/extensions/pi-subagents/test/unit/pi-spawn.test.ts +174 -56
- package/dist/extensions/pi-subagents/test/unit/preflight.test.ts +322 -0
- package/dist/extensions/pi-subagents/test/unit/process-terminal.test.ts +204 -0
- package/dist/extensions/pi-subagents/test/unit/recursion-guard.test.ts +20 -12
- package/dist/extensions/pi-subagents/test/unit/rpc.test.ts +117 -4
- package/dist/extensions/pi-subagents/test/unit/run-status.test.ts +40 -7
- package/dist/extensions/pi-subagents/test/unit/scheduled-runs.test.ts +48 -1
- package/dist/extensions/pi-subagents/test/unit/schemas.test.ts +21 -3
- package/dist/extensions/pi-subagents/test/unit/selector.test.ts +57 -0
- package/dist/extensions/pi-subagents/test/unit/session-lease.test.ts +326 -0
- package/dist/extensions/pi-subagents/test/unit/single-output.test.ts +101 -2
- package/dist/extensions/pi-subagents/test/unit/skills-fallback.test.ts +111 -1
- package/dist/extensions/pi-subagents/test/unit/spawn-budget.test.ts +124 -0
- package/dist/extensions/pi-subagents/test/unit/stale-run-reconciler.test.ts +6 -4
- package/dist/extensions/pi-subagents/test/unit/status-format.test.ts +7 -0
- package/dist/extensions/pi-subagents/test/unit/steering-action.test.ts +397 -0
- package/dist/extensions/pi-subagents/test/unit/steering-notices.test.ts +58 -0
- package/dist/extensions/pi-subagents/test/unit/steering.test.ts +173 -0
- package/dist/extensions/pi-subagents/test/unit/subagent-control.test.ts +25 -4
- package/dist/extensions/pi-subagents/test/unit/subagent-prompt-runtime.test.ts +390 -25
- package/dist/extensions/pi-subagents/test/unit/subagent-wait.test.ts +837 -0
- package/dist/extensions/pi-subagents/test/unit/task-intent.test.ts +86 -0
- package/dist/extensions/pi-subagents/test/unit/tool-budget.test.ts +15 -0
- package/dist/extensions/pi-subagents/test/unit/tool-description.test.ts +47 -1
- package/dist/extensions/pi-subagents/test/unit/turn-budget.test.ts +56 -10
- package/dist/extensions/pi-subagents/test/unit/watchdog-change-signature.test.ts +387 -0
- package/dist/extensions/pi-subagents/test/unit/watchdog-child-status.test.ts +110 -0
- package/dist/extensions/pi-subagents/test/unit/watchdog-emission-guard.test.ts +62 -0
- package/dist/extensions/pi-subagents/test/unit/watchdog-lsp-diagnostics.test.ts +144 -0
- package/dist/extensions/pi-subagents/test/unit/watchdog-model-selection.test.ts +121 -0
- package/dist/extensions/pi-subagents/test/unit/watchdog-render.test.ts +76 -0
- package/dist/extensions/pi-subagents/test/unit/watchdog-review.test.ts +327 -0
- package/dist/extensions/pi-subagents/test/unit/watchdog-runtime.test.ts +863 -0
- package/dist/extensions/pi-subagents/test/unit/watchdog-settings.test.ts +290 -0
- package/dist/extensions/pi-subagents/test/unit/watchdog-tool-actions.test.ts +91 -0
- package/dist/extensions/pi-subagents/test/unit/watchdog-turn-delta.test.ts +130 -0
- package/dist/extensions/pi-subagents/test/unit/widget-nested-render.test.ts +32 -4
- package/dist/extensions/pi-subagents/test/unit/worktree.test.ts +5 -1
- package/dist/extensions/pi-subagents/test/unit/writer-budget-guidance.test.ts +30 -0
- package/dist/extensions/question/batch.ts +39 -0
- package/dist/extensions/question/dialog-adapter.ts +23 -1
- package/dist/extensions/question/index.ts +237 -7
- package/dist/extensions/question/schemas.ts +28 -15
- package/dist/extensions/question/tests/batch.test.ts +26 -0
- package/dist/extensions/question/tests/ui-protocol.test.ts +23 -3
- package/dist/extensions/question/tui-adapter.ts +2 -3
- package/dist/extensions/question/types.ts +37 -0
- package/dist/extensions/question/ui-protocol.ts +3 -3
- package/dist/skills/batch-grill-me/SKILL.md +3 -1
- package/package.json +1 -1
|
@@ -8,11 +8,28 @@ import {
|
|
|
8
8
|
NATIVE_SUPERVISOR_TOOL_NAME,
|
|
9
9
|
createNativeSupervisorChannel,
|
|
10
10
|
ensureSupervisorChannelDir,
|
|
11
|
+
registerNativeSupervisorClient,
|
|
11
12
|
resolveSupervisorChannelDir,
|
|
12
13
|
} from "../../src/intercom/native-supervisor-channel.ts";
|
|
13
|
-
import
|
|
14
|
+
import {
|
|
15
|
+
SUBAGENT_CHILD_AGENT_ENV,
|
|
16
|
+
SUBAGENT_CHILD_INDEX_ENV,
|
|
17
|
+
SUBAGENT_ORCHESTRATOR_SESSION_ID_ENV,
|
|
18
|
+
SUBAGENT_ORCHESTRATOR_TARGET_ENV,
|
|
19
|
+
SUBAGENT_RUN_ID_ENV,
|
|
20
|
+
SUBAGENT_SUPERVISOR_CHANNEL_DIR_ENV,
|
|
21
|
+
} from "../../src/runs/shared/pi-args.ts";
|
|
22
|
+
import { INTERCOM_DETACH_REQUEST_EVENT, type SubagentState } from "../../src/shared/types.ts";
|
|
14
23
|
|
|
15
24
|
const createdChannels: string[] = [];
|
|
25
|
+
const savedEnv = {
|
|
26
|
+
[SUBAGENT_CHILD_AGENT_ENV]: process.env[SUBAGENT_CHILD_AGENT_ENV],
|
|
27
|
+
[SUBAGENT_CHILD_INDEX_ENV]: process.env[SUBAGENT_CHILD_INDEX_ENV],
|
|
28
|
+
[SUBAGENT_ORCHESTRATOR_SESSION_ID_ENV]: process.env[SUBAGENT_ORCHESTRATOR_SESSION_ID_ENV],
|
|
29
|
+
[SUBAGENT_ORCHESTRATOR_TARGET_ENV]: process.env[SUBAGENT_ORCHESTRATOR_TARGET_ENV],
|
|
30
|
+
[SUBAGENT_RUN_ID_ENV]: process.env[SUBAGENT_RUN_ID_ENV],
|
|
31
|
+
[SUBAGENT_SUPERVISOR_CHANNEL_DIR_ENV]: process.env[SUBAGENT_SUPERVISOR_CHANNEL_DIR_ENV],
|
|
32
|
+
};
|
|
16
33
|
|
|
17
34
|
function makeState(sessionId: string | null, ctx: unknown): SubagentState {
|
|
18
35
|
return {
|
|
@@ -31,7 +48,7 @@ function makeState(sessionId: string | null, ctx: unknown): SubagentState {
|
|
|
31
48
|
};
|
|
32
49
|
}
|
|
33
50
|
|
|
34
|
-
function writeRequest(input: { sessionId: string; runId: string; agent?: string; index?: number; message?: string }): string {
|
|
51
|
+
function writeRequest(input: { sessionId: string; runId: string; agent?: string; index?: number; message?: string; createdAt?: number; expiresAt?: number }): string {
|
|
35
52
|
const agent = input.agent ?? "worker";
|
|
36
53
|
const index = input.index ?? 0;
|
|
37
54
|
const channelDir = resolveSupervisorChannelDir(input.runId, agent, index);
|
|
@@ -41,7 +58,8 @@ function writeRequest(input: { sessionId: string; runId: string; agent?: string;
|
|
|
41
58
|
fs.writeFileSync(path.join(channelDir, "requests", `${requestId}.json`), JSON.stringify({
|
|
42
59
|
type: "subagent.supervisor.request",
|
|
43
60
|
id: requestId,
|
|
44
|
-
createdAt: Date.now(),
|
|
61
|
+
createdAt: input.createdAt ?? Date.now(),
|
|
62
|
+
...(input.expiresAt !== undefined ? { expiresAt: input.expiresAt } : {}),
|
|
45
63
|
reason: "need_decision",
|
|
46
64
|
message: input.message ?? "Need a decision",
|
|
47
65
|
expectsReply: true,
|
|
@@ -54,17 +72,51 @@ function writeRequest(input: { sessionId: string; runId: string; agent?: string;
|
|
|
54
72
|
return requestId;
|
|
55
73
|
}
|
|
56
74
|
|
|
75
|
+
function requestFile(runId: string, requestId: string, agent = "worker", index = 0): string {
|
|
76
|
+
return path.join(resolveSupervisorChannelDir(runId, agent, index), "requests", `${requestId}.json`);
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
function replyFile(runId: string, requestId: string, agent = "worker", index = 0): string {
|
|
80
|
+
return path.join(resolveSupervisorChannelDir(runId, agent, index), "replies", `${requestId}.json`);
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
function makeEmptyChannel(runId: string): string {
|
|
84
|
+
const channelDir = resolveSupervisorChannelDir(runId, "worker", 0);
|
|
85
|
+
createdChannels.push(channelDir);
|
|
86
|
+
ensureSupervisorChannelDir(channelDir);
|
|
87
|
+
return channelDir;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
function ageChannel(channelDir: string, ageMs: number): void {
|
|
91
|
+
const timestamp = new Date(Date.now() - ageMs);
|
|
92
|
+
for (const dir of [path.join(channelDir, "requests"), path.join(channelDir, "replies"), channelDir]) {
|
|
93
|
+
fs.utimesSync(dir, timestamp, timestamp);
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
function restoreEnv(): void {
|
|
98
|
+
for (const [key, value] of Object.entries(savedEnv)) {
|
|
99
|
+
if (value === undefined) delete process.env[key];
|
|
100
|
+
else process.env[key] = value;
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
|
|
57
104
|
afterEach(() => {
|
|
105
|
+
restoreEnv();
|
|
106
|
+
delete process.env.PI_INTERCOM_ASK_TIMEOUT_MS;
|
|
58
107
|
for (const channel of createdChannels.splice(0)) fs.rmSync(channel, { recursive: true, force: true });
|
|
59
108
|
});
|
|
60
109
|
|
|
61
110
|
describe("native supervisor channel", () => {
|
|
62
|
-
it("delivers requests only to the exact current session id", () => {
|
|
111
|
+
it("delivers requests only to the exact current session id and wakes the parent", () => {
|
|
63
112
|
const currentSessionId = `session-${randomUUID()}`;
|
|
64
113
|
const otherSessionId = `session-${randomUUID()}`;
|
|
65
114
|
const matchingId = writeRequest({ sessionId: currentSessionId, runId: `run-${randomUUID()}` });
|
|
66
115
|
const otherId = writeRequest({ sessionId: otherSessionId, runId: `run-${randomUUID()}` });
|
|
67
|
-
const sent: Array<{
|
|
116
|
+
const sent: Array<{
|
|
117
|
+
message: { content?: string; details?: { id?: string } };
|
|
118
|
+
options?: { triggerTurn?: boolean };
|
|
119
|
+
}> = [];
|
|
68
120
|
const registeredTools: string[] = [];
|
|
69
121
|
const ctx = {
|
|
70
122
|
cwd: process.cwd(),
|
|
@@ -78,7 +130,10 @@ describe("native supervisor channel", () => {
|
|
|
78
130
|
const pi = {
|
|
79
131
|
getAllTools: () => [],
|
|
80
132
|
registerTool: (tool: { name: string }) => { registeredTools.push(tool.name); },
|
|
81
|
-
sendMessage: (
|
|
133
|
+
sendMessage: (
|
|
134
|
+
message: { content?: string; details?: { id?: string } },
|
|
135
|
+
options?: { triggerTurn?: boolean },
|
|
136
|
+
) => { sent.push({ message, options }); },
|
|
82
137
|
getSessionName: () => "shared-name",
|
|
83
138
|
};
|
|
84
139
|
const channel = createNativeSupervisorChannel(pi as never, makeState(currentSessionId, ctx));
|
|
@@ -88,9 +143,162 @@ describe("native supervisor channel", () => {
|
|
|
88
143
|
channel.dispose();
|
|
89
144
|
|
|
90
145
|
assert.deepEqual(registeredTools, [NATIVE_SUPERVISOR_TOOL_NAME, "intercom"]);
|
|
91
|
-
assert.deepEqual(sent.map((message) => message.details?.id), [matchingId]);
|
|
146
|
+
assert.deepEqual(sent.map(({ message }) => message.details?.id), [matchingId]);
|
|
147
|
+
assert.deepEqual(sent[0]?.options, { triggerTurn: true });
|
|
92
148
|
assert.equal(channel.pending.has(matchingId), false, "disposed channel clears pending requests");
|
|
93
|
-
assert.equal(sent.some((message) => message.details?.id === otherId), false);
|
|
149
|
+
assert.equal(sent.some(({ message }) => message.details?.id === otherId), false);
|
|
150
|
+
});
|
|
151
|
+
|
|
152
|
+
it("prunes stale empty supervisor channel directories before polling", () => {
|
|
153
|
+
const currentSessionId = `session-${randomUUID()}`;
|
|
154
|
+
const staleEmptyChannel = makeEmptyChannel(`run-${randomUUID()}`);
|
|
155
|
+
ageChannel(staleEmptyChannel, 2 * 60 * 1000);
|
|
156
|
+
const sent: Array<{ details?: { id?: string } }> = [];
|
|
157
|
+
const ctx = {
|
|
158
|
+
cwd: process.cwd(),
|
|
159
|
+
hasUI: false,
|
|
160
|
+
sessionManager: {
|
|
161
|
+
getSessionId: () => currentSessionId,
|
|
162
|
+
getSessionFile: () => null,
|
|
163
|
+
getEntries: () => [],
|
|
164
|
+
},
|
|
165
|
+
};
|
|
166
|
+
const pi = {
|
|
167
|
+
getAllTools: () => [],
|
|
168
|
+
registerTool: () => {},
|
|
169
|
+
sendMessage: (message: { details?: { id?: string } }) => { sent.push(message); },
|
|
170
|
+
getSessionName: () => "shared-name",
|
|
171
|
+
};
|
|
172
|
+
const channel = createNativeSupervisorChannel(pi as never, makeState(currentSessionId, ctx));
|
|
173
|
+
|
|
174
|
+
channel.start();
|
|
175
|
+
channel.dispose();
|
|
176
|
+
|
|
177
|
+
assert.equal(fs.existsSync(staleEmptyChannel), false);
|
|
178
|
+
assert.deepEqual(sent, []);
|
|
179
|
+
});
|
|
180
|
+
|
|
181
|
+
it("preserves fresh empty and stale non-empty supervisor channel directories", () => {
|
|
182
|
+
const currentSessionId = `session-${randomUUID()}`;
|
|
183
|
+
const freshEmptyChannel = makeEmptyChannel(`run-${randomUUID()}`);
|
|
184
|
+
const staleWithReply = makeEmptyChannel(`run-${randomUUID()}`);
|
|
185
|
+
fs.writeFileSync(path.join(staleWithReply, "replies", "reply.json"), "{}");
|
|
186
|
+
ageChannel(staleWithReply, 2 * 60 * 1000);
|
|
187
|
+
const ctx = {
|
|
188
|
+
cwd: process.cwd(),
|
|
189
|
+
hasUI: false,
|
|
190
|
+
sessionManager: {
|
|
191
|
+
getSessionId: () => currentSessionId,
|
|
192
|
+
getSessionFile: () => null,
|
|
193
|
+
getEntries: () => [],
|
|
194
|
+
},
|
|
195
|
+
};
|
|
196
|
+
const pi = {
|
|
197
|
+
getAllTools: () => [],
|
|
198
|
+
registerTool: () => {},
|
|
199
|
+
sendMessage: () => {},
|
|
200
|
+
getSessionName: () => "shared-name",
|
|
201
|
+
};
|
|
202
|
+
const channel = createNativeSupervisorChannel(pi as never, makeState(currentSessionId, ctx));
|
|
203
|
+
|
|
204
|
+
channel.start();
|
|
205
|
+
channel.dispose();
|
|
206
|
+
|
|
207
|
+
assert.equal(fs.existsSync(freshEmptyChannel), true);
|
|
208
|
+
assert.equal(fs.existsSync(staleWithReply), true);
|
|
209
|
+
});
|
|
210
|
+
|
|
211
|
+
it("emits foreground detach only after displaying a pending supervisor request", () => {
|
|
212
|
+
const currentSessionId = `session-${randomUUID()}`;
|
|
213
|
+
const runId = `run-${randomUUID()}`;
|
|
214
|
+
const requestId = writeRequest({ sessionId: currentSessionId, runId, agent: "worker", index: 2 });
|
|
215
|
+
const log: string[] = [];
|
|
216
|
+
const emitted: Array<{ channel: string; payload: { requestId?: string; runId?: string; agent?: string; childIndex?: number } }> = [];
|
|
217
|
+
const ctx = {
|
|
218
|
+
cwd: process.cwd(),
|
|
219
|
+
hasUI: false,
|
|
220
|
+
sessionManager: {
|
|
221
|
+
getSessionId: () => currentSessionId,
|
|
222
|
+
getSessionFile: () => null,
|
|
223
|
+
getEntries: () => [],
|
|
224
|
+
},
|
|
225
|
+
};
|
|
226
|
+
const pi = {
|
|
227
|
+
getAllTools: () => [],
|
|
228
|
+
registerTool: () => {},
|
|
229
|
+
sendMessage: () => { log.push("send"); },
|
|
230
|
+
events: {
|
|
231
|
+
emit: (channel: string, payload: { requestId?: string; runId?: string; agent?: string; childIndex?: number }) => {
|
|
232
|
+
log.push("emit");
|
|
233
|
+
emitted.push({ channel, payload });
|
|
234
|
+
},
|
|
235
|
+
},
|
|
236
|
+
getSessionName: () => "shared-name",
|
|
237
|
+
};
|
|
238
|
+
const channel = createNativeSupervisorChannel(pi as never, makeState(currentSessionId, ctx));
|
|
239
|
+
|
|
240
|
+
channel.start();
|
|
241
|
+
try {
|
|
242
|
+
assert.deepEqual(log, ["send", "emit"]);
|
|
243
|
+
assert.deepEqual(emitted, [{
|
|
244
|
+
channel: INTERCOM_DETACH_REQUEST_EVENT,
|
|
245
|
+
payload: { requestId, runId, agent: "worker", childIndex: 2 },
|
|
246
|
+
}]);
|
|
247
|
+
assert.equal(channel.pending.has(requestId), true);
|
|
248
|
+
} finally {
|
|
249
|
+
channel.dispose();
|
|
250
|
+
}
|
|
251
|
+
});
|
|
252
|
+
|
|
253
|
+
it("re-arms remembered foreground attention for each blocking supervisor request", async () => {
|
|
254
|
+
const currentSessionId = `session-${randomUUID()}`;
|
|
255
|
+
const runId = `run-${randomUUID()}`;
|
|
256
|
+
const requestId = writeRequest({ sessionId: currentSessionId, runId });
|
|
257
|
+
const registeredTools = new Map<string, { execute: (_id: string, params: { action: string; replyTo?: string; message?: string }) => Promise<unknown> }>();
|
|
258
|
+
const ctx = {
|
|
259
|
+
cwd: process.cwd(),
|
|
260
|
+
hasUI: false,
|
|
261
|
+
sessionManager: {
|
|
262
|
+
getSessionId: () => currentSessionId,
|
|
263
|
+
getSessionFile: () => null,
|
|
264
|
+
getEntries: () => [],
|
|
265
|
+
},
|
|
266
|
+
};
|
|
267
|
+
const state = makeState(currentSessionId, ctx);
|
|
268
|
+
state.foregroundRuns = new Map([[runId, {
|
|
269
|
+
runId,
|
|
270
|
+
mode: "single",
|
|
271
|
+
cwd: process.cwd(),
|
|
272
|
+
sessionId: currentSessionId,
|
|
273
|
+
updatedAt: 1,
|
|
274
|
+
children: [{ agent: "worker", index: 0, status: "detached", updatedAt: 1 }],
|
|
275
|
+
}]]);
|
|
276
|
+
const pi = {
|
|
277
|
+
getAllTools: () => [...registeredTools.keys()].map((name) => ({ name })),
|
|
278
|
+
registerTool: (tool: { name: string; execute: (_id: string, params: { action: string; replyTo?: string; message?: string }) => Promise<unknown> }) => {
|
|
279
|
+
registeredTools.set(tool.name, tool);
|
|
280
|
+
},
|
|
281
|
+
sendMessage: () => {},
|
|
282
|
+
getSessionName: () => "shared-name",
|
|
283
|
+
};
|
|
284
|
+
const channel = createNativeSupervisorChannel(pi as never, state);
|
|
285
|
+
|
|
286
|
+
try {
|
|
287
|
+
channel.start();
|
|
288
|
+
const child = state.foregroundRuns.get(runId)!.children[0]!;
|
|
289
|
+
assert.equal(child.activityState, "needs_attention");
|
|
290
|
+
assert.equal(child.currentTool, "contact_supervisor");
|
|
291
|
+
|
|
292
|
+
await registeredTools.get(NATIVE_SUPERVISOR_TOOL_NAME)!.execute("reply", {
|
|
293
|
+
action: "reply",
|
|
294
|
+
replyTo: requestId,
|
|
295
|
+
message: "Approved",
|
|
296
|
+
});
|
|
297
|
+
assert.equal(child.activityState, undefined);
|
|
298
|
+
assert.equal(child.currentTool, undefined);
|
|
299
|
+
} finally {
|
|
300
|
+
channel.dispose();
|
|
301
|
+
}
|
|
94
302
|
});
|
|
95
303
|
|
|
96
304
|
it("matches supervisor requests against the runtime session id instead of persisted session file path", () => {
|
|
@@ -151,12 +359,135 @@ describe("native supervisor channel", () => {
|
|
|
151
359
|
|
|
152
360
|
assert.deepEqual([...registeredTools.keys()], [NATIVE_SUPERVISOR_TOOL_NAME]);
|
|
153
361
|
await registeredTools.get(NATIVE_SUPERVISOR_TOOL_NAME)?.execute("reply", { action: "reply", replyTo: requestId, message: "Approved" });
|
|
154
|
-
const
|
|
155
|
-
const reply = JSON.parse(fs.readFileSync(replyFile, "utf-8")) as { message?: string; requestId?: string };
|
|
362
|
+
const reply = JSON.parse(fs.readFileSync(replyFile(runId, requestId), "utf-8")) as { message?: string; requestId?: string };
|
|
156
363
|
assert.equal(reply.requestId, requestId);
|
|
157
364
|
assert.equal(reply.message, "Approved");
|
|
365
|
+
assert.equal(fs.existsSync(requestFile(runId, requestId)), false);
|
|
366
|
+
} finally {
|
|
367
|
+
channel.dispose();
|
|
368
|
+
}
|
|
369
|
+
});
|
|
370
|
+
|
|
371
|
+
it("suppresses resolved, expired, and inactive requests before displaying them", () => {
|
|
372
|
+
const currentSessionId = `session-${randomUUID()}`;
|
|
373
|
+
const resolvedRunId = `run-${randomUUID()}`;
|
|
374
|
+
const expiredRunId = `run-${randomUUID()}`;
|
|
375
|
+
const inactiveRunId = `run-${randomUUID()}`;
|
|
376
|
+
const resolvedId = writeRequest({ sessionId: currentSessionId, runId: resolvedRunId });
|
|
377
|
+
const expiredId = writeRequest({ sessionId: currentSessionId, runId: expiredRunId, expiresAt: Date.now() - 1 });
|
|
378
|
+
const inactiveId = writeRequest({ sessionId: currentSessionId, runId: inactiveRunId });
|
|
379
|
+
fs.writeFileSync(replyFile(resolvedRunId, resolvedId), JSON.stringify({
|
|
380
|
+
type: "subagent.supervisor.reply",
|
|
381
|
+
requestId: resolvedId,
|
|
382
|
+
createdAt: Date.now(),
|
|
383
|
+
message: "Already handled",
|
|
384
|
+
}), "utf-8");
|
|
385
|
+
const sent: Array<{ details?: { id?: string } }> = [];
|
|
386
|
+
const ctx = {
|
|
387
|
+
cwd: process.cwd(),
|
|
388
|
+
hasUI: false,
|
|
389
|
+
sessionManager: {
|
|
390
|
+
getSessionId: () => currentSessionId,
|
|
391
|
+
getSessionFile: () => null,
|
|
392
|
+
getEntries: () => [],
|
|
393
|
+
},
|
|
394
|
+
};
|
|
395
|
+
const state = makeState(currentSessionId, ctx);
|
|
396
|
+
state.foregroundRuns = new Map([[inactiveRunId, {
|
|
397
|
+
runId: inactiveRunId,
|
|
398
|
+
mode: "single",
|
|
399
|
+
cwd: process.cwd(),
|
|
400
|
+
updatedAt: Date.now(),
|
|
401
|
+
children: [{ agent: "worker", index: 0, status: "completed", updatedAt: Date.now() }],
|
|
402
|
+
}]]);
|
|
403
|
+
const pi = {
|
|
404
|
+
getAllTools: () => [],
|
|
405
|
+
registerTool: () => {},
|
|
406
|
+
sendMessage: (message: { details?: { id?: string } }) => { sent.push(message); },
|
|
407
|
+
getSessionName: () => "shared-name",
|
|
408
|
+
};
|
|
409
|
+
const channel = createNativeSupervisorChannel(pi as never, state);
|
|
410
|
+
|
|
411
|
+
channel.start();
|
|
412
|
+
channel.dispose();
|
|
413
|
+
|
|
414
|
+
assert.deepEqual(sent, []);
|
|
415
|
+
assert.equal(fs.existsSync(requestFile(resolvedRunId, resolvedId)), false);
|
|
416
|
+
assert.equal(fs.existsSync(requestFile(expiredRunId, expiredId)), false);
|
|
417
|
+
assert.equal(fs.existsSync(requestFile(inactiveRunId, inactiveId)), false);
|
|
418
|
+
});
|
|
419
|
+
|
|
420
|
+
it("refreshes pending requests before listing or replying", async () => {
|
|
421
|
+
const currentSessionId = `session-${randomUUID()}`;
|
|
422
|
+
const runId = `run-${randomUUID()}`;
|
|
423
|
+
const requestId = writeRequest({ sessionId: currentSessionId, runId });
|
|
424
|
+
const registeredTools = new Map<string, { execute: (_id: string, params: { action: string; replyTo?: string; message?: string }) => Promise<{ content: Array<{ text: string }>; details?: { pending?: unknown[] } }> }>();
|
|
425
|
+
const sent: Array<{ details?: { id?: string } }> = [];
|
|
426
|
+
const ctx = {
|
|
427
|
+
cwd: process.cwd(),
|
|
428
|
+
hasUI: false,
|
|
429
|
+
sessionManager: {
|
|
430
|
+
getSessionId: () => currentSessionId,
|
|
431
|
+
getSessionFile: () => null,
|
|
432
|
+
getEntries: () => [],
|
|
433
|
+
},
|
|
434
|
+
};
|
|
435
|
+
const pi = {
|
|
436
|
+
getAllTools: () => [...registeredTools.keys()].map((name) => ({ name })),
|
|
437
|
+
registerTool: (tool: { name: string; execute: (_id: string, params: { action: string; replyTo?: string; message?: string }) => Promise<{ content: Array<{ text: string }>; details?: { pending?: unknown[] } }> }) => {
|
|
438
|
+
registeredTools.set(tool.name, tool);
|
|
439
|
+
},
|
|
440
|
+
sendMessage: (message: { details?: { id?: string } }) => { sent.push(message); },
|
|
441
|
+
getSessionName: () => "shared-name",
|
|
442
|
+
};
|
|
443
|
+
const channel = createNativeSupervisorChannel(pi as never, makeState(currentSessionId, ctx));
|
|
444
|
+
|
|
445
|
+
try {
|
|
446
|
+
channel.start();
|
|
447
|
+
assert.deepEqual(sent.map((message) => message.details?.id), [requestId]);
|
|
448
|
+
assert.equal(channel.pending.has(requestId), true);
|
|
449
|
+
|
|
450
|
+
fs.rmSync(requestFile(runId, requestId), { force: true });
|
|
451
|
+
const pendingResult = await registeredTools.get(NATIVE_SUPERVISOR_TOOL_NAME)!.execute("pending", { action: "pending" });
|
|
452
|
+
|
|
453
|
+
assert.match(pendingResult.content[0]!.text, /No pending supervisor requests/);
|
|
454
|
+
assert.deepEqual(pendingResult.details?.pending, []);
|
|
455
|
+
assert.equal(channel.pending.has(requestId), false);
|
|
456
|
+
await assert.rejects(
|
|
457
|
+
() => registeredTools.get(NATIVE_SUPERVISOR_TOOL_NAME)!.execute("reply", { action: "reply", replyTo: requestId, message: "Too late" }),
|
|
458
|
+
new RegExp(`No pending supervisor request found for replyTo '${requestId}'`),
|
|
459
|
+
);
|
|
158
460
|
} finally {
|
|
159
461
|
channel.dispose();
|
|
160
462
|
}
|
|
161
463
|
});
|
|
464
|
+
|
|
465
|
+
it("removes the request file when a child supervisor ask is cancelled", async () => {
|
|
466
|
+
const runId = `run-${randomUUID()}`;
|
|
467
|
+
const channelDir = resolveSupervisorChannelDir(runId, "worker", 0);
|
|
468
|
+
createdChannels.push(channelDir);
|
|
469
|
+
process.env[SUBAGENT_ORCHESTRATOR_TARGET_ENV] = "shared-name";
|
|
470
|
+
process.env[SUBAGENT_ORCHESTRATOR_SESSION_ID_ENV] = "session-parent";
|
|
471
|
+
process.env[SUBAGENT_SUPERVISOR_CHANNEL_DIR_ENV] = channelDir;
|
|
472
|
+
process.env[SUBAGENT_RUN_ID_ENV] = runId;
|
|
473
|
+
process.env[SUBAGENT_CHILD_AGENT_ENV] = "worker";
|
|
474
|
+
process.env[SUBAGENT_CHILD_INDEX_ENV] = "0";
|
|
475
|
+
const registeredTools = new Map<string, { execute: (_id: string, params: { reason: string; message?: string }, signal?: AbortSignal) => Promise<unknown> | unknown }>();
|
|
476
|
+
const pi = {
|
|
477
|
+
getAllTools: () => [...registeredTools.keys()].map((name) => ({ name })),
|
|
478
|
+
registerTool: (tool: { name: string; execute: (_id: string, params: { reason: string; message?: string }, signal?: AbortSignal) => Promise<unknown> | unknown }) => {
|
|
479
|
+
registeredTools.set(tool.name, tool);
|
|
480
|
+
},
|
|
481
|
+
};
|
|
482
|
+
registerNativeSupervisorClient(pi as never, { includeIntercomFallback: false });
|
|
483
|
+
const controller = new AbortController();
|
|
484
|
+
controller.abort();
|
|
485
|
+
|
|
486
|
+
await assert.rejects(
|
|
487
|
+
() => registeredTools.get("contact_supervisor")!.execute("contact", { reason: "need_decision", message: "Need a decision" }, controller.signal),
|
|
488
|
+
/Supervisor request cancelled/,
|
|
489
|
+
);
|
|
490
|
+
|
|
491
|
+
assert.deepEqual(fs.readdirSync(path.join(channelDir, "requests")), []);
|
|
492
|
+
});
|
|
162
493
|
});
|
|
@@ -301,6 +301,22 @@ describe("nested control routing", () => {
|
|
|
301
301
|
}
|
|
302
302
|
});
|
|
303
303
|
|
|
304
|
+
it("rejects stopped nested runs before attempting revival", async () => {
|
|
305
|
+
const root = fs.mkdtempSync(path.join(os.tmpdir(), "pi-nested-stopped-resume-"));
|
|
306
|
+
try {
|
|
307
|
+
const route = createNestedRun("nested-stopped-resume", "stopped", { sessionFile: path.join(root, "missing-session.jsonl") });
|
|
308
|
+
|
|
309
|
+
const result = await createExecutor(stateWithNestedRoute(route), [{ name: "worker", description: "Worker", prompt: "Do work" }])
|
|
310
|
+
.execute("resume", { action: "resume", id: "nested-stopped-resume", message: "continue" }, new AbortController().signal, undefined, ctx(root));
|
|
311
|
+
|
|
312
|
+
assert.equal(result.isError, true);
|
|
313
|
+
assert.match(text(result), /was stopped and cannot be resumed/);
|
|
314
|
+
assert.doesNotMatch(text(result), /session file/);
|
|
315
|
+
} finally {
|
|
316
|
+
fs.rmSync(root, { recursive: true, force: true });
|
|
317
|
+
}
|
|
318
|
+
});
|
|
319
|
+
|
|
304
320
|
it("rejects terminal nested resume session files outside trusted roots", async () => {
|
|
305
321
|
const root = fs.mkdtempSync(path.join(os.tmpdir(), "pi-nested-terminal-untrusted-"));
|
|
306
322
|
try {
|
|
@@ -7,6 +7,7 @@ import {
|
|
|
7
7
|
buildNestedRouteIndex,
|
|
8
8
|
createNestedRoute,
|
|
9
9
|
hasLiveNestedDescendants,
|
|
10
|
+
nestedSummaryFromAsyncStatus,
|
|
10
11
|
parseNestedEventRecords,
|
|
11
12
|
projectNestedEvents,
|
|
12
13
|
resolveNestedParentAddressFromEnv,
|
|
@@ -326,4 +327,55 @@ describe("nested event parsing and projection", () => {
|
|
|
326
327
|
assert.equal(records.length, 1);
|
|
327
328
|
assert.equal(records[0]?.child.id, "jsonl-good");
|
|
328
329
|
});
|
|
330
|
+
|
|
331
|
+
|
|
332
|
+
it("sanitizes malformed process-terminal proofs in nested status summaries", () => {
|
|
333
|
+
const summary = nestedSummaryFromAsyncStatus({
|
|
334
|
+
runId: "child-run",
|
|
335
|
+
mode: "single",
|
|
336
|
+
state: "complete",
|
|
337
|
+
startedAt: 1,
|
|
338
|
+
processTerminal: { version: 1, state: "bogus", runId: "child-run", runnerProcessInstanceId: "runner-1" } as never,
|
|
339
|
+
steps: [{
|
|
340
|
+
agent: "worker",
|
|
341
|
+
status: "complete",
|
|
342
|
+
processTerminal: { version: 1, state: "observed", runId: "wrong-run", runnerProcessInstanceId: "runner-1" } as never,
|
|
343
|
+
}],
|
|
344
|
+
}, "/tmp/child-run", { id: "child-run", parentRunId: "parent-run", depth: 1, mode: "single", ts: 2 });
|
|
345
|
+
|
|
346
|
+
assert.equal(summary.processTerminal?.state, "unknown");
|
|
347
|
+
assert.equal(summary.processTerminal?.reason, "proof-write-failed");
|
|
348
|
+
assert.equal(summary.steps?.[0]?.processTerminal?.state, "unknown");
|
|
349
|
+
assert.equal(summary.steps?.[0]?.processTerminal?.reason, "proof-write-failed");
|
|
350
|
+
});
|
|
351
|
+
|
|
352
|
+
it("removes evicted status files without replaying completed children", () => {
|
|
353
|
+
const route = trackRoute();
|
|
354
|
+
for (let index = 0; index < 1000; index++) {
|
|
355
|
+
writeNestedEvent(route, {
|
|
356
|
+
type: "subagent.nested.updated",
|
|
357
|
+
ts: index + 1,
|
|
358
|
+
parentRunId: "root-run",
|
|
359
|
+
parentStepIndex: 1,
|
|
360
|
+
child: child("nested-retained", "running", index + 1),
|
|
361
|
+
});
|
|
362
|
+
}
|
|
363
|
+
writeNestedEvent(route, {
|
|
364
|
+
type: "subagent.nested.completed",
|
|
365
|
+
ts: 1001,
|
|
366
|
+
parentRunId: "root-run",
|
|
367
|
+
parentStepIndex: 1,
|
|
368
|
+
child: child("nested-retained", "complete", 1001),
|
|
369
|
+
});
|
|
370
|
+
|
|
371
|
+
assert.equal(fs.readdirSync(route.eventSink).length, 1001);
|
|
372
|
+
const firstProjection = projectNestedEvents(route);
|
|
373
|
+
assert.equal(firstProjection.processedEvents.length, 1000);
|
|
374
|
+
assert.equal(fs.readdirSync(route.eventSink).length, 1000);
|
|
375
|
+
assert.equal(firstProjection.children[0]?.state, "complete");
|
|
376
|
+
|
|
377
|
+
const secondProjection = projectNestedEvents(route);
|
|
378
|
+
assert.deepEqual(secondProjection, firstProjection);
|
|
379
|
+
assert.equal(secondProjection.children[0]?.state, "complete");
|
|
380
|
+
});
|
|
329
381
|
});
|