@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/README.md +17 -7
- package/dist/commands/api.js +40 -36
- package/dist/commands/chat.js +177 -0
- package/dist/commands/docs.js +62 -5
- package/dist/commands/fmt.js +5 -2
- package/dist/commands/index.js +3 -0
- package/dist/commands/init.js +38 -26
- package/dist/commands/inventory.js +21 -0
- package/dist/commands/limits-set.js +9 -6
- package/dist/commands/loops.js +15 -9
- package/dist/commands/models.js +9 -6
- package/dist/commands/sandboxes.js +8 -4
- package/dist/commands/schema.js +216 -48
- package/dist/commands/session.js +81 -13
- package/dist/commands/setup.js +22 -6
- package/dist/commands/solution.js +318 -66
- package/dist/commands/tenants.js +37 -6
- package/dist/commands/values.js +18 -9
- package/dist/commands/work.js +110 -23
- package/dist/confirm-token.js +72 -0
- package/dist/harness-ref.js +14 -1
- package/dist/kit-codes.js +7 -1
- package/dist/local-state.js +28 -10
- package/dist/main.js +36 -1
- package/dist/mcp.js +63 -14
- package/dist/openapi.js +30 -0
- package/dist/package-check.js +177 -17
- package/dist/package-files.js +75 -39
- package/dist/package-format.js +81 -8
- package/dist/package-references.js +77 -10
- package/dist/results.js +21 -1
- package/dist/skills/cavelon-authoring/SKILL.md +47 -18
- package/dist/skills/cavelon-loop/SKILL.md +91 -27
- package/dist/skills/cavelon-testing/SKILL.md +69 -16
- package/dist/tenant-choice.js +19 -0
- package/dist/trace-view.js +172 -0
- package/package.json +1 -1
package/dist/package-files.js
CHANGED
|
@@ -3,8 +3,8 @@ import path from "node:path";
|
|
|
3
3
|
import { LineCounter, parseDocument } from "yaml";
|
|
4
4
|
import { CavelonError, ExitCode } from "./errors.js";
|
|
5
5
|
import { readTextFile, withoutBom, writeFileAtomic } from "./fsutil.js";
|
|
6
|
-
import { PERSONA_SECTION, sameSectionValue, sectionContent, sectionFields, toYaml
|
|
7
|
-
export { toYaml };
|
|
6
|
+
import { canonical, PERSONA_SECTION, sameEntry, sameSectionValue, sectionContent, sectionFields, toYaml } from "./package-format.js";
|
|
7
|
+
export { canonical, toYaml };
|
|
8
8
|
export const DEFAULT_LAYOUT = { package: "package", items: {} };
|
|
9
9
|
const PACKAGE_FILE = /\.(ya?ml|json)$/i;
|
|
10
10
|
export function layoutFrom(raw) {
|
|
@@ -36,6 +36,15 @@ export function defaultLayoutFor(schema) {
|
|
|
36
36
|
export function schemaSections(schema) {
|
|
37
37
|
return Object.keys(schema?.properties ?? {});
|
|
38
38
|
}
|
|
39
|
+
const SCOPE_KEY = "x-cavelon-scope";
|
|
40
|
+
const TENANT_WIDE_UNMARKED = ["tenant_settings", "model_registry"];
|
|
41
|
+
export function tenantWideSections(schema) {
|
|
42
|
+
const properties = (schema?.properties ?? {});
|
|
43
|
+
const marked = Object.entries(properties).filter(([, node]) => node && typeof node[SCOPE_KEY] === "string");
|
|
44
|
+
if (marked.length)
|
|
45
|
+
return new Set(marked.filter(([, node]) => node[SCOPE_KEY] === "tenant").map(([section]) => section));
|
|
46
|
+
return new Set(TENANT_WIDE_UNMARKED.filter((section) => section in properties));
|
|
47
|
+
}
|
|
39
48
|
function rel(root, file) {
|
|
40
49
|
return path.relative(root, file).split(path.sep).join("/");
|
|
41
50
|
}
|
|
@@ -115,7 +124,7 @@ function parseFile(root, file, text) {
|
|
|
115
124
|
code: "package_file_invalid",
|
|
116
125
|
severity: "error",
|
|
117
126
|
file: relative,
|
|
118
|
-
line: first.linePos?.[0]?.line,
|
|
127
|
+
line: first.linePos?.[0]?.line ?? (typeof first.pos?.[0] === "number" ? lines.linePos(first.pos[0]).line : undefined),
|
|
119
128
|
message: `Not valid YAML: ${first.message.split("\n")[0]}`,
|
|
120
129
|
},
|
|
121
130
|
};
|
|
@@ -126,6 +135,7 @@ export async function readPackage(root, layout) {
|
|
|
126
135
|
const pkg = {};
|
|
127
136
|
const sources = {};
|
|
128
137
|
const findings = [];
|
|
138
|
+
const unreadable = new Set();
|
|
129
139
|
const dir = path.join(root, layout.package);
|
|
130
140
|
let empty = true;
|
|
131
141
|
for (const name of await listFiles(dir)) {
|
|
@@ -144,6 +154,7 @@ export async function readPackage(root, layout) {
|
|
|
144
154
|
if ("finding" in read) {
|
|
145
155
|
sources[section] = { file: rel(root, file) };
|
|
146
156
|
findings.push(read.finding);
|
|
157
|
+
unreadable.add(section);
|
|
147
158
|
empty = false;
|
|
148
159
|
continue;
|
|
149
160
|
}
|
|
@@ -152,8 +163,10 @@ export async function readPackage(root, layout) {
|
|
|
152
163
|
if (!parsed.finding && section === PERSONA_SECTION && (parsed.value === null || parsed.value === undefined))
|
|
153
164
|
continue;
|
|
154
165
|
empty = false;
|
|
155
|
-
if (parsed.finding)
|
|
166
|
+
if (parsed.finding) {
|
|
156
167
|
findings.push(parsed.finding);
|
|
168
|
+
unreadable.add(section);
|
|
169
|
+
}
|
|
157
170
|
else
|
|
158
171
|
pkg[section] = parsed.value;
|
|
159
172
|
}
|
|
@@ -181,21 +194,23 @@ export async function readPackage(root, layout) {
|
|
|
181
194
|
const file = path.join(itemDir, name);
|
|
182
195
|
const read = await readSource(root, file);
|
|
183
196
|
if ("finding" in read) {
|
|
184
|
-
itemSources.push({ file: rel(root, file) });
|
|
185
197
|
findings.push(read.finding);
|
|
198
|
+
unreadable.add(section);
|
|
186
199
|
continue;
|
|
187
200
|
}
|
|
188
201
|
const parsed = parseFile(root, file, read.text);
|
|
189
|
-
|
|
190
|
-
if (parsed.finding)
|
|
202
|
+
if (parsed.finding) {
|
|
191
203
|
findings.push(parsed.finding);
|
|
192
|
-
|
|
193
|
-
|
|
204
|
+
unreadable.add(section);
|
|
205
|
+
continue;
|
|
206
|
+
}
|
|
207
|
+
itemSources.push(parsed.source);
|
|
208
|
+
items.push(parsed.value);
|
|
194
209
|
}
|
|
195
210
|
sources[section] = itemSources;
|
|
196
211
|
pkg[section] = items;
|
|
197
212
|
}
|
|
198
|
-
return { package: pkg, sources, findings, empty };
|
|
213
|
+
return { package: pkg, sources, findings, empty, unreadable: [...unreadable] };
|
|
199
214
|
}
|
|
200
215
|
export function locate(disk, pointer) {
|
|
201
216
|
const keys = pointer
|
|
@@ -239,14 +254,6 @@ function lineOf(source, keys) {
|
|
|
239
254
|
export function safeSectionName(section) {
|
|
240
255
|
return /^[A-Za-z0-9][A-Za-z0-9_.-]{0,99}$/.test(section) && !section.includes("..");
|
|
241
256
|
}
|
|
242
|
-
export function canonical(value) {
|
|
243
|
-
return JSON.stringify(value, (_key, v) => {
|
|
244
|
-
if (v && typeof v === "object" && !Array.isArray(v)) {
|
|
245
|
-
return Object.fromEntries(Object.entries(v).sort(([a], [b]) => (a < b ? -1 : a > b ? 1 : 0)));
|
|
246
|
-
}
|
|
247
|
-
return v;
|
|
248
|
-
});
|
|
249
|
-
}
|
|
250
257
|
async function readValue(root, file) {
|
|
251
258
|
const target = await contentPath(root, file);
|
|
252
259
|
const text = target === undefined ? undefined : await readTextFile(target);
|
|
@@ -267,9 +274,12 @@ export async function placeholdersOnly(root, relative) {
|
|
|
267
274
|
const old = await readValue(root, path.join(root, relative));
|
|
268
275
|
return old.ok && (old.value === null || old.value === undefined);
|
|
269
276
|
}
|
|
270
|
-
function
|
|
277
|
+
export function entryLabel(item) {
|
|
271
278
|
const record = item && typeof item === "object" && !Array.isArray(item) ? item : {};
|
|
272
|
-
|
|
279
|
+
return [record.slug, record.name, record.key].find((v) => typeof v === "string" && v.trim() !== "");
|
|
280
|
+
}
|
|
281
|
+
function itemFileName(item, index, taken) {
|
|
282
|
+
const label = entryLabel(item);
|
|
273
283
|
const base = trimDashesAndDots((label ?? `item-${index + 1}`)
|
|
274
284
|
.toLowerCase()
|
|
275
285
|
.normalize("NFKD")
|
|
@@ -283,7 +293,8 @@ function itemFileName(item, index, taken) {
|
|
|
283
293
|
}
|
|
284
294
|
export async function writePackage(root, layout, pkg, schema, options = {}) {
|
|
285
295
|
const dryRun = options.dryRun === true;
|
|
286
|
-
const
|
|
296
|
+
const skip = options.skip ?? new Set();
|
|
297
|
+
const report = { written: [], unchanged: [], removed: [], kept: [], refused: [], tenant_wide: [] };
|
|
287
298
|
const known = new Set(schemaSections(schema));
|
|
288
299
|
const required = new Set(schema?.required ?? []);
|
|
289
300
|
const dir = path.join(root, layout.package);
|
|
@@ -297,6 +308,10 @@ export async function writePackage(root, layout, pkg, schema, options = {}) {
|
|
|
297
308
|
if (!(PERSONA_SECTION in pkg) && sectionFields(schema, PERSONA_SECTION))
|
|
298
309
|
sections.push([PERSONA_SECTION, null]);
|
|
299
310
|
for (const [section, value] of sections) {
|
|
311
|
+
if (skip.has(section)) {
|
|
312
|
+
report.tenant_wide.push(section);
|
|
313
|
+
continue;
|
|
314
|
+
}
|
|
300
315
|
if (section in layout.items && Array.isArray(value))
|
|
301
316
|
continue;
|
|
302
317
|
if (!safeSectionName(section)) {
|
|
@@ -306,42 +321,58 @@ export async function writePackage(root, layout, pkg, schema, options = {}) {
|
|
|
306
321
|
const current = existing.get(section);
|
|
307
322
|
const file = path.join(dir, current ?? `${section}.yaml`);
|
|
308
323
|
const old = await readValue(root, file);
|
|
309
|
-
if (old.ok && sameSectionValue(section, old.value, value,
|
|
324
|
+
if (old.ok && sameSectionValue(section, old.value, value, schema))
|
|
310
325
|
same.push({ file, section });
|
|
311
326
|
else
|
|
312
327
|
plans.push({ file, section, content: sectionContent(section, value, schema, /\.json$/i.test(file)) });
|
|
313
328
|
}
|
|
314
329
|
for (const [section, folder] of Object.entries(layout.items)) {
|
|
315
330
|
const value = pkg[section];
|
|
316
|
-
if (!Array.isArray(value))
|
|
331
|
+
if (!Array.isArray(value) || skip.has(section))
|
|
317
332
|
continue;
|
|
318
333
|
const itemDir = path.join(root, folder);
|
|
334
|
+
const names = await listFiles(itemDir);
|
|
319
335
|
const before = new Map();
|
|
320
|
-
for (const name of
|
|
336
|
+
for (const name of names) {
|
|
321
337
|
const old = await readValue(root, path.join(itemDir, name));
|
|
322
338
|
if (old.ok)
|
|
323
339
|
before.set(name, old.value);
|
|
324
340
|
}
|
|
325
341
|
const taken = new Set();
|
|
326
|
-
const
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
342
|
+
const claim = (name) => {
|
|
343
|
+
taken.add(name);
|
|
344
|
+
return name;
|
|
345
|
+
};
|
|
346
|
+
const holding = value.map((item) => {
|
|
347
|
+
const name = [...before].find(([name, old]) => !taken.has(name) && sameEntry(section, old, item, schema))?.[0];
|
|
348
|
+
return name && claim(name);
|
|
349
|
+
});
|
|
350
|
+
const recorded = options.itemFiles?.[section] ?? {};
|
|
351
|
+
const home = value.map((item, index) => {
|
|
352
|
+
if (holding[index])
|
|
353
|
+
return holding[index];
|
|
354
|
+
const label = entryLabel(item);
|
|
355
|
+
if (label === undefined)
|
|
356
|
+
return undefined;
|
|
357
|
+
const byName = [...before].find(([name, old]) => !taken.has(name) && entryLabel(old) === label)?.[0];
|
|
358
|
+
if (byName)
|
|
359
|
+
return claim(byName);
|
|
360
|
+
const last = recorded[label];
|
|
361
|
+
return last && !taken.has(last) && names.includes(last) && !before.has(last) ? claim(last) : undefined;
|
|
336
362
|
});
|
|
363
|
+
const placedHere = {};
|
|
337
364
|
value.forEach((item, index) => {
|
|
338
|
-
const name =
|
|
339
|
-
|
|
365
|
+
const name = home[index] ?? itemFileName(item, index, taken);
|
|
366
|
+
const label = entryLabel(item);
|
|
367
|
+
if (label !== undefined)
|
|
368
|
+
placedHere[label] = name;
|
|
369
|
+
if (holding[index])
|
|
340
370
|
same.push({ file: path.join(itemDir, name), section });
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
plans.push({ file: path.join(itemDir, itemFileName(item, index, taken)), section, content: toYaml(item) });
|
|
371
|
+
else
|
|
372
|
+
plans.push({ file: path.join(itemDir, name), section, content: toYaml(item) });
|
|
344
373
|
});
|
|
374
|
+
if (options.placed)
|
|
375
|
+
options.placed[section] = placedHere;
|
|
345
376
|
for (const name of before.keys())
|
|
346
377
|
if (!taken.has(name))
|
|
347
378
|
removals.push(path.join(itemDir, name));
|
|
@@ -349,6 +380,11 @@ export async function writePackage(root, layout, pkg, schema, options = {}) {
|
|
|
349
380
|
await fs.mkdir(itemDir, { recursive: true });
|
|
350
381
|
}
|
|
351
382
|
for (const [section, name] of existing) {
|
|
383
|
+
if (skip.has(section)) {
|
|
384
|
+
if (!report.tenant_wide.includes(section))
|
|
385
|
+
report.tenant_wide.push(section);
|
|
386
|
+
continue;
|
|
387
|
+
}
|
|
352
388
|
if (section in pkg || section === PERSONA_SECTION)
|
|
353
389
|
continue;
|
|
354
390
|
const file = path.join(dir, name);
|
package/dist/package-format.js
CHANGED
|
@@ -59,13 +59,43 @@ export function sectionFields(schema, section) {
|
|
|
59
59
|
return undefined;
|
|
60
60
|
return Object.fromEntries(Object.entries(props).map(([k, v]) => [k, resolve(schema, v) ?? {}]));
|
|
61
61
|
}
|
|
62
|
-
export function
|
|
62
|
+
export function canonical(value) {
|
|
63
|
+
return JSON.stringify(value, (_key, v) => {
|
|
64
|
+
if (v && typeof v === "object" && !Array.isArray(v)) {
|
|
65
|
+
return Object.fromEntries(Object.entries(v).sort(([a], [b]) => (a < b ? -1 : a > b ? 1 : 0)));
|
|
66
|
+
}
|
|
67
|
+
return v;
|
|
68
|
+
});
|
|
69
|
+
}
|
|
70
|
+
const requiredOf = (shape) => new Set(Array.isArray(shape?.required) ? shape.required : []);
|
|
71
|
+
function nullable(schema, field) {
|
|
72
|
+
if (field.type === "null" || (Array.isArray(field.type) && field.type.includes("null")))
|
|
73
|
+
return true;
|
|
74
|
+
return branches(schema, field).some((b) => b.type === "null");
|
|
75
|
+
}
|
|
76
|
+
function implicitDefault(schema, key, sub, required, position) {
|
|
77
|
+
const field = resolve(schema, sub);
|
|
78
|
+
if (!field || required.has(key))
|
|
79
|
+
return undefined;
|
|
80
|
+
if (position !== undefined && key.endsWith("_order") && field.type === "integer" && typeof field.default === "number")
|
|
81
|
+
return field.default + position;
|
|
82
|
+
if (field.default !== undefined)
|
|
83
|
+
return field.default === null ? undefined : field.default;
|
|
84
|
+
if (nullable(schema, field))
|
|
85
|
+
return undefined;
|
|
86
|
+
if (field.type === "array")
|
|
87
|
+
return [];
|
|
88
|
+
if (field.type === "object" || propertiesOf(field))
|
|
89
|
+
return {};
|
|
90
|
+
return undefined;
|
|
91
|
+
}
|
|
92
|
+
export function exportForm(schema, node, value, depth = 0, position) {
|
|
63
93
|
const resolved = resolve(schema, node);
|
|
64
94
|
if (!resolved || depth > 40)
|
|
65
95
|
return value;
|
|
66
96
|
if (Array.isArray(value)) {
|
|
67
97
|
const array = arrayBranch(schema, resolved);
|
|
68
|
-
return array?.items ? value.map((item) => exportForm(schema, array.items, item, depth + 1)) : value;
|
|
98
|
+
return array?.items ? value.map((item, i) => exportForm(schema, array.items, item, depth + 1, i)) : value;
|
|
69
99
|
}
|
|
70
100
|
if (!isObject(value))
|
|
71
101
|
return value;
|
|
@@ -73,13 +103,14 @@ export function exportForm(schema, node, value, depth = 0) {
|
|
|
73
103
|
const props = propertiesOf(object);
|
|
74
104
|
if (!props)
|
|
75
105
|
return value;
|
|
106
|
+
const required = requiredOf(object);
|
|
76
107
|
const out = {};
|
|
77
108
|
for (const [key, sub] of Object.entries(props)) {
|
|
78
109
|
if (key in value)
|
|
79
110
|
out[key] = exportForm(schema, sub, value[key], depth + 1);
|
|
80
111
|
else {
|
|
81
|
-
const fallback =
|
|
82
|
-
if (fallback !== undefined
|
|
112
|
+
const fallback = implicitDefault(schema, key, sub, required, position);
|
|
113
|
+
if (fallback !== undefined)
|
|
83
114
|
out[key] = structuredClone(fallback);
|
|
84
115
|
}
|
|
85
116
|
}
|
|
@@ -110,12 +141,54 @@ export function withoutNulls(value) {
|
|
|
110
141
|
function isEmpty(value) {
|
|
111
142
|
return value === null || value === undefined || (isObject(value) && Object.keys(value).length === 0);
|
|
112
143
|
}
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
const
|
|
144
|
+
const isUnset = (value) => isEmpty(value) || (Array.isArray(value) && value.length === 0);
|
|
145
|
+
export function settledForm(schema, node, value, depth = 0) {
|
|
146
|
+
const resolved = resolve(schema, node);
|
|
147
|
+
if (!resolved || depth > 40)
|
|
148
|
+
return withoutNulls(value);
|
|
149
|
+
if (Array.isArray(value)) {
|
|
150
|
+
const array = arrayBranch(schema, resolved);
|
|
151
|
+
return array?.items ? value.map((item) => settledForm(schema, array.items, item, depth + 1)) : withoutNulls(value);
|
|
152
|
+
}
|
|
153
|
+
if (!isObject(value))
|
|
154
|
+
return value;
|
|
155
|
+
const object = objectBranch(schema, resolved, value);
|
|
156
|
+
const props = propertiesOf(object);
|
|
157
|
+
if (!props)
|
|
158
|
+
return withoutNulls(value);
|
|
159
|
+
const required = requiredOf(object);
|
|
160
|
+
const out = {};
|
|
161
|
+
for (const [key, inner] of Object.entries(value)) {
|
|
162
|
+
if (!(key in props)) {
|
|
163
|
+
if (inner !== null)
|
|
164
|
+
out[key] = withoutNulls(inner);
|
|
165
|
+
continue;
|
|
166
|
+
}
|
|
167
|
+
const settled = settledForm(schema, props[key], inner, depth + 1);
|
|
168
|
+
if (!required.has(key)) {
|
|
169
|
+
const fallback = implicitDefault(schema, key, props[key], required, undefined);
|
|
170
|
+
if (isUnset(settled) && (fallback === undefined || isUnset(fallback)))
|
|
171
|
+
continue;
|
|
172
|
+
if (fallback !== undefined && canonical(settled) === canonical(settledForm(schema, props[key], fallback, depth + 1)))
|
|
173
|
+
continue;
|
|
174
|
+
}
|
|
175
|
+
out[key] = settled;
|
|
176
|
+
}
|
|
177
|
+
return out;
|
|
178
|
+
}
|
|
179
|
+
export function sameSectionValue(section, a, b, schema = null) {
|
|
180
|
+
const node = schema?.properties?.[section];
|
|
181
|
+
const left = schema && node ? settledForm(schema, node, a) : withoutNulls(a);
|
|
182
|
+
const right = schema && node ? settledForm(schema, node, b) : withoutNulls(b);
|
|
116
183
|
if (section === PERSONA_SECTION && isEmpty(left) && isEmpty(right))
|
|
117
184
|
return true;
|
|
118
|
-
return
|
|
185
|
+
return canonical(left) === canonical(right);
|
|
186
|
+
}
|
|
187
|
+
export function sameEntry(section, a, b, schema = null) {
|
|
188
|
+
const node = schema?.properties?.[section];
|
|
189
|
+
if (!schema || !node)
|
|
190
|
+
return canonical(withoutNulls(a)) === canonical(withoutNulls(b));
|
|
191
|
+
return canonical(settledForm(schema, node, [a])) === canonical(settledForm(schema, node, [b]));
|
|
119
192
|
}
|
|
120
193
|
function placeholder(key, field) {
|
|
121
194
|
const fallback = field.default !== undefined ? field.default : field.type === "array" ? [] : null;
|
|
@@ -5,6 +5,8 @@ export const REFERENCE_UNKNOWN_CODE = "package_reference_unknown";
|
|
|
5
5
|
export const FIELD_UNKNOWN_CODE = "package_field_unknown";
|
|
6
6
|
export const MODEL_UNKNOWN_CODE = "package_model_unknown";
|
|
7
7
|
export const SEARCH_TOOL_KEYS = new Set(["search_documents", "search_knowledge_base", "search_kb"]);
|
|
8
|
+
export const KNOWLEDGE_TOOL_KEYS = new Set([...SEARCH_TOOL_KEYS, "list_documents", "list_kb_docs"]);
|
|
9
|
+
const DOCUMENT_TOOL_KEYS = new Set([...KNOWLEDGE_TOOL_KEYS, "read_document", "save_document"]);
|
|
8
10
|
const asObject = (v) => (v && typeof v === "object" && !Array.isArray(v) ? v : undefined);
|
|
9
11
|
const list = (v) => (Array.isArray(v) ? v.map(asObject) : []);
|
|
10
12
|
const text = (v) => (typeof v === "string" && v !== "" ? v : undefined);
|
|
@@ -26,18 +28,29 @@ export function closest(word, candidates, preferred = []) {
|
|
|
26
28
|
if (d <= allowance && (!best || d < best.d))
|
|
27
29
|
best = { name, d };
|
|
28
30
|
};
|
|
29
|
-
|
|
31
|
+
const names = [...candidates];
|
|
32
|
+
const wanted = [...preferred];
|
|
33
|
+
for (const name of wanted)
|
|
30
34
|
consider(name, Math.ceil(Math.max(word.length, name.length) / 2));
|
|
31
|
-
for (const name of
|
|
35
|
+
for (const name of names)
|
|
32
36
|
consider(name, typoAllowance(word));
|
|
33
|
-
|
|
37
|
+
if (best)
|
|
38
|
+
return best.name;
|
|
39
|
+
const lower = word.toLowerCase();
|
|
40
|
+
if (lower.length < 4)
|
|
41
|
+
return undefined;
|
|
42
|
+
const related = [...wanted, ...names].filter((name) => {
|
|
43
|
+
const other = name.toLowerCase();
|
|
44
|
+
return other !== lower && (other.startsWith(lower) || lower.startsWith(other) || other.includes(lower)) && Math.min(other.length, lower.length) >= 4;
|
|
45
|
+
});
|
|
46
|
+
return related.sort((a, b) => Math.abs(a.length - word.length) - Math.abs(b.length - word.length))[0];
|
|
34
47
|
}
|
|
35
48
|
const typoAllowance = (word) => Math.max(2, Math.floor(word.length / 3));
|
|
36
49
|
const didYouMean = (name) => (name ? ` Did you mean "${name}"?` : "");
|
|
37
50
|
const suggested = (message, suggestion) => ({ message: message + didYouMean(suggestion), ...(suggestion ? { suggestion } : {}) });
|
|
38
51
|
const AGENT = { label: "agent", section: "agents", key: "slug" };
|
|
39
52
|
const SKILL = { label: "skill", section: "skills", key: "slug", inventory: "skills" };
|
|
40
|
-
const TOOL = { label: "tool", section: "tools", key: "slug", inventory: "tools", builtin:
|
|
53
|
+
const TOOL = { label: "tool", section: "tools", key: "slug", inventory: "tools", builtin: DOCUMENT_TOOL_KEYS };
|
|
41
54
|
const KNOWLEDGE_BASE = { label: "knowledge base", section: "knowledge_bases", key: "name", inventory: "knowledge_bases" };
|
|
42
55
|
const SOLUTION = { label: "solution", section: "harnesses", key: "slug", inventory: "solutions" };
|
|
43
56
|
const KEYED = [AGENT, SKILL, TOOL, KNOWLEDGE_BASE, SOLUTION, { label: "guardrail", section: "guardrails", key: "slug" }];
|
|
@@ -48,12 +61,19 @@ const INVENTORY_LABEL = {
|
|
|
48
61
|
skills: "skills",
|
|
49
62
|
models: "models",
|
|
50
63
|
};
|
|
64
|
+
const ASSERTION_TARGETS = {
|
|
65
|
+
answered_by: { target: AGENT, field: "value" },
|
|
66
|
+
handoff_to: { target: AGENT, field: "value" },
|
|
67
|
+
tool_called: { target: TOOL, field: "value" },
|
|
68
|
+
tool_not_called: { target: TOOL, field: "value" },
|
|
69
|
+
min_results: { target: TOOL, field: "tool" },
|
|
70
|
+
};
|
|
51
71
|
function references(pkg) {
|
|
52
72
|
const found = [];
|
|
53
|
-
const add = (pointer, from, value, target) => {
|
|
73
|
+
const add = (pointer, from, value, target, how) => {
|
|
54
74
|
const name = text(value);
|
|
55
75
|
if (name)
|
|
56
|
-
found.push({ pointer, from, name, target });
|
|
76
|
+
found.push({ pointer, from, name, target, ...(how ? { how } : {}) });
|
|
57
77
|
};
|
|
58
78
|
list(pkg.agents).forEach((agent, i) => {
|
|
59
79
|
if (!agent)
|
|
@@ -71,6 +91,21 @@ function references(pkg) {
|
|
|
71
91
|
list(skill.knowledge_base_assignments).forEach((a, j) => add(`/skills/${i}/knowledge_base_assignments/${j}/knowledge_base_name`, from, a?.knowledge_base_name, KNOWLEDGE_BASE));
|
|
72
92
|
list(skill.tool_assignments).forEach((a, j) => add(`/skills/${i}/tool_assignments/${j}/tool_slug`, from, a?.tool_slug, TOOL));
|
|
73
93
|
});
|
|
94
|
+
list(pkg.test_suites).forEach((suite, s) => {
|
|
95
|
+
list(suite?.test_cases).forEach((testCase, c) => {
|
|
96
|
+
const from = `The test case "${text(testCase?.name) ?? c}"${text(suite?.name) ? ` of the suite "${suite.name}"` : ""}`;
|
|
97
|
+
list(testCase?.steps).forEach((step, t) => {
|
|
98
|
+
list(step?.evaluation_criteria).forEach((criterion, k) => {
|
|
99
|
+
const type = text(criterion?.type);
|
|
100
|
+
const named = type !== undefined && Object.hasOwn(ASSERTION_TARGETS, type) ? ASSERTION_TARGETS[type] : undefined;
|
|
101
|
+
if (!named)
|
|
102
|
+
return;
|
|
103
|
+
const pointer = `/test_suites/${s}/test_cases/${c}/steps/${t}/evaluation_criteria/${k}/${named.field}`;
|
|
104
|
+
add(pointer, from, criterion[named.field], named.target, `checks ${type}`);
|
|
105
|
+
});
|
|
106
|
+
});
|
|
107
|
+
});
|
|
108
|
+
});
|
|
74
109
|
return found;
|
|
75
110
|
}
|
|
76
111
|
function keysIn(pkg, target) {
|
|
@@ -82,6 +117,7 @@ function pulledAt(inventory, kind) {
|
|
|
82
117
|
export function checkReferences(disk, inventory) {
|
|
83
118
|
const pkg = disk.package;
|
|
84
119
|
const findings = [];
|
|
120
|
+
const unreadable = new Set(disk.unreadable ?? []);
|
|
85
121
|
for (const target of KEYED) {
|
|
86
122
|
const seen = new Map();
|
|
87
123
|
list(pkg[target.section]).forEach((entry, i) => {
|
|
@@ -104,16 +140,20 @@ export function checkReferences(disk, inventory) {
|
|
|
104
140
|
}
|
|
105
141
|
for (const ref of references(pkg)) {
|
|
106
142
|
const { target } = ref;
|
|
143
|
+
if (unreadable.has(target.section))
|
|
144
|
+
continue;
|
|
107
145
|
const inPackage = keysIn(pkg, target);
|
|
108
146
|
if (inPackage.includes(ref.name) || target.builtin?.has(ref.name))
|
|
109
147
|
continue;
|
|
110
148
|
const tenant = target.inventory ? inventory?.names[target.inventory] : undefined;
|
|
111
149
|
if (target === AGENT) {
|
|
150
|
+
if (ref.how && !Array.isArray(pkg.agents))
|
|
151
|
+
continue;
|
|
112
152
|
findings.push({
|
|
113
153
|
code: REFERENCE_MISSING_CODE,
|
|
114
154
|
severity: "error",
|
|
115
155
|
...locate(disk, ref.pointer),
|
|
116
|
-
...suggested(`${ref.from} hands off to the agent "${ref.name}", which is not in the package.`, closest(ref.name, inPackage)),
|
|
156
|
+
...suggested(`${ref.from} ${ref.how ?? "hands off to"} the agent "${ref.name}", which is not in the package.`, closest(ref.name, inPackage)),
|
|
117
157
|
});
|
|
118
158
|
continue;
|
|
119
159
|
}
|
|
@@ -124,8 +164,8 @@ export function checkReferences(disk, inventory) {
|
|
|
124
164
|
code: REFERENCE_UNKNOWN_CODE,
|
|
125
165
|
severity: "warning",
|
|
126
166
|
...locate(disk, ref.pointer),
|
|
127
|
-
...suggested(`${ref.from} names the ${target.label} "${ref.name}", which is neither in the package nor among the tenant's ${kind} ` +
|
|
128
|
-
`at the last pull (${pulledAt(inventory, target.inventory)}).`, closest(ref.name, [...inPackage, ...tenant])),
|
|
167
|
+
...suggested(`${ref.from} ${ref.how ?? "names"} the ${target.label} "${ref.name}", which is neither in the package nor among the tenant's ${kind} ` +
|
|
168
|
+
`at the last pull (${pulledAt(inventory, target.inventory)}).`, closest(ref.name, [...inPackage, ...tenant, ...(target.builtin ?? [])])),
|
|
129
169
|
});
|
|
130
170
|
}
|
|
131
171
|
return findings;
|
|
@@ -140,7 +180,7 @@ function resolve(schema, node) {
|
|
|
140
180
|
}
|
|
141
181
|
return current;
|
|
142
182
|
}
|
|
143
|
-
function branches(schema, node) {
|
|
183
|
+
export function branches(schema, node) {
|
|
144
184
|
const resolved = resolve(schema, node);
|
|
145
185
|
if (!resolved)
|
|
146
186
|
return [];
|
|
@@ -190,6 +230,9 @@ export function checkUnknownFields(disk, schema, schemaFindings = []) {
|
|
|
190
230
|
if (required) {
|
|
191
231
|
required.message += ` ("${key}" is set, which the package schema does not have; did you mean "${suggestion}"?)`;
|
|
192
232
|
required.suggestion = suggestion;
|
|
233
|
+
const misspelt = locate(disk, at);
|
|
234
|
+
if (misspelt.line !== undefined && misspelt.file === required.file)
|
|
235
|
+
required.line = misspelt.line;
|
|
193
236
|
continue;
|
|
194
237
|
}
|
|
195
238
|
const where = locate(disk, at);
|
|
@@ -213,6 +256,8 @@ export function checkModels(disk, inventory) {
|
|
|
213
256
|
const tenant = inventory?.names.models;
|
|
214
257
|
if (!Array.isArray(tenant) || !tenant.length)
|
|
215
258
|
return [];
|
|
259
|
+
if (disk.unreadable?.includes("model_registry"))
|
|
260
|
+
return [];
|
|
216
261
|
const known = new Set([...tenant, ...list(disk.package.model_registry).flatMap((row) => (text(row?.model_id) ? [row.model_id] : []))]);
|
|
217
262
|
const findings = [];
|
|
218
263
|
list(disk.package.agents).forEach((agent, i) => {
|
|
@@ -229,3 +274,25 @@ export function checkModels(disk, inventory) {
|
|
|
229
274
|
});
|
|
230
275
|
return findings;
|
|
231
276
|
}
|
|
277
|
+
const CHECKED_BY = {
|
|
278
|
+
solutions: "the solutions the package names",
|
|
279
|
+
knowledge_bases: "the knowledge bases the package names",
|
|
280
|
+
tools: "the tools the package names",
|
|
281
|
+
skills: "the skills the package names",
|
|
282
|
+
models: "the agents' models",
|
|
283
|
+
};
|
|
284
|
+
export const checkedBy = (kind) => CHECKED_BY[kind];
|
|
285
|
+
export function missingInventory(disk, inventory) {
|
|
286
|
+
const needed = new Set();
|
|
287
|
+
const pkg = disk.package;
|
|
288
|
+
for (const ref of references(pkg)) {
|
|
289
|
+
const kind = ref.target.inventory;
|
|
290
|
+
if (!kind || keysIn(pkg, ref.target).includes(ref.name) || ref.target.builtin?.has(ref.name))
|
|
291
|
+
continue;
|
|
292
|
+
needed.add(kind);
|
|
293
|
+
}
|
|
294
|
+
const own = new Set(list(pkg.model_registry).flatMap((row) => (text(row?.model_id) ? [row.model_id] : [])));
|
|
295
|
+
if (list(pkg.agents).some((agent) => text(agent?.llm_model) && !own.has(agent.llm_model)))
|
|
296
|
+
needed.add("models");
|
|
297
|
+
return [...needed].filter((kind) => !Array.isArray(inventory?.names[kind]));
|
|
298
|
+
}
|
package/dist/results.js
CHANGED
|
@@ -1,7 +1,19 @@
|
|
|
1
1
|
import { CavelonError } from "./errors.js";
|
|
2
2
|
import { clip } from "./format.js";
|
|
3
|
+
import { failedAssertions } from "./trace-view.js";
|
|
3
4
|
import { callStable } from "./invoke.js";
|
|
4
5
|
import { cavelonCommand } from "./shell.js";
|
|
6
|
+
export function caseKnowledgeOutcomes(r) {
|
|
7
|
+
if (!Array.isArray(r.tool_calls))
|
|
8
|
+
return null;
|
|
9
|
+
const outcomes = [];
|
|
10
|
+
for (const row of r.tool_calls) {
|
|
11
|
+
const outcome = row && typeof row === "object" ? row.knowledge_outcome : undefined;
|
|
12
|
+
if (typeof outcome === "string" && outcome && !outcomes.includes(outcome))
|
|
13
|
+
outcomes.push(outcome);
|
|
14
|
+
}
|
|
15
|
+
return outcomes.length ? outcomes : null;
|
|
16
|
+
}
|
|
5
17
|
export const NOT_PASSED = new Set(["fail", "error"]);
|
|
6
18
|
export function caseCounts(summary) {
|
|
7
19
|
return { failed: summaryCount(summary, "failed"), errors: summaryCount(summary, "errors") };
|
|
@@ -92,6 +104,7 @@ function explainedStatuses(counts) {
|
|
|
92
104
|
}
|
|
93
105
|
const MAX_CASES = 5;
|
|
94
106
|
const REASON_CHARS = 500;
|
|
107
|
+
const ANSWER_CHARS = 200;
|
|
95
108
|
export function failedCase(r, max = REASON_CHARS) {
|
|
96
109
|
const reason = r.error_message ?? r.llm_judge_reasoning ?? null;
|
|
97
110
|
return {
|
|
@@ -100,6 +113,8 @@ export function failedCase(r, max = REASON_CHARS) {
|
|
|
100
113
|
status: r.status,
|
|
101
114
|
reason: reason ? clip(reason, max) : null,
|
|
102
115
|
run_id: r.agent_run_id ?? null,
|
|
116
|
+
failed_assertions: failedAssertions(r.judge_breakdown),
|
|
117
|
+
answer: r.generated_answer ? clip(r.generated_answer.replace(/\s+/g, " ").trim(), ANSWER_CHARS) : null,
|
|
103
118
|
};
|
|
104
119
|
}
|
|
105
120
|
export async function resultFailure(ctx, op) {
|
|
@@ -150,8 +165,13 @@ export function failureLines(failure) {
|
|
|
150
165
|
];
|
|
151
166
|
if (failure.comparable === false && failure.non_comparable_reasons.length)
|
|
152
167
|
lines.push(` Not comparable: ${failure.non_comparable_reasons.join(", ")}`);
|
|
153
|
-
for (const c of failure.cases)
|
|
168
|
+
for (const c of failure.cases) {
|
|
154
169
|
lines.push(` ${caseLabel(c)} ${c.status}${c.reason ? ": " + c.reason : ""}`);
|
|
170
|
+
if (c.failed_assertions.length)
|
|
171
|
+
lines.push(` failed: ${c.failed_assertions.join(", ")}`);
|
|
172
|
+
if (c.answer)
|
|
173
|
+
lines.push(` answer: ${c.answer}`);
|
|
174
|
+
}
|
|
155
175
|
const shown = failure.cases.length;
|
|
156
176
|
const total = failure.failed_cases + failure.errored_cases + WAITING_COUNTS.reduce((sum, key) => sum + (failure.counts[key] ?? 0), 0);
|
|
157
177
|
if (total > shown)
|