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,276 @@
|
|
|
1
|
+
import type { ExtensionAPI, ExtensionContext } from "@earendil-works/pi-coding-agent";
|
|
2
|
+
import {
|
|
3
|
+
DESKTOP_RPC_COMMAND,
|
|
4
|
+
DESKTOP_RPC_WIDGET,
|
|
5
|
+
DesktopRpcRouter,
|
|
6
|
+
type DesktopRpcDomain,
|
|
7
|
+
type DesktopRpcPublish,
|
|
8
|
+
} from "../lib/desktop-rpc.ts";
|
|
9
|
+
import {
|
|
10
|
+
DESKTOP_CONFIG_EVENTS,
|
|
11
|
+
DESKTOP_CONFIG_METHODS,
|
|
12
|
+
DesktopConfigBridge,
|
|
13
|
+
} from "../lib/desktop-rpc-config.ts";
|
|
14
|
+
import {
|
|
15
|
+
DESKTOP_PERMISSION_EVENT,
|
|
16
|
+
DESKTOP_PERMISSION_METHODS,
|
|
17
|
+
DesktopPermissionBridge,
|
|
18
|
+
} from "../lib/desktop-rpc-permissions.ts";
|
|
19
|
+
import { DESKTOP_USAGE_EVENTS, DESKTOP_USAGE_METHODS } from "../lib/desktop-rpc-usage.ts";
|
|
20
|
+
import { DesktopUsageBridge } from "../lib/desktop-usage-service.ts";
|
|
21
|
+
import { DESKTOP_DESIGN_EVENTS, DESKTOP_DESIGN_METHODS } from "../lib/desktop-rpc-design.ts";
|
|
22
|
+
import { DesktopDesignBridge } from "../lib/desktop-design-service.ts";
|
|
23
|
+
import { DESKTOP_JOBS_EVENTS, DESKTOP_JOBS_METHODS } from "../lib/desktop-rpc-jobs.ts";
|
|
24
|
+
import { DesktopJobsBridge } from "../lib/desktop-jobs-service.ts";
|
|
25
|
+
import { DESKTOP_AGENTS_EVENTS, DESKTOP_AGENTS_METHODS } from "../lib/desktop-rpc-agents.ts";
|
|
26
|
+
import { DesktopAgentsBridge } from "../lib/desktop-agents-service.ts";
|
|
27
|
+
import { DESKTOP_CHANGES_EVENTS, DESKTOP_CHANGES_METHODS } from "../lib/desktop-rpc-changes.ts";
|
|
28
|
+
import { DesktopChangesBridge } from "../lib/desktop-changes-service.ts";
|
|
29
|
+
import { DESKTOP_PROFILES_EVENTS, DESKTOP_PROFILES_METHODS, DesktopProfilesBridge } from "../lib/desktop-rpc-profiles.ts";
|
|
30
|
+
import { DESKTOP_SESSION_EVENTS } from "../lib/desktop-rpc-session.ts";
|
|
31
|
+
import { DesktopSessionBridge } from "../lib/desktop-session-service.ts";
|
|
32
|
+
import { DESKTOP_SESSIONS_EVENTS, DESKTOP_SESSIONS_METHODS, desktopRequestId, desktopSessionsErrorLine, SESSION_SWITCHING } from "../lib/desktop-rpc-sessions.ts";
|
|
33
|
+
import { DesktopSessionsBridge } from "../lib/desktop-sessions-service.ts";
|
|
34
|
+
import { DESKTOP_REVIEW_EVENTS, DESKTOP_REVIEW_METHODS } from "../lib/desktop-rpc-review.ts";
|
|
35
|
+
import { DesktopReviewBridge } from "../lib/desktop-review-service.ts";
|
|
36
|
+
import { DESKTOP_STATS_EVENTS, DESKTOP_STATS_METHODS } from "../lib/desktop-rpc-stats.ts";
|
|
37
|
+
import { DesktopStatsBridge } from "../lib/desktop-stats-service.ts";
|
|
38
|
+
import { DESKTOP_UPDATES_EVENTS, DESKTOP_UPDATES_METHODS } from "../lib/desktop-rpc-updates.ts";
|
|
39
|
+
import { DesktopUpdatesBridge, type UpdateSourcesFactory } from "../lib/desktop-updates-service.ts";
|
|
40
|
+
import { isInteractiveRpcHost } from "../lib/rpc-host.ts";
|
|
41
|
+
import type { DesktopChangeTimers, DesktopDirectoryWatch } from "../lib/desktop-rpc-config-watch.ts";
|
|
42
|
+
|
|
43
|
+
/** Test seams for external-change detection; production uses `fs.watch` and real timers. */
|
|
44
|
+
export interface DesktopRpcExtensionOptions {
|
|
45
|
+
watch?: DesktopDirectoryWatch;
|
|
46
|
+
timers?: DesktopChangeTimers;
|
|
47
|
+
/** Test seams for `get_update_status`; production reads the real update sources. */
|
|
48
|
+
updateSources?: UpdateSourcesFactory;
|
|
49
|
+
updateTimeoutMs?: number;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
function publisher(ctx: ExtensionContext): DesktopRpcPublish {
|
|
53
|
+
// Extract the UI once: Pi invalidates a captured ctx after a session switch,
|
|
54
|
+
// but an extracted raw object stays usable, so a switch-retired instance can
|
|
55
|
+
// still answer the requests that reach it during the replacement.
|
|
56
|
+
const ui = ctx.ui;
|
|
57
|
+
return (line) => {
|
|
58
|
+
try {
|
|
59
|
+
ui.setWidget(DESKTOP_RPC_WIDGET, [line]);
|
|
60
|
+
} catch {
|
|
61
|
+
throw new Error("Desktop RPC transport unavailable");
|
|
62
|
+
}
|
|
63
|
+
};
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
export default function desktopRpc(pi: ExtensionAPI, options: DesktopRpcExtensionOptions = {}) {
|
|
67
|
+
// Permission control always delegates to the existing Gentle AI session owner;
|
|
68
|
+
// config reads and writes delegate to the existing store owners; subscription
|
|
69
|
+
// usage delegates to the existing usage owner; design canvas reads delegate
|
|
70
|
+
// to the existing design owner; background jobs list/cancel/output delegate to the
|
|
71
|
+
// existing parent-session job registry and monitor controller; subagents
|
|
72
|
+
// list/cancel delegate to the existing parent-session TaskStore and
|
|
73
|
+
// AgentRunner; profile applies delegate to the existing `/gentle:profiles`
|
|
74
|
+
// owner and its own apply actions; session sections delegate to the live
|
|
75
|
+
// feed projection (`extensions/gentle-desktop-feed.ts`); sessions list/switch
|
|
76
|
+
// delegate to Pi's own `SessionManager` and the command context's
|
|
77
|
+
// `switchSession`; changed files and per-file diffs delegate to the existing
|
|
78
|
+
// `/gentle:changes` tracker; review (RDD) mode reads and changes delegate to
|
|
79
|
+
// the `/gentle:review-mode` owner and its native CLI adapter; cross-session
|
|
80
|
+
// usage stats delegate to the existing `/gentle:stats` owner and its one
|
|
81
|
+
// cached loader; update status reads Gentle Shell's own channel and version
|
|
82
|
+
// resolution and Pi's own package update check, keeping refresh results in
|
|
83
|
+
// memory only. None has a store of its own.
|
|
84
|
+
const changeTimers = options.timers === undefined ? {} : { timers: options.timers };
|
|
85
|
+
const permissions = new DesktopPermissionBridge(pi, undefined, changeTimers);
|
|
86
|
+
const config = new DesktopConfigBridge({}, { ...changeTimers, ...(options.watch === undefined ? {} : { watch: options.watch }) });
|
|
87
|
+
const usage = new DesktopUsageBridge(pi);
|
|
88
|
+
const design = new DesktopDesignBridge(pi);
|
|
89
|
+
const jobs = new DesktopJobsBridge(pi);
|
|
90
|
+
const agents = new DesktopAgentsBridge(pi);
|
|
91
|
+
const profiles = new DesktopProfilesBridge(pi);
|
|
92
|
+
const sessions = new DesktopSessionBridge(pi);
|
|
93
|
+
const sessionList = new DesktopSessionsBridge();
|
|
94
|
+
// The requestId of the command being dispatched. The router calls the domain
|
|
95
|
+
// synchronously from `handle`, so the sessions slice reads it before any
|
|
96
|
+
// await; a switch needs it to answer from the replacement session.
|
|
97
|
+
let dispatchingRequestId: string | null = null;
|
|
98
|
+
// The publisher of the running session, and the one kept after a switch tore
|
|
99
|
+
// this instance down. Pi can still dispatch a command to a replaced instance
|
|
100
|
+
// (its ctx is stale by then); that command is answered `session_switching`.
|
|
101
|
+
let activePublish: DesktopRpcPublish | undefined;
|
|
102
|
+
let retiredPublish: DesktopRpcPublish | undefined;
|
|
103
|
+
const changes = new DesktopChangesBridge(pi);
|
|
104
|
+
const review = new DesktopReviewBridge(pi);
|
|
105
|
+
const stats = new DesktopStatsBridge(pi);
|
|
106
|
+
const updates = new DesktopUpdatesBridge({
|
|
107
|
+
...(options.updateSources === undefined ? {} : { sources: options.updateSources }),
|
|
108
|
+
...(options.updateTimeoutMs === undefined ? {} : { timeoutMs: options.updateTimeoutMs }),
|
|
109
|
+
});
|
|
110
|
+
const domain: DesktopRpcDomain = (method, params) => {
|
|
111
|
+
const sessionsOutcome = sessionList.handle(method, params, dispatchingRequestId);
|
|
112
|
+
if (sessionsOutcome !== undefined) return sessionsOutcome;
|
|
113
|
+
// Config is the only synchronous bridge; permission, usage, design, jobs,
|
|
114
|
+
// profiles, agents, changes, review, stats, and updates answers are awaited in fall-through order, so an unknown
|
|
115
|
+
// method still resolves to the router's `unsupported_method` instead of an
|
|
116
|
+
// early `undefined`.
|
|
117
|
+
const configOutcome = config.handle(method, params);
|
|
118
|
+
if (configOutcome !== undefined) return configOutcome;
|
|
119
|
+
return (async () => {
|
|
120
|
+
const permissionOutcome = await permissions.handle(method, params);
|
|
121
|
+
if (permissionOutcome !== undefined) return permissionOutcome;
|
|
122
|
+
const usageOutcome = await usage.handle(method, params);
|
|
123
|
+
if (usageOutcome !== undefined) return usageOutcome;
|
|
124
|
+
const designOutcome = await design.handle(method, params);
|
|
125
|
+
if (designOutcome !== undefined) return designOutcome;
|
|
126
|
+
const jobsOutcome = await jobs.handle(method, params);
|
|
127
|
+
if (jobsOutcome !== undefined) return jobsOutcome;
|
|
128
|
+
const profilesOutcome = await profiles.handle(method, params);
|
|
129
|
+
if (profilesOutcome !== undefined) return profilesOutcome;
|
|
130
|
+
const agentsOutcome = await agents.handle(method, params);
|
|
131
|
+
if (agentsOutcome !== undefined) return agentsOutcome;
|
|
132
|
+
const changesOutcome = await changes.handle(method, params);
|
|
133
|
+
if (changesOutcome !== undefined) return changesOutcome;
|
|
134
|
+
const reviewOutcome = await review.handle(method, params);
|
|
135
|
+
if (reviewOutcome !== undefined) return reviewOutcome;
|
|
136
|
+
const statsOutcome = await stats.handle(method, params);
|
|
137
|
+
if (statsOutcome !== undefined) return statsOutcome;
|
|
138
|
+
return updates.handle(method, params);
|
|
139
|
+
})();
|
|
140
|
+
};
|
|
141
|
+
const events = [...DESKTOP_CONFIG_EVENTS, DESKTOP_PERMISSION_EVENT, ...DESKTOP_USAGE_EVENTS, ...DESKTOP_DESIGN_EVENTS, ...DESKTOP_JOBS_EVENTS, ...DESKTOP_PROFILES_EVENTS, ...DESKTOP_AGENTS_EVENTS, ...DESKTOP_SESSIONS_EVENTS, ...DESKTOP_CHANGES_EVENTS, ...DESKTOP_REVIEW_EVENTS, ...DESKTOP_STATS_EVENTS, ...DESKTOP_UPDATES_EVENTS];
|
|
142
|
+
const router = new DesktopRpcRouter(
|
|
143
|
+
["capabilities", "get_snapshot", ...DESKTOP_CONFIG_METHODS, ...DESKTOP_PERMISSION_METHODS, ...DESKTOP_USAGE_METHODS, ...DESKTOP_DESIGN_METHODS, ...DESKTOP_JOBS_METHODS, ...DESKTOP_PROFILES_METHODS, ...DESKTOP_AGENTS_METHODS, ...DESKTOP_SESSIONS_METHODS, ...DESKTOP_CHANGES_METHODS, ...DESKTOP_REVIEW_METHODS, ...DESKTOP_STATS_METHODS, ...DESKTOP_UPDATES_METHODS],
|
|
144
|
+
// `session_snapshot` is advertised only while the feed owner seam is wired.
|
|
145
|
+
() => (sessions.wired ? [...events, ...DESKTOP_SESSION_EVENTS] : events),
|
|
146
|
+
() => config.snapshotState(),
|
|
147
|
+
domain,
|
|
148
|
+
(params) => sessions.snapshot(params),
|
|
149
|
+
);
|
|
150
|
+
// While a `switch_session` is in flight, every other request is answered at
|
|
151
|
+
// once with a retryable `session_switching`: Pi's RPC loop dispatches
|
|
152
|
+
// prompts concurrently, and an answer that settled after the teardown would
|
|
153
|
+
// otherwise be dropped with the old session.
|
|
154
|
+
router.setGate(() => (sessionList.switchInFlight() ? SESSION_SWITCHING : undefined));
|
|
155
|
+
|
|
156
|
+
pi.on("session_start", (_event, ctx) => {
|
|
157
|
+
permissions.reset();
|
|
158
|
+
config.reset();
|
|
159
|
+
usage.reset();
|
|
160
|
+
design.reset();
|
|
161
|
+
jobs.reset();
|
|
162
|
+
profiles.reset();
|
|
163
|
+
agents.reset();
|
|
164
|
+
sessions.reset();
|
|
165
|
+
sessionList.reset();
|
|
166
|
+
changes.reset();
|
|
167
|
+
review.reset();
|
|
168
|
+
stats.reset();
|
|
169
|
+
updates.reset();
|
|
170
|
+
router.stop();
|
|
171
|
+
activePublish = undefined;
|
|
172
|
+
retiredPublish = undefined;
|
|
173
|
+
if (!isInteractiveRpcHost(ctx.mode)) return;
|
|
174
|
+
design.attach(ctx);
|
|
175
|
+
jobs.attach(ctx);
|
|
176
|
+
agents.attach(ctx);
|
|
177
|
+
sessions.attach(ctx);
|
|
178
|
+
activePublish = publisher(ctx);
|
|
179
|
+
router.start(activePublish);
|
|
180
|
+
// Header-driven usage snapshots (Claude's 5h/7d windows, Codex SSE
|
|
181
|
+
// headers) become ordered `rate_limit` events through the router.
|
|
182
|
+
usage.wire((event, data) => router.emit(event, data));
|
|
183
|
+
// Agent-driven canvas transitions become ordered `design_canvas` events;
|
|
184
|
+
// subscribe eagerly so canvas work that happens before any Desktop
|
|
185
|
+
// request still reaches the app.
|
|
186
|
+
design.wire((event, data) => router.emit(event, data));
|
|
187
|
+
void design.start();
|
|
188
|
+
// Agent-driven background-job registry changes become ordered `jobs_update`
|
|
189
|
+
// events; subscribe eagerly so a job started or stopped before any Desktop
|
|
190
|
+
// request still reaches the app.
|
|
191
|
+
jobs.wire((event, data) => router.emit(event, data));
|
|
192
|
+
void jobs.start();
|
|
193
|
+
// Agent-driven TaskStore transitions become ordered `agents_update` events;
|
|
194
|
+
// subscribe eagerly so a subagent started or settled before any Desktop
|
|
195
|
+
// request still reaches the app.
|
|
196
|
+
agents.wire((event, data) => router.emit(event, data));
|
|
197
|
+
void agents.start();
|
|
198
|
+
// Feed-published session state becomes ordered `session_snapshot` events
|
|
199
|
+
// carrying only the changed sections, on the feed's own tiers.
|
|
200
|
+
sessions.wire((event, data) => router.emit(event, data));
|
|
201
|
+
void sessions.start();
|
|
202
|
+
// Changes made outside Desktop RPC (`/gentle:mode`, `/gentle:profiles`, an
|
|
203
|
+
// editor, another `pi` process) become `source: "external"` events. Both are
|
|
204
|
+
// best effort: the permission side follows the owner's observer, the config
|
|
205
|
+
// side watches the owner files' directories; a missing owner or a watcher that
|
|
206
|
+
// cannot be created leaves the channel working without these events. The
|
|
207
|
+
// session_start/session_shutdown resets above dispose them.
|
|
208
|
+
permissions.attach(ctx);
|
|
209
|
+
void permissions.wire((event, data) => router.emit(event, data));
|
|
210
|
+
config.attach(ctx);
|
|
211
|
+
config.wire((event, data) => router.emit(event, data));
|
|
212
|
+
});
|
|
213
|
+
|
|
214
|
+
pi.on("session_shutdown", () => {
|
|
215
|
+
// A switch is tearing this session down: answer every request still
|
|
216
|
+
// waiting on an owner before the router stops, so none is lost. Only the
|
|
217
|
+
// switch itself is kept; the replacement session answers it.
|
|
218
|
+
const switching = sessionList.switchInFlight();
|
|
219
|
+
if (switching) {
|
|
220
|
+
router.abandonPending(SESSION_SWITCHING, (requestId) => requestId === switching.requestId);
|
|
221
|
+
retiredPublish = activePublish;
|
|
222
|
+
}
|
|
223
|
+
activePublish = undefined;
|
|
224
|
+
permissions.reset();
|
|
225
|
+
config.reset();
|
|
226
|
+
usage.reset();
|
|
227
|
+
design.reset();
|
|
228
|
+
jobs.reset();
|
|
229
|
+
profiles.reset();
|
|
230
|
+
agents.reset();
|
|
231
|
+
sessions.reset();
|
|
232
|
+
sessionList.reset();
|
|
233
|
+
changes.reset();
|
|
234
|
+
review.reset();
|
|
235
|
+
stats.reset();
|
|
236
|
+
updates.reset();
|
|
237
|
+
router.stop();
|
|
238
|
+
});
|
|
239
|
+
|
|
240
|
+
pi.registerCommand(DESKTOP_RPC_COMMAND, {
|
|
241
|
+
description: "Handle a versioned Gentle Desktop RPC request",
|
|
242
|
+
async handler(args, ctx) {
|
|
243
|
+
if (retiredPublish) {
|
|
244
|
+
// This instance was replaced by a switch: never touch the stale ctx.
|
|
245
|
+
try {
|
|
246
|
+
retiredPublish(desktopSessionsErrorLine(desktopRequestId(args), SESSION_SWITCHING));
|
|
247
|
+
} catch {
|
|
248
|
+
/* transport failures are never retried as a second response */
|
|
249
|
+
}
|
|
250
|
+
return;
|
|
251
|
+
}
|
|
252
|
+
if (!isInteractiveRpcHost(ctx.mode)) return;
|
|
253
|
+
permissions.attach(ctx);
|
|
254
|
+
config.attach(ctx);
|
|
255
|
+
usage.attach(ctx);
|
|
256
|
+
design.attach(ctx);
|
|
257
|
+
jobs.attach(ctx);
|
|
258
|
+
profiles.attach(ctx);
|
|
259
|
+
agents.attach(ctx);
|
|
260
|
+
sessions.attach(ctx);
|
|
261
|
+
sessionList.attach(ctx);
|
|
262
|
+
changes.attach(ctx);
|
|
263
|
+
review.attach(ctx);
|
|
264
|
+
stats.attach(ctx);
|
|
265
|
+
updates.attach(ctx);
|
|
266
|
+
dispatchingRequestId = desktopRequestId(args);
|
|
267
|
+
let pending: void | Promise<void>;
|
|
268
|
+
try {
|
|
269
|
+
pending = router.handle(args);
|
|
270
|
+
} finally {
|
|
271
|
+
dispatchingRequestId = null;
|
|
272
|
+
}
|
|
273
|
+
await pending;
|
|
274
|
+
},
|
|
275
|
+
});
|
|
276
|
+
}
|
|
@@ -2,6 +2,7 @@ import type { ExtensionAPI, ExtensionContext } from "@earendil-works/pi-coding-a
|
|
|
2
2
|
import type { TUI } from "@earendil-works/pi-tui";
|
|
3
3
|
import { Type } from "typebox";
|
|
4
4
|
import { appendSystemPromptOnce } from "../lib/append-system-prompt.ts";
|
|
5
|
+
import { codemodeReaches, GUIDE_TOOL_ROUTE, hideBehindCodemode } from "../lib/hidden-tools.ts";
|
|
5
6
|
import { guidePlacement, GuidePopover, guideStepText, guideSteps, GuideTour, type GuideMode, type GuideResult } from "../lib/gentle-guide.ts";
|
|
6
7
|
import { sidebarState } from "../lib/shell-sidebar.ts";
|
|
7
8
|
|
|
@@ -135,6 +136,7 @@ export default function gentleGuide(pi: ExtensionAPI, env: NodeJS.ProcessEnv = p
|
|
|
135
136
|
description: "Drive the /gentle:guide tour of Gentle Shell: start shows the first step as a popover beside the part of the screen it describes and returns its text to explain; next, previous and show (with a step id) move; end closes the popover. Show one step per turn and let the user ask questions between steps.",
|
|
136
137
|
promptSnippet: "Show the Gentle Shell guided tour one step at a time and explain each step.",
|
|
137
138
|
parameters: GuideParams,
|
|
139
|
+
prepareLoadout: hideBehindCodemode(GUIDE_TOOL_NAME),
|
|
138
140
|
async execute(_toolCallId, params, _signal, _onUpdate, ctx) {
|
|
139
141
|
const { action, step } = params as GuideParamsValue;
|
|
140
142
|
const text = (value: string) => ({ content: [{ type: "text" as const, text: value }], details: {} });
|
|
@@ -165,6 +167,7 @@ export default function gentleGuide(pi: ExtensionAPI, env: NodeJS.ProcessEnv = p
|
|
|
165
167
|
|
|
166
168
|
pi.on("before_agent_start", (event) => {
|
|
167
169
|
appendSystemPromptOnce(event.systemPromptOptions, GUIDE_PROMPT_HINT);
|
|
170
|
+
if (codemodeReaches(event.systemPromptOptions?.selectedTools) && event.systemPromptOptions?.selectedTools?.includes(GUIDE_TOOL_NAME)) appendSystemPromptOnce(event.systemPromptOptions, GUIDE_TOOL_ROUTE);
|
|
168
171
|
return undefined;
|
|
169
172
|
});
|
|
170
173
|
pi.on("session_shutdown", () => {
|
|
@@ -0,0 +1,275 @@
|
|
|
1
|
+
import { createHash } from "node:crypto";
|
|
2
|
+
import type { ExtensionAPI, ExtensionContext } from "@earendil-works/pi-coding-agent";
|
|
3
|
+
import type { Terminal } from "@earendil-works/pi-tui";
|
|
4
|
+
import { HERDR_DESKTOP_TASKS, HERDR_DESKTOP_TASKS_REQUEST, HERDR_DESKTOP_TASK_FINISHED, HERDR_DESKTOP_JOBS, HERDR_DESKTOP_JOB_SETTLED, HERDR_DESKTOP_CONSULT, HERDR_DESKTOP_SEND, HERDR_DESKTOP_INBOUND, type HerdrDesktopTask } from "../lib/herdr-desktop-events.ts";
|
|
5
|
+
import { desktopJobTitle, desktopTaskTitle, diffRecords, hasUsableDesktopLabel, projectAll, SEND_TTL_MS, ERROR_TTL_MS, type DesktopRecord } from "../lib/herdr-desktop-status.ts";
|
|
6
|
+
import { isJobsSidebarSnapshot, JOBS_SIDEBAR_EVENT, type JobsSidebarSnapshot, type RunningJobDisplay } from "../lib/jobs-sidebar-state.ts";
|
|
7
|
+
import { replayTodo, todoProgress, TODO_PROGRESS_EVENT, type TodoState } from "../lib/shell-todo.ts";
|
|
8
|
+
|
|
9
|
+
const WIDGET_KEY = "gentle-shell:herdr-desktop-status";
|
|
10
|
+
/** Delay before retrying a diff the terminal rejected part of. */
|
|
11
|
+
export const WRITE_RETRY_MS = 1000;
|
|
12
|
+
const taskStatuses = new Set(["queued", "running", "waiting", "completed", "failed", "cancelled", "timed_out"]);
|
|
13
|
+
const todoStatuses = new Set(["pending", "in_progress", "blocked", "done", "dropped"]);
|
|
14
|
+
|
|
15
|
+
interface StatusOptions {
|
|
16
|
+
env?: NodeJS.ProcessEnv;
|
|
17
|
+
now?: () => number;
|
|
18
|
+
/** Schedule one expiry; return a cancellation function. */
|
|
19
|
+
schedule?: (fn: () => void, ms: number) => () => void;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
// OSC IDs allow slash, but Herdr clears descendants with an ancestor. Reserve
|
|
23
|
+
// h- for hashed segments; the longer subagents/ prefix needs a shorter hash.
|
|
24
|
+
function segment(value: string, maxLength = 59): string {
|
|
25
|
+
return value.length <= maxLength && /^[A-Za-z0-9_.-]+$/.test(value) && !value.startsWith("h-")
|
|
26
|
+
? value : `h-${createHash("sha256").update(value).digest("hex").slice(0, Math.min(56, maxLength - 2))}`;
|
|
27
|
+
}
|
|
28
|
+
function validTasks(value: unknown): value is HerdrDesktopTask[] {
|
|
29
|
+
return Array.isArray(value) && Array.from(value).every(task => task && typeof task === "object"
|
|
30
|
+
&& typeof task.id === "string" && task.id.length > 0 && typeof task.agent === "string" && task.agent.trim().length > 0
|
|
31
|
+
&& typeof task.status === "string" && taskStatuses.has(task.status)
|
|
32
|
+
&& (task.label === undefined || typeof task.label === "string")
|
|
33
|
+
&& (task.explicitLabel === undefined || typeof task.explicitLabel === "string")
|
|
34
|
+
&& (task.pendingQuery === undefined || typeof task.pendingQuery === "boolean"));
|
|
35
|
+
}
|
|
36
|
+
function validTodoTasks(value: unknown): value is TodoState["tasks"] {
|
|
37
|
+
return Array.isArray(value) && Array.from(value).every(task => task && typeof task === "object"
|
|
38
|
+
&& typeof task.title === "string" && typeof task.status === "string" && todoStatuses.has(task.status));
|
|
39
|
+
}
|
|
40
|
+
function validProgress(value: unknown): value is { done: number; total: number; current: string | null } {
|
|
41
|
+
if (!value || typeof value !== "object") return false;
|
|
42
|
+
const v = value as Record<string, unknown>;
|
|
43
|
+
return typeof v.done === "number" && Number.isSafeInteger(v.done) && v.done >= 0
|
|
44
|
+
&& typeof v.total === "number" && Number.isSafeInteger(v.total) && v.total >= v.done
|
|
45
|
+
&& (v.current === null || (typeof v.current === "string" && v.total > 0));
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
type Session = {
|
|
49
|
+
id: string;
|
|
50
|
+
startedAt: number;
|
|
51
|
+
ctx: ExtensionContext;
|
|
52
|
+
manager: ExtensionContext["sessionManager"];
|
|
53
|
+
terminal?: Terminal;
|
|
54
|
+
previous: Map<string, DesktopRecord>;
|
|
55
|
+
todo?: unknown;
|
|
56
|
+
jobs?: JobsSidebarSnapshot;
|
|
57
|
+
tasks: HerdrDesktopTask[];
|
|
58
|
+
jobMetadata: Map<string, { explicitLabel?: string; kind?: "command" | "monitor" }>;
|
|
59
|
+
taskLabels: Map<string, string>;
|
|
60
|
+
consults: Map<string, string>;
|
|
61
|
+
sends: Map<string, number>;
|
|
62
|
+
asksFromPeers: Map<string, Map<string, string>>;
|
|
63
|
+
errors: Map<string, { record: DesktopRecord; expiresAt: number }>;
|
|
64
|
+
seenJobErrors: Set<string>;
|
|
65
|
+
seenTaskErrors: Set<string>;
|
|
66
|
+
/** The last diff stopped at a failed write; retry even without a TTL deadline. */
|
|
67
|
+
dirty: boolean;
|
|
68
|
+
cancelTimer?: () => void;
|
|
69
|
+
unsubscribe: Array<() => void>;
|
|
70
|
+
};
|
|
71
|
+
|
|
72
|
+
export function createHerdrDesktopStatusExtension(options: StatusOptions = {}) {
|
|
73
|
+
return (pi: ExtensionAPI): void => {
|
|
74
|
+
const env = options.env ?? process.env;
|
|
75
|
+
// Fail closed on any GENTLE_PI_AGENTS_CHILD value (gentle-agents checks === "1"): this
|
|
76
|
+
// publishes to an external host, so an ambiguous marker never enables it.
|
|
77
|
+
if (!env.HC_TERMINAL_ID || env.PI_PROGRAM_STATUS_APP !== "gentle-shell" || env.GENTLE_PI_AGENTS_CHILD !== undefined) return;
|
|
78
|
+
const now = options.now ?? Date.now;
|
|
79
|
+
const schedule = options.schedule ?? ((fn: () => void, ms: number) => {
|
|
80
|
+
const timer = setTimeout(fn, ms); timer.unref(); return () => clearTimeout(timer);
|
|
81
|
+
});
|
|
82
|
+
let owner: Session | undefined;
|
|
83
|
+
// Keep seen job identities across replacement of the same session so an
|
|
84
|
+
// old finished sidebar tail cannot revive a record we just cleared.
|
|
85
|
+
const seenJobsBySession = new Map<string, Set<string>>();
|
|
86
|
+
// Records a closing owner could not clear. The next owner starts from them, so
|
|
87
|
+
// its first diff clears them unless it publishes a replacement with the same ID.
|
|
88
|
+
let unflushed = new Map<string, DesktopRecord>();
|
|
89
|
+
const owns = (ctx: ExtensionContext) => owner !== undefined && ctx.sessionManager === owner.manager && ctx.sessionManager.getSessionId() === owner.id;
|
|
90
|
+
// Track successful individual writes so a later cleanup can clear even a
|
|
91
|
+
// partially published diff if terminal.write throws.
|
|
92
|
+
const apply = (s: Session, next: Map<string, DesktopRecord>): boolean => {
|
|
93
|
+
if (!s.terminal) return true;
|
|
94
|
+
for (const chunk of diffRecords(s.previous, next)) {
|
|
95
|
+
try { s.terminal.write(chunk); } catch { return false; }
|
|
96
|
+
const id = /:id=([A-Za-z0-9_./-]+)\x1b\\$/.exec(chunk)?.[1];
|
|
97
|
+
if (!id) continue;
|
|
98
|
+
const record = next.get(id);
|
|
99
|
+
if (record) s.previous.set(id, record); else s.previous.delete(id);
|
|
100
|
+
}
|
|
101
|
+
return true;
|
|
102
|
+
};
|
|
103
|
+
const publish = (s: Session) => {
|
|
104
|
+
if (owner !== s) return;
|
|
105
|
+
const time = now();
|
|
106
|
+
for (const [target, at] of s.sends) if (time - at >= SEND_TTL_MS) s.sends.delete(target);
|
|
107
|
+
for (const [id, error] of s.errors) if (time >= error.expiresAt) s.errors.delete(id);
|
|
108
|
+
const targets = [...new Set(s.consults.values())];
|
|
109
|
+
const next = projectAll({ todo: s.todo,
|
|
110
|
+
jobs: s.jobs && { jobs: s.jobs.jobs.map(job => ({ ...job, id: segment(job.id) })) },
|
|
111
|
+
subagents: s.tasks.map(task => ({ ...task, id: segment(task.id, 54) })),
|
|
112
|
+
waits: targets.map(target => segment(target)), sends: [...s.sends].map(([target, at]) => ({ target: segment(target), at })), now: time });
|
|
113
|
+
// IDs are opaque safe segments, but the user-facing text names the real target.
|
|
114
|
+
for (const target of targets) { const item = next.get(`wait/${segment(target)}`); if (item) item.msg = `consulting ${target}`; }
|
|
115
|
+
for (const target of s.sends.keys()) { const item = next.get(`sent/${segment(target)}`); if (item) item.msg = `sent to ${target}`; }
|
|
116
|
+
for (const [id, error] of s.errors) next.set(id, error.record);
|
|
117
|
+
for (const [peer, pending] of s.asksFromPeers) {
|
|
118
|
+
const name = [...pending.values()].at(-1);
|
|
119
|
+
if (name !== undefined) next.set(`ask/${segment(peer)}`, { state: "blocked", kind: "question", title: name, msg: `question from ${name}` });
|
|
120
|
+
}
|
|
121
|
+
s.dirty = !apply(s, next);
|
|
122
|
+
// arm keeps the earliest deadline, so a pending TTL timer never delays the retry.
|
|
123
|
+
if (s.dirty) arm(s);
|
|
124
|
+
};
|
|
125
|
+
const arm = (s: Session) => {
|
|
126
|
+
s.cancelTimer?.(); s.cancelTimer = undefined;
|
|
127
|
+
if (owner !== s || (s.sends.size === 0 && s.errors.size === 0 && !s.dirty)) return;
|
|
128
|
+
const deadlines = [...s.sends.values()].map(at => at + SEND_TTL_MS);
|
|
129
|
+
for (const error of s.errors.values()) deadlines.push(error.expiresAt);
|
|
130
|
+
if (s.dirty) deadlines.push(now() + WRITE_RETRY_MS);
|
|
131
|
+
const delay = Math.max(0, Math.min(...deadlines) - now());
|
|
132
|
+
s.cancelTimer = schedule(() => { s.cancelTimer = undefined; publish(s); arm(s); }, delay);
|
|
133
|
+
};
|
|
134
|
+
const close = (s: Session) => {
|
|
135
|
+
s.cancelTimer?.(); s.cancelTimer = undefined;
|
|
136
|
+
for (const unsubscribe of s.unsubscribe) unsubscribe();
|
|
137
|
+
s.unsubscribe = [];
|
|
138
|
+
apply(s, new Map());
|
|
139
|
+
if (owner === s) { owner = undefined; unflushed = new Map(s.previous); }
|
|
140
|
+
};
|
|
141
|
+
const updateTodo = (s: Session, tasks: unknown) => {
|
|
142
|
+
if (!validTodoTasks(tasks)) return;
|
|
143
|
+
s.todo = todoProgress({ tasks, nextId: 1, updatedTurn: null }, s.id);
|
|
144
|
+
publish(s);
|
|
145
|
+
};
|
|
146
|
+
const replay = (s: Session) => {
|
|
147
|
+
try { updateTodo(s, replayTodo(s.manager.getBranch()).tasks); } catch { /* malformed branch is ignored */ }
|
|
148
|
+
};
|
|
149
|
+
pi.on("session_start", (_event, ctx) => {
|
|
150
|
+
if (owner) close(owner);
|
|
151
|
+
if (ctx.mode !== "tui" || !ctx.hasUI) return;
|
|
152
|
+
const id = ctx.sessionManager.getSessionId();
|
|
153
|
+
if (!id) return;
|
|
154
|
+
const seenJobErrors = seenJobsBySession.get(id) ?? new Set<string>();
|
|
155
|
+
seenJobsBySession.set(id, seenJobErrors);
|
|
156
|
+
const s: Session = { id, startedAt: now(), ctx, manager: ctx.sessionManager, previous: unflushed, dirty: false, tasks: [], jobMetadata: new Map(), taskLabels: new Map(), consults: new Map(), sends: new Map(), asksFromPeers: new Map(), errors: new Map(), seenJobErrors, seenTaskErrors: new Set(), unsubscribe: [] };
|
|
157
|
+
owner = s;
|
|
158
|
+
unflushed = new Map();
|
|
159
|
+
const listen = (name: string, handler: (data: any) => void) => {
|
|
160
|
+
s.unsubscribe.push(pi.events.on(name, (data: unknown) => {
|
|
161
|
+
try { if (owner === s && s.manager.getSessionId() === s.id && data && typeof data === "object" && (data as { sessionId?: unknown }).sessionId === s.id) handler(data); }
|
|
162
|
+
catch { /* A malformed display event is ignored. */ }
|
|
163
|
+
}));
|
|
164
|
+
};
|
|
165
|
+
listen(TODO_PROGRESS_EVENT, data => { if (validProgress(data)) { s.todo = data; publish(s); } });
|
|
166
|
+
const updateJob = (job: RunningJobDisplay) => {
|
|
167
|
+
const id = `bg/${segment(job.id)}`;
|
|
168
|
+
const identity = JSON.stringify([job.id, job.startedAt]);
|
|
169
|
+
const previous = s.jobMetadata.get(identity);
|
|
170
|
+
const metadata = {
|
|
171
|
+
explicitLabel: hasUsableDesktopLabel(job.explicitLabel) ? job.explicitLabel : previous?.explicitLabel,
|
|
172
|
+
kind: job.kind === "command" || job.kind === "monitor" ? job.kind : previous?.kind,
|
|
173
|
+
};
|
|
174
|
+
s.jobMetadata.set(identity, metadata);
|
|
175
|
+
const failure = job.status === "failed" ? "failed"
|
|
176
|
+
: job.status === "exited" && typeof job.exitCode === "number" && Number.isFinite(job.exitCode) && job.exitCode !== 0 ? `exited ${job.exitCode}` : undefined;
|
|
177
|
+
if (failure && !s.seenJobErrors.has(identity)) {
|
|
178
|
+
s.seenJobErrors.add(identity);
|
|
179
|
+
if (job.endedAt === undefined || job.endedAt >= s.startedAt) {
|
|
180
|
+
s.errors.set(id, { record: { state: "error", title: desktopJobTitle(metadata), msg: failure }, expiresAt: now() + ERROR_TTL_MS });
|
|
181
|
+
}
|
|
182
|
+
} else if (!failure) {
|
|
183
|
+
s.errors.delete(id);
|
|
184
|
+
if (job.status === undefined) s.seenJobErrors.delete(identity);
|
|
185
|
+
}
|
|
186
|
+
};
|
|
187
|
+
const updateJobs = (data: any) => {
|
|
188
|
+
if (!isJobsSidebarSnapshot(data.snapshot) || !Array.from(data.snapshot.jobs).every(job => job !== undefined)) return;
|
|
189
|
+
s.jobs = data.snapshot;
|
|
190
|
+
for (const job of data.snapshot.jobs) updateJob(job);
|
|
191
|
+
publish(s); arm(s);
|
|
192
|
+
};
|
|
193
|
+
listen(JOBS_SIDEBAR_EVENT, updateJobs);
|
|
194
|
+
listen(HERDR_DESKTOP_JOBS, updateJobs);
|
|
195
|
+
listen(HERDR_DESKTOP_JOB_SETTLED, data => {
|
|
196
|
+
if (!data.job || typeof data.job !== "object") return;
|
|
197
|
+
// Reuse the sidebar validator without reading a local command as a title.
|
|
198
|
+
const { id, explicitLabel, kind, startedAt, status, endedAt, exitCode } = data.job;
|
|
199
|
+
const snapshot = { jobs: [{ id, explicitLabel, kind, startedAt, status, endedAt, exitCode, label: "" }] };
|
|
200
|
+
if (!isJobsSidebarSnapshot(snapshot)) return;
|
|
201
|
+
const job = snapshot.jobs[0]!;
|
|
202
|
+
if (job.status === undefined) return;
|
|
203
|
+
updateJob(job);
|
|
204
|
+
// The edge can precede the sidebar refresh, including for success.
|
|
205
|
+
if (s.jobs) s.jobs = { jobs: s.jobs.jobs.filter(active => active.id !== job.id || active.startedAt !== job.startedAt) };
|
|
206
|
+
publish(s); arm(s);
|
|
207
|
+
});
|
|
208
|
+
listen(HERDR_DESKTOP_TASKS, data => {
|
|
209
|
+
if (!validTasks(data.tasks)) return;
|
|
210
|
+
for (const task of data.tasks) if (hasUsableDesktopLabel(task.explicitLabel)) s.taskLabels.set(task.id, task.explicitLabel);
|
|
211
|
+
s.tasks = data.tasks; publish(s);
|
|
212
|
+
});
|
|
213
|
+
listen(HERDR_DESKTOP_TASK_FINISHED, data => {
|
|
214
|
+
if (!validTasks([data.task]) || (data.task.status !== "failed" && data.task.status !== "timed_out")) return;
|
|
215
|
+
const task = data.task as HerdrDesktopTask;
|
|
216
|
+
const id = `subagents/${segment(task.id, 54)}`;
|
|
217
|
+
if (s.seenTaskErrors.has(id)) return;
|
|
218
|
+
s.seenTaskErrors.add(id);
|
|
219
|
+
const explicitLabel = hasUsableDesktopLabel(task.explicitLabel) ? task.explicitLabel : s.taskLabels.get(task.id);
|
|
220
|
+
const title = desktopTaskTitle({ explicitLabel, agent: task.agent });
|
|
221
|
+
s.errors.set(id, { record: { state: "error", title, msg: task.status === "timed_out" ? "timed out" : "failed" }, expiresAt: now() + ERROR_TTL_MS });
|
|
222
|
+
s.tasks = s.tasks.filter(active => active.id !== task.id);
|
|
223
|
+
publish(s); arm(s);
|
|
224
|
+
});
|
|
225
|
+
listen(HERDR_DESKTOP_CONSULT, data => {
|
|
226
|
+
if (typeof data.target !== "string" || !data.target || typeof data.callId !== "string" || !data.callId) return;
|
|
227
|
+
if (data.phase === "start") { if (s.consults.has(data.callId)) return; s.consults.set(data.callId, data.target); }
|
|
228
|
+
else if (data.phase === "settle") { if (s.consults.get(data.callId) !== data.target) return; s.consults.delete(data.callId); }
|
|
229
|
+
else return;
|
|
230
|
+
publish(s);
|
|
231
|
+
});
|
|
232
|
+
listen(HERDR_DESKTOP_SEND, data => {
|
|
233
|
+
if (typeof data.target !== "string" || !data.target) return;
|
|
234
|
+
s.sends.set(data.target, now()); publish(s); arm(s);
|
|
235
|
+
});
|
|
236
|
+
listen(HERDR_DESKTOP_INBOUND, data => {
|
|
237
|
+
if (typeof data.peer !== "string" || !data.peer.trim() || typeof data.id !== "string" || !data.id.trim()
|
|
238
|
+
|| (data.peerName !== undefined && typeof data.peerName !== "string")) return;
|
|
239
|
+
if (data.phase === "received") {
|
|
240
|
+
const pending = s.asksFromPeers.get(data.peer) ?? new Map<string, string>();
|
|
241
|
+
pending.set(data.id, data.peerName?.trim() || data.peer);
|
|
242
|
+
s.asksFromPeers.set(data.peer, pending);
|
|
243
|
+
} else if (data.phase === "handled") {
|
|
244
|
+
const pending = s.asksFromPeers.get(data.peer);
|
|
245
|
+
if (!pending?.delete(data.id)) return;
|
|
246
|
+
if (pending.size === 0) s.asksFromPeers.delete(data.peer);
|
|
247
|
+
} else return;
|
|
248
|
+
publish(s);
|
|
249
|
+
});
|
|
250
|
+
// Replay before the terminal attaches so the first diff already has the todo
|
|
251
|
+
// and replaces an unflushed record instead of clearing it first.
|
|
252
|
+
replay(s);
|
|
253
|
+
ctx.ui.setWidget(WIDGET_KEY, tui => {
|
|
254
|
+
if (owner === s) { s.terminal = tui.terminal; publish(s); }
|
|
255
|
+
return { render: () => [], invalidate() {}, dispose() { if (owner === s) close(s); } };
|
|
256
|
+
});
|
|
257
|
+
try { pi.events.emit(HERDR_DESKTOP_TASKS_REQUEST, { sessionId: s.id }); } catch { /* Optional display source. */ }
|
|
258
|
+
});
|
|
259
|
+
pi.on("session_tree", (_event, ctx) => { if (owns(ctx)) replay(owner!); });
|
|
260
|
+
pi.on("tool_execution_end", (event, ctx) => {
|
|
261
|
+
if (!owns(ctx) || event.toolName !== "todo" || event.isError) return;
|
|
262
|
+
try {
|
|
263
|
+
const details = (event.result as { details?: { gentleTodo?: TodoState; error?: unknown } })?.details;
|
|
264
|
+
if (details && Object.hasOwn(details, "gentleTodo") && !details.error) updateTodo(owner!, details.gentleTodo?.tasks);
|
|
265
|
+
} catch { /* Malformed result is ignored. */ }
|
|
266
|
+
});
|
|
267
|
+
pi.on("session_shutdown", (_event, ctx) => {
|
|
268
|
+
if (!owns(ctx)) return;
|
|
269
|
+
const s = owner!; close(s);
|
|
270
|
+
if (ctx.mode === "tui" && ctx.hasUI) ctx.ui.setWidget(WIDGET_KEY, undefined);
|
|
271
|
+
});
|
|
272
|
+
};
|
|
273
|
+
}
|
|
274
|
+
|
|
275
|
+
export default createHerdrDesktopStatusExtension();
|