@cavelon/cli 0.1.11 → 0.1.13

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.
@@ -14,7 +14,7 @@ import { activate, apply, explain, pull, validate } from "./solution.js";
14
14
  import { schema } from "./schema.js";
15
15
  import { harnessClone, harnessDefault, harnessList, harnessNew, tenantCreate, tenantList } from "./tenants.js";
16
16
  import { kbUpload, testRun, trace } from "./work.js";
17
- import { dbConnections, dbQueries, dbRuns, dbTest, dbTestRun } from "./db.js";
17
+ import { dbConnections, dbInstance, dbQueries, dbRuns, dbTest, dbTestRun } from "./db.js";
18
18
  import { secretsDelete, secretsList, secretsSet, variablesDelete, variablesGet, variablesList, variablesSet } from "./values.js";
19
19
  import { loopCancel, loopIterations, loopPause, loopResume, loopStart, loopWatch, triggerIdentity } from "./loops.js";
20
20
  import { artifactsExport, sandboxActivity, sandboxCat, sandboxFiles, sandboxList, sandboxLogs, sandboxReceipt, sandboxRefresh, sandboxSeed, sandboxValidate, } from "./sandboxes.js";
@@ -103,6 +103,7 @@ export const COMMANDS = [
103
103
  kbUpload,
104
104
  testRun,
105
105
  trace,
106
+ dbInstance,
106
107
  dbConnections,
107
108
  dbQueries,
108
109
  dbRuns,
@@ -1,7 +1,7 @@
1
1
  import { originText } from "../capacity.js";
2
2
  import { positional } from "../command.js";
3
3
  import { CavelonError, ExitCode, usageError } from "../errors.js";
4
- import { confirmation } from "../confirm-token.js";
4
+ import { confirmation, PERSON_CONFIRMS_HELP } from "../confirm-token.js";
5
5
  import { callOperation, openapiOrWarn, workflowOperation } from "../invoke.js";
6
6
  import { changedBy, docsPage, formatValue, isOperatorChange, LIMIT_ABOVE_CEILING, limitRef, quotaSetting, readLimits, } from "../limits.js";
7
7
  import { deref, jsonBodySchema, operationForPath, validateBody } from "../openapi.js";
@@ -471,7 +471,8 @@ export const limitsSet = {
471
471
  "An operator's change (a run cap) is sent only with a personal access token in Platform mode of a role it names, without\n" +
472
472
  "X-Tenant-Id; --tenant <id|slug> then sets one tenant's own run cap. An environment or licence limit, a value out of bounds,\n" +
473
473
  "an instance that does not publish how to change the limit, and a credential without the permission or the role are refused\n" +
474
- "before anything is sent. Propose the change to the person; never raise a limit on your own.",
474
+ "before anything is sent. Propose the change to the person; never raise a limit on your own.\n" +
475
+ PERSON_CONFIRMS_HELP,
475
476
  readOnly: false,
476
477
  destructive: true,
477
478
  idempotent: true,
@@ -491,7 +492,6 @@ export const limitsSet = {
491
492
  examples: [
492
493
  "cavelon limits set kb_upload_max_file_size_mb 50",
493
494
  "cavelon limits set kb_upload_max_file_size_mb 50 --confirm",
494
- "cavelon limits set kb_upload_max_file_size_mb 50 --confirm <token>",
495
495
  "cavelon limits set rate_limit_chat_rpm none --confirm",
496
496
  "cavelon limits set monthly_inference_token_budget 2000000",
497
497
  "cavelon limits set monthly_processing_step_cap none --confirm",
@@ -576,6 +576,10 @@ export const limitsSet = {
576
576
  : `a credential with ${anyOf(change.permissions)} (a session, a personal access token, or an admin API key of the tenant)`;
577
577
  const gate = await confirmation(ctx, input, "limits_set", { key, value, previous: previous ?? null, operation }, {
578
578
  platform: operator ? (target.scope === "one_tenant" ? "tenant" : "outside") : undefined,
579
+ person: {
580
+ what: `${key}: ${from} → ${to}${target.scope === "platform" ? ", the platform's cap for every tenant without its own" : ""}.`,
581
+ words: ["limits", "set", key, argText(value), "--confirm"],
582
+ },
579
583
  });
580
584
  if (!gate.confirmed) {
581
585
  const confirm = gate.confirm(cavelonCommand("limits", "set", key, argText(value), "--confirm"));
@@ -1,7 +1,7 @@
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, confirmTokenRequired } from "../confirm-token.js";
4
+ import { confirmation, confirmTokenRequired, PERSON_CONFIRMS_HELP } 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";
@@ -181,9 +181,10 @@ export const loopStart = {
181
181
  summary: "Start a loop through its trigger, as you; previews first, --confirm starts it and returns the run and operation ids.",
182
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" +
183
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.",
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 an agent confirms with the preview's token (--confirm <token>, or confirm over MCP); for any other,\n" +
186
+ "a coding agent cannot confirm it: over MCP the client asks the person, and from an agent's shell the person runs the\n" +
187
+ "confirm in their own terminal. Follow the run with `loop watch <run>`, or `wait <operation>`; `loop cancel <run>` stops it.",
187
188
  readOnly: false,
188
189
  mcpTool: "loop_start",
189
190
  operations: ["POST /api/v1/triggers/{trigger_id}/run"],
@@ -210,11 +211,15 @@ export const loopStart = {
210
211
  const payload = raw === undefined ? {} : await readBody(ctx, raw);
211
212
  if (!payload || typeof payload !== "object" || Array.isArray(payload))
212
213
  throw usageError("--input must be a JSON object.");
213
- const gate = await confirmation(ctx, input, "loop_start", { trigger: trigger.id, payload });
214
+ const solution = await triggerSolution(ctx, trigger);
215
+ const given = stringOption(input, "idempotency-key");
216
+ const words = ["loop", "start", trigger.slug, ...(raw !== undefined ? ["--input", raw] : []), ...(given ? ["--idempotency-key", given] : [])];
217
+ const gate = await confirmation(ctx, input, "loop_start", { trigger: trigger.id, payload }, {
218
+ ...(solution?.status === "draft"
219
+ ? {}
220
+ : { person: { what: `Start a run of the trigger ${trigger.slug}, which acts as the person and spends the tenant's model budget.`, words: [...words, "--confirm"] } }),
221
+ });
214
222
  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
223
  const confirm = gate.confirm(cavelonCommand(...words, "--confirm"));
219
224
  const payloadText = clip(JSON.stringify(payload), 500);
220
225
  return {
@@ -804,7 +809,8 @@ export const triggerIdentity = {
804
809
  summary: "Show, bind or clear the API key a trigger's unattended runs act as (binding needs --confirm).",
805
810
  description: "Without <key> or --clear, shows the binding. Binding gives the trigger standing authority, so it is never part of\n" +
806
811
  "`apply`: show the person, then run it with --confirm. It needs settings.manage and triggers.manage. Creating keys\n" +
807
- "and Sandbox Access stay in the Admin. A personal access token is never an execution identity.",
812
+ "and Sandbox Access stay in the Admin. A personal access token is never an execution identity.\n" +
813
+ PERSON_CONFIRMS_HELP,
808
814
  readOnly: false,
809
815
  destructive: true,
810
816
  idempotent: true,
@@ -821,7 +827,6 @@ export const triggerIdentity = {
821
827
  examples: [
822
828
  "cavelon trigger identity orders",
823
829
  "cavelon trigger identity orders loop-runner --confirm",
824
- "cavelon trigger identity orders loop-runner --confirm <token>",
825
830
  "cavelon trigger identity orders --clear --confirm",
826
831
  ],
827
832
  async run(ctx, input) {
@@ -842,9 +847,12 @@ export const triggerIdentity = {
842
847
  }
843
848
  const keyName = key && "name" in key ? key.name : wanted;
844
849
  const change = wanted ? `bind API key "${keyName}"` : "clear the binding";
845
- const gate = await confirmation(ctx, input, "trigger_identity", { trigger: trigger.id, from: current.api_key_id ?? null, to: wanted });
850
+ const words = ["trigger", "identity", trigger.slug, keyRef ?? "--clear", "--confirm"];
851
+ const gate = await confirmation(ctx, input, "trigger_identity", { trigger: trigger.id, from: current.api_key_id ?? null, to: wanted }, {
852
+ person: { what: `Trigger ${trigger.slug}: ${change}, which its runs act as.`, words },
853
+ });
846
854
  if (!gate.confirmed) {
847
- const confirm = gate.confirm(cavelonCommand("trigger", "identity", trigger.slug, keyRef ?? "--clear", "--confirm"));
855
+ const confirm = gate.confirm(cavelonCommand(...words));
848
856
  return {
849
857
  data: { trigger: trigger.slug, changed: false, would: change, current: view, confirm, ...gate.fields },
850
858
  text: `${identityText(trigger, view)}\n\n${gate.where}\n${gate.mismatch ? `${gate.mismatch}\n` : ""}Nothing changed. To ${change}: ${confirm}`,
@@ -1,7 +1,7 @@
1
1
  import { CAPACITY_TUTORIAL_PAGE } from "../capacity.js";
2
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
+ import { confirmation, PERSON_CONFIRMS_HELP } 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";
@@ -141,7 +141,8 @@ export const modelsSetLimit = {
141
141
  description: "Sets the row's max_concurrent_requests to <n>, or clears it with none. Without --confirm, shows the old and new value\n" +
142
142
  "and changes nothing. A row without a base_url is refused before anything is sent: it reaches its provider through the\n" +
143
143
  "platform's routes, which have their own limits. Every row with the same base_url shares the count. Propose a value to\n" +
144
- "the person and let them decide; the instance's capacity tutorial says how to find it.",
144
+ "the person and let them decide; the instance's capacity tutorial says how to find it.\n" +
145
+ PERSON_CONFIRMS_HELP,
145
146
  readOnly: false,
146
147
  destructive: true,
147
148
  idempotent: true,
@@ -155,8 +156,7 @@ export const modelsSetLimit = {
155
156
  confirm: { type: "boolean", mcpToken: true, description: "Change it; without this nothing is changed." },
156
157
  env: ENV_OPTION,
157
158
  },
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"],
159
+ examples: ["cavelon models set-limit llama-70b 8", "cavelon models set-limit llama-70b 8 --confirm", "cavelon models set-limit llama-70b none --confirm"],
160
160
  async run(ctx, input) {
161
161
  const ref = positional(input, "model");
162
162
  const limit = parseLimit(positional(input, "limit"));
@@ -184,7 +184,12 @@ export const modelsSetLimit = {
184
184
  return { data: { ...base, changed: false, sent: false }, text: `${label} already has max_concurrent_requests ${limitText(limit)}; nothing to change.` };
185
185
  }
186
186
  const sharing = model.shares_endpoint_with?.length ? ` It shares the count with ${model.shares_endpoint_with.join(", ")} (same endpoint).` : "";
187
- const gate = await confirmation(ctx, input, "models_set_limit", { row: row.id, previous, limit });
187
+ const gate = await confirmation(ctx, input, "models_set_limit", { row: row.id, previous, limit }, {
188
+ person: {
189
+ what: `${label}: max_concurrent_requests ${limitText(previous)} → ${limitText(limit)}.${sharing}`,
190
+ words: ["models", "set-limit", row.model_id, limitText(limit), "--confirm"],
191
+ },
192
+ });
188
193
  if (!gate.confirmed) {
189
194
  const confirm = gate.confirm(cavelonCommand("models", "set-limit", row.model_id, limitText(limit), "--confirm"));
190
195
  return {
@@ -437,7 +437,7 @@ export const whoami = {
437
437
  ["credential", `${session.tokenKind === "api_key" ? "tenant API key" : session.tokenKind === "personal_access_token" ? "personal access token" : "token"}${tokenName} from ${credentialSource(session)}`],
438
438
  ["expires", expires],
439
439
  ["may activate", activateText(data.credential.may_activate, access)],
440
- ["may set secrets", secretsText(data.credential.may_set_secrets)],
440
+ ["may set secrets", secretsText(data.credential.may_set_secrets, access?.complete === true)],
441
441
  ["may set variables", variablesText(data.credential.may_set_variables)],
442
442
  ["scopes", data.credential.scopes ? data.credential.scopes.join(", ") || "none" : undefined],
443
443
  ["permissions", permissionsText(access)],
@@ -482,10 +482,12 @@ function needsAPersonText(access) {
482
482
  const shown = all.slice(0, LISTED).map((o) => `\n ${o.method} ${o.path}${o.reason ? ` (${clip(o.reason, 80)})` : ""}`);
483
483
  return `${all.length} operation${all.length === 1 ? "" : "s"} a person runs, not this credential:${shown.join("")}${all.length > LISTED ? `\n … ${all.length - LISTED} more (--json)` : ""}`;
484
484
  }
485
- function secretsText(may) {
485
+ function secretsText(may, inAdmin) {
486
486
  if (may === null)
487
487
  return undefined;
488
- return may ? "yes" : "no (a tenant Owner sets them, in the Admin or with their own token)";
488
+ if (may)
489
+ return "yes";
490
+ return inAdmin ? "no (a tenant Owner sets them, signed in to the Admin under Settings › Secrets)" : "no (a tenant Owner sets them, in the Admin or with their own token)";
489
491
  }
490
492
  export const use = {
491
493
  name: "use",
@@ -99,7 +99,7 @@ async function confirm(ctx, question, defaultYes) {
99
99
  }
100
100
  function confirmationRequired(what, details) {
101
101
  return new CavelonError(ExitCode.usage, {
102
- code: "confirmation_required",
102
+ code: "yes_required",
103
103
  message: `Nothing was changed: ${what}, and there is no terminal to ask.`,
104
104
  hint: "Read the plan in details, then run the same command with --yes.",
105
105
  details,
@@ -401,8 +401,9 @@ export const setup = {
401
401
  tenantless: true,
402
402
  summary: "Set up your coding agents for Cavelon and log in, in one guided step.",
403
403
  description: "Finds Claude Code, Codex, Cursor, VS Code with GitHub Copilot, Gemini CLI and Kiro, shows what it will change for each, asks once\n" +
404
- "and does it: Claude Code and Codex get the Cavelon plugin through their own plugin command; the others get the `cavelon` MCP\n" +
405
- "server in their user MCP configuration and the skills in their user skills folder. It touches nothing else in those files and\n" +
404
+ "and does it: Claude Code and Codex get the Cavelon plugin through their own plugin command, Gemini CLI the extension of this\n" +
405
+ "release (or the files, when the release has none); the others get the `cavelon` MCP server in their user MCP configuration\n" +
406
+ "and the skills in their user skills folder. It touches nothing else in those files and\n" +
406
407
  "records what it did, so --remove undoes exactly that. Then it logs in if needed, choosing the tenant by name as `login` does.\n" +
407
408
  "The server starts as `cavelon mcp` when cavelon is installed, otherwise through npx. --check reports what is set up and\n" +
408
409
  "working: each agent's entry, the MCP server starting, and the login. An agent found but never set up for Cavelon is\n" +
@@ -5,7 +5,7 @@ import { boolOption, intOption, positional, stringOption } from "../command.js";
5
5
  import { Contracts } from "../contracts.js";
6
6
  import { CavelonError, ExitCode, usageError } from "../errors.js";
7
7
  import { drivenByAgent } from "../agent-env.js";
8
- import { confirmation, confirmTokenRequired, shellTokenRequired } from "../confirm-token.js";
8
+ import { confirmation, confirmInTerminal, confirmTokenRequired, PERSON_CONFIRMS_HELP, personApproves, personRoute, shellTokenRequired } from "../confirm-token.js";
9
9
  import { actingTarget, targetLine, targetText } from "../acting.js";
10
10
  import { clip, keyValues } from "../format.js";
11
11
  import { readTextFile, writeFileAtomic } from "../fsutil.js";
@@ -20,6 +20,7 @@ import { catalogEntry, checkPackage, KIT_CODES, packageVersionOf } from "../pack
20
20
  import { applyQueryNotes, connectorOffer, NEEDS_SUPERADMIN_CODE, queryBlockedHint, queryChanges, readQueryBaseline, rememberQueries } from "../database-queries.js";
21
21
  import { cliFix, similarCodes } from "../code-hints.js";
22
22
  import { KIT_ERROR_CODES } from "../kit-codes.js";
23
+ import { confirmationPointer } from "../change-confirmation.js";
23
24
  import { pairOrderHint, pairOrderPointer } from "../pair-order.js";
24
25
  import { readPackage, tenantWideSections, writePackage } from "../package-files.js";
25
26
  import { blockerDetails, blockerLines, changeLines, fieldChanges, locateBlockers, notApplied, notAppliedLines, tenantWideReport } from "../preview-report.js";
@@ -30,9 +31,9 @@ import { isUuid, requireInstance } from "../session.js";
30
31
  import { listedPages } from "./docs.js";
31
32
  import { readInventory, readInventoryKinds, writeInventory } from "./inventory.js";
32
33
  import { checkedBy, MODEL_UNKNOWN_CODE, missingInventory, REFERENCE_UNKNOWN_CODE } from "../package-references.js";
33
- import { cavelonCommand, printedCommand, spoken } from "../printed.js";
34
- import { secretSetCommand, variableSetCommand } from "./values.js";
35
- import { maySetSecrets, SECRET_SETTER, VARIABLE_SETTER } from "../secret-access.js";
34
+ import { cavelonCommand, personCommand, printedCommand, spoken } from "../printed.js";
35
+ import { secretStep, variableSetCommand } from "./values.js";
36
+ import { maySetSecrets, SECRET_SETTER, SECRET_SETTER_IN_ADMIN, secretsInAdminOnly, VARIABLE_SETTER } from "../secret-access.js";
36
37
  import { ACTIVATOR, accessFor, accessOf, mayActivate, operationAccess, principalOf } from "../access.js";
37
38
  const HARNESS_OPTION = { type: "string", value: "<harness>", description: "The solution (harness): its name, slug or id; default: env file, then cavelon.yaml." };
38
39
  const ENV_OPTION = { type: "string", value: "<name>", description: "Use env/<name>.yaml: its tenant, solution and runtime bindings." };
@@ -449,10 +450,10 @@ export const validate = {
449
450
  function valueNeeds(list) {
450
451
  return (list ?? []).map((n) => (typeof n === "string" ? { name: n } : n)).filter((n) => typeof n.name === "string" && n.name !== "");
451
452
  }
452
- function setCommands(preview, env) {
453
+ function setCommands(preview, env, inAdmin = false) {
453
454
  const needs = preview.target_needs ?? {};
454
455
  return {
455
- secrets: valueNeeds(needs.secrets).map((n) => secretSetCommand(n.name, env)),
456
+ secrets: valueNeeds(needs.secrets).map((n) => secretStep(n.name, inAdmin, env)),
456
457
  variables: valueNeeds(needs.variables).map((n) => variableSetCommand(n.name, env)),
457
458
  };
458
459
  }
@@ -477,8 +478,10 @@ function needsLines(needs, access) {
477
478
  const lines = [];
478
479
  const secrets = valueNeeds(needs.secrets);
479
480
  if (secrets.length) {
480
- const each = needLines(secrets, (name) => secretSetCommand(name), cavelonCommand("secrets", "list", "--missing"));
481
- lines.push(["needs secrets", `${each}\n (a person runs these in a terminal, or sets them in the Admin; never the agent)`]);
481
+ const inAdmin = secretsInAdminOnly(access?.principal) === true;
482
+ const each = needLines(secrets, (name) => secretStep(name, inAdmin), cavelonCommand("secrets", "list", "--missing"));
483
+ const who = inAdmin ? "a person sets them, signed in to the Admin; never the agent" : "a person runs these in a terminal, or sets them in the Admin; never the agent";
484
+ lines.push(["needs secrets", `${each}\n (${who})`]);
482
485
  }
483
486
  const variables = valueNeeds(needs.variables);
484
487
  if (variables.length) {
@@ -695,6 +698,9 @@ async function instanceHolds(ctx, project, stored) {
695
698
  const planned = await writePackage(project.root, project.layout, exported, schema, { dryRun: true });
696
699
  return new Set(planned.unchanged);
697
700
  }
701
+ function personApplyCommand(stored) {
702
+ return personCommand("apply", ...(stored.env ? ["--env", stored.env] : []), "--confirm", stored.preview_id);
703
+ }
698
704
  async function confirmPreview(ctx, project, previewId, allowStale) {
699
705
  const stored = await loadPreview(project.root, previewId);
700
706
  const session = await ctx.session();
@@ -733,6 +739,15 @@ async function confirmPreview(ctx, project, previewId, allowStale) {
733
739
  }
734
740
  if (stored.tenant_id && session.tokenKind !== "api_key")
735
741
  client.target.tenantId = stored.tenant_id;
742
+ const driven = drivenByAgent(ctx);
743
+ const guarded = stored.request[INCLUDE_TENANT_WIDE] === true || stored.request.package.manifest?.scope === "full_config";
744
+ if (driven && stored.person_reason !== null) {
745
+ const into = stored.harness ? `solution ${stored.harness.slug}` : "the tenant";
746
+ const reason = stored.person_reason ?? "was stored by an older cavelon, which did not record whether it needs a person";
747
+ await personApproves(ctx, driven, { tool: "apply", what: `Import preview ${stored.preview_id} into ${into}: it ${reason}.`, command: personApplyCommand(stored), guarded });
748
+ }
749
+ else if (!driven)
750
+ ctx.approved = { guarded };
736
751
  const acting = await actingTarget(ctx);
737
752
  const disk = await readPackage(project.root, project.layout);
738
753
  const changed = await filesChangedSince(project, stored, disk);
@@ -762,7 +777,7 @@ async function confirmPreview(ctx, project, previewId, allowStale) {
762
777
  await rememberImported(ctx, project, stored, disk, changed);
763
778
  await rememberQueries(project.root, stored.request.package, (await schemaFor(ctx, packageVersionOf(stored.request.package), false)).schema, "apply", ctx.io.now());
764
779
  const summary = (result.summary ?? {});
765
- const still = setCommands(stored.preview, stored.env ?? undefined);
780
+ const still = setCommands(stored.preview, stored.env ?? undefined, secretsInAdminOnly((await accessFor(client))?.principal) === true);
766
781
  const sharedSent = stored.request[INCLUDE_TENANT_WIDE] === true;
767
782
  const resultReport = tenantWideReport(result.tenant_wide);
768
783
  const sharedReport = resultReport ?? (sharedSent ? tenantWideReport(stored.preview.tenant_wide) : undefined);
@@ -908,8 +923,10 @@ export const apply = {
908
923
  "still needs (secrets and variables with the command that sets each, grants, runtime bindings, trigger identities), loop\n" +
909
924
  "budgets and ignored sections, and is stored in .cavelon/. A preview never creates the solution: one the env file names\n" +
910
925
  "that is not on the instance yet gets the `cavelon harness new` command that creates it as a draft. A person sets the\n" +
911
- "secrets (`cavelon secrets set <name>`), never the agent.\n" +
912
- "Show a preview that reaches an active solution or env/prod to a person before confirming. A stale preview exits 4 and\n" +
926
+ "secrets (`cavelon secrets set <name>`, or in the Admin where the instance lets no token set one), never the agent.\n" +
927
+ "Show a preview that reaches an active solution or env/prod to a person before confirming. Such a preview (show_to_person:\n" +
928
+ "tenant-wide sections, an active solution, deletions, env/prod) a coding agent cannot confirm: over MCP the client asks\n" +
929
+ "the person, and from an agent's shell the person runs the confirm in their own terminal. A stale preview exits 4 and\n" +
913
930
  "imports nothing: one whose target changed on the instance since, one whose package files changed since (what they\n" +
914
931
  "hold, not their formatting; --allow-stale imports what the preview showed anyway), and one older than a day. So does\n" +
915
932
  "an import its own check refuses when it applies, naming each blocker. --discard <id|all> forgets stored previews;\n" +
@@ -1048,10 +1065,11 @@ export const apply = {
1048
1065
  : sharedLeftOut.length
1049
1066
  ? `tenant-wide: ${sharedLeftOut.join(", ")} left out (\`${cavelonCommand("apply", "--include-tenant-wide")}\` imports them, for every solution of the tenant${reachText ? `; they would reach ${reachText}` : ""})`
1050
1067
  : undefined;
1051
- const commands = setCommands(preview);
1068
+ const access = await accessFor(await ctx.client());
1069
+ const commands = setCommands(preview, undefined, secretsInAdminOnly(access?.principal) === true);
1052
1070
  if (commands.secrets.length || commands.variables.length)
1053
1071
  data.set_commands = commands;
1054
- const context = { disk, harness: harness?.slug, access: await accessFor(await ctx.client()) };
1072
+ const context = { disk, harness: harness?.slug, access };
1055
1073
  Object.assign(data, previewReport(preview, context));
1056
1074
  if (!preview.ready) {
1057
1075
  const pair = pairOrderHint(await catalogFor(ctx, false), [
@@ -1101,6 +1119,7 @@ export const apply = {
1101
1119
  if (!preview.preview_id) {
1102
1120
  ctx.warn("This instance's preview returns no preview id, so `apply --confirm` cannot import exactly it; update the instance.");
1103
1121
  }
1122
+ const reason = personReason(preview, harness, mode, envFile?.name, sharedImported, reaches);
1104
1123
  if (preview.preview_id) {
1105
1124
  const stored = {
1106
1125
  preview_id: preview.preview_id,
@@ -1113,15 +1132,25 @@ export const apply = {
1113
1132
  file_digests: await fileDigests(project.root, sourceFiles(disk)),
1114
1133
  request,
1115
1134
  preview,
1135
+ person_reason: reason ?? null,
1116
1136
  };
1117
1137
  await savePreview(project.root, stored);
1118
1138
  const at = ctx.io.now().toISOString();
1119
1139
  const expired = (await listPreviews(project.root, ctx.io.now())).filter((old) => old.expired);
1120
1140
  await retirePreviews(project.root, expired.map((old) => ({ preview_id: old.preview_id, reason: "expired", at })));
1121
1141
  }
1122
- const reason = personReason(preview, harness, mode, envFile?.name, sharedImported, reaches);
1123
1142
  data.show_to_person = Boolean(reason);
1124
- const confirmLine = preview.preview_id ? cavelonCommand("apply", "--confirm", preview.preview_id) : undefined;
1143
+ const driven = drivenByAgent(ctx);
1144
+ const route = driven && reason && preview.preview_id ? personRoute(ctx, driven) : undefined;
1145
+ if (route)
1146
+ data.needs_person = route;
1147
+ const confirmLine = !preview.preview_id
1148
+ ? undefined
1149
+ : route === "terminal"
1150
+ ? confirmInTerminal(personApplyCommand({ preview_id: preview.preview_id, env: envFile?.name ?? null }))
1151
+ : route === "client"
1152
+ ? `${cavelonCommand("apply", "--confirm", preview.preview_id)}; the client then asks the person to approve it`
1153
+ : cavelonCommand("apply", "--confirm", preview.preview_id);
1125
1154
  const text = [
1126
1155
  `Preview of ${project.layout.package}/ for ${harness ? `solution ${harness.slug}${harness.status ? ` (${harness.status})` : ""}` : "the tenant"}${envFile ? ` [env ${envFile.name}]` : ""}:`,
1127
1156
  previewText(preview, context),
@@ -1272,7 +1301,7 @@ export const explain = {
1272
1301
  ? processingStepCapHint(await readLimits(ctx).catch(() => undefined))
1273
1302
  : ceiling
1274
1303
  ? ceilingHint(await readLimits(ctx).catch(() => undefined))
1275
- : pairOrderPointer(entry.code);
1304
+ : (pairOrderPointer(entry.code) ?? confirmationPointer(entry.code));
1276
1305
  const kitHint = kitText ? spoken(kitText) : undefined;
1277
1306
  const pages = capacity === MODEL_ENDPOINT_BUSY ? [CAPACITY_TUTORIAL_PAGE, CAPACITY_CONCEPT_PAGE] : [CAPACITY_CONCEPT_PAGE, CAPACITY_TUTORIAL_PAGE];
1278
1307
  const read = capacity ? (await listedPages(ctx, pages)).map((page) => ({ page, command: cavelonCommand("docs", "get", page) })) : [];
@@ -1299,7 +1328,7 @@ export const explain = {
1299
1328
  ["meaning", entry.message],
1300
1329
  ["fix", hint ?? undefined],
1301
1330
  ["with the CLI", cli],
1302
- [capacity || stepCap || ceiling ? "raise" : "order", kitHint],
1331
+ [capacity || stepCap || ceiling ? "raise" : confirmationPointer(entry.code) ? "with cavelon" : "order", kitHint],
1303
1332
  ["why", entry.explanation ? clip(entry.explanation.replace(/\s+/g, " "), 600) : undefined],
1304
1333
  ["docs", docs],
1305
1334
  ["read", read.length ? read.map((r) => r.command).join("; ") : undefined],
@@ -1326,11 +1355,16 @@ function missingSecrets(blockers) {
1326
1355
  }
1327
1356
  return [...names];
1328
1357
  }
1329
- function missingSecretsLine(names, may) {
1358
+ function missingSecretsLine(names, may, inAdmin) {
1330
1359
  const which = `Secret${names.length === 1 ? "" : "s"} ${names.join(", ")} ${names.length === 1 ? "is" : "are"} not set`;
1331
- const commands = names.map((n) => secretSetCommand(n)).join("; ");
1332
- if (may === false)
1333
- return `${which}, and this token's role cannot set secrets. ${SECRET_SETTER}: ${commands}`;
1360
+ if (inAdmin === true)
1361
+ return `${which}: ${SECRET_SETTER_IN_ADMIN} (never the agent).`;
1362
+ const commands = names.map((n) => secretStep(n, false)).join("; ");
1363
+ if (may === false) {
1364
+ return inAdmin === false
1365
+ ? `${which}, and this token's role cannot set secrets. ${SECRET_SETTER_IN_ADMIN}.`
1366
+ : `${which}, and this token's role cannot set secrets. ${SECRET_SETTER}: ${commands}`;
1367
+ }
1334
1368
  return `${which}: a person sets ${names.length === 1 ? "it" : "each"} (never the agent): ${commands}`;
1335
1369
  }
1336
1370
  const count = (value) => (typeof value === "number" ? value : null);
@@ -1362,7 +1396,7 @@ export async function solutionState(ctx, ref) {
1362
1396
  const secrets = missingSecrets(readiness.blockers ?? []);
1363
1397
  const principal = await principalOf(await ctx.client());
1364
1398
  if (secrets.length)
1365
- state.missing_secrets = { names: secrets, may_set: maySetSecrets(principal) };
1399
+ state.missing_secrets = { names: secrets, may_set: maySetSecrets(principal), set_in_admin: secretsInAdminOnly(principal) };
1366
1400
  if (harness.status !== "active")
1367
1401
  state.may_activate = mayActivate(accessOf(principal));
1368
1402
  if ("latest_test_run" in readiness) {
@@ -1398,7 +1432,7 @@ export function solutionStateLines(state) {
1398
1432
  : undefined;
1399
1433
  const lines = [["state", [state.harness.status, ready].filter(Boolean).join(", ")]];
1400
1434
  if (state.missing_secrets)
1401
- lines.push(["secrets", missingSecretsLine(state.missing_secrets.names, state.missing_secrets.may_set)]);
1435
+ lines.push(["secrets", missingSecretsLine(state.missing_secrets.names, state.missing_secrets.may_set, state.missing_secrets.set_in_admin ?? null)]);
1402
1436
  const route = state.default_route;
1403
1437
  if (route)
1404
1438
  lines.push(["default route", defaultRouteText(state.harness, route, state.may_activate ?? null)]);
@@ -1462,7 +1496,11 @@ async function defaultRouteAfterActivation(ctx, harness, input, defaultConfirmed
1462
1496
  if (route.current?.id === harness.id)
1463
1497
  return { data: { default_route: { is_default: true, current } }, lines: [`${named(harness)} is the tenant's default route.`] };
1464
1498
  const commands = defaultCommands(harness.slug);
1465
- const gate = make && !defaultConfirmed ? await confirmation(ctx, input, "activate", { harness: harness.id, from: current?.id ?? null }) : undefined;
1499
+ const gate = make && !defaultConfirmed
1500
+ ? await confirmation(ctx, input, "activate", { harness: harness.id, from: current?.id ?? null }, {
1501
+ person: { what: defaultChangeLine(harness, route), words: ["activate", "--harness", harness.slug, "--make-default", "--confirm"] },
1502
+ })
1503
+ : undefined;
1466
1504
  if (gate?.confirmed || (make && defaultConfirmed)) {
1467
1505
  try {
1468
1506
  await setDefaultRoute(ctx, harness.id);
@@ -1535,7 +1573,8 @@ export const activate = {
1535
1573
  "Afterwards it says whether the solution is the tenant's default route (the one the tenant's chat and widget answer with\n" +
1536
1574
  "where no solution is named). --make-default previews making it the default; with --confirm as well, it changes it. That\n" +
1537
1575
  "changes live traffic: show the preview to a person and confirm only with their yes. `cavelon harness default` does the\n" +
1538
- "same for an active solution.",
1576
+ "same for an active solution.\n" +
1577
+ PERSON_CONFIRMS_HELP,
1539
1578
  readOnly: false,
1540
1579
  idempotent: true,
1541
1580
  mcpTool: "activate",
@@ -1597,7 +1636,7 @@ export const activate = {
1597
1636
  const pair = pairOrderHint(await catalogFor(ctx, false), blockers.flatMap((b) => [b.message ?? undefined, b.detail ?? undefined]));
1598
1637
  const secrets = missingSecrets(blockers);
1599
1638
  const maySet = maySetSecrets(principal);
1600
- const secretsLine = secrets.length ? missingSecretsLine(secrets, maySet) : undefined;
1639
+ const secretsLine = secrets.length ? missingSecretsLine(secrets, maySet, secretsInAdminOnly(principal)) : undefined;
1601
1640
  return {
1602
1641
  data: {
1603
1642
  activated: false,
@@ -1631,9 +1670,15 @@ export const activate = {
1631
1670
  triggers: reach.triggers?.map((t) => t.id) ?? null,
1632
1671
  ...(make ? { make_default: true, from: route?.current?.id ?? null } : {}),
1633
1672
  };
1634
- const gate = await confirmation(ctx, input, "activate", change);
1673
+ const words = ["activate", "--harness", harness.slug, ...(make ? ["--make-default"] : []), "--confirm"];
1674
+ const gate = await confirmation(ctx, input, "activate", change, {
1675
+ person: {
1676
+ what: [reachText(harness, reach), ...(make && route && route.current?.id !== harness.id ? [defaultChangeLine(harness, route)] : [])].join("\n"),
1677
+ words,
1678
+ },
1679
+ });
1635
1680
  if (!gate.confirmed) {
1636
- const confirm = gate.confirm(cavelonCommand("activate", "--harness", harness.slug, ...(make ? ["--make-default"] : []), "--confirm"));
1681
+ const confirm = gate.confirm(cavelonCommand(...words));
1637
1682
  const routeLine = make && route && route.current?.id !== harness.id ? [defaultChangeLine(harness, route)] : [];
1638
1683
  return {
1639
1684
  data: {
@@ -1,6 +1,6 @@
1
1
  import { boolOption, CURSOR_OPTION, intOption, LIMIT_OPTION, pageOf, positional, stringOption, } from "../command.js";
2
2
  import { CavelonError, ExitCode, usageError } from "../errors.js";
3
- import { confirmation, confirmTokenRequired } from "../confirm-token.js";
3
+ import { confirmation, confirmTokenRequired, PERSON_CONFIRMS_HELP } from "../confirm-token.js";
4
4
  import { keyValues, moreHint, table } from "../format.js";
5
5
  import { callStable } from "../invoke.js";
6
6
  import { formatQuota, limitError, limitsOrWarn, readQuotas } from "../limits.js";
@@ -82,7 +82,8 @@ export const tenantCreate = {
82
82
  "without tenants.manage, is refused with exit 7 and nothing is sent. Without --confirm nothing is created: the preview\n" +
83
83
  "names the tenant, its plan and the instance it would be created on. A tenant is a platform change, so show the preview\n" +
84
84
  "to a person and confirm only with their yes. With --use, the new tenant is chosen only once the instance confirms the\n" +
85
- "token acts in it. Inviting people and assigning roles stay in the Admin.",
85
+ "token acts in it. Inviting people and assigning roles stay in the Admin.\n" +
86
+ PERSON_CONFIRMS_HELP,
86
87
  readOnly: false,
87
88
  mcpTool: "tenant_create",
88
89
  positionals: [{ name: "slug", description: "Lower-case letters, digits and dashes.", required: true }],
@@ -97,7 +98,7 @@ export const tenantCreate = {
97
98
  "idempotency-key": IDEMPOTENCY_OPTION,
98
99
  confirm: { type: "boolean", mcpToken: true, description: "Create the tenant (after a person saw the preview)." },
99
100
  },
100
- examples: ["cavelon tenant create newco --name NewCo", "cavelon tenant create newco --name NewCo --confirm", "cavelon tenant create newco --name NewCo --confirm <token>"],
101
+ examples: ["cavelon tenant create newco --name NewCo", "cavelon tenant create newco --name NewCo --confirm"],
101
102
  async run(ctx, input) {
102
103
  const session = await ctx.session();
103
104
  if (ctx.mode === "mcp" && input.options.confirm === true)
@@ -116,12 +117,15 @@ export const tenantCreate = {
116
117
  const plan = stringOption(input, "plan");
117
118
  if (plan)
118
119
  body.plan = plan;
119
- const gate = await confirmation(ctx, input, "tenant_create", body, { platform: "outside" });
120
+ const words = ["tenant", "create", slug, "--name", body.name, ...(plan ? ["--plan", plan] : []), ...(boolOption(input, "use") ? ["--use"] : [])];
121
+ const key = stringOption(input, "idempotency-key");
122
+ if (key)
123
+ words.push("--idempotency-key", key);
124
+ const gate = await confirmation(ctx, input, "tenant_create", body, {
125
+ platform: "outside",
126
+ person: { what: `Create the tenant ${body.name} (${slug})${plan ? ` on plan ${plan}` : ""} on the platform.`, words: [...words, "--confirm"] },
127
+ });
120
128
  if (!gate.confirmed) {
121
- const words = ["tenant", "create", slug, "--name", body.name, ...(plan ? ["--plan", plan] : []), ...(boolOption(input, "use") ? ["--use"] : [])];
122
- const key = stringOption(input, "idempotency-key");
123
- if (key)
124
- words.push("--idempotency-key", key);
125
129
  const confirm = gate.confirm(cavelonCommand(...words, "--confirm"));
126
130
  return {
127
131
  data: { created: false, would: "create_tenant", tenant: { slug, name: body.name, plan: plan ?? null }, confirm, ...gate.fields },
@@ -269,7 +273,8 @@ export const harnessDefault = {
269
273
  "tenant's default is an empty `default` solution, so a solution built beside it answers nobody there until it becomes the\n" +
270
274
  "default. Without --confirm nothing changes: the preview names the current default and the one that would replace it.\n" +
271
275
  "This changes live traffic, so show the preview to a person and confirm only with their yes. `is_default` in\n" +
272
- "harnesses.yaml is not applied by `apply`; this is the way to set it.",
276
+ "harnesses.yaml is not applied by `apply`; this is the way to set it.\n" +
277
+ PERSON_CONFIRMS_HELP,
273
278
  readOnly: false,
274
279
  idempotent: true,
275
280
  mcpTool: "harness_default",
@@ -278,7 +283,7 @@ export const harnessDefault = {
278
283
  options: {
279
284
  confirm: { type: "boolean", mcpToken: true, description: "Change the default route (after a person saw the preview)." },
280
285
  },
281
- examples: ["cavelon harness default support", "cavelon harness default support --confirm", "cavelon harness default support --confirm <token>"],
286
+ examples: ["cavelon harness default support", "cavelon harness default support --confirm"],
282
287
  async run(ctx, input) {
283
288
  const session = await ctx.session();
284
289
  const ref = positional(input, "solution") ?? session.envFile?.harness ?? session.project?.harness;
@@ -307,7 +312,9 @@ export const harnessDefault = {
307
312
  details: { harness: target, default_route: current },
308
313
  });
309
314
  }
310
- const gate = await confirmation(ctx, input, "harness_default", { harness: harness.id, from: current?.id ?? null });
315
+ const gate = await confirmation(ctx, input, "harness_default", { harness: harness.id, from: current?.id ?? null }, {
316
+ person: { what: defaultChangeLine(harness, route), words: ["harness", "default", harness.slug, "--confirm"] },
317
+ });
311
318
  if (!gate.confirmed) {
312
319
  return {
313
320
  data: {