@cavelon/cli 0.1.10 → 0.1.12

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 (45) hide show
  1. package/README.md +34 -15
  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/change-confirmation.js +93 -0
  6. package/dist/commands/api.js +77 -30
  7. package/dist/commands/chat.js +16 -8
  8. package/dist/commands/db.js +474 -0
  9. package/dist/commands/docs.js +83 -7
  10. package/dist/commands/index.js +7 -0
  11. package/dist/commands/limits-set.js +11 -5
  12. package/dist/commands/loops.js +72 -9
  13. package/dist/commands/models.js +12 -6
  14. package/dist/commands/sandboxes.js +7 -2
  15. package/dist/commands/session.js +111 -24
  16. package/dist/commands/setup.js +1 -1
  17. package/dist/commands/solution.js +211 -54
  18. package/dist/commands/tenants.js +55 -12
  19. package/dist/commands/values.js +104 -23
  20. package/dist/commands/work.js +13 -5
  21. package/dist/confirm-token.js +90 -7
  22. package/dist/context.js +5 -1
  23. package/dist/contracts.js +37 -12
  24. package/dist/database-queries.js +301 -0
  25. package/dist/fsutil.js +14 -0
  26. package/dist/http.js +69 -3
  27. package/dist/install.js +30 -0
  28. package/dist/invoke.js +12 -2
  29. package/dist/kit-codes.js +9 -2
  30. package/dist/mcp.js +106 -19
  31. package/dist/openapi.js +7 -0
  32. package/dist/package-check.js +19 -0
  33. package/dist/preview-report.js +2 -2
  34. package/dist/principal.js +24 -2
  35. package/dist/printed.js +5 -0
  36. package/dist/secret-access.js +30 -9
  37. package/dist/session.js +36 -8
  38. package/dist/skills/cavelon-authoring/SKILL.md +93 -10
  39. package/dist/skills/cavelon-long-running/SKILL.md +18 -8
  40. package/dist/skills/cavelon-loop/SKILL.md +126 -41
  41. package/dist/skills/cavelon-testing/SKILL.md +32 -3
  42. package/dist/trace-view.js +10 -0
  43. package/dist/update-check.js +2 -2
  44. package/dist/user-config.js +24 -0
  45. package/package.json +1 -1
package/dist/printed.js CHANGED
@@ -34,6 +34,11 @@ export function printedCommand(words, override = {}) {
34
34
  }
35
35
  return commandLine(words);
36
36
  }
