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,509 @@
|
|
|
1
|
+
import assert from "node:assert/strict";
|
|
2
|
+
import { existsSync, mkdirSync, mkdtempSync, readFileSync, 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 type { ExtensionAPI } from "@earendil-works/pi-coding-agent";
|
|
7
|
+
import { createDesktopFeedExtension, type DesktopFeedOptions } from "../extensions/gentle-desktop-feed.ts";
|
|
8
|
+
import desktopRpc from "../extensions/gentle-desktop-rpc.ts";
|
|
9
|
+
import { buildDesktopFeedSnapshot, DESKTOP_FEED_LIMITS, type DesktopFeedInput, type DesktopFeedSnapshot, type DesktopFeedTimers } from "../lib/desktop-feed.ts";
|
|
10
|
+
import { DESKTOP_ACTION_KINDS, DESKTOP_ACTION_SCHEMA, desktopActionInboxDir, desktopActionOutboxDir, parseDesktopAction } from "../lib/desktop-feed-actions.ts";
|
|
11
|
+
import { createDesktopFeedProfileReader } from "../lib/desktop-feed-sources.ts";
|
|
12
|
+
import { desktopFeedFile } from "../lib/desktop-feed-store.ts";
|
|
13
|
+
import { createProfile, emptyProfilesFile, profilesFilePath, serializeProfilesFile, setActiveProfile } from "../lib/agent-profiles.ts";
|
|
14
|
+
import { DESKTOP_PROFILES_SERVICE_CHANNEL, DESKTOP_PROFILES_SERVICE_SCHEMA, type DesktopProfileApplyRequest, type DesktopProfileApplyResult } from "../lib/desktop-rpc-profiles.ts";
|
|
15
|
+
import { DESKTOP_USAGE_SERVICE_CHANNEL, DESKTOP_USAGE_SERVICE_SCHEMA, type DesktopUsageOwnerEntry, type DesktopUsageRecordedSnapshot } from "../lib/desktop-rpc-usage.ts";
|
|
16
|
+
import { DESKTOP_RPC_SCHEMA } from "../lib/desktop-rpc.ts";
|
|
17
|
+
import { INTERACTIVE_HOST_ENV } from "../lib/rpc-host.ts";
|
|
18
|
+
import type { ProviderUsage } from "../lib/shell-usage.ts";
|
|
19
|
+
|
|
20
|
+
// S12 (odd/tasks/herdr-desktop.md): the desktop shows the subscription plan
|
|
21
|
+
// (name and every usage window, as the TUI usage panel does) and the model
|
|
22
|
+
// profiles (list, active, per-agent models), and switches profile through the
|
|
23
|
+
// same owner as /gentle:profiles. Every value comes from the TUI's own owners.
|
|
24
|
+
|
|
25
|
+
const NOW = Date.UTC(2026, 10, 15, 12, 0, 0);
|
|
26
|
+
const settle = () => new Promise((resolve) => setTimeout(resolve, 150));
|
|
27
|
+
const GENTLE_ENV = { PI_PROGRAM_STATUS_APP: "gentle-shell", HERDR_ENV: "1", HERDR_PANE_ID: "t7" };
|
|
28
|
+
|
|
29
|
+
// The usage owner ages snapshots on the real clock (stale after 5 minutes).
|
|
30
|
+
const FETCHED = Date.now() - 1000;
|
|
31
|
+
const CODEX: ProviderUsage = {
|
|
32
|
+
provider: "openai-codex",
|
|
33
|
+
plan: "pro",
|
|
34
|
+
fetchedAt: FETCHED,
|
|
35
|
+
limits: [
|
|
36
|
+
{ name: "codex", limitReached: false, windows: [{ label: "5h", usedPercent: 21, windowSeconds: 18_000, resetAt: NOW + 3_600_000 }, { label: "week", usedPercent: 64, windowSeconds: 604_800, resetAt: NOW + 86_400_000 }] },
|
|
37
|
+
{ name: "codex-spark", limitReached: true, windows: [{ label: "5h", usedPercent: 100, windowSeconds: 18_000, resetAt: null }] },
|
|
38
|
+
],
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
// ---- Harness ----
|
|
42
|
+
|
|
43
|
+
function fakeTimers() {
|
|
44
|
+
const pending = new Map<number, { fn: () => void; ms: number }>();
|
|
45
|
+
let next = 0;
|
|
46
|
+
const timers: DesktopFeedTimers = {
|
|
47
|
+
set(fn, ms) { next += 1; pending.set(next, { fn, ms }); return next; },
|
|
48
|
+
clear(handle) { pending.delete(handle as number); },
|
|
49
|
+
};
|
|
50
|
+
return {
|
|
51
|
+
timers,
|
|
52
|
+
delays: () => [...pending.values()].map((entry) => entry.ms),
|
|
53
|
+
/** Runs the pending timers (only those armed for less than `below` ms, when given). */
|
|
54
|
+
run(below = Number.POSITIVE_INFINITY) {
|
|
55
|
+
const due = [...pending.entries()].filter(([, entry]) => entry.ms < below);
|
|
56
|
+
for (const [id] of due) pending.delete(id);
|
|
57
|
+
for (const [, { fn }] of due) fn();
|
|
58
|
+
},
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
function fakeBus() {
|
|
63
|
+
const listeners = new Map<string, Set<(data: unknown) => void>>();
|
|
64
|
+
return {
|
|
65
|
+
on(name: string, fn: (data: unknown) => void) {
|
|
66
|
+
const set = listeners.get(name) ?? new Set();
|
|
67
|
+
set.add(fn);
|
|
68
|
+
listeners.set(name, set);
|
|
69
|
+
return () => { set.delete(fn); };
|
|
70
|
+
},
|
|
71
|
+
emit(name: string, data: unknown) { for (const fn of [...(listeners.get(name) ?? [])]) fn(data); },
|
|
72
|
+
};
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
type Handler = (event: any, ctx: any) => unknown;
|
|
76
|
+
function fakePi() {
|
|
77
|
+
const bus = fakeBus();
|
|
78
|
+
const handlers = new Map<string, Handler[]>();
|
|
79
|
+
const commands = new Map<string, { handler: (args: string, ctx: any) => Promise<void> }>();
|
|
80
|
+
const pi = {
|
|
81
|
+
on(name: string, fn: Handler) { handlers.set(name, [...(handlers.get(name) ?? []), fn]); return () => {}; },
|
|
82
|
+
events: bus,
|
|
83
|
+
registerCommand(name: string, command: any) { commands.set(name, command); },
|
|
84
|
+
registerTool() {},
|
|
85
|
+
getThinkingLevel: () => "high",
|
|
86
|
+
sendUserMessage() {},
|
|
87
|
+
} as unknown as ExtensionAPI;
|
|
88
|
+
const fire = (name: string, event: unknown, ctx: unknown) => { for (const fn of handlers.get(name) ?? []) fn(event, ctx); };
|
|
89
|
+
return { pi, bus, commands, fire };
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
function fakeCtx(cwd: string, overrides: Record<string, unknown> = {}) {
|
|
93
|
+
const widgets: Array<{ key: string; lines: string[] }> = [];
|
|
94
|
+
let idle = true;
|
|
95
|
+
return {
|
|
96
|
+
cwd, mode: "tui", hasUI: true,
|
|
97
|
+
isIdle: () => idle,
|
|
98
|
+
setIdle(value: boolean) { idle = value; },
|
|
99
|
+
abort() {},
|
|
100
|
+
model: { id: "gpt-5.5", provider: "openai-codex", reasoning: true, contextWindow: 200_000 },
|
|
101
|
+
modelRegistry: { isUsingOAuth: () => true },
|
|
102
|
+
getContextUsage: () => ({ tokens: 1000, contextWindow: 200_000, percent: 0.5 }),
|
|
103
|
+
ui: { setWidget(key: string, lines: string[]) { widgets.push({ key, lines }); }, setStatus() {}, notify() {}, confirm: async () => true },
|
|
104
|
+
widgets,
|
|
105
|
+
sessionManager: {
|
|
106
|
+
getSessionId: () => "sess-1",
|
|
107
|
+
getSessionFile: () => "/agent/sessions/--w--/2026_sess-1.jsonl",
|
|
108
|
+
getSessionName: () => undefined,
|
|
109
|
+
getCwd: () => cwd,
|
|
110
|
+
getBranch: () => [],
|
|
111
|
+
getEntries: () => [],
|
|
112
|
+
getLeafId: () => null,
|
|
113
|
+
},
|
|
114
|
+
...overrides,
|
|
115
|
+
};
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
/** The usage owner (gentle-shell's UsageStore seam), speaking its owner-service contract. */
|
|
119
|
+
function usageOwner(bus: ReturnType<typeof fakeBus>) {
|
|
120
|
+
const state = {
|
|
121
|
+
entries: [] as DesktopUsageOwnerEntry[],
|
|
122
|
+
afterRefresh: undefined as DesktopUsageOwnerEntry[] | undefined,
|
|
123
|
+
refreshes: [] as Array<string | null>,
|
|
124
|
+
reads: 0,
|
|
125
|
+
observers: new Set<(recorded: DesktopUsageRecordedSnapshot) => void>(),
|
|
126
|
+
};
|
|
127
|
+
bus.on(DESKTOP_USAGE_SERVICE_CHANNEL, (payload) => {
|
|
128
|
+
const read = (provider?: string) => {
|
|
129
|
+
state.reads += 1;
|
|
130
|
+
return { providers: state.entries.filter((entry) => provider === undefined || entry.provider === provider) };
|
|
131
|
+
};
|
|
132
|
+
(payload as { respond(service: unknown): void }).respond({
|
|
133
|
+
schema: DESKTOP_USAGE_SERVICE_SCHEMA,
|
|
134
|
+
read,
|
|
135
|
+
refresh: async (provider?: string) => {
|
|
136
|
+
state.refreshes.push(provider ?? null);
|
|
137
|
+
if (state.afterRefresh) state.entries = state.afterRefresh;
|
|
138
|
+
return read(provider);
|
|
139
|
+
},
|
|
140
|
+
observe: (fn: (recorded: DesktopUsageRecordedSnapshot) => void) => { state.observers.add(fn); return () => { state.observers.delete(fn); }; },
|
|
141
|
+
dispose: () => {},
|
|
142
|
+
});
|
|
143
|
+
});
|
|
144
|
+
return state;
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
/** The /gentle:profiles owner (gentle-ai's apply seam). */
|
|
148
|
+
function profilesOwner(bus: ReturnType<typeof fakeBus>, answer: (request: DesktopProfileApplyRequest) => DesktopProfileApplyResult) {
|
|
149
|
+
const calls: DesktopProfileApplyRequest[] = [];
|
|
150
|
+
bus.on(DESKTOP_PROFILES_SERVICE_CHANNEL, (payload) => {
|
|
151
|
+
(payload as { respond(service: unknown): void }).respond({
|
|
152
|
+
schema: DESKTOP_PROFILES_SERVICE_SCHEMA,
|
|
153
|
+
apply: async (request: DesktopProfileApplyRequest) => { calls.push(request); return answer(request); },
|
|
154
|
+
dispose: () => {},
|
|
155
|
+
});
|
|
156
|
+
});
|
|
157
|
+
return calls;
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
function harness(t: { after(fn: () => void): void }, options: Partial<DesktopFeedOptions> = {}) {
|
|
161
|
+
const root = mkdtempSync(join(tmpdir(), "desktop-plan-"));
|
|
162
|
+
t.after(() => rmSync(root, { recursive: true, force: true }));
|
|
163
|
+
const agentDir = join(root, "agent");
|
|
164
|
+
const workspace = join(root, "workspace");
|
|
165
|
+
mkdirSync(workspace, { recursive: true });
|
|
166
|
+
const clock = fakeTimers();
|
|
167
|
+
const h = fakePi();
|
|
168
|
+
let fireWatch: (() => void) | undefined;
|
|
169
|
+
let profileReads = 0;
|
|
170
|
+
createDesktopFeedExtension({
|
|
171
|
+
env: GENTLE_ENV,
|
|
172
|
+
agentDir,
|
|
173
|
+
now: () => NOW,
|
|
174
|
+
timers: clock.timers,
|
|
175
|
+
git: () => async () => ({ stdout: "", code: 128 }),
|
|
176
|
+
parentOf: async () => undefined,
|
|
177
|
+
profile: () => { profileReads += 1; return { name: "work", tier: undefined }; },
|
|
178
|
+
realpath: (path) => path,
|
|
179
|
+
sweep: () => {},
|
|
180
|
+
actionWatch: (_dir, onChange) => { fireWatch = onChange; return () => {}; },
|
|
181
|
+
...options,
|
|
182
|
+
})(h.pi);
|
|
183
|
+
const ctx = fakeCtx(workspace);
|
|
184
|
+
const inbox = desktopActionInboxDir(agentDir, "sess-1");
|
|
185
|
+
const outbox = desktopActionOutboxDir(agentDir, "sess-1");
|
|
186
|
+
let n = 0;
|
|
187
|
+
return {
|
|
188
|
+
...h, ctx, clock, agentDir,
|
|
189
|
+
get profileReads() { return profileReads; },
|
|
190
|
+
start: async () => { h.fire("session_start", { reason: "startup" }, ctx); await settle(); clock.run(); await settle(); clock.run(); },
|
|
191
|
+
/** Drops one action, lets the session answer, and returns its answer. */
|
|
192
|
+
async act(kind: string, args: Record<string, unknown>) {
|
|
193
|
+
n += 1;
|
|
194
|
+
const id = `a${n}`;
|
|
195
|
+
writeFileSync(join(inbox, `${id}.json`), JSON.stringify({ schema: DESKTOP_ACTION_SCHEMA, id, sessionId: "sess-1", kind, args, createdAt: new Date(NOW - 1000).toISOString() }));
|
|
196
|
+
fireWatch?.();
|
|
197
|
+
await settle();
|
|
198
|
+
await settle();
|
|
199
|
+
clock.run();
|
|
200
|
+
await settle();
|
|
201
|
+
const file = join(outbox, `${id}.json`);
|
|
202
|
+
return existsSync(file) ? JSON.parse(readFileSync(file, "utf8")) as { ok: boolean; data?: Record<string, unknown>; error?: { code: string; message: string } } : undefined;
|
|
203
|
+
},
|
|
204
|
+
snapshot: () => JSON.parse(readFileSync(desktopFeedFile(agentDir, "sess-1"), "utf8")) as DesktopFeedSnapshot,
|
|
205
|
+
/** Runs the pending timers and lets the owner reads they start answer, `times` times. */
|
|
206
|
+
async tick(times = 1) { for (let i = 0; i < times; i++) { clock.run(); await settle(); } clock.run(); },
|
|
207
|
+
};
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
function input(overrides: Partial<DesktopFeedInput> = {}): DesktopFeedInput {
|
|
211
|
+
return {
|
|
212
|
+
now: NOW,
|
|
213
|
+
identity: { sessionId: "sess-1", sessionFile: undefined, sessionName: undefined, cwd: "/w", realCwd: undefined, pid: 100, ppid: 99, ancestors: [], mode: "tui", agentDir: "/agent", env: {} },
|
|
214
|
+
branch: null,
|
|
215
|
+
model: { id: "gpt-5.5", provider: "openai-codex", reasoning: true },
|
|
216
|
+
thinkingLevel: "high",
|
|
217
|
+
subscription: true,
|
|
218
|
+
profile: { name: "work (session)", tier: "fast" },
|
|
219
|
+
context: undefined,
|
|
220
|
+
usage: undefined,
|
|
221
|
+
permission: undefined,
|
|
222
|
+
todo: { tasks: [], nextId: 1, updatedTurn: null },
|
|
223
|
+
changes: undefined,
|
|
224
|
+
agents: undefined,
|
|
225
|
+
jobs: undefined,
|
|
226
|
+
review: undefined,
|
|
227
|
+
stats: { cost: 0, input: 0, output: 0, cacheRead: 0, cacheWrite: 0, turns: 0, toolCalls: 0, toolErrors: 0, spanMs: 0, cacheHitRate: null, models: [] },
|
|
228
|
+
activity: { working: false, blocked: 0, blockedLabel: undefined, streaming: false, phase: undefined },
|
|
229
|
+
pendingQuestion: undefined,
|
|
230
|
+
...overrides,
|
|
231
|
+
};
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
const codexWire = {
|
|
235
|
+
provider: "openai-codex", status: "ok", plan: "pro", fetchedAt: FETCHED, note: null,
|
|
236
|
+
limits: [
|
|
237
|
+
{ name: "codex", limitReached: false, windows: [{ label: "5h", usedPercent: 21, windowSeconds: 18_000, resetAt: NOW + 3_600_000 }, { label: "week", usedPercent: 64, windowSeconds: 604_800, resetAt: NOW + 86_400_000 }] },
|
|
238
|
+
{ name: "codex-spark", limitReached: true, windows: [{ label: "5h", usedPercent: 100, windowSeconds: 18_000, resetAt: null }] },
|
|
239
|
+
],
|
|
240
|
+
};
|
|
241
|
+
|
|
242
|
+
// ---- Plan usage: the shape ----
|
|
243
|
+
|
|
244
|
+
test("S12: usage publishes the active provider's plan and every window, and every provider the TUI panel lists", () => {
|
|
245
|
+
const snapshot = buildDesktopFeedSnapshot(input({
|
|
246
|
+
usage: { provider: "openai-codex", status: "ok", fetchedAt: CODEX.fetchedAt, plan: "pro", limits: CODEX.limits },
|
|
247
|
+
usageProviders: [
|
|
248
|
+
{ provider: "openai-codex", status: "ok", fetchedAt: CODEX.fetchedAt, plan: "pro", limits: CODEX.limits },
|
|
249
|
+
{ provider: "claude-bridge", status: "unavailable" },
|
|
250
|
+
{ provider: "nan", status: "failed" },
|
|
251
|
+
{ provider: "anthropic", status: "pending" },
|
|
252
|
+
],
|
|
253
|
+
}));
|
|
254
|
+
assert.deepEqual(snapshot.usage, {
|
|
255
|
+
...codexWire,
|
|
256
|
+
providers: [
|
|
257
|
+
codexWire,
|
|
258
|
+
{ provider: "claude-bridge", status: "unavailable", plan: null, fetchedAt: null, note: "no subscription usage for this provider", limits: [] },
|
|
259
|
+
{ provider: "nan", status: "failed", plan: null, fetchedAt: null, note: "fetch failed · r to retry", limits: [] },
|
|
260
|
+
{ provider: "anthropic", status: "pending", plan: null, fetchedAt: null, note: "usage arrives with the first response", limits: [] },
|
|
261
|
+
],
|
|
262
|
+
});
|
|
263
|
+
});
|
|
264
|
+
|
|
265
|
+
test("S12: a provider that reports nothing says so in the TUI's words; no usage at all stays null", () => {
|
|
266
|
+
const pending = buildDesktopFeedSnapshot(input({ usage: { provider: "openai-codex", status: "pending" }, usageProviders: [{ provider: "openai-codex", status: "pending" }] }));
|
|
267
|
+
assert.deepEqual(pending.usage, { provider: "openai-codex", status: "pending", plan: null, fetchedAt: null, note: "no usage yet · r to fetch", limits: [], providers: [{ provider: "openai-codex", status: "pending", plan: null, fetchedAt: null, note: "no usage yet · r to fetch", limits: [] }] });
|
|
268
|
+
assert.equal(buildDesktopFeedSnapshot(input({ usage: undefined, usageProviders: [] })).usage, null);
|
|
269
|
+
// Bounded: at most DESKTOP_FEED_LIMITS.usageProviders providers.
|
|
270
|
+
const many = Array.from({ length: 20 }, (_, i) => ({ provider: `p${i}`, status: "unavailable" as const }));
|
|
271
|
+
assert.equal(buildDesktopFeedSnapshot(input({ usage: many[0], usageProviders: many })).usage!.providers.length, DESKTOP_FEED_LIMITS.usageProviders);
|
|
272
|
+
});
|
|
273
|
+
|
|
274
|
+
// ---- Profiles: the shape ----
|
|
275
|
+
|
|
276
|
+
test("S12: profiles publish every saved profile with its tier, mode, orchestrator and per-agent models, and which one is active", () => {
|
|
277
|
+
const snapshot = buildDesktopFeedSnapshot(input({
|
|
278
|
+
profile: {
|
|
279
|
+
name: "fast (session)",
|
|
280
|
+
tier: "fast",
|
|
281
|
+
catalog: {
|
|
282
|
+
active: "fast",
|
|
283
|
+
default: "work",
|
|
284
|
+
items: [
|
|
285
|
+
{ name: "work", config: { "gentle-writer": { model: "anthropic/claude-sonnet-5-5", thinking: "medium" }, "gentle-verifier": {} }, mode: "organic" },
|
|
286
|
+
{ name: "fast", config: { orchestrator: { model: "openai-codex/gpt-5.5", thinking: "low", tier: "fast" }, "gentle-writer": { model: "openai-codex/gpt-5.5" } }, mode: "full-delegation" },
|
|
287
|
+
],
|
|
288
|
+
},
|
|
289
|
+
},
|
|
290
|
+
}));
|
|
291
|
+
assert.deepEqual(snapshot.profiles, {
|
|
292
|
+
active: "fast",
|
|
293
|
+
default: "work",
|
|
294
|
+
items: [
|
|
295
|
+
{ name: "work", tier: null, mode: "organic", orchestrator: null, roles: [{ agent: "gentle-verifier", model: "inherit", thinking: "inherit" }, { agent: "gentle-writer", model: "anthropic/claude-sonnet-5-5", thinking: "medium" }], truncated: false },
|
|
296
|
+
{ name: "fast", tier: "fast", mode: "full-delegation", orchestrator: { model: "openai-codex/gpt-5.5", thinking: "low", tier: "fast" }, roles: [{ agent: "gentle-writer", model: "openai-codex/gpt-5.5", thinking: "inherit" }], truncated: false },
|
|
297
|
+
],
|
|
298
|
+
truncated: false,
|
|
299
|
+
});
|
|
300
|
+
// The header's profile label is unchanged.
|
|
301
|
+
assert.deepEqual(snapshot.model.profile, { name: "fast (session)", tier: "fast" });
|
|
302
|
+
// No readable store: no list.
|
|
303
|
+
assert.equal(buildDesktopFeedSnapshot(input()).profiles, null);
|
|
304
|
+
});
|
|
305
|
+
|
|
306
|
+
test("S12: the profiles list is bounded: profiles and roles per profile", () => {
|
|
307
|
+
const roles = Object.fromEntries(Array.from({ length: 60 }, (_, i) => [`agent-${String(i).padStart(2, "0")}`, { model: "m" }]));
|
|
308
|
+
const items = Array.from({ length: 30 }, (_, i) => ({ name: `p${i}`, config: roles, mode: "organic" as const }));
|
|
309
|
+
const profiles = buildDesktopFeedSnapshot(input({ profile: { name: undefined, tier: undefined, catalog: { active: undefined, default: undefined, items } } })).profiles!;
|
|
310
|
+
assert.equal(profiles.items.length, DESKTOP_FEED_LIMITS.profiles);
|
|
311
|
+
assert.equal(profiles.truncated, true);
|
|
312
|
+
assert.equal(profiles.items[0]!.roles.length, DESKTOP_FEED_LIMITS.profileRoles);
|
|
313
|
+
assert.equal(profiles.items[0]!.truncated, true);
|
|
314
|
+
assert.equal(profiles.active, null);
|
|
315
|
+
});
|
|
316
|
+
|
|
317
|
+
test("S12: the profile reader lists the saved profiles from the same store /gentle:profiles uses", (t) => {
|
|
318
|
+
const root = mkdtempSync(join(tmpdir(), "desktop-profiles-"));
|
|
319
|
+
t.after(() => rmSync(root, { recursive: true, force: true }));
|
|
320
|
+
const configHome = join(root, "config");
|
|
321
|
+
mkdirSync(configHome, { recursive: true });
|
|
322
|
+
let file = createProfile(emptyProfilesFile(), "work", { "gentle-writer": { model: "anthropic/claude-sonnet-5-5", thinking: "medium" } });
|
|
323
|
+
file = createProfile(file, "fast", { orchestrator: { model: "openai-codex/gpt-5.5", tier: "fast" }, "gentle-writer": { model: "openai-codex/gpt-5.5" } });
|
|
324
|
+
file = setActiveProfile(file, "work");
|
|
325
|
+
writeFileSync(profilesFilePath(configHome), serializeProfilesFile(file));
|
|
326
|
+
const read = createDesktopFeedProfileReader({ GENTLE_PI_CONFIG_HOME: configHome, HOME: root }, () => undefined)(join(root, "w"), undefined);
|
|
327
|
+
assert.equal(read.name, "work");
|
|
328
|
+
assert.deepEqual(read.catalog?.default, "work");
|
|
329
|
+
assert.deepEqual(read.catalog?.active, "work");
|
|
330
|
+
assert.deepEqual(read.catalog?.items.map((item) => [item.name, item.mode, Object.keys(item.config)]), [["work", "organic", ["gentle-writer"]], ["fast", "organic", ["orchestrator", "gentle-writer"]]]);
|
|
331
|
+
});
|
|
332
|
+
|
|
333
|
+
// ---- Plan usage: the extension, on the TUI's cadence ----
|
|
334
|
+
|
|
335
|
+
test("S12: the feed publishes the owner's plan and windows once the TUI's session-start fetch settles, and never fetches itself", async (t) => {
|
|
336
|
+
const h = harness(t);
|
|
337
|
+
const owner = usageOwner(h.bus);
|
|
338
|
+
owner.entries = [{ provider: "openai-codex", supported: true, refreshable: true, failed: false }];
|
|
339
|
+
// The session starts: the debounced write runs, the follow-up reads wait.
|
|
340
|
+
h.fire("session_start", { reason: "startup" }, h.ctx);
|
|
341
|
+
await settle();
|
|
342
|
+
h.clock.run(1000);
|
|
343
|
+
await settle();
|
|
344
|
+
h.clock.run(1000);
|
|
345
|
+
assert.equal(h.snapshot().usage!.status, "pending");
|
|
346
|
+
assert.deepEqual(h.clock.delays(), [2000], "one follow-up read is armed");
|
|
347
|
+
// gentle-shell's own forced fetch at session_start lands in the owner's store.
|
|
348
|
+
owner.entries = [{ provider: "openai-codex", supported: true, refreshable: true, failed: false, snapshot: CODEX }, { provider: "anthropic", supported: true, refreshable: false, failed: false }];
|
|
349
|
+
await h.tick(3);
|
|
350
|
+
const usage = h.snapshot().usage!;
|
|
351
|
+
assert.equal(usage.plan, "pro");
|
|
352
|
+
assert.deepEqual(usage.limits, codexWire.limits);
|
|
353
|
+
assert.deepEqual(usage.providers.map((entry) => [entry.provider, entry.status, entry.note]), [["openai-codex", "ok", null], ["anthropic", "pending", "usage arrives with the first response"]]);
|
|
354
|
+
// A settled turn is the TUI's other fetch point (agent_end): the feed reads again, never refreshes.
|
|
355
|
+
h.fire("agent_settled", {}, h.ctx);
|
|
356
|
+
await h.tick(3);
|
|
357
|
+
assert.deepEqual(owner.refreshes, [], "the feed adds no provider call");
|
|
358
|
+
// Follow-up reads are bounded: nothing stays armed once they ran.
|
|
359
|
+
await h.tick(3);
|
|
360
|
+
assert.deepEqual(h.clock.delays(), []);
|
|
361
|
+
});
|
|
362
|
+
|
|
363
|
+
test("S12: a header-carried snapshot (Claude's 5h and 7d) reaches the feed for the active provider", async (t) => {
|
|
364
|
+
const h = harness(t);
|
|
365
|
+
const owner = usageOwner(h.bus);
|
|
366
|
+
h.ctx.model = { ...h.ctx.model, provider: "claude-bridge" } as typeof h.ctx.model;
|
|
367
|
+
owner.entries = [{ provider: "claude-bridge", supported: false, refreshable: false, failed: false }];
|
|
368
|
+
await h.start();
|
|
369
|
+
const claude: ProviderUsage = { provider: "claude-bridge", plan: undefined, fetchedAt: NOW, limits: [{ name: "all", limitReached: false, windows: [{ label: "5h", usedPercent: 12, windowSeconds: 18_000, resetAt: null }, { label: "week", usedPercent: 40, windowSeconds: 604_800, resetAt: null }] }] };
|
|
370
|
+
// gentle-shell's after_provider_response: records the snapshot, then tells its observers.
|
|
371
|
+
owner.entries = [{ provider: "claude-bridge", supported: false, refreshable: false, failed: false, snapshot: claude }];
|
|
372
|
+
for (const fn of owner.observers) fn({ provider: "claude-bridge", usage: claude });
|
|
373
|
+
await h.tick(1);
|
|
374
|
+
const usage = h.snapshot().usage!;
|
|
375
|
+
assert.equal(usage.status, "ok");
|
|
376
|
+
assert.deepEqual(usage.limits[0]!.windows.map((w) => w.label), ["5h", "week"]);
|
|
377
|
+
assert.deepEqual(usage.providers.map((entry) => entry.provider), ["claude-bridge"]);
|
|
378
|
+
});
|
|
379
|
+
|
|
380
|
+
test("S12: refresh_usage runs the owner's refresh once, as the TUI panel's r does, and the snapshot follows", async (t) => {
|
|
381
|
+
const h = harness(t);
|
|
382
|
+
const owner = usageOwner(h.bus);
|
|
383
|
+
owner.entries = [{ provider: "openai-codex", supported: true, refreshable: true, failed: false }];
|
|
384
|
+
owner.afterRefresh = [{ provider: "openai-codex", supported: true, refreshable: true, failed: false, snapshot: CODEX }];
|
|
385
|
+
await h.start();
|
|
386
|
+
const answer = await h.act("refresh_usage", {});
|
|
387
|
+
assert.equal(answer?.ok, true);
|
|
388
|
+
assert.deepEqual(answer?.data, { providers: [{ provider: "openai-codex", status: "ok" }] });
|
|
389
|
+
assert.deepEqual(owner.refreshes, [null]);
|
|
390
|
+
assert.equal(h.snapshot().usage!.plan, "pro");
|
|
391
|
+
// One provider, the RPC's own param.
|
|
392
|
+
assert.equal((await h.act("refresh_usage", { provider: "openai-codex" }))?.ok, true);
|
|
393
|
+
assert.deepEqual(owner.refreshes, [null, "openai-codex"]);
|
|
394
|
+
// Anything else never reaches the owner.
|
|
395
|
+
for (const args of [{ provider: "" }, { provider: 5 }, { provider: "x", force: true }]) {
|
|
396
|
+
const refused = await h.act("refresh_usage", args);
|
|
397
|
+
assert.deepEqual(refused?.error?.code, "invalid_action", JSON.stringify(args));
|
|
398
|
+
}
|
|
399
|
+
assert.deepEqual(owner.refreshes, [null, "openai-codex"]);
|
|
400
|
+
});
|
|
401
|
+
|
|
402
|
+
// ---- Profiles: the extension ----
|
|
403
|
+
|
|
404
|
+
test("S12: the snapshot carries the session's profiles from the reader", async (t) => {
|
|
405
|
+
const catalog = { active: "work", default: "work", items: [{ name: "work", config: { "gentle-writer": { model: "m1" } }, mode: "organic" as const }] };
|
|
406
|
+
const h = harness(t, { profile: () => ({ name: "work", tier: undefined, catalog }) });
|
|
407
|
+
await h.start();
|
|
408
|
+
assert.deepEqual(h.snapshot().profiles, { active: "work", default: "work", items: [{ name: "work", tier: null, mode: "organic", orchestrator: null, roles: [{ agent: "gentle-writer", model: "m1", thinking: "inherit" }], truncated: false }], truncated: false });
|
|
409
|
+
});
|
|
410
|
+
|
|
411
|
+
test("S12: apply_profile runs /gentle:profiles' own apply once, for this session, and the profile is read again", async (t) => {
|
|
412
|
+
const h = harness(t);
|
|
413
|
+
const calls = profilesOwner(h.bus, () => ({ status: "applied", notes: [{ level: "info", text: "Using \"fast\" in this session." }] }));
|
|
414
|
+
await h.start();
|
|
415
|
+
const reads = h.profileReads;
|
|
416
|
+
const answer = await h.act("apply_profile", { name: "fast" });
|
|
417
|
+
assert.deepEqual(calls, [{ profile: "fast", mode: "session" }]);
|
|
418
|
+
assert.deepEqual(answer, { ...answer, ok: true, data: { profile: "fast", mode: "session", status: "applied", notes: [{ level: "info", text: "Using \"fast\" in this session." }] } });
|
|
419
|
+
assert.ok(h.profileReads > reads, "the profile is read again after an apply");
|
|
420
|
+
});
|
|
421
|
+
|
|
422
|
+
test("S12: apply_profile hands the owner's confirmation to the desktop and passes its token back unchanged", async (t) => {
|
|
423
|
+
const h = harness(t);
|
|
424
|
+
const calls = profilesOwner(h.bus, (request) => (request.confirmation === "tok-1"
|
|
425
|
+
? { status: "applied", notes: [] }
|
|
426
|
+
: { status: "confirmation_required", title: "Use \"fast\"?", message: "gentle-writer: sonnet → gpt-5.5", confirmation: "tok-1" }));
|
|
427
|
+
await h.start();
|
|
428
|
+
const first = await h.act("apply_profile", { name: "fast" });
|
|
429
|
+
assert.deepEqual(first?.data, { profile: "fast", mode: "session", status: "confirmation_required", confirmation: { title: "Use \"fast\"?", message: "gentle-writer: sonnet → gpt-5.5", token: "tok-1" } });
|
|
430
|
+
const second = await h.act("apply_profile", { name: "fast", confirmation: "tok-1" });
|
|
431
|
+
assert.equal(second?.data?.status, "applied");
|
|
432
|
+
assert.deepEqual(calls, [{ profile: "fast", mode: "session" }, { profile: "fast", mode: "session", confirmation: "tok-1" }]);
|
|
433
|
+
});
|
|
434
|
+
|
|
435
|
+
test("S12: apply_profile keeps the owner's refusals and, like /gentle:profiles, also runs while the session works", async (t) => {
|
|
436
|
+
const h = harness(t);
|
|
437
|
+
const calls = profilesOwner(h.bus, (request) => (request.profile === "busy" ? { status: "busy" } : { status: "unknown_profile" }));
|
|
438
|
+
await h.start();
|
|
439
|
+
assert.deepEqual((await h.act("apply_profile", { name: "ghost" }))?.error, { code: "unknown_profile", message: "No saved profile with that name" });
|
|
440
|
+
assert.deepEqual((await h.act("apply_profile", { name: "busy" }))?.error, { code: "profile_apply_busy", message: "Another profile apply is in progress" });
|
|
441
|
+
assert.equal(calls.length, 2);
|
|
442
|
+
// Never the global default, never another key, never an over-long name: the owner is not asked.
|
|
443
|
+
for (const args of [{ name: "fast", mode: "default" }, { name: "" }, { name: "x".repeat(129) }, { profile: "fast" }, { name: "fast", confirmation: 7 }]) {
|
|
444
|
+
assert.equal((await h.act("apply_profile", args))?.error?.code, "invalid_action", JSON.stringify(args));
|
|
445
|
+
}
|
|
446
|
+
assert.equal(calls.length, 2);
|
|
447
|
+
// While the agent works the TUI still lets you switch the profile; the desktop matches it.
|
|
448
|
+
h.ctx.setIdle(false);
|
|
449
|
+
h.fire("agent_start", {}, h.ctx);
|
|
450
|
+
const busy = await h.act("apply_profile", { name: "fast" });
|
|
451
|
+
assert.notEqual(busy?.error?.code, "profile_while_busy");
|
|
452
|
+
assert.equal(calls.length, 3);
|
|
453
|
+
assert.equal(calls[2].profile, "fast");
|
|
454
|
+
});
|
|
455
|
+
|
|
456
|
+
test("S12: the action kinds add refresh_usage and apply_profile and keep every earlier kind", () => {
|
|
457
|
+
assert.deepEqual([...DESKTOP_ACTION_KINDS], ["set_permission_mode", "cancel_job", "cancel_subagent", "answer_question", "abort_turn", "send_prompt", "refresh_usage", "apply_profile"]);
|
|
458
|
+
const parse = (kind: string, args: Record<string, unknown>) => parseDesktopAction(JSON.stringify({ schema: DESKTOP_ACTION_SCHEMA, id: "x1", sessionId: "s", kind, args, createdAt: new Date(NOW).toISOString() }), "s", NOW);
|
|
459
|
+
assert.equal(parse("refresh_usage", {}).ok, true);
|
|
460
|
+
assert.equal(parse("apply_profile", { name: "fast" }).ok, true);
|
|
461
|
+
assert.equal(parse("set_permission_mode", { mode: "auto" }).ok, true);
|
|
462
|
+
});
|
|
463
|
+
|
|
464
|
+
// ---- The desktop RPC is unchanged ----
|
|
465
|
+
|
|
466
|
+
|
|
467
|
+
/** Channel lines other than the feed's session_snapshot events, without the shared event counter. */
|
|
468
|
+
function withoutSessionSnapshots(lines: Array<string | undefined>): unknown[] {
|
|
469
|
+
return lines
|
|
470
|
+
.map((line) => JSON.parse(line!) as Record<string, unknown>)
|
|
471
|
+
.filter((line) => line.event !== "session_snapshot")
|
|
472
|
+
.map(({ seq: _seq, ...line }) => line);
|
|
473
|
+
}
|
|
474
|
+
|
|
475
|
+
test("S12: desktop RPC refresh_subscription_usage and apply_profile answers are byte-identical with the feed loaded", async (t) => {
|
|
476
|
+
const previous = process.env[INTERACTIVE_HOST_ENV];
|
|
477
|
+
process.env[INTERACTIVE_HOST_ENV] = "1";
|
|
478
|
+
t.after(() => { if (previous === undefined) delete process.env[INTERACTIVE_HOST_ENV]; else process.env[INTERACTIVE_HOST_ENV] = previous; });
|
|
479
|
+
const run = async (withFeed: boolean) => {
|
|
480
|
+
const h = fakePi();
|
|
481
|
+
const owner = usageOwner(h.bus);
|
|
482
|
+
owner.entries = [{ provider: "openai-codex", supported: true, refreshable: true, failed: false }];
|
|
483
|
+
owner.afterRefresh = [{ provider: "openai-codex", supported: true, refreshable: true, failed: false, snapshot: CODEX }];
|
|
484
|
+
const applies = profilesOwner(h.bus, () => ({ status: "applied", notes: [] }));
|
|
485
|
+
desktopRpc(h.pi);
|
|
486
|
+
const root = mkdtempSync(join(tmpdir(), "desktop-plan-rpc-"));
|
|
487
|
+
t.after(() => rmSync(root, { recursive: true, force: true }));
|
|
488
|
+
const clock = fakeTimers();
|
|
489
|
+
if (withFeed) createDesktopFeedExtension({ env: { ...GENTLE_ENV, [INTERACTIVE_HOST_ENV]: "1" }, agentDir: join(root, "agent"), now: () => NOW, timers: clock.timers, git: () => async () => ({ stdout: "", code: 128 }), parentOf: async () => undefined, profile: () => ({ name: undefined, tier: undefined }), sweep: () => {}, actionWatch: () => () => {} })(h.pi);
|
|
490
|
+
const ctx = fakeCtx(root, { mode: "rpc" });
|
|
491
|
+
h.fire("session_start", { reason: "startup" }, ctx);
|
|
492
|
+
await settle();
|
|
493
|
+
const call = async (requestId: string, method: string, params: Record<string, unknown>) =>
|
|
494
|
+
h.commands.get("gentle:desktop")!.handler(JSON.stringify({ schema: DESKTOP_RPC_SCHEMA, requestId, method, params }), ctx);
|
|
495
|
+
await call("r1", "refresh_subscription_usage", {});
|
|
496
|
+
await call("r2", "apply_profile", { profile: "fast", mode: "session" });
|
|
497
|
+
await settle();
|
|
498
|
+
clock.run();
|
|
499
|
+
return { lines: ctx.widgets.filter((widget) => widget.key === "gentle-desktop-rpc").map((widget) => widget.lines[0]), refreshes: owner.refreshes, applies };
|
|
500
|
+
};
|
|
501
|
+
const without = await run(false);
|
|
502
|
+
const withFeed = await run(true);
|
|
503
|
+
// #3319: the feed also publishes its own session_snapshot events on the
|
|
504
|
+
// channel; every other line is unchanged, in the same order.
|
|
505
|
+
assert.deepEqual(withoutSessionSnapshots(withFeed.lines), withoutSessionSnapshots(without.lines));
|
|
506
|
+
assert.ok(without.lines.length >= 2);
|
|
507
|
+
assert.deepEqual(withFeed.refreshes, without.refreshes);
|
|
508
|
+
assert.deepEqual(withFeed.applies, without.applies);
|
|
509
|
+
});
|