@infosupport/huddle-cli 0.0.0-experiment-137.150.1 → 0.0.0-experiment-160.152.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 +14 -32
- package/dist/api.js +11 -5
- package/dist/config.js +5 -2
- package/dist/extension.js +170 -0
- package/dist/host-logs.js +60 -0
- package/dist/index.js +53 -28
- package/dist/init.js +50 -5
- package/dist/pipe/command.js +186 -0
- package/dist/pipe/fs-list.js +181 -0
- package/dist/pipe/protocol.js +99 -0
- package/dist/pipe/sbx-kit.js +142 -0
- package/dist/pipe/sbx-links.js +147 -0
- package/dist/pipe/serve.js +223 -0
- package/dist/pipe/ssh-hosts.js +155 -0
- package/dist/pipe/tools.js +246 -0
- package/dist/runtime.js +38 -19
- package/dist/start.js +10 -8
- package/dist/zip.js +74 -0
- package/images/base-devimage/Dockerfile +16 -2
- package/package.json +6 -3
- package/dist/indexfolder.js +0 -167
|
@@ -0,0 +1,246 @@
|
|
|
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
|
+
// Firebrick (https://firebrick-sandbox.dev): one microVM per project folder.
|
|
27
|
+
fbk: { bins: ['fbk', 'fbk.exe'], env: 'HUDDLE_FBK_BIN' },
|
|
28
|
+
};
|
|
29
|
+
// Windows runs .bat/.cmd through cmd.exe whatever argv we pass, and cmd.exe
|
|
30
|
+
// re-parses the command line, so an argument could inject a command. Only real
|
|
31
|
+
// executables are accepted.
|
|
32
|
+
const REFUSED_EXT = new Set(['.bat', '.cmd']);
|
|
33
|
+
const WIN_RUNNABLE_EXT = new Set(['.exe', '.com']);
|
|
34
|
+
function isRunnableFile(file) {
|
|
35
|
+
try {
|
|
36
|
+
if (!fs_1.default.statSync(file).isFile())
|
|
37
|
+
return false;
|
|
38
|
+
if (process.platform !== 'win32')
|
|
39
|
+
fs_1.default.accessSync(file, fs_1.default.constants.X_OK);
|
|
40
|
+
return true;
|
|
41
|
+
}
|
|
42
|
+
catch {
|
|
43
|
+
return false;
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
/** Candidate file names for one bin: on Windows `sbx` becomes sbx.COM, sbx.EXE, ... per PATHEXT. */
|
|
47
|
+
function candidates(bin) {
|
|
48
|
+
if (process.platform !== 'win32' || path_1.default.extname(bin))
|
|
49
|
+
return [bin];
|
|
50
|
+
const exts = (process.env.PATHEXT || '.COM;.EXE;.BAT;.CMD').split(';').filter(Boolean);
|
|
51
|
+
return exts.map((ext) => bin + ext.toLowerCase());
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* Finds a tool's binary without a shell: the env override if set, otherwise the
|
|
55
|
+
* first runnable match on PATH. A .bat/.cmd hit is skipped, and reported as
|
|
56
|
+
* not_allowed only when nothing else was found.
|
|
57
|
+
*/
|
|
58
|
+
function resolveTool(name) {
|
|
59
|
+
const spec = Object.prototype.hasOwnProperty.call(exports.TOOLS, name) ? exports.TOOLS[name] : undefined;
|
|
60
|
+
if (!spec)
|
|
61
|
+
return { error: new protocol_1.PipeError('not_allowed', `tool '${name}' is not allowlisted on the host`) };
|
|
62
|
+
const override = process.env[spec.env]?.trim();
|
|
63
|
+
const bins = override ? [override] : spec.bins;
|
|
64
|
+
const dirs = (process.env.PATH ?? '').split(path_1.default.delimiter).filter(Boolean);
|
|
65
|
+
let refused;
|
|
66
|
+
// Every file to try, in order. A bin with a directory in it is a path, not a
|
|
67
|
+
// name to look up on PATH.
|
|
68
|
+
const files = bins
|
|
69
|
+
.flatMap((bin) => (bin.includes('/') || bin.includes('\\') ? [path_1.default.resolve(bin)] : dirs.map((d) => path_1.default.join(d, bin))))
|
|
70
|
+
.flatMap(candidates);
|
|
71
|
+
for (const file of files) {
|
|
72
|
+
const ext = path_1.default.extname(file).toLowerCase();
|
|
73
|
+
// On Windows, skip batch files (they go through cmd.exe) and non-executables.
|
|
74
|
+
if (process.platform === 'win32' && !WIN_RUNNABLE_EXT.has(ext)) {
|
|
75
|
+
if (REFUSED_EXT.has(ext) && isRunnableFile(file))
|
|
76
|
+
refused ??= file;
|
|
77
|
+
continue;
|
|
78
|
+
}
|
|
79
|
+
if (isRunnableFile(file))
|
|
80
|
+
return { path: file };
|
|
81
|
+
}
|
|
82
|
+
if (refused) {
|
|
83
|
+
return { error: new protocol_1.PipeError('not_allowed', `refusing to run ${refused}: batch files go through cmd.exe`) };
|
|
84
|
+
}
|
|
85
|
+
const where = override ? `${spec.env}=${override}` : `${spec.bins.join(' / ')} on PATH`;
|
|
86
|
+
return { error: new protocol_1.PipeError('tool_missing', `${name} is not installed on the host (looked for ${where})`) };
|
|
87
|
+
}
|
|
88
|
+
/**
|
|
89
|
+
* Runs `file` with argv `args`: no shell, stdin closed, no console window, a
|
|
90
|
+
* hard timeout and at most MAX_OUTPUT_BYTES kept per stream (the rest is
|
|
91
|
+
* drained and dropped, so a chatty tool cannot exhaust the agent's memory).
|
|
92
|
+
*/
|
|
93
|
+
function execTool(file, args, timeoutMs, maxBytes = protocol_1.MAX_OUTPUT_BYTES, cwd) {
|
|
94
|
+
return new Promise((resolve, reject) => {
|
|
95
|
+
let child;
|
|
96
|
+
try {
|
|
97
|
+
child = (0, child_process_1.spawn)(file, args, { stdio: ['ignore', 'pipe', 'pipe'], windowsHide: true, shell: false, ...(cwd ? { cwd } : {}) });
|
|
98
|
+
}
|
|
99
|
+
catch (err) {
|
|
100
|
+
reject(err);
|
|
101
|
+
return;
|
|
102
|
+
}
|
|
103
|
+
const collect = () => {
|
|
104
|
+
const chunks = [];
|
|
105
|
+
let size = 0;
|
|
106
|
+
let dropped = false;
|
|
107
|
+
return {
|
|
108
|
+
push(chunk) {
|
|
109
|
+
if (size >= maxBytes) {
|
|
110
|
+
dropped = true;
|
|
111
|
+
return;
|
|
112
|
+
}
|
|
113
|
+
const room = maxBytes - size;
|
|
114
|
+
if (chunk.length > room) {
|
|
115
|
+
chunk = chunk.subarray(0, room);
|
|
116
|
+
dropped = true;
|
|
117
|
+
}
|
|
118
|
+
chunks.push(chunk);
|
|
119
|
+
size += chunk.length;
|
|
120
|
+
},
|
|
121
|
+
text() {
|
|
122
|
+
const s = Buffer.concat(chunks).toString('utf8');
|
|
123
|
+
return dropped ? `${s}\n[huddle] output truncated at ${maxBytes} bytes` : s;
|
|
124
|
+
},
|
|
125
|
+
};
|
|
126
|
+
};
|
|
127
|
+
const out = collect();
|
|
128
|
+
const err = collect();
|
|
129
|
+
child.stdout.on('data', (c) => out.push(c));
|
|
130
|
+
child.stderr.on('data', (c) => err.push(c));
|
|
131
|
+
let timedOut = false;
|
|
132
|
+
const timer = setTimeout(() => {
|
|
133
|
+
timedOut = true;
|
|
134
|
+
child.kill('SIGTERM');
|
|
135
|
+
// A tool that ignores SIGTERM still has to go; on Windows kill() is already final.
|
|
136
|
+
setTimeout(() => child.kill('SIGKILL'), 2000).unref();
|
|
137
|
+
}, timeoutMs);
|
|
138
|
+
child.on('error', (e) => {
|
|
139
|
+
clearTimeout(timer);
|
|
140
|
+
reject(e);
|
|
141
|
+
});
|
|
142
|
+
let done = false;
|
|
143
|
+
const finish = (code, signal) => {
|
|
144
|
+
if (done)
|
|
145
|
+
return;
|
|
146
|
+
done = true;
|
|
147
|
+
clearTimeout(timer);
|
|
148
|
+
let stderr = err.text();
|
|
149
|
+
// 124 is what timeout(1) exits with; a signal maps to the shell's 128+n.
|
|
150
|
+
let exit = code ?? (signal ? 128 + (os_1.default.constants.signals[signal] ?? 0) : 1);
|
|
151
|
+
if (timedOut) {
|
|
152
|
+
exit = 124;
|
|
153
|
+
stderr += `${stderr && !stderr.endsWith('\n') ? '\n' : ''}[huddle] timed out after ${timeoutMs} ms`;
|
|
154
|
+
}
|
|
155
|
+
resolve({ code: exit, stdout: out.text(), stderr });
|
|
156
|
+
};
|
|
157
|
+
// 'close' waits for the pipes, which stay open as long as ANY process holds
|
|
158
|
+
// them: a daemon the tool started in the background, or a grandchild that
|
|
159
|
+
// outlived a timeout kill. Once the tool itself has exited, give its output
|
|
160
|
+
// a moment to drain and then stop waiting for the stragglers.
|
|
161
|
+
child.on('exit', (code, signal) => {
|
|
162
|
+
setTimeout(() => {
|
|
163
|
+
child.stdout.destroy();
|
|
164
|
+
child.stderr.destroy();
|
|
165
|
+
finish(code, signal);
|
|
166
|
+
}, 1000);
|
|
167
|
+
});
|
|
168
|
+
child.on('close', finish);
|
|
169
|
+
});
|
|
170
|
+
}
|
|
171
|
+
/** The `tool.run` op. */
|
|
172
|
+
async function toolRun(args) {
|
|
173
|
+
const { tool, args: argv, timeoutMs, cwd } = args;
|
|
174
|
+
if (typeof tool !== 'string' || !tool)
|
|
175
|
+
throw new protocol_1.PipeError('bad_request', 'tool must be a non-empty string');
|
|
176
|
+
if (!Array.isArray(argv) || !argv.every((a) => typeof a === 'string')) {
|
|
177
|
+
throw new protocol_1.PipeError('bad_request', 'args must be an array of strings');
|
|
178
|
+
}
|
|
179
|
+
if (argv.some((a) => a.includes('\0')))
|
|
180
|
+
throw new protocol_1.PipeError('bad_request', 'args must not contain NUL bytes');
|
|
181
|
+
if (timeoutMs !== undefined && (typeof timeoutMs !== 'number' || !Number.isFinite(timeoutMs) || timeoutMs <= 0)) {
|
|
182
|
+
throw new protocol_1.PipeError('bad_request', 'timeoutMs must be a positive number');
|
|
183
|
+
}
|
|
184
|
+
// Optional working directory: Firebrick derives the sandbox from the folder it
|
|
185
|
+
// runs in. Only an absolute path to an existing directory; the gateway has
|
|
186
|
+
// already held it to the mount rules (no ~/.huddle and the like).
|
|
187
|
+
if (cwd !== undefined) {
|
|
188
|
+
if (typeof cwd !== 'string' || !cwd || cwd.includes('\0') || !path_1.default.isAbsolute(cwd)) {
|
|
189
|
+
throw new protocol_1.PipeError('bad_request', 'cwd must be an absolute path');
|
|
190
|
+
}
|
|
191
|
+
let isDir = false;
|
|
192
|
+
try {
|
|
193
|
+
isDir = fs_1.default.statSync(cwd).isDirectory();
|
|
194
|
+
}
|
|
195
|
+
catch {
|
|
196
|
+
isDir = false;
|
|
197
|
+
}
|
|
198
|
+
if (!isDir)
|
|
199
|
+
throw new protocol_1.PipeError('bad_request', `cwd is not a directory on the host: ${cwd}`);
|
|
200
|
+
}
|
|
201
|
+
const resolved = resolveTool(tool);
|
|
202
|
+
if ('error' in resolved)
|
|
203
|
+
throw resolved.error;
|
|
204
|
+
const timeout = Math.min(Math.round(timeoutMs ?? protocol_1.DEFAULT_TOOL_TIMEOUT_MS), protocol_1.MAX_TOOL_TIMEOUT_MS);
|
|
205
|
+
try {
|
|
206
|
+
return await execTool(resolved.path, argv, timeout, protocol_1.MAX_OUTPUT_BYTES, cwd);
|
|
207
|
+
}
|
|
208
|
+
catch (err) {
|
|
209
|
+
const e = err;
|
|
210
|
+
if (e.code === 'ENOENT')
|
|
211
|
+
throw new protocol_1.PipeError('tool_missing', `${tool} disappeared from ${resolved.path}`);
|
|
212
|
+
throw new protocol_1.PipeError('internal', `could not run ${tool}: ${e.message ?? e}`);
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
// One probe per binary path per agent run: `sbx version` can take a moment, and
|
|
216
|
+
// host.info is asked for often enough that re-running it every time would show.
|
|
217
|
+
const versionCache = new Map();
|
|
218
|
+
/** First line of `<tool> version`, best effort (undefined on any failure). */
|
|
219
|
+
function toolVersion(file) {
|
|
220
|
+
let cached = versionCache.get(file);
|
|
221
|
+
if (!cached) {
|
|
222
|
+
cached = execTool(file, ['version'], 5000, 64 * 1024)
|
|
223
|
+
.then((r) => (r.code === 0 ? (r.stdout || r.stderr).trim().split(/\r?\n/)[0] || undefined : undefined))
|
|
224
|
+
.catch(() => undefined);
|
|
225
|
+
versionCache.set(file, cached);
|
|
226
|
+
}
|
|
227
|
+
return cached;
|
|
228
|
+
}
|
|
229
|
+
/** Availability of every allowlisted tool, for host.info. */
|
|
230
|
+
async function toolsInfo() {
|
|
231
|
+
const out = {};
|
|
232
|
+
await Promise.all(Object.keys(exports.TOOLS).map(async (name) => {
|
|
233
|
+
const r = resolveTool(name);
|
|
234
|
+
if ('error' in r) {
|
|
235
|
+
out[name] = { available: false };
|
|
236
|
+
return;
|
|
237
|
+
}
|
|
238
|
+
const version = await toolVersion(r.path);
|
|
239
|
+
out[name] = version ? { available: true, path: r.path, version } : { available: true, path: r.path };
|
|
240
|
+
}));
|
|
241
|
+
return out;
|
|
242
|
+
}
|
|
243
|
+
/** Names of the allowlisted tools that are installed, for the heartbeat. */
|
|
244
|
+
function availableTools() {
|
|
245
|
+
return Object.keys(exports.TOOLS).filter((name) => !('error' in resolveTool(name)));
|
|
246
|
+
}
|
package/dist/runtime.js
CHANGED
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.parseDockerContextSocket = parseDockerContextSocket;
|
|
4
4
|
exports.isRancherDesktopSocket = isRancherDesktopSocket;
|
|
5
|
+
exports.dockerMountSocket = dockerMountSocket;
|
|
5
6
|
exports.parseRuntimeName = parseRuntimeName;
|
|
6
7
|
exports.resolveRuntime = resolveRuntime;
|
|
7
8
|
const child_process_1 = require("child_process");
|
|
@@ -44,9 +45,6 @@ function podmanSocketPath() {
|
|
|
44
45
|
}
|
|
45
46
|
return '/run/podman/podman.sock';
|
|
46
47
|
}
|
|
47
|
-
function dockerSocketPath() {
|
|
48
|
-
return process.platform === 'win32' ? '//var/run/docker.sock' : '/var/run/docker.sock';
|
|
49
|
-
}
|
|
50
48
|
/**
|
|
51
49
|
* Extracts the unix socket path from the JSON of `docker context inspect`. The
|
|
52
50
|
* active context determines which engine the `docker` command talks to; Rancher
|
|
@@ -54,6 +52,11 @@ function dockerSocketPath() {
|
|
|
54
52
|
* `Endpoints.docker.Host` points to `unix:///<home>/.rd/docker.sock` instead of
|
|
55
53
|
* the default `/var/run/docker.sock`.
|
|
56
54
|
*
|
|
55
|
+
* The result is only used to DETECT the engine (see buildRuntime), never as a
|
|
56
|
+
* bind-mount source: a context socket is the path the CLI uses to reach the
|
|
57
|
+
* daemon, which for VM-based engines is a host-side forwarder that the daemon
|
|
58
|
+
* itself cannot mount.
|
|
59
|
+
*
|
|
57
60
|
* Pure function so we can test the parsing in isolation. Returns `null` for
|
|
58
61
|
* non-parsable input or a non-unix endpoint (npipe:// on Windows,
|
|
59
62
|
* tcp:// / ssh:// remote), because those cannot be bind-mounted as a file path.
|
|
@@ -75,10 +78,10 @@ function parseDockerContextSocket(json) {
|
|
|
75
78
|
const path = host.slice('unix://'.length);
|
|
76
79
|
if (!path.startsWith('/'))
|
|
77
80
|
return null;
|
|
78
|
-
// The
|
|
79
|
-
//
|
|
80
|
-
//
|
|
81
|
-
//
|
|
81
|
+
// The `Host` from `docker context inspect` is attacker-influenceable (whoever
|
|
82
|
+
// can create/activate a docker context controls the value). The path is only
|
|
83
|
+
// used for detection now, but keep it as defense in depth should it ever reach
|
|
84
|
+
// a shell command again: restrict it to characters that occur in a real
|
|
82
85
|
// socket path: allow spaces (legal in e.g. macOS `/Users/First Last/.rd/...`)
|
|
83
86
|
// but never the metacharacters that stay dangerous inside double quotes
|
|
84
87
|
// ($, backtick, ", \) or the command separators (;, |, &, (), newline).
|
|
@@ -97,6 +100,28 @@ function dockerContextSocket() {
|
|
|
97
100
|
return undefined;
|
|
98
101
|
return parseDockerContextSocket(json) ?? undefined;
|
|
99
102
|
}
|
|
103
|
+
/**
|
|
104
|
+
* Determines the docker socket to bind-mount (as seen by the engine) and
|
|
105
|
+
* whether the engine runs in a VM, given the active context's socket.
|
|
106
|
+
*
|
|
107
|
+
* Rancher Desktop (dockerd/moby mode) looks like an ordinary Docker engine, but
|
|
108
|
+
* its context points to `~/.rd/docker.sock`. That is a host-side forwarder into
|
|
109
|
+
* the Lima VM that only the CLI can use: bind-mount sources are resolved by
|
|
110
|
+
* dockerd INSIDE the VM, where that file is not a usable socket (dockerd then
|
|
111
|
+
* tries to mkdir it: "operation not supported"). Inside the VM dockerd listens
|
|
112
|
+
* on the standard /var/run/docker.sock, so we always mount that — the same
|
|
113
|
+
* engine-side reasoning as for /tmp/dc-sockets in init.ts.
|
|
114
|
+
*
|
|
115
|
+
* Pure function so we can test it without a daemon.
|
|
116
|
+
*/
|
|
117
|
+
function dockerMountSocket(contextSocket, platform) {
|
|
118
|
+
return {
|
|
119
|
+
socketPath: platform === 'win32' ? '//var/run/docker.sock' : '/var/run/docker.sock',
|
|
120
|
+
// Docker Desktop (macOS/Windows) and Rancher Desktop (every OS, Lima/WSL)
|
|
121
|
+
// run in a VM; native Docker on Linux does not.
|
|
122
|
+
isRemote: isRancherDesktopSocket(contextSocket) || platform !== 'linux',
|
|
123
|
+
};
|
|
124
|
+
}
|
|
100
125
|
function podmanIsRemote() {
|
|
101
126
|
// On macOS/Windows Podman always runs in a `podman machine` VM; on Linux too
|
|
102
127
|
// the client can point at a remote socket. `ServiceIsRemote` is the
|
|
@@ -113,21 +138,15 @@ function buildRuntime(name) {
|
|
|
113
138
|
securityOpts: ['label=disable'],
|
|
114
139
|
};
|
|
115
140
|
}
|
|
116
|
-
//
|
|
117
|
-
//
|
|
118
|
-
//
|
|
119
|
-
|
|
120
|
-
// Docker, Docker Desktop). Rancher Desktop runs the engine in a VM (Lima/WSL)
|
|
121
|
-
// on EVERY platform, so it is always 'remote'.
|
|
122
|
-
const contextSocket = dockerContextSocket();
|
|
123
|
-
const isRancher = isRancherDesktopSocket(contextSocket);
|
|
141
|
+
// The active docker context only tells us WHICH engine this is (Rancher
|
|
142
|
+
// Desktop or not); the mount source is always the engine-side socket. See
|
|
143
|
+
// dockerMountSocket().
|
|
144
|
+
const { socketPath, isRemote } = dockerMountSocket(dockerContextSocket(), process.platform);
|
|
124
145
|
return {
|
|
125
146
|
name,
|
|
126
|
-
socketPath
|
|
147
|
+
socketPath,
|
|
127
148
|
defaultNetwork: 'bridge',
|
|
128
|
-
|
|
129
|
-
// Docker on Linux does not.
|
|
130
|
-
isRemote: isRancher || process.platform !== 'linux',
|
|
149
|
+
isRemote,
|
|
131
150
|
securityOpts: [],
|
|
132
151
|
};
|
|
133
152
|
}
|
package/dist/start.js
CHANGED
|
@@ -98,8 +98,7 @@ async function runStart(opts) {
|
|
|
98
98
|
console.log(`Open in VS Code: ${(0, utils_1.cyan)('Dev Containers: Attach to Running Container')} -> ${(0, utils_1.bold)(result.containerName)}`);
|
|
99
99
|
return;
|
|
100
100
|
}
|
|
101
|
-
|
|
102
|
-
await tryPrintIdeLink(result.containerName);
|
|
101
|
+
await tryPrintSshLink(result.containerName);
|
|
103
102
|
}
|
|
104
103
|
/**
|
|
105
104
|
* Teach VS Code which folder to open on attach. Best-effort: a failure here
|
|
@@ -136,15 +135,18 @@ function containerWorkspacePath(workspaceDir, containerName) {
|
|
|
136
135
|
: containerName.replace(/^devcontainer-/, '') || containerName;
|
|
137
136
|
return `/workspaces/${leaf}`;
|
|
138
137
|
}
|
|
139
|
-
|
|
140
|
-
|
|
138
|
+
// Same link as the portal's Connect IDE button: sets up sshd, the localhost
|
|
139
|
+
// relay and the `<name>.huddle` ssh alias (key made by the host agent), and
|
|
140
|
+
// returns a JetBrains Toolbox link. Best-effort: without the host agent, or on an
|
|
141
|
+
// older image, the portal button explains what is missing.
|
|
142
|
+
async function tryPrintSshLink(containerName) {
|
|
141
143
|
try {
|
|
142
|
-
const res = await (0, api_1.get)(`/api/docker/containers/${encodeURIComponent(containerName)}/
|
|
144
|
+
const res = await (0, api_1.get)(`/api/docker/containers/${encodeURIComponent(containerName)}/ssh-link`);
|
|
143
145
|
if (res?.link)
|
|
144
|
-
console.log((0, utils_1.
|
|
146
|
+
console.log(`Open in JetBrains Toolbox: ${(0, utils_1.cyan)(res.link)} (or: ssh ${containerName}.huddle)`);
|
|
145
147
|
}
|
|
146
|
-
catch {
|
|
147
|
-
|
|
148
|
+
catch (err) {
|
|
149
|
+
console.log((0, utils_1.dim)(`No SSH link yet (${err?.message ?? err}); use Connect IDE in the Huddle portal.`));
|
|
148
150
|
}
|
|
149
151
|
}
|
|
150
152
|
function resolveWorkspace(workspace) {
|
package/dist/zip.js
ADDED
|
@@ -0,0 +1,74 @@
|
|
|
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
|
+
}
|
|
@@ -27,8 +27,13 @@ RUN curl -fsSL https://deb.nodesource.com/setup_24.x | bash - \
|
|
|
27
27
|
&& apt-get install -y --no-install-recommends nodejs \
|
|
28
28
|
&& rm -rf /var/lib/apt/lists/*
|
|
29
29
|
|
|
30
|
-
# Global CLIs
|
|
31
|
-
|
|
30
|
+
# Global CLIs, elk in een eigen laag: samen ~1,3 GB (native binaries). Kleinere
|
|
31
|
+
# lagen downloaden parallel, en een update van één CLI raakt alleen zijn eigen
|
|
32
|
+
# laag en de lagen erna.
|
|
33
|
+
RUN npm install -g @anthropic-ai/claude-code && npm cache clean --force
|
|
34
|
+
RUN npm install -g @openai/codex && npm cache clean --force
|
|
35
|
+
RUN npm install -g @github/copilot && npm cache clean --force
|
|
36
|
+
RUN npm install -g opencode-ai && npm cache clean --force
|
|
32
37
|
|
|
33
38
|
# markitdown: converteert PDF/Office/HTML/afbeeldingen → Markdown.
|
|
34
39
|
# Wordt gebruikt door de markitdown-skill (.ai/claude/skills/markitdown.md).
|
|
@@ -46,6 +51,15 @@ RUN mkdir -p /home/vscode/.claude/agents /home/vscode/.claude/skills \
|
|
|
46
51
|
/home/vscode/.copilot /home/vscode/.config \
|
|
47
52
|
/home/vscode/.ai
|
|
48
53
|
|
|
54
|
+
# openssh-server voor "Connect via SSH" (JetBrains Gateway). sshd draait niet
|
|
55
|
+
# standaard: Huddle configureert en start hem pas bij het opvragen van de SSH-link
|
|
56
|
+
# (gateway/src/ssh-access.ts), met een eigen config en een host key per container.
|
|
57
|
+
# De host keys die het pakket bij installatie maakt worden verwijderd, anders
|
|
58
|
+
# deelt elke container van deze image dezelfde host key.
|
|
59
|
+
RUN apt-get update && apt-get install -y --no-install-recommends openssh-server \
|
|
60
|
+
&& rm -f /etc/ssh/ssh_host_* \
|
|
61
|
+
&& rm -rf /var/lib/apt/lists/*
|
|
62
|
+
|
|
49
63
|
# Verwijder sudo-rechten van vscode (mcr base geeft ze standaard, wij willen dit niet)
|
|
50
64
|
RUN gpasswd -d vscode sudo 2>/dev/null || true \
|
|
51
65
|
&& find /etc/sudoers.d -name '*vscode*' -delete 2>/dev/null || true
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@infosupport/huddle-cli",
|
|
3
|
-
"version": "0.0.0-experiment-
|
|
3
|
+
"version": "0.0.0-experiment-160.152.1",
|
|
4
4
|
"description": "Huddle CLI — start devcontainers and manage firewall rules",
|
|
5
5
|
"license": "GPL-3.0-or-later",
|
|
6
6
|
"author": "Info Support B.V.",
|
|
@@ -21,11 +21,14 @@
|
|
|
21
21
|
"dev": "tsc --watch",
|
|
22
22
|
"install-global": "npm run build && npm install -g .",
|
|
23
23
|
"typecheck": "tsc --noEmit",
|
|
24
|
-
"test": "npm run build && node --test"
|
|
24
|
+
"test": "npm run build && node --test test/*.test.js && vitest run"
|
|
25
25
|
},
|
|
26
26
|
"devDependencies": {
|
|
27
|
+
"@types/adm-zip": "^0.5.8",
|
|
27
28
|
"@types/node": "^22.0.0",
|
|
28
|
-
"
|
|
29
|
+
"adm-zip": "^0.5.18",
|
|
30
|
+
"typescript": "~6.0.3",
|
|
31
|
+
"vitest": "^4.1.11"
|
|
29
32
|
},
|
|
30
33
|
"engines": {
|
|
31
34
|
"node": ">=22"
|