@khanglvm/relay 0.23.0 → 0.23.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/docs/AGENT.md CHANGED
@@ -849,7 +849,9 @@ call rather than calling it repeatedly in a loop.
849
849
 
850
850
  - Prefer `--detach` + `rly wait` if your shell tool kills long commands.
851
851
  - Don't pass `--no-open` for real users — the browser tab opening *is* the
852
- notification. Use it only in tests.
852
+ notification. Use it only in tests. Under T3 Code or Sushi, Relay already
853
+ skips the tab, because the person reads the board from another device.
854
+ Give them the printed URL.
853
855
  - Quote JSON carefully; prefer writing a spec file or piping via `--file -`.
854
856
  - Use stable `id`s on questions so your follow-up logic reads clean keys.
855
857
  - `rly result <id>` while a board is open returns the live draft — useful to
package/docs/SETUP.md CHANGED
@@ -75,6 +75,13 @@ charts and diagrams and loads them only when a board needs them. Local
75
75
  file links open referenced paths in the default app; `RLY_OPEN_CMD` overrides
76
76
  the opener.
77
77
 
78
+ A new board opens in this machine's browser, except under an agent host the
79
+ person drives from another device: T3 Code (`T3CODE_THREAD_ID` or
80
+ `T3CODE_HOME` set) or Sushi (`SUSHI_BOT_ID` or `SUSHI_HOME` set). There the
81
+ board shows in the host app and through the printed URL. `RLY_OPEN=1` or
82
+ `RLY_OPEN=0` sets the default either way, and `--open` or `--no-open` decides
83
+ for one board.
84
+
78
85
  ## Migration from quest-board
79
86
 
80
87
  relay was formerly `@khanglvm/quest-board` (CLI: `qbd`) — that package is
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@khanglvm/relay",
3
- "version": "0.23.0",
3
+ "version": "0.23.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, …): ask users structured questions, present interactive visuals, collect inline comments, read answers as JSON — 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/help.js CHANGED
@@ -79,7 +79,8 @@ USAGE
79
79
 
80
80
  COMMON FLAGS
81
81
  --title <s> --intro <s> --html-file <f> --height <px> --submit-label <s>
82
- --timeout <sec> (default 86400; 0 = none) --port <n> --no-open --detach --display-only
82
+ --timeout <sec> (default 86400; 0 = none) --port <n> --open | --no-open --detach --display-only
83
+ no browser tab by default under T3 Code or Sushi; $RLY_OPEN=1|0 sets the default
83
84
  --devlink | --no-devlink | --public-url <url> where the board link points (see rly config link)
84
85
 
85
86
  EXIT CODES 0 submitted/acknowledged · 2 timeout · 3 cancelled · 4 usage · 5 not found
package/src/cli/io.js CHANGED
@@ -4,6 +4,7 @@ import fs from 'node:fs';
4
4
  import path from 'node:path';
5
5
  import { envFileRoots, expandHome } from '../file-access.js';
6
6
  import { linkSetting, loadConfig, serializeLink } from '../link.js';
7
+ import { autoOpenDefault } from '../open.js';
7
8
  import { runBoard } from '../server/index.js';
8
9
  import { assertSpecReady, questionFromInline } from '../spec/index.js';
9
10
  import { HOME, loadBoard, loadRunning, saveBoard, saveResultFile } from '../store.js';
