@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.
- package/README.md +58 -22
- package/dist/choose.js +8 -4
- package/dist/code-hints.js +74 -0
- package/dist/commands/api.js +83 -44
- package/dist/commands/async.js +26 -5
- package/dist/commands/chat.js +177 -0
- package/dist/commands/docs.js +240 -37
- package/dist/commands/fmt.js +120 -0
- package/dist/commands/index.js +9 -1
- package/dist/commands/init.js +64 -30
- package/dist/commands/inventory.js +48 -5
- package/dist/commands/limits-set.js +9 -6
- package/dist/commands/loops.js +15 -9
- package/dist/commands/models.js +16 -7
- package/dist/commands/sandboxes.js +8 -4
- package/dist/commands/schema.js +361 -0
- package/dist/commands/session.js +148 -24
- package/dist/commands/setup.js +22 -6
- package/dist/commands/solution.js +537 -76
- package/dist/commands/tenants.js +156 -15
- package/dist/commands/values.js +18 -9
- package/dist/commands/work.js +343 -35
- package/dist/confirm-token.js +72 -0
- package/dist/contracts.js +3 -0
- package/dist/default-route.js +21 -0
- package/dist/errors.js +4 -0
- package/dist/git.js +14 -5
- package/dist/harness-ref.js +14 -1
- package/dist/http.js +27 -4
- package/dist/invoke.js +8 -4
- package/dist/kit-codes.js +91 -0
- package/dist/limits.js +12 -1
- package/dist/local-state.js +32 -7
- package/dist/main.js +52 -4
- package/dist/mcp.js +72 -15
- package/dist/openapi.js +77 -21
- package/dist/operations.js +4 -3
- package/dist/package-check.js +361 -12
- package/dist/package-files.js +92 -45
- package/dist/package-format.js +222 -0
- package/dist/package-references.js +298 -0
- package/dist/preview-report.js +152 -0
- package/dist/results.js +21 -1
- package/dist/skills/cavelon-authoring/SKILL.md +98 -13
- package/dist/skills/cavelon-long-running/SKILL.md +3 -1
- package/dist/skills/cavelon-loop/SKILL.md +129 -21
- package/dist/skills/cavelon-testing/SKILL.md +130 -10
- package/dist/tenant-choice.js +31 -5
- package/dist/trace-view.js +172 -0
- package/package.json +1 -1
|
@@ -0,0 +1,298 @@
|
|
|
1
|
+
import { locate } from "./package-files.js";
|
|
2
|
+
export const DUPLICATE_CODE = "package_duplicate_key";
|
|
3
|
+
export const REFERENCE_MISSING_CODE = "package_reference_missing";
|
|
4
|
+
export const REFERENCE_UNKNOWN_CODE = "package_reference_unknown";
|
|
5
|
+
export const FIELD_UNKNOWN_CODE = "package_field_unknown";
|
|
6
|
+
export const MODEL_UNKNOWN_CODE = "package_model_unknown";
|
|
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"]);
|
|
10
|
+
const asObject = (v) => (v && typeof v === "object" && !Array.isArray(v) ? v : undefined);
|
|
11
|
+
const list = (v) => (Array.isArray(v) ? v.map(asObject) : []);
|
|
12
|
+
const text = (v) => (typeof v === "string" && v !== "" ? v : undefined);
|
|
13
|
+
function distance(a, b) {
|
|
14
|
+
let previous = Array.from({ length: b.length + 1 }, (_, j) => j);
|
|
15
|
+
for (let i = 1; i <= a.length; i++) {
|
|
16
|
+
const current = [i];
|
|
17
|
+
for (let j = 1; j <= b.length; j++) {
|
|
18
|
+
current[j] = Math.min(previous[j] + 1, current[j - 1] + 1, previous[j - 1] + (a[i - 1] === b[j - 1] ? 0 : 1));
|
|
19
|
+
}
|
|
20
|
+
previous = current;
|
|
21
|
+
}
|
|
22
|
+
return previous[b.length];
|
|
23
|
+
}
|
|
24
|
+
export function closest(word, candidates, preferred = []) {
|
|
25
|
+
let best;
|
|
26
|
+
const consider = (name, allowance) => {
|
|
27
|
+
const d = distance(word.toLowerCase(), name.toLowerCase());
|
|
28
|
+
if (d <= allowance && (!best || d < best.d))
|
|
29
|
+
best = { name, d };
|
|
30
|
+
};
|
|
31
|
+
const names = [...candidates];
|
|
32
|
+
const wanted = [...preferred];
|
|
33
|
+
for (const name of wanted)
|
|
34
|
+
consider(name, Math.ceil(Math.max(word.length, name.length) / 2));
|
|
35
|
+
for (const name of names)
|
|
36
|
+
consider(name, typoAllowance(word));
|
|
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];
|
|
47
|
+
}
|
|
48
|
+
const typoAllowance = (word) => Math.max(2, Math.floor(word.length / 3));
|
|
49
|
+
const didYouMean = (name) => (name ? ` Did you mean "${name}"?` : "");
|
|
50
|
+
const suggested = (message, suggestion) => ({ message: message + didYouMean(suggestion), ...(suggestion ? { suggestion } : {}) });
|
|
51
|
+
const AGENT = { label: "agent", section: "agents", key: "slug" };
|
|
52
|
+
const SKILL = { label: "skill", section: "skills", key: "slug", inventory: "skills" };
|
|
53
|
+
const TOOL = { label: "tool", section: "tools", key: "slug", inventory: "tools", builtin: DOCUMENT_TOOL_KEYS };
|
|
54
|
+
const KNOWLEDGE_BASE = { label: "knowledge base", section: "knowledge_bases", key: "name", inventory: "knowledge_bases" };
|
|
55
|
+
const SOLUTION = { label: "solution", section: "harnesses", key: "slug", inventory: "solutions" };
|
|
56
|
+
const KEYED = [AGENT, SKILL, TOOL, KNOWLEDGE_BASE, SOLUTION, { label: "guardrail", section: "guardrails", key: "slug" }];
|
|
57
|
+
const INVENTORY_LABEL = {
|
|
58
|
+
solutions: "solutions",
|
|
59
|
+
knowledge_bases: "knowledge bases",
|
|
60
|
+
tools: "tools",
|
|
61
|
+
skills: "skills",
|
|
62
|
+
models: "models",
|
|
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
|
+
};
|
|
71
|
+
function references(pkg) {
|
|
72
|
+
const found = [];
|
|
73
|
+
const add = (pointer, from, value, target, how) => {
|
|
74
|
+
const name = text(value);
|
|
75
|
+
if (name)
|
|
76
|
+
found.push({ pointer, from, name, target, ...(how ? { how } : {}) });
|
|
77
|
+
};
|
|
78
|
+
list(pkg.agents).forEach((agent, i) => {
|
|
79
|
+
if (!agent)
|
|
80
|
+
return;
|
|
81
|
+
const from = `The agent "${text(agent.slug) ?? i}"`;
|
|
82
|
+
add(`/agents/${i}/harness_slug`, from, agent.harness_slug, SOLUTION);
|
|
83
|
+
list(agent.skill_assignments).forEach((a, j) => add(`/agents/${i}/skill_assignments/${j}/skill_slug`, from, a?.skill_slug, SKILL));
|
|
84
|
+
list(agent.tool_assignments).forEach((a, j) => add(`/agents/${i}/tool_assignments/${j}/tool_slug`, from, a?.tool_slug, TOOL));
|
|
85
|
+
list(agent.handoffs).forEach((h, j) => add(`/agents/${i}/handoffs/${j}/to_agent_slug`, from, h?.to_agent_slug, AGENT));
|
|
86
|
+
});
|
|
87
|
+
list(pkg.skills).forEach((skill, i) => {
|
|
88
|
+
if (!skill)
|
|
89
|
+
return;
|
|
90
|
+
const from = `The skill "${text(skill.slug) ?? i}"`;
|
|
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));
|
|
92
|
+
list(skill.tool_assignments).forEach((a, j) => add(`/skills/${i}/tool_assignments/${j}/tool_slug`, from, a?.tool_slug, TOOL));
|
|
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
|
+
});
|
|
109
|
+
return found;
|
|
110
|
+
}
|
|
111
|
+
function keysIn(pkg, target) {
|
|
112
|
+
return list(pkg[target.section]).flatMap((e) => (text(e?.[target.key]) ? [e[target.key]] : []));
|
|
113
|
+
}
|
|
114
|
+
function pulledAt(inventory, kind) {
|
|
115
|
+
return inventory.refreshed_at?.[kind] ?? inventory.written_at;
|
|
116
|
+
}
|
|
117
|
+
export function checkReferences(disk, inventory) {
|
|
118
|
+
const pkg = disk.package;
|
|
119
|
+
const findings = [];
|
|
120
|
+
const unreadable = new Set(disk.unreadable ?? []);
|
|
121
|
+
for (const target of KEYED) {
|
|
122
|
+
const seen = new Map();
|
|
123
|
+
list(pkg[target.section]).forEach((entry, i) => {
|
|
124
|
+
const key = text(entry?.[target.key]);
|
|
125
|
+
if (!key)
|
|
126
|
+
return;
|
|
127
|
+
const first = seen.get(key);
|
|
128
|
+
if (first === undefined) {
|
|
129
|
+
seen.set(key, i);
|
|
130
|
+
return;
|
|
131
|
+
}
|
|
132
|
+
const earlier = locate(disk, `/${target.section}/${first}/${target.key}`);
|
|
133
|
+
findings.push({
|
|
134
|
+
code: DUPLICATE_CODE,
|
|
135
|
+
severity: "error",
|
|
136
|
+
...locate(disk, `/${target.section}/${i}/${target.key}`),
|
|
137
|
+
message: `Two ${target.section} have the ${target.key} "${key}" (also ${earlier.file ?? earlier.path}${earlier.line ? `:${earlier.line}` : ""}); the import keeps one of them.`,
|
|
138
|
+
});
|
|
139
|
+
});
|
|
140
|
+
}
|
|
141
|
+
for (const ref of references(pkg)) {
|
|
142
|
+
const { target } = ref;
|
|
143
|
+
if (unreadable.has(target.section))
|
|
144
|
+
continue;
|
|
145
|
+
const inPackage = keysIn(pkg, target);
|
|
146
|
+
if (inPackage.includes(ref.name) || target.builtin?.has(ref.name))
|
|
147
|
+
continue;
|
|
148
|
+
const tenant = target.inventory ? inventory?.names[target.inventory] : undefined;
|
|
149
|
+
if (target === AGENT) {
|
|
150
|
+
if (ref.how && !Array.isArray(pkg.agents))
|
|
151
|
+
continue;
|
|
152
|
+
findings.push({
|
|
153
|
+
code: REFERENCE_MISSING_CODE,
|
|
154
|
+
severity: "error",
|
|
155
|
+
...locate(disk, ref.pointer),
|
|
156
|
+
...suggested(`${ref.from} ${ref.how ?? "hands off to"} the agent "${ref.name}", which is not in the package.`, closest(ref.name, inPackage)),
|
|
157
|
+
});
|
|
158
|
+
continue;
|
|
159
|
+
}
|
|
160
|
+
if (!Array.isArray(tenant) || tenant.includes(ref.name))
|
|
161
|
+
continue;
|
|
162
|
+
const kind = INVENTORY_LABEL[target.inventory];
|
|
163
|
+
findings.push({
|
|
164
|
+
code: REFERENCE_UNKNOWN_CODE,
|
|
165
|
+
severity: "warning",
|
|
166
|
+
...locate(disk, ref.pointer),
|
|
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 ?? [])])),
|
|
169
|
+
});
|
|
170
|
+
}
|
|
171
|
+
return findings;
|
|
172
|
+
}
|
|
173
|
+
function resolve(schema, node) {
|
|
174
|
+
let current = asObject(node);
|
|
175
|
+
for (let i = 0; i < 10 && current && typeof current.$ref === "string"; i++) {
|
|
176
|
+
const ref = current.$ref;
|
|
177
|
+
if (!ref.startsWith("#/$defs/"))
|
|
178
|
+
return undefined;
|
|
179
|
+
current = asObject(schema.$defs?.[ref.slice("#/$defs/".length)]);
|
|
180
|
+
}
|
|
181
|
+
return current;
|
|
182
|
+
}
|
|
183
|
+
export function branches(schema, node) {
|
|
184
|
+
const resolved = resolve(schema, node);
|
|
185
|
+
if (!resolved)
|
|
186
|
+
return [];
|
|
187
|
+
const union = [resolved.anyOf, resolved.oneOf, resolved.allOf].find(Array.isArray);
|
|
188
|
+
return union ? union.flatMap((b) => branches(schema, b)) : [resolved];
|
|
189
|
+
}
|
|
190
|
+
export function checkUnknownFields(disk, schema, schemaFindings = []) {
|
|
191
|
+
const findings = [];
|
|
192
|
+
const walk = (value, node, pointer) => {
|
|
193
|
+
if (Array.isArray(value)) {
|
|
194
|
+
const items = branches(schema, node).map((b) => b.items).find((i) => i !== undefined);
|
|
195
|
+
if (items !== undefined)
|
|
196
|
+
value.forEach((item, i) => walk(item, items, `${pointer}/${i}`));
|
|
197
|
+
return;
|
|
198
|
+
}
|
|
199
|
+
const object = asObject(value);
|
|
200
|
+
if (!object)
|
|
201
|
+
return;
|
|
202
|
+
const shapes = branches(schema, node).filter((b) => b.type === "object" || asObject(b.properties));
|
|
203
|
+
if (!shapes.length)
|
|
204
|
+
return;
|
|
205
|
+
const open = shapes.some((b) => !asObject(b.properties) || (b.additionalProperties !== undefined && b.additionalProperties !== false));
|
|
206
|
+
const closed = shapes.every((b) => b.additionalProperties === false);
|
|
207
|
+
const known = new Map();
|
|
208
|
+
const required = new Set();
|
|
209
|
+
for (const shape of shapes) {
|
|
210
|
+
for (const [key, sub] of Object.entries(asObject(shape.properties) ?? {}))
|
|
211
|
+
if (!known.has(key))
|
|
212
|
+
known.set(key, sub);
|
|
213
|
+
if (Array.isArray(shape.required))
|
|
214
|
+
for (const r of shape.required)
|
|
215
|
+
if (typeof r === "string")
|
|
216
|
+
required.add(r);
|
|
217
|
+
}
|
|
218
|
+
const missing = [...required].filter((r) => !(r in object));
|
|
219
|
+
for (const [key, inner] of Object.entries(object)) {
|
|
220
|
+
const at = `${pointer}/${key.replace(/~/g, "~0").replace(/\//g, "~1")}`;
|
|
221
|
+
if (known.has(key)) {
|
|
222
|
+
walk(inner, known.get(key), at);
|
|
223
|
+
continue;
|
|
224
|
+
}
|
|
225
|
+
if (open || closed)
|
|
226
|
+
continue;
|
|
227
|
+
const suggestion = closest(key, known.keys(), missing);
|
|
228
|
+
const parent = locate(disk, pointer).path;
|
|
229
|
+
const required = suggestion && missing.includes(suggestion) ? schemaFindings.find((f) => f.path === parent && f.message === `missing required field "${suggestion}"`) : undefined;
|
|
230
|
+
if (required) {
|
|
231
|
+
required.message += ` ("${key}" is set, which the package schema does not have; did you mean "${suggestion}"?)`;
|
|
232
|
+
required.suggestion = suggestion;
|
|
233
|
+
const misspelt = locate(disk, at);
|
|
234
|
+
if (misspelt.line !== undefined && misspelt.file === required.file)
|
|
235
|
+
required.line = misspelt.line;
|
|
236
|
+
continue;
|
|
237
|
+
}
|
|
238
|
+
const where = locate(disk, at);
|
|
239
|
+
findings.push({
|
|
240
|
+
code: FIELD_UNKNOWN_CODE,
|
|
241
|
+
severity: "warning",
|
|
242
|
+
...where,
|
|
243
|
+
message: `"${key}" is not a field of the package schema here; the import ignores it.${didYouMean(suggestion)}`,
|
|
244
|
+
...(suggestion ? { suggestion } : {}),
|
|
245
|
+
});
|
|
246
|
+
}
|
|
247
|
+
};
|
|
248
|
+
const sections = asObject(schema.properties) ?? {};
|
|
249
|
+
for (const [section, value] of Object.entries(disk.package)) {
|
|
250
|
+
if (section in sections)
|
|
251
|
+
walk(value, sections[section], `/${section}`);
|
|
252
|
+
}
|
|
253
|
+
return findings;
|
|
254
|
+
}
|
|
255
|
+
export function checkModels(disk, inventory) {
|
|
256
|
+
const tenant = inventory?.names.models;
|
|
257
|
+
if (!Array.isArray(tenant) || !tenant.length)
|
|
258
|
+
return [];
|
|
259
|
+
if (disk.unreadable?.includes("model_registry"))
|
|
260
|
+
return [];
|
|
261
|
+
const known = new Set([...tenant, ...list(disk.package.model_registry).flatMap((row) => (text(row?.model_id) ? [row.model_id] : []))]);
|
|
262
|
+
const findings = [];
|
|
263
|
+
list(disk.package.agents).forEach((agent, i) => {
|
|
264
|
+
const model = text(agent?.llm_model);
|
|
265
|
+
if (!model || known.has(model))
|
|
266
|
+
return;
|
|
267
|
+
findings.push({
|
|
268
|
+
code: MODEL_UNKNOWN_CODE,
|
|
269
|
+
severity: "warning",
|
|
270
|
+
...locate(disk, `/agents/${i}/llm_model`),
|
|
271
|
+
...suggested(`The agent "${text(agent.slug) ?? i}" uses the model "${model}", which is not in the tenant's model list ` +
|
|
272
|
+
`(${pulledAt(inventory, "models")}).`, closest(model, known)),
|
|
273
|
+
});
|
|
274
|
+
});
|
|
275
|
+
return findings;
|
|
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
|
+
}
|
|
@@ -0,0 +1,152 @@
|
|
|
1
|
+
import { clip } from "./format.js";
|
|
2
|
+
import { locate } from "./package-files.js";
|
|
3
|
+
import { cavelonCommand } from "./shell.js";
|
|
4
|
+
const isObject = (v) => Boolean(v) && typeof v === "object" && !Array.isArray(v);
|
|
5
|
+
const text = (v) => (typeof v === "string" && v.trim() ? v : null);
|
|
6
|
+
const first = (o, keys) => keys.map((k) => o[k]).find((v) => v !== undefined);
|
|
7
|
+
export function pointerOf(path) {
|
|
8
|
+
if (path.startsWith("/"))
|
|
9
|
+
return path;
|
|
10
|
+
const keys = path
|
|
11
|
+
.replace(/\[(\d+)\]/g, ".$1")
|
|
12
|
+
.split(".")
|
|
13
|
+
.filter(Boolean);
|
|
14
|
+
return `/${keys.map((k) => k.replace(/~/g, "~0").replace(/\//g, "~1")).join("/")}`;
|
|
15
|
+
}
|
|
16
|
+
export function blockerDetails(raw, disk) {
|
|
17
|
+
if (!Array.isArray(raw))
|
|
18
|
+
return [];
|
|
19
|
+
const details = raw.filter(isObject).map((b) => ({
|
|
20
|
+
code: text(b.code),
|
|
21
|
+
message: text(b.message) ?? text(b.detail) ?? JSON.stringify(b),
|
|
22
|
+
path: text(b.path) ?? text(b.pointer) ?? text(b.location),
|
|
23
|
+
hint: text(b.hint),
|
|
24
|
+
}));
|
|
25
|
+
return locateBlockers(details, disk);
|
|
26
|
+
}
|
|
27
|
+
export function locateBlockers(details, disk) {
|
|
28
|
+
if (!disk)
|
|
29
|
+
return details;
|
|
30
|
+
return details.map((b) => {
|
|
31
|
+
if (!b.path)
|
|
32
|
+
return b;
|
|
33
|
+
const at = locate(disk, pointerOf(b.path));
|
|
34
|
+
return { ...b, ...(at.file ? { file: at.file } : {}), ...(at.line ? { line: at.line } : {}) };
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
export function blockerLines(details) {
|
|
38
|
+
return details
|
|
39
|
+
.map((b) => {
|
|
40
|
+
const where = [b.file ? `${b.file}${b.line ? `:${b.line}` : ""}` : "", b.path ?? ""].filter(Boolean).join(" ");
|
|
41
|
+
const head = `\n - ${b.code ? `${b.code} ` : ""}${where ? `${where}: ` : ""}${clip(b.message, 300)}`;
|
|
42
|
+
const hint = b.hint ? `\n hint: ${clip(b.hint, 300)}` : "";
|
|
43
|
+
const explain = b.code ? `\n more: ${cavelonCommand("explain", b.code)}` : "";
|
|
44
|
+
return head + hint + explain;
|
|
45
|
+
})
|
|
46
|
+
.join("");
|
|
47
|
+
}
|
|
48
|
+
function change(object, field, raw) {
|
|
49
|
+
if (Array.isArray(raw) && raw.length === 2)
|
|
50
|
+
return { object, field, old: raw[0], new: raw[1] };
|
|
51
|
+
if (!isObject(raw))
|
|
52
|
+
return undefined;
|
|
53
|
+
const before = first(raw, ["old", "before", "from", "old_value", "current"]);
|
|
54
|
+
const after = first(raw, ["new", "after", "to", "new_value", "proposed"]);
|
|
55
|
+
if (before === undefined && after === undefined)
|
|
56
|
+
return undefined;
|
|
57
|
+
return { object, field, old: before ?? null, new: after ?? null };
|
|
58
|
+
}
|
|
59
|
+
function objectOf(entry) {
|
|
60
|
+
const named = text(entry.object) ?? text(entry.target);
|
|
61
|
+
if (named)
|
|
62
|
+
return named;
|
|
63
|
+
const kind = text(entry.kind) ?? text(entry.entity) ?? text(entry.section) ?? text(entry.type);
|
|
64
|
+
const id = text(entry.slug) ?? text(entry.name) ?? text(entry.key) ?? text(entry.id);
|
|
65
|
+
return [kind, id].filter(Boolean).join(":") || "?";
|
|
66
|
+
}
|
|
67
|
+
export function fieldChanges(raw) {
|
|
68
|
+
const out = [];
|
|
69
|
+
const fromFields = (object, fields) => {
|
|
70
|
+
if (Array.isArray(fields)) {
|
|
71
|
+
for (const f of fields.filter(isObject)) {
|
|
72
|
+
const c = change(object, text(f.field) ?? text(f.path) ?? text(f.name) ?? "?", f);
|
|
73
|
+
if (c)
|
|
74
|
+
out.push(c);
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
else if (isObject(fields)) {
|
|
78
|
+
for (const [field, value] of Object.entries(fields)) {
|
|
79
|
+
const c = change(object, field, value);
|
|
80
|
+
if (c)
|
|
81
|
+
out.push(c);
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
};
|
|
85
|
+
if (Array.isArray(raw)) {
|
|
86
|
+
for (const entry of raw.filter(isObject)) {
|
|
87
|
+
const object = objectOf(entry);
|
|
88
|
+
const nested = first(entry, ["fields", "changes", "diff"]);
|
|
89
|
+
if (nested !== undefined)
|
|
90
|
+
fromFields(object, nested);
|
|
91
|
+
else {
|
|
92
|
+
const c = change(object, text(entry.field) ?? text(entry.path) ?? "?", entry);
|
|
93
|
+
if (c)
|
|
94
|
+
out.push(c);
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
else if (isObject(raw)) {
|
|
99
|
+
for (const [object, fields] of Object.entries(raw))
|
|
100
|
+
fromFields(object, fields);
|
|
101
|
+
}
|
|
102
|
+
return out;
|
|
103
|
+
}
|
|
104
|
+
function shown(value) {
|
|
105
|
+
if (value === undefined || value === null)
|
|
106
|
+
return "null";
|
|
107
|
+
return clip(JSON.stringify(value), 80);
|
|
108
|
+
}
|
|
109
|
+
export function changeLines(changes, max = 20) {
|
|
110
|
+
const lines = changes.slice(0, max).map((c) => `\n - ${c.object}.${c.field}: ${shown(c.old)} → ${shown(c.new)}`);
|
|
111
|
+
return lines.join("") + (changes.length > max ? `\n … ${changes.length - max} more (--json)` : "");
|
|
112
|
+
}
|
|
113
|
+
function harnessSlugAt(path, pkg, fallback) {
|
|
114
|
+
const index = /^\/?harnesses[[/.](\d+)/.exec(path)?.[1];
|
|
115
|
+
const list = Array.isArray(pkg?.harnesses) ? pkg.harnesses : [];
|
|
116
|
+
const entry = index !== undefined ? list[Number(index)] : undefined;
|
|
117
|
+
return (isObject(entry) && text(entry.slug)) || fallback;
|
|
118
|
+
}
|
|
119
|
+
export function notApplied(raw, pkg, harness) {
|
|
120
|
+
if (!Array.isArray(raw))
|
|
121
|
+
return [];
|
|
122
|
+
return raw
|
|
123
|
+
.map((entry) => {
|
|
124
|
+
if (typeof entry === "string")
|
|
125
|
+
return { path: entry, how: null };
|
|
126
|
+
if (!isObject(entry))
|
|
127
|
+
return undefined;
|
|
128
|
+
const path = text(entry.path) ?? text(entry.field) ?? text(entry.pointer);
|
|
129
|
+
if (!path)
|
|
130
|
+
return undefined;
|
|
131
|
+
return { path, how: text(entry.how) ?? text(entry.hint) ?? text(entry.set_with) ?? text(entry.reason) ?? text(entry.message) };
|
|
132
|
+
})
|
|
133
|
+
.filter((n) => n !== undefined)
|
|
134
|
+
.map((n) => {
|
|
135
|
+
const field = n.path.split(/[./]/).pop();
|
|
136
|
+
const slug = harnessSlugAt(n.path, pkg, harness);
|
|
137
|
+
if (field === "is_default")
|
|
138
|
+
return { ...n, command: cavelonCommand("harness", "default", slug ?? "<solution>") };
|
|
139
|
+
if (field === "status")
|
|
140
|
+
return { ...n, command: slug ? cavelonCommand("activate", "--harness", slug) : cavelonCommand("activate") };
|
|
141
|
+
return n;
|
|
142
|
+
});
|
|
143
|
+
}
|
|
144
|
+
export function notAppliedLines(list) {
|
|
145
|
+
return list
|
|
146
|
+
.slice(0, 20)
|
|
147
|
+
.map((n) => {
|
|
148
|
+
const how = n.command ? `set with ${n.command}` : n.how ? clip(n.how, 200) : "";
|
|
149
|
+
return `\n - ${n.path}${how ? ` (${how})` : ""}`;
|
|
150
|
+
})
|
|
151
|
+
.join("") + (list.length > 20 ? `\n … ${list.length - 20} more (--json)` : "");
|
|
152
|
+
}
|
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)
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
---
|
|
2
2
|
name: cavelon-authoring
|
|
3
|
-
description: Writing and changing a Cavelon solution package in a repository - the package/ files split by schema section, the package schema, environments in env/, declaring the variables and secrets a solution needs, and fixing validation codes with cavelon explain. Use when editing files under package/, tests/ or env/ of a folder with cavelon.yaml, when cavelon validate or apply reports an error code, when the user asks to add or change agents, tools, skills, knowledge bases or triggers of a Cavelon solution, or when a limit of the tenant needs changing (cavelon limits set) or they set up a self-hosted model endpoint or its concurrency limit (max_concurrent_requests).
|
|
3
|
+
description: Writing and changing a Cavelon solution package in a repository - the package/ files split by schema section, the package schema, the persona (who the assistant is, its greeting and fallback), environments in env/, declaring the variables and secrets a solution needs, and fixing validation codes with cavelon explain. Use when editing files under package/, tests/ or env/ of a folder with cavelon.yaml, when cavelon validate or apply reports an error code, when the user asks to add or change agents, tools, skills, knowledge bases or triggers of a Cavelon solution, or when a limit of the tenant needs changing (cavelon limits set) or they set up a self-hosted model endpoint or its concurrency limit (max_concurrent_requests).
|
|
4
4
|
license: Apache-2.0
|
|
5
5
|
---
|
|
6
6
|
|
|
@@ -53,7 +53,9 @@ for a public widget), **propose the change; the person decides.**
|
|
|
53
53
|
person with your reason (what fails or waits now), and wait for their answer.
|
|
54
54
|
- Only after they agreed, run the confirm command it printed (the `confirm`
|
|
55
55
|
field in `--json`) as it stands: it keeps the `--env` and `--tenant` of the
|
|
56
|
-
preview, so it changes the limit the preview showed.
|
|
56
|
+
preview, so it changes the limit the preview showed. Over MCP, call
|
|
57
|
+
`limits_set` again with the same arguments and `confirm` set to the
|
|
58
|
+
preview's `confirm_token`. Never raise a limit on
|
|
57
59
|
your own, never pick a value higher than the need you named, and never change
|
|
58
60
|
one without telling them.
|
|
59
61
|
- The same goes for the tenant's monthly inference budget
|
|
@@ -131,7 +133,10 @@ it and where, as the output says.
|
|
|
131
133
|
|
|
132
134
|
A file of a section the instance does not know is kept as it is; the preview
|
|
133
135
|
lists it under "ignored". `package/manifest.yaml` names the package format
|
|
134
|
-
version; leave it as `pull` wrote it.
|
|
136
|
+
version; leave it as `pull` wrote it. Some fields are not applied by an
|
|
137
|
+
import: the preview lists them under "not applied", each with the command
|
|
138
|
+
that sets it (a solution's `status` with `cavelon activate`, its `is_default`
|
|
139
|
+
with `cavelon harness default`).
|
|
135
140
|
|
|
136
141
|
## Finding out what a section takes
|
|
137
142
|
|
|
@@ -141,13 +146,71 @@ version; leave it as `pull` wrote it.
|
|
|
141
146
|
(JSON or YAML): it writes the same files as `pull`, refuses to change files
|
|
142
147
|
that hold something else unless `--force`, and names the sections this
|
|
143
148
|
instance ignores.
|
|
144
|
-
2. The schema: `cavelon
|
|
145
|
-
|
|
149
|
+
2. The schema: `cavelon schema` lists the sections and the file each is kept
|
|
150
|
+
in; `cavelon schema <section>` (the `package_schema` tool) lists a section's
|
|
151
|
+
fields with type, required, allowed values and default, and prints the
|
|
152
|
+
smallest entry with every required field, to copy into the file, and one
|
|
153
|
+
with an entry of each nested list. A nested entry has its own fields: reach
|
|
154
|
+
them by path or type name, as the section's output lists them
|
|
155
|
+
(`cavelon schema agents.handoffs`, `cavelon schema test_suites.test_cases.steps`,
|
|
156
|
+
`cavelon schema PackageAgentHandoff`); where entries take several shapes
|
|
157
|
+
(`test_suites.test_cases.steps.evaluation_criteria`), each shape is listed.
|
|
158
|
+
A pulled file that is `[]` shows no shape; this does. `cavelon validate`
|
|
159
|
+
checks the files against the same schema, and each error names the file,
|
|
160
|
+
line and field. It also checks the references: a duplicate slug, and a
|
|
161
|
+
handoff or a test assertion (`answered_by`, `handoff_to`) naming an agent
|
|
162
|
+
the package lacks, are errors; a skill, tool, knowledge base or solution
|
|
163
|
+
that is neither in the package nor in the tenant's list, a field the schema
|
|
164
|
+
does not have (`package_field_unknown`, "did you mean temperature?"), an
|
|
165
|
+
`llm_model` outside the tenant's model list, and a package naming another
|
|
166
|
+
solution than `cavelon.yaml` (`solution_slug_mismatch`) are warnings. A
|
|
167
|
+
finding's `suggestion` (with `--json`) is the closest name. The import
|
|
168
|
+
preview blocks a name the instance does not have: then `validate` does not
|
|
169
|
+
say "Valid", and `cavelon validate --strict` fails on every warning.
|
|
146
170
|
3. Concepts and fields: `cavelon docs search <topic>` (for example "agent
|
|
147
171
|
graph", "tools", "knowledge base", "triggers"), then `cavelon docs get
|
|
148
172
|
<page>`.
|
|
149
|
-
4. A code from `validate`, `apply
|
|
150
|
-
<code>`. It gives the meaning, the fix
|
|
173
|
+
4. A code from `validate`, `apply`, a failed request or `cavelon` itself:
|
|
174
|
+
`cavelon explain <code>`. It gives the meaning, the fix (with the command
|
|
175
|
+
that does it, where the instance's fix names an API route) and a docs link;
|
|
176
|
+
for a code it does not know, the closest known ones. `cavelon api describe
|
|
177
|
+
<operation>` shows a body's fields, and the item fields of a list
|
|
178
|
+
(`updates[]`).
|
|
179
|
+
|
|
180
|
+
## The persona: who the assistant is
|
|
181
|
+
|
|
182
|
+
Every solution has a persona in `package/persona.yaml`. It is not an agent's
|
|
183
|
+
instructions:
|
|
184
|
+
|
|
185
|
+
- **The persona says who** the assistant is, for every agent of the solution:
|
|
186
|
+
its name (`bot_name`), its voice and its boundaries (`persona_prompt`), the
|
|
187
|
+
greeting a conversation opens with and the fallback it gives when it has no
|
|
188
|
+
answer, its language (`language_hint`), response style, disclaimer and the
|
|
189
|
+
widget's copy.
|
|
190
|
+
- **An agent's `system_prompt` says what** that one agent does: its task, its
|
|
191
|
+
tools, when it hands off. Put a rule about tone or identity into the
|
|
192
|
+
persona, and a rule about a task into the agent; `cavelon docs get
|
|
193
|
+
concepts/personas` explains the split.
|
|
194
|
+
|
|
195
|
+
`pull` and `init` write every field the instance's schema lists; a field that
|
|
196
|
+
is not set is a comment with its default (`# bot_name: null`). Remove the `#`
|
|
197
|
+
and fill the field in to set it. A file of comments only sets nothing.
|
|
198
|
+
|
|
199
|
+
- Set at least `bot_name` and `persona_prompt` for a solution people talk to.
|
|
200
|
+
- Write `greeting_message` and `fallback_message` in the content language,
|
|
201
|
+
the language the assistant answers in (the knowledge base's, the
|
|
202
|
+
customer's), not the language of this conversation. `language_hint` names
|
|
203
|
+
it.
|
|
204
|
+
- A greeting or fallback that is on (`greeting_enabled`,
|
|
205
|
+
`fallback_message_enabled`, both on by default) with an empty text shows
|
|
206
|
+
nothing of the solution's own; `cavelon validate` warns
|
|
207
|
+
(`persona_message_empty`). Write the text, or turn it off.
|
|
208
|
+
- Leave the persona out (all fields commented) only for a solution nobody
|
|
209
|
+
talks to directly: a pipeline, a loop, a solution another solution calls.
|
|
210
|
+
- Without `harness_id`, the persona operations of `cavelon api`
|
|
211
|
+
(`get_bot_persona`, `upsert_bot_persona`) reach the tenant's default route;
|
|
212
|
+
in a solution folder, `cavelon api` sends the folder's solution, and says
|
|
213
|
+
so. Prefer the package file and `apply` over those operations.
|
|
151
214
|
|
|
152
215
|
## Rules that keep a package portable
|
|
153
216
|
|
|
@@ -167,12 +230,28 @@ version; leave it as `pull` wrote it.
|
|
|
167
230
|
The preview names them with the Admin path where a person sets them.
|
|
168
231
|
- **Knowledge-base documents** are not in the repository: the package declares
|
|
169
232
|
the knowledge bases; `cavelon kb upload` brings the documents.
|
|
170
|
-
- **A knowledge base reaches an agent only through a
|
|
171
|
-
in a skill's `knowledge_base_assignments` only scopes the
|
|
172
|
-
(or the agent) also needs
|
|
173
|
-
|
|
174
|
-
|
|
233
|
+
- **A knowledge base reaches an agent only through a tool that reads it.**
|
|
234
|
+
Naming it in a skill's `knowledge_base_assignments` only scopes the tools;
|
|
235
|
+
the skill (or the agent) also needs a built-in that reads a knowledge base in
|
|
236
|
+
its `tool_assignments`: `search_documents` searches it, `list_documents`
|
|
237
|
+
lists its documents by their metadata, and `read_document` reads one by the
|
|
238
|
+
id a search or list returned (`cavelon docs get reference/builtin-tools`).
|
|
239
|
+
A tenant tool whose `builtin_key` is one of them counts too; naming
|
|
240
|
+
`knowledge_base_names` on any other tool (a webhook, an MCP tool) reaches
|
|
241
|
+
nothing. Without such a tool the
|
|
242
|
+
agent answers from memory; `cavelon validate` warns
|
|
175
243
|
(`knowledge_base_without_search_tool`).
|
|
244
|
+
- **The model comes from the tenant.** Set an agent's `llm_model` and
|
|
245
|
+
`llm_provider` to a row of `cavelon models list` (MODEL_ID, PROVIDER); the
|
|
246
|
+
models differ per instance and tenant, and the preview blocks one the tenant
|
|
247
|
+
does not have. On a reasoning model (the GPT-5 family, the o-series) from
|
|
248
|
+
OpenAI, Azure OpenAI or Anthropic the instance sends no `temperature` (the
|
|
249
|
+
schema still requires one: keep the default 0.4, and the preview flags any
|
|
250
|
+
other value); the reasoning level is what tunes such a model. Ask the
|
|
251
|
+
person to set it in the agent's **Model** tab in the Admin (Node
|
|
252
|
+
Workbench), then `cavelon pull` brings what the instance stored into
|
|
253
|
+
`package/agents.yaml`. `cavelon docs get concepts/choosing-models` says which
|
|
254
|
+
models take a temperature.
|
|
176
255
|
- **Who approves goes on the Approval node, not into the memo.** When the
|
|
177
256
|
brief says who approves, or that nobody approves their own request, set the
|
|
178
257
|
node's `approvers` (tenant roles or access groups, directly or in `tiers`
|
|
@@ -220,7 +299,13 @@ schema has them: `cavelon validate` reports an unknown section):
|
|
|
220
299
|
|
|
221
300
|
## After each edit
|
|
222
301
|
|
|
223
|
-
1. `cavelon validate` until it reports no errors
|
|
302
|
+
1. `cavelon validate` until it reports no errors (`--strict` before an apply
|
|
303
|
+
you expect to pass: it fails on the warnings the preview would block on).
|
|
304
|
+
After writing files by hand, `cavelon fmt` brings them into the form the
|
|
305
|
+
instance's export gives them (field order, the schema's defaults filled in,
|
|
306
|
+
test cases and steps numbered in their written order), so the first `pull`
|
|
307
|
+
after `apply` shows only what changed on the instance; `cavelon fmt
|
|
308
|
+
--check` changes nothing and exits 3 when a file would change.
|
|
224
309
|
2. `cavelon apply --env test` to see what the instance makes of it; the
|
|
225
310
|
preview re-checks everything on the server, including rules that only the
|
|
226
311
|
instance can check (graph rules, references between sections).
|
|
@@ -68,7 +68,9 @@ connection), the run may have started: retry only with the
|
|
|
68
68
|
starts and spends the budget again. `cavelon trace <operation-id>` reads the
|
|
69
69
|
run's traces. Keep each `watch` or `wait` under your shell's time
|
|
70
70
|
limit and run it again to resume (exit 6 means still running). Over MCP, use the
|
|
71
|
-
`loop_iterations` and `operation_status` tools;
|
|
71
|
+
`loop_iterations` and `operation_status` tools; `loop_iterations` never
|
|
72
|
+
blocks, and `operation_status` waits only when given a `timeout` (at most 50
|
|
73
|
+
seconds).
|
|
72
74
|
|
|
73
75
|
- **Pause** at the next safe point: `cavelon loop pause <run>`. Resume with
|
|
74
76
|
`cavelon loop resume <run>`. A paused loop makes `wait` and `loop watch` exit
|