@infosupport/huddle-cli 1.2.20 → 1.2.36
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/api.js +11 -5
- package/dist/config.js +5 -2
- package/dist/extension.js +133 -0
- package/dist/host-logs.js +60 -0
- package/dist/index.js +36 -1
- package/dist/init.js +16 -5
- package/dist/zip.js +74 -0
- package/package.json +7 -3
package/dist/api.js
CHANGED
|
@@ -3,6 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.del = exports.put = exports.post = exports.get = exports.ApiError = void 0;
|
|
4
4
|
exports.setBaseUrl = setBaseUrl;
|
|
5
5
|
exports.apiCall = apiCall;
|
|
6
|
+
exports.uploadFile = uploadFile;
|
|
6
7
|
const config_1 = require("./config");
|
|
7
8
|
let baseUrl = normalizeBaseUrl(process.env.HUDDLE_URL ?? 'http://localhost:3000');
|
|
8
9
|
class ApiError extends Error {
|
|
@@ -21,6 +22,15 @@ async function apiCall(method, path, body) {
|
|
|
21
22
|
const headers = {};
|
|
22
23
|
if (body !== undefined)
|
|
23
24
|
headers['content-type'] = 'application/json';
|
|
25
|
+
return send(method, path, body !== undefined ? JSON.stringify(body) : undefined, headers);
|
|
26
|
+
}
|
|
27
|
+
/** POSTs one file as multipart/form-data (field `file`), e.g. an extension zip. */
|
|
28
|
+
async function uploadFile(path, fileName, data) {
|
|
29
|
+
const form = new FormData();
|
|
30
|
+
form.append('file', new Blob([new Uint8Array(data)]), fileName);
|
|
31
|
+
return send('POST', path, form, {});
|
|
32
|
+
}
|
|
33
|
+
async function send(method, path, body, headers) {
|
|
24
34
|
// Operator-auth: stuur het token als Bearer mee zodat de CLI de control-plane
|
|
25
35
|
// -auth passeert. Zonder token krijgen we een 401 met een duidelijke hint.
|
|
26
36
|
const token = (0, config_1.operatorToken)();
|
|
@@ -28,11 +38,7 @@ async function apiCall(method, path, body) {
|
|
|
28
38
|
headers['authorization'] = `Bearer ${token}`;
|
|
29
39
|
let res;
|
|
30
40
|
try {
|
|
31
|
-
res = await fetch(`${baseUrl}${path}`, {
|
|
32
|
-
method,
|
|
33
|
-
headers,
|
|
34
|
-
body: body !== undefined ? JSON.stringify(body) : undefined,
|
|
35
|
-
});
|
|
41
|
+
res = await fetch(`${baseUrl}${path}`, { method, headers, body });
|
|
36
42
|
}
|
|
37
43
|
catch (err) {
|
|
38
44
|
const detail = err instanceof Error ? err.message : String(err);
|
package/dist/config.js
CHANGED
|
@@ -139,7 +139,10 @@ let tmpSeq = 0;
|
|
|
139
139
|
* config.
|
|
140
140
|
*/
|
|
141
141
|
function updateConfig(patch) {
|
|
142
|
-
|
|
142
|
+
// The config holds the operator token: owner-only. chmod as well, because
|
|
143
|
+
// mkdir's mode does not tighten a directory created by an older version.
|
|
144
|
+
fs_1.default.mkdirSync(exports.CONFIG_DIR, { recursive: true, mode: 0o700 });
|
|
145
|
+
fs_1.default.chmodSync(exports.CONFIG_DIR, 0o700);
|
|
143
146
|
const token = acquireLock();
|
|
144
147
|
if (token === null) {
|
|
145
148
|
throw new Error(`Could not lock ${CONFIG_PATH} within ${LOCK_WAIT_MS}ms — another Huddle process ` +
|
|
@@ -153,7 +156,7 @@ function updateConfig(patch) {
|
|
|
153
156
|
if (v === undefined)
|
|
154
157
|
delete next[k];
|
|
155
158
|
}
|
|
156
|
-
fs_1.default.writeFileSync(tmp, `${JSON.stringify(next, null, 2)}\n
|
|
159
|
+
fs_1.default.writeFileSync(tmp, `${JSON.stringify(next, null, 2)}\n`, { mode: 0o600 });
|
|
157
160
|
fs_1.default.renameSync(tmp, CONFIG_PATH);
|
|
158
161
|
return next;
|
|
159
162
|
}
|
|
@@ -0,0 +1,133 @@
|
|
|
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.isExtensionId = exports.MAX_FOLDER_DEPTH = void 0;
|
|
7
|
+
exports.insideFolder = insideFolder;
|
|
8
|
+
exports.collectExtensionFiles = collectExtensionFiles;
|
|
9
|
+
exports.planInstall = planInstall;
|
|
10
|
+
exports.asExtensionList = asExtensionList;
|
|
11
|
+
exports.runExtensionList = runExtensionList;
|
|
12
|
+
exports.runExtensionInstall = runExtensionInstall;
|
|
13
|
+
exports.runExtensionRemove = runExtensionRemove;
|
|
14
|
+
const fs_1 = __importDefault(require("fs"));
|
|
15
|
+
const path_1 = __importDefault(require("path"));
|
|
16
|
+
const child_process_1 = require("child_process");
|
|
17
|
+
const api_1 = require("./api");
|
|
18
|
+
const zip_1 = require("./zip");
|
|
19
|
+
const init_1 = require("./init");
|
|
20
|
+
const runtime_1 = require("./runtime");
|
|
21
|
+
const utils_1 = require("./utils");
|
|
22
|
+
const SKIPPED = new Set(['node_modules']);
|
|
23
|
+
exports.MAX_FOLDER_DEPTH = 32;
|
|
24
|
+
/** The gateway's own id rule: one lowercase path component, so it can never point outside the extensions folder. */
|
|
25
|
+
const isExtensionId = (id) => typeof id === 'string' && /^[a-z0-9-]+$/.test(id);
|
|
26
|
+
exports.isExtensionId = isExtensionId;
|
|
27
|
+
/** Resolves `rel` within `root` and refuses anything that lands outside it (`..`, absolute paths). */
|
|
28
|
+
function insideFolder(root, rel) {
|
|
29
|
+
const base = path_1.default.resolve(root);
|
|
30
|
+
const abs = path_1.default.resolve(base, rel);
|
|
31
|
+
if (abs !== base && !abs.startsWith(base + path_1.default.sep))
|
|
32
|
+
throw new Error(`${rel} is outside the extension folder`);
|
|
33
|
+
return abs;
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Reads a regular file of the folder; a symlink is refused, so the zip can never carry a file from outside it.
|
|
37
|
+
* @param root the resolved extension folder @param rel a path relative to it, from readdir
|
|
38
|
+
*/
|
|
39
|
+
function readPlainFile(root, rel) {
|
|
40
|
+
const abs = insideFolder(root, rel);
|
|
41
|
+
const stat = fs_1.default.lstatSync(abs);
|
|
42
|
+
if (stat.isSymbolicLink())
|
|
43
|
+
throw new Error(`${rel} is a symlink; extensions are packaged without symlinks`);
|
|
44
|
+
if (!stat.isFile())
|
|
45
|
+
throw new Error(`${rel} is not a regular file`);
|
|
46
|
+
return fs_1.default.readFileSync(abs);
|
|
47
|
+
}
|
|
48
|
+
/** Reads an extension folder into zip entries; the manifest must pass the gateway's own id rule. */
|
|
49
|
+
function collectExtensionFiles(dir) {
|
|
50
|
+
const root = path_1.default.resolve(dir);
|
|
51
|
+
for (const required of ['manifest.json', 'index.js']) {
|
|
52
|
+
if (!fs_1.default.lstatSync(insideFolder(root, required), { throwIfNoEntry: false }))
|
|
53
|
+
throw new Error(`${required} missing in ${root}`);
|
|
54
|
+
}
|
|
55
|
+
const manifest = JSON.parse(readPlainFile(root, 'manifest.json').toString('utf8'));
|
|
56
|
+
if (!(0, exports.isExtensionId)(manifest.id)) {
|
|
57
|
+
throw new Error(`manifest id ${JSON.stringify(manifest.id)} must be lowercase letters, digits and -`);
|
|
58
|
+
}
|
|
59
|
+
if (typeof manifest.name !== 'string' || !manifest.name)
|
|
60
|
+
throw new Error('manifest name is required');
|
|
61
|
+
readPlainFile(root, 'index.js');
|
|
62
|
+
const entries = [];
|
|
63
|
+
const walk = (rel, depth) => {
|
|
64
|
+
if (depth > exports.MAX_FOLDER_DEPTH)
|
|
65
|
+
throw new Error(`${rel} is nested deeper than ${exports.MAX_FOLDER_DEPTH} folders`);
|
|
66
|
+
for (const item of fs_1.default.readdirSync(insideFolder(root, rel), { withFileTypes: true })) {
|
|
67
|
+
if (item.name.startsWith('.') || SKIPPED.has(item.name))
|
|
68
|
+
continue;
|
|
69
|
+
const childRel = rel ? `${rel}/${item.name}` : item.name;
|
|
70
|
+
if (item.isSymbolicLink())
|
|
71
|
+
throw new Error(`${childRel} is a symlink; extensions are packaged without symlinks`);
|
|
72
|
+
if (item.isDirectory())
|
|
73
|
+
walk(childRel, depth + 1);
|
|
74
|
+
else if (item.isFile())
|
|
75
|
+
entries.push({ name: childRel, data: readPlainFile(root, childRel) });
|
|
76
|
+
}
|
|
77
|
+
};
|
|
78
|
+
walk('', 0);
|
|
79
|
+
return { manifest, entries };
|
|
80
|
+
}
|
|
81
|
+
/** An id already taken by an extension with another name is someone else's; only --force replaces it. */
|
|
82
|
+
function planInstall(incoming, installed, force) {
|
|
83
|
+
const existing = installed.find((e) => e.id === incoming.id);
|
|
84
|
+
if (!existing)
|
|
85
|
+
return { action: 'install' };
|
|
86
|
+
const from = existing.version ?? 'unknown';
|
|
87
|
+
if (existing.name !== incoming.name && !force) {
|
|
88
|
+
return {
|
|
89
|
+
action: 'refuse',
|
|
90
|
+
reason: `id '${incoming.id}' belongs to "${existing.name}" (v${from}), not "${incoming.name}". Use --force to replace it.`,
|
|
91
|
+
};
|
|
92
|
+
}
|
|
93
|
+
return { action: 'update', from };
|
|
94
|
+
}
|
|
95
|
+
/** The answer of /api/extensions, or an error when another service holds Huddle's address. */
|
|
96
|
+
function asExtensionList(value) {
|
|
97
|
+
if (!Array.isArray(value))
|
|
98
|
+
throw new Error('could not reach Huddle: the address answered, but not with its extensions. Check HUDDLE_URL.');
|
|
99
|
+
return value;
|
|
100
|
+
}
|
|
101
|
+
async function runExtensionList() {
|
|
102
|
+
const installed = asExtensionList(await (0, api_1.get)('/api/extensions'));
|
|
103
|
+
if (!installed.length) {
|
|
104
|
+
console.log('No extensions installed.');
|
|
105
|
+
return;
|
|
106
|
+
}
|
|
107
|
+
(0, utils_1.printTable)(['ID', 'NAME', 'VERSION', 'ENABLED'], installed.map((e) => [e.id, e.name, e.version ?? '-', e.enabled === false ? 'no' : 'yes']));
|
|
108
|
+
}
|
|
109
|
+
async function runExtensionInstall(dir, opts) {
|
|
110
|
+
const { manifest, entries } = collectExtensionFiles(dir);
|
|
111
|
+
const plan = planInstall(manifest, asExtensionList(await (0, api_1.get)('/api/extensions')), opts.force);
|
|
112
|
+
if (plan.action === 'refuse')
|
|
113
|
+
throw new Error(plan.reason);
|
|
114
|
+
const result = await (0, api_1.uploadFile)('/api/extensions/upload', `${manifest.id}.zip`, (0, zip_1.createZip)(entries));
|
|
115
|
+
const verb = plan.action === 'update' ? `Updated ${manifest.id} v${plan.from} → v${manifest.version ?? '?'}` : `Installed ${manifest.id} v${manifest.version ?? '?'}`;
|
|
116
|
+
console.log((0, utils_1.green)(`[OK] ${verb}`));
|
|
117
|
+
if (!result.restartRequired)
|
|
118
|
+
return;
|
|
119
|
+
if (!opts.restart) {
|
|
120
|
+
console.log((0, utils_1.yellow)('The gateway keeps running the old code until it restarts. Re-run with --restart, or restart the huddle container.'));
|
|
121
|
+
return;
|
|
122
|
+
}
|
|
123
|
+
const rt = (0, runtime_1.resolveRuntime)().name;
|
|
124
|
+
console.log((0, utils_1.dim)(`Restarting the gateway process (${rt} restart ${init_1.CONTAINER}); the container itself is kept.`));
|
|
125
|
+
(0, child_process_1.execFileSync)(rt, ['restart', init_1.CONTAINER], { stdio: 'ignore' });
|
|
126
|
+
console.log((0, utils_1.green)('[OK] Gateway restarted with the new extension code.'));
|
|
127
|
+
}
|
|
128
|
+
async function runExtensionRemove(id) {
|
|
129
|
+
if (!(0, exports.isExtensionId)(id))
|
|
130
|
+
throw new Error(`invalid extension id: ${id}`);
|
|
131
|
+
await (0, api_1.del)(`/api/extensions/${id}`);
|
|
132
|
+
console.log((0, utils_1.green)(`[OK] Removed ${id}`));
|
|
133
|
+
}
|
|
@@ -0,0 +1,60 @@
|
|
|
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.HOST_CODEX_INDEX_MOUNT = exports.HOST_CODEX_LOGS_MOUNT = exports.HOST_AGENT_LOGS_MOUNT = void 0;
|
|
7
|
+
exports.hostAgentLogsMountArgs = hostAgentLogsMountArgs;
|
|
8
|
+
exports.hostCodexLogsMountArgs = hostCodexLogsMountArgs;
|
|
9
|
+
exports.hostCodexIndexMountArgs = hostCodexIndexMountArgs;
|
|
10
|
+
const fs_1 = __importDefault(require("fs"));
|
|
11
|
+
const path_1 = __importDefault(require("path"));
|
|
12
|
+
/** Must match HOST_AGENT_LOGS_MOUNT in gateway/src/host-config.ts. */
|
|
13
|
+
exports.HOST_AGENT_LOGS_MOUNT = '/host-logs/claude/projects';
|
|
14
|
+
/** Must match HOST_CODEX_LOGS_MOUNT in gateway/src/host-config.ts. */
|
|
15
|
+
exports.HOST_CODEX_LOGS_MOUNT = '/host-logs/codex/sessions';
|
|
16
|
+
/** Extensions read the Codex index here; the gateway itself never opens it. */
|
|
17
|
+
exports.HOST_CODEX_INDEX_MOUNT = '/host-logs/codex/session_index.jsonl';
|
|
18
|
+
/** A real directory only: Docker follows a symlinked source, which could point the mount at ~/.claude itself. */
|
|
19
|
+
const isPlainDir = (p) => {
|
|
20
|
+
try {
|
|
21
|
+
return fs_1.default.lstatSync(p).isDirectory();
|
|
22
|
+
}
|
|
23
|
+
catch {
|
|
24
|
+
return false;
|
|
25
|
+
}
|
|
26
|
+
};
|
|
27
|
+
/**
|
|
28
|
+
* `docker run` args that expose the host's Claude session logs to extensions:
|
|
29
|
+
* only ~/.claude/projects, read-only — never ~/.claude itself, which holds credentials.
|
|
30
|
+
*/
|
|
31
|
+
function hostAgentLogsMountArgs(cfg, homeDir, exists = isPlainDir) {
|
|
32
|
+
if (cfg.hostAgentLogs !== true)
|
|
33
|
+
return [];
|
|
34
|
+
const projects = path_1.default.join(homeDir, '.claude', 'projects');
|
|
35
|
+
return exists(projects) ? ['-v', `${projects}:${exports.HOST_AGENT_LOGS_MOUNT}:ro`] : [];
|
|
36
|
+
}
|
|
37
|
+
/** The same for Codex: only ~/.codex/sessions, read-only — never ~/.codex itself, which holds auth.json. */
|
|
38
|
+
function hostCodexLogsMountArgs(cfg, homeDir, exists = isPlainDir) {
|
|
39
|
+
if (cfg.hostAgentLogs !== true)
|
|
40
|
+
return [];
|
|
41
|
+
const sessions = path_1.default.join(homeDir, '.codex', 'sessions');
|
|
42
|
+
return exists(sessions) ? ['-v', `${sessions}:${exports.HOST_CODEX_LOGS_MOUNT}:ro`] : [];
|
|
43
|
+
}
|
|
44
|
+
/** A plain file only: a symlink or hard link here could point the mount at auth.json. */
|
|
45
|
+
const isPlainFile = (p) => {
|
|
46
|
+
try {
|
|
47
|
+
const stat = fs_1.default.lstatSync(p);
|
|
48
|
+
return stat.isFile() && stat.nlink === 1;
|
|
49
|
+
}
|
|
50
|
+
catch {
|
|
51
|
+
return false;
|
|
52
|
+
}
|
|
53
|
+
};
|
|
54
|
+
/** Codex keeps thread names in ~/.codex/session_index.jsonl; only that file is mounted, read-only. */
|
|
55
|
+
function hostCodexIndexMountArgs(cfg, homeDir, exists = isPlainFile) {
|
|
56
|
+
if (cfg.hostAgentLogs !== true)
|
|
57
|
+
return [];
|
|
58
|
+
const index = path_1.default.join(homeDir, '.codex', 'session_index.jsonl');
|
|
59
|
+
return exists(index) ? ['-v', `${index}:${exports.HOST_CODEX_INDEX_MOUNT}:ro`] : [];
|
|
60
|
+
}
|
package/dist/index.js
CHANGED
|
@@ -8,6 +8,7 @@ const fs_1 = __importDefault(require("fs"));
|
|
|
8
8
|
const path_1 = __importDefault(require("path"));
|
|
9
9
|
const api_1 = require("./api");
|
|
10
10
|
const start_1 = require("./start");
|
|
11
|
+
const extension_1 = require("./extension");
|
|
11
12
|
const firewall_1 = require("./firewall");
|
|
12
13
|
const init_1 = require("./init");
|
|
13
14
|
const migrate_1 = require("./migrate");
|
|
@@ -18,7 +19,7 @@ const utils_1 = require("./utils");
|
|
|
18
19
|
const experiment_1 = require("./experiment");
|
|
19
20
|
const VALUE_FLAGS = new Set(['url', 'ide', 'name', 'image', 'workspace', 'container', 'status', 'runtime', 'experiment', 'path', 'ca-path', 'output', 'out', 'workspace-root', 'depth']);
|
|
20
21
|
const BOOLEAN_FLAGS = new Set(['help', 'h', 'empty', 'i', 'interactive', 'version', 'v', 'deny', 'docker-socket', 'force', 'replace', 'all', 'list', 'clear']);
|
|
21
|
-
const COMMANDS = new Set(['start', 'firewall', 'fw', 'init', 'restart', 'experiment', 'migrate', 'indexfolder', 'indexfolders', 'help', 'version']);
|
|
22
|
+
const COMMANDS = new Set(['start', 'firewall', 'fw', 'extension', 'ext', 'init', 'restart', 'experiment', 'migrate', 'indexfolder', 'indexfolders', 'help', 'version']);
|
|
22
23
|
function parseArgs(argv) {
|
|
23
24
|
const positional = [];
|
|
24
25
|
const flags = {};
|
|
@@ -142,6 +143,12 @@ Usage:
|
|
|
142
143
|
huddle firewall folder set <path> Set the team-managed rules folder
|
|
143
144
|
huddle firewall folder reload Re-read the team-managed rules folder
|
|
144
145
|
huddle firewall folder sync Write the portal's groups back to the folder
|
|
146
|
+
huddle extension list List installed gateway extensions
|
|
147
|
+
huddle ext list Alias for extension list
|
|
148
|
+
huddle extension install <dir> Install or update the extension in a folder
|
|
149
|
+
(--force replaces another extension with the
|
|
150
|
+
same id, --restart reloads the gateway process)
|
|
151
|
+
huddle extension remove <id> Remove an installed extension
|
|
145
152
|
huddle experiment use <nr> Activate the experimental build of issue/PR <nr>
|
|
146
153
|
and run init
|
|
147
154
|
huddle experiment reset Back to the stable release
|
|
@@ -352,6 +359,34 @@ async function main() {
|
|
|
352
359
|
}
|
|
353
360
|
return;
|
|
354
361
|
}
|
|
362
|
+
if (cmd === 'extension' || cmd === 'ext') {
|
|
363
|
+
const subCmd = sub ?? 'list';
|
|
364
|
+
if (subCmd === 'list') {
|
|
365
|
+
await (0, extension_1.runExtensionList)();
|
|
366
|
+
}
|
|
367
|
+
else if (subCmd === 'install') {
|
|
368
|
+
const dir = positional[2];
|
|
369
|
+
if (!dir) {
|
|
370
|
+
console.error('Usage: huddle extension install <dir> [--force] [--restart]');
|
|
371
|
+
process.exit(1);
|
|
372
|
+
}
|
|
373
|
+
await (0, extension_1.runExtensionInstall)(dir, { force: flagBool(flags, 'force'), restart: flagBool(flags, 'restart') });
|
|
374
|
+
}
|
|
375
|
+
else if (subCmd === 'remove' || subCmd === 'rm') {
|
|
376
|
+
const id = positional[2];
|
|
377
|
+
if (!id) {
|
|
378
|
+
console.error('Usage: huddle extension remove <id>');
|
|
379
|
+
process.exit(1);
|
|
380
|
+
}
|
|
381
|
+
await (0, extension_1.runExtensionRemove)(id);
|
|
382
|
+
}
|
|
383
|
+
else {
|
|
384
|
+
console.error(`Unknown extension subcommand: ${subCmd}`);
|
|
385
|
+
console.error('Usage: huddle extension <list|install <dir>|remove <id>>');
|
|
386
|
+
process.exit(1);
|
|
387
|
+
}
|
|
388
|
+
return;
|
|
389
|
+
}
|
|
355
390
|
if (cmd === 'indexfolder' || cmd === 'indexfolders') {
|
|
356
391
|
await (0, indexfolder_1.runIndexFolder)({
|
|
357
392
|
path: positional[1],
|
package/dist/init.js
CHANGED
|
@@ -3,7 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.HOST_SOCKET_DIR = exports.INTERNAL_NET = void 0;
|
|
6
|
+
exports.HOST_SOCKET_DIR = exports.INTERNAL_NET = exports.CONTAINER = void 0;
|
|
7
7
|
exports.runInit = runInit;
|
|
8
8
|
const child_process_1 = require("child_process");
|
|
9
9
|
const crypto_1 = __importDefault(require("crypto"));
|
|
@@ -11,8 +11,10 @@ const utils_1 = require("./utils");
|
|
|
11
11
|
const runtime_1 = require("./runtime");
|
|
12
12
|
const images_1 = require("./images");
|
|
13
13
|
const config_1 = require("./config");
|
|
14
|
+
const os_1 = __importDefault(require("os"));
|
|
15
|
+
const host_logs_1 = require("./host-logs");
|
|
14
16
|
const fs_1 = __importDefault(require("fs"));
|
|
15
|
-
|
|
17
|
+
exports.CONTAINER = 'huddle';
|
|
16
18
|
const VOLUME = 'huddle-data';
|
|
17
19
|
/**
|
|
18
20
|
* The shared, internal network that `huddle init` creates (`--internal`, so it
|
|
@@ -94,7 +96,7 @@ async function runInit(opts, images) {
|
|
|
94
96
|
console.log((0, utils_1.dim)(`Network: ${exports.INTERNAL_NET}`));
|
|
95
97
|
runArgsSilent(rt, ['network', 'inspect', exports.INTERNAL_NET]) || runArgs(rt, ['network', 'create', '--internal', exports.INTERNAL_NET]);
|
|
96
98
|
console.log((0, utils_1.dim)(`Removing old container if it exists`));
|
|
97
|
-
runArgsSilent(rt, ['rm', '-f', CONTAINER]);
|
|
99
|
+
runArgsSilent(rt, ['rm', '-f', exports.CONTAINER]);
|
|
98
100
|
console.log((0, utils_1.dim)(`Socket directory: /tmp/dc-sockets`));
|
|
99
101
|
// The mount SOURCE must be the path on the Docker ENGINE host (on Windows:
|
|
100
102
|
// the WSL2/Linux VM), even when the CLI itself runs on Windows. The gateway
|
|
@@ -163,7 +165,7 @@ async function runInit(opts, images) {
|
|
|
163
165
|
// Build the container command as an argv array (runArgs → execFileSync, no
|
|
164
166
|
// shell). The folder paths below come from config and are operator-writable via
|
|
165
167
|
// the settings API, so they must never reach a shell as a string.
|
|
166
|
-
const dockerArgs = ['run', '-d', '--name', CONTAINER, '--network', runtime.defaultNetwork];
|
|
168
|
+
const dockerArgs = ['run', '-d', '--name', exports.CONTAINER, '--network', runtime.defaultNetwork];
|
|
167
169
|
for (const opt of runtime.securityOpts)
|
|
168
170
|
dockerArgs.push('--security-opt', opt);
|
|
169
171
|
dockerArgs.push('-e', `HUDDLE_RUNTIME=${runtime.name}`);
|
|
@@ -177,6 +179,15 @@ async function runInit(opts, images) {
|
|
|
177
179
|
dockerArgs.push('-v', `${fwFolder}:/firewall-rules:rw`);
|
|
178
180
|
if (extFolder)
|
|
179
181
|
dockerArgs.push('-v', `${extFolder}:/extensions:ro`);
|
|
182
|
+
const hostLogs = (0, host_logs_1.hostAgentLogsMountArgs)(cfg, os_1.default.homedir());
|
|
183
|
+
if (hostLogs.length)
|
|
184
|
+
console.log((0, utils_1.dim)(' Mounting host Claude logs (read-only) for extensions'));
|
|
185
|
+
dockerArgs.push(...hostLogs);
|
|
186
|
+
const hostCodexLogs = (0, host_logs_1.hostCodexLogsMountArgs)(cfg, os_1.default.homedir());
|
|
187
|
+
if (hostCodexLogs.length)
|
|
188
|
+
console.log((0, utils_1.dim)(' Mounting host Codex logs (read-only) for extensions'));
|
|
189
|
+
dockerArgs.push(...hostCodexLogs);
|
|
190
|
+
dockerArgs.push(...(0, host_logs_1.hostCodexIndexMountArgs)(cfg, os_1.default.homedir()));
|
|
180
191
|
dockerArgs.push(...(0, images_1.gatewayEnvArgs)(images));
|
|
181
192
|
dockerArgs.push(IMAGE);
|
|
182
193
|
runArgs(rt, dockerArgs);
|
|
@@ -184,7 +195,7 @@ async function runInit(opts, images) {
|
|
|
184
195
|
// resolv.conf on Podman with that network's internal aardvark-DNS; the
|
|
185
196
|
// gateway cleans that up itself (see dns-egress.ts / the startup sanitize in
|
|
186
197
|
// index.ts).
|
|
187
|
-
runArgsSilent(rt, ['network', 'connect', exports.INTERNAL_NET, CONTAINER]);
|
|
198
|
+
runArgsSilent(rt, ['network', 'connect', exports.INTERNAL_NET, exports.CONTAINER]);
|
|
188
199
|
console.log();
|
|
189
200
|
console.log((0, utils_1.green)(`[OK] Huddle is running at http://localhost:${HOST_PORT}`));
|
|
190
201
|
console.log();
|
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
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@infosupport/huddle-cli",
|
|
3
|
-
"version": "1.2.
|
|
3
|
+
"version": "1.2.36",
|
|
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.",
|
|
@@ -20,11 +20,15 @@
|
|
|
20
20
|
"build": "tsc",
|
|
21
21
|
"dev": "tsc --watch",
|
|
22
22
|
"install-global": "npm run build && npm install -g .",
|
|
23
|
-
"typecheck": "tsc --noEmit"
|
|
23
|
+
"typecheck": "tsc --noEmit",
|
|
24
|
+
"test": "vitest run"
|
|
24
25
|
},
|
|
25
26
|
"devDependencies": {
|
|
27
|
+
"@types/adm-zip": "^0.5.8",
|
|
26
28
|
"@types/node": "^22.0.0",
|
|
27
|
-
"
|
|
29
|
+
"adm-zip": "^0.5.18",
|
|
30
|
+
"typescript": "^5.0.0",
|
|
31
|
+
"vitest": "^4.1.11"
|
|
28
32
|
},
|
|
29
33
|
"engines": {
|
|
30
34
|
"node": ">=18"
|