gentle-pi 4.7.0 → 4.8.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 +55 -44
- package/assets/agents/gentle-ai-explore.md +3 -3
- package/assets/agents/gentle-ai-verify.md +20 -6
- package/assets/agents/gentle-ai-worker.md +6 -6
- package/assets/agents/jd-judge-a.md +1 -3
- package/assets/agents/jd-judge-b.md +1 -3
- package/assets/agents/review-readability.md +1 -5
- package/assets/agents/review-reliability.md +1 -5
- package/assets/agents/review-resilience.md +1 -5
- package/assets/agents/review-risk.md +1 -5
- package/assets/design-canvas/canvas-api.js +45 -0
- package/assets/design-canvas/canvas-boards.js +456 -0
- package/assets/design-canvas/canvas-boot.js +217 -0
- package/assets/design-canvas/canvas-checks.js +491 -0
- package/assets/design-canvas/canvas-comments.js +315 -0
- package/assets/design-canvas/canvas-compare.js +159 -0
- package/assets/design-canvas/canvas-events.js +75 -0
- package/assets/design-canvas/canvas-export.js +393 -0
- package/assets/design-canvas/canvas-focus.js +203 -0
- package/assets/design-canvas/canvas-handoffs.js +150 -0
- package/assets/design-canvas/canvas-i18n-es.js +392 -0
- package/assets/design-canvas/canvas-i18n.js +108 -0
- package/assets/design-canvas/canvas-layout.js +526 -0
- package/assets/design-canvas/canvas-menu.js +213 -0
- package/assets/design-canvas/canvas-messages.js +86 -0
- package/assets/design-canvas/canvas-minimap.js +163 -0
- package/assets/design-canvas/canvas-parts.js +401 -0
- package/assets/design-canvas/canvas-popover.js +234 -0
- package/assets/design-canvas/canvas-rail.js +348 -0
- package/assets/design-canvas/canvas-sizes.js +524 -0
- package/assets/design-canvas/canvas-store.js +164 -0
- package/assets/design-canvas/canvas-tokens.js +674 -0
- package/assets/design-canvas/canvas-ui.js +24 -0
- package/assets/design-canvas/canvas-view.js +184 -0
- package/assets/design-canvas/canvas.css +746 -15
- package/assets/design-canvas/canvas.js +2 -1506
- package/assets/design-canvas/index.html +117 -36
- package/assets/design-canvas/inspector.js +546 -16
- package/assets/install-wizard/wizard.js +5 -1
- package/assets/migrations/agent-body-history.json +24 -0
- package/assets/orchestrator-delegation-reference.md +8 -14
- package/assets/orchestrator-delegation.md +4 -4
- package/assets/orchestrator-full-delegation-card.md +4 -5
- package/assets/orchestrator-full-delegation.md +8 -8
- package/assets/orchestrator-memory.md +2 -2
- package/assets/orchestrator-prompts.md +1 -1
- package/assets/orchestrator-quota-recovery.md +5 -0
- package/assets/orchestrator-skills.md +13 -12
- package/assets/orchestrator-tracking.md +10 -14
- package/assets/orchestrator-verification.md +10 -8
- package/assets/orchestrator-writer.md +4 -4
- package/assets/orchestrator.md +18 -22
- package/bin/gentle-shell.mjs +128 -9
- package/contracts/review-provider-contract-mirror/provider-contract.lock.json +8 -9
- package/contracts/review-provider-contract-mirror/{v1.4.0 → v1.5.0}/bundle/manifest.json +3 -3
- package/contracts/review-provider-contract-mirror/{v1.4.0 → v1.5.0}/bundle/orchestration/pi.md +1 -0
- package/contracts/review-provider-contract-mirror/{v1.4.0 → v1.5.0}/bundle/routing/pi.md +6 -6
- package/contracts/review-provider-contract-mirror/{v1.4.0 → v1.5.0}/generated/provider-capabilities.baseline.json +3 -3
- package/contracts/review-provider-contract-mirror/{v1.4.0 → v1.5.0}/generated/provider-roles.baseline.json +1 -1
- package/docs/assets/brand/sponsor-banner.svg +60 -0
- package/docs/bundled-install.md +14 -6
- package/docs/delegated-verification.md +18 -2
- package/docs/desktop-rpc.md +1253 -0
- package/docs/gentle-agents-activity.md +26 -0
- package/docs/gentle-shell.md +39 -16
- package/docs/install-wizard.md +30 -21
- package/docs/odd-preparation-continuity.md +24 -0
- package/docs/permission-modes.md +9 -1
- package/docs/prompt-budget.md +12 -0
- package/docs/rdd-odd-friction-triage-2026-11-07.md +57 -0
- package/docs/readme-reference.md +76 -24
- package/docs/review-coordinator.md +29 -9
- package/docs/review-delivery-preflight.md +22 -0
- package/docs/work-continuity.md +11 -1
- package/extensions/ask-user-question.ts +2 -2
- package/extensions/child-context.ts +21 -7
- package/extensions/gentle-agents.ts +234 -33
- package/extensions/gentle-ai.ts +576 -135
- package/extensions/gentle-design.ts +69 -3
- package/extensions/gentle-desktop-rpc.ts +143 -0
- package/extensions/gentle-guide.ts +3 -0
- package/extensions/gentle-shell.ts +105 -52
- package/extensions/gentle-todo.ts +48 -25
- package/extensions/skill-registry.ts +248 -223
- package/lib/agent-assets.ts +30 -6
- package/lib/agent-tool-overlay.ts +117 -0
- package/lib/agents-config.ts +47 -6
- package/lib/agents-message-delivery.ts +17 -0
- package/lib/agents-messaging.ts +8 -2
- package/lib/agents-protocol.ts +15 -0
- package/lib/agents-report-cap.ts +115 -0
- package/lib/agents-runner.ts +91 -6
- package/lib/agents-session-transport.ts +17 -1
- package/lib/background-jobs-tools.ts +9 -4
- package/lib/bounded-writer-admission.ts +184 -31
- package/lib/child-context-files.ts +21 -6
- package/lib/codemode-renderer.ts +1 -0
- package/lib/delivery-conflict-markers.ts +349 -0
- package/lib/design-canvas-assets.ts +36 -0
- package/lib/design-canvas-server.ts +241 -23
- package/lib/design-comments.ts +94 -4
- package/lib/design-handoffs.ts +2 -1
- package/lib/design-layout.ts +125 -0
- package/lib/design-parts.ts +281 -0
- package/lib/design-system-tokens.ts +111 -0
- package/lib/desktop-agents-service.ts +294 -0
- package/lib/desktop-design-service.ts +233 -0
- package/lib/desktop-jobs-service.ts +263 -0
- package/lib/desktop-rpc-agents.ts +294 -0
- package/lib/desktop-rpc-config.ts +731 -0
- package/lib/desktop-rpc-design.ts +138 -0
- package/lib/desktop-rpc-jobs.ts +181 -0
- package/lib/desktop-rpc-permissions.ts +177 -0
- package/lib/desktop-rpc-profiles.ts +196 -0
- package/lib/desktop-rpc-usage.ts +229 -0
- package/lib/desktop-rpc.ts +225 -0
- package/lib/desktop-usage-service.ts +310 -0
- package/lib/destructive-command-guard.ts +188 -13
- package/lib/gentle-ai-renderer.ts +13 -1
- package/lib/gentle-design.ts +201 -14
- package/lib/gentle-shell-bundled.ts +100 -9
- package/lib/hidden-tools.ts +35 -0
- package/lib/inprocess-reviewer.ts +96 -12
- package/lib/model-fallback-policy.ts +9 -0
- package/lib/model-routing-authority.ts +9 -0
- package/lib/nan-provider.ts +42 -28
- package/lib/native-review-cli.ts +79 -4
- package/lib/orchestrator-discovery.ts +39 -2
- package/lib/reply-language-anchor.ts +27 -2
- package/lib/request-context-placement.ts +53 -0
- package/lib/review-candidate-view.ts +11 -1
- package/lib/review-continuation-registry.ts +17 -0
- package/lib/review-coordinator.ts +252 -8
- package/lib/review-delivery-preflight.ts +85 -0
- package/lib/review-host-relay.ts +5 -1
- package/lib/review-integration-v2.ts +56 -3
- package/lib/reviewer-stream.ts +87 -0
- package/lib/shell-prompt.ts +16 -3
- package/lib/shell-usage.ts +10 -0
- package/lib/vim-editor-adapter.ts +9 -2
- package/lib/writer-batch-admission.ts +55 -0
- package/lib/yolo-session-policy.ts +6 -1
- package/package.json +2 -2
- package/prompts/skill-creation.md +1 -10
- package/runtime/design-canvas-assets.mjs +37 -0
- package/runtime/gentle-shell-bundled.mjs +100 -9
- package/runtime/native-review-cli.mjs +79 -4
- package/runtime/review-integration-v2.mjs +56 -3
- package/scripts/bootstrap.cmd +2 -2
- package/scripts/bootstrap.sh +41 -4
- package/scripts/build-full-delegation-card.mjs +4 -0
- package/scripts/build-runtime-modules.mjs +1 -0
- package/scripts/gentle-ai-installer.mjs +10 -10
- package/scripts/gentle-ai-proxy.mjs +1 -1
- package/scripts/installer-downloads.mjs +34 -8
- package/scripts/installer-preflight.mjs +28 -17
- package/scripts/installer-probes.mjs +25 -5
- package/scripts/installer-server.mjs +38 -9
- package/scripts/installer-windows.mjs +2 -2
- package/scripts/pi-update.mjs +166 -27
- package/scripts/prepare-verifier.mjs +107 -0
- package/scripts/update-agent-body-history.mjs +55 -8
- package/scripts/verify-package-files.mjs +40 -19
- package/skills/branch-pr/SKILL.md +16 -16
- package/skills/comment-writer/SKILL.md +1 -1
- package/skills/design/SKILL.md +6 -6
- package/skills/gentle-ai/SKILL.md +5 -5
- package/skills/judgment-day/SKILL.md +2 -2
- package/skills/judgment-day/references/prompts-and-formats.md +1 -1
- package/skills/rdd-defect-workflow/SKILL.md +6 -6
- package/skills/skill-improver/SKILL.md +2 -2
- package/skills/skill-registry/SKILL.md +11 -13
- package/skills/tui-design/SKILL.md +1 -1
- package/skills/work-unit-commits/SKILL.md +5 -5
- package/tests/agent-prompt-diet-contract.test.ts +101 -0
- package/tests/agent-tool-overlay-acceptance.test.ts +158 -0
- package/tests/agent-tool-overlay.test.ts +89 -0
- package/tests/agents-config.test.ts +10 -1
- package/tests/agents-message-delivery.test.ts +36 -0
- package/tests/agents-queries.test.ts +144 -4
- package/tests/agents-report-cap.test.ts +126 -0
- package/tests/agents-runner.test.ts +37 -1
- package/tests/agents-session-transport.test.ts +34 -0
- package/tests/always-on-prompt-verdicts-contract.test.ts +188 -0
- package/tests/append-system-prompt-route.test.ts +10 -2
- package/tests/approved-text-leftovers-contract.test.ts +136 -0
- package/tests/artifact-language.test.ts +1 -1
- package/tests/ask-user-question.test.ts +2 -1
- package/tests/audit-leftovers-contract.test.ts +51 -0
- package/tests/bounded-stop-contract.test.ts +9 -1
- package/tests/branch-pr-skill.test.ts +10 -1
- package/tests/bundled-install.test.ts +1 -1
- package/tests/child-context-files.test.ts +64 -8
- package/tests/child-skills-catalog.test.ts +56 -0
- package/tests/codemode-rendering.test.ts +4 -1
- package/tests/delegate-for-reason-contract.test.ts +30 -8
- package/tests/delivery-conflict-markers.test.ts +348 -0
- package/tests/design-canvas-all-sizes.test.ts +631 -0
- package/tests/design-canvas-allowlist.test.ts +32 -0
- package/tests/design-canvas-assets.test.ts +11 -878
- package/tests/design-canvas-boards.test.ts +77 -0
- package/tests/design-canvas-checks.test.ts +655 -0
- package/tests/design-canvas-compare.test.ts +79 -0
- package/tests/design-canvas-events.test.ts +59 -0
- package/tests/design-canvas-export.test.ts +1168 -0
- package/tests/design-canvas-focus.test.ts +113 -0
- package/tests/design-canvas-handoffs.test.ts +59 -0
- package/tests/design-canvas-i18n-review.test.ts +513 -0
- package/tests/design-canvas-i18n-views.test.ts +259 -0
- package/tests/design-canvas-i18n.test.ts +526 -0
- package/tests/design-canvas-inspector.test.ts +937 -0
- package/tests/design-canvas-layout.test.ts +1222 -0
- package/tests/design-canvas-minimap.test.ts +413 -0
- package/tests/design-canvas-modules.test.ts +90 -0
- package/tests/design-canvas-parts.test.ts +721 -0
- package/tests/design-canvas-rail.test.ts +799 -0
- package/tests/design-canvas-server.test.ts +855 -17
- package/tests/design-canvas-sizes.test.ts +548 -0
- package/tests/design-canvas-store.test.ts +180 -0
- package/tests/design-canvas-tokens.test.ts +965 -0
- package/tests/design-canvas-view.test.ts +299 -0
- package/tests/design-comments.test.ts +201 -1
- package/tests/design-handoffs.test.ts +20 -0
- package/tests/design-layout.test.ts +100 -0
- package/tests/design-parts.test.ts +260 -0
- package/tests/design-system-tokens.test.ts +215 -0
- package/tests/desktop-rpc-agents.test.ts +893 -0
- package/tests/desktop-rpc-config.test.ts +1452 -0
- package/tests/desktop-rpc-design.test.ts +662 -0
- package/tests/desktop-rpc-jobs.test.ts +796 -0
- package/tests/desktop-rpc-permissions.test.ts +311 -0
- package/tests/desktop-rpc-profiles.test.ts +140 -0
- package/tests/desktop-rpc-safety.test.ts +119 -0
- package/tests/desktop-rpc-usage.test.ts +697 -0
- package/tests/desktop-rpc.test.ts +252 -0
- package/tests/devbinary/pi-host-relay.devtest.ts +149 -80
- package/tests/devbinary/review-session-consent.devtest.ts +84 -0
- package/tests/engram-safety.test.ts +111 -0
- package/tests/fixtures/devbinary/status-v9-escalated-non-blocking.captured.json +92 -0
- package/tests/fixtures/devbinary/status-v9-escalated-non-blocking.provenance.md +3 -0
- package/tests/fixtures/primary-session-prompt/gentleman.golden.md +20 -29
- package/tests/fixtures/refusal-identity.probe.mjs +139 -0
- package/tests/full-delegation-closure.test.ts +29 -0
- package/tests/gentle-agents.test.ts +329 -4
- package/tests/gentle-ai-binary.test.ts +1 -1
- package/tests/gentle-ai-child-guards.test.ts +1 -0
- package/tests/gentle-ai-installer.test.ts +52 -51
- package/tests/gentle-ai-renderer.test.ts +36 -2
- package/tests/gentle-ai.test.ts +121 -6
- package/tests/gentle-design.test.ts +365 -1
- package/tests/gentle-shell-bundled.test.ts +91 -5
- package/tests/gentle-shell-launcher.test.ts +1 -1
- package/tests/gentle-shell.test.ts +118 -87
- package/tests/gentle-todo.test.ts +32 -9
- package/tests/hidden-tools.test.ts +188 -0
- package/tests/independent-recovery-delivery.test.ts +19 -5
- package/tests/inprocess-reviewer.test.ts +73 -0
- package/tests/install-wizard.test.ts +27 -1
- package/tests/installer-downloads.test.ts +30 -1
- package/tests/installer-posix-bootstrap.test.ts +114 -13
- package/tests/installer-preflight.test.ts +49 -1
- package/tests/installer-probes.test.ts +146 -0
- package/tests/installer-server.test.ts +203 -4
- package/tests/installer-windows-bootstrap.test.ts +19 -1
- package/tests/judgment-day-severity-admission.test.ts +46 -0
- package/tests/lazy-module-contradictions-contract.test.ts +158 -0
- package/tests/maintainer/desktop-rpc.maintest.ts +632 -0
- package/tests/maintainer/pi-update-source.maintest.ts +48 -18
- package/tests/model-fallback-policy.test.ts +26 -7
- package/tests/nan-provider-runtime.test.ts +17 -3
- package/tests/nan-provider.test.ts +111 -56
- package/tests/native-review-capability-contract.test.ts +11 -1
- package/tests/native-review-cli-nonblocking-findings.test.ts +165 -0
- package/tests/native-review-parity.test.ts +24 -5
- package/tests/native-review-refusal-identity.test.ts +25 -0
- package/tests/no-self-pause-contract.test.ts +11 -3
- package/tests/odd-integration.test.ts +11 -3
- package/tests/odd-routing-contract.test.ts +80 -28
- package/tests/orchestrator-budget.test.ts +30 -5
- package/tests/orchestrator-consultation-sdk.test.ts +32 -6
- package/tests/orchestrator-delegation-mode.test.ts +2 -1
- package/tests/orchestrator-discovery.test.ts +28 -0
- package/tests/orchestrator-prompt-budget.test.ts +11 -2
- package/tests/orchestrator-prompt-diet-contract.test.ts +221 -0
- package/tests/orchestrator-rdd-ownership.test.ts +2 -1
- package/tests/orchestrator-work-search.test.ts +4 -2
- package/tests/package-files.test.ts +25 -1
- package/tests/package-manifest.test.ts +11 -10
- package/tests/parallel-reason-contract.test.ts +6 -3
- package/tests/permission-allowlist.test.ts +200 -30
- package/tests/persona-neutral-voseo.test.ts +4 -4
- package/tests/persona-reply-language.test.ts +1 -1
- package/tests/persona-single-channel.test.ts +13 -5
- package/tests/pi-update-launcher.test.ts +17 -7
- package/tests/pi-update-source.test.ts +113 -6
- package/tests/pi-update.test.ts +294 -19
- package/tests/pnpm-workspace-policy.test.ts +47 -0
- package/tests/primary-context-files.test.ts +233 -0
- package/tests/primary-context-three-files.test.ts +174 -0
- package/tests/provider-defect-handoff.test.ts +9 -2
- package/tests/rdd-aware-verification-contract.test.ts +1 -1
- package/tests/rdd-status-line.test.ts +94 -1
- package/tests/reply-language-anchor-placement.test.ts +184 -0
- package/tests/reply-language-anchor.test.ts +17 -1
- package/tests/request-context-append-only.test.ts +218 -0
- package/tests/request-context-placement.test.ts +148 -0
- package/tests/review-agent-end-preflight.test.ts +79 -1
- package/tests/review-candidate-view.test.ts +65 -0
- package/tests/review-continuation-registry.test.ts +31 -0
- package/tests/review-contract-prompt.test.ts +1 -1
- package/tests/review-controller.test.ts +2 -1
- package/tests/review-coordinator-correction-gate.test.ts +105 -0
- package/tests/review-coordinator-findings.test.ts +206 -0
- package/tests/review-coordinator-nonblocking-scope.test.ts +169 -0
- package/tests/review-coordinator.test.ts +271 -4
- package/tests/review-delivery-preflight.test.ts +462 -0
- package/tests/review-due-compaction.test.ts +31 -0
- package/tests/review-due-public-boundary.test.ts +26 -0
- package/tests/review-integration-nonblocking-findings.test.ts +108 -0
- package/tests/review-json-arguments.test.ts +41 -2
- package/tests/review-ledger-contract.test.ts +19 -40
- package/tests/review-loadout-rdd-off-sdk.test.ts +30 -1
- package/tests/review-one-call-findings.test.ts +131 -0
- package/tests/review-one-call-followups.test.ts +308 -0
- package/tests/review-one-call-reviewer-requests.test.ts +207 -0
- package/tests/review-one-call.test.ts +452 -0
- package/tests/review-relay-transport-agent.test.ts +28 -1
- package/tests/review-reviewer-evidence.test.ts +41 -1
- package/tests/review-risk-assessment.test.ts +52 -5
- package/tests/review-run-statement-guidance-independent.test.ts +54 -0
- package/tests/review-session-standing-permission-controller.test.ts +32 -2
- package/tests/review-tool-prose-budget.test.ts +1 -0
- package/tests/reviewer-stream.test.ts +149 -0
- package/tests/session-profile-extension.test.ts +2 -2
- package/tests/shell-prompt.test.ts +17 -0
- package/tests/shell-usage.test.ts +59 -10
- package/tests/skill-contradictions-contract.test.ts +122 -0
- package/tests/skill-registry-watcher.test.ts +216 -2
- package/tests/skill-registry.test.ts +929 -306
- package/tests/support/design-canvas-dom.ts +369 -0
- package/tests/support/review-coordinator-runtime.ts +212 -17
- package/tests/task-size-routing-contract.test.ts +42 -11
- package/tests/test-strength-contract.test.ts +2 -1
- package/tests/todo-request-append-only.test.ts +214 -0
- package/tests/tool-batching-contract.test.ts +3 -1
- package/tests/update-agent-body-history.test.ts +138 -0
- package/tests/verification-tiers-contract.test.ts +229 -0
- package/tests/verifier-preparation.test.ts +229 -0
- package/tests/verify-agent-contract.test.ts +20 -2
- package/tests/verify-first-launch-contract.test.ts +87 -11
- package/tests/vim-editor-adapter.test.ts +2 -2
- package/tests/work-continuity-contract.test.ts +54 -11
- package/tests/writer-admission-messages.test.ts +232 -0
- package/tests/writer-batch-admission.test.ts +66 -0
- package/tests/writer-edit-surface-scope.test.ts +52 -20
- package/tests/writer-feature-document-admission.test.ts +184 -0
- package/tests/yolo-mode.test.ts +39 -0
- package/skills/_shared/review-ledger-contract.md +0 -106
- /package/contracts/review-provider-contract-mirror/{v1.4.0 → v1.5.0}/bundle/README.md +0 -0
- /package/contracts/review-provider-contract-mirror/{v1.4.0 → v1.5.0}/bundle/schemas/lens.schema.json +0 -0
- /package/contracts/review-provider-contract-mirror/{v1.4.0 → v1.5.0}/bundle/schemas/refuter.schema.json +0 -0
- /package/contracts/review-provider-contract-mirror/{v1.4.0 → v1.5.0}/bundle/schemas/targeted-validator.schema.json +0 -0
- /package/contracts/review-provider-contract-mirror/{v1.4.0 → v1.5.0}/bundle/vectors/lens.json +0 -0
- /package/contracts/review-provider-contract-mirror/{v1.4.0 → v1.5.0}/bundle/vectors/refuter.json +0 -0
- /package/contracts/review-provider-contract-mirror/{v1.4.0 → v1.5.0}/bundle/vectors/targeted-validator.json +0 -0
|
@@ -0,0 +1,632 @@
|
|
|
1
|
+
import assert from "node:assert/strict";
|
|
2
|
+
import { spawn, spawnSync, type ChildProcessWithoutNullStreams } from "node:child_process";
|
|
3
|
+
import { existsSync, mkdirSync, mkdtempSync, readFileSync, rmSync, writeFileSync } from "node:fs";
|
|
4
|
+
import { tmpdir } from "node:os";
|
|
5
|
+
import { join, resolve } from "node:path";
|
|
6
|
+
import { test } from "node:test";
|
|
7
|
+
import { fileURLToPath } from "node:url";
|
|
8
|
+
import { DESKTOP_RPC_SCHEMA, DESKTOP_RPC_WIDGET } from "../../lib/desktop-rpc.ts";
|
|
9
|
+
import { normalizeProfilesFile, serializeProfilesFile } from "../../lib/agent-profiles.ts";
|
|
10
|
+
|
|
11
|
+
const packageRoot = fileURLToPath(new URL("../..", import.meta.url));
|
|
12
|
+
const runtime = resolve(packageRoot, "node_modules/@earendil-works/pi-coding-agent/dist/bundle/cli.js");
|
|
13
|
+
const desktopExtension = resolve(packageRoot, "extensions/gentle-desktop-rpc.ts");
|
|
14
|
+
const ownerExtension = resolve(packageRoot, "extensions/gentle-ai.ts");
|
|
15
|
+
const usageOwnerExtension = resolve(packageRoot, "extensions/gentle-shell.ts");
|
|
16
|
+
const designOwnerExtension = resolve(packageRoot, "extensions/gentle-design.ts");
|
|
17
|
+
const jobsOwnerExtension = resolve(packageRoot, "extensions/gentle-agents.ts");
|
|
18
|
+
const WAIT_TIMEOUT_MS = 20_000;
|
|
19
|
+
|
|
20
|
+
/** Isolated filesystem, no provider, no network, no inherited user configuration. */
|
|
21
|
+
function isolatedRoot(prefix: string): string {
|
|
22
|
+
const root = mkdtempSync(join(tmpdir(), prefix));
|
|
23
|
+
for (const name of ["home", "sessions", "tmp", "config", "workspace"]) mkdirSync(join(root, name));
|
|
24
|
+
return root;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
function probeEnvironment(root: string): Record<string, string> {
|
|
28
|
+
const home = join(root, "home");
|
|
29
|
+
const temporary = join(root, "tmp");
|
|
30
|
+
return {
|
|
31
|
+
PATH: process.env.PATH ?? "",
|
|
32
|
+
HOME: home,
|
|
33
|
+
USERPROFILE: home,
|
|
34
|
+
TMPDIR: temporary,
|
|
35
|
+
TMP: temporary,
|
|
36
|
+
TEMP: temporary,
|
|
37
|
+
PI_OFFLINE: "1",
|
|
38
|
+
PI_NO_LOCAL_LLM: "1",
|
|
39
|
+
NO_COLOR: "1",
|
|
40
|
+
GENTLE_SHELL_INTERACTIVE_HOST: "1",
|
|
41
|
+
GENTLE_PI_CONFIG_HOME: join(root, "config"),
|
|
42
|
+
GENTLE_PI_AGENT_HOME: join(home, "agent"),
|
|
43
|
+
PI_CODING_AGENT_DIR: join(home, "agent"),
|
|
44
|
+
GIT_CONFIG_GLOBAL: process.platform === "win32" ? "NUL" : "/dev/null",
|
|
45
|
+
GIT_CONFIG_NOSYSTEM: "1",
|
|
46
|
+
GIT_TERMINAL_PROMPT: "0",
|
|
47
|
+
};
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
function probeArgs(root: string, extensions: string[]): string[] {
|
|
51
|
+
return [
|
|
52
|
+
runtime,
|
|
53
|
+
"--mode", "rpc",
|
|
54
|
+
"--no-extensions",
|
|
55
|
+
...extensions.flatMap((extension) => ["-e", extension]),
|
|
56
|
+
"--session-dir", join(root, "sessions"),
|
|
57
|
+
"--offline", "--no-mcp", "--no-skills", "--no-context-files",
|
|
58
|
+
];
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
/** A live RPC session: one request at a time, correlated by record id or requestId. */
|
|
62
|
+
class LiveProbe {
|
|
63
|
+
readonly root: string;
|
|
64
|
+
private readonly child: ChildProcessWithoutNullStreams;
|
|
65
|
+
private readonly records: Array<Record<string, any>> = [];
|
|
66
|
+
private buffer = "";
|
|
67
|
+
private stderr = "";
|
|
68
|
+
private readonly waiters = new Set<() => void>();
|
|
69
|
+
private readonly closed: Promise<number | null>;
|
|
70
|
+
|
|
71
|
+
constructor(root: string, extensions: string[]) {
|
|
72
|
+
this.root = root;
|
|
73
|
+
this.child = spawn(process.execPath, probeArgs(root, extensions), {
|
|
74
|
+
cwd: join(root, "workspace"),
|
|
75
|
+
env: probeEnvironment(root),
|
|
76
|
+
stdio: ["pipe", "pipe", "pipe"],
|
|
77
|
+
});
|
|
78
|
+
this.closed = new Promise((resolveClosed) => this.child.on("close", (code) => resolveClosed(code)));
|
|
79
|
+
this.child.stdout.setEncoding("utf8");
|
|
80
|
+
this.child.stderr.setEncoding("utf8");
|
|
81
|
+
this.child.stderr.on("data", (chunk: string) => { this.stderr += chunk; });
|
|
82
|
+
this.child.stdout.on("data", (chunk: string) => this.consume(chunk));
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
private consume(chunk: string): void {
|
|
86
|
+
this.buffer += chunk;
|
|
87
|
+
let newline = this.buffer.indexOf("\n");
|
|
88
|
+
while (newline >= 0) {
|
|
89
|
+
const line = this.buffer.slice(0, newline).trim();
|
|
90
|
+
this.buffer = this.buffer.slice(newline + 1);
|
|
91
|
+
if (line.length > 0) this.records.push(JSON.parse(line));
|
|
92
|
+
newline = this.buffer.indexOf("\n");
|
|
93
|
+
}
|
|
94
|
+
for (const waiter of [...this.waiters]) waiter();
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
send(record: Record<string, unknown>): void {
|
|
98
|
+
this.child.stdin.write(`${JSON.stringify(record)}\n`);
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
waitFor<T extends Record<string, any>>(predicate: (record: Record<string, any>) => boolean, label: string): Promise<T> {
|
|
102
|
+
const find = () => this.records.find(predicate) as T | undefined;
|
|
103
|
+
const existing = find();
|
|
104
|
+
if (existing) return Promise.resolve(existing);
|
|
105
|
+
return new Promise((resolveWait, rejectWait) => {
|
|
106
|
+
const timer = setTimeout(() => {
|
|
107
|
+
this.waiters.delete(check);
|
|
108
|
+
rejectWait(new Error(`${label} did not arrive within ${WAIT_TIMEOUT_MS}ms; stderr: ${this.stderr.slice(0, 500)}`));
|
|
109
|
+
}, WAIT_TIMEOUT_MS);
|
|
110
|
+
const check = () => {
|
|
111
|
+
const hit = find();
|
|
112
|
+
if (!hit) return;
|
|
113
|
+
clearTimeout(timer);
|
|
114
|
+
this.waiters.delete(check);
|
|
115
|
+
resolveWait(hit);
|
|
116
|
+
};
|
|
117
|
+
this.waiters.add(check);
|
|
118
|
+
});
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
desktopPayloads(): Array<Record<string, any>> {
|
|
122
|
+
return this.records
|
|
123
|
+
.filter((record) => record.type === "extension_ui_request" && record.widgetKey === DESKTOP_RPC_WIDGET)
|
|
124
|
+
.map((record) => JSON.parse(record.widgetLines[0]));
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
async close(): Promise<{ status: number | null; stderr: string }> {
|
|
128
|
+
if (!this.child.stdin.destroyed) this.child.stdin.end();
|
|
129
|
+
const status = await this.closed;
|
|
130
|
+
return { status, stderr: this.stderr };
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
kill(): void {
|
|
134
|
+
this.child.kill("SIGKILL");
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
function desktopRequest(requestId: string, method: string, params: Record<string, unknown> = {}) {
|
|
139
|
+
return { schema: DESKTOP_RPC_SCHEMA, requestId, method, params };
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
function prompt(id: string, request: Record<string, unknown>) {
|
|
143
|
+
return { id, type: "prompt", message: `/gentle:desktop ${JSON.stringify(request)}` };
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
test("installed Pi dispatches Desktop RPC without adding conversation messages", () => {
|
|
147
|
+
const root = isolatedRoot("desktop-rpc-maintainer-");
|
|
148
|
+
try {
|
|
149
|
+
const input = [
|
|
150
|
+
prompt("prompt-1", desktopRequest("real-1", "capabilities")),
|
|
151
|
+
{ id: "messages-1", type: "get_messages" },
|
|
152
|
+
].map((value) => JSON.stringify(value)).join("\n") + "\n";
|
|
153
|
+
const child = spawnSync(process.execPath, probeArgs(root, [desktopExtension]), {
|
|
154
|
+
cwd: join(root, "workspace"),
|
|
155
|
+
env: probeEnvironment(root),
|
|
156
|
+
input,
|
|
157
|
+
encoding: "utf8",
|
|
158
|
+
timeout: 15000,
|
|
159
|
+
});
|
|
160
|
+
|
|
161
|
+
assert.ifError(child.error);
|
|
162
|
+
assert.equal(child.status, 0, child.stderr);
|
|
163
|
+
assert.equal(child.stderr, "");
|
|
164
|
+
const records = child.stdout.trim().split("\n").map((line) => JSON.parse(line));
|
|
165
|
+
const promptResponse = records.find((record) => record.id === "prompt-1");
|
|
166
|
+
assert.deepEqual(promptResponse, {
|
|
167
|
+
id: "prompt-1",
|
|
168
|
+
type: "response",
|
|
169
|
+
command: "prompt",
|
|
170
|
+
success: true,
|
|
171
|
+
data: { disposition: "handled" },
|
|
172
|
+
});
|
|
173
|
+
const messages = records.find((record) => record.id === "messages-1");
|
|
174
|
+
assert.deepEqual(messages.data, { messages: [] });
|
|
175
|
+
|
|
176
|
+
const widget = records.find((record) => record.type === "extension_ui_request" && record.widgetKey === DESKTOP_RPC_WIDGET);
|
|
177
|
+
assert.equal(widget.method, "setWidget");
|
|
178
|
+
const response = JSON.parse(widget.widgetLines[0]);
|
|
179
|
+
assert.equal(response.schema, DESKTOP_RPC_SCHEMA);
|
|
180
|
+
assert.equal(response.kind, "response");
|
|
181
|
+
assert.equal(response.requestId, "real-1");
|
|
182
|
+
assert.equal(response.ok, true);
|
|
183
|
+
assert.deepEqual(response.data.methods, ["capabilities", "get_snapshot", "get_config", "set_config", "get_permission_mode", "set_permission_mode", "get_subscription_usage", "refresh_subscription_usage", "get_design_canvas", "list_jobs", "cancel_job", "apply_profile", "list_subagents", "cancel_subagent"]);
|
|
184
|
+
assert.deepEqual(response.data.events, ["config_changed", "permission_mode_changed", "rate_limit", "design_canvas", "jobs_update", "profile_applied", "agents_update"]);
|
|
185
|
+
} finally {
|
|
186
|
+
rmSync(root, { recursive: true, force: true });
|
|
187
|
+
}
|
|
188
|
+
});
|
|
189
|
+
|
|
190
|
+
/**
|
|
191
|
+
* Real production wiring for the read-side config slice: the installed runtime
|
|
192
|
+
* serves `get_config` and the bounded `get_snapshot` projection from isolated,
|
|
193
|
+
* pre-seeded stores without a second store, a watcher, or any write.
|
|
194
|
+
*/
|
|
195
|
+
test("installed Pi serves Desktop config reads from the existing stores", () => {
|
|
196
|
+
const root = isolatedRoot("desktop-rpc-config-");
|
|
197
|
+
try {
|
|
198
|
+
const configHome = join(root, "config");
|
|
199
|
+
const workspace = join(root, "workspace");
|
|
200
|
+
mkdirSync(join(workspace, ".pi", "gentle-ai"), { recursive: true });
|
|
201
|
+
writeFileSync(
|
|
202
|
+
join(configHome, "profiles.json"),
|
|
203
|
+
`${JSON.stringify({
|
|
204
|
+
kind: "gentle-pi.agent_model_profiles",
|
|
205
|
+
version: 1,
|
|
206
|
+
active: "team",
|
|
207
|
+
profiles: { team: { explore: { model: "anthropic/claude-probe" } } },
|
|
208
|
+
})}\n`,
|
|
209
|
+
);
|
|
210
|
+
const projectModels = `${JSON.stringify({ worker: { model: "openai/gpt-probe" } })}\n`;
|
|
211
|
+
writeFileSync(join(workspace, ".pi", "gentle-ai", "models.json"), projectModels);
|
|
212
|
+
|
|
213
|
+
const input = [
|
|
214
|
+
prompt("prompt-config", desktopRequest("config-1", "get_config", { store: "profiles" })),
|
|
215
|
+
prompt("prompt-models", desktopRequest("config-2", "get_config", { store: "models" })),
|
|
216
|
+
prompt("prompt-snapshot", desktopRequest("config-3", "get_snapshot")),
|
|
217
|
+
].map((value) => JSON.stringify(value)).join("\n") + "\n";
|
|
218
|
+
const child = spawnSync(process.execPath, probeArgs(root, [desktopExtension]), {
|
|
219
|
+
cwd: workspace,
|
|
220
|
+
env: probeEnvironment(root),
|
|
221
|
+
input,
|
|
222
|
+
encoding: "utf8",
|
|
223
|
+
timeout: 15000,
|
|
224
|
+
});
|
|
225
|
+
|
|
226
|
+
assert.ifError(child.error);
|
|
227
|
+
assert.equal(child.status, 0, child.stderr);
|
|
228
|
+
assert.equal(child.stderr, "");
|
|
229
|
+
const records = child.stdout.trim().split("\n").map((line) => JSON.parse(line));
|
|
230
|
+
const payloads = records
|
|
231
|
+
.filter((record) => record.type === "extension_ui_request" && record.widgetKey === DESKTOP_RPC_WIDGET)
|
|
232
|
+
.map((record) => JSON.parse(record.widgetLines[0]));
|
|
233
|
+
const byRequest = (id: string) => payloads.find((payload) => payload.requestId === id && payload.kind === "response");
|
|
234
|
+
|
|
235
|
+
const profiles = byRequest("config-1");
|
|
236
|
+
assert.equal(profiles.ok, true);
|
|
237
|
+
assert.equal(profiles.data.store, "profiles");
|
|
238
|
+
assert.equal(profiles.data.scope, "global");
|
|
239
|
+
assert.equal(profiles.data.readOnly, false);
|
|
240
|
+
assert.equal(profiles.data.status, "ok");
|
|
241
|
+
assert.equal(profiles.data.value.active, "team");
|
|
242
|
+
assert.match(profiles.data.revision, /^sha256:[a-f0-9]{32}$/);
|
|
243
|
+
|
|
244
|
+
const models = byRequest("config-2");
|
|
245
|
+
assert.equal(models.ok, true);
|
|
246
|
+
assert.equal(models.data.store, "models");
|
|
247
|
+
assert.equal(models.data.readOnly, true);
|
|
248
|
+
assert.deepEqual(models.data.value, { worker: { model: "openai/gpt-probe" } });
|
|
249
|
+
|
|
250
|
+
const snapshot = byRequest("config-3").data;
|
|
251
|
+
assert.equal(snapshot.state.config.stores.length, 6);
|
|
252
|
+
assert.deepEqual(
|
|
253
|
+
snapshot.state.config.stores.map((entry: any) => entry.store),
|
|
254
|
+
["profiles", "models", "profile_fallbacks", "subagents", "pins", "managed_assets"],
|
|
255
|
+
);
|
|
256
|
+
assert.equal(snapshot.state.config.stores[0].status, "ok");
|
|
257
|
+
assert.equal(JSON.stringify(snapshot).includes("claude-probe"), false, "snapshots stay bounded");
|
|
258
|
+
|
|
259
|
+
assert.equal(payloads.some((payload) => payload.kind === "event"), false, "a read emits nothing");
|
|
260
|
+
assert.equal(readFileSync(join(workspace, ".pi", "gentle-ai", "models.json"), "utf8"), projectModels);
|
|
261
|
+
assert.equal(existsSync(join(root, "config", "profile-fallbacks.json")), false, "no store is created by a read");
|
|
262
|
+
} finally {
|
|
263
|
+
rmSync(root, { recursive: true, force: true });
|
|
264
|
+
}
|
|
265
|
+
});
|
|
266
|
+
|
|
267
|
+
/**
|
|
268
|
+
* Real production wiring for the read-side usage slice: the installed runtime
|
|
269
|
+
* loads the actual usage owner (`extensions/gentle-shell.ts`, which owns the
|
|
270
|
+
* UsageStore / UsageSourceRegistry / refreshUsage / after_provider_response
|
|
271
|
+
* closures) plus this transport extension. `get_subscription_usage` is a read,
|
|
272
|
+
* so the probe stays fully offline and only observes truthful pending answers
|
|
273
|
+
* — it never triggers a live provider refresh.
|
|
274
|
+
*/
|
|
275
|
+
test("installed Pi serves offline subscription usage reads from the real owner", () => {
|
|
276
|
+
const root = isolatedRoot("desktop-rpc-usage-");
|
|
277
|
+
try {
|
|
278
|
+
const input = [
|
|
279
|
+
prompt("prompt-anthropic", desktopRequest("usage-1", "get_subscription_usage", { provider: "anthropic" })),
|
|
280
|
+
prompt("prompt-codex", desktopRequest("usage-2", "get_subscription_usage", { provider: "openai-codex" })),
|
|
281
|
+
prompt("prompt-all", desktopRequest("usage-3", "get_subscription_usage")),
|
|
282
|
+
].map((value) => JSON.stringify(value)).join("\n") + "\n";
|
|
283
|
+
const child = spawnSync(process.execPath, probeArgs(root, [usageOwnerExtension, desktopExtension]), {
|
|
284
|
+
cwd: join(root, "workspace"),
|
|
285
|
+
env: probeEnvironment(root),
|
|
286
|
+
input,
|
|
287
|
+
encoding: "utf8",
|
|
288
|
+
timeout: 15000,
|
|
289
|
+
});
|
|
290
|
+
|
|
291
|
+
assert.ifError(child.error);
|
|
292
|
+
assert.equal(child.status, 0, child.stderr);
|
|
293
|
+
assert.equal(child.stderr, "");
|
|
294
|
+
const records = child.stdout.trim().split("\n").map((line) => JSON.parse(line));
|
|
295
|
+
const payloads = records
|
|
296
|
+
.filter((record) => record.type === "extension_ui_request" && record.widgetKey === DESKTOP_RPC_WIDGET)
|
|
297
|
+
.map((record) => JSON.parse(record.widgetLines[0]));
|
|
298
|
+
const byRequest = (id: string) => payloads.find((payload) => payload.requestId === id && payload.kind === "response");
|
|
299
|
+
|
|
300
|
+
// Anthropic has no usage endpoint; offline it must stay pending, never a
|
|
301
|
+
// fabricated snapshot or a failed fetch.
|
|
302
|
+
const anthropic = byRequest("usage-1");
|
|
303
|
+
assert.equal(anthropic.ok, true, JSON.stringify(anthropic));
|
|
304
|
+
assert.deepEqual(anthropic.data.providers, [{ provider: "anthropic", status: "pending" }]);
|
|
305
|
+
|
|
306
|
+
const codex = byRequest("usage-2");
|
|
307
|
+
assert.equal(codex.ok, true, JSON.stringify(codex));
|
|
308
|
+
assert.deepEqual(codex.data.providers, [{ provider: "openai-codex", status: "pending" }]);
|
|
309
|
+
|
|
310
|
+
const all = byRequest("usage-3");
|
|
311
|
+
assert.equal(all.ok, true, JSON.stringify(all));
|
|
312
|
+
assert.ok(Array.isArray(all.data.providers), "an unfiltered read projects the scope providers");
|
|
313
|
+
|
|
314
|
+
assert.equal(payloads.some((payload) => payload.kind === "event"), false, "an offline read emits nothing");
|
|
315
|
+
assert.equal(JSON.stringify(payloads).includes("chatgpt.com"), false, "no endpoint leaks into the wire");
|
|
316
|
+
} finally {
|
|
317
|
+
rmSync(root, { recursive: true, force: true });
|
|
318
|
+
}
|
|
319
|
+
});
|
|
320
|
+
|
|
321
|
+
/**
|
|
322
|
+
* Real production wiring for the read-side design slice: the installed runtime
|
|
323
|
+
* loads the actual design owner (`extensions/gentle-design.ts`, which owns the
|
|
324
|
+
* single `DesignCanvas` from `createDesignCanvas` plus `listDesigns`) alongside
|
|
325
|
+
* this transport extension. `get_design_canvas` is a read, so the probe stays
|
|
326
|
+
* fully offline and observes the truthful owner-loaded stopped state — it never
|
|
327
|
+
* starts a canvas server or opens a browser.
|
|
328
|
+
*/
|
|
329
|
+
test("installed Pi serves the owner-loaded stopped design canvas without starting a server", () => {
|
|
330
|
+
const root = isolatedRoot("desktop-rpc-design-");
|
|
331
|
+
try {
|
|
332
|
+
const input = [
|
|
333
|
+
prompt("prompt-canvas", desktopRequest("design-1", "get_design_canvas")),
|
|
334
|
+
prompt("prompt-url", desktopRequest("design-2", "get_design_canvas", { includeUrl: true })),
|
|
335
|
+
].map((value) => JSON.stringify(value)).join("\n") + "\n";
|
|
336
|
+
const child = spawnSync(process.execPath, probeArgs(root, [designOwnerExtension, desktopExtension]), {
|
|
337
|
+
cwd: join(root, "workspace"),
|
|
338
|
+
env: probeEnvironment(root),
|
|
339
|
+
input,
|
|
340
|
+
encoding: "utf8",
|
|
341
|
+
timeout: 15000,
|
|
342
|
+
});
|
|
343
|
+
|
|
344
|
+
assert.ifError(child.error);
|
|
345
|
+
assert.equal(child.status, 0, child.stderr);
|
|
346
|
+
assert.equal(child.stderr, "");
|
|
347
|
+
const records = child.stdout.trim().split("\n").map((line) => JSON.parse(line));
|
|
348
|
+
const payloads = records
|
|
349
|
+
.filter((record) => record.type === "extension_ui_request" && record.widgetKey === DESKTOP_RPC_WIDGET)
|
|
350
|
+
.map((record) => JSON.parse(record.widgetLines[0]));
|
|
351
|
+
const byRequest = (id: string) => payloads.find((payload) => payload.requestId === id && payload.kind === "response");
|
|
352
|
+
|
|
353
|
+
const canvas = byRequest("design-1");
|
|
354
|
+
assert.equal(canvas.ok, true, JSON.stringify(canvas));
|
|
355
|
+
assert.deepEqual(canvas.data, { running: false, slug: null, connectedClients: 0, designs: [] });
|
|
356
|
+
assert.equal("url" in canvas.data, false, "the tokenized URL is never a default field");
|
|
357
|
+
|
|
358
|
+
// Even an explicit includeUrl cannot invent a URL for a canvas that is not
|
|
359
|
+
// running; the capability simply stays absent.
|
|
360
|
+
const withUrl = byRequest("design-2");
|
|
361
|
+
assert.equal(withUrl.ok, true, JSON.stringify(withUrl));
|
|
362
|
+
assert.equal("url" in withUrl.data, false, "a stopped canvas has no URL to include");
|
|
363
|
+
|
|
364
|
+
assert.equal(payloads.some((payload) => payload.kind === "event"), false, "an offline read emits nothing");
|
|
365
|
+
assert.equal(JSON.stringify(payloads).includes("/tok/"), false, "no tokenized URL leaks into the wire");
|
|
366
|
+
} finally {
|
|
367
|
+
rmSync(root, { recursive: true, force: true });
|
|
368
|
+
}
|
|
369
|
+
});
|
|
370
|
+
|
|
371
|
+
/**
|
|
372
|
+
* Real production wiring for the jobs slice: the installed runtime loads the
|
|
373
|
+
* actual jobs owner (`extensions/gentle-agents.ts`, which owns the single
|
|
374
|
+
* parent-session `JobRegistry` plus the parent `MonitorController`) alongside
|
|
375
|
+
* this transport extension. `list_jobs` is a read, so the probe stays offline
|
|
376
|
+
* and observes the truthful owner-loaded empty list — it never starts a job.
|
|
377
|
+
*/
|
|
378
|
+
test("installed Pi serves the owner-loaded empty job list without starting a job", () => {
|
|
379
|
+
const root = isolatedRoot("desktop-rpc-jobs-");
|
|
380
|
+
try {
|
|
381
|
+
const input = [
|
|
382
|
+
prompt("prompt-list", desktopRequest("jobs-1", "list_jobs")),
|
|
383
|
+
].map((value) => JSON.stringify(value)).join("\n") + "\n";
|
|
384
|
+
const child = spawnSync(process.execPath, probeArgs(root, [jobsOwnerExtension, desktopExtension]), {
|
|
385
|
+
cwd: join(root, "workspace"),
|
|
386
|
+
env: probeEnvironment(root),
|
|
387
|
+
input,
|
|
388
|
+
encoding: "utf8",
|
|
389
|
+
timeout: 20000,
|
|
390
|
+
});
|
|
391
|
+
|
|
392
|
+
assert.ifError(child.error);
|
|
393
|
+
assert.equal(child.status, 0, child.stderr);
|
|
394
|
+
assert.equal(child.stderr, "");
|
|
395
|
+
const records = child.stdout.trim().split("\n").map((line) => JSON.parse(line));
|
|
396
|
+
const payloads = records
|
|
397
|
+
.filter((record) => record.type === "extension_ui_request" && record.widgetKey === DESKTOP_RPC_WIDGET)
|
|
398
|
+
.map((record) => JSON.parse(record.widgetLines[0]));
|
|
399
|
+
const byRequest = (id: string) => payloads.find((payload) => payload.requestId === id && payload.kind === "response");
|
|
400
|
+
|
|
401
|
+
const list = byRequest("jobs-1");
|
|
402
|
+
assert.equal(list.ok, true, JSON.stringify(list));
|
|
403
|
+
assert.deepEqual(list.data, { jobs: [] }, "no jobs exist, so the list is empty rather than fabricated");
|
|
404
|
+
|
|
405
|
+
assert.equal(payloads.some((payload) => payload.kind === "event"), false, "an offline list emits nothing");
|
|
406
|
+
assert.equal(JSON.stringify(payloads).includes("command"), false, "no command text leaks into the wire");
|
|
407
|
+
assert.equal(JSON.stringify(payloads).includes("outputPath"), false, "no output path leaks into the wire");
|
|
408
|
+
} finally {
|
|
409
|
+
rmSync(root, { recursive: true, force: true });
|
|
410
|
+
}
|
|
411
|
+
});
|
|
412
|
+
|
|
413
|
+
/**
|
|
414
|
+
* Real production wiring for the subagents slice: the installed runtime loads
|
|
415
|
+
* the actual agents owner (`extensions/gentle-agents.ts`, which owns the single
|
|
416
|
+
* parent-session `TaskStore` plus the parent `AgentRunner`) alongside this
|
|
417
|
+
* transport extension. `list_subagents` is a read, so the probe stays offline
|
|
418
|
+
* and observes the truthful owner-loaded empty list — it never starts a child.
|
|
419
|
+
*/
|
|
420
|
+
test("installed Pi serves the owner-loaded empty subagent list without starting a child", () => {
|
|
421
|
+
const root = isolatedRoot("desktop-rpc-agents-");
|
|
422
|
+
try {
|
|
423
|
+
const input = [
|
|
424
|
+
prompt("prompt-list", desktopRequest("agents-1", "list_subagents")),
|
|
425
|
+
].map((value) => JSON.stringify(value)).join("\n") + "\n";
|
|
426
|
+
const child = spawnSync(process.execPath, probeArgs(root, [jobsOwnerExtension, desktopExtension]), {
|
|
427
|
+
cwd: join(root, "workspace"),
|
|
428
|
+
env: probeEnvironment(root),
|
|
429
|
+
input,
|
|
430
|
+
encoding: "utf8",
|
|
431
|
+
timeout: 20000,
|
|
432
|
+
});
|
|
433
|
+
|
|
434
|
+
assert.ifError(child.error);
|
|
435
|
+
assert.equal(child.status, 0, child.stderr);
|
|
436
|
+
assert.equal(child.stderr, "");
|
|
437
|
+
const records = child.stdout.trim().split("\n").map((line) => JSON.parse(line));
|
|
438
|
+
const payloads = records
|
|
439
|
+
.filter((record) => record.type === "extension_ui_request" && record.widgetKey === DESKTOP_RPC_WIDGET)
|
|
440
|
+
.map((record) => JSON.parse(record.widgetLines[0]));
|
|
441
|
+
const byRequest = (id: string) => payloads.find((payload) => payload.requestId === id && payload.kind === "response");
|
|
442
|
+
|
|
443
|
+
const list = byRequest("agents-1");
|
|
444
|
+
assert.equal(list.ok, true, JSON.stringify(list));
|
|
445
|
+
assert.deepEqual(list.data, { agents: [] }, "no subagents exist, so the list is empty rather than fabricated");
|
|
446
|
+
|
|
447
|
+
assert.equal(payloads.some((payload) => payload.kind === "event"), false, "an offline list emits nothing");
|
|
448
|
+
assert.equal(JSON.stringify(payloads).includes("prompt"), false, "no prompt text leaks into the wire");
|
|
449
|
+
assert.equal(JSON.stringify(payloads).includes("sessionPath"), false, "no session path leaks into the wire");
|
|
450
|
+
assert.equal(JSON.stringify(payloads).includes("cwd"), false, "no working directory leaks into the wire");
|
|
451
|
+
} finally {
|
|
452
|
+
rmSync(root, { recursive: true, force: true });
|
|
453
|
+
}
|
|
454
|
+
});
|
|
455
|
+
|
|
456
|
+
/**
|
|
457
|
+
* Real production wiring for the write slice: the installed runtime serves a
|
|
458
|
+
* `set_config` round trip through the existing `profiles.json` owner, writes the
|
|
459
|
+
* isolated file atomically, emits exactly one ordered `config_changed`, and adds
|
|
460
|
+
* no conversation message. Nothing here reimplements the store owner.
|
|
461
|
+
*/
|
|
462
|
+
test("installed Pi applies a Desktop config write through the existing store owner", async () => {
|
|
463
|
+
const root = isolatedRoot("desktop-rpc-config-write-");
|
|
464
|
+
const probe = new LiveProbe(root, [desktopExtension]);
|
|
465
|
+
try {
|
|
466
|
+
const configHome = join(root, "config");
|
|
467
|
+
const path = join(configHome, "profiles.json");
|
|
468
|
+
writeFileSync(
|
|
469
|
+
path,
|
|
470
|
+
`${JSON.stringify({
|
|
471
|
+
kind: "gentle-pi.agent_model_profiles",
|
|
472
|
+
version: 1,
|
|
473
|
+
active: "team",
|
|
474
|
+
profiles: { team: { explore: { model: "anthropic/claude-probe" } } },
|
|
475
|
+
})}\n`,
|
|
476
|
+
);
|
|
477
|
+
const responseFor = (requestId: string) => probe.waitFor(
|
|
478
|
+
(record) => record.type === "extension_ui_request" && record.widgetKey === DESKTOP_RPC_WIDGET &&
|
|
479
|
+
JSON.parse(record.widgetLines[0]).kind === "response" &&
|
|
480
|
+
JSON.parse(record.widgetLines[0]).requestId === requestId,
|
|
481
|
+
`response ${requestId}`,
|
|
482
|
+
).then((record) => JSON.parse(record.widgetLines[0]));
|
|
483
|
+
|
|
484
|
+
probe.send(prompt("prompt-read", desktopRequest("read-1", "get_config", { store: "profiles" })));
|
|
485
|
+
const before = await responseFor("read-1");
|
|
486
|
+
assert.equal(before.ok, true, JSON.stringify(before));
|
|
487
|
+
const writeTarget = before.data.writeTargets.find((entry: any) => entry.target === "global");
|
|
488
|
+
assert.equal(writeTarget.status, "ok");
|
|
489
|
+
const previousBytes = readFileSync(path, "utf8");
|
|
490
|
+
|
|
491
|
+
const data = {
|
|
492
|
+
kind: "gentle-pi.agent_model_profiles",
|
|
493
|
+
version: 1,
|
|
494
|
+
active: "team",
|
|
495
|
+
profiles: {
|
|
496
|
+
team: { explore: { model: "anthropic/claude-probe" } },
|
|
497
|
+
ops: { worker: { model: "openai/gpt-probe-write", thinking: "high" } },
|
|
498
|
+
},
|
|
499
|
+
};
|
|
500
|
+
probe.send(prompt("prompt-write", desktopRequest("write-1", "set_config", {
|
|
501
|
+
store: "profiles",
|
|
502
|
+
data,
|
|
503
|
+
expectedRevision: writeTarget.writeRevision,
|
|
504
|
+
})));
|
|
505
|
+
const written = await responseFor("write-1");
|
|
506
|
+
assert.equal(written.ok, true, JSON.stringify(written));
|
|
507
|
+
assert.equal(written.data.changed, true);
|
|
508
|
+
assert.equal(written.data.writeTarget, "global");
|
|
509
|
+
assert.equal(written.data.readOnly, false);
|
|
510
|
+
assert.deepEqual(Object.keys(written.data.value.profiles).sort(), ["ops", "team"]);
|
|
511
|
+
|
|
512
|
+
const event = await probe.waitFor(
|
|
513
|
+
(record) => record.type === "extension_ui_request" && record.widgetKey === DESKTOP_RPC_WIDGET &&
|
|
514
|
+
JSON.parse(record.widgetLines[0]).event === "config_changed",
|
|
515
|
+
"config_changed event",
|
|
516
|
+
).then((record) => JSON.parse(record.widgetLines[0]));
|
|
517
|
+
assert.equal(event.seq, 1);
|
|
518
|
+
assert.deepEqual(event.data, {
|
|
519
|
+
store: "profiles",
|
|
520
|
+
scope: "global",
|
|
521
|
+
writeTarget: "global",
|
|
522
|
+
revision: written.data.revision,
|
|
523
|
+
writeRevision: written.data.writeRevision,
|
|
524
|
+
source: "desktop",
|
|
525
|
+
});
|
|
526
|
+
|
|
527
|
+
probe.send(prompt("prompt-read-2", desktopRequest("read-2", "get_config", { store: "profiles" })));
|
|
528
|
+
const after = await responseFor("read-2");
|
|
529
|
+
assert.equal(after.ok, true, JSON.stringify(after));
|
|
530
|
+
assert.deepEqual(Object.keys(after.data.value.profiles).sort(), ["ops", "team"]);
|
|
531
|
+
assert.notEqual(after.data.revision, before.data.revision);
|
|
532
|
+
|
|
533
|
+
probe.send({ id: "messages-1", type: "get_messages" });
|
|
534
|
+
const messages = await probe.waitFor((record) => record.id === "messages-1", "get_messages response");
|
|
535
|
+
assert.deepEqual(messages.data, { messages: [] }, "control traffic never reaches the conversation");
|
|
536
|
+
|
|
537
|
+
for (const id of ["prompt-read", "prompt-write", "prompt-read-2"]) {
|
|
538
|
+
assert.deepEqual(
|
|
539
|
+
await probe.waitFor((record) => record.id === id, `prompt response ${id}`),
|
|
540
|
+
{ id, type: "response", command: "prompt", success: true, data: { disposition: "handled" } },
|
|
541
|
+
);
|
|
542
|
+
}
|
|
543
|
+
|
|
544
|
+
const onDisk = readFileSync(path, "utf8");
|
|
545
|
+
assert.notEqual(onDisk, previousBytes, "the isolated store really changed on disk");
|
|
546
|
+
assert.equal(onDisk, serializeProfilesFile(normalizeProfilesFile(data)!.file), "the owner serialization is the disk content");
|
|
547
|
+
assert.deepEqual(JSON.parse(onDisk).profiles.ops, { worker: { model: "openai/gpt-probe-write", thinking: "high" } });
|
|
548
|
+
assert.equal(existsSync(join(configHome, "profile-fallbacks.json")), false, "no other store is created");
|
|
549
|
+
|
|
550
|
+
assert.deepEqual(
|
|
551
|
+
probe.desktopPayloads().map((payload) => `${payload.kind}:${payload.requestId ?? payload.event}`),
|
|
552
|
+
["response:read-1", "response:write-1", "event:config_changed", "response:read-2"],
|
|
553
|
+
"one ordered event follows its response and nothing else is emitted",
|
|
554
|
+
);
|
|
555
|
+
|
|
556
|
+
const closed = await probe.close();
|
|
557
|
+
assert.equal(closed.status, 0, closed.stderr);
|
|
558
|
+
assert.equal(closed.stderr, "");
|
|
559
|
+
} finally {
|
|
560
|
+
probe.kill();
|
|
561
|
+
rmSync(root, { recursive: true, force: true });
|
|
562
|
+
}
|
|
563
|
+
});
|
|
564
|
+
|
|
565
|
+
/**
|
|
566
|
+
* Real production wiring: the installed Pi runtime loads the actual owner
|
|
567
|
+
* extension (`extensions/gentle-ai.ts`, which registers the
|
|
568
|
+
* YoloSessionController) plus this transport extension. Nothing here
|
|
569
|
+
* reimplements the owner. Requests are sent one at a time because Pi's RPC
|
|
570
|
+
* loop dispatches prompts concurrently.
|
|
571
|
+
*/
|
|
572
|
+
test("installed Pi applies a Desktop permission change through the real owner without a restart", async () => {
|
|
573
|
+
const root = isolatedRoot("desktop-rpc-owner-");
|
|
574
|
+
const probe = new LiveProbe(root, [ownerExtension, desktopExtension]);
|
|
575
|
+
try {
|
|
576
|
+
const responseFor = (requestId: string) => probe.waitFor(
|
|
577
|
+
(record) => record.type === "extension_ui_request" && record.widgetKey === DESKTOP_RPC_WIDGET &&
|
|
578
|
+
JSON.parse(record.widgetLines[0]).kind === "response" &&
|
|
579
|
+
JSON.parse(record.widgetLines[0]).requestId === requestId,
|
|
580
|
+
`response ${requestId}`,
|
|
581
|
+
).then((record) => JSON.parse(record.widgetLines[0]));
|
|
582
|
+
|
|
583
|
+
probe.send(prompt("prompt-read-1", desktopRequest("read-1", "get_permission_mode")));
|
|
584
|
+
const before = await responseFor("read-1");
|
|
585
|
+
assert.deepEqual(before.data, { mode: "normal", default_mode: "normal" });
|
|
586
|
+
|
|
587
|
+
probe.send(prompt("prompt-set", desktopRequest("set-1", "set_permission_mode", { mode: "auto", persist: false })));
|
|
588
|
+
const set = await responseFor("set-1");
|
|
589
|
+
assert.deepEqual(set.data, { mode: "auto", default_mode: "normal", persisted: false, changed: true });
|
|
590
|
+
const event = await probe.waitFor(
|
|
591
|
+
(record) => record.type === "extension_ui_request" && record.widgetKey === DESKTOP_RPC_WIDGET &&
|
|
592
|
+
JSON.parse(record.widgetLines[0]).event === "permission_mode_changed",
|
|
593
|
+
"permission_mode_changed event",
|
|
594
|
+
).then((record) => JSON.parse(record.widgetLines[0]));
|
|
595
|
+
assert.equal(event.seq, 1);
|
|
596
|
+
assert.deepEqual(event.data, {
|
|
597
|
+
mode: "auto",
|
|
598
|
+
previous_mode: "normal",
|
|
599
|
+
default_mode: "normal",
|
|
600
|
+
persisted: false,
|
|
601
|
+
source: "desktop",
|
|
602
|
+
});
|
|
603
|
+
|
|
604
|
+
probe.send(prompt("prompt-read-2", desktopRequest("read-2", "get_permission_mode")));
|
|
605
|
+
const after = await responseFor("read-2");
|
|
606
|
+
assert.deepEqual(after.data, { mode: "auto", default_mode: "normal" }, "the same process reads the applied mode");
|
|
607
|
+
|
|
608
|
+
probe.send({ id: "messages-1", type: "get_messages" });
|
|
609
|
+
const messages = await probe.waitFor((record) => record.id === "messages-1", "get_messages response");
|
|
610
|
+
assert.deepEqual(messages.data, { messages: [] }, "control traffic never reaches the conversation");
|
|
611
|
+
|
|
612
|
+
for (const id of ["prompt-read-1", "prompt-set", "prompt-read-2"]) {
|
|
613
|
+
assert.deepEqual(
|
|
614
|
+
await probe.waitFor((record) => record.id === id, `prompt response ${id}`),
|
|
615
|
+
{ id, type: "response", command: "prompt", success: true, data: { disposition: "handled" } },
|
|
616
|
+
);
|
|
617
|
+
}
|
|
618
|
+
assert.deepEqual(
|
|
619
|
+
probe.desktopPayloads().map((payload) => `${payload.kind}:${payload.requestId ?? payload.event}`),
|
|
620
|
+
["response:read-1", "response:set-1", "event:permission_mode_changed", "response:read-2"],
|
|
621
|
+
"one ordered event follows its response and nothing else is emitted",
|
|
622
|
+
);
|
|
623
|
+
assert.equal(existsSync(join(root, "config", "permission-mode.json")), false, "persist:false never writes the default");
|
|
624
|
+
|
|
625
|
+
const closed = await probe.close();
|
|
626
|
+
assert.equal(closed.status, 0, closed.stderr);
|
|
627
|
+
assert.equal(closed.stderr, "");
|
|
628
|
+
} finally {
|
|
629
|
+
probe.kill();
|
|
630
|
+
rmSync(root, { recursive: true, force: true });
|
|
631
|
+
}
|
|
632
|
+
});
|