37
+ export function personCommand(...words) {
38
+ const target = current.getStore();
39
+ const spec = target ? commandOf(target.commands, words) : undefined;
40
+ return commandLine(target && spec ? withTarget(spec, words, target) : words);
41
+ }
37
42
  function withTokenPlaceholder(words) {
38
43
  const at = words.indexOf("--confirm");
39
44
  if (at < 0)
@@ -1,30 +1,51 @@
1
+ import { pathMatches } from "./access.js";
1
2
  import { CavelonError, ExitCode } from "./errors.js";
2
- import { cavelonCommand } from "./printed.js";
3
+ import { cavelonCommand, fill } from "./printed.js";
3
4
  export const SECRETS_PERMISSIONS = ["settings.secrets.manage", "settings.manage"];
4
5
  export const SECRET_SETTER = "A tenant Owner (or another role allowed to manage secrets) sets it, in the Admin under Settings › Secrets or with their own token";
6
+ export const SECRET_SETTER_IN_ADMIN = "A tenant Owner (or another role allowed to manage secrets) sets it, signed in to the Admin under Settings › Secrets";
7
+ export const SECRETS_IN_ADMIN = "in the Admin under Settings › Secrets";
8
+ const SECRET_ROUTE = "/api/v1/secrets/{name}";
9
+ export function secretsInAdminOnly(principal, method = "PUT") {
10
+ if (!principal || !Array.isArray(principal.needs_a_person))
11
+ return null;
12
+ return principal.needs_a_person.some((o) => o.method === method && pathMatches(o.path, SECRET_ROUTE));
13
+ }
5
14
  export function maySetSecrets(principal) {
6
15
  if (!principal)
7
16
  return null;
8
- if (principal.kind === "api_key")
17
+ if (principal.kind === "api_key" || secretsInAdminOnly(principal))
9
18
  return false;
10
19
  if (!principal.permissions || principal.mode !== "tenant")
11
20
  return null;
12
21
  return SECRETS_PERMISSIONS.some((p) => principal.permissions.includes(p));
13
22
  }
14
- export function permissionsNamed(message) {
15
- const at = /permissions?:\s*([\w.]+(?:\s*,\s*[\w.]+)*)/i.exec(message);
16
- return at ? at[1].split(",").map((p) => p.trim()).filter(Boolean) : [];
23
+ export { permissionsNamed } from "./access.js";
24
+ export const VARIABLE_SETTER = "A tenant Owner (or another role allowed to manage the tenant's settings) sets it, in the Admin under Settings › Variables or with their own token";
25
+ export function variableSetterHint(name, value) {
26
+ const shown = value !== undefined && value.length <= 120 && !value.includes("\n") ? value : fill("value");
27
+ return `${VARIABLE_SETTER}: \`${cavelonCommand("variables", "set", name, shown)}\`.`;
28
+ }
29
+ export function variablesPermissionMissing(verb, name, permissions, value) {
30
+ const needs = permissions.length ? permissions.join(" or ") : "a permission to manage the tenant's settings";
31
+ return new CavelonError(ExitCode.unauthorized, {
32
+ code: "permission_missing",
33
+ status: 403,
34
+ message: `This credential may not ${verb} tenant variables: the instance refused it, as that needs ${needs}. Variable ${name} is unchanged.`,
35
+ hint: variableSetterHint(name, value),
36
+ details: { name, permissions, sent: true },
37
+ });
17
38
  }
18
- export function secretSetterHint(name) {
19
- return `${SECRET_SETTER}: \`${cavelonCommand("secrets", "set", name)}\`.`;
39
+ export function secretSetterHint(name, inAdmin = false) {
40
+ return inAdmin ? `${SECRET_SETTER_IN_ADMIN}.` : `${SECRET_SETTER}: \`${cavelonCommand("secrets", "set", name)}\`.`;
20
41
  }
21
- export function secretsPermissionMissing(verb, name, permissions) {
42
+ export function secretsPermissionMissing(verb, name, permissions, inAdmin = false) {
22
43
  const needs = permissions.length ? permissions.join(" or ") : "a permission to manage secrets";
23
44
  return new CavelonError(ExitCode.unauthorized, {
24
45
  code: "permission_missing",
25
46
  status: 403,
26
47
  message: `This token's role may not ${verb} secrets: the instance refused it, as that needs ${needs}. Secret ${name} is unchanged.`,
27
- hint: secretSetterHint(name),
48
+ hint: secretSetterHint(name, inAdmin),
28
49
  details: { name, permissions, sent: true },
29
50
  });
30
51
  }
package/dist/session.js CHANGED
@@ -5,7 +5,7 @@ import { exactMatch } from "./choose.js";
5
5
  import { readTenantless } from "./principal.js";
6
6
  import { listsTenants, searchTenants, tenantMissError } from "./tenant-choice.js";
7
7
  import { findProject, readEnvFile } from "./project.js";
8
- import { loadUserConfig, tokenKind, updateInstance } from "./user-config.js";
8
+ import { cachedTenantRef, loadUserConfig, tokenKind, updateInstance, withoutTenantRef, withTenantRefs, } from "./user-config.js";
9
9
  import { cavelonCommand, fill } from "./printed.js";
10
10
  const UUID = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
11
11
  export function isUuid(value) {
@@ -97,6 +97,10 @@ export async function resolveSession(env, cwd, globals) {
97
97
  [session.tenant, session.tenantSource] = [envFile.tenant, `env/${envFile.name}.yaml`];
98
98
  else if (projectMatches && project?.tenant)
99
99
  [session.tenant, session.tenantSource] = [project.tenant, "cavelon.yaml"];
100
+ else if (globals.sessionTenants?.get(url)) {
101
+ session.sessionTenant = globals.sessionTenants.get(url);
102
+ [session.tenant, session.tenantSource] = [session.sessionTenant.ref, "session"];
103
+ }
100
104
  else if (settings.tenant)
101
105
  [session.tenant, session.tenantSource] = [settings.tenant, "use"];
102
106
  return session;
@@ -225,23 +229,47 @@ async function findTenant(client, ref) {
225
229
  }
226
230
  return { known: memberships };
227
231
  }
228
- export async function resolveTenantId(env, session, client) {
232
+ export function knownTenantId(session, now = new Date()) {
229
233
  if (!session.tenant || !session.url)
230
234
  return undefined;
231
235
  if (session.tokenKind === "api_key")
232
236
  return undefined;
233
237
  if (isUuid(session.tenant))
234
238
  return session.tenant;
235
- const cached = session.settings.tenant_ids?.[session.tenant];
236
- if (cached)
237
- return cached;
239
+ if (session.tenantSource === "session" && session.sessionTenant)
240
+ return session.sessionTenant.id;
238
241
  if (session.tenantSource === "use" && session.settings.tenant_id)
239
242
  return session.settings.tenant_id;
240
- const found = await lookupTenantId(client, session.tenant, session.tenantSource);
243
+ return cachedTenantRef(session.settings, session.tenant, session.token, now);
244
+ }
245
+ export async function resolveTenantId(env, session, client, now = new Date()) {
246
+ if (!session.tenant || !session.url)
247
+ return undefined;
248
+ if (session.tokenKind === "api_key")
249
+ return undefined;
250
+ const known = knownTenantId(session, now);
241
251
  const url = session.url;
242
252
  const slug = session.tenant;
243
- await updateInstance(env, url, (current) => ({ ...current, tenant_ids: { ...current.tenant_ids, [slug]: found.id } }));
244
- return found.id;
253
+ const fromCache = known !== undefined && !isUuid(slug) && session.tenantSource !== "use" && session.tenantSource !== "session";
254
+ const resolve = async () => {
255
+ const found = await lookupTenantId(client, slug, session.tenantSource);
256
+ if (client.target.token) {
257
+ const token = client.target.token;
258
+ await updateInstance(env, url, (current) => withTenantRefs(current, [slug], found.id, token, now));
259
+ }
260
+ return found.id;
261
+ };
262
+ if (!fromCache)
263
+ return known ?? resolve();
264
+ client.revalidateTenant = async () => {
265
+ await updateInstance(env, url, (current) => withoutTenantRef(current, slug));
266
+ const fresh = await resolve().catch(() => undefined);
267
+ if (!fresh || fresh === client.target.tenantId)
268
+ return false;
269
+ client.target.tenantId = fresh;
270
+ return true;
271
+ };
272
+ return known;
245
273
  }
246
274
  export async function reloadSettings(env, url) {
247
275
  return (await loadUserConfig(env)).instances[url] ?? {};
@@ -51,11 +51,12 @@ for a public widget), **propose the change; the person decides.**
51
51
  without `confirm`). It changes nothing and shows the old and the new value,
52
52
  the operation it would send and the permissions it needs. Show that to the
53
53
  person with your reason (what fails or waits now), and wait for their answer.
54
- - Only after they agreed, run the confirm command it printed (the `confirm`
55
- field in `--json`) as it stands: it keeps the `--env` and `--tenant` of the
56
- preview, so it changes the limit the preview showed. Over MCP, call
57
- `limits_set` again with the same arguments and `confirm` set to the
58
- preview's `confirm_token`. Never raise a limit on
54
+ - The confirm is the person's. Over MCP, call `limits_set` again with the
55
+ same arguments and `confirm` set to the preview's `confirm_token`: the
56
+ client then asks the person, and nothing changes without their yes. From
57
+ your shell, the preview's `confirm` is the command the person runs in their
58
+ own terminal: give it to them as it stands (it keeps the `--env` and
59
+ `--tenant` of the preview). Never raise a limit on
59
60
  your own, never pick a value higher than the need you named, and never change
60
61
  one without telling them.
61
62
  - The same goes for the tenant's monthly inference budget
@@ -70,7 +71,8 @@ for a public widget), **propose the change; the person decides.**
70
71
  otherwise refuses naming the role and the Admin page; `--tenant <tenant>`
71
72
  then sets one tenant's own run cap. Without a `change` it cannot be changed
72
73
  at runtime. Tell the person who changes it and where, and design within it
73
- meanwhile; never ask for an operator's token.
74
+ meanwhile; never ask for an operator's token. A docs page marked "Platform
75
+ page" describes such an operator's task: this token can read it, not do it.
74
76
  - A rate limit only goes down to what the operator allows; above the ceiling
75
77
  (`maximum_setting`), it is the operator's too. That holds for the per-visitor
76
78
  limits (`rate_limit_chat_visitor_rpm`, `rate_limit_widget_visitor_rpm`) as
@@ -108,8 +110,9 @@ endpoint.
108
110
  - On rows that already exist, `cavelon models list` shows each row's endpoint
109
111
  and `max_concurrent_requests` (never a key). `cavelon models set-limit
110
112
  <model_id> <n|none>` shows the old and the new value and changes nothing;
111
- the confirm command it prints changes the row (from your shell it carries the
112
- preview's token, `--confirm <token>`). It refuses a row without a `base_url`.
113
+ the confirm changes the row, with the person's yes (over MCP the client asks
114
+ them; from your shell they run the confirm command in their own terminal).
115
+ It refuses a row without a `base_url`.
113
116
  Where this instance's package format does not carry the field, `validate`
114
117
  warns that the import ignores it; set it this way instead.
115
118
  - `model_registry` is tenant-wide: in a solution's folder, `cavelon apply`
@@ -295,7 +298,16 @@ schema has them: `cavelon validate` reports an unknown section):
295
298
  - **Variables** are plain text that anyone who may view the tenant's settings
296
299
  reads. You may set one with `cavelon variables set <name> <value>` (the
297
300
  `variables_set` tool) when the value is not a credential and you know it;
298
- ask the person otherwise. `cavelon variables list` shows them.
301
+ ask the person otherwise. Setting one needs the permission a secret needs: a
302
+ Builder's role may not (`cavelon whoami` says "may set variables: no", and
303
+ `apply` says so under "needs variables"); then tell the person that a tenant
304
+ Owner sets it, in the Admin under Settings › Variables or with their own
305
+ token. `cavelon variables list` shows them. A variable
306
+ is tenant-wide: replacing a value previews the old and the new one and
307
+ changes nothing without `--confirm` (the `confirm_token` over MCP); every
308
+ solution of the tenant reads it, active ones too, so the confirm needs the
309
+ person's yes: over MCP the client asks them, and from your shell they run
310
+ the confirm command in their own terminal. A new variable is set at once.
299
311
  - **Secrets are set by a person, never by you.** Tell the person the exact
300
312
  command `apply` printed, `cavelon secrets set <name>` (with the `--env` and
301
313
  `--tenant` it printed), to run in their own terminal; it asks for the value
@@ -307,7 +319,78 @@ schema has them: `cavelon validate` reports an unknown section):
307
319
  says "may set secrets: no", and `secrets set`, `activate` and `status` then
308
320
  name who does instead. Tell the person that a tenant Owner sets it, in the
309
321
  Admin under Settings › Secrets or with their own token; do not suggest the
310
- command to someone whose role cannot run it.
322
+ command to someone whose role cannot run it. Where the instance lets no
323
+ token set a secret (`secret_needs_a_person`; the preview names the Admin
324
+ instead of the command), the person sets it signed in to the Admin under
325
+ Settings › Secrets.
326
+
327
+ ## Database query tools
328
+
329
+ A database query tool lets an agent answer from a customer's live database. A
330
+ saved, read-only query is one tool (`tool_type: database_query` in
331
+ `package/tools.yaml`); the model only calls it and fills the parameters it is
332
+ given, and never writes SQL. `cavelon schema tools.database_query` lists the
333
+ fields this instance takes; `cavelon docs get administration/database-connectors`
334
+ says who does what on the instance.
335
+
336
+ ```yaml
337
+ - slug: order_status # the function name the model calls: a-z, 0-9, - and _
338
+ name: Order status # the label in the Admin
339
+ description: Status and shipping date of one of the signed-in visitor's orders, by order number.
340
+ tool_type: database_query
341
+ scope: tenant_local
342
+ database_query:
343
+ connection: { name: shop-db, dialect: postgresql } # by name only: never a host, user or password; postgresql, mysql or mssql
344
+ sql_text: SELECT number, status, shipped_at FROM orders WHERE number = :order_no AND email = :email LIMIT 5
345
+ parameters:
346
+ - name: order_no
347
+ type: string
348
+ description: Order number as printed on the confirmation, e.g. A-10023
349
+ pattern: "^[A-Z]-[0-9]{4,8}$"
350
+ max_length: 20
351
+ - name: email
352
+ source: end_user.email # filled by the instance from the signed-in visitor
353
+ type: string
354
+ max_rows: 5
355
+ allows_anonymous: false
356
+ ```
357
+
358
+ - **Who writes a query.** Only a superadmin of the instance creates or changes
359
+ a query, in the Admin; your token never does. The query's SQL, parameters,
360
+ limits and `allows_anonymous`, and the tool's own `slug`, `name` and
361
+ `description`, are all part of the query. `cavelon validate` warns
362
+ (`database_query_changed`) for each query tool that differs from the last
363
+ pull or apply, and the import preview blocks it
364
+ (`database_query_needs_superadmin`), which stops the whole apply. Propose a
365
+ query change to the person as a diff of `package/tools.yaml`; they hand it
366
+ to a superadmin, who imports the package in the Admin. What you may change
367
+ freely is how agents and skills use the tool: the assignment
368
+ (`tool_assignments` with `config_overrides` `name`, `description` or
369
+ `max_calls`) is no query change. `params_json_schema` and `default_config`
370
+ of a query tool are derived from the query, and the instance ignores the
371
+ package's (`database_query_fields_ignored`).
372
+ - **Identity parameters.** A parameter with `source: end_user.id`,
373
+ `end_user.external_subject` or `end_user.email` is filled by the instance
374
+ from the signed-in visitor's verified identity (an email only once
375
+ verified), never by the model: it is a required string without
376
+ constraints. Scope every query that returns a person's data by such a
377
+ parameter, so a visitor only reads their own rows. Without a signed-in
378
+ visitor the call answers `identity_required` and the query does not run.
379
+ - **`allows_anonymous`.** Set it to true only for public data (stock, prices,
380
+ opening hours) and only on a query without an identity parameter; the
381
+ instance refuses it otherwise (`anonymous_with_context_parameter`).
382
+ - **Safe query design.** One `SELECT` or `WITH` statement; select only the
383
+ columns the answer needs (never `SELECT *`); always bound the rows (`LIMIT`,
384
+ `TOP`, `FETCH FIRST`) and keep `max_rows` small; constrain every model
385
+ parameter (`pattern`, `max_length`, `enum`, `minimum`/`maximum`) and
386
+ describe it, since the model fills it from the conversation; where a lookup
387
+ has no identity parameter, ask for a second factor (an order number and its
388
+ postal code) rather than one guessable key. Each `:name` in the SQL needs
389
+ exactly one parameter of that name (a literal colon is `\:`); validate checks
390
+ this (`bind_mismatch`) and each parameter's type and constraints.
391
+ - `cavelon explain <code>` explains every code the connector uses: what
392
+ `validate` and the preview name, the codes of a failed call (`timeout`,
393
+ `identity_required`, …) and of a connection test.
311
394
 
