gentle-pi 4.8.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 +60 -0
- package/assets/agents/gentle-ai-explore.md +1 -1
- package/assets/agents/gentle-ai-verify.md +1 -1
- package/assets/agents/gentle-ai-worker.md +10 -9
- package/assets/design-canvas/canvas-boards.js +22 -2
- package/assets/design-canvas/canvas-boot.js +3 -1
- package/assets/design-canvas/canvas-i18n-es.js +5 -0
- package/assets/design-canvas/canvas-menu.js +13 -7
- package/assets/design-canvas/canvas-messages.js +1 -1
- package/assets/design-canvas/canvas-rail.js +5 -2
- package/assets/design-canvas/canvas-store.js +3 -0
- package/assets/design-canvas/canvas-theme.js +69 -0
- package/assets/design-canvas/canvas.css +27 -2
- package/assets/design-canvas/index.html +3 -0
- package/assets/design-canvas/inspector.js +28 -5
- package/assets/design-canvas/theme-early.js +10 -0
- package/assets/migrations/agent-body-history.json +6 -0
- package/assets/orchestrator-delegation.md +1 -5
- package/assets/orchestrator-full-delegation-card.md +9 -13
- package/assets/orchestrator-full-delegation.md +2 -2
- package/assets/orchestrator-memory.md +2 -2
- package/assets/orchestrator-prompts.md +3 -31
- package/assets/orchestrator-tracking.md +6 -6
- package/assets/orchestrator-verification.md +4 -4
- package/assets/orchestrator-writer.md +12 -12
- package/assets/orchestrator.md +2 -2
- package/bin/gentle-shell.mjs +77 -1
- package/contracts/review-provider-contract-mirror/provider-contract.lock.json +7 -7
- package/contracts/review-provider-contract-mirror/{v1.5.0 → v1.6.0}/bundle/manifest.json +3 -3
- package/contracts/review-provider-contract-mirror/{v1.5.0 → v1.6.0}/bundle/orchestration/pi.md +1 -1
- package/contracts/review-provider-contract-mirror/{v1.5.0 → v1.6.0}/bundle/routing/pi.md +10 -10
- package/contracts/review-provider-contract-mirror/{v1.5.0 → v1.6.0}/generated/provider-capabilities.baseline.json +3 -3
- package/contracts/review-provider-contract-mirror/{v1.5.0 → v1.6.0}/generated/provider-roles.baseline.json +1 -1
- package/docs/assets/features/gentle-tower.png +0 -0
- package/docs/auto-permission-answers.md +1 -1
- package/docs/bundled-install.md +1 -1
- package/docs/delegated-verification.md +6 -4
- package/docs/desktop-feed.md +303 -0
- package/docs/desktop-rpc.md +703 -25
- package/docs/fast-mode.md +2 -2
- package/docs/gentle-shell-desktop.md +465 -0
- package/docs/gentle-shell.md +65 -3
- 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 +1 -1
- package/docs/odd-preparation-continuity.md +1 -1
- package/docs/readme-reference.md +44 -15
- package/docs/work-continuity.md +10 -7
- package/extensions/ask-user-choice.ts +36 -18
- package/extensions/ask-user-question.ts +47 -8
- package/extensions/gentle-agents.ts +206 -37
- package/extensions/gentle-ai.ts +234 -24
- package/extensions/gentle-desktop-feed.ts +778 -0
- package/extensions/gentle-desktop-rpc.ts +145 -12
- package/extensions/gentle-herdr-desktop-status.ts +275 -0
- package/extensions/gentle-shell.ts +69 -7
- package/extensions/gentle-stats.ts +30 -1
- package/extensions/gentle-tower.ts +305 -0
- package/extensions/skill-registry.ts +13 -3
- 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/agents-protocol.ts +2 -0
- package/lib/agents-rpc-publisher.ts +39 -12
- package/lib/agents-runner.ts +1 -0
- package/lib/auto-permission-answers.ts +2 -1
- package/lib/background-jobs.ts +22 -2
- package/lib/bounded-writer-admission.ts +1 -1
- package/lib/change-diff.ts +104 -0
- package/lib/commit-slice-signal.ts +1 -1
- package/lib/design-canvas-assets.ts +2 -0
- package/lib/desktop-agents-service.ts +31 -10
- package/lib/desktop-changes-service.ts +171 -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 +34 -7
- package/lib/desktop-review-service.ts +187 -0
- package/lib/desktop-rpc-agents.ts +112 -3
- package/lib/desktop-rpc-changes.ts +223 -0
- package/lib/desktop-rpc-config-watch.ts +285 -0
- package/lib/desktop-rpc-config.ts +162 -8
- package/lib/desktop-rpc-jobs.ts +118 -9
- package/lib/desktop-rpc-permissions.ts +154 -3
- 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.ts +116 -5
- 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/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/jobs-sidebar-state.ts +5 -0
- package/lib/native-review-cli.ts +7 -0
- package/lib/openai-fast-tier.ts +1 -0
- package/lib/session-profile-freeze.ts +13 -5
- 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/package.json +13 -4
- package/runtime/design-canvas-assets.mjs +2 -0
- package/runtime/gentle-shell-desktop.mjs +1371 -0
- package/runtime/gentle-shell-launcher.mjs +44 -2
- package/runtime/native-review-cli.mjs +7 -0
- 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/build-full-delegation-card.mjs +1 -21
- package/scripts/build-runtime-modules.mjs +9 -0
- package/scripts/gentle-ai-installer.mjs +10 -10
- package/scripts/verify-package-files.mjs +35 -15
- package/skills/provider-defect-report/SKILL.md +61 -0
- package/skills/rdd-defect-workflow/SKILL.md +3 -3
- package/tests/agent-prompt-diet-contract.test.ts +2 -2
- package/tests/append-system-prompt-route.test.ts +16 -5
- package/tests/ask-user-choice.test.ts +78 -21
- package/tests/ask-user-question.test.ts +59 -5
- package/tests/auto-permission-answers.test.ts +12 -1
- package/tests/background-jobs.test.ts +12 -0
- package/tests/bounded-stop-contract.test.ts +139 -26
- package/tests/change-diff.test.ts +75 -0
- package/tests/commit-slice-signal.test.ts +3 -2
- package/tests/decision-routing-contract.test.ts +390 -0
- package/tests/delegated-key-learnings-contract.test.ts +21 -28
- package/tests/delivery-b-rendered-surfaces.test.ts +32 -0
- package/tests/design-canvas-i18n.test.ts +24 -22
- package/tests/design-canvas-inspector.test.ts +67 -0
- package/tests/design-canvas-modules.test.ts +3 -2
- package/tests/design-canvas-rail.test.ts +10 -10
- package/tests/design-canvas-store.test.ts +9 -0
- package/tests/design-canvas-theme.test.ts +198 -0
- package/tests/design-canvas-tokens.test.ts +1 -1
- 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 +428 -2
- 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 +11 -1
- package/tests/desktop-rpc-design.test.ts +11 -1
- package/tests/desktop-rpc-jobs.test.ts +402 -5
- package/tests/desktop-rpc-permissions.test.ts +11 -1
- package/tests/desktop-rpc-review.test.ts +678 -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 +11 -1
- package/tests/desktop-rpc.test.ts +43 -2
- package/tests/fixtures/primary-session-prompt/gentleman.golden.md +11 -13
- package/tests/fixtures/session-profile-v1/replay.ts +4 -1
- package/tests/full-delegation-closure.test.ts +20 -1
- package/tests/gentle-agents.test.ts +519 -4
- package/tests/gentle-ai-binary.test.ts +1 -1
- package/tests/gentle-ai-installer.test.ts +52 -52
- package/tests/gentle-ai.test.ts +75 -16
- package/tests/gentle-fast.test.ts +15 -0
- package/tests/gentle-herdr-desktop-status.test.ts +595 -0
- 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.test.ts +3 -0
- package/tests/gentle-tower.test.ts +578 -0
- package/tests/herdr-desktop-status.test.ts +285 -0
- package/tests/independent-recovery-delivery.test.ts +16 -4
- package/tests/installer-server.test.ts +2 -2
- package/tests/lazy-module-contradictions-contract.test.ts +27 -4
- package/tests/maintainer/desktop-rpc.maintest.ts +279 -4
- package/tests/native-review-capability-contract.test.ts +9 -1
- package/tests/no-self-pause-contract.test.ts +23 -13
- package/tests/odd-routing-canonical-ratchet.test.ts +10 -0
- package/tests/odd-routing-contract.test.ts +19 -3
- package/tests/orchestrator-budget.test.ts +3 -1
- package/tests/orchestrator-prompt-budget.test.ts +2 -1
- package/tests/orchestrator-prompt-diet-contract.test.ts +31 -3
- package/tests/package-manifest.test.ts +10 -10
- package/tests/pi-routing-measured-values.test.ts +24 -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 +118 -100
- package/tests/review-contract-prompt.test.ts +2 -1
- package/tests/review-due-public-boundary.test.ts +2 -1
- package/tests/sensitive-path-tools.test.ts +138 -4
- package/tests/session-profile-extension.test.ts +310 -16
- package/tests/session-profile-freeze.test.ts +26 -0
- package/tests/session-profile-v1-compat.test.ts +20 -0
- package/tests/skill-collision-prefixes.test.ts +1 -0
- package/tests/skill-contradictions-contract.test.ts +5 -3
- package/tests/skill-registry.test.ts +54 -0
- package/tests/stats-collector.test.ts +109 -2
- package/tests/support/design-canvas-dom.ts +17 -0
- package/tests/task-size-routing-contract.test.ts +7 -3
- 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/verification-scoped-stop-contract.test.ts +32 -0
- package/tests/verification-tiers-contract.test.ts +5 -5
- package/tests/verifier-settle-reminder.test.ts +2 -2
- package/tests/verify-first-launch-contract.test.ts +2 -2
- package/tests/work-continuity-contract.test.ts +83 -17
- package/tests/writer-rejection-next-step.test.ts +55 -0
- package/tests/writer-surface-authority-contract.test.ts +158 -0
- /package/contracts/review-provider-contract-mirror/{v1.5.0 → v1.6.0}/bundle/README.md +0 -0
- /package/contracts/review-provider-contract-mirror/{v1.5.0 → v1.6.0}/bundle/schemas/lens.schema.json +0 -0
- /package/contracts/review-provider-contract-mirror/{v1.5.0 → v1.6.0}/bundle/schemas/refuter.schema.json +0 -0
- /package/contracts/review-provider-contract-mirror/{v1.5.0 → v1.6.0}/bundle/schemas/targeted-validator.schema.json +0 -0
- /package/contracts/review-provider-contract-mirror/{v1.5.0 → v1.6.0}/bundle/vectors/lens.json +0 -0
- /package/contracts/review-provider-contract-mirror/{v1.5.0 → v1.6.0}/bundle/vectors/refuter.json +0 -0
- /package/contracts/review-provider-contract-mirror/{v1.5.0 → v1.6.0}/bundle/vectors/targeted-validator.json +0 -0
package/lib/desktop-rpc-jobs.ts
CHANGED
|
@@ -4,16 +4,17 @@
|
|
|
4
4
|
//
|
|
5
5
|
// Nothing here starts, stops, or polls a job. It only names the wire shapes,
|
|
6
6
|
// projects the owner's actual `JobRecord` state into the safe Desktop
|
|
7
|
-
// projection,
|
|
8
|
-
// Desktop list uses
|
|
7
|
+
// projection, defines the bounded running + recent-finished selection the
|
|
8
|
+
// Desktop list uses, and turns the owner's bounded output tail into the plain
|
|
9
|
+
// text `get_job_output` answers. The owner (the single parent-session `JobRegistry` plus
|
|
9
10
|
// the parent `MonitorController`, reached through `job_stop`'s exact stop
|
|
10
11
|
// path) stays the single source of truth; this module is a projection, not a
|
|
11
12
|
// second registry, process manager, or store.
|
|
12
13
|
|
|
13
|
-
import type
|
|
14
|
+
import { MAX_TAIL_LINE_CHARS, TAIL_LINES, type JobRecord, type JobStatus } from "./background-jobs.ts";
|
|
14
15
|
import { JOBS_FINISHED_TTL_MS } from "./jobs-widget.ts";
|
|
15
16
|
|
|
16
|
-
export const DESKTOP_JOBS_METHODS = ["list_jobs", "cancel_job"] as const;
|
|
17
|
+
export const DESKTOP_JOBS_METHODS = ["list_jobs", "cancel_job", "get_job_output"] as const;
|
|
17
18
|
export const DESKTOP_JOBS_EVENT = "jobs_update";
|
|
18
19
|
/** Advertised only because the owner seam records the registry changes this event carries. */
|
|
19
20
|
export const DESKTOP_JOBS_EVENTS = [DESKTOP_JOBS_EVENT] as const;
|
|
@@ -27,13 +28,22 @@ export const DESKTOP_JOBS_SERVICE_CHANNEL = "gentle:desktop:jobs-service";
|
|
|
27
28
|
/** Upper bound on the number of jobs one list answer carries (running + recent finished). */
|
|
28
29
|
export const DESKTOP_JOBS_LIST_LIMIT = 50;
|
|
29
30
|
|
|
31
|
+
/**
|
|
32
|
+
* Upper bound, in UTF-16 code units, on one `get_job_output` text: the owner
|
|
33
|
+
* tail's own bound (`TAIL_LINES` lines of at most `MAX_TAIL_LINE_CHARS`
|
|
34
|
+
* characters plus the owner's one-character cut marker) joined by newlines.
|
|
35
|
+
*/
|
|
36
|
+
export const DESKTOP_JOB_OUTPUT_MAX_CHARS = TAIL_LINES * (MAX_TAIL_LINE_CHARS + 1) + (TAIL_LINES - 1);
|
|
37
|
+
|
|
30
38
|
export type DesktopJobStatus = JobStatus;
|
|
31
39
|
|
|
32
40
|
/**
|
|
33
41
|
* The safe wire window for one job. Only these fields exist on the wire:
|
|
34
42
|
* identity, the human label, the status word, start/end timestamps, and the
|
|
35
|
-
* exit code when the owner recorded one. Never a command, cwd, output path
|
|
36
|
-
*
|
|
43
|
+
* exit code when the owner recorded one. Never a command, cwd, output path,
|
|
44
|
+
* environment, owner session id, monitor counters, or an error string. The
|
|
45
|
+
* output tail is not part of this entry: it crosses only through the separate,
|
|
46
|
+
* owner-verified `get_job_output` read (`DesktopJobOutput`).
|
|
37
47
|
*/
|
|
38
48
|
export interface DesktopJobEntry {
|
|
39
49
|
id: string;
|
|
@@ -50,6 +60,29 @@ export interface DesktopJobsOwnerRead {
|
|
|
50
60
|
jobs: DesktopJobEntry[];
|
|
51
61
|
}
|
|
52
62
|
|
|
63
|
+
/**
|
|
64
|
+
* The `get_job_output` answer for one owned job: the job's own whitelisted
|
|
65
|
+
* projection, its bounded output tail as one plain-text field, and whether that
|
|
66
|
+
* tail is incomplete. `output` is the owner's in-memory tail (the last
|
|
67
|
+
* `TAIL_LINES` lines, each at most `MAX_TAIL_LINE_CHARS` characters) with
|
|
68
|
+
* terminal control sequences removed (see `plainJobOutput`). Otherwise it is the
|
|
69
|
+
* job's own unsanitized process output: it can contain anything the job printed,
|
|
70
|
+
* including echoed commands, paths, or secrets. No command, cwd, output path,
|
|
71
|
+
* environment, owner session id, monitor counter, or error string is ever a
|
|
72
|
+
* separate field.
|
|
73
|
+
*/
|
|
74
|
+
export interface DesktopJobOutput {
|
|
75
|
+
job: DesktopJobEntry;
|
|
76
|
+
output: string;
|
|
77
|
+
/** True when earlier output was dropped or a line was shortened. */
|
|
78
|
+
truncated: boolean;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
/** A `get_job_output` owner result; a foreign or unknown id is `not_found`. */
|
|
82
|
+
export type DesktopJobsOutputOutcome =
|
|
83
|
+
| { kind: "ok"; view: DesktopJobOutput }
|
|
84
|
+
| { kind: "not_found" };
|
|
85
|
+
|
|
53
86
|
/**
|
|
54
87
|
* A `cancel_job` owner result. `changed` is `true` only when the job really
|
|
55
88
|
* transitioned from running to stopped; an already-terminal job answers
|
|
@@ -68,6 +101,12 @@ export interface DesktopJobsService {
|
|
|
68
101
|
schema: typeof DESKTOP_JOBS_SERVICE_SCHEMA;
|
|
69
102
|
read(): DesktopJobsOwnerRead;
|
|
70
103
|
cancel(id: string): DesktopJobsCancelOutcome;
|
|
104
|
+
/**
|
|
105
|
+
* Read one owned job's bounded output tail. Optional so an owner adapter
|
|
106
|
+
* without it stays a valid list/cancel owner; the bridge then answers
|
|
107
|
+
* `get_job_output` with `jobs_unavailable`.
|
|
108
|
+
*/
|
|
109
|
+
output?(id: string): DesktopJobsOutputOutcome;
|
|
71
110
|
/** Subscribe to actual registry changes; the unsubscribe stops delivery. */
|
|
72
111
|
observe(onChange: (sessionId: string) => void): () => void;
|
|
73
112
|
dispose(): void;
|
|
@@ -127,6 +166,72 @@ export function selectDesktopJobs(jobs: readonly JobRecord[], now: number): Desk
|
|
|
127
166
|
return [...running, ...finished].slice(0, DESKTOP_JOBS_LIST_LIMIT).map(projectDesktopJob);
|
|
128
167
|
}
|
|
129
168
|
|
|
169
|
+
// Terminal control sequences, matched per line: OSC (BEL- or ST-terminated, or
|
|
170
|
+
// unterminated to the end of the line), DCS/SOS/PM/APC strings, CSI (7- and
|
|
171
|
+
// 8-bit), and the remaining two-character escapes.
|
|
172
|
+
const TERMINAL_SEQUENCE = /\u001b\][\s\S]*?(?:\u0007|\u001b\\|$)|\u001b[PX^_][\s\S]*?(?:\u001b\\|$)|\u001b\[[0-?]*[ -/]*[@-~]|\u009b[0-?]*[ -/]*[@-~]|\u001b[ -/]*[0-~]/g;
|
|
173
|
+
// Every other C0/C1 control character except tab (a line never holds a newline).
|
|
174
|
+
const CONTROL_CHARACTER = /[\u0000-\u0008\u000b-\u001f\u007f-\u009f]/g;
|
|
175
|
+
// Half of a UTF-16 pair, left behind when a line was cut at a fixed length.
|
|
176
|
+
const LONE_SURROGATE = /[\ud800-\udbff](?![\udc00-\udfff])|(?<![\ud800-\udbff])[\udc00-\udfff]/g;
|
|
177
|
+
|
|
178
|
+
/**
|
|
179
|
+
* One tail line as plain text: terminal control sequences (colors, cursor
|
|
180
|
+
* moves, titles, hyperlinks) are removed, a carriage-return progress line keeps
|
|
181
|
+
* only its last non-empty segment (what a terminal leaves visible), other
|
|
182
|
+
* control characters except tab are dropped, and a half character left by a
|
|
183
|
+
* length cut is removed. Idempotent, so the bridge can re-apply it to an owner
|
|
184
|
+
* answer.
|
|
185
|
+
*/
|
|
186
|
+
function plainJobOutputLine(line: string): string {
|
|
187
|
+
const segments = line.replace(TERMINAL_SEQUENCE, "").split("\r");
|
|
188
|
+
let visible = "";
|
|
189
|
+
for (let index = segments.length - 1; index >= 0; index -= 1) {
|
|
190
|
+
if (segments[index] !== "") {
|
|
191
|
+
visible = segments[index]!;
|
|
192
|
+
break;
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
return visible.replace(CONTROL_CHARACTER, "").replace(LONE_SURROGATE, "");
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
/** Owner tail lines as one plain-text field, newline-joined (see `plainJobOutputLine`). */
|
|
199
|
+
export function plainJobOutput(lines: readonly string[]): string {
|
|
200
|
+
return lines.map(plainJobOutputLine).join("\n");
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
/**
|
|
204
|
+
* The whitelisted `get_job_output` projection of one owner `JobRecord`: the job
|
|
205
|
+
* projection, its bounded tail as plain text, and the owner's truncation flag.
|
|
206
|
+
* Nothing else on the record is read.
|
|
207
|
+
*/
|
|
208
|
+
export function projectDesktopJobOutput(job: JobRecord): DesktopJobOutput {
|
|
209
|
+
return {
|
|
210
|
+
job: projectDesktopJob(job),
|
|
211
|
+
output: plainJobOutput(job.tail.slice(-TAIL_LINES)),
|
|
212
|
+
truncated: job.tailTruncated === true,
|
|
213
|
+
};
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
/**
|
|
217
|
+
* Defensive validation of one owner `get_job_output` answer. It crosses the
|
|
218
|
+
* event bus, so it is re-validated, re-bounded to `TAIL_LINES` lines and
|
|
219
|
+
* `DESKTOP_JOB_OUTPUT_MAX_CHARS` code units (newest output kept, `truncated`
|
|
220
|
+
* set when anything is cut), and re-normalized to plain text.
|
|
221
|
+
*/
|
|
222
|
+
export function parseDesktopJobOutput(value: unknown): DesktopJobOutput | undefined {
|
|
223
|
+
if (!value || typeof value !== "object") return undefined;
|
|
224
|
+
const raw = value as Record<string, unknown>;
|
|
225
|
+
const job = parseDesktopJobEntry(raw.job);
|
|
226
|
+
if (job === undefined) return undefined;
|
|
227
|
+
if (typeof raw.output !== "string" || typeof raw.truncated !== "boolean") return undefined;
|
|
228
|
+
const oversized = raw.output.length > DESKTOP_JOB_OUTPUT_MAX_CHARS;
|
|
229
|
+
const text = oversized ? raw.output.slice(-DESKTOP_JOB_OUTPUT_MAX_CHARS) : raw.output;
|
|
230
|
+
const lines = text.split("\n");
|
|
231
|
+
const kept = lines.slice(-TAIL_LINES);
|
|
232
|
+
return { job, output: plainJobOutput(kept), truncated: raw.truncated || oversized || kept.length < lines.length };
|
|
233
|
+
}
|
|
234
|
+
|
|
130
235
|
/**
|
|
131
236
|
* Defensive validation of one owner-projected entry. The owner's answer crosses
|
|
132
237
|
* the event bus, so its shape is never trusted beyond the fields the bridge
|
|
@@ -161,10 +266,11 @@ export function parseListJobsParams(params: Record<string, unknown>): { ok: true
|
|
|
161
266
|
}
|
|
162
267
|
|
|
163
268
|
/**
|
|
164
|
-
* `cancel_job` params are exactly `{ id: non-empty
|
|
165
|
-
* a typed `invalid_request` before any owner work
|
|
269
|
+
* `cancel_job` and `get_job_output` params are exactly `{ id: non-empty
|
|
270
|
+
* string }`. Anything else is a typed `invalid_request` before any owner work
|
|
271
|
+
* happens.
|
|
166
272
|
*/
|
|
167
|
-
|
|
273
|
+
function parseJobIdParams(params: Record<string, unknown>): { id: string } | { error: { code: string; message: string } } {
|
|
168
274
|
const keys = Object.keys(params);
|
|
169
275
|
if (keys.length !== 1 || keys[0] !== "id" || typeof params.id !== "string" || params.id.length === 0) {
|
|
170
276
|
return { error: INVALID_JOBS_PARAMS };
|
|
@@ -172,6 +278,9 @@ export function parseCancelJobParams(params: Record<string, unknown>): { id: str
|
|
|
172
278
|
return { id: params.id };
|
|
173
279
|
}
|
|
174
280
|
|
|
281
|
+
export const parseCancelJobParams = parseJobIdParams;
|
|
282
|
+
export const parseJobOutputParams = parseJobIdParams;
|
|
283
|
+
|
|
175
284
|
/** True only for the adapter-shaped object the discovery responder must return. */
|
|
176
285
|
export function isDesktopJobsServiceShape(value: unknown): value is DesktopJobsService {
|
|
177
286
|
if (!value || typeof value !== "object") return false;
|
|
@@ -2,6 +2,13 @@ import type { ExtensionAPI, ExtensionContext } from "@earendil-works/pi-coding-a
|
|
|
2
2
|
import { discoverYoloUiAdapter, YOLO_DISPLAY, type YoloUiAdapter } from "./yolo-session-policy.ts";
|
|
3
3
|
import { isPermissionMode, type PermissionMode } from "./permission-mode-policy.ts";
|
|
4
4
|
import type { DesktopRpcOutcome } from "./desktop-rpc.ts";
|
|
5
|
+
import {
|
|
6
|
+
createDesktopDebouncer,
|
|
7
|
+
DESKTOP_CHANGE_DEBOUNCE_MS,
|
|
8
|
+
realDesktopChangeTimers,
|
|
9
|
+
type DesktopChangeTimers,
|
|
10
|
+
type DesktopDebouncer,
|
|
11
|
+
} from "./desktop-rpc-config-watch.ts";
|
|
5
12
|
|
|
6
13
|
export const DESKTOP_PERMISSION_METHODS = ["get_permission_mode", "set_permission_mode"] as const;
|
|
7
14
|
export const DESKTOP_PERMISSION_EVENT = "permission_mode_changed";
|
|
@@ -14,6 +21,17 @@ const DEFAULT_UNCHANGED = { code: "default_unchanged", message: "Default permiss
|
|
|
14
21
|
|
|
15
22
|
type PermissionState = { mode: PermissionMode; defaultMode: PermissionMode };
|
|
16
23
|
|
|
24
|
+
export type DesktopPermissionEmit = (event: string, data: Record<string, unknown>) => void;
|
|
25
|
+
|
|
26
|
+
export interface DesktopPermissionWatchOptions {
|
|
27
|
+
timers?: DesktopChangeTimers;
|
|
28
|
+
debounceMs?: number;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
function sameState(left: PermissionState, right: PermissionState): boolean {
|
|
32
|
+
return left.mode === right.mode && left.defaultMode === right.defaultMode;
|
|
33
|
+
}
|
|
34
|
+
|
|
17
35
|
function parseSetParams(params: Record<string, unknown>): { mode: unknown; persist: boolean } | undefined {
|
|
18
36
|
for (const key of Object.keys(params)) {
|
|
19
37
|
if (key !== "mode" && key !== "persist") return undefined;
|
|
@@ -31,6 +49,15 @@ function parseSetParams(params: Record<string, unknown>): { mode: unknown; persi
|
|
|
31
49
|
* store, no second file reader, and no filesystem watcher. Every mutation is
|
|
32
50
|
* validated by the owner (interactive host, live session identity, atomic save);
|
|
33
51
|
* this bridge only shapes owner results into the Desktop RPC contract.
|
|
52
|
+
*
|
|
53
|
+
* Once wired for an interactive RPC host, the bridge subscribes to the owner's
|
|
54
|
+
* existing observer (`observe`, the same one the desktop feed uses). Each owner
|
|
55
|
+
* notification restarts a short debounce window; when it closes, the bridge
|
|
56
|
+
* re-reads the owner and emits `permission_mode_changed` with
|
|
57
|
+
* `source: "external"` only when the state differs from the last state this
|
|
58
|
+
* channel reported. Desktop requests record what they reported, and an observer
|
|
59
|
+
* window that closes while a Desktop change is in flight is deferred until it
|
|
60
|
+
* finishes, so a Desktop change is never echoed as an external one.
|
|
34
61
|
*/
|
|
35
62
|
export class DesktopPermissionBridge {
|
|
36
63
|
private readonly pi: ExtensionAPI;
|
|
@@ -39,10 +66,27 @@ export class DesktopPermissionBridge {
|
|
|
39
66
|
private discovering: Promise<YoloUiAdapter | undefined> | undefined;
|
|
40
67
|
private host: ExtensionContext | undefined;
|
|
41
68
|
private generation = 0;
|
|
69
|
+
private readonly debouncer: DesktopDebouncer;
|
|
70
|
+
private emit: DesktopPermissionEmit | undefined;
|
|
71
|
+
private unobserve: (() => void) | undefined;
|
|
72
|
+
/** The last state this channel reported, and a counter bumped on every report. */
|
|
73
|
+
private reported: PermissionState | undefined;
|
|
74
|
+
private reportEpoch = 0;
|
|
75
|
+
private setsInFlight = 0;
|
|
76
|
+
private refreshDeferred = false;
|
|
42
77
|
|
|
43
|
-
constructor(
|
|
78
|
+
constructor(
|
|
79
|
+
pi: ExtensionAPI,
|
|
80
|
+
discover: typeof discoverYoloUiAdapter = discoverYoloUiAdapter,
|
|
81
|
+
watch: DesktopPermissionWatchOptions = {},
|
|
82
|
+
) {
|
|
44
83
|
this.pi = pi;
|
|
45
84
|
this.discover = discover;
|
|
85
|
+
this.debouncer = createDesktopDebouncer(
|
|
86
|
+
watch.timers ?? realDesktopChangeTimers,
|
|
87
|
+
watch.debounceMs ?? DESKTOP_CHANGE_DEBOUNCE_MS,
|
|
88
|
+
() => void this.refresh(),
|
|
89
|
+
);
|
|
46
90
|
}
|
|
47
91
|
|
|
48
92
|
/** The live interactive context of this Desktop session; bound per command. */
|
|
@@ -54,9 +98,22 @@ export class DesktopPermissionBridge {
|
|
|
54
98
|
reset(): void {
|
|
55
99
|
this.generation += 1;
|
|
56
100
|
const adapter = this.adapter;
|
|
101
|
+
const unobserve = this.unobserve;
|
|
57
102
|
this.adapter = undefined;
|
|
58
103
|
this.discovering = undefined;
|
|
59
104
|
this.host = undefined;
|
|
105
|
+
this.emit = undefined;
|
|
106
|
+
this.unobserve = undefined;
|
|
107
|
+
this.reported = undefined;
|
|
108
|
+
this.reportEpoch += 1;
|
|
109
|
+
this.setsInFlight = 0;
|
|
110
|
+
this.refreshDeferred = false;
|
|
111
|
+
this.debouncer.cancel();
|
|
112
|
+
try {
|
|
113
|
+
unobserve?.();
|
|
114
|
+
} catch {
|
|
115
|
+
/* display-only owner teardown */
|
|
116
|
+
}
|
|
60
117
|
try {
|
|
61
118
|
adapter?.dispose();
|
|
62
119
|
} catch {
|
|
@@ -64,13 +121,88 @@ export class DesktopPermissionBridge {
|
|
|
64
121
|
}
|
|
65
122
|
}
|
|
66
123
|
|
|
124
|
+
/**
|
|
125
|
+
* Interactive RPC hosts only, after `attach`: subscribe to the owner observer
|
|
126
|
+
* and record the current state as the baseline, so wiring never emits by
|
|
127
|
+
* itself. A missing owner simply leaves the session without external events.
|
|
128
|
+
*/
|
|
129
|
+
async wire(emit: DesktopPermissionEmit): Promise<void> {
|
|
130
|
+
const context = this.host;
|
|
131
|
+
if (!context) return;
|
|
132
|
+
this.emit = emit;
|
|
133
|
+
const generation = this.generation;
|
|
134
|
+
try {
|
|
135
|
+
const adapter = await this.owner(context);
|
|
136
|
+
if (generation !== this.generation || !adapter || this.unobserve) return;
|
|
137
|
+
this.unobserve = adapter.observe(() => this.debouncer.schedule());
|
|
138
|
+
const epoch = this.reportEpoch;
|
|
139
|
+
const state = await this.read(context);
|
|
140
|
+
if (generation !== this.generation || epoch !== this.reportEpoch || !state) return;
|
|
141
|
+
this.report(state);
|
|
142
|
+
} catch {
|
|
143
|
+
// A failing owner leaves this session without external permission
|
|
144
|
+
// events; nothing reaches the caller or the process as a rejection.
|
|
145
|
+
if (generation !== this.generation) return;
|
|
146
|
+
this.emit = undefined;
|
|
147
|
+
this.debouncer.cancel();
|
|
148
|
+
const unobserve = this.unobserve;
|
|
149
|
+
this.unobserve = undefined;
|
|
150
|
+
try {
|
|
151
|
+
unobserve?.();
|
|
152
|
+
} catch {
|
|
153
|
+
/* display-only owner teardown */
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
private report(state: PermissionState): void {
|
|
159
|
+
this.reported = state;
|
|
160
|
+
this.reportEpoch += 1;
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
/** Debounced owner notification: emit only a state this channel has not reported. */
|
|
164
|
+
private async refresh(): Promise<void> {
|
|
165
|
+
const context = this.host;
|
|
166
|
+
const emit = this.emit;
|
|
167
|
+
if (!context || !emit) return;
|
|
168
|
+
if (this.setsInFlight > 0) {
|
|
169
|
+
this.refreshDeferred = true;
|
|
170
|
+
return;
|
|
171
|
+
}
|
|
172
|
+
const generation = this.generation;
|
|
173
|
+
const epoch = this.reportEpoch;
|
|
174
|
+
const state = await this.read(context);
|
|
175
|
+
// A newer report (a Desktop request, or a reset) owns the state now.
|
|
176
|
+
if (generation !== this.generation || epoch !== this.reportEpoch || !state) return;
|
|
177
|
+
if (this.setsInFlight > 0) {
|
|
178
|
+
this.refreshDeferred = true;
|
|
179
|
+
return;
|
|
180
|
+
}
|
|
181
|
+
const previous = this.reported;
|
|
182
|
+
this.report(state);
|
|
183
|
+
if (!previous || sameState(previous, state)) return;
|
|
184
|
+
try {
|
|
185
|
+
emit(DESKTOP_PERMISSION_EVENT, {
|
|
186
|
+
mode: state.mode,
|
|
187
|
+
previous_mode: previous.mode,
|
|
188
|
+
default_mode: state.defaultMode,
|
|
189
|
+
persisted: state.defaultMode !== previous.defaultMode,
|
|
190
|
+
source: "external",
|
|
191
|
+
});
|
|
192
|
+
} catch {
|
|
193
|
+
/* a closed transport never throws back into the owner observer */
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
|
|
67
197
|
async handle(method: string, params: Record<string, unknown>): Promise<DesktopRpcOutcome | undefined> {
|
|
68
198
|
const context = this.host;
|
|
69
199
|
if (!context) return { ok: false, error: UNAVAILABLE };
|
|
70
200
|
if (method === "get_permission_mode") {
|
|
71
201
|
if (Object.keys(params).length > 0) return { ok: false, error: INVALID_PARAMS };
|
|
72
202
|
const state = await this.read(context);
|
|
73
|
-
|
|
203
|
+
if (!state) return { ok: false, error: UNAVAILABLE };
|
|
204
|
+
this.report(state);
|
|
205
|
+
return { ok: true, data: { mode: state.mode, default_mode: state.defaultMode } };
|
|
74
206
|
}
|
|
75
207
|
if (method === "set_permission_mode") return this.set(context, params);
|
|
76
208
|
return undefined;
|
|
@@ -107,8 +239,8 @@ export class DesktopPermissionBridge {
|
|
|
107
239
|
|
|
108
240
|
private async read(context: ExtensionContext): Promise<PermissionState | undefined> {
|
|
109
241
|
const adapter = await this.owner(context);
|
|
110
|
-
if (!adapter || typeof adapter.readSnapshot !== "function") return undefined;
|
|
111
242
|
try {
|
|
243
|
+
if (!adapter || typeof adapter.readSnapshot !== "function") return undefined;
|
|
112
244
|
const snapshot = await adapter.readSnapshot();
|
|
113
245
|
if (!snapshot || snapshot.yolo === YOLO_DISPLAY.unavailable) return undefined;
|
|
114
246
|
if (!isPermissionMode(snapshot.mode) || !isPermissionMode(snapshot.defaultMode)) return undefined;
|
|
@@ -122,6 +254,22 @@ export class DesktopPermissionBridge {
|
|
|
122
254
|
const parsed = parseSetParams(params);
|
|
123
255
|
if (!parsed) return { ok: false, error: INVALID_PARAMS };
|
|
124
256
|
if (!isPermissionMode(parsed.mode)) return { ok: false, error: INVALID_MODE };
|
|
257
|
+
const generation = this.generation;
|
|
258
|
+
this.setsInFlight += 1;
|
|
259
|
+
try {
|
|
260
|
+
return await this.apply(context, { mode: parsed.mode, persist: parsed.persist });
|
|
261
|
+
} finally {
|
|
262
|
+
if (generation === this.generation) {
|
|
263
|
+
this.setsInFlight -= 1;
|
|
264
|
+
if (this.setsInFlight === 0 && this.refreshDeferred) {
|
|
265
|
+
this.refreshDeferred = false;
|
|
266
|
+
this.debouncer.schedule();
|
|
267
|
+
}
|
|
268
|
+
}
|
|
269
|
+
}
|
|
270
|
+
}
|
|
271
|
+
|
|
272
|
+
private async apply(context: ExtensionContext, parsed: { mode: PermissionMode; persist: boolean }): Promise<DesktopRpcOutcome> {
|
|
125
273
|
const adapter = await this.owner(context);
|
|
126
274
|
if (!adapter || typeof adapter.setMode !== "function") return { ok: false, error: UNAVAILABLE };
|
|
127
275
|
const before = await this.read(context);
|
|
@@ -153,6 +301,9 @@ export class DesktopPermissionBridge {
|
|
|
153
301
|
// owner is not enforcing.
|
|
154
302
|
const after = await this.read(context);
|
|
155
303
|
if (!after) return { ok: false, error: UNAVAILABLE };
|
|
304
|
+
// Recorded before the response leaves: the owner notified its observers
|
|
305
|
+
// while applying this request, and that window must find nothing new.
|
|
306
|
+
this.report(after);
|
|
156
307
|
const mode = after.mode;
|
|
157
308
|
const defaultMode = after.defaultMode;
|
|
158
309
|
const changed = mode !== before.mode || defaultMode !== before.defaultMode;
|
|
@@ -0,0 +1,180 @@
|
|
|
1
|
+
// Gentle Desktop review-mode contract (#3324): the pure wire shapes, the
|
|
2
|
+
// owner-service interface, strict param parsers, the whitelist projection of
|
|
3
|
+
// the owner's receipt-driven development (RDD) status, and the confirmation
|
|
4
|
+
// text and token. The owner is `extensions/gentle-ai.ts`, which reads and
|
|
5
|
+
// writes the switch through the same native review CLI adapter the
|
|
6
|
+
// `/gentle:review-mode` command uses; nothing here runs `gentle-ai`.
|
|
7
|
+
|
|
8
|
+
import { createHash } from "node:crypto";
|
|
9
|
+
|
|
10
|
+
export const DESKTOP_REVIEW_METHODS = ["get_review_mode", "set_review_mode"] as const;
|
|
11
|
+
export const DESKTOP_REVIEW_MODE_CHANGED_EVENT = "review_mode_changed";
|
|
12
|
+
export const DESKTOP_REVIEW_EVENTS = [DESKTOP_REVIEW_MODE_CHANGED_EVENT] as const;
|
|
13
|
+
export const DESKTOP_REVIEW_SERVICE_SCHEMA = "gentle-pi.desktop-review-service/v1";
|
|
14
|
+
export const DESKTOP_REVIEW_SERVICE_CHANNEL = "gentle:desktop:review-service";
|
|
15
|
+
|
|
16
|
+
const MAX_TOKEN_LENGTH = 128;
|
|
17
|
+
|
|
18
|
+
export const REVIEW_UNAVAILABLE = { code: "review_unavailable", message: "Review mode is not available in this session" } as const;
|
|
19
|
+
export const REVIEW_STATE_UNREADABLE = { code: "review_unavailable", message: "Review mode could not be read; nothing was changed" } as const;
|
|
20
|
+
export const REVIEW_WRITE_UNCONFIRMED = { code: "review_unavailable", message: "The review mode change did not complete; re-read the mode" } as const;
|
|
21
|
+
export const REVIEW_MODE_BUSY = { code: "review_mode_busy", message: "Another review mode change is in progress" } as const;
|
|
22
|
+
export const INVALID_GET_REVIEW_MODE = { code: "invalid_request", message: "Invalid get_review_mode parameters" } as const;
|
|
23
|
+
export const INVALID_SET_REVIEW_MODE = { code: "invalid_request", message: "Invalid set_review_mode parameters" } as const;
|
|
24
|
+
|
|
25
|
+
/** One scope's stored value as the owner reports it: `""` means unset. */
|
|
26
|
+
export type DesktopReviewOwnerScopeValue = "on" | "off" | "";
|
|
27
|
+
|
|
28
|
+
/** The owner's status, already decoded by the native adapter (`gentle-ai.rdd-mode-status/v1`). */
|
|
29
|
+
export interface DesktopReviewOwnerStatus {
|
|
30
|
+
global: DesktopReviewOwnerScopeValue;
|
|
31
|
+
cloneLocal: DesktopReviewOwnerScopeValue;
|
|
32
|
+
effective: "on" | "off";
|
|
33
|
+
source: "default" | "global" | "clone_local";
|
|
34
|
+
revision?: string;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/** `unavailable`: no adapter, or `gentle-ai` is missing or does not support the command. `unknown`: the read failed or timed out. */
|
|
38
|
+
export type DesktopReviewOwnerRead =
|
|
39
|
+
| { kind: "status"; status: DesktopReviewOwnerStatus }
|
|
40
|
+
| { kind: "unknown" }
|
|
41
|
+
| { kind: "unavailable" };
|
|
42
|
+
|
|
43
|
+
/** A write answers the owner's re-read after it, or `failed` when the write's outcome is unknown. */
|
|
44
|
+
export type DesktopReviewOwnerWrite = DesktopReviewOwnerRead | { kind: "failed" };
|
|
45
|
+
|
|
46
|
+
export type DesktopReviewScope = "clone" | "global";
|
|
47
|
+
|
|
48
|
+
export interface DesktopReviewSetRequest {
|
|
49
|
+
enabled: boolean;
|
|
50
|
+
scope: DesktopReviewScope;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
export interface DesktopReviewService {
|
|
54
|
+
readonly schema: typeof DESKTOP_REVIEW_SERVICE_SCHEMA;
|
|
55
|
+
read(): Promise<DesktopReviewOwnerRead>;
|
|
56
|
+
write(request: DesktopReviewSetRequest): Promise<DesktopReviewOwnerWrite>;
|
|
57
|
+
dispose(): void;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
export type DesktopReviewWireScope = "enabled" | "disabled" | "unset" | "unknown";
|
|
61
|
+
|
|
62
|
+
/** The wire projection: never a raw owner value, never CLI output. */
|
|
63
|
+
export interface DesktopReviewMode {
|
|
64
|
+
effective: "enabled" | "disabled" | "unknown";
|
|
65
|
+
source: "default" | "global" | "clone" | "unknown";
|
|
66
|
+
scopes: { global: DesktopReviewWireScope; clone: DesktopReviewWireScope };
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
export const UNKNOWN_REVIEW_MODE: DesktopReviewMode = Object.freeze({
|
|
70
|
+
effective: "unknown",
|
|
71
|
+
source: "unknown",
|
|
72
|
+
scopes: Object.freeze({ global: "unknown", clone: "unknown" }),
|
|
73
|
+
}) as DesktopReviewMode;
|
|
74
|
+
|
|
75
|
+
export function isDesktopReviewServiceShape(value: unknown): value is DesktopReviewService {
|
|
76
|
+
if (!value || typeof value !== "object") return false;
|
|
77
|
+
const service = value as Partial<DesktopReviewService>;
|
|
78
|
+
return service.schema === DESKTOP_REVIEW_SERVICE_SCHEMA && typeof service.read === "function" && typeof service.write === "function" && typeof service.dispose === "function";
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
function isScopeValue(value: unknown): value is DesktopReviewOwnerScopeValue {
|
|
82
|
+
return value === "on" || value === "off" || value === "";
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
/** Re-validates an owner status that crossed the event bus; anything unrecognized is undefined. */
|
|
86
|
+
export function parseDesktopReviewOwnerStatus(value: unknown): DesktopReviewOwnerStatus | undefined {
|
|
87
|
+
if (!value || typeof value !== "object") return undefined;
|
|
88
|
+
const status = value as Record<string, unknown>;
|
|
89
|
+
if (!isScopeValue(status.global) || !isScopeValue(status.cloneLocal)) return undefined;
|
|
90
|
+
if (status.effective !== "on" && status.effective !== "off") return undefined;
|
|
91
|
+
if (status.source !== "default" && status.source !== "global" && status.source !== "clone_local") return undefined;
|
|
92
|
+
if (status.revision !== undefined && (typeof status.revision !== "string" || status.revision.length > MAX_TOKEN_LENGTH)) return undefined;
|
|
93
|
+
return {
|
|
94
|
+
global: status.global,
|
|
95
|
+
cloneLocal: status.cloneLocal,
|
|
96
|
+
effective: status.effective,
|
|
97
|
+
source: status.source,
|
|
98
|
+
...(status.revision === undefined ? {} : { revision: status.revision as string }),
|
|
99
|
+
};
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
function wireScope(value: DesktopReviewOwnerScopeValue): DesktopReviewWireScope {
|
|
103
|
+
return value === "on" ? "enabled" : value === "off" ? "disabled" : "unset";
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
export function projectDesktopReviewMode(status: DesktopReviewOwnerStatus | undefined): DesktopReviewMode {
|
|
107
|
+
if (!status) return { effective: "unknown", source: "unknown", scopes: { global: "unknown", clone: "unknown" } };
|
|
108
|
+
return {
|
|
109
|
+
effective: status.effective === "on" ? "enabled" : "disabled",
|
|
110
|
+
source: status.source === "clone_local" ? "clone" : status.source,
|
|
111
|
+
scopes: { global: wireScope(status.global), clone: wireScope(status.cloneLocal) },
|
|
112
|
+
};
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
export function parseGetReviewModeParams(params: Record<string, unknown>): boolean {
|
|
116
|
+
return Object.keys(params).length === 0;
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
export function parseSetReviewModeParams(params: Record<string, unknown>): (DesktopReviewSetRequest & { confirmationToken?: string }) | undefined {
|
|
120
|
+
for (const key of Object.keys(params)) {
|
|
121
|
+
if (key !== "enabled" && key !== "scope" && key !== "confirmationToken") return undefined;
|
|
122
|
+
}
|
|
123
|
+
if (typeof params.enabled !== "boolean") return undefined;
|
|
124
|
+
if (params.scope !== "clone" && params.scope !== "global") return undefined;
|
|
125
|
+
const token = params.confirmationToken;
|
|
126
|
+
if (token === undefined) return { enabled: params.enabled, scope: params.scope };
|
|
127
|
+
if (typeof token !== "string" || token.length === 0 || token.length > MAX_TOKEN_LENGTH) return undefined;
|
|
128
|
+
return { enabled: params.enabled, scope: params.scope, confirmationToken: token };
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
function sourceLabel(source: DesktopReviewOwnerStatus["source"]): string {
|
|
132
|
+
return source === "global" ? "the machine-wide setting" : source === "clone_local" ? "this repository's setting" : "the default";
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
/**
|
|
136
|
+
* The dialog Desktop must show before a change. It names the current state and
|
|
137
|
+
* the owner's exact semantics; it never carries a path, a command line, or CLI
|
|
138
|
+
* output.
|
|
139
|
+
*/
|
|
140
|
+
export function desktopReviewModeConfirmation(request: DesktopReviewSetRequest, status: DesktopReviewOwnerStatus): { title: string; message: string; token: string } {
|
|
141
|
+
const where = request.scope === "global" ? "machine-wide" : "for this repository";
|
|
142
|
+
const title = `Turn review mode ${request.enabled ? "on" : "off"} ${where}?`;
|
|
143
|
+
const current = `Receipt-driven development is currently ${status.effective} (decided by ${sourceLabel(status.source)}).`;
|
|
144
|
+
let effect: string;
|
|
145
|
+
if (request.scope === "global") {
|
|
146
|
+
effect = request.enabled
|
|
147
|
+
? "Reviews will be on for every repository on this machine, except a repository with its own off setting."
|
|
148
|
+
: "Reviews will be off for every repository on this machine.";
|
|
149
|
+
} else if (!request.enabled) {
|
|
150
|
+
effect = "Reviews will be off for this repository only.";
|
|
151
|
+
} else if (status.global === "off") {
|
|
152
|
+
effect = "This only clears this repository's off setting. Review mode is off machine-wide, and a repository setting cannot override that, so reviews stay off.";
|
|
153
|
+
} else {
|
|
154
|
+
effect = "This clears this repository's off setting; it cannot override a machine-wide off.";
|
|
155
|
+
}
|
|
156
|
+
const message = `${current} ${effect}`;
|
|
157
|
+
return { title, message, token: desktopReviewModeToken(request, title, message, status) };
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
/** sha256 over the request, the exact text shown, and the owner state it was computed from. */
|
|
161
|
+
export function desktopReviewModeToken(request: DesktopReviewSetRequest, title: string, message: string, status: DesktopReviewOwnerStatus): string {
|
|
162
|
+
const state = [status.global, status.cloneLocal, status.effective, status.source, status.revision ?? null];
|
|
163
|
+
return createHash("sha256").update(JSON.stringify([request.enabled, request.scope, title, message, state])).digest("hex");
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
// Process-wide: the review-mode owner and this bridge may load this module
|
|
167
|
+
// separately, so the single-flight gate lives on a registered symbol.
|
|
168
|
+
const SET_GATE = Symbol.for("gentle-shell.desktop-review-mode-set");
|
|
169
|
+
type GateHost = { [SET_GATE]?: boolean };
|
|
170
|
+
|
|
171
|
+
export function beginDesktopReviewModeSet(): boolean {
|
|
172
|
+
const host = globalThis as GateHost;
|
|
173
|
+
if (host[SET_GATE]) return false;
|
|
174
|
+
host[SET_GATE] = true;
|
|
175
|
+
return true;
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
export function endDesktopReviewModeSet(): void {
|
|
179
|
+
(globalThis as GateHost)[SET_GATE] = false;
|
|
180
|
+
}
|