@cavelon/cli 0.1.12 → 0.1.14

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.
@@ -33,18 +33,24 @@ export function schemaKnowsQueries(schema) {
33
33
  const properties = toolSchema(schema)?.properties;
34
34
  return isObject(properties) && QUERY_FIELD in properties;
35
35
  }
36
- function parameterSchema(schema) {
36
+ export function querySchema(schema) {
37
37
  const field = toolSchema(schema)?.properties?.[QUERY_FIELD];
38
38
  const branches = isObject(field) && Array.isArray(field.anyOf) ? field.anyOf : [field];
39
39
  for (const branch of branches) {
40
40
  const query = resolveRef(schema, branch);
41
- const parameters = query?.properties?.parameters;
42
- const items = isObject(parameters) ? resolveRef(schema, parameters.items) : undefined;
43
- if (items)
44
- return items;
41
+ if (isObject(query?.properties))
42
+ return query;
45
43
  }
46
44
  return undefined;
47
45
  }
46
+ export function parameterSchema(schema) {
47
+ const parameters = querySchema(schema)?.properties?.parameters;
48
+ return isObject(parameters) ? resolveRef(schema, parameters.items) : undefined;
49
+ }
50
+ export function schemaKnowsWrites(schema) {
51
+ const kind = querySchema(schema)?.properties?.kind;
52
+ return Array.isArray(kind?.enum) && kind.enum.includes("write");
53
+ }
48
54
  export function queryTools(pkg) {
49
55
  const tools = pkg[TOOLS_SECTION];
50
56
  if (!Array.isArray(tools))
@@ -140,6 +146,164 @@ export function queryProblems(query, schema) {
140
146
  }
141
147
  return problems;
142
148
  }
149
+ export const PROCEDURE_CALL_FORM = "EXEC [schema].[procedure] @p1 = :p1, @p2 = :p2";
150
+ const PROCEDURE_DIALECT = "mssql";
151
+ const WORD_START = /[A-Za-z_]/;
152
+ const WORD_PART = /[A-Za-z0-9_$]/;
153
+ function closing(sql, start, quote, backslash) {
154
+ for (let i = start + 1; i < sql.length; i++) {
155
+ if (backslash && sql[i] === "\\") {
156
+ i++;
157
+ continue;
158
+ }
159
+ if (sql[i] !== quote)
160
+ continue;
161
+ if (sql[i + 1] === quote) {
162
+ i++;
163
+ continue;
164
+ }
165
+ return i + 1;
166
+ }
167
+ return undefined;
168
+ }
169
+ function sqlTokens(sql, dialect) {
170
+ const tokens = [];
171
+ let i = 0;
172
+ while (i < sql.length) {
173
+ const char = sql[i];
174
+ if (/\s/.test(char)) {
175
+ i++;
176
+ continue;
177
+ }
178
+ let end;
179
+ let kind;
180
+ if (sql.startsWith("--", i)) {
181
+ const newline = sql.indexOf("\n", i);
182
+ end = newline === -1 ? sql.length : newline;
183
+ kind = "comment";
184
+ }
185
+ else if (sql.startsWith("/*", i)) {
186
+ const close = sql.indexOf("*/", i + 2);
187
+ if (close === -1)
188
+ return undefined;
189
+ end = close + 2;
190
+ kind = "comment";
191
+ }
192
+ else if (char === "'") {
193
+ end = closing(sql, i, "'", dialect === "mysql");
194
+ kind = "string";
195
+ }
196
+ else if (char === '"') {
197
+ end = closing(sql, i, '"', dialect === "mysql");
198
+ kind = dialect === "mysql" ? "string" : "identifier";
199
+ }
200
+ else if (char === "`" && dialect === "mysql") {
201
+ end = closing(sql, i, "`", false);
202
+ kind = "identifier";
203
+ }
204
+ else if (char === "[" && dialect === PROCEDURE_DIALECT) {
205
+ end = closing(sql, i, "]", false);
206
+ kind = "identifier";
207
+ }
208
+ else if (WORD_START.test(char)) {
209
+ end = i + 1;
210
+ while (end < sql.length && WORD_PART.test(sql[end]))
211
+ end++;
212
+ kind = "word";
213
+ }
214
+ else {
215
+ end = i + 1;
216
+ kind = char === ";" ? "semicolon" : "symbol";
217
+ }
218
+ if (end === undefined)
219
+ return undefined;
220
+ tokens.push({ kind, text: sql.slice(i, end), start: i });
221
+ i = end;
222
+ }
223
+ return tokens;
224
+ }
225
+ const isWord = (token, ...words) => token?.kind === "word" && words.includes(token.text.toUpperCase());
226
+ const isSymbol = (token, text) => token?.kind === "symbol" && token.text === text;
227
+ const touching = (first, second) => second.start === first.start + first.text.length;
228
+ const DYNAMIC_SQL_PROCEDURES = ["sp_executesql", "sp_sqlexec", "sp_execute", "sp_execute_external_script", "sp_invoke_external_rest_endpoint"];
229
+ const DYNAMIC_SQL_PREFIXES = ["xp_", "sp_prep", "sp_cursor", "sp_oa", "sp_msforeach"];
230
+ function namePart(token) {
231
+ if (token?.kind === "identifier" && token.text.startsWith("[") && token.text.length > 2)
232
+ return token.text.slice(1, -1).replaceAll("]]", "]");
233
+ return token?.kind === "word" ? token.text : undefined;
234
+ }
235
+ function procedureFormProblem(sql, code) {
236
+ const tokens = code[code.length - 1]?.kind === "semicolon" ? code.slice(0, -1) : code;
237
+ if (!isWord(tokens[0], "EXEC", "EXECUTE"))
238
+ return "Nothing may stand before EXEC.";
239
+ if (tokens.length < 2)
240
+ return "EXEC names no procedure.";
241
+ const parts = [];
242
+ let position = 1;
243
+ for (;;) {
244
+ const part = namePart(tokens[position]);
245
+ if (part === undefined)
246
+ return `${tokens[position]?.text ?? "Nothing"} is not a procedure name.`;
247
+ parts.push(part);
248
+ position++;
249
+ if (!isSymbol(tokens[position], "."))
250
+ break;
251
+ if (parts.length === 2)
252
+ return "The procedure is named by at most a schema and its name, not a database or server.";
253
+ position++;
254
+ }
255
+ const procedure = parts[parts.length - 1];
256
+ const lower = procedure.toLowerCase();
257
+ if (DYNAMIC_SQL_PROCEDURES.includes(lower) || DYNAMIC_SQL_PREFIXES.some((prefix) => lower.startsWith(prefix))) {
258
+ return `${procedure} runs SQL text or code outside the database; a query may not call it.`;
259
+ }
260
+ const args = tokens.slice(position);
261
+ for (let index = 0; index < args.length;) {
262
+ const [at, name, equals, colon, bind] = args.slice(index, index + 5);
263
+ const argument = isSymbol(at, "@") && name?.kind === "word" && touching(at, name) && isSymbol(equals, "=") && isSymbol(colon, ":") && bind?.kind === "word" && touching(colon, bind) && !bind.text.includes("$");
264
+ if (!argument) {
265
+ const shown = args.slice(index, index + 5);
266
+ const last = shown[shown.length - 1];
267
+ return `The argument '${sql.slice(shown[0].start, last.start + last.text.length)}' is not written @name = :placeholder.`;
268
+ }
269
+ index += 5;
270
+ if (index === args.length)
271
+ break;
272
+ if (!isSymbol(args[index], ","))
273
+ return `'${args[index].text}' follows an argument, where only a comma and the next argument may stand.`;
274
+ if (index + 1 === args.length)
275
+ return "The arguments end with a comma.";
276
+ index++;
277
+ }
278
+ return undefined;
279
+ }
280
+ export function procedureCallProblem(sql, dialect) {
281
+ if (!dialect)
282
+ return undefined;
283
+ const tokens = sqlTokens(sql, dialect);
284
+ if (!tokens)
285
+ return undefined;
286
+ const code = tokens.filter((t) => t.kind !== "comment");
287
+ const first = code.find((t) => !isSymbol(t, "("));
288
+ if (!isWord(first, "EXEC", "EXECUTE"))
289
+ return undefined;
290
+ if (dialect !== PROCEDURE_DIALECT) {
291
+ return problem("not_select", `the SQL calls a stored procedure (${first.text.toUpperCase()}), which only a query on a SQL Server (${PROCEDURE_DIALECT}) connection may do; ` +
292
+ `on ${dialect} the instance refuses it (not_select). Write the query as a SELECT.`, "sql_text");
293
+ }
294
+ if (code.some((t, i) => t.kind === "semicolon" && i !== code.length - 1))
295
+ return undefined;
296
+ const why = procedureFormProblem(sql, code);
297
+ if (!why)
298
+ return undefined;
299
+ return problem("procedure_call_form", `${why} A stored-procedure query is exactly ${PROCEDURE_CALL_FORM}, every argument a :placeholder (procedure_call_form).`, "sql_text");
300
+ }
301
+ export function isProcedureCall(sql, dialect) {
302
+ if (dialect !== PROCEDURE_DIALECT)
303
+ return false;
304
+ const code = sqlTokens(sql, dialect)?.filter((t) => t.kind !== "comment");
305
+ return isWord(code?.find((t) => !isSymbol(t, "(")), "EXEC", "EXECUTE");
306
+ }
143
307
  function settledTool(schema, tool) {
144
308
  const settled = settledForm(schema, schema.properties?.[TOOLS_SECTION], [tool]);
145
309
  return Array.isArray(settled) && isObject(settled[0]) ? settled[0] : tool;
@@ -193,7 +357,7 @@ export function queryChanges(pkg, schema, baseline) {
193
357
  }
194
358
  return out;
195
359
  }
196
- export function checkQueryTools(disk, schema, baseline) {
360
+ export function checkQueryTools(disk, schema, baseline, connections) {
197
361
  if (!schemaKnowsQueries(schema))
198
362
  return [];
199
363
  const findings = [];
@@ -209,6 +373,25 @@ export function checkQueryTools(disk, schema, baseline) {
209
373
  message: `Query tool "${slug}": ${problem.message}`,
210
374
  });
211
375
  }
376
+ const dialect = isObject(query.connection) && typeof query.connection.dialect === "string" ? query.connection.dialect : undefined;
377
+ const write = schemaKnowsWrites(schema) && query.kind === "write";
378
+ const call = !write && typeof query.sql_text === "string" ? procedureCallProblem(query.sql_text, dialect) : undefined;
379
+ if (call) {
380
+ findings.push({
381
+ code: call.code,
382
+ severity: "warning",
383
+ ...locate(disk, `/${TOOLS_SECTION}/${index}/${QUERY_FIELD}/${call.at}`),
384
+ message: `Query tool "${slug}": ${call.message}`,
385
+ });
386
+ }
387
+ const connection = isObject(query.connection) ? query.connection : undefined;
388
+ if (write && connections?.some(c => c.name === connection?.name && c.dialect === dialect && c.allows_writes === false)) {
389
+ findings.push({
390
+ code: "writes_not_allowed", severity: "warning",
391
+ ...locate(disk, `/${TOOLS_SECTION}/${index}/${QUERY_FIELD}/connection`),
392
+ message: `Write query tool "${slug}" names a connection that explicitly disallows writes: its calls and dry-run tests answer writes_not_allowed. A tenant Owner or Admin enables writes on the connection in the Admin; this flag never travels in a package.`,
393
+ });
394
+ }
212
395
  }
