@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,197 @@
1
+ import { CAPACITY_TUTORIAL_PAGE } from "../capacity.js";
2
+ import { boolOption, CURSOR_OPTION, intOption, LIMIT_OPTION, pageOf, positional, stringOption } from "../command.js";
3
+ import { CavelonError, ExitCode, usageError } from "../errors.js";
4
+ import { moreHint, table } from "../format.js";
5
+ import { callStable, workflowOperation } from "../invoke.js";
6
+ import { deref, jsonBodySchema, validateBody } from "../openapi.js";
7
+ import { cavelonCommand, shellWord } from "../shell.js";
8
+ import { listedPages } from "./docs.js";
9
+ import { ENV_OPTION, targetFlags } from "./values.js";
10
+ const LIST_ROUTE = "/api/v1/model-registry";
11
+ const ROW_ROUTE = "/api/v1/model-registry/{model_registry_id}";
12
+ const LIMIT_FIELD = "max_concurrent_requests";
13
+ const WITHOUT_ENDPOINT = "model_endpoint_limit_without_base_url";
14
+ export function endpointOf(baseUrl) {
15
+ const raw = (baseUrl ?? "").trim();
16
+ if (!raw)
17
+ return null;
18
+ let url;
19
+ try {
20
+ url = new URL(raw);
21
+ }
22
+ catch {
23
+ return "(not a URL)";
24
+ }
25
+ if (!url.hostname)
26
+ return "(not a URL)";
27
+ let path = url.pathname;
28
+ while (path.endsWith("/"))
29
+ path = path.slice(0, -1);
30
+ return `${url.protocol}//${url.host}${path}`;
31
+ }
32
+ function rowView(row, all) {
33
+ const endpoint = endpointOf(row.base_url);
34
+ const sharing = endpoint ? all.filter((other) => other.id !== row.id && endpointOf(other.base_url) === endpoint).map((other) => other.model_id) : [];
35
+ return {
36
+ id: row.id,
37
+ model_id: row.model_id,
38
+ display_name: row.display_name ?? null,
39
+ provider: row.provider ?? null,
40
+ endpoint,
41
+ max_concurrent_requests: row.max_concurrent_requests ?? null,
42
+ is_active: row.is_active ?? true,
43
+ capabilities: row.capabilities ?? [],
44
+ api_key_type: row.api_key_type ?? null,
45
+ ...(sharing.length ? { shares_endpoint_with: sharing } : {}),
46
+ };
47
+ }
48
+ function limitText(limit) {
49
+ return limit === null ? "none" : String(limit);
50
+ }
51
+ async function readRows(ctx) {
52
+ const rows = await callStable(ctx, "GET", LIST_ROUTE, "the Model Registry");
53
+ return Array.isArray(rows) ? rows : [];
54
+ }
55
+ function findRow(rows, ref, flags) {
56
+ const byId = rows.find((r) => r.id === ref) ?? rows.find((r) => r.model_id === ref);
57
+ if (byId)
58
+ return byId;
59
+ const byName = rows.filter((r) => (r.display_name ?? "").toLowerCase() === ref.toLowerCase());
60
+ if (byName.length === 1)
61
+ return byName[0];
62
+ if (byName.length > 1) {
63
+ throw usageError(`Several Model Registry rows are called "${ref}": ${byName.map((r) => r.model_id).join(", ")}.`, "Name the row by its model_id or id; `cavelon models list` shows them.");
64
+ }
65
+ throw new CavelonError(ExitCode.failure, {
66
+ code: "model_not_found",
67
+ status: 404,
68
+ message: `This tenant's Model Registry has no row "${ref}".`,
69
+ hint: `\`cavelon models list${flags}\` shows its rows by model_id and id.`,
70
+ });
71
+ }
72
+ function parseLimit(raw) {
73
+ const value = raw.trim().toLowerCase();
74
+ if (value === "none" || value === "null")
75
+ return null;
76
+ if (!/^\d+$/.test(value))
77
+ throw usageError(`<limit> must be a whole number of requests at once, or none to clear it; got "${raw}".`);
78
+ return Number(value);
79
+ }
80
+ function requireLimitField(doc, op) {
81
+ const schema = jsonBodySchema(op);
82
+ if (!doc || !schema)
83
+ return;
84
+ const properties = deref(doc, schema)?.properties;
85
+ if (properties && LIMIT_FIELD in properties)
86
+ return;
87
+ throw new CavelonError(ExitCode.failure, {
88
+ code: "operation_unavailable",
89
+ message: `This instance's Model Registry rows have no ${LIMIT_FIELD} (PATCH ${ROW_ROUTE} does not take it), so nothing was sent.`,
90
+ hint: "The instance is older than endpoint limits; `cavelon status` shows its version.",
91
+ });
92
+ }
93
+ export const modelsList = {
94
+ name: "models list",
95
+ summary: "List the tenant's Model Registry rows with their endpoint and max_concurrent_requests; never a key.",
96
+ description: "Each row's endpoint (scheme, host, port, path of its base_url) and how many requests it may send there at once\n" +
97
+ "(max_concurrent_requests; none means no limit). Rows with the same base_url share that count. A row without a base_url\n" +
98
+ "reaches its provider through the platform's routes and takes no limit. Keys are never shown, only their kind.",
99
+ readOnly: true,
100
+ idempotent: true,
101
+ mcpTool: "models_list",
102
+ options: { limit: LIMIT_OPTION, cursor: CURSOR_OPTION, env: ENV_OPTION },
103
+ examples: ["cavelon models list", "cavelon models list --json"],
104
+ async run(ctx, input) {
105
+ const limit = intOption(input, "limit", { min: 1, max: 500, fallback: 50 });
106
+ const flags = targetFlags(await ctx.session());
107
+ const rows = await readRows(ctx);
108
+ const page = pageOf(rows, limit, stringOption(input, "cursor"));
109
+ const items = page.items.map((row) => rowView(row, rows));
110
+ if (!items.length) {
111
+ return {
112
+ data: { items, next_cursor: page.next_cursor, total: page.total },
113
+ text: "This tenant's Model Registry has no rows; the instance's defaults serve its agents.",
114
+ };
115
+ }
116
+ const shown = items.map((row) => ({
117
+ ...row,
118
+ endpoint: row.endpoint ?? "(platform route)",
119
+ max_concurrent_requests: limitText(row.max_concurrent_requests),
120
+ active: row.is_active ? "yes" : "no",
121
+ }));
122
+ const pages = await listedPages(ctx, [CAPACITY_TUTORIAL_PAGE]);
123
+ const lines = [
124
+ table(shown, ["model_id", "provider", "endpoint", "max_concurrent_requests", "active"], 60) + moreHint(page.next_cursor, `cavelon models list${flags}`),
125
+ "",
126
+ `Rows with the same endpoint share one max_concurrent_requests count. Change it with: cavelon models set-limit <model_id> <n|none>${flags}`,
127
+ ...pages.map((p) => `Plan it for a self-hosted endpoint: ${cavelonCommand("docs", "get", p)}`),
128
+ ];
129
+ return { data: { items, next_cursor: page.next_cursor, total: page.total }, text: lines.join("\n") };
130
+ },
131
+ };
132
+ export const modelsSetLimit = {
133
+ name: "models set-limit",
134
+ summary: "Set or clear how many requests a Model Registry row's endpoint gets at once (needs --confirm).",
135
+ description: "Sets the row's max_concurrent_requests to <n>, or clears it with none. Without --confirm, shows the old and new value\n" +
136
+ "and changes nothing. A row without a base_url is refused before anything is sent: it reaches its provider through the\n" +
137
+ "platform's routes, which have their own limits. Every row with the same base_url shares the count. Propose a value to\n" +
138
+ "the person and let them decide; the instance's capacity tutorial says how to find it.",
139
+ readOnly: false,
140
+ destructive: true,
141
+ idempotent: true,
142
+ mcpTool: "models_set_limit",
143
+ positionals: [
144
+ { name: "model", description: "The row's model_id, id or display name (`cavelon models list`).", required: true },
145
+ { name: "limit", description: "Requests the endpoint serves at once (a whole number), or none to clear the limit.", required: true },
146
+ ],
147
+ options: {
148
+ confirm: { type: "boolean", description: "Change it; without this nothing is changed." },
149
+ env: ENV_OPTION,
150
+ },
151
+ examples: ["cavelon models set-limit llama-70b 8", "cavelon models set-limit llama-70b 8 --confirm", "cavelon models set-limit llama-70b none --confirm"],
152
+ async run(ctx, input) {
153
+ const ref = positional(input, "model");
154
+ const limit = parseLimit(positional(input, "limit"));
155
+ const flags = targetFlags(await ctx.session());
156
+ const { doc, op } = await workflowOperation(ctx, "PATCH", ROW_ROUTE, "changing Model Registry rows");
157
+ requireLimitField(doc, op);
158
+ if (doc)
159
+ validateBody(doc, op, { [LIMIT_FIELD]: limit });
160
+ const rows = await readRows(ctx);
161
+ const row = findRow(rows, ref, flags);
162
+ const model = rowView(row, rows);
163
+ const previous = model.max_concurrent_requests;
164
+ if (limit !== null && !model.endpoint) {
165
+ throw new CavelonError(ExitCode.validation, {
166
+ code: WITHOUT_ENDPOINT,
167
+ message: `Model "${row.model_id}" has no base_url, so it takes no max_concurrent_requests; nothing was sent.`,
168
+ hint: "The limit counts requests to the row's own endpoint (a self-hosted model server). A row without one reaches its " +
169
+ "provider through the platform's routes, which have their own rate limits. Give the row its base_url first (the Admin's " +
170
+ "model form, or model_registry in package/), then set the limit.",
171
+ details: { model_id: row.model_id, id: row.id, sent: false },
172
+ });
173
+ }
174
+ const base = { model, previous, limit };
175
+ const label = `Model ${row.model_id}${model.endpoint ? ` (${model.endpoint})` : ""}`;
176
+ if (previous === limit) {
177
+ return { data: { ...base, changed: false, sent: false }, text: `${label} already has max_concurrent_requests ${limitText(limit)}; nothing to change.` };
178
+ }
179
+ const sharing = model.shares_endpoint_with?.length ? ` It shares the count with ${model.shares_endpoint_with.join(", ")} (same endpoint).` : "";
180
+ if (!boolOption(input, "confirm")) {
181
+ const confirm = `cavelon models set-limit ${shellWord(row.model_id)} ${limitText(limit)}${flags} --confirm`;
182
+ return {
183
+ data: { ...base, changed: false, sent: false, confirm },
184
+ text: `${label}: max_concurrent_requests ${limitText(previous)} → ${limitText(limit)}.${sharing}\nNothing was changed. Change it with: ${confirm}`,
185
+ };
186
+ }
187
+ const saved = await callStable(ctx, "PATCH", ROW_ROUTE, "changing Model Registry rows", {
188
+ params: { model_registry_id: [row.id] },
189
+ body: { [LIMIT_FIELD]: limit },
190
+ });
191
+ const now = rowView({ ...row, ...saved }, rows);
192
+ return {
193
+ data: { model: now, previous, limit: now.max_concurrent_requests, changed: true, sent: true },
194
+ text: `Changed ${label}: max_concurrent_requests ${limitText(previous)} → ${limitText(now.max_concurrent_requests)}.${sharing}`,
195
+ };
196
+ },
197
+ };