@cavelon/cli 0.0.0 → 0.1.2

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 (61) hide show
  1. package/README.md +713 -3
  2. package/dist/LICENSE +201 -0
  3. package/dist/agents.js +107 -0
  4. package/dist/branches.js +61 -0
  5. package/dist/capacity.js +162 -0
  6. package/dist/cli.js +4 -0
  7. package/dist/command.js +62 -0
  8. package/dist/commands/api.js +313 -0
  9. package/dist/commands/async.js +207 -0
  10. package/dist/commands/docs.js +158 -0
  11. package/dist/commands/index.js +112 -0
  12. package/dist/commands/init.js +481 -0
  13. package/dist/commands/inventory.js +56 -0
  14. package/dist/commands/limits-set.js +633 -0
  15. package/dist/commands/limits.js +156 -0
  16. package/dist/commands/loops.js +798 -0
  17. package/dist/commands/models.js +197 -0
  18. package/dist/commands/sandboxes.js +674 -0
  19. package/dist/commands/session.js +480 -0
  20. package/dist/commands/solution.js +830 -0
  21. package/dist/commands/tenants.js +266 -0
  22. package/dist/commands/values.js +386 -0
  23. package/dist/commands/work.js +761 -0
  24. package/dist/context.js +60 -0
  25. package/dist/contracts.js +234 -0
  26. package/dist/credentials.js +134 -0
  27. package/dist/errors.js +64 -0
  28. package/dist/features.js +52 -0
  29. package/dist/format.js +36 -0
  30. package/dist/fsutil.js +43 -0
  31. package/dist/git.js +41 -0
  32. package/dist/http.js +304 -0
  33. package/dist/invoke.js +165 -0
  34. package/dist/io.js +49 -0
  35. package/dist/limits.js +307 -0
  36. package/dist/local-state.js +78 -0
  37. package/dist/main.js +227 -0
  38. package/dist/markers.js +113 -0
  39. package/dist/mcp.js +137 -0
  40. package/dist/openapi.js +233 -0
  41. package/dist/operations.js +107 -0
  42. package/dist/package-check.js +342 -0
  43. package/dist/package-files.js +394 -0
  44. package/dist/pair-order.js +39 -0
  45. package/dist/paths.js +77 -0
  46. package/dist/principal.js +33 -0
  47. package/dist/project.js +157 -0
  48. package/dist/prompt.js +34 -0
  49. package/dist/results.js +104 -0
  50. package/dist/session.js +190 -0
  51. package/dist/shell.js +41 -0
  52. package/dist/skills/cavelon-authoring/SKILL.md +224 -0
  53. package/dist/skills/cavelon-long-running/SKILL.md +185 -0
  54. package/dist/skills/cavelon-loop/SKILL.md +159 -0
  55. package/dist/skills/cavelon-testing/SKILL.md +97 -0
  56. package/dist/sse.js +44 -0
  57. package/dist/tar.js +172 -0
  58. package/dist/user-config.js +36 -0
  59. package/dist/version.js +17 -0
  60. package/dist/zip.js +132 -0
  61. package/package.json +40 -4
