@blackbelt-technology/pi-agent-dashboard 0.9.0 → 0.10.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 +38 -5
- package/docs/architecture.md +1673 -75
- package/package.json +23 -15
- package/packages/extension/package.json +8 -8
- package/packages/extension/src/ask-user-tool.ts +65 -3
- package/packages/extension/src/auto-session-namer.ts +190 -50
- package/packages/extension/src/bridge-handlers/dispatch.ts +450 -0
- package/packages/extension/src/bridge-handlers/forwarders.ts +616 -0
- package/packages/extension/src/bridge-handlers/instance.ts +220 -0
- package/packages/extension/src/bridge-handlers/lifecycle.ts +1030 -0
- package/packages/extension/src/bridge-handlers/ui-prompt-patch.ts +198 -0
- package/packages/extension/src/bridge-identity-log.ts +45 -0
- package/packages/extension/src/bridge.ts +480 -2510
- package/packages/extension/src/command-handler.ts +180 -11
- package/packages/extension/src/connection.ts +265 -18
- package/packages/extension/src/dashboard-context-injector.ts +26 -47
- package/packages/extension/src/empty-actionable-guard.ts +8 -3
- package/packages/extension/src/flow-event-wiring.ts +1 -1
- package/packages/extension/src/followup-buffer.ts +1 -1
- package/packages/extension/src/followup-drain.ts +79 -0
- package/packages/extension/src/local-token-header.ts +161 -17
- package/packages/extension/src/message-update-coalescer.ts +3 -1
- package/packages/extension/src/model-refresh.ts +19 -0
- package/packages/extension/src/multiselect-list.ts +6 -2
- package/packages/extension/src/multiselect-polyfill.ts +2 -2
- package/packages/extension/src/openspec-cli-shim.ts +1 -1
- package/packages/extension/src/path-gate/decide.ts +15 -41
- package/packages/extension/src/path-gate/grant-cache.ts +3 -1
- package/packages/extension/src/path-gate/handler.ts +51 -2
- package/packages/extension/src/path-gate/index.ts +12 -1
- package/packages/extension/src/path-gate/resolve.ts +6 -124
- package/packages/extension/src/path-gate/roots.ts +4 -1
- package/packages/extension/src/path-gate/suppression.ts +4 -1
- package/packages/extension/src/path-gate/yolo-link.ts +104 -0
- package/packages/extension/src/plugin-event-forward-registry.ts +200 -0
- package/packages/extension/src/project-trust.ts +119 -25
- package/packages/extension/src/prompt-expander.ts +5 -1
- package/packages/extension/src/prompt-meta.ts +64 -0
- package/packages/extension/src/provider-register.ts +87 -20
- package/packages/extension/src/role-manager.ts +5 -4
- package/packages/extension/src/server-auto-start.ts +12 -5
- package/packages/extension/src/server-launcher.ts +11 -13
- package/packages/extension/src/session-move.ts +19 -0
- package/packages/extension/src/session-sync.ts +31 -38
- package/packages/extension/src/spawn-token.ts +46 -0
- package/packages/extension/src/stream-forward-buffer.ts +161 -0
- package/packages/extension/src/subagent-frame-buffer.ts +6 -2
- package/packages/extension/src/subagent-tick-throttle.ts +3 -1
- package/packages/extension/src/vault-delivery.ts +394 -0
- package/packages/extension/src/vault-forwarder.ts +128 -0
- package/packages/extension/src/vault-masker.ts +165 -0
- package/packages/extension/src/vault-redaction.ts +181 -0
- package/packages/extension/src/vcs-info.ts +5 -2
- package/packages/server/bin/pi-dashboard.mjs +26 -89
- package/packages/server/package.json +29 -15
- package/packages/server/src/access/access-grants.ts +18 -0
- package/packages/server/src/access/agent-confirm-registry.ts +31 -13
- package/packages/server/src/access/agent-grant.ts +1 -1
- package/packages/server/src/access/agent-yolo.ts +91 -0
- package/packages/server/src/access/containment-gate.ts +28 -1
- package/packages/server/src/access/cwd-admission-log.ts +46 -0
- package/packages/server/src/access/cwd-verdict.ts +144 -0
- package/packages/server/src/access/grant-coordinator.ts +3 -1
- package/packages/server/src/access/pi-trust-mirror-service.ts +374 -0
- package/packages/server/src/access/planes.ts +10 -1
- package/packages/server/src/access/refusal-ledger.ts +6 -6
- package/packages/server/src/access/yolo-session.ts +73 -12
- package/packages/server/src/acp-bridge/acp-connection.ts +225 -0
- package/packages/server/src/acp-bridge/acp-restore.ts +41 -0
- package/packages/server/src/acp-bridge/acp-session-adapter.ts +544 -0
- package/packages/server/src/acp-bridge/child-env.ts +73 -0
- package/packages/server/src/acp-bridge/event-log.ts +194 -0
- package/packages/server/src/acp-bridge/gateway-client.ts +136 -0
- package/packages/server/src/acp-bridge/local-bridge-socket.ts +67 -0
- package/packages/server/src/acp-bridge/local-host.ts +132 -0
- package/packages/server/src/acp-bridge/main.ts +118 -0
- package/packages/server/src/acp-bridge/models.ts +33 -0
- package/packages/server/src/acp-bridge/permission-bridge.ts +106 -0
- package/packages/server/src/acp-bridge/server-requests.ts +136 -0
- package/packages/server/src/acp-bridge/session-state.ts +127 -0
- package/packages/server/src/addons/addon-toggle-restore.ts +110 -0
- package/packages/server/src/addons/addons-catalog.ts +408 -0
- package/packages/server/src/addons/addons-folder-service.ts +347 -0
- package/packages/server/src/addons/addons-folder.ts +310 -0
- package/packages/server/src/addons/addons-service.ts +470 -0
- package/packages/server/src/addons/package-contents.ts +99 -0
- package/packages/server/src/addons/settings-entries.ts +120 -0
- package/packages/server/src/attachments/fit-worker-pool.ts +12 -17
- package/packages/server/src/auth/approval-refusal.ts +87 -0
- package/packages/server/src/auth/auth-plugin.ts +292 -79
- package/packages/server/src/auth/auth.ts +78 -7
- package/packages/server/src/auth/bearer-auth.ts +23 -1
- package/packages/server/src/auth/cors-origin.ts +10 -0
- package/packages/server/src/auth/csp.ts +6 -0
- package/packages/server/src/auth/host-admission.ts +26 -0
- package/packages/server/src/auth/host-gate.ts +6 -1
- package/packages/server/src/auth/local-credential.ts +258 -0
- package/packages/server/src/auth/local-proof.ts +7 -4
- package/packages/server/src/auth/local-token.ts +16 -0
- package/packages/server/src/auth/localhost-guard.ts +251 -8
- package/packages/server/src/auth/network-trust-telemetry.ts +126 -0
- package/packages/server/src/auth/node-guard.ts +43 -0
- package/packages/server/src/auth/operate-required.ts +126 -0
- package/packages/server/src/auth/passkey/challenge-store.ts +90 -0
- package/packages/server/src/auth/passkey/passkey-log.ts +34 -0
- package/packages/server/src/auth/passkey/passkey-pages.ts +173 -0
- package/packages/server/src/auth/passkey/passkey-routes.ts +224 -0
- package/packages/server/src/auth/passkey/passkey-service.ts +247 -0
- package/packages/server/src/auth/passkey/phone-signin.ts +211 -0
- package/packages/server/src/auth/passkey/requester.ts +83 -0
- package/packages/server/src/auth/passkey/rp-context.ts +98 -0
- package/packages/server/src/auth/passkey/user-directory.ts +348 -0
- package/packages/server/src/auth/pi-legacy-credentials.ts +321 -0
- package/packages/server/src/auth/provider-auth-registry.ts +35 -1
- package/packages/server/src/auth/provider-auth-storage.ts +55 -8
- package/packages/server/src/auth/radius-override.ts +13 -0
- package/packages/server/src/auth/route-tier-gate.ts +27 -11
- package/packages/server/src/auth/runtime-provider-catalogue.ts +107 -0
- package/packages/server/src/auth/scan-legacy-provider-ids.ts +80 -0
- package/packages/server/src/auth/serve-app-host.ts +97 -0
- package/packages/server/src/auth/trust-mode-boot.ts +93 -0
- package/packages/server/src/auth/trust-mode.ts +83 -0
- package/packages/server/src/auto-name-outcome-store.ts +4 -1
- package/packages/server/src/browse.ts +114 -2
- package/packages/server/src/browser-handlers/acp-guard.ts +79 -0
- package/packages/server/src/browser-handlers/directory-handler.ts +128 -6
- package/packages/server/src/browser-handlers/session-action-handler.ts +129 -62
- package/packages/server/src/browser-handlers/session-meta-handler.ts +16 -6
- package/packages/server/src/browser-handlers/spawn-choice.ts +99 -0
- package/packages/server/src/cli.ts +883 -97
- package/packages/server/src/config-api.ts +143 -1
- package/packages/server/src/config-snapshot.ts +5 -0
- package/packages/server/src/directory-service.ts +435 -32
- package/packages/server/src/embed-lifecycle/caps.ts +35 -4
- package/packages/server/src/embed-lifecycle/embed-lifecycle-controller.ts +45 -4
- package/packages/server/src/embed-lifecycle/idle-reaper.ts +195 -20
- package/packages/server/src/embed-lifecycle/lifecycle-metrics.ts +38 -0
- package/packages/server/src/embed-lifecycle/plugin-session-close.ts +123 -0
- package/packages/server/src/embed-lifecycle/quiescence.ts +29 -3
- package/packages/server/src/embed-lifecycle/reclaim-give-up.ts +54 -0
- package/packages/server/src/event-wiring.ts +208 -35
- package/packages/server/src/file-watch-manager.ts +187 -39
- package/packages/server/src/git-worktree/git-operations.ts +16 -5
- package/packages/server/src/git-worktree/worktree-init-trust.ts +48 -5
- package/packages/server/src/git-worktree/worktree-init.ts +7 -56
- package/packages/server/src/identity/host-resources.ts +3 -0
- package/packages/server/src/identity/http-road-classification.ts +18 -0
- package/packages/server/src/identity/identity-registration-tracker.ts +4 -1
- package/packages/server/src/identity/plugin-identity.ts +19 -0
- package/packages/server/src/identity/policy-registry.ts +4 -1
- package/packages/server/src/identity/resolver-registry.ts +12 -3
- package/packages/server/src/identity/ws-message-scope.ts +9 -0
- package/packages/server/src/identity/ws-road-classification.ts +9 -0
- package/packages/server/src/known-server-moves.ts +175 -0
- package/packages/server/src/lib/browse-roots.ts +36 -0
- package/packages/server/src/lib/digest-gate.ts +82 -0
- package/packages/server/src/lib/file-write-lock.ts +24 -0
- package/packages/server/src/lib/folder-project.ts +439 -0
- package/packages/server/src/lib/purify.ts +13 -5
- package/packages/server/src/lib/writable-handler-target.ts +66 -0
- package/packages/server/src/lib/writable-md-target.ts +12 -1
- package/packages/server/src/lifecycle/classify-dashboard-port.ts +134 -0
- package/packages/server/src/lifecycle/home-lock.ts +344 -130
- package/packages/server/src/lifecycle/home-rendezvous.ts +41 -11
- package/packages/server/src/lifecycle/recovery-server.ts +77 -1
- package/packages/server/src/lifecycle/stop-ownership.ts +97 -11
- package/packages/server/src/live-server/live-capability.ts +254 -0
- package/packages/server/src/live-server/live-server-proxy.ts +173 -26
- package/packages/server/src/metrics/eventloop-spike-metrics.ts +2 -2
- package/packages/server/src/model-proxy/internal-auth-storage.ts +27 -26
- package/packages/server/src/model-proxy/internal-registry.ts +6 -0
- package/packages/server/src/model-proxy/server-model-runtime.ts +6 -0
- package/packages/server/src/openspec/openspec-change-watcher.ts +109 -16
- package/packages/server/src/openspec/openspec-poll-fs-helpers.ts +132 -0
- package/packages/server/src/openspec/openspec-poll-worker-pool.ts +90 -35
- package/packages/server/src/openspec/openspec-poll-worker.ts +200 -44
- package/packages/server/src/openspec/proposal-attach-naming.ts +5 -3
- package/packages/server/src/openspec/readiness.ts +9 -0
- package/packages/server/src/openspec/workflow-schema.ts +1128 -0
- package/packages/server/src/package/installed-package-enricher.ts +38 -3
- package/packages/server/src/package/package-health-scanner.ts +133 -0
- package/packages/server/src/package/package-manager-wrapper.ts +18 -2
- package/packages/server/src/package/provider-catalogue-cache.ts +17 -3
- package/packages/server/src/package/provider-probe.ts +5 -3
- package/packages/server/src/pairing/browser-gateway.ts +108 -8
- package/packages/server/src/pairing/knock-admission.ts +277 -0
- package/packages/server/src/pairing/pairing.ts +154 -27
- package/packages/server/src/pairing/subagent-resync-routing.ts +4 -1
- package/packages/server/src/pairing/ws-tier-gate.ts +34 -0
- package/packages/server/src/peer-servers.ts +77 -0
- package/packages/server/src/pending/pending-plugin-ref-registry.ts +57 -2
- package/packages/server/src/persistence/boot-state.ts +48 -1
- package/packages/server/src/persistence/memory-event-store.ts +216 -237
- package/packages/server/src/persistence/meta-persistence.ts +12 -1
- package/packages/server/src/persistence/preferences-store.ts +116 -7
- package/packages/server/src/pi/bridge-upgrade-auth.ts +32 -21
- package/packages/server/src/pi/folder-commands.ts +141 -0
- package/packages/server/src/pi/gateway-socket-bind.ts +9 -3
- package/packages/server/src/pi/gateway-transport-policy.ts +13 -0
- package/packages/server/src/pi/host-project-trust.ts +158 -33
- package/packages/server/src/pi/pi-gateway.ts +93 -9
- package/packages/server/src/pi/pi-resource-scanner.ts +15 -0
- package/packages/server/src/pi/resource-activation-toggle.ts +6 -0
- package/packages/server/src/pi/resource-toggle-trust.ts +34 -2
- package/packages/server/src/pi/session-skill-registry.ts +13 -3
- package/packages/server/src/pi/settings-write-lock.ts +32 -0
- package/packages/server/src/pi/trust-challenges.ts +38 -0
- package/packages/server/src/pi-agent-settings.ts +701 -100
- package/packages/server/src/pi-settings-themes.ts +104 -0
- package/packages/server/src/questions/brief-generator.ts +138 -0
- package/packages/server/src/questions/brief-model.ts +55 -0
- package/packages/server/src/questions/brief-policy.ts +36 -0
- package/packages/server/src/questions/brief-prompt.ts +92 -0
- package/packages/server/src/questions/brief-runtime.ts +50 -0
- package/packages/server/src/questions/question-answer.ts +55 -0
- package/packages/server/src/questions/question-broadcast.ts +106 -0
- package/packages/server/src/questions/question-files.ts +128 -0
- package/packages/server/src/questions/question-routes.ts +126 -0
- package/packages/server/src/questions/question-snapshot.ts +150 -0
- package/packages/server/src/questions/question-stack.ts +57 -0
- package/packages/server/src/questions/question-store.ts +477 -0
- package/packages/server/src/routes/access-prompt-routes.ts +5 -3
- package/packages/server/src/routes/access-routes.ts +123 -5
- package/packages/server/src/routes/acme-routes.ts +190 -0
- package/packages/server/src/routes/acp-routes.ts +16 -0
- package/packages/server/src/routes/addons-routes.ts +221 -0
- package/packages/server/src/routes/file-routes.ts +366 -75
- package/packages/server/src/routes/file-write-binary-routes.ts +473 -0
- package/packages/server/src/routes/folder-project-routes.ts +99 -0
- package/packages/server/src/routes/git-routes.ts +17 -2
- package/packages/server/src/routes/known-servers-routes.ts +333 -53
- package/packages/server/src/routes/live-server-routes.ts +72 -4
- package/packages/server/src/routes/local-proof-routes.ts +12 -7
- package/packages/server/src/routes/mermaid-repair-routes.ts +254 -0
- package/packages/server/src/routes/model-proxy-routes.ts +4 -2
- package/packages/server/src/routes/openspec-routes.ts +270 -40
- package/packages/server/src/routes/package-health-routes.ts +140 -0
- package/packages/server/src/routes/package-routes.ts +28 -1
- package/packages/server/src/routes/pairing-routes.ts +158 -24
- package/packages/server/src/routes/pi-retry-routes.ts +18 -2
- package/packages/server/src/routes/pi-settings-routes.ts +264 -0
- package/packages/server/src/routes/plugin-activation-routes.ts +87 -27
- package/packages/server/src/routes/provider-auth-routes.ts +22 -5
- package/packages/server/src/routes/provider-routes.ts +29 -0
- package/packages/server/src/routes/resource-activation-routes.ts +16 -32
- package/packages/server/src/routes/session-routes.ts +49 -5
- package/packages/server/src/routes/system-routes.ts +207 -23
- package/packages/server/src/routes/tls-routes.ts +55 -0
- package/packages/server/src/routes/user-routes.ts +192 -0
- package/packages/server/src/runtime-overlay/runtime-stager.ts +15 -2
- package/packages/server/src/runtime-overlay/runtime-update-checker.ts +11 -2
- package/packages/server/src/server.ts +919 -139
- package/packages/server/src/services/attached-driver.ts +175 -0
- package/packages/server/src/services/change-notifier.ts +55 -0
- package/packages/server/src/services/cli-service.ts +450 -0
- package/packages/server/src/services/command-runner.ts +92 -0
- package/packages/server/src/services/definitions-store.ts +121 -0
- package/packages/server/src/services/driver.ts +112 -0
- package/packages/server/src/services/health.ts +94 -0
- package/packages/server/src/services/leases.ts +117 -0
- package/packages/server/src/services/log-text.ts +97 -0
- package/packages/server/src/services/native-driver.ts +283 -0
- package/packages/server/src/services/oci-driver.ts +590 -0
- package/packages/server/src/services/output-capture.ts +183 -0
- package/packages/server/src/services/paths.ts +82 -0
- package/packages/server/src/services/ports.ts +26 -0
- package/packages/server/src/services/routes.ts +140 -0
- package/packages/server/src/services/runtime-detect.ts +108 -0
- package/packages/server/src/services/secret-delivery.ts +61 -0
- package/packages/server/src/services/secrets-resolver.ts +145 -0
- package/packages/server/src/services/secrets-store.ts +137 -0
- package/packages/server/src/services/service-manager.ts +1565 -0
- package/packages/server/src/services/start-record.ts +66 -0
- package/packages/server/src/services/state-machine.ts +241 -0
- package/packages/server/src/session/archive-sweeper.ts +92 -3
- package/packages/server/src/session/custom-event-group-matcher.ts +4 -3
- package/packages/server/src/session/in-flight-tool-calls.ts +74 -0
- package/packages/server/src/session/memory-session-manager.ts +53 -0
- package/packages/server/src/session/name-provenance.ts +102 -0
- package/packages/server/src/session/open-tool-calls.ts +15 -6
- package/packages/server/src/session/session-api.ts +47 -12
- package/packages/server/src/session/session-archive.ts +56 -4
- package/packages/server/src/session/session-diff-cache.ts +11 -4
- package/packages/server/src/session/session-load-worker-pool.ts +4 -3
- package/packages/server/src/session/session-scanner.ts +73 -3
- package/packages/server/src/session/session-to-meta.ts +15 -0
- package/packages/server/src/spawn-process/abort-spawned-run.ts +55 -0
- package/packages/server/src/spawn-process/acp-spawn.ts +131 -0
- package/packages/server/src/spawn-process/process-manager.ts +164 -30
- package/packages/server/src/spawn-process/restart-helper.ts +9 -8
- package/packages/server/src/spawn-process/server-pid.ts +16 -7
- package/packages/server/src/spawn-process/session-terminator.ts +218 -0
- package/packages/server/src/spawn-process/spawn-env-contributors.ts +159 -0
- package/packages/server/src/spawn-process/spawn-register-watchdog.ts +10 -1
- package/packages/server/src/terminal/terminal-manager.ts +67 -1
- package/packages/server/src/tls/cert-files.ts +228 -0
- package/packages/server/src/tls/cert-manager.ts +703 -0
- package/packages/server/src/tls/cert-store.ts +69 -0
- package/packages/server/src/tls/source-registry.ts +71 -0
- package/packages/server/src/tls/sources/acme/accounts.ts +76 -0
- package/packages/server/src/tls/sources/acme/acme-source.ts +508 -0
- package/packages/server/src/tls/sources/acme/config-projection.ts +34 -0
- package/packages/server/src/tls/sources/acme/credentials.ts +185 -0
- package/packages/server/src/tls/sources/acme/dns.ts +303 -0
- package/packages/server/src/tls/sources/acme/e2e-overrides.ts +49 -0
- package/packages/server/src/tls/sources/acme/entry.ts +180 -0
- package/packages/server/src/tls/sources/acme/gc.ts +78 -0
- package/packages/server/src/tls/sources/acme/runtime.ts +51 -0
- package/packages/server/src/tls/sources/acme/solvers/acme-dns.ts +154 -0
- package/packages/server/src/tls/sources/acme/solvers/cloudflare.ts +147 -0
- package/packages/server/src/tls/sources/acme/types.ts +72 -0
- package/packages/server/src/tls/sources/tailscale-cert.ts +172 -0
- package/packages/server/src/tls/tls-config-validation.ts +92 -0
- package/packages/server/src/tls/tls-listener.ts +351 -0
- package/packages/server/src/tls/types.ts +80 -0
- package/packages/server/src/tunnel/tunnel-block-events.ts +4 -1
- package/packages/server/src/tunnel/tunnel-core.ts +4 -1
- package/packages/server/src/tunnel/tunnel-endpoints.ts +4 -0
- package/packages/server/src/tunnel-providers/tailscale.ts +27 -6
- package/packages/server/src/vault/vault-bindings.ts +101 -0
- package/packages/server/src/vault/vault-delivery-hub.ts +294 -0
- package/packages/server/src/vault/vault-grants.ts +260 -0
- package/packages/server/src/vault/vault-import.ts +161 -0
- package/packages/server/src/vault/vault-permissions.ts +39 -0
- package/packages/server/src/vault/vault-plugin-read.ts +64 -0
- package/packages/server/src/vault/vault-projects.ts +156 -0
- package/packages/server/src/vault/vault-routes.ts +277 -0
- package/packages/server/src/vault/vault-store.ts +371 -0
- package/packages/shared/package.json +5 -2
- package/packages/shared/src/acp/acp-config.ts +123 -0
- package/packages/shared/src/acp/normalize-v1.ts +92 -0
- package/packages/shared/src/acp/paths.ts +36 -0
- package/packages/shared/src/acp/to-dashboard-events.ts +533 -0
- package/packages/shared/src/acp/update-model.ts +574 -0
- package/packages/shared/src/anthropic-messages-source.ts +8 -0
- package/packages/shared/src/bind-reachability.ts +21 -2
- package/packages/shared/src/boot-state.ts +6 -0
- package/packages/shared/src/browser-host-identity.ts +49 -0
- package/packages/shared/src/browser-host-ipc.ts +107 -0
- package/packages/shared/src/browser-protocol.ts +385 -71
- package/packages/shared/src/canonical-subject.ts +27 -2
- package/packages/shared/src/card-sections.ts +185 -1
- package/packages/shared/src/chrome-profiles.ts +188 -0
- package/packages/shared/src/config.ts +473 -26
- package/packages/shared/src/custom-event-groups.ts +5 -2
- package/packages/shared/src/cwd-guard.ts +381 -1
- package/packages/shared/src/dashboard-paths.ts +12 -0
- package/packages/shared/src/dashboard-plugin/editor-pane-tab.ts +26 -0
- package/packages/shared/src/dashboard-plugin/file-handler.ts +71 -0
- package/packages/shared/src/dashboard-plugin/index.ts +7 -3
- package/packages/shared/src/dashboard-plugin/manifest-types.ts +106 -2
- package/packages/shared/src/dashboard-plugin/project-identity.ts +42 -0
- package/packages/shared/src/dashboard-plugin/project-markers.ts +60 -0
- package/packages/shared/src/dashboard-plugin/slot-props.ts +95 -0
- package/packages/shared/src/dashboard-plugin/slot-types.ts +64 -4
- package/packages/shared/src/dashboard-plugin/ui-primitives.ts +22 -3
- package/packages/shared/src/dashboard-starter.ts +30 -0
- package/packages/shared/src/display-name.ts +42 -0
- package/packages/shared/src/doctor-core.ts +25 -107
- package/packages/shared/src/enabled-models-match.ts +47 -0
- package/packages/shared/src/event-forward-declaration.ts +187 -0
- package/packages/shared/src/file-kind.ts +54 -2
- package/packages/shared/src/git-worktree-helpers.ts +8 -4
- package/packages/shared/src/grammar-types.ts +3 -1
- package/packages/shared/src/host-admission.ts +2 -1
- package/packages/shared/src/host-port.ts +34 -0
- package/packages/shared/src/launcher-origin.ts +26 -0
- package/packages/shared/src/local-credential-proof.ts +219 -0
- package/packages/shared/src/markup-repair/asciidoc.ts +130 -0
- package/packages/shared/src/markup-repair/types.ts +13 -0
- package/packages/shared/src/md-table-cell.ts +11 -0
- package/packages/shared/src/mdns-discovery.ts +392 -42
- package/packages/shared/src/models-json-reader.ts +6 -0
- package/packages/shared/src/openspec-design-evidence.ts +25 -1
- package/packages/shared/src/openspec-poller.ts +210 -9
- package/packages/shared/src/openspec-status-all.ts +393 -0
- package/packages/shared/src/operate-required.ts +29 -0
- package/packages/shared/src/pairing-knock-client.ts +261 -0
- package/packages/shared/src/pairing-knock.ts +71 -0
- package/packages/shared/src/pairing-refusal.ts +32 -0
- package/packages/shared/src/path-containment-guard-name.ts +8 -0
- package/packages/shared/src/pi-settings-keys.ts +9 -0
- package/packages/shared/src/pi-settings-schema.ts +285 -0
- package/packages/shared/src/pi-trust-mirror-snapshot.ts +200 -0
- package/packages/shared/src/pi-trust-mirror-types.ts +57 -0
- package/packages/shared/src/pi-trust-mirror.ts +328 -0
- package/packages/shared/src/platform/binary-lookup.ts +2 -194
- package/packages/shared/src/platform/git.ts +204 -4
- package/packages/shared/src/platform/native-ts-hooks.mjs +93 -40
- package/packages/shared/src/platform/native-ts-register.mjs +22 -10
- package/packages/shared/src/platform/native-ts-tier.d.mts +1 -0
- package/packages/shared/src/platform/native-ts-tier.mjs +17 -0
- package/packages/shared/src/platform/node-spawn.ts +1 -2
- package/packages/shared/src/platform/openspec.ts +129 -31
- package/packages/shared/src/platform/process-scan.ts +199 -1
- package/packages/shared/src/platform/process.ts +51 -0
- package/packages/shared/src/platform/runner.ts +46 -2
- package/packages/shared/src/platform/spawn-mechanism.ts +14 -2
- package/packages/shared/src/platform/ts-loader-select.d.mts +1 -7
- package/packages/shared/src/platform/ts-loader-select.mjs +14 -43
- package/packages/shared/src/plugin-bridge-register.ts +24 -1
- package/packages/shared/src/project-name.ts +42 -0
- package/packages/shared/src/prompt-answer.ts +183 -0
- package/packages/shared/src/protocol.ts +133 -8
- package/packages/shared/src/question-types.ts +73 -0
- package/packages/shared/src/recommended-extensions.ts +80 -23
- package/packages/shared/src/recovery-timing.ts +12 -0
- package/packages/shared/src/redaction.ts +50 -0
- package/packages/shared/src/rest-api.ts +484 -1
- package/packages/shared/src/role-config-disk.ts +23 -0
- package/packages/shared/src/role-schema.ts +79 -0
- package/packages/shared/src/route-tiers.ts +127 -0
- package/packages/shared/src/runtime-overlay/materialize-plugins.d.mts +17 -0
- package/packages/shared/src/runtime-overlay/materialize-plugins.mjs +119 -8
- package/packages/shared/src/server-identity.ts +51 -15
- package/packages/shared/src/server-launcher.ts +12 -33
- package/packages/shared/src/server-pinning.ts +81 -0
- package/packages/shared/src/services/offers.ts +114 -0
- package/packages/shared/src/services/schema.ts +628 -0
- package/packages/shared/src/services/status.ts +169 -0
- package/packages/shared/src/session-meta.ts +59 -2
- package/packages/shared/src/session-name.ts +8 -0
- package/packages/shared/src/skill-block-parser.ts +14 -0
- package/packages/shared/src/source-matching.ts +5 -1
- package/packages/shared/src/state-replay.ts +19 -0
- package/packages/shared/src/terminal-safe.ts +24 -0
- package/packages/shared/src/tls-status.ts +69 -0
- package/packages/shared/src/tool-path-resolve.ts +243 -0
- package/packages/shared/src/tool-registry/definitions.ts +26 -4
- package/packages/shared/src/tool-registry/index.ts +2 -2
- package/packages/shared/src/tool-registry/pi-tools.ts +32 -3
- package/packages/shared/src/tunnel-provider.ts +3 -2
- package/packages/shared/src/types.ts +104 -9
- package/packages/shared/src/vault-delivery.ts +73 -0
- package/packages/shared/src/vault-origin.ts +51 -0
- package/packages/shared/src/vault-project-key.ts +53 -0
- package/packages/shared/src/worktree-init-hook.ts +69 -0
- package/packages/shared/src/ws-message-tiers.ts +135 -0
- package/tsconfig.base.json +1 -0
|
@@ -5,118 +5,23 @@
|
|
|
5
5
|
*/
|
|
6
6
|
|
|
7
7
|
import { existsSync, realpathSync } from "node:fs";
|
|
8
|
-
import { createRequire } from "node:module";
|
|
9
8
|
import os from "node:os";
|
|
10
9
|
import path from "node:path";
|
|
11
|
-
import { pathToFileURL } from "node:url";
|
|
12
10
|
import { MANAGED_BIN, MANAGED_DIR } from "../managed-paths.js";
|
|
13
11
|
import { ensureWindowsSystemPath } from "./ensure-windows-path.js";
|
|
14
12
|
import { normalizeEnvPathKey } from "./env-path-key.js";
|
|
15
13
|
import { buildSafeArgv, execSync, spawnSync } from "./exec.js";
|
|
16
14
|
import { augmentEnvWithGitSource } from "./git-source.js";
|
|
17
15
|
|
|
18
|
-
// ──
|
|
16
|
+
// ── managed pi package names ──────────────────────────────────────────────
|
|
19
17
|
|
|
20
18
|
/**
|
|
21
|
-
* Pi-coding-agent package names searched for a managed
|
|
19
|
+
* Pi-coding-agent package names searched for a managed install.
|
|
22
20
|
* Earendil only — the legacy fork is never an anchor.
|
|
23
21
|
* See change: drop-mariozechner-pi-fork.
|
|
24
22
|
*/
|
|
25
23
|
export const MANAGED_PI_PACKAGES = ["@earendil-works/pi-coding-agent"] as const;
|
|
26
24
|
|
|
27
|
-
/**
|
|
28
|
-
* jiti provider package names tried inside every anchor's resolution
|
|
29
|
-
* chain. Upstream `jiti` first; legacy `@mariozechner/jiti` fallback.
|
|
30
|
-
* Carried over verbatim from `resolve-jiti.ts`.
|
|
31
|
-
*/
|
|
32
|
-
export const JITI_PACKAGES = ["jiti", "@mariozechner/jiti"] as const;
|
|
33
|
-
|
|
34
|
-
/**
|
|
35
|
-
* Test seam: a function that takes a package specifier (e.g.
|
|
36
|
-
* `"jiti/package.json"`) and returns the resolved path. Production
|
|
37
|
-
* supplies `createRequire(<anchor>).resolve`; tests supply a stub.
|
|
38
|
-
* Carried over verbatim from `resolve-jiti.ts`.
|
|
39
|
-
*/
|
|
40
|
-
export type JitiResolver = (specifier: string) => string;
|
|
41
|
-
|
|
42
|
-
/**
|
|
43
|
-
* Pure helper: given a jiti package.json path, return the file:// URL
|
|
44
|
-
* of its register hook. Handles Windows-style drive letters regardless
|
|
45
|
-
* of host OS (`pathToFileURL` on POSIX URL-encodes backslashes).
|
|
46
|
-
*
|
|
47
|
-
* Mirrors the prior helper from the deleted `resolve-jiti.ts`.
|
|
48
|
-
*/
|
|
49
|
-
function jitiRegisterUrl(pkgJsonPath: string): string {
|
|
50
|
-
const isWindowsStyle = /^[A-Za-z]:[\\/]/.test(pkgJsonPath);
|
|
51
|
-
if (isWindowsStyle) {
|
|
52
|
-
const registerPath = path.win32.join(
|
|
53
|
-
path.win32.dirname(pkgJsonPath),
|
|
54
|
-
"lib",
|
|
55
|
-
"jiti-register.mjs",
|
|
56
|
-
);
|
|
57
|
-
return `file:///${registerPath.replace(/\\/g, "/")}`;
|
|
58
|
-
}
|
|
59
|
-
const registerPath = path.join(path.dirname(pkgJsonPath), "lib", "jiti-register.mjs");
|
|
60
|
-
return pathToFileURL(registerPath).href;
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
/**
|
|
64
|
-
* Walk JITI_PACKAGES with the supplied resolver and return the first
|
|
65
|
-
* hit's register URL. Optional `pathExists` guard rejects hits whose
|
|
66
|
-
* `lib/jiti-register.mjs` is absent on disk (corrupt installs). When
|
|
67
|
-
* `pathExists` is omitted, the package.json hit alone is sufficient
|
|
68
|
-
* — used by the argv/system-pi anchors which already realpath'd a
|
|
69
|
-
* trustworthy node_modules tree.
|
|
70
|
-
*/
|
|
71
|
-
function walkJiti(
|
|
72
|
-
resolver: JitiResolver,
|
|
73
|
-
pathExists?: (p: string) => boolean,
|
|
74
|
-
): string | null {
|
|
75
|
-
for (const jiti of JITI_PACKAGES) {
|
|
76
|
-
try {
|
|
77
|
-
const pkgJson = resolver(`${jiti}/package.json`);
|
|
78
|
-
if (pathExists) {
|
|
79
|
-
const registerPath = path.join(path.dirname(pkgJson), "lib", "jiti-register.mjs");
|
|
80
|
-
if (!pathExists(registerPath)) continue;
|
|
81
|
-
}
|
|
82
|
-
return jitiRegisterUrl(pkgJson);
|
|
83
|
-
} catch { /* next */ }
|
|
84
|
-
}
|
|
85
|
-
return null;
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
/**
|
|
89
|
-
* Internal deps for `ToolResolver.resolveJiti`. Underscore-prefixed
|
|
90
|
-
* fields are test seams — production callers pass only `anchor` /
|
|
91
|
-
* `resolver`.
|
|
92
|
-
*/
|
|
93
|
-
export interface ResolveJitiOpts {
|
|
94
|
-
/** Caller-supplied anchor inside a node_modules tree (e.g. cliPath). */
|
|
95
|
-
anchor?: string;
|
|
96
|
-
/**
|
|
97
|
-
* When true, skip the managed-pi / system-pi / argv anchors and try
|
|
98
|
-
* ONLY `opts.anchor`. Used for health-probing a specific extracted
|
|
99
|
-
* tree where finding jiti elsewhere does not prove the tree itself
|
|
100
|
-
* is healthy.
|
|
101
|
-
*/
|
|
102
|
-
anchorOnly?: boolean;
|
|
103
|
-
/**
|
|
104
|
-
* Test seam: replaces `createRequire(<anchor>).resolve` at every
|
|
105
|
-
* probe site. Production omits — actual `createRequire` is used.
|
|
106
|
-
*/
|
|
107
|
-
resolver?: JitiResolver;
|
|
108
|
-
/** Test seam: replaces `existsSync` for managed-pi pkg.json + register guards. */
|
|
109
|
-
_pathExists?: (p: string) => boolean;
|
|
110
|
-
/** Test seam: replaces `realpathSync` for system-pi + argv anchors. */
|
|
111
|
-
_realpath?: (p: string) => string;
|
|
112
|
-
/** Test seam: replaces this resolver's `which("pi")` call. */
|
|
113
|
-
_whichPi?: () => string | null;
|
|
114
|
-
/** Test seam: replaces `process.argv[1]`. */
|
|
115
|
-
_argv1?: string | undefined;
|
|
116
|
-
/** Test seam: replaces `~/.pi-dashboard` root used to probe managed-pi. */
|
|
117
|
-
_managedDir?: string;
|
|
118
|
-
}
|
|
119
|
-
|
|
120
25
|
// ── AppImage self-hit guard (Linux power-user mode safety) ────────────────
|
|
121
26
|
|
|
122
27
|
/**
|
|
@@ -343,103 +248,6 @@ export class ToolResolver {
|
|
|
343
248
|
return this.which("node");
|
|
344
249
|
}
|
|
345
250
|
|
|
346
|
-
/**
|
|
347
|
-
* Resolve pi's jiti register hook as a `file://` URL.
|
|
348
|
-
*
|
|
349
|
-
* Resolution order (first hit wins):
|
|
350
|
-
* 1. Managed pi install — `~/.pi-dashboard/node_modules/<pkg>` for
|
|
351
|
-
* every entry of `MANAGED_PI_PACKAGES` (upstream first, legacy
|
|
352
|
-
* fallback). Each candidate's pkg.json is the createRequire
|
|
353
|
-
* anchor; walk `JITI_PACKAGES` from there.
|
|
354
|
-
* 2. System pi via `this.which("pi")` (realpathed to escape
|
|
355
|
-
* symlinks like `/usr/local/bin/pi → .../dist/cli.js`).
|
|
356
|
-
* 3. Caller-supplied `opts.anchor` (e.g. an electron `cliPath`).
|
|
357
|
-
* 4. `process.argv[1]` (the running pi/node entry; populated for
|
|
358
|
-
* bridge-extension callers).
|
|
359
|
-
*
|
|
360
|
-
* Returns null when none yield a jiti install. Preserves the
|
|
361
|
-
* Windows drive-letter URL-wrapping contract that previously lived
|
|
362
|
-
* on the prior `buildJitiRegisterUrl` helper in `resolve-jiti.ts`.
|
|
363
|
-
*
|
|
364
|
-
* Tests inject `_pathExists` / `_realpath` / `_whichPi` / `_argv1`
|
|
365
|
-
* / `_managedDir` and a flat `resolver` to exercise individual
|
|
366
|
-
* anchors deterministically.
|
|
367
|
-
*
|
|
368
|
-
* Subsumes the previous `resolveJitiImport`, `resolveJitiFromAnchor`,
|
|
369
|
-
* `pickJitiRegisterUrl`, `pickJitiFromAnchor`, `buildJitiRegisterUrl`,
|
|
370
|
-
* and the duplicate `resolveJitiFromPi` wrappers in electron.
|
|
371
|
-
*/
|
|
372
|
-
resolveJiti(opts: ResolveJitiOpts = {}): string | null {
|
|
373
|
-
const pathExists = opts._pathExists ?? existsSync;
|
|
374
|
-
const realpath = opts._realpath ?? realpathSync;
|
|
375
|
-
const whichPi = opts._whichPi ?? (() => this.which("pi"));
|
|
376
|
-
const argv1 = "_argv1" in opts ? opts._argv1 : process.argv[1];
|
|
377
|
-
const managedDir = opts._managedDir ?? MANAGED_DIR;
|
|
378
|
-
|
|
379
|
-
const makeResolver = (anchor: string): JitiResolver | null => {
|
|
380
|
-
if (opts.resolver) return opts.resolver;
|
|
381
|
-
try {
|
|
382
|
-
const req = createRequire(anchor);
|
|
383
|
-
return (spec) => req.resolve(spec);
|
|
384
|
-
} catch {
|
|
385
|
-
return null;
|
|
386
|
-
}
|
|
387
|
-
};
|
|
388
|
-
|
|
389
|
-
// anchor-only short-circuit: skip every anchor except opts.anchor.
|
|
390
|
-
if (opts.anchorOnly) {
|
|
391
|
-
if (!opts.anchor) return null;
|
|
392
|
-
if (!pathExists(opts.anchor)) return null;
|
|
393
|
-
const r = makeResolver(opts.anchor);
|
|
394
|
-
if (!r) return null;
|
|
395
|
-
return walkJiti(r, pathExists);
|
|
396
|
-
}
|
|
397
|
-
|
|
398
|
-
// 1. Managed pi installs.
|
|
399
|
-
for (const pkg of MANAGED_PI_PACKAGES) {
|
|
400
|
-
const pkgJson = path.join(managedDir, "node_modules", pkg, "package.json");
|
|
401
|
-
if (!pathExists(pkgJson)) continue;
|
|
402
|
-
const resolver = makeResolver(pkgJson);
|
|
403
|
-
if (!resolver) continue;
|
|
404
|
-
const url = walkJiti(resolver, pathExists);
|
|
405
|
-
if (url) return url;
|
|
406
|
-
}
|
|
407
|
-
|
|
408
|
-
// 2. System pi.
|
|
409
|
-
const piPath = whichPi();
|
|
410
|
-
if (piPath) {
|
|
411
|
-
let realPi: string;
|
|
412
|
-
try { realPi = realpath(piPath); } catch { realPi = piPath; }
|
|
413
|
-
const resolver = makeResolver(realPi);
|
|
414
|
-
if (resolver) {
|
|
415
|
-
const url = walkJiti(resolver, pathExists);
|
|
416
|
-
if (url) return url;
|
|
417
|
-
}
|
|
418
|
-
}
|
|
419
|
-
|
|
420
|
-
// 3. Caller-supplied anchor.
|
|
421
|
-
if (opts.anchor && pathExists(opts.anchor)) {
|
|
422
|
-
const resolver = makeResolver(opts.anchor);
|
|
423
|
-
if (resolver) {
|
|
424
|
-
const url = walkJiti(resolver, pathExists);
|
|
425
|
-
if (url) return url;
|
|
426
|
-
}
|
|
427
|
-
}
|
|
428
|
-
|
|
429
|
-
// 4. process.argv[1] (or test override).
|
|
430
|
-
if (argv1) {
|
|
431
|
-
let realArgv: string;
|
|
432
|
-
try { realArgv = realpath(argv1); } catch { realArgv = argv1; }
|
|
433
|
-
const resolver = makeResolver(realArgv);
|
|
434
|
-
if (resolver) {
|
|
435
|
-
const url = walkJiti(resolver, pathExists);
|
|
436
|
-
if (url) return url;
|
|
437
|
-
}
|
|
438
|
-
}
|
|
439
|
-
|
|
440
|
-
return null;
|
|
441
|
-
}
|
|
442
|
-
|
|
443
251
|
/**
|
|
444
252
|
* Build a spawn environment with managed bin, node bin, extra dirs,
|
|
445
253
|
* and common user bin dirs prepended to PATH.
|
|
@@ -15,12 +15,12 @@
|
|
|
15
15
|
* See change: platform-command-executor.
|
|
16
16
|
*/
|
|
17
17
|
import { realpathSync } from "node:fs";
|
|
18
|
-
import { realpath as
|
|
18
|
+
import { realpath as fsRealpath } from "node:fs/promises";
|
|
19
19
|
import path from "node:path";
|
|
20
20
|
import type { GitPrChecks, GitPrState, GitStatus } from "../types.js";
|
|
21
21
|
import { type CheckRollupEntry, collapseCheckRollup } from "./check-rollup.js";
|
|
22
22
|
import { normalizePath, samePath } from "./paths.js";
|
|
23
|
-
import { type Recipe, type Result, run, runAsync, unwrap } from "./runner.js";
|
|
23
|
+
import { type Recipe, type Result, type RunCtx, run, runAsync, unwrap } from "./runner.js";
|
|
24
24
|
|
|
25
25
|
/**
|
|
26
26
|
* Parse `git status --porcelain=v2 --branch` stdout into a `GitStatus`.
|
|
@@ -739,7 +739,7 @@ function realpathOrNull(p: string): string | null {
|
|
|
739
739
|
/** `fs.promises.realpath`, or `null` when the path does not exist. */
|
|
740
740
|
async function realpathOrNullAsync(p: string): Promise<string | null> {
|
|
741
741
|
try {
|
|
742
|
-
return await
|
|
742
|
+
return await fsRealpath(p);
|
|
743
743
|
} catch {
|
|
744
744
|
return null;
|
|
745
745
|
}
|
|
@@ -758,7 +758,7 @@ function canonical(p: string, platform: NodeJS.Platform): string {
|
|
|
758
758
|
* loop outside every git probe timeout — the same DoS the async PROBES exist to
|
|
759
759
|
* avoid. `fs.promises.realpath` keeps the whole path non-blocking.
|
|
760
760
|
*/
|
|
761
|
-
async function canonicalAsync(p: string, platform: NodeJS.Platform): Promise<string> {
|
|
761
|
+
export async function canonicalAsync(p: string, platform: NodeJS.Platform = process.platform): Promise<string> {
|
|
762
762
|
return normalizePath((await realpathOrNullAsync(p)) ?? p, platform);
|
|
763
763
|
}
|
|
764
764
|
|
|
@@ -878,6 +878,206 @@ export async function isBoundCheckoutAsync(
|
|
|
878
878
|
return bindDecision(candidateCanon, commonCanon, reResolved, reCommonCanon, reThisCanon, platform);
|
|
879
879
|
}
|
|
880
880
|
|
|
881
|
+
// ── Classified resolution (harden-plugin-cwd-admission) ─────────────────────
|
|
882
|
+
// The unclassified resolvers above collapse a probe that did not COMPLETE
|
|
883
|
+
// (timeout, spawn failure, …) into the same "no result" as a definitive
|
|
884
|
+
// "not a repository". An authorization consumer must tell them apart: a
|
|
885
|
+
// failure to decide is not a refusal. The classified twins below share the
|
|
886
|
+
// resolution core and read `Result.error.kind` per probe; nothing above changes.
|
|
887
|
+
|
|
888
|
+
/** `fs.promises.realpath` outcome that keeps the errno. */
|
|
889
|
+
export type RealpathOutcome =
|
|
890
|
+
| { kind: "ok"; path: string }
|
|
891
|
+
/** `ENOENT` / `ENOTDIR`: the path (or a parent) does not exist. */
|
|
892
|
+
| { kind: "missing" }
|
|
893
|
+
/** Any other failure (`EACCES`, `ELOOP`, …): existence is undecided. */
|
|
894
|
+
| { kind: "error"; code: string };
|
|
895
|
+
|
|
896
|
+
/** Errno-reporting async realpath. Unlike `realpathOrNullAsync` it never swallows a non-ENOENT error. */
|
|
897
|
+
export async function realpathAsync(p: string): Promise<RealpathOutcome> {
|
|
898
|
+
try {
|
|
899
|
+
return { kind: "ok", path: await fsRealpath(p) };
|
|
900
|
+
} catch (err) {
|
|
901
|
+
const code = (err as NodeJS.ErrnoException)?.code ?? "UNKNOWN";
|
|
902
|
+
if (code === "ENOENT" || code === "ENOTDIR") return { kind: "missing" };
|
|
903
|
+
return { kind: "error", code };
|
|
904
|
+
}
|
|
905
|
+
}
|
|
906
|
+
|
|
907
|
+
/** Runs one git recipe. Production uses `runAsync`; tests inject Results. */
|
|
908
|
+
export type GitProbeRunner = <I, O>(recipe: Recipe<I, O>, input: I, ctx: RunCtx) => Promise<Result<O>>;
|
|
909
|
+
|
|
910
|
+
/** Options shared by the classified resolver and binding check. */
|
|
911
|
+
export interface ClassifiedGitOptions {
|
|
912
|
+
/** Per-probe timeout. */
|
|
913
|
+
timeout?: number;
|
|
914
|
+
/** Aborting terminates in-flight probes (see `RunCtx.signal`). */
|
|
915
|
+
signal?: AbortSignal;
|
|
916
|
+
/** Called once per probe before it is issued. Paired with `onProbeEnd`. */
|
|
917
|
+
onProbeStart?: () => void;
|
|
918
|
+
/** Called once per probe when its child process has ended (or never started). */
|
|
919
|
+
onProbeEnd?: () => void;
|
|
920
|
+
/** Injected runner (tests). Defaults to `runAsync`. */
|
|
921
|
+
runner?: GitProbeRunner;
|
|
922
|
+
/** Injected errno-reporting realpath (tests). Defaults to {@link realpathAsync}. */
|
|
923
|
+
realpath?: (p: string) => Promise<RealpathOutcome>;
|
|
924
|
+
}
|
|
925
|
+
|
|
926
|
+
/** Three-way outcome of the classified checkout-root resolution. */
|
|
927
|
+
export type ClassifiedCheckoutRoots =
|
|
928
|
+
| { kind: "roots"; roots: GitCheckoutRoots }
|
|
929
|
+
/** Definitive: a required probe completed with a non-zero exit — not a repository. */
|
|
930
|
+
| { kind: "none" }
|
|
931
|
+
/** A needed probe did not complete or gave an untrustworthy answer. */
|
|
932
|
+
| { kind: "failed"; failedProbes: string[] };
|
|
933
|
+
|
|
934
|
+
/** Three-way outcome of the classified repository-binding check. */
|
|
935
|
+
export type ClassifiedBinding =
|
|
936
|
+
| { kind: "bound" }
|
|
937
|
+
| { kind: "unbound" }
|
|
938
|
+
| { kind: "failed"; failedProbes: string[] };
|
|
939
|
+
|
|
940
|
+
/** Issue one probe through the (possibly injected) runner, pairing start/end exactly once. */
|
|
941
|
+
function classifiedRunner(opts: ClassifiedGitOptions): <I, O>(recipe: Recipe<I, O>, input: I) => Promise<Result<O>> {
|
|
942
|
+
const runner = opts.runner ?? runAsync;
|
|
943
|
+
const injected = opts.runner !== undefined;
|
|
944
|
+
return async <I, O>(recipe: Recipe<I, O>, input: I): Promise<Result<O>> => {
|
|
945
|
+
let ended = false;
|
|
946
|
+
const end = () => {
|
|
947
|
+
if (ended) return;
|
|
948
|
+
ended = true;
|
|
949
|
+
opts.onProbeEnd?.();
|
|
950
|
+
};
|
|
951
|
+
opts.onProbeStart?.();
|
|
952
|
+
try {
|
|
953
|
+
return await runner(recipe, input, {
|
|
954
|
+
cwd: (input as WithCwd).cwd,
|
|
955
|
+
timeout: opts.timeout,
|
|
956
|
+
signal: opts.signal,
|
|
957
|
+
onClose: end,
|
|
958
|
+
});
|
|
959
|
+
} finally {
|
|
960
|
+
// The real runner reports process exit through `onClose`; an injected one
|
|
961
|
+
// has no process, so settling is the end — unless the probe was aborted,
|
|
962
|
+
// where a process may still be dying and only `onClose` may say so.
|
|
963
|
+
if (injected && !opts.signal?.aborted) end();
|
|
964
|
+
}
|
|
965
|
+
};
|
|
966
|
+
}
|
|
967
|
+
|
|
968
|
+
/**
|
|
969
|
+
* Classified async twin of {@link checkoutRootsAsync}. Same resolution core,
|
|
970
|
+
* different probe adapter (design D1):
|
|
971
|
+
*
|
|
972
|
+
* - `--git-dir` / `--git-common-dir`: non-zero `exit` → definitive "not a repository";
|
|
973
|
+
* any other error kind → failed.
|
|
974
|
+
* - `--show-toplevel`: `exit` → `thisCheckout = null` (bare); other kinds → failed.
|
|
975
|
+
* - `config core.worktree` / `core.bare`: only the tolerated "unset" is an answer;
|
|
976
|
+
* ANY other error (including `exit` ≠ 1, e.g. 128 for a corrupt config) → failed.
|
|
977
|
+
*
|
|
978
|
+
* Any failed probe makes the whole resolution `failed`: it is never read as an
|
|
979
|
+
* unset value and never falls through to a weaker derivation rule.
|
|
980
|
+
*/
|
|
981
|
+
export async function checkoutRootsClassifiedAsync(
|
|
982
|
+
input: WithCwd,
|
|
983
|
+
opts: ClassifiedGitOptions = {},
|
|
984
|
+
): Promise<ClassifiedCheckoutRoots> {
|
|
985
|
+
const exec = classifiedRunner(opts);
|
|
986
|
+
const failed: string[] = [];
|
|
987
|
+
const fail = (name: string) => {
|
|
988
|
+
if (!failed.includes(name)) failed.push(name);
|
|
989
|
+
};
|
|
990
|
+
const roots = await resolveCheckoutRootsFromAsync({
|
|
991
|
+
gitDir: async () => {
|
|
992
|
+
const r = await exec(GIT_DIR_ABS, input);
|
|
993
|
+
if (r.ok) return r.value;
|
|
994
|
+
if (r.error.kind !== "exit") fail("git-dir");
|
|
995
|
+
return undefined;
|
|
996
|
+
},
|
|
997
|
+
commonDir: async () => {
|
|
998
|
+
const r = await exec(GIT_COMMON_DIR_ABS, input);
|
|
999
|
+
if (r.ok) return r.value;
|
|
1000
|
+
if (r.error.kind !== "exit") fail("git-common-dir");
|
|
1001
|
+
return undefined;
|
|
1002
|
+
},
|
|
1003
|
+
topLevel: async () => {
|
|
1004
|
+
const r = await exec(GIT_TOPLEVEL, input);
|
|
1005
|
+
if (r.ok) return r.value;
|
|
1006
|
+
if (r.error.kind !== "exit") fail("show-toplevel");
|
|
1007
|
+
return undefined;
|
|
1008
|
+
},
|
|
1009
|
+
localCoreWorktree: async (commonDir) => {
|
|
1010
|
+
const r = await exec(GIT_CONFIG_LOCAL_CORE_WORKTREE, { cwd: input.cwd, gitDir: commonDir });
|
|
1011
|
+
if (r.ok) return r.value;
|
|
1012
|
+
fail("config core.worktree");
|
|
1013
|
+
return undefined;
|
|
1014
|
+
},
|
|
1015
|
+
localCoreBare: async (commonDir) => {
|
|
1016
|
+
// A failed earlier read already decides the outcome: do not spend a spawn.
|
|
1017
|
+
if (failed.length > 0) return "unknown";
|
|
1018
|
+
const r = await exec(GIT_CONFIG_LOCAL_CORE_BARE, { cwd: input.cwd, gitDir: commonDir });
|
|
1019
|
+
if (!r.ok) {
|
|
1020
|
+
fail("config core.bare");
|
|
1021
|
+
return "unknown";
|
|
1022
|
+
}
|
|
1023
|
+
return r.value === "true" ? "bare" : "not-bare";
|
|
1024
|
+
},
|
|
1025
|
+
});
|
|
1026
|
+
if (failed.length > 0) return { kind: "failed", failedProbes: failed };
|
|
1027
|
+
return roots ? { kind: "roots", roots } : { kind: "none" };
|
|
1028
|
+
}
|
|
1029
|
+
|
|
1030
|
+
/**
|
|
1031
|
+
* Errno-aware canonicalization for a binding compare: follow symlinks, fall back to the
|
|
1032
|
+
* normalized path only when it does not exist, and report `null` for any OTHER failure
|
|
1033
|
+
* (the check cannot be decided — unlike {@link canonicalAsync}, which swallows it).
|
|
1034
|
+
*/
|
|
1035
|
+
async function canonicalClassified(
|
|
1036
|
+
p: string,
|
|
1037
|
+
platform: NodeJS.Platform,
|
|
1038
|
+
realpath: (p: string) => Promise<RealpathOutcome>,
|
|
1039
|
+
): Promise<string | null> {
|
|
1040
|
+
const r = await realpath(p);
|
|
1041
|
+
if (r.kind === "error") return null;
|
|
1042
|
+
return normalizePath(r.kind === "ok" ? r.path : p, platform);
|
|
1043
|
+
}
|
|
1044
|
+
|
|
1045
|
+
/**
|
|
1046
|
+
* Classified twin of {@link isBoundCheckoutAsync}: `bound`, `unbound`, or
|
|
1047
|
+
* `failed` when the candidate's re-resolution could not complete. The
|
|
1048
|
+
* unclassified twin keeps returning `false` for both unbound and failed.
|
|
1049
|
+
*/
|
|
1050
|
+
export async function bindCheckoutClassifiedAsync(
|
|
1051
|
+
candidate: string,
|
|
1052
|
+
commonDir: string,
|
|
1053
|
+
opts: ClassifiedGitOptions = {},
|
|
1054
|
+
): Promise<ClassifiedBinding> {
|
|
1055
|
+
const platform = process.platform;
|
|
1056
|
+
const realpath = opts.realpath ?? realpathAsync;
|
|
1057
|
+
const real = await realpath(candidate);
|
|
1058
|
+
if (real.kind === "missing") return { kind: "unbound" };
|
|
1059
|
+
if (real.kind === "error") return { kind: "failed", failedProbes: ["realpath"] };
|
|
1060
|
+
if (hasGitPathSegment(real.path)) return { kind: "unbound" };
|
|
1061
|
+
const re = await checkoutRootsClassifiedAsync({ cwd: real.path }, opts);
|
|
1062
|
+
if (re.kind === "failed") return re;
|
|
1063
|
+
if (re.kind === "none") return { kind: "unbound" };
|
|
1064
|
+
const reResolved = re.roots;
|
|
1065
|
+
const [candidateCanon, commonCanon, reCommonCanon, reThisCanon] = await Promise.all([
|
|
1066
|
+
canonicalClassified(real.path, platform, realpath),
|
|
1067
|
+
canonicalClassified(commonDir, platform, realpath),
|
|
1068
|
+
canonicalClassified(reResolved.commonDir, platform, realpath),
|
|
1069
|
+
reResolved.thisCheckout ? canonicalClassified(reResolved.thisCheckout, platform, realpath) : Promise.resolve(""),
|
|
1070
|
+
]);
|
|
1071
|
+
// A needed canonicalization that failed for a reason other than non-existence is a
|
|
1072
|
+
// failure to DECIDE, not an "unbound" answer.
|
|
1073
|
+
if (candidateCanon === null || commonCanon === null || reCommonCanon === null || reThisCanon === null) {
|
|
1074
|
+
return { kind: "failed", failedProbes: ["realpath"] };
|
|
1075
|
+
}
|
|
1076
|
+
return bindDecision(candidateCanon, commonCanon, reResolved, reCommonCanon, reThisCanon || null, platform)
|
|
1077
|
+
? { kind: "bound" }
|
|
1078
|
+
: { kind: "unbound" };
|
|
1079
|
+
}
|
|
1080
|
+
|
|
881
1081
|
export function diff(input: WithCwd & { path: string; ref?: string }): Result<string> {
|
|
882
1082
|
return run(GIT_DIFF, input, { cwd: input.cwd });
|
|
883
1083
|
}
|
|
@@ -1,23 +1,33 @@
|
|
|
1
1
|
// resolve/load hooks for the Node-native TypeScript loader, registered by
|
|
2
|
-
// `native-ts-register.mjs`.
|
|
2
|
+
// `native-ts-register.mjs`. STRIP-ONLY: types are erased to whitespace, so
|
|
3
|
+
// line/column numbers stay exact and no source map is needed. Non-erasable
|
|
4
|
+
// syntax (enum, parameter properties, runtime namespace) fails loudly with the
|
|
5
|
+
// file path; there is no transpiling fallback.
|
|
6
|
+
//
|
|
7
|
+
// One resolve/load core, two registrations (design D4):
|
|
8
|
+
// - tier 1: `module.registerHooks` — `resolveSync` / `loadSync` run in-thread.
|
|
9
|
+
// - tiers 2/3: `module.register` — `resolve` / `load` wrap the same helpers
|
|
10
|
+
// as async hooks off-thread; `initialize({ tier })` picks the stripper.
|
|
11
|
+
//
|
|
3
12
|
// - resolve: Node first. Only on a not-found / dir-import failure for a
|
|
4
13
|
// relative or file: specifier, retry `.js→.ts`, `.mjs→.mts`, `.cjs→.cts`;
|
|
5
14
|
// an extensionless specifier tries `.ts .js .mjs /index.ts /index.js`.
|
|
6
15
|
// Bare specifiers are never rewritten. Attribute-less JSON imports get
|
|
7
16
|
// `type: "json"` here (in `load` it is too late — ERR_IMPORT_ATTRIBUTE_MISSING).
|
|
8
|
-
//
|
|
9
|
-
//
|
|
10
|
-
//
|
|
11
|
-
//
|
|
12
|
-
// See change: fix-appimage-cold-boot-latency (design D3)
|
|
13
|
-
|
|
17
|
+
// CommonJS `require()` reports MODULE_NOT_FOUND, so it never takes the retry.
|
|
18
|
+
// - load: every .ts/.mts/.cts is stripped and short-circuited, so it also
|
|
19
|
+
// loads under node_modules where Node refuses native stripping.
|
|
20
|
+
// `.cts` → commonjs, else module.
|
|
21
|
+
// See change: fix-appimage-cold-boot-latency (design D3);
|
|
22
|
+
// strip-only-native-ts-loader (design D4).
|
|
23
|
+
import { readFileSync, statSync } from "node:fs";
|
|
14
24
|
import { readFile } from "node:fs/promises";
|
|
15
|
-
import nodeModule from "node:module";
|
|
25
|
+
import nodeModule, { createRequire } from "node:module";
|
|
16
26
|
import { fileURLToPath } from "node:url";
|
|
17
27
|
|
|
18
|
-
// `stripTypeScriptTypes` emits an ExperimentalWarning
|
|
19
|
-
//
|
|
20
|
-
// reaches stderr.
|
|
28
|
+
// `stripTypeScriptTypes` emits an ExperimentalWarning, from whichever thread
|
|
29
|
+
// strips (the main thread on tier 1, the hooks thread on tiers 2/3). Silence
|
|
30
|
+
// only that warning; every other warning still reaches stderr.
|
|
21
31
|
const originalEmitWarning = process.emitWarning;
|
|
22
32
|
process.emitWarning = function emitWarning(warning, ...rest) {
|
|
23
33
|
const msg = typeof warning === "string" ? warning : warning?.message;
|
|
@@ -30,6 +40,21 @@ const JS_RE = /\.(m|c)?js$/;
|
|
|
30
40
|
const EXT_RE = /\.[a-z0-9]+$/i;
|
|
31
41
|
const EXTENSIONLESS_CANDIDATES = [".ts", ".js", ".mjs", "/index.ts", "/index.js"];
|
|
32
42
|
|
|
43
|
+
// Stripper. Native `stripTypeScriptTypes` by default; tier 3 (Node 23.0-23.1,
|
|
44
|
+
// which has no such API) swaps in the bundled `amaro`, loaded lazily so no
|
|
45
|
+
// other line ever reads it.
|
|
46
|
+
let stripper = (source, url) => nodeModule.stripTypeScriptTypes(source, { mode: "strip", sourceUrl: url });
|
|
47
|
+
|
|
48
|
+
function amaroStripper() {
|
|
49
|
+
const { transformSync } = createRequire(import.meta.url)("amaro");
|
|
50
|
+
return (source, url) => transformSync(source, { mode: "strip-only", filename: fileURLToPath(url) }).code;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
/** Hooks-thread init for `module.register` (tiers 2/3); tier 3 uses amaro. */
|
|
54
|
+
export function initialize(data) {
|
|
55
|
+
if (data?.tier === 3) stripper = amaroStripper();
|
|
56
|
+
}
|
|
57
|
+
|
|
33
58
|
function isFile(url) {
|
|
34
59
|
try {
|
|
35
60
|
return statSync(fileURLToPath(url)).isFile();
|
|
@@ -50,41 +75,69 @@ function withJsonAttribute(result) {
|
|
|
50
75
|
return result;
|
|
51
76
|
}
|
|
52
77
|
|
|
78
|
+
function isRetryable(err) {
|
|
79
|
+
return err?.code === "ERR_MODULE_NOT_FOUND" || err?.code === "ERR_UNSUPPORTED_DIR_IMPORT";
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
/** Candidate URLs to retry after a not-found, or `[]` when the specifier is not eligible. */
|
|
83
|
+
function retryUrls(specifier, parent) {
|
|
84
|
+
if (!isRelativeOrFile(specifier) || !parent?.startsWith("file:")) return [];
|
|
85
|
+
const candidates = [];
|
|
86
|
+
if (JS_RE.test(specifier)) {
|
|
87
|
+
candidates.push(specifier.replace(/\.js$/, ".ts").replace(/\.mjs$/, ".mts").replace(/\.cjs$/, ".cts"));
|
|
88
|
+
} else if (!EXT_RE.test(specifier)) {
|
|
89
|
+
const base = specifier.replace(/\/$/, "");
|
|
90
|
+
for (const ext of EXTENSIONLESS_CANDIDATES) candidates.push(base + ext);
|
|
91
|
+
}
|
|
92
|
+
return candidates.map((c) => new URL(c, parent)).filter(isFile).map((u) => u.href);
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
function stripTs(source, url) {
|
|
96
|
+
try {
|
|
97
|
+
return stripper(source, url);
|
|
98
|
+
} catch (err) {
|
|
99
|
+
const wrapped = new Error(`pi-dashboard native TS loader: cannot strip types from ${fileURLToPath(url)}: ${err?.message ?? err}`);
|
|
100
|
+
wrapped.code = err?.code;
|
|
101
|
+
wrapped.cause = err;
|
|
102
|
+
throw wrapped;
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
const isTsUrl = (url) => url.startsWith("file:") && TS_RE.test(url);
|
|
107
|
+
const tsResult = (url, code) => ({ format: url.endsWith(".cts") ? "commonjs" : "module", source: code, shortCircuit: true });
|
|
108
|
+
|
|
109
|
+
// ── tier 1: synchronous, in-thread (`module.registerHooks`) ─────────────────
|
|
110
|
+
|
|
111
|
+
export function resolveSync(specifier, context, nextResolve) {
|
|
112
|
+
try {
|
|
113
|
+
return withJsonAttribute(nextResolve(specifier, context));
|
|
114
|
+
} catch (err) {
|
|
115
|
+
if (!isRetryable(err)) throw err;
|
|
116
|
+
const [url] = retryUrls(specifier, context.parentURL);
|
|
117
|
+
if (!url) throw err;
|
|
118
|
+
return withJsonAttribute(nextResolve(url, context));
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
export function loadSync(url, context, nextLoad) {
|
|
123
|
+
if (!isTsUrl(url)) return nextLoad(url, context);
|
|
124
|
+
return tsResult(url, stripTs(readFileSync(fileURLToPath(url), "utf8"), url));
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
// ── tiers 2/3: async, off-thread (`module.register`) ────────────────────────
|
|
128
|
+
|
|
53
129
|
export async function resolve(specifier, context, nextResolve) {
|
|
54
130
|
try {
|
|
55
131
|
return withJsonAttribute(await nextResolve(specifier, context));
|
|
56
132
|
} catch (err) {
|
|
57
|
-
if (err
|
|
58
|
-
const
|
|
59
|
-
if (!
|
|
60
|
-
|
|
61
|
-
if (JS_RE.test(specifier)) {
|
|
62
|
-
candidates.push(specifier.replace(/\.js$/, ".ts").replace(/\.mjs$/, ".mts").replace(/\.cjs$/, ".cts"));
|
|
63
|
-
} else if (!EXT_RE.test(specifier)) {
|
|
64
|
-
const base = specifier.replace(/\/$/, "");
|
|
65
|
-
for (const ext of EXTENSIONLESS_CANDIDATES) candidates.push(base + ext);
|
|
66
|
-
}
|
|
67
|
-
for (const candidate of candidates) {
|
|
68
|
-
const url = new URL(candidate, parent);
|
|
69
|
-
if (isFile(url)) return withJsonAttribute(await nextResolve(url.href, context));
|
|
70
|
-
}
|
|
71
|
-
throw err;
|
|
133
|
+
if (!isRetryable(err)) throw err;
|
|
134
|
+
const [url] = retryUrls(specifier, context.parentURL);
|
|
135
|
+
if (!url) throw err;
|
|
136
|
+
return withJsonAttribute(await nextResolve(url, context));
|
|
72
137
|
}
|
|
73
138
|
}
|
|
74
139
|
|
|
75
140
|
export async function load(url, context, nextLoad) {
|
|
76
|
-
if (url
|
|
77
|
-
|
|
78
|
-
let code;
|
|
79
|
-
try {
|
|
80
|
-
code = nodeModule.stripTypeScriptTypes(source, { mode: "transform", sourceUrl: url });
|
|
81
|
-
} catch (err) {
|
|
82
|
-
const wrapped = new Error(`pi-dashboard native TS loader: cannot transform ${fileURLToPath(url)}: ${err?.message ?? err}`);
|
|
83
|
-
wrapped.code = err?.code;
|
|
84
|
-
wrapped.cause = err;
|
|
85
|
-
throw wrapped;
|
|
86
|
-
}
|
|
87
|
-
return { format: url.endsWith(".cts") ? "commonjs" : "module", source: code, shortCircuit: true };
|
|
88
|
-
}
|
|
89
|
-
return nextLoad(url, context);
|
|
141
|
+
if (!isTsUrl(url)) return nextLoad(url, context);
|
|
142
|
+
return tsResult(url, stripTs(await readFile(fileURLToPath(url), "utf8"), url));
|
|
90
143
|
}
|
|
@@ -1,18 +1,30 @@
|
|
|
1
|
-
// Node-native TypeScript loader — the dashboard server's
|
|
2
|
-
//
|
|
3
|
-
//
|
|
4
|
-
//
|
|
1
|
+
// Node-native TypeScript loader — the dashboard server's `--import` loader.
|
|
2
|
+
// Strips types (strip-only) and registers the resolve/load hooks in
|
|
3
|
+
// `native-ts-hooks.mjs` on the best API this Node offers (tier, design D4):
|
|
4
|
+
// `module.registerHooks` (sync, in-thread), else `module.register` with the
|
|
5
|
+
// native stripper, else `module.register` with the bundled `amaro` (EOL 23.0-23.1).
|
|
6
|
+
// No transpile cache, so a read-only bundle (FUSE-mounted AppImage) boots as
|
|
7
|
+
// fast as a writable one.
|
|
5
8
|
//
|
|
6
9
|
// Plain `.mjs` on purpose: it runs before any TypeScript loader exists.
|
|
7
|
-
// See change: fix-appimage-cold-boot-latency (design D3)
|
|
10
|
+
// See change: fix-appimage-cold-boot-latency (design D3);
|
|
11
|
+
// strip-only-native-ts-loader (design D4).
|
|
8
12
|
import nodeModule from "node:module";
|
|
13
|
+
import { loadSync, resolveSync } from "./native-ts-hooks.mjs";
|
|
14
|
+
import { selectLoaderTier } from "./native-ts-tier.mjs";
|
|
9
15
|
|
|
10
|
-
|
|
16
|
+
const tier = selectLoaderTier(nodeModule);
|
|
17
|
+
// The tier names the registration API it needs; fail with a readable message when
|
|
18
|
+
// that exact API is missing (never happens inside the engines range).
|
|
19
|
+
if (typeof (tier === 1 ? nodeModule.registerHooks : nodeModule.register) !== "function") {
|
|
11
20
|
throw new Error(
|
|
12
|
-
`pi-dashboard: this Node (${process.version}) lacks module
|
|
13
|
-
"
|
|
14
|
-
"PI_DASHBOARD_TS_LOADER=jiti to boot with the jiti loader.",
|
|
21
|
+
`pi-dashboard: this Node (${process.version}) lacks the module hook registration API ` +
|
|
22
|
+
"(module.registerHooks / module.register) the native TypeScript loader needs. Use a supported Node (>=22.19.0 <27).",
|
|
15
23
|
);
|
|
16
24
|
}
|
|
17
25
|
|
|
18
|
-
|
|
26
|
+
if (tier === 1) {
|
|
27
|
+
nodeModule.registerHooks({ resolve: resolveSync, load: loadSync });
|
|
28
|
+
} else {
|
|
29
|
+
nodeModule.register("./native-ts-hooks.mjs", import.meta.url, { data: { tier } });
|
|
30
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function selectLoaderTier(mod: { registerHooks?: unknown; stripTypeScriptTypes?: unknown }): 1 | 2 | 3;
|