@cavelon/cli 0.1.9 → 0.1.11

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 (64) hide show
  1. package/README.md +23 -10
  2. package/dist/access.js +194 -0
  3. package/dist/acting.js +123 -0
  4. package/dist/agent-env.js +20 -2
  5. package/dist/branches.js +4 -3
  6. package/dist/capacity.js +3 -2
  7. package/dist/code-hints.js +5 -4
  8. package/dist/command.js +6 -0
  9. package/dist/commands/api.js +40 -21
  10. package/dist/commands/async.js +7 -4
  11. package/dist/commands/chat.js +18 -15
  12. package/dist/commands/db.js +367 -0
  13. package/dist/commands/docs.js +87 -9
  14. package/dist/commands/fmt.js +6 -4
  15. package/dist/commands/index.js +8 -0
  16. package/dist/commands/init.js +106 -28
  17. package/dist/commands/limits-set.js +12 -11
  18. package/dist/commands/limits.js +4 -3
  19. package/dist/commands/loops.js +75 -19
  20. package/dist/commands/models.js +12 -13
  21. package/dist/commands/sandboxes.js +22 -16
  22. package/dist/commands/schema.js +6 -5
  23. package/dist/commands/session.js +134 -37
  24. package/dist/commands/setup.js +4 -2
  25. package/dist/commands/solution.js +289 -93
  26. package/dist/commands/tenants.js +58 -22
  27. package/dist/commands/values.js +110 -45
  28. package/dist/commands/work.js +31 -17
  29. package/dist/confirm-token.js +15 -5
  30. package/dist/context.js +3 -1
  31. package/dist/contracts.js +39 -13
  32. package/dist/database-queries.js +301 -0
  33. package/dist/default-route.js +1 -1
  34. package/dist/features.js +2 -1
  35. package/dist/fsutil.js +14 -0
  36. package/dist/harness-ref.js +6 -4
  37. package/dist/http.js +39 -4
  38. package/dist/invoke.js +7 -2
  39. package/dist/kit-codes.js +14 -2
  40. package/dist/limits.js +1 -1
  41. package/dist/main.js +13 -1
  42. package/dist/mcp.js +105 -26
  43. package/dist/openapi.js +5 -2
  44. package/dist/operations.js +3 -2
  45. package/dist/package-check.js +29 -4
  46. package/dist/package-files.js +5 -1
  47. package/dist/package-format.js +10 -0
  48. package/dist/preview-report.js +46 -7
  49. package/dist/principal.js +24 -2
  50. package/dist/printed.js +182 -0
  51. package/dist/project.js +2 -1
  52. package/dist/results.js +1 -1
  53. package/dist/secret-access.js +42 -0
  54. package/dist/session.js +39 -19
  55. package/dist/shell.js +0 -3
  56. package/dist/skills/cavelon-authoring/SKILL.md +88 -4
  57. package/dist/skills/cavelon-long-running/SKILL.md +9 -3
  58. package/dist/skills/cavelon-loop/SKILL.md +81 -19
  59. package/dist/skills/cavelon-testing/SKILL.md +28 -1
  60. package/dist/tenant-choice.js +7 -7
  61. package/dist/trace-view.js +11 -1
  62. package/dist/update-check.js +2 -2
  63. package/dist/user-config.js +24 -0
  64. package/package.json +1 -1
@@ -1,14 +1,14 @@
1
1
  import { noteLines, runCapacityNote } from "../capacity.js";
2
2
  import { boolOption, CURSOR_OPTION, intOption, LIMIT_OPTION, positional, stringOption, } from "../command.js";
3
3
  import { CavelonError, ExitCode, usageError } from "../errors.js";
4
- import { confirmation } from "../confirm-token.js";
4
+ import { confirmation, confirmTokenRequired } from "../confirm-token.js";
5
5
  import { idempotencyKey, requireFeature, UUID_KEY_OPTION, withRetryKey } from "../features.js";
6
6
  import { clip, keyValues, moreHint, table } from "../format.js";
7
7
  import { callStable } from "../invoke.js";
8
8
  import { catalogEntry } from "../package-check.js";
9
9
  import { readPrincipal } from "../principal.js";
10
10
  import { isUuid } from "../session.js";
11
- import { cavelonCommand } from "../shell.js";
11
+ import { cavelonCommand, fill } from "../printed.js";
12
12
  import { readBody } from "./api.js";
13
13
  import { TIMEOUT_OPTION, timeoutMs, waitAndReport } from "./async.js";
14
14
  import { catalogFor } from "./solution.js";
@@ -18,6 +18,14 @@ const MAX_ITERATION_CURSOR = 100;
18
18
  const LOOP_TERMINAL = new Set(["completed", "failed", "cancelled", "stopped"]);
19
19
  const LOOP_SETTLED = new Set([...LOOP_TERMINAL, "paused"]);
20
20
  const RUN_TERMINAL = new Set(["completed", "failed", "blocked", "rejected", "skipped_budget", "expired", "cancelled", "debug_stopped"]);
