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
package/lib/agents-runner.ts
CHANGED
|
@@ -1,18 +1,21 @@
|
|
|
1
|
+
import { pickModel, sharedCooldown, shouldFallBack, type ModelCooldown } from "./model-fallback-policy.ts";
|
|
2
|
+
import type { FallbackChain } from "./model-fallback-store.ts";
|
|
3
|
+
import { fallbackContinuePrompt } from "./model-fallback-notice.ts";
|
|
1
4
|
import { isSessionChangeEvidence, type SessionChangeEvidence } from "./session-changes.ts";
|
|
2
|
-
import { chmodSync, existsSync, mkdtempSync, realpathSync, rmSync, writeFileSync } from "node:fs";
|
|
5
|
+
import { chmodSync, existsSync, mkdtempSync, readFileSync, realpathSync, rmSync, writeFileSync } from "node:fs";
|
|
3
6
|
import { DefaultPackageManager, SettingsManager } from "@earendil-works/pi-coding-agent";
|
|
4
7
|
import { tmpdir, userInfo } from "node:os";
|
|
5
|
-
import { isAbsolute, join, resolve } from "node:path";
|
|
8
|
+
import { dirname, isAbsolute, join, resolve, win32 } from "node:path";
|
|
6
9
|
import { Duplex, type Readable, type Writable } from "node:stream";
|
|
7
10
|
import { stripVTControlCharacters } from "node:util";
|
|
8
11
|
import { withoutInteractiveHost } from "./rpc-host.ts";
|
|
9
12
|
import { gentlePiConfigHome } from "./agent-home.ts";
|
|
10
13
|
import { resolveBackgroundSubagentsPolicy } from "./background-subagents-policy.ts";
|
|
11
14
|
import { childPackageExtensionArgs } from "./child-package-injection.ts";
|
|
12
|
-
import { AGENT_MODE, formatModelRef, type AgentDefinition, type AgentMode, type ModelRef } from "./agents-config.ts";
|
|
13
|
-
import { CHILD_QUERY_MAX_INFLIGHT, CHILD_QUERY_TIMEOUT_MS, parseChildFrame, validChildMessage, validChildQueryId } from "./agents-messaging.ts";
|
|
15
|
+
import { AGENT_MODE, formatModelRef, parseModelRef, type AgentDefinition, type AgentMode, type ModelRef } from "./agents-config.ts";
|
|
16
|
+
import { CHILD_QUERY_MAX_INFLIGHT, CHILD_QUERY_TIMEOUT_MS, parseChildFrame, parseChildJobState, validChildMessage, validChildQueryId } from "./agents-messaging.ts";
|
|
14
17
|
import { ParentStandingReviewPermissionBroker } from "./review-session-standing-permission-ipc.ts";
|
|
15
|
-
import { isFinished, normalizeRpcEvent, ToolArgumentProgress, TASK_EVENT, TASK_STATUS, taskLabel, type AskRequest, type ChildResponseObservation, type TaskRecord, type TaskStore } from "./agents-protocol.ts";
|
|
18
|
+
import { isFinished, normalizeRpcEvent, ToolArgumentProgress, TASK_EVENT, TASK_STATUS, taskLabel, type AskRequest, type ChildResponseObservation, type TaskRecord, type TaskStore, type TerminalErrorCategory } from "./agents-protocol.ts";
|
|
16
19
|
import { WriterSurfaceRegistry, writerSurfaceConflictMessage } from "./writer-surfaces.ts";
|
|
17
20
|
import { holdSubagentScratch, releaseSubagentScratch, SUBAGENT_SCRATCH_PREFIX } from "./session-scratch.ts";
|
|
18
21
|
|
|
@@ -64,6 +67,8 @@ export interface RunnerDeps {
|
|
|
64
67
|
pi: PiCommand;
|
|
65
68
|
resolvePi?(): PiCommand;
|
|
66
69
|
process?: ProcessControl;
|
|
70
|
+
/** Models that recently ran out; the process-wide registry when absent. */
|
|
71
|
+
cooldown?: ModelCooldown;
|
|
67
72
|
}
|
|
68
73
|
|
|
69
74
|
export interface RunnerLimits {
|
|
@@ -74,6 +79,8 @@ export interface RunnerLimits {
|
|
|
74
79
|
toolStallTimeoutMs?: number;
|
|
75
80
|
// Bounded asynchronous cleanup window allowed after settlement before escalating to SIGTERM/SIGKILL.
|
|
76
81
|
cleanupTimeoutMs?: number;
|
|
82
|
+
// One bounded drain granted when agent_settled arrives while a child background job still runs.
|
|
83
|
+
drainTimeoutMs?: number;
|
|
77
84
|
}
|
|
78
85
|
|
|
79
86
|
export interface AskAnswer {
|
|
@@ -120,6 +127,8 @@ export interface RunnerHooks {
|
|
|
120
127
|
onQuerySettled?(taskId: string, requestId: string, outcome: "replied" | "expired"): void;
|
|
121
128
|
// Parent-only observation of a paired successful filesystem tool, not prose.
|
|
122
129
|
onSuccessfulMutation?(task: TaskRecord, tool: { toolName: "write" | "edit"; toolCallId: string; path: string; evidence?: SessionChangeEvidence }): void | Promise<void>;
|
|
130
|
+
/** The child moved to the next model of its fallback chain and keeps going. */
|
|
131
|
+
onFallback?(task: TaskRecord, change: { from: string; to: string; category: TerminalErrorCategory; launch?: boolean }): void;
|
|
123
132
|
}
|
|
124
133
|
|
|
125
134
|
export interface TaskRequest {
|
|
@@ -132,6 +141,8 @@ export interface TaskRequest {
|
|
|
132
141
|
parentSessionId: string;
|
|
133
142
|
model: ModelRef | undefined;
|
|
134
143
|
thinking: string | undefined;
|
|
144
|
+
/** Ordered fallbacks for when `model` runs out or keeps failing; only models the user chose. */
|
|
145
|
+
fallbacks?: FallbackChain;
|
|
135
146
|
sessionDir: string;
|
|
136
147
|
resumeSessionPath: string | undefined;
|
|
137
148
|
env: NodeJS.ProcessEnv;
|
|
@@ -181,6 +192,7 @@ interface ProcessLike {
|
|
|
181
192
|
execPath: string;
|
|
182
193
|
argv: string[];
|
|
183
194
|
env: NodeJS.ProcessEnv;
|
|
195
|
+
platform?: NodeJS.Platform;
|
|
184
196
|
}
|
|
185
197
|
|
|
186
198
|
interface Pending {
|
|
@@ -199,6 +211,10 @@ interface PendingReply {
|
|
|
199
211
|
interface LiveTask {
|
|
200
212
|
child: ChildLike;
|
|
201
213
|
sawRunEvent: boolean;
|
|
214
|
+
/** The category of the last failed final response, for the fallback decision. */
|
|
215
|
+
errorCategory?: TerminalErrorCategory;
|
|
216
|
+
/** Models this run already used or tried, so a chain never loops. */
|
|
217
|
+
triedModels?: Set<string>;
|
|
202
218
|
observations?: ChildObservationBuffer;
|
|
203
219
|
observationGuard?: () => boolean;
|
|
204
220
|
observationPreparation?: () => boolean;
|
|
@@ -215,6 +231,10 @@ interface LiveTask {
|
|
|
215
231
|
/** The child's own TMPDIR, removed when the child ends unless its exit is unconfirmed. */
|
|
216
232
|
scratchDir?: string;
|
|
217
233
|
cleanupDeadlineAt: number | undefined;
|
|
234
|
+
/** The child's last reported background-job state, if any (#2266). */
|
|
235
|
+
childJobState?: { running: number; pending: boolean };
|
|
236
|
+
/** One bounded post-settlement drain while the child's background jobs finish (#2266). */
|
|
237
|
+
drain?: { status: TaskRecord["status"]; error: string | null; cancel: () => void };
|
|
218
238
|
quarantined: boolean;
|
|
219
239
|
nextId: number;
|
|
220
240
|
permissionBroker?: ParentStandingReviewPermissionBroker;
|
|
@@ -241,6 +261,8 @@ export const MAX_INLINE_INSTRUCTIONS_BYTES = 1000;
|
|
|
241
261
|
const MAX_TRANSPORT_PREFIX_CHARS = 64;
|
|
242
262
|
const CHILD_MARKER = "GENTLE_PI_AGENTS_CHILD";
|
|
243
263
|
const IPC_MARKER = "GENTLE_PI_AGENTS_OWNED_IPC";
|
|
264
|
+
/** Forwarded to the child only when a declared `bash_background` admitted its policy (#2266). */
|
|
265
|
+
export const CHILD_JOBS_ENV = "GENTLE_PI_AGENTS_CHILD_JOBS";
|
|
244
266
|
const PARENT_NOTIFICATION_TOOL = "subagent_parent_message";
|
|
245
267
|
/** The exact --tools list, so the child can report requested names Pi dropped silently (#1690). */
|
|
246
268
|
export const REQUESTED_TOOLS_ENV = "GENTLE_PI_AGENTS_REQUESTED_TOOLS";
|
|
@@ -250,6 +272,8 @@ const GROUP_CONFIRM_MS = 25;
|
|
|
250
272
|
const GROUP_CONFIRM_DEADLINE_MS = 1_000;
|
|
251
273
|
const QUARANTINE_PROBE_MS = 1_000;
|
|
252
274
|
export const DEFAULT_CLEANUP_TIMEOUT_MS = 5_000;
|
|
275
|
+
// One bounded drain window for a child's own background jobs at settlement (#2266).
|
|
276
|
+
export const DEFAULT_DRAIN_TIMEOUT_MS = 5_000;
|
|
253
277
|
const QUERY_REJECTION_ERRORS = new Set([
|
|
254
278
|
"invalid child IPC frame",
|
|
255
279
|
"invalid child IPC correlation",
|
|
@@ -340,16 +364,124 @@ export function childArguments(request: TaskRequest, instructionsPath?: string):
|
|
|
340
364
|
return args;
|
|
341
365
|
}
|
|
342
366
|
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
367
|
+
/**
|
|
368
|
+
* Resolves the underlying JavaScript entry point targeted by a Windows .cmd or .bat shim.
|
|
369
|
+
*
|
|
370
|
+
* Scans the shim text for referenced .js/.mjs/.cjs files (such as npm or pnpm cmd-shims)
|
|
371
|
+
* or inspects adjacent package metadata without invoking cmd.exe or a shell.
|
|
372
|
+
*/
|
|
373
|
+
export function resolvePiScriptFromCmd(
|
|
374
|
+
cmdPath: string,
|
|
375
|
+
exists: (path: string) => boolean = existsSync,
|
|
376
|
+
readFile: (path: string) => string = (p) => readFileSync(p, "utf8"),
|
|
377
|
+
): string | undefined {
|
|
378
|
+
const baseDir = win32.dirname(cmdPath);
|
|
379
|
+
let text = "";
|
|
380
|
+
try {
|
|
381
|
+
text = readFile(cmdPath);
|
|
382
|
+
} catch {
|
|
383
|
+
text = "";
|
|
384
|
+
}
|
|
385
|
+
|
|
386
|
+
if (text) {
|
|
387
|
+
const targetMatch = /^#\s*cmd-shim-target\s*=\s*([^\r\n]+)$/m.exec(text);
|
|
388
|
+
if (targetMatch) {
|
|
389
|
+
const candidate = targetMatch[1].trim();
|
|
390
|
+
const resolved = win32.isAbsolute(candidate) ? candidate : win32.resolve(baseDir, candidate);
|
|
391
|
+
if (exists(resolved)) return resolved;
|
|
392
|
+
}
|
|
393
|
+
|
|
394
|
+
const scriptMatches = text.matchAll(/(?:["'])([^"']+\.[cm]?js)(?:["'])|(?:^|\s)((?:%~?dp0|%dp0%)\\?[^\s"']+\.[cm]?js)(?:\s|$)/gi);
|
|
395
|
+
for (const m of scriptMatches) {
|
|
396
|
+
const raw = (m[1] ?? m[2])?.trim();
|
|
397
|
+
if (!raw) continue;
|
|
398
|
+
const stripped = raw.replace(/^(?:%~?dp0|%dp0%)\\?/i, "");
|
|
399
|
+
const candidate = /^(?:%~?dp0|%dp0%)/i.test(raw) || !win32.isAbsolute(stripped)
|
|
400
|
+
? win32.resolve(baseDir, stripped)
|
|
401
|
+
: stripped;
|
|
402
|
+
if (exists(candidate)) return candidate;
|
|
403
|
+
}
|
|
404
|
+
}
|
|
405
|
+
|
|
406
|
+
const standardPaths = [
|
|
407
|
+
win32.join(baseDir, "node_modules", "@earendil-works", "pi-coding-agent", "dist", "cli.js"),
|
|
408
|
+
win32.join(baseDir, "node_modules", "@earendil-works", "pi-coding-agent", "dist", "bundle", "cli.js"),
|
|
409
|
+
win32.join(baseDir, "pi-launcher.js"),
|
|
410
|
+
win32.join(baseDir, "dist", "cli.js"),
|
|
411
|
+
win32.join(baseDir, "dist", "bundle", "cli.js"),
|
|
412
|
+
];
|
|
413
|
+
for (const candidate of standardPaths) {
|
|
414
|
+
if (exists(candidate)) return candidate;
|
|
415
|
+
}
|
|
416
|
+
|
|
417
|
+
return undefined;
|
|
418
|
+
}
|
|
419
|
+
|
|
420
|
+
/**
|
|
421
|
+
* Searches the Windows PATH and known locations for an installed pi command,
|
|
422
|
+
* resolving .cmd shims to their direct Node script entry points to avoid cmd.exe shell invocation.
|
|
423
|
+
*/
|
|
424
|
+
export function findWindowsPiCommand(
|
|
425
|
+
proc: ProcessLike = process,
|
|
426
|
+
exists: (path: string) => boolean = existsSync,
|
|
427
|
+
readFile: (path: string) => string = (p) => readFileSync(p, "utf8"),
|
|
428
|
+
): PiCommand | undefined {
|
|
429
|
+
const pathEnv = proc.env.Path ?? proc.env.PATH ?? "";
|
|
430
|
+
for (const entry of pathEnv.split(";")) {
|
|
431
|
+
const dir = entry.length >= 2 && entry.startsWith('"') && entry.endsWith('"')
|
|
432
|
+
? entry.slice(1, -1)
|
|
433
|
+
: entry;
|
|
434
|
+
if (!dir) continue;
|
|
435
|
+
|
|
436
|
+
const candidateExe = win32.join(dir, "pi.exe");
|
|
437
|
+
if (exists(candidateExe)) {
|
|
438
|
+
return { command: candidateExe, args: [] };
|
|
439
|
+
}
|
|
440
|
+
|
|
441
|
+
for (const ext of [".cmd", ".bat"]) {
|
|
442
|
+
const candidateCmd = win32.join(dir, `pi${ext}`);
|
|
443
|
+
if (exists(candidateCmd)) {
|
|
444
|
+
const script = resolvePiScriptFromCmd(candidateCmd, exists, readFile);
|
|
445
|
+
if (script) {
|
|
446
|
+
return { command: proc.execPath, args: [script] };
|
|
447
|
+
}
|
|
448
|
+
}
|
|
449
|
+
}
|
|
450
|
+
}
|
|
451
|
+
return undefined;
|
|
452
|
+
}
|
|
453
|
+
|
|
454
|
+
/**
|
|
455
|
+
* Resolves the pi invocation command for subagent execution.
|
|
456
|
+
*
|
|
457
|
+
* Reuses the running pi CLI entry point while it exists on disk.
|
|
458
|
+
* When the running entry point disappears (e.g. after a package upgrade on Windows),
|
|
459
|
+
* re-resolves the current installation from PATH and returns Node plus the target script
|
|
460
|
+
* so arguments are never passed through an unescaped shell wrapper.
|
|
461
|
+
*/
|
|
462
|
+
export function piCommand(
|
|
463
|
+
proc: ProcessLike = process,
|
|
464
|
+
exists: (path: string) => boolean = existsSync,
|
|
465
|
+
readFile: (path: string) => string = (p) => readFileSync(p, "utf8"),
|
|
466
|
+
): PiCommand {
|
|
346
467
|
const override = proc.env.GENTLE_PI_AGENTS_PI?.trim();
|
|
347
468
|
if (override) {
|
|
348
469
|
const [command, ...args] = override.split(/\s+/);
|
|
470
|
+
if (/\.(?:cmd|bat)$/i.test(command) && exists(command)) {
|
|
471
|
+
const script = resolvePiScriptFromCmd(command, exists, readFile);
|
|
472
|
+
if (script) return { command: proc.execPath, args: [script, ...args] };
|
|
473
|
+
}
|
|
349
474
|
return { command, args };
|
|
350
475
|
}
|
|
351
476
|
const entry = proc.argv[1];
|
|
352
477
|
if (entry && /(^|[\\/])cli\.js$/.test(entry) && exists(entry)) return { command: proc.execPath, args: [entry] };
|
|
478
|
+
const isWin32 = proc.platform !== undefined
|
|
479
|
+
? proc.platform === "win32"
|
|
480
|
+
: (proc === process ? process.platform === "win32" : /^[a-zA-Z]:\\/i.test(proc.execPath) || /\\/.test(proc.execPath));
|
|
481
|
+
if (isWin32) {
|
|
482
|
+
const resolved = findWindowsPiCommand(proc, exists, readFile);
|
|
483
|
+
if (resolved) return resolved;
|
|
484
|
+
}
|
|
353
485
|
return { command: "pi", args: [] };
|
|
354
486
|
}
|
|
355
487
|
|
|
@@ -565,7 +697,10 @@ export class AgentRunner {
|
|
|
565
697
|
this.finish(id, TASK_STATUS.FAILED, `could not start pi: explicit tool bash_background requires background-subagents policy on. Set ${file} to {"schema":"gentle-pi.background-subagents/v1","policy":"on"}; inspect or change policy with /gentle:background-subagents enable|disable|status.`);
|
|
566
698
|
return;
|
|
567
699
|
}
|
|
568
|
-
|
|
700
|
+
// Admission passed: the child registers its own private job tools and is
|
|
701
|
+
// trusted to report job state for the settlement drain.
|
|
702
|
+
env[CHILD_JOBS_ENV] = "1";
|
|
703
|
+
} else delete env[CHILD_JOBS_ENV];
|
|
569
704
|
if (tools !== undefined) env[REQUESTED_TOOLS_ENV] = tools;
|
|
570
705
|
else delete env[REQUESTED_TOOLS_ENV];
|
|
571
706
|
let instructionsTransportDir: string | undefined;
|
|
@@ -604,9 +739,10 @@ export class AgentRunner {
|
|
|
604
739
|
if (this.processControl.platform === "win32") { env.TMP = scratchDir; env.TEMP = scratchDir; }
|
|
605
740
|
} catch { scratchDir = undefined; }
|
|
606
741
|
let child: ChildLike;
|
|
742
|
+
const launch = this.launchRequest(id, request);
|
|
607
743
|
try {
|
|
608
744
|
const pi = this.deps.resolvePi?.() ?? this.deps.pi;
|
|
609
|
-
child = this.deps.spawn(pi.command, [...pi.args, ...childArguments(request, instructionsTransportPath)], {
|
|
745
|
+
child = this.deps.spawn(pi.command, [...pi.args, ...childArguments(launch.request, instructionsTransportPath)], {
|
|
610
746
|
cwd: request.cwd,
|
|
611
747
|
env,
|
|
612
748
|
detached,
|
|
@@ -622,6 +758,7 @@ export class AgentRunner {
|
|
|
622
758
|
this.finish(id, TASK_STATUS.FAILED, `could not start pi: ${error instanceof Error ? error.message : String(error)}`);
|
|
623
759
|
return;
|
|
624
760
|
}
|
|
761
|
+
launch.announce?.();
|
|
625
762
|
const processGroup = detached && typeof child.pid === "number" && child.pid > 0 ? child.pid : undefined;
|
|
626
763
|
const live: LiveTask = { child, sawRunEvent: false, mutationStarts: new Map(), inFlightTools: new Map(), argumentProgress: new ToolArgumentProgress(), pending: new Map(), queries: new Map(), replies: new Map(), cancelStall: () => {}, cancelGrace: () => {}, processGroup, terminal: undefined, childExit: undefined, childExitSignal: undefined, instructionsTransportDir, scratchDir, cleanupDeadlineAt: undefined, quarantined: false, nextId: 0, ipcClosed: false, acknowledgedIpcIds: new Set(), acknowledgedIpcOrder: [], stderrTail: "" };
|
|
627
764
|
if (request.prepareResponseObservations) {
|
|
@@ -725,6 +862,90 @@ export class AgentRunner {
|
|
|
725
862
|
}, budget);
|
|
726
863
|
}
|
|
727
864
|
|
|
865
|
+
/** The request a child starts with: a primary model that is cooling down gives way to its first usable fallback. */
|
|
866
|
+
private launchRequest(id: string, request: TaskRequest): { request: TaskRequest; announce?: () => void } {
|
|
867
|
+
const chain = request.fallbacks ?? [];
|
|
868
|
+
if (!chain.length || !request.model) return { request };
|
|
869
|
+
const cooldown = this.deps.cooldown ?? sharedCooldown();
|
|
870
|
+
const now = this.deps.now();
|
|
871
|
+
const primary = formatModelRef(request.model);
|
|
872
|
+
const pick = pickModel(primary, chain, { cooldown, now });
|
|
873
|
+
const model = pick?.fallback && pick.model ? parseModelRef(pick.model) : undefined;
|
|
874
|
+
if (!model?.provider || !pick?.model) return { request };
|
|
875
|
+
const updated = this.store.update(id, { model: pick.model, fallbackFrom: primary, ...(pick.thinking ? { thinking: pick.thinking } : {}) });
|
|
876
|
+
const category = cooldown.reason(primary, now);
|
|
877
|
+
const to = pick.model;
|
|
878
|
+
// Announced by the caller once the child actually started.
|
|
879
|
+
const announce = () => {
|
|
880
|
+
try { if (updated && category) this.hooks.onFallback?.(this.store.get(id) ?? updated, { from: primary, to, category, launch: true }); }
|
|
881
|
+
catch { /* A notice failure must not stop the launch. */ }
|
|
882
|
+
};
|
|
883
|
+
return { request: { ...request, model, thinking: pick.thinking ?? request.thinking }, announce };
|
|
884
|
+
}
|
|
885
|
+
|
|
886
|
+
/**
|
|
887
|
+
* After a failed final response, moves the live child to the next usable
|
|
888
|
+
* model of its chain and asks it to continue the same conversation. False
|
|
889
|
+
* when the error would repeat on any model or nothing is left: the caller
|
|
890
|
+
* then fails the task as before.
|
|
891
|
+
*/
|
|
892
|
+
private fallBack(id: string, request: TaskRequest, live: LiveTask): boolean {
|
|
893
|
+
const chain = request.fallbacks ?? [];
|
|
894
|
+
const category = live.errorCategory;
|
|
895
|
+
if (!chain.length || live.terminal || !shouldFallBack(category)) return false;
|
|
896
|
+
const cooldown = this.deps.cooldown ?? sharedCooldown();
|
|
897
|
+
const now = this.deps.now();
|
|
898
|
+
const task = this.store.get(id);
|
|
899
|
+
const current = task?.model && task.model !== "default" ? task.model : request.model ? formatModelRef(request.model) : undefined;
|
|
900
|
+
const tried = (live.triedModels ??= new Set());
|
|
901
|
+
if (current) {
|
|
902
|
+
tried.add(current);
|
|
903
|
+
cooldown.mark(current, category!, now);
|
|
904
|
+
}
|
|
905
|
+
// The next selectable step: one with a provider, untried and not cooling down.
|
|
906
|
+
const next = () => {
|
|
907
|
+
for (;;) {
|
|
908
|
+
const pick = pickModel(current, chain, { cooldown, now: this.deps.now(), tried });
|
|
909
|
+
if (!pick?.fallback || !pick.model) return undefined;
|
|
910
|
+
tried.add(pick.model);
|
|
911
|
+
if (parseModelRef(pick.model)?.provider) return pick;
|
|
912
|
+
}
|
|
913
|
+
};
|
|
914
|
+
let pick = next();
|
|
915
|
+
if (!pick) return false;
|
|
916
|
+
live.errorCategory = undefined;
|
|
917
|
+
this.store.update(id, { error: null, result: null, lastStep: `↪ ${pick.model}` });
|
|
918
|
+
const alive = () => this.live.get(id) === live && !live.terminal;
|
|
919
|
+
const fail = (reason: string) => { if (alive()) this.settleOrderly(id, TASK_STATUS.FAILED, reason); };
|
|
920
|
+
void (async () => {
|
|
921
|
+
// Pi may refuse a step (no key, unknown model): the next one gets its turn.
|
|
922
|
+
for (;;) {
|
|
923
|
+
const target = parseModelRef(pick.model!)!;
|
|
924
|
+
const switched = await this.send(id, { type: "set_model", provider: target.provider, modelId: target.id });
|
|
925
|
+
if (!alive()) return;
|
|
926
|
+
if (switched.success !== false) break;
|
|
927
|
+
const refused = `could not switch to ${pick.model}: ${String(switched.error ?? "rejected")}`;
|
|
928
|
+
const following = next();
|
|
929
|
+
if (!following) return fail(refused);
|
|
930
|
+
pick = following;
|
|
931
|
+
this.store.update(id, { lastStep: `↪ ${pick.model}` });
|
|
932
|
+
}
|
|
933
|
+
const to = pick.model!;
|
|
934
|
+
// Pi accepted the model: the record follows at once, even if the run stops next.
|
|
935
|
+
const level = pick.thinking ?? request.thinking;
|
|
936
|
+
this.store.update(id, { model: to, fallbackFrom: this.store.get(id)?.fallbackFrom ?? current ?? "default", ...(level ? { thinking: level } : {}) });
|
|
937
|
+
// A step without its own effort runs at the agent's configured effort, not the previous step's.
|
|
938
|
+
if (level) await this.send(id, { type: "set_thinking_level", level });
|
|
939
|
+
if (!alive()) return;
|
|
940
|
+
const updated = this.store.get(id);
|
|
941
|
+
try { if (updated) this.hooks.onFallback?.(updated, { from: current ?? "default", to, category: category! }); }
|
|
942
|
+
catch { /* A notice failure must not stop the switch. */ }
|
|
943
|
+
const resumed = await this.send(id, { type: "prompt", message: fallbackContinuePrompt(current, to, category!) });
|
|
944
|
+
if (resumed.success === false) fail(`could not continue on ${to}: ${String(resumed.error ?? "prompt rejected")}`);
|
|
945
|
+
})().catch((error) => fail(`could not continue: ${error instanceof Error ? error.message : String(error)}`));
|
|
946
|
+
return true;
|
|
947
|
+
}
|
|
948
|
+
|
|
728
949
|
private send(id: string, command: Record<string, unknown>): Promise<Record<string, unknown>> {
|
|
729
950
|
const live = this.live.get(id);
|
|
730
951
|
if (!live) return Promise.resolve({ success: false, error: "task is not running" });
|
|
@@ -747,8 +968,8 @@ export class AgentRunner {
|
|
|
747
968
|
}
|
|
748
969
|
const task = this.store.get(id);
|
|
749
970
|
if (!task || live.terminal || isFinished(task.status) || task.parentSessionId === "") {
|
|
750
|
-
if (parsed.frame.kind === "
|
|
751
|
-
else this.
|
|
971
|
+
if (parsed.frame.kind === "query") this.sendQueryError(live, parsed.frame.id, "task is not a live owned recipient");
|
|
972
|
+
else this.acknowledge(live, parsed.frame.id, false, "task is not a live owned recipient");
|
|
752
973
|
return;
|
|
753
974
|
}
|
|
754
975
|
if (parsed.frame.kind === "notification") {
|
|
@@ -759,6 +980,18 @@ export class AgentRunner {
|
|
|
759
980
|
} catch { this.acknowledge(live, parsed.frame.id, false, "parent rejected notification"); }
|
|
760
981
|
return;
|
|
761
982
|
}
|
|
983
|
+
if (parsed.frame.kind === "job") {
|
|
984
|
+
const state = parseChildJobState(parsed.frame.message);
|
|
985
|
+
if (!state) {
|
|
986
|
+
this.acknowledge(live, parsed.frame.id, false, "invalid child job state");
|
|
987
|
+
return;
|
|
988
|
+
}
|
|
989
|
+
// Ack before the report can open a drain that closes IPC.
|
|
990
|
+
this.acknowledge(live, parsed.frame.id, true);
|
|
991
|
+
live.childJobState = state;
|
|
992
|
+
if (live.drain && state.running === 0 && !state.pending) this.beginSettle(id, live);
|
|
993
|
+
return;
|
|
994
|
+
}
|
|
762
995
|
let query: PendingQuery | undefined;
|
|
763
996
|
try {
|
|
764
997
|
if (live.queries.has(parsed.frame.id)) rejectQuery("duplicate query request");
|
|
@@ -894,6 +1127,7 @@ export class AgentRunner {
|
|
|
894
1127
|
continue; // Separate from store persistence, UI totals and notifications.
|
|
895
1128
|
}
|
|
896
1129
|
live.sawRunEvent = true;
|
|
1130
|
+
if (event.type === TASK_EVENT.AGENT_END) live.errorCategory = event.outcome === "error" ? event.errorCategory : undefined;
|
|
897
1131
|
this.store.apply(id, event, this.deps.now());
|
|
898
1132
|
if (event.type === TASK_EVENT.TOOL_START && event.callId) {
|
|
899
1133
|
live.inFlightTools.set(event.callId, event.name);
|
|
@@ -920,9 +1154,10 @@ export class AgentRunner {
|
|
|
920
1154
|
if (event.type === TASK_EVENT.AGENT_SETTLED) {
|
|
921
1155
|
if (live.observations) live.observations.agentSettled = true;
|
|
922
1156
|
const terminal = this.store.get(id);
|
|
923
|
-
if (terminal?.error
|
|
924
|
-
else if (terminal?.
|
|
925
|
-
else this.
|
|
1157
|
+
if (terminal?.error && this.fallBack(id, request, live)) { /* The child keeps going on its next model. */ }
|
|
1158
|
+
else if (terminal?.error) this.settleOrDrain(id, TASK_STATUS.FAILED, terminal.error, live);
|
|
1159
|
+
else if (terminal?.result) this.settleOrDrain(id, TASK_STATUS.COMPLETED, null, live);
|
|
1160
|
+
else this.settleOrDrain(id, TASK_STATUS.FAILED, "assistant settled without a final report", live);
|
|
926
1161
|
}
|
|
927
1162
|
}
|
|
928
1163
|
if (!live.terminal && progress) this.armStall(id, live);
|
|
@@ -963,6 +1198,34 @@ export class AgentRunner {
|
|
|
963
1198
|
}
|
|
964
1199
|
}
|
|
965
1200
|
|
|
1201
|
+
/**
|
|
1202
|
+
* Settles a task, but when the child still reports running background jobs
|
|
1203
|
+
* (#2266) it grants one bounded drain window first so the jobs can finish;
|
|
1204
|
+
* the drain ends early when the child reports nothing left.
|
|
1205
|
+
*/
|
|
1206
|
+
private settleOrDrain(id: string, status: TaskRecord["status"], error: string | null, live: LiveTask): void {
|
|
1207
|
+
if (live.drain || live.terminal) return;
|
|
1208
|
+
const state = live.childJobState;
|
|
1209
|
+
// No child job work, or the child already reports none: settle as before.
|
|
1210
|
+
if (!state || (state.running === 0 && !state.pending)) {
|
|
1211
|
+
this.settleOrderly(id, status, error);
|
|
1212
|
+
return;
|
|
1213
|
+
}
|
|
1214
|
+
// One bounded extension: the child keeps running its jobs, and the drain
|
|
1215
|
+
// ends early on a report with nothing left. A late report cannot re-open it.
|
|
1216
|
+
const cancel = this.deps.schedule(() => this.beginSettle(id, live), this.limits.drainTimeoutMs ?? DEFAULT_DRAIN_TIMEOUT_MS);
|
|
1217
|
+
live.drain = { status, error, cancel };
|
|
1218
|
+
if (this.store.get(id)?.status === TASK_STATUS.RUNNING) this.store.update(id, { lastStep: "draining background jobs" });
|
|
1219
|
+
}
|
|
1220
|
+
|
|
1221
|
+
private beginSettle(id: string, live: LiveTask): void {
|
|
1222
|
+
const drain = live.drain;
|
|
1223
|
+
if (!drain || this.live.get(id) !== live) return;
|
|
1224
|
+
live.drain = undefined;
|
|
1225
|
+
drain.cancel();
|
|
1226
|
+
this.settleOrderly(id, drain.status, drain.error);
|
|
1227
|
+
}
|
|
1228
|
+
|
|
966
1229
|
/**
|
|
967
1230
|
* Requests orderly child shutdown via stdin upon settlement and schedules
|
|
968
1231
|
* bounded signal escalation if the child process does not exit within cleanupTimeoutMs.
|
|
@@ -970,6 +1233,8 @@ export class AgentRunner {
|
|
|
970
1233
|
private settleOrderly(id: string, status: TaskRecord["status"], error: string | null): void {
|
|
971
1234
|
const live = this.live.get(id);
|
|
972
1235
|
if (!live || live.terminal) return;
|
|
1236
|
+
live.drain?.cancel();
|
|
1237
|
+
live.drain = undefined;
|
|
973
1238
|
live.terminal = { status, error };
|
|
974
1239
|
live.mutationStarts.clear();
|
|
975
1240
|
live.inFlightTools.clear();
|
|
@@ -1001,6 +1266,8 @@ export class AgentRunner {
|
|
|
1001
1266
|
private requestStop(id: string, status: TaskRecord["status"], error: string | null, abort = false): void {
|
|
1002
1267
|
const live = this.live.get(id);
|
|
1003
1268
|
if (!live || live.terminal) return;
|
|
1269
|
+
live.drain?.cancel();
|
|
1270
|
+
live.drain = undefined;
|
|
1004
1271
|
live.terminal = { status, error };
|
|
1005
1272
|
live.mutationStarts.clear();
|
|
1006
1273
|
live.inFlightTools.clear();
|
|
@@ -1080,6 +1347,8 @@ export class AgentRunner {
|
|
|
1080
1347
|
this.closeIpc(live);
|
|
1081
1348
|
live.cancelStall();
|
|
1082
1349
|
live.cancelGrace();
|
|
1350
|
+
live.drain?.cancel();
|
|
1351
|
+
live.drain = undefined;
|
|
1083
1352
|
if (live.instructionsTransportDir) {
|
|
1084
1353
|
try { rmSync(live.instructionsTransportDir, { recursive: true, force: true }); } catch { /* best effort */ }
|
|
1085
1354
|
live.instructionsTransportDir = undefined;
|
|
@@ -1112,6 +1381,9 @@ export class AgentRunner {
|
|
|
1112
1381
|
if (!live) return;
|
|
1113
1382
|
live.childExit = code;
|
|
1114
1383
|
live.childExitSignal = signal ?? null;
|
|
1384
|
+
// A child that exits mid-drain still settles on the run agent_settled already
|
|
1385
|
+
// produced; the ordinary orderly shutdown then owns the exit.
|
|
1386
|
+
if (live.drain) this.beginSettle(id, live);
|
|
1115
1387
|
const exitDesc = formatChildExit(code, signal);
|
|
1116
1388
|
if (this.groupExists(live)) {
|
|
1117
1389
|
if (!live.terminal) this.requestStop(id, TASK_STATUS.FAILED, `pi exited with ${exitDesc} before agent_settled${this.stderrSuffix(live)}`);
|
package/lib/agents-view.ts
CHANGED
|
@@ -778,8 +778,13 @@ export class AgentsView {
|
|
|
778
778
|
}
|
|
779
779
|
|
|
780
780
|
private scrollBy(delta: number): void {
|
|
781
|
+
const task = this.selectedTask();
|
|
782
|
+
const layout = this.layout();
|
|
783
|
+
const lines = task ? this.threadLines(this.remoteThreads.get(task.id) ?? this.deps.store.thread(task.id), layout.threadWidth) : [];
|
|
784
|
+
const maxScroll = Math.max(0, lines.length - Math.max(0, layout.bodyRows - 1));
|
|
781
785
|
this.follow = false;
|
|
782
|
-
|
|
786
|
+
// Clamp the current visible position before moving, including after resize.
|
|
787
|
+
this.scroll = Math.max(0, Math.min(maxScroll, Math.min(this.scroll, maxScroll) + delta));
|
|
783
788
|
this.deps.requestRender();
|
|
784
789
|
}
|
|
785
790
|
|