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
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
// Gentle Desktop update-status slice: the pure contract shared by the Desktop
|
|
2
|
+
// bridge (`lib/desktop-updates-service.ts`) and the update sources it reads
|
|
3
|
+
// (`lib/update-status.ts`).
|
|
4
|
+
//
|
|
5
|
+
// Nothing here reaches the network or the filesystem. The sources supply what
|
|
6
|
+
// Gentle Shell's own channel and version resolution and Pi's own package
|
|
7
|
+
// update check already know; this module only parses the request and projects
|
|
8
|
+
// those facts into the safe, bounded Desktop shape. It never decides that
|
|
9
|
+
// something is up to date without a successful lookup.
|
|
10
|
+
|
|
11
|
+
export const DESKTOP_UPDATES_METHODS = ["get_update_status"] as const;
|
|
12
|
+
/** Update status is an explicit read: this slice advertises no event. */
|
|
13
|
+
export const DESKTOP_UPDATES_EVENTS = [] as const;
|
|
14
|
+
|
|
15
|
+
export const INVALID_UPDATES_PARAMS = { code: "invalid_request", message: "Invalid update status parameters" } as const;
|
|
16
|
+
export const UPDATES_UNAVAILABLE = { code: "updates_unavailable", message: "Update status unavailable" } as const;
|
|
17
|
+
|
|
18
|
+
/** Upper bound on the package rows one answer carries. */
|
|
19
|
+
export const DESKTOP_UPDATES_LIMITS = { packages: 100 } as const;
|
|
20
|
+
/** Longest package name the wire carries; longer names are cut. */
|
|
21
|
+
export const DESKTOP_UPDATES_NAME_LIMIT = 128;
|
|
22
|
+
/** Longest version string the wire carries; longer values are dropped as unknown. */
|
|
23
|
+
export const DESKTOP_UPDATES_VERSION_LIMIT = 64;
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* How this Gentle Shell was installed, from the existing resolvers: a bundled
|
|
27
|
+
* prefix (`runningBundledPrefix`), gentle-pi loaded as a Pi package
|
|
28
|
+
* (`npm:gentle-pi`, the way the Gentle AI managed stack declares it), or the
|
|
29
|
+
* release/main channel record `gentle-shell upgrade` keeps (`readChannel`).
|
|
30
|
+
* `unknown` when the channel record cannot be read.
|
|
31
|
+
*/
|
|
32
|
+
export type ShellChannel = "release" | "main" | "bundled" | "gentle-ai-managed" | "unknown";
|
|
33
|
+
export type ItemState = "update_available" | "up_to_date" | "unknown";
|
|
34
|
+
/**
|
|
35
|
+
* Pi's package check only says which packages have a newer version, and it
|
|
36
|
+
* treats a failed lookup like "no update". So a package it did not list is
|
|
37
|
+
* `no_update_reported`, never `up_to_date`; `skipped` is a package Pi never
|
|
38
|
+
* checks (pinned, local, or not installed); `unknown` means not checked yet,
|
|
39
|
+
* offline, or the check failed or timed out.
|
|
40
|
+
*/
|
|
41
|
+
export type PackageState = "update_available" | "no_update_reported" | "skipped" | "unknown";
|
|
42
|
+
export type PackageKind = "npm" | "git" | "local" | "unknown";
|
|
43
|
+
|
|
44
|
+
/** Fixed command text per kind of install; never built from user input. */
|
|
45
|
+
export const SHELL_UPDATE_COMMANDS: Readonly<Record<ShellChannel, string | null>> = Object.freeze({
|
|
46
|
+
release: "gentle-shell upgrade",
|
|
47
|
+
main: "gentle-shell upgrade --channel main",
|
|
48
|
+
bundled: "gentle-shell upgrade",
|
|
49
|
+
"gentle-ai-managed": "gentle-shell update --extensions",
|
|
50
|
+
unknown: null,
|
|
51
|
+
});
|
|
52
|
+
export const PI_UPDATE_COMMAND = "gentle-shell update";
|
|
53
|
+
export const PACKAGES_UPDATE_COMMAND = "gentle-shell update --extensions";
|
|
54
|
+
|
|
55
|
+
export interface DesktopUpdatesQuery {
|
|
56
|
+
refresh: boolean;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
export interface DesktopShellUpdate {
|
|
60
|
+
current: string | null;
|
|
61
|
+
latest: string | null;
|
|
62
|
+
channel: ShellChannel;
|
|
63
|
+
state: ItemState;
|
|
64
|
+
command: string | null;
|
|
65
|
+
checkedAt: string | null;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
export interface DesktopPiUpdate {
|
|
69
|
+
current: string | null;
|
|
70
|
+
latest: string | null;
|
|
71
|
+
state: ItemState;
|
|
72
|
+
command: string;
|
|
73
|
+
checkedAt: string | null;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
export interface DesktopPackageUpdate {
|
|
77
|
+
name: string;
|
|
78
|
+
kind: PackageKind;
|
|
79
|
+
scope: "user" | "project";
|
|
80
|
+
current: string | null;
|
|
81
|
+
/** Pi's check reports that a newer version exists, not which one: always null today. */
|
|
82
|
+
latest: string | null;
|
|
83
|
+
pinned: boolean | null;
|
|
84
|
+
state: PackageState;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
export interface DesktopPackagesUpdate {
|
|
88
|
+
/** False when Pi's configured-package listing could not be read. */
|
|
89
|
+
available: boolean;
|
|
90
|
+
items: DesktopPackageUpdate[];
|
|
91
|
+
truncated: boolean;
|
|
92
|
+
command: string;
|
|
93
|
+
checkedAt: string | null;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
/** The `get_update_status` answer. */
|
|
97
|
+
export interface DesktopUpdateStatus {
|
|
98
|
+
/** True only when this answer ran a check (`refresh: true`, not offline). */
|
|
99
|
+
refreshed: boolean;
|
|
100
|
+
/** `PI_OFFLINE` is set: no lookup runs, and nothing is reported as up to date by a check. */
|
|
101
|
+
offline: boolean;
|
|
102
|
+
gentleShell: DesktopShellUpdate;
|
|
103
|
+
pi: DesktopPiUpdate;
|
|
104
|
+
packages: DesktopPackagesUpdate;
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
/** `get_update_status` params: only an optional boolean `refresh`. */
|
|
108
|
+
export function parseUpdateStatusParams(params: Record<string, unknown>): DesktopUpdatesQuery | { error: { code: string; message: string } } {
|
|
109
|
+
if (Object.keys(params).some((key) => key !== "refresh")) return { error: INVALID_UPDATES_PARAMS };
|
|
110
|
+
if (!("refresh" in params)) return { refresh: false };
|
|
111
|
+
if (typeof params.refresh !== "boolean") return { error: INVALID_UPDATES_PARAMS };
|
|
112
|
+
return { refresh: params.refresh };
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
/** A version string safe for the wire, or null. */
|
|
116
|
+
export function boundedVersion(value: unknown): string | null {
|
|
117
|
+
if (typeof value !== "string") return null;
|
|
118
|
+
const trimmed = value.trim();
|
|
119
|
+
if (trimmed.length === 0 || trimmed.length > DESKTOP_UPDATES_VERSION_LIMIT || /[\s\\/]/.test(trimmed)) return null;
|
|
120
|
+
return trimmed;
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
/**
|
|
124
|
+
* A package display name safe for the wire: Pi's own display name (npm name,
|
|
125
|
+
* or `host/path` for git), or the last segment of a local path. Anything
|
|
126
|
+
* that still looks like a path, URL, or credential is replaced by `unknown`.
|
|
127
|
+
*/
|
|
128
|
+
export function packageDisplayName(kind: PackageKind, name: string | undefined): string {
|
|
129
|
+
if (typeof name !== "string") return "unknown";
|
|
130
|
+
let value = name.trim();
|
|
131
|
+
if (kind === "local") value = value.split(/[\\/]+/).filter((segment) => segment.length > 0).at(-1) ?? "";
|
|
132
|
+
if (value.length === 0 || value.includes("://") || value.includes("\\") || value.startsWith("/") || /^[A-Za-z]:/.test(value)) return "unknown";
|
|
133
|
+
// A git display name is `host/path`; userinfo never belongs in it.
|
|
134
|
+
if (kind === "git" && value.split("/")[0]!.includes("@")) return "unknown";
|
|
135
|
+
return value.length > DESKTOP_UPDATES_NAME_LIMIT ? value.slice(0, DESKTOP_UPDATES_NAME_LIMIT) : value;
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
/** Bounds the package rows, keeping their order, and reports the cut. */
|
|
139
|
+
export function boundPackages(items: readonly DesktopPackageUpdate[]): { items: DesktopPackageUpdate[]; truncated: boolean } {
|
|
140
|
+
return { items: items.slice(0, DESKTOP_UPDATES_LIMITS.packages), truncated: items.length > DESKTOP_UPDATES_LIMITS.packages };
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
export const isoTime = (ms: number | undefined): string | null => (typeof ms === "number" && Number.isFinite(ms) ? new Date(ms).toISOString() : null);
|
package/lib/desktop-rpc.ts
CHANGED
|
@@ -20,6 +20,15 @@ export type DesktopRpcDomain = (
|
|
|
20
20
|
params: Record<string, unknown>,
|
|
21
21
|
) => DesktopRpcOutcome | undefined | Promise<DesktopRpcOutcome | undefined>;
|
|
22
22
|
|
|
23
|
+
/**
|
|
24
|
+
* Reads `get_snapshot`'s optional session sections. `undefined` means the
|
|
25
|
+
* request named none, so the legacy snapshot answers unchanged; a success's
|
|
26
|
+
* `data` becomes `state.session`.
|
|
27
|
+
*/
|
|
28
|
+
export type DesktopRpcSessionReader = (
|
|
29
|
+
params: Record<string, unknown>,
|
|
30
|
+
) => DesktopRpcOutcome | undefined | Promise<DesktopRpcOutcome>;
|
|
31
|
+
|
|
23
32
|
type DesktopRpcRequest = {
|
|
24
33
|
schema: typeof DESKTOP_RPC_SCHEMA;
|
|
25
34
|
requestId: string;
|
|
@@ -27,6 +36,15 @@ type DesktopRpcRequest = {
|
|
|
27
36
|
params: Record<string, unknown>;
|
|
28
37
|
};
|
|
29
38
|
|
|
39
|
+
/** A typed refusal a gate or an abandonment answers with. */
|
|
40
|
+
export type DesktopRpcError = { code: string; message: string };
|
|
41
|
+
|
|
42
|
+
/** Decides, before dispatch, whether a request must be refused (for example while a session switch is in flight). */
|
|
43
|
+
export type DesktopRpcGate = (method: string) => DesktopRpcError | undefined;
|
|
44
|
+
|
|
45
|
+
/** One dispatched request still waiting for its asynchronous domain outcome. */
|
|
46
|
+
type PendingRequest = { requestId: string; done: boolean };
|
|
47
|
+
|
|
30
48
|
type DecodedRequest = {
|
|
31
49
|
request?: DesktopRpcRequest;
|
|
32
50
|
requestId: string | null;
|
|
@@ -84,20 +102,26 @@ export class DesktopRpcRouter {
|
|
|
84
102
|
private sequence = 0;
|
|
85
103
|
private publisher: DesktopRpcPublish | undefined;
|
|
86
104
|
private readonly methods: readonly string[];
|
|
87
|
-
|
|
105
|
+
/** A list, or a reader for events whose wiring is only known at request time. */
|
|
106
|
+
private readonly events: readonly string[] | (() => readonly string[]);
|
|
88
107
|
private readonly state: () => DesktopRpcState;
|
|
89
108
|
private readonly domain: DesktopRpcDomain | undefined;
|
|
109
|
+
private readonly session: DesktopRpcSessionReader | undefined;
|
|
110
|
+
private readonly pending = new Set<PendingRequest>();
|
|
111
|
+
private gate: DesktopRpcGate | undefined;
|
|
90
112
|
|
|
91
113
|
constructor(
|
|
92
114
|
methods: readonly string[] = DEFAULT_METHODS,
|
|
93
|
-
events: readonly string[] = [],
|
|
115
|
+
events: readonly string[] | (() => readonly string[]) = [],
|
|
94
116
|
state: () => DesktopRpcState = () => ({}),
|
|
95
117
|
domain?: DesktopRpcDomain,
|
|
118
|
+
session?: DesktopRpcSessionReader,
|
|
96
119
|
) {
|
|
97
120
|
this.methods = methods;
|
|
98
121
|
this.events = events;
|
|
99
122
|
this.state = state;
|
|
100
123
|
this.domain = domain;
|
|
124
|
+
this.session = session;
|
|
101
125
|
}
|
|
102
126
|
|
|
103
127
|
start(publish: DesktopRpcPublish): void {
|
|
@@ -108,6 +132,34 @@ export class DesktopRpcRouter {
|
|
|
108
132
|
stop(): void {
|
|
109
133
|
this.sequence = 0;
|
|
110
134
|
this.publisher = undefined;
|
|
135
|
+
for (const token of this.pending) token.done = true;
|
|
136
|
+
this.pending.clear();
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
/** Install (or clear) the pre-dispatch gate. A gated request is answered synchronously and never reaches a domain. */
|
|
140
|
+
setGate(gate: DesktopRpcGate | undefined): void {
|
|
141
|
+
this.gate = gate;
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
/**
|
|
145
|
+
* Answer every still-pending domain request with `error`, except those
|
|
146
|
+
* `keep` names, and drop their late outcomes. Used right before the session
|
|
147
|
+
* is torn down, so a request dispatched before the teardown still gets
|
|
148
|
+
* exactly one response instead of a silently dropped one.
|
|
149
|
+
*/
|
|
150
|
+
abandonPending(error: DesktopRpcError, keep: (requestId: string) => boolean = () => false): void {
|
|
151
|
+
const publish = this.publisher;
|
|
152
|
+
if (!publish) return;
|
|
153
|
+
for (const token of [...this.pending]) {
|
|
154
|
+
if (keep(token.requestId)) continue;
|
|
155
|
+
token.done = true;
|
|
156
|
+
this.pending.delete(token);
|
|
157
|
+
try {
|
|
158
|
+
publish(JSON.stringify(errorResponse(token.requestId, error.code, error.message)));
|
|
159
|
+
} catch {
|
|
160
|
+
/* transport failures are never retried as a second response */
|
|
161
|
+
}
|
|
162
|
+
}
|
|
111
163
|
}
|
|
112
164
|
|
|
113
165
|
snapshot() {
|
|
@@ -145,6 +197,16 @@ export class DesktopRpcRouter {
|
|
|
145
197
|
publish(JSON.stringify(errorResponse(request.requestId, "unsupported_method", "Unsupported Desktop RPC method")));
|
|
146
198
|
return;
|
|
147
199
|
}
|
|
200
|
+
let refused: DesktopRpcError | undefined;
|
|
201
|
+
try {
|
|
202
|
+
refused = this.gate?.(request.method);
|
|
203
|
+
} catch {
|
|
204
|
+
refused = INTERNAL_ERROR;
|
|
205
|
+
}
|
|
206
|
+
if (refused) {
|
|
207
|
+
publish(JSON.stringify(errorResponse(request.requestId, refused.code, refused.message)));
|
|
208
|
+
return;
|
|
209
|
+
}
|
|
148
210
|
if (request.method !== "capabilities" && request.method !== "get_snapshot") {
|
|
149
211
|
if (!this.domain) {
|
|
150
212
|
publish(JSON.stringify(errorResponse(request.requestId, "unsupported_method", "Unsupported Desktop RPC method")));
|
|
@@ -158,14 +220,20 @@ export class DesktopRpcRouter {
|
|
|
158
220
|
return;
|
|
159
221
|
}
|
|
160
222
|
if (isThenable(outcome)) {
|
|
223
|
+
const token: PendingRequest = { requestId: request.requestId, done: false };
|
|
224
|
+
this.pending.add(token);
|
|
161
225
|
return Promise.resolve(outcome).then(
|
|
162
|
-
(value) => this.settle(publish, request.requestId, value),
|
|
163
|
-
() => this.settle(publish, request.requestId, { ok: false, error: INTERNAL_ERROR }),
|
|
226
|
+
(value) => this.settle(publish, request.requestId, value, token),
|
|
227
|
+
() => this.settle(publish, request.requestId, { ok: false, error: INTERNAL_ERROR }, token),
|
|
164
228
|
);
|
|
165
229
|
}
|
|
166
230
|
this.settle(publish, request.requestId, outcome);
|
|
167
231
|
return;
|
|
168
232
|
}
|
|
233
|
+
if (request.method === "get_snapshot" && this.session) {
|
|
234
|
+
const pending = this.sessionSnapshot(publish, request.requestId, request.params);
|
|
235
|
+
if (pending !== false) return pending;
|
|
236
|
+
}
|
|
169
237
|
|
|
170
238
|
let data: Record<string, unknown>;
|
|
171
239
|
try {
|
|
@@ -176,7 +244,7 @@ export class DesktopRpcRouter {
|
|
|
176
244
|
command: DESKTOP_RPC_COMMAND,
|
|
177
245
|
widget: DESKTOP_RPC_WIDGET,
|
|
178
246
|
methods: [...this.methods],
|
|
179
|
-
events: [...this.events],
|
|
247
|
+
events: [...(typeof this.events === "function" ? this.events() : this.events)],
|
|
180
248
|
};
|
|
181
249
|
break;
|
|
182
250
|
default:
|
|
@@ -190,11 +258,54 @@ export class DesktopRpcRouter {
|
|
|
190
258
|
this.settle(publish, request.requestId, { ok: true, data });
|
|
191
259
|
}
|
|
192
260
|
|
|
261
|
+
/**
|
|
262
|
+
* `get_snapshot` with session sections: the snapshot is assembled once the
|
|
263
|
+
* owner answered, so `sequence` is the one current at answer time. Returns
|
|
264
|
+
* `false` when the request named no sections (the legacy read answers).
|
|
265
|
+
*/
|
|
266
|
+
private sessionSnapshot(publish: DesktopRpcPublish, requestId: string, params: Record<string, unknown>): false | void | Promise<void> {
|
|
267
|
+
let outcome: DesktopRpcOutcome | undefined | Promise<DesktopRpcOutcome>;
|
|
268
|
+
try {
|
|
269
|
+
outcome = this.session!(params);
|
|
270
|
+
} catch {
|
|
271
|
+
this.settle(publish, requestId, { ok: false, error: INTERNAL_ERROR });
|
|
272
|
+
return;
|
|
273
|
+
}
|
|
274
|
+
if (outcome === undefined) return false;
|
|
275
|
+
const finish = (value: DesktopRpcOutcome | undefined) => {
|
|
276
|
+
if (!value || value.ok === false) {
|
|
277
|
+
this.settle(publish, requestId, value ?? { ok: false, error: INTERNAL_ERROR });
|
|
278
|
+
return;
|
|
279
|
+
}
|
|
280
|
+
let data: DesktopRpcState;
|
|
281
|
+
try {
|
|
282
|
+
const snapshot = this.snapshot();
|
|
283
|
+
data = { ...snapshot, state: { ...snapshot.state, session: value.data } };
|
|
284
|
+
} catch {
|
|
285
|
+
this.settle(publish, requestId, { ok: false, error: INTERNAL_ERROR });
|
|
286
|
+
return;
|
|
287
|
+
}
|
|
288
|
+
// A read never carries an event.
|
|
289
|
+
this.settle(publish, requestId, { ok: true, data });
|
|
290
|
+
};
|
|
291
|
+
if (isThenable(outcome)) {
|
|
292
|
+
return Promise.resolve(outcome).then(finish, () => this.settle(publish, requestId, { ok: false, error: INTERNAL_ERROR }));
|
|
293
|
+
}
|
|
294
|
+
finish(outcome);
|
|
295
|
+
}
|
|
296
|
+
|
|
193
297
|
private settle(
|
|
194
298
|
publish: DesktopRpcPublish,
|
|
195
299
|
requestId: string,
|
|
196
300
|
outcome: DesktopRpcOutcome | undefined,
|
|
301
|
+
token?: PendingRequest,
|
|
197
302
|
): void {
|
|
303
|
+
if (token) {
|
|
304
|
+
// Already answered by `abandonPending` (or dropped by `stop`): never a second response.
|
|
305
|
+
if (token.done) return;
|
|
306
|
+
token.done = true;
|
|
307
|
+
this.pending.delete(token);
|
|
308
|
+
}
|
|
198
309
|
if (this.publisher !== publish) return;
|
|
199
310
|
if (!outcome) {
|
|
200
311
|
publish(JSON.stringify(errorResponse(requestId, "unsupported_method", "Unsupported Desktop RPC method")));
|
|
@@ -0,0 +1,223 @@
|
|
|
1
|
+
// Gentle Desktop session-state bridge (#3319): reaches the existing session
|
|
2
|
+
// projection owner (the feed extension, `extensions/gentle-desktop-feed.ts`)
|
|
3
|
+
// through a defensive, versioned owner-service event/adapter — the session
|
|
4
|
+
// analogue of `discoverDesktopJobsService`. It never reads the feed's file and
|
|
5
|
+
// keeps no state of its own beyond the last sections it emitted: every read is
|
|
6
|
+
// the owner's live projection, shaped by `lib/desktop-rpc-session.ts`.
|
|
7
|
+
|
|
8
|
+
import type { ExtensionAPI, ExtensionContext } from "@earendil-works/pi-coding-agent";
|
|
9
|
+
import type { DesktopFeedSnapshot } from "./desktop-feed.ts";
|
|
10
|
+
import {
|
|
11
|
+
DESKTOP_SESSION_EVENT,
|
|
12
|
+
DESKTOP_SESSION_SECTIONS,
|
|
13
|
+
DESKTOP_SESSION_SERVICE_CHANNEL,
|
|
14
|
+
desktopSessionSectionKey,
|
|
15
|
+
isDesktopSessionServiceShape,
|
|
16
|
+
parseSessionSnapshotParams,
|
|
17
|
+
projectDesktopSessionSections,
|
|
18
|
+
SESSION_UNAVAILABLE,
|
|
19
|
+
type DesktopSessionSection,
|
|
20
|
+
type DesktopSessionSections,
|
|
21
|
+
type DesktopSessionService,
|
|
22
|
+
} from "./desktop-rpc-session.ts";
|
|
23
|
+
import type { DesktopRpcOutcome } from "./desktop-rpc.ts";
|
|
24
|
+
|
|
25
|
+
const DISCOVERY_TIMEOUT_MS = 100;
|
|
26
|
+
|
|
27
|
+
/** The `session_snapshot` event payload: only the sections whose content changed. */
|
|
28
|
+
export interface DesktopSessionSnapshotEvent {
|
|
29
|
+
sections: DesktopSessionSections;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
interface HostUiSessionRequest { context: ExtensionContext; respond(service: DesktopSessionService): void }
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* Discover the live feed owner exactly like the jobs seam: emit a bounded,
|
|
36
|
+
* versioned request and accept only an adapter-shaped responder.
|
|
37
|
+
*/
|
|
38
|
+
export function discoverDesktopSessionService(pi: ExtensionAPI, context: ExtensionContext): Promise<DesktopSessionService | undefined> {
|
|
39
|
+
return new Promise((resolve) => {
|
|
40
|
+
let settled = false;
|
|
41
|
+
const timer = setTimeout(() => { settled = true; resolve(undefined); }, DISCOVERY_TIMEOUT_MS);
|
|
42
|
+
const respond = (value: unknown) => {
|
|
43
|
+
if (!isDesktopSessionServiceShape(value)) return;
|
|
44
|
+
if (settled) { value.dispose(); return; }
|
|
45
|
+
settled = true; clearTimeout(timer); resolve(value);
|
|
46
|
+
};
|
|
47
|
+
try {
|
|
48
|
+
pi.events.emit(DESKTOP_SESSION_SERVICE_CHANNEL, { context, respond } satisfies HostUiSessionRequest);
|
|
49
|
+
} catch {
|
|
50
|
+
settled = true; clearTimeout(timer); resolve(undefined);
|
|
51
|
+
}
|
|
52
|
+
});
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
type Emit = (event: string, data: Record<string, unknown>) => void;
|
|
56
|
+
|
|
57
|
+
interface DesktopSessionBridgeOptions {
|
|
58
|
+
discover?: typeof discoverDesktopSessionService;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
/**
|
|
62
|
+
* The Desktop domain slice for `get_snapshot { sections }` and the
|
|
63
|
+
* `session_snapshot` event. The feed owner publishes on its own tiers (urgent,
|
|
64
|
+
* debounced, busy-throttled); this bridge only diffs each published snapshot
|
|
65
|
+
* against the sections it last emitted and forwards the changed ones.
|
|
66
|
+
*/
|
|
67
|
+
export class DesktopSessionBridge {
|
|
68
|
+
private readonly pi: ExtensionAPI;
|
|
69
|
+
private readonly discover: typeof discoverDesktopSessionService;
|
|
70
|
+
private host: ExtensionContext | undefined;
|
|
71
|
+
private service: DesktopSessionService | undefined;
|
|
72
|
+
private discovering: Promise<DesktopSessionService | undefined> | undefined;
|
|
73
|
+
private generation = 0;
|
|
74
|
+
private observeDispose: (() => void) | undefined;
|
|
75
|
+
private emit: Emit | undefined;
|
|
76
|
+
/** Per-section comparison keys of the last state emitted (or seen at subscription). */
|
|
77
|
+
private baseline = new Map<DesktopSessionSection, string>();
|
|
78
|
+
|
|
79
|
+
constructor(pi: ExtensionAPI, options: DesktopSessionBridgeOptions = {}) {
|
|
80
|
+
this.pi = pi;
|
|
81
|
+
this.discover = options.discover ?? discoverDesktopSessionService;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
/** True while the feed owner seam is wired for this session: gates `capabilities`. */
|
|
85
|
+
get wired(): boolean {
|
|
86
|
+
return this.service !== undefined;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
/** The live interactive context of this Desktop session; bound per command. */
|
|
90
|
+
attach(context: ExtensionContext): void {
|
|
91
|
+
this.host = context;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
/** Route feed-published changes through the router's sequencer. */
|
|
95
|
+
wire(emit: Emit): void {
|
|
96
|
+
this.emit = emit;
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
/** Eager discovery/subscription so feed changes arrive before any request. */
|
|
100
|
+
async start(): Promise<void> {
|
|
101
|
+
const host = this.host;
|
|
102
|
+
if (!host) return;
|
|
103
|
+
await this.owner(host);
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
/** Session start/shutdown: the owner adapter of a previous session is invalid. */
|
|
107
|
+
reset(): void {
|
|
108
|
+
this.generation += 1;
|
|
109
|
+
try { this.observeDispose?.(); } catch { /* owner teardown */ }
|
|
110
|
+
this.observeDispose = undefined;
|
|
111
|
+
const service = this.service;
|
|
112
|
+
this.service = undefined;
|
|
113
|
+
this.discovering = undefined;
|
|
114
|
+
this.host = undefined;
|
|
115
|
+
this.emit = undefined;
|
|
116
|
+
this.baseline = new Map();
|
|
117
|
+
try {
|
|
118
|
+
service?.dispose();
|
|
119
|
+
} catch {
|
|
120
|
+
/* owner teardown */
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
/**
|
|
125
|
+
* `get_snapshot` sections. `undefined` (synchronously) when the request
|
|
126
|
+
* names no `sections`, so the router answers its legacy snapshot unchanged;
|
|
127
|
+
* malformed sections fail before any owner work.
|
|
128
|
+
*/
|
|
129
|
+
snapshot(params: Record<string, unknown>): DesktopRpcOutcome | Promise<DesktopRpcOutcome> | undefined {
|
|
130
|
+
const parsed = parseSessionSnapshotParams(params);
|
|
131
|
+
if ("legacy" in parsed) return undefined;
|
|
132
|
+
if ("error" in parsed) return { ok: false, error: parsed.error };
|
|
133
|
+
const host = this.host;
|
|
134
|
+
if (!host) return { ok: false, error: SESSION_UNAVAILABLE };
|
|
135
|
+
const generation = this.generation;
|
|
136
|
+
return this.owner(host).then((service): DesktopRpcOutcome => {
|
|
137
|
+
if (generation !== this.generation || !service) return { ok: false, error: SESSION_UNAVAILABLE };
|
|
138
|
+
const snapshot = this.readOwner(service);
|
|
139
|
+
if (!snapshot) return { ok: false, error: SESSION_UNAVAILABLE };
|
|
140
|
+
return { ok: true, data: projectDesktopSessionSections(snapshot, parsed.sections) as Record<string, unknown> };
|
|
141
|
+
});
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
private async owner(context: ExtensionContext): Promise<DesktopSessionService | undefined> {
|
|
145
|
+
if (this.service) return this.service;
|
|
146
|
+
if (!this.discovering) {
|
|
147
|
+
const generation = this.generation;
|
|
148
|
+
const discovering = Promise.resolve()
|
|
149
|
+
.then(() => this.discover(this.pi, context))
|
|
150
|
+
.then((service) => {
|
|
151
|
+
// A late adapter of a superseded session is disposed, never cached.
|
|
152
|
+
if (generation !== this.generation || !service) {
|
|
153
|
+
try { service?.dispose(); } catch { /* owner teardown */ }
|
|
154
|
+
return undefined;
|
|
155
|
+
}
|
|
156
|
+
this.service = service;
|
|
157
|
+
this.subscribe(service);
|
|
158
|
+
return service;
|
|
159
|
+
})
|
|
160
|
+
.catch(() => undefined)
|
|
161
|
+
.finally(() => {
|
|
162
|
+
if (this.discovering === discovering) this.discovering = undefined;
|
|
163
|
+
});
|
|
164
|
+
this.discovering = discovering;
|
|
165
|
+
}
|
|
166
|
+
return this.discovering;
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
private subscribe(service: DesktopSessionService): void {
|
|
170
|
+
const generation = this.generation;
|
|
171
|
+
// The state at subscription is the baseline: the first event carries
|
|
172
|
+
// only what changed after it.
|
|
173
|
+
const current = this.readOwner(service);
|
|
174
|
+
if (current) this.baseline = this.keys(projectDesktopSessionSections(current, DESKTOP_SESSION_SECTIONS));
|
|
175
|
+
try {
|
|
176
|
+
this.observeDispose = service.observe((snapshot) => {
|
|
177
|
+
if (generation !== this.generation) return;
|
|
178
|
+
this.onSnapshot(snapshot);
|
|
179
|
+
});
|
|
180
|
+
} catch {
|
|
181
|
+
this.observeDispose = undefined;
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
private keys(sections: DesktopSessionSections): Map<DesktopSessionSection, string> {
|
|
186
|
+
const keys = new Map<DesktopSessionSection, string>();
|
|
187
|
+
for (const name of DESKTOP_SESSION_SECTIONS) keys.set(name, desktopSessionSectionKey(name, sections[name]));
|
|
188
|
+
return keys;
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
/** A feed-published snapshot: forward only the sections whose content changed. */
|
|
192
|
+
private onSnapshot(snapshot: DesktopFeedSnapshot): void {
|
|
193
|
+
const emit = this.emit;
|
|
194
|
+
if (!emit) return;
|
|
195
|
+
let sections: DesktopSessionSections;
|
|
196
|
+
try {
|
|
197
|
+
sections = projectDesktopSessionSections(snapshot, DESKTOP_SESSION_SECTIONS);
|
|
198
|
+
} catch {
|
|
199
|
+
return;
|
|
200
|
+
}
|
|
201
|
+
const keys = this.keys(sections);
|
|
202
|
+
const changed: DesktopSessionSections = {};
|
|
203
|
+
let any = false;
|
|
204
|
+
for (const name of DESKTOP_SESSION_SECTIONS) {
|
|
205
|
+
if (keys.get(name) === this.baseline.get(name)) continue;
|
|
206
|
+
changed[name] = sections[name];
|
|
207
|
+
any = true;
|
|
208
|
+
}
|
|
209
|
+
if (!any) return;
|
|
210
|
+
this.baseline = keys;
|
|
211
|
+
emit(DESKTOP_SESSION_EVENT, { sections: changed } satisfies DesktopSessionSnapshotEvent as unknown as Record<string, unknown>);
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
private readOwner(service: DesktopSessionService): DesktopFeedSnapshot | undefined {
|
|
215
|
+
try {
|
|
216
|
+
const snapshot = service.read();
|
|
217
|
+
return snapshot && typeof snapshot === "object" ? snapshot : undefined;
|
|
218
|
+
} catch {
|
|
219
|
+
// Raw owner failures may carry paths; none of it crosses the contract.
|
|
220
|
+
return undefined;
|
|
221
|
+
}
|
|
222
|
+
}
|
|
223
|
+
}
|