gentle-pi 4.5.1 → 4.7.0
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/README.md +17 -15
- package/assets/agents/gentle-ai-explore.md +1 -0
- package/assets/agents/gentle-ai-verify.md +8 -1
- package/assets/agents/gentle-ai-worker.md +4 -0
- package/assets/agents/jd-fix-agent.md +1 -0
- package/assets/agents/jd-judge-a.md +1 -0
- package/assets/agents/jd-judge-b.md +1 -0
- package/assets/design-canvas/canvas.css +13 -1
- package/assets/design-canvas/canvas.js +11 -2
- package/assets/install-wizard/wizard.js +1 -0
- package/assets/migrations/agent-body-history.json +162 -0
- package/assets/orchestrator-delegation-reference.md +7 -7
- package/assets/orchestrator-delegation.md +3 -3
- package/assets/orchestrator-full-delegation-card.md +65 -0
- package/assets/orchestrator-full-delegation.md +34 -0
- package/assets/orchestrator-memory.md +3 -3
- package/assets/orchestrator-prompts.md +1 -1
- package/assets/orchestrator-skills.md +1 -1
- package/assets/orchestrator-verification.md +14 -8
- package/assets/orchestrator.md +11 -11
- package/bin/gentle-shell.mjs +225 -82
- package/docs/agent-status.md +61 -0
- package/docs/bundled-install.md +7 -5
- package/docs/ci-performance.md +11 -0
- package/docs/delegated-verification.md +35 -7
- package/docs/fast-mode.md +15 -0
- package/docs/gentle-agents-activity.md +22 -0
- package/docs/gentle-shell.md +113 -25
- package/docs/install-wizard.md +2 -2
- package/docs/mcp-status.md +52 -0
- package/docs/permission-modes.md +9 -4
- package/docs/prompt-budget.md +28 -0
- package/docs/readme-reference.md +154 -50
- package/docs/render-cache-performance.md +11 -1
- package/docs/review-coordinator.md +33 -0
- package/docs/review-request-context.md +19 -0
- package/docs/review-windows-acl.md +18 -0
- package/docs/session-profile-format.md +20 -5
- package/docs/sound-notifications.md +1 -1
- package/docs/star-prompt.md +32 -0
- package/docs/voice.md +6 -3
- package/docs/work-continuity.md +46 -0
- package/docs/yolo-mode.md +5 -5
- package/extensions/ask-user-choice.ts +1 -0
- package/extensions/ask-user-question.ts +2 -0
- package/extensions/child-safety.ts +3 -0
- package/extensions/codegraph-tools.ts +38 -4
- package/extensions/gentle-agent-status.ts +99 -0
- package/extensions/gentle-agents.ts +803 -84
- package/extensions/gentle-ai.ts +2491 -596
- package/extensions/gentle-fast.ts +61 -0
- package/extensions/gentle-guide.ts +174 -0
- package/extensions/gentle-herdr-activity.ts +21 -1
- package/extensions/gentle-herdr-agent.ts +144 -0
- package/extensions/gentle-program-identity.ts +61 -0
- package/extensions/gentle-shell.ts +895 -120
- package/extensions/gentle-star-prompt.ts +334 -0
- package/extensions/gentle-stats.ts +5 -5
- package/extensions/gentle-todo.ts +59 -23
- package/extensions/gentle-tps.ts +48 -0
- package/extensions/history/store.ts +18 -12
- package/extensions/quiet-tools.ts +38 -8
- package/extensions/skill-registry.ts +210 -21
- package/extensions/startup-banner.ts +69 -10
- package/lib/agent-assets.ts +74 -17
- package/lib/agent-profile-pin.ts +3 -3
- package/lib/agent-profiles.ts +161 -3
- package/lib/agent-status.ts +105 -0
- package/lib/agents-config.ts +58 -3
- package/lib/agents-history.ts +24 -5
- package/lib/agents-keys.ts +8 -16
- package/lib/agents-messaging.ts +47 -5
- package/lib/agents-protocol.ts +80 -4
- package/lib/agents-runner.ts +287 -15
- package/lib/agents-view.ts +6 -1
- package/lib/agents-widget.ts +132 -9
- package/lib/auto-permission-runtime.ts +1 -1
- package/lib/bounded-writer-admission.ts +13 -1
- package/lib/bridge-cost.ts +28 -0
- package/lib/card-content-policy.ts +8 -6
- package/lib/codemode-renderer.ts +16 -0
- package/lib/command-palette-catalog.ts +1 -0
- package/lib/command-palette.ts +154 -25
- package/lib/context-backstop.ts +14 -5
- package/lib/destructive-command-guard.ts +48 -4
- package/lib/execution-surface-guard.ts +20 -0
- package/lib/exploration-budget.ts +64 -0
- package/lib/gentle-ai-binary.ts +1 -1
- package/lib/gentle-design.ts +3 -0
- package/lib/gentle-guide.ts +201 -0
- package/lib/gentle-shell-bundled.ts +6 -19
- package/lib/gentle-shell-launcher.ts +47 -8
- package/lib/herdr-activity.ts +23 -5
- package/lib/herdr-busy.ts +45 -0
- package/lib/herdr-task-summary-policy.ts +85 -0
- package/lib/image-attachments.ts +33 -0
- package/lib/image-disk-cache.ts +137 -0
- package/lib/inprocess-reviewer.ts +282 -132
- package/lib/jobs-sidebar-state.ts +5 -6
- package/lib/jobs-view.ts +198 -11
- package/lib/jobs-widget.ts +16 -52
- package/lib/keymaps-customize.ts +81 -0
- package/lib/keymaps.ts +291 -0
- package/lib/model-fallback-notice.ts +61 -0
- package/lib/model-fallback-policy.ts +141 -0
- package/lib/model-fallback-store.ts +143 -0
- package/lib/model-routing-authority.ts +32 -6
- package/lib/nan-provider.ts +3 -2
- package/lib/native-choice-list.ts +20 -2
- package/lib/native-review-cli.ts +103 -21
- package/lib/notification-customize.ts +48 -51
- package/lib/openai-fast-tier.ts +22 -0
- package/lib/orchestrator-discovery.ts +5 -1
- package/lib/orchestrator-fallback.ts +75 -0
- package/lib/orchestrator-mode-policy.ts +105 -0
- package/lib/pasted-image-paths.ts +113 -0
- package/lib/questionnaire/questionnaire-view.ts +225 -18
- package/lib/rdd-mode-control.ts +32 -0
- package/lib/reply-language-anchor.ts +104 -0
- package/lib/review-blocker.ts +92 -0
- package/lib/review-candidate-symlink-scan.ts +136 -0
- package/lib/review-candidate-view-owner.ts +85 -44
- package/lib/review-candidate-view.ts +10 -7
- package/lib/review-continuation-registry.ts +99 -0
- package/lib/review-coordinator.ts +163 -0
- package/lib/review-failure-facts.ts +49 -0
- package/lib/review-host-relay.ts +51 -11
- package/lib/review-integration-v2.ts +29 -8
- package/lib/review-relay-phase-timing.ts +45 -0
- package/lib/review-repository.ts +5 -0
- package/lib/review-start-context.ts +17 -0
- package/lib/session-profile-append-controller.ts +21 -6
- package/lib/session-profile-authority.ts +119 -0
- package/lib/session-profile-binding.ts +54 -5
- package/lib/session-profile-freeze.ts +107 -9
- package/lib/session-profile-integration.ts +313 -0
- package/lib/session-profile-persistence.ts +63 -9
- package/lib/shell-bar.ts +269 -72
- package/lib/shell-card.ts +26 -6
- package/lib/shell-changes.ts +2 -0
- package/lib/shell-page.ts +120 -0
- package/lib/shell-panel.ts +163 -0
- package/lib/shell-prompt.ts +53 -1
- package/lib/shell-sidebar-layout.ts +198 -53
- package/lib/shell-sidebar.ts +61 -1
- package/lib/shell-stats.ts +123 -0
- package/lib/shell-todo.ts +79 -1
- package/lib/shell-usage.ts +12 -2
- package/lib/star-prompt.ts +197 -0
- package/lib/verifier-admission.ts +18 -8
- package/lib/verifier-settle-reminder.ts +64 -0
- package/lib/vim-editor-adapter.ts +6 -1
- package/lib/visual-customization-policy.ts +67 -12
- package/lib/visual-customize-view.ts +373 -40
- package/lib/visual-layout-preview.ts +47 -0
- package/lib/visual-profiles.ts +2 -2
- package/lib/windows-session-transport.ts +53 -2
- package/lib/yolo-session-policy.ts +68 -16
- package/package.json +2 -1
- package/runtime/gentle-ai-binary.mjs +1 -1
- package/runtime/gentle-shell-bundled.mjs +6 -19
- package/runtime/gentle-shell-launcher.mjs +46 -7
- package/runtime/native-review-cli.mjs +100 -18
- package/runtime/review-integration-v2.mjs +29 -8
- package/runtime/windows-session-transport.ps1 +60 -3
- package/scripts/bootstrap.sh +4 -1
- package/scripts/build-full-delegation-card.mjs +175 -0
- package/scripts/bundled-install.mjs +38 -8
- package/scripts/download-progress.mjs +68 -0
- package/scripts/gentle-ai-installer.mjs +41 -18
- package/scripts/gentle-ai-proxy.mjs +294 -0
- package/scripts/install-gentle-ai.mjs +14 -1
- package/scripts/installer-preflight.mjs +6 -6
- package/scripts/installer-runner.mjs +27 -12
- package/scripts/installer-server.mjs +8 -7
- package/scripts/pi-update.mjs +113 -3
- package/scripts/render-cache-host.mjs +72 -0
- package/scripts/render-cache-performance-worker.mjs +5 -4
- package/scripts/render-cache-performance.mjs +6 -1
- package/scripts/run-test-suite.mjs +41 -13
- package/scripts/shell-snapshot.mjs +340 -0
- package/scripts/test-packed-runner.mjs +1 -1
- package/scripts/update-agent-body-history.mjs +41 -0
- package/scripts/verify-installer-tap.mjs +45 -0
- package/scripts/verify-package-files.mjs +14 -2
- package/scripts/voice-worker.cjs +32 -6
- package/skills/design/SKILL.md +11 -8
- package/skills/gentle-ai/SKILL.md +4 -4
- package/skills/gentle-ui-design/SKILL.md +46 -0
- package/skills/gentle-ui-design/references/adaptive-interfaces.md +46 -0
- package/skills/gentle-ui-design/references/browse-and-compare.md +62 -0
- package/skills/gentle-ui-design/references/composition-and-feedback.md +56 -0
- package/skills/gentle-ui-design/references/task-and-content.md +60 -0
- package/skills/skill-registry/SKILL.md +4 -2
- package/skills/tui-design/NOTICE.md +5 -0
- package/skills/tui-design/SKILL.md +56 -0
- package/skills/tui-design/references/commands.md +75 -0
- package/skills/tui-design/references/critique.md +48 -0
- package/skills/tui-design/references/design-doc.md +44 -0
- package/skills/tui-design/references/terminal-craft.md +64 -0
- package/skills/tui-design/references/visual-loop.md +32 -0
- package/skills/work-unit-commits/SKILL.md +6 -7
- package/tests/agent-home.test.ts +28 -9
- package/tests/agent-profiles-workflow.test.ts +163 -0
- package/tests/agent-risk-escalation.test.ts +1 -1
- package/tests/agent-status.test.ts +143 -0
- package/tests/agents-config.test.ts +96 -0
- package/tests/agents-history.test.ts +31 -0
- package/tests/agents-jobs-frames.test.ts +93 -0
- package/tests/agents-prompt-lifecycle-runtime.test.ts +376 -0
- package/tests/agents-protocol.test.ts +53 -1
- package/tests/agents-runner-drain.test.ts +193 -0
- package/tests/agents-runner.test.ts +345 -4
- package/tests/agents-view.test.ts +27 -0
- package/tests/agents-widget.test.ts +312 -10
- package/tests/append-system-prompt-route.test.ts +4 -1
- package/tests/ask-user-choice.test.ts +4 -3
- package/tests/ask-user-question.test.ts +97 -0
- package/tests/auto-permission-runtime.test.ts +1 -1
- package/tests/autonomous-guard.test.ts +346 -10
- package/tests/bounded-scan-contract.test.ts +39 -0
- package/tests/bounded-stop-contract.test.ts +43 -3
- package/tests/bridge-cost.test.ts +47 -0
- package/tests/bundled-install.test.ts +36 -9
- package/tests/card-content-policy.test.ts +3 -3
- package/tests/chained-pr-skill.test.ts +8 -6
- package/tests/child-safety.test.ts +11 -0
- package/tests/ci-concurrency.test.ts +11 -0
- package/tests/ci-merge-base-identity.test.ts +114 -0
- package/tests/codegraph-tools.test.ts +80 -5
- package/tests/codemode-rendering.test.ts +22 -2
- package/tests/command-palette.test.ts +300 -3
- package/tests/commit-slice-signal.test.ts +11 -9
- package/tests/delegate-for-reason-contract.test.ts +8 -7
- package/tests/design-canvas-assets.test.ts +185 -2
- package/tests/destructive-command-guard.test.ts +52 -0
- package/tests/download-progress.test.ts +71 -0
- package/tests/execution-surface-guard.test.ts +55 -0
- package/tests/exploration-budget.test.ts +128 -0
- package/tests/fixtures/agent-assets/gentle-ai-worker.strict-tdd-era.md +122 -0
- package/tests/fixtures/measure-orchestrator-prompt.mjs +2 -1
- package/tests/fixtures/primary-session-prompt/gentleman.golden.md +26 -14
- package/tests/fixtures/proxy-tls/proxy.crt +19 -0
- package/tests/fixtures/proxy-tls/proxy.key +28 -0
- package/tests/fixtures/session-profile-v1/gentle-ai-reviewer.ts +89 -0
- package/tests/fixtures/session-profile-v1/replay.ts +172 -0
- package/tests/fixtures/session-profile-v1/session-profile-authority.ts +113 -0
- package/tests/fixtures/session-profile-v1/session-profile-binding.ts +83 -0
- package/tests/fixtures/session-profile-v1/session-profile-disk-reader.ts +182 -0
- package/tests/fixtures/session-profile-v1/session-profile-freeze.ts +290 -0
- package/tests/fixtures/session-profile-v1/session-profile-persistence.ts +195 -0
- package/tests/fixtures/session-profile-v1/v1-inputs.ts +16 -0
- package/tests/fixtures/windows-pipe-availability.ps1 +26 -0
- package/tests/fixtures/windows-session-bootstrap.ps1 +6 -2
- package/tests/full-delegation-closure.test.ts +131 -0
- package/tests/full-delegation-notices.test.ts +76 -0
- package/tests/generic-agent-tools.test.ts +3 -3
- package/tests/gentle-agent-status.test.ts +74 -0
- package/tests/gentle-agents-child-jobs.test.ts +237 -0
- package/tests/gentle-agents.test.ts +1491 -38
- package/tests/gentle-ai-binary.test.ts +3 -1
- package/tests/gentle-ai-elapsed-store.test.ts +19 -0
- package/tests/gentle-ai-exploration-budget.test.ts +151 -0
- package/tests/gentle-ai-installer.test.ts +134 -51
- package/tests/gentle-ai-proxy.test.ts +434 -0
- package/tests/gentle-ai.test.ts +1101 -52
- package/tests/gentle-design.test.ts +21 -0
- package/tests/gentle-fast.test.ts +73 -0
- package/tests/gentle-guide.test.ts +208 -0
- package/tests/gentle-herdr-activity.test.ts +80 -3
- package/tests/gentle-herdr-agent.test.ts +111 -0
- package/tests/gentle-program-identity.test.ts +197 -0
- package/tests/gentle-shell-bin.test.ts +172 -26
- package/tests/gentle-shell-bundled.test.ts +207 -31
- package/tests/gentle-shell-launcher.test.ts +93 -10
- package/tests/gentle-shell.test.ts +1937 -66
- package/tests/gentle-stats.test.ts +15 -2
- package/tests/gentle-todo.test.ts +67 -4
- package/tests/gentle-tps.test.ts +123 -0
- package/tests/gentle-ui-design-skill.test.ts +59 -0
- package/tests/herdr-busy.test.ts +59 -0
- package/tests/herdr-task-summary-policy.test.ts +132 -0
- package/tests/history-store-private-mode.test.ts +40 -0
- package/tests/image-disk-cache.test.ts +163 -0
- package/tests/image-paste-chips.test.ts +42 -0
- package/tests/independent-recovery-delivery.test.ts +83 -0
- package/tests/inprocess-reviewer.test.ts +298 -4
- package/tests/installer-posix-bootstrap.test.ts +68 -6
- package/tests/installer-preflight.test.ts +5 -4
- package/tests/installer-runner.test.ts +79 -44
- package/tests/installer-server.test.ts +14 -11
- package/tests/installer-windows-diagnostics.test.ts +4 -5
- package/tests/isolated-config-home.ts +28 -0
- package/tests/jobs-view.test.ts +260 -6
- package/tests/jobs-widget.test.ts +25 -37
- package/tests/keymaps-customize.test.ts +114 -0
- package/tests/keymaps.test.ts +103 -0
- package/tests/maintainer/mcp-status.maintest.ts +88 -0
- package/tests/maintainer/pi-update-source.maintest.ts +116 -0
- package/tests/modal-mouse-boundaries.test.ts +136 -0
- package/tests/model-fallback-notice.test.ts +45 -0
- package/tests/model-fallback-policy.test.ts +83 -0
- package/tests/model-fallback-store.test.ts +111 -0
- package/tests/model-routing-authority.test.ts +178 -2
- package/tests/nan-provider.test.ts +4 -4
- package/tests/native-choice-list.test.ts +77 -2
- package/tests/native-review-capability-contract.test.ts +7 -1
- package/tests/native-review-cli.test.ts +269 -1
- package/tests/no-self-pause-contract.test.ts +22 -0
- package/tests/notification-customize.test.ts +58 -34
- package/tests/odd-routing-canonical-ratchet.test.ts +6 -6
- package/tests/odd-routing-contract.test.ts +1 -1
- package/tests/orchestrator-budget.test.ts +7 -2
- package/tests/orchestrator-delegation-mode.test.ts +153 -0
- package/tests/orchestrator-fallback.test.ts +82 -0
- package/tests/orchestrator-mode-policy.test.ts +175 -0
- package/tests/orchestrator-prompt-budget.test.ts +133 -0
- package/tests/orchestrator-rdd-ownership.test.ts +2 -2
- package/tests/package-manifest.test.ts +169 -14
- package/tests/pasted-image-paths.test.ts +118 -0
- package/tests/permission-allowlist.test.ts +202 -0
- package/tests/persona-reply-language.test.ts +20 -1
- package/tests/pi-update-launcher.test.ts +40 -8
- package/tests/pi-update-source.test.ts +162 -0
- package/tests/pnpm-workspace-config.test.ts +58 -0
- package/tests/primary-session-prompt.test.ts +13 -0
- package/tests/profile-fast-tier.test.ts +311 -0
- package/tests/profile-pin.test.ts +29 -2
- package/tests/profile-tier-footer.test.ts +84 -0
- package/tests/profiles-panel-delegation-mode.test.ts +422 -0
- package/tests/questionnaire-view.test.ts +265 -0
- package/tests/quiet-bash-runtime.test.ts +1 -1
- package/tests/quiet-tool-rendering.test.ts +48 -0
- package/tests/rdd-aware-verification-contract.test.ts +16 -11
- package/tests/rdd-customize.test.ts +287 -0
- package/tests/rdd-mode-cache.test.ts +450 -0
- package/tests/rdd-mode-control.test.ts +407 -0
- package/tests/rdd-mode-scope-regression.test.ts +137 -0
- package/tests/rdd-off-independent-regression.test.ts +69 -0
- package/tests/rdd-status-line.test.ts +18 -0
- package/tests/render-cache-performance.test.ts +171 -2
- package/tests/reply-language-anchor.test.ts +173 -0
- package/tests/review-agent-end-preflight.test.ts +1 -1
- package/tests/review-blocker.test.ts +193 -0
- package/tests/review-candidate-owner-retry.test.ts +1 -1
- package/tests/review-candidate-owner-sweep.test.ts +93 -0
- package/tests/review-candidate-symlink-scan.test.ts +157 -0
- package/tests/review-candidate-view.test.ts +52 -1
- package/tests/review-candidate-windows-boundary.test.ts +131 -0
- package/tests/review-candidate-windows-probe.test.ts +63 -0
- package/tests/review-committed-restart-ack.test.ts +129 -0
- package/tests/review-continuation-registry.test.ts +76 -0
- package/tests/review-controller-native-routing.test.ts +381 -11
- package/tests/review-controller-workspace-root.test.ts +230 -3
- package/tests/review-controller.test.ts +96 -11
- package/tests/review-coordinator-runtime.test.ts +117 -0
- package/tests/review-coordinator.test.ts +195 -0
- package/tests/review-failure-facts.test.ts +87 -0
- package/tests/review-gate.test.ts +24 -0
- package/tests/review-host-relay-routing.test.ts +258 -4
- package/tests/review-host-relay.test.ts +39 -0
- package/tests/review-inspect-preflight.test.ts +197 -0
- package/tests/review-integration-v2-forward.test.ts +59 -0
- package/tests/review-integration-v2.test.ts +46 -3
- package/tests/review-json-arguments.test.ts +65 -10
- package/tests/review-last-event-closure.test.ts +68 -0
- package/tests/review-loadout-rdd-off-sdk.test.ts +65 -31
- package/tests/review-owner-identity.test.ts +60 -24
- package/tests/review-relay-phase-timing.test.ts +128 -0
- package/tests/review-relay-transport-agent.test.ts +12 -2
- package/tests/review-repository.test.ts +52 -1
- package/tests/review-reviewer-evidence.test.ts +183 -0
- package/tests/review-risk-assessment.test.ts +74 -3
- package/tests/review-session-standing-permission-controller.test.ts +21 -1
- package/tests/review-sidebar-state.test.ts +5 -5
- package/tests/review-start-context.test.ts +19 -0
- package/tests/review-tool-prose-budget.test.ts +121 -0
- package/tests/run-test-suite.test.ts +183 -6
- package/tests/runtime-harness.mjs +4 -1
- package/tests/sensitive-path-tools.test.ts +250 -0
- package/tests/session-profile-append-controller-pi.test.ts +60 -31
- package/tests/session-profile-append-controller.test.ts +63 -0
- package/tests/session-profile-authority.test.ts +259 -0
- package/tests/session-profile-binding.test.ts +34 -1
- package/tests/session-profile-disk-reader-pi.test.ts +58 -16
- package/tests/session-profile-extension.test.ts +615 -0
- package/tests/session-profile-freeze.test.ts +110 -2
- package/tests/session-profile-integration.test.ts +857 -0
- package/tests/session-profile-persistence.test.ts +57 -0
- package/tests/session-profile-v1-compat.test.ts +255 -0
- package/tests/shell-bar.test.ts +274 -72
- package/tests/shell-card.test.ts +13 -1
- package/tests/shell-page.test.ts +108 -0
- package/tests/shell-panel.test.ts +360 -0
- package/tests/shell-prompt.test.ts +54 -0
- package/tests/shell-render-cache.test.ts +5 -0
- package/tests/shell-sidebar-fullscreen.test.ts +13 -1
- package/tests/shell-sidebar-layout.test.ts +447 -44
- package/tests/shell-sidebar-scroll-benchmark.test.ts +1 -1
- package/tests/shell-stats.test.ts +90 -0
- package/tests/shell-surface-transparent.test.ts +89 -0
- package/tests/shell-todo.test.ts +12 -0
- package/tests/shell-usage.test.ts +14 -0
- package/tests/skill-registry.test.ts +902 -2
- package/tests/star-prompt.test.ts +470 -0
- package/tests/startup-banner.test.ts +209 -2
- package/tests/startup-home-repo.test.ts +2 -0
- package/tests/support/review-coordinator-runtime.ts +69 -0
- package/tests/task-size-routing-contract.test.ts +50 -4
- package/tests/verifier-admission.test.ts +49 -0
- package/tests/verifier-settle-reminder.test.ts +281 -0
- package/tests/verify-first-launch-contract.test.ts +134 -8
- package/tests/verify-installer-tap.test.ts +57 -0
- package/tests/vim-editor-adapter.test.ts +2 -2
- package/tests/visual-customization-policy.test.ts +95 -8
- package/tests/visual-customize-view.test.ts +818 -9
- package/tests/visual-layout-preview.test.ts +42 -0
- package/tests/visual-profiles.test.ts +11 -0
- package/tests/voice-worker.test.ts +73 -2
- package/tests/windows-session-bootstrap.test.ts +105 -2
- package/tests/windows-session-transport.test.ts +126 -0
- package/tests/work-continuity-contract.test.ts +114 -0
- package/tests/writer-feature-document-admission.test.ts +92 -0
- package/tests/writer-surfaces.test.ts +12 -10
- package/tests/yolo-customize.test.ts +57 -15
- package/tests/yolo-mode-runtime.test.ts +4 -2
- package/tests/yolo-mode.test.ts +39 -20
- package/tests/yolo-session-policy.test.ts +270 -1
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import assert from "node:assert/strict";
|
|
2
|
-
import { appendFileSync, chmodSync, copyFileSync, existsSync, mkdirSync, mkdtempSync, readFileSync, realpathSync, renameSync, rmSync, writeFileSync } from "node:fs";
|
|
2
|
+
import { appendFileSync, chmodSync, copyFileSync, existsSync, mkdirSync, mkdtempSync, readdirSync, readFileSync, realpathSync, renameSync, rmSync, writeFileSync } from "node:fs";
|
|
3
3
|
import { execFileSync } from "node:child_process";
|
|
4
4
|
import { homedir, tmpdir } from "node:os";
|
|
5
5
|
import { createRequire, syncBuiltinESMExports } from "node:module";
|
|
@@ -16,10 +16,10 @@ import { createAssistantMessageEventStream, type AssistantMessage } from "@earen
|
|
|
16
16
|
import { visibleWidth, type Component, type TUI, type TuiMouseEvent } from "@earendil-works/pi-tui";
|
|
17
17
|
import { sidebarState } from "../lib/shell-sidebar.ts";
|
|
18
18
|
import { CHILD_PACKAGE_INJECTION_ENV, encodeChildPackageInjection } from "../lib/child-package-injection.ts";
|
|
19
|
-
import
|
|
19
|
+
import installGentleAgents, { agentRuntimePaths, agentsCollapseKey, agentsEnabled, agentsStopKey, agentsViewKey, agentResultPreview, answerThroughUi, childContextExtensionPaths, completionText, createDefaultSessionTransport, legacySubagentsInstalled, HOLD_RECHECK_MS, INPUT_PROMPT_GRACE_MS, PARENT_WAKE_GRACE_MS, type AgentsDeps, type SessionTransportFactory } from "../extensions/gentle-agents.ts";
|
|
20
20
|
import { ActiveSessionClient, ActiveSessionListener, SessionPresenceError, SessionPresenceRegistry, type PresenceRecord } from "../lib/agents-session-transport.ts";
|
|
21
21
|
import { WindowsActiveSessionClient, WindowsActiveSessionListener } from "../lib/windows-session-transport.ts";
|
|
22
|
-
import { historyDir, loadHistory, saveTask } from "../lib/agents-history.ts";
|
|
22
|
+
import { historyDir, loadHistory, loadStoredTask, saveTask } from "../lib/agents-history.ts";
|
|
23
23
|
import { STALE_COMPLETION_MS } from "../lib/agents-completion-delivery.ts";
|
|
24
24
|
import { applyTaskEvent, emptyThread, MISSING_TOOLS_NOTE_PREFIX, TASK_EVENT, TASK_STATUS, TaskStore, type TaskRecord } from "../lib/agents-protocol.ts";
|
|
25
25
|
import { NativePointerScope } from "../lib/native-pointer-region.ts";
|
|
@@ -35,6 +35,10 @@ import { taskHeader } from "../lib/agents-view.ts";
|
|
|
35
35
|
import { readFrozenInheritedProfile, resetFrozenInheritedProfilesForTesting } from "../lib/session-profile-freeze.ts";
|
|
36
36
|
import { CHILD_METRICS_EVENT } from "../lib/runtime-metrics-children.ts";
|
|
37
37
|
import { CARD_STYLE, cardStyle, setCardStyle } from "../lib/shell-card.ts";
|
|
38
|
+
import { isolatedConfigEnv, keymapsConfigHome, removeIsolatedConfigHomes } from "./isolated-config-home.ts";
|
|
39
|
+
|
|
40
|
+
const gentleAgents: typeof installGentleAgents = (pi, env, overrides) => installGentleAgents(pi, isolatedConfigEnv(env), overrides);
|
|
41
|
+
after(removeIsolatedConfigHomes);
|
|
38
42
|
// The card style defaults to float; these assertions pin the outlined (neon)
|
|
39
43
|
// panels unless a test switches the style itself.
|
|
40
44
|
const initialCardStyle = cardStyle();
|
|
@@ -50,8 +54,8 @@ interface Registered {
|
|
|
50
54
|
renderShell?: string;
|
|
51
55
|
name: string;
|
|
52
56
|
execute(id: string, params: unknown, signal: AbortSignal | undefined, onUpdate: undefined, ctx: ExtensionContext): Promise<{ content: Array<{ text: string }>; details: Record<string, unknown> }>;
|
|
53
|
-
renderCall(args: unknown, theme: unknown): { render(width: number): string[] };
|
|
54
|
-
renderResult(result: { content: Array<{ type: string; text: string }>; details: Record<string, unknown> }, options: { expanded: boolean }, theme: unknown): { render(width: number): string[] };
|
|
57
|
+
renderCall(args: unknown, theme: unknown, context?: unknown): { render(width: number): string[] };
|
|
58
|
+
renderResult(result: { content: Array<{ type: string; text: string }>; details: Record<string, unknown> | undefined }, options: { expanded: boolean; isPartial?: boolean }, theme: unknown, context?: unknown): { render(width: number): string[] };
|
|
55
59
|
}
|
|
56
60
|
|
|
57
61
|
const plainTheme = { fg: (_color: string, text: string) => text };
|
|
@@ -130,7 +134,7 @@ function fakePi(initialProvider: string = "claude-bridge") {
|
|
|
130
134
|
const handlers = new Map<string, Handler[]>();
|
|
131
135
|
const tools = new Map<string, Registered>();
|
|
132
136
|
const shortcuts = new Map<string, { description: string; handler(ctx: ExtensionContext): Promise<void> }>();
|
|
133
|
-
const commands = new Map<string, { handler(args: string, ctx: ExtensionContext): Promise<void> }>();
|
|
137
|
+
const commands = new Map<string, { description?: string; handler(args: string, ctx: ExtensionContext): Promise<void> }>();
|
|
134
138
|
const sent: Array<{ message: Record<string, unknown>; options: Record<string, unknown> }> = [];
|
|
135
139
|
// `delivery` records custom messages and user wakes in dispatch order.
|
|
136
140
|
const userMessages: Array<{ content: unknown; options: Record<string, unknown> | undefined }> = [];
|
|
@@ -164,7 +168,7 @@ function fakePi(initialProvider: string = "claude-bridge") {
|
|
|
164
168
|
on: (event: string, handler: Handler) => handlers.set(event, [...(handlers.get(event) ?? []), handler]),
|
|
165
169
|
registerTool: (tool: Registered) => tools.set(tool.name, tool),
|
|
166
170
|
registerShortcut: (key: string, registration: { description: string; handler(ctx: ExtensionContext): Promise<void> }) => shortcuts.set(key, registration),
|
|
167
|
-
registerCommand: (name: string, registration: { handler(args: string, ctx: ExtensionContext): Promise<void> }) => commands.set(name, registration),
|
|
171
|
+
registerCommand: (name: string, registration: { description?: string; handler(args: string, ctx: ExtensionContext): Promise<void> }) => commands.set(name, registration),
|
|
168
172
|
} as unknown as ExtensionAPI;
|
|
169
173
|
let activeSession: ExtensionContext | undefined;
|
|
170
174
|
const teardown = async () => {
|
|
@@ -207,7 +211,7 @@ function fakeContext(tui: { requestRender(): void } = fakeTui, confirmResult: (t
|
|
|
207
211
|
cwd,
|
|
208
212
|
hasUI: true,
|
|
209
213
|
mode: "tui",
|
|
210
|
-
sessionManager: { getSessionId: () => "s1", getCwd: () => cwd, getEntries: () => [], getBranch: () => [] },
|
|
214
|
+
sessionManager: { getSessionId: () => "s1", getCwd: () => cwd, getEntries: () => [], getBranch: () => [], getSessionFile: () => undefined },
|
|
211
215
|
ui: {
|
|
212
216
|
notify: (message: string) => dialogs.push(`notify:${message}`),
|
|
213
217
|
custom: (factory: (tui: unknown, theme: unknown, keybindings: unknown, done: (value: unknown) => void) => Overlay, options: unknown) =>
|
|
@@ -244,7 +248,7 @@ function fakeContext(tui: { requestRender(): void } = fakeTui, confirmResult: (t
|
|
|
244
248
|
return factory ? factory(tui, plainTheme).render(72).map(stripAnsi) : undefined;
|
|
245
249
|
};
|
|
246
250
|
const widgetComponent = () => widgets.get("gentle-agents")?.(tui, plainTheme) as Component | undefined;
|
|
247
|
-
return { ctx, widget, widgetComponent, dialogs, overlays, customCompletions, customOptions };
|
|
251
|
+
return { ctx, widget, widgetComponent, widgets, dialogs, overlays, customCompletions, customOptions };
|
|
248
252
|
}
|
|
249
253
|
|
|
250
254
|
for (const scenario of ["background", "task", "append-failure", "overflow", "bytes", "replacement", "task-replacement", "unsafe-id", "no-transport"] as const) {
|
|
@@ -1200,6 +1204,65 @@ test("child parent-message tooling admits notifications and the active parent pr
|
|
|
1200
1204
|
assert.deepEqual(runtime.children[0].sent, [{ id: "n1", kind: "ack", accepted: true }, { id: "n2", kind: "ack", accepted: false, error: "task parent is not the active host session" }]);
|
|
1201
1205
|
await parent.fire("session_shutdown", ctx);
|
|
1202
1206
|
});
|
|
1207
|
+
|
|
1208
|
+
// #2266: a child with the forwarded job capability and owned IPC registers the
|
|
1209
|
+
// background job tools for its own session; the monitor stays parent-only.
|
|
1210
|
+
function childJobsChild(env: NodeJS.ProcessEnv, overrides: Partial<AgentsDeps> = {}) {
|
|
1211
|
+
const child = fakePi();
|
|
1212
|
+
const listeners = new Map<string, Array<(value: Record<string, unknown>) => void>>();
|
|
1213
|
+
const frames: Array<Record<string, unknown>> = [];
|
|
1214
|
+
gentleAgents(child.pi, { GENTLE_PI_AGENTS_CHILD: "1", GENTLE_PI_AGENTS_OWNED_IPC: "fixture", ...env }, {
|
|
1215
|
+
childIpc: {
|
|
1216
|
+
send: (frame: Record<string, unknown>) => { frames.push(frame); return true; },
|
|
1217
|
+
on: (event: string, listener: (value: Record<string, unknown>) => void) => listeners.set(event, [...(listeners.get(event) ?? []), listener]),
|
|
1218
|
+
},
|
|
1219
|
+
...overrides,
|
|
1220
|
+
});
|
|
1221
|
+
return { child, frames, listeners };
|
|
1222
|
+
}
|
|
1223
|
+
|
|
1224
|
+
test("a child with the forwarded job capability registers bash_background/job_list/job_stop privately, never the monitor", () => {
|
|
1225
|
+
const jobs = fakeJobShell();
|
|
1226
|
+
const { child } = childJobsChild({ GENTLE_PI_AGENTS_CHILD_JOBS: "1" }, { jobShell: jobs.shell, jobOutputDir: () => jobs.dir, now: () => 1_000 });
|
|
1227
|
+
try {
|
|
1228
|
+
assert.deepEqual([...child.tools.keys()].sort(), ["bash_background", "job_list", "job_stop", "subagent_parent_message"]);
|
|
1229
|
+
assert.equal(child.tools.has("monitor"), false, "the monitor stays parent-only");
|
|
1230
|
+
} finally { jobs.cleanup(); }
|
|
1231
|
+
});
|
|
1232
|
+
|
|
1233
|
+
test("a child without the forwarded job capability keeps only parent messaging", () => {
|
|
1234
|
+
const child = fakePi();
|
|
1235
|
+
gentleAgents(child.pi, { GENTLE_PI_AGENTS_CHILD: "1", GENTLE_PI_AGENTS_OWNED_IPC: "fixture" }, {
|
|
1236
|
+
childIpc: { send: () => true, on: () => undefined },
|
|
1237
|
+
});
|
|
1238
|
+
assert.deepEqual([...child.tools.keys()], ["subagent_parent_message"]);
|
|
1239
|
+
});
|
|
1240
|
+
|
|
1241
|
+
test("a child without owned IPC never registers background job tools even with the forwarded capability", () => {
|
|
1242
|
+
const child = fakePi();
|
|
1243
|
+
gentleAgents(child.pi, { GENTLE_PI_AGENTS_CHILD: "1", GENTLE_PI_AGENTS_CHILD_JOBS: "1" });
|
|
1244
|
+
assert.deepEqual([...child.tools.keys()], []);
|
|
1245
|
+
});
|
|
1246
|
+
|
|
1247
|
+
test("a child reports its background job state to the parent and delivers the exit notice to its own session", async () => {
|
|
1248
|
+
const jobs = fakeJobShell();
|
|
1249
|
+
const { child, frames } = childJobsChild({ GENTLE_PI_AGENTS_CHILD_JOBS: "1" }, { jobShell: jobs.shell, jobOutputDir: () => jobs.dir, now: () => 1_000 });
|
|
1250
|
+
const { ctx } = fakeContext();
|
|
1251
|
+
try {
|
|
1252
|
+
await child.tools.get("bash_background")!.execute("b1", { command: "gh run watch 1 --exit-status", label: "CI" }, undefined, undefined, ctx);
|
|
1253
|
+
assert.deepEqual(frames.at(-1), { id: "j1", kind: "job", message: JSON.stringify({ running: 1, pending: true }) });
|
|
1254
|
+
await child.fire("agent_settled", ctx);
|
|
1255
|
+
assert.deepEqual(frames.at(-1), { id: "j2", kind: "job", message: JSON.stringify({ running: 1, pending: true }) }, "settlement reports the still-running job");
|
|
1256
|
+
jobs.runs[0]!.exit(0);
|
|
1257
|
+
await eventually(() => child.sent.some((entry) => entry.message.customType === "gentle-jobs.notice"), "the child delivers its own job exit notice");
|
|
1258
|
+
assert.deepEqual(frames.at(-1), { id: "j3", kind: "job", message: JSON.stringify({ running: 0, pending: false }) }, "the settlement report clears the running count");
|
|
1259
|
+
const notice = child.sent.find((entry) => entry.message.customType === "gentle-jobs.notice")!;
|
|
1260
|
+
assert.deepEqual(notice.options, { deliverAs: "steer", triggerTurn: true });
|
|
1261
|
+
assert.equal(notice.message.display, true);
|
|
1262
|
+
assert.match(String(notice.message.content), /Background job job-1/);
|
|
1263
|
+
} finally { jobs.cleanup(); }
|
|
1264
|
+
});
|
|
1265
|
+
|
|
1203
1266
|
for (const boundary of ["allowed", "env", "session", "replacement", "bus-throws", "no-spawn", "long-running"] as const) {
|
|
1204
1267
|
test(`local child composition through real extensions and RPC runner: ${boundary}`, async (t) => {
|
|
1205
1268
|
const discarded: number[] = [];
|
|
@@ -3376,6 +3439,26 @@ test("a stale or unreadable pin degrades to the global routing instead of failin
|
|
|
3376
3439
|
// gentle-shell#1558 (barbatdev review): the two registered launch-seam gaps.
|
|
3377
3440
|
// The pure helpers were covered, but the real subagent_run seam had no
|
|
3378
3441
|
// committed test for the session layer.
|
|
3442
|
+
// gentle-shell#1709: a context without a session manager must fail the launch
|
|
3443
|
+
// with the fail-closed authority message, not a TypeError from an unguarded
|
|
3444
|
+
// sessionManager read.
|
|
3445
|
+
test("a launch without a session manager fails closed with the authority message", async t => {
|
|
3446
|
+
const base = pinFixture("no-session-manager");
|
|
3447
|
+
base.writeStore({ pinned: { explore: { model: "openai/alpha" } } });
|
|
3448
|
+
base.writePin("pinned");
|
|
3449
|
+
const harness = deps();
|
|
3450
|
+
harness.deps.resolveWorktree = () => ({ root: base.root, commonDir: base.commonDir });
|
|
3451
|
+
harness.deps.env = { PATH: "/bin", GENTLE_PI_CONFIG_HOME: base.configHome };
|
|
3452
|
+
const { pi, tools, fire } = fakePi();
|
|
3453
|
+
gentleAgents(pi, {}, harness.deps);
|
|
3454
|
+
const { ctx } = fakeContext();
|
|
3455
|
+
const managerless = { ...ctx, sessionManager: undefined } as unknown as typeof ctx;
|
|
3456
|
+
await assert.rejects(
|
|
3457
|
+
tools.get("subagent_run")!.execute("no-manager", { agent: "explore", task: "Map", mode: "background" }, undefined, undefined, managerless),
|
|
3458
|
+
(error: unknown) => error instanceof Error && error.message.includes("Session profile authority unavailable"),
|
|
3459
|
+
);
|
|
3460
|
+
});
|
|
3461
|
+
|
|
3379
3462
|
test("a session binding outranks the repository pin at the launch seam", async t => {
|
|
3380
3463
|
t.after(() => resetSessionProfileBindingsForTesting());
|
|
3381
3464
|
const base = pinFixture("session-over-pin");
|
|
@@ -3698,6 +3781,20 @@ test("the agents task card shows the winning layer next to the model, and render
|
|
|
3698
3781
|
assert.equal(taskHeader(record, 61_000), "explore · running · nan/glm5.3 · 1s", "absent modelSource renders exactly as today");
|
|
3699
3782
|
});
|
|
3700
3783
|
|
|
3784
|
+
test("saved keymaps replace the agents shortcuts, and the environment still wins", () => {
|
|
3785
|
+
const home = keymapsConfigHome({ "agents.view": "alt+v", "agents.stop": null, "agents.collapse": "alt+c" });
|
|
3786
|
+
const { pi, shortcuts } = fakePi();
|
|
3787
|
+
gentleAgents(pi, { GENTLE_PI_CONFIG_HOME: home }, deps().deps);
|
|
3788
|
+
assert.ok(shortcuts.has("alt+v") && shortcuts.has("alt+c"));
|
|
3789
|
+
for (const key of ["alt+a", "alt+s", "ctrl+shift+a"]) assert.equal(shortcuts.has(key), false, key);
|
|
3790
|
+
const envWins = fakePi();
|
|
3791
|
+
gentleAgents(envWins.pi, { GENTLE_PI_CONFIG_HOME: home, GENTLE_PI_AGENTS_VIEW_KEY: "alt+w" }, deps().deps);
|
|
3792
|
+
assert.ok(envWins.shortcuts.has("alt+w"));
|
|
3793
|
+
assert.equal(envWins.shortcuts.has("alt+v"), false);
|
|
3794
|
+
assert.equal(agentsViewKey({}, { "agents.view": "alt+v" }), "alt+v");
|
|
3795
|
+
assert.equal(agentsStopKey({}, { "agents.stop": null }), undefined);
|
|
3796
|
+
});
|
|
3797
|
+
|
|
3701
3798
|
test("agentsEnabled and agentsCollapseKey read their flags and stay off inside a child", () => {
|
|
3702
3799
|
assert.equal(agentsEnabled({}), true);
|
|
3703
3800
|
assert.equal(agentsEnabled({ GENTLE_PI_AGENTS: "off" }), false);
|
|
@@ -3787,7 +3884,9 @@ test("subagent_list_agents and subagent_run in task mode launch a child with the
|
|
|
3787
3884
|
const result = await running;
|
|
3788
3885
|
const runId = (result.details.gentleAgents as { taskId: string }).taskId;
|
|
3789
3886
|
assert.equal(result.content[0].text, `Subagent explore (task ${runId}, "map lib modules") finished.\n\nlib has three agent files.`, "the model sees the real task id and label, not only details");
|
|
3790
|
-
|
|
3887
|
+
const collapsedRun = tools.get("subagent_run")!.renderResult(result as Parameters<Registered["renderResult"]>[0], { expanded: false }, plainTheme).render(80).map((line) => line.trimEnd());
|
|
3888
|
+
assert.match(collapsedRun.join("\n"), /lib has three agent files\./, "the collapsed card still leads with the answer");
|
|
3889
|
+
assert.match(collapsedRun.join("\n"), /╰/, "the collapsed result closes the card the call opened");
|
|
3791
3890
|
assert.equal((result.details.gentleAgents as { status: string }).status, "completed");
|
|
3792
3891
|
assert.match(widget()![1], /✓ explore map lib modules/);
|
|
3793
3892
|
const orphan = tools.get("subagent_run")!.execute("c9", { agent: "explore", task: "Orphan", mode: "background" }, undefined, undefined, ctx);
|
|
@@ -3796,7 +3895,7 @@ test("subagent_list_agents and subagent_run in task mode launch a child with the
|
|
|
3796
3895
|
await fire("session_shutdown", ctx);
|
|
3797
3896
|
await tick();
|
|
3798
3897
|
assert.deepEqual(harness.children[1].killed, ["SIGTERM"], "closing pi stops the running children");
|
|
3799
|
-
assert.match(tools.get("subagent_run")!.renderCall({ agent: "explore" }, plainTheme).render(60).join(""),
|
|
3898
|
+
assert.match(stripAnsi(tools.get("subagent_run")!.renderCall({ agent: "explore" }, plainTheme).render(60).join("")), /→ Delegating · explore/);
|
|
3800
3899
|
});
|
|
3801
3900
|
|
|
3802
3901
|
test("running subagent_result polls hide only their tool chrome, not the model result or final completion", async () => {
|
|
@@ -3815,15 +3914,93 @@ test("running subagent_result polls hide only their tool chrome, not the model r
|
|
|
3815
3914
|
assert.deepEqual(resultTool.renderCall({ task_id: id }, plainTheme).render(80), [], "poll title is hidden");
|
|
3816
3915
|
assert.deepEqual(resultTool.renderResult(poll as Parameters<Registered["renderResult"]>[0], { expanded }, plainTheme).render(80), [], "poll body is hidden");
|
|
3817
3916
|
}
|
|
3818
|
-
assert.match(tools.get("subagent_status")!.renderCall({ task_id: id }, plainTheme).render(80).join(""), /
|
|
3917
|
+
assert.match(tools.get("subagent_status")!.renderCall({ task_id: id }, plainTheme).render(80).join(""), /Agent status/, "other tools retain their rendering");
|
|
3819
3918
|
harness.children[0].emit({ type: "agent_end", messages: [{ role: "assistant", content: [{ type: "text", text: "All done." }] }] });
|
|
3820
3919
|
harness.children[0].emit({ type: "agent_settled" });
|
|
3821
3920
|
await tick();
|
|
3822
3921
|
const finished = await resultTool.execute("finished", { task_id: id }, undefined, undefined, ctx);
|
|
3823
3922
|
assert.equal(finished.content[0].text, "All done.");
|
|
3824
|
-
assert.match(resultTool.renderResult(finished as Parameters<Registered["renderResult"]>[0], { expanded: true }, plainTheme).render(80).join("\n"), /
|
|
3923
|
+
assert.match(resultTool.renderResult(finished as Parameters<Registered["renderResult"]>[0], { expanded: true }, plainTheme).render(80).join("\n"), /Agent answer.*All done\./s, "completed result remains visible");
|
|
3825
3924
|
assert.equal(sent.length, 1);
|
|
3826
|
-
assert.match(renderers.get("gentle-agents.result")!(sent[0].message, { expanded: true }, plainTheme).render(80).join("\n"), /Agent
|
|
3925
|
+
assert.match(renderers.get("gentle-agents.result")!(sent[0].message, { expanded: true }, plainTheme).render(80).join("\n"), /Agent answer.*All done\./s, "background completion card remains visible");
|
|
3926
|
+
});
|
|
3927
|
+
|
|
3928
|
+
// Agent tool cards: the status result continues the call's card with the task
|
|
3929
|
+
// state, its counts, label and last step; results without task details keep
|
|
3930
|
+
// the plain text preview.
|
|
3931
|
+
test("subagent_status continues its card with the task state, counts, label and last step", async () => {
|
|
3932
|
+
const { pi, tools, fire } = fakePi();
|
|
3933
|
+
const harness = deps();
|
|
3934
|
+
gentleAgents(pi, {}, harness.deps);
|
|
3935
|
+
const { ctx } = fakeContext();
|
|
3936
|
+
await fire("session_start", ctx);
|
|
3937
|
+
const started = await tools.get("subagent_run")!.execute("start", { agent: "explore", task: "Long job", label: "map lib modules", mode: "background" }, undefined, undefined, ctx);
|
|
3938
|
+
const id = (started.details.gentleAgents as { taskId: string }).taskId;
|
|
3939
|
+
await tick();
|
|
3940
|
+
const statusTool = tools.get("subagent_status")!;
|
|
3941
|
+
assert.match(stripAnsi(statusTool.renderCall({ task_id: id }, plainTheme).render(80).join("\n")), new RegExp(`◎ Agent status · explore · task ${id}`), "the call names the action and resolves the agent from the store");
|
|
3942
|
+
const result = await statusTool.execute("status", { task_id: id }, undefined, undefined, ctx);
|
|
3943
|
+
assert.match(result.content[0].text, new RegExp(`^${id} · explore · `), "the model-facing text is the unchanged describeTask line");
|
|
3944
|
+
const collapsed = stripAnsi(statusTool.renderResult(result as Parameters<Registered["renderResult"]>[0], { expanded: false }, plainTheme).render(80).join("\n"));
|
|
3945
|
+
assert.match(collapsed, /(RUNNING|QUEUED) · background · \d+ turns · \d+ tool calls/, "the state leads the body");
|
|
3946
|
+
assert.match(collapsed, /map lib modules/, "the task label follows the state");
|
|
3947
|
+
assert.match(collapsed, /last: /, "the last step stays visible collapsed");
|
|
3948
|
+
assert.doesNotMatch(collapsed, /cwd /, "the workspace waits for expansion");
|
|
3949
|
+
const narrow = statusTool.renderResult(result as Parameters<Registered["renderResult"]>[0], { expanded: false }, plainTheme).render(40).map(stripAnsi);
|
|
3950
|
+
assert.match(narrow.join("\n"), /last: /, "a narrow collapsed card still shows the last step");
|
|
3951
|
+
for (const row of narrow) assert.ok(visibleWidth(row) <= 40, `narrow row fits: ${JSON.stringify(row)}`);
|
|
3952
|
+
assert.match(stripAnsi(statusTool.renderResult(result as Parameters<Registered["renderResult"]>[0], { expanded: true }, plainTheme).render(80).join("\n")), /cwd /, "expanded shows the workspace");
|
|
3953
|
+
const fallback = stripAnsi(statusTool.renderResult({ content: [{ type: "text", text: "Error: no task nope" }], details: { error: "unknown task" } } as Parameters<Registered["renderResult"]>[0], { expanded: false }, plainTheme).render(80).join("\n"));
|
|
3954
|
+
assert.match(fallback, /Error: no task nope/, "a result without task details previews its text");
|
|
3955
|
+
assert.doesNotMatch(fallback, /RUNNING|QUEUED|COMPLETED/, "no invented state");
|
|
3956
|
+
await fire("session_shutdown", ctx);
|
|
3957
|
+
});
|
|
3958
|
+
|
|
3959
|
+
test("agent card subtitles stay on one row when a task id carries line breaks", () => {
|
|
3960
|
+
const { pi, tools } = fakePi();
|
|
3961
|
+
gentleAgents(pi, {}, deps().deps);
|
|
3962
|
+
const rows = tools.get("subagent_status")!.renderCall({ task_id: "t1\nINJECTED\r\nrow" }, plainTheme).render(80);
|
|
3963
|
+
for (const row of rows) assert.doesNotMatch(row, /[\n\r]/, `row stays single-line: ${JSON.stringify(row)}`);
|
|
3964
|
+
assert.match(stripAnsi(rows.join("")), /task t1 INJECTED/, "the id is kept, with the break folded into a space");
|
|
3965
|
+
const run = tools.get("subagent_run")!.renderCall({ agent: "explore\nINJECTED" }, plainTheme).render(80);
|
|
3966
|
+
for (const row of run) assert.doesNotMatch(row, /[\n\r]/, `run row stays single-line: ${JSON.stringify(row)}`);
|
|
3967
|
+
});
|
|
3968
|
+
|
|
3969
|
+
test("the stale agent answer heading stays on one row when its agent or task id carries line breaks", () => {
|
|
3970
|
+
const { pi, entryRenderers } = fakePi();
|
|
3971
|
+
gentleAgents(pi, {}, deps().deps);
|
|
3972
|
+
const entry = { type: "custom", customType: "gentle-agents.stale-result", data: { taskId: "t9\nINJECTED", agent: "explore\r\nrow", label: "map lib", status: "completed", ageSeconds: 120 } };
|
|
3973
|
+
const rows = entryRenderers.get("gentle-agents.stale-result")!(entry, { expanded: false }, plainTheme).render(80);
|
|
3974
|
+
for (const row of rows) assert.doesNotMatch(row, /[\n\r]/, `stale row stays single-line: ${JSON.stringify(row)}`);
|
|
3975
|
+
assert.match(stripAnsi(rows[0]!), /↩ Stale agent answer · explore row · task t9 INJECTED/, "the heading keeps both values with the breaks folded");
|
|
3976
|
+
});
|
|
3977
|
+
|
|
3978
|
+
test("an agent tool result takes the error tone from the host error flag", () => {
|
|
3979
|
+
const { pi, tools } = fakePi();
|
|
3980
|
+
gentleAgents(pi, {}, deps().deps);
|
|
3981
|
+
const taggedTheme = { fg: (color: string, text: string) => `<${color}>${text}</${color}>` };
|
|
3982
|
+
const result = { content: [{ type: "text", text: "Subagent dispatch requires a named agent." }], details: {} };
|
|
3983
|
+
const render = (isError: boolean) => (tools.get("subagent_run")!.renderResult as (r: unknown, o: unknown, t: unknown, c: unknown) => { render(width: number): string[] })(result, { expanded: false }, taggedTheme, { isError, state: {} }).render(80).join("\n");
|
|
3984
|
+
assert.match(render(true), /<error>/, "a host error paints the result frame in the error role");
|
|
3985
|
+
assert.doesNotMatch(render(false), /<error>/, "an ordinary result keeps the agent chrome");
|
|
3986
|
+
});
|
|
3987
|
+
|
|
3988
|
+
test("the iris float tint stays on agent info cards and leaves success cards on the theme background", async () => {
|
|
3989
|
+
const { pi, tools, renderers } = fakePi();
|
|
3990
|
+
gentleAgents(pi, {}, deps().deps);
|
|
3991
|
+
const irisTint = "\x1b[48;2;26;21;38m";
|
|
3992
|
+
const themeBg = "\x1b[48;5;236m";
|
|
3993
|
+
const bgTheme = { fg: (_color: string, text: string) => text, bg: (_role: string, text: string) => `${themeBg}${text}\x1b[49m` };
|
|
3994
|
+
setCardStyle(CARD_STYLE.FLOAT);
|
|
3995
|
+
try {
|
|
3996
|
+
const running = tools.get("subagent_status")!.renderCall({ task_id: "t1" }, bgTheme).render(80).join("\n");
|
|
3997
|
+
assert.ok(running.includes(irisTint), "an info agent card wears the iris tint");
|
|
3998
|
+
const answer = renderers.get("gentle-agents.result")!({ customType: "gentle-agents.result", content: "Subagent explore (task t1, \"x\") finished.\n\nAll done.", details: { gentleAgents: { taskId: "t1", agent: "explore", status: "completed" } } }, { expanded: false }, bgTheme).render(80).join("\n");
|
|
3999
|
+
assert.ok(!answer.includes(irisTint), "a completed answer card keeps the theme's success background");
|
|
4000
|
+
assert.ok(answer.includes(themeBg), "the theme background paints the success card");
|
|
4001
|
+
} finally {
|
|
4002
|
+
setCardStyle(CARD_STYLE.NEON);
|
|
4003
|
+
}
|
|
3827
4004
|
});
|
|
3828
4005
|
|
|
3829
4006
|
test("the Agents card moves to the fullscreen rail like Todos and its header toggles collapse on left click", async () => {
|
|
@@ -3834,7 +4011,7 @@ test("the Agents card moves to the fullscreen rail like Todos and its header tog
|
|
|
3834
4011
|
// (a host with no .terminal is already a passthrough); this is the host
|
|
3835
4012
|
// shape the fullscreen layout actually uses.
|
|
3836
4013
|
const terminalTui = { requestRender() {}, terminal: { columns: 160, rows: 40 } };
|
|
3837
|
-
const { ctx, widgetComponent } = fakeContext(terminalTui);
|
|
4014
|
+
const { ctx, widgetComponent, overlays } = fakeContext(terminalTui);
|
|
3838
4015
|
await fire("session_start", ctx);
|
|
3839
4016
|
await tools.get("subagent_run")!.execute("c1", { agent: "explore", task: "Map lib/", label: "map lib modules", mode: "background" }, undefined, undefined, ctx);
|
|
3840
4017
|
await tools.get("subagent_run")!.execute("c2", { agent: "explore", task: "Map tests/", label: "map test suites", mode: "background" }, undefined, undefined, ctx);
|
|
@@ -3851,6 +4028,10 @@ test("the Agents card moves to the fullscreen rail like Todos and its header tog
|
|
|
3851
4028
|
assert.ok(rail, "Agents claims the rail slot, so a wide fullscreen terminal shows it at the right");
|
|
3852
4029
|
assert.equal(rail.render(46).filter((line) => /explore/.test(stripAnsi(line))).length, 2, "the rail lists every task");
|
|
3853
4030
|
assert.ok(rail.digest?.(), "the rail declares a digest so its clock and counters repaint");
|
|
4031
|
+
assert.equal((rail as { surface?: string }).surface, "panel", "the rail draws Agents as a panel section");
|
|
4032
|
+
const railRows = rail.render(46).map((line) => stripAnsi(line).trimEnd());
|
|
4033
|
+
assert.match(railRows[0]!, /^▾ AGENTS +2 running$/, "the panel header is row 0 with the live count");
|
|
4034
|
+
assert.match(railRows[1]!, /^ {2}◐ map lib modules +explore +\S/, "the task leads each row, the agent kind follows");
|
|
3854
4035
|
|
|
3855
4036
|
// While the fullscreen sidebar owns the host, the bottom copy steps aside.
|
|
3856
4037
|
state.active = true;
|
|
@@ -3862,13 +4043,25 @@ test("the Agents card moves to the fullscreen rail like Todos and its header tog
|
|
|
3862
4043
|
type, button, x: 1, y, screenX: 1, screenY: y, width: 72, height: bottom.length, shift: false, alt: false, ctrl: false,
|
|
3863
4044
|
});
|
|
3864
4045
|
assert.equal(component.handleMouse?.(event("click", "right")), undefined);
|
|
3865
|
-
assert.equal(component.handleMouse?.(event("click", "
|
|
4046
|
+
assert.equal(component.handleMouse?.(event("click", "right", 1)), undefined, "a right click on an agent row does nothing");
|
|
4047
|
+
assert.equal(component.handleMouse?.(event("click", "left", 1))?.handled, true, "a left click on an agent row is handled");
|
|
4048
|
+
await tick();
|
|
4049
|
+
assert.equal(overlays.length, 1, "a left click on an agent row opens /gentle:agents");
|
|
3866
4050
|
assert.match(stripAnsi(component.render(72)[0]!), /Agents ▾ Collapse/, "only a left click on the header toggles");
|
|
3867
4051
|
assert.equal(component.handleMouse?.(event("click", "left"))?.handled, true);
|
|
3868
4052
|
const collapsed = component.render(72).map(stripAnsi);
|
|
3869
4053
|
assert.match(collapsed[0]!, /Agents ▸ Expand/);
|
|
3870
4054
|
assert.doesNotMatch(collapsed.join("\n"), /map test suites/, "the collapsed card keeps one row");
|
|
3871
4055
|
assert.equal(rail.render(46).filter((line) => /explore/.test(stripAnsi(line))).length, 1, "both surfaces share the collapsed state");
|
|
4056
|
+
assert.match(stripAnsi(rail.render(46)[0]!), /^▸ AGENTS/);
|
|
4057
|
+
const railClick = { type: "click" as const, button: "left" as const, x: 1, y: 0, screenX: 1, screenY: 0, width: 46, height: 2, shift: false, alt: false, ctrl: false };
|
|
4058
|
+
assert.equal(rail.handleMouse?.(railClick)?.handled, true, "the rail header row 0 is the collapse control");
|
|
4059
|
+
assert.match(stripAnsi(rail.render(46)[0]!), /^▾ AGENTS/);
|
|
4060
|
+
assert.equal(rail.handleMouse?.({ ...railClick, y: 1, screenY: 1 })?.handled, true, "a left click on a rail agent row is handled");
|
|
4061
|
+
await tick();
|
|
4062
|
+
assert.equal(overlays.length, 2, "a left click on a rail agent row opens /gentle:agents, never the panel");
|
|
4063
|
+
assert.match(stripAnsi(rail.render(46)[0]!), /^▾ AGENTS/, "an agent row click never toggles the section");
|
|
4064
|
+
assert.equal(typeof (rail as { open?: unknown }).open, "function", "the rail part exposes the agents view for the mobile work row");
|
|
3872
4065
|
});
|
|
3873
4066
|
|
|
3874
4067
|
test("the Agents rail digest stays stable while no task is running, so an idle card never rebuilds the rail every second", async () => {
|
|
@@ -3915,8 +4108,9 @@ test("background runs return at once; status, result, send_message, cancel, and
|
|
|
3915
4108
|
assert.deepEqual(sent[0].options, { triggerTurn: false });
|
|
3916
4109
|
assert.match(String(sent[0].message.content), new RegExp(`^Subagent explore \\(task ${id}, "Long job"\\) finished\\.\n\nAll done\\.$`));
|
|
3917
4110
|
const card = renderers.get("gentle-agents.result")!(sent[0].message, { expanded: true }, plainTheme).render(70).map(stripAnsi);
|
|
3918
|
-
assert.match(card[0], /^╭─
|
|
3919
|
-
assert.match(card[1], /
|
|
4111
|
+
assert.match(card[0], /^╭─ ↩ Agent answer · explore ─+ collapse ╮$/);
|
|
4112
|
+
assert.match(card[1], /COMPLETED · background/, "the state pill leads the expanded answer card");
|
|
4113
|
+
assert.match(card[2], /Subagent explore/);
|
|
3920
4114
|
assert.match(card[card.length - 2], /All done\./);
|
|
3921
4115
|
const resumed = tools.get("subagent_continue")!.execute("c8", { task_id: id, prompt: "Now summarize", mode: "task" }, undefined, undefined, ctx);
|
|
3922
4116
|
await tick();
|
|
@@ -3987,7 +4181,7 @@ test("the Agent result card previews the answer or error when collapsed and keep
|
|
|
3987
4181
|
|
|
3988
4182
|
const done = render(message(base), { expanded: false }, plainTheme).render(80).map(stripAnsi);
|
|
3989
4183
|
assert.ok(done.length <= 5, "the collapsed card stays bounded");
|
|
3990
|
-
assert.match(done[0]!, /^╭─
|
|
4184
|
+
assert.match(done[0]!, /^╭─ ↩ Agent answer · explore ─+ expand ╮$/);
|
|
3991
4185
|
assert.match(done[1]!, /^│ All done\. +│$/, "the answer leads the collapsed preview");
|
|
3992
4186
|
assert.doesNotMatch(done.join("\n"), /Subagent explore \(task/, "the bookkeeping header stays out of the collapsed preview");
|
|
3993
4187
|
assert.match(render(message(base), { expanded: false }, taggedTheme).render(80)[0]!, /^<success>╭/);
|
|
@@ -4018,6 +4212,87 @@ test("the Agent result card previews the answer or error when collapsed and keep
|
|
|
4018
4212
|
}
|
|
4019
4213
|
});
|
|
4020
4214
|
|
|
4215
|
+
test("agent cards name the model and effort beside the agent, so a delegation says what answers", async () => {
|
|
4216
|
+
const h = fakePi();
|
|
4217
|
+
const harness = deps();
|
|
4218
|
+
gentleAgents(h.pi, {}, harness.deps);
|
|
4219
|
+
const { ctx } = fakeContext();
|
|
4220
|
+
mkdirSync(join(cwd, ".pi"), { recursive: true });
|
|
4221
|
+
writeFileSync(join(cwd, ".pi", "subagents.json"), `${JSON.stringify({ model_profiles: { explore: { model: "openai/alpha", effort: "high" } } })}\n`);
|
|
4222
|
+
await h.fire("session_start", ctx);
|
|
4223
|
+
const run = h.tools.get("subagent_run")!;
|
|
4224
|
+
const state = {};
|
|
4225
|
+
const launched = await run.execute("run", { agent: "explore", task: "route", mode: "background" }, undefined, undefined, ctx);
|
|
4226
|
+
await tick();
|
|
4227
|
+
const taskId = (launched.details.gentleAgents as { taskId: string }).taskId;
|
|
4228
|
+
|
|
4229
|
+
// The status tools know the task, so the store already carries the answer.
|
|
4230
|
+
const status = h.tools.get("subagent_status")!;
|
|
4231
|
+
const statusHeading = stripAnsi(status.renderCall({ task_id: taskId }, plainTheme, { expanded: false, state: {} } as never).render(120).join("\n"));
|
|
4232
|
+
assert.match(statusHeading, /◎ Agent status · explore · task \S+ · openai\/alpha · high/, "the launch's model and effort sit beside the agent");
|
|
4233
|
+
|
|
4234
|
+
// A launch has no task id at call time: the result slot hands them over.
|
|
4235
|
+
const launchedRows = run.renderResult(launched as Parameters<Registered["renderResult"]>[0], { expanded: false, isPartial: false }, plainTheme, { isError: false, isPartial: false, state } as never).render(120);
|
|
4236
|
+
assert.ok(launchedRows.length > 0, "the result still renders");
|
|
4237
|
+
const heading = stripAnsi(run.renderCall({ agent: "explore" }, plainTheme, { expanded: false, state } as never).render(120).join("\n"));
|
|
4238
|
+
assert.match(heading, /→ Delegating · explore · openai\/alpha · high/, "the card names what the child runs on once the launch exists");
|
|
4239
|
+
|
|
4240
|
+
// One heading row: a tight row sheds the profile, and the hint outranks
|
|
4241
|
+
// even the agent name at the narrowest widths.
|
|
4242
|
+
const tight = stripAnsi(status.renderCall({ task_id: taskId }, plainTheme, { expanded: false, state: {} } as never).render(70).join("\n"));
|
|
4243
|
+
assert.match(tight, /expand/, "the affordance survives the wider heading");
|
|
4244
|
+
assert.match(tight, /openai\/alpha/, "the model still fits");
|
|
4245
|
+
assert.doesNotMatch(tight, /· high/, "effort is the first chip a tight row gives up");
|
|
4246
|
+
const narrow = stripAnsi(status.renderCall({ task_id: taskId }, plainTheme, { expanded: false, state: {} } as never).render(50).join("\n"));
|
|
4247
|
+
assert.match(narrow, /expand/, "the affordance never goes");
|
|
4248
|
+
assert.doesNotMatch(narrow, /openai\/alpha/, "the model is the next chip to go");
|
|
4249
|
+
assert.match(narrow, /◎ Agent status · explore /, "the agent stays while it still fits");
|
|
4250
|
+
const tiny = stripAnsi(status.renderCall({ task_id: taskId }, plainTheme, { expanded: false, state: {} } as never).render(32).join("\n"));
|
|
4251
|
+
assert.match(tiny, /expand/, "the hint survives even when only the verb fits");
|
|
4252
|
+
assert.doesNotMatch(tiny, /explore/, "the agent name is what gives up its columns");
|
|
4253
|
+
|
|
4254
|
+
// A continuation is a new task: once its result speaks, its profile wins
|
|
4255
|
+
// whole, so the predecessor's model and effort never leak into the heading.
|
|
4256
|
+
writeFileSync(join(cwd, ".pi", "subagents.json"), `${JSON.stringify({ model_profiles: { explore: { model: "openai/beta" } } })}\n`);
|
|
4257
|
+
harness.children[0].emit({ type: "agent_end", messages: [{ role: "assistant", content: [{ type: "text", text: "first done" }] }] });
|
|
4258
|
+
harness.children[0].emit({ type: "agent_settled" });
|
|
4259
|
+
await tick();
|
|
4260
|
+
const resumed = h.tools.get("subagent_continue")!.execute("c8", { task_id: taskId, prompt: "go on", mode: "task" }, undefined, undefined, ctx);
|
|
4261
|
+
await tick();
|
|
4262
|
+
harness.children[1].emit({ type: "agent_end", messages: [{ role: "assistant", content: [{ type: "text", text: "second done" }] }] });
|
|
4263
|
+
harness.children[1].emit({ type: "agent_settled" });
|
|
4264
|
+
const continuation = await resumed;
|
|
4265
|
+
const continueState = {};
|
|
4266
|
+
h.tools.get("subagent_continue")!.renderResult(continuation as Parameters<Registered["renderResult"]>[0], { expanded: false, isPartial: false }, plainTheme, { isError: false, isPartial: false, state: continueState } as never).render(120);
|
|
4267
|
+
const continueHeading = stripAnsi(h.tools.get("subagent_continue")!.renderCall({ task_id: taskId }, plainTheme, { expanded: false, state: continueState } as never).render(120).join("\n"));
|
|
4268
|
+
assert.match(continueHeading, /openai\/beta/, "the continuation names its own model");
|
|
4269
|
+
assert.doesNotMatch(continueHeading, /openai\/alpha|high/, "the predecessor's model and effort never leak into it");
|
|
4270
|
+
|
|
4271
|
+
await h.fire("session_shutdown", ctx, { reason: "quit" });
|
|
4272
|
+
});
|
|
4273
|
+
|
|
4274
|
+
test("a rejected delegation reads as a FAIL card, never as a live one", () => {
|
|
4275
|
+
const { pi, tools } = fakePi();
|
|
4276
|
+
gentleAgents(pi, {}, deps().deps);
|
|
4277
|
+
const tool = tools.get("subagent_run")!;
|
|
4278
|
+
const taggedTheme = { fg: (color: string, text: string) => `<${color}>${text}</${color}>` };
|
|
4279
|
+
// Pi reports a thrown execute() as isError with no details: no task was made
|
|
4280
|
+
// and no facts reached the card, so the renderer has only the row state.
|
|
4281
|
+
const rejected = { content: [{ type: "text", text: "Select an existing worktree in the same Git clone as this session." }], details: undefined };
|
|
4282
|
+
const context = { isError: true, isPartial: false, expanded: false, state: {} };
|
|
4283
|
+
const rows = tool.renderResult(rejected as Parameters<Registered["renderResult"]>[0], { expanded: false, isPartial: false }, taggedTheme, context as never).render(80);
|
|
4284
|
+
const body = stripAnsi(rows.join("\n"));
|
|
4285
|
+
assert.match(body, /FAILED/, "the failure leads the body as the state pill the docs name");
|
|
4286
|
+
assert.match(body, /Select an existing worktree/, "the reason is still shown");
|
|
4287
|
+
assert.doesNotMatch(body, /RUNNING/, "a rejected call never reads as still delegating");
|
|
4288
|
+
// The heading belongs to the call slot, which only shares `state` with the
|
|
4289
|
+
// result, so the failure has to travel there: no `isError` here, or this
|
|
4290
|
+
// would pass on the call's own frozen snapshot instead of the handshake.
|
|
4291
|
+
const call = tool.renderCall({ agent: "explore" }, taggedTheme, { expanded: false, state: context.state } as never).render(80);
|
|
4292
|
+
assert.match(call[0]!, /^<error>╭/, "the rejected card wears the error frame, not the live iris one");
|
|
4293
|
+
assert.match(stripAnsi(call.join("\n").replace(/<\/?[a-z]+>/g, "")), /→ Delegating · explore/, "the heading stays the call's");
|
|
4294
|
+
});
|
|
4295
|
+
|
|
4021
4296
|
test("the Stale agent result card previews its truthful warning when collapsed", () => {
|
|
4022
4297
|
const { pi, entryRenderers } = fakePi();
|
|
4023
4298
|
gentleAgents(pi, {}, deps().deps);
|
|
@@ -4025,7 +4300,7 @@ test("the Stale agent result card previews its truthful warning when collapsed",
|
|
|
4025
4300
|
const entry = { type: "custom", customType: "gentle-agents.stale-result", data: { taskId: "t9", agent: "explore", label: "map lib", status: "completed", ageSeconds: 120 } };
|
|
4026
4301
|
const collapsed = render(entry, { expanded: false }, plainTheme).render(80).map(stripAnsi);
|
|
4027
4302
|
assert.ok(collapsed.length > 3 && collapsed.length <= 5, "a bounded multi-row preview");
|
|
4028
|
-
assert.match(collapsed[0]!, /^╭─
|
|
4303
|
+
assert.match(collapsed[0]!, /^╭─ ↩ Stale agent answer · explore · task t9 ─+ expand ╮$/);
|
|
4029
4304
|
assert.match(collapsed.join("\n"), /Subagent explore \(task t9, "map lib"\) completed about 2m ago/);
|
|
4030
4305
|
assert.doesNotMatch(collapsed.join("\n"), /All done|Last answer/, "no invented answer");
|
|
4031
4306
|
assert.match(render(entry, { expanded: false }, { fg: (color: string, text: string) => `<${color}>${text}</${color}>` }).render(80)[0]!, /^<warning>╭/);
|
|
@@ -4244,6 +4519,124 @@ test("a task that finishes live stays visible as history, in both scopes, and it
|
|
|
4244
4519
|
await opened;
|
|
4245
4520
|
});
|
|
4246
4521
|
|
|
4522
|
+
test("an in-flight task is persisted on launch, and reconciles to interrupted if the parent dies before it finishes (#1741)", async () => {
|
|
4523
|
+
const { pi, tools, fire } = fakePi();
|
|
4524
|
+
const harness = deps();
|
|
4525
|
+
gentleAgents(pi, {}, harness.deps);
|
|
4526
|
+
const { ctx } = fakeContext();
|
|
4527
|
+
await fire("session_start", ctx);
|
|
4528
|
+
const started = await tools.get("subagent_run")!.execute("c1", { agent: "explore", task: "Survive abrupt crash", mode: "background" }, undefined, undefined, ctx);
|
|
4529
|
+
const id = (started.details.gentleAgents as { taskId: string }).taskId;
|
|
4530
|
+
assert.ok(id, "task ID allocated");
|
|
4531
|
+
|
|
4532
|
+
// Wait for the async launch persistence to write the file
|
|
4533
|
+
const tasksDir = join(home, ".pi", "agent", "gentle-agents", "tasks");
|
|
4534
|
+
let stored = await loadStoredTask(tasksDir, id);
|
|
4535
|
+
for (let attempt = 0; attempt < 10 && !stored; attempt += 1) {
|
|
4536
|
+
await new Promise((resolve) => setTimeout(resolve, 25));
|
|
4537
|
+
stored = await loadStoredTask(tasksDir, id);
|
|
4538
|
+
}
|
|
4539
|
+
assert.ok(stored, "the in-flight task is written to disk upon launch");
|
|
4540
|
+
assert.equal(stored.task.id, id);
|
|
4541
|
+
assert.ok(stored.task.status === "queued" || stored.task.status === "running", "task status is in-flight on disk");
|
|
4542
|
+
assert.equal(stored.task.endedAt, null, "task is not ended yet");
|
|
4543
|
+
|
|
4544
|
+
// Simulate abrupt death of parent: no session_shutdown, no runner.cancelAll.
|
|
4545
|
+
// A completely new session in another process starts up with the same disk store.
|
|
4546
|
+
const fresh = fakePi();
|
|
4547
|
+
const freshHarness = deps();
|
|
4548
|
+
gentleAgents(fresh.pi, {}, freshHarness.deps);
|
|
4549
|
+
const freshCtx = fakeContext();
|
|
4550
|
+
await fresh.fire("session_start", freshCtx.ctx);
|
|
4551
|
+
|
|
4552
|
+
// In the new session, subagent_status must NOT fail with "Error: no task <id>"
|
|
4553
|
+
const statusResult = await fresh.tools.get("subagent_status")!.execute("s1", { task_id: id }, undefined, undefined, freshCtx.ctx);
|
|
4554
|
+
assert.doesNotMatch(statusResult.content[0].text, /Error: no task/, "interrupted task must resolve");
|
|
4555
|
+
assert.match(statusResult.content[0].text, /failed/, "status must report terminal failure");
|
|
4556
|
+
assert.match(statusResult.content[0].text, /interrupted/i, "status must explain interruption");
|
|
4557
|
+
|
|
4558
|
+
// The disk record must now be updated to the terminal reconciled state
|
|
4559
|
+
const reconciledOnDisk = await loadStoredTask(tasksDir, id);
|
|
4560
|
+
assert.ok(reconciledOnDisk, "reconciled record on disk");
|
|
4561
|
+
assert.equal(reconciledOnDisk.task.status, "failed");
|
|
4562
|
+
assert.match(reconciledOnDisk.task.error ?? "", /interrupted/i);
|
|
4563
|
+
assert.ok(typeof reconciledOnDisk.task.endedAt === "number", "endedAt is populated");
|
|
4564
|
+
|
|
4565
|
+
// On resume of the original session, subagent_list_tasks must list the interrupted task
|
|
4566
|
+
const resumedPi = fakePi();
|
|
4567
|
+
const resumedHarness = deps();
|
|
4568
|
+
gentleAgents(resumedPi.pi, {}, resumedHarness.deps);
|
|
4569
|
+
const resumedCtx = fakeContext();
|
|
4570
|
+
(resumedCtx.ctx.sessionManager as { getSessionId(): string }).getSessionId = () => ctx.sessionManager.getSessionId();
|
|
4571
|
+
(resumedCtx.ctx.sessionManager as { getEntries(): unknown[] }).getEntries = () => [{ type: "custom" }];
|
|
4572
|
+
await resumedPi.fire("session_start", resumedCtx.ctx, { reason: "resume" });
|
|
4573
|
+
// No delay: list_tasks waits for the resumed session's restoration itself.
|
|
4574
|
+
const listResult = await resumedPi.tools.get("subagent_list_tasks")!.execute("l1", {}, undefined, undefined, resumedCtx.ctx);
|
|
4575
|
+
assert.match(listResult.content[0].text, new RegExp(id), "interrupted task must appear in resumed session task list");
|
|
4576
|
+
assert.match(listResult.content[0].text, /interrupted/i);
|
|
4577
|
+
});
|
|
4578
|
+
|
|
4579
|
+
test("a task that finishes before its launch save settles ends terminal on disk (#1741)", async (t) => {
|
|
4580
|
+
const { pi, tools, fire } = fakePi();
|
|
4581
|
+
const harness = deps();
|
|
4582
|
+
// A large in-flight thread makes the stale launch write slower than the terminal one.
|
|
4583
|
+
const thread = TaskStore.prototype.thread;
|
|
4584
|
+
const slow = applyTaskEvent(emptyThread(), { type: TASK_EVENT.TEXT, text: "x".repeat(32 * 1024 * 1024) });
|
|
4585
|
+
t.mock.method(TaskStore.prototype, "thread", function (this: TaskStore, id: string) {
|
|
4586
|
+
const current = this.get(id);
|
|
4587
|
+
return current && current.status !== TASK_STATUS.COMPLETED ? slow : thread.call(this, id);
|
|
4588
|
+
});
|
|
4589
|
+
gentleAgents(pi, {}, harness.deps);
|
|
4590
|
+
const { ctx } = fakeContext();
|
|
4591
|
+
await fire("session_start", ctx);
|
|
4592
|
+
const started = await tools.get("subagent_run")!.execute("race", { agent: "explore", task: "Finish fast", mode: "background" }, undefined, undefined, ctx);
|
|
4593
|
+
const id = (started.details.gentleAgents as { taskId: string }).taskId;
|
|
4594
|
+
await tick();
|
|
4595
|
+
harness.children[0].emit({ type: "agent_end", messages: [{ role: "assistant", content: [{ type: "text", text: "done" }], stopReason: "stop" }] });
|
|
4596
|
+
harness.children[0].emit({ type: "agent_settled" });
|
|
4597
|
+
const tasksDir = historyDir(home);
|
|
4598
|
+
const pendingWrites = () => { try { return readdirSync(tasksDir).filter((name) => name.startsWith(`${id}.json.`)).length; } catch { return 1; } };
|
|
4599
|
+
let stored = await loadStoredTask(tasksDir, id);
|
|
4600
|
+
for (let attempt = 0; attempt < 120 && (stored?.task.status !== TASK_STATUS.COMPLETED || pendingWrites() > 0); attempt += 1) {
|
|
4601
|
+
await new Promise((resolve) => setTimeout(resolve, 25));
|
|
4602
|
+
stored = await loadStoredTask(tasksDir, id);
|
|
4603
|
+
}
|
|
4604
|
+
// Give any stale launch write that is still in flight time to land.
|
|
4605
|
+
for (let settle = 0; settle < 8; settle += 1) {
|
|
4606
|
+
await new Promise((resolve) => setTimeout(resolve, 50));
|
|
4607
|
+
assert.equal(pendingWrites(), 0);
|
|
4608
|
+
}
|
|
4609
|
+
stored = await loadStoredTask(tasksDir, id);
|
|
4610
|
+
assert.equal(stored?.task.status, TASK_STATUS.COMPLETED, "the terminal record is never overwritten by a launch write");
|
|
4611
|
+
assert.equal(stored?.task.result, "done");
|
|
4612
|
+
});
|
|
4613
|
+
|
|
4614
|
+
test("a resumed session reconciles an interrupted task before publishing restored history (#1741)", async (t) => {
|
|
4615
|
+
const { pi, fire } = fakePi();
|
|
4616
|
+
const harness = deps();
|
|
4617
|
+
const resumeHome = join(root, "reconcile-resume-home");
|
|
4618
|
+
const interrupted: TaskRecord = { id: "interrupted-1", agent: "explore", mode: "background", prompt: "p", label: "p", cwd, parentSessionId: "reconcile-session", status: TASK_STATUS.RUNNING, createdAt: 1, startedAt: 1, endedAt: null, model: "m", thinking: undefined, sessionPath: null, error: null, result: null, lastStep: "working", lastActivityAt: 1, turns: 0, toolCalls: 0, tokens: 0, cost: 0 };
|
|
4619
|
+
await saveTask(historyDir(resumeHome), interrupted, emptyThread());
|
|
4620
|
+
harness.deps.home = resumeHome;
|
|
4621
|
+
let store: TaskStore | undefined;
|
|
4622
|
+
const restore = TaskStore.prototype.restore;
|
|
4623
|
+
t.mock.method(TaskStore.prototype, "restore", function (this: TaskStore, ...args: Parameters<TaskStore["restore"]>) {
|
|
4624
|
+
store = this;
|
|
4625
|
+
return restore.apply(this, args);
|
|
4626
|
+
});
|
|
4627
|
+
gentleAgents(pi, {}, harness.deps);
|
|
4628
|
+
const { ctx } = fakeContext();
|
|
4629
|
+
ctx.sessionManager.getSessionId = () => "reconcile-session";
|
|
4630
|
+
await fire("session_start", ctx, { reason: "resume" });
|
|
4631
|
+
await eventually(() => store?.get("interrupted-1") !== undefined, "restored history published");
|
|
4632
|
+
const restored = store!.get("interrupted-1")!;
|
|
4633
|
+
assert.equal(restored.status, TASK_STATUS.FAILED);
|
|
4634
|
+
assert.match(restored.error ?? "", /interrupted/);
|
|
4635
|
+
assert.equal(typeof restored.endedAt, "number");
|
|
4636
|
+
assert.equal((await loadStoredTask(historyDir(resumeHome), "interrupted-1"))?.task.status, TASK_STATUS.FAILED);
|
|
4637
|
+
await fire("session_shutdown", ctx);
|
|
4638
|
+
});
|
|
4639
|
+
|
|
4247
4640
|
test("the overlay confirms a running task once and reports when it finishes during confirmation", async () => {
|
|
4248
4641
|
const { pi, tools, fire, commands, sent } = fakePi();
|
|
4249
4642
|
const harness = deps();
|
|
@@ -4373,7 +4766,10 @@ test("restored task history cannot enter the live panel or discovery during sync
|
|
|
4373
4766
|
assert.deepEqual(readDiscovery(profile, listPresence(profile).entries[0])?.tasks, []);
|
|
4374
4767
|
const opened = commands.get("gentle:agents")!.handler("", ctx);
|
|
4375
4768
|
for (let attempt = 0; attempt < 40 && overlays.length === 0; attempt += 1) await new Promise((resolve) => setTimeout(resolve, 25));
|
|
4376
|
-
|
|
4769
|
+
// The interrupted record is reconciled on resume, so it shows as finished history, never as stoppable work (#1741).
|
|
4770
|
+
const rendered = stripAnsi(overlays[0]!.render(80).join("\n"));
|
|
4771
|
+
assert.doesNotMatch(rendered, /Stop selected|running/);
|
|
4772
|
+
assert.match(rendered, /failed/);
|
|
4377
4773
|
overlays[0]!.handleInput("s");
|
|
4378
4774
|
overlays[0]!.handleInput("c");
|
|
4379
4775
|
await tick();
|
|
@@ -4520,8 +4916,8 @@ test("the card follows the active session: after /new the earlier session's task
|
|
|
4520
4916
|
await tools.get("subagent_run")!.execute("c1", { agent: "explore", task: "Long job", mode: "background" }, undefined, undefined, ctx);
|
|
4521
4917
|
await tick();
|
|
4522
4918
|
assert.match(widget()![1], /◐ explore Long job/);
|
|
4523
|
-
const sessions = ctx as unknown as { sessionManager: { getSessionId(): string; getCwd(): string; getBranch(): []; getEntries(): [] } };
|
|
4524
|
-
sessions.sessionManager = { getSessionId: () => "s2", getCwd: () => cwd, getBranch: () => [], getEntries: () => [] };
|
|
4919
|
+
const sessions = ctx as unknown as { sessionManager: { getSessionId(): string; getCwd(): string; getBranch(): []; getEntries(): []; getSessionFile(): undefined } };
|
|
4920
|
+
sessions.sessionManager = { getSessionId: () => "s2", getCwd: () => cwd, getBranch: () => [], getEntries: () => [], getSessionFile: () => undefined };
|
|
4525
4921
|
await fire("session_start", ctx, { type: "session_start", reason: "new" });
|
|
4526
4922
|
assert.deepEqual(widget(), [], "the new session starts with an empty card");
|
|
4527
4923
|
assert.match((await tools.get("subagent_list_tasks")!.execute("c2", {}, undefined, undefined, ctx)).content[0].text, /No subagent tasks in this session/);
|
|
@@ -4533,7 +4929,7 @@ test("the card follows the active session: after /new the earlier session's task
|
|
|
4533
4929
|
assert.doesNotMatch(overlay.render(80).map(stripAnsi).join("\n"), /◐ Subagent explore/, "retained children of a replaced session do not imply an open orchestrator");
|
|
4534
4930
|
overlay.handleInput("\x1b");
|
|
4535
4931
|
await opened;
|
|
4536
|
-
sessions.sessionManager = { getSessionId: () => "s1", getCwd: () => cwd, getBranch: () => [], getEntries: () => [] };
|
|
4932
|
+
sessions.sessionManager = { getSessionId: () => "s1", getCwd: () => cwd, getBranch: () => [], getEntries: () => [], getSessionFile: () => undefined };
|
|
4537
4933
|
await fire("session_start", ctx, { type: "session_start", reason: "resume" });
|
|
4538
4934
|
assert.match(widget()![1], /◐ explore Long job/, "resuming the first session shows its task again");
|
|
4539
4935
|
});
|
|
@@ -4588,6 +4984,70 @@ test("default session transport selects Windows or POSIX classes without mutatin
|
|
|
4588
4984
|
assert.notEqual(windows.createRegistry, posix.createRegistry);
|
|
4589
4985
|
});
|
|
4590
4986
|
|
|
4987
|
+
test("session transport startup diagnostic reports only bounded current failures", async (t) => {
|
|
4988
|
+
for (const mode of ["initialize", "registry", "listener", "malformed", "success", "stale-id", "reload", "shutdown"] as const) {
|
|
4989
|
+
await t.test(mode, async () => {
|
|
4990
|
+
const h = fakePi(), runtime = deps(), { ctx } = fakeContext();
|
|
4991
|
+
const notices: Array<{ message: string; level: unknown }> = [];
|
|
4992
|
+
ctx.ui.notify = (message, level) => { notices.push({ message, level }); };
|
|
4993
|
+
let release!: () => void;
|
|
4994
|
+
const pending = new Promise<void>((resolve) => { release = resolve; });
|
|
4995
|
+
let entered = false;
|
|
4996
|
+
let starts = 0;
|
|
4997
|
+
let observerResult: unknown = "not called";
|
|
4998
|
+
const registry = { list: async () => [], listActivations: async () => [] };
|
|
4999
|
+
runtime.deps.sessionTransport = {
|
|
5000
|
+
createRegistry: async (_home, observe) => {
|
|
5001
|
+
if (mode === "initialize") {
|
|
5002
|
+
observerResult = observe?.({ phase: "start", status: "succeeded", error: null, lastStartupMarker: "native-ready" });
|
|
5003
|
+
observe?.({ phase: "initialize", status: "failed", error: { class: "timed-out", code: "deadline" }, lastStartupMarker: "native-ready" });
|
|
5004
|
+
observe?.({ phase: "cleanup", status: "succeeded", error: null, lastStartupMarker: "native-ready" });
|
|
5005
|
+
throw new Error("SECRET path SID stderr session-id");
|
|
5006
|
+
}
|
|
5007
|
+
if (mode === "malformed") {
|
|
5008
|
+
observe?.({ phase: "SECRET", status: "failed", error: { class: "SECRET", code: "SECRET" }, lastStartupMarker: "SECRET" } as never);
|
|
5009
|
+
throw new Error("SECRET");
|
|
5010
|
+
}
|
|
5011
|
+
if (mode === "registry") throw new Error("SECRET path SID stderr session-id");
|
|
5012
|
+
if (mode === "stale-id" || mode === "reload" || mode === "shutdown") {
|
|
5013
|
+
entered = true;
|
|
5014
|
+
await pending;
|
|
5015
|
+
throw new Error("SECRET");
|
|
5016
|
+
}
|
|
5017
|
+
return registry;
|
|
5018
|
+
},
|
|
5019
|
+
createListener: () => ({ registry, start: async () => { starts++; if (mode === "listener") throw new Error("SECRET"); }, close: async () => {} }),
|
|
5020
|
+
createClient: inertSessionTransport.createClient,
|
|
5021
|
+
};
|
|
5022
|
+
gentleAgents(h.pi, {}, runtime.deps);
|
|
5023
|
+
await h.fire("session_start", ctx);
|
|
5024
|
+
if (mode === "stale-id" || mode === "reload" || mode === "shutdown") {
|
|
5025
|
+
await eventually(() => entered, "registry startup entered");
|
|
5026
|
+
if (mode === "stale-id") Object.assign(ctx.sessionManager, { getSessionId: () => "replacement" });
|
|
5027
|
+
if (mode === "reload") await h.fire("session_start", fakeContext().ctx);
|
|
5028
|
+
if (mode === "shutdown") {
|
|
5029
|
+
const closing = h.fire("session_shutdown", ctx);
|
|
5030
|
+
release();
|
|
5031
|
+
await closing;
|
|
5032
|
+
}
|
|
5033
|
+
release();
|
|
5034
|
+
}
|
|
5035
|
+
// Shutdown drains tracked startup operations, including catch and cleanup.
|
|
5036
|
+
if (mode === "success") await eventually(() => starts === 1, "successful listener start");
|
|
5037
|
+
if (["initialize", "registry", "listener", "malformed"].includes(mode)) {
|
|
5038
|
+
await eventually(() => notices.length === 1, "startup diagnostic notification");
|
|
5039
|
+
}
|
|
5040
|
+
await h.fire("session_shutdown", ctx);
|
|
5041
|
+
const expected = mode === "initialize"
|
|
5042
|
+
? "Session transport startup failed: phase=initialize class=timed-out code=deadline lastStartupMarker=native-ready."
|
|
5043
|
+
: mode === "listener" ? "Session transport startup failed: phase=listener diagnostics=unavailable."
|
|
5044
|
+
: mode === "registry" || mode === "malformed" ? "Session transport startup failed: phase=registry diagnostics=unavailable." : undefined;
|
|
5045
|
+
assert.deepEqual(notices, expected ? [{ message: expected, level: "warning" }] : []);
|
|
5046
|
+
if (mode === "initialize") assert.equal(observerResult, undefined);
|
|
5047
|
+
});
|
|
5048
|
+
}
|
|
5049
|
+
});
|
|
5050
|
+
|
|
4591
5051
|
test("session transport startup failure cleans the constructed Windows-capable transport and stays unavailable", async () => {
|
|
4592
5052
|
const h = fakePi();
|
|
4593
5053
|
const runtime = deps();
|
|
@@ -4622,6 +5082,179 @@ test("session transport startup failure cleans the constructed Windows-capable t
|
|
|
4622
5082
|
assert.match((await h.tools.get("orchestrator_session_id")!.execute("id", {}, undefined, undefined, ctx)).content[0].text, /not ready/);
|
|
4623
5083
|
});
|
|
4624
5084
|
|
|
5085
|
+
test("session transport startup failure re-arms exactly once on a later session event", async (t) => {
|
|
5086
|
+
for (const mode of ["recovers", "fails-again", "first-succeeds", "agent-start"] as const) {
|
|
5087
|
+
await t.test(mode, async () => {
|
|
5088
|
+
const h = fakePi(), runtime = deps(), { ctx } = fakeContext();
|
|
5089
|
+
const notices: Array<{ message: string; level: unknown }> = [];
|
|
5090
|
+
ctx.ui.notify = (message, level) => { notices.push({ message, level }); };
|
|
5091
|
+
let registries = 0, starts = 0, closes = 0;
|
|
5092
|
+
const registry = { list: async () => [], listActivations: async () => [] };
|
|
5093
|
+
runtime.deps.sessionTransport = {
|
|
5094
|
+
createRegistry: async () => { registries++; return registry; },
|
|
5095
|
+
createListener: () => ({ registry, start: async () => {
|
|
5096
|
+
starts++;
|
|
5097
|
+
if (mode !== "first-succeeds" && (starts === 1 || mode === "fails-again")) throw new Error("SECRET path token");
|
|
5098
|
+
}, close: async () => { closes++; } }),
|
|
5099
|
+
createClient: inertSessionTransport.createClient,
|
|
5100
|
+
};
|
|
5101
|
+
gentleAgents(h.pi, {}, runtime.deps);
|
|
5102
|
+
await h.fire("session_start", ctx);
|
|
5103
|
+
const id = async () => (await h.tools.get("orchestrator_session_id")!.execute("id", {}, undefined, undefined, ctx)).content[0].text;
|
|
5104
|
+
const warning = { message: "Session transport startup failed: phase=listener diagnostics=unavailable.", level: "warning" };
|
|
5105
|
+
if (mode === "first-succeeds") {
|
|
5106
|
+
await eventually(() => starts === 1, "first startup");
|
|
5107
|
+
await h.fire("turn_end", ctx);
|
|
5108
|
+
await h.fire("agent_start", ctx);
|
|
5109
|
+
await new Promise((resolve) => setTimeout(resolve, 20));
|
|
5110
|
+
assert.equal(registries, 1, "a live transport is never re-armed");
|
|
5111
|
+
assert.deepEqual(notices, []);
|
|
5112
|
+
await h.fire("session_shutdown", ctx);
|
|
5113
|
+
return;
|
|
5114
|
+
}
|
|
5115
|
+
await eventually(() => notices.length === 1 && closes === 1, "first startup failure and cleanup");
|
|
5116
|
+
assert.match(await id(), /not ready/);
|
|
5117
|
+
await h.fire(mode === "agent-start" ? "agent_start" : "turn_end", ctx);
|
|
5118
|
+
await eventually(() => starts === 2, "one re-arm attempt");
|
|
5119
|
+
if (mode === "fails-again") {
|
|
5120
|
+
await eventually(() => notices.length === 2 && closes === 2, "second failure warns again");
|
|
5121
|
+
for (const event of ["turn_end", "agent_start", "turn_end"]) await h.fire(event, ctx);
|
|
5122
|
+
await new Promise((resolve) => setTimeout(resolve, 20));
|
|
5123
|
+
assert.equal(registries, 2, "no further retries after the bounded re-arm");
|
|
5124
|
+
assert.deepEqual(notices, [warning, warning]);
|
|
5125
|
+
assert.match(await id(), /not ready/);
|
|
5126
|
+
} else {
|
|
5127
|
+
await new Promise((resolve) => setTimeout(resolve, 20));
|
|
5128
|
+
assert.doesNotMatch(await id(), /not ready/, "re-armed transport is active");
|
|
5129
|
+
await h.fire("turn_end", ctx);
|
|
5130
|
+
assert.equal(registries, 2);
|
|
5131
|
+
assert.deepEqual(notices, [warning]);
|
|
5132
|
+
}
|
|
5133
|
+
await h.fire("session_shutdown", ctx);
|
|
5134
|
+
});
|
|
5135
|
+
}
|
|
5136
|
+
});
|
|
5137
|
+
|
|
5138
|
+
test("session transport re-arm stays bounded across shutdown, pending close, and session replacement races", async (t) => {
|
|
5139
|
+
for (const mode of ["shutdown", "close-pending", "session-switch", "changed-id"] as const) {
|
|
5140
|
+
await t.test(mode, async () => {
|
|
5141
|
+
const h = fakePi(), runtime = deps(), { ctx } = fakeContext(), { ctx: other } = fakeContext();
|
|
5142
|
+
Object.assign(other.sessionManager, { getSessionId: () => "s2" });
|
|
5143
|
+
const notices: string[] = [];
|
|
5144
|
+
ctx.ui.notify = (message) => { notices.push(message); };
|
|
5145
|
+
other.ui.notify = (message) => { notices.push(message); };
|
|
5146
|
+
const starts = new Map<string, number>();
|
|
5147
|
+
let registries = 0, closes = 0;
|
|
5148
|
+
let releaseClose: (() => void) | undefined;
|
|
5149
|
+
const closeGate = mode === "close-pending" ? new Promise<void>((resolve) => { releaseClose = resolve; }) : undefined;
|
|
5150
|
+
const registry = { list: async () => [], listActivations: async () => [] };
|
|
5151
|
+
runtime.deps.sessionTransport = {
|
|
5152
|
+
createRegistry: async () => { registries++; return registry; },
|
|
5153
|
+
createListener: (_registry, sessionId) => ({ registry, start: async () => {
|
|
5154
|
+
starts.set(sessionId, (starts.get(sessionId) ?? 0) + 1);
|
|
5155
|
+
throw new Error("SECRET");
|
|
5156
|
+
}, close: async () => { closes++; if (closes === 1) await closeGate; } }),
|
|
5157
|
+
createClient: inertSessionTransport.createClient,
|
|
5158
|
+
};
|
|
5159
|
+
gentleAgents(h.pi, {}, runtime.deps);
|
|
5160
|
+
await h.fire("session_start", ctx);
|
|
5161
|
+
await eventually(() => notices.length === 1, "first startup failure");
|
|
5162
|
+
const settle = () => new Promise((resolve) => setTimeout(resolve, 20));
|
|
5163
|
+
if (mode === "shutdown") {
|
|
5164
|
+
await Promise.all([h.fire("session_shutdown", ctx), h.fire("agent_start", ctx), h.fire("turn_end", ctx)]);
|
|
5165
|
+
const after = registries;
|
|
5166
|
+
for (const event of ["agent_start", "turn_end"]) await h.fire(event, ctx);
|
|
5167
|
+
await settle();
|
|
5168
|
+
assert.equal(starts.get("s1"), 1, "no listener starts after shutdown");
|
|
5169
|
+
assert.equal(registries, after, "no startup begins after shutdown completed");
|
|
5170
|
+
return;
|
|
5171
|
+
}
|
|
5172
|
+
if (mode === "close-pending") {
|
|
5173
|
+
try {
|
|
5174
|
+
await h.fire("turn_end", ctx);
|
|
5175
|
+
await h.fire("agent_start", ctx);
|
|
5176
|
+
await settle();
|
|
5177
|
+
assert.equal(registries, 1, "no re-arm while the failed startup is still closing");
|
|
5178
|
+
} finally {
|
|
5179
|
+
// A failed assertion must not leave shutdown waiting on the gated close.
|
|
5180
|
+
releaseClose!();
|
|
5181
|
+
}
|
|
5182
|
+
await settle();
|
|
5183
|
+
await h.fire("turn_end", ctx);
|
|
5184
|
+
await eventually(() => starts.get("s1") === 2, "exactly one re-arm after close resolves");
|
|
5185
|
+
await eventually(() => notices.length === 2, "re-arm failure warns");
|
|
5186
|
+
for (const event of ["turn_end", "agent_start"]) await h.fire(event, ctx);
|
|
5187
|
+
await settle();
|
|
5188
|
+
assert.equal(registries, 2);
|
|
5189
|
+
}
|
|
5190
|
+
if (mode === "session-switch") {
|
|
5191
|
+
await settle();
|
|
5192
|
+
await h.fire("session_start", other);
|
|
5193
|
+
await eventually(() => notices.length === 2, "replacement session startup failure");
|
|
5194
|
+
await settle();
|
|
5195
|
+
await h.fire("turn_end", ctx);
|
|
5196
|
+
await h.fire("agent_start", ctx);
|
|
5197
|
+
await settle();
|
|
5198
|
+
assert.equal(starts.get("s1"), 1, "the retired session is never re-armed");
|
|
5199
|
+
assert.equal(starts.get("s2"), 1);
|
|
5200
|
+
await h.fire("turn_end", other);
|
|
5201
|
+
await eventually(() => starts.get("s2") === 2, "the replacement session gets its own single re-arm");
|
|
5202
|
+
await eventually(() => notices.length === 3, "replacement re-arm failure warns");
|
|
5203
|
+
for (const event of ["turn_end", "agent_start"]) await h.fire(event, other);
|
|
5204
|
+
await settle();
|
|
5205
|
+
assert.equal(starts.get("s2"), 2);
|
|
5206
|
+
assert.equal(starts.get("s1"), 1);
|
|
5207
|
+
await h.fire("session_shutdown", other);
|
|
5208
|
+
return;
|
|
5209
|
+
}
|
|
5210
|
+
if (mode === "changed-id") {
|
|
5211
|
+
await settle();
|
|
5212
|
+
Object.assign(ctx.sessionManager, { getSessionId: () => "replacement" });
|
|
5213
|
+
for (const event of ["turn_end", "agent_start"]) await h.fire(event, ctx);
|
|
5214
|
+
await settle();
|
|
5215
|
+
assert.equal(registries, 1, "a changed session id on the same manager is never re-armed");
|
|
5216
|
+
assert.equal(notices.length, 1);
|
|
5217
|
+
}
|
|
5218
|
+
await h.fire("session_shutdown", ctx);
|
|
5219
|
+
});
|
|
5220
|
+
}
|
|
5221
|
+
});
|
|
5222
|
+
|
|
5223
|
+
test("a failed presence start at session_start warns with a fixed code and clears presence", async (t) => {
|
|
5224
|
+
const start = t.mock.method(PresencePublisher, "start", () => { throw new Error("SECRET C:\\Users\\private token"); });
|
|
5225
|
+
const h = fakePi(), runtime = deps(), { ctx } = fakeContext();
|
|
5226
|
+
const notices: Array<{ message: string; level: unknown }> = [];
|
|
5227
|
+
ctx.ui.notify = (message, level) => { notices.push({ message, level }); };
|
|
5228
|
+
gentleAgents(h.pi, {}, runtime.deps);
|
|
5229
|
+
await h.fire("session_start", ctx);
|
|
5230
|
+
assert.ok(start.mock.callCount() >= 1);
|
|
5231
|
+
assert.deepEqual(notices.filter((notice) => notice.message.includes("presence")), [{ message: "Session presence unavailable: phase=presence class=transport code=presence-cleared.", level: "warning" }]);
|
|
5232
|
+
assert.ok(notices.every((notice) => !notice.message.includes("SECRET")));
|
|
5233
|
+
await h.fire("session_shutdown", ctx);
|
|
5234
|
+
});
|
|
5235
|
+
|
|
5236
|
+
test("Windows bootstrap stderr codes reach the startup warning without raw stderr", async () => {
|
|
5237
|
+
const h = fakePi(), runtime = deps(), { ctx } = fakeContext();
|
|
5238
|
+
const notices: Array<{ message: string; level: unknown }> = [];
|
|
5239
|
+
ctx.ui.notify = (message, level) => { notices.push({ message, level }); };
|
|
5240
|
+
runtime.deps.sessionTransport = {
|
|
5241
|
+
...inertSessionTransport,
|
|
5242
|
+
createRegistry: async (_home, observe, observeBootstrap) => {
|
|
5243
|
+
observeBootstrap?.("rejection-transport-assert-owned");
|
|
5244
|
+
observeBootstrap?.("SECRET stderr" as never);
|
|
5245
|
+
observe?.({ phase: "start", status: "succeeded", error: null, lastStartupMarker: "native-ready" });
|
|
5246
|
+
observe?.({ phase: "initialize", status: "failed", error: { class: "rejected", code: "protocol" }, lastStartupMarker: "native-ready" });
|
|
5247
|
+
observe?.({ phase: "cleanup", status: "succeeded", error: null, lastStartupMarker: "native-ready" });
|
|
5248
|
+
throw new Error("SECRET");
|
|
5249
|
+
},
|
|
5250
|
+
};
|
|
5251
|
+
gentleAgents(h.pi, {}, runtime.deps);
|
|
5252
|
+
await h.fire("session_start", ctx);
|
|
5253
|
+
await eventually(() => notices.length === 1, "startup warning");
|
|
5254
|
+
await h.fire("session_shutdown", ctx);
|
|
5255
|
+
assert.deepEqual(notices, [{ message: "Session transport startup failed: phase=initialize class=rejected code=protocol lastStartupMarker=native-ready bootstrap=rejection-transport-assert-owned.", level: "warning" }]);
|
|
5256
|
+
});
|
|
5257
|
+
|
|
4625
5258
|
test("registered task aliases persist independently of human names and curated state", async () => {
|
|
4626
5259
|
const h = fakePi(), runtime = deps(), { ctx } = fakeContext();
|
|
4627
5260
|
const timers = recordTimers(runtime.deps);
|
|
@@ -4992,6 +5625,47 @@ test("orchestrator_list labels a live peer that predates discovery publication (
|
|
|
4992
5625
|
} finally { publisher.dispose(); }
|
|
4993
5626
|
});
|
|
4994
5627
|
|
|
5628
|
+
test("orchestrator_list flags classified-work peers that never publish state (#2633)", async () => {
|
|
5629
|
+
const h = fakePi();
|
|
5630
|
+
const runtime = deps();
|
|
5631
|
+
const profile = realpathSync(mkdtempSync(join(root, "discovery-unpublished-")));
|
|
5632
|
+
const peer = { version: 1 as const, sessionId: "peer", endpoint: "/fixture/peer.sock", createdAt: 1 };
|
|
5633
|
+
const publisher = PresencePublisher.start({ profile, sessionId: "peer", label: "Silent worker", activity: [] });
|
|
5634
|
+
try {
|
|
5635
|
+
let ready = false;
|
|
5636
|
+
const registry = { list: async () => [], listActivations: async () => [peer] };
|
|
5637
|
+
runtime.deps.agentHome = profile;
|
|
5638
|
+
runtime.deps.sessionTransport = {
|
|
5639
|
+
createRegistry: async () => registry,
|
|
5640
|
+
createListener: () => ({ registry, start: async () => { ready = true; }, close: async () => {} }),
|
|
5641
|
+
createClient: () => ({ close() {}, sendNotification: async () => { throw new Error("no messages expected"); } }),
|
|
5642
|
+
};
|
|
5643
|
+
gentleAgents(h.pi, {}, runtime.deps);
|
|
5644
|
+
const { ctx } = fakeContext();
|
|
5645
|
+
await h.fire("session_start", ctx);
|
|
5646
|
+
await eventually(() => ready, "discovery transport ready");
|
|
5647
|
+
// A live peer with a discovery sidecar but no owner-curated state publication:
|
|
5648
|
+
// the catalog must flag it instead of showing an unexplained unknown.
|
|
5649
|
+
publisher.updateDiscovery(peer, { workspace: "/repo", tasks: [] });
|
|
5650
|
+
const result = await h.tools.get("orchestrator_list")!.execute("list", {}, undefined, undefined, ctx);
|
|
5651
|
+
assert.equal(result.content[0].text, "Advertised sessions (reachability is unknown):\n"
|
|
5652
|
+
+ "- peer · Silent worker · Session name: Silent worker · Current alias (CURRENT TASK): unknown · Initial alias (FIRST TASK): unknown · recorded workspace: /repo"
|
|
5653
|
+
+ " · repository: unknown · metadata: recent\n recorded catalog (not Git identity): {\"tasks\":[],\"registered\":[],\"omittedTasks\":0,\"omittedRegistered\":0} · work state: never published"
|
|
5654
|
+
+ "\n1 of 1 advertised sessions have never published work state. Publication is mandatory for classified work: each owner session publishes state (objective, work.topic) at session start and again on every task-topic change via orchestrator_session_id.");
|
|
5655
|
+
assert.equal((result.details.gentleAgents as any).candidates[0].statePublished, false);
|
|
5656
|
+
publisher.updateDiscovery(peer, { workspace: "/repo", tasks: [], state: {
|
|
5657
|
+
schema: 2, sessionId: "peer", cwd: "/repo", recordedAt: 1, source: "owner-curated",
|
|
5658
|
+
ownerReply: false, authority: "none", state: { objective: "Ship review", work: { area: "Auth" } },
|
|
5659
|
+
} });
|
|
5660
|
+
const published = await h.tools.get("orchestrator_list")!.execute("published", {}, undefined, undefined, ctx);
|
|
5661
|
+
assert.doesNotMatch(published.content[0].text, /never published/);
|
|
5662
|
+
assert.equal((published.details.gentleAgents as any).candidates[0].statePublished, true);
|
|
5663
|
+
assert.equal(runtime.spawned.length, 0);
|
|
5664
|
+
assert.equal(h.sent.length, 0);
|
|
5665
|
+
await h.fire("session_shutdown", ctx);
|
|
5666
|
+
} finally { publisher.dispose(); }
|
|
5667
|
+
});
|
|
5668
|
+
|
|
4995
5669
|
test("registered reasoning and revocation use live SDK host and published source only", async () => {
|
|
4996
5670
|
const h = fakePi(), runtime = deps();
|
|
4997
5671
|
const profile = realpathSync(mkdtempSync(join(root, "reasoning-runtime-")));
|
|
@@ -5126,6 +5800,9 @@ test("session transport adds host tools, forwards notifications, and closes on s
|
|
|
5126
5800
|
assert.match((await h.tools.get("orchestrator_list")!.execute("list", {}, undefined, undefined, ctx)).content[0].text, /peer/);
|
|
5127
5801
|
assert.ok(callback, "listener receives the inbound callback");
|
|
5128
5802
|
Object.assign(ctx.sessionManager, { getSessionName: () => "Integration" });
|
|
5803
|
+
// Idle and held routing are covered by the orchestrator delivery tests; a
|
|
5804
|
+
// running parent keeps the original follow-up delivery.
|
|
5805
|
+
await h.fire("agent_start", ctx);
|
|
5129
5806
|
await callback!({ id: "message-1", senderSessionId: "peer", message: "\u001b[31mraw model content" });
|
|
5130
5807
|
assert.equal(h.sent.at(-1)?.message.customType, "gentle-agents.orchestrator-message");
|
|
5131
5808
|
assert.match(String(h.sent.at(-1)?.message.content), /\u001b\[31mraw model content/);
|
|
@@ -5197,7 +5874,7 @@ test("session transport selects a peer for outbound delivery and rejects stale c
|
|
|
5197
5874
|
Object.assign(ctx.sessionManager, { getSessionName: () => "Backend" });
|
|
5198
5875
|
const result = await h.tools.get("orchestrator_send_message")!.execute("send", { message: "hello peer", reason: "because the peer needs an update" }, undefined, undefined, ctx);
|
|
5199
5876
|
assert.deepEqual(dialogs, [
|
|
5200
|
-
"select:Select recipient orchestrator:Orchestrator alpha|Orchestrator beta",
|
|
5877
|
+
"select:Select recipient orchestrator:Orchestrator · alpha|Orchestrator · beta",
|
|
5201
5878
|
"select:Authorize cross-orchestrator message to alpha?\nReason: because the peer needs an update\nMessage: hello peer:Allow once|Allow for this session|Deny",
|
|
5202
5879
|
]);
|
|
5203
5880
|
assert.deepEqual(sent, [{ recipient: "alpha", message: "hello peer", expectedActivation: records[0] }]);
|
|
@@ -5225,6 +5902,95 @@ test("session transport selects a peer for outbound delivery and rejects stale c
|
|
|
5225
5902
|
await h.fire("session_shutdown", ctx);
|
|
5226
5903
|
});
|
|
5227
5904
|
|
|
5905
|
+
test("recipient picker uses published labels and grows the suffix until every label is unique", async () => {
|
|
5906
|
+
const h = fakePi();
|
|
5907
|
+
const runtime = deps();
|
|
5908
|
+
// Three long ids share their last four characters, and two peers share the same
|
|
5909
|
+
// published label, so only a grown suffix can tell the whole list apart.
|
|
5910
|
+
const alphaId = "11111111-1111-4111-8111-11111111abcd";
|
|
5911
|
+
const betaId = "22222222-2222-4222-8222-22222222abcd";
|
|
5912
|
+
const gammaId = "33333333-3333-4333-8333-33333333abcd";
|
|
5913
|
+
const activations: PresenceRecord[] = [
|
|
5914
|
+
{ version: 1, sessionId: alphaId, endpoint: "/alpha.sock", createdAt: 1 },
|
|
5915
|
+
{ version: 1, sessionId: betaId, endpoint: "/beta.sock", createdAt: 2 },
|
|
5916
|
+
{ version: 1, sessionId: gammaId, endpoint: "/gamma.sock", createdAt: 3 },
|
|
5917
|
+
];
|
|
5918
|
+
const profile = realpathSync(mkdtempSync(join(tmpdir(), "gentle-agents-labels-")));
|
|
5919
|
+
const publishers = [
|
|
5920
|
+
PresencePublisher.start({ profile, sessionId: alphaId, label: "api", activity: [] }),
|
|
5921
|
+
PresencePublisher.start({ profile, sessionId: betaId, label: "api", activity: [] }),
|
|
5922
|
+
PresencePublisher.start({ profile, sessionId: gammaId, label: "database", activity: [] }),
|
|
5923
|
+
];
|
|
5924
|
+
publishers[0]!.updateDiscovery(activations[0]!, { workspace: "/repo/api", tasks: [] });
|
|
5925
|
+
publishers[1]!.updateDiscovery(activations[1]!, { workspace: "/repo/api", tasks: [] });
|
|
5926
|
+
publishers[2]!.updateDiscovery(activations[2]!, { workspace: "/repo/melia/db", tasks: [] });
|
|
5927
|
+
const sent: Array<{ recipient: string }> = [];
|
|
5928
|
+
const registry = { list: async () => [], listActivations: async () => activations };
|
|
5929
|
+
runtime.deps.sessionTransport = {
|
|
5930
|
+
createRegistry: async () => registry,
|
|
5931
|
+
createListener: () => ({ registry, start: async () => {}, close: async () => {} }),
|
|
5932
|
+
createClient: () => ({ close: () => {}, sendNotification: async (recipient: string) => { sent.push({ recipient }); return { id: "accepted-1", accepted: true }; } }),
|
|
5933
|
+
} as never;
|
|
5934
|
+
let chosen = 0;
|
|
5935
|
+
const { ctx, dialogs } = fakeContext(undefined, undefined, undefined, undefined, async (title, options) => title.startsWith("Select recipient") ? options[chosen] : options[0]);
|
|
5936
|
+
gentleAgents(h.pi, {}, { ...runtime.deps, agentHome: profile });
|
|
5937
|
+
try {
|
|
5938
|
+
await h.fire("session_start", ctx);
|
|
5939
|
+
const tool = h.tools.get("orchestrator_send_message")!;
|
|
5940
|
+
const params = { message: "hello", reason: "because the peer needs an update" };
|
|
5941
|
+
for (chosen = 0; chosen < 3; chosen += 1) await tool.execute("send", params, undefined, undefined, ctx);
|
|
5942
|
+
} finally {
|
|
5943
|
+
for (const publisher of publishers) publisher.dispose();
|
|
5944
|
+
rmSync(profile, { recursive: true, force: true });
|
|
5945
|
+
}
|
|
5946
|
+
// The published label leads, the workspace basename follows only when it adds
|
|
5947
|
+
// something, and the shared four-character tail forces the suffix to grow to six.
|
|
5948
|
+
assert.equal(dialogs[0], "select:Select recipient orchestrator:api · 11abcd|api · 22abcd|database (db) · 33abcd");
|
|
5949
|
+
assert.deepEqual(sent, [{ recipient: alphaId }, { recipient: betaId }, { recipient: gammaId }], "each displayed label must send to its own session");
|
|
5950
|
+
});
|
|
5951
|
+
|
|
5952
|
+
test("recipient picker keeps one row per session when a transport repeats an activation", async () => {
|
|
5953
|
+
const h = fakePi();
|
|
5954
|
+
const runtime = deps();
|
|
5955
|
+
const alphaId = "11111111-1111-4111-8111-111111111111";
|
|
5956
|
+
const betaId = "22222222-2222-4222-8222-222222222222";
|
|
5957
|
+
// The canonical activation is the one the publication binds to, and it comes last, so a
|
|
5958
|
+
// deduplication that keeps only one record would resolve the label of an ambiguous peer.
|
|
5959
|
+
const activations: PresenceRecord[] = [
|
|
5960
|
+
{ version: 1, sessionId: alphaId, endpoint: "/alpha-again.sock", createdAt: 1 },
|
|
5961
|
+
{ version: 1, sessionId: alphaId, endpoint: "/alpha.sock", createdAt: 2 },
|
|
5962
|
+
{ version: 1, sessionId: betaId, endpoint: "/beta.sock", createdAt: 3 },
|
|
5963
|
+
];
|
|
5964
|
+
const profile = realpathSync(mkdtempSync(join(tmpdir(), "gentle-agents-dedupe-")));
|
|
5965
|
+
const publishers = [
|
|
5966
|
+
PresencePublisher.start({ profile, sessionId: alphaId, label: "api", activity: [] }),
|
|
5967
|
+
PresencePublisher.start({ profile, sessionId: betaId, label: "database", activity: [] }),
|
|
5968
|
+
];
|
|
5969
|
+
publishers[0]!.updateDiscovery(activations[1]!, { workspace: "/repo/api", tasks: [] });
|
|
5970
|
+
publishers[1]!.updateDiscovery(activations[2]!, { workspace: "/repo/melia/db", tasks: [] });
|
|
5971
|
+
const sent: Array<{ recipient: string }> = [];
|
|
5972
|
+
const registry = { list: async () => [], listActivations: async () => activations };
|
|
5973
|
+
runtime.deps.sessionTransport = {
|
|
5974
|
+
createRegistry: async () => registry,
|
|
5975
|
+
createListener: () => ({ registry, start: async () => {}, close: async () => {} }),
|
|
5976
|
+
createClient: () => ({ close: () => {}, sendNotification: async (recipient: string) => { sent.push({ recipient }); return { id: "accepted-1", accepted: true }; } }),
|
|
5977
|
+
} as never;
|
|
5978
|
+
let chosen = 1;
|
|
5979
|
+
const { ctx, dialogs } = fakeContext(undefined, undefined, undefined, undefined, async (title, options) => title.startsWith("Select recipient") ? options[chosen] : options[0]);
|
|
5980
|
+
gentleAgents(h.pi, {}, { ...runtime.deps, agentHome: profile });
|
|
5981
|
+
try {
|
|
5982
|
+
await h.fire("session_start", ctx);
|
|
5983
|
+
await h.tools.get("orchestrator_send_message")!.execute("send", { message: "hello", reason: "because the peer needs an update" }, undefined, undefined, ctx);
|
|
5984
|
+
} finally {
|
|
5985
|
+
for (const publisher of publishers) publisher.dispose();
|
|
5986
|
+
rmSync(profile, { recursive: true, force: true });
|
|
5987
|
+
}
|
|
5988
|
+
// One row per session, and the duplicated session stays unlabelled: discovery still
|
|
5989
|
+
// sees both activations and fails closed instead of guessing which one it is.
|
|
5990
|
+
assert.equal(dialogs[0], "select:Select recipient orchestrator:Orchestrator · 1111|database (db) · 2222");
|
|
5991
|
+
assert.deepEqual(sent, [{ recipient: betaId }], "the second row must still be the second session");
|
|
5992
|
+
});
|
|
5993
|
+
|
|
5228
5994
|
test("all orchestrator tools own compact and expanded card rendering", () => {
|
|
5229
5995
|
const h = fakePi();
|
|
5230
5996
|
gentleAgents(h.pi, {}, deps().deps);
|
|
@@ -5438,7 +6204,7 @@ test("orchestrator_send_message snapshots message and reason before recipient an
|
|
|
5438
6204
|
await eventually(() => dialogs.length === 1, "recipient selector opens");
|
|
5439
6205
|
params.message = "mutated during recipient selection";
|
|
5440
6206
|
params.reason = "mutated reason one";
|
|
5441
|
-
chooseRecipient("Orchestrator alpha");
|
|
6207
|
+
chooseRecipient("Orchestrator · alpha");
|
|
5442
6208
|
await eventually(() => dialogs.length === 2, "consent selector opens");
|
|
5443
6209
|
params.message = "mutated during consent selection";
|
|
5444
6210
|
params.reason = "mutated reason two";
|
|
@@ -5570,7 +6336,9 @@ for (const provider of ["openai", "anthropic", "custom-extension", undefined, "c
|
|
|
5570
6336
|
assert.deepEqual(h.sent[1]!.options, { deliverAs: "steer", triggerTurn: true });
|
|
5571
6337
|
assert.equal(h.sent[1]!.message.display, false);
|
|
5572
6338
|
assert.equal(h.sent[1]!.message.customType, "gentle-agents.wake");
|
|
5573
|
-
|
|
6339
|
+
// Pi hands custom messages to the model with the user role, so the wake
|
|
6340
|
+
// must disown authorship and keep the human's reply language.
|
|
6341
|
+
assert.equal(h.sent[1]!.message.content, "[System-generated Gentle Agents notification, not written by the user] Subagent output was delivered to this session above. Review it and continue. Reply in the language of the human's own last message, not the language of this notification or of the subagent output.");
|
|
5574
6342
|
assert.deepEqual(h.delivery, [`custom:gentle-agents.${kind === "query" ? "message" : "result"}`, "custom:gentle-agents.wake"]);
|
|
5575
6343
|
}
|
|
5576
6344
|
await h.fire("session_shutdown", ctx);
|
|
@@ -5763,15 +6531,113 @@ for (const boundary of ["session_compact", "session_compact_failed"] as const) {
|
|
|
5763
6531
|
});
|
|
5764
6532
|
}
|
|
5765
6533
|
|
|
5766
|
-
|
|
5767
|
-
|
|
6534
|
+
// Incoming orchestrator session messages share the child-content delivery
|
|
6535
|
+
// router: an idle parent must be woken through the prompt lifecycle, a busy
|
|
6536
|
+
// run keeps the follow-up route, and a parent compacting without a run holds
|
|
6537
|
+
// the message for the next boundary.
|
|
6538
|
+
async function orchestratorHost() {
|
|
6539
|
+
const host = fakePi();
|
|
5768
6540
|
const harness = deps();
|
|
5769
|
-
|
|
6541
|
+
const timers = recordTimers(harness.deps);
|
|
6542
|
+
let received: ((notification: { id: string; senderSessionId: string; message: string }) => Promise<void>) | undefined;
|
|
6543
|
+
harness.deps.sessionTransport = {
|
|
6544
|
+
...inertSessionTransport,
|
|
6545
|
+
createListener: (registry, _sessionId, callback) => {
|
|
6546
|
+
received = callback;
|
|
6547
|
+
return { registry, start: async () => {}, close: async () => {} };
|
|
6548
|
+
},
|
|
6549
|
+
};
|
|
6550
|
+
gentleAgents(host.pi, {}, harness.deps);
|
|
5770
6551
|
const { ctx } = fakeContext();
|
|
5771
|
-
await fire("session_start", ctx);
|
|
5772
|
-
await
|
|
6552
|
+
await host.fire("session_start", ctx);
|
|
6553
|
+
await eventually(() => received !== undefined, "session transport listener starts");
|
|
6554
|
+
const notify = (message: string) => received!({ id: "m1", senderSessionId: "peer", message });
|
|
6555
|
+
return { ...host, ctx, timers, notify };
|
|
6556
|
+
}
|
|
6557
|
+
|
|
6558
|
+
test("an orchestrator message to an idle parent is stored without a direct turn and wakes the parent once", async () => {
|
|
6559
|
+
const { fire, ctx, sent, userMessages, delivery, notify } = await orchestratorHost();
|
|
6560
|
+
await notify("hello idle");
|
|
5773
6561
|
await tick();
|
|
5774
|
-
|
|
6562
|
+
assert.deepEqual(sent.map((entry) => entry.options), [{ triggerTurn: false }], "the message is stored without triggerTurn");
|
|
6563
|
+
assert.equal(sent[0]!.message.customType, "gentle-agents.orchestrator-message");
|
|
6564
|
+
assert.match(String(sent[0]!.message.content), /hello idle/);
|
|
6565
|
+
assert.equal(userMessages.length, 1, "one wake starts the turn through the prompt lifecycle");
|
|
6566
|
+
assert.doesNotMatch(String(userMessages[0]!.content), /hello idle/, "the wake never repeats the message");
|
|
6567
|
+
assert.deepEqual(delivery, ["custom:gentle-agents.orchestrator-message", "user"]);
|
|
6568
|
+
await fire("session_shutdown", ctx);
|
|
6569
|
+
});
|
|
6570
|
+
|
|
6571
|
+
test("an orchestrator message during a parent run keeps the follow-up route and sends no wake", async () => {
|
|
6572
|
+
const { fire, ctx, sent, userMessages, notify } = await orchestratorHost();
|
|
6573
|
+
await fire("agent_start", ctx);
|
|
6574
|
+
await notify("hello run");
|
|
6575
|
+
await tick();
|
|
6576
|
+
assert.deepEqual(sent.map((entry) => entry.options), [{ deliverAs: "followUp", triggerTurn: true }]);
|
|
6577
|
+
assert.equal(userMessages.length, 0);
|
|
6578
|
+
await fire("session_shutdown", ctx);
|
|
6579
|
+
});
|
|
6580
|
+
|
|
6581
|
+
test("an orchestrator message held while the parent compacts is routed after the boundary", async () => {
|
|
6582
|
+
const { fire, ctx, sent, userMessages, delivery, notify, setIdle, timers } = await orchestratorHost();
|
|
6583
|
+
setIdle(false);
|
|
6584
|
+
await notify("hello compaction");
|
|
6585
|
+
await tick();
|
|
6586
|
+
assert.equal(sent.length, 0, "no direct turn starts while the parent compacts");
|
|
6587
|
+
assert.equal(userMessages.length, 0, "no wake is sent while the parent compacts");
|
|
6588
|
+
await fire("session_compact", ctx);
|
|
6589
|
+
setIdle(true);
|
|
6590
|
+
assert.equal(timers.run(0), 1, "one deferred flush is scheduled for the boundary");
|
|
6591
|
+
await tick();
|
|
6592
|
+
assert.deepEqual(sent.map((entry) => entry.options), [{ triggerTurn: false }], "the held message is stored without a direct turn");
|
|
6593
|
+
assert.deepEqual(delivery, ["custom:gentle-agents.orchestrator-message", "user"]);
|
|
6594
|
+
await fire("session_shutdown", ctx);
|
|
6595
|
+
});
|
|
6596
|
+
|
|
6597
|
+
test("an orchestrator message held for a busy parent is delivered by the next turn boundary flush", async () => {
|
|
6598
|
+
const { fire, ctx, sent, notify, setIdle } = await orchestratorHost();
|
|
6599
|
+
setIdle(false);
|
|
6600
|
+
await notify("hello hold");
|
|
6601
|
+
assert.equal(sent.length, 0, "nothing is sent while the parent is busy without a run");
|
|
6602
|
+
await fire("agent_start", ctx);
|
|
6603
|
+
await fire("turn_end", ctx);
|
|
6604
|
+
assert.deepEqual(sent.map((entry) => entry.options), [{ deliverAs: "followUp", triggerTurn: true }], "a run that started meanwhile receives it as a follow-up");
|
|
6605
|
+
await fire("session_shutdown", ctx);
|
|
6606
|
+
});
|
|
6607
|
+
|
|
6608
|
+
test("an orchestrator message to a parent with a stale context fails delivery so the sender learns", async () => {
|
|
6609
|
+
const { fire, ctx, sent, userMessages, notify } = await orchestratorHost();
|
|
6610
|
+
Object.assign(ctx, { isIdle: () => { throw new Error("This extension ctx is stale after session replacement or reload."); } });
|
|
6611
|
+
await assert.rejects(notify("hello stale"), /stale/);
|
|
6612
|
+
assert.equal(sent.length, 0);
|
|
6613
|
+
assert.equal(userMessages.length, 0);
|
|
6614
|
+
await fire("session_shutdown", ctx);
|
|
6615
|
+
});
|
|
6616
|
+
|
|
6617
|
+
test("a held orchestrator message does not survive a session change", async () => {
|
|
6618
|
+
const { fire, ctx, sent, userMessages, notify, setIdle, timers } = await orchestratorHost();
|
|
6619
|
+
setIdle(false);
|
|
6620
|
+
await notify("hello dropped");
|
|
6621
|
+
await fire("session_start", ctx, { reason: "new" });
|
|
6622
|
+
setIdle(true);
|
|
6623
|
+
await fire("agent_settled", ctx);
|
|
6624
|
+
await fire("session_compact", ctx);
|
|
6625
|
+
timers.run(0);
|
|
6626
|
+
await tick();
|
|
6627
|
+
assert.equal(sent.length, 0, "the old session's held message is not replayed into the new one");
|
|
6628
|
+
assert.equal(userMessages.length, 0);
|
|
6629
|
+
await fire("session_shutdown", ctx);
|
|
6630
|
+
});
|
|
6631
|
+
|
|
6632
|
+
test("between agent_end and agent_settled the parent run is still active, so child content keeps the steer route", async () => {
|
|
6633
|
+
const { pi, tools, fire, sent, userMessages } = fakePi();
|
|
6634
|
+
const harness = deps();
|
|
6635
|
+
gentleAgents(pi, {}, harness.deps);
|
|
6636
|
+
const { ctx } = fakeContext();
|
|
6637
|
+
await fire("session_start", ctx);
|
|
6638
|
+
await tools.get("subagent_run")!.execute("c1", { agent: "explore", task: "Post-run window", mode: "background" }, undefined, undefined, ctx);
|
|
6639
|
+
await tick();
|
|
6640
|
+
await fire("agent_start", ctx);
|
|
5775
6641
|
await fire("agent_end", ctx);
|
|
5776
6642
|
harness.children[0].emit({ type: "agent_end", messages: [{ role: "assistant", content: [{ type: "text", text: "done" }] }] });
|
|
5777
6643
|
harness.children[0].emit({ type: "agent_settled" });
|
|
@@ -6493,7 +7359,7 @@ test("a subdirectory session cwd and workspace_root of the same worktree share o
|
|
|
6493
7359
|
const env: NodeJS.ProcessEnv = {};
|
|
6494
7360
|
gentleAgents(h.pi, env, { ...runtime.deps, resolveWorktree, env, agentHome: profile });
|
|
6495
7361
|
const { ctx } = fakeContext();
|
|
6496
|
-
Object.assign(ctx, { cwd: sub, sessionManager: { getSessionId: () => "s1", getCwd: () => sub, getEntries: () => [], getBranch: () => [] } });
|
|
7362
|
+
Object.assign(ctx, { cwd: sub, sessionManager: { getSessionId: () => "s1", getCwd: () => sub, getEntries: () => [], getBranch: () => [], getSessionFile: () => undefined } });
|
|
6497
7363
|
await h.fire("session_start", ctx);
|
|
6498
7364
|
const task = "Write it.\n\n## Allowed edit surfaces\nsrc/app.ts\n\n## Return\nReport";
|
|
6499
7365
|
try {
|
|
@@ -6610,6 +7476,11 @@ test("a busy parent gets the exit notice steered into its run at the next turn b
|
|
|
6610
7476
|
await jobIo();
|
|
6611
7477
|
assert.equal(sent.length, 0, "a busy parent is not interrupted mid-tool-call");
|
|
6612
7478
|
await fire("turn_end", ctx);
|
|
7479
|
+
// The notice lands when the job log closes, which can outlast this boundary under load; a later turn boundary then delivers it.
|
|
7480
|
+
for (let boundary = 0; boundary < 40 && sent.length === 0; boundary++) {
|
|
7481
|
+
await new Promise((resolve) => setTimeout(resolve, 25));
|
|
7482
|
+
await fire("turn_end", ctx);
|
|
7483
|
+
}
|
|
6613
7484
|
assert.equal(sent.length, 1);
|
|
6614
7485
|
assert.deepEqual(sent[0]!.options, { deliverAs: "steer", triggerTurn: true });
|
|
6615
7486
|
assert.match(String(sent[0]!.message.content), /job-1 \("make build"\) exited with code 0/);
|
|
@@ -6673,7 +7544,8 @@ test("/gentle:jobs opens this session's jobs overlay, stops the selected job, an
|
|
|
6673
7544
|
assert.equal(jobs.runs[0]!.signal?.aborted, true, "s stops the selected job");
|
|
6674
7545
|
assert.equal(statuses.at(-1), undefined, "the footer count clears when nothing runs");
|
|
6675
7546
|
assert.deepEqual(snapshots.at(-1)?.snapshot.jobs.map(({ status }) => status), ["stopped"], "the finished tail keeps the stopped job visible once the count clears");
|
|
6676
|
-
|
|
7547
|
+
// The stop notice follows the job log close, which can outlast a fixed wait under load.
|
|
7548
|
+
await eventually(() => sent.some((entry) => entry.message.customType === "gentle-jobs.notice"), "the stopped job must report its stop notice");
|
|
6677
7549
|
const notices = sent.filter((entry) => entry.message.customType === "gentle-jobs.notice");
|
|
6678
7550
|
assert.equal(notices.length, 1, "the agent was told it would be notified, so a human stop is reported once");
|
|
6679
7551
|
assert.match(String(notices[0]!.message.content), /job-1 \("CI"\) was stopped by the user/);
|
|
@@ -6686,6 +7558,48 @@ test("/gentle:jobs opens this session's jobs overlay, stops the selected job, an
|
|
|
6686
7558
|
}
|
|
6687
7559
|
});
|
|
6688
7560
|
|
|
7561
|
+
test("/gentle:jobs mouse controls route the chosen running job through the existing stop and notice path", async () => {
|
|
7562
|
+
const { pi, tools, commands, fire, sent } = fakePi();
|
|
7563
|
+
const jobs = fakeJobShell();
|
|
7564
|
+
gentleAgents(pi, {}, { ...deps().deps, jobShell: jobs.shell, jobOutputDir: () => jobs.dir });
|
|
7565
|
+
const { ctx, overlays } = fakeContext();
|
|
7566
|
+
try {
|
|
7567
|
+
assert.match(commands.get("gentle:jobs")?.description ?? "", /click.*Stop/i, "command help advertises the explicit mouse control");
|
|
7568
|
+
await fire("session_start", ctx);
|
|
7569
|
+
await tools.get("bash_background")!.execute("b1", { command: "first command", label: "first job" }, undefined, undefined, ctx);
|
|
7570
|
+
await tools.get("bash_background")!.execute("b2", { command: "second command", label: "second job" }, undefined, undefined, ctx);
|
|
7571
|
+
const opened = commands.get("gentle:jobs")!.handler("", ctx);
|
|
7572
|
+
await tick();
|
|
7573
|
+
const overlay = overlays.at(-1)!;
|
|
7574
|
+
const eventFor = (text: string, type: TuiMouseEvent["type"]) => {
|
|
7575
|
+
const lines = overlay.render(100).map(stripAnsi);
|
|
7576
|
+
const y = lines.findIndex((line) => line.includes(text));
|
|
7577
|
+
assert.ok(y >= 0, `Missing ${text}`);
|
|
7578
|
+
const x = visibleWidth(lines[y]!.slice(0, lines[y]!.indexOf(text)));
|
|
7579
|
+
return mouse(type, type === "move" ? "none" : "left", x, y, 100, lines.length);
|
|
7580
|
+
};
|
|
7581
|
+
overlay.handleMouse?.(eventFor("second job", "move"));
|
|
7582
|
+
assert.equal(jobs.runs[0]!.signal?.aborted, false);
|
|
7583
|
+
assert.equal(jobs.runs[1]!.signal?.aborted, false);
|
|
7584
|
+
overlay.handleMouse?.(eventFor("second job", "press"));
|
|
7585
|
+
overlay.handleMouse?.(eventFor("second job", "click"));
|
|
7586
|
+
assert.equal(jobs.runs[1]!.signal?.aborted, false, "selecting a row does not stop it");
|
|
7587
|
+
overlay.handleMouse?.(eventFor("s Stop", "press"));
|
|
7588
|
+
overlay.handleMouse?.(eventFor("s Stop", "click"));
|
|
7589
|
+
assert.equal(jobs.runs[0]!.signal?.aborted, false);
|
|
7590
|
+
assert.equal(jobs.runs[1]!.signal?.aborted, true, "the selected job alone is stopped");
|
|
7591
|
+
await eventually(() => sent.some((entry) => entry.message.customType === "gentle-jobs.notice"), "the stopped job must report its stop notice");
|
|
7592
|
+
const notices = sent.filter((entry) => entry.message.customType === "gentle-jobs.notice");
|
|
7593
|
+
assert.equal(notices.length, 1);
|
|
7594
|
+
assert.match(String(notices[0]!.message.content), /job-2 \("second job"\) was stopped by the user/);
|
|
7595
|
+
overlay.handleInput("q");
|
|
7596
|
+
await opened;
|
|
7597
|
+
} finally {
|
|
7598
|
+
await fire("session_shutdown", ctx);
|
|
7599
|
+
jobs.cleanup();
|
|
7600
|
+
}
|
|
7601
|
+
});
|
|
7602
|
+
|
|
6689
7603
|
test("a job exit notice whose forwarding throws while the parent is idle is retried after the bounded grace", async () => {
|
|
6690
7604
|
const { pi, tools, fire, sent, userMessages } = fakePi();
|
|
6691
7605
|
const harness = deps();
|
|
@@ -6702,9 +7616,13 @@ test("a job exit notice whose forwarding throws while the parent is idle is retr
|
|
|
6702
7616
|
await jobIo();
|
|
6703
7617
|
assert.equal(sent.length, 0);
|
|
6704
7618
|
assert.equal(userMessages.length, 0);
|
|
7619
|
+
assert.equal(sent.length, 0);
|
|
7620
|
+
assert.equal(userMessages.length, 0);
|
|
7621
|
+
// Forwarding keeps throwing until the job settles: the failed flush is what arms the bounded retry.
|
|
7622
|
+
await eventually(() => timers.pending(PARENT_WAKE_GRACE_MS) >= 1, "the failed flush arms the bounded retry timer");
|
|
6705
7623
|
Object.assign(pi, { sendMessage });
|
|
6706
7624
|
// No turn boundary is coming for an idle parent, so the retry is a timer.
|
|
6707
|
-
assert.equal(timers.run(PARENT_WAKE_GRACE_MS), 1, "one bounded retry flush is armed");
|
|
7625
|
+
assert.equal(timers.run(PARENT_WAKE_GRACE_MS), 1, "exactly one bounded retry flush is armed");
|
|
6708
7626
|
await tick();
|
|
6709
7627
|
const notices = sent.filter((entry) => entry.message.customType === "gentle-jobs.notice");
|
|
6710
7628
|
assert.equal(notices.length, 1, "the requeued notice reaches the idle parent");
|
|
@@ -6739,7 +7657,8 @@ for (const boundary of ["session_compact", "session_compact_failed"] as const) {
|
|
|
6739
7657
|
assert.equal(sent.length, 0, "the boundary handler runs before Pi leaves the compacting state");
|
|
6740
7658
|
setIdle(true);
|
|
6741
7659
|
assert.equal(timers.run(0), 1, "one deferred flush is scheduled for the compaction boundary");
|
|
6742
|
-
|
|
7660
|
+
// The flush only succeeds once the job log close settles, which can outlast the boundary under load.
|
|
7661
|
+
await eventually(() => sent.length >= 1, "the held notice is flushed after the compaction boundary");
|
|
6743
7662
|
assert.deepEqual(sent.map((entry) => entry.options), [{ triggerTurn: false }], "the held notice is stored without a direct turn");
|
|
6744
7663
|
assert.deepEqual(delivery, ["custom:gentle-jobs.notice", "user"], "one wake follows the held notice");
|
|
6745
7664
|
} finally {
|
|
@@ -6808,7 +7727,8 @@ test("monitor delivers line events to an idle parent with one wake, and reports
|
|
|
6808
7727
|
assert.match(renderers.get("gentle-jobs.notice")!(events[0]!.message, { expanded: true }, plainTheme).render(70).map(stripAnsi).join("\n"), /unit: fail/);
|
|
6809
7728
|
jobs.runs[0]!.onData(Buffer.from("e2e: pass\n"));
|
|
6810
7729
|
jobs.runs[0]!.exit(1);
|
|
6811
|
-
|
|
7730
|
+
// Pending lines and the end notice follow the job log close, which can outlast a fixed wait under load.
|
|
7731
|
+
await eventually(() => sent.filter((entry) => entry.message.customType === "gentle-jobs.notice").length >= 3, "the closed monitor log must deliver its pending lines and end notice");
|
|
6812
7732
|
const contents = sent.filter((entry) => entry.message.customType === "gentle-jobs.notice").map((entry) => String(entry.message.content));
|
|
6813
7733
|
assert.equal(contents.length, 3, "pending lines are delivered before the end notice");
|
|
6814
7734
|
assert.match(contents[1]!, /reported 1 new line:\ne2e: pass/);
|
|
@@ -6931,6 +7851,160 @@ test("a human stop of a monitor from /gentle:jobs delivers its pending lines, th
|
|
|
6931
7851
|
}
|
|
6932
7852
|
});
|
|
6933
7853
|
|
|
7854
|
+
// gentle-shell#626: the herdr pane stays busy while owned background subagents
|
|
7855
|
+
// of the active session run, even after the parent itself settles. Mirrors the
|
|
7856
|
+
// pi-subagents edge-triggered herdr producer exactly.
|
|
7857
|
+
const busyEvents = (h: ReturnType<typeof fakePi>) => h.events.filter((entry) => entry.name === "herdr:busy").map((entry) => entry.data);
|
|
7858
|
+
|
|
7859
|
+
test("herdr:busy follows owned background subagents, not the parent run", async () => {
|
|
7860
|
+
const h = fakePi();
|
|
7861
|
+
const runtime = deps();
|
|
7862
|
+
gentleAgents(h.pi, {}, runtime.deps);
|
|
7863
|
+
const { ctx } = fakeContext();
|
|
7864
|
+
await h.fire("session_start", ctx);
|
|
7865
|
+
assert.deepEqual(busyEvents(h), [], "no busy event before any subagent work");
|
|
7866
|
+
|
|
7867
|
+
await h.tools.get("subagent_run")!.execute("busy-a", { agent: "explore", task: "Map one", mode: "background" }, undefined, undefined, ctx);
|
|
7868
|
+
await tick();
|
|
7869
|
+
assert.deepEqual(busyEvents(h), [{ active: true, label: "1 subagent running" }]);
|
|
7870
|
+
|
|
7871
|
+
await h.tools.get("subagent_run")!.execute("busy-b", { agent: "explore", task: "Map two", mode: "background" }, undefined, undefined, ctx);
|
|
7872
|
+
await tick();
|
|
7873
|
+
assert.deepEqual(busyEvents(h), [
|
|
7874
|
+
{ active: true, label: "1 subagent running" },
|
|
7875
|
+
{ active: false },
|
|
7876
|
+
{ active: true, label: "2 subagents running" },
|
|
7877
|
+
], "a label change emits the lower before the raise, in one step");
|
|
7878
|
+
|
|
7879
|
+
// The parent's own run settling must not drop busy while children still run.
|
|
7880
|
+
const raised = busyEvents(h).length;
|
|
7881
|
+
await h.fire("agent_start", ctx);
|
|
7882
|
+
await h.fire("agent_settled", ctx);
|
|
7883
|
+
assert.equal(busyEvents(h).length, raised, "an idle parent never lowers busy while a child still runs");
|
|
7884
|
+
|
|
7885
|
+
runtime.children[0].emit({ type: "agent_end", messages: [{ role: "assistant", content: [{ type: "text", text: "one" }] }] });
|
|
7886
|
+
runtime.children[0].emit({ type: "agent_settled" });
|
|
7887
|
+
await tick();
|
|
7888
|
+
assert.deepEqual(busyEvents(h).slice(-2), [{ active: false }, { active: true, label: "1 subagent running" }], "the first settlement relabels with lower then raise");
|
|
7889
|
+
|
|
7890
|
+
runtime.children[1].emit({ type: "agent_end", messages: [{ role: "assistant", content: [{ type: "text", text: "two" }] }] });
|
|
7891
|
+
runtime.children[1].emit({ type: "agent_settled" });
|
|
7892
|
+
await tick();
|
|
7893
|
+
assert.deepEqual(busyEvents(h).at(-1), { active: false }, "the last settlement lowers busy exactly once");
|
|
7894
|
+
const lowered = busyEvents(h).length;
|
|
7895
|
+
await tick();
|
|
7896
|
+
assert.equal(busyEvents(h).length, lowered, "no stale busy after the last settlement");
|
|
7897
|
+
});
|
|
7898
|
+
|
|
7899
|
+
test("herdr:busy lowers on failure and cancellation", async () => {
|
|
7900
|
+
const h = fakePi();
|
|
7901
|
+
const runtime = deps();
|
|
7902
|
+
gentleAgents(h.pi, {}, runtime.deps);
|
|
7903
|
+
const { ctx } = fakeContext();
|
|
7904
|
+
await h.fire("session_start", ctx);
|
|
7905
|
+
|
|
7906
|
+
await h.tools.get("subagent_run")!.execute("busy-fail", { agent: "explore", task: "Fail", mode: "background" }, undefined, undefined, ctx);
|
|
7907
|
+
await tick();
|
|
7908
|
+
assert.deepEqual(busyEvents(h), [{ active: true, label: "1 subagent running" }]);
|
|
7909
|
+
runtime.children[0].fail("boom");
|
|
7910
|
+
await tick();
|
|
7911
|
+
assert.deepEqual(busyEvents(h), [{ active: true, label: "1 subagent running" }, { active: false }], "a failed child lowers busy");
|
|
7912
|
+
|
|
7913
|
+
const cancelled = await h.tools.get("subagent_run")!.execute("busy-cancel", { agent: "explore", task: "Cancel me", mode: "background" }, undefined, undefined, ctx);
|
|
7914
|
+
await tick();
|
|
7915
|
+
assert.deepEqual(busyEvents(h).at(-1), { active: true, label: "1 subagent running" });
|
|
7916
|
+
const cancelId = (cancelled.details.gentleAgents as { taskId: string }).taskId;
|
|
7917
|
+
await h.tools.get("subagent_cancel")!.execute("busy-stop", { task_id: cancelId }, undefined, undefined, ctx);
|
|
7918
|
+
await tick();
|
|
7919
|
+
assert.deepEqual(busyEvents(h).at(-1), { active: false }, "a cancelled task lowers busy");
|
|
7920
|
+
});
|
|
7921
|
+
|
|
7922
|
+
test("herdr:busy restores on session_start and lowers on session_shutdown", async () => {
|
|
7923
|
+
const h = fakePi();
|
|
7924
|
+
const runtime = deps();
|
|
7925
|
+
gentleAgents(h.pi, {}, runtime.deps);
|
|
7926
|
+
const { ctx } = fakeContext();
|
|
7927
|
+
await h.fire("session_start", ctx);
|
|
7928
|
+
|
|
7929
|
+
await h.tools.get("subagent_run")!.execute("busy-edge", { agent: "explore", task: "Map", mode: "background" }, undefined, undefined, ctx);
|
|
7930
|
+
await tick();
|
|
7931
|
+
assert.deepEqual(busyEvents(h), [{ active: true, label: "1 subagent running" }]);
|
|
7932
|
+
|
|
7933
|
+
// A reload of the same session keeps the pane busy: the consumer already
|
|
7934
|
+
// holds the raise, so the unchanged label dedups to nothing.
|
|
7935
|
+
await h.fire("session_start", ctx, { reason: "reload" });
|
|
7936
|
+
assert.deepEqual(busyEvents(h), [{ active: true, label: "1 subagent running" }], "reload neither duplicates nor drops the raise");
|
|
7937
|
+
|
|
7938
|
+
// Switching to a session that owns no running work lowers busy.
|
|
7939
|
+
const other = fakeContext();
|
|
7940
|
+
other.ctx.sessionManager = { ...other.ctx.sessionManager, getSessionId: () => "s2" };
|
|
7941
|
+
await h.fire("session_start", other.ctx, { reason: "new" });
|
|
7942
|
+
assert.deepEqual(busyEvents(h).at(-1), { active: false }, "a session without owned running work is not busy");
|
|
7943
|
+
|
|
7944
|
+
// Resuming the original session restores busy from its still-running child.
|
|
7945
|
+
await h.fire("session_start", ctx, { reason: "resume" });
|
|
7946
|
+
assert.deepEqual(busyEvents(h).at(-1), { active: true, label: "1 subagent running" }, "session_start restores busy for owned running work");
|
|
7947
|
+
|
|
7948
|
+
await h.fire("session_shutdown", ctx);
|
|
7949
|
+
assert.deepEqual(busyEvents(h).at(-1), { active: false }, "session_shutdown lowers busy");
|
|
7950
|
+
const lowered = busyEvents(h).length;
|
|
7951
|
+
await tick();
|
|
7952
|
+
assert.equal(busyEvents(h).length, lowered, "no busy event trails the shutdown lower");
|
|
7953
|
+
});
|
|
7954
|
+
|
|
7955
|
+
test("herdr:busy ignores a disk-restored running task via the ownership filter", async () => {
|
|
7956
|
+
const h = fakePi();
|
|
7957
|
+
const runtime = deps();
|
|
7958
|
+
const historyHome = join(root, "busy-restore-history-home");
|
|
7959
|
+
const restored: TaskRecord = { id: "busy-restored", agent: "explore", mode: "background", prompt: "p", label: "p", cwd, parentSessionId: "busy-restore-session", status: TASK_STATUS.RUNNING, createdAt: 1, startedAt: 1, endedAt: null, model: "m", thinking: undefined, sessionPath: null, error: null, result: null, lastStep: "running", lastActivityAt: 1, turns: 1, toolCalls: 0, tokens: 0, cost: 0 };
|
|
7960
|
+
await saveTask(historyDir(historyHome), restored, emptyThread());
|
|
7961
|
+
runtime.deps.home = historyHome;
|
|
7962
|
+
gentleAgents(h.pi, {}, runtime.deps);
|
|
7963
|
+
const { ctx } = fakeContext();
|
|
7964
|
+
ctx.sessionManager.getSessionId = () => "busy-restore-session";
|
|
7965
|
+
await h.fire("session_start", ctx, { reason: "resume" });
|
|
7966
|
+
|
|
7967
|
+
// Pull the task from disk into the store: it lands in restoredTaskIds,
|
|
7968
|
+
// never ownedTaskIds, so the pane must stay quiet -- it is not live work
|
|
7969
|
+
// this runtime owns, and counting it would report busy for work that no
|
|
7970
|
+
// longer exists.
|
|
7971
|
+
await h.tools.get("subagent_status")!.execute("status", { task_id: "busy-restored" }, undefined, undefined, ctx);
|
|
7972
|
+
await tick();
|
|
7973
|
+
assert.deepEqual(busyEvents(h), [], "a disk-restored running task never raises busy");
|
|
7974
|
+
await h.fire("session_shutdown", ctx);
|
|
7975
|
+
});
|
|
7976
|
+
|
|
7977
|
+
test("herdr:busy treats an empty session id as no active session", async () => {
|
|
7978
|
+
const h = fakePi();
|
|
7979
|
+
const runtime = deps();
|
|
7980
|
+
gentleAgents(h.pi, {}, runtime.deps);
|
|
7981
|
+
const { ctx } = fakeContext();
|
|
7982
|
+
ctx.sessionManager.getSessionId = () => "";
|
|
7983
|
+
await h.fire("session_start", ctx);
|
|
7984
|
+
|
|
7985
|
+
// An empty session id has no session profile authority, so the launch is
|
|
7986
|
+
// rejected before it becomes owned work and busy is never raised.
|
|
7987
|
+
await assert.rejects(
|
|
7988
|
+
h.tools.get("subagent_run")!.execute("busy-blank", { agent: "explore", task: "Map", mode: "background" }, undefined, undefined, ctx),
|
|
7989
|
+
/Session profile authority unavailable/,
|
|
7990
|
+
);
|
|
7991
|
+
await tick();
|
|
7992
|
+
assert.deepEqual(busyEvents(h), [], "an empty session id never raises busy");
|
|
7993
|
+
|
|
7994
|
+
// A busy state raised by a real session must lower once the active session
|
|
7995
|
+
// id becomes empty, even though the blank session still owns running work.
|
|
7996
|
+
const real = fakeContext();
|
|
7997
|
+
await h.fire("session_start", real.ctx, { reason: "new" });
|
|
7998
|
+
await h.tools.get("subagent_run")!.execute("busy-real", { agent: "explore", task: "Map", mode: "background" }, undefined, undefined, real.ctx);
|
|
7999
|
+
await tick();
|
|
8000
|
+
assert.deepEqual(busyEvents(h).at(-1), { active: true, label: "1 subagent running" });
|
|
8001
|
+
await h.fire("session_start", ctx, { reason: "resume" });
|
|
8002
|
+
assert.deepEqual(busyEvents(h).at(-1), { active: false }, "an empty session id lowers already-raised busy");
|
|
8003
|
+
const lowered = busyEvents(h).length;
|
|
8004
|
+
await tick();
|
|
8005
|
+
assert.equal(busyEvents(h).length, lowered, "an empty session id never re-raises busy");
|
|
8006
|
+
});
|
|
8007
|
+
|
|
6934
8008
|
// Harness roadmap T6: todo progress reaches peers without a model turn spent on
|
|
6935
8009
|
// orchestrator_session_id, and never replaces the owner's curated fields.
|
|
6936
8010
|
test("todo progress publishes merged into the owner's curated state, only for this session", async () => {
|
|
@@ -7067,6 +8141,49 @@ test("subagent_run does not warn about a key that matches another discovered age
|
|
|
7067
8141
|
assert.equal(dialogs.filter((message) => /did not match any agent/.test(message)).length, 0, "a key naming a discovered agent is never unmatched");
|
|
7068
8142
|
});
|
|
7069
8143
|
|
|
8144
|
+
// Issue #2430: review-refuter and review-validator are provider review roles
|
|
8145
|
+
// routed by key (gentle-pi#2271), never agent files, so the launch warning must
|
|
8146
|
+
// not report them as unmatched; a real typo next to them is still named.
|
|
8147
|
+
test("subagent_run never reports provider review routing keys as unmatched", async (t) => {
|
|
8148
|
+
const child = fakePi();
|
|
8149
|
+
const runtime = deps();
|
|
8150
|
+
captureLaunches(t);
|
|
8151
|
+
gentleAgents(child.pi, {}, runtime.deps);
|
|
8152
|
+
const { ctx, dialogs } = fakeContext();
|
|
8153
|
+
ctx.sessionManager.getSessionId = () => "provider-review-roles";
|
|
8154
|
+
mkdirSync(join(cwd, ".pi"), { recursive: true });
|
|
8155
|
+
const subagents = join(cwd, ".pi", "subagents.json");
|
|
8156
|
+
t.after(() => rmSync(subagents, { force: true }));
|
|
8157
|
+
writeFileSync(subagents, `${JSON.stringify({ model_profiles: { "review-refuter": { model: "openai/alpha" }, "review-validator": { model: "openai/beta" }, explor: { model: "openai/gamma" } } })}\n`);
|
|
8158
|
+
await child.fire("session_start", ctx);
|
|
8159
|
+
await child.tools.get("subagent_run")!.execute("run", { agent: "explore", task: "first", mode: "background" }, undefined, undefined, ctx);
|
|
8160
|
+
await tick();
|
|
8161
|
+
const warnings = dialogs.filter((message) => /did not match any agent/.test(message));
|
|
8162
|
+
assert.equal(warnings.length, 1, "the typo is still reported once");
|
|
8163
|
+
assert.match(warnings[0]!, /"explor" did not match any agent and was ignored\./);
|
|
8164
|
+
assert.doesNotMatch(warnings[0]!, /review-refuter|review-validator/);
|
|
8165
|
+
});
|
|
8166
|
+
|
|
8167
|
+
// A profile bound with "Use in this session" keeps the reserved `orchestrator`
|
|
8168
|
+
// key (the parent's own model); it is never a subagent routing key, so the
|
|
8169
|
+
// launch warning must not report it, while a real typo next to it still is.
|
|
8170
|
+
test("subagent_run never reports the bound profile's orchestrator key as unmatched", async (t) => {
|
|
8171
|
+
t.after(() => resetSessionProfileBindingsForTesting());
|
|
8172
|
+
const child = fakePi();
|
|
8173
|
+
const runtime = deps();
|
|
8174
|
+
captureLaunches(t);
|
|
8175
|
+
gentleAgents(child.pi, {}, runtime.deps);
|
|
8176
|
+
const { ctx, dialogs } = fakeContext();
|
|
8177
|
+
bindSessionProfile("s1", "team", { orchestrator: { model: "openai/alpha" }, explore: { model: "openai/beta" }, explor: { model: "openai/gamma" } });
|
|
8178
|
+
await child.fire("session_start", ctx);
|
|
8179
|
+
await child.tools.get("subagent_run")!.execute("run", { agent: "explore", task: "first", mode: "background" }, undefined, undefined, ctx);
|
|
8180
|
+
await tick();
|
|
8181
|
+
const warnings = dialogs.filter((message) => /did not match any agent and was ignored/.test(message));
|
|
8182
|
+
assert.equal(warnings.length, 1, "the typo is still reported once");
|
|
8183
|
+
assert.match(warnings[0]!, /"explor" did not match any agent and was ignored\./);
|
|
8184
|
+
assert.doesNotMatch(warnings[0]!, /"orchestrator"/, "the reserved orchestrator key is never a subagent key");
|
|
8185
|
+
});
|
|
8186
|
+
|
|
7070
8187
|
// Issue #2400: a model_profiles key that matches no discovered agent and has no
|
|
7071
8188
|
// did-you-mean suggestion (a typo such as `explor`) was still silent, because
|
|
7072
8189
|
// the launch warning only named keys suggesting the launched agent. The first
|
|
@@ -7124,3 +8241,339 @@ test("a matched model_profiles key routes the task request model end to end", as
|
|
|
7124
8241
|
assert.equal(captures[0]!.request.thinking, "high");
|
|
7125
8242
|
assert.equal(captures[0]!.request.modelSource, "profile");
|
|
7126
8243
|
});
|
|
8244
|
+
|
|
8245
|
+
test("an agent asking the user exposes an alert row for the panel editor", async () => {
|
|
8246
|
+
const { pi, tools, fire } = fakePi();
|
|
8247
|
+
const harness = deps();
|
|
8248
|
+
gentleAgents(pi, {}, harness.deps);
|
|
8249
|
+
const terminalTui = { requestRender() {}, terminal: { columns: 160, rows: 40 } };
|
|
8250
|
+
// The relayed dialog stays open: the user has not answered yet.
|
|
8251
|
+
const { ctx, widgets } = fakeContext(terminalTui, undefined, undefined, undefined, () => new Promise<string | undefined>(() => {}));
|
|
8252
|
+
await fire("session_start", ctx);
|
|
8253
|
+
// Only a task-mode child can ask the user; a background child's dialog is dismissed.
|
|
8254
|
+
void tools.get("subagent_run")!.execute("ask", { agent: "explore", task: "Ask once" }, undefined, undefined, ctx);
|
|
8255
|
+
await tick();
|
|
8256
|
+
// The rail part supplies the alert rows; the panel editor draws them above its rule.
|
|
8257
|
+
widgets.get("gentle-agents")!(terminalTui, plainTheme);
|
|
8258
|
+
const alert = () => ((sidebarState(terminalTui as unknown as TUI).parts.get("agents") as { alert?(width: number): string[] }).alert?.(100) ?? []).map(stripAnsi);
|
|
8259
|
+
assert.deepEqual(alert(), [], "a running agent needs no alert");
|
|
8260
|
+
// A child question relayed to this session's UI is what makes a task wait for the user.
|
|
8261
|
+
harness.children[0].emit({ type: "extension_ui_request", id: "u1", method: "select", title: "Which file?", options: ["a.ts", "b.ts"] });
|
|
8262
|
+
await tick();
|
|
8263
|
+
assert.match(alert()[0]!, /^ \? explore asked: Which file\? +\/gentle:agents $/, "the alert row names the asking agent and its question");
|
|
8264
|
+
});
|
|
8265
|
+
|
|
8266
|
+
test("a subagent launched under a profile carries its fallback chain, and a quota error switches it with a notice and a session entry", async () => {
|
|
8267
|
+
const agentHome = join(root, "fallback-launch", "agent");
|
|
8268
|
+
const config = join(root, "fallback-launch", "config");
|
|
8269
|
+
mkdirSync(join(agentHome, "agents"), { recursive: true });
|
|
8270
|
+
mkdirSync(config, { recursive: true });
|
|
8271
|
+
writeFileSync(join(agentHome, "agents", "fallbacker.md"), "---\ndescription: fallback fixture\n---\nMap things.");
|
|
8272
|
+
writeFileSync(join(agentHome, "subagents.json"), JSON.stringify({ default_model: "fbx/primary-model" }));
|
|
8273
|
+
writeFileSync(join(config, "profiles.json"), JSON.stringify({ kind: "gentle-pi.agent_model_profiles", version: 1, active: "home", profiles: { home: {} } }));
|
|
8274
|
+
writeFileSync(join(config, "profile-fallbacks.json"), JSON.stringify({ kind: "gentle-pi.profile_model_fallbacks", version: 1, profiles: { home: { "*": [{ model: "fby/second-model", thinking: "low" }] } } }));
|
|
8275
|
+
const harness = deps();
|
|
8276
|
+
const { home: _home, env: _env, ...overrides } = harness.deps;
|
|
8277
|
+
const { pi, tools, fire, entries } = fakePi();
|
|
8278
|
+
gentleAgents(pi, { GENTLE_PI_AGENT_HOME: agentHome, GENTLE_PI_CONFIG_HOME: config }, overrides);
|
|
8279
|
+
const { ctx, dialogs } = fakeContext();
|
|
8280
|
+
await fire("session_start", ctx);
|
|
8281
|
+
await tools.get("subagent_run")!.execute("fb", { agent: "fallbacker", task: "Map", mode: "background" }, undefined, undefined, ctx);
|
|
8282
|
+
await tick();
|
|
8283
|
+
try {
|
|
8284
|
+
const child = harness.children[0]!;
|
|
8285
|
+
child.emit({ type: "agent_end", messages: [{ role: "assistant", content: [], stopReason: "error", errorMessage: "429 insufficient_quota: usage limit reached" }] });
|
|
8286
|
+
child.emit({ type: "agent_settled" });
|
|
8287
|
+
await tick(); await tick(); await tick();
|
|
8288
|
+
assert.deepEqual(child.written.filter((command) => command.type === "set_model").map((command) => `${command.provider}/${command.modelId}`), ["fby/second-model"]);
|
|
8289
|
+
assert.ok(dialogs.some((line) => /fallbacker: fbx\/primary-model hit its usage limit; continuing on fby\/second-model/.test(line)), dialogs.join("\n"));
|
|
8290
|
+
const recorded = entries.filter((entry) => entry.customType === "gentle-pi.model-fallback/v1").map((entry) => entry.data as Record<string, unknown>);
|
|
8291
|
+
assert.equal(recorded.length, 1);
|
|
8292
|
+
assert.deepEqual({ agent: recorded[0]!.agent, from: recorded[0]!.from, to: recorded[0]!.to, category: recorded[0]!.category }, { agent: "fallbacker", from: "fbx/primary-model", to: "fby/second-model", category: "quota" });
|
|
8293
|
+
} finally {
|
|
8294
|
+
await fire("session_shutdown", ctx);
|
|
8295
|
+
await tick();
|
|
8296
|
+
}
|
|
8297
|
+
});
|
|
8298
|
+
|
|
8299
|
+
test("the orchestrator's usage limit moves the session to the profile's orchestrator fallback and resumes; children never do it themselves", async () => {
|
|
8300
|
+
const config = join(root, "orchestrator-fallback", "config");
|
|
8301
|
+
mkdirSync(config, { recursive: true });
|
|
8302
|
+
writeFileSync(join(config, "profiles.json"), JSON.stringify({ kind: "gentle-pi.agent_model_profiles", version: 1, active: "home", profiles: { home: {} } }));
|
|
8303
|
+
writeFileSync(join(config, "profile-fallbacks.json"), JSON.stringify({ kind: "gentle-pi.profile_model_fallbacks", version: 1, profiles: { home: { orchestrator: [{ model: "orx/backup", thinking: "high" }] } } }));
|
|
8304
|
+
const catalog = new Map([["orx/main", { provider: "orx", id: "main", cost: { input: 1, output: 1, cacheRead: 0, cacheWrite: 0 } }], ["orx/backup", { provider: "orx", id: "backup", cost: { input: 3, output: 3, cacheRead: 0, cacheWrite: 0 } }]]);
|
|
8305
|
+
const run = async (env: Record<string, string>) => {
|
|
8306
|
+
const harness = deps();
|
|
8307
|
+
const { home: _home, env: _env, ...overrides } = harness.deps;
|
|
8308
|
+
const fake = fakePi();
|
|
8309
|
+
const selected: string[] = [];
|
|
8310
|
+
const levels: string[] = [];
|
|
8311
|
+
Object.assign(fake.pi, { setModel: async (model: { provider: string; id: string }) => { selected.push(`${model.provider}/${model.id}`); return true; }, setThinkingLevel: (level: string) => levels.push(level) });
|
|
8312
|
+
gentleAgents(fake.pi, { GENTLE_PI_CONFIG_HOME: config, ...env }, overrides);
|
|
8313
|
+
const { ctx, dialogs } = fakeContext();
|
|
8314
|
+
Object.assign(ctx, { model: catalog.get("orx/main"), modelRegistry: { find: (provider: string, id: string) => catalog.get(`${provider}/${id}`), getAll: () => [...catalog.values()] } });
|
|
8315
|
+
await fake.fire("session_start", ctx);
|
|
8316
|
+
await fake.fire("agent_end", ctx, { type: "agent_end", messages: [{ role: "assistant", content: [], stopReason: "error", errorMessage: "insufficient_quota: monthly usage limit reached" }] });
|
|
8317
|
+
await tick(); await tick();
|
|
8318
|
+
// Pi fires agent_end on every failed attempt and only then decides to retry: nothing moves yet.
|
|
8319
|
+
const beforeSettle = selected.length;
|
|
8320
|
+
await fake.fire("agent_settled", ctx, { type: "agent_settled", aborted: false });
|
|
8321
|
+
await tick(); await tick();
|
|
8322
|
+
await fake.fire("session_shutdown", ctx);
|
|
8323
|
+
await tick();
|
|
8324
|
+
return { selected, levels, dialogs, entries: fake.entries, userMessages: fake.userMessages, beforeSettle };
|
|
8325
|
+
};
|
|
8326
|
+
const parent = await run({});
|
|
8327
|
+
assert.equal(parent.beforeSettle, 0, "the switch waits for the run to settle, after Pi's own retries");
|
|
8328
|
+
assert.deepEqual(parent.selected, ["orx/backup"]);
|
|
8329
|
+
assert.deepEqual(parent.levels, ["high"]);
|
|
8330
|
+
assert.ok(parent.dialogs.some((line) => /orchestrator: orx\/main hit its usage limit; continuing on orx\/backup \(3\.0x the price\)/.test(line)), parent.dialogs.join("\n"));
|
|
8331
|
+
assert.equal(parent.entries.filter((entry) => entry.customType === "gentle-pi.model-fallback/v1").length, 1);
|
|
8332
|
+
assert.equal(parent.userMessages.length, 1);
|
|
8333
|
+
assert.match(String(parent.userMessages[0]!.content), /continue/i);
|
|
8334
|
+
const child = await run({ GENTLE_PI_AGENTS_CHILD: "1" });
|
|
8335
|
+
assert.deepEqual(child.selected, [], "a child leaves its fallback to the parent's runner");
|
|
8336
|
+
});
|
|
8337
|
+
|
|
8338
|
+
// Held content is released by lifecycle events (the fast path), and by a
|
|
8339
|
+
// held-only re-check that does not depend on any event: a cancelled `/tree`
|
|
8340
|
+
// summarization emits none.
|
|
8341
|
+
test("session_tree releases content held while the parent summarized a branch", async () => {
|
|
8342
|
+
const { fire, ctx, sent, userMessages, notify, setIdle, timers } = await orchestratorHost();
|
|
8343
|
+
setIdle(false);
|
|
8344
|
+
await notify("hello tree");
|
|
8345
|
+
assert.equal(sent.length, 0, "nothing is sent while the parent is busy without a run");
|
|
8346
|
+
await fire("session_tree", ctx);
|
|
8347
|
+
setIdle(true);
|
|
8348
|
+
assert.equal(timers.run(0), 1, "one deferred flush is scheduled for the tree boundary");
|
|
8349
|
+
await tick();
|
|
8350
|
+
assert.deepEqual(sent.map((entry) => entry.options), [{ triggerTurn: false }]);
|
|
8351
|
+
assert.equal(userMessages.length, 1, "one wake follows the held content");
|
|
8352
|
+
await fire("session_shutdown", ctx);
|
|
8353
|
+
});
|
|
8354
|
+
|
|
8355
|
+
test("a held-only re-check releases content when the busy state ends without any event", async () => {
|
|
8356
|
+
const { fire, ctx, sent, userMessages, notify, setIdle, timers } = await orchestratorHost();
|
|
8357
|
+
setIdle(false);
|
|
8358
|
+
await notify("hello cancelled summary");
|
|
8359
|
+
assert.equal(timers.pending(HOLD_RECHECK_MS), 1, "holding content arms exactly one re-check");
|
|
8360
|
+
assert.equal(timers.run(HOLD_RECHECK_MS), 1);
|
|
8361
|
+
assert.equal(sent.length, 0, "still busy: nothing is delivered");
|
|
8362
|
+
assert.equal(timers.pending(HOLD_RECHECK_MS), 1, "a still-busy parent keeps one re-check armed");
|
|
8363
|
+
setIdle(true);
|
|
8364
|
+
assert.equal(timers.run(HOLD_RECHECK_MS), 1);
|
|
8365
|
+
await tick();
|
|
8366
|
+
assert.deepEqual(sent.map((entry) => entry.options), [{ triggerTurn: false }]);
|
|
8367
|
+
assert.equal(userMessages.length, 1);
|
|
8368
|
+
assert.equal(timers.pending(HOLD_RECHECK_MS), 0, "the re-check stops once the content was delivered");
|
|
8369
|
+
await fire("session_shutdown", ctx);
|
|
8370
|
+
});
|
|
8371
|
+
|
|
8372
|
+
test("the held-only re-check also releases child completions and child messages", async () => {
|
|
8373
|
+
const { pi, tools, fire, sent, userMessages, setIdle } = fakePi();
|
|
8374
|
+
const harness = deps();
|
|
8375
|
+
const timers = recordTimers(harness.deps);
|
|
8376
|
+
gentleAgents(pi, {}, harness.deps);
|
|
8377
|
+
const { ctx } = fakeContext();
|
|
8378
|
+
await fire("session_start", ctx);
|
|
8379
|
+
await tools.get("subagent_run")!.execute("c1", { agent: "explore", task: "Asks while busy", mode: "background" }, undefined, undefined, ctx);
|
|
8380
|
+
await tools.get("subagent_run")!.execute("c2", { agent: "explore", task: "Ends while busy", mode: "background" }, undefined, undefined, ctx);
|
|
8381
|
+
await tick();
|
|
8382
|
+
// The runner's own clock tick shares HOLD_RECHECK_MS, so count against it.
|
|
8383
|
+
const clockTicks = timers.pending(HOLD_RECHECK_MS);
|
|
8384
|
+
setIdle(false);
|
|
8385
|
+
harness.children[0].message({ id: "q1", kind: "query", message: "Which branch?" });
|
|
8386
|
+
harness.children[1].emit({ type: "agent_end", messages: [{ role: "assistant", content: [{ type: "text", text: "done" }] }] });
|
|
8387
|
+
harness.children[1].emit({ type: "agent_settled" });
|
|
8388
|
+
await tick();
|
|
8389
|
+
assert.equal(sent.length, 0);
|
|
8390
|
+
const armed = timers.pending(HOLD_RECHECK_MS) - clockTicks;
|
|
8391
|
+
assert.equal(armed, 1, "held child content arms exactly one re-check");
|
|
8392
|
+
setIdle(true);
|
|
8393
|
+
timers.run(HOLD_RECHECK_MS);
|
|
8394
|
+
await tick();
|
|
8395
|
+
assert.equal(sent.length, 2, "the query and the completion are both delivered");
|
|
8396
|
+
assert.equal(userMessages.length, 1);
|
|
8397
|
+
assert.equal(timers.pending(HOLD_RECHECK_MS) <= clockTicks, true, "the re-check stops once the content was delivered");
|
|
8398
|
+
await fire("session_shutdown", ctx);
|
|
8399
|
+
});
|
|
8400
|
+
|
|
8401
|
+
test("a completion re-queued after a failed forward still arms the held-only re-check", async () => {
|
|
8402
|
+
const { pi, tools, fire, sent, setIdle } = fakePi();
|
|
8403
|
+
const harness = deps();
|
|
8404
|
+
const timers = recordTimers(harness.deps);
|
|
8405
|
+
gentleAgents(pi, {}, harness.deps);
|
|
8406
|
+
const { ctx } = fakeContext();
|
|
8407
|
+
await fire("session_start", ctx);
|
|
8408
|
+
await tools.get("subagent_run")!.execute("c1", { agent: "explore", task: "Fails to forward", mode: "background" }, undefined, undefined, ctx);
|
|
8409
|
+
await tick();
|
|
8410
|
+
const sendMessage = pi.sendMessage;
|
|
8411
|
+
Object.assign(pi, { sendMessage: () => { throw new Error("host busy"); } });
|
|
8412
|
+
harness.children[0].emit({ type: "agent_end", messages: [{ role: "assistant", content: [{ type: "text", text: "Requeued answer." }] }] });
|
|
8413
|
+
harness.children[0].emit({ type: "agent_settled" });
|
|
8414
|
+
await tick();
|
|
8415
|
+
assert.equal(sent.length, 0, "the idle forward failed and the completion was re-queued");
|
|
8416
|
+
Object.assign(pi, { sendMessage });
|
|
8417
|
+
// The runner's own clock tick shares HOLD_RECHECK_MS, so count against it.
|
|
8418
|
+
const clockTicks = timers.pending(HOLD_RECHECK_MS);
|
|
8419
|
+
// The bounded retry fires while the parent compacts without a run, so the
|
|
8420
|
+
// re-queued completion is held and only the re-check can release it.
|
|
8421
|
+
setIdle(false);
|
|
8422
|
+
assert.equal(timers.run(PARENT_WAKE_GRACE_MS), 1, "the idle failure armed one bounded retry");
|
|
8423
|
+
await tick();
|
|
8424
|
+
assert.equal(sent.length, 0, "still busy: nothing is delivered");
|
|
8425
|
+
assert.equal(timers.pending(HOLD_RECHECK_MS) - clockTicks, 1, "the re-queued completion arms exactly one re-check");
|
|
8426
|
+
setIdle(true);
|
|
8427
|
+
timers.run(HOLD_RECHECK_MS);
|
|
8428
|
+
await tick();
|
|
8429
|
+
const results = sent.filter((entry) => entry.message.customType === "gentle-agents.result");
|
|
8430
|
+
assert.equal(results.length, 1, "the re-check delivers the re-queued completion");
|
|
8431
|
+
assert.match(String(results[0]!.message.content), /Requeued answer\./);
|
|
8432
|
+
await fire("session_shutdown", ctx);
|
|
8433
|
+
});
|
|
8434
|
+
|
|
8435
|
+
test("no held-only re-check is armed when nothing is held", async () => {
|
|
8436
|
+
const { fire, ctx, notify, setIdle, timers } = await orchestratorHost();
|
|
8437
|
+
setIdle(false);
|
|
8438
|
+
await fire("turn_end", ctx);
|
|
8439
|
+
await fire("session_tree", ctx);
|
|
8440
|
+
timers.run(0);
|
|
8441
|
+
assert.equal(timers.pending(HOLD_RECHECK_MS), 0, "a busy parent with nothing held is never polled");
|
|
8442
|
+
setIdle(true);
|
|
8443
|
+
await notify("hello idle");
|
|
8444
|
+
await tick();
|
|
8445
|
+
assert.equal(timers.pending(HOLD_RECHECK_MS), 0, "an idle parent is never polled");
|
|
8446
|
+
await fire("agent_start", ctx);
|
|
8447
|
+
await notify("hello run");
|
|
8448
|
+
await tick();
|
|
8449
|
+
assert.equal(timers.pending(HOLD_RECHECK_MS), 0, "a running parent is never polled");
|
|
8450
|
+
await fire("session_shutdown", ctx);
|
|
8451
|
+
});
|
|
8452
|
+
|
|
8453
|
+
test("a boundary flush that delivers held content cancels the re-check", async () => {
|
|
8454
|
+
const { fire, ctx, sent, notify, setIdle, timers } = await orchestratorHost();
|
|
8455
|
+
setIdle(false);
|
|
8456
|
+
await notify("hello boundary");
|
|
8457
|
+
assert.equal(timers.pending(HOLD_RECHECK_MS), 1);
|
|
8458
|
+
await fire("agent_start", ctx);
|
|
8459
|
+
await fire("turn_end", ctx);
|
|
8460
|
+
assert.equal(sent.length, 1, "the boundary flush delivered the held message");
|
|
8461
|
+
assert.equal(timers.pending(HOLD_RECHECK_MS), 0, "nothing is left to re-check");
|
|
8462
|
+
await fire("session_shutdown", ctx);
|
|
8463
|
+
});
|
|
8464
|
+
|
|
8465
|
+
test("a session change cancels the held-only re-check and drops the held content", async () => {
|
|
8466
|
+
const { fire, ctx, sent, notify, setIdle, timers } = await orchestratorHost();
|
|
8467
|
+
setIdle(false);
|
|
8468
|
+
await notify("hello replaced");
|
|
8469
|
+
assert.equal(timers.pending(HOLD_RECHECK_MS), 1);
|
|
8470
|
+
await fire("session_start", fakeContext().ctx);
|
|
8471
|
+
assert.equal(timers.pending(HOLD_RECHECK_MS), 0, "the old session's re-check is cancelled");
|
|
8472
|
+
setIdle(true);
|
|
8473
|
+
timers.run(HOLD_RECHECK_MS);
|
|
8474
|
+
await tick();
|
|
8475
|
+
assert.equal(sent.length, 0, "the old session's message is not replayed into the new one");
|
|
8476
|
+
await fire("session_shutdown", ctx);
|
|
8477
|
+
});
|
|
8478
|
+
|
|
8479
|
+
// A user prompt is "starting" from `input` until `before_agent_start`, while
|
|
8480
|
+
// the host still reports idle. A wake dispatched in that window races the
|
|
8481
|
+
// user's prompt into Agent.prompt().
|
|
8482
|
+
test("content stored while a user prompt is starting sends no wake and rides that prompt's run", async () => {
|
|
8483
|
+
const { fire, ctx, sent, userMessages, notify, timers } = await orchestratorHost();
|
|
8484
|
+
await fire("input", ctx, { type: "input", text: "hi", source: "interactive" });
|
|
8485
|
+
assert.equal(timers.pending(INPUT_PROMPT_GRACE_MS), 1, "the starting prompt is bounded by its own grace");
|
|
8486
|
+
await notify("hello starting");
|
|
8487
|
+
await tick();
|
|
8488
|
+
assert.deepEqual(sent.map((entry) => entry.options), [{ triggerTurn: false }], "the message is stored");
|
|
8489
|
+
assert.equal(userMessages.length, 0, "no wake races the starting prompt");
|
|
8490
|
+
await fire("before_agent_start", ctx, { prompt: "hi" });
|
|
8491
|
+
await fire("agent_start", ctx);
|
|
8492
|
+
assert.equal(timers.pending(INPUT_PROMPT_GRACE_MS), 0);
|
|
8493
|
+
assert.equal(timers.pending(PARENT_WAKE_GRACE_MS), 0);
|
|
8494
|
+
await fire("agent_settled", ctx);
|
|
8495
|
+
await tick();
|
|
8496
|
+
assert.equal(userMessages.length, 0, "the run that started carried the content, so no wake is owed");
|
|
8497
|
+
await fire("session_shutdown", ctx);
|
|
8498
|
+
});
|
|
8499
|
+
|
|
8500
|
+
test("an input that never starts a run lets the owed wake go out after INPUT_PROMPT_GRACE_MS", async () => {
|
|
8501
|
+
const { fire, ctx, userMessages, notify, timers } = await orchestratorHost();
|
|
8502
|
+
await fire("input", ctx, { type: "input", text: "handled elsewhere", source: "interactive" });
|
|
8503
|
+
await notify("hello expired");
|
|
8504
|
+
await tick();
|
|
8505
|
+
assert.equal(userMessages.length, 0);
|
|
8506
|
+
assert.equal(timers.run(INPUT_PROMPT_GRACE_MS), 1);
|
|
8507
|
+
await tick();
|
|
8508
|
+
assert.equal(userMessages.length, 1, "the owed wake is sent once the starting state expires");
|
|
8509
|
+
await fire("session_shutdown", ctx);
|
|
8510
|
+
});
|
|
8511
|
+
|
|
8512
|
+
// A dispatched wake is itself a prompt: it reaches `input` too. That must not
|
|
8513
|
+
// shorten the wake's own PARENT_WAKE_GRACE_MS window to INPUT_PROMPT_GRACE_MS,
|
|
8514
|
+
// or content arriving while the wake is still in its pre-run phase would send
|
|
8515
|
+
// a second wake that races the first into Agent.prompt().
|
|
8516
|
+
test("the dispatched wake's own input does not shorten its start window", async () => {
|
|
8517
|
+
const { fire, ctx, userMessages, notify, timers } = await orchestratorHost();
|
|
8518
|
+
await notify("first");
|
|
8519
|
+
await tick();
|
|
8520
|
+
assert.equal(userMessages.length, 1, "the idle wake is dispatched");
|
|
8521
|
+
await fire("input", ctx, { type: "input", text: String(userMessages[0]!.content), source: "extension" });
|
|
8522
|
+
await notify("second");
|
|
8523
|
+
await tick();
|
|
8524
|
+
timers.run(INPUT_PROMPT_GRACE_MS);
|
|
8525
|
+
await tick();
|
|
8526
|
+
assert.equal(userMessages.length, 1, "no second wake while the first is still starting");
|
|
8527
|
+
assert.equal(timers.pending(PARENT_WAKE_GRACE_MS), 1, "the wake keeps its own start window");
|
|
8528
|
+
await fire("session_shutdown", ctx);
|
|
8529
|
+
});
|
|
8530
|
+
|
|
8531
|
+
test("an input during a run or with a streaming behavior changes nothing", async () => {
|
|
8532
|
+
const { fire, ctx, userMessages, notify, timers } = await orchestratorHost();
|
|
8533
|
+
await fire("input", ctx, { type: "input", text: "queued", source: "interactive", streamingBehavior: "steer" });
|
|
8534
|
+
assert.equal(timers.pending(INPUT_PROMPT_GRACE_MS), 0, "a queued input is not a starting prompt");
|
|
8535
|
+
await notify("hello idle");
|
|
8536
|
+
await tick();
|
|
8537
|
+
assert.equal(userMessages.length, 1, "the idle wake is unaffected");
|
|
8538
|
+
await fire("agent_start", ctx);
|
|
8539
|
+
await fire("input", ctx, { type: "input", text: "mid-run", source: "interactive" });
|
|
8540
|
+
assert.equal(timers.pending(INPUT_PROMPT_GRACE_MS), 0, "an input during a run is not a starting prompt");
|
|
8541
|
+
await fire("session_shutdown", ctx);
|
|
8542
|
+
});
|
|
8543
|
+
|
|
8544
|
+
// A job notice is held content too: one stored while the parent is busy
|
|
8545
|
+
// without a run (a cancelled `/tree` summarization emits no event) must arm the
|
|
8546
|
+
// held-only re-check like any other held content.
|
|
8547
|
+
test("a job notice held for a parent busy without a run is delivered by the held-only re-check", async () => {
|
|
8548
|
+
const { pi, tools, fire, sent, userMessages, setIdle } = fakePi();
|
|
8549
|
+
const jobs = fakeJobShell();
|
|
8550
|
+
const harness = deps();
|
|
8551
|
+
const timers = recordTimers(harness.deps);
|
|
8552
|
+
gentleAgents(pi, {}, { ...harness.deps, jobShell: jobs.shell, jobOutputDir: () => jobs.dir });
|
|
8553
|
+
const { ctx } = fakeContext();
|
|
8554
|
+
try {
|
|
8555
|
+
await fire("session_start", ctx);
|
|
8556
|
+
await tools.get("bash_background")!.execute("b1", { command: "make build" }, undefined, undefined, ctx);
|
|
8557
|
+
// The runner's own clock tick shares HOLD_RECHECK_MS, so count against it.
|
|
8558
|
+
const clockTicks = timers.pending(HOLD_RECHECK_MS);
|
|
8559
|
+
setIdle(false);
|
|
8560
|
+
jobs.runs[0]!.exit(0);
|
|
8561
|
+
await jobIo();
|
|
8562
|
+
assert.equal(sent.length, 0, "a parent busy without a run gets nothing yet");
|
|
8563
|
+
// The notice arms the re-check when the job settles, which can outlast a fixed wait under load.
|
|
8564
|
+
await eventually(() => timers.pending(HOLD_RECHECK_MS) > clockTicks, "the held job notice arms the re-check once it settles");
|
|
8565
|
+
assert.equal(timers.pending(HOLD_RECHECK_MS) - clockTicks, 1, "the held job notice arms exactly one re-check");
|
|
8566
|
+
setIdle(true);
|
|
8567
|
+
timers.run(HOLD_RECHECK_MS);
|
|
8568
|
+
await tick();
|
|
8569
|
+
const notices = sent.filter((entry) => entry.message.customType === "gentle-jobs.notice");
|
|
8570
|
+
assert.equal(notices.length, 1, "the re-check delivers the held job notice");
|
|
8571
|
+
assert.deepEqual(notices[0]!.options, { triggerTurn: false });
|
|
8572
|
+
assert.match(String(notices[0]!.message.content), /job-1 \("make build"\) exited with code 0/);
|
|
8573
|
+
assert.equal(userMessages.length, 1, "one wake follows the notice");
|
|
8574
|
+
assert.equal(timers.pending(HOLD_RECHECK_MS) <= clockTicks, true, "the re-check stops once the notice was delivered");
|
|
8575
|
+
} finally {
|
|
8576
|
+
await fire("session_shutdown", ctx);
|
|
8577
|
+
jobs.cleanup();
|
|
8578
|
+
}
|
|
8579
|
+
});
|