@@ -158,7 +159,7 @@ export async function runOrDetach(record, args) {
158
159
  await assertSpecReady(record.spec);
159
160
  const timeoutSec = args.timeout !== undefined ? Math.max(0, Number.parseInt(args.timeout, 10) || 0) : DEFAULT_BOARD_TIMEOUT_SEC;
160
161
  const port = args.port !== undefined ? Number.parseInt(args.port, 10) || 0 : 0;
161
- const open = args.open !== false;
162
+ const open = args.open === true || (args.open !== false && autoOpenDefault());
162
163
  const link = linkSetting({ args, config: loadConfig(HOME) });
163
164
 
164
165
  // Push-wake: persist the agent's --on-result command on the record so BOTH
@@ -112,9 +112,24 @@ export function checkReadable(access, raw, { allowDirectory = false } = {}) {
112
112
  // O_NONBLOCK keeps a file swapped for a FIFO from hanging the open; the identity check below then refuses it.
113
113
  const OPEN_FLAGS = fs.constants.O_RDONLY | (fs.constants.O_NOFOLLOW ?? 0) | (fs.constants.O_NONBLOCK ?? 0);
114
114
 
115
- /** True when `file` still resolves to itself, inside the roots, and is the very file `fd` has open. */
115
+ /**
116
+ * The path the kernel holds for an open descriptor, or null where Node cannot ask (macOS, Windows).
117
+ * Linux keeps it in /proc/self/fd, which no rename of a parent folder can fake.
118
+ */
119
+ function openedPath(fd) {
120
+ if (process.platform !== 'linux') return null;
121
+ try { return fs.readlinkSync(`/proc/self/fd/${fd}`); } catch { return null; }
122
+ }
123
+
124
+ /**
125
+ * True when `file` still resolves to itself, inside the roots, and is the very file `fd` has open.
126
+ * Known open risk on macOS and Windows: the name checks below walk the path again, so a writer inside a
127
+ * root who swaps a parent folder for a symlink and back between those calls can still win the race.
128
+ */
116
129
  function isStillTheCheckedFile(access, file, fd) {
117
130
  try {
131
+ const opened = openedPath(fd);
132
+ if (opened !== null && opened !== file) return false;
118
133
  if (fs.realpathSync.native(file) !== file || !isInsideRoots(file, access.roots)) return false;
119
134
  const open = fs.fstatSync(fd);
120
135
  const named = fs.statSync(file);
package/src/open.js CHANGED
@@ -7,6 +7,24 @@ import { spawn } from 'node:child_process';
7
7
  // RLY_OPEN_CMD overrides the platform opener with a custom command — the target
8
8
  // is passed as its sole argument ("$1"). Power users can point it at a chooser;
9
9
  // the test suite points it at a no-op so opening a file launches nothing.
10
+ // Agent hosts the person drives from another device (T3 Code, Sushi). A tab
11
+ // opened on this Mac lands on a screen nobody is watching, and the board is
12
+ // already in front of the person through the host's own view of it.
13
+ const REMOTE_AGENT_HOST_VARS = ['T3CODE_THREAD_ID', 'T3CODE_HOME', 'SUSHI_BOT_ID', 'SUSHI_HOME'];
14
+
15
+ /**
16
+ * Whether a new board opens in this machine's browser when the caller passed
17
+ * neither --open nor --no-open. RLY_OPEN (1/0, on/off, true/false, yes/no)
18
+ * decides when set; otherwise boards stay closed under a remote agent host.
19
+ * @param {NodeJS.ProcessEnv} [env]
20
+ */
21
+ export function autoOpenDefault(env = process.env) {
22
+ const forced = String(env.RLY_OPEN ?? '').trim().toLowerCase();
23
+ if (['1', 'on', 'true', 'yes'].includes(forced)) return true;
24
+ if (['0', 'off', 'false', 'no'].includes(forced)) return false;
25
+ return !REMOTE_AGENT_HOST_VARS.some((name) => env[name]);
26
+ }
27
+
10
28
  export function openUrl(url) {
11
29
  try {
12
30
  const custom = process.env.RLY_OPEN_CMD;
package/src/store.js CHANGED
@@ -62,6 +62,8 @@ export function boardFileRoots(record) {
62
62
  * @param {{ fileRoots?: string[], retentionDays?: number | string | boolean }} [options] `fileRoots`: the roots the spec was read under; the live server opens only files inside them. `retentionDays`: how long old boards stay (see `resolveRetentionDays`)
63
63
  */
64
64
  export function createBoard(spec, { fileRoots, retentionDays } = {}) {
65
+ // A bad retention setting throws here, before any file is written.
66
+ const days = resolveRetentionDays(retentionDays);
65
67
  ensureDirs();
66
68
  const record = {
67
69
  id: newId(),
@@ -77,7 +79,7 @@ export function createBoard(spec, { fileRoots, retentionDays } = {}) {
77
79
  result: null,
78
80
  };
79
81
  saveBoard(record);
80
- pruneOldBoards(resolveRetentionDays(retentionDays));
82
+ pruneOldBoards(days);
81
83
  return record;
82
84
  }
83
85