@infosupport/huddle-cli 0.0.0-experiment-109.59.1 → 0.0.0-experiment-98.60.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.
@@ -1,237 +0,0 @@
1
- "use strict";
2
- // ── Huddle CA → HOST trust store (sbx mode) ───────────────────────────────────
3
- // WHY THIS EXISTS (measured, not assumed):
4
- //
5
- // In sbx mode there are TWO TLS terminators, not one. For most hosts the sbx
6
- // proxy just tunnels CONNECT to Huddle, so the client *inside* the sandbox sees
7
- // Huddle's leaf and `sbx.ts:trustCa()` (CA installed in the sandbox) is enough:
8
- //
9
- // sandbox curl https://github.com → issuer: CN=Huddle DMZ Proxy Root CA
10
- //
11
- // But for at least the Claude/Anthropic hosts sbx terminates TLS ITSELF:
12
- //
13
- // sandbox curl https://platform.claude.com → issuer: CN=Docker Sandboxes Proxy CA
14
- //
15
- // There the upstream leg to Huddle is dialed by the sbx daemon — a HOST process
16
- // that validates against the HOST trust store, which does not know Huddle's CA.
17
- // The handshake with the client succeeds (sbx signs its own leaf immediately),
18
- // the upstream validation then fails, and the connection is closed without a
19
- // response: `curl: (52) Empty reply from server`, and `claude` reports
20
- // "Failed to connect to platform.claude.com: ECONNRESET".
21
- //
22
- // So the CA has to be trusted in TWO places: inside the sandbox (trustCa) and on
23
- // the host (here). Idempotent — safe to call on every `huddle init`.
24
- var __importDefault = (this && this.__importDefault) || function (mod) {
25
- return (mod && mod.__esModule) ? mod : { "default": mod };
26
- };
27
- Object.defineProperty(exports, "__esModule", { value: true });
28
- exports.HOST_CA_PATH = void 0;
29
- exports.certFingerprint = certFingerprint;
30
- exports.installHostCa = installHostCa;
31
- exports.printHostCaResult = printHostCaResult;
32
- const fs_1 = __importDefault(require("fs"));
33
- const os_1 = __importDefault(require("os"));
34
- const path_1 = __importDefault(require("path"));
35
- const crypto_1 = __importDefault(require("crypto"));
36
- const child_process_1 = require("child_process");
37
- const config_1 = require("./config");
38
- const sbx_host_1 = require("./sbx-host");
39
- const node_1 = require("./node");
40
- const utils_1 = require("./utils");
41
- /** Stable host path, so re-running init points at the same file. */
42
- exports.HOST_CA_PATH = path_1.default.join(config_1.CONFIG_DIR, 'huddle-ca.crt');
43
- const LINUX_CA_PATH = '/usr/local/share/ca-certificates/huddle-ca.crt';
44
- /** No console window per child process on Windows (same reason as sbx-host.ts). */
45
- const NO_WINDOW = { windowsHide: true };
46
- function run(file, args, timeout = 30_000) {
47
- try {
48
- const out = (0, child_process_1.execFileSync)(file, args, { encoding: 'utf8', timeout, stdio: ['ignore', 'pipe', 'pipe'], ...NO_WINDOW });
49
- return { code: 0, out: out ?? '' };
50
- }
51
- catch (err) {
52
- const e = err;
53
- const out = `${e.stdout ?? ''}${e.stderr ?? ''}` || e.message || '';
54
- return { code: typeof e.status === 'number' ? e.status : 1, out: String(out) };
55
- }
56
- }
57
- /** Blocking sleep — this runs in the CLI's synchronous init path, not in a loop. */
58
- function sleepSync(ms) {
59
- Atomics.wait(new Int32Array(new SharedArrayBuffer(4)), 0, 0, ms);
60
- }
61
- /**
62
- * Read the CA off this machine. It used to take a `docker exec` into the gateway
63
- * container, because that is where the CA lived; Huddle Node owns it now and
64
- * writes it to ~/.huddle/ca (gateway/src/runtime-env.ts), so this is a file read.
65
- *
66
- * Still retried: initCa() runs during Node's boot, and `huddle init` calls this
67
- * moments after the process reported healthy.
68
- */
69
- function readHostCa(tries = 12) {
70
- const caPath = path_1.default.join((0, node_1.nodeCaDir)(), 'ca.crt');
71
- for (let i = 0; i < tries; i++) {
72
- try {
73
- const pem = fs_1.default.readFileSync(caPath, 'utf8');
74
- if (pem.includes('-----BEGIN CERTIFICATE-----'))
75
- return pem;
76
- }
77
- catch {
78
- // Not written yet — that is the race this loop exists for.
79
- }
80
- if (i === tries - 1)
81
- return null;
82
- sleepSync(500);
83
- }
84
- return null;
85
- }
86
- /** SHA-1 over the DER body of the first PEM block — the thumbprint certutil uses. */
87
- function certFingerprint(pem) {
88
- const b64 = pem
89
- .split('-----BEGIN CERTIFICATE-----')[1]
90
- ?.split('-----END CERTIFICATE-----')[0]
91
- ?.replace(/\s+/g, '');
92
- if (!b64)
93
- throw new Error('not a PEM certificate');
94
- return crypto_1.default.createHash('sha1').update(Buffer.from(b64, 'base64')).digest('hex').toUpperCase();
95
- }
96
- // ── per-platform install ─────────────────────────────────────────────────────
97
- /**
98
- * Is the cert in this Windows root store? Asks the STORE, never the exit code:
99
- * certutil's status codes are unreliable here (`-addstore` can print its success
100
- * banner "Signature matches Public Key" and still exit non-zero, and
101
- * `-verifystore` fails a chain check on a root it does happily hold). The
102
- * thumbprint appearing in the listing is the only honest answer.
103
- */
104
- function inWindowsStore(scope, fp) {
105
- const scoped = scope === 'user' ? ['-user'] : [];
106
- const has = (out) => out.replace(/[\s:]/g, '').toUpperCase().includes(fp);
107
- // Targeted lookup first; fall back to a full dump for certutil builds that
108
- // don't take a thumbprint as the cert-id argument.
109
- if (has(run('certutil', [...scoped, '-store', 'Root', fp]).out))
110
- return true;
111
- return has(run('certutil', [...scoped, '-store', 'Root'], 60_000).out);
112
- }
113
- /** Pick the line that actually says what went wrong, not just the last one. */
114
- function certutilError(out) {
115
- const lines = out.split(/\r?\n/).map((l) => l.trim()).filter(Boolean);
116
- const blame = [...lines].reverse().find((l) => /CertUtil:|FAILED|denied|0x[0-9A-Fa-f]{8}/.test(l));
117
- return blame ?? lines.pop() ?? 'certutil failed';
118
- }
119
- function installWindows(certPath, fp) {
120
- const manualHint = `certutil -addstore -f Root "${certPath}" (elevated prompt)`;
121
- const found = (store, alreadyTrusted) => ({ ok: true, alreadyTrusted, store, certPath, fingerprint: fp, daemonRestarted: false });
122
- // Go (which sbx is built with) reads the CURRENT_USER "ROOT" store, which the
123
- // machine store is merged into — so the user store works WITHOUT elevation.
124
- if (inWindowsStore('user', fp))
125
- return found('windows-user', true);
126
- if (inWindowsStore('machine', fp))
127
- return found('windows-machine', true);
128
- const user = run('certutil', ['-user', '-addstore', '-f', 'Root', certPath]);
129
- if (inWindowsStore('user', fp))
130
- return found('windows-user', false);
131
- // Fall back to the machine store (needs an elevated prompt; usually fails here).
132
- run('certutil', ['-addstore', '-f', 'Root', certPath]);
133
- if (inWindowsStore('machine', fp))
134
- return found('windows-machine', false);
135
- return {
136
- ok: false, alreadyTrusted: false, certPath, fingerprint: fp, daemonRestarted: false,
137
- error: certutilError(user.out),
138
- manualHint,
139
- };
140
- }
141
- function installMacos(certPath, fp) {
142
- const keychain = path_1.default.join(os_1.default.homedir(), 'Library/Keychains/login.keychain-db');
143
- const manualHint = `security add-trusted-cert -r trustRoot -k "${keychain}" "${certPath}"`;
144
- const found = run('security', ['find-certificate', '-a', '-Z', keychain]);
145
- if (found.code === 0 && found.out.toUpperCase().includes(fp)) {
146
- return { ok: true, alreadyTrusted: true, store: 'macos-login', certPath, fingerprint: fp, daemonRestarted: false };
147
- }
148
- // No -d: the login keychain needs no sudo (it may raise a GUI confirmation).
149
- const add = run('security', ['add-trusted-cert', '-r', 'trustRoot', '-k', keychain, certPath], 60_000);
150
- if (add.code === 0) {
151
- return { ok: true, alreadyTrusted: false, store: 'macos-login', certPath, fingerprint: fp, daemonRestarted: false };
152
- }
153
- return { ok: false, alreadyTrusted: false, certPath, fingerprint: fp, daemonRestarted: false, error: add.out.trim(), manualHint };
154
- }
155
- function installLinux(certPath, pem, fp) {
156
- const manualHint = `sudo cp "${certPath}" ${LINUX_CA_PATH} && sudo update-ca-certificates`;
157
- try {
158
- if (fs_1.default.readFileSync(LINUX_CA_PATH, 'utf8').trim() === pem.trim()) {
159
- return { ok: true, alreadyTrusted: true, store: 'linux-system', certPath, fingerprint: fp, daemonRestarted: false };
160
- }
161
- }
162
- catch { /* not installed yet */ }
163
- const copy = run('sh', ['-c', `cp ${JSON.stringify(certPath)} ${LINUX_CA_PATH} 2>/dev/null || (command -v sudo >/dev/null 2>&1 && sudo -n cp ${JSON.stringify(certPath)} ${LINUX_CA_PATH})`]);
164
- if (copy.code !== 0) {
165
- return { ok: false, alreadyTrusted: false, certPath, fingerprint: fp, daemonRestarted: false, error: 'need root to write ' + LINUX_CA_PATH, manualHint };
166
- }
167
- run('sh', ['-c', 'command -v update-ca-certificates >/dev/null 2>&1 && (update-ca-certificates >/dev/null 2>&1 || sudo -n update-ca-certificates >/dev/null 2>&1) || true'], 60_000);
168
- return { ok: true, alreadyTrusted: false, store: 'linux-system', certPath, fingerprint: fp, daemonRestarted: false };
169
- }
170
- /**
171
- * Trust Huddle's CA on the HOST, then restart the sbx daemon so it reloads its
172
- * root set. Never throws — sandbox mode is optional
173
- * and this must never fail `huddle init`.
174
- */
175
- function installHostCa(opts = {}) {
176
- const pem = readHostCa();
177
- if (!pem) {
178
- const caPath = path_1.default.join((0, node_1.nodeCaDir)(), 'ca.crt');
179
- return {
180
- ok: false, alreadyTrusted: false, daemonRestarted: false,
181
- error: `could not read ${caPath} — is Huddle Node running?`,
182
- manualHint: `huddle init (Huddle Node writes the CA on boot)`,
183
- };
184
- }
185
- let fp;
186
- try {
187
- fp = certFingerprint(pem);
188
- }
189
- catch (err) {
190
- return { ok: false, alreadyTrusted: false, daemonRestarted: false, error: err.message };
191
- }
192
- try {
193
- fs_1.default.mkdirSync(config_1.CONFIG_DIR, { recursive: true });
194
- fs_1.default.writeFileSync(exports.HOST_CA_PATH, pem, { mode: 0o644 });
195
- }
196
- catch (err) {
197
- return { ok: false, alreadyTrusted: false, fingerprint: fp, daemonRestarted: false, error: err.message };
198
- }
199
- let result;
200
- if (process.platform === 'win32')
201
- result = installWindows(exports.HOST_CA_PATH, fp);
202
- else if (process.platform === 'darwin')
203
- result = installMacos(exports.HOST_CA_PATH, fp);
204
- else
205
- result = installLinux(exports.HOST_CA_PATH, pem, fp);
206
- // A freshly added root is only picked up by a running daemon after a restart.
207
- // 'always' is for the explicit `huddle sbx trust-host`: you only type that when
208
- // something is broken, and a store that was filled by an earlier run (before
209
- // any restart) must not be silently skipped as "already trusted".
210
- const mode = opts.restartDaemon ?? 'auto';
211
- if (result.ok && mode !== 'never' && (mode === 'always' || !result.alreadyTrusted)) {
212
- result.daemonRestarted = run((0, sbx_host_1.resolveSbxBin)(), ['daemon', 'restart'], 120_000).code === 0;
213
- }
214
- return result;
215
- }
216
- /** Human-readable one-liner + guidance. Shared by `huddle init` and `huddle sbx trust-host`. */
217
- function printHostCaResult(r, indent = ' ') {
218
- if (r.ok && r.alreadyTrusted) {
219
- console.log((0, utils_1.dim)(`${indent}Huddle CA already trusted on the host (${r.store}) — sbx can reach Huddle over TLS.`));
220
- if (r.daemonRestarted)
221
- console.log((0, utils_1.dim)(`${indent} sbx daemon restarted so it re-reads the root store.`));
222
- return;
223
- }
224
- if (r.ok) {
225
- console.log((0, utils_1.green)(`${indent}[OK] Huddle CA trusted on the host (${r.store})`));
226
- console.log((0, utils_1.dim)(`${indent} ${r.certPath} · SHA-1 ${r.fingerprint}`));
227
- console.log((0, utils_1.dim)(`${indent} ${r.daemonRestarted ? 'sbx daemon restarted' : 'restart the sbx daemon to pick it up: sbx daemon restart'}`));
228
- return;
229
- }
230
- console.log((0, utils_1.yellow)(`${indent}Could not trust Huddle's CA on the host: ${r.error}`));
231
- console.log((0, utils_1.dim)(`${indent} Without it, sbx cannot validate Huddle for the hosts it MITMs itself`));
232
- console.log((0, utils_1.dim)(`${indent} (e.g. platform.claude.com) — those requests die as "Empty reply from server".`));
233
- if (r.manualHint)
234
- console.log((0, utils_1.dim)(`${indent} Do it manually: ${r.manualHint}`));
235
- if (r.certPath)
236
- console.log((0, utils_1.dim)(`${indent} Then: sbx daemon restart`));
237
- }
package/dist/sbx-host.js DELETED
@@ -1,36 +0,0 @@
1
- "use strict";
2
- // ── Finding sbx on the host ───────────────────────────────────────────────────
3
- // Docker Sandboxes (`sbx`) is a HOST binary. It manages VMs/containers through
4
- // the user's own Docker installation and it is the thing Huddle points at its
5
- // egress proxy — it was never something the gateway container could run.
6
- //
7
- // This module is what remains of the sbx bridge after the split (step 5 of
8
- // docs/ADR-huddle-node-split.md): the bridge existed only to carry argv from a
9
- // containerized Huddle to the host and back, and Huddle Node runs on the host,
10
- // so it exec's sbx directly. Resolving WHICH binary and keeping Windows from
11
- // flashing a console window are still real problems, so they live on here.
12
- Object.defineProperty(exports, "__esModule", { value: true });
13
- exports.NO_WINDOW = void 0;
14
- exports.resolveSbxBin = resolveSbxBin;
15
- const child_process_1 = require("child_process");
16
- /**
17
- * No console window per child process on Windows.
18
- *
19
- * Huddle spawns sbx often and sometimes from a detached, console-less process;
20
- * without this, Windows opens a terminal window for every single call.
21
- */
22
- exports.NO_WINDOW = { windowsHide: true };
23
- /** Resolve the host sbx binary: HUDDLE_SBX_BIN, else `sbx`, else `sbx.exe`. */
24
- function resolveSbxBin() {
25
- const env = process.env.HUDDLE_SBX_BIN?.trim();
26
- if (env)
27
- return env;
28
- for (const c of ['sbx', 'sbx.exe']) {
29
- try {
30
- (0, child_process_1.execFileSync)(c, ['version'], { stdio: 'ignore', timeout: 15000, ...exports.NO_WINDOW });
31
- return c;
32
- }
33
- catch { /* try next */ }
34
- }
35
- return 'sbx';
36
- }
package/dist/sbx.js DELETED
@@ -1,206 +0,0 @@
1
- "use strict";
2
- // ── `huddle sbx` — Docker Sandboxes command group ─────────────────────────────
3
- // Thin client: every subcommand just calls the gateway's /api/sbx/* endpoints
4
- // (same role the rest of the CLI plays). The gateway talks to the native
5
- // host-agent over the volume-mapped socket; nothing sbx-related runs here.
6
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
7
- if (k2 === undefined) k2 = k;
8
- var desc = Object.getOwnPropertyDescriptor(m, k);
9
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
10
- desc = { enumerable: true, get: function() { return m[k]; } };
11
- }
12
- Object.defineProperty(o, k2, desc);
13
- }) : (function(o, m, k, k2) {
14
- if (k2 === undefined) k2 = k;
15
- o[k2] = m[k];
16
- }));
17
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
18
- Object.defineProperty(o, "default", { enumerable: true, value: v });
19
- }) : function(o, v) {
20
- o["default"] = v;
21
- });
22
- var __importStar = (this && this.__importStar) || (function () {
23
- var ownKeys = function(o) {
24
- ownKeys = Object.getOwnPropertyNames || function (o) {
25
- var ar = [];
26
- for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
27
- return ar;
28
- };
29
- return ownKeys(o);
30
- };
31
- return function (mod) {
32
- if (mod && mod.__esModule) return mod;
33
- var result = {};
34
- if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
35
- __setModuleDefault(result, mod);
36
- return result;
37
- };
38
- })();
39
- Object.defineProperty(exports, "__esModule", { value: true });
40
- exports.runSbxStatus = runSbxStatus;
41
- exports.runSbxList = runSbxList;
42
- exports.runSbxStart = runSbxStart;
43
- exports.runSbxRemove = runSbxRemove;
44
- exports.runSbxLog = runSbxLog;
45
- exports.runSbxTrustCa = runSbxTrustCa;
46
- exports.runSbxTrustHost = runSbxTrustHost;
47
- exports.runSbxSshSetup = runSbxSshSetup;
48
- exports.runSbxReconcile = runSbxReconcile;
49
- const api_1 = require("./api");
50
- const utils_1 = require("./utils");
51
- function scopeLabel(scope) {
52
- return scope.kind === 'sandbox' && scope.name ? `sandbox:${scope.name}` : 'global';
53
- }
54
- async function runSbxStatus() {
55
- const s = await (0, api_1.get)('/api/sbx/status');
56
- console.log(`Sandbox (sbx) mode`);
57
- console.log(` host-agent socket: ${s.socket ?? (0, utils_1.dim)('(not reachable)')}`);
58
- console.log(` upstream proxy: ${s.upstreamUrl} ${(0, utils_1.dim)(`(port ${s.proxyPort})`)}`);
59
- if (s.available) {
60
- console.log(` sbx: ready — ${s.version}`);
61
- }
62
- else {
63
- console.log(` sbx: unavailable`);
64
- if (s.error)
65
- console.log((0, utils_1.dim)(` reason: ${s.error}`));
66
- }
67
- }
68
- async function runSbxList() {
69
- const { sandboxes } = await (0, api_1.get)('/api/sbx/sandboxes');
70
- if (!sandboxes.length) {
71
- console.log((0, utils_1.dim)('No sandboxes.'));
72
- return;
73
- }
74
- const nameW = Math.max(4, ...sandboxes.map((s) => s.name.length));
75
- console.log(`${'NAME'.padEnd(nameW)} STATUS`);
76
- for (const s of sandboxes)
77
- console.log(`${s.name.padEnd(nameW)} ${s.status ?? ''}`);
78
- }
79
- async function runSbxStart(opts) {
80
- const body = {};
81
- if (opts.name)
82
- body.name = opts.name;
83
- if (opts.agent)
84
- body.agent = opts.agent;
85
- // A sandbox can hold several folders: --workspace is the one the agent starts in,
86
- // every --folder is mounted alongside it. `<path>:ro` mounts that folder
87
- // read-only (sbx's own suffix). Huddle's settings folders are added server-side.
88
- const folders = (opts.folders ?? []).map((f) => f.trim()).filter(Boolean);
89
- if (folders.length) {
90
- const first = opts.workspace ? [{ path: opts.workspace, readOnly: false }] : [];
91
- body.workspaces = [...first, ...folders.map(parseFolderArg)];
92
- }
93
- else if (opts.workspace) {
94
- body.workspace = opts.workspace;
95
- }
96
- const r = await (0, api_1.post)('/api/sbx/start', body);
97
- console.log(`${r.ok ? '✓ sandbox created' : '✗ stopped at a wall'}: ${r.name}`);
98
- console.log((0, utils_1.dim)(` upstream ${r.upstreamUrl}`));
99
- for (const w of r.workspaces ?? [])
100
- console.log((0, utils_1.dim)(` folder ${w.path}${w.readOnly ? ' (read-only)' : ''}`));
101
- for (const step of r.steps) {
102
- console.log(` ${step.code === 0 ? '✓' : '✗'} ${step.label} ${(0, utils_1.dim)(`(exit ${step.code})`)}`);
103
- console.log((0, utils_1.dim)(` ${step.command}`));
104
- if (step.stdout?.trim() && step.label.startsWith('link settings folders')) {
105
- console.log((0, utils_1.dim)(` ${step.stdout.trim().split('\n').join('\n ')}`));
106
- }
107
- if (step.stderr.trim())
108
- console.log((0, utils_1.dim)(` ${step.stderr.trim().split('\n').join('\n ')}`));
109
- }
110
- for (const s of r.settingsSkipped ?? [])
111
- console.log((0, utils_1.dim)(` ! settings folder '${s.name}' not mounted: ${s.reason}`));
112
- if (!r.ok)
113
- process.exitCode = 1;
114
- }
115
- /** `<host path>` or `<host path>:ro` — sbx's own read-only workspace suffix. */
116
- function parseFolderArg(raw) {
117
- const m = /^(.*?):(ro|rw)$/i.exec(raw);
118
- if (!m)
119
- return { path: raw, readOnly: false };
120
- return { path: m[1], readOnly: m[2].toLowerCase() === 'ro' };
121
- }
122
- async function runSbxRemove(opts) {
123
- if (!opts.name) {
124
- console.error('Usage: huddle sbx rm <name> [--force]');
125
- process.exit(1);
126
- }
127
- const q = opts.force ? '?force=1' : '';
128
- const r = await (0, api_1.del)(`/api/sbx/sandboxes/${encodeURIComponent(opts.name)}${q}`);
129
- console.log(`${r.ok ? '✓ removed' : '✗ failed'}: ${r.name} ${(0, utils_1.dim)(`(exit ${r.exitCode})`)}`);
130
- if (!r.ok)
131
- process.exitCode = 1;
132
- }
133
- async function runSbxLog(opts) {
134
- if (!opts.name) {
135
- console.error('Usage: huddle sbx log <name>');
136
- process.exit(1);
137
- }
138
- const r = await (0, api_1.get)(`/api/sbx/sandboxes/${encodeURIComponent(opts.name)}/log`);
139
- console.log((0, utils_1.dim)('── raw `sbx policy log --json` ──'));
140
- console.log(r.raw.trim() || (0, utils_1.dim)('(empty)'));
141
- console.log((0, utils_1.dim)(`── parsed denied (${r.denied.length}) ──`));
142
- for (const d of r.denied)
143
- console.log(` ✗ ${d.domain}${d.sandbox ? (0, utils_1.dim)(' @ ' + d.sandbox) : ''}`);
144
- if (r.denied.length === 0)
145
- console.log((0, utils_1.dim)(' (parser matched nothing — paste the raw JSON above so the parser can be tuned)'));
146
- }
147
- async function runSbxTrustCa(opts) {
148
- if (!opts.name) {
149
- console.error('Usage: huddle sbx trust-ca <name>');
150
- process.exit(1);
151
- }
152
- const r = await (0, api_1.post)(`/api/sbx/sandboxes/${encodeURIComponent(opts.name)}/trust-ca`, {});
153
- const marker = (r.stdout || '').match(/HUDDLE_CA_INSTALLED_\w+/)?.[0];
154
- console.log(`${r.ok ? '✓ Huddle CA installed' : '✗ CA install failed'}: ${r.name} ${(0, utils_1.dim)(`(exit ${r.code}${marker ? ', ' + marker.toLowerCase() : ''})`)}`);
155
- if (r.stderr?.trim())
156
- console.log((0, utils_1.dim)(` ${r.stderr.trim().split('\n').join('\n ')}`));
157
- if (r.ok)
158
- console.log((0, utils_1.dim)(' HTTPS from inside the sandbox now trusts Huddle — reconnect your editor.'));
159
- else
160
- process.exitCode = 1;
161
- }
162
- /**
163
- * Trust Huddle's CA on the HOST (where the sbx daemon runs), not inside a
164
- * sandbox. Needed because sbx terminates TLS itself for some hosts (measured:
165
- * platform.claude.com gets a `Docker Sandboxes Proxy CA` leaf) and then
166
- * validates Huddle's certificate against the host trust store. Without it those
167
- * requests die as "Empty reply from server" / ECONNRESET — see sbx-host-ca.ts.
168
- */
169
- async function runSbxTrustHost(opts = {}) {
170
- const { installHostCa, printHostCaResult } = await Promise.resolve().then(() => __importStar(require('./sbx-host-ca')));
171
- console.log('Trusting Huddle’s CA on the host (for the sbx daemon)');
172
- const r = installHostCa({ restartDaemon: 'always' });
173
- printHostCaResult(r);
174
- if (!r.ok)
175
- process.exitCode = 1;
176
- }
177
- async function runSbxSshSetup() {
178
- const r = await (0, api_1.post)('/api/sbx/ssh-setup', {});
179
- if (r.ok) {
180
- console.log('✓ SSH bridge ready. Connect an editor with:');
181
- console.log((0, utils_1.dim)(' ssh <sandbox-name>.sbx # or add it as a VS Code / JetBrains remote host'));
182
- }
183
- else {
184
- console.log(`✗ ssh setup failed (exit ${r.exitCode})`);
185
- process.exitCode = 1;
186
- }
187
- }
188
- async function runSbxReconcile(opts) {
189
- const q = opts.dryRun ? '?dryRun=1' : '';
190
- const r = await (0, api_1.post)(`/api/sbx/reconcile${q}`, {});
191
- const mode = r.dryRun ? 'DRY RUN — ' : '';
192
- if (r.error) {
193
- console.error(`✗ ${mode}reconcile could not run: ${r.error}`);
194
- process.exit(1);
195
- }
196
- console.log(`${mode}Reconcile sbx policy (allow-all per sandbox; Huddle's proxy enforces)`);
197
- console.log(` created: ${r.created} removed: ${r.deleted} failed: ${r.failed}`);
198
- if (r.sandboxes.length)
199
- console.log((0, utils_1.dim)(` sandboxes: ${r.sandboxes.map((n) => 'sandbox:' + n).join(', ')}`));
200
- for (const a of r.actions) {
201
- const sym = a.ok ? (a.op === 'create' ? '+' : '-') : '✗';
202
- console.log(` ${sym} ${a.op} ${a.action} ${a.target} @ ${scopeLabel(a.scope)}${a.error ? (0, utils_1.dim)(' — ' + a.error) : ''}`);
203
- }
204
- if (r.failed > 0)
205
- process.exitCode = 1;
206
- }