@blackbelt-technology/pi-agent-dashboard 0.11.0 → 0.12.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 +2 -0
- package/README.md +17 -12
- package/docs/architecture.md +973 -224
- package/package.json +29 -18
- package/packages/extension/package.json +16 -9
- package/packages/extension/src/bridge-context.ts +6 -0
- package/packages/extension/src/bridge-handlers/dispatch.ts +54 -69
- package/packages/extension/src/bridge-handlers/forwarders.ts +19 -42
- package/packages/extension/src/bridge-handlers/instance.ts +21 -12
- package/packages/extension/src/bridge-handlers/lifecycle.ts +84 -40
- package/packages/extension/src/bridge-shutdown.ts +44 -0
- package/packages/extension/src/bridge.ts +272 -260
- package/packages/extension/src/command-handler.ts +26 -31
- package/packages/extension/src/connection.ts +123 -31
- package/packages/extension/src/credential-guard.ts +300 -0
- package/packages/extension/src/custom-entry-forward.ts +27 -18
- package/packages/extension/src/default-model-apply.ts +83 -0
- package/packages/extension/src/flow-event-wiring.ts +19 -95
- package/packages/extension/src/followup-drain.ts +19 -5
- package/packages/extension/src/path-gate/decide.ts +68 -5
- package/packages/extension/src/path-gate/handler.ts +16 -8
- package/packages/extension/src/path-gate/index.ts +2 -2
- package/packages/extension/src/path-gate/roots.ts +15 -3
- package/packages/extension/src/path-gate/suppression.ts +3 -0
- package/packages/extension/src/pi-env.d.ts +8 -1
- package/packages/extension/src/pi-retry-settings.ts +11 -2
- package/packages/extension/src/plugin-event-forward-registry.ts +90 -14
- package/packages/extension/src/preview-path-link.ts +151 -0
- package/packages/extension/src/project-init/scaffold.ts +98 -35
- package/packages/extension/src/project-trust.ts +24 -15
- package/packages/extension/src/provider-model-cache.ts +118 -0
- package/packages/extension/src/provider-register.ts +428 -28
- package/packages/extension/src/retry-tracker.ts +90 -7
- package/packages/extension/src/role-manager.ts +4 -2
- package/packages/extension/src/role-model-tools.ts +21 -4
- package/packages/extension/src/server-auto-start.ts +68 -2
- package/packages/extension/src/server-launcher.ts +26 -8
- package/packages/extension/src/session-sync.ts +11 -12
- package/packages/extension/src/spawn-new-session.ts +22 -0
- package/packages/extension/src/steer-buffer.ts +164 -0
- package/packages/extension/src/stream-forward-buffer.ts +64 -15
- package/packages/extension/src/sudo-askpass/config-reader.ts +32 -0
- package/packages/extension/src/sudo-askpass/controller.ts +405 -0
- package/packages/extension/src/sudo-askpass/helper-script.ts +69 -0
- package/packages/extension/src/sudo-askpass/in-flight.ts +79 -0
- package/packages/extension/src/sudo-askpass/index.ts +11 -0
- package/packages/extension/src/sudo-askpass/install.ts +143 -0
- package/packages/extension/src/sudo-askpass/password-cache.ts +118 -0
- package/packages/extension/src/sudo-askpass/prompt-text.ts +55 -0
- package/packages/extension/src/sudo-askpass/protocol.ts +18 -0
- package/packages/extension/src/sudo-askpass/sudo-mask-registry.ts +52 -0
- package/packages/extension/src/terminal-reload.ts +19 -5
- package/packages/extension/src/tool-update-filter-registry.ts +210 -0
- package/packages/extension/src/vault-redaction.ts +4 -3
- package/packages/server/package.json +17 -14
- package/packages/server/src/access/access-denials.ts +8 -0
- package/packages/server/src/access/access-grants.ts +244 -58
- package/packages/server/src/access/access-plane.ts +7 -0
- package/packages/server/src/access/containment-gate.ts +66 -21
- package/packages/server/src/access/denial-hold.ts +3 -0
- package/packages/server/src/access/grant-coordinator.ts +17 -1
- package/packages/server/src/access/named-grant.ts +3 -0
- package/packages/server/src/access/pending-grant-registry.ts +32 -5
- package/packages/server/src/access/pi-trust-mirror-service.ts +7 -1
- package/packages/server/src/access/planes.ts +1 -0
- package/packages/server/src/access/verified-read.ts +24 -7
- package/packages/server/src/acp-bridge/acp-session-adapter.ts +10 -2
- package/packages/server/src/acp-bridge/server-requests.ts +10 -4
- package/packages/server/src/agent-events/agent-event-hub.ts +1 -1
- package/packages/server/src/auth/audit-log.ts +28 -0
- package/packages/server/src/auth/auth-plugin.ts +188 -15
- package/packages/server/src/auth/auth.ts +80 -0
- package/packages/server/src/auth/bridge-ticket-eligibility.ts +53 -10
- package/packages/server/src/auth/cors-origin.ts +14 -1
- package/packages/server/src/auth/credential-envelope.ts +233 -0
- package/packages/server/src/auth/credential-key-worker.d.mts +16 -0
- package/packages/server/src/auth/credential-key-worker.mjs +108 -0
- package/packages/server/src/auth/credential-key.ts +479 -0
- package/packages/server/src/auth/credential-migration.ts +162 -0
- package/packages/server/src/auth/csp-report-paths.ts +0 -5
- package/packages/server/src/auth/csp.ts +74 -36
- package/packages/server/src/auth/device-proof.ts +202 -0
- package/packages/server/src/auth/duplicate-cookie-gate.ts +271 -0
- package/packages/server/src/auth/host-admission.ts +7 -0
- package/packages/server/src/auth/host-gate.ts +13 -2
- package/packages/server/src/auth/localhost-guard.ts +50 -23
- package/packages/server/src/auth/locked-json-file.ts +68 -6
- package/packages/server/src/auth/models-json-store.ts +269 -0
- package/packages/server/src/auth/mutation-origin-gate.ts +5 -2
- package/packages/server/src/auth/node-guard.ts +36 -49
- package/packages/server/src/auth/plugin-credential-store.ts +81 -10
- package/packages/server/src/auth/provider-auth-storage.ts +208 -11
- package/packages/server/src/auth/provider-block-checks.ts +321 -0
- package/packages/server/src/auth/provider-host-detect.ts +151 -0
- package/packages/server/src/auth/provider-key-file.ts +71 -0
- package/packages/server/src/auth/provider-readiness.ts +91 -0
- package/packages/server/src/auth/route-tier-gate.ts +3 -2
- package/packages/server/src/auth/vertex-key-check.ts +140 -0
- package/packages/server/src/auth/ws-ticket.ts +1 -1
- package/packages/server/src/browse.ts +73 -20
- package/packages/server/src/browser-handlers/acp-guard.ts +1 -4
- package/packages/server/src/browser-handlers/directory-handler.ts +11 -24
- package/packages/server/src/browser-handlers/session-action-handler.ts +158 -62
- package/packages/server/src/browser-handlers/spawn-choice.ts +138 -1
- package/packages/server/src/browser-handlers/subscription-handler.ts +46 -1
- package/packages/server/src/build-plugin-send-prompt.ts +18 -0
- package/packages/server/src/cli/credentials-command.ts +555 -0
- package/packages/server/src/cli.ts +21 -16
- package/packages/server/src/config-api.ts +34 -38
- package/packages/server/src/config-snapshot.ts +149 -0
- package/packages/server/src/directory-service.ts +33 -14
- package/packages/server/src/embed-lifecycle/idle-reaper.ts +13 -3
- package/packages/server/src/event-wiring.ts +181 -101
- package/packages/server/src/git-worktree/ensure-worktree.ts +185 -0
- package/packages/server/src/git-worktree/git-operations.ts +1 -1
- package/packages/server/src/git-worktree/repo-lock.ts +42 -0
- package/packages/server/src/git-worktree/start-worktree-init.ts +151 -0
- package/packages/server/src/git-worktree/worktree-init.ts +5 -1
- package/packages/server/src/identity/http-road-classification.ts +5 -1
- package/packages/server/src/identity/identity-floor.ts +5 -2
- package/packages/server/src/identity/ws-message-scope.ts +10 -3
- package/packages/server/src/identity/ws-road-classification.ts +2 -1
- package/packages/server/src/lib/browse-roots.ts +13 -2
- package/packages/server/src/lib/content-disposition.ts +20 -0
- package/packages/server/src/lib/dashboard-state-guard.ts +304 -21
- package/packages/server/src/lib/eml.ts +2 -2
- package/packages/server/src/lib/frame-policy-probe.ts +308 -0
- package/packages/server/src/lib/frame-policy-test-seam.ts +99 -0
- package/packages/server/src/lib/frame-policy-verdict.ts +125 -0
- package/packages/server/src/lib/grep.ts +4 -1
- package/packages/server/src/lib/index-html.ts +2 -2
- package/packages/server/src/lib/mention-fuzzy-index.ts +263 -0
- package/packages/server/src/lib/office-preview.ts +47 -10
- package/packages/server/src/lib/path-containment.ts +45 -12
- package/packages/server/src/lib/resolve-file-mention.ts +230 -38
- package/packages/server/src/lib/resolve-mentions-batch.ts +143 -0
- package/packages/server/src/lib/writable-handler-target.ts +4 -0
- package/packages/server/src/lib/writable-md-target.ts +22 -0
- package/packages/server/src/lifecycle/boot-parent-liveness.ts +10 -25
- package/packages/server/src/lifecycle/credential-exit-barrier.ts +207 -0
- package/packages/server/src/lifecycle/exit-signal.ts +43 -0
- package/packages/server/src/live-server/capability-redact.ts +21 -5
- package/packages/server/src/live-server/live-capability.ts +416 -52
- package/packages/server/src/live-server/live-csp-report.ts +1 -1
- package/packages/server/src/live-server/live-csp.ts +64 -16
- package/packages/server/src/live-server/live-log.ts +5 -1
- package/packages/server/src/live-server/live-server-manager.ts +11 -0
- package/packages/server/src/live-server/live-server-proxy.ts +268 -52
- package/packages/server/src/live-server/live-static.ts +4 -1
- package/packages/server/src/live-server/preview-dispatch.ts +286 -0
- package/packages/server/src/live-server/preview-observe.ts +53 -0
- package/packages/server/src/live-server/preview-origin.ts +182 -0
- package/packages/server/src/live-server/preview-path-bridge.ts +70 -0
- package/packages/server/src/live-server/preview-path-store.ts +420 -0
- package/packages/server/src/live-server/preview-path.ts +40 -0
- package/packages/server/src/live-server/preview-pool.ts +385 -0
- package/packages/server/src/live-server/preview-preflight.ts +41 -0
- package/packages/server/src/live-server/preview-reserve.ts +44 -0
- package/packages/server/src/live-server/preview-tier.ts +217 -0
- package/packages/server/src/live-server/preview-viewers.ts +54 -0
- package/packages/server/src/live-server/preview-ws-registry.ts +43 -0
- package/packages/server/src/model-proxy/custom-provider-discovery.ts +4 -2
- package/packages/server/src/model-proxy/internal-auth-storage.ts +5 -1
- package/packages/server/src/model-proxy/internal-registry.ts +283 -21
- package/packages/server/src/model-proxy/models-block-apply.ts +291 -0
- package/packages/server/src/model-proxy/pi-models-validator.ts +164 -0
- package/packages/server/src/model-proxy/registry-singleton.ts +44 -9
- package/packages/server/src/model-proxy/server-model-runtime.ts +17 -0
- package/packages/server/src/openspec/readiness.ts +1 -1
- package/packages/server/src/package/provider-probe.ts +194 -5
- package/packages/server/src/pairing/browser-gateway.ts +140 -42
- package/packages/server/src/pairing/device-key-intake.ts +120 -0
- package/packages/server/src/pairing/paired-devices.ts +370 -8
- package/packages/server/src/pairing/pairing.ts +69 -7
- package/packages/server/src/pairing/{subagent-resync-routing.ts → resync-requester-registry.ts} +6 -10
- package/packages/server/src/pairing/ws-tier-gate.ts +74 -0
- package/packages/server/src/pending/pending-attach-registry.ts +15 -0
- package/packages/server/src/pending/pending-initial-prompt-registry.ts +15 -0
- package/packages/server/src/persistence/memory-event-store.ts +251 -296
- package/packages/server/src/persistence/preferences-store.ts +52 -2
- package/packages/server/src/pi/bridge-contention.ts +84 -2
- package/packages/server/src/pi/host-project-trust.ts +15 -9
- package/packages/server/src/pi/pi-gateway.ts +208 -21
- package/packages/server/src/pi/provisional-registration.ts +4 -1
- package/packages/server/src/pi/resource-toggle-trust.ts +17 -6
- package/packages/server/src/pi-agent-settings.ts +95 -301
- package/packages/server/src/pi-default-remirror.ts +89 -0
- package/packages/server/src/plugin-append-event.ts +35 -0
- package/packages/server/src/plugin-entry-stats.ts +61 -0
- package/packages/server/src/plugin-local-request.ts +207 -0
- package/packages/server/src/plugin-ownership.ts +111 -0
- package/packages/server/src/plugin-policy-registry.ts +297 -0
- package/packages/server/src/plugin-request-lane.ts +92 -16
- package/packages/server/src/preferences-relay.ts +20 -0
- package/packages/server/src/project-seed.ts +347 -0
- package/packages/server/src/push/push-transports/webhook-url.ts +8 -5
- package/packages/server/src/questions/question-store.ts +3 -2
- package/packages/server/src/routes/access-routes.ts +23 -6
- package/packages/server/src/routes/acme-routes.ts +14 -4
- package/packages/server/src/routes/agent-event-stream-routes.ts +1 -1
- package/packages/server/src/routes/file-routes.ts +327 -86
- package/packages/server/src/routes/file-write-binary-routes.ts +20 -4
- package/packages/server/src/routes/frame-policy-routes.ts +215 -0
- package/packages/server/src/routes/git-routes.ts +29 -78
- package/packages/server/src/routes/grep-routes.ts +26 -0
- package/packages/server/src/routes/live-server-routes.ts +198 -4
- package/packages/server/src/routes/models-introspection-routes.ts +1 -1
- package/packages/server/src/routes/openspec-routes.ts +17 -3
- package/packages/server/src/routes/pairing-routes.ts +200 -11
- package/packages/server/src/routes/pi-settings-routes.ts +2 -0
- package/packages/server/src/routes/preferences-auto-name-routes.ts +5 -2
- package/packages/server/src/routes/preferences-claude-compat-routes.ts +49 -0
- package/packages/server/src/routes/provider-auth-routes.ts +167 -9
- package/packages/server/src/routes/provider-override-routes.ts +158 -0
- package/packages/server/src/routes/provider-routes.ts +348 -86
- package/packages/server/src/routes/session-routes.ts +25 -22
- package/packages/server/src/routes/system-routes.ts +87 -39
- package/packages/server/src/rpc-keeper/keeper-manager.ts +196 -25
- package/packages/server/src/rpc-keeper/keeper.cjs +37 -23
- package/packages/server/src/runtime-overlay/extension-reload.ts +16 -10
- package/packages/server/src/runtime-overlay/runtime-stager.ts +4 -2
- package/packages/server/src/server.ts +512 -175
- package/packages/server/src/services/cli-service.ts +59 -10
- package/packages/server/src/services/secrets-resolver.ts +46 -30
- package/packages/server/src/session/custom-event-group-annotation.ts +3 -3
- package/packages/server/src/session/custom-event-group-resolver.ts +10 -5
- package/packages/server/src/session/death-reason.ts +11 -7
- package/packages/server/src/session/event-status-extraction.ts +5 -1
- package/packages/server/src/session/memory-session-manager.ts +24 -2
- package/packages/server/src/session/open-tool-calls.ts +81 -47
- package/packages/server/src/session/pid-target.ts +127 -0
- package/packages/server/src/session/replay-compaction.ts +18 -5
- package/packages/server/src/session/seed-discovered-history.ts +85 -0
- package/packages/server/src/session/server-pid-context.ts +14 -0
- package/packages/server/src/session/session-api.ts +78 -29
- package/packages/server/src/session/session-archive.ts +7 -0
- package/packages/server/src/session/session-bootstrap.ts +9 -54
- package/packages/server/src/session/session-load-worker-pool.ts +11 -1
- package/packages/server/src/session/session-load-worker.ts +22 -3
- package/packages/server/src/spawn-process/abort-spawned-run.ts +28 -9
- package/packages/server/src/spawn-process/acp-spawn.ts +8 -2
- package/packages/server/src/spawn-process/headless-pid-registry.ts +383 -72
- package/packages/server/src/spawn-process/link-register.ts +42 -0
- package/packages/server/src/spawn-process/plugin-spawn-choice.ts +48 -0
- package/packages/server/src/spawn-process/plugin-spawn-worktree.ts +290 -0
- package/packages/server/src/spawn-process/process-classifier.ts +8 -3
- package/packages/server/src/spawn-process/process-manager.ts +61 -6
- package/packages/server/src/spawn-process/restored-identity.ts +112 -0
- package/packages/server/src/spawn-process/session-terminator.ts +179 -18
- package/packages/server/src/spawn-process/spawn-env-contributors.ts +2 -1
- package/packages/server/src/spawn-process/spawn-failure-log.ts +9 -0
- package/packages/server/src/spawn-process/spawn-register-watchdog.ts +44 -19
- package/packages/server/src/sudo-credential/relay.ts +337 -0
- package/packages/server/src/terminal/terminal-gateway.ts +10 -0
- package/packages/server/src/tls/sources/acme/credentials.ts +3 -2
- package/packages/server/src/tls/sources/acme/runtime.ts +2 -1
- package/packages/server/src/vault/vault-delivery-hub.ts +17 -1
- package/packages/server/src/vault/vault-routes.ts +9 -2
- package/packages/server/src/vault/vault-store.ts +87 -24
- package/packages/server/vendor/xlsx/LICENSE +201 -0
- package/packages/server/vendor/xlsx/PROVENANCE.json +13 -0
- package/packages/server/vendor/xlsx/xlsx.d.mts +1065 -0
- package/packages/server/vendor/xlsx/xlsx.mjs +28228 -0
- package/packages/shared/package.json +4 -2
- package/packages/shared/src/agent-credential-files.ts +32 -0
- package/packages/shared/src/browser-protocol.ts +137 -57
- package/packages/shared/src/canvas-detect.ts +1 -1
- package/packages/shared/src/canvas-types.ts +2 -2
- package/packages/shared/src/config.ts +73 -136
- package/packages/shared/src/containment-guard.ts +14 -4
- package/packages/shared/src/credential-encryption.ts +87 -0
- package/packages/shared/src/custom-event-groups.ts +2 -0
- package/packages/shared/src/dashboard-plugin/claude-compat.ts +159 -0
- package/packages/shared/src/dashboard-plugin/host-api.ts +1 -1
- package/packages/shared/src/dashboard-plugin/manifest-types.ts +46 -0
- package/packages/shared/src/dashboard-plugin/plugin-status.ts +4 -3
- package/packages/shared/src/dashboard-plugin/replay-entry-types.ts +46 -0
- package/packages/shared/src/dashboard-plugin/slot-props.ts +2 -0
- package/packages/shared/src/dashboard-plugin/slot-types.ts +1 -1
- package/packages/shared/src/dashboard-plugin/ui-primitives.ts +11 -3
- package/packages/shared/src/device-key-proof.ts +309 -0
- package/packages/shared/src/event-forward-declaration.ts +85 -12
- package/packages/shared/src/forbidden-subjects.ts +126 -14
- package/packages/shared/src/heap-limits.ts +0 -30
- package/packages/shared/src/host-admission.ts +2 -1
- package/packages/shared/src/index.ts +7 -6
- package/packages/shared/src/live-server.ts +20 -0
- package/packages/shared/src/mcp/verb-tiers.generated.ts +1 -3
- package/packages/shared/src/models-json-reader.ts +41 -0
- package/packages/shared/src/network-denial-signal.ts +15 -0
- package/packages/shared/src/node-version.ts +63 -60
- package/packages/shared/src/pairing-knock-client.ts +92 -8
- package/packages/shared/src/pi-agent-settings-lock.ts +311 -0
- package/packages/shared/src/pi-path-compare.ts +31 -0
- package/packages/shared/src/pi-settings-schema.ts +52 -9
- package/packages/shared/src/pi-trust-mirror-snapshot.ts +16 -4
- package/packages/shared/src/pi-trust-mirror-types.ts +2 -0
- package/packages/shared/src/pi-trust-mirror.ts +18 -8
- package/packages/shared/src/pi-trust-resource-digest.ts +18 -12
- package/packages/shared/src/pid-namespace.ts +86 -0
- package/packages/shared/src/platform/native-ts-register.mjs +1 -1
- package/packages/shared/src/platform/process.ts +404 -1
- package/packages/shared/src/platform/resolve-pi-shell.ts +38 -9
- package/packages/shared/src/platform/spawn-runtime.ts +193 -7
- package/packages/shared/src/preview-egress.ts +56 -2
- package/packages/shared/src/preview-origins.ts +398 -0
- package/packages/shared/src/prompt-answer.ts +9 -5
- package/packages/shared/src/protocol.ts +147 -85
- package/packages/shared/src/provider-env-catalog.ts +413 -0
- package/packages/shared/src/provider-overrides.ts +112 -0
- package/packages/shared/src/question-types.ts +6 -0
- package/packages/shared/src/recommended-extensions.ts +79 -26
- package/packages/shared/src/renderer-by-ext.ts +5 -2
- package/packages/shared/src/rest-api.ts +93 -3
- package/packages/shared/src/role-schema.ts +24 -0
- package/packages/shared/src/route-tiers.ts +94 -3
- package/packages/shared/src/runtime-overlay/compat.ts +70 -6
- package/packages/shared/src/secret-patterns.ts +49 -0
- package/packages/shared/src/source-matching.ts +2 -2
- package/packages/shared/src/state-replay.ts +40 -24
- package/packages/shared/src/sudo-credential.ts +71 -0
- package/packages/shared/src/tool-path-resolve.ts +16 -1
- package/packages/shared/src/tool-registry/strategies.ts +1 -1
- package/packages/shared/src/tool-workdir.ts +56 -0
- package/packages/shared/src/trusted-types-mode.ts +72 -0
- package/packages/shared/src/types.ts +68 -109
- package/packages/shared/src/vertex-regions.ts +81 -0
- package/packages/shared/src/ws-message-tiers.ts +10 -3
- package/packages/extension/src/subagent-fanout-admission.ts +0 -234
- package/packages/extension/src/subagent-forward-sites.ts +0 -69
- package/packages/extension/src/subagent-frame-buffer.ts +0 -245
- package/packages/extension/src/subagent-frame-strip.ts +0 -109
- package/packages/extension/src/subagent-saturation.ts +0 -196
- package/packages/extension/src/subagent-tick-throttle.ts +0 -252
- package/packages/shared/src/anthropic-messages-source.ts +0 -8
- package/packages/shared/src/dashboard-plugin/anthropic-peer-names.ts +0 -9
- package/packages/shared/src/dashboard-plugin/subagent-types.ts +0 -219
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Resolve WHICH pid namespace a session's recorded `pid` belongs to, before any
|
|
3
|
+
* probe, signal or pid-based link (design D2). The first matching rule wins:
|
|
4
|
+
*
|
|
5
|
+
* 1. `originDeviceId` ⇒ `foreign`.
|
|
6
|
+
* 2. A report is present (`null` = malformed ⇒ `unknown`, S7):
|
|
7
|
+
* - platform differs ⇒ `foreign`, except a Linux `kind:"wsl"` report to a
|
|
8
|
+
* win32 server ⇒ `{ wsl, distro }`;
|
|
9
|
+
* - Linux server: either side lacks `hostId`/`nsId` ⇒ `unknown`; `hostId` or
|
|
10
|
+
* `nsId` differs ⇒ `foreign`; else `host`;
|
|
11
|
+
* - macOS/Windows server: either side lacks `hostId` ⇒ `unknown` (S1);
|
|
12
|
+
* differs ⇒ `foreign`; else `host`.
|
|
13
|
+
* 3. No report (legacy bridge): `ownEntryPid === pid` ⇒ `host`; win32 with a
|
|
14
|
+
* POSIX-style cwd ⇒ `legacy-wsl`; other win32 ⇒ `unknown`; POSIX ⇒ `host`.
|
|
15
|
+
*
|
|
16
|
+
* Pure: no I/O per call (S10). `ServerPidContext` is computed once at startup.
|
|
17
|
+
* Link-time callers omit `ownEntryPid`, so linking is never circular.
|
|
18
|
+
* See change: scope-pids-to-namespace.
|
|
19
|
+
*/
|
|
20
|
+
import type { ServerPidContext } from "@blackbelt-technology/pi-dashboard-shared/pid-namespace.js";
|
|
21
|
+
import type { PidNamespace } from "@blackbelt-technology/pi-dashboard-shared/types.js";
|
|
22
|
+
|
|
23
|
+
export type { ServerPidContext } from "@blackbelt-technology/pi-dashboard-shared/pid-namespace.js";
|
|
24
|
+
|
|
25
|
+
export type PidTarget =
|
|
26
|
+
| { kind: "host" }
|
|
27
|
+
| { kind: "wsl"; distro: string }
|
|
28
|
+
| { kind: "legacy-wsl" }
|
|
29
|
+
| { kind: "foreign" }
|
|
30
|
+
| { kind: "unknown" };
|
|
31
|
+
|
|
32
|
+
/** The session fields resolution reads (a stored session or a register message). */
|
|
33
|
+
export interface PidTargetSession {
|
|
34
|
+
pid?: number;
|
|
35
|
+
cwd?: string;
|
|
36
|
+
originDeviceId?: string;
|
|
37
|
+
pidNamespace?: PidNamespace | null;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
const HOST: PidTarget = { kind: "host" };
|
|
41
|
+
const FOREIGN: PidTarget = { kind: "foreign" };
|
|
42
|
+
const UNKNOWN: PidTarget = { kind: "unknown" };
|
|
43
|
+
const LEGACY_WSL: PidTarget = { kind: "legacy-wsl" };
|
|
44
|
+
|
|
45
|
+
const CAP_PLATFORM = 32;
|
|
46
|
+
const CAP_DISTRO = 64;
|
|
47
|
+
const CAP_ID = 128;
|
|
48
|
+
|
|
49
|
+
function capped(v: unknown, cap: number): v is string {
|
|
50
|
+
return typeof v === "string" && v.length > 0 && v.length <= cap;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
function optionalCapped(o: Record<string, unknown>, key: string, cap: number): boolean {
|
|
54
|
+
return !(key in o) || o[key] === undefined || capped(o[key], cap);
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* Normalise a bridge-supplied `pidNamespace` (untrusted) for storage (S7):
|
|
59
|
+
* `undefined` ⇒ no report (legacy); a valid report ⇒ a fresh copy holding only
|
|
60
|
+
* the known fields; anything malformed or over the caps ⇒ `null` (an unusable
|
|
61
|
+
* report that resolves `unknown`). Never copies an oversized value.
|
|
62
|
+
*/
|
|
63
|
+
export function sanitizePidNamespace(raw: unknown): PidNamespace | null | undefined {
|
|
64
|
+
if (raw === undefined) return undefined;
|
|
65
|
+
if (raw === null || typeof raw !== "object" || Array.isArray(raw)) return null;
|
|
66
|
+
const o = raw as Record<string, unknown>;
|
|
67
|
+
if (!capped(o.platform, CAP_PLATFORM)) return null;
|
|
68
|
+
if (o.kind !== "host" && o.kind !== "wsl") return null;
|
|
69
|
+
if (o.kind === "wsl" && !capped(o.distro, CAP_DISTRO)) return null;
|
|
70
|
+
if (!optionalCapped(o, "distro", CAP_DISTRO)) return null;
|
|
71
|
+
if (!optionalCapped(o, "hostId", CAP_ID) || !optionalCapped(o, "nsId", CAP_ID)) return null;
|
|
72
|
+
const ns: PidNamespace = { platform: o.platform as string, kind: o.kind };
|
|
73
|
+
if (typeof o.distro === "string") ns.distro = o.distro;
|
|
74
|
+
if (typeof o.nsId === "string") ns.nsId = o.nsId;
|
|
75
|
+
if (typeof o.hostId === "string") ns.hostId = o.hostId;
|
|
76
|
+
return ns;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
export function resolvePidTarget(
|
|
80
|
+
session: PidTargetSession,
|
|
81
|
+
ctx: ServerPidContext,
|
|
82
|
+
ownEntryPid?: number,
|
|
83
|
+
): PidTarget {
|
|
84
|
+
// 1. Remote origin: another host's namespace, whatever the bridge reported.
|
|
85
|
+
if (session.originDeviceId) return FOREIGN;
|
|
86
|
+
|
|
87
|
+
const reported = session.pidNamespace;
|
|
88
|
+
if (reported !== undefined) {
|
|
89
|
+
// A stored report is re-validated (persisted JSON is not trusted either).
|
|
90
|
+
const ns = reported === null ? null : sanitizePidNamespace(reported);
|
|
91
|
+
if (!ns) return UNKNOWN;
|
|
92
|
+
// 2.1 Platform differs.
|
|
93
|
+
if (ns.platform !== ctx.platform) {
|
|
94
|
+
if (ctx.platform === "win32" && ns.platform === "linux" && ns.kind === "wsl" && ns.distro) {
|
|
95
|
+
return { kind: "wsl", distro: ns.distro };
|
|
96
|
+
}
|
|
97
|
+
return FOREIGN;
|
|
98
|
+
}
|
|
99
|
+
// 2.2 Linux server: boot id AND pid namespace.
|
|
100
|
+
if (ctx.platform === "linux") {
|
|
101
|
+
if (!ns.hostId || !ns.nsId || !ctx.hostId || !ctx.nsId) return UNKNOWN;
|
|
102
|
+
if (ns.hostId !== ctx.hostId || ns.nsId !== ctx.nsId) return FOREIGN;
|
|
103
|
+
return HOST;
|
|
104
|
+
}
|
|
105
|
+
// 2.3 macOS / Windows server: hostname only (weak, documented).
|
|
106
|
+
if (!ns.hostId || !ctx.hostId) return UNKNOWN;
|
|
107
|
+
return ns.hostId === ctx.hostId ? HOST : FOREIGN;
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
// 3. No report (legacy bridge).
|
|
111
|
+
if (ownEntryPid !== undefined && session.pid !== undefined && ownEntryPid === session.pid) return HOST;
|
|
112
|
+
if (ctx.platform === "win32") return session.cwd?.startsWith("/") ? LEGACY_WSL : UNKNOWN;
|
|
113
|
+
return HOST;
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
/** `wsl`, `legacy-wsl` or `foreign`: never probed, signalled or pid-linked. */
|
|
117
|
+
export function isNonLocalTarget(t: PidTarget): boolean {
|
|
118
|
+
return t.kind === "wsl" || t.kind === "legacy-wsl" || t.kind === "foreign";
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
/**
|
|
122
|
+
* May an OPERATOR path (shutdown, force-kill) signal this pid? `host` always;
|
|
123
|
+
* `unknown` only on a Windows server (Q8 — a legacy native Windows pi).
|
|
124
|
+
*/
|
|
125
|
+
export function operatorMaySignal(t: PidTarget, ctx: ServerPidContext): boolean {
|
|
126
|
+
return t.kind === "host" || (t.kind === "unknown" && ctx.platform === "win32");
|
|
127
|
+
}
|
|
@@ -33,8 +33,8 @@
|
|
|
33
33
|
* Because snapshots are CUMULATIVE, keeping only the last update before
|
|
34
34
|
* the tool start reproduces `streamingText` exactly.
|
|
35
35
|
*
|
|
36
|
-
*
|
|
37
|
-
*
|
|
36
|
+
* After the boundary, retain only the last of each originally adjacent run of
|
|
37
|
+
* full assistant text snapshots. Other events delimit runs and pass through.
|
|
38
38
|
*
|
|
39
39
|
* Seq values are NEVER rewritten — the client's `getEvents` filter tolerates
|
|
40
40
|
* gaps, and monotonicity is what the reset rule depends on. The caller must
|
|
@@ -53,14 +53,27 @@ function isThinkingUpdate(event: StoredEvent["event"]): boolean {
|
|
|
53
53
|
return typeof ame?.type === "string" && ame.type.startsWith("thinking");
|
|
54
54
|
}
|
|
55
55
|
|
|
56
|
+
function isTextSnapshot(event: StoredEvent["event"]): boolean {
|
|
57
|
+
if (event.eventType !== "message_update") return false;
|
|
58
|
+
const message = event.data?.message as { role?: unknown; content?: unknown } | null | undefined;
|
|
59
|
+
if (message?.role !== "assistant") return false;
|
|
60
|
+
const content = message.content;
|
|
61
|
+
if (typeof content !== "string" && !(Array.isArray(content) && content.every(
|
|
62
|
+
(block) => block !== null && typeof block === "object" && block.type === "text" && typeof block.text === "string",
|
|
63
|
+
))) return false;
|
|
64
|
+
const metadata = event.data?.assistantMessageEvent;
|
|
65
|
+
return metadata === undefined || (metadata !== null && typeof metadata === "object" &&
|
|
66
|
+
["text_start", "text_delta", "text_end"].includes((metadata as { type: string }).type));
|
|
67
|
+
}
|
|
68
|
+
|
|
56
69
|
/**
|
|
57
70
|
* Compact a replay window. Pure: returns a NEW array, never mutates the input
|
|
58
71
|
* or any event object (survivors are passed through by reference).
|
|
59
72
|
*
|
|
60
73
|
* `supersessionBoundaryIdx` (optional) is the index BEFORE which non-exempt
|
|
61
74
|
* `message_update` events are considered superseded. Omitted, it defaults to
|
|
62
|
-
* this array's own last `message_end
|
|
63
|
-
*
|
|
75
|
+
* this array's own last `message_end`. Indices refer to the original input.
|
|
76
|
+
* At or after the boundary, adjacent eligible text snapshots collapse to the last.
|
|
64
77
|
*
|
|
65
78
|
* A caller MUST supply it when compacting a SLICE of a larger stream: the
|
|
66
79
|
* derived boundary is array-relative, so a gap slice would keep updates whose
|
|
@@ -105,7 +118,6 @@ export function compactEventsForReplay(
|
|
|
105
118
|
// nothing-finalized-yet short-circuit: a slice with no `message_end` of its
|
|
106
119
|
// own is exactly the case the caller is correcting for.
|
|
107
120
|
const boundary = supersessionBoundaryIdx ?? lastMessageEndIdx;
|
|
108
|
-
if (boundary < 0) return stored.slice(); // nothing finalized yet
|
|
109
121
|
|
|
110
122
|
// Pass 2 — emit.
|
|
111
123
|
const out: StoredEvent[] = [];
|
|
@@ -119,6 +131,7 @@ export function compactEventsForReplay(
|
|
|
119
131
|
) {
|
|
120
132
|
continue;
|
|
121
133
|
}
|
|
134
|
+
if (i >= boundary && i + 1 < stored.length && isTextSnapshot(entry.event) && isTextSnapshot(stored[i + 1].event)) continue;
|
|
122
135
|
out.push(entry);
|
|
123
136
|
}
|
|
124
137
|
return out;
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The one history-seeding path for `.jsonl` header discovery (boot,
|
|
3
|
+
* first-session-in-folder, pin-folder). Seeds a discovered transcript as an
|
|
4
|
+
* ended, visible session via `sessionManager.restore()` — no lifecycle hook,
|
|
5
|
+
* no sidecar write.
|
|
6
|
+
*
|
|
7
|
+
* Skips an id that is resident, in the archive index, or already has a
|
|
8
|
+
* `.meta.json` sidecar: boot restored every usable sidecar, so a non-resident
|
|
9
|
+
* sidecar-backed id is archived or broken, and a header-only seed must never
|
|
10
|
+
* stand in for it. Fails closed (seeds nothing) without an archive index.
|
|
11
|
+
* Synchronous on purpose: no await between the guard and `restore()`.
|
|
12
|
+
*
|
|
13
|
+
* See change: fix-discovery-resurrects-archived.
|
|
14
|
+
*/
|
|
15
|
+
import { existsSync } from "node:fs";
|
|
16
|
+
import type { DashboardSession } from "@blackbelt-technology/pi-dashboard-shared/types.js";
|
|
17
|
+
import { metaPath } from "@blackbelt-technology/pi-dashboard-shared/session-meta.js";
|
|
18
|
+
import { deriveEndedAt } from "./derive-ended-at.js";
|
|
19
|
+
import type { SessionManager } from "./memory-session-manager.js";
|
|
20
|
+
import type { SessionArchive } from "./session-archive.js";
|
|
21
|
+
import type { DiscoveredSession } from "./session-discovery.js";
|
|
22
|
+
import { extractSessionStats } from "./session-stats-reader.js";
|
|
23
|
+
|
|
24
|
+
export interface SeedDiscoveredHistoryDeps {
|
|
25
|
+
sessionManager: SessionManager;
|
|
26
|
+
/** Required key: an absent index would silently reinstate resurrection. */
|
|
27
|
+
sessionArchive: Pick<SessionArchive, "has"> | undefined;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
/** Seed the guard-passing transcripts; returns the seeded sessions. */
|
|
31
|
+
export function seedDiscoveredHistory(
|
|
32
|
+
discovered: readonly DiscoveredSession[],
|
|
33
|
+
deps: SeedDiscoveredHistoryDeps,
|
|
34
|
+
): DashboardSession[] {
|
|
35
|
+
const { sessionManager, sessionArchive } = deps;
|
|
36
|
+
if (!sessionArchive) return [];
|
|
37
|
+
const seeded: DashboardSession[] = [];
|
|
38
|
+
for (const hist of discovered) {
|
|
39
|
+
if (sessionManager.get(hist.id)) continue;
|
|
40
|
+
if (sessionArchive.has(hist.id)) continue;
|
|
41
|
+
if (hist.sessionFile && existsSync(metaPath(hist.sessionFile))) continue;
|
|
42
|
+
|
|
43
|
+
let contextTokens: number | undefined;
|
|
44
|
+
let contextWindow: number | undefined;
|
|
45
|
+
let model: string | undefined;
|
|
46
|
+
if (hist.sessionFile) {
|
|
47
|
+
try {
|
|
48
|
+
const stats = extractSessionStats(hist.sessionFile);
|
|
49
|
+
if (stats) {
|
|
50
|
+
contextTokens = stats.lastTotalTokens;
|
|
51
|
+
contextWindow = stats.contextWindow;
|
|
52
|
+
model = stats.model;
|
|
53
|
+
}
|
|
54
|
+
} catch { /* ignore */ }
|
|
55
|
+
}
|
|
56
|
+
sessionManager.restore({
|
|
57
|
+
id: hist.id,
|
|
58
|
+
cwd: hist.cwd,
|
|
59
|
+
name: hist.name,
|
|
60
|
+
source: "tui",
|
|
61
|
+
status: "ended",
|
|
62
|
+
startedAt: hist.startedAt,
|
|
63
|
+
// No `lastActivityAt` here, so stat the transcript rather than lean on a
|
|
64
|
+
// last-activity fallback. See change: fix-ended-session-missing-endedat.
|
|
65
|
+
endedAt: deriveEndedAt({
|
|
66
|
+
sessionFile: hist.sessionFile,
|
|
67
|
+
startedAt: hist.startedAt,
|
|
68
|
+
}),
|
|
69
|
+
sessionFile: hist.sessionFile,
|
|
70
|
+
sessionDir: hist.sessionDir,
|
|
71
|
+
firstMessage: hist.firstMessage,
|
|
72
|
+
// Discovered non-archived history is a visible ended session; `hidden`
|
|
73
|
+
// means "auto-hidden headless worker" only. See change:
|
|
74
|
+
// archive-sessions-lazy-load.
|
|
75
|
+
hidden: false,
|
|
76
|
+
dataUnavailable: true,
|
|
77
|
+
model,
|
|
78
|
+
contextTokens,
|
|
79
|
+
contextWindow,
|
|
80
|
+
});
|
|
81
|
+
const session = sessionManager.get(hist.id);
|
|
82
|
+
if (session) seeded.push(session);
|
|
83
|
+
}
|
|
84
|
+
return seeded;
|
|
85
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The server's own pid namespace (`ServerPidContext`), built ONCE on first use
|
|
3
|
+
* with the same builder the bridge uses, so `resolvePidTarget` compares like
|
|
4
|
+
* with like and performs no I/O per call (S10).
|
|
5
|
+
* See change: scope-pids-to-namespace.
|
|
6
|
+
*/
|
|
7
|
+
import { buildServerPidContext, type ServerPidContext } from "@blackbelt-technology/pi-dashboard-shared/pid-namespace.js";
|
|
8
|
+
|
|
9
|
+
let ctx: ServerPidContext | undefined;
|
|
10
|
+
|
|
11
|
+
export function getServerPidContext(): ServerPidContext {
|
|
12
|
+
ctx ??= buildServerPidContext();
|
|
13
|
+
return ctx;
|
|
14
|
+
}
|
|
@@ -7,6 +7,7 @@
|
|
|
7
7
|
import { randomUUID } from "node:crypto";
|
|
8
8
|
import { existsSync } from "node:fs";
|
|
9
9
|
import { loadConfig } from "@blackbelt-technology/pi-dashboard-shared/config.js";
|
|
10
|
+
import type { RestSpawnSessionRequest } from "@blackbelt-technology/pi-dashboard-shared/rest-api.js";
|
|
10
11
|
import type { ApiResponse } from "@blackbelt-technology/pi-dashboard-shared/types.js";
|
|
11
12
|
import type { FastifyInstance } from "fastify";
|
|
12
13
|
import {
|
|
@@ -30,6 +31,7 @@ import type { PendingResumeIntentRegistry } from "../pending/pending-resume-inte
|
|
|
30
31
|
import type { PiGateway } from "../pi/pi-gateway.js";
|
|
31
32
|
import { keeperOptsFromSpawnResult } from "../spawn-process/headless-pid-registry.js";
|
|
32
33
|
import { isAcp, UNSUPPORTED_FOR_ACP, unsupportedMessage } from "../browser-handlers/acp-guard.js";
|
|
34
|
+
import { choiceToSpawnOptions, resolveSpawnChoice } from "../browser-handlers/spawn-choice.js";
|
|
33
35
|
import { preflightAcpSpawn, spawnAcpSession, validateAcpAgent } from "../spawn-process/acp-spawn.js";
|
|
34
36
|
import { spawnPiSession } from "../spawn-process/process-manager.js";
|
|
35
37
|
import { deriveSpawnCorrelationTtlMs } from "../spawn-process/spawn-recovery-window.js";
|
|
@@ -64,6 +66,11 @@ export interface SessionApiDeps {
|
|
|
64
66
|
* See change: fix-fork-empty-session-silent-timeout.
|
|
65
67
|
*/
|
|
66
68
|
pendingAttachRegistry?: import("../pending/pending-attach-registry.js").PendingAttachRegistry;
|
|
69
|
+
/**
|
|
70
|
+
* Initial-prompt intents consumed on `session_register` (REST spawn
|
|
71
|
+
* `initialPrompt`). See change: add-spawn-model-choice (D3).
|
|
72
|
+
*/
|
|
73
|
+
pendingInitialPromptRegistry?: import("../pending/pending-initial-prompt-registry.js").PendingInitialPromptRegistry;
|
|
67
74
|
/**
|
|
68
75
|
* Prompts transmitted and awaiting a bridge acknowledgement.
|
|
69
76
|
* See change: fix-spawn-correlation-ttl-coupling (D7).
|
|
@@ -98,6 +105,24 @@ export interface SessionApiDeps {
|
|
|
98
105
|
|
|
99
106
|
type IdParams = { Params: { id: string } };
|
|
100
107
|
|
|
108
|
+
const REST_SPAWN_STRING_FIELDS = ["agent", "model", "thinkingLevel", "initialPrompt", "attachProposal"] as const;
|
|
109
|
+
|
|
110
|
+
function nonEmpty(v: unknown): string | undefined {
|
|
111
|
+
return typeof v === "string" && v.length > 0 ? v : undefined;
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
/** Type + combination checks for `POST /api/session/spawn`; returns an error text or null. See change: add-spawn-model-choice. */
|
|
115
|
+
function validateRestSpawnBody(body: Partial<Record<keyof RestSpawnSessionRequest, unknown>>): string | null {
|
|
116
|
+
for (const field of REST_SPAWN_STRING_FIELDS) {
|
|
117
|
+
const v = body[field];
|
|
118
|
+
if (v !== undefined && v !== null && typeof v !== "string") return `${field} must be a string`;
|
|
119
|
+
}
|
|
120
|
+
if (nonEmpty(body.agent) && (nonEmpty(body.model) || nonEmpty(body.thinkingLevel))) {
|
|
121
|
+
return "model and thinkingLevel are pi-only and cannot be combined with agent";
|
|
122
|
+
}
|
|
123
|
+
return null;
|
|
124
|
+
}
|
|
125
|
+
|
|
101
126
|
/** Helper: validate session exists, return it or send error response */
|
|
102
127
|
function getSessionOrFail(sessionManager: SessionManager, id: string): { session: any } | { error: ApiResponse } {
|
|
103
128
|
const session = sessionManager.get(id);
|
|
@@ -117,11 +142,11 @@ export function registerSessionApi(fastify: FastifyInstance, deps: SessionApiDep
|
|
|
117
142
|
// install window is no longer needed.
|
|
118
143
|
|
|
119
144
|
// POST /api/session/:id/prompt
|
|
120
|
-
fastify.post<IdParams & { Body: { text?: string; images?: any[] } }>(
|
|
145
|
+
fastify.post<IdParams & { Body: { text?: string; images?: any[]; delivery?: unknown } }>(
|
|
121
146
|
"/api/session/:id/prompt",
|
|
122
147
|
async (request, reply) => {
|
|
123
148
|
const { id } = request.params;
|
|
124
|
-
const { text, images } = request.body ?? {};
|
|
149
|
+
const { text, images, delivery } = request.body ?? {};
|
|
125
150
|
// Untrusted input: a bare truthiness check accepted objects and numbers,
|
|
126
151
|
// which then reached the bridge as a `send_prompt.text`.
|
|
127
152
|
// See change: fix-spawn-correlation-ttl-coupling.
|
|
@@ -133,6 +158,13 @@ export function registerSessionApi(fastify: FastifyInstance, deps: SessionApiDep
|
|
|
133
158
|
reply.code(400);
|
|
134
159
|
return { success: false, error: "images must be an array" } satisfies ApiResponse;
|
|
135
160
|
}
|
|
161
|
+
// Input errors do not depend on server state: checked before the session
|
|
162
|
+
// lookup. Absent stays absent — the bridge treats it as `followUp`.
|
|
163
|
+
// See change: add-rest-prompt-delivery-mode.
|
|
164
|
+
if (delivery !== undefined && delivery !== "steer" && delivery !== "followUp") {
|
|
165
|
+
reply.code(400);
|
|
166
|
+
return { success: false, error: 'delivery must be "steer" or "followUp"' } satisfies ApiResponse;
|
|
167
|
+
}
|
|
136
168
|
const result = getSessionOrFail(sessionManager, id);
|
|
137
169
|
if ("error" in result) {
|
|
138
170
|
reply.code(404);
|
|
@@ -148,6 +180,7 @@ export function registerSessionApi(fastify: FastifyInstance, deps: SessionApiDep
|
|
|
148
180
|
sessionId: id,
|
|
149
181
|
text,
|
|
150
182
|
images,
|
|
183
|
+
...(delivery !== undefined ? { delivery } : {}),
|
|
151
184
|
promptId,
|
|
152
185
|
});
|
|
153
186
|
if (!sent) {
|
|
@@ -299,14 +332,36 @@ export function registerSessionApi(fastify: FastifyInstance, deps: SessionApiDep
|
|
|
299
332
|
);
|
|
300
333
|
|
|
301
334
|
// POST /api/session/spawn
|
|
302
|
-
fastify.post<{ Body:
|
|
335
|
+
fastify.post<{ Body: Partial<Record<keyof RestSpawnSessionRequest, unknown>> }>(
|
|
303
336
|
"/api/session/spawn",
|
|
304
337
|
async (request, reply) => {
|
|
305
|
-
const
|
|
338
|
+
const body = request.body ?? {};
|
|
339
|
+
const { cwd, agent } = body as { cwd?: string; agent?: string };
|
|
306
340
|
if (!cwd) {
|
|
307
341
|
reply.code(400);
|
|
308
342
|
return { success: false, error: "cwd is required" } satisfies ApiResponse;
|
|
309
343
|
}
|
|
344
|
+
// Validate the WHOLE body before any side effect (owner token, queued
|
|
345
|
+
// intents, spawn). REST is strict: a dropped choice is a 400, never a
|
|
346
|
+
// silent default-model spawn. Empty strings count as absent.
|
|
347
|
+
// See change: add-spawn-model-choice (D2, D3).
|
|
348
|
+
const bodyError = validateRestSpawnBody(body);
|
|
349
|
+
if (bodyError) {
|
|
350
|
+
reply.code(400);
|
|
351
|
+
return { success: false, error: bodyError } satisfies ApiResponse;
|
|
352
|
+
}
|
|
353
|
+
const model = nonEmpty(body.model);
|
|
354
|
+
const thinkingLevel = nonEmpty(body.thinkingLevel);
|
|
355
|
+
const initialPrompt = nonEmpty(body.initialPrompt);
|
|
356
|
+
const attachProposal = nonEmpty(body.attachProposal);
|
|
357
|
+
const { choice, warnings } = resolveSpawnChoice(
|
|
358
|
+
{ model, thinkingLevel },
|
|
359
|
+
{ defaultModel: loadConfig().defaultModel || undefined },
|
|
360
|
+
);
|
|
361
|
+
if (warnings.length > 0) {
|
|
362
|
+
reply.code(400);
|
|
363
|
+
return { success: false, error: warnings.join("; ") } satisfies ApiResponse;
|
|
364
|
+
}
|
|
310
365
|
// `agent` selects a configured ACP agent (see change: add-acp-session-driver).
|
|
311
366
|
const acpAgent = agent === undefined ? undefined : validateAcpAgent(agent);
|
|
312
367
|
if (acpAgent && !acpAgent.ok) {
|
|
@@ -333,12 +388,22 @@ export function registerSessionApi(fastify: FastifyInstance, deps: SessionApiDep
|
|
|
333
388
|
const ownerSpawnToken = ownerToStamp ? mintSpawnToken() : undefined;
|
|
334
389
|
if (ownerToStamp && ownerSpawnToken) deps.pendingPrincipalOwnerRegistry?.file(ownerSpawnToken, ownerToStamp);
|
|
335
390
|
|
|
391
|
+
// Queue intents BEFORE the spawn await so a fast `session_register`
|
|
392
|
+
// cannot miss them (same race-safe FIFO as the browser road).
|
|
393
|
+
if (initialPrompt) deps.pendingInitialPromptRegistry?.enqueue(cwd, initialPrompt);
|
|
394
|
+
if (attachProposal) pendingAttachRegistry?.enqueue(cwd, attachProposal);
|
|
395
|
+
const withdrawIntents = (): void => {
|
|
396
|
+
if (initialPrompt) deps.pendingInitialPromptRegistry?.withdraw(cwd, initialPrompt);
|
|
397
|
+
if (attachProposal) pendingAttachRegistry?.withdraw(cwd, attachProposal);
|
|
398
|
+
};
|
|
399
|
+
|
|
336
400
|
const doSpawn = async () => {
|
|
337
401
|
const config = loadConfig();
|
|
338
402
|
const spawnResult = acpAgent?.ok
|
|
339
403
|
? await spawnAcpSession(cwd, { agent: acpAgent.agent.id, ...(ownerSpawnToken ? { spawnToken: ownerSpawnToken } : {}) })
|
|
340
404
|
: await spawnPiSession(cwd, {
|
|
341
405
|
strategy: config.spawnStrategy,
|
|
406
|
+
...choiceToSpawnOptions(choice),
|
|
342
407
|
...(ownerSpawnToken ? { spawnToken: ownerSpawnToken } : {}),
|
|
343
408
|
});
|
|
344
409
|
// REST spawn has no browser socket; the reclaim must run regardless, or
|
|
@@ -360,9 +425,17 @@ export function registerSessionApi(fastify: FastifyInstance, deps: SessionApiDep
|
|
|
360
425
|
return spawnResult;
|
|
361
426
|
};
|
|
362
427
|
|
|
363
|
-
|
|
428
|
+
let spawnResult: Awaited<ReturnType<typeof doSpawn>>;
|
|
429
|
+
try {
|
|
430
|
+
spawnResult = await doSpawn();
|
|
431
|
+
} catch (err) {
|
|
432
|
+
if (ownerSpawnToken) deps.pendingPrincipalOwnerRegistry?.remove(ownerSpawnToken);
|
|
433
|
+
withdrawIntents();
|
|
434
|
+
throw err;
|
|
435
|
+
}
|
|
364
436
|
if (!spawnResult.success) {
|
|
365
437
|
if (ownerSpawnToken) deps.pendingPrincipalOwnerRegistry?.remove(ownerSpawnToken);
|
|
438
|
+
withdrawIntents();
|
|
366
439
|
reply.code(500);
|
|
367
440
|
return { success: false, error: spawnResult.message } satisfies ApiResponse;
|
|
368
441
|
}
|
|
@@ -528,30 +601,6 @@ export function registerSessionApi(fastify: FastifyInstance, deps: SessionApiDep
|
|
|
528
601
|
},
|
|
529
602
|
);
|
|
530
603
|
|
|
531
|
-
// POST /api/session/:id/flow-control
|
|
532
|
-
fastify.post<IdParams & { Body: { action?: string } }>(
|
|
533
|
-
"/api/session/:id/flow-control",
|
|
534
|
-
async (request, reply) => {
|
|
535
|
-
const { id } = request.params;
|
|
536
|
-
const { action } = request.body ?? {};
|
|
537
|
-
if (action !== "abort" && action !== "toggle_autonomous") {
|
|
538
|
-
reply.code(400);
|
|
539
|
-
return { success: false, error: "action must be 'abort' or 'toggle_autonomous'" } satisfies ApiResponse;
|
|
540
|
-
}
|
|
541
|
-
const result = getSessionOrFail(sessionManager, id);
|
|
542
|
-
if ("error" in result) {
|
|
543
|
-
reply.code(404);
|
|
544
|
-
return result.error;
|
|
545
|
-
}
|
|
546
|
-
if (isAcp(result.session)) {
|
|
547
|
-
reply.code(409);
|
|
548
|
-
return { success: false, error: unsupportedMessage("flow_control"), code: UNSUPPORTED_FOR_ACP } as ApiResponse;
|
|
549
|
-
}
|
|
550
|
-
piGateway.sendToSession(id, { type: "flow_control", sessionId: id, action });
|
|
551
|
-
return { success: true } satisfies ApiResponse;
|
|
552
|
-
},
|
|
553
|
-
);
|
|
554
|
-
|
|
555
604
|
// POST /api/session/:id/model
|
|
556
605
|
fastify.post<IdParams & { Body: { provider?: string; modelId?: string } }>(
|
|
557
606
|
"/api/session/:id/model",
|
|
@@ -73,6 +73,12 @@ interface ArchivedListResult {
|
|
|
73
73
|
}
|
|
74
74
|
|
|
75
75
|
export interface SessionArchive {
|
|
76
|
+
/**
|
|
77
|
+
* Platform the index folds keys with, narrowed to the wire's
|
|
78
|
+
* `pathKeyPlatform` (non-linux/win32 platforms fold like darwin).
|
|
79
|
+
* See change: fix-archive-fold-key-and-filter-chips.
|
|
80
|
+
*/
|
|
81
|
+
readonly pathKeyPlatform: "linux" | "darwin" | "win32";
|
|
76
82
|
/** Seed the index from the boot scan's archived rows. */
|
|
77
83
|
seed(rows: ArchivedSessionSummary[]): void;
|
|
78
84
|
/** Re-key every row after a pinned-directory change; broadcasts changed counts. */
|
|
@@ -237,6 +243,7 @@ export function createSessionArchive(deps: SessionArchiveDeps): SessionArchive {
|
|
|
237
243
|
}
|
|
238
244
|
|
|
239
245
|
return {
|
|
246
|
+
pathKeyPlatform: platform === "linux" || platform === "win32" ? platform : "darwin",
|
|
240
247
|
seed(rows) {
|
|
241
248
|
rebuild(rows);
|
|
242
249
|
},
|
|
@@ -2,12 +2,11 @@
|
|
|
2
2
|
* Session bootstrap: discovers sessions from known directories and starts OpenSpec polling.
|
|
3
3
|
* Called during server startup (async, non-blocking).
|
|
4
4
|
*/
|
|
5
|
-
import { deriveEndedAt } from "./derive-ended-at.js";
|
|
6
5
|
import type { SessionManager } from "./memory-session-manager.js";
|
|
7
6
|
import type { SessionArchive } from "./session-archive.js";
|
|
8
7
|
import type { BrowserGateway } from "../pairing/browser-gateway.js";
|
|
9
8
|
import { isOpenSpecDataEmpty, type DirectoryService } from "../directory-service.js";
|
|
10
|
-
import {
|
|
9
|
+
import { seedDiscoveredHistory } from "./seed-discovered-history.js";
|
|
11
10
|
|
|
12
11
|
export interface SessionBootstrapDeps {
|
|
13
12
|
sessionManager: SessionManager;
|
|
@@ -27,58 +26,14 @@ export async function discoverAndBroadcastSessions(deps: SessionBootstrapDeps):
|
|
|
27
26
|
try {
|
|
28
27
|
const dirs = directoryService.knownDirectories();
|
|
29
28
|
for (const cwd of dirs) {
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
let contextWindow: number | undefined;
|
|
39
|
-
let model: string | undefined;
|
|
40
|
-
if (hist.sessionFile) {
|
|
41
|
-
try {
|
|
42
|
-
const stats = extractSessionStats(hist.sessionFile);
|
|
43
|
-
if (stats) {
|
|
44
|
-
contextTokens = stats.lastTotalTokens;
|
|
45
|
-
contextWindow = stats.contextWindow;
|
|
46
|
-
model = stats.model;
|
|
47
|
-
}
|
|
48
|
-
} catch { /* ignore */ }
|
|
49
|
-
}
|
|
50
|
-
sessionManager.restore({
|
|
51
|
-
id: hist.id,
|
|
52
|
-
cwd: hist.cwd,
|
|
53
|
-
name: hist.name,
|
|
54
|
-
source: "tui",
|
|
55
|
-
status: "ended",
|
|
56
|
-
startedAt: hist.startedAt,
|
|
57
|
-
// This path sets no `lastActivityAt`, so it must stat its own
|
|
58
|
-
// transcript rather than lean on a last-activity fallback — the one
|
|
59
|
-
// case where the card's time badge is actually wrong today.
|
|
60
|
-
// See change: fix-ended-session-missing-endedat.
|
|
61
|
-
endedAt: deriveEndedAt({
|
|
62
|
-
sessionFile: hist.sessionFile,
|
|
63
|
-
startedAt: hist.startedAt,
|
|
64
|
-
}),
|
|
65
|
-
sessionFile: hist.sessionFile,
|
|
66
|
-
sessionDir: hist.sessionDir,
|
|
67
|
-
firstMessage: hist.firstMessage,
|
|
68
|
-
// Discovered history that is NOT archived is seeded as a visible
|
|
69
|
-
// ended session (the old `hidden: true` literal made all TUI
|
|
70
|
-
// history an auto-hidden worker). See change:
|
|
71
|
-
// archive-sessions-lazy-load.
|
|
72
|
-
hidden: false,
|
|
73
|
-
dataUnavailable: true,
|
|
74
|
-
model,
|
|
75
|
-
contextTokens,
|
|
76
|
-
contextWindow,
|
|
77
|
-
});
|
|
78
|
-
const session = sessionManager.get(hist.id);
|
|
79
|
-
if (session) browserGateway.broadcastSessionAdded(session);
|
|
80
|
-
}
|
|
81
|
-
}
|
|
29
|
+
// Archived / sidecar-backed ids are never re-seeded from their `.jsonl`
|
|
30
|
+
// header; no index → seed nothing. See change:
|
|
31
|
+
// fix-discovery-resurrects-archived.
|
|
32
|
+
const seeded = seedDiscoveredHistory(directoryService.discoverSessions(cwd), {
|
|
33
|
+
sessionManager,
|
|
34
|
+
sessionArchive,
|
|
35
|
+
});
|
|
36
|
+
for (const session of seeded) browserGateway.broadcastSessionAdded(session);
|
|
82
37
|
}
|
|
83
38
|
} catch (err) {
|
|
84
39
|
console.error("[dashboard] Session discovery failed:", err);
|
|
@@ -27,6 +27,7 @@
|
|
|
27
27
|
import { dirname, resolve } from "node:path";
|
|
28
28
|
import { fileURLToPath, pathToFileURL } from "node:url";
|
|
29
29
|
import { Worker } from "node:worker_threads";
|
|
30
|
+
import { getReplayEntryTypes, recordPluginEntriesReplayed } from "../plugin-entry-stats.js";
|
|
30
31
|
import {
|
|
31
32
|
loadAndReplay,
|
|
32
33
|
type SessionLoadRequest,
|
|
@@ -123,6 +124,7 @@ export function createSessionLoadWorkerPool(
|
|
|
123
124
|
function finish(p: Pending, out: SessionLoadResult): void {
|
|
124
125
|
if (p.resolved) return;
|
|
125
126
|
p.resolved = true;
|
|
127
|
+
recordPluginEntriesReplayed(out.pluginEntriesReplayed ?? 0);
|
|
126
128
|
p.resolve(out);
|
|
127
129
|
}
|
|
128
130
|
|
|
@@ -235,7 +237,15 @@ export function createSessionLoadWorkerPool(
|
|
|
235
237
|
|
|
236
238
|
function load(req: Omit<SessionLoadRequest, "jobId">): SessionLoadDispatch {
|
|
237
239
|
const id = nextId++;
|
|
238
|
-
|
|
240
|
+
// Manifest-derived plugin entry types ride every request, so an offline
|
|
241
|
+
// session replays its plugin runs. See change: update-flows-plugin (D3).
|
|
242
|
+
const types = getReplayEntryTypes();
|
|
243
|
+
const payload: SessionLoadRequest = {
|
|
244
|
+
replayEntryTypes: types.replay,
|
|
245
|
+
hiddenEntryTypes: types.hidden,
|
|
246
|
+
...req,
|
|
247
|
+
jobId: id,
|
|
248
|
+
};
|
|
239
249
|
let resolveOuter!: (out: SessionLoadResult) => void;
|
|
240
250
|
const result = new Promise<SessionLoadResult>((r) => { resolveOuter = r; });
|
|
241
251
|
const p: Pending = {
|