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,1370 @@
|
|
|
1
|
+
import { spawn, spawnSync } from "node:child_process";
|
|
2
|
+
import { createHash } from "node:crypto";
|
|
3
|
+
import { accessSync, constants as fsConstants, cpSync, existsSync, lstatSync, mkdirSync, readdirSync, readFileSync, realpathSync, renameSync, rmdirSync, rmSync, statSync, symlinkSync, writeFileSync } from "node:fs";
|
|
4
|
+
import { delimiter, join } from "node:path";
|
|
5
|
+
|
|
6
|
+
// `gentle-shell desktop` (Gentle Shell Desktop, odd/tasks/herdr-desktop.md T8):
|
|
7
|
+
// the pinned Herdr app, unchanged, plus our gentle-* mods and the gentle-shell
|
|
8
|
+
// layout from this package's herdr/ folder, the way Gentle Shell ships Pi.
|
|
9
|
+
// Everything it writes in Herdr's home is a gentle-* mod folder,
|
|
10
|
+
// layouts/gentle-shell.json or a themes/gentle-shell-*.json (the layout's light
|
|
11
|
+
// and dark palettes, S14); its own state and backups live in
|
|
12
|
+
// ~/.gentle-shell/desktop. Whatever was at one of those paths before Gentle
|
|
13
|
+
// Shell first installed there (state.json says which paths are ours) is kept
|
|
14
|
+
// in ~/.gentle-shell/desktop/originals, never rotated, and put back exactly by
|
|
15
|
+
// --uninstall. The one shared file it edits is keys.json: it adds only the
|
|
16
|
+
// layout:gentle-shell shortcuts of herdr/keys.json (state.json records each
|
|
17
|
+
// one), never changes a key the person binds, and --uninstall removes exactly
|
|
18
|
+
// those entries.
|
|
19
|
+
|
|
20
|
+
// The Herdr app the mods were built and checked against (`herdr-app check`,
|
|
21
|
+
// live fidelity passes). Newer apps are accepted; older or missing ones get
|
|
22
|
+
// exactly this release.
|
|
23
|
+
export const HERDR_APP_VERSION = "0.1.16";
|
|
24
|
+
|
|
25
|
+
export interface HerdrAppRelease {
|
|
26
|
+
version: string;
|
|
27
|
+
// SHA-256 of herdr-app-<target>.tar.gz, by Herdr target (macos-aarch64, linux-x86_64, ...).
|
|
28
|
+
sha256: Record<string, string>;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
// From Herdr's immutable per-version manifest,
|
|
32
|
+
// https://releases.herdr.dev/app/0.1.16/manifest.json (the file the official
|
|
33
|
+
// install.sh reads through app/latest.json). Pinned here so a changed or
|
|
34
|
+
// replaced download never installs.
|
|
35
|
+
export const HERDR_APP_RELEASE: HerdrAppRelease = {
|
|
36
|
+
version: HERDR_APP_VERSION,
|
|
37
|
+
sha256: {
|
|
38
|
+
"linux-aarch64": "efeef4f1759b0e8900f205c2c22b14287a112f874406539b4ea1b3be24b73631",
|
|
39
|
+
"linux-x86_64": "282d2632196b238206cfe66bfb61c0faf299ca1c91843bd076521bbe36571216",
|
|
40
|
+
"macos-aarch64": "99000875ead9333a33f5cb60274ccd9cf9d3e47360f03613a467295105c71c04",
|
|
41
|
+
"windows-x86_64": "abdc5400679cb730223a43b2a5216999a1edad3c2e80368f0ad3c43ea9895fe3",
|
|
42
|
+
},
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
export const HERDR_RELEASES_URL = "https://releases.herdr.dev";
|
|
46
|
+
export const DESKTOP_LAYOUT = "gentle-shell";
|
|
47
|
+
const OFFICIAL_WINDOWS_INSTALL = 'powershell -c "irm https://releases.herdr.dev/app/install.ps1 | iex"';
|
|
48
|
+
const START_ATTEMPTS = 40;
|
|
49
|
+
const START_INTERVAL_MS = 500;
|
|
50
|
+
// The keys.json section our shortcuts live in: they apply only while the gentle-shell layout shows.
|
|
51
|
+
export const DESKTOP_KEYS_SECTION = `layout:${DESKTOP_LAYOUT}`;
|
|
52
|
+
// A running Herdr reloads keys.json on its file event and writes keys.error when it rejects it.
|
|
53
|
+
const KEYS_CHECK_ATTEMPTS = 4;
|
|
54
|
+
const KEYS_CHECK_INTERVAL_MS = 250;
|
|
55
|
+
// After starting the window: how long to wait for the keys.json Herdr writes on its first start.
|
|
56
|
+
const KEYS_WAIT_ATTEMPTS = 10;
|
|
57
|
+
|
|
58
|
+
export interface RunResult {
|
|
59
|
+
status: number | null;
|
|
60
|
+
stdout: string;
|
|
61
|
+
stderr: string;
|
|
62
|
+
error?: Error;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
export interface DesktopIO {
|
|
66
|
+
run: (command: string, args: string[], options: { env: Record<string, string | undefined>; cwd?: string }) => RunResult;
|
|
67
|
+
spawnDetached: (command: string, args: string[], options: { env: Record<string, string | undefined>; cwd?: string }) => void;
|
|
68
|
+
download: (url: string, file: string) => Promise<void>;
|
|
69
|
+
sha256: (file: string) => string;
|
|
70
|
+
// undefined when the bundle carries a valid Developer ID signature, else why not.
|
|
71
|
+
verifyMacSignature: (app: string) => string | undefined;
|
|
72
|
+
sleep: (ms: number) => Promise<void>;
|
|
73
|
+
ask: (question: string) => Promise<string>;
|
|
74
|
+
out: (line: string) => void;
|
|
75
|
+
err: (line: string) => void;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
export interface DesktopContext {
|
|
79
|
+
args: string[];
|
|
80
|
+
env: Record<string, string | undefined>;
|
|
81
|
+
home: string;
|
|
82
|
+
platform: string;
|
|
83
|
+
arch: string;
|
|
84
|
+
cwd: string;
|
|
85
|
+
interactive: boolean;
|
|
86
|
+
packageRoot: string;
|
|
87
|
+
shellVersion: string;
|
|
88
|
+
io: DesktopIO;
|
|
89
|
+
release?: HerdrAppRelease;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
export function desktopUsage(): string {
|
|
93
|
+
return [
|
|
94
|
+
"Usage: gentle-shell desktop [--yes] [--no-open]",
|
|
95
|
+
" gentle-shell desktop --status",
|
|
96
|
+
" gentle-shell desktop --uninstall",
|
|
97
|
+
"",
|
|
98
|
+
`Gentle Shell Desktop is Herdr app (${HERDR_APP_VERSION} or newer, unchanged) with Gentle Shell's`,
|
|
99
|
+
"gentle-* mods and its gentle-shell layout.",
|
|
100
|
+
"",
|
|
101
|
+
" (no option) Install what is missing, then open Herdr on the gentle-shell layout with a",
|
|
102
|
+
" Gentle Shell space in this folder. Shows what it will install and where, and",
|
|
103
|
+
` asks first. A missing or older Herdr app gets the pinned ${HERDR_APP_VERSION} release`,
|
|
104
|
+
" from releases.herdr.dev, verified against its pinned SHA-256. Each mod must",
|
|
105
|
+
" pass 'herdr-app check' before anything is installed. Only gentle-* mods,",
|
|
106
|
+
" layouts/gentle-shell.json and its light and dark themes (themes/gentle-shell-*.json)",
|
|
107
|
+
" are written in Herdr's home: anything Gentle Shell",
|
|
108
|
+
" did not install there is kept in ~/.gentle-shell/desktop/originals until",
|
|
109
|
+
" --uninstall puts it back; our own previous copy goes to .../desktop/backup.",
|
|
110
|
+
" The Gentle shortcuts (layout:gentle-shell: Cmd-K palette, Cmd-J chat/terminal,",
|
|
111
|
+
" Cmd-. stop, Cmd-Alt-1..6 inspector tabs) are added to Herdr's keys.json; a key",
|
|
112
|
+
" you already bind there stays yours and is reported.",
|
|
113
|
+
" --yes, -y Do not ask (needed when not run in an interactive terminal).",
|
|
114
|
+
" --no-open Install only; do not start or switch Herdr app.",
|
|
115
|
+
" --status Print versions and what is installed.",
|
|
116
|
+
" --uninstall Remove our mods, layout, themes and shortcuts (a copy stays in the backup), put back",
|
|
117
|
+
" what was there before, and switch Herdr back to your previous layout. Herdr",
|
|
118
|
+
" app itself stays installed.",
|
|
119
|
+
" --refresh Reinstall our mods, layout, themes and shortcuts from this Gentle Shell when they are installed;",
|
|
120
|
+
" 'gentle-shell upgrade' runs it. Does nothing if desktop was never installed.",
|
|
121
|
+
].join("\n");
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
type Action = "open" | "status" | "uninstall" | "refresh" | "help";
|
|
125
|
+
|
|
126
|
+
function parseDesktopArgs(args: string[]): { action: Action; yes: boolean; open: boolean } | { error: string } {
|
|
127
|
+
let yes = false;
|
|
128
|
+
let open = true;
|
|
129
|
+
const actions: Action[] = [];
|
|
130
|
+
for (const arg of args) {
|
|
131
|
+
if (arg === "--yes" || arg === "-y") yes = true;
|
|
132
|
+
else if (arg === "--no-open") open = false;
|
|
133
|
+
else if (arg === "--status") actions.push("status");
|
|
134
|
+
else if (arg === "--uninstall") actions.push("uninstall");
|
|
135
|
+
else if (arg === "--refresh") actions.push("refresh");
|
|
136
|
+
else if (arg === "--help" || arg === "-h") return { action: "help", yes, open };
|
|
137
|
+
else return { error: `unknown option ${arg}` };
|
|
138
|
+
}
|
|
139
|
+
if (actions.length > 1) return { error: "choose one of --status, --uninstall or --refresh" };
|
|
140
|
+
return { action: actions[0] ?? "open", yes, open };
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
// Whether the Gentle Shell package at `packageRoot` has the `desktop` command:
|
|
144
|
+
// a version without this module treats `desktop` as a prompt for the model, so
|
|
145
|
+
// `gentle-shell upgrade` only asks a package that ships it to refresh.
|
|
146
|
+
export function supportsDesktop(packageRoot: string): boolean {
|
|
147
|
+
return existsSync(join(packageRoot, "runtime", "gentle-shell-desktop.mjs")) && existsSync(join(packageRoot, "bin", "gentle-shell.mjs"));
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
// --- paths -------------------------------------------------------------------
|
|
151
|
+
|
|
152
|
+
export interface DesktopPaths {
|
|
153
|
+
herdrHome: string;
|
|
154
|
+
mods: string;
|
|
155
|
+
layouts: string;
|
|
156
|
+
layoutFile: string;
|
|
157
|
+
themes: string;
|
|
158
|
+
stateDir: string;
|
|
159
|
+
stateFile: string;
|
|
160
|
+
stage: string;
|
|
161
|
+
backup: string;
|
|
162
|
+
backupNext: string;
|
|
163
|
+
originals: string;
|
|
164
|
+
localBin: string;
|
|
165
|
+
keysFile: string;
|
|
166
|
+
keysError: string;
|
|
167
|
+
keysBackup: string;
|
|
168
|
+
keysOriginal: string;
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
const nonEmpty = (value: string | undefined) => (value !== undefined && value.length > 0 ? value : undefined);
|
|
172
|
+
|
|
173
|
+
// Herdr's own rule (herdr-app src/mods.rs app_dir): $HERDR_APP_HOME, else
|
|
174
|
+
// $XDG_CONFIG_HOME/herdr-app, else ~/.config/herdr-app, on every OS.
|
|
175
|
+
export function desktopPaths(env: Record<string, string | undefined>, home: string): DesktopPaths {
|
|
176
|
+
const herdrHome = nonEmpty(env.HERDR_APP_HOME) ?? join(nonEmpty(env.XDG_CONFIG_HOME) ?? join(home, ".config"), "herdr-app");
|
|
177
|
+
const stateDir = join(home, ".gentle-shell", "desktop");
|
|
178
|
+
return {
|
|
179
|
+
herdrHome,
|
|
180
|
+
mods: join(herdrHome, "mods"),
|
|
181
|
+
layouts: join(herdrHome, "layouts"),
|
|
182
|
+
layoutFile: join(herdrHome, "layouts", `${DESKTOP_LAYOUT}.json`),
|
|
183
|
+
themes: join(herdrHome, "themes"),
|
|
184
|
+
stateDir,
|
|
185
|
+
stateFile: join(stateDir, "state.json"),
|
|
186
|
+
stage: join(stateDir, "stage"),
|
|
187
|
+
backup: join(stateDir, "backup"),
|
|
188
|
+
backupNext: join(stateDir, "backup.next"),
|
|
189
|
+
originals: join(stateDir, "originals"),
|
|
190
|
+
localBin: join(home, ".local", "bin"),
|
|
191
|
+
// One keys.json on every OS; only Herdr's built-in defaults differ (keys.macos.json on macOS).
|
|
192
|
+
keysFile: join(herdrHome, "keys.json"),
|
|
193
|
+
keysError: join(herdrHome, "keys.error"),
|
|
194
|
+
keysBackup: join(stateDir, "keys-backup.json"),
|
|
195
|
+
keysOriginal: join(stateDir, "originals", "keys.json"),
|
|
196
|
+
};
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
// --- shipped assets ------------------------------------------------------------
|
|
200
|
+
|
|
201
|
+
// Herdr regenerates gpui-kit.d.ts and jsconfig.json next to a mod per version
|
|
202
|
+
// (the mods' own .gitignore); FIDELITY*/SPIKE* are our design notes.
|
|
203
|
+
export function isShippedModFile(name: string): boolean {
|
|
204
|
+
if (name === "gpui-kit.d.ts" || name === "jsconfig.json" || name === ".gitignore") return false;
|
|
205
|
+
return !/^(FIDELITY|SPIKE).*\.md$/.test(name);
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
interface Assets {
|
|
209
|
+
mods: string[];
|
|
210
|
+
modsDir: string;
|
|
211
|
+
layoutFile: string;
|
|
212
|
+
// The layout's theme files (herdr/themes/gentle-shell-*.json, S14): its light and dark
|
|
213
|
+
// palettes, by file name.
|
|
214
|
+
themes: string[];
|
|
215
|
+
themesDir: string;
|
|
216
|
+
// The layout:gentle-shell section of herdr/keys.json, when this package ships one.
|
|
217
|
+
keys?: Record<string, KeyAction>;
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
function shippedAssets(packageRoot: string): Assets | { error: string } {
|
|
221
|
+
const root = join(packageRoot, "herdr");
|
|
222
|
+
const modsDir = join(root, "mods");
|
|
223
|
+
const layoutFile = join(root, "layouts", `${DESKTOP_LAYOUT}.json`);
|
|
224
|
+
let mods: string[] = [];
|
|
225
|
+
try {
|
|
226
|
+
mods = readdirSync(modsDir).filter((name) => name.startsWith("gentle-") && isDirectory(join(modsDir, name))).sort();
|
|
227
|
+
} catch {
|
|
228
|
+
mods = [];
|
|
229
|
+
}
|
|
230
|
+
if (mods.length === 0 || !existsSync(layoutFile)) return { error: `this Gentle Shell (${packageRoot}) has no herdr/ mods and layout to install` };
|
|
231
|
+
const themesDir = join(root, "themes");
|
|
232
|
+
let themes: string[] = [];
|
|
233
|
+
try {
|
|
234
|
+
themes = readdirSync(themesDir).filter((name) => isThemeFile(name) && !isDirectory(join(themesDir, name))).sort();
|
|
235
|
+
} catch {
|
|
236
|
+
themes = [];
|
|
237
|
+
}
|
|
238
|
+
const keysFile = join(root, "keys.json");
|
|
239
|
+
if (!existsSync(keysFile)) return { mods, modsDir, layoutFile, themes, themesDir };
|
|
240
|
+
const keys = readKeysText(readFileSync(keysFile, "utf8"));
|
|
241
|
+
if ("problem" in keys) return { error: `this Gentle Shell's ${keysFile} ${keys.problem}` };
|
|
242
|
+
const section = keys.sections[DESKTOP_KEYS_SECTION] as Record<string, KeyAction> | undefined;
|
|
243
|
+
return { mods, modsDir, layoutFile, themes, themesDir, ...(section ? { keys: { ...section } } : {}) };
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
// Our theme files: themes/gentle-shell-<appearance>.json, named after the layout.
|
|
247
|
+
const isThemeFile = (name: string) => new RegExp(`^${DESKTOP_LAYOUT}-[A-Za-z0-9._-]+\\.json$`).test(name);
|
|
248
|
+
|
|
249
|
+
function isDirectory(path: string): boolean {
|
|
250
|
+
try {
|
|
251
|
+
return lstatSync(path).isDirectory();
|
|
252
|
+
} catch {
|
|
253
|
+
return false;
|
|
254
|
+
}
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
function shippedFiles(dir: string, rel = ""): string[] {
|
|
258
|
+
const files: string[] = [];
|
|
259
|
+
for (const name of readdirSync(join(dir, rel)).sort()) {
|
|
260
|
+
const relPath = rel ? join(rel, name) : name;
|
|
261
|
+
if (isDirectory(join(dir, relPath))) files.push(...shippedFiles(dir, relPath));
|
|
262
|
+
else if (isShippedModFile(name)) files.push(relPath);
|
|
263
|
+
}
|
|
264
|
+
return files;
|
|
265
|
+
}
|
|
266
|
+
|
|
267
|
+
function sameFile(a: string, b: string): boolean {
|
|
268
|
+
try {
|
|
269
|
+
return readFileSync(a).equals(readFileSync(b));
|
|
270
|
+
} catch {
|
|
271
|
+
return false;
|
|
272
|
+
}
|
|
273
|
+
}
|
|
274
|
+
|
|
275
|
+
function assetsUpToDate(assets: Assets, paths: DesktopPaths): boolean {
|
|
276
|
+
if (!sameFile(assets.layoutFile, paths.layoutFile)) return false;
|
|
277
|
+
if (!assets.themes.every((name) => sameFile(join(assets.themesDir, name), join(paths.themes, name)))) return false;
|
|
278
|
+
return assets.mods.every((mod) => shippedFiles(join(assets.modsDir, mod)).every((file) => sameFile(join(assets.modsDir, mod, file), join(paths.mods, mod, file))));
|
|
279
|
+
}
|
|
280
|
+
|
|
281
|
+
// --- state -------------------------------------------------------------------
|
|
282
|
+
|
|
283
|
+
// The paths in Herdr's home that are ours: `mods` folders, `themes` files and,
|
|
284
|
+
// when `layout`, layouts/gentle-shell.json. Anything else there is the user's.
|
|
285
|
+
interface DesktopState {
|
|
286
|
+
mods: string[];
|
|
287
|
+
themes?: string[];
|
|
288
|
+
layout: boolean;
|
|
289
|
+
previousLayout?: string;
|
|
290
|
+
keys?: KeysState;
|
|
291
|
+
}
|
|
292
|
+
|
|
293
|
+
function readState(paths: DesktopPaths): DesktopState | undefined {
|
|
294
|
+
try {
|
|
295
|
+
const parsed = JSON.parse(readFileSync(paths.stateFile, "utf8"));
|
|
296
|
+
const mods = Array.isArray(parsed?.mods) ? parsed.mods.filter((name: unknown) => typeof name === "string" && /^gentle-[A-Za-z0-9._-]+$/.test(name)) : [];
|
|
297
|
+
const previousLayout = typeof parsed?.previousLayout === "string" && parsed.previousLayout !== DESKTOP_LAYOUT ? parsed.previousLayout : undefined;
|
|
298
|
+
const keys = parseKeysState(parsed?.keys);
|
|
299
|
+
const themes = Array.isArray(parsed?.themes) ? parsed.themes.filter((name: unknown) => typeof name === "string" && isThemeFile(name)) : [];
|
|
300
|
+
return { mods, ...(themes.length > 0 ? { themes } : {}), layout: parsed?.layout !== false, ...(previousLayout ? { previousLayout } : {}), ...(keys ? { keys } : {}) };
|
|
301
|
+
} catch {
|
|
302
|
+
return undefined;
|
|
303
|
+
}
|
|
304
|
+
}
|
|
305
|
+
|
|
306
|
+
function writeState(paths: DesktopPaths, state: DesktopState) {
|
|
307
|
+
mkdirSync(paths.stateDir, { recursive: true });
|
|
308
|
+
const temp = `${paths.stateFile}.${process.pid}.tmp`;
|
|
309
|
+
writeFileSync(temp, `${JSON.stringify(state, null, 2)}\n`);
|
|
310
|
+
renameSync(temp, paths.stateFile);
|
|
311
|
+
}
|
|
312
|
+
|
|
313
|
+
// --- Herdr app -----------------------------------------------------------------
|
|
314
|
+
|
|
315
|
+
function findOnPath(name: string, env: Record<string, string | undefined>, platform: string): string | undefined {
|
|
316
|
+
const extensions = platform === "win32" ? (env.PATHEXT || ".COM;.EXE;.BAT;.CMD").split(";") : [""];
|
|
317
|
+
for (const dir of (env.PATH ?? "").split(platform === "win32" ? ";" : delimiter).filter(Boolean)) {
|
|
318
|
+
for (const extension of extensions) {
|
|
319
|
+
const candidate = join(dir, `${name}${extension}`);
|
|
320
|
+
try {
|
|
321
|
+
accessSync(candidate, fsConstants.X_OK);
|
|
322
|
+
if (!isDirectory(candidate)) return candidate;
|
|
323
|
+
} catch {
|
|
324
|
+
// keep looking
|
|
325
|
+
}
|
|
326
|
+
}
|
|
327
|
+
}
|
|
328
|
+
return undefined;
|
|
329
|
+
}
|
|
330
|
+
|
|
331
|
+
export function findHerdrApp(env: Record<string, string | undefined>, home: string, platform: string): string | undefined {
|
|
332
|
+
const onPath = findOnPath("herdr-app", env, platform);
|
|
333
|
+
if (onPath) return onPath;
|
|
334
|
+
const local = join(home, ".local", "bin", platform === "win32" ? "herdr-app.exe" : "herdr-app");
|
|
335
|
+
return existsSync(local) ? local : undefined;
|
|
336
|
+
}
|
|
337
|
+
|
|
338
|
+
export function compareVersions(a: string, b: string): number {
|
|
339
|
+
const parts = (value: string) => value.split(".").map((part) => Number.parseInt(part, 10) || 0);
|
|
340
|
+
const left = parts(a);
|
|
341
|
+
const right = parts(b);
|
|
342
|
+
for (let i = 0; i < Math.max(left.length, right.length); i += 1) {
|
|
343
|
+
const diff = (left[i] ?? 0) - (right[i] ?? 0);
|
|
344
|
+
if (diff !== 0) return diff < 0 ? -1 : 1;
|
|
345
|
+
}
|
|
346
|
+
return 0;
|
|
347
|
+
}
|
|
348
|
+
|
|
349
|
+
interface InstalledApp {
|
|
350
|
+
path: string;
|
|
351
|
+
version?: string;
|
|
352
|
+
}
|
|
353
|
+
|
|
354
|
+
function detectApp(ctx: DesktopContext): InstalledApp | undefined {
|
|
355
|
+
const path = findHerdrApp(ctx.env, ctx.home, ctx.platform);
|
|
356
|
+
if (!path) return undefined;
|
|
357
|
+
const result = ctx.io.run(path, ["--version"], { env: ctx.env });
|
|
358
|
+
const version = /herdr-app\s+v?(\d+\.\d+\.\d+)/.exec(`${result.stdout}`)?.[1];
|
|
359
|
+
return { path, ...(version ? { version } : {}) };
|
|
360
|
+
}
|
|
361
|
+
|
|
362
|
+
function herdrTarget(platform: string, arch: string): string | undefined {
|
|
363
|
+
const cpu = arch === "arm64" ? "aarch64" : arch === "x64" ? "x86_64" : undefined;
|
|
364
|
+
if (!cpu) return undefined;
|
|
365
|
+
if (platform === "darwin") return cpu === "aarch64" ? "macos-aarch64" : undefined;
|
|
366
|
+
if (platform === "linux") return `linux-${cpu}`;
|
|
367
|
+
if (platform === "win32") return cpu === "x86_64" ? "windows-x86_64" : undefined;
|
|
368
|
+
return undefined;
|
|
369
|
+
}
|
|
370
|
+
|
|
371
|
+
interface AppPlan {
|
|
372
|
+
target: string;
|
|
373
|
+
url: string;
|
|
374
|
+
sha256: string;
|
|
375
|
+
destination: string;
|
|
376
|
+
link: string;
|
|
377
|
+
replaces?: InstalledApp;
|
|
378
|
+
}
|
|
379
|
+
|
|
380
|
+
function planApp(ctx: DesktopContext, installed: InstalledApp | undefined, release: HerdrAppRelease): AppPlan | { error: string } | undefined {
|
|
381
|
+
if (installed?.version && compareVersions(installed.version, release.version) >= 0) return undefined;
|
|
382
|
+
const target = herdrTarget(ctx.platform, ctx.arch);
|
|
383
|
+
const have = installed ? `Herdr app ${installed.version ?? "(unknown version)"} at ${installed.path} is older than ${release.version}` : `Herdr app ${release.version} or newer is not installed`;
|
|
384
|
+
if (ctx.platform === "win32") {
|
|
385
|
+
return { error: `${have}. Install it with Herdr's official installer, then run gentle-shell desktop again:\n ${OFFICIAL_WINDOWS_INSTALL}` };
|
|
386
|
+
}
|
|
387
|
+
const sha256 = target ? release.sha256[target] : undefined;
|
|
388
|
+
if (!target || !sha256) {
|
|
389
|
+
return { error: `${have}, and Herdr publishes no ${release.version} build for ${ctx.platform}-${ctx.arch}. See https://herdr.dev/download/` };
|
|
390
|
+
}
|
|
391
|
+
const releases = (nonEmpty(ctx.env.HERDR_RELEASES_URL) ?? HERDR_RELEASES_URL).replace(/\/+$/, "");
|
|
392
|
+
const destination = ctx.platform === "darwin"
|
|
393
|
+
? join(ctx.home, "Applications", "Herdr.app")
|
|
394
|
+
: join(nonEmpty(ctx.env.XDG_DATA_HOME) ?? join(ctx.home, ".local", "share"), "herdr-app");
|
|
395
|
+
return {
|
|
396
|
+
target,
|
|
397
|
+
url: `${releases}/app/${release.version}/herdr-app-${target}.tar.gz`,
|
|
398
|
+
sha256,
|
|
399
|
+
destination,
|
|
400
|
+
link: join(ctx.home, ".local", "bin", "herdr-app"),
|
|
401
|
+
...(installed ? { replaces: installed } : {}),
|
|
402
|
+
};
|
|
403
|
+
}
|
|
404
|
+
|
|
405
|
+
function replacePath(source: string, destination: string, scratch: string) {
|
|
406
|
+
const old = join(scratch, "previous");
|
|
407
|
+
const hadOld = existsSync(destination) || isSymlink(destination);
|
|
408
|
+
if (hadOld) moveSync(destination, old);
|
|
409
|
+
try {
|
|
410
|
+
moveSync(source, destination);
|
|
411
|
+
} catch (error) {
|
|
412
|
+
if (hadOld) moveSync(old, destination);
|
|
413
|
+
throw error;
|
|
414
|
+
}
|
|
415
|
+
rmSync(old, { recursive: true, force: true });
|
|
416
|
+
}
|
|
417
|
+
|
|
418
|
+
function isSymlink(path: string): boolean {
|
|
419
|
+
try {
|
|
420
|
+
return lstatSync(path).isSymbolicLink();
|
|
421
|
+
} catch {
|
|
422
|
+
return false;
|
|
423
|
+
}
|
|
424
|
+
}
|
|
425
|
+
|
|
426
|
+
function linkBinary(target: string, link: string) {
|
|
427
|
+
mkdirSync(join(link, ".."), { recursive: true });
|
|
428
|
+
if (isSymlink(link) || existsSync(link)) rmSync(link, { force: true });
|
|
429
|
+
symlinkSync(target, link);
|
|
430
|
+
}
|
|
431
|
+
|
|
432
|
+
// The official install.sh steps (herdr-app distribution/install.sh) for one
|
|
433
|
+
// pinned version: download the release tarball, refuse it unless its SHA-256
|
|
434
|
+
// matches the pin, unpack, then place it where the official installer does.
|
|
435
|
+
// herdr-core is not installed here: Herdr app offers to set it up when it opens.
|
|
436
|
+
async function installApp(ctx: DesktopContext, paths: DesktopPaths, plan: AppPlan): Promise<string> {
|
|
437
|
+
mkdirSync(paths.stateDir, { recursive: true });
|
|
438
|
+
const scratch = join(paths.stateDir, `download-${process.pid}`);
|
|
439
|
+
rmSync(scratch, { recursive: true, force: true });
|
|
440
|
+
mkdirSync(join(scratch, "unpacked"), { recursive: true });
|
|
441
|
+
try {
|
|
442
|
+
const archive = join(scratch, `herdr-app-${plan.target}.tar.gz`);
|
|
443
|
+
ctx.io.out(`Downloading ${plan.url} ...`);
|
|
444
|
+
await ctx.io.download(plan.url, archive);
|
|
445
|
+
const actual = ctx.io.sha256(archive);
|
|
446
|
+
if (actual !== plan.sha256) throw new Error(`the Herdr app download failed its checksum (checksum mismatch: expected ${plan.sha256}, got ${actual}); nothing was installed`);
|
|
447
|
+
const unpack = ctx.io.run("tar", ["-xzf", archive, "-C", join(scratch, "unpacked")], { env: ctx.env });
|
|
448
|
+
if (unpack.status !== 0) throw new Error(`could not unpack ${archive}: ${unpack.stderr || unpack.error?.message || "tar failed"}`);
|
|
449
|
+
if (ctx.platform === "darwin") {
|
|
450
|
+
const app = join(scratch, "unpacked", "Herdr.app");
|
|
451
|
+
if (!existsSync(app)) throw new Error("the Herdr app download has no Herdr.app");
|
|
452
|
+
const signature = ctx.io.verifyMacSignature(app);
|
|
453
|
+
if (signature !== undefined) throw new Error(`the Herdr app download is not validly signed: ${signature}`);
|
|
454
|
+
mkdirSync(join(plan.destination, ".."), { recursive: true });
|
|
455
|
+
replacePath(app, plan.destination, scratch);
|
|
456
|
+
const binary = join(plan.destination, "Contents", "MacOS", "Herdr");
|
|
457
|
+
linkBinary(binary, plan.link);
|
|
458
|
+
ctx.io.run("/System/Library/Frameworks/CoreServices.framework/Frameworks/LaunchServices.framework/Support/lsregister", ["-f", plan.destination], { env: ctx.env });
|
|
459
|
+
return plan.link;
|
|
460
|
+
}
|
|
461
|
+
const unpacked = join(scratch, "unpacked", "herdr-app");
|
|
462
|
+
if (!existsSync(join(unpacked, "herdr-app"))) throw new Error("the Herdr app download has no herdr-app/herdr-app");
|
|
463
|
+
mkdirSync(join(plan.destination, ".."), { recursive: true });
|
|
464
|
+
replacePath(unpacked, plan.destination, scratch);
|
|
465
|
+
linkBinary(join(plan.destination, "herdr-app"), plan.link);
|
|
466
|
+
const data = join(plan.destination, "..");
|
|
467
|
+
try {
|
|
468
|
+
mkdirSync(join(data, "applications"), { recursive: true });
|
|
469
|
+
mkdirSync(join(data, "icons", "hicolor", "scalable", "apps"), { recursive: true });
|
|
470
|
+
if (existsSync(join(plan.destination, "herdr-app.svg"))) cpSync(join(plan.destination, "herdr-app.svg"), join(data, "icons", "hicolor", "scalable", "apps", "herdr-app.svg"));
|
|
471
|
+
writeFileSync(join(data, "applications", "herdr-app.desktop"), [
|
|
472
|
+
"[Desktop Entry]", "Type=Application", "Name=Herdr", "Comment=Terminals and coding agents that keep running",
|
|
473
|
+
`Exec=${plan.link}`, "Icon=herdr-app", "Terminal=false", "Categories=Development;", "StartupWMClass=herdr-app", "",
|
|
474
|
+
].join("\n"));
|
|
475
|
+
} catch {
|
|
476
|
+
// The launcher entry is a convenience; the app and its command are installed.
|
|
477
|
+
}
|
|
478
|
+
return plan.link;
|
|
479
|
+
} finally {
|
|
480
|
+
rmSync(scratch, { recursive: true, force: true });
|
|
481
|
+
}
|
|
482
|
+
}
|
|
483
|
+
|
|
484
|
+
// --- mods and layout -----------------------------------------------------------
|
|
485
|
+
|
|
486
|
+
// rename, or copy + remove across file systems ($HERDR_APP_HOME elsewhere).
|
|
487
|
+
function moveSync(source: string, destination: string) {
|
|
488
|
+
try {
|
|
489
|
+
renameSync(source, destination);
|
|
490
|
+
} catch (error) {
|
|
491
|
+
if ((error as NodeJS.ErrnoException).code !== "EXDEV") throw error;
|
|
492
|
+
cpSync(source, destination, { recursive: true, verbatimSymlinks: true });
|
|
493
|
+
rmSync(source, { recursive: true, force: true });
|
|
494
|
+
}
|
|
495
|
+
}
|
|
496
|
+
|
|
497
|
+
interface Swap {
|
|
498
|
+
target: string;
|
|
499
|
+
movedTo?: string;
|
|
500
|
+
}
|
|
501
|
+
|
|
502
|
+
function rollback(swaps: Swap[]) {
|
|
503
|
+
for (const swap of [...swaps].reverse()) {
|
|
504
|
+
rmSync(swap.target, { recursive: true, force: true });
|
|
505
|
+
if (swap.movedTo) moveSync(swap.movedTo, swap.target);
|
|
506
|
+
}
|
|
507
|
+
}
|
|
508
|
+
|
|
509
|
+
// Removes each folder that is empty, in order (deepest first); others stay.
|
|
510
|
+
function removeEmptyDirs(dirs: string[]) {
|
|
511
|
+
for (const dir of dirs) {
|
|
512
|
+
try {
|
|
513
|
+
rmdirSync(dir);
|
|
514
|
+
} catch {
|
|
515
|
+
// not empty, or already gone
|
|
516
|
+
}
|
|
517
|
+
}
|
|
518
|
+
}
|
|
519
|
+
|
|
520
|
+
function promoteBackup(paths: DesktopPaths) {
|
|
521
|
+
const kept = existsSync(paths.backupNext) && readdirSync(paths.backupNext).some((name) => readdirSync(join(paths.backupNext, name)).length > 0);
|
|
522
|
+
if (kept) {
|
|
523
|
+
rmSync(paths.backup, { recursive: true, force: true });
|
|
524
|
+
moveSync(paths.backupNext, paths.backup);
|
|
525
|
+
} else {
|
|
526
|
+
rmSync(paths.backupNext, { recursive: true, force: true });
|
|
527
|
+
}
|
|
528
|
+
}
|
|
529
|
+
|
|
530
|
+
function prepareScratch(paths: DesktopPaths) {
|
|
531
|
+
for (const dir of [paths.stage, paths.backupNext]) rmSync(dir, { recursive: true, force: true });
|
|
532
|
+
for (const kind of ["mods", "layouts", "themes"]) for (const dir of [join(paths.stage, kind), join(paths.backupNext, kind)]) mkdirSync(dir, { recursive: true });
|
|
533
|
+
}
|
|
534
|
+
|
|
535
|
+
function cleanOriginals(paths: DesktopPaths) {
|
|
536
|
+
removeEmptyDirs([join(paths.originals, "mods"), join(paths.originals, "layouts"), join(paths.originals, "themes"), paths.originals]);
|
|
537
|
+
}
|
|
538
|
+
|
|
539
|
+
// Where a path in Herdr's home goes when it is replaced or removed: our own
|
|
540
|
+
// copy rotates through backup.next; anything else is an original, kept until
|
|
541
|
+
// --uninstall. An original is never overwritten.
|
|
542
|
+
function moveAside(target: string, ours: boolean, backupName: string, originalName: string): string {
|
|
543
|
+
if (ours) {
|
|
544
|
+
moveSync(target, backupName);
|
|
545
|
+
return backupName;
|
|
546
|
+
}
|
|
547
|
+
if (existsSync(originalName) || isSymlink(originalName)) {
|
|
548
|
+
throw new Error(`${target} was not installed by Gentle Shell Desktop and ${originalName} already keeps an earlier original; move one of them elsewhere and run gentle-shell desktop again`);
|
|
549
|
+
}
|
|
550
|
+
mkdirSync(join(originalName, ".."), { recursive: true });
|
|
551
|
+
moveSync(target, originalName);
|
|
552
|
+
return originalName;
|
|
553
|
+
}
|
|
554
|
+
|
|
555
|
+
// Stages our mods and layout and runs `herdr-app check` on every staged mod;
|
|
556
|
+
// only then swaps each into Herdr's home. A path that was ours moves to the
|
|
557
|
+
// backup; anything else moves to the originals. Any failure puts every
|
|
558
|
+
// previous copy back and removes folders this install created.
|
|
559
|
+
function installAssets(ctx: DesktopContext, paths: DesktopPaths, assets: Assets, app: string, previous: DesktopState | undefined): string | undefined {
|
|
560
|
+
prepareScratch(paths);
|
|
561
|
+
const ownedMods = previous?.mods ?? [];
|
|
562
|
+
const ownedThemes = previous?.themes ?? [];
|
|
563
|
+
const ownedLayout = previous?.layout === true;
|
|
564
|
+
try {
|
|
565
|
+
for (const mod of assets.mods) {
|
|
566
|
+
const staged = join(paths.stage, "mods", mod);
|
|
567
|
+
mkdirSync(staged);
|
|
568
|
+
for (const file of shippedFiles(join(assets.modsDir, mod))) {
|
|
569
|
+
mkdirSync(join(staged, file, ".."), { recursive: true });
|
|
570
|
+
cpSync(join(assets.modsDir, mod, file), join(staged, file));
|
|
571
|
+
}
|
|
572
|
+
}
|
|
573
|
+
cpSync(assets.layoutFile, join(paths.stage, "layouts", `${DESKTOP_LAYOUT}.json`));
|
|
574
|
+
for (const name of assets.themes) cpSync(join(assets.themesDir, name), join(paths.stage, "themes", name));
|
|
575
|
+
} catch (error) {
|
|
576
|
+
rmSync(paths.stage, { recursive: true, force: true });
|
|
577
|
+
rmSync(paths.backupNext, { recursive: true, force: true });
|
|
578
|
+
return `could not stage the Gentle mods in ${paths.stage}: ${(error as Error).message}; nothing in ${paths.herdrHome} was changed`;
|
|
579
|
+
}
|
|
580
|
+
for (const mod of assets.mods) {
|
|
581
|
+
const result = ctx.io.run(app, ["check", join(paths.stage, "mods", mod)], { env: ctx.env });
|
|
582
|
+
if (result.status !== 0) {
|
|
583
|
+
rmSync(paths.stage, { recursive: true, force: true });
|
|
584
|
+
rmSync(paths.backupNext, { recursive: true, force: true });
|
|
585
|
+
const detail = `${result.stderr}${result.stdout}`.trim() || result.error?.message || `exit ${result.status}`;
|
|
586
|
+
return `herdr-app check failed for ${mod}:\n${detail}\nthe Gentle mods and layout were not installed; nothing in ${paths.herdrHome} was changed`;
|
|
587
|
+
}
|
|
588
|
+
}
|
|
589
|
+
const created = [paths.layouts, paths.mods, ...(assets.themes.length > 0 ? [paths.themes] : []), paths.herdrHome].filter((dir) => !existsSync(dir));
|
|
590
|
+
const swaps: Swap[] = [];
|
|
591
|
+
const swapIn = (staged: string, target: string, ours: boolean, kind: "mods" | "layouts" | "themes", name: string) => {
|
|
592
|
+
const swap: Swap = { target };
|
|
593
|
+
if (existsSync(target) || isSymlink(target)) swap.movedTo = moveAside(target, ours, join(paths.backupNext, kind, name), join(paths.originals, kind, name));
|
|
594
|
+
swaps.push(swap);
|
|
595
|
+
if (staged) moveSync(staged, target);
|
|
596
|
+
};
|
|
597
|
+
try {
|
|
598
|
+
mkdirSync(paths.mods, { recursive: true });
|
|
599
|
+
mkdirSync(paths.layouts, { recursive: true });
|
|
600
|
+
for (const mod of assets.mods) swapIn(join(paths.stage, "mods", mod), join(paths.mods, mod), ownedMods.includes(mod), "mods", mod);
|
|
601
|
+
// A gentle-* mod an earlier Gentle Shell installed and this one no longer ships;
|
|
602
|
+
// what was there before it comes back.
|
|
603
|
+
for (const mod of ownedMods) {
|
|
604
|
+
if (assets.mods.includes(mod)) continue;
|
|
605
|
+
const target = join(paths.mods, mod);
|
|
606
|
+
if (existsSync(target)) swapIn("", target, true, "mods", mod);
|
|
607
|
+
const original = join(paths.originals, "mods", mod);
|
|
608
|
+
if (existsSync(original)) {
|
|
609
|
+
moveSync(original, target);
|
|
610
|
+
swaps.push({ target: original, movedTo: target });
|
|
611
|
+
}
|
|
612
|
+
}
|
|
613
|
+
// The layout's themes go in before the layout that names them.
|
|
614
|
+
if (assets.themes.length > 0) mkdirSync(paths.themes, { recursive: true });
|
|
615
|
+
for (const name of assets.themes) swapIn(join(paths.stage, "themes", name), join(paths.themes, name), ownedThemes.includes(name), "themes", name);
|
|
616
|
+
// A theme an earlier Gentle Shell installed and this one no longer ships; what was there before comes back.
|
|
617
|
+
for (const name of ownedThemes) {
|
|
618
|
+
if (assets.themes.includes(name)) continue;
|
|
619
|
+
const target = join(paths.themes, name);
|
|
620
|
+
if (existsSync(target)) swapIn("", target, true, "themes", name);
|
|
621
|
+
const original = join(paths.originals, "themes", name);
|
|
622
|
+
if (existsSync(original)) {
|
|
623
|
+
moveSync(original, target);
|
|
624
|
+
swaps.push({ target: original, movedTo: target });
|
|
625
|
+
}
|
|
626
|
+
}
|
|
627
|
+
swapIn(join(paths.stage, "layouts", `${DESKTOP_LAYOUT}.json`), paths.layoutFile, ownedLayout, "layouts", `${DESKTOP_LAYOUT}.json`);
|
|
628
|
+
} catch (error) {
|
|
629
|
+
rollback(swaps);
|
|
630
|
+
removeEmptyDirs(created);
|
|
631
|
+
cleanOriginals(paths);
|
|
632
|
+
rmSync(paths.stage, { recursive: true, force: true });
|
|
633
|
+
rmSync(paths.backupNext, { recursive: true, force: true });
|
|
634
|
+
return `could not install the Gentle mods into ${paths.herdrHome}: ${(error as Error).message}; restored the previous Gentle mods and layout`;
|
|
635
|
+
}
|
|
636
|
+
rmSync(paths.stage, { recursive: true, force: true });
|
|
637
|
+
promoteBackup(paths);
|
|
638
|
+
return undefined;
|
|
639
|
+
}
|
|
640
|
+
|
|
641
|
+
// --- keys.json ---------------------------------------------------------------------
|
|
642
|
+
|
|
643
|
+
// keys.json is the whole keymap: Herdr writes its defaults there on first start
|
|
644
|
+
// and never layers them under it (herdr-app src/keys.rs), so Gentle Shell only
|
|
645
|
+
// ever edits an existing file, as text: every byte outside the entries it adds
|
|
646
|
+
// stays as the person wrote it. state.json's `keys` is the tag: the entries in
|
|
647
|
+
// `entries` are ours while they still hold the action we wrote; a Gentle key
|
|
648
|
+
// the person deleted or rebound is theirs (`dropped`) and is never added again.
|
|
649
|
+
|
|
650
|
+
export type KeyAction = string | Record<string, unknown>;
|
|
651
|
+
|
|
652
|
+
interface KeysState {
|
|
653
|
+
entries: Record<string, KeyAction>;
|
|
654
|
+
dropped: string[];
|
|
655
|
+
conflicts: string[];
|
|
656
|
+
// Whether Gentle Shell added the layout:gentle-shell section itself.
|
|
657
|
+
createdSection: boolean;
|
|
658
|
+
// SHA-256 of keys.json as Gentle Shell last wrote it.
|
|
659
|
+
written: string;
|
|
660
|
+
// SHA-256 of keys.json as the FIRST Gentle write left it (never updated): only
|
|
661
|
+
// then is the saved original still the whole truth.
|
|
662
|
+
firstWritten?: string;
|
|
663
|
+
}
|
|
664
|
+
|
|
665
|
+
const isPlainObject = (value: unknown): value is Record<string, unknown> => typeof value === "object" && value !== null && !Array.isArray(value);
|
|
666
|
+
const stringList = (value: unknown) => (Array.isArray(value) ? value.filter((item): item is string => typeof item === "string") : []);
|
|
667
|
+
|
|
668
|
+
function parseKeysState(value: unknown): KeysState | undefined {
|
|
669
|
+
if (!isPlainObject(value) || !isPlainObject(value.entries) || typeof value.written !== "string") return undefined;
|
|
670
|
+
const entries: Record<string, KeyAction> = {};
|
|
671
|
+
for (const [key, action] of Object.entries(value.entries)) if (typeof action === "string" || isPlainObject(action)) entries[key] = action;
|
|
672
|
+
return { entries, dropped: stringList(value.dropped), conflicts: stringList(value.conflicts), createdSection: value.createdSection === true, written: value.written, ...(typeof value.firstWritten === "string" ? { firstWritten: value.firstWritten } : {}) };
|
|
673
|
+
}
|
|
674
|
+
|
|
675
|
+
const sha256Text = (text: string) => createHash("sha256").update(text).digest("hex");
|
|
676
|
+
const sameAction = (a: unknown, b: unknown) => JSON.stringify(a) === JSON.stringify(b);
|
|
677
|
+
|
|
678
|
+
// Herdr's sections (keys.rs `tab`): anything else makes Herdr reject the whole file.
|
|
679
|
+
const knownSection = (name: string) => name === "global" || name === "terminal" || /^(layout|mod):.+$/.test(name);
|
|
680
|
+
|
|
681
|
+
function readKeysText(text: string): { sections: Record<string, Record<string, unknown>> } | { problem: string } {
|
|
682
|
+
let parsed: unknown;
|
|
683
|
+
try {
|
|
684
|
+
parsed = JSON.parse(text);
|
|
685
|
+
} catch (error) {
|
|
686
|
+
return { problem: `is not valid JSON (${(error as Error).message})` };
|
|
687
|
+
}
|
|
688
|
+
if (!isPlainObject(parsed)) return { problem: "must be a JSON object of sections (global, terminal, layout:<name>, mod:<name>)" };
|
|
689
|
+
for (const [section, bindings] of Object.entries(parsed)) {
|
|
690
|
+
if (!knownSection(section)) return { problem: `is not a keys file Herdr accepts: section ${JSON.stringify(section)} is not global, terminal, layout:<name> or mod:<name>` };
|
|
691
|
+
if (!isPlainObject(bindings)) return { problem: `is not a keys file Herdr accepts: ${section} must be an object of key bindings` };
|
|
692
|
+
for (const [keys, action] of Object.entries(bindings)) {
|
|
693
|
+
if (typeof action !== "string" && !isPlainObject(action)) return { problem: `is not a keys file Herdr accepts: ${section}.${keys} must be a command string or an object` };
|
|
694
|
+
}
|
|
695
|
+
}
|
|
696
|
+
return { sections: parsed as Record<string, Record<string, unknown>> };
|
|
697
|
+
}
|
|
698
|
+
|
|
699
|
+
// The same keystroke however it is spelled: modifiers in any order and case, cmd = super = win.
|
|
700
|
+
export function normalizeKeystroke(keys: string): string {
|
|
701
|
+
const alias: Record<string, string> = { super: "cmd", win: "cmd", command: "cmd", option: "alt", control: "ctrl" };
|
|
702
|
+
return keys.trim().split(/\s+/).map((stroke) => {
|
|
703
|
+
if (stroke === "-") return "-";
|
|
704
|
+
const parts = stroke.endsWith("--") ? [...stroke.slice(0, -2).split("-"), "-"] : stroke.split("-");
|
|
705
|
+
const key = (parts.pop() ?? "").toLowerCase();
|
|
706
|
+
const modifiers = parts.map((part) => alias[part.toLowerCase()] ?? part.toLowerCase());
|
|
707
|
+
return [...new Set(modifiers)].sort().concat(key).join("-");
|
|
708
|
+
}).join(" ");
|
|
709
|
+
}
|
|
710
|
+
|
|
711
|
+
// A minimal scanner for text JSON.parse already accepted: where each member of an
|
|
712
|
+
// object starts and ends, so entries are added, replaced or removed in place.
|
|
713
|
+
interface JsonMember {
|
|
714
|
+
key: string;
|
|
715
|
+
keyStart: number;
|
|
716
|
+
valueStart: number;
|
|
717
|
+
valueEnd: number;
|
|
718
|
+
}
|
|
719
|
+
|
|
720
|
+
interface JsonObject {
|
|
721
|
+
open: number;
|
|
722
|
+
close: number;
|
|
723
|
+
members: JsonMember[];
|
|
724
|
+
}
|
|
725
|
+
|
|
726
|
+
const isJsonSpace = (char: string | undefined) => char === " " || char === "\t" || char === "\n" || char === "\r";
|
|
727
|
+
|
|
728
|
+
function skipSpace(text: string, index: number): number {
|
|
729
|
+
let i = index;
|
|
730
|
+
while (isJsonSpace(text[i])) i += 1;
|
|
731
|
+
return i;
|
|
732
|
+
}
|
|
733
|
+
|
|
734
|
+
function skipString(text: string, index: number): number {
|
|
735
|
+
let i = index + 1;
|
|
736
|
+
while (text[i] !== '"') i += text[i] === "\\" ? 2 : 1;
|
|
737
|
+
return i + 1;
|
|
738
|
+
}
|
|
739
|
+
|
|
740
|
+
function skipValue(text: string, index: number): number {
|
|
741
|
+
const first = text[index];
|
|
742
|
+
if (first === '"') return skipString(text, index);
|
|
743
|
+
if (first === "{" || first === "[") {
|
|
744
|
+
let depth = 0;
|
|
745
|
+
let i = index;
|
|
746
|
+
for (;;) {
|
|
747
|
+
const char = text[i];
|
|
748
|
+
if (char === '"') {
|
|
749
|
+
i = skipString(text, i);
|
|
750
|
+
continue;
|
|
751
|
+
}
|
|
752
|
+
if (char === "{" || char === "[") depth += 1;
|
|
753
|
+
else if (char === "}" || char === "]") {
|
|
754
|
+
depth -= 1;
|
|
755
|
+
if (depth === 0) return i + 1;
|
|
756
|
+
}
|
|
757
|
+
i += 1;
|
|
758
|
+
}
|
|
759
|
+
}
|
|
760
|
+
let i = index;
|
|
761
|
+
while (i < text.length && !isJsonSpace(text[i]) && text[i] !== "," && text[i] !== "}" && text[i] !== "]") i += 1;
|
|
762
|
+
return i;
|
|
763
|
+
}
|
|
764
|
+
|
|
765
|
+
function objectAt(text: string, open: number): JsonObject {
|
|
766
|
+
const members: JsonMember[] = [];
|
|
767
|
+
let i = skipSpace(text, open + 1);
|
|
768
|
+
if (text[i] === "}") return { open, close: i, members };
|
|
769
|
+
for (;;) {
|
|
770
|
+
const keyStart = skipSpace(text, i);
|
|
771
|
+
const keyEnd = skipString(text, keyStart);
|
|
772
|
+
const valueStart = skipSpace(text, skipSpace(text, keyEnd) + 1);
|
|
773
|
+
const valueEnd = skipValue(text, valueStart);
|
|
774
|
+
members.push({ key: JSON.parse(text.slice(keyStart, keyEnd)), keyStart, valueStart, valueEnd });
|
|
775
|
+
i = skipSpace(text, valueEnd);
|
|
776
|
+
if (text[i] !== ",") return { open, close: i, members };
|
|
777
|
+
i += 1;
|
|
778
|
+
}
|
|
779
|
+
}
|
|
780
|
+
|
|
781
|
+
// JSON.parse keeps the last of duplicate keys; so do we.
|
|
782
|
+
const lastMember = (object: JsonObject, key: string) => {
|
|
783
|
+
for (let i = object.members.length - 1; i >= 0; i -= 1) if (object.members[i].key === key) return i;
|
|
784
|
+
return -1;
|
|
785
|
+
};
|
|
786
|
+
|
|
787
|
+
// The whitespace from the start of the line to `index`, when only whitespace precedes it there.
|
|
788
|
+
function indentAt(text: string, index: number | undefined): string | undefined {
|
|
789
|
+
if (index === undefined) return undefined;
|
|
790
|
+
const lineStart = text.lastIndexOf("\n", index - 1) + 1;
|
|
791
|
+
const before = text.slice(lineStart, index);
|
|
792
|
+
return lineStart > 0 && /^[ \t]*$/.test(before) ? before : undefined;
|
|
793
|
+
}
|
|
794
|
+
|
|
795
|
+
function sectionAt(text: string): { root: JsonObject; index: number; section?: JsonObject } {
|
|
796
|
+
const root = objectAt(text, skipSpace(text, 0));
|
|
797
|
+
const index = lastMember(root, DESKTOP_KEYS_SECTION);
|
|
798
|
+
const member = root.members[index];
|
|
799
|
+
return { root, index, ...(member && text[member.valueStart] === "{" ? { section: objectAt(text, member.valueStart) } : {}) };
|
|
800
|
+
}
|
|
801
|
+
|
|
802
|
+
// Appends `"key": value` after the last member, or fills an empty object.
|
|
803
|
+
function insertMember(text: string, object: JsonObject, key: string, value: string, indent: string, closeIndent: string): string {
|
|
804
|
+
const last = object.members.at(-1);
|
|
805
|
+
if (last) return `${text.slice(0, last.valueEnd)},\n${indent}${JSON.stringify(key)}: ${value}${text.slice(last.valueEnd)}`;
|
|
806
|
+
return `${text.slice(0, object.open + 1)}\n${indent}${JSON.stringify(key)}: ${value}\n${closeIndent}${text.slice(object.close)}`;
|
|
807
|
+
}
|
|
808
|
+
|
|
809
|
+
// The inverse of insertMember: the member and the separator before it.
|
|
810
|
+
function removeMember(text: string, object: JsonObject, index: number): string {
|
|
811
|
+
const member = object.members[index];
|
|
812
|
+
if (object.members.length === 1) return `${text.slice(0, object.open + 1)}${text.slice(object.close)}`;
|
|
813
|
+
if (index > 0) return `${text.slice(0, object.members[index - 1].valueEnd)}${text.slice(member.valueEnd)}`;
|
|
814
|
+
return `${text.slice(0, member.keyStart)}${text.slice(object.members[1].keyStart)}`;
|
|
815
|
+
}
|
|
816
|
+
|
|
817
|
+
function addKey(text: string, key: string, action: KeyAction): string {
|
|
818
|
+
let at = sectionAt(text);
|
|
819
|
+
const unit = indentAt(text, at.root.members[0]?.keyStart) ?? " ";
|
|
820
|
+
if (!at.section) {
|
|
821
|
+
text = insertMember(text, at.root, DESKTOP_KEYS_SECTION, "{}", unit, "");
|
|
822
|
+
at = sectionAt(text);
|
|
823
|
+
}
|
|
824
|
+
const section = at.section as JsonObject;
|
|
825
|
+
const sectionIndent = indentAt(text, at.root.members[at.index].keyStart) ?? unit;
|
|
826
|
+
const indent = indentAt(text, section.members[0]?.keyStart) ?? `${sectionIndent}${unit}`;
|
|
827
|
+
return insertMember(text, section, key, JSON.stringify(action), indent, sectionIndent);
|
|
828
|
+
}
|
|
829
|
+
|
|
830
|
+
function replaceKey(text: string, key: string, action: KeyAction): string {
|
|
831
|
+
const { section } = sectionAt(text);
|
|
832
|
+
const member = section?.members[lastMember(section, key)];
|
|
833
|
+
return member ? `${text.slice(0, member.valueStart)}${JSON.stringify(action)}${text.slice(member.valueEnd)}` : text;
|
|
834
|
+
}
|
|
835
|
+
|
|
836
|
+
function removeKey(text: string, key: string): string {
|
|
837
|
+
const { section } = sectionAt(text);
|
|
838
|
+
const index = section ? lastMember(section, key) : -1;
|
|
839
|
+
return section && index >= 0 ? removeMember(text, section, index) : text;
|
|
840
|
+
}
|
|
841
|
+
|
|
842
|
+
// The section Gentle Shell added, once nothing is left in it.
|
|
843
|
+
function removeEmptySection(text: string, created: boolean): string {
|
|
844
|
+
const at = sectionAt(text);
|
|
845
|
+
return created && at.section && at.section.members.length === 0 ? removeMember(text, at.root, at.index) : text;
|
|
846
|
+
}
|
|
847
|
+
|
|
848
|
+
interface KeysConflict {
|
|
849
|
+
key: string;
|
|
850
|
+
theirs: string;
|
|
851
|
+
theirAction: unknown;
|
|
852
|
+
action: KeyAction;
|
|
853
|
+
}
|
|
854
|
+
|
|
855
|
+
interface KeysMerge {
|
|
856
|
+
text: string;
|
|
857
|
+
keys: Omit<KeysState, "written">;
|
|
858
|
+
added: string[];
|
|
859
|
+
conflicts: KeysConflict[];
|
|
860
|
+
}
|
|
861
|
+
|
|
862
|
+
// keys.json text with `shipped` (our layout:gentle-shell entries) merged in.
|
|
863
|
+
// `previous` says which entries are ours from an earlier merge.
|
|
864
|
+
function mergeKeys(original: string, shipped: Record<string, KeyAction>, previous: KeysState | undefined): KeysMerge | { problem: string } {
|
|
865
|
+
const read = readKeysText(original);
|
|
866
|
+
if ("problem" in read) return read;
|
|
867
|
+
let text = original;
|
|
868
|
+
const sectionNow = () => (JSON.parse(text) as Record<string, Record<string, unknown> | undefined>)[DESKTOP_KEYS_SECTION] ?? {};
|
|
869
|
+
const own = (object: Record<string, unknown>, key: string) => (Object.hasOwn(object, key) ? object[key] : undefined);
|
|
870
|
+
const entries: Record<string, KeyAction> = {};
|
|
871
|
+
const dropped = new Set(previous?.dropped ?? []);
|
|
872
|
+
const createdSection = previous ? previous.createdSection : !Object.hasOwn(read.sections, DESKTOP_KEYS_SECTION);
|
|
873
|
+
for (const [key, action] of Object.entries(previous?.entries ?? {})) {
|
|
874
|
+
const value = own(sectionNow(), key);
|
|
875
|
+
if (value === undefined || !sameAction(value, action)) {
|
|
876
|
+
dropped.add(key);
|
|
877
|
+
continue;
|
|
878
|
+
}
|
|
879
|
+
if (!Object.hasOwn(shipped, key)) {
|
|
880
|
+
text = removeKey(text, key);
|
|
881
|
+
continue;
|
|
882
|
+
}
|
|
883
|
+
if (!sameAction(shipped[key], value)) text = replaceKey(text, key, shipped[key]);
|
|
884
|
+
entries[key] = shipped[key];
|
|
885
|
+
}
|
|
886
|
+
const added: string[] = [];
|
|
887
|
+
const conflicts: KeysConflict[] = [];
|
|
888
|
+
for (const [key, action] of Object.entries(shipped)) {
|
|
889
|
+
if (Object.hasOwn(entries, key) || dropped.has(key)) continue;
|
|
890
|
+
const section = sectionNow();
|
|
891
|
+
const theirs = Object.keys(section).find((bound) => normalizeKeystroke(bound) === normalizeKeystroke(key));
|
|
892
|
+
if (theirs !== undefined) {
|
|
893
|
+
if (theirs !== key || !sameAction(section[theirs], action)) conflicts.push({ key, theirs, theirAction: section[theirs], action });
|
|
894
|
+
continue;
|
|
895
|
+
}
|
|
896
|
+
text = addKey(text, key, action);
|
|
897
|
+
entries[key] = action;
|
|
898
|
+
added.push(key);
|
|
899
|
+
}
|
|
900
|
+
text = removeEmptySection(text, createdSection);
|
|
901
|
+
// What we wrote must read back as exactly what we meant.
|
|
902
|
+
const check = readKeysText(text);
|
|
903
|
+
if ("problem" in check || Object.entries(entries).some(([key, action]) => !sameAction(own(sectionNow(), key), action))) {
|
|
904
|
+
return { problem: "could not be merged safely" };
|
|
905
|
+
}
|
|
906
|
+
return { text, keys: { entries, dropped: [...dropped], conflicts: conflicts.map((conflict) => conflict.key), createdSection }, added, conflicts };
|
|
907
|
+
}
|
|
908
|
+
|
|
909
|
+
// keys.json without the entries that are still ours.
|
|
910
|
+
function unmergeKeys(original: string, previous: KeysState): string | { problem: string } {
|
|
911
|
+
const read = readKeysText(original);
|
|
912
|
+
if ("problem" in read) return read;
|
|
913
|
+
const section = read.sections[DESKTOP_KEYS_SECTION] ?? {};
|
|
914
|
+
let text = original;
|
|
915
|
+
for (const [key, action] of Object.entries(previous.entries)) {
|
|
916
|
+
if (Object.hasOwn(section, key) && sameAction(section[key], action)) text = removeKey(text, key);
|
|
917
|
+
}
|
|
918
|
+
return removeEmptySection(text, previous.createdSection);
|
|
919
|
+
}
|
|
920
|
+
|
|
921
|
+
function writeAtomic(file: string, text: string) {
|
|
922
|
+
let mode = 0o644;
|
|
923
|
+
try {
|
|
924
|
+
mode = statSync(file).mode & 0o777;
|
|
925
|
+
} catch {
|
|
926
|
+
// a new file
|
|
927
|
+
}
|
|
928
|
+
const temp = `${file}.gentle-${process.pid}.tmp`;
|
|
929
|
+
writeFileSync(temp, text, { mode });
|
|
930
|
+
renameSync(temp, file);
|
|
931
|
+
}
|
|
932
|
+
|
|
933
|
+
const keysRefusal = (subject: string) => `gentle-shell desktop: ${subject}; it was not changed and the Gentle shortcuts were not added. Fix it and run gentle-shell desktop again.`;
|
|
934
|
+
|
|
935
|
+
// Writes keys.json atomically, the previous file kept in keys-backup.json. A
|
|
936
|
+
// running Herdr reloads it at once: if it writes keys.error, the previous file
|
|
937
|
+
// goes back. Returns why it did not apply, or undefined.
|
|
938
|
+
async function writeKeys(ctx: DesktopContext, paths: DesktopPaths, previousText: string, text: string, running: boolean): Promise<string | undefined> {
|
|
939
|
+
mkdirSync(paths.stateDir, { recursive: true });
|
|
940
|
+
writeAtomic(paths.keysBackup, previousText);
|
|
941
|
+
writeAtomic(paths.keysFile, text);
|
|
942
|
+
if (!running) return undefined;
|
|
943
|
+
for (let attempt = 0; attempt < KEYS_CHECK_ATTEMPTS; attempt += 1) {
|
|
944
|
+
await ctx.io.sleep(KEYS_CHECK_INTERVAL_MS);
|
|
945
|
+
if (existsSync(paths.keysError)) {
|
|
946
|
+
const why = readTextOr(paths.keysError).trim() || "keys.error";
|
|
947
|
+
writeAtomic(paths.keysFile, previousText);
|
|
948
|
+
return why;
|
|
949
|
+
}
|
|
950
|
+
}
|
|
951
|
+
return undefined;
|
|
952
|
+
}
|
|
953
|
+
|
|
954
|
+
function readTextOr(file: string): string {
|
|
955
|
+
try {
|
|
956
|
+
return readFileSync(file, "utf8");
|
|
957
|
+
} catch {
|
|
958
|
+
return "";
|
|
959
|
+
}
|
|
960
|
+
}
|
|
961
|
+
|
|
962
|
+
const isRunning = (ctx: DesktopContext, app: string | undefined) => app !== undefined && windowStatus(ctx, app) !== undefined;
|
|
963
|
+
|
|
964
|
+
// Adds or refreshes our shortcuts in keys.json. "missing": Herdr has not written
|
|
965
|
+
// keys.json yet (it does on its first start), so nothing was done.
|
|
966
|
+
async function syncKeys(ctx: DesktopContext, paths: DesktopPaths, shipped: Record<string, KeyAction>, app: string | undefined): Promise<"missing" | "done" | "failed"> {
|
|
967
|
+
const state = readState(paths);
|
|
968
|
+
if (!state) return "failed";
|
|
969
|
+
if (!existsSync(paths.keysFile)) return "missing";
|
|
970
|
+
const original = readFileSync(paths.keysFile, "utf8");
|
|
971
|
+
const merged = mergeKeys(original, shipped, state.keys);
|
|
972
|
+
if ("problem" in merged) {
|
|
973
|
+
ctx.io.err(keysRefusal(`${paths.keysFile} ${merged.problem}`));
|
|
974
|
+
return "failed";
|
|
975
|
+
}
|
|
976
|
+
const changed = merged.text !== original;
|
|
977
|
+
const running = changed && isRunning(ctx, app);
|
|
978
|
+
if (running && existsSync(paths.keysError)) {
|
|
979
|
+
ctx.io.err(keysRefusal(`Herdr app reports a problem in your ${paths.keysFile} (${readTextOr(paths.keysError).trim()})`));
|
|
980
|
+
return "failed";
|
|
981
|
+
}
|
|
982
|
+
if (changed) {
|
|
983
|
+
if (!state.keys) {
|
|
984
|
+
mkdirSync(join(paths.keysOriginal, ".."), { recursive: true });
|
|
985
|
+
writeAtomic(paths.keysOriginal, original);
|
|
986
|
+
}
|
|
987
|
+
const rejected = await writeKeys(ctx, paths, original, merged.text, running);
|
|
988
|
+
if (rejected !== undefined) {
|
|
989
|
+
if (!state.keys) rmSync(paths.keysOriginal, { force: true });
|
|
990
|
+
cleanOriginals(paths);
|
|
991
|
+
ctx.io.err(`gentle-shell desktop: Herdr app did not accept the Gentle shortcuts (${rejected}); put back the previous ${paths.keysFile}.`);
|
|
992
|
+
return "failed";
|
|
993
|
+
}
|
|
994
|
+
}
|
|
995
|
+
const known = new Set(state.keys?.conflicts ?? []);
|
|
996
|
+
for (const conflict of merged.conflicts) {
|
|
997
|
+
if (known.has(conflict.key)) continue;
|
|
998
|
+
ctx.io.err(`gentle-shell desktop: your ${paths.keysFile} binds ${conflict.theirs} to ${JSON.stringify(conflict.theirAction)} in ${DESKTOP_KEYS_SECTION}; kept yours, so the Gentle shortcut ${conflict.key} (${typeof conflict.action === "string" ? conflict.action : JSON.stringify(conflict.action)}) was not added.`);
|
|
999
|
+
}
|
|
1000
|
+
const written = changed ? sha256Text(merged.text) : state.keys?.written ?? sha256Text(original);
|
|
1001
|
+
const firstWritten = state.keys ? state.keys.firstWritten : changed ? written : undefined;
|
|
1002
|
+
writeState(paths, { ...state, keys: { ...merged.keys, written, ...(firstWritten ? { firstWritten } : {}) } });
|
|
1003
|
+
if (merged.added.length > 0) ctx.io.out(`Added the Gentle shortcuts ${merged.added.join(", ")} to ${paths.keysFile} (${DESKTOP_KEYS_SECTION}); the previous file is in ${paths.keysBackup}.`);
|
|
1004
|
+
else if (changed) ctx.io.out(`Updated the Gentle shortcuts in ${paths.keysFile} (${DESKTOP_KEYS_SECTION}); the previous file is in ${paths.keysBackup}.`);
|
|
1005
|
+
return "done";
|
|
1006
|
+
}
|
|
1007
|
+
|
|
1008
|
+
// Removes the entries that are still ours. Returns false when keys.json could not be changed.
|
|
1009
|
+
async function removeKeys(ctx: DesktopContext, paths: DesktopPaths, keys: KeysState, app: string | undefined): Promise<boolean> {
|
|
1010
|
+
if (!existsSync(paths.keysFile)) {
|
|
1011
|
+
rmSync(paths.keysOriginal, { force: true });
|
|
1012
|
+
return true;
|
|
1013
|
+
}
|
|
1014
|
+
const current = readFileSync(paths.keysFile, "utf8");
|
|
1015
|
+
// Untouched since our first write: the file from before Gentle Shell, byte for byte.
|
|
1016
|
+
const text = sha256Text(current) === keys.firstWritten && existsSync(paths.keysOriginal) ? readFileSync(paths.keysOriginal, "utf8") : unmergeKeys(current, keys);
|
|
1017
|
+
if (typeof text !== "string") {
|
|
1018
|
+
ctx.io.err(`gentle-shell desktop: ${paths.keysFile} ${text.problem}; it was not changed, so the Gentle shortcuts are still in it. Fix it and run gentle-shell desktop --uninstall again.`);
|
|
1019
|
+
return false;
|
|
1020
|
+
}
|
|
1021
|
+
if (text !== current) {
|
|
1022
|
+
const rejected = await writeKeys(ctx, paths, current, text, isRunning(ctx, app));
|
|
1023
|
+
if (rejected !== undefined) {
|
|
1024
|
+
ctx.io.err(`gentle-shell desktop: Herdr app did not accept ${paths.keysFile} without the Gentle shortcuts (${rejected}); put it back as it was.`);
|
|
1025
|
+
return false;
|
|
1026
|
+
}
|
|
1027
|
+
}
|
|
1028
|
+
rmSync(paths.keysOriginal, { force: true });
|
|
1029
|
+
ctx.io.out(`Removed the Gentle shortcuts from ${paths.keysFile}; your own keys are unchanged.`);
|
|
1030
|
+
return true;
|
|
1031
|
+
}
|
|
1032
|
+
|
|
1033
|
+
// --- the Herdr window ------------------------------------------------------------
|
|
1034
|
+
|
|
1035
|
+
function windowStatus(ctx: DesktopContext, app: string): { layout?: string; errors: unknown[] } | undefined {
|
|
1036
|
+
const result = ctx.io.run(app, ["status"], { env: ctx.env });
|
|
1037
|
+
if (result.status !== 0) return undefined;
|
|
1038
|
+
try {
|
|
1039
|
+
const parsed = JSON.parse(result.stdout);
|
|
1040
|
+
return { ...(typeof parsed?.layout === "string" ? { layout: parsed.layout } : {}), errors: Array.isArray(parsed?.errors) ? parsed.errors : [] };
|
|
1041
|
+
} catch {
|
|
1042
|
+
return { errors: [] };
|
|
1043
|
+
}
|
|
1044
|
+
}
|
|
1045
|
+
|
|
1046
|
+
async function ensureWindow(ctx: DesktopContext, app: string) {
|
|
1047
|
+
const running = windowStatus(ctx, app);
|
|
1048
|
+
if (running) return running;
|
|
1049
|
+
ctx.io.out("Starting Herdr app ...");
|
|
1050
|
+
ctx.io.spawnDetached(app, [], { env: ctx.env, cwd: ctx.cwd });
|
|
1051
|
+
for (let attempt = 0; attempt < START_ATTEMPTS; attempt += 1) {
|
|
1052
|
+
await ctx.io.sleep(START_INTERVAL_MS);
|
|
1053
|
+
const status = windowStatus(ctx, app);
|
|
1054
|
+
if (status) return status;
|
|
1055
|
+
}
|
|
1056
|
+
return undefined;
|
|
1057
|
+
}
|
|
1058
|
+
|
|
1059
|
+
function sameFolder(a: unknown, b: string): boolean {
|
|
1060
|
+
if (typeof a !== "string") return false;
|
|
1061
|
+
const real = (path: string) => {
|
|
1062
|
+
try {
|
|
1063
|
+
return realpathSync(path);
|
|
1064
|
+
} catch {
|
|
1065
|
+
return path;
|
|
1066
|
+
}
|
|
1067
|
+
};
|
|
1068
|
+
return real(a) === real(b);
|
|
1069
|
+
}
|
|
1070
|
+
|
|
1071
|
+
function hasGentleSpace(listing: unknown, cwd: string): boolean {
|
|
1072
|
+
const spaces = (listing as { spaces?: unknown })?.spaces;
|
|
1073
|
+
if (!Array.isArray(spaces)) return false;
|
|
1074
|
+
return spaces.some((space) => sameFolder(space?.folder, cwd) && Array.isArray(space?.tabs)
|
|
1075
|
+
&& space.tabs.some((tab: { terminals?: unknown }) => Array.isArray(tab?.terminals) && tab.terminals.some((terminal: { app?: unknown }) => terminal?.app === "gentle-shell")));
|
|
1076
|
+
}
|
|
1077
|
+
|
|
1078
|
+
function herdrDo(ctx: DesktopContext, app: string, command: string, payload: Record<string, unknown>): RunResult {
|
|
1079
|
+
return ctx.io.run(app, ["do", command, JSON.stringify(payload)], { env: ctx.env, cwd: ctx.cwd });
|
|
1080
|
+
}
|
|
1081
|
+
|
|
1082
|
+
const keysDeferred = (paths: DesktopPaths) => `Herdr writes ${paths.keysFile} when its window first opens; the Gentle shortcuts are added the next time gentle-shell desktop opens Herdr.`;
|
|
1083
|
+
|
|
1084
|
+
async function openDesktop(ctx: DesktopContext, paths: DesktopPaths, app: string, keys: Record<string, KeyAction> | undefined): Promise<number> {
|
|
1085
|
+
const status = await ensureWindow(ctx, app);
|
|
1086
|
+
if (!status) {
|
|
1087
|
+
ctx.io.err("gentle-shell desktop: Herdr app did not open its window. Open Herdr (it may ask to set up herdr-core), then run gentle-shell desktop again.");
|
|
1088
|
+
return 1;
|
|
1089
|
+
}
|
|
1090
|
+
// Shortcuts waiting for the keys.json Herdr writes on its first start.
|
|
1091
|
+
if (keys) {
|
|
1092
|
+
for (let attempt = 0; attempt < KEYS_WAIT_ATTEMPTS && !existsSync(paths.keysFile); attempt += 1) await ctx.io.sleep(START_INTERVAL_MS);
|
|
1093
|
+
if ((await syncKeys(ctx, paths, keys, app)) === "missing") ctx.io.out(keysDeferred(paths));
|
|
1094
|
+
}
|
|
1095
|
+
const state = readState(paths);
|
|
1096
|
+
if (state && status.layout && status.layout !== DESKTOP_LAYOUT && state.previousLayout !== status.layout) {
|
|
1097
|
+
writeState(paths, { ...state, previousLayout: status.layout });
|
|
1098
|
+
}
|
|
1099
|
+
const switched = herdrDo(ctx, app, "layout.switch", { name: DESKTOP_LAYOUT });
|
|
1100
|
+
if (switched.status !== 0) {
|
|
1101
|
+
ctx.io.err(`gentle-shell desktop: Herdr app could not switch to the ${DESKTOP_LAYOUT} layout: ${`${switched.stderr}${switched.stdout}`.trim() || `exit ${switched.status}`}`);
|
|
1102
|
+
return 1;
|
|
1103
|
+
}
|
|
1104
|
+
const listed = ctx.io.run(app, ["ls"], { env: ctx.env });
|
|
1105
|
+
let listing: unknown;
|
|
1106
|
+
try {
|
|
1107
|
+
listing = JSON.parse(listed.stdout);
|
|
1108
|
+
} catch {
|
|
1109
|
+
listing = undefined;
|
|
1110
|
+
}
|
|
1111
|
+
if (listed.status === 0 && !hasGentleSpace(listing, ctx.cwd)) {
|
|
1112
|
+
const created = herdrDo(ctx, app, "space.new", { folder: ctx.cwd, argv: ["gentle-shell"] });
|
|
1113
|
+
if (created.status !== 0) ctx.io.err(`gentle-shell desktop: could not open a Gentle Shell space in ${ctx.cwd}: ${`${created.stderr}${created.stdout}`.trim()}`);
|
|
1114
|
+
}
|
|
1115
|
+
const after = windowStatus(ctx, app);
|
|
1116
|
+
if (after && after.errors.length > 0) ctx.io.err(`gentle-shell desktop: Herdr app reports: ${JSON.stringify(after.errors)}`);
|
|
1117
|
+
ctx.io.out(`Herdr app is showing the ${DESKTOP_LAYOUT} layout.`);
|
|
1118
|
+
return 0;
|
|
1119
|
+
}
|
|
1120
|
+
|
|
1121
|
+
// --- commands ----------------------------------------------------------------------
|
|
1122
|
+
|
|
1123
|
+
function printStatus(ctx: DesktopContext, paths: DesktopPaths, assets: Assets | { error: string }, release: HerdrAppRelease): number {
|
|
1124
|
+
const app = detectApp(ctx);
|
|
1125
|
+
const shipped = "mods" in assets ? assets.mods : [];
|
|
1126
|
+
const installed = (readState(paths)?.mods ?? []).concat(shipped).filter((mod, index, all) => all.indexOf(mod) === index && existsSync(join(paths.mods, mod))).sort();
|
|
1127
|
+
const missing = shipped.filter((mod) => !installed.includes(mod));
|
|
1128
|
+
const window = app ? windowStatus(ctx, app.path) : undefined;
|
|
1129
|
+
const needs = `needs ${release.version} or newer`;
|
|
1130
|
+
ctx.io.out("Gentle Shell Desktop");
|
|
1131
|
+
ctx.io.out(` Gentle Shell: ${ctx.shellVersion}`);
|
|
1132
|
+
ctx.io.out(app ? ` Herdr app: ${app.version ?? "unknown version"} at ${app.path} (${needs})` : ` Herdr app: not installed (${needs})`);
|
|
1133
|
+
ctx.io.out(` Herdr home: ${paths.herdrHome}`);
|
|
1134
|
+
ctx.io.out(existsSync(paths.layoutFile) ? ` Layout ${DESKTOP_LAYOUT}: installed at ${paths.layoutFile}` : ` Layout ${DESKTOP_LAYOUT}: not installed`);
|
|
1135
|
+
const themes = "mods" in assets ? assets.themes : [];
|
|
1136
|
+
if (themes.length > 0) {
|
|
1137
|
+
const present = themes.filter((name) => existsSync(join(paths.themes, name)));
|
|
1138
|
+
ctx.io.out(present.length === 0 ? ` Themes: none installed (ships ${themes.join(", ")})` : ` Themes: ${present.join(", ")} installed in ${paths.themes}${present.length < themes.length ? `; missing ${themes.filter((name) => !present.includes(name)).join(", ")}` : ""}`);
|
|
1139
|
+
}
|
|
1140
|
+
if (installed.length === 0) ctx.io.out(` Mods: none installed (ships ${shipped.join(", ")})`);
|
|
1141
|
+
else ctx.io.out(` Mods: ${installed.join(", ")} installed in ${paths.mods}${missing.length > 0 ? `; missing ${missing.join(", ")}` : ""}`);
|
|
1142
|
+
if ("mods" in assets && assets.keys) {
|
|
1143
|
+
const keys = readState(paths)?.keys;
|
|
1144
|
+
ctx.io.out(keys ? ` Keys: ${Object.keys(keys.entries).length} Gentle shortcuts in ${paths.keysFile} (${DESKTOP_KEYS_SECTION})` : " Keys: Gentle shortcuts not added");
|
|
1145
|
+
}
|
|
1146
|
+
ctx.io.out(window ? ` Window: running, layout ${window.layout ?? "unknown"}` : " Window: not running");
|
|
1147
|
+
return 0;
|
|
1148
|
+
}
|
|
1149
|
+
|
|
1150
|
+
async function uninstall(ctx: DesktopContext, paths: DesktopPaths): Promise<number> {
|
|
1151
|
+
const state = readState(paths);
|
|
1152
|
+
const ours = (state?.mods ?? []).filter((mod) => existsSync(join(paths.mods, mod)));
|
|
1153
|
+
const layoutOurs = state?.layout === true && existsSync(paths.layoutFile);
|
|
1154
|
+
const themesOurs = (state?.themes ?? []).filter((name) => existsSync(join(paths.themes, name)));
|
|
1155
|
+
if (ours.length === 0 && !layoutOurs && themesOurs.length === 0 && !state?.keys) {
|
|
1156
|
+
rmSync(paths.stateFile, { force: true });
|
|
1157
|
+
ctx.io.out(`Gentle Shell Desktop mods and layout are not installed in ${paths.herdrHome}; nothing to remove.`);
|
|
1158
|
+
return 0;
|
|
1159
|
+
}
|
|
1160
|
+
const app = detectApp(ctx);
|
|
1161
|
+
const keysKept = state?.keys && !(await removeKeys(ctx, paths, state.keys, app?.path)) ? state.keys : undefined;
|
|
1162
|
+
const restored: string[] = [];
|
|
1163
|
+
if (ours.length > 0 || layoutOurs || themesOurs.length > 0) {
|
|
1164
|
+
prepareScratch(paths);
|
|
1165
|
+
rmSync(paths.stage, { recursive: true, force: true });
|
|
1166
|
+
const putBack = (kind: "mods" | "layouts" | "themes", name: string, target: string) => {
|
|
1167
|
+
const original = join(paths.originals, kind, name);
|
|
1168
|
+
if (!existsSync(original) && !isSymlink(original)) return;
|
|
1169
|
+
moveSync(original, target);
|
|
1170
|
+
restored.push(kind === "mods" ? `mods ${name}` : kind === "themes" ? `theme ${name}` : `layout ${DESKTOP_LAYOUT}`);
|
|
1171
|
+
};
|
|
1172
|
+
for (const mod of ours) {
|
|
1173
|
+
moveSync(join(paths.mods, mod), join(paths.backupNext, "mods", mod));
|
|
1174
|
+
putBack("mods", mod, join(paths.mods, mod));
|
|
1175
|
+
}
|
|
1176
|
+
if (layoutOurs) {
|
|
1177
|
+
moveSync(paths.layoutFile, join(paths.backupNext, "layouts", `${DESKTOP_LAYOUT}.json`));
|
|
1178
|
+
putBack("layouts", `${DESKTOP_LAYOUT}.json`, paths.layoutFile);
|
|
1179
|
+
}
|
|
1180
|
+
for (const name of themesOurs) {
|
|
1181
|
+
moveSync(join(paths.themes, name), join(paths.backupNext, "themes", name));
|
|
1182
|
+
putBack("themes", name, join(paths.themes, name));
|
|
1183
|
+
}
|
|
1184
|
+
promoteBackup(paths);
|
|
1185
|
+
}
|
|
1186
|
+
cleanOriginals(paths);
|
|
1187
|
+
// Shortcuts that could not be removed stay recorded, so a later --uninstall still finds them.
|
|
1188
|
+
if (keysKept) writeState(paths, { mods: [], layout: false, keys: keysKept });
|
|
1189
|
+
else rmSync(paths.stateFile, { force: true });
|
|
1190
|
+
if (ours.length === 0 && !layoutOurs && themesOurs.length === 0) return keysKept ? 1 : 0;
|
|
1191
|
+
const window = app ? windowStatus(ctx, app.path) : undefined;
|
|
1192
|
+
if (app && window?.layout === DESKTOP_LAYOUT) {
|
|
1193
|
+
const back = state?.previousLayout ?? "main";
|
|
1194
|
+
const switched = herdrDo(ctx, app.path, "layout.switch", { name: back });
|
|
1195
|
+
if (switched.status !== 0) ctx.io.err(`gentle-shell desktop: could not switch Herdr app back to the ${back} layout; choose another layout in Herdr.`);
|
|
1196
|
+
}
|
|
1197
|
+
ctx.io.out(`Removed Gentle Shell Desktop ${themesOurs.length > 0 ? "mods, layout and themes" : "mods and layout"} from ${paths.herdrHome}; a copy is in ${paths.backup}. Herdr app itself stays installed.`);
|
|
1198
|
+
if (restored.length > 0) ctx.io.out(`Put back what was there before Gentle Shell Desktop: ${restored.join(", ")} in ${paths.herdrHome}.`);
|
|
1199
|
+
return keysKept ? 1 : 0;
|
|
1200
|
+
}
|
|
1201
|
+
|
|
1202
|
+
// "mods a, b and layout gentle-shell", or with themes "mods a, b, layout gentle-shell and themes x, y".
|
|
1203
|
+
const assetsText = (assets: Assets) => (assets.themes.length > 0
|
|
1204
|
+
? `mods ${assets.mods.join(", ")}, layout ${DESKTOP_LAYOUT} and themes ${assets.themes.join(", ")}`
|
|
1205
|
+
: `mods ${assets.mods.join(", ")} and layout ${DESKTOP_LAYOUT}`);
|
|
1206
|
+
|
|
1207
|
+
async function refresh(ctx: DesktopContext, paths: DesktopPaths, assets: Assets | { error: string }): Promise<number> {
|
|
1208
|
+
const state = readState(paths);
|
|
1209
|
+
if (!state) return 0;
|
|
1210
|
+
if ("error" in assets) {
|
|
1211
|
+
ctx.io.err(`gentle-shell desktop: ${assets.error}`);
|
|
1212
|
+
return 1;
|
|
1213
|
+
}
|
|
1214
|
+
const app = detectApp(ctx);
|
|
1215
|
+
if (!app) {
|
|
1216
|
+
ctx.io.err("gentle-shell desktop: Herdr app is not installed, so the Gentle mods were not refreshed; run gentle-shell desktop.");
|
|
1217
|
+
return 1;
|
|
1218
|
+
}
|
|
1219
|
+
if (!assetsUpToDate(assets, paths) || !(state.mods ?? []).every((mod) => assets.mods.includes(mod)) || !(state.themes ?? []).every((name) => assets.themes.includes(name))) {
|
|
1220
|
+
const failure = installAssets(ctx, paths, assets, app.path, state);
|
|
1221
|
+
if (failure !== undefined) {
|
|
1222
|
+
ctx.io.err(`gentle-shell desktop: ${failure}`);
|
|
1223
|
+
return 1;
|
|
1224
|
+
}
|
|
1225
|
+
writeState(paths, { ...state, mods: assets.mods, themes: assets.themes, layout: true });
|
|
1226
|
+
ctx.io.out(`Gentle Shell Desktop: refreshed ${assetsText(assets)} in ${paths.herdrHome}.`);
|
|
1227
|
+
}
|
|
1228
|
+
// Only shortcuts the person already accepted with gentle-shell desktop are refreshed.
|
|
1229
|
+
if (assets.keys && state.keys) await syncKeys(ctx, paths, assets.keys, app.path);
|
|
1230
|
+
return 0;
|
|
1231
|
+
}
|
|
1232
|
+
|
|
1233
|
+
export async function runDesktop(ctx: DesktopContext): Promise<number> {
|
|
1234
|
+
const parsed = parseDesktopArgs(ctx.args);
|
|
1235
|
+
if ("error" in parsed) {
|
|
1236
|
+
ctx.io.err(`gentle-shell desktop: ${parsed.error}`);
|
|
1237
|
+
ctx.io.err(desktopUsage());
|
|
1238
|
+
return 2;
|
|
1239
|
+
}
|
|
1240
|
+
if (parsed.action === "help") {
|
|
1241
|
+
ctx.io.out(desktopUsage());
|
|
1242
|
+
return 0;
|
|
1243
|
+
}
|
|
1244
|
+
const release = ctx.release ?? HERDR_APP_RELEASE;
|
|
1245
|
+
const paths = desktopPaths(ctx.env, ctx.home);
|
|
1246
|
+
const assets = shippedAssets(ctx.packageRoot);
|
|
1247
|
+
if (parsed.action === "status") return printStatus(ctx, paths, assets, release);
|
|
1248
|
+
if (parsed.action === "uninstall") return await uninstall(ctx, paths);
|
|
1249
|
+
if (parsed.action === "refresh") return await refresh(ctx, paths, assets);
|
|
1250
|
+
if ("error" in assets) {
|
|
1251
|
+
ctx.io.err(`gentle-shell desktop: ${assets.error}`);
|
|
1252
|
+
return 1;
|
|
1253
|
+
}
|
|
1254
|
+
|
|
1255
|
+
const installed = detectApp(ctx);
|
|
1256
|
+
const planned = planApp(ctx, installed, release);
|
|
1257
|
+
if (planned && "error" in planned) {
|
|
1258
|
+
ctx.io.err(`gentle-shell desktop: ${planned.error}`);
|
|
1259
|
+
return 1;
|
|
1260
|
+
}
|
|
1261
|
+
const appPlan = planned as AppPlan | undefined;
|
|
1262
|
+
const previous = readState(paths);
|
|
1263
|
+
const assetsNeeded = !previous || !assetsUpToDate(assets, paths);
|
|
1264
|
+
// Never merged yet: asked for with the rest. A keys.json Herdr has not written yet is
|
|
1265
|
+
// merged once the window opens (and with --no-open, the next time it does).
|
|
1266
|
+
const keysNeeded = assets.keys !== undefined && !previous?.keys && (parsed.open || existsSync(paths.keysFile));
|
|
1267
|
+
if (appPlan || assetsNeeded || keysNeeded) {
|
|
1268
|
+
ctx.io.out("Gentle Shell Desktop will:");
|
|
1269
|
+
if (appPlan) {
|
|
1270
|
+
const where = `${appPlan.destination} and link ${appPlan.link}`;
|
|
1271
|
+
ctx.io.out(appPlan.replaces
|
|
1272
|
+
? ` - replace Herdr app ${appPlan.replaces.version ?? "(unknown version)"} at ${appPlan.replaces.path} with ${release.version} (${appPlan.target}) into ${where}`
|
|
1273
|
+
: ` - install Herdr app ${release.version} (${appPlan.target}) into ${where}`);
|
|
1274
|
+
ctx.io.out(` from ${appPlan.url}`);
|
|
1275
|
+
ctx.io.out(` verified against SHA-256 ${appPlan.sha256} (pinned by Gentle Shell ${ctx.shellVersion})`);
|
|
1276
|
+
}
|
|
1277
|
+
if (assetsNeeded) {
|
|
1278
|
+
ctx.io.out(` - install mods ${assets.mods.join(", ")} into ${paths.mods}`);
|
|
1279
|
+
ctx.io.out(` - install layout ${DESKTOP_LAYOUT} into ${paths.layoutFile}`);
|
|
1280
|
+
if (assets.themes.length > 0) ctx.io.out(` - install its light and dark themes ${assets.themes.join(", ")} into ${paths.themes}`);
|
|
1281
|
+
ctx.io.out(` - check each mod with herdr-app check before installing anything`);
|
|
1282
|
+
ctx.io.out(` - keep anything Gentle Shell did not install at those paths in ${paths.originals}, put back by --uninstall`);
|
|
1283
|
+
ctx.io.out(` - keep our own previous copy in ${paths.backup}`);
|
|
1284
|
+
}
|
|
1285
|
+
if (keysNeeded) {
|
|
1286
|
+
ctx.io.out(` - add the Gentle shortcuts (${DESKTOP_KEYS_SECTION}) to ${paths.keysFile}, keeping every key you already use`);
|
|
1287
|
+
ctx.io.out(` a key you already bind there stays yours; --uninstall removes exactly ours`);
|
|
1288
|
+
}
|
|
1289
|
+
if (assetsNeeded || keysNeeded) {
|
|
1290
|
+
ctx.io.out(` Your other mods, layouts, keys and settings in ${paths.herdrHome} are not touched.`);
|
|
1291
|
+
}
|
|
1292
|
+
if (!parsed.yes) {
|
|
1293
|
+
if (!ctx.interactive) {
|
|
1294
|
+
ctx.io.err("gentle-shell desktop: nothing was installed. Run it in an interactive terminal to confirm, or pass --yes.");
|
|
1295
|
+
return 1;
|
|
1296
|
+
}
|
|
1297
|
+
const answer = (await ctx.io.ask("Install Gentle Shell Desktop as shown above? [y/N] ")).trim().toLowerCase();
|
|
1298
|
+
if (answer !== "y" && answer !== "yes") {
|
|
1299
|
+
ctx.io.err("gentle-shell desktop: nothing was installed.");
|
|
1300
|
+
return 1;
|
|
1301
|
+
}
|
|
1302
|
+
}
|
|
1303
|
+
}
|
|
1304
|
+
|
|
1305
|
+
let app = installed?.path;
|
|
1306
|
+
if (appPlan) {
|
|
1307
|
+
try {
|
|
1308
|
+
app = await installApp(ctx, paths, appPlan);
|
|
1309
|
+
} catch (error) {
|
|
1310
|
+
ctx.io.err(`gentle-shell desktop: ${(error as Error).message}`);
|
|
1311
|
+
return 1;
|
|
1312
|
+
}
|
|
1313
|
+
ctx.io.out(`Installed Herdr app ${release.version} at ${appPlan.destination}.`);
|
|
1314
|
+
if (!findOnPath("herdr-core", ctx.env, ctx.platform) && !existsSync(join(paths.localBin, "herdr-core"))) {
|
|
1315
|
+
ctx.io.out("Herdr app sets up herdr-core (the terminal runtime) itself when it opens.");
|
|
1316
|
+
}
|
|
1317
|
+
}
|
|
1318
|
+
if (!app) {
|
|
1319
|
+
ctx.io.err("gentle-shell desktop: Herdr app is not available.");
|
|
1320
|
+
return 1;
|
|
1321
|
+
}
|
|
1322
|
+
if (assetsNeeded) {
|
|
1323
|
+
const failure = installAssets(ctx, paths, assets, app, previous);
|
|
1324
|
+
if (failure !== undefined) {
|
|
1325
|
+
ctx.io.err(`gentle-shell desktop: ${failure}`);
|
|
1326
|
+
return 1;
|
|
1327
|
+
}
|
|
1328
|
+
writeState(paths, { mods: assets.mods, themes: assets.themes, layout: true, ...(previous?.previousLayout ? { previousLayout: previous.previousLayout } : {}), ...(previous?.keys ? { keys: previous.keys } : {}) });
|
|
1329
|
+
ctx.io.out(`Installed ${assetsText(assets)} in ${paths.herdrHome}.`);
|
|
1330
|
+
} else {
|
|
1331
|
+
ctx.io.out("Gentle Shell Desktop is up to date.");
|
|
1332
|
+
}
|
|
1333
|
+
const keysPending = assets.keys !== undefined && (await syncKeys(ctx, paths, assets.keys, app)) === "missing";
|
|
1334
|
+
if (!parsed.open) {
|
|
1335
|
+
if (keysPending) ctx.io.out(keysDeferred(paths));
|
|
1336
|
+
return 0;
|
|
1337
|
+
}
|
|
1338
|
+
return openDesktop(ctx, paths, app, keysPending ? assets.keys : undefined);
|
|
1339
|
+
}
|
|
1340
|
+
|
|
1341
|
+
// --- the real process --------------------------------------------------------------
|
|
1342
|
+
|
|
1343
|
+
export function nodeDesktopIO(): Omit<DesktopIO, "ask" | "out" | "err"> {
|
|
1344
|
+
const run: DesktopIO["run"] = (command, args, options) => {
|
|
1345
|
+
const result = spawnSync(command, args, { env: options.env, cwd: options.cwd, encoding: "utf8", timeout: 10 * 60_000, stdio: ["ignore", "pipe", "pipe"] });
|
|
1346
|
+
return { status: result.status, stdout: result.stdout ?? "", stderr: result.stderr ?? "", ...(result.error ? { error: result.error } : {}) };
|
|
1347
|
+
};
|
|
1348
|
+
return {
|
|
1349
|
+
run,
|
|
1350
|
+
spawnDetached: (command, args, options) => {
|
|
1351
|
+
const child = spawn(command, args, { env: options.env, cwd: options.cwd, detached: true, stdio: "ignore" });
|
|
1352
|
+
child.on("error", () => {});
|
|
1353
|
+
child.unref();
|
|
1354
|
+
},
|
|
1355
|
+
// curl, as the official installer uses; the pinned SHA-256 is what is trusted.
|
|
1356
|
+
download: async (url, file) => {
|
|
1357
|
+
const result = run("curl", ["-fsSL", "--retry", "2", "-o", file, url], { env: process.env });
|
|
1358
|
+
if (result.status !== 0) throw new Error(`download of ${url} failed: ${result.stderr.trim() || result.error?.message || `curl exit ${result.status}`}`);
|
|
1359
|
+
},
|
|
1360
|
+
sha256: (file) => createHash("sha256").update(readFileSync(file)).digest("hex"),
|
|
1361
|
+
// The official installer's rule for release builds: a Developer ID signature that verifies.
|
|
1362
|
+
verifyMacSignature: (app) => {
|
|
1363
|
+
const info = run("/usr/bin/codesign", ["-dvv", app], { env: process.env });
|
|
1364
|
+
if (!/^Authority=Developer ID Application:/m.test(`${info.stderr}${info.stdout}`)) return `no Developer ID signature (${info.stderr.trim() || info.error?.message || "codesign failed"})`;
|
|
1365
|
+
const verify = run("/usr/bin/codesign", ["--verify", "--deep", "--strict", app], { env: process.env });
|
|
1366
|
+
return verify.status === 0 ? undefined : `invalid signature: ${verify.stderr.trim()}`;
|
|
1367
|
+
},
|
|
1368
|
+
sleep: (ms) => new Promise((resolve) => setTimeout(resolve, ms)),
|
|
1369
|
+
};
|
|
1370
|
+
}
|