@infosupport/huddle-cli 0.0.0-experiment-98.52.1 → 0.0.0-experiment-109.54.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 +37 -32
- package/dist/api.js +45 -14
- package/dist/control-address.js +160 -0
- package/dist/control-probe.js +174 -0
- package/dist/experiment.js +6 -0
- package/dist/firewall.js +10 -6
- package/dist/images.js +13 -9
- package/dist/index.js +139 -45
- package/dist/init.js +354 -89
- package/dist/logs.js +213 -0
- package/dist/migrate.js +53 -17
- package/dist/node.js +534 -0
- package/dist/sbx-host-ca.js +237 -0
- package/dist/sbx-host.js +36 -0
- package/dist/sbx.js +211 -0
- package/package.json +11 -3
- package/dist/indexfolder.js +0 -167
package/dist/indexfolder.js
DELETED
|
@@ -1,167 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.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
|
-
}
|