@blackbelt-technology/pi-agent-dashboard 0.10.0 → 0.11.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 -2
- package/README.md +47 -6
- package/docs/architecture.md +1369 -63
- package/package.json +14 -9
- package/packages/extension/package.json +5 -3
- package/packages/extension/src/bridge-handlers/dispatch.ts +57 -3
- package/packages/extension/src/bridge-handlers/instance.ts +10 -1
- package/packages/extension/src/bridge-handlers/lifecycle.ts +65 -26
- package/packages/extension/src/bridge-ticket-client.ts +61 -7
- package/packages/extension/src/bridge-tls-checks.ts +79 -0
- package/packages/extension/src/bridge.ts +41 -28
- package/packages/extension/src/canvas-tool.ts +2 -0
- package/packages/extension/src/command-handler.ts +80 -6
- package/packages/extension/src/connect-target.ts +23 -0
- package/packages/extension/src/connection.ts +30 -7
- package/packages/extension/src/dashboard-http-origin.ts +88 -0
- package/packages/extension/src/dev-build.ts +11 -1
- package/packages/extension/src/git-link-builder.ts +11 -2
- package/packages/extension/src/inbound-limits.ts +138 -0
- package/packages/extension/src/local-token-header.ts +77 -6
- package/packages/extension/src/model-refresh.ts +69 -0
- package/packages/extension/src/pinned-endpoint.ts +44 -0
- package/packages/extension/src/project-trust-live.ts +143 -0
- package/packages/extension/src/project-trust.ts +159 -20
- package/packages/extension/src/provider-register.ts +59 -18
- package/packages/extension/src/remote-registration-gate.ts +21 -21
- package/packages/extension/src/remote-upgrade-preparer.ts +104 -0
- package/packages/extension/src/role-model-tools.ts +47 -6
- package/packages/extension/src/server-auto-start.ts +1 -1
- package/packages/extension/src/server-proof-probe.ts +117 -0
- package/packages/extension/src/session-sync.ts +42 -12
- package/packages/extension/src/vault-delivery.ts +11 -1
- package/packages/server/package.json +8 -8
- package/packages/server/src/access/access-grants.ts +61 -8
- package/packages/server/src/access/access-health.ts +10 -0
- package/packages/server/src/access/access-plane.ts +5 -1
- package/packages/server/src/access/containment-gate.ts +55 -17
- package/packages/server/src/access/cwd-verdict.ts +3 -3
- package/packages/server/src/access/pi-trust-live.ts +244 -0
- package/packages/server/src/access/pi-trust-mirror-service.ts +44 -11
- package/packages/server/src/access/planes.ts +106 -1
- package/packages/server/src/access/preview-egress-store.ts +153 -0
- package/packages/server/src/access/prompt-channel.ts +5 -0
- package/packages/server/src/access/provisioning-wiring.ts +113 -0
- package/packages/server/src/access/provisioning.ts +763 -0
- package/packages/server/src/access/yolo-session.ts +54 -2
- package/packages/server/src/acp-bridge/acp-session-adapter.ts +8 -3
- package/packages/server/src/agent-events/agent-event-hub.ts +158 -0
- package/packages/server/src/auth/audit-log.ts +80 -0
- package/packages/server/src/auth/auth-plugin.ts +44 -25
- package/packages/server/src/auth/auth.ts +24 -4
- package/packages/server/src/auth/bearer-auth.ts +52 -12
- package/packages/server/src/auth/cors-origin.ts +76 -29
- package/packages/server/src/auth/csp-report-paths.ts +31 -0
- package/packages/server/src/auth/csp-report-sink.ts +302 -0
- package/packages/server/src/auth/csp-report-store.ts +406 -0
- package/packages/server/src/auth/csp.ts +105 -9
- package/packages/server/src/auth/dashboard-credential-store.ts +4 -0
- package/packages/server/src/auth/dashboard-state-caller.ts +29 -0
- package/packages/server/src/auth/local-proof-refusal-log.ts +89 -0
- package/packages/server/src/auth/local-proof.ts +69 -18
- package/packages/server/src/auth/localhost-guard.ts +48 -10
- package/packages/server/src/auth/nav-intent.ts +72 -0
- package/packages/server/src/auth/passkey/passkey-assets.ts +99 -0
- package/packages/server/src/auth/passkey/passkey-pages.ts +17 -81
- package/packages/server/src/auth/passkey/passkey-routes.ts +8 -0
- package/packages/server/src/auth/pi-legacy-credentials.ts +3 -0
- package/packages/server/src/auth/plugin-server-trust.ts +29 -0
- package/packages/server/src/auth/plugin-trust-store.ts +103 -0
- package/packages/server/src/auth/proven-tls.ts +45 -0
- package/packages/server/src/auth/provider-auth-storage.ts +6 -1
- package/packages/server/src/auth/radius-mcp.ts +1 -1
- package/packages/server/src/auth/request-principal.ts +32 -0
- package/packages/server/src/auth/secret-rotation.ts +246 -0
- package/packages/server/src/auth/secure-origin.ts +56 -0
- package/packages/server/src/auth/serve-app-host.ts +111 -11
- package/packages/server/src/auth/ws-ticket.ts +39 -1
- package/packages/server/src/auth/ws-upgrade-reject-log.ts +4 -1
- package/packages/server/src/browser-handlers/directory-handler.ts +23 -0
- package/packages/server/src/browser-handlers/folder-gate.ts +55 -0
- package/packages/server/src/browser-handlers/handler-context.ts +25 -2
- package/packages/server/src/browser-handlers/session-action-handler.ts +9 -1
- package/packages/server/src/browser-handlers/subscription-handler.ts +100 -2
- package/packages/server/src/browser-handlers/terminal-handler.ts +108 -10
- package/packages/server/src/canvas/canvas-accumulator.ts +35 -7
- package/packages/server/src/cli.ts +210 -39
- package/packages/server/src/config-api.ts +23 -1
- package/packages/server/src/config-snapshot.ts +48 -1
- package/packages/server/src/directory-service.ts +160 -54
- package/packages/server/src/event-wiring.ts +143 -108
- package/packages/server/src/git-worktree/git-operations.ts +44 -10
- package/packages/server/src/git-worktree/redact-git-text.ts +124 -0
- package/packages/server/src/git-worktree/ref-arg.ts +39 -0
- package/packages/server/src/git-worktree/worktree-init-trust.ts +43 -1
- package/packages/server/src/identity/http-road-classification.ts +13 -1
- package/packages/server/src/identity/ws-message-scope.ts +1 -0
- package/packages/server/src/identity/ws-road-classification.ts +1 -0
- package/packages/server/src/known-server-moves.ts +36 -15
- package/packages/server/src/lib/browse-roots.ts +118 -17
- package/packages/server/src/lib/client-dist.ts +36 -21
- package/packages/server/src/lib/dashboard-state-guard.ts +230 -0
- package/packages/server/src/lib/diagram-render.ts +4 -6
- package/packages/server/src/lib/eml.ts +3 -8
- package/packages/server/src/lib/file-cwd-admission.ts +145 -0
- package/packages/server/src/lib/grep-worker.ts +23 -0
- package/packages/server/src/lib/grep.ts +93 -7
- package/packages/server/src/lib/index-html.ts +81 -0
- package/packages/server/src/lib/office-preview.ts +2 -3
- package/packages/server/src/lib/path-containment.ts +7 -0
- package/packages/server/src/lib/resolve-file-mention.ts +11 -9
- package/packages/server/src/lib/route-admission.ts +80 -0
- package/packages/server/src/lib/writable-md-target.ts +4 -0
- package/packages/server/src/lifecycle/recovery-server.ts +65 -18
- package/packages/server/src/live-server/capability-redact.ts +15 -0
- package/packages/server/src/live-server/live-browser-gate.ts +22 -0
- package/packages/server/src/live-server/live-capability.ts +224 -17
- package/packages/server/src/live-server/live-csp-report.ts +63 -0
- package/packages/server/src/live-server/live-csp.ts +93 -0
- package/packages/server/src/live-server/live-egress.ts +435 -0
- package/packages/server/src/live-server/live-exposure.ts +149 -0
- package/packages/server/src/live-server/live-log.ts +21 -0
- package/packages/server/src/live-server/live-origin-scan.ts +298 -0
- package/packages/server/src/live-server/live-server-manager.ts +209 -33
- package/packages/server/src/live-server/live-server-proxy.ts +162 -17
- package/packages/server/src/live-server/live-static.ts +228 -0
- package/packages/server/src/openspec/dependencies-file.ts +122 -0
- package/packages/server/src/openspec/openspec-change-watcher.ts +3 -1
- package/packages/server/src/openspec/openspec-dependency-inputs.ts +281 -0
- package/packages/server/src/openspec/openspec-poll-fs-helpers.ts +72 -26
- package/packages/server/src/openspec/openspec-poll-worker-pool.ts +48 -12
- package/packages/server/src/openspec/openspec-poll-worker.ts +95 -9
- package/packages/server/src/openspec/workflow-schema-status.ts +379 -0
- package/packages/server/src/openspec/workflow-schema.ts +141 -267
- package/packages/server/src/package/npm-search-proxy.ts +5 -2
- package/packages/server/src/package/provider-probe.ts +8 -2
- package/packages/server/src/pairing/browser-gateway.ts +188 -12
- package/packages/server/src/pairing/device-token-services.ts +26 -0
- package/packages/server/src/pairing/paired-devices.ts +335 -22
- package/packages/server/src/pairing/pairing.ts +34 -4
- package/packages/server/src/pairing/socket-locality.ts +26 -0
- package/packages/server/src/persistence/preferences-store.ts +9 -0
- package/packages/server/src/pi/bridge-channel.ts +33 -0
- package/packages/server/src/pi/bridge-upgrade-auth.ts +18 -3
- package/packages/server/src/pi/gateway-listeners.ts +9 -3
- package/packages/server/src/pi/host-project-trust.ts +14 -6
- package/packages/server/src/pi/pi-gateway.ts +191 -21
- package/packages/server/src/pi/resource-toggle-trust.ts +1 -1
- package/packages/server/src/plugin-discovery-wiring.ts +142 -0
- package/packages/server/src/plugin-event-seam.ts +116 -4
- package/packages/server/src/plugin-runtime-clients.ts +89 -0
- package/packages/server/src/routes/access-routes.ts +159 -9
- package/packages/server/src/routes/agent-event-stream-routes.ts +137 -0
- package/packages/server/src/routes/canvas-types-routes.ts +20 -6
- package/packages/server/src/routes/csp-violations-routes.ts +162 -0
- package/packages/server/src/routes/file-routes.ts +329 -209
- package/packages/server/src/routes/file-write-binary-routes.ts +77 -20
- package/packages/server/src/routes/folder-project-routes.ts +18 -12
- package/packages/server/src/routes/git-routes.ts +319 -203
- package/packages/server/src/routes/grep-routes.ts +38 -14
- package/packages/server/src/routes/known-servers-routes.ts +189 -91
- package/packages/server/src/routes/live-server-routes.ts +378 -15
- package/packages/server/src/routes/local-proof-routes.ts +14 -0
- package/packages/server/src/routes/nav-intent-routes.ts +46 -0
- package/packages/server/src/routes/openspec-group-routes.ts +53 -44
- package/packages/server/src/routes/openspec-routes.ts +379 -28
- package/packages/server/src/routes/package-routes.ts +58 -10
- package/packages/server/src/routes/pairing-routes.ts +146 -10
- package/packages/server/src/routes/pi-trust-query-routes.ts +330 -0
- package/packages/server/src/routes/plugin-activation-routes.ts +59 -0
- package/packages/server/src/routes/plugin-runtime-client-routes.ts +149 -0
- package/packages/server/src/routes/provider-auth-routes.ts +15 -2
- package/packages/server/src/routes/resource-activation-routes.ts +18 -4
- package/packages/server/src/routes/session-routes.ts +51 -4
- package/packages/server/src/routes/system-routes.ts +84 -15
- package/packages/server/src/routes/ui-link-base.ts +88 -0
- package/packages/server/src/runtime-overlay/runtime-io.ts +2 -9
- package/packages/server/src/server.ts +648 -137
- package/packages/server/src/session/hydration-state.ts +148 -0
- package/packages/server/src/session/memory-session-manager.ts +7 -0
- package/packages/server/src/session/replay-exit-controller.ts +221 -0
- package/packages/server/src/session/retained-transcript.ts +9 -2
- package/packages/server/src/session/session-load-worker.ts +11 -2
- package/packages/server/src/spawn-process/headless-pid-registry.ts +14 -9
- package/packages/server/src/terminal/terminal-manager.ts +54 -46
- package/packages/server/src/tls/tls-bridge-route.ts +61 -0
- package/packages/server/src/tls/tls-config-validation.ts +2 -0
- package/packages/server/src/vault/device-expiry-sweep.ts +36 -0
- package/packages/server/src/vault/vault-delivery-hub.ts +155 -25
- package/packages/server/src/watch-files-handler.ts +66 -0
- package/packages/shared/package.json +1 -1
- package/packages/shared/src/browser-protocol.ts +148 -2
- package/packages/shared/src/canvas-declare.ts +27 -0
- package/packages/shared/src/config.ts +372 -53
- package/packages/shared/src/containment-guard.ts +35 -0
- package/packages/shared/src/dashboard-plugin/anthropic-peer-names.ts +9 -0
- package/packages/shared/src/dashboard-plugin/event-type-owners.ts +50 -0
- package/packages/shared/src/dashboard-plugin/file-handler.ts +2 -0
- package/packages/shared/src/dashboard-plugin/host-api.ts +61 -0
- package/packages/shared/src/dashboard-plugin/host-fx-classes.ts +23 -0
- package/packages/shared/src/dashboard-plugin/host-import-map.ts +38 -0
- package/packages/shared/src/dashboard-plugin/index.ts +2 -0
- package/packages/shared/src/dashboard-plugin/manifest-types.ts +54 -1
- package/packages/shared/src/dashboard-plugin/plugin-status.ts +54 -0
- package/packages/shared/src/dashboard-plugin/slot-props.ts +45 -3
- package/packages/shared/src/dashboard-plugin/slot-types.ts +8 -0
- package/packages/shared/src/dashboard-plugin/subagent-types.ts +219 -0
- package/packages/shared/src/dashboard-plugin/ui-primitives.ts +28 -0
- package/packages/shared/src/display-prefs.ts +13 -0
- package/packages/shared/src/doctor-core.ts +94 -27
- package/packages/shared/src/live-server.ts +141 -0
- package/packages/shared/src/local-proof-signal.ts +16 -0
- package/packages/shared/src/loopback-host.ts +26 -0
- package/packages/shared/src/mcp/verb-tiers.generated.ts +178 -0
- package/packages/shared/src/mdns-discovery.ts +25 -6
- package/packages/shared/src/nav-intent.ts +29 -0
- package/packages/shared/src/openspec-dependencies.ts +760 -0
- package/packages/shared/src/openspec-poller.ts +3 -2
- package/packages/shared/src/pairing-knock-client.ts +44 -4
- package/packages/shared/src/pi-trust-live-query.ts +93 -0
- package/packages/shared/src/pi-trust-mirror-snapshot.ts +5 -7
- package/packages/shared/src/pi-trust-mirror-types.ts +36 -3
- package/packages/shared/src/pi-trust-mirror.ts +29 -3
- package/packages/shared/src/pi-trust-resource-digest.ts +255 -0
- package/packages/shared/src/platform/ensure-bundled-git.ts +57 -34
- package/packages/shared/src/platform/git-source.ts +88 -26
- package/packages/shared/src/platform/git.ts +14 -8
- package/packages/shared/src/platform/process.ts +48 -4
- package/packages/shared/src/platform/resolve-pi-shell.ts +76 -0
- package/packages/shared/src/platform/select-git-source.ts +7 -0
- package/packages/shared/src/plugin-route-cwd.ts +95 -0
- package/packages/shared/src/preview-egress.ts +138 -0
- package/packages/shared/src/project-root.ts +16 -0
- package/packages/shared/src/protocol.ts +40 -1
- package/packages/shared/src/recommended-extensions.ts +18 -0
- package/packages/shared/src/recovery-timing.ts +27 -0
- package/packages/shared/src/remote-credentials.ts +63 -0
- package/packages/shared/src/rest-api.ts +55 -8
- package/packages/shared/src/route-tiers.ts +55 -1
- package/packages/shared/src/runtime-overlay/archive-safety.d.mts +2 -0
- package/packages/shared/src/runtime-overlay/archive-safety.mjs +33 -0
- package/packages/shared/src/runtime-overlay/manifest.d.mts +7 -0
- package/packages/shared/src/runtime-overlay/manifest.mjs +22 -2
- package/packages/shared/src/safe-local-path.ts +24 -0
- package/packages/shared/src/sanitize-profiles.ts +98 -0
- package/packages/shared/src/server-launcher.ts +9 -1
- package/packages/shared/src/server-pinning.ts +55 -2
- package/packages/shared/src/server-routes.ts +462 -0
- package/packages/shared/src/session-ui-path.ts +11 -0
- package/packages/shared/src/tls-only-token.ts +16 -0
- package/packages/shared/src/tool-registry/definitions.ts +5 -5
- package/packages/shared/src/tool-registry/strategies.ts +12 -11
- package/packages/shared/src/types.ts +66 -0
- package/packages/shared/src/url-policy.ts +96 -0
- package/packages/shared/src/vault-delivery.ts +15 -0
- package/packages/shared/src/ws-message-tiers.ts +1 -0
|
@@ -19,12 +19,12 @@ import { AbortLatch } from "./abort-latch.js";
|
|
|
19
19
|
import { type AutoNamer, createAutoNamer, type PersistedNamerState, type StreamSimpleFn } from "./auto-session-namer.js";
|
|
20
20
|
import type { BridgeContext } from "./bridge-context.js";
|
|
21
21
|
import { extractLatestTurnWindow, } from "./bridge-context.js";
|
|
22
|
-
import { mintBridgeTicket, readDeviceToken, withTicket } from "./bridge-ticket-client.js";
|
|
23
22
|
import {
|
|
24
23
|
createCommandHandler,
|
|
25
24
|
tryExecSlashTemplate,
|
|
26
25
|
validateImages,
|
|
27
26
|
} from "./command-handler.js";
|
|
27
|
+
import { createInboundLimits } from "./inbound-limits.js";
|
|
28
28
|
import { buildSessionContextText, runForkSubagentDraft } from "./commit-draft-agent.js";
|
|
29
29
|
import { ConnectionManager, type WatchdogFireInfo } from "./connection.js";
|
|
30
30
|
import {
|
|
@@ -50,7 +50,9 @@ import { createPollingHolder, drainDisposables, ensureDisposable, teardownPrevio
|
|
|
50
50
|
import { createGitTracker, type GitTracker } from "./git-tracker.js";
|
|
51
51
|
import { createPrStatusScheduler, type PrStatusScheduler } from "./pr-status.js";
|
|
52
52
|
import * as git from "@blackbelt-technology/pi-dashboard-shared/platform/git.js";
|
|
53
|
-
import { localCredentialPlan } from "./local-token-header.js";
|
|
53
|
+
import { localCredentialPlan, proofFailureLogCause } from "./local-token-header.js";
|
|
54
|
+
import { isPinnedEndpoint } from "./pinned-endpoint.js";
|
|
55
|
+
import { loadServerPins, serverPinsPath } from "./server-pin-store.js";
|
|
54
56
|
import { inlineMessageText, type ReadFileOutcome } from "./markdown-image-inliner.js";
|
|
55
57
|
import { createMcpDashboardRegistrar, type McpRegistrationApi, } from "./mcp-token-delivery.js";
|
|
56
58
|
import { createPluginRequestClient, installPluginRequest } from "./plugin-request-client.js";
|
|
@@ -63,7 +65,7 @@ import { readPiRetrySettings } from "./pi-retry-settings.js";
|
|
|
63
65
|
import { getOwnPgid, } from "./process-scanner.js";
|
|
64
66
|
import { expandPromptTemplateFromDisk } from "./prompt-expander.js";
|
|
65
67
|
import { activate as activateProviderRegister, buildProviderCatalogue, onProviderChanged, reloadProviders, toModelInfo } from "./provider-register.js";
|
|
66
|
-
import {
|
|
68
|
+
import { createRemoteUpgradePreparer } from "./remote-upgrade-preparer.js";
|
|
67
69
|
import { RetryTracker } from "./retry-tracker.js";
|
|
68
70
|
import { activate as activateRoleManager, resolveNamingModel } from "./role-manager.js";
|
|
69
71
|
import { replaySessionEntries as _replaySessionEntries, sendStateSync as _sendStateSync, filterByEnabledModels, isLive } from "./session-sync.js";
|
|
@@ -1034,27 +1036,24 @@ function initBridge(pi: ExtensionAPI) {
|
|
|
1034
1036
|
inst.transportDiagnostics = transportDiagnostics;
|
|
1035
1037
|
transportDiagnostics.record({ event: "endpoint_resolved", detail: endpointDetail });
|
|
1036
1038
|
|
|
1037
|
-
|
|
1038
|
-
|
|
1039
|
-
|
|
1040
|
-
|
|
1041
|
-
|
|
1042
|
-
|
|
1043
|
-
|
|
1044
|
-
|
|
1045
|
-
|
|
1046
|
-
|
|
1047
|
-
|
|
1048
|
-
|
|
1049
|
-
|
|
1050
|
-
|
|
1051
|
-
|
|
1052
|
-
|
|
1053
|
-
|
|
1054
|
-
|
|
1055
|
-
}
|
|
1056
|
-
return { url: withTicket(endpoint, minted.ticket) };
|
|
1057
|
-
}
|
|
1039
|
+
// Mint a bridge ticket per remote dial; origin + failure causes: see
|
|
1040
|
+
// `remote-upgrade-preparer.ts`. Log the resolved HTTP origin up front too
|
|
1041
|
+
// (D4), deduped with the per-dial log.
|
|
1042
|
+
// The bearer goes only to a PINNED endpoint: the one this bridge was configured
|
|
1043
|
+
// with (or the user explicitly moved to), or a pin-store `lastEndpoint`.
|
|
1044
|
+
// A discovery-only host is never pinned. See change: harden-bridge-inbound-and-discovery (D19).
|
|
1045
|
+
const configuredEndpoint = inst.dashboardUrl;
|
|
1046
|
+
const prepareRemoteUpgrade = createRemoteUpgradePreparer({
|
|
1047
|
+
env: process.env,
|
|
1048
|
+
log: console,
|
|
1049
|
+
record: (d) => transportDiagnostics.record(d),
|
|
1050
|
+
isPinned: (endpoint) =>
|
|
1051
|
+
isPinnedEndpoint(endpoint, {
|
|
1052
|
+
configured: [configuredEndpoint, inst.dashboardUrl],
|
|
1053
|
+
pins: loadServerPins(serverPinsPath()),
|
|
1054
|
+
}),
|
|
1055
|
+
});
|
|
1056
|
+
prepareRemoteUpgrade.noteOrigin(inst.dashboardUrl);
|
|
1058
1057
|
|
|
1059
1058
|
// Long-lived ctx wrapper for the Extension UI System (Phase 1) — see
|
|
1060
1059
|
// change: add-extension-ui-modal. `getSessionId` reads the closed-over
|
|
@@ -1123,6 +1122,7 @@ function initBridge(pi: ExtensionAPI) {
|
|
|
1123
1122
|
const vaultDelivery = createVaultDelivery({
|
|
1124
1123
|
send: (m) => inst.connection.sendIfOpen(m),
|
|
1125
1124
|
sessionId: () => inst.sessionId ?? "",
|
|
1125
|
+
certValidation: () => inst.connection.certValidation,
|
|
1126
1126
|
log: (line) => console.log(line),
|
|
1127
1127
|
});
|
|
1128
1128
|
inst.vaultDelivery = vaultDelivery;
|
|
@@ -1197,7 +1197,7 @@ function initBridge(pi: ExtensionAPI) {
|
|
|
1197
1197
|
// counter-proof before `open`. See change: loopback-credential-proof (D6, D7).
|
|
1198
1198
|
planDial: (base) => localCredentialPlan(base),
|
|
1199
1199
|
onIdentityFailure: (report) => {
|
|
1200
|
-
console.error(`[dashboard] server identity check failed (${report.cause}) at ${report.endpoint}`);
|
|
1200
|
+
console.error(`[dashboard] server identity check failed (${proofFailureLogCause(report.cause)}) at ${report.endpoint}`);
|
|
1201
1201
|
appendIdentityLog(report);
|
|
1202
1202
|
},
|
|
1203
1203
|
// Every accepted re-target (and every reversal) re-derives these from the
|
|
@@ -1265,7 +1265,10 @@ function initBridge(pi: ExtensionAPI) {
|
|
|
1265
1265
|
const _bc = syncBc();
|
|
1266
1266
|
_resetReconnectCaches(_bc);
|
|
1267
1267
|
applyBc(_bc);
|
|
1268
|
-
|
|
1268
|
+
// Computed ONCE: the register's `liveTailOpen` and the replay's are the
|
|
1269
|
+
// same value. See change: fix-large-session-resume-replay (D7).
|
|
1270
|
+
const liveTailOpen = isLive(inst.cachedCtx, getBridgeState().isAgentStreaming);
|
|
1271
|
+
sendStateSync({ liveTailOpen });
|
|
1269
1272
|
// The server does not persist `piVersion` / `piBelowFloor`; re-send now
|
|
1270
1273
|
// rather than on the next poll tick. See change: update-pi-core-1-0-adopt-apis.
|
|
1271
1274
|
sendPiVersionIfChanged();
|
|
@@ -1284,7 +1287,7 @@ function initBridge(pi: ExtensionAPI) {
|
|
|
1284
1287
|
} catch { /* probe failure non-fatal */ }
|
|
1285
1288
|
// A live reconnect keeps in-flight calls open (no fabricated end).
|
|
1286
1289
|
// See change: fix-replay-fabricates-orphan-end-for-live-calls (D3).
|
|
1287
|
-
replaySessionEntries({ liveTailOpen
|
|
1290
|
+
replaySessionEntries({ liveTailOpen });
|
|
1288
1291
|
// Flush subagent frames buffered while the socket was down (D1). Unlike
|
|
1289
1292
|
// session_start, a transient WS reconnect keeps `sessionReady` true, so
|
|
1290
1293
|
// the intercept routes those frames into the per-agent buffer; drain them
|
|
@@ -1338,7 +1341,15 @@ function initBridge(pi: ExtensionAPI) {
|
|
|
1338
1341
|
// See change: fix-terminal-session-dashboard-reload.
|
|
1339
1342
|
const terminalReload = createTerminalReload({ pi, getSessionId: () => inst.sessionId });
|
|
1340
1343
|
|
|
1344
|
+
// One limiter per bridge process: kept in the process-global state so a
|
|
1345
|
+
// `/reload` does not refill the prompt bucket. See change:
|
|
1346
|
+
// harden-bridge-inbound-and-discovery (D17).
|
|
1347
|
+
const bridgeState = getBridgeState();
|
|
1348
|
+
const inboundLimits = (bridgeState.inboundLimits ??= createInboundLimits());
|
|
1349
|
+
inst.inboundLimits = inboundLimits;
|
|
1350
|
+
|
|
1341
1351
|
const commandHandler = createCommandHandler(pi, () => inst.sessionId, {
|
|
1352
|
+
limits: inboundLimits,
|
|
1342
1353
|
getModelRegistry: () => inst.cachedModelRegistry,
|
|
1343
1354
|
// Selector-open re-sync of providers.json: heals a missed credentials_updated.
|
|
1344
1355
|
// See change: refresh-models-on-provider-change (D1).
|
|
@@ -1507,6 +1518,7 @@ function initBridge(pi: ExtensionAPI) {
|
|
|
1507
1518
|
process.cwd(),
|
|
1508
1519
|
inst.sessionId,
|
|
1509
1520
|
(msg) => inst.connection.send(msg),
|
|
1521
|
+
inst.inboundLimits,
|
|
1510
1522
|
);
|
|
1511
1523
|
if (ranExec) {
|
|
1512
1524
|
// Non-turn exec-template route: settle optimistic idle bubble.
|
|
@@ -1687,6 +1699,7 @@ function initBridge(pi: ExtensionAPI) {
|
|
|
1687
1699
|
source: "tui",
|
|
1688
1700
|
pid: process.pid,
|
|
1689
1701
|
provisional: true,
|
|
1702
|
+
...(targetManager?.certValidation ? { certValidation: "enforced" as const } : {}),
|
|
1690
1703
|
});
|
|
1691
1704
|
},
|
|
1692
1705
|
});
|
|
@@ -1807,7 +1820,7 @@ function initBridge(pi: ExtensionAPI) {
|
|
|
1807
1820
|
inst.applyBc = applyBc;
|
|
1808
1821
|
|
|
1809
1822
|
// Local wrappers that sync bc around extracted module calls
|
|
1810
|
-
function sendStateSync() { const bc = syncBc(); _sendStateSync(bc, getFlowsList); applyBc(bc); inst.connection.noteRegistered(); }
|
|
1823
|
+
function sendStateSync(opts?: { liveTailOpen?: boolean }) { const bc = syncBc(); _sendStateSync(bc, getFlowsList, opts); applyBc(bc); inst.connection.noteRegistered(); }
|
|
1811
1824
|
function replaySessionEntries(opts?: { liveTailOpen?: boolean }) { _replaySessionEntries(syncBc(), opts); }
|
|
1812
1825
|
inst.replaySessionEntries = replaySessionEntries;
|
|
1813
1826
|
function sendModelUpdateIfChanged() { const bc = syncBc(); _sendModelUpdateIfChanged(bc); applyBc(bc); }
|
|
@@ -37,6 +37,8 @@ export function registerCanvasTool(pi: ExtensionAPI): void {
|
|
|
37
37
|
"Point the dashboard canvas at a deliverable you're producing (file, url, or a running dev server)",
|
|
38
38
|
promptGuidelines: [
|
|
39
39
|
"Call canvas() when you produce or update a user-facing deliverable — a report/doc/mockup/image (target.kind='file', path relative to the session cwd), a web page (target.kind='url'), or a dev server you started (target.kind='server', port).",
|
|
40
|
+
"For a local server pass its localhost URL (target.kind='url' with http://localhost:<port>/…, or kind='server'), never a LAN/IP URL — the dashboard only embeds loopback servers.",
|
|
41
|
+
"For a local HTML file prefer kind:'file' (relative path): the dashboard serves it with its relative CSS/JS/images instead of needing a server.",
|
|
40
42
|
"Paths MUST be relative to the session cwd — never absolute and never containing '..'.",
|
|
41
43
|
"This is fire-and-forget: it returns immediately and never blocks. Keep working after calling it.",
|
|
42
44
|
"Use mode='pin' to keep the canvas on this artifact across later writes; default 'replace' lets the newest artifact take the slot.",
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
*/
|
|
4
4
|
import { readdirSync, readFileSync, realpathSync, statSync } from "node:fs";
|
|
5
5
|
import { homedir } from "node:os";
|
|
6
|
-
import { dirname, isAbsolute, join, relative } from "node:path";
|
|
6
|
+
import { dirname, isAbsolute, join, relative, resolve } from "node:path";
|
|
7
7
|
import { resolveDashboardPorts } from "@blackbelt-technology/pi-dashboard-shared/config.js";
|
|
8
8
|
import { imageBlockData, imageBlockMime } from "@blackbelt-technology/pi-dashboard-shared/image-block.js";
|
|
9
9
|
import { diffOr } from "@blackbelt-technology/pi-dashboard-shared/platform/git.js";
|
|
@@ -18,10 +18,12 @@ import type { FileEntry, ImageContent, MissingToolError, PiSessionInfo } from "@
|
|
|
18
18
|
import type { ExtensionAPI } from "@earendil-works/pi-coding-agent";
|
|
19
19
|
import { filterHiddenCommands } from "./bridge-context.js";
|
|
20
20
|
import { draftCommitMessage } from "./commit-draft.js";
|
|
21
|
+
import { createInboundLimits, type InboundLimits } from "./inbound-limits.js";
|
|
21
22
|
import { errText, reportRefresh } from "./model-refresh.js";
|
|
22
23
|
import { killProcessByPgid } from "./process-scanner.js";
|
|
23
24
|
import { expandPromptTemplateFromDisk, loadPromptTemplate, readTemplate } from "./prompt-expander.js";
|
|
24
25
|
import { buildProviderCatalogue, toModelInfo } from "./provider-register.js";
|
|
26
|
+
import { resolveServerCliPath } from "./server-launcher.js";
|
|
25
27
|
import { filterByEnabledModels } from "./session-sync.js";
|
|
26
28
|
import { tryDispatchExtensionCommand } from "./slash-dispatch.js";
|
|
27
29
|
|
|
@@ -442,6 +444,13 @@ export function createCommandHandler(
|
|
|
442
444
|
sessionIdOrGetter: string | (() => string),
|
|
443
445
|
options?: {
|
|
444
446
|
getModelRegistry?: () => any;
|
|
447
|
+
/**
|
|
448
|
+
* Process-wide inbound bounds (bash concurrency + prompt bucket). The
|
|
449
|
+
* bridge passes its single instance so the allowance survives `/reload`;
|
|
450
|
+
* absent → a handler-local one built from the environment.
|
|
451
|
+
* See change: harden-bridge-inbound-and-discovery (D17).
|
|
452
|
+
*/
|
|
453
|
+
limits?: InboundLimits;
|
|
445
454
|
/** Re-sync dashboard-registered providers from providers.json (bridge wires
|
|
446
455
|
* `reloadProviders(pi)`). Awaited by `request_models` before the registry
|
|
447
456
|
* refresh. See change: refresh-models-on-provider-change (D1). */
|
|
@@ -637,6 +646,8 @@ export function createCommandHandler(
|
|
|
637
646
|
}, PERSISTENT_ABORT_INTERVAL_MS);
|
|
638
647
|
}
|
|
639
648
|
|
|
649
|
+
const limits = options?.limits ?? createInboundLimits();
|
|
650
|
+
|
|
640
651
|
return {
|
|
641
652
|
async handle(msg: ServerToExtensionMessage): Promise<ExtensionToServerMessage | undefined> {
|
|
642
653
|
const sessionId = getSessionId();
|
|
@@ -715,7 +726,7 @@ export function createCommandHandler(
|
|
|
715
726
|
|
|
716
727
|
// Route based on parsed command type
|
|
717
728
|
if (parsed.type === "bash") {
|
|
718
|
-
await handleBashCommand(pi, sessionId, parsed.command, parsed.excludeFromContext, options?.eventSink);
|
|
729
|
+
await handleBashCommand(pi, sessionId, parsed.command, parsed.excludeFromContext, options?.eventSink, undefined, limits);
|
|
719
730
|
return undefined;
|
|
720
731
|
}
|
|
721
732
|
|
|
@@ -857,7 +868,7 @@ export function createCommandHandler(
|
|
|
857
868
|
// precedence). See change: add-dashboard-slash-commands.
|
|
858
869
|
const ranExec =
|
|
859
870
|
!handled &&
|
|
860
|
-
(await tryExecSlashTemplate(pi, parsed.text, process.cwd(), sessionId, options?.eventSink));
|
|
871
|
+
(await tryExecSlashTemplate(pi, parsed.text, process.cwd(), sessionId, options?.eventSink, limits));
|
|
861
872
|
if (!handled && !ranExec) {
|
|
862
873
|
// sendUserMessage exempt from gating: only typed single-line
|
|
863
874
|
// slashes that are NOT extension commands reach this — i.e.
|
|
@@ -1354,14 +1365,36 @@ function resolveDashboardPort(): number {
|
|
|
1354
1365
|
}
|
|
1355
1366
|
|
|
1356
1367
|
/**
|
|
1357
|
-
*
|
|
1358
|
-
*
|
|
1368
|
+
* A word safe to paste into a bash command line: left bare when it has nothing the shell would
|
|
1369
|
+
* interpret, else POSIX single-quoted (a path with a space, a `'`, a `$`).
|
|
1370
|
+
*/
|
|
1371
|
+
function posixWord(word: string): string {
|
|
1372
|
+
return /^[A-Za-z0-9_@%+=:,./-]+$/.test(word) ? word : `'${word.replace(/'/g, `'\\''`)}'`;
|
|
1373
|
+
}
|
|
1374
|
+
|
|
1375
|
+
/**
|
|
1376
|
+
* Absolute, shell-quoted command that runs the `pi-dashboard` CLI shipped with THIS bridge
|
|
1377
|
+
* (`<node> <server>/bin/pi-dashboard.mjs`), so a template can call a non-observe route with
|
|
1378
|
+
* `eval "$PI_DASHBOARD_CLI" api <METHOD> <path>` (which sends local proof) with no `pi-dashboard` on PATH.
|
|
1379
|
+
* `eval` is what makes the quoting take effect for an install path with a space; a bare
|
|
1380
|
+
* `$PI_DASHBOARD_CLI` expansion also works whenever the path needs no quoting.
|
|
1381
|
+
*/
|
|
1382
|
+
function dashboardCliCommand(): string {
|
|
1383
|
+
const wrapper = resolve(dirname(resolveServerCliPath()), "..", "bin", "pi-dashboard.mjs");
|
|
1384
|
+
return `${posixWord(process.execPath)} ${posixWord(wrapper)}`;
|
|
1385
|
+
}
|
|
1386
|
+
|
|
1387
|
+
/**
|
|
1388
|
+
* Build the env vars exec-mode slash templates rely on: `PI_DASHBOARD_PORT`,
|
|
1389
|
+
* `PI_DASHBOARD_BASE` and `PI_DASHBOARD_CLI`. See changes: add-dashboard-slash-commands,
|
|
1390
|
+
* close-container-loopback-impersonation (D5).
|
|
1359
1391
|
*/
|
|
1360
1392
|
export function buildDashboardExecEnv(): Record<string, string> {
|
|
1361
1393
|
const port = resolveDashboardPort();
|
|
1362
1394
|
return {
|
|
1363
1395
|
PI_DASHBOARD_PORT: String(port),
|
|
1364
1396
|
PI_DASHBOARD_BASE: `http://localhost:${port}`,
|
|
1397
|
+
PI_DASHBOARD_CLI: dashboardCliCommand(),
|
|
1365
1398
|
};
|
|
1366
1399
|
}
|
|
1367
1400
|
|
|
@@ -1382,6 +1415,7 @@ export async function tryExecSlashTemplate(
|
|
|
1382
1415
|
cwd: string,
|
|
1383
1416
|
sessionId: string,
|
|
1384
1417
|
eventSink?: (msg: ExtensionToServerMessage) => void,
|
|
1418
|
+
limits?: InboundLimits,
|
|
1385
1419
|
): Promise<boolean> {
|
|
1386
1420
|
const loaded = loadPromptTemplate(text, cwd, pi as any);
|
|
1387
1421
|
if (!loaded || loaded.kind !== "exec") return false;
|
|
@@ -1393,7 +1427,7 @@ export async function tryExecSlashTemplate(
|
|
|
1393
1427
|
args,
|
|
1394
1428
|
env: buildDashboardExecEnv(),
|
|
1395
1429
|
source: "slash-exec",
|
|
1396
|
-
});
|
|
1430
|
+
}, limits);
|
|
1397
1431
|
return true;
|
|
1398
1432
|
}
|
|
1399
1433
|
|
|
@@ -1466,6 +1500,46 @@ async function handleBashCommand(
|
|
|
1466
1500
|
excludeFromContext: boolean,
|
|
1467
1501
|
eventSink?: (msg: ExtensionToServerMessage) => void,
|
|
1468
1502
|
execOpts?: BashExecOptions,
|
|
1503
|
+
limits?: InboundLimits,
|
|
1504
|
+
): Promise<void> {
|
|
1505
|
+
// Concurrency bound: `!`, `!!` and exec slash templates share ONE counter
|
|
1506
|
+
// per session. A refusal is visible (command_feedback), never silent; the
|
|
1507
|
+
// slot is released on every exit path (success, non-zero, spawn error,
|
|
1508
|
+
// timeout, abort). See change: harden-bridge-inbound-and-discovery (D17).
|
|
1509
|
+
let release: (() => void) | undefined;
|
|
1510
|
+
if (limits) {
|
|
1511
|
+
release = limits.tryAcquireBash(sessionId);
|
|
1512
|
+
if (!release) {
|
|
1513
|
+
eventSink?.({
|
|
1514
|
+
type: "event_forward",
|
|
1515
|
+
sessionId,
|
|
1516
|
+
event: {
|
|
1517
|
+
eventType: "command_feedback",
|
|
1518
|
+
timestamp: Date.now(),
|
|
1519
|
+
data: {
|
|
1520
|
+
command: "bash",
|
|
1521
|
+
status: "error",
|
|
1522
|
+
message: `bash concurrency limit reached (${limits.maxBash} in flight per session) — wait for a running command to finish`,
|
|
1523
|
+
},
|
|
1524
|
+
},
|
|
1525
|
+
});
|
|
1526
|
+
return;
|
|
1527
|
+
}
|
|
1528
|
+
}
|
|
1529
|
+
try {
|
|
1530
|
+
await runBashCommand(pi, sessionId, command, excludeFromContext, eventSink, execOpts);
|
|
1531
|
+
} finally {
|
|
1532
|
+
release?.();
|
|
1533
|
+
}
|
|
1534
|
+
}
|
|
1535
|
+
|
|
1536
|
+
async function runBashCommand(
|
|
1537
|
+
pi: ExtensionAPI,
|
|
1538
|
+
sessionId: string,
|
|
1539
|
+
command: string,
|
|
1540
|
+
excludeFromContext: boolean,
|
|
1541
|
+
eventSink?: (msg: ExtensionToServerMessage) => void,
|
|
1542
|
+
execOpts?: BashExecOptions,
|
|
1469
1543
|
): Promise<void> {
|
|
1470
1544
|
// Resolve the shell binary through the tool registry instead of
|
|
1471
1545
|
// spawning the literal "sh". On a clean Windows host (no Git-for-Windows
|
|
@@ -128,3 +128,26 @@ export function resolveConnectTarget(
|
|
|
128
128
|
}
|
|
129
129
|
}
|
|
130
130
|
}
|
|
131
|
+
|
|
132
|
+
/** The bridge route on the dashboard's native TLS listener. */
|
|
133
|
+
const BRIDGE_WS_PATH = "/ws/bridge";
|
|
134
|
+
|
|
135
|
+
/**
|
|
136
|
+
* The URL actually dialled for `endpoint`: a `wss:` endpoint with an empty or `/`
|
|
137
|
+
* path dials the bridge route (on the TLS listener only `/ws/bridge` is one); any
|
|
138
|
+
* other path (a proxy in front of the gateway) and every `ws:` / `ws+unix:` URL is
|
|
139
|
+
* kept unchanged. The query (the ticket) is preserved. Idempotent.
|
|
140
|
+
*
|
|
141
|
+
* See change: prove-vault-bridge-tls (D7).
|
|
142
|
+
*/
|
|
143
|
+
export function bridgeDialUrl(endpoint: string): string {
|
|
144
|
+
let u: URL;
|
|
145
|
+
try {
|
|
146
|
+
u = new URL(endpoint);
|
|
147
|
+
} catch {
|
|
148
|
+
return endpoint;
|
|
149
|
+
}
|
|
150
|
+
if (u.protocol !== "wss:" || u.pathname !== "/") return endpoint;
|
|
151
|
+
u.pathname = BRIDGE_WS_PATH;
|
|
152
|
+
return u.toString();
|
|
153
|
+
}
|
|
@@ -3,9 +3,13 @@
|
|
|
3
3
|
* and message buffering during disconnection.
|
|
4
4
|
*/
|
|
5
5
|
|
|
6
|
+
import { normalizeQuiesceMs } from "@blackbelt-technology/pi-dashboard-shared/recovery-timing.js";
|
|
6
7
|
import { WebSocket as WsWebSocket } from "ws";
|
|
7
8
|
|
|
9
|
+
import { certValidationFor } from "./bridge-tls-checks.js";
|
|
10
|
+
import { bridgeDialUrl } from "./connect-target.js";
|
|
8
11
|
import { isLoopbackEndpoint as defaultLoopbackClassifier } from "./endpoint-resolution.js";
|
|
12
|
+
import { isRemoteEndpoint } from "./remote-registration-gate.js";
|
|
9
13
|
|
|
10
14
|
/** One migration decision, accepted or refused. The bridge's ONLY record
|
|
11
15
|
* channel for re-targeting — wired to `transportDiagnostics` in bridge.ts so
|
|
@@ -410,7 +414,7 @@ export class ConnectionManager {
|
|
|
410
414
|
* are NOT suppressed.
|
|
411
415
|
* See change: fix-restart-bridge-auto-start-race.
|
|
412
416
|
*/
|
|
413
|
-
private suppressUntil =
|
|
417
|
+
private suppressUntil = -Infinity;
|
|
414
418
|
|
|
415
419
|
/** Upgrade headers presented on every (re)connect. */
|
|
416
420
|
private headers?: Record<string, string>;
|
|
@@ -745,10 +749,15 @@ export class ConnectionManager {
|
|
|
745
749
|
* the suppression window, never shortens it. See change:
|
|
746
750
|
* fix-restart-bridge-auto-start-race.
|
|
747
751
|
*/
|
|
748
|
-
pauseAutoStart(ms: number):
|
|
749
|
-
|
|
750
|
-
|
|
752
|
+
pauseAutoStart(ms: number): number {
|
|
753
|
+
// Every caller is bounded here: invalid -> ignored, fractional -> rounded
|
|
754
|
+
// up, > MAX_QUIESCE_MS (incl. Infinity) -> clamped. Returns the applied
|
|
755
|
+
// pause (0 = ignored). See change: harden-bridge-inbound-and-discovery (D17).
|
|
756
|
+
const applied = normalizeQuiesceMs(ms);
|
|
757
|
+
if (applied === undefined) return 0;
|
|
758
|
+
const next = Date.now() + applied;
|
|
751
759
|
if (next > this.suppressUntil) this.suppressUntil = next;
|
|
760
|
+
return applied;
|
|
752
761
|
}
|
|
753
762
|
|
|
754
763
|
/**
|
|
@@ -756,7 +765,8 @@ export class ConnectionManager {
|
|
|
756
765
|
* See change: fix-restart-bridge-auto-start-race.
|
|
757
766
|
*/
|
|
758
767
|
shouldSuppressAutoStart(): boolean {
|
|
759
|
-
|
|
768
|
+
// `<=`: the pause is "at least quiesceMs" (inclusive deadline).
|
|
769
|
+
return Date.now() <= this.suppressUntil;
|
|
760
770
|
}
|
|
761
771
|
|
|
762
772
|
/**
|
|
@@ -858,7 +868,7 @@ export class ConnectionManager {
|
|
|
858
868
|
reachable = false;
|
|
859
869
|
}
|
|
860
870
|
if (!reachable) {
|
|
861
|
-
return record(false, "refused: candidate health check did not
|
|
871
|
+
return record(false, "refused: candidate health or identity check did not pass");
|
|
862
872
|
}
|
|
863
873
|
|
|
864
874
|
// Localhost preference as an invariant on the connection (D3) — keyed on
|
|
@@ -978,10 +988,23 @@ export class ConnectionManager {
|
|
|
978
988
|
if (!this.intentionalClose) this.scheduleReconnect();
|
|
979
989
|
}
|
|
980
990
|
|
|
981
|
-
|
|
991
|
+
/**
|
|
992
|
+
* `"enforced"` when the TLS checks apply to the current endpoint (a remote
|
|
993
|
+
* `wss:` one with validation not disabled); declared on `session_register` and
|
|
994
|
+
* the vault sync request. See change: prove-vault-bridge-tls (D7).
|
|
995
|
+
*/
|
|
996
|
+
get certValidation(): "enforced" | undefined {
|
|
997
|
+
return certValidationFor(this.url);
|
|
998
|
+
}
|
|
999
|
+
|
|
1000
|
+
private openSocket(rawDialUrl: string = this.url, plan?: DialPlan): void {
|
|
1001
|
+
// A path-less `wss://` endpoint dials the bridge route; a remote `wss` dial
|
|
1002
|
+
// always validates the certificate, whatever the process env says.
|
|
1003
|
+
const dialUrl = bridgeDialUrl(rawDialUrl);
|
|
982
1004
|
const headers = this.headers || plan?.headers ? { ...this.headers, ...plan?.headers } : undefined;
|
|
983
1005
|
const wsOptions: Record<string, unknown> = {};
|
|
984
1006
|
if (headers) wsOptions.headers = headers;
|
|
1007
|
+
if (dialUrl.startsWith("wss:") && isRemoteEndpoint(dialUrl)) wsOptions.rejectUnauthorized = true;
|
|
985
1008
|
if (plan?.createConnection) wsOptions.createConnection = plan.createConnection;
|
|
986
1009
|
this.identityFailure = null;
|
|
987
1010
|
this.dialVerified = false;
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The HTTP origin a REMOTE bridge uses for its `/api/*` calls: ticket mint,
|
|
3
|
+
* server-identity challenge, live trust query.
|
|
4
|
+
*
|
|
5
|
+
* A bridge dials the pi gateway (`PI_DASHBOARD_URL=ws://host:9999`), but the
|
|
6
|
+
* gateway serves bridge WebSockets only; `/api/*` lives on the dashboard HTTP
|
|
7
|
+
* listener (default 8000). Deriving the HTTP origin from the gateway port
|
|
8
|
+
* answered `426` on the mint and read as a revoked credential.
|
|
9
|
+
*
|
|
10
|
+
* Pure: `env` is an argument, never read from `process.env` here, and the
|
|
11
|
+
* bridge machine's own `~/.pi/dashboard/config.json` is deliberately NOT
|
|
12
|
+
* consulted — it describes the local dashboard, not the remote one.
|
|
13
|
+
*
|
|
14
|
+
* Precedence (design D1):
|
|
15
|
+
* 0. `PI_DASHBOARD_HTTP_URL` set but invalid → `bad-http-url`, for every endpoint
|
|
16
|
+
* 1. valid override, in scope (endpoint host == `PI_DASHBOARD_URL` host or override host)
|
|
17
|
+
* 2. plaintext `ws:` with an explicit port → endpoint host + HTTP port env/default
|
|
18
|
+
* 3. `wss:` or port-less `ws:` → endpoint origin with the scheme swapped
|
|
19
|
+
* 4. anything else → `no-http-origin`
|
|
20
|
+
*
|
|
21
|
+
* The bearer therefore only leaves for the endpoint's own host, except where
|
|
22
|
+
* the operator explicitly named another one (step 1, scoped to their hosts).
|
|
23
|
+
*
|
|
24
|
+
* See change: fix-remote-bridge-ticket-origin (D1).
|
|
25
|
+
*/
|
|
26
|
+
import { resolveDashboardPorts } from "@blackbelt-technology/pi-dashboard-shared/config.js";
|
|
27
|
+
|
|
28
|
+
/** Env var naming the dashboard's HTTP origin explicitly. */
|
|
29
|
+
const DASHBOARD_HTTP_URL_ENV = "PI_DASHBOARD_HTTP_URL";
|
|
30
|
+
|
|
31
|
+
type HttpOriginSource = "PI_DASHBOARD_HTTP_URL" | "endpoint-host+http-port" | "endpoint-origin";
|
|
32
|
+
|
|
33
|
+
export type HttpOriginResult =
|
|
34
|
+
| { ok: true; origin: string; source: HttpOriginSource }
|
|
35
|
+
| { ok: false; cause: "bad-http-url" | "no-http-origin"; reason: string };
|
|
36
|
+
|
|
37
|
+
function parseUrl(raw: string): URL | null {
|
|
38
|
+
try {
|
|
39
|
+
return new URL(raw);
|
|
40
|
+
} catch {
|
|
41
|
+
return null;
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
/** `origin` of a valid http(s) URL without credentials; otherwise null. */
|
|
46
|
+
function validOverrideOrigin(raw: string): string | null {
|
|
47
|
+
const u = parseUrl(raw);
|
|
48
|
+
if (!u) return null;
|
|
49
|
+
if (u.protocol !== "http:" && u.protocol !== "https:") return null;
|
|
50
|
+
if (u.username !== "" || u.password !== "") return null;
|
|
51
|
+
return u.origin;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
export function resolveDashboardHttpOrigin(endpoint: string, env: Record<string, string | undefined>): HttpOriginResult {
|
|
55
|
+
const ep = parseUrl(endpoint);
|
|
56
|
+
const override = env[DASHBOARD_HTTP_URL_ENV]?.trim();
|
|
57
|
+
|
|
58
|
+
if (override) {
|
|
59
|
+
const origin = validOverrideOrigin(override);
|
|
60
|
+
if (!origin) {
|
|
61
|
+
return {
|
|
62
|
+
ok: false,
|
|
63
|
+
cause: "bad-http-url",
|
|
64
|
+
reason: `${DASHBOARD_HTTP_URL_ENV} is not an http(s) URL without credentials — fix or unset it`,
|
|
65
|
+
};
|
|
66
|
+
}
|
|
67
|
+
if (ep) {
|
|
68
|
+
const pinnedHost = parseUrl(env.PI_DASHBOARD_URL?.trim() ?? "")?.hostname;
|
|
69
|
+
const overrideHost = parseUrl(override)?.hostname;
|
|
70
|
+
if (ep.hostname === pinnedHost || ep.hostname === overrideHost) {
|
|
71
|
+
return { ok: true, origin, source: "PI_DASHBOARD_HTTP_URL" };
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
if (ep && ep.protocol === "ws:" && ep.port !== "") {
|
|
77
|
+
const { port } = resolveDashboardPorts(env);
|
|
78
|
+
return { ok: true, origin: `http://${ep.hostname}:${port}`, source: "endpoint-host+http-port" };
|
|
79
|
+
}
|
|
80
|
+
if (ep && (ep.protocol === "ws:" || ep.protocol === "wss:")) {
|
|
81
|
+
return {
|
|
82
|
+
ok: true,
|
|
83
|
+
origin: `${ep.protocol === "wss:" ? "https" : "http"}://${ep.host}`,
|
|
84
|
+
source: "endpoint-origin",
|
|
85
|
+
};
|
|
86
|
+
}
|
|
87
|
+
return { ok: false, cause: "no-http-origin", reason: `${endpoint} has no http origin` };
|
|
88
|
+
}
|
|
@@ -2,7 +2,9 @@
|
|
|
2
2
|
* Dev build-on-reload helper.
|
|
3
3
|
* Builds the Vite client and requests server shutdown.
|
|
4
4
|
*/
|
|
5
|
+
import { httpProofHeaders } from "@blackbelt-technology/pi-dashboard-shared/local-credential-proof.js";
|
|
5
6
|
import { execSync as defaultExecSync } from "@blackbelt-technology/pi-dashboard-shared/platform/exec.js";
|
|
7
|
+
import { readLocalToken } from "./local-token-header.js";
|
|
6
8
|
|
|
7
9
|
export interface DevBuildOptions {
|
|
8
10
|
packageRoot: string;
|
|
@@ -11,6 +13,8 @@ export interface DevBuildOptions {
|
|
|
11
13
|
_execSync?: typeof defaultExecSync;
|
|
12
14
|
/** @internal for testing */
|
|
13
15
|
_fetch?: typeof fetch;
|
|
16
|
+
/** @internal for testing: the local token (default: read from `~/.pi/dashboard/local/token`). */
|
|
17
|
+
_token?: string | undefined;
|
|
14
18
|
}
|
|
15
19
|
|
|
16
20
|
/**
|
|
@@ -31,7 +35,13 @@ export function runDevBuild(opts: DevBuildOptions): void {
|
|
|
31
35
|
|
|
32
36
|
try {
|
|
33
37
|
console.log("🛑 Dashboard: stopping server...");
|
|
34
|
-
|
|
38
|
+
// `/api/shutdown` is an operate route: under the strict `requireLocalProof` default a bare POST is
|
|
39
|
+
// refused, so dial the loopback literal and carry a proof for this exact request. No token ⇒ no
|
|
40
|
+
// proof header (the refusal is then the honest answer). See change: close-container-loopback-impersonation (D5).
|
|
41
|
+
const url = `http://127.0.0.1:${opts.serverPort}/api/shutdown`;
|
|
42
|
+
const token = "_token" in opts ? opts._token : readLocalToken();
|
|
43
|
+
const headers = token ? httpProofHeaders(token, url, "POST") : {};
|
|
44
|
+
fetchFn(url, { method: "POST", headers }).catch(() => {});
|
|
35
45
|
console.log("✅ Dashboard: server stopped");
|
|
36
46
|
} catch {
|
|
37
47
|
// Server may not be running — that's fine
|
|
@@ -2,6 +2,8 @@
|
|
|
2
2
|
* Git link builder — parses remote URLs and builds platform-specific links.
|
|
3
3
|
*/
|
|
4
4
|
|
|
5
|
+
import { stripRemoteCredentials } from "@blackbelt-technology/pi-dashboard-shared/remote-credentials.js";
|
|
6
|
+
|
|
5
7
|
export interface GitLinks {
|
|
6
8
|
branchUrl?: string;
|
|
7
9
|
prUrl?: string;
|
|
@@ -24,8 +26,15 @@ const HOST_TO_PLATFORM: Record<string, Platform> = {
|
|
|
24
26
|
"sr.ht": "sourcehut",
|
|
25
27
|
};
|
|
26
28
|
|
|
27
|
-
/** Parse an SSH or HTTPS remote URL into host/user/repo. */
|
|
28
|
-
export function parseRemoteUrl(
|
|
29
|
+
/** Parse an SSH or HTTPS remote URL into host/user/repo. Credentials never reach a link. */
|
|
30
|
+
export function parseRemoteUrl(rawUrl: string): ParsedRemote | undefined {
|
|
31
|
+
// Strip userinfo FIRST so `user:token@host` can never be captured as the host
|
|
32
|
+
// (and so leak into a built link). Unparseable-with-userinfo → no parse, no link.
|
|
33
|
+
// See change: harden-bridge-inbound-and-discovery (D18).
|
|
34
|
+
const stripped = stripRemoteCredentials(rawUrl);
|
|
35
|
+
if (stripped === undefined) return undefined;
|
|
36
|
+
// A query / fragment (`?access_token=…`) is never part of the repository path.
|
|
37
|
+
const url = stripped.replace(/[?#].*$/s, "");
|
|
29
38
|
// SSH: git@host:user/repo.git
|
|
30
39
|
const sshMatch = url.match(/^git@([^:]+):(.+?)(?:\.git)?$/);
|
|
31
40
|
if (sshMatch) {
|