@vibecontrols/plugin-sdk 2026.1107.1 → 2026.1110.1

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.
Files changed (51) hide show
  1. package/README.md +1 -1
  2. package/dist/audit/index.d.ts +7 -13
  3. package/dist/audit/index.js +13 -14
  4. package/dist/broadcast/index.d.ts +6 -12
  5. package/dist/broadcast/index.js +8 -9
  6. package/dist/cli/index.d.ts +7 -72
  7. package/dist/cli/index.js +1 -104
  8. package/dist/cli-CGyu31Cn.js +104 -0
  9. package/dist/config/index.d.ts +18 -24
  10. package/dist/config/index.js +56 -61
  11. package/dist/context/index.d.ts +26 -32
  12. package/dist/context/index.js +33 -21
  13. package/dist/contract/index.d.ts +2 -413
  14. package/dist/contract/index.js +11 -12
  15. package/dist/host/fs-safety.d.ts +13 -17
  16. package/dist/host/fs-safety.js +223 -217
  17. package/dist/host/os.d.ts +2 -68
  18. package/dist/host/os.js +15 -7
  19. package/dist/host/paths.d.ts +2 -36
  20. package/dist/host/paths.js +44 -44
  21. package/dist/host/request-security.d.ts +6 -7
  22. package/dist/host/request-security.js +26 -14
  23. package/dist/http/index.d.ts +23 -25
  24. package/dist/http/index.js +60 -65
  25. package/dist/index-BM4zNXSR.d.ts +25 -0
  26. package/dist/index-D946chPf.d.ts +410 -0
  27. package/dist/index-Q_hnxaN_.d.ts +60 -0
  28. package/dist/index.d.ts +44 -18
  29. package/dist/index.js +16 -749
  30. package/dist/install/index.d.ts +46 -50
  31. package/dist/install/index.js +269 -189
  32. package/dist/lifecycle/index.d.ts +24 -30
  33. package/dist/lifecycle/index.js +18 -30
  34. package/dist/log/index.d.ts +10 -15
  35. package/dist/log/index.js +19 -20
  36. package/dist/os-DoFa9kjr.d.ts +67 -0
  37. package/dist/paths-h28H4Xeb.d.ts +35 -0
  38. package/dist/providers/index.d.ts +50 -56
  39. package/dist/providers/index.js +101 -126
  40. package/dist/routes/index.d.ts +22 -28
  41. package/dist/routes/index.js +80 -72
  42. package/dist/storage/index.d.ts +2 -38
  43. package/dist/storage/index.js +1 -67
  44. package/dist/storage-DkNBaJHC.js +64 -0
  45. package/dist/subprocess/index.d.ts +5 -11
  46. package/dist/subprocess/index.js +85 -56
  47. package/dist/telemetry/index.d.ts +15 -21
  48. package/dist/telemetry/index.js +35 -36
  49. package/dist/testing/index.d.ts +6 -28
  50. package/dist/testing/index.js +87 -88
  51. package/package.json +10 -10
@@ -1,5 +1,3 @@
1
- import { ChildProcess } from 'node:child_process';
2
-
3
1
  /**
4
2
  * @vibecontrols/plugin-sdk/install
5
3
  *
@@ -24,45 +22,45 @@ import { ChildProcess } from 'node:child_process';
24
22
  * out to `tar` (POSIX + Windows 10+) / `unzip` (POSIX, with a `tar.exe`
25
23
  * fallback on Windows).
26
24
  */