312
395
  ## After each edit
313
396
 
@@ -57,14 +57,21 @@ Do not work around it; use the other column.
57
57
  ## Run and follow
58
58
 
59
59
  ```bash
60
- cavelon loop start <trigger> --input @request.json # prints the run id and an operation id
60
+ cavelon loop start <trigger> --input @request.json # previews: the trigger, its solution, the payload
61
+ cavelon loop start <trigger> --input @request.json --confirm <token> # a draft's trigger: starts it, the run id and an operation id
61
62
  cavelon loop watch <run> --timeout 5m # each iteration's verdict, then the loop's outcome
62
63
  cavelon loop iterations <run> # state, budget, iterations (a page at a time)
63
64
  cavelon wait <operation-id> --timeout 90s # exit 0 done, 1 failed, 5 needs a person, 6 still running
64
65
  ```
65
66
 
66
67
  A loop started from `cavelon` runs **as the person whose token it is**, checked
67
- again on every iteration. If `loop start` exits 8 (a timeout, a cut
68
+ again on every iteration, and spends the tenant's budget. So `loop start`
69
+ previews first and starts nothing without `--confirm`. For a trigger of a
70
+ draft solution, run the confirm command it prints (from your shell it carries
71
+ the preview's token; over MCP call `loop_start` again with `confirm` set to its
72
+ `confirm_token`). Any other run needs the person's yes (`needs_person` in the
73
+ preview): over MCP the client asks them when you confirm with the token; from
74
+ your shell the preview names the command they run in their own terminal. If `loop start` exits 8 (a timeout, a cut
68
75
  connection), the run may have started: retry only with the
