@cavelon/cli 0.1.4 → 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.
Files changed (50) hide show
  1. package/README.md +58 -22
  2. package/dist/choose.js +8 -4
  3. package/dist/code-hints.js +74 -0
  4. package/dist/commands/api.js +83 -44
  5. package/dist/commands/async.js +26 -5
  6. package/dist/commands/chat.js +177 -0
  7. package/dist/commands/docs.js +240 -37
  8. package/dist/commands/fmt.js +120 -0
  9. package/dist/commands/index.js +9 -1
  10. package/dist/commands/init.js +64 -30
  11. package/dist/commands/inventory.js +48 -5
  12. package/dist/commands/limits-set.js +9 -6
  13. package/dist/commands/loops.js +15 -9
  14. package/dist/commands/models.js +16 -7
  15. package/dist/commands/sandboxes.js +8 -4
  16. package/dist/commands/schema.js +361 -0
  17. package/dist/commands/session.js +148 -24
  18. package/dist/commands/setup.js +22 -6
  19. package/dist/commands/solution.js +537 -76
  20. package/dist/commands/tenants.js +156 -15
  21. package/dist/commands/values.js +18 -9
  22. package/dist/commands/work.js +343 -35
  23. package/dist/confirm-token.js +72 -0
  24. package/dist/contracts.js +3 -0
  25. package/dist/default-route.js +21 -0
  26. package/dist/errors.js +4 -0
  27. package/dist/git.js +14 -5
  28. package/dist/harness-ref.js +14 -1
  29. package/dist/http.js +27 -4
  30. package/dist/invoke.js +8 -4
  31. package/dist/kit-codes.js +91 -0
  32. package/dist/limits.js +12 -1
  33. package/dist/local-state.js +32 -7
  34. package/dist/main.js +52 -4
  35. package/dist/mcp.js +72 -15
  36. package/dist/openapi.js +77 -21
  37. package/dist/operations.js +4 -3
  38. package/dist/package-check.js +361 -12
  39. package/dist/package-files.js +92 -45
  40. package/dist/package-format.js +222 -0
  41. package/dist/package-references.js +298 -0
  42. package/dist/preview-report.js +152 -0
  43. package/dist/results.js +21 -1
  44. package/dist/skills/cavelon-authoring/SKILL.md +98 -13
  45. package/dist/skills/cavelon-long-running/SKILL.md +3 -1
  46. package/dist/skills/cavelon-loop/SKILL.md +129 -21
  47. package/dist/skills/cavelon-testing/SKILL.md +130 -10
  48. package/dist/tenant-choice.js +31 -5
  49. package/dist/trace-view.js +172 -0
  50. package/package.json +1 -1
@@ -1,19 +1,32 @@
1
1
  import { Ajv2020 } from "ajv/dist/2020.js";
2
2
  import { BRANCH_WIDTH_KEY, branchConcurrency, offText } from "./branches.js";
3
3
  import { locate, schemaSections } from "./package-files.js";
4
+ import { PERSONA_SECTION, sectionFields } from "./package-format.js";
5
+ import { kitErrorEntry } from "./kit-codes.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";
4
7
  export const SCHEMA_CODE = "package_schema_invalid";
5
8
  const ENDPOINT_LIMIT_CODE = "model_endpoint_limit_without_base_url";
6
9
  const ENDPOINT_LIMIT_NOT_CARRIED = "model_endpoint_limit_not_in_package_schema";
7
10
  const REGISTRY_SECTION = "model_registry";
8
11
  const ENDPOINT_LIMIT_FIELD = "max_concurrent_requests";
9
12
  const PACKAGE_DOCS = "/docs/reference/api-endpoints";
13
+ const IMPORT_DOCS = "/docs/concepts/harnesses#import-export-and-backup";
10
14
  const BRANCH_WIDTH_CODE = "branch_width_capped";
11
15
  const BRANCHES_SEQUENTIAL_CODE = "branches_run_in_sequence";
