@selesai/code 0.3.0 → 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/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/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/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/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/history.ts +2 -1
- package/dist/extensions/pi-powerline-footer/index.ts +9 -16
- package/dist/extensions/pi-powerline-footer/welcome.ts +23 -16
- package/dist/extensions/pi-powerline-footer/working-vibes.ts +2 -9
- 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/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 +100 -15
- 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/src/changelog-notice.ts +5 -2
- package/dist/extensions/pi-web-agent/src/presentation/config-store.ts +6 -4
- 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/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/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 +1 -1
|
@@ -0,0 +1,470 @@
|
|
|
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 { afterEach, describe, it } from "node:test";
|
|
6
|
+
import registerFanoutChildSubagentExtension from "../../src/extension/fanout-child.ts";
|
|
7
|
+
import { createSubagentExecutor } from "../../src/runs/foreground/subagent-executor.ts";
|
|
8
|
+
import { createNestedRoute, projectNestedEvents, readNestedControlRequests, readNestedControlResults, writeNestedControlRequest, writeNestedControlResult, writeNestedEvent } from "../../src/runs/shared/nested-events.ts";
|
|
9
|
+
import {
|
|
10
|
+
SUBAGENT_CHILD_ENV,
|
|
11
|
+
SUBAGENT_FANOUT_CHILD_ENV,
|
|
12
|
+
SUBAGENT_PARENT_CAPABILITY_TOKEN_ENV,
|
|
13
|
+
SUBAGENT_PARENT_CHILD_INDEX_ENV,
|
|
14
|
+
SUBAGENT_PARENT_CONTROL_INBOX_ENV,
|
|
15
|
+
SUBAGENT_PARENT_EVENT_SINK_ENV,
|
|
16
|
+
SUBAGENT_PARENT_ROOT_RUN_ID_ENV,
|
|
17
|
+
SUBAGENT_PARENT_RUN_ID_ENV,
|
|
18
|
+
} from "../../src/runs/shared/pi-args.ts";
|
|
19
|
+
import { ASYNC_DIR, type SubagentState } from "../../src/shared/types.ts";
|
|
20
|
+
|
|
21
|
+
const routeRoots: string[] = [];
|
|
22
|
+
const savedEnv = {
|
|
23
|
+
[SUBAGENT_CHILD_ENV]: process.env[SUBAGENT_CHILD_ENV],
|
|
24
|
+
[SUBAGENT_FANOUT_CHILD_ENV]: process.env[SUBAGENT_FANOUT_CHILD_ENV],
|
|
25
|
+
[SUBAGENT_PARENT_EVENT_SINK_ENV]: process.env[SUBAGENT_PARENT_EVENT_SINK_ENV],
|
|
26
|
+
[SUBAGENT_PARENT_CONTROL_INBOX_ENV]: process.env[SUBAGENT_PARENT_CONTROL_INBOX_ENV],
|
|
27
|
+
[SUBAGENT_PARENT_ROOT_RUN_ID_ENV]: process.env[SUBAGENT_PARENT_ROOT_RUN_ID_ENV],
|
|
28
|
+
[SUBAGENT_PARENT_CAPABILITY_TOKEN_ENV]: process.env[SUBAGENT_PARENT_CAPABILITY_TOKEN_ENV],
|
|
29
|
+
[SUBAGENT_PARENT_RUN_ID_ENV]: process.env[SUBAGENT_PARENT_RUN_ID_ENV],
|
|
30
|
+
[SUBAGENT_PARENT_CHILD_INDEX_ENV]: process.env[SUBAGENT_PARENT_CHILD_INDEX_ENV],
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
afterEach(() => {
|
|
34
|
+
for (const root of routeRoots.splice(0)) fs.rmSync(root, { recursive: true, force: true });
|
|
35
|
+
for (const [key, value] of Object.entries(savedEnv)) {
|
|
36
|
+
if (value === undefined) delete process.env[key];
|
|
37
|
+
else process.env[key] = value;
|
|
38
|
+
}
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
function createState(): SubagentState {
|
|
42
|
+
return {
|
|
43
|
+
baseCwd: "",
|
|
44
|
+
currentSessionId: null,
|
|
45
|
+
asyncJobs: new Map(),
|
|
46
|
+
foregroundRuns: new Map(),
|
|
47
|
+
foregroundControls: new Map(),
|
|
48
|
+
lastForegroundControlId: null,
|
|
49
|
+
pendingForegroundControlNotices: new Map(),
|
|
50
|
+
cleanupTimers: new Map(),
|
|
51
|
+
lastUiContext: null,
|
|
52
|
+
poller: null,
|
|
53
|
+
completionSeen: new Map(),
|
|
54
|
+
watcher: null,
|
|
55
|
+
watcherRestartTimer: null,
|
|
56
|
+
resultFileCoalescer: { schedule: () => false, clear: () => {} },
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
function createExecutor(state = createState(), agents: Array<Record<string, unknown>> = [], allowMutatingManagementActions = true, events: any = { emit() {}, on() { return () => {}; } }) {
|
|
61
|
+
return createSubagentExecutor({
|
|
62
|
+
pi: { events, getSessionName() { return "parent"; } } as any,
|
|
63
|
+
state,
|
|
64
|
+
config: { maxSubagentDepth: 2, control: {}, intercomBridge: {} } as any,
|
|
65
|
+
asyncByDefault: false,
|
|
66
|
+
tempArtifactsDir: os.tmpdir(),
|
|
67
|
+
getSubagentSessionRoot: (parentSessionFile) => parentSessionFile ? path.join(path.dirname(parentSessionFile), path.basename(parentSessionFile, ".jsonl")) : os.tmpdir(),
|
|
68
|
+
expandTilde: (value) => value,
|
|
69
|
+
discoverAgents: () => ({ agents: agents as any }),
|
|
70
|
+
allowMutatingManagementActions,
|
|
71
|
+
});
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
function ctx(root: string, sessionFile: string | null = null) {
|
|
75
|
+
return {
|
|
76
|
+
cwd: root,
|
|
77
|
+
hasUI: false,
|
|
78
|
+
sessionManager: { getSessionId() { return "session"; }, getSessionFile() { return sessionFile; } },
|
|
79
|
+
modelRegistry: { getAvailable() { return []; } },
|
|
80
|
+
} as any;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
function createNestedRun(id = "nested-live", state: "running" | "complete" | "failed" | "paused" = "running", extras: Record<string, unknown> = {}) {
|
|
84
|
+
const route = createNestedRoute("root-control");
|
|
85
|
+
routeRoots.push(path.dirname(route.eventSink));
|
|
86
|
+
writeNestedEvent(route, {
|
|
87
|
+
type: state === "running" ? "subagent.nested.updated" : "subagent.nested.completed",
|
|
88
|
+
ts: 100,
|
|
89
|
+
parentRunId: "root-control",
|
|
90
|
+
parentStepIndex: 0,
|
|
91
|
+
child: { id, parentRunId: "root-control", parentStepIndex: 0, depth: 1, path: [{ runId: "root-control", stepIndex: 0 }], state, agent: "worker", ownerState: state === "running" ? "live" : "gone", ...extras },
|
|
92
|
+
});
|
|
93
|
+
return route;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
function stateWithNestedRoute(route: ReturnType<typeof createNestedRoute>): SubagentState {
|
|
97
|
+
const state = createState();
|
|
98
|
+
state.foregroundControls.set(route.rootRunId, {
|
|
99
|
+
runId: route.rootRunId,
|
|
100
|
+
mode: "single",
|
|
101
|
+
startedAt: 1,
|
|
102
|
+
updatedAt: 1,
|
|
103
|
+
nestedRoute: route,
|
|
104
|
+
});
|
|
105
|
+
state.lastForegroundControlId = route.rootRunId;
|
|
106
|
+
return state;
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
function setNestedRouteEnv(route: ReturnType<typeof createNestedRoute>, parentRunId = route.rootRunId) {
|
|
110
|
+
process.env[SUBAGENT_PARENT_EVENT_SINK_ENV] = route.eventSink;
|
|
111
|
+
process.env[SUBAGENT_PARENT_CONTROL_INBOX_ENV] = route.controlInbox;
|
|
112
|
+
process.env[SUBAGENT_PARENT_ROOT_RUN_ID_ENV] = route.rootRunId;
|
|
113
|
+
process.env[SUBAGENT_PARENT_CAPABILITY_TOKEN_ENV] = route.capabilityToken;
|
|
114
|
+
process.env[SUBAGENT_PARENT_RUN_ID_ENV] = parentRunId;
|
|
115
|
+
process.env[SUBAGENT_PARENT_CHILD_INDEX_ENV] = "0";
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
function text(result: Awaited<ReturnType<ReturnType<typeof createExecutor>["execute"]>>): string {
|
|
119
|
+
return result.content[0]?.type === "text" ? result.content[0].text : "";
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
async function waitFor(predicate: () => boolean, timeoutMs = 1_000): Promise<void> {
|
|
123
|
+
const deadline = Date.now() + timeoutMs;
|
|
124
|
+
while (Date.now() < deadline) {
|
|
125
|
+
if (predicate()) return;
|
|
126
|
+
await new Promise((resolve) => setTimeout(resolve, 25));
|
|
127
|
+
}
|
|
128
|
+
assert.equal(predicate(), true);
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
describe("nested control routing", () => {
|
|
132
|
+
it("routes interrupt to an explicit nested id through the control inbox", async () => {
|
|
133
|
+
const root = fs.mkdtempSync(path.join(os.tmpdir(), "pi-nested-control-"));
|
|
134
|
+
try {
|
|
135
|
+
const route = createNestedRun();
|
|
136
|
+
const executor = createExecutor(stateWithNestedRoute(route));
|
|
137
|
+
setTimeout(() => {
|
|
138
|
+
const request = readNestedControlRequests(route)[0];
|
|
139
|
+
assert.ok(request, "expected a nested control request");
|
|
140
|
+
writeNestedControlResult(route, { ts: Date.now(), requestId: request.requestId, targetRunId: request.targetRunId, ok: true, message: "nested interrupt accepted" });
|
|
141
|
+
}, 50);
|
|
142
|
+
|
|
143
|
+
const result = await executor.execute("interrupt", { action: "interrupt", id: "nested-live" }, new AbortController().signal, undefined, ctx(root));
|
|
144
|
+
assert.equal(result.isError, undefined);
|
|
145
|
+
assert.match(text(result), /nested interrupt accepted/);
|
|
146
|
+
} finally {
|
|
147
|
+
fs.rmSync(root, { recursive: true, force: true });
|
|
148
|
+
}
|
|
149
|
+
});
|
|
150
|
+
|
|
151
|
+
it("renders nested children in foreground status output", async () => {
|
|
152
|
+
const root = fs.mkdtempSync(path.join(os.tmpdir(), "pi-nested-foreground-status-"));
|
|
153
|
+
try {
|
|
154
|
+
const route = createNestedRun("nested-foreground");
|
|
155
|
+
const state = createState();
|
|
156
|
+
state.foregroundControls.set("root-control", {
|
|
157
|
+
runId: "root-control",
|
|
158
|
+
mode: "single",
|
|
159
|
+
startedAt: 1,
|
|
160
|
+
updatedAt: 1,
|
|
161
|
+
currentAgent: "orchestrator",
|
|
162
|
+
currentIndex: 0,
|
|
163
|
+
nestedRoute: route,
|
|
164
|
+
});
|
|
165
|
+
state.lastForegroundControlId = "root-control";
|
|
166
|
+
|
|
167
|
+
const result = await createExecutor(state).execute("status", { action: "status", id: "root-control" }, new AbortController().signal, undefined, ctx(root));
|
|
168
|
+
|
|
169
|
+
assert.equal(result.isError, undefined);
|
|
170
|
+
assert.match(text(result), /Run: root-control/);
|
|
171
|
+
assert.match(text(result), /↳ worker \[nested-foreground\] running/);
|
|
172
|
+
assert.match(text(result), /Status: subagent\(\{ action: "status", id: "nested-foreground" \}\)/);
|
|
173
|
+
} finally {
|
|
174
|
+
fs.rmSync(root, { recursive: true, force: true });
|
|
175
|
+
}
|
|
176
|
+
});
|
|
177
|
+
|
|
178
|
+
it("scopes child-safe nested status lookup to the inherited route and child address", async () => {
|
|
179
|
+
const root = fs.mkdtempSync(path.join(os.tmpdir(), "pi-nested-child-scope-"));
|
|
180
|
+
try {
|
|
181
|
+
const allowedRoute = createNestedRun("shared-nested");
|
|
182
|
+
setNestedRouteEnv(allowedRoute, "root-control");
|
|
183
|
+
const outsideRoute = createNestedRoute("root-outside");
|
|
184
|
+
routeRoots.push(path.dirname(outsideRoute.eventSink));
|
|
185
|
+
writeNestedEvent(outsideRoute, {
|
|
186
|
+
type: "subagent.nested.updated",
|
|
187
|
+
ts: 100,
|
|
188
|
+
parentRunId: "root-outside",
|
|
189
|
+
parentStepIndex: 0,
|
|
190
|
+
child: { id: "shared-nested", parentRunId: "root-outside", parentStepIndex: 0, depth: 1, path: [{ runId: "root-outside", stepIndex: 0 }], state: "running", agent: "outside" },
|
|
191
|
+
});
|
|
192
|
+
|
|
193
|
+
const result = await createExecutor(createState(), [], false).execute("status", { action: "status", id: "shared-nested" }, new AbortController().signal, undefined, ctx(root));
|
|
194
|
+
|
|
195
|
+
assert.equal(result.isError, undefined);
|
|
196
|
+
assert.match(text(result), /Nested run: shared-nested/);
|
|
197
|
+
assert.match(text(result), /Root: root-control/);
|
|
198
|
+
assert.doesNotMatch(text(result), /root-outside/);
|
|
199
|
+
} finally {
|
|
200
|
+
fs.rmSync(root, { recursive: true, force: true });
|
|
201
|
+
}
|
|
202
|
+
});
|
|
203
|
+
|
|
204
|
+
it("requires an id for child-safe status instead of listing unrelated top-level async runs", async () => {
|
|
205
|
+
const root = fs.mkdtempSync(path.join(os.tmpdir(), "pi-nested-child-safe-status-"));
|
|
206
|
+
const runId = `child-safe-unrelated-${Date.now().toString(36)}`;
|
|
207
|
+
const asyncDir = path.join(ASYNC_DIR, runId);
|
|
208
|
+
try {
|
|
209
|
+
fs.mkdirSync(asyncDir, { recursive: true });
|
|
210
|
+
fs.writeFileSync(path.join(asyncDir, "status.json"), JSON.stringify({
|
|
211
|
+
runId,
|
|
212
|
+
mode: "single",
|
|
213
|
+
state: "running",
|
|
214
|
+
pid: 12345,
|
|
215
|
+
startedAt: 100,
|
|
216
|
+
lastUpdate: 100,
|
|
217
|
+
steps: [{ agent: "outside", status: "running", startedAt: 100 }],
|
|
218
|
+
}, null, 2), "utf-8");
|
|
219
|
+
|
|
220
|
+
const result = await createExecutor(createState(), [], false).execute("status", { action: "status" }, new AbortController().signal, undefined, ctx(root));
|
|
221
|
+
|
|
222
|
+
assert.equal(result.isError, true);
|
|
223
|
+
assert.match(text(result), /requires an id/);
|
|
224
|
+
assert.doesNotMatch(text(result), new RegExp(runId));
|
|
225
|
+
} finally {
|
|
226
|
+
fs.rmSync(root, { recursive: true, force: true });
|
|
227
|
+
fs.rmSync(asyncDir, { recursive: true, force: true });
|
|
228
|
+
}
|
|
229
|
+
});
|
|
230
|
+
|
|
231
|
+
it("does not let bare interrupt target hidden nested descendants", async () => {
|
|
232
|
+
const root = fs.mkdtempSync(path.join(os.tmpdir(), "pi-nested-bare-interrupt-"));
|
|
233
|
+
try {
|
|
234
|
+
createNestedRun("nested-only");
|
|
235
|
+
const result = await createExecutor().execute("interrupt", { action: "interrupt" }, new AbortController().signal, undefined, ctx(root));
|
|
236
|
+
assert.equal(result.isError, true);
|
|
237
|
+
assert.match(text(result), /No interrupt-capable run found/);
|
|
238
|
+
} finally {
|
|
239
|
+
fs.rmSync(root, { recursive: true, force: true });
|
|
240
|
+
}
|
|
241
|
+
});
|
|
242
|
+
|
|
243
|
+
it("times out owner-gone nested control and ignores late results", async () => {
|
|
244
|
+
const root = fs.mkdtempSync(path.join(os.tmpdir(), "pi-nested-timeout-"));
|
|
245
|
+
try {
|
|
246
|
+
const route = createNestedRun("nested-timeout");
|
|
247
|
+
const executor = createExecutor(stateWithNestedRoute(route));
|
|
248
|
+
setTimeout(() => {
|
|
249
|
+
const request = readNestedControlRequests(route)[0];
|
|
250
|
+
if (request) writeNestedControlResult(route, { ts: Date.now(), requestId: request.requestId, targetRunId: request.targetRunId, ok: true, message: "late success" });
|
|
251
|
+
}, 1_200);
|
|
252
|
+
const result = await executor.execute("interrupt", { action: "interrupt", id: "nested-timeout" }, new AbortController().signal, undefined, ctx(root));
|
|
253
|
+
assert.equal(result.isError, true);
|
|
254
|
+
assert.match(text(result), /owner is not reachable/);
|
|
255
|
+
assert.doesNotMatch(text(result), /late success/);
|
|
256
|
+
} finally {
|
|
257
|
+
fs.rmSync(root, { recursive: true, force: true });
|
|
258
|
+
}
|
|
259
|
+
});
|
|
260
|
+
|
|
261
|
+
it("routes resume for live nested runs through the control inbox", async () => {
|
|
262
|
+
const root = fs.mkdtempSync(path.join(os.tmpdir(), "pi-nested-live-resume-"));
|
|
263
|
+
try {
|
|
264
|
+
const emitted: Array<{ name: string; payload: unknown }> = [];
|
|
265
|
+
const events = { emit(name: string, payload: unknown) { emitted.push({ name, payload }); }, on() { return () => {}; } };
|
|
266
|
+
const route = createNestedRun("nested-live-resume", "running", { intercomTarget: "attacker-target", leafIntercomTarget: "attacker-leaf" });
|
|
267
|
+
const executor = createExecutor(stateWithNestedRoute(route), [], true, events);
|
|
268
|
+
setTimeout(() => {
|
|
269
|
+
const request = readNestedControlRequests(route)[0];
|
|
270
|
+
assert.ok(request, "expected a nested resume request");
|
|
271
|
+
assert.equal(request.action, "resume");
|
|
272
|
+
assert.equal(request.message, "continue please");
|
|
273
|
+
writeNestedControlResult(route, { ts: Date.now(), requestId: request.requestId, targetRunId: request.targetRunId, ok: true, message: "nested resume accepted" });
|
|
274
|
+
}, 50);
|
|
275
|
+
|
|
276
|
+
const result = await executor.execute("resume", { action: "resume", id: "nested-live-resume", message: "continue please" }, new AbortController().signal, undefined, ctx(root));
|
|
277
|
+
|
|
278
|
+
assert.equal(result.isError, undefined);
|
|
279
|
+
assert.match(text(result), /nested resume accepted/);
|
|
280
|
+
assert.equal(emitted.some((event) => {
|
|
281
|
+
const payload = event.payload as { to?: unknown };
|
|
282
|
+
return payload.to === "attacker-target" || payload.to === "attacker-leaf";
|
|
283
|
+
}), false);
|
|
284
|
+
} finally {
|
|
285
|
+
fs.rmSync(root, { recursive: true, force: true });
|
|
286
|
+
}
|
|
287
|
+
});
|
|
288
|
+
|
|
289
|
+
it("validates terminal nested resume session files before revive", async () => {
|
|
290
|
+
const root = fs.mkdtempSync(path.join(os.tmpdir(), "pi-nested-terminal-resume-"));
|
|
291
|
+
try {
|
|
292
|
+
const route = createNestedRun("nested-terminal-resume", "complete", { sessionFile: path.join(root, "missing-session.jsonl") });
|
|
293
|
+
|
|
294
|
+
const result = await createExecutor(stateWithNestedRoute(route), [{ name: "worker", description: "Worker", prompt: "Do work" }])
|
|
295
|
+
.execute("resume", { action: "resume", id: "nested-terminal-resume", message: "continue" }, new AbortController().signal, undefined, ctx(root));
|
|
296
|
+
|
|
297
|
+
assert.equal(result.isError, true);
|
|
298
|
+
assert.match(text(result), /session file does not exist/);
|
|
299
|
+
} finally {
|
|
300
|
+
fs.rmSync(root, { recursive: true, force: true });
|
|
301
|
+
}
|
|
302
|
+
});
|
|
303
|
+
|
|
304
|
+
it("rejects terminal nested resume session files outside trusted roots", async () => {
|
|
305
|
+
const root = fs.mkdtempSync(path.join(os.tmpdir(), "pi-nested-terminal-untrusted-"));
|
|
306
|
+
try {
|
|
307
|
+
const parentSessionFile = path.join(root, "parent.jsonl");
|
|
308
|
+
const attackerSessionFile = path.join(root, "outside", "session.jsonl");
|
|
309
|
+
fs.mkdirSync(path.dirname(attackerSessionFile), { recursive: true });
|
|
310
|
+
fs.writeFileSync(parentSessionFile, "");
|
|
311
|
+
fs.writeFileSync(attackerSessionFile, "");
|
|
312
|
+
const route = createNestedRun("nested-untrusted-resume", "complete", { sessionFile: attackerSessionFile });
|
|
313
|
+
|
|
314
|
+
const result = await createExecutor(stateWithNestedRoute(route), [{ name: "worker", description: "Worker", prompt: "Do work" }])
|
|
315
|
+
.execute("resume", { action: "resume", id: "nested-untrusted-resume", message: "continue" }, new AbortController().signal, undefined, ctx(root, parentSessionFile));
|
|
316
|
+
|
|
317
|
+
assert.equal(result.isError, true);
|
|
318
|
+
assert.match(text(result), /outside trusted nested session roots/);
|
|
319
|
+
} finally {
|
|
320
|
+
fs.rmSync(root, { recursive: true, force: true });
|
|
321
|
+
}
|
|
322
|
+
});
|
|
323
|
+
|
|
324
|
+
it("rejects terminal nested resume session files from sibling run directories", async () => {
|
|
325
|
+
const root = fs.mkdtempSync(path.join(os.tmpdir(), "pi-nested-terminal-sibling-"));
|
|
326
|
+
try {
|
|
327
|
+
const parentSessionFile = path.join(root, "parent.jsonl");
|
|
328
|
+
const siblingSessionFile = path.join(root, "parent", "other-run", "run-0", "session.jsonl");
|
|
329
|
+
fs.mkdirSync(path.dirname(siblingSessionFile), { recursive: true });
|
|
330
|
+
fs.writeFileSync(parentSessionFile, "");
|
|
331
|
+
fs.writeFileSync(siblingSessionFile, "");
|
|
332
|
+
const route = createNestedRun("nested-sibling-resume", "complete", { sessionFile: siblingSessionFile });
|
|
333
|
+
|
|
334
|
+
const result = await createExecutor(stateWithNestedRoute(route), [{ name: "worker", description: "Worker", prompt: "Do work" }])
|
|
335
|
+
.execute("resume", { action: "resume", id: "nested-sibling-resume", message: "continue" }, new AbortController().signal, undefined, ctx(root, parentSessionFile));
|
|
336
|
+
|
|
337
|
+
assert.equal(result.isError, true);
|
|
338
|
+
assert.match(text(result), /not under that nested run's session directory/);
|
|
339
|
+
} finally {
|
|
340
|
+
fs.rmSync(root, { recursive: true, force: true });
|
|
341
|
+
}
|
|
342
|
+
});
|
|
343
|
+
|
|
344
|
+
it("emits a failed completed nested event when foreground execution throws after start", async () => {
|
|
345
|
+
const root = fs.mkdtempSync(path.join(os.tmpdir(), "pi-nested-foreground-throw-"));
|
|
346
|
+
try {
|
|
347
|
+
const route = createNestedRoute("root-parent");
|
|
348
|
+
routeRoots.push(path.dirname(route.eventSink));
|
|
349
|
+
setNestedRouteEnv(route, "root-parent");
|
|
350
|
+
const throwingCtx = {
|
|
351
|
+
...ctx(root),
|
|
352
|
+
modelRegistry: { getAvailable() { throw new Error("model registry exploded"); } },
|
|
353
|
+
};
|
|
354
|
+
|
|
355
|
+
const result = await createExecutor(createState(), [{ name: "worker", description: "Worker", prompt: "Do work" }])
|
|
356
|
+
.execute("run", { agent: "worker", task: "go" }, new AbortController().signal, undefined, throwingCtx);
|
|
357
|
+
|
|
358
|
+
assert.equal(result.isError, true);
|
|
359
|
+
assert.match(text(result), /model registry exploded/);
|
|
360
|
+
const registry = projectNestedEvents(route);
|
|
361
|
+
assert.equal(registry.children.length, 1);
|
|
362
|
+
assert.equal(registry.children[0]?.state, "failed");
|
|
363
|
+
assert.match(registry.children[0]?.error ?? "", /model registry exploded/);
|
|
364
|
+
} finally {
|
|
365
|
+
fs.rmSync(root, { recursive: true, force: true });
|
|
366
|
+
}
|
|
367
|
+
});
|
|
368
|
+
|
|
369
|
+
it("keeps the fanout child control listener alive after control inbox polling errors", async () => {
|
|
370
|
+
const route = createNestedRoute("root-poll-error");
|
|
371
|
+
routeRoots.push(path.dirname(route.eventSink));
|
|
372
|
+
setNestedRouteEnv(route, "root-poll-error");
|
|
373
|
+
process.env[SUBAGENT_CHILD_ENV] = "1";
|
|
374
|
+
process.env[SUBAGENT_FANOUT_CHILD_ENV] = "1";
|
|
375
|
+
const pi = {
|
|
376
|
+
events: { emit() {}, on() { return () => {}; } },
|
|
377
|
+
registerTool() {},
|
|
378
|
+
getSessionName() { return "child"; },
|
|
379
|
+
} as any;
|
|
380
|
+
fs.rmSync(route.controlInbox, { recursive: true, force: true });
|
|
381
|
+
fs.writeFileSync(route.controlInbox, "not a directory", "utf-8");
|
|
382
|
+
const originalError = console.error;
|
|
383
|
+
const logged: unknown[][] = [];
|
|
384
|
+
console.error = (...args: unknown[]) => {
|
|
385
|
+
logged.push(args);
|
|
386
|
+
};
|
|
387
|
+
try {
|
|
388
|
+
registerFanoutChildSubagentExtension(pi);
|
|
389
|
+
await waitFor(() => logged.some((entry) => String(entry[0] ?? "").includes(route.controlInbox) && String(entry[0] ?? "").includes("root-poll-error")));
|
|
390
|
+
|
|
391
|
+
fs.rmSync(route.controlInbox, { force: true });
|
|
392
|
+
fs.mkdirSync(route.controlInbox, { recursive: true });
|
|
393
|
+
const requestPath = writeNestedControlRequest(route, {
|
|
394
|
+
ts: Date.now(),
|
|
395
|
+
requestId: "poll-error-recovers",
|
|
396
|
+
targetRunId: "missing-run",
|
|
397
|
+
action: "interrupt",
|
|
398
|
+
});
|
|
399
|
+
|
|
400
|
+
await waitFor(() => readNestedControlResults(route).some((result) => result.requestId === "poll-error-recovers" && result.ok === false));
|
|
401
|
+
assert.equal(fs.existsSync(requestPath), false);
|
|
402
|
+
} finally {
|
|
403
|
+
console.error = originalError;
|
|
404
|
+
}
|
|
405
|
+
});
|
|
406
|
+
|
|
407
|
+
it("keeps fanout child control requests when result writing fails and retries after recovery", async () => {
|
|
408
|
+
const route = createNestedRoute("root-result-write-fails");
|
|
409
|
+
routeRoots.push(path.dirname(route.eventSink));
|
|
410
|
+
setNestedRouteEnv(route, "root-result-write-fails");
|
|
411
|
+
process.env[SUBAGENT_CHILD_ENV] = "1";
|
|
412
|
+
process.env[SUBAGENT_FANOUT_CHILD_ENV] = "1";
|
|
413
|
+
const pi = {
|
|
414
|
+
events: { emit() {}, on() { return () => {}; } },
|
|
415
|
+
registerTool() {},
|
|
416
|
+
getSessionName() { return "child"; },
|
|
417
|
+
} as any;
|
|
418
|
+
fs.rmSync(route.eventSink, { recursive: true, force: true });
|
|
419
|
+
fs.writeFileSync(route.eventSink, "not a directory", "utf-8");
|
|
420
|
+
const requestPath = writeNestedControlRequest(route, {
|
|
421
|
+
ts: Date.now(),
|
|
422
|
+
requestId: "result-write-fails",
|
|
423
|
+
targetRunId: "missing-run",
|
|
424
|
+
action: "interrupt",
|
|
425
|
+
});
|
|
426
|
+
const originalError = console.error;
|
|
427
|
+
const logged: unknown[][] = [];
|
|
428
|
+
console.error = (...args: unknown[]) => {
|
|
429
|
+
logged.push(args);
|
|
430
|
+
};
|
|
431
|
+
try {
|
|
432
|
+
registerFanoutChildSubagentExtension(pi);
|
|
433
|
+
await waitFor(() => logged.some((entry) => String(entry[0] ?? "").includes("result-write-fails") && /keeping request for retry/.test(String(entry[0] ?? ""))));
|
|
434
|
+
assert.equal(fs.existsSync(requestPath), true);
|
|
435
|
+
|
|
436
|
+
fs.rmSync(route.eventSink, { force: true });
|
|
437
|
+
fs.mkdirSync(route.eventSink, { recursive: true });
|
|
438
|
+
await waitFor(() => readNestedControlResults(route).some((result) => result.requestId === "result-write-fails" && result.ok === false));
|
|
439
|
+
assert.equal(fs.existsSync(requestPath), false);
|
|
440
|
+
} finally {
|
|
441
|
+
console.error = originalError;
|
|
442
|
+
}
|
|
443
|
+
});
|
|
444
|
+
|
|
445
|
+
it("negatively acknowledges ownerless fanout child control requests and removes them", async () => {
|
|
446
|
+
const route = createNestedRoute("root-ownerless");
|
|
447
|
+
routeRoots.push(path.dirname(route.eventSink));
|
|
448
|
+
setNestedRouteEnv(route, "root-ownerless");
|
|
449
|
+
process.env[SUBAGENT_CHILD_ENV] = "1";
|
|
450
|
+
process.env[SUBAGENT_FANOUT_CHILD_ENV] = "1";
|
|
451
|
+
const pi = {
|
|
452
|
+
events: { emit() {}, on() { return () => {}; } },
|
|
453
|
+
registerTool() {},
|
|
454
|
+
getSessionName() { return "child"; },
|
|
455
|
+
} as any;
|
|
456
|
+
const requestPath = writeNestedControlRequest(route, {
|
|
457
|
+
ts: Date.now(),
|
|
458
|
+
requestId: "ownerless-request",
|
|
459
|
+
targetRunId: "missing-run",
|
|
460
|
+
action: "interrupt",
|
|
461
|
+
});
|
|
462
|
+
|
|
463
|
+
registerFanoutChildSubagentExtension(pi);
|
|
464
|
+
await waitFor(() => readNestedControlResults(route).some((result) => result.requestId === "ownerless-request" && result.ok === false));
|
|
465
|
+
|
|
466
|
+
assert.equal(fs.existsSync(requestPath), false);
|
|
467
|
+
const result = readNestedControlResults(route).find((item) => item.requestId === "ownerless-request");
|
|
468
|
+
assert.match(result?.message ?? "", /not active/);
|
|
469
|
+
});
|
|
470
|
+
});
|