69
76
  `--idempotency-key <key>` its error names, never without it, or a second run
70
77
  starts and spends the budget again. `cavelon trace <operation-id>` reads the
@@ -124,8 +131,9 @@ Two reasons end work for capacity; each has its code in `cavelon explain`:
124
131
  `model_endpoint_slot_wait_seconds`. Retry later, or, if the endpoint can serve
125
132
  more, propose raising the Model Registry row's `max_concurrent_requests`
126
133
  (`cavelon models list` shows it). The person decides; only then run
127
- `cavelon models set-limit <model_id> <n>` and the confirm command it prints
128
- (`--confirm <token>` from your shell).
134
+ `cavelon models set-limit <model_id> <n>`: over MCP the client asks the person
135
+ when you confirm with the token; from your shell the person runs the confirm
136
+ command it prints in their own terminal.
129
137
 
130
138
  `cavelon limits` shows the caps, their source and origin, the slot waits, and
131
139
  branch concurrency (how many items of a Map loop run at once, and whether they
@@ -160,12 +168,14 @@ its trigger. `apply` never binds one; it lists unbound triggers in the preview.
160
168
 
161
169
  ```bash
162
170
  cavelon trigger identity <trigger> # who it runs as, what the key must reach
163
- cavelon trigger identity <trigger> <key-name> # shows the change and its confirm token
164
- cavelon trigger identity <trigger> <key-name> --confirm <token> # from your shell; a person's terminal takes a bare --confirm
171
+ cavelon trigger identity <trigger> <key-name> # shows the change
172
+ cavelon trigger identity <trigger> <key-name> --confirm # the person, in their own terminal
165
173
  ```
166
174
 
167
- Binding gives the trigger standing authority over its Sandboxes: show the person
168
- first and confirm only after they agree. Name the key by its name or id, never
175
+ Binding gives the trigger standing authority over its Sandboxes, so the person
176
+ confirms it: over MCP the client asks them when you call `trigger_identity`
177
+ with the preview's token; from your shell they run the confirm command in their
178
+ own terminal. Name the key by its name or id, never
169
179
  its value. A personal access token is never an execution identity. Creating keys
170
180
  and adding a key to a Sandbox's Access stay in the Admin; the output says when
171
181
  that is still missing.
@@ -18,7 +18,16 @@ use it when you parse the result.
18
18
  deactivate; whether it is ready to
19
19
  activate, its latest test run), the last pull and the open previews.
