@khanglvm/relay 0.20.0 → 0.20.2
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 +11 -4
- package/package.json +1 -1
- package/src/cli/args.js +1 -1
- package/src/cli/config.js +1 -1
- package/src/cli/help.js +4 -3
- package/src/cli/io.js +1 -1
- package/src/link.js +57 -9
- package/src/server/board.js +1 -1
- package/src/server/http.js +1 -1
- package/src/spec/ready.js +31 -9
- package/src/store.js +1 -1
package/README.md
CHANGED
|
@@ -64,10 +64,17 @@ rules to Codex's instruction file. Run `rly install` to see other targets.
|
|
|
64
64
|
|
|
65
65
|
## Open a board on your phone
|
|
66
66
|
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
67
|
+
A board listens on this machine only until you give it a link. Two generic ways:
|
|
68
|
+
|
|
69
|
+
- A URL template for any proxy or tunnel you run: `--public-url 'https://host.example.com:{port}'`.
|
|
70
|
+
- A link-provider command: `--link-command 'my-publisher {port}'`. Relay runs it with the
|
|
71
|
+
board's port; it prints an https URL (plain text, or JSON with `url`), and the board is
|
|
72
|
+
served at that origin. Set `RLY_LINK_RELEASE_COMMAND` to a command that runs when the
|
|
73
|
+
board closes. Commands are split on spaces and run without a shell.
|
|
74
|
+
|
|
75
|
+
[`devlink`](https://github.com/khanglvm/devlink) is one such provider and has a shortcut:
|
|
76
|
+
`--devlink`. Run `rly config link <off|auto|devlink|url|command:CMD>` to make a choice the
|
|
77
|
+
default. The details are in the [agent guide](docs/AGENT.md).
|
|
71
78
|
|
|
72
79
|
## More help
|
|
73
80
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@khanglvm/relay",
|
|
3
|
-
"version": "0.20.
|
|
3
|
+
"version": "0.20.2",
|
|
4
4
|
"description": "Question boards with rich blocks (markdown, charts, mermaid, tables, code, diffs, video, sandboxed HTML), clickable local file-links, and element-level annotations for AI coding agents (Claude Code, Codex, \u2026): ask users structured questions, present interactive visuals, collect inline comments, read answers as JSON \u2014 in a local browser board OR rendered INLINE inside the Claude & Codex apps as an MCP App (SEP-1865).",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"ai-agents",
|
package/src/cli/args.js
CHANGED
|
@@ -5,7 +5,7 @@ const VALUED_FLAGS = new Set([
|
|
|
5
5
|
'file', 'html', 'html-file', 'title', 'intro', 'timeout', 'port',
|
|
6
6
|
'submit-label', 'height', 'limit', 'target', 'id', 'replies',
|
|
7
7
|
'on-result', 'notify-cmd', 'idle-grace', 'scope', 'range',
|
|
8
|
-
'host', 'token', 'allow-origin', 'role', 'public-url', 'link',
|
|
8
|
+
'host', 'token', 'allow-origin', 'role', 'public-url', 'link', 'link-command',
|
|
9
9
|
]);
|
|
10
10
|
|
|
11
11
|
function camel(key) {
|
package/src/cli/config.js
CHANGED
|
@@ -18,7 +18,7 @@ export function cmdAgent() {
|
|
|
18
18
|
return 0;
|
|
19
19
|
}
|
|
20
20
|
|
|
21
|
-
// `rly config [link [off|auto|devlink|<url>]]` — the saved link default, so
|
|
21
|
+
// `rly config [link [off|auto|devlink|command:CMD|<url>]]` — the saved link default, so
|
|
22
22
|
// every board prints a cross-device URL without a flag.
|
|
23
23
|
export function cmdConfig(args) {
|
|
24
24
|
const [key, value] = args._;
|
package/src/cli/help.js
CHANGED
|
@@ -38,10 +38,11 @@ USAGE
|
|
|
38
38
|
rly share <id> --role review --revoke
|
|
39
39
|
revoke one share role; use --revoke --all to disable all roles
|
|
40
40
|
active links survive same-port reopen/rescue until revoked
|
|
41
|
-
rly ask ... --
|
|
42
|
-
|
|
41
|
+
rly ask ... --link-command <cmd> serve the board at the https URL a link-provider command prints
|
|
42
|
+
for its port ({port} in <cmd>, else appended); no local browser opens
|
|
43
|
+
rly ask ... --devlink same, through the optional devlink command
|
|
43
44
|
rly ask ... --public-url <url> same, through your own proxy or tunnel: https://relay.example.com:{port}
|
|
44
|
-
rly config link <off|auto|devlink|url>
|
|
45
|
+
rly config link <off|auto|devlink|url|command:CMD>
|
|
45
46
|
save that choice for every board (auto = devlink when installed)
|
|
46
47
|
rly list [--json] running boards
|
|
47
48
|
rly open [id] re-open the browser tab of a running board
|
package/src/cli/io.js
CHANGED
|
@@ -163,7 +163,7 @@ export async function runOrDetach(record, args) {
|
|
|
163
163
|
{ detached: true, stdio: 'ignore' }
|
|
164
164
|
);
|
|
165
165
|
child.unref();
|
|
166
|
-
// A link setting adds a
|
|
166
|
+
// A link setting adds a link-provider round trip before the board is announced.
|
|
167
167
|
const startSec = link.mode === 'off' ? 8 : 40;
|
|
168
168
|
const info = await pollFor(() => loadRunning(record.id), startSec * 1000);
|
|
169
169
|
if (!info) throw new CliError(`board ${record.id} failed to start (no server after ${startSec}s).`, 1);
|
package/src/link.js
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
// Where a board can be opened from other devices. By default a board lives on a
|
|
2
|
-
// loopback port. A link setting turns that into a URL a phone or another
|
|
3
|
-
// reach: through
|
|
4
|
-
// or through a
|
|
2
|
+
// loopback port. A link setting turns that into a URL a phone or another computer
|
|
3
|
+
// can reach: through a URL template for any reverse proxy or tunnel the user
|
|
4
|
+
// runs, or through a link-provider command that publishes the board's port and
|
|
5
|
+
// prints the https URL. `devlink` is one such provider, with a built-in preset.
|
|
5
6
|
// Nothing here is required; with no setting Relay behaves as before.
|
|
6
7
|
import fs from 'node:fs';
|
|
7
8
|
import os from 'node:os';
|
|
@@ -10,18 +11,23 @@ import { execFile } from 'node:child_process';
|
|
|
10
11
|
import { CliError } from './util.js';
|
|
11
12
|
|
|
12
13
|
const DEVLINK_TIMEOUT_MS = 30_000;
|
|
13
|
-
export const LINK_MODES = ['off', 'auto', 'devlink'];
|
|
14
|
+
export const LINK_MODES = ['off', 'auto', 'devlink', 'command'];
|
|
14
15
|
|
|
15
16
|
const LOOPBACK_HOST = /^(localhost|0\.0\.0\.0|127(?:\.\d{1,3}){3}|\[?::1?\]?)$/i;
|
|
16
17
|
|
|
17
18
|
export const isLoopbackHost = (host) => LOOPBACK_HOST.test(String(host || ''));
|
|
18
19
|
|
|
19
|
-
/** '
|
|
20
|
+
/** 'off' | 'auto' | 'devlink' | 'command:<publish command>' | an https URL template -> a normalized setting. */
|
|
20
21
|
export function parseLinkValue(raw, where = 'link') {
|
|
21
22
|
const value = String(raw ?? '').trim();
|
|
22
23
|
const lower = value.toLowerCase();
|
|
23
24
|
if (lower === 'off' || lower === 'local') return { mode: 'off' };
|
|
24
25
|
if (lower === 'auto' || lower === 'devlink') return { mode: lower };
|
|
26
|
+
if (/^command:/i.test(value)) {
|
|
27
|
+
const publish = value.slice('command:'.length).trim();
|
|
28
|
+
if (!publish) throw new CliError(`${where}: command: needs a command, for example command:my-publisher {port}.`);
|
|
29
|
+
return { mode: 'command', publish };
|
|
30
|
+
}
|
|
25
31
|
if (/^http:\/\//i.test(value)) throw new CliError(`${where}: use https://, because the board's share token travels in the URL.`);
|
|
26
32
|
if (/^https:\/\//i.test(value)) {
|
|
27
33
|
let host;
|
|
@@ -29,18 +35,20 @@ export function parseLinkValue(raw, where = 'link') {
|
|
|
29
35
|
if (isLoopbackHost(host)) throw new CliError(`${where}: ${host} only works on this machine. Use a host other devices can reach.`);
|
|
30
36
|
return { mode: 'url', template: value.replace(/\/+$/, '') };
|
|
31
37
|
}
|
|
32
|
-
throw new CliError(`${where}: use off, auto, devlink, or an https:// URL (with {port} for the board port).`);
|
|
38
|
+
throw new CliError(`${where}: use off, auto, devlink, command:<link provider command>, or an https:// URL (with {port} for the board port).`);
|
|
33
39
|
}
|
|
34
40
|
|
|
35
41
|
/**
|
|
36
|
-
* Picks the link setting. Highest first: --no-devlink, --devlink, --
|
|
37
|
-
* RLY_PUBLIC_URL, RLY_LINK, the saved config, then off.
|
|
42
|
+
* Picks the link setting. Highest first: --no-devlink, --devlink, --link-command,
|
|
43
|
+
* RLY_LINK_COMMAND, --public-url, RLY_PUBLIC_URL, RLY_LINK, the saved config, then off.
|
|
38
44
|
* @param {{ args?: Record<string, any>, env?: Record<string, string | undefined>, config?: Record<string, any> }} [input]
|
|
39
45
|
*/
|
|
40
46
|
export function linkSetting({ args = {}, env = process.env, config = {} } = {}) {
|
|
41
47
|
if (args.noDevlink === true) return { mode: 'off' };
|
|
42
48
|
if (args.devlink === true) return { mode: 'devlink' };
|
|
49
|
+
if (typeof args.linkCommand === 'string') return parseLinkValue(`command:${args.linkCommand}`, '--link-command');
|
|
43
50
|
if (typeof args.publicUrl === 'string') return parseLinkValue(args.publicUrl, '--public-url');
|
|
51
|
+
if (env.RLY_LINK_COMMAND && typeof args.publicUrl !== 'string') return parseLinkValue(`command:${env.RLY_LINK_COMMAND}`, 'RLY_LINK_COMMAND');
|
|
44
52
|
if (env.RLY_PUBLIC_URL) return parseLinkValue(env.RLY_PUBLIC_URL, 'RLY_PUBLIC_URL');
|
|
45
53
|
if (env.RLY_LINK) return parseLinkValue(env.RLY_LINK, 'RLY_LINK');
|
|
46
54
|
if (config.link) return parseLinkValue(config.link, 'config link');
|
|
@@ -48,7 +56,7 @@ export function linkSetting({ args = {}, env = process.env, config = {} } = {})
|
|
|
48
56
|
}
|
|
49
57
|
|
|
50
58
|
/** The setting in the one-string form `__serve` takes on its command line. */
|
|
51
|
-
export const serializeLink = (s) => (s.mode === 'url' ? s.template : s.mode);
|
|
59
|
+
export const serializeLink = (s) => (s.mode === 'url' ? s.template : s.mode === 'command' ? `command:${s.publish}` : s.mode);
|
|
52
60
|
|
|
53
61
|
/** devlink's own binary: RLY_DEVLINK_BIN, then PATH, then its usual install folder. */
|
|
54
62
|
export function findDevlink({ env = process.env, exists = fs.existsSync } = {}) {
|
|
@@ -70,6 +78,27 @@ export function pickDevlinkUrl(stdout) {
|
|
|
70
78
|
return parsed.origin;
|
|
71
79
|
}
|
|
72
80
|
|
|
81
|
+
/**
|
|
82
|
+
* The verified private https origin out of a link provider's output: a plain
|
|
83
|
+
* URL, or JSON with `url` or `records[].url`.
|
|
84
|
+
*/
|
|
85
|
+
export function pickLinkUrl(stdout, name = 'the link command') {
|
|
86
|
+
const text = String(stdout || '').trim();
|
|
87
|
+
let url = text.split('\n').pop().trim();
|
|
88
|
+
if (text.startsWith('{')) {
|
|
89
|
+
let data;
|
|
90
|
+
try { data = JSON.parse(text); } catch { throw new CliError(`${name} printed something that is not JSON.`, 1); }
|
|
91
|
+
url = typeof data.url === 'string' ? data.url : Array.isArray(data.records) ? data.records.map((r) => r && r.url).find((u) => typeof u === 'string') : '';
|
|
92
|
+
}
|
|
93
|
+
if (!url) throw new CliError(`${name} returned no URL for this board.`, 1);
|
|
94
|
+
let parsed;
|
|
95
|
+
try { parsed = new URL(url); } catch { throw new CliError(`${name} returned "${url}", which is not a URL.`, 1); }
|
|
96
|
+
if (parsed.protocol !== 'https:' || isLoopbackHost(parsed.hostname)) throw new CliError(`${name} returned ${url}, which is not a private https URL.`, 1);
|
|
97
|
+
return parsed.origin;
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
const argvFor = (command, port) => String(command).trim().split(/\s+/).map((part) => part.replaceAll('{port}', String(port)));
|
|
101
|
+
|
|
73
102
|
const runFile = (file, args) => new Promise((resolve, reject) => {
|
|
74
103
|
execFile(file, args, { timeout: DEVLINK_TIMEOUT_MS, maxBuffer: 1 << 20 }, (err, stdout, stderr) => {
|
|
75
104
|
if (err) reject(Object.assign(err, { stderr }));
|
|
@@ -89,6 +118,25 @@ export async function resolveLink(setting, port, { env = process.env, exec = run
|
|
|
89
118
|
const origin = new URL(setting.template.replace('{port}', String(port))).origin;
|
|
90
119
|
return { kind: 'url', origin, release: () => {} };
|
|
91
120
|
}
|
|
121
|
+
if (setting.mode === 'command') {
|
|
122
|
+
const [file, ...rest] = argvFor(setting.publish, port);
|
|
123
|
+
const hasPort = setting.publish.includes('{port}');
|
|
124
|
+
let out;
|
|
125
|
+
try {
|
|
126
|
+
out = await exec(file, hasPort ? rest : [...rest, String(port)]);
|
|
127
|
+
} catch (err) {
|
|
128
|
+
const detail = String((err && (err.stderr || err.message)) || err).trim().split('\n').pop();
|
|
129
|
+
throw new CliError(`the link command could not publish port ${port}: ${detail}`, 1);
|
|
130
|
+
}
|
|
131
|
+
const origin = pickLinkUrl(out.stdout);
|
|
132
|
+
const releaseCommand = env.RLY_LINK_RELEASE_COMMAND;
|
|
133
|
+
const release = () => {
|
|
134
|
+
if (!releaseCommand) return;
|
|
135
|
+
const [rfile, ...rrest] = argvFor(releaseCommand, port);
|
|
136
|
+
exec(rfile, releaseCommand.includes('{port}') ? rrest : [...rrest, String(port)]).catch(() => {});
|
|
137
|
+
};
|
|
138
|
+
return { kind: 'command', origin, release };
|
|
139
|
+
}
|
|
92
140
|
const bin = findDevlink({ env, exists });
|
|
93
141
|
if (!bin) {
|
|
94
142
|
if (setting.mode === 'auto') return null;
|
package/src/server/board.js
CHANGED
|
@@ -87,7 +87,7 @@ export async function runBoard({ id, port = 0, open = true, timeoutSec = 86400,
|
|
|
87
87
|
const presenceByRole = { owner: null, collab: null, review: null, read: null };
|
|
88
88
|
let actualPort = 0;
|
|
89
89
|
let url = '';
|
|
90
|
-
// The cross-device origin from a link setting (
|
|
90
|
+
// The cross-device origin from a link setting (a link provider or a URL template), once resolved.
|
|
91
91
|
let publicLink = null;
|
|
92
92
|
const advertisedHost = shareHost();
|
|
93
93
|
const accessFor = (req, reqUrl = null) => {
|
package/src/server/http.js
CHANGED
|
@@ -4,7 +4,7 @@ import path from 'node:path';
|
|
|
4
4
|
|
|
5
5
|
const PROXY_HEADERS = ['forwarded', 'x-forwarded-for', 'x-forwarded-host', 'x-forwarded-proto', 'x-real-ip'];
|
|
6
6
|
|
|
7
|
-
// Security: a local reverse proxy can send a loopback Host (
|
|
7
|
+
// Security: a local reverse proxy can send a loopback Host (a link gateway
|
|
8
8
|
// sends `Host: localhost:PORT`), so a request carrying proxy headers is never the
|
|
9
9
|
// tokenless owner. A proxy that adds none is covered by the control token runBoard
|
|
10
10
|
// requires for the owner while a link is set.
|
package/src/spec/ready.js
CHANGED
|
@@ -17,6 +17,36 @@ function compactError(err) {
|
|
|
17
17
|
return msg.length > 500 ? msg.slice(0, 497) + '...' : msg;
|
|
18
18
|
}
|
|
19
19
|
|
|
20
|
+
// A sandbox in which the browser build of mermaid can parse, but not render.
|
|
21
|
+
function parserContext() {
|
|
22
|
+
const quietConsole = { log() {}, info() {}, warn() {}, error() {}, debug() {} };
|
|
23
|
+
const context = {
|
|
24
|
+
console: quietConsole,
|
|
25
|
+
setTimeout,
|
|
26
|
+
clearTimeout,
|
|
27
|
+
// Mermaid 11's langium parsers (pie, gitGraph, packet, architecture, radar)
|
|
28
|
+
// and its link handling call these browser globals, which a vm context lacks.
|
|
29
|
+
TextEncoder,
|
|
30
|
+
TextDecoder,
|
|
31
|
+
structuredClone,
|
|
32
|
+
URL,
|
|
33
|
+
};
|
|
34
|
+
context.globalThis = context;
|
|
35
|
+
// DOMPurify 3 (bundled in mermaid) builds a stub without addHook or sanitize
|
|
36
|
+
// when window has no document, and mermaid calls both while it parses labels.
|
|
37
|
+
// This document is just enough for DOMPurify to build its full API: with no
|
|
38
|
+
// document.implementation it reports isSupported = false, and then sanitize
|
|
39
|
+
// returns its input unchanged. That is safe only because this instance parses
|
|
40
|
+
// and never renders. The document stays on window, not as a global, so
|
|
41
|
+
// mermaid's own code never takes a DOM path.
|
|
42
|
+
context.window = {
|
|
43
|
+
addEventListener() {},
|
|
44
|
+
document: { nodeType: 9, createElement: () => ({}) },
|
|
45
|
+
Element: function Element() {},
|
|
46
|
+
};
|
|
47
|
+
return vm.createContext(context);
|
|
48
|
+
}
|
|
49
|
+
|
|
20
50
|
async function mermaidValidator() {
|
|
21
51
|
if (mermaidValidatorPromise) return mermaidValidatorPromise;
|
|
22
52
|
mermaidValidatorPromise = (async () => {
|
|
@@ -27,15 +57,7 @@ async function mermaidValidator() {
|
|
|
27
57
|
} catch {
|
|
28
58
|
throw new CliError('mermaid blocks need the vendored parser (vendor/mermaid.min.js is missing).');
|
|
29
59
|
}
|
|
30
|
-
const
|
|
31
|
-
const context = {
|
|
32
|
-
console: quietConsole,
|
|
33
|
-
setTimeout,
|
|
34
|
-
clearTimeout,
|
|
35
|
-
};
|
|
36
|
-
context.globalThis = context;
|
|
37
|
-
context.window = { addEventListener() {} };
|
|
38
|
-
vm.createContext(context);
|
|
60
|
+
const context = parserContext();
|
|
39
61
|
try {
|
|
40
62
|
vm.runInContext(source, context, { filename: sourcePath });
|
|
41
63
|
} catch (err) {
|
package/src/store.js
CHANGED
|
@@ -122,7 +122,7 @@ export function loadRunning(id) {
|
|
|
122
122
|
}
|
|
123
123
|
|
|
124
124
|
// The URL this machine uses to talk to a running board. `url` may be a
|
|
125
|
-
// cross-device link (
|
|
125
|
+
// cross-device link (a link provider, a proxy) that only people open.
|
|
126
126
|
export function controlUrl(running) {
|
|
127
127
|
return running.localUrl || running.url;
|
|
128
128
|
}
|