12
16
  const BRANCH_DOCS = "/docs/concepts/capacity-and-concurrency#branch-concurrency";
13
17
  const KB_WITHOUT_SEARCH_CODE = "knowledge_base_without_search_tool";
14
18
  const SEARCH_DOCS = "/docs/reference/builtin-tools#binding-knowledge-bases-to-search_documents";
15
19
  const SEARCH_TOOL = "search_documents";
16
- const SEARCH_TOOL_KEYS = new Set([SEARCH_TOOL, "search_knowledge_base", "search_kb"]);
20
+ const LIST_TOOL = "list_documents";
21
+ const PERSONA_MESSAGE_CODE = "persona_message_empty";
22
+ const PERSONA_DOCS = "/docs/concepts/personas";
23
+ const PERSONA_MESSAGES = [
24
+ { switch: "greeting_enabled", text: "greeting_message", what: "greeting", when: "when a conversation starts" },
25
+ { switch: "fallback_message_enabled", text: "fallback_message", what: "fallback message", when: "when the assistant has no answer" },
26
+ ];
27
+ const SOLUTION_MISMATCH_CODE = "solution_slug_mismatch";
28
+ const ASSERTION_UNCHECKED_CODE = "test_assertion_unchecked";
29
+ const TESTING_DOCS = "/docs/concepts/regression-testing";
17
30
  export const KIT_CODES = [
18
31
  {
19
32
  code: SCHEMA_CODE,
@@ -67,10 +80,72 @@ export const KIT_CODES = [
67
80
  {
68
81
  code: KB_WITHOUT_SEARCH_CODE,
69
82
  area: "package",
70
- message: "An agent is given knowledge bases, but no search tool reaches it, so it cannot read them.",
71
- 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.",
72
86
  docs: SEARCH_DOCS,
73
87
  },
88
+ {
89
+ code: ASSERTION_UNCHECKED_CODE,
90
+ area: "package",
91
+ message: "A test step has assertions (criteria with a type), and this instance's package schema does not describe a step's criteria, so validate cannot check them.",
92
+ hint: "An instance that knows the type checks the assertion in code; one that does not grades it as a judge criterion. " +
93
+ "`cavelon docs get concepts/regression-testing` says which types this instance knows; a newer instance publishes them in its package schema.",
94
+ docs: TESTING_DOCS,
95
+ },
96
+ {
97
+ code: PERSONA_MESSAGE_CODE,
98
+ area: "package",
99
+ message: "The persona turns a greeting or a fallback message on, but its text is empty.",
100
+ hint: "Write the text in persona.yaml (greeting_message, fallback_message) in the language the assistant answers in, or set " +
101
+ "greeting_enabled / fallback_message_enabled to false. The persona says who the assistant is for every agent of the solution.",
102
+ docs: PERSONA_DOCS,
103
+ },
104
+ {
105
+ code: DUPLICATE_CODE,
106
+ area: "package",
107
+ message: "Two entries of one section have the same key (slug, or name for a knowledge base).",
108
+ hint: "Rename or remove one of them: the import keeps only one entry per key.",
109
+ docs: IMPORT_DOCS,
110
+ },
111
+ {
112
+ code: REFERENCE_MISSING_CODE,
113
+ area: "package",
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.",
116
+ docs: PACKAGE_DOCS,
117
+ },
118
+ {
119
+ code: REFERENCE_UNKNOWN_CODE,
120
+ area: "package",
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.",
124
+ docs: PACKAGE_DOCS,
125
+ },
126
+ {
127
+ code: FIELD_UNKNOWN_CODE,
128
+ area: "package",
129
+ message: "A package file sets a field this instance's package schema does not have; the import ignores it.",
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.",
131
+ docs: IMPORT_DOCS,
132
+ },
133
+ {
134
+ code: MODEL_UNKNOWN_CODE,
135
+ area: "package",
136
+ message: "An agent's llm_model is not in the tenant's model list as the kit last read it.",
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.",
147
+ docs: PACKAGE_DOCS,
148
+ },
74
149
  {
75
150
  code: "package_file_duplicate",
76
151
  area: "package",
@@ -79,6 +154,9 @@ export const KIT_CODES = [
79
154
  docs: PACKAGE_DOCS,
80
155
  },
81
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
+ }
82
160
  export function catalogEntry(catalog, code) {
83
161
  const rule = catalog?.rule_codes?.find((e) => e.code === code);
84
162
  if (rule)
@@ -87,7 +165,10 @@ export function catalogEntry(catalog, code) {
87
165
  if (api)
88
166
  return { ...api, kind: "api" };
89
167
  const kit = KIT_CODES.find((e) => e.code === code);
90
- return kit ? { ...kit, kind: "kit" } : undefined;
168
+ if (kit)
169
+ return { ...kit, kind: "kit" };
170
+ const cli = kitErrorEntry(code);
171
+ return cli ? { ...cli, kind: "cli" } : undefined;
91
172
  }
92
173
  export function packageVersionOf(pkg) {
93
174
  const manifest = pkg.manifest;
@@ -98,11 +179,57 @@ export function packageVersionOf(pkg) {
98
179
  }
99
180
  function compile(schema) {
100
181
  const { $id: _id, $schema: _schema, ...body } = schema;
101
- const ajv = new Ajv2020({ strict: false, allErrors: true, validateSchema: false, validateFormats: false });
182
+ const ajv = new Ajv2020({ strict: false, allErrors: true, verbose: true, validateSchema: false, validateFormats: false });
102
183
  return ajv.compile(body);
103
184
  }
185
+ function closestBranchErrors(errors) {
186
+ const dropped = new Set();
187
+ const countedAt = new Map();
188
+ const pathOf = (e) => countedAt.get(e) ?? e.schemaPath;
189
+ const isChoice = (e) => e.keyword === "anyOf" || e.keyword === "oneOf";
190
+ errors.forEach((choice, index) => {
191
+ if (!isChoice(choice))
192
+ return;
193
+ const list = choice.schema;
194
+ if (!Array.isArray(list))
195
+ return;
196
+ const prefixes = list.map((branch, i) => {
197
+ const ref = branch && typeof branch === "object" ? branch.$ref : undefined;
198
+ return [`${choice.schemaPath}/${i}/`, ...(typeof ref === "string" && ref.startsWith("#/") ? [`${ref}/`] : [])];
199
+ });
200
+ const here = choice.instancePath;
201
+ const byBranch = new Map();
202
+ for (const error of errors.slice(0, index)) {
203
+ if (dropped.has(error) || isChoice(error))
204
+ continue;
205
+ if (error.instancePath !== here && !error.instancePath.startsWith(`${here}/`))
206
+ continue;
207
+ const branch = prefixes.findIndex((list) => list.some((prefix) => pathOf(error).startsWith(prefix)));
208
+ if (branch >= 0)
209
+ byBranch.set(branch, [...(byBranch.get(branch) ?? []), error]);
210
+ }
211
+ const distance = (list) => list.reduce((sum, e) => {
212
+ if (e.keyword === "type" && e.instancePath === here)
213
+ return sum + 1000;
214
+ const field = e.instancePath.startsWith(`${here}/`) && !e.instancePath.slice(here.length + 1).includes("/");
215
+ return sum + ((e.keyword === "const" || e.keyword === "enum") && field ? 100 : 1);
216
+ }, 0);
217
+ const ranked = [...byBranch.values()].map((list) => ({ list, distance: distance(list) })).sort((a, b) => a.distance - b.distance);
218
+ if (ranked.length < 2 || ranked[0].distance === ranked[1].distance)
219
+ return;
220
+ for (const other of ranked.slice(1))
221
+ for (const error of other.list)
222
+ dropped.add(error);
223
+ for (const error of ranked[0].list)
224
+ countedAt.set(error, pathOf(choice));
225
+ });
226
+ return errors.filter((e) => !dropped.has(e));
227
+ }
104
228
  function describe(error) {
105
229
  const params = error.params;
230
+ if (error.keyword === "additionalProperties") {
231
+ return { pointer: error.instancePath, message: `field "${String(params.additionalProperty)}" is not allowed here` };
232
+ }
106
233
  if (error.keyword === "required") {
107
234
  return { pointer: error.instancePath, message: `missing required field "${String(params.missingProperty)}"` };
108
235
  }
@@ -142,22 +269,45 @@ export function checkPackage(disk, options) {
142
269
  const validate = compile(options.schema);
143
270
  if (!validate(disk.package)) {
144
271
  const seen = new Set();
145
- for (const error of 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)) {
146
286
  if (error.keyword === "anyOf" || error.keyword === "oneOf")
147
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;
148
292
  const { pointer, message } = describe(error);
149
293
  const key = `${pointer} ${message}`;
150
294
  if (seen.has(key))
151
295
  continue;
152
296
  seen.add(key);
153
- 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) });
154
298
  }
155
299
  }
156
300
  findings.push(...checkEndpointLimits(disk, options.schema));
157
301
  findings.push(...checkBranchConcurrency(disk, options.limits));
158
302
  findings.push(...checkKnowledgeSearch(disk));
303
+ findings.push(...checkUnknownFields(disk, options.schema, findings));
304
+ findings.push(...checkReferences(disk, options.inventory));
305
+ findings.push(...checkModels(disk, options.inventory));
306
+ findings.push(...checkPersonaMessages(disk, options.schema));
307
+ findings.push(...checkUncheckedAssertions(disk, options.schema));
308
+ findings.push(...checkSolutionSlug(disk, options.solution));
159
309
  for (const finding of findings) {
160
- const entry = catalogEntry(options.catalog, finding.code);
310
+ const entry = findingEntry(options.catalog, finding.code);
161
311
  if (!entry)
162
312
  continue;
163
313
  finding.hint ??= entry.hint ?? undefined;
@@ -279,9 +429,9 @@ const active = (e) => e.is_active !== false;
279
429
  const quoted = (names) => names.map((n) => `"${n}"`).join(", ");
280
430
  function checkKnowledgeSearch(disk) {
281
431
  const pkg = disk.package;
282
- const searchSlugs = new Set(SEARCH_TOOL_KEYS);
432
+ const searchSlugs = new Set(KNOWLEDGE_TOOL_KEYS);
283
433
  for (const tool of asList(pkg.tools)) {
284
- 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))
285
435
  searchSlugs.add(tool.slug);
286
436
  }
287
437
  const searches = (assignments) => asList(assignments).some((a) => active(a) && typeof a.tool_slug === "string" && searchSlugs.has(a.tool_slug));
@@ -334,9 +484,208 @@ function checkKnowledgeSearch(disk) {
334
484
  severity: "warning",
335
485
  ...locate(disk, first.pointer),
336
486
  message: `The agent${agentName} is given the knowledge base${names.length === 1 ? "" : "s"} ${quoted(names)}` +
337
- `${first.via ? ` through the skill "${first.via}"` : ""}, but no search tool reaches it, so it cannot search ${names.length === 1 ? "it" : "them"}: ` +
338
- `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.`,
489
+ });
490
+ });
491
+ return findings;
492
+ }
493
+ function schemaNode(schema, node) {
494
+ let at = asObject(node);
495
+ for (let hops = 0; at && typeof at.$ref === "string" && hops < 10; hops++) {
496
+ const ref = at.$ref;
497
+ at = ref.startsWith("#/$defs/") ? asObject(schema.$defs?.[ref.slice("#/$defs/".length)]) : undefined;
498
+ }
499
+ return at;
500
+ }
501
+ function listItems(schema, node) {
502
+ const at = schemaNode(schema, node);
503
+ if (!at)
504
+ return undefined;
505
+ const branches = Array.isArray(at.anyOf) ? at.anyOf.map((b) => schemaNode(schema, b)) : [at];
506
+ const arrays = branches.filter((b) => b?.type === "array");
507
+ return arrays.length === 1 && "items" in arrays[0] ? (asObject(arrays[0].items) ?? {}) : undefined;
508
+ }
509
+ function checkUncheckedAssertions(disk, schema) {
510
+ const field = (node, name) => (asObject(schemaNode(schema, node)?.properties) ?? {})[name];
511
+ const step = schemaNode(schema, listItems(schema, field(listItems(schema, field(listItems(schema, schema.properties?.test_suites), "test_cases")), "steps")));
512
+ const criteria = listItems(schema, field(step, "evaluation_criteria"));
513
+ const described = !criteria || Object.keys(criteria).some((k) => k !== "title" && k !== "description");
514
+ if (described)
515
+ return [];
516
+ const suites = Array.isArray(disk.package.test_suites) ? disk.package.test_suites : [];
517
+ const byFile = new Map();
518
+ suites.forEach((suite, s) => {
519
+ (Array.isArray(asObject(suite)?.test_cases) ? asObject(suite).test_cases : []).forEach((testCase, c) => {
520
+ (Array.isArray(asObject(testCase)?.steps) ? asObject(testCase).steps : []).forEach((step, t) => {
521
+ const list = asObject(step)?.evaluation_criteria;
522
+ (Array.isArray(list) ? list : []).forEach((criterion, i) => {
523
+ const type = asObject(criterion)?.type;
524
+ if (typeof type !== "string")
525
+ return;
526
+ const at = locate(disk, `/test_suites/${s}/test_cases/${c}/steps/${t}/evaluation_criteria/${i}`);
527
+ const key = at.file ?? "";
528
+ if (!byFile.has(key))
529
+ byFile.set(key, { at, types: new Set() });
530
+ byFile.get(key).types.add(type);
531
+ });
532
+ });
339
533
  });
340
534
  });
535
+ return [...byFile.values()].map(({ at, types }) => ({
536
+ code: ASSERTION_UNCHECKED_CODE,
537
+ severity: "warning",
538
+ ...at,
539
+ message: `This instance's package schema does not describe a step's criteria, so the assertions here (${[...types].join(", ")}) are not checked. ` +
540
+ "An instance that does not know a type grades it as a judge criterion instead of checking it in code.",
541
+ }));
542
+ }
543
+ function checkPersonaMessages(disk, schema) {
544
+ const persona = asObject(disk.package[PERSONA_SECTION]);
545
+ const fields = sectionFields(schema, PERSONA_SECTION);
546
+ if (!persona || !fields)
547
+ return [];
548
+ const findings = [];
549
+ for (const pair of PERSONA_MESSAGES) {
550
+ if (!fields[pair.switch] || !fields[pair.text])
551
+ continue;
552
+ const on = persona[pair.switch] ?? fields[pair.switch].default;
553
+ const text = persona[pair.text];
554
+ if (on !== true || (typeof text === "string" && text.trim()))
555
+ continue;
556
+ const at = locate(disk, `/${PERSONA_SECTION}/${pair.switch in persona ? pair.switch : pair.text}`);
557
+ findings.push({
558
+ code: PERSONA_MESSAGE_CODE,
559
+ severity: "warning",
560
+ ...at,
561
+ message: `${pair.switch} is ${pair.switch in persona ? "true" : "true by default"}, but ${pair.text} is empty: ` +
562
+ `the solution shows no ${pair.what} of its own ${pair.when}. Write ${pair.text}, or set ${pair.switch} to false.`,
563
+ });
564
+ }
565
+ return findings;
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
+ }
341
690
  return findings;
342
691
  }