20
20
  `cavelon whoami` says who the token acts as, when it expires, whether it may
21
- enter Platform mode and which tenants it reaches.
21
+ enter Platform mode, which tenants it reaches, and what it may do there: its
22
+ permissions (an API key's scopes too), whether it may activate and set
23
+ variables, and the operations a person runs instead.
24
+ - **Offer only what the credential may do.** Over MCP, a tool whose
25
+ description starts with "Not for this credential" is one the instance says
26
+ this token or key may not use in this tenant; `api_list` marks such
27
+ operations (`may_send: false`). Do not call them to find out: tell the
28
+ person who does it (the description says who), as for a secret. Where the
29
+ instance does not say (an older one), try, and a refusal names what the
30
+ credential lacks.
22
31
  - **Never handle a token.** If a command exits 7 (not authorised) or says no
23
32
  token, ask the person to run `cavelon login --instance <url>` themselves (in a
24
33
  terminal, or with a `!` prefix where your client offers one). Never ask them
@@ -26,9 +35,15 @@ use it when you parse the result.
26
35
  - **Secrets are set by a person.** When a preview or `cavelon secrets list`
27
36
  names a secret that is not set, tell the person the exact command to run in
28
37
  their terminal, `cavelon secrets set <name>` (as `apply` prints it, with its
29
- `--env` and `--tenant`). Never ask for the value, never pipe or pass one yourself; there is
38
+ `--env` and `--tenant`). Where the instance lets no token set a secret,
39
+ `apply`, `activate`, `status` and `secrets list` name the Admin page
40
+ (Settings › Secrets) instead: tell the person that, not the command. Never ask for the value, never pipe or pass one yourself; there is
30
41
  no MCP tool for it. Plain-text variables you may set with `cavelon variables
31
- set <name> <value>` when the value is not a credential.
42
+ set <name> <value>` when the value is not a credential and your role may
43
+ manage the tenant's settings, as for a secret: a Builder's may not, and
44
+ `cavelon whoami` then says "may set variables: no". Then tell the person
45
+ that a tenant Owner sets it, in the Admin under Settings › Variables or with
46
+ their own token.
32
47
  - **Pass on an update warning.** The first MCP result of a session may warn
33
48
  that `cavelon`, the Cavelon plugin or this folder's skills are behind the
34
49
  latest release (`… is out; this is …`, `The Cavelon plugin is …`), with the
@@ -58,7 +73,13 @@ use it when you parse the result.
58
73
  pass `--tenant` (and `--instance`) to every command, `harness new` and
59
74
  `pull` included: without it a command acts in the tenant `cavelon use`
60
75
  chose, which may be another one. The commands `cavelon` prints carry the
61
- `--tenant` (and `--env`) you gave, confirm lines included; run them as printed. `apply` never creates a solution: when the one an env file names
76
+ `--tenant` (and `--env`) you gave, confirm lines included; run them as printed.
77
+ Every preview names where it acts (`acts on:`, `target` in `--json`): the
78
+ instance, the tenant and the mode; show it to the person with the change.
79
+ Over MCP, `use_tenant` chooses the tenant for this session only and never
80
+ changes the person's stored tenant. A tenant API key in `CAVELON_TOKEN` acts
81
+ only in its own tenant: a command that names another is refused with
82
+ `tenant_mismatch`; never work around it, tell the person which key fits. `apply` never creates a solution: when the one an env file names
62
83
  is missing it stops with `solution_not_found` and names that command. To start from a package file (a blueprint, an
63
84
  export from another instance), run
64
85
  `cavelon init --instance <url> --tenant <tenant> --from <file>` instead of
@@ -71,6 +92,25 @@ use it when you parse the result.
71
92
  In their own terminal, a plain `cavelon init` asks them. Ask for the instance
72
93
  URL if you do not know it.
73
94
 
95
+ - **Database connections are set up by a person.** A database query tool
96
+ needs a connection of the name and dialect its package names, tested
97
+ successfully, in every tenant it is applied to. A superadmin creates it in
98
+ the Admin (Settings › Security & access › Databases), and the tenant Owner tests it
99
+ (`cavelon db test <connection>`); you never handle its host, user or
100
+ password. Use the same connection name in every tenant and environment
101
+ (`env/test.yaml`, `env/prod.yaml`), each pointing at that environment's
102
+ database, so one package serves them all. `cavelon db instance` says which
103
+ dialects this instance runs and the addresses it connects from, which the
104
+ customer allows through their database's firewall; tell the person both
105
+ before they set up a connection. The dialects are `postgresql`, `mysql` and
106
+ `mssql` (SQL Server). A SQL Server login that can write keeps the
107
+ connection's queries from running (`write_privileges_unacknowledged`) until
108
+ it may only read or a superadmin acknowledges it in the Admin, so ask for a
109
+ read-only login. `cavelon db connections` shows which exist, whether their
110
+ last test passed, when their CA certificates expire and why a connection's
111
+ queries cannot be enabled. A pull writes each query's SQL into
112
+ `package/tools.yaml`, so the repository holds it: review it like code.
113
+
74
114
  ## The loop
75
115
 
76
116
  1. **Pull** what is live: `cavelon pull`. It refuses when `package/` has
@@ -119,6 +159,13 @@ use it when you parse the result.
119
159
  code, package file and path, and hint; `cavelon explain <code>` says more.
120
160
  A preview that changes nothing says "Nothing to import" and stores no
121
161
  preview: there is nothing to confirm.
162
+ **A database query your package creates or changes stops the whole
163
+ apply** (`database_query_needs_superadmin`): only a superadmin writes a
164
+ query, in the Admin, and `apply` says so before it sends. Tell the person;
165
+ to apply the other changes now, leave the query as the instance holds it
166
+ (restore the tool's entry as the last pull wrote it, or remove its
167
+ `database_query` block) and preview again. Once a superadmin has imported
168
+ the package in the Admin, `apply` passes while the queries match.
122
169
  5. **Confirm** exactly that preview: `cavelon apply --confirm <preview-id>`
123
170
  (the line `apply` printed, with the same `--env` and `--tenant`). Exit 4
124
171
  means the preview is stale and nothing was imported: the target changed on
@@ -164,7 +211,8 @@ use it when you parse the result.
164
211
  were put on the VM (customer VM).
165
212
  7. **Test**: `cavelon test run --suite <suite>`, then `cavelon wait <operation>`.
166
213
  See the cavelon-testing skill. A solution with a Masterloop node is run with
167
- `cavelon loop start <trigger>` and followed with `cavelon loop watch <run>`;
214
+ `cavelon loop start <trigger>` (it previews; run the confirm command it
215
+ prints) and followed with `cavelon loop watch <run>`;
168
216
  see the cavelon-long-running skill.
169
217
  8. **Fix** what the results and traces show, and go back to step 2. Commit
170
218
  when a step works.
@@ -180,9 +228,10 @@ says when the solution it activated is not the default.
180
228
  - **Ask the person** whether the new solution should become the default. It
181
229
  changes live traffic; never decide it yourself.
182
230
  - With their yes: `cavelon activate --make-default` (or `cavelon harness
