gentle-pi 4.6.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 +65 -55
- package/assets/agents/gentle-ai-explore.md +4 -3
- package/assets/agents/gentle-ai-verify.md +23 -6
- package/assets/agents/gentle-ai-worker.md +9 -6
- package/assets/agents/jd-fix-agent.md +1 -0
- package/assets/agents/jd-judge-a.md +2 -3
- package/assets/agents/jd-judge-b.md +2 -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 +759 -16
- package/assets/design-canvas/canvas.js +2 -1497
- package/assets/design-canvas/index.html +117 -36
- package/assets/design-canvas/inspector.js +546 -16
- package/assets/install-wizard/wizard.js +6 -1
- package/assets/migrations/agent-body-history.json +40 -1
- package/assets/orchestrator-delegation-reference.md +10 -16
- package/assets/orchestrator-delegation.md +5 -5
- package/assets/orchestrator-full-delegation-card.md +64 -0
- package/assets/orchestrator-full-delegation.md +34 -0
- package/assets/orchestrator-memory.md +5 -5
- package/assets/orchestrator-prompts.md +2 -2
- package/assets/orchestrator-quota-recovery.md +5 -0
- package/assets/orchestrator-skills.md +14 -13
- package/assets/orchestrator-tracking.md +10 -14
- package/assets/orchestrator-verification.md +12 -8
- package/assets/orchestrator-writer.md +4 -4
- package/assets/orchestrator.md +21 -25
- package/bin/gentle-shell.mjs +292 -65
- 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/agent-status.md +61 -0
- package/docs/assets/brand/sponsor-banner.svg +60 -0
- package/docs/bundled-install.md +20 -10
- package/docs/delegated-verification.md +46 -8
- package/docs/desktop-rpc.md +1253 -0
- package/docs/gentle-agents-activity.md +40 -0
- package/docs/gentle-shell.md +91 -30
- package/docs/install-wizard.md +30 -21
- package/docs/odd-preparation-continuity.md +24 -0
- package/docs/permission-modes.md +17 -4
- package/docs/prompt-budget.md +12 -0
- package/docs/rdd-odd-friction-triage-2026-11-07.md +57 -0
- package/docs/readme-reference.md +142 -45
- package/docs/render-cache-performance.md +11 -1
- package/docs/review-coordinator.md +53 -0
- package/docs/review-delivery-preflight.md +22 -0
- package/docs/review-request-context.md +19 -0
- package/docs/review-windows-acl.md +18 -0
- package/docs/voice.md +6 -3
- package/docs/work-continuity.md +11 -1
- package/docs/yolo-mode.md +5 -5
- package/extensions/ask-user-choice.ts +1 -0
- package/extensions/ask-user-question.ts +3 -2
- package/extensions/child-context.ts +21 -7
- package/extensions/child-safety.ts +3 -0
- package/extensions/gentle-agent-status.ts +99 -0
- package/extensions/gentle-agents.ts +559 -66
- package/extensions/gentle-ai.ts +2001 -518
- 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 +398 -115
- package/extensions/gentle-todo.ts +66 -27
- package/extensions/gentle-tps.ts +48 -0
- package/extensions/quiet-tools.ts +38 -8
- package/extensions/skill-registry.ts +349 -167
- package/extensions/startup-banner.ts +30 -3
- package/lib/agent-assets.ts +30 -6
- package/lib/agent-profile-pin.ts +3 -3
- package/lib/agent-profiles.ts +160 -2
- package/lib/agent-status.ts +105 -0
- package/lib/agent-tool-overlay.ts +117 -0
- package/lib/agents-config.ts +93 -6
- package/lib/agents-history.ts +24 -5
- package/lib/agents-message-delivery.ts +17 -0
- package/lib/agents-messaging.ts +55 -7
- package/lib/agents-protocol.ts +15 -0
- package/lib/agents-report-cap.ts +115 -0
- package/lib/agents-runner.ts +272 -16
- package/lib/agents-session-transport.ts +17 -1
- package/lib/auto-permission-runtime.ts +1 -1
- package/lib/background-jobs-tools.ts +9 -4
- package/lib/bounded-writer-admission.ts +197 -32
- package/lib/card-content-policy.ts +8 -6
- package/lib/child-context-files.ts +21 -6
- package/lib/codemode-renderer.ts +1 -0
- package/lib/command-palette.ts +133 -17
- package/lib/context-backstop.ts +14 -5
- 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 +236 -17
- package/lib/execution-surface-guard.ts +20 -0
- package/lib/exploration-budget.ts +4 -2
- package/lib/gentle-ai-binary.ts +1 -1
- package/lib/gentle-ai-renderer.ts +13 -1
- package/lib/gentle-design.ts +204 -14
- package/lib/gentle-shell-bundled.ts +106 -28
- package/lib/gentle-shell-launcher.ts +43 -8
- package/lib/herdr-activity.ts +14 -2
- package/lib/herdr-busy.ts +45 -0
- package/lib/hidden-tools.ts +35 -0
- package/lib/image-attachments.ts +33 -0
- package/lib/image-disk-cache.ts +137 -0
- package/lib/inprocess-reviewer.ts +358 -144
- package/lib/jobs-view.ts +198 -11
- package/lib/model-fallback-policy.ts +9 -0
- package/lib/model-routing-authority.ts +31 -4
- package/lib/nan-provider.ts +42 -28
- package/lib/native-choice-list.ts +20 -2
- package/lib/native-review-cli.ts +172 -20
- package/lib/orchestrator-discovery.ts +39 -2
- package/lib/orchestrator-mode-policy.ts +105 -0
- package/lib/questionnaire/questionnaire-view.ts +105 -12
- package/lib/rdd-mode-control.ts +32 -0
- package/lib/reply-language-anchor.ts +129 -0
- package/lib/request-context-placement.ts +53 -0
- package/lib/review-blocker.ts +92 -0
- package/lib/review-candidate-symlink-scan.ts +136 -0
- package/lib/review-candidate-view-owner.ts +81 -44
- package/lib/review-candidate-view.ts +11 -1
- package/lib/review-continuation-registry.ts +116 -0
- package/lib/review-coordinator.ts +407 -0
- package/lib/review-delivery-preflight.ts +85 -0
- package/lib/review-failure-facts.ts +49 -0
- package/lib/review-host-relay.ts +51 -11
- package/lib/review-integration-v2.ts +63 -4
- package/lib/review-relay-phase-timing.ts +45 -0
- package/lib/review-start-context.ts +17 -0
- package/lib/reviewer-stream.ts +87 -0
- package/lib/session-profile-freeze.ts +4 -2
- package/lib/shell-bar.ts +140 -58
- package/lib/shell-changes.ts +2 -0
- package/lib/shell-panel.ts +17 -3
- package/lib/shell-prompt.ts +16 -3
- package/lib/shell-sidebar-layout.ts +112 -40
- package/lib/shell-sidebar.ts +7 -0
- package/lib/shell-todo.ts +10 -3
- package/lib/shell-usage.ts +10 -0
- package/lib/verifier-admission.ts +1 -1
- package/lib/vim-editor-adapter.ts +9 -2
- package/lib/visual-customization-policy.ts +36 -16
- package/lib/visual-customize-view.ts +216 -21
- package/lib/visual-layout-preview.ts +9 -5
- package/lib/visual-profiles.ts +2 -2
- package/lib/windows-session-transport.ts +53 -2
- package/lib/writer-batch-admission.ts +55 -0
- package/lib/yolo-session-policy.ts +46 -16
- package/package.json +3 -2
- package/prompts/skill-creation.md +1 -10
- package/runtime/design-canvas-assets.mjs +37 -0
- package/runtime/gentle-ai-binary.mjs +1 -1
- package/runtime/gentle-shell-bundled.mjs +106 -28
- package/runtime/gentle-shell-launcher.mjs +42 -7
- package/runtime/native-review-cli.mjs +169 -17
- package/runtime/review-integration-v2.mjs +63 -4
- package/scripts/bootstrap.cmd +2 -2
- package/scripts/bootstrap.sh +41 -4
- package/scripts/build-full-delegation-card.mjs +179 -0
- package/scripts/build-runtime-modules.mjs +1 -0
- package/scripts/bundled-install.mjs +38 -8
- package/scripts/download-progress.mjs +68 -0
- package/scripts/gentle-ai-installer.mjs +41 -18
- package/scripts/gentle-ai-proxy.mjs +294 -0
- package/scripts/install-gentle-ai.mjs +14 -1
- package/scripts/installer-downloads.mjs +34 -8
- package/scripts/installer-preflight.mjs +33 -22
- package/scripts/installer-probes.mjs +25 -5
- package/scripts/installer-runner.mjs +27 -12
- package/scripts/installer-server.mjs +46 -16
- package/scripts/installer-windows.mjs +2 -2
- package/scripts/pi-update.mjs +166 -27
- package/scripts/prepare-verifier.mjs +107 -0
- package/scripts/render-cache-host.mjs +72 -0
- package/scripts/render-cache-performance-worker.mjs +5 -4
- package/scripts/render-cache-performance.mjs +6 -1
- package/scripts/run-test-suite.mjs +40 -28
- package/scripts/update-agent-body-history.mjs +55 -8
- package/scripts/verify-package-files.mjs +50 -19
- package/scripts/voice-worker.cjs +32 -6
- package/skills/branch-pr/SKILL.md +16 -16
- package/skills/comment-writer/SKILL.md +1 -1
- package/skills/design/SKILL.md +16 -13
- package/skills/gentle-ai/SKILL.md +7 -7
- package/skills/gentle-ui-design/SKILL.md +46 -0
- package/skills/gentle-ui-design/references/adaptive-interfaces.md +46 -0
- package/skills/gentle-ui-design/references/browse-and-compare.md +62 -0
- package/skills/gentle-ui-design/references/composition-and-feedback.md +56 -0
- package/skills/gentle-ui-design/references/task-and-content.md +60 -0
- 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 -11
- package/skills/tui-design/SKILL.md +1 -1
- package/skills/work-unit-commits/SKILL.md +10 -11
- package/tests/agent-home.test.ts +28 -9
- package/tests/agent-profiles-workflow.test.ts +163 -0
- package/tests/agent-prompt-diet-contract.test.ts +101 -0
- package/tests/agent-risk-escalation.test.ts +1 -1
- package/tests/agent-status.test.ts +143 -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 +106 -1
- package/tests/agents-history.test.ts +31 -0
- package/tests/agents-jobs-frames.test.ts +93 -0
- package/tests/agents-message-delivery.test.ts +36 -0
- package/tests/agents-prompt-lifecycle-runtime.test.ts +376 -0
- package/tests/agents-queries.test.ts +144 -4
- package/tests/agents-report-cap.test.ts +126 -0
- package/tests/agents-runner-drain.test.ts +193 -0
- package/tests/agents-runner.test.ts +215 -3
- 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 +12 -1
- package/tests/approved-text-leftovers-contract.test.ts +136 -0
- package/tests/artifact-language.test.ts +1 -1
- package/tests/ask-user-choice.test.ts +4 -3
- package/tests/ask-user-question.test.ts +99 -1
- package/tests/audit-leftovers-contract.test.ts +51 -0
- package/tests/auto-permission-runtime.test.ts +1 -1
- package/tests/autonomous-guard.test.ts +346 -10
- package/tests/bounded-stop-contract.test.ts +51 -3
- package/tests/branch-pr-skill.test.ts +10 -1
- package/tests/bridge-cost.test.ts +19 -4
- package/tests/bundled-install.test.ts +31 -6
- package/tests/card-content-policy.test.ts +3 -3
- package/tests/chained-pr-skill.test.ts +8 -6
- package/tests/child-context-files.test.ts +64 -8
- package/tests/child-safety.test.ts +11 -0
- package/tests/child-skills-catalog.test.ts +56 -0
- package/tests/codegraph-tools.test.ts +11 -5
- package/tests/codemode-rendering.test.ts +4 -1
- package/tests/command-palette.test.ts +284 -1
- package/tests/delegate-for-reason-contract.test.ts +32 -10
- 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 -695
- 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/destructive-command-guard.test.ts +52 -0
- package/tests/devbinary/pi-host-relay.devtest.ts +149 -80
- package/tests/devbinary/review-session-consent.devtest.ts +84 -0
- package/tests/download-progress.test.ts +71 -0
- package/tests/engram-safety.test.ts +111 -0
- package/tests/execution-surface-guard.test.ts +55 -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 +26 -31
- package/tests/fixtures/proxy-tls/proxy.crt +19 -0
- package/tests/fixtures/proxy-tls/proxy.key +28 -0
- package/tests/fixtures/refusal-identity.probe.mjs +139 -0
- package/tests/fixtures/session-profile-v1/gentle-ai-reviewer.ts +89 -0
- package/tests/fixtures/session-profile-v1/replay.ts +53 -6
- package/tests/full-delegation-closure.test.ts +160 -0
- package/tests/full-delegation-notices.test.ts +76 -0
- package/tests/generic-agent-tools.test.ts +3 -3
- package/tests/gentle-agent-status.test.ts +74 -0
- package/tests/gentle-agents-child-jobs.test.ts +237 -0
- package/tests/gentle-agents.test.ts +1403 -20
- package/tests/gentle-ai-binary.test.ts +3 -1
- package/tests/gentle-ai-child-guards.test.ts +1 -0
- package/tests/gentle-ai-elapsed-store.test.ts +19 -0
- package/tests/gentle-ai-exploration-budget.test.ts +18 -2
- package/tests/gentle-ai-installer.test.ts +135 -51
- package/tests/gentle-ai-proxy.test.ts +434 -0
- package/tests/gentle-ai-renderer.test.ts +36 -2
- package/tests/gentle-ai.test.ts +233 -43
- package/tests/gentle-design.test.ts +386 -1
- package/tests/gentle-herdr-activity.test.ts +9 -6
- package/tests/gentle-shell-bin.test.ts +123 -0
- package/tests/gentle-shell-bundled.test.ts +293 -31
- package/tests/gentle-shell-launcher.test.ts +78 -11
- package/tests/gentle-shell.test.ts +1017 -146
- package/tests/gentle-todo.test.ts +51 -11
- package/tests/gentle-tps.test.ts +123 -0
- package/tests/gentle-ui-design-skill.test.ts +59 -0
- package/tests/herdr-busy.test.ts +59 -0
- package/tests/herdr-task-summary-policy.test.ts +8 -4
- package/tests/hidden-tools.test.ts +188 -0
- package/tests/image-disk-cache.test.ts +163 -0
- package/tests/independent-recovery-delivery.test.ts +97 -0
- package/tests/inprocess-reviewer.test.ts +249 -4
- package/tests/install-wizard.test.ts +27 -1
- package/tests/installer-downloads.test.ts +30 -1
- package/tests/installer-posix-bootstrap.test.ts +115 -14
- package/tests/installer-preflight.test.ts +54 -5
- package/tests/installer-probes.test.ts +146 -0
- package/tests/installer-runner.test.ts +79 -44
- package/tests/installer-server.test.ts +215 -13
- package/tests/installer-windows-bootstrap.test.ts +19 -1
- package/tests/jobs-view.test.ts +260 -6
- 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/modal-mouse-boundaries.test.ts +136 -0
- package/tests/model-fallback-policy.test.ts +26 -7
- package/tests/model-routing-authority.test.ts +178 -2
- package/tests/nan-provider-runtime.test.ts +17 -3
- package/tests/nan-provider.test.ts +111 -56
- package/tests/native-choice-list.test.ts +77 -2
- package/tests/native-review-capability-contract.test.ts +17 -1
- package/tests/native-review-cli-nonblocking-findings.test.ts +165 -0
- package/tests/native-review-cli.test.ts +269 -1
- 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 +13 -2
- package/tests/odd-integration.test.ts +11 -3
- package/tests/odd-routing-canonical-ratchet.test.ts +3 -3
- package/tests/odd-routing-contract.test.ts +80 -28
- package/tests/orchestrator-budget.test.ts +35 -5
- package/tests/orchestrator-consultation-sdk.test.ts +32 -6
- package/tests/orchestrator-delegation-mode.test.ts +154 -0
- package/tests/orchestrator-discovery.test.ts +28 -0
- package/tests/orchestrator-mode-policy.test.ts +175 -0
- package/tests/orchestrator-prompt-budget.test.ts +13 -2
- package/tests/orchestrator-prompt-diet-contract.test.ts +221 -0
- package/tests/orchestrator-rdd-ownership.test.ts +4 -3
- package/tests/orchestrator-work-search.test.ts +4 -2
- package/tests/package-files.test.ts +25 -1
- package/tests/package-manifest.test.ts +16 -13
- package/tests/parallel-reason-contract.test.ts +6 -3
- package/tests/permission-allowlist.test.ts +372 -0
- 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 +25 -7
- package/tests/pi-update-source.test.ts +113 -6
- package/tests/pi-update.test.ts +294 -19
- package/tests/pnpm-workspace-config.test.ts +58 -0
- 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/primary-session-prompt.test.ts +13 -0
- package/tests/profile-pin.test.ts +29 -2
- package/tests/profile-tier-footer.test.ts +5 -0
- package/tests/profiles-panel-delegation-mode.test.ts +422 -0
- package/tests/provider-defect-handoff.test.ts +9 -2
- package/tests/questionnaire-view.test.ts +115 -0
- package/tests/quiet-bash-runtime.test.ts +1 -1
- package/tests/quiet-tool-rendering.test.ts +48 -0
- package/tests/rdd-aware-verification-contract.test.ts +17 -12
- package/tests/rdd-customize.test.ts +287 -0
- package/tests/rdd-mode-cache.test.ts +450 -0
- package/tests/rdd-mode-control.test.ts +407 -0
- package/tests/rdd-mode-scope-regression.test.ts +137 -0
- package/tests/rdd-off-independent-regression.test.ts +69 -0
- package/tests/rdd-status-line.test.ts +112 -1
- package/tests/render-cache-performance.test.ts +171 -2
- package/tests/reply-language-anchor-placement.test.ts +184 -0
- package/tests/reply-language-anchor.test.ts +189 -0
- 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 +80 -2
- package/tests/review-blocker.test.ts +193 -0
- package/tests/review-candidate-owner-retry.test.ts +1 -1
- package/tests/review-candidate-symlink-scan.test.ts +157 -0
- package/tests/review-candidate-view.test.ts +66 -1
- package/tests/review-candidate-windows-boundary.test.ts +131 -0
- package/tests/review-candidate-windows-probe.test.ts +63 -0
- package/tests/review-committed-restart-ack.test.ts +129 -0
- package/tests/review-continuation-registry.test.ts +107 -0
- package/tests/review-contract-prompt.test.ts +1 -1
- package/tests/review-controller-native-routing.test.ts +261 -5
- package/tests/review-controller-workspace-root.test.ts +230 -3
- package/tests/review-controller.test.ts +98 -12
- 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-runtime.test.ts +117 -0
- package/tests/review-coordinator.test.ts +462 -0
- 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-failure-facts.test.ts +87 -0
- package/tests/review-host-relay-routing.test.ts +258 -4
- package/tests/review-host-relay.test.ts +39 -0
- package/tests/review-integration-nonblocking-findings.test.ts +108 -0
- package/tests/review-integration-v2.test.ts +46 -3
- package/tests/review-json-arguments.test.ts +105 -11
- package/tests/review-last-event-closure.test.ts +68 -0
- package/tests/review-ledger-contract.test.ts +19 -40
- package/tests/review-loadout-rdd-off-sdk.test.ts +95 -32
- 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-owner-identity.test.ts +60 -24
- package/tests/review-relay-phase-timing.test.ts +128 -0
- package/tests/review-relay-transport-agent.test.ts +39 -2
- package/tests/review-reviewer-evidence.test.ts +223 -0
- package/tests/review-risk-assessment.test.ts +126 -8
- package/tests/review-run-statement-guidance-independent.test.ts +54 -0
- package/tests/review-session-standing-permission-controller.test.ts +53 -3
- package/tests/review-start-context.test.ts +19 -0
- package/tests/review-tool-prose-budget.test.ts +122 -0
- package/tests/reviewer-stream.test.ts +149 -0
- package/tests/run-test-suite.test.ts +122 -1
- package/tests/runtime-harness.mjs +4 -1
- package/tests/sensitive-path-tools.test.ts +181 -5
- package/tests/session-profile-append-controller-pi.test.ts +60 -31
- package/tests/session-profile-binding.test.ts +19 -1
- package/tests/session-profile-disk-reader-pi.test.ts +58 -16
- package/tests/session-profile-extension.test.ts +2 -2
- package/tests/session-profile-v1-compat.test.ts +35 -1
- package/tests/shell-bar.test.ts +186 -42
- package/tests/shell-panel.test.ts +50 -22
- package/tests/shell-prompt.test.ts +17 -0
- package/tests/shell-sidebar-fullscreen.test.ts +5 -5
- package/tests/shell-sidebar-layout.test.ts +294 -23
- package/tests/shell-sidebar-scroll-benchmark.test.ts +1 -1
- package/tests/shell-surface-transparent.test.ts +89 -0
- package/tests/shell-todo.test.ts +12 -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 +1461 -5
- package/tests/startup-banner.test.ts +152 -1
- package/tests/startup-home-repo.test.ts +2 -0
- package/tests/support/design-canvas-dom.ts +369 -0
- package/tests/support/review-coordinator-runtime.ts +264 -0
- package/tests/task-size-routing-contract.test.ts +45 -12
- 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-admission.test.ts +49 -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 +162 -11
- package/tests/vim-editor-adapter.test.ts +2 -2
- package/tests/visual-customization-policy.test.ts +39 -6
- package/tests/visual-customize-view.test.ts +573 -9
- package/tests/visual-layout-preview.test.ts +15 -1
- package/tests/visual-profiles.test.ts +11 -0
- package/tests/voice-worker.test.ts +73 -2
- package/tests/windows-session-transport.test.ts +126 -0
- package/tests/work-continuity-contract.test.ts +77 -6
- 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 +276 -0
- package/tests/yolo-customize.test.ts +27 -4
- package/tests/yolo-mode.test.ts +62 -18
- package/tests/yolo-session-policy.test.ts +270 -1
- 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,310 @@
|
|
|
1
|
+
// Gentle Desktop subscription-usage bridge: reaches the existing usage owner
|
|
2
|
+
// (UsageStore / UsageSourceRegistry / refreshUsage / after_provider_response
|
|
3
|
+
// closures inside `extensions/gentle-shell.ts`) through a defensive, versioned
|
|
4
|
+
// owner-service event/adapter — the usage analogue of the YOLO
|
|
5
|
+
// `discoverYoloUiAdapter` seam. It never fetches, resolves auth, or keeps a
|
|
6
|
+
// second store: every read and every refresh is the owner's own answer, shaped
|
|
7
|
+
// into the Desktop RPC contract by `lib/desktop-rpc-usage.ts`.
|
|
8
|
+
|
|
9
|
+
import type { ExtensionAPI, ExtensionContext } from "@earendil-works/pi-coding-agent";
|
|
10
|
+
import {
|
|
11
|
+
DESKTOP_USAGE_EVENT,
|
|
12
|
+
DESKTOP_USAGE_SERVICE_CHANNEL,
|
|
13
|
+
DESKTOP_USAGE_STALE_MS,
|
|
14
|
+
desktopUsageStatus,
|
|
15
|
+
isDesktopUsageServiceShape,
|
|
16
|
+
parseDesktopUsageOwnerEntry,
|
|
17
|
+
parseUsageProviderParam,
|
|
18
|
+
projectUsageEntry,
|
|
19
|
+
USAGE_UNAVAILABLE,
|
|
20
|
+
type DesktopUsageEntry,
|
|
21
|
+
type DesktopUsageOwnerEntry,
|
|
22
|
+
type DesktopUsageOwnerRead,
|
|
23
|
+
type DesktopUsageRecordedSnapshot,
|
|
24
|
+
type DesktopUsageService,
|
|
25
|
+
type DesktopRateLimitEvent,
|
|
26
|
+
} from "./desktop-rpc-usage.ts";
|
|
27
|
+
import type { DesktopRpcOutcome } from "./desktop-rpc.ts";
|
|
28
|
+
import { parseProviderUsage, type ProviderUsage } from "./shell-usage.ts";
|
|
29
|
+
|
|
30
|
+
const DISCOVERY_TIMEOUT_MS = 100;
|
|
31
|
+
|
|
32
|
+
/** A content identity that deliberately excludes `fetchedAt`: a snapshot that
|
|
33
|
+
* changed its payload within the same millisecond still differs, while
|
|
34
|
+
* byte-equivalent data — whatever timestamp the owner stamped on it — is a
|
|
35
|
+
* no-op. The objects are freshly rebuilt by `parseProviderUsage`, so their key
|
|
36
|
+
* order is fixed and the JSON is stable for equivalent content. */
|
|
37
|
+
function usageContentKey(usage: ProviderUsage): string {
|
|
38
|
+
return JSON.stringify({ provider: usage.provider, plan: usage.plan, limits: usage.limits });
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
interface HostUiUsageRequest { context: ExtensionContext; respond(service: DesktopUsageService): void }
|
|
42
|
+
|
|
43
|
+
/** Discover the live usage owner exactly like the YOLO seam: emit a bounded,
|
|
44
|
+
* versioned request and accept only an adapter-shaped responder. */
|
|
45
|
+
export function discoverDesktopUsageService(pi: ExtensionAPI, context: ExtensionContext): Promise<DesktopUsageService | undefined> {
|
|
46
|
+
return new Promise((resolve) => {
|
|
47
|
+
let settled = false;
|
|
48
|
+
const timer = setTimeout(() => { settled = true; resolve(undefined); }, DISCOVERY_TIMEOUT_MS);
|
|
49
|
+
const respond = (value: unknown) => {
|
|
50
|
+
if (!isDesktopUsageServiceShape(value)) return;
|
|
51
|
+
if (settled) { value.dispose(); return; }
|
|
52
|
+
settled = true; clearTimeout(timer); resolve(value);
|
|
53
|
+
};
|
|
54
|
+
try {
|
|
55
|
+
pi.events.emit(DESKTOP_USAGE_SERVICE_CHANNEL, { context, respond } satisfies HostUiUsageRequest);
|
|
56
|
+
} catch {
|
|
57
|
+
settled = true; clearTimeout(timer); resolve(undefined);
|
|
58
|
+
}
|
|
59
|
+
});
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
type Emit = (event: string, data: Record<string, unknown>) => void;
|
|
63
|
+
|
|
64
|
+
interface DesktopUsageBridgeOptions {
|
|
65
|
+
discover?: typeof discoverDesktopUsageService;
|
|
66
|
+
now?: () => number;
|
|
67
|
+
staleAfterMs?: number;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
/**
|
|
71
|
+
* The Desktop domain slice for `get_subscription_usage` and
|
|
72
|
+
* `refresh_subscription_usage`. It is wired to the router's `emit` so header-
|
|
73
|
+
* driven snapshots become `rate_limit` events, and it owns the session-scoped
|
|
74
|
+
* lifecycle: a reset (session replacement or shutdown) disconnects the owner
|
|
75
|
+
* observer and drops stale async outcomes.
|
|
76
|
+
*/
|
|
77
|
+
export class DesktopUsageBridge {
|
|
78
|
+
private readonly pi: ExtensionAPI;
|
|
79
|
+
private readonly discover: typeof discoverDesktopUsageService;
|
|
80
|
+
private readonly now: () => number;
|
|
81
|
+
private readonly staleAfterMs: number;
|
|
82
|
+
private host: ExtensionContext | undefined;
|
|
83
|
+
private service: DesktopUsageService | undefined;
|
|
84
|
+
private discovering: Promise<DesktopUsageService | undefined> | undefined;
|
|
85
|
+
private generation = 0;
|
|
86
|
+
private observeDispose: (() => void) | undefined;
|
|
87
|
+
private observeGeneration = 0;
|
|
88
|
+
private emit: Emit | undefined;
|
|
89
|
+
|
|
90
|
+
constructor(pi: ExtensionAPI, options: DesktopUsageBridgeOptions = {}) {
|
|
91
|
+
this.pi = pi;
|
|
92
|
+
this.discover = options.discover ?? discoverDesktopUsageService;
|
|
93
|
+
this.now = options.now ?? (() => Date.now());
|
|
94
|
+
this.staleAfterMs = options.staleAfterMs ?? DESKTOP_USAGE_STALE_MS;
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
/** The live interactive context of this Desktop session; bound per command. */
|
|
98
|
+
attach(context: ExtensionContext): void {
|
|
99
|
+
this.host = context;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
/** Route header-driven `rate_limit` events through the router's sequencer. */
|
|
103
|
+
wire(emit: Emit): void {
|
|
104
|
+
this.emit = emit;
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
/** Session start/shutdown: the owner adapter of a previous session is invalid. */
|
|
108
|
+
reset(): void {
|
|
109
|
+
this.generation += 1;
|
|
110
|
+
this.observeDispose?.();
|
|
111
|
+
this.observeDispose = undefined;
|
|
112
|
+
const service = this.service;
|
|
113
|
+
this.service = undefined;
|
|
114
|
+
this.discovering = undefined;
|
|
115
|
+
this.host = undefined;
|
|
116
|
+
this.emit = undefined;
|
|
117
|
+
try {
|
|
118
|
+
service?.dispose();
|
|
119
|
+
} catch {
|
|
120
|
+
/* display-only owner teardown */
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
async handle(method: string, params: Record<string, unknown>): Promise<DesktopRpcOutcome | undefined> {
|
|
125
|
+
if (method !== "get_subscription_usage" && method !== "refresh_subscription_usage") return undefined;
|
|
126
|
+
const host = this.host;
|
|
127
|
+
if (!host) return { ok: false, error: USAGE_UNAVAILABLE };
|
|
128
|
+
const generation = this.generation;
|
|
129
|
+
const service = await this.owner(host);
|
|
130
|
+
if (generation !== this.generation || !service) return { ok: false, error: USAGE_UNAVAILABLE };
|
|
131
|
+
if (method === "get_subscription_usage") return this.read(service, params);
|
|
132
|
+
return this.refresh(service, params, generation);
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
private async owner(context: ExtensionContext): Promise<DesktopUsageService | undefined> {
|
|
136
|
+
if (this.service) return this.service;
|
|
137
|
+
if (!this.discovering) {
|
|
138
|
+
const generation = this.generation;
|
|
139
|
+
const discovering = Promise.resolve()
|
|
140
|
+
.then(() => this.discover(this.pi, context))
|
|
141
|
+
.then((service) => {
|
|
142
|
+
// A reset/replacement happened while discovery was in flight: the
|
|
143
|
+
// late adapter belongs to a superseded session. Dispose it and never
|
|
144
|
+
// cache or re-subscribe it for the next session.
|
|
145
|
+
if (generation !== this.generation || !service) {
|
|
146
|
+
try { service?.dispose(); } catch { /* owner teardown */ }
|
|
147
|
+
return undefined;
|
|
148
|
+
}
|
|
149
|
+
this.service = service;
|
|
150
|
+
this.subscribe(service);
|
|
151
|
+
return service;
|
|
152
|
+
})
|
|
153
|
+
.catch(() => undefined)
|
|
154
|
+
.finally(() => {
|
|
155
|
+
if (this.discovering === discovering) this.discovering = undefined;
|
|
156
|
+
});
|
|
157
|
+
this.discovering = discovering;
|
|
158
|
+
}
|
|
159
|
+
return this.discovering;
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
private subscribe(service: DesktopUsageService): void {
|
|
163
|
+
this.observeGeneration = this.generation;
|
|
164
|
+
try {
|
|
165
|
+
this.observeDispose = service.observe((recorded) => this.onRecorded(recorded));
|
|
166
|
+
} catch {
|
|
167
|
+
this.observeDispose = undefined;
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
/** Header-driven recording: the owner already parsed the headers. */
|
|
172
|
+
private onRecorded(recorded: DesktopUsageRecordedSnapshot): void {
|
|
173
|
+
if (this.observeGeneration !== this.generation) return;
|
|
174
|
+
const emit = this.emit;
|
|
175
|
+
if (!emit) return;
|
|
176
|
+
const usage = this.validatedSnapshot(recorded);
|
|
177
|
+
if (!usage) return;
|
|
178
|
+
// A response-carried snapshot is fresh by definition; it is never
|
|
179
|
+
// refreshed, so the status is always `ok` here.
|
|
180
|
+
const entry = projectUsageEntry(recorded.provider, "ok", usage);
|
|
181
|
+
emit(DESKTOP_USAGE_EVENT, { source: "response", snapshots: [entry] } satisfies DesktopRateLimitEvent);
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
/** The owner's snapshot crosses the event bus: re-validate before projecting. */
|
|
185
|
+
private validatedSnapshot(recorded: DesktopUsageRecordedSnapshot): ProviderUsage | undefined {
|
|
186
|
+
if (!recorded || typeof recorded !== "object") return undefined;
|
|
187
|
+
if (typeof recorded.provider !== "string") return undefined;
|
|
188
|
+
return parseProviderUsage(recorded.usage, recorded.provider);
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
private read(service: DesktopUsageService, params: Record<string, unknown>): DesktopRpcOutcome {
|
|
192
|
+
const parsed = parseUsageProviderParam(params);
|
|
193
|
+
if ("error" in parsed) return { ok: false, error: parsed.error };
|
|
194
|
+
const providers = this.projectRead(service, parsed.provider, undefined, false);
|
|
195
|
+
return { ok: true, data: { providers } as unknown as Record<string, unknown> };
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
private async refresh(service: DesktopUsageService, params: Record<string, unknown>, generation: number): Promise<DesktopRpcOutcome> {
|
|
199
|
+
const parsed = parseUsageProviderParam(params);
|
|
200
|
+
if ("error" in parsed) return { ok: false, error: parsed.error };
|
|
201
|
+
const provider = parsed.provider;
|
|
202
|
+
const before = this.readOwner(service, provider);
|
|
203
|
+
let after: DesktopUsageOwnerRead;
|
|
204
|
+
try {
|
|
205
|
+
// The owner's refresh result crosses the event bus, so it is re-validated
|
|
206
|
+
// before anything is projected or diffed.
|
|
207
|
+
after = this.parseOwnerRead(await service.refresh(provider));
|
|
208
|
+
} catch {
|
|
209
|
+
// Raw owner failures carry endpoint/key detail; none of it crosses the
|
|
210
|
+
// contract. Fall back to the current owner state (which still reports a
|
|
211
|
+
// truthful pending/failed) and never fabricate a snapshot.
|
|
212
|
+
after = this.readOwner(service, provider);
|
|
213
|
+
}
|
|
214
|
+
if (generation !== this.generation) return { ok: false, error: USAGE_UNAVAILABLE };
|
|
215
|
+
const providers = this.projectRead(service, provider, after, true);
|
|
216
|
+
// Exactly one rate_limit event per response, carrying every snapshot this
|
|
217
|
+
// refresh actually changed. A no-op (unsupported, throttled, or failed)
|
|
218
|
+
// refresh changes nothing and therefore emits no duplicate event.
|
|
219
|
+
const snapshots = this.changedSnapshots(before, after);
|
|
220
|
+
const data = { providers } as unknown as Record<string, unknown>;
|
|
221
|
+
if (snapshots.length === 0) return { ok: true, data };
|
|
222
|
+
return {
|
|
223
|
+
ok: true,
|
|
224
|
+
data,
|
|
225
|
+
event: {
|
|
226
|
+
name: DESKTOP_USAGE_EVENT,
|
|
227
|
+
data: { source: "refresh", snapshots } satisfies DesktopRateLimitEvent,
|
|
228
|
+
},
|
|
229
|
+
};
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
private parseOwnerRead(value: unknown): DesktopUsageOwnerRead {
|
|
233
|
+
if (!value || typeof value !== "object") return { providers: [] };
|
|
234
|
+
const raw = value as { providers?: unknown };
|
|
235
|
+
if (!Array.isArray(raw.providers)) return { providers: [] };
|
|
236
|
+
return {
|
|
237
|
+
providers: raw.providers
|
|
238
|
+
.map((entry) => parseDesktopUsageOwnerEntry(entry))
|
|
239
|
+
.filter((entry): entry is NonNullable<typeof entry> => entry !== undefined),
|
|
240
|
+
};
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
private readOwner(service: DesktopUsageService, provider: string | undefined): DesktopUsageOwnerRead {
|
|
244
|
+
try {
|
|
245
|
+
return this.parseOwnerRead(service.read(provider));
|
|
246
|
+
} catch {
|
|
247
|
+
return { providers: [] };
|
|
248
|
+
}
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
private projectRead(
|
|
252
|
+
service: DesktopUsageService,
|
|
253
|
+
provider: string | undefined,
|
|
254
|
+
read: DesktopUsageOwnerRead | undefined,
|
|
255
|
+
markRefreshDisposition: boolean,
|
|
256
|
+
): DesktopUsageEntry[] {
|
|
257
|
+
const owners = read ?? this.readOwner(service, provider);
|
|
258
|
+
const now = this.now();
|
|
259
|
+
return owners.providers.map((owner) => {
|
|
260
|
+
const snapshot = owner.snapshot === undefined ? undefined : parseProviderUsage(owner.snapshot, owner.provider);
|
|
261
|
+
const status = desktopUsageStatus({
|
|
262
|
+
supported: owner.supported,
|
|
263
|
+
refreshable: owner.refreshable,
|
|
264
|
+
failed: owner.failed,
|
|
265
|
+
fetchedAt: snapshot?.fetchedAt,
|
|
266
|
+
now,
|
|
267
|
+
staleAfterMs: this.staleAfterMs,
|
|
268
|
+
});
|
|
269
|
+
return projectUsageEntry(owner.provider, status, snapshot, {
|
|
270
|
+
refresh: markRefreshDisposition ? this.refreshDisposition(owner) : undefined,
|
|
271
|
+
});
|
|
272
|
+
});
|
|
273
|
+
}
|
|
274
|
+
|
|
275
|
+
/** The typed no-op marker a refresh answer reports, in precedence order. */
|
|
276
|
+
private refreshDisposition(owner: DesktopUsageOwnerEntry): "unsupported" | "out_of_scope" | undefined {
|
|
277
|
+
// The owner said it never even attempted the fetch: the provider is outside
|
|
278
|
+
// the current session scope. This wins for a refreshable provider so a
|
|
279
|
+
// client can tell an out-of-scope no-op from a supported-but-header-only one.
|
|
280
|
+
if (owner.outOfScope === true && owner.refreshable) return "out_of_scope";
|
|
281
|
+
if (owner.supported && !owner.refreshable) return "unsupported";
|
|
282
|
+
return undefined;
|
|
283
|
+
}
|
|
284
|
+
|
|
285
|
+
private changedSnapshots(before: DesktopUsageOwnerRead, after: DesktopUsageOwnerRead): DesktopUsageEntry[] {
|
|
286
|
+
const beforeByProvider = new Map(before.providers.map((entry) => [entry.provider, entry]));
|
|
287
|
+
const changed: DesktopUsageEntry[] = [];
|
|
288
|
+
for (const entry of after.providers) {
|
|
289
|
+
const previous = beforeByProvider.get(entry.provider);
|
|
290
|
+
const afterSnapshot = entry.snapshot === undefined ? undefined : parseProviderUsage(entry.snapshot, entry.provider);
|
|
291
|
+
const beforeSnapshot = previous?.snapshot === undefined ? undefined : parseProviderUsage(previous.snapshot, entry.provider);
|
|
292
|
+
// Compare the actual snapshot content, not only `fetchedAt`: a payload
|
|
293
|
+
// that changed within the same millisecond still emits, while byte-equivalent
|
|
294
|
+
// data (whatever its timestamp) stays a no-op. A failure (still no snapshot)
|
|
295
|
+
// is not a change.
|
|
296
|
+
if (afterSnapshot && usageContentKey(afterSnapshot) !== (beforeSnapshot ? usageContentKey(beforeSnapshot) : undefined)) {
|
|
297
|
+
const status = desktopUsageStatus({
|
|
298
|
+
supported: entry.supported,
|
|
299
|
+
refreshable: entry.refreshable,
|
|
300
|
+
failed: entry.failed,
|
|
301
|
+
fetchedAt: afterSnapshot.fetchedAt,
|
|
302
|
+
now: this.now(),
|
|
303
|
+
staleAfterMs: this.staleAfterMs,
|
|
304
|
+
});
|
|
305
|
+
changed.push(projectUsageEntry(entry.provider, status, afterSnapshot));
|
|
306
|
+
}
|
|
307
|
+
}
|
|
308
|
+
return changed;
|
|
309
|
+
}
|
|
310
|
+
}
|
|
@@ -17,6 +17,7 @@ interface Token {
|
|
|
17
17
|
raw: string;
|
|
18
18
|
operator: boolean;
|
|
19
19
|
index: number;
|
|
20
|
+
redirect?: "target";
|
|
20
21
|
}
|
|
21
22
|
const separators = new Set([";", "&&", "||", "|", "&", "\n", "(", ")"]);
|
|
22
23
|
// Separators after which the next segment starts only once this one finished.
|
|
@@ -25,35 +26,206 @@ const separators = new Set([";", "&&", "||", "|", "&", "\n", "(", ")"]);
|
|
|
25
26
|
const SEQUENTIAL_SEPARATORS = new Set(["", ";", "&&", "||", "\n"]);
|
|
26
27
|
|
|
27
28
|
/** Literal, named heredocs are data, not executable shell segments; offsets are preserved. */
|
|
28
|
-
function blankHeredocs(command: string): string {
|
|
29
|
+
function blankHeredocs(command: string, joinBody = false): string {
|
|
29
30
|
return command.replace(/<<-?\s*(['"]?)([A-Za-z_]\w*)\1[^\n]*\n[\s\S]*?\n\2(?=\n|$)/g, (raw) => {
|
|
30
|
-
const headerLength = raw.indexOf("\n") + 1;
|
|
31
|
+
const headerLength = raw.indexOf("\n") + (joinBody ? 0 : 1);
|
|
31
32
|
return raw.slice(0, headerLength) + " ".repeat(raw.length - headerLength);
|
|
32
33
|
});
|
|
33
34
|
}
|
|
34
35
|
|
|
36
|
+
const deliveryTokenPattern = /(?:\\\n)*#[^\n]*|(?:\d*(?:[<>]&|>\||<>|>>?|<<-?)|&>>?)|(?:"(?:\\[\s\S]|[^"\\])*"|'[^']*'|`(?:\\[\s\S]|[^`\\])*`|\\[\s\S]|[^\s;&|()<>'"\\])+|&&|\|\||[;&|()\n]/g;
|
|
37
|
+
|
|
35
38
|
/** Keep quoted arguments intact so harmless prose is never treated as a command. */
|
|
36
|
-
function tokenize(command: string, blank = true): Token[] {
|
|
39
|
+
function tokenize(command: string, blank = true, delivery = false): Token[] {
|
|
37
40
|
const tokens: Token[] = [];
|
|
38
|
-
if (blank) command = blankHeredocs(command);
|
|
39
|
-
|
|
41
|
+
if (blank) command = blankHeredocs(command, delivery);
|
|
42
|
+
// Delivery routing needs redirections as separate tokens, including attached
|
|
43
|
+
// forms (`push>out`) and descriptor merges whose & is not a shell boundary.
|
|
44
|
+
const pattern = delivery
|
|
45
|
+
? deliveryTokenPattern
|
|
46
|
+
: /(?:"(?:\\.|[^"\\])*"|'[^']*'|\\.|[^\s;&|()'"\\])+|&&|\|\||[;&|()\n]/g;
|
|
40
47
|
for (const match of command.matchAll(pattern)) {
|
|
41
48
|
const raw = match[0];
|
|
42
|
-
|
|
49
|
+
if (delivery && /^(?:\\\n)*#/.test(raw)) continue;
|
|
50
|
+
const wordPattern = delivery
|
|
51
|
+
? /"((?:\\[\s\S]|[^"\\])*)"|'([^']*)'|\\([\s\S])/g
|
|
52
|
+
: /"((?:\\.|[^"\\])*)"|'([^']*)'|\\(.)/g;
|
|
53
|
+
const value = raw.replace(wordPattern,
|
|
43
54
|
(_raw, double: string | undefined, single: string | undefined, escaped: string | undefined) => {
|
|
44
55
|
if (double !== undefined) return double.replace(/\\(["\\$`\n])/g, (_escape, char: string) => char === "\n" ? "" : char);
|
|
45
|
-
return single ?? escaped ?? "";
|
|
56
|
+
return single ?? (delivery && escaped === "\n" ? "" : escaped) ?? "";
|
|
46
57
|
});
|
|
58
|
+
if (delivery && !value && /^(?:\\\n)+$/.test(raw)) continue;
|
|
47
59
|
// Only raw operators are boundaries; quoted/escaped operators are words.
|
|
48
|
-
|
|
60
|
+
// Consume the whole operand as one word: >&1--dry-run is a filename,
|
|
61
|
+
// never descriptor 1 followed by a git option.
|
|
62
|
+
const redirect = delivery && /^(?:\d*(?:[<>]&|>\||<>|>>?|<<-?)|&>>?)$/.test(raw) ? "target" : undefined;
|
|
63
|
+
tokens.push({ value, raw, operator: separators.has(raw), index: match.index, ...(redirect ? { redirect } : {}) });
|
|
49
64
|
}
|
|
50
65
|
return tokens;
|
|
51
66
|
}
|
|
52
67
|
const executable = (value: string) => value.split("/").at(-1) ?? value;
|
|
53
68
|
|
|
69
|
+
/** `&` schedules its whole and/or list, including a closed compound command. */
|
|
70
|
+
function deliveryCommandScopes(tokens: readonly Token[], substitutions: readonly { index: number; end: number }[]): { background: Array<readonly [number, number]>; subshells: Array<readonly [number, number]> } {
|
|
71
|
+
const ranges: Array<readonly [number, number]> = [];
|
|
72
|
+
const subshells: Array<readonly [number, number]> = [];
|
|
73
|
+
const scopes = [{ start: 0, close: "", opening: -1 }];
|
|
74
|
+
const compoundEnds: Record<string, string> = { if: "fi", while: "done", until: "done", for: "done", select: "done", case: "esac", "{": "}" };
|
|
75
|
+
let commandHead = true;
|
|
76
|
+
let continuation = false;
|
|
77
|
+
for (const token of tokens) {
|
|
78
|
+
if (substitutions.some(body => token.index >= body.index && token.index < body.end)) continue;
|
|
79
|
+
if (token.operator && token.raw === "(") { scopes.push({ start: token.index + 1, close: ")", opening: token.index }); commandHead = true; continue; }
|
|
80
|
+
if ((token.operator && token.raw === ")") || (commandHead && token.raw === token.value && token.raw === scopes.at(-1)!.close)) {
|
|
81
|
+
if (scopes.length > 1 && scopes.at(-1)!.close === token.raw) {
|
|
82
|
+
const closed = scopes.pop()!;
|
|
83
|
+
if (closed.opening >= 0) subshells.push([closed.opening, token.index + 1]);
|
|
84
|
+
}
|
|
85
|
+
commandHead = false;
|
|
86
|
+
continue;
|
|
87
|
+
}
|
|
88
|
+
if (token.operator) {
|
|
89
|
+
const scope = scopes.at(-1)!;
|
|
90
|
+
if (token.raw === "&") ranges.push([scope.start, token.index]);
|
|
91
|
+
if (["&", ";", "\n"].includes(token.raw) && !(token.raw === "\n" && continuation)) scope.start = token.index + token.raw.length;
|
|
92
|
+
if (token.raw !== "\n") continuation = ["&&", "||", "|"].includes(token.raw);
|
|
93
|
+
commandHead = true;
|
|
94
|
+
continue;
|
|
95
|
+
}
|
|
96
|
+
continuation = false;
|
|
97
|
+
if (commandHead && token.raw === token.value) {
|
|
98
|
+
const close = compoundEnds[token.raw];
|
|
99
|
+
if (close) scopes.push({ start: token.index, close, opening: -1 });
|
|
100
|
+
if (["if", "while", "until", "then", "else", "elif", "do", "{", "!"].includes(token.raw)) continue;
|
|
101
|
+
}
|
|
102
|
+
commandHead = false;
|
|
103
|
+
}
|
|
104
|
+
for (const scope of scopes) if (scope.opening >= 0) subshells.push([scope.opening, Number.POSITIVE_INFINITY]);
|
|
105
|
+
return { background: ranges, subshells };
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
/** Delivery and candidate changes share the guard's existing command-position rules. */
|
|
109
|
+
export function recognizeReviewDeliveryActions(command: string, depth = 0): Array<{ kind: "change" | "delivery"; directories?: readonly string[]; unresolvedDirectory?: true; background?: true }> {
|
|
110
|
+
return collectReviewDeliveryActions(command, depth);
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
function collectReviewDeliveryActions(command: string, depth: number, onRoutingExport?: () => void): ReturnType<typeof recognizeReviewDeliveryActions> {
|
|
114
|
+
if (depth > 8) return [];
|
|
115
|
+
// Preserve offsets while removing comment data from every delivery scan,
|
|
116
|
+
// including the secondary command-substitution and backtick scans.
|
|
117
|
+
command = blankHeredocs(command, true).replace(deliveryTokenPattern, raw => /^(?:\\\n)*#/.test(raw) ? " ".repeat(raw.length) : raw);
|
|
118
|
+
const matches: ReturnType<typeof recognizeReviewDeliveryActions> = [];
|
|
119
|
+
const tokens = tokenize(command, true, true);
|
|
120
|
+
const backticks = backtickBodies(command);
|
|
121
|
+
const scopes = deliveryCommandScopes(tokens, backticks);
|
|
122
|
+
const isBackground = (index: number) => scopes.background.some(([from, to]) => index >= from && index < to);
|
|
123
|
+
const childScopes = [...scopes.subshells, ...scopes.background, ...backticks.map(body => [body.index, body.end] as const)];
|
|
124
|
+
const exports: Array<{ index: number; children: Array<readonly [number, number]> }> = [];
|
|
125
|
+
const routingUnknown = (index: number) => exports.some(entry => entry.index <= index && entry.children.every(([from, to]) => index >= from && index < to));
|
|
126
|
+
const recordRoutingExport = (index: number) => {
|
|
127
|
+
const children = childScopes.filter(([from, to]) => index >= from && index < to);
|
|
128
|
+
exports.push({ index, children });
|
|
129
|
+
if (!children.length) onRoutingExport?.();
|
|
130
|
+
};
|
|
131
|
+
const directories: string[] = [];
|
|
132
|
+
const contexts: Array<{ from: number; to: number; unresolved: boolean; directories: string[] }> = [];
|
|
133
|
+
let unresolvedDirectory = false;
|
|
134
|
+
let leadingCdChain = true;
|
|
135
|
+
const ambiguousCdScope = tokens.some(token => token.operator && !["&&", "||", "|"].includes(token.raw));
|
|
136
|
+
let start = 0;
|
|
137
|
+
for (let end = 0; end <= tokens.length; end++) {
|
|
138
|
+
if (end < tokens.length && !tokens[end].operator) continue;
|
|
139
|
+
const preceding = tokens[start - 1]?.raw;
|
|
140
|
+
// A fallback may execute after cd itself failed. Never carry its selected
|
|
141
|
+
// directory into a later delivery, even though the earlier push was scoped.
|
|
142
|
+
if (tokens[start - 1]?.raw === "||" && directories.length) unresolvedDirectory = true;
|
|
143
|
+
const words = tokens.slice(start, end);
|
|
144
|
+
const from = tokens[start]?.index ?? command.length;
|
|
145
|
+
const segment = words.filter((token, at) => !token.redirect && words[at - 1]?.redirect !== "target");
|
|
146
|
+
start = end + 1;
|
|
147
|
+
let unresolvedPrefix = false;
|
|
148
|
+
const cursor = headCursor(segment, () => { unresolvedPrefix = true; });
|
|
149
|
+
const name = executable(segment[cursor]?.value ?? "").replace(/\.exe$/i, "");
|
|
150
|
+
const args = segment.slice(cursor + 1).map(token => token.value);
|
|
151
|
+
// A persistent export may change the later Git target; never borrow the cwd's mode.
|
|
152
|
+
if (name === "export" && args.some(arg => /^GIT_(?:DIR|WORK_TREE|COMMON_DIR|NAMESPACE)(?:=|$)/.test(arg))) recordRoutingExport(segment[cursor].index);
|
|
153
|
+
let index = 0;
|
|
154
|
+
const gitDirectories: string[] = [];
|
|
155
|
+
let unresolvedGitDirectory = false;
|
|
156
|
+
if (name === "cd") {
|
|
157
|
+
if (leadingCdChain && !ambiguousCdScope && (preceding === undefined || preceding === "&&") && cursor === 0 && tokens[end]?.raw === "&&" &&
|
|
158
|
+
args.length === 1 && !/[\n\r$`~]/.test(args[0]) && !args[0].startsWith("-")) directories.push(args[0]);
|
|
159
|
+
else unresolvedDirectory = true;
|
|
160
|
+
}
|
|
161
|
+
if (name === "pushd" || name === "popd") unresolvedDirectory = true;
|
|
162
|
+
if (segment.length && name !== "cd") leadingCdChain = false;
|
|
163
|
+
contexts.push({ from, to: tokens[end]?.index ?? command.length, unresolved: unresolvedDirectory || unresolvedPrefix, directories: [...directories] });
|
|
164
|
+
while (name === "git" && index < args.length && args[index].startsWith("-")) {
|
|
165
|
+
if (args[index] === "-C") {
|
|
166
|
+
if (!args[index + 1] || /[\n\r$`~]/.test(args[index + 1])) unresolvedGitDirectory = true;
|
|
167
|
+
else gitDirectories.push(args[index + 1]);
|
|
168
|
+
index += 2;
|
|
169
|
+
}
|
|
170
|
+
else if (args[index].startsWith("-C") && args[index].length > 2) {
|
|
171
|
+
const directory = args[index++].slice(2);
|
|
172
|
+
if (/[\n\r$`~]/.test(directory)) unresolvedGitDirectory = true;
|
|
173
|
+
else gitDirectories.push(directory);
|
|
174
|
+
}
|
|
175
|
+
else if (args[index] === "-c") index += 2;
|
|
176
|
+
else if (["--git-dir", "--work-tree", "--namespace"].includes(args[index])) { unresolvedGitDirectory = true; index += 2; }
|
|
177
|
+
else if (/^--(?:git-dir|work-tree|namespace)=/.test(args[index])) { unresolvedGitDirectory = true; index++; }
|
|
178
|
+
else index++;
|
|
179
|
+
}
|
|
180
|
+
while (name === "gh" && index < args.length && args[index].startsWith("-")) {
|
|
181
|
+
index += ["-R", "--repo"].includes(args[index]) ? 2 : 1;
|
|
182
|
+
}
|
|
183
|
+
if (name === "git" && args[index] === "push" && args.slice(index + 1).some(arg => ["--dry-run", "-n", "--delete", "-d"].includes(arg))) continue;
|
|
184
|
+
if (name === "git" && ["commit", "merge", "rebase", "reset", "checkout", "switch", "cherry-pick", "revert", "am", "pull", "update-ref"].includes(args[index])) matches.push({ kind: "change" });
|
|
185
|
+
if ((name === "git" && args[index] === "push") || (name === "gh" && args[index] === "pr" && ["create", "merge"].includes(args[index + 1]))) {
|
|
186
|
+
matches.push({ kind: "delivery",
|
|
187
|
+
...(isBackground(segment[cursor].index) ? { background: true as const } : {}),
|
|
188
|
+
...(unresolvedDirectory || unresolvedGitDirectory || unresolvedPrefix || routingUnknown(segment[cursor].index) ? { unresolvedDirectory: true as const } : {}),
|
|
189
|
+
...(!directories.length && !gitDirectories.length ? {} : { directories: [...directories, ...gitDirectories] }) });
|
|
190
|
+
}
|
|
191
|
+
if (["sh", "bash", "zsh", "dash", "eval"].includes(name)) {
|
|
192
|
+
const flag = args.findIndex(arg => /^-[a-z]*c[a-z]*$/.test(arg));
|
|
193
|
+
const payload = name === "eval" ? (args[0] === "--" ? args.slice(1) : args).join(" ") : flag >= 0 ? args[flag + 1] : undefined;
|
|
194
|
+
if (payload) {
|
|
195
|
+
const inheritedUnknown = unresolvedDirectory || unresolvedPrefix || routingUnknown(segment[cursor].index);
|
|
196
|
+
const nested = collectReviewDeliveryActions(payload, depth + 1, name === "eval" ? () => recordRoutingExport(segment[cursor].index) : undefined);
|
|
197
|
+
matches.push(...nested.map(match => ({ ...match,
|
|
198
|
+
...(match.kind === "delivery" && isBackground(segment[cursor].index) ? { background: true as const } : {}),
|
|
199
|
+
...(inheritedUnknown ? { unresolvedDirectory: true as const } : {}), directories: [...directories, ...(match.directories ?? [])] })));
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
const inheritSubstitution = (payload: string, index: number) => {
|
|
204
|
+
const context = contexts.find(scope => index >= scope.from && index < scope.to);
|
|
205
|
+
return collectReviewDeliveryActions(payload, depth + 1).map(match => ({ ...match,
|
|
206
|
+
...(context?.unresolved || routingUnknown(index) ? { unresolvedDirectory: true as const } : {}),
|
|
207
|
+
...(context?.directories.length ? { directories: [...context.directories, ...(match.directories ?? [])] } : {}),
|
|
208
|
+
...(match.kind === "delivery" && isBackground(index) ? { background: true as const } : {}),
|
|
209
|
+
}));
|
|
210
|
+
};
|
|
211
|
+
for (const match of command.matchAll(/\$\(([^()]*)\)/g)) {
|
|
212
|
+
let quote: "'" | '"' | undefined;
|
|
213
|
+
for (let index = 0; index < match.index; index++) {
|
|
214
|
+
const char = command[index];
|
|
215
|
+
if (quote === "'") { if (char === "'") quote = undefined; }
|
|
216
|
+
else if (char === "\\") index++;
|
|
217
|
+
else if (char === "'" && quote === undefined) quote = "'";
|
|
218
|
+
else if (char === '"') quote = quote === '"' ? undefined : '"';
|
|
219
|
+
}
|
|
220
|
+
if (quote !== "'") matches.push(...inheritSubstitution(match[1], match.index));
|
|
221
|
+
}
|
|
222
|
+
for (const { body, index } of backticks) matches.push(...inheritSubstitution(body, index));
|
|
223
|
+
return matches;
|
|
224
|
+
}
|
|
225
|
+
|
|
54
226
|
const WRAPPER_VALUE_OPTIONS: Record<string, readonly string[]> = {
|
|
55
227
|
env: ["-u", "--unset", "-C", "--chdir"],
|
|
56
|
-
sudo: ["-u", "-g", "-h", "-p", "-C", "--user", "--group", "--host", "--prompt", "--chdir"],
|
|
228
|
+
sudo: ["-u", "-g", "-h", "-p", "-C", "-D", "--user", "--group", "--host", "--prompt", "--chdir"],
|
|
57
229
|
timeout: ["-s", "--signal", "-k", "--kill-after"],
|
|
58
230
|
xargs: ["-n", "-I", "-P", "--max-args", "--replace", "--max-procs"],
|
|
59
231
|
};
|
|
@@ -63,12 +235,13 @@ const WRAPPERS = ["env", "sudo", "command", "exec", "nohup", "timeout", "xargs"]
|
|
|
63
235
|
const RESERVED_WORDS = new Set(["then", "else", "elif", "do", "{", "!", "if", "while", "until"]);
|
|
64
236
|
|
|
65
237
|
/** Index of the executable token after reserved words, assignments and familiar wrappers. */
|
|
66
|
-
function headCursor(segment: readonly Token[]): number {
|
|
238
|
+
function headCursor(segment: readonly Token[], onTargetRedirect?: () => void): number {
|
|
67
239
|
let cursor = 0;
|
|
68
240
|
while (cursor < segment.length && segment[cursor].raw === segment[cursor].value && RESERVED_WORDS.has(segment[cursor].value)) cursor++;
|
|
69
241
|
while (cursor < segment.length) {
|
|
70
242
|
const value = segment[cursor].value;
|
|
71
243
|
if (/^[A-Za-z_][A-Za-z_0-9]*=/.test(value)) {
|
|
244
|
+
if (/^GIT_(?:DIR|WORK_TREE|COMMON_DIR|NAMESPACE)=/.test(value)) onTargetRedirect?.();
|
|
72
245
|
cursor++;
|
|
73
246
|
continue;
|
|
74
247
|
}
|
|
@@ -78,6 +251,8 @@ function headCursor(segment: readonly Token[]): number {
|
|
|
78
251
|
while (cursor < segment.length && segment[cursor].value.startsWith("-")) {
|
|
79
252
|
const flag = segment[cursor++].value;
|
|
80
253
|
if (flag === "--") break;
|
|
254
|
+
if (name === "env" && /^(?:-C.*|--chdir(?:=|$))/.test(flag)) onTargetRedirect?.();
|
|
255
|
+
if (name === "sudo" && /^(?:-D.*|--chdir(?:=|$))/.test(flag)) onTargetRedirect?.();
|
|
81
256
|
if (WRAPPER_VALUE_OPTIONS[name]?.includes(flag)) cursor++;
|
|
82
257
|
}
|
|
83
258
|
if (name === "timeout") cursor++;
|
|
@@ -96,6 +271,39 @@ const DATA_COMMANDS = new Set([
|
|
|
96
271
|
"wc", "sort", "uniq", "cut", "tr", "jq", "diff", "ls", "file", "stat",
|
|
97
272
|
]);
|
|
98
273
|
const INERT_COMMANDS = new Set(["cd", "pwd", "true", "false", "test", "[", "mkdir", "touch"]);
|
|
274
|
+
// gentle-shell#1202: read-only subcommands that neither execute nor re-route
|
|
275
|
+
// text. A segment headed by one of these no longer makes the whole line opaque,
|
|
276
|
+
// provided nothing is piped into it and nothing precedes the head (assignments,
|
|
277
|
+
// wrappers) or follows `git` besides `-C <path>` / `--no-pager`. `push` and
|
|
278
|
+
// `rebase` are the guarded operations themselves: they match lexically on their
|
|
279
|
+
// own text and run only their own literal arguments. Every such segment must be
|
|
280
|
+
// free of `$`: a masked data substitution could smuggle in options such as
|
|
281
|
+
// `--receive-pack=` or `-x`.
|
|
282
|
+
const READ_ONLY_GIT = new Set(["status", "log", "diff", "show", "rev-parse", "rev-list", "ls-files", "describe"]);
|
|
283
|
+
const LITERAL_GIT = new Set(["push", "rebase"]);
|
|
284
|
+
const READ_ONLY_GH = new Map([["pr", ["view", "list", "checks", "diff", "status"]], ["issue", ["view", "list", "status"]], ["run", ["view", "list"]]]);
|
|
285
|
+
|
|
286
|
+
/**
|
|
287
|
+
* True when the segment at `cursor` is a top-level, literal `git` or `gh`
|
|
288
|
+
* command that reads only (or a literal push/rebase the YOLO waiver already
|
|
289
|
+
* judges on its own), so it cannot turn a sibling data argument into an action.
|
|
290
|
+
* Piped-into, nested or `$`-bearing segments are never eligible.
|
|
291
|
+
*/
|
|
292
|
+
function readOnlyVcsSegment(segment: readonly Token[], cursor: number, pipedInto: boolean, literal: boolean): boolean {
|
|
293
|
+
if (pipedInto || !literal || cursor !== 0) return false;
|
|
294
|
+
const name = segment[0].value;
|
|
295
|
+
if (name !== "git" && name !== "gh") return false;
|
|
296
|
+
if (segment.some((token) => token.value !== token.raw)) return false;
|
|
297
|
+
if (name === "gh") return READ_ONLY_GH.get(segment[1]?.value)?.includes(segment[2]?.value) ?? false;
|
|
298
|
+
let index = 1;
|
|
299
|
+
while (index < segment.length) {
|
|
300
|
+
if (segment[index].value === "--no-pager") index++;
|
|
301
|
+
else if (segment[index].value === "-C" && index + 1 < segment.length) index += 2;
|
|
302
|
+
else break;
|
|
303
|
+
}
|
|
304
|
+
const subcommand = segment[index]?.value;
|
|
305
|
+
return READ_ONLY_GIT.has(subcommand) || LITERAL_GIT.has(subcommand);
|
|
306
|
+
}
|
|
99
307
|
const HEREDOC_RE = /<<-?\s*(['"]?)([A-Za-z_]\w*)\1[^\n]*\n[\s\S]*?\n\2(?=\n|$)/g;
|
|
100
308
|
|
|
101
309
|
type Ranges = Array<readonly [number, number]>;
|
|
@@ -115,7 +323,7 @@ function maskDataSubstitutions(command: string): { masked: string; ranges: Range
|
|
|
115
323
|
const ranges: Ranges = [];
|
|
116
324
|
let opaque = false;
|
|
117
325
|
const masked = command.replace(SIMPLE_SUBSTITUTION_RE, (raw: string, body: string, offset: number) => {
|
|
118
|
-
const inner = dataRanges(body);
|
|
326
|
+
const inner = dataRanges(body, true);
|
|
119
327
|
if (inner === undefined) opaque = true;
|
|
120
328
|
else ranges.push(...inner.map(([from, to]) => [offset + 2 + from, offset + 2 + to] as const));
|
|
121
329
|
return "_".repeat(raw.length);
|
|
@@ -136,8 +344,12 @@ export function dataArgumentRanges(command: string): Ranges {
|
|
|
136
344
|
return dataRanges(command) ?? [];
|
|
137
345
|
}
|
|
138
346
|
|
|
139
|
-
/**
|
|
140
|
-
|
|
347
|
+
/**
|
|
348
|
+
* Undefined means opaque; an empty list means only inert commands. A nested
|
|
349
|
+
* (substitution) body admits data and inert commands only: its output is text
|
|
350
|
+
* that can run, so an ordinary git or gh segment inside it proves nothing.
|
|
351
|
+
*/
|
|
352
|
+
function dataRanges(original: string, nested = false): Ranges | undefined {
|
|
141
353
|
const substitutions = maskDataSubstitutions(original);
|
|
142
354
|
if (substitutions === undefined) return undefined;
|
|
143
355
|
const command = substitutions.masked;
|
|
@@ -172,7 +384,14 @@ function dataRanges(original: string): Ranges | undefined {
|
|
|
172
384
|
if (head === undefined || head.value !== head.raw) return undefined;
|
|
173
385
|
const name = head.value;
|
|
174
386
|
if (INERT_COMMANDS.has(name)) continue;
|
|
175
|
-
if (!DATA_COMMANDS.has(name))
|
|
387
|
+
if (!DATA_COMMANDS.has(name)) {
|
|
388
|
+
// Output of an earlier segment may be piped into this one, also across
|
|
389
|
+
// blank segments (`|` then newline, `|&`).
|
|
390
|
+
let pipedInto = false;
|
|
391
|
+
for (let back = end - segment.length - 1; back >= 0 && tokens[back].operator; back--) pipedInto ||= tokens[back].raw === "|";
|
|
392
|
+
if (!nested && readOnlyVcsSegment(segment, cursor, pipedInto, !original.slice(segment[0].index, segment.at(-1)!.index + segment.at(-1)!.raw.length).includes("$"))) continue;
|
|
393
|
+
return undefined;
|
|
394
|
+
}
|
|
176
395
|
ranges.push([head.index + head.raw.length, tokens[end]?.index ?? command.length]);
|
|
177
396
|
}
|
|
178
397
|
// A heredoc body belongs to the segment of its `<<` header, which the
|
|
@@ -216,8 +435,8 @@ function removalTargets(args: readonly Token[]): string[] | undefined {
|
|
|
216
435
|
* backtick. An unterminated substitution is a shell syntax error and runs
|
|
217
436
|
* nothing, so it yields no body. Heredoc bodies stay data, as elsewhere.
|
|
218
437
|
*/
|
|
219
|
-
function backtickBodies(command: string): Array<{ body: string; index: number }> {
|
|
220
|
-
const bodies: Array<{ body: string; index: number }> = [];
|
|
438
|
+
function backtickBodies(command: string): Array<{ body: string; index: number; end: number }> {
|
|
439
|
+
const bodies: Array<{ body: string; index: number; end: number }> = [];
|
|
221
440
|
const text = blankHeredocs(command);
|
|
222
441
|
let quote: "'" | '"' | undefined;
|
|
223
442
|
for (let index = 0; index < text.length; index++) {
|
|
@@ -234,7 +453,7 @@ function backtickBodies(command: string): Array<{ body: string; index: number }>
|
|
|
234
453
|
let end = index + 1;
|
|
235
454
|
while (end < text.length && text[end] !== "`") end += text[end] === "\\" ? 2 : 1;
|
|
236
455
|
if (end >= text.length) break;
|
|
237
|
-
bodies.push({ body: text.slice(index + 1, end).replace(/\\([\\$`])/g, "$1"), index });
|
|
456
|
+
bodies.push({ body: text.slice(index + 1, end).replace(/\\([\\$`])/g, "$1"), index, end: end + 1 });
|
|
238
457
|
index = end;
|
|
239
458
|
}
|
|
240
459
|
}
|