@blackbelt-technology/pi-agent-dashboard 0.7.0 → 0.9.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/AGENTS.md +26 -57
- package/README.md +41 -22
- package/docs/architecture.md +3722 -213
- package/package.json +52 -33
- package/packages/extension/package.json +30 -16
- package/packages/extension/src/ask-user-tool.ts +4 -0
- package/packages/extension/src/auto-session-namer.ts +486 -70
- package/packages/extension/src/autostart-guard.ts +99 -0
- package/packages/extension/src/autostart-lock.ts +258 -0
- package/packages/extension/src/bridge-activation.ts +26 -0
- package/packages/extension/src/bridge-context.ts +106 -23
- package/packages/extension/src/bridge-default-model-gate.ts +38 -0
- package/packages/extension/src/bridge-polling.ts +148 -0
- package/packages/extension/src/bridge-ticket-client.ts +105 -0
- package/packages/extension/src/bridge.ts +1760 -350
- package/packages/extension/src/canvas-tool.ts +5 -0
- package/packages/extension/src/command-handler.ts +392 -71
- package/packages/extension/src/connect-target.ts +130 -0
- package/packages/extension/src/connection.ts +846 -17
- package/packages/extension/src/custom-entry-forward.ts +92 -0
- package/packages/extension/src/endpoint-resolution.ts +253 -0
- package/packages/extension/src/event-forwarder.ts +42 -0
- package/packages/extension/src/extension-identity.ts +59 -0
- package/packages/extension/src/flow-event-wiring.ts +125 -3
- package/packages/extension/src/followup-buffer.ts +217 -0
- package/packages/extension/src/git-dir-watcher.ts +79 -0
- package/packages/extension/src/git-poll.ts +45 -12
- package/packages/extension/src/git-probe-scheduler.ts +119 -0
- package/packages/extension/src/git-tracker.ts +284 -0
- package/packages/extension/src/instance-verification.ts +156 -0
- package/packages/extension/src/local-token-header.ts +44 -0
- package/packages/extension/src/mcp-token-delivery.ts +147 -0
- package/packages/extension/src/message-update-coalescer.ts +340 -0
- package/packages/extension/src/model-refresh.ts +95 -0
- package/packages/extension/src/model-tracker.ts +118 -35
- package/packages/extension/src/notify-proxy.ts +36 -0
- package/packages/extension/src/path-gate/decide.ts +149 -0
- package/packages/extension/src/path-gate/grant-cache.ts +71 -0
- package/packages/extension/src/path-gate/grant-link.ts +108 -0
- package/packages/extension/src/path-gate/handler.ts +307 -0
- package/packages/extension/src/path-gate/index.ts +155 -0
- package/packages/extension/src/path-gate/resolve.ts +126 -0
- package/packages/extension/src/path-gate/roots.ts +137 -0
- package/packages/extension/src/path-gate/suppression.ts +27 -0
- package/packages/extension/src/pending-prompt-emitter.ts +59 -0
- package/packages/extension/src/pi-env.d.ts +6 -10
- package/packages/extension/src/pi-retry-settings.ts +91 -0
- package/packages/extension/src/plugin-request-client.ts +114 -0
- package/packages/extension/src/poll-cost.ts +40 -0
- package/packages/extension/src/pr-status.ts +338 -0
- package/packages/extension/src/process-metrics.ts +77 -1
- package/packages/extension/src/process-scan-scheduler.ts +137 -0
- package/packages/extension/src/process-scanner.ts +226 -247
- package/packages/extension/src/project-init/dox-kb-config.ts +3 -0
- package/packages/extension/src/project-init/scaffold.ts +1 -4
- package/packages/extension/src/project-init/seed-doctrine.ts +23 -60
- package/packages/extension/src/prompt-bus.ts +13 -0
- package/packages/extension/src/provider-register.ts +92 -21
- package/packages/extension/src/remote-registration-gate.ts +102 -0
- package/packages/extension/src/retry-tracker.ts +258 -86
- package/packages/extension/src/role-manager.ts +38 -91
- package/packages/extension/src/role-model-tools.ts +44 -3
- package/packages/extension/src/server-auto-start.ts +331 -20
- package/packages/extension/src/server-launcher.ts +70 -34
- package/packages/extension/src/server-pin-store.ts +92 -0
- package/packages/extension/src/session-move.ts +275 -0
- package/packages/extension/src/session-sync.ts +75 -20
- package/packages/extension/src/slash-dispatch.ts +66 -81
- package/packages/extension/src/subagent-fanout-admission.ts +234 -0
- package/packages/extension/src/subagent-forward-sites.ts +69 -0
- package/packages/extension/src/subagent-frame-buffer.ts +24 -3
- package/packages/extension/src/subagent-frame-strip.ts +109 -0
- package/packages/extension/src/subagent-saturation.ts +196 -0
- package/packages/extension/src/subagent-tick-throttle.ts +250 -0
- package/packages/extension/src/terminal-reload.ts +298 -0
- package/packages/extension/src/transcript-backfill.ts +151 -0
- package/packages/extension/src/transport-diagnostics.ts +76 -0
- package/packages/extension/src/tui-prompt-adapter.ts +13 -1
- package/packages/extension/src/turn-actionability.ts +20 -0
- package/packages/extension/src/ui-stale-guard.ts +58 -0
- package/packages/extension/src/usage-drain.ts +167 -0
- package/packages/extension/src/vcs-info.ts +261 -63
- package/packages/server/bin/pi-dashboard.mjs +179 -16
- package/packages/server/package.json +57 -15
- package/packages/server/src/access/access-denials.ts +91 -0
- package/packages/server/src/access/access-grants.ts +398 -0
- package/packages/server/src/access/access-health.ts +77 -0
- package/packages/server/src/access/access-plane.ts +192 -0
- package/packages/server/src/access/agent-confirm-registry.ts +102 -0
- package/packages/server/src/access/agent-grant.ts +73 -0
- package/packages/server/src/access/ancestor-ladder.ts +151 -0
- package/packages/server/src/access/canonical-subject.ts +2 -0
- package/packages/server/src/access/capability-issuance.ts +105 -0
- package/packages/server/src/access/containment-gate.ts +310 -0
- package/packages/server/src/access/cors-denial.ts +45 -0
- package/packages/server/src/access/denial-hold.ts +73 -0
- package/packages/server/src/access/forbidden-subjects.ts +2 -0
- package/packages/server/src/access/grant-coordinator.ts +404 -0
- package/packages/server/src/access/grant-store-id.ts +62 -0
- package/packages/server/src/access/hold-request.ts +49 -0
- package/packages/server/src/access/named-grant.ts +73 -0
- package/packages/server/src/access/pending-grant-registry.ts +504 -0
- package/packages/server/src/access/planes.ts +194 -0
- package/packages/server/src/access/prompt-channel.ts +131 -0
- package/packages/server/src/access/refusal-ledger.ts +153 -0
- package/packages/server/src/access/source-channel.ts +33 -0
- package/packages/server/src/access/verified-read.ts +170 -0
- package/packages/server/src/access/yolo-env.ts +60 -0
- package/packages/server/src/access/yolo-session.ts +257 -0
- package/packages/server/src/attachments/attachment-ingest.ts +165 -0
- package/packages/server/src/attachments/attachment-resolver.ts +172 -0
- package/packages/server/src/attachments/display-fit.ts +307 -0
- package/packages/server/src/attachments/fit-worker-pool.ts +390 -0
- package/packages/server/src/attachments/fit-worker.ts +89 -0
- package/packages/server/src/attachments/gif.ts +124 -0
- package/packages/server/src/attachments/image-mime.ts +52 -0
- package/packages/server/src/attachments/original-store.ts +133 -0
- package/packages/server/src/auth/auth-plugin.ts +267 -52
- package/packages/server/src/auth/auth.ts +130 -6
- package/packages/server/src/auth/bearer-auth.ts +74 -5
- package/packages/server/src/auth/begin-flow.ts +165 -0
- package/packages/server/src/auth/bind-reachability-service.ts +132 -0
- package/packages/server/src/auth/bridge-ticket-eligibility.ts +82 -0
- package/packages/server/src/auth/bypass-urls.ts +22 -0
- package/packages/server/src/auth/cors-origin.ts +240 -15
- package/packages/server/src/auth/dashboard-credential-store.ts +301 -0
- package/packages/server/src/auth/host-admission.ts +106 -0
- package/packages/server/src/auth/host-gate.ts +378 -0
- package/packages/server/src/auth/local-proof.ts +105 -0
- package/packages/server/src/auth/local-token.ts +13 -3
- package/packages/server/src/auth/localhost-guard.ts +678 -42
- package/packages/server/src/auth/locked-json-file.ts +316 -0
- package/packages/server/src/auth/loopback.ts +40 -0
- package/packages/server/src/auth/mutation-origin-gate.ts +55 -0
- package/packages/server/src/auth/node-guard.ts +37 -8
- package/packages/server/src/auth/pi-oauth-types.ts +107 -0
- package/packages/server/src/auth/plugin-credential-store.ts +206 -0
- package/packages/server/src/auth/provider-auth-adapter.ts +557 -0
- package/packages/server/src/auth/provider-auth-handlers.ts +15 -287
- package/packages/server/src/auth/provider-auth-registry.ts +234 -0
- package/packages/server/src/auth/provider-auth-storage.ts +404 -84
- package/packages/server/src/auth/radius-mcp.ts +189 -0
- package/packages/server/src/auth/radius-override.ts +103 -0
- package/packages/server/src/auth/route-tier-gate.ts +126 -0
- package/packages/server/src/auth/ws-ticket.ts +118 -12
- package/packages/server/src/auth/ws-upgrade-reject-log.ts +81 -0
- package/packages/server/src/auto-name-outcome-store.ts +92 -0
- package/packages/server/src/browser-handlers/directory-handler.ts +250 -10
- package/packages/server/src/browser-handlers/handler-context.ts +75 -0
- package/packages/server/src/browser-handlers/session-action-handler.ts +615 -69
- package/packages/server/src/browser-handlers/session-action-helpers.ts +14 -17
- package/packages/server/src/browser-handlers/session-lifecycle.ts +67 -0
- package/packages/server/src/browser-handlers/session-meta-handler.ts +161 -48
- package/packages/server/src/browser-handlers/subscription-handler.ts +864 -46
- package/packages/server/src/browser-handlers/terminal-handler.ts +80 -7
- package/packages/server/src/changelog/changelog-parser.ts +1 -1
- package/packages/server/src/changelog/changelog-remote.ts +2 -2
- package/packages/server/src/cli.ts +578 -52
- package/packages/server/src/config-api.ts +190 -3
- package/packages/server/src/config-snapshot.ts +155 -0
- package/packages/server/src/directory-service.ts +833 -72
- package/packages/server/src/embed-lifecycle/embed-lifecycle-controller.ts +17 -1
- package/packages/server/src/event-wiring.ts +1306 -296
- package/packages/server/src/git-worktree/folder-head-poll.ts +34 -20
- package/packages/server/src/git-worktree/git-operations.ts +629 -231
- package/packages/server/src/git-worktree/git-worktree-compose.ts +15 -4
- package/packages/server/src/git-worktree/git-worktree-lifecycle.ts +49 -6
- package/packages/server/src/git-worktree/git-worktree.ts +27 -5
- package/packages/server/src/git-worktree/worktree-init-trust.ts +37 -0
- package/packages/server/src/git-worktree/worktree-init.ts +17 -5
- package/packages/server/src/identity/activation.ts +69 -0
- package/packages/server/src/identity/auth-context.ts +78 -0
- package/packages/server/src/identity/bootstrap-grants.ts +94 -0
- package/packages/server/src/identity/break-glass.ts +76 -0
- package/packages/server/src/identity/browser-login-auth-status.ts +46 -0
- package/packages/server/src/identity/browser-login-config-registry.ts +151 -0
- package/packages/server/src/identity/dispatch.ts +115 -0
- package/packages/server/src/identity/domain-fanout.ts +78 -0
- package/packages/server/src/identity/host-access.ts +47 -0
- package/packages/server/src/identity/host-resources.ts +63 -0
- package/packages/server/src/identity/http-road-classification.ts +181 -0
- package/packages/server/src/identity/identity-floor.ts +44 -0
- package/packages/server/src/identity/identity-me.ts +56 -0
- package/packages/server/src/identity/identity-registration-tracker.ts +66 -0
- package/packages/server/src/identity/identity-road-gate.ts +73 -0
- package/packages/server/src/identity/plugin-identity.ts +98 -0
- package/packages/server/src/identity/policy-registry.ts +181 -0
- package/packages/server/src/identity/principal-guard.ts +92 -0
- package/packages/server/src/identity/resolver-hook.ts +123 -0
- package/packages/server/src/identity/resolver-registry.ts +106 -0
- package/packages/server/src/identity/route-owner-registry.ts +49 -0
- package/packages/server/src/identity/session-access.ts +138 -0
- package/packages/server/src/identity/socket-lifetime.ts +132 -0
- package/packages/server/src/identity/upgrade-gate.ts +35 -0
- package/packages/server/src/identity/ws-message-scope.ts +149 -0
- package/packages/server/src/identity/ws-road-classification.ts +116 -0
- package/packages/server/src/lib/client-dist.ts +162 -0
- package/packages/server/src/lib/diagram-render.ts +214 -0
- package/packages/server/src/lib/eml.ts +34 -14
- package/packages/server/src/lib/grep.ts +3 -1
- package/packages/server/src/lib/office-preview.ts +8 -7
- package/packages/server/src/lib/path-containment.ts +101 -58
- package/packages/server/src/lib/purify.ts +30 -0
- package/packages/server/src/lib/resolve-file-mention.ts +5 -2
- package/packages/server/src/lib/writable-md-target.ts +6 -3
- package/packages/server/src/lifecycle/boot-parent-liveness.ts +52 -7
- package/packages/server/src/lifecycle/bounded-startup.ts +106 -0
- package/packages/server/src/lifecycle/ephemeral-parent-watch.ts +118 -0
- package/packages/server/src/lifecycle/home-lock.ts +174 -25
- package/packages/server/src/lifecycle/home-rendezvous.ts +169 -0
- package/packages/server/src/lifecycle/instance-id.ts +127 -0
- package/packages/server/src/lifecycle/recovery-server.ts +71 -16
- package/packages/server/src/lifecycle/stop-ownership.ts +115 -0
- package/packages/server/src/model-proxy/auth-gate.ts +7 -0
- package/packages/server/src/model-proxy/custom-provider-discovery.ts +18 -10
- package/packages/server/src/model-proxy/internal-auth-storage.ts +126 -123
- package/packages/server/src/model-proxy/internal-registry.ts +199 -32
- package/packages/server/src/model-proxy/oauth-compat.ts +10 -4
- package/packages/server/src/model-proxy/registry-singleton.ts +70 -37
- package/packages/server/src/model-proxy/server-model-runtime.ts +140 -0
- package/packages/server/src/model-proxy/streamer.ts +59 -26
- package/packages/server/src/openspec/global-signature.ts +20 -0
- package/packages/server/src/openspec/openspec-poll-worker-pool.ts +14 -1
- package/packages/server/src/openspec/readiness.ts +85 -0
- package/packages/server/src/package/package-manager-wrapper.ts +68 -4
- package/packages/server/src/package/provider-catalogue-cache.ts +21 -0
- package/packages/server/src/package/provider-probe.ts +78 -9
- package/packages/server/src/pairing/browser-gateway.ts +1792 -69
- package/packages/server/src/pairing/notify-log.ts +100 -0
- package/packages/server/src/pairing/paired-devices.ts +55 -6
- package/packages/server/src/pairing/pairing.ts +253 -13
- package/packages/server/src/pairing/subagent-resync-routing.ts +89 -0
- package/packages/server/src/pending/pending-archive-intent-registry.ts +71 -0
- package/packages/server/src/pending/pending-client-correlations.ts +15 -16
- package/packages/server/src/pending/pending-fork-registry.ts +14 -8
- package/packages/server/src/pending/pending-plugin-ref-registry.ts +249 -0
- package/packages/server/src/pending/pending-principal-owner-registry.ts +98 -0
- package/packages/server/src/pending/pending-prompt-acks.ts +116 -0
- package/packages/server/src/persistence/boot-state.ts +127 -0
- package/packages/server/src/persistence/json-store.ts +8 -2
- package/packages/server/src/persistence/memory-event-store.ts +1193 -45
- package/packages/server/src/persistence/meta-persistence.ts +25 -2
- package/packages/server/src/persistence/migrate-custom-entry-fallback.ts +60 -0
- package/packages/server/src/persistence/preferences-store.ts +502 -9
- package/packages/server/src/pi/bridge-contention.ts +220 -0
- package/packages/server/src/pi/bridge-upgrade-auth.ts +179 -0
- package/packages/server/src/pi/gateway-listeners.ts +75 -0
- package/packages/server/src/pi/gateway-socket-bind.ts +398 -0
- package/packages/server/src/pi/gateway-transport-policy.ts +65 -0
- package/packages/server/src/pi/host-project-trust.ts +62 -0
- package/packages/server/src/pi/pi-core-checker.ts +13 -69
- package/packages/server/src/pi/pi-core-updater.ts +6 -2
- package/packages/server/src/pi/pi-gateway.ts +949 -76
- package/packages/server/src/pi/pi-resource-activation.ts +46 -3
- package/packages/server/src/pi/pi-resource-scanner.ts +186 -12
- package/packages/server/src/pi/pi-resources-watcher.ts +183 -0
- package/packages/server/src/pi/pi-runtime.ts +240 -0
- package/packages/server/src/pi/pi-version-skew.ts +74 -74
- package/packages/server/src/pi/provisional-registration.ts +152 -0
- package/packages/server/src/pi/resource-activation-toggle.ts +376 -91
- package/packages/server/src/pi/resource-entry-ownership.ts +93 -0
- package/packages/server/src/pi/resource-origin.ts +183 -0
- package/packages/server/src/pi/resource-toggle-trust.ts +161 -0
- package/packages/server/src/pi/session-skill-registry.ts +249 -0
- package/packages/server/src/pi-agent-settings.ts +209 -0
- package/packages/server/src/plugin-event-seam.ts +39 -0
- package/packages/server/src/plugin-request-lane.ts +87 -0
- package/packages/server/src/push/build-push-payload.ts +64 -0
- package/packages/server/src/push/push-dispatcher.ts +192 -0
- package/packages/server/src/push/push-service.ts +88 -0
- package/packages/server/src/push/push-token-display.ts +29 -0
- package/packages/server/src/push/push-token-registry.ts +184 -0
- package/packages/server/src/push/push-transports/fcm.ts +128 -0
- package/packages/server/src/push/push-transports/types.ts +67 -0
- package/packages/server/src/push/push-transports/web-push.ts +71 -0
- package/packages/server/src/push/push-transports/webhook-url.ts +164 -0
- package/packages/server/src/push/push-transports/webhook.ts +79 -0
- package/packages/server/src/push/push-vapid.ts +35 -0
- package/packages/server/src/routes/access-prompt-routes.ts +264 -0
- package/packages/server/src/routes/access-routes.ts +429 -0
- package/packages/server/src/routes/attachment-routes.ts +87 -0
- package/packages/server/src/routes/custom-event-groups-routes.ts +34 -0
- package/packages/server/src/routes/doctor-routes.ts +63 -9
- package/packages/server/src/routes/file-routes.ts +374 -62
- package/packages/server/src/routes/git-routes.ts +221 -21
- package/packages/server/src/routes/grep-routes.ts +13 -3
- package/packages/server/src/routes/host-gate-routes.ts +25 -0
- package/packages/server/src/routes/local-proof-routes.ts +49 -0
- package/packages/server/src/routes/model-proxy-diagnostics-routes.ts +5 -1
- package/packages/server/src/routes/model-proxy-routes.ts +352 -251
- package/packages/server/src/routes/network-interfaces.ts +64 -0
- package/packages/server/src/routes/node-runtime-routes.ts +165 -0
- package/packages/server/src/routes/openspec-group-routes.ts +16 -6
- package/packages/server/src/routes/openspec-routes.ts +231 -3
- package/packages/server/src/routes/pairing-routes.ts +314 -13
- package/packages/server/src/routes/pi-core-routes.ts +4 -3
- package/packages/server/src/routes/pi-retry-routes.ts +57 -0
- package/packages/server/src/routes/pi-runtime-routes.ts +181 -0
- package/packages/server/src/routes/plugin-activation-routes.ts +129 -42
- package/packages/server/src/routes/plugin-config-routes.ts +22 -14
- package/packages/server/src/routes/preferences-auto-name-routes.ts +16 -1
- package/packages/server/src/routes/provider-auth-routes.ts +241 -182
- package/packages/server/src/routes/provider-health-cache.ts +46 -0
- package/packages/server/src/routes/provider-routes.ts +416 -33
- package/packages/server/src/routes/push-routes.ts +176 -0
- package/packages/server/src/routes/recommended-routes.ts +119 -25
- package/packages/server/src/routes/resource-activation-routes.ts +150 -14
- package/packages/server/src/routes/runtime-routes.ts +283 -0
- package/packages/server/src/routes/session-routes.ts +342 -15
- package/packages/server/src/routes/system-routes.ts +914 -92
- package/packages/server/src/routes/tool-routes.ts +32 -3
- package/packages/server/src/rpc-keeper/dispatch-reload.ts +339 -0
- package/packages/server/src/rpc-keeper/keeper-log-rotation.cjs +189 -0
- package/packages/server/src/rpc-keeper/keeper-manager.ts +313 -79
- package/packages/server/src/rpc-keeper/keeper.cjs +113 -1
- package/packages/server/src/runtime-overlay/extension-reload.ts +154 -0
- package/packages/server/src/runtime-overlay/runtime-doctor.ts +58 -0
- package/packages/server/src/runtime-overlay/runtime-health.ts +129 -0
- package/packages/server/src/runtime-overlay/runtime-io.ts +140 -0
- package/packages/server/src/runtime-overlay/runtime-stager.ts +283 -0
- package/packages/server/src/runtime-overlay/runtime-update-checker.ts +158 -0
- package/packages/server/src/runtime-publication.ts +134 -0
- package/packages/server/src/runtime-resolution.ts +42 -0
- package/packages/server/src/server-heap-telemetry.ts +89 -0
- package/packages/server/src/server.ts +2472 -508
- package/packages/server/src/session/active-sessions-in-cwd.ts +28 -23
- package/packages/server/src/session/archive-sweeper.ts +112 -0
- package/packages/server/src/session/custom-event-group-annotation.ts +58 -0
- package/packages/server/src/session/custom-event-group-matcher-worker.ts +40 -0
- package/packages/server/src/session/custom-event-group-matcher.ts +242 -0
- package/packages/server/src/session/custom-event-group-resolver.ts +85 -0
- package/packages/server/src/session/death-reason.ts +34 -0
- package/packages/server/src/session/derive-ended-at.ts +56 -0
- package/packages/server/src/session/event-status-extraction.ts +115 -2
- package/packages/server/src/session/host-pressure-tracker.ts +121 -0
- package/packages/server/src/session/memory-session-manager.ts +369 -10
- package/packages/server/src/session/open-tool-calls.ts +146 -0
- package/packages/server/src/session/openspec-locality.ts +112 -0
- package/packages/server/src/session/plugin-refs.ts +133 -0
- package/packages/server/src/session/remote-transcript-store.ts +300 -0
- package/packages/server/src/session/replay-compaction.ts +125 -0
- package/packages/server/src/session/retained-transcript.ts +251 -0
- package/packages/server/src/session/session-api.ts +309 -38
- package/packages/server/src/session/session-archive.ts +418 -0
- package/packages/server/src/session/session-bootstrap.ts +23 -3
- package/packages/server/src/session/session-diff-cache.ts +55 -11
- package/packages/server/src/session/session-diff-source.ts +283 -0
- package/packages/server/src/session/session-diff.ts +106 -15
- package/packages/server/src/session/session-discovery.ts +2 -13
- package/packages/server/src/session/session-file-reader.ts +83 -3
- package/packages/server/src/session/session-load-worker-pool.ts +14 -1
- package/packages/server/src/session/session-load-worker.ts +49 -4
- package/packages/server/src/session/session-origin.ts +128 -0
- package/packages/server/src/session/session-scanner.ts +253 -27
- package/packages/server/src/session/session-stats-reader.ts +10 -13
- package/packages/server/src/session/session-to-meta.ts +57 -1
- package/packages/server/src/spawn-process/cwd-policy.ts +360 -0
- package/packages/server/src/spawn-process/headless-pid-registry.ts +145 -54
- package/packages/server/src/spawn-process/heap-args.ts +163 -0
- package/packages/server/src/spawn-process/process-manager.ts +506 -58
- package/packages/server/src/spawn-process/restart-helper.ts +60 -3
- package/packages/server/src/spawn-process/spawn-failure-log.ts +7 -0
- package/packages/server/src/spawn-process/spawn-recovery-window.ts +37 -0
- package/packages/server/src/spawn-process/spawn-register-watchdog.ts +284 -87
- package/packages/server/src/system-open-capability.ts +5 -24
- package/packages/server/src/terminal/terminal-gateway.ts +38 -3
- package/packages/server/src/terminal/terminal-manager.ts +192 -15
- package/packages/server/src/tunnel/tunnel-block-events.ts +56 -6
- package/packages/server/src/tunnel/tunnel-core.ts +58 -6
- package/packages/server/src/tunnel/tunnel-endpoints.ts +14 -1
- package/packages/server/src/tunnel/tunnel-readiness.ts +219 -0
- package/packages/server/src/tunnel/tunnel.ts +408 -8
- package/packages/server/src/tunnel-providers/daemon-exec.ts +52 -0
- package/packages/server/src/tunnel-providers/ngrok.ts +22 -0
- package/packages/server/src/tunnel-providers/tailscale.ts +137 -3
- package/packages/server/src/tunnel-providers/zerotier.ts +54 -1
- package/packages/server/src/tunnel-providers/zrok.ts +213 -17
- package/packages/shared/package.json +28 -4
- package/packages/shared/src/bind-reachability.ts +452 -0
- package/packages/shared/src/boot-state.ts +73 -0
- package/packages/shared/src/bridge-register.ts +24 -6
- package/packages/shared/src/browser-protocol.ts +846 -24
- package/packages/shared/src/canonical-subject.ts +163 -0
- package/packages/shared/src/card-sections.ts +102 -0
- package/packages/shared/src/config.ts +1204 -29
- package/packages/shared/src/custom-event-groups-store.ts +215 -0
- package/packages/shared/src/custom-event-groups.ts +81 -0
- package/packages/shared/src/cwd-guard.ts +97 -0
- package/packages/shared/src/dashboard-paths.ts +79 -0
- package/packages/shared/src/dashboard-plugin/manifest-types.ts +92 -1
- package/packages/shared/src/dashboard-plugin/plugin-status.ts +7 -0
- package/packages/shared/src/dashboard-plugin/route-descriptor.ts +6 -1
- package/packages/shared/src/dashboard-plugin/slot-props.ts +64 -1
- package/packages/shared/src/dashboard-plugin/slot-types.ts +27 -0
- package/packages/shared/src/dashboard-plugin/ui-primitives.ts +92 -1
- package/packages/shared/src/display-prefs.ts +238 -3
- package/packages/shared/src/doctor-core.ts +371 -22
- package/packages/shared/src/electron-restart.ts +15 -0
- package/packages/shared/src/file-kind.ts +25 -1
- package/packages/shared/src/forbidden-subjects.ts +186 -0
- package/packages/shared/src/grammar-types.ts +88 -0
- package/packages/shared/src/heap-flags.ts +244 -0
- package/packages/shared/src/heap-limits.ts +159 -0
- package/packages/shared/src/host-admission.ts +124 -0
- package/packages/shared/src/host-pressure.ts +24 -0
- package/packages/shared/src/identity.ts +179 -0
- package/packages/shared/src/image-block.ts +118 -0
- package/packages/shared/src/instance-directory.ts +124 -0
- package/packages/shared/src/launch-source-types.ts +8 -2
- package/packages/shared/src/legacy-managed-dir.ts +99 -14
- package/packages/shared/src/mdns-discovery.ts +91 -2
- package/packages/shared/src/memory-limits.ts +140 -0
- package/packages/shared/src/model-catalogue.ts +78 -0
- package/packages/shared/src/models-json-reader.ts +7 -0
- package/packages/shared/src/node-installs/candidates.ts +296 -0
- package/packages/shared/src/node-installs/child-path.ts +79 -0
- package/packages/shared/src/node-installs/coherence.ts +160 -0
- package/packages/shared/src/node-installs/index.ts +42 -0
- package/packages/shared/src/node-installs/select.ts +158 -0
- package/packages/shared/src/node-installs/vm-roots.ts +92 -0
- package/packages/shared/src/node-version.ts +86 -14
- package/packages/shared/src/notify.ts +16 -0
- package/packages/shared/src/openspec-activity-detector.ts +74 -6
- package/packages/shared/src/openspec-poller.ts +46 -11
- package/packages/shared/src/path-containment.ts +41 -0
- package/packages/shared/src/pi-installs/candidates.ts +361 -0
- package/packages/shared/src/pi-installs/index.ts +46 -0
- package/packages/shared/src/pi-installs/installs.ts +149 -0
- package/packages/shared/src/pi-installs/validate.ts +111 -0
- package/packages/shared/src/pi-installs/versions.ts +65 -0
- package/packages/shared/src/pi-package-resolver.ts +41 -10
- package/packages/shared/src/platform/binary-lookup.ts +13 -9
- package/packages/shared/src/platform/check-rollup.ts +74 -0
- package/packages/shared/src/platform/env-path-key.ts +55 -0
- package/packages/shared/src/platform/exec.ts +32 -5
- package/packages/shared/src/platform/git.ts +671 -23
- package/packages/shared/src/platform/index.ts +13 -10
- package/packages/shared/src/platform/native-module-abi.ts +540 -0
- package/packages/shared/src/platform/native-ts-hooks.mjs +90 -0
- package/packages/shared/src/platform/native-ts-register.mjs +18 -0
- package/packages/shared/src/platform/node-spawn.ts +19 -0
- package/packages/shared/src/platform/openspec.ts +70 -4
- package/packages/shared/src/platform/paths.ts +84 -0
- package/packages/shared/src/platform/process-identify.ts +93 -0
- package/packages/shared/src/platform/process.ts +74 -0
- package/packages/shared/src/platform/runner.ts +84 -12
- package/packages/shared/src/platform/spawn-mechanism.ts +59 -6
- package/packages/shared/src/platform/spawn-runtime.ts +974 -0
- package/packages/shared/src/platform/system-open.ts +46 -0
- package/packages/shared/src/platform/ts-loader-select.d.mts +10 -0
- package/packages/shared/src/platform/ts-loader-select.mjs +84 -0
- package/packages/shared/src/protocol.ts +696 -22
- package/packages/shared/src/provider-model-metadata.ts +135 -0
- package/packages/shared/src/recommended-extensions.ts +173 -17
- package/packages/shared/src/recovery-timing.ts +34 -0
- package/packages/shared/src/renderer-by-ext.ts +6 -1
- package/packages/shared/src/rendezvous.ts +94 -0
- package/packages/shared/src/rest-api.ts +435 -20
- package/packages/shared/src/role-schema.ts +201 -0
- package/packages/shared/src/route-tiers.ts +377 -0
- package/packages/shared/src/runtime-overlay/compat.ts +91 -0
- package/packages/shared/src/runtime-overlay/manifest.d.mts +22 -0
- package/packages/shared/src/runtime-overlay/manifest.mjs +63 -0
- package/packages/shared/src/runtime-overlay/materialize-plugins.d.mts +10 -0
- package/packages/shared/src/runtime-overlay/materialize-plugins.mjs +71 -0
- package/packages/shared/src/runtime-overlay/state.ts +268 -0
- package/packages/shared/src/server-identity.ts +39 -10
- package/packages/shared/src/server-launcher.ts +63 -8
- package/packages/shared/src/server-pinning.ts +179 -0
- package/packages/shared/src/session-group-by.ts +50 -0
- package/packages/shared/src/session-meta.ts +114 -7
- package/packages/shared/src/state-replay.ts +126 -14
- package/packages/shared/src/terminal-types.ts +7 -0
- package/packages/shared/src/tiers.ts +47 -0
- package/packages/shared/src/tool-registry/default-registry.ts +76 -0
- package/packages/shared/src/tool-registry/definitions.ts +241 -18
- package/packages/shared/src/tool-registry/ensure-cli.ts +138 -0
- package/packages/shared/src/tool-registry/ensure.ts +200 -0
- package/packages/shared/src/tool-registry/index.ts +16 -40
- package/packages/shared/src/tool-registry/overrides.ts +24 -2
- package/packages/shared/src/tool-registry/pi-tools.ts +258 -0
- package/packages/shared/src/tool-registry/registry.ts +46 -5
- package/packages/shared/src/tool-registry/strategies.ts +295 -31
- package/packages/shared/src/tool-registry/types.ts +57 -5
- package/packages/shared/src/transcript-request-guard.ts +83 -0
- package/packages/shared/src/tunnel-concurrency.ts +158 -0
- package/packages/shared/src/tunnel-provider.ts +119 -0
- package/packages/shared/src/types.ts +399 -25
- package/packages/shared/src/usage-totals.ts +127 -0
- package/tsconfig.base.json +27 -0
- package/packages/extension/src/AGENTS.md +0 -57
- package/packages/extension/src/__tests__/abort-latch.test.ts +0 -97
- package/packages/extension/src/__tests__/agent-settled.test.ts +0 -82
- package/packages/extension/src/__tests__/artifact-roots.test.ts +0 -83
- package/packages/extension/src/__tests__/ask-user-attachments.test.ts +0 -106
- package/packages/extension/src/__tests__/ask-user-schema-discriminator.test.ts +0 -141
- package/packages/extension/src/__tests__/ask-user-tool.test.ts +0 -571
- package/packages/extension/src/__tests__/auto-session-namer.test.ts +0 -339
- package/packages/extension/src/__tests__/bridge-default-model-apply.test.ts +0 -242
- package/packages/extension/src/__tests__/bridge-default-model-gate.test.ts +0 -50
- package/packages/extension/src/__tests__/bridge-entry-id-pi-070.test.ts +0 -174
- package/packages/extension/src/__tests__/bridge-followup-chat-order.test.ts +0 -215
- package/packages/extension/src/__tests__/bridge-followup-multi-entry.test.ts +0 -202
- package/packages/extension/src/__tests__/bridge-followup-mutation.test.ts +0 -217
- package/packages/extension/src/__tests__/bridge-followup-queue-drain.test.ts +0 -266
- package/packages/extension/src/__tests__/bridge-hasui-flip.test.ts +0 -109
- package/packages/extension/src/__tests__/bridge-no-queue-mutation.test.ts +0 -112
- package/packages/extension/src/__tests__/bridge-plugin-emit-event.test.ts +0 -44
- package/packages/extension/src/__tests__/bridge-queue-update-forward.test.ts +0 -77
- package/packages/extension/src/__tests__/bridge-resume-disconnect.test.ts +0 -333
- package/packages/extension/src/__tests__/bridge-shadow-queue-gate.test.ts +0 -299
- package/packages/extension/src/__tests__/bridge-shutdown-reset.test.ts +0 -159
- package/packages/extension/src/__tests__/bridge-slash-command-routing.test.ts +0 -458
- package/packages/extension/src/__tests__/bridge-stop-after-turn.test.ts +0 -72
- package/packages/extension/src/__tests__/bridge-system-followup.test.ts +0 -163
- package/packages/extension/src/__tests__/bridge-thinking-level-select.test.ts +0 -68
- package/packages/extension/src/__tests__/browser-skill-registered.test.ts +0 -84
- package/packages/extension/src/__tests__/build-provider-catalogue.test.ts +0 -210
- package/packages/extension/src/__tests__/command-handler.test.ts +0 -1180
- package/packages/extension/src/__tests__/commit-draft.test.ts +0 -100
- package/packages/extension/src/__tests__/connection-dropped-frames.test.ts +0 -78
- package/packages/extension/src/__tests__/connection-suppress-auto-start.test.ts +0 -97
- package/packages/extension/src/__tests__/connection.test.ts +0 -344
- package/packages/extension/src/__tests__/credentials-updated.test.ts +0 -26
- package/packages/extension/src/__tests__/custom-provider-apikey-roundtrip.test.ts +0 -128
- package/packages/extension/src/__tests__/cwd-missing-probe.test.ts +0 -82
- package/packages/extension/src/__tests__/dashboard-commands-shipped.test.ts +0 -53
- package/packages/extension/src/__tests__/dashboard-context-injector.test.ts +0 -190
- package/packages/extension/src/__tests__/dashboard-default-adapter.test.ts +0 -77
- package/packages/extension/src/__tests__/dev-build.test.ts +0 -79
- package/packages/extension/src/__tests__/doctor/checks.test.ts +0 -121
- package/packages/extension/src/__tests__/doctor/modules.test.ts +0 -64
- package/packages/extension/src/__tests__/doctor/provenance-hash.test.ts +0 -94
- package/packages/extension/src/__tests__/doctor/router.test.ts +0 -143
- package/packages/extension/src/__tests__/empty-actionable-guard-config.test.ts +0 -32
- package/packages/extension/src/__tests__/empty-actionable-guard.test.ts +0 -73
- package/packages/extension/src/__tests__/enrich-model-metadata.test.ts +0 -222
- package/packages/extension/src/__tests__/event-forwarder.test.ts +0 -119
- package/packages/extension/src/__tests__/extension-slash-command-detection.test.ts +0 -143
- package/packages/extension/src/__tests__/filter-enabled-models.test.ts +0 -151
- package/packages/extension/src/__tests__/fixtures/turn-actionability-fixtures.ts +0 -69
- package/packages/extension/src/__tests__/fork-entryid-timing.test.ts +0 -88
- package/packages/extension/src/__tests__/git-info-status.test.ts +0 -73
- package/packages/extension/src/__tests__/git-link-builder.test.ts +0 -102
- package/packages/extension/src/__tests__/git-poll.test.ts +0 -69
- package/packages/extension/src/__tests__/markdown-image-inliner.test.ts +0 -392
- package/packages/extension/src/__tests__/model-resolve.test.ts +0 -379
- package/packages/extension/src/__tests__/multiselect-dashboard-routing.test.ts +0 -203
- package/packages/extension/src/__tests__/multiselect-list.test.ts +0 -137
- package/packages/extension/src/__tests__/multiselect-polyfill.test.ts +0 -92
- package/packages/extension/src/__tests__/no-session-replacement-calls.test.ts +0 -99
- package/packages/extension/src/__tests__/no-tui-multiselect-arm-regression.test.ts +0 -81
- package/packages/extension/src/__tests__/openspec-activity-detector.test.ts +0 -337
- package/packages/extension/src/__tests__/openspec-cli-shim.test.ts +0 -145
- package/packages/extension/src/__tests__/openspec-poller.test.ts +0 -124
- package/packages/extension/src/__tests__/pi-version-tracker.test.ts +0 -109
- package/packages/extension/src/__tests__/process-metrics.test.ts +0 -47
- package/packages/extension/src/__tests__/process-scanner-kill.test.ts +0 -61
- package/packages/extension/src/__tests__/process-scanner.test.ts +0 -292
- package/packages/extension/src/__tests__/project-init-detect-stack.test.ts +0 -61
- package/packages/extension/src/__tests__/project-init-dox-kb-config.test.ts +0 -53
- package/packages/extension/src/__tests__/project-init-profiles.test.ts +0 -84
- package/packages/extension/src/__tests__/project-init-scaffold.test.ts +0 -139
- package/packages/extension/src/__tests__/project-init-seed-doctrine.test.ts +0 -100
- package/packages/extension/src/__tests__/project-trust.test.ts +0 -92
- package/packages/extension/src/__tests__/prompt-bus-wiring.test.ts +0 -791
- package/packages/extension/src/__tests__/prompt-bus.test.ts +0 -513
- package/packages/extension/src/__tests__/prompt-expander.test.ts +0 -398
- package/packages/extension/src/__tests__/provider-register-native-models.test.ts +0 -182
- package/packages/extension/src/__tests__/provider-register-reload.test.ts +0 -498
- package/packages/extension/src/__tests__/provider-register-thinking-levels.test.ts +0 -104
- package/packages/extension/src/__tests__/retry-tracker.test.ts +0 -152
- package/packages/extension/src/__tests__/role-manager.test.ts +0 -585
- package/packages/extension/src/__tests__/role-model-tools-registry-readiness.test.ts +0 -114
- package/packages/extension/src/__tests__/role-model-tools.test.ts +0 -229
- package/packages/extension/src/__tests__/search-files-completeness.test.ts +0 -111
- package/packages/extension/src/__tests__/search-files-ranking.test.ts +0 -168
- package/packages/extension/src/__tests__/server-auto-start.test.ts +0 -375
- package/packages/extension/src/__tests__/server-launcher-launch.test.ts +0 -96
- package/packages/extension/src/__tests__/server-launcher.test.ts +0 -101
- package/packages/extension/src/__tests__/server-probe.test.ts +0 -25
- package/packages/extension/src/__tests__/session-switch.test.ts +0 -139
- package/packages/extension/src/__tests__/session-sync.test.ts +0 -243
- package/packages/extension/src/__tests__/single-derivation-guard.test.ts +0 -39
- package/packages/extension/src/__tests__/source-detector.test.ts +0 -88
- package/packages/extension/src/__tests__/stats-extractor.test.ts +0 -92
- package/packages/extension/src/__tests__/subagent-frame-buffer.test.ts +0 -239
- package/packages/extension/src/__tests__/tool-result-image-inliner.test.ts +0 -206
- package/packages/extension/src/__tests__/tui-prompt-adapter.test.ts +0 -213
- package/packages/extension/src/__tests__/turn-actionability.test.ts +0 -86
- package/packages/extension/src/__tests__/ui-decorators.test.ts +0 -309
- package/packages/extension/src/__tests__/ui-modules.test.ts +0 -293
- package/packages/extension/src/__tests__/vcs-info.test.ts +0 -265
- package/packages/extension/src/__tests__/visibility-intent.test.ts +0 -43
- package/packages/extension/src/__tests__/watchdog.test.ts +0 -161
- package/packages/extension/src/abort-latch.ts.AGENTS.md +0 -3
- package/packages/extension/src/agent-settled.ts +0 -72
- package/packages/extension/src/agent-settled.ts.AGENTS.md +0 -3
- package/packages/extension/src/artifact-roots.ts.AGENTS.md +0 -3
- package/packages/extension/src/ask-user-attachments.ts.AGENTS.md +0 -3
- package/packages/extension/src/ask-user-tool.ts.AGENTS.md +0 -3
- package/packages/extension/src/auto-session-namer.ts.AGENTS.md +0 -3
- package/packages/extension/src/bridge-context.ts.AGENTS.md +0 -3
- package/packages/extension/src/bridge-default-model-gate.ts.AGENTS.md +0 -3
- package/packages/extension/src/bridge.ts.AGENTS.md +0 -3
- package/packages/extension/src/command-handler.ts.AGENTS.md +0 -3
- package/packages/extension/src/commit-draft-agent.ts.AGENTS.md +0 -3
- package/packages/extension/src/commit-draft.ts.AGENTS.md +0 -3
- package/packages/extension/src/connection.ts.AGENTS.md +0 -3
- package/packages/extension/src/dashboard-context-injector.ts.AGENTS.md +0 -3
- package/packages/extension/src/dashboard-default-adapter.ts.AGENTS.md +0 -3
- package/packages/extension/src/dev-build.ts.AGENTS.md +0 -3
- package/packages/extension/src/empty-actionable-guard-config.ts.AGENTS.md +0 -3
- package/packages/extension/src/empty-actionable-guard.ts.AGENTS.md +0 -3
- package/packages/extension/src/event-forwarder.ts.AGENTS.md +0 -3
- package/packages/extension/src/flow-event-wiring.ts.AGENTS.md +0 -3
- package/packages/extension/src/git-link-builder.ts.AGENTS.md +0 -3
- package/packages/extension/src/git-poll.ts.AGENTS.md +0 -3
- package/packages/extension/src/hasui-flip.ts.AGENTS.md +0 -3
- package/packages/extension/src/markdown-image-inliner.ts.AGENTS.md +0 -3
- package/packages/extension/src/model-tracker.ts.AGENTS.md +0 -3
- package/packages/extension/src/multiselect-decode.ts.AGENTS.md +0 -3
- package/packages/extension/src/multiselect-list.ts.AGENTS.md +0 -3
- package/packages/extension/src/multiselect-polyfill.ts.AGENTS.md +0 -3
- package/packages/extension/src/openspec-cli-shim.ts.AGENTS.md +0 -7
- package/packages/extension/src/process-metrics.ts.AGENTS.md +0 -3
- package/packages/extension/src/process-scanner.ts.AGENTS.md +0 -3
- package/packages/extension/src/project-init/AGENTS.md +0 -12
- package/packages/extension/src/project-trust.ts.AGENTS.md +0 -3
- package/packages/extension/src/prompt-bus.ts.AGENTS.md +0 -3
- package/packages/extension/src/prompt-expander.ts.AGENTS.md +0 -3
- package/packages/extension/src/provider-register.ts.AGENTS.md +0 -3
- package/packages/extension/src/retry-tracker.ts.AGENTS.md +0 -3
- package/packages/extension/src/role-manager.ts.AGENTS.md +0 -3
- package/packages/extension/src/role-model-tools.ts.AGENTS.md +0 -3
- package/packages/extension/src/server-auto-start.ts.AGENTS.md +0 -3
- package/packages/extension/src/server-launcher.ts.AGENTS.md +0 -3
- package/packages/extension/src/session-sync.ts.AGENTS.md +0 -3
- package/packages/extension/src/slash-dispatch.ts.AGENTS.md +0 -3
- package/packages/extension/src/source-detector.ts.AGENTS.md +0 -3
- package/packages/extension/src/subagent-frame-buffer.ts.AGENTS.md +0 -3
- package/packages/extension/src/tool-result-image-inliner.ts.AGENTS.md +0 -3
- package/packages/extension/src/tui-prompt-adapter.ts.AGENTS.md +0 -3
- package/packages/extension/src/turn-actionability.ts.AGENTS.md +0 -3
- package/packages/extension/src/ui-modules.ts.AGENTS.md +0 -3
- package/packages/extension/src/vcs-info.ts.AGENTS.md +0 -3
- package/packages/extension/src/visibility-intent.ts.AGENTS.md +0 -3
- package/packages/server/src/AGENTS.md +0 -20
- package/packages/server/src/__tests__/active-sessions-in-cwd.test.ts +0 -97
- package/packages/server/src/__tests__/attach-proposal-replay.test.ts +0 -92
- package/packages/server/src/__tests__/auth-plugin.test.ts +0 -117
- package/packages/server/src/__tests__/auth.test.ts +0 -224
- package/packages/server/src/__tests__/auto-attach-slug-defense.test.ts +0 -101
- package/packages/server/src/__tests__/auto-attach.test.ts +0 -302
- package/packages/server/src/__tests__/auto-resume.test.ts +0 -135
- package/packages/server/src/__tests__/auto-shutdown.test.ts +0 -134
- package/packages/server/src/__tests__/automation-session-close.test.ts +0 -73
- package/packages/server/src/__tests__/bearer-auth.test.ts +0 -67
- package/packages/server/src/__tests__/boot-parent-liveness.test.ts +0 -48
- package/packages/server/src/__tests__/bridge-register-nondestructive.test.ts +0 -108
- package/packages/server/src/__tests__/browse-endpoint.test.ts +0 -616
- package/packages/server/src/__tests__/browser-gateway-broadcast-serialize-once.test.ts +0 -144
- package/packages/server/src/__tests__/browser-gateway-dropped-frames.test.ts +0 -96
- package/packages/server/src/__tests__/browser-gateway-handler-errors.test.ts +0 -129
- package/packages/server/src/__tests__/browser-gateway-load.test.ts +0 -233
- package/packages/server/src/__tests__/browser-gateway-plugin-action-fanout.test.ts +0 -113
- package/packages/server/src/__tests__/browser-gateway-register-handler.test.ts +0 -69
- package/packages/server/src/__tests__/browser-gateway-role-remove.test.ts +0 -68
- package/packages/server/src/__tests__/browser-gateway-snapshot-on-connect.test.ts +0 -187
- package/packages/server/src/__tests__/build-auth-status.test.ts +0 -190
- package/packages/server/src/__tests__/bulk-archive-handler.test.ts +0 -15
- package/packages/server/src/__tests__/canvas-accumulator.test.ts +0 -187
- package/packages/server/src/__tests__/canvas-settings.test.ts +0 -68
- package/packages/server/src/__tests__/changelog-fs.test.ts +0 -231
- package/packages/server/src/__tests__/changelog-parser.test.ts +0 -220
- package/packages/server/src/__tests__/changelog-remote.test.ts +0 -193
- package/packages/server/src/__tests__/cli-env-no-clobber.test.ts +0 -46
- package/packages/server/src/__tests__/cli-no-bootstrap-references.test.ts +0 -69
- package/packages/server/src/__tests__/cli-parse.test.ts +0 -149
- package/packages/server/src/__tests__/cli-restart.test.ts +0 -78
- package/packages/server/src/__tests__/cli-version.test.ts +0 -151
- package/packages/server/src/__tests__/client-discovery.test.ts +0 -39
- package/packages/server/src/__tests__/cold-boot-openspec-broadcast.test.ts +0 -161
- package/packages/server/src/__tests__/cold-start-recovery-exempt.test.ts +0 -94
- package/packages/server/src/__tests__/commit-draft-relay.test.ts +0 -61
- package/packages/server/src/__tests__/concurrent-launch.test.ts +0 -110
- package/packages/server/src/__tests__/config-api.test.ts +0 -188
- package/packages/server/src/__tests__/cors.test.ts +0 -117
- package/packages/server/src/__tests__/crash-recovery.test.ts +0 -88
- package/packages/server/src/__tests__/csp.test.ts +0 -71
- package/packages/server/src/__tests__/cwd-missing-handling.test.ts +0 -101
- package/packages/server/src/__tests__/dashboard-source-decision.test.ts +0 -156
- package/packages/server/src/__tests__/decorate-goals-spend.test.ts +0 -79
- package/packages/server/src/__tests__/directory-service-eventloop-turns.test.ts +0 -211
- package/packages/server/src/__tests__/directory-service-folderhead-async.test.ts +0 -145
- package/packages/server/src/__tests__/directory-service-known-dirs.test.ts +0 -125
- package/packages/server/src/__tests__/directory-service-openspec-enabled.test.ts +0 -211
- package/packages/server/src/__tests__/directory-service-pending-emit.test.ts +0 -226
- package/packages/server/src/__tests__/directory-service-refresh-force.test.ts +0 -187
- package/packages/server/src/__tests__/directory-service-specs-mtime.test.ts +0 -351
- package/packages/server/src/__tests__/directory-service-toctou.test.ts +0 -321
- package/packages/server/src/__tests__/directory-service-watcher-dedup.test.ts +0 -166
- package/packages/server/src/__tests__/directory-service.test.ts +0 -666
- package/packages/server/src/__tests__/dispatch-extension-command-router.test.ts +0 -178
- package/packages/server/src/__tests__/doctor-route.test.ts +0 -329
- package/packages/server/src/__tests__/draining-ws.test.ts +0 -131
- package/packages/server/src/__tests__/e2e/model-proxy-google-flash.test.ts +0 -184
- package/packages/server/src/__tests__/embed-lifecycle-boot-smoke.test.ts +0 -44
- package/packages/server/src/__tests__/eml-cache.test.ts +0 -60
- package/packages/server/src/__tests__/event-status-extraction.test.ts +0 -58
- package/packages/server/src/__tests__/event-wiring-is-git-repo.test.ts +0 -128
- package/packages/server/src/__tests__/event-wiring-process-classify.test.ts +0 -122
- package/packages/server/src/__tests__/event-wiring-providers-list.test.ts +0 -152
- package/packages/server/src/__tests__/event-wiring-queue-state.test.ts +0 -154
- package/packages/server/src/__tests__/event-wiring-resume-clear.test.ts +0 -103
- package/packages/server/src/__tests__/event-wiring-roles-list-builtin.test.ts +0 -90
- package/packages/server/src/__tests__/event-wiring-source-stamp.test.ts +0 -180
- package/packages/server/src/__tests__/event-wiring-worktree-rekey.test.ts +0 -157
- package/packages/server/src/__tests__/eventloop-sampler.test.ts +0 -111
- package/packages/server/src/__tests__/eventloop-spike-metrics.test.ts +0 -60
- package/packages/server/src/__tests__/extension-register-appimage.test.ts +0 -43
- package/packages/server/src/__tests__/extension-register.test.ts +0 -67
- package/packages/server/src/__tests__/faux-echo-system-context.unit.test.ts +0 -31
- package/packages/server/src/__tests__/faux-router.unit.test.ts +0 -71
- package/packages/server/src/__tests__/faux-session.integration.test.ts +0 -316
- package/packages/server/src/__tests__/file-absolute-containment.test.ts +0 -224
- package/packages/server/src/__tests__/file-artifact-serving.test.ts +0 -189
- package/packages/server/src/__tests__/file-endpoint.test.ts +0 -49
- package/packages/server/src/__tests__/file-kind-endpoint.test.ts +0 -133
- package/packages/server/src/__tests__/file-raw-render-endpoints.test.ts +0 -936
- package/packages/server/src/__tests__/file-tree-endpoint.test.ts +0 -90
- package/packages/server/src/__tests__/file-watch-manager.test.ts +0 -88
- package/packages/server/src/__tests__/file-write-endpoint.test.ts +0 -222
- package/packages/server/src/__tests__/find-port-holders.test.ts +0 -94
- package/packages/server/src/__tests__/fix-pty-permissions.test.ts +0 -59
- package/packages/server/src/__tests__/fixtures/fork-jsonl-roundtrip.jsonl +0 -8
- package/packages/server/src/__tests__/fixtures/pi-changelog-slice.md +0 -180
- package/packages/server/src/__tests__/folder-head-integration.test.ts +0 -83
- package/packages/server/src/__tests__/folder-head-poll.test.ts +0 -167
- package/packages/server/src/__tests__/folder-head-watcher.test.ts +0 -133
- package/packages/server/src/__tests__/force-kill-handler.test.ts +0 -158
- package/packages/server/src/__tests__/fork-empty-session-preflight.test.ts +0 -268
- package/packages/server/src/__tests__/fork-jsonl-roundtrip.test.ts +0 -49
- package/packages/server/src/__tests__/genuine-local.test.ts +0 -96
- package/packages/server/src/__tests__/git-commit-operations.test.ts +0 -153
- package/packages/server/src/__tests__/git-operations.test.ts +0 -312
- package/packages/server/src/__tests__/git-pr-operations.test.ts +0 -299
- package/packages/server/src/__tests__/git-worktree-compose.test.ts +0 -57
- package/packages/server/src/__tests__/git-worktree-lifecycle-ops.test.ts +0 -363
- package/packages/server/src/__tests__/git-worktree-lifecycle-routes.test.ts +0 -322
- package/packages/server/src/__tests__/git-worktree-lifecycle.test.ts +0 -161
- package/packages/server/src/__tests__/git-worktree-ops.test.ts +0 -263
- package/packages/server/src/__tests__/git-worktree-routes.test.ts +0 -342
- package/packages/server/src/__tests__/git-worktree.test.ts +0 -395
- package/packages/server/src/__tests__/goal-budget-guard.test.ts +0 -32
- package/packages/server/src/__tests__/goal-routes.test.ts +0 -302
- package/packages/server/src/__tests__/goal-session-primer.test.ts +0 -53
- package/packages/server/src/__tests__/goal-status-projector.test.ts +0 -133
- package/packages/server/src/__tests__/goal-store.test.ts +0 -364
- package/packages/server/src/__tests__/goal-supervisor.test.ts +0 -321
- package/packages/server/src/__tests__/goal-verdict-accumulator.test.ts +0 -90
- package/packages/server/src/__tests__/grep.test.ts +0 -95
- package/packages/server/src/__tests__/has-openspec-dir.test.ts +0 -64
- package/packages/server/src/__tests__/headless-pid-registry-goal-id.test.ts +0 -71
- package/packages/server/src/__tests__/headless-pid-registry-kill-by-token.test.ts +0 -107
- package/packages/server/src/__tests__/headless-pid-registry-kill-escalation.test.ts +0 -163
- package/packages/server/src/__tests__/headless-pid-registry.test.ts +0 -561
- package/packages/server/src/__tests__/headless-shutdown-fallback.test.ts +0 -112
- package/packages/server/src/__tests__/health-compatibility.test.ts +0 -81
- package/packages/server/src/__tests__/health-endpoint.test.ts +0 -39
- package/packages/server/src/__tests__/health-shape.test.ts +0 -129
- package/packages/server/src/__tests__/heartbeat-ack.test.ts +0 -63
- package/packages/server/src/__tests__/helpers/draining-ws.ts +0 -170
- package/packages/server/src/__tests__/helpers/load-fixtures.ts +0 -152
- package/packages/server/src/__tests__/hide-unhide-placement.test.ts +0 -88
- package/packages/server/src/__tests__/home-lock-escape-hatch.test.ts +0 -60
- package/packages/server/src/__tests__/home-lock-release.test.ts +0 -85
- package/packages/server/src/__tests__/home-lock.test.ts +0 -308
- package/packages/server/src/__tests__/hydration-metrics.test.ts +0 -62
- package/packages/server/src/__tests__/identity.test.ts +0 -79
- package/packages/server/src/__tests__/idle-timer-respects-terminals.test.ts +0 -114
- package/packages/server/src/__tests__/inline-terminal-handler.test.ts +0 -73
- package/packages/server/src/__tests__/installed-package-enricher.test.ts +0 -225
- package/packages/server/src/__tests__/internal-registry.test.ts +0 -76
- package/packages/server/src/__tests__/is-activity-event.test.ts +0 -75
- package/packages/server/src/__tests__/is-pi-process.test.ts +0 -36
- package/packages/server/src/__tests__/is-unread-trigger.test.ts +0 -166
- package/packages/server/src/__tests__/json-store.test.ts +0 -70
- package/packages/server/src/__tests__/keeper-manager.test.ts +0 -332
- package/packages/server/src/__tests__/known-servers-routes.test.ts +0 -129
- package/packages/server/src/__tests__/last-activity-broadcast.test.ts +0 -188
- package/packages/server/src/__tests__/launch-source-effective.test.ts +0 -39
- package/packages/server/src/__tests__/live-server-endpoint.test.ts +0 -134
- package/packages/server/src/__tests__/liveness-stamp-wiring.test.ts +0 -144
- package/packages/server/src/__tests__/localhost-guard.test.ts +0 -172
- package/packages/server/src/__tests__/memory-event-store.test.ts +0 -934
- package/packages/server/src/__tests__/memory-session-manager.test.ts +0 -155
- package/packages/server/src/__tests__/meta-persistence.test.ts +0 -244
- package/packages/server/src/__tests__/migrate-persistence.test.ts +0 -180
- package/packages/server/src/__tests__/model-proxy-api-key-routes.test.ts +0 -277
- package/packages/server/src/__tests__/model-proxy-auth-gate.test.ts +0 -263
- package/packages/server/src/__tests__/model-proxy-diagnostics-routes.test.ts +0 -64
- package/packages/server/src/__tests__/model-proxy-multi-user.test.ts +0 -169
- package/packages/server/src/__tests__/model-proxy-routes.test.ts +0 -448
- package/packages/server/src/__tests__/model-proxy-second-port.test.ts +0 -116
- package/packages/server/src/__tests__/models-introspection-routes.test.ts +0 -107
- package/packages/server/src/__tests__/models-introspection-thinking-map.test.ts +0 -67
- package/packages/server/src/__tests__/node-guard.test.ts +0 -174
- package/packages/server/src/__tests__/npm-search-proxy.test.ts +0 -181
- package/packages/server/src/__tests__/oauth-callback-server.test.ts +0 -181
- package/packages/server/src/__tests__/office-preview.test.ts +0 -198
- package/packages/server/src/__tests__/openspec-archive.test.ts +0 -87
- package/packages/server/src/__tests__/openspec-change-order-store.test.ts +0 -62
- package/packages/server/src/__tests__/openspec-change-watcher-debounce.test.ts +0 -112
- package/packages/server/src/__tests__/openspec-change-watcher-filter.test.ts +0 -45
- package/packages/server/src/__tests__/openspec-change-watcher-fs.test.ts +0 -142
- package/packages/server/src/__tests__/openspec-connect-snapshot.test.ts +0 -148
- package/packages/server/src/__tests__/openspec-group-broadcast.test.ts +0 -97
- package/packages/server/src/__tests__/openspec-group-join.test.ts +0 -80
- package/packages/server/src/__tests__/openspec-group-routes.test.ts +0 -370
- package/packages/server/src/__tests__/openspec-group-store.test.ts +0 -496
- package/packages/server/src/__tests__/openspec-poll-worker.test.ts +0 -220
- package/packages/server/src/__tests__/openspec-profile-routes.test.ts +0 -415
- package/packages/server/src/__tests__/openspec-tasks-parser.test.ts +0 -292
- package/packages/server/src/__tests__/openspec-tasks-routes.test.ts +0 -180
- package/packages/server/src/__tests__/package-manager-wrapper-move.test.ts +0 -414
- package/packages/server/src/__tests__/package-manager-wrapper-reset.test.ts +0 -194
- package/packages/server/src/__tests__/package-manager-wrapper-resolve.test.ts +0 -136
- package/packages/server/src/__tests__/package-manager-wrapper.test.ts +0 -198
- package/packages/server/src/__tests__/package-routes.test.ts +0 -404
- package/packages/server/src/__tests__/package-source-helpers.test.ts +0 -101
- package/packages/server/src/__tests__/paired-devices.test.ts +0 -59
- package/packages/server/src/__tests__/pairing.test.ts +0 -191
- package/packages/server/src/__tests__/pending-attach-registry.test.ts +0 -123
- package/packages/server/src/__tests__/pending-automation-run-registry.test.ts +0 -54
- package/packages/server/src/__tests__/pending-fork-registry.test.ts +0 -93
- package/packages/server/src/__tests__/pending-initial-prompt-registry.test.ts +0 -52
- package/packages/server/src/__tests__/pending-load-manager.test.ts +0 -144
- package/packages/server/src/__tests__/pending-resume-intent-registry.test.ts +0 -138
- package/packages/server/src/__tests__/pending-resume-registry.test.ts +0 -130
- package/packages/server/src/__tests__/pending-worktree-base-registry.test.ts +0 -97
- package/packages/server/src/__tests__/pi-ai-shape.test.ts +0 -147
- package/packages/server/src/__tests__/pi-changelog-integration.test.ts +0 -165
- package/packages/server/src/__tests__/pi-changelog-routes.test.ts +0 -425
- package/packages/server/src/__tests__/pi-core-checker.test.ts +0 -380
- package/packages/server/src/__tests__/pi-core-routes.test.ts +0 -184
- package/packages/server/src/__tests__/pi-core-updater-managed-path.test.ts +0 -236
- package/packages/server/src/__tests__/pi-core-updater.test.ts +0 -214
- package/packages/server/src/__tests__/pi-dashboard-bin-wrapper.test.ts +0 -84
- package/packages/server/src/__tests__/pi-dev-version-check.test.ts +0 -184
- package/packages/server/src/__tests__/pi-gateway-bind-host.test.ts +0 -81
- package/packages/server/src/__tests__/pi-gateway-consume-pending-attach.test.ts +0 -115
- package/packages/server/src/__tests__/pi-resource-scanner.test.ts +0 -369
- package/packages/server/src/__tests__/pi-version-skew.test.ts +0 -259
- package/packages/server/src/__tests__/pi-version-update-handling.test.ts +0 -51
- package/packages/server/src/__tests__/plugin-activation-routes.test.ts +0 -267
- package/packages/server/src/__tests__/plugin-intent-cache.test.ts +0 -75
- package/packages/server/src/__tests__/preferences-store.test.ts +0 -682
- package/packages/server/src/__tests__/process-classifier.test.ts +0 -104
- package/packages/server/src/__tests__/process-manager-codes.test.ts +0 -80
- package/packages/server/src/__tests__/process-manager-keeper-spawn.test.ts +0 -259
- package/packages/server/src/__tests__/process-manager-managed-path.test.ts +0 -73
- package/packages/server/src/__tests__/process-manager.test.ts +0 -214
- package/packages/server/src/__tests__/proposal-attach-naming.test.ts +0 -79
- package/packages/server/src/__tests__/provider-auth-handlers.test.ts +0 -77
- package/packages/server/src/__tests__/provider-auth-routes.test.ts +0 -168
- package/packages/server/src/__tests__/provider-auth-storage.test.ts +0 -150
- package/packages/server/src/__tests__/provider-catalogue-cache.test.ts +0 -44
- package/packages/server/src/__tests__/provider-probe.test.ts +0 -287
- package/packages/server/src/__tests__/provider-routes-masked-key.test.ts +0 -110
- package/packages/server/src/__tests__/provider-routes-recursion-guard.test.ts +0 -131
- package/packages/server/src/__tests__/provider-test-route.test.ts +0 -149
- package/packages/server/src/__tests__/reattach-placement.test.ts +0 -254
- package/packages/server/src/__tests__/recommended-routes.test.ts +0 -431
- package/packages/server/src/__tests__/reconcile-session-order.test.ts +0 -71
- package/packages/server/src/__tests__/recovery-dedupe-and-lock.test.ts +0 -40
- package/packages/server/src/__tests__/recovery-e2e.test.ts +0 -191
- package/packages/server/src/__tests__/recovery-offer.test.ts +0 -227
- package/packages/server/src/__tests__/recovery-reattach-retraction.test.ts +0 -188
- package/packages/server/src/__tests__/recovery-server.test.ts +0 -198
- package/packages/server/src/__tests__/replace-proposal-race.test.ts +0 -236
- package/packages/server/src/__tests__/replay-truncate.test.ts +0 -61
- package/packages/server/src/__tests__/resolve-mention-endpoint.test.ts +0 -153
- package/packages/server/src/__tests__/resolve-order-key.test.ts +0 -31
- package/packages/server/src/__tests__/resolve-path.test.ts +0 -38
- package/packages/server/src/__tests__/resolve-published-variant.test.ts +0 -133
- package/packages/server/src/__tests__/resource-activation-routes.test.ts +0 -151
- package/packages/server/src/__tests__/resource-activation-toggle.test.ts +0 -153
- package/packages/server/src/__tests__/restart-helper.test.ts +0 -223
- package/packages/server/src/__tests__/retire-view-message-surface.test.ts +0 -35
- package/packages/server/src/__tests__/ring-buffer.test.ts +0 -45
- package/packages/server/src/__tests__/routes-git-worktree-init.test.ts +0 -464
- package/packages/server/src/__tests__/server-pid.test.ts +0 -89
- package/packages/server/src/__tests__/session-action-handler-followup-queue.test.ts +0 -163
- package/packages/server/src/__tests__/session-action-handler-headless-reload.test.ts +0 -510
- package/packages/server/src/__tests__/session-action-handler-reload-predicate.test.ts +0 -73
- package/packages/server/src/__tests__/session-action-handler-spawn-error.test.ts +0 -89
- package/packages/server/src/__tests__/session-action-handler-spawn-with-attach.test.ts +0 -108
- package/packages/server/src/__tests__/session-action-handler-spawn-with-initial-prompt.test.ts +0 -80
- package/packages/server/src/__tests__/session-action-handler-spawn.test.ts +0 -150
- package/packages/server/src/__tests__/session-api.test.ts +0 -246
- package/packages/server/src/__tests__/session-card-ordering-gates.test.ts +0 -160
- package/packages/server/src/__tests__/session-diff.test.ts +0 -852
- package/packages/server/src/__tests__/session-discovery-skill-firstmessage.test.ts +0 -95
- package/packages/server/src/__tests__/session-file-dedup.test.ts +0 -102
- package/packages/server/src/__tests__/session-file-reader.test.ts +0 -170
- package/packages/server/src/__tests__/session-kill-e2e.test.ts +0 -245
- package/packages/server/src/__tests__/session-lifecycle-logging.test.ts +0 -144
- package/packages/server/src/__tests__/session-load-worker.test.ts +0 -175
- package/packages/server/src/__tests__/session-name-provenance-persistence.test.ts +0 -74
- package/packages/server/src/__tests__/session-order-manager.test.ts +0 -267
- package/packages/server/src/__tests__/session-order-reboot.test.ts +0 -383
- package/packages/server/src/__tests__/session-ordering-integration.test.ts +0 -125
- package/packages/server/src/__tests__/session-routes-tool-result.test.ts +0 -134
- package/packages/server/src/__tests__/session-scanner-resolve-dir.integration.test.ts +0 -96
- package/packages/server/src/__tests__/session-scanner.test.ts +0 -366
- package/packages/server/src/__tests__/session-tags-persistence.test.ts +0 -114
- package/packages/server/src/__tests__/shutdown-endpoint.test.ts +0 -43
- package/packages/server/src/__tests__/skip-wipe.test.ts +0 -123
- package/packages/server/src/__tests__/sleep-aware-heartbeat.test.ts +0 -128
- package/packages/server/src/__tests__/smoke-integration.test.ts +0 -175
- package/packages/server/src/__tests__/spa-fallback.test.ts +0 -70
- package/packages/server/src/__tests__/spawn-correlation-token-integration.test.ts +0 -91
- package/packages/server/src/__tests__/spawn-env-electron-parity.test.ts +0 -47
- package/packages/server/src/__tests__/spawn-failure-log.test.ts +0 -118
- package/packages/server/src/__tests__/spawn-preflight.test.ts +0 -91
- package/packages/server/src/__tests__/spawn-register-watchdog.test.ts +0 -250
- package/packages/server/src/__tests__/spawn-token.test.ts +0 -88
- package/packages/server/src/__tests__/spawned-turn-log.test.ts +0 -88
- package/packages/server/src/__tests__/subscription-handler.test.ts +0 -396
- package/packages/server/src/__tests__/system-open-endpoints.test.ts +0 -150
- package/packages/server/src/__tests__/system-routes-restart.test.ts +0 -182
- package/packages/server/src/__tests__/system-routes-spawn-failures.test.ts +0 -84
- package/packages/server/src/__tests__/terminal-gateway.test.ts +0 -62
- package/packages/server/src/__tests__/terminal-manager.test.ts +0 -356
- package/packages/server/src/__tests__/test-server-canary.test.ts +0 -98
- package/packages/server/src/__tests__/tool-routes.test.ts +0 -304
- package/packages/server/src/__tests__/translate-path-source.test.ts +0 -77
- package/packages/server/src/__tests__/trusted-networks-config.test.ts +0 -103
- package/packages/server/src/__tests__/trusted-networks-no-oauth-roundtrip.test.ts +0 -126
- package/packages/server/src/__tests__/tunnel-block-events.test.ts +0 -74
- package/packages/server/src/__tests__/tunnel-cleanup.test.ts +0 -90
- package/packages/server/src/__tests__/tunnel-config-redaction.test.ts +0 -68
- package/packages/server/src/__tests__/tunnel-enroll.test.ts +0 -105
- package/packages/server/src/__tests__/tunnel-kind-gate.test.ts +0 -48
- package/packages/server/src/__tests__/tunnel-ngrok.test.ts +0 -101
- package/packages/server/src/__tests__/tunnel-tailscale.test.ts +0 -99
- package/packages/server/src/__tests__/tunnel-watchdog.test.ts +0 -139
- package/packages/server/src/__tests__/tunnel-zerotier.test.ts +0 -91
- package/packages/server/src/__tests__/tunnel-zrok-v2.test.ts +0 -319
- package/packages/server/src/__tests__/tunnel.test.ts +0 -315
- package/packages/server/src/__tests__/ui-decorators-replay.test.ts +0 -209
- package/packages/server/src/__tests__/ui-modules-replay.test.ts +0 -221
- package/packages/server/src/__tests__/unread-persistence.test.ts +0 -55
- package/packages/server/src/__tests__/unread-trigger-wiring.test.ts +0 -208
- package/packages/server/src/__tests__/viewed-session-tracker.test.ts +0 -93
- package/packages/server/src/__tests__/worktree-base-spawn-flow.test.ts +0 -157
- package/packages/server/src/__tests__/worktree-init-errors.test.ts +0 -72
- package/packages/server/src/__tests__/worktree-init-registry.test.ts +0 -178
- package/packages/server/src/__tests__/worktree-init-trust.test.ts +0 -105
- package/packages/server/src/__tests__/worktree-init.test.ts +0 -214
- package/packages/server/src/__tests__/worktree-pi-settings-rewrite.test.ts +0 -207
- package/packages/server/src/__tests__/ws-ping-pong.test.ts +0 -120
- package/packages/server/src/__tests__/ws-ticket.test.ts +0 -58
- package/packages/server/src/__tests__/ws-upgrade-routing.test.ts +0 -160
- package/packages/server/src/__tests__/wsl-tmux-probe-cache.test.ts +0 -44
- package/packages/server/src/auth/AGENTS.md +0 -21
- package/packages/server/src/auth/auth-plugin.ts.AGENTS.md +0 -3
- package/packages/server/src/auth/auth.ts.AGENTS.md +0 -3
- package/packages/server/src/auth/bearer-auth.ts.AGENTS.md +0 -3
- package/packages/server/src/auth/cors-origin.ts.AGENTS.md +0 -3
- package/packages/server/src/auth/csp.ts.AGENTS.md +0 -3
- package/packages/server/src/auth/identity.ts.AGENTS.md +0 -3
- package/packages/server/src/auth/local-token.ts.AGENTS.md +0 -3
- package/packages/server/src/auth/localhost-guard.ts.AGENTS.md +0 -3
- package/packages/server/src/auth/node-guard.ts.AGENTS.md +0 -3
- package/packages/server/src/auth/oauth-callback-server.ts +0 -177
- package/packages/server/src/auth/oauth-callback-server.ts.AGENTS.md +0 -3
- package/packages/server/src/auth/provider-auth-handlers.ts.AGENTS.md +0 -3
- package/packages/server/src/auth/provider-auth-storage.ts.AGENTS.md +0 -3
- package/packages/server/src/auth/spawn-token.ts.AGENTS.md +0 -3
- package/packages/server/src/auth/test-env-guard.ts.AGENTS.md +0 -3
- package/packages/server/src/auth/ws-ticket.ts.AGENTS.md +0 -3
- package/packages/server/src/browse.ts.AGENTS.md +0 -3
- package/packages/server/src/browser-handlers/AGENTS.md +0 -13
- package/packages/server/src/browser-handlers/__tests__/session-action-handler.test.ts +0 -49
- package/packages/server/src/browser-handlers/__tests__/session-action-liveness-clear.test.ts +0 -75
- package/packages/server/src/browser-handlers/__tests__/session-meta-handler.test.ts +0 -416
- package/packages/server/src/canvas/AGENTS.md +0 -8
- package/packages/server/src/changelog/AGENTS.md +0 -9
- package/packages/server/src/changelog/changelog-fs.ts.AGENTS.md +0 -3
- package/packages/server/src/changelog/changelog-parser.ts.AGENTS.md +0 -3
- package/packages/server/src/changelog/changelog-remote.ts.AGENTS.md +0 -3
- package/packages/server/src/cli.ts.AGENTS.md +0 -3
- package/packages/server/src/commit-draft-relay.ts.AGENTS.md +0 -3
- package/packages/server/src/config-api.ts.AGENTS.md +0 -3
- package/packages/server/src/directory-service.ts.AGENTS.md +0 -3
- package/packages/server/src/embed-lifecycle/AGENTS.md +0 -17
- package/packages/server/src/embed-lifecycle/__tests__/caps.test.ts +0 -129
- package/packages/server/src/embed-lifecycle/__tests__/embed-lifecycle-controller.test.ts +0 -84
- package/packages/server/src/embed-lifecycle/__tests__/identity-key.test.ts +0 -73
- package/packages/server/src/embed-lifecycle/__tests__/idle-reaper.test.ts +0 -173
- package/packages/server/src/embed-lifecycle/__tests__/lifecycle-config.test.ts +0 -26
- package/packages/server/src/embed-lifecycle/__tests__/lifecycle-event-capture.test.ts +0 -32
- package/packages/server/src/embed-lifecycle/__tests__/lifecycle-marker-persistence.test.ts +0 -106
- package/packages/server/src/embed-lifecycle/__tests__/lifecycle-metrics.test.ts +0 -39
- package/packages/server/src/embed-lifecycle/__tests__/liveness-probe.test.ts +0 -77
- package/packages/server/src/embed-lifecycle/__tests__/quiescence.test.ts +0 -175
- package/packages/server/src/embed-lifecycle/__tests__/reclamation-soak.test.ts +0 -77
- package/packages/server/src/embed-lifecycle/__tests__/session-lifecycle-policy.test.ts +0 -38
- package/packages/server/src/embed-lifecycle/__tests__/visitor-session-registry.test.ts +0 -140
- package/packages/server/src/event-wiring.ts.AGENTS.md +0 -4
- package/packages/server/src/fix-pty-permissions.ts.AGENTS.md +0 -3
- package/packages/server/src/git-worktree/AGENTS.md +0 -16
- package/packages/server/src/git-worktree/folder-head-poll.ts.AGENTS.md +0 -3
- package/packages/server/src/git-worktree/folder-head-watcher.ts.AGENTS.md +0 -3
- package/packages/server/src/git-worktree/git-operations.ts.AGENTS.md +0 -3
- package/packages/server/src/git-worktree/git-worktree-compose.ts.AGENTS.md +0 -3
- package/packages/server/src/git-worktree/git-worktree-lifecycle.ts.AGENTS.md +0 -3
- package/packages/server/src/git-worktree/git-worktree.ts.AGENTS.md +0 -3
- package/packages/server/src/git-worktree/worktree-init-errors.ts.AGENTS.md +0 -3
- package/packages/server/src/git-worktree/worktree-init-registry.ts.AGENTS.md +0 -3
- package/packages/server/src/git-worktree/worktree-init-trust.ts.AGENTS.md +0 -3
- package/packages/server/src/git-worktree/worktree-init.ts.AGENTS.md +0 -3
- package/packages/server/src/goal/AGENTS.md +0 -13
- package/packages/server/src/goal/decorate-goals-spend.ts +0 -47
- package/packages/server/src/goal/goal-budget-guard.ts +0 -42
- package/packages/server/src/goal/goal-budget-guard.ts.AGENTS.md +0 -3
- package/packages/server/src/goal/goal-session-primer.ts +0 -99
- package/packages/server/src/goal/goal-session-primer.ts.AGENTS.md +0 -3
- package/packages/server/src/goal/goal-status-projector.ts +0 -121
- package/packages/server/src/goal/goal-status-projector.ts.AGENTS.md +0 -3
- package/packages/server/src/goal/goal-store.ts +0 -530
- package/packages/server/src/goal/goal-store.ts.AGENTS.md +0 -3
- package/packages/server/src/goal/goal-supervisor.ts +0 -447
- package/packages/server/src/goal/goal-supervisor.ts.AGENTS.md +0 -3
- package/packages/server/src/goal/goal-verdict-accumulator.ts +0 -101
- package/packages/server/src/goal/goal-verdict-accumulator.ts.AGENTS.md +0 -3
- package/packages/server/src/home-lock.d.ts +0 -124
- package/packages/server/src/home-lock.js +0 -330
- package/packages/server/src/home-lock.js.AGENTS.md +0 -3
- package/packages/server/src/home-lock.js.map +0 -1
- package/packages/server/src/lib/AGENTS.md +0 -16
- package/packages/server/src/lib/__tests__/md-candidates.test.ts +0 -81
- package/packages/server/src/lib/__tests__/path-containment.test.ts +0 -119
- package/packages/server/src/lib/__tests__/resolve-file-mention.test.ts +0 -87
- package/packages/server/src/lib/__tests__/writable-md-target.test.ts +0 -112
- package/packages/server/src/lifecycle/AGENTS.md +0 -12
- package/packages/server/src/lifecycle/boot-parent-liveness.ts.AGENTS.md +0 -3
- package/packages/server/src/lifecycle/dashboard-source-decision.ts.AGENTS.md +0 -3
- package/packages/server/src/lifecycle/home-lock-release.ts.AGENTS.md +0 -3
- package/packages/server/src/lifecycle/home-lock.ts.AGENTS.md +0 -3
- package/packages/server/src/lifecycle/launch-source-effective.ts.AGENTS.md +0 -3
- package/packages/server/src/lifecycle/recovery-server.ts.AGENTS.md +0 -3
- package/packages/server/src/live-server/AGENTS.md +0 -8
- package/packages/server/src/live-server/live-server-manager.ts.AGENTS.md +0 -3
- package/packages/server/src/live-server/live-server-proxy.ts.AGENTS.md +0 -3
- package/packages/server/src/metrics/AGENTS.md +0 -9
- package/packages/server/src/metrics/eventloop-sampler.ts.AGENTS.md +0 -3
- package/packages/server/src/metrics/eventloop-spike-metrics.ts.AGENTS.md +0 -3
- package/packages/server/src/metrics/hydration-metrics.ts.AGENTS.md +0 -3
- package/packages/server/src/model-proxy/AGENTS.md +0 -18
- package/packages/server/src/model-proxy/__tests__/api-key-store.test.ts +0 -142
- package/packages/server/src/model-proxy/__tests__/auth-json-contention.test.ts +0 -98
- package/packages/server/src/model-proxy/__tests__/concurrency.test.ts +0 -107
- package/packages/server/src/model-proxy/__tests__/failed-auth-backoff.test.ts +0 -46
- package/packages/server/src/model-proxy/__tests__/internal-registry-native-merge.test.ts +0 -155
- package/packages/server/src/model-proxy/__tests__/internal-registry.test.ts +0 -167
- package/packages/server/src/model-proxy/__tests__/oauth-compat.test.ts +0 -31
- package/packages/server/src/model-proxy/__tests__/read-native-models.test.ts +0 -92
- package/packages/server/src/model-proxy/__tests__/recursion-guard.test.ts +0 -61
- package/packages/server/src/model-proxy/__tests__/streamer.test.ts +0 -139
- package/packages/server/src/model-proxy/convert/AGENTS.md +0 -13
- package/packages/server/src/model-proxy/convert/__tests__/anthropic-in.test.ts +0 -137
- package/packages/server/src/model-proxy/convert/__tests__/anthropic-out.test.ts +0 -183
- package/packages/server/src/model-proxy/convert/__tests__/openai-in.test.ts +0 -134
- package/packages/server/src/model-proxy/convert/__tests__/openai-out.test.ts +0 -166
- package/packages/server/src/openspec/AGENTS.md +0 -14
- package/packages/server/src/openspec/openspec-archive.ts.AGENTS.md +0 -3
- package/packages/server/src/openspec/openspec-change-watcher.ts.AGENTS.md +0 -3
- package/packages/server/src/openspec/openspec-group-store.ts.AGENTS.md +0 -3
- package/packages/server/src/openspec/openspec-poll-fs-helpers.ts.AGENTS.md +0 -3
- package/packages/server/src/openspec/openspec-poll-worker-pool.ts.AGENTS.md +0 -3
- package/packages/server/src/openspec/openspec-poll-worker.ts.AGENTS.md +0 -3
- package/packages/server/src/openspec/openspec-tasks.ts.AGENTS.md +0 -3
- package/packages/server/src/openspec/proposal-attach-naming.ts.AGENTS.md +0 -3
- package/packages/server/src/package/AGENTS.md +0 -12
- package/packages/server/src/package/installed-package-enricher.ts.AGENTS.md +0 -8
- package/packages/server/src/package/npm-search-proxy.ts.AGENTS.md +0 -8
- package/packages/server/src/package/package-manager-wrapper.ts.AGENTS.md +0 -8
- package/packages/server/src/package/package-source-helpers.ts.AGENTS.md +0 -3
- package/packages/server/src/package/provider-catalogue-cache.ts.AGENTS.md +0 -3
- package/packages/server/src/package/provider-probe.ts.AGENTS.md +0 -3
- package/packages/server/src/pairing/AGENTS.md +0 -9
- package/packages/server/src/pairing/browser-gateway.ts.AGENTS.md +0 -3
- package/packages/server/src/pairing/paired-devices.ts.AGENTS.md +0 -3
- package/packages/server/src/pairing/pairing.ts.AGENTS.md +0 -3
- package/packages/server/src/pending/AGENTS.md +0 -16
- package/packages/server/src/pending/pending-attach-registry.ts.AGENTS.md +0 -3
- package/packages/server/src/pending/pending-automation-run-registry.ts +0 -116
- package/packages/server/src/pending/pending-automation-run-registry.ts.AGENTS.md +0 -3
- package/packages/server/src/pending/pending-client-correlations.ts.AGENTS.md +0 -3
- package/packages/server/src/pending/pending-fork-registry.ts.AGENTS.md +0 -3
- package/packages/server/src/pending/pending-goal-link-registry.ts +0 -107
- package/packages/server/src/pending/pending-goal-link-registry.ts.AGENTS.md +0 -3
- package/packages/server/src/pending/pending-initial-prompt-registry.ts.AGENTS.md +0 -3
- package/packages/server/src/pending/pending-load-manager.ts.AGENTS.md +0 -3
- package/packages/server/src/pending/pending-resume-intent-registry.ts.AGENTS.md +0 -3
- package/packages/server/src/pending/pending-resume-registry.ts.AGENTS.md +0 -3
- package/packages/server/src/pending/pending-worktree-base-registry.ts.AGENTS.md +0 -3
- package/packages/server/src/persistence/AGENTS.md +0 -11
- package/packages/server/src/persistence/json-store.ts.AGENTS.md +0 -3
- package/packages/server/src/persistence/memory-event-store.ts.AGENTS.md +0 -3
- package/packages/server/src/persistence/meta-persistence.ts.AGENTS.md +0 -3
- package/packages/server/src/persistence/migrate-persistence.ts.AGENTS.md +0 -3
- package/packages/server/src/persistence/preferences-store.ts.AGENTS.md +0 -3
- package/packages/server/src/pi/AGENTS.md +0 -14
- package/packages/server/src/pi/pi-core-checker.ts.AGENTS.md +0 -3
- package/packages/server/src/pi/pi-core-updater.ts.AGENTS.md +0 -3
- package/packages/server/src/pi/pi-dev-version-check.ts +0 -145
- package/packages/server/src/pi/pi-dev-version-check.ts.AGENTS.md +0 -3
- package/packages/server/src/pi/pi-gateway.ts.AGENTS.md +0 -3
- package/packages/server/src/pi/pi-resource-activation.ts.AGENTS.md +0 -3
- package/packages/server/src/pi/pi-resource-scanner.ts.AGENTS.md +0 -3
- package/packages/server/src/pi/pi-version-skew.ts.AGENTS.md +0 -3
- package/packages/server/src/pi/resource-activation-toggle.ts.AGENTS.md +0 -3
- package/packages/server/src/plugin-intent-cache.ts.AGENTS.md +0 -3
- package/packages/server/src/routes/AGENTS.md +0 -38
- package/packages/server/src/routes/__tests__/grep-routes.test.ts +0 -84
- package/packages/server/src/routes/__tests__/manifest-route.test.ts +0 -138
- package/packages/server/src/routes/goal-routes.ts +0 -406
- package/packages/server/src/rpc-keeper/AGENTS.md +0 -8
- package/packages/server/src/rpc-keeper/__tests__/fixtures/mock-pi-shim.sh +0 -9
- package/packages/server/src/rpc-keeper/__tests__/fixtures/mock-pi.cjs +0 -89
- package/packages/server/src/rpc-keeper/__tests__/keeper-electron-run-as-node.test.ts +0 -67
- package/packages/server/src/rpc-keeper/__tests__/keeper-env.test.ts +0 -47
- package/packages/server/src/rpc-keeper/__tests__/keeper-shutdown-kills-pi.test.ts +0 -134
- package/packages/server/src/rpc-keeper/__tests__/keeper.test.ts +0 -517
- package/packages/server/src/rpc-keeper/dispatch-router.ts +0 -85
- package/packages/server/src/server.ts.AGENTS.md +0 -3
- package/packages/server/src/session/AGENTS.md +0 -26
- package/packages/server/src/session/__tests__/session-diff-cache.test.ts +0 -62
- package/packages/server/src/session/__tests__/session-diff-eventloop.test.ts +0 -79
- package/packages/server/src/session/active-sessions-in-cwd.ts.AGENTS.md +0 -3
- package/packages/server/src/session/event-status-extraction.ts.AGENTS.md +0 -3
- package/packages/server/src/session/memory-session-manager.ts.AGENTS.md +0 -3
- package/packages/server/src/session/reattach-placement.ts.AGENTS.md +0 -3
- package/packages/server/src/session/reconcile-session-order.ts.AGENTS.md +0 -3
- package/packages/server/src/session/replay-truncate.ts.AGENTS.md +0 -3
- package/packages/server/src/session/resolve-order-key.ts.AGENTS.md +0 -3
- package/packages/server/src/session/session-api.ts.AGENTS.md +0 -3
- package/packages/server/src/session/session-bootstrap.ts.AGENTS.md +0 -3
- package/packages/server/src/session/session-diff.ts.AGENTS.md +0 -9
- package/packages/server/src/session/session-discovery.ts.AGENTS.md +0 -3
- package/packages/server/src/session/session-file-reader.ts.AGENTS.md +0 -3
- package/packages/server/src/session/session-load-worker-pool.ts.AGENTS.md +0 -3
- package/packages/server/src/session/session-load-worker.ts.AGENTS.md +0 -3
- package/packages/server/src/session/session-order-manager.ts.AGENTS.md +0 -3
- package/packages/server/src/session/session-scanner.ts.AGENTS.md +0 -3
- package/packages/server/src/session/session-stats-reader.ts.AGENTS.md +0 -3
- package/packages/server/src/session/session-to-meta.ts.AGENTS.md +0 -3
- package/packages/server/src/session/viewed-session-tracker.ts.AGENTS.md +0 -3
- package/packages/server/src/spawn-process/AGENTS.md +0 -16
- package/packages/server/src/spawn-process/headless-pid-registry.ts.AGENTS.md +0 -3
- package/packages/server/src/spawn-process/idle-timer.ts.AGENTS.md +0 -3
- package/packages/server/src/spawn-process/process-classifier.ts.AGENTS.md +0 -3
- package/packages/server/src/spawn-process/process-manager.ts.AGENTS.md +0 -3
- package/packages/server/src/spawn-process/restart-helper.ts.AGENTS.md +0 -3
- package/packages/server/src/spawn-process/server-pid.ts.AGENTS.md +0 -3
- package/packages/server/src/spawn-process/spawn-preflight.ts.AGENTS.md +0 -3
- package/packages/server/src/spawn-process/spawned-turn-log.ts.AGENTS.md +0 -3
- package/packages/server/src/terminal/AGENTS.md +0 -8
- package/packages/server/src/terminal/terminal-gateway.ts.AGENTS.md +0 -3
- package/packages/server/src/terminal/terminal-manager.ts.AGENTS.md +0 -3
- package/packages/server/src/test-support/AGENTS.md +0 -7
- package/packages/server/src/test-support/test-server.ts +0 -63
- package/packages/server/src/tunnel/AGENTS.md +0 -12
- package/packages/server/src/tunnel/tunnel-block-events.ts.AGENTS.md +0 -3
- package/packages/server/src/tunnel/tunnel-core.ts.AGENTS.md +0 -3
- package/packages/server/src/tunnel/tunnel-endpoints.ts.AGENTS.md +0 -3
- package/packages/server/src/tunnel/tunnel-enroll.ts.AGENTS.md +0 -3
- package/packages/server/src/tunnel/tunnel-watchdog.ts.AGENTS.md +0 -3
- package/packages/server/src/tunnel/tunnel.ts.AGENTS.md +0 -3
- package/packages/server/src/tunnel-providers/AGENTS.md +0 -13
- package/packages/shared/src/AGENTS.md +0 -52
- package/packages/shared/src/__tests__/binary-lookup-resolveJiti.test.ts +0 -256
- package/packages/shared/src/__tests__/binary-lookup-spawn-env.test.ts +0 -61
- package/packages/shared/src/__tests__/binary-lookup.test.ts +0 -211
- package/packages/shared/src/__tests__/bridge-register.test.ts +0 -252
- package/packages/shared/src/__tests__/browser-protocol-types.test.ts +0 -232
- package/packages/shared/src/__tests__/bundled-node-meets-pi-floor.test.ts +0 -109
- package/packages/shared/src/__tests__/bundled-plugins-complete.test.ts +0 -90
- package/packages/shared/src/__tests__/bundled-server-materialization.test.ts +0 -93
- package/packages/shared/src/__tests__/canvas-declare.test.ts +0 -103
- package/packages/shared/src/__tests__/canvas-detect.test.ts +0 -83
- package/packages/shared/src/__tests__/canvas-types.test.ts +0 -46
- package/packages/shared/src/__tests__/changelog-types.test.ts +0 -78
- package/packages/shared/src/__tests__/ci-electron-no-side-effects.test.ts +0 -129
- package/packages/shared/src/__tests__/config-keeper-log.test.ts +0 -77
- package/packages/shared/src/__tests__/config-openspec.test.ts +0 -180
- package/packages/shared/src/__tests__/config-plugins.test.ts +0 -68
- package/packages/shared/src/__tests__/config.test.ts +0 -688
- package/packages/shared/src/__tests__/credential-detect.test.ts +0 -145
- package/packages/shared/src/__tests__/cwd-missing-protocol.test.ts +0 -47
- package/packages/shared/src/__tests__/dashboard-paths.test.ts +0 -145
- package/packages/shared/src/__tests__/dashboard-starter.test.ts +0 -40
- package/packages/shared/src/__tests__/deriveChangeState.test.ts +0 -95
- package/packages/shared/src/__tests__/detached-spawn.test.ts +0 -267
- package/packages/shared/src/__tests__/display-prefs.test.ts +0 -147
- package/packages/shared/src/__tests__/doctor-core-legacy-advisory.test.ts +0 -88
- package/packages/shared/src/__tests__/doctor-core.test.ts +0 -234
- package/packages/shared/src/__tests__/doctor-fault-tolerance.test.ts +0 -218
- package/packages/shared/src/__tests__/doctor-format.test.ts +0 -124
- package/packages/shared/src/__tests__/doctor-tunnel-checks.test.ts +0 -422
- package/packages/shared/src/__tests__/ensure-bundled-git.test.ts +0 -111
- package/packages/shared/src/__tests__/ensure-windows-path.test.ts +0 -112
- package/packages/shared/src/__tests__/extension-ui-module-shape.test.ts +0 -265
- package/packages/shared/src/__tests__/file-kind.test.ts +0 -199
- package/packages/shared/src/__tests__/intent-types.test.ts +0 -120
- package/packages/shared/src/__tests__/jiti-packages-parity.test.ts +0 -85
- package/packages/shared/src/__tests__/legacy-managed-dir.test.ts +0 -59
- package/packages/shared/src/__tests__/live-server.test.ts +0 -75
- package/packages/shared/src/__tests__/managed-node-path.test.ts +0 -122
- package/packages/shared/src/__tests__/managed-paths.test.ts +0 -60
- package/packages/shared/src/__tests__/managed-runtime-strategy.test.ts +0 -74
- package/packages/shared/src/__tests__/mdns-discovery.test.ts +0 -127
- package/packages/shared/src/__tests__/model-id.test.ts +0 -31
- package/packages/shared/src/__tests__/model-proxy-config.test.ts +0 -183
- package/packages/shared/src/__tests__/models-json-reader.test.ts +0 -100
- package/packages/shared/src/__tests__/nightly-workflow-contract.test.ts +0 -125
- package/packages/shared/src/__tests__/no-bash-on-windows.test.ts +0 -308
- package/packages/shared/src/__tests__/no-direct-child-process.test.ts +0 -124
- package/packages/shared/src/__tests__/no-direct-platform-branch.test.ts +0 -182
- package/packages/shared/src/__tests__/no-direct-process-kill.test.ts +0 -105
- package/packages/shared/src/__tests__/no-electron-execpath-spawn.test.ts +0 -149
- package/packages/shared/src/__tests__/no-flow-command-route-claims.test.ts +0 -71
- package/packages/shared/src/__tests__/no-flow-references-in-shell.test.ts +0 -221
- package/packages/shared/src/__tests__/no-hardcoded-bundled-git-paths.test.ts +0 -95
- package/packages/shared/src/__tests__/no-hardcoded-node-modules-paths.test.ts +0 -176
- package/packages/shared/src/__tests__/no-managed-dir-reference.test.ts +0 -137
- package/packages/shared/src/__tests__/no-pi-dashboard-version-jiti-gate.test.ts +0 -41
- package/packages/shared/src/__tests__/no-primitive-direct-import.test.ts +0 -236
- package/packages/shared/src/__tests__/no-raw-node-import.test.ts +0 -148
- package/packages/shared/src/__tests__/no-raw-openspec-status-in-skills.test.ts +0 -86
- package/packages/shared/src/__tests__/no-remote-debugging-address.test.ts +0 -72
- package/packages/shared/src/__tests__/no-server-imports-in-resolver.test.ts +0 -53
- package/packages/shared/src/__tests__/node-spawn-jiti-contract.test.ts +0 -96
- package/packages/shared/src/__tests__/node-spawn.test.ts +0 -277
- package/packages/shared/src/__tests__/node-version.test.ts +0 -59
- package/packages/shared/src/__tests__/openspec-design-evidence.test.ts +0 -288
- package/packages/shared/src/__tests__/openspec-effective-status-script.test.ts +0 -174
- package/packages/shared/src/__tests__/openspec-groups-types.test.ts +0 -135
- package/packages/shared/src/__tests__/openspec-poller-1.6.0-compat.test.ts +0 -112
- package/packages/shared/src/__tests__/openspec-poller-derive.test.ts +0 -115
- package/packages/shared/src/__tests__/openspec-poller-design-override.test.ts +0 -225
- package/packages/shared/src/__tests__/openspec-poller-parity.test.ts +0 -77
- package/packages/shared/src/__tests__/openspec-poller-specs-override.test.ts +0 -284
- package/packages/shared/src/__tests__/openspec-poller.test.ts +0 -44
- package/packages/shared/src/__tests__/openspec-specs-evidence.test.ts +0 -144
- package/packages/shared/src/__tests__/pi-package-resolver.test.ts +0 -300
- package/packages/shared/src/__tests__/pi-version-update-protocol.test.ts +0 -30
- package/packages/shared/src/__tests__/platform/is-appimage-self-hit.test.ts +0 -164
- package/packages/shared/src/__tests__/platform-commands.test.ts +0 -136
- package/packages/shared/src/__tests__/platform-exec.test.ts +0 -103
- package/packages/shared/src/__tests__/platform-git.test.ts +0 -300
- package/packages/shared/src/__tests__/platform-npm.test.ts +0 -137
- package/packages/shared/src/__tests__/platform-openspec.test.ts +0 -95
- package/packages/shared/src/__tests__/platform-paths.test.ts +0 -284
- package/packages/shared/src/__tests__/platform-process-scan.test.ts +0 -55
- package/packages/shared/src/__tests__/platform-process.test.ts +0 -160
- package/packages/shared/src/__tests__/platform-runner.test.ts +0 -173
- package/packages/shared/src/__tests__/platform-shell.test.ts +0 -74
- package/packages/shared/src/__tests__/plugin-activation-contracts.test.ts +0 -78
- package/packages/shared/src/__tests__/plugin-bridge-classify-source.test.ts +0 -73
- package/packages/shared/src/__tests__/plugin-bridge-register-extended.test.ts +0 -84
- package/packages/shared/src/__tests__/plugin-bridge-register-packages.test.ts +0 -233
- package/packages/shared/src/__tests__/plugin-bridge-register.test.ts +0 -123
- package/packages/shared/src/__tests__/plugin-config-update-protocol.test.ts +0 -41
- package/packages/shared/src/__tests__/pnpm-migration-contract.test.ts +0 -177
- package/packages/shared/src/__tests__/process-identify.test.ts +0 -113
- package/packages/shared/src/__tests__/protocol.test.ts +0 -276
- package/packages/shared/src/__tests__/publish-allowlist-complete.test.ts +0 -146
- package/packages/shared/src/__tests__/publish-workflow-contract.test.ts +0 -600
- package/packages/shared/src/__tests__/recommended-extensions.test.ts +0 -225
- package/packages/shared/src/__tests__/recovery-candidate.test.ts +0 -51
- package/packages/shared/src/__tests__/resolve-tool-cli.test.ts +0 -105
- package/packages/shared/src/__tests__/resolver-parity-with-scanner.test.ts +0 -77
- package/packages/shared/src/__tests__/role-name-validation.test.ts +0 -46
- package/packages/shared/src/__tests__/select-git-source.test.ts +0 -65
- package/packages/shared/src/__tests__/semaphore.test.ts +0 -119
- package/packages/shared/src/__tests__/server-identity.test.ts +0 -200
- package/packages/shared/src/__tests__/server-launcher.test.ts +0 -329
- package/packages/shared/src/__tests__/session-meta-worktree.test.ts +0 -61
- package/packages/shared/src/__tests__/session-meta.test.ts +0 -140
- package/packages/shared/src/__tests__/skill-block-parser.test.ts +0 -153
- package/packages/shared/src/__tests__/source-matching.test.ts +0 -198
- package/packages/shared/src/__tests__/spawn-mechanism.test.ts +0 -131
- package/packages/shared/src/__tests__/spawn-session-attach-proposal.test.ts +0 -47
- package/packages/shared/src/__tests__/state-replay-entry-id.test.ts +0 -69
- package/packages/shared/src/__tests__/state-replay-flow-events.test.ts +0 -100
- package/packages/shared/src/__tests__/sync-versions-spec.test.ts +0 -76
- package/packages/shared/src/__tests__/tags.test.ts +0 -65
- package/packages/shared/src/__tests__/tool-registry-definitions.test.ts +0 -453
- package/packages/shared/src/__tests__/tool-registry-overrides.test.ts +0 -137
- package/packages/shared/src/__tests__/tool-registry-registry.test.ts +0 -343
- package/packages/shared/src/__tests__/tool-registry-strategies-appimage.test.ts +0 -118
- package/packages/shared/src/__tests__/tunnel-config-migration.test.ts +0 -111
- package/packages/shared/src/__tests__/tunnel-provider.test.ts +0 -54
- package/packages/shared/src/dashboard-plugin/AGENTS.md +0 -14
- package/packages/shared/src/platform/AGENTS.md +0 -28
- package/packages/shared/src/platform/__tests__/openspec-profile-config.test.ts +0 -109
- package/packages/shared/src/platform/__tests__/openspec-runner-stripped-path.integration.test.ts +0 -127
- package/packages/shared/src/platform/__tests__/runner-spawn-env.test.ts +0 -59
- package/packages/shared/src/platform/__tests__/spawn-mechanism.test.ts +0 -57
- package/packages/shared/src/platform/git.ts.AGENTS.md +0 -19
- package/packages/shared/src/test-support/AGENTS.md +0 -8
- package/packages/shared/src/test-support/setup-home-perfile.ts +0 -43
- package/packages/shared/src/test-support/setup-home.ts +0 -74
- package/packages/shared/src/tool-registry/AGENTS.md +0 -12
- package/packages/shared/src/tool-registry/__tests__/bare-import-exports-map.test.ts +0 -77
- package/packages/shared/src/tool-registry/__tests__/bundled-git-bash-strategy.test.ts +0 -74
- package/packages/shared/src/tool-registry/__tests__/bundled-node-strategy.test.ts +0 -125
- package/packages/shared/src/tool-registry/__tests__/install-hints.test.ts +0 -126
- package/packages/shared/src/tool-registry/__tests__/managed-runtime-strategy.test.ts +0 -166
- package/packages/shared/src/tool-registry/__tests__/node-electron-resolution.test.ts +0 -242
- package/packages/shared/src/tool-registry/__tests__/node-script-argv-matrix.test.ts +0 -157
- package/packages/shared/src/tool-registry/__tests__/node-script-toargv-fallback.test.ts +0 -84
- package/packages/shared/src/tool-registry/__tests__/openspec-unix-node-wrap.test.ts +0 -62
- package/packages/shared/src/tool-registry/__tests__/pi-ai-registration.test.ts +0 -130
|
@@ -5,19 +5,25 @@
|
|
|
5
5
|
* forwards all pi events, and relays commands back.
|
|
6
6
|
*/
|
|
7
7
|
|
|
8
|
+
import { bridgeExtensionIdentity } from "./extension-identity.js";
|
|
8
9
|
import fs from "node:fs";
|
|
9
10
|
import os from "node:os";
|
|
10
11
|
import path from "node:path";
|
|
11
12
|
import { fileURLToPath } from "node:url";
|
|
12
|
-
import { ensureConfig, loadConfig } from "@blackbelt-technology/pi-dashboard-shared/config.js";
|
|
13
|
+
import { ensureConfig, loadConfig, resolveDashboardPorts } from "@blackbelt-technology/pi-dashboard-shared/config.js";
|
|
14
|
+
import { shouldActivateBridge } from "./bridge-activation.js";
|
|
13
15
|
import { discoverDashboard } from "@blackbelt-technology/pi-dashboard-shared/mdns-discovery.js";
|
|
14
|
-
import type {
|
|
16
|
+
import type {
|
|
17
|
+
ServerToExtensionMessage,
|
|
18
|
+
TranscriptRequestMessage,
|
|
19
|
+
} from "@blackbelt-technology/pi-dashboard-shared/protocol.js";
|
|
20
|
+
import { rendezvousEndpoint } from "@blackbelt-technology/pi-dashboard-shared/rendezvous.js";
|
|
15
21
|
import { isDashboardRunning } from "@blackbelt-technology/pi-dashboard-shared/server-identity.js";
|
|
22
|
+
import { decideTranscriptRequest } from "@blackbelt-technology/pi-dashboard-shared/transcript-request-guard.js";
|
|
16
23
|
import type { FlowInfo, ImageContent } from "@blackbelt-technology/pi-dashboard-shared/types.js";
|
|
17
24
|
import type { ExtensionAPI } from "@earendil-works/pi-coding-agent";
|
|
18
25
|
import { Loader } from "@earendil-works/pi-tui";
|
|
19
26
|
import { AbortLatch } from "./abort-latch.js";
|
|
20
|
-
import { nativeAgentSettledSupported, settleFollowUp } from "./agent-settled.js";
|
|
21
27
|
import { isUnderArtifactRoot, resolveArtifactRoots } from "./artifact-roots.js";
|
|
22
28
|
import {
|
|
23
29
|
MAX_PER_MESSAGE_BYTES as ATTACH_MAX_PER_MESSAGE_BYTES,
|
|
@@ -25,57 +31,121 @@ import {
|
|
|
25
31
|
persistAttachment,
|
|
26
32
|
} from "./ask-user-attachments.js";
|
|
27
33
|
import { registerAskUserTool } from "./ask-user-tool.js";
|
|
28
|
-
import { type AutoNamer, createAutoNamer, type StreamSimpleFn } from "./auto-session-namer.js";
|
|
34
|
+
import { type AutoNamer, adoptRestoredNamerState, createAutoNamer, type PersistedNamerState, type StreamSimpleFn } from "./auto-session-namer.js";
|
|
29
35
|
import type { BridgeContext } from "./bridge-context.js";
|
|
30
|
-
import {
|
|
31
|
-
import { shouldApplyDefaultModel } from "./bridge-default-model-gate.js";
|
|
36
|
+
import { extractFirstMessage, extractLatestTurnWindow, filterHiddenCommands, getCurrentModelString, isHeadlessRpcSession, safeCwd } from "./bridge-context.js";
|
|
37
|
+
import { hasExplicitModelArg, shouldApplyDefaultModel } from "./bridge-default-model-gate.js";
|
|
38
|
+
import { mintBridgeTicket, readDeviceToken, withTicket } from "./bridge-ticket-client.js";
|
|
32
39
|
import { registerCanvasTool } from "./canvas-tool.js";
|
|
33
|
-
import {
|
|
40
|
+
import {
|
|
41
|
+
buildUserMessageContent,
|
|
42
|
+
createCommandHandler,
|
|
43
|
+
tryExecSlashTemplate,
|
|
44
|
+
validateImages,
|
|
45
|
+
} from "./command-handler.js";
|
|
34
46
|
import { buildSessionContextText, runForkSubagentDraft } from "./commit-draft-agent.js";
|
|
35
|
-
import { ConnectionManager } from "./connection.js";
|
|
47
|
+
import { ConnectionManager, type WatchdogFireInfo } from "./connection.js";
|
|
48
|
+
import {
|
|
49
|
+
consumePendingReloadOnSessionStart,
|
|
50
|
+
createTerminalReload,
|
|
51
|
+
isBridgeReentry,
|
|
52
|
+
RELOAD_COMMAND_NAME,
|
|
53
|
+
releaseBridgeOwnerOnShutdown,
|
|
54
|
+
reloadCompletedFeedback,
|
|
55
|
+
} from "./terminal-reload.js";
|
|
56
|
+
import { toCustomEntryForward, toCustomMessageForward } from "./custom-entry-forward.js";
|
|
36
57
|
import { registerDashboardContextInjector } from "./dashboard-context-injector.js";
|
|
37
58
|
import { DashboardDefaultAdapter } from "./dashboard-default-adapter.js";
|
|
38
59
|
import { runDevBuild } from "./dev-build.js";
|
|
39
|
-
import { provisionOpenspecCli } from "./openspec-cli-shim.js";
|
|
40
60
|
import { EmptyActionableGuard, SURFACE_MESSAGE } from "./empty-actionable-guard.js";
|
|
41
61
|
import { resolveGuardConfig } from "./empty-actionable-guard-config.js";
|
|
42
|
-
import {
|
|
43
|
-
import {
|
|
44
|
-
import {
|
|
62
|
+
import { decideRetarget, instanceIdFileForSocket, resolveEndpoint } from "./endpoint-resolution.js";
|
|
63
|
+
import { mapEventToProtocol, redactBeforeSettleContext, redactCompactionEntry } from "./event-forwarder.js";
|
|
64
|
+
import {
|
|
65
|
+
FLOW_EVENT_MAP,
|
|
66
|
+
registerEventBusForwarding,
|
|
67
|
+
registerFlowEventListeners,
|
|
68
|
+
SUBAGENT_EVENT_MAP,
|
|
69
|
+
} from "./flow-event-wiring.js";
|
|
70
|
+
import { createFollowupBuffer } from "./followup-buffer.js";
|
|
71
|
+
import { createPollingHolder, drainDisposables, ensureDisposable, feedPollingEvent, routeGitInfoRefresh, scheduleModelRecheckOnSelect, teardownPreviousIncarnation } from "./bridge-polling.js";
|
|
72
|
+
import { createGitPollState, runGitPollTick } from "./git-poll.js";
|
|
73
|
+
import { createGitTracker, type GitTracker } from "./git-tracker.js";
|
|
74
|
+
import { createPrStatusScheduler, type PrStatusScheduler } from "./pr-status.js";
|
|
75
|
+
import * as git from "@blackbelt-technology/pi-dashboard-shared/platform/git.js";
|
|
45
76
|
import { flipHasUI } from "./hasui-flip.js";
|
|
77
|
+
import { healthUrlForInstance, probeEndpointReachability, verifyInstanceIdentity } from "./instance-verification.js";
|
|
78
|
+
import { localTokenHeaders } from "./local-token-header.js";
|
|
46
79
|
import { inlineMessageText, type ReadFileOutcome } from "./markdown-image-inliner.js";
|
|
47
|
-
import {
|
|
80
|
+
import { createMcpDashboardRegistrar, type McpRegistrationApi, type McpTokenMintedPayload } from "./mcp-token-delivery.js";
|
|
81
|
+
import { createPluginRequestClient, installPluginRequest } from "./plugin-request-client.js";
|
|
82
|
+
import { COALESCE_WINDOW_MS, flushesParkedText, MessageUpdateCoalescer } from "./message-update-coalescer.js";
|
|
83
|
+
import { reportRefresh } from "./model-refresh.js";
|
|
84
|
+
import { resetReconnectCaches as _resetReconnectCaches, sendCwdMissingIfChanged as _sendCwdMissingIfChanged, sendModelUpdateIfChanged as _sendModelUpdateIfChanged, sendPiVersionIfChanged as _sendPiVersionIfChanged, sendSessionNameIfChanged as _sendSessionNameIfChanged } from "./model-tracker.js";
|
|
48
85
|
import { decodeMultiselectAnswer } from "./multiselect-decode.js";
|
|
86
|
+
import { createNotifyProxy } from "./notify-proxy.js";
|
|
87
|
+
import { provisionOpenspecCli } from "./openspec-cli-shim.js";
|
|
88
|
+
import { createPathGate } from "./path-gate/index.js";
|
|
89
|
+
import { Suppression } from "./path-gate/suppression.js";
|
|
90
|
+
import { emitPendingPrompts } from "./pending-prompt-emitter.js";
|
|
91
|
+
import { readPiRetrySettings } from "./pi-retry-settings.js";
|
|
49
92
|
import { collectMetrics, startMetricsMonitor, stopMetricsMonitor } from "./process-metrics.js";
|
|
50
|
-
import { getOwnPgid,
|
|
93
|
+
import { getOwnPgid, scanChildProcessesAsync } from "./process-scanner.js";
|
|
94
|
+
import { createProcessScanScheduler } from "./process-scan-scheduler.js";
|
|
95
|
+
import { pollCost } from "./poll-cost.js";
|
|
51
96
|
import { decideProjectTrust, readEventCwd } from "./project-trust.js";
|
|
52
97
|
import { PromptBus } from "./prompt-bus.js";
|
|
53
98
|
import { expandPromptTemplateFromDisk } from "./prompt-expander.js";
|
|
54
99
|
import { activate as activateProviderRegister, buildProviderCatalogue, onProviderChanged, reloadProviders, toModelInfo } from "./provider-register.js";
|
|
100
|
+
import { gateRemoteRegistration, httpBaseUrlFor, isRemoteEndpoint } from "./remote-registration-gate.js";
|
|
55
101
|
import { RetryTracker } from "./retry-tracker.js";
|
|
56
|
-
import { activate as activateRoleManager, lookupRole } from "./role-manager.js";
|
|
102
|
+
import { activate as activateRoleManager, lookupRole, resolveNamingModel } from "./role-manager.js";
|
|
57
103
|
import { registerRoleModelTools } from "./role-model-tools.js";
|
|
58
104
|
import { autoStartServer } from "./server-auto-start.js";
|
|
59
105
|
import { launchServer } from "./server-launcher.js";
|
|
60
|
-
import {
|
|
106
|
+
import { loadServerPins, notePinEndpoint, serverPinsPath } from "./server-pin-store.js";
|
|
107
|
+
import { handleSessionChange as _handleSessionChange, replaySessionEntries as _replaySessionEntries, sendStateSync as _sendStateSync, consumeSpawnToken, filterByEnabledModels } from "./session-sync.js";
|
|
61
108
|
import { tryDispatchExtensionCommand } from "./slash-dispatch.js";
|
|
109
|
+
import { UsageDrain, drainUsageAndSend, makeCacheWarmingDecisionHandler, sendShutdownUsageThenUnregister } from "./usage-drain.js";
|
|
62
110
|
import { detectSessionSource } from "./source-detector.js";
|
|
111
|
+
import { flushBufferedSubagentFrames, serveSubagentResync } from "./subagent-forward-sites.js";
|
|
63
112
|
import { SubagentFrameBuffer } from "./subagent-frame-buffer.js";
|
|
113
|
+
import { stripForForward } from "./subagent-frame-strip.js";
|
|
114
|
+
import { FanoutAdmissionGate, resolveAdmissionConfig } from "./subagent-fanout-admission.js";
|
|
115
|
+
import { SaturationSampler } from "./subagent-saturation.js";
|
|
116
|
+
import { isSubagentTick, SubagentTickThrottle } from "./subagent-tick-throttle.js";
|
|
64
117
|
import { inlineToolResultImages } from "./tool-result-image-inliner.js";
|
|
118
|
+
import { readTranscriptChunk, type TranscriptCursor } from "./transcript-backfill.js";
|
|
119
|
+
import { createTransportDiagnostics } from "./transport-diagnostics.js";
|
|
65
120
|
import { createTuiPromptAdapter } from "./tui-prompt-adapter.js";
|
|
66
121
|
import { classifyTurnActionability } from "./turn-actionability.js";
|
|
67
122
|
import { handleUiManagement, refreshUiModules, subscribeUiInvalidate, type UiModulesBridgeCtx } from "./ui-modules.js";
|
|
123
|
+
import { runUiSafely } from "./ui-stale-guard.js";
|
|
68
124
|
import { detectIsGitRepo } from "./vcs-info.js";
|
|
69
125
|
import { buildVisibilityRegisterFields } from "./visibility-intent.js";
|
|
70
126
|
|
|
71
127
|
const HEARTBEAT_INTERVAL = 15_000;
|
|
128
|
+
|
|
129
|
+
/**
|
|
130
|
+
* Formats the state behind a watchdog force-close for `server.log`.
|
|
131
|
+
*
|
|
132
|
+
* Shared by the primary connection and the `/dashboard-connect` move target:
|
|
133
|
+
* after a move the target IS the live connection, so omitting it there would
|
|
134
|
+
* silence exactly the socket under observation.
|
|
135
|
+
*/
|
|
136
|
+
function formatWatchdogFire(w: WatchdogFireInfo): string {
|
|
137
|
+
return (
|
|
138
|
+
`silent=${w.silentForMs}ms threshold=${w.watchdogTimeout}ms ` +
|
|
139
|
+
`readyState=${w.readyState} inboundQueue=${w.inboundQueueDepth} ` +
|
|
140
|
+
`refusedInbound=${w.refusedInbound} maxTickDrift=${w.maxTickDriftMs}ms`
|
|
141
|
+
);
|
|
142
|
+
}
|
|
72
143
|
const GIT_POLL_INTERVAL = 30_000;
|
|
73
144
|
// Platform-aware process scan cadence. Windows keeps the original 10 s /
|
|
74
145
|
// 30 s floor because PowerShell Get-CimInstance is expensive and can flash consoles;
|
|
75
146
|
// Unix uses 5 s / 5 s so legitimate bash subprocesses surface while still
|
|
76
147
|
// running. See change: tighten-process-list-ux.
|
|
77
|
-
const
|
|
78
|
-
const PROCESS_MIN_ELAPSED_MS = process.platform === "win32" ? 30_000 : 5_000; // platform-branch-ok: matches PROCESS_SCAN_INTERVAL's Windows-safe defaults
|
|
148
|
+
const PROCESS_MIN_ELAPSED_MS = process.platform === "win32" ? 30_000 : 5_000; // platform-branch-ok: Windows-safe default (costly PowerShell Get-CimInstance)
|
|
79
149
|
|
|
80
150
|
|
|
81
151
|
|
|
@@ -90,14 +160,29 @@ interface BridgeState {
|
|
|
90
160
|
hasUI?: boolean;
|
|
91
161
|
/** Monotonic generation counter — stale listeners bail out when mismatched */
|
|
92
162
|
generation?: number;
|
|
163
|
+
/** Path-gate denial map; process-global so a /reload keeps the 120 s suppression. */
|
|
164
|
+
pathGateSuppression?: Suppression;
|
|
93
165
|
/** The pi instance that owns the bridge (used to detect subagent re-entry) */
|
|
94
166
|
pi?: ExtensionAPI;
|
|
95
167
|
/** All connection instances from any bridge incarnation (for cleanup) */
|
|
96
168
|
connections?: ConnectionManager[];
|
|
97
169
|
/** All interval timers from any bridge incarnation (for cleanup) */
|
|
98
170
|
timers?: ReturnType<typeof setInterval>[];
|
|
171
|
+
/**
|
|
172
|
+
* Teardown callbacks for schedulers/watchers owned by a bridge incarnation
|
|
173
|
+
* (process-scan scheduler, git probe scheduler, git-dir watcher). Drained on
|
|
174
|
+
* re-init, `state.cleanup` and `session_shutdown`.
|
|
175
|
+
* See change: optimize-polling-hot-paths.
|
|
176
|
+
*/
|
|
177
|
+
disposables?: Array<() => void>;
|
|
99
178
|
/** True when the agent is currently in a turn (between agent_start and agent_end) */
|
|
100
179
|
isAgentStreaming?: boolean;
|
|
180
|
+
/**
|
|
181
|
+
* The auto-namer's durable state set, carried across reload as VALUES. The
|
|
182
|
+
* namer OBJECT is deliberately not carried: its closures would hold a stale
|
|
183
|
+
* connection, session id and ctx. See change: fix-auto-naming-reasoning-model.
|
|
184
|
+
*/
|
|
185
|
+
namerState?: PersistedNamerState;
|
|
101
186
|
/**
|
|
102
187
|
* Capture-once "was this pi dashboard-spawned?" boolean. Set on first bridge
|
|
103
188
|
* activation from `!!process.env.PI_DASHBOARD_SPAWN_TOKEN` BEFORE the token is
|
|
@@ -128,6 +213,10 @@ function getBridgeState(): BridgeState {
|
|
|
128
213
|
}
|
|
129
214
|
|
|
130
215
|
export default function (pi: ExtensionAPI) {
|
|
216
|
+
// Per-process opt-out, decided before ANY registration: an inert bridge
|
|
217
|
+
// registers no tool/command/handler/MCP and never connects or auto-starts.
|
|
218
|
+
// Dashboard spawns stamp PI_DASHBOARD_BRIDGE=on. See change: add-bridge-env-opt-out.
|
|
219
|
+
if (!shouldActivateBridge(process.env, () => loadConfig().bridge)) return;
|
|
131
220
|
try {
|
|
132
221
|
// Activate provider management before bridge init so providers are
|
|
133
222
|
// registered before session_start fires and models_list is sent.
|
|
@@ -160,28 +249,16 @@ function initBridge(pi: ExtensionAPI) {
|
|
|
160
249
|
// If bridge is already active for a different pi instance (e.g. a subagent
|
|
161
250
|
// loading extensions in the same process), skip initialization to avoid
|
|
162
251
|
// invalidating the parent session's bridge connection and event forwarding.
|
|
163
|
-
|
|
252
|
+
// `session_shutdown{reason:"reload"}` releases `prev.pi`, so the reloaded
|
|
253
|
+
// main session (a fresh ExtensionAPI) is not mistaken for a subagent.
|
|
254
|
+
// See change: fix-terminal-session-dashboard-reload (D4).
|
|
255
|
+
// Re-init teardown (cleanup, connections, timers, disposables) runs only for a
|
|
256
|
+
// genuine re-init; a subagent re-entry returns here untouched. Seam:
|
|
257
|
+
// `bridge-polling.ts`. See change: optimize-polling-hot-paths (D11).
|
|
258
|
+
if (!teardownPreviousIncarnation(prev, () => isBridgeReentry(prev, pi))) {
|
|
164
259
|
return;
|
|
165
260
|
}
|
|
166
261
|
|
|
167
|
-
prev.cleanup?.();
|
|
168
|
-
prev.cleanup = undefined;
|
|
169
|
-
|
|
170
|
-
// Disconnect ALL orphaned connections from previous bridge incarnations
|
|
171
|
-
if (prev.connections) {
|
|
172
|
-
for (const conn of prev.connections) {
|
|
173
|
-
conn.disconnect();
|
|
174
|
-
}
|
|
175
|
-
}
|
|
176
|
-
prev.connections = [];
|
|
177
|
-
// Clear ALL orphaned timers
|
|
178
|
-
if (prev.timers) {
|
|
179
|
-
for (const t of prev.timers) {
|
|
180
|
-
clearInterval(t);
|
|
181
|
-
}
|
|
182
|
-
}
|
|
183
|
-
prev.timers = [];
|
|
184
|
-
|
|
185
262
|
// Bump generation so stale listeners from previous initBridge calls bail out
|
|
186
263
|
const generation = (prev.generation ?? 0) + 1;
|
|
187
264
|
prev.generation = generation;
|
|
@@ -194,6 +271,15 @@ function initBridge(pi: ExtensionAPI) {
|
|
|
194
271
|
let sessionId: string = prev.sessionId ?? crypto.randomUUID();
|
|
195
272
|
let attachedChange: string | null = prev.attachedChange ?? null;
|
|
196
273
|
let sessionReady = false; // true after session_start has run
|
|
274
|
+
// Non-message usage drain cursor (usage / compaction / branch_summary
|
|
275
|
+
// entries → `usage_recorded`). Baselined at every session_start (init,
|
|
276
|
+
// reload, new/fork/resume) from the same snapshot as `usageSeed`; a
|
|
277
|
+
// reconnect never touches it. See change: count-non-message-usage.
|
|
278
|
+
const usageDrain = new UsageDrain();
|
|
279
|
+
function drainUsage(ctx: any): void {
|
|
280
|
+
if (!sessionReady) return;
|
|
281
|
+
drainUsageAndSend(usageDrain, (ctx ?? cachedCtx)?.sessionManager, (m) => connection.send(m));
|
|
282
|
+
}
|
|
197
283
|
let lastSessionFile: string | undefined;
|
|
198
284
|
let lastSessionDir: string | undefined;
|
|
199
285
|
let lastFirstMessage: string | undefined;
|
|
@@ -216,6 +302,13 @@ function initBridge(pi: ExtensionAPI) {
|
|
|
216
302
|
const found = cachedModelRegistry.find(provider, modelId);
|
|
217
303
|
if (found) {
|
|
218
304
|
(pi as any).setModel(found).then(() => {
|
|
305
|
+
// Apply the configured default thinking level alongside the default
|
|
306
|
+
// model. setModel preserves the current level, so an explicit call is
|
|
307
|
+
// required. pi.setThinkingLevel is synchronous and clamps the level to
|
|
308
|
+
// the model's capabilities. Empty value = "do not override".
|
|
309
|
+
// See change: add-default-thinking-level.
|
|
310
|
+
const level = freshConfig.defaultThinkingLevel;
|
|
311
|
+
if (level) (pi as any).setThinkingLevel?.(level);
|
|
219
312
|
setTimeout(() => sendModelUpdateIfChanged(), 50);
|
|
220
313
|
}).catch(() => {});
|
|
221
314
|
return null; // applied
|
|
@@ -243,7 +336,12 @@ function initBridge(pi: ExtensionAPI) {
|
|
|
243
336
|
|
|
244
337
|
let heartbeatTimer: ReturnType<typeof setInterval> | null = null;
|
|
245
338
|
let gitPollTimer: ReturnType<typeof setInterval> | null = null;
|
|
246
|
-
|
|
339
|
+
// Adaptive async process-scan scheduler (replaces the fixed setInterval).
|
|
340
|
+
// See change: optimize-polling-hot-paths.
|
|
341
|
+
const polling = createPollingHolder();
|
|
342
|
+
// Per-session git tracker (facts cache, HEAD branch, async status probe);
|
|
343
|
+
// renewed at every session_start / session change. See change:
|
|
344
|
+
// optimize-polling-hot-paths.
|
|
247
345
|
let previousProcessPids: string = ""; // JSON-stringified PID set for diff
|
|
248
346
|
const trackedPgids = new Set<number>(); // PGIDs captured during bash tool calls
|
|
249
347
|
// PIDs of subprocesses the bridge has spawned itself (dashboard server,
|
|
@@ -260,7 +358,62 @@ function initBridge(pi: ExtensionAPI) {
|
|
|
260
358
|
if (ownPgid !== undefined) selfSpawnedPgids.add(ownPgid);
|
|
261
359
|
}
|
|
262
360
|
let lastGitBranch: string | undefined;
|
|
263
|
-
let
|
|
361
|
+
let lastGitPrJson: string | undefined; // see change: redesign-composer-session-strip
|
|
362
|
+
// Async PR-status scheduler: `gh pr view` off the 30 s tick, own ≥120 s
|
|
363
|
+
// cadence + forced refresh on `git_info_refresh`. Timers are registered in
|
|
364
|
+
// the bridge-timer registry so a reload cannot leak them; probe completion
|
|
365
|
+
// re-runs the one git change-detector. See change:
|
|
366
|
+
// redesign-composer-session-strip (D5).
|
|
367
|
+
const unregisterTimer = (timer: ReturnType<typeof setTimeout>) => {
|
|
368
|
+
const timers = getBridgeState().timers;
|
|
369
|
+
const index = timers ? timers.indexOf(timer as unknown as ReturnType<typeof setInterval>) : -1;
|
|
370
|
+
if (index !== -1) timers!.splice(index, 1);
|
|
371
|
+
};
|
|
372
|
+
// One-shot timers leave the registry when they fire as well as when they
|
|
373
|
+
// are cleared, so a long-lived session never accumulates dead handles.
|
|
374
|
+
const setRegisteredTimeout = (fn: () => void, ms: number): ReturnType<typeof setTimeout> => {
|
|
375
|
+
const timer = setTimeout(() => {
|
|
376
|
+
unregisterTimer(timer);
|
|
377
|
+
fn();
|
|
378
|
+
}, ms);
|
|
379
|
+
getBridgeState().timers!.push(timer as unknown as ReturnType<typeof setInterval>);
|
|
380
|
+
return timer;
|
|
381
|
+
};
|
|
382
|
+
const clearRegisteredTimeout = (timer: ReturnType<typeof setTimeout>): void => {
|
|
383
|
+
clearTimeout(timer);
|
|
384
|
+
unregisterTimer(timer);
|
|
385
|
+
};
|
|
386
|
+
const registerDisposable = (fn: () => void): void => {
|
|
387
|
+
(getBridgeState().disposables ??= []).push(fn);
|
|
388
|
+
};
|
|
389
|
+
// ONE stable disposer, (re-)ensured on every session_start: a shutdown drains
|
|
390
|
+
// and empties the list, and this incarnation may start a new session after it.
|
|
391
|
+
const disposePolling = () => polling.disposeAll();
|
|
392
|
+
const ensurePollingDisposable = () => ensureDisposable(getBridgeState(), disposePolling);
|
|
393
|
+
ensurePollingDisposable();
|
|
394
|
+
/** Dispose the previous tracker and start a fresh one for the incoming session. */
|
|
395
|
+
function renewGitTracker(): GitTracker {
|
|
396
|
+
ensurePollingDisposable();
|
|
397
|
+
return polling.replaceGitTracker(createGitTracker({
|
|
398
|
+
getBc: () => syncBc(),
|
|
399
|
+
applyBc: (bc) => applyBc(bc),
|
|
400
|
+
isActive,
|
|
401
|
+
setTimer: setRegisteredTimeout,
|
|
402
|
+
clearTimer: clearRegisteredTimeout,
|
|
403
|
+
}));
|
|
404
|
+
}
|
|
405
|
+
const prStatus: PrStatusScheduler = createPrStatusScheduler({
|
|
406
|
+
probe: (cwd) => git.prStatusAsync({ cwd }),
|
|
407
|
+
// A reload starts a new bridge incarnation; the old scheduler must not
|
|
408
|
+
// keep probing into the new timer registry. See change:
|
|
409
|
+
// redesign-composer-session-strip (doubt-review #2).
|
|
410
|
+
alive: isActive,
|
|
411
|
+
onChange: () => {
|
|
412
|
+
if (isActive()) polling.gitTracker?.sendCached();
|
|
413
|
+
},
|
|
414
|
+
setTimer: setRegisteredTimeout,
|
|
415
|
+
clearTimer: clearRegisteredTimeout,
|
|
416
|
+
});
|
|
264
417
|
let lastGitWorktreeJson: string | undefined; // see change: add-worktree-spawn-dialog
|
|
265
418
|
let lastGitStatusJson: string | undefined; // see change: add-session-uncommitted-indicator-and-commit
|
|
266
419
|
let lastCwdMissing: boolean | undefined; // see change: add-worktree-lifecycle-actions
|
|
@@ -270,6 +423,10 @@ function initBridge(pi: ExtensionAPI) {
|
|
|
270
423
|
// Default true so a bridge that registers before the first push still names.
|
|
271
424
|
let autoNameSessions = true;
|
|
272
425
|
let autoNamer: AutoNamer | undefined;
|
|
426
|
+
// The namer's durable state set is carried across reload as VALUES, never as
|
|
427
|
+
// the namer object: its closures would retain a stale connection, session id
|
|
428
|
+
// and ctx. See change: fix-auto-naming-reasoning-model (design D7).
|
|
429
|
+
let namerState: PersistedNamerState | undefined = prev.namerState;
|
|
273
430
|
// Lazily-loaded pi-ai streamSimple (null = load attempted and failed).
|
|
274
431
|
let piAiStreamSimple: StreamSimpleFn | null | undefined;
|
|
275
432
|
let cachedHasUI: boolean | undefined = prev.hasUI;
|
|
@@ -295,23 +452,15 @@ function initBridge(pi: ExtensionAPI) {
|
|
|
295
452
|
// dashboard-provided spawn cwd. See change: adopt-pi-074-080-features (A.3).
|
|
296
453
|
const activationCwd = process.cwd();
|
|
297
454
|
|
|
298
|
-
// Does the running pi emit `agent_settled` natively (≥ 0.80.4)? Read once at
|
|
299
|
-
// activation. Floor pi → the bridge synthesizes a settle after each
|
|
300
|
-
// `agent_end`. Read failure → false → synthesize (safe default: the
|
|
301
|
-
// dashboard still gets exactly one terminal settle). See change:
|
|
302
|
-
// adopt-pi-074-080-features (A.1).
|
|
303
|
-
let piEmitsNativeSettled = false;
|
|
304
|
-
try {
|
|
305
|
-
piEmitsNativeSettled = nativeAgentSettledSupported(defaultReadPiVersion());
|
|
306
|
-
} catch { /* unknown version → synthesize */ }
|
|
307
|
-
|
|
308
455
|
let promptBus: PromptBus | undefined;
|
|
309
456
|
|
|
310
457
|
// Provider-retry synthesis tracker. pi's ExtensionAPI does not expose
|
|
311
458
|
// `auto_retry_*` events, so the bridge synthesizes them by OBSERVING pi's
|
|
312
|
-
//
|
|
313
|
-
//
|
|
314
|
-
|
|
459
|
+
// real event shape: one full agent_start…agent_end cycle PER attempt, with a
|
|
460
|
+
// single agent_settled as the sole terminal signal. `maxAttempts`/`delayMs`
|
|
461
|
+
// are sourced READ-ONLY from pi's retry settings for the display countdown;
|
|
462
|
+
// the bridge never writes them. See change: retry-forever-with-stop-control.
|
|
463
|
+
const retryTracker = new RetryTracker(readPiRetrySettings({ cwd: activationCwd }));
|
|
315
464
|
// Empty-actionable-turn guard: when a terminal turn is a clean-but-empty
|
|
316
465
|
// `stop` (thinking-only, no text, no tool call), continue-or-surface instead
|
|
317
466
|
// of idling silently. Provider-agnostic. See change:
|
|
@@ -331,6 +480,98 @@ function initBridge(pi: ExtensionAPI) {
|
|
|
331
480
|
// See change: fix-subagent-live-detail-reliability.
|
|
332
481
|
const subagentFrameBuffer = new SubagentFrameBuffer();
|
|
333
482
|
|
|
483
|
+
// Dashboard MCP server registration with pi's built-in MCP. The bearer lives
|
|
484
|
+
// only in this registrar and pi's registration — never in process.env.
|
|
485
|
+
// See change: migrate-mcp-to-pi-builtin (D1).
|
|
486
|
+
const mcpRegistrar = createMcpDashboardRegistrar({
|
|
487
|
+
pi: pi as unknown as McpRegistrationApi,
|
|
488
|
+
sessionId: () => sessionId,
|
|
489
|
+
reportUnavailable: (reason) => {
|
|
490
|
+
connection.send({
|
|
491
|
+
type: "plugin_pi_message",
|
|
492
|
+
sessionId,
|
|
493
|
+
pluginId: "mcp-server",
|
|
494
|
+
messageType: "mcp/registration-unavailable",
|
|
495
|
+
payload: { reason },
|
|
496
|
+
});
|
|
497
|
+
},
|
|
498
|
+
log: console,
|
|
499
|
+
});
|
|
500
|
+
|
|
501
|
+
// Bound the Agent-tick rate on the `tool_execution_update` carrier. That
|
|
502
|
+
// carrier has no throttle anywhere on its path, so its rate is the
|
|
503
|
+
// subagent's raw session-event rate; the sibling `subagents:*` carrier is
|
|
504
|
+
// already coalesced to 250 ms by the producer and is what paces the LIVE
|
|
505
|
+
// render, so this window costs replay staleness, not liveness.
|
|
506
|
+
//
|
|
507
|
+
// `windowMs` comes from the shared dashboard config, read once here at
|
|
508
|
+
// bridge init (`0` = disabled, the byte-identical rollback path). `send` and
|
|
509
|
+
// `canSend` deliberately resolve `connection` / `sessionReady` / `sessionId`
|
|
510
|
+
// at CALL time: all three can move while a frame is held, and a captured
|
|
511
|
+
// reference would send over a dead connection or under a stale session.
|
|
512
|
+
// See change: reduce-bridge-tick-bandwidth (D2/D3/D4).
|
|
513
|
+
const subagentTickThrottle = new SubagentTickThrottle<unknown>({
|
|
514
|
+
windowMs: loadConfig().subagentTickThrottleMs,
|
|
515
|
+
send: (msg) => connection.send(msg),
|
|
516
|
+
canSend: (frameSessionId) => isActive() && sessionReady && frameSessionId === sessionId,
|
|
517
|
+
});
|
|
518
|
+
|
|
519
|
+
// Bound the bridge's per-token streaming cost. pi's `message_update` carries
|
|
520
|
+
// the FULL accumulated text snapshot, so forwarding each one synchronously
|
|
521
|
+
// paid a `JSON.stringify` per source token on pi's own event loop — O(N²)
|
|
522
|
+
// bytes for an N-token turn. Only contiguous `text_*` snapshots coalesce;
|
|
523
|
+
// thinking/toolcall/unknown sub-events flush first and forward immediately so
|
|
524
|
+
// they stay lossless and in source order.
|
|
525
|
+
//
|
|
526
|
+
// `send` resolves `connection` / `sessionReady` at CALL time: both can move
|
|
527
|
+
// while a snapshot is parked, and a captured reference would write a stale
|
|
528
|
+
// snapshot over a dead socket. The inliner moves INTO the send callback so it
|
|
529
|
+
// runs once per flushed window instead of once per token, still ahead of the
|
|
530
|
+
// snapshot that references its assets. `setTimer`/`clearTimer` own the single
|
|
531
|
+
// armed window and keep it in the bridge-timer registry so a reload cannot
|
|
532
|
+
// leak it.
|
|
533
|
+
// See change: coalesce-bridge-message-update-snapshots (D1–D7).
|
|
534
|
+
const coalescer = new MessageUpdateCoalescer<Record<string, unknown>>({
|
|
535
|
+
windowMs: COALESCE_WINDOW_MS,
|
|
536
|
+
isActive: () => isActive() && sessionReady,
|
|
537
|
+
send: (event) => {
|
|
538
|
+
if (!isActive() || !sessionReady) return;
|
|
539
|
+
maybeInlineAssistantImages(event);
|
|
540
|
+
connection.send(mapEventToProtocol(sessionId, event));
|
|
541
|
+
},
|
|
542
|
+
setTimer: (fn, ms) => {
|
|
543
|
+
const timer = setTimeout(fn, ms);
|
|
544
|
+
getBridgeState().timers!.push(timer as unknown as ReturnType<typeof setInterval>);
|
|
545
|
+
return timer;
|
|
546
|
+
},
|
|
547
|
+
clearTimer: (timer) => {
|
|
548
|
+
clearTimeout(timer);
|
|
549
|
+
const timers = getBridgeState().timers;
|
|
550
|
+
const index = timers ? timers.indexOf(timer as unknown as ReturnType<typeof setInterval>) : -1;
|
|
551
|
+
if (index !== -1) timers!.splice(index, 1);
|
|
552
|
+
},
|
|
553
|
+
});
|
|
554
|
+
|
|
555
|
+
// Per-message generation for the coalescing barrier. Distinct from the
|
|
556
|
+
// bridge-instance `generation` above, which only changes on `initBridge` and
|
|
557
|
+
// so gives no intra-session ordering. Incremented on EVERY `message_start`
|
|
558
|
+
// (user, assistant and — for the barrier only — `system`): a retry chain or a
|
|
559
|
+
// new turn must reset the barrier too. A `system` message reaches the barrier
|
|
560
|
+
// and then returns, so it opens an identity no `message_update` can ever
|
|
561
|
+
// match (pi emits its start/end adjacently — see
|
|
562
|
+
// filter-system-role-message-forwarding design D2). Folded into the message
|
|
563
|
+
// key rather than compared standalone, because a `message_update` carries no
|
|
564
|
+
// generation of its own — an update can only be stamped with the counter's
|
|
565
|
+
// current value.
|
|
566
|
+
// See change: coalesce-bridge-message-update-snapshots (D4).
|
|
567
|
+
let assistantMessageGen = 0;
|
|
568
|
+
|
|
569
|
+
/**
|
|
570
|
+
* Identity of a message for the barrier: `<gen>:<role>:<timestamp>`.
|
|
571
|
+
* `message.id` is unusable — pi stamps it only at post-handler persistence.
|
|
572
|
+
*/
|
|
573
|
+
const messageKeyOf = (gen: number, message: unknown): string => coalescer.keyOf(gen, message);
|
|
574
|
+
|
|
334
575
|
// Bridge-owned queue structures with TWO different ownership models:
|
|
335
576
|
//
|
|
336
577
|
// • bridgeSteering (pi-OWNED + SHADOW) — mirrors pi's Agent.steeringQueue.
|
|
@@ -342,8 +583,13 @@ function initBridge(pi: ExtensionAPI) {
|
|
|
342
583
|
// dashboard-originated follow-up entries while the agent is streaming.
|
|
343
584
|
// Pi never sees these entries until `drainFollowupQueue()` ships them
|
|
344
585
|
// one-at-a-time on `agent_end`. Mutated by `bufferFollowupSend`,
|
|
345
|
-
// `drainFollowupQueue`, and the
|
|
346
|
-
// promote / clear
|
|
586
|
+
// `drainFollowupQueue`, and the four mutation handlers (edit / remove /
|
|
587
|
+
// promote / clear).
|
|
588
|
+
//
|
|
589
|
+
// Entries carry their image attachments (`{ text, images? }`) and the
|
|
590
|
+
// buffer is bounded in BYTES as well as depth; the state itself lives in
|
|
591
|
+
// `followup-buffer.ts` so the admission arithmetic is testable and the
|
|
592
|
+
// ceiling injectable. See change: fix-bridge-followup-image-drop.
|
|
347
593
|
//
|
|
348
594
|
// Both feed the same `queue_update` ExtensionToServerMessage.
|
|
349
595
|
//
|
|
@@ -352,14 +598,32 @@ function initBridge(pi: ExtensionAPI) {
|
|
|
352
598
|
//
|
|
353
599
|
// See change: rework-mid-turn-prompt-queue (spec mid-turn-prompt-queue).
|
|
354
600
|
let bridgeSteering: string[] = [];
|
|
355
|
-
|
|
601
|
+
const bridgeFollowUp = createFollowupBuffer();
|
|
356
602
|
function emitQueueUpdate(): void {
|
|
357
603
|
if (!isActive() || !sessionReady) return;
|
|
358
604
|
connection.send({
|
|
359
605
|
type: "queue_update",
|
|
360
606
|
sessionId,
|
|
361
607
|
steering: [...bridgeSteering],
|
|
362
|
-
|
|
608
|
+
// Views only: text + image COUNT. Image bytes never cross the wire.
|
|
609
|
+
followUp: bridgeFollowUp.views(),
|
|
610
|
+
});
|
|
611
|
+
}
|
|
612
|
+
/**
|
|
613
|
+
* Surface a refusal to the user. Every follow-up refusal path emits one:
|
|
614
|
+
* a bare `console.warn` is invisible in the dashboard, which is the same
|
|
615
|
+
* defect class this change exists to fix (design D4).
|
|
616
|
+
*/
|
|
617
|
+
function sendCommandFeedback(command: string, message: string): void {
|
|
618
|
+
if (!isActive() || !sessionReady) return;
|
|
619
|
+
connection.send({
|
|
620
|
+
type: "event_forward",
|
|
621
|
+
sessionId,
|
|
622
|
+
event: {
|
|
623
|
+
eventType: "command_feedback",
|
|
624
|
+
timestamp: Date.now(),
|
|
625
|
+
data: { command, status: "error", message },
|
|
626
|
+
},
|
|
363
627
|
});
|
|
364
628
|
}
|
|
365
629
|
function recordSteerSent(text: string): void {
|
|
@@ -370,8 +634,6 @@ function initBridge(pi: ExtensionAPI) {
|
|
|
370
634
|
bridgeSteering.push(text);
|
|
371
635
|
emitQueueUpdate();
|
|
372
636
|
}
|
|
373
|
-
/** Soft cap on follow-up buffer depth. See design.md Decision 8. */
|
|
374
|
-
const FOLLOWUP_QUEUE_CAP = 20;
|
|
375
637
|
/**
|
|
376
638
|
* Push a follow-up entry into the bridge-owned buffer.
|
|
377
639
|
*
|
|
@@ -383,18 +645,36 @@ function initBridge(pi: ExtensionAPI) {
|
|
|
383
645
|
* The `isAgentStreaming` gate is defense-in-depth (callers already gate on
|
|
384
646
|
* `wasStreaming === true` before invoking this function).
|
|
385
647
|
*
|
|
386
|
-
* Image attachments
|
|
387
|
-
*
|
|
388
|
-
*
|
|
389
|
-
*
|
|
648
|
+
* Image attachments ride the entry and are delivered when the drain ships
|
|
649
|
+
* it. They are validated HERE rather than at drain time so the byte
|
|
650
|
+
* accounting reflects what will actually be sent, and so a bad attachment is
|
|
651
|
+
* reported while the user is still looking at the composer (design D7).
|
|
652
|
+
*
|
|
653
|
+
* Refused entries are refused WHOLE — images are never stripped to make an
|
|
654
|
+
* entry fit, because delivering a prompt whose attachment vanished is the
|
|
655
|
+
* original bug. See change: fix-bridge-followup-image-drop.
|
|
390
656
|
*/
|
|
391
|
-
function bufferFollowupSend(text: string): void {
|
|
657
|
+
function bufferFollowupSend(text: string, images?: unknown): void {
|
|
392
658
|
if (!getBridgeState().isAgentStreaming) return;
|
|
393
|
-
|
|
394
|
-
|
|
659
|
+
const { valid, dropped } = validateImages(images);
|
|
660
|
+
const admitted = bridgeFollowUp.push({
|
|
661
|
+
text,
|
|
662
|
+
...(valid.length > 0 ? { images: valid } : {}),
|
|
663
|
+
});
|
|
664
|
+
if (!admitted.ok) {
|
|
665
|
+
console.warn("[dashboard] follow-up buffer refused entry:", admitted.message);
|
|
666
|
+
sendCommandFeedback("send_prompt", admitted.message);
|
|
395
667
|
return;
|
|
396
668
|
}
|
|
397
|
-
|
|
669
|
+
// Reported only once the entry is actually queued: a refused entry is not
|
|
670
|
+
// in the queue at all, so telling the user which of its attachments were
|
|
671
|
+
// dropped is noise on top of the refusal.
|
|
672
|
+
if (dropped.length > 0) {
|
|
673
|
+
sendCommandFeedback(
|
|
674
|
+
"send_prompt",
|
|
675
|
+
`${dropped.length} attachment(s) dropped: ${dropped.join("; ")}`,
|
|
676
|
+
);
|
|
677
|
+
}
|
|
398
678
|
emitQueueUpdate();
|
|
399
679
|
}
|
|
400
680
|
/**
|
|
@@ -420,7 +700,10 @@ function initBridge(pi: ExtensionAPI) {
|
|
|
420
700
|
* `executor` returns, pi's `finishRun()` flips `isStreaming = false` and
|
|
421
701
|
* `activeRun = undefined`. After that point, anything queued into pi's
|
|
422
702
|
* internal followUpQueue NEVER drains — pi has stopped reading it.
|
|
423
|
-
* (Verified at pi-coding-agent pi-agent-core/agent.js:
|
|
703
|
+
* (Verified at pi-coding-agent pi-agent-core/agent.js: `finishRun()` clears
|
|
704
|
+
* `isStreaming` + `activeRun`, and `getFollowUpMessages` is only supplied to
|
|
705
|
+
* the loop while a run is active. Re-verified against pi 0.84.1 — behaviour
|
|
706
|
+
* unchanged, line numbers moved. See change: update-pi-core-0-84-adopt-apis.)
|
|
424
707
|
*
|
|
425
708
|
* Two retry loops handle the transition window correctly:
|
|
426
709
|
* - retryCount tracks how many setTimeout retries we've done
|
|
@@ -467,8 +750,14 @@ function initBridge(pi: ExtensionAPI) {
|
|
|
467
750
|
|
|
468
751
|
// Hand to pi as a fresh turn (no deliverAs). Pi is now idle, so
|
|
469
752
|
// pi.sendUserMessage starts a new run via Agent.prompt().
|
|
753
|
+
//
|
|
754
|
+
// NO send options, deliberately: `{deliverAs:"followUp"}` here is a
|
|
755
|
+
// known-broken path (pi has already exited `getFollowUpMessages()`, so
|
|
756
|
+
// the entry would never drain). `buildUserMessageContent` supplies the
|
|
757
|
+
// content shape WITHOUT inheriting the steer/idle send options.
|
|
758
|
+
// See change: fix-bridge-followup-image-drop (design D6).
|
|
470
759
|
try {
|
|
471
|
-
(pi.sendUserMessage as any)(entry);
|
|
760
|
+
(pi.sendUserMessage as any)(buildUserMessageContent(entry.text, entry.images));
|
|
472
761
|
} catch (err) {
|
|
473
762
|
console.warn(
|
|
474
763
|
"[dashboard] drainFollowupQueue: pi.sendUserMessage threw — entry lost:",
|
|
@@ -492,8 +781,13 @@ function initBridge(pi: ExtensionAPI) {
|
|
|
492
781
|
* user follow-ups: both share the one `bridgeFollowUp` buffer and the
|
|
493
782
|
* `isDraining` lock, shipping one entry per `agent_end`.
|
|
494
783
|
*
|
|
495
|
-
*
|
|
496
|
-
* `
|
|
784
|
+
* Text-only by design — the plugin path has no image source — so it wraps
|
|
785
|
+
* into a `{ text }` entry. Subject to BOTH buffer bounds, with the refusal
|
|
786
|
+
* reported under its OWN command name (`enqueue_followup`): a refused system
|
|
787
|
+
* nudge is a lost plugin continuation, and attributing it to `send_prompt`
|
|
788
|
+
* would misreport a programmatic refusal as a user action (design D8).
|
|
789
|
+
*
|
|
790
|
+
* Schedules `drainFollowupQueue(0)` via
|
|
497
791
|
* `setTimeout(…, 0)` so the drain re-runs AFTER the async judge verdict
|
|
498
792
|
* resolves (the bridge's own `agent_end` drain already ran against an
|
|
499
793
|
* empty buffer by then).
|
|
@@ -503,11 +797,12 @@ function initBridge(pi: ExtensionAPI) {
|
|
|
503
797
|
*/
|
|
504
798
|
function enqueueSystemFollowup(text: string): void {
|
|
505
799
|
if (typeof text !== "string" || text.length === 0) return;
|
|
506
|
-
|
|
507
|
-
|
|
800
|
+
const admitted = bridgeFollowUp.push({ text });
|
|
801
|
+
if (!admitted.ok) {
|
|
802
|
+
console.warn("[dashboard] follow-up buffer refused system entry:", admitted.message);
|
|
803
|
+
sendCommandFeedback("enqueue_followup", admitted.message);
|
|
508
804
|
return;
|
|
509
805
|
}
|
|
510
|
-
bridgeFollowUp.push(text);
|
|
511
806
|
emitQueueUpdate();
|
|
512
807
|
setTimeout(() => drainFollowupQueue(0), 0);
|
|
513
808
|
}
|
|
@@ -536,6 +831,9 @@ function initBridge(pi: ExtensionAPI) {
|
|
|
536
831
|
/** Forward a synthesized auto_retry_* event using the standard event_forward shape. */
|
|
537
832
|
const sendSyntheticRetryEvent = (eventType: string, data: Record<string, unknown>): void => {
|
|
538
833
|
if (!isActive() || !sessionReady) return;
|
|
834
|
+
// A synthesized retry event renders as a chat row, so a parked snapshot must
|
|
835
|
+
// still land first. See change: coalesce-bridge-message-update-snapshots (D5).
|
|
836
|
+
coalescer.flush();
|
|
539
837
|
connection.send({
|
|
540
838
|
type: "event_forward",
|
|
541
839
|
sessionId,
|
|
@@ -688,6 +986,84 @@ function initBridge(pi: ExtensionAPI) {
|
|
|
688
986
|
appendMessageWrapped = true;
|
|
689
987
|
}
|
|
690
988
|
|
|
989
|
+
let customPersistenceWrapped = false;
|
|
990
|
+
let customWrappedSm: any = null;
|
|
991
|
+
|
|
992
|
+
/**
|
|
993
|
+
* Wrap the sessionManager custom-persistence methods so the bridge can
|
|
994
|
+
* forward BOTH custom surfaces at the single chokepoint where pi commits
|
|
995
|
+
* them (change: render-inline-reasoning-and-custom-entries, D2):
|
|
996
|
+
*
|
|
997
|
+
* - `appendCustomMessageEntry` (pi.sendMessage) → synthesized `message_end`
|
|
998
|
+
* with `message.role === "custom"` — pi's idle-path sendMessage emits
|
|
999
|
+
* message_start/end to INTERNAL listeners only, so the enriched loop
|
|
1000
|
+
* never sees it (and is guarded against double-forwarding the
|
|
1001
|
+
* agent-loop path above).
|
|
1002
|
+
* - `appendCustomEntry` (pi.appendEntry) → `custom_entry` protocol event —
|
|
1003
|
+
* pi does not dispatch `entry_appended` to extensions at all.
|
|
1004
|
+
*
|
|
1005
|
+
* pi-flows' `flow-event` entries are excluded inside the shared mapper
|
|
1006
|
+
* (they are appended live by pi-flows itself; forwarding would
|
|
1007
|
+
* double-render beside the dedicated flow card).
|
|
1008
|
+
*/
|
|
1009
|
+
function wrapCustomPersistenceForCtx(ctx: any): void {
|
|
1010
|
+
const sm = ctx?.sessionManager;
|
|
1011
|
+
if (!sm || typeof sm.appendCustomMessageEntry !== "function" || typeof sm.appendCustomEntry !== "function") {
|
|
1012
|
+
return;
|
|
1013
|
+
}
|
|
1014
|
+
// Re-wrap when sessionManager identity changes (session replacement).
|
|
1015
|
+
if (sm === customWrappedSm && customPersistenceWrapped) return;
|
|
1016
|
+
const origMessage = sm.appendCustomMessageEntry.bind(sm);
|
|
1017
|
+
sm.appendCustomMessageEntry = (customType: any, content: any, display: any, details: any) => {
|
|
1018
|
+
const entryId = origMessage(customType, content, display, details);
|
|
1019
|
+
// Chat-row ordering: this sink is OUTSIDE the two event loops, so it needs
|
|
1020
|
+
// its own flush. See change: coalesce-bridge-message-update-snapshots (D5).
|
|
1021
|
+
coalescer.flush();
|
|
1022
|
+
try {
|
|
1023
|
+
const forward = toCustomMessageForward({ customType, content, display, details, entryId });
|
|
1024
|
+
if (forward && sessionReady && isActive()) {
|
|
1025
|
+
connection.send({
|
|
1026
|
+
type: "event_forward",
|
|
1027
|
+
sessionId,
|
|
1028
|
+
event: {
|
|
1029
|
+
eventType: "message_end",
|
|
1030
|
+
timestamp: Date.now(),
|
|
1031
|
+
data: { type: "message_end", message: forward.message, entryId: forward.entryId },
|
|
1032
|
+
},
|
|
1033
|
+
});
|
|
1034
|
+
}
|
|
1035
|
+
} catch (err) {
|
|
1036
|
+
console.error("[dashboard] custom message forward failed:", err);
|
|
1037
|
+
}
|
|
1038
|
+
return entryId;
|
|
1039
|
+
};
|
|
1040
|
+
const origEntry = sm.appendCustomEntry.bind(sm);
|
|
1041
|
+
sm.appendCustomEntry = (customType: any, data: any) => {
|
|
1042
|
+
const entryId = origEntry(customType, data);
|
|
1043
|
+
// Chat-row ordering: the second out-of-loop sink. See D5.
|
|
1044
|
+
coalescer.flush();
|
|
1045
|
+
try {
|
|
1046
|
+
const forward = toCustomEntryForward({ type: "custom", customType, data, id: entryId });
|
|
1047
|
+
if (forward && sessionReady && isActive()) {
|
|
1048
|
+
connection.send({
|
|
1049
|
+
type: "event_forward",
|
|
1050
|
+
sessionId,
|
|
1051
|
+
event: {
|
|
1052
|
+
eventType: "custom_entry",
|
|
1053
|
+
timestamp: Date.now(),
|
|
1054
|
+
data: { type: "custom_entry", ...forward },
|
|
1055
|
+
},
|
|
1056
|
+
});
|
|
1057
|
+
}
|
|
1058
|
+
} catch (err) {
|
|
1059
|
+
console.error("[dashboard] custom entry forward failed:", err);
|
|
1060
|
+
}
|
|
1061
|
+
return entryId;
|
|
1062
|
+
};
|
|
1063
|
+
customWrappedSm = sm;
|
|
1064
|
+
customPersistenceWrapped = true;
|
|
1065
|
+
}
|
|
1066
|
+
|
|
691
1067
|
/** Wrap a callback so errors log instead of crashing the host pi agent. */
|
|
692
1068
|
function safe<T extends (...args: any[]) => any>(fn: T): T {
|
|
693
1069
|
return ((...args: any[]) => {
|
|
@@ -708,7 +1084,83 @@ function initBridge(pi: ExtensionAPI) {
|
|
|
708
1084
|
// Load config to determine WebSocket URL
|
|
709
1085
|
ensureConfig();
|
|
710
1086
|
const config = loadConfig();
|
|
711
|
-
|
|
1087
|
+
// The ONE place an endpoint is chosen (D3, task 3.1). Explicit configuration
|
|
1088
|
+
// is pinned and outranks everything; the HOME-derived rendezvous record is
|
|
1089
|
+
// the default; discovery may only suggest. The legacy
|
|
1090
|
+
// `ws://localhost:<configured piPort>` is the last resort, kept so a new
|
|
1091
|
+
// bridge still works against a dashboard that predates the record (task 8.3).
|
|
1092
|
+
const rendezvous = rendezvousEndpoint();
|
|
1093
|
+
const endpointChoice = resolveEndpoint({
|
|
1094
|
+
socketEnv: process.env.PI_DASHBOARD_SOCKET,
|
|
1095
|
+
urlEnv: process.env.PI_DASHBOARD_URL,
|
|
1096
|
+
record: rendezvous ?? undefined,
|
|
1097
|
+
});
|
|
1098
|
+
// The instance this bridge believes it is talking to (task 3.4). Any
|
|
1099
|
+
// re-target is judged against THIS id, not against the endpoint string —
|
|
1100
|
+
// the same instance may legitimately move, and a different instance may
|
|
1101
|
+
// legitimately answer at the same endpoint.
|
|
1102
|
+
let registeredInstanceId: string | undefined = endpointChoice.available
|
|
1103
|
+
? endpointChoice.instanceId
|
|
1104
|
+
: undefined;
|
|
1105
|
+
// A socket-pinned bridge learns its instance from the FILESYSTEM, beside the
|
|
1106
|
+
// socket it was pinned to. Without this every dashboard-spawned session
|
|
1107
|
+
// answered `/dashboard-where` with `instance: unverified`, because only the
|
|
1108
|
+
// record-sourced path carried an id — and the record could not be used here,
|
|
1109
|
+
// since it names the HOME's owner rather than whichever instance owns this
|
|
1110
|
+
// socket. Best-effort: a missing or unreadable file leaves the id unset,
|
|
1111
|
+
// which is the honest answer and exactly today's behaviour.
|
|
1112
|
+
// See change: add-pi-gateway-transport-identity (task 9.6).
|
|
1113
|
+
if (registeredInstanceId === undefined && endpointChoice.available && process.env.PI_DASHBOARD_SOCKET) {
|
|
1114
|
+
const idFile = instanceIdFileForSocket(process.env.PI_DASHBOARD_SOCKET);
|
|
1115
|
+
if (idFile) {
|
|
1116
|
+
try {
|
|
1117
|
+
const id = fs.readFileSync(idFile, "utf8").trim();
|
|
1118
|
+
if (id) registeredInstanceId = id;
|
|
1119
|
+
} catch {
|
|
1120
|
+
/* absent or unreadable — stay unverified rather than guess */
|
|
1121
|
+
}
|
|
1122
|
+
}
|
|
1123
|
+
}
|
|
1124
|
+
// `let`: a completed move re-points this, so diagnostics and `/dashboard-where`
|
|
1125
|
+
// report where the session actually IS rather than where it started.
|
|
1126
|
+
// biome-ignore lint/style/useConst: reassigned by the move command.
|
|
1127
|
+
let dashboardUrl = endpointChoice.available
|
|
1128
|
+
? endpointChoice.url
|
|
1129
|
+
: `ws://localhost:${config.piPort}`;
|
|
1130
|
+
// Pinned endpoints refuse every re-target, including a discovered one (D3).
|
|
1131
|
+
const endpointPinned = endpointChoice.available && endpointChoice.pinned;
|
|
1132
|
+
// Task 10.1: log the winning precedence rule, or diagnosing "it connected to
|
|
1133
|
+
// the wrong dashboard" means guessing which source won.
|
|
1134
|
+
const endpointDetail = `${dashboardUrl} (source=${
|
|
1135
|
+
endpointChoice.available ? endpointChoice.source : "legacy-config-piPort"
|
|
1136
|
+
} pinned=${endpointPinned})`;
|
|
1137
|
+
console.log(`[dashboard] endpoint ${endpointDetail}`);
|
|
1138
|
+
// ...and again over the wire, because the line above is discarded under the
|
|
1139
|
+
// default `capturePiOutput:false` (task 10.5).
|
|
1140
|
+
const transportDiagnostics = createTransportDiagnostics();
|
|
1141
|
+
transportDiagnostics.record({ event: "endpoint_resolved", detail: endpointDetail });
|
|
1142
|
+
|
|
1143
|
+
/**
|
|
1144
|
+
* Mint a fresh, single-use bridge ticket for a REMOTE endpoint.
|
|
1145
|
+
*
|
|
1146
|
+
* Returns undefined for a local endpoint (nothing to mint) and THROWS when a
|
|
1147
|
+
* remote endpoint cannot be authorised, so ConnectionManager retries on its
|
|
1148
|
+
* backoff rather than dialling a credential-less upgrade the gateway will
|
|
1149
|
+
* refuse. The reason is logged once per attempt: "refused" here means the
|
|
1150
|
+
* bearer is missing, unpaired or revoked, which is an operator problem and
|
|
1151
|
+
* must not be reported as an unreachable dashboard.
|
|
1152
|
+
*/
|
|
1153
|
+
async function prepareRemoteUpgrade(endpoint: string): Promise<{ url?: string } | undefined> {
|
|
1154
|
+
if (!isRemoteEndpoint(endpoint)) return undefined;
|
|
1155
|
+
const httpBase = httpBaseUrlFor(endpoint);
|
|
1156
|
+
if (!httpBase) return undefined;
|
|
1157
|
+
const minted = await mintBridgeTicket({ httpBase, token: readDeviceToken() });
|
|
1158
|
+
if (!minted.ok) {
|
|
1159
|
+
console.error(`[dashboard] bridge ticket ${minted.cause}: ${minted.reason}`);
|
|
1160
|
+
throw new Error(minted.reason);
|
|
1161
|
+
}
|
|
1162
|
+
return { url: withTicket(endpoint, minted.ticket) };
|
|
1163
|
+
}
|
|
712
1164
|
|
|
713
1165
|
// Long-lived ctx wrapper for the Extension UI System (Phase 1) — see
|
|
714
1166
|
// change: add-extension-ui-modal. `getSessionId` reads the closed-over
|
|
@@ -720,11 +1172,154 @@ function initBridge(pi: ExtensionAPI) {
|
|
|
720
1172
|
getSessionId: () => sessionId,
|
|
721
1173
|
};
|
|
722
1174
|
|
|
723
|
-
const
|
|
1175
|
+
// `let`, not `const`: a completed move REBINDS this to the target's
|
|
1176
|
+
// connection, and every closure in this module captured the BINDING rather
|
|
1177
|
+
// than the value, so all ~100 `connection.send(...)` sites follow the session
|
|
1178
|
+
// to its new dashboard without being rewritten (task 9.4).
|
|
1179
|
+
// biome-ignore lint/style/useConst: reassigned by the move command below.
|
|
1180
|
+
// Private plugin request/reply lane (bridge half). The global symbol is
|
|
1181
|
+
// installed only while the socket is open; a close fails pending calls
|
|
1182
|
+
// `disconnected`. See change: expose-plugin-credential-and-oauth-seams (D7).
|
|
1183
|
+
// Non-buffering send: a request must never be replayed after a reconnect.
|
|
1184
|
+
const pluginRequests = createPluginRequestClient({ send: (m) => connection.sendIfOpen(m) });
|
|
1185
|
+
let uninstallPluginRequest: (() => void) | null = null;
|
|
1186
|
+
const pluginLaneUp = (): void => {
|
|
1187
|
+
uninstallPluginRequest?.();
|
|
1188
|
+
uninstallPluginRequest = installPluginRequest(pluginRequests.request);
|
|
1189
|
+
};
|
|
1190
|
+
const pluginLaneDown = (): void => {
|
|
1191
|
+
uninstallPluginRequest?.();
|
|
1192
|
+
uninstallPluginRequest = null;
|
|
1193
|
+
pluginRequests.failAll("disconnected");
|
|
1194
|
+
};
|
|
1195
|
+
|
|
1196
|
+
// Agent path gate: asks the operator before read/write/edit leave the session's
|
|
1197
|
+
// roots. Created before the connection so the close handler can reset it.
|
|
1198
|
+
// See change: ask-agent-file-access-in-chat.
|
|
1199
|
+
const pathGate = createPathGate({
|
|
1200
|
+
suppression: (getBridgeState().pathGateSuppression ??= new Suppression()),
|
|
1201
|
+
getSessionId: () => sessionId,
|
|
1202
|
+
getPromptBus: () => promptBus,
|
|
1203
|
+
send: (m) => connection.sendIfOpen(m),
|
|
1204
|
+
readConfig: () => loadConfig().agentPathGate,
|
|
1205
|
+
getCwd: () => cachedCwd ?? process.cwd(),
|
|
1206
|
+
getSessionDir: () => {
|
|
1207
|
+
try {
|
|
1208
|
+
return cachedCtx?.sessionManager?.getSessionDir?.();
|
|
1209
|
+
} catch {
|
|
1210
|
+
return undefined;
|
|
1211
|
+
}
|
|
1212
|
+
},
|
|
1213
|
+
log: (line) => console.log(line),
|
|
1214
|
+
notify: (message) => {
|
|
1215
|
+
try {
|
|
1216
|
+
cachedCtx?.ui?.notify?.(message, "warning");
|
|
1217
|
+
} catch {
|
|
1218
|
+
/* best effort */
|
|
1219
|
+
}
|
|
1220
|
+
},
|
|
1221
|
+
});
|
|
1222
|
+
|
|
1223
|
+
let connection = new ConnectionManager({
|
|
724
1224
|
url: dashboardUrl,
|
|
1225
|
+
// fix-bridge-mdns-migration-hijack (D5): every migration decision —
|
|
1226
|
+
// accepted or refused, including a reversibility fallback — is reported
|
|
1227
|
+
// through this single chokepoint. `console.log` serves capture-enabled
|
|
1228
|
+
// runs; `bridge_diagnostic` serves the default, where pi's stdout is
|
|
1229
|
+
// discarded and server.log is the only durable record. A re-target
|
|
1230
|
+
// cannot occur without a corresponding record.
|
|
1231
|
+
onMigrationEvent: (r) => {
|
|
1232
|
+
const detail = `${r.from} -> ${r.to} (${r.trigger}): ${r.accepted ? "accepted" : "refused"} — ${r.reason}`;
|
|
1233
|
+
console.log(`[dashboard] bridge migration ${detail}`);
|
|
1234
|
+
transportDiagnostics.record({
|
|
1235
|
+
event: r.accepted ? "retarget_accepted" : "retarget_refused",
|
|
1236
|
+
detail,
|
|
1237
|
+
});
|
|
1238
|
+
},
|
|
1239
|
+
// D6 (task 5.3): a LOOPBACK TCP dial carries this HOME's local token, the
|
|
1240
|
+
// credential that replaces the socket's file mode where there is no socket
|
|
1241
|
+
// (Windows, or a sun_path fallback). Undefined over a socket and never
|
|
1242
|
+
// sent to a remote endpoint.
|
|
1243
|
+
headers: localTokenHeaders(dashboardUrl),
|
|
1244
|
+
// Every accepted re-target (and every reversal) re-derives these from the
|
|
1245
|
+
// endpoint actually being dialled — a loopback token must never ride a
|
|
1246
|
+
// dial to a discovered remote host, and a remote candidate needs its own
|
|
1247
|
+
// bridge ticket. (CodeRabbit review, fix-bridge-mdns-migration-hijack.)
|
|
1248
|
+
credentialsFor: (u) => ({
|
|
1249
|
+
headers: localTokenHeaders(u),
|
|
1250
|
+
prepare: () => prepareRemoteUpgrade(u),
|
|
1251
|
+
}),
|
|
1252
|
+
// A REMOTE endpoint needs a bridge ticket per attempt (§6 made TCP bridge
|
|
1253
|
+
// auth mandatory). Local dials — unix socket or loopback — are authorised
|
|
1254
|
+
// by file mode or the local token and mint nothing.
|
|
1255
|
+
// See change: add-pi-gateway-transport-identity (D10b).
|
|
1256
|
+
prepareConnect: () => prepareRemoteUpgrade(dashboardUrl),
|
|
1257
|
+
// Attribute every force-close. `record` flushes through the live socket
|
|
1258
|
+
// when one is still OPEN (the callback runs BEFORE teardown) and falls
|
|
1259
|
+
// back to the buffer otherwise, so the report survives either way.
|
|
1260
|
+
onWatchdogFire: (w) => {
|
|
1261
|
+
const detail = formatWatchdogFire(w);
|
|
1262
|
+
console.log(`[dashboard] watchdog force-close ${detail}`);
|
|
1263
|
+
transportDiagnostics.record({ event: "watchdog_force_close", detail });
|
|
1264
|
+
},
|
|
1265
|
+
// Routing field for a drop report — the reporting bridge's OWN session,
|
|
1266
|
+
// never the id the dropped message named.
|
|
1267
|
+
// See change: fix-spawn-correlation-ttl-coupling (D6).
|
|
1268
|
+
getSessionId: () => sessionId,
|
|
1269
|
+
// Lane lifecycle follows the CURRENT connection only: after a
|
|
1270
|
+
// `/dashboard-connect` move, `connection` is rebound to the target.
|
|
1271
|
+
onOpen: () => {
|
|
1272
|
+
if (!isActive() || connection !== primaryConnection) return;
|
|
1273
|
+
pluginLaneUp();
|
|
1274
|
+
},
|
|
1275
|
+
onClose: () => {
|
|
1276
|
+
if (connection !== primaryConnection) return;
|
|
1277
|
+
pluginLaneDown();
|
|
1278
|
+
pathGate.reset();
|
|
1279
|
+
},
|
|
725
1280
|
onMessage: safe(async (data: unknown) => {
|
|
726
1281
|
if (!isActive()) return; // Stale listener guard
|
|
727
1282
|
const msg = data as ServerToExtensionMessage;
|
|
1283
|
+
// D12: the dashboard asking for a slice of THIS session's transcript.
|
|
1284
|
+
// Guarded before any filesystem touch — a request naming a path, or
|
|
1285
|
+
// another session, never reaches the reader. See change:
|
|
1286
|
+
// add-pi-gateway-transport-identity (tasks 11.3/11.4/11.6).
|
|
1287
|
+
if ((msg as any).type === "transcript_request") {
|
|
1288
|
+
const req = msg as unknown as TranscriptRequestMessage;
|
|
1289
|
+
const verdict = decideTranscriptRequest({
|
|
1290
|
+
request: req as never,
|
|
1291
|
+
ownSessionId: sessionId,
|
|
1292
|
+
});
|
|
1293
|
+
if (!verdict.allow) {
|
|
1294
|
+
console.warn(`[dashboard] transcript request refused: ${verdict.reason}`);
|
|
1295
|
+
connection.send({
|
|
1296
|
+
type: "transcript_chunk",
|
|
1297
|
+
// Echo the caller's id: routing is the connection, and the server
|
|
1298
|
+
// must be able to correlate a refusal with what it asked for.
|
|
1299
|
+
sessionId: req.sessionId,
|
|
1300
|
+
entries: [],
|
|
1301
|
+
complete: false,
|
|
1302
|
+
restarted: false,
|
|
1303
|
+
refused: { cause: verdict.cause, reason: verdict.reason },
|
|
1304
|
+
});
|
|
1305
|
+
return;
|
|
1306
|
+
}
|
|
1307
|
+
if (!lastSessionFile) return;
|
|
1308
|
+
const chunk = readTranscriptChunk(
|
|
1309
|
+
lastSessionFile,
|
|
1310
|
+
req.cursor as TranscriptCursor | undefined,
|
|
1311
|
+
{ maxBytes: req.maxBytes },
|
|
1312
|
+
);
|
|
1313
|
+
connection.send({
|
|
1314
|
+
type: "transcript_chunk",
|
|
1315
|
+
sessionId: req.sessionId,
|
|
1316
|
+
entries: chunk.entries,
|
|
1317
|
+
cursor: chunk.cursor,
|
|
1318
|
+
complete: chunk.complete,
|
|
1319
|
+
restarted: chunk.restarted,
|
|
1320
|
+
});
|
|
1321
|
+
return;
|
|
1322
|
+
}
|
|
728
1323
|
// Extension UI System (Phase 1): browser-originated action / data
|
|
729
1324
|
// request. Re-emit on pi.events; the listener either populates
|
|
730
1325
|
// data.items synchronously or calls _reply asynchronously.
|
|
@@ -748,6 +1343,21 @@ function initBridge(pi: ExtensionAPI) {
|
|
|
748
1343
|
return;
|
|
749
1344
|
}
|
|
750
1345
|
// Legacy extension_ui_response removed — now handled by prompt_response → promptBus.respond()
|
|
1346
|
+
if (msg.type === "plugin_reply") {
|
|
1347
|
+
// Resolves the caller's Promise only — never re-emitted on pi.events.
|
|
1348
|
+
pluginRequests.handleReply(msg);
|
|
1349
|
+
return;
|
|
1350
|
+
}
|
|
1351
|
+
// Agent path gate: grant-store identity + grant results (never re-emitted).
|
|
1352
|
+
if (pathGate.onServerMessage(msg as { type?: string })) return;
|
|
1353
|
+
if (msg.type === "mcp_token_minted") {
|
|
1354
|
+
// The minted MCP bearer (+ /mcp url) arrives on the session-private
|
|
1355
|
+
// lane and is registered with pi's built-in MCP — never placed in
|
|
1356
|
+
// process.env, a log line, or pi.events.
|
|
1357
|
+
// See change: migrate-mcp-to-pi-builtin (D1).
|
|
1358
|
+
mcpRegistrar.onMinted(msg as McpTokenMintedPayload);
|
|
1359
|
+
return;
|
|
1360
|
+
}
|
|
751
1361
|
// Reload auth credentials when dashboard notifies of changes
|
|
752
1362
|
if (msg.type === "credentials_updated") {
|
|
753
1363
|
try {
|
|
@@ -763,7 +1373,21 @@ function initBridge(pi: ExtensionAPI) {
|
|
|
763
1373
|
);
|
|
764
1374
|
}
|
|
765
1375
|
cachedModelRegistry?.authStorage?.reload?.();
|
|
766
|
-
|
|
1376
|
+
// pi 0.84.0: refresh() takes ModelsRefreshOptions and returns
|
|
1377
|
+
// { aborted, errors }. Await + inspect it so getAvailable() below
|
|
1378
|
+
// sees the refreshed catalogue and a per-provider failure is
|
|
1379
|
+
// reported rather than silently dropped. Scope the refresh to the
|
|
1380
|
+
// providers this reload actually touched -- an unrelated provider's
|
|
1381
|
+
// catalogue has no reason to be re-fetched because one credential
|
|
1382
|
+
// changed. Empty scope (removals only) => refresh nothing.
|
|
1383
|
+
// See change: update-pi-core-0-84-adopt-apis.
|
|
1384
|
+
const touched = [...new Set([...diff.added, ...diff.changed])];
|
|
1385
|
+
if (touched.length > 0) {
|
|
1386
|
+
await reportRefresh(
|
|
1387
|
+
cachedModelRegistry?.refresh?.({ providers: touched }),
|
|
1388
|
+
`credentials reload refresh (${touched.join(", ")})`,
|
|
1389
|
+
);
|
|
1390
|
+
}
|
|
767
1391
|
} catch (err) { console.error("[dashboard] credentials reload failed:", err); }
|
|
768
1392
|
// Push updated models list to dashboard client
|
|
769
1393
|
if (cachedModelRegistry && sessionReady) {
|
|
@@ -784,6 +1408,22 @@ function initBridge(pi: ExtensionAPI) {
|
|
|
784
1408
|
}
|
|
785
1409
|
return;
|
|
786
1410
|
}
|
|
1411
|
+
// Persisted stop state pushed at register, so a permanent stop survives a
|
|
1412
|
+
// PROCESS restart. Only the STOP fields are adopted. `nameSource`,
|
|
1413
|
+
// `lastSelfApplied` and `hasAutoName` are deliberately NOT restored:
|
|
1414
|
+
// reinstating them would change the behaviour of the separate auto→`user`
|
|
1415
|
+
// relabel bug, which has a different root cause and is tracked on its own
|
|
1416
|
+
// (design D8b, change: investigate-auto-name-provenance-relabel). They are
|
|
1417
|
+
// still carried across an in-process RELOAD via `prev.namerState`.
|
|
1418
|
+
// See change: fix-auto-naming-reasoning-model (design D7).
|
|
1419
|
+
if (msg.type === "auto_name_state_restore") {
|
|
1420
|
+
const adopted = adoptRestoredNamerState((msg as any).state);
|
|
1421
|
+
if (adopted && !autoNamer) {
|
|
1422
|
+
namerState = adopted;
|
|
1423
|
+
prev.namerState = adopted;
|
|
1424
|
+
}
|
|
1425
|
+
return;
|
|
1426
|
+
}
|
|
787
1427
|
// Graceful stop-after-turn: latch a per-session flag; the next turn_end
|
|
788
1428
|
// shuts the session down cleanly. Idempotent. See change:
|
|
789
1429
|
// adopt-pi-071-072-073-features.
|
|
@@ -791,6 +1431,10 @@ function initBridge(pi: ExtensionAPI) {
|
|
|
791
1431
|
getBridgeState().shouldStopAfterTurn = true;
|
|
792
1432
|
return;
|
|
793
1433
|
}
|
|
1434
|
+
// Forced PR-status probe after a worktree Push / Open PR. The server
|
|
1435
|
+
// only targets bridges whose cwd is inside the worktree. See change:
|
|
1436
|
+
// redesign-composer-session-strip (D5).
|
|
1437
|
+
if (routeGitInfoRefresh(msg, { prStatus, gitTracker: polling.gitTracker })) return;
|
|
794
1438
|
// Route flow management actions from dashboard buttons
|
|
795
1439
|
if (msg.type === "flow_management" && pi.events) {
|
|
796
1440
|
if (msg.action === "run") {
|
|
@@ -951,17 +1595,40 @@ function initBridge(pi: ExtensionAPI) {
|
|
|
951
1595
|
// agentSessionId (from a deep-link route); resync() resolves both.
|
|
952
1596
|
// See change: resolve-subagent-inspector-by-session-id (D3/D4).
|
|
953
1597
|
const requestedId = (msg as { agentId?: unknown }).agentId;
|
|
954
|
-
if (typeof requestedId === "string" && requestedId.length > 0
|
|
955
|
-
|
|
956
|
-
|
|
957
|
-
|
|
958
|
-
|
|
959
|
-
|
|
960
|
-
|
|
961
|
-
|
|
962
|
-
|
|
963
|
-
|
|
964
|
-
|
|
1598
|
+
if (typeof requestedId === "string" && requestedId.length > 0) {
|
|
1599
|
+
// The reply is NEVER stripped: it IS the pull model's answer and
|
|
1600
|
+
// carries the full timeline for a RUNNING agent — exactly the shape a
|
|
1601
|
+
// strip inside `sendEventForward` would have destroyed.
|
|
1602
|
+
// See change: reduce-subagent-details-payload (X6).
|
|
1603
|
+
const echoId = (msg as { requestId?: unknown }).requestId;
|
|
1604
|
+
const resolvedAgentId = serveSubagentResync(
|
|
1605
|
+
subagentFrameBuffer,
|
|
1606
|
+
requestedId,
|
|
1607
|
+
sendEventForward,
|
|
1608
|
+
() => sessionReady && isActive(),
|
|
1609
|
+
typeof echoId === "string" && echoId.length > 0 ? echoId : undefined,
|
|
1610
|
+
(msg as { reason?: "open" | "cadence" }).reason,
|
|
1611
|
+
);
|
|
1612
|
+
console.log(
|
|
1613
|
+
resolvedAgentId
|
|
1614
|
+
? `[dashboard] served subagent resync for id=${requestedId} (resolved agentId=${resolvedAgentId})`
|
|
1615
|
+
: `[dashboard] subagent resync no-op (unknown/finished/not-ready) id=${requestedId}`,
|
|
1616
|
+
);
|
|
1617
|
+
}
|
|
1618
|
+
return;
|
|
1619
|
+
}
|
|
1620
|
+
// Prompt resync (fix B, extension half): a browser asked the bridge to
|
|
1621
|
+
// re-emit every prompt it is still awaiting an answer for — the bus's
|
|
1622
|
+
// pending set is the source of truth, NOT the server's derived registry
|
|
1623
|
+
// (D6). Each frame echoes the requester token so the server unicasts it
|
|
1624
|
+
// back to the asking browser as a critical frame. Empty pending set →
|
|
1625
|
+
// zero frames, no error (E10); a malformed token degrades to tokenless.
|
|
1626
|
+
// See change: fix-pending-prompt-lost-on-replay (design D5/D6/D7).
|
|
1627
|
+
if (msg.type === "prompt_resync_request") {
|
|
1628
|
+
const echoId = (msg as { requestId?: unknown }).requestId;
|
|
1629
|
+
const token = typeof echoId === "string" && echoId.length > 0 ? echoId : undefined;
|
|
1630
|
+
if (promptBus) {
|
|
1631
|
+
emitPendingPrompts(promptBus, (m) => connection.send(m as any), sessionId, token);
|
|
965
1632
|
}
|
|
966
1633
|
return;
|
|
967
1634
|
}
|
|
@@ -980,7 +1647,7 @@ function initBridge(pi: ExtensionAPI) {
|
|
|
980
1647
|
}
|
|
981
1648
|
// ── Follow-up queue mutation (bridge-owned buffer) ─────────────────
|
|
982
1649
|
//
|
|
983
|
-
// These
|
|
1650
|
+
// These four handlers mutate `bridgeFollowUp` only. NONE of them
|
|
984
1651
|
// call pi.sendUserMessage, pi.clear*Queue, or any other pi method.
|
|
985
1652
|
// The bridge owns the buffer; pi never sees these entries until the
|
|
986
1653
|
// drain loop ships them on agent_end as fresh-turn sendUserMessage.
|
|
@@ -994,66 +1661,37 @@ function initBridge(pi: ExtensionAPI) {
|
|
|
994
1661
|
// See change: rework-mid-turn-prompt-queue (design.md D3).
|
|
995
1662
|
if (msg.type === "edit_followup_entry") {
|
|
996
1663
|
const { index, text } = msg as { type: string; index: number; text: string };
|
|
997
|
-
|
|
998
|
-
|
|
999
|
-
|
|
1000
|
-
|
|
1001
|
-
|
|
1002
|
-
|
|
1003
|
-
|
|
1004
|
-
});
|
|
1664
|
+
// Text-only edit: the entry's images are PRESERVED (design D5). Gated
|
|
1665
|
+
// on the byte ceiling because the inline editor can grow text without
|
|
1666
|
+
// bound; a refused edit leaves the entry untouched and emits no
|
|
1667
|
+
// `queue_update`. See change: fix-bridge-followup-image-drop.
|
|
1668
|
+
const edited = bridgeFollowUp.editText(index, text);
|
|
1669
|
+
if (!edited.ok) {
|
|
1670
|
+
sendCommandFeedback("edit_followup_entry", edited.message);
|
|
1005
1671
|
return;
|
|
1006
1672
|
}
|
|
1007
|
-
bridgeFollowUp[index] = text;
|
|
1008
1673
|
emitQueueUpdate();
|
|
1009
1674
|
return;
|
|
1010
1675
|
}
|
|
1011
1676
|
if (msg.type === "remove_followup_entry") {
|
|
1012
1677
|
const { index } = msg as { type: string; index: number };
|
|
1013
|
-
if (
|
|
1014
|
-
|
|
1015
|
-
type: "event_forward",
|
|
1016
|
-
sessionId,
|
|
1017
|
-
event: { eventType: "command_feedback", timestamp: Date.now(), data: {
|
|
1018
|
-
command: "remove_followup_entry", status: "error", message: "Index out of range",
|
|
1019
|
-
} },
|
|
1020
|
-
});
|
|
1678
|
+
if (!bridgeFollowUp.removeAt(index)) {
|
|
1679
|
+
sendCommandFeedback("remove_followup_entry", "Index out of range");
|
|
1021
1680
|
return;
|
|
1022
1681
|
}
|
|
1023
|
-
bridgeFollowUp.splice(index, 1);
|
|
1024
1682
|
emitQueueUpdate();
|
|
1025
1683
|
return;
|
|
1026
1684
|
}
|
|
1027
1685
|
if (msg.type === "promote_followup_entry") {
|
|
1028
1686
|
const { index } = msg as { type: string; index: number };
|
|
1029
|
-
// Silent no-op for index 0 or invalid — no emit (D3).
|
|
1030
|
-
if (
|
|
1031
|
-
return;
|
|
1032
|
-
}
|
|
1033
|
-
const [entry] = bridgeFollowUp.splice(index, 1);
|
|
1034
|
-
bridgeFollowUp.unshift(entry);
|
|
1035
|
-
emitQueueUpdate();
|
|
1687
|
+
// Silent no-op for index 0 or invalid — no emit (D3). Carries images.
|
|
1688
|
+
if (bridgeFollowUp.promote(index)) emitQueueUpdate();
|
|
1036
1689
|
return;
|
|
1037
1690
|
}
|
|
1038
1691
|
if (msg.type === "clear_followup_entries") {
|
|
1039
1692
|
const { indices } = msg as { type: string; indices: number[] | "all" };
|
|
1040
|
-
|
|
1041
|
-
|
|
1042
|
-
bridgeFollowUp = [];
|
|
1043
|
-
emitQueueUpdate();
|
|
1044
|
-
}
|
|
1045
|
-
return;
|
|
1046
|
-
}
|
|
1047
|
-
if (!Array.isArray(indices)) return;
|
|
1048
|
-
// Sort descending to avoid index drift across multiple splices.
|
|
1049
|
-
const sorted = [...indices].sort((a, b) => b - a);
|
|
1050
|
-
let mutated = false;
|
|
1051
|
-
for (const i of sorted) {
|
|
1052
|
-
if (typeof i === "number" && i >= 0 && i < bridgeFollowUp.length) {
|
|
1053
|
-
bridgeFollowUp.splice(i, 1);
|
|
1054
|
-
mutated = true;
|
|
1055
|
-
}
|
|
1056
|
-
}
|
|
1693
|
+
const mutated =
|
|
1694
|
+
indices === "all" ? bridgeFollowUp.clearAll() : bridgeFollowUp.clearIndices(indices);
|
|
1057
1695
|
if (mutated) emitQueueUpdate();
|
|
1058
1696
|
return;
|
|
1059
1697
|
}
|
|
@@ -1067,19 +1705,30 @@ function initBridge(pi: ExtensionAPI) {
|
|
|
1067
1705
|
}),
|
|
1068
1706
|
onReconnect: safe(() => {
|
|
1069
1707
|
if (!isActive()) return; // Stale listener guard
|
|
1708
|
+
// A reconnect is a TRANSPORT boundary, not a session boundary: the live
|
|
1709
|
+
// content is still valid (dropping it would lose the tail of an in-flight
|
|
1710
|
+
// turn) but must never land after the replay below. Flush it first.
|
|
1711
|
+
// See change: coalesce-bridge-message-update-snapshots (D8).
|
|
1712
|
+
coalescer.flush();
|
|
1070
1713
|
// Reset caches that aren't persisted server-side so the upcoming
|
|
1071
1714
|
// 30s tick (and the inline calls below) re-emit the live state.
|
|
1072
1715
|
const _bc = syncBc();
|
|
1073
1716
|
_resetReconnectCaches(_bc);
|
|
1074
1717
|
applyBc(_bc);
|
|
1075
1718
|
sendStateSync();
|
|
1719
|
+
// The server does not persist `piVersion` / `piBelowFloor`; re-send now
|
|
1720
|
+
// rather than on the next poll tick. See change: update-pi-core-1-0-adopt-apis.
|
|
1721
|
+
sendPiVersionIfChanged();
|
|
1076
1722
|
// Force-emit git state for the active session’s cwd. The bridge
|
|
1077
1723
|
// doesn't have direct ctx here, so we walk the active session.
|
|
1078
1724
|
try {
|
|
1079
1725
|
const activeId = (pi as any).getCurrentSessionId?.();
|
|
1080
1726
|
const activeCtx = activeId ? (pi as any).getCtx?.(activeId) : (cachedCtx as any);
|
|
1081
1727
|
if (activeCtx?.cwd) {
|
|
1082
|
-
|
|
1728
|
+
// First evaluation again: the server lost its git state with the connection.
|
|
1729
|
+
const gbc = syncBc();
|
|
1730
|
+
polling.gitTracker?.evaluateFirst(gbc, activeCtx.cwd);
|
|
1731
|
+
applyBc(gbc);
|
|
1083
1732
|
sendCwdMissingIfChanged(activeCtx.cwd);
|
|
1084
1733
|
}
|
|
1085
1734
|
} catch { /* probe failure non-fatal */ }
|
|
@@ -1092,25 +1741,11 @@ function initBridge(pi: ExtensionAPI) {
|
|
|
1092
1741
|
flushPendingSubagentFrames();
|
|
1093
1742
|
// Re-send pending PromptBus requests so dashboard dialogs survive browser refresh.
|
|
1094
1743
|
// Synchronous within this tick to prevent TUI respond() from interleaving.
|
|
1095
|
-
// Client-side dedup by requestId prevents double-rendering.
|
|
1744
|
+
// Client-side dedup by requestId prevents double-rendering. Shared with the
|
|
1745
|
+
// prompt_resync_request handler so the two frames cannot drift (D7).
|
|
1746
|
+
// See change: fix-pending-prompt-lost-on-replay.
|
|
1096
1747
|
if (promptBus) {
|
|
1097
|
-
|
|
1098
|
-
connection.send({
|
|
1099
|
-
type: "prompt_request" as any,
|
|
1100
|
-
sessionId,
|
|
1101
|
-
promptId: request.id,
|
|
1102
|
-
prompt: {
|
|
1103
|
-
type: request.type,
|
|
1104
|
-
question: request.question,
|
|
1105
|
-
options: request.options,
|
|
1106
|
-
defaultValue: request.defaultValue,
|
|
1107
|
-
pipeline: request.pipeline,
|
|
1108
|
-
metadata: request.metadata,
|
|
1109
|
-
},
|
|
1110
|
-
component,
|
|
1111
|
-
placement,
|
|
1112
|
-
});
|
|
1113
|
-
}
|
|
1748
|
+
emitPendingPrompts(promptBus, (m) => connection.send(m as any), sessionId);
|
|
1114
1749
|
}
|
|
1115
1750
|
connection.send({ type: "replay_complete", sessionId });
|
|
1116
1751
|
// If agent is mid-turn, send synthetic agent_start so server sets status to "streaming"
|
|
@@ -1123,13 +1758,40 @@ function initBridge(pi: ExtensionAPI) {
|
|
|
1123
1758
|
// See change: add-extension-ui-modal.
|
|
1124
1759
|
refreshUiModules(uiModulesBridgeCtx);
|
|
1125
1760
|
}),
|
|
1761
|
+
// The idle half of the reconnect heal. The `agent_start` above re-asserts
|
|
1762
|
+
// `streaming` when mid-turn; without this branch a `streaming` latched by
|
|
1763
|
+
// an `agent_end` lost in the drop is never corrected.
|
|
1764
|
+
//
|
|
1765
|
+
// Spelled as a heartbeat, NOT a synthetic `agent_end`: that event carries
|
|
1766
|
+
// run-boundary side effects (unread stamping, card reordering, OpenSpec
|
|
1767
|
+
// proposal clearing) a correction must not fire (design D3).
|
|
1768
|
+
//
|
|
1769
|
+
// Sent from the POST-FLUSH hook so a real buffered `agent_end` is still
|
|
1770
|
+
// processed first and still stamps unread (design D8).
|
|
1771
|
+
//
|
|
1772
|
+
// See change: fix-stuck-streaming-status-latch.
|
|
1773
|
+
onPostFlush: safe(() => {
|
|
1774
|
+
if (!isActive()) return; // Stale listener guard
|
|
1775
|
+
if (getBridgeState().isAgentStreaming) return;
|
|
1776
|
+
connection.send({ type: "session_heartbeat", sessionId, agentRunning: false });
|
|
1777
|
+
}),
|
|
1126
1778
|
});
|
|
1779
|
+
// The lane's lifecycle hooks compare against this to ignore a moved-away origin.
|
|
1780
|
+
const primaryConnection = connection;
|
|
1127
1781
|
|
|
1128
1782
|
// Track connection so future bridge incarnations can disconnect it
|
|
1129
1783
|
getBridgeState().connections!.push(connection);
|
|
1130
1784
|
|
|
1785
|
+
// See change: fix-terminal-session-dashboard-reload.
|
|
1786
|
+
const terminalReload = createTerminalReload({ pi, getSessionId: () => sessionId });
|
|
1787
|
+
|
|
1131
1788
|
const commandHandler = createCommandHandler(pi, () => sessionId, {
|
|
1132
1789
|
getModelRegistry: () => cachedModelRegistry,
|
|
1790
|
+
// Surface a session-id-mismatch drop server-side; the guard's own
|
|
1791
|
+
// `console.error` goes to /dev/null under the default
|
|
1792
|
+
// `keeperLog.capturePiOutput:false`.
|
|
1793
|
+
// See change: fix-spawn-correlation-ttl-coupling (D6).
|
|
1794
|
+
reportInboundDrop: (drop) => connection.reportInboundDrop(drop),
|
|
1133
1795
|
// AI-draft fork-subagent wiring (see change:
|
|
1134
1796
|
// add-session-uncommitted-indicator-and-commit). Both degrade silently
|
|
1135
1797
|
// to the draft ladder's lower rungs when unavailable.
|
|
@@ -1186,17 +1848,12 @@ function initBridge(pi: ExtensionAPI) {
|
|
|
1186
1848
|
// turn. Cleared on the next user prompt (noteUserPrompt) or terminal
|
|
1187
1849
|
// agent_end. See change: unify-error-retry-lifecycle.
|
|
1188
1850
|
abortLatch.request(sessionId);
|
|
1851
|
+
// Install retry cancellation BEFORE invoking pi: abort() can dispatch
|
|
1852
|
+
// terminal events synchronously, and those belong to the cancelled chain.
|
|
1853
|
+
retryTracker.noteAbort(sessionId);
|
|
1189
1854
|
if (cachedCtx?.abort) {
|
|
1190
1855
|
cachedCtx.abort();
|
|
1191
1856
|
}
|
|
1192
|
-
// Clear retry attempt counter so a subsequent agent_end does not
|
|
1193
|
-
// double-emit auto_retry_end{success:true}. See change:
|
|
1194
|
-
// fix-provider-retry-infinite-loop.
|
|
1195
|
-
retryTracker.noteAbort(sessionId);
|
|
1196
|
-
// pi's eventual terminal agent_end still surfaces the real provider
|
|
1197
|
-
// errorMessage through the reducer's own agent_end error path; the
|
|
1198
|
-
// observe-based tracker only synthesizes retry lifecycle events, never
|
|
1199
|
-
// the settled error. See change: simplify-error-retry-single-card.
|
|
1200
1857
|
},
|
|
1201
1858
|
/**
|
|
1202
1859
|
* Raw cachedCtx.abort() only. Used by the persistent-abort scheduler
|
|
@@ -1221,20 +1878,17 @@ function initBridge(pi: ExtensionAPI) {
|
|
|
1221
1878
|
cachedCtx.compact(opts);
|
|
1222
1879
|
}
|
|
1223
1880
|
},
|
|
1224
|
-
|
|
1225
|
-
|
|
1226
|
-
|
|
1227
|
-
|
|
1228
|
-
|
|
1229
|
-
|
|
1230
|
-
|
|
1231
|
-
console.error("[dashboard] reload not available — type /__dashboard_reload in pi TUI once to bootstrap");
|
|
1232
|
-
}
|
|
1233
|
-
},
|
|
1881
|
+
// Terminal-hosted path only. Dashboard-spawned headless sessions are
|
|
1882
|
+
// reloaded by the SERVER via kill-and-respawn (`dispatchReload`).
|
|
1883
|
+
// Self-dispatches `/__dashboard_reload <token>` in-process (no pi version gate);
|
|
1884
|
+
// resolves `handedOff` on success, because the RELOADED instance reports
|
|
1885
|
+
// `completed` after re-registering. See `terminal-reload.ts`.
|
|
1886
|
+
// See change: fix-terminal-session-dashboard-reload (D1/D3/D4).
|
|
1887
|
+
reload: terminalReload.reload,
|
|
1234
1888
|
spawnNew: () => {
|
|
1235
1889
|
connection.send({ type: "spawn_new_session", sessionId, cwd: process.cwd() });
|
|
1236
1890
|
},
|
|
1237
|
-
sessionPrompt: async (text, delivery) => {
|
|
1891
|
+
sessionPrompt: async (text, delivery, promptId) => {
|
|
1238
1892
|
// Route slash commands: management events, flow:run, extension dispatch, then fallback.
|
|
1239
1893
|
// See change: fix-extension-slash-commands-in-dashboard.
|
|
1240
1894
|
if (text.startsWith("/") && pi.events) {
|
|
@@ -1256,15 +1910,15 @@ function initBridge(pi: ExtensionAPI) {
|
|
|
1256
1910
|
|
|
1257
1911
|
// Extension-command dispatch (routing step 9). When matched, the helper
|
|
1258
1912
|
// emits its own command_feedback events and we MUST NOT fall through.
|
|
1259
|
-
//
|
|
1260
|
-
//
|
|
1261
|
-
//
|
|
1913
|
+
// One in-process `sendUserMessage({expandPromptTemplates:true})` works in
|
|
1914
|
+
// every session shape; the old headless-only RPC path is retired.
|
|
1915
|
+
// See change: retire-slash-dispatch-via-expand-prompt-templates.
|
|
1262
1916
|
const handled = await tryDispatchExtensionCommand(
|
|
1263
1917
|
pi,
|
|
1264
1918
|
text,
|
|
1265
1919
|
sessionId,
|
|
1266
1920
|
(msg) => connection.send(msg),
|
|
1267
|
-
|
|
1921
|
+
delivery,
|
|
1268
1922
|
);
|
|
1269
1923
|
if (handled) {
|
|
1270
1924
|
// Non-turn dispatch route: settle optimistic idle bubble (no message_start
|
|
@@ -1309,9 +1963,20 @@ function initBridge(pi: ExtensionAPI) {
|
|
|
1309
1963
|
// flow / template path). Mirrors the passthrough emit in command-handler.
|
|
1310
1964
|
// fresh:true → optimistic bubble "sent"; fresh:false → drop (raced mid-turn).
|
|
1311
1965
|
// See change: optimistic-prompt-progress.
|
|
1312
|
-
|
|
1966
|
+
// `promptId` (when the server minted one) rides ONLY when this send
|
|
1967
|
+
// actually hands the prompt to pi: a follow-up racing a streaming turn is
|
|
1968
|
+
// buffered, and the non-turn routes above returned already.
|
|
1969
|
+
// See change: optimistic-prompt-progress,
|
|
1970
|
+
// fix-spawn-correlation-ttl-coupling (D7).
|
|
1971
|
+
const buffered = wasStreaming && deliverAs === "followUp";
|
|
1972
|
+
connection.send({
|
|
1973
|
+
type: "prompt_received",
|
|
1974
|
+
sessionId,
|
|
1975
|
+
fresh: !wasStreaming,
|
|
1976
|
+
...(promptId && !buffered ? { promptId } : {}),
|
|
1977
|
+
});
|
|
1313
1978
|
const expanded = expandPromptTemplateFromDisk(text, process.cwd(), pi);
|
|
1314
|
-
if (
|
|
1979
|
+
if (buffered) {
|
|
1315
1980
|
// Bridge-owned buffer path — do NOT call pi.sendUserMessage. The
|
|
1316
1981
|
// drain loop on agent_end will ship the entry as a fresh turn.
|
|
1317
1982
|
bufferFollowupSend(expanded);
|
|
@@ -1324,24 +1989,202 @@ function initBridge(pi: ExtensionAPI) {
|
|
|
1324
1989
|
onSteerSent: recordSteerSent,
|
|
1325
1990
|
onFollowupSent: bufferFollowupSend,
|
|
1326
1991
|
isStreaming: () => getBridgeState().isAgentStreaming === true,
|
|
1327
|
-
// Clear the abort latch
|
|
1328
|
-
//
|
|
1992
|
+
// Clear only the abort latch before prompt routing. A streaming follow-up
|
|
1993
|
+
// may be buffered rather than start a run, so retry cancellation is released
|
|
1994
|
+
// only by the observed user message_start below.
|
|
1329
1995
|
noteUserPrompt: () => abortLatch.clear(sessionId),
|
|
1996
|
+
// Disarm a still-armed provider-retry chain so a manual retry's native
|
|
1997
|
+
// agent_start is not converted into a synthetic auto_retry_start.
|
|
1998
|
+
// See change: replace-dashboard-retry-command-with-protocol-message.
|
|
1999
|
+
disarmRetryChain: () => retryTracker.noteExplicitRun(sessionId),
|
|
2000
|
+
});
|
|
2001
|
+
|
|
2002
|
+
// Reload support: only a command handler's ctx has `reload()`. The bridge
|
|
2003
|
+
// self-dispatches this command (dashboard reload, token arg); a human may
|
|
2004
|
+
// also type it in the TUI (no args, no dashboard feedback). Nothing callable
|
|
2005
|
+
// is cached — every dispatch gets a fresh command ctx.
|
|
2006
|
+
// See change: fix-terminal-session-dashboard-reload (D1/D3).
|
|
2007
|
+
pi.registerCommand(RELOAD_COMMAND_NAME, {
|
|
2008
|
+
handler: (args: string, ctx: any) => terminalReload.handleReloadCommand(args, ctx),
|
|
1330
2009
|
});
|
|
1331
2010
|
|
|
1332
|
-
|
|
1333
|
-
|
|
1334
|
-
|
|
1335
|
-
|
|
1336
|
-
|
|
1337
|
-
|
|
2011
|
+
/**
|
|
2012
|
+
* `/dashboard-connect <target>` — move this live session to another dashboard
|
|
2013
|
+
* (D11, task 9.4).
|
|
2014
|
+
*
|
|
2015
|
+
* The overlap is the point: the target proves it can serve BEFORE the origin
|
|
2016
|
+
* is released, so a failed move is a no-op rather than an outage. On success
|
|
2017
|
+
* the module-level `connection` binding is rebound, which is what carries
|
|
2018
|
+
* every existing send site over to the new dashboard.
|
|
2019
|
+
*/
|
|
2020
|
+
pi.registerCommand("dashboard-connect", {
|
|
2021
|
+
handler: async (args: string) => {
|
|
2022
|
+
const { parseConnectTarget, describeConnectTarget, resolveConnectTarget } = await import(
|
|
2023
|
+
"./connect-target.js"
|
|
2024
|
+
);
|
|
2025
|
+
const { listLocalInstances } = await import(
|
|
2026
|
+
"@blackbelt-technology/pi-dashboard-shared/instance-directory.js"
|
|
2027
|
+
);
|
|
2028
|
+
const { createMoveCoordinator } = await import("./session-move.js");
|
|
2029
|
+
const { rendezvousEndpoint } = await import(
|
|
2030
|
+
"@blackbelt-technology/pi-dashboard-shared/rendezvous.js"
|
|
2031
|
+
);
|
|
2032
|
+
|
|
2033
|
+
const parsed = parseConnectTarget(args ?? "");
|
|
2034
|
+
const resolved = resolveConnectTarget(parsed, {
|
|
2035
|
+
defaultEndpoint: () => rendezvousEndpoint()?.endpoint ?? null,
|
|
2036
|
+
instances: () => listLocalInstances(),
|
|
2037
|
+
});
|
|
2038
|
+
if (!resolved.ok) {
|
|
2039
|
+
console.error(`[dashboard] connect refused: ${resolved.reason}`);
|
|
2040
|
+
return;
|
|
2041
|
+
}
|
|
2042
|
+
if (resolved.endpoint === dashboardUrl) {
|
|
2043
|
+
console.error(`[dashboard] already on ${describeConnectTarget(parsed)}`);
|
|
2044
|
+
return;
|
|
2045
|
+
}
|
|
2046
|
+
|
|
2047
|
+
// The target's identity must be known BEFORE the move: the coordinator
|
|
2048
|
+
// refuses a target whose instance id is not the expected one, and
|
|
2049
|
+
// "whatever answers" is not an expectation (D14).
|
|
2050
|
+
const expectInstanceId =
|
|
2051
|
+
resolved.instanceId ??
|
|
2052
|
+
listLocalInstances().find((i) => i.endpoint === resolved.endpoint)?.instanceId;
|
|
2053
|
+
if (!expectInstanceId) {
|
|
2054
|
+
console.error(
|
|
2055
|
+
`[dashboard] connect refused: cannot determine the instance id of ${describeConnectTarget(parsed)} — refusing to move to an unverified dashboard`,
|
|
2056
|
+
);
|
|
2057
|
+
return;
|
|
2058
|
+
}
|
|
2059
|
+
|
|
2060
|
+
let targetManager: ConnectionManager | undefined;
|
|
2061
|
+
const coordinator = createMoveCoordinator({
|
|
2062
|
+
origin: {
|
|
2063
|
+
connect: () => connection.connect(),
|
|
2064
|
+
disconnect: () => connection.disconnect(),
|
|
2065
|
+
send: (m) => connection.send(m),
|
|
2066
|
+
get isConnected() {
|
|
2067
|
+
return connection.isConnected;
|
|
2068
|
+
},
|
|
2069
|
+
// The coordinator never subscribes to the origin; only the target
|
|
2070
|
+
// answers the handshake.
|
|
2071
|
+
onMessage: () => {},
|
|
2072
|
+
},
|
|
2073
|
+
sessionId,
|
|
2074
|
+
sessionFile: lastSessionFile,
|
|
2075
|
+
originEndpoint: dashboardUrl,
|
|
2076
|
+
connect: (url) => {
|
|
2077
|
+
let handler: (msg: unknown) => void = () => {};
|
|
2078
|
+
targetManager = new ConnectionManager({
|
|
2079
|
+
url,
|
|
2080
|
+
headers: localTokenHeaders(url),
|
|
2081
|
+
getSessionId: () => sessionId,
|
|
2082
|
+
onMessage: (data) => {
|
|
2083
|
+
// Plugin lane replies resolve the caller's Promise only.
|
|
2084
|
+
if ((data as { type?: unknown } | null)?.type === "plugin_reply") {
|
|
2085
|
+
pluginRequests.handleReply(data as { requestId?: unknown });
|
|
2086
|
+
return;
|
|
2087
|
+
}
|
|
2088
|
+
handler(data);
|
|
2089
|
+
},
|
|
2090
|
+
onClose: () => {
|
|
2091
|
+
if (connection === targetManager) pluginLaneDown();
|
|
2092
|
+
},
|
|
2093
|
+
// The move REBINDS `connection` to this manager, so without this
|
|
2094
|
+
// every post-move force-close would be silent again.
|
|
2095
|
+
onWatchdogFire: (w) => {
|
|
2096
|
+
const detail = formatWatchdogFire(w);
|
|
2097
|
+
console.log(`[dashboard] watchdog force-close (move target) ${detail}`);
|
|
2098
|
+
transportDiagnostics.record({ event: "watchdog_force_close", detail });
|
|
2099
|
+
},
|
|
2100
|
+
// On the FIRST open, not just reconnects: this is where the
|
|
2101
|
+
// provisional registration is announced, and a send before the
|
|
2102
|
+
// socket is live would be silently dropped.
|
|
2103
|
+
onOpen: () => {
|
|
2104
|
+
if (connection === targetManager) pluginLaneUp();
|
|
2105
|
+
targetManager?.send({
|
|
2106
|
+
type: "session_register",
|
|
2107
|
+
extensionIdentity: bridgeExtensionIdentity(),
|
|
2108
|
+
sessionId,
|
|
2109
|
+
cwd: process.cwd(),
|
|
2110
|
+
source: "tui",
|
|
2111
|
+
pid: process.pid,
|
|
2112
|
+
provisional: true,
|
|
2113
|
+
});
|
|
2114
|
+
},
|
|
2115
|
+
});
|
|
2116
|
+
const mgr = targetManager;
|
|
2117
|
+
return {
|
|
2118
|
+
connect: () => mgr.connect(),
|
|
2119
|
+
disconnect: () => mgr.disconnect(),
|
|
2120
|
+
send: (m) => mgr.send(m),
|
|
2121
|
+
get isConnected() {
|
|
2122
|
+
return mgr.isConnected;
|
|
2123
|
+
},
|
|
2124
|
+
onMessage: (h) => {
|
|
2125
|
+
handler = h;
|
|
2126
|
+
},
|
|
2127
|
+
};
|
|
2128
|
+
},
|
|
2129
|
+
});
|
|
2130
|
+
|
|
2131
|
+
const result = await coordinator.begin({
|
|
2132
|
+
targetUrl: resolved.endpoint,
|
|
2133
|
+
expectInstanceId,
|
|
2134
|
+
initiator: "/dashboard-connect",
|
|
2135
|
+
});
|
|
2136
|
+
|
|
2137
|
+
if (!result.ok) {
|
|
2138
|
+
console.error(
|
|
2139
|
+
`[dashboard] move to ${describeConnectTarget(parsed)} failed: ${result.cause} — still on ${dashboardUrl}`,
|
|
2140
|
+
);
|
|
2141
|
+
return;
|
|
2142
|
+
}
|
|
2143
|
+
|
|
2144
|
+
// Rebind: from here every `connection.send(...)` in this module reaches
|
|
2145
|
+
// the new dashboard.
|
|
2146
|
+
if (targetManager) connection = targetManager;
|
|
2147
|
+
// The origin's close already took the plugin lane down; bring it up on
|
|
2148
|
+
// the target now that it is the current connection.
|
|
2149
|
+
if (connection.isConnected) pluginLaneUp();
|
|
2150
|
+
dashboardUrl = resolved.endpoint;
|
|
2151
|
+
registeredInstanceId = expectInstanceId;
|
|
2152
|
+
console.error(`[dashboard] moved to ${describeConnectTarget(parsed)} (${expectInstanceId})`);
|
|
2153
|
+
},
|
|
2154
|
+
});
|
|
1338
2155
|
|
|
1339
|
-
|
|
1340
|
-
|
|
1341
|
-
|
|
1342
|
-
|
|
1343
|
-
|
|
2156
|
+
// `/dashboard-list` — every dashboard instance visible under this HOME
|
|
2157
|
+
// (task 9.6). This is the DISPLAY-only side of the D2 carve-out: it scans so
|
|
2158
|
+
// a human can choose, and never feeds automatic endpoint selection.
|
|
2159
|
+
pi.registerCommand("dashboard-list", {
|
|
2160
|
+
handler: async () => {
|
|
2161
|
+
const { listLocalInstances, formatInstanceLine } = await import(
|
|
2162
|
+
"@blackbelt-technology/pi-dashboard-shared/instance-directory.js"
|
|
2163
|
+
);
|
|
2164
|
+
const found = listLocalInstances();
|
|
2165
|
+
if (found.length === 0) {
|
|
2166
|
+
console.error("[dashboard] no dashboard instances found under this HOME");
|
|
2167
|
+
return;
|
|
1344
2168
|
}
|
|
2169
|
+
console.error(
|
|
2170
|
+
`[dashboard] instances (* = default for this HOME):\n${found.map(formatInstanceLine).join("\n")}`,
|
|
2171
|
+
);
|
|
2172
|
+
},
|
|
2173
|
+
});
|
|
2174
|
+
|
|
2175
|
+
// `/dashboard-where` — endpoint + identity + pinned, for the session that
|
|
2176
|
+
// cannot otherwise answer "which dashboard am I actually on?" (task 9.6).
|
|
2177
|
+
// Written with console.error because pi's stdout is discarded under the
|
|
2178
|
+
// default `capturePiOutput:false`.
|
|
2179
|
+
pi.registerCommand("dashboard-where", {
|
|
2180
|
+
handler: async () => {
|
|
2181
|
+
const lines = [
|
|
2182
|
+
`endpoint: ${dashboardUrl}`,
|
|
2183
|
+
`instance: ${registeredInstanceId ?? "unverified"}`,
|
|
2184
|
+
`pinned: ${endpointPinned ? "yes (explicit configuration)" : "no (resolved from the $HOME rendezvous record)"}`,
|
|
2185
|
+
`pr-probe: ${prStatus.invocations()} gh invocation(s) this bridge`,
|
|
2186
|
+
];
|
|
2187
|
+
console.error(`[dashboard] where:\n${lines.join("\n")}`);
|
|
1345
2188
|
},
|
|
1346
2189
|
});
|
|
1347
2190
|
|
|
@@ -1352,13 +2195,15 @@ function initBridge(pi: ExtensionAPI) {
|
|
|
1352
2195
|
cachedCtx, cachedModelRegistry, cachedHasUI,
|
|
1353
2196
|
lastModel, lastThinkingLevel,
|
|
1354
2197
|
lastSessionFile, lastSessionDir, lastFirstMessage,
|
|
1355
|
-
lastGitBranch,
|
|
2198
|
+
lastGitBranch, lastGitPrJson, lastSessionName,
|
|
1356
2199
|
lastGitWorktreeJson,
|
|
1357
2200
|
lastGitStatusJson,
|
|
1358
2201
|
lastCwdMissing,
|
|
1359
2202
|
hasRegisteredOnce,
|
|
1360
2203
|
dashboardSpawned,
|
|
1361
2204
|
selfSpawnedPgids,
|
|
2205
|
+
prStatus,
|
|
2206
|
+
gitTracker: polling.gitTracker ?? undefined,
|
|
1362
2207
|
};
|
|
1363
2208
|
}
|
|
1364
2209
|
/** Sync BridgeContext mutations back to local variables */
|
|
@@ -1374,7 +2219,7 @@ function initBridge(pi: ExtensionAPI) {
|
|
|
1374
2219
|
lastSessionDir = bc.lastSessionDir;
|
|
1375
2220
|
lastFirstMessage = bc.lastFirstMessage;
|
|
1376
2221
|
lastGitBranch = bc.lastGitBranch;
|
|
1377
|
-
|
|
2222
|
+
lastGitPrJson = bc.lastGitPrJson;
|
|
1378
2223
|
lastSessionName = bc.lastSessionName;
|
|
1379
2224
|
lastGitWorktreeJson = bc.lastGitWorktreeJson;
|
|
1380
2225
|
lastGitStatusJson = bc.lastGitStatusJson;
|
|
@@ -1383,14 +2228,29 @@ function initBridge(pi: ExtensionAPI) {
|
|
|
1383
2228
|
}
|
|
1384
2229
|
|
|
1385
2230
|
// Local wrappers that sync bc around extracted module calls
|
|
1386
|
-
function sendStateSync() { const bc = syncBc(); _sendStateSync(bc, getFlowsList); applyBc(bc); }
|
|
2231
|
+
function sendStateSync() { const bc = syncBc(); _sendStateSync(bc, getFlowsList); applyBc(bc); connection.noteRegistered(); }
|
|
1387
2232
|
function replaySessionEntries() { _replaySessionEntries(syncBc()); }
|
|
1388
2233
|
function sendModelUpdateIfChanged() { const bc = syncBc(); _sendModelUpdateIfChanged(bc); applyBc(bc); }
|
|
1389
2234
|
function sendSessionNameIfChanged() { const bc = syncBc(); _sendSessionNameIfChanged(bc); applyBc(bc); }
|
|
1390
2235
|
|
|
1391
2236
|
// ── add-auto-session-naming ──────────────────────────────────────────────
|
|
1392
|
-
//
|
|
2237
|
+
// Stream through pi's OWN `ctx.modelRegistry`, not a bare-imported pi-ai
|
|
2238
|
+
// module (design D6). `ModelRuntime.streamSimple` already performs the full
|
|
2239
|
+
// normalize → prepare → `provider.streamSimple` sequence with credentials pi
|
|
2240
|
+
// has already resolved, so this is shorter than adapting a module AND it
|
|
2241
|
+
// removes a compat surface instead of adding one.
|
|
2242
|
+
//
|
|
2243
|
+
// pi >= 0.85 exports no global `streamSimple` at all, so the old bare import
|
|
2244
|
+
// silently yielded `undefined` and auto-naming never ran. The module import
|
|
2245
|
+
// is kept only as a fallback for a pi older than `piCompatibility.minimum`.
|
|
2246
|
+
// NOT cached across calls when it resolves from the registry: the registry
|
|
2247
|
+
// is captured lazily, so caching a miss would pin auto-naming off for the
|
|
2248
|
+
// whole session. See change: adopt-piai-factory-api-registry.
|
|
1393
2249
|
async function loadStreamSimple(): Promise<StreamSimpleFn | undefined> {
|
|
2250
|
+
const registry: any = cachedModelRegistry;
|
|
2251
|
+
if (typeof registry?.streamSimple === "function") {
|
|
2252
|
+
return registry.streamSimple.bind(registry) as StreamSimpleFn;
|
|
2253
|
+
}
|
|
1394
2254
|
if (piAiStreamSimple !== undefined) return piAiStreamSimple ?? undefined;
|
|
1395
2255
|
try {
|
|
1396
2256
|
const mod: any = await import("@earendil-works/pi-ai");
|
|
@@ -1407,13 +2267,10 @@ function initBridge(pi: ExtensionAPI) {
|
|
|
1407
2267
|
if (autoNamer) return autoNamer;
|
|
1408
2268
|
autoNamer = createAutoNamer({
|
|
1409
2269
|
getAutoNameSessions: () => autoNameSessions,
|
|
1410
|
-
|
|
2270
|
+
resolveNamingModel,
|
|
1411
2271
|
getRegistry: () => cachedModelRegistry,
|
|
1412
2272
|
loadStreamSimple,
|
|
1413
|
-
getTranscript: () => (
|
|
1414
|
-
firstUserMsg: extractFirstMessage(cachedCtx),
|
|
1415
|
-
firstAssistantReply: extractFirstAssistantReply(cachedCtx),
|
|
1416
|
-
}),
|
|
2273
|
+
getTranscript: () => extractLatestTurnWindow(cachedCtx),
|
|
1417
2274
|
applyName: (title: string) => {
|
|
1418
2275
|
try { pi.setSessionName(title); } catch { /* ignore */ }
|
|
1419
2276
|
lastSessionName = title; // suppress the redundant plain name_update poll
|
|
@@ -1425,20 +2282,40 @@ function initBridge(pi: ExtensionAPI) {
|
|
|
1425
2282
|
emitError: (reason: string) => {
|
|
1426
2283
|
connection.send({ type: "auto_name_error", sessionId, reason });
|
|
1427
2284
|
},
|
|
1428
|
-
|
|
2285
|
+
reportOutcome: ({ outcome, reason, modelRef }) => {
|
|
2286
|
+
connection.send({
|
|
2287
|
+
type: "auto_name_outcome", sessionId, outcome, reason, modelRef, at: Date.now(),
|
|
2288
|
+
});
|
|
2289
|
+
},
|
|
2290
|
+
// Carried across reload AND persisted server-side into the session's
|
|
2291
|
+
// `.meta.json`, so "permanent" survives a process restart rather than
|
|
2292
|
+
// re-spending a full budget on every cold start (design D7).
|
|
2293
|
+
persistState: (state: PersistedNamerState) => {
|
|
2294
|
+
namerState = state;
|
|
2295
|
+
prev.namerState = state;
|
|
2296
|
+
connection.send({ type: "auto_name_state", sessionId, state });
|
|
2297
|
+
},
|
|
2298
|
+
}, namerState);
|
|
1429
2299
|
return autoNamer;
|
|
1430
2300
|
}
|
|
1431
2301
|
|
|
1432
2302
|
// Run one naming attempt after a terminal turn. Observing the current name
|
|
1433
2303
|
// first catches a pre-existing / in-pi rename (external → permanent "user"
|
|
1434
2304
|
// lockout) before attempting to auto-name.
|
|
2305
|
+
//
|
|
2306
|
+
// The toggle gates the OBSERVATION but not the attempt: `maybeName` checks it
|
|
2307
|
+
// internally so the `disabled` outcome is reportable at all (design D9),
|
|
2308
|
+
// while `onObservedName` stays gated exactly as before this change. Letting
|
|
2309
|
+
// it run with the feature OFF would newly latch `nameSource: "user"` (plus a
|
|
2310
|
+
// persisted update) on sessions the user never asked to auto-name, inflating
|
|
2311
|
+
// the very population the follow-up investigation has to measure.
|
|
2312
|
+
// See change: fix-auto-naming-reasoning-model.
|
|
1435
2313
|
function runAutoNameOnTurnEnd(): void {
|
|
1436
|
-
if (!autoNameSessions) return;
|
|
1437
2314
|
const namer = getAutoNamer();
|
|
1438
|
-
namer.onObservedName(pi.getSessionName() ?? "");
|
|
2315
|
+
if (autoNameSessions) namer.onObservedName(pi.getSessionName() ?? "");
|
|
1439
2316
|
void namer.maybeName();
|
|
1440
2317
|
}
|
|
1441
|
-
|
|
2318
|
+
|
|
1442
2319
|
function sendCwdMissingIfChanged(cwd: string) { const bc = syncBc(); _sendCwdMissingIfChanged(bc, cwd); applyBc(bc); }
|
|
1443
2320
|
function sendPiVersionIfChanged() { _sendPiVersionIfChanged(syncBc()); }
|
|
1444
2321
|
|
|
@@ -1474,6 +2351,20 @@ function initBridge(pi: ExtensionAPI) {
|
|
|
1474
2351
|
"session_before_compact",
|
|
1475
2352
|
"session_before_tree",
|
|
1476
2353
|
"session_tree",
|
|
2354
|
+
// pi >= 0.84.3. Clears the server-side `compacting` latch on the failure
|
|
2355
|
+
// path (see event-status-extraction.ts) — without it a failed or aborted
|
|
2356
|
+
// compaction blocks every later reload of the session.
|
|
2357
|
+
"session_compact_failed",
|
|
2358
|
+
// pi >= 0.84.4. Brackets a BLOCKING `ctx.ui` prompt so the dashboard can
|
|
2359
|
+
// tell "agent working" apart from "pi parked waiting on a user prompt".
|
|
2360
|
+
// The 0.85.1 lockstep floor guarantees both events; the subscription is
|
|
2361
|
+
// unconditional (no version gate, not merely inert below an old floor).
|
|
2362
|
+
"ui_prompt_start",
|
|
2363
|
+
"ui_prompt_end",
|
|
2364
|
+
// pi >= 0.87. Fires before final settlement; no status effect (the agent
|
|
2365
|
+
// may still continue). Forwarded without its `context` preview.
|
|
2366
|
+
// See change: update-pi-core-1-0-adopt-apis (D5).
|
|
2367
|
+
"agent_before_settle",
|
|
1477
2368
|
] as const;
|
|
1478
2369
|
// Excluded from subscription (not forwarded):
|
|
1479
2370
|
// - `context`: carries full message arrays (very large)
|
|
@@ -1481,6 +2372,8 @@ function initBridge(pi: ExtensionAPI) {
|
|
|
1481
2372
|
// - `session_start`: dedicated handler → session_register protocol message
|
|
1482
2373
|
// - session change (new/fork/resume): handled inside session_start via event.reason
|
|
1483
2374
|
// - `session_shutdown`: dedicated handler → disconnect/cleanup
|
|
2375
|
+
// - `cache_warming_decision`: dedicated observe-only handler → usage drain
|
|
2376
|
+
// (`usage_recorded`), never `event_forward`. See change: count-non-message-usage.
|
|
1484
2377
|
|
|
1485
2378
|
// Unified EventBus rename map for the emit intercept (flow + subagent events)
|
|
1486
2379
|
const EVENT_BUS_MAP: Record<string, string> = { ...FLOW_EVENT_MAP, ...SUBAGENT_EVENT_MAP };
|
|
@@ -1493,6 +2386,16 @@ function initBridge(pi: ExtensionAPI) {
|
|
|
1493
2386
|
cachedCtx = ctx;
|
|
1494
2387
|
// Don't send events before session_start has established the correct session ID
|
|
1495
2388
|
if (!sessionReady) return;
|
|
2389
|
+
// ── Flush choke point (D5) ──────────────────────────────────────────
|
|
2390
|
+
// The invariant is "no non-`message_update` event may reach the wire while
|
|
2391
|
+
// a text snapshot is parked". ONE statement here — before ANY branch, so
|
|
2392
|
+
// it covers every early return below, including ones added later. Do not
|
|
2393
|
+
// move it into a branch: a branch-scoped flush is exactly the bug this
|
|
2394
|
+
// change exists to prevent.
|
|
2395
|
+
// See change: coalesce-bridge-message-update-snapshots.
|
|
2396
|
+
if (flushesParkedText(eventType)) coalescer.flush();
|
|
2397
|
+
// Adaptive process-scan cadence hooks. See change: optimize-polling-hot-paths.
|
|
2398
|
+
feedPollingEvent(eventType, event, polling);
|
|
1496
2399
|
// Track agent streaming state (survives reconnect/reload)
|
|
1497
2400
|
if (eventType === "agent_start") {
|
|
1498
2401
|
getBridgeState().isAgentStreaming = true;
|
|
@@ -1503,26 +2406,45 @@ function initBridge(pi: ExtensionAPI) {
|
|
|
1503
2406
|
if (abortLatch.shouldAbort(sessionId)) {
|
|
1504
2407
|
try { cachedCtx?.abort?.(); } catch { /* idempotent */ }
|
|
1505
2408
|
}
|
|
2409
|
+
// Provider-retry synthesis: when this agent_start is the awaited retry
|
|
2410
|
+
// attempt (a chain is armed), emit auto_retry_start so the surface
|
|
2411
|
+
// flips waiting → in-flight. Deferred via setTimeout(0) so it lands on
|
|
2412
|
+
// the wire AFTER this agent_start (the reducer defensively clears
|
|
2413
|
+
// retryState on agent_start, so the synth must arrive next to re-set
|
|
2414
|
+
// it). See change: retry-forever-with-stop-control (design D4).
|
|
2415
|
+
const retryStart = retryTracker.observeAgentStart(sessionId);
|
|
2416
|
+
if (retryStart) {
|
|
2417
|
+
setTimeout(() => {
|
|
2418
|
+
if (retryTracker.isRetrying(sessionId)) {
|
|
2419
|
+
sendSyntheticRetryEvent(retryStart.eventType, retryStart.data);
|
|
2420
|
+
}
|
|
2421
|
+
}, 0);
|
|
2422
|
+
}
|
|
1506
2423
|
}
|
|
1507
2424
|
if (eventType === "agent_settled") {
|
|
1508
|
-
// Terminal settle (native pi
|
|
1509
|
-
//
|
|
1510
|
-
//
|
|
1511
|
-
//
|
|
2425
|
+
// Terminal settle (native pi, guaranteed at the 0.85.1 lockstep floor;
|
|
2426
|
+
// fires once after the run loop). Clear streaming. This is the SOLE
|
|
2427
|
+
// terminal signal for a retry chain: close it with auto_retry_end
|
|
2428
|
+
// BEFORE forwarding the settle. The floor-pi synthesis path was
|
|
2429
|
+
// retired with agent-settled.ts. See changes: adopt-pi-074-080-features
|
|
2430
|
+
// (A.1), retry-forever-with-stop-control, update-pi-core-0-85-adopt-apis.
|
|
1512
2431
|
getBridgeState().isAgentStreaming = false;
|
|
2432
|
+
abortLatch.clear(sessionId);
|
|
2433
|
+
// Drain point. See change: count-non-message-usage.
|
|
2434
|
+
drainUsage(ctx);
|
|
2435
|
+
const retryEnd = retryTracker.observeAgentSettled(sessionId);
|
|
2436
|
+
if (retryEnd) {
|
|
2437
|
+
sendSyntheticRetryEvent(retryEnd.eventType, retryEnd.data);
|
|
2438
|
+
}
|
|
1513
2439
|
}
|
|
1514
2440
|
if (eventType === "agent_end") {
|
|
1515
2441
|
getBridgeState().isAgentStreaming = false;
|
|
1516
|
-
//
|
|
1517
|
-
//
|
|
1518
|
-
//
|
|
1519
|
-
|
|
1520
|
-
//
|
|
1521
|
-
//
|
|
1522
|
-
// clears before the settled error renders. A terminal error pi never
|
|
1523
|
-
// re-attempted (no chain) yields nothing here — the reducer's own
|
|
1524
|
-
// agent_end arm surfaces lastError.
|
|
1525
|
-
// See change: simplify-error-retry-single-card.
|
|
2442
|
+
// Provider-retry synthesis: an error agent_end means an attempt just
|
|
2443
|
+
// failed and (optimistically) another is coming — emit the WAITING
|
|
2444
|
+
// signal (attempt + computed delay + nextAttemptAt) so the surface
|
|
2445
|
+
// shows a live countdown during pi's sleep. The chain is NOT closed
|
|
2446
|
+
// here; only agent_settled (above) terminates it. A non-error agent_end
|
|
2447
|
+
// returns null. See change: retry-forever-with-stop-control (design D4).
|
|
1526
2448
|
const trackerSynth = retryTracker.observeAgentEnd(sessionId, event as any);
|
|
1527
2449
|
if (trackerSynth) {
|
|
1528
2450
|
sendSyntheticRetryEvent(trackerSynth.eventType, trackerSynth.data);
|
|
@@ -1603,6 +2525,11 @@ function initBridge(pi: ExtensionAPI) {
|
|
|
1603
2525
|
const enriched = { ...event, thinkingLevel: (pi as any).getThinkingLevel?.() };
|
|
1604
2526
|
const msg = mapEventToProtocol(sessionId, enriched);
|
|
1605
2527
|
connection.send(msg);
|
|
2528
|
+
// A TUI-initiated model change otherwise waits for the 30 s tick. The
|
|
2529
|
+
// 50 ms deferral lets pi's ctx.model reflect the new model first (same
|
|
2530
|
+
// as the dashboard-initiated setModel path). See change:
|
|
2531
|
+
// optimize-polling-hot-paths (D8).
|
|
2532
|
+
scheduleModelRecheckOnSelect(setRegisteredTimeout, sendModelUpdateIfChanged);
|
|
1606
2533
|
return;
|
|
1607
2534
|
}
|
|
1608
2535
|
|
|
@@ -1658,7 +2585,37 @@ function initBridge(pi: ExtensionAPI) {
|
|
|
1658
2585
|
// streamingTextFlushed reset depends on message_start being processed
|
|
1659
2586
|
// first. See change: add-followup-edit-and-steer-cancel (chat-order).
|
|
1660
2587
|
if (eventType === "message_start") {
|
|
2588
|
+
// Barrier, at ENTRY: bump the generation and open the identity BEFORE
|
|
2589
|
+
// the `role === "custom"` early return below, so a custom message still
|
|
2590
|
+
// closes out the previous identity's slot.
|
|
2591
|
+
// See change: coalesce-bridge-message-update-snapshots (D4).
|
|
2592
|
+
assistantMessageGen += 1;
|
|
2593
|
+
coalescer.messageStart(
|
|
2594
|
+
assistantMessageGen,
|
|
2595
|
+
messageKeyOf(assistantMessageGen, (event as any).message),
|
|
2596
|
+
(event as any).message,
|
|
2597
|
+
);
|
|
2598
|
+
// Custom messages are forwarded by wrapCustomPersistenceForCtx (pi's
|
|
2599
|
+
// idle-path sendMessage emits message_start/end internally only, and
|
|
2600
|
+
// the agent-loop path would double-forward here). See change:
|
|
2601
|
+
// render-inline-reasoning-and-custom-entries (D2).
|
|
2602
|
+
if ((event as any).message?.role === "custom") return;
|
|
2603
|
+
// pi >= 0.86.0 makes the system prompt/tool loadout transcript-backed:
|
|
2604
|
+
// `agent-loop.js` emits the first request's `role:"system"` message with
|
|
2605
|
+
// every prompt `section` and the full `toolsAdded` declaration list as a
|
|
2606
|
+
// `message_start`/`message_end` pair (~150 KB per message, so both
|
|
2607
|
+
// events cost ~2x that per session). The client has no `role:"system"`
|
|
2608
|
+
// arm, so forwarding it is pure wire cost with no render. Return AFTER
|
|
2609
|
+
// the barrier above (same placement as `custom`) so the barrier's
|
|
2610
|
+
// contract — every `message_start` opens an identity — is unchanged.
|
|
2611
|
+
// No version gate: pi < 0.86 never emits the role, so this is inert
|
|
2612
|
+
// there. See change: filter-system-role-message-forwarding (D2).
|
|
2613
|
+
if ((event as any).message?.role === "system") return;
|
|
1661
2614
|
wrapAppendMessageForCtx(ctx);
|
|
2615
|
+
// Lazy retry (review round 1): if session_start ran before the
|
|
2616
|
+
// sessionManager exposed its persistence methods, the wrapper would
|
|
2617
|
+
// never engage. Idempotent per-sm — re-invoking here repairs that.
|
|
2618
|
+
wrapCustomPersistenceForCtx(ctx);
|
|
1662
2619
|
const messageRef = (event as any).message;
|
|
1663
2620
|
if (messageRef && typeof messageRef === "object") {
|
|
1664
2621
|
const nonce = nextNonce();
|
|
@@ -1673,6 +2630,7 @@ function initBridge(pi: ExtensionAPI) {
|
|
|
1673
2630
|
// See change: unify-error-retry-lifecycle.
|
|
1674
2631
|
if (role === "user") {
|
|
1675
2632
|
abortLatch.clear(sessionId);
|
|
2633
|
+
retryTracker.noteExplicitRun(sessionId);
|
|
1676
2634
|
// A deliberate new user turn resets the empty-actionable guard's
|
|
1677
2635
|
// consecutive-continuation counter, so a stale count from a prior
|
|
1678
2636
|
// (possibly aborted) empty-actionable chain never shortens the next
|
|
@@ -1682,14 +2640,10 @@ function initBridge(pi: ExtensionAPI) {
|
|
|
1682
2640
|
} else if (abortLatch.shouldAbort(sessionId)) {
|
|
1683
2641
|
try { cachedCtx?.abort?.(); } catch { /* idempotent */ }
|
|
1684
2642
|
}
|
|
1685
|
-
//
|
|
1686
|
-
//
|
|
1687
|
-
//
|
|
1688
|
-
//
|
|
1689
|
-
if (role !== "user") {
|
|
1690
|
-
const retrySynth = retryTracker.observeMessageStart(sessionId, messageRef as any);
|
|
1691
|
-
if (retrySynth) sendSyntheticRetryEvent(retrySynth.eventType, retrySynth.data);
|
|
1692
|
-
}
|
|
2643
|
+
// NOTE: retry synthesis moved off `message_start`. pi ends a full
|
|
2644
|
+
// agent turn per attempt, so the retry lifecycle is now driven by
|
|
2645
|
+
// agent_start (in-flight) / agent_end (waiting) / agent_settled
|
|
2646
|
+
// (terminal). See change: retry-forever-with-stop-control.
|
|
1693
2647
|
if (role === "user") {
|
|
1694
2648
|
// Per-entry shadow-queue drain matcher: mirror pi's internal
|
|
1695
2649
|
// logic (`_processAgentEvent` in pi-coding-agent
|
|
@@ -1720,9 +2674,9 @@ function initBridge(pi: ExtensionAPI) {
|
|
|
1720
2674
|
bridgeSteering.splice(sIdx, 1);
|
|
1721
2675
|
emitQueueUpdate();
|
|
1722
2676
|
} else {
|
|
1723
|
-
const fIdx = bridgeFollowUp.
|
|
2677
|
+
const fIdx = bridgeFollowUp.indexOfText(text);
|
|
1724
2678
|
if (fIdx !== -1) {
|
|
1725
|
-
bridgeFollowUp.
|
|
2679
|
+
bridgeFollowUp.removeAt(fIdx);
|
|
1726
2680
|
emitQueueUpdate();
|
|
1727
2681
|
}
|
|
1728
2682
|
}
|
|
@@ -1748,6 +2702,26 @@ function initBridge(pi: ExtensionAPI) {
|
|
|
1748
2702
|
// earlier message_start nonce is what the reducer is waiting on).
|
|
1749
2703
|
// See change: fix-per-message-fork.
|
|
1750
2704
|
if (eventType === "message_end") {
|
|
2705
|
+
// Barrier, at ENTRY and BEFORE the deferred send is scheduled below: the
|
|
2706
|
+
// entry flush has already put the final snapshot on the wire, so closing
|
|
2707
|
+
// here means any update arriving during the macrotask gap is dropped by
|
|
2708
|
+
// the closed slot instead of landing after the `message_end`.
|
|
2709
|
+
// See change: coalesce-bridge-message-update-snapshots (D4/D5).
|
|
2710
|
+
// The generation this message was OPENED under, not the counter's
|
|
2711
|
+
// current value: a message_end for a message whose start we saw must
|
|
2712
|
+
// close ITS identity, never a newer one. Falls back to the current
|
|
2713
|
+
// counter for a message this instance never saw open (reload mid-turn).
|
|
2714
|
+
const endMessage = (event as any).message;
|
|
2715
|
+
const endGen = coalescer.generationOf(endMessage, assistantMessageGen);
|
|
2716
|
+
coalescer.messageEnd(endGen, messageKeyOf(endGen, endMessage));
|
|
2717
|
+
// Custom messages are forwarded by wrapCustomPersistenceForCtx — see
|
|
2718
|
+
// the message_start guard above. See change:
|
|
2719
|
+
// render-inline-reasoning-and-custom-entries (D2).
|
|
2720
|
+
if ((event as any).message?.role === "custom") return;
|
|
2721
|
+
// Same pi >= 0.86.0 system-role drop as the `message_start` arm above,
|
|
2722
|
+
// after the same barrier. See change:
|
|
2723
|
+
// filter-system-role-message-forwarding (D2).
|
|
2724
|
+
if ((event as any).message?.role === "system") return;
|
|
1751
2725
|
wrapAppendMessageForCtx(ctx);
|
|
1752
2726
|
const messageRef = (event as any).message;
|
|
1753
2727
|
const nonce = messageRef && typeof messageRef === "object"
|
|
@@ -1794,11 +2768,20 @@ function initBridge(pi: ExtensionAPI) {
|
|
|
1794
2768
|
return;
|
|
1795
2769
|
}
|
|
1796
2770
|
|
|
1797
|
-
//
|
|
1798
|
-
//
|
|
1799
|
-
//
|
|
2771
|
+
// Text snapshots are COALESCED (D1–D3): one wire write per fixed window
|
|
2772
|
+
// instead of one per source token. `offer` owns the family split and the
|
|
2773
|
+
// closed-identity drop rule; the markdown-image inliner now runs inside the
|
|
2774
|
+
// coalescer's send callback (once per flushed window, still ahead of the
|
|
2775
|
+
// snapshot that references its assets). This branch returns, so the shared
|
|
2776
|
+
// tail below never sees a `message_update`.
|
|
2777
|
+
// See change: coalesce-bridge-message-update-snapshots (D6).
|
|
1800
2778
|
if (eventType === "message_update") {
|
|
1801
|
-
|
|
2779
|
+
// Resolve the message's OWN generation, so a late update for an already
|
|
2780
|
+
// closed message still keys to that closed identity and is dropped —
|
|
2781
|
+
// keying it under the counter's current value would fail open.
|
|
2782
|
+
const updateMessage = (event as any)?.message;
|
|
2783
|
+
coalescer.offer(event, coalescer.generationOf(updateMessage, assistantMessageGen));
|
|
2784
|
+
return;
|
|
1802
2785
|
}
|
|
1803
2786
|
|
|
1804
2787
|
// Inline path-referenced image tool results (e.g. browser `screenshot`)
|
|
@@ -1851,18 +2834,56 @@ function initBridge(pi: ExtensionAPI) {
|
|
|
1851
2834
|
} catch { /* non-fatal */ }
|
|
1852
2835
|
}
|
|
1853
2836
|
|
|
1854
|
-
|
|
1855
|
-
connection.send
|
|
1856
|
-
|
|
1857
|
-
//
|
|
1858
|
-
//
|
|
1859
|
-
//
|
|
1860
|
-
//
|
|
1861
|
-
//
|
|
1862
|
-
|
|
1863
|
-
|
|
1864
|
-
|
|
2837
|
+
// The `tool_execution_update` carrier is structurally disjoint from the
|
|
2838
|
+
// EventBus path (pi core event → `pi.on()` → `connection.send`), but one
|
|
2839
|
+
// `snapshotDetails()` object feeds both — so stripping one carrier only
|
|
2840
|
+
// is a half-fix. `tool_execution_end` is terminal and stays fat.
|
|
2841
|
+
// See change: reduce-subagent-details-payload (D2, task 3.8).
|
|
2842
|
+
//
|
|
2843
|
+
// `session_compact` is forwarded WITHOUT its `compactionEntry`. pi >= 0.86
|
|
2844
|
+
// fills that entry's `systemMessage` with the same prompt-sections +
|
|
2845
|
+
// tool-declaration checkpoint the system-role arms above drop, and carries
|
|
2846
|
+
// the compaction `summary` beside it. No dashboard consumer reads either:
|
|
2847
|
+
// the client renders the divider from the event's presence and the badge
|
|
2848
|
+
// from `reason`/`willRetry`/`estimatedPostCompactionTokens`; the server
|
|
2849
|
+
// uses the event only to clear the `compacting` latch. Redact on a COPY —
|
|
2850
|
+
// pi hands the SAME event object to every subscribed extension, so a
|
|
2851
|
+
// `delete event.compactionEntry` would strip the field from unrelated
|
|
2852
|
+
// extensions too. The redaction stays OUT of `mapEventToProtocol` (which
|
|
2853
|
+
// is generic over every forwarded type). No version gate: the field is
|
|
2854
|
+
// simply omitted wherever it is absent.
|
|
2855
|
+
// See change: filter-system-role-message-forwarding (D6/D7).
|
|
2856
|
+
const forwardEvent =
|
|
2857
|
+
eventType === "session_compact"
|
|
2858
|
+
? redactCompactionEntry(event as Record<string, unknown>)
|
|
2859
|
+
: event;
|
|
2860
|
+
const msg = mapEventToProtocol(sessionId, forwardEvent);
|
|
2861
|
+
let heldByThrottle = false;
|
|
2862
|
+
if (eventType === "tool_execution_update") {
|
|
2863
|
+
msg.event.data = stripForForward(msg.event.data as Record<string, unknown>);
|
|
2864
|
+
// Agent ticks only (allowlist predicate) — every other tool's update
|
|
2865
|
+
// stream forwards 1:1. `offer` returns false when it has taken
|
|
2866
|
+
// ownership of the frame and will send (or discard) it later.
|
|
2867
|
+
// See change: reduce-bridge-tick-bandwidth (D2).
|
|
2868
|
+
if (isSubagentTick(event) && typeof event.toolCallId === "string") {
|
|
2869
|
+
heldByThrottle = !subagentTickThrottle.offer(event.toolCallId, msg, sessionId);
|
|
2870
|
+
}
|
|
2871
|
+
}
|
|
2872
|
+
if (eventType === "tool_execution_end" && typeof event.toolCallId === "string") {
|
|
2873
|
+
// Terminal: DISCARD any held tick rather than flushing it. This carrier
|
|
2874
|
+
// never carries terminal state, so a held frame is a strictly stale
|
|
2875
|
+
// intermediate snapshot; flushing it would race the overwrite that
|
|
2876
|
+
// visibly re-opens a finished tool row. Runs before the send so no held
|
|
2877
|
+
// frame can interleave after the end event.
|
|
2878
|
+
subagentTickThrottle.onTerminal(event.toolCallId);
|
|
1865
2879
|
}
|
|
2880
|
+
if (!heldByThrottle) connection.send(msg);
|
|
2881
|
+
|
|
2882
|
+
// Native `agent_settled` (pi ≥ 0.80.4, guaranteed at the 0.85.1 floor) is
|
|
2883
|
+
// the single terminal signal; the bridge forwards it above and the
|
|
2884
|
+
// `agent_settled` handler closes the retry chain. The floor-pi synthesis
|
|
2885
|
+
// path was retired once `piCompatibility.minimum` reached a version that
|
|
2886
|
+
// emits natively. See change: update-pi-core-0-85-adopt-apis.
|
|
1866
2887
|
}));
|
|
1867
2888
|
}
|
|
1868
2889
|
|
|
@@ -1872,11 +2893,76 @@ function initBridge(pi: ExtensionAPI) {
|
|
|
1872
2893
|
if (!isActive()) return;
|
|
1873
2894
|
cachedCtx = ctx;
|
|
1874
2895
|
if (!sessionReady) return;
|
|
1875
|
-
|
|
2896
|
+
// Same choke point as the enriched loop (D5).
|
|
2897
|
+
coalescer.flush();
|
|
2898
|
+
const forwarded = event?.type === "agent_before_settle" ? redactBeforeSettleContext(event) : event;
|
|
2899
|
+
const msg = mapEventToProtocol(sessionId, forwarded);
|
|
1876
2900
|
connection.send(msg);
|
|
1877
2901
|
}));
|
|
1878
2902
|
}
|
|
1879
2903
|
|
|
2904
|
+
// ── Subagent fan-out admission ────────────────────────────────────────────
|
|
2905
|
+
// Bounds concurrently in-flight `Agent` children so a wide fan-out on a loaded
|
|
2906
|
+
// host cannot stall the parent's event loop until the process is reaped.
|
|
2907
|
+
//
|
|
2908
|
+
// Registered AFTER the pass-through loop above ON PURPOSE: `runner.emitToolCall`
|
|
2909
|
+
// returns on the FIRST handler that answers a blocking result, so a gate
|
|
2910
|
+
// registered earlier would starve the bridge's own `tool_call` forwarder — the
|
|
2911
|
+
// dashboard would miss the refused call's `tool_call` while still seeing its
|
|
2912
|
+
// `tool_execution_end`, and live UI and transcript would disagree. See D8.
|
|
2913
|
+
//
|
|
2914
|
+
// The result carries `block` + `reason` and NEVER `terminate`: a refusal is
|
|
2915
|
+
// "not now" (re-issue after running children finish), not a task failure. The
|
|
2916
|
+
// `block` decision itself lives in `subagent-fanout-admission.ts`. See change:
|
|
2917
|
+
// bound-subagent-fanout-under-host-pressure (D2/D4/D5/D6/D7/D8).
|
|
2918
|
+
const admissionSampler = new SaturationSampler();
|
|
2919
|
+
const fanoutAdmission = new FanoutAdmissionGate({
|
|
2920
|
+
resolveConfig: () => resolveAdmissionConfig(config),
|
|
2921
|
+
saturation: admissionSampler,
|
|
2922
|
+
// Refusals are ALSO written durably: the failure this mitigates ends with the
|
|
2923
|
+
// process gone, so counters carried only by the live frame vanish in exactly
|
|
2924
|
+
// the case that matters. Admissions write nothing (hot path, no FS I/O).
|
|
2925
|
+
recordRefusal: (record) => {
|
|
2926
|
+
try {
|
|
2927
|
+
pi.appendEntry("subagent-admission-refused", record);
|
|
2928
|
+
} catch (err) {
|
|
2929
|
+
console.error("[dashboard] subagent-admission-refused entry failed:", err);
|
|
2930
|
+
}
|
|
2931
|
+
},
|
|
2932
|
+
});
|
|
2933
|
+
pi.on("tool_call", safe((event: any) => {
|
|
2934
|
+
if (!isActive()) return;
|
|
2935
|
+
return fanoutAdmission.onToolCall(event);
|
|
2936
|
+
}));
|
|
2937
|
+
// Agent path gate — registered AFTER the fan-out admission handler (and after the
|
|
2938
|
+
// bridge's own forwarder) and deliberately NOT wrapped in the fail-open `safe()`:
|
|
2939
|
+
// its own try/catch maps any internal error to a block. Stale bridge instances
|
|
2940
|
+
// (after reload) pass through. See change: ask-agent-file-access-in-chat (D1).
|
|
2941
|
+
pi.on("tool_call", ((event: any, ctx: any) => {
|
|
2942
|
+
if (!isActive()) return undefined;
|
|
2943
|
+
return pathGate.handler(event, ctx);
|
|
2944
|
+
}) as any);
|
|
2945
|
+
pi.on("before_agent_start", safe((event: any) => {
|
|
2946
|
+
if (!isActive()) return;
|
|
2947
|
+
pathGate.onBeforeAgentStart(event);
|
|
2948
|
+
}));
|
|
2949
|
+
// Release permits on `tool_execution_end` — the ONE signal pi emits on the
|
|
2950
|
+
// normal, blocked AND aborted paths. NEVER `tool_result`: an aborted call
|
|
2951
|
+
// skips the path that produces it, so a permit released there would leak on
|
|
2952
|
+
// every Esc and eventually refuse all subagent work for the session. See D2.
|
|
2953
|
+
pi.on("tool_execution_end", safe((event: any) => {
|
|
2954
|
+
if (!isActive()) return;
|
|
2955
|
+
fanoutAdmission.onExecutionEnd(event);
|
|
2956
|
+
}));
|
|
2957
|
+
|
|
2958
|
+
// Generic custom entries/messages (pi.appendEntry / pi.sendMessage) are NOT
|
|
2959
|
+
// subscribed here: pi does NOT dispatch `entry_appended` to extensions, and
|
|
2960
|
+
// the idle-path sendMessage emits message_start/end to internal listeners
|
|
2961
|
+
// only. The SINGLE chokepoint both surfaces share is the sessionManager
|
|
2962
|
+
// persistence methods — wrapped in `wrapCustomPersistenceForCtx` (same
|
|
2963
|
+
// pattern as wrapAppendMessageForCtx), installed at session_start below.
|
|
2964
|
+
// See change: render-inline-reasoning-and-custom-entries (D2).
|
|
2965
|
+
|
|
1880
2966
|
// Push external renames the moment they happen (pi 0.80.3+ session_info_changed)
|
|
1881
2967
|
// instead of waiting for the turn-end name poll. The new name is routed
|
|
1882
2968
|
// through the auto-namer's self-filter: the bridge's OWN auto-name echoing
|
|
@@ -1956,70 +3042,78 @@ function initBridge(pi: ExtensionAPI) {
|
|
|
1956
3042
|
// right after `sessionReady` flips true on (re-)register, in emission order.
|
|
1957
3043
|
// See change: fix-subagent-live-detail-reliability.
|
|
1958
3044
|
function flushPendingSubagentFrames(): void {
|
|
1959
|
-
|
|
1960
|
-
|
|
1961
|
-
|
|
1962
|
-
|
|
1963
|
-
|
|
3045
|
+
// Drained intermediate frames are stripped too: this path calls
|
|
3046
|
+
// `sendEventForward` directly, so a bus-path-only strip would leak every
|
|
3047
|
+
// buffered frame fat. See change: reduce-subagent-details-payload (X5).
|
|
3048
|
+
const flushed = flushBufferedSubagentFrames(subagentFrameBuffer, sendEventForward);
|
|
3049
|
+
if (flushed === 0) return;
|
|
1964
3050
|
console.log(
|
|
1965
|
-
`[dashboard] flushed ${
|
|
3051
|
+
`[dashboard] flushed ${flushed} buffered subagent frame(s) on re-register` +
|
|
1966
3052
|
` (forwarded=${subagentFrameBuffer.stats.forwarded} buffered=${subagentFrameBuffer.stats.buffered}` +
|
|
1967
3053
|
` flushed=${subagentFrameBuffer.stats.flushed})`,
|
|
1968
3054
|
);
|
|
1969
3055
|
}
|
|
1970
3056
|
|
|
1971
|
-
// EventBus
|
|
1972
|
-
//
|
|
1973
|
-
//
|
|
1974
|
-
//
|
|
1975
|
-
|
|
1976
|
-
|
|
1977
|
-
|
|
1978
|
-
|
|
1979
|
-
|
|
1980
|
-
|
|
1981
|
-
|
|
1982
|
-
|
|
1983
|
-
|
|
1984
|
-
|
|
1985
|
-
|
|
1986
|
-
|
|
1987
|
-
|
|
1988
|
-
|
|
1989
|
-
|
|
1990
|
-
|
|
1991
|
-
|
|
1992
|
-
|
|
1993
|
-
subagentFrameBuffer.markForwarded(channel, eventData);
|
|
1994
|
-
} else if (!subagentFrameBuffer.buffer(channel, eventData)) {
|
|
1995
|
-
console.warn(
|
|
1996
|
-
`[dashboard] subagent frame dropped (no agentId) channel=${channel} while not ready`,
|
|
1997
|
-
);
|
|
1998
|
-
}
|
|
1999
|
-
} else if (sessionReady && isActive()) {
|
|
2000
|
-
sendEventForward(channel, eventData);
|
|
2001
|
-
}
|
|
2002
|
-
} catch { /* forwarding failure must never break the original emit */ }
|
|
2003
|
-
origEventsEmit!(channel, data);
|
|
2004
|
-
};
|
|
2005
|
-
}
|
|
3057
|
+
// EventBus forwarding: ONE `pi.events.on` subscription per declared channel
|
|
3058
|
+
// (every key of EVENT_BUS_MAP). NOT an `emit` intercept — pi hands each
|
|
3059
|
+
// extension its own `events` facade, so patching OUR `emit` never observed
|
|
3060
|
+
// pi-flows' or pi-subagents' emissions, and every live flow_*/subagent_*
|
|
3061
|
+
// event was silently dropped (automation runs then hung until the max-age
|
|
3062
|
+
// reaper). The gating + subagent-buffer semantics live in `forwardBusEvent`.
|
|
3063
|
+
// See change: fix-automation-run-lifecycle.
|
|
3064
|
+
const disposeEventBusForwarding = registerEventBusForwarding(
|
|
3065
|
+
pi.events,
|
|
3066
|
+
{
|
|
3067
|
+
sendEventForward,
|
|
3068
|
+
isSessionReady: () => sessionReady,
|
|
3069
|
+
isActive,
|
|
3070
|
+
isConnected: () => connection.isConnected,
|
|
3071
|
+
subagent: {
|
|
3072
|
+
isSubagentChannel: (channel) => SubagentFrameBuffer.isSubagentChannel(channel),
|
|
3073
|
+
markForwarded: (channel, data) => subagentFrameBuffer.markForwarded(channel, data),
|
|
3074
|
+
buffer: (channel, data) => subagentFrameBuffer.buffer(channel, data),
|
|
3075
|
+
stripForForward,
|
|
3076
|
+
},
|
|
3077
|
+
},
|
|
3078
|
+
);
|
|
2006
3079
|
|
|
2007
3080
|
pi.on("session_start", safe(async (_event: any, ctx: any) => {
|
|
2008
3081
|
|
|
2009
3082
|
// Bail out if a newer bridge instance has taken over
|
|
2010
3083
|
if (!isActive()) return;
|
|
2011
3084
|
const newSessionId = ctx.sessionManager.getSessionId();
|
|
3085
|
+
pathGate.onSessionStart();
|
|
3086
|
+
// Re-arm MCP registration for the (replacement) session; its mint below
|
|
3087
|
+
// registers pi-dashboard again. See change: migrate-mcp-to-pi-builtin (D1).
|
|
3088
|
+
mcpRegistrar.onSessionStart();
|
|
2012
3089
|
|
|
2013
3090
|
// On session switch/fork (0.65.0+: event.reason replaces session_switch/session_fork events),
|
|
2014
3091
|
// unregister the old session before re-registering the new one.
|
|
2015
3092
|
const reason = _event?.reason;
|
|
2016
|
-
|
|
3093
|
+
// Synchronous compare-and-set BEFORE any await: this instance was loaded
|
|
3094
|
+
// by a dashboard-requested reload → it owns the `/reload` `completed`,
|
|
3095
|
+
// emitted after `replay_complete` below.
|
|
3096
|
+
// See change: fix-terminal-session-dashboard-reload (D4).
|
|
3097
|
+
const reloadDelivered = consumePendingReloadOnSessionStart(reason, newSessionId);
|
|
3098
|
+
// Baseline + seed from ONE snapshot, before any register goes out: the
|
|
3099
|
+
// drain forwards only entries appended after this point, and the register
|
|
3100
|
+
// carries this snapshot's full totals. Undefined on a failed read.
|
|
3101
|
+
// See change: count-non-message-usage.
|
|
3102
|
+
let usageSeed: ReturnType<UsageDrain["baseline"]> | undefined;
|
|
3103
|
+
try {
|
|
3104
|
+
usageSeed = usageDrain.baseline(ctx.sessionManager);
|
|
3105
|
+
} catch (err) {
|
|
3106
|
+
console.error("[dashboard] usage baseline failed:", err);
|
|
3107
|
+
}
|
|
3108
|
+
const sessionChanged =
|
|
3109
|
+
(reason === "new" || reason === "fork" || reason === "resume") && !!sessionId && sessionId !== newSessionId;
|
|
3110
|
+
if (sessionChanged) {
|
|
2017
3111
|
// Clear any latched abort for the OUTGOING session id. Otherwise a
|
|
2018
3112
|
// latched old session that is resumed later would have its first
|
|
2019
3113
|
// legitimate turn aborted by the agent_start/message_start latch hooks.
|
|
2020
3114
|
// See change: unify-error-retry-lifecycle.
|
|
2021
3115
|
abortLatch.clear(sessionId);
|
|
2022
|
-
handleSessionChange(ctx);
|
|
3116
|
+
handleSessionChange(ctx, usageSeed);
|
|
2023
3117
|
}
|
|
2024
3118
|
|
|
2025
3119
|
cachedHasUI = ctx.hasUI;
|
|
@@ -2060,6 +3154,12 @@ function initBridge(pi: ExtensionAPI) {
|
|
|
2060
3154
|
appendMessageWrapped = false;
|
|
2061
3155
|
lastWrappedSm = null;
|
|
2062
3156
|
wrapAppendMessageForCtx(ctx);
|
|
3157
|
+
// Wrap the custom-persistence chokepoint BEFORE any events flow, so an
|
|
3158
|
+
// extension appending at session_start is still forwarded. See change:
|
|
3159
|
+
// render-inline-reasoning-and-custom-entries (D2).
|
|
3160
|
+
customPersistenceWrapped = false;
|
|
3161
|
+
customWrappedSm = null;
|
|
3162
|
+
wrapCustomPersistenceForCtx(ctx);
|
|
2063
3163
|
|
|
2064
3164
|
// Register ask_user at runtime (not at load time) to avoid static
|
|
2065
3165
|
// tool-name conflicts with other extensions like pi-flows.
|
|
@@ -2074,7 +3174,13 @@ function initBridge(pi: ExtensionAPI) {
|
|
|
2074
3174
|
// update_roles). list_models reads the in-process session registry via a
|
|
2075
3175
|
// live getter so its refs match the human Model Selector exactly.
|
|
2076
3176
|
// See change: add-agent-role-model-tools.
|
|
2077
|
-
registerRoleModelTools(pi, {
|
|
3177
|
+
registerRoleModelTools(pi, {
|
|
3178
|
+
getRegistry: () => cachedModelRegistry,
|
|
3179
|
+
// Live scope read at call time from the latest captured ctx (dynamic via
|
|
3180
|
+
// Ctrl+P cycling). Absent on older pi / empty when unscoped → no filter.
|
|
3181
|
+
// See change: update-pi-core-0-83-adopt-apis.
|
|
3182
|
+
getScopedModels: () => (cachedCtx as any)?.scopedModels,
|
|
3183
|
+
});
|
|
2078
3184
|
|
|
2079
3185
|
// Extract session file/dir early — needed for source detection and UI proxy
|
|
2080
3186
|
const sessionFile = ctx.sessionManager.getSessionFile?.() ?? undefined;
|
|
@@ -2292,18 +3398,13 @@ function initBridge(pi: ExtensionAPI) {
|
|
|
2292
3398
|
}
|
|
2293
3399
|
});
|
|
2294
3400
|
|
|
2295
|
-
// Notify is fire-and-forget: call original + forward to dashboard
|
|
2296
|
-
|
|
2297
|
-
|
|
2298
|
-
|
|
2299
|
-
|
|
2300
|
-
|
|
2301
|
-
|
|
2302
|
-
prompt: { question: message, type: "notify" },
|
|
2303
|
-
component: { type: "notify", props: { message, level } },
|
|
2304
|
-
placement: "inline",
|
|
2305
|
-
});
|
|
2306
|
-
};
|
|
3401
|
+
// Notify is fire-and-forget: call original + forward to dashboard on the
|
|
3402
|
+
// dedicated `notify` channel. See change: split-notify-from-prompt-request.
|
|
3403
|
+
(ctx.ui as any).notify = createNotifyProxy({
|
|
3404
|
+
sessionId,
|
|
3405
|
+
send: (msg) => connection.send(msg),
|
|
3406
|
+
originalNotify,
|
|
3407
|
+
});
|
|
2307
3408
|
}
|
|
2308
3409
|
|
|
2309
3410
|
// Flip ctx.hasUI=true now that ctx.ui.* has been patched to route
|
|
@@ -2371,7 +3472,92 @@ function initBridge(pi: ExtensionAPI) {
|
|
|
2371
3472
|
|
|
2372
3473
|
// Connect first, then auto-start if needed.
|
|
2373
3474
|
// session_register must be buffered before any event_forward messages.
|
|
2374
|
-
|
|
3475
|
+
//
|
|
3476
|
+
// (tasks 7.2/7.3) A REMOTE endpoint is challenged BEFORE the connection
|
|
3477
|
+
// opens: across a network an address proves nothing, so the pinned Ed25519
|
|
3478
|
+
// identity is the only thing that answers "is this my dashboard?" (D8).
|
|
3479
|
+
// Local endpoints are unaffected — the socket/loopback token already
|
|
3480
|
+
// authorises them — so this adds no latency to the common path.
|
|
3481
|
+
if (isRemoteEndpoint(dashboardUrl)) {
|
|
3482
|
+
const pinsFile = serverPinsPath();
|
|
3483
|
+
const connectIfIdentityVerifies = async () => {
|
|
3484
|
+
const verdict = await gateRemoteRegistration({
|
|
3485
|
+
endpoint: dashboardUrl,
|
|
3486
|
+
store: loadServerPins(pinsFile),
|
|
3487
|
+
});
|
|
3488
|
+
// Task 10.3: the cause is distinguishable in the log, not folded into
|
|
3489
|
+
// a generic connection failure.
|
|
3490
|
+
const line = `[dashboard] remote identity ${verdict.cause}: ${verdict.reason}`;
|
|
3491
|
+
if (!verdict.allow) {
|
|
3492
|
+
console.error(`${line} — not registering`);
|
|
3493
|
+
return;
|
|
3494
|
+
}
|
|
3495
|
+
console.log(line);
|
|
3496
|
+
// Only a VERIFIED identity gets its address remembered.
|
|
3497
|
+
if (verdict.fingerprint) notePinEndpoint(pinsFile, verdict.fingerprint, dashboardUrl);
|
|
3498
|
+
connection.connect();
|
|
3499
|
+
};
|
|
3500
|
+
// Guarded discard: a failure here must be OBSERVED, never take the host
|
|
3501
|
+
// pi agent down.
|
|
3502
|
+
void connectIfIdentityVerifies().catch((err) => console.error("[dashboard]", err));
|
|
3503
|
+
} else {
|
|
3504
|
+
connection.connect();
|
|
3505
|
+
}
|
|
3506
|
+
// Drain the buffered transport diagnostics through the live connection
|
|
3507
|
+
// (task 10.5). `send()` buffers while the socket is down, which is the
|
|
3508
|
+
// right behaviour here: the detail is self-describing, so a late delivery
|
|
3509
|
+
// is still a true one.
|
|
3510
|
+
transportDiagnostics.attach({
|
|
3511
|
+
send: (m) => connection.send(m),
|
|
3512
|
+
getSessionId: () => sessionId,
|
|
3513
|
+
});
|
|
3514
|
+
|
|
3515
|
+
// (task 3.8) Verify the instance answering at the recorded endpoint really
|
|
3516
|
+
// is the one the record named. The socket's mode and the local token are
|
|
3517
|
+
// both per-HOME, so a same-HOME impostor passes them — only the published
|
|
3518
|
+
// `instanceId` distinguishes instances. Refusal is loud and does NOT fall
|
|
3519
|
+
// back to a discovered substitute: that substitution is the bug.
|
|
3520
|
+
if (
|
|
3521
|
+
endpointChoice.available &&
|
|
3522
|
+
endpointChoice.source === "rendezvous-record" &&
|
|
3523
|
+
rendezvous?.instanceId
|
|
3524
|
+
) {
|
|
3525
|
+
const verifyRecordedInstance = async () => {
|
|
3526
|
+
const verdict = await verifyInstanceIdentity({
|
|
3527
|
+
healthUrl: healthUrlForInstance(rendezvous.httpPort),
|
|
3528
|
+
expectedInstanceId: rendezvous.instanceId,
|
|
3529
|
+
});
|
|
3530
|
+
if (verdict.adopt) {
|
|
3531
|
+
registeredInstanceId = rendezvous.instanceId;
|
|
3532
|
+
return;
|
|
3533
|
+
}
|
|
3534
|
+
// Only a CONFLICT justifies tearing the connection down. `disconnect()`
|
|
3535
|
+
// sets `intentionalClose`, so nothing rearms the backoff loop and the
|
|
3536
|
+
// session is dead until pi itself restarts — right for an impostor,
|
|
3537
|
+
// catastrophic for an outage. `/api/health` is unreachable for seconds
|
|
3538
|
+
// on every `POST /api/restart` while the gateway socket stays healthy,
|
|
3539
|
+
// so treating silence as refusal would kill every bridge on the host on
|
|
3540
|
+
// every rebuild. Unverified means we simply do not claim an identity.
|
|
3541
|
+
if (!verdict.conflict) {
|
|
3542
|
+
console.error(
|
|
3543
|
+
`[dashboard] instance verification ${verdict.reason} — keeping the connection, identity unclaimed`,
|
|
3544
|
+
);
|
|
3545
|
+
registeredInstanceId = undefined;
|
|
3546
|
+
return;
|
|
3547
|
+
}
|
|
3548
|
+
console.error(`[dashboard] instance verification ${verdict.reason} — disconnecting`);
|
|
3549
|
+
registeredInstanceId = undefined;
|
|
3550
|
+
try {
|
|
3551
|
+
connection.disconnect();
|
|
3552
|
+
} catch {
|
|
3553
|
+
/* already down */
|
|
3554
|
+
}
|
|
3555
|
+
};
|
|
3556
|
+
// Guarded discard: the verification runs alongside the connection and
|
|
3557
|
+
// must never take the host pi agent down, but its failure must still be
|
|
3558
|
+
// OBSERVED rather than dropped on the floor.
|
|
3559
|
+
void verifyRecordedInstance().catch((err) => console.error("[dashboard]", err));
|
|
3560
|
+
}
|
|
2375
3561
|
|
|
2376
3562
|
// Extract first message (sessionFile/sessionDir already extracted above)
|
|
2377
3563
|
const firstMessage = extractFirstMessage(ctx);
|
|
@@ -2400,8 +3586,10 @@ function initBridge(pi: ExtensionAPI) {
|
|
|
2400
3586
|
// the heartbeat/git timers, leaving a resumed session dead in the UI.
|
|
2401
3587
|
// See change: fix-bridge-resume-disconnect.
|
|
2402
3588
|
const startCwd = safeCwd(ctx);
|
|
3589
|
+
const spawnToken = consumeSpawnToken();
|
|
2403
3590
|
connection.send({
|
|
2404
3591
|
type: "session_register",
|
|
3592
|
+
extensionIdentity: bridgeExtensionIdentity(),
|
|
2405
3593
|
sessionId,
|
|
2406
3594
|
cwd: startCwd,
|
|
2407
3595
|
name: lastSessionName || undefined,
|
|
@@ -2412,6 +3600,23 @@ function initBridge(pi: ExtensionAPI) {
|
|
|
2412
3600
|
sessionDir,
|
|
2413
3601
|
firstMessage,
|
|
2414
3602
|
eventCount,
|
|
3603
|
+
// The ONLY channel by which the server learns this session's process for a
|
|
3604
|
+
// non-headless spawn: `tmux new-window` returns tmux's own pid, not pi's,
|
|
3605
|
+
// so without this the server's record has no `pid` and shutdown has
|
|
3606
|
+
// nothing to escalate to — the session was unregistered while a ~127 MB
|
|
3607
|
+
// pi kept running (#452). The two `session_register` sends in
|
|
3608
|
+
// session-sync.ts already carry it; this one, the FIRST register of a
|
|
3609
|
+
// fresh session, did not.
|
|
3610
|
+
// See change: fix-tmux-session-shutdown-leak (D6).
|
|
3611
|
+
pid: process.pid,
|
|
3612
|
+
// The spawn correlation token, echoed back so the server can match THIS
|
|
3613
|
+
// register to the spawn that produced it. This is a fresh session's FIRST
|
|
3614
|
+
// register, and it omitted the token entirely: tier-1 correlation never
|
|
3615
|
+
// fired for a dashboard spawn, so the spawn watchdog could only match by
|
|
3616
|
+
// cwd and reported false register-timeouts for concurrent spawns into one
|
|
3617
|
+
// directory. Single-use — `consumeSpawnToken` scrubs the env.
|
|
3618
|
+
// See change: fix-tmux-session-shutdown-leak (D5).
|
|
3619
|
+
...(spawnToken ? { spawnToken } : {}),
|
|
2415
3620
|
...(dashboardSpawned ? { dashboardSpawned: true } : {}),
|
|
2416
3621
|
// Tri-state git-repo signal, computed at register time (authority).
|
|
2417
3622
|
// See change: gate-session-worktree-button-on-git.
|
|
@@ -2419,11 +3624,36 @@ function initBridge(pi: ExtensionAPI) {
|
|
|
2419
3624
|
// Fact-forwarding: server decides auto-hide. See change:
|
|
2420
3625
|
// auto-hide-headless-worker-sessions.
|
|
2421
3626
|
...buildVisibilityRegisterFields(cachedHasUI, process.env),
|
|
3627
|
+
// Applied server-side only for an id it has no record of.
|
|
3628
|
+
// See change: count-non-message-usage.
|
|
3629
|
+
...(usageSeed ? { usageSeed } : {}),
|
|
2422
3630
|
});
|
|
2423
3631
|
|
|
3632
|
+
// The register above just went out (live socket, or buffered for the
|
|
3633
|
+
// open — either way the manager learns its last-registered endpoint for
|
|
3634
|
+
// the migration gate's reversal target).
|
|
3635
|
+
// See change: fix-bridge-mdns-migration-hijack (task 2.1).
|
|
3636
|
+
connection.noteRegistered();
|
|
3637
|
+
|
|
2424
3638
|
// Allow event forwarding now that session_register is buffered
|
|
2425
3639
|
sessionReady = true;
|
|
2426
3640
|
|
|
3641
|
+
// D3: mint-on-registration. Ask the mcp-server plugin for this session's
|
|
3642
|
+
// /mcp credential now that the socket is (re)registered — the reply
|
|
3643
|
+
// arrives on the session-private lane (mcp_token_minted) and registers
|
|
3644
|
+
// pi-dashboard with pi's built-in MCP, and re-registers after every
|
|
3645
|
+
// reconnect, which is what makes a dashboard restart self-heal. Ordered
|
|
3646
|
+
// after session_register on the SAME socket, so the server's
|
|
3647
|
+
// connection-key attribution is already established when it arrives.
|
|
3648
|
+
// See change: wire-mcp-session-token (D3/D5).
|
|
3649
|
+
connection.send({
|
|
3650
|
+
type: "plugin_pi_message",
|
|
3651
|
+
sessionId,
|
|
3652
|
+
pluginId: "mcp-server",
|
|
3653
|
+
messageType: "mcp/mint-token",
|
|
3654
|
+
payload: {},
|
|
3655
|
+
});
|
|
3656
|
+
|
|
2427
3657
|
// Flush any subagent frames buffered during the not-ready window (D1) so a
|
|
2428
3658
|
// reconnect/discovery/reload gap self-heals instead of leaving a running
|
|
2429
3659
|
// subagent's detail empty. See change: fix-subagent-live-detail-reliability.
|
|
@@ -2432,6 +3662,10 @@ function initBridge(pi: ExtensionAPI) {
|
|
|
2432
3662
|
// Replay full session history so the dashboard has all messages
|
|
2433
3663
|
replaySessionEntries();
|
|
2434
3664
|
connection.send({ type: "replay_complete", sessionId });
|
|
3665
|
+
// After replay_complete: inside the replay window the server may drop
|
|
3666
|
+
// forwarded events without insert or broadcast (`skipReplayInsert`).
|
|
3667
|
+
// See change: fix-terminal-session-dashboard-reload (D4).
|
|
3668
|
+
if (reloadDelivered) connection.send(reloadCompletedFeedback(sessionId));
|
|
2435
3669
|
// If agent is mid-turn (e.g. reload during streaming), send synthetic agent_start
|
|
2436
3670
|
if (getBridgeState().isAgentStreaming) {
|
|
2437
3671
|
connection.send(mapEventToProtocol(sessionId, { type: "agent_start" }));
|
|
@@ -2459,14 +3693,22 @@ function initBridge(pi: ExtensionAPI) {
|
|
|
2459
3693
|
} catch { /* modelRegistry not available */ }
|
|
2460
3694
|
}
|
|
2461
3695
|
|
|
2462
|
-
// Apply default model only on brand-new sessions (no prior message history)
|
|
2463
|
-
//
|
|
2464
|
-
//
|
|
2465
|
-
//
|
|
2466
|
-
//
|
|
2467
|
-
//
|
|
2468
|
-
//
|
|
2469
|
-
//
|
|
3696
|
+
// Apply default model only on brand-new sessions (no prior message history)
|
|
3697
|
+
// that were NOT launched with an explicit --model flag. Resume (--session) and
|
|
3698
|
+
// fork (--fork) both load parent messages, so messageCount > 0 and we keep their
|
|
3699
|
+
// existing model. Mirrors pi's own !hasExistingSession gate (sdk.js:106 —
|
|
3700
|
+
// `existingSession.messages.length > 0`). NOT the raw getEntries() count: pi's
|
|
3701
|
+
// sdk.js auto-appends model_change + thinking_level_change setup entries to a
|
|
3702
|
+
// brand-new session BEFORE emitting session_start, so getEntries() is ≥ 2 even
|
|
3703
|
+
// for a session with no user history. Only message entries count.
|
|
3704
|
+
// The bridge runs inside the pi process, so process.argv is pi's argv — an
|
|
3705
|
+
// explicit --model there is the spawner's resolved choice and the default
|
|
3706
|
+
// never overrides it. The deferred retry below needs no separate guard: when
|
|
3707
|
+
// the gate is false this never sets pendingDefaultModel, so onProviderChanged
|
|
3708
|
+
// has nothing to re-apply.
|
|
3709
|
+
// See changes: fix-resume-keeps-session-model,
|
|
3710
|
+
// fix-default-model-new-session-entry-count,
|
|
3711
|
+
// fix-default-model-clobbers-explicit-model (issue #595).
|
|
2470
3712
|
const entryCount = ctx.sessionManager.buildSessionContext?.()?.messages?.length ?? 0;
|
|
2471
3713
|
const freshConfig = loadConfig();
|
|
2472
3714
|
if (shouldApplyDefaultModel({
|
|
@@ -2474,6 +3716,7 @@ function initBridge(pi: ExtensionAPI) {
|
|
|
2474
3716
|
entryCount,
|
|
2475
3717
|
hasModelRegistry: Boolean(cachedModelRegistry),
|
|
2476
3718
|
hasDefaultModel: Boolean(freshConfig.defaultModel),
|
|
3719
|
+
hasExplicitModel: hasExplicitModelArg(process.argv),
|
|
2477
3720
|
})) {
|
|
2478
3721
|
pendingDefaultModel = applyDefaultModel();
|
|
2479
3722
|
}
|
|
@@ -2510,25 +3753,40 @@ function initBridge(pi: ExtensionAPI) {
|
|
|
2510
3753
|
let spinnerStart = 0;
|
|
2511
3754
|
let activeLoader: Loader | null = null;
|
|
2512
3755
|
const stopSpinner = () => {
|
|
3756
|
+
// Release the interval BEFORE the guarded ctx.ui call, so a stale ctx
|
|
3757
|
+
// still stops the 1s label refresh instead of leaking it.
|
|
2513
3758
|
if (spinnerTimer) {
|
|
2514
3759
|
clearInterval(spinnerTimer);
|
|
2515
3760
|
spinnerTimer = null;
|
|
2516
3761
|
}
|
|
2517
3762
|
activeLoader = null;
|
|
2518
|
-
|
|
3763
|
+
// This runs from `onLaunchEnd` AND from the terminal .then()/.catch()
|
|
3764
|
+
// below, either of which can land after a session replacement/reload has
|
|
3765
|
+
// invalidated `ctx`. See ui-stale-guard.ts.
|
|
3766
|
+
runUiSafely(() => ctx.ui.setWidget("pi-dashboard-launch", undefined));
|
|
2519
3767
|
};
|
|
2520
|
-
|
|
3768
|
+
// Resolve the ports the auto-start chain uses (health check + launch)
|
|
3769
|
+
// with the shared env → config.json → default precedence, so a session
|
|
3770
|
+
// whose environment names the dashboard's real ports attaches to (or
|
|
3771
|
+
// launches on) THOSE ports instead of a stale config/default — this is
|
|
3772
|
+
// the split-brain fix: without it, a harness/container session with
|
|
3773
|
+
// DASHBOARD_PORT in its env health-checked 8000, found nothing, and
|
|
3774
|
+
// launched a competing dashboard on 8000. `config` is not mutated;
|
|
3775
|
+
// `loadConfig()` stays untouched (design D1/D2).
|
|
3776
|
+
// See change: fix-bridge-autostart-port-resolution.
|
|
3777
|
+
autoStartServer({ ...config, ...resolveDashboardPorts(process.env, config) }, {
|
|
2521
3778
|
discoverDashboard,
|
|
2522
3779
|
isDashboardRunning,
|
|
2523
3780
|
launchServer,
|
|
2524
|
-
notify: (msg, level) => ctx.ui.notify(msg, level),
|
|
3781
|
+
notify: (msg, level) => runUiSafely(() => ctx.ui.notify(msg, level)),
|
|
2525
3782
|
onLaunchStart: () => {
|
|
2526
3783
|
spinnerStart = Date.now();
|
|
2527
3784
|
const buildMessage = () => {
|
|
2528
3785
|
const elapsed = Math.floor((Date.now() - spinnerStart) / 1000);
|
|
2529
3786
|
return `starting dashboard server … (${elapsed}s)`;
|
|
2530
3787
|
};
|
|
2531
|
-
|
|
3788
|
+
runUiSafely(() =>
|
|
3789
|
+
ctx.ui.setWidget(
|
|
2532
3790
|
"pi-dashboard-launch",
|
|
2533
3791
|
(tui: unknown, theme: { fg: (role: string, s: string) => string }) => {
|
|
2534
3792
|
const loader = new Loader(
|
|
@@ -2544,6 +3802,7 @@ function initBridge(pi: ExtensionAPI) {
|
|
|
2544
3802
|
return loader;
|
|
2545
3803
|
},
|
|
2546
3804
|
{ placement: "aboveEditor" },
|
|
3805
|
+
),
|
|
2547
3806
|
);
|
|
2548
3807
|
// Refresh the elapsed-seconds label every second. Frame animation is
|
|
2549
3808
|
// driven by the Loader's own 80ms interval.
|
|
@@ -2569,13 +3828,56 @@ function initBridge(pi: ExtensionAPI) {
|
|
|
2569
3828
|
}).then((result) => {
|
|
2570
3829
|
stopSpinner(); // safety net — covers onLaunchEnd not firing
|
|
2571
3830
|
if (result.server && result.server.piPort !== config.piPort) {
|
|
2572
|
-
|
|
2573
|
-
|
|
3831
|
+
const candidateUrl = `ws://${result.server.host === "localhost" ? "localhost" : result.server.host}:${result.server.piPort}`;
|
|
3832
|
+
// fix-bridge-mdns-migration-hijack: a DISCOVERED candidate only
|
|
3833
|
+
// SUGGESTS. Whether the connection follows it is decided — and
|
|
3834
|
+
// recorded — by `ConnectionManager.retargetTo`, which refuses to
|
|
3835
|
+
// drop an established, registered connection until the candidate has
|
|
3836
|
+
// PROVEN reachable (`GET /api/health` → `{ok:true}`, D1), honours
|
|
3837
|
+
// localhost preference against a remote candidate (D3), and returns
|
|
3838
|
+
// to the last registered endpoint if the candidate dies after
|
|
3839
|
+
// adoption (D2). The blanket refusal this replaces also blocked
|
|
3840
|
+
// every LEGITIMATE migration (a server that really moved).
|
|
3841
|
+
if (endpointPinned) {
|
|
3842
|
+
// D3 (add-pi-gateway-transport-identity): a pinned endpoint
|
|
3843
|
+
// refuses every re-target. The refusal stays on the record (10.2).
|
|
3844
|
+
const decision = decideRetarget({
|
|
3845
|
+
current: { endpoint: dashboardUrl, instanceId: registeredInstanceId },
|
|
3846
|
+
candidate: { endpoint: candidateUrl },
|
|
3847
|
+
pinned: true,
|
|
3848
|
+
failed: false,
|
|
3849
|
+
identityVerified: false,
|
|
3850
|
+
});
|
|
3851
|
+
const refusedDetail = `${dashboardUrl} -> ${candidateUrl}: ${decision.reason}`;
|
|
3852
|
+
console.log(`[dashboard] re-target ${refusedDetail}`);
|
|
3853
|
+
transportDiagnostics.record({ event: "retarget_refused", detail: refusedDetail });
|
|
3854
|
+
return;
|
|
3855
|
+
}
|
|
3856
|
+
const trigger = `mdns discovery (${result.server.host}:${result.server.port}, gateway ${result.server.piPort})`;
|
|
3857
|
+
// The health probe runs on the candidate's HTTP port — the record's
|
|
3858
|
+
// `port`, not the gateway port — and completes BEFORE the incumbent
|
|
3859
|
+
// is dropped (retargetTo owns that ordering).
|
|
3860
|
+
const healthUrl = `http://${result.server.host}:${result.server.port}/api/health`;
|
|
3861
|
+
connection
|
|
3862
|
+
.retargetTo(candidateUrl, {
|
|
3863
|
+
trigger,
|
|
3864
|
+
verify: () => probeEndpointReachability({ healthUrl }),
|
|
3865
|
+
})
|
|
3866
|
+
.then((accepted) => {
|
|
3867
|
+
console.log(`[dashboard] re-target ${dashboardUrl} -> ${candidateUrl}: ${accepted ? "accepted" : "refused by migration gate"}`);
|
|
3868
|
+
})
|
|
3869
|
+
.catch((err: unknown) => console.error("[dashboard] re-target decision failed:", err));
|
|
2574
3870
|
}
|
|
2575
3871
|
}).catch(() => { stopSpinner(); });
|
|
2576
3872
|
|
|
2577
|
-
// Send initial git info + the session's pi version
|
|
2578
|
-
|
|
3873
|
+
// Send initial git info + the session's pi version. A session change already
|
|
3874
|
+
// ran the first evaluation (and renewed the tracker) in handleSessionChange;
|
|
3875
|
+
// doing it again would double the synchronous git work.
|
|
3876
|
+
if (!sessionChanged) {
|
|
3877
|
+
const gbc = syncBc();
|
|
3878
|
+
renewGitTracker().evaluateFirst(gbc, startCwd);
|
|
3879
|
+
applyBc(gbc);
|
|
3880
|
+
}
|
|
2579
3881
|
sendCwdMissingIfChanged(startCwd);
|
|
2580
3882
|
sendPiVersionIfChanged();
|
|
2581
3883
|
|
|
@@ -2586,10 +3888,38 @@ function initBridge(pi: ExtensionAPI) {
|
|
|
2586
3888
|
connection.send({
|
|
2587
3889
|
type: "session_heartbeat",
|
|
2588
3890
|
sessionId,
|
|
3891
|
+
// Liveness truth for the server's status reconcile: `streaming` is
|
|
3892
|
+
// otherwise a one-way latch and a single dropped `agent_end` sticks
|
|
3893
|
+
// the card on `Thinking…` forever.
|
|
3894
|
+
// `=== true` because the flag is optional and is `undefined` before
|
|
3895
|
+
// the first turn: sent raw it would serialize away and read as "old
|
|
3896
|
+
// bridge, no liveness truth" instead of "idle".
|
|
3897
|
+
// See change: fix-stuck-streaming-status-latch.
|
|
3898
|
+
agentRunning: getBridgeState().isAgentStreaming === true,
|
|
2589
3899
|
// Fold the bridge→server ring-buffer eviction count into the heartbeat
|
|
2590
3900
|
// so it reaches `/api/health`. See change:
|
|
2591
3901
|
// fix-stuck-tool-card-on-dropped-event.
|
|
2592
|
-
metrics: {
|
|
3902
|
+
metrics: {
|
|
3903
|
+
...collectMetrics(),
|
|
3904
|
+
droppedBufferedFrames: connection.getDroppedBufferedCount(),
|
|
3905
|
+
refusedInboundFrames: connection.getDroppedInboundCount(),
|
|
3906
|
+
// Subagent-tick throttle counters ride the same transport, so the
|
|
3907
|
+
// throttle's two information-loss modes are observable in production
|
|
3908
|
+
// instead of only at L1. See change: reduce-bridge-tick-bandwidth (D6).
|
|
3909
|
+
...subagentTickThrottle.stats,
|
|
3910
|
+
// Subagent fan-out admission counters ride the same transport, so a
|
|
3911
|
+
// narrowed fan-out is observable instead of looking like a model that
|
|
3912
|
+
// chose not to parallelize. See change:
|
|
3913
|
+
// bound-subagent-fanout-under-host-pressure (D7).
|
|
3914
|
+
...fanoutAdmission.counters,
|
|
3915
|
+
// Agent path gate counters (in-root decisions are counted, not logged).
|
|
3916
|
+
pathGateInRoot: pathGate.counters.inRoot,
|
|
3917
|
+
pathGateAsked: pathGate.counters.asked,
|
|
3918
|
+
pathGateBlocked: pathGate.counters.blocked,
|
|
3919
|
+
// Poll-cost counters (summed across sessions on /api/health).
|
|
3920
|
+
// See change: optimize-polling-hot-paths.
|
|
3921
|
+
...pollCost,
|
|
3922
|
+
},
|
|
2593
3923
|
});
|
|
2594
3924
|
}, HEARTBEAT_INTERVAL);
|
|
2595
3925
|
getBridgeState().timers!.push(heartbeatTimer);
|
|
@@ -2597,27 +3927,37 @@ function initBridge(pi: ExtensionAPI) {
|
|
|
2597
3927
|
// Start git + name/model polling
|
|
2598
3928
|
startGitPollTimer(ctx);
|
|
2599
3929
|
|
|
2600
|
-
// Start process scanner (detect stalled child processes)
|
|
2601
|
-
//
|
|
2602
|
-
|
|
2603
|
-
|
|
2604
|
-
|
|
2605
|
-
|
|
2606
|
-
|
|
2607
|
-
|
|
2608
|
-
|
|
2609
|
-
)
|
|
2610
|
-
|
|
2611
|
-
|
|
3930
|
+
// Start the adaptive process scanner (detect stalled child processes).
|
|
3931
|
+
// One async `ps -A` per scan; fast while the agent/tools run, idle
|
|
3932
|
+
// otherwise. session_start re-runs: dispose the previous scheduler first so
|
|
3933
|
+
// schedules never stack. See change: optimize-polling-hot-paths.
|
|
3934
|
+
ensurePollingDisposable();
|
|
3935
|
+
const scheduler = createProcessScanScheduler({
|
|
3936
|
+
platform: process.platform,
|
|
3937
|
+
setTimer: setRegisteredTimeout,
|
|
3938
|
+
clearTimer: clearRegisteredTimeout,
|
|
3939
|
+
scan: async () => {
|
|
3940
|
+
if (!isActive()) return { changed: false };
|
|
3941
|
+
const processes = await scanChildProcessesAsync(
|
|
3942
|
+
process.pid,
|
|
3943
|
+
trackedPgids,
|
|
3944
|
+
PROCESS_MIN_ELAPSED_MS,
|
|
3945
|
+
{ excludedPgids: selfSpawnedPgids },
|
|
3946
|
+
);
|
|
3947
|
+
if (!isActive() || polling.processScan !== scheduler) return { changed: false };
|
|
3948
|
+
const currentPids = JSON.stringify(processes.map((p) => p.pid).sort());
|
|
3949
|
+
if (currentPids === previousProcessPids) return { changed: false };
|
|
2612
3950
|
previousProcessPids = currentPids;
|
|
2613
3951
|
connection.send({
|
|
2614
3952
|
type: "process_list",
|
|
2615
3953
|
sessionId,
|
|
2616
3954
|
processes: processes.map((p) => ({ pid: p.pid, pgid: p.pgid, command: p.command, elapsedMs: p.elapsedMs })),
|
|
2617
3955
|
});
|
|
2618
|
-
|
|
2619
|
-
|
|
2620
|
-
|
|
3956
|
+
return { changed: true };
|
|
3957
|
+
},
|
|
3958
|
+
});
|
|
3959
|
+
polling.replaceProcessScan(scheduler);
|
|
3960
|
+
scheduler.start();
|
|
2621
3961
|
|
|
2622
3962
|
// Register flow event listeners (pi-flows emits these via pi.events)
|
|
2623
3963
|
registerFlowEventListeners(syncBc(), () => sessionReady, getFlowsList);
|
|
@@ -2631,7 +3971,7 @@ function initBridge(pi: ExtensionAPI) {
|
|
|
2631
3971
|
}));
|
|
2632
3972
|
|
|
2633
3973
|
// Shared handler for session changes (new/fork/resume)
|
|
2634
|
-
function handleSessionChange(ctx: any) {
|
|
3974
|
+
function handleSessionChange(ctx: any, usageSeed?: ReturnType<UsageDrain["baseline"]>) {
|
|
2635
3975
|
// Clear attachedChange on a real session switch (new/fork/resume): it is
|
|
2636
3976
|
// persisted globally + restored at activate, so without this the previous
|
|
2637
3977
|
// session's attached change would leak into the new session's prompt until
|
|
@@ -2643,20 +3983,45 @@ function initBridge(pi: ExtensionAPI) {
|
|
|
2643
3983
|
// new/fork/resumed session's subagents are unrelated to the outgoing one.
|
|
2644
3984
|
// See change: fix-subagent-live-detail-reliability.
|
|
2645
3985
|
subagentFrameBuffer.reset();
|
|
3986
|
+
// Same disposal point for the tick throttle: clear every armed trailing
|
|
3987
|
+
// timer and drop every held frame, so nothing from the outgoing session
|
|
3988
|
+
// can fire against the new one.
|
|
3989
|
+
// See change: reduce-bridge-tick-bandwidth (D3).
|
|
3990
|
+
subagentTickThrottle.reset();
|
|
3991
|
+
// A session boundary invalidates the CONTENT itself (unlike a reconnect), so
|
|
3992
|
+
// drop any parked text snapshot and cancel its window rather than flushing
|
|
3993
|
+
// it into the new session. See change:
|
|
3994
|
+
// coalesce-bridge-message-update-snapshots (D8).
|
|
3995
|
+
coalescer.clear();
|
|
2646
3996
|
// Clear the stop-after-turn latch so a new/fork/resumed session does not
|
|
2647
3997
|
// inherit the previous session's pending graceful-stop and shut down on
|
|
2648
3998
|
// its first turn_end. See change: adopt-pi-071-072-073-features.
|
|
2649
3999
|
getBridgeState().shouldStopAfterTurn = false;
|
|
4000
|
+
// Drop the auto-namer and its carried state: it is a PER-SESSION state
|
|
4001
|
+
// machine, so a new/fork/resumed session must not inherit the outgoing
|
|
4002
|
+
// session's permanent stop, spent attempt budget or auto-named flag — it
|
|
4003
|
+
// would report `stopped` / `already-named` without ever attempting to name.
|
|
4004
|
+
// The server re-pushes the incoming session's own persisted state on its
|
|
4005
|
+
// session_register. See change: fix-auto-naming-reasoning-model.
|
|
4006
|
+
autoNamer = undefined;
|
|
4007
|
+
namerState = undefined;
|
|
4008
|
+
prev.namerState = undefined;
|
|
2650
4009
|
// Bridge shadow queues reset on session change so the new session
|
|
2651
4010
|
// starts with empty chips. See change: add-followup-edit-and-steer-cancel.
|
|
2652
4011
|
if (bridgeSteering.length > 0 || bridgeFollowUp.length > 0) {
|
|
2653
4012
|
bridgeSteering = [];
|
|
2654
|
-
|
|
4013
|
+
// Drops every entry AND its image bytes, releasing the byte budget.
|
|
4014
|
+
bridgeFollowUp.reset();
|
|
2655
4015
|
emitQueueUpdate();
|
|
2656
4016
|
}
|
|
4017
|
+
renewGitTracker();
|
|
2657
4018
|
const bc = syncBc();
|
|
2658
|
-
_handleSessionChange(bc, ctx, getFlowsList);
|
|
4019
|
+
_handleSessionChange(bc, ctx, getFlowsList, usageSeed);
|
|
2659
4020
|
applyBc(bc);
|
|
4021
|
+
// A new session id needs its own `pi_version_update` (below-floor flag).
|
|
4022
|
+
// After applyBc, so syncBc() carries the NEW session id.
|
|
4023
|
+
// See change: update-pi-core-1-0-adopt-apis.
|
|
4024
|
+
sendPiVersionIfChanged();
|
|
2660
4025
|
|
|
2661
4026
|
// Restart polling timers
|
|
2662
4027
|
startGitPollTimer(ctx);
|
|
@@ -2671,15 +4036,25 @@ function initBridge(pi: ExtensionAPI) {
|
|
|
2671
4036
|
// connection.connect(); an un-guarded ctx.cwd throw here skips connect()
|
|
2672
4037
|
// (#393). See change: fix-bridge-resume-disconnect.
|
|
2673
4038
|
cachedCwd = safeCwd(ctx);
|
|
2674
|
-
|
|
2675
|
-
|
|
2676
|
-
|
|
2677
|
-
|
|
2678
|
-
|
|
2679
|
-
|
|
2680
|
-
|
|
2681
|
-
|
|
2682
|
-
|
|
4039
|
+
const pollState = createGitPollState();
|
|
4040
|
+
gitPollTimer = setInterval(() => {
|
|
4041
|
+
// runGitPollTick handles a rejecting git tick itself; this catch is the
|
|
4042
|
+
// last line so the interval callback can never raise an unhandled rejection.
|
|
4043
|
+
runGitPollTick({
|
|
4044
|
+
isActive,
|
|
4045
|
+
cachedCwd: () => cachedCwd,
|
|
4046
|
+
tickGit: (cwd) => {
|
|
4047
|
+
const gbc = syncBc();
|
|
4048
|
+
polling.gitTracker?.tick(gbc, cwd);
|
|
4049
|
+
applyBc(gbc);
|
|
4050
|
+
},
|
|
4051
|
+
sendCwdMissingIfChanged,
|
|
4052
|
+
sendSessionNameIfChanged,
|
|
4053
|
+
sendModelUpdateIfChanged,
|
|
4054
|
+
sendPiVersionIfChanged: () => _sendPiVersionIfChanged(syncBc()),
|
|
4055
|
+
state: pollState,
|
|
4056
|
+
}).catch((err) => console.error("[dashboard] git poll tick failed:", err));
|
|
4057
|
+
}, GIT_POLL_INTERVAL);
|
|
2683
4058
|
getBridgeState().timers!.push(gitPollTimer);
|
|
2684
4059
|
}
|
|
2685
4060
|
|
|
@@ -2690,6 +4065,9 @@ function initBridge(pi: ExtensionAPI) {
|
|
|
2690
4065
|
if (!isActive()) return;
|
|
2691
4066
|
cachedCtx = ctx;
|
|
2692
4067
|
if (!sessionReady) return;
|
|
4068
|
+
// Drain point: compaction / usage entries recorded during the turn.
|
|
4069
|
+
// See change: count-non-message-usage.
|
|
4070
|
+
drainUsage(ctx);
|
|
2693
4071
|
|
|
2694
4072
|
// Send firstMessage update after first turn if not previously sent
|
|
2695
4073
|
if (!lastFirstMessage) {
|
|
@@ -2706,8 +4084,24 @@ function initBridge(pi: ExtensionAPI) {
|
|
|
2706
4084
|
|
|
2707
4085
|
}));
|
|
2708
4086
|
|
|
2709
|
-
|
|
4087
|
+
// Control event (never `event_forward`): an idle cache refresh's usage
|
|
4088
|
+
// entry lands before the NEXT decision, so each decision is a drain point.
|
|
4089
|
+
// Observe-only — returns no override and never throws (pi falls back to
|
|
4090
|
+
// its own decision on a handler failure, but we never give it one).
|
|
4091
|
+
// See change: count-non-message-usage.
|
|
4092
|
+
pi.on("cache_warming_decision", makeCacheWarmingDecisionHandler((ctx: any) => {
|
|
4093
|
+
if (!isActive()) return;
|
|
4094
|
+
drainUsage(ctx);
|
|
4095
|
+
}) as any);
|
|
4096
|
+
|
|
4097
|
+
pi.on("session_shutdown", safe(async (event: any, ctx: any) => {
|
|
2710
4098
|
if (!isActive()) return;
|
|
4099
|
+
// Let the reloaded instance (fresh ExtensionAPI) pass the re-entry guard.
|
|
4100
|
+
// See change: fix-terminal-session-dashboard-reload (D4).
|
|
4101
|
+
releaseBridgeOwnerOnShutdown(getBridgeState(), event?.reason);
|
|
4102
|
+
// Remove this session's pi-dashboard MCP registration (a reloaded
|
|
4103
|
+
// instance re-registers on its own mint). See change: migrate-mcp-to-pi-builtin (D1).
|
|
4104
|
+
mcpRegistrar.onSessionShutdown();
|
|
2711
4105
|
getBridgeState().isAgentStreaming = false;
|
|
2712
4106
|
stopMetricsMonitor();
|
|
2713
4107
|
if (heartbeatTimer) {
|
|
@@ -2718,14 +4112,26 @@ function initBridge(pi: ExtensionAPI) {
|
|
|
2718
4112
|
clearInterval(gitPollTimer);
|
|
2719
4113
|
gitPollTimer = null;
|
|
2720
4114
|
}
|
|
2721
|
-
|
|
2722
|
-
|
|
2723
|
-
|
|
2724
|
-
|
|
4115
|
+
drainDisposables(getBridgeState());
|
|
4116
|
+
// Flush undrained entry usage BEFORE session_unregister (which ends the
|
|
4117
|
+
// session server-side), on every shutdown reason: quit, reload and
|
|
4118
|
+
// session replacement (new/resume/fork). See change: count-non-message-usage.
|
|
4119
|
+
sendShutdownUsageThenUnregister(
|
|
4120
|
+
() => drainUsage(ctx),
|
|
4121
|
+
() => connection.send({
|
|
4122
|
+
type: "session_unregister",
|
|
4123
|
+
sessionId,
|
|
4124
|
+
}),
|
|
4125
|
+
);
|
|
2725
4126
|
|
|
2726
4127
|
// Drop retained subagent frames/snapshots on shutdown.
|
|
2727
4128
|
// See change: fix-subagent-live-detail-reliability.
|
|
2728
4129
|
subagentFrameBuffer.reset();
|
|
4130
|
+
// See change: reduce-bridge-tick-bandwidth (D3).
|
|
4131
|
+
subagentTickThrottle.reset();
|
|
4132
|
+
// A shutdown is a session boundary: discard parked text, cancel the window.
|
|
4133
|
+
// See change: coalesce-bridge-message-update-snapshots (D8).
|
|
4134
|
+
coalescer.clear();
|
|
2729
4135
|
|
|
2730
4136
|
// Best-effort: remove this session's pasted ask_user attachments.
|
|
2731
4137
|
// See change: add-ask-user-input-multiline-paste.
|
|
@@ -2765,6 +4171,11 @@ function initBridge(pi: ExtensionAPI) {
|
|
|
2765
4171
|
s.hasUI = cachedHasUI;
|
|
2766
4172
|
if (heartbeatTimer) { clearInterval(heartbeatTimer); heartbeatTimer = null; }
|
|
2767
4173
|
if (gitPollTimer) { clearInterval(gitPollTimer); gitPollTimer = null; }
|
|
4174
|
+
drainDisposables(s);
|
|
4175
|
+
// Disable the admission sampler's private event-loop histogram. A bridge
|
|
4176
|
+
// re-init (/reload, session replacement) constructs a fresh sampler; without
|
|
4177
|
+
// this the superseded 20 ms-resolution monitor runs until process exit.
|
|
4178
|
+
admissionSampler.dispose();
|
|
2768
4179
|
|
|
2769
4180
|
// Dev build & restart: rebuild client and stop server before reload
|
|
2770
4181
|
if (config.devBuildOnReload) {
|
|
@@ -2774,10 +4185,9 @@ function initBridge(pi: ExtensionAPI) {
|
|
|
2774
4185
|
runDevBuild({ packageRoot, serverPort: config.port });
|
|
2775
4186
|
}
|
|
2776
4187
|
|
|
2777
|
-
//
|
|
2778
|
-
|
|
2779
|
-
|
|
2780
|
-
}
|
|
4188
|
+
// Release our EventBus subscriptions. Nothing to "restore": the bridge no
|
|
4189
|
+
// longer replaces any host function. See change: fix-automation-run-lifecycle.
|
|
4190
|
+
disposeEventBusForwarding();
|
|
2781
4191
|
connection.disconnect();
|
|
2782
4192
|
};
|
|
2783
4193
|
|