@vibecontrols/plugin-sdk 2026.530.3 → 2026.530.5
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/dist/contract/index.d.ts +9 -0
- package/dist/install/index.d.ts +54 -0
- package/dist/install/index.js +140 -0
- package/package.json +5 -1
package/dist/contract/index.d.ts
CHANGED
|
@@ -209,6 +209,15 @@ interface VibePlugin {
|
|
|
209
209
|
* registration descriptor of the same short name.
|
|
210
210
|
*/
|
|
211
211
|
metaProviders?: ReadonlyArray<MetaProviderRef>;
|
|
212
|
+
/**
|
|
213
|
+
* Tunnel PROVIDER plugins only: the public DNS suffix(es) the tunnels this
|
|
214
|
+
* provider opens live under, e.g. `[".trycloudflare.com"]`. The agent adds
|
|
215
|
+
* these to its allow-list of advertise-able / reachable tunnel URLs at
|
|
216
|
+
* provider registration, so the thin agent never hardcodes a provider's
|
|
217
|
+
* domain in its URL-security layer. Each entry SHOULD start with a dot and
|
|
218
|
+
* be a registrable suffix (matched with `host.endsWith(suffix)`).
|
|
219
|
+
*/
|
|
220
|
+
tunnelDomainSuffixes?: ReadonlyArray<string>;
|
|
212
221
|
cliCommand?: string;
|
|
213
222
|
apiPrefix?: string;
|
|
214
223
|
createRoutes?: () => unknown;
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
type ToolPlatform = "linux-x64" | "linux-arm64" | "darwin-x64" | "darwin-arm64" | "win32-x64" | "win32-arm64";
|
|
2
|
+
declare function currentPlatform(): ToolPlatform;
|
|
3
|
+
interface BinaryDownload {
|
|
4
|
+
/** Direct download URL for this platform (HTTPS). */
|
|
5
|
+
url: string;
|
|
6
|
+
/** Optional sha256 of the downloaded artifact; verified before use when set. */
|
|
7
|
+
sha256?: string;
|
|
8
|
+
/** Archive format. Inferred from the URL extension when omitted. */
|
|
9
|
+
archive?: "tar.gz" | "zip" | "raw";
|
|
10
|
+
/** Path to the binary inside the archive (for tar.gz/zip). */
|
|
11
|
+
binaryWithinArchive?: string;
|
|
12
|
+
}
|
|
13
|
+
interface InstallLogger {
|
|
14
|
+
info?: (msg: string) => void;
|
|
15
|
+
warn?: (msg: string) => void;
|
|
16
|
+
error?: (msg: string) => void;
|
|
17
|
+
}
|
|
18
|
+
interface InstallBinarySpec {
|
|
19
|
+
/** Tool key — also the cache subdir and default binary name. */
|
|
20
|
+
name: string;
|
|
21
|
+
/** Installed binary filename (`.exe` is appended on Windows if absent). */
|
|
22
|
+
binaryName?: string;
|
|
23
|
+
/** Per-platform download manifest. */
|
|
24
|
+
downloads: Partial<Record<ToolPlatform, BinaryDownload>>;
|
|
25
|
+
/** Args used for the post-install / PATH sanity check. Default `["--version"]`. */
|
|
26
|
+
versionArgs?: string[];
|
|
27
|
+
/** Regex applied to the version output to accept a PATH/cache binary. */
|
|
28
|
+
versionMatcher?: string;
|
|
29
|
+
/** Override platform detection (testing). */
|
|
30
|
+
platform?: ToolPlatform;
|
|
31
|
+
/** Override the cache root (testing). Default `~/.boff/vibecontrols/tools`. */
|
|
32
|
+
cacheRoot?: string;
|
|
33
|
+
log?: InstallLogger;
|
|
34
|
+
}
|
|
35
|
+
/** Stable per-machine cache root for provider-installed binaries. */
|
|
36
|
+
declare function toolsCacheRoot(): string;
|
|
37
|
+
/** Absolute path the binary lives at once installed by this module. */
|
|
38
|
+
declare function cachedBinaryPath(name: string, binaryName?: string, cacheRoot?: string): string;
|
|
39
|
+
/**
|
|
40
|
+
* Resolve a binary WITHOUT downloading — synchronous, safe to call from hot
|
|
41
|
+
* paths (e.g. a `resolve<tool>Cmd()` used on every spawn). Checks the provider
|
|
42
|
+
* cache first (absolute path, immune to the PATH snapshot), then `$PATH` using
|
|
43
|
+
* the CURRENT `process.env.PATH` (not the snapshot `Bun.which` would otherwise
|
|
44
|
+
* use). Returns the absolute path, or null when not installed.
|
|
45
|
+
*/
|
|
46
|
+
declare function resolveBinary(name: string, binaryName?: string, cacheRoot?: string): string | null;
|
|
47
|
+
/**
|
|
48
|
+
* Resolve a binary, downloading + installing it into the cache if it is not
|
|
49
|
+
* already available. Returns the absolute path. Throws when no manifest entry
|
|
50
|
+
* exists for the current platform or the download fails.
|
|
51
|
+
*/
|
|
52
|
+
declare function installBinary(spec: InstallBinarySpec): Promise<string>;
|
|
53
|
+
|
|
54
|
+
export { type BinaryDownload, type InstallBinarySpec, type InstallLogger, type ToolPlatform, cachedBinaryPath, currentPlatform, installBinary, resolveBinary, toolsCacheRoot };
|
|
@@ -0,0 +1,140 @@
|
|
|
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
|
+
|
|
9
|
+
// src/install/index.ts
|
|
10
|
+
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}`;
|
|
14
|
+
}
|
|
15
|
+
function toolsCacheRoot() {
|
|
16
|
+
return path.join(homedir(), ".boff", "vibecontrols", "tools");
|
|
17
|
+
}
|
|
18
|
+
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;
|
|
24
|
+
}
|
|
25
|
+
function cachedBinaryPath(name, binaryName, cacheRoot) {
|
|
26
|
+
return path.join(cacheRoot ?? toolsCacheRoot(), name, binFileName(name, binaryName));
|
|
27
|
+
}
|
|
28
|
+
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;
|
|
37
|
+
}
|
|
38
|
+
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
|
+
});
|
|
56
|
+
}
|
|
57
|
+
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;
|
|
79
|
+
}
|
|
80
|
+
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
|
+
}
|
|
115
|
+
}
|
|
116
|
+
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
|
+
}
|
|
124
|
+
}
|
|
125
|
+
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
|
+
});
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
export { cachedBinaryPath, currentPlatform, installBinary, resolveBinary, toolsCacheRoot };
|
|
139
|
+
//# sourceMappingURL=index.js.map
|
|
140
|
+
//# sourceMappingURL=index.js.map
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vibecontrols/plugin-sdk",
|
|
3
|
-
"version": "2026.530.
|
|
3
|
+
"version": "2026.530.5",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "VibeControls Plugin SDK — shared contract, lifecycle, CLI, telemetry, storage helpers for all vibe-plugin-* packages.",
|
|
6
6
|
"engines": {
|
|
@@ -52,6 +52,10 @@
|
|
|
52
52
|
"import": "./dist/subprocess/index.js",
|
|
53
53
|
"types": "./dist/subprocess/index.d.ts"
|
|
54
54
|
},
|
|
55
|
+
"./install": {
|
|
56
|
+
"import": "./dist/install/index.js",
|
|
57
|
+
"types": "./dist/install/index.d.ts"
|
|
58
|
+
},
|
|
55
59
|
"./http": {
|
|
56
60
|
"import": "./dist/http/index.js",
|
|
57
61
|
"types": "./dist/http/index.d.ts"
|