@beryl-so/cli 0.6.0 → 0.7.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 CHANGED
@@ -26,6 +26,10 @@ npx @beryl-so/cli@latest … # or run one-off without installing
26
26
 
27
27
  From the monorepo (development): `cd cli && npm install && npm run build && npm link`.
28
28
 
29
+ `beryl init` and `beryl mcp` warn (stderr, best-effort) when the running CLI is behind the
30
+ latest npm release — a stale MCP server silently exposes fewer tools. Set
31
+ `BERYL_NO_UPDATE_CHECK=1` to opt out.
32
+
29
33
  ## Authenticate
30
34
 
31
35
  ```bash
@@ -251,11 +255,14 @@ Manage the variables, secrets, and files the agent can use while exploring and r
251
255
  | --- | --- | --- |
252
256
  | `beryl config vars list` | List the project's config variables (visible to the agent during runs) | `config_vars_list` |
253
257
  | `beryl config vars set <key> <value>` | Create or update a config variable | `config_vars_set` |
258
+ | `beryl config vars get <key>` | Show one config variable | `config_vars_get` |
254
259
  | `beryl config vars delete <key>` | Delete a config variable | `config_vars_delete` |
255
260
  | `beryl config secrets list` | List the project's secrets (values are never returned) | `config_secrets_list` |
256
261
  | `beryl config secrets set <key> <value>` | Create a secret (write-only; re-setting a key replaces it) | `config_secrets_set` |
262
+ | `beryl config secrets get <key>` | Show one secret's metadata (the value is never returned) | `config_secrets_get` |
257
263
  | `beryl config secrets delete <key>` | Delete a secret | `config_secrets_delete` |
258
264
  | `beryl config files list` | List files uploaded for the agent to use (e.g. CSVs, upload fixtures) | `config_files_list` |
265
+ | `beryl config files get <file>` | Show one uploaded file's metadata | `config_files_get` |
259
266
  | `beryl config files upload <file>` | Upload a file | `config_files_upload` |
260
267
  | `beryl config files download <file-id>` | Get a short-lived download URL for a file | `config_files_download` |
261
268
  | `beryl config files delete <file-id>` | Delete an uploaded file | `config_files_delete` |
@@ -307,6 +314,7 @@ Disposable email inboxes for testing flows that send mail — signups, OTPs, rec
307
314
  | Command | Summary | MCP tool |
308
315
  | --- | --- | --- |
309
316
  | `beryl inbox create` | Mint a disposable email inbox that Beryl receives mail for | `inbox_create` |
317
+ | `beryl inbox list` | List the workspace's inboxes, newest first | `inbox_list` |
310
318
  | `beryl inbox read <inbox-id>` | Read the latest email from an inbox (waits for one to arrive) | `inbox_read` |
311
319
  | `beryl inbox emails <inbox-id>` | List the emails an inbox has received | `inbox_emails` |
312
320
 
@@ -1,10 +1,10 @@
1
- import fs from "node:fs";
2
1
  import { loadConfig } from "../config.js";
3
2
  import { createContext } from "../context.js";
4
3
  import { CliError, EXIT_OK, EXIT_USAGE, UsageError } from "../errors.js";
5
4
  import { ApiClient } from "../http.js";
6
5
  import { autoFormat, bold, cyan, dim } from "../output.js";
7
6
  import { commandGroups, findCommand, groupSummary } from "../registry/index.js";
7
+ import { cliVersion } from "../version-check.js";
8
8
  import { mcpToolFor } from "./mcp.js";
9
9
  export const GLOBAL_FLAGS = [
10
10
  { name: "version", description: "Print the CLI version and exit", alias: "V" },
@@ -13,15 +13,6 @@ export const GLOBAL_FLAGS = [
13
13
  { name: "token", description: "Personal access token (overrides config/BERYL_API_KEY)", value: true },
14
14
  { name: "help", description: "Show help", alias: "h" },
15
15
  ];
16
- export function cliVersion() {
17
- try {
18
- const pkg = JSON.parse(fs.readFileSync(new URL("../../package.json", import.meta.url), "utf8"));
19
- return pkg.version;
20
- }
21
- catch {
22
- return "unknown";
23
- }
24
- }
25
16
  export function parseArgv(spec, tokens) {
26
17
  const flags = {};
27
18
  const positional = [];
@@ -222,21 +213,47 @@ function groupHelp(group, specs) {
222
213
  lines.push("", `Run ${cyan(`beryl ${group} <subcommand> --help`)} for details.`);
223
214
  return lines.join("\n");
224
215
  }
216
+ // Whether argv[i] is a recognised global flag, and how many tokens it spans (2 when it
217
+ // takes its value from the next token, 1 for boolean/alias/inline `--name=value` forms).
218
+ function globalFlagSpan(argv, i) {
219
+ const tok = argv[i];
220
+ const eq = tok.indexOf("=");
221
+ const name = (eq === -1 ? tok : tok.slice(0, eq)).replace(/^--?/, "");
222
+ const flag = GLOBAL_FLAGS.find((g) => (tok.startsWith("--") ? g.name === name : "alias" in g && g.alias === name));
223
+ if (!flag)
224
+ return 0;
225
+ return "value" in flag && flag.value && eq === -1 ? 2 : 1;
226
+ }
225
227
  export async function runCli(argv) {
228
+ // Global flags are position-independent: collect command words by skipping over
229
+ // recognised global flags (leaving them in place for parseArgv), and stop only at a
230
+ // flag we don't recognise as global — that one belongs to the command.
226
231
  const words = [];
227
- let rest = argv;
228
- for (const tok of argv) {
229
- if (tok.startsWith("-"))
232
+ const wordIndices = [];
233
+ for (let i = 0; i < argv.length; i++) {
234
+ const tok = argv[i];
235
+ if (tok === "--")
230
236
  break;
237
+ if (tok.startsWith("-") && tok !== "-") {
238
+ const span = globalFlagSpan(argv, i);
239
+ if (span === 0)
240
+ break;
241
+ i += span - 1;
242
+ continue;
243
+ }
231
244
  words.push(tok);
245
+ wordIndices.push(i);
232
246
  }
233
- if (argv.includes("--version") || argv.includes("-V") || argv[0] === "version") {
247
+ let rest = argv;
248
+ let restWordIndices = wordIndices;
249
+ if (argv.includes("--version") || argv.includes("-V") || words[0] === "version") {
234
250
  process.stdout.write(cliVersion() + "\n");
235
251
  return EXIT_OK;
236
252
  }
237
253
  if (words[0] === "help") {
238
254
  words.shift();
239
255
  rest = [...words, "--help"];
256
+ restWordIndices = words.map((_, i) => i);
240
257
  }
241
258
  if (words.length === 0) {
242
259
  process.stdout.write(rootHelp() + "\n");
@@ -266,7 +283,10 @@ export async function runCli(argv) {
266
283
  return EXIT_USAGE;
267
284
  }
268
285
  const { spec } = found;
269
- const tokens = rest.slice(found.consumed);
286
+ // Drop the consumed command words wherever they sit — global flags before or between
287
+ // them stay in place for parseArgv.
288
+ const consumedIndices = new Set(restWordIndices.slice(0, found.consumed));
289
+ const tokens = rest.filter((_, i) => !consumedIndices.has(i));
270
290
  let parsed;
271
291
  try {
272
292
  parsed = parseArgv(spec, tokens);
@@ -4,7 +4,7 @@ import { CallToolRequestSchema, ListToolsRequestSchema, } from "@modelcontextpro
4
4
  import { createContext } from "../context.js";
5
5
  import { CliError } from "../errors.js";
6
6
  import { commands } from "../registry/index.js";
7
- import { cliVersion } from "./cli.js";
7
+ import { cliVersion, warnIfStale } from "../version-check.js";
8
8
  export function toolName(spec) {
9
9
  return spec.name.replace(/ /g, "_").replace(/-/g, "_");
10
10
  }
@@ -72,6 +72,9 @@ function toInput(spec, params) {
72
72
  return { args, flags };
73
73
  }
74
74
  export async function serveMcp(baseCtx) {
75
+ // Fire-and-forget staleness warning: a stale MCP server silently exposes fewer
76
+ // tools, and stderr is the one channel a stdio MCP server can safely log to.
77
+ void warnIfStale(cliVersion(), (msg) => console.error(msg));
75
78
  const server = new Server({ name: "beryl", version: cliVersion() }, { capabilities: { tools: {} } });
76
79
  server.setRequestHandler(ListToolsRequestSchema, () => ({
77
80
  tools: mcpTools().map((spec) => ({
@@ -5,6 +5,20 @@
5
5
  // the CLI and another in the docs. Edit here; `init` writes it verbatim.
6
6
  export const BERYL_TEST_SKILL_FILENAME = "SKILL.md";
7
7
  export const BERYL_TEST_SKILL_DIR = "beryl-test";
8
+ // The example plan the skill shows verbatim. Exported so the test suite lints it with
9
+ // lintPlan — the skill's documented shape must pass `beryl tests lint` on the first try.
10
+ export const BERYL_TEST_SKILL_EXAMPLE_PLAN = {
11
+ steps: [
12
+ { action: "goto", url: "https://app.example.com/pricing" },
13
+ {
14
+ action: "expect",
15
+ expect_kind: "have_text",
16
+ selector: "h1",
17
+ expect_text: "Pricing",
18
+ },
19
+ { action: "expect", expect_kind: "visible", selector: "text=Pro plan" },
20
+ ],
21
+ };
8
22
  export const BERYL_TEST_SKILL = `---
