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,138 @@
|
|
|
1
|
+
// Gentle Desktop design-canvas slice: the pure contract shared by the Desktop
|
|
2
|
+
// bridge (`lib/desktop-design-service.ts`) and the owner seam inside
|
|
3
|
+
// `extensions/gentle-design.ts`.
|
|
4
|
+
//
|
|
5
|
+
// Nothing here opens a server, opens a browser, or reaches the network. It
|
|
6
|
+
// only names the wire shapes, projects the owner's actual canvas state into
|
|
7
|
+
// the safe Desktop projection, and keeps the tokenized canvas URL a capability
|
|
8
|
+
// that is never a bare field. The owner (the single `DesignCanvas` returned by
|
|
9
|
+
// `createDesignCanvas`, plus `listDesigns`) stays the single source of truth;
|
|
10
|
+
// this module is a projection, not a second store, port, or canvas.
|
|
11
|
+
|
|
12
|
+
export const DESKTOP_DESIGN_METHODS = ["get_design_canvas"] as const;
|
|
13
|
+
export const DESKTOP_DESIGN_EVENT = "design_canvas";
|
|
14
|
+
/** Advertised only because the owner seam records the transitions this event carries. */
|
|
15
|
+
export const DESKTOP_DESIGN_EVENTS = [DESKTOP_DESIGN_EVENT] as const;
|
|
16
|
+
|
|
17
|
+
// The versioned owner-service discovery seam (the design analogue of the usage
|
|
18
|
+
// `gentle:desktop:usage-service` adapter). The schema string guards the adapter
|
|
19
|
+
// against drift; the bridge ignores any responder whose shape does not match.
|
|
20
|
+
export const DESKTOP_DESIGN_SERVICE_SCHEMA = "gentle-pi.desktop-design-service/v1";
|
|
21
|
+
export const DESKTOP_DESIGN_SERVICE_CHANNEL = "gentle:desktop:design-service";
|
|
22
|
+
|
|
23
|
+
export type DesktopDesignTransition = "open" | "refresh" | "stop";
|
|
24
|
+
|
|
25
|
+
/** A design under `<cwd>/design`, as the owner's `listDesigns` already reports it. */
|
|
26
|
+
export interface DesktopDesignEntry {
|
|
27
|
+
slug: string;
|
|
28
|
+
title: string;
|
|
29
|
+
/** design.json modification time in milliseconds. */
|
|
30
|
+
mtime: number;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* The sanitized owner state: whether a canvas server is running, the slug it
|
|
35
|
+
* last showed (null for the system-only root), and how many canvas pages are
|
|
36
|
+
* connected. Never a URL, token, port, or server detail.
|
|
37
|
+
*/
|
|
38
|
+
export interface DesktopDesignOwnerState {
|
|
39
|
+
running: boolean;
|
|
40
|
+
slug: string | null;
|
|
41
|
+
connectedClients: number;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* An actual owner open/refresh/stop transition, carrying the sanitized
|
|
46
|
+
* post-transition state. `url` is present only when the observer explicitly
|
|
47
|
+
* subscribed with `includeUrl` (the same capability policy as the read).
|
|
48
|
+
*/
|
|
49
|
+
export interface DesktopDesignOwnerTransition extends DesktopDesignOwnerState {
|
|
50
|
+
transition: DesktopDesignTransition;
|
|
51
|
+
url?: string;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
/** The `get_design_canvas` response: owner state plus the designs the owner lists. */
|
|
55
|
+
export interface DesktopDesignCanvasData extends DesktopDesignOwnerState {
|
|
56
|
+
designs: DesktopDesignEntry[];
|
|
57
|
+
/** The tokenized canvas URL; present only after `includeUrl: true` and trust. */
|
|
58
|
+
url?: string;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
/**
|
|
62
|
+
* The owner-service adapter the bridge discovers. Every method is defensive:
|
|
63
|
+
* after `dispose()` it answers empty/no-op rather than speaking into a
|
|
64
|
+
* replaced session.
|
|
65
|
+
*/
|
|
66
|
+
export interface DesktopDesignService {
|
|
67
|
+
schema: typeof DESKTOP_DESIGN_SERVICE_SCHEMA;
|
|
68
|
+
read(): Promise<DesktopDesignOwnerState>;
|
|
69
|
+
/** The tokenized URL the running canvas last showed, or undefined. A capability. */
|
|
70
|
+
url(): string | undefined;
|
|
71
|
+
listDesigns(): DesktopDesignEntry[];
|
|
72
|
+
/** Subscribe to actual open/refresh/stop transitions. `includeUrl` adds the URL. */
|
|
73
|
+
observe(options: { includeUrl?: boolean }, onTransition: (transition: DesktopDesignOwnerTransition) => void): () => void;
|
|
74
|
+
dispose(): void;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
export const INVALID_DESIGN_PARAMS = { code: "invalid_request", message: "Invalid design canvas parameters" } as const;
|
|
78
|
+
export const DESIGN_UNAVAILABLE = { code: "design_unavailable", message: "Design canvas owner unavailable for this session" } as const;
|
|
79
|
+
|
|
80
|
+
/**
|
|
81
|
+
* `get_design_canvas` params: either empty (omit the URL) or exactly
|
|
82
|
+
* `{ includeUrl: boolean }`. Anything else is a typed `invalid_request` before
|
|
83
|
+
* any owner work happens.
|
|
84
|
+
*/
|
|
85
|
+
export function parseDesignCanvasParams(
|
|
86
|
+
params: Record<string, unknown>,
|
|
87
|
+
): { includeUrl: boolean } | { error: { code: string; message: string } } {
|
|
88
|
+
const keys = Object.keys(params);
|
|
89
|
+
if (keys.length === 0) return { includeUrl: false };
|
|
90
|
+
if (keys.length !== 1 || keys[0] !== "includeUrl" || typeof params.includeUrl !== "boolean") {
|
|
91
|
+
return { error: INVALID_DESIGN_PARAMS };
|
|
92
|
+
}
|
|
93
|
+
return { includeUrl: params.includeUrl };
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
/** True only for the adapter-shaped object the discovery responder must return. */
|
|
97
|
+
export function isDesktopDesignServiceShape(value: unknown): value is DesktopDesignService {
|
|
98
|
+
if (!value || typeof value !== "object") return false;
|
|
99
|
+
const adapter = value as Partial<DesktopDesignService>;
|
|
100
|
+
if (adapter.schema !== DESKTOP_DESIGN_SERVICE_SCHEMA) return false;
|
|
101
|
+
return [adapter.read, adapter.url, adapter.listDesigns, adapter.observe, adapter.dispose].every((fn) => typeof fn === "function");
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
/**
|
|
105
|
+
* True only for a well-shaped owner state. The owner's answer crosses the event
|
|
106
|
+
* bus, so its shape is never trusted beyond the fields the bridge projects:
|
|
107
|
+
* `running` boolean, `slug` null or a non-empty string, `connectedClients` a
|
|
108
|
+
* non-negative integer. Anything else is junk the bridge answers
|
|
109
|
+
* `design_unavailable` for rather than projecting into a malformed success.
|
|
110
|
+
*/
|
|
111
|
+
export function isValidDesktopDesignOwnerState(value: unknown): value is DesktopDesignOwnerState {
|
|
112
|
+
if (!value || typeof value !== "object") return false;
|
|
113
|
+
const state = value as Record<string, unknown>;
|
|
114
|
+
if (typeof state.running !== "boolean") return false;
|
|
115
|
+
if (state.slug !== null && (typeof state.slug !== "string" || state.slug.length === 0)) return false;
|
|
116
|
+
return typeof state.connectedClients === "number" && Number.isInteger(state.connectedClients) && state.connectedClients >= 0;
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
/**
|
|
120
|
+
* Projects one owner design list, rebuilding each entry with only the named
|
|
121
|
+
* fields (`slug`, `title`, `mtime`) so a foreign `token`, `url`, or path member
|
|
122
|
+
* is dropped rather than echoed. Returns `undefined` for a non-array or any
|
|
123
|
+
* malformed entry, which the bridge treats as an unavailable owner instead of a
|
|
124
|
+
* malformed success.
|
|
125
|
+
*/
|
|
126
|
+
export function parseDesktopDesignEntries(value: unknown): DesktopDesignEntry[] | undefined {
|
|
127
|
+
if (!Array.isArray(value)) return undefined;
|
|
128
|
+
const entries: DesktopDesignEntry[] = [];
|
|
129
|
+
for (const entry of value) {
|
|
130
|
+
if (!entry || typeof entry !== "object") return undefined;
|
|
131
|
+
const raw = entry as Record<string, unknown>;
|
|
132
|
+
if (typeof raw.slug !== "string" || raw.slug.length === 0) return undefined;
|
|
133
|
+
if (typeof raw.title !== "string") return undefined;
|
|
134
|
+
if (typeof raw.mtime !== "number" || !Number.isFinite(raw.mtime) || raw.mtime < 0) return undefined;
|
|
135
|
+
entries.push({ slug: raw.slug, title: raw.title, mtime: raw.mtime });
|
|
136
|
+
}
|
|
137
|
+
return entries;
|
|
138
|
+
}
|
|
@@ -0,0 +1,181 @@
|
|
|
1
|
+
// Gentle Desktop background-jobs slice: the pure contract shared by the
|
|
2
|
+
// Desktop bridge (`lib/desktop-jobs-service.ts`) and the owner seam inside
|
|
3
|
+
// `extensions/gentle-agents.ts`.
|
|
4
|
+
//
|
|
5
|
+
// Nothing here starts, stops, or polls a job. It only names the wire shapes,
|
|
6
|
+
// projects the owner's actual `JobRecord` state into the safe Desktop
|
|
7
|
+
// projection, and defines the bounded running + recent-finished selection the
|
|
8
|
+
// Desktop list uses. The owner (the single parent-session `JobRegistry` plus
|
|
9
|
+
// the parent `MonitorController`, reached through `job_stop`'s exact stop
|
|
10
|
+
// path) stays the single source of truth; this module is a projection, not a
|
|
11
|
+
// second registry, process manager, or store.
|
|
12
|
+
|
|
13
|
+
import type { JobRecord, JobStatus } from "./background-jobs.ts";
|
|
14
|
+
import { JOBS_FINISHED_TTL_MS } from "./jobs-widget.ts";
|
|
15
|
+
|
|
16
|
+
export const DESKTOP_JOBS_METHODS = ["list_jobs", "cancel_job"] as const;
|
|
17
|
+
export const DESKTOP_JOBS_EVENT = "jobs_update";
|
|
18
|
+
/** Advertised only because the owner seam records the registry changes this event carries. */
|
|
19
|
+
export const DESKTOP_JOBS_EVENTS = [DESKTOP_JOBS_EVENT] as const;
|
|
20
|
+
|
|
21
|
+
// The versioned owner-service discovery seam (the jobs analogue of the usage
|
|
22
|
+
// `gentle:desktop:usage-service` adapter). The schema string guards the adapter
|
|
23
|
+
// against drift; the bridge ignores any responder whose shape does not match.
|
|
24
|
+
export const DESKTOP_JOBS_SERVICE_SCHEMA = "gentle-pi.desktop-jobs-service/v1";
|
|
25
|
+
export const DESKTOP_JOBS_SERVICE_CHANNEL = "gentle:desktop:jobs-service";
|
|
26
|
+
|
|
27
|
+
/** Upper bound on the number of jobs one list answer carries (running + recent finished). */
|
|
28
|
+
export const DESKTOP_JOBS_LIST_LIMIT = 50;
|
|
29
|
+
|
|
30
|
+
export type DesktopJobStatus = JobStatus;
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* The safe wire window for one job. Only these fields exist on the wire:
|
|
34
|
+
* identity, the human label, the status word, start/end timestamps, and the
|
|
35
|
+
* exit code when the owner recorded one. Never a command, cwd, output path or
|
|
36
|
+
* tail, environment, owner session id, monitor counters, or an error string.
|
|
37
|
+
*/
|
|
38
|
+
export interface DesktopJobEntry {
|
|
39
|
+
id: string;
|
|
40
|
+
label: string;
|
|
41
|
+
status: DesktopJobStatus;
|
|
42
|
+
startedAt: number;
|
|
43
|
+
endedAt?: number;
|
|
44
|
+
exitCode?: number | null;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
/** The owner's list answer for one session: which session, plus its projected jobs. */
|
|
48
|
+
export interface DesktopJobsOwnerRead {
|
|
49
|
+
sessionId: string;
|
|
50
|
+
jobs: DesktopJobEntry[];
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* A `cancel_job` owner result. `changed` is `true` only when the job really
|
|
55
|
+
* transitioned from running to stopped; an already-terminal job answers
|
|
56
|
+
* `changed: false` with its terminal projection instead of a race-driven error.
|
|
57
|
+
*/
|
|
58
|
+
export type DesktopJobsCancelOutcome =
|
|
59
|
+
| { kind: "ok"; job: DesktopJobEntry; changed: boolean }
|
|
60
|
+
| { kind: "not_found" };
|
|
61
|
+
|
|
62
|
+
/**
|
|
63
|
+
* The owner-service adapter the bridge discovers. Every method is defensive:
|
|
64
|
+
* after `dispose()` it answers empty/no-op rather than speaking into a
|
|
65
|
+
* replaced session.
|
|
66
|
+
*/
|
|
67
|
+
export interface DesktopJobsService {
|
|
68
|
+
schema: typeof DESKTOP_JOBS_SERVICE_SCHEMA;
|
|
69
|
+
read(): DesktopJobsOwnerRead;
|
|
70
|
+
cancel(id: string): DesktopJobsCancelOutcome;
|
|
71
|
+
/** Subscribe to actual registry changes; the unsubscribe stops delivery. */
|
|
72
|
+
observe(onChange: (sessionId: string) => void): () => void;
|
|
73
|
+
dispose(): void;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
export const INVALID_JOBS_PARAMS = { code: "invalid_request", message: "Invalid background jobs parameters" } as const;
|
|
77
|
+
export const JOBS_UNAVAILABLE = { code: "jobs_unavailable", message: "Background jobs owner unavailable for this session" } as const;
|
|
78
|
+
export const JOB_NOT_FOUND = { code: "not_found", message: "No background job with that id in this session" } as const;
|
|
79
|
+
|
|
80
|
+
/** Shown for a command job the agent started without a label. */
|
|
81
|
+
export const DESKTOP_JOB_FALLBACK_LABEL = "Background job";
|
|
82
|
+
/** Shown for a monitor the agent started without a label. */
|
|
83
|
+
export const DESKTOP_MONITOR_FALLBACK_LABEL = "Background monitor";
|
|
84
|
+
|
|
85
|
+
/**
|
|
86
|
+
* The label a job may show on the wire. An explicit label is the agent's own
|
|
87
|
+
* wording and is kept. Without one, the registry falls back to the command
|
|
88
|
+
* itself, and a command can hide a secret in more shell forms (headers,
|
|
89
|
+
* quoted or escaped assignments, substitutions) than any parser here could
|
|
90
|
+
* safely cover, so no part of it is derived: the label is fixed by kind.
|
|
91
|
+
*/
|
|
92
|
+
export function desktopJobLabel(job: Pick<JobRecord, "label" | "command" | "kind">): string {
|
|
93
|
+
if (job.label.trim() !== job.command.trim()) return job.label;
|
|
94
|
+
return job.kind === "monitor" ? DESKTOP_MONITOR_FALLBACK_LABEL : DESKTOP_JOB_FALLBACK_LABEL;
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
/**
|
|
98
|
+
* The whitelisted projection of one owner `JobRecord`. Every field is rebuilt
|
|
99
|
+
* from the named members only, so a foreign or stale object can never smuggle
|
|
100
|
+
* a command, path, tail line, or secret into the Desktop payload.
|
|
101
|
+
*/
|
|
102
|
+
export function projectDesktopJob(job: JobRecord): DesktopJobEntry {
|
|
103
|
+
const entry: DesktopJobEntry = {
|
|
104
|
+
id: job.id,
|
|
105
|
+
label: desktopJobLabel(job),
|
|
106
|
+
status: job.status,
|
|
107
|
+
startedAt: job.startedAt,
|
|
108
|
+
};
|
|
109
|
+
if (job.endedAt !== undefined) entry.endedAt = job.endedAt;
|
|
110
|
+
if (job.exitCode !== undefined) entry.exitCode = job.exitCode;
|
|
111
|
+
return entry;
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
/**
|
|
115
|
+
* The bounded `list_jobs` selection: running jobs first (newest start first),
|
|
116
|
+
* then recently-finished jobs (newest end first), capped so the answer can
|
|
117
|
+
* never grow with the lifetime of the process. Finished jobs older than the
|
|
118
|
+
* TTL drop out, matching the jobs widget's lingering semantics.
|
|
119
|
+
*/
|
|
120
|
+
export function selectDesktopJobs(jobs: readonly JobRecord[], now: number): DesktopJobEntry[] {
|
|
121
|
+
const running = jobs
|
|
122
|
+
.filter((job) => job.status === "running")
|
|
123
|
+
.sort((left, right) => right.startedAt - left.startedAt);
|
|
124
|
+
const finished = jobs
|
|
125
|
+
.filter((job) => job.status !== "running" && job.endedAt !== undefined && now - job.endedAt < JOBS_FINISHED_TTL_MS)
|
|
126
|
+
.sort((left, right) => (right.endedAt ?? 0) - (left.endedAt ?? 0));
|
|
127
|
+
return [...running, ...finished].slice(0, DESKTOP_JOBS_LIST_LIMIT).map(projectDesktopJob);
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
/**
|
|
131
|
+
* Defensive validation of one owner-projected entry. The owner's answer crosses
|
|
132
|
+
* the event bus, so its shape is never trusted beyond the fields the bridge
|
|
133
|
+
* projects; anything else is junk the bridge answers `jobs_unavailable` for
|
|
134
|
+
* rather than projecting into a malformed success.
|
|
135
|
+
*/
|
|
136
|
+
export function parseDesktopJobEntry(value: unknown): DesktopJobEntry | undefined {
|
|
137
|
+
if (!value || typeof value !== "object") return undefined;
|
|
138
|
+
const raw = value as Record<string, unknown>;
|
|
139
|
+
if (typeof raw.id !== "string" || raw.id.length === 0) return undefined;
|
|
140
|
+
if (typeof raw.label !== "string") return undefined;
|
|
141
|
+
if (raw.status !== "running" && raw.status !== "exited" && raw.status !== "stopped" && raw.status !== "failed") return undefined;
|
|
142
|
+
if (typeof raw.startedAt !== "number" || !Number.isFinite(raw.startedAt) || raw.startedAt < 0) return undefined;
|
|
143
|
+
const entry: DesktopJobEntry = { id: raw.id, label: raw.label, status: raw.status, startedAt: raw.startedAt };
|
|
144
|
+
if (raw.endedAt !== undefined) {
|
|
145
|
+
if (typeof raw.endedAt !== "number" || !Number.isFinite(raw.endedAt) || raw.endedAt < 0) return undefined;
|
|
146
|
+
entry.endedAt = raw.endedAt;
|
|
147
|
+
}
|
|
148
|
+
if (raw.exitCode !== undefined) {
|
|
149
|
+
if (raw.exitCode !== null && (typeof raw.exitCode !== "number" || !Number.isFinite(raw.exitCode))) return undefined;
|
|
150
|
+
entry.exitCode = raw.exitCode as number | null;
|
|
151
|
+
}
|
|
152
|
+
return entry;
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
/**
|
|
156
|
+
* `list_jobs` params must be an empty object; anything else is a typed
|
|
157
|
+
* `invalid_request` before any owner work happens.
|
|
158
|
+
*/
|
|
159
|
+
export function parseListJobsParams(params: Record<string, unknown>): { ok: true } | { error: { code: string; message: string } } {
|
|
160
|
+
return Object.keys(params).length === 0 ? { ok: true } : { error: INVALID_JOBS_PARAMS };
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
/**
|
|
164
|
+
* `cancel_job` params are exactly `{ id: non-empty string }`. Anything else is
|
|
165
|
+
* a typed `invalid_request` before any owner work happens.
|
|
166
|
+
*/
|
|
167
|
+
export function parseCancelJobParams(params: Record<string, unknown>): { id: string } | { error: { code: string; message: string } } {
|
|
168
|
+
const keys = Object.keys(params);
|
|
169
|
+
if (keys.length !== 1 || keys[0] !== "id" || typeof params.id !== "string" || params.id.length === 0) {
|
|
170
|
+
return { error: INVALID_JOBS_PARAMS };
|
|
171
|
+
}
|
|
172
|
+
return { id: params.id };
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
/** True only for the adapter-shaped object the discovery responder must return. */
|
|
176
|
+
export function isDesktopJobsServiceShape(value: unknown): value is DesktopJobsService {
|
|
177
|
+
if (!value || typeof value !== "object") return false;
|
|
178
|
+
const adapter = value as Partial<DesktopJobsService>;
|
|
179
|
+
if (adapter.schema !== DESKTOP_JOBS_SERVICE_SCHEMA) return false;
|
|
180
|
+
return [adapter.read, adapter.cancel, adapter.observe, adapter.dispose].every((fn) => typeof fn === "function");
|
|
181
|
+
}
|
|
@@ -0,0 +1,177 @@
|
|
|
1
|
+
import type { ExtensionAPI, ExtensionContext } from "@earendil-works/pi-coding-agent";
|
|
2
|
+
import { discoverYoloUiAdapter, YOLO_DISPLAY, type YoloUiAdapter } from "./yolo-session-policy.ts";
|
|
3
|
+
import { isPermissionMode, type PermissionMode } from "./permission-mode-policy.ts";
|
|
4
|
+
import type { DesktopRpcOutcome } from "./desktop-rpc.ts";
|
|
5
|
+
|
|
6
|
+
export const DESKTOP_PERMISSION_METHODS = ["get_permission_mode", "set_permission_mode"] as const;
|
|
7
|
+
export const DESKTOP_PERMISSION_EVENT = "permission_mode_changed";
|
|
8
|
+
|
|
9
|
+
const UNAVAILABLE = { code: "permission_unavailable", message: "Permission owner unavailable for this session" } as const;
|
|
10
|
+
const DENIED = { code: "permission_denied", message: "Permission mode unchanged for this session" } as const;
|
|
11
|
+
const INVALID_PARAMS = { code: "invalid_request", message: "Invalid permission mode parameters" } as const;
|
|
12
|
+
const INVALID_MODE = { code: "invalid_request", message: "Unknown permission mode" } as const;
|
|
13
|
+
const DEFAULT_UNCHANGED = { code: "default_unchanged", message: "Default permission mode unchanged" } as const;
|
|
14
|
+
|
|
15
|
+
type PermissionState = { mode: PermissionMode; defaultMode: PermissionMode };
|
|
16
|
+
|
|
17
|
+
function parseSetParams(params: Record<string, unknown>): { mode: unknown; persist: boolean } | undefined {
|
|
18
|
+
for (const key of Object.keys(params)) {
|
|
19
|
+
if (key !== "mode" && key !== "persist") return undefined;
|
|
20
|
+
}
|
|
21
|
+
if (typeof params.mode !== "string") return undefined;
|
|
22
|
+
if (params.persist !== undefined && typeof params.persist !== "boolean") return undefined;
|
|
23
|
+
return { mode: params.mode, persist: params.persist === true };
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* Desktop's permission surface over the existing YoloSessionController owner.
|
|
28
|
+
*
|
|
29
|
+
* The owner is reached only through its published `gentle:yolo:host-ui` adapter:
|
|
30
|
+
* the same controller that answers `/gentle:mode`, so there is no parallel mode
|
|
31
|
+
* store, no second file reader, and no filesystem watcher. Every mutation is
|
|
32
|
+
* validated by the owner (interactive host, live session identity, atomic save);
|
|
33
|
+
* this bridge only shapes owner results into the Desktop RPC contract.
|
|
34
|
+
*/
|
|
35
|
+
export class DesktopPermissionBridge {
|
|
36
|
+
private readonly pi: ExtensionAPI;
|
|
37
|
+
private readonly discover: typeof discoverYoloUiAdapter;
|
|
38
|
+
private adapter: YoloUiAdapter | undefined;
|
|
39
|
+
private discovering: Promise<YoloUiAdapter | undefined> | undefined;
|
|
40
|
+
private host: ExtensionContext | undefined;
|
|
41
|
+
private generation = 0;
|
|
42
|
+
|
|
43
|
+
constructor(pi: ExtensionAPI, discover: typeof discoverYoloUiAdapter = discoverYoloUiAdapter) {
|
|
44
|
+
this.pi = pi;
|
|
45
|
+
this.discover = discover;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
/** The live interactive context of this Desktop session; bound per command. */
|
|
49
|
+
attach(context: ExtensionContext): void {
|
|
50
|
+
this.host = context;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
/** Session start/shutdown: the owner adapter of a previous session is invalid. */
|
|
54
|
+
reset(): void {
|
|
55
|
+
this.generation += 1;
|
|
56
|
+
const adapter = this.adapter;
|
|
57
|
+
this.adapter = undefined;
|
|
58
|
+
this.discovering = undefined;
|
|
59
|
+
this.host = undefined;
|
|
60
|
+
try {
|
|
61
|
+
adapter?.dispose();
|
|
62
|
+
} catch {
|
|
63
|
+
/* display-only owner teardown */
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
async handle(method: string, params: Record<string, unknown>): Promise<DesktopRpcOutcome | undefined> {
|
|
68
|
+
const context = this.host;
|
|
69
|
+
if (!context) return { ok: false, error: UNAVAILABLE };
|
|
70
|
+
if (method === "get_permission_mode") {
|
|
71
|
+
if (Object.keys(params).length > 0) return { ok: false, error: INVALID_PARAMS };
|
|
72
|
+
const state = await this.read(context);
|
|
73
|
+
return state ? { ok: true, data: { mode: state.mode, default_mode: state.defaultMode } } : { ok: false, error: UNAVAILABLE };
|
|
74
|
+
}
|
|
75
|
+
if (method === "set_permission_mode") return this.set(context, params);
|
|
76
|
+
return undefined;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
private async owner(context: ExtensionContext): Promise<YoloUiAdapter | undefined> {
|
|
80
|
+
if (this.adapter) return this.adapter;
|
|
81
|
+
if (!this.discovering) {
|
|
82
|
+
// A discovery that outlives a reset belongs to the replaced session: its
|
|
83
|
+
// adapter is disposed and never cached, like the other Desktop bridges.
|
|
84
|
+
const generation = this.generation;
|
|
85
|
+
const discovering: Promise<YoloUiAdapter | undefined> = Promise.resolve()
|
|
86
|
+
.then(() => this.discover(this.pi, context))
|
|
87
|
+
.then((adapter) => {
|
|
88
|
+
if (generation !== this.generation) {
|
|
89
|
+
try {
|
|
90
|
+
adapter?.dispose();
|
|
91
|
+
} catch {
|
|
92
|
+
/* display-only owner teardown */
|
|
93
|
+
}
|
|
94
|
+
return undefined;
|
|
95
|
+
}
|
|
96
|
+
this.adapter = adapter ?? undefined;
|
|
97
|
+
return adapter;
|
|
98
|
+
})
|
|
99
|
+
.catch(() => undefined)
|
|
100
|
+
.finally(() => {
|
|
101
|
+
if (this.discovering === discovering) this.discovering = undefined;
|
|
102
|
+
});
|
|
103
|
+
this.discovering = discovering;
|
|
104
|
+
}
|
|
105
|
+
return this.discovering;
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
private async read(context: ExtensionContext): Promise<PermissionState | undefined> {
|
|
109
|
+
const adapter = await this.owner(context);
|
|
110
|
+
if (!adapter || typeof adapter.readSnapshot !== "function") return undefined;
|
|
111
|
+
try {
|
|
112
|
+
const snapshot = await adapter.readSnapshot();
|
|
113
|
+
if (!snapshot || snapshot.yolo === YOLO_DISPLAY.unavailable) return undefined;
|
|
114
|
+
if (!isPermissionMode(snapshot.mode) || !isPermissionMode(snapshot.defaultMode)) return undefined;
|
|
115
|
+
return { mode: snapshot.mode, defaultMode: snapshot.defaultMode };
|
|
116
|
+
} catch {
|
|
117
|
+
return undefined;
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
private async set(context: ExtensionContext, params: Record<string, unknown>): Promise<DesktopRpcOutcome> {
|
|
122
|
+
const parsed = parseSetParams(params);
|
|
123
|
+
if (!parsed) return { ok: false, error: INVALID_PARAMS };
|
|
124
|
+
if (!isPermissionMode(parsed.mode)) return { ok: false, error: INVALID_MODE };
|
|
125
|
+
const adapter = await this.owner(context);
|
|
126
|
+
if (!adapter || typeof adapter.setMode !== "function") return { ok: false, error: UNAVAILABLE };
|
|
127
|
+
const before = await this.read(context);
|
|
128
|
+
if (!before) return { ok: false, error: UNAVAILABLE };
|
|
129
|
+
|
|
130
|
+
let applied = false;
|
|
131
|
+
try {
|
|
132
|
+
applied = await adapter.setMode(parsed.mode);
|
|
133
|
+
} catch {
|
|
134
|
+
applied = false;
|
|
135
|
+
}
|
|
136
|
+
if (!applied) return { ok: false, error: DENIED };
|
|
137
|
+
|
|
138
|
+
// Persistence is a separate, explicitly requested owner write. A failure
|
|
139
|
+
// never rolls the live session change back.
|
|
140
|
+
let persisted = false;
|
|
141
|
+
let persistFailed = false;
|
|
142
|
+
if (parsed.persist) {
|
|
143
|
+
try {
|
|
144
|
+
persisted = typeof adapter.saveDefault === "function" ? await adapter.saveDefault(parsed.mode) : false;
|
|
145
|
+
} catch {
|
|
146
|
+
persisted = false;
|
|
147
|
+
}
|
|
148
|
+
persistFailed = !persisted;
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
// The response reports only what the owner confirms. If the session was
|
|
152
|
+
// replaced or revoked meanwhile, echoing the request could claim a mode the
|
|
153
|
+
// owner is not enforcing.
|
|
154
|
+
const after = await this.read(context);
|
|
155
|
+
if (!after) return { ok: false, error: UNAVAILABLE };
|
|
156
|
+
const mode = after.mode;
|
|
157
|
+
const defaultMode = after.defaultMode;
|
|
158
|
+
const changed = mode !== before.mode || defaultMode !== before.defaultMode;
|
|
159
|
+
const data: Record<string, unknown> = { mode, default_mode: defaultMode, persisted, changed };
|
|
160
|
+
if (persistFailed) data.persist_error = { ...DEFAULT_UNCHANGED };
|
|
161
|
+
const outcome: DesktopRpcOutcome = { ok: true, data };
|
|
162
|
+
if (!changed) return outcome;
|
|
163
|
+
return {
|
|
164
|
+
...outcome,
|
|
165
|
+
event: {
|
|
166
|
+
name: DESKTOP_PERMISSION_EVENT,
|
|
167
|
+
data: {
|
|
168
|
+
mode,
|
|
169
|
+
previous_mode: before.mode,
|
|
170
|
+
default_mode: defaultMode,
|
|
171
|
+
persisted,
|
|
172
|
+
source: "desktop",
|
|
173
|
+
},
|
|
174
|
+
},
|
|
175
|
+
};
|
|
176
|
+
}
|
|
177
|
+
}
|