183
- default <solution>`) shows the change, naming the current default; show it,
184
- then run the confirm command it printed (from your shell it carries the
185
- change's token: `--confirm <token>`). `harness default` refuses a draft
231
+ default <solution>`) shows the change, naming the current default; show it.
232
+ You cannot confirm it yourself: over MCP the client asks the person when you
233
+ call the tool with the preview's token; from your shell the person runs the
234
+ confirm command it printed in their own terminal. `harness default` refuses a draft
186
235
  (`solution_not_active`, exit 4): only an active solution can be the
187
236
  default, so use `cavelon activate --make-default`.
188
237
  - `is_default` in `harnesses.yaml` is not applied by `apply`; the preview
@@ -202,8 +251,12 @@ says when the solution it activated is not the default.
202
251
 
203
252
  ## Show the person before confirming
204
253
 
205
- Confirm on your own only for a draft solution in a test environment. Stop and
206
- show the preview to the person, and confirm only after they agree, when:
254
+ Show every preview to the person. Confirm on your own only a preview that
255
+ needs no person: `apply` to a draft solution in a test environment (the
256
+ preview says nothing about showing it to a person), `loop start` of a trigger
257
+ of a draft solution, `loop cancel` and `sandbox seed` of a test run or Sandbox
258
+ you started, and `kb upload --replace`. Stop, show the preview, and wait for
259
+ the person when:
207
260
 