9
23
  name: beryl-test
10
24
  description: Author durable, healable end-to-end tests for a web app with Beryl. Use when writing, running, or fixing a Beryl test locally with your own coding agent — drafting the plan over the Playwright MCP, writing the natural-language intent, and running it with \`beryl runs local\`.
@@ -33,6 +47,28 @@ assertion**, a strong **natural-language intent**, and the **local run-fix loop*
33
47
  - **at least one step is an \`expect\`** (a test that asserts nothing is not a test).
34
48
  Optional \`before\` / \`after\` arrays hold setup and teardown; \`after\` runs even when a
35
49
  main step fails, so a create/update/delete flow can clean up the record it made.
50
+
51
+ An \`expect\` step's shape is \`{action: "expect", expect_kind, selector, expect_text}\`:
52
+ - \`expect_kind\` (required) is one of \`visible\`, \`attached\`, \`hidden\`, \`checked\`,
53
+ \`enabled\`, \`disabled\`, \`have_text\`, \`have_value\`, \`have_url\`, \`have_title\`,
54
+ \`have_count\`, \`persisted\`, \`gone\`, \`count_delta\`.
55
+ - \`selector\` is required for every kind except the page-level \`have_url\` /
56
+ \`have_title\` (those assert on the page, not an element).
57
+ - \`expect_text\` carries the expected string for \`have_text\` / \`have_value\` (exact
58
+ match on the element) and \`have_url\` / \`have_title\` (substring match on the page).
59
+ There is no \`value\` field on an expect and no bare \`text\` / \`url\` kind.
60
+ - Two kinds take other fields instead: \`have_count\` needs \`expect_count\`, and
61
+ \`count_delta\` needs \`capture_ref\` + \`expect_delta\` (vs a baseline banked by an
62
+ earlier \`capture_count\` step).
63
+
64
+ A fully valid minimal plan ("the pricing page renders"):
65
+
66
+ \`\`\`json
67
+ ${JSON.stringify(BERYL_TEST_SKILL_EXAMPLE_PLAN, null, 2)
68
+ .split("\n")
69
+ .map((line) => ` ${line}`)
70
+ .join("\n")}
71
+ \`\`\`
36
72
  3. **Validate offline, then create:**
37
73
  \`\`\`
38
74
  beryl tests lint --file plan.json # check the plan against the schema, no network
@@ -60,8 +96,15 @@ observable proof the flow worked. Get this right and everything else follows.
60
96
  "the URL is /pricing" passes even on a blank or broken page that never rendered.
61
97
  Reserve a URL-only assertion for when the URL *is* the outcome (a form that lands on
62
98
  \`/thank-you\`) and no distinctive destination content is available.
63
- - \`expect\` kinds: \`text\` (a string is visible), \`url\` (the URL contains a value), \`gone\`
64
- (an element disappeared e.g. a spinner, or the item you just deleted).
99
+ - The usual outcome kinds: \`visible\` (the success element showed up), \`have_text\` (an
100
+ element's text matches), \`have_url\` (the URL contains a value), \`gone\` (an element
101
+ disappeared — e.g. a spinner, or the item you just deleted). §1 has the full
102
+ \`expect_kind\` list and the step shape.
103
+ - **\`have_text\` is an EXACT full-text match on the selector's element** — asserting
104
+ \`have_text: "Documentation"\` on \`body\` fails, because \`body\`'s text includes all the
105
+ nav chrome. Target the specific element that carries the text (the \`h1\`, the toast),
106
+ or assert the page instead (\`have_title\`, which is a substring match). To check "this
107
+ string is visible somewhere", use \`expect_kind: "visible"\` with a \`text=…\` selector.
65
108
  - **If you can't name a success signal, the flow is not test-worthy.** Don't bank a test
66
109
  that verifies nothing. Explore a different flow instead.
67
110
  - **Don't work around a real app failure to make a test go green.** If the flow is
@@ -3,13 +3,16 @@ import path from "node:path";
3
3
  import { UsageError } from "../errors.js";
4
4
  import { arg, flagBool, flagStr, projectPath } from "./util.js";
5
5
  const configPath = (ws, p) => `${projectPath(ws, p)}/config`;
6
- async function resolveByKey(rows, value, kind) {
6
+ function findByKey(rows, value, kind) {
7
7
  const byId = rows.find((r) => r.id === value);
8
8
  if (byId)
9
- return byId.id;
9
+ return byId;
10
10
  const byKey = rows.filter((r) => r.key === value);
11
11
  if (byKey.length === 1)
12
- return byKey[0].id;
12
+ return byKey[0];
13
+ if (byKey.length > 1) {
14
+ throw new UsageError(`Multiple ${kind}s have key "${value}" (per-environment copies) — use the id instead`);
15
+ }
13
16
  throw new UsageError(`No ${kind} with key or id "${value}"`);
14
17
  }
15
18
  export const configCommands = [
@@ -51,17 +54,30 @@ export const configCommands = [
51
54
  };
52
55
  },
53
56
  },
57
+ {
58
+ name: "config vars get",
59
+ summary: "Show one config variable",
60
+ scope: "project",
61
+ args: [{ name: "key", description: "Variable key or id", required: true }],
62
+ async run(ctx, input) {
63
+ const { workspaceId, projectId } = await ctx.requireProject(input);
64
+ const rows = (await ctx.client.get(`${configPath(workspaceId, projectId)}/variables`));
65
+ return { data: findByKey(rows, arg(input, "key"), "variable") };
66
+ },
67
+ },
54
68
  {
55
69
  name: "config vars delete",
56
70
  summary: "Delete a config variable",
57
71
  scope: "project",
58
72
  args: [{ name: "key", description: "Variable key or id", required: true }],
73
+ flags: [{ name: "force", type: "boolean", description: "Skip the confirmation prompt" }],
59
74
  async run(ctx, input) {
60
75
  const { workspaceId, projectId } = await ctx.requireProject(input);
61
76
  const base = `${configPath(workspaceId, projectId)}/variables`;
62
77
  const rows = (await ctx.client.get(base));
63
- const id = await resolveByKey(rows, arg(input, "key"), "variable");
64
- await ctx.client.del(`${base}/${id}`);
78
+ const row = findByKey(rows, arg(input, "key"), "variable");
79
+ await ctx.confirm(`Delete config variable ${row.key}?`, flagBool(input, "force"));
80
+ await ctx.client.del(`${base}/${row.id}`);
65
81
  return { human: "Deleted." };
66
82
  },
67
83
  },
@@ -94,17 +110,30 @@ export const configCommands = [
94
110
  return { data: await ctx.client.post(base, { key, value, environment_id: envId }) };
95
111
  },
96
112
  },
113
+ {
114
+ name: "config secrets get",
115
+ summary: "Show one secret's metadata (the value is never returned)",
116
+ scope: "project",
117
+ args: [{ name: "key", description: "Secret key or id", required: true }],
118
+ async run(ctx, input) {
119
+ const { workspaceId, projectId } = await ctx.requireProject(input);
120
+ const rows = (await ctx.client.get(`${configPath(workspaceId, projectId)}/secrets`));
121
+ return { data: findByKey(rows, arg(input, "key"), "secret") };
122
+ },
123
+ },
97
124
  {
98
125
  name: "config secrets delete",
99
126
  summary: "Delete a secret",
100
127
  scope: "project",
101
128
  args: [{ name: "key", description: "Secret key or id", required: true }],
129
+ flags: [{ name: "force", type: "boolean", description: "Skip the confirmation prompt" }],
102
130
  async run(ctx, input) {
103
131
  const { workspaceId, projectId } = await ctx.requireProject(input);
104
132
  const base = `${configPath(workspaceId, projectId)}/secrets`;
105
133
  const rows = (await ctx.client.get(base));
106
- const id = await resolveByKey(rows, arg(input, "key"), "secret");
107
- await ctx.client.del(`${base}/${id}`);
134
+ const row = findByKey(rows, arg(input, "key"), "secret");
135
+ await ctx.confirm(`Delete secret ${row.key}?`, flagBool(input, "force"));
136
+ await ctx.client.del(`${base}/${row.id}`);
108
137
  return { human: "Deleted." };
109
138
  },
110
139
  },
@@ -117,6 +146,27 @@ export const configCommands = [
117
146
  return { data: await ctx.client.get(`${configPath(workspaceId, projectId)}/files`) };
118
147
  },
119
148
  },
149
+ {
150
+ name: "config files get",
151
+ summary: "Show one uploaded file's metadata",
152
+ scope: "project",
153
+ args: [{ name: "file", description: "File name or id", required: true }],
154
+ async run(ctx, input) {
155
+ const { workspaceId, projectId } = await ctx.requireProject(input);
156
+ const rows = (await ctx.client.get(`${configPath(workspaceId, projectId)}/files`));
157
+ const value = arg(input, "file");
158
+ const byId = rows.find((r) => r.id === value);
159
+ if (byId)
160
+ return { data: byId };
161
+ const byName = rows.filter((r) => r.name === value);
162
+ if (byName.length === 1)
163
+ return { data: byName[0] };
164
+ if (byName.length > 1) {
165
+ throw new UsageError(`Multiple files are named "${value}" (per-environment copies) — use the id instead`);
166
+ }
167
+ throw new UsageError(`No file with name or id "${value}"`);
168
+ },
169
+ },
120
170
  {
121
171
  name: "config files upload",
122
172
  summary: "Upload a file",
@@ -126,8 +176,18 @@ export const configCommands = [
126
176
  async run(ctx, input) {
127
177
  const { workspaceId, projectId } = await ctx.requireProject(input);
128
178
  const file = arg(input, "file");
179
+ let bytes;
180
+ try {
181
+ bytes = new Uint8Array(fs.readFileSync(file));
182
+ }
183
+ catch (err) {
184
+ const code = err.code;
185
+ if (code === "ENOENT")
186
+ throw new UsageError(`file not found: ${file}`);
187
+ throw new UsageError(`cannot read ${file} (${code ?? err.message})`);
188
+ }
129
189
  const form = new FormData();
130
- form.set("file", new Blob([fs.readFileSync(file)]), path.basename(file));
190
+ form.set("file", new Blob([bytes]), path.basename(file));
131
191
  const envId = flagStr(input, "env");
132
192
  if (envId)
133
193
  form.set("environment_id", envId);
@@ -53,6 +53,18 @@ export const inboxCommands = [
53
53
  };
54
54
  },
55
55
  },
56
+ {
57
+ name: "inbox list",
58
+ summary: "List the workspace's inboxes, newest first",
59
+ description: "Every inbox the workspace has minted with `beryl inbox create`. Expired inboxes " +
60
+ "stop receiving and are hard-deleted by a background sweep, so they drop off " +
61
+ "this list shortly after their TTL.",
62
+ scope: "workspace",
63
+ async run(ctx, input) {
64
+ const ws = await ctx.requireWorkspace(input);
65
+ return { data: await ctx.client.get(`/workspaces/${ws}/inboxes`) };
66
+ },
67
+ },
56
68
  {
57
69
  name: "inbox read",
58
70
  summary: "Read the latest email from an inbox (waits for one to arrive)",
@@ -4,12 +4,17 @@ import { BERYL_TEST_SKILL, BERYL_TEST_SKILL_DIR, BERYL_TEST_SKILL_FILENAME, } fr
4
4
  import { LOCAL_CONFIG_FILENAME, loadConfig } from "../config.js";
5
5
  import { CliError, UsageError } from "../errors.js";
6
6
  import { ApiClient } from "../http.js";
7
- import { bold, cyan, dim, green } from "../output.js";
7
+ import { bold, cyan, dim, green, yellow } from "../output.js";
8
+ import { cliVersion, warnIfStale } from "../version-check.js";
8
9
  import { authCommands } from "./auth.js";
9
10
  import { flagBool, flagStr } from "./util.js";
11
+ // Pinned to @latest (like the Playwright entry below) — an unpinned spec lets npx
12
+ // serve whatever stale global/cache install already resolves, so the agent's MCP
13
+ // server would silently miss newer tools. mergeMcpConfig compares entries verbatim,
14
+ // so re-running init also upgrades an old unpinned entry in place.
10
15
  const MCP_SERVER_ENTRY = {
11
16
  command: "npx",
12
- args: ["-y", "@beryl-so/cli", "mcp"],
17
+ args: ["-y", "@beryl-so/cli@latest", "mcp"],
13
18
  };
14
19
  const PLAYWRIGHT_SERVER_ENTRY = {
15
20
  command: "npx",
@@ -263,6 +268,9 @@ export const initCommands = [
263
268
  ? `\n\nPlaywright MCP is wired — your coding agent can explore the site locally ` +
264
269
  `and push tests with ${cyan("beryl tests create")}.`
265
270
  : "");
271
+ // The .mcp.json entry is pinned to @latest, but a global install / old npx cache
272
+ // still wins resolution — so tell the user when the CLI they just ran is stale.
273
+ await warnIfStale(cliVersion(), (msg) => ctx.err(yellow(msg)));
266
274
  return {
267
275
  data: { workspace: workspaceId ?? null, project: projectId ?? null, editors },
268
276
  human: nextSteps,
@@ -1,9 +1,23 @@
1
1
  import fs from "node:fs";
2
2
  import { UsageError } from "../errors.js";
3
3
  import { lintPlan } from "../lint.js";
4
+ import { table } from "../output.js";
4
5
  import { ACTION_PLAN_SCHEMA } from "../schema.generated.js";
5
6
  import { arg, argList, flagBool, flagNum, flagStr, projectPath, readJsonFlag } from "./util.js";
6
7
  const testPath = (ws, p, id) => `${projectPath(ws, p)}/tests/${id}`;
8
+ // The concise human table for `tests list` — the full TestResponse is a 24-column
9
+ // firehose of internal ids that wraps unreadably in a normal terminal. `--wide`
10
+ // (and `--json`) still expose every field.
11
+ const LIST_COLUMNS = ["title", "status", "id", "last_result_status", "last_run_at"];
12
+ function conciseTestRow(row) {
13
+ return {
14
+ title: row.nl_title,
15
+ status: row.quarantined ? "quarantined" : row.is_active ? "active" : "inactive",
16
+ id: row.id,
17
+ last_result_status: row.last_result_status,
18
+ last_run_at: row.last_run_at,
19
+ };
20
+ }
7
21
  export const testCommands = [
8
22
  {
9
23
  name: "tests lint",
@@ -33,17 +47,24 @@ export const testCommands = [
33
47
  {
34
48
  name: "tests list",
35
49
  summary: "List the project's tests with their latest result",
50
+ description: "Prints a concise table by default (title / status / id / last result / last run). " +
51
+ "Pass --wide for every field, or --json for the raw records.",
36
52
  scope: "project",
37
53
  groupDefault: true,
38
54
  groupSummary: "Author, inspect, version, and heal a project's tests — the checks Beryl runs on each run.",
39
- flags: [{ name: "env", type: "string", description: "Filter by environment id" }],
55
+ flags: [
56
+ { name: "env", type: "string", description: "Filter by environment id" },
57
+ { name: "wide", type: "boolean", description: "Show all columns, not the concise default" },
58
+ ],
40
59
  async run(ctx, input) {
41
60
  const { workspaceId, projectId } = await ctx.requireProject(input);
42
- return {
43
- data: await ctx.client.get(`${projectPath(workspaceId, projectId)}/tests`, {
44
- environment_id: flagStr(input, "env"),
45
- }),
46
- };
61
+ const data = (await ctx.client.get(`${projectPath(workspaceId, projectId)}/tests`, {
62
+ environment_id: flagStr(input, "env"),
63
+ }));
64
+ if (flagBool(input, "wide"))
65
+ return { data };
66
+ // `data` stays the full records so --json is unchanged; only the human table is trimmed.
67
+ return { data, human: table(data.map(conciseTestRow), LIST_COLUMNS) };
47
68
  },
48
69
  },
49
70
  {
@@ -29,11 +29,24 @@ export function flagNum(input, name) {
29
29
  throw new UsageError(`--${name} must be a number`);
30
30
  return n;
31
31
  }
32
+ /** Read a local file for a flag/arg, turning fs errors (ENOENT, EACCES, EISDIR…) into a
33
+ * clean usage message instead of a raw Node stack. */
34
+ export function readFileArg(path, label) {
35
+ try {
36
+ return fs.readFileSync(path === "-" ? 0 : path, "utf8");
37
+ }
38
+ catch (err) {
39
+ const code = err.code;
40
+ if (code === "ENOENT")
41
+ throw new UsageError(`${label}: file not found: ${path}`);
42
+ throw new UsageError(`${label}: cannot read ${path} (${code ?? err.message})`);
43
+ }
44
+ }
32
45
  export function readJsonFlag(input, name) {
33
46
  const file = flagStr(input, name);
34
47
  if (!file)
35
48
  throw new UsageError(`--${name} <file> is required`);
36
- const text = file === "-" ? fs.readFileSync(0, "utf8") : fs.readFileSync(file, "utf8");
49
+ const text = readFileArg(file, `--${name}`);
37
50
  try {
38
51
  return JSON.parse(text);
39
52
  }
@@ -0,0 +1,65 @@
1
+ import fs from "node:fs";
2
+ // Best-effort "are we stale?" check against the npm registry. The `.mcp.json` entry
3
+ // `init` writes pins `@beryl-so/cli@latest`, but a user with a global install (or an
4
+ // old npx cache) can still be running a stale CLI — and an MCP server that's behind
5
+ // silently exposes fewer tools. So `init` and `beryl mcp` warn when the running
6
+ // version is behind the registry's `latest`. Never fatal: offline, a slow registry,
7
+ // or an unparseable response just skips the warning.
8
+ const REGISTRY_LATEST_URL = "https://registry.npmjs.org/@beryl-so/cli/latest";
9
+ const TIMEOUT_MS = 1500;
10
+ export function cliVersion() {
11
+ try {
12
+ const pkg = JSON.parse(fs.readFileSync(new URL("../package.json", import.meta.url), "utf8"));
13
+ return pkg.version;
14
+ }
15
+ catch {
16
+ return "unknown";
17
+ }
18
+ }
19
+ // Numeric-triple compare; returns true only when `current` is strictly behind
20
+ // `latest`. Anything non-numeric (dev builds, "unknown", dist-tags) compares as
21
+ // not-behind so we never nag on unparseable versions.
22
+ export function isBehind(current, latest) {
23
+ const parse = (v) => {
24
+ const m = /^(\d+)\.(\d+)\.(\d+)/.exec(v.trim());
25
+ return m ? [Number(m[1]), Number(m[2]), Number(m[3])] : null;
26
+ };
27
+ const cur = parse(current);
28
+ const lat = parse(latest);
29
+ if (!cur || !lat)
30
+ return false;
31
+ for (let i = 0; i < 3; i++) {
32
+ if (cur[i] !== lat[i])
33
+ return cur[i] < lat[i];
34
+ }
35
+ return false;
36
+ }
37
+ /** The registry's `latest` version, or null when it can't be fetched quickly. */
38
+ export async function fetchLatestVersion() {
39
+ try {
40
+ const res = await fetch(REGISTRY_LATEST_URL, {
41
+ signal: AbortSignal.timeout(TIMEOUT_MS),
42
+ });
43
+ if (!res.ok)
44
+ return null;
45
+ const body = (await res.json());
46
+ return typeof body.version === "string" ? body.version : null;
47
+ }
48
+ catch {
49
+ return null;
50
+ }
51
+ }
52
+ /**
53
+ * Warn (via `warn`) when `current` is behind the registry's `latest`.
54
+ * Best-effort and quiet on any failure — safe to await on every startup.
55
+ * BERYL_NO_UPDATE_CHECK=1 opts out entirely (no network call).
56
+ */
57
+ export async function warnIfStale(current, warn) {
58
+ if (process.env.BERYL_NO_UPDATE_CHECK)
59
+ return;
60
+ const latest = await fetchLatestVersion();
61
+ if (latest && isBehind(current, latest)) {
62
+ warn(`@beryl-so/cli ${current} is behind the latest release ${latest} — ` +
63
+ `some commands/MCP tools may be missing. Upgrade with: npm i -g @beryl-so/cli@latest`);
64
+ }
65
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@beryl-so/cli",
3
- "version": "0.6.0",
3
+ "version": "0.7.1",
4
4
  "description": "Beryl on the command line — projects, runs, the exploring agent, and an MCP server over the same commands.",
5
5
  "license": "MIT",
6
6
  "type": "module",