vyomi-tunnel 1.2.3 → 1.3.0-rc.3
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 +31 -0
- package/bin/credentials.mjs +1 -1
- package/bin/creds-sync.mjs +1 -1
- package/bin/mcp-launch.mjs +69 -0
- package/bin/mesh-cli.mjs +35 -10
- package/bin/mesh-ssh.mjs +38 -3
- package/bin/vyomi-tunnel.mjs +13 -2
- package/mcp/darwin-arm64/vyomi-mcp +0 -0
- package/mcp/darwin-x64/vyomi-mcp +0 -0
- package/mcp/linux-arm64/vyomi-mcp +0 -0
- package/mcp/linux-x64/vyomi-mcp +0 -0
- package/mcp/win32-x64/vyomi-mcp.exe +0 -0
- package/package.json +2 -1
package/README.md
CHANGED
|
@@ -69,6 +69,37 @@ ssh -i ~/.ssh/vyomi-<instance>.pem -p 22000 ec2-user@127.0.0.1
|
|
|
69
69
|
`GET /health` lists `"vm-tcp"` in `features` and the bridged VMs under `vms`.
|
|
70
70
|
Port range: `VM_PORT_MIN` / `VM_PORT_MAX`.
|
|
71
71
|
|
|
72
|
+
## Agents: the Vyomi MCP server (1.3.0+)
|
|
73
|
+
|
|
74
|
+
`vyomi-tunnel mcp` runs the Vyomi MCP server on stdin/stdout for Claude Code and
|
|
75
|
+
other agents. The package bundles it for macOS (arm64, x64), Linux (arm64, x64) and Windows
|
|
76
|
+
(x64), so there is nothing else to install:
|
|
77
|
+
|
|
78
|
+
```bash
|
|
79
|
+
claude mcp add vyomi -- vyomi-tunnel mcp
|
|
80
|
+
```
|
|
81
|
+
|
|
82
|
+
It finds your simulator (the Nano tab through this tunnel, a local mesh, or your
|
|
83
|
+
Mesh Codespace), says which one it uses, and gives SDK settings, capability levels
|
|
84
|
+
and examples for it. It needs no access key; only live Mesh Codespace details do
|
|
85
|
+
(through `vyomi-tunnel list`). On a platform without a bundled binary it runs
|
|
86
|
+
`vyomi-mcp`, then `vyomi mcp`, from your PATH. The Vyomi Claude Code plugin uses it.
|
|
87
|
+
|
|
88
|
+
## `vyomi-tunnel list --json`
|
|
89
|
+
|
|
90
|
+
A stable contract for scripts and the MCP:
|
|
91
|
+
|
|
92
|
+
```json
|
|
93
|
+
{ "schema": 1,
|
|
94
|
+
"rows": [ { "where": "local", "name": "nano-api", "type": "api",
|
|
95
|
+
"address": "http://127.0.0.1:8090", "connect": "aws --endpoint-url ..." } ],
|
|
96
|
+
"notes": [ "mesh: Mesh is not running. Start it in the Vyomi console, then retry." ] }
|
|
97
|
+
```
|
|
98
|
+
|
|
99
|
+
Exit code 0 when there are rows, 1 when there are none, 2 with no credentials or a
|
|
100
|
+
usage error. JSON is printed in every case except a usage error. Listing never
|
|
101
|
+
edits `~/.ssh/config`: run `vyomi-tunnel config` once for `ssh <name>.vyomi`.
|
|
102
|
+
|
|
72
103
|
## Notes
|
|
73
104
|
|
|
74
105
|
- **Safari**: connecting an `https://` page to `ws://localhost` can be blocked;
|
package/bin/credentials.mjs
CHANGED
|
@@ -48,7 +48,7 @@ const friendly = (portal) => ({
|
|
|
48
48
|
Throttled: "too many requests; wait a moment and retry.",
|
|
49
49
|
});
|
|
50
50
|
|
|
51
|
-
export async function fetchSession({ creds, fetchFn = globalThis.fetch, now = () => new Date(), version = "1.
|
|
51
|
+
export async function fetchSession({ creds, fetchFn = globalThis.fetch, now = () => new Date(), version = "1.3.0-rc.3" }) {
|
|
52
52
|
const path = "/api/tunnel/session", body = JSON.stringify({ client: "vyomi-tunnel/" + version });
|
|
53
53
|
const date = now().toISOString().replace(/\.\d+Z$/, "Z");
|
|
54
54
|
let r;
|
package/bin/creds-sync.mjs
CHANGED
|
@@ -16,7 +16,7 @@ export const ALLOWED_ORIGINS = [/^https:\/\/(www\.)?vyomi\.cloud$/, /^https?:\/\
|
|
|
16
16
|
export const originAllowed = (origin) => !origin || ALLOWED_ORIGINS.some((re) => re.test(origin));
|
|
17
17
|
export const hostIsLoopback = (host) => /^(localhost|127\.0\.0\.1|\[::1\])(:\d+)?$/i.test(String(host || ""));
|
|
18
18
|
|
|
19
|
-
export function createCredsSync({ env = process.env, fetchFn = globalThis.fetch, version = "1.
|
|
19
|
+
export function createCredsSync({ env = process.env, fetchFn = globalThis.fetch, version = "1.3.0-rc.3", log = () => {}, intervalMs = 300000, now = () => Date.now() } = {}) {
|
|
20
20
|
const home = env.VYOMI_HOME || join(homedir(), ".vyomi");
|
|
21
21
|
const file = env.VYOMI_CREDENTIALS_FILE || join(home, "credentials");
|
|
22
22
|
let st = { state: "unknown", key_id: "", portal: "", checked_at: 0, error: "" };
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
/* `vyomi-tunnel mcp`: run the Vyomi MCP server (the Go vyomi-mcp, cmd/vyomi) on this process's stdin/stdout.
|
|
2
|
+
*
|
|
3
|
+
* The npm package bundles one binary per platform at ../mcp/<platform>-<arch>/vyomi-mcp[.exe], relative to this file (Node's names:
|
|
4
|
+
* darwin-arm64, darwin-x64, linux-arm64, linux-x64, win32-x64; built by scripts/build_tunnel_mcp.sh, never committed). Without it
|
|
5
|
+
* (unsupported platform, trimmed install, the in-repo copy) the launcher falls back to `vyomi-mcp`, then `vyomi mcp`, on PATH.
|
|
6
|
+
*
|
|
7
|
+
* Rules: stdout is the MCP protocol channel, so this file never writes to it; a failure is ONE stderr line and exit 127.
|
|
8
|
+
* It needs no Vyomi key (the entry script dispatches `mcp` before the credentials gate). The child gets VYOMI_TUNNEL_BIN = this
|
|
9
|
+
* install's entry script, so the MCP calls back the same vyomi-tunnel (`list mesh --json`) instead of whatever is on PATH.
|
|
10
|
+
*/
|
|
11
|
+
import fs from "node:fs";
|
|
12
|
+
import path from "node:path";
|
|
13
|
+
import os from "node:os";
|
|
14
|
+
import { spawn } from "node:child_process";
|
|
15
|
+
import { fileURLToPath } from "node:url";
|
|
16
|
+
|
|
17
|
+
const here = path.dirname(fileURLToPath(import.meta.url));
|
|
18
|
+
const exe = (platform) => (platform === "win32" ? ".exe" : "");
|
|
19
|
+
|
|
20
|
+
/** First executable `name` on PATH (PATHEXT on Windows), or null. */
|
|
21
|
+
export function onPath(name, { env = process.env, platform = process.platform } = {}) {
|
|
22
|
+
const exts = platform === "win32" ? (env.PATHEXT || ".EXE;.CMD;.BAT").split(";").filter(Boolean) : [""];
|
|
23
|
+
for (const dir of String(env.PATH || "").split(path.delimiter)) {
|
|
24
|
+
if (!dir) continue;
|
|
25
|
+
for (const ext of exts) {
|
|
26
|
+
const f = path.join(dir, name + ext);
|
|
27
|
+
try { if (fs.statSync(f).isFile()) { if (platform !== "win32") fs.accessSync(f, fs.constants.X_OK); return f; } } catch { /* next */ }
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
return null;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
/** Which binary to run: {cmd, args, via} or {error}. The bundled binary first (its exec bit restored once if an unpack dropped it). */
|
|
34
|
+
export function resolveMcp(args = [], { dir = here, platform = process.platform, arch = process.arch, env = process.env } = {}) {
|
|
35
|
+
const bundled = path.join(dir, "..", "mcp", `${platform}-${arch}`, "vyomi-mcp" + exe(platform));
|
|
36
|
+
let bundledNote = "";
|
|
37
|
+
if (fs.existsSync(bundled)) {
|
|
38
|
+
if (platform === "win32") return { cmd: bundled, args, via: "bundled" };
|
|
39
|
+
try { fs.accessSync(bundled, fs.constants.X_OK); return { cmd: bundled, args, via: "bundled" }; } catch { /* not executable */ }
|
|
40
|
+
try { fs.chmodSync(bundled, 0o755); fs.accessSync(bundled, fs.constants.X_OK); return { cmd: bundled, args, via: "bundled (exec bit restored)" }; }
|
|
41
|
+
catch { bundledNote = ` (${bundled} is not executable: chmod 755 it)`; }
|
|
42
|
+
}
|
|
43
|
+
const mcp = onPath("vyomi-mcp", { env, platform }); if (mcp) return { cmd: mcp, args, via: "PATH vyomi-mcp" };
|
|
44
|
+
const vyomi = onPath("vyomi", { env, platform }); if (vyomi) return { cmd: vyomi, args: ["mcp", ...args], via: "PATH vyomi mcp" };
|
|
45
|
+
return { error: `vyomi-tunnel: no Vyomi MCP server for ${platform}-${arch}${bundledNote}. Reinstall: npm i -g vyomi-tunnel@latest (or brew reinstall vyomi-tunnel), or put vyomi-mcp on your PATH.` };
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
/** Run the MCP with stdio inherited; resolves with its exit code (128 + signal number when it was killed). */
|
|
49
|
+
export function launchMcp(args = [], { entryUrl, dir = here, env = process.env, stderr = process.stderr } = {}) {
|
|
50
|
+
const r = resolveMcp(args, { dir, env });
|
|
51
|
+
if (r.error) { stderr.write(r.error + "\n"); return Promise.resolve(127); }
|
|
52
|
+
const childEnv = { ...env };
|
|
53
|
+
// An explicit VYOMI_TUNNEL_BIN (a test harness, a pinned install) wins, like every other VYOMI_* override.
|
|
54
|
+
if (entryUrl && !env.VYOMI_TUNNEL_BIN) childEnv.VYOMI_TUNNEL_BIN = fileURLToPath(entryUrl);
|
|
55
|
+
// The MCP runs `node <VYOMI_TUNNEL_BIN> list ...`: make sure the node running us is findable even if PATH lacks it (appended, so it never shadows).
|
|
56
|
+
const nodeDir = path.dirname(process.execPath);
|
|
57
|
+
if (!String(childEnv.PATH || "").split(path.delimiter).includes(nodeDir)) childEnv.PATH = [childEnv.PATH, nodeDir].filter(Boolean).join(path.delimiter);
|
|
58
|
+
return new Promise((resolve) => {
|
|
59
|
+
let child;
|
|
60
|
+
try { child = spawn(r.cmd, r.args, { stdio: "inherit", env: childEnv, windowsHide: true }); }
|
|
61
|
+
catch (e) { stderr.write(`vyomi-tunnel: cannot start ${r.cmd}: ${e.message}\n`); resolve(127); return; }
|
|
62
|
+
const fwd = (sig) => () => { try { child.kill(sig); } catch { /* gone */ } };
|
|
63
|
+
const handlers = ["SIGINT", "SIGTERM", "SIGHUP"].filter((s) => !(process.platform === "win32" && s === "SIGHUP")).map((s) => [s, fwd(s)]);
|
|
64
|
+
for (const [s, h] of handlers) process.on(s, h);
|
|
65
|
+
const done = (code) => { for (const [s, h] of handlers) process.off(s, h); resolve(code); };
|
|
66
|
+
child.on("error", (e) => { stderr.write(`vyomi-tunnel: cannot start ${r.cmd}: ${e.code || e.message}\n`); done(127); });
|
|
67
|
+
child.on("exit", (code, signal) => done(code ?? 128 + (os.constants.signals[signal] || 0)));
|
|
68
|
+
});
|
|
69
|
+
}
|
package/bin/mesh-cli.mjs
CHANGED
|
@@ -156,6 +156,10 @@ export async function configureSsh({ yes = false, cmd = "vyomi-tunnel", sshDir =
|
|
|
156
156
|
fs.writeFileSync(main, inc + "\n\n" + cur, { mode: 0o600 }); // Include must come first to apply to all hosts
|
|
157
157
|
return { changed: true, file: main };
|
|
158
158
|
}
|
|
159
|
+
/** Read-only: does ~/.ssh/config already Include ~/.vyomi/ssh_config? (`list` reports it; listing never writes ssh config.) */
|
|
160
|
+
export function sshConfigured({ sshDir = path.join(os.homedir(), ".ssh") } = {}) {
|
|
161
|
+
try { return fs.readFileSync(path.join(sshDir, "config"), "utf8").split("\n").some((l) => l.trim() === `Include ${SSH_CONF}`); } catch { return false; }
|
|
162
|
+
}
|
|
159
163
|
export function removeSshConfig({ sshDir = path.join(os.homedir(), ".ssh") } = {}) {
|
|
160
164
|
const main = path.join(sshDir, "config"), inc = `Include ${SSH_CONF}`;
|
|
161
165
|
try { const cur = fs.readFileSync(main, "utf8"); fs.writeFileSync(main, cur.split("\n").filter((l) => l.trim() !== inc).join("\n").replace(/^\n+/, "")); } catch { /* none */ }
|
|
@@ -202,7 +206,10 @@ const HELP = `vyomi-tunnel - connect your machine to Vyomi
|
|
|
202
206
|
re-pair this tunnel with your Vyomi account (see: help reset)
|
|
203
207
|
vyomi-tunnel start the local relay for the Nano console
|
|
204
208
|
|
|
205
|
-
|
|
209
|
+
Agents:
|
|
210
|
+
vyomi-tunnel mcp the Vyomi MCP server for Claude Code and other agents (see: help mcp)
|
|
211
|
+
|
|
212
|
+
Everything else needs a key (Free works for Nano; Mesh needs Pro or Max).
|
|
206
213
|
Get one: 'vyomi-tunnel help credentials'.
|
|
207
214
|
Log in to a Mesh VM over SSH: 'vyomi-tunnel help ssh'. Something failing? 'vyomi-tunnel help troubleshoot'.
|
|
208
215
|
`;
|
|
@@ -253,7 +260,8 @@ Shows what you can reach right now, and the command for each.
|
|
|
253
260
|
Add a type to narrow it:
|
|
254
261
|
vyomi-tunnel list nano vm (also: api, db)
|
|
255
262
|
vyomi-tunnel list mesh k3s (also: host, instance, llm, service, forward)
|
|
256
|
-
A type alone works too: vyomi-tunnel list vm
|
|
263
|
+
A type alone works too: vyomi-tunnel list vm
|
|
264
|
+
--json prints {schema: 1, rows: [{where, name, type, address, connect}], notes: [...]} (exit 0 rows, 1 none, 2 no key).`,
|
|
257
265
|
ssh: `Log in to a Mesh VM over SSH
|
|
258
266
|
|
|
259
267
|
1. See your Mesh and its VMs:
|
|
@@ -288,16 +296,23 @@ A new Mesh is a new machine with a new key: repeat step 3. Problems: 'vyomi-tunn
|
|
|
288
296
|
Listen on 127.0.0.1:<local> and forward to <name>:<remote> in your Mesh Codespace.
|
|
289
297
|
vyomi-tunnel forward k3s 6443:6443
|
|
290
298
|
vyomi-tunnel forward host 2222:22`,
|
|
299
|
+
mcp: `vyomi-tunnel mcp
|
|
300
|
+
|
|
301
|
+
Runs the Vyomi MCP server (vyomi-mcp, bundled with this package) on stdin/stdout, for Claude Code and other agents:
|
|
302
|
+
claude mcp add vyomi -- vyomi-tunnel mcp
|
|
303
|
+
It finds your simulator (the Nano tab through this tunnel, a local mesh, or your Mesh Codespace), and answers what Vyomi
|
|
304
|
+
supports and how to point your SDKs at it. It needs no key; only live Mesh Codespace details need one (through 'list').
|
|
305
|
+
Without a bundled binary for this platform it runs 'vyomi-mcp' or 'vyomi mcp' from your PATH.`,
|
|
291
306
|
};
|
|
292
307
|
export const helpText = (topic) => (topic && DETAILS[topic]) || HELP;
|
|
293
308
|
|
|
294
309
|
/** Credentials -> Vyomi session -> an ssh transport to the user's Mesh Codespace. Returns {transport, sess} or {error, code}. */
|
|
295
|
-
export async function openMesh({ cs, log = () => {} } = {}) {
|
|
310
|
+
export async function openMesh({ cs, log = () => {}, configure = true } = {}) {
|
|
296
311
|
const { createSessionManager } = await import("./credentials.mjs");
|
|
297
312
|
const ssh = await import("./mesh-ssh.mjs");
|
|
298
313
|
let sess; try { sess = await createSessionManager({ log }).get(); } catch (e) { return { error: e.message, code: e.code }; }
|
|
299
314
|
if (!sess.meshAllowed) return { error: "Mesh needs a Pro or Max plan.", code: "PlanNotAllowed" };
|
|
300
|
-
try { await configureSsh({ yes: true }); } catch { /* ssh setup is best effort */ }
|
|
315
|
+
if (configure) try { await configureSsh({ yes: true }); } catch { /* ssh setup is best effort */ }
|
|
301
316
|
const transport = ssh.createSshTransport({ codespace: cs || sess.codespace || null, env: sess.githubToken ? { GH_TOKEN: sess.githubToken } : {}, log });
|
|
302
317
|
if (sess.sessionEnd) transport.stopAt(sess.sessionEnd);
|
|
303
318
|
return { transport, sess };
|
|
@@ -315,7 +330,7 @@ export async function main(argv) {
|
|
|
315
330
|
if (!cmd || ["help", "-h", "--help", "-help", "-?"].includes(cmd) || rest.some((a) => ["-h", "--help", "-help"].includes(a))) { const topic = cmd === "help" ? rest[0] : (["-h", "--help", "-help", "-?"].includes(cmd) ? undefined : cmd); const t = topic && DETAILS[topic];
|
|
316
331
|
if (topic && !t) { console.error(`vyomi-tunnel: no help for "${topic}".`); process.stdout.write(HELP); return 2; }
|
|
317
332
|
process.stdout.write((t || HELP) + (t ? "\n" : "")); return cmd ? 0 : 2; }
|
|
318
|
-
if (cmd === "--version" || cmd === "-v" || cmd === "version") { console.log(process.env.VYOMI_TUNNEL_VERSION || "vyomi-tunnel 1.
|
|
333
|
+
if (cmd === "--version" || cmd === "-v" || cmd === "version") { console.log(process.env.VYOMI_TUNNEL_VERSION || "vyomi-tunnel 1.3.0-rc.3"); return 0; }
|
|
319
334
|
const WS = createRequire(import.meta.url)(process.env.WS_PKG || "ws");
|
|
320
335
|
// Mesh over the user's own ssh session (`--codespace <name>` or VYOMI_MESH_CODESPACE): no relay, no token (mesh-ssh.mjs).
|
|
321
336
|
const ci = rest.indexOf("--codespace");
|
|
@@ -371,7 +386,7 @@ export async function main(argv) {
|
|
|
371
386
|
if (!/^[A-Za-z0-9_-]{20,64}$/.test(code)) { console.error("usage: vyomi-tunnel reset <code> (get a code in the Vyomi console: Setup Tunnel > Get install command; see `vyomi-tunnel help reset`)"); return 2; }
|
|
372
387
|
const { createCredsSync } = await import("./creds-sync.mjs");
|
|
373
388
|
try {
|
|
374
|
-
const cs = createCredsSync({ version: process.env.VYOMI_TUNNEL_VERSION_NUM || "1.
|
|
389
|
+
const cs = createCredsSync({ version: process.env.VYOMI_TUNNEL_VERSION_NUM || "1.3.0-rc.3" });
|
|
375
390
|
const st = await cs.reset(code, os.hostname());
|
|
376
391
|
console.log(st.state === "ok" ? `Done. The tunnel now uses access key ${st.key_id}.` : `The new key was saved (${st.key_id}) but the portal answered: ${st.error || st.state}.`);
|
|
377
392
|
try { await fetch(`http://127.0.0.1:${process.env.RELAY_PORT || 8090}/reload`, { method: "POST", signal: AbortSignal.timeout(3000) }); console.log("The running tunnel reloaded it."); }
|
|
@@ -384,9 +399,15 @@ export async function main(argv) {
|
|
|
384
399
|
return 2;
|
|
385
400
|
}
|
|
386
401
|
if (cmd === "list" || cmd === "ls") { // every transport line, with the command to use it
|
|
402
|
+
// --json is a contract (read by the Vyomi MCP): {schema: 1, rows: [{where, name, type, address, connect}], notes: [string]}. Exit 0 with rows,
|
|
403
|
+
// 1 with none, 2 with no credentials or a usage error; JSON is printed in every case but a usage error. Listing never edits ssh config.
|
|
387
404
|
const json = rest.includes("--json"); const pos = rest.filter((x) => !x.startsWith("-"));
|
|
388
405
|
const auth = await requireSession(); // nothing is listed without a valid key, Nano included
|
|
389
|
-
|
|
406
|
+
const meshDown = !!auth.error && ["NoMeshSession", "SessionEnded"].includes(auth.code); // the key is valid, only the Mesh is not running
|
|
407
|
+
if (auth.error && !meshDown) {
|
|
408
|
+
if (json) console.log(JSON.stringify({ schema: 1, rows: [], notes: [auth.error] }, null, 2));
|
|
409
|
+
console.error("vyomi-tunnel: " + auth.error); return auth.code === "NoCredentials" ? 2 : 1;
|
|
410
|
+
}
|
|
390
411
|
const KINDS = ["api", "vm", "db", "host", "instance", "k3s", "llm", "service", "forward"];
|
|
391
412
|
const SCOPES = { nano: ["api", "vm", "db"], mesh: ["host", "instance", "k3s", "llm", "service", "forward"], all: KINDS }; // forwards go to a Mesh target
|
|
392
413
|
const norm = (w) => { w = String(w || "").toLowerCase(); return w === "k3s" || KINDS.includes(w) || SCOPES[w] ? w : w.replace(/(s|es)$/, "") && KINDS.includes(w.replace(/s$/, "")) ? w.replace(/s$/, "") : w; }; // vms -> vm, dbs -> db
|
|
@@ -400,10 +421,11 @@ export async function main(argv) {
|
|
|
400
421
|
const rows = []; const notes = [];
|
|
401
422
|
let transport = null, meshP = Promise.resolve(null);
|
|
402
423
|
if (kinds.some((k) => ["host", "instance", "k3s", "llm", "service"].includes(k))) { // Mesh also needs a plan that allows it
|
|
403
|
-
const o = await openMesh({ cs });
|
|
424
|
+
const o = meshDown ? { error: auth.error } : await openMesh({ cs, configure: false });
|
|
404
425
|
if (o.error) meshP = Promise.resolve({ err: o.error });
|
|
405
426
|
else { transport = o.transport; meshP = transport.list().then((ts) => ({ ts, cs: transport.codespace })).catch((e) => ({ err: e.message })); }
|
|
406
427
|
}
|
|
428
|
+
const ssh = await import("./mesh-ssh.mjs");
|
|
407
429
|
const port = process.env.RELAY_PORT || 8090;
|
|
408
430
|
if (kinds.some((k) => ["api", "vm", "db"].includes(k))) try {
|
|
409
431
|
const h = await (await fetch(`http://127.0.0.1:${port}/health`, { signal: AbortSignal.timeout(1500) })).json();
|
|
@@ -414,7 +436,9 @@ export async function main(argv) {
|
|
|
414
436
|
const m = await meshP;
|
|
415
437
|
if (m && m.err) notes.push("mesh: " + m.err);
|
|
416
438
|
else if (m) for (const t of m.ts) {
|
|
417
|
-
|
|
439
|
+
// a free local port, as the MCP does: the offline appliance or another stack often holds :9000 / :6443 here
|
|
440
|
+
const fwd = async (r) => `vyomi-tunnel forward ${t.name} ${await ssh.freeLocalPort(r)}:${r}`;
|
|
441
|
+
const how = t.kind === "k3s" ? await fwd(6443) : t.ssh ? `ssh ${t.name}${SUFFIX}` : t.ports.length ? await fwd(t.ports[0]) : "";
|
|
418
442
|
rows.push({ where: "mesh", name: t.name, type: t.kind, address: t.ip ? t.ip + (t.ports[0] ? ":" + t.ports[0] : "") : "", connect: how });
|
|
419
443
|
}
|
|
420
444
|
transport?.close();
|
|
@@ -425,7 +449,8 @@ export async function main(argv) {
|
|
|
425
449
|
rows.push({ where: "local", name: `${d.target}`, type: "forward", address: `127.0.0.1:${d.local}`, connect: `-> ${d.target}:${d.remote} (pid ${d.pid})` });
|
|
426
450
|
} } catch { /* none */ }
|
|
427
451
|
const out = rows.filter((r) => kinds.includes(r.type));
|
|
428
|
-
if (
|
|
452
|
+
if (out.some((r) => r.connect.startsWith("ssh ") && r.connect.endsWith(SUFFIX)) && !sshConfigured()) notes.push(`'ssh <name>${SUFFIX}' needs a one-time setup: vyomi-tunnel config`);
|
|
453
|
+
if (json) { console.log(JSON.stringify({ schema: 1, rows: out, notes }, null, 2)); return out.length ? 0 : 1; }
|
|
429
454
|
const w = [9, 22, 10, 22]; const line = (r) => [r.where, r.name, r.type, r.address].map((c, i) => String(c).padEnd(w[i])).join(" ") + " " + r.connect;
|
|
430
455
|
if (out.length) { console.log(line({ where: "WHERE", name: "NAME", type: "TYPE", address: "ADDRESS", connect: "CONNECT" })); for (const r of out) console.log(line(r)); }
|
|
431
456
|
else console.log(want && want !== "all" ? `No ${want} targets right now.` : "Nothing reachable right now.");
|
package/bin/mesh-ssh.mjs
CHANGED
|
@@ -14,6 +14,7 @@ import { tmpdir } from "node:os";
|
|
|
14
14
|
import { join } from "node:path";
|
|
15
15
|
import http from "node:http";
|
|
16
16
|
import crypto from "node:crypto";
|
|
17
|
+
import nodeNet from "node:net";
|
|
17
18
|
import { ensureGh, ghAuthOk } from "./gh-manager.mjs";
|
|
18
19
|
|
|
19
20
|
const NAME = /^[A-Za-z0-9._-]{1,80}$/;
|
|
@@ -38,13 +39,22 @@ export function classifyTargets(text) {
|
|
|
38
39
|
return out;
|
|
39
40
|
}
|
|
40
41
|
|
|
42
|
+
/** `gh codespace list` failed: say what to do. GitHub answers a token without the `codespace` scope with a 403 "Must have admin
|
|
43
|
+
* rights to Repository", which reads like a permissions problem on some repo; the fix is one command. Short: callers prefix it. */
|
|
44
|
+
export function ghListError(stderr) {
|
|
45
|
+
const e = String(stderr || "").trim();
|
|
46
|
+
if (/codespace"? scope|admin rights|HTTP 403/i.test(e)) return "gh cannot list your Codespaces: its login lacks the codespace scope. Run: gh auth refresh -h github.com -s codespace";
|
|
47
|
+
if (/not logged in|gh auth login|HTTP 401|authentication required/i.test(e)) return "gh is not logged in to GitHub. Run: gh auth login";
|
|
48
|
+
return (e || "gh codespace list failed").slice(0, 200);
|
|
49
|
+
}
|
|
50
|
+
|
|
41
51
|
/** Find the user's Mesh Codespace on their own account: the newest running (or starting) one named vyomi-mesh-* / vyomi-mesh-*. */
|
|
42
52
|
export async function findCodespace(ghBin, spawn = nodeSpawn) {
|
|
43
53
|
const text = await new Promise((resolve, reject) => {
|
|
44
54
|
let out = "", err = "";
|
|
45
55
|
const c = spawn(ghBin, ["codespace", "list", "--json", "name,state,createdAt"], { stdio: ["ignore", "pipe", "pipe"] });
|
|
46
56
|
c.stdout.on("data", (d) => { out += d; }); c.stderr?.on("data", (d) => { err += d; });
|
|
47
|
-
c.on("error", reject); c.on("close", (code) => (code === 0 ? resolve(out) : reject(new Error((err
|
|
57
|
+
c.on("error", reject); c.on("close", (code) => (code === 0 ? resolve(out) : reject(new Error(ghListError(err)))));
|
|
48
58
|
});
|
|
49
59
|
let list; try { list = JSON.parse(text); } catch { list = []; }
|
|
50
60
|
const mine = list.filter((c) => /^vyomi-mesh-/.test(c.name || ""));
|
|
@@ -323,7 +333,7 @@ export function createSshHub({ WebSocketServer, WebSocket: WSClient = null, tran
|
|
|
323
333
|
/** `connect`: pipe stdin/stdout to <name>:<port> in the Codespace. Resolves with the exit code (0 clean, 1 failed, 3 not found). */
|
|
324
334
|
export async function connectSsh(name, { port = 22, transport, stdin = process.stdin, stdout = process.stdout, stderr = process.stderr } = {}) {
|
|
325
335
|
let t; try { t = await transport.resolve(name, port); } catch (e) { stderr.write(`vyomi-tunnel: ${e.message}\n`); return 1; }
|
|
326
|
-
if (!t) { stderr.write(`vyomi-tunnel: ${name}: not found in the Codespace
|
|
336
|
+
if (!t) { stderr.write(`vyomi-tunnel: ${name}: not found in the Codespace. If it was just started or woken from idle, its mesh may still be starting: \`vyomi-tunnel list mesh\` lists it once it is up.\n`); return 3; }
|
|
327
337
|
let up; try { up = await transport.open(t.host, t.port); } catch (e) { stderr.write(`vyomi-tunnel: ${e.message}\n`); return 1; }
|
|
328
338
|
return new Promise((resolve) => {
|
|
329
339
|
let done = false; const fin = (c) => { if (done) return; done = true; try { up.destroy(); } catch { /* */ } try { stdin.pause(); } catch { /* */ } resolve(c); };
|
|
@@ -333,10 +343,35 @@ export async function connectSsh(name, { port = 22, transport, stdin = process.s
|
|
|
333
343
|
});
|
|
334
344
|
}
|
|
335
345
|
|
|
346
|
+
/** Is 127.0.0.1:<port> taken? Something answers a connect, or it cannot be bound. The connect matters on macOS, where a
|
|
347
|
+
* socket on *:<port> (Docker Desktop publishing the offline appliance on :9000) does not stop a bind to 127.0.0.1:<port>:
|
|
348
|
+
* a bind-only test calls it free and the forward then shadows that service for every 127.0.0.1 client. */
|
|
349
|
+
export async function localPortBusy(port, net = nodeNet) {
|
|
350
|
+
const answers = await new Promise((r) => {
|
|
351
|
+
const s = net.connect({ host: "127.0.0.1", port }); const t = setTimeout(() => { s.destroy(); r(false); }, 300);
|
|
352
|
+
s.on("connect", () => { clearTimeout(t); s.destroy(); r(true); }); s.on("error", () => { clearTimeout(t); r(false); });
|
|
353
|
+
});
|
|
354
|
+
if (answers) return true;
|
|
355
|
+
return new Promise((r) => { const srv = net.createServer(); srv.once("error", () => r(true)); srv.listen(port, "127.0.0.1", () => srv.close(() => r(false))); });
|
|
356
|
+
}
|
|
357
|
+
|
|
358
|
+
/** The local port to suggest for forwarding <remote>: <remote> itself when free here, else the first free one of <remote>+100..+199
|
|
359
|
+
* (9000 -> 9100+, 9443 -> 9543+, the same rule as the vyomi MCP's forward hint). */
|
|
360
|
+
export async function freeLocalPort(remote, net = nodeNet) {
|
|
361
|
+
if (!(await localPortBusy(remote, net))) return remote;
|
|
362
|
+
for (let p = remote + 100; p < remote + 200; p++) if (!(await localPortBusy(p, net))) return p;
|
|
363
|
+
return remote;
|
|
364
|
+
}
|
|
365
|
+
|
|
336
366
|
/** `forward`: listen on 127.0.0.1:<local>; each accepted socket is one ssh stream to <target>:<remote> inside the Codespace. */
|
|
337
367
|
export async function forwardSsh(target, { local, remote, transport, net, stderr = process.stderr } = {}) {
|
|
338
368
|
const t = await transport.resolve(target, remote);
|
|
339
|
-
if (!t) { stderr.write(`vyomi-tunnel: ${target}: not found in the Codespace
|
|
369
|
+
if (!t) { stderr.write(`vyomi-tunnel: ${target}: not found in the Codespace. If it was just started or woken from idle, its mesh may still be starting: \`vyomi-tunnel list mesh\` lists it once it is up.\n`); return { close() {}, done: Promise.resolve(3), port: 0 }; }
|
|
370
|
+
if (local > 0 && await localPortBusy(local, net)) {
|
|
371
|
+
const alt = await freeLocalPort(remote, net);
|
|
372
|
+
stderr.write(`vyomi-tunnel: 127.0.0.1:${local} is already in use on this machine (another Vyomi or Docker stack?). Use another local port: vyomi-tunnel forward ${target} ${alt}:${remote}\n`);
|
|
373
|
+
return { close() {}, done: Promise.resolve(1), port: 0 };
|
|
374
|
+
}
|
|
340
375
|
const socks = new Set(); let finish; const done = new Promise((r) => { finish = r; });
|
|
341
376
|
const srv = net.createServer(async (sock) => {
|
|
342
377
|
socks.add(sock); sock.setNoDelay(true);
|
package/bin/vyomi-tunnel.mjs
CHANGED
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
// GENERATED — canonical source: wasm/relay/local-relay.mjs
|
|
3
|
-
// Re-sync:
|
|
3
|
+
// Re-sync: this entry file is hand-derived (no hosted-relay hubs): port each change of
|
|
4
|
+
// local-relay.mjs by hand. The other bin/*.mjs are copies of wasm/relay/<same name>, with only the version stamps changed to package.json's
|
|
5
|
+
// version (mesh-cli.mjs `vyomi-tunnel X.Y.Z`, credentials.mjs `version = "X.Y.Z"`). bin/mcp-launch.mjs is a plain copy. The ../mcp/ binaries
|
|
6
|
+
// are built by scripts/build_tunnel_mcp.sh and never committed.
|
|
4
7
|
/* Vyomi-Nano local relay — the local, zero-cloud reverse-tunnel. The
|
|
5
8
|
* install-once counterpart to the Cloudflare Worker (worker.js): same WS
|
|
6
9
|
* protocol, same external HTTP surface, but everything stays on your machine
|
|
@@ -41,6 +44,14 @@ import http from "node:http";
|
|
|
41
44
|
import net from "node:net";
|
|
42
45
|
import crypto from "node:crypto";
|
|
43
46
|
import { createRequire } from "node:module";
|
|
47
|
+
|
|
48
|
+
// `vyomi-tunnel mcp`: the Vyomi MCP server for agents, on stdin/stdout (mcp-launch.mjs). First, before the credentials gate: it needs no key,
|
|
49
|
+
// and stdout is the protocol channel, so nothing may be printed before it.
|
|
50
|
+
if (process.argv[2] === "mcp") {
|
|
51
|
+
const { launchMcp } = await import("./mcp-launch.mjs");
|
|
52
|
+
process.exit(await launchMcp(process.argv.slice(3), { entryUrl: import.meta.url }));
|
|
53
|
+
}
|
|
54
|
+
|
|
44
55
|
// CommonJS require honors NODE_PATH (unlike ESM import), so the `ws` package
|
|
45
56
|
// resolves wherever it's installed (e.g. NODE_PATH=/tmp/node_modules for tests).
|
|
46
57
|
const { WebSocketServer, WebSocket } = createRequire(import.meta.url)(process.env.WS_PKG || "ws");
|
|
@@ -55,7 +66,7 @@ if (process.argv[2] && !process.argv[2].startsWith("-")) { console.error(`vyomi-
|
|
|
55
66
|
|
|
56
67
|
// The tunnel keeps running even when its key is missing, revoked or wrong (a service manager would crash-loop it otherwise): the state is
|
|
57
68
|
// shown on /health, re-checked on a timer and when ~/.vyomi/credentials changes, and the Vyomi page can re-pair it (POST /reset).
|
|
58
|
-
const VERSION = "1.
|
|
69
|
+
const VERSION = "1.3.0-rc.3";
|
|
59
70
|
const credsSync = createCredsSync({ version: VERSION, log: (m) => console.log("[creds] " + m) });
|
|
60
71
|
const PORT = Number(process.env.RELAY_PORT || 8090);
|
|
61
72
|
// Mesh plane: the Nano console reaches the user's Mesh Codespace THROUGH this relay (the link runs on the laptop, over their own
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "vyomi-tunnel",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.3.0-rc.3",
|
|
4
4
|
"description": "Vyomi-Nano local reverse-tunnel — reach the in-browser cloud simulator from any local SDK/CLI. The install-once, zero-cloud counterpart to the hosted Cloudflare relay; the Nano tab auto-detects it and prefers it.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"bin": {
|
|
@@ -8,6 +8,7 @@
|
|
|
8
8
|
},
|
|
9
9
|
"files": [
|
|
10
10
|
"bin/",
|
|
11
|
+
"mcp/",
|
|
11
12
|
"README.md"
|
|
12
13
|
],
|
|
13
14
|
"dependencies": {
|