@infosupport/huddle-cli 0.0.0-experiment-109.66.1 → 0.0.0-experiment-56.68.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 +1 -59
- package/dist/api.js +14 -52
- package/dist/config.js +6 -145
- package/dist/experiment.js +7 -18
- package/dist/firewall.js +3 -168
- package/dist/images.js +8 -16
- package/dist/index.js +17 -222
- package/dist/init.js +84 -372
- package/dist/migrate.js +75 -120
- package/dist/start.js +2 -49
- package/package.json +3 -11
- package/dist/control-address.js +0 -160
- package/dist/control-probe.js +0 -174
- package/dist/logs.js +0 -213
- package/dist/node.js +0 -667
- package/dist/sbx-host-ca.js +0 -237
- package/dist/sbx-host.js +0 -36
- package/dist/sbx.js +0 -206
package/README.md
CHANGED
|
@@ -25,66 +25,11 @@ 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
|
|
29
28
|
huddle fw list
|
|
30
29
|
huddle firewall list -i
|
|
31
30
|
```
|
|
32
31
|
|
|
33
|
-
|
|
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
|
-
|
|
45
|
-
Default API URL: `http://localhost:24842` — Huddle Node, on the host. Override it with
|
|
46
|
-
`--url` or `HUDDLE_URL`.
|
|
47
|
-
|
|
48
|
-
## Selecting host folders in the portal
|
|
49
|
-
|
|
50
|
-
A browser cannot hand a server a folder path, so every host-path field in the portal
|
|
51
|
-
grows a **Browse** button that opens Huddle's own folder dialog — starting a
|
|
52
|
-
devcontainer, the folder mappings, and the team-managed folders. Ctrl-click picks
|
|
53
|
-
several folders at once when starting a devcontainer, and each becomes its own
|
|
54
|
-
worktree.
|
|
55
|
-
|
|
56
|
-
It browses your host live: Huddle Node runs there and lists one folder per request as
|
|
57
|
-
you open them, so a project you cloned a minute ago is simply in the list. There is
|
|
58
|
-
nothing to index and no CLI command to run first. Hidden (dot) folders are listed too,
|
|
59
|
-
and every input keeps accepting a path you type or paste.
|
|
60
|
-
|
|
61
|
-
Windows paths may be typed either way (`T:\projects\app` or `T:/projects/app`) —
|
|
62
|
-
Huddle stores one canonical form, so the two spellings are the same folder.
|
|
63
|
-
|
|
64
|
-
## Starting sandboxes (Docker Sandboxes / sbx)
|
|
65
|
-
|
|
66
|
-
```bash
|
|
67
|
-
huddle sbx start # sandbox for the current directory
|
|
68
|
-
huddle sbx start my-box --workspace T:\projects\app # a specific folder
|
|
69
|
-
huddle sbx start my-box \
|
|
70
|
-
--workspace T:\projects\app \
|
|
71
|
-
--folder T:\projects\shared-lib \
|
|
72
|
-
--folder T:\docs:ro # extra folders, one read-only
|
|
73
|
-
```
|
|
74
|
-
|
|
75
|
-
`--workspace <path>` is the folder the agent starts in. `--folder <host path>` adds
|
|
76
|
-
another folder and is **repeatable**; append `:ro` to mount that folder read-only.
|
|
77
|
-
Unlike `--mount` for devcontainers there is no container path to choose: sbx mounts
|
|
78
|
-
every folder inside the sandbox at the same path it has on the host (a Windows path
|
|
79
|
-
`T:\projects\app` becomes `/t/projects/app`).
|
|
80
|
-
|
|
81
|
-
The **folder mappings** from Settings (the settings folders devcontainers get, e.g.
|
|
82
|
-
`~/.claude`) are added to every sandbox automatically: each one rides along as an
|
|
83
|
-
extra folder and is then linked at the path the agent reads it from. An existing
|
|
84
|
-
folder in the sandbox is never overwritten — only its missing entries are linked in,
|
|
85
|
-
so the agent credentials sbx manages itself stay untouched. Mappings that cannot
|
|
86
|
-
travel (a Docker volume, or a `~`/relative host path) are reported per sandbox
|
|
87
|
-
instead of silently dropped.
|
|
32
|
+
Default API URL: `http://localhost:3000`. Override it with `--url` or `HUDDLE_URL`.
|
|
88
33
|
|
|
89
34
|
## Experiments
|
|
90
35
|
|
|
@@ -114,9 +59,6 @@ Main flags:
|
|
|
114
59
|
```text
|
|
115
60
|
--ide <intellij|rider|vscode>
|
|
116
61
|
--workspace <path>
|
|
117
|
-
--mount <host>=<container> (repeatable, container path must be absolute)
|
|
118
|
-
--workspace-root <path> (container path the IDE opens; requires --mount)
|
|
119
|
-
--folder <host path>[:ro] (repeatable; extra sandbox folder for `huddle sbx start`)
|
|
120
62
|
--name <name>
|
|
121
63
|
--image <image>
|
|
122
64
|
--empty
|
package/dist/api.js
CHANGED
|
@@ -4,29 +4,7 @@ exports.del = exports.put = exports.post = exports.get = exports.ApiError = void
|
|
|
4
4
|
exports.setBaseUrl = setBaseUrl;
|
|
5
5
|
exports.apiCall = apiCall;
|
|
6
6
|
const config_1 = require("./config");
|
|
7
|
-
|
|
8
|
-
// Huddle Node, on the host, on loopback. Not 3000 and not a container address:
|
|
9
|
-
// after the Node/Gateway split the API this talks to is the host process, and
|
|
10
|
-
// the gateway container has no API at all (docs/ADR-huddle-node-split.md).
|
|
11
|
-
//
|
|
12
|
-
// The loopback LITERALS, not `localhost` — nodeProbeUrls() is where that reason
|
|
13
|
-
// is written down. Both are kept, not just the first: Node binds one address and
|
|
14
|
-
// which one depends on the host, so the only honest default is to try each and
|
|
15
|
-
// keep whichever answers.
|
|
16
|
-
//
|
|
17
|
-
// An explicit --url or HUDDLE_URL replaces the list entirely — the operator named
|
|
18
|
-
// an address, and silently talking to a different one would be worse than failing.
|
|
19
|
-
//
|
|
20
|
-
// HUDDLE_PORT, when set, still has to flow through here: it is the same env var
|
|
21
|
-
// `huddle init`/`huddle node` read for a custom port (init.ts's HOST_PORT), so a
|
|
22
|
-
// custom port that stuck for the command that started Huddle Node must also
|
|
23
|
-
// stick for every command that talks to it afterwards — otherwise every command
|
|
24
|
-
// after `HUDDLE_PORT=<n> huddle init` probes the default port and never finds it.
|
|
25
|
-
const port = process.env.HUDDLE_PORT?.trim() || node_1.DEFAULT_NODE_PORT;
|
|
26
|
-
let candidates = (process.env.HUDDLE_URL
|
|
27
|
-
? [process.env.HUDDLE_URL]
|
|
28
|
-
: (0, node_1.nodeProbeUrls)(port)).map(normalizeBaseUrl);
|
|
29
|
-
let baseUrl = candidates[0];
|
|
7
|
+
let baseUrl = normalizeBaseUrl(process.env.HUDDLE_URL ?? 'http://localhost:3000');
|
|
30
8
|
class ApiError extends Error {
|
|
31
9
|
status;
|
|
32
10
|
constructor(message, status) {
|
|
@@ -37,30 +15,7 @@ class ApiError extends Error {
|
|
|
37
15
|
}
|
|
38
16
|
exports.ApiError = ApiError;
|
|
39
17
|
function setBaseUrl(url) {
|
|
40
|
-
|
|
41
|
-
baseUrl = candidates[0];
|
|
42
|
-
}
|
|
43
|
-
/**
|
|
44
|
-
* The first candidate that answers, remembered for the rest of the process.
|
|
45
|
-
*
|
|
46
|
-
* A refused connection is not a failure here — it is how we find out which
|
|
47
|
-
* loopback address Node bound. Anything the server actually answers, including a
|
|
48
|
-
* 500, ends the search: it proves we found Huddle.
|
|
49
|
-
*/
|
|
50
|
-
async function reachHuddle(path, init) {
|
|
51
|
-
const order = [baseUrl, ...candidates.filter((c) => c !== baseUrl)];
|
|
52
|
-
let detail = '';
|
|
53
|
-
for (const candidate of order) {
|
|
54
|
-
try {
|
|
55
|
-
const res = await fetch(`${candidate}${path}`, init);
|
|
56
|
-
baseUrl = candidate;
|
|
57
|
-
return res;
|
|
58
|
-
}
|
|
59
|
-
catch (err) {
|
|
60
|
-
detail = err instanceof Error ? err.message : String(err);
|
|
61
|
-
}
|
|
62
|
-
}
|
|
63
|
-
throw new ApiError(`Cannot reach Huddle API at ${order.join(' or ')}: ${detail}`);
|
|
18
|
+
baseUrl = normalizeBaseUrl(url);
|
|
64
19
|
}
|
|
65
20
|
async function apiCall(method, path, body) {
|
|
66
21
|
const headers = {};
|
|
@@ -71,11 +26,18 @@ async function apiCall(method, path, body) {
|
|
|
71
26
|
const token = (0, config_1.operatorToken)();
|
|
72
27
|
if (token)
|
|
73
28
|
headers['authorization'] = `Bearer ${token}`;
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
29
|
+
let res;
|
|
30
|
+
try {
|
|
31
|
+
res = await fetch(`${baseUrl}${path}`, {
|
|
32
|
+
method,
|
|
33
|
+
headers,
|
|
34
|
+
body: body !== undefined ? JSON.stringify(body) : undefined,
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
catch (err) {
|
|
38
|
+
const detail = err instanceof Error ? err.message : String(err);
|
|
39
|
+
throw new ApiError(`Cannot reach Huddle API at ${baseUrl}: ${detail}`);
|
|
40
|
+
}
|
|
79
41
|
const raw = await res.text();
|
|
80
42
|
const payload = parsePayload(raw);
|
|
81
43
|
if (!res.ok) {
|
package/dist/config.js
CHANGED
|
@@ -3,19 +3,17 @@ 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;
|
|
7
6
|
exports.configPath = configPath;
|
|
8
7
|
exports.readConfig = readConfig;
|
|
9
|
-
exports.
|
|
8
|
+
exports.writeConfig = writeConfig;
|
|
10
9
|
exports.operatorToken = operatorToken;
|
|
11
10
|
exports.activeExperiment = activeExperiment;
|
|
12
11
|
exports.imageTag = imageTag;
|
|
13
12
|
const fs_1 = __importDefault(require("fs"));
|
|
14
|
-
const crypto_1 = require("crypto");
|
|
15
13
|
const os_1 = __importDefault(require("os"));
|
|
16
14
|
const path_1 = __importDefault(require("path"));
|
|
17
|
-
|
|
18
|
-
const CONFIG_PATH = path_1.default.join(
|
|
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');
|
|
19
17
|
function configPath() {
|
|
20
18
|
return CONFIG_PATH;
|
|
21
19
|
}
|
|
@@ -27,146 +25,9 @@ function readConfig() {
|
|
|
27
25
|
return {};
|
|
28
26
|
}
|
|
29
27
|
}
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
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
|
-
}
|
|
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`);
|
|
170
31
|
}
|
|
171
32
|
/** Operator-token voor API-auth: env wint, anders uit de config. */
|
|
172
33
|
function operatorToken() {
|
package/dist/experiment.js
CHANGED
|
@@ -34,12 +34,6 @@ 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;
|
|
43
37
|
const wanted = (0, config_1.activeExperiment)();
|
|
44
38
|
// Normally we only switch when the experiment NUMBER differs — otherwise every
|
|
45
39
|
// command would reinstall. But `huddle experiment use <n>` must pick up a newer
|
|
@@ -63,7 +57,7 @@ function ensureCliForChannel(relaunchArgs, opts = {}) {
|
|
|
63
57
|
*/
|
|
64
58
|
async function runExperimentUse(issue, initOpts = {}) {
|
|
65
59
|
const previous = (0, config_1.readConfig)();
|
|
66
|
-
(0, config_1.
|
|
60
|
+
(0, config_1.writeConfig)({ ...previous, channel: 'experiment', experiment: issue });
|
|
67
61
|
console.log((0, utils_1.green)(`Experiment ${issue} activated`) + (0, utils_1.dim)(` (${(0, config_1.configPath)()})`));
|
|
68
62
|
const relaunchArgs = ['init', ...(initOpts.runtime ? ['--runtime', initOpts.runtime] : [])];
|
|
69
63
|
try {
|
|
@@ -73,27 +67,22 @@ async function runExperimentUse(issue, initOpts = {}) {
|
|
|
73
67
|
}
|
|
74
68
|
catch (err) {
|
|
75
69
|
// Activation failed → roll back the config so a subsequent `huddle init`
|
|
76
|
-
// doesn't stay stuck on an experiment that cannot be installed.
|
|
77
|
-
|
|
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
|
-
}
|
|
70
|
+
// doesn't stay stuck on an experiment that cannot be installed.
|
|
71
|
+
(0, config_1.writeConfig)(previous);
|
|
86
72
|
throw err;
|
|
87
73
|
}
|
|
88
74
|
await (0, init_1.runInit)(initOpts, (0, images_1.resolveImages)());
|
|
89
75
|
}
|
|
90
76
|
/** Puts Huddle back on the stable release. */
|
|
91
77
|
async function runExperimentReset() {
|
|
78
|
+
const config = (0, config_1.readConfig)();
|
|
92
79
|
if ((0, config_1.activeExperiment)() === undefined && cliExperiment() === undefined) {
|
|
93
80
|
console.log('No experiment active; Huddle is already running on stable.');
|
|
94
81
|
return;
|
|
95
82
|
}
|
|
96
|
-
|
|
83
|
+
delete config.experiment;
|
|
84
|
+
config.channel = 'stable';
|
|
85
|
+
(0, config_1.writeConfig)(config);
|
|
97
86
|
console.log((0, utils_1.green)('Experiment config removed') + (0, utils_1.dim)(` (${(0, config_1.configPath)()})`));
|
|
98
87
|
// If an experimental CLI is still running, this installs the stable version
|
|
99
88
|
// and the new CLI restarts itself to show the status.
|
package/dist/firewall.js
CHANGED
|
@@ -1,18 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
3
|
exports.runFirewallList = runFirewallList;
|
|
7
4
|
exports.runFirewallAdd = runFirewallAdd;
|
|
8
5
|
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"));
|
|
14
6
|
const api_1 = require("./api");
|
|
15
|
-
const config_1 = require("./config");
|
|
16
7
|
const utils_1 = require("./utils");
|
|
17
8
|
async function runFirewallList(opts) {
|
|
18
9
|
const qs = new URLSearchParams({ status: opts.status ?? 'requested' });
|
|
@@ -65,9 +56,9 @@ async function resolveRule(rule, status, scope) {
|
|
|
65
56
|
}
|
|
66
57
|
// Creates a custom firewall rule. Supports wildcards: `*.` in the domain
|
|
67
58
|
// (e.g. `*.pkgs.dev.azure.com`) and `*` in the path pattern (e.g.
|
|
68
|
-
// `/_packaging/*/nuget/v3/*` for an Azure DevOps feed with a
|
|
69
|
-
// GUID). Defaults to 'allow'; --deny
|
|
70
|
-
//
|
|
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.
|
|
71
62
|
async function runFirewallAdd(opts) {
|
|
72
63
|
const domain = (opts.domain ?? '').trim();
|
|
73
64
|
if (!domain) {
|
|
@@ -144,159 +135,3 @@ function printRulesTable(rules) {
|
|
|
144
135
|
function formatTarget(rule) {
|
|
145
136
|
return rule.path_pattern ? `${rule.domain}${rule.path_pattern}` : rule.domain;
|
|
146
137
|
}
|
|
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.
|
|
4
|
+
exports.gatewayEnvFlags = gatewayEnvFlags;
|
|
5
5
|
const config_1 = require("./config");
|
|
6
6
|
function resolveImages() {
|
|
7
7
|
const experiment = (0, config_1.activeExperiment)();
|
|
@@ -19,21 +19,13 @@ function resolveImages() {
|
|
|
19
19
|
};
|
|
20
20
|
}
|
|
21
21
|
/**
|
|
22
|
-
*
|
|
23
|
-
*
|
|
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
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.
|
|
30
25
|
*/
|
|
31
|
-
function
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
return env;
|
|
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('');
|
|
39
31
|
}
|