@cavelon/cli 0.1.5 → 0.1.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +17 -7
- package/dist/commands/api.js +40 -36
- package/dist/commands/chat.js +177 -0
- package/dist/commands/docs.js +62 -5
- package/dist/commands/fmt.js +5 -2
- package/dist/commands/index.js +3 -0
- package/dist/commands/init.js +38 -26
- package/dist/commands/inventory.js +21 -0
- package/dist/commands/limits-set.js +9 -6
- package/dist/commands/loops.js +15 -9
- package/dist/commands/models.js +9 -6
- package/dist/commands/sandboxes.js +8 -4
- package/dist/commands/schema.js +216 -48
- package/dist/commands/session.js +81 -13
- package/dist/commands/setup.js +22 -6
- package/dist/commands/solution.js +318 -66
- package/dist/commands/tenants.js +37 -6
- package/dist/commands/values.js +18 -9
- package/dist/commands/work.js +110 -23
- package/dist/confirm-token.js +72 -0
- package/dist/harness-ref.js +14 -1
- package/dist/kit-codes.js +7 -1
- package/dist/local-state.js +28 -10
- package/dist/main.js +36 -1
- package/dist/mcp.js +63 -14
- package/dist/openapi.js +30 -0
- package/dist/package-check.js +177 -17
- package/dist/package-files.js +75 -39
- package/dist/package-format.js +81 -8
- package/dist/package-references.js +77 -10
- package/dist/results.js +21 -1
- package/dist/skills/cavelon-authoring/SKILL.md +47 -18
- package/dist/skills/cavelon-loop/SKILL.md +91 -27
- package/dist/skills/cavelon-testing/SKILL.md +69 -16
- package/dist/tenant-choice.js +19 -0
- package/dist/trace-view.js +172 -0
- package/package.json +1 -1
package/dist/commands/schema.js
CHANGED
|
@@ -61,6 +61,7 @@ function fieldsOf(schema, entry) {
|
|
|
61
61
|
required: required.has(name),
|
|
62
62
|
description: description ? clip(description, 160) : null,
|
|
63
63
|
...(Array.isArray(node.enum) ? { enum: node.enum } : {}),
|
|
64
|
+
...(node.const !== undefined ? { const: node.const } : {}),
|
|
64
65
|
...(node.default !== undefined && node.default !== null ? { default: node.default } : {}),
|
|
65
66
|
};
|
|
66
67
|
});
|
|
@@ -92,6 +93,51 @@ function minimal(schema, entry, depth = 0) {
|
|
|
92
93
|
}
|
|
93
94
|
return out;
|
|
94
95
|
}
|
|
96
|
+
function variants(schema, raw, depth = 0) {
|
|
97
|
+
const resolved = resolve(schema, raw);
|
|
98
|
+
const list = (resolved.anyOf ?? resolved.oneOf);
|
|
99
|
+
if (Array.isArray(list) && depth < 10)
|
|
100
|
+
return list.flatMap((b) => variants(schema, b, depth + 1));
|
|
101
|
+
return resolved.type === "null" ? [] : [{ name: refName(raw), node: resolved }];
|
|
102
|
+
}
|
|
103
|
+
function objectShapes(schema, raw) {
|
|
104
|
+
const { list } = entryOf(schema, raw);
|
|
105
|
+
const all = variants(schema, list ? nonNull(schema, raw).items : raw);
|
|
106
|
+
const shapes = all.filter((v) => v.node.properties);
|
|
107
|
+
const others = all.filter((v) => !v.node.properties).map((v) => schemaTypes(v.node).join("|") || "any");
|
|
108
|
+
return { list, shapes, others };
|
|
109
|
+
}
|
|
110
|
+
function nestedOf(schema, shape, at) {
|
|
111
|
+
const props = (shape.properties ?? {});
|
|
112
|
+
return Object.entries(props).flatMap(([field, raw]) => objectShapes(schema, raw).shapes.length ? [{ field, type: typeOf(schema, raw), path: `${at}.${field}` }] : []);
|
|
113
|
+
}
|
|
114
|
+
function itemSamples(schema, items, name, depth) {
|
|
115
|
+
const resolved = resolve(schema, items);
|
|
116
|
+
const list = (resolved.anyOf ?? resolved.oneOf);
|
|
117
|
+
const first = (node) => {
|
|
118
|
+
const at = resolve(schema, node);
|
|
119
|
+
const inner = (at.anyOf ?? at.oneOf);
|
|
120
|
+
return Array.isArray(inner) && inner.length ? first(inner[0]) : at;
|
|
121
|
+
};
|
|
122
|
+
const branches = Array.isArray(list) ? list.map(first).filter((b) => b.type !== "null") : [resolved];
|
|
123
|
+
return branches.map((b) => (b.properties ? fuller(schema, b, depth + 1) : sample(schema, b, name, depth)));
|
|
124
|
+
}
|
|
125
|
+
function fuller(schema, entry, depth = 0) {
|
|
126
|
+
const out = minimal(schema, entry, depth);
|
|
127
|
+
if (depth >= EXAMPLE_DEPTH)
|
|
128
|
+
return out;
|
|
129
|
+
for (const [name, raw] of Object.entries((entry.properties ?? {}))) {
|
|
130
|
+
if (name in out)
|
|
131
|
+
continue;
|
|
132
|
+
const node = nonNull(schema, raw);
|
|
133
|
+
if (!schemaTypes(node).includes("array") || !node.items)
|
|
134
|
+
continue;
|
|
135
|
+
if (!objectShapes(schema, raw).shapes.length)
|
|
136
|
+
continue;
|
|
137
|
+
out[name] = itemSamples(schema, node.items, name, depth);
|
|
138
|
+
}
|
|
139
|
+
return out;
|
|
140
|
+
}
|
|
95
141
|
function fileOf(layout, section) {
|
|
96
142
|
const folder = layout.items[section];
|
|
97
143
|
return folder ? `${folder}/<one file per entry>.yaml` : `${layout.package}/${section}.yaml`;
|
|
@@ -100,18 +146,178 @@ function sourceLine(used) {
|
|
|
100
146
|
const from = used.source === "instance" ? "read from the instance now" : `cached at ${used.fetched_at ?? "an unknown time"}`;
|
|
101
147
|
return `package format ${used.package_version ?? "?"}, ${from}${used.instance_version ? ` (instance ${used.instance_version})` : ""}`;
|
|
102
148
|
}
|
|
149
|
+
function descend(schema, section, keys) {
|
|
150
|
+
let node = schema.properties[section];
|
|
151
|
+
let at = section;
|
|
152
|
+
for (const key of keys) {
|
|
153
|
+
const { shapes } = objectShapes(schema, node);
|
|
154
|
+
const field = shapes.map((s) => s.node.properties[key]).find((f) => f !== undefined);
|
|
155
|
+
if (!field)
|
|
156
|
+
return { at, key, options: [...new Set(shapes.flatMap((s) => nestedOf(schema, s.node, at).map((n) => n.field)))] };
|
|
157
|
+
node = field;
|
|
158
|
+
at = `${at}.${key}`;
|
|
159
|
+
}
|
|
160
|
+
return { node };
|
|
161
|
+
}
|
|
162
|
+
function usesOf(schema, type) {
|
|
163
|
+
const found = [];
|
|
164
|
+
const walk = (raw, at, seen) => {
|
|
165
|
+
for (const shape of objectShapes(schema, raw).shapes) {
|
|
166
|
+
if (shape.name === type)
|
|
167
|
+
found.push(at);
|
|
168
|
+
if (shape.name && seen.has(shape.name))
|
|
169
|
+
continue;
|
|
170
|
+
const next = new Set(seen);
|
|
171
|
+
if (shape.name)
|
|
172
|
+
next.add(shape.name);
|
|
173
|
+
for (const [field, sub] of Object.entries((shape.node.properties ?? {})))
|
|
174
|
+
walk(sub, `${at}.${field}`, next);
|
|
175
|
+
}
|
|
176
|
+
};
|
|
177
|
+
for (const [section, node] of Object.entries(schema.properties ?? {}))
|
|
178
|
+
walk(node, section, new Set());
|
|
179
|
+
return [...new Set(found)];
|
|
180
|
+
}
|
|
181
|
+
function fieldRows(fields) {
|
|
182
|
+
return fields.map((f) => ({
|
|
183
|
+
field: f.name,
|
|
184
|
+
type: f.type,
|
|
185
|
+
required: f.required ? "yes" : "",
|
|
186
|
+
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 ?? ""]
|
|
187
|
+
.filter(Boolean)
|
|
188
|
+
.join("; "),
|
|
189
|
+
}));
|
|
190
|
+
}
|
|
191
|
+
const yamlOf = (value) => stringify(value, { lineWidth: 0 }).trimEnd();
|
|
192
|
+
function unknownField(found) {
|
|
193
|
+
const near = found.options.filter((o) => o.includes(found.key) || found.key.includes(o)).slice(0, 5);
|
|
194
|
+
const guess = near.length ? `Did you mean: ${near.map((o) => `${found.at}.${o}`).join(", ")}? ` : "";
|
|
195
|
+
return usageError(`The package schema has no nested field "${found.key}" under ${found.at}.`, found.options.length
|
|
196
|
+
? `${guess}Nested under ${found.at}: ${found.options.join(", ")}.`
|
|
197
|
+
: `Nothing under ${found.at} has fields of its own; \`cavelon schema ${found.at}\` shows its fields.`);
|
|
198
|
+
}
|
|
199
|
+
function findTarget(schema, name) {
|
|
200
|
+
const defs = (schema.$defs ?? {});
|
|
201
|
+
const [section, ...keys] = name.split(".");
|
|
202
|
+
if (section && schema.properties[section]) {
|
|
203
|
+
const found = descend(schema, section, keys);
|
|
204
|
+
if ("options" in found)
|
|
205
|
+
throw unknownField(found);
|
|
206
|
+
return { name, node: found.node, at: name, nested: keys.length > 0 };
|
|
207
|
+
}
|
|
208
|
+
if (!keys.length && Object.hasOwn(defs, name)) {
|
|
209
|
+
const usedIn = usesOf(schema, name);
|
|
210
|
+
return { name, node: { $ref: `#/$defs/${name}` }, at: usedIn[0] ?? name, nested: false, usedIn };
|
|
211
|
+
}
|
|
212
|
+
const lower = name.toLowerCase();
|
|
213
|
+
const near = [...Object.keys(schema.properties), ...Object.keys(defs)].filter((s) => s.toLowerCase().includes(lower) || lower.includes(s.toLowerCase())).slice(0, 5);
|
|
214
|
+
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.");
|
|
215
|
+
}
|
|
216
|
+
function targetData(schema, target, context) {
|
|
217
|
+
const { node, usedIn } = target;
|
|
218
|
+
const top = (usedIn?.[0] ?? target.name).split(".")[0];
|
|
219
|
+
const { list, shapes, others } = objectShapes(schema, node);
|
|
220
|
+
const one = shapes.length === 1 ? shapes[0] : undefined;
|
|
221
|
+
const wrap = (value) => (list ? [value] : value);
|
|
222
|
+
const minimalOne = one ? minimal(schema, one.node) : undefined;
|
|
223
|
+
const fullOne = one ? fuller(schema, one.node) : undefined;
|
|
224
|
+
const fullDiffers = fullOne !== undefined && JSON.stringify(fullOne) !== JSON.stringify(minimalOne);
|
|
225
|
+
const entry = one?.name ?? (list ? namedType(schema, nonNull(schema, node).items) : namedType(schema, node));
|
|
226
|
+
const unused = usedIn !== undefined && usedIn.length === 0;
|
|
227
|
+
return {
|
|
228
|
+
schema: context.used,
|
|
229
|
+
section: unused ? null : top,
|
|
230
|
+
path: usedIn ? (usedIn[0] ?? null) : target.name,
|
|
231
|
+
...(usedIn ? { used_in: usedIn } : {}),
|
|
232
|
+
kind: list ? "list" : "object",
|
|
233
|
+
required: !usedIn && !target.nested ? context.required.has(target.name) : false,
|
|
234
|
+
file: unused ? null : fileOf(context.layout, top),
|
|
235
|
+
entry: entry ?? null,
|
|
236
|
+
fields: one ? fieldsOf(schema, one.node) : [],
|
|
237
|
+
example: minimalOne === undefined ? null : wrap(minimalOne),
|
|
238
|
+
...(fullDiffers ? { nested_example: wrap(fullOne) } : {}),
|
|
239
|
+
nested: one ? nestedOf(schema, one.node, target.at) : [],
|
|
240
|
+
...(shapes.length > 1
|
|
241
|
+
? { shapes: shapes.map((s) => ({ type: s.name ?? null, fields: fieldsOf(schema, s.node), example: minimal(schema, s.node) })), other_shapes: others }
|
|
242
|
+
: {}),
|
|
243
|
+
};
|
|
244
|
+
}
|
|
245
|
+
function headLines(target, data, used) {
|
|
246
|
+
if (target.usedIn) {
|
|
247
|
+
const where = target.usedIn.length ? target.usedIn.join(", ") : "not used by any section";
|
|
248
|
+
return keyValues([
|
|
249
|
+
["type", `${target.name} (an object)`],
|
|
250
|
+
["used at", where],
|
|
251
|
+
["file", data.file ?? "(none)"],
|
|
252
|
+
["schema", sourceLine(used)],
|
|
253
|
+
]);
|
|
254
|
+
}
|
|
255
|
+
const what = data.kind === "list" ? "a list of entries" : "one object";
|
|
256
|
+
const each = data.entry ? `, each a ${data.entry}` : "";
|
|
257
|
+
return keyValues([
|
|
258
|
+
[target.nested ? "field" : "section", `${target.name} (${what}${each})`],
|
|
259
|
+
["file", data.file ?? "(none)"],
|
|
260
|
+
["schema", sourceLine(used)],
|
|
261
|
+
]);
|
|
262
|
+
}
|
|
263
|
+
const FIELD_COLUMNS = ["field", "type", "required", "notes"];
|
|
264
|
+
function shapeLines(data) {
|
|
265
|
+
const shapes = data.shapes ?? [];
|
|
266
|
+
const others = data.other_shapes ?? [];
|
|
267
|
+
const besides = others.length ? ` (${others.map((o) => `a ${o}`).join(", ")}, or an object below)` : "";
|
|
268
|
+
const lines = [`Each entry takes one of ${shapes.length + others.length} shapes${besides}:`, ""];
|
|
269
|
+
for (const shape of shapes) {
|
|
270
|
+
const example = data.kind === "list" ? [shape.example] : shape.example;
|
|
271
|
+
lines.push(`${shape.type ?? "object"}:`, table(fieldRows(shape.fields), FIELD_COLUMNS), yamlOf(example), "");
|
|
272
|
+
}
|
|
273
|
+
return lines;
|
|
274
|
+
}
|
|
275
|
+
function fieldLines(data) {
|
|
276
|
+
const empty = data.example === null || Object.keys((Array.isArray(data.example) ? data.example[0] : data.example)).length === 0;
|
|
277
|
+
const lines = [
|
|
278
|
+
data.fields.length ? table(fieldRows(data.fields), FIELD_COLUMNS) : "No fields are published here.",
|
|
279
|
+
"",
|
|
280
|
+
empty ? "No field is required; the smallest entry is empty:" : "Minimal example (required fields only):",
|
|
281
|
+
yamlOf(data.example),
|
|
282
|
+
];
|
|
283
|
+
if (data.nested_example)
|
|
284
|
+
lines.push("", "With one entry of each nested list:", yamlOf(data.nested_example));
|
|
285
|
+
if (data.nested.length) {
|
|
286
|
+
const rows = data.nested.map((n) => ({ command: `cavelon schema ${n.path}`, type: n.type }));
|
|
287
|
+
lines.push("", "Fields with fields of their own:", table(rows, ["command", "type"]));
|
|
288
|
+
}
|
|
289
|
+
return lines;
|
|
290
|
+
}
|
|
291
|
+
function targetLines(schema, target, data, used) {
|
|
292
|
+
const head = [headLines(target, data, used), ""];
|
|
293
|
+
if (data.shapes)
|
|
294
|
+
return [...head, ...shapeLines(data)];
|
|
295
|
+
if (data.example !== null)
|
|
296
|
+
return [...head, ...fieldLines(data)];
|
|
297
|
+
const others = objectShapes(schema, target.node).others;
|
|
298
|
+
return [...head, `Each entry is a ${others.join(" or ") || typeOf(schema, entryOf(schema, target.node).entry)}; there are no fields to list.`];
|
|
299
|
+
}
|
|
103
300
|
export const schema = {
|
|
104
301
|
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
|
-
"
|
|
302
|
+
summary: "Show the package schema the instance publishes: its sections, or the fields of a section or a nested type, with a minimal example.",
|
|
303
|
+
description: "Without an argument, lists the sections with the file each is kept in. With a section, lists its fields (type, required,\n" +
|
|
304
|
+
"allowed values, default) and prints the smallest entry that has every required field, ready to copy into the file, and an\n" +
|
|
305
|
+
"example with one entry of each nested list. A field whose entries have fields of their own is reached by its path\n" +
|
|
306
|
+
"(`agents.handoffs`, `test_suites.test_cases.steps`) or by its type's name (`PackageAgentHandoff`); the section's\n" +
|
|
307
|
+
"output names them. Where entries take one of several shapes (a step's evaluation_criteria: a text, a judge criterion, an\n" +
|
|
308
|
+
"assertion by type), each shape is listed with its fields. Placeholders are written <field>. Reads the schema as `validate`\n" +
|
|
309
|
+
"does: the cached copy first, the instance otherwise.",
|
|
109
310
|
readOnly: true,
|
|
110
311
|
idempotent: true,
|
|
111
312
|
mcpTool: "package_schema",
|
|
112
|
-
positionals: [
|
|
313
|
+
positionals: [
|
|
314
|
+
{
|
|
315
|
+
name: "section",
|
|
316
|
+
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).",
|
|
317
|
+
},
|
|
318
|
+
],
|
|
113
319
|
options: { offline: { type: "boolean", description: "Use only the cached schema; never contact the instance." } },
|
|
114
|
-
examples: ["cavelon schema", "cavelon schema agents", "cavelon schema
|
|
320
|
+
examples: ["cavelon schema", "cavelon schema agents", "cavelon schema agents.handoffs", "cavelon schema test_suites.test_cases.steps.evaluation_criteria --json"],
|
|
115
321
|
async run(ctx, input) {
|
|
116
322
|
const session = await ctx.session();
|
|
117
323
|
requireInstance(session);
|
|
@@ -144,50 +350,12 @@ export const schema = {
|
|
|
144
350
|
"",
|
|
145
351
|
table(items, ["section", "kind", "required", "file"]),
|
|
146
352
|
"",
|
|
147
|
-
"One section's fields and a minimal example: cavelon schema <section>",
|
|
353
|
+
"One section's fields and a minimal example: cavelon schema <section>; a nested field's: cavelon schema <section>.<field>",
|
|
148
354
|
].join("\n"),
|
|
149
355
|
};
|
|
150
356
|
}
|
|
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 };
|
|
357
|
+
const target = findTarget(published, name);
|
|
358
|
+
const data = targetData(published, target, { used, layout, required });
|
|
359
|
+
return { data, text: targetLines(published, target, data, used).join("\n").trimEnd() };
|
|
192
360
|
},
|
|
193
361
|
};
|
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 });
|
|
@@ -326,8 +327,13 @@ export const whoami = {
|
|
|
326
327
|
}
|
|
327
328
|
const listed = reach?.tenants.find((t) => t.id === contextTenant);
|
|
328
329
|
const stored = session.settings.tenant_id === contextTenant ? session.settings : undefined;
|
|
329
|
-
|
|
330
|
-
|
|
330
|
+
let tenantName = listed?.name ?? membership?.tenant_name ?? stored?.tenant_name ?? null;
|
|
331
|
+
let tenantSlug = listed?.slug ?? membership?.tenant_slug ?? stored?.tenant_slug ?? null;
|
|
332
|
+
if (contextTenant && (!tenantName || !tenantSlug)) {
|
|
333
|
+
const described = await describeTenant(client, contextTenant);
|
|
334
|
+
tenantName ??= described.name ?? null;
|
|
335
|
+
tenantSlug ??= described.slug ?? null;
|
|
336
|
+
}
|
|
331
337
|
if (nowhere && reach) {
|
|
332
338
|
ctx.warn(reach.tenants.length
|
|
333
339
|
? `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))}`
|
|
@@ -540,7 +546,7 @@ export const status = {
|
|
|
540
546
|
root: session.project.root,
|
|
541
547
|
harness: session.project.harness ?? null,
|
|
542
548
|
last_pull: (await readPull(session.project.root)) ?? null,
|
|
543
|
-
open_previews: await listPreviews(session.project.root),
|
|
549
|
+
open_previews: await listPreviews(session.project.root, ctx.io.now()),
|
|
544
550
|
}
|
|
545
551
|
: null,
|
|
546
552
|
logged_in_at: session.settings.logged_in_at ?? null,
|
|
@@ -563,8 +569,15 @@ export const status = {
|
|
|
563
569
|
if (!offline && session.url && session.token) {
|
|
564
570
|
try {
|
|
565
571
|
client = await ctx.client();
|
|
566
|
-
|
|
567
|
-
|
|
572
|
+
const tenantId = client.target.tenantId;
|
|
573
|
+
if (tenantId) {
|
|
574
|
+
const shown = data.tenant;
|
|
575
|
+
shown.id = tenantId;
|
|
576
|
+
const stored = session.settings.tenant_id === tenantId ? session.settings : undefined;
|
|
577
|
+
const described = stored?.tenant_name && stored.tenant_slug ? {} : await describeTenant(client, tenantId);
|
|
578
|
+
shown.name = stored?.tenant_name ?? described.name ?? null;
|
|
579
|
+
shown.slug = stored?.tenant_slug ?? described.slug ?? null;
|
|
580
|
+
}
|
|
568
581
|
const contracts = await ctx.contracts();
|
|
569
582
|
const caps = await contracts.liveCapabilities();
|
|
570
583
|
data.instance_version = caps?.instance.version ?? null;
|
|
@@ -578,7 +591,7 @@ export const status = {
|
|
|
578
591
|
});
|
|
579
592
|
operations = page.status === 200 ? page.data.items : undefined;
|
|
580
593
|
data.operations = operations
|
|
581
|
-
? { items: operations, more: Boolean(page.data.next_cursor) }
|
|
594
|
+
? { items: operations, more: Boolean(page.data.next_cursor), scope: "tenant" }
|
|
582
595
|
: { unavailable: "This instance does not offer /api/v1/operations." };
|
|
583
596
|
}
|
|
584
597
|
else {
|
|
@@ -591,8 +604,19 @@ export const status = {
|
|
|
591
604
|
published = limits.published;
|
|
592
605
|
data.limits = limits.data;
|
|
593
606
|
const ref = session.envFile?.harness ?? session.project?.harness;
|
|
594
|
-
if (session.project && ref)
|
|
595
|
-
|
|
607
|
+
if (session.project && ref) {
|
|
608
|
+
const state = await solutionState(ctx, ref);
|
|
609
|
+
data.solution.state = state;
|
|
610
|
+
if (operations && state.harness) {
|
|
611
|
+
const owners = await operationSolutions(ctx, operations);
|
|
612
|
+
const others = operations.filter((o) => owners.get(o.id) && owners.get(o.id) !== state.harness.id);
|
|
613
|
+
if (others.length) {
|
|
614
|
+
operations = operations.filter((o) => !others.includes(o));
|
|
615
|
+
data.operations = { ...data.operations, items: operations, other_solutions: others.length };
|
|
616
|
+
}
|
|
617
|
+
data.operations = { ...data.operations, scope: "solution", harness: state.harness.slug };
|
|
618
|
+
}
|
|
619
|
+
}
|
|
596
620
|
}
|
|
597
621
|
}
|
|
598
622
|
catch (error) {
|
|
@@ -600,8 +624,9 @@ export const status = {
|
|
|
600
624
|
data.error = error instanceof CavelonError ? error.toJSON() : { message: reachError };
|
|
601
625
|
}
|
|
602
626
|
}
|
|
627
|
+
const shownTenant = data.tenant;
|
|
603
628
|
const tenantText = session.tenant
|
|
604
|
-
? `${session.tenant} (${session.tenantSource})`
|
|
629
|
+
? `${shownTenant?.id && (shownTenant.name || shownTenant.slug) ? tenantTitle({ id: shownTenant.id, name: shownTenant.name, slug: shownTenant.slug }) : session.tenant} (${session.tenantSource})`
|
|
605
630
|
: session.tokenKind === "api_key"
|
|
606
631
|
? "the API key's tenant"
|
|
607
632
|
: "not chosen (`cavelon use` lists your tenants to choose from)";
|
|
@@ -621,7 +646,9 @@ export const status = {
|
|
|
621
646
|
lines.push([
|
|
622
647
|
"open previews",
|
|
623
648
|
solution.open_previews.length
|
|
624
|
-
? solution.open_previews
|
|
649
|
+
? solution.open_previews
|
|
650
|
+
.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}`}`)
|
|
651
|
+
.join("")
|
|
625
652
|
: "none",
|
|
626
653
|
]);
|
|
627
654
|
}
|
|
@@ -642,18 +669,59 @@ export const status = {
|
|
|
642
669
|
const waiting = waits.flatMap((wait, i) => (wait ? [{ operation_id: operations[i].id, ...wait }] : []));
|
|
643
670
|
if (waiting.length)
|
|
644
671
|
data.capacity_waits = waiting;
|
|
672
|
+
const ops = data.operations;
|
|
673
|
+
const others = ops.other_solutions ? ` (${ops.other_solutions} of other solutions not shown; \`cavelon api list_operations_route\` lists all)` : "";
|
|
674
|
+
const heading = ops.scope === "solution" ? `Running operations of ${ops.harness} and the tenant's shared work${others}` : "Running operations in the tenant";
|
|
645
675
|
text += operations.length
|
|
646
|
-
? `\n\
|
|
676
|
+
? `\n\n${heading}:\n${operations
|
|
647
677
|
.map((o, i) => {
|
|
648
678
|
const wait = waits[i];
|
|
649
679
|
return ` ${o.id} ${o.kind} ${o.status}${o.progress?.phase ? ` (${o.progress.phase})` : ""}${wait ? ` ${wait.note}` : ""}`;
|
|
650
680
|
})
|
|
651
681
|
.join("\n")}`
|
|
652
|
-
:
|
|
682
|
+
: `\n\nNo running operations${ops.scope === "solution" ? ` of ${ops.harness}${others}` : " in the tenant"}.`;
|
|
653
683
|
}
|
|
654
684
|
return { data, text };
|
|
655
685
|
},
|
|
656
686
|
};
|
|
687
|
+
async function operationSolutions(ctx, operations) {
|
|
688
|
+
const owners = new Map();
|
|
689
|
+
const triggers = new Map();
|
|
690
|
+
const triggerSolution = (id) => {
|
|
691
|
+
if (!triggers.has(id)) {
|
|
692
|
+
triggers.set(id, callStable(ctx, "GET", "/api/v1/triggers/{trigger_id}", "reading triggers", { params: { trigger_id: [id] } }).then((t) => t.harness_id ?? undefined, () => undefined));
|
|
693
|
+
}
|
|
694
|
+
return triggers.get(id);
|
|
695
|
+
};
|
|
696
|
+
for (const op of operations) {
|
|
697
|
+
const harnessId = op.harness_id;
|
|
698
|
+
if (typeof harnessId === "string" && harnessId) {
|
|
699
|
+
owners.set(op.id, harnessId);
|
|
700
|
+
continue;
|
|
701
|
+
}
|
|
702
|
+
const ref = op.result_ref;
|
|
703
|
+
if (!ref?.id)
|
|
704
|
+
continue;
|
|
705
|
+
try {
|
|
706
|
+
if (ref.type === "test_run") {
|
|
707
|
+
const run = await callStable(ctx, "GET", "/api/v1/test-runs/{run_id}", "test runs", { params: { run_id: [ref.id] } });
|
|
708
|
+
if (run.harness_id)
|
|
709
|
+
owners.set(op.id, run.harness_id);
|
|
710
|
+
}
|
|
711
|
+
else if (ref.type === "agent_run") {
|
|
712
|
+
const run = await callStable(ctx, "GET", "/api/v1/triggers/runs/{run_id}", "reading runs", {
|
|
713
|
+
params: { run_id: [ref.id] },
|
|
714
|
+
});
|
|
715
|
+
const owner = run.harness_id ?? (run.trigger_definition_id ? await triggerSolution(run.trigger_definition_id) : undefined);
|
|
716
|
+
if (owner)
|
|
717
|
+
owners.set(op.id, owner);
|
|
718
|
+
}
|
|
719
|
+
}
|
|
720
|
+
catch {
|
|
721
|
+
}
|
|
722
|
+
}
|
|
723
|
+
return owners;
|
|
724
|
+
}
|
|
657
725
|
export async function rememberTenant(ctx, url, tenant) {
|
|
658
726
|
await updateInstance(ctx.io.env, url, (c) => ({
|
|
659
727
|
...c,
|
package/dist/commands/setup.js
CHANGED
|
@@ -266,14 +266,19 @@ async function runCheck(ctx, input) {
|
|
|
266
266
|
const agents = setupAgents(env);
|
|
267
267
|
const named = namedAgents(input, agents);
|
|
268
268
|
const state = await loadState(env);
|
|
269
|
+
const strict = boolOption(input, "strict");
|
|
269
270
|
const checks = [];
|
|
270
271
|
for (const agent of named.length ? named : agents) {
|
|
271
|
-
const
|
|
272
|
-
|
|
273
|
-
|
|
272
|
+
const record = state.agents[agent.name];
|
|
273
|
+
const check = await checkAgent(agent, env, record);
|
|
274
|
+
if (!named.length && !check.found && !record)
|
|
275
|
+
continue;
|
|
276
|
+
const skipped = !named.length && !strict && !record && !check.ok;
|
|
277
|
+
checks.push(skipped ? { ...check, skipped: true } : check);
|
|
274
278
|
}
|
|
279
|
+
const counted = checks.filter((c) => !c.skipped);
|
|
275
280
|
const servers = [];
|
|
276
|
-
for (const server of
|
|
281
|
+
for (const server of counted.flatMap((c) => c.servers)) {
|
|
277
282
|
if (!servers.some((s) => JSON.stringify(s) === JSON.stringify(server)))
|
|
278
283
|
servers.push(server);
|
|
279
284
|
}
|
|
@@ -300,12 +305,18 @@ async function runCheck(ctx, input) {
|
|
|
300
305
|
loginCheck = { ok: false, instance: session.url, problem: `${err.message}${err.hint ? ` ${err.hint}` : ""}` };
|
|
301
306
|
}
|
|
302
307
|
}
|
|
303
|
-
const ok =
|
|
308
|
+
const ok = counted.length > 0 && counted.every((c) => c.ok) && probes.every((p) => p.ok) && loginCheck.ok;
|
|
304
309
|
const mark = (good) => (good ? ctx.style.green("ok ") : ctx.style.red("no "));
|
|
305
310
|
const lines = [];
|
|
306
311
|
if (!checks.length)
|
|
307
312
|
lines.push(`${mark(false)}No coding agent found, and setup has set up none.`);
|
|
313
|
+
else if (!counted.length)
|
|
314
|
+
lines.push(`${mark(false)}No coding agent is set up for Cavelon.`);
|
|
308
315
|
for (const check of checks) {
|
|
316
|
+
if (check.skipped) {
|
|
317
|
+
lines.push(`skip ${check.label}: found, not set up for Cavelon (${cavelonCommand("setup", "--agents", check.name)} sets it up)`);
|
|
318
|
+
continue;
|
|
319
|
+
}
|
|
309
320
|
lines.push(`${mark(check.ok)}${check.label}${check.found ? "" : " (not found on this computer)"}`);
|
|
310
321
|
for (const detail of check.details)
|
|
311
322
|
lines.push(` ${detail}`);
|
|
@@ -392,7 +403,9 @@ export const setup = {
|
|
|
392
403
|
"server in their user MCP configuration and the skills in their user skills folder. It touches nothing else in those files and\n" +
|
|
393
404
|
"records what it did, so --remove undoes exactly that. Then it logs in if needed, choosing the tenant by name as `login` does.\n" +
|
|
394
405
|
"The server starts as `cavelon mcp` when cavelon is installed, otherwise through npx. --check reports what is set up and\n" +
|
|
395
|
-
"working: each agent's entry, the MCP server starting, and the login.
|
|
406
|
+
"working: each agent's entry, the MCP server starting, and the login. An agent found but never set up for Cavelon is\n" +
|
|
407
|
+
"reported and skipped (exit 0 when the rest works); --strict, or naming it with --agents, counts it.\n" +
|
|
408
|
+
"Without a terminal it changes nothing unless --yes.",
|
|
396
409
|
readOnly: false,
|
|
397
410
|
destructive: true,
|
|
398
411
|
idempotent: true,
|
|
@@ -406,6 +419,7 @@ export const setup = {
|
|
|
406
419
|
},
|
|
407
420
|
yes: { type: "boolean", short: "y", description: "Make the changes without asking." },
|
|
408
421
|
check: { type: "boolean", description: "Report what is set up and working; change nothing." },
|
|
422
|
+
strict: { type: "boolean", description: "With --check: fail for every agent found that is not set up, not only the ones setup set up." },
|
|
409
423
|
remove: { type: "boolean", description: "Undo what setup did (your login stays)." },
|
|
410
424
|
},
|
|
411
425
|
examples: [
|
|
@@ -417,6 +431,8 @@ export const setup = {
|
|
|
417
431
|
async run(ctx, input) {
|
|
418
432
|
if (boolOption(input, "check") && boolOption(input, "remove"))
|
|
419
433
|
throw usageError("--check and --remove do not go together.");
|
|
434
|
+
if (boolOption(input, "strict") && !boolOption(input, "check"))
|
|
435
|
+
throw usageError("--strict goes with --check.");
|
|
420
436
|
if (boolOption(input, "check"))
|
|
421
437
|
return runCheck(ctx, input);
|
|
422
438
|
if (boolOption(input, "remove"))
|