@@ -0,0 +1,342 @@
1
+ import { Ajv2020 } from "ajv/dist/2020.js";
2
+ import { BRANCH_WIDTH_KEY, branchConcurrency, offText } from "./branches.js";
3
+ import { locate, schemaSections } from "./package-files.js";
4
+ export const SCHEMA_CODE = "package_schema_invalid";
5
+ const ENDPOINT_LIMIT_CODE = "model_endpoint_limit_without_base_url";
6
+ const ENDPOINT_LIMIT_NOT_CARRIED = "model_endpoint_limit_not_in_package_schema";
7
+ const REGISTRY_SECTION = "model_registry";
8
+ const ENDPOINT_LIMIT_FIELD = "max_concurrent_requests";
9
+ const PACKAGE_DOCS = "/docs/reference/api-endpoints";
10
+ const BRANCH_WIDTH_CODE = "branch_width_capped";
11
+ const BRANCHES_SEQUENTIAL_CODE = "branches_run_in_sequence";
12
+ const BRANCH_DOCS = "/docs/concepts/capacity-and-concurrency#branch-concurrency";
13
+ const KB_WITHOUT_SEARCH_CODE = "knowledge_base_without_search_tool";
14
+ const SEARCH_DOCS = "/docs/reference/builtin-tools#binding-knowledge-bases-to-search_documents";
15
+ const SEARCH_TOOL = "search_documents";
16
+ const SEARCH_TOOL_KEYS = new Set([SEARCH_TOOL, "search_knowledge_base", "search_kb"]);
17
+ export const KIT_CODES = [
18
+ {
19
+ code: SCHEMA_CODE,
20
+ area: "package",
21
+ message: "A package file does not match the instance's package schema.",
22
+ hint: "Fix the field the finding names (file, line and path); copy the shape of a similar entry from `cavelon pull`.",
23
+ docs: PACKAGE_DOCS,
24
+ },
25
+ {
26
+ code: "package_section_unknown",
27
+ area: "package",
28
+ message: "A file in package/ holds a section this instance's package schema does not have.",
29
+ hint: "Check the file name for a typo; a section from a newer instance is kept and sent, and this instance ignores it.",
30
+ docs: PACKAGE_DOCS,
31
+ },
32
+ {
33
+ code: "package_file_invalid",
34
+ area: "package",
35
+ message: "A package file is not valid YAML or JSON, or is a link to a file outside the solution or to none.",
36
+ hint: "Fix the syntax at the line the finding names.",
37
+ docs: PACKAGE_DOCS,
38
+ },
39
+ {
40
+ code: ENDPOINT_LIMIT_CODE,
41
+ area: "package",
42
+ message: "A Model Registry row sets max_concurrent_requests without a base_url.",
43
+ hint: "The limit belongs to a self-hosted endpoint: add the row's base_url, or remove max_concurrent_requests (empty means no limit).",
44
+ docs: PACKAGE_DOCS,
45
+ },
46
+ {
47
+ code: ENDPOINT_LIMIT_NOT_CARRIED,
48
+ area: "package",
49
+ message: "This instance's package format does not carry max_concurrent_requests on Model Registry rows.",
50
+ hint: "The import ignores it. Set it on the row in the Admin's model form, or with PATCH /api/v1/model-registry/{model_registry_id}.",
51
+ docs: PACKAGE_DOCS,
52
+ },
53
+ {
54
+ code: BRANCH_WIDTH_CODE,
55
+ area: "package",
56
+ message: "A fan-out or Map loop sets max_concurrency above the branch width this instance publishes; it runs at the width.",
57
+ hint: "Nothing fails: the node runs at most the published width at once. Lower max_concurrency to the width, or ask the operator to raise ORCHESTRATION_MAX_BRANCH_CONCURRENCY. `cavelon limits --key orchestration_max_branch_concurrency` shows it.",
58
+ docs: BRANCH_DOCS,
59
+ },
60
+ {
61
+ code: BRANCHES_SEQUENTIAL_CODE,
62
+ area: "package",
63
+ message: "This tenant runs fan-outs and Map loops in sequence: a switch for concurrent branches is off.",
64
+ hint: "The result is the same, only slower. `cavelon limits --key orchestration_parallel_branches` names the switch that is off and who turns it on.",
65
+ docs: BRANCH_DOCS,
66
+ },
67
+ {
68
+ code: KB_WITHOUT_SEARCH_CODE,
69
+ 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.`,
72
+ docs: SEARCH_DOCS,
73
+ },
74
+ {
75
+ code: "package_file_duplicate",
76
+ area: "package",
77
+ message: "One section is in two files.",
78
+ hint: "Keep one of them: package/<section>.yaml, or the section's own folder from cavelon.yaml's layout.",
79
+ docs: PACKAGE_DOCS,
80
+ },
81
+ ];
82
+ export function catalogEntry(catalog, code) {
83
+ const rule = catalog?.rule_codes?.find((e) => e.code === code);
84
+ if (rule)
85
+ return { ...rule, kind: "rule" };
86
+ const api = catalog?.api_error_codes?.find((e) => e.code === code);
87
+ if (api)
88
+ return { ...api, kind: "api" };
89
+ const kit = KIT_CODES.find((e) => e.code === code);
90
+ return kit ? { ...kit, kind: "kit" } : undefined;
91
+ }
92
+ export function packageVersionOf(pkg) {
93
+ const manifest = pkg.manifest;
94
+ if (!manifest || typeof manifest !== "object")
95
+ return undefined;
96
+ const version = manifest.package_version;
97
+ return typeof version === "string" ? version : undefined;
98
+ }
99
+ function compile(schema) {
100
+ const { $id: _id, $schema: _schema, ...body } = schema;
101
+ const ajv = new Ajv2020({ strict: false, allErrors: true, validateSchema: false, validateFormats: false });
102
+ return ajv.compile(body);
103
+ }
104
+ function describe(error) {
105
+ const params = error.params;
106
+ if (error.keyword === "required") {
107
+ return { pointer: error.instancePath, message: `missing required field "${String(params.missingProperty)}"` };
108
+ }
109
+ if (error.keyword === "enum") {
110
+ return { pointer: error.instancePath, message: `must be one of ${params.allowedValues.map((v) => JSON.stringify(v)).join(", ")}` };
111
+ }
112
+ if (error.keyword === "const") {
113
+ return { pointer: error.instancePath, message: `must be ${JSON.stringify(params.allowedValue)}` };
114
+ }
115
+ return { pointer: error.instancePath, message: error.message ?? "is invalid" };
116
+ }
117
+ export function checkPackage(disk, options) {
118
+ const findings = [...disk.findings];
119
+ const known = new Set(schemaSections(options.schema));
120
+ for (const section of Object.keys(disk.package)) {
121
+ if (known.has(section))
122
+ continue;
123
+ const source = disk.sources[section];
124
+ findings.push({
125
+ code: "package_section_unknown",
126
+ severity: "warning",
127
+ file: Array.isArray(source) ? source[0]?.file : source?.file,
128
+ path: section,
129
+ message: `This instance's package schema has no section "${section}". apply sends it as it is, and the instance ignores it (the preview lists it under "ignored").`,
130
+ });
131
+ }
132
+ const version = packageVersionOf(disk.package);
133
+ if (version && options.accepted?.length && !options.accepted.includes(version)) {
134
+ const at = locate(disk, "/manifest/package_version");
135
+ findings.push({
136
+ code: "package_version_unsupported",
137
+ severity: "error",
138
+ ...at,
139
+ message: `The package is written in format ${version}; this instance accepts ${options.accepted.join(", ")}.`,
140
+ });
141
+ }
142
+ const validate = compile(options.schema);
143
+ if (!validate(disk.package)) {
144
+ const seen = new Set();
145
+ for (const error of validate.errors ?? []) {
146
+ if (error.keyword === "anyOf" || error.keyword === "oneOf")
147
+ continue;
148
+ const { pointer, message } = describe(error);
149
+ const key = `${pointer} ${message}`;
150
+ if (seen.has(key))
151
+ continue;
152
+ seen.add(key);
153
+ findings.push({ code: SCHEMA_CODE, severity: "error", ...locate(disk, pointer), message });
154
+ }
155
+ }
156
+ findings.push(...checkEndpointLimits(disk, options.schema));
157
+ findings.push(...checkBranchConcurrency(disk, options.limits));
158
+ findings.push(...checkKnowledgeSearch(disk));
159
+ for (const finding of findings) {
160
+ const entry = catalogEntry(options.catalog, finding.code);
161
+ if (!entry)
162
+ continue;
163
+ finding.hint ??= entry.hint ?? undefined;
164
+ finding.docs ??= entry.docs;
165
+ }
166
+ return findings;
167
+ }
168
+ function entryProperties(schema, section) {
169
+ let entry = schema.properties?.[section]?.items;
170
+ const ref = typeof entry?.$ref === "string" ? entry.$ref : undefined;
171
+ if (ref?.startsWith("#/$defs/"))
172
+ entry = schema.$defs?.[ref.slice("#/$defs/".length)];
173
+ const properties = entry?.properties;
174
+ return properties && typeof properties === "object" ? properties : undefined;
175
+ }
176
+ function checkEndpointLimits(disk, schema) {
177
+ const rows = disk.package[REGISTRY_SECTION];
178
+ if (!Array.isArray(rows))
179
+ return [];
180
+ const carried = Boolean(entryProperties(schema, REGISTRY_SECTION)?.[ENDPOINT_LIMIT_FIELD]);
181
+ const findings = [];
182
+ rows.forEach((row, index) => {
183
+ if (!row || typeof row !== "object")
184
+ return;
185
+ const entry = row;
186
+ const limit = entry[ENDPOINT_LIMIT_FIELD];
187
+ if (limit === undefined || limit === null)
188
+ return;
189
+ const at = locate(disk, `/${REGISTRY_SECTION}/${index}/${ENDPOINT_LIMIT_FIELD}`);
190
+ const name = typeof entry.model_id === "string" ? ` "${entry.model_id}"` : "";
191
+ if (!carried) {
192
+ findings.push({
193
+ code: ENDPOINT_LIMIT_NOT_CARRIED,
194
+ severity: "warning",
195
+ ...at,
196
+ message: `Model${name} sets ${ENDPOINT_LIMIT_FIELD}, which this instance's package format does not carry; the import ignores it.`,
197
+ });
198
+ }
199
+ else if (typeof entry.base_url !== "string" || !entry.base_url.trim()) {
200
+ findings.push({
201
+ code: ENDPOINT_LIMIT_CODE,
202
+ severity: "error",
203
+ ...at,
204
+ message: `Model${name} sets ${ENDPOINT_LIMIT_FIELD} without a base_url; the limit belongs to a self-hosted endpoint.`,
205
+ });
206
+ }
207
+ });
208
+ return findings;
209
+ }
210
+ const asObject = (v) => (v && typeof v === "object" && !Array.isArray(v) ? v : undefined);
211
+ function branchingConfigs(pkg) {
212
+ const found = [];
213
+ const runsBranches = (c) => typeof c.max_concurrency === "number" || c.mode === "map" || c.fanout === true || c.execution === "parallel";
214
+ const registry = asObject(pkg.registry_entities);
215
+ const nodes = Array.isArray(registry?.orchestration_nodes) ? registry.orchestration_nodes : [];
216
+ nodes.forEach((raw, i) => {
217
+ const node = asObject(raw);
218
+ const config = asObject(node?.config);
219
+ if (config && runsBranches(config))
220
+ found.push({ name: `node "${String(node.slug ?? i)}"`, pointer: `/registry_entities/orchestration_nodes/${i}/config`, config });
221
+ });
222
+ const edges = Array.isArray(registry?.graph_edges) ? registry.graph_edges : [];
223
+ edges.forEach((raw, i) => {
224
+ const edge = asObject(raw);
225
+ const config = asObject(edge?.config);
226
+ const end = (ref) => String(asObject(ref)?.slug ?? "?");
227
+ if (config && runsBranches(config))
228
+ found.push({ name: `edge ${end(edge.from_node_ref)} → ${end(edge.to_node_ref)}`, pointer: `/registry_entities/graph_edges/${i}/config`, config });
229
+ });
230
+ const agents = Array.isArray(pkg.agents) ? pkg.agents : [];
231
+ agents.forEach((raw, i) => {
232
+ const agent = asObject(raw);
233
+ const handoffs = Array.isArray(agent?.handoffs) ? agent.handoffs : [];
234
+ handoffs.forEach((h, j) => {
235
+ const handoff = asObject(h);
236
+ const config = asObject(handoff?.orchestration_config);
237
+ if (config && runsBranches(config)) {
238
+ found.push({ name: `edge ${String(agent.slug ?? i)} → ${String(handoff.to_agent_slug ?? "?")}`, pointer: `/agents/${i}/handoffs/${j}/orchestration_config`, config });
239
+ }
240
+ });
241
+ });
242
+ return found;
243
+ }
244
+ function checkBranchConcurrency(disk, limits) {
245
+ const branches = branchConcurrency(limits);
246
+ if (!branches)
247
+ return [];
248
+ const configs = branchingConfigs(disk.package);
249
+ const findings = [];
250
+ const width = branches.width;
251
+ if (width !== null) {
252
+ for (const c of configs) {
253
+ const requested = c.config.max_concurrency;
254
+ if (typeof requested !== "number" || requested <= width)
255
+ continue;
256
+ findings.push({
257
+ code: BRANCH_WIDTH_CODE,
258
+ severity: "warning",
259
+ ...locate(disk, `${c.pointer}/max_concurrency`),
260
+ message: `The ${c.name} sets max_concurrency ${requested}, above this instance's branch width of ${width} ` +
261
+ `(${branches.width_setting ?? BRANCH_WIDTH_KEY}): it runs at most ${width} branches at once.`,
262
+ });
263
+ }
264
+ }
265
+ if (branches.parallel === false && configs.length) {
266
+ const names = configs.slice(0, 3).map((c) => c.name).join(", ") + (configs.length > 3 ? `, and ${configs.length - 3} more` : "");
267
+ findings.push({
268
+ code: BRANCHES_SEQUENTIAL_CODE,
269
+ severity: "warning",
270
+ ...locate(disk, configs[0].pointer),
271
+ message: `This tenant runs fan-outs and Map loops in sequence, so the ${names} run${configs.length === 1 ? "s" : ""} one branch after another ` +
272
+ `(same result, slower): ${offText(branches)}.`,
273
+ });
274
+ }
275
+ return findings;
276
+ }
277
+ const asList = (v) => Array.isArray(v) ? v.map(asObject).filter((e) => e !== undefined) : [];
278
+ const active = (e) => e.is_active !== false;
279
+ const quoted = (names) => names.map((n) => `"${n}"`).join(", ");
280
+ function checkKnowledgeSearch(disk) {
281
+ const pkg = disk.package;
282
+ const searchSlugs = new Set(SEARCH_TOOL_KEYS);
283
+ 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))
285
+ searchSlugs.add(tool.slug);
286
+ }
287
+ const searches = (assignments) => asList(assignments).some((a) => active(a) && typeof a.tool_slug === "string" && searchSlugs.has(a.tool_slug));
288
+ const skills = asList(pkg.skills);
289
+ const skillIndex = new Map();
290
+ skills.forEach((skill, i) => {
291
+ if (typeof skill.slug === "string")
292
+ skillIndex.set(skill.slug, i);
293
+ });
294
+ const findings = [];
295
+ asList(pkg.agents).forEach((agent, i) => {
296
+ if (!active(agent))
297
+ return;
298
+ const named = [];
299
+ let reached = searches(agent.tool_assignments);
300
+ let unseen = false;
301
+ asList(agent.tool_assignments).forEach((assignment, j) => {
302
+ const names = asObject(assignment.config_overrides)?.knowledge_base_names;
303
+ const list = Array.isArray(names) ? names.filter((n) => typeof n === "string") : [];
304
+ if (active(assignment) && list.length)
305
+ named.push({ names: list, pointer: `/agents/${i}/tool_assignments/${j}/config_overrides/knowledge_base_names` });
306
+ });
307
+ for (const assignment of asList(agent.skill_assignments)) {
308
+ if (!active(assignment) || typeof assignment.skill_slug !== "string")
309
+ continue;
310
+ const k = skillIndex.get(assignment.skill_slug);
311
+ if (k === undefined) {
312
+ unseen = true;
313
+ continue;
314
+ }
315
+ const skill = skills[k];
316
+ if (!active(skill))
317
+ continue;
318
+ if (searches(skill.tool_assignments))
319
+ reached = true;
320
+ const names = asList(skill.knowledge_base_assignments)
321
+ .filter(active)
322
+ .map((a) => a.knowledge_base_name)
323
+ .filter((n) => typeof n === "string");
324
+ if (names.length)
325
+ named.push({ names, pointer: `/skills/${k}/knowledge_base_assignments`, via: assignment.skill_slug });
326
+ }
327
+ if (reached || unseen || !named.length)
328
+ return;
329
+ const names = [...new Set(named.flatMap((n) => n.names))];
330
+ const first = named[0];
331
+ const agentName = typeof agent.slug === "string" ? ` "${agent.slug}"` : "";
332
+ findings.push({
333
+ code: KB_WITHOUT_SEARCH_CODE,
334
+ severity: "warning",
335
+ ...locate(disk, first.pointer),
336
+ 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.`,
339
+ });
340
+ });
341
+ return findings;
342
+ }