27
-
28
- type ToolPlatform = "linux-x64" | "linux-arm64" | "darwin-x64" | "darwin-arm64" | "win32-x64" | "win32-arm64";
29
- declare function currentPlatform(): ToolPlatform;
30
- interface BinaryDownload {
31
- /** Direct download URL for this platform (HTTPS). */
32
- url: string;
33
- /** Optional sha256 of the downloaded artifact; verified before use when set. */
34
- sha256?: string;
35
- /** Archive format. Inferred from the URL extension when omitted. */
36
- archive?: "tar.gz" | "zip" | "raw";
37
- /** Path to the binary inside the archive (for tar.gz/zip). */
38
- binaryWithinArchive?: string;
25
+ import { ChildProcess } from "node:child_process";
26
+ export type ToolPlatform = "linux-x64" | "linux-arm64" | "darwin-x64" | "darwin-arm64" | "win32-x64" | "win32-arm64";
27
+ export declare function currentPlatform(): ToolPlatform;
28
+ export interface BinaryDownload {
29
+ /** Direct download URL for this platform (HTTPS). */
30
+ url: string;
31
+ /** Optional sha256 of the downloaded artifact; verified before use when set. */
32
+ sha256?: string;
33
+ /** Archive format. Inferred from the URL extension when omitted. */
34
+ archive?: "tar.gz" | "zip" | "raw";
35
+ /** Path to the binary inside the archive (for tar.gz/zip). */
36
+ binaryWithinArchive?: string;
39
37
  }
40
- interface InstallLogger {
41
- info?: (msg: string) => void;
42
- warn?: (msg: string) => void;
43
- error?: (msg: string) => void;
38
+ export interface InstallLogger {
39
+ info?: (msg: string) => void;
40
+ warn?: (msg: string) => void;
41
+ error?: (msg: string) => void;
44
42
  }
45
- interface InstallBinarySpec {
46
- /** Tool key — also the cache subdir and default binary name. */
47
- name: string;
48
- /** Installed binary filename (`.exe` is appended on Windows if absent). */
49
- binaryName?: string;
50
- /** Per-platform download manifest. */
51
- downloads: Partial<Record<ToolPlatform, BinaryDownload>>;
52
- /** Args used for the post-install / PATH sanity check. Default `["--version"]`. */
53
- versionArgs?: string[];
54
- /** Regex applied to the version output to accept a PATH/cache binary. */
55
- versionMatcher?: string;
56
- /** Override platform detection (testing). */
57
- platform?: ToolPlatform;
58
- /** Override the cache root (testing). Default `~/.boff/vibecontrols/tools`. */
59
- cacheRoot?: string;
60
- log?: InstallLogger;
43
+ export interface InstallBinarySpec {
44
+ /** Tool key — also the cache subdir and default binary name. */
45
+ name: string;
46
+ /** Installed binary filename (`.exe` is appended on Windows if absent). */
47
+ binaryName?: string;
48
+ /** Per-platform download manifest. */
49
+ downloads: Partial<Record<ToolPlatform, BinaryDownload>>;
50
+ /** Args used for the post-install / PATH sanity check. Default `["--version"]`. */
51
+ versionArgs?: string[];
52
+ /** Regex applied to the version output to accept a PATH/cache binary. */
53
+ versionMatcher?: string;
54
+ /** Override platform detection (testing). */
55
+ platform?: ToolPlatform;
56
+ /** Override the cache root (testing). Default `~/.boff/vibecontrols/tools`. */
57
+ cacheRoot?: string;
58
+ log?: InstallLogger;
61
59
  }
62
60
  /** Stable per-machine cache root for provider-installed binaries. */
63
- declare function toolsCacheRoot(): string;
61
+ export declare function toolsCacheRoot(): string;
64
62
  /** Absolute path the binary lives at once installed by this module. */
65
- declare function cachedBinaryPath(name: string, binaryName?: string, cacheRoot?: string): string;
63
+ export declare function cachedBinaryPath(name: string, binaryName?: string, cacheRoot?: string): string;
66
64
  /**
67
65
  * Resolve a binary WITHOUT downloading — synchronous, safe to call from hot
68
66
  * paths (e.g. a `resolve<tool>Cmd()` used on every spawn). Checks the provider
@@ -70,24 +68,24 @@ declare function cachedBinaryPath(name: string, binaryName?: string, cacheRoot?:
70
68
  * the CURRENT `process.env.PATH` (not the snapshot `Bun.which` would otherwise
71
69
  * use). Returns the absolute path, or null when not installed.
72
70
  */
73
- declare function resolveBinary(name: string, binaryName?: string, cacheRoot?: string): string | null;
71
+ export declare function resolveBinary(name: string, binaryName?: string, cacheRoot?: string): string | null;
74
72
  /**
75
73
  * Resolve a binary, downloading + installing it into the cache if it is not
76
74
  * already available. Returns the absolute path. Throws when no manifest entry
77
75
  * exists for the current platform or the download fails.
78
76
  */
79
- declare function installBinary(spec: InstallBinarySpec): Promise<string>;
77
+ export declare function installBinary(spec: InstallBinarySpec): Promise<string>;
80
78
  /**
81
79
  * Canonical cloudflared release-asset manifest. Imported by both the agent
82
80
  * bootstrap and the cloudflare provider — the ONE source of truth for the
83
81
  * binary the quick tunnel uses.
84
82
  */
85
- declare const CLOUDFLARED_DOWNLOADS: Partial<Record<ToolPlatform, BinaryDownload>>;
86
- interface QuickTunnel {
87
- /** The advertised public quick-tunnel URL. */
88
- url: string;
89
- /** The spawned cloudflared child (caller owns its lifecycle / handover). */
90
- child: ChildProcess;
83
+ export declare const CLOUDFLARED_DOWNLOADS: Partial<Record<ToolPlatform, BinaryDownload>>;
84
+ export interface QuickTunnel {
85
+ /** The advertised public quick-tunnel URL. */
86
+ url: string;
87
+ /** The spawned cloudflared child (caller owns its lifecycle / handover). */
88
+ child: ChildProcess;
91
89
  }
92
90
  /**
93
91
  * Open a minimal cloudflared quick tunnel to `http://127.0.0.1:<port>` and
@@ -99,9 +97,7 @@ interface QuickTunnel {
99
97
  * pre-registration exception; the provider owns the full tunnel lifecycle
100
98
  * post-registration.
101
99
  */
102
- declare function openQuickTunnel(port: number, opts?: {
103
- log?: InstallLogger;
104
- timeoutMs?: number;
105
- }): Promise<QuickTunnel | null>;
106
-
107
- export { type BinaryDownload, CLOUDFLARED_DOWNLOADS, type InstallBinarySpec, type InstallLogger, type QuickTunnel, type ToolPlatform, cachedBinaryPath, currentPlatform, installBinary, openQuickTunnel, resolveBinary, toolsCacheRoot };
100
+ export declare function openQuickTunnel(port: number, opts?: {
101
+ log?: InstallLogger;
102
+ timeoutMs?: number;
103
+ }): Promise<QuickTunnel | null>;
@@ -1,215 +1,295 @@
1
- import { spawn } from 'child_process';
2
- import { createHash } from 'crypto';
3
- import { existsSync, promises, createWriteStream } from 'fs';
4
- import { homedir, tmpdir } from 'os';
5
- import * as path from 'path';
6
- import { Readable } from 'stream';
7
- import { pipeline } from 'stream/promises';
8
-
1
+ import { homedir, tmpdir } from "node:os";
2
+ import * as path$1 from "node:path";
3
+ import { spawn } from "node:child_process";
4
+ import { createHash } from "node:crypto";
5
+ import { createWriteStream, existsSync, promises } from "node:fs";
6
+ import { Readable } from "node:stream";
7
+ import { pipeline } from "node:stream/promises";
9
8
  // src/install/index.ts
9
+ /**
10
+ * @vibecontrols/plugin-sdk/install
11
+ *
12
+ * Cross-platform binary auto-installer for provider plugins. A provider that
13
+ * needs an external binary (a tunnel daemon, a terminal server, …) ships a
14
+ * per-platform download manifest and calls `installBinary()` from its
15
+ * `/prereqs/install`. The binary lands in a stable per-machine cache that the
16
+ * provider resolves by ABSOLUTE PATH, so it is immune to the PATH snapshot
17
+ * `Bun.which()` takes at process start — a mid-run install is otherwise
18
+ * invisible to the daemon until a restart (notably on Windows, where a freshly
19
+ * installed tool's directory isn't on the running process's PATH at all).
20
+ *
21
+ * This keeps binary ownership inside the provider: the thin agent installs no
22
+ * provider tool itself; it only triggers the provider's `/prereqs` protocol.
23
+ *
24
+ * Resolution order: provider cache → $PATH (current env) → download.
25
+ * sha256 is OPTIONAL — when a manifest entry pins it, the download is verified
26
+ * before use; otherwise the HTTPS download plus an optional `--version` sanity
27
+ * check are the integrity gate.
28
+ *
29
+ * Cross-platform: pure node built-ins + Bun.which. Archive extraction shells
30
+ * out to `tar` (POSIX + Windows 10+) / `unzip` (POSIX, with a `tar.exe`
31
+ * fallback on Windows).
32
+ */
10
33
  function currentPlatform() {
11
- const arch = process.arch === "x64" ? "x64" : "arm64";
12
- const osName = process.platform === "win32" ? "win32" : process.platform === "darwin" ? "darwin" : "linux";
13
- return `${osName}-${arch}`;
34
+ const arch = process.arch === "x64" ? "x64" : "arm64";
35
+ return `${process.platform === "win32" ? "win32" : process.platform === "darwin" ? "darwin" : "linux"}-${arch}`;
14
36
  }
37
+ /** Stable per-machine cache root for provider-installed binaries. */
15
38
  function toolsCacheRoot() {
16
- return path.join(homedir(), ".boff", "vibecontrols", "tools");
39
+ return path$1.join(homedir(), ".boff", "vibecontrols", "tools");
17
40
  }
18
41
  function binFileName(name, binaryName) {
19
- const base = binaryName ?? name;
20
- if (process.platform === "win32" && !base.toLowerCase().endsWith(".exe")) {
21
- return `${base}.exe`;
22
- }
23
- return base;
42
+ const base = binaryName ?? name;
43
+ if (process.platform === "win32" && !base.toLowerCase().endsWith(".exe")) return `${base}.exe`;
44
+ return base;
24
45
  }
46
+ /** Absolute path the binary lives at once installed by this module. */
25
47
  function cachedBinaryPath(name, binaryName, cacheRoot) {
26
- return path.join(cacheRoot ?? toolsCacheRoot(), name, binFileName(name, binaryName));
48
+ return path$1.join(cacheRoot ?? toolsCacheRoot(), name, binFileName(name, binaryName));
27
49
  }
50
+ /**
51
+ * Resolve a binary WITHOUT downloading — synchronous, safe to call from hot
52
+ * paths (e.g. a `resolve<tool>Cmd()` used on every spawn). Checks the provider
53
+ * cache first (absolute path, immune to the PATH snapshot), then `$PATH` using
54
+ * the CURRENT `process.env.PATH` (not the snapshot `Bun.which` would otherwise
55
+ * use). Returns the absolute path, or null when not installed.
56
+ */
28
57
  function resolveBinary(name, binaryName, cacheRoot) {
29
- const cached = cachedBinaryPath(name, binaryName, cacheRoot);
30
- if (existsSync(cached)) return cached;
31
- try {
32
- const onPath = typeof Bun !== "undefined" && typeof Bun.which === "function" ? Bun.which(binaryName ?? name, { PATH: process.env.PATH }) : null;
33
- if (onPath) return onPath;
34
- } catch {
35
- }
36
- return null;
58
+ const cached = cachedBinaryPath(name, binaryName, cacheRoot);
59
+ if (existsSync(cached)) return cached;
60
+ try {
61
+ const onPath = typeof Bun !== "undefined" && typeof Bun.which === "function" ? Bun.which(binaryName ?? name, { PATH: process.env.PATH }) : null;
62
+ if (onPath) return onPath;
63
+ } catch {}
64
+ return null;
37
65
  }
38
66
  async function versionOk(binaryPath, spec) {
39
- if (!spec.versionMatcher) return true;
40
- return new Promise((resolve) => {
41
- const child = spawn(binaryPath, spec.versionArgs ?? ["--version"], {
42
- stdio: ["ignore", "pipe", "pipe"]
43
- });
44
- let out = "";
45
- child.stdout.on("data", (b) => out += b.toString());
46
- child.stderr.on("data", (b) => out += b.toString());
47
- child.on("close", () => {
48
- try {
49
- resolve(new RegExp(spec.versionMatcher).test(out));
50
- } catch {
51
- resolve(false);
52
- }
53
- });
54
- child.on("error", () => resolve(false));
55
- });
67
+ if (!spec.versionMatcher) return true;
68
+ return new Promise((resolve) => {
69
+ const child = spawn(binaryPath, spec.versionArgs ?? ["--version"], { stdio: [
70
+ "ignore",
71
+ "pipe",
72
+ "pipe"
73
+ ] });
74
+ let out = "";
75
+ child.stdout.on("data", (b) => out += b.toString());
76
+ child.stderr.on("data", (b) => out += b.toString());
77
+ child.on("close", () => {
78
+ try {
79
+ resolve(new RegExp(spec.versionMatcher).test(out));
80
+ } catch {
81
+ resolve(false);
82
+ }
83
+ });
84
+ child.on("error", () => resolve(false));
85
+ });
56
86
  }
87
+ /**
88
+ * Resolve a binary, downloading + installing it into the cache if it is not
89
+ * already available. Returns the absolute path. Throws when no manifest entry
90
+ * exists for the current platform or the download fails.
91
+ */
57
92
  async function installBinary(spec) {
58
- const platform = spec.platform ?? currentPlatform();
59
- const binaryName = binFileName(spec.name, spec.binaryName);
60
- const cached = cachedBinaryPath(spec.name, spec.binaryName, spec.cacheRoot);
61
- if (existsSync(cached) && await versionOk(cached, spec)) return cached;
62
- try {
63
- const onPath = typeof Bun !== "undefined" && typeof Bun.which === "function" ? Bun.which(spec.binaryName ?? spec.name, { PATH: process.env.PATH }) : null;
64
- if (onPath && await versionOk(onPath, spec)) {
65
- spec.log?.info?.(`[install] using PATH binary ${spec.name} (${onPath})`);
66
- return onPath;
67
- }
68
- } catch {
69
- }
70
- const download = spec.downloads[platform];
71
- if (!download) {
72
- throw new Error(`[install] no download manifest entry for ${spec.name} on ${platform}`);
73
- }
74
- spec.log?.info?.(`[install] downloading ${spec.name} for ${platform}`);
75
- await promises.mkdir(path.dirname(cached), { recursive: true });
76
- await downloadAndInstall(download, cached, binaryName, spec.name);
77
- spec.log?.info?.(`[install] installed ${spec.name} \u2192 ${cached}`);
78
- return cached;
93
+ const platform = spec.platform ?? currentPlatform();
94
+ const binaryName = binFileName(spec.name, spec.binaryName);
95
+ const cached = cachedBinaryPath(spec.name, spec.binaryName, spec.cacheRoot);
96
+ if (existsSync(cached) && await versionOk(cached, spec)) return cached;
97
+ try {
98
+ const onPath = typeof Bun !== "undefined" && typeof Bun.which === "function" ? Bun.which(spec.binaryName ?? spec.name, { PATH: process.env.PATH }) : null;
99
+ if (onPath && await versionOk(onPath, spec)) {
100
+ spec.log?.info?.(`[install] using PATH binary ${spec.name} (${onPath})`);
101
+ return onPath;
102
+ }
103
+ } catch {}
104
+ const download = spec.downloads[platform];
105
+ if (!download) throw new Error(`[install] no download manifest entry for ${spec.name} on ${platform}`);
106
+ spec.log?.info?.(`[install] downloading ${spec.name} for ${platform}`);
107
+ await promises.mkdir(path$1.dirname(cached), { recursive: true });
108
+ await downloadAndInstall(download, cached, binaryName, spec.name);
109
+ spec.log?.info?.(`[install] installed ${spec.name} → ${cached}`);
110
+ return cached;
79
111
  }
80
112
  async function downloadAndInstall(d, destBinary, binaryName, toolName) {
81
- const destDir = path.dirname(destBinary);
82
- const tmp = path.join(tmpdir(), `vibe-install-${toolName}-${process.pid}`);
83
- await promises.mkdir(tmp, { recursive: true });
84
- const archivePath = path.join(tmp, "artifact");
85
- try {
86
- const res = await fetch(d.url, { redirect: "follow" });
87
- if (!res.ok) throw new Error(`download failed (${res.status}) for ${d.url}`);
88
- if (!res.body) throw new Error(`empty response body for ${d.url}`);
89
- await pipeline(Readable.fromWeb(res.body), createWriteStream(archivePath));
90
- if (d.sha256) {
91
- const actual = createHash("sha256").update(await promises.readFile(archivePath)).digest("hex");
92
- if (actual !== d.sha256) {
93
- throw new Error(`sha256 mismatch for ${toolName}: expected ${d.sha256}, got ${actual}`);
94
- }
95
- }
96
- const archiveType = d.archive ?? (d.url.endsWith(".tar.gz") || d.url.endsWith(".tgz") ? "tar.gz" : d.url.endsWith(".zip") ? "zip" : "raw");
97
- if (archiveType === "raw") {
98
- await promises.copyFile(archivePath, destBinary);
99
- } else {
100
- if (archiveType === "tar.gz") {
101
- await runProcess("tar", ["-xzf", archivePath, "-C", tmp]);
102
- } else {
103
- await extractZip(archivePath, tmp);
104
- }
105
- const inner = d.binaryWithinArchive ?? binaryName;
106
- await promises.copyFile(path.join(tmp, inner), destBinary);
107
- }
108
- if (process.platform !== "win32") {
109
- await promises.chmod(destBinary, 493);
110
- }
111
- void destDir;
112
- } finally {
113
- await promises.rm(tmp, { recursive: true, force: true });
114
- }
113
+ path$1.dirname(destBinary);
114
+ const tmp = path$1.join(tmpdir(), `vibe-install-${toolName}-${process.pid}`);
115
+ await promises.mkdir(tmp, { recursive: true });
116
+ const archivePath = path$1.join(tmp, "artifact");
117
+ try {
118
+ const res = await fetch(d.url, { redirect: "follow" });
119
+ if (!res.ok) throw new Error(`download failed (${res.status}) for ${d.url}`);
120
+ if (!res.body) throw new Error(`empty response body for ${d.url}`);
121
+ await pipeline(Readable.fromWeb(res.body), createWriteStream(archivePath));
122
+ if (d.sha256) {
123
+ const actual = createHash("sha256").update(await promises.readFile(archivePath)).digest("hex");
124
+ if (actual !== d.sha256) throw new Error(`sha256 mismatch for ${toolName}: expected ${d.sha256}, got ${actual}`);
125
+ }
126
+ const archiveType = d.archive ?? (d.url.endsWith(".tar.gz") || d.url.endsWith(".tgz") ? "tar.gz" : d.url.endsWith(".zip") ? "zip" : "raw");
127
+ if (archiveType === "raw") await promises.copyFile(archivePath, destBinary);
128
+ else {
129
+ if (archiveType === "tar.gz") await runProcess("tar", [
130
+ "-xzf",
131
+ archivePath,
132
+ "-C",
133
+ tmp
134
+ ]);
135
+ else await extractZip(archivePath, tmp);
136
+ const inner = d.binaryWithinArchive ?? binaryName;
137
+ await promises.copyFile(path$1.join(tmp, inner), destBinary);
138
+ }
139
+ if (process.platform !== "win32") await promises.chmod(destBinary, 493);
140
+ } finally {
141
+ await promises.rm(tmp, {
142
+ recursive: true,
143
+ force: true
144
+ });
145
+ }
115
146
  }
116
147
  async function extractZip(archive, dest) {
117
- try {
118
- await runProcess("unzip", ["-q", "-o", archive, "-d", dest]);
119
- return;
120
- } catch (err) {
121
- if (process.platform !== "win32") throw err;
122
- await runProcess("tar", ["-xf", archive, "-C", dest]);
123
- }
148
+ try {
149
+ await runProcess("unzip", [
150
+ "-q",
151
+ "-o",
152
+ archive,
153
+ "-d",
154
+ dest
155
+ ]);
156
+ return;
157
+ } catch (err) {
158
+ if (process.platform !== "win32") throw err;
159
+ await runProcess("tar", [
160
+ "-xf",
161
+ archive,
162
+ "-C",
163
+ dest
164
+ ]);
165
+ }
124
166
  }
125
167
  async function runProcess(cmd, args) {
126
- return new Promise((resolve, reject) => {
127
- const child = spawn(cmd, args, { stdio: ["ignore", "ignore", "pipe"] });
128
- let err = "";
129
- child.stderr.on("data", (b) => err += b.toString());
130
- child.on(
131
- "close",
132
- (code) => code === 0 ? resolve() : reject(new Error(`${cmd} exit ${code}: ${err}`))
133
- );
134
- child.on("error", reject);
135
- });
168
+ return new Promise((resolve, reject) => {
169
+ const child = spawn(cmd, args, { stdio: [
170
+ "ignore",
171
+ "ignore",
172
+ "pipe"
173
+ ] });
174
+ let err = "";
175
+ child.stderr.on("data", (b) => err += b.toString());
176
+ child.on("close", (code) => code === 0 ? resolve() : reject(/* @__PURE__ */ new Error(`${cmd} exit ${code}: ${err}`)));
177
+ child.on("error", reject);
178
+ });
136
179
  }
137
- var CLOUDFLARED_BASE = "https://github.com/cloudflare/cloudflared/releases/latest/download";
138
- var CLOUDFLARED_DOWNLOADS = {
139
- "linux-x64": { url: `${CLOUDFLARED_BASE}/cloudflared-linux-amd64`, archive: "raw" },
140
- "linux-arm64": { url: `${CLOUDFLARED_BASE}/cloudflared-linux-arm64`, archive: "raw" },
141
- "darwin-x64": {
142
- url: `${CLOUDFLARED_BASE}/cloudflared-darwin-amd64.tgz`,
143
- archive: "tar.gz",
144
- binaryWithinArchive: "cloudflared"
145
- },
146
- "darwin-arm64": {
147
- url: `${CLOUDFLARED_BASE}/cloudflared-darwin-arm64.tgz`,
148
- archive: "tar.gz",
149
- binaryWithinArchive: "cloudflared"
150
- },
151
- "win32-x64": { url: `${CLOUDFLARED_BASE}/cloudflared-windows-amd64.exe`, archive: "raw" },
152
- "win32-arm64": { url: `${CLOUDFLARED_BASE}/cloudflared-windows-arm64.exe`, archive: "raw" }
180
+ const CLOUDFLARED_BASE = "https://github.com/cloudflare/cloudflared/releases/latest/download";
181
+ /**
182
+ * Canonical cloudflared release-asset manifest. Imported by both the agent
183
+ * bootstrap and the cloudflare provider — the ONE source of truth for the
184
+ * binary the quick tunnel uses.
185
+ */
186
+ const CLOUDFLARED_DOWNLOADS = {
187
+ "linux-x64": {
188
+ url: `${CLOUDFLARED_BASE}/cloudflared-linux-amd64`,
189
+ archive: "raw"
190
+ },
191
+ "linux-arm64": {
192
+ url: `${CLOUDFLARED_BASE}/cloudflared-linux-arm64`,
193
+ archive: "raw"
194
+ },
195
+ "darwin-x64": {
196
+ url: `${CLOUDFLARED_BASE}/cloudflared-darwin-amd64.tgz`,
197
+ archive: "tar.gz",
198
+ binaryWithinArchive: "cloudflared"
199
+ },
200
+ "darwin-arm64": {
201
+ url: `${CLOUDFLARED_BASE}/cloudflared-darwin-arm64.tgz`,
202
+ archive: "tar.gz",
203
+ binaryWithinArchive: "cloudflared"
204
+ },
205
+ "win32-x64": {
206
+ url: `${CLOUDFLARED_BASE}/cloudflared-windows-amd64.exe`,
207
+ archive: "raw"
208
+ },
209
+ "win32-arm64": {
210
+ url: `${CLOUDFLARED_BASE}/cloudflared-windows-arm64.exe`,
211
+ archive: "raw"
212
+ }
153
213
  };
154
- var QUICK_TUNNEL_URL_RE = /(https:\/\/(?!api\.)[a-zA-Z0-9-]+\.trycloudflare\.com)/;
214
+ /** Quick-tunnel URL matcher (excludes the `api.` endpoint, not a tunnel host). */
215
+ const QUICK_TUNNEL_URL_RE = /(https:\/\/(?!api\.)[a-zA-Z0-9-]+\.trycloudflare\.com)/;
216
+ /**
217
+ * Open a minimal cloudflared quick tunnel to `http://127.0.0.1:<port>` and
218
+ * resolve its public URL + child process. Installs cloudflared into the shared
219
+ * tools cache if needed (so a later provider `resolveBinary("cloudflared")`
220
+ * reuses it and ADOPTS this pid via `AGENT_TUNNEL_PID_*`). Storage-free and
221
+ * never throws — returns null on any failure so the caller can degrade and
222
+ * register once the provider starts. This is the agent's single deliberate
223
+ * pre-registration exception; the provider owns the full tunnel lifecycle
224
+ * post-registration.
225
+ */
155
226
  async function openQuickTunnel(port, opts) {
156
- const log = opts?.log ?? {};
157
- let cmd;
158
- try {
159
- cmd = await installBinary({
160
- name: "cloudflared",
161
- downloads: CLOUDFLARED_DOWNLOADS,
162
- versionMatcher: "cloudflared version",
163
- log
164
- });
165
- } catch (err) {
166
- log.warn?.(`quick-tunnel: could not obtain cloudflared: ${String(err)}`);
167
- return null;
168
- }
169
- let child;
170
- try {
171
- child = spawn(cmd, ["tunnel", "--url", `http://127.0.0.1:${port}`, "--no-autoupdate"], {
172
- stdio: ["ignore", "pipe", "pipe"]
173
- });
174
- } catch (err) {
175
- log.warn?.(`quick-tunnel: failed to spawn cloudflared: ${String(err)}`);
176
- return null;
177
- }
178
- const url = await new Promise((resolve) => {
179
- let settled = false;
180
- const finish = (u) => {
181
- if (settled) return;
182
- settled = true;
183
- resolve(u);
184
- };
185
- const timer = setTimeout(() => {
186
- log.warn?.("quick-tunnel: cloudflared did not advertise a URL in time");
187
- finish(null);
188
- }, opts?.timeoutMs ?? 3e4);
189
- const scan = (chunk) => {
190
- const m = chunk.toString("utf8").match(QUICK_TUNNEL_URL_RE);
191
- if (m) {
192
- clearTimeout(timer);
193
- finish(m[0]);
194
- }
195
- };
196
- child.stdout?.on("data", scan);
197
- child.stderr?.on("data", scan);
198
- child.on("error", (err) => {
199
- clearTimeout(timer);
200
- log.warn?.(`quick-tunnel: cloudflared failed to spawn: ${String(err)}`);
201
- finish(null);
202
- });
203
- child.on("exit", (code) => {
204
- clearTimeout(timer);
205
- log.warn?.(`quick-tunnel: cloudflared exited (code=${code})`);
206
- finish(null);
207
- });
208
- });
209
- if (!url) return null;
210
- return { url, child };
227
+ const log = opts?.log ?? {};
228
+ let cmd;
229
+ try {
230
+ cmd = await installBinary({
231
+ name: "cloudflared",
232
+ downloads: CLOUDFLARED_DOWNLOADS,
233
+ versionMatcher: "cloudflared version",
234
+ log
235
+ });
236
+ } catch (err) {
237
+ log.warn?.(`quick-tunnel: could not obtain cloudflared: ${String(err)}`);
238
+ return null;
239
+ }
240
+ let child;
241
+ try {
242
+ child = spawn(cmd, [
243
+ "tunnel",
244
+ "--url",
245
+ `http://127.0.0.1:${port}`,
246
+ "--no-autoupdate"
247
+ ], { stdio: [
248
+ "ignore",
249
+ "pipe",
250
+ "pipe"
251
+ ] });
252
+ } catch (err) {
253
+ log.warn?.(`quick-tunnel: failed to spawn cloudflared: ${String(err)}`);
254
+ return null;
255
+ }
256
+ const url = await new Promise((resolve) => {
257
+ let settled = false;
258
+ const finish = (u) => {
259
+ if (settled) return;
260
+ settled = true;
261
+ resolve(u);
262
+ };
263
+ const timer = setTimeout(() => {
264
+ log.warn?.("quick-tunnel: cloudflared did not advertise a URL in time");
265
+ finish(null);
266
+ }, opts?.timeoutMs ?? 3e4);
267
+ const scan = (chunk) => {
268
+ const m = chunk.toString("utf8").match(QUICK_TUNNEL_URL_RE);
269
+ if (m) {
270
+ clearTimeout(timer);
271
+ finish(m[0]);
272
+ }
273
+ };
274
+ child.stdout?.on("data", scan);
275
+ child.stderr?.on("data", scan);
276
+ child.on("error", (err) => {
277
+ clearTimeout(timer);
278
+ log.warn?.(`quick-tunnel: cloudflared failed to spawn: ${String(err)}`);
279
+ finish(null);
280
+ });
281
+ child.on("exit", (code) => {
282
+ clearTimeout(timer);
283
+ log.warn?.(`quick-tunnel: cloudflared exited (code=${code})`);
284
+ finish(null);
285
+ });
286
+ });
287
+ if (!url) return null;
288
+ return {
289
+ url,
290
+ child
291
+ };
211
292
  }
212
-
213
293
  export { CLOUDFLARED_DOWNLOADS, cachedBinaryPath, currentPlatform, installBinary, openQuickTunnel, resolveBinary, toolsCacheRoot };
214
- //# sourceMappingURL=index.js.map
294
+
215
295
  //# sourceMappingURL=index.js.map