@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
|
@@ -28,6 +28,11 @@ import { fileURLToPath } from "node:url";
|
|
|
28
28
|
* pi-dashboard pair deny <pendingId>
|
|
29
29
|
* Approve/deny a pending device pairing from this host. The code is read from a
|
|
30
30
|
* prompt or stdin; --code is visible in `ps`.
|
|
31
|
+
* pi-dashboard api <METHOD> <path> [--data <json>] [--port n]
|
|
32
|
+
* Call the running dashboard's REST API with a freshly minted local proof
|
|
33
|
+
* (what curl cannot do under the strict `requireLocalProof` default).
|
|
34
|
+
* Exit 0 on 2xx, 1 on any other status (body on stderr), 2 on usage error
|
|
35
|
+
* or server not running.
|
|
31
36
|
*
|
|
32
37
|
* Flags:
|
|
33
38
|
* --port <n> HTTP port (default: 8000)
|
|
@@ -42,6 +47,7 @@ import { fileURLToPath } from "node:url";
|
|
|
42
47
|
import { ensureConfig, loadConfig, SERVER_STARTUP_DEADLINE_MS } from "@blackbelt-technology/pi-dashboard-shared/config.js";
|
|
43
48
|
import { getDashboardConfigDir } from "@blackbelt-technology/pi-dashboard-shared/dashboard-paths.js";
|
|
44
49
|
import { isLauncherOrigin } from "@blackbelt-technology/pi-dashboard-shared/launcher-origin.js";
|
|
50
|
+
import { isSafeLocalPath } from "@blackbelt-technology/pi-dashboard-shared/safe-local-path.js";
|
|
45
51
|
import { httpProofHeaders, localDialHost } from "@blackbelt-technology/pi-dashboard-shared/local-credential-proof.js";
|
|
46
52
|
import {
|
|
47
53
|
findPortHolders as platformFindPortHolders,
|
|
@@ -100,6 +106,42 @@ import { servicesPaths } from "./services/paths.js";
|
|
|
100
106
|
|
|
101
107
|
const SUBCOMMANDS = ["start", "stop", "restart", "status", "runtime", "open"] as const;
|
|
102
108
|
type Subcommand = (typeof SUBCOMMANDS)[number];
|
|
109
|
+
/** Words dispatched to their own command (before `parseArgs`), not to a daemon subcommand. */
|
|
110
|
+
const COMMAND_WORDS = ["token", "service", "pair", "login", "api"] as const;
|
|
111
|
+
type CommandWord = (typeof COMMAND_WORDS)[number];
|
|
112
|
+
/** Flags whose NEXT token is their value, never the subcommand word. */
|
|
113
|
+
const VALUE_FLAGS: ReadonlySet<string> = new Set(["--port", "--host", "--pi-port", "--url", "--data", "--code", "--name", "--tier"]);
|
|
114
|
+
|
|
115
|
+
/** The one-line usage printed for an unknown subcommand word (exit 2). */
|
|
116
|
+
export const CLI_USAGE =
|
|
117
|
+
"usage: pi-dashboard [start|stop|restart|status|runtime|open|pair|token|service|login|api] [flags] (no word: run in the foreground)";
|
|
118
|
+
|
|
119
|
+
export type ArgvClass =
|
|
120
|
+
| { kind: "none" }
|
|
121
|
+
| { kind: "subcommand"; word: Subcommand; index: number }
|
|
122
|
+
| { kind: "command"; word: CommandWord; index: number }
|
|
123
|
+
| { kind: "unknown"; word: string; index: number };
|
|
124
|
+
|
|
125
|
+
/**
|
|
126
|
+
* The subcommand word: the FIRST positional that is not a flag value. `--port 9000 api GET /x`
|
|
127
|
+
* resolves to `api` (9000 is `--port`'s value). One scan serves `api`, `token`, `service`,
|
|
128
|
+
* `pair`, `login` and the daemon subcommands, so none of them can be missed behind a flag.
|
|
129
|
+
* A flag-only invocation has no word and runs in the foreground.
|
|
130
|
+
*/
|
|
131
|
+
export function classifyArgv(args: readonly string[]): ArgvClass {
|
|
132
|
+
for (let i = 0; i < args.length; i++) {
|
|
133
|
+
const a = args[i] as string;
|
|
134
|
+
if (a === "--") break;
|
|
135
|
+
if (a.startsWith("-")) {
|
|
136
|
+
if (VALUE_FLAGS.has(a)) i++; // skip its value
|
|
137
|
+
continue;
|
|
138
|
+
}
|
|
139
|
+
if ((SUBCOMMANDS as readonly string[]).includes(a)) return { kind: "subcommand", word: a as Subcommand, index: i };
|
|
140
|
+
if ((COMMAND_WORDS as readonly string[]).includes(a)) return { kind: "command", word: a as CommandWord, index: i };
|
|
141
|
+
return { kind: "unknown", word: a, index: i };
|
|
142
|
+
}
|
|
143
|
+
return { kind: "none" };
|
|
144
|
+
}
|
|
103
145
|
|
|
104
146
|
export interface ParsedArgs {
|
|
105
147
|
subcommand: Subcommand | null;
|
|
@@ -1043,7 +1085,30 @@ export async function cmdLogin(
|
|
|
1043
1085
|
err(`[login] failed to issue a code: ${json.error ?? "unknown error"}`);
|
|
1044
1086
|
return 1;
|
|
1045
1087
|
}
|
|
1046
|
-
|
|
1088
|
+
// The browser that opens the link is a plain tab: under the strict `requireLocalProof` default it
|
|
1089
|
+
// cannot even redeem the code (`/api/identity/local-exchange` needs proof), so route it through the
|
|
1090
|
+
// local-proof bootstrap first — same as `pi-dashboard open` — and land on the `pi_local` link.
|
|
1091
|
+
// Falls back to the plain link when no proof code can be minted.
|
|
1092
|
+
const plain = `/?pi_local=${encodeURIComponent(json.data.code)}`;
|
|
1093
|
+
let link = `${base}${plain}`;
|
|
1094
|
+
try {
|
|
1095
|
+
const proofUrl = `${localBase(opts)}/api/local-proof`;
|
|
1096
|
+
const pr = await fetchFn(proofUrl, {
|
|
1097
|
+
method: "POST",
|
|
1098
|
+
headers: { "content-type": "application/json", ...localCredentialHeaders("POST", proofUrl, localToken) },
|
|
1099
|
+
body: "{}",
|
|
1100
|
+
signal: AbortSignal.timeout(deps.timeoutMs ?? 5000),
|
|
1101
|
+
});
|
|
1102
|
+
if (pr.ok) {
|
|
1103
|
+
const pj = (await pr.json()) as { success?: boolean; data?: { code?: string } };
|
|
1104
|
+
if (pj.success && typeof pj.data?.code === "string") {
|
|
1105
|
+
link = `${base}/auth/local-proof?code=${encodeURIComponent(pj.data.code)}&next=${encodeURIComponent(plain)}`;
|
|
1106
|
+
}
|
|
1107
|
+
}
|
|
1108
|
+
} catch {
|
|
1109
|
+
/* keep the plain link */
|
|
1110
|
+
}
|
|
1111
|
+
out(link);
|
|
1047
1112
|
out(`Open this link on this machine within ${json.data.expiresInSeconds} s (single-use). You sign in as the local operator (break-glass).`);
|
|
1048
1113
|
return 0;
|
|
1049
1114
|
} catch (e) {
|
|
@@ -1052,6 +1117,98 @@ export async function cmdLogin(
|
|
|
1052
1117
|
}
|
|
1053
1118
|
}
|
|
1054
1119
|
|
|
1120
|
+
/** HTTP methods `pi-dashboard api` accepts. */
|
|
1121
|
+
const API_METHODS: ReadonlySet<string> = new Set(["GET", "POST", "PUT", "PATCH", "DELETE"]);
|
|
1122
|
+
|
|
1123
|
+
export interface CmdApiDeps {
|
|
1124
|
+
fetchImpl?: typeof fetch;
|
|
1125
|
+
out?: (text: string) => void;
|
|
1126
|
+
err?: (line: string) => void;
|
|
1127
|
+
/** Local token; defaults to the on-disk one (created if absent — the server owns it). */
|
|
1128
|
+
localToken?: string | null;
|
|
1129
|
+
timeoutMs?: number;
|
|
1130
|
+
}
|
|
1131
|
+
|
|
1132
|
+
/**
|
|
1133
|
+
* `pi-dashboard api <METHOD> <path> [--data <json>] [--port n]` — call the running dashboard's REST
|
|
1134
|
+
* API from a shell with a freshly minted local proof, which a bare `curl` cannot do under the
|
|
1135
|
+
* strict `requireLocalProof` default. It dials the address literal `restart` dials, sends ONE proof
|
|
1136
|
+
* for this method + target, and never follows a redirect (a `Location` to another origin must not
|
|
1137
|
+
* receive the proof's request). The path is checked by the same predicate the OAuth return-URL
|
|
1138
|
+
* sanitiser uses, plus `#`; a rejected path sends nothing.
|
|
1139
|
+
*
|
|
1140
|
+
* Exit: 0 on 2xx (body on stdout) · 1 on any other status (body on stderr) · 2 on a usage error
|
|
1141
|
+
* or when the server is not running.
|
|
1142
|
+
* See change: close-container-loopback-impersonation (D4).
|
|
1143
|
+
*/
|
|
1144
|
+
export async function cmdApi(
|
|
1145
|
+
argv: string[],
|
|
1146
|
+
opts: { port: number; host?: string },
|
|
1147
|
+
deps: CmdApiDeps = {},
|
|
1148
|
+
): Promise<number> {
|
|
1149
|
+
const out = deps.out ?? ((t: string) => process.stdout.write(t.endsWith("\n") ? t : `${t}\n`));
|
|
1150
|
+
const err = deps.err ?? ((l: string) => console.error(l));
|
|
1151
|
+
const usage = (why: string): number => {
|
|
1152
|
+
err(`[api] ${why}`);
|
|
1153
|
+
err("usage: pi-dashboard api <GET|POST|PUT|PATCH|DELETE> </path> [--data <json>] [--port <n>]");
|
|
1154
|
+
return 2;
|
|
1155
|
+
};
|
|
1156
|
+
|
|
1157
|
+
const positionals: string[] = [];
|
|
1158
|
+
let data: string | undefined;
|
|
1159
|
+
for (let i = 0; i < argv.length; i++) {
|
|
1160
|
+
const a = argv[i] as string;
|
|
1161
|
+
if (a === "--data") {
|
|
1162
|
+
data = argv[++i];
|
|
1163
|
+
if (data === undefined) return usage("--data needs a JSON value");
|
|
1164
|
+
} else if (a.startsWith("-")) {
|
|
1165
|
+
if (VALUE_FLAGS.has(a)) i++; // --port/--host value: already applied by buildConfig
|
|
1166
|
+
} else {
|
|
1167
|
+
positionals.push(a);
|
|
1168
|
+
}
|
|
1169
|
+
}
|
|
1170
|
+
if (positionals.length !== 2) return usage("expected a method and a path");
|
|
1171
|
+
const method = (positionals[0] as string).toUpperCase();
|
|
1172
|
+
const target = positionals[1] as string;
|
|
1173
|
+
if (!API_METHODS.has(method)) return usage(`unsupported method ${terminalSafe(positionals[0] as string, 20)}`);
|
|
1174
|
+
if (!isSafeLocalPath(target) || target.includes("#")) return usage("path must be a same-origin path starting with a single '/' (no '#', no control characters)");
|
|
1175
|
+
if (data !== undefined) {
|
|
1176
|
+
try {
|
|
1177
|
+
JSON.parse(data);
|
|
1178
|
+
} catch {
|
|
1179
|
+
return usage("--data must be valid JSON");
|
|
1180
|
+
}
|
|
1181
|
+
}
|
|
1182
|
+
|
|
1183
|
+
const url = `${localBase(opts)}${target}`;
|
|
1184
|
+
const token = deps.localToken !== undefined ? deps.localToken : safeEnsureLocalToken();
|
|
1185
|
+
const fetchFn = deps.fetchImpl ?? fetch;
|
|
1186
|
+
let res: Response;
|
|
1187
|
+
try {
|
|
1188
|
+
res = await fetchFn(url, {
|
|
1189
|
+
method,
|
|
1190
|
+
redirect: "manual",
|
|
1191
|
+
headers: {
|
|
1192
|
+
...(data !== undefined ? { "content-type": "application/json" } : {}),
|
|
1193
|
+
...localCredentialHeaders(method, url, token),
|
|
1194
|
+
},
|
|
1195
|
+
...(data !== undefined ? { body: data } : {}),
|
|
1196
|
+
signal: AbortSignal.timeout(deps.timeoutMs ?? 30_000),
|
|
1197
|
+
});
|
|
1198
|
+
} catch (e) {
|
|
1199
|
+
err(`[api] dashboard server not running at ${localBase(opts)} (${(e as Error).message ?? e})`);
|
|
1200
|
+
return 2;
|
|
1201
|
+
}
|
|
1202
|
+
const body = await res.text().catch(() => "");
|
|
1203
|
+
if (res.status >= 200 && res.status < 300) {
|
|
1204
|
+
if (body) out(body);
|
|
1205
|
+
return 0;
|
|
1206
|
+
}
|
|
1207
|
+
if (body) err(body);
|
|
1208
|
+
else err(`[api] HTTP ${res.status}`);
|
|
1209
|
+
return 1;
|
|
1210
|
+
}
|
|
1211
|
+
|
|
1055
1212
|
/** The dial base for local calls: the address LITERAL the server's bind maps to, never `localhost`. */
|
|
1056
1213
|
function localBase(c: { host?: string; port: number }): string {
|
|
1057
1214
|
return `http://${localDialHost(c.host)}:${c.port}`;
|
|
@@ -1737,6 +1894,14 @@ function flagValue(args: string[], flag: string): string | undefined {
|
|
|
1737
1894
|
|
|
1738
1895
|
async function main() {
|
|
1739
1896
|
installCrashSafetyNet();
|
|
1897
|
+
// Refuse an unknown subcommand word BEFORE anything is created or bound: an older binary fell
|
|
1898
|
+
// through to the foreground server for it. Flag-only invocations still run in the foreground.
|
|
1899
|
+
const early = classifyArgv(process.argv.slice(2));
|
|
1900
|
+
if (early.kind === "unknown") {
|
|
1901
|
+
console.error(`[cli] unknown subcommand '${terminalSafe(early.word, 40)}'`);
|
|
1902
|
+
console.error(CLI_USAGE);
|
|
1903
|
+
process.exit(2);
|
|
1904
|
+
}
|
|
1740
1905
|
ensureConfig();
|
|
1741
1906
|
// One-shot: rewrite a pre-flip materialized `subagentTickThrottleMs: 0`.
|
|
1742
1907
|
// Boot path only — `loadConfig` is a pure read called by every bridge
|
|
@@ -1744,45 +1909,51 @@ async function main() {
|
|
|
1744
1909
|
migrateSubagentTickThrottle();
|
|
1745
1910
|
|
|
1746
1911
|
const rawArgs = process.argv.slice(2);
|
|
1747
|
-
|
|
1748
|
-
|
|
1749
|
-
|
|
1750
|
-
|
|
1751
|
-
|
|
1752
|
-
|
|
1753
|
-
|
|
1754
|
-
|
|
1755
|
-
|
|
1756
|
-
|
|
1757
|
-
|
|
1758
|
-
|
|
1759
|
-
|
|
1760
|
-
|
|
1761
|
-
|
|
1762
|
-
|
|
1763
|
-
|
|
1764
|
-
|
|
1765
|
-
|
|
1766
|
-
|
|
1767
|
-
|
|
1768
|
-
|
|
1769
|
-
|
|
1770
|
-
|
|
1771
|
-
|
|
1772
|
-
|
|
1773
|
-
|
|
1774
|
-
|
|
1775
|
-
|
|
1776
|
-
|
|
1777
|
-
|
|
1912
|
+
const cls = classifyArgv(rawArgs);
|
|
1913
|
+
if (cls.kind === "command") {
|
|
1914
|
+
// Everything but the command word: its own args plus any flags that came BEFORE it (`--port 9000 api …`).
|
|
1915
|
+
const rest = [...rawArgs.slice(0, cls.index), ...rawArgs.slice(cls.index + 1)];
|
|
1916
|
+
if (cls.word === "token") {
|
|
1917
|
+
const { flags } = parseArgs(rest);
|
|
1918
|
+
const config = buildConfig(flags);
|
|
1919
|
+
process.exit(await cmdTokenCreate(rest, { port: config.port, host: config.host }));
|
|
1920
|
+
}
|
|
1921
|
+
if (cls.word === "service") {
|
|
1922
|
+
// Managed services consumer contract. See change: add-service-registry-core.
|
|
1923
|
+
const { flags } = parseArgs(rest);
|
|
1924
|
+
const config = buildConfig(flags, () => {});
|
|
1925
|
+
const resolveBinary = (name: string) => {
|
|
1926
|
+
try {
|
|
1927
|
+
const r = getDefaultRegistry().resolve(name);
|
|
1928
|
+
return r.ok ? r.path : null;
|
|
1929
|
+
} catch {
|
|
1930
|
+
return null;
|
|
1931
|
+
}
|
|
1932
|
+
};
|
|
1933
|
+
process.exit(
|
|
1934
|
+
await cmdService(rest, {
|
|
1935
|
+
port: config.port,
|
|
1936
|
+
host: config.host,
|
|
1937
|
+
authHeaders: (method, target) => localCredentialHeaders(method, `${localBase(config)}${target}`),
|
|
1938
|
+
resolveExecSecrets: localExecSecretsResolver({ paths: servicesPaths(), run: defaultCommandRunner, resolveBinary }),
|
|
1939
|
+
}),
|
|
1940
|
+
);
|
|
1941
|
+
}
|
|
1942
|
+
if (cls.word === "pair") {
|
|
1943
|
+
// Host-side approval of a pending device. See change: fix-pairing-approval-credential.
|
|
1944
|
+
const { flags } = parseArgs(rest);
|
|
1945
|
+
const config = buildConfig(flags, () => {});
|
|
1946
|
+
process.exit(await cmdPair(rest, { port: config.port, host: config.host }));
|
|
1947
|
+
}
|
|
1948
|
+
if (cls.word === "login") {
|
|
1949
|
+
const { flags } = parseArgs(rest);
|
|
1950
|
+
const config = buildConfig(flags);
|
|
1951
|
+
process.exit(await cmdLogin(rest, { port: config.port, host: config.host }));
|
|
1952
|
+
}
|
|
1953
|
+
// api
|
|
1954
|
+
const { flags } = parseArgs(rest);
|
|
1778
1955
|
const config = buildConfig(flags, () => {});
|
|
1779
|
-
process.exit(await
|
|
1780
|
-
}
|
|
1781
|
-
|
|
1782
|
-
if (rawArgs[0] === "login") {
|
|
1783
|
-
const { flags } = parseArgs(rawArgs.slice(1));
|
|
1784
|
-
const config = buildConfig(flags);
|
|
1785
|
-
process.exit(await cmdLogin(rawArgs.slice(1), { port: config.port, host: config.host }));
|
|
1956
|
+
process.exit(await cmdApi(rest, { port: config.port, host: config.host }));
|
|
1786
1957
|
}
|
|
1787
1958
|
|
|
1788
1959
|
const { subcommand, flags } = parseArgs(rawArgs);
|
|
@@ -13,7 +13,10 @@ import {
|
|
|
13
13
|
loadConfig,
|
|
14
14
|
writeConfigFileSecure,
|
|
15
15
|
} from "@blackbelt-technology/pi-dashboard-shared/config.js";
|
|
16
|
-
import {
|
|
16
|
+
import {
|
|
17
|
+
setWindowsBashSourceSetting,
|
|
18
|
+
setWindowsGitSourceSetting,
|
|
19
|
+
} from "@blackbelt-technology/pi-dashboard-shared/platform/git-source.js";
|
|
17
20
|
import { getPiTrustMirror } from "./access/pi-trust-mirror-service.js";
|
|
18
21
|
import { refreshModelRegistry } from "./model-proxy/registry-singleton.js";
|
|
19
22
|
|
|
@@ -305,6 +308,9 @@ export function writeConfigPartial(
|
|
|
305
308
|
mergedAuth.capabilityRoutePlugins = partial.auth.capabilityRoutePlugins;
|
|
306
309
|
}
|
|
307
310
|
|
|
311
|
+
// `auth.trustedPlugins` is deliberately NOT merged: only the trust endpoints write it
|
|
312
|
+
// (`auth/plugin-trust-store.ts`). `mergedAuth` starts from the stored auth block and copies only the
|
|
313
|
+
// keys named above, so the stored list is kept whatever the body carries (design D12, R1).
|
|
308
314
|
partial.auth = mergedAuth;
|
|
309
315
|
}
|
|
310
316
|
|
|
@@ -484,6 +490,11 @@ export function writeConfigPartial(
|
|
|
484
490
|
if (partial.windowsGitSource === "auto" || partial.windowsGitSource === "host" || partial.windowsGitSource === "bundled") {
|
|
485
491
|
setWindowsGitSourceSetting(partial.windowsGitSource);
|
|
486
492
|
}
|
|
493
|
+
// windowsBashSource: same live-apply contract (moves bundled usr/bin on the
|
|
494
|
+
// spawn PATH for new children). See change: fix-windows-bundled-bash-exe.
|
|
495
|
+
if (partial.windowsBashSource === "bundled" || partial.windowsBashSource === "host") {
|
|
496
|
+
setWindowsBashSourceSetting(partial.windowsBashSource);
|
|
497
|
+
}
|
|
487
498
|
|
|
488
499
|
return { success: true, restartRequired };
|
|
489
500
|
} catch (err: any) {
|
|
@@ -491,6 +502,17 @@ export function writeConfigPartial(
|
|
|
491
502
|
}
|
|
492
503
|
}
|
|
493
504
|
|
|
505
|
+
/**
|
|
506
|
+
* Seed the Windows git/bash source state from the stored config so spawn-env
|
|
507
|
+
* augmentation (ToolResolver.buildSpawnEnv + PTY) places the bundled tree
|
|
508
|
+
* correctly. Called once at server startup; reads, never writes. No-op effect
|
|
509
|
+
* on macOS/Linux. See change: embed-git-bash-on-windows, fix-windows-bundled-bash-exe.
|
|
510
|
+
*/
|
|
511
|
+
export function seedWindowsSourceSettings(cfg: DashboardConfig = loadConfig()): void {
|
|
512
|
+
setWindowsGitSourceSetting(cfg.windowsGitSource);
|
|
513
|
+
setWindowsBashSourceSetting(cfg.windowsBashSource);
|
|
514
|
+
}
|
|
515
|
+
|
|
494
516
|
/**
|
|
495
517
|
* One-shot boot migration: a stored `subagentTickThrottleMs: 0` that predates
|
|
496
518
|
* the default flip is rewritten to the current default and marked.
|
|
@@ -27,6 +27,10 @@ let cached: DashboardConfig | null = null;
|
|
|
27
27
|
/** `${mtimeMs}:${size}` of the file behind `cached`; `""` = never loaded. */
|
|
28
28
|
let cachedStamp = "";
|
|
29
29
|
let parseCount = 0;
|
|
30
|
+
/** Raw `requireLocalProof` as found in the file behind `cached`; `undefined` = absent or a valid boolean. */
|
|
31
|
+
let cachedRlpInvalid: { raw: unknown } | undefined;
|
|
32
|
+
/** Last non-boolean value already warned about (JSON-keyed), so the log never repeats. */
|
|
33
|
+
let lastWarnedRlp: string | undefined;
|
|
30
34
|
|
|
31
35
|
/** Resolved per call — `os.homedir()` follows `$HOME`, which tests reassign. */
|
|
32
36
|
function configFile(): string {
|
|
@@ -68,6 +72,24 @@ function parsesCleanly(): boolean {
|
|
|
68
72
|
}
|
|
69
73
|
}
|
|
70
74
|
|
|
75
|
+
/**
|
|
76
|
+
* A PRESENT, non-boolean `requireLocalProof` in the file (e.g. a quoted
|
|
77
|
+
* `"false"` rollback attempt). It parses as strict, so the operator must be told.
|
|
78
|
+
* Read here, not in `loadConfig`, which every bridge process also runs.
|
|
79
|
+
* See change: close-container-loopback-impersonation (D1).
|
|
80
|
+
*/
|
|
81
|
+
function readInvalidRequireLocalProof(): { raw: unknown } | undefined {
|
|
82
|
+
try {
|
|
83
|
+
const parsed = JSON.parse(fs.readFileSync(configFile(), "utf-8")) as Record<string, unknown> | null;
|
|
84
|
+
if (parsed && typeof parsed === "object" && "requireLocalProof" in parsed && typeof parsed.requireLocalProof !== "boolean") {
|
|
85
|
+
return { raw: parsed.requireLocalProof };
|
|
86
|
+
}
|
|
87
|
+
} catch {
|
|
88
|
+
/* absent / unparseable → nothing to report */
|
|
89
|
+
}
|
|
90
|
+
return undefined;
|
|
91
|
+
}
|
|
92
|
+
|
|
71
93
|
/**
|
|
72
94
|
* The current config, reparsed only when the file changed since the last call.
|
|
73
95
|
* Callers MUST NOT mutate the returned object — it is shared. When the file
|
|
@@ -91,6 +113,7 @@ export function getConfigSnapshot(): DashboardConfig {
|
|
|
91
113
|
}
|
|
92
114
|
cached = loadConfig();
|
|
93
115
|
cachedStamp = current;
|
|
116
|
+
cachedRlpInvalid = readInvalidRequireLocalProof();
|
|
94
117
|
parseCount++;
|
|
95
118
|
return cached;
|
|
96
119
|
}
|
|
@@ -104,6 +127,11 @@ export function liveCorsAllowedOrigins(fallback: string[] = []): string[] {
|
|
|
104
127
|
return getConfigSnapshot().cors?.allowedOrigins ?? fallback;
|
|
105
128
|
}
|
|
106
129
|
|
|
130
|
+
/** `cors.allowZrokWildcard` as of this request (live; boolean `true` only). */
|
|
131
|
+
export function liveCorsAllowZrokWildcard(): boolean {
|
|
132
|
+
return getConfigSnapshot().cors?.allowZrokWildcard === true;
|
|
133
|
+
}
|
|
134
|
+
|
|
107
135
|
/** Trusted networks as of this request (top-level ∪ `auth.bypassHosts`). */
|
|
108
136
|
export function liveTrustedNetworks(fallback: string[] = []): string[] {
|
|
109
137
|
return getConfigSnapshot().resolvedTrustedNetworks ?? fallback;
|
|
@@ -111,7 +139,24 @@ export function liveTrustedNetworks(fallback: string[] = []): string[] {
|
|
|
111
139
|
|
|
112
140
|
/** `requireLocalProof` as of this request (live, no restart). */
|
|
113
141
|
export function liveRequireLocalProof(): boolean {
|
|
114
|
-
|
|
142
|
+
const effective = getConfigSnapshot().requireLocalProof !== false;
|
|
143
|
+
if (cachedRlpInvalid) {
|
|
144
|
+
const key = JSON.stringify(cachedRlpInvalid.raw) ?? "undefined";
|
|
145
|
+
if (key !== lastWarnedRlp) {
|
|
146
|
+
lastWarnedRlp = key;
|
|
147
|
+
console.warn(
|
|
148
|
+
`[config] requireLocalProof=${key} is not a boolean; treating it as true (strict). Use an explicit \`false\` to opt out.`,
|
|
149
|
+
);
|
|
150
|
+
}
|
|
151
|
+
} else {
|
|
152
|
+
lastWarnedRlp = undefined;
|
|
153
|
+
}
|
|
154
|
+
return effective;
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
/** `liveServer.previewExposure` as of this request (`"exposed"` forces exposed; otherwise `undefined`). See change: improve-canvas-html-and-url-ux. */
|
|
158
|
+
export function livePreviewExposureOverride(): string | undefined {
|
|
159
|
+
return getConfigSnapshot().liveServer?.previewExposure;
|
|
115
160
|
}
|
|
116
161
|
|
|
117
162
|
/** `pairing.acceptLanRequests` as of this request (live, no restart). See change: add-lan-knock-pairing. */
|
|
@@ -152,6 +197,8 @@ export function resetConfigSnapshot(): void {
|
|
|
152
197
|
cached = null;
|
|
153
198
|
cachedStamp = "";
|
|
154
199
|
parseCount = 0;
|
|
200
|
+
cachedRlpInvalid = undefined;
|
|
201
|
+
lastWarnedRlp = undefined;
|
|
155
202
|
}
|
|
156
203
|
|
|
157
204
|
/** How many full read+parse cycles happened. Test-only observability (P3/P4). */
|