@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.
- package/README.md +1 -1
- package/dist/audit/index.d.ts +7 -13
- package/dist/audit/index.js +13 -14
- package/dist/broadcast/index.d.ts +6 -12
- package/dist/broadcast/index.js +8 -9
- package/dist/cli/index.d.ts +7 -72
- package/dist/cli/index.js +1 -104
- package/dist/cli-CGyu31Cn.js +104 -0
- package/dist/config/index.d.ts +18 -24
- package/dist/config/index.js +56 -61
- package/dist/context/index.d.ts +26 -32
- package/dist/context/index.js +33 -21
- package/dist/contract/index.d.ts +2 -413
- package/dist/contract/index.js +11 -12
- package/dist/host/fs-safety.d.ts +13 -17
- package/dist/host/fs-safety.js +223 -217
- package/dist/host/os.d.ts +2 -68
- package/dist/host/os.js +15 -7
- package/dist/host/paths.d.ts +2 -36
- package/dist/host/paths.js +44 -44
- package/dist/host/request-security.d.ts +6 -7
- package/dist/host/request-security.js +26 -14
- package/dist/http/index.d.ts +23 -25
- package/dist/http/index.js +60 -65
- package/dist/index-BM4zNXSR.d.ts +25 -0
- package/dist/index-D946chPf.d.ts +410 -0
- package/dist/index-Q_hnxaN_.d.ts +60 -0
- package/dist/index.d.ts +44 -18
- package/dist/index.js +16 -749
- package/dist/install/index.d.ts +46 -50
- package/dist/install/index.js +269 -189
- package/dist/lifecycle/index.d.ts +24 -30
- package/dist/lifecycle/index.js +18 -30
- package/dist/log/index.d.ts +10 -15
- package/dist/log/index.js +19 -20
- package/dist/os-DoFa9kjr.d.ts +67 -0
- package/dist/paths-h28H4Xeb.d.ts +35 -0
- package/dist/providers/index.d.ts +50 -56
- package/dist/providers/index.js +101 -126
- package/dist/routes/index.d.ts +22 -28
- package/dist/routes/index.js +80 -72
- package/dist/storage/index.d.ts +2 -38
- package/dist/storage/index.js +1 -67
- package/dist/storage-DkNBaJHC.js +64 -0
- package/dist/subprocess/index.d.ts +5 -11
- package/dist/subprocess/index.js +85 -56
- package/dist/telemetry/index.d.ts +15 -21
- package/dist/telemetry/index.js +35 -36
- package/dist/testing/index.d.ts +6 -28
- package/dist/testing/index.js +87 -88
- package/package.json +10 -10
package/dist/install/index.d.ts
CHANGED
|
@@ -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
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
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
|
-
|
|
42
|
-
|
|
43
|
-
|
|
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
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
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
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
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
|
-
|
|
104
|
-
|
|
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>;
|
package/dist/install/index.js
CHANGED
|
@@ -1,215 +1,295 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import
|
|
6
|
-
import { Readable } from
|
|
7
|
-
import { pipeline } from
|
|
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
|
-
|
|
12
|
-
|
|
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
|
-
|
|
39
|
+
return path$1.join(homedir(), ".boff", "vibecontrols", "tools");
|
|
17
40
|
}
|
|
18
41
|
function binFileName(name, binaryName) {
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
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
|
-
|
|
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
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
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
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
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
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
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
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
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
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
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
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
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
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
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
|
-
|
|
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
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
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
|
-
|
|
294
|
+
|
|
215
295
|
//# sourceMappingURL=index.js.map
|