@infosupport/huddle-cli 0.0.0-experiment-160.132.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/README.md
CHANGED
|
@@ -44,25 +44,43 @@ huddle --ide vscode \
|
|
|
44
44
|
|
|
45
45
|
Default API URL: `http://localhost:3000`. Override it with `--url` or `HUDDLE_URL`.
|
|
46
46
|
|
|
47
|
-
##
|
|
47
|
+
## Making host folders selectable in the portal
|
|
48
48
|
|
|
49
|
-
Huddle's portal runs inside a container, so it cannot
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
49
|
+
Huddle's portal runs inside a container, so it cannot open a folder dialog on your
|
|
50
|
+
host: every host path had to be typed from memory. `huddle indexfolder` scans your
|
|
51
|
+
host once and stores what it finds, and every host-path field in the portal grows a
|
|
52
|
+
**Browse** button that opens those folders as a tree — starting a devcontainer, the
|
|
53
|
+
folder mappings, and the team-managed folders. Starting a devcontainer, Ctrl-click picks
|
|
54
|
+
several folders at once and each becomes its own worktree. Typing a path by hand keeps working:
|
|
55
|
+
the index is a snapshot, so a folder created after the last scan must not be
|
|
56
|
+
unreachable.
|
|
56
57
|
|
|
57
58
|
```bash
|
|
58
|
-
|
|
59
|
-
huddle
|
|
60
|
-
huddle
|
|
61
|
-
huddle
|
|
59
|
+
cd T:/projects
|
|
60
|
+
huddle indexfolder # this folder + 2 levels below it
|
|
61
|
+
huddle indexfolder T:/projects --depth 3
|
|
62
|
+
huddle indexfolder --all # also index node_modules, dist, target, ...
|
|
63
|
+
huddle indexfolder --replace # re-scan: drop the earlier entries under this folder first
|
|
64
|
+
huddle indexfolder --list # show what is indexed
|
|
65
|
+
huddle indexfolder --clear # empty the index (with a folder: only that subtree)
|
|
62
66
|
```
|
|
63
67
|
|
|
64
|
-
|
|
65
|
-
|
|
68
|
+
Hidden (dot) folders and the usual build folders (`node_modules`, `dist`, `target`,
|
|
69
|
+
`obj`, …) are skipped, which is what keeps a scan of a projects folder in the
|
|
70
|
+
hundreds instead of the tens of thousands; `--all` turns that off. The scan stops
|
|
71
|
+
at 1500 folders and the index holds at most 2000 — index a more specific folder if
|
|
72
|
+
you hit that.
|
|
73
|
+
|
|
74
|
+
The index is a **snapshot**, not a live view: the gateway cannot read your host, so
|
|
75
|
+
re-run the command after adding projects. Every input keeps accepting a typed path,
|
|
76
|
+
so a folder you created a minute ago works without re-indexing first. Windows paths
|
|
77
|
+
may be typed either way (`T:\projects\app` or `T:/projects/app`) — they are stored
|
|
78
|
+
in one canonical form, and the two spellings are the same entry.
|
|
79
|
+
|
|
80
|
+
Individual folders can also be added or removed under **Settings > Indexed
|
|
81
|
+
folders** in the portal. The index lives in Huddle's database, not in
|
|
82
|
+
`~/.huddle/config.json`: it describes this machine, so unlike the team-managed
|
|
83
|
+
settings it is not something to share in version control.
|
|
66
84
|
|
|
67
85
|
## Experiments
|
|
68
86
|
|
package/dist/api.js
CHANGED
|
@@ -3,7 +3,6 @@ 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;
|
|
7
6
|
const config_1 = require("./config");
|
|
8
7
|
let baseUrl = normalizeBaseUrl(process.env.HUDDLE_URL ?? 'http://localhost:3000');
|
|
9
8
|
class ApiError extends Error {
|
|
@@ -22,15 +21,6 @@ async function apiCall(method, path, body) {
|
|
|
22
21
|
const headers = {};
|
|
23
22
|
if (body !== undefined)
|
|
24
23
|
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) {
|
|
34
24
|
// Operator-auth: stuur het token als Bearer mee zodat de CLI de control-plane
|
|
35
25
|
// -auth passeert. Zonder token krijgen we een 401 met een duidelijke hint.
|
|
36
26
|
const token = (0, config_1.operatorToken)();
|
|
@@ -38,7 +28,11 @@ async function send(method, path, body, headers) {
|
|
|
38
28
|
headers['authorization'] = `Bearer ${token}`;
|
|
39
29
|
let res;
|
|
40
30
|
try {
|
|
41
|
-
res = await fetch(`${baseUrl}${path}`, {
|
|
31
|
+
res = await fetch(`${baseUrl}${path}`, {
|
|
32
|
+
method,
|
|
33
|
+
headers,
|
|
34
|
+
body: body !== undefined ? JSON.stringify(body) : undefined,
|
|
35
|
+
});
|
|
42
36
|
}
|
|
43
37
|
catch (err) {
|
|
44
38
|
const detail = err instanceof Error ? err.message : String(err);
|
package/dist/config.js
CHANGED
|
@@ -139,10 +139,7 @@ let tmpSeq = 0;
|
|
|
139
139
|
* config.
|
|
140
140
|
*/
|
|
141
141
|
function updateConfig(patch) {
|
|
142
|
-
|
|
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);
|
|
142
|
+
fs_1.default.mkdirSync(exports.CONFIG_DIR, { recursive: true });
|
|
146
143
|
const token = acquireLock();
|
|
147
144
|
if (token === null) {
|
|
148
145
|
throw new Error(`Could not lock ${CONFIG_PATH} within ${LOCK_WAIT_MS}ms — another Huddle process ` +
|
|
@@ -156,7 +153,7 @@ function updateConfig(patch) {
|
|
|
156
153
|
if (v === undefined)
|
|
157
154
|
delete next[k];
|
|
158
155
|
}
|
|
159
|
-
fs_1.default.writeFileSync(tmp, `${JSON.stringify(next, null, 2)}\n
|
|
156
|
+
fs_1.default.writeFileSync(tmp, `${JSON.stringify(next, null, 2)}\n`);
|
|
160
157
|
fs_1.default.renameSync(tmp, CONFIG_PATH);
|
|
161
158
|
return next;
|
|
162
159
|
}
|
package/dist/index.js
CHANGED
|
@@ -8,18 +8,17 @@ 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");
|
|
12
11
|
const firewall_1 = require("./firewall");
|
|
13
12
|
const init_1 = require("./init");
|
|
14
13
|
const migrate_1 = require("./migrate");
|
|
15
|
-
const
|
|
14
|
+
const indexfolder_1 = require("./indexfolder");
|
|
16
15
|
const images_1 = require("./images");
|
|
17
16
|
const self_update_1 = require("./self-update");
|
|
18
17
|
const utils_1 = require("./utils");
|
|
19
18
|
const experiment_1 = require("./experiment");
|
|
20
|
-
const VALUE_FLAGS = new Set(['url', 'ide', 'name', 'image', 'workspace', 'container', 'status', 'runtime', 'experiment', 'path', 'ca-path', 'output', 'out', 'workspace-root']);
|
|
21
|
-
const BOOLEAN_FLAGS = new Set(['help', 'h', 'empty', 'i', 'interactive', 'version', 'v', 'deny', 'docker-socket', 'force', 'replace']);
|
|
22
|
-
const COMMANDS = new Set(['start', 'firewall', 'fw', '
|
|
19
|
+
const VALUE_FLAGS = new Set(['url', 'ide', 'name', 'image', 'workspace', 'container', 'status', 'runtime', 'experiment', 'path', 'ca-path', 'output', 'out', 'workspace-root', 'depth']);
|
|
20
|
+
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']);
|
|
23
22
|
function parseArgs(argv) {
|
|
24
23
|
const positional = [];
|
|
25
24
|
const flags = {};
|
|
@@ -124,11 +123,10 @@ Usage:
|
|
|
124
123
|
team firewall-rules folder)
|
|
125
124
|
huddle migrate [folder] Wire an existing docker-compose devcontainer
|
|
126
125
|
behind Huddle by generating an override file
|
|
127
|
-
huddle
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
huddle pipe serve Run the host pipe in the foreground (debugging)
|
|
126
|
+
huddle indexfolder [folder] Index the folders under this one so the portal
|
|
127
|
+
can offer them where a host path is needed
|
|
128
|
+
(the portal runs in a container and cannot
|
|
129
|
+
browse your host)
|
|
132
130
|
huddle firewall list [options] Show firewall requests
|
|
133
131
|
huddle fw list [options] Alias for firewall list
|
|
134
132
|
huddle firewall add <domain> Add a custom firewall rule (wildcards
|
|
@@ -144,13 +142,6 @@ Usage:
|
|
|
144
142
|
huddle firewall folder set <path> Set the team-managed rules folder
|
|
145
143
|
huddle firewall folder reload Re-read the team-managed rules folder
|
|
146
144
|
huddle firewall folder sync Write the portal's groups back to the folder
|
|
147
|
-
huddle extension list List installed gateway extensions
|
|
148
|
-
huddle ext list Alias for extension list
|
|
149
|
-
huddle extension install <dir> Install or update the extension in a folder
|
|
150
|
-
(--force replaces another extension with the
|
|
151
|
-
same id, --restart reloads the gateway process
|
|
152
|
-
on the engine that runs Huddle, or --runtime)
|
|
153
|
-
huddle extension remove <id> Remove an installed extension
|
|
154
145
|
huddle experiment use <nr> Activate the experimental build of issue/PR <nr>
|
|
155
146
|
and run init
|
|
156
147
|
huddle experiment reset Back to the stable release
|
|
@@ -171,8 +162,7 @@ Start options:
|
|
|
171
162
|
--workspace-root <path> Container path the IDE opens as project root when using
|
|
172
163
|
--mount (default: common parent of the mount targets)
|
|
173
164
|
--name <name> Container name (default: devcontainer-<foldername>)
|
|
174
|
-
--image <image> Use a specific image
|
|
175
|
-
Huddle builds it once with its own layer on top
|
|
165
|
+
--image <image> Use a specific image
|
|
176
166
|
--empty Empty container without a workspace
|
|
177
167
|
|
|
178
168
|
Migrate options:
|
|
@@ -184,6 +174,16 @@ Migrate options:
|
|
|
184
174
|
(default: docker-compose.huddle.yml next to the source)
|
|
185
175
|
--force Overwrite an existing override file
|
|
186
176
|
|
|
177
|
+
Indexfolder options:
|
|
178
|
+
--depth <n> How deep to walk (default: 2, max 8)
|
|
179
|
+
--all Also index build folders (node_modules, dist,
|
|
180
|
+
target, ...); hidden folders stay skipped
|
|
181
|
+
--replace Drop the earlier entries under this folder
|
|
182
|
+
first, instead of merging
|
|
183
|
+
--list Show the current index and exit
|
|
184
|
+
--clear Empty the index (or, with a folder, only the
|
|
185
|
+
entries under it)
|
|
186
|
+
|
|
187
187
|
Firewall options:
|
|
188
188
|
-i, --interactive Interactively approve/deny (list)
|
|
189
189
|
--container <name> Filter by (list) / scope to (add) a container
|
|
@@ -352,40 +352,15 @@ async function main() {
|
|
|
352
352
|
}
|
|
353
353
|
return;
|
|
354
354
|
}
|
|
355
|
-
if (cmd === '
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
process.exit(1);
|
|
365
|
-
}
|
|
366
|
-
await (0, extension_1.runExtensionInstall)(dir, {
|
|
367
|
-
force: flagBool(flags, 'force'),
|
|
368
|
-
restart: flagBool(flags, 'restart'),
|
|
369
|
-
runtime: flagString(flags, 'runtime'),
|
|
370
|
-
});
|
|
371
|
-
}
|
|
372
|
-
else if (subCmd === 'remove' || subCmd === 'rm') {
|
|
373
|
-
const id = positional[2];
|
|
374
|
-
if (!id) {
|
|
375
|
-
console.error('Usage: huddle extension remove <id>');
|
|
376
|
-
process.exit(1);
|
|
377
|
-
}
|
|
378
|
-
await (0, extension_1.runExtensionRemove)(id);
|
|
379
|
-
}
|
|
380
|
-
else {
|
|
381
|
-
console.error(`Unknown extension subcommand: ${subCmd}`);
|
|
382
|
-
console.error('Usage: huddle extension <list|install <dir>|remove <id>>');
|
|
383
|
-
process.exit(1);
|
|
384
|
-
}
|
|
385
|
-
return;
|
|
386
|
-
}
|
|
387
|
-
if (cmd === 'pipe') {
|
|
388
|
-
await (0, command_1.runPipe)({ action: sub });
|
|
355
|
+
if (cmd === 'indexfolder' || cmd === 'indexfolders') {
|
|
356
|
+
await (0, indexfolder_1.runIndexFolder)({
|
|
357
|
+
path: positional[1],
|
|
358
|
+
depth: flagString(flags, 'depth'),
|
|
359
|
+
all: flagBool(flags, 'all'),
|
|
360
|
+
replace: flagBool(flags, 'replace'),
|
|
361
|
+
clear: flagBool(flags, 'clear'),
|
|
362
|
+
list: flagBool(flags, 'list'),
|
|
363
|
+
});
|
|
389
364
|
return;
|
|
390
365
|
}
|
|
391
366
|
if (cmd === 'migrate') {
|
|
@@ -0,0 +1,167 @@
|
|
|
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.runIndexFolder = runIndexFolder;
|
|
7
|
+
const fs_1 = __importDefault(require("fs"));
|
|
8
|
+
const path_1 = __importDefault(require("path"));
|
|
9
|
+
const api_1 = require("./api");
|
|
10
|
+
const utils_1 = require("./utils");
|
|
11
|
+
// `huddle indexfolder` — make host folders selectable in the portal.
|
|
12
|
+
//
|
|
13
|
+
// The portal runs inside a container: it cannot open a file dialog on the host,
|
|
14
|
+
// so every host path had to be typed from memory. This command walks the host
|
|
15
|
+
// filesystem where the operator already is (their projects folder) and posts the
|
|
16
|
+
// folders it finds to the gateway, which stores them as an index. The portal then
|
|
17
|
+
// offers that index wherever a host path is needed.
|
|
18
|
+
//
|
|
19
|
+
// Deliberately a snapshot, not a live view: the gateway has no way to read the
|
|
20
|
+
// host filesystem, and re-running the command is cheap.
|
|
21
|
+
// Folders that are never a workspace choice but do contain thousands of
|
|
22
|
+
// subfolders. Skipping them is what keeps a scan of a projects folder in the
|
|
23
|
+
// hundreds rather than the tens of thousands. `--all` turns this off; hidden
|
|
24
|
+
// (dot) folders stay skipped either way.
|
|
25
|
+
const NOISE = new Set([
|
|
26
|
+
'node_modules', 'dist', 'build', 'out', 'bin', 'obj', 'target', 'vendor',
|
|
27
|
+
'venv', '__pycache__', 'coverage', 'packages', 'AppData', 'Library',
|
|
28
|
+
'$RECYCLE.BIN', 'System Volume Information', 'Windows', 'Program Files',
|
|
29
|
+
'Program Files (x86)', 'ProgramData',
|
|
30
|
+
]);
|
|
31
|
+
// Hard stop on discovery, well under the gateway's own cap. Pointing the command
|
|
32
|
+
// at a drive root should end in a clear warning, not a ten-minute walk.
|
|
33
|
+
const MAX_FOLDERS = 1500;
|
|
34
|
+
// Host paths travel to the gateway with forward slashes: `path.resolve` hands
|
|
35
|
+
// back `T:\projects\app` on Windows, and the whole stack (the portal, the index,
|
|
36
|
+
// the Docker mount translation) speaks the forward-slash form. The gateway
|
|
37
|
+
// normalizes again on ingest — this is only so what we PRINT matches what gets
|
|
38
|
+
// stored.
|
|
39
|
+
function toPosix(p) {
|
|
40
|
+
return p.replace(/\\/g, '/').replace(/^([a-z]):/, (_m, d) => `${d.toUpperCase()}:`);
|
|
41
|
+
}
|
|
42
|
+
function parseDepth(raw) {
|
|
43
|
+
if (raw === undefined)
|
|
44
|
+
return 2;
|
|
45
|
+
const n = Number(raw);
|
|
46
|
+
if (!Number.isInteger(n) || n < 0 || n > 8) {
|
|
47
|
+
throw new Error(`Invalid --depth "${raw}": use a whole number between 0 and 8.`);
|
|
48
|
+
}
|
|
49
|
+
return n;
|
|
50
|
+
}
|
|
51
|
+
// The folder to walk comes from argv, or from wherever the operator's shell is.
|
|
52
|
+
// Resolving it here — once, before anything touches the filesystem — is what lets
|
|
53
|
+
// the rest of the command treat "the root" as one absolute, `..`-free path: the
|
|
54
|
+
// walk below, the containment check, and the paths posted to the gateway all
|
|
55
|
+
// derive from this value.
|
|
56
|
+
function resolveScanRoot(raw) {
|
|
57
|
+
const input = raw ?? process.cwd();
|
|
58
|
+
// A null byte makes every fs call throw ERR_INVALID_ARG_VALUE with a stack
|
|
59
|
+
// trace; say what is wrong instead.
|
|
60
|
+
if (input.includes('\0'))
|
|
61
|
+
throw new Error('Invalid folder: the path contains a null byte.');
|
|
62
|
+
return path_1.default.resolve(input);
|
|
63
|
+
}
|
|
64
|
+
// Whether `candidate` is the root or sits underneath it.
|
|
65
|
+
function contains(root, candidate) {
|
|
66
|
+
const rel = path_1.default.relative(root, candidate);
|
|
67
|
+
return rel === '' || (!rel.startsWith('..') && !path_1.default.isAbsolute(rel));
|
|
68
|
+
}
|
|
69
|
+
// Breadth-first so a depth cut-off keeps the folders nearest the root — those are
|
|
70
|
+
// the ones an operator actually mounts. Symlinks are not followed: `isDirectory()`
|
|
71
|
+
// is false for a symlink entry, which also rules out a link loop.
|
|
72
|
+
function scan(root, depth, all) {
|
|
73
|
+
const folders = [root];
|
|
74
|
+
let level = [root];
|
|
75
|
+
for (let d = 0; d < depth; d++) {
|
|
76
|
+
const next = [];
|
|
77
|
+
for (const dir of level) {
|
|
78
|
+
let entries;
|
|
79
|
+
try {
|
|
80
|
+
entries = fs_1.default.readdirSync(dir, { withFileTypes: true });
|
|
81
|
+
}
|
|
82
|
+
catch {
|
|
83
|
+
continue; // unreadable folder (permissions, a vanished dir) — skip it
|
|
84
|
+
}
|
|
85
|
+
for (const e of entries) {
|
|
86
|
+
if (!e.isDirectory())
|
|
87
|
+
continue;
|
|
88
|
+
if (e.name.startsWith('.'))
|
|
89
|
+
continue;
|
|
90
|
+
if (!all && NOISE.has(e.name))
|
|
91
|
+
continue;
|
|
92
|
+
const full = path_1.default.join(dir, e.name);
|
|
93
|
+
// Nothing outside the folder the operator named ever enters the index or
|
|
94
|
+
// gets opened by the next round of readdirSync. Entries come from
|
|
95
|
+
// readdirSync and symlinks are already skipped, so this should never
|
|
96
|
+
// fire — it is here so a scan can never walk out of its root by accident.
|
|
97
|
+
if (!contains(root, full))
|
|
98
|
+
continue;
|
|
99
|
+
folders.push(full);
|
|
100
|
+
next.push(full);
|
|
101
|
+
if (folders.length >= MAX_FOLDERS)
|
|
102
|
+
return { folders, truncated: true };
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
level = next;
|
|
106
|
+
if (level.length === 0)
|
|
107
|
+
break;
|
|
108
|
+
}
|
|
109
|
+
return { folders, truncated: false };
|
|
110
|
+
}
|
|
111
|
+
async function runIndexFolder(opts) {
|
|
112
|
+
if (opts.list) {
|
|
113
|
+
const res = await (0, api_1.get)('/api/indexed-folders');
|
|
114
|
+
if (res.folders.length === 0) {
|
|
115
|
+
console.log((0, utils_1.dim)('No folders indexed yet. Run `huddle indexfolder` in your projects folder.'));
|
|
116
|
+
return;
|
|
117
|
+
}
|
|
118
|
+
(0, utils_1.printTable)(['ID', 'PATH', 'SOURCE'], res.folders.map((f) => [String(f.id), f.path, f.source]));
|
|
119
|
+
console.log((0, utils_1.dim)(`\n${res.folders.length} folder(s) indexed (max ${res.max}).`));
|
|
120
|
+
return;
|
|
121
|
+
}
|
|
122
|
+
if (opts.clear) {
|
|
123
|
+
// Scoped when a folder is given, so clearing one project's entries does not
|
|
124
|
+
// throw away everything else that was indexed.
|
|
125
|
+
const root = opts.path ? toPosix(resolveScanRoot(opts.path)) : undefined;
|
|
126
|
+
const query = root ? `?root=${encodeURIComponent(root)}` : '';
|
|
127
|
+
const res = await (0, api_1.del)(`/api/indexed-folders${query}`);
|
|
128
|
+
console.log((0, utils_1.green)(`[OK] Removed ${res.removed} folder(s) from the index${root ? ` under ${(0, utils_1.cyan)(root)}` : ''}.`));
|
|
129
|
+
return;
|
|
130
|
+
}
|
|
131
|
+
const depth = parseDepth(opts.depth);
|
|
132
|
+
const root = resolveScanRoot(opts.path);
|
|
133
|
+
let stat;
|
|
134
|
+
try {
|
|
135
|
+
stat = fs_1.default.statSync(root);
|
|
136
|
+
}
|
|
137
|
+
catch {
|
|
138
|
+
throw new Error(`Folder does not exist: ${root}`);
|
|
139
|
+
}
|
|
140
|
+
if (!stat.isDirectory())
|
|
141
|
+
throw new Error(`Not a folder: ${root}`);
|
|
142
|
+
const posixRoot = toPosix(root);
|
|
143
|
+
console.log(`Indexing ${(0, utils_1.bold)(posixRoot)} ${(0, utils_1.dim)(`(depth ${depth}${opts.all ? ', including build folders' : ''})`)}`);
|
|
144
|
+
const { folders, truncated } = scan(root, depth, opts.all === true);
|
|
145
|
+
if (truncated) {
|
|
146
|
+
console.log((0, utils_1.yellow)(`[!] Stopped at ${MAX_FOLDERS} folders. Index a more specific folder, or lower --depth.`));
|
|
147
|
+
}
|
|
148
|
+
const res = await (0, api_1.post)('/api/indexed-folders', {
|
|
149
|
+
paths: folders.map(toPosix),
|
|
150
|
+
root: posixRoot,
|
|
151
|
+
replace: opts.replace === true,
|
|
152
|
+
});
|
|
153
|
+
if (res.removed)
|
|
154
|
+
console.log((0, utils_1.dim)(` Replaced: removed ${res.removed} earlier entr(y|ies) under this folder.`));
|
|
155
|
+
console.log((0, utils_1.green)(`[OK] ${res.added} added, ${res.updated} already known — ${res.total} folder(s) in the index.`));
|
|
156
|
+
if (res.skipped) {
|
|
157
|
+
console.log((0, utils_1.yellow)(`[!] ${res.skipped} folder(s) skipped (index limit ${res.max} reached, or a duplicate spelling).`));
|
|
158
|
+
}
|
|
159
|
+
for (const bad of res.invalid.slice(0, 5)) {
|
|
160
|
+
console.log((0, utils_1.yellow)(`[!] Refused ${bad.path}: ${bad.error}`));
|
|
161
|
+
}
|
|
162
|
+
if (res.invalid.length > 5)
|
|
163
|
+
console.log((0, utils_1.yellow)(`[!] ...and ${res.invalid.length - 5} more refused.`));
|
|
164
|
+
console.log();
|
|
165
|
+
console.log('Pick these folders in the portal when starting a devcontainer,');
|
|
166
|
+
console.log(`or manage the index under ${(0, utils_1.cyan)('Settings > Indexed folders')}.`);
|
|
167
|
+
}
|
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.
|
|
6
|
+
exports.HOST_SOCKET_DIR = exports.INTERNAL_NET = 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,12 +11,8 @@ 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");
|
|
16
|
-
const protocol_1 = require("./pipe/protocol");
|
|
17
|
-
const command_1 = require("./pipe/command");
|
|
18
14
|
const fs_1 = __importDefault(require("fs"));
|
|
19
|
-
|
|
15
|
+
const CONTAINER = 'huddle';
|
|
20
16
|
const VOLUME = 'huddle-data';
|
|
21
17
|
/**
|
|
22
18
|
* The shared, internal network that `huddle init` creates (`--internal`, so it
|
|
@@ -33,15 +29,6 @@ exports.INTERNAL_NET = 'devcontainer-net';
|
|
|
33
29
|
*/
|
|
34
30
|
exports.HOST_SOCKET_DIR = '/tmp/dc-sockets';
|
|
35
31
|
const HOST_PORT = process.env.HUDDLE_PORT ?? '3000';
|
|
36
|
-
/**
|
|
37
|
-
* Ports of the per-devcontainer SSH relays (JetBrains Gateway over SSH), bound to
|
|
38
|
-
* the host's loopback only. Kept in sync with SSH_RELAY_PORT_MIN/MAX in
|
|
39
|
-
* gateway/src/ssh-access.ts.
|
|
40
|
-
*/
|
|
41
|
-
exports.SSH_RELAY_PORTS = '2200-2219';
|
|
42
|
-
// Host port of the gateway's sbx egress proxy (docs/host-pipe.md). Published on
|
|
43
|
-
// loopback only: the sbx daemon runs on this machine, nothing else needs it.
|
|
44
|
-
const SBX_PROXY_HOST_PORT = process.env.HUDDLE_SBX_PROXY_PORT ?? '32768';
|
|
45
32
|
// Run a binary with an argv array — NO shell. Values that originate from config
|
|
46
33
|
// (team-folder paths, which are writable via `huddle firewall folder set` and the
|
|
47
34
|
// authenticated settings API) must never be interpolated into a shell string, or
|
|
@@ -107,7 +94,7 @@ async function runInit(opts, images) {
|
|
|
107
94
|
console.log((0, utils_1.dim)(`Network: ${exports.INTERNAL_NET}`));
|
|
108
95
|
runArgsSilent(rt, ['network', 'inspect', exports.INTERNAL_NET]) || runArgs(rt, ['network', 'create', '--internal', exports.INTERNAL_NET]);
|
|
109
96
|
console.log((0, utils_1.dim)(`Removing old container if it exists`));
|
|
110
|
-
runArgsSilent(rt, ['rm', '-f',
|
|
97
|
+
runArgsSilent(rt, ['rm', '-f', CONTAINER]);
|
|
111
98
|
console.log((0, utils_1.dim)(`Socket directory: /tmp/dc-sockets`));
|
|
112
99
|
// The mount SOURCE must be the path on the Docker ENGINE host (on Windows:
|
|
113
100
|
// the WSL2/Linux VM), even when the CLI itself runs on Windows. The gateway
|
|
@@ -173,45 +160,23 @@ async function runInit(opts, images) {
|
|
|
173
160
|
console.log((0, utils_1.dim)(` Mounting firewall-rules folder: ${fwFolder} -> /firewall-rules`));
|
|
174
161
|
if (extFolder)
|
|
175
162
|
console.log((0, utils_1.dim)(` Mounting extensions folder: ${extFolder} -> /extensions`));
|
|
176
|
-
// The host pipe lives inside the ~/.huddle mount; create it now so the
|
|
177
|
-
// gateway sees the folder from its first start, before the agent runs.
|
|
178
|
-
try {
|
|
179
|
-
(0, protocol_1.ensurePrivateDir)(protocol_1.PIPE_DIR);
|
|
180
|
-
}
|
|
181
|
-
catch (err) {
|
|
182
|
-
console.log((0, utils_1.yellow)(` Host pipe folder not usable: ${err instanceof Error ? err.message : err}`));
|
|
183
|
-
}
|
|
184
163
|
// Build the container command as an argv array (runArgs → execFileSync, no
|
|
185
164
|
// shell). The folder paths below come from config and are operator-writable via
|
|
186
165
|
// the settings API, so they must never reach a shell as a string.
|
|
187
|
-
const dockerArgs = ['run', '-d', '--name',
|
|
166
|
+
const dockerArgs = ['run', '-d', '--name', CONTAINER, '--network', runtime.defaultNetwork];
|
|
188
167
|
for (const opt of runtime.securityOpts)
|
|
189
168
|
dockerArgs.push('--security-opt', opt);
|
|
190
169
|
dockerArgs.push('-e', `HUDDLE_RUNTIME=${runtime.name}`);
|
|
191
170
|
dockerArgs.push('-e', `HUDDLE_OPERATOR_TOKEN=${operatorToken}`);
|
|
192
171
|
dockerArgs.push('-p', `${HOST_PORT}:3000`);
|
|
193
|
-
dockerArgs.push('-p', `127.0.0.1:${exports.SSH_RELAY_PORTS}:${exports.SSH_RELAY_PORTS}`);
|
|
194
|
-
dockerArgs.push('-p', `127.0.0.1:${SBX_PROXY_HOST_PORT}:3128`, '-e', `HUDDLE_SBX_PROXY_HOST_PORT=${SBX_PROXY_HOST_PORT}`);
|
|
195
172
|
dockerArgs.push('-v', `${VOLUME}:/data`);
|
|
196
173
|
dockerArgs.push('-v', `${runtime.socketPath}:/var/run/docker.sock`);
|
|
197
174
|
dockerArgs.push('-v', `${hostTmpSockets}:/tmp/dc-sockets`);
|
|
198
175
|
dockerArgs.push('-v', `${config_1.CONFIG_DIR}:/huddle-home:rw`, '-e', 'HUDDLE_HOME_DIR=/huddle-home');
|
|
199
|
-
// Its host path, so the gateway can refuse mounts that would expose it (the
|
|
200
|
-
// operator token in config.json, the host pipe) to a devcontainer or sandbox.
|
|
201
|
-
dockerArgs.push('-e', `HUDDLE_HOST_HOME_DIR=${config_1.CONFIG_DIR}`);
|
|
202
176
|
if (fwFolder)
|
|
203
177
|
dockerArgs.push('-v', `${fwFolder}:/firewall-rules:rw`);
|
|
204
178
|
if (extFolder)
|
|
205
179
|
dockerArgs.push('-v', `${extFolder}:/extensions:ro`);
|
|
206
|
-
const hostLogs = (0, host_logs_1.hostAgentLogsMountArgs)(cfg, os_1.default.homedir());
|
|
207
|
-
if (hostLogs.length)
|
|
208
|
-
console.log((0, utils_1.dim)(' Mounting host Claude logs (read-only) for extensions'));
|
|
209
|
-
dockerArgs.push(...hostLogs);
|
|
210
|
-
const hostCodexLogs = (0, host_logs_1.hostCodexLogsMountArgs)(cfg, os_1.default.homedir());
|
|
211
|
-
if (hostCodexLogs.length)
|
|
212
|
-
console.log((0, utils_1.dim)(' Mounting host Codex logs (read-only) for extensions'));
|
|
213
|
-
dockerArgs.push(...hostCodexLogs);
|
|
214
|
-
dockerArgs.push(...(0, host_logs_1.hostCodexIndexMountArgs)(cfg, os_1.default.homedir()));
|
|
215
180
|
dockerArgs.push(...(0, images_1.gatewayEnvArgs)(images));
|
|
216
181
|
dockerArgs.push(IMAGE);
|
|
217
182
|
runArgs(rt, dockerArgs);
|
|
@@ -219,17 +184,7 @@ async function runInit(opts, images) {
|
|
|
219
184
|
// resolv.conf on Podman with that network's internal aardvark-DNS; the
|
|
220
185
|
// gateway cleans that up itself (see dns-egress.ts / the startup sanitize in
|
|
221
186
|
// index.ts).
|
|
222
|
-
runArgsSilent(rt, ['network', 'connect', exports.INTERNAL_NET,
|
|
223
|
-
// The host pipe lets the portal browse host folders and drive host tools
|
|
224
|
-
// (docs/host-pipe.md). Restarting it here means it always runs the CLI that
|
|
225
|
-
// was just installed. It is an extra, so a failure only warns.
|
|
226
|
-
const pipe = await (0, command_1.startPipeAgent)();
|
|
227
|
-
if (pipe.ok) {
|
|
228
|
-
console.log((0, utils_1.dim)(`Host pipe: running (pid ${pipe.pid})`));
|
|
229
|
-
}
|
|
230
|
-
else {
|
|
231
|
-
console.log((0, utils_1.yellow)(`[!] Host pipe did not start: ${pipe.error}. Run: huddle pipe start`));
|
|
232
|
-
}
|
|
187
|
+
runArgsSilent(rt, ['network', 'connect', exports.INTERNAL_NET, CONTAINER]);
|
|
233
188
|
console.log();
|
|
234
189
|
console.log((0, utils_1.green)(`[OK] Huddle is running at http://localhost:${HOST_PORT}`));
|
|
235
190
|
console.log();
|
package/dist/runtime.js
CHANGED
|
@@ -2,7 +2,6 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.parseDockerContextSocket = parseDockerContextSocket;
|
|
4
4
|
exports.isRancherDesktopSocket = isRancherDesktopSocket;
|
|
5
|
-
exports.dockerMountSocket = dockerMountSocket;
|
|
6
5
|
exports.parseRuntimeName = parseRuntimeName;
|
|
7
6
|
exports.resolveRuntime = resolveRuntime;
|
|
8
7
|
const child_process_1 = require("child_process");
|
|
@@ -42,6 +41,9 @@ function podmanSocketPath() {
|
|
|
42
41
|
}
|
|
43
42
|
return '/run/podman/podman.sock';
|
|
44
43
|
}
|
|
44
|
+
function dockerSocketPath() {
|
|
45
|
+
return process.platform === 'win32' ? '//var/run/docker.sock' : '/var/run/docker.sock';
|
|
46
|
+
}
|
|
45
47
|
/**
|
|
46
48
|
* Extracts the unix socket path from the JSON of `docker context inspect`. The
|
|
47
49
|
* active context determines which engine the `docker` command talks to; Rancher
|
|
@@ -49,11 +51,6 @@ function podmanSocketPath() {
|
|
|
49
51
|
* `Endpoints.docker.Host` points to `unix:///<home>/.rd/docker.sock` instead of
|
|
50
52
|
* the default `/var/run/docker.sock`.
|
|
51
53
|
*
|
|
52
|
-
* The result is only used to DETECT the engine (see buildRuntime), never as a
|
|
53
|
-
* bind-mount source: a context socket is the path the CLI uses to reach the
|
|
54
|
-
* daemon, which for VM-based engines is a host-side forwarder that the daemon
|
|
55
|
-
* itself cannot mount.
|
|
56
|
-
*
|
|
57
54
|
* Pure function so we can test the parsing in isolation. Returns `null` for
|
|
58
55
|
* non-parsable input or a non-unix endpoint (npipe:// on Windows,
|
|
59
56
|
* tcp:// / ssh:// remote), because those cannot be bind-mounted as a file path.
|
|
@@ -75,10 +72,10 @@ function parseDockerContextSocket(json) {
|
|
|
75
72
|
const path = host.slice('unix://'.length);
|
|
76
73
|
if (!path.startsWith('/'))
|
|
77
74
|
return null;
|
|
78
|
-
// The
|
|
79
|
-
//
|
|
80
|
-
//
|
|
81
|
-
//
|
|
75
|
+
// The returned path is interpolated into a `docker run -v "<path>:..."` shell
|
|
76
|
+
// command (init.ts), where it is DOUBLE-QUOTED. The `Host` from `docker context
|
|
77
|
+
// inspect` is attacker-influenceable (whoever can create/activate a docker
|
|
78
|
+
// context controls the value), so restrict it to characters that occur in a real
|
|
82
79
|
// socket path: allow spaces (legal in e.g. macOS `/Users/First Last/.rd/...`)
|
|
83
80
|
// but never the metacharacters that stay dangerous inside double quotes
|
|
84
81
|
// ($, backtick, ", \) or the command separators (;, |, &, (), newline).
|
|
@@ -97,28 +94,6 @@ function dockerContextSocket() {
|
|
|
97
94
|
return undefined;
|
|
98
95
|
return parseDockerContextSocket(json) ?? undefined;
|
|
99
96
|
}
|
|
100
|
-
/**
|
|
101
|
-
* Determines the docker socket to bind-mount (as seen by the engine) and
|
|
102
|
-
* whether the engine runs in a VM, given the active context's socket.
|
|
103
|
-
*
|
|
104
|
-
* Rancher Desktop (dockerd/moby mode) looks like an ordinary Docker engine, but
|
|
105
|
-
* its context points to `~/.rd/docker.sock`. That is a host-side forwarder into
|
|
106
|
-
* the Lima VM that only the CLI can use: bind-mount sources are resolved by
|
|
107
|
-
* dockerd INSIDE the VM, where that file is not a usable socket (dockerd then
|
|
108
|
-
* tries to mkdir it: "operation not supported"). Inside the VM dockerd listens
|
|
109
|
-
* on the standard /var/run/docker.sock, so we always mount that — the same
|
|
110
|
-
* engine-side reasoning as for /tmp/dc-sockets in init.ts.
|
|
111
|
-
*
|
|
112
|
-
* Pure function so we can test it without a daemon.
|
|
113
|
-
*/
|
|
114
|
-
function dockerMountSocket(contextSocket, platform) {
|
|
115
|
-
return {
|
|
116
|
-
socketPath: platform === 'win32' ? '//var/run/docker.sock' : '/var/run/docker.sock',
|
|
117
|
-
// Docker Desktop (macOS/Windows) and Rancher Desktop (every OS, Lima/WSL)
|
|
118
|
-
// run in a VM; native Docker on Linux does not.
|
|
119
|
-
isRemote: isRancherDesktopSocket(contextSocket) || platform !== 'linux',
|
|
120
|
-
};
|
|
121
|
-
}
|
|
122
97
|
function podmanIsRemote() {
|
|
123
98
|
// On macOS/Windows Podman always runs in a `podman machine` VM; on Linux too
|
|
124
99
|
// the client can point at a remote socket. `ServiceIsRemote` is the
|
|
@@ -135,15 +110,21 @@ function buildRuntime(name) {
|
|
|
135
110
|
securityOpts: ['label=disable'],
|
|
136
111
|
};
|
|
137
112
|
}
|
|
138
|
-
//
|
|
139
|
-
//
|
|
140
|
-
//
|
|
141
|
-
|
|
113
|
+
// Rancher Desktop (dockerd/moby mode) looks like an ordinary Docker engine,
|
|
114
|
+
// but the socket is not at /var/run/docker.sock: the active docker context
|
|
115
|
+
// points to `~/.rd/docker.sock`. Follow that context so we bind-mount the
|
|
116
|
+
// correct socket; otherwise we fall back to the default location (real native
|
|
117
|
+
// Docker, Docker Desktop). Rancher Desktop runs the engine in a VM (Lima/WSL)
|
|
118
|
+
// on EVERY platform, so it is always 'remote'.
|
|
119
|
+
const contextSocket = dockerContextSocket();
|
|
120
|
+
const isRancher = isRancherDesktopSocket(contextSocket);
|
|
142
121
|
return {
|
|
143
122
|
name,
|
|
144
|
-
socketPath,
|
|
123
|
+
socketPath: isRancher ? contextSocket : dockerSocketPath(),
|
|
145
124
|
defaultNetwork: 'bridge',
|
|
146
|
-
|
|
125
|
+
// Docker Desktop (macOS/Windows) and Rancher Desktop run in a VM; native
|
|
126
|
+
// Docker on Linux does not.
|
|
127
|
+
isRemote: isRancher || process.platform !== 'linux',
|
|
147
128
|
securityOpts: [],
|
|
148
129
|
};
|
|
149
130
|
}
|