21
+ async function triggerSolution(ctx, trigger) {
22
+ if (!trigger.harness_id)
23
+ return null;
24
+ const harness = await callStable(ctx, "GET", "/api/v1/harnesses/{harness_id}", "reading solutions", {
25
+ params: { harness_id: [trigger.harness_id] },
26
+ }).catch(() => undefined);
27
+ return { id: trigger.harness_id, slug: harness?.slug ?? null, name: harness?.name ?? null, status: harness?.status ?? null };
28
+ }
21
29
  export async function resolveTrigger(ctx, ref) {
22
30
  if (isUuid(ref)) {
23
31
  return callStable(ctx, "GET", "/api/v1/triggers/{trigger_id}", "triggers", { params: { trigger_id: [ref] } });
@@ -31,12 +39,12 @@ export async function resolveTrigger(ctx, ref) {
31
39
  throw new CavelonError(ExitCode.failure, {
32
40
  code: hits.length ? "trigger_ambiguous" : "trigger_not_found",
33
41
  message: hits.length ? `${hits.length} triggers are named "${ref}"; pass its id.` : `No trigger "${ref}" in this tenant.`,
34
- hint: "`cavelon api list_triggers` lists them with their ids and slugs.",
42
+ hint: `\`${cavelonCommand("api", "list_triggers")}\` lists them with their ids and slugs.`,
35
43
  });
36
44
  }
37
45
  async function getRun(ctx, runId) {
38
46
  if (!isUuid(runId))
39
- throw usageError(`"${runId}" is not a run id.`, "`cavelon loop start` prints the run id.");
47
+ throw usageError(`"${runId}" is not a run id.`, `\`${cavelonCommand("loop", "start")}\` prints the run id.`);
40
48
  return callStable(ctx, "GET", "/api/v1/triggers/runs/{run_id}", "trigger runs", { params: { run_id: [runId] } });
41
49
  }
42
50
  const MAX_LOOP_PAGES = 5;
@@ -71,7 +79,7 @@ async function pickLoop(ctx, runId, loopId, fits, what) {
71
79
  throw new CavelonError(ExitCode.failure, {
72
80
  code: "loop_not_found",
73
81
  message: `Run ${runId} has no loop (yet).`,
74
- hint: `A loop starts when the run reaches its Masterloop node; \`cavelon loop watch ${runId}\` waits for it.`,
82
+ hint: `A loop starts when the run reaches its Masterloop node; \`${cavelonCommand("loop", "watch", runId)}\` waits for it.`,
75
83
  });
76
84
  }
77
85
  const candidates = loops.filter(fits);
@@ -170,26 +178,69 @@ function loopExitCode(state) {
170
178
  }
171
179
  export const loopStart = {
172
180
  name: "loop start",
173
- summary: "Start a loop through its trigger, as you; returns the run and operation ids.",
181
+ summary: "Start a loop through its trigger, as you; previews first, --confirm starts it and returns the run and operation ids.",
174
182
  description: "Calls the trigger's run-now route. The run (and its loop) acts as the caller: with a personal access token, the person.\n" +
175
- "Follow it with `loop watch <run>`, or `wait <operation>`; `loop cancel <run>` stops it.",
183
+ "It runs on its own and spends the tenant's model budget, so without --confirm nothing starts: the preview names the\n" +
184
+ "trigger, its solution and the payload. Show it to a person and confirm only with their yes; for a trigger of a draft\n" +
185
+ "solution in a test environment an agent may confirm on its own. Follow the run with `loop watch <run>`, or\n" +
186
+ "`wait <operation>`; `loop cancel <run>` stops it.",
176
187
  readOnly: false,
177
188
  mcpTool: "loop_start",
189
+ operations: ["POST /api/v1/triggers/{trigger_id}/run"],
178
190
  positionals: [{ name: "trigger", description: "Trigger slug, name or id.", required: true }],
179
191
  options: {
180
192
  input: { type: "string", value: "<json|@file|->", description: "The run's payload: JSON, @file.json or - for stdin." },
181
193
  wait: WAIT_OPTION,
182
194
  timeout: TIMEOUT_OPTION,
183
195
  "idempotency-key": UUID_KEY_OPTION,
196
+ confirm: { type: "boolean", mcpToken: true, description: "Start the run (after a person saw the preview)." },
184
197
  },
185
- examples: ["cavelon loop start counter", "cavelon loop start orders --input @orders-request.json --json"],
198
+ examples: [
199
+ "cavelon loop start counter",
200
+ "cavelon loop start counter --confirm",
201
+ "cavelon loop start counter --confirm <token>",
202
+ "cavelon loop start orders --input @orders-request.json --confirm --json",
203
+ ],
186
204
  async run(ctx, input) {
205
+ if (ctx.mode === "mcp" && input.options.confirm === true)
206
+ throw confirmTokenRequired("loop_start");
187
207
  await requireFeature(ctx, "masterloop_enabled", "masterloop_feature_disabled", "Masterloop");
188
208
  const trigger = await resolveTrigger(ctx, positional(input, "trigger"));
189
209
  const raw = stringOption(input, "input");
190
210
  const payload = raw === undefined ? {} : await readBody(ctx, raw);
191
211
  if (!payload || typeof payload !== "object" || Array.isArray(payload))
192
212
  throw usageError("--input must be a JSON object.");
213
+ const gate = await confirmation(ctx, input, "loop_start", { trigger: trigger.id, payload });
214
+ if (!gate.confirmed) {
215
+ const solution = await triggerSolution(ctx, trigger);
216
+ const given = stringOption(input, "idempotency-key");
217
+ const words = ["loop", "start", trigger.slug, ...(raw !== undefined ? ["--input", raw] : []), ...(given ? ["--idempotency-key", given] : [])];
218
+ const confirm = gate.confirm(cavelonCommand(...words, "--confirm"));
219
+ const payloadText = clip(JSON.stringify(payload), 500);
220
+ return {
221
+ data: {
222
+ started: false,
223
+ would: "start_run",
224
+ trigger: { id: trigger.id, slug: trigger.slug, name: trigger.name, type: trigger.trigger_type, is_active: trigger.is_active },
225
+ solution,
226
+ payload,
227
+ confirm,
228
+ ...gate.fields,
229
+ },
230
+ text: [
231
+ `Starting ${trigger.slug} (${trigger.trigger_type}) starts a run that acts as you, runs on its own and spends the tenant's model budget until it ends or is cancelled.`,
232
+ !solution
233
+ ? "Solution: none named by the trigger."
234
+ : solution.status
235
+ ? `Solution: ${solution.name ?? solution.id}${solution.slug ? ` (${solution.slug})` : ""}, ${solution.status}.`
236
+ : `Solution: ${solution.id} (not readable).`,
237
+ `Payload: ${payloadText}`,
238
+ gate.where, ...(gate.mismatch ? [gate.mismatch] : []),
239
+ `Nothing was started. Show this to a person; with their yes: ${confirm}`,
240
+ ].join("\n"),
241
+ ...(gate.exitCode ? { exitCode: gate.exitCode } : {}),
242
+ };
243
+ }
193
244
  const key = idempotencyKey(input);
194
245
  const run = await callStable(ctx, "POST", "/api/v1/triggers/{trigger_id}/run", "starting triggers", {
195
246
  params: { trigger_id: [trigger.id] },
@@ -217,9 +268,9 @@ export const loopStart = {
217
268
  return {
218
269
  data: started,
219
270
  text: `Started run ${run.id} of ${trigger.slug} (${run.status}).\n` +
220
- `Follow: cavelon loop watch ${run.id}\n` +
221
- (run.operation_id ? `Wait: cavelon wait ${run.operation_id}\n` : "") +
222
- `Stop: cavelon loop cancel ${run.id} --confirm`,
271
+ `Follow: ${cavelonCommand("loop", "watch", run.id)}\n` +
272
+ (run.operation_id ? `Wait: ${cavelonCommand("wait", run.operation_id)}\n` : "") +
273
+ `Stop: ${cavelonCommand("loop", "cancel", run.id, "--confirm")}`,
223
274
  };
224
275
  },
225
276
  };
@@ -231,6 +282,7 @@ export const loopCancel = {
231
282
  destructive: true,
232
283
  idempotent: true,
233
284
  mcpTool: "loop_cancel",
285
+ operations: ["POST /api/v1/triggers/runs/{run_id}/cancel"],
234
286
  positionals: [{ name: "run", description: "The trigger run id (from `loop start`).", required: true }],
235
287
  options: {
236
288
  confirm: { type: "boolean", mcpToken: true, description: "Stop the run; without it nothing is stopped." },
@@ -246,12 +298,13 @@ export const loopCancel = {
246
298
  const loops = (await loopsOf(ctx, run.id)).map(loopSummary);
247
299
  const gate = await confirmation(ctx, input, "loop_cancel", { run: run.id });
248
300
  if (!gate.confirmed) {
249
- const confirm = gate.confirm(`cavelon loop cancel ${run.id} --confirm`);
301
+ const confirm = gate.confirm(cavelonCommand("loop", "cancel", run.id, "--confirm"));
250
302
  return {
251
303
  data: { cancelled: false, run: runSummary(run, note), loops, confirm, ...gate.fields },
252
304
  text: `Run ${run.id} (${run.workflow_name}) is ${run.status}` +
253
305
  (loops.length ? `, with loops:\n${table(loops, ["loop_id", "node", "state", "iteration"])}\n` : ".\n") +
254
306
  (note ? `${noteLines(note).slice(1)}\n` : "") +
307
+ `${gate.where}\n` +
255
308
  (gate.mismatch ? `${gate.mismatch}\n` : "") +
256
309
  `Nothing was stopped. Stop it with: ${confirm}`,
257
310
  ...(gate.exitCode ? { exitCode: gate.exitCode } : {}),
@@ -260,7 +313,7 @@ export const loopCancel = {
260
313
  const cancelled = await callStable(ctx, "POST", "/api/v1/triggers/runs/{run_id}/cancel", "cancelling runs", { params: { run_id: [run.id] } });
261
314
  return {
262
315
  data: { cancelled: true, run: runSummary(cancelled), loops },
263
- text: `Run ${cancelled.id} is ${cancelled.status}; its loops stop at their next safe point.` + (cancelled.operation_id ? `\nWait: cavelon wait ${cancelled.operation_id}` : ""),
316
+ text: `Run ${cancelled.id} is ${cancelled.status}; its loops stop at their next safe point.` + (cancelled.operation_id ? `\nWait: ${cavelonCommand("wait", cancelled.operation_id)}` : ""),
264
317
  };
265
318
  },
266
319
  };
@@ -298,7 +351,7 @@ export const loopIterations = {
298
351
  (table(items, ["iteration", "child_status", "verdict", "outcome", "duration_ms", "child_run_id"]) || "No iterations yet.") +
299
352
  moreHint(next, cavelonCommand("loop", "iterations", loop.owner_run_id, "--loop", loop.id)) +
300
353
  (page.content_visible ? "" : "\nIteration results are hidden from this credential.") +
301
- (items.length ? `\nOne iteration's run: ${cavelonCommand("trace")} <child_run_id>` : ""),
354
+ (items.length ? `\nOne iteration's run: ${cavelonCommand("trace", fill("child_run_id"))}` : ""),
302
355
  };
303
356
  },
304
357
  };
@@ -318,6 +371,7 @@ function envelopeIn(it, loop, newest) {
318
371
  }
319
372
  export const loopWatch = {
320
373
  name: "loop watch",
374
+ mcpInstead: "loop iterations",
321
375
  summary: "Follow a loop: one line per decided iteration and per state change, then the loop's outcome.",
322
376
  description: "Prints each iteration once the loop accepted it, rejected it or its child failed, with its outcome and usage\n" +
323
377
  "(one JSON object per line with --json), and the loop's outcome when it ends or pauses. Exit 0 when the loop\n" +
@@ -525,7 +579,7 @@ function resumeCommand(loop, reason) {
525
579
  return cavelonCommand("loop", "resume", loop.owner_run_id, "--loop", loop.id, ...(reason ? ["--reason", reason] : []));
526
580
  }
527
581
  async function startAgain(ctx, loop) {
528
- let start = "cavelon loop start <trigger>";
582
+ let start = cavelonCommand("loop", "start", fill("trigger"));
529
583
  try {
530
584
  const run = await getRun(ctx, loop.owner_run_id);
531
585
  if (run.trigger_definition_id)
@@ -589,6 +643,7 @@ function controlCommand(action) {
589
643
  "the command); any other pause resumes without it. A pause that cannot be resumed is refused with what to do instead.",
590
644
  readOnly: false,
591
645
  mcpTool: `loop_${action}`,
646
+ operations: [`POST /api/v1/triggers/runs/{run_id}/loops/{loop_id}/${action}`],
592
647
  positionals: [{ name: "run", description: "The trigger run id.", required: true }],
593
648
  options: {
594
649
  loop: LOOP_OPTION,
@@ -623,7 +678,7 @@ function controlCommand(action) {
623
678
  const text = pausing
624
679
  ? `Pause requested for loop ${receipt.loop_id} (${receipt.state}); it pauses after the current iteration.`
625
680
  : `Loop ${receipt.loop_id} resumes (${receipt.state}).`;
626
- return { data: { ...receipt, run_id: loop.owner_run_id, operation_id: loop.operation_id }, text: `${text}\nFollow: cavelon loop watch ${loop.owner_run_id}` };
681
+ return { data: { ...receipt, run_id: loop.owner_run_id, operation_id: loop.operation_id }, text: `${text}\nFollow: ${cavelonCommand("loop", "watch", loop.owner_run_id)}` };
627
682
  },
628
683
  };
629
684
  }
@@ -633,11 +688,11 @@ const REVIEWED_REASON_OPTION = {
633
688
  description: "The pause reason a person reviewed, exactly as the loop names it (task_blocked, not free text); only a verdict on the task needs it.",
634
689
  };
635
690
  function reviewRequired(loop, message, hint) {
636
- const check = `${cavelonCommand("loop", "iterations", loop.owner_run_id, "--loop", loop.id)} and ${cavelonCommand("trace")} <child_run_id>`;
691
+ const check = `${cavelonCommand("loop", "iterations", loop.owner_run_id, "--loop", loop.id)} and ${cavelonCommand("trace", fill("child_run_id"))}`;
637
692
  return new CavelonError(ExitCode.needsAction, {
638
693
  code: "loop_resume_review_required",
639
694
  message,
640
- hint: [hint, `A person checks the cause (${check}) and fixes it, then: ${resumeCommand(loop, loop.reason ?? "<pause_reason>")}`].filter(Boolean).join(" "),
695
+ hint: [hint, `A person checks the cause (${check}) and fixes it, then: ${resumeCommand(loop, loop.reason ?? fill("pause_reason"))}`].filter(Boolean).join(" "),
641
696
  });
642
697
  }
643
698
  async function checkResume(ctx, loop, reason) {
@@ -754,6 +809,7 @@ export const triggerIdentity = {
754
809
  destructive: true,
755
810
  idempotent: true,
756
811
  mcpTool: "trigger_identity",
812
+ operations: ["PUT /api/v1/triggers/{trigger_id}/execution-identity"],
757
813
  positionals: [
758
814
  { name: "trigger", description: "Trigger slug, name or id.", required: true },
759
815
  { name: "key", description: "The API key's name or id (never its value)." },
@@ -791,7 +847,7 @@ export const triggerIdentity = {
791
847
  const confirm = gate.confirm(cavelonCommand("trigger", "identity", trigger.slug, keyRef ?? "--clear", "--confirm"));
792
848
  return {
793
849
  data: { trigger: trigger.slug, changed: false, would: change, current: view, confirm, ...gate.fields },
794
- text: `${identityText(trigger, view)}\n\n${gate.mismatch ? `${gate.mismatch}\n` : ""}Nothing changed. To ${change}: ${confirm}`,
850
+ text: `${identityText(trigger, view)}\n\n${gate.where}\n${gate.mismatch ? `${gate.mismatch}\n` : ""}Nothing changed. To ${change}: ${confirm}`,
795
851
  ...(gate.exitCode ? { exitCode: gate.exitCode } : {}),
796
852
  };
797
853
  }
@@ -5,11 +5,11 @@ import { confirmation } from "../confirm-token.js";
5
5
  import { moreHint, table } from "../format.js";
6
6
  import { callStable, workflowOperation } from "../invoke.js";
7
7
  import { deref, jsonBodySchema, validateBody } from "../openapi.js";
8
- import { cavelonCommand, shellWord } from "../shell.js";
8
+ import { cavelonCommand, fill } from "../printed.js";
9
9
  import { STATE_DIR } from "../local-state.js";
10
10
  import { listedPages } from "./docs.js";
11
11
  import { refreshInventory } from "./inventory.js";
12
- import { ENV_OPTION, targetFlags } from "./values.js";
12
+ import { ENV_OPTION } from "./values.js";
13
13
  const LIST_ROUTE = "/api/v1/model-registry";
14
14
  const ROW_ROUTE = "/api/v1/model-registry/{model_registry_id}";
15
15
  const LIMIT_FIELD = "max_concurrent_requests";
@@ -55,7 +55,7 @@ async function readRows(ctx) {
55
55
  const rows = await callStable(ctx, "GET", LIST_ROUTE, "the Model Registry");
56
56
  return Array.isArray(rows) ? rows : [];
57
57
  }
58
- function findRow(rows, ref, flags) {
58
+ function findRow(rows, ref) {
59
59
  const byId = rows.find((r) => r.id === ref) ?? rows.find((r) => r.model_id === ref);
60
60
  if (byId)
61
61
  return byId;
@@ -63,13 +63,13 @@ function findRow(rows, ref, flags) {
63
63
  if (byName.length === 1)
64
64
  return byName[0];
65
65
  if (byName.length > 1) {
66
- 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.");
66
+ 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; \`${cavelonCommand("models", "list")}\` shows them.`);
67
67
  }
68
68
  throw new CavelonError(ExitCode.failure, {
69
69
  code: "model_not_found",
70
70
  status: 404,
71
71
  message: `This tenant's Model Registry has no row "${ref}".`,
72
- hint: `\`cavelon models list${flags}\` shows its rows by model_id and id.`,
72
+ hint: `\`${cavelonCommand("models", "list")}\` shows its rows by model_id and id.`,
73
73
  });
74
74
  }
75
75
  function parseLimit(raw) {
@@ -90,7 +90,7 @@ function requireLimitField(doc, op) {
90
90
  throw new CavelonError(ExitCode.failure, {
91
91
  code: "operation_unavailable",
92
92
  message: `This instance's Model Registry rows have no ${LIMIT_FIELD} (PATCH ${ROW_ROUTE} does not take it), so nothing was sent.`,
93
- hint: "The instance is older than endpoint limits; `cavelon status` shows its version.",
93
+ hint: `The instance is older than endpoint limits; \`${cavelonCommand("status")}\` shows its version.`,
94
94
  });
95
95
  }
96
96
  export const modelsList = {
@@ -107,7 +107,6 @@ export const modelsList = {
107
107
  async run(ctx, input) {
108
108
  const limit = intOption(input, "limit", { min: 1, max: 500, fallback: 50 });
109
109
  const session = await ctx.session();
110
- const flags = targetFlags(session);
111
110
  const rows = await readRows(ctx);
112
111
  if (session.project) {
113
112
  await refreshInventory(session.project.root, "models", rows.map((r) => r.model_id), ctx.io.now()).catch((error) => ctx.warn(`Could not keep the model list for validate in ${STATE_DIR}/ (${error instanceof Error ? error.message : String(error)}).`));
@@ -128,9 +127,9 @@ export const modelsList = {
128
127
  }));
129
128
  const pages = await listedPages(ctx, [CAPACITY_TUTORIAL_PAGE]);
130
129
  const lines = [
131
- table(shown, ["model_id", "provider", "endpoint", "max_concurrent_requests", "active"], 60) + moreHint(page.next_cursor, `cavelon models list${flags}`),
130
+ table(shown, ["model_id", "provider", "endpoint", "max_concurrent_requests", "active"], 60) + moreHint(page.next_cursor, cavelonCommand("models", "list")),
132
131
  "",
133
- `Rows with the same endpoint share one max_concurrent_requests count. Change it with: cavelon models set-limit <model_id> <n|none>${flags}`,
132
+ `Rows with the same endpoint share one max_concurrent_requests count. Change it with: ${cavelonCommand("models", "set-limit", fill("model_id"), fill("n|none"))}`,
134
133
  ...pages.map((p) => `Plan it for a self-hosted endpoint: ${cavelonCommand("docs", "get", p)}`),
135
134
  ];
136
135
  return { data: { items, next_cursor: page.next_cursor, total: page.total }, text: lines.join("\n") };
@@ -147,6 +146,7 @@ export const modelsSetLimit = {
147
146
  destructive: true,
148
147
  idempotent: true,
149
148
  mcpTool: "models_set_limit",
149
+ operations: ["PATCH /api/v1/model-registry/{model_registry_id}"],
150
150
  positionals: [
151
151
  { name: "model", description: "The row's model_id, id or display name (`cavelon models list`).", required: true },
152
152
  { name: "limit", description: "Requests the endpoint serves at once (a whole number), or none to clear the limit.", required: true },
@@ -160,13 +160,12 @@ export const modelsSetLimit = {
160
160
  async run(ctx, input) {
161
161
  const ref = positional(input, "model");
162
162
  const limit = parseLimit(positional(input, "limit"));
163
- const flags = targetFlags(await ctx.session());
164
163
  const { doc, op } = await workflowOperation(ctx, "PATCH", ROW_ROUTE, "changing Model Registry rows");
165
164
  requireLimitField(doc, op);
166
165
  if (doc)
167
166
  validateBody(doc, op, { [LIMIT_FIELD]: limit });
168
167
  const rows = await readRows(ctx);
169
- const row = findRow(rows, ref, flags);
168
+ const row = findRow(rows, ref);
170
169
  const model = rowView(row, rows);
171
170
  const previous = model.max_concurrent_requests;
172
171
  if (limit !== null && !model.endpoint) {
@@ -187,10 +186,10 @@ export const modelsSetLimit = {
187
186
  const sharing = model.shares_endpoint_with?.length ? ` It shares the count with ${model.shares_endpoint_with.join(", ")} (same endpoint).` : "";
188
187
  const gate = await confirmation(ctx, input, "models_set_limit", { row: row.id, previous, limit });
189
188
  if (!gate.confirmed) {
190
- const confirm = gate.confirm(`cavelon models set-limit ${shellWord(row.model_id)} ${limitText(limit)}${flags} --confirm`);
189
+ const confirm = gate.confirm(cavelonCommand("models", "set-limit", row.model_id, limitText(limit), "--confirm"));
191
190
  return {
192
191
  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}`,
192
+ text: `${label}: max_concurrent_requests ${limitText(previous)} → ${limitText(limit)}.${sharing}\n${gate.where}\n${gate.mismatch ? `${gate.mismatch}\n` : ""}Nothing was changed. Change it with: ${confirm}`,
194
193
  ...(gate.exitCode ? { exitCode: gate.exitCode } : {}),
195
194
  };
196
195
  }
@@ -10,7 +10,7 @@ import { clip, keyValues, moreHint, table } from "../format.js";
10
10
  import { bodyBytes } from "../http.js";
11
11
  import { buildRequest, callStable, workflowOperation } from "../invoke.js";
12
12
  import { isUuid } from "../session.js";
13
- import { cavelonCommand } from "../shell.js";
13
+ import { cavelonCommand, fill } from "../printed.js";
14
14
  import { archiveFrom } from "../tar.js";
15
15
  import { TIMEOUT_OPTION, timeoutMs, waitAndReport } from "./async.js";
16
16
  import { resolveHarnessId } from "../harness-ref.js";
@@ -61,7 +61,7 @@ export async function resolveSandbox(ctx, ref) {
61
61
  throw new CavelonError(ExitCode.failure, {
62
62
  code: hits.length ? "sandbox_ambiguous" : "sandbox_not_found",
63
63
  message: hits.length ? `${hits.length} Sandboxes are named "${ref}"; pass its id.` : `No Sandbox "${ref}" in this tenant.`,
64
- hint: "`cavelon sandbox list` lists them.",
64
+ hint: `\`${cavelonCommand("sandbox", "list")}\` lists them.`,
65
65
  });
66
66
  }
67
67
  const REFUSALS = {
@@ -69,17 +69,17 @@ const REFUSALS = {
69
69
  code: "sandbox_capability_unavailable",
70
70
  what: "archive import and export",
71
71
  elsewhere: (s) => `On a customer VM, put the files into its directory on the VM, then run \`${cavelonCommand("sandbox", "refresh", s.name)}\`; ` +
72
- `read results with \`${cavelonCommand("sandbox", "files", s.name)}\` and \`${cavelonCommand("sandbox", "cat", s.name)} <path>\`.`,
72
+ `read results with \`${cavelonCommand("sandbox", "files", s.name)}\` and \`${cavelonCommand("sandbox", "cat", s.name, fill("path"))}\`.`,
73
73
  },
74
74
  receipt: {
75
75
  code: "sandbox_validation_receipt_unavailable",
76
76
  what: "a runner validation receipt (it reports agent_reported completion only)",
77
- elsewhere: (s) => `The evidence is the files: \`${cavelonCommand("sandbox", "files", s.name)}\` and \`${cavelonCommand("sandbox", "cat", s.name)} <path>\`.`,
77
+ elsewhere: (s) => `The evidence is the files: \`${cavelonCommand("sandbox", "files", s.name)}\` and \`${cavelonCommand("sandbox", "cat", s.name, fill("path"))}\`.`,
78
78
  },
79
79
  refresh: {
80
80
  code: "sandbox_workspace_refresh_unavailable",
81
81
  what: "a workspace refresh (nothing edits it outside Cavelon)",
82
- elsewhere: (s) => `Seed an isolated container with \`${cavelonCommand("sandbox", "seed", s.name)} <folder>\`.`,
82
+ elsewhere: (s) => `Seed an isolated container with \`${cavelonCommand("sandbox", "seed", s.name, fill("folder"))}\`.`,
83
83
  },
84
84
  };
85
85
  function requireOffer(ctx, sandbox, offer, command) {
@@ -156,7 +156,7 @@ export const sandboxList = {
156
156
  return {
157
157
  data: { items, next_cursor: next, instance_modes: modes ?? null },
158
158
  text: (table(items, ["name", "mode", "state", "ready", "revision", "connection", "id"]) || "No Sandboxes.") +
159
- moreHint(next, "cavelon sandbox list") +
159
+ moreHint(next, cavelonCommand("sandbox", "list")) +
160
160
  (modes ? `\n\nNew Sandboxes on this instance: ${modes.join(", ") || "none (switched off)"}.` : ""),
161
161
  };
162
162
  },
@@ -168,6 +168,7 @@ export const sandboxValidate = {
168
168
  readOnly: false,
169
169
  idempotent: true,
170
170
  mcpTool: "sandbox_validate",
171
+ operations: ["POST /api/v1/sandboxes/{sandbox_id}/validate"],
171
172
  positionals: [{ name: "sandbox", description: "Sandbox name or id.", required: true }],
172
173
  examples: ["cavelon sandbox validate orders-test"],
173
174
  async run(ctx, input) {
@@ -384,6 +385,7 @@ export const sandboxRefresh = {
384
385
  readOnly: false,
385
386
  idempotent: true,
386
387
  mcpTool: "sandbox_refresh",
388
+ operations: ["POST /api/v1/sandboxes/{sandbox_id}/refresh-workspace"],
387
389
  positionals: [{ name: "sandbox", description: "Sandbox name or id.", required: true }],
388
390
  options: { "idempotency-key": UUID_KEY_OPTION },
389
391
  examples: ["cavelon sandbox refresh spec-vm"],
@@ -446,13 +448,13 @@ function jobFailed(job) {
446
448
  return new CavelonError(ExitCode.failure, {
447
449
  code: job.error_code ?? "sandbox_artifact_job_failed",
448
450
  message: `Archive job ${job.id} ${job.status}${job.error_code ? ": " + job.error_code : ""}.`,
449
- hint: job.error_code ? `\`cavelon explain ${job.error_code}\` says what it means.` : undefined,
451
+ hint: job.error_code ? `\`${cavelonCommand("explain", job.error_code)}\` says what it means.` : undefined,
450
452
  });
451
453
  }
452
454
  const UPLOAD_READY_MS = 30_000;
453
- function seedCommand(sandbox, input) {
455
+ function seedCommand(sandbox, input, token) {
454
456
  const harness = stringOption(input, "harness");
455
- return cavelonCommand("sandbox", "seed", sandbox.name, positional(input, "source"), ...(harness ? ["--harness", harness] : []), "--confirm");
457
+ return cavelonCommand("sandbox", "seed", sandbox.name, positional(input, "source"), ...(harness ? ["--harness", harness] : []), "--confirm", ...(token ? [token] : []));
456
458
  }
457
459
  export const sandboxSeed = {
458
460
  name: "sandbox seed",
@@ -464,6 +466,7 @@ export const sandboxSeed = {
464
466
  destructive: true,
465
467
  idempotent: true,
466
468
  mcpTool: "sandbox_seed",
469
+ operations: ["POST /api/v1/sandboxes/{sandbox_id}/artifact-jobs"],
467
470
  positionals: [
468
471
  { name: "sandbox", description: "Sandbox name or id.", required: true },
469
472
  { name: "source", description: "A folder, an uncompressed .tar, or one file.", required: true },
@@ -495,7 +498,7 @@ export const sandboxSeed = {
495
498
  archive: { from: archive.from, sha256: archive.sha256, size_bytes: archive.bytes.length, ...(archive.files >= 0 ? { files: archive.files, folders: archive.directories } : {}) },
496
499
  };
497
500
  if (sandbox.lifecycle_state !== "ready")
498
- ctx.warn(`Sandbox "${sandbox.name}" is ${sandbox.lifecycle_state}; the instance accepts a seed only when it is ready (\`cavelon sandbox validate\`).`);
501
+ ctx.warn(`Sandbox "${sandbox.name}" is ${sandbox.lifecycle_state}; the instance accepts a seed only when it is ready (\`${cavelonCommand("sandbox", "validate", sandbox.name)}\`).`);
499
502
  if (sandbox.writer_owner_run_id)
500
503
  ctx.warn(`Run ${sandbox.writer_owner_run_id} holds the Sandbox's writer; the instance refuses a seed until it ends.`);
501
504
  const what = archive.files >= 0 ? `${archive.files} files in ${archive.directories} folders` : "the tar archive";
@@ -505,6 +508,7 @@ export const sandboxSeed = {
505
508
  return {
506
509
  data: { ...summary, seeded: false, confirm, ...gate.fields },
507
510
  text: `Would replace the workspace of "${sandbox.name}" (${revision}) with ${what}, ${archive.bytes.length} bytes, sha256 ${archive.sha256}.\n` +
511
+ `${gate.where}\n` +
508
512
  (gate.mismatch ? `${gate.mismatch}\n` : "") +
509
513
  `Nothing was sent. Seed it with: ${confirm}`,
510
514
  ...(gate.exitCode ? { exitCode: gate.exitCode } : {}),
@@ -523,7 +527,8 @@ export const sandboxSeed = {
523
527
  }
524
528
  if (job.status === "failed" || job.status === "cancelled")
525
529
  throw jobFailed(job);
526
- const resume = seedCommand(sandbox, input);
530
+ const given = input.options.confirm;
531
+ const resume = seedCommand(sandbox, input, typeof given === "string" && given ? given : undefined);
527
532
  if (job.status === "active" && job.phase === "awaiting_upload") {
528
533
  job = await upload(ctx, sandbox.id, job.id, archive.bytes);
529
534
  }
@@ -541,7 +546,7 @@ export const sandboxSeed = {
541
546
  }
542
547
  return {
543
548
  data: result,
544
- text: `Sent ${what} to "${sandbox.name}"; the import runs on the instance.\nWait with: cavelon wait ${job.operation_id}`,
549
+ text: `Sent ${what} to "${sandbox.name}"; the import runs on the instance.\nWait with: ${cavelonCommand("wait", job.operation_id)}`,
545
550
  };
546
551
  },
547
552
  };
@@ -559,7 +564,7 @@ async function upload(ctx, sandboxId, jobId, bytes) {
559
564
  catch {
560
565
  }
561
566
  if (!response.ok)
562
- throw await client.refusal(response.status, data, `PUT ${target}`, response.headers);
567
+ throw await client.refusal(response.status, data, `PUT ${target}`, response.headers, { method: "PUT", path: new URL(client.resolve(target)).pathname });
563
568
  return data;
564
569
  }
565
570
  async function download(ctx, sandbox, job, out) {
@@ -580,7 +585,7 @@ async function download(ctx, sandbox, job, out) {
580
585
  }
581
586
  catch {
582
587
  }
583
- throw await client.refusal(response.status, data, `GET ${target}`, response.headers);
588
+ throw await client.refusal(response.status, data, `GET ${target}`, response.headers, { method: "GET", path: new URL(client.resolve(target)).pathname });
584
589
  }
585
590
  const sha256 = createHash("sha256").update(bytes).digest("hex");
586
591
  const declared = response.headers.get("x-content-sha256");
@@ -599,7 +604,7 @@ async function download(ctx, sandbox, job, out) {
599
604
  throw new CavelonError(ExitCode.conflict, {
600
605
  code: "file_exists",
601
606
  message: `${file} exists; cavelon does not overwrite it.`,
602
- hint: `Choose another file with --out, then: ${cavelonCommand("artifacts", "export", sandbox.name, "--job", job.id, "--out")} <file>`,
607
+ hint: `Choose another file with --out, then: ${cavelonCommand("artifacts", "export", sandbox.name, "--job", job.id, "--out", fill("file"))}`,
603
608
  });
604
609
  }
605
610
  throw error;
@@ -613,6 +618,7 @@ export const artifactsExport = {
613
618
  "(default sandbox-<job>.tar), never over an existing file. On a customer VM, read results with `sandbox cat`.",
614
619
  readOnly: false,
615
620
  mcpTool: "artifacts_export",
621
+ operations: ["POST /api/v1/sandboxes/{sandbox_id}/artifact-jobs"],
616
622
  positionals: [{ name: "sandbox", description: "Sandbox name or id.", required: true }],
617
623
  options: {
618
624
  path: { type: "string", multiple: true, value: "<path>", description: "Export only these workspace paths (repeatable; default: all)." },
@@ -657,7 +663,7 @@ export const artifactsExport = {
657
663
  if (!(boolOption(input, "wait") && ctx.mode === "cli")) {
658
664
  return {
659
665
  data: { ...base, status: job.status, phase: job.phase, download: later },
660
- text: `Export job ${job.id} is ${job.phase}.\nWait with: cavelon wait ${job.operation_id}\nThen download: ${later}`,
666
+ text: `Export job ${job.id} is ${job.phase}.\nWait with: ${cavelonCommand("wait", job.operation_id)}\nThen download: ${later}`,
661
667
  exitCode: jobRef ? ExitCode.timeout : ExitCode.ok,
662
668
  };
663
669
  }
@@ -4,6 +4,7 @@ import { CavelonError, ExitCode, usageError } from "../errors.js";
4
4
  import { clip, keyValues, table } from "../format.js";
5
5
  import { deref, schemaTypes } from "../openapi.js";
6
6
  import { DEFAULT_LAYOUT } from "../package-files.js";
7
+ import { cavelonCommand, fill } from "../printed.js";
7
8
  import { requireInstance } from "../session.js";
8
9
  import { schemaFor } from "./solution.js";
9
10
  const EXAMPLE_DEPTH = 4;
@@ -204,7 +205,7 @@ function unknownField(found) {
204
205
  const guess = near.length ? `Did you mean: ${near.map((o) => `${found.at}.${o}`).join(", ")}? ` : "";
205
206
  return usageError(`The package schema has no nested field "${found.key}" under ${found.at}.`, found.options.length
206
207
  ? `${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
+ : `Nothing under ${found.at} has fields of its own; \`${cavelonCommand("schema", found.at)}\` shows its fields.`);
208
209
  }
209
210
  function findTarget(schema, name) {
210
211
  const defs = (schema.$defs ?? {});
@@ -221,7 +222,7 @@ function findTarget(schema, name) {
221
222
  }
222
223
  const lower = name.toLowerCase();
223
224
  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
+ throw usageError(`The package schema has no section or type "${name}".`, near.length ? `Did you mean: ${near.join(", ")}? (\`${cavelonCommand("schema")}\` lists them)` : `\`${cavelonCommand("schema")}\` lists the sections.`);
225
226
  }
226
227
  function targetData(schema, target, context) {
227
228
  const { node, usedIn } = target;
@@ -293,7 +294,7 @@ function fieldLines(data) {
293
294
  if (data.nested_example)
294
295
  lines.push("", "With one entry of each nested list:", yamlOf(data.nested_example));
295
296
  if (data.nested.length) {
296
- const rows = data.nested.map((n) => ({ command: `cavelon schema ${n.path}`, type: n.type }));
297
+ const rows = data.nested.map((n) => ({ command: cavelonCommand("schema", n.path), type: n.type }));
297
298
  lines.push("", "Fields with fields of their own:", table(rows, ["command", "type"], 60, ["command"]));
298
299
  }
299
300
  return lines;
@@ -342,7 +343,7 @@ export const schema = {
342
343
  code: "package_schema_unavailable",
343
344
  message: "No package schema is cached for this instance, and it was not read.",
344
345
  hint: offline
345
- ? "Run `cavelon schema` once without --offline while the instance is reachable."
346
+ ? `Run \`${cavelonCommand("schema")}\` once without --offline while the instance is reachable.`
346
347
  : "The instance does not publish its package schema (/api/v1/meta/package-schema).",
347
348
  });
348
349
  }
@@ -364,7 +365,7 @@ export const schema = {
364
365
  "",
365
366
  table(items, ["section", "kind", "required", "file"]),
366
367
  "",
367
- "One section's fields and a minimal example: cavelon schema <section>; a nested field's: cavelon schema <section>.<field>",
368
+ `One section's fields and a minimal example: ${cavelonCommand("schema", fill("section"))}; a nested field's: ${cavelonCommand("schema", fill("section.field"))}`,
368
369
  ].join("\n"),
369
370
  };
370
371
  }