@cavelon/cli 0.1.5 → 0.1.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/main.js CHANGED
@@ -1,6 +1,7 @@
1
1
  import { parseArgs } from "node:util";
2
2
  import { GLOBAL_OPTIONS } from "./command.js";
3
3
  import { createContext, withWarnings } from "./context.js";
4
+ import { CONFIRM_TOKEN } from "./confirm-token.js";
4
5
  import { asCavelonError, ExitCode, usageError } from "./errors.js";
5
6
  import { blockerLines } from "./format.js";
6
7
  import { blockerLines as detailedBlockerLines } from "./preview-report.js";
@@ -116,8 +117,9 @@ function parse(spec, args) {
116
117
  }
117
118
  }
118
119
  const options = { ...GLOBAL_OPTIONS, ...spec.options };
120
+ const { rest, tokens } = takeTokens(spec, args);
119
121
  const config = {
120
- args,
122
+ args: rest,
121
123
  allowPositionals: true,
122
124
  strict: true,
123
125
  options: Object.fromEntries(Object.entries(options).map(([name, o]) => [
@@ -140,6 +142,7 @@ function parse(spec, args) {
140
142
  }
141
143
  if (values.help === true)
142
144
  return { positionals: {}, options: { help: true } };
145
+ Object.assign(values, tokens);
143
146
  const named = {};
144
147
  const specs = spec.positionals ?? [];
145
148
  let index = 0;
@@ -161,6 +164,38 @@ function parse(spec, args) {
161
164
  }
162
165
  return { positionals: named, options: values };
163
166
  }
167
+ function takeTokens(spec, args) {
168
+ const names = Object.entries(spec.options ?? {})
169
+ .filter(([, o]) => o.mcpToken && o.type === "boolean")
170
+ .map(([name]) => name);
171
+ const tokens = {};
172
+ if (!names.length)
173
+ return { rest: args, tokens };
174
+ const rest = [];
175
+ for (let i = 0; i < args.length; i++) {
176
+ const arg = args[i];
177
+ if (arg === "--") {
178
+ rest.push(...args.slice(i));
179
+ break;
180
+ }
181
+ const name = names.find((n) => arg === `--${n}` || arg.startsWith(`--${n}=`));
182
+ if (!name) {
183
+ rest.push(arg);
184
+ continue;
185
+ }
186
+ const inline = arg.startsWith(`--${name}=`) ? arg.slice(name.length + 3) : undefined;
187
+ const next = args[i + 1];
188
+ if (inline)
189
+ tokens[name] = inline;
190
+ else if (inline === undefined && next !== undefined && CONFIRM_TOKEN.test(next)) {
191
+ tokens[name] = next;
192
+ i++;
193
+ }
194
+ else
195
+ rest.push(`--${name}`);
196
+ }
197
+ return { rest, tokens };
198
+ }
164
199
  function missing(spec, name) {
165
200
  return usageError(`Missing <${name}>.`, `Usage: ${usageLine(spec)}`);
166
201
  }
package/dist/mcp.js CHANGED
@@ -2,20 +2,24 @@ import { Server } from "@modelcontextprotocol/sdk/server/index.js";
2
2
  import { CallToolRequestSchema, ListToolsRequestSchema } from "@modelcontextprotocol/sdk/types.js";
3
3
  import { MCP_MAX_WAIT_MS } from "./commands/async.js";
4
4
  import { createContext, withWarnings } from "./context.js";
5
- import { asCavelonError, usageError } from "./errors.js";
5
+ import { asCavelonError, CavelonError, ExitCode, usageError } from "./errors.js";
6
+ import { closest } from "./package-references.js";
6
7
  import { KIT_VERSION } from "./version.js";
7
8
  const INSTRUCTIONS = "Tools for one Cavelon instance, acting with the token a person stored with `cavelon login` " +
8
9
  "(or CAVELON_TOKEN). You never see or pass the token. Tools that start work (kb_upload, test_run, " +
9
10
  "loop_start, sandbox_seed, artifacts_export) return operation ids at once; read them with operation_status, which returns " +
10
11
  `the state at once, or waits up to its timeout (at most ${MCP_MAX_WAIT_MS / 1000} s) when given one, and reports waited_ms, ` +
11
12
  "and follow a loop with loop_iterations. What needs confirmation: apply imports only with confirm set to a preview's id; " +
12
- "limits_set, models_set_limit, loop_cancel, sandbox_seed, trigger_identity, harness_default, activate with make_default, " +
13
+ "limits_set, models_set_limit, loop_cancel, sandbox_seed, trigger_identity, harness_default, activate with make_default, deactivate, " +
13
14
  "and api for an operation that is not read-only, " +
14
- "return what they would do and change nothing without confirm: true; show the person that first. The default route " +
15
+ "return what they would do and a confirm_token, and change nothing until called again with the same arguments and " +
16
+ "confirm set to that token: show the person the preview first. The token confirms exactly the change the preview showed; " +
17
+ "a different change needs a new preview, and confirm: true is refused. The default route " +
15
18
  "(harness_default, activate's make_default) decides which solution the tenant's chat and widget answer with: live traffic, " +
16
- "so ask the person, and confirm only with their yes. " +
19
+ "so ask the person, and confirm only with their yes; the same goes for deactivate, which takes a solution out of live traffic. " +
20
+ "chat sends one message to a solution and returns its answer: the way to try one that is not the default route. " +
17
21
  "kb_upload names files that match an active document of the knowledge base; with replace it replaces them, and where the " +
18
- "instance's upload cannot, it returns what it would deactivate and uploads nothing without confirm: true. " +
22
+ "instance's upload cannot, it returns what it would deactivate and uploads nothing without its confirm_token. " +
19
23
  "init, pull and fmt change nothing on the instance (pull only reads it); they write files in the solution folder without confirm " +
20
24
  "(pull refuses to replace a package file that changed since the last pull or apply and is not committed, unless force), " +
21
25
  "and the other changing tools act at once. api refuses, even with confirm, an operation the instance marks for a person " +
@@ -34,27 +38,32 @@ const INSTRUCTIONS = "Tools for one Cavelon instance, acting with the token a pe
34
38
  "to run in their terminal, and never ask for, read or pass a secret value. Never approve or decide an approval; " +
35
39
  "that stays with a person. Use docs_search before guessing, " +
36
40
  "and api_list/api_describe/api for anything without its own tool.";
41
+ const TOKEN_DESCRIPTION = "Over MCP: the confirm_token this tool's preview returned, which confirms exactly the change it showed; true is refused.";
37
42
  export function toolName(spec) {
38
43
  return spec.mcpTool || undefined;
39
44
  }
40
45
  function ownsTenant(spec) {
41
46
  return Boolean(spec.positionals?.some((p) => p.name === "tenant") || spec.options?.tenant);
42
47
  }
48
+ export function propertyName(name) {
49
+ return name.replaceAll("-", "_");
50
+ }
43
51
  export function inputSchema(spec) {
44
52
  const properties = {};
45
53
  const required = [];
46
54
  for (const p of spec.positionals ?? []) {
47
- properties[p.name] = p.variadic
55
+ properties[propertyName(p.name)] = p.variadic
48
56
  ? { type: "array", items: { type: "string" }, description: p.description }
49
57
  : { type: "string", description: p.description };
50
58
  if (p.required)
51
- required.push(p.name);
59
+ required.push(propertyName(p.name));
52
60
  }
53
61
  for (const [name, option] of Object.entries(spec.options ?? {})) {
54
62
  if (option.cliOnly)
55
63
  continue;
56
- properties[name] =
57
- option.type === "boolean" || option.mcpBoolean
64
+ properties[propertyName(name)] = option.mcpToken
65
+ ? { type: "string", description: `${option.description} ${TOKEN_DESCRIPTION}` }
66
+ : option.type === "boolean"
58
67
  ? { type: "boolean", description: option.description }
59
68
  : option.multiple
60
69
  ? { type: "array", items: { type: "string" }, description: option.description }
@@ -80,10 +89,35 @@ export function toolFor(spec) {
80
89
  },
81
90
  };
82
91
  }
92
+ function argumentsOf(spec, args, warn) {
93
+ const properties = Object.keys(inputSchema(spec).properties ?? {});
94
+ const out = {};
95
+ for (const [key, value] of Object.entries(args)) {
96
+ if (properties.includes(key)) {
97
+ out[key] = value;
98
+ continue;
99
+ }
100
+ const spelled = propertyName(key);
101
+ if (spelled !== key && properties.includes(spelled)) {
102
+ warn(`"${key}" is spelled "${spelled}" in this tool's schema; "${key}" is still taken for now and will be refused in a later release.`);
103
+ if (!(spelled in args))
104
+ out[spelled] = value;
105
+ continue;
106
+ }
107
+ const near = closest(key, properties);
108
+ throw new CavelonError(ExitCode.usage, {
109
+ code: "unknown_argument",
110
+ message: `${spec.mcpTool} has no argument "${key}"; nothing was done.${near ? ` Did you mean "${near}"?` : ""}`,
111
+ hint: `Its arguments: ${properties.join(", ")}.`,
112
+ details: { argument: key, ...(near ? { suggestion: near } : {}), arguments: properties },
113
+ });
114
+ }
115
+ return out;
116
+ }
83
117
  function inputFrom(spec, args) {
84
118
  const input = { positionals: {}, options: {} };
85
119
  for (const p of spec.positionals ?? []) {
86
- const value = args[p.name];
120
+ const value = args[propertyName(p.name)];
87
121
  if (value === undefined || value === null)
88
122
  continue;
89
123
  input.positionals[p.name] = p.variadic ? (Array.isArray(value) ? value.map(String) : [String(value)]) : String(value);
@@ -91,10 +125,12 @@ function inputFrom(spec, args) {
91
125
  for (const [name, option] of Object.entries(spec.options ?? {})) {
92
126
  if (option.cliOnly)
93
127
  continue;
94
- const value = args[name];
128
+ const value = args[propertyName(name)];
95
129
  if (value === undefined || value === null)
96
130
  continue;
97
- if (option.type === "boolean" || option.mcpBoolean)
131
+ if (option.mcpToken)
132
+ input.options[name] = value === true || value === "true" ? true : value === false ? false : String(value);
133
+ else if (option.type === "boolean")
98
134
  input.options[name] = value === true || value === "true";
99
135
  else if (option.multiple)
100
136
  input.options[name] = Array.isArray(value) ? value.map(String) : [String(value)];
@@ -104,7 +140,10 @@ function inputFrom(spec, args) {
104
140
  return input;
105
141
  }
106
142
  function missingRequired(spec, args) {
107
- return (spec.positionals ?? []).filter((p) => p.required && (args[p.name] === undefined || args[p.name] === "")).map((p) => p.name);
143
+ return (spec.positionals ?? [])
144
+ .map((p) => ({ ...p, name: propertyName(p.name) }))
145
+ .filter((p) => p.required && (args[p.name] === undefined || args[p.name] === ""))
146
+ .map((p) => p.name);
108
147
  }
109
148
  function mcpIo(io) {
110
149
  return { ...io, stdout: { write: () => true, isTTY: false } };
@@ -116,13 +155,21 @@ export function createMcpServer(io, commands) {
116
155
  server.setRequestHandler(ListToolsRequestSchema, async () => ({ tools: tools.map(toolFor) }));
117
156
  server.setRequestHandler(CallToolRequestSchema, async (request) => {
118
157
  const spec = byName.get(request.params.name);
119
- const args = (request.params.arguments ?? {});
158
+ const given = (request.params.arguments ?? {});
120
159
  const fail = (error) => ({
121
160
  isError: true,
122
161
  content: [{ type: "text", text: JSON.stringify({ error: asCavelonError(error).toJSON() }) }],
123
162
  });
124
163
  if (!spec)
125
164
  return fail(new Error(`Unknown tool ${request.params.name}.`));
165
+ const spelling = [];
166
+ let args;
167
+ try {
168
+ args = argumentsOf(spec, given, (message) => spelling.push(message));
169
+ }
170
+ catch (error) {
171
+ return fail(error);
172
+ }
126
173
  const missing = missingRequired(spec, args);
127
174
  if (missing.length) {
128
175
  return fail(usageError(`Missing ${missing.join(", ")}.`));
@@ -130,6 +177,8 @@ export function createMcpServer(io, commands) {
130
177
  const tenant = !ownsTenant(spec) && typeof args.tenant === "string" ? args.tenant : undefined;
131
178
  const solutionEnv = spec.options?.env && typeof args.env === "string" ? args.env : undefined;
132
179
  const ctx = createContext(mcpIo(io), { json: true, tenant, solutionEnv }, "mcp");
180
+ for (const message of spelling)
181
+ ctx.warn(message);
133
182
  try {
134
183
  const result = await spec.run(ctx, inputFrom(spec, args));
135
184
  let data = result.data;
package/dist/openapi.js CHANGED
@@ -226,6 +226,34 @@ export function secretFields(doc, schema, body) {
226
226
  walk(schema, body, "", 0);
227
227
  return [...found];
228
228
  }
229
+ export function secretPaths(doc, schema) {
230
+ const found = new Set();
231
+ let budget = 2_000;
232
+ const list = (value) => (Array.isArray(value) ? value : []);
233
+ const walk = (raw, where, depth) => {
234
+ if (depth > 6 || --budget < 0)
235
+ return;
236
+ const node = deref(doc, raw);
237
+ if (!node || typeof node !== "object")
238
+ return;
239
+ const s = node;
240
+ if (s["x-cavelon-secret"] === true) {
241
+ found.add(where || "(body)");
242
+ return;
243
+ }
244
+ for (const key of ["allOf", "anyOf", "oneOf"])
245
+ for (const sub of list(s[key]))
246
+ walk(sub, where, depth + 1);
247
+ if (s.items)
248
+ walk(s.items, `${where}[]`, depth + 1);
249
+ for (const [key, sub] of Object.entries((s.properties ?? {})))
250
+ walk(sub, where ? `${where}.${key}` : key, depth + 1);
251
+ if (s.additionalProperties && typeof s.additionalProperties === "object")
252
+ walk(s.additionalProperties, where ? `${where}.*` : "*", depth + 1);
253
+ };
254
+ walk(schema, "", 0);
255
+ return [...found];
256
+ }
229
257
  function matches(pattern, key) {
230
258
  try {
231
259
  return new RegExp(pattern, "u").test(key);
@@ -295,6 +323,8 @@ export function describeSchema(doc, schema, depth = 0) {
295
323
  parts.push(`one of ${sub.enum.join(", ")}`);
296
324
  if (sub.default !== undefined)
297
325
  parts.push(`default ${JSON.stringify(sub.default)}`);
326
+ if (secretPaths(doc, p).includes("(body)"))
327
+ parts.push("secret value (x-cavelon-secret): a person enters it");
298
328
  fields[name] = parts.join(", ");
299
329
  if (items && depth < 3)
300
330
  fields[`${name}[]`] = describeSchema(doc, items, depth + 1);
@@ -3,25 +3,28 @@ import { BRANCH_WIDTH_KEY, branchConcurrency, offText } from "./branches.js";
3
3
  import { locate, schemaSections } from "./package-files.js";
4
4
  import { PERSONA_SECTION, sectionFields } from "./package-format.js";
5
5
  import { kitErrorEntry } from "./kit-codes.js";
6
- import { checkModels, checkReferences, checkUnknownFields, DUPLICATE_CODE, FIELD_UNKNOWN_CODE, MODEL_UNKNOWN_CODE, REFERENCE_MISSING_CODE, REFERENCE_UNKNOWN_CODE, SEARCH_TOOL_KEYS, } from "./package-references.js";
6
+ 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
7
  export const SCHEMA_CODE = "package_schema_invalid";
8
8
  const ENDPOINT_LIMIT_CODE = "model_endpoint_limit_without_base_url";
9
9
  const ENDPOINT_LIMIT_NOT_CARRIED = "model_endpoint_limit_not_in_package_schema";
10
10
  const REGISTRY_SECTION = "model_registry";
11
11
  const ENDPOINT_LIMIT_FIELD = "max_concurrent_requests";
12
12
  const PACKAGE_DOCS = "/docs/reference/api-endpoints";
13
+ const IMPORT_DOCS = "/docs/concepts/harnesses#import-export-and-backup";
13
14
  const BRANCH_WIDTH_CODE = "branch_width_capped";
14
15
  const BRANCHES_SEQUENTIAL_CODE = "branches_run_in_sequence";
15
16
  const BRANCH_DOCS = "/docs/concepts/capacity-and-concurrency#branch-concurrency";
16
17
  const KB_WITHOUT_SEARCH_CODE = "knowledge_base_without_search_tool";
17
18
  const SEARCH_DOCS = "/docs/reference/builtin-tools#binding-knowledge-bases-to-search_documents";
18
19
  const SEARCH_TOOL = "search_documents";
20
+ const LIST_TOOL = "list_documents";
19
21
  const PERSONA_MESSAGE_CODE = "persona_message_empty";
20
22
  const PERSONA_DOCS = "/docs/concepts/personas";
21
23
  const PERSONA_MESSAGES = [
22
24
  { switch: "greeting_enabled", text: "greeting_message", what: "greeting", when: "when a conversation starts" },
23
25
  { switch: "fallback_message_enabled", text: "fallback_message", what: "fallback message", when: "when the assistant has no answer" },
24
26
  ];
27
+ const SOLUTION_MISMATCH_CODE = "solution_slug_mismatch";
25
28
  const ASSERTION_UNCHECKED_CODE = "test_assertion_unchecked";
26
29
  const TESTING_DOCS = "/docs/concepts/regression-testing";
27
30
  export const KIT_CODES = [
@@ -77,8 +80,9 @@ export const KIT_CODES = [
77
80
  {
78
81
  code: KB_WITHOUT_SEARCH_CODE,
79
82
  area: "package",
80
- message: "An agent is given knowledge bases, but no search tool reaches it, so it cannot read them.",
81
- hint: `A knowledge base reaches an agent only through a search tool: add \`- tool_slug: ${SEARCH_TOOL}\` to the tool_assignments of the skill that names the knowledge base, or of the agent. \`cavelon docs get reference/builtin-tools\` shows the binding.`,
83
+ message: "An agent is given knowledge bases, but no tool that searches or lists them reaches it, so it cannot read them.",
84
+ hint: `A knowledge base reaches an agent only through a built-in document tool: add \`- tool_slug: ${SEARCH_TOOL}\` (or ${LIST_TOOL}, with read_document to read ` +
85
+ "what it lists) to the tool_assignments of the skill that names the knowledge base, or of the agent. `cavelon docs get reference/builtin-tools` shows the binding.",
82
86
  docs: SEARCH_DOCS,
83
87
  },
84
88
  {
@@ -102,20 +106,21 @@ export const KIT_CODES = [
102
106
  area: "package",
103
107
  message: "Two entries of one section have the same key (slug, or name for a knowledge base).",
104
108
  hint: "Rename or remove one of them: the import keeps only one entry per key.",
105
- docs: PACKAGE_DOCS,
109
+ docs: IMPORT_DOCS,
106
110
  },
107
111
  {
108
112
  code: REFERENCE_MISSING_CODE,
109
113
  area: "package",
110
- message: "An agent hands off to an agent that is not in the package.",
111
- hint: "Fix the to_agent_slug (the finding suggests the closest slug), or add the agent to package/agents.yaml.",
114
+ message: "An agent hands off to an agent that is not in the package, or a test step's assertion (answered_by, handoff_to) names one.",
115
+ hint: "Fix the to_agent_slug or the assertion's value (the finding suggests the closest slug), or add the agent to package/agents.yaml.",
112
116
  docs: PACKAGE_DOCS,
113
117
  },
114
118
  {
115
119
  code: REFERENCE_UNKNOWN_CODE,
116
120
  area: "package",
117
- message: "A skill, tool, knowledge base or solution is named that is neither in the package nor among what the tenant held at the last pull.",
118
- hint: "Fix the name (the finding suggests the closest one), or add the entry to the package. If it was created on the instance since, `cavelon pull` refreshes the list in .cavelon/inventory.json.",
121
+ message: "A skill, tool, knowledge base or solution is named (by an agent, a skill or a test step's assertion) that is neither in the package nor among what the tenant held at the last pull.",
122
+ hint: "Fix the name (the finding suggests the closest one), or add the entry to the package. The import preview blocks a reference it cannot resolve, " +
123
+ "so validate --strict fails on it. If it was created on the instance since, `cavelon pull` refreshes the list in .cavelon/inventory.json.",
119
124
  docs: PACKAGE_DOCS,
120
125
  },
121
126
  {
@@ -123,13 +128,22 @@ export const KIT_CODES = [
123
128
  area: "package",
124
129
  message: "A package file sets a field this instance's package schema does not have; the import ignores it.",
125
130
  hint: "Check the field name for a typo (the finding suggests the closest field); a field from a newer instance is ignored by this one.",
126
- docs: PACKAGE_DOCS,
131
+ docs: IMPORT_DOCS,
127
132
  },
128
133
  {
129
134
  code: MODEL_UNKNOWN_CODE,
130
135
  area: "package",
131
136
  message: "An agent's llm_model is not in the tenant's model list as the kit last read it.",
132
- hint: "Fix the model id (the finding suggests the closest one), or register the model. `cavelon models list` shows the tenant's models and refreshes the list validate checks against.",
137
+ hint: "Fix the model id (the finding suggests the closest one), or register the model: the import preview blocks a model the tenant does not have. " +
138
+ "`cavelon models list` shows the tenant's models and refreshes the list validate checks against.",
139
+ docs: PACKAGE_DOCS,
140
+ },
141
+ {
142
+ code: SOLUTION_MISMATCH_CODE,
143
+ area: "package",
144
+ message: "The package names another solution than cavelon.yaml: harnesses.yaml's slug, or an entry's harness_slug.",
145
+ hint: "After copying a solution under another name, change the slug in package/harnesses.yaml and every harness_slug to the one cavelon.yaml names " +
146
+ "(or set harness in cavelon.yaml to the package's); the import otherwise works on the solution the package names.",
133
147
  docs: PACKAGE_DOCS,
134
148
  },
135
149
  {
@@ -140,6 +154,9 @@ export const KIT_CODES = [
140
154
  docs: PACKAGE_DOCS,
141
155
  },
142
156
  ];
157
+ function findingEntry(catalog, code) {
158
+ return catalog?.rule_codes?.find((e) => e.code === code) ?? KIT_CODES.find((e) => e.code === code) ?? catalog?.api_error_codes?.find((e) => e.code === code);
159
+ }
143
160
  export function catalogEntry(catalog, code) {
144
161
  const rule = catalog?.rule_codes?.find((e) => e.code === code);
145
162
  if (rule)
@@ -252,15 +269,32 @@ export function checkPackage(disk, options) {
252
269
  const validate = compile(options.schema);
253
270
  if (!validate(disk.package)) {
254
271
  const seen = new Set();
255
- for (const error of closestBranchErrors(validate.errors ?? [])) {
272
+ const errors = validate.errors ?? [];
273
+ const misnamed = misnamedVariants(options.schema, disk.package).filter((m) => errors.some((e) => within(e.instancePath, m.pointer)));
274
+ for (const m of misnamed) {
275
+ findings.push({
276
+ code: SCHEMA_CODE,
277
+ severity: "error",
278
+ ...locate(disk, `${m.pointer}/${m.field}`),
279
+ message: `${m.field} "${m.value}" is none of the types this field takes (${m.allowed.join(", ")}).` + (m.suggestion ? ` Did you mean "${m.suggestion}"?` : ""),
280
+ ...(m.suggestion ? { suggestion: m.suggestion } : {}),
281
+ hint: schemaHint(disk.package, m.pointer),
282
+ });
283
+ }
284
+ const unreadable = new Set(disk.unreadable ?? []);
285
+ for (const error of closestBranchErrors(errors)) {
256
286
  if (error.keyword === "anyOf" || error.keyword === "oneOf")
257
287
  continue;
288
+ if (misnamed.some((m) => within(error.instancePath, m.pointer)))
289
+ continue;
290
+ if (error.keyword === "required" && error.instancePath === "" && unreadable.has(String(error.params.missingProperty)))
291
+ continue;
258
292
  const { pointer, message } = describe(error);
259
293
  const key = `${pointer} ${message}`;
260
294
  if (seen.has(key))
261
295
  continue;
262
296
  seen.add(key);
263
- findings.push({ code: SCHEMA_CODE, severity: "error", ...locate(disk, pointer), message });
297
+ findings.push({ code: SCHEMA_CODE, severity: "error", ...locate(disk, pointer), message, hint: schemaHint(disk.package, pointer) });
264
298
  }
265
299
  }
266
300
  findings.push(...checkEndpointLimits(disk, options.schema));
@@ -271,8 +305,9 @@ export function checkPackage(disk, options) {
271
305
  findings.push(...checkModels(disk, options.inventory));
272
306
  findings.push(...checkPersonaMessages(disk, options.schema));
273
307
  findings.push(...checkUncheckedAssertions(disk, options.schema));
308
+ findings.push(...checkSolutionSlug(disk, options.solution));
274
309
  for (const finding of findings) {
275
- const entry = catalogEntry(options.catalog, finding.code);
310
+ const entry = findingEntry(options.catalog, finding.code);
276
311
  if (!entry)
277
312
  continue;
278
313
  finding.hint ??= entry.hint ?? undefined;
@@ -394,9 +429,9 @@ const active = (e) => e.is_active !== false;
394
429
  const quoted = (names) => names.map((n) => `"${n}"`).join(", ");
395
430
  function checkKnowledgeSearch(disk) {
396
431
  const pkg = disk.package;
397
- const searchSlugs = new Set(SEARCH_TOOL_KEYS);
432
+ const searchSlugs = new Set(KNOWLEDGE_TOOL_KEYS);
398
433
  for (const tool of asList(pkg.tools)) {
399
- if (typeof tool.slug === "string" && typeof tool.builtin_key === "string" && SEARCH_TOOL_KEYS.has(tool.builtin_key))
434
+ if (typeof tool.slug === "string" && typeof tool.builtin_key === "string" && KNOWLEDGE_TOOL_KEYS.has(tool.builtin_key))
400
435
  searchSlugs.add(tool.slug);
401
436
  }
402
437
  const searches = (assignments) => asList(assignments).some((a) => active(a) && typeof a.tool_slug === "string" && searchSlugs.has(a.tool_slug));
@@ -449,8 +484,8 @@ function checkKnowledgeSearch(disk) {
449
484
  severity: "warning",
450
485
  ...locate(disk, first.pointer),
451
486
  message: `The agent${agentName} is given the knowledge base${names.length === 1 ? "" : "s"} ${quoted(names)}` +
452
- `${first.via ? ` through the skill "${first.via}"` : ""}, but no search tool reaches it, so it cannot search ${names.length === 1 ? "it" : "them"}: ` +
453
- `add ${SEARCH_TOOL} to the ${first.via ? "skill's" : "agent's"} tool_assignments.`,
487
+ `${first.via ? ` through the skill "${first.via}"` : ""}, but no tool that searches or lists ${names.length === 1 ? "it" : "them"} reaches the agent, ` +
488
+ `so it cannot read ${names.length === 1 ? "it" : "them"}: add ${SEARCH_TOOL} (or ${LIST_TOOL}) to the ${first.via ? "skill's" : "agent's"} tool_assignments.`,
454
489
  });
455
490
  });
456
491
  return findings;
@@ -529,3 +564,128 @@ function checkPersonaMessages(disk, schema) {
529
564
  }
530
565
  return findings;
531
566
  }
567
+ const within = (pointer, outer) => pointer === outer || pointer.startsWith(`${outer}/`);
568
+ export function schemaPathOf(pkg, pointer) {
569
+ const keys = pointer.split("/").slice(1).map((k) => k.replace(/~1/g, "/").replace(/~0/g, "~"));
570
+ let value = pkg;
571
+ const names = [];
572
+ for (const key of keys) {
573
+ const inner = Array.isArray(value) ? value[Number(key)] : asObject(value)?.[key];
574
+ if (inner === undefined || inner === null || typeof inner !== "object")
575
+ break;
576
+ if (!Array.isArray(value))
577
+ names.push(key);
578
+ value = inner;
579
+ }
580
+ return names.join(".");
581
+ }
582
+ function schemaHint(pkg, pointer) {
583
+ const at = schemaPathOf(pkg, pointer);
584
+ return at
585
+ ? `Fix the field the finding names; \`cavelon schema ${at}\` lists the fields there (type, required, allowed values) with a minimal entry.`
586
+ : "Fix the field the finding names; `cavelon schema` lists the sections, and `cavelon schema <section>` their fields.";
587
+ }
588
+ const propertiesIn = (node) => asObject(node.properties);
589
+ function listedValues(schema, node) {
590
+ const values = [];
591
+ for (const branch of branches(schema, node)) {
592
+ if ("const" in branch)
593
+ values.push(branch.const);
594
+ else if (Array.isArray(branch.enum))
595
+ values.push(...branch.enum);
596
+ else if (branch.type !== "null")
597
+ return undefined;
598
+ }
599
+ return values.length ? values : undefined;
600
+ }
601
+ function misnamedVariants(schema, pkg) {
602
+ const found = [];
603
+ const walk = (value, node, pointer, depth) => {
604
+ if (depth > 40)
605
+ return;
606
+ if (Array.isArray(value)) {
607
+ const items = branches(schema, node).map((b) => b.items).find((i) => i !== undefined);
608
+ if (items !== undefined)
609
+ value.forEach((item, i) => walk(item, items, `${pointer}/${i}`, depth + 1));
610
+ return;
611
+ }
612
+ const object = asObject(value);
613
+ if (!object)
614
+ return;
615
+ const shapes = branches(schema, node).filter((b) => propertiesIn(b));
616
+ if (shapes.length > 1) {
617
+ for (const [field, given] of Object.entries(object)) {
618
+ if (typeof given !== "string")
619
+ continue;
620
+ const defining = shapes.filter((shape) => propertiesIn(shape)[field] !== undefined);
621
+ if (defining.length < 2)
622
+ continue;
623
+ const lists = defining.map((shape) => listedValues(schema, propertiesIn(shape)[field]));
624
+ if (lists.some((l) => l === undefined))
625
+ continue;
626
+ const allowed = [...new Set(lists.flat().filter((v) => typeof v === "string"))];
627
+ if (allowed.includes(given)) {
628
+ const shape = defining.find((_, i) => lists[i].includes(given));
629
+ for (const [key, inner] of Object.entries(object)) {
630
+ const sub = propertiesIn(shape)[key];
631
+ if (sub !== undefined)
632
+ walk(inner, sub, `${pointer}/${key}`, depth + 1);
633
+ }
634
+ return;
635
+ }
636
+ found.push({ pointer, field, value: given, allowed: allowed.sort((a, b) => a.localeCompare(b, "en")), suggestion: closest(given, allowed) });
637
+ return;
638
+ }
639
+ }
640
+ const shape = shapes.length === 1 ? shapes[0] : undefined;
641
+ if (!shape)
642
+ return;
643
+ for (const [key, inner] of Object.entries(object)) {
644
+ const sub = propertiesIn(shape)[key];
645
+ if (sub !== undefined)
646
+ walk(inner, sub, `${pointer}/${key}`, depth + 1);
647
+ }
648
+ };
649
+ const sections = asObject(schema.properties) ?? {};
650
+ for (const [section, value] of Object.entries(pkg))
651
+ if (section in sections)
652
+ walk(value, sections[section], `/${section}`, 0);
653
+ return found;
654
+ }
655
+ const UUID = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
656
+ function checkSolutionSlug(disk, solution) {
657
+ if (!solution || UUID.test(solution))
658
+ return [];
659
+ const pkg = disk.package;
660
+ const harnesses = asList(pkg.harnesses);
661
+ const own = harnesses.find((h) => h.slug === solution || h.name === solution);
662
+ const slug = typeof own?.slug === "string" ? own.slug : solution;
663
+ const findings = [];
664
+ if (harnesses.length && !own) {
665
+ const named = harnesses.map((h) => h.slug).filter((v) => typeof v === "string");
666
+ findings.push({
667
+ code: SOLUTION_MISMATCH_CODE,
668
+ severity: "warning",
669
+ ...locate(disk, "/harnesses/0/slug"),
670
+ message: `cavelon.yaml names the solution "${solution}", and the package's harnesses name ${quoted(named)}: ` +
671
+ `rename the slug (and every harness_slug) to "${solution}", or set harness in cavelon.yaml to the package's.`,
672
+ });
673
+ }
674
+ if (harnesses.length)
675
+ return findings;
676
+ for (const section of ["agents", "test_suites"]) {
677
+ const entries = asList(pkg[section]);
678
+ const off = entries.flatMap((entry, i) => (typeof entry.harness_slug === "string" && entry.harness_slug !== slug ? [{ i, name: entry.harness_slug }] : []));
679
+ if (!off.length)
680
+ continue;
681
+ const names = [...new Set(off.map((o) => o.name))];
682
+ findings.push({
683
+ code: SOLUTION_MISMATCH_CODE,
684
+ severity: "warning",
685
+ ...locate(disk, `/${section}/${off[0].i}/harness_slug`),
686
+ message: `${off.length} of the ${section} name${off.length === 1 ? "s" : ""} the solution ${quoted(names)} in harness_slug, and cavelon.yaml names "${slug}": ` +
687
+ `set harness_slug to "${slug}".`,
688
+ });
689
+ }
690
+ return findings;
691
+ }