@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
|
@@ -0,0 +1,462 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Route model for server identities: one pure, I/O-free module shared by the
|
|
3
|
+
* dashboard server, the browser client and Electron.
|
|
4
|
+
*
|
|
5
|
+
* A server is its identity (fingerprint); an address at which it answers is a
|
|
6
|
+
* {@link Route}. This module owns the rules that turn addresses into rows:
|
|
7
|
+
* host normalisation, derived route kind (never stored), grouping (D1), best
|
|
8
|
+
* route (D3), validation of routes delivered at pairing (D7) and the pair
|
|
9
|
+
* action per client (D8).
|
|
10
|
+
*
|
|
11
|
+
* See change: group-servers-by-identity (design D1–D4, D7, D8, D11).
|
|
12
|
+
*/
|
|
13
|
+
|
|
14
|
+
export type RouteScheme = "http" | "https";
|
|
15
|
+
/** How a route was learned. `config` is not a source: legacy entries are `saved`. */
|
|
16
|
+
export type RouteSource = "saved" | "mdns" | "pairing";
|
|
17
|
+
export type RouteKind = "loopback" | "lan" | "mdns" | "tunnel" | "public";
|
|
18
|
+
|
|
19
|
+
/** The persisted shape of a route: host, port, scheme and source only (kind is derived). */
|
|
20
|
+
export interface Route {
|
|
21
|
+
host: string;
|
|
22
|
+
port: number;
|
|
23
|
+
scheme: RouteScheme;
|
|
24
|
+
source: RouteSource;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
/** A route is "similar" in latency to another within this many ms (inclusive, D11). */
|
|
28
|
+
export const SIMILAR_LATENCY_MS = 50;
|
|
29
|
+
/** At most this many delivered routes are kept (D7). */
|
|
30
|
+
export const MAX_DELIVERED_ROUTES = 8;
|
|
31
|
+
const MAX_HOST_CHARS = 253;
|
|
32
|
+
|
|
33
|
+
export const ROUTE_SCHEMES: readonly RouteScheme[] = ["http", "https"];
|
|
34
|
+
export const ROUTE_SOURCES: readonly RouteSource[] = ["saved", "mdns", "pairing"];
|
|
35
|
+
|
|
36
|
+
/** Scheme a legacy `host`/`port` pair is read as: `https` on 443, else `http`. */
|
|
37
|
+
export function defaultSchemeForPort(port: number): RouteScheme {
|
|
38
|
+
return port === 443 ? "https" : "http";
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/** Valid TCP port: integer in 1..65535. */
|
|
42
|
+
export function isValidPort(port: unknown): port is number {
|
|
43
|
+
return typeof port === "number" && Number.isInteger(port) && port >= 1 && port <= 65535;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
// ── Host normalisation (D4, D11) ──────────────────────────────────────
|
|
47
|
+
|
|
48
|
+
const IPV4_RE = /^(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})$/;
|
|
49
|
+
|
|
50
|
+
function parseIpv4(text: string): Uint8Array | null {
|
|
51
|
+
const m = IPV4_RE.exec(text);
|
|
52
|
+
if (!m) return null;
|
|
53
|
+
const bytes = new Uint8Array(4);
|
|
54
|
+
for (let i = 0; i < 4; i++) {
|
|
55
|
+
const n = Number(m[i + 1]);
|
|
56
|
+
if (n > 255) return null;
|
|
57
|
+
bytes[i] = n;
|
|
58
|
+
}
|
|
59
|
+
return bytes;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
/** Hex groups of one `::`-free side of an IPv6 literal; null when any group is malformed. */
|
|
63
|
+
function ipv6Groups(side: string): number[] | null {
|
|
64
|
+
if (side === "") return [];
|
|
65
|
+
const out: number[] = [];
|
|
66
|
+
for (const g of side.split(":")) {
|
|
67
|
+
if (!/^[0-9a-f]{1,4}$/i.test(g)) return null;
|
|
68
|
+
out.push(Number.parseInt(g, 16));
|
|
69
|
+
}
|
|
70
|
+
return out;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
/** Parse an IPv6 literal (no brackets, no zone) into 16 bytes; embedded IPv4 tail supported. */
|
|
74
|
+
function parseIpv6(text: string): Uint8Array | null {
|
|
75
|
+
if (!/^[0-9a-f:.]+$/i.test(text) || !text.includes(":")) return null;
|
|
76
|
+
let head = text;
|
|
77
|
+
let tail: number[] = [];
|
|
78
|
+
if (head.includes(".")) {
|
|
79
|
+
const cut = head.lastIndexOf(":");
|
|
80
|
+
const v4 = parseIpv4(head.slice(cut + 1));
|
|
81
|
+
if (!v4) return null;
|
|
82
|
+
tail = [(v4[0] << 8) | v4[1], (v4[2] << 8) | v4[3]];
|
|
83
|
+
// `::1.2.3.4` keeps its `::`; `a:b:1.2.3.4` loses the dangling `:`.
|
|
84
|
+
head = head.slice(0, cut + 1);
|
|
85
|
+
if (!head.endsWith("::")) head = head.slice(0, -1);
|
|
86
|
+
}
|
|
87
|
+
const halves = head.split("::");
|
|
88
|
+
if (halves.length > 2) return null;
|
|
89
|
+
const left = ipv6Groups(halves[0]);
|
|
90
|
+
const right = halves.length === 2 ? ipv6Groups(halves[1]) : [];
|
|
91
|
+
if (!left || !right) return null;
|
|
92
|
+
const zeros = halves.length === 2 ? 8 - left.length - right.length - tail.length : 0;
|
|
93
|
+
const all = [...left, ...new Array<number>(Math.max(zeros, 0)).fill(0), ...right, ...tail];
|
|
94
|
+
if (all.length !== 8 || (halves.length === 2 && zeros < 1)) return null;
|
|
95
|
+
const bytes = new Uint8Array(16);
|
|
96
|
+
all.forEach((g, i) => {
|
|
97
|
+
bytes[i * 2] = g >> 8;
|
|
98
|
+
bytes[i * 2 + 1] = g & 0xff;
|
|
99
|
+
});
|
|
100
|
+
return bytes;
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
function isIpv4Mapped(b: Uint8Array): boolean {
|
|
104
|
+
for (let i = 0; i < 10; i++) if (b[i] !== 0) return false;
|
|
105
|
+
return b[10] === 0xff && b[11] === 0xff;
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
/**
|
|
109
|
+
* One spelling per host: trimmed, lower-cased, brackets and an IPv6 zone id
|
|
110
|
+
* removed, one trailing dot removed, an IPv4-mapped IPv6 literal rewritten as
|
|
111
|
+
* its IPv4 address. Used before classifying and before comparing hosts.
|
|
112
|
+
*/
|
|
113
|
+
export function normalizeHost(host: string): string {
|
|
114
|
+
let h = host.trim().toLowerCase();
|
|
115
|
+
if (h.startsWith("[") && h.endsWith("]")) h = h.slice(1, -1);
|
|
116
|
+
const zone = h.indexOf("%");
|
|
117
|
+
if (zone !== -1) h = h.slice(0, zone);
|
|
118
|
+
if (h.endsWith(".")) h = h.slice(0, -1);
|
|
119
|
+
if (h.includes(":")) {
|
|
120
|
+
const bytes = parseIpv6(h);
|
|
121
|
+
if (bytes && isIpv4Mapped(bytes)) return `${bytes[12]}.${bytes[13]}.${bytes[14]}.${bytes[15]}`;
|
|
122
|
+
}
|
|
123
|
+
return h;
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
/** Stable identity of a route for de-duplication: scheme, normalised host, port. */
|
|
127
|
+
export function routeKey(route: Pick<Route, "host" | "port" | "scheme">): string {
|
|
128
|
+
return `${route.scheme}://${normalizeHost(route.host)}:${route.port}`;
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
// ── Route kind (D4) ───────────────────────────────────────────────────
|
|
132
|
+
|
|
133
|
+
function ipv4Kind(b: Uint8Array): RouteKind {
|
|
134
|
+
if (b[0] === 127) return "loopback";
|
|
135
|
+
if (
|
|
136
|
+
b[0] === 10 ||
|
|
137
|
+
(b[0] === 172 && b[1] >= 16 && b[1] <= 31) ||
|
|
138
|
+
(b[0] === 192 && b[1] === 168) ||
|
|
139
|
+
(b[0] === 100 && b[1] >= 64 && b[1] <= 127) ||
|
|
140
|
+
(b[0] === 169 && b[1] === 254)
|
|
141
|
+
) {
|
|
142
|
+
return "lan";
|
|
143
|
+
}
|
|
144
|
+
return "public";
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
function ipv6Kind(b: Uint8Array): RouteKind {
|
|
148
|
+
if (b.slice(0, 15).every((x) => x === 0) && b[15] === 1) return "loopback";
|
|
149
|
+
if ((b[0] & 0xfe) === 0xfc || (b[0] === 0xfe && (b[1] & 0xc0) === 0x80)) return "lan";
|
|
150
|
+
return "public";
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
/**
|
|
154
|
+
* Derived, never persisted. `lan` mirrors the knock gate's private ranges
|
|
155
|
+
* (a boundary-table test pins them together); `tunnel` is `zrok.io` over https
|
|
156
|
+
* only, the one tunnel host the code names; everything unlisted is `public`.
|
|
157
|
+
*/
|
|
158
|
+
export function classifyRoute(route: { host: string; scheme: RouteScheme }): RouteKind {
|
|
159
|
+
const h = normalizeHost(route.host);
|
|
160
|
+
if (!h) return "public";
|
|
161
|
+
const v4 = parseIpv4(h);
|
|
162
|
+
if (v4) return ipv4Kind(v4);
|
|
163
|
+
if (h.includes(":")) {
|
|
164
|
+
const v6 = parseIpv6(h);
|
|
165
|
+
return v6 ? ipv6Kind(v6) : "public";
|
|
166
|
+
}
|
|
167
|
+
if (h === "localhost") return "loopback";
|
|
168
|
+
if (h.endsWith(".local")) return "mdns";
|
|
169
|
+
if (route.scheme === "https" && (h === "zrok.io" || h.endsWith(".zrok.io"))) return "tunnel";
|
|
170
|
+
if (!h.includes(".") || h.endsWith(".lan") || h.endsWith(".home.arpa") || h.endsWith(".internal")) return "lan";
|
|
171
|
+
return "public";
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
/** On-link = a knock may be possible: kind `lan` or `mdns`, over plain http. */
|
|
175
|
+
export function isOnLinkRoute(route: { host: string; scheme: RouteScheme }): boolean {
|
|
176
|
+
if (route.scheme !== "http") return false;
|
|
177
|
+
const kind = classifyRoute(route);
|
|
178
|
+
return kind === "lan" || kind === "mdns";
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
/** Primary route: the first `http` route, else the first route. */
|
|
182
|
+
export function primaryRoute<R extends Pick<Route, "scheme">>(routes: readonly R[]): R | undefined {
|
|
183
|
+
return routes.find((r) => r.scheme === "http") ?? routes[0];
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
// ── Grouping (D1) ─────────────────────────────────────────────────────
|
|
187
|
+
|
|
188
|
+
export interface RouteEntry {
|
|
189
|
+
fingerprint?: string;
|
|
190
|
+
routes: readonly Route[];
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
/** A route plus the fingerprint it proved (or advertised); none ⇒ identity not known. */
|
|
194
|
+
export interface ProvenRoute {
|
|
195
|
+
route: Route;
|
|
196
|
+
fingerprint?: string;
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
export interface GroupedEntry {
|
|
200
|
+
fingerprint?: string;
|
|
201
|
+
routes: Route[];
|
|
202
|
+
/** Indices (in the result) of other entries holding the same fingerprint on another instance port. */
|
|
203
|
+
sameIdentityAs: number[];
|
|
204
|
+
/** False for an entry with no known fingerprint ("identity not advertised"). */
|
|
205
|
+
identityAdvertised: boolean;
|
|
206
|
+
/** Index of the input entry this one grew from; absent for entries created here. */
|
|
207
|
+
sourceIndex?: number;
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
/** Does `routes` already hold `route` (same scheme, normalised host, port)? */
|
|
211
|
+
function holdsRoute(routes: readonly Route[], route: Route): boolean {
|
|
212
|
+
const key = routeKey(route);
|
|
213
|
+
return routes.some((r) => routeKey(r) === key);
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
/**
|
|
217
|
+
* Index of the entry a route proving `fingerprint` joins, or -1 for "start a
|
|
218
|
+
* new entry". An `https` route joins the FIRST entry holding the fingerprint
|
|
219
|
+
* (stored order decides, not port); an `http` route joins the first holder that
|
|
220
|
+
* has no `http` route yet or already has one on the same port.
|
|
221
|
+
*/
|
|
222
|
+
export function findAttachTarget(entries: readonly RouteEntry[], route: Route, fingerprint: string | undefined): number {
|
|
223
|
+
if (fingerprint === undefined) return -1;
|
|
224
|
+
for (let i = 0; i < entries.length; i++) {
|
|
225
|
+
const entry = entries[i];
|
|
226
|
+
if (entry.fingerprint !== fingerprint) continue;
|
|
227
|
+
if (route.scheme === "https") return i;
|
|
228
|
+
const httpRoutes = entry.routes.filter((r) => r.scheme === "http");
|
|
229
|
+
if (httpRoutes.length === 0 || httpRoutes.some((r) => r.port === route.port)) return i;
|
|
230
|
+
}
|
|
231
|
+
return -1;
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
/**
|
|
235
|
+
* Group `incoming` routes into `entries` (copied, never mutated). A route with
|
|
236
|
+
* no fingerprint joins the entry that already holds the same route, else is a
|
|
237
|
+
* single-route entry. A route already held is not duplicated; the first
|
|
238
|
+
* spelling and source win.
|
|
239
|
+
*/
|
|
240
|
+
export function groupRoutes(entries: readonly RouteEntry[], incoming: readonly ProvenRoute[]): GroupedEntry[] {
|
|
241
|
+
const out: GroupedEntry[] = entries.map((e, i) => ({
|
|
242
|
+
...(e.fingerprint !== undefined ? { fingerprint: e.fingerprint } : {}),
|
|
243
|
+
routes: [...e.routes],
|
|
244
|
+
sameIdentityAs: [],
|
|
245
|
+
identityAdvertised: e.fingerprint !== undefined,
|
|
246
|
+
sourceIndex: i,
|
|
247
|
+
}));
|
|
248
|
+
for (const { route, fingerprint } of incoming) {
|
|
249
|
+
let target = findAttachTarget(out, route, fingerprint);
|
|
250
|
+
if (target === -1 && fingerprint === undefined) {
|
|
251
|
+
target = out.findIndex((e) => holdsRoute(e.routes, route));
|
|
252
|
+
}
|
|
253
|
+
if (target === -1) {
|
|
254
|
+
out.push({
|
|
255
|
+
...(fingerprint !== undefined ? { fingerprint } : {}),
|
|
256
|
+
routes: [route],
|
|
257
|
+
sameIdentityAs: [],
|
|
258
|
+
identityAdvertised: fingerprint !== undefined,
|
|
259
|
+
});
|
|
260
|
+
} else if (!holdsRoute(out[target].routes, route)) {
|
|
261
|
+
out[target].routes.push(route);
|
|
262
|
+
}
|
|
263
|
+
}
|
|
264
|
+
out.forEach((entry, i) => {
|
|
265
|
+
if (entry.fingerprint === undefined) return;
|
|
266
|
+
out.forEach((other, j) => {
|
|
267
|
+
if (j !== i && other.fingerprint === entry.fingerprint) entry.sameIdentityAs.push(j);
|
|
268
|
+
});
|
|
269
|
+
});
|
|
270
|
+
return out;
|
|
271
|
+
}
|
|
272
|
+
|
|
273
|
+
// ── Best route (D3) ───────────────────────────────────────────────────
|
|
274
|
+
|
|
275
|
+
/** A route with its check result; `latencyMs` is the identity-challenge round trip. */
|
|
276
|
+
export type RankableRoute<R extends Route = Route> = R & {
|
|
277
|
+
/** The challenge proved the group's fingerprint. Anything else is never a candidate. */
|
|
278
|
+
proven: boolean;
|
|
279
|
+
latencyMs?: number;
|
|
280
|
+
/** Seen by discovery this session rather than stored (credentialed order only). */
|
|
281
|
+
discovered?: boolean;
|
|
282
|
+
};
|
|
283
|
+
|
|
284
|
+
function fastest<T extends { latencyMs?: number }>(routes: readonly T[]): T | undefined {
|
|
285
|
+
let best: T | undefined;
|
|
286
|
+
for (const r of routes) {
|
|
287
|
+
if (!best || (r.latencyMs ?? Number.POSITIVE_INFINITY) < (best.latencyMs ?? Number.POSITIVE_INFINITY)) best = r;
|
|
288
|
+
}
|
|
289
|
+
return best;
|
|
290
|
+
}
|
|
291
|
+
|
|
292
|
+
/**
|
|
293
|
+
* Pick the route in use among the PROVEN ones; `null` when none is.
|
|
294
|
+
*
|
|
295
|
+
* `credentialed: false` (list marker, in-page switch): `https` wins when its
|
|
296
|
+
* latency is within {@link SIMILAR_LATENCY_MS} of the fastest `http` (inclusive),
|
|
297
|
+
* otherwise the lowest latency wins.
|
|
298
|
+
*
|
|
299
|
+
* `credentialed: true` (the app sends a stored bearer, Electron): stored https,
|
|
300
|
+
* then stored http (input order), then discovered; the first proven route wins
|
|
301
|
+
* and latency is never compared, so a faster http route cannot downgrade a
|
|
302
|
+
* bearer-carrying open to cleartext.
|
|
303
|
+
*/
|
|
304
|
+
export function rankRoutes<R extends RankableRoute>(routes: readonly R[], opts: { credentialed: boolean }): R | null {
|
|
305
|
+
const candidates = routes.filter((r) => r.proven);
|
|
306
|
+
if (candidates.length === 0) return null;
|
|
307
|
+
if (opts.credentialed) {
|
|
308
|
+
const stored = candidates.filter((r) => !r.discovered);
|
|
309
|
+
const discovered = candidates.filter((r) => r.discovered);
|
|
310
|
+
return (
|
|
311
|
+
stored.find((r) => r.scheme === "https") ??
|
|
312
|
+
stored.find((r) => r.scheme === "http") ??
|
|
313
|
+
discovered.find((r) => r.scheme === "https") ??
|
|
314
|
+
discovered[0] ??
|
|
315
|
+
null
|
|
316
|
+
);
|
|
317
|
+
}
|
|
318
|
+
const bestHttp = fastest(candidates.filter((r) => r.scheme === "http"));
|
|
319
|
+
const bestHttps = fastest(candidates.filter((r) => r.scheme === "https"));
|
|
320
|
+
if (!bestHttp) return bestHttps ?? null;
|
|
321
|
+
if (!bestHttps) return bestHttp;
|
|
322
|
+
const gap = (bestHttps.latencyMs ?? Number.POSITIVE_INFINITY) - (bestHttp.latencyMs ?? Number.POSITIVE_INFINITY);
|
|
323
|
+
return gap <= SIMILAR_LATENCY_MS ? bestHttps : bestHttp;
|
|
324
|
+
}
|
|
325
|
+
|
|
326
|
+
// ── Delivered routes (D7) ─────────────────────────────────────────────
|
|
327
|
+
|
|
328
|
+
const DNS_NAME_RE = /^[a-z0-9]([a-z0-9-]*[a-z0-9])?(\.[a-z0-9]([a-z0-9-]*[a-z0-9])?)*$/;
|
|
329
|
+
|
|
330
|
+
/**
|
|
331
|
+
* Validate ONE delivered route origin; returns its normalised origin or null.
|
|
332
|
+
* `https` only; origin only (the bare trailing slash is accepted); a DNS name
|
|
333
|
+
* that is not an IP literal, `localhost` or `*.local`; host at most 253 chars.
|
|
334
|
+
*/
|
|
335
|
+
export function validateDeliveredOrigin(input: unknown): string | null {
|
|
336
|
+
if (typeof input !== "string") return null;
|
|
337
|
+
const m = /^https:\/\/([^/?#@\s\\]+)\/?$/i.exec(input);
|
|
338
|
+
if (!m) return null;
|
|
339
|
+
let url: URL;
|
|
340
|
+
try {
|
|
341
|
+
url = new URL(`https://${m[1]}`);
|
|
342
|
+
} catch {
|
|
343
|
+
return null;
|
|
344
|
+
}
|
|
345
|
+
const host = url.hostname;
|
|
346
|
+
if (host.length === 0 || host.length > MAX_HOST_CHARS) return null;
|
|
347
|
+
if (url.username || url.password) return null;
|
|
348
|
+
const name = host.endsWith(".") ? host.slice(0, -1) : host;
|
|
349
|
+
if (!DNS_NAME_RE.test(name)) return null; // also rejects IPv6 (brackets) and anything URL parsing normalised oddly
|
|
350
|
+
if (parseIpv4(name)) return null;
|
|
351
|
+
if (name === "localhost" || name.endsWith(".local")) return null;
|
|
352
|
+
return url.origin;
|
|
353
|
+
}
|
|
354
|
+
|
|
355
|
+
/**
|
|
356
|
+
* Validate the `routes` of an approved poll or the urls of a pairing payload:
|
|
357
|
+
* keep the valid origins, normalised, de-duplicated, in delivery order, at most
|
|
358
|
+
* {@link MAX_DELIVERED_ROUTES}. Anything not an array yields nothing.
|
|
359
|
+
*/
|
|
360
|
+
export function validateDeliveredRoutes(input: unknown): string[] {
|
|
361
|
+
if (!Array.isArray(input)) return [];
|
|
362
|
+
const out: string[] = [];
|
|
363
|
+
for (const item of input) {
|
|
364
|
+
const origin = validateDeliveredOrigin(item);
|
|
365
|
+
if (origin === null || out.includes(origin)) continue;
|
|
366
|
+
out.push(origin);
|
|
367
|
+
if (out.length >= MAX_DELIVERED_ROUTES) break;
|
|
368
|
+
}
|
|
369
|
+
return out;
|
|
370
|
+
}
|
|
371
|
+
|
|
372
|
+
/** A validated delivered origin as a persistable route (source `pairing`). */
|
|
373
|
+
export function originToRoute(origin: string): Route {
|
|
374
|
+
const url = new URL(origin);
|
|
375
|
+
return { host: url.hostname, port: url.port ? Number(url.port) : 443, scheme: "https", source: "pairing" };
|
|
376
|
+
}
|
|
377
|
+
|
|
378
|
+
// ── Request page URL ──────────────────────────────────────────────────
|
|
379
|
+
|
|
380
|
+
/**
|
|
381
|
+
* `http://<host>:<port>/pair?request`, built only from a route's host and port
|
|
382
|
+
* and refused (null) unless the result round-trips to exactly them: no userinfo,
|
|
383
|
+
* path, query or fragment smuggled in the host, port 1..65535, IPv6 bracketed.
|
|
384
|
+
*/
|
|
385
|
+
export function buildRequestPageUrl(host: string, port: number): string | null {
|
|
386
|
+
if (!isValidPort(port)) return null;
|
|
387
|
+
const bare = host.startsWith("[") && host.endsWith("]") ? host.slice(1, -1) : host;
|
|
388
|
+
if (!bare || /[\s/\\?#@%]/.test(bare)) return null;
|
|
389
|
+
const authority = bare.includes(":") ? `[${bare}]` : bare;
|
|
390
|
+
const built = `http://${authority}:${port}/pair?request`;
|
|
391
|
+
let url: URL;
|
|
392
|
+
try {
|
|
393
|
+
url = new URL(built);
|
|
394
|
+
} catch {
|
|
395
|
+
return null;
|
|
396
|
+
}
|
|
397
|
+
const portOk = url.port === String(port) || (port === 80 && url.port === "");
|
|
398
|
+
const roundTrips =
|
|
399
|
+
url.protocol === "http:" &&
|
|
400
|
+
!url.username &&
|
|
401
|
+
!url.password &&
|
|
402
|
+
url.hostname === authority.toLowerCase() &&
|
|
403
|
+
portOk &&
|
|
404
|
+
url.pathname === "/pair" &&
|
|
405
|
+
url.search === "?request" &&
|
|
406
|
+
url.hash === "";
|
|
407
|
+
return roundTrips ? built : null;
|
|
408
|
+
}
|
|
409
|
+
|
|
410
|
+
// ── Pair action (D8) ──────────────────────────────────────────────────
|
|
411
|
+
|
|
412
|
+
export type PairClient = "browser" | "electron";
|
|
413
|
+
|
|
414
|
+
export interface PairActionInput {
|
|
415
|
+
client: PairClient;
|
|
416
|
+
routes: ReadonlyArray<Route & { discovered?: boolean; inKeyring?: boolean }>;
|
|
417
|
+
/** Advertised or pinned fingerprint of the entry, if any. */
|
|
418
|
+
fingerprint?: string;
|
|
419
|
+
/** This device already holds a credential for the entry. */
|
|
420
|
+
credentialHeld: boolean;
|
|
421
|
+
/** The entry is the dashboard the page is loaded from. */
|
|
422
|
+
isCurrent: boolean;
|
|
423
|
+
}
|
|
424
|
+
|
|
425
|
+
export type PairAction =
|
|
426
|
+
/** Browser: navigate a new context (noopener) to `url`. Electron: `openServerWindow({host, port})`. */
|
|
427
|
+
| { kind: "request-access"; route: Route; url?: string }
|
|
428
|
+
/** Electron only, no fingerprint known: prove, show it in full, request after the user confirms. */
|
|
429
|
+
| { kind: "verify-and-request"; route: Route }
|
|
430
|
+
/** Paste a pairing code; needs a fingerprint to compare against. */
|
|
431
|
+
| { kind: "pair-with-code" };
|
|
432
|
+
|
|
433
|
+
/**
|
|
434
|
+
* The one pair action for an entry this device has no credential for, or null
|
|
435
|
+
* (no action: state text only). A browser sends and proves nothing from the
|
|
436
|
+
* current page — it only navigates to the peer's own request page — so it never
|
|
437
|
+
* verifies a fingerprint. Electron proves identity before anything is sent.
|
|
438
|
+
*/
|
|
439
|
+
export function pairAction(input: PairActionInput): PairAction | null {
|
|
440
|
+
if (input.credentialHeld || input.isCurrent) return null;
|
|
441
|
+
const onLink = input.routes.filter(isOnLinkRoute);
|
|
442
|
+
const code: PairAction | null = input.fingerprint ? { kind: "pair-with-code" } : null;
|
|
443
|
+
|
|
444
|
+
if (input.client === "browser") {
|
|
445
|
+
const ordered = [...onLink.filter((r) => r.discovered), ...onLink.filter((r) => !r.discovered)];
|
|
446
|
+
for (const r of ordered) {
|
|
447
|
+
const url = buildRequestPageUrl(r.host, r.port);
|
|
448
|
+
if (url) return { kind: "request-access", route: toRoute(r), url };
|
|
449
|
+
}
|
|
450
|
+
return code;
|
|
451
|
+
}
|
|
452
|
+
|
|
453
|
+
const discovered = onLink.find((r) => r.discovered);
|
|
454
|
+
if (!input.fingerprint && discovered) return { kind: "verify-and-request", route: toRoute(discovered) };
|
|
455
|
+
const reachable = discovered ?? onLink.find((r) => r.inKeyring);
|
|
456
|
+
if (reachable) return { kind: "request-access", route: toRoute(reachable) };
|
|
457
|
+
return code;
|
|
458
|
+
}
|
|
459
|
+
|
|
460
|
+
function toRoute(r: Route): Route {
|
|
461
|
+
return { host: r.host, port: r.port, scheme: r.scheme, source: r.source };
|
|
462
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Browser route for a session: `/session/<id>[/diff|/editor]`. Pure and
|
|
3
|
+
* base-free; callers prepend their own origin (server `uiUrl` / `diffUrl`).
|
|
4
|
+
* See change: add-session-ui-deep-links-for-agents (D2).
|
|
5
|
+
*/
|
|
6
|
+
export type SessionUiView = "diff" | "editor";
|
|
7
|
+
|
|
8
|
+
export function sessionUiPath(id: string, view?: SessionUiView): string {
|
|
9
|
+
const base = `/session/${encodeURIComponent(id)}`;
|
|
10
|
+
return view ? `${base}/${view}` : base;
|
|
11
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Prefix of a bridge device token issued over a proven TLS channel. The bridge
|
|
3
|
+
* never sends such a token to a non-`https:` origin; the hub refuses (and marks
|
|
4
|
+
* exposed) one presented on a non-proven channel.
|
|
5
|
+
*
|
|
6
|
+
* See change: prove-vault-bridge-tls (D9).
|
|
7
|
+
*/
|
|
8
|
+
export const TLS_ONLY_TOKEN_PREFIX = "pi_tls_";
|
|
9
|
+
|
|
10
|
+
/** 401 error code the hub answers when a `pi_tls_` bearer arrives off a proven channel. */
|
|
11
|
+
export const TLS_ONLY_TOKEN_UNTRUSTED_CHANNEL = "tls_only_token_untrusted_channel";
|
|
12
|
+
|
|
13
|
+
/** True for a TLS-only bridge token. */
|
|
14
|
+
export function isTlsOnlyToken(token: unknown): token is string {
|
|
15
|
+
return typeof token === "string" && token.startsWith(TLS_ONLY_TOKEN_PREFIX);
|
|
16
|
+
}
|
|
@@ -25,8 +25,8 @@ import {
|
|
|
25
25
|
npmGlobalStrategy,
|
|
26
26
|
overrideStrategy,
|
|
27
27
|
pwBrowserProbeStrategy,
|
|
28
|
-
staticNpmStrategy,
|
|
29
28
|
type StrategyDeps,
|
|
29
|
+
staticNpmStrategy,
|
|
30
30
|
whereStrategy,
|
|
31
31
|
} from "./strategies.js";
|
|
32
32
|
import type { InstallHints, Source, Strategy, ToolDefinition } from "./types.js";
|
|
@@ -74,7 +74,7 @@ const INSTALL_HINTS: Record<string, InstallHints> = {
|
|
|
74
74
|
commands: { brew: "brew install bash" },
|
|
75
75
|
},
|
|
76
76
|
win32: {
|
|
77
|
-
manual: "
|
|
77
|
+
manual: "The desktop app ships its own bash. Otherwise install Git for Windows and use its bundled bash. To use WSL bash instead, set windowsBashSource to \"host\" (or set a bash override).",
|
|
78
78
|
commands: {
|
|
79
79
|
winget: "winget install --id Git.Git -e",
|
|
80
80
|
choco: "choco install git",
|
|
@@ -341,9 +341,9 @@ function binaryDef(binaryName: string, deps?: StrategyDeps): ToolDefinition {
|
|
|
341
341
|
managedRuntimeStrategy("node", deps),
|
|
342
342
|
]
|
|
343
343
|
: []),
|
|
344
|
-
// bash resolves the Windows bundled git shell (
|
|
345
|
-
// before PATH lookup. No-op on Unix. See
|
|
346
|
-
// resolve-bundled-bash-on-windows.
|
|
344
|
+
// bash resolves the Windows bundled git shell (usr/bin/bash.exe, a copy
|
|
345
|
+
// of dugite-native's sh.exe) before PATH lookup. No-op on Unix. See
|
|
346
|
+
// change: resolve-bundled-bash-on-windows, fix-windows-bundled-bash-exe.
|
|
347
347
|
...(isBash ? [bundledGitBashStrategy(deps)] : []),
|
|
348
348
|
managedBinStrategy(binaryName, deps),
|
|
349
349
|
whereStrategy(binaryName, deps),
|
|
@@ -8,15 +8,15 @@
|
|
|
8
8
|
*
|
|
9
9
|
* See change: consolidate-tool-resolution (design §2).
|
|
10
10
|
*/
|
|
11
|
-
import { existsSync,
|
|
12
|
-
import os from "node:os";
|
|
11
|
+
import { existsSync, readdirSync, readFileSync, realpathSync } from "node:fs";
|
|
13
12
|
import { createRequire } from "node:module";
|
|
14
|
-
import
|
|
13
|
+
import os from "node:os";
|
|
15
14
|
import path from "node:path";
|
|
16
15
|
import { fileURLToPath } from "node:url";
|
|
17
16
|
import { getManagedBin, getManagedDir } from "../managed-paths.js";
|
|
18
17
|
import { isAppImageSelfHit, ToolResolver } from "../platform/binary-lookup.js";
|
|
19
18
|
import { resolveBundledGitDir } from "../platform/ensure-bundled-git.js";
|
|
19
|
+
import { spawnSync } from "../platform/exec.js";
|
|
20
20
|
import { getManagedNodeBinDir } from "../platform/managed-node-path.js";
|
|
21
21
|
import * as npm from "../platform/npm.js";
|
|
22
22
|
import type { Strategy, StrategyCtx, StrategyResult } from "./types.js";
|
|
@@ -428,16 +428,17 @@ export function bundledNodeStrategy(
|
|
|
428
428
|
|
|
429
429
|
/**
|
|
430
430
|
* Windows-only: resolve `bash` to the bundled dugite-native shell at
|
|
431
|
-
* `<resourcesPath>/git/usr/bin/
|
|
432
|
-
*
|
|
433
|
-
*
|
|
434
|
-
* Tools panel shows bash ✓ instead of "not found".
|
|
431
|
+
* `<resourcesPath>/git/usr/bin/bash.exe` — a byte copy of dugite-native's
|
|
432
|
+
* `sh.exe` (GNU bash under the name `sh`) added by the build step, because pi's
|
|
433
|
+
* getShellConfig resolves only a file named `bash.exe`. This strategy surfaces
|
|
434
|
+
* it as a `bundled` hit so the Tools panel shows bash ✓ instead of "not found".
|
|
435
|
+
* `sh.exe` alone does NOT satisfy it (pi would not find that shell).
|
|
435
436
|
*
|
|
436
437
|
* Fast-fails on non-win32 → chain falls through to `where` (finds
|
|
437
438
|
* /bin/bash on Unix). Uses {@link resolveBundledGitDir} (cmd/git.exe
|
|
438
439
|
* marker) for the bundle root.
|
|
439
440
|
*
|
|
440
|
-
* See change: resolve-bundled-bash-on-windows.
|
|
441
|
+
* See change: resolve-bundled-bash-on-windows, fix-windows-bundled-bash-exe.
|
|
441
442
|
*/
|
|
442
443
|
export function bundledGitBashStrategy(deps?: StrategyDeps): Strategy {
|
|
443
444
|
const { exists } = d(deps);
|
|
@@ -451,9 +452,9 @@ export function bundledGitBashStrategy(deps?: StrategyDeps): Strategy {
|
|
|
451
452
|
exists,
|
|
452
453
|
});
|
|
453
454
|
if (!gitDir) return { ok: false, reason: "no bundled git tree" };
|
|
454
|
-
const
|
|
455
|
-
if (exists(
|
|
456
|
-
return { ok: false, reason: `missing: ${
|
|
455
|
+
const bash = path.win32.join(gitDir, "usr", "bin", "bash.exe");
|
|
456
|
+
if (exists(bash)) return { ok: true, path: bash };
|
|
457
|
+
return { ok: false, reason: `missing: ${bash}` };
|
|
457
458
|
},
|
|
458
459
|
};
|
|
459
460
|
}
|
|
@@ -997,6 +997,60 @@ export interface OpenSpecChange {
|
|
|
997
997
|
* OpenSpec actions are blocked for this change. See change: use-openspec-status-all.
|
|
998
998
|
*/
|
|
999
999
|
error?: { code: string; message: string };
|
|
1000
|
+
/**
|
|
1001
|
+
* Computed change-to-change dependency graph entry (declared + inferred edges,
|
|
1002
|
+
* waves, validator issues). Absent on the fallback poll path (CLI without
|
|
1003
|
+
* `status --all`). See change: add-openspec-change-dependencies.
|
|
1004
|
+
*/
|
|
1005
|
+
dependencies?: ChangeDependencies;
|
|
1006
|
+
}
|
|
1007
|
+
|
|
1008
|
+
/** Where a dependency edge came from. */
|
|
1009
|
+
export type DependencyEdgeSource = "declared" | "inferred-text" | "inferred-capability";
|
|
1010
|
+
|
|
1011
|
+
/** One `blocked by` edge of a change. `satisfied` = the blocker is archived. */
|
|
1012
|
+
export interface DependencyEdge {
|
|
1013
|
+
/** The blocking change name. */
|
|
1014
|
+
change: string;
|
|
1015
|
+
source: DependencyEdgeSource;
|
|
1016
|
+
/** Declared reason, matched proposal line (≤ 200 chars) or capability name. */
|
|
1017
|
+
reason?: string;
|
|
1018
|
+
state: "open" | "satisfied";
|
|
1019
|
+
}
|
|
1020
|
+
|
|
1021
|
+
export type DependencyIssueCode =
|
|
1022
|
+
| "invalid-file"
|
|
1023
|
+
| "self-reference"
|
|
1024
|
+
| "cycle"
|
|
1025
|
+
| "blocked-by-cycle"
|
|
1026
|
+
| "unknown-change"
|
|
1027
|
+
| "conflicting-entry"
|
|
1028
|
+
| "duplicate-capability";
|
|
1029
|
+
|
|
1030
|
+
export interface DependencyIssue {
|
|
1031
|
+
severity: "error" | "warning";
|
|
1032
|
+
code: DependencyIssueCode;
|
|
1033
|
+
message: string;
|
|
1034
|
+
/** Canonical cycle path (`cycle` only), e.g. `["a", "b", "a"]`. */
|
|
1035
|
+
path?: string[];
|
|
1036
|
+
/** Other change names involved (`duplicate-capability`, `unknown-change`, `conflicting-entry`). */
|
|
1037
|
+
with?: string[];
|
|
1038
|
+
}
|
|
1039
|
+
|
|
1040
|
+
/** Computed dependency entry of one active change. See change: add-openspec-change-dependencies. */
|
|
1041
|
+
export interface ChangeDependencies {
|
|
1042
|
+
/** Whether `dependencies.yaml` exists for the change. */
|
|
1043
|
+
hasFile: boolean;
|
|
1044
|
+
blockedBy: DependencyEdge[];
|
|
1045
|
+
/** Active changes with an open edge to this one (computed inverse). */
|
|
1046
|
+
blocks: string[];
|
|
1047
|
+
/** Non-blocking references (declared `related` + backticked prose mentions). */
|
|
1048
|
+
related: string[];
|
|
1049
|
+
/** Active changes sharing a capability delta (undirected, never blocking). */
|
|
1050
|
+
overlaps: string[];
|
|
1051
|
+
/** Execution wave (1 = no open blockers); `null` for cycle members and their dependents. */
|
|
1052
|
+
wave: number | null;
|
|
1053
|
+
issues: DependencyIssue[];
|
|
1000
1054
|
}
|
|
1001
1055
|
|
|
1002
1056
|
/** Schema version for the per-repo OpenSpec groups file at
|
|
@@ -1399,6 +1453,18 @@ export interface OpenSpecWorkflowSchemaStatus {
|
|
|
1399
1453
|
* See change: add-pi-spec-driven-schema.
|
|
1400
1454
|
*/
|
|
1401
1455
|
projectSchemas: string[];
|
|
1456
|
+
/**
|
|
1457
|
+
* Members of `affectedChanges` without a regular `dependencies.yaml`; with
|
|
1458
|
+
* patch v2 they stay in planning until they declare. Absent until the server
|
|
1459
|
+
* computes it. See change: add-openspec-change-dependencies.
|
|
1460
|
+
*/
|
|
1461
|
+
undeclaredChanges?: string[];
|
|
1462
|
+
/**
|
|
1463
|
+
* True when the pending `outdated` update lifts the installed stamp across the patch that adds the
|
|
1464
|
+
* required `dependencies` artifact; gates the Update dialog's "return to planning" message.
|
|
1465
|
+
* See change: add-openspec-change-dependencies.
|
|
1466
|
+
*/
|
|
1467
|
+
raisesToDependencies?: boolean;
|
|
1402
1468
|
}
|
|
1403
1469
|
|
|
1404
1470
|
/** OpenSpec workflow phase detected from tool calls */
|