@beryl-so/cli 0.34.3 → 0.34.4
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/dist/adapters/mcp.js +48 -7
- package/dist/commands/auth.js +1 -1
- package/dist/context.js +19 -4
- package/dist/registry/index.js +4 -0
- package/package.json +1 -1
package/dist/adapters/mcp.js
CHANGED
|
@@ -18,29 +18,68 @@ export function mcpTools() {
|
|
|
18
18
|
return commands.filter((c) => !c.interactive && !c.hidden && !c.mcpHidden && c.name !== "mcp");
|
|
19
19
|
}
|
|
20
20
|
const mcpToolNames = new Set(mcpTools().map(toolName));
|
|
21
|
+
const toolByCommand = new Map(mcpTools().map((spec) => [spec.name, toolName(spec)]));
|
|
22
|
+
const flagNames = new Set(commands.flatMap((spec) => (spec.flags ?? []).map((f) => f.name)));
|
|
21
23
|
/** The tool name a command is exposed as under `beryl mcp`, or undefined if it isn't exposed. */
|
|
22
24
|
export function mcpToolFor(spec) {
|
|
23
25
|
const name = toolName(spec);
|
|
24
26
|
return mcpToolNames.has(name) ? name : undefined;
|
|
25
27
|
}
|
|
28
|
+
/** `[beryl] tests list ...` as its tool name plus the rest, or undefined when the words are
|
|
29
|
+
* no MCP tool (login, init, mcp): those are real terminal instructions and must stay. */
|
|
30
|
+
function commandToTool(text) {
|
|
31
|
+
const words = text.trim().split(/\s+/);
|
|
32
|
+
if (words[0] === "beryl")
|
|
33
|
+
words.shift();
|
|
34
|
+
for (const n of [3, 2, 1]) {
|
|
35
|
+
const tool = toolByCommand.get(words.slice(0, n).join(" "));
|
|
36
|
+
if (tool)
|
|
37
|
+
return [tool, ...words.slice(n)].join(" ");
|
|
38
|
+
}
|
|
39
|
+
return undefined;
|
|
40
|
+
}
|
|
41
|
+
function flagsToParams(text, wrap) {
|
|
42
|
+
return text
|
|
43
|
+
.replace(/--json\b/g, "JSON output (always on over MCP)")
|
|
44
|
+
.replace(/--no-([a-z][a-z-]*)/g, (_, name) => flagNames.has(`no-${name}`) ? wrap(`no-${name}`) : wrap(`${name}: false`))
|
|
45
|
+
.replace(/--([a-z][a-z-]*)/g, (_, name) => wrap(name));
|
|
46
|
+
}
|
|
47
|
+
/** Registry text is written for `beryl --help`; the agent sees JSON parameters and tool
|
|
48
|
+
* names, so `--wide` becomes `wide`, `beryl groups list` becomes `groups_list`, and a
|
|
49
|
+
* command that only exists in a terminal is left verbatim. */
|
|
50
|
+
export function toMcpDialect(text) {
|
|
51
|
+
return text.replace(/`[^`]*`|[^`]+/g, (segment) => {
|
|
52
|
+
if (segment.startsWith("`")) {
|
|
53
|
+
const inner = segment.slice(1, -1);
|
|
54
|
+
const asTool = commandToTool(inner);
|
|
55
|
+
if (asTool === undefined && inner.startsWith("beryl "))
|
|
56
|
+
return segment;
|
|
57
|
+
return `\`${flagsToParams(asTool ?? inner, (n) => n)}\``;
|
|
58
|
+
}
|
|
59
|
+
const prose = segment.replace(/\bberyl( [a-z][a-z-]*){1,3}(?=$|[^a-z-])/g, (command) => commandToTool(command) ?? command);
|
|
60
|
+
return flagsToParams(prose, (n) => `\`${n}\``);
|
|
61
|
+
});
|
|
62
|
+
}
|
|
26
63
|
export function toolInputSchema(spec) {
|
|
27
64
|
const properties = {};
|
|
28
65
|
const required = [];
|
|
29
66
|
for (const a of spec.args ?? []) {
|
|
67
|
+
const description = toMcpDialect(a.description);
|
|
30
68
|
properties[a.name] = a.variadic
|
|
31
|
-
? { type: "array", items: { type: "string" }, description
|
|
32
|
-
: { type: "string", description
|
|
69
|
+
? { type: "array", items: { type: "string" }, description }
|
|
70
|
+
: { type: "string", description };
|
|
33
71
|
if (a.required)
|
|
34
72
|
required.push(a.name);
|
|
35
73
|
}
|
|
36
74
|
for (const f of spec.flags ?? []) {
|
|
37
75
|
const withDefault = f.default !== undefined ? { default: f.default } : {};
|
|
76
|
+
const description = toMcpDialect(f.mcpDescription ?? f.description);
|
|
38
77
|
properties[f.name] =
|
|
39
78
|
f.type === "strings"
|
|
40
|
-
? { type: "array", items: { type: "string" }, description
|
|
79
|
+
? { type: "array", items: { type: "string" }, description, ...withDefault }
|
|
41
80
|
: {
|
|
42
81
|
type: f.type,
|
|
43
|
-
description
|
|
82
|
+
description,
|
|
44
83
|
...(f.enum ? { enum: f.enum } : {}),
|
|
45
84
|
...withDefault,
|
|
46
85
|
};
|
|
@@ -124,7 +163,7 @@ export function exampleArgs(spec, example) {
|
|
|
124
163
|
return Object.keys(out).length ? out : null;
|
|
125
164
|
}
|
|
126
165
|
export function toolDescription(spec) {
|
|
127
|
-
const base = spec.description ? `${spec.summary}. ${spec.description}` : spec.summary;
|
|
166
|
+
const base = toMcpDialect(spec.description ? `${spec.summary}. ${spec.description}` : spec.summary);
|
|
128
167
|
const lines = (spec.examples ?? [])
|
|
129
168
|
.map((e) => exampleArgs(spec, e))
|
|
130
169
|
.filter((a) => a !== null)
|
|
@@ -251,7 +290,9 @@ export function mcpInstructions() {
|
|
|
251
290
|
"run-fix loop) ships as both the beryl-test skill and the `guide` tool — same " +
|
|
252
291
|
`content. If a beryl-test skill stating v${version} is already loaded, do not ` +
|
|
253
292
|
"call `guide`; if no beryl-test skill is available or it states another version, " +
|
|
254
|
-
"call `guide` before authoring your first test plan."
|
|
293
|
+
"call `guide` before authoring your first test plan. " +
|
|
294
|
+
"An account can hold several workspaces and projects: call `projects_list` first " +
|
|
295
|
+
"and pass `project` (an id is enough) on every project-scoped tool, or the call fails.");
|
|
255
296
|
}
|
|
256
297
|
export async function serveMcp(baseCtx) {
|
|
257
298
|
setSurface("mcp");
|
|
@@ -300,7 +341,7 @@ export async function serveMcp(baseCtx) {
|
|
|
300
341
|
return toolResult(result, lines);
|
|
301
342
|
}
|
|
302
343
|
catch (err) {
|
|
303
|
-
const message = err instanceof CliError ? err.message : String(err);
|
|
344
|
+
const message = toMcpDialect(err instanceof CliError ? err.message : String(err));
|
|
304
345
|
return {
|
|
305
346
|
content: [{ type: "text", text: [...lines, message].join("\n") }],
|
|
306
347
|
isError: true,
|
package/dist/commands/auth.js
CHANGED
|
@@ -186,7 +186,7 @@ export const authCommands = [
|
|
|
186
186
|
description: "Creates a passwordless account for the email and sends it a 6-digit code. " +
|
|
187
187
|
"Finish with `beryl login --email <addr> --code <the 6 digits>`, which verifies " +
|
|
188
188
|
"the account, creates its workspace, and signs the CLI in. With an inbox from " +
|
|
189
|
-
"`beryl
|
|
189
|
+
"`beryl mailbox create` as the address, an agent can provision a fresh account " +
|
|
190
190
|
"end-to-end with no human at a prompt.",
|
|
191
191
|
flags: [
|
|
192
192
|
{
|
package/dist/context.js
CHANGED
|
@@ -18,6 +18,23 @@ async function pickOne(ctx, candidates, kind, usageMessage) {
|
|
|
18
18
|
}
|
|
19
19
|
return candidates[n - 1].id;
|
|
20
20
|
}
|
|
21
|
+
// Over MCP there is no --flag and no env var to set: the only fix is a JSON parameter on
|
|
22
|
+
// every call, and a project id alone already resolves its workspace.
|
|
23
|
+
function ambiguousMessage(ctx, kind, candidates) {
|
|
24
|
+
const rows = candidates.map((c) => ` ${c.id} ${c.name ?? c.root_url ?? ""}`).join("\n");
|
|
25
|
+
let how;
|
|
26
|
+
if (ctx.mcp) {
|
|
27
|
+
how =
|
|
28
|
+
kind === "workspace"
|
|
29
|
+
? 'pass "workspace": "<id>" on each call, or "project": "<project id>", which implies its workspace:'
|
|
30
|
+
: 'pass "project": "<id>" on every project-scoped call (a project id alone is enough, no workspace needed):';
|
|
31
|
+
}
|
|
32
|
+
else {
|
|
33
|
+
const forms = kind === "workspace" ? "<id|name>" : "<id|name|url>";
|
|
34
|
+
how = `pass --${kind} ${forms} or set BERYL_${kind.toUpperCase()}:`;
|
|
35
|
+
}
|
|
36
|
+
return `Multiple ${kind}s: ${how}\n${rows}`;
|
|
37
|
+
}
|
|
21
38
|
function matchByName(candidates, value, kind) {
|
|
22
39
|
const lower = value.toLowerCase();
|
|
23
40
|
const matches = candidates.filter((c) => c.name?.toLowerCase() === lower ||
|
|
@@ -82,8 +99,7 @@ export function createContext(options) {
|
|
|
82
99
|
throw new CliError("You have no workspaces yet — create one with `beryl workspaces create`");
|
|
83
100
|
}
|
|
84
101
|
else {
|
|
85
|
-
workspaceCache = await pickOne(ctx, workspaces, "workspace", "
|
|
86
|
-
workspaces.map((w) => ` ${w.id} ${w.name ?? ""}`).join("\n"));
|
|
102
|
+
workspaceCache = await pickOne(ctx, workspaces, "workspace", ambiguousMessage(ctx, "workspace", workspaces));
|
|
87
103
|
}
|
|
88
104
|
return workspaceCache;
|
|
89
105
|
},
|
|
@@ -121,8 +137,7 @@ export function createContext(options) {
|
|
|
121
137
|
"`beryl projects create <url>` (add --no-explore to author tests yourself).");
|
|
122
138
|
}
|
|
123
139
|
else {
|
|
124
|
-
projectId = await pickOne(ctx, projects, "project", "
|
|
125
|
-
projects.map((p) => ` ${p.id} ${p.name ?? p.root_url ?? ""}`).join("\n"));
|
|
140
|
+
projectId = await pickOne(ctx, projects, "project", ambiguousMessage(ctx, "project", projects));
|
|
126
141
|
}
|
|
127
142
|
projectCache = { workspaceId, projectId };
|
|
128
143
|
return projectCache;
|
package/dist/registry/index.js
CHANGED
|
@@ -17,11 +17,15 @@ export const WORKSPACE_FLAG = {
|
|
|
17
17
|
name: "workspace",
|
|
18
18
|
type: "string",
|
|
19
19
|
description: "Workspace id or name (defaults to BERYL_WORKSPACE, or your only workspace)",
|
|
20
|
+
mcpDescription: "Workspace id or name. Needed only when the account has more than one workspace and " +
|
|
21
|
+
"no project id is passed (a project id implies its workspace)",
|
|
20
22
|
};
|
|
21
23
|
export const PROJECT_FLAG = {
|
|
22
24
|
name: "project",
|
|
23
25
|
type: "string",
|
|
24
26
|
description: "Project id, name, or URL (defaults to BERYL_PROJECT, or the workspace's only project)",
|
|
27
|
+
mcpDescription: "Project id, name, or URL. Pass it on every call unless the account has exactly one " +
|
|
28
|
+
"project; a project id alone is enough, its workspace is looked up",
|
|
25
29
|
};
|
|
26
30
|
function withScopeFlags(spec) {
|
|
27
31
|
if (!spec.scope || spec.scope === "none")
|
package/package.json
CHANGED