@infosupport/huddle-cli 0.0.0-experiment-98.52.1 → 0.0.0-experiment-109.54.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +37 -32
- package/dist/api.js +45 -14
- package/dist/control-address.js +160 -0
- package/dist/control-probe.js +174 -0
- package/dist/experiment.js +6 -0
- package/dist/firewall.js +10 -6
- package/dist/images.js +13 -9
- package/dist/index.js +139 -45
- package/dist/init.js +354 -89
- package/dist/logs.js +213 -0
- package/dist/migrate.js +53 -17
- package/dist/node.js +534 -0
- package/dist/sbx-host-ca.js +237 -0
- package/dist/sbx-host.js +36 -0
- package/dist/sbx.js +211 -0
- package/package.json +11 -3
- package/dist/indexfolder.js +0 -167
package/README.md
CHANGED
|
@@ -42,45 +42,49 @@ huddle --ide vscode \
|
|
|
42
42
|
--workspace-root /workspaces --name corpa-dev
|
|
43
43
|
```
|
|
44
44
|
|
|
45
|
-
Default API URL: `http://localhost:
|
|
45
|
+
Default API URL: `http://localhost:24842` — Huddle Node, on the host. Override it with
|
|
46
|
+
`--url` or `HUDDLE_URL`.
|
|
46
47
|
|
|
47
|
-
##
|
|
48
|
+
## Selecting host folders in the portal
|
|
48
49
|
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
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)
|
|
57
65
|
|
|
58
66
|
```bash
|
|
59
|
-
|
|
60
|
-
huddle
|
|
61
|
-
huddle
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
huddle indexfolder --clear # empty the index (with a folder: only that subtree)
|
|
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
|
|
66
73
|
```
|
|
67
74
|
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
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.
|
|
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`).
|
|
79
80
|
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
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.
|
|
84
88
|
|
|
85
89
|
## Experiments
|
|
86
90
|
|
|
@@ -112,6 +116,7 @@ Main flags:
|
|
|
112
116
|
--workspace <path>
|
|
113
117
|
--mount <host>=<container> (repeatable, container path must be absolute)
|
|
114
118
|
--workspace-root <path> (container path the IDE opens; requires --mount)
|
|
119
|
+
--folder <host path>[:ro] (repeatable; extra sandbox folder for `huddle sbx start`)
|
|
115
120
|
--name <name>
|
|
116
121
|
--image <image>
|
|
117
122
|
--empty
|
package/dist/api.js
CHANGED
|
@@ -4,7 +4,22 @@ 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
|
-
|
|
7
|
+
const node_1 = require("./node");
|
|
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
|
+
let candidates = (process.env.HUDDLE_URL
|
|
20
|
+
? [process.env.HUDDLE_URL]
|
|
21
|
+
: (0, node_1.nodeProbeUrls)(node_1.DEFAULT_NODE_PORT)).map(normalizeBaseUrl);
|
|
22
|
+
let baseUrl = candidates[0];
|
|
8
23
|
class ApiError extends Error {
|
|
9
24
|
status;
|
|
10
25
|
constructor(message, status) {
|
|
@@ -15,7 +30,30 @@ class ApiError extends Error {
|
|
|
15
30
|
}
|
|
16
31
|
exports.ApiError = ApiError;
|
|
17
32
|
function setBaseUrl(url) {
|
|
18
|
-
|
|
33
|
+
candidates = [normalizeBaseUrl(url)];
|
|
34
|
+
baseUrl = candidates[0];
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* The first candidate that answers, remembered for the rest of the process.
|
|
38
|
+
*
|
|
39
|
+
* A refused connection is not a failure here — it is how we find out which
|
|
40
|
+
* loopback address Node bound. Anything the server actually answers, including a
|
|
41
|
+
* 500, ends the search: it proves we found Huddle.
|
|
42
|
+
*/
|
|
43
|
+
async function reachHuddle(path, init) {
|
|
44
|
+
const order = [baseUrl, ...candidates.filter((c) => c !== baseUrl)];
|
|
45
|
+
let detail = '';
|
|
46
|
+
for (const candidate of order) {
|
|
47
|
+
try {
|
|
48
|
+
const res = await fetch(`${candidate}${path}`, init);
|
|
49
|
+
baseUrl = candidate;
|
|
50
|
+
return res;
|
|
51
|
+
}
|
|
52
|
+
catch (err) {
|
|
53
|
+
detail = err instanceof Error ? err.message : String(err);
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
throw new ApiError(`Cannot reach Huddle API at ${order.join(' or ')}: ${detail}`);
|
|
19
57
|
}
|
|
20
58
|
async function apiCall(method, path, body) {
|
|
21
59
|
const headers = {};
|
|
@@ -26,18 +64,11 @@ async function apiCall(method, path, body) {
|
|
|
26
64
|
const token = (0, config_1.operatorToken)();
|
|
27
65
|
if (token)
|
|
28
66
|
headers['authorization'] = `Bearer ${token}`;
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
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
|
-
}
|
|
67
|
+
const res = await reachHuddle(path, {
|
|
68
|
+
method,
|
|
69
|
+
headers,
|
|
70
|
+
body: body !== undefined ? JSON.stringify(body) : undefined,
|
|
71
|
+
});
|
|
41
72
|
const raw = await res.text();
|
|
42
73
|
const payload = parsePayload(raw);
|
|
43
74
|
if (!res.ok) {
|
|
@@ -0,0 +1,160 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// Where huddle-gateway finds Huddle Node.
|
|
3
|
+
//
|
|
4
|
+
// The gateway follows Huddle Node's control channel (policy in, decisions out).
|
|
5
|
+
// Node runs on the host now, so this is a container→host call, and how a
|
|
6
|
+
// container reaches its host is the one thing that genuinely differs per engine:
|
|
7
|
+
//
|
|
8
|
+
// Engine in a VM (Docker Desktop, Rancher, `podman machine`)
|
|
9
|
+
// `host.docker.internal` is routed to the real host, and a process bound
|
|
10
|
+
// to the host's LOOPBACK is reachable through it. Node keeps 127.0.0.1.
|
|
11
|
+
//
|
|
12
|
+
// Engine native on Linux (docker/podman on the same kernel)
|
|
13
|
+
// There is no such routing: the container sees the host only as the bridge
|
|
14
|
+
// gateway address (172.17.0.1 for Docker's `bridge`, 10.88.0.1 for
|
|
15
|
+
// Podman's `podman`). A loopback-bound listener is simply not reachable,
|
|
16
|
+
// so the control channel has to bind that address.
|
|
17
|
+
//
|
|
18
|
+
// Only the CONTROL channel moves. The portal and the REST API stay on loopback
|
|
19
|
+
// in both cases — they carry the operator token, which opens container
|
|
20
|
+
// terminals, execs and policy writes. The control channel carries a second,
|
|
21
|
+
// narrower token (gateway/src/auth.ts) and is the only thing worth exposing to
|
|
22
|
+
// the bridge. Devcontainers cannot reach even that: their network is `--internal`
|
|
23
|
+
// and has no route off itself.
|
|
24
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
25
|
+
exports.HOST_ALIAS = void 0;
|
|
26
|
+
exports.parseBridgeGateway = parseBridgeGateway;
|
|
27
|
+
exports.bridgeGateway = bridgeGateway;
|
|
28
|
+
exports.resolveControlAddress = resolveControlAddress;
|
|
29
|
+
const child_process_1 = require("child_process");
|
|
30
|
+
exports.HOST_ALIAS = 'host.docker.internal';
|
|
31
|
+
/**
|
|
32
|
+
* Pull the bridge gateway address out of `network inspect` JSON.
|
|
33
|
+
*
|
|
34
|
+
* Two shapes, because the engines disagree: Docker nests it under
|
|
35
|
+
* `IPAM.Config[].Gateway`, Podman under `subnets[].gateway`. Parsing the JSON
|
|
36
|
+
* rather than passing a Go template is what makes one code path serve both.
|
|
37
|
+
*
|
|
38
|
+
* Pure, so the shapes can be tested without an engine.
|
|
39
|
+
*/
|
|
40
|
+
function parseBridgeGateway(json) {
|
|
41
|
+
let parsed;
|
|
42
|
+
try {
|
|
43
|
+
parsed = JSON.parse(json);
|
|
44
|
+
}
|
|
45
|
+
catch {
|
|
46
|
+
return null;
|
|
47
|
+
}
|
|
48
|
+
const entry = Array.isArray(parsed) ? parsed[0] : parsed;
|
|
49
|
+
if (!entry || typeof entry !== 'object')
|
|
50
|
+
return null;
|
|
51
|
+
const docker = entry.IPAM?.Config;
|
|
52
|
+
const podman = entry.subnets;
|
|
53
|
+
const rows = Array.isArray(docker) ? docker : Array.isArray(podman) ? podman : [];
|
|
54
|
+
for (const row of rows) {
|
|
55
|
+
if (!row || typeof row !== 'object')
|
|
56
|
+
continue;
|
|
57
|
+
const value = row.Gateway
|
|
58
|
+
?? row.gateway;
|
|
59
|
+
if (typeof value === 'string' && isIpLiteral(value))
|
|
60
|
+
return value;
|
|
61
|
+
}
|
|
62
|
+
return null;
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* An IP literal and nothing else. This value ends up as a bind address and
|
|
66
|
+
* inside a `-e HUDDLE_NODE_CONTROL_URL=...` argument, and it comes from whatever
|
|
67
|
+
* the engine reports — so a hostname, a CIDR suffix or anything with a shell
|
|
68
|
+
* metacharacter in it is rejected rather than passed on.
|
|
69
|
+
*/
|
|
70
|
+
function isIpLiteral(value) {
|
|
71
|
+
const v = value.trim();
|
|
72
|
+
if (/^\d{1,3}(\.\d{1,3}){3}$/.test(v)) {
|
|
73
|
+
return v.split('.').every((o) => Number(o) <= 255);
|
|
74
|
+
}
|
|
75
|
+
return /^[0-9a-fA-F:]+$/.test(v) && v.includes(':');
|
|
76
|
+
}
|
|
77
|
+
/** Ask the engine for the default network's gateway address. Best-effort. */
|
|
78
|
+
function bridgeGateway(rt, network) {
|
|
79
|
+
try {
|
|
80
|
+
const out = (0, child_process_1.execFileSync)(rt, ['network', 'inspect', network], {
|
|
81
|
+
encoding: 'utf8',
|
|
82
|
+
stdio: ['ignore', 'pipe', 'ignore'],
|
|
83
|
+
timeout: 15_000,
|
|
84
|
+
});
|
|
85
|
+
return parseBridgeGateway(out);
|
|
86
|
+
}
|
|
87
|
+
catch {
|
|
88
|
+
return null;
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
/** Bracket a literal IPv6 host for use in a URL, the way every other http://host:port here does. */
|
|
92
|
+
function formatHost(host) {
|
|
93
|
+
return host.includes(':') && !host.startsWith('[') ? `[${host}]` : host;
|
|
94
|
+
}
|
|
95
|
+
/**
|
|
96
|
+
* Decide the pair (bind host, URL) from what we know about the engine. Pure —
|
|
97
|
+
* the engine probing happens in bridgeGateway() above.
|
|
98
|
+
*/
|
|
99
|
+
function resolveControlAddress(input) {
|
|
100
|
+
const override = input.override?.trim();
|
|
101
|
+
const bindOverride = input.bindOverride?.trim();
|
|
102
|
+
const derived = derive(input);
|
|
103
|
+
// HUDDLE_CONTROL_HOST moves where Node binds; unless HUDDLE_NODE_CONTROL_URL
|
|
104
|
+
// says otherwise too, the URL handed to the gateway has to move with it. Left
|
|
105
|
+
// pinned to the auto-derived URL, Node ends up listening on the overridden
|
|
106
|
+
// host while the gateway keeps probing the stale one — and being fail-closed,
|
|
107
|
+
// denies every request. HUDDLE_NODE_CONTROL_URL, when given, still wins: it is
|
|
108
|
+
// the more specific override and may legitimately name something other than
|
|
109
|
+
// the bind host (a different port, a tunnel, host.docker.internal itself).
|
|
110
|
+
const url = override || (bindOverride ? `http://${formatHost(bindOverride)}:${input.port}` : derived.url);
|
|
111
|
+
return {
|
|
112
|
+
...derived,
|
|
113
|
+
bindHost: bindOverride || derived.bindHost,
|
|
114
|
+
url,
|
|
115
|
+
reason: override || bindOverride
|
|
116
|
+
? 'set explicitly via HUDDLE_NODE_CONTROL_URL / HUDDLE_CONTROL_HOST'
|
|
117
|
+
: derived.reason,
|
|
118
|
+
// Whoever set it explicitly knows their own topology better than we do.
|
|
119
|
+
reachable: derived.reachable || !!override || !!bindOverride,
|
|
120
|
+
// Either override may name something other than the alias; adding a host
|
|
121
|
+
// entry for a name nobody asked about would be noise at best.
|
|
122
|
+
runArgs: (override || bindOverride) ? [] : derived.runArgs,
|
|
123
|
+
};
|
|
124
|
+
}
|
|
125
|
+
function derive(input) {
|
|
126
|
+
const { port } = input;
|
|
127
|
+
if (input.isRemote) {
|
|
128
|
+
return {
|
|
129
|
+
bindHost: '127.0.0.1',
|
|
130
|
+
url: `http://${exports.HOST_ALIAS}:${port}`,
|
|
131
|
+
// Docker Desktop provides the alias already; Podman machine and Rancher
|
|
132
|
+
// are less consistent about it, and asking for it twice costs nothing.
|
|
133
|
+
runArgs: ['--add-host', `${exports.HOST_ALIAS}:host-gateway`],
|
|
134
|
+
reason: 'the engine runs in a VM, so the host is reachable on its loopback',
|
|
135
|
+
reachable: true,
|
|
136
|
+
};
|
|
137
|
+
}
|
|
138
|
+
if (input.gatewayIp) {
|
|
139
|
+
return {
|
|
140
|
+
bindHost: input.gatewayIp,
|
|
141
|
+
url: `http://${formatHost(input.gatewayIp)}:${port}`,
|
|
142
|
+
runArgs: [],
|
|
143
|
+
reason: `native engine — the container reaches this host at ${input.gatewayIp}`,
|
|
144
|
+
reachable: true,
|
|
145
|
+
};
|
|
146
|
+
}
|
|
147
|
+
// Native engine, and we could not read the bridge address — so there is no
|
|
148
|
+
// address we can honestly name. Loopback is deliberate: 0.0.0.0 would put the
|
|
149
|
+
// control channel on the LAN and any VPN to fix a problem we have not even
|
|
150
|
+
// confirmed. The gateway then reaches nothing and, being fail-closed, denies
|
|
151
|
+
// every request until an operator sets HUDDLE_CONTROL_HOST. A visibly dead
|
|
152
|
+
// firewall beats a quietly widened one.
|
|
153
|
+
return {
|
|
154
|
+
bindHost: '127.0.0.1',
|
|
155
|
+
url: `http://${exports.HOST_ALIAS}:${port}`,
|
|
156
|
+
runArgs: ['--add-host', `${exports.HOST_ALIAS}:host-gateway`],
|
|
157
|
+
reason: 'the bridge gateway address could not be read from the engine',
|
|
158
|
+
reachable: false,
|
|
159
|
+
};
|
|
160
|
+
}
|
|
@@ -0,0 +1,174 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// Does the gateway container ACTUALLY reach Huddle Node?
|
|
3
|
+
//
|
|
4
|
+
// control-address.ts derives an answer from what the engine says it is. That
|
|
5
|
+
// derivation has one assumption in it — "engine in a VM ⇒ the host is reachable
|
|
6
|
+
// on its loopback via host.docker.internal" — and it is false on Rancher
|
|
7
|
+
// Desktop for Windows: the engine runs in a WSL distro, `host.docker.internal`
|
|
8
|
+
// resolves to that distro's docker0 gateway (172.17.0.1), and Huddle Node is a
|
|
9
|
+
// Windows process bound to the Windows loopback. The name resolves, nothing
|
|
10
|
+
// listens, and the gateway fails closed: every devcontainer is denied all egress
|
|
11
|
+
// and nothing is filed as `requested`, because a gateway with no policy is not
|
|
12
|
+
// allowed to invent one.
|
|
13
|
+
//
|
|
14
|
+
// A derivation cannot tell that apart from a working setup. A connection can.
|
|
15
|
+
// So init stops guessing: it starts Node, then opens the real connection from a
|
|
16
|
+
// throwaway container, and only trusts an address that answered.
|
|
17
|
+
//
|
|
18
|
+
// Split from control-address.ts because everything here SPAWNS — the pure
|
|
19
|
+
// decision stays testable without an engine, and the parsers below are exported
|
|
20
|
+
// for the same reason.
|
|
21
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
22
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
23
|
+
};
|
|
24
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
25
|
+
exports.parseProbeOutput = parseProbeOutput;
|
|
26
|
+
exports.probeControlUrl = probeControlUrl;
|
|
27
|
+
exports.parseDefaultGateway = parseDefaultGateway;
|
|
28
|
+
exports.engineHostAddress = engineHostAddress;
|
|
29
|
+
exports.hostCandidateUrls = hostCandidateUrls;
|
|
30
|
+
exports.localIpv4Addresses = localIpv4Addresses;
|
|
31
|
+
exports.pickBindAddress = pickBindAddress;
|
|
32
|
+
const child_process_1 = require("child_process");
|
|
33
|
+
const os_1 = __importDefault(require("os"));
|
|
34
|
+
/** How long any single engine call may take before we call it a failure. */
|
|
35
|
+
const PROBE_TIMEOUT_MS = 25_000;
|
|
36
|
+
/**
|
|
37
|
+
* Run the probe inside the gateway image itself.
|
|
38
|
+
*
|
|
39
|
+
* That image, not a stock one: it is already present (init just pulled or built
|
|
40
|
+
* it), so this costs no download, and it is the exact runtime the real gateway
|
|
41
|
+
* uses — same Node, same DNS resolution, same TLS stack.
|
|
42
|
+
*/
|
|
43
|
+
function runInImage(rt, image, runArgs, entrypoint, cmdArgs = []) {
|
|
44
|
+
try {
|
|
45
|
+
return (0, child_process_1.execFileSync)(rt, ['run', '--rm', '--entrypoint', entrypoint, ...runArgs, image, ...cmdArgs], { encoding: 'utf8', stdio: ['ignore', 'pipe', 'ignore'], timeout: PROBE_TIMEOUT_MS });
|
|
46
|
+
}
|
|
47
|
+
catch {
|
|
48
|
+
return null;
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
// The script the probe container runs. One line, because it travels as an argv
|
|
52
|
+
// entry through a shell on Windows. A 4s timeout of its own: an address that is
|
|
53
|
+
// silently dropped (a host firewall) must come back as a result, not as a hang.
|
|
54
|
+
const PROBE_SCRIPT = "fetch(process.env.PROBE_URL + '/control/health', { signal: AbortSignal.timeout(4000) })" +
|
|
55
|
+
".then(r => console.log('PROBE_HTTP ' + r.status))" +
|
|
56
|
+
".catch(e => console.log('PROBE_ERR ' + ((e.cause && e.cause.code) || e.name || e.message)))";
|
|
57
|
+
/**
|
|
58
|
+
* Read the probe container's single line of output.
|
|
59
|
+
*
|
|
60
|
+
* ANY HTTP status means reachable, and 401 is the expected one: /control/health
|
|
61
|
+
* is behind the gateway token and the probe deliberately sends none. What is
|
|
62
|
+
* being tested is whether the packets arrive, not whether we are authorised —
|
|
63
|
+
* the token is checked separately, and conflating the two is how "unreachable"
|
|
64
|
+
* ends up hiding a token mismatch.
|
|
65
|
+
*/
|
|
66
|
+
function parseProbeOutput(out) {
|
|
67
|
+
if (out === null)
|
|
68
|
+
return { reachable: false, detail: 'the probe container could not be started' };
|
|
69
|
+
const line = out.split('\n').map((l) => l.trim()).filter(Boolean).pop() ?? '';
|
|
70
|
+
const http = /^PROBE_HTTP (\d+)$/.exec(line);
|
|
71
|
+
if (http)
|
|
72
|
+
return { reachable: true, detail: `HTTP ${http[1]}` };
|
|
73
|
+
const err = /^PROBE_ERR (.+)$/.exec(line);
|
|
74
|
+
if (err)
|
|
75
|
+
return { reachable: false, detail: err[1] };
|
|
76
|
+
return { reachable: false, detail: line || 'no output' };
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* Open the control channel from where the gateway will open it: same image,
|
|
80
|
+
* same network, same --add-host arguments. Anything less tests a different path
|
|
81
|
+
* than the one that has to work.
|
|
82
|
+
*/
|
|
83
|
+
function probeControlUrl(rt, image, url, network, runArgs) {
|
|
84
|
+
const out = runInImage(rt, image, ['--network', network, ...runArgs, '-e', `PROBE_URL=${url}`], 'node', ['-e', PROBE_SCRIPT]);
|
|
85
|
+
return parseProbeOutput(out);
|
|
86
|
+
}
|
|
87
|
+
/**
|
|
88
|
+
* Pull the gateway out of `ip route show default`.
|
|
89
|
+
*
|
|
90
|
+
* Two shapes, since busybox and iproute2 order the fields differently:
|
|
91
|
+
* default via 172.20.144.1 dev eth0 proto kernel
|
|
92
|
+
* default dev eth0 scope link src 10.0.0.5 via 10.0.0.1
|
|
93
|
+
* so match on `via <ip>` wherever it sits rather than on a field position.
|
|
94
|
+
*/
|
|
95
|
+
function parseDefaultGateway(routeOutput) {
|
|
96
|
+
if (!routeOutput)
|
|
97
|
+
return null;
|
|
98
|
+
for (const line of routeOutput.split('\n')) {
|
|
99
|
+
if (!line.trim().startsWith('default'))
|
|
100
|
+
continue;
|
|
101
|
+
const via = /\bvia\s+(\d{1,3}(?:\.\d{1,3}){3})\b/.exec(line);
|
|
102
|
+
if (via && via[1].split('.').every((o) => Number(o) <= 255))
|
|
103
|
+
return via[1];
|
|
104
|
+
}
|
|
105
|
+
return null;
|
|
106
|
+
}
|
|
107
|
+
/**
|
|
108
|
+
* The address of the machine the ENGINE runs on, seen from inside the engine.
|
|
109
|
+
*
|
|
110
|
+
* `--network host` puts the probe in the engine host's own network namespace —
|
|
111
|
+
* the WSL distro on Rancher Desktop, the Linux VM elsewhere — so its default
|
|
112
|
+
* route names the next hop out of that namespace. On WSL that next hop is the
|
|
113
|
+
* Windows host, on the vEthernet adapter the two share, which is exactly the
|
|
114
|
+
* address a container can reach and `host.docker.internal` failed to name.
|
|
115
|
+
*
|
|
116
|
+
* Only worth asking when the derived address did not answer: on Docker Desktop
|
|
117
|
+
* this returns the VM's own internal gateway, which is not what anyone wants.
|
|
118
|
+
*/
|
|
119
|
+
function engineHostAddress(rt, image) {
|
|
120
|
+
return parseDefaultGateway(runInImage(rt, image, ['--network', 'host'], 'ip', ['-4', 'route', 'show', 'default']));
|
|
121
|
+
}
|
|
122
|
+
/**
|
|
123
|
+
* The other names and addresses a container might reach this machine on, tried
|
|
124
|
+
* only when the derived one did not answer.
|
|
125
|
+
*
|
|
126
|
+
* `host.docker.internal` is not a promise. Rancher Desktop points it at the
|
|
127
|
+
* WSL distro's own docker0 gateway, which is the distro, not this machine —
|
|
128
|
+
* measured, and it is what sent us here. So try the aliases other engines
|
|
129
|
+
* publish, and then the one address that is not a guess at all:
|
|
130
|
+
*
|
|
131
|
+
* Rancher Desktop and `podman machine` both route the VM through
|
|
132
|
+
* gvisor-tap-vsock, which serves 192.168.127.0/24 with the gateway on .1 and
|
|
133
|
+
* THIS MACHINE on .254 — a userspace forwarder running here, so it reaches the
|
|
134
|
+
* host loopback exactly like Docker Desktop's alias does. Derived from whatever
|
|
135
|
+
* gateway the engine reported rather than hardcoded, because the subnet is
|
|
136
|
+
* configurable.
|
|
137
|
+
*
|
|
138
|
+
* Every one of these is a candidate, not an answer: each is probed, and only an
|
|
139
|
+
* address that replies is used.
|
|
140
|
+
*/
|
|
141
|
+
function hostCandidateUrls(port, vmGateway) {
|
|
142
|
+
const hosts = ['host.rancher-desktop.internal', 'host.containers.internal'];
|
|
143
|
+
const octets = vmGateway ? /^(\d{1,3}\.\d{1,3}\.\d{1,3})\.\d{1,3}$/.exec(vmGateway) : null;
|
|
144
|
+
if (octets)
|
|
145
|
+
hosts.push(`${octets[1]}.254`);
|
|
146
|
+
return hosts.map((h) => `http://${h}:${port}`);
|
|
147
|
+
}
|
|
148
|
+
/** Every IPv4 address this machine actually has, loopback excluded. */
|
|
149
|
+
function localIpv4Addresses() {
|
|
150
|
+
const out = [];
|
|
151
|
+
for (const addrs of Object.values(os_1.default.networkInterfaces())) {
|
|
152
|
+
for (const a of addrs ?? []) {
|
|
153
|
+
if (a.family === 'IPv4' && !a.internal)
|
|
154
|
+
out.push(a.address);
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
return out;
|
|
158
|
+
}
|
|
159
|
+
/**
|
|
160
|
+
* An address Huddle Node can BIND that the engine can also reach.
|
|
161
|
+
*
|
|
162
|
+
* Both halves matter, and the second one is the trap: the engine's default
|
|
163
|
+
* gateway is not this machine. On Rancher Desktop it is 192.168.127.1, served by
|
|
164
|
+
* a forwarder — binding it fails with EADDRNOTAVAIL and takes Huddle Node down
|
|
165
|
+
* with it, which is exactly how a control-channel fix turned into no Huddle at
|
|
166
|
+
* all. So only ever offer an address this machine really owns, on the same
|
|
167
|
+
* subnet the engine routes through.
|
|
168
|
+
*/
|
|
169
|
+
function pickBindAddress(local, vmGateway) {
|
|
170
|
+
if (!vmGateway)
|
|
171
|
+
return null;
|
|
172
|
+
const prefix = vmGateway.replace(/\.\d+$/, '.');
|
|
173
|
+
return local.find((a) => a.startsWith(prefix)) ?? null;
|
|
174
|
+
}
|
package/dist/experiment.js
CHANGED
|
@@ -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
|
package/dist/firewall.js
CHANGED
|
@@ -258,17 +258,19 @@ async function runFirewallFolder(opts) {
|
|
|
258
258
|
const path = (opts.path ?? '').trim();
|
|
259
259
|
if (!path)
|
|
260
260
|
throw new Error('Usage: huddle firewall folder set <path>');
|
|
261
|
-
// Config-only:
|
|
262
|
-
//
|
|
261
|
+
// Config-only: Huddle Node reads this file per call, so the new folder is
|
|
262
|
+
// live immediately — no remount, no restart.
|
|
263
263
|
(0, config_1.updateConfig)({ firewallRulesFolder: path });
|
|
264
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)('
|
|
265
|
+
console.log((0, utils_1.dim)(' Read on start and on `huddle firewall folder reload`.'));
|
|
266
266
|
return;
|
|
267
267
|
}
|
|
268
268
|
if (action === 'reload') {
|
|
269
269
|
const res = await (0, api_1.post)('/api/firewall-rules-folder/reload', {});
|
|
270
270
|
if (!res.mounted) {
|
|
271
|
-
console.log((0, utils_1.dim)(
|
|
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>`.'));
|
|
272
274
|
return;
|
|
273
275
|
}
|
|
274
276
|
console.log((0, utils_1.green)(`[OK] Reloaded: ${res.groups} group(s), ${res.imported} rule(s), ${res.errors.length} error(s)`));
|
|
@@ -280,11 +282,13 @@ async function runFirewallFolder(opts) {
|
|
|
280
282
|
// Write the portal's groups back out to the folder (app → files).
|
|
281
283
|
const res = await (0, api_1.post)('/api/firewall-rules-folder/sync', {});
|
|
282
284
|
if (!res.mounted) {
|
|
283
|
-
console.log((0, utils_1.dim)(
|
|
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>`.'));
|
|
284
288
|
return;
|
|
285
289
|
}
|
|
286
290
|
if (res.written === 0 && res.errors.length > 0) {
|
|
287
|
-
console.error((0, utils_1.red)('[!] Could not write to the folder —
|
|
291
|
+
console.error((0, utils_1.red)('[!] Could not write to the folder — check that Huddle Node may write there.'));
|
|
288
292
|
for (const e of res.errors)
|
|
289
293
|
console.error((0, utils_1.red)(` [!] ${e.file}: ${e.message}`));
|
|
290
294
|
return;
|
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.baseImageEnv = baseImageEnv;
|
|
5
5
|
const config_1 = require("./config");
|
|
6
6
|
function resolveImages() {
|
|
7
7
|
const experiment = (0, config_1.activeExperiment)();
|
|
@@ -19,17 +19,21 @@ function resolveImages() {
|
|
|
19
19
|
};
|
|
20
20
|
}
|
|
21
21
|
/**
|
|
22
|
-
*
|
|
23
|
-
* with an explicit override)
|
|
24
|
-
* base images the CLI just pulled.
|
|
25
|
-
*
|
|
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
|
+
* 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.
|
|
26
30
|
*/
|
|
27
|
-
function
|
|
28
|
-
const
|
|
31
|
+
function baseImageEnv(resolved) {
|
|
32
|
+
const env = {};
|
|
29
33
|
for (const b of resolved.baseImages) {
|
|
30
34
|
if (b.gatewayEnv && (resolved.experiment !== undefined || process.env[b.gatewayEnv])) {
|
|
31
|
-
|
|
35
|
+
env[b.gatewayEnv] = b.image;
|
|
32
36
|
}
|
|
33
37
|
}
|
|
34
|
-
return
|
|
38
|
+
return env;
|
|
35
39
|
}
|