@infosupport/huddle-cli 0.0.0-experiment-160.131.1 → 0.0.0-experiment-44.133.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 +32 -14
- package/dist/api.js +5 -11
- package/dist/config.js +2 -5
- package/dist/index.js +28 -53
- package/dist/indexfolder.js +167 -0
- package/dist/init.js +5 -50
- package/dist/runtime.js +19 -38
- package/dist/start.js +8 -10
- package/package.json +3 -7
- package/dist/extension.js +0 -170
- package/dist/host-logs.js +0 -60
- package/dist/pipe/command.js +0 -186
- package/dist/pipe/fs-list.js +0 -181
- package/dist/pipe/protocol.js +0 -99
- package/dist/pipe/sbx-kit.js +0 -142
- package/dist/pipe/sbx-links.js +0 -147
- package/dist/pipe/serve.js +0 -223
- package/dist/pipe/ssh-hosts.js +0 -155
- package/dist/pipe/tools.js +0 -227
- package/dist/zip.js +0 -74
package/dist/pipe/ssh-hosts.js
DELETED
|
@@ -1,155 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
// ── Host pipe ops `ssh.key` and `ssh.host`: SSH into a devcontainer, no key setup ──
|
|
3
|
-
// Like `sbx setup ssh` does for Docker Sandboxes: Huddle keeps its own key pair in
|
|
4
|
-
// ~/.huddle/ssh (made here, on the host, so the private key never leaves it) and
|
|
5
|
-
// one ssh config entry per devcontainer, `<name>.huddle`, in ~/.huddle/ssh/hosts.
|
|
6
|
-
// ~/.ssh/config includes those at its top, so the IDE (JetBrains Toolbox), and
|
|
7
|
-
// `ssh <name>.huddle` in a terminal, connect without asking for a key.
|
|
8
|
-
//
|
|
9
|
-
// The gateway only ever gets the public key (`ssh.key`), which it puts in the
|
|
10
|
-
// container's authorized_keys. `ssh.host` writes the entry with the container's
|
|
11
|
-
// host key pinned, so the connection is verified without a fingerprint prompt.
|
|
12
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
13
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
14
|
-
};
|
|
15
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
16
|
-
exports.INCLUDE_LINE = exports.SSH_DIR = void 0;
|
|
17
|
-
exports.generateEd25519 = generateEd25519;
|
|
18
|
-
exports.ensureInclude = ensureInclude;
|
|
19
|
-
exports.sshKey = sshKey;
|
|
20
|
-
exports.sshHost = sshHost;
|
|
21
|
-
const crypto_1 = __importDefault(require("crypto"));
|
|
22
|
-
const fs_1 = __importDefault(require("fs"));
|
|
23
|
-
const os_1 = __importDefault(require("os"));
|
|
24
|
-
const path_1 = __importDefault(require("path"));
|
|
25
|
-
const config_1 = require("../config");
|
|
26
|
-
const protocol_1 = require("./protocol");
|
|
27
|
-
exports.SSH_DIR = path_1.default.join(config_1.CONFIG_DIR, 'ssh');
|
|
28
|
-
const KEY_FILE = 'id_ed25519';
|
|
29
|
-
/** The line Huddle puts at the top of ~/.ssh/config. Hosts in an included file stay in it. */
|
|
30
|
-
exports.INCLUDE_LINE = 'Include ~/.huddle/ssh/hosts/*.conf';
|
|
31
|
-
// Docker container names ([a-zA-Z0-9][a-zA-Z0-9_.-]*) plus `.huddle`; also a file name here.
|
|
32
|
-
const ALIAS_RE = /^[a-zA-Z0-9][a-zA-Z0-9_.-]{0,127}\.huddle$/;
|
|
33
|
-
const USER_RE = /^[a-z_][a-z0-9_-]{0,31}$/;
|
|
34
|
-
const HOST_KEY_RE = /^ssh-ed25519 [A-Za-z0-9+/]+={0,3}$/;
|
|
35
|
-
const DEFAULT_DIRS = { huddle: exports.SSH_DIR, user: path_1.default.join(os_1.default.homedir(), '.ssh') };
|
|
36
|
-
function sshString(b) {
|
|
37
|
-
const buf = typeof b === 'string' ? Buffer.from(b) : b;
|
|
38
|
-
const len = Buffer.alloc(4);
|
|
39
|
-
len.writeUInt32BE(buf.length);
|
|
40
|
-
return Buffer.concat([len, buf]);
|
|
41
|
-
}
|
|
42
|
-
/** A new ed25519 key pair in OpenSSH's formats (unencrypted private key, `ssh-ed25519 …` public key). */
|
|
43
|
-
function generateEd25519(comment) {
|
|
44
|
-
const { privateKey } = crypto_1.default.generateKeyPairSync('ed25519');
|
|
45
|
-
const jwk = privateKey.export({ format: 'jwk' });
|
|
46
|
-
const seed = Buffer.from(jwk.d, 'base64url');
|
|
47
|
-
const pub = Buffer.from(jwk.x, 'base64url');
|
|
48
|
-
const pubBlob = Buffer.concat([sshString('ssh-ed25519'), sshString(pub)]);
|
|
49
|
-
const check = crypto_1.default.randomBytes(4);
|
|
50
|
-
let priv = Buffer.concat([check, check, sshString('ssh-ed25519'), sshString(pub), sshString(Buffer.concat([seed, pub])), sshString(comment)]);
|
|
51
|
-
const pad = (8 - (priv.length % 8)) % 8;
|
|
52
|
-
priv = Buffer.concat([priv, Buffer.from(Array.from({ length: pad }, (_, i) => i + 1))]);
|
|
53
|
-
const body = Buffer.concat([
|
|
54
|
-
Buffer.from('openssh-key-v1\0'),
|
|
55
|
-
sshString('none'), sshString('none'), sshString(''),
|
|
56
|
-
Buffer.from([0, 0, 0, 1]),
|
|
57
|
-
sshString(pubBlob),
|
|
58
|
-
sshString(priv),
|
|
59
|
-
]).toString('base64');
|
|
60
|
-
return {
|
|
61
|
-
privateKey: `-----BEGIN OPENSSH PRIVATE KEY-----\n${body.match(/.{1,70}/g).join('\n')}\n-----END OPENSSH PRIVATE KEY-----\n`,
|
|
62
|
-
publicKey: `ssh-ed25519 ${pubBlob.toString('base64')} ${comment}`,
|
|
63
|
-
};
|
|
64
|
-
}
|
|
65
|
-
/** Huddle's public key, after making the key pair if there is none. */
|
|
66
|
-
function ensureKey(dir) {
|
|
67
|
-
(0, protocol_1.ensurePrivateDir)(dir);
|
|
68
|
-
const keyPath = path_1.default.join(dir, KEY_FILE);
|
|
69
|
-
const pubPath = `${keyPath}.pub`;
|
|
70
|
-
if (fs_1.default.existsSync(keyPath) && fs_1.default.existsSync(pubPath))
|
|
71
|
-
return fs_1.default.readFileSync(pubPath, 'utf8').trim();
|
|
72
|
-
const { privateKey, publicKey } = generateEd25519(`huddle@${os_1.default.hostname()}`);
|
|
73
|
-
fs_1.default.rmSync(keyPath, { force: true });
|
|
74
|
-
fs_1.default.writeFileSync(keyPath, privateKey, { mode: 0o600 });
|
|
75
|
-
fs_1.default.writeFileSync(pubPath, `${publicKey}\n`, { mode: 0o644 });
|
|
76
|
-
return publicKey;
|
|
77
|
-
}
|
|
78
|
-
/** Puts INCLUDE_LINE at the top of ~/.ssh/config (making it when there is none). */
|
|
79
|
-
function ensureInclude(userDir) {
|
|
80
|
-
const file = path_1.default.join(userDir, 'config');
|
|
81
|
-
let text = '';
|
|
82
|
-
try {
|
|
83
|
-
text = fs_1.default.readFileSync(file, 'utf8');
|
|
84
|
-
}
|
|
85
|
-
catch {
|
|
86
|
-
fs_1.default.mkdirSync(userDir, { recursive: true, mode: 0o700 });
|
|
87
|
-
}
|
|
88
|
-
if (text.split(/\r?\n/).some((l) => l.trim() === exports.INCLUDE_LINE))
|
|
89
|
-
return;
|
|
90
|
-
const eol = text.includes('\r\n') ? '\r\n' : '\n';
|
|
91
|
-
// At the top: an Include after a Host block would only apply inside that block.
|
|
92
|
-
const head = `# Added by Huddle: SSH into devcontainers as <name>.huddle${eol}${exports.INCLUDE_LINE}${eol}`;
|
|
93
|
-
fs_1.default.writeFileSync(file, text ? `${head}${eol}${text}` : head, { mode: 0o600 });
|
|
94
|
-
}
|
|
95
|
-
function prepare(dirs) {
|
|
96
|
-
try {
|
|
97
|
-
const publicKey = ensureKey(dirs.huddle);
|
|
98
|
-
(0, protocol_1.ensurePrivateDir)(path_1.default.join(dirs.huddle, 'hosts'));
|
|
99
|
-
ensureInclude(dirs.user);
|
|
100
|
-
return publicKey;
|
|
101
|
-
}
|
|
102
|
-
catch (err) {
|
|
103
|
-
throw new protocol_1.PipeError('internal', `could not prepare SSH: ${err.message ?? err}`);
|
|
104
|
-
}
|
|
105
|
-
}
|
|
106
|
-
/** The `ssh.key` op: Huddle's public key. */
|
|
107
|
-
function sshKey(_args, dirs = DEFAULT_DIRS) {
|
|
108
|
-
return { publicKey: prepare(dirs) };
|
|
109
|
-
}
|
|
110
|
-
/**
|
|
111
|
-
* The `ssh.host` op: (re)writes the entry for one devcontainer,
|
|
112
|
-
* `{ alias, port, user, hostKey }`, or removes it with `{ alias, remove: true }`.
|
|
113
|
-
*/
|
|
114
|
-
function sshHost(args, dirs = DEFAULT_DIRS) {
|
|
115
|
-
const { alias, port, user, hostKey, remove } = args;
|
|
116
|
-
if (typeof alias !== 'string' || !ALIAS_RE.test(alias))
|
|
117
|
-
throw new protocol_1.PipeError('bad_request', 'alias must be <container name>.huddle');
|
|
118
|
-
const hosts = path_1.default.join(dirs.huddle, 'hosts');
|
|
119
|
-
const conf = path_1.default.join(hosts, `${alias}.conf`);
|
|
120
|
-
const known = path_1.default.join(hosts, `${alias}.known_hosts`);
|
|
121
|
-
if (remove === true) {
|
|
122
|
-
fs_1.default.rmSync(conf, { force: true });
|
|
123
|
-
fs_1.default.rmSync(known, { force: true });
|
|
124
|
-
return { publicKey: null };
|
|
125
|
-
}
|
|
126
|
-
if (typeof port !== 'number' || !Number.isInteger(port) || port < 1 || port > 65535)
|
|
127
|
-
throw new protocol_1.PipeError('bad_request', 'port must be 1-65535');
|
|
128
|
-
if (typeof user !== 'string' || !USER_RE.test(user))
|
|
129
|
-
throw new protocol_1.PipeError('bad_request', 'invalid user');
|
|
130
|
-
if (typeof hostKey !== 'string' || !HOST_KEY_RE.test(hostKey.trim()))
|
|
131
|
-
throw new protocol_1.PipeError('bad_request', 'hostKey must be an ssh-ed25519 public key');
|
|
132
|
-
const publicKey = prepare(dirs);
|
|
133
|
-
try {
|
|
134
|
-
fs_1.default.writeFileSync(known, `${alias} ${hostKey.trim()}\n`, { mode: 0o600 });
|
|
135
|
-
fs_1.default.writeFileSync(conf, [
|
|
136
|
-
'# Generated by Huddle; rewritten on every Connect IDE.',
|
|
137
|
-
`Host ${alias}`,
|
|
138
|
-
// 127.0.0.1, not localhost: the relay port is published on IPv4 loopback only,
|
|
139
|
-
// and a client that tries ::1 first (Toolbox's) gets "connection refused".
|
|
140
|
-
' HostName 127.0.0.1',
|
|
141
|
-
` Port ${port}`,
|
|
142
|
-
` User ${user}`,
|
|
143
|
-
` IdentityFile ~/.huddle/ssh/${KEY_FILE}`,
|
|
144
|
-
' IdentitiesOnly yes',
|
|
145
|
-
` HostKeyAlias ${alias}`,
|
|
146
|
-
` UserKnownHostsFile ~/.huddle/ssh/hosts/${alias}.known_hosts`,
|
|
147
|
-
' StrictHostKeyChecking yes',
|
|
148
|
-
'',
|
|
149
|
-
].join('\n'), { mode: 0o600 });
|
|
150
|
-
}
|
|
151
|
-
catch (err) {
|
|
152
|
-
throw new protocol_1.PipeError('internal', `could not write the SSH entry: ${err.message ?? err}`);
|
|
153
|
-
}
|
|
154
|
-
return { publicKey };
|
|
155
|
-
}
|
package/dist/pipe/tools.js
DELETED
|
@@ -1,227 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
// ── Host pipe op `tool.run`: allowlisted host binaries, argv only ─────────────
|
|
3
|
-
// The gateway can ask the host to run a tool such as Docker Sandboxes (`sbx`).
|
|
4
|
-
// Only binaries named in TOOLS can run, always with an argv array and never via
|
|
5
|
-
// a shell, so an argument like `$(whoami)` or `& calc` stays a literal string.
|
|
6
|
-
// Adding the next environment tool is one entry in TOOLS (plus its provider in
|
|
7
|
-
// gateway/src/environments/).
|
|
8
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
9
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
10
|
-
};
|
|
11
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
-
exports.TOOLS = void 0;
|
|
13
|
-
exports.resolveTool = resolveTool;
|
|
14
|
-
exports.execTool = execTool;
|
|
15
|
-
exports.toolRun = toolRun;
|
|
16
|
-
exports.toolVersion = toolVersion;
|
|
17
|
-
exports.toolsInfo = toolsInfo;
|
|
18
|
-
exports.availableTools = availableTools;
|
|
19
|
-
const fs_1 = __importDefault(require("fs"));
|
|
20
|
-
const os_1 = __importDefault(require("os"));
|
|
21
|
-
const path_1 = __importDefault(require("path"));
|
|
22
|
-
const child_process_1 = require("child_process");
|
|
23
|
-
const protocol_1 = require("./protocol");
|
|
24
|
-
exports.TOOLS = {
|
|
25
|
-
sbx: { bins: ['sbx', 'sbx.exe'], env: 'HUDDLE_SBX_BIN' },
|
|
26
|
-
};
|
|
27
|
-
// Windows runs .bat/.cmd through cmd.exe whatever argv we pass, and cmd.exe
|
|
28
|
-
// re-parses the command line, so an argument could inject a command. Only real
|
|
29
|
-
// executables are accepted.
|
|
30
|
-
const REFUSED_EXT = new Set(['.bat', '.cmd']);
|
|
31
|
-
const WIN_RUNNABLE_EXT = new Set(['.exe', '.com']);
|
|
32
|
-
function isRunnableFile(file) {
|
|
33
|
-
try {
|
|
34
|
-
if (!fs_1.default.statSync(file).isFile())
|
|
35
|
-
return false;
|
|
36
|
-
if (process.platform !== 'win32')
|
|
37
|
-
fs_1.default.accessSync(file, fs_1.default.constants.X_OK);
|
|
38
|
-
return true;
|
|
39
|
-
}
|
|
40
|
-
catch {
|
|
41
|
-
return false;
|
|
42
|
-
}
|
|
43
|
-
}
|
|
44
|
-
/** Candidate file names for one bin: on Windows `sbx` becomes sbx.COM, sbx.EXE, ... per PATHEXT. */
|
|
45
|
-
function candidates(bin) {
|
|
46
|
-
if (process.platform !== 'win32' || path_1.default.extname(bin))
|
|
47
|
-
return [bin];
|
|
48
|
-
const exts = (process.env.PATHEXT || '.COM;.EXE;.BAT;.CMD').split(';').filter(Boolean);
|
|
49
|
-
return exts.map((ext) => bin + ext.toLowerCase());
|
|
50
|
-
}
|
|
51
|
-
/**
|
|
52
|
-
* Finds a tool's binary without a shell: the env override if set, otherwise the
|
|
53
|
-
* first runnable match on PATH. A .bat/.cmd hit is skipped, and reported as
|
|
54
|
-
* not_allowed only when nothing else was found.
|
|
55
|
-
*/
|
|
56
|
-
function resolveTool(name) {
|
|
57
|
-
const spec = Object.prototype.hasOwnProperty.call(exports.TOOLS, name) ? exports.TOOLS[name] : undefined;
|
|
58
|
-
if (!spec)
|
|
59
|
-
return { error: new protocol_1.PipeError('not_allowed', `tool '${name}' is not allowlisted on the host`) };
|
|
60
|
-
const override = process.env[spec.env]?.trim();
|
|
61
|
-
const bins = override ? [override] : spec.bins;
|
|
62
|
-
const dirs = (process.env.PATH ?? '').split(path_1.default.delimiter).filter(Boolean);
|
|
63
|
-
let refused;
|
|
64
|
-
// Every file to try, in order. A bin with a directory in it is a path, not a
|
|
65
|
-
// name to look up on PATH.
|
|
66
|
-
const files = bins
|
|
67
|
-
.flatMap((bin) => (bin.includes('/') || bin.includes('\\') ? [path_1.default.resolve(bin)] : dirs.map((d) => path_1.default.join(d, bin))))
|
|
68
|
-
.flatMap(candidates);
|
|
69
|
-
for (const file of files) {
|
|
70
|
-
const ext = path_1.default.extname(file).toLowerCase();
|
|
71
|
-
// On Windows, skip batch files (they go through cmd.exe) and non-executables.
|
|
72
|
-
if (process.platform === 'win32' && !WIN_RUNNABLE_EXT.has(ext)) {
|
|
73
|
-
if (REFUSED_EXT.has(ext) && isRunnableFile(file))
|
|
74
|
-
refused ??= file;
|
|
75
|
-
continue;
|
|
76
|
-
}
|
|
77
|
-
if (isRunnableFile(file))
|
|
78
|
-
return { path: file };
|
|
79
|
-
}
|
|
80
|
-
if (refused) {
|
|
81
|
-
return { error: new protocol_1.PipeError('not_allowed', `refusing to run ${refused}: batch files go through cmd.exe`) };
|
|
82
|
-
}
|
|
83
|
-
const where = override ? `${spec.env}=${override}` : `${spec.bins.join(' / ')} on PATH`;
|
|
84
|
-
return { error: new protocol_1.PipeError('tool_missing', `${name} is not installed on the host (looked for ${where})`) };
|
|
85
|
-
}
|
|
86
|
-
/**
|
|
87
|
-
* Runs `file` with argv `args`: no shell, stdin closed, no console window, a
|
|
88
|
-
* hard timeout and at most MAX_OUTPUT_BYTES kept per stream (the rest is
|
|
89
|
-
* drained and dropped, so a chatty tool cannot exhaust the agent's memory).
|
|
90
|
-
*/
|
|
91
|
-
function execTool(file, args, timeoutMs, maxBytes = protocol_1.MAX_OUTPUT_BYTES) {
|
|
92
|
-
return new Promise((resolve, reject) => {
|
|
93
|
-
let child;
|
|
94
|
-
try {
|
|
95
|
-
child = (0, child_process_1.spawn)(file, args, { stdio: ['ignore', 'pipe', 'pipe'], windowsHide: true, shell: false });
|
|
96
|
-
}
|
|
97
|
-
catch (err) {
|
|
98
|
-
reject(err);
|
|
99
|
-
return;
|
|
100
|
-
}
|
|
101
|
-
const collect = () => {
|
|
102
|
-
const chunks = [];
|
|
103
|
-
let size = 0;
|
|
104
|
-
let dropped = false;
|
|
105
|
-
return {
|
|
106
|
-
push(chunk) {
|
|
107
|
-
if (size >= maxBytes) {
|
|
108
|
-
dropped = true;
|
|
109
|
-
return;
|
|
110
|
-
}
|
|
111
|
-
const room = maxBytes - size;
|
|
112
|
-
if (chunk.length > room) {
|
|
113
|
-
chunk = chunk.subarray(0, room);
|
|
114
|
-
dropped = true;
|
|
115
|
-
}
|
|
116
|
-
chunks.push(chunk);
|
|
117
|
-
size += chunk.length;
|
|
118
|
-
},
|
|
119
|
-
text() {
|
|
120
|
-
const s = Buffer.concat(chunks).toString('utf8');
|
|
121
|
-
return dropped ? `${s}\n[huddle] output truncated at ${maxBytes} bytes` : s;
|
|
122
|
-
},
|
|
123
|
-
};
|
|
124
|
-
};
|
|
125
|
-
const out = collect();
|
|
126
|
-
const err = collect();
|
|
127
|
-
child.stdout.on('data', (c) => out.push(c));
|
|
128
|
-
child.stderr.on('data', (c) => err.push(c));
|
|
129
|
-
let timedOut = false;
|
|
130
|
-
const timer = setTimeout(() => {
|
|
131
|
-
timedOut = true;
|
|
132
|
-
child.kill('SIGTERM');
|
|
133
|
-
// A tool that ignores SIGTERM still has to go; on Windows kill() is already final.
|
|
134
|
-
setTimeout(() => child.kill('SIGKILL'), 2000).unref();
|
|
135
|
-
}, timeoutMs);
|
|
136
|
-
child.on('error', (e) => {
|
|
137
|
-
clearTimeout(timer);
|
|
138
|
-
reject(e);
|
|
139
|
-
});
|
|
140
|
-
let done = false;
|
|
141
|
-
const finish = (code, signal) => {
|
|
142
|
-
if (done)
|
|
143
|
-
return;
|
|
144
|
-
done = true;
|
|
145
|
-
clearTimeout(timer);
|
|
146
|
-
let stderr = err.text();
|
|
147
|
-
// 124 is what timeout(1) exits with; a signal maps to the shell's 128+n.
|
|
148
|
-
let exit = code ?? (signal ? 128 + (os_1.default.constants.signals[signal] ?? 0) : 1);
|
|
149
|
-
if (timedOut) {
|
|
150
|
-
exit = 124;
|
|
151
|
-
stderr += `${stderr && !stderr.endsWith('\n') ? '\n' : ''}[huddle] timed out after ${timeoutMs} ms`;
|
|
152
|
-
}
|
|
153
|
-
resolve({ code: exit, stdout: out.text(), stderr });
|
|
154
|
-
};
|
|
155
|
-
// 'close' waits for the pipes, which stay open as long as ANY process holds
|
|
156
|
-
// them: a daemon the tool started in the background, or a grandchild that
|
|
157
|
-
// outlived a timeout kill. Once the tool itself has exited, give its output
|
|
158
|
-
// a moment to drain and then stop waiting for the stragglers.
|
|
159
|
-
child.on('exit', (code, signal) => {
|
|
160
|
-
setTimeout(() => {
|
|
161
|
-
child.stdout.destroy();
|
|
162
|
-
child.stderr.destroy();
|
|
163
|
-
finish(code, signal);
|
|
164
|
-
}, 1000);
|
|
165
|
-
});
|
|
166
|
-
child.on('close', finish);
|
|
167
|
-
});
|
|
168
|
-
}
|
|
169
|
-
/** The `tool.run` op. */
|
|
170
|
-
async function toolRun(args) {
|
|
171
|
-
const { tool, args: argv, timeoutMs } = args;
|
|
172
|
-
if (typeof tool !== 'string' || !tool)
|
|
173
|
-
throw new protocol_1.PipeError('bad_request', 'tool must be a non-empty string');
|
|
174
|
-
if (!Array.isArray(argv) || !argv.every((a) => typeof a === 'string')) {
|
|
175
|
-
throw new protocol_1.PipeError('bad_request', 'args must be an array of strings');
|
|
176
|
-
}
|
|
177
|
-
if (argv.some((a) => a.includes('\0')))
|
|
178
|
-
throw new protocol_1.PipeError('bad_request', 'args must not contain NUL bytes');
|
|
179
|
-
if (timeoutMs !== undefined && (typeof timeoutMs !== 'number' || !Number.isFinite(timeoutMs) || timeoutMs <= 0)) {
|
|
180
|
-
throw new protocol_1.PipeError('bad_request', 'timeoutMs must be a positive number');
|
|
181
|
-
}
|
|
182
|
-
const resolved = resolveTool(tool);
|
|
183
|
-
if ('error' in resolved)
|
|
184
|
-
throw resolved.error;
|
|
185
|
-
const timeout = Math.min(Math.round(timeoutMs ?? protocol_1.DEFAULT_TOOL_TIMEOUT_MS), protocol_1.MAX_TOOL_TIMEOUT_MS);
|
|
186
|
-
try {
|
|
187
|
-
return await execTool(resolved.path, argv, timeout);
|
|
188
|
-
}
|
|
189
|
-
catch (err) {
|
|
190
|
-
const e = err;
|
|
191
|
-
if (e.code === 'ENOENT')
|
|
192
|
-
throw new protocol_1.PipeError('tool_missing', `${tool} disappeared from ${resolved.path}`);
|
|
193
|
-
throw new protocol_1.PipeError('internal', `could not run ${tool}: ${e.message ?? e}`);
|
|
194
|
-
}
|
|
195
|
-
}
|
|
196
|
-
// One probe per binary path per agent run: `sbx version` can take a moment, and
|
|
197
|
-
// host.info is asked for often enough that re-running it every time would show.
|
|
198
|
-
const versionCache = new Map();
|
|
199
|
-
/** First line of `<tool> version`, best effort (undefined on any failure). */
|
|
200
|
-
function toolVersion(file) {
|
|
201
|
-
let cached = versionCache.get(file);
|
|
202
|
-
if (!cached) {
|
|
203
|
-
cached = execTool(file, ['version'], 5000, 64 * 1024)
|
|
204
|
-
.then((r) => (r.code === 0 ? (r.stdout || r.stderr).trim().split(/\r?\n/)[0] || undefined : undefined))
|
|
205
|
-
.catch(() => undefined);
|
|
206
|
-
versionCache.set(file, cached);
|
|
207
|
-
}
|
|
208
|
-
return cached;
|
|
209
|
-
}
|
|
210
|
-
/** Availability of every allowlisted tool, for host.info. */
|
|
211
|
-
async function toolsInfo() {
|
|
212
|
-
const out = {};
|
|
213
|
-
await Promise.all(Object.keys(exports.TOOLS).map(async (name) => {
|
|
214
|
-
const r = resolveTool(name);
|
|
215
|
-
if ('error' in r) {
|
|
216
|
-
out[name] = { available: false };
|
|
217
|
-
return;
|
|
218
|
-
}
|
|
219
|
-
const version = await toolVersion(r.path);
|
|
220
|
-
out[name] = version ? { available: true, path: r.path, version } : { available: true, path: r.path };
|
|
221
|
-
}));
|
|
222
|
-
return out;
|
|
223
|
-
}
|
|
224
|
-
/** Names of the allowlisted tools that are installed, for the heartbeat. */
|
|
225
|
-
function availableTools() {
|
|
226
|
-
return Object.keys(exports.TOOLS).filter((name) => !('error' in resolveTool(name)));
|
|
227
|
-
}
|
package/dist/zip.js
DELETED
|
@@ -1,74 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.createZip = createZip;
|
|
7
|
-
const zlib_1 = __importDefault(require("zlib"));
|
|
8
|
-
const CRC_TABLE = (() => {
|
|
9
|
-
const table = new Uint32Array(256);
|
|
10
|
-
for (let n = 0; n < 256; n++) {
|
|
11
|
-
let c = n;
|
|
12
|
-
for (let k = 0; k < 8; k++)
|
|
13
|
-
c = c & 1 ? 0xedb88320 ^ (c >>> 1) : c >>> 1;
|
|
14
|
-
table[n] = c >>> 0;
|
|
15
|
-
}
|
|
16
|
-
return table;
|
|
17
|
-
})();
|
|
18
|
-
function crc32(data) {
|
|
19
|
-
let crc = 0xffffffff;
|
|
20
|
-
for (const byte of data)
|
|
21
|
-
crc = CRC_TABLE[(crc ^ byte) & 0xff] ^ (crc >>> 8);
|
|
22
|
-
return (crc ^ 0xffffffff) >>> 0;
|
|
23
|
-
}
|
|
24
|
-
function assertSafeName(name) {
|
|
25
|
-
const segments = name.split('/');
|
|
26
|
-
if (!name || name.startsWith('/') || name.includes('\\') || segments.some((s) => s === '..' || s === '')) {
|
|
27
|
-
throw new Error(`invalid zip entry name: ${JSON.stringify(name)}`);
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
/** Builds a deflated zip archive with UTF-8 entry names, in the order given. */
|
|
31
|
-
function createZip(entries) {
|
|
32
|
-
const UTF8_NAMES = 0x0800;
|
|
33
|
-
const DEFLATE = 8;
|
|
34
|
-
const locals = [];
|
|
35
|
-
const centrals = [];
|
|
36
|
-
let offset = 0;
|
|
37
|
-
for (const entry of entries) {
|
|
38
|
-
assertSafeName(entry.name);
|
|
39
|
-
const name = Buffer.from(entry.name, 'utf8');
|
|
40
|
-
const packed = zlib_1.default.deflateRawSync(entry.data);
|
|
41
|
-
const crc = crc32(entry.data);
|
|
42
|
-
const local = Buffer.alloc(30);
|
|
43
|
-
local.writeUInt32LE(0x04034b50, 0);
|
|
44
|
-
local.writeUInt16LE(20, 4);
|
|
45
|
-
local.writeUInt16LE(UTF8_NAMES, 6);
|
|
46
|
-
local.writeUInt16LE(DEFLATE, 8);
|
|
47
|
-
local.writeUInt32LE(crc, 14);
|
|
48
|
-
local.writeUInt32LE(packed.length, 18);
|
|
49
|
-
local.writeUInt32LE(entry.data.length, 22);
|
|
50
|
-
local.writeUInt16LE(name.length, 26);
|
|
51
|
-
locals.push(local, name, packed);
|
|
52
|
-
const central = Buffer.alloc(46);
|
|
53
|
-
central.writeUInt32LE(0x02014b50, 0);
|
|
54
|
-
central.writeUInt16LE(20, 4);
|
|
55
|
-
central.writeUInt16LE(20, 6);
|
|
56
|
-
central.writeUInt16LE(UTF8_NAMES, 8);
|
|
57
|
-
central.writeUInt16LE(DEFLATE, 10);
|
|
58
|
-
central.writeUInt32LE(crc, 16);
|
|
59
|
-
central.writeUInt32LE(packed.length, 20);
|
|
60
|
-
central.writeUInt32LE(entry.data.length, 24);
|
|
61
|
-
central.writeUInt16LE(name.length, 28);
|
|
62
|
-
central.writeUInt32LE(offset, 42);
|
|
63
|
-
centrals.push(central, name);
|
|
64
|
-
offset += local.length + name.length + packed.length;
|
|
65
|
-
}
|
|
66
|
-
const centralDir = Buffer.concat(centrals);
|
|
67
|
-
const end = Buffer.alloc(22);
|
|
68
|
-
end.writeUInt32LE(0x06054b50, 0);
|
|
69
|
-
end.writeUInt16LE(entries.length, 8);
|
|
70
|
-
end.writeUInt16LE(entries.length, 10);
|
|
71
|
-
end.writeUInt32LE(centralDir.length, 12);
|
|
72
|
-
end.writeUInt32LE(offset, 16);
|
|
73
|
-
return Buffer.concat([...locals, centralDir, end]);
|
|
74
|
-
}
|