gentle-pi 4.8.0 → 4.9.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +60 -0
- package/assets/agents/gentle-ai-explore.md +1 -1
- package/assets/agents/gentle-ai-verify.md +1 -1
- package/assets/agents/gentle-ai-worker.md +10 -9
- package/assets/design-canvas/canvas-boards.js +22 -2
- package/assets/design-canvas/canvas-boot.js +3 -1
- package/assets/design-canvas/canvas-i18n-es.js +5 -0
- package/assets/design-canvas/canvas-menu.js +13 -7
- package/assets/design-canvas/canvas-messages.js +1 -1
- package/assets/design-canvas/canvas-rail.js +5 -2
- package/assets/design-canvas/canvas-store.js +3 -0
- package/assets/design-canvas/canvas-theme.js +69 -0
- package/assets/design-canvas/canvas.css +27 -2
- package/assets/design-canvas/index.html +3 -0
- package/assets/design-canvas/inspector.js +28 -5
- package/assets/design-canvas/theme-early.js +10 -0
- package/assets/migrations/agent-body-history.json +6 -0
- package/assets/orchestrator-delegation.md +1 -5
- package/assets/orchestrator-full-delegation-card.md +9 -13
- package/assets/orchestrator-full-delegation.md +2 -2
- package/assets/orchestrator-memory.md +2 -2
- package/assets/orchestrator-prompts.md +3 -31
- package/assets/orchestrator-tracking.md +6 -6
- package/assets/orchestrator-verification.md +4 -4
- package/assets/orchestrator-writer.md +12 -12
- package/assets/orchestrator.md +2 -2
- package/bin/gentle-shell.mjs +77 -1
- package/contracts/review-provider-contract-mirror/provider-contract.lock.json +7 -7
- package/contracts/review-provider-contract-mirror/{v1.5.0 → v1.6.0}/bundle/manifest.json +3 -3
- package/contracts/review-provider-contract-mirror/{v1.5.0 → v1.6.0}/bundle/orchestration/pi.md +1 -1
- package/contracts/review-provider-contract-mirror/{v1.5.0 → v1.6.0}/bundle/routing/pi.md +10 -10
- package/contracts/review-provider-contract-mirror/{v1.5.0 → v1.6.0}/generated/provider-capabilities.baseline.json +3 -3
- package/contracts/review-provider-contract-mirror/{v1.5.0 → v1.6.0}/generated/provider-roles.baseline.json +1 -1
- package/docs/assets/features/gentle-tower.png +0 -0
- package/docs/auto-permission-answers.md +1 -1
- package/docs/bundled-install.md +1 -1
- package/docs/delegated-verification.md +6 -4
- package/docs/desktop-feed.md +303 -0
- package/docs/desktop-rpc.md +703 -25
- package/docs/fast-mode.md +2 -2
- package/docs/gentle-shell-desktop.md +465 -0
- package/docs/gentle-shell.md +65 -3
- package/docs/images/desktop/chat.png +0 -0
- package/docs/images/desktop/palette.png +0 -0
- package/docs/images/desktop/todo.png +0 -0
- package/docs/install-wizard.md +1 -1
- package/docs/odd-preparation-continuity.md +1 -1
- package/docs/readme-reference.md +44 -15
- package/docs/work-continuity.md +10 -7
- package/extensions/ask-user-choice.ts +36 -18
- package/extensions/ask-user-question.ts +47 -8
- package/extensions/gentle-agents.ts +206 -37
- package/extensions/gentle-ai.ts +234 -24
- package/extensions/gentle-desktop-feed.ts +778 -0
- package/extensions/gentle-desktop-rpc.ts +145 -12
- package/extensions/gentle-herdr-desktop-status.ts +275 -0
- package/extensions/gentle-shell.ts +69 -7
- package/extensions/gentle-stats.ts +30 -1
- package/extensions/gentle-tower.ts +305 -0
- package/extensions/skill-registry.ts +13 -3
- package/herdr/RECIPE.md +157 -0
- package/herdr/keys.json +14 -0
- package/herdr/layouts/gentle-shell.json +202 -0
- package/herdr/mods/gentle-agents/icons/kind-herdr.svg +1 -0
- package/herdr/mods/gentle-agents/icons/kind-remote.svg +1 -0
- package/herdr/mods/gentle-agents/icons/kind-tui.svg +1 -0
- package/herdr/mods/gentle-agents/main.js +190 -0
- package/herdr/mods/gentle-agents/mod.json +1 -0
- package/herdr/mods/gentle-agents/snapshot.js +469 -0
- package/herdr/mods/gentle-agents/tokens.js +273 -0
- package/herdr/mods/gentle-chat/MINIMAL.md +69 -0
- package/herdr/mods/gentle-chat/actions.js +180 -0
- package/herdr/mods/gentle-chat/feed.js +321 -0
- package/herdr/mods/gentle-chat/icons/branch.svg +1 -0
- package/herdr/mods/gentle-chat/icons/chat.svg +1 -0
- package/herdr/mods/gentle-chat/icons/check.svg +1 -0
- package/herdr/mods/gentle-chat/icons/chev.svg +1 -0
- package/herdr/mods/gentle-chat/icons/clip.svg +1 -0
- package/herdr/mods/gentle-chat/icons/down.svg +1 -0
- package/herdr/mods/gentle-chat/icons/folder.svg +1 -0
- package/herdr/mods/gentle-chat/icons/kind-herdr.svg +1 -0
- package/herdr/mods/gentle-chat/icons/kind-remote.svg +1 -0
- package/herdr/mods/gentle-chat/icons/kind-tui.svg +1 -0
- package/herdr/mods/gentle-chat/icons/mark.svg +1 -0
- package/herdr/mods/gentle-chat/icons/send.svg +1 -0
- package/herdr/mods/gentle-chat/icons/shield.svg +1 -0
- package/herdr/mods/gentle-chat/icons/stop.svg +1 -0
- package/herdr/mods/gentle-chat/icons/term.svg +1 -0
- package/herdr/mods/gentle-chat/icons/user.svg +1 -0
- package/herdr/mods/gentle-chat/icons/x.svg +1 -0
- package/herdr/mods/gentle-chat/main.js +968 -0
- package/herdr/mods/gentle-chat/mod.json +1 -0
- package/herdr/mods/gentle-chat/session.js +212 -0
- package/herdr/mods/gentle-chat/snapshot.js +469 -0
- package/herdr/mods/gentle-chat/tokens.js +137 -0
- package/herdr/mods/gentle-chat/ui.js +883 -0
- package/herdr/mods/gentle-confirm/main.js +60 -0
- package/herdr/mods/gentle-confirm/mod.json +1 -0
- package/herdr/mods/gentle-inspector/actions.js +180 -0
- package/herdr/mods/gentle-inspector/icons/bolt.svg +1 -0
- package/herdr/mods/gentle-inspector/icons/bot.svg +1 -0
- package/herdr/mods/gentle-inspector/icons/check.svg +1 -0
- package/herdr/mods/gentle-inspector/icons/db.svg +1 -0
- package/herdr/mods/gentle-inspector/icons/diff.svg +1 -0
- package/herdr/mods/gentle-inspector/icons/jobs.svg +1 -0
- package/herdr/mods/gentle-inspector/icons/plug.svg +1 -0
- package/herdr/mods/gentle-inspector/icons/review.svg +1 -0
- package/herdr/mods/gentle-inspector/icons/stats.svg +1 -0
- package/herdr/mods/gentle-inspector/icons/stop.svg +1 -0
- package/herdr/mods/gentle-inspector/icons/todo.svg +1 -0
- package/herdr/mods/gentle-inspector/main.js +500 -0
- package/herdr/mods/gentle-inspector/mod.json +1 -0
- package/herdr/mods/gentle-inspector/snapshot.js +469 -0
- package/herdr/mods/gentle-inspector/tokens.js +273 -0
- package/herdr/mods/gentle-palette/actions.js +180 -0
- package/herdr/mods/gentle-palette/icons/bolt.svg +1 -0
- package/herdr/mods/gentle-palette/icons/bot.svg +1 -0
- package/herdr/mods/gentle-palette/icons/chat.svg +1 -0
- package/herdr/mods/gentle-palette/icons/check.svg +1 -0
- package/herdr/mods/gentle-palette/icons/cmd.svg +1 -0
- package/herdr/mods/gentle-palette/icons/diff.svg +1 -0
- package/herdr/mods/gentle-palette/icons/jobs.svg +1 -0
- package/herdr/mods/gentle-palette/icons/plus.svg +1 -0
- package/herdr/mods/gentle-palette/icons/review.svg +1 -0
- package/herdr/mods/gentle-palette/icons/search.svg +1 -0
- package/herdr/mods/gentle-palette/icons/shield.svg +1 -0
- package/herdr/mods/gentle-palette/icons/stats.svg +1 -0
- package/herdr/mods/gentle-palette/icons/stop.svg +1 -0
- package/herdr/mods/gentle-palette/icons/term.svg +1 -0
- package/herdr/mods/gentle-palette/icons/todo.svg +1 -0
- package/herdr/mods/gentle-palette/main.js +333 -0
- package/herdr/mods/gentle-palette/mod.json +1 -0
- package/herdr/mods/gentle-palette/snapshot.js +469 -0
- package/herdr/mods/gentle-palette/tokens.js +273 -0
- package/herdr/mods/gentle-pane/icons/chat.svg +1 -0
- package/herdr/mods/gentle-pane/icons/close.svg +1 -0
- package/herdr/mods/gentle-pane/icons/kind-herdr.svg +1 -0
- package/herdr/mods/gentle-pane/icons/kind-remote.svg +1 -0
- package/herdr/mods/gentle-pane/icons/kind-tui.svg +1 -0
- package/herdr/mods/gentle-pane/icons/split-down.svg +1 -0
- package/herdr/mods/gentle-pane/icons/split-right.svg +1 -0
- package/herdr/mods/gentle-pane/icons/term.svg +1 -0
- package/herdr/mods/gentle-pane/icons/unzoom.svg +1 -0
- package/herdr/mods/gentle-pane/icons/zoom.svg +1 -0
- package/herdr/mods/gentle-pane/main.js +91 -0
- package/herdr/mods/gentle-pane/mod.json +1 -0
- package/herdr/mods/gentle-pane/snapshot.js +469 -0
- package/herdr/mods/gentle-pane/tokens.js +273 -0
- package/herdr/mods/gentle-sidebar/actions.js +180 -0
- package/herdr/mods/gentle-sidebar/icons/gear.svg +1 -0
- package/herdr/mods/gentle-sidebar/icons/mark.svg +1 -0
- package/herdr/mods/gentle-sidebar/icons/refresh.svg +1 -0
- package/herdr/mods/gentle-sidebar/icons/server-plus.svg +1 -0
- package/herdr/mods/gentle-sidebar/main.js +171 -0
- package/herdr/mods/gentle-sidebar/mod.json +1 -0
- package/herdr/mods/gentle-sidebar/snapshot.js +469 -0
- package/herdr/mods/gentle-sidebar/tokens.js +273 -0
- package/herdr/mods/gentle-spaces/icons/kind-herdr.svg +1 -0
- package/herdr/mods/gentle-spaces/icons/kind-remote.svg +1 -0
- package/herdr/mods/gentle-spaces/icons/kind-tui.svg +1 -0
- package/herdr/mods/gentle-spaces/icons/monitor.svg +1 -0
- package/herdr/mods/gentle-spaces/icons/plus.svg +1 -0
- package/herdr/mods/gentle-spaces/icons/server.svg +1 -0
- package/herdr/mods/gentle-spaces/machines.js +31 -0
- package/herdr/mods/gentle-spaces/main.js +299 -0
- package/herdr/mods/gentle-spaces/mod.json +1 -0
- package/herdr/mods/gentle-spaces/snapshot.js +469 -0
- package/herdr/mods/gentle-spaces/tokens.js +273 -0
- package/herdr/mods/gentle-status/actions.js +180 -0
- package/herdr/mods/gentle-status/main.js +192 -0
- package/herdr/mods/gentle-status/mod.json +1 -0
- package/herdr/mods/gentle-status/snapshot.js +469 -0
- package/herdr/mods/gentle-status/tokens.js +273 -0
- package/herdr/mods/gentle-tabs/icons/close.svg +1 -0
- package/herdr/mods/gentle-tabs/icons/kind-herdr.svg +1 -0
- package/herdr/mods/gentle-tabs/icons/kind-remote.svg +1 -0
- package/herdr/mods/gentle-tabs/icons/kind-tui.svg +1 -0
- package/herdr/mods/gentle-tabs/icons/plus.svg +1 -0
- package/herdr/mods/gentle-tabs/icons/win-close.svg +1 -0
- package/herdr/mods/gentle-tabs/icons/win-max.svg +1 -0
- package/herdr/mods/gentle-tabs/icons/win-min.svg +1 -0
- package/herdr/mods/gentle-tabs/icons/win-restore.svg +1 -0
- package/herdr/mods/gentle-tabs/main.js +171 -0
- package/herdr/mods/gentle-tabs/mod.json +1 -0
- package/herdr/mods/gentle-tabs/snapshot.js +469 -0
- package/herdr/mods/gentle-tabs/tokens.js +273 -0
- package/herdr/mods/gentle-tokens/main.js +20 -0
- package/herdr/mods/gentle-tokens/mod.json +1 -0
- package/herdr/mods/gentle-tokens/snapshot.js +469 -0
- package/herdr/mods/gentle-tokens/tokens.js +273 -0
- package/herdr/preview.png +0 -0
- package/herdr/themes/gentle-shell-dark.json +33 -0
- package/herdr/themes/gentle-shell-light.json +34 -0
- package/lib/agents-protocol.ts +2 -0
- package/lib/agents-rpc-publisher.ts +39 -12
- package/lib/agents-runner.ts +1 -0
- package/lib/auto-permission-answers.ts +2 -1
- package/lib/background-jobs.ts +22 -2
- package/lib/bounded-writer-admission.ts +1 -1
- package/lib/change-diff.ts +104 -0
- package/lib/commit-slice-signal.ts +1 -1
- package/lib/design-canvas-assets.ts +2 -0
- package/lib/desktop-agents-service.ts +31 -10
- package/lib/desktop-changes-service.ts +171 -0
- package/lib/desktop-feed-actions.ts +804 -0
- package/lib/desktop-feed-answers.ts +129 -0
- package/lib/desktop-feed-sources.ts +184 -0
- package/lib/desktop-feed-stats.ts +98 -0
- package/lib/desktop-feed-store.ts +124 -0
- package/lib/desktop-feed.ts +788 -0
- package/lib/desktop-jobs-service.ts +34 -7
- package/lib/desktop-review-service.ts +187 -0
- package/lib/desktop-rpc-agents.ts +112 -3
- package/lib/desktop-rpc-changes.ts +223 -0
- package/lib/desktop-rpc-config-watch.ts +285 -0
- package/lib/desktop-rpc-config.ts +162 -8
- package/lib/desktop-rpc-jobs.ts +118 -9
- package/lib/desktop-rpc-permissions.ts +154 -3
- package/lib/desktop-rpc-review.ts +180 -0
- package/lib/desktop-rpc-session.ts +203 -0
- package/lib/desktop-rpc-sessions.ts +250 -0
- package/lib/desktop-rpc-stats.ts +187 -0
- package/lib/desktop-rpc-updates.ts +143 -0
- package/lib/desktop-rpc.ts +116 -5
- package/lib/desktop-session-service.ts +223 -0
- package/lib/desktop-sessions-service.ts +249 -0
- package/lib/desktop-stats-service.ts +142 -0
- package/lib/desktop-updates-service.ts +268 -0
- package/lib/gentle-shell-desktop.ts +1370 -0
- package/lib/gentle-shell-launcher.ts +45 -3
- package/lib/herdr-desktop-events.ts +40 -0
- package/lib/herdr-desktop-status.ts +229 -0
- package/lib/jobs-sidebar-state.ts +5 -0
- package/lib/native-review-cli.ts +7 -0
- package/lib/openai-fast-tier.ts +1 -0
- package/lib/session-profile-freeze.ts +13 -5
- package/lib/stats-collector.ts +56 -27
- package/lib/tower-actions.ts +100 -0
- package/lib/tower-hub.ts +73 -0
- package/lib/tower-launch.ts +111 -0
- package/lib/tower-open.ts +99 -0
- package/lib/tower-presence.ts +70 -0
- package/lib/tower-server.ts +234 -0
- package/lib/tower-snapshot.ts +298 -0
- package/lib/update-status.ts +238 -0
- package/lib/verifier-settle-reminder.ts +1 -1
- package/package.json +13 -4
- package/runtime/design-canvas-assets.mjs +2 -0
- package/runtime/gentle-shell-desktop.mjs +1371 -0
- package/runtime/gentle-shell-launcher.mjs +44 -2
- package/runtime/native-review-cli.mjs +7 -0
- package/runtime/tower-actions.mjs +101 -0
- package/runtime/tower-hub.mjs +74 -0
- package/runtime/tower-launch.mjs +112 -0
- package/runtime/tower-open.mjs +100 -0
- package/runtime/tower-presence.mjs +71 -0
- package/runtime/tower-server.mjs +234 -0
- package/runtime/tower-snapshot.mjs +299 -0
- package/scripts/build-full-delegation-card.mjs +1 -21
- package/scripts/build-runtime-modules.mjs +9 -0
- package/scripts/gentle-ai-installer.mjs +10 -10
- package/scripts/verify-package-files.mjs +35 -15
- package/skills/provider-defect-report/SKILL.md +61 -0
- package/skills/rdd-defect-workflow/SKILL.md +3 -3
- package/tests/agent-prompt-diet-contract.test.ts +2 -2
- package/tests/append-system-prompt-route.test.ts +16 -5
- package/tests/ask-user-choice.test.ts +78 -21
- package/tests/ask-user-question.test.ts +59 -5
- package/tests/auto-permission-answers.test.ts +12 -1
- package/tests/background-jobs.test.ts +12 -0
- package/tests/bounded-stop-contract.test.ts +139 -26
- package/tests/change-diff.test.ts +75 -0
- package/tests/commit-slice-signal.test.ts +3 -2
- package/tests/decision-routing-contract.test.ts +390 -0
- package/tests/delegated-key-learnings-contract.test.ts +21 -28
- package/tests/delivery-b-rendered-surfaces.test.ts +32 -0
- package/tests/design-canvas-i18n.test.ts +24 -22
- package/tests/design-canvas-inspector.test.ts +67 -0
- package/tests/design-canvas-modules.test.ts +3 -2
- package/tests/design-canvas-rail.test.ts +10 -10
- package/tests/design-canvas-store.test.ts +9 -0
- package/tests/design-canvas-theme.test.ts +198 -0
- package/tests/design-canvas-tokens.test.ts +1 -1
- package/tests/desktop-feed-actions-guards.test.ts +595 -0
- package/tests/desktop-feed-actions.test.ts +761 -0
- package/tests/desktop-feed-live-work.test.ts +209 -0
- package/tests/desktop-feed-performance.test.ts +369 -0
- package/tests/desktop-feed-plan-profiles.test.ts +509 -0
- package/tests/desktop-feed-send-prompt.test.ts +303 -0
- package/tests/desktop-feed-tool-summaries.test.ts +69 -0
- package/tests/desktop-feed.test.ts +615 -0
- package/tests/desktop-rpc-agents.test.ts +428 -2
- package/tests/desktop-rpc-changes.test.ts +608 -0
- package/tests/desktop-rpc-config-watch.test.ts +1159 -0
- package/tests/desktop-rpc-config.test.ts +11 -1
- package/tests/desktop-rpc-design.test.ts +11 -1
- package/tests/desktop-rpc-jobs.test.ts +402 -5
- package/tests/desktop-rpc-permissions.test.ts +11 -1
- package/tests/desktop-rpc-review.test.ts +678 -0
- package/tests/desktop-rpc-session.test.ts +642 -0
- package/tests/desktop-rpc-sessions.test.ts +647 -0
- package/tests/desktop-rpc-stats.test.ts +431 -0
- package/tests/desktop-rpc-updates.test.ts +525 -0
- package/tests/desktop-rpc-usage.test.ts +11 -1
- package/tests/desktop-rpc.test.ts +43 -2
- package/tests/fixtures/primary-session-prompt/gentleman.golden.md +11 -13
- package/tests/fixtures/session-profile-v1/replay.ts +4 -1
- package/tests/full-delegation-closure.test.ts +20 -1
- package/tests/gentle-agents.test.ts +519 -4
- package/tests/gentle-ai-binary.test.ts +1 -1
- package/tests/gentle-ai-installer.test.ts +52 -52
- package/tests/gentle-ai.test.ts +75 -16
- package/tests/gentle-fast.test.ts +15 -0
- package/tests/gentle-herdr-desktop-status.test.ts +595 -0
- package/tests/gentle-shell-desktop-bin.test.ts +125 -0
- package/tests/gentle-shell-desktop.test.ts +927 -0
- package/tests/gentle-shell-launcher-tower.test.ts +104 -0
- package/tests/gentle-shell.test.ts +3 -0
- package/tests/gentle-tower.test.ts +578 -0
- package/tests/herdr-desktop-status.test.ts +285 -0
- package/tests/independent-recovery-delivery.test.ts +16 -4
- package/tests/installer-server.test.ts +2 -2
- package/tests/lazy-module-contradictions-contract.test.ts +27 -4
- package/tests/maintainer/desktop-rpc.maintest.ts +279 -4
- package/tests/native-review-capability-contract.test.ts +9 -1
- package/tests/no-self-pause-contract.test.ts +23 -13
- package/tests/odd-routing-canonical-ratchet.test.ts +10 -0
- package/tests/odd-routing-contract.test.ts +19 -3
- package/tests/orchestrator-budget.test.ts +3 -1
- package/tests/orchestrator-prompt-budget.test.ts +2 -1
- package/tests/orchestrator-prompt-diet-contract.test.ts +31 -3
- package/tests/package-manifest.test.ts +10 -10
- package/tests/pi-routing-measured-values.test.ts +24 -0
- package/tests/primary-session-prompt.test.ts +25 -0
- package/tests/profile-fast-tier.test.ts +66 -1
- package/tests/provider-defect-handoff.test.ts +118 -100
- package/tests/review-contract-prompt.test.ts +2 -1
- package/tests/review-due-public-boundary.test.ts +2 -1
- package/tests/sensitive-path-tools.test.ts +138 -4
- package/tests/session-profile-extension.test.ts +310 -16
- package/tests/session-profile-freeze.test.ts +26 -0
- package/tests/session-profile-v1-compat.test.ts +20 -0
- package/tests/skill-collision-prefixes.test.ts +1 -0
- package/tests/skill-contradictions-contract.test.ts +5 -3
- package/tests/skill-registry.test.ts +54 -0
- package/tests/stats-collector.test.ts +109 -2
- package/tests/support/design-canvas-dom.ts +17 -0
- package/tests/task-size-routing-contract.test.ts +7 -3
- package/tests/tower-actions.test.ts +247 -0
- package/tests/tower-artifacts.test.ts +114 -0
- package/tests/tower-open.test.ts +97 -0
- package/tests/tower-presence.test.ts +175 -0
- package/tests/tower-server.test.ts +122 -0
- package/tests/tower-snapshot.test.ts +236 -0
- package/tests/tower-web-echo.test.ts +125 -0
- package/tests/tower-web-hover.test.ts +251 -0
- package/tests/verification-scoped-stop-contract.test.ts +32 -0
- package/tests/verification-tiers-contract.test.ts +5 -5
- package/tests/verifier-settle-reminder.test.ts +2 -2
- package/tests/verify-first-launch-contract.test.ts +2 -2
- package/tests/work-continuity-contract.test.ts +83 -17
- package/tests/writer-rejection-next-step.test.ts +55 -0
- package/tests/writer-surface-authority-contract.test.ts +158 -0
- /package/contracts/review-provider-contract-mirror/{v1.5.0 → v1.6.0}/bundle/README.md +0 -0
- /package/contracts/review-provider-contract-mirror/{v1.5.0 → v1.6.0}/bundle/schemas/lens.schema.json +0 -0
- /package/contracts/review-provider-contract-mirror/{v1.5.0 → v1.6.0}/bundle/schemas/refuter.schema.json +0 -0
- /package/contracts/review-provider-contract-mirror/{v1.5.0 → v1.6.0}/bundle/schemas/targeted-validator.schema.json +0 -0
- /package/contracts/review-provider-contract-mirror/{v1.5.0 → v1.6.0}/bundle/vectors/lens.json +0 -0
- /package/contracts/review-provider-contract-mirror/{v1.5.0 → v1.6.0}/bundle/vectors/refuter.json +0 -0
- /package/contracts/review-provider-contract-mirror/{v1.5.0 → v1.6.0}/bundle/vectors/targeted-validator.json +0 -0
|
@@ -0,0 +1,1159 @@
|
|
|
1
|
+
import assert from "node:assert/strict";
|
|
2
|
+
import { mkdirSync, mkdtempSync, renameSync, rmSync, unlinkSync, writeFileSync } from "node:fs";
|
|
3
|
+
import { tmpdir } from "node:os";
|
|
4
|
+
import { dirname, join } from "node:path";
|
|
5
|
+
import { test } from "node:test";
|
|
6
|
+
import type { ExtensionAPI, ExtensionContext } from "@earendil-works/pi-coding-agent";
|
|
7
|
+
import desktopRpc from "../extensions/gentle-desktop-rpc.ts";
|
|
8
|
+
import { PROFILES_KIND, PROFILES_VERSION, profilesFilePath } from "../lib/agent-profiles.ts";
|
|
9
|
+
import { DESKTOP_CHANGE_DEBOUNCE_MS, DesktopDirectoryWatcher, watchDesktopDirectory, type DesktopChangeTimers } from "../lib/desktop-rpc-config-watch.ts";
|
|
10
|
+
import { DESKTOP_RPC_SCHEMA, DESKTOP_RPC_WIDGET } from "../lib/desktop-rpc.ts";
|
|
11
|
+
import { configWatchTargets, DesktopConfigBridge } from "../lib/desktop-rpc-config.ts";
|
|
12
|
+
import { DesktopPermissionBridge } from "../lib/desktop-rpc-permissions.ts";
|
|
13
|
+
import { PROFILE_PIN_KIND, PROFILE_PIN_VERSION, localProfilePinPath, repoProfileDeclarationPath } from "../lib/agent-profile-pin.ts";
|
|
14
|
+
import { FALLBACKS_KIND, FALLBACKS_VERSION, fallbacksFilePath } from "../lib/model-fallback-store.ts";
|
|
15
|
+
import { INTERACTIVE_HOST_ENV } from "../lib/rpc-host.ts";
|
|
16
|
+
import { registerYoloSessionPolicy } from "../lib/yolo-session-policy.ts";
|
|
17
|
+
|
|
18
|
+
// External-change events (#3321). Every watcher and timer is injected: the fake
|
|
19
|
+
// directory watcher lets a test say exactly which owner directory reported a
|
|
20
|
+
// change, and the fake clock decides when the debounce window closes, so no test
|
|
21
|
+
// depends on real filesystem notification timing.
|
|
22
|
+
|
|
23
|
+
interface FakeClock extends DesktopChangeTimers {
|
|
24
|
+
advance(ms: number): void;
|
|
25
|
+
pending(): number;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
function fakeClock(): FakeClock {
|
|
29
|
+
let now = 0;
|
|
30
|
+
let next = 1;
|
|
31
|
+
const timers = new Map<number, { at: number; fn: () => void }>();
|
|
32
|
+
return {
|
|
33
|
+
set(fn, ms) {
|
|
34
|
+
const id = next++;
|
|
35
|
+
timers.set(id, { at: now + ms, fn });
|
|
36
|
+
return id;
|
|
37
|
+
},
|
|
38
|
+
clear(handle) {
|
|
39
|
+
timers.delete(handle as number);
|
|
40
|
+
},
|
|
41
|
+
advance(ms) {
|
|
42
|
+
now += ms;
|
|
43
|
+
for (const [id, timer] of [...timers].sort((a, b) => a[1].at - b[1].at)) {
|
|
44
|
+
if (timer.at > now || !timers.has(id)) continue;
|
|
45
|
+
timers.delete(id);
|
|
46
|
+
timer.fn();
|
|
47
|
+
}
|
|
48
|
+
},
|
|
49
|
+
pending() {
|
|
50
|
+
return timers.size;
|
|
51
|
+
},
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
interface FakeWatch {
|
|
56
|
+
dir: string;
|
|
57
|
+
onChange: (filename: string | undefined, removed?: boolean) => void;
|
|
58
|
+
closed: boolean;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
function fakeWatches(fails: (dir: string) => boolean = () => false) {
|
|
62
|
+
const all: FakeWatch[] = [];
|
|
63
|
+
const attempts: string[] = [];
|
|
64
|
+
return {
|
|
65
|
+
all,
|
|
66
|
+
attempts,
|
|
67
|
+
factory(dir: string, onChange: (filename: string | undefined, removed?: boolean) => void) {
|
|
68
|
+
attempts.push(dir);
|
|
69
|
+
if (fails(dir)) throw Object.assign(new Error("ENOSPC: watcher limit"), { code: "ENOSPC" });
|
|
70
|
+
const watch: FakeWatch = { dir, onChange, closed: false };
|
|
71
|
+
all.push(watch);
|
|
72
|
+
return () => {
|
|
73
|
+
watch.closed = true;
|
|
74
|
+
};
|
|
75
|
+
},
|
|
76
|
+
open(): FakeWatch[] {
|
|
77
|
+
return all.filter((watch) => !watch.closed);
|
|
78
|
+
},
|
|
79
|
+
fire(dir: string, filename: string | undefined): number {
|
|
80
|
+
let delivered = 0;
|
|
81
|
+
for (const watch of all) {
|
|
82
|
+
if (watch.closed || watch.dir !== dir) continue;
|
|
83
|
+
watch.onChange(filename);
|
|
84
|
+
delivered += 1;
|
|
85
|
+
}
|
|
86
|
+
return delivered;
|
|
87
|
+
},
|
|
88
|
+
/** What the real watcher does when its own directory disappears: close, then report it. */
|
|
89
|
+
remove(dir: string): number {
|
|
90
|
+
let delivered = 0;
|
|
91
|
+
for (const watch of all) {
|
|
92
|
+
if (watch.closed || watch.dir !== dir) continue;
|
|
93
|
+
watch.closed = true;
|
|
94
|
+
watch.onChange(undefined, true);
|
|
95
|
+
delivered += 1;
|
|
96
|
+
}
|
|
97
|
+
return delivered;
|
|
98
|
+
},
|
|
99
|
+
};
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
/** Real owner reads (realpath, file reads) finish on the event loop, not the fake clock. */
|
|
103
|
+
async function settle(): Promise<void> {
|
|
104
|
+
for (let index = 0; index < 25; index += 1) await new Promise((resolve) => setTimeout(resolve, 1));
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
// ---- The debounced directory watcher on its own ----
|
|
108
|
+
|
|
109
|
+
test("a burst of directory changes is coalesced into one recompute per debounce window", () => {
|
|
110
|
+
const clock = fakeClock();
|
|
111
|
+
const watches = fakeWatches();
|
|
112
|
+
let runs = 0;
|
|
113
|
+
const watcher = new DesktopDirectoryWatcher(() => (runs += 1), { watch: watches.factory, timers: clock, exists: () => true });
|
|
114
|
+
assert.equal(watcher.start([{ dir: "/owner", names: ["profiles.json"] }]), 1);
|
|
115
|
+
|
|
116
|
+
watches.fire("/owner", "profiles.json");
|
|
117
|
+
clock.advance(DESKTOP_CHANGE_DEBOUNCE_MS - 50);
|
|
118
|
+
watches.fire("/owner", "profiles.json");
|
|
119
|
+
clock.advance(DESKTOP_CHANGE_DEBOUNCE_MS - 50);
|
|
120
|
+
assert.equal(runs, 0, "every change restarts the window");
|
|
121
|
+
clock.advance(50);
|
|
122
|
+
assert.equal(runs, 1, "one recompute after the last change");
|
|
123
|
+
clock.advance(DESKTOP_CHANGE_DEBOUNCE_MS * 4);
|
|
124
|
+
assert.equal(runs, 1, "no trailing recompute without a new change");
|
|
125
|
+
watcher.dispose();
|
|
126
|
+
});
|
|
127
|
+
|
|
128
|
+
test("unrelated entries in a watched directory never schedule a recompute; unnamed events do", () => {
|
|
129
|
+
const clock = fakeClock();
|
|
130
|
+
const watches = fakeWatches();
|
|
131
|
+
let runs = 0;
|
|
132
|
+
const watcher = new DesktopDirectoryWatcher(() => (runs += 1), { watch: watches.factory, timers: clock, exists: () => true });
|
|
133
|
+
watcher.start([
|
|
134
|
+
{ dir: "/owner", names: ["profiles.json"] },
|
|
135
|
+
{ dir: "/owner", names: ["profile-fallbacks.json"] },
|
|
136
|
+
]);
|
|
137
|
+
assert.equal(watches.all.length, 1, "one watcher per directory, names merged");
|
|
138
|
+
|
|
139
|
+
watches.fire("/owner", "notes.txt");
|
|
140
|
+
clock.advance(DESKTOP_CHANGE_DEBOUNCE_MS);
|
|
141
|
+
assert.equal(runs, 0);
|
|
142
|
+
assert.equal(clock.pending(), 0);
|
|
143
|
+
|
|
144
|
+
watches.fire("/owner", "profile-fallbacks.json");
|
|
145
|
+
clock.advance(DESKTOP_CHANGE_DEBOUNCE_MS);
|
|
146
|
+
assert.equal(runs, 1);
|
|
147
|
+
|
|
148
|
+
watches.fire("/owner", undefined);
|
|
149
|
+
clock.advance(DESKTOP_CHANGE_DEBOUNCE_MS);
|
|
150
|
+
assert.equal(runs, 2, "a platform that reports no name still triggers a recompute");
|
|
151
|
+
watcher.dispose();
|
|
152
|
+
});
|
|
153
|
+
|
|
154
|
+
test("a directory that cannot be watched is skipped without throwing", () => {
|
|
155
|
+
const clock = fakeClock();
|
|
156
|
+
const watches = fakeWatches((dir) => dir === "/missing");
|
|
157
|
+
let runs = 0;
|
|
158
|
+
const watcher = new DesktopDirectoryWatcher(() => (runs += 1), { watch: watches.factory, timers: clock, exists: () => true });
|
|
159
|
+
assert.equal(
|
|
160
|
+
watcher.start([
|
|
161
|
+
{ dir: "/missing", names: ["models.json"] },
|
|
162
|
+
{ dir: "/owner", names: ["profiles.json"] },
|
|
163
|
+
]),
|
|
164
|
+
1,
|
|
165
|
+
);
|
|
166
|
+
assert.deepEqual(watches.attempts, ["/missing", "/owner"]);
|
|
167
|
+
watches.fire("/owner", "profiles.json");
|
|
168
|
+
clock.advance(DESKTOP_CHANGE_DEBOUNCE_MS);
|
|
169
|
+
assert.equal(runs, 1, "the remaining watcher still works");
|
|
170
|
+
|
|
171
|
+
const none = new DesktopDirectoryWatcher(() => (runs += 1), {
|
|
172
|
+
watch: () => {
|
|
173
|
+
throw new Error("unsupported platform");
|
|
174
|
+
},
|
|
175
|
+
timers: clock,
|
|
176
|
+
exists: () => true,
|
|
177
|
+
});
|
|
178
|
+
assert.equal(none.start([{ dir: "/owner", names: ["profiles.json"] }]), 0);
|
|
179
|
+
none.dispose();
|
|
180
|
+
watcher.dispose();
|
|
181
|
+
});
|
|
182
|
+
|
|
183
|
+
test("dispose closes every watcher and cancels a pending recompute", () => {
|
|
184
|
+
const clock = fakeClock();
|
|
185
|
+
const watches = fakeWatches();
|
|
186
|
+
let runs = 0;
|
|
187
|
+
const watcher = new DesktopDirectoryWatcher(() => (runs += 1), { watch: watches.factory, timers: clock, exists: () => true });
|
|
188
|
+
watcher.start([
|
|
189
|
+
{ dir: "/a", names: ["x.json"] },
|
|
190
|
+
{ dir: "/b", names: ["y.json"] },
|
|
191
|
+
]);
|
|
192
|
+
watches.fire("/a", "x.json");
|
|
193
|
+
watcher.dispose();
|
|
194
|
+
watcher.dispose();
|
|
195
|
+
assert.equal(watches.open().length, 0);
|
|
196
|
+
assert.equal(clock.pending(), 0);
|
|
197
|
+
clock.advance(DESKTOP_CHANGE_DEBOUNCE_MS);
|
|
198
|
+
assert.equal(runs, 0);
|
|
199
|
+
assert.equal(watcher.start([{ dir: "/a", names: ["x.json"] }]), 0, "a disposed watcher never restarts");
|
|
200
|
+
});
|
|
201
|
+
|
|
202
|
+
// ---- Through the channel ----
|
|
203
|
+
|
|
204
|
+
function profilesFile(active: string): Record<string, unknown> {
|
|
205
|
+
return {
|
|
206
|
+
kind: PROFILES_KIND,
|
|
207
|
+
version: PROFILES_VERSION,
|
|
208
|
+
active,
|
|
209
|
+
profiles: {
|
|
210
|
+
team: { explore: { model: "anthropic/claude-explore" } },
|
|
211
|
+
ops: { worker: { model: "openai/gpt-worker" } },
|
|
212
|
+
},
|
|
213
|
+
};
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
function writeJson(path: string, value: unknown): void {
|
|
217
|
+
mkdirSync(dirname(path), { recursive: true });
|
|
218
|
+
writeFileSync(path, `${JSON.stringify(value)}\n`);
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
function desktopHost(
|
|
222
|
+
t: test.TestContext,
|
|
223
|
+
options: { mode?: string; watchFails?: (dir: string) => boolean; owner?: boolean } = {},
|
|
224
|
+
) {
|
|
225
|
+
const root = mkdtempSync(join(tmpdir(), "gentle-desktop-watch-"));
|
|
226
|
+
const configHome = join(root, "config");
|
|
227
|
+
const agentHome = join(root, "agent");
|
|
228
|
+
const workspace = join(root, "workspace");
|
|
229
|
+
for (const directory of [configHome, agentHome, workspace]) mkdirSync(directory, { recursive: true });
|
|
230
|
+
const previous = {
|
|
231
|
+
host: process.env[INTERACTIVE_HOST_ENV],
|
|
232
|
+
configHome: process.env.GENTLE_PI_CONFIG_HOME,
|
|
233
|
+
agentHome: process.env.GENTLE_PI_AGENT_HOME,
|
|
234
|
+
child: process.env.GENTLE_PI_AGENTS_CHILD,
|
|
235
|
+
};
|
|
236
|
+
process.env[INTERACTIVE_HOST_ENV] = "1";
|
|
237
|
+
process.env.GENTLE_PI_CONFIG_HOME = configHome;
|
|
238
|
+
process.env.GENTLE_PI_AGENT_HOME = agentHome;
|
|
239
|
+
delete process.env.GENTLE_PI_AGENTS_CHILD;
|
|
240
|
+
|
|
241
|
+
const commands = new Map<string, { handler: (args: string, ctx: ExtensionContext) => Promise<void> }>();
|
|
242
|
+
const lifecycle = new Map<string, (event: unknown, ctx: ExtensionContext) => unknown>();
|
|
243
|
+
const hostUi = new Map<string, (value: unknown) => void>();
|
|
244
|
+
const pi = {
|
|
245
|
+
registerCommand(name: string, command: { handler: (args: string, ctx: ExtensionContext) => Promise<void> }) {
|
|
246
|
+
commands.set(name, command);
|
|
247
|
+
},
|
|
248
|
+
on(name: string, handler: (event: unknown, ctx: ExtensionContext) => unknown) {
|
|
249
|
+
lifecycle.set(name, handler);
|
|
250
|
+
},
|
|
251
|
+
registerTool() {},
|
|
252
|
+
events: {
|
|
253
|
+
on(name: string, handler: (value: unknown) => void) {
|
|
254
|
+
hostUi.set(name, handler);
|
|
255
|
+
},
|
|
256
|
+
emit(name: string, value: unknown) {
|
|
257
|
+
hostUi.get(name)?.(value);
|
|
258
|
+
},
|
|
259
|
+
},
|
|
260
|
+
} as unknown as ExtensionAPI;
|
|
261
|
+
if (options.owner !== false) registerYoloSessionPolicy(pi, process.env, { resolveIdentity: async () => "workspace:test" });
|
|
262
|
+
const clock = fakeClock();
|
|
263
|
+
const watches = fakeWatches(options.watchFails);
|
|
264
|
+
desktopRpc(pi, { watch: watches.factory, timers: clock });
|
|
265
|
+
|
|
266
|
+
const widgets: string[] = [];
|
|
267
|
+
const session = { id: "session-1" };
|
|
268
|
+
const ctx = {
|
|
269
|
+
mode: options.mode ?? "rpc",
|
|
270
|
+
hasUI: true,
|
|
271
|
+
cwd: workspace,
|
|
272
|
+
sessionManager: { getSessionId: () => session.id },
|
|
273
|
+
ui: {
|
|
274
|
+
setWidget(key: string, lines: string[]) {
|
|
275
|
+
if (key === DESKTOP_RPC_WIDGET) widgets.push(lines[0]!);
|
|
276
|
+
},
|
|
277
|
+
setStatus() {},
|
|
278
|
+
notify() {},
|
|
279
|
+
select: async () => undefined,
|
|
280
|
+
getAllThemes: () => [],
|
|
281
|
+
},
|
|
282
|
+
} as unknown as ExtensionContext;
|
|
283
|
+
const app = {
|
|
284
|
+
root,
|
|
285
|
+
configHome,
|
|
286
|
+
agentHome,
|
|
287
|
+
workspace,
|
|
288
|
+
clock,
|
|
289
|
+
watches,
|
|
290
|
+
ctx,
|
|
291
|
+
session,
|
|
292
|
+
start() {
|
|
293
|
+
lifecycle.get("session_start")?.({}, ctx);
|
|
294
|
+
},
|
|
295
|
+
shutdown() {
|
|
296
|
+
lifecycle.get("session_shutdown")?.({}, ctx);
|
|
297
|
+
},
|
|
298
|
+
async invoke(method: string, params: Record<string, unknown> = {}, requestId = `request-${method}`) {
|
|
299
|
+
await commands.get("gentle:desktop")!.handler(
|
|
300
|
+
JSON.stringify({ schema: DESKTOP_RPC_SCHEMA, requestId, method, params }),
|
|
301
|
+
ctx,
|
|
302
|
+
);
|
|
303
|
+
},
|
|
304
|
+
async mode(args: string) {
|
|
305
|
+
await commands.get("gentle:mode")!.handler(args, ctx);
|
|
306
|
+
},
|
|
307
|
+
lines(): any[] {
|
|
308
|
+
return widgets.map((line) => JSON.parse(line));
|
|
309
|
+
},
|
|
310
|
+
events(name?: string): any[] {
|
|
311
|
+
return app.lines().filter((line) => line.kind === "event" && (name === undefined || line.event === name));
|
|
312
|
+
},
|
|
313
|
+
/** Closes the debounce window, then lets the owner re-reads finish. */
|
|
314
|
+
async elapse() {
|
|
315
|
+
clock.advance(DESKTOP_CHANGE_DEBOUNCE_MS);
|
|
316
|
+
await settle();
|
|
317
|
+
},
|
|
318
|
+
};
|
|
319
|
+
t.after(async () => {
|
|
320
|
+
app.shutdown();
|
|
321
|
+
const restore = (key: string, value: string | undefined) => {
|
|
322
|
+
if (value === undefined) delete process.env[key];
|
|
323
|
+
else process.env[key] = value;
|
|
324
|
+
};
|
|
325
|
+
restore(INTERACTIVE_HOST_ENV, previous.host);
|
|
326
|
+
restore("GENTLE_PI_CONFIG_HOME", previous.configHome);
|
|
327
|
+
restore("GENTLE_PI_AGENT_HOME", previous.agentHome);
|
|
328
|
+
restore("GENTLE_PI_AGENTS_CHILD", previous.child);
|
|
329
|
+
rmSync(root, { recursive: true, force: true });
|
|
330
|
+
});
|
|
331
|
+
return app;
|
|
332
|
+
}
|
|
333
|
+
|
|
334
|
+
test("an external profiles edit emits one config_changed with source external and no content or path", async (t) => {
|
|
335
|
+
const app = desktopHost(t);
|
|
336
|
+
writeJson(profilesFilePath(app.configHome), profilesFile("team"));
|
|
337
|
+
app.start();
|
|
338
|
+
await settle();
|
|
339
|
+
const configDir = dirname(profilesFilePath(app.configHome));
|
|
340
|
+
assert.ok(app.watches.open().some((watch) => watch.dir === configDir), "the owner directory is watched");
|
|
341
|
+
|
|
342
|
+
writeJson(profilesFilePath(app.configHome), profilesFile("ops"));
|
|
343
|
+
app.watches.fire(configDir, "profiles.json");
|
|
344
|
+
app.clock.advance(DESKTOP_CHANGE_DEBOUNCE_MS - 1);
|
|
345
|
+
await settle();
|
|
346
|
+
assert.deepEqual(app.events(), [], "nothing before the debounce window closes");
|
|
347
|
+
await app.elapse();
|
|
348
|
+
|
|
349
|
+
await app.invoke("get_config", { store: "profiles" });
|
|
350
|
+
const current = app.lines().at(-1).data;
|
|
351
|
+
const events = app.events("config_changed");
|
|
352
|
+
assert.equal(events.length, 1);
|
|
353
|
+
assert.equal(events[0].seq, 1);
|
|
354
|
+
assert.deepEqual(events[0].data, {
|
|
355
|
+
store: "profiles",
|
|
356
|
+
scope: "global",
|
|
357
|
+
revision: current.revision,
|
|
358
|
+
status: "ok",
|
|
359
|
+
source: "external",
|
|
360
|
+
});
|
|
361
|
+
assert.equal(JSON.stringify(events[0]).includes(app.root), false, "no absolute path on the wire");
|
|
362
|
+
|
|
363
|
+
await app.elapse();
|
|
364
|
+
assert.equal(app.events().length, 1, "no repeat without a new change");
|
|
365
|
+
});
|
|
366
|
+
|
|
367
|
+
test("a burst of external writes to several stores coalesces into one event per changed store", async (t) => {
|
|
368
|
+
const app = desktopHost(t);
|
|
369
|
+
writeJson(profilesFilePath(app.configHome), profilesFile("team"));
|
|
370
|
+
app.start();
|
|
371
|
+
await settle();
|
|
372
|
+
const configDir = dirname(profilesFilePath(app.configHome));
|
|
373
|
+
|
|
374
|
+
writeJson(profilesFilePath(app.configHome), profilesFile("ops"));
|
|
375
|
+
app.watches.fire(configDir, "profiles.json");
|
|
376
|
+
writeJson(profilesFilePath(app.configHome), profilesFile("team"));
|
|
377
|
+
app.watches.fire(configDir, "profiles.json");
|
|
378
|
+
writeJson(fallbacksFilePath(app.configHome), { kind: FALLBACKS_KIND, version: FALLBACKS_VERSION, profiles: {} });
|
|
379
|
+
app.watches.fire(configDir, "profile-fallbacks.json");
|
|
380
|
+
await app.elapse();
|
|
381
|
+
|
|
382
|
+
// profiles went team -> ops -> team inside one window: its revision is back to
|
|
383
|
+
// the last one reported, so only the fallbacks store changed.
|
|
384
|
+
const events = app.events("config_changed");
|
|
385
|
+
assert.deepEqual(
|
|
386
|
+
events.map((event) => [event.data.store, event.data.source]),
|
|
387
|
+
[["profile_fallbacks", "external"]],
|
|
388
|
+
);
|
|
389
|
+
});
|
|
390
|
+
|
|
391
|
+
test("a Desktop set_config is reported once, as desktop, never echoed as external", async (t) => {
|
|
392
|
+
const app = desktopHost(t);
|
|
393
|
+
writeJson(profilesFilePath(app.configHome), profilesFile("team"));
|
|
394
|
+
app.start();
|
|
395
|
+
await settle();
|
|
396
|
+
await app.invoke("get_config", { store: "profiles" });
|
|
397
|
+
const read = app.lines().at(-1).data;
|
|
398
|
+
|
|
399
|
+
await app.invoke("set_config", {
|
|
400
|
+
store: "profiles",
|
|
401
|
+
data: profilesFile("ops"),
|
|
402
|
+
expectedRevision: read.writeTargets[0].writeRevision,
|
|
403
|
+
});
|
|
404
|
+
const [response, desktopEvent] = app.lines().slice(-2);
|
|
405
|
+
assert.equal(response.ok, true);
|
|
406
|
+
assert.equal(desktopEvent.data.source, "desktop");
|
|
407
|
+
|
|
408
|
+
// The owner's own write wakes the directory watcher like any other write.
|
|
409
|
+
app.watches.fire(dirname(profilesFilePath(app.configHome)), "profiles.json");
|
|
410
|
+
await app.elapse();
|
|
411
|
+
assert.deepEqual(
|
|
412
|
+
app.events("config_changed").map((event) => event.data.source),
|
|
413
|
+
["desktop"],
|
|
414
|
+
"the recomputed revision equals the one the channel already reported",
|
|
415
|
+
);
|
|
416
|
+
});
|
|
417
|
+
|
|
418
|
+
test("an event whose recomputed revisions did not change emits nothing", async (t) => {
|
|
419
|
+
const app = desktopHost(t);
|
|
420
|
+
writeJson(profilesFilePath(app.configHome), profilesFile("team"));
|
|
421
|
+
app.start();
|
|
422
|
+
await settle();
|
|
423
|
+
// Same content rewritten (formatting only): the canonical revision is unchanged.
|
|
424
|
+
writeFileSync(profilesFilePath(app.configHome), `${JSON.stringify(profilesFile("team"), null, 2)}\n`);
|
|
425
|
+
app.watches.fire(dirname(profilesFilePath(app.configHome)), "profiles.json");
|
|
426
|
+
await app.elapse();
|
|
427
|
+
assert.deepEqual(app.events(), []);
|
|
428
|
+
});
|
|
429
|
+
|
|
430
|
+
test("watcher creation failure leaves the channel working without external events", async (t) => {
|
|
431
|
+
const app = desktopHost(t, { watchFails: () => true });
|
|
432
|
+
writeJson(profilesFilePath(app.configHome), profilesFile("team"));
|
|
433
|
+
app.start();
|
|
434
|
+
await settle();
|
|
435
|
+
assert.ok(app.watches.attempts.length > 0, "watchers were attempted");
|
|
436
|
+
assert.equal(app.watches.open().length, 0);
|
|
437
|
+
|
|
438
|
+
writeJson(profilesFilePath(app.configHome), profilesFile("ops"));
|
|
439
|
+
await app.elapse();
|
|
440
|
+
assert.deepEqual(app.events(), []);
|
|
441
|
+
|
|
442
|
+
await app.invoke("get_snapshot");
|
|
443
|
+
const snapshot = app.lines().at(-1);
|
|
444
|
+
assert.equal(snapshot.ok, true, "get_snapshot stays the source of truth");
|
|
445
|
+
await app.invoke("get_config", { store: "profiles" });
|
|
446
|
+
const read = app.lines().at(-1);
|
|
447
|
+
assert.equal(read.ok, true);
|
|
448
|
+
assert.equal(read.data.value.active, "ops");
|
|
449
|
+
assert.equal(
|
|
450
|
+
snapshot.data.state.config.stores.find((store: any) => store.store === "profiles").revision,
|
|
451
|
+
read.data.revision,
|
|
452
|
+
);
|
|
453
|
+
await app.invoke("set_config", {
|
|
454
|
+
store: "profiles",
|
|
455
|
+
data: profilesFile("team"),
|
|
456
|
+
expectedRevision: read.data.writeTargets[0].writeRevision,
|
|
457
|
+
});
|
|
458
|
+
assert.equal(app.lines().at(-2).ok, true, "writes still work");
|
|
459
|
+
assert.equal(app.events("config_changed").length, 1);
|
|
460
|
+
});
|
|
461
|
+
|
|
462
|
+
test("session shutdown and session switch dispose every watcher and pending recompute", async (t) => {
|
|
463
|
+
const app = desktopHost(t);
|
|
464
|
+
writeJson(profilesFilePath(app.configHome), profilesFile("team"));
|
|
465
|
+
app.start();
|
|
466
|
+
await settle();
|
|
467
|
+
const first = app.watches.open();
|
|
468
|
+
assert.ok(first.length > 0);
|
|
469
|
+
const configDir = dirname(profilesFilePath(app.configHome));
|
|
470
|
+
|
|
471
|
+
// Switch: a new session_start replaces every watcher of the old session.
|
|
472
|
+
writeJson(profilesFilePath(app.configHome), profilesFile("ops"));
|
|
473
|
+
app.watches.fire(configDir, "profiles.json");
|
|
474
|
+
app.start();
|
|
475
|
+
await settle();
|
|
476
|
+
assert.equal(first.every((watch) => watch.closed), true, "old watchers closed on switch");
|
|
477
|
+
assert.ok(app.watches.open().length > 0, "the new session watches again");
|
|
478
|
+
await app.elapse();
|
|
479
|
+
assert.deepEqual(app.events(), [], "the old session's pending recompute was cancelled");
|
|
480
|
+
|
|
481
|
+
app.shutdown();
|
|
482
|
+
assert.equal(app.watches.open().length, 0, "shutdown closes every watcher");
|
|
483
|
+
writeJson(profilesFilePath(app.configHome), profilesFile("team"));
|
|
484
|
+
for (const watch of app.watches.all) watch.onChange("profiles.json");
|
|
485
|
+
await app.elapse();
|
|
486
|
+
assert.equal(app.clock.pending(), 0);
|
|
487
|
+
assert.deepEqual(app.lines(), [], "nothing is published after shutdown");
|
|
488
|
+
});
|
|
489
|
+
|
|
490
|
+
test("non-interactive hosts create no watchers and subscribe to no owner", async (t) => {
|
|
491
|
+
for (const mode of ["tui", "print"]) {
|
|
492
|
+
const app = desktopHost(t, { mode });
|
|
493
|
+
app.start();
|
|
494
|
+
await settle();
|
|
495
|
+
assert.deepEqual(app.watches.attempts, [], `${mode}: no watcher attempted`);
|
|
496
|
+
await app.mode("yolo");
|
|
497
|
+
await app.elapse();
|
|
498
|
+
assert.deepEqual(app.lines(), [], `${mode}: nothing published`);
|
|
499
|
+
}
|
|
500
|
+
});
|
|
501
|
+
|
|
502
|
+
// ---- Permission mode changes made outside Desktop RPC ----
|
|
503
|
+
|
|
504
|
+
test("a /gentle:mode change emits permission_mode_changed with source external", async (t) => {
|
|
505
|
+
const app = desktopHost(t);
|
|
506
|
+
app.start();
|
|
507
|
+
await settle();
|
|
508
|
+
|
|
509
|
+
await app.mode("yolo");
|
|
510
|
+
await settle();
|
|
511
|
+
assert.deepEqual(app.events(), [], "debounced, not immediate");
|
|
512
|
+
await app.elapse();
|
|
513
|
+
const events = app.events("permission_mode_changed");
|
|
514
|
+
assert.equal(events.length, 1);
|
|
515
|
+
assert.deepEqual(events[0].data, {
|
|
516
|
+
mode: "yolo",
|
|
517
|
+
previous_mode: "normal",
|
|
518
|
+
default_mode: "normal",
|
|
519
|
+
persisted: false,
|
|
520
|
+
source: "external",
|
|
521
|
+
});
|
|
522
|
+
|
|
523
|
+
await app.mode("default auto");
|
|
524
|
+
await app.elapse();
|
|
525
|
+
assert.deepEqual(app.events("permission_mode_changed").at(-1).data, {
|
|
526
|
+
mode: "yolo",
|
|
527
|
+
previous_mode: "yolo",
|
|
528
|
+
default_mode: "auto",
|
|
529
|
+
persisted: true,
|
|
530
|
+
source: "external",
|
|
531
|
+
});
|
|
532
|
+
assert.equal(app.events().length, 2);
|
|
533
|
+
|
|
534
|
+
await app.invoke("get_permission_mode");
|
|
535
|
+
assert.deepEqual(app.lines().at(-1).data, { mode: "yolo", default_mode: "auto" });
|
|
536
|
+
});
|
|
537
|
+
|
|
538
|
+
test("a Desktop set_permission_mode is reported once, as desktop, never echoed as external", async (t) => {
|
|
539
|
+
const app = desktopHost(t);
|
|
540
|
+
app.start();
|
|
541
|
+
await settle();
|
|
542
|
+
await app.invoke("set_permission_mode", { mode: "auto", persist: true });
|
|
543
|
+
await app.elapse();
|
|
544
|
+
await app.elapse();
|
|
545
|
+
assert.deepEqual(
|
|
546
|
+
app.events().map((event) => [event.event, event.data.source]),
|
|
547
|
+
[["permission_mode_changed", "desktop"]],
|
|
548
|
+
);
|
|
549
|
+
});
|
|
550
|
+
|
|
551
|
+
test("permission observation stops on shutdown and restarts on a new session", async (t) => {
|
|
552
|
+
const app = desktopHost(t);
|
|
553
|
+
app.start();
|
|
554
|
+
await settle();
|
|
555
|
+
app.shutdown();
|
|
556
|
+
await app.mode("yolo");
|
|
557
|
+
await app.elapse();
|
|
558
|
+
assert.deepEqual(app.lines(), [], "no event after shutdown");
|
|
559
|
+
|
|
560
|
+
app.session.id = "session-2";
|
|
561
|
+
app.start();
|
|
562
|
+
await settle();
|
|
563
|
+
await app.mode("auto");
|
|
564
|
+
await app.elapse();
|
|
565
|
+
const events = app.events("permission_mode_changed");
|
|
566
|
+
assert.equal(events.length, 1);
|
|
567
|
+
assert.equal(events[0].data.mode, "auto");
|
|
568
|
+
assert.equal(events[0].data.source, "external");
|
|
569
|
+
assert.equal(events[0].seq, 1, "the new session's sequence starts at 1");
|
|
570
|
+
});
|
|
571
|
+
|
|
572
|
+
test("a missing permission owner leaves config watching and the channel intact", async (t) => {
|
|
573
|
+
const app = desktopHost(t, { owner: false });
|
|
574
|
+
writeJson(profilesFilePath(app.configHome), profilesFile("team"));
|
|
575
|
+
app.start();
|
|
576
|
+
await settle();
|
|
577
|
+
writeJson(profilesFilePath(app.configHome), profilesFile("ops"));
|
|
578
|
+
app.watches.fire(dirname(profilesFilePath(app.configHome)), "profiles.json");
|
|
579
|
+
await app.elapse();
|
|
580
|
+
assert.deepEqual(app.events().map((event) => event.event), ["config_changed"]);
|
|
581
|
+
await app.invoke("get_permission_mode");
|
|
582
|
+
assert.equal(app.lines().at(-1).error.code, "permission_unavailable");
|
|
583
|
+
});
|
|
584
|
+
|
|
585
|
+
// ---- Bridge seams: pin layers follow the session cwd; Desktop sets are never echoed ----
|
|
586
|
+
|
|
587
|
+
test("pin layers are watched in the session worktree and follow a cwd change", async (t) => {
|
|
588
|
+
const root = mkdtempSync(join(tmpdir(), "gentle-desktop-watch-pins-"));
|
|
589
|
+
t.after(() => rmSync(root, { recursive: true, force: true }));
|
|
590
|
+
const configHome = join(root, "config");
|
|
591
|
+
const first = join(root, "first");
|
|
592
|
+
const second = join(root, "second");
|
|
593
|
+
for (const directory of [configHome, first, second]) mkdirSync(directory, { recursive: true });
|
|
594
|
+
const resolveWorktree = (_path: string, cwd: string) => ({ root: cwd, commonDir: join(cwd, ".git-common") });
|
|
595
|
+
const pinDirs = (cwd: string) => [dirname(localProfilePinPath(join(cwd, ".git-common"))), dirname(repoProfileDeclarationPath(cwd))];
|
|
596
|
+
for (const directory of [...pinDirs(first), ...pinDirs(second)]) mkdirSync(directory, { recursive: true });
|
|
597
|
+
const clock = fakeClock();
|
|
598
|
+
const watches = fakeWatches();
|
|
599
|
+
const bridge = new DesktopConfigBridge(
|
|
600
|
+
{ configHome, agentHome: join(root, "agent"), resolveWorktree },
|
|
601
|
+
{ watch: watches.factory, timers: clock },
|
|
602
|
+
);
|
|
603
|
+
const events: Array<{ event: string; data: Record<string, unknown> }> = [];
|
|
604
|
+
bridge.attach({ cwd: first } as unknown as ExtensionContext);
|
|
605
|
+
bridge.wire((event, data) => events.push({ event, data }));
|
|
606
|
+
|
|
607
|
+
const open = () => watches.open().map((watch) => watch.dir);
|
|
608
|
+
for (const dir of pinDirs(first)) assert.ok(open().includes(dir), `watches ${dir}`);
|
|
609
|
+
const targets = configWatchTargets({ cwd: first, configHome, agentHome: join(root, "agent"), resolveWorktree });
|
|
610
|
+
const pinTargets = targets.filter((target) => target.names.includes("profile-pin.json") || target.names.includes("profile.json"));
|
|
611
|
+
assert.deepEqual(
|
|
612
|
+
pinTargets.map((target) => [target.dir, target.names[0]]),
|
|
613
|
+
[
|
|
614
|
+
[pinDirs(first)[0], "profile-pin.json"],
|
|
615
|
+
[pinDirs(first)[1], "profile.json"],
|
|
616
|
+
],
|
|
617
|
+
"each pin layer is watched by its owner file name in its own directory",
|
|
618
|
+
);
|
|
619
|
+
|
|
620
|
+
writeJson(profilesFilePath(configHome), profilesFile("team"));
|
|
621
|
+
writeJson(repoProfileDeclarationPath(first), { kind: PROFILE_PIN_KIND, version: PROFILE_PIN_VERSION, profile: "ops" });
|
|
622
|
+
watches.fire(dirname(repoProfileDeclarationPath(first)), "profile.json");
|
|
623
|
+
clock.advance(DESKTOP_CHANGE_DEBOUNCE_MS);
|
|
624
|
+
assert.deepEqual(
|
|
625
|
+
events.map((entry) => entry.data.store).sort(),
|
|
626
|
+
["pins", "profiles"],
|
|
627
|
+
"the pin layer and the profiles store it resolves against both changed",
|
|
628
|
+
);
|
|
629
|
+
|
|
630
|
+
// A command bound with another cwd moves the pin layers, so the watchers move.
|
|
631
|
+
bridge.attach({ cwd: second } as unknown as ExtensionContext);
|
|
632
|
+
for (const dir of pinDirs(first)) assert.equal(open().includes(dir), false, `stopped watching ${dir}`);
|
|
633
|
+
for (const dir of pinDirs(second)) assert.ok(open().includes(dir), `watches ${dir}`);
|
|
634
|
+
|
|
635
|
+
bridge.reset();
|
|
636
|
+
assert.deepEqual(open(), []);
|
|
637
|
+
});
|
|
638
|
+
|
|
639
|
+
test("an owner notification that settles during a Desktop set is deferred and never echoed", async () => {
|
|
640
|
+
const clock = fakeClock();
|
|
641
|
+
let state = { mode: "normal", defaultMode: "normal" };
|
|
642
|
+
let notify: () => void = () => {};
|
|
643
|
+
let release: () => void = () => {};
|
|
644
|
+
const adapter = {
|
|
645
|
+
read: async () => "OFF",
|
|
646
|
+
readSnapshot: async () => ({ yolo: "OFF", mode: state.mode, defaultMode: state.defaultMode }),
|
|
647
|
+
setMode: async (mode: string) => {
|
|
648
|
+
state = { ...state, mode: "normal" };
|
|
649
|
+
notify();
|
|
650
|
+
await new Promise<void>((resolve) => (release = resolve));
|
|
651
|
+
state = { ...state, mode };
|
|
652
|
+
notify();
|
|
653
|
+
return true;
|
|
654
|
+
},
|
|
655
|
+
toggle: async () => {},
|
|
656
|
+
observe: (refresh: () => void) => {
|
|
657
|
+
notify = refresh;
|
|
658
|
+
return () => (notify = () => {});
|
|
659
|
+
},
|
|
660
|
+
dispose: () => {},
|
|
661
|
+
};
|
|
662
|
+
const bridge = new DesktopPermissionBridge({} as ExtensionAPI, async () => adapter as never, { timers: clock });
|
|
663
|
+
const events: Array<Record<string, unknown>> = [];
|
|
664
|
+
bridge.attach({ cwd: "/workspace" } as unknown as ExtensionContext);
|
|
665
|
+
await bridge.wire((_event, data) => events.push(data));
|
|
666
|
+
|
|
667
|
+
const pending = bridge.handle("set_permission_mode", { mode: "yolo" });
|
|
668
|
+
await settle();
|
|
669
|
+
// The owner's transient revoke-to-normal window closes while the set is in flight.
|
|
670
|
+
clock.advance(DESKTOP_CHANGE_DEBOUNCE_MS);
|
|
671
|
+
await settle();
|
|
672
|
+
assert.deepEqual(events, [], "no external event mid-set");
|
|
673
|
+
release();
|
|
674
|
+
const outcome = await pending;
|
|
675
|
+
assert.equal(outcome?.ok, true);
|
|
676
|
+
assert.equal((outcome as any).event.data.source, "desktop");
|
|
677
|
+
clock.advance(DESKTOP_CHANGE_DEBOUNCE_MS);
|
|
678
|
+
await settle();
|
|
679
|
+
assert.deepEqual(events, [], "the deferred window finds the state Desktop already reported");
|
|
680
|
+
|
|
681
|
+
state = { ...state, mode: "auto" };
|
|
682
|
+
notify();
|
|
683
|
+
clock.advance(DESKTOP_CHANGE_DEBOUNCE_MS);
|
|
684
|
+
await settle();
|
|
685
|
+
assert.deepEqual(events, [
|
|
686
|
+
{ mode: "auto", previous_mode: "yolo", default_mode: "normal", persisted: false, source: "external" },
|
|
687
|
+
]);
|
|
688
|
+
|
|
689
|
+
bridge.reset();
|
|
690
|
+
state = { ...state, mode: "normal" };
|
|
691
|
+
notify();
|
|
692
|
+
clock.advance(DESKTOP_CHANGE_DEBOUNCE_MS);
|
|
693
|
+
await settle();
|
|
694
|
+
assert.equal(events.length, 1, "reset unsubscribes from the owner");
|
|
695
|
+
});
|
|
696
|
+
|
|
697
|
+
test("the real directory watcher closes itself when its directory is removed", { timeout: 10_000 }, async (t) => {
|
|
698
|
+
// Regression: on Windows a removed watched directory keeps reporting events
|
|
699
|
+
// forever, which kept the process alive after a test (or session) removed it.
|
|
700
|
+
const root = mkdtempSync(join(tmpdir(), "gentle-desktop-watch-real-"));
|
|
701
|
+
t.after(() => rmSync(root, { recursive: true, force: true }));
|
|
702
|
+
const dir = join(root, "config");
|
|
703
|
+
mkdirSync(dir);
|
|
704
|
+
const seen: Array<string | undefined> = [];
|
|
705
|
+
const close = watchDesktopDirectory(dir, (filename) => seen.push(filename));
|
|
706
|
+
writeFileSync(join(dir, "profiles.json"), "{}\n");
|
|
707
|
+
const delay = (ms: number) => new Promise((resolve) => setTimeout(resolve, ms));
|
|
708
|
+
for (let index = 0; index < 100 && !seen.includes("profiles.json"); index += 1) await delay(20);
|
|
709
|
+
assert.ok(seen.includes("profiles.json"), "a named owner file event is delivered");
|
|
710
|
+
|
|
711
|
+
rmSync(dir, { recursive: true, force: true });
|
|
712
|
+
await delay(500);
|
|
713
|
+
const afterRemoval = seen.length;
|
|
714
|
+
await delay(300);
|
|
715
|
+
assert.equal(seen.length, afterRemoval, "a removed directory stops delivering events");
|
|
716
|
+
if (seen.length > 0 && !seen.slice(-1).includes("profiles.json")) assert.equal(seen.at(-1), undefined);
|
|
717
|
+
close();
|
|
718
|
+
close();
|
|
719
|
+
});
|
|
720
|
+
|
|
721
|
+
// ---- Verifier follow-ups (#3321): knock-on stores, cwd re-target, late directories ----
|
|
722
|
+
|
|
723
|
+
const worktreeAt = (_path: string, cwd: string) => ({ root: cwd, commonDir: join(cwd, ".git-common") });
|
|
724
|
+
const pinFile = (profile: string) => ({ kind: PROFILE_PIN_KIND, version: PROFILE_PIN_VERSION, profile });
|
|
725
|
+
function profilesNamed(names: string[], active: string): Record<string, unknown> {
|
|
726
|
+
return {
|
|
727
|
+
kind: PROFILES_KIND,
|
|
728
|
+
version: PROFILES_VERSION,
|
|
729
|
+
active,
|
|
730
|
+
profiles: Object.fromEntries(names.map((name) => [name, { explore: { model: "anthropic/claude-explore" } }])),
|
|
731
|
+
};
|
|
732
|
+
}
|
|
733
|
+
function scratchRoot(t: test.TestContext, prefix: string): string {
|
|
734
|
+
const root = mkdtempSync(join(tmpdir(), prefix));
|
|
735
|
+
t.after(() => rmSync(root, { recursive: true, force: true }));
|
|
736
|
+
return root;
|
|
737
|
+
}
|
|
738
|
+
|
|
739
|
+
test("a Desktop profiles write that makes a pin stale reports the pin once, as external", (t) => {
|
|
740
|
+
const root = scratchRoot(t, "gentle-desktop-watch-p1-");
|
|
741
|
+
const configHome = join(root, "config");
|
|
742
|
+
const cwd = join(root, "ws");
|
|
743
|
+
mkdirSync(cwd, { recursive: true });
|
|
744
|
+
writeJson(profilesFilePath(configHome), profilesNamed(["team", "ops"], "team"));
|
|
745
|
+
writeJson(repoProfileDeclarationPath(cwd), pinFile("ops"));
|
|
746
|
+
const clock = fakeClock();
|
|
747
|
+
const watches = fakeWatches();
|
|
748
|
+
const bridge = new DesktopConfigBridge(
|
|
749
|
+
{ configHome, agentHome: join(root, "agent"), resolveWorktree: worktreeAt },
|
|
750
|
+
{ watch: watches.factory, timers: clock },
|
|
751
|
+
);
|
|
752
|
+
const events: Array<Record<string, unknown>> = [];
|
|
753
|
+
bridge.attach({ cwd } as unknown as ExtensionContext);
|
|
754
|
+
bridge.wire((_event, data) => events.push(data));
|
|
755
|
+
|
|
756
|
+
const read = bridge.handle("get_config", { store: "profiles" }) as any;
|
|
757
|
+
const out = bridge.handle("set_config", {
|
|
758
|
+
store: "profiles",
|
|
759
|
+
data: profilesNamed(["team"], "team"),
|
|
760
|
+
expectedRevision: read.data.writeTargets[0].writeRevision,
|
|
761
|
+
}) as any;
|
|
762
|
+
assert.equal(out.ok, true);
|
|
763
|
+
assert.equal(out.event.data.store, "profiles");
|
|
764
|
+
assert.equal(out.event.data.source, "desktop");
|
|
765
|
+
|
|
766
|
+
watches.fire(dirname(profilesFilePath(configHome)), "profiles.json");
|
|
767
|
+
clock.advance(DESKTOP_CHANGE_DEBOUNCE_MS);
|
|
768
|
+
watches.fire(dirname(profilesFilePath(configHome)), "profiles.json");
|
|
769
|
+
clock.advance(DESKTOP_CHANGE_DEBOUNCE_MS);
|
|
770
|
+
// `source` answers "was this a Desktop write to this store": the pin went stale
|
|
771
|
+
// as a consequence, so it is reported once, as external; profiles is not echoed.
|
|
772
|
+
assert.deepEqual(
|
|
773
|
+
events.map((data) => [data.store, data.source, data.status]),
|
|
774
|
+
[["pins", "external", "invalid"]],
|
|
775
|
+
);
|
|
776
|
+
bridge.reset();
|
|
777
|
+
});
|
|
778
|
+
|
|
779
|
+
test("a cwd re-target reports cwd-dependent stores that changed and re-baselines them", (t) => {
|
|
780
|
+
const root = scratchRoot(t, "gentle-desktop-watch-p2-");
|
|
781
|
+
const configHome = join(root, "config");
|
|
782
|
+
const first = join(root, "a");
|
|
783
|
+
const second = join(root, "b");
|
|
784
|
+
writeJson(profilesFilePath(configHome), profilesNamed(["team", "ops"], "team"));
|
|
785
|
+
writeJson(repoProfileDeclarationPath(first), pinFile("ops"));
|
|
786
|
+
mkdirSync(second, { recursive: true });
|
|
787
|
+
const clock = fakeClock();
|
|
788
|
+
const watches = fakeWatches();
|
|
789
|
+
const bridge = new DesktopConfigBridge(
|
|
790
|
+
{ configHome, agentHome: join(root, "agent"), resolveWorktree: worktreeAt },
|
|
791
|
+
{ watch: watches.factory, timers: clock },
|
|
792
|
+
);
|
|
793
|
+
const events: Array<Record<string, unknown>> = [];
|
|
794
|
+
bridge.attach({ cwd: first } as unknown as ExtensionContext);
|
|
795
|
+
bridge.wire((_event, data) => events.push(data));
|
|
796
|
+
|
|
797
|
+
bridge.attach({ cwd: second } as unknown as ExtensionContext);
|
|
798
|
+
assert.deepEqual(
|
|
799
|
+
events.map((data) => [data.store, data.source, data.status]),
|
|
800
|
+
[["pins", "external", "missing"]],
|
|
801
|
+
"the pins of the new cwd differ; models and subagents read the same in both",
|
|
802
|
+
);
|
|
803
|
+
|
|
804
|
+
// An unrelated external change afterwards reports only itself.
|
|
805
|
+
writeJson(fallbacksFilePath(configHome), { kind: FALLBACKS_KIND, version: FALLBACKS_VERSION, profiles: {} });
|
|
806
|
+
watches.fire(configHome, "profile-fallbacks.json");
|
|
807
|
+
clock.advance(DESKTOP_CHANGE_DEBOUNCE_MS);
|
|
808
|
+
assert.deepEqual(
|
|
809
|
+
events.map((data) => data.store),
|
|
810
|
+
["pins", "profile_fallbacks"],
|
|
811
|
+
);
|
|
812
|
+
|
|
813
|
+
// Re-binding the same cwd changes nothing and emits nothing.
|
|
814
|
+
bridge.attach({ cwd: second } as unknown as ExtensionContext);
|
|
815
|
+
assert.equal(events.length, 2);
|
|
816
|
+
bridge.reset();
|
|
817
|
+
});
|
|
818
|
+
|
|
819
|
+
test("a missing owner directory is watched through its nearest existing ancestor and upgraded once created", (t) => {
|
|
820
|
+
const root = scratchRoot(t, "gentle-desktop-watch-late-");
|
|
821
|
+
const target = join(root, "a", "b");
|
|
822
|
+
const clock = fakeClock();
|
|
823
|
+
const watches = fakeWatches();
|
|
824
|
+
let runs = 0;
|
|
825
|
+
const watcher = new DesktopDirectoryWatcher(() => (runs += 1), { watch: watches.factory, timers: clock });
|
|
826
|
+
assert.equal(watcher.start([{ dir: target, names: ["x.json"] }]), 1);
|
|
827
|
+
assert.deepEqual(watches.open().map((watch) => watch.dir), [root], "the nearest existing ancestor, not recursive");
|
|
828
|
+
|
|
829
|
+
watches.fire(root, "zzz");
|
|
830
|
+
watches.fire(root, "a");
|
|
831
|
+
assert.deepEqual(watches.open().map((watch) => watch.dir), [root], "no upgrade before the segment exists");
|
|
832
|
+
|
|
833
|
+
mkdirSync(join(root, "a"));
|
|
834
|
+
watches.fire(root, "a");
|
|
835
|
+
assert.deepEqual(watches.open().map((watch) => watch.dir), [join(root, "a")], "one level closer; the ancestor watcher is closed");
|
|
836
|
+
|
|
837
|
+
mkdirSync(target);
|
|
838
|
+
writeFileSync(join(target, "x.json"), "{}\n");
|
|
839
|
+
watches.fire(join(root, "a"), undefined);
|
|
840
|
+
assert.deepEqual(watches.open().map((watch) => watch.dir), [target], "upgraded to the real directory");
|
|
841
|
+
clock.advance(DESKTOP_CHANGE_DEBOUNCE_MS);
|
|
842
|
+
assert.equal(runs, 1, "the upgrade recomputes once, in case the file was written before the watcher");
|
|
843
|
+
|
|
844
|
+
watches.fire(target, "other.json");
|
|
845
|
+
clock.advance(DESKTOP_CHANGE_DEBOUNCE_MS);
|
|
846
|
+
assert.equal(runs, 1);
|
|
847
|
+
watches.fire(target, "x.json");
|
|
848
|
+
clock.advance(DESKTOP_CHANGE_DEBOUNCE_MS);
|
|
849
|
+
assert.equal(runs, 2);
|
|
850
|
+
|
|
851
|
+
watcher.dispose();
|
|
852
|
+
assert.deepEqual(watches.open(), []);
|
|
853
|
+
assert.equal(watches.all.length, 3, "one watcher per step, each closed");
|
|
854
|
+
});
|
|
855
|
+
|
|
856
|
+
test("a pending ancestor watcher is closed on dispose", (t) => {
|
|
857
|
+
const root = scratchRoot(t, "gentle-desktop-watch-late-dispose-");
|
|
858
|
+
const clock = fakeClock();
|
|
859
|
+
const watches = fakeWatches();
|
|
860
|
+
let runs = 0;
|
|
861
|
+
const watcher = new DesktopDirectoryWatcher(() => (runs += 1), { watch: watches.factory, timers: clock });
|
|
862
|
+
watcher.start([{ dir: join(root, "later"), names: ["x.json"] }]);
|
|
863
|
+
watcher.dispose();
|
|
864
|
+
assert.deepEqual(watches.open(), []);
|
|
865
|
+
mkdirSync(join(root, "later"));
|
|
866
|
+
for (const watch of watches.all) watch.onChange("later");
|
|
867
|
+
clock.advance(DESKTOP_CHANGE_DEBOUNCE_MS);
|
|
868
|
+
assert.equal(runs, 0);
|
|
869
|
+
assert.deepEqual(watches.open(), [], "a disposed watcher never upgrades");
|
|
870
|
+
});
|
|
871
|
+
|
|
872
|
+
const delay = (ms: number) => new Promise((resolve) => setTimeout(resolve, ms));
|
|
873
|
+
async function waitFor(condition: () => boolean, ms = 3000): Promise<void> {
|
|
874
|
+
for (let waited = 0; waited < ms && !condition(); waited += 25) await delay(25);
|
|
875
|
+
}
|
|
876
|
+
|
|
877
|
+
test("real fs.watch: a local pin written into a fresh git-common gentle-ai directory raises exactly one event", { timeout: 20_000 }, async (t) => {
|
|
878
|
+
const root = scratchRoot(t, "gentle-desktop-watch-real-pin-");
|
|
879
|
+
const configHome = join(root, "config");
|
|
880
|
+
const cwd = join(root, "ws");
|
|
881
|
+
mkdirSync(cwd, { recursive: true });
|
|
882
|
+
writeJson(profilesFilePath(configHome), profilesNamed(["team"], "team"));
|
|
883
|
+
const bridge = new DesktopConfigBridge({ configHome, agentHome: join(root, "agent"), resolveWorktree: worktreeAt });
|
|
884
|
+
const events: Array<Record<string, unknown>> = [];
|
|
885
|
+
bridge.attach({ cwd } as unknown as ExtensionContext);
|
|
886
|
+
bridge.wire((_event, data) => events.push(data));
|
|
887
|
+
t.after(() => bridge.reset());
|
|
888
|
+
await delay(100);
|
|
889
|
+
|
|
890
|
+
writeJson(localProfilePinPath(join(cwd, ".git-common")), pinFile("team"));
|
|
891
|
+
await waitFor(() => events.length > 0);
|
|
892
|
+
await delay(800);
|
|
893
|
+
assert.deepEqual(events.map((data) => [data.store, data.source, data.status]), [["pins", "external", "ok"]]);
|
|
894
|
+
});
|
|
895
|
+
|
|
896
|
+
// P3 from the verifier probe: real fs.watch and real timers.
|
|
897
|
+
test("real fs.watch: rename-replace, Desktop write, delete, recreate, late .pi directory, reset", { timeout: 30_000 }, async (t) => {
|
|
898
|
+
const root = scratchRoot(t, "gentle-desktop-watch-real-p3-");
|
|
899
|
+
const configHome = join(root, "config");
|
|
900
|
+
const cwd = join(root, "ws");
|
|
901
|
+
const agentHome = join(root, "agent");
|
|
902
|
+
mkdirSync(cwd, { recursive: true });
|
|
903
|
+
mkdirSync(agentHome, { recursive: true });
|
|
904
|
+
const path = profilesFilePath(configHome);
|
|
905
|
+
writeJson(path, profilesNamed(["team", "ops"], "team"));
|
|
906
|
+
const bridge = new DesktopConfigBridge({ configHome, agentHome, resolveWorktree: worktreeAt });
|
|
907
|
+
const events: Array<Record<string, unknown>> = [];
|
|
908
|
+
bridge.attach({ cwd } as unknown as ExtensionContext);
|
|
909
|
+
bridge.wire((_event, data) => events.push(data));
|
|
910
|
+
t.after(() => bridge.reset());
|
|
911
|
+
await delay(100);
|
|
912
|
+
const since = (start: number) => events.slice(start).map((data) => [data.store, data.status]);
|
|
913
|
+
|
|
914
|
+
// Atomic temp + rename replace.
|
|
915
|
+
writeFileSync(`${path}.tmp123`, JSON.stringify(profilesNamed(["team", "ops"], "ops")));
|
|
916
|
+
renameSync(`${path}.tmp123`, path);
|
|
917
|
+
await waitFor(() => events.length > 0);
|
|
918
|
+
await delay(600);
|
|
919
|
+
assert.deepEqual(
|
|
920
|
+
events.map((data) => [data.store, data.source, Object.keys(data).sort().join(",")]),
|
|
921
|
+
[["profiles", "external", "revision,scope,source,status,store"]],
|
|
922
|
+
);
|
|
923
|
+
|
|
924
|
+
// A Desktop write is never echoed by the real watcher.
|
|
925
|
+
let start = events.length;
|
|
926
|
+
const read = bridge.handle("get_config", { store: "profiles" }) as any;
|
|
927
|
+
const out = bridge.handle("set_config", {
|
|
928
|
+
store: "profiles",
|
|
929
|
+
data: profilesNamed(["team", "ops"], "team"),
|
|
930
|
+
expectedRevision: read.data.writeTargets[0].writeRevision,
|
|
931
|
+
}) as any;
|
|
932
|
+
assert.equal(out.ok, true);
|
|
933
|
+
await delay(800);
|
|
934
|
+
assert.deepEqual(since(start), []);
|
|
935
|
+
|
|
936
|
+
start = events.length;
|
|
937
|
+
unlinkSync(path);
|
|
938
|
+
await waitFor(() => events.length > start);
|
|
939
|
+
await delay(600);
|
|
940
|
+
assert.deepEqual(since(start), [["profiles", "missing"]]);
|
|
941
|
+
|
|
942
|
+
start = events.length;
|
|
943
|
+
writeJson(path, profilesNamed(["team"], "team"));
|
|
944
|
+
await waitFor(() => events.length > start);
|
|
945
|
+
await delay(600);
|
|
946
|
+
assert.deepEqual(since(start), [["profiles", "ok"]]);
|
|
947
|
+
|
|
948
|
+
// `.pi` did not exist at start: the cwd ancestor watcher upgrades to it.
|
|
949
|
+
start = events.length;
|
|
950
|
+
writeJson(join(cwd, ".pi", "subagents.json"), { agents: {} });
|
|
951
|
+
writeJson(repoProfileDeclarationPath(cwd), pinFile("team"));
|
|
952
|
+
await waitFor(() => new Set(events.slice(start).map((data) => data.store)).size >= 2);
|
|
953
|
+
await delay(800);
|
|
954
|
+
const late = since(start).map(([store]) => store as string);
|
|
955
|
+
assert.deepEqual([...late].sort(), ["pins", "subagents"], "one event per changed store, no duplicates");
|
|
956
|
+
|
|
957
|
+
bridge.reset();
|
|
958
|
+
start = events.length;
|
|
959
|
+
writeJson(path, profilesNamed(["ops"], "ops"));
|
|
960
|
+
await delay(600);
|
|
961
|
+
assert.deepEqual(since(start), [], "nothing after reset");
|
|
962
|
+
});
|
|
963
|
+
|
|
964
|
+
// P4 from the verifier probe.
|
|
965
|
+
test("an external permission change right after a Desktop set's response is still reported", async () => {
|
|
966
|
+
const clock = fakeClock();
|
|
967
|
+
let state = { mode: "normal", defaultMode: "normal" };
|
|
968
|
+
let notify = () => {};
|
|
969
|
+
const adapter = {
|
|
970
|
+
read: async () => "OFF",
|
|
971
|
+
toggle: async () => {},
|
|
972
|
+
readSnapshot: async () => ({ yolo: "OFF", mode: state.mode, defaultMode: state.defaultMode }),
|
|
973
|
+
setMode: async (mode: string) => {
|
|
974
|
+
state = { ...state, mode };
|
|
975
|
+
notify();
|
|
976
|
+
return true;
|
|
977
|
+
},
|
|
978
|
+
observe: (refresh: () => void) => {
|
|
979
|
+
notify = refresh;
|
|
980
|
+
return () => (notify = () => {});
|
|
981
|
+
},
|
|
982
|
+
dispose: () => {},
|
|
983
|
+
};
|
|
984
|
+
const bridge = new DesktopPermissionBridge({} as ExtensionAPI, async () => adapter as never, { timers: clock });
|
|
985
|
+
const events: Array<Record<string, unknown>> = [];
|
|
986
|
+
bridge.attach({ cwd: "/w" } as unknown as ExtensionContext);
|
|
987
|
+
await bridge.wire((_event, data) => events.push(data));
|
|
988
|
+
const out = (await bridge.handle("set_permission_mode", { mode: "yolo" })) as any;
|
|
989
|
+
assert.equal(out.event.data.source, "desktop");
|
|
990
|
+
state = { ...state, mode: "auto" };
|
|
991
|
+
notify();
|
|
992
|
+
clock.advance(DESKTOP_CHANGE_DEBOUNCE_MS);
|
|
993
|
+
await settle();
|
|
994
|
+
assert.deepEqual(events, [{ mode: "auto", previous_mode: "yolo", default_mode: "normal", persisted: false, source: "external" }]);
|
|
995
|
+
|
|
996
|
+
// A throwing emitter never propagates into the owner observer or the timer.
|
|
997
|
+
const throwing = new DesktopPermissionBridge({} as ExtensionAPI, async () => adapter as never, { timers: clock });
|
|
998
|
+
throwing.attach({ cwd: "/w" } as unknown as ExtensionContext);
|
|
999
|
+
await throwing.wire(() => {
|
|
1000
|
+
throw new Error("closed");
|
|
1001
|
+
});
|
|
1002
|
+
state = { ...state, mode: "normal" };
|
|
1003
|
+
assert.doesNotThrow(() => notify());
|
|
1004
|
+
assert.doesNotThrow(() => clock.advance(DESKTOP_CHANGE_DEBOUNCE_MS));
|
|
1005
|
+
await settle();
|
|
1006
|
+
throwing.reset();
|
|
1007
|
+
bridge.reset();
|
|
1008
|
+
});
|
|
1009
|
+
|
|
1010
|
+
// P5 from the verifier probe.
|
|
1011
|
+
test("a permission re-read still in flight when the session resets never emits", async () => {
|
|
1012
|
+
const clock = fakeClock();
|
|
1013
|
+
let state = { mode: "normal", defaultMode: "normal" };
|
|
1014
|
+
let notify = () => {};
|
|
1015
|
+
let hold: (() => void) | undefined;
|
|
1016
|
+
const adapter = {
|
|
1017
|
+
read: async () => "OFF",
|
|
1018
|
+
toggle: async () => {},
|
|
1019
|
+
readSnapshot: async () => {
|
|
1020
|
+
if (hold === undefined && state.mode === "yolo") await new Promise<void>((resolve) => (hold = resolve));
|
|
1021
|
+
return { yolo: "OFF", mode: state.mode, defaultMode: state.defaultMode };
|
|
1022
|
+
},
|
|
1023
|
+
observe: (refresh: () => void) => {
|
|
1024
|
+
notify = refresh;
|
|
1025
|
+
return () => (notify = () => {});
|
|
1026
|
+
},
|
|
1027
|
+
dispose: () => {},
|
|
1028
|
+
};
|
|
1029
|
+
const bridge = new DesktopPermissionBridge({} as ExtensionAPI, async () => adapter as never, { timers: clock });
|
|
1030
|
+
const events: Array<Record<string, unknown>> = [];
|
|
1031
|
+
bridge.attach({ cwd: "/w" } as unknown as ExtensionContext);
|
|
1032
|
+
await bridge.wire((_event, data) => events.push(data));
|
|
1033
|
+
state = { ...state, mode: "yolo" };
|
|
1034
|
+
notify();
|
|
1035
|
+
clock.advance(DESKTOP_CHANGE_DEBOUNCE_MS);
|
|
1036
|
+
await delay(5);
|
|
1037
|
+
bridge.reset();
|
|
1038
|
+
hold?.();
|
|
1039
|
+
await settle();
|
|
1040
|
+
assert.deepEqual(events, []);
|
|
1041
|
+
});
|
|
1042
|
+
|
|
1043
|
+
// ---- Native review follow-ups (#3321): pending recompute on re-target, removed directories, wire() rejections ----
|
|
1044
|
+
|
|
1045
|
+
test("a change debounced before a cwd re-target is still reported", (t) => {
|
|
1046
|
+
const root = scratchRoot(t, "gentle-desktop-watch-r3-");
|
|
1047
|
+
const configHome = join(root, "config");
|
|
1048
|
+
const first = join(root, "a");
|
|
1049
|
+
const second = join(root, "b");
|
|
1050
|
+
for (const directory of [first, second]) mkdirSync(directory, { recursive: true });
|
|
1051
|
+
writeJson(profilesFilePath(configHome), profilesNamed(["team", "ops"], "team"));
|
|
1052
|
+
const clock = fakeClock();
|
|
1053
|
+
const watches = fakeWatches();
|
|
1054
|
+
const bridge = new DesktopConfigBridge(
|
|
1055
|
+
{ configHome, agentHome: join(root, "agent"), resolveWorktree: worktreeAt },
|
|
1056
|
+
{ watch: watches.factory, timers: clock },
|
|
1057
|
+
);
|
|
1058
|
+
const events: Array<Record<string, unknown>> = [];
|
|
1059
|
+
bridge.attach({ cwd: first } as unknown as ExtensionContext);
|
|
1060
|
+
bridge.wire((_event, data) => events.push(data));
|
|
1061
|
+
|
|
1062
|
+
writeJson(profilesFilePath(configHome), profilesNamed(["team", "ops"], "ops"));
|
|
1063
|
+
watches.fire(configHome, "profiles.json");
|
|
1064
|
+
// The window has not closed yet when a command binds another cwd.
|
|
1065
|
+
bridge.attach({ cwd: second } as unknown as ExtensionContext);
|
|
1066
|
+
clock.advance(DESKTOP_CHANGE_DEBOUNCE_MS * 2);
|
|
1067
|
+
assert.deepEqual(
|
|
1068
|
+
events.map((data) => [data.store, data.source]),
|
|
1069
|
+
[["profiles", "external"]],
|
|
1070
|
+
"the pending global change is flushed by the re-target, once",
|
|
1071
|
+
);
|
|
1072
|
+
bridge.reset();
|
|
1073
|
+
});
|
|
1074
|
+
|
|
1075
|
+
test("a removed owner directory is re-armed through its ancestor and reports its recreation once", (t) => {
|
|
1076
|
+
const root = scratchRoot(t, "gentle-desktop-watch-r4-");
|
|
1077
|
+
const configHome = join(root, "config");
|
|
1078
|
+
const cwd = join(root, "ws");
|
|
1079
|
+
mkdirSync(cwd, { recursive: true });
|
|
1080
|
+
writeJson(profilesFilePath(configHome), profilesNamed(["team"], "team"));
|
|
1081
|
+
const clock = fakeClock();
|
|
1082
|
+
const watches = fakeWatches();
|
|
1083
|
+
const bridge = new DesktopConfigBridge(
|
|
1084
|
+
{ configHome, agentHome: join(root, "agent"), resolveWorktree: worktreeAt },
|
|
1085
|
+
{ watch: watches.factory, timers: clock },
|
|
1086
|
+
);
|
|
1087
|
+
const events: Array<Record<string, unknown>> = [];
|
|
1088
|
+
bridge.attach({ cwd } as unknown as ExtensionContext);
|
|
1089
|
+
bridge.wire((_event, data) => events.push(data));
|
|
1090
|
+
|
|
1091
|
+
rmSync(configHome, { recursive: true, force: true });
|
|
1092
|
+
assert.equal(watches.remove(configHome), 1);
|
|
1093
|
+
clock.advance(DESKTOP_CHANGE_DEBOUNCE_MS);
|
|
1094
|
+
assert.deepEqual(events.map((data) => [data.store, data.status]), [["profiles", "missing"]]);
|
|
1095
|
+
assert.ok(
|
|
1096
|
+
watches.open().some((watch) => watch.dir === root),
|
|
1097
|
+
"the nearest existing ancestor watches for the directory to come back",
|
|
1098
|
+
);
|
|
1099
|
+
|
|
1100
|
+
mkdirSync(configHome);
|
|
1101
|
+
writeJson(profilesFilePath(configHome), profilesNamed(["ops"], "ops"));
|
|
1102
|
+
watches.fire(root, "config");
|
|
1103
|
+
assert.ok(watches.open().some((watch) => watch.dir === configHome), "upgraded to the recreated directory");
|
|
1104
|
+
watches.fire(configHome, "profiles.json");
|
|
1105
|
+
clock.advance(DESKTOP_CHANGE_DEBOUNCE_MS);
|
|
1106
|
+
assert.deepEqual(
|
|
1107
|
+
events.slice(1).map((data) => [data.store, data.source, data.status]),
|
|
1108
|
+
[["profiles", "external", "ok"]],
|
|
1109
|
+
"exactly one event for the recreated store",
|
|
1110
|
+
);
|
|
1111
|
+
bridge.reset();
|
|
1112
|
+
assert.deepEqual(watches.open(), []);
|
|
1113
|
+
});
|
|
1114
|
+
|
|
1115
|
+
test("wire() never rejects when the permission owner throws, and leaves no external events", async () => {
|
|
1116
|
+
const clock = fakeClock();
|
|
1117
|
+
let notify: (() => void) | undefined;
|
|
1118
|
+
const adapter = {
|
|
1119
|
+
read: async () => "OFF",
|
|
1120
|
+
toggle: async () => {},
|
|
1121
|
+
get readSnapshot(): never {
|
|
1122
|
+
throw new Error("owner torn down");
|
|
1123
|
+
},
|
|
1124
|
+
observe: (refresh: () => void) => {
|
|
1125
|
+
notify = refresh;
|
|
1126
|
+
return () => (notify = undefined);
|
|
1127
|
+
},
|
|
1128
|
+
dispose: () => {},
|
|
1129
|
+
};
|
|
1130
|
+
const unhandled: unknown[] = [];
|
|
1131
|
+
const onUnhandled = (reason: unknown) => unhandled.push(reason);
|
|
1132
|
+
process.on("unhandledRejection", onUnhandled);
|
|
1133
|
+
try {
|
|
1134
|
+
const bridge = new DesktopPermissionBridge({} as ExtensionAPI, async () => adapter as never, { timers: clock });
|
|
1135
|
+
const events: unknown[] = [];
|
|
1136
|
+
bridge.attach({ cwd: "/w" } as unknown as ExtensionContext);
|
|
1137
|
+
await assert.doesNotReject(bridge.wire((_event, data) => events.push(data)));
|
|
1138
|
+
notify?.();
|
|
1139
|
+
clock.advance(DESKTOP_CHANGE_DEBOUNCE_MS);
|
|
1140
|
+
await settle();
|
|
1141
|
+
assert.deepEqual(events, []);
|
|
1142
|
+
|
|
1143
|
+
const failing = new DesktopPermissionBridge(
|
|
1144
|
+
{} as ExtensionAPI,
|
|
1145
|
+
(() => {
|
|
1146
|
+
throw new Error("discovery exploded");
|
|
1147
|
+
}) as never,
|
|
1148
|
+
{ timers: clock },
|
|
1149
|
+
);
|
|
1150
|
+
failing.attach({ cwd: "/w" } as unknown as ExtensionContext);
|
|
1151
|
+
await assert.doesNotReject(failing.wire(() => {}));
|
|
1152
|
+
bridge.reset();
|
|
1153
|
+
failing.reset();
|
|
1154
|
+
await settle();
|
|
1155
|
+
assert.deepEqual(unhandled, []);
|
|
1156
|
+
} finally {
|
|
1157
|
+
process.off("unhandledRejection", onUnhandled);
|
|
1158
|
+
}
|
|
1159
|
+
});
|