213
396
  if (!baseline)
214
397
  return findings;
@@ -221,8 +404,8 @@ export function checkQueryTools(disk, schema, baseline) {
221
404
  code: QUERY_CHANGED_CODE,
222
405
  severity: "warning",
223
406
  ...locate(disk, `/${TOOLS_SECTION}/${change.index}`),
224
- message: `Query tool "${change.slug}" ${what} needs a superadmin in the Admin, and the import preview of a personal access token ` +
225
- `blocks it (${NEEDS_SUPERADMIN_CODE}). An agent's or skill's override of the tool's name, description or max_calls is no query change.`,
407
+ message: `Query tool "${change.slug}" ${what} needs database_connectors.manage (the tenant Owner or a superadmin in Tenant mode) and the person's approval. ` +
408
+ `The import preview blocks a credential without that permission (${NEEDS_SUPERADMIN_CODE}). An agent's or skill's override of the tool's name, description or max_calls is no query change.`,
226
409
  });
227
410
  }
228
411
  for (const { slug, index, tool } of queryTools(disk.package)) {
@@ -275,7 +458,7 @@ export function applyQueryNotes(pkg, changes, offer) {
275
458
  }
276
459
  }
277
460
  const slugs = changes.map((c) => c.slug);
278
- if (slugs.length && offer.may_write_queries === false) {
461
+ if (slugs.length && offer.enabled !== false && offer.may_write_queries === false) {
279
462
  warnings.push(`This apply would ${changes.every((c) => c.created) ? "create" : "create or change"} the database quer${slugs.length === 1 ? "y" : "ies"} ${named(slugs)}, ` +
280
463
  `which this credential may not do (may_write_queries is false): the preview blocks ${slugs.length === 1 ? "it" : "them"}, and one blocked query stops the whole import. ` +
281
464
  (offer.queries_written_by ? `${offer.queries_written_by} ` : "") +
@@ -295,7 +478,11 @@ export function applyQueryNotes(pkg, changes, offer) {
295
478
  export function queryBlockedHint(files) {
296
479
  const where = files.length ? ` in ${files.join(", ")}` : "";
297
480
  return ("A database query the import would create or change stops the whole import: nothing is applied while one blocks. " +
298
- "A superadmin applies it in the Admin (the blocker's hint names where); after that, apply passes while the queries match. " +
481
+ "The blocker's hint names who this instance permits and where they apply it (with the manage gate, the tenant Owner may use a personal access token holding database_connectors.manage); after that, apply passes while the queries match. " +
299
482
  `To apply the other changes first, leave each blocked query as the instance holds it${where}: restore the tool's entry as the last pull wrote it, ` +
300
483
  "or remove its database_query block (the tool then keeps the instance's query, name and description), and apply again.");
301
484
  }
485
+ export function importWritesQueries(preview) {
486
+ const report = preview.database_queries;
487
+ return isObject(report) && Array.isArray(report.would_write) && report.would_write.length > 0;
488
+ }
package/dist/http.js CHANGED
@@ -30,6 +30,7 @@ export class ApiClient {
30
30
  target;
31
31
  env;
32
32
  tokensOff;
33
+ genericForbiddenHint;
33
34
  revalidateTenant;
34
35
  confirmer;
35
36
  constructor(target, env = {}) {
@@ -172,6 +173,12 @@ export class ApiClient {
172
173
  const kind = this.target.token.startsWith("cbp_") ? "api_key" : this.target.token.startsWith("cvpat_") ? "personal_access_token" : undefined;
173
174
  const access = await accessFor(this).catch(() => undefined);
174
175
  sent = { ...sent, credential: { kind, access, method: sent.method, path: sent.path } };
176
+ if (forbiddenHint("", sent.credential).details.needs_a_person === true) {
177
+ this.genericForbiddenHint ??= this.get("/api/v1/meta/error-catalog", { allow: [400, 401, 403, 404, 405], timeoutMs: 10_000 })
178
+ .then((response) => response.data?.api_error_codes?.find((entry) => entry.code === "forbidden")?.hint ?? undefined)
179
+ .catch(() => undefined);
180
+ sent.genericForbiddenHint = await this.genericForbiddenHint;
181
+ }
175
182
  }
176
183
  return errorFromResponse(status, body, what, headers, sent);
177
184
  }
@@ -340,6 +347,14 @@ export function errorFromResponse(status, body, what, headers, sent = {}) {
340
347
  if (status === 400 && !hint && message && /select a tenant|tenant context|X-Tenant-Id/i.test(message)) {
341
348
  hint = `Choose a tenant with \`${cavelonCommand("use")}\` (it lists your tenants), --tenant or CAVELON_TENANT.`;
342
349
  }
350
+ if (status === 403 && sent.credential) {
351
+ const forbidden = forbiddenHint(message ?? "", sent.credential);
352
+ if (forbidden.details.needs_a_person === true) {
353
+ hint = !hint || hint === sent.genericForbiddenHint || hint === forbidden.hint ? forbidden.hint : `${forbidden.hint} ${hint}`;
354
+ if (details === undefined)
355
+ details = forbidden.details;
356
+ }
357
+ }
343
358
  if ((status === 401 || status === 403) && !hint) {
344
359
  hint =
345
360
  status === 401
package/dist/install.js CHANGED
@@ -79,7 +79,7 @@ function pypiInstall(facts, p, lower) {
79
79
  return { method: "uv-tool", path: file, update: "uv tool upgrade cavelon", source: "github" };
80
80
  if (follows("pipx", "venvs") || under(facts.env.PIPX_HOME))
81
81
  return { method: "pipx", path: file, update: "pipx upgrade cavelon", source: "github" };
82
- if (lower.includes("uv") && lower.some((s) => s.startsWith("archive-v"))) {
82
+ if ((lower.includes("uv") || under(facts.env.UV_CACHE_DIR)) && lower.some((s) => s.startsWith("archive-v"))) {
83
83
  return { method: "uvx", path: file, advice: "uvx reuses the release it cached; `uvx cavelon@latest` runs the newest.", source: "github" };
84
84
  }
85
85
  return { method: "pip", path: file, update: "pip install --upgrade cavelon", source: "github" };
package/dist/kit-codes.js CHANGED
@@ -22,6 +22,7 @@ export const KIT_ERROR_CODES = [
22
22
  { code: "unexpected_redirect", area: "cli", message: "The instance redirected a request elsewhere.", hint: "Check the instance URL (https, host, path)." },
23
23
  { code: "internal_error", area: "cli", message: "cavelon failed in an unexpected way.", hint: "Run the command again; if it repeats, report it with the command and its output." },
24
24
  { code: "operation_unavailable", area: "cli", message: "This instance does not offer what the command needs (the route or a field is not in its OpenAPI).", hint: "The instance may be older than the feature; `cavelon status` shows its version." },
25
+ { code: "chat_user_reader_forbidden", area: "cli", message: "This credential cannot read as a selected Chat User; nothing was sent.", hint: "Chat needs a personal access token; chat and test runs need knowledge_bases.view and end_users.read. `cavelon whoami` shows the acting tenant and credential's permissions. Choose a current reader with `cavelon api list_chat_users -p tenant_id=<tenant_id>`; check email_verified for email-bound queries." },
25
26
  { code: "openapi_unavailable", area: "cli", message: "The instance does not serve its OpenAPI.", hint: "`cavelon api` needs it; ask the instance's operator to route it." },
26
27
  { code: "error_catalog_unavailable", area: "cli", message: "The instance does not publish its error catalog.", hint: "Try `cavelon docs search <code>`." },
27
28
  { code: "docs_unavailable", area: "cli", message: "The instance does not serve its docs to agents (no /llms.txt).", hint: "Read the docs in the Admin until the instance is updated." },
@@ -53,6 +54,7 @@ export const KIT_ERROR_CODES = [
53
54
  { code: "path_outside_solution", area: "cli", message: "A tool reads and writes files only inside the solution folder.", hint: "Name a file inside the solution folder, or ask the person to run the command in their terminal." },
54
55
  { code: "path_in_kit_directory", area: "cli", message: "The file is in cavelon's own directory (login and cache); no tool reads or writes there.", hint: "Name a file in the solution folder." },
55
56
  { code: "skills_missing", area: "cli", message: "This cavelon has no skills to install; its package is incomplete.", hint: "Reinstall @cavelon/cli." },
57
+ { code: "import_needs_a_person", area: "cli", message: "The instance keeps package imports from this credential; nothing was imported.", hint: "A person imports in the Admin or with their own personal access token. The API key can still preview with `cavelon apply`." },
56
58
  { code: "preview_unknown", area: "cli", message: "No open preview with that id in this solution.", hint: "Run `cavelon apply` for a new preview and confirm its id; `cavelon status` lists the open ones." },
57
59
  { code: "preview_other_instance", area: "cli", message: "The preview was made on another instance.", hint: "Confirm it with the instance it was made on, or preview again here." },
58
60
  { code: "preview_other_tenant", area: "cli", message: "The preview was made for another tenant than this command acts in.", hint: "Run the confirm command the preview printed (it names --env and --tenant), or preview again here." },
package/dist/mcp.js CHANGED
@@ -52,9 +52,12 @@ const INSTRUCTIONS = "Tools for one Cavelon instance, acting with the token a pe
52
52
  "instance allows this tenant (upload sizes and types, run and tool limits, timeouts, quotas) and who changes each. " +
53
53
  "Never change a limit on your own: propose the old and new value (limits_set for a limit a tenant admin changes, " +
54
54
  "models_set_limit for an endpoint's max_concurrent_requests) and let the person decide; an operator's limit goes to the operator. " +
55
- "db_connections, db_queries and db_runs read the database connections, saved queries and their runs behind database query " +
56
- "tools; only a superadmin in the Admin creates or changes a connection or a query, so an apply that changes a query is " +
57
- "blocked for any token: tell the person, and apply the rest with the query left as the instance holds it. " +
55
+ "db_connections, db_queries and db_runs read database connections, saved queries and their runs. Connection commands " +
56
+ "and query-writing apply follow the permissions and needs_a_person the instance publishes: use whoami, including " +
57
+ "database_connectors.manage, instead of assuming every token is blocked. An authorized personal access token may " +
58
+ "manage definitions. Query changes need the person's approval even on a draft; after approval cavelon sends the " +
59
+ "instance's confirmation for the exact change where required. Passwords, privilege acknowledgment and enabling writes " +
60
+ "stay with a person in the Admin; never accept or pass the database password or set allows_writes through a tool. " +
58
61
  "variables_list/variables_get/variables_set handle plain-text {{var:…}} values; setting one needs a role that may manage " +
59
62
  "the tenant's settings, as a secret does (a Builder's may not): where whoami says the credential may not, tell the person " +
60
63
  "who sets it instead of calling variables_set. secrets_list shows which {{secret:…}} " +
@@ -134,9 +137,13 @@ export function notForThisCredential(spec, access) {
134
137
  export function toolFor(spec, commands = [], access) {
135
138
  const marked = spec.mcpEffect ?? (spec.readOnly ? "Read-only." : spec.destructive ? "Changes the instance; may delete or overwrite." : "Changes the instance.");
136
139
  const refused = notForThisCredential(spec, access);
140
+ const conditional = (spec.operations ?? []).flatMap(operation => {
141
+ const reason = operationAccess(access, operation).personWhen;
142
+ return reason === undefined ? [] : [`Needs a person only when (${operation}): ${reason}. Ordinary requests remain usable; the instance decides every request.`];
143
+ });
137
144
  return {
138
145
  name: toolName(spec),
139
- description: mcpSpelling([refused, spec.summary, spec.description, marked].filter(Boolean).join("\n"), spec, commands),
146
+ description: mcpSpelling([refused, spec.summary, spec.description, ...conditional, marked].filter(Boolean).join("\n"), spec, commands),
140
147
  inputSchema: inputSchema(spec, commands),
141
148
  annotations: {
142
149
  title: spec.summary,
@@ -4,6 +4,7 @@ import { checkQueryTools, QUERY_CHANGED_CODE, QUERY_FIELDS_IGNORED_CODE } from "
4
4
  import { locate, schemaSections, tenantWideSections } from "./package-files.js";
5
5
  import { MANIFEST_SECTION, PERSONA_SECTION, sectionFields } from "./package-format.js";
6
6
  import { kitErrorEntry } from "./kit-codes.js";
7
+ import { checkWorkflowQueries } from "./workflow-queries.js";
7
8
  import { cavelonCommand, fill, folderCommand } from "./printed.js";
8
9
  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";
9
10
  export const SCHEMA_CODE = "package_schema_invalid";
@@ -163,8 +164,9 @@ export const KIT_CODES = [
163
164
  {
164
165
  code: QUERY_CHANGED_CODE,
165
166
  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. " +
167
+ message: "A database query tool's query (database_query), name or description differs from the last pull or apply, or the tool is new. Creating or changing it needs database_connectors.manage and the person's approval.",
168
+ hint: "Preview with `cavelon apply`: a personal access token holding database_connectors.manage (the tenant Owner or a superadmin in Tenant mode) may import it after the person approves. " +
169
+ "Over MCP the client asks the person; from an agent's shell the person runs the preview's confirm command in their own terminal. A credential without that permission gets database_query_needs_superadmin; its published hint names who this instance permits. " +
168
170
  "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
171
  "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
172
  docs: DATABASE_DOCS,
@@ -338,7 +340,8 @@ export function checkPackage(disk, options) {
338
340
  findings.push(...checkUncheckedAssertions(disk, options.schema));
339
341
  findings.push(...checkSolutionSlug(disk, options.solution));
340
342
  findings.push(...checkTenantWide(disk, options.schema, options.solution));
341
- findings.push(...checkQueryTools(disk, options.schema, options.queryBaseline));
343
+ findings.push(...checkQueryTools(disk, options.schema, options.queryBaseline, options.queryConnections));
344
+ findings.push(...checkWorkflowQueries(disk, options.schema, options.inventory, options.queryBaseline));
342
345
  noteTenantWide(findings, options.schema, options.solution);
343
346
  for (const finding of findings) {
344
347
  const entry = findingEntry(options.catalog, finding.code);
@@ -1,4 +1,5 @@
1
1
  import { locate } from "./package-files.js";
2
+ import { schemaRunsQueryNodes, workflowQueryNodes } from "./workflow-queries.js";
2
3
  export const DUPLICATE_CODE = "package_duplicate_key";
3
4
  export const REFERENCE_MISSING_CODE = "package_reference_missing";
4
5
  export const REFERENCE_UNKNOWN_CODE = "package_reference_unknown";
@@ -282,9 +283,12 @@ const CHECKED_BY = {
282
283
  models: "the agents' models",
283
284
  };
284
285
  export const checkedBy = (kind) => CHECKED_BY[kind];
285
- export function missingInventory(disk, inventory) {
286
+ export function missingInventory(disk, inventory, schema) {
286
287
  const needed = new Set();
287
288
  const pkg = disk.package;
289
+ const ownTools = new Set(keysIn(pkg, TOOL));
290
+ if ((!schema || schemaRunsQueryNodes(schema)) && workflowQueryNodes(pkg).some((node) => !ownTools.has(node.slug)))
291
+ needed.add("tools");
288
292
  for (const ref of references(pkg)) {
289
293
  const kind = ref.target.inventory;
290
294
  if (!kind || keysIn(pkg, ref.target).includes(ref.name) || ref.target.builtin?.has(ref.name))
package/dist/principal.js CHANGED
@@ -2,12 +2,14 @@ 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, needs_a_person: needsAPerson, tenant, ...rest } = response.data;
5
+ const { permissions, needs_a_person: needsAPerson, needs_a_person_when: needsAPersonWhen, tenant, ...rest } = response.data;
6
6
  const principal = rest;
7
7
  if (Array.isArray(permissions))
8
8
  principal.permissions = permissions.filter((p) => typeof p === "string");
9
9
  if (Array.isArray(needsAPerson))
10
10
  principal.needs_a_person = operationsNeedingAPerson(needsAPerson);
11
+ if (Array.isArray(needsAPersonWhen))
12
+ principal.needs_a_person_when = conditionalOperations(needsAPersonWhen);
11
13
  if (tenant === null)
12
14
  principal.tenant = null;
13
15
  else if (tenant && typeof tenant === "object" && typeof tenant.id === "string") {
@@ -16,6 +18,14 @@ export async function readPrincipal(client, options = {}) {
16
18
  }
17
19
  return principal;
18
20
  }
21
+ function conditionalOperations(value) {
22
+ return value
23
+ .filter((o) => Boolean(o) && typeof o === "object" && !Array.isArray(o))
24
+ .filter((o) => typeof o.method === "string" && ["GET", "POST", "PUT", "PATCH", "DELETE", "HEAD", "OPTIONS", "TRACE"].includes(o.method.toUpperCase())
25
+ && typeof o.path === "string" && o.path.startsWith("/") && !/[\s?#]/.test(o.path)
26
+ && (o.operation === null || typeof o.operation === "string") && typeof o.reason === "string")
27
+ .map((o) => ({ operation: o.operation, method: o.method.toUpperCase(), path: o.path, reason: o.reason }));
28
+ }
19
29
  function operationsNeedingAPerson(value) {
20
30
  return value
21
31
  .filter((o) => Boolean(o) && typeof o === "object")
@@ -11,7 +11,7 @@ export function invocation(file, args, env = process.env, platform = process.pla
11
11
  export function runProgram(file, args, options) {
12
12
  const how = invocation(file, args, options.env);
13
13
  return new Promise((resolve) => {
14
- execFile(how.file, how.args, {
14
+ const child = execFile(how.file, how.args, {
15
15
  env: options.env,
16
16
  cwd: options.cwd,
17
17
  timeout: options.timeoutMs,
@@ -29,6 +29,7 @@ export function runProgram(file, args, options) {
29
29
  return resolve({ code: err.code, stdout, stderr });
30
30
  resolve({ code: null, stdout, stderr, error: err.message });
31
31
  });
32
+ child.stdin?.end();
32
33
  });
33
34
  }
34
35
  export function probeMcpServer(command, args, options) {