gentle-pi 4.7.0 → 4.9.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 +115 -44
- package/assets/agents/gentle-ai-explore.md +3 -3
- package/assets/agents/gentle-ai-verify.md +20 -6
- package/assets/agents/gentle-ai-worker.md +14 -13
- package/assets/agents/jd-judge-a.md +1 -3
- package/assets/agents/jd-judge-b.md +1 -3
- package/assets/agents/review-readability.md +1 -5
- package/assets/agents/review-reliability.md +1 -5
- package/assets/agents/review-resilience.md +1 -5
- package/assets/agents/review-risk.md +1 -5
- package/assets/design-canvas/canvas-api.js +45 -0
- package/assets/design-canvas/canvas-boards.js +476 -0
- package/assets/design-canvas/canvas-boot.js +219 -0
- package/assets/design-canvas/canvas-checks.js +491 -0
- package/assets/design-canvas/canvas-comments.js +315 -0
- package/assets/design-canvas/canvas-compare.js +159 -0
- package/assets/design-canvas/canvas-events.js +75 -0
- package/assets/design-canvas/canvas-export.js +393 -0
- package/assets/design-canvas/canvas-focus.js +203 -0
- package/assets/design-canvas/canvas-handoffs.js +150 -0
- package/assets/design-canvas/canvas-i18n-es.js +397 -0
- package/assets/design-canvas/canvas-i18n.js +108 -0
- package/assets/design-canvas/canvas-layout.js +526 -0
- package/assets/design-canvas/canvas-menu.js +219 -0
- package/assets/design-canvas/canvas-messages.js +86 -0
- package/assets/design-canvas/canvas-minimap.js +163 -0
- package/assets/design-canvas/canvas-parts.js +401 -0
- package/assets/design-canvas/canvas-popover.js +234 -0
- package/assets/design-canvas/canvas-rail.js +351 -0
- package/assets/design-canvas/canvas-sizes.js +524 -0
- package/assets/design-canvas/canvas-store.js +167 -0
- package/assets/design-canvas/canvas-theme.js +69 -0
- package/assets/design-canvas/canvas-tokens.js +674 -0
- package/assets/design-canvas/canvas-ui.js +24 -0
- package/assets/design-canvas/canvas-view.js +184 -0
- package/assets/design-canvas/canvas.css +773 -17
- package/assets/design-canvas/canvas.js +2 -1506
- package/assets/design-canvas/index.html +120 -36
- package/assets/design-canvas/inspector.js +574 -21
- package/assets/design-canvas/theme-early.js +10 -0
- package/assets/install-wizard/wizard.js +5 -1
- package/assets/migrations/agent-body-history.json +30 -0
- package/assets/orchestrator-delegation-reference.md +8 -14
- package/assets/orchestrator-delegation.md +5 -9
- package/assets/orchestrator-full-delegation-card.md +11 -16
- package/assets/orchestrator-full-delegation.md +9 -9
- package/assets/orchestrator-memory.md +4 -4
- package/assets/orchestrator-prompts.md +3 -31
- package/assets/orchestrator-quota-recovery.md +5 -0
- package/assets/orchestrator-skills.md +13 -12
- package/assets/orchestrator-tracking.md +13 -17
- package/assets/orchestrator-verification.md +12 -10
- package/assets/orchestrator-writer.md +13 -13
- package/assets/orchestrator.md +20 -24
- package/bin/gentle-shell.mjs +205 -10
- package/contracts/review-provider-contract-mirror/provider-contract.lock.json +8 -9
- package/contracts/review-provider-contract-mirror/{v1.4.0 → v1.6.0}/bundle/manifest.json +3 -3
- package/contracts/review-provider-contract-mirror/{v1.4.0 → v1.6.0}/bundle/orchestration/pi.md +2 -1
- package/contracts/review-provider-contract-mirror/{v1.4.0 → v1.6.0}/bundle/routing/pi.md +16 -16
- package/contracts/review-provider-contract-mirror/{v1.4.0 → v1.6.0}/generated/provider-capabilities.baseline.json +3 -3
- package/contracts/review-provider-contract-mirror/{v1.4.0 → v1.6.0}/generated/provider-roles.baseline.json +1 -1
- package/docs/assets/brand/sponsor-banner.svg +60 -0
- package/docs/assets/features/gentle-tower.png +0 -0
- package/docs/auto-permission-answers.md +1 -1
- package/docs/bundled-install.md +14 -6
- package/docs/delegated-verification.md +23 -5
- package/docs/desktop-feed.md +303 -0
- package/docs/desktop-rpc.md +1931 -0
- package/docs/fast-mode.md +2 -2
- package/docs/gentle-agents-activity.md +26 -0
- package/docs/gentle-shell-desktop.md +465 -0
- package/docs/gentle-shell.md +102 -17
- package/docs/images/desktop/chat.png +0 -0
- package/docs/images/desktop/palette.png +0 -0
- package/docs/images/desktop/todo.png +0 -0
- package/docs/install-wizard.md +30 -21
- package/docs/odd-preparation-continuity.md +24 -0
- package/docs/permission-modes.md +9 -1
- package/docs/prompt-budget.md +12 -0
- package/docs/rdd-odd-friction-triage-2026-11-07.md +57 -0
- package/docs/readme-reference.md +113 -32
- package/docs/review-coordinator.md +29 -9
- package/docs/review-delivery-preflight.md +22 -0
- package/docs/work-continuity.md +19 -6
- package/extensions/ask-user-choice.ts +36 -18
- package/extensions/ask-user-question.ts +48 -9
- package/extensions/child-context.ts +21 -7
- package/extensions/gentle-agents.ts +436 -66
- package/extensions/gentle-ai.ts +809 -158
- package/extensions/gentle-design.ts +69 -3
- package/extensions/gentle-desktop-feed.ts +778 -0
- package/extensions/gentle-desktop-rpc.ts +276 -0
- package/extensions/gentle-guide.ts +3 -0
- package/extensions/gentle-herdr-desktop-status.ts +275 -0
- package/extensions/gentle-shell.ts +174 -59
- package/extensions/gentle-stats.ts +30 -1
- package/extensions/gentle-todo.ts +48 -25
- package/extensions/gentle-tower.ts +305 -0
- package/extensions/skill-registry.ts +260 -225
- package/herdr/RECIPE.md +157 -0
- package/herdr/keys.json +14 -0
- package/herdr/layouts/gentle-shell.json +202 -0
- package/herdr/mods/gentle-agents/icons/kind-herdr.svg +1 -0
- package/herdr/mods/gentle-agents/icons/kind-remote.svg +1 -0
- package/herdr/mods/gentle-agents/icons/kind-tui.svg +1 -0
- package/herdr/mods/gentle-agents/main.js +190 -0
- package/herdr/mods/gentle-agents/mod.json +1 -0
- package/herdr/mods/gentle-agents/snapshot.js +469 -0
- package/herdr/mods/gentle-agents/tokens.js +273 -0
- package/herdr/mods/gentle-chat/MINIMAL.md +69 -0
- package/herdr/mods/gentle-chat/actions.js +180 -0
- package/herdr/mods/gentle-chat/feed.js +321 -0
- package/herdr/mods/gentle-chat/icons/branch.svg +1 -0
- package/herdr/mods/gentle-chat/icons/chat.svg +1 -0
- package/herdr/mods/gentle-chat/icons/check.svg +1 -0
- package/herdr/mods/gentle-chat/icons/chev.svg +1 -0
- package/herdr/mods/gentle-chat/icons/clip.svg +1 -0
- package/herdr/mods/gentle-chat/icons/down.svg +1 -0
- package/herdr/mods/gentle-chat/icons/folder.svg +1 -0
- package/herdr/mods/gentle-chat/icons/kind-herdr.svg +1 -0
- package/herdr/mods/gentle-chat/icons/kind-remote.svg +1 -0
- package/herdr/mods/gentle-chat/icons/kind-tui.svg +1 -0
- package/herdr/mods/gentle-chat/icons/mark.svg +1 -0
- package/herdr/mods/gentle-chat/icons/send.svg +1 -0
- package/herdr/mods/gentle-chat/icons/shield.svg +1 -0
- package/herdr/mods/gentle-chat/icons/stop.svg +1 -0
- package/herdr/mods/gentle-chat/icons/term.svg +1 -0
- package/herdr/mods/gentle-chat/icons/user.svg +1 -0
- package/herdr/mods/gentle-chat/icons/x.svg +1 -0
- package/herdr/mods/gentle-chat/main.js +968 -0
- package/herdr/mods/gentle-chat/mod.json +1 -0
- package/herdr/mods/gentle-chat/session.js +212 -0
- package/herdr/mods/gentle-chat/snapshot.js +469 -0
- package/herdr/mods/gentle-chat/tokens.js +137 -0
- package/herdr/mods/gentle-chat/ui.js +883 -0
- package/herdr/mods/gentle-confirm/main.js +60 -0
- package/herdr/mods/gentle-confirm/mod.json +1 -0
- package/herdr/mods/gentle-inspector/actions.js +180 -0
- package/herdr/mods/gentle-inspector/icons/bolt.svg +1 -0
- package/herdr/mods/gentle-inspector/icons/bot.svg +1 -0
- package/herdr/mods/gentle-inspector/icons/check.svg +1 -0
- package/herdr/mods/gentle-inspector/icons/db.svg +1 -0
- package/herdr/mods/gentle-inspector/icons/diff.svg +1 -0
- package/herdr/mods/gentle-inspector/icons/jobs.svg +1 -0
- package/herdr/mods/gentle-inspector/icons/plug.svg +1 -0
- package/herdr/mods/gentle-inspector/icons/review.svg +1 -0
- package/herdr/mods/gentle-inspector/icons/stats.svg +1 -0
- package/herdr/mods/gentle-inspector/icons/stop.svg +1 -0
- package/herdr/mods/gentle-inspector/icons/todo.svg +1 -0
- package/herdr/mods/gentle-inspector/main.js +500 -0
- package/herdr/mods/gentle-inspector/mod.json +1 -0
- package/herdr/mods/gentle-inspector/snapshot.js +469 -0
- package/herdr/mods/gentle-inspector/tokens.js +273 -0
- package/herdr/mods/gentle-palette/actions.js +180 -0
- package/herdr/mods/gentle-palette/icons/bolt.svg +1 -0
- package/herdr/mods/gentle-palette/icons/bot.svg +1 -0
- package/herdr/mods/gentle-palette/icons/chat.svg +1 -0
- package/herdr/mods/gentle-palette/icons/check.svg +1 -0
- package/herdr/mods/gentle-palette/icons/cmd.svg +1 -0
- package/herdr/mods/gentle-palette/icons/diff.svg +1 -0
- package/herdr/mods/gentle-palette/icons/jobs.svg +1 -0
- package/herdr/mods/gentle-palette/icons/plus.svg +1 -0
- package/herdr/mods/gentle-palette/icons/review.svg +1 -0
- package/herdr/mods/gentle-palette/icons/search.svg +1 -0
- package/herdr/mods/gentle-palette/icons/shield.svg +1 -0
- package/herdr/mods/gentle-palette/icons/stats.svg +1 -0
- package/herdr/mods/gentle-palette/icons/stop.svg +1 -0
- package/herdr/mods/gentle-palette/icons/term.svg +1 -0
- package/herdr/mods/gentle-palette/icons/todo.svg +1 -0
- package/herdr/mods/gentle-palette/main.js +333 -0
- package/herdr/mods/gentle-palette/mod.json +1 -0
- package/herdr/mods/gentle-palette/snapshot.js +469 -0
- package/herdr/mods/gentle-palette/tokens.js +273 -0
- package/herdr/mods/gentle-pane/icons/chat.svg +1 -0
- package/herdr/mods/gentle-pane/icons/close.svg +1 -0
- package/herdr/mods/gentle-pane/icons/kind-herdr.svg +1 -0
- package/herdr/mods/gentle-pane/icons/kind-remote.svg +1 -0
- package/herdr/mods/gentle-pane/icons/kind-tui.svg +1 -0
- package/herdr/mods/gentle-pane/icons/split-down.svg +1 -0
- package/herdr/mods/gentle-pane/icons/split-right.svg +1 -0
- package/herdr/mods/gentle-pane/icons/term.svg +1 -0
- package/herdr/mods/gentle-pane/icons/unzoom.svg +1 -0
- package/herdr/mods/gentle-pane/icons/zoom.svg +1 -0
- package/herdr/mods/gentle-pane/main.js +91 -0
- package/herdr/mods/gentle-pane/mod.json +1 -0
- package/herdr/mods/gentle-pane/snapshot.js +469 -0
- package/herdr/mods/gentle-pane/tokens.js +273 -0
- package/herdr/mods/gentle-sidebar/actions.js +180 -0
- package/herdr/mods/gentle-sidebar/icons/gear.svg +1 -0
- package/herdr/mods/gentle-sidebar/icons/mark.svg +1 -0
- package/herdr/mods/gentle-sidebar/icons/refresh.svg +1 -0
- package/herdr/mods/gentle-sidebar/icons/server-plus.svg +1 -0
- package/herdr/mods/gentle-sidebar/main.js +171 -0
- package/herdr/mods/gentle-sidebar/mod.json +1 -0
- package/herdr/mods/gentle-sidebar/snapshot.js +469 -0
- package/herdr/mods/gentle-sidebar/tokens.js +273 -0
- package/herdr/mods/gentle-spaces/icons/kind-herdr.svg +1 -0
- package/herdr/mods/gentle-spaces/icons/kind-remote.svg +1 -0
- package/herdr/mods/gentle-spaces/icons/kind-tui.svg +1 -0
- package/herdr/mods/gentle-spaces/icons/monitor.svg +1 -0
- package/herdr/mods/gentle-spaces/icons/plus.svg +1 -0
- package/herdr/mods/gentle-spaces/icons/server.svg +1 -0
- package/herdr/mods/gentle-spaces/machines.js +31 -0
- package/herdr/mods/gentle-spaces/main.js +299 -0
- package/herdr/mods/gentle-spaces/mod.json +1 -0
- package/herdr/mods/gentle-spaces/snapshot.js +469 -0
- package/herdr/mods/gentle-spaces/tokens.js +273 -0
- package/herdr/mods/gentle-status/actions.js +180 -0
- package/herdr/mods/gentle-status/main.js +192 -0
- package/herdr/mods/gentle-status/mod.json +1 -0
- package/herdr/mods/gentle-status/snapshot.js +469 -0
- package/herdr/mods/gentle-status/tokens.js +273 -0
- package/herdr/mods/gentle-tabs/icons/close.svg +1 -0
- package/herdr/mods/gentle-tabs/icons/kind-herdr.svg +1 -0
- package/herdr/mods/gentle-tabs/icons/kind-remote.svg +1 -0
- package/herdr/mods/gentle-tabs/icons/kind-tui.svg +1 -0
- package/herdr/mods/gentle-tabs/icons/plus.svg +1 -0
- package/herdr/mods/gentle-tabs/icons/win-close.svg +1 -0
- package/herdr/mods/gentle-tabs/icons/win-max.svg +1 -0
- package/herdr/mods/gentle-tabs/icons/win-min.svg +1 -0
- package/herdr/mods/gentle-tabs/icons/win-restore.svg +1 -0
- package/herdr/mods/gentle-tabs/main.js +171 -0
- package/herdr/mods/gentle-tabs/mod.json +1 -0
- package/herdr/mods/gentle-tabs/snapshot.js +469 -0
- package/herdr/mods/gentle-tabs/tokens.js +273 -0
- package/herdr/mods/gentle-tokens/main.js +20 -0
- package/herdr/mods/gentle-tokens/mod.json +1 -0
- package/herdr/mods/gentle-tokens/snapshot.js +469 -0
- package/herdr/mods/gentle-tokens/tokens.js +273 -0
- package/herdr/preview.png +0 -0
- package/herdr/themes/gentle-shell-dark.json +33 -0
- package/herdr/themes/gentle-shell-light.json +34 -0
- package/lib/agent-assets.ts +30 -6
- package/lib/agent-tool-overlay.ts +117 -0
- package/lib/agents-config.ts +47 -6
- package/lib/agents-message-delivery.ts +17 -0
- package/lib/agents-messaging.ts +8 -2
- package/lib/agents-protocol.ts +17 -0
- package/lib/agents-report-cap.ts +115 -0
- package/lib/agents-rpc-publisher.ts +39 -12
- package/lib/agents-runner.ts +92 -6
- package/lib/agents-session-transport.ts +17 -1
- package/lib/auto-permission-answers.ts +2 -1
- package/lib/background-jobs-tools.ts +9 -4
- package/lib/background-jobs.ts +22 -2
- package/lib/bounded-writer-admission.ts +184 -31
- package/lib/change-diff.ts +104 -0
- package/lib/child-context-files.ts +21 -6
- package/lib/codemode-renderer.ts +1 -0
- package/lib/commit-slice-signal.ts +1 -1
- package/lib/delivery-conflict-markers.ts +349 -0
- package/lib/design-canvas-assets.ts +38 -0
- package/lib/design-canvas-server.ts +241 -23
- package/lib/design-comments.ts +94 -4
- package/lib/design-handoffs.ts +2 -1
- package/lib/design-layout.ts +125 -0
- package/lib/design-parts.ts +281 -0
- package/lib/design-system-tokens.ts +111 -0
- package/lib/desktop-agents-service.ts +315 -0
- package/lib/desktop-changes-service.ts +171 -0
- package/lib/desktop-design-service.ts +233 -0
- package/lib/desktop-feed-actions.ts +804 -0
- package/lib/desktop-feed-answers.ts +129 -0
- package/lib/desktop-feed-sources.ts +184 -0
- package/lib/desktop-feed-stats.ts +98 -0
- package/lib/desktop-feed-store.ts +124 -0
- package/lib/desktop-feed.ts +788 -0
- package/lib/desktop-jobs-service.ts +290 -0
- package/lib/desktop-review-service.ts +187 -0
- package/lib/desktop-rpc-agents.ts +403 -0
- package/lib/desktop-rpc-changes.ts +223 -0
- package/lib/desktop-rpc-config-watch.ts +285 -0
- package/lib/desktop-rpc-config.ts +885 -0
- package/lib/desktop-rpc-design.ts +138 -0
- package/lib/desktop-rpc-jobs.ts +290 -0
- package/lib/desktop-rpc-permissions.ts +328 -0
- package/lib/desktop-rpc-profiles.ts +196 -0
- package/lib/desktop-rpc-review.ts +180 -0
- package/lib/desktop-rpc-session.ts +203 -0
- package/lib/desktop-rpc-sessions.ts +250 -0
- package/lib/desktop-rpc-stats.ts +187 -0
- package/lib/desktop-rpc-updates.ts +143 -0
- package/lib/desktop-rpc-usage.ts +229 -0
- package/lib/desktop-rpc.ts +336 -0
- package/lib/desktop-session-service.ts +223 -0
- package/lib/desktop-sessions-service.ts +249 -0
- package/lib/desktop-stats-service.ts +142 -0
- package/lib/desktop-updates-service.ts +268 -0
- package/lib/desktop-usage-service.ts +310 -0
- package/lib/destructive-command-guard.ts +188 -13
- package/lib/gentle-ai-renderer.ts +13 -1
- package/lib/gentle-design.ts +201 -14
- package/lib/gentle-shell-bundled.ts +100 -9
- package/lib/gentle-shell-desktop.ts +1370 -0
- package/lib/gentle-shell-launcher.ts +45 -3
- package/lib/herdr-desktop-events.ts +40 -0
- package/lib/herdr-desktop-status.ts +229 -0
- package/lib/hidden-tools.ts +35 -0
- package/lib/inprocess-reviewer.ts +96 -12
- package/lib/jobs-sidebar-state.ts +5 -0
- package/lib/model-fallback-policy.ts +9 -0
- package/lib/model-routing-authority.ts +9 -0
- package/lib/nan-provider.ts +42 -28
- package/lib/native-review-cli.ts +86 -4
- package/lib/openai-fast-tier.ts +1 -0
- package/lib/orchestrator-discovery.ts +39 -2
- package/lib/reply-language-anchor.ts +27 -2
- package/lib/request-context-placement.ts +53 -0
- package/lib/review-candidate-view.ts +11 -1
- package/lib/review-continuation-registry.ts +17 -0
- package/lib/review-coordinator.ts +252 -8
- package/lib/review-delivery-preflight.ts +85 -0
- package/lib/review-host-relay.ts +5 -1
- package/lib/review-integration-v2.ts +56 -3
- package/lib/reviewer-stream.ts +87 -0
- package/lib/session-profile-freeze.ts +13 -5
- package/lib/shell-prompt.ts +16 -3
- package/lib/shell-usage.ts +10 -0
- package/lib/stats-collector.ts +56 -27
- package/lib/tower-actions.ts +100 -0
- package/lib/tower-hub.ts +73 -0
- package/lib/tower-launch.ts +111 -0
- package/lib/tower-open.ts +99 -0
- package/lib/tower-presence.ts +70 -0
- package/lib/tower-server.ts +234 -0
- package/lib/tower-snapshot.ts +298 -0
- package/lib/update-status.ts +238 -0
- package/lib/verifier-settle-reminder.ts +1 -1
- package/lib/vim-editor-adapter.ts +9 -2
- package/lib/writer-batch-admission.ts +55 -0
- package/lib/yolo-session-policy.ts +6 -1
- package/package.json +14 -5
- package/prompts/skill-creation.md +1 -10
- package/runtime/design-canvas-assets.mjs +39 -0
- package/runtime/gentle-shell-bundled.mjs +100 -9
- package/runtime/gentle-shell-desktop.mjs +1371 -0
- package/runtime/gentle-shell-launcher.mjs +44 -2
- package/runtime/native-review-cli.mjs +86 -4
- package/runtime/review-integration-v2.mjs +56 -3
- package/runtime/tower-actions.mjs +101 -0
- package/runtime/tower-hub.mjs +74 -0
- package/runtime/tower-launch.mjs +112 -0
- package/runtime/tower-open.mjs +100 -0
- package/runtime/tower-presence.mjs +71 -0
- package/runtime/tower-server.mjs +234 -0
- package/runtime/tower-snapshot.mjs +299 -0
- package/scripts/bootstrap.cmd +2 -2
- package/scripts/bootstrap.sh +41 -4
- package/scripts/build-full-delegation-card.mjs +5 -21
- package/scripts/build-runtime-modules.mjs +10 -0
- package/scripts/gentle-ai-installer.mjs +10 -10
- package/scripts/gentle-ai-proxy.mjs +1 -1
- package/scripts/installer-downloads.mjs +34 -8
- package/scripts/installer-preflight.mjs +28 -17
- package/scripts/installer-probes.mjs +25 -5
- package/scripts/installer-server.mjs +38 -9
- package/scripts/installer-windows.mjs +2 -2
- package/scripts/pi-update.mjs +166 -27
- package/scripts/prepare-verifier.mjs +107 -0
- package/scripts/update-agent-body-history.mjs +55 -8
- package/scripts/verify-package-files.mjs +61 -20
- package/skills/branch-pr/SKILL.md +16 -16
- package/skills/comment-writer/SKILL.md +1 -1
- package/skills/design/SKILL.md +6 -6
- package/skills/gentle-ai/SKILL.md +5 -5
- package/skills/judgment-day/SKILL.md +2 -2
- package/skills/judgment-day/references/prompts-and-formats.md +1 -1
- package/skills/provider-defect-report/SKILL.md +61 -0
- package/skills/rdd-defect-workflow/SKILL.md +6 -6
- package/skills/skill-improver/SKILL.md +2 -2
- package/skills/skill-registry/SKILL.md +11 -13
- package/skills/tui-design/SKILL.md +1 -1
- package/skills/work-unit-commits/SKILL.md +5 -5
- package/tests/agent-prompt-diet-contract.test.ts +101 -0
- package/tests/agent-tool-overlay-acceptance.test.ts +158 -0
- package/tests/agent-tool-overlay.test.ts +89 -0
- package/tests/agents-config.test.ts +10 -1
- package/tests/agents-message-delivery.test.ts +36 -0
- package/tests/agents-queries.test.ts +144 -4
- package/tests/agents-report-cap.test.ts +126 -0
- package/tests/agents-runner.test.ts +37 -1
- package/tests/agents-session-transport.test.ts +34 -0
- package/tests/always-on-prompt-verdicts-contract.test.ts +188 -0
- package/tests/append-system-prompt-route.test.ts +26 -7
- package/tests/approved-text-leftovers-contract.test.ts +136 -0
- package/tests/artifact-language.test.ts +1 -1
- package/tests/ask-user-choice.test.ts +78 -21
- package/tests/ask-user-question.test.ts +61 -6
- package/tests/audit-leftovers-contract.test.ts +51 -0
- package/tests/auto-permission-answers.test.ts +12 -1
- package/tests/background-jobs.test.ts +12 -0
- package/tests/bounded-stop-contract.test.ts +148 -27
- package/tests/branch-pr-skill.test.ts +10 -1
- package/tests/bundled-install.test.ts +1 -1
- package/tests/change-diff.test.ts +75 -0
- package/tests/child-context-files.test.ts +64 -8
- package/tests/child-skills-catalog.test.ts +56 -0
- package/tests/codemode-rendering.test.ts +4 -1
- package/tests/commit-slice-signal.test.ts +3 -2
- package/tests/decision-routing-contract.test.ts +390 -0
- package/tests/delegate-for-reason-contract.test.ts +30 -8
- package/tests/delegated-key-learnings-contract.test.ts +21 -28
- package/tests/delivery-b-rendered-surfaces.test.ts +32 -0
- package/tests/delivery-conflict-markers.test.ts +348 -0
- package/tests/design-canvas-all-sizes.test.ts +631 -0
- package/tests/design-canvas-allowlist.test.ts +32 -0
- package/tests/design-canvas-assets.test.ts +11 -878
- package/tests/design-canvas-boards.test.ts +77 -0
- package/tests/design-canvas-checks.test.ts +655 -0
- package/tests/design-canvas-compare.test.ts +79 -0
- package/tests/design-canvas-events.test.ts +59 -0
- package/tests/design-canvas-export.test.ts +1168 -0
- package/tests/design-canvas-focus.test.ts +113 -0
- package/tests/design-canvas-handoffs.test.ts +59 -0
- package/tests/design-canvas-i18n-review.test.ts +513 -0
- package/tests/design-canvas-i18n-views.test.ts +259 -0
- package/tests/design-canvas-i18n.test.ts +528 -0
- package/tests/design-canvas-inspector.test.ts +1004 -0
- package/tests/design-canvas-layout.test.ts +1222 -0
- package/tests/design-canvas-minimap.test.ts +413 -0
- package/tests/design-canvas-modules.test.ts +91 -0
- package/tests/design-canvas-parts.test.ts +721 -0
- package/tests/design-canvas-rail.test.ts +799 -0
- package/tests/design-canvas-server.test.ts +855 -17
- package/tests/design-canvas-sizes.test.ts +548 -0
- package/tests/design-canvas-store.test.ts +189 -0
- package/tests/design-canvas-theme.test.ts +198 -0
- package/tests/design-canvas-tokens.test.ts +965 -0
- package/tests/design-canvas-view.test.ts +299 -0
- package/tests/design-comments.test.ts +201 -1
- package/tests/design-handoffs.test.ts +20 -0
- package/tests/design-layout.test.ts +100 -0
- package/tests/design-parts.test.ts +260 -0
- package/tests/design-system-tokens.test.ts +215 -0
- package/tests/desktop-feed-actions-guards.test.ts +595 -0
- package/tests/desktop-feed-actions.test.ts +761 -0
- package/tests/desktop-feed-live-work.test.ts +209 -0
- package/tests/desktop-feed-performance.test.ts +369 -0
- package/tests/desktop-feed-plan-profiles.test.ts +509 -0
- package/tests/desktop-feed-send-prompt.test.ts +303 -0
- package/tests/desktop-feed-tool-summaries.test.ts +69 -0
- package/tests/desktop-feed.test.ts +615 -0
- package/tests/desktop-rpc-agents.test.ts +1319 -0
- package/tests/desktop-rpc-changes.test.ts +608 -0
- package/tests/desktop-rpc-config-watch.test.ts +1159 -0
- package/tests/desktop-rpc-config.test.ts +1462 -0
- package/tests/desktop-rpc-design.test.ts +672 -0
- package/tests/desktop-rpc-jobs.test.ts +1193 -0
- package/tests/desktop-rpc-permissions.test.ts +321 -0
- package/tests/desktop-rpc-profiles.test.ts +140 -0
- package/tests/desktop-rpc-review.test.ts +678 -0
- package/tests/desktop-rpc-safety.test.ts +119 -0
- package/tests/desktop-rpc-session.test.ts +642 -0
- package/tests/desktop-rpc-sessions.test.ts +647 -0
- package/tests/desktop-rpc-stats.test.ts +431 -0
- package/tests/desktop-rpc-updates.test.ts +525 -0
- package/tests/desktop-rpc-usage.test.ts +707 -0
- package/tests/desktop-rpc.test.ts +293 -0
- package/tests/devbinary/pi-host-relay.devtest.ts +149 -80
- package/tests/devbinary/review-session-consent.devtest.ts +84 -0
- package/tests/engram-safety.test.ts +111 -0
- package/tests/fixtures/devbinary/status-v9-escalated-non-blocking.captured.json +92 -0
- package/tests/fixtures/devbinary/status-v9-escalated-non-blocking.provenance.md +3 -0
- package/tests/fixtures/primary-session-prompt/gentleman.golden.md +30 -41
- package/tests/fixtures/refusal-identity.probe.mjs +139 -0
- package/tests/fixtures/session-profile-v1/replay.ts +4 -1
- package/tests/full-delegation-closure.test.ts +48 -0
- package/tests/gentle-agents.test.ts +848 -8
- package/tests/gentle-ai-binary.test.ts +1 -1
- package/tests/gentle-ai-child-guards.test.ts +1 -0
- package/tests/gentle-ai-installer.test.ts +52 -51
- package/tests/gentle-ai-renderer.test.ts +36 -2
- package/tests/gentle-ai.test.ts +195 -21
- package/tests/gentle-design.test.ts +365 -1
- package/tests/gentle-fast.test.ts +15 -0
- package/tests/gentle-herdr-desktop-status.test.ts +595 -0
- package/tests/gentle-shell-bundled.test.ts +91 -5
- package/tests/gentle-shell-desktop-bin.test.ts +125 -0
- package/tests/gentle-shell-desktop.test.ts +927 -0
- package/tests/gentle-shell-launcher-tower.test.ts +104 -0
- package/tests/gentle-shell-launcher.test.ts +1 -1
- package/tests/gentle-shell.test.ts +121 -87
- package/tests/gentle-todo.test.ts +32 -9
- package/tests/gentle-tower.test.ts +578 -0
- package/tests/herdr-desktop-status.test.ts +285 -0
- package/tests/hidden-tools.test.ts +188 -0
- package/tests/independent-recovery-delivery.test.ts +35 -9
- package/tests/inprocess-reviewer.test.ts +73 -0
- package/tests/install-wizard.test.ts +27 -1
- package/tests/installer-downloads.test.ts +30 -1
- package/tests/installer-posix-bootstrap.test.ts +114 -13
- package/tests/installer-preflight.test.ts +49 -1
- package/tests/installer-probes.test.ts +146 -0
- package/tests/installer-server.test.ts +203 -4
- package/tests/installer-windows-bootstrap.test.ts +19 -1
- package/tests/judgment-day-severity-admission.test.ts +46 -0
- package/tests/lazy-module-contradictions-contract.test.ts +181 -0
- package/tests/maintainer/desktop-rpc.maintest.ts +907 -0
- package/tests/maintainer/pi-update-source.maintest.ts +48 -18
- package/tests/model-fallback-policy.test.ts +26 -7
- package/tests/nan-provider-runtime.test.ts +17 -3
- package/tests/nan-provider.test.ts +111 -56
- package/tests/native-review-capability-contract.test.ts +19 -1
- package/tests/native-review-cli-nonblocking-findings.test.ts +165 -0
- package/tests/native-review-parity.test.ts +24 -5
- package/tests/native-review-refusal-identity.test.ts +25 -0
- package/tests/no-self-pause-contract.test.ts +33 -15
- package/tests/odd-integration.test.ts +11 -3
- package/tests/odd-routing-canonical-ratchet.test.ts +10 -0
- package/tests/odd-routing-contract.test.ts +99 -31
- package/tests/orchestrator-budget.test.ts +32 -5
- package/tests/orchestrator-consultation-sdk.test.ts +32 -6
- package/tests/orchestrator-delegation-mode.test.ts +2 -1
- package/tests/orchestrator-discovery.test.ts +28 -0
- package/tests/orchestrator-prompt-budget.test.ts +12 -2
- package/tests/orchestrator-prompt-diet-contract.test.ts +249 -0
- package/tests/orchestrator-rdd-ownership.test.ts +2 -1
- package/tests/orchestrator-work-search.test.ts +4 -2
- package/tests/package-files.test.ts +25 -1
- package/tests/package-manifest.test.ts +15 -14
- package/tests/parallel-reason-contract.test.ts +6 -3
- package/tests/permission-allowlist.test.ts +200 -30
- package/tests/persona-neutral-voseo.test.ts +4 -4
- package/tests/persona-reply-language.test.ts +1 -1
- package/tests/persona-single-channel.test.ts +13 -5
- package/tests/pi-routing-measured-values.test.ts +24 -0
- package/tests/pi-update-launcher.test.ts +17 -7
- package/tests/pi-update-source.test.ts +113 -6
- package/tests/pi-update.test.ts +294 -19
- package/tests/pnpm-workspace-policy.test.ts +47 -0
- package/tests/primary-context-files.test.ts +233 -0
- package/tests/primary-context-three-files.test.ts +174 -0
- package/tests/primary-session-prompt.test.ts +25 -0
- package/tests/profile-fast-tier.test.ts +66 -1
- package/tests/provider-defect-handoff.test.ts +124 -99
- package/tests/rdd-aware-verification-contract.test.ts +1 -1
- package/tests/rdd-status-line.test.ts +94 -1
- package/tests/reply-language-anchor-placement.test.ts +184 -0
- package/tests/reply-language-anchor.test.ts +17 -1
- package/tests/request-context-append-only.test.ts +218 -0
- package/tests/request-context-placement.test.ts +148 -0
- package/tests/review-agent-end-preflight.test.ts +79 -1
- package/tests/review-candidate-view.test.ts +65 -0
- package/tests/review-continuation-registry.test.ts +31 -0
- package/tests/review-contract-prompt.test.ts +2 -1
- package/tests/review-controller.test.ts +2 -1
- package/tests/review-coordinator-correction-gate.test.ts +105 -0
- package/tests/review-coordinator-findings.test.ts +206 -0
- package/tests/review-coordinator-nonblocking-scope.test.ts +169 -0
- package/tests/review-coordinator.test.ts +271 -4
- package/tests/review-delivery-preflight.test.ts +462 -0
- package/tests/review-due-compaction.test.ts +31 -0
- package/tests/review-due-public-boundary.test.ts +27 -0
- package/tests/review-integration-nonblocking-findings.test.ts +108 -0
- package/tests/review-json-arguments.test.ts +41 -2
- package/tests/review-ledger-contract.test.ts +19 -40
- package/tests/review-loadout-rdd-off-sdk.test.ts +30 -1
- package/tests/review-one-call-findings.test.ts +131 -0
- package/tests/review-one-call-followups.test.ts +308 -0
- package/tests/review-one-call-reviewer-requests.test.ts +207 -0
- package/tests/review-one-call.test.ts +452 -0
- package/tests/review-relay-transport-agent.test.ts +28 -1
- package/tests/review-reviewer-evidence.test.ts +41 -1
- package/tests/review-risk-assessment.test.ts +52 -5
- package/tests/review-run-statement-guidance-independent.test.ts +54 -0
- package/tests/review-session-standing-permission-controller.test.ts +32 -2
- package/tests/review-tool-prose-budget.test.ts +1 -0
- package/tests/reviewer-stream.test.ts +149 -0
- package/tests/sensitive-path-tools.test.ts +138 -4
- package/tests/session-profile-extension.test.ts +312 -18
- package/tests/session-profile-freeze.test.ts +26 -0
- package/tests/session-profile-v1-compat.test.ts +20 -0
- package/tests/shell-prompt.test.ts +17 -0
- package/tests/shell-usage.test.ts +59 -10
- package/tests/skill-collision-prefixes.test.ts +1 -0
- package/tests/skill-contradictions-contract.test.ts +124 -0
- package/tests/skill-registry-watcher.test.ts +216 -2
- package/tests/skill-registry.test.ts +983 -306
- package/tests/stats-collector.test.ts +109 -2
- package/tests/support/design-canvas-dom.ts +386 -0
- package/tests/support/review-coordinator-runtime.ts +212 -17
- package/tests/task-size-routing-contract.test.ts +49 -14
- package/tests/test-strength-contract.test.ts +2 -1
- package/tests/todo-request-append-only.test.ts +214 -0
- package/tests/tool-batching-contract.test.ts +3 -1
- package/tests/tower-actions.test.ts +247 -0
- package/tests/tower-artifacts.test.ts +114 -0
- package/tests/tower-open.test.ts +97 -0
- package/tests/tower-presence.test.ts +175 -0
- package/tests/tower-server.test.ts +122 -0
- package/tests/tower-snapshot.test.ts +236 -0
- package/tests/tower-web-echo.test.ts +125 -0
- package/tests/tower-web-hover.test.ts +251 -0
- package/tests/update-agent-body-history.test.ts +138 -0
- package/tests/verification-scoped-stop-contract.test.ts +32 -0
- package/tests/verification-tiers-contract.test.ts +229 -0
- package/tests/verifier-preparation.test.ts +229 -0
- package/tests/verifier-settle-reminder.test.ts +2 -2
- package/tests/verify-agent-contract.test.ts +20 -2
- package/tests/verify-first-launch-contract.test.ts +88 -12
- package/tests/vim-editor-adapter.test.ts +2 -2
- package/tests/work-continuity-contract.test.ts +136 -27
- package/tests/writer-admission-messages.test.ts +232 -0
- package/tests/writer-batch-admission.test.ts +66 -0
- package/tests/writer-edit-surface-scope.test.ts +52 -20
- package/tests/writer-feature-document-admission.test.ts +184 -0
- package/tests/writer-rejection-next-step.test.ts +55 -0
- package/tests/writer-surface-authority-contract.test.ts +158 -0
- package/tests/yolo-mode.test.ts +39 -0
- package/skills/_shared/review-ledger-contract.md +0 -106
- /package/contracts/review-provider-contract-mirror/{v1.4.0 → v1.6.0}/bundle/README.md +0 -0
- /package/contracts/review-provider-contract-mirror/{v1.4.0 → v1.6.0}/bundle/schemas/lens.schema.json +0 -0
- /package/contracts/review-provider-contract-mirror/{v1.4.0 → v1.6.0}/bundle/schemas/refuter.schema.json +0 -0
- /package/contracts/review-provider-contract-mirror/{v1.4.0 → v1.6.0}/bundle/schemas/targeted-validator.schema.json +0 -0
- /package/contracts/review-provider-contract-mirror/{v1.4.0 → v1.6.0}/bundle/vectors/lens.json +0 -0
- /package/contracts/review-provider-contract-mirror/{v1.4.0 → v1.6.0}/bundle/vectors/refuter.json +0 -0
- /package/contracts/review-provider-contract-mirror/{v1.4.0 → v1.6.0}/bundle/vectors/targeted-validator.json +0 -0
|
@@ -0,0 +1,761 @@
|
|
|
1
|
+
import assert from "node:assert/strict";
|
|
2
|
+
import { existsSync, mkdirSync, mkdtempSync, readdirSync, readFileSync, rmSync, statSync, symlinkSync, utimesSync, writeFileSync } from "node:fs";
|
|
3
|
+
import { tmpdir } from "node:os";
|
|
4
|
+
import { join } from "node:path";
|
|
5
|
+
import { test } from "node:test";
|
|
6
|
+
import type { ExtensionAPI } from "@earendil-works/pi-coding-agent";
|
|
7
|
+
import { createDesktopFeedExtension, type DesktopFeedOptions } from "../extensions/gentle-desktop-feed.ts";
|
|
8
|
+
import desktopRpc from "../extensions/gentle-desktop-rpc.ts";
|
|
9
|
+
import {
|
|
10
|
+
answerKeys,
|
|
11
|
+
DESKTOP_ACTION_RESULT_SCHEMA,
|
|
12
|
+
DESKTOP_ACTION_SCHEMA,
|
|
13
|
+
desktopActionInboxDir,
|
|
14
|
+
desktopActionOutboxDir,
|
|
15
|
+
parseDesktopAction,
|
|
16
|
+
questionShape,
|
|
17
|
+
runDesktopAction,
|
|
18
|
+
sweepDesktopActionOrphans,
|
|
19
|
+
type DesktopActionOwners,
|
|
20
|
+
} from "../lib/desktop-feed-actions.ts";
|
|
21
|
+
import type { DesktopFeedSnapshot, DesktopFeedTimers } from "../lib/desktop-feed.ts";
|
|
22
|
+
import { DESKTOP_FEED_BUILTIN_COMMANDS } from "../lib/desktop-feed.ts";
|
|
23
|
+
import { desktopFeedFile } from "../lib/desktop-feed-store.ts";
|
|
24
|
+
import { publishChoiceAnswerHandle, publishQuestionnaireAnswerHandle } from "../lib/desktop-feed-answers.ts";
|
|
25
|
+
import { DESKTOP_AGENTS_SERVICE_CHANNEL, DESKTOP_AGENTS_SERVICE_SCHEMA } from "../lib/desktop-rpc-agents.ts";
|
|
26
|
+
import { DESKTOP_JOBS_SERVICE_CHANNEL, DESKTOP_JOBS_SERVICE_SCHEMA, type DesktopJobEntry } from "../lib/desktop-rpc-jobs.ts";
|
|
27
|
+
import { DESKTOP_RPC_SCHEMA, type DesktopRpcOutcome } from "../lib/desktop-rpc.ts";
|
|
28
|
+
import { INTERACTIVE_HOST_ENV } from "../lib/rpc-host.ts";
|
|
29
|
+
import { NOTIFICATION_ATTENTION_EVENT } from "../lib/notification-events.ts";
|
|
30
|
+
import { registerYoloSessionPolicy } from "../lib/yolo-session-policy.ts";
|
|
31
|
+
|
|
32
|
+
// T7 (odd/tasks/herdr-desktop.md, S2/S5): the desktop's actions reach a live
|
|
33
|
+
// Gentle Shell session through a private per-session inbox, and every action
|
|
34
|
+
// goes through the same owner the desktop RPC already uses — never around it.
|
|
35
|
+
|
|
36
|
+
const NOW = Date.UTC(2026, 10, 15, 12, 0, 0);
|
|
37
|
+
const settle = () => new Promise((resolve) => setTimeout(resolve, 150));
|
|
38
|
+
const GENTLE_ENV = { PI_PROGRAM_STATUS_APP: "gentle-shell", HERDR_ENV: "1", HERDR_PANE_ID: "t7" };
|
|
39
|
+
|
|
40
|
+
// ---- Harness ----
|
|
41
|
+
|
|
42
|
+
function fakeTimers() {
|
|
43
|
+
const pending = new Map<number, () => void>();
|
|
44
|
+
let next = 0;
|
|
45
|
+
const timers: DesktopFeedTimers = {
|
|
46
|
+
set(fn) { next += 1; pending.set(next, fn); return next; },
|
|
47
|
+
clear(handle) { pending.delete(handle as number); },
|
|
48
|
+
};
|
|
49
|
+
return { timers, get armed() { return pending.size; }, run() { const fns = [...pending.values()]; pending.clear(); for (const fn of fns) fn(); } };
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
function fakeBus() {
|
|
53
|
+
const listeners = new Map<string, Set<(data: unknown) => void>>();
|
|
54
|
+
return {
|
|
55
|
+
on(name: string, fn: (data: unknown) => void) {
|
|
56
|
+
const set = listeners.get(name) ?? new Set();
|
|
57
|
+
set.add(fn);
|
|
58
|
+
listeners.set(name, set);
|
|
59
|
+
return () => { set.delete(fn); };
|
|
60
|
+
},
|
|
61
|
+
emit(name: string, data: unknown) { for (const fn of [...(listeners.get(name) ?? [])]) fn(data); },
|
|
62
|
+
};
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
type Handler = (event: any, ctx: any) => unknown;
|
|
66
|
+
function fakePi() {
|
|
67
|
+
const bus = fakeBus();
|
|
68
|
+
const handlers = new Map<string, Handler[]>();
|
|
69
|
+
const commands = new Map<string, { handler: (args: string, ctx: any) => Promise<void> }>();
|
|
70
|
+
// What pi.sendUserMessage received (T11 send_prompt).
|
|
71
|
+
const sent: Array<{ content: unknown; options: unknown }> = [];
|
|
72
|
+
// pi refuses a prompt while it compacts (agent-session prompt(): "Cannot submit a prompt
|
|
73
|
+
// while compaction is in progress") and its runtime swallows the error (V9).
|
|
74
|
+
const refused: Array<{ content: unknown; options: unknown }> = [];
|
|
75
|
+
const state = { compacting: false };
|
|
76
|
+
const pi = {
|
|
77
|
+
on(name: string, fn: Handler) { handlers.set(name, [...(handlers.get(name) ?? []), fn]); return () => {}; },
|
|
78
|
+
events: bus,
|
|
79
|
+
registerCommand(name: string, command: any) { commands.set(name, command); },
|
|
80
|
+
registerTool() {},
|
|
81
|
+
getThinkingLevel: () => "high",
|
|
82
|
+
sendUserMessage(content: unknown, options: unknown) { (state.compacting ? refused : sent).push({ content, options }); },
|
|
83
|
+
} as unknown as ExtensionAPI;
|
|
84
|
+
const fire = (name: string, event: unknown, ctx: unknown) => { for (const fn of handlers.get(name) ?? []) fn(event, ctx); };
|
|
85
|
+
return { pi, bus, commands, fire, sent, refused, setCompacting(value: boolean) { state.compacting = value; } };
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
function fakeCtx(cwd: string, overrides: Record<string, unknown> = {}) {
|
|
89
|
+
const widgets: Array<{ key: string; lines: string[] }> = [];
|
|
90
|
+
const notices: string[] = [];
|
|
91
|
+
return {
|
|
92
|
+
cwd, mode: "tui", hasUI: true,
|
|
93
|
+
isIdle: () => true,
|
|
94
|
+
model: { id: "claude-opus-5-5", provider: "anthropic", reasoning: true, contextWindow: 200_000 },
|
|
95
|
+
modelRegistry: { isUsingOAuth: () => true },
|
|
96
|
+
getContextUsage: () => ({ tokens: 1000, contextWindow: 200_000, percent: 0.5 }),
|
|
97
|
+
ui: {
|
|
98
|
+
setWidget(key: string, lines: string[]) { widgets.push({ key, lines }); },
|
|
99
|
+
setStatus() {},
|
|
100
|
+
notify(message: string) { notices.push(message); },
|
|
101
|
+
select: async () => undefined,
|
|
102
|
+
getAllThemes: () => [{}],
|
|
103
|
+
confirm: async () => true,
|
|
104
|
+
},
|
|
105
|
+
widgets, notices,
|
|
106
|
+
sessionManager: {
|
|
107
|
+
getSessionId: () => "sess-1",
|
|
108
|
+
getSessionFile: () => "/agent/sessions/--w--/2026_sess-1.jsonl",
|
|
109
|
+
getSessionName: () => undefined,
|
|
110
|
+
getCwd: () => cwd,
|
|
111
|
+
getBranch: () => [],
|
|
112
|
+
getEntries: () => [],
|
|
113
|
+
getLeafId: () => null,
|
|
114
|
+
},
|
|
115
|
+
...overrides,
|
|
116
|
+
};
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
interface OwnerCalls { cancelJob: string[]; cancelSubagent: string[] }
|
|
120
|
+
|
|
121
|
+
/** Minimal jobs and agents owners speaking the existing owner-service contracts. */
|
|
122
|
+
function fakeOwners(bus: ReturnType<typeof fakeBus>, calls: OwnerCalls, idle = false) {
|
|
123
|
+
// `idle`: the job and the subagent have finished, so nothing of the session runs (T7 escalations).
|
|
124
|
+
const job: DesktopJobEntry = idle ? { id: "j1", label: "npm test", status: "exited", startedAt: 1, endedAt: 2 } : { id: "j1", label: "npm test", status: "running", startedAt: 1 };
|
|
125
|
+
bus.on(DESKTOP_JOBS_SERVICE_CHANNEL, (payload) => {
|
|
126
|
+
(payload as { respond(service: unknown): void }).respond({
|
|
127
|
+
schema: DESKTOP_JOBS_SERVICE_SCHEMA,
|
|
128
|
+
read: () => ({ sessionId: "sess-1", jobs: [job] }),
|
|
129
|
+
cancel: (id: string) => { calls.cancelJob.push(id); return id === "j1" ? { kind: "ok", job: { ...job, status: "stopped", endedAt: 2 }, changed: true } : { kind: "not_found" }; },
|
|
130
|
+
observe: () => () => {},
|
|
131
|
+
dispose: () => {},
|
|
132
|
+
});
|
|
133
|
+
});
|
|
134
|
+
const agent = { id: "a1", agent: "gentle-writer", status: idle ? "completed" : "running", model: "sonnet", lastStep: "writing", usage: { total: 10, cost: 0.1 } };
|
|
135
|
+
bus.on(DESKTOP_AGENTS_SERVICE_CHANNEL, (payload) => {
|
|
136
|
+
(payload as { respond(service: unknown): void }).respond({
|
|
137
|
+
schema: DESKTOP_AGENTS_SERVICE_SCHEMA,
|
|
138
|
+
read: () => ({ sessionId: "sess-1", agents: [agent] }),
|
|
139
|
+
cancel: (id: string) => { calls.cancelSubagent.push(id); return id === "a1" ? { kind: "ok", agent, requested: true, changed: false } : { kind: "not_found" }; },
|
|
140
|
+
observe: () => () => {},
|
|
141
|
+
dispose: () => {},
|
|
142
|
+
});
|
|
143
|
+
});
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
function harness(t: test.TestContext, { idle, ...options }: Partial<DesktopFeedOptions> & { owner?: "real" | "refusing" | "none"; idle?: boolean } = {}) {
|
|
147
|
+
const root = mkdtempSync(join(tmpdir(), "desktop-actions-"));
|
|
148
|
+
t.after(() => rmSync(root, { recursive: true, force: true }));
|
|
149
|
+
const agentDir = join(root, "agent");
|
|
150
|
+
const workspace = join(root, "workspace");
|
|
151
|
+
const configHome = join(root, "config");
|
|
152
|
+
mkdirSync(workspace, { recursive: true });
|
|
153
|
+
mkdirSync(configHome, { recursive: true });
|
|
154
|
+
const clock = fakeTimers();
|
|
155
|
+
const h = fakePi();
|
|
156
|
+
const calls: OwnerCalls = { cancelJob: [], cancelSubagent: [] };
|
|
157
|
+
const setModes: string[] = [];
|
|
158
|
+
fakeOwners(h.bus, calls, idle);
|
|
159
|
+
const ownerEnv = { ...GENTLE_ENV, GENTLE_PI_CONFIG_HOME: configHome };
|
|
160
|
+
if ((options.owner ?? "real") === "real") {
|
|
161
|
+
// Count every owner setMode the adapter receives without changing what it
|
|
162
|
+
// does (registered first, so it wraps the request before the owner answers).
|
|
163
|
+
h.bus.on("gentle:yolo:host-ui", (payload) => {
|
|
164
|
+
const request = payload as { respond(adapter: unknown): void };
|
|
165
|
+
const original = request.respond;
|
|
166
|
+
request.respond = (adapter: any) => {
|
|
167
|
+
if (adapter && typeof adapter.setMode === "function") {
|
|
168
|
+
const setMode = adapter.setMode;
|
|
169
|
+
adapter.setMode = async (mode: string) => { setModes.push(mode); return setMode(mode); };
|
|
170
|
+
}
|
|
171
|
+
original(adapter);
|
|
172
|
+
};
|
|
173
|
+
});
|
|
174
|
+
registerYoloSessionPolicy(h.pi, ownerEnv, { resolveIdentity: async () => "workspace:test" });
|
|
175
|
+
} else if (options.owner === "refusing") {
|
|
176
|
+
h.bus.on("gentle:yolo:host-ui", (payload) => {
|
|
177
|
+
(payload as { respond(adapter: unknown): void }).respond({
|
|
178
|
+
read: async () => "OFF",
|
|
179
|
+
readSnapshot: async () => ({ yolo: "OFF", mode: "normal", defaultMode: "normal" }),
|
|
180
|
+
setMode: async (mode: string) => { setModes.push(mode); return false; },
|
|
181
|
+
toggle: async () => {},
|
|
182
|
+
observe: () => () => {},
|
|
183
|
+
dispose: () => {},
|
|
184
|
+
});
|
|
185
|
+
});
|
|
186
|
+
}
|
|
187
|
+
let fireWatch: (() => void) | undefined;
|
|
188
|
+
let watchClosed = 0;
|
|
189
|
+
createDesktopFeedExtension({
|
|
190
|
+
env: GENTLE_ENV,
|
|
191
|
+
agentDir,
|
|
192
|
+
now: () => NOW,
|
|
193
|
+
timers: clock.timers,
|
|
194
|
+
git: () => async () => ({ stdout: "", code: 128 }),
|
|
195
|
+
parentOf: async () => undefined,
|
|
196
|
+
profile: () => ({ name: undefined, tier: undefined }),
|
|
197
|
+
realpath: (path) => path,
|
|
198
|
+
sweep: () => {},
|
|
199
|
+
actionWatch: (_dir, onChange) => { fireWatch = onChange; return () => { watchClosed += 1; }; },
|
|
200
|
+
...options,
|
|
201
|
+
})(h.pi);
|
|
202
|
+
const ctx = fakeCtx(workspace);
|
|
203
|
+
const inbox = desktopActionInboxDir(agentDir, "sess-1");
|
|
204
|
+
const outbox = desktopActionOutboxDir(agentDir, "sess-1");
|
|
205
|
+
const feedFile = desktopFeedFile(agentDir, "sess-1");
|
|
206
|
+
const action = (id: string, kind: string, args: Record<string, unknown>, extra: Record<string, unknown> = {}) =>
|
|
207
|
+
JSON.stringify({ schema: DESKTOP_ACTION_SCHEMA, id, sessionId: "sess-1", kind, args, createdAt: new Date(NOW - 1000).toISOString(), ...extra });
|
|
208
|
+
return {
|
|
209
|
+
...h, ctx, clock, agentDir, inbox, outbox, calls, setModes,
|
|
210
|
+
get watchClosed() { return watchClosed; },
|
|
211
|
+
start: async () => { h.fire("session_start", { reason: "startup" }, ctx); await settle(); clock.run(); await settle(); clock.run(); },
|
|
212
|
+
drop(name: string, text: string) { writeFileSync(join(inbox, name), text); },
|
|
213
|
+
action,
|
|
214
|
+
/** Fire the inbox watch, let the owners answer, flush the debounced snapshot. */
|
|
215
|
+
async deliver() { fireWatch?.(); await settle(); await settle(); clock.run(); },
|
|
216
|
+
result(id: string) {
|
|
217
|
+
const file = join(outbox, `${id}.json`);
|
|
218
|
+
return existsSync(file) ? JSON.parse(readFileSync(file, "utf8")) : undefined;
|
|
219
|
+
},
|
|
220
|
+
// The session's pid marker (`.owner`) is not an action.
|
|
221
|
+
inboxFiles: () => readdirSync(inbox).filter((name) => !name.startsWith(".")),
|
|
222
|
+
snapshot: () => JSON.parse(readFileSync(feedFile, "utf8")) as DesktopFeedSnapshot,
|
|
223
|
+
};
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
// ---- The inbox ----
|
|
227
|
+
|
|
228
|
+
test("S2: the session creates a private inbox and outbox, and removes them when it ends", async (t) => {
|
|
229
|
+
const h = harness(t);
|
|
230
|
+
await h.start();
|
|
231
|
+
assert.equal(statSync(h.inbox).mode & 0o777, 0o700);
|
|
232
|
+
assert.equal(statSync(h.outbox).mode & 0o777, 0o700);
|
|
233
|
+
h.fire("session_shutdown", { reason: "quit" }, h.ctx);
|
|
234
|
+
assert.equal(existsSync(h.inbox), false);
|
|
235
|
+
assert.equal(existsSync(h.outbox), false);
|
|
236
|
+
assert.equal(h.watchClosed, 1);
|
|
237
|
+
});
|
|
238
|
+
|
|
239
|
+
test("S2: set_permission_mode goes through the permission owner once and the snapshot follows it", async (t) => {
|
|
240
|
+
const h = harness(t, { idle: true });
|
|
241
|
+
await h.start();
|
|
242
|
+
assert.equal(h.snapshot().permission!.mode, "normal");
|
|
243
|
+
h.drop("p1.json", h.action("p1", "set_permission_mode", { mode: "super-yolo" }));
|
|
244
|
+
await h.deliver();
|
|
245
|
+
assert.deepEqual(h.setModes, ["super-yolo"], "the owner decides, once");
|
|
246
|
+
assert.deepEqual(h.inboxFiles(), [], "the handled file is removed");
|
|
247
|
+
const result = h.result("p1");
|
|
248
|
+
assert.equal(result.schema, DESKTOP_ACTION_RESULT_SCHEMA);
|
|
249
|
+
assert.equal(result.id, "p1");
|
|
250
|
+
assert.equal(result.kind, "set_permission_mode");
|
|
251
|
+
assert.equal(result.ok, true);
|
|
252
|
+
assert.equal(result.data.mode, "super-yolo");
|
|
253
|
+
assert.equal(statSync(join(h.outbox, "p1.json")).mode & 0o777, 0o600);
|
|
254
|
+
assert.equal(h.snapshot().permission!.mode, "super-yolo");
|
|
255
|
+
h.drop("p2.json", h.action("p2", "set_permission_mode", { mode: "normal" }));
|
|
256
|
+
await h.deliver();
|
|
257
|
+
assert.deepEqual(h.setModes, ["super-yolo", "normal"]);
|
|
258
|
+
assert.equal(h.snapshot().permission!.mode, "normal");
|
|
259
|
+
});
|
|
260
|
+
|
|
261
|
+
test("S2: an owner refusal of super-yolo is reported and changes nothing", async (t) => {
|
|
262
|
+
const h = harness(t, { owner: "refusing", idle: true });
|
|
263
|
+
await h.start();
|
|
264
|
+
h.drop("p1.json", h.action("p1", "set_permission_mode", { mode: "super-yolo" }));
|
|
265
|
+
await h.deliver();
|
|
266
|
+
assert.deepEqual(h.setModes, ["super-yolo"]);
|
|
267
|
+
assert.deepEqual(h.result("p1").error, { code: "permission_denied", message: "Permission mode unchanged for this session" });
|
|
268
|
+
assert.equal(h.result("p1").ok, false);
|
|
269
|
+
assert.equal(h.snapshot().permission!.mode, "normal");
|
|
270
|
+
assert.deepEqual(h.inboxFiles(), []);
|
|
271
|
+
});
|
|
272
|
+
|
|
273
|
+
test("S2: cancel_job and cancel_subagent call their owners exactly once with the id", async (t) => {
|
|
274
|
+
const h = harness(t);
|
|
275
|
+
await h.start();
|
|
276
|
+
h.drop("c1.json", h.action("c1", "cancel_job", { id: "j1" }));
|
|
277
|
+
h.drop("c2.json", h.action("c2", "cancel_subagent", { id: "a1" }));
|
|
278
|
+
await h.deliver();
|
|
279
|
+
assert.deepEqual(h.calls.cancelJob, ["j1"]);
|
|
280
|
+
assert.deepEqual(h.calls.cancelSubagent, ["a1"]);
|
|
281
|
+
assert.equal(h.result("c1").ok, true);
|
|
282
|
+
assert.equal(h.result("c1").data.job.status, "stopped");
|
|
283
|
+
assert.equal(h.result("c2").ok, true);
|
|
284
|
+
assert.equal(h.result("c2").data.agent.id, "a1");
|
|
285
|
+
h.drop("c3.json", h.action("c3", "cancel_job", { id: "nope" }));
|
|
286
|
+
await h.deliver();
|
|
287
|
+
assert.equal(h.result("c3").ok, false);
|
|
288
|
+
assert.equal(h.result("c3").error.code, "not_found");
|
|
289
|
+
assert.deepEqual(h.inboxFiles(), []);
|
|
290
|
+
});
|
|
291
|
+
|
|
292
|
+
test("S2: a crashed session's inbox and outbox are swept once they are old and its snapshot is gone", (t) => {
|
|
293
|
+
const agentDir = mkdtempSync(join(tmpdir(), "desktop-actions-sweep-"));
|
|
294
|
+
t.after(() => rmSync(agentDir, { recursive: true, force: true }));
|
|
295
|
+
const old = (Date.now() - 11 * 60_000) / 1000;
|
|
296
|
+
const make = (session: string, age: number | undefined, snapshot: boolean) => {
|
|
297
|
+
for (const dir of [desktopActionInboxDir(agentDir, session), desktopActionOutboxDir(agentDir, session)]) {
|
|
298
|
+
mkdirSync(dir, { recursive: true, mode: 0o700 });
|
|
299
|
+
writeFileSync(join(dir, "x.json"), "{}");
|
|
300
|
+
if (age !== undefined) utimesSync(dir, age, age);
|
|
301
|
+
}
|
|
302
|
+
if (snapshot) { mkdirSync(join(agentDir, "desktop", "sessions"), { recursive: true }); writeFileSync(desktopFeedFile(agentDir, session), "{}"); }
|
|
303
|
+
};
|
|
304
|
+
make("dead", old, false);
|
|
305
|
+
make("fresh", undefined, false);
|
|
306
|
+
make("alive", old, true);
|
|
307
|
+
make("mine", old, false);
|
|
308
|
+
sweepDesktopActionOrphans(agentDir, "mine");
|
|
309
|
+
assert.equal(existsSync(desktopActionInboxDir(agentDir, "dead")), false);
|
|
310
|
+
assert.equal(existsSync(desktopActionOutboxDir(agentDir, "dead")), false);
|
|
311
|
+
for (const kept of ["fresh", "alive", "mine"]) {
|
|
312
|
+
assert.ok(existsSync(desktopActionInboxDir(agentDir, kept)), kept);
|
|
313
|
+
assert.ok(existsSync(desktopActionOutboxDir(agentDir, kept)), kept);
|
|
314
|
+
}
|
|
315
|
+
});
|
|
316
|
+
|
|
317
|
+
// ---- Guards: each rejection has no side effect ----
|
|
318
|
+
|
|
319
|
+
test("S2: rejected actions never reach an owner, are removed and answer why", async (t) => {
|
|
320
|
+
const h = harness(t);
|
|
321
|
+
await h.start();
|
|
322
|
+
const target = join(h.agentDir, "target.json");
|
|
323
|
+
writeFileSync(target, h.action("g1", "cancel_job", { id: "j1" }));
|
|
324
|
+
symlinkSync(target, join(h.inbox, "g1.json"));
|
|
325
|
+
h.drop("g2.json", h.action("g2", "cancel_job", { id: "j1" }, { pad: "x".repeat(17 * 1024) }));
|
|
326
|
+
h.drop("g3.json", h.action("g3", "cancel_job", { id: "j1" }, { createdAt: new Date(NOW - 61_000).toISOString() }));
|
|
327
|
+
h.drop("g4.json", h.action("g4", "run_shell", { command: "rm -rf /" }));
|
|
328
|
+
h.drop("g5.json", h.action("g5", "cancel_job", { id: "j1" }, { sessionId: "other" }));
|
|
329
|
+
h.drop("g6.json", h.action("g6", "set_permission_mode", { mode: "super-yolo", persist: true, extra: 1 }));
|
|
330
|
+
h.drop("g7.json", h.action("g7", "answer_question", { toolCallId: "call-1", option: 0 }));
|
|
331
|
+
h.drop("g8.json", h.action("g8", "cancel_job", { id: "j1" }, { createdAt: new Date(NOW + 60_000).toISOString() }));
|
|
332
|
+
h.drop("g9.json", h.action("other-id", "cancel_job", { id: "j1" }));
|
|
333
|
+
await h.deliver();
|
|
334
|
+
assert.deepEqual(h.calls, { cancelJob: [], cancelSubagent: [] });
|
|
335
|
+
assert.deepEqual(h.setModes, []);
|
|
336
|
+
assert.equal(h.snapshot().permission!.mode, "normal");
|
|
337
|
+
assert.deepEqual(h.inboxFiles(), []);
|
|
338
|
+
assert.ok(existsSync(target), "a symlink is removed, never followed");
|
|
339
|
+
const codes = Object.fromEntries(["g1", "g2", "g3", "g4", "g5", "g6", "g7", "g8", "g9"].map((id) => [id, h.result(id)?.error?.code]));
|
|
340
|
+
assert.deepEqual(codes, {
|
|
341
|
+
g1: "unsafe_file", g2: "too_large", g3: "stale", g4: "unknown_kind", g5: "wrong_session",
|
|
342
|
+
g6: "invalid_action", g7: "question_mismatch", g8: "stale", g9: "invalid_action",
|
|
343
|
+
});
|
|
344
|
+
});
|
|
345
|
+
|
|
346
|
+
test("S2: an id seen before is refused, so an action never runs twice", async (t) => {
|
|
347
|
+
const h = harness(t);
|
|
348
|
+
await h.start();
|
|
349
|
+
h.drop("d1.json", h.action("d1", "cancel_job", { id: "j1" }));
|
|
350
|
+
await h.deliver();
|
|
351
|
+
h.drop("d1.json", h.action("d1", "cancel_job", { id: "j1" }));
|
|
352
|
+
await h.deliver();
|
|
353
|
+
assert.deepEqual(h.calls.cancelJob, ["j1"]);
|
|
354
|
+
assert.equal(h.result("d1").error.code, "duplicate");
|
|
355
|
+
});
|
|
356
|
+
|
|
357
|
+
test("S2: a half-written file waits for the rest instead of being rejected", async (t) => {
|
|
358
|
+
const h = harness(t);
|
|
359
|
+
await h.start();
|
|
360
|
+
const full = h.action("w1", "cancel_job", { id: "j1" });
|
|
361
|
+
h.drop("w1.json", full.slice(0, 20));
|
|
362
|
+
await h.deliver();
|
|
363
|
+
assert.deepEqual(h.inboxFiles(), ["w1.json"]);
|
|
364
|
+
assert.equal(h.result("w1"), undefined);
|
|
365
|
+
writeFileSync(join(h.inbox, "w1.json"), full);
|
|
366
|
+
h.clock.run(); // the retry armed for the partial file
|
|
367
|
+
await settle();
|
|
368
|
+
assert.deepEqual(h.calls.cancelJob, ["j1"]);
|
|
369
|
+
assert.deepEqual(h.inboxFiles(), []);
|
|
370
|
+
});
|
|
371
|
+
|
|
372
|
+
// ---- Stop the agent's turn (T10, S9: the TUI's Esc Esc) ----
|
|
373
|
+
|
|
374
|
+
test("S9: abort_turn stops a working turn through the session's own abort, once", async (t) => {
|
|
375
|
+
const h = harness(t);
|
|
376
|
+
await h.start();
|
|
377
|
+
let aborts = 0;
|
|
378
|
+
let idle = false;
|
|
379
|
+
Object.assign(h.ctx, { isIdle: () => idle, abort: () => { aborts += 1; } });
|
|
380
|
+
h.drop("s1.json", h.action("s1", "abort_turn", {}));
|
|
381
|
+
await h.deliver();
|
|
382
|
+
assert.equal(aborts, 1);
|
|
383
|
+
assert.deepEqual(h.result("s1"), { schema: DESKTOP_ACTION_RESULT_SCHEMA, id: "s1", sessionId: "sess-1", kind: "abort_turn", ok: true, data: { aborted: true }, finishedAt: new Date(NOW).toISOString() });
|
|
384
|
+
assert.deepEqual(h.inboxFiles(), []);
|
|
385
|
+
idle = true;
|
|
386
|
+
h.drop("s2.json", h.action("s2", "abort_turn", {}));
|
|
387
|
+
h.drop("s3.json", h.action("s3", "abort_turn", { force: true }));
|
|
388
|
+
await h.deliver();
|
|
389
|
+
assert.equal(aborts, 1, "an idle session or a malformed action aborts nothing");
|
|
390
|
+
assert.deepEqual(h.result("s2").error, { code: "not_working", message: "The agent is not working" });
|
|
391
|
+
assert.equal(h.result("s3").error.code, "invalid_action");
|
|
392
|
+
assert.deepEqual(h.inboxFiles(), []);
|
|
393
|
+
assert.deepEqual(h.calls, { cancelJob: [], cancelSubagent: [] }, "no other owner is reached");
|
|
394
|
+
assert.deepEqual(h.setModes, []);
|
|
395
|
+
});
|
|
396
|
+
|
|
397
|
+
// ---- Questions ----
|
|
398
|
+
|
|
399
|
+
test("S5: answer_question answers only the open question with the keys the real list takes", async (t) => {
|
|
400
|
+
const h = harness(t);
|
|
401
|
+
await h.start();
|
|
402
|
+
h.fire("tool_execution_start", { toolCallId: "call-9", toolName: "ask_user_choice", args: { question: "Which?", options: [{ label: "A", value: "x" }, { label: "B", value: "y" }, { label: "C", value: "z" }], allowCustomResponse: true } }, h.ctx);
|
|
403
|
+
h.drop("q1.json", h.action("q1", "answer_question", { toolCallId: "call-9", option: 1 }));
|
|
404
|
+
h.drop("q2.json", h.action("q2", "answer_question", { toolCallId: "call-8", option: 0 }));
|
|
405
|
+
h.drop("q3.json", h.action("q3", "answer_question", { toolCallId: "call-9", option: 3 }));
|
|
406
|
+
await h.deliver();
|
|
407
|
+
// NativeChoiceList clamps: four ups reach the top from anywhere, one down is option 2.
|
|
408
|
+
assert.deepEqual(h.result("q1"), { schema: DESKTOP_ACTION_RESULT_SCHEMA, id: "q1", sessionId: "sess-1", kind: "answer_question", ok: true, data: { toolCallId: "call-9", keys: ["up", "up", "up", "up", "down", "enter"] }, finishedAt: new Date(NOW).toISOString() });
|
|
409
|
+
assert.equal(h.result("q2").error.code, "question_mismatch");
|
|
410
|
+
assert.equal(h.result("q3").error.code, "invalid_action");
|
|
411
|
+
h.drop("q4.json", h.action("q4", "answer_question", { toolCallId: "call-9", text: "my own" }));
|
|
412
|
+
await h.deliver();
|
|
413
|
+
assert.deepEqual(h.result("q4").data, { toolCallId: "call-9", keys: ["up", "up", "up", "up", "down", "down", "down", "enter"], text: "my own" });
|
|
414
|
+
h.fire("tool_execution_end", { toolCallId: "call-9", toolName: "ask_user_choice", isError: false, result: {} }, h.ctx);
|
|
415
|
+
h.drop("q5.json", h.action("q5", "answer_question", { toolCallId: "call-9", option: 0 }));
|
|
416
|
+
await h.deliver();
|
|
417
|
+
assert.equal(h.result("q5").error.code, "question_mismatch", "a closed question cannot be answered");
|
|
418
|
+
});
|
|
419
|
+
|
|
420
|
+
test("S5: multi-question, multi-select and consent prompts are answered in the terminal", () => {
|
|
421
|
+
const multi = questionShape("ask_user_question", "q", { questions: [{ question: "a", options: [{ label: "1" }, { label: "2" }] }, { question: "b", options: [{ label: "1" }, { label: "2" }] }] })!;
|
|
422
|
+
assert.deepEqual(answerKeys(multi, { option: 0 }), { error: { code: "answer_in_terminal", message: "Answer this question in the Terminal view" } });
|
|
423
|
+
const select = questionShape("ask_user_question", "q", { questions: [{ question: "a", multiSelect: true, options: [{ label: "1" }, { label: "2" }] }] })!;
|
|
424
|
+
assert.equal("error" in answerKeys(select, { option: 0 }), true);
|
|
425
|
+
const single = questionShape("ask_user_question", "q", { questions: [{ question: "a", options: [{ label: "1" }, { label: "2" }] }] })!;
|
|
426
|
+
assert.deepEqual(answerKeys(single, { option: 1 }), { keys: ["up", "up", "up", "down", "enter"] });
|
|
427
|
+
const noCustom = questionShape("ask_user_choice", "c", { question: "a", options: [{ label: "1" }, { label: "2" }] })!;
|
|
428
|
+
assert.equal("error" in answerKeys(noCustom, { text: "x" }), true, "free text only where the list offers it");
|
|
429
|
+
assert.equal(questionShape("bash", "b", {}), undefined);
|
|
430
|
+
});
|
|
431
|
+
|
|
432
|
+
// ---- Pure parsing and dispatch ----
|
|
433
|
+
|
|
434
|
+
test("S2: parseDesktopAction checks schema, id, session, kind, args and age", () => {
|
|
435
|
+
const base = { schema: DESKTOP_ACTION_SCHEMA, id: "a-1", sessionId: "s", kind: "cancel_job", args: { id: "j" }, createdAt: new Date(NOW).toISOString() };
|
|
436
|
+
assert.deepEqual(parseDesktopAction(JSON.stringify(base), "s", NOW), { ok: true, action: { id: "a-1", sessionId: "s", kind: "cancel_job", args: { id: "j" }, createdAt: NOW } });
|
|
437
|
+
const code = (value: unknown) => { const r = parseDesktopAction(JSON.stringify(value), "s", NOW); return "error" in r ? r.error.code : "ok"; };
|
|
438
|
+
assert.equal(code({ ...base, schema: "other" }), "invalid_action");
|
|
439
|
+
assert.equal(code({ ...base, id: "../x" }), "invalid_action");
|
|
440
|
+
assert.equal(code({ ...base, args: { id: "" } }), "invalid_action");
|
|
441
|
+
assert.equal(code({ ...base, args: { id: "j", more: 1 } }), "invalid_action");
|
|
442
|
+
assert.equal(code({ ...base, kind: "set_permission_mode", args: { mode: "root" } }), "invalid_action");
|
|
443
|
+
assert.equal(code({ ...base, kind: "answer_question", args: { toolCallId: "c", option: 0, text: "x" } }), "invalid_action");
|
|
444
|
+
assert.equal(code({ ...base, kind: "abort_turn", args: {} }), "ok");
|
|
445
|
+
assert.equal(code({ ...base, kind: "abort_turn", args: { id: "j" } }), "invalid_action");
|
|
446
|
+
assert.equal(parseDesktopAction("{", "s", NOW).ok, false);
|
|
447
|
+
});
|
|
448
|
+
|
|
449
|
+
test("S2: runDesktopAction calls only the owner its kind names", async () => {
|
|
450
|
+
const seen: string[] = [];
|
|
451
|
+
const answer = (name: string) => async (value: string): Promise<DesktopRpcOutcome> => { seen.push(`${name}:${value}`); return { ok: true, data: { value } }; };
|
|
452
|
+
let working = true;
|
|
453
|
+
const owners: DesktopActionOwners = { setPermissionMode: answer("mode"), cancelJob: answer("job"), cancelSubagent: answer("agent"), question: () => undefined, working: () => working, abortTurn: () => { seen.push("abort"); }, permissionMode: () => "normal", busyAt: () => false, confirmEscalation: async () => true };
|
|
454
|
+
const run = (kind: string, args: Record<string, unknown>) => runDesktopAction({ id: "x", sessionId: "s", kind: kind as never, args, createdAt: NOW }, owners);
|
|
455
|
+
assert.deepEqual(await run("set_permission_mode", { mode: "auto" }), { ok: true, data: { value: "auto" } });
|
|
456
|
+
assert.deepEqual(await run("cancel_job", { id: "j" }), { ok: true, data: { value: "j" } });
|
|
457
|
+
assert.deepEqual(await run("cancel_subagent", { id: "a" }), { ok: true, data: { value: "a" } });
|
|
458
|
+
assert.deepEqual(await run("abort_turn", {}), { ok: true, data: { aborted: true } });
|
|
459
|
+
working = false;
|
|
460
|
+
assert.deepEqual(await run("abort_turn", {}), { ok: false, error: { code: "not_working", message: "The agent is not working" } });
|
|
461
|
+
assert.deepEqual(seen, ["mode:auto", "job:j", "agent:a", "abort"]);
|
|
462
|
+
const failing: DesktopActionOwners = { ...owners, cancelJob: async () => { throw new Error("/secret/path exploded"); } };
|
|
463
|
+
const failed = await runDesktopAction({ id: "x", sessionId: "s", kind: "cancel_job", args: { id: "j" }, createdAt: NOW }, failing);
|
|
464
|
+
assert.deepEqual(failed, { ok: false, error: { code: "owner_failed", message: "The session could not run this action" } });
|
|
465
|
+
});
|
|
466
|
+
|
|
467
|
+
// ---- Existing desktop RPC behaviour is unchanged ----
|
|
468
|
+
|
|
469
|
+
|
|
470
|
+
/** Channel lines other than the feed's session_snapshot events, without the shared event counter. */
|
|
471
|
+
function withoutSessionSnapshots(lines: Array<string | undefined>): unknown[] {
|
|
472
|
+
return lines
|
|
473
|
+
.map((line) => JSON.parse(line!) as Record<string, unknown>)
|
|
474
|
+
.filter((line) => line.event !== "session_snapshot")
|
|
475
|
+
.map(({ seq: _seq, ...line }) => line);
|
|
476
|
+
}
|
|
477
|
+
|
|
478
|
+
test("S2: desktop RPC set_permission_mode answers are byte-identical with the feed and its inbox loaded", async (t) => {
|
|
479
|
+
const previous = process.env[INTERACTIVE_HOST_ENV];
|
|
480
|
+
process.env[INTERACTIVE_HOST_ENV] = "1";
|
|
481
|
+
t.after(() => { if (previous === undefined) delete process.env[INTERACTIVE_HOST_ENV]; else process.env[INTERACTIVE_HOST_ENV] = previous; });
|
|
482
|
+
const run = async (withFeed: boolean) => {
|
|
483
|
+
const root = mkdtempSync(join(tmpdir(), "desktop-actions-rpc-"));
|
|
484
|
+
t.after(() => rmSync(root, { recursive: true, force: true }));
|
|
485
|
+
mkdirSync(join(root, "w"));
|
|
486
|
+
mkdirSync(join(root, "config"));
|
|
487
|
+
const h = fakePi();
|
|
488
|
+
registerYoloSessionPolicy(h.pi, { ...GENTLE_ENV, GENTLE_PI_CONFIG_HOME: join(root, "config"), [INTERACTIVE_HOST_ENV]: "1" }, { resolveIdentity: async () => "workspace:test" });
|
|
489
|
+
desktopRpc(h.pi);
|
|
490
|
+
const clock = fakeTimers();
|
|
491
|
+
if (withFeed) createDesktopFeedExtension({ env: { ...GENTLE_ENV, [INTERACTIVE_HOST_ENV]: "1" }, agentDir: join(root, "agent"), timers: clock.timers, git: () => async () => ({ stdout: "", code: 128 }), parentOf: async () => undefined, profile: () => ({ name: undefined, tier: undefined }), sweep: () => {}, actionWatch: () => () => {} })(h.pi);
|
|
492
|
+
const ctx = fakeCtx(join(root, "w"), { mode: "rpc" });
|
|
493
|
+
h.fire("session_start", { reason: "startup" }, ctx);
|
|
494
|
+
await settle();
|
|
495
|
+
for (const [requestId, params] of [["r1", { mode: "super-yolo" }], ["r2", { mode: "normal" }], ["r3", { mode: "nope" }]] as const) {
|
|
496
|
+
await h.commands.get("gentle:desktop")!.handler(JSON.stringify({ schema: DESKTOP_RPC_SCHEMA, requestId, method: "set_permission_mode", params }), ctx);
|
|
497
|
+
}
|
|
498
|
+
clock.run();
|
|
499
|
+
return ctx.widgets.filter((widget) => widget.key === "gentle-desktop-rpc").map((widget) => widget.lines[0]);
|
|
500
|
+
};
|
|
501
|
+
const without = await run(false);
|
|
502
|
+
const withFeed = await run(true);
|
|
503
|
+
// #3319: the feed also publishes its own session_snapshot events on the
|
|
504
|
+
// channel; every other line is unchanged, in the same order.
|
|
505
|
+
assert.deepEqual(withoutSessionSnapshots(withFeed), withoutSessionSnapshots(without));
|
|
506
|
+
assert.equal(without.length, 5, "two answers with their events and one refusal");
|
|
507
|
+
});
|
|
508
|
+
|
|
509
|
+
// ---- T11: sessions outside Herdr app (S10) ----
|
|
510
|
+
|
|
511
|
+
test("S10: send_prompt types the text into the session through pi, steering while the agent works", async (t) => {
|
|
512
|
+
const h = harness(t);
|
|
513
|
+
await h.start();
|
|
514
|
+
Object.assign(h.pi, { getCommands: () => [{ name: "gentle:mode", source: "extension" }, { name: "review", source: "prompt" }] });
|
|
515
|
+
h.drop("p1.json", h.action("p1", "send_prompt", { text: "hola" }));
|
|
516
|
+
await h.deliver();
|
|
517
|
+
assert.deepEqual(h.sent, [{ content: "hola", options: { deliverAs: "steer", expandPromptTemplates: false } }]);
|
|
518
|
+
assert.deepEqual(h.result("p1"), { schema: DESKTOP_ACTION_RESULT_SCHEMA, id: "p1", sessionId: "sess-1", kind: "send_prompt", ok: true, data: { queued: false }, finishedAt: new Date(NOW).toISOString() });
|
|
519
|
+
Object.assign(h.ctx, { isIdle: () => false });
|
|
520
|
+
h.fire("agent_start", {}, h.ctx);
|
|
521
|
+
h.drop("p2.json", h.action("p2", "send_prompt", { text: "/review the parser" }));
|
|
522
|
+
await h.deliver();
|
|
523
|
+
assert.deepEqual(h.sent[1], { content: "/review the parser", options: { deliverAs: "steer", expandPromptTemplates: true } });
|
|
524
|
+
assert.deepEqual(h.result("p2").data, { queued: true });
|
|
525
|
+
h.drop("p3.json", h.action("p3", "send_prompt", { text: "/gentle:mode super-yolo" }));
|
|
526
|
+
h.drop("p4.json", h.action("p4", "send_prompt", { text: "/new" }));
|
|
527
|
+
await h.deliver();
|
|
528
|
+
assert.equal(h.result("p3").error.code, "terminal_command");
|
|
529
|
+
assert.equal(h.result("p4").error.code, "terminal_command");
|
|
530
|
+
assert.equal(h.sent.length, 2, "no command reached pi");
|
|
531
|
+
assert.deepEqual(h.setModes, [], "the permission owner was never asked");
|
|
532
|
+
assert.deepEqual(h.inboxFiles(), []);
|
|
533
|
+
});
|
|
534
|
+
|
|
535
|
+
test("S10: send_prompt is refused while a question, an extension prompt or a consent is open", async (t) => {
|
|
536
|
+
const h = harness(t);
|
|
537
|
+
await h.start();
|
|
538
|
+
h.fire("tool_execution_start", { toolCallId: "call-1", toolName: "ask_user_choice", args: { question: "Which?", options: [{ label: "A", value: "a" }, { label: "B", value: "b" }] } }, h.ctx);
|
|
539
|
+
h.drop("p1.json", h.action("p1", "send_prompt", { text: "A" }));
|
|
540
|
+
await h.deliver();
|
|
541
|
+
assert.deepEqual(h.result("p1").error, { code: "question_open", message: "Answer the open question first." });
|
|
542
|
+
h.fire("tool_execution_end", { toolCallId: "call-1", toolName: "ask_user_choice", isError: false, result: {} }, h.ctx);
|
|
543
|
+
h.fire("ui_prompt_start", { title: "Continue?", kind: "confirm" }, h.ctx);
|
|
544
|
+
h.drop("p2.json", h.action("p2", "send_prompt", { text: "yes" }));
|
|
545
|
+
await h.deliver();
|
|
546
|
+
assert.equal(h.result("p2").error.code, "question_open");
|
|
547
|
+
h.fire("ui_prompt_end", {}, h.ctx);
|
|
548
|
+
h.bus.emit(NOTIFICATION_ATTENTION_EVENT, { active: true, label: "Review consent" });
|
|
549
|
+
h.drop("p3.json", h.action("p3", "send_prompt", { text: "yes" }));
|
|
550
|
+
await h.deliver();
|
|
551
|
+
assert.equal(h.result("p3").error.code, "question_open");
|
|
552
|
+
assert.deepEqual(h.sent, []);
|
|
553
|
+
});
|
|
554
|
+
|
|
555
|
+
test("S10: answer_question via session answers through the ask tool's handle; the key path is unchanged", async (t) => {
|
|
556
|
+
const h = harness(t);
|
|
557
|
+
await h.start();
|
|
558
|
+
const params = { question: "Which?", options: [{ label: "A", description: "", value: "tok-a" }, { label: "B", description: "", value: "tok-b" }] };
|
|
559
|
+
h.fire("tool_execution_start", { toolCallId: "call-1", toolName: "ask_user_choice", args: params }, h.ctx);
|
|
560
|
+
h.drop("a0.json", h.action("a0", "answer_question", { toolCallId: "call-1", option: 1, via: "session" }));
|
|
561
|
+
await h.deliver();
|
|
562
|
+
assert.deepEqual(h.result("a0").error, { code: "answer_in_terminal", message: "Answer this question in that session's terminal." }, "no handle yet");
|
|
563
|
+
const finished: unknown[] = [];
|
|
564
|
+
let done = false;
|
|
565
|
+
publishChoiceAnswerHandle("call-1", params, (result) => { finished.push(result); done = true; }, () => done);
|
|
566
|
+
h.drop("a1.json", h.action("a1", "answer_question", { toolCallId: "call-1", option: 1, via: "session" }));
|
|
567
|
+
await h.deliver();
|
|
568
|
+
assert.deepEqual(finished, [{ value: "tok-b", label: "B", index: 2 }]);
|
|
569
|
+
assert.deepEqual(h.result("a1").data, { toolCallId: "call-1", answered: true });
|
|
570
|
+
h.drop("a2.json", h.action("a2", "answer_question", { toolCallId: "call-1", option: 0 }));
|
|
571
|
+
await h.deliver();
|
|
572
|
+
assert.deepEqual(h.result("a2").data, { toolCallId: "call-1", keys: ["up", "up", "enter"] }, "keys, as before");
|
|
573
|
+
assert.equal(finished.length, 1, "the key path never answers by itself");
|
|
574
|
+
h.fire("tool_execution_end", { toolCallId: "call-1", toolName: "ask_user_choice", isError: false, result: {} }, h.ctx);
|
|
575
|
+
h.drop("a3.json", h.action("a3", "answer_question", { toolCallId: "call-1", option: 0, via: "session" }));
|
|
576
|
+
await h.deliver();
|
|
577
|
+
assert.equal(h.result("a3").error.code, "question_mismatch");
|
|
578
|
+
assert.equal(finished.length, 1);
|
|
579
|
+
});
|
|
580
|
+
|
|
581
|
+
// ---- T11 regressions (verifier, S10) ----
|
|
582
|
+
|
|
583
|
+
const STEER = (content: string, expand = false) => ({ content, options: { deliverAs: "steer", expandPromptTemplates: expand } });
|
|
584
|
+
|
|
585
|
+
test("S10: no pi built-in, extension command or ! line reaches pi, leading whitespace included", async (t) => {
|
|
586
|
+
const h = harness(t);
|
|
587
|
+
await h.start();
|
|
588
|
+
Object.assign(h.pi, { getCommands: () => [{ name: "gentle:mode", source: "extension" }, { name: "gentle:agents", source: "extension" }, { name: "review", source: "prompt" }] });
|
|
589
|
+
const texts = [
|
|
590
|
+
...DESKTOP_FEED_BUILTIN_COMMANDS.map((command) => `/${command.name}`),
|
|
591
|
+
"/quit", "/exit", "/settings", "/scoped-models", "/hotkeys", "/debug",
|
|
592
|
+
"/gentle:mode super-yolo", "/gentle:agents", " /new", "\t/model x", "\n/gentle:mode yolo",
|
|
593
|
+
"!rm -rf build", "!!ls", " !ls", "\n!ls",
|
|
594
|
+
];
|
|
595
|
+
// Batches under the outbox's 32 kept answers.
|
|
596
|
+
for (let start = 0; start < texts.length; start += 20) {
|
|
597
|
+
const batch = texts.slice(start, start + 20);
|
|
598
|
+
const id = (index: number) => `c${String(start + index).padStart(3, "0")}`;
|
|
599
|
+
batch.forEach((text, index) => h.drop(`${id(index)}.json`, h.action(id(index), "send_prompt", { text })));
|
|
600
|
+
await h.deliver();
|
|
601
|
+
batch.forEach((text, index) => assert.equal(h.result(id(index))?.error?.code, "terminal_command", JSON.stringify(text)));
|
|
602
|
+
}
|
|
603
|
+
assert.deepEqual(h.sent, [], "nothing reached pi");
|
|
604
|
+
assert.deepEqual(h.refused, []);
|
|
605
|
+
assert.deepEqual(h.setModes, [], "the permission owner was never asked");
|
|
606
|
+
assert.deepEqual(h.inboxFiles(), []);
|
|
607
|
+
});
|
|
608
|
+
|
|
609
|
+
test("S10: send_prompt bounds through the inbox: 4000 characters and multi-line text go in, CRLF as LF; the rest is invalid", async (t) => {
|
|
610
|
+
const h = harness(t);
|
|
611
|
+
await h.start();
|
|
612
|
+
h.drop("b1.json", h.action("b1", "send_prompt", { text: "x".repeat(4000) }));
|
|
613
|
+
h.drop("b2.json", h.action("b2", "send_prompt", { text: "x".repeat(4001) }));
|
|
614
|
+
h.drop("b3.json", h.action("b3", "send_prompt", { text: "" }));
|
|
615
|
+
h.drop("b4.json", h.action("b4", "send_prompt", { text: " \n\t " }));
|
|
616
|
+
h.drop("b5.json", h.action("b5", "send_prompt", { text: "clear\u001b[2J" }));
|
|
617
|
+
h.drop("b6.json", h.action("b6", "send_prompt", { text: 42 }));
|
|
618
|
+
h.drop("b7.json", h.action("b7", "send_prompt", { text: "line one\nline two\tend" }));
|
|
619
|
+
h.drop("b8.json", h.action("b8", "send_prompt", { text: "from windows\r\nsecond line" }));
|
|
620
|
+
h.drop("b9.json", h.action("b9", "send_prompt", { text: "lone\rreturn" }));
|
|
621
|
+
await h.deliver();
|
|
622
|
+
for (const id of ["b1", "b7", "b8"]) assert.deepEqual(h.result(id).data, { queued: false }, id);
|
|
623
|
+
for (const id of ["b2", "b3", "b4", "b5", "b6", "b9"]) assert.equal(h.result(id).error.code, "invalid_action", id);
|
|
624
|
+
assert.deepEqual(h.sent, [STEER("x".repeat(4000)), STEER("line one\nline two\tend"), STEER("from windows\nsecond line")]);
|
|
625
|
+
assert.deepEqual(h.inboxFiles(), []);
|
|
626
|
+
});
|
|
627
|
+
|
|
628
|
+
test("S10: via session never answers a relayed consent, another call id or a multi-select list", async (t) => {
|
|
629
|
+
const h = harness(t);
|
|
630
|
+
await h.start();
|
|
631
|
+
const answered: unknown[] = [];
|
|
632
|
+
// A consent relayed by its own tokens.
|
|
633
|
+
const consent = { question: "Allow review?", options: [{ label: "Yes", description: "", value: "granted" }, { label: "No", description: "", value: "declined" }] };
|
|
634
|
+
h.fire("tool_execution_start", { toolCallId: "call-c", toolName: "ask_user_choice", args: consent }, h.ctx);
|
|
635
|
+
publishChoiceAnswerHandle("call-c", consent, (result) => answered.push(result), () => false);
|
|
636
|
+
h.drop("v1.json", h.action("v1", "answer_question", { toolCallId: "call-c", option: 0, via: "session" }));
|
|
637
|
+
h.drop("v2.json", h.action("v2", "answer_question", { toolCallId: "call-c", text: "granted", via: "session" }));
|
|
638
|
+
await h.deliver();
|
|
639
|
+
assert.deepEqual(h.result("v1").error, { code: "answer_in_terminal", message: "Answer this question in the Terminal view" });
|
|
640
|
+
assert.equal(h.result("v2").error.code, "answer_in_terminal");
|
|
641
|
+
h.fire("tool_execution_end", { toolCallId: "call-c", toolName: "ask_user_choice", isError: false, result: {} }, h.ctx);
|
|
642
|
+
// A consent relayed after a provider decision envelope in this run's tool results.
|
|
643
|
+
h.fire("agent_start", {}, h.ctx);
|
|
644
|
+
h.fire("tool_execution_end", { toolCallId: "b-1", toolName: "bash", isError: false, result: { content: [{ type: "text", text: "status: consent_required" }] } }, h.ctx);
|
|
645
|
+
const plain = { question: "Go on?", options: [{ label: "Yes", description: "", value: "yes" }, { label: "No", description: "", value: "no" }] };
|
|
646
|
+
h.fire("tool_execution_start", { toolCallId: "call-r", toolName: "ask_user_choice", args: plain }, h.ctx);
|
|
647
|
+
publishChoiceAnswerHandle("call-r", plain, (result) => answered.push(result), () => false);
|
|
648
|
+
h.drop("v3.json", h.action("v3", "answer_question", { toolCallId: "call-r", option: 0, via: "session" }));
|
|
649
|
+
await h.deliver();
|
|
650
|
+
assert.equal(h.result("v3").error.code, "answer_in_terminal");
|
|
651
|
+
h.fire("tool_execution_end", { toolCallId: "call-r", toolName: "ask_user_choice", isError: false, result: {} }, h.ctx);
|
|
652
|
+
// Another call id: the open question is call-o; a handle for call-x exists.
|
|
653
|
+
h.fire("agent_start", {}, h.ctx);
|
|
654
|
+
h.fire("agent_start", {}, h.ctx);
|
|
655
|
+
h.fire("tool_execution_start", { toolCallId: "call-o", toolName: "ask_user_choice", args: plain }, h.ctx);
|
|
656
|
+
publishChoiceAnswerHandle("call-x", plain, (result) => answered.push(result), () => false);
|
|
657
|
+
h.drop("v4.json", h.action("v4", "answer_question", { toolCallId: "call-x", option: 0, via: "session" }));
|
|
658
|
+
await h.deliver();
|
|
659
|
+
assert.deepEqual(h.result("v4").error, { code: "question_mismatch", message: "That question is no longer open" });
|
|
660
|
+
h.fire("tool_execution_end", { toolCallId: "call-o", toolName: "ask_user_choice", isError: false, result: {} }, h.ctx);
|
|
661
|
+
// A multi-select list.
|
|
662
|
+
const multi = [{ question: "Which?", header: "H", multiSelect: true, options: [{ label: "A", description: "" }, { label: "B", description: "" }] }];
|
|
663
|
+
h.fire("tool_execution_start", { toolCallId: "call-m", toolName: "ask_user_question", args: { questions: multi } }, h.ctx);
|
|
664
|
+
publishQuestionnaireAnswerHandle("call-m", multi, (result) => answered.push(result), () => false);
|
|
665
|
+
h.drop("v5.json", h.action("v5", "answer_question", { toolCallId: "call-m", option: 0, via: "session" }));
|
|
666
|
+
await h.deliver();
|
|
667
|
+
assert.equal(h.result("v5").error.code, "answer_in_terminal");
|
|
668
|
+
assert.deepEqual(answered, [], "no handle was ever used");
|
|
669
|
+
assert.deepEqual(h.sent, []);
|
|
670
|
+
});
|
|
671
|
+
|
|
672
|
+
test("S10 (V9): a prompt sent while pi compacts is held, never reported delivered while pi refuses it, and goes in once compaction ends", async (t) => {
|
|
673
|
+
const h = harness(t);
|
|
674
|
+
await h.start();
|
|
675
|
+
// /compact: pi refuses prompts until its compaction state clears.
|
|
676
|
+
h.setCompacting(true);
|
|
677
|
+
Object.assign(h.ctx, { isIdle: () => false });
|
|
678
|
+
h.fire("session_before_compact", { reason: "manual", willRetry: false }, h.ctx);
|
|
679
|
+
h.drop("k1.json", h.action("k1", "send_prompt", { text: "after the summary" }));
|
|
680
|
+
await h.deliver();
|
|
681
|
+
assert.deepEqual(h.refused, [], "nothing was handed to pi while it refuses prompts");
|
|
682
|
+
assert.deepEqual(h.sent, []);
|
|
683
|
+
assert.deepEqual(h.result("k1").data, { queued: true, after: "compaction" });
|
|
684
|
+
h.drop("k2.json", h.action("k2", "send_prompt", { text: "and this too" }));
|
|
685
|
+
await h.deliver();
|
|
686
|
+
assert.deepEqual(h.result("k2").error, { code: "session_compacting", message: "Pi is compacting this session and already holds one prompt for after it; send this one when compaction ends." });
|
|
687
|
+
h.clock.run();
|
|
688
|
+
h.clock.run();
|
|
689
|
+
assert.deepEqual([h.sent, h.refused], [[], []], "still compacting: still held");
|
|
690
|
+
// pi emits session_compact, then clears its compaction state.
|
|
691
|
+
h.fire("session_compact", { reason: "manual", willRetry: false }, h.ctx);
|
|
692
|
+
h.setCompacting(false);
|
|
693
|
+
Object.assign(h.ctx, { isIdle: () => true });
|
|
694
|
+
h.clock.run();
|
|
695
|
+
assert.deepEqual(h.sent, [STEER("after the summary")]);
|
|
696
|
+
h.clock.run();
|
|
697
|
+
assert.equal(h.sent.length, 1, "delivered once");
|
|
698
|
+
assert.deepEqual(h.refused, []);
|
|
699
|
+
assert.equal(h.clock.armed, 0, "no timer while nothing is held");
|
|
700
|
+
});
|
|
701
|
+
|
|
702
|
+
test("S10 (V9): /tree's summary holds a prompt too, also when the navigation ends without session_tree", async (t) => {
|
|
703
|
+
const h = harness(t);
|
|
704
|
+
await h.start();
|
|
705
|
+
h.setCompacting(true);
|
|
706
|
+
Object.assign(h.ctx, { isIdle: () => false });
|
|
707
|
+
h.fire("session_before_tree", { preparation: {} }, h.ctx);
|
|
708
|
+
h.drop("t1.json", h.action("t1", "send_prompt", { text: "first" }));
|
|
709
|
+
await h.deliver();
|
|
710
|
+
assert.deepEqual(h.result("t1").data, { queued: true, after: "compaction" });
|
|
711
|
+
h.fire("session_tree", { newLeafId: "x", oldLeafId: "y" }, h.ctx);
|
|
712
|
+
h.setCompacting(false);
|
|
713
|
+
Object.assign(h.ctx, { isIdle: () => true });
|
|
714
|
+
h.clock.run();
|
|
715
|
+
assert.deepEqual(h.sent, [STEER("first")]);
|
|
716
|
+
// A cancelled navigation emits no session_tree: pi turning idle releases the prompt.
|
|
717
|
+
h.setCompacting(true);
|
|
718
|
+
Object.assign(h.ctx, { isIdle: () => false });
|
|
719
|
+
h.fire("session_before_tree", { preparation: {} }, h.ctx);
|
|
720
|
+
h.drop("t2.json", h.action("t2", "send_prompt", { text: "second" }));
|
|
721
|
+
await h.deliver();
|
|
722
|
+
h.clock.run();
|
|
723
|
+
assert.equal(h.sent.length, 1);
|
|
724
|
+
h.setCompacting(false);
|
|
725
|
+
Object.assign(h.ctx, { isIdle: () => true });
|
|
726
|
+
h.clock.run();
|
|
727
|
+
assert.deepEqual(h.sent, [STEER("first"), STEER("second")]);
|
|
728
|
+
assert.deepEqual(h.refused, []);
|
|
729
|
+
});
|
|
730
|
+
|
|
731
|
+
test("S10 (V9): a busy pi with no agent run started is waited for, not handed a prompt it may refuse", async (t) => {
|
|
732
|
+
const h = harness(t);
|
|
733
|
+
await h.start();
|
|
734
|
+
// Compacting before this extension heard of it (an earlier handler still runs).
|
|
735
|
+
h.setCompacting(true);
|
|
736
|
+
Object.assign(h.ctx, { isIdle: () => false });
|
|
737
|
+
h.drop("w1.json", h.action("w1", "send_prompt", { text: "wait for it" }));
|
|
738
|
+
await h.deliver();
|
|
739
|
+
assert.deepEqual(h.result("w1").data, { queued: true });
|
|
740
|
+
assert.deepEqual([h.sent, h.refused], [[], []]);
|
|
741
|
+
h.setCompacting(false);
|
|
742
|
+
Object.assign(h.ctx, { isIdle: () => true });
|
|
743
|
+
h.clock.run();
|
|
744
|
+
assert.deepEqual(h.sent, [STEER("wait for it")]);
|
|
745
|
+
});
|
|
746
|
+
|
|
747
|
+
test("S10 (V9): a held prompt is dropped with a clear error when the session ends", async (t) => {
|
|
748
|
+
const h = harness(t);
|
|
749
|
+
await h.start();
|
|
750
|
+
h.setCompacting(true);
|
|
751
|
+
Object.assign(h.ctx, { isIdle: () => false });
|
|
752
|
+
h.fire("session_before_compact", { reason: "manual", willRetry: false }, h.ctx);
|
|
753
|
+
h.drop("s1.json", h.action("s1", "send_prompt", { text: "never mind" }));
|
|
754
|
+
await h.deliver();
|
|
755
|
+
assert.deepEqual(h.result("s1").data, { queued: true, after: "compaction" });
|
|
756
|
+
h.fire("session_shutdown", { reason: "quit" }, h.ctx);
|
|
757
|
+
h.clock.run();
|
|
758
|
+
assert.deepEqual([h.sent, h.refused], [[], []]);
|
|
759
|
+
assert.deepEqual(h.ctx.notices, ["Gentle Shell Desktop: a prompt sent during compaction was not delivered (the session ended)."]);
|
|
760
|
+
assert.equal(h.clock.armed, 0);
|
|
761
|
+
});
|