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,311 @@
|
|
|
1
|
+
import assert from "node:assert/strict";
|
|
2
|
+
import { existsSync, mkdirSync, mkdtempSync, readFileSync, rmSync, statSync, 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, ExtensionContext } from "@earendil-works/pi-coding-agent";
|
|
7
|
+
import desktopRpc from "../extensions/gentle-desktop-rpc.ts";
|
|
8
|
+
import { DESKTOP_RPC_SCHEMA, DESKTOP_RPC_WIDGET } from "../lib/desktop-rpc.ts";
|
|
9
|
+
import { PERMISSION_MODE_SCHEMA, permissionModePolicyFile, writePermissionModePolicy } from "../lib/permission-mode-policy.ts";
|
|
10
|
+
import { INTERACTIVE_HOST_ENV } from "../lib/rpc-host.ts";
|
|
11
|
+
import { registerYoloSessionPolicy } from "../lib/yolo-session-policy.ts";
|
|
12
|
+
|
|
13
|
+
type WidgetCall = { key: string; lines: string[] };
|
|
14
|
+
|
|
15
|
+
function isolatedEnvironment(t: test.TestContext) {
|
|
16
|
+
const root = mkdtempSync(join(tmpdir(), "gentle-desktop-permissions-"));
|
|
17
|
+
const home = join(root, "config");
|
|
18
|
+
const workspace = join(root, "workspace");
|
|
19
|
+
mkdirSync(home);
|
|
20
|
+
mkdirSync(workspace);
|
|
21
|
+
const previous = {
|
|
22
|
+
host: process.env[INTERACTIVE_HOST_ENV],
|
|
23
|
+
configHome: process.env.GENTLE_PI_CONFIG_HOME,
|
|
24
|
+
child: process.env.GENTLE_PI_AGENTS_CHILD,
|
|
25
|
+
};
|
|
26
|
+
process.env[INTERACTIVE_HOST_ENV] = "1";
|
|
27
|
+
process.env.GENTLE_PI_CONFIG_HOME = home;
|
|
28
|
+
delete process.env.GENTLE_PI_AGENTS_CHILD;
|
|
29
|
+
t.after(() => {
|
|
30
|
+
if (previous.host === undefined) delete process.env[INTERACTIVE_HOST_ENV];
|
|
31
|
+
else process.env[INTERACTIVE_HOST_ENV] = previous.host;
|
|
32
|
+
if (previous.configHome === undefined) delete process.env.GENTLE_PI_CONFIG_HOME;
|
|
33
|
+
else process.env.GENTLE_PI_CONFIG_HOME = previous.configHome;
|
|
34
|
+
if (previous.child === undefined) delete process.env.GENTLE_PI_AGENTS_CHILD;
|
|
35
|
+
else process.env.GENTLE_PI_AGENTS_CHILD = previous.child;
|
|
36
|
+
rmSync(root, { recursive: true, force: true });
|
|
37
|
+
});
|
|
38
|
+
return { root, home, workspace, policyFile: permissionModePolicyFile({ gentlePiConfigHome: home }) };
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
function desktopHost(t: test.TestContext, options: { owner?: boolean } = {}) {
|
|
42
|
+
const dirs = isolatedEnvironment(t);
|
|
43
|
+
const commands = new Map<string, { handler: (args: string, ctx: ExtensionContext) => Promise<void> }>();
|
|
44
|
+
const lifecycle = new Map<string, (event: unknown, ctx: ExtensionContext) => unknown>();
|
|
45
|
+
const hostUi = new Map<string, (value: unknown) => void>();
|
|
46
|
+
const tools: string[] = [];
|
|
47
|
+
const pi = {
|
|
48
|
+
registerCommand(name: string, command: { handler: (args: string, ctx: ExtensionContext) => Promise<void> }) {
|
|
49
|
+
commands.set(name, command);
|
|
50
|
+
},
|
|
51
|
+
on(name: string, handler: (event: unknown, ctx: ExtensionContext) => unknown) { lifecycle.set(name, handler); },
|
|
52
|
+
registerTool(tool: { name: string }) { tools.push(tool.name); },
|
|
53
|
+
events: {
|
|
54
|
+
on(name: string, handler: (value: unknown) => void) { hostUi.set(name, handler); },
|
|
55
|
+
emit(name: string, value: unknown) { hostUi.get(name)?.(value); },
|
|
56
|
+
},
|
|
57
|
+
} as unknown as ExtensionAPI;
|
|
58
|
+
const owner = options.owner === false
|
|
59
|
+
? undefined
|
|
60
|
+
: registerYoloSessionPolicy(pi, process.env, { resolveIdentity: async () => "workspace:test" });
|
|
61
|
+
desktopRpc(pi);
|
|
62
|
+
const widgets: WidgetCall[] = [];
|
|
63
|
+
const notices: string[] = [];
|
|
64
|
+
const statuses = new Map<string, string | undefined>();
|
|
65
|
+
const session = { id: "session-1" };
|
|
66
|
+
const ctx = {
|
|
67
|
+
mode: "rpc",
|
|
68
|
+
hasUI: true,
|
|
69
|
+
cwd: dirs.workspace,
|
|
70
|
+
sessionManager: { getSessionId: () => session.id },
|
|
71
|
+
ui: {
|
|
72
|
+
setWidget(key: string, lines: string[]) { if (key === DESKTOP_RPC_WIDGET) widgets.push({ key, lines }); },
|
|
73
|
+
setStatus(key: string, value?: string) { statuses.set(key, value); },
|
|
74
|
+
notify(message: string) { notices.push(message); },
|
|
75
|
+
select: async () => undefined,
|
|
76
|
+
getAllThemes: () => [],
|
|
77
|
+
},
|
|
78
|
+
} as unknown as ExtensionContext;
|
|
79
|
+
return {
|
|
80
|
+
...dirs,
|
|
81
|
+
owner,
|
|
82
|
+
pi,
|
|
83
|
+
tools,
|
|
84
|
+
ctx,
|
|
85
|
+
widgets,
|
|
86
|
+
notices,
|
|
87
|
+
statuses,
|
|
88
|
+
session,
|
|
89
|
+
start() { lifecycle.get("session_start")?.({}, ctx); },
|
|
90
|
+
shutdown() { lifecycle.get("session_shutdown")?.({}, ctx); },
|
|
91
|
+
async invoke(method: string, params: Record<string, unknown> = {}, requestId = `request-${method}`) {
|
|
92
|
+
assert.deepEqual([...commands.keys()].includes("gentle:desktop"), true);
|
|
93
|
+
await commands.get("gentle:desktop")!.handler(
|
|
94
|
+
JSON.stringify({ schema: DESKTOP_RPC_SCHEMA, requestId, method, params }),
|
|
95
|
+
ctx,
|
|
96
|
+
);
|
|
97
|
+
},
|
|
98
|
+
lines() { return widgets.map((call) => JSON.parse(call.lines[0]!)); },
|
|
99
|
+
};
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
const eventOf = (line: any) => line.kind === "event";
|
|
103
|
+
|
|
104
|
+
test("capabilities advertise the wired permission domain and no agent tool", async (t) => {
|
|
105
|
+
const app = desktopHost(t);
|
|
106
|
+
app.start();
|
|
107
|
+
await app.invoke("capabilities");
|
|
108
|
+
const [response] = app.lines();
|
|
109
|
+
assert.deepEqual(response.data.methods, [
|
|
110
|
+
"capabilities",
|
|
111
|
+
"get_snapshot",
|
|
112
|
+
"get_config",
|
|
113
|
+
"set_config",
|
|
114
|
+
"get_permission_mode",
|
|
115
|
+
"set_permission_mode",
|
|
116
|
+
"get_subscription_usage",
|
|
117
|
+
"refresh_subscription_usage",
|
|
118
|
+
"get_design_canvas",
|
|
119
|
+
"list_jobs",
|
|
120
|
+
"cancel_job",
|
|
121
|
+
"apply_profile",
|
|
122
|
+
"list_subagents",
|
|
123
|
+
"cancel_subagent",
|
|
124
|
+
]);
|
|
125
|
+
assert.deepEqual(response.data.events, ["config_changed", "permission_mode_changed", "rate_limit", "design_canvas", "jobs_update", "profile_applied", "agents_update"]);
|
|
126
|
+
assert.deepEqual(app.tools, [], "the control surface is never an agent-callable tool");
|
|
127
|
+
});
|
|
128
|
+
|
|
129
|
+
test("get_permission_mode reports the live owner state and never persists a default", async (t) => {
|
|
130
|
+
const app = desktopHost(t);
|
|
131
|
+
app.start();
|
|
132
|
+
await app.invoke("get_permission_mode");
|
|
133
|
+
const lines = app.lines();
|
|
134
|
+
assert.equal(lines.length, 1, "a read never emits an event");
|
|
135
|
+
assert.deepEqual(lines[0], {
|
|
136
|
+
schema: DESKTOP_RPC_SCHEMA,
|
|
137
|
+
kind: "response",
|
|
138
|
+
requestId: "request-get_permission_mode",
|
|
139
|
+
ok: true,
|
|
140
|
+
data: { mode: "normal", default_mode: "normal" },
|
|
141
|
+
});
|
|
142
|
+
assert.equal(await app.owner!.mode(app.ctx), "normal");
|
|
143
|
+
assert.equal(existsSync(app.policyFile), false, "a read never writes the default store");
|
|
144
|
+
|
|
145
|
+
// The owner initializes a session lazily, so this first call pinned the session
|
|
146
|
+
// to the default in effect then; a later default change belongs to new sessions.
|
|
147
|
+
writePermissionModePolicy("auto", { gentlePiConfigHome: app.home });
|
|
148
|
+
await app.invoke("get_permission_mode", {}, "request-read-2");
|
|
149
|
+
assert.deepEqual(app.lines().at(-1).data, { mode: "normal", default_mode: "auto" });
|
|
150
|
+
assert.equal(app.lines().filter((line) => line.kind === "event").length, 0, "reads never emit events");
|
|
151
|
+
});
|
|
152
|
+
|
|
153
|
+
test("set_permission_mode applies every mode immediately with one ordered event", async (t) => {
|
|
154
|
+
const app = desktopHost(t);
|
|
155
|
+
app.start();
|
|
156
|
+
const order = ["auto", "yolo", "super-yolo", "normal"] as const;
|
|
157
|
+
const previous = ["normal", "auto", "yolo", "super-yolo"];
|
|
158
|
+
for (const [index, mode] of order.entries()) {
|
|
159
|
+
await app.invoke("set_permission_mode", { mode }, `set-${mode}`);
|
|
160
|
+
const lines = app.lines();
|
|
161
|
+
const response = lines.at(-2);
|
|
162
|
+
const event = lines.at(-1);
|
|
163
|
+
assert.equal(response.requestId, `set-${mode}`);
|
|
164
|
+
assert.deepEqual(response.data, { mode, default_mode: "normal", persisted: false, changed: true });
|
|
165
|
+
assert.equal(eventOf(event), true, `${mode}: the event follows its response`);
|
|
166
|
+
assert.equal(event.event, "permission_mode_changed");
|
|
167
|
+
assert.equal(event.seq, index + 1);
|
|
168
|
+
assert.deepEqual(event.data, {
|
|
169
|
+
mode,
|
|
170
|
+
previous_mode: previous[index],
|
|
171
|
+
default_mode: "normal",
|
|
172
|
+
persisted: false,
|
|
173
|
+
source: "desktop",
|
|
174
|
+
});
|
|
175
|
+
assert.equal(await app.owner!.mode(app.ctx), mode, `${mode}: applied without a restart`);
|
|
176
|
+
}
|
|
177
|
+
await app.invoke("get_snapshot");
|
|
178
|
+
assert.equal(app.lines().at(-1).data.sequence, order.length);
|
|
179
|
+
assert.equal(existsSync(app.policyFile), false, "session changes never persist by accident");
|
|
180
|
+
});
|
|
181
|
+
|
|
182
|
+
test("set_permission_mode persists the default only when explicitly requested", async (t) => {
|
|
183
|
+
const app = desktopHost(t);
|
|
184
|
+
app.start();
|
|
185
|
+
await app.invoke("set_permission_mode", { mode: "yolo" });
|
|
186
|
+
assert.equal(existsSync(app.policyFile), false);
|
|
187
|
+
assert.deepEqual(app.lines().at(-2).data, { mode: "yolo", default_mode: "normal", persisted: false, changed: true });
|
|
188
|
+
|
|
189
|
+
await app.invoke("set_permission_mode", { mode: "auto", persist: true });
|
|
190
|
+
assert.equal(readFileSync(app.policyFile, "utf8"), `${JSON.stringify({ schema: PERMISSION_MODE_SCHEMA, mode: "auto" })}\n`);
|
|
191
|
+
assert.equal(statSync(app.policyFile).mode & 0o777, 0o600);
|
|
192
|
+
assert.deepEqual(app.lines().at(-2).data, { mode: "auto", default_mode: "auto", persisted: true, changed: true });
|
|
193
|
+
assert.deepEqual(app.lines().at(-1).data, {
|
|
194
|
+
mode: "auto",
|
|
195
|
+
previous_mode: "yolo",
|
|
196
|
+
default_mode: "auto",
|
|
197
|
+
persisted: true,
|
|
198
|
+
source: "desktop",
|
|
199
|
+
});
|
|
200
|
+
|
|
201
|
+
await app.invoke("set_permission_mode", { mode: "yolo", persist: false });
|
|
202
|
+
assert.match(readFileSync(app.policyFile, "utf8"), /"mode":"auto"/);
|
|
203
|
+
assert.deepEqual(app.lines().at(-2).data, { mode: "yolo", default_mode: "auto", persisted: false, changed: true });
|
|
204
|
+
});
|
|
205
|
+
|
|
206
|
+
test("invalid params and unknown modes are typed rejections without events", async (t) => {
|
|
207
|
+
const app = desktopHost(t);
|
|
208
|
+
app.start();
|
|
209
|
+
const cases: Array<[Record<string, unknown>, string]> = [
|
|
210
|
+
[{ mode: "turbo" }, "Unknown permission mode"],
|
|
211
|
+
[{}, "Invalid permission mode parameters"],
|
|
212
|
+
[{ mode: 7 }, "Invalid permission mode parameters"],
|
|
213
|
+
[{ mode: "auto", persist: "yes" }, "Invalid permission mode parameters"],
|
|
214
|
+
[{ mode: "auto", unexpected: true }, "Invalid permission mode parameters"],
|
|
215
|
+
];
|
|
216
|
+
for (const [params, message] of cases) {
|
|
217
|
+
await app.invoke("set_permission_mode", params, "invalid");
|
|
218
|
+
const lines = app.lines();
|
|
219
|
+
assert.equal(lines.at(-1).requestId, "invalid");
|
|
220
|
+
assert.deepEqual(lines.at(-1).error, { code: "invalid_request", message });
|
|
221
|
+
assert.equal(lines.filter(eventOf).length, 0, "rejections never emit events");
|
|
222
|
+
}
|
|
223
|
+
await app.invoke("get_snapshot");
|
|
224
|
+
assert.equal(app.lines().at(-1).data.sequence, 0);
|
|
225
|
+
assert.equal(await app.owner!.mode(app.ctx), "normal");
|
|
226
|
+
assert.equal(existsSync(app.policyFile), false);
|
|
227
|
+
|
|
228
|
+
await app.invoke("get_permission_mode", { mode: "auto" }, "invalid-read");
|
|
229
|
+
assert.deepEqual(app.lines().at(-1).error, { code: "invalid_request", message: "Invalid permission mode parameters" });
|
|
230
|
+
assert.equal(app.lines().filter(eventOf).length, 0);
|
|
231
|
+
});
|
|
232
|
+
|
|
233
|
+
test("repeating the current mode is a no-op with actual state and no event", async (t) => {
|
|
234
|
+
const app = desktopHost(t);
|
|
235
|
+
app.start();
|
|
236
|
+
await app.invoke("set_permission_mode", { mode: "normal" });
|
|
237
|
+
const lines = app.lines();
|
|
238
|
+
assert.equal(lines.length, 1);
|
|
239
|
+
assert.deepEqual(lines[0].data, { mode: "normal", default_mode: "normal", persisted: false, changed: false });
|
|
240
|
+
assert.equal(lines.filter(eventOf).length, 0);
|
|
241
|
+
await app.invoke("get_snapshot");
|
|
242
|
+
assert.equal(app.lines().at(-1).data.sequence, 0);
|
|
243
|
+
});
|
|
244
|
+
|
|
245
|
+
test("owner absence and stale sessions map to safe typed errors", async (t) => {
|
|
246
|
+
const absent = desktopHost(t, { owner: false });
|
|
247
|
+
absent.start();
|
|
248
|
+
await absent.invoke("get_permission_mode");
|
|
249
|
+
await absent.invoke("set_permission_mode", { mode: "yolo" });
|
|
250
|
+
const lines = absent.lines();
|
|
251
|
+
assert.equal(lines.length, 2);
|
|
252
|
+
for (const line of lines) {
|
|
253
|
+
assert.deepEqual(line.error, {
|
|
254
|
+
code: "permission_unavailable",
|
|
255
|
+
message: "Permission owner unavailable for this session",
|
|
256
|
+
});
|
|
257
|
+
}
|
|
258
|
+
assert.equal(lines.filter(eventOf).length, 0);
|
|
259
|
+
assert.equal(absent.lines().some((line) => JSON.stringify(line).includes(tmpdir())), false, "no paths leak");
|
|
260
|
+
|
|
261
|
+
const app = desktopHost(t);
|
|
262
|
+
app.start();
|
|
263
|
+
await app.invoke("set_permission_mode", { mode: "yolo" });
|
|
264
|
+
app.session.id = "session-2";
|
|
265
|
+
const before = app.lines().length;
|
|
266
|
+
await app.invoke("get_permission_mode");
|
|
267
|
+
await app.invoke("set_permission_mode", { mode: "auto" });
|
|
268
|
+
const after = app.lines().slice(before);
|
|
269
|
+
assert.equal(after.length, 2);
|
|
270
|
+
for (const line of after) assert.equal(line.error.code, "permission_unavailable");
|
|
271
|
+
assert.equal(app.lines().filter(eventOf).length, 1, "only the successful change emitted");
|
|
272
|
+
});
|
|
273
|
+
|
|
274
|
+
test("a failed default save keeps the session change and reports a safe typed error", async (t) => {
|
|
275
|
+
const app = desktopHost(t);
|
|
276
|
+
app.start();
|
|
277
|
+
writeFileSync(app.policyFile, "{");
|
|
278
|
+
await app.invoke("set_permission_mode", { mode: "auto", persist: true });
|
|
279
|
+
const response = app.lines().at(-2);
|
|
280
|
+
assert.deepEqual(response.data, {
|
|
281
|
+
mode: "auto",
|
|
282
|
+
default_mode: "normal",
|
|
283
|
+
persisted: false,
|
|
284
|
+
changed: true,
|
|
285
|
+
persist_error: { code: "default_unchanged", message: "Default permission mode unchanged" },
|
|
286
|
+
});
|
|
287
|
+
assert.equal(readFileSync(app.policyFile, "utf8"), "{", "a malformed preference is never repaired");
|
|
288
|
+
assert.equal(JSON.stringify(app.lines()).includes(tmpdir()), false, "no paths leak");
|
|
289
|
+
const event = app.lines().at(-1);
|
|
290
|
+
assert.equal(event.event, "permission_mode_changed");
|
|
291
|
+
assert.deepEqual(event.data, {
|
|
292
|
+
mode: "auto",
|
|
293
|
+
previous_mode: "normal",
|
|
294
|
+
default_mode: "normal",
|
|
295
|
+
persisted: false,
|
|
296
|
+
source: "desktop",
|
|
297
|
+
});
|
|
298
|
+
});
|
|
299
|
+
|
|
300
|
+
test("TUI and headless hosts keep the permission channel closed", async (t) => {
|
|
301
|
+
const app = desktopHost(t);
|
|
302
|
+
app.start();
|
|
303
|
+
delete process.env[INTERACTIVE_HOST_ENV];
|
|
304
|
+
app.ctx.mode = "rpc";
|
|
305
|
+
await app.invoke("set_permission_mode", { mode: "yolo" });
|
|
306
|
+
process.env[INTERACTIVE_HOST_ENV] = "1";
|
|
307
|
+
app.ctx.mode = "tui";
|
|
308
|
+
await app.invoke("set_permission_mode", { mode: "yolo" });
|
|
309
|
+
assert.deepEqual(app.lines(), []);
|
|
310
|
+
assert.equal(await app.owner!.mode(app.ctx), "normal");
|
|
311
|
+
});
|
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
import assert from "node:assert/strict";
|
|
2
|
+
import test from "node:test";
|
|
3
|
+
import type { ExtensionAPI, ExtensionContext } from "@earendil-works/pi-coding-agent";
|
|
4
|
+
import {
|
|
5
|
+
DESKTOP_PROFILES_SERVICE_CHANNEL,
|
|
6
|
+
DESKTOP_PROFILES_SERVICE_SCHEMA,
|
|
7
|
+
DesktopProfilesBridge,
|
|
8
|
+
desktopConfirmationToken,
|
|
9
|
+
discoverDesktopProfilesService,
|
|
10
|
+
type DesktopProfileApplyRequest,
|
|
11
|
+
type DesktopProfileApplyResult,
|
|
12
|
+
type DesktopProfilesService,
|
|
13
|
+
} from "../lib/desktop-rpc-profiles.ts";
|
|
14
|
+
|
|
15
|
+
const context = { cwd: "/repo" } as unknown as ExtensionContext;
|
|
16
|
+
|
|
17
|
+
function fakeService(result: DesktopProfileApplyResult, seen: DesktopProfileApplyRequest[] = []): DesktopProfilesService & { disposed: number } {
|
|
18
|
+
const service = {
|
|
19
|
+
schema: DESKTOP_PROFILES_SERVICE_SCHEMA as typeof DESKTOP_PROFILES_SERVICE_SCHEMA,
|
|
20
|
+
disposed: 0,
|
|
21
|
+
apply: async (request: DesktopProfileApplyRequest) => {
|
|
22
|
+
seen.push(request);
|
|
23
|
+
return result;
|
|
24
|
+
},
|
|
25
|
+
dispose() {
|
|
26
|
+
service.disposed += 1;
|
|
27
|
+
},
|
|
28
|
+
};
|
|
29
|
+
return service;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
function bridgeWith(service: DesktopProfilesService | undefined): DesktopProfilesBridge {
|
|
33
|
+
const bridge = new DesktopProfilesBridge({} as ExtensionAPI, async () => service);
|
|
34
|
+
bridge.attach(context);
|
|
35
|
+
return bridge;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
test("apply_profile rejects malformed params before reaching the owner", async () => {
|
|
39
|
+
const seen: DesktopProfileApplyRequest[] = [];
|
|
40
|
+
const bridge = bridgeWith(fakeService({ status: "applied", notes: [] }, seen));
|
|
41
|
+
const invalid = { ok: false, error: { code: "invalid_request", message: "Invalid apply_profile parameters" } };
|
|
42
|
+
for (const params of [
|
|
43
|
+
{},
|
|
44
|
+
{ profile: "team" },
|
|
45
|
+
{ profile: "", mode: "default" },
|
|
46
|
+
{ profile: "x".repeat(129), mode: "default" },
|
|
47
|
+
{ profile: "team", mode: "global" },
|
|
48
|
+
{ profile: 1, mode: "default" },
|
|
49
|
+
{ profile: "team", mode: "default", confirmation: 1 },
|
|
50
|
+
{ profile: "team", mode: "default", confirmation: "x".repeat(129) },
|
|
51
|
+
{ profile: "team", mode: "default", extra: true },
|
|
52
|
+
]) {
|
|
53
|
+
assert.deepEqual(await bridge.handle("apply_profile", params), invalid, JSON.stringify(params));
|
|
54
|
+
}
|
|
55
|
+
assert.equal(seen.length, 0);
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
test("apply_profile forwards exactly the request and maps each owner outcome", async () => {
|
|
59
|
+
const seen: DesktopProfileApplyRequest[] = [];
|
|
60
|
+
const confirm = fakeService({ status: "confirmation_required", title: "Apply profile \"team\"?", message: "diff", confirmation: "a".repeat(64) }, seen);
|
|
61
|
+
assert.deepEqual(await bridgeWith(confirm).handle("apply_profile", { profile: "team", mode: "default" }), {
|
|
62
|
+
ok: true,
|
|
63
|
+
data: { profile: "team", mode: "default", status: "confirmation_required", confirmation: { title: "Apply profile \"team\"?", message: "diff", token: "a".repeat(64) } },
|
|
64
|
+
});
|
|
65
|
+
assert.deepEqual(seen, [{ profile: "team", mode: "default" }]);
|
|
66
|
+
assert.equal(confirm.disposed, 1, "the owner service is disposed after each request");
|
|
67
|
+
|
|
68
|
+
const notes = [{ level: "info" as const, text: "applied" }];
|
|
69
|
+
const applied = fakeService({ status: "applied", notes }, seen);
|
|
70
|
+
assert.deepEqual(await bridgeWith(applied).handle("apply_profile", { profile: "team", mode: "session", confirmation: "b".repeat(64) }), {
|
|
71
|
+
ok: true,
|
|
72
|
+
data: { profile: "team", mode: "session", status: "applied", notes },
|
|
73
|
+
event: { name: "profile_applied", data: { profile: "team", mode: "session", source: "desktop" } },
|
|
74
|
+
});
|
|
75
|
+
assert.deepEqual(seen.at(-1), { profile: "team", mode: "session", confirmation: "b".repeat(64) });
|
|
76
|
+
|
|
77
|
+
const failed = [{ level: "warning" as const, text: "could not apply" }];
|
|
78
|
+
assert.deepEqual(await bridgeWith(fakeService({ status: "not_applied", notes: failed })).handle("apply_profile", { profile: "team", mode: "default" }), {
|
|
79
|
+
ok: true,
|
|
80
|
+
data: { profile: "team", mode: "default", status: "not_applied", notes: failed },
|
|
81
|
+
});
|
|
82
|
+
assert.deepEqual(await bridgeWith(fakeService({ status: "unknown_profile" })).handle("apply_profile", { profile: "team", mode: "default" }), {
|
|
83
|
+
ok: false,
|
|
84
|
+
error: { code: "unknown_profile", message: "No saved profile with that name" },
|
|
85
|
+
});
|
|
86
|
+
assert.deepEqual(await bridgeWith(fakeService({ status: "busy" })).handle("apply_profile", { profile: "team", mode: "default" }), {
|
|
87
|
+
ok: false,
|
|
88
|
+
error: { code: "profile_apply_busy", message: "Another profile apply is in progress" },
|
|
89
|
+
});
|
|
90
|
+
});
|
|
91
|
+
|
|
92
|
+
test("apply_profile is unavailable without a host or an owner, and leaves other methods alone", async () => {
|
|
93
|
+
const unavailable = { ok: false, error: { code: "profiles_unavailable", message: "Profiles owner unavailable for this session" } };
|
|
94
|
+
assert.deepEqual(await bridgeWith(undefined).handle("apply_profile", { profile: "team", mode: "default" }), unavailable);
|
|
95
|
+
const detached = new DesktopProfilesBridge({} as ExtensionAPI, async () => fakeService({ status: "applied", notes: [] }));
|
|
96
|
+
assert.deepEqual(await detached.handle("apply_profile", { profile: "team", mode: "default" }), unavailable);
|
|
97
|
+
const bridge = bridgeWith(fakeService({ status: "applied", notes: [] }));
|
|
98
|
+
bridge.reset();
|
|
99
|
+
assert.deepEqual(await bridge.handle("apply_profile", { profile: "team", mode: "default" }), unavailable, "a reset drops the host");
|
|
100
|
+
assert.equal(await bridgeWith(fakeService({ status: "applied", notes: [] })).handle("get_config", { store: "profiles" }), undefined);
|
|
101
|
+
const throwing = { schema: DESKTOP_PROFILES_SERVICE_SCHEMA, apply: async () => { throw new Error("boom"); }, dispose() {} } satisfies DesktopProfilesService;
|
|
102
|
+
assert.deepEqual(await bridgeWith(throwing).handle("apply_profile", { profile: "team", mode: "default" }), unavailable);
|
|
103
|
+
});
|
|
104
|
+
|
|
105
|
+
test("discovery accepts only a schema-shaped owner", async () => {
|
|
106
|
+
const listeners = new Map<string, Array<(payload: unknown) => void>>();
|
|
107
|
+
const pi = {
|
|
108
|
+
events: {
|
|
109
|
+
on(channel: string, listener: (payload: unknown) => void) {
|
|
110
|
+
listeners.set(channel, [...(listeners.get(channel) ?? []), listener]);
|
|
111
|
+
},
|
|
112
|
+
emit(channel: string, payload: unknown) {
|
|
113
|
+
for (const listener of listeners.get(channel) ?? []) listener(payload);
|
|
114
|
+
},
|
|
115
|
+
},
|
|
116
|
+
} as unknown as ExtensionAPI;
|
|
117
|
+
assert.equal(await discoverDesktopProfilesService(pi, context), undefined, "no owner times out");
|
|
118
|
+
const owner = fakeService({ status: "applied", notes: [] });
|
|
119
|
+
pi.events.on(DESKTOP_PROFILES_SERVICE_CHANNEL, (payload) => {
|
|
120
|
+
const request = payload as { context: unknown; respond(value: unknown): void };
|
|
121
|
+
assert.equal(request.context, context);
|
|
122
|
+
request.respond({ schema: "other/v1", apply: owner.apply, dispose: owner.dispose });
|
|
123
|
+
request.respond(owner);
|
|
124
|
+
});
|
|
125
|
+
assert.equal(await discoverDesktopProfilesService(pi, context), owner);
|
|
126
|
+
});
|
|
127
|
+
|
|
128
|
+
test("the confirmation token binds the mode, profile, title, message and profile content", () => {
|
|
129
|
+
const config = { worker: { model: "openai/alpha" } };
|
|
130
|
+
const token = desktopConfirmationToken("default", "team", "Apply profile \"team\"?", "diff", config);
|
|
131
|
+
assert.match(token, /^[0-9a-f]{64}$/);
|
|
132
|
+
assert.equal(desktopConfirmationToken("default", "team", "Apply profile \"team\"?", "diff", { worker: { model: "openai/alpha" } }), token);
|
|
133
|
+
for (const other of [
|
|
134
|
+
desktopConfirmationToken("session", "team", "Apply profile \"team\"?", "diff", config),
|
|
135
|
+
desktopConfirmationToken("default", "teams", "Apply profile \"team\"?", "diff", config),
|
|
136
|
+
desktopConfirmationToken("default", "team", "Apply profile \"team\"?!", "diff", config),
|
|
137
|
+
desktopConfirmationToken("default", "team", "Apply profile \"team\"?", "diff2", config),
|
|
138
|
+
desktopConfirmationToken("default", "team", "Apply profile \"team\"?", "diff", { worker: { model: "openai/beta" } }),
|
|
139
|
+
]) assert.notEqual(other, token);
|
|
140
|
+
});
|
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
import assert from "node:assert/strict";
|
|
2
|
+
import { test } from "node:test";
|
|
3
|
+
import type { JobRecord } from "../lib/background-jobs.ts";
|
|
4
|
+
import { projectDesktopJob } from "../lib/desktop-rpc-jobs.ts";
|
|
5
|
+
import { DesktopPermissionBridge } from "../lib/desktop-rpc-permissions.ts";
|
|
6
|
+
import { YOLO_DISPLAY } from "../lib/yolo-session-policy.ts";
|
|
7
|
+
|
|
8
|
+
function job(command: string, label = command, kind: JobRecord["kind"] = "command"): JobRecord {
|
|
9
|
+
return {
|
|
10
|
+
id: "job-1",
|
|
11
|
+
kind,
|
|
12
|
+
label,
|
|
13
|
+
command,
|
|
14
|
+
cwd: "/home/devel/secret-repo",
|
|
15
|
+
ownerSessionId: "session-a",
|
|
16
|
+
outputPath: "/tmp/gentle-jobs/job-1.log",
|
|
17
|
+
startedAt: 1000,
|
|
18
|
+
status: "running",
|
|
19
|
+
tail: [],
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
test("a job without its own label never shows any part of its command", () => {
|
|
24
|
+
// Every form a shell can hide a value in: headers, assignments (plain,
|
|
25
|
+
// quoted, escaped), quoted and Windows paths, substitutions, unbalanced quotes.
|
|
26
|
+
const commands = [
|
|
27
|
+
'curl -H "Authorization: Bearer sk-live-123" https://api.example.com',
|
|
28
|
+
"GITHUB_TOKEN=ghp_secret /home/devel/bin/deploy.sh --key=s3cr3t",
|
|
29
|
+
'"C:\\Program Files\\Tools\\app.exe" --token=s3cr3t',
|
|
30
|
+
'API_KEY="prefix s3cr3t" /usr/bin/curl https://example.com',
|
|
31
|
+
"TOKEN=prefix\\ s3cr3t /usr/bin/curl",
|
|
32
|
+
"$(printf s3cr3t) --flag",
|
|
33
|
+
'API_KEY="unterminated s3cr3t /usr/bin/curl',
|
|
34
|
+
" npm run build ",
|
|
35
|
+
"",
|
|
36
|
+
];
|
|
37
|
+
for (const [index, command] of commands.entries()) {
|
|
38
|
+
const projected = projectDesktopJob(job(command));
|
|
39
|
+
assert.equal(projected.label, "Background job", `case ${index}`);
|
|
40
|
+
const wire = JSON.stringify(projected);
|
|
41
|
+
for (const secret of ["sk-live-123", "ghp_secret", "s3cr3t", "/home/devel", "Authorization", "npm"]) {
|
|
42
|
+
assert.equal(wire.includes(secret), false, `case ${index} leaks a command fragment`);
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
assert.equal(projectDesktopJob(job("tail -f /var/log/app.log", undefined, "monitor")).label, "Background monitor");
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
test("an explicit job label is kept as the agent wrote it", () => {
|
|
49
|
+
assert.equal(projectDesktopJob(job("gh run watch 42 --exit-status", "CI for PR 42")).label, "CI for PR 42");
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
type Snapshot = { mode: string; defaultMode: string; yolo: string };
|
|
53
|
+
|
|
54
|
+
function fakeAdapter(snapshots: Array<Snapshot | undefined>) {
|
|
55
|
+
let reads = 0;
|
|
56
|
+
const disposed: string[] = [];
|
|
57
|
+
const adapter = {
|
|
58
|
+
readSnapshot: async () => snapshots[Math.min(reads++, snapshots.length - 1)],
|
|
59
|
+
setMode: async () => true,
|
|
60
|
+
saveDefault: async () => true,
|
|
61
|
+
dispose: () => disposed.push("adapter"),
|
|
62
|
+
};
|
|
63
|
+
return { adapter, disposed };
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
const live = (mode: string): Snapshot => ({ mode, defaultMode: "normal", yolo: "on" });
|
|
67
|
+
|
|
68
|
+
test("set_permission_mode never echoes the request when the owner cannot confirm the result", async () => {
|
|
69
|
+
// Before the write the owner answers; after it the session was replaced or
|
|
70
|
+
// revoked, so the post-write read is unavailable.
|
|
71
|
+
const { adapter } = fakeAdapter([live("normal"), { mode: "yolo", defaultMode: "normal", yolo: YOLO_DISPLAY.unavailable }]);
|
|
72
|
+
const bridge = new DesktopPermissionBridge({} as never, (async () => adapter) as never);
|
|
73
|
+
bridge.attach({} as never);
|
|
74
|
+
const outcome = await bridge.handle("set_permission_mode", { mode: "yolo", persist: true });
|
|
75
|
+
assert.equal(outcome?.ok, false);
|
|
76
|
+
assert.deepEqual((outcome as { ok: false; error: { code: string } }).error.code, "permission_unavailable");
|
|
77
|
+
assert.equal("event" in (outcome ?? {}), false, "no permission_mode_changed for an unconfirmed result");
|
|
78
|
+
});
|
|
79
|
+
|
|
80
|
+
test("a confirmed set still reports the owner's state and one event", async () => {
|
|
81
|
+
const { adapter } = fakeAdapter([live("normal"), live("auto")]);
|
|
82
|
+
const bridge = new DesktopPermissionBridge({} as never, (async () => adapter) as never);
|
|
83
|
+
bridge.attach({} as never);
|
|
84
|
+
const outcome = (await bridge.handle("set_permission_mode", { mode: "auto" })) as {
|
|
85
|
+
ok: true;
|
|
86
|
+
data: Record<string, unknown>;
|
|
87
|
+
event?: { name: string };
|
|
88
|
+
};
|
|
89
|
+
assert.equal(outcome.ok, true);
|
|
90
|
+
assert.equal(outcome.data.mode, "auto");
|
|
91
|
+
assert.equal(outcome.event?.name, "permission_mode_changed");
|
|
92
|
+
});
|
|
93
|
+
|
|
94
|
+
test("an owner discovered after a reset is disposed and never cached for the next session", async () => {
|
|
95
|
+
const stale = fakeAdapter([live("yolo")]);
|
|
96
|
+
const fresh = fakeAdapter([live("normal")]);
|
|
97
|
+
let release: (value: unknown) => void = () => {};
|
|
98
|
+
let calls = 0;
|
|
99
|
+
const discover = (() => {
|
|
100
|
+
calls += 1;
|
|
101
|
+
if (calls === 1) return new Promise((resolve) => { release = () => resolve(stale.adapter); });
|
|
102
|
+
return Promise.resolve(fresh.adapter);
|
|
103
|
+
}) as never;
|
|
104
|
+
const bridge = new DesktopPermissionBridge({} as never, discover);
|
|
105
|
+
bridge.attach({} as never);
|
|
106
|
+
const pending = bridge.handle("get_permission_mode", {});
|
|
107
|
+
await Promise.resolve();
|
|
108
|
+
bridge.reset();
|
|
109
|
+
bridge.attach({} as never);
|
|
110
|
+
release(undefined);
|
|
111
|
+
const late = await pending;
|
|
112
|
+
assert.equal(late?.ok, false, "the replaced session's request does not answer from its owner");
|
|
113
|
+
assert.deepEqual(stale.disposed, ["adapter"], "the late owner is disposed");
|
|
114
|
+
|
|
115
|
+
const next = (await bridge.handle("get_permission_mode", {})) as { ok: true; data: Record<string, unknown> };
|
|
116
|
+
assert.equal(next.ok, true);
|
|
117
|
+
assert.equal(next.data.mode, "normal", "the next session reads its own owner, not the late one");
|
|
118
|
+
assert.equal(calls, 2);
|
|
119
|
+
});
|