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
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
import assert from "node:assert/strict";
|
|
2
|
+
import { existsSync, readFileSync } from "node:fs";
|
|
3
|
+
import { join } from "node:path";
|
|
4
|
+
import test from "node:test";
|
|
5
|
+
|
|
6
|
+
// ---------------------------------------------------------------------------
|
|
7
|
+
// full-delegation-mode-conflicts S2/S3/S4/S6/S8.
|
|
8
|
+
//
|
|
9
|
+
// In full delegation mode the organic routing rules are removed from what the
|
|
10
|
+
// orchestrator can read, never annotated as "does not apply": a rule left in
|
|
11
|
+
// context is a rule a model may follow. This file pins that closure over the
|
|
12
|
+
// whole always-on prompt AND every lazy asset it names, so the day the mirrored
|
|
13
|
+
// provider contract or a shared asset reintroduces an inline-first rule, this
|
|
14
|
+
// test fails instead of a user's session deadlocking.
|
|
15
|
+
// ---------------------------------------------------------------------------
|
|
16
|
+
|
|
17
|
+
const REPO_ROOT = join(import.meta.dirname, "..");
|
|
18
|
+
const ASSETS = join(REPO_ROOT, "assets");
|
|
19
|
+
const { __testing } = await import("../extensions/gentle-ai.ts");
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* Phrases that route work inline, or decide delegation by size. "Task Size" is deliberately absent: it defines
|
|
23
|
+
* tracking and risk in both modes, and the full delegation core keeps that section.
|
|
24
|
+
*/
|
|
25
|
+
const ORGANIC_ROUTING = /\binline\b|small path|small edits|never delegates|Writer (?:rule|trigger)/i;
|
|
26
|
+
|
|
27
|
+
test("S6: the closure rule recognises the organic sentences a narrower pattern let through", () => {
|
|
28
|
+
// Independent verification B1: each of these, inserted into a reachable asset, passed an earlier,
|
|
29
|
+
// phrase-by-phrase pattern. Any "inline" now fails the closure, with no allowlist to maintain.
|
|
30
|
+
for (const sentence of [
|
|
31
|
+
"Units of about 100 changed lines or less always run inline: the parent edits them.",
|
|
32
|
+
"Without a reason, the parent works inline, following the logbook.",
|
|
33
|
+
"Is the change small? If no, delegate it. If no, do it inline.",
|
|
34
|
+
"Small task pattern: parent edits inline, then reports.",
|
|
35
|
+
"6. **Implement task by task.** Implement inline unless a trigger fires.",
|
|
36
|
+
"A large task alone never delegates.",
|
|
37
|
+
]) {
|
|
38
|
+
assert.ok(ORGANIC_ROUTING.test(sentence), sentence);
|
|
39
|
+
}
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
function render(mode: "organic" | "full-delegation"): string {
|
|
43
|
+
return __testing.buildGentlePrompt("gentleman", REPO_ROOT, undefined, undefined, undefined, mode);
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
function namesIn(text: string): string[] {
|
|
47
|
+
return [...new Set([...text.matchAll(/orchestrator(?:-[a-z]+)*\.md/g)].map((match) => match[0]))];
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
/** Every lazy asset reachable from the prompt: named by it, or by an asset it names, transitively. */
|
|
51
|
+
function namedAssets(prompt: string): string[] {
|
|
52
|
+
const reached = new Set<string>();
|
|
53
|
+
const pending = namesIn(prompt);
|
|
54
|
+
while (pending.length > 0) {
|
|
55
|
+
const name = pending.pop()!;
|
|
56
|
+
if (reached.has(name)) continue;
|
|
57
|
+
reached.add(name);
|
|
58
|
+
const path = join(ASSETS, name);
|
|
59
|
+
if (existsSync(path)) pending.push(...namesIn(readFileSync(path, "utf8")));
|
|
60
|
+
}
|
|
61
|
+
return [...reached].sort();
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
function organicLines(text: string): string[] {
|
|
65
|
+
return text.split("\n").filter((line) => ORGANIC_ROUTING.test(line));
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
test("S2/S6: the full delegation prompt carries no organic routing rule", () => {
|
|
69
|
+
assert.deepEqual(organicLines(render("full-delegation")), []);
|
|
70
|
+
});
|
|
71
|
+
|
|
72
|
+
test("S2/S6: no lazy asset reachable from the full delegation prompt carries an organic routing rule", () => {
|
|
73
|
+
const named = namedAssets(render("full-delegation"));
|
|
74
|
+
assert.ok(named.length > 0, "the prompt must still point at its lazy detail");
|
|
75
|
+
for (const name of named) {
|
|
76
|
+
const path = join(ASSETS, name);
|
|
77
|
+
assert.ok(existsSync(path), `the prompt names a lazy asset that does not exist: ${name}`);
|
|
78
|
+
assert.deepEqual(organicLines(readFileSync(path, "utf8")), [], `${name} reaches a full delegation session`);
|
|
79
|
+
}
|
|
80
|
+
});
|
|
81
|
+
|
|
82
|
+
test("S3: full delegation keeps a Task Size that decides tracking and risk, never who writes", () => {
|
|
83
|
+
const prompt = render("full-delegation");
|
|
84
|
+
assert.match(prompt, /## Task Size/);
|
|
85
|
+
assert.match(prompt, /resume test/i);
|
|
86
|
+
for (const item of ["(1)", "(2)", "(3)", "(4)", "(5)", "(6)"]) assert.ok(prompt.includes(item), `high-risk item ${item} is missing`);
|
|
87
|
+
assert.match(prompt, /Risk line/);
|
|
88
|
+
assert.doesNotMatch(prompt, /small work follows/i);
|
|
89
|
+
});
|
|
90
|
+
|
|
91
|
+
test("S4: full delegation tells the agent how the human switches the mode, and that no new session is needed", () => {
|
|
92
|
+
const prompt = render("full-delegation");
|
|
93
|
+
assert.match(prompt, /\/gentle:profiles/);
|
|
94
|
+
assert.match(prompt, /`w`/);
|
|
95
|
+
assert.match(prompt, /next turn/i);
|
|
96
|
+
assert.match(prompt, /no new session/i);
|
|
97
|
+
});
|
|
98
|
+
|
|
99
|
+
test("S2: the projected ODD steps keep every unchanged step and the shared tail lines byte for byte", () => {
|
|
100
|
+
const organic = render("organic").split("\n");
|
|
101
|
+
const full = render("full-delegation");
|
|
102
|
+
for (const step of ["1. **Authorize.**", "3. **Resolve uncertainty.**", "5. **Track before the first write.**", "7. **Close.**", "Phase reporting: "]) {
|
|
103
|
+
const line = organic.find((candidate) => candidate.startsWith(step));
|
|
104
|
+
assert.ok(line, `organic render lost ${step}`);
|
|
105
|
+
assert.ok(full.includes(line), `full delegation must keep ${step} verbatim`);
|
|
106
|
+
}
|
|
107
|
+
// The resume line is shared too; only its pointer to the organic card is projected.
|
|
108
|
+
const resume = organic.find((candidate) => candidate.startsWith("Resume an interrupted feature "));
|
|
109
|
+
assert.ok(resume?.includes("`orchestrator-delegation.md`"));
|
|
110
|
+
assert.ok(full.includes(resume!.replace("`orchestrator-delegation.md`", "`orchestrator-full-delegation-card.md`")), "resume keeps every byte but its pointer");
|
|
111
|
+
for (const step of ["2. **Explore.**", "4. **Classify.**", "6. **Implement task by task.**"]) {
|
|
112
|
+
assert.ok(full.split("\n").some((line) => line.startsWith(step)), `full delegation must keep a step ${step}`);
|
|
113
|
+
}
|
|
114
|
+
});
|
|
115
|
+
|
|
116
|
+
test("S8: the organic render still carries the mirrored steps unprojected", () => {
|
|
117
|
+
const organic = render("organic");
|
|
118
|
+
assert.match(organic, /4\. \*\*Classify\.\*\* Size the task by the orchestrator's Task Size section; its criteria and resume test alone decide small or large, and small work follows its small path\./);
|
|
119
|
+
assert.match(organic, /when in doubt, work inline/);
|
|
120
|
+
assert.match(organic, /`orchestrator-delegation-reference\.md`/);
|
|
121
|
+
});
|
|
122
|
+
|
|
123
|
+
test("S2: the full delegation card is up to date with the organic sources it projects", async () => {
|
|
124
|
+
const { renderFullDelegationCard, FULL_DELEGATION_CARD } = await import("../scripts/build-full-delegation-card.mjs");
|
|
125
|
+
assert.equal(
|
|
126
|
+
readFileSync(join(ASSETS, FULL_DELEGATION_CARD), "utf8"),
|
|
127
|
+
renderFullDelegationCard(ASSETS),
|
|
128
|
+
"run node scripts/build-full-delegation-card.mjs --write",
|
|
129
|
+
);
|
|
130
|
+
});
|
|
131
|
+
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import assert from "node:assert/strict";
|
|
2
|
+
import test from "node:test";
|
|
3
|
+
|
|
4
|
+
import { createContextBackstopSignal } from "../lib/context-backstop.ts";
|
|
5
|
+
import { createExplorationBudget } from "../lib/exploration-budget.ts";
|
|
6
|
+
import { todoPromptBlock } from "../lib/shell-todo.ts";
|
|
7
|
+
|
|
8
|
+
// ---------------------------------------------------------------------------
|
|
9
|
+
// full-delegation-mode-conflicts S5: runtime notices emitted in full delegation
|
|
10
|
+
// mode never tell the parent to work inline. Organic notices keep their exact
|
|
11
|
+
// text. The mode is passed as a thunk so it is resolved only when a notice is
|
|
12
|
+
// actually emitted, never on every tool result.
|
|
13
|
+
// ---------------------------------------------------------------------------
|
|
14
|
+
|
|
15
|
+
const INLINE = /stays? inline|inline write|do it and report/;
|
|
16
|
+
const env = { GENTLE_PI_CONTEXT_BACKSTOP_TOKENS: "1000" };
|
|
17
|
+
const usage = { tokens: 5_000, contextWindow: 100_000 };
|
|
18
|
+
|
|
19
|
+
test("S5: the context backstop notice in full delegation mode has no inline clause", () => {
|
|
20
|
+
const notice = createContextBackstopSignal(env)("full", usage, () => "full-delegation");
|
|
21
|
+
assert.ok(notice);
|
|
22
|
+
assert.doesNotMatch(notice, INLINE);
|
|
23
|
+
assert.match(notice, /delegate the next bounded unit/);
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
test("S5: the organic context backstop notice is unchanged", () => {
|
|
27
|
+
const organic = createContextBackstopSignal(env)("organic", usage, () => "organic");
|
|
28
|
+
const legacy = createContextBackstopSignal(env)("legacy", usage);
|
|
29
|
+
assert.equal(organic, legacy, "an organic mode and no mode at all read the same");
|
|
30
|
+
assert.match(organic ?? "", /while single small edits and state checks stay inline\.$/);
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
test("S5: the mode is resolved only when the backstop notice is emitted", () => {
|
|
34
|
+
let resolved = 0;
|
|
35
|
+
const signal = createContextBackstopSignal(env);
|
|
36
|
+
signal("lazy", { tokens: 10, contextWindow: 100_000 }, () => { resolved += 1; return "full-delegation"; });
|
|
37
|
+
assert.equal(resolved, 0, "below the backstop nothing reads the mode");
|
|
38
|
+
signal("lazy", usage, () => { resolved += 1; return "full-delegation"; });
|
|
39
|
+
signal("lazy", usage, () => { resolved += 1; return "full-delegation"; });
|
|
40
|
+
assert.equal(resolved, 1, "one notice per crossing, one resolution");
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
function overBudget(mode?: () => "organic" | "full-delegation"): string | undefined {
|
|
44
|
+
const budget = createExplorationBudget();
|
|
45
|
+
budget.start("s");
|
|
46
|
+
let notice: string | undefined;
|
|
47
|
+
for (let index = 0; index < 5; index++) {
|
|
48
|
+
const id = `call-${index}`;
|
|
49
|
+
budget.call("s", id, "read");
|
|
50
|
+
notice ??= budget.result("s", { toolCallId: id, toolName: "read", isError: false, content: [{ type: "text", text: "x".repeat(20_000) }] } as never, true, false, mode);
|
|
51
|
+
}
|
|
52
|
+
return notice;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
test("S5: the exploration budget notice in full delegation mode names the writer, not an inline write", () => {
|
|
56
|
+
const notice = overBudget(() => "full-delegation");
|
|
57
|
+
assert.ok(notice);
|
|
58
|
+
assert.doesNotMatch(notice, INLINE);
|
|
59
|
+
assert.match(notice, /Reading that prepares a writer belongs in that writer's prompt\./);
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
test("S5: the organic exploration budget notice is unchanged", () => {
|
|
63
|
+
const organic = overBudget(() => "organic");
|
|
64
|
+
assert.equal(organic, overBudget());
|
|
65
|
+
assert.match(organic ?? "", /Preparation for an already-understood authorized inline write remains exempt\./);
|
|
66
|
+
});
|
|
67
|
+
|
|
68
|
+
test("S5: the todo block in full delegation mode delegates small tasks instead of doing them", () => {
|
|
69
|
+
assert.doesNotMatch(todoPromptBlock("full-delegation"), INLINE);
|
|
70
|
+
assert.match(todoPromptBlock("full-delegation"), /A small task \(Task Size\) uses no todo list: delegate it and report\./);
|
|
71
|
+
});
|
|
72
|
+
|
|
73
|
+
test("S5: the organic todo block is byte-identical", () => {
|
|
74
|
+
assert.equal(todoPromptBlock("organic"), todoPromptBlock());
|
|
75
|
+
assert.match(todoPromptBlock(), /A small task \(Task Size\) uses no todo list: do it and report\./);
|
|
76
|
+
});
|
|
@@ -5,9 +5,9 @@ import test from "node:test";
|
|
|
5
5
|
|
|
6
6
|
const agents = join(process.cwd(), "assets", "agents");
|
|
7
7
|
const roles: Record<string, string[]> = {
|
|
8
|
-
"gentle-ai-explore.md": ["read", "grep", "find", "codegraph", "web_enable", "web_search", "source_check", "fetch_content", "get_search_content"],
|
|
9
|
-
"gentle-ai-worker.md": ["read", "grep", "find", "edit", "write", "bash", "mem_save"],
|
|
10
|
-
"gentle-ai-verify.md": ["read", "grep", "find", "bash"],
|
|
8
|
+
"gentle-ai-explore.md": ["read", "grep", "find", "codegraph", "web_enable", "web_search", "source_check", "fetch_content", "get_search_content", "mcp__codegraph__codegraph_explore"],
|
|
9
|
+
"gentle-ai-worker.md": ["read", "grep", "find", "edit", "write", "bash", "mem_save", "mcp__codegraph__codegraph_explore"],
|
|
10
|
+
"gentle-ai-verify.md": ["read", "grep", "find", "bash", "mcp__codegraph__codegraph_explore"],
|
|
11
11
|
};
|
|
12
12
|
|
|
13
13
|
function tools(file: string): string[] {
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import assert from "node:assert/strict";
|
|
2
|
+
import test from "node:test";
|
|
3
|
+
import { mkdtempSync, writeFileSync } from "node:fs";
|
|
4
|
+
import { tmpdir } from "node:os";
|
|
5
|
+
import { join } from "node:path";
|
|
6
|
+
import type { ExtensionAPI, ExtensionContext } from "@earendil-works/pi-coding-agent";
|
|
7
|
+
import type { AgentStatus } from "../lib/agent-status.ts";
|
|
8
|
+
|
|
9
|
+
type Handler = (event: any, ctx: ExtensionContext) => void;
|
|
10
|
+
async function harness(env: NodeJS.ProcessEnv = {}, failing = false) {
|
|
11
|
+
const { createAgentStatusExtension } = await import("../extensions/gentle-agent-status.ts");
|
|
12
|
+
const home = mkdtempSync(join(tmpdir(), "agent-status-extension-"));
|
|
13
|
+
const handlers = new Map<string, Handler>(); const listeners = new Map<string, (data: any) => void>();
|
|
14
|
+
const values: AgentStatus[] = []; let now = 0; let tick = () => {}; let flush = () => {}; let stopped = false; let removed = 0;
|
|
15
|
+
createAgentStatusExtension({ env, gentlePiConfigHome: home, now: () => now,
|
|
16
|
+
store: () => ({ write: (value: AgentStatus) => { if (failing) throw Error("disk"); values.push(value); return true; }, remove: () => { removed++; if (failing) throw Error("disk"); } }),
|
|
17
|
+
watch: (fn) => { tick = fn; return () => { stopped = true; }; },
|
|
18
|
+
schedule: (fn) => { flush = fn; return () => { flush = () => {}; }; },
|
|
19
|
+
})({ on: (name: string, fn: Handler) => handlers.set(name, fn), events: { on: (name: string, fn: (data: any) => void) => {
|
|
20
|
+
listeners.set(name, fn); return () => { listeners.delete(name); };
|
|
21
|
+
} } } as unknown as ExtensionAPI);
|
|
22
|
+
const ctx = { cwd: "/workspace", mode: "tui", hasUI: true, isIdle: () => true,
|
|
23
|
+
sessionManager: { getSessionId: () => "root", getBranch: () => [] } } as unknown as ExtensionContext;
|
|
24
|
+
return { values, ctx, listeners, fire: (name: string, event = {}, context = ctx) => { handlers.get(name)?.(event, context); flush(); },
|
|
25
|
+
burst: () => { handlers.get("agent_start")?.({}, ctx); handlers.get("agent_settled")?.({}, ctx); flush(); },
|
|
26
|
+
attention: (active: boolean) => { listeners.get("herdr:blocked")?.({ active }); flush(); },
|
|
27
|
+
settings: (enabled: boolean) => { writeFileSync(join(home, "herdr-task-summary.json"), JSON.stringify({ schema: "gentle-pi.herdr-task-summary/v1", enabled, summaryColor: "accent", continuationColor: "muted" })); },
|
|
28
|
+
change: () => { listeners.get("gentle-pi:herdr-task-summary:changed")?.({ configHome: home }); flush(); },
|
|
29
|
+
pulse: (ms: number) => { now += ms; tick(); flush(); }, stopped: () => stopped, removed: () => removed };
|
|
30
|
+
}
|
|
31
|
+
const todo = (title: string) => ({ toolName: "todo", result: { details: { gentleTodo: { tasks: [{ title, status: "in_progress" }] } } } });
|
|
32
|
+
test("S2/S3: initial state, blocked dominance, settled idle guard and label", async () => {
|
|
33
|
+
const h = await harness({ GENTLE_SHELL_HERDR_REPORTER: "1" }); h.fire("session_start");
|
|
34
|
+
assert.equal(h.values.at(-1)?.agent, "gentle-shell"); assert.equal(h.values.at(-1)?.state, "idle");
|
|
35
|
+
h.fire("agent_start"); assert.equal(h.values.at(-1)?.state, "working");
|
|
36
|
+
h.fire("agent_settled", {}, { ...h.ctx, isIdle: () => false }); assert.equal(h.values.at(-1)?.state, "working");
|
|
37
|
+
h.attention(true); h.attention(true); h.fire("agent_start"); h.fire("agent_settled");
|
|
38
|
+
assert.equal(h.values.at(-1)?.state, "blocked"); h.attention(false); assert.equal(h.values.at(-1)?.state, "blocked");
|
|
39
|
+
h.attention(false); assert.equal(h.values.at(-1)?.state, "idle");
|
|
40
|
+
const active = await harness(); active.fire("session_start", {}, { ...active.ctx, isIdle: () => false });
|
|
41
|
+
assert.equal(active.values.at(-1)?.state, "working"); assert.equal(active.values.at(-1)?.agent, "pi");
|
|
42
|
+
});
|
|
43
|
+
test("S4: task preference, live changes, successful Todo only, settled/tree clear", async () => {
|
|
44
|
+
const h = await harness(); h.settings(false); h.fire("session_start"); h.fire("agent_start");
|
|
45
|
+
h.fire("tool_execution_end", todo("raw\ntitle")); assert.equal(h.values.at(-1)?.task, null);
|
|
46
|
+
h.settings(true); h.change(); assert.deepEqual(h.values.at(-1)?.task, { title: "raw title" });
|
|
47
|
+
h.fire("tool_execution_end", { ...todo("failed"), isError: true }); assert.deepEqual(h.values.at(-1)?.task, { title: "raw title" });
|
|
48
|
+
h.settings(false); h.change(); assert.equal(h.values.at(-1)?.task, null);
|
|
49
|
+
h.settings(true); h.change();
|
|
50
|
+
h.fire("tool_execution_end", { toolName: "todo", result: { details: { gentleTodo: { tasks: [] } } } });
|
|
51
|
+
assert.equal(h.values.at(-1)?.task, null); h.fire("tool_execution_end", todo("raw title"));
|
|
52
|
+
h.fire("agent_settled"); assert.equal(h.values.at(-1)?.task, null);
|
|
53
|
+
h.fire("agent_start"); assert.deepEqual(h.values.at(-1)?.task, { title: "raw title" });
|
|
54
|
+
h.fire("session_tree"); assert.equal(h.values.at(-1)?.task, null);
|
|
55
|
+
});
|
|
56
|
+
test("S6: coalescing, refresh within 10 seconds, shutdown cancellation/removal", async () => {
|
|
57
|
+
const h = await harness(); h.fire("session_start"); const before = h.values.length;
|
|
58
|
+
h.burst(); assert.equal(h.values.length, before); h.pulse(8999); assert.equal(h.values.length, before);
|
|
59
|
+
h.pulse(1); assert.equal(h.values.length, before + 1); assert.equal(h.values.at(-1)?.updatedAt, "1970-01-01T00:00:09.000Z");
|
|
60
|
+
h.fire("session_shutdown"); assert.ok(h.stopped()); assert.equal(h.removed(), 1); assert.equal(h.listeners.size, 0);
|
|
61
|
+
h.pulse(10000); h.fire("agent_start"); assert.equal(h.values.length, before + 1);
|
|
62
|
+
});
|
|
63
|
+
test("S7: children and noninteractive excluded; Herdr not required; ownership guarded", async () => {
|
|
64
|
+
for (const [env, mode] of [[{ GENTLE_PI_AGENTS_CHILD: "1" }, "tui"], [{}, "rpc"], [{}, "json"]] as const) {
|
|
65
|
+
const h = await harness(env); h.fire("session_start", {}, { ...h.ctx, mode } as ExtensionContext); h.fire("agent_start"); assert.deepEqual(h.values, []);
|
|
66
|
+
}
|
|
67
|
+
const h = await harness(); h.fire("session_start"); assert.equal(h.values.length, 1);
|
|
68
|
+
h.fire("agent_start", {}, { ...h.ctx, sessionManager: { getSessionId: () => "other" } } as ExtensionContext);
|
|
69
|
+
assert.equal(h.values.at(-1)?.state, "idle");
|
|
70
|
+
});
|
|
71
|
+
test("S6: writer and removal failures never escape into Pi", async () => {
|
|
72
|
+
const h = await harness({}, true);
|
|
73
|
+
assert.doesNotThrow(() => { h.fire("session_start"); h.fire("agent_start"); h.pulse(10000); h.fire("session_shutdown"); });
|
|
74
|
+
});
|
|
@@ -0,0 +1,237 @@
|
|
|
1
|
+
import assert from "node:assert/strict";
|
|
2
|
+
import { after } from "node:test";
|
|
3
|
+
import test from "node:test";
|
|
4
|
+
import { existsSync, mkdirSync, mkdtempSync, readFileSync, rmSync, writeFileSync } from "node:fs";
|
|
5
|
+
import { tmpdir } from "node:os";
|
|
6
|
+
import { dirname, join } from "node:path";
|
|
7
|
+
import installGentleAgents from "../extensions/gentle-agents.ts";
|
|
8
|
+
import { AGENT_MODE, type AgentDefinition } from "../lib/agents-config.ts";
|
|
9
|
+
import { TASK_STATUS, TaskStore } from "../lib/agents-protocol.ts";
|
|
10
|
+
import { AgentRunner, CHILD_JOBS_ENV, type RunnerDeps, type TaskRequest } from "../lib/agents-runner.ts";
|
|
11
|
+
import { fakeChild } from "./agents-fake-child.ts";
|
|
12
|
+
import { isolatedConfigEnv, removeIsolatedConfigHomes } from "./isolated-config-home.ts";
|
|
13
|
+
|
|
14
|
+
// Child background jobs (#2266): admission end to end. The runner only sets the
|
|
15
|
+
// job marker for a child that declares bash_background and is admitted by the
|
|
16
|
+
// background-subagents policy, and the child extension only registers its
|
|
17
|
+
// private job tools for that marker plus an owned IPC channel.
|
|
18
|
+
|
|
19
|
+
const gentleAgents: typeof installGentleAgents = (pi, env, overrides) => installGentleAgents(pi, isolatedConfigEnv(env), overrides);
|
|
20
|
+
after(removeIsolatedConfigHomes);
|
|
21
|
+
|
|
22
|
+
const explore: AgentDefinition = { name: "explore", description: "m", filePath: "/a/e.md", scope: "global", instructions: "x", model: undefined, thinking: undefined, mode: undefined, tools: ["read", "bash_background"] };
|
|
23
|
+
const tick = () => new Promise((resolve) => setImmediate(resolve));
|
|
24
|
+
|
|
25
|
+
// --- Runner admission (P-D) ------------------------------------------------
|
|
26
|
+
|
|
27
|
+
function build() {
|
|
28
|
+
const spawned: Array<{ env: NodeJS.ProcessEnv }> = [];
|
|
29
|
+
const deps: RunnerDeps = {
|
|
30
|
+
spawn: (_command, _args, options) => { spawned.push({ env: options.env }); return fakeChild({ exitOnKill: false, exitOnStdinEnd: false }).child; },
|
|
31
|
+
now: () => Date.now(),
|
|
32
|
+
schedule: () => () => undefined,
|
|
33
|
+
pi: { command: "pi", args: [] },
|
|
34
|
+
};
|
|
35
|
+
const store = new TaskStore();
|
|
36
|
+
const runner = new AgentRunner(store, { maxConcurrency: 2, stallTimeoutMs: 600_000 }, deps, { askUser: async () => ({ cancelled: true }) });
|
|
37
|
+
return { store, runner, spawned };
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
function request(root: string, env: NodeJS.ProcessEnv, mode = AGENT_MODE.TASK): TaskRequest {
|
|
41
|
+
return { agent: explore, prompt: "p", label: undefined, context: undefined, mode, cwd: root, parentSessionId: "s1", model: { provider: "p", id: "m" }, thinking: "high", sessionDir: "/s", resumeSessionPath: undefined, env: { GENTLE_PI_CONFIG_HOME: join(root, "config"), ...env } };
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
test("P-D policy off fails before spawn and never forwards the job capability", async (t) => {
|
|
45
|
+
const root = mkdtempSync(join(tmpdir(), "probe-admission-"));
|
|
46
|
+
t.after(() => rmSync(root, { recursive: true, force: true }));
|
|
47
|
+
const h = build();
|
|
48
|
+
const task = h.runner.run(request(root, {}));
|
|
49
|
+
await tick();
|
|
50
|
+
assert.equal(h.store.get(task.id)?.status, TASK_STATUS.FAILED);
|
|
51
|
+
assert.equal(h.store.get(task.id)?.error, `could not start pi: explicit tool bash_background requires background-subagents policy on. Set ${join(root, ".pi", "gentle-ai", "background-subagents.json")} to {"schema":"gentle-pi.background-subagents/v1","policy":"on"}; inspect or change policy with /gentle:background-subagents enable|disable|status.`);
|
|
52
|
+
assert.equal(h.spawned.length, 0, "nothing spawned, so no child env exists");
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
test("P-D policy on forwards exactly one job marker, and a malformed policy still refuses", async (t) => {
|
|
56
|
+
const root = mkdtempSync(join(tmpdir(), "probe-admission-"));
|
|
57
|
+
t.after(() => rmSync(root, { recursive: true, force: true }));
|
|
58
|
+
mkdirSync(join(root, "config"), { recursive: true });
|
|
59
|
+
const file = join(root, "config", "background-subagents.json");
|
|
60
|
+
writeFileSync(file, JSON.stringify({ schema: "gentle-pi.background-subagents/v1", policy: "on" }));
|
|
61
|
+
const on = build();
|
|
62
|
+
const task = on.runner.run(request(root, { GENTLE_PI_BACKGROUND_SUBAGENTS: "off" }));
|
|
63
|
+
await tick();
|
|
64
|
+
assert.equal(on.store.get(task.id)?.status, TASK_STATUS.RUNNING);
|
|
65
|
+
assert.equal(on.spawned.length, 1);
|
|
66
|
+
assert.equal(on.spawned[0]!.env[CHILD_JOBS_ENV], "1");
|
|
67
|
+
on.runner.cancel(task.id);
|
|
68
|
+
await tick();
|
|
69
|
+
|
|
70
|
+
writeFileSync(file, "{broken");
|
|
71
|
+
const raw = readFileSync(file, "utf8");
|
|
72
|
+
const broken = build();
|
|
73
|
+
const failed = broken.runner.run(request(root, {}));
|
|
74
|
+
await tick();
|
|
75
|
+
assert.equal(broken.store.get(failed.id)?.status, TASK_STATUS.FAILED);
|
|
76
|
+
assert.equal(broken.spawned.length, 0);
|
|
77
|
+
assert.equal(readFileSync(file, "utf8"), raw, "the policy file is never rewritten");
|
|
78
|
+
});
|
|
79
|
+
|
|
80
|
+
test("P-D an agent without bash_background never gets the job capability", async (t) => {
|
|
81
|
+
const root = mkdtempSync(join(tmpdir(), "probe-admission-"));
|
|
82
|
+
t.after(() => rmSync(root, { recursive: true, force: true }));
|
|
83
|
+
mkdirSync(join(root, "config"), { recursive: true });
|
|
84
|
+
writeFileSync(join(root, "config", "background-subagents.json"), JSON.stringify({ schema: "gentle-pi.background-subagents/v1", policy: "on" }));
|
|
85
|
+
const h = build();
|
|
86
|
+
const task = h.runner.run({ ...request(root, {}), agent: { ...explore, tools: ["read", "grep"] } });
|
|
87
|
+
await tick();
|
|
88
|
+
assert.equal(h.store.get(task.id)?.status, TASK_STATUS.RUNNING);
|
|
89
|
+
assert.equal(h.spawned[0]!.env[CHILD_JOBS_ENV], undefined);
|
|
90
|
+
h.runner.cancel(task.id);
|
|
91
|
+
await tick();
|
|
92
|
+
});
|
|
93
|
+
|
|
94
|
+
test("P-D a job marker inherited through request.env never reaches a child without bash_background", async (t) => {
|
|
95
|
+
const root = mkdtempSync(join(tmpdir(), "probe-admission-"));
|
|
96
|
+
t.after(() => rmSync(root, { recursive: true, force: true }));
|
|
97
|
+
mkdirSync(join(root, "config"), { recursive: true });
|
|
98
|
+
writeFileSync(join(root, "config", "background-subagents.json"), JSON.stringify({ schema: "gentle-pi.background-subagents/v1", policy: "on" }));
|
|
99
|
+
const h = build();
|
|
100
|
+
const task = h.runner.run({ ...request(root, { [CHILD_JOBS_ENV]: "1" }), agent: { ...explore, tools: ["read", "grep"] } });
|
|
101
|
+
await tick();
|
|
102
|
+
assert.equal(h.store.get(task.id)?.status, TASK_STATUS.RUNNING);
|
|
103
|
+
assert.equal(h.spawned.length, 1);
|
|
104
|
+
assert.equal(h.spawned[0]!.env[CHILD_JOBS_ENV], undefined, "a stale inherited marker is stripped, like the requested-tools marker");
|
|
105
|
+
h.runner.cancel(task.id);
|
|
106
|
+
await tick();
|
|
107
|
+
});
|
|
108
|
+
|
|
109
|
+
// --- Child extension registration (P-C) ------------------------------------
|
|
110
|
+
|
|
111
|
+
type Fake = ReturnType<typeof fakePi>;
|
|
112
|
+
|
|
113
|
+
function fakePi() {
|
|
114
|
+
const tools = new Map<string, any>();
|
|
115
|
+
const handlers = new Map<string, Array<(ctx?: any) => unknown>>();
|
|
116
|
+
const sent: Array<{ message: any; options: any }> = [];
|
|
117
|
+
const base: any = {
|
|
118
|
+
registerTool: (tool: any) => { tools.set(tool.name, tool); },
|
|
119
|
+
registerMessageRenderer: () => undefined,
|
|
120
|
+
registerCommand: () => undefined,
|
|
121
|
+
registerShortcut: () => undefined,
|
|
122
|
+
registerMarkdownTransformer: () => undefined,
|
|
123
|
+
appendEntry: () => undefined,
|
|
124
|
+
sendMessage: (message: any, options: any) => { sent.push({ message, options }); return true; },
|
|
125
|
+
events: { emit: () => undefined, on: () => () => undefined },
|
|
126
|
+
on: (event: string, handler: (ctx?: any) => unknown) => { handlers.set(event, [...(handlers.get(event) ?? []), handler]); return () => undefined; },
|
|
127
|
+
};
|
|
128
|
+
const api: any = new Proxy(base, { get: (target, prop) => (prop in target ? target[prop] : () => undefined) });
|
|
129
|
+
const fire = async (event: string, ctx?: any) => { for (const handler of handlers.get(event) ?? []) await handler(ctx); };
|
|
130
|
+
return { api, tools, handlers, sent, fire };
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
function fakeJobShell() {
|
|
134
|
+
const runs: Array<{ command: string; exit(code: number | null): void }> = [];
|
|
135
|
+
const dir = mkdtempSync(join(tmpdir(), "probe-child-jobs-"));
|
|
136
|
+
const shell = () => ({
|
|
137
|
+
operations: {
|
|
138
|
+
exec: (command: string, _cwd: string, options: { onData(data: Buffer): void; signal?: AbortSignal }) => new Promise<{ exitCode: number | null }>((done, fail) => {
|
|
139
|
+
options.signal?.addEventListener("abort", () => fail(new Error("aborted")), { once: true });
|
|
140
|
+
runs.push({ command, exit: (code) => done({ exitCode: code }) });
|
|
141
|
+
}),
|
|
142
|
+
},
|
|
143
|
+
});
|
|
144
|
+
return { runs, shell, dir, cleanup: () => rmSync(dir, { recursive: true, force: true }) };
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
function childEnv(extra: NodeJS.ProcessEnv = {}) {
|
|
148
|
+
return { GENTLE_PI_AGENTS_CHILD: "1", GENTLE_PI_AGENTS_OWNED_IPC: "probe-token", ...extra } as NodeJS.ProcessEnv;
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
function ownedIpc() {
|
|
152
|
+
const frames: Array<Record<string, unknown>> = [];
|
|
153
|
+
return { frames, ipc: { send: (frame: Record<string, unknown>) => { frames.push(frame); return true; }, on: () => undefined } };
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
const ctx = { cwd: "/repo", sessionManager: { getSessionId: () => "child-session" } } as any;
|
|
157
|
+
const toolNames = (pi: Fake) => [...pi.tools.keys()].sort();
|
|
158
|
+
|
|
159
|
+
for (const { label, env, ipc, expected } of [
|
|
160
|
+
{ label: "child + owned IPC + jobs=1", env: childEnv({ GENTLE_PI_AGENTS_CHILD_JOBS: "1" }), ipc: true, expected: ["bash_background", "job_list", "job_stop", "subagent_parent_message"] },
|
|
161
|
+
{ label: "child + owned IPC, no capability", env: childEnv(), ipc: true, expected: ["subagent_parent_message"] },
|
|
162
|
+
{ label: "child + jobs=1, no owned IPC", env: childEnv({ GENTLE_PI_AGENTS_CHILD_JOBS: "1" }), ipc: false, expected: [] },
|
|
163
|
+
{ label: 'child + owned IPC + jobs="true"', env: childEnv({ GENTLE_PI_AGENTS_CHILD_JOBS: "true" }), ipc: true, expected: ["subagent_parent_message"] },
|
|
164
|
+
{ label: 'child + owned IPC + jobs="0"', env: childEnv({ GENTLE_PI_AGENTS_CHILD_JOBS: "0" }), ipc: true, expected: ["subagent_parent_message"] },
|
|
165
|
+
{ label: 'child + owned IPC + jobs=""', env: childEnv({ GENTLE_PI_AGENTS_CHILD_JOBS: "" }), ipc: true, expected: ["subagent_parent_message"] },
|
|
166
|
+
]) {
|
|
167
|
+
test(`P-C registration gating: ${label}`, () => {
|
|
168
|
+
const pi = fakePi();
|
|
169
|
+
const jobs = fakeJobShell();
|
|
170
|
+
const wire = ownedIpc();
|
|
171
|
+
try {
|
|
172
|
+
gentleAgents(pi.api, env, { childIpc: ipc ? wire.ipc : undefined, jobShell: jobs.shell, jobOutputDir: () => jobs.dir });
|
|
173
|
+
assert.deepEqual(toolNames(pi), expected);
|
|
174
|
+
assert.equal(pi.tools.has("monitor"), false, "the monitor is never a child tool");
|
|
175
|
+
} finally { jobs.cleanup(); }
|
|
176
|
+
});
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
test("P-C child job reports go over the owned IPC and the notice stays in the child session", async () => {
|
|
180
|
+
const pi = fakePi();
|
|
181
|
+
const jobs = fakeJobShell();
|
|
182
|
+
const wire = ownedIpc();
|
|
183
|
+
try {
|
|
184
|
+
gentleAgents(pi.api, childEnv({ GENTLE_PI_AGENTS_CHILD_JOBS: "1" }), { childIpc: wire.ipc, jobShell: jobs.shell, jobOutputDir: () => jobs.dir, now: () => 1_000 });
|
|
185
|
+
await pi.tools.get("bash_background").execute("b1", { command: "gh run watch 7 --exit-status", label: "CI" }, undefined, undefined, ctx);
|
|
186
|
+
assert.deepEqual(wire.frames.at(-1), { id: "j1", kind: "job", message: '{"running":1,"pending":true}' });
|
|
187
|
+
await pi.fire("agent_settled", ctx);
|
|
188
|
+
assert.deepEqual(wire.frames.at(-1), { id: "j2", kind: "job", message: '{"running":1,"pending":true}' });
|
|
189
|
+
jobs.runs[0]!.exit(0);
|
|
190
|
+
await new Promise((done) => setTimeout(done, 60));
|
|
191
|
+
assert.deepEqual(wire.frames.at(-1), { id: "j3", kind: "job", message: '{"running":0,"pending":false}' });
|
|
192
|
+
const notice = pi.sent.at(-1)!;
|
|
193
|
+
assert.equal(notice.message.customType, "gentle-jobs.notice");
|
|
194
|
+
assert.deepEqual(notice.options, { deliverAs: "steer", triggerTurn: true });
|
|
195
|
+
// Nothing was routed to the parent model: the IPC frames carry state only.
|
|
196
|
+
assert.equal(wire.frames.every((frame) => frame.kind === "job"), true);
|
|
197
|
+
assert.equal(JSON.stringify(wire.frames).includes("gentle-jobs.notice"), false);
|
|
198
|
+
} finally { jobs.cleanup(); }
|
|
199
|
+
});
|
|
200
|
+
|
|
201
|
+
test("P-C a child job_list only sees its own session's jobs", async () => {
|
|
202
|
+
const pi = fakePi();
|
|
203
|
+
const jobs = fakeJobShell();
|
|
204
|
+
const wire = ownedIpc();
|
|
205
|
+
try {
|
|
206
|
+
gentleAgents(pi.api, childEnv({ GENTLE_PI_AGENTS_CHILD_JOBS: "1" }), { childIpc: wire.ipc, jobShell: jobs.shell, jobOutputDir: () => jobs.dir, now: () => 1_000 });
|
|
207
|
+
const other = { cwd: "/repo", sessionManager: { getSessionId: () => "other-session" } } as any;
|
|
208
|
+
await pi.tools.get("bash_background").execute("b1", { command: "sleep 1" }, undefined, undefined, ctx);
|
|
209
|
+
const listed = await pi.tools.get("job_list").execute("l1", {}, undefined, undefined, other);
|
|
210
|
+
assert.match(listed.content[0].text, /No background jobs in this session/);
|
|
211
|
+
const own = await pi.tools.get("job_list").execute("l2", {}, undefined, undefined, ctx);
|
|
212
|
+
assert.match(own.content[0].text, /job-1/);
|
|
213
|
+
await assert.rejects(() => pi.tools.get("job_stop").execute("s1", { job_id: "job-1" }, undefined, undefined, other), /No background job job-1 in this session/);
|
|
214
|
+
} finally { jobs.cleanup(); }
|
|
215
|
+
});
|
|
216
|
+
|
|
217
|
+
test("P-C the child's own job output directory is removed at session shutdown", async () => {
|
|
218
|
+
const pi = fakePi();
|
|
219
|
+
const jobs = fakeJobShell();
|
|
220
|
+
const wire = ownedIpc();
|
|
221
|
+
const root = mkdtempSync(join(tmpdir(), "probe-child-jobs-root-"));
|
|
222
|
+
const previous = process.env.TMPDIR;
|
|
223
|
+
process.env.TMPDIR = root;
|
|
224
|
+
try {
|
|
225
|
+
gentleAgents(pi.api, childEnv({ GENTLE_PI_AGENTS_CHILD_JOBS: "1" }), { childIpc: wire.ipc, jobShell: jobs.shell });
|
|
226
|
+
const result = await pi.tools.get("bash_background").execute("b1", { command: "echo hi" }, undefined, undefined, ctx);
|
|
227
|
+
const outputPath = String(result.content[0].text).match(/Output: (.+)/)![1]!.trim();
|
|
228
|
+
assert.match(outputPath, /gentle-jobs-/);
|
|
229
|
+
assert.equal(existsSync(dirname(outputPath)), true, "the private log directory exists while the child runs");
|
|
230
|
+
await pi.fire("session_shutdown", ctx);
|
|
231
|
+
assert.equal(existsSync(dirname(outputPath)), false, "the private log directory is removed at shutdown");
|
|
232
|
+
} finally {
|
|
233
|
+
if (previous === undefined) delete process.env.TMPDIR; else process.env.TMPDIR = previous;
|
|
234
|
+
rmSync(root, { recursive: true, force: true });
|
|
235
|
+
jobs.cleanup();
|
|
236
|
+
}
|
|
237
|
+
});
|