gentle-pi 4.7.0 → 4.9.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +115 -44
- package/assets/agents/gentle-ai-explore.md +3 -3
- package/assets/agents/gentle-ai-verify.md +20 -6
- package/assets/agents/gentle-ai-worker.md +14 -13
- package/assets/agents/jd-judge-a.md +1 -3
- package/assets/agents/jd-judge-b.md +1 -3
- package/assets/agents/review-readability.md +1 -5
- package/assets/agents/review-reliability.md +1 -5
- package/assets/agents/review-resilience.md +1 -5
- package/assets/agents/review-risk.md +1 -5
- package/assets/design-canvas/canvas-api.js +45 -0
- package/assets/design-canvas/canvas-boards.js +476 -0
- package/assets/design-canvas/canvas-boot.js +219 -0
- package/assets/design-canvas/canvas-checks.js +491 -0
- package/assets/design-canvas/canvas-comments.js +315 -0
- package/assets/design-canvas/canvas-compare.js +159 -0
- package/assets/design-canvas/canvas-events.js +75 -0
- package/assets/design-canvas/canvas-export.js +393 -0
- package/assets/design-canvas/canvas-focus.js +203 -0
- package/assets/design-canvas/canvas-handoffs.js +150 -0
- package/assets/design-canvas/canvas-i18n-es.js +397 -0
- package/assets/design-canvas/canvas-i18n.js +108 -0
- package/assets/design-canvas/canvas-layout.js +526 -0
- package/assets/design-canvas/canvas-menu.js +219 -0
- package/assets/design-canvas/canvas-messages.js +86 -0
- package/assets/design-canvas/canvas-minimap.js +163 -0
- package/assets/design-canvas/canvas-parts.js +401 -0
- package/assets/design-canvas/canvas-popover.js +234 -0
- package/assets/design-canvas/canvas-rail.js +351 -0
- package/assets/design-canvas/canvas-sizes.js +524 -0
- package/assets/design-canvas/canvas-store.js +167 -0
- package/assets/design-canvas/canvas-theme.js +69 -0
- package/assets/design-canvas/canvas-tokens.js +674 -0
- package/assets/design-canvas/canvas-ui.js +24 -0
- package/assets/design-canvas/canvas-view.js +184 -0
- package/assets/design-canvas/canvas.css +773 -17
- package/assets/design-canvas/canvas.js +2 -1506
- package/assets/design-canvas/index.html +120 -36
- package/assets/design-canvas/inspector.js +574 -21
- package/assets/design-canvas/theme-early.js +10 -0
- package/assets/install-wizard/wizard.js +5 -1
- package/assets/migrations/agent-body-history.json +30 -0
- package/assets/orchestrator-delegation-reference.md +8 -14
- package/assets/orchestrator-delegation.md +5 -9
- package/assets/orchestrator-full-delegation-card.md +11 -16
- package/assets/orchestrator-full-delegation.md +9 -9
- package/assets/orchestrator-memory.md +4 -4
- package/assets/orchestrator-prompts.md +3 -31
- package/assets/orchestrator-quota-recovery.md +5 -0
- package/assets/orchestrator-skills.md +13 -12
- package/assets/orchestrator-tracking.md +13 -17
- package/assets/orchestrator-verification.md +12 -10
- package/assets/orchestrator-writer.md +13 -13
- package/assets/orchestrator.md +20 -24
- package/bin/gentle-shell.mjs +205 -10
- package/contracts/review-provider-contract-mirror/provider-contract.lock.json +8 -9
- package/contracts/review-provider-contract-mirror/{v1.4.0 → v1.6.0}/bundle/manifest.json +3 -3
- package/contracts/review-provider-contract-mirror/{v1.4.0 → v1.6.0}/bundle/orchestration/pi.md +2 -1
- package/contracts/review-provider-contract-mirror/{v1.4.0 → v1.6.0}/bundle/routing/pi.md +16 -16
- package/contracts/review-provider-contract-mirror/{v1.4.0 → v1.6.0}/generated/provider-capabilities.baseline.json +3 -3
- package/contracts/review-provider-contract-mirror/{v1.4.0 → v1.6.0}/generated/provider-roles.baseline.json +1 -1
- package/docs/assets/brand/sponsor-banner.svg +60 -0
- package/docs/assets/features/gentle-tower.png +0 -0
- package/docs/auto-permission-answers.md +1 -1
- package/docs/bundled-install.md +14 -6
- package/docs/delegated-verification.md +23 -5
- package/docs/desktop-feed.md +303 -0
- package/docs/desktop-rpc.md +1931 -0
- package/docs/fast-mode.md +2 -2
- package/docs/gentle-agents-activity.md +26 -0
- package/docs/gentle-shell-desktop.md +465 -0
- package/docs/gentle-shell.md +102 -17
- package/docs/images/desktop/chat.png +0 -0
- package/docs/images/desktop/palette.png +0 -0
- package/docs/images/desktop/todo.png +0 -0
- package/docs/install-wizard.md +30 -21
- package/docs/odd-preparation-continuity.md +24 -0
- package/docs/permission-modes.md +9 -1
- package/docs/prompt-budget.md +12 -0
- package/docs/rdd-odd-friction-triage-2026-11-07.md +57 -0
- package/docs/readme-reference.md +113 -32
- package/docs/review-coordinator.md +29 -9
- package/docs/review-delivery-preflight.md +22 -0
- package/docs/work-continuity.md +19 -6
- package/extensions/ask-user-choice.ts +36 -18
- package/extensions/ask-user-question.ts +48 -9
- package/extensions/child-context.ts +21 -7
- package/extensions/gentle-agents.ts +436 -66
- package/extensions/gentle-ai.ts +809 -158
- package/extensions/gentle-design.ts +69 -3
- package/extensions/gentle-desktop-feed.ts +778 -0
- package/extensions/gentle-desktop-rpc.ts +276 -0
- package/extensions/gentle-guide.ts +3 -0
- package/extensions/gentle-herdr-desktop-status.ts +275 -0
- package/extensions/gentle-shell.ts +174 -59
- package/extensions/gentle-stats.ts +30 -1
- package/extensions/gentle-todo.ts +48 -25
- package/extensions/gentle-tower.ts +305 -0
- package/extensions/skill-registry.ts +260 -225
- package/herdr/RECIPE.md +157 -0
- package/herdr/keys.json +14 -0
- package/herdr/layouts/gentle-shell.json +202 -0
- package/herdr/mods/gentle-agents/icons/kind-herdr.svg +1 -0
- package/herdr/mods/gentle-agents/icons/kind-remote.svg +1 -0
- package/herdr/mods/gentle-agents/icons/kind-tui.svg +1 -0
- package/herdr/mods/gentle-agents/main.js +190 -0
- package/herdr/mods/gentle-agents/mod.json +1 -0
- package/herdr/mods/gentle-agents/snapshot.js +469 -0
- package/herdr/mods/gentle-agents/tokens.js +273 -0
- package/herdr/mods/gentle-chat/MINIMAL.md +69 -0
- package/herdr/mods/gentle-chat/actions.js +180 -0
- package/herdr/mods/gentle-chat/feed.js +321 -0
- package/herdr/mods/gentle-chat/icons/branch.svg +1 -0
- package/herdr/mods/gentle-chat/icons/chat.svg +1 -0
- package/herdr/mods/gentle-chat/icons/check.svg +1 -0
- package/herdr/mods/gentle-chat/icons/chev.svg +1 -0
- package/herdr/mods/gentle-chat/icons/clip.svg +1 -0
- package/herdr/mods/gentle-chat/icons/down.svg +1 -0
- package/herdr/mods/gentle-chat/icons/folder.svg +1 -0
- package/herdr/mods/gentle-chat/icons/kind-herdr.svg +1 -0
- package/herdr/mods/gentle-chat/icons/kind-remote.svg +1 -0
- package/herdr/mods/gentle-chat/icons/kind-tui.svg +1 -0
- package/herdr/mods/gentle-chat/icons/mark.svg +1 -0
- package/herdr/mods/gentle-chat/icons/send.svg +1 -0
- package/herdr/mods/gentle-chat/icons/shield.svg +1 -0
- package/herdr/mods/gentle-chat/icons/stop.svg +1 -0
- package/herdr/mods/gentle-chat/icons/term.svg +1 -0
- package/herdr/mods/gentle-chat/icons/user.svg +1 -0
- package/herdr/mods/gentle-chat/icons/x.svg +1 -0
- package/herdr/mods/gentle-chat/main.js +968 -0
- package/herdr/mods/gentle-chat/mod.json +1 -0
- package/herdr/mods/gentle-chat/session.js +212 -0
- package/herdr/mods/gentle-chat/snapshot.js +469 -0
- package/herdr/mods/gentle-chat/tokens.js +137 -0
- package/herdr/mods/gentle-chat/ui.js +883 -0
- package/herdr/mods/gentle-confirm/main.js +60 -0
- package/herdr/mods/gentle-confirm/mod.json +1 -0
- package/herdr/mods/gentle-inspector/actions.js +180 -0
- package/herdr/mods/gentle-inspector/icons/bolt.svg +1 -0
- package/herdr/mods/gentle-inspector/icons/bot.svg +1 -0
- package/herdr/mods/gentle-inspector/icons/check.svg +1 -0
- package/herdr/mods/gentle-inspector/icons/db.svg +1 -0
- package/herdr/mods/gentle-inspector/icons/diff.svg +1 -0
- package/herdr/mods/gentle-inspector/icons/jobs.svg +1 -0
- package/herdr/mods/gentle-inspector/icons/plug.svg +1 -0
- package/herdr/mods/gentle-inspector/icons/review.svg +1 -0
- package/herdr/mods/gentle-inspector/icons/stats.svg +1 -0
- package/herdr/mods/gentle-inspector/icons/stop.svg +1 -0
- package/herdr/mods/gentle-inspector/icons/todo.svg +1 -0
- package/herdr/mods/gentle-inspector/main.js +500 -0
- package/herdr/mods/gentle-inspector/mod.json +1 -0
- package/herdr/mods/gentle-inspector/snapshot.js +469 -0
- package/herdr/mods/gentle-inspector/tokens.js +273 -0
- package/herdr/mods/gentle-palette/actions.js +180 -0
- package/herdr/mods/gentle-palette/icons/bolt.svg +1 -0
- package/herdr/mods/gentle-palette/icons/bot.svg +1 -0
- package/herdr/mods/gentle-palette/icons/chat.svg +1 -0
- package/herdr/mods/gentle-palette/icons/check.svg +1 -0
- package/herdr/mods/gentle-palette/icons/cmd.svg +1 -0
- package/herdr/mods/gentle-palette/icons/diff.svg +1 -0
- package/herdr/mods/gentle-palette/icons/jobs.svg +1 -0
- package/herdr/mods/gentle-palette/icons/plus.svg +1 -0
- package/herdr/mods/gentle-palette/icons/review.svg +1 -0
- package/herdr/mods/gentle-palette/icons/search.svg +1 -0
- package/herdr/mods/gentle-palette/icons/shield.svg +1 -0
- package/herdr/mods/gentle-palette/icons/stats.svg +1 -0
- package/herdr/mods/gentle-palette/icons/stop.svg +1 -0
- package/herdr/mods/gentle-palette/icons/term.svg +1 -0
- package/herdr/mods/gentle-palette/icons/todo.svg +1 -0
- package/herdr/mods/gentle-palette/main.js +333 -0
- package/herdr/mods/gentle-palette/mod.json +1 -0
- package/herdr/mods/gentle-palette/snapshot.js +469 -0
- package/herdr/mods/gentle-palette/tokens.js +273 -0
- package/herdr/mods/gentle-pane/icons/chat.svg +1 -0
- package/herdr/mods/gentle-pane/icons/close.svg +1 -0
- package/herdr/mods/gentle-pane/icons/kind-herdr.svg +1 -0
- package/herdr/mods/gentle-pane/icons/kind-remote.svg +1 -0
- package/herdr/mods/gentle-pane/icons/kind-tui.svg +1 -0
- package/herdr/mods/gentle-pane/icons/split-down.svg +1 -0
- package/herdr/mods/gentle-pane/icons/split-right.svg +1 -0
- package/herdr/mods/gentle-pane/icons/term.svg +1 -0
- package/herdr/mods/gentle-pane/icons/unzoom.svg +1 -0
- package/herdr/mods/gentle-pane/icons/zoom.svg +1 -0
- package/herdr/mods/gentle-pane/main.js +91 -0
- package/herdr/mods/gentle-pane/mod.json +1 -0
- package/herdr/mods/gentle-pane/snapshot.js +469 -0
- package/herdr/mods/gentle-pane/tokens.js +273 -0
- package/herdr/mods/gentle-sidebar/actions.js +180 -0
- package/herdr/mods/gentle-sidebar/icons/gear.svg +1 -0
- package/herdr/mods/gentle-sidebar/icons/mark.svg +1 -0
- package/herdr/mods/gentle-sidebar/icons/refresh.svg +1 -0
- package/herdr/mods/gentle-sidebar/icons/server-plus.svg +1 -0
- package/herdr/mods/gentle-sidebar/main.js +171 -0
- package/herdr/mods/gentle-sidebar/mod.json +1 -0
- package/herdr/mods/gentle-sidebar/snapshot.js +469 -0
- package/herdr/mods/gentle-sidebar/tokens.js +273 -0
- package/herdr/mods/gentle-spaces/icons/kind-herdr.svg +1 -0
- package/herdr/mods/gentle-spaces/icons/kind-remote.svg +1 -0
- package/herdr/mods/gentle-spaces/icons/kind-tui.svg +1 -0
- package/herdr/mods/gentle-spaces/icons/monitor.svg +1 -0
- package/herdr/mods/gentle-spaces/icons/plus.svg +1 -0
- package/herdr/mods/gentle-spaces/icons/server.svg +1 -0
- package/herdr/mods/gentle-spaces/machines.js +31 -0
- package/herdr/mods/gentle-spaces/main.js +299 -0
- package/herdr/mods/gentle-spaces/mod.json +1 -0
- package/herdr/mods/gentle-spaces/snapshot.js +469 -0
- package/herdr/mods/gentle-spaces/tokens.js +273 -0
- package/herdr/mods/gentle-status/actions.js +180 -0
- package/herdr/mods/gentle-status/main.js +192 -0
- package/herdr/mods/gentle-status/mod.json +1 -0
- package/herdr/mods/gentle-status/snapshot.js +469 -0
- package/herdr/mods/gentle-status/tokens.js +273 -0
- package/herdr/mods/gentle-tabs/icons/close.svg +1 -0
- package/herdr/mods/gentle-tabs/icons/kind-herdr.svg +1 -0
- package/herdr/mods/gentle-tabs/icons/kind-remote.svg +1 -0
- package/herdr/mods/gentle-tabs/icons/kind-tui.svg +1 -0
- package/herdr/mods/gentle-tabs/icons/plus.svg +1 -0
- package/herdr/mods/gentle-tabs/icons/win-close.svg +1 -0
- package/herdr/mods/gentle-tabs/icons/win-max.svg +1 -0
- package/herdr/mods/gentle-tabs/icons/win-min.svg +1 -0
- package/herdr/mods/gentle-tabs/icons/win-restore.svg +1 -0
- package/herdr/mods/gentle-tabs/main.js +171 -0
- package/herdr/mods/gentle-tabs/mod.json +1 -0
- package/herdr/mods/gentle-tabs/snapshot.js +469 -0
- package/herdr/mods/gentle-tabs/tokens.js +273 -0
- package/herdr/mods/gentle-tokens/main.js +20 -0
- package/herdr/mods/gentle-tokens/mod.json +1 -0
- package/herdr/mods/gentle-tokens/snapshot.js +469 -0
- package/herdr/mods/gentle-tokens/tokens.js +273 -0
- package/herdr/preview.png +0 -0
- package/herdr/themes/gentle-shell-dark.json +33 -0
- package/herdr/themes/gentle-shell-light.json +34 -0
- package/lib/agent-assets.ts +30 -6
- package/lib/agent-tool-overlay.ts +117 -0
- package/lib/agents-config.ts +47 -6
- package/lib/agents-message-delivery.ts +17 -0
- package/lib/agents-messaging.ts +8 -2
- package/lib/agents-protocol.ts +17 -0
- package/lib/agents-report-cap.ts +115 -0
- package/lib/agents-rpc-publisher.ts +39 -12
- package/lib/agents-runner.ts +92 -6
- package/lib/agents-session-transport.ts +17 -1
- package/lib/auto-permission-answers.ts +2 -1
- package/lib/background-jobs-tools.ts +9 -4
- package/lib/background-jobs.ts +22 -2
- package/lib/bounded-writer-admission.ts +184 -31
- package/lib/change-diff.ts +104 -0
- package/lib/child-context-files.ts +21 -6
- package/lib/codemode-renderer.ts +1 -0
- package/lib/commit-slice-signal.ts +1 -1
- package/lib/delivery-conflict-markers.ts +349 -0
- package/lib/design-canvas-assets.ts +38 -0
- package/lib/design-canvas-server.ts +241 -23
- package/lib/design-comments.ts +94 -4
- package/lib/design-handoffs.ts +2 -1
- package/lib/design-layout.ts +125 -0
- package/lib/design-parts.ts +281 -0
- package/lib/design-system-tokens.ts +111 -0
- package/lib/desktop-agents-service.ts +315 -0
- package/lib/desktop-changes-service.ts +171 -0
- package/lib/desktop-design-service.ts +233 -0
- package/lib/desktop-feed-actions.ts +804 -0
- package/lib/desktop-feed-answers.ts +129 -0
- package/lib/desktop-feed-sources.ts +184 -0
- package/lib/desktop-feed-stats.ts +98 -0
- package/lib/desktop-feed-store.ts +124 -0
- package/lib/desktop-feed.ts +788 -0
- package/lib/desktop-jobs-service.ts +290 -0
- package/lib/desktop-review-service.ts +187 -0
- package/lib/desktop-rpc-agents.ts +403 -0
- package/lib/desktop-rpc-changes.ts +223 -0
- package/lib/desktop-rpc-config-watch.ts +285 -0
- package/lib/desktop-rpc-config.ts +885 -0
- package/lib/desktop-rpc-design.ts +138 -0
- package/lib/desktop-rpc-jobs.ts +290 -0
- package/lib/desktop-rpc-permissions.ts +328 -0
- package/lib/desktop-rpc-profiles.ts +196 -0
- package/lib/desktop-rpc-review.ts +180 -0
- package/lib/desktop-rpc-session.ts +203 -0
- package/lib/desktop-rpc-sessions.ts +250 -0
- package/lib/desktop-rpc-stats.ts +187 -0
- package/lib/desktop-rpc-updates.ts +143 -0
- package/lib/desktop-rpc-usage.ts +229 -0
- package/lib/desktop-rpc.ts +336 -0
- package/lib/desktop-session-service.ts +223 -0
- package/lib/desktop-sessions-service.ts +249 -0
- package/lib/desktop-stats-service.ts +142 -0
- package/lib/desktop-updates-service.ts +268 -0
- package/lib/desktop-usage-service.ts +310 -0
- package/lib/destructive-command-guard.ts +188 -13
- package/lib/gentle-ai-renderer.ts +13 -1
- package/lib/gentle-design.ts +201 -14
- package/lib/gentle-shell-bundled.ts +100 -9
- package/lib/gentle-shell-desktop.ts +1370 -0
- package/lib/gentle-shell-launcher.ts +45 -3
- package/lib/herdr-desktop-events.ts +40 -0
- package/lib/herdr-desktop-status.ts +229 -0
- package/lib/hidden-tools.ts +35 -0
- package/lib/inprocess-reviewer.ts +96 -12
- package/lib/jobs-sidebar-state.ts +5 -0
- package/lib/model-fallback-policy.ts +9 -0
- package/lib/model-routing-authority.ts +9 -0
- package/lib/nan-provider.ts +42 -28
- package/lib/native-review-cli.ts +86 -4
- package/lib/openai-fast-tier.ts +1 -0
- package/lib/orchestrator-discovery.ts +39 -2
- package/lib/reply-language-anchor.ts +27 -2
- package/lib/request-context-placement.ts +53 -0
- package/lib/review-candidate-view.ts +11 -1
- package/lib/review-continuation-registry.ts +17 -0
- package/lib/review-coordinator.ts +252 -8
- package/lib/review-delivery-preflight.ts +85 -0
- package/lib/review-host-relay.ts +5 -1
- package/lib/review-integration-v2.ts +56 -3
- package/lib/reviewer-stream.ts +87 -0
- package/lib/session-profile-freeze.ts +13 -5
- package/lib/shell-prompt.ts +16 -3
- package/lib/shell-usage.ts +10 -0
- package/lib/stats-collector.ts +56 -27
- package/lib/tower-actions.ts +100 -0
- package/lib/tower-hub.ts +73 -0
- package/lib/tower-launch.ts +111 -0
- package/lib/tower-open.ts +99 -0
- package/lib/tower-presence.ts +70 -0
- package/lib/tower-server.ts +234 -0
- package/lib/tower-snapshot.ts +298 -0
- package/lib/update-status.ts +238 -0
- package/lib/verifier-settle-reminder.ts +1 -1
- package/lib/vim-editor-adapter.ts +9 -2
- package/lib/writer-batch-admission.ts +55 -0
- package/lib/yolo-session-policy.ts +6 -1
- package/package.json +14 -5
- package/prompts/skill-creation.md +1 -10
- package/runtime/design-canvas-assets.mjs +39 -0
- package/runtime/gentle-shell-bundled.mjs +100 -9
- package/runtime/gentle-shell-desktop.mjs +1371 -0
- package/runtime/gentle-shell-launcher.mjs +44 -2
- package/runtime/native-review-cli.mjs +86 -4
- package/runtime/review-integration-v2.mjs +56 -3
- package/runtime/tower-actions.mjs +101 -0
- package/runtime/tower-hub.mjs +74 -0
- package/runtime/tower-launch.mjs +112 -0
- package/runtime/tower-open.mjs +100 -0
- package/runtime/tower-presence.mjs +71 -0
- package/runtime/tower-server.mjs +234 -0
- package/runtime/tower-snapshot.mjs +299 -0
- package/scripts/bootstrap.cmd +2 -2
- package/scripts/bootstrap.sh +41 -4
- package/scripts/build-full-delegation-card.mjs +5 -21
- package/scripts/build-runtime-modules.mjs +10 -0
- package/scripts/gentle-ai-installer.mjs +10 -10
- package/scripts/gentle-ai-proxy.mjs +1 -1
- package/scripts/installer-downloads.mjs +34 -8
- package/scripts/installer-preflight.mjs +28 -17
- package/scripts/installer-probes.mjs +25 -5
- package/scripts/installer-server.mjs +38 -9
- package/scripts/installer-windows.mjs +2 -2
- package/scripts/pi-update.mjs +166 -27
- package/scripts/prepare-verifier.mjs +107 -0
- package/scripts/update-agent-body-history.mjs +55 -8
- package/scripts/verify-package-files.mjs +61 -20
- package/skills/branch-pr/SKILL.md +16 -16
- package/skills/comment-writer/SKILL.md +1 -1
- package/skills/design/SKILL.md +6 -6
- package/skills/gentle-ai/SKILL.md +5 -5
- package/skills/judgment-day/SKILL.md +2 -2
- package/skills/judgment-day/references/prompts-and-formats.md +1 -1
- package/skills/provider-defect-report/SKILL.md +61 -0
- package/skills/rdd-defect-workflow/SKILL.md +6 -6
- package/skills/skill-improver/SKILL.md +2 -2
- package/skills/skill-registry/SKILL.md +11 -13
- package/skills/tui-design/SKILL.md +1 -1
- package/skills/work-unit-commits/SKILL.md +5 -5
- package/tests/agent-prompt-diet-contract.test.ts +101 -0
- package/tests/agent-tool-overlay-acceptance.test.ts +158 -0
- package/tests/agent-tool-overlay.test.ts +89 -0
- package/tests/agents-config.test.ts +10 -1
- package/tests/agents-message-delivery.test.ts +36 -0
- package/tests/agents-queries.test.ts +144 -4
- package/tests/agents-report-cap.test.ts +126 -0
- package/tests/agents-runner.test.ts +37 -1
- package/tests/agents-session-transport.test.ts +34 -0
- package/tests/always-on-prompt-verdicts-contract.test.ts +188 -0
- package/tests/append-system-prompt-route.test.ts +26 -7
- package/tests/approved-text-leftovers-contract.test.ts +136 -0
- package/tests/artifact-language.test.ts +1 -1
- package/tests/ask-user-choice.test.ts +78 -21
- package/tests/ask-user-question.test.ts +61 -6
- package/tests/audit-leftovers-contract.test.ts +51 -0
- package/tests/auto-permission-answers.test.ts +12 -1
- package/tests/background-jobs.test.ts +12 -0
- package/tests/bounded-stop-contract.test.ts +148 -27
- package/tests/branch-pr-skill.test.ts +10 -1
- package/tests/bundled-install.test.ts +1 -1
- package/tests/change-diff.test.ts +75 -0
- package/tests/child-context-files.test.ts +64 -8
- package/tests/child-skills-catalog.test.ts +56 -0
- package/tests/codemode-rendering.test.ts +4 -1
- package/tests/commit-slice-signal.test.ts +3 -2
- package/tests/decision-routing-contract.test.ts +390 -0
- package/tests/delegate-for-reason-contract.test.ts +30 -8
- package/tests/delegated-key-learnings-contract.test.ts +21 -28
- package/tests/delivery-b-rendered-surfaces.test.ts +32 -0
- package/tests/delivery-conflict-markers.test.ts +348 -0
- package/tests/design-canvas-all-sizes.test.ts +631 -0
- package/tests/design-canvas-allowlist.test.ts +32 -0
- package/tests/design-canvas-assets.test.ts +11 -878
- package/tests/design-canvas-boards.test.ts +77 -0
- package/tests/design-canvas-checks.test.ts +655 -0
- package/tests/design-canvas-compare.test.ts +79 -0
- package/tests/design-canvas-events.test.ts +59 -0
- package/tests/design-canvas-export.test.ts +1168 -0
- package/tests/design-canvas-focus.test.ts +113 -0
- package/tests/design-canvas-handoffs.test.ts +59 -0
- package/tests/design-canvas-i18n-review.test.ts +513 -0
- package/tests/design-canvas-i18n-views.test.ts +259 -0
- package/tests/design-canvas-i18n.test.ts +528 -0
- package/tests/design-canvas-inspector.test.ts +1004 -0
- package/tests/design-canvas-layout.test.ts +1222 -0
- package/tests/design-canvas-minimap.test.ts +413 -0
- package/tests/design-canvas-modules.test.ts +91 -0
- package/tests/design-canvas-parts.test.ts +721 -0
- package/tests/design-canvas-rail.test.ts +799 -0
- package/tests/design-canvas-server.test.ts +855 -17
- package/tests/design-canvas-sizes.test.ts +548 -0
- package/tests/design-canvas-store.test.ts +189 -0
- package/tests/design-canvas-theme.test.ts +198 -0
- package/tests/design-canvas-tokens.test.ts +965 -0
- package/tests/design-canvas-view.test.ts +299 -0
- package/tests/design-comments.test.ts +201 -1
- package/tests/design-handoffs.test.ts +20 -0
- package/tests/design-layout.test.ts +100 -0
- package/tests/design-parts.test.ts +260 -0
- package/tests/design-system-tokens.test.ts +215 -0
- package/tests/desktop-feed-actions-guards.test.ts +595 -0
- package/tests/desktop-feed-actions.test.ts +761 -0
- package/tests/desktop-feed-live-work.test.ts +209 -0
- package/tests/desktop-feed-performance.test.ts +369 -0
- package/tests/desktop-feed-plan-profiles.test.ts +509 -0
- package/tests/desktop-feed-send-prompt.test.ts +303 -0
- package/tests/desktop-feed-tool-summaries.test.ts +69 -0
- package/tests/desktop-feed.test.ts +615 -0
- package/tests/desktop-rpc-agents.test.ts +1319 -0
- package/tests/desktop-rpc-changes.test.ts +608 -0
- package/tests/desktop-rpc-config-watch.test.ts +1159 -0
- package/tests/desktop-rpc-config.test.ts +1462 -0
- package/tests/desktop-rpc-design.test.ts +672 -0
- package/tests/desktop-rpc-jobs.test.ts +1193 -0
- package/tests/desktop-rpc-permissions.test.ts +321 -0
- package/tests/desktop-rpc-profiles.test.ts +140 -0
- package/tests/desktop-rpc-review.test.ts +678 -0
- package/tests/desktop-rpc-safety.test.ts +119 -0
- package/tests/desktop-rpc-session.test.ts +642 -0
- package/tests/desktop-rpc-sessions.test.ts +647 -0
- package/tests/desktop-rpc-stats.test.ts +431 -0
- package/tests/desktop-rpc-updates.test.ts +525 -0
- package/tests/desktop-rpc-usage.test.ts +707 -0
- package/tests/desktop-rpc.test.ts +293 -0
- package/tests/devbinary/pi-host-relay.devtest.ts +149 -80
- package/tests/devbinary/review-session-consent.devtest.ts +84 -0
- package/tests/engram-safety.test.ts +111 -0
- package/tests/fixtures/devbinary/status-v9-escalated-non-blocking.captured.json +92 -0
- package/tests/fixtures/devbinary/status-v9-escalated-non-blocking.provenance.md +3 -0
- package/tests/fixtures/primary-session-prompt/gentleman.golden.md +30 -41
- package/tests/fixtures/refusal-identity.probe.mjs +139 -0
- package/tests/fixtures/session-profile-v1/replay.ts +4 -1
- package/tests/full-delegation-closure.test.ts +48 -0
- package/tests/gentle-agents.test.ts +848 -8
- package/tests/gentle-ai-binary.test.ts +1 -1
- package/tests/gentle-ai-child-guards.test.ts +1 -0
- package/tests/gentle-ai-installer.test.ts +52 -51
- package/tests/gentle-ai-renderer.test.ts +36 -2
- package/tests/gentle-ai.test.ts +195 -21
- package/tests/gentle-design.test.ts +365 -1
- package/tests/gentle-fast.test.ts +15 -0
- package/tests/gentle-herdr-desktop-status.test.ts +595 -0
- package/tests/gentle-shell-bundled.test.ts +91 -5
- package/tests/gentle-shell-desktop-bin.test.ts +125 -0
- package/tests/gentle-shell-desktop.test.ts +927 -0
- package/tests/gentle-shell-launcher-tower.test.ts +104 -0
- package/tests/gentle-shell-launcher.test.ts +1 -1
- package/tests/gentle-shell.test.ts +121 -87
- package/tests/gentle-todo.test.ts +32 -9
- package/tests/gentle-tower.test.ts +578 -0
- package/tests/herdr-desktop-status.test.ts +285 -0
- package/tests/hidden-tools.test.ts +188 -0
- package/tests/independent-recovery-delivery.test.ts +35 -9
- package/tests/inprocess-reviewer.test.ts +73 -0
- package/tests/install-wizard.test.ts +27 -1
- package/tests/installer-downloads.test.ts +30 -1
- package/tests/installer-posix-bootstrap.test.ts +114 -13
- package/tests/installer-preflight.test.ts +49 -1
- package/tests/installer-probes.test.ts +146 -0
- package/tests/installer-server.test.ts +203 -4
- package/tests/installer-windows-bootstrap.test.ts +19 -1
- package/tests/judgment-day-severity-admission.test.ts +46 -0
- package/tests/lazy-module-contradictions-contract.test.ts +181 -0
- package/tests/maintainer/desktop-rpc.maintest.ts +907 -0
- package/tests/maintainer/pi-update-source.maintest.ts +48 -18
- package/tests/model-fallback-policy.test.ts +26 -7
- package/tests/nan-provider-runtime.test.ts +17 -3
- package/tests/nan-provider.test.ts +111 -56
- package/tests/native-review-capability-contract.test.ts +19 -1
- package/tests/native-review-cli-nonblocking-findings.test.ts +165 -0
- package/tests/native-review-parity.test.ts +24 -5
- package/tests/native-review-refusal-identity.test.ts +25 -0
- package/tests/no-self-pause-contract.test.ts +33 -15
- package/tests/odd-integration.test.ts +11 -3
- package/tests/odd-routing-canonical-ratchet.test.ts +10 -0
- package/tests/odd-routing-contract.test.ts +99 -31
- package/tests/orchestrator-budget.test.ts +32 -5
- package/tests/orchestrator-consultation-sdk.test.ts +32 -6
- package/tests/orchestrator-delegation-mode.test.ts +2 -1
- package/tests/orchestrator-discovery.test.ts +28 -0
- package/tests/orchestrator-prompt-budget.test.ts +12 -2
- package/tests/orchestrator-prompt-diet-contract.test.ts +249 -0
- package/tests/orchestrator-rdd-ownership.test.ts +2 -1
- package/tests/orchestrator-work-search.test.ts +4 -2
- package/tests/package-files.test.ts +25 -1
- package/tests/package-manifest.test.ts +15 -14
- package/tests/parallel-reason-contract.test.ts +6 -3
- package/tests/permission-allowlist.test.ts +200 -30
- package/tests/persona-neutral-voseo.test.ts +4 -4
- package/tests/persona-reply-language.test.ts +1 -1
- package/tests/persona-single-channel.test.ts +13 -5
- package/tests/pi-routing-measured-values.test.ts +24 -0
- package/tests/pi-update-launcher.test.ts +17 -7
- package/tests/pi-update-source.test.ts +113 -6
- package/tests/pi-update.test.ts +294 -19
- package/tests/pnpm-workspace-policy.test.ts +47 -0
- package/tests/primary-context-files.test.ts +233 -0
- package/tests/primary-context-three-files.test.ts +174 -0
- package/tests/primary-session-prompt.test.ts +25 -0
- package/tests/profile-fast-tier.test.ts +66 -1
- package/tests/provider-defect-handoff.test.ts +124 -99
- package/tests/rdd-aware-verification-contract.test.ts +1 -1
- package/tests/rdd-status-line.test.ts +94 -1
- package/tests/reply-language-anchor-placement.test.ts +184 -0
- package/tests/reply-language-anchor.test.ts +17 -1
- package/tests/request-context-append-only.test.ts +218 -0
- package/tests/request-context-placement.test.ts +148 -0
- package/tests/review-agent-end-preflight.test.ts +79 -1
- package/tests/review-candidate-view.test.ts +65 -0
- package/tests/review-continuation-registry.test.ts +31 -0
- package/tests/review-contract-prompt.test.ts +2 -1
- package/tests/review-controller.test.ts +2 -1
- package/tests/review-coordinator-correction-gate.test.ts +105 -0
- package/tests/review-coordinator-findings.test.ts +206 -0
- package/tests/review-coordinator-nonblocking-scope.test.ts +169 -0
- package/tests/review-coordinator.test.ts +271 -4
- package/tests/review-delivery-preflight.test.ts +462 -0
- package/tests/review-due-compaction.test.ts +31 -0
- package/tests/review-due-public-boundary.test.ts +27 -0
- package/tests/review-integration-nonblocking-findings.test.ts +108 -0
- package/tests/review-json-arguments.test.ts +41 -2
- package/tests/review-ledger-contract.test.ts +19 -40
- package/tests/review-loadout-rdd-off-sdk.test.ts +30 -1
- package/tests/review-one-call-findings.test.ts +131 -0
- package/tests/review-one-call-followups.test.ts +308 -0
- package/tests/review-one-call-reviewer-requests.test.ts +207 -0
- package/tests/review-one-call.test.ts +452 -0
- package/tests/review-relay-transport-agent.test.ts +28 -1
- package/tests/review-reviewer-evidence.test.ts +41 -1
- package/tests/review-risk-assessment.test.ts +52 -5
- package/tests/review-run-statement-guidance-independent.test.ts +54 -0
- package/tests/review-session-standing-permission-controller.test.ts +32 -2
- package/tests/review-tool-prose-budget.test.ts +1 -0
- package/tests/reviewer-stream.test.ts +149 -0
- package/tests/sensitive-path-tools.test.ts +138 -4
- package/tests/session-profile-extension.test.ts +312 -18
- package/tests/session-profile-freeze.test.ts +26 -0
- package/tests/session-profile-v1-compat.test.ts +20 -0
- package/tests/shell-prompt.test.ts +17 -0
- package/tests/shell-usage.test.ts +59 -10
- package/tests/skill-collision-prefixes.test.ts +1 -0
- package/tests/skill-contradictions-contract.test.ts +124 -0
- package/tests/skill-registry-watcher.test.ts +216 -2
- package/tests/skill-registry.test.ts +983 -306
- package/tests/stats-collector.test.ts +109 -2
- package/tests/support/design-canvas-dom.ts +386 -0
- package/tests/support/review-coordinator-runtime.ts +212 -17
- package/tests/task-size-routing-contract.test.ts +49 -14
- package/tests/test-strength-contract.test.ts +2 -1
- package/tests/todo-request-append-only.test.ts +214 -0
- package/tests/tool-batching-contract.test.ts +3 -1
- package/tests/tower-actions.test.ts +247 -0
- package/tests/tower-artifacts.test.ts +114 -0
- package/tests/tower-open.test.ts +97 -0
- package/tests/tower-presence.test.ts +175 -0
- package/tests/tower-server.test.ts +122 -0
- package/tests/tower-snapshot.test.ts +236 -0
- package/tests/tower-web-echo.test.ts +125 -0
- package/tests/tower-web-hover.test.ts +251 -0
- package/tests/update-agent-body-history.test.ts +138 -0
- package/tests/verification-scoped-stop-contract.test.ts +32 -0
- package/tests/verification-tiers-contract.test.ts +229 -0
- package/tests/verifier-preparation.test.ts +229 -0
- package/tests/verifier-settle-reminder.test.ts +2 -2
- package/tests/verify-agent-contract.test.ts +20 -2
- package/tests/verify-first-launch-contract.test.ts +88 -12
- package/tests/vim-editor-adapter.test.ts +2 -2
- package/tests/work-continuity-contract.test.ts +136 -27
- package/tests/writer-admission-messages.test.ts +232 -0
- package/tests/writer-batch-admission.test.ts +66 -0
- package/tests/writer-edit-surface-scope.test.ts +52 -20
- package/tests/writer-feature-document-admission.test.ts +184 -0
- package/tests/writer-rejection-next-step.test.ts +55 -0
- package/tests/writer-surface-authority-contract.test.ts +158 -0
- package/tests/yolo-mode.test.ts +39 -0
- package/skills/_shared/review-ledger-contract.md +0 -106
- /package/contracts/review-provider-contract-mirror/{v1.4.0 → v1.6.0}/bundle/README.md +0 -0
- /package/contracts/review-provider-contract-mirror/{v1.4.0 → v1.6.0}/bundle/schemas/lens.schema.json +0 -0
- /package/contracts/review-provider-contract-mirror/{v1.4.0 → v1.6.0}/bundle/schemas/refuter.schema.json +0 -0
- /package/contracts/review-provider-contract-mirror/{v1.4.0 → v1.6.0}/bundle/schemas/targeted-validator.schema.json +0 -0
- /package/contracts/review-provider-contract-mirror/{v1.4.0 → v1.6.0}/bundle/vectors/lens.json +0 -0
- /package/contracts/review-provider-contract-mirror/{v1.4.0 → v1.6.0}/bundle/vectors/refuter.json +0 -0
- /package/contracts/review-provider-contract-mirror/{v1.4.0 → v1.6.0}/bundle/vectors/targeted-validator.json +0 -0
|
@@ -0,0 +1,885 @@
|
|
|
1
|
+
// Gentle Desktop config access (`get_config`) and the bounded write slice
|
|
2
|
+
// (`set_config`).
|
|
3
|
+
//
|
|
4
|
+
// Desktop names a store, never a path: this module maps each store identifier to
|
|
5
|
+
// the existing owner reader and its current precedence, then reports the
|
|
6
|
+
// normalized content plus an opaque revision. Writes exist only for the three
|
|
7
|
+
// stores whose owners already accept validated, atomic writes — `profiles`,
|
|
8
|
+
// `profile_fallbacks`, and `pins` — and they go through those same owner writers,
|
|
9
|
+
// so no invariant is re-implemented here. A pin layer is set or cleared through
|
|
10
|
+
// the owner's `writeProfilePinSync` / `clearProfilePinSync`, one explicitly named
|
|
11
|
+
// layer per request. `models`, `subagents`, and `managed_assets` are derived or
|
|
12
|
+
// installer-owned and answer a typed `read_only` error to every write. There is no
|
|
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.
|
|
21
|
+
//
|
|
22
|
+
// The write revision is the digest of the exact single file the owner rewrites,
|
|
23
|
+
// which is why `pins` reports one revision per layer instead of the merged read
|
|
24
|
+
// revision. `expectedRevision` is re-checked against a fresh read immediately
|
|
25
|
+
// before the owner write, in the same synchronous step, so an interleaved Desktop
|
|
26
|
+
// request in this process cannot pass the check with a stale token. That is a
|
|
27
|
+
// per-process serialization, not a cross-process transaction: there is no lock,
|
|
28
|
+
// so a second `pi` process can still write between the check and the rename.
|
|
29
|
+
|
|
30
|
+
import { createHash } from "node:crypto";
|
|
31
|
+
import { basename, dirname } from "node:path";
|
|
32
|
+
import type { ExtensionContext } from "@earendil-works/pi-coding-agent";
|
|
33
|
+
import { managedAssetsManifestPath, readManagedAssetsManifestResult, type ManagedAssetsManifest } from "./agent-assets.ts";
|
|
34
|
+
import { gentlePiConfigHome, resolveGentlePiAgentHome } from "./agent-home.ts";
|
|
35
|
+
import {
|
|
36
|
+
isValidProfileName,
|
|
37
|
+
normalizeProfilesFile,
|
|
38
|
+
parseProfilesFileText,
|
|
39
|
+
profilesFilePath,
|
|
40
|
+
readProfilesFileResult,
|
|
41
|
+
serializeProfilesFile,
|
|
42
|
+
writeProfilesFileSync,
|
|
43
|
+
type ProfilesParseDrops,
|
|
44
|
+
} from "./agent-profiles.ts";
|
|
45
|
+
import { evaluateProfilePin, clearProfilePinSync, readProfilePinStatus, writeProfilePinSync } from "./agent-profile-pin.ts";
|
|
46
|
+
import { parseAgentsConfig, readSubagentsFileResult, subagentsConfigPaths } from "./agents-config.ts";
|
|
47
|
+
import type { DesktopRpcOutcome, DesktopRpcState } from "./desktop-rpc.ts";
|
|
48
|
+
import { DesktopDirectoryWatcher, type DesktopDirectoryWatcherOptions, type DesktopWatchTarget } from "./desktop-rpc-config-watch.ts";
|
|
49
|
+
import { isDesktopProfileApplyRunning } from "./desktop-rpc-profiles.ts";
|
|
50
|
+
import { fallbacksFilePath, normalizeFallbacksFile, readFallbacksFile, writeFallbacksFile } from "./model-fallback-store.ts";
|
|
51
|
+
import { modelConfigPaths, normalizeModelConfig, readModelConfigFile, readSavedModelConfig } from "./model-routing-authority.ts";
|
|
52
|
+
import type { WorktreeResolver } from "./session-worktree-registry.ts";
|
|
53
|
+
|
|
54
|
+
export const DESKTOP_CONFIG_METHODS = ["get_config", "set_config"] as const;
|
|
55
|
+
/** Advertised only because this module wires the writer that publishes it. */
|
|
56
|
+
export const DESKTOP_CONFIG_EVENTS = ["config_changed"] as const;
|
|
57
|
+
export const DESKTOP_CONFIG_EVENT = "config_changed";
|
|
58
|
+
|
|
59
|
+
/** Every store this channel can read, in the order `get_snapshot` projects them. */
|
|
60
|
+
export const DESKTOP_CONFIG_STORES = [
|
|
61
|
+
"profiles",
|
|
62
|
+
"models",
|
|
63
|
+
"profile_fallbacks",
|
|
64
|
+
"subagents",
|
|
65
|
+
"pins",
|
|
66
|
+
"managed_assets",
|
|
67
|
+
] as const;
|
|
68
|
+
|
|
69
|
+
export type DesktopConfigStore = (typeof DESKTOP_CONFIG_STORES)[number];
|
|
70
|
+
|
|
71
|
+
/** A layer status is the owner reader's own answer, never an inferred one. */
|
|
72
|
+
export type DesktopConfigStatus = "ok" | "missing" | "invalid";
|
|
73
|
+
export type DesktopConfigLayerSource = "global" | "project" | "local" | "repo";
|
|
74
|
+
export type DesktopConfigScope = "global" | "global+project" | "local+repo";
|
|
75
|
+
|
|
76
|
+
export interface DesktopConfigLayer {
|
|
77
|
+
source: DesktopConfigLayerSource;
|
|
78
|
+
status: DesktopConfigStatus;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
export interface DesktopConfigData {
|
|
82
|
+
store: DesktopConfigStore;
|
|
83
|
+
scope: DesktopConfigScope;
|
|
84
|
+
/** See `storeReadOnly`: only the persistent family is written by this slice. */
|
|
85
|
+
readOnly: boolean;
|
|
86
|
+
status: DesktopConfigStatus;
|
|
87
|
+
/** Opaque digest of the canonical normalized content; stable across equivalent reads. */
|
|
88
|
+
revision: string;
|
|
89
|
+
/**
|
|
90
|
+
* Normalized owner content. Absent when the owner produced none: a missing store
|
|
91
|
+
* or one whose layers are all unreadable. `pins` is the deliberate exception —
|
|
92
|
+
* it always reports what its layers amount to, because a broken or stale pin is
|
|
93
|
+
* exactly the state an operator needs to see.
|
|
94
|
+
*/
|
|
95
|
+
value?: unknown;
|
|
96
|
+
layers: DesktopConfigLayer[];
|
|
97
|
+
/**
|
|
98
|
+
* One entry per file this store's owner rewrites, each with its own write
|
|
99
|
+
* revision. Present only for stores this slice may write.
|
|
100
|
+
*/
|
|
101
|
+
writeTargets?: DesktopConfigWriteTargetInfo[];
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
/**
|
|
105
|
+
* A write target is one file, not one store: `profiles` and `profile_fallbacks`
|
|
106
|
+
* each own a single global file, while `pins` owns two independent layers that a
|
|
107
|
+
* request must select explicitly.
|
|
108
|
+
*/
|
|
109
|
+
export type DesktopConfigWriteTarget = "global" | "local" | "repo";
|
|
110
|
+
|
|
111
|
+
export interface DesktopConfigWriteTargetInfo {
|
|
112
|
+
target: DesktopConfigWriteTarget;
|
|
113
|
+
status: DesktopConfigStatus;
|
|
114
|
+
/** Digest of the target's current content, not of a merged multi-layer read. */
|
|
115
|
+
writeRevision: string;
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
const INVALID_PARAMS = { code: "invalid_request", message: "Invalid Desktop config parameters" } as const;
|
|
119
|
+
const UNKNOWN_STORE = { code: "unknown_store", message: "Unknown Desktop config store" } as const;
|
|
120
|
+
const UNAVAILABLE = { code: "config_unavailable", message: "Config stores unavailable for this session" } as const;
|
|
121
|
+
const READ_ONLY = { code: "read_only", message: "Config store is read-only over Desktop RPC" } as const;
|
|
122
|
+
const APPLY_BUSY = { code: "profile_apply_busy", message: "A profile apply is in progress" } as const;
|
|
123
|
+
const INVALID_DATA = { code: "invalid_data", message: "Invalid config data for this store" } as const;
|
|
124
|
+
const UNKNOWN_PIN_PROFILE = { code: "invalid_data", message: "Pin target profile is not defined by the profiles store" } as const;
|
|
125
|
+
const MISSING_REVISION = { code: "revision_conflict", message: "expectedRevision is required before writing" } as const;
|
|
126
|
+
const STALE_REVISION = { code: "revision_conflict", message: "Config changed since expectedRevision was read" } as const;
|
|
127
|
+
const WRITE_FAILED = { code: "write_failed", message: "Config store write failed" } as const;
|
|
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
|
+
|
|
132
|
+
/** Authoritative stores this slice may write; every other store is read-only. */
|
|
133
|
+
const AUTHORITATIVE_STORES: ReadonlySet<DesktopConfigStore> = new Set(["profiles", "profile_fallbacks", "pins"]);
|
|
134
|
+
|
|
135
|
+
export function storeReadOnly(store: DesktopConfigStore): boolean {
|
|
136
|
+
return !AUTHORITATIVE_STORES.has(store);
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
export function isDesktopConfigStore(value: unknown): value is DesktopConfigStore {
|
|
140
|
+
return typeof value === "string" && (DESKTOP_CONFIG_STORES as readonly string[]).includes(value);
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
/** Paths are resolved by the owner helpers so a store spelling cannot move. */
|
|
144
|
+
export interface DesktopConfigRoots {
|
|
145
|
+
cwd: string;
|
|
146
|
+
configHome: string;
|
|
147
|
+
agentHome: string;
|
|
148
|
+
resolveWorktree?: WorktreeResolver;
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
export interface DesktopConfigOverrides {
|
|
152
|
+
configHome?: string;
|
|
153
|
+
agentHome?: string;
|
|
154
|
+
resolveWorktree?: WorktreeResolver;
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
/**
|
|
158
|
+
* The project and pin layers depend on the live session cwd, so a host without
|
|
159
|
+
* one has no truthful roots to report: the bridge answers unavailable instead of
|
|
160
|
+
* inventing a directory or exposing the process cwd.
|
|
161
|
+
*/
|
|
162
|
+
function withRoots(context: ExtensionContext, overrides: DesktopConfigOverrides): DesktopConfigRoots | undefined {
|
|
163
|
+
if (typeof context.cwd !== "string" || context.cwd.length === 0) return undefined;
|
|
164
|
+
return {
|
|
165
|
+
cwd: context.cwd,
|
|
166
|
+
configHome: overrides.configHome ?? gentlePiConfigHome(),
|
|
167
|
+
agentHome: overrides.agentHome ?? resolveGentlePiAgentHome(),
|
|
168
|
+
...(overrides.resolveWorktree === undefined ? {} : { resolveWorktree: overrides.resolveWorktree }),
|
|
169
|
+
};
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
/**
|
|
173
|
+
* Canonical JSON: sorted keys, `undefined` members dropped exactly like
|
|
174
|
+
* `JSON.stringify` would drop them on the wire, so the digest describes the
|
|
175
|
+
* content the client actually receives and formatting never moves it.
|
|
176
|
+
*/
|
|
177
|
+
function canonicalJson(value: unknown): string {
|
|
178
|
+
if (value === undefined) return "null";
|
|
179
|
+
if (value === null || typeof value !== "object") return JSON.stringify(value) ?? "null";
|
|
180
|
+
if (Array.isArray(value)) return `[${value.map((item) => canonicalJson(item)).join(",")}]`;
|
|
181
|
+
const entries = Object.entries(value as Record<string, unknown>)
|
|
182
|
+
.filter(([, entry]) => entry !== undefined)
|
|
183
|
+
.sort(([left], [right]) => (left < right ? -1 : left > right ? 1 : 0))
|
|
184
|
+
.map(([key, entry]) => `${JSON.stringify(key)}:${canonicalJson(entry)}`);
|
|
185
|
+
return `{${entries.join(",")}}`;
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
/** Read-time content digest. It orders nothing across processes and is not a transaction token. */
|
|
189
|
+
export function configRevision(store: DesktopConfigStore, status: DesktopConfigStatus, value: unknown): string {
|
|
190
|
+
const payload = value === undefined ? { store, status } : { store, status, value };
|
|
191
|
+
return `sha256:${createHash("sha256").update(canonicalJson(payload)).digest("hex").slice(0, 32)}`;
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
/**
|
|
195
|
+
* Write-time digest of exactly one target file. It is deliberately a different
|
|
196
|
+
* token from the read `revision` (the payload names the target), because the value
|
|
197
|
+
* a write replaces is one file while a multi-layer read describes a merge: a pin
|
|
198
|
+
* layer's write revision must not be confusable with the merged `pins` revision.
|
|
199
|
+
*/
|
|
200
|
+
export function configWriteRevision(
|
|
201
|
+
store: DesktopConfigStore,
|
|
202
|
+
target: DesktopConfigWriteTarget,
|
|
203
|
+
status: DesktopConfigStatus,
|
|
204
|
+
value: unknown,
|
|
205
|
+
): string {
|
|
206
|
+
const payload = value === undefined ? { store, target, status } : { store, target, status, value };
|
|
207
|
+
return `sha256:${createHash("sha256").update(canonicalJson(payload)).digest("hex").slice(0, 32)}`;
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
/**
|
|
211
|
+
* The projection is the JSON a client receives, so absent owner fields are
|
|
212
|
+
* dropped here instead of surviving as `undefined` members that no consumer of
|
|
213
|
+
* the wire format can ever see.
|
|
214
|
+
*/
|
|
215
|
+
function wireValue<T>(value: T): T {
|
|
216
|
+
if (Array.isArray(value)) return value.map((entry) => wireValue(entry)) as unknown as T;
|
|
217
|
+
if (value === null || typeof value !== "object") return value;
|
|
218
|
+
const projected: Record<string, unknown> = {};
|
|
219
|
+
for (const [key, entry] of Object.entries(value as Record<string, unknown>)) {
|
|
220
|
+
if (entry === undefined) continue;
|
|
221
|
+
projected[key] = wireValue(entry);
|
|
222
|
+
}
|
|
223
|
+
return projected as T;
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
interface StoreRead {
|
|
227
|
+
status: DesktopConfigStatus;
|
|
228
|
+
value?: unknown;
|
|
229
|
+
layers: DesktopConfigLayer[];
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
function layer(source: DesktopConfigLayerSource, status: "missing" | "invalid" | "valid"): DesktopConfigLayer {
|
|
233
|
+
return { source, status: status === "valid" ? "ok" : status };
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
type LayerReadStatus = "missing" | "invalid" | "valid";
|
|
237
|
+
|
|
238
|
+
/**
|
|
239
|
+
* Store status for a store the owner assembles from layers it reads independently.
|
|
240
|
+
* `missing` only when every layer is absent, `invalid` only when no layer produced
|
|
241
|
+
* content, and `ok` as soon as one layer is usable — the same merge the runtime
|
|
242
|
+
* performs, with the broken layers still named in `layers`.
|
|
243
|
+
*/
|
|
244
|
+
function layeredStatus(...statuses: LayerReadStatus[]): DesktopConfigStatus {
|
|
245
|
+
if (statuses.every((status) => status === "missing")) return "missing";
|
|
246
|
+
return statuses.some((status) => status === "valid") ? "ok" : "invalid";
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
function readProfiles(root: DesktopConfigRoots): StoreRead {
|
|
250
|
+
const read = readProfilesFileResult(profilesFilePath(root.configHome));
|
|
251
|
+
const status: DesktopConfigStatus = read.status === "valid" ? "ok" : read.status;
|
|
252
|
+
return {
|
|
253
|
+
status,
|
|
254
|
+
...(read.status === "valid" ? { value: read.file } : {}),
|
|
255
|
+
layers: [layer("global", read.status)],
|
|
256
|
+
};
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
function readModels(root: DesktopConfigRoots): StoreRead {
|
|
260
|
+
const paths = modelConfigPaths(root.configHome, root.cwd);
|
|
261
|
+
// The owner merge stays authoritative: it decides precedence and rejects a
|
|
262
|
+
// broken layer, and `normalizeModelConfig` keeps the same safe-key policy the
|
|
263
|
+
// rest of the routing uses. The per-layer reads exist only to report which
|
|
264
|
+
// layer is missing or malformed.
|
|
265
|
+
const global = readModelConfigFile(paths.global);
|
|
266
|
+
const project = readModelConfigFile(paths.project);
|
|
267
|
+
const merged = readSavedModelConfig(paths.global, paths.project);
|
|
268
|
+
const status: DesktopConfigStatus = merged.status === "valid" ? "ok" : merged.status;
|
|
269
|
+
return {
|
|
270
|
+
status,
|
|
271
|
+
...(merged.status === "valid" ? { value: normalizeModelConfig(merged.config) ?? {} } : {}),
|
|
272
|
+
layers: [layer("global", global.status), layer("project", project.status)],
|
|
273
|
+
};
|
|
274
|
+
}
|
|
275
|
+
|
|
276
|
+
function readProfileFallbacks(root: DesktopConfigRoots): StoreRead {
|
|
277
|
+
const read = readFallbacksFile(fallbacksFilePath(root.configHome));
|
|
278
|
+
const status: DesktopConfigStatus = read.status === "valid" ? "ok" : read.status;
|
|
279
|
+
return {
|
|
280
|
+
status,
|
|
281
|
+
...(read.status === "valid" ? { value: read.file } : {}),
|
|
282
|
+
layers: [layer("global", read.status)],
|
|
283
|
+
};
|
|
284
|
+
}
|
|
285
|
+
|
|
286
|
+
function readSubagents(root: DesktopConfigRoots): StoreRead {
|
|
287
|
+
const paths = subagentsConfigPaths({ cwd: root.cwd, home: root.agentHome, agentHome: root.agentHome });
|
|
288
|
+
const global = readSubagentsFileResult(paths.global);
|
|
289
|
+
const project = readSubagentsFileResult(paths.project);
|
|
290
|
+
const layers = [layer("global", global.status), layer("project", project.status)];
|
|
291
|
+
const status = layeredStatus(global.status, project.status);
|
|
292
|
+
if (status !== "ok") return { status, layers };
|
|
293
|
+
// The same parser the runtime uses, so the projection cannot drift from the
|
|
294
|
+
// routing a launch would read. Like the owner, a layer that cannot be parsed is
|
|
295
|
+
// skipped and the remaining layer still merges; `layers` reports which one it was.
|
|
296
|
+
const value = parseAgentsConfig(
|
|
297
|
+
global.status === "valid" ? global.value : undefined,
|
|
298
|
+
project.status === "valid" ? project.value : undefined,
|
|
299
|
+
);
|
|
300
|
+
return { status, value, layers };
|
|
301
|
+
}
|
|
302
|
+
|
|
303
|
+
function readPins(root: DesktopConfigRoots): StoreRead {
|
|
304
|
+
const status = readProfilePinStatus(root.cwd, root.resolveWorktree);
|
|
305
|
+
if (!status) {
|
|
306
|
+
// Outside a resolvable worktree there are no pin layers to report: say so
|
|
307
|
+
// instead of pretending the repository declares nothing.
|
|
308
|
+
return {
|
|
309
|
+
status: "invalid",
|
|
310
|
+
value: { resolved: false, invalid: [], stale: [], reason: "worktree_unresolved" },
|
|
311
|
+
layers: [],
|
|
312
|
+
};
|
|
313
|
+
}
|
|
314
|
+
const store = readProfilesFileResult(profilesFilePath(root.configHome));
|
|
315
|
+
const evaluation = evaluateProfilePin(status, store.status === "valid" ? store.file.profiles : {});
|
|
316
|
+
const bothMissing = status.local.status === "missing" && status.repo.status === "missing";
|
|
317
|
+
const storeStatus: DesktopConfigStatus = bothMissing ? "missing" : evaluation.winner ? "ok" : "invalid";
|
|
318
|
+
// The owner reports layer paths for the panel; Desktop only needs which layer
|
|
319
|
+
// and what it held, so the paths are dropped here. The layers are already read,
|
|
320
|
+
// so even an all-missing or unresolvable pin set is reported instead of hidden.
|
|
321
|
+
return {
|
|
322
|
+
status: storeStatus,
|
|
323
|
+
value: {
|
|
324
|
+
resolved: evaluation.winner !== undefined,
|
|
325
|
+
...(evaluation.winner === undefined
|
|
326
|
+
? {}
|
|
327
|
+
: { winner: { source: evaluation.winner.source, profile: evaluation.winner.profile } }),
|
|
328
|
+
invalid: evaluation.invalid.map((issue) => ({ source: issue.source })),
|
|
329
|
+
stale: evaluation.stale.map((issue) => ({ source: issue.source, profile: issue.profile })),
|
|
330
|
+
},
|
|
331
|
+
layers: [layer("local", status.local.status), layer("repo", status.repo.status)],
|
|
332
|
+
};
|
|
333
|
+
}
|
|
334
|
+
|
|
335
|
+
const OWNERSHIP_KEY_MAX_LENGTH = 256;
|
|
336
|
+
const OWNERSHIP_HASH_PATTERN = /^[a-fA-F0-9]{64}$/;
|
|
337
|
+
const CONTROL_CHARACTERS = /[\u0000-\u001f\u007f]/;
|
|
338
|
+
|
|
339
|
+
function ownershipAssetKey(key: string): boolean {
|
|
340
|
+
if (key.length === 0 || key.length > OWNERSHIP_KEY_MAX_LENGTH) return false;
|
|
341
|
+
if (CONTROL_CHARACTERS.test(key) || key.includes("\\")) return false;
|
|
342
|
+
// An ownership key is a relative POSIX-style asset path below the agent home.
|
|
343
|
+
if (key.startsWith("/") || /^[A-Za-z]:/.test(key)) return false;
|
|
344
|
+
return key.includes("/") && key.split("/").every((segment) => segment.length > 0 && segment !== "." && segment !== "..");
|
|
345
|
+
}
|
|
346
|
+
|
|
347
|
+
/**
|
|
348
|
+
* The manifest is installer state, but it reaches a protocol, so it is filtered:
|
|
349
|
+
* only ownership-shaped entries are projected and an absolute path, a traversal
|
|
350
|
+
* segment, or an arbitrary string can never be echoed to a Desktop client. The
|
|
351
|
+
* installer's own current and legacy manifests hold sha256 digests over relative
|
|
352
|
+
* keys, so they pass unchanged.
|
|
353
|
+
*/
|
|
354
|
+
function projectManagedAssets(manifest: ManagedAssetsManifest): ManagedAssetsManifest {
|
|
355
|
+
return {
|
|
356
|
+
schemaVersion: manifest.schemaVersion,
|
|
357
|
+
assets: Object.fromEntries(
|
|
358
|
+
Object.entries(manifest.assets).filter(
|
|
359
|
+
([key, hash]) => ownershipAssetKey(key) && OWNERSHIP_HASH_PATTERN.test(hash),
|
|
360
|
+
),
|
|
361
|
+
),
|
|
362
|
+
};
|
|
363
|
+
}
|
|
364
|
+
|
|
365
|
+
function readManagedAssets(root: DesktopConfigRoots): StoreRead {
|
|
366
|
+
const read = readManagedAssetsManifestResult(managedAssetsManifestPath(root.agentHome));
|
|
367
|
+
const status: DesktopConfigStatus = read.status === "valid" ? "ok" : read.status;
|
|
368
|
+
return {
|
|
369
|
+
status,
|
|
370
|
+
...(read.status === "valid" ? { value: projectManagedAssets(read.manifest) } : {}),
|
|
371
|
+
layers: [layer("global", read.status)],
|
|
372
|
+
};
|
|
373
|
+
}
|
|
374
|
+
|
|
375
|
+
const STORE_READERS: Record<DesktopConfigStore, { scope: DesktopConfigScope; read: (root: DesktopConfigRoots) => StoreRead }> = {
|
|
376
|
+
profiles: { scope: "global", read: readProfiles },
|
|
377
|
+
models: { scope: "global+project", read: readModels },
|
|
378
|
+
profile_fallbacks: { scope: "global", read: readProfileFallbacks },
|
|
379
|
+
subagents: { scope: "global+project", read: readSubagents },
|
|
380
|
+
pins: { scope: "local+repo", read: readPins },
|
|
381
|
+
managed_assets: { scope: "global", read: readManagedAssets },
|
|
382
|
+
};
|
|
383
|
+
|
|
384
|
+
export function readConfigStore(store: DesktopConfigStore, root: DesktopConfigRoots): DesktopConfigData {
|
|
385
|
+
const reader = STORE_READERS[store];
|
|
386
|
+
const read = reader.read(root);
|
|
387
|
+
const value = read.value === undefined ? undefined : wireValue(read.value);
|
|
388
|
+
const revision = configRevision(store, read.status, value);
|
|
389
|
+
const writeTargets = writeTargetsFor(store, root);
|
|
390
|
+
return {
|
|
391
|
+
store,
|
|
392
|
+
scope: reader.scope,
|
|
393
|
+
readOnly: storeReadOnly(store),
|
|
394
|
+
status: read.status,
|
|
395
|
+
revision,
|
|
396
|
+
...(value === undefined ? {} : { value }),
|
|
397
|
+
layers: read.layers,
|
|
398
|
+
...(writeTargets === undefined ? {} : { writeTargets }),
|
|
399
|
+
};
|
|
400
|
+
}
|
|
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
|
+
|
|
443
|
+
function layerWriteInfo(
|
|
444
|
+
store: DesktopConfigStore,
|
|
445
|
+
target: DesktopConfigWriteTarget,
|
|
446
|
+
status: DesktopConfigStatus,
|
|
447
|
+
value: unknown,
|
|
448
|
+
): DesktopConfigWriteTargetInfo {
|
|
449
|
+
return { target, status, writeRevision: configWriteRevision(store, target, status, value) };
|
|
450
|
+
}
|
|
451
|
+
|
|
452
|
+
/**
|
|
453
|
+
* The files a store's owner rewrites, one entry each, or `undefined` for a store
|
|
454
|
+
* this slice never writes. `pins` returns an empty list outside a resolvable Git
|
|
455
|
+
* worktree: there is no truthful pin target then, so none is reported or written.
|
|
456
|
+
*/
|
|
457
|
+
function writeTargetsFor(
|
|
458
|
+
store: DesktopConfigStore,
|
|
459
|
+
root: DesktopConfigRoots,
|
|
460
|
+
): DesktopConfigWriteTargetInfo[] | undefined {
|
|
461
|
+
switch (store) {
|
|
462
|
+
case "profiles": {
|
|
463
|
+
const read = readProfilesFileResult(profilesFilePath(root.configHome));
|
|
464
|
+
const status: DesktopConfigStatus = read.status === "valid" ? "ok" : read.status;
|
|
465
|
+
return [layerWriteInfo(store, "global", status, read.status === "valid" ? read.file : undefined)];
|
|
466
|
+
}
|
|
467
|
+
case "profile_fallbacks": {
|
|
468
|
+
const read = readFallbacksFile(fallbacksFilePath(root.configHome));
|
|
469
|
+
const status: DesktopConfigStatus = read.status === "valid" ? "ok" : read.status;
|
|
470
|
+
return [layerWriteInfo(store, "global", status, read.status === "valid" ? read.file : undefined)];
|
|
471
|
+
}
|
|
472
|
+
case "pins": {
|
|
473
|
+
const status = readProfilePinStatus(root.cwd, root.resolveWorktree);
|
|
474
|
+
if (!status) return [];
|
|
475
|
+
return (["local", "repo"] as const).map((source) => {
|
|
476
|
+
const layerRead = source === "local" ? status.local : status.repo;
|
|
477
|
+
const layerStatus: DesktopConfigStatus = layerRead.status === "valid" ? "ok" : layerRead.status;
|
|
478
|
+
return layerWriteInfo(
|
|
479
|
+
store,
|
|
480
|
+
source,
|
|
481
|
+
layerStatus,
|
|
482
|
+
layerRead.status === "valid" ? { profile: layerRead.profile } : undefined,
|
|
483
|
+
);
|
|
484
|
+
});
|
|
485
|
+
}
|
|
486
|
+
default:
|
|
487
|
+
return undefined;
|
|
488
|
+
}
|
|
489
|
+
}
|
|
490
|
+
|
|
491
|
+
// ---- Write slice: validated, owner-delegated, revision-guarded ----
|
|
492
|
+
|
|
493
|
+
/**
|
|
494
|
+
* One write plan: either a typed rejection before anything is touched, or the
|
|
495
|
+
* exact target, its revision as re-read now, whether the content really differs,
|
|
496
|
+
* and the owner writer to call.
|
|
497
|
+
*/
|
|
498
|
+
type WritePlan =
|
|
499
|
+
| { error: { code: string; message: string } }
|
|
500
|
+
| { target: DesktopConfigWriteTarget; writeRevision: string; changed: boolean; write: () => void };
|
|
501
|
+
|
|
502
|
+
function isRecordValue(value: unknown): value is Record<string, unknown> {
|
|
503
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
504
|
+
}
|
|
505
|
+
|
|
506
|
+
/**
|
|
507
|
+
* `expectedRevision` is mandatory and is compared before the payload is validated,
|
|
508
|
+
* so "you did not prove you saw the current state" never depends on what the data
|
|
509
|
+
* happens to look like. Absent, empty, and non-string tokens are the same answer.
|
|
510
|
+
*/
|
|
511
|
+
function revisionConflict(
|
|
512
|
+
expected: string,
|
|
513
|
+
current: string,
|
|
514
|
+
): typeof STALE_REVISION | undefined {
|
|
515
|
+
return expected === current ? undefined : STALE_REVISION;
|
|
516
|
+
}
|
|
517
|
+
|
|
518
|
+
/**
|
|
519
|
+
* The owner normalizer drops entries it cannot keep (an illegal profile name, an
|
|
520
|
+
* unsafe agent key, a stale `active` marker, an unknown workflow mode). Writing
|
|
521
|
+
* that result would silently delete operator data, so any drop rejects the write
|
|
522
|
+
* instead.
|
|
523
|
+
*/
|
|
524
|
+
function hasNormalizationDrops(drops: ProfilesParseDrops): boolean {
|
|
525
|
+
return (
|
|
526
|
+
drops.droppedProfiles.length > 0 ||
|
|
527
|
+
drops.droppedAgents.length > 0 ||
|
|
528
|
+
drops.droppedActive !== undefined ||
|
|
529
|
+
(drops.droppedWorkflow?.length ?? 0) > 0
|
|
530
|
+
);
|
|
531
|
+
}
|
|
532
|
+
|
|
533
|
+
function planProfilesWrite(data: unknown, root: DesktopConfigRoots, expected: string): WritePlan {
|
|
534
|
+
const normalized = normalizeProfilesFile(data);
|
|
535
|
+
if (!normalized || hasNormalizationDrops(normalized.drops)) return { error: INVALID_DATA };
|
|
536
|
+
const file = normalized.file;
|
|
537
|
+
// The request must already be in the owner's canonical form: anything the
|
|
538
|
+
// normalizer would rewrite (the `effort` alias, an organic workflow entry) is
|
|
539
|
+
// rejected instead of being applied behind the client's back.
|
|
540
|
+
if (canonicalJson(file) !== canonicalJson(data)) return { error: INVALID_DATA };
|
|
541
|
+
// The owner's serializer must be lossless for this file; data it cannot
|
|
542
|
+
// round-trip is data this channel refuses to write.
|
|
543
|
+
const reparsed = parseProfilesFileText(serializeProfilesFile(file));
|
|
544
|
+
if (reparsed.status !== "valid" || canonicalJson(reparsed.file) !== canonicalJson(file)) {
|
|
545
|
+
return { error: INVALID_DATA };
|
|
546
|
+
}
|
|
547
|
+
const path = profilesFilePath(root.configHome);
|
|
548
|
+
const current = readProfilesFileResult(path);
|
|
549
|
+
const currentStatus: DesktopConfigStatus = current.status === "valid" ? "ok" : current.status;
|
|
550
|
+
const currentValue = current.status === "valid" ? current.file : undefined;
|
|
551
|
+
const writeRevision = configWriteRevision("profiles", "global", currentStatus, currentValue);
|
|
552
|
+
const conflict = revisionConflict(expected, writeRevision);
|
|
553
|
+
if (conflict) return { error: conflict };
|
|
554
|
+
const changed = current.status !== "valid" || canonicalJson(currentValue) !== canonicalJson(file);
|
|
555
|
+
return { target: "global", writeRevision, changed, write: () => writeProfilesFileSync(path, file) };
|
|
556
|
+
}
|
|
557
|
+
|
|
558
|
+
function planFallbacksWrite(data: unknown, root: DesktopConfigRoots, expected: string): WritePlan {
|
|
559
|
+
const normalized = normalizeFallbacksFile(data);
|
|
560
|
+
// The owner normalizer drops an empty chain and an emptied profile block. A
|
|
561
|
+
// Desktop write must be lossless, so the normalized value has to equal the
|
|
562
|
+
// request exactly; anything else would delete content the client sent.
|
|
563
|
+
if (!normalized || canonicalJson(normalized) !== canonicalJson(data)) return { error: INVALID_DATA };
|
|
564
|
+
const path = fallbacksFilePath(root.configHome);
|
|
565
|
+
const current = readFallbacksFile(path);
|
|
566
|
+
const currentStatus: DesktopConfigStatus = current.status === "valid" ? "ok" : current.status;
|
|
567
|
+
const currentValue = current.status === "valid" ? current.file : undefined;
|
|
568
|
+
const writeRevision = configWriteRevision("profile_fallbacks", "global", currentStatus, currentValue);
|
|
569
|
+
const conflict = revisionConflict(expected, writeRevision);
|
|
570
|
+
if (conflict) return { error: conflict };
|
|
571
|
+
const changed = current.status !== "valid" || canonicalJson(currentValue) !== canonicalJson(normalized);
|
|
572
|
+
return { target: "global", writeRevision, changed, write: () => writeFallbacksFile(path, normalized) };
|
|
573
|
+
}
|
|
574
|
+
|
|
575
|
+
function planPinsWrite(data: unknown, root: DesktopConfigRoots, expected: string): WritePlan {
|
|
576
|
+
if (!isRecordValue(data)) return { error: INVALID_DATA };
|
|
577
|
+
if (!Object.keys(data).every((key) => key === "source" || key === "profile")) return { error: INVALID_DATA };
|
|
578
|
+
const source = data.source;
|
|
579
|
+
// The layer is chosen by the request, never by which file happens to exist.
|
|
580
|
+
if (source !== "local" && source !== "repo") return { error: INVALID_DATA };
|
|
581
|
+
// `profile: null` is the explicit clear; every other value must be a pinnable
|
|
582
|
+
// name. There is no "clear everything" and no implicit clear by omission.
|
|
583
|
+
const requested = data.profile;
|
|
584
|
+
let profile: string | undefined;
|
|
585
|
+
if (requested !== null) {
|
|
586
|
+
if (!isValidProfileName(requested)) return { error: INVALID_DATA };
|
|
587
|
+
profile = requested;
|
|
588
|
+
// The invariant the `/gentle:profiles` panel enforces: only a profile the store
|
|
589
|
+
// still defines can be pinned, so this channel never writes a stale pin.
|
|
590
|
+
const store = readProfilesFileResult(profilesFilePath(root.configHome));
|
|
591
|
+
if (store.status !== "valid" || !Object.prototype.hasOwnProperty.call(store.file.profiles, profile)) {
|
|
592
|
+
return { error: UNKNOWN_PIN_PROFILE };
|
|
593
|
+
}
|
|
594
|
+
}
|
|
595
|
+
const status = readProfilePinStatus(root.cwd, root.resolveWorktree);
|
|
596
|
+
if (!status) return { error: UNAVAILABLE };
|
|
597
|
+
const layer = source === "local" ? status.local : status.repo;
|
|
598
|
+
const path = source === "local" ? status.localPath : status.repoPath;
|
|
599
|
+
const layerStatus: DesktopConfigStatus = layer.status === "valid" ? "ok" : layer.status;
|
|
600
|
+
const writeRevision = configWriteRevision(
|
|
601
|
+
"pins",
|
|
602
|
+
source,
|
|
603
|
+
layerStatus,
|
|
604
|
+
layer.status === "valid" ? { profile: layer.profile } : undefined,
|
|
605
|
+
);
|
|
606
|
+
const conflict = revisionConflict(expected, writeRevision);
|
|
607
|
+
if (conflict) return { error: conflict };
|
|
608
|
+
// Clearing a layer that holds no file is already the desired state; a layer that
|
|
609
|
+
// exists but is not a readable pin is still removed by an explicit clear.
|
|
610
|
+
if (profile === undefined) {
|
|
611
|
+
return {
|
|
612
|
+
target: source,
|
|
613
|
+
writeRevision,
|
|
614
|
+
changed: layer.status !== "missing",
|
|
615
|
+
write: () => clearProfilePinSync(path),
|
|
616
|
+
};
|
|
617
|
+
}
|
|
618
|
+
return {
|
|
619
|
+
target: source,
|
|
620
|
+
writeRevision,
|
|
621
|
+
changed: !(layer.status === "valid" && layer.profile === profile),
|
|
622
|
+
write: () => writeProfilePinSync(path, profile),
|
|
623
|
+
};
|
|
624
|
+
}
|
|
625
|
+
|
|
626
|
+
/** Params are exactly `{store}`: no path, no scope selector, no store options. */
|
|
627
|
+
function parseStoreParam(params: Record<string, unknown>): DesktopConfigStore | { error: typeof INVALID_PARAMS | typeof UNKNOWN_STORE } {
|
|
628
|
+
const keys = Object.keys(params);
|
|
629
|
+
if (keys.length !== 1 || keys[0] !== "store" || typeof params.store !== "string") {
|
|
630
|
+
return { error: INVALID_PARAMS };
|
|
631
|
+
}
|
|
632
|
+
if (!isDesktopConfigStore(params.store)) return { error: UNKNOWN_STORE };
|
|
633
|
+
return params.store;
|
|
634
|
+
}
|
|
635
|
+
|
|
636
|
+
export type DesktopConfigEmit = (event: string, data: Record<string, unknown>) => void;
|
|
637
|
+
|
|
638
|
+
/**
|
|
639
|
+
* `get_config` and the bounded `set_config` writer, over the owner readers and
|
|
640
|
+
* the three owner writers.
|
|
641
|
+
*
|
|
642
|
+
* The host context is bound per Desktop command, exactly like the permission
|
|
643
|
+
* bridge, because the pin and project layers depend on the live session cwd.
|
|
644
|
+
* Reads never write, so a read can never advance a store.
|
|
645
|
+
*/
|
|
646
|
+
export class DesktopConfigBridge {
|
|
647
|
+
private host: ExtensionContext | undefined;
|
|
648
|
+
private readonly overrides: DesktopConfigOverrides;
|
|
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 = {}) {
|
|
657
|
+
this.overrides = overrides;
|
|
658
|
+
this.watchOptions = watchOptions;
|
|
659
|
+
}
|
|
660
|
+
|
|
661
|
+
attach(context: ExtensionContext): void {
|
|
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
|
+
}
|
|
675
|
+
}
|
|
676
|
+
|
|
677
|
+
/** Session start/shutdown: watchers, baselines, and the emitter belong to one session. */
|
|
678
|
+
reset(): void {
|
|
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
|
+
}
|
|
755
|
+
}
|
|
756
|
+
|
|
757
|
+
handle(method: string, params: Record<string, unknown>): DesktopRpcOutcome | undefined {
|
|
758
|
+
// Only the config methods are this bridge's business; anything else falls
|
|
759
|
+
// through to the next domain (the permission bridge) untouched.
|
|
760
|
+
if (method !== "get_config" && method !== "set_config") return undefined;
|
|
761
|
+
const host = this.host;
|
|
762
|
+
if (!host) return { ok: false, error: UNAVAILABLE };
|
|
763
|
+
return method === "get_config" ? this.read(host, params) : this.write(host, params);
|
|
764
|
+
}
|
|
765
|
+
|
|
766
|
+
private read(host: ExtensionContext, params: Record<string, unknown>): DesktopRpcOutcome {
|
|
767
|
+
const parsed = parseStoreParam(params);
|
|
768
|
+
if (typeof parsed !== "string") return { ok: false, error: parsed.error };
|
|
769
|
+
const root = withRoots(host, this.overrides);
|
|
770
|
+
if (!root) return { ok: false, error: UNAVAILABLE };
|
|
771
|
+
const data = readConfigStore(parsed, root);
|
|
772
|
+
this.reported.set(parsed, data.revision);
|
|
773
|
+
return { ok: true, data: data as unknown as Record<string, unknown> };
|
|
774
|
+
}
|
|
775
|
+
|
|
776
|
+
/**
|
|
777
|
+
* `set_config`: validate the store-specific data with the owner, re-check
|
|
778
|
+
* `expectedRevision` against a fresh read, then let the owner write.
|
|
779
|
+
*
|
|
780
|
+
* Everything here is synchronous on purpose. Pi dispatches Desktop prompts
|
|
781
|
+
* concurrently, and only an `await` can interleave another request, so the check
|
|
782
|
+
* and the owner's atomic rename cannot be split by another Desktop request in
|
|
783
|
+
* this process. That is a per-process guarantee only; it is not a cross-process
|
|
784
|
+
* transaction (see `docs/desktop-rpc.md`).
|
|
785
|
+
*/
|
|
786
|
+
private write(host: ExtensionContext, params: Record<string, unknown>): DesktopRpcOutcome {
|
|
787
|
+
for (const key of Object.keys(params)) {
|
|
788
|
+
if (key !== "store" && key !== "data" && key !== "expectedRevision") {
|
|
789
|
+
return { ok: false, error: INVALID_PARAMS };
|
|
790
|
+
}
|
|
791
|
+
}
|
|
792
|
+
if (typeof params.store !== "string" || params.data === undefined) {
|
|
793
|
+
return { ok: false, error: INVALID_PARAMS };
|
|
794
|
+
}
|
|
795
|
+
if (!isDesktopConfigStore(params.store)) return { ok: false, error: UNKNOWN_STORE };
|
|
796
|
+
// A read-only store is rejected before its data is inspected: the reason a
|
|
797
|
+
// write cannot happen is the store itself, not the payload.
|
|
798
|
+
if (storeReadOnly(params.store)) return { ok: false, error: READ_ONLY };
|
|
799
|
+
// An apply_profile reads these stores, awaits, then rewrites the profiles
|
|
800
|
+
// store (and restores it on failure) from that snapshot; a write accepted in
|
|
801
|
+
// between would be silently overwritten, so it waits for the apply instead.
|
|
802
|
+
if (isDesktopProfileApplyRunning()) return { ok: false, error: APPLY_BUSY };
|
|
803
|
+
// A usable revision is required before the payload is validated: absent, empty,
|
|
804
|
+
// and non-string tokens are all "the client did not prove current state".
|
|
805
|
+
const expected =
|
|
806
|
+
typeof params.expectedRevision === "string" && params.expectedRevision.length > 0
|
|
807
|
+
? params.expectedRevision
|
|
808
|
+
: undefined;
|
|
809
|
+
if (expected === undefined) return { ok: false, error: MISSING_REVISION };
|
|
810
|
+
const root = withRoots(host, this.overrides);
|
|
811
|
+
if (!root) return { ok: false, error: UNAVAILABLE };
|
|
812
|
+
|
|
813
|
+
const store = params.store;
|
|
814
|
+
const plan =
|
|
815
|
+
store === "profiles"
|
|
816
|
+
? planProfilesWrite(params.data, root, expected)
|
|
817
|
+
: store === "profile_fallbacks"
|
|
818
|
+
? planFallbacksWrite(params.data, root, expected)
|
|
819
|
+
: planPinsWrite(params.data, root, expected);
|
|
820
|
+
if ("error" in plan) return { ok: false, error: plan.error };
|
|
821
|
+
|
|
822
|
+
// Identical content is not a change: the owner writer would skip the rename
|
|
823
|
+
// anyway, and skipping it here keeps a no-op free of a rewrite and an event.
|
|
824
|
+
if (plan.changed) {
|
|
825
|
+
try {
|
|
826
|
+
plan.write();
|
|
827
|
+
} catch {
|
|
828
|
+
// Owner failures carry paths and OS detail; none of it crosses the contract.
|
|
829
|
+
return { ok: false, error: WRITE_FAILED };
|
|
830
|
+
}
|
|
831
|
+
}
|
|
832
|
+
|
|
833
|
+
// The response reports what the store now holds, re-read through the owner,
|
|
834
|
+
// not an echo of the request. The resulting write revision also decides
|
|
835
|
+
// whether this request really changed anything.
|
|
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);
|
|
840
|
+
const writeRevision = after.writeTargets?.find((entry) => entry.target === plan.target)?.writeRevision;
|
|
841
|
+
const changed = writeRevision !== plan.writeRevision;
|
|
842
|
+
const data = { ...after, writeTarget: plan.target, writeRevision, changed } as Record<string, unknown>;
|
|
843
|
+
if (!changed) return { ok: true, data };
|
|
844
|
+
return {
|
|
845
|
+
ok: true,
|
|
846
|
+
data,
|
|
847
|
+
event: {
|
|
848
|
+
name: DESKTOP_CONFIG_EVENT,
|
|
849
|
+
data: {
|
|
850
|
+
store: after.store,
|
|
851
|
+
scope: after.scope,
|
|
852
|
+
writeTarget: plan.target,
|
|
853
|
+
revision: after.revision,
|
|
854
|
+
writeRevision,
|
|
855
|
+
source: "desktop",
|
|
856
|
+
},
|
|
857
|
+
},
|
|
858
|
+
};
|
|
859
|
+
}
|
|
860
|
+
|
|
861
|
+
/** Bounded status/revision/readOnly projection; store content never enters a snapshot. */
|
|
862
|
+
snapshotState(): DesktopRpcState {
|
|
863
|
+
const host = this.host;
|
|
864
|
+
if (!host) return {};
|
|
865
|
+
const root = withRoots(host, this.overrides);
|
|
866
|
+
// Without a session cwd the project and pin layers cannot be read truthfully,
|
|
867
|
+
// so the snapshot stays empty rather than reporting a guess.
|
|
868
|
+
if (!root) return {};
|
|
869
|
+
return {
|
|
870
|
+
config: {
|
|
871
|
+
stores: DESKTOP_CONFIG_STORES.map((store) => {
|
|
872
|
+
const current = storeRevision(store, root);
|
|
873
|
+
this.reported.set(store, current.revision);
|
|
874
|
+
return {
|
|
875
|
+
store,
|
|
876
|
+
scope: current.scope,
|
|
877
|
+
readOnly: storeReadOnly(store),
|
|
878
|
+
status: current.status,
|
|
879
|
+
revision: current.revision,
|
|
880
|
+
};
|
|
881
|
+
}),
|
|
882
|
+
},
|
|
883
|
+
};
|
|
884
|
+
}
|
|
885
|
+
}
|