@cavelon/cli 0.1.8 → 0.1.10
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/branches.js +4 -3
- package/dist/capacity.js +3 -2
- package/dist/code-hints.js +5 -4
- package/dist/command.js +6 -0
- package/dist/commands/api.js +3 -3
- package/dist/commands/async.js +7 -4
- package/dist/commands/chat.js +10 -12
- package/dist/commands/docs.js +5 -3
- package/dist/commands/fmt.js +6 -4
- package/dist/commands/index.js +2 -0
- package/dist/commands/init.js +106 -28
- package/dist/commands/limits-set.js +8 -9
- package/dist/commands/limits.js +4 -3
- package/dist/commands/loops.js +15 -14
- package/dist/commands/models.js +10 -12
- package/dist/commands/sandboxes.js +15 -14
- package/dist/commands/schema.js +6 -5
- package/dist/commands/session.js +27 -15
- package/dist/commands/setup.js +4 -2
- package/dist/commands/solution.js +152 -68
- package/dist/commands/tenants.js +14 -14
- package/dist/commands/values.js +62 -38
- package/dist/commands/work.js +18 -12
- package/dist/confirm-token.js +3 -1
- package/dist/contracts.js +2 -1
- package/dist/default-route.js +1 -1
- package/dist/features.js +2 -1
- package/dist/harness-ref.js +6 -4
- package/dist/http.js +4 -3
- package/dist/invoke.js +3 -2
- package/dist/kit-codes.js +9 -2
- package/dist/limits.js +1 -1
- package/dist/main.js +13 -1
- package/dist/mcp.js +65 -32
- package/dist/openapi.js +5 -2
- package/dist/operations.js +3 -2
- package/dist/package-check.js +10 -4
- package/dist/package-files.js +5 -1
- package/dist/package-format.js +10 -0
- package/dist/preview-report.js +44 -5
- package/dist/printed.js +182 -0
- package/dist/project.js +2 -1
- package/dist/results.js +1 -1
- package/dist/secret-access.js +30 -0
- package/dist/session.js +3 -11
- package/dist/shell.js +0 -3
- package/dist/skills/cavelon-authoring/SKILL.md +9 -2
- package/dist/skills/cavelon-long-running/SKILL.md +1 -1
- package/dist/skills/cavelon-loop/SKILL.md +16 -4
- package/dist/tenant-choice.js +7 -7
- package/dist/trace-view.js +1 -1
- package/dist/update-check.js +156 -10
- package/package.json +1 -1
package/dist/commands/values.js
CHANGED
|
@@ -6,9 +6,11 @@ import { callStable, workflowOperation } from "../invoke.js";
|
|
|
6
6
|
import { readAll } from "../io.js";
|
|
7
7
|
import { schemaErrors } from "../openapi.js";
|
|
8
8
|
import { readPrincipal } from "../principal.js";
|
|
9
|
+
import { permissionsNamed, SECRETS_PERMISSIONS, secretsPermissionMissing } from "../secret-access.js";
|
|
9
10
|
import { readHidden } from "../prompt.js";
|
|
11
|
+
import { readPackage } from "../package-files.js";
|
|
10
12
|
import { requireToken } from "../session.js";
|
|
11
|
-
import {
|
|
13
|
+
import { cavelonCommand, fill, printedCommand } from "../printed.js";
|
|
12
14
|
export const ENV_OPTION = { type: "string", value: "<name>", description: "Act in the tenant that env/<name>.yaml names." };
|
|
13
15
|
const CONFIRM_OPTION = {
|
|
14
16
|
type: "boolean",
|
|
@@ -17,21 +19,11 @@ const CONFIRM_OPTION = {
|
|
|
17
19
|
};
|
|
18
20
|
const TOKEN_PREFIXES = ["cbp_", "cvpat_"];
|
|
19
21
|
const LIST_VALUE_CHARS = 200;
|
|
20
|
-
export function
|
|
21
|
-
|
|
22
|
-
if (session.urlSource === "option" && session.url)
|
|
23
|
-
flags += ` --instance ${shellWord(session.url)}`;
|
|
24
|
-
if (env)
|
|
25
|
-
flags += ` --env ${shellWord(env)}`;
|
|
26
|
-
if (session.tenantSource === "option" && session.tenant)
|
|
27
|
-
flags += ` --tenant ${shellWord(session.tenant)}`;
|
|
28
|
-
return flags;
|
|
22
|
+
export function secretSetCommand(name, env) {
|
|
23
|
+
return printedCommand(["secrets", "set", name], { env });
|
|
29
24
|
}
|
|
30
|
-
export function
|
|
31
|
-
return
|
|
32
|
-
}
|
|
33
|
-
export function variableSetCommand(name, flags = "") {
|
|
34
|
-
return `cavelon variables set ${shellWord(name)} <value>${flags}`;
|
|
25
|
+
export function variableSetCommand(name, env) {
|
|
26
|
+
return printedCommand(["variables", "set", name, fill("value")], { env });
|
|
35
27
|
}
|
|
36
28
|
async function checkName(ctx, method, template, what, name) {
|
|
37
29
|
const { doc, op } = await workflowOperation(ctx, method, template, what);
|
|
@@ -56,12 +48,12 @@ async function readVariable(ctx, name) {
|
|
|
56
48
|
throw error;
|
|
57
49
|
}
|
|
58
50
|
}
|
|
59
|
-
function variableNotSet(name
|
|
51
|
+
function variableNotSet(name) {
|
|
60
52
|
return new CavelonError(ExitCode.failure, {
|
|
61
53
|
code: "variable_not_set",
|
|
62
54
|
status: 404,
|
|
63
55
|
message: `This tenant has no variable "${name}".`,
|
|
64
|
-
hint:
|
|
56
|
+
hint: `\`${cavelonCommand("variables", "list")}\` shows them; \`${variableSetCommand(name)}\` sets it.`,
|
|
65
57
|
});
|
|
66
58
|
}
|
|
67
59
|
export const variablesList = {
|
|
@@ -84,10 +76,9 @@ export const variablesList = {
|
|
|
84
76
|
...(v.value.length > LIST_VALUE_CHARS ? { value_truncated: true } : {}),
|
|
85
77
|
source: v.source ?? null,
|
|
86
78
|
}));
|
|
87
|
-
const flags = targetFlags(await ctx.session());
|
|
88
79
|
const text = items.length
|
|
89
|
-
? table(items.map((v) => ({ ...v, source: v.source ?? "" })), ["name", "value", "source"], 60) + moreHint(page.next_cursor,
|
|
90
|
-
: `No variables in this tenant. Set one with:
|
|
80
|
+
? table(items.map((v) => ({ ...v, source: v.source ?? "" })), ["name", "value", "source"], 60) + moreHint(page.next_cursor, cavelonCommand("variables", "list"))
|
|
81
|
+
: `No variables in this tenant. Set one with: ${cavelonCommand("variables", "set", fill("name"), fill("value"))}`;
|
|
91
82
|
return { data: { items, next_cursor: page.next_cursor, total: page.total }, text };
|
|
92
83
|
},
|
|
93
84
|
};
|
|
@@ -103,7 +94,7 @@ export const variablesGet = {
|
|
|
103
94
|
const name = positional(input, "name");
|
|
104
95
|
const variable = await readVariable(ctx, name);
|
|
105
96
|
if (!variable)
|
|
106
|
-
throw variableNotSet(name
|
|
97
|
+
throw variableNotSet(name);
|
|
107
98
|
const data = { name: variable.name, value: variable.value, source: variable.source ?? null };
|
|
108
99
|
return {
|
|
109
100
|
data,
|
|
@@ -172,13 +163,12 @@ export const variablesDelete = {
|
|
|
172
163
|
examples: ["cavelon variables delete old_url", "cavelon variables delete old_url --confirm", "cavelon variables delete old_url --confirm <token>"],
|
|
173
164
|
async run(ctx, input) {
|
|
174
165
|
const name = positional(input, "name");
|
|
175
|
-
const flags = targetFlags(await ctx.session());
|
|
176
166
|
const current = await readVariable(ctx, name);
|
|
177
167
|
if (!current)
|
|
178
168
|
return { data: { name, deleted: false, existed: false }, text: `This tenant has no variable "${name}"; nothing to delete.` };
|
|
179
169
|
const gate = await confirmation(ctx, input, "variables_delete", { name, value: current.value });
|
|
180
170
|
if (!gate.confirmed) {
|
|
181
|
-
const confirm = gate.confirm(
|
|
171
|
+
const confirm = gate.confirm(cavelonCommand("variables", "delete", name, "--confirm"));
|
|
182
172
|
return {
|
|
183
173
|
data: { name, deleted: false, existed: true, value: current.value, confirm, ...gate.fields },
|
|
184
174
|
text: `Variable ${name} = ${JSON.stringify(clip(current.value, LIST_VALUE_CHARS))}.\n${gate.mismatch ? `${gate.mismatch}\n` : ""}Nothing was deleted. Delete it with: ${confirm}`,
|
|
@@ -208,10 +198,18 @@ async function requirePerson(ctx, verb, name) {
|
|
|
208
198
|
throw new CavelonError(ExitCode.unauthorized, {
|
|
209
199
|
code: "secret_needs_a_person",
|
|
210
200
|
message: `A tenant API key cannot ${verb} a secret, so nothing was sent: ${verb === "set" ? "setting" : "deleting"} a secret needs a person (a dashboard session or a personal access token).`,
|
|
211
|
-
hint: `${fromEnv}A person logs in with a personal access token (
|
|
201
|
+
hint: `${fromEnv}A person logs in with a personal access token (\`${cavelonCommand("login")}\`) and runs \`${cavelonCommand("secrets", verb, name)}\`, or does it in the Admin.`,
|
|
212
202
|
details: { sent: false, credential: "api_key" },
|
|
213
203
|
});
|
|
214
204
|
}
|
|
205
|
+
function refusedForRole(error, verb, name) {
|
|
206
|
+
if (!(error instanceof CavelonError) || error.status !== 403 || error.code === "secret_needs_a_person")
|
|
207
|
+
return error;
|
|
208
|
+
const named = permissionsNamed(error.message);
|
|
209
|
+
if (!named.length && error.code !== "forbidden")
|
|
210
|
+
return error;
|
|
211
|
+
return secretsPermissionMissing(verb, name, named.length ? named : SECRETS_PERMISSIONS);
|
|
212
|
+
}
|
|
215
213
|
function withoutLineEnd(text) {
|
|
216
214
|
if (text.endsWith("\r\n"))
|
|
217
215
|
return text.slice(0, -2);
|
|
@@ -288,11 +286,26 @@ function secretView(status) {
|
|
|
288
286
|
description: status.description ?? null,
|
|
289
287
|
};
|
|
290
288
|
}
|
|
289
|
+
const REQUIRED_SECRETS_SECTION = "required_secrets";
|
|
290
|
+
async function locallyDeclaredSecrets(session) {
|
|
291
|
+
const project = session.project;
|
|
292
|
+
if (!project)
|
|
293
|
+
return [];
|
|
294
|
+
const disk = await readPackage(project.root, project.layout).catch(() => undefined);
|
|
295
|
+
const declared = disk?.package[REQUIRED_SECRETS_SECTION];
|
|
296
|
+
if (!Array.isArray(declared))
|
|
297
|
+
return [];
|
|
298
|
+
const source = disk.sources[REQUIRED_SECRETS_SECTION];
|
|
299
|
+
const file = (Array.isArray(source) ? source[0]?.file : source?.file) ?? null;
|
|
300
|
+
const names = declared.map((d) => (d && typeof d === "object" ? d.name : d)).filter((n) => typeof n === "string" && n !== "");
|
|
301
|
+
return [...new Set(names)].map((name) => ({ name, file }));
|
|
302
|
+
}
|
|
291
303
|
export const secretsList = {
|
|
292
304
|
name: "secrets list",
|
|
293
305
|
summary: "List the tenant's secret names ({{secret:…}}) with whether each is set; never a value.",
|
|
294
|
-
description: "Lists every secret that has a value or that an imported package declared
|
|
295
|
-
"
|
|
306
|
+
description: "Lists every secret that has a value or that an imported package declared, and in a solution folder the ones its\n" +
|
|
307
|
+
"package declares that the tenant does not know yet. A person sets a missing one with `cavelon secrets set <name>`;\n" +
|
|
308
|
+
"an agent never sets or reads a secret value.",
|
|
296
309
|
readOnly: true,
|
|
297
310
|
idempotent: true,
|
|
298
311
|
mcpTool: "secrets_list",
|
|
@@ -305,28 +318,40 @@ export const secretsList = {
|
|
|
305
318
|
examples: ["cavelon secrets list", "cavelon secrets list --missing --json"],
|
|
306
319
|
async run(ctx, input) {
|
|
307
320
|
const limit = intOption(input, "limit", { min: 1, max: 500, fallback: 50 });
|
|
308
|
-
const
|
|
321
|
+
const session = await ctx.session();
|
|
309
322
|
const all = ((await callStable(ctx, "GET", "/api/v1/secrets", "tenant secrets")).items ?? []).map(secretView);
|
|
323
|
+
const local = (await locallyDeclaredSecrets(session)).filter((d) => !all.some((s) => s.name === d.name));
|
|
310
324
|
const wanted = boolOption(input, "missing") ? all.filter((s) => s.status !== "set") : all;
|
|
311
325
|
const page = pageOf(wanted, limit, stringOption(input, "cursor"));
|
|
312
|
-
const items = page.items.map((s) => (s.status === "set" ? s : { ...s, set_by_person: secretSetCommand(s.name
|
|
326
|
+
const items = page.items.map((s) => (s.status === "set" ? s : { ...s, set_by_person: secretSetCommand(s.name) }));
|
|
313
327
|
const missing = all.filter((s) => s.status !== "set").length;
|
|
314
328
|
const onlyMissing = boolOption(input, "missing");
|
|
315
|
-
let text = onlyMissing ? "Every secret this tenant knows is set." : "This tenant has no secrets and no package declared one.";
|
|
329
|
+
let text = onlyMissing ? "Every secret this tenant knows is set." : "This tenant has no secrets, and no package applied to it declared one.";
|
|
316
330
|
if (items.length) {
|
|
317
331
|
const rows = items.map((s) => ({ ...s, declared: s.declared ? "yes" : "", changed_at: s.changed_at ?? "", description: s.description ?? "" }));
|
|
318
|
-
const next = moreHint(page.next_cursor,
|
|
319
|
-
const howTo = missing ? `\n\n${missing} not set. A person sets each with:
|
|
332
|
+
const next = moreHint(page.next_cursor, cavelonCommand("secrets", "list", ...(onlyMissing ? ["--missing"] : [])));
|
|
333
|
+
const howTo = missing ? `\n\n${missing} not set. A person sets each with: ${cavelonCommand("secrets", "set", fill("name"))}` : "";
|
|
320
334
|
text = table(rows, ["name", "status", "declared", "changed_at", "description"], 50) + next + howTo;
|
|
321
335
|
}
|
|
322
|
-
|
|
336
|
+
if (local.length) {
|
|
337
|
+
const where = local[0].file ?? "this folder's package";
|
|
338
|
+
text +=
|
|
339
|
+
`\n\n${where} declares ${local.map((d) => d.name).join(", ")}, which the tenant does not know yet: it lists ` +
|
|
340
|
+
`${local.length === 1 ? "it" : "them"} once the package is applied (\`${cavelonCommand("apply")}\`). A person may set ${local.length === 1 ? "it" : "each"} before that: ` +
|
|
341
|
+
local.map((d) => secretSetCommand(d.name)).join("; ");
|
|
342
|
+
}
|
|
343
|
+
return {
|
|
344
|
+
data: { items, next_cursor: page.next_cursor, total: page.total, not_set: missing, ...(local.length ? { declared_locally: local } : {}) },
|
|
345
|
+
text,
|
|
346
|
+
};
|
|
323
347
|
},
|
|
324
348
|
};
|
|
325
349
|
export const secretsSet = {
|
|
326
350
|
name: "secrets set",
|
|
327
351
|
summary: "Set a secret's value (a person runs this, never the agent).",
|
|
328
352
|
description: "Asks for the value without echoing it, or reads it from standard input when that is piped (one trailing line break is\n" +
|
|
329
|
-
"dropped). The value is never an argument, never printed and never read back. A tenant API key cannot set a secret
|
|
353
|
+
"dropped). The value is never an argument, never printed and never read back. A tenant API key cannot set a secret,\n" +
|
|
354
|
+
"nor can a role the instance does not allow to manage secrets (a Builder): its refusal then names who can, a tenant Owner.",
|
|
330
355
|
readOnly: false,
|
|
331
356
|
idempotent: true,
|
|
332
357
|
mcpTool: false,
|
|
@@ -344,7 +369,7 @@ export const secretsSet = {
|
|
|
344
369
|
status = await callStable(ctx, "PUT", "/api/v1/secrets/{name}", "setting secrets", { params: { name: [name] }, body: { value } });
|
|
345
370
|
}
|
|
346
371
|
catch (error) {
|
|
347
|
-
throw withoutValue(error, value);
|
|
372
|
+
throw withoutValue(refusedForRole(error, "set", name), value);
|
|
348
373
|
}
|
|
349
374
|
const data = secretView(status);
|
|
350
375
|
return { data, text: `Secret ${data.name} is set${changedNote(data.changed_at)}. Its value is never shown.` };
|
|
@@ -365,14 +390,13 @@ export const secretsDelete = {
|
|
|
365
390
|
async run(ctx, input) {
|
|
366
391
|
const name = positional(input, "name");
|
|
367
392
|
await requirePerson(ctx, "delete", name);
|
|
368
|
-
const flags = targetFlags(await ctx.session());
|
|
369
393
|
const current = secretView(await callStable(ctx, "GET", "/api/v1/secrets/{name}", "tenant secrets", { params: { name: [name] } }));
|
|
370
394
|
const nothing = { data: { ...current, deleted: false }, text: `Secret ${name} has no value; nothing to delete.` };
|
|
371
395
|
if (current.status !== "set")
|
|
372
396
|
return nothing;
|
|
373
397
|
const gate = await confirmation(ctx, input, "secrets_delete", { name, changed_at: current.changed_at ?? null });
|
|
374
398
|
if (!gate.confirmed) {
|
|
375
|
-
const confirm = gate.confirm(
|
|
399
|
+
const confirm = gate.confirm(cavelonCommand("secrets", "delete", name, "--confirm"));
|
|
376
400
|
return {
|
|
377
401
|
data: { ...current, deleted: false, confirm, ...gate.fields },
|
|
378
402
|
text: `Secret ${name} is set${changedNote(current.changed_at)}.\n${gate.mismatch ? `${gate.mismatch}\n` : ""}Nothing was deleted. Delete it with: ${confirm}`,
|
|
@@ -385,11 +409,11 @@ export const secretsDelete = {
|
|
|
385
409
|
catch (error) {
|
|
386
410
|
if (notFound(error))
|
|
387
411
|
return nothing;
|
|
388
|
-
throw error;
|
|
412
|
+
throw refusedForRole(error, "delete", name);
|
|
389
413
|
}
|
|
390
414
|
return {
|
|
391
415
|
data: { ...current, status: "not_set", deleted: true },
|
|
392
|
-
text: `Deleted the value of secret ${name}. A person sets it again with: ${secretSetCommand(name
|
|
416
|
+
text: `Deleted the value of secret ${name}. A person sets it again with: ${secretSetCommand(name)}`,
|
|
393
417
|
};
|
|
394
418
|
},
|
|
395
419
|
};
|
package/dist/commands/work.js
CHANGED
|
@@ -14,7 +14,7 @@ import { bindsNow, changedBy, limitError, limitsOrWarn, readLimits } from "../li
|
|
|
14
14
|
import { getOperation } from "../operations.js";
|
|
15
15
|
import { caseCounts, caseLabel, countsText, failedCase, caseKnowledgeOutcomes, NOT_PASSED, runVerdict } from "../results.js";
|
|
16
16
|
import { isUuid } from "../session.js";
|
|
17
|
-
import { cavelonCommand
|
|
17
|
+
import { cavelonCommand } from "../printed.js";
|
|
18
18
|
import { readZipSummary, ZipError } from "../zip.js";
|
|
19
19
|
import { TIMEOUT_OPTION, timeoutMs, waitAndReport } from "./async.js";
|
|
20
20
|
import { stageErrors, stageErrorText } from "./loops.js";
|
|
@@ -118,6 +118,8 @@ function plannedLine(match) {
|
|
|
118
118
|
return `${head} and is replaced once the new file is verified`;
|
|
119
119
|
case "deactivate":
|
|
120
120
|
return `${head} and is deactivated after the upload`;
|
|
121
|
+
case "identical":
|
|
122
|
+
return `${head} and stays as it is: the file is identical to it`;
|
|
121
123
|
}
|
|
122
124
|
}
|
|
123
125
|
function outcomeLine(match) {
|
|
@@ -190,7 +192,7 @@ async function resolveKbId(ctx, ref) {
|
|
|
190
192
|
throw new CavelonError(ExitCode.failure, {
|
|
191
193
|
code: hits.length ? "kb_ambiguous" : "kb_not_found",
|
|
192
194
|
message: hits.length ? `${hits.length} knowledge bases are named "${ref}".` : `No knowledge base named "${ref}".`,
|
|
193
|
-
hint:
|
|
195
|
+
hint: `Pass its id; \`${cavelonCommand("api", "list_knowledge_bases")}\` lists them.`,
|
|
194
196
|
});
|
|
195
197
|
}
|
|
196
198
|
async function collectFiles(dir, recursive, extensions) {
|
|
@@ -467,19 +469,22 @@ export const kbUpload = {
|
|
|
467
469
|
const differing = matches.filter((m) => !isIdentical(m));
|
|
468
470
|
const dryHint = staysActiveHint(differing, mode);
|
|
469
471
|
const dryDeactivations = differing.filter((m) => m.plan === "deactivate");
|
|
472
|
+
const same = new Set((identical ?? []).map((i) => i.file));
|
|
473
|
+
const fresh = rel.filter((f) => !same.has(f));
|
|
470
474
|
return {
|
|
471
475
|
data: {
|
|
472
476
|
kb: kbRef,
|
|
473
477
|
files: rel,
|
|
474
478
|
count: rel.length,
|
|
479
|
+
new_files: fresh,
|
|
475
480
|
dry_run: true,
|
|
476
|
-
existing: planned.map((m, index) => (identical ? { ...m, identical: isIdentical(matches[index]) } : m)),
|
|
481
|
+
existing: planned.map((m, index) => (identical ? { ...m, identical: isIdentical(matches[index]), ...(isIdentical(matches[index]) ? { plan: "identical" } : {}) } : m)),
|
|
477
482
|
content_compared: identical !== undefined,
|
|
478
483
|
identical: identical ?? [],
|
|
479
484
|
},
|
|
480
485
|
text: [
|
|
481
|
-
`Would upload ${fileCount(
|
|
482
|
-
...
|
|
486
|
+
fresh.length ? `Would upload ${fileCount(fresh.length)}:` : "Nothing new to upload:",
|
|
487
|
+
...fresh,
|
|
483
488
|
...(identical ?? []).map((i) => `${i.file}: identical to the active document ${shortId(i.document_id)}${i.filename === path.basename(i.file) ? "" : ` (${i.filename})`}; nothing new would be created (deduplicated)`),
|
|
484
489
|
...differing.map(plannedLine),
|
|
485
490
|
...(dryHint ? [dryHint] : []),
|
|
@@ -489,7 +494,7 @@ export const kbUpload = {
|
|
|
489
494
|
}
|
|
490
495
|
const gate = deactivations.length ? await confirmation(ctx, input, "kb_upload", { kb: kb.id, files: rel, existing: planned }) : undefined;
|
|
491
496
|
if (gate && !gate.confirmed) {
|
|
492
|
-
const confirm = gate.confirm(cavelonCommand("kb", "upload", dirArg, "--kb", kbRef, ...(boolOption(input, "recursive") ? ["
|
|
497
|
+
const confirm = gate.confirm(cavelonCommand("kb", "upload", dirArg, "--kb", kbRef, ...(boolOption(input, "recursive") ? ["--recursive"] : []), ...extensions.flatMap((e) => ["--ext", e]), "--replace", "--confirm"));
|
|
493
498
|
return {
|
|
494
499
|
data: { kb: { id: kb.id, name: kb.name ?? null }, files: rel, count: rel.length, uploaded: false, existing: planned, confirm, ...gate.fields },
|
|
495
500
|
text: [
|
|
@@ -590,7 +595,7 @@ export const kbUpload = {
|
|
|
590
595
|
`Uploaded ${fileCount(documents.length)}, then: ${failure.error.message}`,
|
|
591
596
|
`Not uploaded (${failure.notUploaded.length}): ${failure.notUploaded.join(", ")}`,
|
|
592
597
|
...matchLines(),
|
|
593
|
-
...(operationIds.length ? [`Wait for the uploaded ones with:
|
|
598
|
+
...(operationIds.length ? [`Wait for the uploaded ones with: ${cavelonCommand("wait", ...operationIds)}`] : []),
|
|
594
599
|
].join("\n"),
|
|
595
600
|
exitCode: failure.error.exitCode,
|
|
596
601
|
};
|
|
@@ -619,7 +624,7 @@ export const kbUpload = {
|
|
|
619
624
|
text: [
|
|
620
625
|
uploadedText(` to ${kb.name ?? kb.id}`),
|
|
621
626
|
...matchLines(),
|
|
622
|
-
...(operationIds.length ? [`Operations: ${operationIds.length}`, `Wait with:
|
|
627
|
+
...(operationIds.length ? [`Operations: ${operationIds.length}`, `Wait with: ${cavelonCommand("wait", ...operationIds)}`] : []),
|
|
623
628
|
].join("\n"),
|
|
624
629
|
exitCode: refused?.exitCode,
|
|
625
630
|
};
|
|
@@ -675,7 +680,7 @@ export const testRun = {
|
|
|
675
680
|
throw new CavelonError(ExitCode.failure, {
|
|
676
681
|
code: hit.length ? "suite_ambiguous" : "suite_not_found",
|
|
677
682
|
message: hit.length ? `${hit.length} suites are named "${ref}"; pass its id.` : `No test suite "${ref}"${harnessRef ? ` for ${harnessRef}` : ""}.`,
|
|
678
|
-
hint: "
|
|
683
|
+
hint: `\`${cavelonCommand("api", "list_suites")}\` lists the suites.`,
|
|
679
684
|
});
|
|
680
685
|
}
|
|
681
686
|
return hit;
|
|
@@ -736,7 +741,7 @@ export const testRun = {
|
|
|
736
741
|
return {
|
|
737
742
|
data: { runs: started, operation_ids: operationIds },
|
|
738
743
|
text: table(started, ["suite", "run_id", "status", "operation_id"]) +
|
|
739
|
-
(operationIds.length ? `\n\nWait with:
|
|
744
|
+
(operationIds.length ? `\n\nWait with: ${cavelonCommand("wait", ...operationIds)}` : ""),
|
|
740
745
|
};
|
|
741
746
|
},
|
|
742
747
|
};
|
|
@@ -1045,14 +1050,15 @@ export const trace = {
|
|
|
1045
1050
|
return { data, text: retrieval ? retrievalText(data, retrieval) : JSON.stringify(data, null, 2) };
|
|
1046
1051
|
}
|
|
1047
1052
|
const page = pageOf(spans.map((s) => summarizeSpan(s, outcomes)), limit, cursor);
|
|
1048
|
-
const
|
|
1053
|
+
const words = ["trace", id, ...(kind ? ["--kind", kind] : []), "--trace", traceId];
|
|
1054
|
+
const base = cavelonCommand(...words);
|
|
1049
1055
|
const open = suggestedSpan(spans);
|
|
1050
1056
|
return {
|
|
1051
1057
|
data: { trace: summarizeTrace(detail), spans: page },
|
|
1052
1058
|
text: `${keyValues(Object.entries(summarizeTrace(detail)))}\n\n` +
|
|
1053
1059
|
table(page.items, ["seq", "type", "name", "status", ...(outcomes.size ? ["knowledge_outcome"] : []), "duration_ms", "span_id"]) +
|
|
1054
1060
|
moreHint(page.next_cursor, base) +
|
|
1055
|
-
(open ? `\n\nOne span in full (${spanPick(open)}), by the span_id in its row: ${
|
|
1061
|
+
(open ? `\n\nOne span in full (${spanPick(open)}), by the span_id in its row: ${cavelonCommand(...words, "--span", open.id)}` : ""),
|
|
1056
1062
|
};
|
|
1057
1063
|
}
|
|
1058
1064
|
const order = kind ? [kind] : ["trigger", "test", "conversation"];
|
package/dist/confirm-token.js
CHANGED
|
@@ -2,6 +2,7 @@ import { createHash } from "node:crypto";
|
|
|
2
2
|
import { drivenByAgent } from "./agent-env.js";
|
|
3
3
|
import { CavelonError, ExitCode } from "./errors.js";
|
|
4
4
|
import { canonical } from "./package-files.js";
|
|
5
|
+
import { PREVIEW_TOKEN } from "./printed.js";
|
|
5
6
|
export const CONFIRM_TOKEN = /^[0-9a-f]{12}$/;
|
|
6
7
|
export function confirmToken(target, tool, change) {
|
|
7
8
|
return createHash("sha256")
|
|
@@ -13,7 +14,8 @@ export function confirmGiven(input) {
|
|
|
13
14
|
const value = input.options.confirm;
|
|
14
15
|
return value !== undefined && value !== false && value !== "";
|
|
15
16
|
}
|
|
16
|
-
export function withToken(
|
|
17
|
+
export function withToken(printed, token) {
|
|
18
|
+
const command = printed.replace(` --confirm ${PREVIEW_TOKEN}`, " --confirm");
|
|
17
19
|
if (command.endsWith(" --confirm"))
|
|
18
20
|
return `${command} ${token}`;
|
|
19
21
|
const at = command.indexOf(" --confirm ");
|
package/dist/contracts.js
CHANGED
|
@@ -3,6 +3,7 @@ import path from "node:path";
|
|
|
3
3
|
import { CavelonError, ExitCode } from "./errors.js";
|
|
4
4
|
import { NOT_HERE } from "./http.js";
|
|
5
5
|
import { cacheDir, instanceKey } from "./paths.js";
|
|
6
|
+
import { cavelonCommand } from "./printed.js";
|
|
6
7
|
import { readJsonFile, readTextFile, writeFileAtomic } from "./fsutil.js";
|
|
7
8
|
import { SUPPORTED_CONTRACTS } from "./version.js";
|
|
8
9
|
const NOT_MODIFIED = Symbol("not modified");
|
|
@@ -175,7 +176,7 @@ export class Contracts {
|
|
|
175
176
|
throw new CavelonError(ExitCode.validation, {
|
|
176
177
|
code: "package_version_unsupported",
|
|
177
178
|
message: `${this.client.url} does not accept package version ${wanted}.`,
|
|
178
|
-
hint:
|
|
179
|
+
hint: `Read contracts.package_versions.accepted from \`${cavelonCommand("status", "--json")}\`, or pull the package again.`,
|
|
179
180
|
});
|
|
180
181
|
}
|
|
181
182
|
return null;
|
package/dist/default-route.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { listHarnesses } from "./harness-ref.js";
|
|
2
2
|
import { callStable } from "./invoke.js";
|
|
3
|
-
import { cavelonCommand } from "./
|
|
3
|
+
import { cavelonCommand } from "./printed.js";
|
|
4
4
|
export async function readDefaultRoute(ctx) {
|
|
5
5
|
const all = await listHarnesses(ctx);
|
|
6
6
|
const known = all.some((h) => typeof h.is_default === "boolean");
|
package/dist/features.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { createHash, randomUUID } from "node:crypto";
|
|
2
2
|
import { stringOption } from "./command.js";
|
|
3
3
|
import { CavelonError, ExitCode, usageError } from "./errors.js";
|
|
4
|
+
import { cavelonCommand } from "./printed.js";
|
|
4
5
|
import { isUuid } from "./session.js";
|
|
5
6
|
export async function requireFeature(ctx, feature, code, what) {
|
|
6
7
|
const caps = await (await ctx.contracts()).capabilities();
|
|
@@ -8,7 +9,7 @@ export async function requireFeature(ctx, feature, code, what) {
|
|
|
8
9
|
throw new CavelonError(ExitCode.failure, {
|
|
9
10
|
code,
|
|
10
11
|
message: `This instance has ${what} switched off.`,
|
|
11
|
-
hint: `Its operator switches it on (${feature.toUpperCase()});
|
|
12
|
+
hint: `Its operator switches it on (${feature.toUpperCase()}); \`${cavelonCommand("status")}\` shows the instance.`,
|
|
12
13
|
});
|
|
13
14
|
}
|
|
14
15
|
}
|
package/dist/harness-ref.js
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import { closest, displayName, exactMatch } from "./choose.js";
|
|
2
2
|
import { CavelonError, ExitCode } from "./errors.js";
|
|
3
3
|
import { callStable } from "./invoke.js";
|
|
4
|
-
import {
|
|
4
|
+
import { cavelonCommand, fill } from "./printed.js";
|
|
5
|
+
import { isUuid } from "./session.js";
|
|
5
6
|
import { shellWord } from "./shell.js";
|
|
6
7
|
function notFound(error) {
|
|
7
8
|
return error instanceof CavelonError && error.status === 404;
|
|
@@ -33,14 +34,15 @@ export async function lookupHarness(ctx, ref) {
|
|
|
33
34
|
return { harness: hit, candidates: [] };
|
|
34
35
|
return { candidates: closest(all, ref) };
|
|
35
36
|
}
|
|
36
|
-
export function harnessNotFoundError(ref, candidates, source, command
|
|
37
|
+
export function harnessNotFoundError(ref, candidates, source, command) {
|
|
37
38
|
const near = candidates.map(displayName).join(", ");
|
|
38
39
|
const lines = candidates.map((h) => ` ${command ? command(h.slug) : `--harness ${shellWord(h.slug)}`}`).join("\n");
|
|
39
40
|
return new CavelonError(ExitCode.failure, {
|
|
40
41
|
code: "solution_not_found",
|
|
41
42
|
message: `No solution "${ref}" in this tenant${source ? ` (from ${source})` : ""}.${near ? ` Closest: ${near}.` : ""}`,
|
|
42
43
|
hint: (candidates.length ? `If you meant one of them:\n${lines}\n` : "") +
|
|
43
|
-
|
|
44
|
+
`\`${cavelonCommand("harness", "list")}\` shows this tenant's solutions with name, slug and id; ` +
|
|
45
|
+
`\`${cavelonCommand("harness", "new", fill("slug"), "--name", fill("name"))}\` creates one as a draft.`,
|
|
44
46
|
details: candidates.length ? { candidates: candidates.map((h) => ({ id: h.id, slug: h.slug, name: h.name })) } : undefined,
|
|
45
47
|
});
|
|
46
48
|
}
|
|
@@ -49,7 +51,7 @@ export async function resolveHarnessId(ctx, ref) {
|
|
|
49
51
|
return ref;
|
|
50
52
|
const { harness, candidates } = await lookupHarness(ctx, ref);
|
|
51
53
|
if (!harness)
|
|
52
|
-
throw harnessNotFoundError(ref, candidates
|
|
54
|
+
throw harnessNotFoundError(ref, candidates);
|
|
53
55
|
return harness.id;
|
|
54
56
|
}
|
|
55
57
|
export function slugFromName(name) {
|
package/dist/http.js
CHANGED
|
@@ -2,6 +2,7 @@ import { capacityCodeIn, capacityHint } from "./capacity.js";
|
|
|
2
2
|
import { ceilingRefusal, LIMIT_ABOVE_CEILING } from "./limits.js";
|
|
3
3
|
import { CavelonError, ExitCode } from "./errors.js";
|
|
4
4
|
import { blockerDetails } from "./preview-report.js";
|
|
5
|
+
import { cavelonCommand } from "./printed.js";
|
|
5
6
|
import { KIT_VERSION } from "./version.js";
|
|
6
7
|
const RUNTIME = process.versions.bun ? "bun/" + process.versions.bun : "node/" + process.versions.node;
|
|
7
8
|
export const DEFAULT_TIMEOUT_MS = 30_000;
|
|
@@ -274,7 +275,7 @@ export function errorFromResponse(status, body, what, headers, sent = {}) {
|
|
|
274
275
|
hint = retryAfter ? `Retry after ${retryAfter} seconds.` : "Retry later.";
|
|
275
276
|
const capacity = capacityCodeIn(code) ?? (status === 429 || status === 503 ? capacityCodeIn(message) : undefined);
|
|
276
277
|
if (capacity)
|
|
277
|
-
hint = [hint, capacityHint(capacity),
|
|
278
|
+
hint = [hint, capacityHint(capacity), `\`${cavelonCommand("explain", capacity)}\` says more.`].filter(Boolean).join(" ");
|
|
278
279
|
const ceiling = code === LIMIT_ABOVE_CEILING ? ceilingRefusal(body) : undefined;
|
|
279
280
|
if (ceiling) {
|
|
280
281
|
hint = ceiling.hint;
|
|
@@ -283,7 +284,7 @@ export function errorFromResponse(status, body, what, headers, sent = {}) {
|
|
|
283
284
|
if (changed)
|
|
284
285
|
details = details && typeof details === "object" && !Array.isArray(details) ? { ...details, changed } : { changed };
|
|
285
286
|
if (status === 400 && !hint && message && /select a tenant|tenant context|X-Tenant-Id/i.test(message)) {
|
|
286
|
-
hint =
|
|
287
|
+
hint = `Choose a tenant with \`${cavelonCommand("use")}\` (it lists your tenants), --tenant or CAVELON_TENANT.`;
|
|
287
288
|
}
|
|
288
289
|
if ((status === 401 || status === 403) && !hint) {
|
|
289
290
|
hint =
|
|
@@ -293,7 +294,7 @@ export function errorFromResponse(status, body, what, headers, sent = {}) {
|
|
|
293
294
|
? PLATFORM_ROUTE_HINT
|
|
294
295
|
: sent.tenantless
|
|
295
296
|
? `No tenant was named. ${TENANT_ID_HINT} Otherwise check the token's permission ceiling.`
|
|
296
|
-
:
|
|
297
|
+
: `The token does not reach this. Check the tenant (\`${cavelonCommand("whoami")}\`) and the token's permission ceiling.`;
|
|
297
298
|
}
|
|
298
299
|
return new CavelonError(exitCode, {
|
|
299
300
|
code: code ?? defaultCode(status),
|
package/dist/invoke.js
CHANGED
|
@@ -3,6 +3,7 @@ import path from "node:path";
|
|
|
3
3
|
import { CavelonError, ExitCode, validationError } from "./errors.js";
|
|
4
4
|
import { bodyBytes, isPlatformRoute } from "./http.js";
|
|
5
5
|
import { coerceParameter, isArrayParameter, operationAt, validateBody } from "./openapi.js";
|
|
6
|
+
import { cavelonCommand } from "./printed.js";
|
|
6
7
|
export async function openapiOrWarn(ctx) {
|
|
7
8
|
try {
|
|
8
9
|
return await (await ctx.contracts()).openapi();
|
|
@@ -122,7 +123,7 @@ export async function workflowOperation(ctx, method, pathTemplate, what) {
|
|
|
122
123
|
throw new CavelonError(ExitCode.failure, {
|
|
123
124
|
code: "operation_unavailable",
|
|
124
125
|
message: `This instance does not offer ${what} (${method} ${pathTemplate} is not in its OpenAPI).`,
|
|
125
|
-
hint:
|
|
126
|
+
hint: `The instance may be older than this feature; \`${cavelonCommand("status")}\` shows its version.`,
|
|
126
127
|
});
|
|
127
128
|
}
|
|
128
129
|
return { doc, op };
|
|
@@ -156,7 +157,7 @@ export async function callStable(ctx, method, pathTemplate, what, args = {}) {
|
|
|
156
157
|
throw new CavelonError(ExitCode.failure, {
|
|
157
158
|
code: "operation_unavailable",
|
|
158
159
|
message: `This instance's ${method} ${pathTemplate} does not take ${unknown.join(", ")}, so it cannot do this (${what}).`,
|
|
159
|
-
hint:
|
|
160
|
+
hint: `The instance may be older than this feature; \`${cavelonCommand("status")}\` shows its version.`,
|
|
160
161
|
});
|
|
161
162
|
}
|
|
162
163
|
}
|
package/dist/kit-codes.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { printMode } from "./printed.js";
|
|
1
2
|
export const KIT_ERROR_CODES = [
|
|
2
3
|
{ code: "not_logged_in", area: "cli", message: "There is no token for the instance.", hint: "A person runs `cavelon login` (or sets CAVELON_URL and CAVELON_TOKEN); an agent never handles the token." },
|
|
3
4
|
{ code: "no_instance", area: "cli", message: "No Cavelon instance is selected.", hint: "Run `cavelon login --instance <url>`, set CAVELON_URL, or work inside a folder with cavelon.yaml." },
|
|
@@ -28,7 +29,7 @@ export const KIT_ERROR_CODES = [
|
|
|
28
29
|
{ code: "operation_ambiguous", area: "cli", message: "The short name matches several operations.", hint: "Use the full operationId the message lists." },
|
|
29
30
|
{ code: "operation_for_a_person", area: "cli", message: "The operation stays with a person (the instance marks it, or it changes a secret, a credential or an approval), so an agent does not send it.", hint: "A person runs it in their own terminal, or in the Admin." },
|
|
30
31
|
{ code: "secret_field_for_a_person", area: "cli", message: "The request sets a field the instance marks as a secret value, so an agent does not send it.", hint: "Leave the field out; a person enters the value with `cavelon secrets set <name>` or in the Admin." },
|
|
31
|
-
{ code: "confirmation_required", area: "cli", message: "The command changes something and there is no terminal to ask.", hint: "Read the plan it printed, then run it again with --yes
|
|
32
|
+
{ code: "confirmation_required", area: "cli", message: "The command changes something and there is no terminal to ask.", hint: "Read the plan it printed, then run it again with --yes." },
|
|
32
33
|
{ code: "operations_unavailable", area: "cli", message: "The instance does not offer the operations API.", hint: "Its operator turns it on with OPERATIONS_API_ENABLED." },
|
|
33
34
|
{ code: "not_an_operation_id", area: "cli", message: "That is not an operation id; they start with op_.", hint: "Commands that start work print the operation id; `cavelon status` lists running ones." },
|
|
34
35
|
{ code: "operation_gone", area: "cli", message: "The operation no longer exists on the instance.", hint: "Start the work again; `cavelon status` lists the running operations." },
|
|
@@ -59,6 +60,7 @@ export const KIT_ERROR_CODES = [
|
|
|
59
60
|
{ code: "preview_discarded", area: "cli", message: "The preview was discarded (apply --discard); nothing was imported.", hint: "Run `cavelon apply` for a new preview, show it, and confirm its id." },
|
|
60
61
|
{ code: "preview_expired", area: "cli", message: "The preview is older than the kit keeps previews; nothing was imported.", hint: "Run `cavelon apply` for a new preview, show it, and confirm its id." },
|
|
61
62
|
{ code: "confirm_token_required", area: "cli", message: "Over MCP, or run by a coding agent in its shell, a changing command confirms only with the token its preview returned, never with true or a bare --confirm.", hint: "Call the tool (or run the command) without confirm, show the person the preview, then call it again with the same arguments and confirm set to its confirm_token (--confirm <token> in a shell)." },
|
|
63
|
+
{ code: "token_mismatch", area: "cli", message: "The confirm token is not the one for this change: it belongs to another preview, or the change differs from what its preview showed; nothing was changed (exit code 4).", hint: "Show the person the new preview this answer carries, and confirm only with its confirm_token after their yes; a token confirms exactly the change its preview showed." },
|
|
62
64
|
{ code: "unknown_argument", area: "cli", message: "An MCP tool was called with an argument its schema does not list; nothing was done.", hint: "Call it again with the argument the error names (the tool's schema lists them all), spelled in snake_case." },
|
|
63
65
|
{ code: "solution_not_active", area: "cli", message: "Only an active solution can be the tenant's default route; this one is not (a draft, or inactive after a deactivate), so nothing was changed.", hint: "Activate it through the readiness gate and preview the default route in one step: `cavelon activate --harness <slug> --make-default`." },
|
|
64
66
|
{ code: "default_route_deactivate", area: "cli", message: "The solution is the tenant's default route, so deactivate refused it; nothing was changed.", hint: "Ask the person which solution should answer in the tenant's chat and widget instead, make it the default (`cavelon harness default <solution>`), then deactivate." },
|
|
@@ -90,6 +92,11 @@ export const KIT_ERROR_CODES = [
|
|
|
90
92
|
{ code: "validation_failed", area: "cli", message: "A value did not pass the check before it was sent, or the instance refused it as invalid.", hint: "The message names the field; `cavelon api describe <operation>` shows the shape." },
|
|
91
93
|
{ code: "cancelled", area: "cli", message: "Nothing was chosen or confirmed, so nothing changed.", hint: "Run the command again, or name the choice with an option." },
|
|
92
94
|
];
|
|
95
|
+
const MCP_HINTS = {
|
|
96
|
+
usage: "The message names the argument; the tool's input schema lists them all.",
|
|
97
|
+
};
|
|
93
98
|
export function kitErrorEntry(code) {
|
|
94
|
-
|
|
99
|
+
const entry = KIT_ERROR_CODES.find((e) => e.code === code);
|
|
100
|
+
const mcp = entry && printMode() === "mcp" ? MCP_HINTS[code] : undefined;
|
|
101
|
+
return mcp ? { ...entry, hint: mcp } : entry;
|
|
95
102
|
}
|
package/dist/limits.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { CavelonError, ExitCode } from "./errors.js";
|
|
2
2
|
import { readPrincipal } from "./principal.js";
|
|
3
|
-
import { cavelonCommand } from "./
|
|
3
|
+
import { cavelonCommand } from "./printed.js";
|
|
4
4
|
const NEAR = 0.8;
|
|
5
5
|
export function changedBy(limit) {
|
|
6
6
|
if (limit.changeable_by === "tenant_admin")
|
package/dist/main.js
CHANGED
|
@@ -1,10 +1,12 @@
|
|
|
1
1
|
import { parseArgs } from "node:util";
|
|
2
2
|
import { GLOBAL_OPTIONS, optionDescription, optionFlag, renameFormerOptions } from "./command.js";
|
|
3
|
+
import { agentVariable } from "./agent-env.js";
|
|
3
4
|
import { createContext, withWarnings } from "./context.js";
|
|
4
5
|
import { CONFIRM_TOKEN } from "./confirm-token.js";
|
|
5
6
|
import { asCavelonError, ExitCode, usageError } from "./errors.js";
|
|
6
7
|
import { blockerLines } from "./format.js";
|
|
7
8
|
import { blockerLines as detailedBlockerLines } from "./preview-report.js";
|
|
9
|
+
import { printingFor, spokenError } from "./printed.js";
|
|
8
10
|
import { KIT_VERSION } from "./version.js";
|
|
9
11
|
import { currentInstall, installLabel } from "./install.js";
|
|
10
12
|
import { startUpdateCheck } from "./update-check.js";
|
|
@@ -59,7 +61,17 @@ export async function run(argv, io, commands = COMMANDS, updates = {}) {
|
|
|
59
61
|
command: spec.name,
|
|
60
62
|
fetch: updates.fetch,
|
|
61
63
|
});
|
|
62
|
-
const
|
|
64
|
+
const { globals } = ctx;
|
|
65
|
+
const given = spec.storesTarget ? {} : { instance: globals.instance, tenant: globals.tenant, env: globals.solutionEnv };
|
|
66
|
+
const target = { mode: "cli", commands, agentShell: Boolean(agentVariable(io.env)), ...given };
|
|
67
|
+
const result = await printingFor(target, async () => {
|
|
68
|
+
try {
|
|
69
|
+
return await spec.run(ctx, parsed);
|
|
70
|
+
}
|
|
71
|
+
catch (error) {
|
|
72
|
+
throw spokenError(error);
|
|
73
|
+
}
|
|
74
|
+
});
|
|
63
75
|
printResult(ctx, result);
|
|
64
76
|
await printNotice(io, notice);
|
|
65
77
|
return result.exitCode ?? ExitCode.ok;
|