@infosupport/huddle-cli 0.0.0-experiment-128.65.1 → 0.0.0-experiment-109.66.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.
@@ -34,6 +34,12 @@ function parseIssueNumber(raw) {
34
34
  * function does not return (process.exit with the exit code of the new process).
35
35
  */
36
36
  function ensureCliForChannel(relaunchArgs, opts = {}) {
37
+ // Escape hatch for locally-built CLIs (e.g. dev-install.sh):
38
+ // when we deliberately run THIS build we must not hop to the published channel
39
+ // CLI — that would discard local, unpublished changes. The active experiment
40
+ // config is left untouched; only the auto-switch is suppressed for this run.
41
+ if (process.env.HUDDLE_SKIP_CLI_SWITCH === '1')
42
+ return;
37
43
  const wanted = (0, config_1.activeExperiment)();
38
44
  // Normally we only switch when the experiment NUMBER differs — otherwise every
39
45
  // command would reinstall. But `huddle experiment use <n>` must pick up a newer
@@ -57,7 +63,7 @@ function ensureCliForChannel(relaunchArgs, opts = {}) {
57
63
  */
58
64
  async function runExperimentUse(issue, initOpts = {}) {
59
65
  const previous = (0, config_1.readConfig)();
60
- (0, config_1.writeConfig)({ ...previous, channel: 'experiment', experiment: issue });
66
+ (0, config_1.updateConfig)({ channel: 'experiment', experiment: issue });
61
67
  console.log((0, utils_1.green)(`Experiment ${issue} activated`) + (0, utils_1.dim)(` (${(0, config_1.configPath)()})`));
62
68
  const relaunchArgs = ['init', ...(initOpts.runtime ? ['--runtime', initOpts.runtime] : [])];
63
69
  try {
@@ -67,22 +73,27 @@ async function runExperimentUse(issue, initOpts = {}) {
67
73
  }
68
74
  catch (err) {
69
75
  // 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);
76
+ // doesn't stay stuck on an experiment that cannot be installed. Only the two
77
+ // keys this function set are restored; anything the gateway wrote to the
78
+ // shared file meanwhile (folder mappings, resource defaults) stays put.
79
+ try {
80
+ (0, config_1.updateConfig)({ channel: previous.channel, experiment: previous.experiment });
81
+ }
82
+ catch (rollbackErr) {
83
+ // The rollback is a courtesy; never let it mask why activation failed.
84
+ console.error((0, utils_1.dim)(`Could not roll back ${(0, config_1.configPath)()}: ${rollbackErr.message}`));
85
+ }
72
86
  throw err;
73
87
  }
74
88
  await (0, init_1.runInit)(initOpts, (0, images_1.resolveImages)());
75
89
  }
76
90
  /** Puts Huddle back on the stable release. */
77
91
  async function runExperimentReset() {
78
- const config = (0, config_1.readConfig)();
79
92
  if ((0, config_1.activeExperiment)() === undefined && cliExperiment() === undefined) {
80
93
  console.log('No experiment active; Huddle is already running on stable.');
81
94
  return;
82
95
  }
83
- delete config.experiment;
84
- config.channel = 'stable';
85
- (0, config_1.writeConfig)(config);
96
+ (0, config_1.updateConfig)({ channel: 'stable', experiment: undefined });
86
97
  console.log((0, utils_1.green)('Experiment config removed') + (0, utils_1.dim)(` (${(0, config_1.configPath)()})`));
87
98
  // If an experimental CLI is still running, this installs the stable version
88
99
  // 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,159 @@ 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
+ async function runFirewallImport(opts) {
181
+ const doc = readJsonFile(opts.file);
182
+ const mode = opts.replace ? 'replace' : 'merge';
183
+ const qs = new URLSearchParams();
184
+ if (opts.container)
185
+ qs.set('container', opts.container);
186
+ const suffix = qs.toString() ? `?${qs}` : '';
187
+ const res = await (0, api_1.post)(`/api/rules/import${suffix}`, { mode, rules: doc.rules });
188
+ console.error((0, utils_1.green)(`[OK] Imported (${mode}): ${res.imported} added, ${res.updated} updated, ${res.skipped} skipped`));
189
+ }
190
+ async function resolveGroupByName(name) {
191
+ const groups = await (0, api_1.get)('/api/groups');
192
+ const match = groups.filter((g) => g.name.toLowerCase() === name.toLowerCase());
193
+ if (match.length === 0)
194
+ throw new Error(`No group named "${name}". Run \`huddle firewall group list\`.`);
195
+ return match[0];
196
+ }
197
+ async function runFirewallGroup(opts) {
198
+ const action = opts.action ?? 'list';
199
+ if (action === 'list') {
200
+ const groups = await (0, api_1.get)('/api/groups');
201
+ if (groups.length === 0) {
202
+ console.log((0, utils_1.dim)('No firewall groups yet.'));
203
+ return;
204
+ }
205
+ const headers = ['ID', 'Name', 'Rules', 'Shared', 'Source'];
206
+ const rows = groups.map((g) => [String(g.id), g.name, String(g.rule_count), g.shared ? 'yes' : 'no', g.source]);
207
+ (0, utils_1.printTable)(headers, rows);
208
+ return;
209
+ }
210
+ if (action === 'export') {
211
+ const name = (opts.arg ?? '').trim();
212
+ if (!name)
213
+ throw new Error('Usage: huddle firewall group export <name> [--out <file>]');
214
+ const g = await resolveGroupByName(name);
215
+ const env = await (0, api_1.get)(`/api/groups/${g.id}/export`);
216
+ const json = JSON.stringify(env, null, 2);
217
+ if (opts.out) {
218
+ fs_1.default.writeFileSync(opts.out, `${json}\n`);
219
+ console.error((0, utils_1.green)(`[OK] Exported group "${g.name}" to ${opts.out}`));
220
+ }
221
+ else {
222
+ console.log(json);
223
+ }
224
+ return;
225
+ }
226
+ if (action === 'import') {
227
+ const file = (opts.arg ?? '').trim();
228
+ if (!file)
229
+ throw new Error('Usage: huddle firewall group import <file> [--replace]');
230
+ const envelope = readJsonFile(file);
231
+ const mode = opts.replace ? 'replace' : 'merge';
232
+ const res = await (0, api_1.post)('/api/groups/import', { mode, envelope });
233
+ console.error((0, utils_1.green)(`[OK] Imported group "${res.group.name}" (${mode}): ${res.imported} added, ${res.updated} updated, ${res.skipped} skipped`));
234
+ return;
235
+ }
236
+ if (action === 'apply') {
237
+ const name = (opts.arg ?? '').trim();
238
+ if (!name)
239
+ throw new Error('Usage: huddle firewall group apply <name> [--container <id>]');
240
+ const g = await resolveGroupByName(name);
241
+ const container = opts.container ?? null;
242
+ const res = await (0, api_1.post)(`/api/groups/${g.id}/apply`, { container });
243
+ const scope = container ? `container ${container}` : 'global';
244
+ console.log((0, utils_1.green)(`[OK] Applied "${g.name}" to ${scope}: ${res.applied} added, ${res.updated} updated`));
245
+ return;
246
+ }
247
+ throw new Error(`Unknown group action: ${action}. Use list | export | import | apply.`);
248
+ }
249
+ async function runFirewallFolder(opts) {
250
+ const action = opts.action ?? 'show';
251
+ if (action === 'show') {
252
+ // The CLI config is the source of truth for the path.
253
+ const folder = (0, config_1.readConfig)().firewallRulesFolder;
254
+ console.log(folder ? folder : (0, utils_1.dim)('(no firewall rules folder configured)'));
255
+ return;
256
+ }
257
+ if (action === 'set') {
258
+ const path = (opts.path ?? '').trim();
259
+ if (!path)
260
+ throw new Error('Usage: huddle firewall folder set <path>');
261
+ // Config-only: Huddle Node reads this file per call, so the new folder is
262
+ // live immediately — no remount, no restart.
263
+ (0, config_1.updateConfig)({ firewallRulesFolder: path });
264
+ console.log((0, utils_1.green)(`[OK] Firewall rules folder set to ${(0, utils_1.cyan)(path)}`));
265
+ console.log((0, utils_1.dim)(' Read on start and on `huddle firewall folder reload`.'));
266
+ return;
267
+ }
268
+ if (action === 'reload') {
269
+ const res = await (0, api_1.post)('/api/firewall-rules-folder/reload', {});
270
+ if (!res.mounted) {
271
+ console.log((0, utils_1.dim)(res.folder
272
+ ? `Cannot read ${res.folder} — set an existing folder with \`huddle firewall folder set <path>\`.`
273
+ : 'No firewall rules folder configured. Set one with `huddle firewall folder set <path>`.'));
274
+ return;
275
+ }
276
+ console.log((0, utils_1.green)(`[OK] Reloaded: ${res.groups} group(s), ${res.imported} rule(s), ${res.errors.length} error(s)`));
277
+ for (const e of res.errors)
278
+ console.error((0, utils_1.red)(` [!] ${e.file}: ${e.message}`));
279
+ return;
280
+ }
281
+ if (action === 'sync') {
282
+ // Write the portal's groups back out to the folder (app → files).
283
+ const res = await (0, api_1.post)('/api/firewall-rules-folder/sync', {});
284
+ if (!res.mounted) {
285
+ console.log((0, utils_1.dim)(res.folder
286
+ ? `Cannot read ${res.folder} — set an existing folder with \`huddle firewall folder set <path>\`.`
287
+ : 'No firewall rules folder configured. Set one with `huddle firewall folder set <path>`.'));
288
+ return;
289
+ }
290
+ if (res.written === 0 && res.errors.length > 0) {
291
+ console.error((0, utils_1.red)('[!] Could not write to the folder — check that Huddle Node may write there.'));
292
+ for (const e of res.errors)
293
+ console.error((0, utils_1.red)(` [!] ${e.file}: ${e.message}`));
294
+ return;
295
+ }
296
+ console.log((0, utils_1.green)(`[OK] Synced: ${res.written} group(s) written, ${res.pruned} stale file(s) removed, ${res.errors.length} error(s)`));
297
+ for (const e of res.errors)
298
+ console.error((0, utils_1.red)(` [!] ${e.file}: ${e.message}`));
299
+ return;
300
+ }
301
+ throw new Error(`Unknown folder action: ${action}. Use show | set | reload | sync.`);
302
+ }
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.baseImageEnv = baseImageEnv;
5
5
  const config_1 = require("./config");
6
6
  function resolveImages() {
7
7
  const experiment = (0, config_1.activeExperiment)();
@@ -19,13 +19,21 @@ 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
22
+ * Base-image overrides for HUDDLE NODE's environment. During an experiment (or
23
+ * with an explicit override) Huddle Node must start devcontainers from the same
24
24
  * base images the CLI just pulled.
25
+ *
26
+ * These went to the gateway container as `-e` pairs until Docker orchestration
27
+ * moved to the host (docs/ADR-huddle-node-split.md). The gateway does not create
28
+ * containers any more, so it has no use for them — and giving the network-facing
29
+ * half env vars it does not read is how stale coupling survives a split.
25
30
  */
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('');
31
+ function baseImageEnv(resolved) {
32
+ const env = {};
33
+ for (const b of resolved.baseImages) {
34
+ if (b.gatewayEnv && (resolved.experiment !== undefined || process.env[b.gatewayEnv])) {
35
+ env[b.gatewayEnv] = b.image;
36
+ }
37
+ }
38
+ return env;
31
39
  }
package/dist/index.js CHANGED
@@ -4,23 +4,29 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
4
4
  return (mod && mod.__esModule) ? mod : { "default": mod };
5
5
  };
6
6
  Object.defineProperty(exports, "__esModule", { value: true });
7
+ exports.parseArgs = parseArgs;
7
8
  const fs_1 = __importDefault(require("fs"));
8
9
  const path_1 = __importDefault(require("path"));
9
10
  const api_1 = require("./api");
10
11
  const start_1 = require("./start");
11
12
  const firewall_1 = require("./firewall");
12
13
  const init_1 = require("./init");
14
+ const node_1 = require("./node");
13
15
  const migrate_1 = require("./migrate");
16
+ const logs_1 = require("./logs");
17
+ const sbx_1 = require("./sbx");
14
18
  const images_1 = require("./images");
15
19
  const self_update_1 = require("./self-update");
16
20
  const utils_1 = require("./utils");
17
21
  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']);
22
+ const VALUE_FLAGS = new Set(['url', 'ide', 'name', 'image', 'workspace', 'container', 'status', 'runtime', 'experiment', 'path', 'ca-path', 'output', 'out', 'workspace-root', 'agent', 'entry', 'port', 'data-dir', 'lines', 'n']);
23
+ const BOOLEAN_FLAGS = new Set(['help', 'h', 'empty', 'i', 'interactive', 'version', 'v', 'deny', 'docker-socket', 'force', 'replace', 'dry-run', 'follow', 'f', 'node', 'gateway']);
24
+ const COMMANDS = new Set(['start', 'firewall', 'fw', 'init', 'restart', 'experiment', 'migrate', 'sbx', 'node', 'logs', 'log', 'help', 'version']);
21
25
  function parseArgs(argv) {
22
26
  const positional = [];
23
27
  const flags = {};
28
+ const mounts = [];
29
+ const folders = [];
24
30
  for (let i = 0; i < argv.length; i++) {
25
31
  const arg = argv[i];
26
32
  if (arg === '--') {
@@ -33,6 +39,25 @@ function parseArgs(argv) {
33
39
  const name = eq >= 0 ? raw.slice(0, eq) : raw;
34
40
  if (!name)
35
41
  throw new Error(`Invalid option: ${arg}`);
42
+ // Repeatable, unlike every other value flag (one `--mount host=container` or
43
+ // one `--folder <host path>` per folder).
44
+ if (name === 'mount' || name === 'folder') {
45
+ const expects = name === 'mount' ? 'host=container' : 'a host path';
46
+ let value;
47
+ if (eq >= 0) {
48
+ value = raw.slice(eq + 1);
49
+ }
50
+ else {
51
+ const next = argv[i + 1];
52
+ if (next === undefined || next.startsWith('-')) {
53
+ throw new Error(`Option --${name} expects a value (${expects})`);
54
+ }
55
+ value = next;
56
+ i++;
57
+ }
58
+ (name === 'mount' ? mounts : folders).push(value);
59
+ continue;
60
+ }
36
61
  if (eq >= 0) {
37
62
  flags[name] = raw.slice(eq + 1);
38
63
  }
@@ -70,7 +95,13 @@ function parseArgs(argv) {
70
95
  }
71
96
  positional.push(arg);
72
97
  }
73
- return { positional, flags };
98
+ return { positional, flags, mounts, folders };
99
+ }
100
+ function parseMountFlag(raw) {
101
+ const eq = raw.indexOf('=');
102
+ if (eq <= 0)
103
+ throw new Error(`Invalid --mount value "${raw}", expected host=container`);
104
+ return { hostPath: raw.slice(0, eq), containerPath: raw.slice(eq + 1) };
74
105
  }
75
106
  function readVersion() {
76
107
  // npm always includes package.json in the published tarball, and it holds the
@@ -94,6 +125,8 @@ Usage:
94
125
  huddle start [options] [folder] Explicitly start a devcontainer
95
126
  huddle init [options] Pull the Huddle + devcontainer base images and
96
127
  start them via Docker or Podman
128
+ huddle restart Recreate the gateway (e.g. after changing the
129
+ team extensions folder, which loads at boot)
97
130
  huddle migrate [folder] Wire an existing docker-compose devcontainer
98
131
  behind Huddle by generating an override file
99
132
  huddle firewall list [options] Show firewall requests
@@ -102,11 +135,57 @@ Usage:
102
135
  supported: *.example.com and /path/*)
103
136
  huddle firewall delete <id> Delete a firewall rule by id (or domain;
104
137
  narrow with --container)
138
+ huddle firewall export [options] Export firewall rules as JSON
139
+ huddle firewall import <file> Import firewall rules from a JSON file
140
+ huddle firewall group list List firewall groups (#69)
141
+ huddle firewall group export <name> Export a group as JSON (--out <file>)
142
+ huddle firewall group import <file> Import a group (--replace to mirror)
143
+ huddle firewall group apply <name> Apply a group (--container <id> or global)
144
+ huddle sbx status Show Docker Sandboxes (sbx) mode status:
145
+ host-agent pipe, upstream proxy, sbx version
146
+ huddle sbx list List sandboxes the host sbx daemon knows
147
+ huddle sbx start [name] [options] Start a microVM sandbox with Huddle as its
148
+ upstream proxy (--agent <name> --workspace <path>)
149
+ --folder <host path>[:ro] adds another folder
150
+ (repeatable); Huddle's folder mappings are
151
+ mounted automatically
152
+ huddle sbx rm <name> [--force] Remove a sandbox
153
+ huddle sbx reconcile [--dry-run] Set every Huddle sandbox to allow-all in sbx
154
+ (Huddle's proxy enforces the rules)
155
+ huddle sbx trust-ca <name> Install Huddle's CA in a sandbox so HTTPS
156
+ works (needed for VS Code / JetBrains backends)
157
+ huddle sbx trust-host Trust Huddle's CA on the HOST, where the sbx
158
+ daemon runs — sbx terminates TLS itself for
159
+ some hosts (platform.claude.com) and then
160
+ validates Huddle against the host store; without
161
+ this those calls fail with "Empty reply from
162
+ server". Run by 'huddle init'; idempotent.
163
+ huddle sbx ssh-setup Enable the SSH bridge (<name>.sbx) for
164
+ VS Code / JetBrains remote development
165
+ huddle firewall folder set <path> Set the team-managed rules folder
166
+ huddle firewall folder reload Re-read the team-managed rules folder
167
+ huddle firewall folder sync Write the portal's groups back to the folder
168
+ huddle logs [options] Show both halves' output: Huddle Node's log
169
+ file on this host and the gateway container
170
+ (-n <lines>, -f to follow, --node/--gateway
171
+ for one half)
172
+ huddle node [options] Run Huddle Node (portal + API + orchestration)
173
+ directly on this host instead of in the
174
+ gateway container. The firewall stays in
175
+ huddle-gateway. Foreground; Ctrl-C to stop.
105
176
  huddle experiment use <nr> Activate the experimental build of issue/PR <nr>
106
177
  and run init
107
178
  huddle experiment reset Back to the stable release
108
179
  huddle experiment status Show the active channel and CLI version
109
180
 
181
+ Node options:
182
+ --entry <path> Path to the built Huddle Node entrypoint
183
+ (default: the gateway build in this checkout;
184
+ also via HUDDLE_NODE_ENTRY)
185
+ --port <port> Portal + API port (default: 24842)
186
+ --data-dir <path> Database, CA and config location
187
+ (default: ~/.huddle)
188
+
110
189
  Init options:
111
190
  --runtime <docker|podman> Container runtime (default: auto-detected;
112
191
  also via the HUDDLE_RUNTIME env var)
@@ -116,6 +195,11 @@ Init options:
116
195
  Start options:
117
196
  --ide <intellij|rider|vscode> IDE (default: intellij)
118
197
  --workspace <path> Workspace directory (default: current directory)
198
+ --mount <host>=<container> Mount a host folder at an absolute container path, e.g.
199
+ C:/projects/my-repo/backend=/workspace/backend
200
+ (repeatable; cannot combine with --workspace/--empty)
201
+ --workspace-root <path> Container path the IDE opens as project root when using
202
+ --mount (default: common parent of the mount targets)
119
203
  --name <name> Container name (default: devcontainer-<foldername>)
120
204
  --image <image> Use a specific image
121
205
  --empty Empty container without a workspace
@@ -123,8 +207,9 @@ Start options:
123
207
  Migrate options:
124
208
  --ca-path <path> Where the Huddle CA lands in the container
125
209
  (NODE_EXTRA_CA_CERTS; default /home/vscode/.huddle-ca.crt)
126
- --docker-socket Also wire the filtered Docker socket + DOCKER_HOST
127
- (requires gateway socket pre-provisioning; see docs)
210
+ --docker-socket Also wire the filtered Docker socket + DOCKER_HOST;
211
+ registers the container(s) with Huddle Node so the
212
+ socket exists before "docker compose up" starts them
128
213
  --output <path> Override file to write
129
214
  (default: docker-compose.huddle.yml next to the source)
130
215
  --force Overwrite an existing override file
@@ -132,6 +217,8 @@ Migrate options:
132
217
  Firewall options:
133
218
  -i, --interactive Interactively approve/deny (list)
134
219
  --container <name> Filter by (list) / scope to (add) a container
220
+ (or __global__). On import: remap all rules
221
+ to this scope
135
222
  --status <requested|allow|deny> Filter by status (default: requested)
136
223
 
137
224
  Firewall add options:
@@ -140,8 +227,13 @@ Firewall add options:
140
227
  (e.g. /_packaging/*/nuget/v3/*)
141
228
  --deny Create a block rule (default: allow)
142
229
 
230
+ Firewall export/import options:
231
+ --out <file> Write export to a file (default: stdout)
232
+ --replace Import in replace mode: wipe the target
233
+ scope first (default: merge/upsert)
234
+
143
235
  Global options:
144
- --url <url> Huddle URL (default: http://localhost:3000)
236
+ --url <url> Huddle URL (default: http://localhost:24842)
145
237
  Or via the HUDDLE_URL env var
146
238
  --help, -h Show help
147
239
  --version, -v Show version (as published to
@@ -158,7 +250,7 @@ async function main() {
158
250
  console.error('Run "huddle --help" for help.');
159
251
  process.exit(1);
160
252
  }
161
- const { positional, flags } = parsed;
253
+ const { positional, flags, mounts } = parsed;
162
254
  const [cmd, sub] = positional;
163
255
  if (flagBool(flags, 'version', 'v') || cmd === 'version') {
164
256
  console.log(readVersion());
@@ -168,8 +260,16 @@ async function main() {
168
260
  printHelp();
169
261
  return;
170
262
  }
171
- const url = flagString(flags, 'url') ?? process.env.HUDDLE_URL ?? 'http://localhost:3000';
172
- (0, api_1.setBaseUrl)(url);
263
+ // Only when the operator named an address. The fallback used to be nodeUrl(),
264
+ // which is the URL for a HUMAN — `http://localhost:…` — and that is the one
265
+ // spelling the CLI must not use: Node binds a single literal, `localhost` is
266
+ // two, and on Windows it resolves to ::1 first. A browser papers over that,
267
+ // fetch() does not, so every command failed with "Huddle does not appear to be
268
+ // running" against a healthy process the portal was talking to happily.
269
+ // Leaving this unset lets api.ts try the loopback literals instead.
270
+ const url = flagString(flags, 'url') ?? process.env.HUDDLE_URL;
271
+ if (url)
272
+ (0, api_1.setBaseUrl)(url);
173
273
  const startsWithExistingPath = cmd !== undefined && !COMMANDS.has(cmd) && fs_1.default.existsSync(path_1.default.resolve(cmd));
174
274
  if (!cmd || cmd === 'start' || startsWithExistingPath) {
175
275
  const startArgs = cmd === 'start' ? positional.slice(1) : startsWithExistingPath ? positional : [];
@@ -179,12 +279,25 @@ async function main() {
179
279
  await (0, start_1.runStart)({
180
280
  ide: flagString(flags, 'ide') ?? 'intellij',
181
281
  workspace: flagString(flags, 'workspace') ?? startArgs[0],
282
+ mounts: mounts.length ? mounts.map(parseMountFlag) : undefined,
283
+ workspaceRoot: flagString(flags, 'workspace-root'),
182
284
  name: flagString(flags, 'name'),
183
285
  image: flagString(flags, 'image'),
184
286
  empty: flagBool(flags, 'empty'),
185
287
  });
186
288
  return;
187
289
  }
290
+ if (cmd === 'node') {
291
+ // Runs Huddle Node in the FOREGROUND on this host — the shape you want
292
+ // while working on Huddle itself. `huddle init` starts the same process
293
+ // detached, alongside the gateway container.
294
+ await (0, node_1.runNode)({
295
+ entry: flagString(flags, 'entry'),
296
+ port: flagString(flags, 'port'),
297
+ dataDir: flagString(flags, 'data-dir'),
298
+ });
299
+ return;
300
+ }
188
301
  if (cmd === 'init') {
189
302
  // Shows the exact CLI build, so with experiments it's immediately visible
190
303
  // which version is running.
@@ -202,6 +315,15 @@ async function main() {
202
315
  await (0, init_1.runInit)(initOpts, (0, images_1.resolveImages)());
203
316
  return;
204
317
  }
318
+ if (cmd === 'restart') {
319
+ // Stop + recreate the gateway (runInit does `rm -f` first) so changed team
320
+ // folders get mounted. The portal writes the paths straight into the mounted
321
+ // ~/.huddle/config.json, so runInit already reads the latest values here.
322
+ const initOpts = { runtime: flagString(flags, 'runtime') };
323
+ (0, experiment_1.ensureCliForChannel)(process.argv.slice(2));
324
+ await (0, init_1.runInit)(initOpts, (0, images_1.resolveImages)());
325
+ return;
326
+ }
205
327
  if (cmd === 'experiment') {
206
328
  const subCmd = sub ?? 'status';
207
329
  if (subCmd === 'use') {
@@ -243,12 +365,92 @@ async function main() {
243
365
  container: flagString(flags, 'container'),
244
366
  });
245
367
  }
368
+ else if (subCmd === 'export') {
369
+ await (0, firewall_1.runFirewallExport)({
370
+ container: flagString(flags, 'container'),
371
+ out: flagString(flags, 'out'),
372
+ });
373
+ }
374
+ else if (subCmd === 'import') {
375
+ const file = positional[2];
376
+ if (!file) {
377
+ console.error('Usage: huddle firewall import <file> [--replace] [--container <id>]');
378
+ process.exit(1);
379
+ }
380
+ await (0, firewall_1.runFirewallImport)({
381
+ file,
382
+ replace: flagBool(flags, 'replace'),
383
+ container: flagString(flags, 'container'),
384
+ });
385
+ }
386
+ else if (subCmd === 'group' || subCmd === 'groups') {
387
+ await (0, firewall_1.runFirewallGroup)({
388
+ action: positional[2],
389
+ arg: positional[3],
390
+ out: flagString(flags, 'out'),
391
+ replace: flagBool(flags, 'replace'),
392
+ container: flagString(flags, 'container'),
393
+ });
394
+ }
395
+ else if (subCmd === 'folder') {
396
+ await (0, firewall_1.runFirewallFolder)({ action: positional[2], path: positional[3] });
397
+ }
246
398
  else {
247
399
  console.error(`Unknown firewall subcommand: ${subCmd}`);
248
400
  process.exit(1);
249
401
  }
250
402
  return;
251
403
  }
404
+ if (cmd === 'logs' || cmd === 'log') {
405
+ await (0, logs_1.runLogs)({
406
+ lines: flagString(flags, 'lines', 'n'),
407
+ follow: flagBool(flags, 'follow', 'f'),
408
+ node: flagBool(flags, 'node'),
409
+ gateway: flagBool(flags, 'gateway'),
410
+ });
411
+ return;
412
+ }
413
+ if (cmd === 'sbx') {
414
+ const subCmd = sub ?? 'status';
415
+ if (subCmd === 'status') {
416
+ await (0, sbx_1.runSbxStatus)();
417
+ }
418
+ else if (subCmd === 'list' || subCmd === 'ls') {
419
+ await (0, sbx_1.runSbxList)();
420
+ }
421
+ else if (subCmd === 'start' || subCmd === 'create') {
422
+ await (0, sbx_1.runSbxStart)({
423
+ name: positional[2] ?? flagString(flags, 'name'),
424
+ agent: flagString(flags, 'agent'),
425
+ workspace: flagString(flags, 'workspace'),
426
+ folders: parsed.folders,
427
+ });
428
+ }
429
+ else if (subCmd === 'rm' || subCmd === 'remove' || subCmd === 'delete') {
430
+ await (0, sbx_1.runSbxRemove)({ name: positional[2] ?? flagString(flags, 'name'), force: flagBool(flags, 'force') });
431
+ }
432
+ else if (subCmd === 'reconcile' || subCmd === 'sync') {
433
+ await (0, sbx_1.runSbxReconcile)({ dryRun: flagBool(flags, 'dry-run') });
434
+ }
435
+ else if (subCmd === 'trust-ca' || subCmd === 'ca') {
436
+ await (0, sbx_1.runSbxTrustCa)({ name: positional[2] ?? flagString(flags, 'name') });
437
+ }
438
+ else if (subCmd === 'trust-host' || subCmd === 'host-ca') {
439
+ await (0, sbx_1.runSbxTrustHost)({ runtime: flagString(flags, 'runtime') });
440
+ }
441
+ else if (subCmd === 'log') {
442
+ await (0, sbx_1.runSbxLog)({ name: positional[2] ?? flagString(flags, 'name') });
443
+ }
444
+ else if (subCmd === 'ssh-setup' || subCmd === 'ssh') {
445
+ await (0, sbx_1.runSbxSshSetup)();
446
+ }
447
+ else {
448
+ console.error(`Unknown sbx subcommand: ${subCmd}`);
449
+ console.error('Usage: huddle sbx <status|list|start|rm|reconcile|trust-ca|trust-host|ssh-setup|log>');
450
+ process.exit(1);
451
+ }
452
+ return;
453
+ }
252
454
  if (cmd === 'migrate') {
253
455
  await (0, migrate_1.runMigrate)({
254
456
  path: positional[1],
@@ -275,10 +477,13 @@ function flagString(flags, ...names) {
275
477
  function flagBool(flags, ...names) {
276
478
  return names.some((name) => flags[name] === true);
277
479
  }
278
- main().catch((err) => {
279
- console.error(`Error: ${err.message ?? err}`);
280
- if (err instanceof api_1.ApiError && err.message.includes('Cannot reach Huddle API')) {
281
- console.error('\nHuddle does not appear to be running. Start it with:\n huddle init');
282
- }
283
- process.exit(1);
284
- });
480
+ // Guarded so the arg parser above can be imported by tests without the CLI
481
+ // running itself as a side effect of the import.
482
+ if (require.main === module)
483
+ main().catch((err) => {
484
+ console.error(`Error: ${err.message ?? err}`);
485
+ if (err instanceof api_1.ApiError && err.message.includes('Cannot reach Huddle API')) {
486
+ console.error('\nHuddle does not appear to be running. Start it with:\n huddle init');
487
+ }
488
+ process.exit(1);
489
+ });