@cavelon/cli 0.1.10 → 0.1.12
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 +34 -15
- package/dist/access.js +194 -0
- package/dist/acting.js +123 -0
- package/dist/agent-env.js +20 -2
- package/dist/change-confirmation.js +93 -0
- package/dist/commands/api.js +77 -30
- package/dist/commands/chat.js +16 -8
- package/dist/commands/db.js +474 -0
- package/dist/commands/docs.js +83 -7
- package/dist/commands/index.js +7 -0
- package/dist/commands/limits-set.js +11 -5
- package/dist/commands/loops.js +72 -9
- package/dist/commands/models.js +12 -6
- package/dist/commands/sandboxes.js +7 -2
- package/dist/commands/session.js +111 -24
- package/dist/commands/setup.js +1 -1
- package/dist/commands/solution.js +211 -54
- package/dist/commands/tenants.js +55 -12
- package/dist/commands/values.js +104 -23
- package/dist/commands/work.js +13 -5
- package/dist/confirm-token.js +90 -7
- package/dist/context.js +5 -1
- package/dist/contracts.js +37 -12
- package/dist/database-queries.js +301 -0
- package/dist/fsutil.js +14 -0
- package/dist/http.js +69 -3
- package/dist/install.js +30 -0
- package/dist/invoke.js +12 -2
- package/dist/kit-codes.js +9 -2
- package/dist/mcp.js +106 -19
- package/dist/openapi.js +7 -0
- package/dist/package-check.js +19 -0
- package/dist/preview-report.js +2 -2
- package/dist/principal.js +24 -2
- package/dist/printed.js +5 -0
- package/dist/secret-access.js +30 -9
- package/dist/session.js +36 -8
- package/dist/skills/cavelon-authoring/SKILL.md +93 -10
- package/dist/skills/cavelon-long-running/SKILL.md +18 -8
- package/dist/skills/cavelon-loop/SKILL.md +126 -41
- package/dist/skills/cavelon-testing/SKILL.md +32 -3
- package/dist/trace-view.js +10 -0
- package/dist/update-check.js +2 -2
- package/dist/user-config.js +24 -0
- package/package.json +1 -1
package/dist/commands/tenants.js
CHANGED
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
import { boolOption, CURSOR_OPTION, intOption, LIMIT_OPTION, pageOf, positional, stringOption, } from "../command.js";
|
|
2
2
|
import { CavelonError, ExitCode, usageError } from "../errors.js";
|
|
3
|
-
import { confirmation, confirmTokenRequired } from "../confirm-token.js";
|
|
3
|
+
import { confirmation, confirmTokenRequired, PERSON_CONFIRMS_HELP } from "../confirm-token.js";
|
|
4
4
|
import { keyValues, moreHint, table } from "../format.js";
|
|
5
5
|
import { callStable } from "../invoke.js";
|
|
6
6
|
import { formatQuota, limitError, limitsOrWarn, readQuotas } from "../limits.js";
|
|
7
7
|
import { containing } from "../choose.js";
|
|
8
8
|
import { readPrincipal, readTenantless } from "../principal.js";
|
|
9
|
+
import { ACTIVATOR, accessFor, mayActivate } from "../access.js";
|
|
9
10
|
import { requireInstance } from "../session.js";
|
|
10
11
|
import { listsTenants, searchTenants } from "../tenant-choice.js";
|
|
11
12
|
import { harnessNotFoundError, lookupHarness, resolveHarnessId } from "../harness-ref.js";
|
|
@@ -76,21 +77,32 @@ async function entersTenant(client, tenantId) {
|
|
|
76
77
|
export const tenantCreate = {
|
|
77
78
|
name: "tenant create",
|
|
78
79
|
tenantless: true,
|
|
79
|
-
summary: "Create a tenant (personal access token in Platform mode with tenants.manage).",
|
|
80
|
+
summary: "Create a tenant (personal access token in Platform mode with tenants.manage); previews first, --confirm creates it.",
|
|
80
81
|
description: "A tenant API key never can. Before sending, the token is checked: one that may not enter Platform mode, or enters it\n" +
|
|
81
|
-
"without tenants.manage, is refused with exit 7 and nothing is sent.
|
|
82
|
-
"
|
|
82
|
+
"without tenants.manage, is refused with exit 7 and nothing is sent. Without --confirm nothing is created: the preview\n" +
|
|
83
|
+
"names the tenant, its plan and the instance it would be created on. A tenant is a platform change, so show the preview\n" +
|
|
84
|
+
"to a person and confirm only with their yes. With --use, the new tenant is chosen only once the instance confirms the\n" +
|
|
85
|
+
"token acts in it. Inviting people and assigning roles stay in the Admin.\n" +
|
|
86
|
+
PERSON_CONFIRMS_HELP,
|
|
83
87
|
readOnly: false,
|
|
84
88
|
mcpTool: "tenant_create",
|
|
85
89
|
positionals: [{ name: "slug", description: "Lower-case letters, digits and dashes.", required: true }],
|
|
86
90
|
options: {
|
|
87
91
|
name: { type: "string", value: "<name>", description: "Display name (default: the slug)." },
|
|
88
92
|
plan: { type: "string", value: "<plan>", description: "Licence plan, when the instance knows several." },
|
|
89
|
-
use: {
|
|
93
|
+
use: {
|
|
94
|
+
type: "boolean",
|
|
95
|
+
description: "Switch to the new tenant afterwards (`cavelon use`), once the token is known to act in it.",
|
|
96
|
+
mcpDescription: "Switch to the new tenant afterwards for this MCP session only (as use_tenant does), once the token is known to act in it.",
|
|
97
|
+
},
|
|
90
98
|
"idempotency-key": IDEMPOTENCY_OPTION,
|
|
99
|
+
confirm: { type: "boolean", mcpToken: true, description: "Create the tenant (after a person saw the preview)." },
|
|
91
100
|
},
|
|
101
|
+
examples: ["cavelon tenant create newco --name NewCo", "cavelon tenant create newco --name NewCo --confirm"],
|
|
92
102
|
async run(ctx, input) {
|
|
93
103
|
const session = await ctx.session();
|
|
104
|
+
if (ctx.mode === "mcp" && input.options.confirm === true)
|
|
105
|
+
throw confirmTokenRequired("tenant_create");
|
|
94
106
|
if (session.tokenKind === "api_key") {
|
|
95
107
|
throw new CavelonError(ExitCode.unauthorized, {
|
|
96
108
|
code: "api_key_cannot_create_tenants",
|
|
@@ -105,6 +117,26 @@ export const tenantCreate = {
|
|
|
105
117
|
const plan = stringOption(input, "plan");
|
|
106
118
|
if (plan)
|
|
107
119
|
body.plan = plan;
|
|
120
|
+
const words = ["tenant", "create", slug, "--name", body.name, ...(plan ? ["--plan", plan] : []), ...(boolOption(input, "use") ? ["--use"] : [])];
|
|
121
|
+
const key = stringOption(input, "idempotency-key");
|
|
122
|
+
if (key)
|
|
123
|
+
words.push("--idempotency-key", key);
|
|
124
|
+
const gate = await confirmation(ctx, input, "tenant_create", body, {
|
|
125
|
+
platform: "outside",
|
|
126
|
+
person: { what: `Create the tenant ${body.name} (${slug})${plan ? ` on plan ${plan}` : ""} on the platform.`, words: [...words, "--confirm"] },
|
|
127
|
+
});
|
|
128
|
+
if (!gate.confirmed) {
|
|
129
|
+
const confirm = gate.confirm(cavelonCommand(...words, "--confirm"));
|
|
130
|
+
return {
|
|
131
|
+
data: { created: false, would: "create_tenant", tenant: { slug, name: body.name, plan: plan ?? null }, confirm, ...gate.fields },
|
|
132
|
+
text: [
|
|
133
|
+
`Creating tenant ${body.name} (${slug})${plan ? ` on plan ${plan}` : ""} adds a tenant to the platform: it holds its own solutions, people, limits and budget.`,
|
|
134
|
+
gate.where, ...(gate.mismatch ? [gate.mismatch] : []),
|
|
135
|
+
`Nothing was created. Show this to a person; with their yes: ${confirm}`,
|
|
136
|
+
].join("\n"),
|
|
137
|
+
...(gate.exitCode ? { exitCode: gate.exitCode } : {}),
|
|
138
|
+
};
|
|
139
|
+
}
|
|
108
140
|
const tenant = await callStable(ctx, "POST", "/api/v1/tenants", "creating tenants", {
|
|
109
141
|
body,
|
|
110
142
|
sendTenant: false,
|
|
@@ -120,8 +152,11 @@ export const tenantCreate = {
|
|
|
120
152
|
`\`${cavelonCommand("use", tenant.slug)}\`.`);
|
|
121
153
|
return { data: { ...tenant, used: false }, text: `${created} Not switched: this token does not act in it.` };
|
|
122
154
|
}
|
|
123
|
-
await rememberTenant(ctx, requireInstance(session), { ref: tenant.slug, id: tenant.id, name: tenant.name });
|
|
124
|
-
return {
|
|
155
|
+
const scope = await rememberTenant(ctx, requireInstance(session), { ref: tenant.slug, id: tenant.id, name: tenant.name, slug: tenant.slug });
|
|
156
|
+
return {
|
|
157
|
+
data: { ...tenant, used: true, ...(scope === "session" ? { used_in: "session" } : {}) },
|
|
158
|
+
text: scope === "session" ? `${created} Now using it in this MCP session; the tenant stored for your user is unchanged.` : `${created} Now using it.`,
|
|
159
|
+
};
|
|
125
160
|
},
|
|
126
161
|
};
|
|
127
162
|
export const tenantList = {
|
|
@@ -238,15 +273,17 @@ export const harnessDefault = {
|
|
|
238
273
|
"tenant's default is an empty `default` solution, so a solution built beside it answers nobody there until it becomes the\n" +
|
|
239
274
|
"default. Without --confirm nothing changes: the preview names the current default and the one that would replace it.\n" +
|
|
240
275
|
"This changes live traffic, so show the preview to a person and confirm only with their yes. `is_default` in\n" +
|
|
241
|
-
"harnesses.yaml is not applied by `apply`; this is the way to set it
|
|
276
|
+
"harnesses.yaml is not applied by `apply`; this is the way to set it.\n" +
|
|
277
|
+
PERSON_CONFIRMS_HELP,
|
|
242
278
|
readOnly: false,
|
|
243
279
|
idempotent: true,
|
|
244
280
|
mcpTool: "harness_default",
|
|
281
|
+
operations: ["POST /api/v1/harnesses/{harness_id}/default"],
|
|
245
282
|
positionals: [{ name: "solution", description: "Name, slug or id of the solution; default: cavelon.yaml's harness." }],
|
|
246
283
|
options: {
|
|
247
284
|
confirm: { type: "boolean", mcpToken: true, description: "Change the default route (after a person saw the preview)." },
|
|
248
285
|
},
|
|
249
|
-
examples: ["cavelon harness default support", "cavelon harness default support --confirm"
|
|
286
|
+
examples: ["cavelon harness default support", "cavelon harness default support --confirm"],
|
|
250
287
|
async run(ctx, input) {
|
|
251
288
|
const session = await ctx.session();
|
|
252
289
|
const ref = positional(input, "solution") ?? session.envFile?.harness ?? session.project?.harness;
|
|
@@ -268,12 +305,16 @@ export const harnessDefault = {
|
|
|
268
305
|
throw new CavelonError(ExitCode.conflict, {
|
|
269
306
|
code: "solution_not_active",
|
|
270
307
|
message: `${named(harness)} is ${harness.status}, and only an active solution can be the tenant's default route; nothing was changed.`,
|
|
271
|
-
hint:
|
|
308
|
+
hint: (mayActivate(await accessFor(await ctx.client())) === false
|
|
309
|
+
? `Only an active solution can be the default, and to activate it ${ACTIVATOR}. `
|
|
310
|
+
: `Activate it through the readiness gate and preview the default route in one step: ${cavelonCommand("activate", "--harness", harness.slug, "--make-default")}. `) +
|
|
272
311
|
`The default route stays ${current ? named(current) : "as it is"} until then.`,
|
|
273
312
|
details: { harness: target, default_route: current },
|
|
274
313
|
});
|
|
275
314
|
}
|
|
276
|
-
const gate = await confirmation(ctx, input, "harness_default", { harness: harness.id, from: current?.id ?? null }
|
|
315
|
+
const gate = await confirmation(ctx, input, "harness_default", { harness: harness.id, from: current?.id ?? null }, {
|
|
316
|
+
person: { what: defaultChangeLine(harness, route), words: ["harness", "default", harness.slug, "--confirm"] },
|
|
317
|
+
});
|
|
277
318
|
if (!gate.confirmed) {
|
|
278
319
|
return {
|
|
279
320
|
data: {
|
|
@@ -286,7 +327,7 @@ export const harnessDefault = {
|
|
|
286
327
|
},
|
|
287
328
|
text: [
|
|
288
329
|
defaultChangeLine(harness, route),
|
|
289
|
-
...(gate.mismatch ? [gate.mismatch] : []),
|
|
330
|
+
gate.where, ...(gate.mismatch ? [gate.mismatch] : []),
|
|
290
331
|
`Show this to a person; with their yes: ${gate.confirm(commands.confirm)}`,
|
|
291
332
|
].join("\n"),
|
|
292
333
|
...(gate.exitCode ? { exitCode: gate.exitCode } : {}),
|
|
@@ -347,6 +388,7 @@ export const harnessNew = {
|
|
|
347
388
|
summary: "Create an empty draft solution (harness).",
|
|
348
389
|
readOnly: false,
|
|
349
390
|
mcpTool: "harness_new",
|
|
391
|
+
operations: ["POST /api/v1/harnesses"],
|
|
350
392
|
positionals: [{ name: "slug", description: "The new solution's slug.", required: true }],
|
|
351
393
|
options: {
|
|
352
394
|
name: { type: "string", value: "<name>", description: "Display name (default: the slug)." },
|
|
@@ -375,6 +417,7 @@ export const harnessClone = {
|
|
|
375
417
|
summary: "Copy a solution into a new draft solution.",
|
|
376
418
|
readOnly: false,
|
|
377
419
|
mcpTool: "harness_clone",
|
|
420
|
+
operations: ["POST /api/v1/harnesses/{harness_id}/clone"],
|
|
378
421
|
positionals: [{ name: "source", description: "Name, slug or id of the solution to copy.", required: true }],
|
|
379
422
|
options: {
|
|
380
423
|
slug: { type: "string", value: "<slug>", description: "The copy's slug." },
|
package/dist/commands/values.js
CHANGED
|
@@ -1,12 +1,14 @@
|
|
|
1
1
|
import { boolOption, CURSOR_OPTION, intOption, LIMIT_OPTION, pageOf, positional, stringOption, } from "../command.js";
|
|
2
|
-
import {
|
|
2
|
+
import { refuseForAgent } from "../agent-env.js";
|
|
3
|
+
import { confirmation, PERSON_CONFIRMS_HELP } from "../confirm-token.js";
|
|
3
4
|
import { CavelonError, ExitCode, usageError, validationError } from "../errors.js";
|
|
4
5
|
import { clip, keyValues, moreHint, table } from "../format.js";
|
|
5
6
|
import { callStable, workflowOperation } from "../invoke.js";
|
|
6
7
|
import { readAll } from "../io.js";
|
|
7
8
|
import { schemaErrors } from "../openapi.js";
|
|
8
9
|
import { readPrincipal } from "../principal.js";
|
|
9
|
-
import {
|
|
10
|
+
import { principalOf } from "../access.js";
|
|
11
|
+
import { permissionsNamed, SECRETS_IN_ADMIN, SECRETS_PERMISSIONS, secretsInAdminOnly, secretsPermissionMissing, variablesPermissionMissing, } from "../secret-access.js";
|
|
10
12
|
import { readHidden } from "../prompt.js";
|
|
11
13
|
import { readPackage } from "../package-files.js";
|
|
12
14
|
import { requireToken } from "../session.js";
|
|
@@ -22,6 +24,12 @@ const LIST_VALUE_CHARS = 200;
|
|
|
22
24
|
export function secretSetCommand(name, env) {
|
|
23
25
|
return printedCommand(["secrets", "set", name], { env });
|
|
24
26
|
}
|
|
27
|
+
export function secretStep(name, inAdmin, env) {
|
|
28
|
+
return inAdmin ? `${SECRETS_IN_ADMIN} (${name})` : secretSetCommand(name, env);
|
|
29
|
+
}
|
|
30
|
+
export async function secretsSetInAdmin(ctx) {
|
|
31
|
+
return secretsInAdminOnly(await ctx.client().then(principalOf, () => undefined)) === true;
|
|
32
|
+
}
|
|
25
33
|
export function variableSetCommand(name, env) {
|
|
26
34
|
return printedCommand(["variables", "set", name, fill("value")], { env });
|
|
27
35
|
}
|
|
@@ -108,12 +116,17 @@ export const variablesGet = {
|
|
|
108
116
|
};
|
|
109
117
|
export const variablesSet = {
|
|
110
118
|
name: "variables set",
|
|
111
|
-
summary: "Create or replace
|
|
119
|
+
summary: "Create a tenant variable, or replace one (previews first, --confirm replaces it).",
|
|
112
120
|
description: "The value is plain text that anyone who may view the tenant's settings reads; never put a credential into a variable,\n" +
|
|
113
|
-
"use `cavelon secrets set` (a person runs it). --stdin reads the value from standard input instead of the argument
|
|
121
|
+
"use `cavelon secrets set` (a person runs it). --stdin reads the value from standard input instead of the argument.\n" +
|
|
122
|
+
"A new variable is created at once. Replacing another value needs --confirm: without it nothing changes, and the preview\n" +
|
|
123
|
+
"shows the old and the new value. A variable is tenant-wide, so every solution that names it, active ones included, reads\n" +
|
|
124
|
+
"the new value: show the preview to a person and confirm only with their yes.\n" +
|
|
125
|
+
PERSON_CONFIRMS_HELP,
|
|
114
126
|
readOnly: false,
|
|
115
127
|
idempotent: true,
|
|
116
128
|
mcpTool: "variables_set",
|
|
129
|
+
operations: ["PUT /api/v1/variables/{name}"],
|
|
117
130
|
positionals: [
|
|
118
131
|
{ name: "name", description: "The variable's name, as {{var:<name>}} uses it.", required: true },
|
|
119
132
|
{ name: "value", description: "The value (plain text, not a credential)." },
|
|
@@ -121,8 +134,14 @@ export const variablesSet = {
|
|
|
121
134
|
options: {
|
|
122
135
|
stdin: { type: "boolean", description: "Read the value from standard input.", cliOnly: true },
|
|
123
136
|
env: ENV_OPTION,
|
|
137
|
+
confirm: { type: "boolean", mcpToken: true, description: "Replace an existing value (after a person saw the preview); a new variable needs none." },
|
|
124
138
|
},
|
|
125
|
-
examples: [
|
|
139
|
+
examples: [
|
|
140
|
+
"cavelon variables set crm_base_url https://crm.example.com",
|
|
141
|
+
"cavelon variables set greeting --stdin < greeting.txt",
|
|
142
|
+
"cavelon variables set crm_base_url https://crm2.example.com --confirm",
|
|
143
|
+
"cavelon variables set crm_base_url https://crm2.example.com --confirm <token>",
|
|
144
|
+
],
|
|
126
145
|
async run(ctx, input) {
|
|
127
146
|
const name = positional(input, "name");
|
|
128
147
|
const argument = positional(input, "value");
|
|
@@ -133,13 +152,37 @@ export const variablesSet = {
|
|
|
133
152
|
throw usageError("Missing <value>.", "Usage: cavelon variables set <name> <value> (or --stdin)");
|
|
134
153
|
const value = argument ?? withoutLineEnd(await readAll(ctx.io.stdin));
|
|
135
154
|
if (TOKEN_PREFIXES.some((prefix) => value.startsWith(prefix))) {
|
|
136
|
-
throw usageError("That value looks like a key or token. A variable is plain text anyone with settings access reads; nothing was sent.", `Keep credentials in a secret, which a person sets: ${
|
|
155
|
+
throw usageError("That value looks like a key or token. A variable is plain text anyone with settings access reads; nothing was sent.", `Keep credentials in a secret, which a person sets: ${secretStep(name, await secretsSetInAdmin(ctx))}. If this was a real token, revoke it.`);
|
|
137
156
|
}
|
|
138
157
|
await checkName(ctx, "PUT", "/api/v1/variables/{name}", "setting tenant variables", name);
|
|
139
158
|
const previous = await readVariable(ctx, name);
|
|
159
|
+
if (previous && previous.value !== value) {
|
|
160
|
+
const words = ["variables", "set", name, ...(fromStdin ? ["--stdin"] : [value]), "--confirm"];
|
|
161
|
+
const gate = await confirmation(ctx, input, "variables_set", { name, previous: previous.value, value }, {
|
|
162
|
+
person: {
|
|
163
|
+
what: `Replace the tenant variable ${name}, which every solution of the tenant reads: ${JSON.stringify(clip(previous.value, LIST_VALUE_CHARS))} → ${JSON.stringify(clip(value, LIST_VALUE_CHARS))}.`,
|
|
164
|
+
words,
|
|
165
|
+
},
|
|
166
|
+
});
|
|
167
|
+
if (!gate.confirmed) {
|
|
168
|
+
const confirm = gate.confirm(cavelonCommand(...words));
|
|
169
|
+
return {
|
|
170
|
+
data: { name, changed: false, created: false, would: "replace", previous: previous.value, value, confirm, ...gate.fields },
|
|
171
|
+
text: [
|
|
172
|
+
`Variable ${name}: ${JSON.stringify(clip(previous.value, LIST_VALUE_CHARS))} → ${JSON.stringify(clip(value, LIST_VALUE_CHARS))}.`,
|
|
173
|
+
"It is tenant-wide: every solution of the tenant that names {{var:" + name + "}}, active ones included, reads the new value.",
|
|
174
|
+
gate.where, ...(gate.mismatch ? [gate.mismatch] : []),
|
|
175
|
+
`Nothing was changed. Show this to a person; with their yes: ${confirm}${fromStdin ? " (with the same value on standard input)" : ""}`,
|
|
176
|
+
].join("\n"),
|
|
177
|
+
...(gate.exitCode ? { exitCode: gate.exitCode } : {}),
|
|
178
|
+
};
|
|
179
|
+
}
|
|
180
|
+
}
|
|
140
181
|
const saved = await callStable(ctx, "PUT", "/api/v1/variables/{name}", "setting tenant variables", {
|
|
141
182
|
params: { name: [name] },
|
|
142
183
|
body: { value },
|
|
184
|
+
}).catch((error) => {
|
|
185
|
+
throw variablesRefusedForRole(error, "set", name, fromStdin ? undefined : value);
|
|
143
186
|
});
|
|
144
187
|
const changed = previous?.value !== saved.value;
|
|
145
188
|
let text = `Variable ${saved.name} already had this value.`;
|
|
@@ -160,18 +203,21 @@ export const variablesDelete = {
|
|
|
160
203
|
mcpTool: false,
|
|
161
204
|
positionals: [{ name: "name", description: "The variable's name.", required: true }],
|
|
162
205
|
options: { confirm: CONFIRM_OPTION, env: ENV_OPTION },
|
|
163
|
-
examples: ["cavelon variables delete old_url", "cavelon variables delete old_url --confirm"
|
|
206
|
+
examples: ["cavelon variables delete old_url", "cavelon variables delete old_url --confirm"],
|
|
164
207
|
async run(ctx, input) {
|
|
165
208
|
const name = positional(input, "name");
|
|
166
209
|
const current = await readVariable(ctx, name);
|
|
167
210
|
if (!current)
|
|
168
211
|
return { data: { name, deleted: false, existed: false }, text: `This tenant has no variable "${name}"; nothing to delete.` };
|
|
169
|
-
const
|
|
212
|
+
const words = ["variables", "delete", name, "--confirm"];
|
|
213
|
+
const gate = await confirmation(ctx, input, "variables_delete", { name, value: current.value }, {
|
|
214
|
+
person: { what: `Delete the tenant variable ${name}; a prompt or tool that names it gets no value afterwards.`, words },
|
|
215
|
+
});
|
|
170
216
|
if (!gate.confirmed) {
|
|
171
|
-
const confirm = gate.confirm(cavelonCommand(
|
|
217
|
+
const confirm = gate.confirm(cavelonCommand(...words));
|
|
172
218
|
return {
|
|
173
219
|
data: { name, deleted: false, existed: true, value: current.value, confirm, ...gate.fields },
|
|
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}`,
|
|
220
|
+
text: `Variable ${name} = ${JSON.stringify(clip(current.value, LIST_VALUE_CHARS))}.\n${gate.where}\n${gate.mismatch ? `${gate.mismatch}\n` : ""}Nothing was deleted. Delete it with: ${confirm}`,
|
|
175
221
|
...(gate.exitCode ? { exitCode: gate.exitCode } : {}),
|
|
176
222
|
};
|
|
177
223
|
}
|
|
@@ -180,12 +226,25 @@ export const variablesDelete = {
|
|
|
180
226
|
}
|
|
181
227
|
catch (error) {
|
|
182
228
|
if (!notFound(error))
|
|
183
|
-
throw error;
|
|
229
|
+
throw variablesRefusedForRole(error, "delete", name);
|
|
184
230
|
return { data: { name, deleted: false, existed: false }, text: `This tenant has no variable "${name}"; nothing to delete.` };
|
|
185
231
|
}
|
|
186
232
|
return { data: { name, deleted: true, existed: true, value: current.value }, text: `Deleted variable ${name}.` };
|
|
187
233
|
},
|
|
188
234
|
};
|
|
235
|
+
async function refuseWhereAdminOnly(ctx, verb, name) {
|
|
236
|
+
const principal = await ctx.client().then(principalOf, () => undefined);
|
|
237
|
+
const inAdmin = Array.isArray(principal?.needs_a_person);
|
|
238
|
+
if (secretsInAdminOnly(principal, verb === "set" ? "PUT" : "DELETE") !== true)
|
|
239
|
+
return { inAdmin };
|
|
240
|
+
const credential = principal.kind === "api_key" ? "A tenant API key" : "A personal access token";
|
|
241
|
+
throw new CavelonError(ExitCode.needsAction, {
|
|
242
|
+
code: "secret_needs_a_person",
|
|
243
|
+
message: `${credential} cannot ${verb} a secret on this instance, so nothing was sent: only a person signed in to the Admin ${verb === "set" ? "sets" : "deletes"} a secret's value.`,
|
|
244
|
+
hint: `A person ${verb === "set" ? "sets" : "deletes"} ${name} ${SECRETS_IN_ADMIN}.`,
|
|
245
|
+
details: { sent: false, credential: principal.kind },
|
|
246
|
+
});
|
|
247
|
+
}
|
|
189
248
|
async function requirePerson(ctx, verb, name) {
|
|
190
249
|
const session = await ctx.session();
|
|
191
250
|
requireToken(session);
|
|
@@ -202,13 +261,21 @@ async function requirePerson(ctx, verb, name) {
|
|
|
202
261
|
details: { sent: false, credential: "api_key" },
|
|
203
262
|
});
|
|
204
263
|
}
|
|
205
|
-
function refusedForRole(error, verb, name) {
|
|
264
|
+
function refusedForRole(error, verb, name, inAdmin) {
|
|
206
265
|
if (!(error instanceof CavelonError) || error.status !== 403 || error.code === "secret_needs_a_person")
|
|
207
266
|
return error;
|
|
208
267
|
const named = permissionsNamed(error.message);
|
|
209
268
|
if (!named.length && error.code !== "forbidden")
|
|
210
269
|
return error;
|
|
211
|
-
return secretsPermissionMissing(verb, name, named.length ? named : SECRETS_PERMISSIONS);
|
|
270
|
+
return secretsPermissionMissing(verb, name, named.length ? named : SECRETS_PERMISSIONS, inAdmin);
|
|
271
|
+
}
|
|
272
|
+
function variablesRefusedForRole(error, verb, name, value) {
|
|
273
|
+
if (!(error instanceof CavelonError) || error.status !== 403)
|
|
274
|
+
return error;
|
|
275
|
+
const named = permissionsNamed(error.message);
|
|
276
|
+
if (!named.length && error.code !== "forbidden")
|
|
277
|
+
return error;
|
|
278
|
+
return variablesPermissionMissing(verb, name, named.length ? named : SECRETS_PERMISSIONS, value);
|
|
212
279
|
}
|
|
213
280
|
function withoutLineEnd(text) {
|
|
214
281
|
if (text.endsWith("\r\n"))
|
|
@@ -304,8 +371,8 @@ export const secretsList = {
|
|
|
304
371
|
name: "secrets list",
|
|
305
372
|
summary: "List the tenant's secret names ({{secret:…}}) with whether each is set; never a value.",
|
|
306
373
|
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
|
|
308
|
-
"an agent never sets or reads a secret value.",
|
|
374
|
+
"package declares that the tenant does not know yet. A person sets a missing one with `cavelon secrets set <name>`, or\n" +
|
|
375
|
+
"in the Admin under Settings › Secrets where the instance lets no token set one; an agent never sets or reads a secret value.",
|
|
309
376
|
readOnly: true,
|
|
310
377
|
idempotent: true,
|
|
311
378
|
mcpTool: "secrets_list",
|
|
@@ -323,14 +390,19 @@ export const secretsList = {
|
|
|
323
390
|
const local = (await locallyDeclaredSecrets(session)).filter((d) => !all.some((s) => s.name === d.name));
|
|
324
391
|
const wanted = boolOption(input, "missing") ? all.filter((s) => s.status !== "set") : all;
|
|
325
392
|
const page = pageOf(wanted, limit, stringOption(input, "cursor"));
|
|
326
|
-
const
|
|
393
|
+
const inAdmin = await secretsSetInAdmin(ctx);
|
|
394
|
+
const items = page.items.map((s) => (s.status === "set" ? s : { ...s, set_by_person: secretStep(s.name, inAdmin) }));
|
|
327
395
|
const missing = all.filter((s) => s.status !== "set").length;
|
|
328
396
|
const onlyMissing = boolOption(input, "missing");
|
|
329
397
|
let text = onlyMissing ? "Every secret this tenant knows is set." : "This tenant has no secrets, and no package applied to it declared one.";
|
|
330
398
|
if (items.length) {
|
|
331
399
|
const rows = items.map((s) => ({ ...s, declared: s.declared ? "yes" : "", changed_at: s.changed_at ?? "", description: s.description ?? "" }));
|
|
332
400
|
const next = moreHint(page.next_cursor, cavelonCommand("secrets", "list", ...(onlyMissing ? ["--missing"] : [])));
|
|
333
|
-
const howTo = missing
|
|
401
|
+
const howTo = !missing
|
|
402
|
+
? ""
|
|
403
|
+
: inAdmin
|
|
404
|
+
? `\n\n${missing} not set. A person sets each, signed in to the Admin under Settings › Secrets.`
|
|
405
|
+
: `\n\n${missing} not set. A person sets each with: ${cavelonCommand("secrets", "set", fill("name"))}`;
|
|
334
406
|
text = table(rows, ["name", "status", "declared", "changed_at", "description"], 50) + next + howTo;
|
|
335
407
|
}
|
|
336
408
|
if (local.length) {
|
|
@@ -338,7 +410,7 @@ export const secretsList = {
|
|
|
338
410
|
text +=
|
|
339
411
|
`\n\n${where} declares ${local.map((d) => d.name).join(", ")}, which the tenant does not know yet: it lists ` +
|
|
340
412
|
`${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) =>
|
|
413
|
+
local.map((d) => secretStep(d.name, inAdmin)).join("; ");
|
|
342
414
|
}
|
|
343
415
|
return {
|
|
344
416
|
data: { items, next_cursor: page.next_cursor, total: page.total, not_set: missing, ...(local.length ? { declared_locally: local } : {}) },
|
|
@@ -351,7 +423,10 @@ export const secretsSet = {
|
|
|
351
423
|
summary: "Set a secret's value (a person runs this, never the agent).",
|
|
352
424
|
description: "Asks for the value without echoing it, or reads it from standard input when that is piped (one trailing line break is\n" +
|
|
353
425
|
"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
|
|
426
|
+
"nor can a role the instance does not allow to manage secrets (a Builder): its refusal then names who can, a tenant Owner.\n" +
|
|
427
|
+
"An instance that lets only a person signed in to the Admin set a secret (its /meta/principal lists the operation in\n" +
|
|
428
|
+
"needs_a_person) refuses every token; there it is refused before it reads a value, naming the Admin page.\n" +
|
|
429
|
+
"Run by a coding agent in its shell, it is refused before it reads a value (operation_for_a_person).",
|
|
355
430
|
readOnly: false,
|
|
356
431
|
idempotent: true,
|
|
357
432
|
mcpTool: false,
|
|
@@ -361,6 +436,8 @@ export const secretsSet = {
|
|
|
361
436
|
preprocess: refuseValueArgument,
|
|
362
437
|
async run(ctx, input) {
|
|
363
438
|
const name = positional(input, "name");
|
|
439
|
+
const { inAdmin } = await refuseWhereAdminOnly(ctx, "set", name);
|
|
440
|
+
refuseForAgent(ctx, "Setting a secret's value", secretSetCommand(name));
|
|
364
441
|
await requirePerson(ctx, "set", name);
|
|
365
442
|
await checkName(ctx, "PUT", "/api/v1/secrets/{name}", "setting secrets", name);
|
|
366
443
|
const value = await readSecretValue(ctx, name);
|
|
@@ -369,7 +446,7 @@ export const secretsSet = {
|
|
|
369
446
|
status = await callStable(ctx, "PUT", "/api/v1/secrets/{name}", "setting secrets", { params: { name: [name] }, body: { value } });
|
|
370
447
|
}
|
|
371
448
|
catch (error) {
|
|
372
|
-
throw withoutValue(refusedForRole(error, "set", name), value);
|
|
449
|
+
throw withoutValue(refusedForRole(error, "set", name, inAdmin), value);
|
|
373
450
|
}
|
|
374
451
|
const data = secretView(status);
|
|
375
452
|
return { data, text: `Secret ${data.name} is set${changedNote(data.changed_at)}. Its value is never shown.` };
|
|
@@ -379,7 +456,9 @@ export const secretsDelete = {
|
|
|
379
456
|
name: "secrets delete",
|
|
380
457
|
summary: "Delete a secret's value (needs --confirm; a person runs this).",
|
|
381
458
|
description: "Without --confirm, shows the secret's status and deletes nothing. A tool or prompt that names it fails until a person\n" +
|
|
382
|
-
"sets it again. A tenant API key cannot delete a secret
|
|
459
|
+
"sets it again. A tenant API key cannot delete a secret, nor can any token on an instance that lets only a person signed\n" +
|
|
460
|
+
"in to the Admin do it (secret_needs_a_person). Run by a coding agent in its shell, it is refused, with or without\n" +
|
|
461
|
+
"--confirm (operation_for_a_person).",
|
|
383
462
|
readOnly: false,
|
|
384
463
|
destructive: true,
|
|
385
464
|
idempotent: true,
|
|
@@ -389,6 +468,8 @@ export const secretsDelete = {
|
|
|
389
468
|
examples: ["cavelon secrets delete old_token", "cavelon secrets delete old_token --confirm", "cavelon secrets delete old_token --confirm <token>"],
|
|
390
469
|
async run(ctx, input) {
|
|
391
470
|
const name = positional(input, "name");
|
|
471
|
+
const { inAdmin } = await refuseWhereAdminOnly(ctx, "delete", name);
|
|
472
|
+
refuseForAgent(ctx, "Deleting a secret's value", cavelonCommand("secrets", "delete", name));
|
|
392
473
|
await requirePerson(ctx, "delete", name);
|
|
393
474
|
const current = secretView(await callStable(ctx, "GET", "/api/v1/secrets/{name}", "tenant secrets", { params: { name: [name] } }));
|
|
394
475
|
const nothing = { data: { ...current, deleted: false }, text: `Secret ${name} has no value; nothing to delete.` };
|
|
@@ -399,7 +480,7 @@ export const secretsDelete = {
|
|
|
399
480
|
const confirm = gate.confirm(cavelonCommand("secrets", "delete", name, "--confirm"));
|
|
400
481
|
return {
|
|
401
482
|
data: { ...current, deleted: false, confirm, ...gate.fields },
|
|
402
|
-
text: `Secret ${name} is set${changedNote(current.changed_at)}.\n${gate.mismatch ? `${gate.mismatch}\n` : ""}Nothing was deleted. Delete it with: ${confirm}`,
|
|
483
|
+
text: `Secret ${name} is set${changedNote(current.changed_at)}.\n${gate.where}\n${gate.mismatch ? `${gate.mismatch}\n` : ""}Nothing was deleted. Delete it with: ${confirm}`,
|
|
403
484
|
...(gate.exitCode ? { exitCode: gate.exitCode } : {}),
|
|
404
485
|
};
|
|
405
486
|
}
|
|
@@ -409,7 +490,7 @@ export const secretsDelete = {
|
|
|
409
490
|
catch (error) {
|
|
410
491
|
if (notFound(error))
|
|
411
492
|
return nothing;
|
|
412
|
-
throw refusedForRole(error, "delete", name);
|
|
493
|
+
throw refusedForRole(error, "delete", name, inAdmin);
|
|
413
494
|
}
|
|
414
495
|
return {
|
|
415
496
|
data: { ...current, status: "not_set", deleted: true },
|
package/dist/commands/work.js
CHANGED
|
@@ -3,7 +3,7 @@ import { createReadStream, promises as fs } from "node:fs";
|
|
|
3
3
|
import path from "node:path";
|
|
4
4
|
import { boolOption, CURSOR_OPTION, intOption, LIMIT_OPTION, listOption, pageOf, positional, stringOption, } from "../command.js";
|
|
5
5
|
import { capacityCodeIn, capacityHint, noteLines, runCapacityNote } from "../capacity.js";
|
|
6
|
-
import { assertionCount, assertionLine, retrievalRows, retrievalView, spanAttributes, stepAssertions, suggestedSpan } from "../trace-view.js";
|
|
6
|
+
import { assertionCount, assertionLine, queryErrorCode, retrievalRows, retrievalView, spanAttributes, stepAssertions, suggestedSpan } from "../trace-view.js";
|
|
7
7
|
import { CavelonError, ExitCode, usageError } from "../errors.js";
|
|
8
8
|
import { confirmation } from "../confirm-token.js";
|
|
9
9
|
import { confinedPath } from "../paths.js";
|
|
@@ -412,6 +412,7 @@ export const kbUpload = {
|
|
|
412
412
|
"instance publishes its documents' file hashes.",
|
|
413
413
|
readOnly: false,
|
|
414
414
|
mcpTool: "kb_upload",
|
|
415
|
+
operations: ["POST /api/v1/knowledge-bases/{kb_id}/documents/upload"],
|
|
415
416
|
positionals: [{ name: "dir", description: "Folder (or single file) to upload.", required: true }],
|
|
416
417
|
options: {
|
|
417
418
|
kb: { type: "string", value: "<kb>", description: "Knowledge base name or id (required)." },
|
|
@@ -500,7 +501,7 @@ export const kbUpload = {
|
|
|
500
501
|
text: [
|
|
501
502
|
`--replace uploads ${fileCount(rel.length)} and then deactivates ${deactivations.length} document${deactivations.length === 1 ? "" : "s"} the instance's upload does not replace itself:`,
|
|
502
503
|
...matches.map(plannedLine),
|
|
503
|
-
...(gate.mismatch ? [gate.mismatch] : []),
|
|
504
|
+
gate.where, ...(gate.mismatch ? [gate.mismatch] : []),
|
|
504
505
|
`Nothing was sent. Upload and deactivate with: ${confirm}`,
|
|
505
506
|
].join("\n"),
|
|
506
507
|
...(gate.exitCode ? { exitCode: gate.exitCode } : {}),
|
|
@@ -654,6 +655,7 @@ export const testRun = {
|
|
|
654
655
|
"5 when answers wait for a manual verdict or a value a case needs.",
|
|
655
656
|
readOnly: false,
|
|
656
657
|
mcpTool: "test_run",
|
|
658
|
+
operations: ["POST /api/v1/test-suites/{suite_id}/runs"],
|
|
657
659
|
options: {
|
|
658
660
|
suite: { type: "string", multiple: true, value: "<suite>", description: "Suite name or id." },
|
|
659
661
|
harness: { type: "string", value: "<harness>", description: "The solution to run against: its name, slug or id." },
|
|
@@ -802,6 +804,7 @@ function knowledgeOutcomes(spans) {
|
|
|
802
804
|
}
|
|
803
805
|
function summarizeSpan(s, outcomes) {
|
|
804
806
|
const error = s.error_json ? clip(typeof s.error_json === "string" ? s.error_json : JSON.stringify(s.error_json), 200) : null;
|
|
807
|
+
const code = queryErrorCode(s);
|
|
805
808
|
return {
|
|
806
809
|
span_id: s.id,
|
|
807
810
|
seq: s.sequence ?? null,
|
|
@@ -811,6 +814,8 @@ function summarizeSpan(s, outcomes) {
|
|
|
811
814
|
status: s.status ?? null,
|
|
812
815
|
duration_ms: s.duration_ms ?? null,
|
|
813
816
|
knowledge_outcome: outcomeOf(s) ?? outcomes?.get(s.id) ?? null,
|
|
817
|
+
...(s.tool_type ? { tool_type: s.tool_type } : {}),
|
|
818
|
+
...(code ? { error_code: code } : {}),
|
|
814
819
|
error,
|
|
815
820
|
};
|
|
816
821
|
}
|
|
@@ -1047,16 +1052,19 @@ export const trace = {
|
|
|
1047
1052
|
tokens: span.token_usage_json ?? null,
|
|
1048
1053
|
error: span.error_json ?? null,
|
|
1049
1054
|
};
|
|
1050
|
-
|
|
1055
|
+
const code = queryErrorCode(span);
|
|
1056
|
+
const meaning = code ? `\n\nThe query answered the model with ${code}. What it means: ${cavelonCommand("explain", code)}` : "";
|
|
1057
|
+
return { data, text: retrieval ? retrievalText(data, retrieval) : JSON.stringify(data, null, 2) + meaning };
|
|
1051
1058
|
}
|
|
1052
1059
|
const page = pageOf(spans.map((s) => summarizeSpan(s, outcomes)), limit, cursor);
|
|
1053
1060
|
const words = ["trace", id, ...(kind ? ["--kind", kind] : []), "--trace", traceId];
|
|
1054
1061
|
const base = cavelonCommand(...words);
|
|
1055
|
-
const open = suggestedSpan(spans);
|
|
1062
|
+
const open = suggestedSpan(spans.map((s) => (queryErrorCode(s) ? { ...s, status: "error" } : s)));
|
|
1063
|
+
const codes = page.items.some((s) => "error_code" in s);
|
|
1056
1064
|
return {
|
|
1057
1065
|
data: { trace: summarizeTrace(detail), spans: page },
|
|
1058
1066
|
text: `${keyValues(Object.entries(summarizeTrace(detail)))}\n\n` +
|
|
1059
|
-
table(page.items, ["seq", "type", "name", "status", ...(outcomes.size ? ["knowledge_outcome"] : []), "duration_ms", "span_id"]) +
|
|
1067
|
+
table(page.items, ["seq", "type", "name", "status", ...(outcomes.size ? ["knowledge_outcome"] : []), ...(codes ? ["error_code"] : []), "duration_ms", "span_id"]) +
|
|
1060
1068
|
moreHint(page.next_cursor, base) +
|
|
1061
1069
|
(open ? `\n\nOne span in full (${spanPick(open)}), by the span_id in its row: ${cavelonCommand(...words, "--span", open.id)}` : ""),
|
|
1062
1070
|
};
|