@infosupport/huddle-cli 0.0.0-experiment-136.72.1 → 0.0.0-experiment-98.74.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 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,10 +110,11 @@ 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
65
- --no-vscode-config
66
118
  -i, --interactive
67
119
  --container <name>
68
120
  --status <requested|allow|deny>
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.writeConfig = writeConfig;
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
- const CONFIG_DIR = path_1.default.join(os_1.default.homedir(), '.huddle');
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
- function writeConfig(config) {
29
- fs_1.default.mkdirSync(CONFIG_DIR, { recursive: true });
30
- fs_1.default.writeFileSync(CONFIG_PATH, `${JSON.stringify(config, null, 2)}\n`);
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() {
@@ -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.writeConfig)({ ...previous, channel: 'experiment', experiment: issue });
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
- (0, config_1.writeConfig)(previous);
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
- delete config.experiment;
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 rotating
60
- // GUID). Defaults to 'allow'; with --deny a block rule. Without --container the
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.gatewayEnvFlags = gatewayEnvFlags;
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` flags for the gateway container. During an experiment (or with an
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 gatewayEnvFlags(resolved) {
27
- return resolved.baseImages
28
- .filter((b) => b.gatewayEnv && (resolved.experiment !== undefined || process.env[b.gatewayEnv]))
29
- .map((b) => ` -e ${b.gatewayEnv}=${b.image}`)
30
- .join('');
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
  }