@vibecontrols/plugin-sdk 2026.530.4 → 2026.530.6
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 +17 -1
- package/dist/host/fs-safety.d.ts +34 -0
- package/dist/host/fs-safety.js +255 -0
- package/dist/host/request-security.d.ts +9 -0
- package/dist/host/request-security.js +23 -0
- package/dist/index.js +1 -1
- package/dist/install/index.d.ts +54 -0
- package/dist/install/index.js +140 -0
- package/dist/subprocess/index.js +1 -1
- package/package.json +13 -1
package/dist/contract/index.d.ts
CHANGED
|
@@ -30,6 +30,13 @@ declare const FULL_TRUST_CAPS: Required<PluginCapabilities>;
|
|
|
30
30
|
type PluginTag = "backend" | "frontend" | "cli" | "provider" | "adapter" | "integration";
|
|
31
31
|
type PrerequisiteKind = "binary" | "npm" | "pip" | "cargo" | "manual";
|
|
32
32
|
type SupportedOS = "linux" | "darwin" | "win32";
|
|
33
|
+
/**
|
|
34
|
+
* Provider-registry type a META plugin's providers register under, mirroring
|
|
35
|
+
* the agent `ServiceRegistry`'s provider types. Declared on `MetaProviderRef`
|
|
36
|
+
* so the agent can ELECT a platform default (not merely install it) without
|
|
37
|
+
* having to scan every registry type to discover which one a provider owns.
|
|
38
|
+
*/
|
|
39
|
+
type ProviderType = "tunnel" | "session" | "ai" | "plan";
|
|
33
40
|
interface Prerequisite {
|
|
34
41
|
name: string;
|
|
35
42
|
kind: PrerequisiteKind;
|
|
@@ -57,6 +64,15 @@ interface MetaProviderRef {
|
|
|
57
64
|
* meta. Empty/undefined = opt-in only (never auto-installed at bootstrap).
|
|
58
65
|
*/
|
|
59
66
|
defaultOn?: ReadonlyArray<SupportedOS>;
|
|
67
|
+
/**
|
|
68
|
+
* The agent `ServiceRegistry` provider type this entry registers under
|
|
69
|
+
* (e.g. "session" for tmux/wezterm/zellij). When set, the agent elects the
|
|
70
|
+
* `defaultOn`-matching provider of this type as the registry default for the
|
|
71
|
+
* current platform (win32 → wezterm, linux/darwin → tmux) instead of only
|
|
72
|
+
* installing it. Optional — when omitted the agent infers the type by
|
|
73
|
+
* scanning the registry, so older metas keep working.
|
|
74
|
+
*/
|
|
75
|
+
providerType?: ProviderType;
|
|
60
76
|
}
|
|
61
77
|
/**
|
|
62
78
|
* Context passed to a plugin's `onNuke` hook. The agent calls `onNuke`
|
|
@@ -246,4 +262,4 @@ interface VibePlugin {
|
|
|
246
262
|
}
|
|
247
263
|
type VibePluginFactory = (ctx: ProfileContext) => VibePlugin;
|
|
248
264
|
|
|
249
|
-
export { FULL_TRUST_CAPS, type HostServices, type MetaProviderRef, type NukeResult, type PluginCapabilities, type PluginNukeContext, type PluginTag, type Prerequisite, type PrerequisiteKind, type ProfileContext, type SdkLogger, type ServiceRegistry, type StorageProvider, type SupportedOS, type VibePlugin, type VibePluginFactory };
|
|
265
|
+
export { FULL_TRUST_CAPS, type HostServices, type MetaProviderRef, type NukeResult, type PluginCapabilities, type PluginNukeContext, type PluginTag, type Prerequisite, type PrerequisiteKind, type ProfileContext, type ProviderType, type SdkLogger, type ServiceRegistry, type StorageProvider, type SupportedOS, type VibePlugin, type VibePluginFactory };
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import * as node_fs from 'node:fs';
|
|
2
|
+
|
|
3
|
+
interface SafePathResult {
|
|
4
|
+
path: string;
|
|
5
|
+
realPath: string;
|
|
6
|
+
}
|
|
7
|
+
declare const MAX_FILE_READ_BYTES: number;
|
|
8
|
+
declare const MAX_DIRECTORY_ENTRIES: number;
|
|
9
|
+
declare function isSensitivePath(filePath: string): boolean;
|
|
10
|
+
declare function isProtectedPath(filePath: string): boolean;
|
|
11
|
+
declare function resolveSafePath(inputPath: string, options?: {
|
|
12
|
+
mustExist?: boolean;
|
|
13
|
+
forWrite?: boolean;
|
|
14
|
+
}): Promise<SafePathResult>;
|
|
15
|
+
declare function assertReadableFileSize(filePath: string): Promise<void>;
|
|
16
|
+
/**
|
|
17
|
+
* A8 — atomic, symlink-safe file read.
|
|
18
|
+
*
|
|
19
|
+
* Closes the resolve-then-open TOCTOU window in the prior implementation
|
|
20
|
+
* (a symlink swap between `lstat` and `readFile` could redirect the read
|
|
21
|
+
* to /etc/passwd or any other root-owned file).
|
|
22
|
+
*
|
|
23
|
+
* POSIX: `open(2)` with `O_NOFOLLOW` errors with `ELOOP` if the final
|
|
24
|
+
* path component is a symlink, and we read via the resulting fd so the
|
|
25
|
+
* file identity is pinned for the duration of the read.
|
|
26
|
+
*
|
|
27
|
+
* Windows: `O_NOFOLLOW` isn't honoured the same way — we lstat, reject
|
|
28
|
+
* symlinks explicitly, then re-stat by realpath and confirm the same
|
|
29
|
+
* inode before reading.
|
|
30
|
+
*/
|
|
31
|
+
declare function safeReadFile(filePath: string): Buffer;
|
|
32
|
+
declare function listDirectoryCapped(filePath: string): Promise<node_fs.Dirent<string>[]>;
|
|
33
|
+
|
|
34
|
+
export { MAX_DIRECTORY_ENTRIES, MAX_FILE_READ_BYTES, type SafePathResult, assertReadableFileSize, isProtectedPath, isSensitivePath, listDirectoryCapped, resolveSafePath, safeReadFile };
|
|
@@ -0,0 +1,255 @@
|
|
|
1
|
+
import { realpathSync, promises, lstatSync, statSync, openSync, constants, readSync, closeSync, fstatSync } from 'fs';
|
|
2
|
+
import os from 'os';
|
|
3
|
+
import path from 'path';
|
|
4
|
+
|
|
5
|
+
// src/host/fs-safety.ts
|
|
6
|
+
function positiveIntFromEnv(name, fallback) {
|
|
7
|
+
const parsed = parseInt(process.env[name] ?? "", 10);
|
|
8
|
+
return Number.isInteger(parsed) && parsed > 0 ? parsed : fallback;
|
|
9
|
+
}
|
|
10
|
+
var MAX_FILE_READ_BYTES = positiveIntFromEnv(
|
|
11
|
+
"VIBECONTROLS_MAX_FILE_READ_BYTES",
|
|
12
|
+
10 * 1024 * 1024
|
|
13
|
+
);
|
|
14
|
+
var MAX_DIRECTORY_ENTRIES = positiveIntFromEnv("VIBECONTROLS_MAX_DIRECTORY_ENTRIES", 2e3);
|
|
15
|
+
var SENSITIVE_PATTERNS = [
|
|
16
|
+
/(?:^|\/)\.env(?:\..*)?$/,
|
|
17
|
+
/\.pem$/,
|
|
18
|
+
/\.key$/,
|
|
19
|
+
/(?:^|\/)id_rsa(?:$|\.)/,
|
|
20
|
+
/(?:^|\/)\.ssh(?:\/|$)/,
|
|
21
|
+
/(?:^|\/)\.git\/config$/,
|
|
22
|
+
/(?:^|\/)\.npmrc$/
|
|
23
|
+
];
|
|
24
|
+
var POSIX_PROTECTED_PATHS = ["/", "/etc", "/usr", "/bin", "/sbin", "/var", "/opt"];
|
|
25
|
+
var WIN32_PROTECTED_PATHS = [
|
|
26
|
+
"C:\\Windows",
|
|
27
|
+
"C:\\Program Files",
|
|
28
|
+
"C:\\Program Files (x86)",
|
|
29
|
+
"C:\\ProgramData"
|
|
30
|
+
];
|
|
31
|
+
function protectedPathsForHost() {
|
|
32
|
+
return process.platform === "win32" ? WIN32_PROTECTED_PATHS : POSIX_PROTECTED_PATHS;
|
|
33
|
+
}
|
|
34
|
+
function normalizeForCompare(p) {
|
|
35
|
+
return process.platform === "win32" ? p.toLowerCase() : p;
|
|
36
|
+
}
|
|
37
|
+
function configuredRoots() {
|
|
38
|
+
const raw = process.env.VIBECONTROLS_ALLOWED_ROOTS;
|
|
39
|
+
if (raw) {
|
|
40
|
+
return raw.split(path.delimiter).map((entry) => entry.trim()).filter(Boolean);
|
|
41
|
+
}
|
|
42
|
+
return [process.cwd(), os.homedir(), os.tmpdir()].filter(Boolean);
|
|
43
|
+
}
|
|
44
|
+
async function realpathIfExists(candidate) {
|
|
45
|
+
try {
|
|
46
|
+
return await promises.realpath(candidate);
|
|
47
|
+
} catch {
|
|
48
|
+
return null;
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
async function allowedRootRealpaths() {
|
|
52
|
+
const roots = [];
|
|
53
|
+
for (const root of configuredRoots()) {
|
|
54
|
+
const resolved = path.resolve(root);
|
|
55
|
+
const real = await realpathIfExists(resolved) ?? resolved;
|
|
56
|
+
if (!roots.includes(real)) roots.push(real);
|
|
57
|
+
}
|
|
58
|
+
return roots;
|
|
59
|
+
}
|
|
60
|
+
function isWithinRoot(target, root) {
|
|
61
|
+
const relative = path.relative(root, target);
|
|
62
|
+
return relative === "" || !!relative && !relative.startsWith("..") && !path.isAbsolute(relative);
|
|
63
|
+
}
|
|
64
|
+
async function assertUnderAllowedRoot(realPath) {
|
|
65
|
+
const roots = await allowedRootRealpaths();
|
|
66
|
+
if (!roots.some((root) => isWithinRoot(realPath, root))) {
|
|
67
|
+
throw new Error("Access denied: path is outside allowed directories");
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
async function nearestExistingParent(candidate) {
|
|
71
|
+
let current = path.dirname(candidate);
|
|
72
|
+
while (current && current !== path.dirname(current)) {
|
|
73
|
+
const real = await realpathIfExists(current);
|
|
74
|
+
if (real) return real;
|
|
75
|
+
current = path.dirname(current);
|
|
76
|
+
}
|
|
77
|
+
const rootReal = await realpathIfExists(current || path.parse(candidate).root);
|
|
78
|
+
if (!rootReal) throw new Error("Path parent does not exist");
|
|
79
|
+
return rootReal;
|
|
80
|
+
}
|
|
81
|
+
async function assertFinalIsNotSymlink(candidate) {
|
|
82
|
+
const stat = await promises.lstat(path.resolve(candidate)).catch(() => null);
|
|
83
|
+
if (stat?.isSymbolicLink()) {
|
|
84
|
+
throw new Error("Access denied: symbolic links are not allowed");
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
function isSensitivePath(filePath) {
|
|
88
|
+
return SENSITIVE_PATTERNS.some((pattern) => pattern.test(filePath));
|
|
89
|
+
}
|
|
90
|
+
function looksLikePosixProtected(raw) {
|
|
91
|
+
if (!raw.startsWith("/")) return false;
|
|
92
|
+
const fwd = raw.replace(/\\/g, "/").replace(/\/+/g, "/");
|
|
93
|
+
return POSIX_PROTECTED_PATHS.some((p) => fwd === p || fwd.startsWith(p === "/" ? "/" : `${p}/`));
|
|
94
|
+
}
|
|
95
|
+
function isProtectedPath(filePath) {
|
|
96
|
+
const normalized = path.resolve(filePath);
|
|
97
|
+
const realIfExists = (() => {
|
|
98
|
+
try {
|
|
99
|
+
return realpathSync(normalized);
|
|
100
|
+
} catch {
|
|
101
|
+
return null;
|
|
102
|
+
}
|
|
103
|
+
})();
|
|
104
|
+
const candidates = realIfExists ? [normalized, realIfExists] : [normalized];
|
|
105
|
+
const tmpRaw = os.tmpdir();
|
|
106
|
+
const homeRaw = os.homedir();
|
|
107
|
+
const tmpReal = (() => {
|
|
108
|
+
try {
|
|
109
|
+
return realpathSync(tmpRaw);
|
|
110
|
+
} catch {
|
|
111
|
+
return tmpRaw;
|
|
112
|
+
}
|
|
113
|
+
})();
|
|
114
|
+
const homeReal = (() => {
|
|
115
|
+
try {
|
|
116
|
+
return realpathSync(homeRaw);
|
|
117
|
+
} catch {
|
|
118
|
+
return homeRaw;
|
|
119
|
+
}
|
|
120
|
+
})();
|
|
121
|
+
const sep = path.sep;
|
|
122
|
+
const allowPrefixes = [tmpRaw, tmpReal, homeRaw, homeReal];
|
|
123
|
+
for (const candidate of candidates) {
|
|
124
|
+
const cmp = normalizeForCompare(candidate);
|
|
125
|
+
if (allowPrefixes.some((prefix) => {
|
|
126
|
+
const pCmp = normalizeForCompare(prefix);
|
|
127
|
+
return cmp === pCmp || cmp.startsWith(pCmp + sep);
|
|
128
|
+
})) {
|
|
129
|
+
return false;
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
if (candidates.some((candidate) => {
|
|
133
|
+
const cmp = normalizeForCompare(candidate);
|
|
134
|
+
return protectedPathsForHost().some((protectedPath) => {
|
|
135
|
+
const pCmp = normalizeForCompare(protectedPath);
|
|
136
|
+
return cmp === pCmp || cmp.startsWith(pCmp + sep);
|
|
137
|
+
});
|
|
138
|
+
})) {
|
|
139
|
+
return true;
|
|
140
|
+
}
|
|
141
|
+
return looksLikePosixProtected(filePath);
|
|
142
|
+
}
|
|
143
|
+
async function resolveSafePath(inputPath, options = {}) {
|
|
144
|
+
if (!inputPath || inputPath.includes("\0")) {
|
|
145
|
+
throw new Error("Invalid path");
|
|
146
|
+
}
|
|
147
|
+
const normalized = path.resolve(inputPath);
|
|
148
|
+
await assertFinalIsNotSymlink(normalized);
|
|
149
|
+
const realPath = await realpathIfExists(normalized);
|
|
150
|
+
if (realPath) {
|
|
151
|
+
await assertUnderAllowedRoot(realPath);
|
|
152
|
+
return { path: normalized, realPath };
|
|
153
|
+
}
|
|
154
|
+
if (options.mustExist) {
|
|
155
|
+
throw new Error("Path not found");
|
|
156
|
+
}
|
|
157
|
+
if (!options.forWrite) {
|
|
158
|
+
await assertUnderAllowedRoot(normalized);
|
|
159
|
+
return { path: normalized, realPath: normalized };
|
|
160
|
+
}
|
|
161
|
+
const parentReal = await nearestExistingParent(normalized);
|
|
162
|
+
await assertUnderAllowedRoot(parentReal);
|
|
163
|
+
return { path: normalized, realPath: normalized };
|
|
164
|
+
}
|
|
165
|
+
async function assertReadableFileSize(filePath) {
|
|
166
|
+
const stats = await promises.stat(filePath);
|
|
167
|
+
if (stats.isFile() && stats.size > MAX_FILE_READ_BYTES) {
|
|
168
|
+
throw new Error(
|
|
169
|
+
`File is too large to read safely (${stats.size} bytes, max ${MAX_FILE_READ_BYTES})`
|
|
170
|
+
);
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
function safeReadFile(filePath) {
|
|
174
|
+
if (process.platform === "win32") {
|
|
175
|
+
const lstat = lstatSync(filePath);
|
|
176
|
+
if (lstat.isSymbolicLink()) {
|
|
177
|
+
throw new Error("Access denied: symbolic links are not allowed");
|
|
178
|
+
}
|
|
179
|
+
const real = realpathSync.native(filePath);
|
|
180
|
+
const realStat = statSync(real);
|
|
181
|
+
if (realStat.ino !== lstat.ino) {
|
|
182
|
+
throw new Error("Access denied: path swapped under check");
|
|
183
|
+
}
|
|
184
|
+
if (realStat.size > MAX_FILE_READ_BYTES) {
|
|
185
|
+
throw new Error(
|
|
186
|
+
`File is too large to read safely (${realStat.size} bytes, max ${MAX_FILE_READ_BYTES})`
|
|
187
|
+
);
|
|
188
|
+
}
|
|
189
|
+
const fd2 = openSync(real, constants.O_RDONLY);
|
|
190
|
+
try {
|
|
191
|
+
const buf = Buffer.allocUnsafe(realStat.size);
|
|
192
|
+
let read = 0;
|
|
193
|
+
while (read < realStat.size) {
|
|
194
|
+
const n = readSync(fd2, buf, read, realStat.size - read, read);
|
|
195
|
+
if (n <= 0) break;
|
|
196
|
+
read += n;
|
|
197
|
+
}
|
|
198
|
+
return read === realStat.size ? buf : buf.subarray(0, read);
|
|
199
|
+
} finally {
|
|
200
|
+
closeSync(fd2);
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
let fd;
|
|
204
|
+
try {
|
|
205
|
+
fd = openSync(filePath, constants.O_RDONLY | constants.O_NOFOLLOW);
|
|
206
|
+
} catch (err) {
|
|
207
|
+
const code = err.code;
|
|
208
|
+
if (code === "ELOOP" || code === "EMLINK") {
|
|
209
|
+
throw new Error("Access denied: symbolic links are not allowed", {
|
|
210
|
+
cause: err
|
|
211
|
+
});
|
|
212
|
+
}
|
|
213
|
+
throw err;
|
|
214
|
+
}
|
|
215
|
+
try {
|
|
216
|
+
const stat = fstatSync(fd);
|
|
217
|
+
if (stat.size > MAX_FILE_READ_BYTES) {
|
|
218
|
+
throw new Error(
|
|
219
|
+
`File is too large to read safely (${stat.size} bytes, max ${MAX_FILE_READ_BYTES})`
|
|
220
|
+
);
|
|
221
|
+
}
|
|
222
|
+
const buf = Buffer.allocUnsafe(stat.size);
|
|
223
|
+
let read = 0;
|
|
224
|
+
while (read < stat.size) {
|
|
225
|
+
const n = readSync(fd, buf, read, stat.size - read, read);
|
|
226
|
+
if (n <= 0) break;
|
|
227
|
+
read += n;
|
|
228
|
+
}
|
|
229
|
+
return read === stat.size ? buf : buf.subarray(0, read);
|
|
230
|
+
} finally {
|
|
231
|
+
closeSync(fd);
|
|
232
|
+
}
|
|
233
|
+
}
|
|
234
|
+
async function listDirectoryCapped(filePath) {
|
|
235
|
+
const dir = await promises.opendir(filePath);
|
|
236
|
+
const entries = [];
|
|
237
|
+
try {
|
|
238
|
+
for await (const entry of dir) {
|
|
239
|
+
entries.push(entry);
|
|
240
|
+
if (entries.length > MAX_DIRECTORY_ENTRIES) {
|
|
241
|
+
throw new Error(`Directory has too many entries (>${MAX_DIRECTORY_ENTRIES})`);
|
|
242
|
+
}
|
|
243
|
+
}
|
|
244
|
+
} finally {
|
|
245
|
+
const closeResult = dir.close?.();
|
|
246
|
+
if (closeResult && typeof closeResult.catch === "function") {
|
|
247
|
+
await closeResult.catch(() => void 0);
|
|
248
|
+
}
|
|
249
|
+
}
|
|
250
|
+
return entries;
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
export { MAX_DIRECTORY_ENTRIES, MAX_FILE_READ_BYTES, assertReadableFileSize, isProtectedPath, isSensitivePath, listDirectoryCapped, resolveSafePath, safeReadFile };
|
|
254
|
+
//# sourceMappingURL=fs-safety.js.map
|
|
255
|
+
//# sourceMappingURL=fs-safety.js.map
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
interface RequestIpServer {
|
|
2
|
+
requestIP(request: Request): {
|
|
3
|
+
address: string;
|
|
4
|
+
} | null;
|
|
5
|
+
}
|
|
6
|
+
declare function isLikelyLocalRequest(request: Request, server?: RequestIpServer | null): boolean;
|
|
7
|
+
declare function denyNonLocalMutation(request: Request, envOverride: string, server?: RequestIpServer | null): string | null;
|
|
8
|
+
|
|
9
|
+
export { denyNonLocalMutation, isLikelyLocalRequest };
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
// src/host/request-security.ts
|
|
2
|
+
var LOOPBACK_HOSTS = /* @__PURE__ */ new Set(["localhost", "127.0.0.1", "0.0.0.0", "::1", "[::1]"]);
|
|
3
|
+
function normalizedHost(hostname) {
|
|
4
|
+
return hostname.toLowerCase().replace(/^\[|\]$/g, "");
|
|
5
|
+
}
|
|
6
|
+
function isLikelyLocalRequest(request, server) {
|
|
7
|
+
const headers = request.headers;
|
|
8
|
+
if (headers.has("cf-connecting-ip") || headers.has("x-forwarded-for") || headers.has("x-real-ip") || headers.has("forwarded")) {
|
|
9
|
+
return false;
|
|
10
|
+
}
|
|
11
|
+
const peerAddress = server?.requestIP(request)?.address;
|
|
12
|
+
if (!peerAddress) return false;
|
|
13
|
+
return LOOPBACK_HOSTS.has(normalizedHost(peerAddress));
|
|
14
|
+
}
|
|
15
|
+
function denyNonLocalMutation(request, envOverride, server) {
|
|
16
|
+
if (isLikelyLocalRequest(request, server)) return null;
|
|
17
|
+
if (process.env[envOverride] === "1") return null;
|
|
18
|
+
return `This operation is local-only by default. Set ${envOverride}=1 to allow it over a tunnel.`;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export { denyNonLocalMutation, isLikelyLocalRequest };
|
|
22
|
+
//# sourceMappingURL=request-security.js.map
|
|
23
|
+
//# sourceMappingURL=request-security.js.map
|
package/dist/index.js
CHANGED
|
@@ -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/dist/subprocess/index.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vibecontrols/plugin-sdk",
|
|
3
|
-
"version": "2026.530.
|
|
3
|
+
"version": "2026.530.6",
|
|
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"
|
|
@@ -83,6 +87,14 @@
|
|
|
83
87
|
"./host/paths": {
|
|
84
88
|
"import": "./dist/host/paths.js",
|
|
85
89
|
"types": "./dist/host/paths.d.ts"
|
|
90
|
+
},
|
|
91
|
+
"./host/fs-safety": {
|
|
92
|
+
"import": "./dist/host/fs-safety.js",
|
|
93
|
+
"types": "./dist/host/fs-safety.d.ts"
|
|
94
|
+
},
|
|
95
|
+
"./host/request-security": {
|
|
96
|
+
"import": "./dist/host/request-security.js",
|
|
97
|
+
"types": "./dist/host/request-security.d.ts"
|
|
86
98
|
}
|
|
87
99
|
},
|
|
88
100
|
"scripts": {
|