@selesai/code 0.5.19 → 0.5.21
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/extensions/handoff-new.test.ts +8 -9
- package/dist/extensions/handoff-new.ts +6 -8
- package/dist/extensions/pi-intercom/broker/spawn.test.ts +31 -0
- package/dist/extensions/pi-intercom/broker/spawn.ts +5 -3
- package/dist/extensions/pi-subagents/CHANGELOG.md +1367 -0
- package/dist/extensions/pi-subagents/README.md +602 -220
- package/dist/extensions/pi-subagents/banner.png +0 -0
- package/dist/extensions/pi-subagents/index.ts +1 -0
- package/dist/extensions/pi-subagents/install.mjs +3 -3
- package/dist/extensions/pi-subagents/package-lock.json +3405 -0
- package/dist/extensions/pi-subagents/package.json +26 -14
- package/dist/extensions/pi-subagents/prompts/gather-context-and-clarify.md +1 -1
- package/dist/extensions/pi-subagents/prompts/parallel-cleanup.md +9 -9
- package/dist/extensions/pi-subagents/prompts/parallel-context-build.md +3 -3
- package/dist/extensions/pi-subagents/prompts/parallel-handoff-plan.md +7 -7
- package/dist/extensions/pi-subagents/prompts/parallel-research.md +6 -6
- package/dist/extensions/pi-subagents/prompts/parallel-review.md +8 -8
- package/dist/extensions/pi-subagents/prompts/review-loop.md +13 -11
- package/dist/extensions/pi-subagents/skills/pi-subagents/SKILL.md +267 -176
- package/dist/extensions/pi-subagents/src/agents/agent-management.ts +89 -16
- package/dist/extensions/pi-subagents/src/agents/agent-serializer.ts +19 -0
- package/dist/extensions/pi-subagents/src/agents/agents.ts +218 -120
- package/dist/extensions/pi-subagents/src/agents/frontmatter.ts +67 -13
- package/dist/extensions/pi-subagents/src/agents/proactive-skills.ts +2 -2
- package/dist/extensions/pi-subagents/src/agents/skills.ts +25 -12
- package/dist/extensions/pi-subagents/src/api/background-work.ts +197 -0
- package/dist/extensions/pi-subagents/src/api/capability-ceiling.ts +17 -0
- package/dist/extensions/pi-subagents/src/api/delegation.ts +285 -0
- package/dist/extensions/pi-subagents/src/api/preflight.ts +399 -0
- package/dist/extensions/pi-subagents/src/extension/chain-validation.ts +165 -0
- package/dist/extensions/pi-subagents/src/extension/config.ts +7 -1
- package/dist/extensions/pi-subagents/src/extension/doctor.ts +15 -0
- package/dist/extensions/pi-subagents/src/extension/fanout-child.ts +3 -1
- package/dist/extensions/pi-subagents/src/extension/index.ts +113 -157
- package/dist/extensions/pi-subagents/src/extension/rpc.ts +41 -4
- package/dist/extensions/pi-subagents/src/extension/schemas.ts +45 -15
- package/dist/extensions/pi-subagents/src/extension/steering-notices.ts +35 -0
- package/dist/extensions/pi-subagents/src/extension/tool-description.ts +28 -15
- package/dist/extensions/pi-subagents/src/intercom/intercom-bridge.ts +4 -3
- package/dist/extensions/pi-subagents/src/intercom/native-supervisor-channel.ts +225 -29
- package/dist/extensions/pi-subagents/src/intercom/result-intercom.ts +11 -0
- package/dist/extensions/pi-subagents/src/profiles/profiles.ts +8 -10
- package/dist/extensions/pi-subagents/src/runs/background/async-execution.ts +452 -62
- package/dist/extensions/pi-subagents/src/runs/background/async-job-tracker.ts +60 -9
- package/dist/extensions/pi-subagents/src/runs/background/async-resume.ts +198 -52
- package/dist/extensions/pi-subagents/src/runs/background/async-status.ts +119 -21
- package/dist/extensions/pi-subagents/src/runs/background/auto-drain.ts +67 -0
- package/dist/extensions/pi-subagents/src/runs/background/chain-append.ts +2 -0
- package/dist/extensions/pi-subagents/src/runs/background/chain-root-attachment.ts +16 -8
- package/dist/extensions/pi-subagents/src/runs/background/completion-batcher.ts +6 -4
- package/dist/extensions/pi-subagents/src/runs/background/completion-dedupe.ts +2 -11
- package/dist/extensions/pi-subagents/src/runs/background/control-channel.ts +260 -13
- package/dist/extensions/pi-subagents/src/runs/background/fleet-view.ts +32 -6
- package/dist/extensions/pi-subagents/src/runs/background/notify.ts +171 -90
- package/dist/extensions/pi-subagents/src/runs/background/process-terminal.ts +280 -0
- package/dist/extensions/pi-subagents/src/runs/background/result-watcher.ts +149 -88
- package/dist/extensions/pi-subagents/src/runs/background/run-id-resolver.ts +14 -2
- package/dist/extensions/pi-subagents/src/runs/background/run-status.ts +33 -17
- package/dist/extensions/pi-subagents/src/runs/background/scheduled-runs.ts +9 -1
- package/dist/extensions/pi-subagents/src/runs/background/stale-run-reconciler.ts +38 -10
- package/dist/extensions/pi-subagents/src/runs/background/steering.ts +237 -0
- package/dist/extensions/pi-subagents/src/runs/background/subagent-runner.ts +1297 -307
- package/dist/extensions/pi-subagents/src/runs/background/subagent-wait.ts +610 -0
- package/dist/extensions/pi-subagents/src/runs/background/top-level-async.ts +2 -1
- package/dist/extensions/pi-subagents/src/runs/background/wait-config.ts +36 -0
- package/dist/extensions/pi-subagents/src/runs/background/wait-tool.ts +26 -0
- package/dist/extensions/pi-subagents/src/runs/foreground/async-steering-action.ts +230 -0
- package/dist/extensions/pi-subagents/src/runs/foreground/chain-clarify.ts +22 -6
- package/dist/extensions/pi-subagents/src/runs/foreground/chain-execution.ts +228 -140
- package/dist/extensions/pi-subagents/src/runs/foreground/execution.ts +452 -138
- package/dist/extensions/pi-subagents/src/runs/foreground/foreground-control.ts +90 -0
- package/dist/extensions/pi-subagents/src/runs/foreground/subagent-executor.ts +1001 -416
- package/dist/extensions/pi-subagents/src/runs/shared/acceptance.ts +443 -132
- package/dist/extensions/pi-subagents/src/runs/shared/agent-contract.ts +38 -0
- package/dist/extensions/pi-subagents/src/runs/shared/capability-ceiling.ts +178 -0
- package/dist/extensions/pi-subagents/src/runs/shared/child-protocol.ts +121 -0
- package/dist/extensions/pi-subagents/src/runs/shared/completion-guard.ts +41 -93
- package/dist/extensions/pi-subagents/src/runs/shared/context-mode.ts +44 -0
- package/dist/extensions/pi-subagents/src/runs/shared/dynamic-fanout.ts +11 -9
- package/dist/extensions/pi-subagents/src/runs/shared/long-running-guard.ts +4 -0
- package/dist/extensions/pi-subagents/src/runs/shared/mcp-direct-tool-allowlist.ts +12 -6
- package/dist/extensions/pi-subagents/src/runs/shared/model-fallback.ts +36 -0
- package/dist/extensions/pi-subagents/src/runs/shared/nested-events.ts +44 -7
- package/dist/extensions/pi-subagents/src/runs/shared/nested-render.ts +4 -1
- package/dist/extensions/pi-subagents/src/runs/shared/parallel-handoff.ts +154 -0
- package/dist/extensions/pi-subagents/src/runs/shared/parallel-utils.ts +18 -0
- package/dist/extensions/pi-subagents/src/runs/shared/pi-args.ts +174 -54
- package/dist/extensions/pi-subagents/src/runs/shared/pi-spawn.ts +38 -31
- package/dist/extensions/pi-subagents/src/runs/shared/run-history.ts +90 -5
- package/dist/extensions/pi-subagents/src/runs/shared/session-lease.ts +299 -0
- package/dist/extensions/pi-subagents/src/runs/shared/single-output.ts +61 -6
- package/dist/extensions/pi-subagents/src/runs/shared/spawn-budget.ts +128 -0
- package/dist/extensions/pi-subagents/src/runs/shared/structured-output.ts +112 -7
- package/dist/extensions/pi-subagents/src/runs/shared/subagent-control.ts +14 -6
- package/dist/extensions/pi-subagents/src/runs/shared/subagent-prompt-runtime.ts +149 -36
- package/dist/extensions/pi-subagents/src/runs/shared/task-intent.ts +181 -0
- package/dist/extensions/pi-subagents/src/runs/shared/tool-availability.ts +83 -0
- package/dist/extensions/pi-subagents/src/runs/shared/tool-budget.ts +11 -5
- package/dist/extensions/pi-subagents/src/runs/shared/turn-budget.ts +50 -4
- package/dist/extensions/pi-subagents/src/runs/shared/worktree.ts +63 -14
- package/dist/extensions/pi-subagents/src/shared/accessible-dir.ts +25 -0
- package/dist/extensions/pi-subagents/src/shared/artifacts.ts +37 -7
- package/dist/extensions/pi-subagents/src/shared/atomic-json.ts +18 -43
- package/dist/extensions/pi-subagents/src/shared/child-transcript.ts +52 -0
- package/dist/extensions/pi-subagents/src/shared/env.ts +16 -0
- package/dist/extensions/pi-subagents/src/shared/file-system-retry.ts +47 -0
- package/dist/extensions/pi-subagents/src/shared/fork-context.ts +28 -3
- package/dist/extensions/pi-subagents/src/shared/launch-contract.ts +123 -0
- package/dist/extensions/pi-subagents/src/shared/model-info.ts +8 -5
- package/dist/extensions/pi-subagents/src/shared/settings.ts +9 -1
- package/dist/extensions/pi-subagents/src/shared/status-format.ts +7 -1
- package/dist/extensions/pi-subagents/src/shared/types.ts +522 -51
- package/dist/extensions/pi-subagents/src/shared/utils.ts +59 -53
- package/dist/extensions/pi-subagents/src/slash/delegation-adapters.ts +604 -0
- package/dist/extensions/pi-subagents/src/slash/delegation-json.ts +108 -0
- package/dist/extensions/pi-subagents/src/slash/delegation-request.ts +249 -0
- package/dist/extensions/pi-subagents/src/slash/prompt-template-bridge.ts +353 -345
- package/dist/extensions/pi-subagents/src/slash/prompt-workflows.ts +2 -2
- package/dist/extensions/pi-subagents/src/slash/selector.ts +147 -0
- package/dist/extensions/pi-subagents/src/slash/slash-commands.ts +265 -23
- package/dist/extensions/pi-subagents/src/slash/slash-live-state.ts +2 -2
- package/dist/extensions/pi-subagents/src/slash/subagents-admin.ts +428 -0
- package/dist/extensions/pi-subagents/src/tui/fleet-status.ts +362 -0
- package/dist/extensions/pi-subagents/src/tui/fleet-transcript.ts +472 -0
- package/dist/extensions/pi-subagents/src/tui/fleet.ts +664 -0
- package/dist/extensions/pi-subagents/src/tui/render.ts +115 -31
- package/dist/extensions/pi-subagents/src/watchdog/change-signature.ts +220 -0
- package/dist/extensions/pi-subagents/src/watchdog/child-status.ts +205 -0
- package/dist/extensions/pi-subagents/src/watchdog/emission-guard.ts +123 -0
- package/dist/extensions/pi-subagents/src/watchdog/lsp-diagnostics.ts +532 -0
- package/dist/extensions/pi-subagents/src/watchdog/model-selection.ts +167 -0
- package/dist/extensions/pi-subagents/src/watchdog/register-child.ts +117 -0
- package/dist/extensions/pi-subagents/src/watchdog/register-main.ts +433 -0
- package/dist/extensions/pi-subagents/src/watchdog/render.ts +54 -0
- package/dist/extensions/pi-subagents/src/watchdog/review.ts +298 -0
- package/dist/extensions/pi-subagents/src/watchdog/runtime.ts +714 -0
- package/dist/extensions/pi-subagents/src/watchdog/settings.ts +528 -0
- package/dist/extensions/pi-subagents/src/watchdog/tool-actions.ts +155 -0
- package/dist/extensions/pi-subagents/src/watchdog/turn-delta.ts +161 -0
- package/dist/extensions/pi-subagents/src/watchdog/types.ts +188 -0
- package/dist/extensions/pi-subagents/src/watchdog/warning-format.ts +73 -0
- package/dist/extensions/pi-subagents/test/e2e/real-session-subagent.test.ts +130 -2
- package/dist/extensions/pi-subagents/test/integration/acceptance-file-report.test.ts +439 -0
- package/dist/extensions/pi-subagents/test/integration/async-execution.test.ts +1632 -61
- package/dist/extensions/pi-subagents/test/integration/async-job-tracker.test.ts +54 -1
- package/dist/extensions/pi-subagents/test/integration/async-status.test.ts +112 -0
- package/dist/extensions/pi-subagents/test/integration/chain-clarify.test.ts +98 -1
- package/dist/extensions/pi-subagents/test/integration/chain-execution.test.ts +179 -9
- package/dist/extensions/pi-subagents/test/integration/detect-error.test.ts +16 -9
- package/dist/extensions/pi-subagents/test/integration/error-handling.test.ts +6 -5
- package/dist/extensions/pi-subagents/test/integration/fork-context-execution.test.ts +589 -9
- package/dist/extensions/pi-subagents/test/integration/intercom-result-delivery.test.ts +528 -21
- package/dist/extensions/pi-subagents/test/integration/parallel-execution.test.ts +227 -3
- package/dist/extensions/pi-subagents/test/integration/render-fork-badge.test.ts +235 -7
- package/dist/extensions/pi-subagents/test/integration/render-widget.test.ts +27 -0
- package/dist/extensions/pi-subagents/test/integration/result-watcher.test.ts +172 -2
- package/dist/extensions/pi-subagents/test/integration/single-execution.test.ts +1502 -18
- package/dist/extensions/pi-subagents/test/integration/slash-commands.test.ts +993 -4
- package/dist/extensions/pi-subagents/test/integration/slash-live-state.test.ts +27 -0
- package/dist/extensions/pi-subagents/test/integration/top-level-async.test.ts +7 -1
- package/dist/extensions/pi-subagents/test/support/helpers.ts +32 -0
- package/dist/extensions/pi-subagents/test/support/mock-pi-script.mjs +59 -2
- package/dist/extensions/pi-subagents/test/support/mock-pi.ts +32 -6
- package/dist/extensions/pi-subagents/test/support/real-session-child-cli.mjs +25 -24
- package/dist/extensions/pi-subagents/test/support/real-session-runner.ts +59 -35
- package/dist/extensions/pi-subagents/test/support/session-lease-child.mjs +42 -0
- package/dist/extensions/pi-subagents/test/unit/acceptance.test.ts +703 -69
- package/dist/extensions/pi-subagents/test/unit/accessible-dir.test.ts +82 -0
- package/dist/extensions/pi-subagents/test/unit/agent-disabled.test.ts +15 -15
- package/dist/extensions/pi-subagents/test/unit/agent-eject-disable.test.ts +66 -66
- package/dist/extensions/pi-subagents/test/unit/agent-frontmatter.test.ts +478 -19
- package/dist/extensions/pi-subagents/test/unit/agent-management.test.ts +228 -7
- package/dist/extensions/pi-subagents/test/unit/agent-memory.test.ts +1 -1
- package/dist/extensions/pi-subagents/test/unit/agent-overrides.test.ts +198 -78
- package/dist/extensions/pi-subagents/test/unit/async-execution.test.ts +15 -1
- package/dist/extensions/pi-subagents/test/unit/async-interrupt-action.test.ts +102 -7
- package/dist/extensions/pi-subagents/test/unit/async-resume.test.ts +439 -6
- package/dist/extensions/pi-subagents/test/unit/atomic-json.test.ts +41 -1
- package/dist/extensions/pi-subagents/test/unit/auto-drain.test.ts +79 -0
- package/dist/extensions/pi-subagents/test/unit/background-work.test.ts +285 -0
- package/dist/extensions/pi-subagents/test/unit/capability-ceiling-pi-args.test.ts +84 -0
- package/dist/extensions/pi-subagents/test/unit/capability-ceiling.test.ts +68 -0
- package/dist/extensions/pi-subagents/test/unit/chain-validation.test.ts +326 -0
- package/dist/extensions/pi-subagents/test/unit/child-protocol.test.ts +82 -0
- package/dist/extensions/pi-subagents/test/unit/child-transcript.test.ts +46 -4
- package/dist/extensions/pi-subagents/test/unit/completion-batcher.test.ts +3 -1
- package/dist/extensions/pi-subagents/test/unit/completion-dedupe.test.ts +9 -17
- package/dist/extensions/pi-subagents/test/unit/completion-guard.test.ts +175 -3
- package/dist/extensions/pi-subagents/test/unit/config-dir-runtime.test.ts +10 -5
- package/dist/extensions/pi-subagents/test/unit/control-channel.test.ts +126 -6
- package/dist/extensions/pi-subagents/test/unit/default-extensions.test.ts +219 -0
- package/dist/extensions/pi-subagents/test/unit/delegation-api.test.ts +913 -0
- package/dist/extensions/pi-subagents/test/unit/doctor.test.ts +13 -2
- package/dist/extensions/pi-subagents/test/unit/dynamic-fanout.test.ts +3 -3
- package/dist/extensions/pi-subagents/test/unit/fleet-status.test.ts +351 -0
- package/dist/extensions/pi-subagents/test/unit/fleet-transcript.test.ts +280 -0
- package/dist/extensions/pi-subagents/test/unit/fleet.test.ts +575 -0
- package/dist/extensions/pi-subagents/test/unit/foreground-control.test.ts +65 -0
- package/dist/extensions/pi-subagents/test/unit/fork-context.test.ts +94 -1
- package/dist/extensions/pi-subagents/test/unit/get-final-output.test.ts +23 -0
- package/dist/extensions/pi-subagents/test/unit/host-peer-runtime-imports.test.ts +157 -0
- package/dist/extensions/pi-subagents/test/unit/index-child-registration.test.ts +367 -5
- package/dist/extensions/pi-subagents/test/unit/intercom-bridge.test.ts +11 -0
- package/dist/extensions/pi-subagents/test/unit/model-fallback.test.ts +36 -0
- package/dist/extensions/pi-subagents/test/unit/model-info.test.ts +25 -3
- package/dist/extensions/pi-subagents/test/unit/model-scope.test.ts +1 -1
- package/dist/extensions/pi-subagents/test/unit/native-supervisor-channel.test.ts +341 -10
- package/dist/extensions/pi-subagents/test/unit/nested-control.test.ts +16 -0
- package/dist/extensions/pi-subagents/test/unit/nested-events.test.ts +52 -0
- package/dist/extensions/pi-subagents/test/unit/notify.test.ts +168 -7
- package/dist/extensions/pi-subagents/test/unit/package-manifest.test.ts +85 -7
- package/dist/extensions/pi-subagents/test/unit/parallel-handoff.test.ts +175 -0
- package/dist/extensions/pi-subagents/test/unit/path-resolution.test.ts +1 -1
- package/dist/extensions/pi-subagents/test/unit/pi-args.test.ts +243 -16
- package/dist/extensions/pi-subagents/test/unit/pi-coding-agent-dir.test.ts +79 -36
- package/dist/extensions/pi-subagents/test/unit/pi-spawn.test.ts +174 -56
- package/dist/extensions/pi-subagents/test/unit/preflight.test.ts +322 -0
- package/dist/extensions/pi-subagents/test/unit/process-terminal.test.ts +204 -0
- package/dist/extensions/pi-subagents/test/unit/recursion-guard.test.ts +20 -12
- package/dist/extensions/pi-subagents/test/unit/rpc.test.ts +117 -4
- package/dist/extensions/pi-subagents/test/unit/run-status.test.ts +40 -7
- package/dist/extensions/pi-subagents/test/unit/scheduled-runs.test.ts +48 -1
- package/dist/extensions/pi-subagents/test/unit/schemas.test.ts +21 -3
- package/dist/extensions/pi-subagents/test/unit/selector.test.ts +57 -0
- package/dist/extensions/pi-subagents/test/unit/session-lease.test.ts +326 -0
- package/dist/extensions/pi-subagents/test/unit/single-output.test.ts +101 -2
- package/dist/extensions/pi-subagents/test/unit/skills-fallback.test.ts +111 -1
- package/dist/extensions/pi-subagents/test/unit/spawn-budget.test.ts +124 -0
- package/dist/extensions/pi-subagents/test/unit/stale-run-reconciler.test.ts +6 -4
- package/dist/extensions/pi-subagents/test/unit/status-format.test.ts +7 -0
- package/dist/extensions/pi-subagents/test/unit/steering-action.test.ts +397 -0
- package/dist/extensions/pi-subagents/test/unit/steering-notices.test.ts +58 -0
- package/dist/extensions/pi-subagents/test/unit/steering.test.ts +173 -0
- package/dist/extensions/pi-subagents/test/unit/subagent-control.test.ts +25 -4
- package/dist/extensions/pi-subagents/test/unit/subagent-prompt-runtime.test.ts +390 -25
- package/dist/extensions/pi-subagents/test/unit/subagent-wait.test.ts +837 -0
- package/dist/extensions/pi-subagents/test/unit/task-intent.test.ts +86 -0
- package/dist/extensions/pi-subagents/test/unit/tool-budget.test.ts +15 -0
- package/dist/extensions/pi-subagents/test/unit/tool-description.test.ts +47 -1
- package/dist/extensions/pi-subagents/test/unit/turn-budget.test.ts +56 -10
- package/dist/extensions/pi-subagents/test/unit/watchdog-change-signature.test.ts +387 -0
- package/dist/extensions/pi-subagents/test/unit/watchdog-child-status.test.ts +110 -0
- package/dist/extensions/pi-subagents/test/unit/watchdog-emission-guard.test.ts +62 -0
- package/dist/extensions/pi-subagents/test/unit/watchdog-lsp-diagnostics.test.ts +144 -0
- package/dist/extensions/pi-subagents/test/unit/watchdog-model-selection.test.ts +121 -0
- package/dist/extensions/pi-subagents/test/unit/watchdog-render.test.ts +76 -0
- package/dist/extensions/pi-subagents/test/unit/watchdog-review.test.ts +327 -0
- package/dist/extensions/pi-subagents/test/unit/watchdog-runtime.test.ts +863 -0
- package/dist/extensions/pi-subagents/test/unit/watchdog-settings.test.ts +290 -0
- package/dist/extensions/pi-subagents/test/unit/watchdog-tool-actions.test.ts +91 -0
- package/dist/extensions/pi-subagents/test/unit/watchdog-turn-delta.test.ts +130 -0
- package/dist/extensions/pi-subagents/test/unit/widget-nested-render.test.ts +32 -4
- package/dist/extensions/pi-subagents/test/unit/worktree.test.ts +5 -1
- package/dist/extensions/pi-subagents/test/unit/writer-budget-guidance.test.ts +30 -0
- package/dist/extensions/question/batch.ts +39 -0
- package/dist/extensions/question/dialog-adapter.ts +23 -1
- package/dist/extensions/question/index.ts +237 -7
- package/dist/extensions/question/schemas.ts +28 -15
- package/dist/extensions/question/tests/batch.test.ts +26 -0
- package/dist/extensions/question/tests/ui-protocol.test.ts +23 -3
- package/dist/extensions/question/tui-adapter.ts +2 -3
- package/dist/extensions/question/types.ts +37 -0
- package/dist/extensions/question/ui-protocol.ts +3 -3
- package/dist/skills/batch-grill-me/SKILL.md +3 -1
- package/package.json +2 -1
|
@@ -7,14 +7,23 @@ class FakeFs {
|
|
|
7
7
|
files = new Map<string, string>();
|
|
8
8
|
madeDirs: string[] = [];
|
|
9
9
|
renameCalls = 0;
|
|
10
|
+
failMkdirCodes: string[] = [];
|
|
10
11
|
failRenameCodes: string[] = [];
|
|
12
|
+
writeOptions = new Map<string, unknown>();
|
|
11
13
|
|
|
12
14
|
mkdirSync(dirPath: string): void {
|
|
13
15
|
this.madeDirs.push(dirPath);
|
|
16
|
+
const failureCode = this.failMkdirCodes.shift();
|
|
17
|
+
if (failureCode) {
|
|
18
|
+
const error = new Error(`mkdir failed with ${failureCode}`) as NodeJS.ErrnoException;
|
|
19
|
+
error.code = failureCode;
|
|
20
|
+
throw error;
|
|
21
|
+
}
|
|
14
22
|
}
|
|
15
23
|
|
|
16
|
-
writeFileSync(filePath: string, contents: string): void {
|
|
24
|
+
writeFileSync(filePath: string, contents: string, options?: unknown): void {
|
|
17
25
|
this.files.set(filePath, contents);
|
|
26
|
+
this.writeOptions.set(filePath, options);
|
|
18
27
|
}
|
|
19
28
|
|
|
20
29
|
renameSync(sourcePath: string, targetPath: string): void {
|
|
@@ -65,6 +74,37 @@ describe("writeAtomicJson", () => {
|
|
|
65
74
|
assert.equal(fakeFs.files.size, 1);
|
|
66
75
|
});
|
|
67
76
|
|
|
77
|
+
it("retries transient directory creation failures before writing", () => {
|
|
78
|
+
const fakeFs = new FakeFs();
|
|
79
|
+
fakeFs.failMkdirCodes = ["EPERM", "EACCES"];
|
|
80
|
+
const waits: number[] = [];
|
|
81
|
+
const writeAtomicJson = createWriter(fakeFs, waits);
|
|
82
|
+
const targetPath = path.join("/tmp", "status.json");
|
|
83
|
+
|
|
84
|
+
writeAtomicJson(targetPath, { state: "running" });
|
|
85
|
+
|
|
86
|
+
assert.equal(fakeFs.renameCalls, 1);
|
|
87
|
+
assert.deepEqual(waits, [1, 2]);
|
|
88
|
+
assert.deepEqual(fakeFs.madeDirs, [path.dirname(targetPath), path.dirname(targetPath), path.dirname(targetPath)]);
|
|
89
|
+
assert.equal(fakeFs.files.get(targetPath), JSON.stringify({ state: "running" }, null, 2));
|
|
90
|
+
});
|
|
91
|
+
|
|
92
|
+
it("writes the temporary descriptor with the requested private mode", () => {
|
|
93
|
+
const fakeFs = new FakeFs();
|
|
94
|
+
const writeAtomicJson = createAtomicJsonWriter({
|
|
95
|
+
fs: fakeFs as any,
|
|
96
|
+
now: () => 12345,
|
|
97
|
+
pid: 678,
|
|
98
|
+
random: () => 0.5,
|
|
99
|
+
mode: 0o600,
|
|
100
|
+
});
|
|
101
|
+
const targetPath = path.join("/tmp", "recovery-descriptor.json");
|
|
102
|
+
|
|
103
|
+
writeAtomicJson(targetPath, { sourceRunId: "run" });
|
|
104
|
+
|
|
105
|
+
assert.deepEqual([...fakeFs.writeOptions.values()], [{ encoding: "utf-8", mode: 0o600 }]);
|
|
106
|
+
});
|
|
107
|
+
|
|
68
108
|
it("uses longer default retries for transient Windows rename locks", () => {
|
|
69
109
|
const fakeFs = new FakeFs();
|
|
70
110
|
fakeFs.failRenameCodes = ["EPERM", "EPERM", "EPERM", "EPERM", "EPERM", "EPERM"];
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
import assert from "node:assert/strict";
|
|
2
|
+
import { describe, it } from "node:test";
|
|
3
|
+
import { drainOutstandingWork } from "../../src/runs/background/auto-drain.ts";
|
|
4
|
+
import type { Details, SubagentState } from "../../src/shared/types.ts";
|
|
5
|
+
|
|
6
|
+
function state(sessionId: string | null = "session-a"): SubagentState {
|
|
7
|
+
return { currentSessionId: sessionId } as SubagentState;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
function waitResult(text: string, isError = false) {
|
|
11
|
+
return {
|
|
12
|
+
content: [{ type: "text" as const, text }],
|
|
13
|
+
...(isError ? { isError: true } : {}),
|
|
14
|
+
details: { mode: "management" as const, results: [] } satisfies Details,
|
|
15
|
+
};
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
describe("headless background-work auto-drain", () => {
|
|
19
|
+
it("is a no-op when the exact session has no work", async () => {
|
|
20
|
+
let waited = false;
|
|
21
|
+
await drainOutstandingWork({
|
|
22
|
+
state: state(),
|
|
23
|
+
hasWork: () => false,
|
|
24
|
+
wait: async () => { waited = true; return waitResult("unexpected"); },
|
|
25
|
+
});
|
|
26
|
+
assert.equal(waited, false);
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
it("loops until work added while draining is also gone", async () => {
|
|
30
|
+
let checks = 0;
|
|
31
|
+
const waits: Array<{ all?: boolean; timeoutMs?: number; stopOnAttention?: boolean; failOnFailedRuns?: boolean }> = [];
|
|
32
|
+
await drainOutstandingWork({
|
|
33
|
+
state: state(),
|
|
34
|
+
timeoutMs: 1000,
|
|
35
|
+
now: () => checks * 10,
|
|
36
|
+
hasWork: () => checks++ < 2,
|
|
37
|
+
wait: async (params, _signal, deps) => {
|
|
38
|
+
waits.push({ ...params, stopOnAttention: deps.stopOnAttention, failOnFailedRuns: deps.failOnFailedRuns });
|
|
39
|
+
return waitResult("done");
|
|
40
|
+
},
|
|
41
|
+
});
|
|
42
|
+
assert.equal(waits.length, 2);
|
|
43
|
+
assert.ok(waits.every((entry) => entry.all === true && entry.stopOnAttention === false && entry.failOnFailedRuns === true));
|
|
44
|
+
assert.ok((waits[1]!.timeoutMs ?? 0) < (waits[0]!.timeoutMs ?? 0), "each wait must share one absolute deadline");
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
it("preserves wait errors instead of treating them as a successful drain", async () => {
|
|
48
|
+
await assert.rejects(() => drainOutstandingWork({
|
|
49
|
+
state: state(),
|
|
50
|
+
hasWork: () => true,
|
|
51
|
+
wait: async () => waitResult("provider 'patty' snapshot failed", true),
|
|
52
|
+
}), /Auto-drain failed.*provider 'patty' snapshot failed/);
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
it("propagates work-discovery errors", async () => {
|
|
56
|
+
await assert.rejects(() => drainOutstandingWork({
|
|
57
|
+
state: state(),
|
|
58
|
+
hasWork: () => { throw new Error("provider reconcile failed"); },
|
|
59
|
+
}), /provider reconcile failed/);
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
it("enforces one absolute timeout across repeated drains", async () => {
|
|
63
|
+
let clock = 0;
|
|
64
|
+
await assert.rejects(() => drainOutstandingWork({
|
|
65
|
+
state: state(),
|
|
66
|
+
timeoutMs: 100,
|
|
67
|
+
now: () => clock,
|
|
68
|
+
hasWork: () => true,
|
|
69
|
+
wait: async () => {
|
|
70
|
+
clock = 101;
|
|
71
|
+
return waitResult("first batch done");
|
|
72
|
+
},
|
|
73
|
+
}), /timed out after 100ms.*session 'session-a'/);
|
|
74
|
+
});
|
|
75
|
+
|
|
76
|
+
it("fails without a session identity", async () => {
|
|
77
|
+
await assert.rejects(() => drainOutstandingWork({ state: state(null) }), /without an active session identity/);
|
|
78
|
+
});
|
|
79
|
+
});
|
|
@@ -0,0 +1,285 @@
|
|
|
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 {
|
|
7
|
+
BACKGROUND_WORK_REGISTRY_KEY,
|
|
8
|
+
listBackgroundWorkProviders,
|
|
9
|
+
listBackgroundWorkWakeChannels,
|
|
10
|
+
registerBackgroundWorkProvider,
|
|
11
|
+
snapshotBackgroundWork,
|
|
12
|
+
type BackgroundWorkSnapshot,
|
|
13
|
+
} from "../../src/api/background-work.ts";
|
|
14
|
+
import { waitForSubagents, type SubagentWaitDeps } from "../../src/runs/background/subagent-wait.ts";
|
|
15
|
+
import type { SubagentState } from "../../src/shared/types.ts";
|
|
16
|
+
|
|
17
|
+
function clearRegistry(): void {
|
|
18
|
+
delete (globalThis as Record<PropertyKey, unknown>)[Symbol.for(BACKGROUND_WORK_REGISTRY_KEY)];
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
afterEach(clearRegistry);
|
|
22
|
+
|
|
23
|
+
function makeState(sessionId = "session-a"): SubagentState {
|
|
24
|
+
return {
|
|
25
|
+
baseCwd: "",
|
|
26
|
+
currentSessionId: sessionId,
|
|
27
|
+
asyncJobs: new Map(),
|
|
28
|
+
foregroundControls: new Map(),
|
|
29
|
+
lastForegroundControlId: null,
|
|
30
|
+
cleanupTimers: new Map(),
|
|
31
|
+
lastUiContext: null,
|
|
32
|
+
poller: null,
|
|
33
|
+
completionSeen: new Map(),
|
|
34
|
+
watcher: null,
|
|
35
|
+
watcherRestartTimer: null,
|
|
36
|
+
resultFileCoalescer: { schedule: () => false, clear: () => {} },
|
|
37
|
+
} as SubagentState;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
function writeStatus(root: string, id: string, state: string, sessionId = "session-a"): void {
|
|
41
|
+
const dir = path.join(root, id);
|
|
42
|
+
fs.mkdirSync(dir, { recursive: true });
|
|
43
|
+
const now = Date.now();
|
|
44
|
+
fs.writeFileSync(path.join(dir, "status.json"), JSON.stringify({
|
|
45
|
+
runId: id,
|
|
46
|
+
mode: "single",
|
|
47
|
+
state,
|
|
48
|
+
sessionId,
|
|
49
|
+
startedAt: now,
|
|
50
|
+
lastUpdate: now,
|
|
51
|
+
pid: 999999,
|
|
52
|
+
steps: [{ agent: "worker", status: state }],
|
|
53
|
+
}));
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
function waitDeps(root: string, state: SubagentState, backgroundWork: SubagentWaitDeps["backgroundWork"], sleep: () => Promise<void>): SubagentWaitDeps {
|
|
57
|
+
return {
|
|
58
|
+
state,
|
|
59
|
+
backgroundWork,
|
|
60
|
+
sleep,
|
|
61
|
+
pollIntervalMs: 250,
|
|
62
|
+
asyncDirRoot: path.join(root, "runs"),
|
|
63
|
+
resultsDir: path.join(root, "results"),
|
|
64
|
+
kill: () => true,
|
|
65
|
+
};
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
function textOf(result: { content: Array<{ type: string; text?: string }> }): string {
|
|
69
|
+
return result.content.map((part) => part.text ?? "").join("");
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
function snapshot(providers: string[], items: BackgroundWorkSnapshot["items"]): BackgroundWorkSnapshot {
|
|
73
|
+
return { providers, items };
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
describe("background-work provider protocol", () => {
|
|
77
|
+
it("replaces registrations safely across reloads and scopes snapshots to one session", () => {
|
|
78
|
+
let context: { sessionId: string; nowMs: number } | undefined;
|
|
79
|
+
const disposeOld = registerBackgroundWorkProvider({
|
|
80
|
+
name: "patty",
|
|
81
|
+
listActiveWork: () => [{ id: "old", sessionId: "session-a" }],
|
|
82
|
+
});
|
|
83
|
+
const replacement = {
|
|
84
|
+
name: "patty",
|
|
85
|
+
wakeChannels: ["patty:finished"],
|
|
86
|
+
reconcile: (value: { sessionId: string; nowMs: number }) => { context = value; },
|
|
87
|
+
listActiveWork: () => [
|
|
88
|
+
{ id: "mine", sessionId: "session-a" },
|
|
89
|
+
{ id: "theirs", sessionId: "session-b" },
|
|
90
|
+
],
|
|
91
|
+
};
|
|
92
|
+
const disposeReplacement = registerBackgroundWorkProvider(replacement);
|
|
93
|
+
disposeOld();
|
|
94
|
+
|
|
95
|
+
assert.deepEqual(listBackgroundWorkProviders(), [replacement]);
|
|
96
|
+
assert.deepEqual(listBackgroundWorkWakeChannels(), ["patty:finished"]);
|
|
97
|
+
assert.deepEqual(snapshotBackgroundWork("session-a", 42), {
|
|
98
|
+
providers: ["patty"],
|
|
99
|
+
items: [{ provider: "patty", id: "mine", sessionId: "session-a" }],
|
|
100
|
+
});
|
|
101
|
+
assert.deepEqual(context, { sessionId: "session-a", nowMs: 42 });
|
|
102
|
+
|
|
103
|
+
disposeReplacement();
|
|
104
|
+
assert.deepEqual(listBackgroundWorkProviders(), []);
|
|
105
|
+
});
|
|
106
|
+
|
|
107
|
+
it("validates provider metadata and work items strictly", () => {
|
|
108
|
+
assert.throws(() => registerBackgroundWorkProvider({ name: " patty", listActiveWork: () => [] }), /leading or trailing/);
|
|
109
|
+
assert.throws(() => registerBackgroundWorkProvider({ name: "patty", listActiveWork: () => [], wakeChannels: ["done", "done"] }), /duplicates/);
|
|
110
|
+
|
|
111
|
+
registerBackgroundWorkProvider({
|
|
112
|
+
name: "patty",
|
|
113
|
+
listActiveWork: () => [{ id: "job", sessionId: "session-a", extra: true } as never],
|
|
114
|
+
});
|
|
115
|
+
assert.throws(() => snapshotBackgroundWork("session-a"), /unknown fields: extra/);
|
|
116
|
+
clearRegistry();
|
|
117
|
+
|
|
118
|
+
registerBackgroundWorkProvider({
|
|
119
|
+
name: "patty",
|
|
120
|
+
listActiveWork: () => [
|
|
121
|
+
{ id: "job", sessionId: "session-a" },
|
|
122
|
+
{ id: "job", sessionId: "session-a" },
|
|
123
|
+
],
|
|
124
|
+
});
|
|
125
|
+
assert.throws(() => snapshotBackgroundWork("session-a"), /duplicate item 'job'/);
|
|
126
|
+
});
|
|
127
|
+
|
|
128
|
+
it("preserves list and reconcile errors with provider context", () => {
|
|
129
|
+
registerBackgroundWorkProvider({
|
|
130
|
+
name: "broken-reconcile",
|
|
131
|
+
reconcile: () => { throw new Error("pid probe failed"); },
|
|
132
|
+
listActiveWork: () => [],
|
|
133
|
+
});
|
|
134
|
+
assert.throws(() => snapshotBackgroundWork("session-a"), /broken-reconcile.*pid probe failed/);
|
|
135
|
+
clearRegistry();
|
|
136
|
+
|
|
137
|
+
registerBackgroundWorkProvider({
|
|
138
|
+
name: "broken-list",
|
|
139
|
+
listActiveWork: () => { throw new Error("registry unavailable"); },
|
|
140
|
+
});
|
|
141
|
+
assert.throws(() => snapshotBackgroundWork("session-a"), /broken-list.*registry unavailable/);
|
|
142
|
+
});
|
|
143
|
+
|
|
144
|
+
it("discovers wake channels without reconciling or listing work", () => {
|
|
145
|
+
let called = false;
|
|
146
|
+
registerBackgroundWorkProvider({
|
|
147
|
+
name: "patty",
|
|
148
|
+
wakeChannels: ["patty:finished"],
|
|
149
|
+
reconcile: () => { called = true; },
|
|
150
|
+
listActiveWork: () => { called = true; return []; },
|
|
151
|
+
});
|
|
152
|
+
assert.deepEqual(listBackgroundWorkWakeChannels(), ["patty:finished"]);
|
|
153
|
+
assert.equal(called, false);
|
|
154
|
+
});
|
|
155
|
+
});
|
|
156
|
+
|
|
157
|
+
describe("subagent_wait with background-work providers", () => {
|
|
158
|
+
it("detects completion when another item replaces it at the same count", async () => {
|
|
159
|
+
const root = fs.mkdtempSync(path.join(os.tmpdir(), "pi-provider-replace-"));
|
|
160
|
+
try {
|
|
161
|
+
let stage = 0;
|
|
162
|
+
const backgroundWork = {
|
|
163
|
+
wakeChannels: () => [],
|
|
164
|
+
snapshot: () => stage === 0
|
|
165
|
+
? snapshot(["patty"], [{ provider: "patty", id: "job-a", sessionId: "session-a" }])
|
|
166
|
+
: snapshot(["patty"], [{ provider: "patty", id: "job-b", sessionId: "session-a" }]),
|
|
167
|
+
};
|
|
168
|
+
const result = await waitForSubagents({}, undefined, waitDeps(root, makeState(), backgroundWork, async () => { stage = 1; }));
|
|
169
|
+
assert.equal(result.isError, undefined);
|
|
170
|
+
assert.match(textOf(result), /1 of 1 item\(s\) finished/);
|
|
171
|
+
assert.match(textOf(result), /provider item\(s\) finished/);
|
|
172
|
+
} finally {
|
|
173
|
+
fs.rmSync(root, { recursive: true, force: true });
|
|
174
|
+
}
|
|
175
|
+
});
|
|
176
|
+
|
|
177
|
+
it("waits for both initial async and provider identities in all mode", async () => {
|
|
178
|
+
const root = fs.mkdtempSync(path.join(os.tmpdir(), "pi-provider-mixed-"));
|
|
179
|
+
try {
|
|
180
|
+
const asyncRoot = path.join(root, "runs");
|
|
181
|
+
writeStatus(asyncRoot, "run-a", "running");
|
|
182
|
+
let stage = 0;
|
|
183
|
+
const backgroundWork = {
|
|
184
|
+
wakeChannels: () => [],
|
|
185
|
+
snapshot: () => snapshot(["patty"], stage < 2 ? [{ provider: "patty", id: "job-a", sessionId: "session-a" }] : []),
|
|
186
|
+
};
|
|
187
|
+
const result = await waitForSubagents({ all: true }, undefined, waitDeps(root, makeState(), backgroundWork, async () => {
|
|
188
|
+
stage += 1;
|
|
189
|
+
if (stage === 1) writeStatus(asyncRoot, "run-a", "complete");
|
|
190
|
+
}));
|
|
191
|
+
assert.equal(result.isError, undefined);
|
|
192
|
+
assert.match(textOf(result), /1 async run\(s\) and 1 provider item\(s\).*done/s);
|
|
193
|
+
assert.equal(stage, 2);
|
|
194
|
+
} finally {
|
|
195
|
+
fs.rmSync(root, { recursive: true, force: true });
|
|
196
|
+
}
|
|
197
|
+
});
|
|
198
|
+
|
|
199
|
+
it("fails closed when a provider disappears or its snapshot throws", async () => {
|
|
200
|
+
const root = fs.mkdtempSync(path.join(os.tmpdir(), "pi-provider-missing-"));
|
|
201
|
+
try {
|
|
202
|
+
let calls = 0;
|
|
203
|
+
const disappeared = await waitForSubagents({}, undefined, waitDeps(root, makeState(), {
|
|
204
|
+
wakeChannels: () => [],
|
|
205
|
+
snapshot: () => calls++ === 0
|
|
206
|
+
? snapshot(["patty"], [{ provider: "patty", id: "job-a", sessionId: "session-a" }])
|
|
207
|
+
: snapshot([], []),
|
|
208
|
+
}, async () => {}));
|
|
209
|
+
assert.equal(disappeared.isError, true);
|
|
210
|
+
assert.match(textOf(disappeared), /provider 'patty' disappeared/);
|
|
211
|
+
|
|
212
|
+
const failed = await waitForSubagents({}, undefined, waitDeps(root, makeState(), {
|
|
213
|
+
wakeChannels: () => [],
|
|
214
|
+
snapshot: () => { throw new Error("provider registry failed"); },
|
|
215
|
+
}, async () => {}));
|
|
216
|
+
assert.equal(failed.isError, true);
|
|
217
|
+
assert.match(textOf(failed), /provider registry failed/);
|
|
218
|
+
} finally {
|
|
219
|
+
fs.rmSync(root, { recursive: true, force: true });
|
|
220
|
+
}
|
|
221
|
+
});
|
|
222
|
+
|
|
223
|
+
it("can continue through needs-attention while draining", async () => {
|
|
224
|
+
const root = fs.mkdtempSync(path.join(os.tmpdir(), "pi-provider-attention-"));
|
|
225
|
+
try {
|
|
226
|
+
const asyncRoot = path.join(root, "runs");
|
|
227
|
+
writeStatus(asyncRoot, "run-a", "running");
|
|
228
|
+
const statusPath = path.join(asyncRoot, "run-a", "status.json");
|
|
229
|
+
const status = JSON.parse(fs.readFileSync(statusPath, "utf-8"));
|
|
230
|
+
fs.writeFileSync(statusPath, JSON.stringify({ ...status, activityState: "needs_attention" }));
|
|
231
|
+
let polls = 0;
|
|
232
|
+
const result = await waitForSubagents({ all: true }, undefined, {
|
|
233
|
+
...waitDeps(root, makeState(), { wakeChannels: () => [], snapshot: () => snapshot([], []) }, async () => {
|
|
234
|
+
polls += 1;
|
|
235
|
+
writeStatus(asyncRoot, "run-a", "complete");
|
|
236
|
+
}),
|
|
237
|
+
stopOnAttention: false,
|
|
238
|
+
});
|
|
239
|
+
assert.equal(result.isError, undefined);
|
|
240
|
+
assert.equal(polls, 1);
|
|
241
|
+
assert.match(textOf(result), /done/);
|
|
242
|
+
} finally {
|
|
243
|
+
fs.rmSync(root, { recursive: true, force: true });
|
|
244
|
+
}
|
|
245
|
+
});
|
|
246
|
+
|
|
247
|
+
it("wakes on a provider channel instead of the poll interval", async () => {
|
|
248
|
+
const root = fs.mkdtempSync(path.join(os.tmpdir(), "pi-provider-event-"));
|
|
249
|
+
try {
|
|
250
|
+
let active = true;
|
|
251
|
+
const handlers = new Map<string, Array<(data: unknown) => void>>();
|
|
252
|
+
const events = {
|
|
253
|
+
on(channel: string, handler: (data: unknown) => void) {
|
|
254
|
+
const channelHandlers = handlers.get(channel) ?? [];
|
|
255
|
+
channelHandlers.push(handler);
|
|
256
|
+
handlers.set(channel, channelHandlers);
|
|
257
|
+
return () => handlers.set(channel, (handlers.get(channel) ?? []).filter((candidate) => candidate !== handler));
|
|
258
|
+
},
|
|
259
|
+
emit(channel: string) {
|
|
260
|
+
for (const handler of handlers.get(channel) ?? []) handler(undefined);
|
|
261
|
+
},
|
|
262
|
+
};
|
|
263
|
+
const backgroundWork = {
|
|
264
|
+
wakeChannels: () => ["patty:finished"],
|
|
265
|
+
snapshot: () => snapshot(["patty"], active ? [{ provider: "patty", id: "job-a", sessionId: "session-a" }] : []),
|
|
266
|
+
};
|
|
267
|
+
const promise = waitForSubagents({}, undefined, {
|
|
268
|
+
...waitDeps(root, makeState(), backgroundWork, async (ms?: number, signal?: AbortSignal) => {
|
|
269
|
+
await new Promise<void>((resolve) => {
|
|
270
|
+
const timer = setTimeout(resolve, ms ?? 10_000);
|
|
271
|
+
signal?.addEventListener("abort", () => { clearTimeout(timer); resolve(); }, { once: true });
|
|
272
|
+
});
|
|
273
|
+
}),
|
|
274
|
+
events,
|
|
275
|
+
pollIntervalMs: 10_000,
|
|
276
|
+
});
|
|
277
|
+
setTimeout(() => { active = false; events.emit("patty:finished"); }, 15);
|
|
278
|
+
const result = await promise;
|
|
279
|
+
assert.equal(result.isError, undefined);
|
|
280
|
+
assert.match(textOf(result), /provider item\(s\) finished/);
|
|
281
|
+
} finally {
|
|
282
|
+
fs.rmSync(root, { recursive: true, force: true });
|
|
283
|
+
}
|
|
284
|
+
});
|
|
285
|
+
});
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
import assert from "node:assert/strict";
|
|
2
|
+
import { describe, it } from "node:test";
|
|
3
|
+
import { buildPiArgs } from "../../src/runs/shared/pi-args.ts";
|
|
4
|
+
|
|
5
|
+
describe("capability ceiling child launch enforcement", () => {
|
|
6
|
+
const base = {
|
|
7
|
+
baseArgs: [] as string[],
|
|
8
|
+
task: "test",
|
|
9
|
+
sessionEnabled: false,
|
|
10
|
+
inheritProjectContext: false,
|
|
11
|
+
inheritSkills: false,
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
it("intersects declared tools and preserves structured output as an internal tool", () => {
|
|
15
|
+
const { args, env } = buildPiArgs({
|
|
16
|
+
...base,
|
|
17
|
+
tools: ["read", "write", "subagent"],
|
|
18
|
+
capabilityCeiling: { version: 1, allowedTools: ["read", "structured_output"], denyExtensions: false, sources: ["test"] },
|
|
19
|
+
structuredOutput: { schema: {}, schemaPath: "/tmp/schema.json", outputPath: "/tmp/output.json" },
|
|
20
|
+
});
|
|
21
|
+
assert.deepEqual(args.slice(args.indexOf("--tools") + 1, args.indexOf("--tools") + 2), ["read,structured_output"]);
|
|
22
|
+
assert.equal(env.SELESAI_SUBAGENT_CAPABILITY_CEILING_V1 !== undefined, true);
|
|
23
|
+
assert.equal(args.includes("write"), false);
|
|
24
|
+
assert.equal(args.includes("subagent"), false);
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
it("allows a valid empty intersection and denies configured extensions", () => {
|
|
28
|
+
const { args } = buildPiArgs({
|
|
29
|
+
...base,
|
|
30
|
+
tools: ["read", "/tmp/provider.ts"],
|
|
31
|
+
extensions: ["/tmp/extension.ts"],
|
|
32
|
+
capabilityCeiling: { version: 1, allowedTools: [], denyExtensions: true, sources: ["plan"] },
|
|
33
|
+
});
|
|
34
|
+
assert.ok(args.includes("--no-tools"));
|
|
35
|
+
assert.ok(args.includes("--no-extensions"));
|
|
36
|
+
assert.equal(args.includes("/tmp/provider.ts"), false);
|
|
37
|
+
assert.equal(args.includes("/tmp/extension.ts"), false);
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
it("restricts omitted tool declarations without requiring every allowed name", () => {
|
|
41
|
+
const { args, env } = buildPiArgs({
|
|
42
|
+
...base,
|
|
43
|
+
capabilityCeiling: { version: 1, allowedTools: ["read", "grep"], denyExtensions: true, sources: ["plan"] },
|
|
44
|
+
});
|
|
45
|
+
assert.ok(args.includes("--tools"));
|
|
46
|
+
assert.ok(args.includes("grep,read"));
|
|
47
|
+
assert.equal(env.SELESAI_SUBAGENT_REQUIRED_TOOLS, undefined);
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
it("does not report retained extension paths as removed tools", () => {
|
|
52
|
+
const { capabilityAudit } = buildPiArgs({
|
|
53
|
+
...base,
|
|
54
|
+
tools: ["read", "/tmp/provider.ts"],
|
|
55
|
+
extensions: ["/tmp/extension.ts"],
|
|
56
|
+
capabilityCeiling: { version: 1, allowedTools: ["read"], denyExtensions: false, sources: ["plan"] },
|
|
57
|
+
});
|
|
58
|
+
assert.deepEqual(capabilityAudit?.requestedTools, ["read"]);
|
|
59
|
+
assert.deepEqual(capabilityAudit?.removedTools, []);
|
|
60
|
+
assert.equal(capabilityAudit?.removedExtensionCount, 0);
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
it("counts denied extension entries without exposing them as tool names", () => {
|
|
64
|
+
const { capabilityAudit } = buildPiArgs({
|
|
65
|
+
...base,
|
|
66
|
+
tools: ["read", "/tmp/provider.ts"],
|
|
67
|
+
extensions: ["/tmp/extension.ts"],
|
|
68
|
+
subagentOnlyExtensions: ["/tmp/child-only.ts"],
|
|
69
|
+
capabilityCeiling: { version: 1, allowedTools: ["read"], denyExtensions: true, sources: ["plan"] },
|
|
70
|
+
});
|
|
71
|
+
assert.deepEqual(capabilityAudit?.requestedTools, ["read"]);
|
|
72
|
+
assert.deepEqual(capabilityAudit?.removedTools, []);
|
|
73
|
+
assert.equal(capabilityAudit?.removedExtensionCount, 3);
|
|
74
|
+
});
|
|
75
|
+
|
|
76
|
+
it("fails closed when lazy skills require a denied read tool", () => {
|
|
77
|
+
assert.throws(() => buildPiArgs({
|
|
78
|
+
...base,
|
|
79
|
+
tools: ["grep"],
|
|
80
|
+
requireReadTool: true,
|
|
81
|
+
capabilityCeiling: { version: 1, allowedTools: ["grep"], denyExtensions: false, sources: ["plan"] },
|
|
82
|
+
}), /excludes required tool 'read'/);
|
|
83
|
+
});
|
|
84
|
+
});
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import assert from "node:assert/strict";
|
|
2
|
+
import { describe, it } from "node:test";
|
|
3
|
+
import {
|
|
4
|
+
decodeSubagentCapabilityCeiling,
|
|
5
|
+
encodeSubagentCapabilityCeiling,
|
|
6
|
+
intersectSubagentCapabilityCeilings,
|
|
7
|
+
resolveCurrentSubagentCapabilityCeiling,
|
|
8
|
+
parseSubagentCapabilityCeiling,
|
|
9
|
+
registerSubagentCapabilityCeiling,
|
|
10
|
+
resolveSubagentCapabilityCeiling,
|
|
11
|
+
} from "../../src/api/capability-ceiling.ts";
|
|
12
|
+
|
|
13
|
+
describe("subagent capability ceiling", () => {
|
|
14
|
+
it("intersects active registrations for an exact session", () => {
|
|
15
|
+
const sessionId = `cap-${Date.now()}-${Math.random()}`;
|
|
16
|
+
const first = registerSubagentCapabilityCeiling({ sessionId, source: "plan", ceiling: { allowedTools: ["read", "grep", "write"] } });
|
|
17
|
+
const second = registerSubagentCapabilityCeiling({ sessionId, source: "review", ceiling: { allowedTools: ["read", "grep"], denyExtensions: true } });
|
|
18
|
+
assert.deepEqual(resolveSubagentCapabilityCeiling(sessionId), {
|
|
19
|
+
version: 1,
|
|
20
|
+
allowedTools: ["grep", "read"],
|
|
21
|
+
denyExtensions: true,
|
|
22
|
+
sources: ["plan", "review"],
|
|
23
|
+
});
|
|
24
|
+
assert.equal(resolveSubagentCapabilityCeiling(`${sessionId}-other`), undefined);
|
|
25
|
+
second.dispose();
|
|
26
|
+
first.dispose();
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
it("keeps explicit empty allowlists distinct from unrestricted state", () => {
|
|
30
|
+
const ceiling = intersectSubagentCapabilityCeilings({ version: 1, allowedTools: [], denyExtensions: false, sources: ["test"] });
|
|
31
|
+
assert.deepEqual(ceiling?.allowedTools, []);
|
|
32
|
+
assert.equal(intersectSubagentCapabilityCeilings(), undefined);
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
it("rejects malformed policy and disposed updates", () => {
|
|
36
|
+
assert.throws(() => registerSubagentCapabilityCeiling({ sessionId: "x", source: "x", ceiling: {} }), /allowedTools or denyExtensions/);
|
|
37
|
+
const handle = registerSubagentCapabilityCeiling({ sessionId: "disposed", source: "test", ceiling: { denyExtensions: true } });
|
|
38
|
+
handle.dispose();
|
|
39
|
+
assert.throws(() => handle.update({ allowedTools: ["read"] }), /disposed/);
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
it("round-trips inherited policy and rejects malformed payloads", () => {
|
|
43
|
+
const input = { version: 1 as const, allowedTools: ["read"], denyExtensions: true, sources: ["plan"] };
|
|
44
|
+
assert.deepEqual(decodeSubagentCapabilityCeiling(encodeSubagentCapabilityCeiling(input)), input);
|
|
45
|
+
assert.throws(() => decodeSubagentCapabilityCeiling("not-base64-json"), /Invalid inherited capability ceiling/);
|
|
46
|
+
assert.throws(() => parseSubagentCapabilityCeiling({ version: 1, allowedTools: ["read"], denyExtensions: true }), /sources/);
|
|
47
|
+
assert.throws(() => parseSubagentCapabilityCeiling({ version: 2, allowedTools: ["read"], denyExtensions: true, sources: ["plan"] }), /version/);
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
it("combines inherited process policy with exact-session registrations", () => {
|
|
51
|
+
const previous = process.env.SELESAI_SUBAGENT_CAPABILITY_CEILING_V1;
|
|
52
|
+
const sessionId = `current-${Date.now()}-${Math.random()}`;
|
|
53
|
+
const handle = registerSubagentCapabilityCeiling({ sessionId, source: "local", ceiling: { allowedTools: ["grep", "read"] } });
|
|
54
|
+
try {
|
|
55
|
+
process.env.SELESAI_SUBAGENT_CAPABILITY_CEILING_V1 = encodeSubagentCapabilityCeiling({ version: 1, allowedTools: ["read", "write"], denyExtensions: true, sources: ["ancestor"] });
|
|
56
|
+
assert.deepEqual(resolveCurrentSubagentCapabilityCeiling(sessionId), {
|
|
57
|
+
version: 1,
|
|
58
|
+
allowedTools: ["read"],
|
|
59
|
+
denyExtensions: true,
|
|
60
|
+
sources: ["ancestor", "local"],
|
|
61
|
+
});
|
|
62
|
+
} finally {
|
|
63
|
+
handle.dispose();
|
|
64
|
+
if (previous === undefined) delete process.env.SELESAI_SUBAGENT_CAPABILITY_CEILING_V1;
|
|
65
|
+
else process.env.SELESAI_SUBAGENT_CAPABILITY_CEILING_V1 = previous;
|
|
66
|
+
}
|
|
67
|
+
});
|
|
68
|
+
});
|