@cavelon/cli 0.1.5 → 0.1.7
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 +56 -18
- package/dist/command.js +10 -0
- package/dist/commands/api.js +40 -36
- package/dist/commands/chat.js +183 -0
- package/dist/commands/docs.js +77 -9
- package/dist/commands/fmt.js +61 -6
- package/dist/commands/index.js +3 -0
- package/dist/commands/init.js +61 -26
- package/dist/commands/inventory.js +21 -0
- package/dist/commands/limits-set.js +10 -6
- package/dist/commands/loops.js +22 -11
- package/dist/commands/models.js +11 -7
- package/dist/commands/sandboxes.js +11 -5
- package/dist/commands/schema.js +230 -48
- package/dist/commands/session.js +100 -14
- package/dist/commands/setup.js +22 -6
- package/dist/commands/solution.js +493 -86
- package/dist/commands/tenants.js +43 -10
- package/dist/commands/values.js +20 -11
- package/dist/commands/work.js +167 -33
- package/dist/confirm-token.js +72 -0
- package/dist/format.js +4 -4
- package/dist/harness-ref.js +17 -4
- package/dist/http.js +6 -0
- package/dist/kit-codes.js +11 -1
- package/dist/local-state.js +46 -10
- package/dist/main.js +38 -6
- package/dist/mcp.js +65 -14
- package/dist/openapi.js +30 -0
- package/dist/package-check.js +206 -18
- package/dist/package-files.js +98 -40
- package/dist/package-format.js +81 -8
- package/dist/package-references.js +77 -10
- package/dist/results.js +21 -1
- package/dist/session.js +9 -0
- package/dist/skills/cavelon-authoring/SKILL.md +54 -21
- package/dist/skills/cavelon-long-running/SKILL.md +13 -9
- package/dist/skills/cavelon-loop/SKILL.md +124 -28
- 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/commands/models.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { CAPACITY_TUTORIAL_PAGE } from "../capacity.js";
|
|
2
|
-
import {
|
|
2
|
+
import { CURSOR_OPTION, intOption, LIMIT_OPTION, pageOf, positional, stringOption } from "../command.js";
|
|
3
3
|
import { CavelonError, ExitCode, usageError } from "../errors.js";
|
|
4
|
+
import { confirmation } from "../confirm-token.js";
|
|
4
5
|
import { moreHint, table } from "../format.js";
|
|
5
6
|
import { callStable, workflowOperation } from "../invoke.js";
|
|
6
7
|
import { deref, jsonBodySchema, validateBody } from "../openapi.js";
|
|
@@ -151,10 +152,11 @@ export const modelsSetLimit = {
|
|
|
151
152
|
{ name: "limit", description: "Requests the endpoint serves at once (a whole number), or none to clear the limit.", required: true },
|
|
152
153
|
],
|
|
153
154
|
options: {
|
|
154
|
-
confirm: { type: "boolean", description: "Change it; without this nothing is changed." },
|
|
155
|
+
confirm: { type: "boolean", mcpToken: true, description: "Change it; without this nothing is changed." },
|
|
155
156
|
env: ENV_OPTION,
|
|
156
157
|
},
|
|
157
|
-
examples: ["cavelon models set-limit llama-70b 8", "cavelon models set-limit llama-70b 8 --confirm",
|
|
158
|
+
examples: ["cavelon models set-limit llama-70b 8", "cavelon models set-limit llama-70b 8 --confirm",
|
|
159
|
+
"cavelon models set-limit llama-70b 8 --confirm <token>", "cavelon models set-limit llama-70b none --confirm"],
|
|
158
160
|
async run(ctx, input) {
|
|
159
161
|
const ref = positional(input, "model");
|
|
160
162
|
const limit = parseLimit(positional(input, "limit"));
|
|
@@ -183,11 +185,13 @@ export const modelsSetLimit = {
|
|
|
183
185
|
return { data: { ...base, changed: false, sent: false }, text: `${label} already has max_concurrent_requests ${limitText(limit)}; nothing to change.` };
|
|
184
186
|
}
|
|
185
187
|
const sharing = model.shares_endpoint_with?.length ? ` It shares the count with ${model.shares_endpoint_with.join(", ")} (same endpoint).` : "";
|
|
186
|
-
|
|
187
|
-
|
|
188
|
+
const gate = await confirmation(ctx, input, "models_set_limit", { row: row.id, previous, limit });
|
|
189
|
+
if (!gate.confirmed) {
|
|
190
|
+
const confirm = gate.confirm(`cavelon models set-limit ${shellWord(row.model_id)} ${limitText(limit)}${flags} --confirm`);
|
|
188
191
|
return {
|
|
189
|
-
data: { ...base, changed: false, sent: false, confirm },
|
|
190
|
-
text: `${label}: max_concurrent_requests ${limitText(previous)} → ${limitText(limit)}.${sharing}\
|
|
192
|
+
data: { ...base, changed: false, sent: false, confirm, ...gate.fields },
|
|
193
|
+
text: `${label}: max_concurrent_requests ${limitText(previous)} → ${limitText(limit)}.${sharing}\n${gate.mismatch ? `${gate.mismatch}\n` : ""}Nothing was changed. Change it with: ${confirm}`,
|
|
194
|
+
...(gate.exitCode ? { exitCode: gate.exitCode } : {}),
|
|
191
195
|
};
|
|
192
196
|
}
|
|
193
197
|
const saved = await callStable(ctx, "PATCH", ROW_ROUTE, "changing Model Registry rows", {
|
|
@@ -3,6 +3,7 @@ import { promises as fs } from "node:fs";
|
|
|
3
3
|
import path from "node:path";
|
|
4
4
|
import { boolOption, CURSOR_OPTION, intOption, LIMIT_OPTION, listOption, positional, stringOption, } from "../command.js";
|
|
5
5
|
import { CavelonError, ExitCode, usageError } from "../errors.js";
|
|
6
|
+
import { confirmation } from "../confirm-token.js";
|
|
6
7
|
import { confinedPath } from "../paths.js";
|
|
7
8
|
import { idempotencyKey, instanceModes, requireFeature, stableKey, UUID_KEY_OPTION, withRetryKey } from "../features.js";
|
|
8
9
|
import { clip, keyValues, moreHint, table } from "../format.js";
|
|
@@ -470,12 +471,14 @@ export const sandboxSeed = {
|
|
|
470
471
|
options: {
|
|
471
472
|
harness: HARNESS_OPTION,
|
|
472
473
|
revision: REVISION_OPTION,
|
|
473
|
-
confirm: { type: "boolean", description: "Send it; without it nothing changes." },
|
|
474
|
+
confirm: { type: "boolean", mcpToken: true, description: "Send it; without it nothing changes." },
|
|
474
475
|
wait: WAIT_OPTION,
|
|
475
476
|
timeout: TIMEOUT_OPTION,
|
|
476
477
|
"idempotency-key": UUID_KEY_OPTION,
|
|
477
478
|
},
|
|
478
|
-
examples: ["cavelon sandbox seed orders-test seeds/orders", "cavelon sandbox seed orders-test seeds/orders --confirm --wait"
|
|
479
|
+
examples: ["cavelon sandbox seed orders-test seeds/orders", "cavelon sandbox seed orders-test seeds/orders --confirm --wait",
|
|
480
|
+
"cavelon sandbox seed orders-test seeds/orders --confirm <token> --wait",
|
|
481
|
+
],
|
|
479
482
|
async run(ctx, input) {
|
|
480
483
|
const sandbox = await resolveSandbox(ctx, positional(input, "sandbox"));
|
|
481
484
|
requireOffer(ctx, sandbox, "archive", "sandbox seed");
|
|
@@ -496,12 +499,15 @@ export const sandboxSeed = {
|
|
|
496
499
|
if (sandbox.writer_owner_run_id)
|
|
497
500
|
ctx.warn(`Run ${sandbox.writer_owner_run_id} holds the Sandbox's writer; the instance refuses a seed until it ends.`);
|
|
498
501
|
const what = archive.files >= 0 ? `${archive.files} files in ${archive.directories} folders` : "the tar archive";
|
|
499
|
-
|
|
500
|
-
|
|
502
|
+
const gate = await confirmation(ctx, input, "sandbox_seed", { sandbox: sandbox.id, harness, revision, sha256: archive.sha256 });
|
|
503
|
+
if (!gate.confirmed) {
|
|
504
|
+
const confirm = gate.confirm(seedCommand(sandbox, input));
|
|
501
505
|
return {
|
|
502
|
-
data: { ...summary, seeded: false, confirm },
|
|
506
|
+
data: { ...summary, seeded: false, confirm, ...gate.fields },
|
|
503
507
|
text: `Would replace the workspace of "${sandbox.name}" (${revision}) with ${what}, ${archive.bytes.length} bytes, sha256 ${archive.sha256}.\n` +
|
|
508
|
+
(gate.mismatch ? `${gate.mismatch}\n` : "") +
|
|
504
509
|
`Nothing was sent. Seed it with: ${confirm}`,
|
|
510
|
+
...(gate.exitCode ? { exitCode: gate.exitCode } : {}),
|
|
505
511
|
};
|
|
506
512
|
}
|
|
507
513
|
const key = stringOption(input, "idempotency-key") !== undefined ? idempotencyKey(input) : stableKey(`seed:${sandbox.id}:${revision}:${archive.sha256}`);
|
package/dist/commands/schema.js
CHANGED
|
@@ -39,14 +39,24 @@ function namedType(schema, raw) {
|
|
|
39
39
|
}
|
|
40
40
|
return undefined;
|
|
41
41
|
}
|
|
42
|
+
function shapeCount(schema, raw) {
|
|
43
|
+
const all = variants(schema, raw);
|
|
44
|
+
return all.length > 1 && all.some((v) => v.node.properties) ? all.length : undefined;
|
|
45
|
+
}
|
|
42
46
|
function typeOf(schema, raw) {
|
|
43
47
|
const node = nonNull(schema, raw);
|
|
44
48
|
const ref = namedType(schema, raw);
|
|
45
49
|
const types = schemaTypes(node).filter((t) => t !== "null");
|
|
46
50
|
if (types.includes("array") && node.items) {
|
|
47
51
|
const item = node.items;
|
|
52
|
+
const shapes = shapeCount(schema, item);
|
|
53
|
+
if (shapes)
|
|
54
|
+
return `list of ${shapes} shapes`;
|
|
48
55
|
return `list of ${refName(item) ?? (schemaTypes(resolve(schema, item)).join("|") || "any")}`;
|
|
49
56
|
}
|
|
57
|
+
const shapes = ref ? undefined : shapeCount(schema, raw);
|
|
58
|
+
if (shapes)
|
|
59
|
+
return `one of ${shapes} shapes`;
|
|
50
60
|
return ref ?? (types.join("|") || "object");
|
|
51
61
|
}
|
|
52
62
|
function fieldsOf(schema, entry) {
|
|
@@ -61,6 +71,7 @@ function fieldsOf(schema, entry) {
|
|
|
61
71
|
required: required.has(name),
|
|
62
72
|
description: description ? clip(description, 160) : null,
|
|
63
73
|
...(Array.isArray(node.enum) ? { enum: node.enum } : {}),
|
|
74
|
+
...(node.const !== undefined ? { const: node.const } : {}),
|
|
64
75
|
...(node.default !== undefined && node.default !== null ? { default: node.default } : {}),
|
|
65
76
|
};
|
|
66
77
|
});
|
|
@@ -92,6 +103,51 @@ function minimal(schema, entry, depth = 0) {
|
|
|
92
103
|
}
|
|
93
104
|
return out;
|
|
94
105
|
}
|
|
106
|
+
function variants(schema, raw, depth = 0) {
|
|
107
|
+
const resolved = resolve(schema, raw);
|
|
108
|
+
const list = (resolved.anyOf ?? resolved.oneOf);
|
|
109
|
+
if (Array.isArray(list) && depth < 10)
|
|
110
|
+
return list.flatMap((b) => variants(schema, b, depth + 1));
|
|
111
|
+
return resolved.type === "null" ? [] : [{ name: refName(raw), node: resolved }];
|
|
112
|
+
}
|
|
113
|
+
function objectShapes(schema, raw) {
|
|
114
|
+
const { list } = entryOf(schema, raw);
|
|
115
|
+
const all = variants(schema, list ? nonNull(schema, raw).items : raw);
|
|
116
|
+
const shapes = all.filter((v) => v.node.properties);
|
|
117
|
+
const others = all.filter((v) => !v.node.properties).map((v) => schemaTypes(v.node).join("|") || "any");
|
|
118
|
+
return { list, shapes, others };
|
|
119
|
+
}
|
|
120
|
+
function nestedOf(schema, shape, at) {
|
|
121
|
+
const props = (shape.properties ?? {});
|
|
122
|
+
return Object.entries(props).flatMap(([field, raw]) => objectShapes(schema, raw).shapes.length ? [{ field, type: typeOf(schema, raw), path: `${at}.${field}` }] : []);
|
|
123
|
+
}
|
|
124
|
+
function itemSamples(schema, items, name, depth) {
|
|
125
|
+
const resolved = resolve(schema, items);
|
|
126
|
+
const list = (resolved.anyOf ?? resolved.oneOf);
|
|
127
|
+
const first = (node) => {
|
|
128
|
+
const at = resolve(schema, node);
|
|
129
|
+
const inner = (at.anyOf ?? at.oneOf);
|
|
130
|
+
return Array.isArray(inner) && inner.length ? first(inner[0]) : at;
|
|
131
|
+
};
|
|
132
|
+
const branches = Array.isArray(list) ? list.map(first).filter((b) => b.type !== "null") : [resolved];
|
|
133
|
+
return branches.map((b) => (b.properties ? fuller(schema, b, depth + 1) : sample(schema, b, name, depth)));
|
|
134
|
+
}
|
|
135
|
+
function fuller(schema, entry, depth = 0) {
|
|
136
|
+
const out = minimal(schema, entry, depth);
|
|
137
|
+
if (depth >= EXAMPLE_DEPTH)
|
|
138
|
+
return out;
|
|
139
|
+
for (const [name, raw] of Object.entries((entry.properties ?? {}))) {
|
|
140
|
+
if (name in out)
|
|
141
|
+
continue;
|
|
142
|
+
const node = nonNull(schema, raw);
|
|
143
|
+
if (!schemaTypes(node).includes("array") || !node.items)
|
|
144
|
+
continue;
|
|
145
|
+
if (!objectShapes(schema, raw).shapes.length)
|
|
146
|
+
continue;
|
|
147
|
+
out[name] = itemSamples(schema, node.items, name, depth);
|
|
148
|
+
}
|
|
149
|
+
return out;
|
|
150
|
+
}
|
|
95
151
|
function fileOf(layout, section) {
|
|
96
152
|
const folder = layout.items[section];
|
|
97
153
|
return folder ? `${folder}/<one file per entry>.yaml` : `${layout.package}/${section}.yaml`;
|
|
@@ -100,18 +156,182 @@ function sourceLine(used) {
|
|
|
100
156
|
const from = used.source === "instance" ? "read from the instance now" : `cached at ${used.fetched_at ?? "an unknown time"}`;
|
|
101
157
|
return `package format ${used.package_version ?? "?"}, ${from}${used.instance_version ? ` (instance ${used.instance_version})` : ""}`;
|
|
102
158
|
}
|
|
159
|
+
function descend(schema, section, keys) {
|
|
160
|
+
let node = schema.properties[section];
|
|
161
|
+
let at = section;
|
|
162
|
+
for (const key of keys) {
|
|
163
|
+
const { shapes } = objectShapes(schema, node);
|
|
164
|
+
const field = shapes.map((s) => s.node.properties[key]).find((f) => f !== undefined);
|
|
165
|
+
if (!field)
|
|
166
|
+
return { at, key, options: [...new Set(shapes.flatMap((s) => nestedOf(schema, s.node, at).map((n) => n.field)))] };
|
|
167
|
+
node = field;
|
|
168
|
+
at = `${at}.${key}`;
|
|
169
|
+
}
|
|
170
|
+
return { node };
|
|
171
|
+
}
|
|
172
|
+
function usesOf(schema, type) {
|
|
173
|
+
const found = [];
|
|
174
|
+
const walk = (raw, at, seen) => {
|
|
175
|
+
for (const shape of objectShapes(schema, raw).shapes) {
|
|
176
|
+
if (shape.name === type)
|
|
177
|
+
found.push(at);
|
|
178
|
+
if (shape.name && seen.has(shape.name))
|
|
179
|
+
continue;
|
|
180
|
+
const next = new Set(seen);
|
|
181
|
+
if (shape.name)
|
|
182
|
+
next.add(shape.name);
|
|
183
|
+
for (const [field, sub] of Object.entries((shape.node.properties ?? {})))
|
|
184
|
+
walk(sub, `${at}.${field}`, next);
|
|
185
|
+
}
|
|
186
|
+
};
|
|
187
|
+
for (const [section, node] of Object.entries(schema.properties ?? {}))
|
|
188
|
+
walk(node, section, new Set());
|
|
189
|
+
return [...new Set(found)];
|
|
190
|
+
}
|
|
191
|
+
function fieldRows(fields) {
|
|
192
|
+
return fields.map((f) => ({
|
|
193
|
+
field: f.name,
|
|
194
|
+
type: f.type,
|
|
195
|
+
required: f.required ? "yes" : "",
|
|
196
|
+
notes: [f.enum ? `one of ${f.enum.map(String).join(", ")}` : "", f.const !== undefined ? `always ${JSON.stringify(f.const)}` : "", f.default !== undefined ? `default ${JSON.stringify(f.default)}` : "", f.description ?? ""]
|
|
197
|
+
.filter(Boolean)
|
|
198
|
+
.join("; "),
|
|
199
|
+
}));
|
|
200
|
+
}
|
|
201
|
+
const yamlOf = (value) => stringify(value, { lineWidth: 0 }).trimEnd();
|
|
202
|
+
function unknownField(found) {
|
|
203
|
+
const near = found.options.filter((o) => o.includes(found.key) || found.key.includes(o)).slice(0, 5);
|
|
204
|
+
const guess = near.length ? `Did you mean: ${near.map((o) => `${found.at}.${o}`).join(", ")}? ` : "";
|
|
205
|
+
return usageError(`The package schema has no nested field "${found.key}" under ${found.at}.`, found.options.length
|
|
206
|
+
? `${guess}Nested under ${found.at}: ${found.options.join(", ")}.`
|
|
207
|
+
: `Nothing under ${found.at} has fields of its own; \`cavelon schema ${found.at}\` shows its fields.`);
|
|
208
|
+
}
|
|
209
|
+
function findTarget(schema, name) {
|
|
210
|
+
const defs = (schema.$defs ?? {});
|
|
211
|
+
const [section, ...keys] = name.split(".");
|
|
212
|
+
if (section && schema.properties[section]) {
|
|
213
|
+
const found = descend(schema, section, keys);
|
|
214
|
+
if ("options" in found)
|
|
215
|
+
throw unknownField(found);
|
|
216
|
+
return { name, node: found.node, at: name, nested: keys.length > 0 };
|
|
217
|
+
}
|
|
218
|
+
if (!keys.length && Object.hasOwn(defs, name)) {
|
|
219
|
+
const usedIn = usesOf(schema, name);
|
|
220
|
+
return { name, node: { $ref: `#/$defs/${name}` }, at: usedIn[0] ?? name, nested: false, usedIn };
|
|
221
|
+
}
|
|
222
|
+
const lower = name.toLowerCase();
|
|
223
|
+
const near = [...Object.keys(schema.properties), ...Object.keys(defs)].filter((s) => s.toLowerCase().includes(lower) || lower.includes(s.toLowerCase())).slice(0, 5);
|
|
224
|
+
throw usageError(`The package schema has no section or type "${name}".`, near.length ? `Did you mean: ${near.join(", ")}? (\`cavelon schema\` lists them)` : "`cavelon schema` lists the sections.");
|
|
225
|
+
}
|
|
226
|
+
function targetData(schema, target, context) {
|
|
227
|
+
const { node, usedIn } = target;
|
|
228
|
+
const top = (usedIn?.[0] ?? target.name).split(".")[0];
|
|
229
|
+
const { list, shapes, others } = objectShapes(schema, node);
|
|
230
|
+
const one = shapes.length === 1 ? shapes[0] : undefined;
|
|
231
|
+
const wrap = (value) => (list ? [value] : value);
|
|
232
|
+
const minimalOne = one ? minimal(schema, one.node) : undefined;
|
|
233
|
+
const fullOne = one ? fuller(schema, one.node) : undefined;
|
|
234
|
+
const fullDiffers = fullOne !== undefined && JSON.stringify(fullOne) !== JSON.stringify(minimalOne);
|
|
235
|
+
const entry = one?.name ?? (list ? namedType(schema, nonNull(schema, node).items) : namedType(schema, node));
|
|
236
|
+
const unused = usedIn !== undefined && usedIn.length === 0;
|
|
237
|
+
return {
|
|
238
|
+
schema: context.used,
|
|
239
|
+
section: unused ? null : top,
|
|
240
|
+
path: usedIn ? (usedIn[0] ?? null) : target.name,
|
|
241
|
+
...(usedIn ? { used_in: usedIn } : {}),
|
|
242
|
+
kind: list ? "list" : "object",
|
|
243
|
+
required: !usedIn && !target.nested ? context.required.has(target.name) : false,
|
|
244
|
+
file: unused ? null : fileOf(context.layout, top),
|
|
245
|
+
entry: entry ?? null,
|
|
246
|
+
fields: one ? fieldsOf(schema, one.node) : [],
|
|
247
|
+
example: minimalOne === undefined ? null : wrap(minimalOne),
|
|
248
|
+
...(fullDiffers ? { nested_example: wrap(fullOne) } : {}),
|
|
249
|
+
nested: one ? nestedOf(schema, one.node, target.at) : [],
|
|
250
|
+
...(shapes.length > 1
|
|
251
|
+
? { shapes: shapes.map((s) => ({ type: s.name ?? null, fields: fieldsOf(schema, s.node), example: minimal(schema, s.node) })), other_shapes: others }
|
|
252
|
+
: {}),
|
|
253
|
+
};
|
|
254
|
+
}
|
|
255
|
+
function headLines(target, data, used) {
|
|
256
|
+
if (target.usedIn) {
|
|
257
|
+
const where = target.usedIn.length ? target.usedIn.join(", ") : "not used by any section";
|
|
258
|
+
return keyValues([
|
|
259
|
+
["type", `${target.name} (an object)`],
|
|
260
|
+
["used at", where],
|
|
261
|
+
["file", data.file ?? "(none)"],
|
|
262
|
+
["schema", sourceLine(used)],
|
|
263
|
+
]);
|
|
264
|
+
}
|
|
265
|
+
const what = data.kind === "list" ? "a list of entries" : "one object";
|
|
266
|
+
const each = data.entry ? `, each ${withArticle(data.entry)}` : "";
|
|
267
|
+
return keyValues([
|
|
268
|
+
[target.nested ? "field" : "section", `${target.name} (${what}${each})`],
|
|
269
|
+
["file", data.file ?? "(none)"],
|
|
270
|
+
["schema", sourceLine(used)],
|
|
271
|
+
]);
|
|
272
|
+
}
|
|
273
|
+
const FIELD_COLUMNS = ["field", "type", "required", "notes"];
|
|
274
|
+
function shapeLines(data) {
|
|
275
|
+
const shapes = data.shapes ?? [];
|
|
276
|
+
const others = data.other_shapes ?? [];
|
|
277
|
+
const besides = others.length ? ` (${others.map(withArticle).join(", ")}, or an object below)` : "";
|
|
278
|
+
const lines = [`Each entry takes one of ${shapes.length + others.length} shapes${besides}:`, ""];
|
|
279
|
+
for (const shape of shapes) {
|
|
280
|
+
const example = data.kind === "list" ? [shape.example] : shape.example;
|
|
281
|
+
lines.push(`${shape.type ?? "object"}:`, table(fieldRows(shape.fields), FIELD_COLUMNS), yamlOf(example), "");
|
|
282
|
+
}
|
|
283
|
+
return lines;
|
|
284
|
+
}
|
|
285
|
+
function fieldLines(data) {
|
|
286
|
+
const empty = data.example === null || Object.keys((Array.isArray(data.example) ? data.example[0] : data.example)).length === 0;
|
|
287
|
+
const lines = [
|
|
288
|
+
data.fields.length ? table(fieldRows(data.fields), FIELD_COLUMNS) : "No fields are published here.",
|
|
289
|
+
"",
|
|
290
|
+
empty ? "No field is required; the smallest entry is empty:" : "Minimal example (required fields only):",
|
|
291
|
+
yamlOf(data.example),
|
|
292
|
+
];
|
|
293
|
+
if (data.nested_example)
|
|
294
|
+
lines.push("", "With one entry of each nested list:", yamlOf(data.nested_example));
|
|
295
|
+
if (data.nested.length) {
|
|
296
|
+
const rows = data.nested.map((n) => ({ command: `cavelon schema ${n.path}`, type: n.type }));
|
|
297
|
+
lines.push("", "Fields with fields of their own:", table(rows, ["command", "type"], 60, ["command"]));
|
|
298
|
+
}
|
|
299
|
+
return lines;
|
|
300
|
+
}
|
|
301
|
+
function withArticle(type) {
|
|
302
|
+
return `${/^[aeiou]/i.test(type) ? "an" : "a"} ${type}`;
|
|
303
|
+
}
|
|
304
|
+
function targetLines(schema, target, data, used) {
|
|
305
|
+
const head = [headLines(target, data, used), ""];
|
|
306
|
+
if (data.shapes)
|
|
307
|
+
return [...head, ...shapeLines(data)];
|
|
308
|
+
if (data.example !== null)
|
|
309
|
+
return [...head, ...fieldLines(data)];
|
|
310
|
+
const { list, others } = objectShapes(schema, target.node);
|
|
311
|
+
const type = others.map(withArticle).join(" or ") || withArticle(typeOf(schema, entryOf(schema, target.node).entry));
|
|
312
|
+
return [...head, `${list ? "Each entry is" : "It is"} ${type}; there are no fields to list.`];
|
|
313
|
+
}
|
|
103
314
|
export const schema = {
|
|
104
315
|
name: "schema",
|
|
105
|
-
summary: "Show the package schema the instance publishes: its sections, or
|
|
106
|
-
description: "Without
|
|
107
|
-
"allowed values, default) and prints the smallest entry that has every required field, ready to copy into the file
|
|
108
|
-
"
|
|
316
|
+
summary: "Show the package schema the instance publishes: its sections, or the fields of a section or a nested type, with a minimal example.",
|
|
317
|
+
description: "Without an argument, lists the sections with the file each is kept in. With a section, lists its fields (type, required,\n" +
|
|
318
|
+
"allowed values, default) and prints the smallest entry that has every required field, ready to copy into the file, and an\n" +
|
|
319
|
+
"example with one entry of each nested list. A field whose entries have fields of their own is reached by its path\n" +
|
|
320
|
+
"(`agents.handoffs`, `test_suites.test_cases.steps`) or by its type's name (`PackageAgentHandoff`); the section's\n" +
|
|
321
|
+
"output names them. Where entries take one of several shapes (a step's evaluation_criteria: a text, a judge criterion, an\n" +
|
|
322
|
+
"assertion by type), each shape is listed with its fields. Placeholders are written <field>. Reads the schema as `validate`\n" +
|
|
323
|
+
"does: the cached copy first, the instance otherwise.",
|
|
109
324
|
readOnly: true,
|
|
110
325
|
idempotent: true,
|
|
111
326
|
mcpTool: "package_schema",
|
|
112
|
-
positionals: [
|
|
327
|
+
positionals: [
|
|
328
|
+
{
|
|
329
|
+
name: "section",
|
|
330
|
+
description: "A section of the package (agents), a path to a nested field (agents.handoffs, test_suites.test_cases.steps), or a type name (PackageAgentHandoff).",
|
|
331
|
+
},
|
|
332
|
+
],
|
|
113
333
|
options: { offline: { type: "boolean", description: "Use only the cached schema; never contact the instance." } },
|
|
114
|
-
examples: ["cavelon schema", "cavelon schema agents", "cavelon schema
|
|
334
|
+
examples: ["cavelon schema", "cavelon schema agents", "cavelon schema agents.handoffs", "cavelon schema test_suites.test_cases.steps.evaluation_criteria --json"],
|
|
115
335
|
async run(ctx, input) {
|
|
116
336
|
const session = await ctx.session();
|
|
117
337
|
requireInstance(session);
|
|
@@ -144,50 +364,12 @@ export const schema = {
|
|
|
144
364
|
"",
|
|
145
365
|
table(items, ["section", "kind", "required", "file"]),
|
|
146
366
|
"",
|
|
147
|
-
"One section's fields and a minimal example: cavelon schema <section>",
|
|
367
|
+
"One section's fields and a minimal example: cavelon schema <section>; a nested field's: cavelon schema <section>.<field>",
|
|
148
368
|
].join("\n"),
|
|
149
369
|
};
|
|
150
370
|
}
|
|
151
|
-
const
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
throw usageError(`The package schema has no section "${name}".`, near.length ? `Did you mean: ${near.join(", ")}? (\`cavelon schema\` lists them)` : "`cavelon schema` lists the sections.");
|
|
155
|
-
}
|
|
156
|
-
const { list, entry } = entryOf(published, node);
|
|
157
|
-
const fields = fieldsOf(published, entry);
|
|
158
|
-
const one = minimal(published, entry);
|
|
159
|
-
const example = list ? [one] : one;
|
|
160
|
-
const exampleYaml = stringify(example, { lineWidth: 0 });
|
|
161
|
-
const data = {
|
|
162
|
-
schema: used,
|
|
163
|
-
section: name,
|
|
164
|
-
kind: list ? "list" : "object",
|
|
165
|
-
required: required.has(name),
|
|
166
|
-
file: fileOf(layout, name),
|
|
167
|
-
entry: (list ? namedType(published, nonNull(published, node).items) : namedType(published, node)) ?? null,
|
|
168
|
-
fields,
|
|
169
|
-
example,
|
|
170
|
-
};
|
|
171
|
-
const rows = fields.map((f) => ({
|
|
172
|
-
field: f.name,
|
|
173
|
-
type: f.type,
|
|
174
|
-
required: f.required ? "yes" : "",
|
|
175
|
-
notes: [f.enum ? `one of ${f.enum.map(String).join(", ")}` : "", f.default !== undefined ? `default ${JSON.stringify(f.default)}` : "", f.description ?? ""]
|
|
176
|
-
.filter(Boolean)
|
|
177
|
-
.join("; "),
|
|
178
|
-
}));
|
|
179
|
-
const text = [
|
|
180
|
-
keyValues([
|
|
181
|
-
["section", `${name} (${list ? "a list of entries" : "one object"}${data.entry ? `, each a ${data.entry}` : ""})`],
|
|
182
|
-
["file", data.file],
|
|
183
|
-
["schema", sourceLine(used)],
|
|
184
|
-
]),
|
|
185
|
-
"",
|
|
186
|
-
rows.length ? table(rows, ["field", "type", "required", "notes"]) : "No fields are published for this section.",
|
|
187
|
-
"",
|
|
188
|
-
Object.keys(one).length ? "Minimal example (required fields only):" : "No field is required; the smallest entry is empty:",
|
|
189
|
-
exampleYaml.trimEnd(),
|
|
190
|
-
].join("\n");
|
|
191
|
-
return { data, text };
|
|
371
|
+
const target = findTarget(published, name);
|
|
372
|
+
const data = targetData(published, target, { used, layout, required });
|
|
373
|
+
return { data, text: targetLines(published, target, data, used).join("\n").trimEnd() };
|
|
192
374
|
},
|
|
193
375
|
};
|
package/dist/commands/session.js
CHANGED
|
@@ -4,6 +4,7 @@ import { compareContracts, Contracts } from "../contracts.js";
|
|
|
4
4
|
import { deleteToken, saveToken } from "../credentials.js";
|
|
5
5
|
import { CavelonError, ExitCode, usageError } from "../errors.js";
|
|
6
6
|
import { keyValues } from "../format.js";
|
|
7
|
+
import { callStable } from "../invoke.js";
|
|
7
8
|
import { formatQuota, formatValue, limitRef, readLimits, readQuotas } from "../limits.js";
|
|
8
9
|
import { ApiClient, tokensDisabledError } from "../http.js";
|
|
9
10
|
import { readAll } from "../io.js";
|
|
@@ -13,7 +14,7 @@ import { expiryOf, readPrincipal, readTenantless } from "../principal.js";
|
|
|
13
14
|
import { readHidden } from "../prompt.js";
|
|
14
15
|
import { isUuid, lookupTenantId, requireInstance, requireToken, tenantRequiredError } from "../session.js";
|
|
15
16
|
import { cavelonCommand } from "../shell.js";
|
|
16
|
-
import { choicesOf, chooseTenant, commandLines, listsTenants, noTenantError, tenantOpenError, tenantRef, tenantTitle } from "../tenant-choice.js";
|
|
17
|
+
import { choicesOf, chooseTenant, commandLines, describeTenant, listsTenants, noTenantError, tenantOpenError, tenantRef, tenantTitle } from "../tenant-choice.js";
|
|
17
18
|
import { loadUserConfig, saveUserConfig, tokenKind, updateInstance } from "../user-config.js";
|
|
18
19
|
async function readCapabilities(contracts, refresh) {
|
|
19
20
|
const caps = await contracts.capabilities({ refresh });
|
|
@@ -268,6 +269,22 @@ export const logout = {
|
|
|
268
269
|
return { data: { logged_out: results }, text: text || "No stored logins." };
|
|
269
270
|
},
|
|
270
271
|
};
|
|
272
|
+
function tenantSourceText(session) {
|
|
273
|
+
switch (session.tenantSource) {
|
|
274
|
+
case undefined:
|
|
275
|
+
return undefined;
|
|
276
|
+
case "option":
|
|
277
|
+
return "--tenant";
|
|
278
|
+
case "CAVELON_TENANT":
|
|
279
|
+
return "the CAVELON_TENANT variable";
|
|
280
|
+
case "use":
|
|
281
|
+
return session.project
|
|
282
|
+
? "`cavelon use` (this folder's cavelon.yaml names no tenant for this instance)"
|
|
283
|
+
: "`cavelon use`, for every folder without a cavelon.yaml (--tenant chooses another for one command)";
|
|
284
|
+
default:
|
|
285
|
+
return session.tenantSource;
|
|
286
|
+
}
|
|
287
|
+
}
|
|
271
288
|
function credentialSource(session) {
|
|
272
289
|
if (session.tokenSource === "CAVELON_TOKEN")
|
|
273
290
|
return "CAVELON_TOKEN";
|
|
@@ -326,8 +343,13 @@ export const whoami = {
|
|
|
326
343
|
}
|
|
327
344
|
const listed = reach?.tenants.find((t) => t.id === contextTenant);
|
|
328
345
|
const stored = session.settings.tenant_id === contextTenant ? session.settings : undefined;
|
|
329
|
-
|
|
330
|
-
|
|
346
|
+
let tenantName = listed?.name ?? membership?.tenant_name ?? stored?.tenant_name ?? null;
|
|
347
|
+
let tenantSlug = listed?.slug ?? membership?.tenant_slug ?? stored?.tenant_slug ?? null;
|
|
348
|
+
if (contextTenant && (!tenantName || !tenantSlug)) {
|
|
349
|
+
const described = await describeTenant(client, contextTenant);
|
|
350
|
+
tenantName ??= described.name ?? null;
|
|
351
|
+
tenantSlug ??= described.slug ?? null;
|
|
352
|
+
}
|
|
331
353
|
if (nowhere && reach) {
|
|
332
354
|
ctx.warn(reach.tenants.length
|
|
333
355
|
? `No tenant is chosen. Choose one with \`cavelon use\`, or run the line for the tenant you want:\n${commandLines(reach.tenants, (r) => cavelonCommand("use", r))}`
|
|
@@ -394,7 +416,7 @@ export const whoami = {
|
|
|
394
416
|
["instance", `${session.url} (${session.urlSource})`],
|
|
395
417
|
["acting as", owner],
|
|
396
418
|
["tenant", contextTenant ? tenantTitle({ id: contextTenant, name: tenantName, slug: tenantSlug }) : nowhere ? "none chosen (`cavelon use` chooses one)" : "none (Platform mode)"],
|
|
397
|
-
["tenant from", session.tenant ? session
|
|
419
|
+
["tenant from", session.tenant ? tenantSourceText(session) : nowhere ? undefined : "the token's default"],
|
|
398
420
|
["role", data.role ?? undefined],
|
|
399
421
|
["credential", `${session.tokenKind === "api_key" ? "tenant API key" : session.tokenKind === "personal_access_token" ? "personal access token" : "token"}${tokenName} from ${credentialSource(session)}`],
|
|
400
422
|
["expires", expires],
|
|
@@ -540,7 +562,7 @@ export const status = {
|
|
|
540
562
|
root: session.project.root,
|
|
541
563
|
harness: session.project.harness ?? null,
|
|
542
564
|
last_pull: (await readPull(session.project.root)) ?? null,
|
|
543
|
-
open_previews: await listPreviews(session.project.root),
|
|
565
|
+
open_previews: await listPreviews(session.project.root, ctx.io.now()),
|
|
544
566
|
}
|
|
545
567
|
: null,
|
|
546
568
|
logged_in_at: session.settings.logged_in_at ?? null,
|
|
@@ -563,8 +585,15 @@ export const status = {
|
|
|
563
585
|
if (!offline && session.url && session.token) {
|
|
564
586
|
try {
|
|
565
587
|
client = await ctx.client();
|
|
566
|
-
|
|
567
|
-
|
|
588
|
+
const tenantId = client.target.tenantId;
|
|
589
|
+
if (tenantId) {
|
|
590
|
+
const shown = data.tenant;
|
|
591
|
+
shown.id = tenantId;
|
|
592
|
+
const stored = session.settings.tenant_id === tenantId ? session.settings : undefined;
|
|
593
|
+
const described = stored?.tenant_name && stored.tenant_slug ? {} : await describeTenant(client, tenantId);
|
|
594
|
+
shown.name = stored?.tenant_name ?? described.name ?? null;
|
|
595
|
+
shown.slug = stored?.tenant_slug ?? described.slug ?? null;
|
|
596
|
+
}
|
|
568
597
|
const contracts = await ctx.contracts();
|
|
569
598
|
const caps = await contracts.liveCapabilities();
|
|
570
599
|
data.instance_version = caps?.instance.version ?? null;
|
|
@@ -578,7 +607,7 @@ export const status = {
|
|
|
578
607
|
});
|
|
579
608
|
operations = page.status === 200 ? page.data.items : undefined;
|
|
580
609
|
data.operations = operations
|
|
581
|
-
? { items: operations, more: Boolean(page.data.next_cursor) }
|
|
610
|
+
? { items: operations, more: Boolean(page.data.next_cursor), scope: "tenant" }
|
|
582
611
|
: { unavailable: "This instance does not offer /api/v1/operations." };
|
|
583
612
|
}
|
|
584
613
|
else {
|
|
@@ -591,8 +620,19 @@ export const status = {
|
|
|
591
620
|
published = limits.published;
|
|
592
621
|
data.limits = limits.data;
|
|
593
622
|
const ref = session.envFile?.harness ?? session.project?.harness;
|
|
594
|
-
if (session.project && ref)
|
|
595
|
-
|
|
623
|
+
if (session.project && ref) {
|
|
624
|
+
const state = await solutionState(ctx, ref);
|
|
625
|
+
data.solution.state = state;
|
|
626
|
+
if (operations && state.harness) {
|
|
627
|
+
const owners = await operationSolutions(ctx, operations);
|
|
628
|
+
const others = operations.filter((o) => owners.get(o.id) && owners.get(o.id) !== state.harness.id);
|
|
629
|
+
if (others.length) {
|
|
630
|
+
operations = operations.filter((o) => !others.includes(o));
|
|
631
|
+
data.operations = { ...data.operations, items: operations, other_solutions: others.length };
|
|
632
|
+
}
|
|
633
|
+
data.operations = { ...data.operations, scope: "solution", harness: state.harness.slug };
|
|
634
|
+
}
|
|
635
|
+
}
|
|
596
636
|
}
|
|
597
637
|
}
|
|
598
638
|
catch (error) {
|
|
@@ -600,8 +640,9 @@ export const status = {
|
|
|
600
640
|
data.error = error instanceof CavelonError ? error.toJSON() : { message: reachError };
|
|
601
641
|
}
|
|
602
642
|
}
|
|
643
|
+
const shownTenant = data.tenant;
|
|
603
644
|
const tenantText = session.tenant
|
|
604
|
-
? `${session.tenant}
|
|
645
|
+
? `${shownTenant?.id && (shownTenant.name || shownTenant.slug) ? tenantTitle({ id: shownTenant.id, name: shownTenant.name, slug: shownTenant.slug }) : session.tenant}, from ${tenantSourceText(session)}`
|
|
605
646
|
: session.tokenKind === "api_key"
|
|
606
647
|
? "the API key's tenant"
|
|
607
648
|
: "not chosen (`cavelon use` lists your tenants to choose from)";
|
|
@@ -621,7 +662,9 @@ export const status = {
|
|
|
621
662
|
lines.push([
|
|
622
663
|
"open previews",
|
|
623
664
|
solution.open_previews.length
|
|
624
|
-
? solution.open_previews
|
|
665
|
+
? solution.open_previews
|
|
666
|
+
.map((p) => `\n ${p.preview_id}${p.env ? ` env ${p.env}` : ""} ${p.created_at} ${p.expired ? "expired (`cavelon apply --discard all` removes it)" : `expires ${p.expires_at}`}`)
|
|
667
|
+
.join("")
|
|
625
668
|
: "none",
|
|
626
669
|
]);
|
|
627
670
|
}
|
|
@@ -642,18 +685,61 @@ export const status = {
|
|
|
642
685
|
const waiting = waits.flatMap((wait, i) => (wait ? [{ operation_id: operations[i].id, ...wait }] : []));
|
|
643
686
|
if (waiting.length)
|
|
644
687
|
data.capacity_waits = waiting;
|
|
688
|
+
const ops = data.operations;
|
|
689
|
+
const others = ops.other_solutions
|
|
690
|
+
? ` (${ops.other_solutions} operation${ops.other_solutions === 1 ? "" : "s"} of other solutions not shown; \`cavelon api list_operations_route\` lists all)`
|
|
691
|
+
: "";
|
|
692
|
+
const heading = ops.scope === "solution" ? `Running operations of ${ops.harness} and the tenant's shared work${others}` : "Running operations in the tenant";
|
|
645
693
|
text += operations.length
|
|
646
|
-
? `\n\
|
|
694
|
+
? `\n\n${heading}:\n${operations
|
|
647
695
|
.map((o, i) => {
|
|
648
696
|
const wait = waits[i];
|
|
649
697
|
return ` ${o.id} ${o.kind} ${o.status}${o.progress?.phase ? ` (${o.progress.phase})` : ""}${wait ? ` ${wait.note}` : ""}`;
|
|
650
698
|
})
|
|
651
699
|
.join("\n")}`
|
|
652
|
-
:
|
|
700
|
+
: `\n\nNo running operations${ops.scope === "solution" ? ` of ${ops.harness}${others}` : " in the tenant"}.`;
|
|
653
701
|
}
|
|
654
702
|
return { data, text };
|
|
655
703
|
},
|
|
656
704
|
};
|
|
705
|
+
async function operationSolutions(ctx, operations) {
|
|
706
|
+
const owners = new Map();
|
|
707
|
+
const triggers = new Map();
|
|
708
|
+
const triggerSolution = (id) => {
|
|
709
|
+
if (!triggers.has(id)) {
|
|
710
|
+
triggers.set(id, callStable(ctx, "GET", "/api/v1/triggers/{trigger_id}", "reading triggers", { params: { trigger_id: [id] } }).then((t) => t.harness_id ?? undefined, () => undefined));
|
|
711
|
+
}
|
|
712
|
+
return triggers.get(id);
|
|
713
|
+
};
|
|
714
|
+
for (const op of operations) {
|
|
715
|
+
const harnessId = op.harness_id;
|
|
716
|
+
if (typeof harnessId === "string" && harnessId) {
|
|
717
|
+
owners.set(op.id, harnessId);
|
|
718
|
+
continue;
|
|
719
|
+
}
|
|
720
|
+
const ref = op.result_ref;
|
|
721
|
+
if (!ref?.id)
|
|
722
|
+
continue;
|
|
723
|
+
try {
|
|
724
|
+
if (ref.type === "test_run") {
|
|
725
|
+
const run = await callStable(ctx, "GET", "/api/v1/test-runs/{run_id}", "test runs", { params: { run_id: [ref.id] } });
|
|
726
|
+
if (run.harness_id)
|
|
727
|
+
owners.set(op.id, run.harness_id);
|
|
728
|
+
}
|
|
729
|
+
else if (ref.type === "agent_run") {
|
|
730
|
+
const run = await callStable(ctx, "GET", "/api/v1/triggers/runs/{run_id}", "reading runs", {
|
|
731
|
+
params: { run_id: [ref.id] },
|
|
732
|
+
});
|
|
733
|
+
const owner = run.harness_id ?? (run.trigger_definition_id ? await triggerSolution(run.trigger_definition_id) : undefined);
|
|
734
|
+
if (owner)
|
|
735
|
+
owners.set(op.id, owner);
|
|
736
|
+
}
|
|
737
|
+
}
|
|
738
|
+
catch {
|
|
739
|
+
}
|
|
740
|
+
}
|
|
741
|
+
return owners;
|
|
742
|
+
}
|
|
657
743
|
export async function rememberTenant(ctx, url, tenant) {
|
|
658
744
|
await updateInstance(ctx.io.env, url, (c) => ({
|
|
659
745
|
...c,
|