@cavelon/cli 0.1.9 → 0.1.11
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 +23 -10
- package/dist/access.js +194 -0
- package/dist/acting.js +123 -0
- package/dist/agent-env.js +20 -2
- 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 +40 -21
- package/dist/commands/async.js +7 -4
- package/dist/commands/chat.js +18 -15
- package/dist/commands/db.js +367 -0
- package/dist/commands/docs.js +87 -9
- package/dist/commands/fmt.js +6 -4
- package/dist/commands/index.js +8 -0
- package/dist/commands/init.js +106 -28
- package/dist/commands/limits-set.js +12 -11
- package/dist/commands/limits.js +4 -3
- package/dist/commands/loops.js +75 -19
- package/dist/commands/models.js +12 -13
- package/dist/commands/sandboxes.js +22 -16
- package/dist/commands/schema.js +6 -5
- package/dist/commands/session.js +134 -37
- package/dist/commands/setup.js +4 -2
- package/dist/commands/solution.js +289 -93
- package/dist/commands/tenants.js +58 -22
- package/dist/commands/values.js +110 -45
- package/dist/commands/work.js +31 -17
- package/dist/confirm-token.js +15 -5
- package/dist/context.js +3 -1
- package/dist/contracts.js +39 -13
- package/dist/database-queries.js +301 -0
- package/dist/default-route.js +1 -1
- package/dist/features.js +2 -1
- package/dist/fsutil.js +14 -0
- package/dist/harness-ref.js +6 -4
- package/dist/http.js +39 -4
- package/dist/invoke.js +7 -2
- package/dist/kit-codes.js +14 -2
- package/dist/limits.js +1 -1
- package/dist/main.js +13 -1
- package/dist/mcp.js +105 -26
- package/dist/openapi.js +5 -2
- package/dist/operations.js +3 -2
- package/dist/package-check.js +29 -4
- package/dist/package-files.js +5 -1
- package/dist/package-format.js +10 -0
- package/dist/preview-report.js +46 -7
- package/dist/principal.js +24 -2
- package/dist/printed.js +182 -0
- package/dist/project.js +2 -1
- package/dist/results.js +1 -1
- package/dist/secret-access.js +42 -0
- package/dist/session.js +39 -19
- package/dist/shell.js +0 -3
- package/dist/skills/cavelon-authoring/SKILL.md +88 -4
- package/dist/skills/cavelon-long-running/SKILL.md +9 -3
- package/dist/skills/cavelon-loop/SKILL.md +81 -19
- package/dist/skills/cavelon-testing/SKILL.md +28 -1
- package/dist/tenant-choice.js +7 -7
- package/dist/trace-view.js +11 -1
- package/dist/update-check.js +2 -2
- package/dist/user-config.js +24 -0
- package/package.json +1 -1
package/dist/mcp.js
CHANGED
|
@@ -1,10 +1,12 @@
|
|
|
1
1
|
import { Server } from "@modelcontextprotocol/sdk/server/index.js";
|
|
2
2
|
import { CallToolRequestSchema, ListToolsRequestSchema } from "@modelcontextprotocol/sdk/types.js";
|
|
3
|
-
import {
|
|
3
|
+
import { accessFor, allOf, credentialWords, operationAccess, whoInstead } from "./access.js";
|
|
4
|
+
import { formerlyWarning, ownsTenant, propertyName } from "./command.js";
|
|
4
5
|
import { MCP_MAX_WAIT_MS } from "./commands/async.js";
|
|
5
6
|
import { createContext, withWarnings } from "./context.js";
|
|
6
7
|
import { asCavelonError, CavelonError, ExitCode, usageError } from "./errors.js";
|
|
7
8
|
import { closest } from "./package-references.js";
|
|
9
|
+
import { printingFor, spoken, spokenError, spokenHints } from "./printed.js";
|
|
8
10
|
import { startSessionUpdateCheck } from "./update-check.js";
|
|
9
11
|
import { KIT_VERSION } from "./version.js";
|
|
10
12
|
const INSTRUCTIONS = "Tools for one Cavelon instance, acting with the token a person stored with `cavelon login` " +
|
|
@@ -12,7 +14,8 @@ const INSTRUCTIONS = "Tools for one Cavelon instance, acting with the token a pe
|
|
|
12
14
|
"loop_start, sandbox_seed, artifacts_export) return operation ids at once; read them with operation_status, which returns " +
|
|
13
15
|
`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, ` +
|
|
14
16
|
"and follow a loop with loop_iterations. What needs confirmation: apply imports only with confirm set to a preview's id; " +
|
|
15
|
-
"
|
|
17
|
+
"tenant_create, variables_set where it replaces another value, loop_start, limits_set, models_set_limit, loop_cancel, sandbox_seed, " +
|
|
18
|
+
"trigger_identity, harness_default, activate of a solution a channel or trigger reaches or with make_default, deactivate, " +
|
|
16
19
|
"and api for an operation that is not read-only, " +
|
|
17
20
|
"return what they would do and a confirm_token, and change nothing until called again with the same arguments and " +
|
|
18
21
|
"confirm set to that token: show the person the preview first. The token confirms exactly the change the preview showed; " +
|
|
@@ -20,7 +23,9 @@ const INSTRUCTIONS = "Tools for one Cavelon instance, acting with the token a pe
|
|
|
20
23
|
"(harness_default, activate's make_default) decides which solution the tenant's chat and widget answer with: live traffic, " +
|
|
21
24
|
"so ask the person, and confirm only with their yes; the same goes for deactivate, which takes a solution out of live traffic " +
|
|
22
25
|
"(its status becomes inactive), and for apply with include_tenant_wide, which imports the tenant-wide sections (tenant_settings, " +
|
|
23
|
-
"model_registry, …) for every solution of the tenant. " +
|
|
26
|
+
"model_registry, …) for every solution of the tenant. A new tenant, a replaced variable (every solution of the tenant reads it) and " +
|
|
27
|
+
"the activation of a solution a channel or trigger reaches are the person's to confirm too; confirm a loop_start on your own " +
|
|
28
|
+
"only for a trigger of a draft solution in a test environment (a run acts as the person and spends budget). " +
|
|
24
29
|
"chat sends one message to a solution and returns its answer: the way to try one that is not the default route. " +
|
|
25
30
|
"kb_upload names files that match an active document of the knowledge base; with replace it replaces them, and where the " +
|
|
26
31
|
"instance's upload cannot, it returns what it would deactivate and uploads nothing without its confirm_token. " +
|
|
@@ -30,62 +35,101 @@ const INSTRUCTIONS = "Tools for one Cavelon instance, acting with the token a pe
|
|
|
30
35
|
"(x-cavelon-person-only; its reason is in the error), or on an instance that marks none, one that changes a secret, " +
|
|
31
36
|
"creates or revokes a credential (tokens, API keys, sign-in) or decides an approval; it also refuses a body that sets a field " +
|
|
32
37
|
"the instance marks as a secret value (x-cavelon-secret): leave the field out and let a person enter the value. " +
|
|
33
|
-
"
|
|
38
|
+
"A tool whose description starts with \"Not for this credential\" is one the instance says this token or key may not use " +
|
|
39
|
+
"in this tenant (whoami lists its permissions, an API key's scopes and the operations a person runs): do not call it to " +
|
|
40
|
+
"find out; tell the person who does it. api_list marks such operations (may_send false) and leaves them out with usable. " +
|
|
41
|
+
"Run from your shell, cavelon's api command applies the same guards, and sends a changing operation only with --confirm and the token " +
|
|
34
42
|
"its preview printed. Tools read and write files only " +
|
|
35
43
|
"inside the solution folder (the folder of cavelon.yaml, or the one the server started in), never in cavelon's own " +
|
|
36
44
|
"config or cache directory. Read limits before planning a solution: it lists what the " +
|
|
37
45
|
"instance allows this tenant (upload sizes and types, run and tool limits, timeouts, quotas) and who changes each. " +
|
|
38
46
|
"Never change a limit on your own: propose the old and new value (limits_set for a limit a tenant admin changes, " +
|
|
39
47
|
"models_set_limit for an endpoint's max_concurrent_requests) and let the person decide; an operator's limit goes to the operator. " +
|
|
40
|
-
"
|
|
48
|
+
"db_connections, db_queries and db_runs read the database connections, saved queries and their runs behind database query " +
|
|
49
|
+
"tools; only a superadmin in the Admin creates or changes a connection or a query, so an apply that changes a query is " +
|
|
50
|
+
"blocked for any token: tell the person, and apply the rest with the query left as the instance holds it. " +
|
|
51
|
+
"variables_list/variables_get/variables_set handle plain-text {{var:…}} values; setting one needs a role that may manage " +
|
|
52
|
+
"the tenant's settings, as a secret does (a Builder's may not): where whoami says the credential may not, tell the person " +
|
|
53
|
+
"who sets it instead of calling variables_set. secrets_list shows which {{secret:…}} " +
|
|
41
54
|
"values are set, never a value: a person sets a secret, so tell them the exact `cavelon secrets set <name>` command " +
|
|
42
55
|
"to run in their terminal, and never ask for, read or pass a secret value. Never approve or decide an approval; " +
|
|
43
56
|
"that stays with a person. Use docs_search before guessing, " +
|
|
44
57
|
"and api_list/api_describe/api for anything without its own tool. " +
|
|
58
|
+
"use_tenant chooses the tenant for this MCP session only and never changes the tenant stored for the person; every preview " +
|
|
59
|
+
"names the instance, the tenant and the mode it acts on (its target): show that to the person with the change. " +
|
|
45
60
|
"The first result of a session may carry a warning that cavelon, the Cavelon plugin or this folder's skills are behind " +
|
|
46
61
|
"the latest release, with the commands that update them: pass it on to the person, who runs them; do not run them yourself.";
|
|
62
|
+
export function mcpInstructions(commands) {
|
|
63
|
+
return printingFor({ mode: "mcp", commands }, () => spoken(INSTRUCTIONS));
|
|
64
|
+
}
|
|
65
|
+
const TOOL_LIST_ACCESS_MS = 5_000;
|
|
66
|
+
const TENANT_CHOOSERS = new Set(["use_tenant", "tenant_create"]);
|
|
47
67
|
const TOKEN_DESCRIPTION = "Over MCP: the confirm_token this tool's preview returned, which confirms exactly the change it showed; true is refused.";
|
|
48
68
|
export function toolName(spec) {
|
|
49
69
|
return spec.mcpTool || undefined;
|
|
50
70
|
}
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
|
|
71
|
+
export { propertyName };
|
|
72
|
+
export function mcpSpelling(text, spec, commands = []) {
|
|
73
|
+
const own = new Set(Object.entries(spec.options ?? {}).filter(([, o]) => !o.cliOnly).map(([name]) => name));
|
|
74
|
+
if (!ownsTenant(spec))
|
|
75
|
+
own.add("tenant");
|
|
76
|
+
return text
|
|
77
|
+
.replace(/`cavelon ([a-z][a-z -]*[a-z])`/g, (whole, words) => {
|
|
78
|
+
const tool = commands.find((c) => c.name === words)?.mcpTool;
|
|
79
|
+
return tool ? `\`${tool}\`` : whole;
|
|
80
|
+
})
|
|
81
|
+
.replace(/--([a-z][a-z0-9-]*)/g, (whole, name) => (own.has(name) ? propertyName(name) : whole));
|
|
56
82
|
}
|
|
57
|
-
export function inputSchema(spec) {
|
|
83
|
+
export function inputSchema(spec, commands = []) {
|
|
58
84
|
const properties = {};
|
|
59
85
|
const required = [];
|
|
86
|
+
const said = (text) => mcpSpelling(text, spec, commands);
|
|
60
87
|
for (const p of spec.positionals ?? []) {
|
|
61
88
|
properties[propertyName(p.name)] = p.variadic
|
|
62
|
-
? { type: "array", items: { type: "string" }, description: p.description }
|
|
63
|
-
: { type: "string", description: p.description };
|
|
89
|
+
? { type: "array", items: { type: "string" }, description: said(p.description) }
|
|
90
|
+
: { type: "string", description: said(p.description) };
|
|
64
91
|
if (p.required)
|
|
65
92
|
required.push(propertyName(p.name));
|
|
66
93
|
}
|
|
67
94
|
for (const [name, option] of Object.entries(spec.options ?? {})) {
|
|
68
95
|
if (option.cliOnly)
|
|
69
96
|
continue;
|
|
97
|
+
const description = said(option.mcpDescription ?? option.description);
|
|
70
98
|
properties[propertyName(name)] = option.mcpToken
|
|
71
|
-
? { type: "string", description: `${
|
|
99
|
+
? { type: "string", description: `${description} ${TOKEN_DESCRIPTION}` }
|
|
72
100
|
: option.type === "boolean"
|
|
73
|
-
? { type: "boolean", description
|
|
101
|
+
? { type: "boolean", description }
|
|
74
102
|
: option.multiple
|
|
75
|
-
? { type: "array", items: { type: "string" }, description
|
|
76
|
-
: { type: ["string", "number"], description
|
|
103
|
+
? { type: "array", items: { type: "string" }, description }
|
|
104
|
+
: { type: ["string", "number"], description };
|
|
77
105
|
}
|
|
78
106
|
if (!ownsTenant(spec)) {
|
|
79
|
-
properties.tenant = {
|
|
107
|
+
properties.tenant = {
|
|
108
|
+
type: "string",
|
|
109
|
+
description: "Tenant slug or id, when not the one chosen for this directory or with use_tenant in this session. A preview names the tenant it acts on.",
|
|
110
|
+
};
|
|
80
111
|
}
|
|
81
112
|
return { type: "object", properties, ...(required.length ? { required } : {}), additionalProperties: false };
|
|
82
113
|
}
|
|
83
|
-
export function
|
|
114
|
+
export function notForThisCredential(spec, access) {
|
|
115
|
+
if (!access)
|
|
116
|
+
return undefined;
|
|
117
|
+
for (const operation of spec.operations ?? []) {
|
|
118
|
+
const refused = operationAccess(access, operation);
|
|
119
|
+
if (refused.allowed !== false)
|
|
120
|
+
continue;
|
|
121
|
+
const why = refused.person ? "a person runs it" : `it needs ${allOf(refused.missing)}, which it does not hold`;
|
|
122
|
+
return `Not for this credential: ${credentialWords(access)} may not send ${operation} (${why}). ${whoInstead(access, refused)} Do not call it to find out; tell the person.`;
|
|
123
|
+
}
|
|
124
|
+
return undefined;
|
|
125
|
+
}
|
|
126
|
+
export function toolFor(spec, commands = [], access) {
|
|
84
127
|
const marked = spec.mcpEffect ?? (spec.readOnly ? "Read-only." : spec.destructive ? "Changes the instance; may delete or overwrite." : "Changes the instance.");
|
|
128
|
+
const refused = notForThisCredential(spec, access);
|
|
85
129
|
return {
|
|
86
130
|
name: toolName(spec),
|
|
87
|
-
description: [spec.summary, spec.description, marked].filter(Boolean).join("\n"),
|
|
88
|
-
inputSchema: inputSchema(spec),
|
|
131
|
+
description: mcpSpelling([refused, spec.summary, spec.description, marked].filter(Boolean).join("\n"), spec, commands),
|
|
132
|
+
inputSchema: inputSchema(spec, commands),
|
|
89
133
|
annotations: {
|
|
90
134
|
title: spec.summary,
|
|
91
135
|
readOnlyHint: spec.readOnly,
|
|
@@ -161,9 +205,33 @@ function mcpIo(io) {
|
|
|
161
205
|
export function createMcpServer(io, commands, updates = {}) {
|
|
162
206
|
const tools = commands.filter((c) => c.mcpTool);
|
|
163
207
|
const byName = new Map(tools.map((c) => [toolName(c), c]));
|
|
164
|
-
const server = new Server({ name: "cavelon", version: KIT_VERSION }, { capabilities: { tools: {} }, instructions:
|
|
208
|
+
const server = new Server({ name: "cavelon", version: KIT_VERSION }, { capabilities: { tools: { listChanged: true } }, instructions: mcpInstructions(commands) });
|
|
165
209
|
const notice = startSessionUpdateCheck(io, updates);
|
|
166
|
-
|
|
210
|
+
const sessionTenants = new Map();
|
|
211
|
+
async function credentialAccess() {
|
|
212
|
+
const read = (async () => {
|
|
213
|
+
const ctx = createContext(mcpIo(io), { json: true, sessionTenants }, "mcp");
|
|
214
|
+
const session = await ctx.session();
|
|
215
|
+
if (!session.url || !session.token)
|
|
216
|
+
return undefined;
|
|
217
|
+
return accessFor(await ctx.client());
|
|
218
|
+
})().catch(() => undefined);
|
|
219
|
+
let timer;
|
|
220
|
+
const late = new Promise((resolve) => {
|
|
221
|
+
timer = setTimeout(() => resolve(undefined), TOOL_LIST_ACCESS_MS);
|
|
222
|
+
timer.unref?.();
|
|
223
|
+
});
|
|
224
|
+
try {
|
|
225
|
+
return await Promise.race([read, late]);
|
|
226
|
+
}
|
|
227
|
+
finally {
|
|
228
|
+
clearTimeout(timer);
|
|
229
|
+
}
|
|
230
|
+
}
|
|
231
|
+
server.setRequestHandler(ListToolsRequestSchema, async () => {
|
|
232
|
+
const access = await credentialAccess();
|
|
233
|
+
return { tools: tools.map((t) => toolFor(t, commands, access)) };
|
|
234
|
+
});
|
|
167
235
|
async function call(name, given) {
|
|
168
236
|
const spec = byName.get(name);
|
|
169
237
|
const fail = (error) => ({ isError: true, body: { error: asCavelonError(error).toJSON() } });
|
|
@@ -183,14 +251,23 @@ export function createMcpServer(io, commands, updates = {}) {
|
|
|
183
251
|
}
|
|
184
252
|
const tenant = !ownsTenant(spec) && typeof args.tenant === "string" ? args.tenant : undefined;
|
|
185
253
|
const solutionEnv = spec.options?.env && typeof args.env === "string" ? args.env : undefined;
|
|
186
|
-
const ctx = createContext(mcpIo(io), { json: true, tenant, solutionEnv }, "mcp");
|
|
254
|
+
const ctx = createContext(mcpIo(io), { json: true, tenant, solutionEnv, sessionTenants }, "mcp");
|
|
187
255
|
for (const message of renamed)
|
|
188
256
|
ctx.warn(message);
|
|
189
257
|
try {
|
|
190
|
-
const
|
|
258
|
+
const chosen = tenant ?? (await ctx.session().then((s) => (s.tenantSource === "session" ? s.tenant : undefined), () => undefined));
|
|
259
|
+
const { result, warnings } = await printingFor({ mode: "mcp", commands, ...(spec.storesTarget ? {} : { tenant: chosen, env: solutionEnv }) }, async () => {
|
|
260
|
+
try {
|
|
261
|
+
const done = await spec.run(ctx, inputFrom(spec, args));
|
|
262
|
+
return { result: { ...done, data: spokenHints(done.data) }, warnings: ctx.warnings.map(spoken) };
|
|
263
|
+
}
|
|
264
|
+
catch (error) {
|
|
265
|
+
throw spokenError(error);
|
|
266
|
+
}
|
|
267
|
+
});
|
|
191
268
|
let data = result.data;
|
|
192
269
|
if (data && typeof data === "object" && !Array.isArray(data)) {
|
|
193
|
-
data =
|
|
270
|
+
data = warnings.length ? withWarnings(data, warnings) : { ...data };
|
|
194
271
|
if (result.exitCode)
|
|
195
272
|
data.exit_code = result.exitCode;
|
|
196
273
|
}
|
|
@@ -203,6 +280,8 @@ export function createMcpServer(io, commands, updates = {}) {
|
|
|
203
280
|
server.setRequestHandler(CallToolRequestSchema, async (request) => {
|
|
204
281
|
const warning = notice.forCall(() => server.getClientVersion()?.name);
|
|
205
282
|
const { body, isError } = await call(request.params.name, (request.params.arguments ?? {}));
|
|
283
|
+
if (!isError && TENANT_CHOOSERS.has(request.params.name))
|
|
284
|
+
void server.sendToolListChanged().catch(() => undefined);
|
|
206
285
|
let out = body;
|
|
207
286
|
const text = await warning;
|
|
208
287
|
if (text) {
|
package/dist/openapi.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { Ajv2020 } from "ajv/dist/2020.js";
|
|
2
2
|
import addFormatsModule from "ajv-formats";
|
|
3
3
|
import { CavelonError, ExitCode, validationError } from "./errors.js";
|
|
4
|
+
import { cavelonCommand, fill } from "./printed.js";
|
|
4
5
|
const METHODS = ["get", "put", "post", "delete", "patch", "head", "options"];
|
|
5
6
|
export function aliasOf(operationId, path, method) {
|
|
6
7
|
const suffix = `${path.replace(/\W/g, "_")}_${method.toLowerCase()}`;
|
|
@@ -97,7 +98,9 @@ export function findOperation(doc, name) {
|
|
|
97
98
|
throw new CavelonError(ExitCode.usage, {
|
|
98
99
|
code: "operation_not_found",
|
|
99
100
|
message: `This instance publishes no operation "${name}".`,
|
|
100
|
-
hint: similar.length
|
|
101
|
+
hint: similar.length
|
|
102
|
+
? `Did you mean: ${similar.join(", ")}? (\`${cavelonCommand("api", "list", "--search", fill("text"))}\`)`
|
|
103
|
+
: `Find it with \`${cavelonCommand("api", "list", "--search", fill("text"))}\`.`,
|
|
101
104
|
});
|
|
102
105
|
}
|
|
103
106
|
function looseName(name) {
|
|
@@ -187,7 +190,7 @@ export function validateBody(doc, op, body) {
|
|
|
187
190
|
return;
|
|
188
191
|
const errors = schemaErrors(doc, schema, body);
|
|
189
192
|
if (errors.length) {
|
|
190
|
-
throw validationError(`The body does not match ${op.alias}'s schema: ${errors.join("; ")}`, errors, `See
|
|
193
|
+
throw validationError(`The body does not match ${op.alias}'s schema: ${errors.join("; ")}`, errors, `See \`${cavelonCommand("api", "describe", op.alias)}\`.`);
|
|
191
194
|
}
|
|
192
195
|
}
|
|
193
196
|
export function secretFields(doc, schema, body) {
|
package/dist/operations.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { CavelonError, ExitCode } from "./errors.js";
|
|
2
|
+
import { cavelonCommand } from "./printed.js";
|
|
2
3
|
import { failureLines } from "./results.js";
|
|
3
4
|
export const TERMINAL = new Set(["succeeded", "failed", "cancelled"]);
|
|
4
5
|
export function isSettled(op) {
|
|
@@ -44,7 +45,7 @@ export async function getOperation(client, id, signal) {
|
|
|
44
45
|
throw new CavelonError(ExitCode.usage, {
|
|
45
46
|
code: "not_an_operation_id",
|
|
46
47
|
message: `"${id}" is not an operation id (they start with op_).`,
|
|
47
|
-
hint:
|
|
48
|
+
hint: `Commands that start work print the operation id; \`${cavelonCommand("status")}\` lists running ones.`,
|
|
48
49
|
});
|
|
49
50
|
}
|
|
50
51
|
const probe = await client.get("/api/v1/operations", { query: { limit: 1 }, allow: [404] });
|
|
@@ -54,7 +55,7 @@ export async function getOperation(client, id, signal) {
|
|
|
54
55
|
code: "operation_not_found",
|
|
55
56
|
status: 404,
|
|
56
57
|
message: `No operation ${id} in this tenant.`,
|
|
57
|
-
hint:
|
|
58
|
+
hint: `Operation ids are per tenant; check \`${cavelonCommand("whoami")}\`.`,
|
|
58
59
|
});
|
|
59
60
|
}
|
|
60
61
|
throw error;
|
package/dist/package-check.js
CHANGED
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
import { Ajv2020 } from "ajv/dist/2020.js";
|
|
2
2
|
import { BRANCH_WIDTH_KEY, branchConcurrency, offText } from "./branches.js";
|
|
3
|
+
import { checkQueryTools, QUERY_CHANGED_CODE, QUERY_FIELDS_IGNORED_CODE } from "./database-queries.js";
|
|
3
4
|
import { locate, schemaSections, tenantWideSections } from "./package-files.js";
|
|
4
|
-
import { PERSONA_SECTION, sectionFields } from "./package-format.js";
|
|
5
|
+
import { MANIFEST_SECTION, PERSONA_SECTION, sectionFields } from "./package-format.js";
|
|
5
6
|
import { kitErrorEntry } from "./kit-codes.js";
|
|
7
|
+
import { cavelonCommand, fill, folderCommand } from "./printed.js";
|
|
6
8
|
import { branches, checkModels, checkReferences, checkUnknownFields, closest, DUPLICATE_CODE, FIELD_UNKNOWN_CODE, MODEL_UNKNOWN_CODE, REFERENCE_MISSING_CODE, REFERENCE_UNKNOWN_CODE, KNOWLEDGE_TOOL_KEYS, } from "./package-references.js";
|
|
7
9
|
export const SCHEMA_CODE = "package_schema_invalid";
|
|
8
10
|
const ENDPOINT_LIMIT_CODE = "model_endpoint_limit_without_base_url";
|
|
@@ -28,6 +30,7 @@ const SOLUTION_MISMATCH_CODE = "solution_slug_mismatch";
|
|
|
28
30
|
const TENANT_WIDE_CODE = "tenant_wide_section";
|
|
29
31
|
const ASSERTION_UNCHECKED_CODE = "test_assertion_unchecked";
|
|
30
32
|
const TESTING_DOCS = "/docs/concepts/regression-testing";
|
|
33
|
+
const DATABASE_DOCS = "/docs/administration/database-connectors";
|
|
31
34
|
export const KIT_CODES = [
|
|
32
35
|
{
|
|
33
36
|
code: SCHEMA_CODE,
|
|
@@ -157,6 +160,22 @@ export const KIT_CODES = [
|
|
|
157
160
|
"Remove the file unless that is meant. An instance that does not publish include_tenant_wide imports it with every apply.",
|
|
158
161
|
docs: PACKAGE_DOCS,
|
|
159
162
|
},
|
|
163
|
+
{
|
|
164
|
+
code: QUERY_CHANGED_CODE,
|
|
165
|
+
area: "package",
|
|
166
|
+
message: "A database query tool's query (database_query), name or description differs from the last pull or apply, or the tool is new. Only a superadmin in the Admin creates or changes a query; a personal access token's import preview blocks it.",
|
|
167
|
+
hint: "Hand the change to a superadmin, who imports the package in the Admin (`cavelon explain database_query_needs_superadmin` names the step); then apply passes while the queries match. " +
|
|
168
|
+
"To apply the rest first, leave the query as the instance holds it: restore the tool's entry as the last pull wrote it, or remove its database_query block (a query tool without one keeps the instance's query, name and description). " +
|
|
169
|
+
"Rename the tool for one agent with the assignment's config_overrides instead: an override of name, description or max_calls is no query change.",
|
|
170
|
+
docs: DATABASE_DOCS,
|
|
171
|
+
},
|
|
172
|
+
{
|
|
173
|
+
code: QUERY_FIELDS_IGNORED_CODE,
|
|
174
|
+
area: "package",
|
|
175
|
+
message: "A database query tool's params_json_schema or default_config differs from the last pull or apply; the instance derives both from the query and ignores the package's.",
|
|
176
|
+
hint: "Change the query's parameters instead (database_query.parameters), or put the field back as pulled.",
|
|
177
|
+
docs: DATABASE_DOCS,
|
|
178
|
+
},
|
|
160
179
|
{
|
|
161
180
|
code: "package_file_duplicate",
|
|
162
181
|
area: "package",
|
|
@@ -305,7 +324,8 @@ export function checkPackage(disk, options) {
|
|
|
305
324
|
if (seen.has(key))
|
|
306
325
|
continue;
|
|
307
326
|
seen.add(key);
|
|
308
|
-
|
|
327
|
+
const manifest = error.keyword === "required" && pointer === "" && error.params.missingProperty === MANIFEST_SECTION;
|
|
328
|
+
findings.push({ code: SCHEMA_CODE, severity: "error", ...locate(disk, pointer), message, hint: manifest ? manifestHint() : schemaHint(disk.package, pointer) });
|
|
309
329
|
}
|
|
310
330
|
}
|
|
311
331
|
findings.push(...checkEndpointLimits(disk, options.schema));
|
|
@@ -318,6 +338,7 @@ export function checkPackage(disk, options) {
|
|
|
318
338
|
findings.push(...checkUncheckedAssertions(disk, options.schema));
|
|
319
339
|
findings.push(...checkSolutionSlug(disk, options.solution));
|
|
320
340
|
findings.push(...checkTenantWide(disk, options.schema, options.solution));
|
|
341
|
+
findings.push(...checkQueryTools(disk, options.schema, options.queryBaseline));
|
|
321
342
|
noteTenantWide(findings, options.schema, options.solution);
|
|
322
343
|
for (const finding of findings) {
|
|
323
344
|
const entry = findingEntry(options.catalog, finding.code);
|
|
@@ -592,11 +613,15 @@ export function schemaPathOf(pkg, pointer) {
|
|
|
592
613
|
}
|
|
593
614
|
return names.join(".");
|
|
594
615
|
}
|
|
616
|
+
function manifestHint() {
|
|
617
|
+
return (`\`${folderCommand("pull")}\` writes the instance's manifest (the package format and the tenant the package is for); for a solution not on the instance ` +
|
|
618
|
+
`yet, run \`${folderCommand("init")}\` again in this folder: it writes a minimal one.`);
|
|
619
|
+
}
|
|
595
620
|
function schemaHint(pkg, pointer) {
|
|
596
621
|
const at = schemaPathOf(pkg, pointer);
|
|
597
622
|
return at
|
|
598
|
-
? `Fix the field the finding names;
|
|
599
|
-
:
|
|
623
|
+
? `Fix the field the finding names; \`${cavelonCommand("schema", at)}\` lists the fields there (type, required, allowed values) with a minimal entry.`
|
|
624
|
+
: `Fix the field the finding names; \`${cavelonCommand("schema")}\` lists the sections, and \`${cavelonCommand("schema", fill("section"))}\` their fields.`;
|
|
600
625
|
}
|
|
601
626
|
const propertiesIn = (node) => asObject(node.properties);
|
|
602
627
|
function listedValues(schema, node) {
|
package/dist/package-files.js
CHANGED
|
@@ -3,7 +3,7 @@ import path from "node:path";
|
|
|
3
3
|
import { CST, LineCounter, Parser, parseDocument } from "yaml";
|
|
4
4
|
import { CavelonError, ExitCode } from "./errors.js";
|
|
5
5
|
import { readTextFile, withoutBom, writeFileAtomic } from "./fsutil.js";
|
|
6
|
-
import { canonical, PERSONA_SECTION, sameEntry, sameSectionValue, sectionContent, sectionFields, toYaml } from "./package-format.js";
|
|
6
|
+
import { canonical, MANIFEST_SECTION, PERSONA_SECTION, sameEntry, sameSectionValue, sectionContent, sectionFields, toYaml } from "./package-format.js";
|
|
7
7
|
export { canonical, toYaml };
|
|
8
8
|
export const DEFAULT_LAYOUT = { package: "package", items: {} };
|
|
9
9
|
const PACKAGE_FILE = /\.(ya?ml|json)$/i;
|
|
@@ -183,6 +183,10 @@ export async function readPackage(root, layout) {
|
|
|
183
183
|
sources[section] = parsed.source;
|
|
184
184
|
if (!parsed.finding && section === PERSONA_SECTION && (parsed.value === null || parsed.value === undefined))
|
|
185
185
|
continue;
|
|
186
|
+
if (!parsed.finding && section === MANIFEST_SECTION) {
|
|
187
|
+
pkg[section] = parsed.value;
|
|
188
|
+
continue;
|
|
189
|
+
}
|
|
186
190
|
empty = false;
|
|
187
191
|
if (parsed.finding) {
|
|
188
192
|
findings.push(parsed.finding);
|
package/dist/package-format.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { stringify } from "yaml";
|
|
2
2
|
export const PERSONA_SECTION = "persona";
|
|
3
|
+
export const MANIFEST_SECTION = "manifest";
|
|
3
4
|
export function toYaml(value) {
|
|
4
5
|
return stringify(value, { lineWidth: 0, aliasDuplicateObjects: false });
|
|
5
6
|
}
|
|
@@ -59,6 +60,15 @@ export function sectionFields(schema, section) {
|
|
|
59
60
|
return undefined;
|
|
60
61
|
return Object.fromEntries(Object.entries(props).map(([k, v]) => [k, resolve(schema, v) ?? {}]));
|
|
61
62
|
}
|
|
63
|
+
export function requiredFields(schema, section) {
|
|
64
|
+
if (!schema)
|
|
65
|
+
return undefined;
|
|
66
|
+
const node = resolve(schema, schema.properties?.[section]);
|
|
67
|
+
const object = node ? branches(schema, node).find((b) => propertiesOf(b)) : undefined;
|
|
68
|
+
if (!object)
|
|
69
|
+
return undefined;
|
|
70
|
+
return Array.isArray(object.required) ? object.required.filter((k) => typeof k === "string") : [];
|
|
71
|
+
}
|
|
62
72
|
export function canonical(value) {
|
|
63
73
|
return JSON.stringify(value, (_key, v) => {
|
|
64
74
|
if (v && typeof v === "object" && !Array.isArray(v)) {
|
package/dist/preview-report.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { clip } from "./format.js";
|
|
2
2
|
import { locate } from "./package-files.js";
|
|
3
|
-
import { cavelonCommand } from "./
|
|
3
|
+
import { cavelonCommand } from "./printed.js";
|
|
4
4
|
const isObject = (v) => Boolean(v) && typeof v === "object" && !Array.isArray(v);
|
|
5
5
|
const text = (v) => (typeof v === "string" && v.trim() ? v : null);
|
|
6
6
|
const first = (o, keys) => keys.map((k) => o[k]).find((v) => v !== undefined);
|
|
@@ -101,13 +101,40 @@ export function fieldChanges(raw) {
|
|
|
101
101
|
}
|
|
102
102
|
return out;
|
|
103
103
|
}
|
|
104
|
+
function commonPrefix(a, b) {
|
|
105
|
+
let n = 0;
|
|
106
|
+
while (n < a.length && n < b.length && a[n] === b[n])
|
|
107
|
+
n++;
|
|
108
|
+
return n;
|
|
109
|
+
}
|
|
104
110
|
function shown(value) {
|
|
105
111
|
if (value === undefined || value === null)
|
|
106
112
|
return "null";
|
|
107
113
|
return clip(JSON.stringify(value), 80);
|
|
108
114
|
}
|
|
115
|
+
const DIFF_CONTEXT = 30;
|
|
116
|
+
export function shownPair(before, after) {
|
|
117
|
+
if (typeof before !== "string" || typeof after !== "string" || (JSON.stringify(before).length <= 80 && JSON.stringify(after).length <= 80)) {
|
|
118
|
+
return [shown(before), shown(after)];
|
|
119
|
+
}
|
|
120
|
+
const start = commonPrefix(before, after);
|
|
121
|
+
let end = 0;
|
|
122
|
+
while (end < before.length - start && end < after.length - start && before[before.length - 1 - end] === after[after.length - 1 - end])
|
|
123
|
+
end++;
|
|
124
|
+
const from = Math.max(0, start - DIFF_CONTEXT);
|
|
125
|
+
const window = (value) => {
|
|
126
|
+
const to = Math.min(value.length, value.length - end + DIFF_CONTEXT);
|
|
127
|
+
const part = JSON.stringify(value.slice(from, to));
|
|
128
|
+
return `${from > 0 ? "…" : ""}${clip(part, 160)}${to < value.length ? "…" : ""}`;
|
|
129
|
+
};
|
|
130
|
+
return [window(before), window(after)];
|
|
131
|
+
}
|
|
109
132
|
export function changeLines(changes, max = 20) {
|
|
110
|
-
const lines = changes.slice(0, max).map((c) =>
|
|
133
|
+
const lines = changes.slice(0, max).map((c) => {
|
|
134
|
+
const [before, after] = shownPair(c.old, c.new);
|
|
135
|
+
const at = typeof c.old === "string" && typeof c.new === "string" && (before.startsWith("…") || after.startsWith("…")) ? ` (from character ${commonPrefix(c.old, c.new) + 1})` : "";
|
|
136
|
+
return `\n - ${c.object}.${c.field}: ${before} → ${after}${at}`;
|
|
137
|
+
});
|
|
111
138
|
return lines.join("") + (changes.length > max ? `\n … ${changes.length - max} more (--json)` : "");
|
|
112
139
|
}
|
|
113
140
|
function harnessSlugAt(path, pkg, fallback) {
|
|
@@ -116,7 +143,7 @@ function harnessSlugAt(path, pkg, fallback) {
|
|
|
116
143
|
const entry = index !== undefined ? list[Number(index)] : undefined;
|
|
117
144
|
return (isObject(entry) && text(entry.slug)) || fallback;
|
|
118
145
|
}
|
|
119
|
-
export function notApplied(raw, pkg, harness) {
|
|
146
|
+
export function notApplied(raw, pkg, harness, mayActivate = null) {
|
|
120
147
|
if (!Array.isArray(raw))
|
|
121
148
|
return [];
|
|
122
149
|
return raw
|
|
@@ -137,7 +164,7 @@ export function notApplied(raw, pkg, harness) {
|
|
|
137
164
|
if (field === "is_default")
|
|
138
165
|
return { ...n, command: cavelonCommand("harness", "default", slug ?? "<solution>") };
|
|
139
166
|
if (field === "status")
|
|
140
|
-
return { ...n, command: slug ? cavelonCommand("activate", "--harness", slug) : cavelonCommand("activate") };
|
|
167
|
+
return mayActivate === false ? n : { ...n, command: slug ? cavelonCommand("activate", "--harness", slug) : cavelonCommand("activate") };
|
|
141
168
|
return n;
|
|
142
169
|
});
|
|
143
170
|
}
|
|
@@ -150,13 +177,25 @@ export function notAppliedLines(list) {
|
|
|
150
177
|
})
|
|
151
178
|
.join("") + (list.length > 20 ? `\n … ${list.length - 20} more (--json)` : "");
|
|
152
179
|
}
|
|
180
|
+
const names = (raw) => (Array.isArray(raw) ? raw.map(text).filter((s) => s !== null) : undefined);
|
|
153
181
|
export function tenantWideReport(raw) {
|
|
154
182
|
if (!isObject(raw) || !Array.isArray(raw.sections))
|
|
155
183
|
return undefined;
|
|
156
|
-
const sections = raw.sections
|
|
184
|
+
const sections = names(raw.sections);
|
|
157
185
|
const reaches = Array.isArray(raw.reaches_active_solutions) ? raw.reaches_active_solutions : [];
|
|
158
|
-
const
|
|
186
|
+
const solutions = reaches
|
|
159
187
|
.map((h) => (isObject(h) ? (text(h.slug) ?? text(h.harness_slug) ?? text(h.name) ?? text(h.id)) : text(h)))
|
|
160
188
|
.filter((n) => n !== null);
|
|
161
|
-
|
|
189
|
+
const applied = raw.applied === true;
|
|
190
|
+
const said = names(raw.would_import) ?? names(raw.imported);
|
|
191
|
+
const leftOut = names(raw.left_out);
|
|
192
|
+
const imports = said ?? (leftOut ? sections.filter((s) => !leftOut.includes(s)) : applied ? sections : []);
|
|
193
|
+
return {
|
|
194
|
+
sections,
|
|
195
|
+
applied,
|
|
196
|
+
imports,
|
|
197
|
+
left_out: leftOut ?? sections.filter((s) => !imports.includes(s)),
|
|
198
|
+
listed: said !== undefined || leftOut !== undefined,
|
|
199
|
+
reaches_active_solutions: [...new Set(solutions)],
|
|
200
|
+
};
|
|
162
201
|
}
|
package/dist/principal.js
CHANGED
|
@@ -2,8 +2,30 @@ export async function readPrincipal(client, options = {}) {
|
|
|
2
2
|
const response = await client.get("/api/v1/meta/principal", { allow: [400, 403, 404, 405], sendTenant: options.sendTenant });
|
|
3
3
|
if (response.status !== 200 || !response.data?.kind)
|
|
4
4
|
return undefined;
|
|
5
|
-
const { permissions, ...rest } = response.data;
|
|
6
|
-
|
|
5
|
+
const { permissions, needs_a_person: needsAPerson, tenant, ...rest } = response.data;
|
|
6
|
+
const principal = rest;
|
|
7
|
+
if (Array.isArray(permissions))
|
|
8
|
+
principal.permissions = permissions.filter((p) => typeof p === "string");
|
|
9
|
+
if (Array.isArray(needsAPerson))
|
|
10
|
+
principal.needs_a_person = operationsNeedingAPerson(needsAPerson);
|
|
11
|
+
if (tenant === null)
|
|
12
|
+
principal.tenant = null;
|
|
13
|
+
else if (tenant && typeof tenant === "object" && typeof tenant.id === "string") {
|
|
14
|
+
const text = (v) => (typeof v === "string" && v ? v : null);
|
|
15
|
+
principal.tenant = { id: tenant.id, name: text(tenant.name), slug: text(tenant.slug) };
|
|
16
|
+
}
|
|
17
|
+
return principal;
|
|
18
|
+
}
|
|
19
|
+
function operationsNeedingAPerson(value) {
|
|
20
|
+
return value
|
|
21
|
+
.filter((o) => Boolean(o) && typeof o === "object")
|
|
22
|
+
.filter((o) => typeof o.method === "string" && typeof o.path === "string")
|
|
23
|
+
.map((o) => ({
|
|
24
|
+
operation: typeof o.operation === "string" && o.operation ? o.operation : null,
|
|
25
|
+
method: o.method.toUpperCase(),
|
|
26
|
+
path: o.path,
|
|
27
|
+
reason: typeof o.reason === "string" ? o.reason : "",
|
|
28
|
+
}));
|
|
7
29
|
}
|
|
8
30
|
const TENANT_PAGE = 200;
|
|
9
31
|
const MAX_TENANT_PAGES = 5;
|