208
261
  - the preview lists an active solution under "reaches active", or the target
209
262
  solution is active;
@@ -214,24 +267,51 @@ show the preview to the person, and confirm only after they agree, when:
214
267
  `--include-tenant-wide` or on an instance that imports them anyway): every
215
268
  solution of the tenant sees the change;
216
269
  - the preview lists target needs (secrets, grants, identities): only a person
217
- can provide them, with `cavelon secrets set <name>` or in the Admin.
218
-
219
- The same holds for the other commands that take `--confirm`: without it they
220
- only show what would happen. Show it to the person before `cavelon trigger
221
- identity <trigger> <key> --confirm` (it gives a trigger standing authority),
222
- before `cavelon harness default … --confirm`, `cavelon activate
223
- --make-default --confirm` or `cavelon deactivate --confirm` (they move live
224
- traffic), and
225
- before `cavelon sandbox seed … --confirm` or `cavelon loop cancel … --confirm` on
226
- anything but a test Sandbox or a run you started yourself.
227
-
228
- **Over MCP, confirm with the preview's token.** `api`, `limits_set`,
270
+ can provide them, with `cavelon secrets set <name>` or in the Admin, as the
271
+ preview names it.
272
+
273
+ **The person's yes is theirs to give.** For these, and for `tenant create` (a
274
+ new tenant on the platform), `variables set` that replaces a value (every
275
+ solution of the tenant reads it) and `variables delete`, `loop start` of a
276
+ trigger whose solution is not a draft (a run acts as the person and spends
277
+ budget), `limits set`, `models set-limit`, `trigger identity` (standing
278
+ authority for a trigger), `harness default`, `activate --make-default`,
279
+ `activate` of a solution its preview says a channel or trigger reaches,
280
+ `deactivate` (they move live traffic), and `api` for any operation that is
281
+ not read-only, `cavelon` does not take your confirm as theirs. Their preview
282
+ says how in `needs_person`:
283
+
284
+ - `"client"` (over MCP, where your client can ask the person): show the
285
+ preview, then call the tool again with the same arguments and `confirm` set
286
+ to its token (for `apply`, the preview id). The client then asks the person
287
+ to approve exactly that change, and nothing changes without their yes. A no,
288
+ or no answer within 10 minutes, returns `confirm_declined` (exit code 5):
289
+ ask the person what they want instead of trying again.
290
+ - `"terminal"` (your shell, or a client that cannot ask): the preview's
291
+ `confirm` is the command the person runs in their own terminal, not with `!`
292
+ in your session. Give them that command and wait; never run it yourself. A
293
+ token is refused (`confirm_needs_person`, exit code 5).
294
+
295
+ A new variable, and a draft solution no channel or trigger reaches, need no
296
+ confirm.
297
+
298
+ An instance that publishes `confirmations.enforced` checks the person's yes
299
+ too: after it, `cavelon` asks the instance for a confirmation id for exactly
300
+ that request and sends it along; you never handle it. `confirmation_required`
301
+ or `confirmation_invalid` (exit code 5) means the instance changed nothing:
302
+ show the person the preview again and let them confirm it (in the client's
303
+ dialog or their own terminal), never retry on your own.
304
+
305
+ **Over MCP, confirm with the preview's token.** `api`, `tenant_create`,
306
+ `variables_set` where it replaces a value, `loop_start`, `limits_set`,
229
307
  `models_set_limit`, `loop_cancel`, `sandbox_seed`, `trigger_identity`,
230
- `harness_default`, `deactivate`, `activate` with `make_default`, and
308
+ `harness_default`, `deactivate`, `activate` of a solution a channel or
309
+ trigger reaches or with `make_default`, and
231
310
  `kb_upload` where it would deactivate documents return a `confirm_token` with
