@cavelon/cli 0.1.4 → 0.1.6
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 +58 -22
- package/dist/choose.js +8 -4
- package/dist/code-hints.js +74 -0
- package/dist/commands/api.js +83 -44
- package/dist/commands/async.js +26 -5
- package/dist/commands/chat.js +177 -0
- package/dist/commands/docs.js +240 -37
- package/dist/commands/fmt.js +120 -0
- package/dist/commands/index.js +9 -1
- package/dist/commands/init.js +64 -30
- package/dist/commands/inventory.js +48 -5
- package/dist/commands/limits-set.js +9 -6
- package/dist/commands/loops.js +15 -9
- package/dist/commands/models.js +16 -7
- package/dist/commands/sandboxes.js +8 -4
- package/dist/commands/schema.js +361 -0
- package/dist/commands/session.js +148 -24
- package/dist/commands/setup.js +22 -6
- package/dist/commands/solution.js +537 -76
- package/dist/commands/tenants.js +156 -15
- package/dist/commands/values.js +18 -9
- package/dist/commands/work.js +343 -35
- package/dist/confirm-token.js +72 -0
- package/dist/contracts.js +3 -0
- package/dist/default-route.js +21 -0
- package/dist/errors.js +4 -0
- package/dist/git.js +14 -5
- package/dist/harness-ref.js +14 -1
- package/dist/http.js +27 -4
- package/dist/invoke.js +8 -4
- package/dist/kit-codes.js +91 -0
- package/dist/limits.js +12 -1
- package/dist/local-state.js +32 -7
- package/dist/main.js +52 -4
- package/dist/mcp.js +72 -15
- package/dist/openapi.js +77 -21
- package/dist/operations.js +4 -3
- package/dist/package-check.js +361 -12
- package/dist/package-files.js +92 -45
- package/dist/package-format.js +222 -0
- package/dist/package-references.js +298 -0
- package/dist/preview-report.js +152 -0
- package/dist/results.js +21 -1
- package/dist/skills/cavelon-authoring/SKILL.md +98 -13
- package/dist/skills/cavelon-long-running/SKILL.md +3 -1
- package/dist/skills/cavelon-loop/SKILL.md +129 -21
- package/dist/skills/cavelon-testing/SKILL.md +130 -10
- package/dist/tenant-choice.js +31 -5
- package/dist/trace-view.js +172 -0
- package/package.json +1 -1
package/dist/mcp.js
CHANGED
|
@@ -1,15 +1,27 @@
|
|
|
1
1
|
import { Server } from "@modelcontextprotocol/sdk/server/index.js";
|
|
2
2
|
import { CallToolRequestSchema, ListToolsRequestSchema } from "@modelcontextprotocol/sdk/types.js";
|
|
3
|
+
import { MCP_MAX_WAIT_MS } from "./commands/async.js";
|
|
3
4
|
import { createContext, withWarnings } from "./context.js";
|
|
4
|
-
import { asCavelonError, usageError } from "./errors.js";
|
|
5
|
+
import { asCavelonError, CavelonError, ExitCode, usageError } from "./errors.js";
|
|
6
|
+
import { closest } from "./package-references.js";
|
|
5
7
|
import { KIT_VERSION } from "./version.js";
|
|
6
8
|
const INSTRUCTIONS = "Tools for one Cavelon instance, acting with the token a person stored with `cavelon login` " +
|
|
7
9
|
"(or CAVELON_TOKEN). You never see or pass the token. Tools that start work (kb_upload, test_run, " +
|
|
8
|
-
"loop_start, sandbox_seed, artifacts_export) return operation ids at once; read them with operation_status, " +
|
|
10
|
+
"loop_start, sandbox_seed, artifacts_export) return operation ids at once; read them with operation_status, which returns " +
|
|
11
|
+
`the state at once, or waits up to its timeout (at most ${MCP_MAX_WAIT_MS / 1000} s) when given one, and reports waited_ms, ` +
|
|
9
12
|
"and follow a loop with loop_iterations. What needs confirmation: apply imports only with confirm set to a preview's id; " +
|
|
10
|
-
"limits_set, models_set_limit, loop_cancel, sandbox_seed, trigger_identity,
|
|
11
|
-
"
|
|
12
|
-
"
|
|
13
|
+
"limits_set, models_set_limit, loop_cancel, sandbox_seed, trigger_identity, harness_default, activate with make_default, deactivate, " +
|
|
14
|
+
"and api for an operation that is not read-only, " +
|
|
15
|
+
"return what they would do and a confirm_token, and change nothing until called again with the same arguments and " +
|
|
16
|
+
"confirm set to that token: show the person the preview first. The token confirms exactly the change the preview showed; " +
|
|
17
|
+
"a different change needs a new preview, and confirm: true is refused. The default route " +
|
|
18
|
+
"(harness_default, activate's make_default) decides which solution the tenant's chat and widget answer with: live traffic, " +
|
|
19
|
+
"so ask the person, and confirm only with their yes; the same goes for deactivate, which takes a solution out of live traffic. " +
|
|
20
|
+
"chat sends one message to a solution and returns its answer: the way to try one that is not the default route. " +
|
|
21
|
+
"kb_upload names files that match an active document of the knowledge base; with replace it replaces them, and where the " +
|
|
22
|
+
"instance's upload cannot, it returns what it would deactivate and uploads nothing without its confirm_token. " +
|
|
23
|
+
"init, pull and fmt change nothing on the instance (pull only reads it); they write files in the solution folder without confirm " +
|
|
24
|
+
"(pull refuses to replace a package file that changed since the last pull or apply and is not committed, unless force), " +
|
|
13
25
|
"and the other changing tools act at once. api refuses, even with confirm, an operation the instance marks for a person " +
|
|
14
26
|
"(x-cavelon-person-only; its reason is in the error), or on an instance that marks none, one that changes a secret, " +
|
|
15
27
|
"creates or revokes a credential (tokens, API keys, sign-in) or decides an approval; it also refuses a body that sets a field " +
|
|
@@ -26,27 +38,32 @@ const INSTRUCTIONS = "Tools for one Cavelon instance, acting with the token a pe
|
|
|
26
38
|
"to run in their terminal, and never ask for, read or pass a secret value. Never approve or decide an approval; " +
|
|
27
39
|
"that stays with a person. Use docs_search before guessing, " +
|
|
28
40
|
"and api_list/api_describe/api for anything without its own tool.";
|
|
41
|
+
const TOKEN_DESCRIPTION = "Over MCP: the confirm_token this tool's preview returned, which confirms exactly the change it showed; true is refused.";
|
|
29
42
|
export function toolName(spec) {
|
|
30
43
|
return spec.mcpTool || undefined;
|
|
31
44
|
}
|
|
32
45
|
function ownsTenant(spec) {
|
|
33
46
|
return Boolean(spec.positionals?.some((p) => p.name === "tenant") || spec.options?.tenant);
|
|
34
47
|
}
|
|
48
|
+
export function propertyName(name) {
|
|
49
|
+
return name.replaceAll("-", "_");
|
|
50
|
+
}
|
|
35
51
|
export function inputSchema(spec) {
|
|
36
52
|
const properties = {};
|
|
37
53
|
const required = [];
|
|
38
54
|
for (const p of spec.positionals ?? []) {
|
|
39
|
-
properties[p.name] = p.variadic
|
|
55
|
+
properties[propertyName(p.name)] = p.variadic
|
|
40
56
|
? { type: "array", items: { type: "string" }, description: p.description }
|
|
41
57
|
: { type: "string", description: p.description };
|
|
42
58
|
if (p.required)
|
|
43
|
-
required.push(p.name);
|
|
59
|
+
required.push(propertyName(p.name));
|
|
44
60
|
}
|
|
45
61
|
for (const [name, option] of Object.entries(spec.options ?? {})) {
|
|
46
62
|
if (option.cliOnly)
|
|
47
63
|
continue;
|
|
48
|
-
properties[name] =
|
|
49
|
-
|
|
64
|
+
properties[propertyName(name)] = option.mcpToken
|
|
65
|
+
? { type: "string", description: `${option.description} ${TOKEN_DESCRIPTION}` }
|
|
66
|
+
: option.type === "boolean"
|
|
50
67
|
? { type: "boolean", description: option.description }
|
|
51
68
|
: option.multiple
|
|
52
69
|
? { type: "array", items: { type: "string" }, description: option.description }
|
|
@@ -58,7 +75,7 @@ export function inputSchema(spec) {
|
|
|
58
75
|
return { type: "object", properties, ...(required.length ? { required } : {}), additionalProperties: false };
|
|
59
76
|
}
|
|
60
77
|
export function toolFor(spec) {
|
|
61
|
-
const marked = spec.readOnly ? "Read-only." : spec.destructive ? "Changes the instance; may delete or overwrite." : "Changes the instance.";
|
|
78
|
+
const marked = spec.mcpEffect ?? (spec.readOnly ? "Read-only." : spec.destructive ? "Changes the instance; may delete or overwrite." : "Changes the instance.");
|
|
62
79
|
return {
|
|
63
80
|
name: toolName(spec),
|
|
64
81
|
description: [spec.summary, spec.description, marked].filter(Boolean).join("\n"),
|
|
@@ -72,10 +89,35 @@ export function toolFor(spec) {
|
|
|
72
89
|
},
|
|
73
90
|
};
|
|
74
91
|
}
|
|
92
|
+
function argumentsOf(spec, args, warn) {
|
|
93
|
+
const properties = Object.keys(inputSchema(spec).properties ?? {});
|
|
94
|
+
const out = {};
|
|
95
|
+
for (const [key, value] of Object.entries(args)) {
|
|
96
|
+
if (properties.includes(key)) {
|
|
97
|
+
out[key] = value;
|
|
98
|
+
continue;
|
|
99
|
+
}
|
|
100
|
+
const spelled = propertyName(key);
|
|
101
|
+
if (spelled !== key && properties.includes(spelled)) {
|
|
102
|
+
warn(`"${key}" is spelled "${spelled}" in this tool's schema; "${key}" is still taken for now and will be refused in a later release.`);
|
|
103
|
+
if (!(spelled in args))
|
|
104
|
+
out[spelled] = value;
|
|
105
|
+
continue;
|
|
106
|
+
}
|
|
107
|
+
const near = closest(key, properties);
|
|
108
|
+
throw new CavelonError(ExitCode.usage, {
|
|
109
|
+
code: "unknown_argument",
|
|
110
|
+
message: `${spec.mcpTool} has no argument "${key}"; nothing was done.${near ? ` Did you mean "${near}"?` : ""}`,
|
|
111
|
+
hint: `Its arguments: ${properties.join(", ")}.`,
|
|
112
|
+
details: { argument: key, ...(near ? { suggestion: near } : {}), arguments: properties },
|
|
113
|
+
});
|
|
114
|
+
}
|
|
115
|
+
return out;
|
|
116
|
+
}
|
|
75
117
|
function inputFrom(spec, args) {
|
|
76
118
|
const input = { positionals: {}, options: {} };
|
|
77
119
|
for (const p of spec.positionals ?? []) {
|
|
78
|
-
const value = args[p.name];
|
|
120
|
+
const value = args[propertyName(p.name)];
|
|
79
121
|
if (value === undefined || value === null)
|
|
80
122
|
continue;
|
|
81
123
|
input.positionals[p.name] = p.variadic ? (Array.isArray(value) ? value.map(String) : [String(value)]) : String(value);
|
|
@@ -83,10 +125,12 @@ function inputFrom(spec, args) {
|
|
|
83
125
|
for (const [name, option] of Object.entries(spec.options ?? {})) {
|
|
84
126
|
if (option.cliOnly)
|
|
85
127
|
continue;
|
|
86
|
-
const value = args[name];
|
|
128
|
+
const value = args[propertyName(name)];
|
|
87
129
|
if (value === undefined || value === null)
|
|
88
130
|
continue;
|
|
89
|
-
if (option.
|
|
131
|
+
if (option.mcpToken)
|
|
132
|
+
input.options[name] = value === true || value === "true" ? true : value === false ? false : String(value);
|
|
133
|
+
else if (option.type === "boolean")
|
|
90
134
|
input.options[name] = value === true || value === "true";
|
|
91
135
|
else if (option.multiple)
|
|
92
136
|
input.options[name] = Array.isArray(value) ? value.map(String) : [String(value)];
|
|
@@ -96,7 +140,10 @@ function inputFrom(spec, args) {
|
|
|
96
140
|
return input;
|
|
97
141
|
}
|
|
98
142
|
function missingRequired(spec, args) {
|
|
99
|
-
return (spec.positionals ?? [])
|
|
143
|
+
return (spec.positionals ?? [])
|
|
144
|
+
.map((p) => ({ ...p, name: propertyName(p.name) }))
|
|
145
|
+
.filter((p) => p.required && (args[p.name] === undefined || args[p.name] === ""))
|
|
146
|
+
.map((p) => p.name);
|
|
100
147
|
}
|
|
101
148
|
function mcpIo(io) {
|
|
102
149
|
return { ...io, stdout: { write: () => true, isTTY: false } };
|
|
@@ -108,13 +155,21 @@ export function createMcpServer(io, commands) {
|
|
|
108
155
|
server.setRequestHandler(ListToolsRequestSchema, async () => ({ tools: tools.map(toolFor) }));
|
|
109
156
|
server.setRequestHandler(CallToolRequestSchema, async (request) => {
|
|
110
157
|
const spec = byName.get(request.params.name);
|
|
111
|
-
const
|
|
158
|
+
const given = (request.params.arguments ?? {});
|
|
112
159
|
const fail = (error) => ({
|
|
113
160
|
isError: true,
|
|
114
161
|
content: [{ type: "text", text: JSON.stringify({ error: asCavelonError(error).toJSON() }) }],
|
|
115
162
|
});
|
|
116
163
|
if (!spec)
|
|
117
164
|
return fail(new Error(`Unknown tool ${request.params.name}.`));
|
|
165
|
+
const spelling = [];
|
|
166
|
+
let args;
|
|
167
|
+
try {
|
|
168
|
+
args = argumentsOf(spec, given, (message) => spelling.push(message));
|
|
169
|
+
}
|
|
170
|
+
catch (error) {
|
|
171
|
+
return fail(error);
|
|
172
|
+
}
|
|
118
173
|
const missing = missingRequired(spec, args);
|
|
119
174
|
if (missing.length) {
|
|
120
175
|
return fail(usageError(`Missing ${missing.join(", ")}.`));
|
|
@@ -122,6 +177,8 @@ export function createMcpServer(io, commands) {
|
|
|
122
177
|
const tenant = !ownsTenant(spec) && typeof args.tenant === "string" ? args.tenant : undefined;
|
|
123
178
|
const solutionEnv = spec.options?.env && typeof args.env === "string" ? args.env : undefined;
|
|
124
179
|
const ctx = createContext(mcpIo(io), { json: true, tenant, solutionEnv }, "mcp");
|
|
180
|
+
for (const message of spelling)
|
|
181
|
+
ctx.warn(message);
|
|
125
182
|
try {
|
|
126
183
|
const result = await spec.run(ctx, inputFrom(spec, args));
|
|
127
184
|
let data = result.data;
|
package/dist/openapi.js
CHANGED
|
@@ -82,9 +82,16 @@ export function findOperation(doc, name) {
|
|
|
82
82
|
hint: `Use the full operationId: ${byAlias.map((o) => o.operationId).join(", ")}`,
|
|
83
83
|
});
|
|
84
84
|
}
|
|
85
|
+
const wanted = looseName(name);
|
|
86
|
+
const loose = all.filter((o) => looseName(o.alias) === wanted || looseName(o.operationId) === wanted);
|
|
87
|
+
if (loose.length === 1)
|
|
88
|
+
return loose[0];
|
|
85
89
|
const needle = name.toLowerCase();
|
|
86
|
-
const similar =
|
|
87
|
-
|
|
90
|
+
const similar = [
|
|
91
|
+
...loose,
|
|
92
|
+
...all.filter((o) => !loose.includes(o) &&
|
|
93
|
+
(o.alias.toLowerCase().includes(needle) || needle.includes(o.alias.toLowerCase()) || looselyContains(looseName(o.alias), wanted))),
|
|
94
|
+
]
|
|
88
95
|
.slice(0, 5)
|
|
89
96
|
.map((o) => o.alias);
|
|
90
97
|
throw new CavelonError(ExitCode.usage, {
|
|
@@ -93,6 +100,15 @@ export function findOperation(doc, name) {
|
|
|
93
100
|
hint: similar.length ? `Did you mean: ${similar.join(", ")}? (\`cavelon api list --search <text>\`)` : "Find it with `cavelon api list --search <text>`.",
|
|
94
101
|
});
|
|
95
102
|
}
|
|
103
|
+
function looseName(name) {
|
|
104
|
+
return name.toLowerCase().replace(/[^a-z0-9]/g, "");
|
|
105
|
+
}
|
|
106
|
+
function looselyContains(a, b) {
|
|
107
|
+
return a.length > 3 && b.length > 3 && (a.includes(b) || b.includes(a));
|
|
108
|
+
}
|
|
109
|
+
export function matchedLoosely(op, name) {
|
|
110
|
+
return name !== op.operationId && name !== op.alias;
|
|
111
|
+
}
|
|
96
112
|
export function operationAt(doc, method, path) {
|
|
97
113
|
return operations(doc).find((o) => o.method === method.toUpperCase() && o.path === path);
|
|
98
114
|
}
|
|
@@ -210,6 +226,34 @@ export function secretFields(doc, schema, body) {
|
|
|
210
226
|
walk(schema, body, "", 0);
|
|
211
227
|
return [...found];
|
|
212
228
|
}
|
|
229
|
+
export function secretPaths(doc, schema) {
|
|
230
|
+
const found = new Set();
|
|
231
|
+
let budget = 2_000;
|
|
232
|
+
const list = (value) => (Array.isArray(value) ? value : []);
|
|
233
|
+
const walk = (raw, where, depth) => {
|
|
234
|
+
if (depth > 6 || --budget < 0)
|
|
235
|
+
return;
|
|
236
|
+
const node = deref(doc, raw);
|
|
237
|
+
if (!node || typeof node !== "object")
|
|
238
|
+
return;
|
|
239
|
+
const s = node;
|
|
240
|
+
if (s["x-cavelon-secret"] === true) {
|
|
241
|
+
found.add(where || "(body)");
|
|
242
|
+
return;
|
|
243
|
+
}
|
|
244
|
+
for (const key of ["allOf", "anyOf", "oneOf"])
|
|
245
|
+
for (const sub of list(s[key]))
|
|
246
|
+
walk(sub, where, depth + 1);
|
|
247
|
+
if (s.items)
|
|
248
|
+
walk(s.items, `${where}[]`, depth + 1);
|
|
249
|
+
for (const [key, sub] of Object.entries((s.properties ?? {})))
|
|
250
|
+
walk(sub, where ? `${where}.${key}` : key, depth + 1);
|
|
251
|
+
if (s.additionalProperties && typeof s.additionalProperties === "object")
|
|
252
|
+
walk(s.additionalProperties, where ? `${where}.*` : "*", depth + 1);
|
|
253
|
+
};
|
|
254
|
+
walk(schema, "", 0);
|
|
255
|
+
return [...found];
|
|
256
|
+
}
|
|
213
257
|
function matches(pattern, key) {
|
|
214
258
|
try {
|
|
215
259
|
return new RegExp(pattern, "u").test(key);
|
|
@@ -245,7 +289,15 @@ export function schemaTypes(schema) {
|
|
|
245
289
|
export function isArrayParameter(param) {
|
|
246
290
|
return schemaTypes(param.schema).includes("array");
|
|
247
291
|
}
|
|
248
|
-
|
|
292
|
+
function arrayItemObject(doc, field) {
|
|
293
|
+
const options = [field, ...(field.anyOf ?? field.oneOf ?? []).map((b) => deref(doc, b))];
|
|
294
|
+
const array = options.find((o) => o?.type === "array" && o.items);
|
|
295
|
+
if (!array)
|
|
296
|
+
return undefined;
|
|
297
|
+
const items = deref(doc, array.items);
|
|
298
|
+
return items && typeof items.properties === "object" ? array.items : undefined;
|
|
299
|
+
}
|
|
300
|
+
export function describeSchema(doc, schema, depth = 0) {
|
|
249
301
|
if (!schema)
|
|
250
302
|
return null;
|
|
251
303
|
const resolved = deref(doc, schema);
|
|
@@ -253,25 +305,29 @@ export function describeSchema(doc, schema) {
|
|
|
253
305
|
const ref = typeof schema.$ref === "string" ? schema.$ref.split("/").pop() : undefined;
|
|
254
306
|
if (!props) {
|
|
255
307
|
if (resolved.type === "array" && resolved.items)
|
|
256
|
-
return { type: "array", items: describeSchema(doc, resolved.items) };
|
|
308
|
+
return { type: "array", items: describeSchema(doc, resolved.items, depth + 1) };
|
|
257
309
|
return { ...(ref ? { name: ref } : {}), type: resolved.type ?? (schemaTypes(resolved).join("|") || "any") };
|
|
258
310
|
}
|
|
259
311
|
const required = new Set(resolved.required ?? []);
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
312
|
+
const fields = {};
|
|
313
|
+
for (const [name, p] of Object.entries(props)) {
|
|
314
|
+
const sub = deref(doc, p);
|
|
315
|
+
const subRef = typeof p.$ref === "string" ? p.$ref.split("/").pop() : undefined;
|
|
316
|
+
const items = arrayItemObject(doc, sub);
|
|
317
|
+
const itemName = items && typeof items.$ref === "string" ? items.$ref.split("/").pop() : undefined;
|
|
318
|
+
const type = subRef ?? (items ? `array of ${itemName ?? "object"}` : schemaTypes(sub).filter((t) => t !== "null").join("|") || "object");
|
|
319
|
+
const parts = [type];
|
|
320
|
+
if (required.has(name))
|
|
321
|
+
parts.push("required");
|
|
322
|
+
if (Array.isArray(sub.enum))
|
|
323
|
+
parts.push(`one of ${sub.enum.join(", ")}`);
|
|
324
|
+
if (sub.default !== undefined)
|
|
325
|
+
parts.push(`default ${JSON.stringify(sub.default)}`);
|
|
326
|
+
if (secretPaths(doc, p).includes("(body)"))
|
|
327
|
+
parts.push("secret value (x-cavelon-secret): a person enters it");
|
|
328
|
+
fields[name] = parts.join(", ");
|
|
329
|
+
if (items && depth < 3)
|
|
330
|
+
fields[`${name}[]`] = describeSchema(doc, items, depth + 1);
|
|
331
|
+
}
|
|
332
|
+
return { ...(ref ? { name: ref } : {}), type: "object", fields };
|
|
277
333
|
}
|
package/dist/operations.js
CHANGED
|
@@ -61,7 +61,8 @@ export async function getOperation(client, id, signal) {
|
|
|
61
61
|
}
|
|
62
62
|
}
|
|
63
63
|
export async function waitFor(ctx, client, ids, options) {
|
|
64
|
-
const
|
|
64
|
+
const started = Date.now();
|
|
65
|
+
const deadline = started + options.timeoutMs;
|
|
65
66
|
const latest = new Map();
|
|
66
67
|
let interval = options.intervalMs;
|
|
67
68
|
for (;;) {
|
|
@@ -77,10 +78,10 @@ export async function waitFor(ctx, client, ids, options) {
|
|
|
77
78
|
}
|
|
78
79
|
const ops = ids.map((id) => latest.get(id));
|
|
79
80
|
if (ops.every(isSettled))
|
|
80
|
-
return { operations: ops, timedOut: false };
|
|
81
|
+
return { operations: ops, timedOut: false, waitedMs: Date.now() - started };
|
|
81
82
|
const left = deadline - Date.now();
|
|
82
83
|
if (left <= 0)
|
|
83
|
-
return { operations: ops, timedOut:
|
|
84
|
+
return { operations: ops, timedOut: options.timeoutMs > 0, waitedMs: Date.now() - started };
|
|
84
85
|
await ctx.io.sleep(Math.min(interval, left));
|
|
85
86
|
interval = Math.min(Math.round(interval * 1.5), 5000);
|
|
86
87
|
}
|