@infosupport/huddle-cli 1.2.18 → 1.2.19
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 +53 -0
- package/dist/config.js +145 -6
- package/dist/experiment.js +12 -7
- package/dist/firewall.js +184 -3
- package/dist/images.js +13 -9
- package/dist/index.js +119 -5
- package/dist/indexfolder.js +167 -0
- package/dist/init.js +49 -26
- package/dist/migrate.js +67 -58
- package/dist/start.js +49 -2
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -25,12 +25,63 @@ huddle # start an IntelliJ devcontainer for the current director
|
|
|
25
25
|
huddle ./project # start for a specific directory
|
|
26
26
|
huddle --ide rider
|
|
27
27
|
huddle --ide vscode --name devcontainer-demo
|
|
28
|
+
huddle --ide vscode --mount ../docker-corpa=/workspaces/backend --mount ../frontend-real-estate-info=/workspaces/frontend --name corpa-dev
|
|
28
29
|
huddle fw list
|
|
29
30
|
huddle firewall list -i
|
|
30
31
|
```
|
|
31
32
|
|
|
33
|
+
`--mount <host>=<container>` mounts an additional folder, worktree-isolated like the main workspace, at the container path you choose. The left side is a host path (relative paths are resolved against the current directory); the right side must be an **absolute** container path. Repeatable — pass one per folder — and cannot be combined with `--workspace`/`--empty`. Two mounts may not target the same container path.
|
|
34
|
+
|
|
35
|
+
`--workspace-root <path>` sets the absolute container path the IDE opens as its project root. It requires at least one `--mount`. Without it the root defaults to the deepest directory the mount targets share, so the example above opens `/workspaces` and shows `backend/` and `frontend/` inside it. Mount targets that share nothing fall back to `/workspaces`.
|
|
36
|
+
|
|
37
|
+
```bash
|
|
38
|
+
huddle --ide vscode \
|
|
39
|
+
--mount ../ai-context-repo=/workspaces/ai \
|
|
40
|
+
--mount ../backend-repo=/workspaces/backend \
|
|
41
|
+
--mount ../frontend-repo=/workspaces/frontend \
|
|
42
|
+
--workspace-root /workspaces --name corpa-dev
|
|
43
|
+
```
|
|
44
|
+
|
|
32
45
|
Default API URL: `http://localhost:3000`. Override it with `--url` or `HUDDLE_URL`.
|
|
33
46
|
|
|
47
|
+
## Making host folders selectable in the portal
|
|
48
|
+
|
|
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.
|
|
57
|
+
|
|
58
|
+
```bash
|
|
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)
|
|
66
|
+
```
|
|
67
|
+
|
|
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.
|
|
84
|
+
|
|
34
85
|
## Experiments
|
|
35
86
|
|
|
36
87
|
An experiment is a complete Huddle version (CLI + all Docker images) tied to a single GitHub issue. Push a branch `experiment/<issue-number>-<description>` and the pipeline publishes everything under the tag `experiment-<issue-number>`, fully separated from the normal releases.
|
|
@@ -59,6 +110,8 @@ Main flags:
|
|
|
59
110
|
```text
|
|
60
111
|
--ide <intellij|rider|vscode>
|
|
61
112
|
--workspace <path>
|
|
113
|
+
--mount <host>=<container> (repeatable, container path must be absolute)
|
|
114
|
+
--workspace-root <path> (container path the IDE opens; requires --mount)
|
|
62
115
|
--name <name>
|
|
63
116
|
--image <image>
|
|
64
117
|
--empty
|
package/dist/config.js
CHANGED
|
@@ -3,17 +3,19 @@ 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.CONFIG_DIR = void 0;
|
|
6
7
|
exports.configPath = configPath;
|
|
7
8
|
exports.readConfig = readConfig;
|
|
8
|
-
exports.
|
|
9
|
+
exports.updateConfig = updateConfig;
|
|
9
10
|
exports.operatorToken = operatorToken;
|
|
10
11
|
exports.activeExperiment = activeExperiment;
|
|
11
12
|
exports.imageTag = imageTag;
|
|
12
13
|
const fs_1 = __importDefault(require("fs"));
|
|
14
|
+
const crypto_1 = require("crypto");
|
|
13
15
|
const os_1 = __importDefault(require("os"));
|
|
14
16
|
const path_1 = __importDefault(require("path"));
|
|
15
|
-
|
|
16
|
-
const CONFIG_PATH = path_1.default.join(CONFIG_DIR, 'config.json');
|
|
17
|
+
exports.CONFIG_DIR = path_1.default.join(os_1.default.homedir(), '.huddle');
|
|
18
|
+
const CONFIG_PATH = path_1.default.join(exports.CONFIG_DIR, 'config.json');
|
|
17
19
|
function configPath() {
|
|
18
20
|
return CONFIG_PATH;
|
|
19
21
|
}
|
|
@@ -25,9 +27,146 @@ function readConfig() {
|
|
|
25
27
|
return {};
|
|
26
28
|
}
|
|
27
29
|
}
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
30
|
+
// ── Cross-process locking ─────────────────────────────────────────────────────
|
|
31
|
+
//
|
|
32
|
+
// The gateway edits this same file from inside its container (the portal writes
|
|
33
|
+
// the folder mappings and resource defaults there, see gateway/src/host-config.ts)
|
|
34
|
+
// while the CLI edits it from the host. Both do a read-modify-write of the whole
|
|
35
|
+
// document, so without a lock whoever writes last silently reverts the other's
|
|
36
|
+
// change. Same protocol on both sides: exclusive create of a sibling lock file,
|
|
37
|
+
// which works across the bind mount that joins the two.
|
|
38
|
+
const LOCK_PATH = `${CONFIG_PATH}.lock`;
|
|
39
|
+
const LOCK_WAIT_MS = 5000; // the gateway holds it for microseconds; this is pure headroom
|
|
40
|
+
const LOCK_STALE_MS = 10_000; // older than this means the holder died mid-write
|
|
41
|
+
function sleepSync(ms) {
|
|
42
|
+
Atomics.wait(new Int32Array(new SharedArrayBuffer(4)), 0, 0, ms);
|
|
43
|
+
}
|
|
44
|
+
// The lock file carries the identity of its holder, not just its existence. Age
|
|
45
|
+
// alone is not enough to decide it may be removed: a writer that pauses past
|
|
46
|
+
// LOCK_STALE_MS gets its lock broken and taken over, and would then delete the
|
|
47
|
+
// *new* holder's lock on the way out — letting a third writer in alongside the
|
|
48
|
+
// second, which is exactly the clobber the lock exists to prevent. A pid would
|
|
49
|
+
// not do as identity: the gateway runs in a container and this CLI on the host,
|
|
50
|
+
// sharing the file over a bind mount, so their pid spaces are unrelated.
|
|
51
|
+
function lockToken() {
|
|
52
|
+
return `${process.pid}:${(0, crypto_1.randomUUID)()}`;
|
|
53
|
+
}
|
|
54
|
+
function readLockToken() {
|
|
55
|
+
try {
|
|
56
|
+
return fs_1.default.readFileSync(LOCK_PATH, 'utf8');
|
|
57
|
+
}
|
|
58
|
+
catch {
|
|
59
|
+
return null; // gone between the stat and the read
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
// Remove a lock left behind by a writer that was killed mid-update, but only that
|
|
63
|
+
// exact lock: the token and mtime are re-read right before the unlink, so a lock
|
|
64
|
+
// another contender has meanwhile broken and taken over is left in place.
|
|
65
|
+
function breakStaleLock() {
|
|
66
|
+
let mtimeMs;
|
|
67
|
+
try {
|
|
68
|
+
mtimeMs = fs_1.default.statSync(LOCK_PATH).mtimeMs;
|
|
69
|
+
}
|
|
70
|
+
catch {
|
|
71
|
+
return; // already gone
|
|
72
|
+
}
|
|
73
|
+
if (Date.now() - mtimeMs <= LOCK_STALE_MS)
|
|
74
|
+
return;
|
|
75
|
+
const token = readLockToken();
|
|
76
|
+
if (token === null)
|
|
77
|
+
return;
|
|
78
|
+
try {
|
|
79
|
+
if (readLockToken() !== token)
|
|
80
|
+
return;
|
|
81
|
+
if (fs_1.default.statSync(LOCK_PATH).mtimeMs !== mtimeMs)
|
|
82
|
+
return;
|
|
83
|
+
fs_1.default.unlinkSync(LOCK_PATH);
|
|
84
|
+
}
|
|
85
|
+
catch { /* another process got there first — just retry */ }
|
|
86
|
+
}
|
|
87
|
+
// Returns the token identifying this holder, to be handed back to releaseLock.
|
|
88
|
+
function acquireLock() {
|
|
89
|
+
const deadline = Date.now() + LOCK_WAIT_MS;
|
|
90
|
+
for (;;) {
|
|
91
|
+
const token = lockToken();
|
|
92
|
+
try {
|
|
93
|
+
const fd = fs_1.default.openSync(LOCK_PATH, 'wx');
|
|
94
|
+
try {
|
|
95
|
+
fs_1.default.writeSync(fd, token);
|
|
96
|
+
}
|
|
97
|
+
finally {
|
|
98
|
+
fs_1.default.closeSync(fd);
|
|
99
|
+
}
|
|
100
|
+
return token;
|
|
101
|
+
}
|
|
102
|
+
catch (err) {
|
|
103
|
+
if (err.code !== 'EEXIST')
|
|
104
|
+
return null;
|
|
105
|
+
breakStaleLock();
|
|
106
|
+
if (Date.now() >= deadline)
|
|
107
|
+
return null;
|
|
108
|
+
sleepSync(25);
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
function releaseLock(token) {
|
|
113
|
+
// Never unlink a lock this writer no longer owns: if it was broken as stale and
|
|
114
|
+
// taken over, the file belongs to the writer that is running right now.
|
|
115
|
+
if (readLockToken() !== token)
|
|
116
|
+
return;
|
|
117
|
+
try {
|
|
118
|
+
fs_1.default.unlinkSync(LOCK_PATH);
|
|
119
|
+
}
|
|
120
|
+
catch { /* already gone */ }
|
|
121
|
+
}
|
|
122
|
+
let tmpSeq = 0;
|
|
123
|
+
/**
|
|
124
|
+
* The only writer. Merges a patch into the config file, re-reading it inside the
|
|
125
|
+
* lock so a concurrent gateway write is preserved instead of reverted; a key set
|
|
126
|
+
* to `undefined` is removed from the file. There is deliberately no
|
|
127
|
+
* write-the-whole-document variant: every such write was a read-modify-write of
|
|
128
|
+
* a snapshot that could already be stale.
|
|
129
|
+
*
|
|
130
|
+
* Throws when the lock cannot be taken. Writing anyway would reintroduce exactly
|
|
131
|
+
* the clobber the lock exists to prevent — the gateway would have the config open
|
|
132
|
+
* for a read-modify-write of its own, and one of the two edits would vanish. A
|
|
133
|
+
* failed command the operator can retry is the better outcome; the callers below
|
|
134
|
+
* (`huddle init`, `huddle firewall …`, `huddle experiment …`) all abort cleanly
|
|
135
|
+
* because nothing has been written yet at that point.
|
|
136
|
+
*
|
|
137
|
+
* The temp file name is unique per write — a shared `.tmp` lets two writers
|
|
138
|
+
* truncate each other's half-written file and rename the wreckage over the real
|
|
139
|
+
* config.
|
|
140
|
+
*/
|
|
141
|
+
function updateConfig(patch) {
|
|
142
|
+
fs_1.default.mkdirSync(exports.CONFIG_DIR, { recursive: true });
|
|
143
|
+
const token = acquireLock();
|
|
144
|
+
if (token === null) {
|
|
145
|
+
throw new Error(`Could not lock ${CONFIG_PATH} within ${LOCK_WAIT_MS}ms — another Huddle process ` +
|
|
146
|
+
`is writing it. Nothing was changed; retry the command. If no other process is ` +
|
|
147
|
+
`running, remove the stale lock: rm ${LOCK_PATH}`);
|
|
148
|
+
}
|
|
149
|
+
const tmp = `${CONFIG_PATH}.${process.pid}.${tmpSeq++}.tmp`;
|
|
150
|
+
try {
|
|
151
|
+
const next = { ...readConfig(), ...patch };
|
|
152
|
+
for (const [k, v] of Object.entries(next)) {
|
|
153
|
+
if (v === undefined)
|
|
154
|
+
delete next[k];
|
|
155
|
+
}
|
|
156
|
+
fs_1.default.writeFileSync(tmp, `${JSON.stringify(next, null, 2)}\n`);
|
|
157
|
+
fs_1.default.renameSync(tmp, CONFIG_PATH);
|
|
158
|
+
return next;
|
|
159
|
+
}
|
|
160
|
+
catch (err) {
|
|
161
|
+
try {
|
|
162
|
+
fs_1.default.unlinkSync(tmp);
|
|
163
|
+
}
|
|
164
|
+
catch { /* never created, or already renamed */ }
|
|
165
|
+
throw err;
|
|
166
|
+
}
|
|
167
|
+
finally {
|
|
168
|
+
releaseLock(token);
|
|
169
|
+
}
|
|
31
170
|
}
|
|
32
171
|
/** Operator-token voor API-auth: env wint, anders uit de config. */
|
|
33
172
|
function operatorToken() {
|
package/dist/experiment.js
CHANGED
|
@@ -57,7 +57,7 @@ function ensureCliForChannel(relaunchArgs, opts = {}) {
|
|
|
57
57
|
*/
|
|
58
58
|
async function runExperimentUse(issue, initOpts = {}) {
|
|
59
59
|
const previous = (0, config_1.readConfig)();
|
|
60
|
-
(0, config_1.
|
|
60
|
+
(0, config_1.updateConfig)({ channel: 'experiment', experiment: issue });
|
|
61
61
|
console.log((0, utils_1.green)(`Experiment ${issue} activated`) + (0, utils_1.dim)(` (${(0, config_1.configPath)()})`));
|
|
62
62
|
const relaunchArgs = ['init', ...(initOpts.runtime ? ['--runtime', initOpts.runtime] : [])];
|
|
63
63
|
try {
|
|
@@ -67,22 +67,27 @@ async function runExperimentUse(issue, initOpts = {}) {
|
|
|
67
67
|
}
|
|
68
68
|
catch (err) {
|
|
69
69
|
// Activation failed → roll back the config so a subsequent `huddle init`
|
|
70
|
-
// doesn't stay stuck on an experiment that cannot be installed.
|
|
71
|
-
|
|
70
|
+
// doesn't stay stuck on an experiment that cannot be installed. Only the two
|
|
71
|
+
// keys this function set are restored; anything the gateway wrote to the
|
|
72
|
+
// shared file meanwhile (folder mappings, resource defaults) stays put.
|
|
73
|
+
try {
|
|
74
|
+
(0, config_1.updateConfig)({ channel: previous.channel, experiment: previous.experiment });
|
|
75
|
+
}
|
|
76
|
+
catch (rollbackErr) {
|
|
77
|
+
// The rollback is a courtesy; never let it mask why activation failed.
|
|
78
|
+
console.error((0, utils_1.dim)(`Could not roll back ${(0, config_1.configPath)()}: ${rollbackErr.message}`));
|
|
79
|
+
}
|
|
72
80
|
throw err;
|
|
73
81
|
}
|
|
74
82
|
await (0, init_1.runInit)(initOpts, (0, images_1.resolveImages)());
|
|
75
83
|
}
|
|
76
84
|
/** Puts Huddle back on the stable release. */
|
|
77
85
|
async function runExperimentReset() {
|
|
78
|
-
const config = (0, config_1.readConfig)();
|
|
79
86
|
if ((0, config_1.activeExperiment)() === undefined && cliExperiment() === undefined) {
|
|
80
87
|
console.log('No experiment active; Huddle is already running on stable.');
|
|
81
88
|
return;
|
|
82
89
|
}
|
|
83
|
-
|
|
84
|
-
config.channel = 'stable';
|
|
85
|
-
(0, config_1.writeConfig)(config);
|
|
90
|
+
(0, config_1.updateConfig)({ channel: 'stable', experiment: undefined });
|
|
86
91
|
console.log((0, utils_1.green)('Experiment config removed') + (0, utils_1.dim)(` (${(0, config_1.configPath)()})`));
|
|
87
92
|
// If an experimental CLI is still running, this installs the stable version
|
|
88
93
|
// and the new CLI restarts itself to show the status.
|
package/dist/firewall.js
CHANGED
|
@@ -1,9 +1,18 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
2
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
6
|
exports.runFirewallList = runFirewallList;
|
|
4
7
|
exports.runFirewallAdd = runFirewallAdd;
|
|
5
8
|
exports.runFirewallDelete = runFirewallDelete;
|
|
9
|
+
exports.runFirewallExport = runFirewallExport;
|
|
10
|
+
exports.runFirewallImport = runFirewallImport;
|
|
11
|
+
exports.runFirewallGroup = runFirewallGroup;
|
|
12
|
+
exports.runFirewallFolder = runFirewallFolder;
|
|
13
|
+
const fs_1 = __importDefault(require("fs"));
|
|
6
14
|
const api_1 = require("./api");
|
|
15
|
+
const config_1 = require("./config");
|
|
7
16
|
const utils_1 = require("./utils");
|
|
8
17
|
async function runFirewallList(opts) {
|
|
9
18
|
const qs = new URLSearchParams({ status: opts.status ?? 'requested' });
|
|
@@ -56,9 +65,9 @@ async function resolveRule(rule, status, scope) {
|
|
|
56
65
|
}
|
|
57
66
|
// Creates a custom firewall rule. Supports wildcards: `*.` in the domain
|
|
58
67
|
// (e.g. `*.pkgs.dev.azure.com`) and `*` in the path pattern (e.g.
|
|
59
|
-
// `/_packaging/*/nuget/v3/*` for an Azure DevOps feed with a
|
|
60
|
-
// GUID). Defaults to 'allow';
|
|
61
|
-
// rule is global.
|
|
68
|
+
// `/_packaging/*/nuget/v3/*` for an Azure DevOps feed with a changing
|
|
69
|
+
// GUID). Defaults to 'allow'; --deny creates a block rule. Without --container
|
|
70
|
+
// the rule is global.
|
|
62
71
|
async function runFirewallAdd(opts) {
|
|
63
72
|
const domain = (opts.domain ?? '').trim();
|
|
64
73
|
if (!domain) {
|
|
@@ -135,3 +144,175 @@ function printRulesTable(rules) {
|
|
|
135
144
|
function formatTarget(rule) {
|
|
136
145
|
return rule.path_pattern ? `${rule.domain}${rule.path_pattern}` : rule.domain;
|
|
137
146
|
}
|
|
147
|
+
async function runFirewallExport(opts) {
|
|
148
|
+
const qs = new URLSearchParams();
|
|
149
|
+
if (opts.container)
|
|
150
|
+
qs.set('container', opts.container);
|
|
151
|
+
const suffix = qs.toString() ? `?${qs}` : '';
|
|
152
|
+
const doc = await (0, api_1.get)(`/api/rules/export${suffix}`);
|
|
153
|
+
const json = JSON.stringify(doc, null, 2);
|
|
154
|
+
if (opts.out) {
|
|
155
|
+
fs_1.default.writeFileSync(opts.out, `${json}\n`);
|
|
156
|
+
// Progress to stderr so a pure `--out` run leaks nothing to stdout.
|
|
157
|
+
console.error((0, utils_1.green)(`[OK] Exported ${doc.rules.length} rule(s) to ${opts.out}`));
|
|
158
|
+
}
|
|
159
|
+
else {
|
|
160
|
+
console.log(json);
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
// Read + JSON-parse a file with uniform, actionable errors. Shared by both
|
|
164
|
+
// import paths (flat rules and groups).
|
|
165
|
+
function readJsonFile(file) {
|
|
166
|
+
let raw;
|
|
167
|
+
try {
|
|
168
|
+
raw = fs_1.default.readFileSync(file, 'utf8');
|
|
169
|
+
}
|
|
170
|
+
catch {
|
|
171
|
+
throw new Error(`Cannot read ${file}`);
|
|
172
|
+
}
|
|
173
|
+
try {
|
|
174
|
+
return JSON.parse(raw);
|
|
175
|
+
}
|
|
176
|
+
catch {
|
|
177
|
+
throw new Error(`${file} is not valid JSON`);
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
// The name of the group a document describes, or null when it is a plain rules
|
|
181
|
+
// export. A group envelope carries it under `group`, or at the top level in the
|
|
182
|
+
// documented bare form.
|
|
183
|
+
function groupNameOf(doc) {
|
|
184
|
+
const meta = (doc['group'] && typeof doc['group'] === 'object' && !Array.isArray(doc['group']) ? doc['group'] : doc);
|
|
185
|
+
const name = typeof meta['name'] === 'string' ? meta['name'].trim() : '';
|
|
186
|
+
return name || null;
|
|
187
|
+
}
|
|
188
|
+
async function runFirewallImport(opts) {
|
|
189
|
+
const doc = readJsonFile(opts.file);
|
|
190
|
+
const mode = opts.replace ? 'replace' : 'merge';
|
|
191
|
+
// A group envelope handed to the flat importer used to import its rules and
|
|
192
|
+
// silently drop the group (#98). Send it where it belongs instead — unless
|
|
193
|
+
// --container asks for a scope remap, which only the flat importer does.
|
|
194
|
+
const groupName = groupNameOf(doc);
|
|
195
|
+
if (groupName && !opts.container) {
|
|
196
|
+
console.error((0, utils_1.dim)(`[i] ${opts.file} is the group "${groupName}" — importing it as a group.`));
|
|
197
|
+
await runFirewallGroup({ action: 'import', arg: opts.file, replace: opts.replace });
|
|
198
|
+
return;
|
|
199
|
+
}
|
|
200
|
+
if (groupName) {
|
|
201
|
+
console.error((0, utils_1.dim)(`[i] ${opts.file} is the group "${groupName}"; --container imports its rules into that scope without the group.`));
|
|
202
|
+
}
|
|
203
|
+
const qs = new URLSearchParams();
|
|
204
|
+
if (opts.container)
|
|
205
|
+
qs.set('container', opts.container);
|
|
206
|
+
const suffix = qs.toString() ? `?${qs}` : '';
|
|
207
|
+
const res = await (0, api_1.post)(`/api/rules/import${suffix}`, { mode, rules: doc.rules });
|
|
208
|
+
console.error((0, utils_1.green)(`[OK] Imported (${mode}): ${res.imported} added, ${res.updated} updated, ${res.skipped} skipped`));
|
|
209
|
+
}
|
|
210
|
+
async function resolveGroupByName(name) {
|
|
211
|
+
const groups = await (0, api_1.get)('/api/groups');
|
|
212
|
+
const match = groups.filter((g) => g.name.toLowerCase() === name.toLowerCase());
|
|
213
|
+
if (match.length === 0)
|
|
214
|
+
throw new Error(`No group named "${name}". Run \`huddle firewall group list\`.`);
|
|
215
|
+
return match[0];
|
|
216
|
+
}
|
|
217
|
+
async function runFirewallGroup(opts) {
|
|
218
|
+
const action = opts.action ?? 'list';
|
|
219
|
+
if (action === 'list') {
|
|
220
|
+
const groups = await (0, api_1.get)('/api/groups');
|
|
221
|
+
if (groups.length === 0) {
|
|
222
|
+
console.log((0, utils_1.dim)('No firewall groups yet.'));
|
|
223
|
+
return;
|
|
224
|
+
}
|
|
225
|
+
const headers = ['ID', 'Name', 'Rules', 'Shared', 'Source'];
|
|
226
|
+
const rows = groups.map((g) => [String(g.id), g.name, String(g.rule_count), g.shared ? 'yes' : 'no', g.source]);
|
|
227
|
+
(0, utils_1.printTable)(headers, rows);
|
|
228
|
+
return;
|
|
229
|
+
}
|
|
230
|
+
if (action === 'export') {
|
|
231
|
+
const name = (opts.arg ?? '').trim();
|
|
232
|
+
if (!name)
|
|
233
|
+
throw new Error('Usage: huddle firewall group export <name> [--out <file>]');
|
|
234
|
+
const g = await resolveGroupByName(name);
|
|
235
|
+
const env = await (0, api_1.get)(`/api/groups/${g.id}/export`);
|
|
236
|
+
const json = JSON.stringify(env, null, 2);
|
|
237
|
+
if (opts.out) {
|
|
238
|
+
fs_1.default.writeFileSync(opts.out, `${json}\n`);
|
|
239
|
+
console.error((0, utils_1.green)(`[OK] Exported group "${g.name}" to ${opts.out}`));
|
|
240
|
+
}
|
|
241
|
+
else {
|
|
242
|
+
console.log(json);
|
|
243
|
+
}
|
|
244
|
+
return;
|
|
245
|
+
}
|
|
246
|
+
if (action === 'import') {
|
|
247
|
+
const file = (opts.arg ?? '').trim();
|
|
248
|
+
if (!file)
|
|
249
|
+
throw new Error('Usage: huddle firewall group import <file> [--replace]');
|
|
250
|
+
const envelope = readJsonFile(file);
|
|
251
|
+
const mode = opts.replace ? 'replace' : 'merge';
|
|
252
|
+
const res = await (0, api_1.post)('/api/groups/import', { mode, envelope });
|
|
253
|
+
console.error((0, utils_1.green)(`[OK] Imported group "${res.group.name}" (${mode}): ${res.imported} added, ${res.updated} updated, ${res.skipped} skipped`));
|
|
254
|
+
return;
|
|
255
|
+
}
|
|
256
|
+
if (action === 'apply') {
|
|
257
|
+
const name = (opts.arg ?? '').trim();
|
|
258
|
+
if (!name)
|
|
259
|
+
throw new Error('Usage: huddle firewall group apply <name> [--container <id>]');
|
|
260
|
+
const g = await resolveGroupByName(name);
|
|
261
|
+
const container = opts.container ?? null;
|
|
262
|
+
const res = await (0, api_1.post)(`/api/groups/${g.id}/apply`, { container });
|
|
263
|
+
const scope = container ? `container ${container}` : 'global';
|
|
264
|
+
console.log((0, utils_1.green)(`[OK] Applied "${g.name}" to ${scope}: ${res.applied} added, ${res.updated} updated`));
|
|
265
|
+
return;
|
|
266
|
+
}
|
|
267
|
+
throw new Error(`Unknown group action: ${action}. Use list | export | import | apply.`);
|
|
268
|
+
}
|
|
269
|
+
async function runFirewallFolder(opts) {
|
|
270
|
+
const action = opts.action ?? 'show';
|
|
271
|
+
if (action === 'show') {
|
|
272
|
+
// The CLI config is the source of truth for the path.
|
|
273
|
+
const folder = (0, config_1.readConfig)().firewallRulesFolder;
|
|
274
|
+
console.log(folder ? folder : (0, utils_1.dim)('(no firewall rules folder configured)'));
|
|
275
|
+
return;
|
|
276
|
+
}
|
|
277
|
+
if (action === 'set') {
|
|
278
|
+
const path = (opts.path ?? '').trim();
|
|
279
|
+
if (!path)
|
|
280
|
+
throw new Error('Usage: huddle firewall folder set <path>');
|
|
281
|
+
// Config-only: the gateway reads the folder at the fixed mount point the CLI
|
|
282
|
+
// binds it to; there is no DB setting. Persist here and mount on restart.
|
|
283
|
+
(0, config_1.updateConfig)({ firewallRulesFolder: path });
|
|
284
|
+
console.log((0, utils_1.green)(`[OK] Firewall rules folder set to ${(0, utils_1.cyan)(path)}`));
|
|
285
|
+
console.log((0, utils_1.dim)(' Run `huddle restart` to mount it into the gateway; it is then read on start & reload.'));
|
|
286
|
+
return;
|
|
287
|
+
}
|
|
288
|
+
if (action === 'reload') {
|
|
289
|
+
const res = await (0, api_1.post)('/api/firewall-rules-folder/reload', {});
|
|
290
|
+
if (!res.mounted) {
|
|
291
|
+
console.log((0, utils_1.dim)('No firewall rules folder mounted. Set one with `huddle firewall folder set <path>` and run `huddle restart`.'));
|
|
292
|
+
return;
|
|
293
|
+
}
|
|
294
|
+
console.log((0, utils_1.green)(`[OK] Reloaded: ${res.groups} group(s), ${res.imported} rule(s), ${res.errors.length} error(s)`));
|
|
295
|
+
for (const e of res.errors)
|
|
296
|
+
console.error((0, utils_1.red)(` [!] ${e.file}: ${e.message}`));
|
|
297
|
+
return;
|
|
298
|
+
}
|
|
299
|
+
if (action === 'sync') {
|
|
300
|
+
// Write the portal's groups back out to the folder (app → files).
|
|
301
|
+
const res = await (0, api_1.post)('/api/firewall-rules-folder/sync', {});
|
|
302
|
+
if (!res.mounted) {
|
|
303
|
+
console.log((0, utils_1.dim)('No firewall rules folder mounted. Set one with `huddle firewall folder set <path>` and run `huddle restart`.'));
|
|
304
|
+
return;
|
|
305
|
+
}
|
|
306
|
+
if (res.written === 0 && res.errors.length > 0) {
|
|
307
|
+
console.error((0, utils_1.red)('[!] Could not write to the folder — it may still be mounted read-only. Run `huddle restart` to remount it writable.'));
|
|
308
|
+
for (const e of res.errors)
|
|
309
|
+
console.error((0, utils_1.red)(` [!] ${e.file}: ${e.message}`));
|
|
310
|
+
return;
|
|
311
|
+
}
|
|
312
|
+
console.log((0, utils_1.green)(`[OK] Synced: ${res.written} group(s) written, ${res.pruned} stale file(s) removed, ${res.errors.length} error(s)`));
|
|
313
|
+
for (const e of res.errors)
|
|
314
|
+
console.error((0, utils_1.red)(` [!] ${e.file}: ${e.message}`));
|
|
315
|
+
return;
|
|
316
|
+
}
|
|
317
|
+
throw new Error(`Unknown folder action: ${action}. Use show | set | reload | sync.`);
|
|
318
|
+
}
|
package/dist/images.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.resolveImages = resolveImages;
|
|
4
|
-
exports.
|
|
4
|
+
exports.gatewayEnvArgs = gatewayEnvArgs;
|
|
5
5
|
const config_1 = require("./config");
|
|
6
6
|
function resolveImages() {
|
|
7
7
|
const experiment = (0, config_1.activeExperiment)();
|
|
@@ -19,13 +19,17 @@ function resolveImages() {
|
|
|
19
19
|
};
|
|
20
20
|
}
|
|
21
21
|
/**
|
|
22
|
-
* `-e`
|
|
23
|
-
* explicit override) the gateway must start devcontainers from the same
|
|
24
|
-
* base images the CLI just pulled.
|
|
22
|
+
* `-e KEY=val` argv pairs for the gateway container. During an experiment (or
|
|
23
|
+
* with an explicit override) the gateway must start devcontainers from the same
|
|
24
|
+
* base images the CLI just pulled. Returned as an argv array (not a shell
|
|
25
|
+
* string) so init can spawn `docker run` without a shell.
|
|
25
26
|
*/
|
|
26
|
-
function
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
27
|
+
function gatewayEnvArgs(resolved) {
|
|
28
|
+
const args = [];
|
|
29
|
+
for (const b of resolved.baseImages) {
|
|
30
|
+
if (b.gatewayEnv && (resolved.experiment !== undefined || process.env[b.gatewayEnv])) {
|
|
31
|
+
args.push('-e', `${b.gatewayEnv}=${b.image}`);
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
return args;
|
|
31
35
|
}
|
package/dist/index.js
CHANGED
|
@@ -11,16 +11,18 @@ const start_1 = require("./start");
|
|
|
11
11
|
const firewall_1 = require("./firewall");
|
|
12
12
|
const init_1 = require("./init");
|
|
13
13
|
const migrate_1 = require("./migrate");
|
|
14
|
+
const indexfolder_1 = require("./indexfolder");
|
|
14
15
|
const images_1 = require("./images");
|
|
15
16
|
const self_update_1 = require("./self-update");
|
|
16
17
|
const utils_1 = require("./utils");
|
|
17
18
|
const experiment_1 = require("./experiment");
|
|
18
|
-
const VALUE_FLAGS = new Set(['url', 'ide', 'name', 'image', 'workspace', 'container', 'status', 'runtime', 'experiment', 'path', 'ca-path', 'output']);
|
|
19
|
-
const BOOLEAN_FLAGS = new Set(['help', 'h', 'empty', 'i', 'interactive', 'version', 'v', 'deny', 'docker-socket', 'force']);
|
|
20
|
-
const COMMANDS = new Set(['start', 'firewall', 'fw', 'init', 'experiment', 'migrate', 'help', 'version']);
|
|
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']);
|
|
21
22
|
function parseArgs(argv) {
|
|
22
23
|
const positional = [];
|
|
23
24
|
const flags = {};
|
|
25
|
+
const mounts = [];
|
|
24
26
|
for (let i = 0; i < argv.length; i++) {
|
|
25
27
|
const arg = argv[i];
|
|
26
28
|
if (arg === '--') {
|
|
@@ -33,6 +35,23 @@ function parseArgs(argv) {
|
|
|
33
35
|
const name = eq >= 0 ? raw.slice(0, eq) : raw;
|
|
34
36
|
if (!name)
|
|
35
37
|
throw new Error(`Invalid option: ${arg}`);
|
|
38
|
+
// Repeatable, unlike every other value flag (one `--mount host=container` per folder).
|
|
39
|
+
if (name === 'mount') {
|
|
40
|
+
let value;
|
|
41
|
+
if (eq >= 0) {
|
|
42
|
+
value = raw.slice(eq + 1);
|
|
43
|
+
}
|
|
44
|
+
else {
|
|
45
|
+
const next = argv[i + 1];
|
|
46
|
+
if (next === undefined || next.startsWith('-')) {
|
|
47
|
+
throw new Error('Option --mount expects a value (host=container)');
|
|
48
|
+
}
|
|
49
|
+
value = next;
|
|
50
|
+
i++;
|
|
51
|
+
}
|
|
52
|
+
mounts.push(value);
|
|
53
|
+
continue;
|
|
54
|
+
}
|
|
36
55
|
if (eq >= 0) {
|
|
37
56
|
flags[name] = raw.slice(eq + 1);
|
|
38
57
|
}
|
|
@@ -70,7 +89,13 @@ function parseArgs(argv) {
|
|
|
70
89
|
}
|
|
71
90
|
positional.push(arg);
|
|
72
91
|
}
|
|
73
|
-
return { positional, flags };
|
|
92
|
+
return { positional, flags, mounts };
|
|
93
|
+
}
|
|
94
|
+
function parseMountFlag(raw) {
|
|
95
|
+
const eq = raw.indexOf('=');
|
|
96
|
+
if (eq <= 0)
|
|
97
|
+
throw new Error(`Invalid --mount value "${raw}", expected host=container`);
|
|
98
|
+
return { hostPath: raw.slice(0, eq), containerPath: raw.slice(eq + 1) };
|
|
74
99
|
}
|
|
75
100
|
function readVersion() {
|
|
76
101
|
// npm always includes package.json in the published tarball, and it holds the
|
|
@@ -94,14 +119,29 @@ Usage:
|
|
|
94
119
|
huddle start [options] [folder] Explicitly start a devcontainer
|
|
95
120
|
huddle init [options] Pull the Huddle + devcontainer base images and
|
|
96
121
|
start them via Docker or Podman
|
|
122
|
+
huddle restart Recreate the gateway (e.g. to mount a changed
|
|
123
|
+
team firewall-rules folder)
|
|
97
124
|
huddle migrate [folder] Wire an existing docker-compose devcontainer
|
|
98
125
|
behind Huddle by generating an override file
|
|
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)
|
|
99
130
|
huddle firewall list [options] Show firewall requests
|
|
100
131
|
huddle fw list [options] Alias for firewall list
|
|
101
132
|
huddle firewall add <domain> Add a custom firewall rule (wildcards
|
|
102
133
|
supported: *.example.com and /path/*)
|
|
103
134
|
huddle firewall delete <id> Delete a firewall rule by id (or domain;
|
|
104
135
|
narrow with --container)
|
|
136
|
+
huddle firewall export [options] Export firewall rules as JSON
|
|
137
|
+
huddle firewall import <file> Import firewall rules from a JSON file
|
|
138
|
+
huddle firewall group list List firewall groups (#69)
|
|
139
|
+
huddle firewall group export <name> Export a group as JSON (--out <file>)
|
|
140
|
+
huddle firewall group import <file> Import a group (--replace to mirror)
|
|
141
|
+
huddle firewall group apply <name> Apply a group (--container <id> or global)
|
|
142
|
+
huddle firewall folder set <path> Set the team-managed rules folder
|
|
143
|
+
huddle firewall folder reload Re-read the team-managed rules folder
|
|
144
|
+
huddle firewall folder sync Write the portal's groups back to the folder
|
|
105
145
|
huddle experiment use <nr> Activate the experimental build of issue/PR <nr>
|
|
106
146
|
and run init
|
|
107
147
|
huddle experiment reset Back to the stable release
|
|
@@ -116,6 +156,11 @@ Init options:
|
|
|
116
156
|
Start options:
|
|
117
157
|
--ide <intellij|rider|vscode> IDE (default: intellij)
|
|
118
158
|
--workspace <path> Workspace directory (default: current directory)
|
|
159
|
+
--mount <host>=<container> Mount a host folder at an absolute container path, e.g.
|
|
160
|
+
C:/projects/my-repo/backend=/workspace/backend
|
|
161
|
+
(repeatable; cannot combine with --workspace/--empty)
|
|
162
|
+
--workspace-root <path> Container path the IDE opens as project root when using
|
|
163
|
+
--mount (default: common parent of the mount targets)
|
|
119
164
|
--name <name> Container name (default: devcontainer-<foldername>)
|
|
120
165
|
--image <image> Use a specific image
|
|
121
166
|
--empty Empty container without a workspace
|
|
@@ -129,9 +174,21 @@ Migrate options:
|
|
|
129
174
|
(default: docker-compose.huddle.yml next to the source)
|
|
130
175
|
--force Overwrite an existing override file
|
|
131
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
|
+
|
|
132
187
|
Firewall options:
|
|
133
188
|
-i, --interactive Interactively approve/deny (list)
|
|
134
189
|
--container <name> Filter by (list) / scope to (add) a container
|
|
190
|
+
(or __global__). On import: remap all rules
|
|
191
|
+
to this scope
|
|
135
192
|
--status <requested|allow|deny> Filter by status (default: requested)
|
|
136
193
|
|
|
137
194
|
Firewall add options:
|
|
@@ -140,6 +197,11 @@ Firewall add options:
|
|
|
140
197
|
(e.g. /_packaging/*/nuget/v3/*)
|
|
141
198
|
--deny Create a block rule (default: allow)
|
|
142
199
|
|
|
200
|
+
Firewall export/import options:
|
|
201
|
+
--out <file> Write export to a file (default: stdout)
|
|
202
|
+
--replace Import in replace mode: wipe the target
|
|
203
|
+
scope first (default: merge/upsert)
|
|
204
|
+
|
|
143
205
|
Global options:
|
|
144
206
|
--url <url> Huddle URL (default: http://localhost:3000)
|
|
145
207
|
Or via the HUDDLE_URL env var
|
|
@@ -158,7 +220,7 @@ async function main() {
|
|
|
158
220
|
console.error('Run "huddle --help" for help.');
|
|
159
221
|
process.exit(1);
|
|
160
222
|
}
|
|
161
|
-
const { positional, flags } = parsed;
|
|
223
|
+
const { positional, flags, mounts } = parsed;
|
|
162
224
|
const [cmd, sub] = positional;
|
|
163
225
|
if (flagBool(flags, 'version', 'v') || cmd === 'version') {
|
|
164
226
|
console.log(readVersion());
|
|
@@ -179,6 +241,8 @@ async function main() {
|
|
|
179
241
|
await (0, start_1.runStart)({
|
|
180
242
|
ide: flagString(flags, 'ide') ?? 'intellij',
|
|
181
243
|
workspace: flagString(flags, 'workspace') ?? startArgs[0],
|
|
244
|
+
mounts: mounts.length ? mounts.map(parseMountFlag) : undefined,
|
|
245
|
+
workspaceRoot: flagString(flags, 'workspace-root'),
|
|
182
246
|
name: flagString(flags, 'name'),
|
|
183
247
|
image: flagString(flags, 'image'),
|
|
184
248
|
empty: flagBool(flags, 'empty'),
|
|
@@ -202,6 +266,15 @@ async function main() {
|
|
|
202
266
|
await (0, init_1.runInit)(initOpts, (0, images_1.resolveImages)());
|
|
203
267
|
return;
|
|
204
268
|
}
|
|
269
|
+
if (cmd === 'restart') {
|
|
270
|
+
// Stop + recreate the gateway (runInit does `rm -f` first) so changed team
|
|
271
|
+
// folders get mounted. The portal writes the paths straight into the mounted
|
|
272
|
+
// ~/.huddle/config.json, so runInit already reads the latest values here.
|
|
273
|
+
const initOpts = { runtime: flagString(flags, 'runtime') };
|
|
274
|
+
(0, experiment_1.ensureCliForChannel)(process.argv.slice(2));
|
|
275
|
+
await (0, init_1.runInit)(initOpts, (0, images_1.resolveImages)());
|
|
276
|
+
return;
|
|
277
|
+
}
|
|
205
278
|
if (cmd === 'experiment') {
|
|
206
279
|
const subCmd = sub ?? 'status';
|
|
207
280
|
if (subCmd === 'use') {
|
|
@@ -243,12 +316,53 @@ async function main() {
|
|
|
243
316
|
container: flagString(flags, 'container'),
|
|
244
317
|
});
|
|
245
318
|
}
|
|
319
|
+
else if (subCmd === 'export') {
|
|
320
|
+
await (0, firewall_1.runFirewallExport)({
|
|
321
|
+
container: flagString(flags, 'container'),
|
|
322
|
+
out: flagString(flags, 'out'),
|
|
323
|
+
});
|
|
324
|
+
}
|
|
325
|
+
else if (subCmd === 'import') {
|
|
326
|
+
const file = positional[2];
|
|
327
|
+
if (!file) {
|
|
328
|
+
console.error('Usage: huddle firewall import <file> [--replace] [--container <id>]');
|
|
329
|
+
process.exit(1);
|
|
330
|
+
}
|
|
331
|
+
await (0, firewall_1.runFirewallImport)({
|
|
332
|
+
file,
|
|
333
|
+
replace: flagBool(flags, 'replace'),
|
|
334
|
+
container: flagString(flags, 'container'),
|
|
335
|
+
});
|
|
336
|
+
}
|
|
337
|
+
else if (subCmd === 'group' || subCmd === 'groups') {
|
|
338
|
+
await (0, firewall_1.runFirewallGroup)({
|
|
339
|
+
action: positional[2],
|
|
340
|
+
arg: positional[3],
|
|
341
|
+
out: flagString(flags, 'out'),
|
|
342
|
+
replace: flagBool(flags, 'replace'),
|
|
343
|
+
container: flagString(flags, 'container'),
|
|
344
|
+
});
|
|
345
|
+
}
|
|
346
|
+
else if (subCmd === 'folder') {
|
|
347
|
+
await (0, firewall_1.runFirewallFolder)({ action: positional[2], path: positional[3] });
|
|
348
|
+
}
|
|
246
349
|
else {
|
|
247
350
|
console.error(`Unknown firewall subcommand: ${subCmd}`);
|
|
248
351
|
process.exit(1);
|
|
249
352
|
}
|
|
250
353
|
return;
|
|
251
354
|
}
|
|
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
|
+
});
|
|
364
|
+
return;
|
|
365
|
+
}
|
|
252
366
|
if (cmd === 'migrate') {
|
|
253
367
|
await (0, migrate_1.runMigrate)({
|
|
254
368
|
path: positional[1],
|
|
@@ -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
|
@@ -29,12 +29,16 @@ exports.INTERNAL_NET = 'devcontainer-net';
|
|
|
29
29
|
*/
|
|
30
30
|
exports.HOST_SOCKET_DIR = '/tmp/dc-sockets';
|
|
31
31
|
const HOST_PORT = process.env.HUDDLE_PORT ?? '3000';
|
|
32
|
-
|
|
33
|
-
|
|
32
|
+
// Run a binary with an argv array — NO shell. Values that originate from config
|
|
33
|
+
// (team-folder paths, which are writable via `huddle firewall folder set` and the
|
|
34
|
+
// authenticated settings API) must never be interpolated into a shell string, or
|
|
35
|
+
// a path containing `$()`/quotes would execute on the host. Used for `docker run`.
|
|
36
|
+
function runArgs(file, args) {
|
|
37
|
+
(0, child_process_1.execFileSync)(file, args, { stdio: 'inherit' });
|
|
34
38
|
}
|
|
35
|
-
function
|
|
39
|
+
function runArgsSilent(file, args) {
|
|
36
40
|
try {
|
|
37
|
-
(0, child_process_1.
|
|
41
|
+
(0, child_process_1.execFileSync)(file, args, { stdio: 'ignore' });
|
|
38
42
|
return true;
|
|
39
43
|
}
|
|
40
44
|
catch {
|
|
@@ -52,7 +56,7 @@ function pullBaseImages(rt, images) {
|
|
|
52
56
|
for (const image of images) {
|
|
53
57
|
console.log((0, utils_1.dim)(` Pulling ${image}`));
|
|
54
58
|
try {
|
|
55
|
-
|
|
59
|
+
runArgs(rt, ['pull', image]);
|
|
56
60
|
}
|
|
57
61
|
catch {
|
|
58
62
|
failed.push(image);
|
|
@@ -82,15 +86,15 @@ async function runInit(opts, images) {
|
|
|
82
86
|
}
|
|
83
87
|
else {
|
|
84
88
|
console.log((0, utils_1.dim)(`Pulling ${IMAGE}`));
|
|
85
|
-
|
|
89
|
+
runArgs(rt, ['pull', IMAGE]);
|
|
86
90
|
pullBaseImages(rt, images.baseImages.map((b) => b.image));
|
|
87
91
|
}
|
|
88
92
|
console.log((0, utils_1.dim)(`Volume: ${VOLUME}`));
|
|
89
|
-
|
|
93
|
+
runArgsSilent(rt, ['volume', 'inspect', VOLUME]) || runArgs(rt, ['volume', 'create', VOLUME]);
|
|
90
94
|
console.log((0, utils_1.dim)(`Network: ${exports.INTERNAL_NET}`));
|
|
91
|
-
|
|
95
|
+
runArgsSilent(rt, ['network', 'inspect', exports.INTERNAL_NET]) || runArgs(rt, ['network', 'create', '--internal', exports.INTERNAL_NET]);
|
|
92
96
|
console.log((0, utils_1.dim)(`Removing old container if it exists`));
|
|
93
|
-
|
|
97
|
+
runArgsSilent(rt, ['rm', '-f', CONTAINER]);
|
|
94
98
|
console.log((0, utils_1.dim)(`Socket directory: /tmp/dc-sockets`));
|
|
95
99
|
// The mount SOURCE must be the path on the Docker ENGINE host (on Windows:
|
|
96
100
|
// the WSL2/Linux VM), even when the CLI itself runs on Windows. The gateway
|
|
@@ -105,7 +109,7 @@ async function runInit(opts, images) {
|
|
|
105
109
|
// Desktop) and fails with "statfs: no such file or directory". So create
|
|
106
110
|
// the directory explicitly in the machine VM; the socket lives there too.
|
|
107
111
|
console.log((0, utils_1.dim)(` (Podman: creating ${hostTmpSockets} in the machine VM)`));
|
|
108
|
-
if (!
|
|
112
|
+
if (!runArgsSilent('podman', ['machine', 'ssh', `mkdir -p ${hostTmpSockets}`])) {
|
|
109
113
|
console.log((0, utils_1.yellow)(`[!] Could not create ${hostTmpSockets} in the Podman VM.`));
|
|
110
114
|
}
|
|
111
115
|
}
|
|
@@ -126,8 +130,7 @@ async function runInit(opts, images) {
|
|
|
126
130
|
// The gateway is engine-agnostic (talks the Docker-compatible API on the
|
|
127
131
|
// mounted socket), but does need to know it's Podman: it then sets
|
|
128
132
|
// `--security-opt label=disable` on every devcontainer so it can reach the
|
|
129
|
-
// SELinux-labeled proxy socket.
|
|
130
|
-
const securityOptFlags = runtime.securityOpts.map((opt) => ` --security-opt ${opt}`).join('');
|
|
133
|
+
// SELinux-labeled proxy socket. (Applied as argv below via runtime.securityOpts.)
|
|
131
134
|
// Operator token for control-plane auth. Reuse the token from the config (so an
|
|
132
135
|
// existing browser session/CLI keeps working across re-inits), otherwise
|
|
133
136
|
// generate one. We pass it to the gateway via env AND store it locally so that
|
|
@@ -137,7 +140,7 @@ async function runInit(opts, images) {
|
|
|
137
140
|
(cfg.operatorToken && cfg.operatorToken.trim()) ||
|
|
138
141
|
crypto_1.default.randomBytes(32).toString('base64url');
|
|
139
142
|
if (cfg.operatorToken !== operatorToken) {
|
|
140
|
-
(0, config_1.
|
|
143
|
+
(0, config_1.updateConfig)({ operatorToken });
|
|
141
144
|
}
|
|
142
145
|
// The container is created on the engine's default network first (with -p),
|
|
143
146
|
// then joins devcontainer-net (--internal) afterwards: Docker skips the host
|
|
@@ -145,23 +148,43 @@ async function runInit(opts, images) {
|
|
|
145
148
|
// network (moby/moby#36174). Which source IP the gateway sees for forwarded
|
|
146
149
|
// traffic no longer matters — the control plane authenticates with the
|
|
147
150
|
// operator token instead of source-IP filtering.
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
` -
|
|
158
|
-
|
|
159
|
-
` ${
|
|
151
|
+
// Team-managed folders (#69). Bind the CLI config dir (~/.huddle) read-write so
|
|
152
|
+
// the gateway/portal read and write the folder paths there (config.json is the
|
|
153
|
+
// single source of truth), then bind each configured team folder to a FIXED
|
|
154
|
+
// path so the gateway reads it without knowing the host path. The firewall-rules
|
|
155
|
+
// folder is bound read-write so the portal's "Sync to folder" can write the
|
|
156
|
+
// groups back out; extensions stay read-only (loaded, never written).
|
|
157
|
+
const fwFolder = cfg.firewallRulesFolder?.trim();
|
|
158
|
+
const extFolder = cfg.extensionsFolder?.trim();
|
|
159
|
+
if (fwFolder)
|
|
160
|
+
console.log((0, utils_1.dim)(` Mounting firewall-rules folder: ${fwFolder} -> /firewall-rules`));
|
|
161
|
+
if (extFolder)
|
|
162
|
+
console.log((0, utils_1.dim)(` Mounting extensions folder: ${extFolder} -> /extensions`));
|
|
163
|
+
// Build the container command as an argv array (runArgs → execFileSync, no
|
|
164
|
+
// shell). The folder paths below come from config and are operator-writable via
|
|
165
|
+
// the settings API, so they must never reach a shell as a string.
|
|
166
|
+
const dockerArgs = ['run', '-d', '--name', CONTAINER, '--network', runtime.defaultNetwork];
|
|
167
|
+
for (const opt of runtime.securityOpts)
|
|
168
|
+
dockerArgs.push('--security-opt', opt);
|
|
169
|
+
dockerArgs.push('-e', `HUDDLE_RUNTIME=${runtime.name}`);
|
|
170
|
+
dockerArgs.push('-e', `HUDDLE_OPERATOR_TOKEN=${operatorToken}`);
|
|
171
|
+
dockerArgs.push('-p', `${HOST_PORT}:3000`);
|
|
172
|
+
dockerArgs.push('-v', `${VOLUME}:/data`);
|
|
173
|
+
dockerArgs.push('-v', `${runtime.socketPath}:/var/run/docker.sock`);
|
|
174
|
+
dockerArgs.push('-v', `${hostTmpSockets}:/tmp/dc-sockets`);
|
|
175
|
+
dockerArgs.push('-v', `${config_1.CONFIG_DIR}:/huddle-home:rw`, '-e', 'HUDDLE_HOME_DIR=/huddle-home');
|
|
176
|
+
if (fwFolder)
|
|
177
|
+
dockerArgs.push('-v', `${fwFolder}:/firewall-rules:rw`);
|
|
178
|
+
if (extFolder)
|
|
179
|
+
dockerArgs.push('-v', `${extFolder}:/extensions:ro`);
|
|
180
|
+
dockerArgs.push(...(0, images_1.gatewayEnvArgs)(images));
|
|
181
|
+
dockerArgs.push(IMAGE);
|
|
182
|
+
runArgs(rt, dockerArgs);
|
|
160
183
|
// Attaching devcontainer-net after the container has started pollutes
|
|
161
184
|
// resolv.conf on Podman with that network's internal aardvark-DNS; the
|
|
162
185
|
// gateway cleans that up itself (see dns-egress.ts / the startup sanitize in
|
|
163
186
|
// index.ts).
|
|
164
|
-
|
|
187
|
+
runArgsSilent(rt, ['network', 'connect', exports.INTERNAL_NET, CONTAINER]);
|
|
165
188
|
console.log();
|
|
166
189
|
console.log((0, utils_1.green)(`[OK] Huddle is running at http://localhost:${HOST_PORT}`));
|
|
167
190
|
console.log();
|
package/dist/migrate.js
CHANGED
|
@@ -292,67 +292,76 @@ function rejectUnsupportedYaml(lines) {
|
|
|
292
292
|
throw unsupportedYaml('a YAML alias (`*`)');
|
|
293
293
|
}
|
|
294
294
|
}
|
|
295
|
+
function atIndent(c, indent) {
|
|
296
|
+
return c.pos < c.lines.length && c.lines[c.pos].indent === indent;
|
|
297
|
+
}
|
|
298
|
+
// Cap the mutual recursion (parseNode ↔ parseMapping/parseSequence) so a deeply
|
|
299
|
+
// nested (malformed or hostile) compose file cannot exhaust the stack (CWE-674).
|
|
300
|
+
function parseNode(c, indent, depth) {
|
|
301
|
+
if (depth > MAX_YAML_DEPTH) {
|
|
302
|
+
throw new Error(`YAML nesting exceeds ${MAX_YAML_DEPTH} levels; refusing to parse this compose file.`);
|
|
303
|
+
}
|
|
304
|
+
if (c.pos >= c.lines.length || c.lines[c.pos].indent < indent)
|
|
305
|
+
return null;
|
|
306
|
+
return isSeqItem(c.lines[c.pos].text) ? parseSequence(c, indent, depth) : parseMapping(c, indent, depth);
|
|
307
|
+
}
|
|
308
|
+
function parseMapping(c, indent, depth) {
|
|
309
|
+
const map = {};
|
|
310
|
+
while (atIndent(c, indent) && !isSeqItem(c.lines[c.pos].text)) {
|
|
311
|
+
const { text } = c.lines[c.pos];
|
|
312
|
+
const colon = findKeyColon(text);
|
|
313
|
+
// Not a mapping line where we expected one — stop and let the caller cope.
|
|
314
|
+
if (colon < 0)
|
|
315
|
+
break;
|
|
316
|
+
const key = unquote(text.slice(0, colon).trim());
|
|
317
|
+
const rest = text.slice(colon + 1).trim();
|
|
318
|
+
c.pos++;
|
|
319
|
+
map[key] = parseMappingValue(c, rest, indent, depth);
|
|
320
|
+
}
|
|
321
|
+
return map;
|
|
322
|
+
}
|
|
323
|
+
/** The value belonging to `key:` — inline, the indented block below it, or none. */
|
|
324
|
+
function parseMappingValue(c, rest, indent, depth) {
|
|
325
|
+
if (rest !== '')
|
|
326
|
+
return parseScalar(rest);
|
|
327
|
+
if (c.pos < c.lines.length && c.lines[c.pos].indent > indent) {
|
|
328
|
+
return parseNode(c, c.lines[c.pos].indent, depth + 1);
|
|
329
|
+
}
|
|
330
|
+
return null;
|
|
331
|
+
}
|
|
332
|
+
function parseSequence(c, indent, depth) {
|
|
333
|
+
const arr = [];
|
|
334
|
+
while (atIndent(c, indent) && isSeqItem(c.lines[c.pos].text)) {
|
|
335
|
+
arr.push(parseSequenceItem(c, indent, depth));
|
|
336
|
+
}
|
|
337
|
+
return arr;
|
|
338
|
+
}
|
|
339
|
+
function parseSequenceItem(c, indent, depth) {
|
|
340
|
+
const line = c.lines[c.pos];
|
|
341
|
+
const afterDash = line.text.replace(/^-\s*/, '');
|
|
342
|
+
// A bare `-`: the item is the indented block on the following lines.
|
|
343
|
+
if (afterDash === '') {
|
|
344
|
+
c.pos++;
|
|
345
|
+
return c.pos < c.lines.length && c.lines[c.pos].indent > indent
|
|
346
|
+
? parseNode(c, c.lines[c.pos].indent, depth + 1)
|
|
347
|
+
: null;
|
|
348
|
+
}
|
|
349
|
+
// Inline map item: "- key: value". Re-interpret the remainder as a mapping
|
|
350
|
+
// that starts at a virtual indent past the dash. parseMapping consumes this
|
|
351
|
+
// same line, so the cursor deliberately does not advance here.
|
|
352
|
+
if (findKeyColon(afterDash) >= 0) {
|
|
353
|
+
const virtualIndent = indent + (line.text.length - afterDash.length);
|
|
354
|
+
c.lines[c.pos] = { indent: virtualIndent, text: afterDash };
|
|
355
|
+
return parseMapping(c, virtualIndent, depth + 1);
|
|
356
|
+
}
|
|
357
|
+
c.pos++;
|
|
358
|
+
return parseScalar(afterDash);
|
|
359
|
+
}
|
|
295
360
|
function parseYaml(input) {
|
|
296
361
|
const lines = tokenize(input);
|
|
297
362
|
rejectUnsupportedYaml(lines);
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
// nested (malformed or hostile) compose file cannot exhaust the stack (CWE-674).
|
|
301
|
-
function parseNode(indent, depth) {
|
|
302
|
-
if (depth > MAX_YAML_DEPTH) {
|
|
303
|
-
throw new Error(`YAML nesting exceeds ${MAX_YAML_DEPTH} levels; refusing to parse this compose file.`);
|
|
304
|
-
}
|
|
305
|
-
if (pos >= lines.length || lines[pos].indent < indent)
|
|
306
|
-
return null;
|
|
307
|
-
return isSeqItem(lines[pos].text) ? parseSequence(indent, depth) : parseMapping(indent, depth);
|
|
308
|
-
}
|
|
309
|
-
function parseMapping(indent, depth) {
|
|
310
|
-
const map = {};
|
|
311
|
-
while (pos < lines.length && lines[pos].indent === indent && !isSeqItem(lines[pos].text)) {
|
|
312
|
-
const { text } = lines[pos];
|
|
313
|
-
const colon = findKeyColon(text);
|
|
314
|
-
if (colon < 0) {
|
|
315
|
-
// Not a mapping line where we expected one — stop and let the caller cope.
|
|
316
|
-
break;
|
|
317
|
-
}
|
|
318
|
-
const key = unquote(text.slice(0, colon).trim());
|
|
319
|
-
const rest = text.slice(colon + 1).trim();
|
|
320
|
-
pos++;
|
|
321
|
-
if (rest !== '') {
|
|
322
|
-
map[key] = parseScalar(rest);
|
|
323
|
-
}
|
|
324
|
-
else if (pos < lines.length && lines[pos].indent > indent) {
|
|
325
|
-
map[key] = parseNode(lines[pos].indent, depth + 1);
|
|
326
|
-
}
|
|
327
|
-
else {
|
|
328
|
-
map[key] = null;
|
|
329
|
-
}
|
|
330
|
-
}
|
|
331
|
-
return map;
|
|
332
|
-
}
|
|
333
|
-
function parseSequence(indent, depth) {
|
|
334
|
-
const arr = [];
|
|
335
|
-
while (pos < lines.length && lines[pos].indent === indent && isSeqItem(lines[pos].text)) {
|
|
336
|
-
const afterDash = lines[pos].text.replace(/^-\s*/, '');
|
|
337
|
-
if (afterDash === '') {
|
|
338
|
-
pos++;
|
|
339
|
-
arr.push(pos < lines.length && lines[pos].indent > indent ? parseNode(lines[pos].indent, depth + 1) : null);
|
|
340
|
-
}
|
|
341
|
-
else if (findKeyColon(afterDash) >= 0) {
|
|
342
|
-
// Inline map item: "- key: value". Re-interpret the remainder as a
|
|
343
|
-
// mapping that starts at a virtual indent past the dash.
|
|
344
|
-
const virtualIndent = indent + (lines[pos].text.length - afterDash.length);
|
|
345
|
-
lines[pos] = { indent: virtualIndent, text: afterDash };
|
|
346
|
-
arr.push(parseMapping(virtualIndent, depth + 1));
|
|
347
|
-
}
|
|
348
|
-
else {
|
|
349
|
-
arr.push(parseScalar(afterDash));
|
|
350
|
-
pos++;
|
|
351
|
-
}
|
|
352
|
-
}
|
|
353
|
-
return arr;
|
|
354
|
-
}
|
|
355
|
-
const root = parseNode(lines.length ? lines[0].indent : 0, 0);
|
|
363
|
+
const cursor = { lines, pos: 0 };
|
|
364
|
+
const root = parseNode(cursor, lines.length ? lines[0].indent : 0, 0);
|
|
356
365
|
return (root && typeof root === 'object' ? root : {});
|
|
357
366
|
}
|
|
358
367
|
function isSeqItem(text) {
|
package/dist/start.js
CHANGED
|
@@ -10,12 +10,47 @@ const api_1 = require("./api");
|
|
|
10
10
|
const utils_1 = require("./utils");
|
|
11
11
|
async function runStart(opts) {
|
|
12
12
|
const ide = parseIde(opts.ide);
|
|
13
|
-
const
|
|
14
|
-
|
|
13
|
+
const hasMounts = !!opts.mounts && opts.mounts.length > 0;
|
|
14
|
+
if (hasMounts && opts.workspace) {
|
|
15
|
+
throw new Error('Cannot combine --workspace with --mount; use --mount for every folder instead.');
|
|
16
|
+
}
|
|
17
|
+
if (hasMounts && opts.empty) {
|
|
18
|
+
throw new Error('Cannot combine --empty with --mount.');
|
|
19
|
+
}
|
|
20
|
+
const resolvedMounts = hasMounts
|
|
21
|
+
? opts.mounts.map((m) => ({ hostPath: resolveWorkspace(m.hostPath), containerPath: validateContainerPath(m.containerPath) }))
|
|
22
|
+
: undefined;
|
|
23
|
+
if (resolvedMounts) {
|
|
24
|
+
const seen = new Set();
|
|
25
|
+
for (const m of resolvedMounts) {
|
|
26
|
+
if (seen.has(m.containerPath))
|
|
27
|
+
throw new Error(`Duplicate --mount container path: ${m.containerPath}`);
|
|
28
|
+
seen.add(m.containerPath);
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
const workspaceRoot = opts.workspaceRoot?.trim() || undefined;
|
|
32
|
+
if (workspaceRoot && !hasMounts) {
|
|
33
|
+
throw new Error('--workspace-root requires at least one --mount.');
|
|
34
|
+
}
|
|
35
|
+
if (workspaceRoot && !workspaceRoot.startsWith('/')) {
|
|
36
|
+
throw new Error(`--workspace-root must be an absolute container path: "${workspaceRoot}".`);
|
|
37
|
+
}
|
|
38
|
+
const workspaceDir = opts.empty || hasMounts ? undefined : resolveWorkspace(opts.workspace);
|
|
39
|
+
const baseName = opts.empty
|
|
40
|
+
? 'empty'
|
|
41
|
+
: hasMounts
|
|
42
|
+
? (resolvedMounts[0].containerPath.split('/').filter(Boolean).pop() ?? 'workspace')
|
|
43
|
+
: path_1.default.basename(workspaceDir);
|
|
15
44
|
const containerName = opts.name ? validateContainerName(opts.name) : defaultContainerName(baseName);
|
|
16
45
|
console.log(`Starting ${(0, utils_1.bold)(containerName)} with ${(0, utils_1.bold)(ide)}...`);
|
|
17
46
|
if (workspaceDir)
|
|
18
47
|
console.log((0, utils_1.dim)(`Workspace: ${workspaceDir}`));
|
|
48
|
+
if (resolvedMounts) {
|
|
49
|
+
for (const m of resolvedMounts)
|
|
50
|
+
console.log((0, utils_1.dim)(`Mount ${m.hostPath} -> ${m.containerPath}`));
|
|
51
|
+
if (workspaceRoot)
|
|
52
|
+
console.log((0, utils_1.dim)(`Open IDE at: ${workspaceRoot}`));
|
|
53
|
+
}
|
|
19
54
|
let imageName = opts.image;
|
|
20
55
|
if (!imageName) {
|
|
21
56
|
const res = await (0, api_1.get)(`/api/docker/base-image?ide=${encodeURIComponent(ide)}`);
|
|
@@ -30,6 +65,11 @@ async function runStart(opts) {
|
|
|
30
65
|
if (opts.empty) {
|
|
31
66
|
body.empty = true;
|
|
32
67
|
}
|
|
68
|
+
else if (resolvedMounts) {
|
|
69
|
+
body.mounts = resolvedMounts;
|
|
70
|
+
if (workspaceRoot)
|
|
71
|
+
body.containerWorkspace = workspaceRoot;
|
|
72
|
+
}
|
|
33
73
|
else {
|
|
34
74
|
body.workspaceDir = workspaceDir;
|
|
35
75
|
}
|
|
@@ -79,6 +119,13 @@ function validateContainerName(name) {
|
|
|
79
119
|
}
|
|
80
120
|
return trimmed;
|
|
81
121
|
}
|
|
122
|
+
function validateContainerPath(path) {
|
|
123
|
+
const trimmed = (path ?? '').replace(/\\/g, '/').replace(/\/+$/, '').trim();
|
|
124
|
+
if (!trimmed.startsWith('/')) {
|
|
125
|
+
throw new Error(`Invalid --mount container path: "${path}". Use an absolute path, e.g. /workspace/backend.`);
|
|
126
|
+
}
|
|
127
|
+
return trimmed;
|
|
128
|
+
}
|
|
82
129
|
function parseIde(value) {
|
|
83
130
|
const normalized = value.toLowerCase().replace(/[ _-]+/g, '');
|
|
84
131
|
if (normalized === 'rider')
|