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,647 @@
|
|
|
1
|
+
import assert from "node:assert/strict";
|
|
2
|
+
import { mkdirSync, mkdtempSync, rmSync, writeFileSync } from "node:fs";
|
|
3
|
+
import { tmpdir } from "node:os";
|
|
4
|
+
import { join } from "node:path";
|
|
5
|
+
import { test } from "node:test";
|
|
6
|
+
import desktopRpc from "../extensions/gentle-desktop-rpc.ts";
|
|
7
|
+
import { DESKTOP_RPC_SCHEMA, DESKTOP_RPC_WIDGET } from "../lib/desktop-rpc.ts";
|
|
8
|
+
import {
|
|
9
|
+
DESKTOP_SESSIONS_EVENTS,
|
|
10
|
+
DESKTOP_SESSIONS_FIRST_MESSAGE_MAX,
|
|
11
|
+
DESKTOP_SESSIONS_METHODS,
|
|
12
|
+
INVALID_SESSIONS_PARAMS,
|
|
13
|
+
SESSION_NOT_FOUND,
|
|
14
|
+
SESSION_SWITCHING,
|
|
15
|
+
projectDesktopSession,
|
|
16
|
+
SESSIONS_UNAVAILABLE,
|
|
17
|
+
parseListSessionsParams,
|
|
18
|
+
parseSwitchSessionParams,
|
|
19
|
+
sessionProjectName,
|
|
20
|
+
} from "../lib/desktop-rpc-sessions.ts";
|
|
21
|
+
import { DesktopSessionsBridge } from "../lib/desktop-sessions-service.ts";
|
|
22
|
+
import { INTERACTIVE_HOST_ENV } from "../lib/rpc-host.ts";
|
|
23
|
+
|
|
24
|
+
type WidgetCall = { key: string; lines: string[] };
|
|
25
|
+
|
|
26
|
+
// ---- Fixtures: real Pi session files in an isolated root ----
|
|
27
|
+
|
|
28
|
+
interface SeedSession {
|
|
29
|
+
id: string;
|
|
30
|
+
cwd: string;
|
|
31
|
+
/** Header timestamp; message timestamps follow it by one second each. */
|
|
32
|
+
at: number;
|
|
33
|
+
messages?: Array<{ role: "user" | "assistant"; text: string }>;
|
|
34
|
+
name?: string;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/** Write one session file in Pi's own on-disk shape (header, optional name, messages). */
|
|
38
|
+
function writeSession(dir: string, seed: SeedSession): string {
|
|
39
|
+
mkdirSync(dir, { recursive: true });
|
|
40
|
+
const stamp = new Date(seed.at).toISOString();
|
|
41
|
+
const lines: unknown[] = [{ type: "session", version: 3, id: seed.id, timestamp: stamp, cwd: seed.cwd }];
|
|
42
|
+
let parentId: string | null = null;
|
|
43
|
+
(seed.messages ?? []).forEach((message, index) => {
|
|
44
|
+
const id = `${seed.id}-m${index}`;
|
|
45
|
+
const at = seed.at + (index + 1) * 1000;
|
|
46
|
+
lines.push({
|
|
47
|
+
type: "message",
|
|
48
|
+
id,
|
|
49
|
+
parentId,
|
|
50
|
+
timestamp: new Date(at).toISOString(),
|
|
51
|
+
message: { role: message.role, content: [{ type: "text", text: message.text }], timestamp: at },
|
|
52
|
+
});
|
|
53
|
+
parentId = id;
|
|
54
|
+
});
|
|
55
|
+
if (seed.name !== undefined) {
|
|
56
|
+
lines.push({ type: "session_info", id: `${seed.id}-info`, parentId, timestamp: stamp, name: seed.name });
|
|
57
|
+
}
|
|
58
|
+
const file = join(dir, `${stamp.replace(/[:.]/g, "-")}_${seed.id}.jsonl`);
|
|
59
|
+
writeFileSync(file, `${lines.map((line) => JSON.stringify(line)).join("\n")}\n`);
|
|
60
|
+
return file;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
interface Root {
|
|
64
|
+
root: string;
|
|
65
|
+
projectCwd: string;
|
|
66
|
+
otherCwd: string;
|
|
67
|
+
customDir: string;
|
|
68
|
+
agentDir: string;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
function makeRoot(t: test.TestContext): Root {
|
|
72
|
+
const root = mkdtempSync(join(tmpdir(), "desktop-rpc-sessions-"));
|
|
73
|
+
t.after(() => rmSync(root, { recursive: true, force: true }));
|
|
74
|
+
const projectCwd = join(root, "work", "gentle-shell");
|
|
75
|
+
const otherCwd = join(root, "work", "other-app");
|
|
76
|
+
mkdirSync(projectCwd, { recursive: true });
|
|
77
|
+
mkdirSync(otherCwd, { recursive: true });
|
|
78
|
+
return { root, projectCwd, otherCwd, customDir: join(root, "custom-sessions"), agentDir: join(root, "agent") };
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
function interactiveHost(t: test.TestContext): void {
|
|
82
|
+
const previous = process.env[INTERACTIVE_HOST_ENV];
|
|
83
|
+
process.env[INTERACTIVE_HOST_ENV] = "1";
|
|
84
|
+
t.after(() => {
|
|
85
|
+
if (previous === undefined) delete process.env[INTERACTIVE_HOST_ENV];
|
|
86
|
+
else process.env[INTERACTIVE_HOST_ENV] = previous;
|
|
87
|
+
});
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
/** Point Pi's default agent directory (and so its default sessions root) at the isolated root. */
|
|
91
|
+
function isolatedAgentDir(t: test.TestContext, dir: string): void {
|
|
92
|
+
const previous = process.env.PI_CODING_AGENT_DIR;
|
|
93
|
+
process.env.PI_CODING_AGENT_DIR = dir;
|
|
94
|
+
t.after(() => {
|
|
95
|
+
if (previous === undefined) delete process.env.PI_CODING_AGENT_DIR;
|
|
96
|
+
else process.env.PI_CODING_AGENT_DIR = previous;
|
|
97
|
+
});
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
interface SessionLocation {
|
|
101
|
+
cwd: string;
|
|
102
|
+
sessionDir: string;
|
|
103
|
+
usesDefault: boolean;
|
|
104
|
+
currentId: string;
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
type SwitchBehavior = "replace" | "cancel" | "throw";
|
|
108
|
+
|
|
109
|
+
/**
|
|
110
|
+
* Loads the real Desktop extension with a fake `pi`. The command context's
|
|
111
|
+
* `sessionManager` exposes Pi's own session-location getters over real files,
|
|
112
|
+
* so listing and lookup run through Pi's real `SessionManager`. `switchSession`
|
|
113
|
+
* reproduces Pi's replacement order: the old instance gets `session_shutdown`,
|
|
114
|
+
* the replacement gets `session_start`, then `withSession` runs with a fresh
|
|
115
|
+
* command context bound to the new session.
|
|
116
|
+
*
|
|
117
|
+
* `holdSwitch` keeps the switch in flight (before teardown) until it resolves.
|
|
118
|
+
* `newInstance` models Pi loading a fresh extension instance for the
|
|
119
|
+
* replacement: this instance is shut down and never restarted.
|
|
120
|
+
*/
|
|
121
|
+
function harness(t: test.TestContext, location: SessionLocation, options: { switchBehavior?: SwitchBehavior; withSwitch?: boolean; withSessionManager?: boolean; holdSwitch?: Promise<void>; newInstance?: boolean } = {}) {
|
|
122
|
+
interactiveHost(t);
|
|
123
|
+
const commands = new Map<string, { handler: (args: string, ctx: any) => Promise<void> }>();
|
|
124
|
+
const events = new Map<string, Array<(event: unknown, ctx: any) => void>>();
|
|
125
|
+
const pi = {
|
|
126
|
+
registerCommand(name: string, command: any) { commands.set(name, command); },
|
|
127
|
+
on(name: string, handler: any) { events.set(name, [...(events.get(name) ?? []), handler]); },
|
|
128
|
+
events: { emit() {}, on() { return () => {}; } },
|
|
129
|
+
};
|
|
130
|
+
desktopRpc(pi as any);
|
|
131
|
+
const widgets: WidgetCall[] = [];
|
|
132
|
+
const switches: string[] = [];
|
|
133
|
+
const state = { ...location };
|
|
134
|
+
const fire = (name: string, ctx: unknown) => { for (const handler of events.get(name) ?? []) handler({}, ctx); };
|
|
135
|
+
const makeCtx = (): any => {
|
|
136
|
+
const ctx: any = {
|
|
137
|
+
mode: "rpc",
|
|
138
|
+
cwd: state.cwd,
|
|
139
|
+
ui: { setWidget(key: string, lines: string[]) { widgets.push({ key, lines }); } },
|
|
140
|
+
};
|
|
141
|
+
if (options.withSessionManager !== false) {
|
|
142
|
+
ctx.sessionManager = {
|
|
143
|
+
getCwd: () => state.cwd,
|
|
144
|
+
getSessionDir: () => state.sessionDir,
|
|
145
|
+
usesDefaultSessionDir: () => state.usesDefault,
|
|
146
|
+
getSessionId: () => state.currentId,
|
|
147
|
+
};
|
|
148
|
+
}
|
|
149
|
+
if (options.withSwitch !== false) {
|
|
150
|
+
ctx.switchSession = async (sessionPath: string, switchOptions?: { withSession?: (next: unknown) => Promise<void> }) => {
|
|
151
|
+
switches.push(sessionPath);
|
|
152
|
+
await options.holdSwitch;
|
|
153
|
+
const behavior = options.switchBehavior ?? "replace";
|
|
154
|
+
if (behavior === "cancel") return { cancelled: true };
|
|
155
|
+
if (behavior === "throw") throw new Error(`Session cwd missing: ${sessionPath}`);
|
|
156
|
+
fire("session_shutdown", ctx);
|
|
157
|
+
state.currentId = sessionPath;
|
|
158
|
+
const next = makeCtx();
|
|
159
|
+
if (!options.newInstance) fire("session_start", next);
|
|
160
|
+
await switchOptions?.withSession?.(next);
|
|
161
|
+
return { cancelled: false };
|
|
162
|
+
};
|
|
163
|
+
}
|
|
164
|
+
return ctx;
|
|
165
|
+
};
|
|
166
|
+
const ctx = makeCtx();
|
|
167
|
+
return {
|
|
168
|
+
ctx,
|
|
169
|
+
widgets,
|
|
170
|
+
switches,
|
|
171
|
+
state,
|
|
172
|
+
start() { fire("session_start", ctx); },
|
|
173
|
+
async invoke(request: unknown, targetCtx: any = ctx) {
|
|
174
|
+
const raw = typeof request === "string" ? request : JSON.stringify(request);
|
|
175
|
+
await commands.get("gentle:desktop")!.handler(raw, targetCtx);
|
|
176
|
+
},
|
|
177
|
+
payloads(): any[] {
|
|
178
|
+
return widgets.map((call) => {
|
|
179
|
+
assert.equal(call.key, DESKTOP_RPC_WIDGET);
|
|
180
|
+
assert.equal(call.lines.length, 1);
|
|
181
|
+
return JSON.parse(call.lines[0]!);
|
|
182
|
+
});
|
|
183
|
+
},
|
|
184
|
+
};
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
function request(requestId: string, method: string, params: Record<string, unknown> = {}) {
|
|
188
|
+
return { schema: DESKTOP_RPC_SCHEMA, requestId, method, params };
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
function responseFor(payloads: any[], requestId: string): any {
|
|
192
|
+
const matches = payloads.filter((payload) => payload.kind === "response" && payload.requestId === requestId);
|
|
193
|
+
assert.equal(matches.length, 1, `exactly one response for ${requestId}`);
|
|
194
|
+
return matches[0];
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
/** Three sessions for the project and one for another project, all in one custom directory. */
|
|
198
|
+
function seedCustom(root: Root) {
|
|
199
|
+
const base = Date.UTC(2026, 10, 1);
|
|
200
|
+
const oldest = writeSession(root.customDir, { id: "s-old", cwd: root.projectCwd, at: base, messages: [{ role: "user", text: "first question" }] });
|
|
201
|
+
const middle = writeSession(root.customDir, {
|
|
202
|
+
id: "s-mid",
|
|
203
|
+
cwd: root.projectCwd,
|
|
204
|
+
at: base + 60_000,
|
|
205
|
+
name: "Release prep",
|
|
206
|
+
messages: [{ role: "user", text: `secret-ish long\n${"x".repeat(400)}` }, { role: "assistant", text: "assistant body text" }],
|
|
207
|
+
});
|
|
208
|
+
const newest = writeSession(root.customDir, { id: "s-new", cwd: root.projectCwd, at: base + 120_000, messages: [{ role: "user", text: "newest" }, { role: "assistant", text: "ok" }] });
|
|
209
|
+
const foreign = writeSession(root.customDir, { id: "s-foreign", cwd: root.otherCwd, at: base + 180_000, messages: [{ role: "user", text: "other project" }] });
|
|
210
|
+
return { oldest, middle, newest, foreign, base };
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
function customLocation(root: Root, currentId = "s-new"): SessionLocation {
|
|
214
|
+
return { cwd: root.projectCwd, sessionDir: root.customDir, usesDefault: false, currentId };
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
function assertNoPrivateFields(value: unknown, root: Root): void {
|
|
218
|
+
const text = JSON.stringify(value);
|
|
219
|
+
assert.equal(text.includes(root.root), false, "no absolute path crosses the wire");
|
|
220
|
+
assert.equal(text.includes(root.root.replace(/\\/g, "\\\\")), false, "no escaped absolute path crosses the wire");
|
|
221
|
+
assert.equal(text.includes(".jsonl"), false, "no session file crosses the wire");
|
|
222
|
+
assert.equal(text.includes("assistant body text"), false, "no full message text crosses the wire");
|
|
223
|
+
for (const key of ["path", "cwd", "allMessagesText", "parentSessionPath", "created"]) {
|
|
224
|
+
assert.equal(text.includes(`"${key}"`), false, `no ${key} field crosses the wire`);
|
|
225
|
+
}
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
// ---- Contract ----
|
|
229
|
+
|
|
230
|
+
test("the sessions slice advertises two methods and no event", async (t) => {
|
|
231
|
+
assert.deepEqual([...DESKTOP_SESSIONS_METHODS], ["list_sessions", "switch_session"]);
|
|
232
|
+
assert.deepEqual([...DESKTOP_SESSIONS_EVENTS], []);
|
|
233
|
+
const root = makeRoot(t);
|
|
234
|
+
const app = harness(t, customLocation(root));
|
|
235
|
+
app.start();
|
|
236
|
+
await app.invoke(request("caps", "capabilities"));
|
|
237
|
+
const caps = responseFor(app.payloads(), "caps");
|
|
238
|
+
assert.equal(caps.ok, true);
|
|
239
|
+
const at = caps.data.methods.indexOf("list_sessions");
|
|
240
|
+
assert.notEqual(at, -1);
|
|
241
|
+
assert.deepEqual(caps.data.methods.slice(at, at + 2), ["list_sessions", "switch_session"]);
|
|
242
|
+
assert.equal(caps.data.events.includes("list_sessions"), false);
|
|
243
|
+
});
|
|
244
|
+
|
|
245
|
+
test("list params are optional scope, limit 1-50, and an opaque cursor; anything else is invalid_request", () => {
|
|
246
|
+
assert.deepEqual(parseListSessionsParams({}), { scope: "project", limit: 20 });
|
|
247
|
+
assert.deepEqual(parseListSessionsParams({ scope: "all", limit: 50 }), { scope: "all", limit: 50 });
|
|
248
|
+
assert.deepEqual(parseListSessionsParams({ limit: 1 }), { scope: "project", limit: 1 });
|
|
249
|
+
for (const bad of [
|
|
250
|
+
{ scope: "global" },
|
|
251
|
+
{ scope: 1 },
|
|
252
|
+
{ limit: 0 },
|
|
253
|
+
{ limit: 51 },
|
|
254
|
+
{ limit: 1.5 },
|
|
255
|
+
{ limit: "20" },
|
|
256
|
+
{ cursor: "" },
|
|
257
|
+
{ cursor: 3 },
|
|
258
|
+
{ cursor: "not a cursor" },
|
|
259
|
+
{ path: "/tmp/x.jsonl" },
|
|
260
|
+
{ sessionDir: "/tmp" },
|
|
261
|
+
]) {
|
|
262
|
+
assert.deepEqual(parseListSessionsParams(bad as Record<string, unknown>), { error: INVALID_SESSIONS_PARAMS }, JSON.stringify(bad));
|
|
263
|
+
}
|
|
264
|
+
});
|
|
265
|
+
|
|
266
|
+
test("switch params are exactly an id plus an optional scope; anything else is invalid_request", () => {
|
|
267
|
+
assert.deepEqual(parseSwitchSessionParams({ id: "abc" }), { id: "abc", scope: "project" });
|
|
268
|
+
assert.deepEqual(parseSwitchSessionParams({ id: "abc", scope: "all" }), { id: "abc", scope: "all" });
|
|
269
|
+
for (const bad of [{}, { id: "" }, { id: 7 }, { id: "abc", extra: true }, { id: "abc", scope: "global" }, { sessionPath: "/tmp/a.jsonl" }, { id: "x".repeat(257) }]) {
|
|
270
|
+
assert.deepEqual(parseSwitchSessionParams(bad as Record<string, unknown>), { error: INVALID_SESSIONS_PARAMS }, JSON.stringify(bad));
|
|
271
|
+
}
|
|
272
|
+
});
|
|
273
|
+
|
|
274
|
+
test("the project display name is the last path segment, never a path", () => {
|
|
275
|
+
assert.equal(sessionProjectName("/home/me/work/gentle-shell"), "gentle-shell");
|
|
276
|
+
assert.equal(sessionProjectName("C:\\Users\\me\\dev\\gentle-shell\\"), "gentle-shell");
|
|
277
|
+
assert.equal(sessionProjectName(""), "unknown");
|
|
278
|
+
assert.equal(sessionProjectName("C:\\"), "unknown");
|
|
279
|
+
assert.equal(sessionProjectName("/"), "unknown");
|
|
280
|
+
});
|
|
281
|
+
|
|
282
|
+
// ---- list_sessions ----
|
|
283
|
+
|
|
284
|
+
test("list_sessions returns the project's sessions newest first through Pi's own resolution, with only whitelisted fields", async (t) => {
|
|
285
|
+
const root = makeRoot(t);
|
|
286
|
+
const seeded = seedCustom(root);
|
|
287
|
+
const app = harness(t, customLocation(root));
|
|
288
|
+
app.start();
|
|
289
|
+
|
|
290
|
+
await app.invoke(request("list-1", "list_sessions"));
|
|
291
|
+
const payloads = app.payloads();
|
|
292
|
+
const response = responseFor(payloads, "list-1");
|
|
293
|
+
assert.equal(response.ok, true, JSON.stringify(response));
|
|
294
|
+
// Project scope filters a custom directory by cwd exactly as Pi's /resume does.
|
|
295
|
+
assert.deepEqual(response.data.sessions.map((session: any) => session.id), ["s-new", "s-mid", "s-old"]);
|
|
296
|
+
assert.equal("nextCursor" in response.data, false);
|
|
297
|
+
const [newest, middle, oldest] = response.data.sessions;
|
|
298
|
+
assert.deepEqual(newest, {
|
|
299
|
+
id: "s-new",
|
|
300
|
+
modified: seeded.base + 120_000 + 2000,
|
|
301
|
+
messageCount: 2,
|
|
302
|
+
firstMessage: "newest",
|
|
303
|
+
project: "gentle-shell",
|
|
304
|
+
current: true,
|
|
305
|
+
});
|
|
306
|
+
assert.equal(middle.name, "Release prep");
|
|
307
|
+
assert.equal(middle.current, false);
|
|
308
|
+
assert.equal(middle.firstMessage.length <= DESKTOP_SESSIONS_FIRST_MESSAGE_MAX, true);
|
|
309
|
+
assert.equal(middle.firstMessage.startsWith("secret-ish long x"), true, "whitespace is collapsed for display");
|
|
310
|
+
assert.equal(middle.firstMessage.endsWith("…"), true, "a cut first message is marked");
|
|
311
|
+
assert.deepEqual(Object.keys(oldest).sort(), ["current", "firstMessage", "id", "messageCount", "modified", "project"]);
|
|
312
|
+
assertNoPrivateFields(payloads, root);
|
|
313
|
+
assert.equal(payloads.some((payload) => payload.kind === "event"), false, "a read emits no event");
|
|
314
|
+
});
|
|
315
|
+
|
|
316
|
+
test("list_sessions scope all covers a custom session directory across projects", async (t) => {
|
|
317
|
+
const root = makeRoot(t);
|
|
318
|
+
seedCustom(root);
|
|
319
|
+
const app = harness(t, customLocation(root));
|
|
320
|
+
app.start();
|
|
321
|
+
|
|
322
|
+
await app.invoke(request("list-all", "list_sessions", { scope: "all" }));
|
|
323
|
+
const response = responseFor(app.payloads(), "list-all");
|
|
324
|
+
assert.equal(response.ok, true, JSON.stringify(response));
|
|
325
|
+
assert.deepEqual(
|
|
326
|
+
response.data.sessions.map((session: any) => [session.id, session.project]),
|
|
327
|
+
[["s-foreign", "other-app"], ["s-new", "gentle-shell"], ["s-mid", "gentle-shell"], ["s-old", "gentle-shell"]],
|
|
328
|
+
);
|
|
329
|
+
assertNoPrivateFields(app.payloads(), root);
|
|
330
|
+
});
|
|
331
|
+
|
|
332
|
+
test("list_sessions with the default session directory reads Pi's per-project directory and its all-projects root", async (t) => {
|
|
333
|
+
const root = makeRoot(t);
|
|
334
|
+
isolatedAgentDir(t, root.agentDir);
|
|
335
|
+
const base = Date.UTC(2026, 10, 2);
|
|
336
|
+
// Pi's default layout: <agentDir>/sessions/--<encoded cwd>--/<file>.jsonl
|
|
337
|
+
const encode = (cwd: string) => `--${cwd.replace(/^[/\\]/, "").replace(/[/\\:]/g, "-")}--`;
|
|
338
|
+
const projectDir = join(root.agentDir, "sessions", encode(root.projectCwd));
|
|
339
|
+
writeSession(projectDir, { id: "d-project", cwd: root.projectCwd, at: base, messages: [{ role: "user", text: "here" }] });
|
|
340
|
+
writeSession(join(root.agentDir, "sessions", encode(root.otherCwd)), { id: "d-other", cwd: root.otherCwd, at: base + 1000, messages: [{ role: "user", text: "there" }] });
|
|
341
|
+
const app = harness(t, { cwd: root.projectCwd, sessionDir: projectDir, usesDefault: true, currentId: "d-project" });
|
|
342
|
+
app.start();
|
|
343
|
+
|
|
344
|
+
await app.invoke(request("list-project", "list_sessions"));
|
|
345
|
+
await app.invoke(request("list-all", "list_sessions", { scope: "all" }));
|
|
346
|
+
const project = responseFor(app.payloads(), "list-project");
|
|
347
|
+
const all = responseFor(app.payloads(), "list-all");
|
|
348
|
+
assert.deepEqual(project.data.sessions.map((session: any) => session.id), ["d-project"]);
|
|
349
|
+
assert.deepEqual(all.data.sessions.map((session: any) => [session.id, session.project, session.current]), [["d-other", "other-app", false], ["d-project", "gentle-shell", true]]);
|
|
350
|
+
assertNoPrivateFields(app.payloads(), root);
|
|
351
|
+
});
|
|
352
|
+
|
|
353
|
+
test("list_sessions pages with an opaque cursor and stops when the list is exhausted", async (t) => {
|
|
354
|
+
const root = makeRoot(t);
|
|
355
|
+
seedCustom(root);
|
|
356
|
+
const app = harness(t, customLocation(root));
|
|
357
|
+
app.start();
|
|
358
|
+
|
|
359
|
+
await app.invoke(request("page-1", "list_sessions", { scope: "all", limit: 2 }));
|
|
360
|
+
const first = responseFor(app.payloads(), "page-1");
|
|
361
|
+
assert.deepEqual(first.data.sessions.map((session: any) => session.id), ["s-foreign", "s-new"]);
|
|
362
|
+
assert.equal(typeof first.data.nextCursor, "string");
|
|
363
|
+
assertNoPrivateFields(first, root);
|
|
364
|
+
|
|
365
|
+
await app.invoke(request("page-2", "list_sessions", { scope: "all", limit: 2, cursor: first.data.nextCursor }));
|
|
366
|
+
const second = responseFor(app.payloads(), "page-2");
|
|
367
|
+
assert.deepEqual(second.data.sessions.map((session: any) => session.id), ["s-mid", "s-old"]);
|
|
368
|
+
assert.equal("nextCursor" in second.data, false, "the last page carries no cursor");
|
|
369
|
+
|
|
370
|
+
await app.invoke(request("page-bad", "list_sessions", { cursor: "%%%" }));
|
|
371
|
+
assert.deepEqual(responseFor(app.payloads(), "page-bad").error, INVALID_SESSIONS_PARAMS);
|
|
372
|
+
});
|
|
373
|
+
|
|
374
|
+
test("list_sessions rejects bad params before any owner work", async (t) => {
|
|
375
|
+
const root = makeRoot(t);
|
|
376
|
+
const app = harness(t, customLocation(root));
|
|
377
|
+
app.start();
|
|
378
|
+
await app.invoke(request("bad-limit", "list_sessions", { limit: 0 }));
|
|
379
|
+
await app.invoke(request("bad-scope", "list_sessions", { scope: "everything" }));
|
|
380
|
+
await app.invoke(request("bad-key", "list_sessions", { sessionDir: root.customDir }));
|
|
381
|
+
for (const id of ["bad-limit", "bad-scope", "bad-key"]) {
|
|
382
|
+
const response = responseFor(app.payloads(), id);
|
|
383
|
+
assert.equal(response.ok, false);
|
|
384
|
+
assert.deepEqual(response.error, INVALID_SESSIONS_PARAMS);
|
|
385
|
+
}
|
|
386
|
+
assertNoPrivateFields(app.payloads(), root);
|
|
387
|
+
});
|
|
388
|
+
|
|
389
|
+
test("an empty or missing session directory lists nothing rather than failing", async (t) => {
|
|
390
|
+
const root = makeRoot(t);
|
|
391
|
+
const app = harness(t, customLocation(root));
|
|
392
|
+
app.start();
|
|
393
|
+
await app.invoke(request("empty", "list_sessions"));
|
|
394
|
+
assert.deepEqual(responseFor(app.payloads(), "empty").data, { sessions: [] });
|
|
395
|
+
});
|
|
396
|
+
|
|
397
|
+
test("sessions answer sessions_unavailable when no command context with a session manager is bound", async (t) => {
|
|
398
|
+
const bridge = new DesktopSessionsBridge();
|
|
399
|
+
assert.deepEqual(await bridge.handle("list_sessions", {}, "r-1"), { ok: false, error: SESSIONS_UNAVAILABLE });
|
|
400
|
+
assert.deepEqual(await bridge.handle("switch_session", { id: "abc" }, "r-2"), { ok: false, error: SESSIONS_UNAVAILABLE });
|
|
401
|
+
assert.equal(bridge.handle("list_jobs", {}, "r-3"), undefined, "other methods fall through");
|
|
402
|
+
|
|
403
|
+
const root = makeRoot(t);
|
|
404
|
+
const app = harness(t, customLocation(root), { withSessionManager: false });
|
|
405
|
+
app.start();
|
|
406
|
+
await app.invoke(request("no-manager", "list_sessions"));
|
|
407
|
+
assert.deepEqual(responseFor(app.payloads(), "no-manager").error, SESSIONS_UNAVAILABLE);
|
|
408
|
+
});
|
|
409
|
+
|
|
410
|
+
test("a bridge reset drops a late list outcome", async (t) => {
|
|
411
|
+
const root = makeRoot(t);
|
|
412
|
+
seedCustom(root);
|
|
413
|
+
let release!: () => void;
|
|
414
|
+
const gate = new Promise<void>((resolve) => { release = resolve; });
|
|
415
|
+
const bridge = new DesktopSessionsBridge({
|
|
416
|
+
owner: {
|
|
417
|
+
list: async () => { await gate; return []; },
|
|
418
|
+
listAll: async () => [],
|
|
419
|
+
findById: () => undefined,
|
|
420
|
+
},
|
|
421
|
+
});
|
|
422
|
+
bridge.attach({ cwd: root.projectCwd, sessionManager: { getCwd: () => root.projectCwd, getSessionDir: () => root.customDir, usesDefaultSessionDir: () => false, getSessionId: () => "s-new" } } as any);
|
|
423
|
+
const pending = bridge.handle("list_sessions", {}, "late")!;
|
|
424
|
+
bridge.reset();
|
|
425
|
+
release();
|
|
426
|
+
assert.deepEqual(await pending, { ok: false, error: SESSIONS_UNAVAILABLE });
|
|
427
|
+
});
|
|
428
|
+
|
|
429
|
+
// ---- switch_session ----
|
|
430
|
+
|
|
431
|
+
test("switch_session resolves the id through the owner, switches, and answers after the new session starts with a reset sequence", async (t) => {
|
|
432
|
+
const root = makeRoot(t);
|
|
433
|
+
const seeded = seedCustom(root);
|
|
434
|
+
const app = harness(t, customLocation(root));
|
|
435
|
+
app.start();
|
|
436
|
+
|
|
437
|
+
await app.invoke(request("switch-1", "switch_session", { id: "s-old" }));
|
|
438
|
+
assert.deepEqual(app.switches, [seeded.oldest], "Pi's switchSession receives the owner-resolved file");
|
|
439
|
+
const payloads = app.payloads();
|
|
440
|
+
const response = responseFor(payloads, "switch-1");
|
|
441
|
+
assert.deepEqual(response, { schema: DESKTOP_RPC_SCHEMA, kind: "response", requestId: "switch-1", ok: true, data: { id: "s-old", changed: true } });
|
|
442
|
+
assertNoPrivateFields(payloads, root);
|
|
443
|
+
assert.equal(payloads.some((payload) => payload.kind === "event"), false, "a switch emits no Desktop event");
|
|
444
|
+
|
|
445
|
+
// The replacement session's router answers with its own fresh sequence.
|
|
446
|
+
await app.invoke(request("snapshot-after", "get_snapshot"));
|
|
447
|
+
assert.equal(responseFor(app.payloads(), "snapshot-after").data.sequence, 0);
|
|
448
|
+
});
|
|
449
|
+
|
|
450
|
+
test("switching to the current session is a no-op that answers changed false", async (t) => {
|
|
451
|
+
const root = makeRoot(t);
|
|
452
|
+
seedCustom(root);
|
|
453
|
+
const app = harness(t, customLocation(root, "s-new"));
|
|
454
|
+
app.start();
|
|
455
|
+
await app.invoke(request("same", "switch_session", { id: "s-new" }));
|
|
456
|
+
assert.deepEqual(responseFor(app.payloads(), "same").data, { id: "s-new", changed: false });
|
|
457
|
+
assert.deepEqual(app.switches, [], "no switch happens");
|
|
458
|
+
assert.equal(app.payloads().some((payload) => payload.kind === "event"), false);
|
|
459
|
+
});
|
|
460
|
+
|
|
461
|
+
test("switch_session answers not_found for an id outside the requested scope and switches across projects only with scope all", async (t) => {
|
|
462
|
+
const root = makeRoot(t);
|
|
463
|
+
const seeded = seedCustom(root);
|
|
464
|
+
const app = harness(t, customLocation(root));
|
|
465
|
+
app.start();
|
|
466
|
+
|
|
467
|
+
await app.invoke(request("missing", "switch_session", { id: "no-such-session" }));
|
|
468
|
+
await app.invoke(request("foreign-project", "switch_session", { id: "s-foreign" }));
|
|
469
|
+
assert.deepEqual(responseFor(app.payloads(), "missing").error, SESSION_NOT_FOUND);
|
|
470
|
+
assert.deepEqual(responseFor(app.payloads(), "foreign-project").error, SESSION_NOT_FOUND);
|
|
471
|
+
assert.deepEqual(app.switches, [], "nothing was switched");
|
|
472
|
+
|
|
473
|
+
await app.invoke(request("foreign-all", "switch_session", { id: "s-foreign", scope: "all" }));
|
|
474
|
+
assert.deepEqual(responseFor(app.payloads(), "foreign-all").data, { id: "s-foreign", changed: true });
|
|
475
|
+
assert.deepEqual(app.switches, [seeded.foreign]);
|
|
476
|
+
assertNoPrivateFields(app.payloads(), root);
|
|
477
|
+
});
|
|
478
|
+
|
|
479
|
+
test("switch_session rejects bad params before any owner work", async (t) => {
|
|
480
|
+
const root = makeRoot(t);
|
|
481
|
+
seedCustom(root);
|
|
482
|
+
const app = harness(t, customLocation(root));
|
|
483
|
+
app.start();
|
|
484
|
+
await app.invoke(request("no-id", "switch_session", {}));
|
|
485
|
+
await app.invoke(request("path-shaped", "switch_session", { sessionPath: join(root.customDir, "a.jsonl") }));
|
|
486
|
+
await app.invoke(request("extra", "switch_session", { id: "s-old", force: true }));
|
|
487
|
+
for (const id of ["no-id", "path-shaped", "extra"]) assert.deepEqual(responseFor(app.payloads(), id).error, INVALID_SESSIONS_PARAMS);
|
|
488
|
+
assert.deepEqual(app.switches, []);
|
|
489
|
+
assertNoPrivateFields(app.payloads(), root);
|
|
490
|
+
});
|
|
491
|
+
|
|
492
|
+
test("switch_session answers sessions_unavailable when the bound context cannot switch", async (t) => {
|
|
493
|
+
const root = makeRoot(t);
|
|
494
|
+
seedCustom(root);
|
|
495
|
+
const app = harness(t, customLocation(root), { withSwitch: false });
|
|
496
|
+
app.start();
|
|
497
|
+
await app.invoke(request("no-switch", "switch_session", { id: "s-old" }));
|
|
498
|
+
assert.deepEqual(responseFor(app.payloads(), "no-switch").error, SESSIONS_UNAVAILABLE);
|
|
499
|
+
});
|
|
500
|
+
|
|
501
|
+
test("a switch cancelled by a session_before_switch handler answers changed false and cancelled", async (t) => {
|
|
502
|
+
const root = makeRoot(t);
|
|
503
|
+
seedCustom(root);
|
|
504
|
+
const app = harness(t, customLocation(root), { switchBehavior: "cancel" });
|
|
505
|
+
app.start();
|
|
506
|
+
await app.invoke(request("cancelled", "switch_session", { id: "s-old" }));
|
|
507
|
+
assert.deepEqual(responseFor(app.payloads(), "cancelled").data, { id: "s-old", changed: false, cancelled: true });
|
|
508
|
+
assert.equal(app.payloads().some((payload) => payload.kind === "event"), false);
|
|
509
|
+
});
|
|
510
|
+
|
|
511
|
+
test("a switch the runtime refuses answers sessions_unavailable without the raw error or path", async (t) => {
|
|
512
|
+
const root = makeRoot(t);
|
|
513
|
+
seedCustom(root);
|
|
514
|
+
const app = harness(t, customLocation(root), { switchBehavior: "throw" });
|
|
515
|
+
app.start();
|
|
516
|
+
await app.invoke(request("refused", "switch_session", { id: "s-old" }));
|
|
517
|
+
const response = responseFor(app.payloads(), "refused");
|
|
518
|
+
assert.equal(response.ok, false);
|
|
519
|
+
assert.equal(response.error.code, SESSIONS_UNAVAILABLE.code);
|
|
520
|
+
assertNoPrivateFields(app.payloads(), root);
|
|
521
|
+
});
|
|
522
|
+
|
|
523
|
+
// ---- Requests while a switch is in flight ----
|
|
524
|
+
|
|
525
|
+
test("while a switch is in flight every other request answers session_switching at once, and only the switch answers from the new session", async (t) => {
|
|
526
|
+
const root = makeRoot(t);
|
|
527
|
+
seedCustom(root);
|
|
528
|
+
let release!: () => void;
|
|
529
|
+
const hold = new Promise<void>((resolve) => { release = resolve; });
|
|
530
|
+
const app = harness(t, customLocation(root), { holdSwitch: hold });
|
|
531
|
+
app.start();
|
|
532
|
+
|
|
533
|
+
const switching = app.invoke(request("sw-2", "switch_session", { id: "s-old" }));
|
|
534
|
+
// Dispatched while sw-2 waits for Pi: answered before the teardown, never queued.
|
|
535
|
+
await app.invoke(request("sw-3", "switch_session", { id: "s-mid" }));
|
|
536
|
+
await app.invoke(request("ls-4", "list_sessions"));
|
|
537
|
+
await app.invoke(request("caps-5", "capabilities"));
|
|
538
|
+
for (const id of ["sw-3", "ls-4", "caps-5"]) assert.deepEqual(responseFor(app.payloads(), id).error, SESSION_SWITCHING, id);
|
|
539
|
+
assert.equal(app.payloads().some((payload) => payload.requestId === "sw-2"), false, "the switch has not answered yet");
|
|
540
|
+
|
|
541
|
+
release();
|
|
542
|
+
await switching;
|
|
543
|
+
assert.deepEqual(responseFor(app.payloads(), "sw-2").data, { id: "s-old", changed: true });
|
|
544
|
+
assert.equal(app.switches.length, 1, "the refused switch never reached Pi");
|
|
545
|
+
for (const id of ["sw-2", "sw-3", "ls-4", "caps-5"]) responseFor(app.payloads(), id);
|
|
546
|
+
|
|
547
|
+
// After the switch settles, requests are served again.
|
|
548
|
+
await app.invoke(request("ls-6", "list_sessions"));
|
|
549
|
+
assert.equal(responseFor(app.payloads(), "ls-6").ok, true);
|
|
550
|
+
});
|
|
551
|
+
|
|
552
|
+
test("a request still waiting on an owner when a switch tears the session down answers session_switching exactly once", async (t) => {
|
|
553
|
+
const root = makeRoot(t);
|
|
554
|
+
seedCustom(root);
|
|
555
|
+
const app = harness(t, customLocation(root));
|
|
556
|
+
app.start();
|
|
557
|
+
|
|
558
|
+
// `list_jobs` waits for jobs-owner discovery (no owner here), so it is still
|
|
559
|
+
// pending when the switch dispatched right after it tears the session down.
|
|
560
|
+
const jobs = app.invoke(request("jobs-1", "list_jobs"));
|
|
561
|
+
const switching = app.invoke(request("sw-1", "switch_session", { id: "s-old" }));
|
|
562
|
+
await Promise.all([jobs, switching]);
|
|
563
|
+
await new Promise((resolve) => setTimeout(resolve, 150));
|
|
564
|
+
assert.deepEqual(responseFor(app.payloads(), "jobs-1").error, SESSION_SWITCHING, "answered before the teardown, not dropped");
|
|
565
|
+
assert.deepEqual(responseFor(app.payloads(), "sw-1").data, { id: "s-old", changed: true });
|
|
566
|
+
});
|
|
567
|
+
|
|
568
|
+
test("a cancelled or failed switch releases the gate", async (t) => {
|
|
569
|
+
const root = makeRoot(t);
|
|
570
|
+
seedCustom(root);
|
|
571
|
+
for (const behavior of ["cancel", "throw"] as const) {
|
|
572
|
+
const app = harness(t, customLocation(root), { switchBehavior: behavior });
|
|
573
|
+
app.start();
|
|
574
|
+
await app.invoke(request(`sw-${behavior}`, "switch_session", { id: "s-old" }));
|
|
575
|
+
await app.invoke(request(`ls-${behavior}`, "list_sessions"));
|
|
576
|
+
assert.equal(responseFor(app.payloads(), `ls-${behavior}`).ok, true, behavior);
|
|
577
|
+
}
|
|
578
|
+
});
|
|
579
|
+
|
|
580
|
+
test("a command Pi dispatches to the instance a switch replaced answers session_switching without touching its stale context", async (t) => {
|
|
581
|
+
const root = makeRoot(t);
|
|
582
|
+
seedCustom(root);
|
|
583
|
+
const app = harness(t, customLocation(root), { newInstance: true });
|
|
584
|
+
app.start();
|
|
585
|
+
await app.invoke(request("sw-1", "switch_session", { id: "s-old" }));
|
|
586
|
+
assert.deepEqual(responseFor(app.payloads(), "sw-1").data, { id: "s-old", changed: true });
|
|
587
|
+
|
|
588
|
+
// Pi invalidates a replaced instance's ctx: every access throws.
|
|
589
|
+
const stale = new Proxy({}, { get() { throw new Error("This extension ctx is stale after session replacement"); } });
|
|
590
|
+
await app.invoke(request("late-1", "list_sessions"), stale);
|
|
591
|
+
await app.invoke("{not json", stale);
|
|
592
|
+
assert.deepEqual(responseFor(app.payloads(), "late-1").error, SESSION_SWITCHING);
|
|
593
|
+
const malformed = app.payloads().filter((payload) => payload.requestId === null);
|
|
594
|
+
assert.equal(malformed.length, 1);
|
|
595
|
+
assert.deepEqual(malformed[0].error, SESSION_SWITCHING);
|
|
596
|
+
});
|
|
597
|
+
|
|
598
|
+
// ---- Exposure, traversal and cursor regressions (from the independent verifier's probe) ----
|
|
599
|
+
|
|
600
|
+
test("ids shaped like paths, globs, or prefixes never resolve a session", async (t) => {
|
|
601
|
+
const root = makeRoot(t);
|
|
602
|
+
seedCustom(root);
|
|
603
|
+
const app = harness(t, customLocation(root));
|
|
604
|
+
app.start();
|
|
605
|
+
const ids = ["../custom-sessions/s-old", "s-old.jsonl", root.customDir, "*", "s", "s-ol"];
|
|
606
|
+
for (const [index, id] of ids.entries()) {
|
|
607
|
+
await app.invoke(request(`trav-${index}`, "switch_session", { id, scope: "all" }));
|
|
608
|
+
assert.deepEqual(responseFor(app.payloads(), `trav-${index}`).error, SESSION_NOT_FOUND, id);
|
|
609
|
+
}
|
|
610
|
+
assert.deepEqual(app.switches, [], "nothing was switched");
|
|
611
|
+
assertNoPrivateFields(app.payloads(), root);
|
|
612
|
+
});
|
|
613
|
+
|
|
614
|
+
test("another project's sessions expose only its display name and the whitelisted fields", async (t) => {
|
|
615
|
+
const root = makeRoot(t);
|
|
616
|
+
const secret = join(root.root, "home", "secret-proj");
|
|
617
|
+
mkdirSync(secret, { recursive: true });
|
|
618
|
+
writeSession(root.customDir, { id: "s-secret", cwd: secret, at: Date.UTC(2026, 10, 3), messages: [{ role: "user", text: "hello" }, { role: "assistant", text: "assistant body text" }] });
|
|
619
|
+
const app = harness(t, customLocation(root));
|
|
620
|
+
app.start();
|
|
621
|
+
await app.invoke(request("all", "list_sessions", { scope: "all" }));
|
|
622
|
+
const [entry] = responseFor(app.payloads(), "all").data.sessions;
|
|
623
|
+
assert.deepEqual(Object.keys(entry).sort(), ["current", "firstMessage", "id", "messageCount", "modified", "project"]);
|
|
624
|
+
assert.equal(entry.project, "secret-proj");
|
|
625
|
+
assertNoPrivateFields(app.payloads(), root);
|
|
626
|
+
});
|
|
627
|
+
|
|
628
|
+
test("forged cursors are either rejected or read as a plain keyset position", async (t) => {
|
|
629
|
+
const root = makeRoot(t);
|
|
630
|
+
seedCustom(root);
|
|
631
|
+
const app = harness(t, customLocation(root));
|
|
632
|
+
app.start();
|
|
633
|
+
const forged = (value: string) => Buffer.from(value).toString("base64url");
|
|
634
|
+
await app.invoke(request("c-proto", "list_sessions", { cursor: forged('{"__proto__":1}') }));
|
|
635
|
+
await app.invoke(request("c-object", "list_sessions", { cursor: forged('{"modified":1,"id":"x"}') }));
|
|
636
|
+
await app.invoke(request("c-nan", "list_sessions", { cursor: forged('[null,"x"]') }));
|
|
637
|
+
await app.invoke(request("c-long", "list_sessions", { cursor: "A".repeat(600) }));
|
|
638
|
+
for (const id of ["c-proto", "c-object", "c-nan", "c-long"]) assert.deepEqual(responseFor(app.payloads(), id).error, INVALID_SESSIONS_PARAMS, id);
|
|
639
|
+
// A well-formed position far in the future is just "everything older": every session, newest first.
|
|
640
|
+
await app.invoke(request("c-huge", "list_sessions", { cursor: forged(JSON.stringify([1e300, "z"])) }));
|
|
641
|
+
assert.deepEqual(responseFor(app.payloads(), "c-huge").data.sessions.map((session: any) => session.id), ["s-new", "s-mid", "s-old"]);
|
|
642
|
+
});
|
|
643
|
+
|
|
644
|
+
test("a session name with backslashes is projected unchanged", () => {
|
|
645
|
+
const entry = projectDesktopSession({ id: "a", cwd: "/w/p", name: "my name C:\Users\devel\secret", modified: new Date(1), messageCount: 1, firstMessage: "hi" }, "b");
|
|
646
|
+
assert.equal(entry?.name, "my name C:\Users\devel\secret");
|
|
647
|
+
});
|