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,285 @@
|
|
|
1
|
+
// Best-effort change detection for Desktop RPC's external-change events.
|
|
2
|
+
//
|
|
3
|
+
// Two pieces, both side-effect free until started and both safe to dispose
|
|
4
|
+
// twice: a trailing debouncer over injectable timers, and a directory watcher
|
|
5
|
+
// that turns "something in one of these owner directories changed" into one
|
|
6
|
+
// debounced callback. Neither ever throws into the caller: a directory that
|
|
7
|
+
// cannot be watched (missing, unsupported platform, watcher limits) is skipped,
|
|
8
|
+
// and a watcher that later errors is closed. Revisions stay the source of truth;
|
|
9
|
+
// this module only decides *when* to recompute them.
|
|
10
|
+
|
|
11
|
+
import { existsSync, watch as fsWatch } from "node:fs";
|
|
12
|
+
import { basename, dirname } from "node:path";
|
|
13
|
+
|
|
14
|
+
/** Debounce window shared by config and permission change detection. */
|
|
15
|
+
export const DESKTOP_CHANGE_DEBOUNCE_MS = 250;
|
|
16
|
+
|
|
17
|
+
export interface DesktopChangeTimers {
|
|
18
|
+
set(fn: () => void, ms: number): unknown;
|
|
19
|
+
clear(handle: unknown): void;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export const realDesktopChangeTimers: DesktopChangeTimers = {
|
|
23
|
+
set(fn, ms) {
|
|
24
|
+
const timer = setTimeout(fn, ms);
|
|
25
|
+
timer.unref?.();
|
|
26
|
+
return timer;
|
|
27
|
+
},
|
|
28
|
+
clear(handle) {
|
|
29
|
+
clearTimeout(handle as ReturnType<typeof setTimeout>);
|
|
30
|
+
},
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* Watches one directory and calls `onChange` with the changed entry name when
|
|
35
|
+
* the platform reports one. Answers a closer, or throws when the directory
|
|
36
|
+
* cannot be watched; the caller treats a throw as "no watcher here". When the
|
|
37
|
+
* directory itself disappears the watcher closes itself and calls `onChange`
|
|
38
|
+
* one last time with `removed: true`, so the caller can watch for its return.
|
|
39
|
+
*/
|
|
40
|
+
export type DesktopDirectoryWatch = (
|
|
41
|
+
dir: string,
|
|
42
|
+
onChange: (filename: string | undefined, removed?: boolean) => void,
|
|
43
|
+
) => () => void;
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* `fs.watch` on a directory, non-persistent; a runtime error closes it silently.
|
|
47
|
+
*
|
|
48
|
+
* When the watched directory itself is removed, Windows keeps reporting events
|
|
49
|
+
* for it indefinitely, which keeps the process alive and never reaches the
|
|
50
|
+
* `error` path. A watcher whose directory is gone is therefore closed on its
|
|
51
|
+
* next event and reports `removed`; `DesktopDirectoryWatcher` then watches the
|
|
52
|
+
* nearest existing ancestor until the directory comes back.
|
|
53
|
+
*/
|
|
54
|
+
export const watchDesktopDirectory: DesktopDirectoryWatch = (dir, onChange) => {
|
|
55
|
+
let closed = false;
|
|
56
|
+
const close = () => {
|
|
57
|
+
if (closed) return;
|
|
58
|
+
closed = true;
|
|
59
|
+
try {
|
|
60
|
+
watcher.close();
|
|
61
|
+
} catch {
|
|
62
|
+
/* already closed */
|
|
63
|
+
}
|
|
64
|
+
};
|
|
65
|
+
const watcher = fsWatch(dir, { persistent: false }, (_event, filename) => {
|
|
66
|
+
if (closed) return;
|
|
67
|
+
if (!existsSync(dir)) {
|
|
68
|
+
close();
|
|
69
|
+
onChange(undefined, true);
|
|
70
|
+
return;
|
|
71
|
+
}
|
|
72
|
+
onChange(typeof filename === "string" && filename.length > 0 ? basename(filename) : undefined);
|
|
73
|
+
});
|
|
74
|
+
watcher.on("error", close);
|
|
75
|
+
return close;
|
|
76
|
+
};
|
|
77
|
+
|
|
78
|
+
export interface DesktopDebouncer {
|
|
79
|
+
/** (Re)starts the window; the callback runs once, `ms` after the last call. */
|
|
80
|
+
schedule(): void;
|
|
81
|
+
cancel(): void;
|
|
82
|
+
/** Whether a window is open, i.e. a change is waiting for its recompute. */
|
|
83
|
+
pending(): boolean;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
export function createDesktopDebouncer(timers: DesktopChangeTimers, ms: number, run: () => void): DesktopDebouncer {
|
|
87
|
+
let handle: unknown;
|
|
88
|
+
let pending = false;
|
|
89
|
+
const cancel = () => {
|
|
90
|
+
if (!pending) return;
|
|
91
|
+
pending = false;
|
|
92
|
+
try {
|
|
93
|
+
timers.clear(handle);
|
|
94
|
+
} catch {
|
|
95
|
+
/* timer already gone */
|
|
96
|
+
}
|
|
97
|
+
handle = undefined;
|
|
98
|
+
};
|
|
99
|
+
return {
|
|
100
|
+
schedule() {
|
|
101
|
+
cancel();
|
|
102
|
+
pending = true;
|
|
103
|
+
handle = timers.set(() => {
|
|
104
|
+
if (!pending) return;
|
|
105
|
+
pending = false;
|
|
106
|
+
handle = undefined;
|
|
107
|
+
try {
|
|
108
|
+
run();
|
|
109
|
+
} catch {
|
|
110
|
+
/* change detection never throws into a timer */
|
|
111
|
+
}
|
|
112
|
+
}, ms);
|
|
113
|
+
},
|
|
114
|
+
cancel,
|
|
115
|
+
pending: () => pending,
|
|
116
|
+
};
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
/** One owner directory and the entry names in it that belong to a store. */
|
|
120
|
+
export interface DesktopWatchTarget {
|
|
121
|
+
dir: string;
|
|
122
|
+
names: readonly string[];
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
export interface DesktopDirectoryWatcherOptions {
|
|
126
|
+
watch?: DesktopDirectoryWatch;
|
|
127
|
+
timers?: DesktopChangeTimers;
|
|
128
|
+
debounceMs?: number;
|
|
129
|
+
/** Directory existence check; injectable so tests can use abstract paths. */
|
|
130
|
+
exists?: (path: string) => boolean;
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
/**
|
|
134
|
+
* Watches the given owner directories and calls `onChange` once per debounce
|
|
135
|
+
* window after any relevant entry changed. Entries are filtered by name, so an
|
|
136
|
+
* unrelated file in a shared directory (a repository's `.pi/`) does not trigger
|
|
137
|
+
* a recompute; an event without a name is always relevant, because some
|
|
138
|
+
* platforms never report one.
|
|
139
|
+
*
|
|
140
|
+
* A target directory that does not exist yet (a project without `.pi/`, a fresh
|
|
141
|
+
* `<git common dir>/gentle-ai/`) is watched through its nearest existing
|
|
142
|
+
* ancestor, non-recursively, for the creation of the next path segment only.
|
|
143
|
+
* When that segment appears, the ancestor watcher is closed and the target is
|
|
144
|
+
* armed again one level closer, until the real directory is watched; each
|
|
145
|
+
* upgrade schedules one recompute, because the owner file may already have been
|
|
146
|
+
* written before the closer watcher existed. A watched directory that is later
|
|
147
|
+
* removed falls back to the same ancestor watching, so its recreation is seen.
|
|
148
|
+
*/
|
|
149
|
+
export class DesktopDirectoryWatcher {
|
|
150
|
+
private readonly watch: DesktopDirectoryWatch;
|
|
151
|
+
private readonly exists: (path: string) => boolean;
|
|
152
|
+
private readonly debouncer: DesktopDebouncer;
|
|
153
|
+
private readonly closers = new Set<() => void>();
|
|
154
|
+
private disposed = false;
|
|
155
|
+
|
|
156
|
+
constructor(onChange: () => void, options: DesktopDirectoryWatcherOptions = {}) {
|
|
157
|
+
this.watch = options.watch ?? watchDesktopDirectory;
|
|
158
|
+
this.exists = options.exists ?? existsSync;
|
|
159
|
+
this.debouncer = createDesktopDebouncer(
|
|
160
|
+
options.timers ?? realDesktopChangeTimers,
|
|
161
|
+
options.debounceMs ?? DESKTOP_CHANGE_DEBOUNCE_MS,
|
|
162
|
+
onChange,
|
|
163
|
+
);
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
/** Starts every watcher it can; answers how many watchers are open. */
|
|
167
|
+
start(targets: readonly DesktopWatchTarget[]): number {
|
|
168
|
+
if (this.disposed) return 0;
|
|
169
|
+
const byDir = new Map<string, Set<string>>();
|
|
170
|
+
for (const target of targets) {
|
|
171
|
+
const names = byDir.get(target.dir) ?? new Set<string>();
|
|
172
|
+
for (const name of target.names) names.add(name);
|
|
173
|
+
byDir.set(target.dir, names);
|
|
174
|
+
}
|
|
175
|
+
for (const [dir, names] of byDir) this.arm(dir, names);
|
|
176
|
+
return this.closers.size;
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
/** Whether a detected change is still waiting for its debounced recompute. */
|
|
180
|
+
hasPending(): boolean {
|
|
181
|
+
return !this.disposed && this.debouncer.pending();
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
dispose(): void {
|
|
185
|
+
this.disposed = true;
|
|
186
|
+
this.debouncer.cancel();
|
|
187
|
+
const closers = [...this.closers];
|
|
188
|
+
this.closers.clear();
|
|
189
|
+
for (const close of closers) safeClose(close);
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
private arm(dir: string, names: ReadonlySet<string>): void {
|
|
193
|
+
if (this.disposed) return;
|
|
194
|
+
let present: boolean;
|
|
195
|
+
try {
|
|
196
|
+
present = this.exists(dir);
|
|
197
|
+
} catch {
|
|
198
|
+
present = false;
|
|
199
|
+
}
|
|
200
|
+
if (present) {
|
|
201
|
+
const close = this.open(dir, (filename, removed) => {
|
|
202
|
+
if (removed) {
|
|
203
|
+
// The real watcher already closed itself; watch for the directory
|
|
204
|
+
// to come back, and recompute: its stores just changed.
|
|
205
|
+
if (close) this.release(close);
|
|
206
|
+
this.arm(dir, names);
|
|
207
|
+
this.debouncer.schedule();
|
|
208
|
+
return;
|
|
209
|
+
}
|
|
210
|
+
if (filename !== undefined && !names.has(filename)) return;
|
|
211
|
+
this.debouncer.schedule();
|
|
212
|
+
});
|
|
213
|
+
return;
|
|
214
|
+
}
|
|
215
|
+
const pending = this.nearestExisting(dir);
|
|
216
|
+
if (!pending) return;
|
|
217
|
+
let upgraded = false;
|
|
218
|
+
const close = this.open(pending.ancestor, (filename) => {
|
|
219
|
+
if (upgraded) return;
|
|
220
|
+
if (filename !== undefined && filename !== basename(pending.next)) return;
|
|
221
|
+
let created: boolean;
|
|
222
|
+
try {
|
|
223
|
+
created = this.exists(pending.next);
|
|
224
|
+
} catch {
|
|
225
|
+
created = false;
|
|
226
|
+
}
|
|
227
|
+
if (!created) return;
|
|
228
|
+
upgraded = true;
|
|
229
|
+
if (close) this.release(close);
|
|
230
|
+
this.arm(dir, names);
|
|
231
|
+
this.debouncer.schedule();
|
|
232
|
+
});
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
/** The closest existing ancestor of `dir` and the missing child below it. */
|
|
236
|
+
private nearestExisting(dir: string): { ancestor: string; next: string } | undefined {
|
|
237
|
+
let next = dir;
|
|
238
|
+
let ancestor = dirname(dir);
|
|
239
|
+
while (ancestor !== next) {
|
|
240
|
+
try {
|
|
241
|
+
if (this.exists(ancestor)) return { ancestor, next };
|
|
242
|
+
} catch {
|
|
243
|
+
return undefined;
|
|
244
|
+
}
|
|
245
|
+
next = ancestor;
|
|
246
|
+
ancestor = dirname(ancestor);
|
|
247
|
+
}
|
|
248
|
+
return undefined;
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
/** Opens one watcher, or none: a directory that cannot be watched is skipped. */
|
|
252
|
+
private open(
|
|
253
|
+
dir: string,
|
|
254
|
+
onEvent: (filename: string | undefined, removed?: boolean) => void,
|
|
255
|
+
): (() => void) | undefined {
|
|
256
|
+
try {
|
|
257
|
+
const close = this.watch(dir, (filename, removed) => {
|
|
258
|
+
if (this.disposed) return;
|
|
259
|
+
onEvent(filename, removed);
|
|
260
|
+
});
|
|
261
|
+
if (this.disposed) {
|
|
262
|
+
safeClose(close);
|
|
263
|
+
return undefined;
|
|
264
|
+
}
|
|
265
|
+
this.closers.add(close);
|
|
266
|
+
return close;
|
|
267
|
+
} catch {
|
|
268
|
+
/* best effort: this directory simply produces no external events */
|
|
269
|
+
return undefined;
|
|
270
|
+
}
|
|
271
|
+
}
|
|
272
|
+
|
|
273
|
+
private release(close: () => void): void {
|
|
274
|
+
this.closers.delete(close);
|
|
275
|
+
safeClose(close);
|
|
276
|
+
}
|
|
277
|
+
}
|
|
278
|
+
|
|
279
|
+
function safeClose(close: () => void): void {
|
|
280
|
+
try {
|
|
281
|
+
close();
|
|
282
|
+
} catch {
|
|
283
|
+
/* already closed */
|
|
284
|
+
}
|
|
285
|
+
}
|
|
@@ -10,7 +10,14 @@
|
|
|
10
10
|
// the owner's `writeProfilePinSync` / `clearProfilePinSync`, one explicitly named
|
|
11
11
|
// layer per request. `models`, `subagents`, and `managed_assets` are derived or
|
|
12
12
|
// installer-owned and answer a typed `read_only` error to every write. There is no
|
|
13
|
-
// second store
|
|
13
|
+
// second store and no cached copy.
|
|
14
|
+
//
|
|
15
|
+
// Changes made outside this channel are detected best effort: once wired for an
|
|
16
|
+
// interactive RPC host, the bridge watches the owner files' directories (see
|
|
17
|
+
// `configWatchTargets`), and after a debounced change recomputes every store's
|
|
18
|
+
// revision and emits `config_changed` with `source: "external"` only for a store
|
|
19
|
+
// whose revision differs from the last revision this channel reported. A
|
|
20
|
+
// Desktop write records its own resulting revision first, so it is never echoed.
|
|
14
21
|
//
|
|
15
22
|
// The write revision is the digest of the exact single file the owner rewrites,
|
|
16
23
|
// which is why `pins` reports one revision per layer instead of the merged read
|
|
@@ -21,6 +28,7 @@
|
|
|
21
28
|
// so a second `pi` process can still write between the check and the rename.
|
|
22
29
|
|
|
23
30
|
import { createHash } from "node:crypto";
|
|
31
|
+
import { basename, dirname } from "node:path";
|
|
24
32
|
import type { ExtensionContext } from "@earendil-works/pi-coding-agent";
|
|
25
33
|
import { managedAssetsManifestPath, readManagedAssetsManifestResult, type ManagedAssetsManifest } from "./agent-assets.ts";
|
|
26
34
|
import { gentlePiConfigHome, resolveGentlePiAgentHome } from "./agent-home.ts";
|
|
@@ -37,6 +45,7 @@ import {
|
|
|
37
45
|
import { evaluateProfilePin, clearProfilePinSync, readProfilePinStatus, writeProfilePinSync } from "./agent-profile-pin.ts";
|
|
38
46
|
import { parseAgentsConfig, readSubagentsFileResult, subagentsConfigPaths } from "./agents-config.ts";
|
|
39
47
|
import type { DesktopRpcOutcome, DesktopRpcState } from "./desktop-rpc.ts";
|
|
48
|
+
import { DesktopDirectoryWatcher, type DesktopDirectoryWatcherOptions, type DesktopWatchTarget } from "./desktop-rpc-config-watch.ts";
|
|
40
49
|
import { isDesktopProfileApplyRunning } from "./desktop-rpc-profiles.ts";
|
|
41
50
|
import { fallbacksFilePath, normalizeFallbacksFile, readFallbacksFile, writeFallbacksFile } from "./model-fallback-store.ts";
|
|
42
51
|
import { modelConfigPaths, normalizeModelConfig, readModelConfigFile, readSavedModelConfig } from "./model-routing-authority.ts";
|
|
@@ -117,6 +126,9 @@ const MISSING_REVISION = { code: "revision_conflict", message: "expectedRevision
|
|
|
117
126
|
const STALE_REVISION = { code: "revision_conflict", message: "Config changed since expectedRevision was read" } as const;
|
|
118
127
|
const WRITE_FAILED = { code: "write_failed", message: "Config store write failed" } as const;
|
|
119
128
|
|
|
129
|
+
/** Stores with a layer that the session cwd locates (project layers and pins). */
|
|
130
|
+
const CWD_DEPENDENT_STORES: readonly DesktopConfigStore[] = ["models", "subagents", "pins"];
|
|
131
|
+
|
|
120
132
|
/** Authoritative stores this slice may write; every other store is read-only. */
|
|
121
133
|
const AUTHORITATIVE_STORES: ReadonlySet<DesktopConfigStore> = new Set(["profiles", "profile_fallbacks", "pins"]);
|
|
122
134
|
|
|
@@ -387,6 +399,47 @@ export function readConfigStore(store: DesktopConfigStore, root: DesktopConfigRo
|
|
|
387
399
|
};
|
|
388
400
|
}
|
|
389
401
|
|
|
402
|
+
/** One store's revision as `get_snapshot` reports it, without its content. */
|
|
403
|
+
interface StoreRevision {
|
|
404
|
+
store: DesktopConfigStore;
|
|
405
|
+
scope: DesktopConfigScope;
|
|
406
|
+
status: DesktopConfigStatus;
|
|
407
|
+
revision: string;
|
|
408
|
+
}
|
|
409
|
+
|
|
410
|
+
function storeRevision(store: DesktopConfigStore, root: DesktopConfigRoots): StoreRevision {
|
|
411
|
+
const reader = STORE_READERS[store];
|
|
412
|
+
const read = reader.read(root);
|
|
413
|
+
return { store, scope: reader.scope, status: read.status, revision: configRevision(store, read.status, read.value) };
|
|
414
|
+
}
|
|
415
|
+
|
|
416
|
+
function watchTarget(path: string): DesktopWatchTarget {
|
|
417
|
+
return { dir: dirname(path), names: [basename(path)] };
|
|
418
|
+
}
|
|
419
|
+
|
|
420
|
+
/**
|
|
421
|
+
* The owner files every store reads, as directory + entry name, resolved by the
|
|
422
|
+
* same owner path helpers the readers use. Pin layers depend on the session cwd's
|
|
423
|
+
* worktree, so they are absent outside a resolvable worktree. Directories are
|
|
424
|
+
* watched, not files, because the owners replace files by atomic rename.
|
|
425
|
+
*/
|
|
426
|
+
export function configWatchTargets(root: DesktopConfigRoots): DesktopWatchTarget[] {
|
|
427
|
+
const models = modelConfigPaths(root.configHome, root.cwd);
|
|
428
|
+
const subagents = subagentsConfigPaths({ cwd: root.cwd, home: root.agentHome, agentHome: root.agentHome });
|
|
429
|
+
const targets = [
|
|
430
|
+
watchTarget(profilesFilePath(root.configHome)),
|
|
431
|
+
watchTarget(fallbacksFilePath(root.configHome)),
|
|
432
|
+
watchTarget(models.global),
|
|
433
|
+
watchTarget(models.project),
|
|
434
|
+
watchTarget(subagents.global),
|
|
435
|
+
watchTarget(subagents.project),
|
|
436
|
+
watchTarget(managedAssetsManifestPath(root.agentHome)),
|
|
437
|
+
];
|
|
438
|
+
const pins = readProfilePinStatus(root.cwd, root.resolveWorktree);
|
|
439
|
+
if (pins) targets.push(watchTarget(pins.localPath), watchTarget(pins.repoPath));
|
|
440
|
+
return targets;
|
|
441
|
+
}
|
|
442
|
+
|
|
390
443
|
function layerWriteInfo(
|
|
391
444
|
store: DesktopConfigStore,
|
|
392
445
|
target: DesktopConfigWriteTarget,
|
|
@@ -580,6 +633,8 @@ function parseStoreParam(params: Record<string, unknown>): DesktopConfigStore |
|
|
|
580
633
|
return params.store;
|
|
581
634
|
}
|
|
582
635
|
|
|
636
|
+
export type DesktopConfigEmit = (event: string, data: Record<string, unknown>) => void;
|
|
637
|
+
|
|
583
638
|
/**
|
|
584
639
|
* `get_config` and the bounded `set_config` writer, over the owner readers and
|
|
585
640
|
* the three owner writers.
|
|
@@ -591,17 +646,112 @@ function parseStoreParam(params: Record<string, unknown>): DesktopConfigStore |
|
|
|
591
646
|
export class DesktopConfigBridge {
|
|
592
647
|
private host: ExtensionContext | undefined;
|
|
593
648
|
private readonly overrides: DesktopConfigOverrides;
|
|
594
|
-
|
|
595
|
-
|
|
649
|
+
private readonly watchOptions: DesktopDirectoryWatcherOptions;
|
|
650
|
+
private emit: DesktopConfigEmit | undefined;
|
|
651
|
+
private watcher: DesktopDirectoryWatcher | undefined;
|
|
652
|
+
private watchedCwd: string | undefined;
|
|
653
|
+
/** The last revision this channel reported per store (read, snapshot, write, or event). */
|
|
654
|
+
private readonly reported = new Map<DesktopConfigStore, string>();
|
|
655
|
+
|
|
656
|
+
constructor(overrides: DesktopConfigOverrides = {}, watchOptions: DesktopDirectoryWatcherOptions = {}) {
|
|
596
657
|
this.overrides = overrides;
|
|
658
|
+
this.watchOptions = watchOptions;
|
|
597
659
|
}
|
|
598
660
|
|
|
599
661
|
attach(context: ExtensionContext): void {
|
|
600
662
|
this.host = context;
|
|
663
|
+
// Pin and project layers follow the session cwd: a moved cwd moves the
|
|
664
|
+
// owner files, so the watchers follow it, and the stores whose layers
|
|
665
|
+
// depend on the cwd are re-read now. One that reads differently from what
|
|
666
|
+
// this channel last reported is announced as external and re-baselined, so
|
|
667
|
+
// the next unrelated change does not carry a stale extra event. A change
|
|
668
|
+
// the old watchers detected but had not recomputed yet would be dropped
|
|
669
|
+
// with them, so a pending window flushes every store instead.
|
|
670
|
+
if (this.emit && this.watchedCwd !== undefined && context.cwd !== this.watchedCwd) {
|
|
671
|
+
const pending = this.watcher?.hasPending() ?? false;
|
|
672
|
+
this.watch();
|
|
673
|
+
this.report(pending ? DESKTOP_CONFIG_STORES : CWD_DEPENDENT_STORES);
|
|
674
|
+
}
|
|
601
675
|
}
|
|
602
676
|
|
|
677
|
+
/** Session start/shutdown: watchers, baselines, and the emitter belong to one session. */
|
|
603
678
|
reset(): void {
|
|
604
679
|
this.host = undefined;
|
|
680
|
+
this.emit = undefined;
|
|
681
|
+
this.unwatch();
|
|
682
|
+
this.reported.clear();
|
|
683
|
+
}
|
|
684
|
+
|
|
685
|
+
/**
|
|
686
|
+
* Interactive RPC hosts only: turn external store changes into ordered
|
|
687
|
+
* `config_changed` events. The current revisions become the baseline, so
|
|
688
|
+
* wiring never emits by itself.
|
|
689
|
+
*/
|
|
690
|
+
wire(emit: DesktopConfigEmit): void {
|
|
691
|
+
this.emit = emit;
|
|
692
|
+
this.watch();
|
|
693
|
+
}
|
|
694
|
+
|
|
695
|
+
private unwatch(): void {
|
|
696
|
+
const watcher = this.watcher;
|
|
697
|
+
this.watcher = undefined;
|
|
698
|
+
this.watchedCwd = undefined;
|
|
699
|
+
watcher?.dispose();
|
|
700
|
+
}
|
|
701
|
+
|
|
702
|
+
private watch(): void {
|
|
703
|
+
this.unwatch();
|
|
704
|
+
const host = this.host;
|
|
705
|
+
if (!host || !this.emit) return;
|
|
706
|
+
try {
|
|
707
|
+
const root = withRoots(host, this.overrides);
|
|
708
|
+
if (!root) return;
|
|
709
|
+
for (const store of DESKTOP_CONFIG_STORES) {
|
|
710
|
+
if (!this.reported.has(store)) this.reported.set(store, storeRevision(store, root).revision);
|
|
711
|
+
}
|
|
712
|
+
const watcher = new DesktopDirectoryWatcher(() => this.recompute(watcher), this.watchOptions);
|
|
713
|
+
this.watcher = watcher;
|
|
714
|
+
this.watchedCwd = root.cwd;
|
|
715
|
+
watcher.start(configWatchTargets(root));
|
|
716
|
+
} catch {
|
|
717
|
+
/* best effort: the channel keeps working without external events */
|
|
718
|
+
}
|
|
719
|
+
}
|
|
720
|
+
|
|
721
|
+
/** Debounced: recompute every revision and report only real, unreported changes. */
|
|
722
|
+
private recompute(watcher: DesktopDirectoryWatcher): void {
|
|
723
|
+
if (watcher !== this.watcher) return;
|
|
724
|
+
this.report(DESKTOP_CONFIG_STORES);
|
|
725
|
+
}
|
|
726
|
+
|
|
727
|
+
/** Emits an external `config_changed` for each given store whose revision moved. */
|
|
728
|
+
private report(stores: readonly DesktopConfigStore[]): void {
|
|
729
|
+
const host = this.host;
|
|
730
|
+
const emit = this.emit;
|
|
731
|
+
if (!host || !emit) return;
|
|
732
|
+
const root = withRoots(host, this.overrides);
|
|
733
|
+
if (!root) return;
|
|
734
|
+
for (const store of stores) {
|
|
735
|
+
let current: StoreRevision;
|
|
736
|
+
try {
|
|
737
|
+
current = storeRevision(store, root);
|
|
738
|
+
} catch {
|
|
739
|
+
continue;
|
|
740
|
+
}
|
|
741
|
+
if (this.reported.get(store) === current.revision) continue;
|
|
742
|
+
this.reported.set(store, current.revision);
|
|
743
|
+
try {
|
|
744
|
+
emit(DESKTOP_CONFIG_EVENT, {
|
|
745
|
+
store: current.store,
|
|
746
|
+
scope: current.scope,
|
|
747
|
+
revision: current.revision,
|
|
748
|
+
status: current.status,
|
|
749
|
+
source: "external",
|
|
750
|
+
});
|
|
751
|
+
} catch {
|
|
752
|
+
/* a closed transport never throws back into a watcher */
|
|
753
|
+
}
|
|
754
|
+
}
|
|
605
755
|
}
|
|
606
756
|
|
|
607
757
|
handle(method: string, params: Record<string, unknown>): DesktopRpcOutcome | undefined {
|
|
@@ -619,6 +769,7 @@ export class DesktopConfigBridge {
|
|
|
619
769
|
const root = withRoots(host, this.overrides);
|
|
620
770
|
if (!root) return { ok: false, error: UNAVAILABLE };
|
|
621
771
|
const data = readConfigStore(parsed, root);
|
|
772
|
+
this.reported.set(parsed, data.revision);
|
|
622
773
|
return { ok: true, data: data as unknown as Record<string, unknown> };
|
|
623
774
|
}
|
|
624
775
|
|
|
@@ -683,6 +834,9 @@ export class DesktopConfigBridge {
|
|
|
683
834
|
// not an echo of the request. The resulting write revision also decides
|
|
684
835
|
// whether this request really changed anything.
|
|
685
836
|
const after = readConfigStore(store, root);
|
|
837
|
+
// Recorded before the response leaves, so the watcher waking on the owner's
|
|
838
|
+
// own rename recomputes this revision and stays silent.
|
|
839
|
+
this.reported.set(store, after.revision);
|
|
686
840
|
const writeRevision = after.writeTargets?.find((entry) => entry.target === plan.target)?.writeRevision;
|
|
687
841
|
const changed = writeRevision !== plan.writeRevision;
|
|
688
842
|
const data = { ...after, writeTarget: plan.target, writeRevision, changed } as Record<string, unknown>;
|
|
@@ -715,14 +869,14 @@ export class DesktopConfigBridge {
|
|
|
715
869
|
return {
|
|
716
870
|
config: {
|
|
717
871
|
stores: DESKTOP_CONFIG_STORES.map((store) => {
|
|
718
|
-
const
|
|
719
|
-
|
|
872
|
+
const current = storeRevision(store, root);
|
|
873
|
+
this.reported.set(store, current.revision);
|
|
720
874
|
return {
|
|
721
875
|
store,
|
|
722
|
-
scope:
|
|
876
|
+
scope: current.scope,
|
|
723
877
|
readOnly: storeReadOnly(store),
|
|
724
|
-
status:
|
|
725
|
-
revision:
|
|
878
|
+
status: current.status,
|
|
879
|
+
revision: current.revision,
|
|
726
880
|
};
|
|
727
881
|
}),
|
|
728
882
|
},
|