232
311
  their preview. Show
233
312
  the preview, then call the tool again with the same arguments and `confirm`
234
- set to that token; it makes exactly the change shown. `confirm: true` is
313
+ set to that token; it makes exactly the change shown, after the person's yes
314
+ where the preview says `needs_person`. `confirm: true` is
235
315
  refused (`confirm_token_required`), and a token of another change returns the
236
316
  new preview with `token_mismatch` (exit code 4): show that one instead. Tool
237
317
  arguments are spelled in snake_case (`make_default`, `keep_both`, `dry_run`);
@@ -241,12 +321,12 @@ closest one named. Over MCP the next steps a tool returns (hints, `next`,
241
321
  make the call as written, filling a value in angle brackets (a
242
322
  `confirm_token` comes from that tool's preview).
243
323
 
244
- **From your shell, `--confirm` takes the same token.** Run by a coding agent,
245
- `limits set`, `models set-limit`, `loop cancel`, `sandbox seed`,
246
- `trigger identity`, `harness default`, `activate --make-default`,
247
- `deactivate`, `kb upload --replace`, `variables delete` and `secrets delete`
248
- print their preview with a confirm token and the command that confirms it
249
- (`… --confirm <token>`). Show the preview, then run exactly that command. A
324
+ **From your shell, `--confirm` takes the same token, where you may confirm.**
325
+ Run by a coding agent, `loop start` of a draft's trigger, `loop cancel`,
326
+ `sandbox seed` and `kb upload --replace` print their preview with a confirm
327
+ token and the command that confirms it (`… --confirm <token>`). Show the
328
+ preview, then run exactly that command. The changes that need the person's yes
329
+ print no token and name the command the person runs in their own terminal. A
250
330
  bare `--confirm`, as the docs show it for a person's terminal, changes nothing
251
331
  from your shell and exits 5; a token of another change exits 4 with the new
252
332
  preview. A line printed before its preview exists ends in
@@ -254,14 +334,13 @@ preview. A line printed before its preview exists ends in
254
334
  `--confirm` first for the preview and its token.
255
335
 
256
336
  **`cavelon api` from your shell has the guards of the MCP `api` tool**, since
257
- `cavelon` sees that a coding agent runs it (`CLAUDECODE`, `CODEX_THREAD_ID`, `CODEX_SANDBOX`,
258
- `CURSOR_AGENT`, `GEMINI_CLI`, `COPILOT_CLI`, `COPILOT_AGENT`, `AI_AGENT` or
259
- `CAVELON_AGENT=1`):
260
-
261
- - For an operation that is not read-only, it prints the request and a confirm
262
- token and sends nothing. Show the request to the person when the rules above
263
- say so, then run the same command again with `--confirm <token>`; it sends
264
- exactly that request. A changed body or parameter needs a new preview (exit 4).
337
+ `cavelon` sees that a coding agent runs it:
338
+
339
+ - For an operation that is not read-only, it prints the request and the
340
+ command the person runs in their own terminal to send it, and sends nothing.
341
+ Show both to the person; you cannot send it yourself, with or without a
342
+ token (`confirm_needs_person`). Over MCP the `api` tool sends it after the
343
+ person's yes in the client.
265
344
  - It refuses an operation the instance keeps for a person
266
345
  (`operation_for_a_person`) and a body that sets a field the instance marks as
267
346
  a secret value (`secret_field_for_a_person`), with or without `--confirm`,
@@ -269,10 +348,14 @@ preview. A line printed before its preview exists ends in
269
348
  both marks up front.
270
349
  Tell the person what the error's hint says; for a secret field, send the rest
271
350
  without it and let the person enter the value (`cavelon secrets set <name>`
272
- or the Admin). Never work around a refusal, by unsetting the variable or by
273
- any other way.
351
+ or the Admin). Never work around a refusal in any way.
274
352
  - Its `@file` body, `--file` and `--output` stay inside the solution folder.
275
353
 
354
+ `cavelon secrets set` and `cavelon secrets delete` are refused from your shell
355
+ (`operation_for_a_person`, exit 5), with or without `--confirm`, before a value
356
+ is read or anything is sent: give the person the command from the error's hint
357
+ to run in their own terminal.
358
+
276
359
  `activate` goes through the readiness gate only, and only with a token that
277
360
  may activate. It never forces: activating without the evidence stays a person's
278
361
  decision in the Admin, so do not ask for it as a shortcut.
@@ -329,7 +412,9 @@ preview · 5 needs a person · 6 timed out (still running) · 7 not authorised
329
412
  - `cavelon docs search <query>` and `cavelon docs get <page>`: the instance's
330
413
  own docs, for its version. They are in English; a German question works for
331
414
  the core concepts, English words for the rest. `cavelon docs get index`
332
- lists every page.
415
+ lists every page. A page marked "Platform page" (`mark` in `--json`)
416
+ describes an operator's actions this token cannot take: tell the person who
417
+ can, never ask for a Platform-mode token.
333
418
  - `.cavelon/inventory.md`: the tenant's solutions, knowledge bases, tools,
334
419
  skills, models, test suites and sandboxes from the last pull; `cavelon sandbox list` for their
335
420
  current state and mode.