@cavelon/cli 0.1.12 → 0.1.14

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.
@@ -1,14 +1,17 @@
1
1
  import { promises as fs } from "node:fs";
2
2
  import path from "node:path";
3
3
  import { bundledSkills, generatedCopy, INSTALLED_MCP_COMMAND, mcpCommand } from "./agents.js";
4
- import { readTextFile, writeFileAtomic } from "./fsutil.js";
4
+ import { readJsonFile, readTextFile, writeFileAtomic } from "./fsutil.js";
5
5
  import { findProgram } from "./git.js";
6
6
  import { isGenerated, removeBlock, removeJsonEntry, upsertBlock, upsertJsonEntry } from "./markers.js";
7
- import { homeDir } from "./paths.js";
7
+ import { cacheDir, homeDir } from "./paths.js";
8
8
  import { runProgram } from "./run-program.js";
9
+ import { KIT_VERSION } from "./version.js";
9
10
  export const MARKETPLACE_SOURCE = "goodguys-gmbh/cavelon-dev-kit";
10
11
  export const MARKETPLACE = "cavelon-dev-kit";
11
12
  export const PLUGIN_ID = "cavelon@cavelon-dev-kit";
13
+ export const GEMINI_EXTENSION = "cavelon";
14
+ export const GEMINI_SOURCE = `https://github.com/${MARKETPLACE_SOURCE}`;
12
15
  function vscodeUserDir(env, platform) {
13
16
  const home = homeDir(env);
14
17
  if (platform === "win32")
@@ -18,11 +21,14 @@ function vscodeUserDir(env, platform) {
18
21
  return path.join(env.XDG_CONFIG_HOME || path.join(home, ".config"), "Code", "User");
19
22
  }
20
23
  const json = (file, key = "mcpServers", extra = {}) => ({ file, format: "json", keys: [key, "cavelon"], extra });
24
+ function geminiHome(env) {
25
+ return path.join(env.GEMINI_CLI_HOME || homeDir(env), ".gemini");
26
+ }
21
27
  export function setupAgents(env, platform = process.platform) {
22
28
  const home = homeDir(env);
23
29
  const claudeDir = env.CLAUDE_CONFIG_DIR || path.join(home, ".claude");
24
30
  const codexDir = env.CODEX_HOME || path.join(home, ".codex");
25
- const geminiDir = path.join(env.GEMINI_CLI_HOME || home, ".gemini");
31
+ const geminiDir = geminiHome(env);
26
32
  const vscode = vscodeUserDir(env, platform);
27
33
  return [
28
34
  {
@@ -64,6 +70,7 @@ export function setupAgents(env, platform = process.platform) {
64
70
  label: "Gemini CLI",
65
71
  commands: ["gemini"],
66
72
  folders: [geminiDir],
73
+ plugin: "gemini",
67
74
  mcp: json(path.join(geminiDir, "settings.json")),
68
75
  skills: path.join(geminiDir, "skills"),
69
76
  },
@@ -146,6 +153,10 @@ async function pluginState(kind, program, env) {
146
153
  return { error: `\`${display(program, args)}\` did not answer in JSON` };
147
154
  }
148
155
  };
156
+ if (kind === "gemini") {
157
+ const manifest = await readJsonFile(path.join(geminiHome(env), "extensions", GEMINI_EXTENSION, "gemini-extension.json"));
158
+ return { marketplace: true, installed: manifest?.name === GEMINI_EXTENSION, enabled: true };
159
+ }
149
160
  const plugins = await read(["plugin", "list", "--json"]);
150
161
  if ("error" in plugins)
151
162
  return { error: plugins.error };
@@ -165,7 +176,25 @@ async function pluginState(kind, program, env) {
165
176
  function firstLine(text) {
166
177
  return (text.split(/\r?\n/).find((l) => l.trim()) ?? "").trim().slice(0, 300);
167
178
  }
179
+ function lastLine(text) {
180
+ return (text.split(/\r?\n/).findLast((l) => l.trim()) ?? "").trim().slice(0, 300);
181
+ }
182
+ async function geminiFolder(kind, env) {
183
+ if (kind !== "gemini")
184
+ return undefined;
185
+ const dir = path.join(cacheDir(env), "gemini");
186
+ await fs.mkdir(dir, { recursive: true, mode: 0o700 });
187
+ return dir;
188
+ }
168
189
  function pluginCommands(kind) {
190
+ if (kind === "gemini") {
191
+ return {
192
+ marketplaceAdd: [],
193
+ marketplaceRemove: [],
194
+ install: ["extensions", "install", GEMINI_SOURCE, "--ref", `v${KIT_VERSION}`, "--consent"],
195
+ uninstall: ["extensions", "uninstall", GEMINI_EXTENSION],
196
+ };
197
+ }
169
198
  return {
170
199
  marketplaceAdd: ["plugin", "marketplace", "add", MARKETPLACE_SOURCE],
171
200
  marketplaceRemove: ["plugin", "marketplace", "remove", MARKETPLACE],
@@ -175,23 +204,23 @@ function pluginCommands(kind) {
175
204
  }
176
205
  export async function planAgent(agent, found, env, command, skills, platform = process.platform) {
177
206
  const usePlugin = Boolean(agent.plugin && found.program);
207
+ const state = usePlugin ? await pluginState(agent.plugin, found.program, env) : undefined;
178
208
  const plan = { agent, found, method: usePlugin ? "plugin" : "files", changes: [] };
179
- if (usePlugin) {
209
+ if (usePlugin && state) {
180
210
  const kind = agent.plugin;
181
211
  const program = found.program;
182
212
  const commands = pluginCommands(kind);
183
- const state = await pluginState(kind, program, env);
184
213
  if ("error" in state) {
185
214
  plan.changes.push({ kind: "plugin", summary: "install the Cavelon plugin", target: display(program, commands.install), outcome: "failed", reason: state.error });
186
215
  return plan;
187
216
  }
188
217
  plan.plugin = state;
189
- if (!state.marketplace) {
218
+ if (!state.marketplace && commands.marketplaceAdd.length) {
190
219
  plan.changes.push({ kind: "marketplace", summary: "add the Cavelon plugin marketplace", target: display(program, commands.marketplaceAdd), outcome: "planned" });
191
220
  }
192
221
  plan.changes.push({
193
222
  kind: "plugin",
194
- summary: "install the Cavelon plugin (skills and tools)",
223
+ summary: kind === "gemini" ? "install the Cavelon extension (skills and tools)" : "install the Cavelon plugin (skills and tools)",
195
224
  target: display(program, commands.install),
196
225
  outcome: state.installed ? "unchanged" : "planned",
197
226
  ...(state.installed && !state.enabled ? { reason: `it is installed but turned off; turn it on in ${agent.label}` } : {}),
@@ -306,11 +335,19 @@ export async function applyPlan(plan, env, command, skills, record) {
306
335
  }
307
336
  try {
308
337
  if (change.kind === "marketplace" || change.kind === "plugin") {
309
- const commands = pluginCommands(plan.agent.plugin);
338
+ const kind = plan.agent.plugin;
339
+ const commands = pluginCommands(kind);
310
340
  const args = change.kind === "marketplace" ? commands.marketplaceAdd : commands.install;
311
- const result = await runProgram(plan.found.program, args, { env, timeoutMs: RUN_TIMEOUT_MS });
341
+ const result = await runProgram(plan.found.program, args, { env, timeoutMs: RUN_TIMEOUT_MS, cwd: await geminiFolder(kind, env) });
312
342
  if (result.code !== 0) {
313
- done.push({ ...change, outcome: "failed", reason: result.error ?? firstLine(result.stderr || result.stdout) ?? `exit ${result.code}` });
343
+ if (kind === "gemini") {
344
+ const reason = result.error ?? (lastLine(`${result.stdout}\n${result.stderr}`) || `exit ${result.code}`);
345
+ done.push({ ...change, outcome: "skipped", reason: `${reason}; the tools server and skills go into Gemini CLI's files instead` });
346
+ done.push(await mcpChange(plan.agent.mcp, command, true, record));
347
+ done.push(await skillsChange(plan.agent.skills, skills, true, record));
348
+ break;
349
+ }
350
+ done.push({ ...change, outcome: "failed", reason: result.error ?? (firstLine(result.stderr || result.stdout) || `exit ${result.code}`) });
314
351
  break;
315
352
  }
316
353
  if (change.kind === "marketplace")
@@ -318,6 +355,8 @@ export async function applyPlan(plan, env, command, skills, record) {
318
355
  else
319
356
  record.plugin_installed = true;
320
357
  done.push({ ...change, outcome: "done" });
358
+ if (kind === "gemini" && change.kind === "plugin")
359
+ done.push(...(await removeFiles(plan.agent, record, skills, new Set())));
321
360
  }
322
361
  else if (change.kind === "mcp") {
323
362
  done.push(await mcpChange(plan.agent.mcp, command, true, record));
@@ -340,7 +379,7 @@ export async function removeAgent(agent, record, env, skills, sharedSkillDirs) {
340
379
  const commands = pluginCommands(agent.plugin);
341
380
  const steps = [];
342
381
  if (record.plugin_installed)
343
- steps.push(["plugin", commands.uninstall, "uninstall the Cavelon plugin", "plugin_installed"]);
382
+ steps.push(["plugin", commands.uninstall, `uninstall the Cavelon ${agent.plugin === "gemini" ? "extension" : "plugin"}`, "plugin_installed"]);
344
383
  if (record.marketplace_added)
345
384
  steps.push(["marketplace", commands.marketplaceRemove, "remove the Cavelon plugin marketplace", "marketplace_added"]);
346
385
  for (const [kind, args, summary, key] of steps) {
@@ -348,7 +387,7 @@ export async function removeAgent(agent, record, env, skills, sharedSkillDirs) {
348
387
  changes.push({ kind, summary, target: [agent.commands[0], ...args].join(" "), outcome: "failed", reason: `${agent.commands[0]} is not on the PATH; run it yourself` });
349
388
  continue;
350
389
  }
351
- const result = await runProgram(found.program, args, { env, timeoutMs: RUN_TIMEOUT_MS });
390
+ const result = await runProgram(found.program, args, { env, timeoutMs: RUN_TIMEOUT_MS, cwd: await geminiFolder(agent.plugin, env) });
352
391
  if (result.code === 0) {
353
392
  delete record[key];
354
393
  changes.push({ kind, summary, target: display(found.program, args), outcome: "removed" });
@@ -358,6 +397,11 @@ export async function removeAgent(agent, record, env, skills, sharedSkillDirs) {
358
397
  }
359
398
  }
360
399
  }
400
+ changes.push(...(await removeFiles(agent, record, skills, sharedSkillDirs)));
401
+ return changes;
402
+ }
403
+ async function removeFiles(agent, record, skills, sharedSkillDirs) {
404
+ const changes = [];
361
405
  if (record.mcp) {
362
406
  const change = await removeMcp(agent.mcp, record.mcp);
363
407
  if (change.outcome !== "failed" && change.outcome !== "skipped")
@@ -444,23 +488,25 @@ async function topmostMissing(dir) {
444
488
  export async function checkAgent(agent, env, record, platform = process.platform) {
445
489
  const found = await findAgent(agent, env, platform);
446
490
  const check = { name: agent.name, label: agent.label, found: Boolean(found.program || found.folder), method: null, ok: true, details: [], servers: [] };
447
- if (agent.plugin && found.program) {
491
+ const state = agent.plugin && found.program ? await pluginState(agent.plugin, found.program, env) : undefined;
492
+ const viaFiles = !state || (agent.plugin === "gemini" && ("error" in state || !state.installed));
493
+ const what = agent.plugin === "gemini" ? "extension" : "plugin";
494
+ if (state && !viaFiles) {
448
495
  check.method = "plugin";
449
- const state = await pluginState(agent.plugin, found.program, env);
450
496
  if ("error" in state) {
451
497
  check.ok = false;
452
498
  check.details.push(`could not ask ${agent.label} about its plugins: ${state.error}`);
453
499
  }
454
500
  else if (!state.installed) {
455
501
  check.ok = false;
456
- check.details.push("the Cavelon plugin is not installed");
502
+ check.details.push(`the Cavelon ${what} is not installed`);
457
503
  }
458
504
  else if (!state.enabled) {
459
505
  check.ok = false;
460
- check.details.push(`the Cavelon plugin is installed but turned off; turn it on in ${agent.label}`);
506
+ check.details.push(`the Cavelon ${what} is installed but turned off; turn it on in ${agent.label}`);
461
507
  }
462
508
  else {
463
- check.details.push("the Cavelon plugin is installed");
509
+ check.details.push(`the Cavelon ${what} is installed`);
464
510
  if (platform !== "win32")
465
511
  check.servers.push(await serverCommand(env, platform));
466
512
  }
@@ -327,7 +327,7 @@ schema has them: `cavelon validate` reports an unknown section):
327
327
  ## Database query tools
328
328
 
329
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
330
+ saved query of explicit `kind: read` or `kind: write` is one tool (`tool_type: database_query` in
331
331
  `package/tools.yaml`); the model only calls it and fills the parameters it is
332
332
  given, and never writes SQL. `cavelon schema tools.database_query` lists the
333
333
  fields this instance takes; `cavelon docs get administration/database-connectors`
@@ -355,15 +355,25 @@ says who does what on the instance.
355
355
  allows_anonymous: false
356
356
  ```
357
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
358
+ - **Who writes a query.** A personal access token whose principal holds
359
+ `database_connectors.manage` may create or change a query with `cavelon
360
+ apply`: the tenant Owner (or Admin) and a superadmin in Tenant mode hold
361
+ that permission. Read `cavelon whoami` and the instance's
362
+ `database_connector.may_write_queries`; the instance decides. The query's
363
+ SQL, parameters, limits and `allows_anonymous`, and the tool's own `slug`, `name` and
361
364
  `description`, are all part of the query. `cavelon validate` warns
362
365
  (`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
366
+ pull or apply. Edit the definition in `package/tools.yaml`, validate it and
367
+ preview with `cavelon apply`. If the preview's
368
+ `database_queries.would_write` is nonempty, the person approves even for a
369
+ draft: over MCP the client asks them when you confirm the preview id; from
370
+ an agent's shell they run the printed confirm in their own terminal. Only
371
+ after their yes does cavelon request the instance's confirmation id and
372
+ send it with that exact import. An unchanged definition needs no query
373
+ confirmation. A credential without manage is blocked with
374
+ `database_query_needs_superadmin`, stopping the whole import; its hint
375
+ names who this instance permits (older instances can still require a
376
+ superadmin in the Admin). What you may change
367
377
  freely is how agents and skills use the tool: the assignment
368
378
  (`tool_assignments` with `config_overrides` `name`, `description` or
369
379
  `max_calls`) is no query change. `params_json_schema` and `default_config`
@@ -379,7 +389,7 @@ says who does what on the instance.
379
389
  - **`allows_anonymous`.** Set it to true only for public data (stock, prices,
380
390
  opening hours) and only on a query without an identity parameter; the
381
391
  instance refuses it otherwise (`anonymous_with_context_parameter`).
382
- - **Safe query design.** One `SELECT` or `WITH` statement; select only the
392
+ - **Read query design.** One `SELECT` or `WITH` statement; select only the
383
393
  columns the answer needs (never `SELECT *`); always bound the rows (`LIMIT`,
384
394
  `TOP`, `FETCH FIRST`) and keep `max_rows` small; constrain every model
385
395
  parameter (`pattern`, `max_length`, `enum`, `minimum`/`maximum`) and
@@ -388,10 +398,157 @@ says who does what on the instance.
388
398
  postal code) rather than one guessable key. Each `:name` in the SQL needs
389
399
  exactly one parameter of that name (a literal colon is `\:`); validate checks
390
400
  this (`bind_mismatch`) and each parameter's type and constraints.
401
+ - **Read stored procedures (SQL Server only).** On an `mssql` connection the SQL
402
+ may instead be exactly one call, `EXEC [schema].[procedure] @p1 = :p1, @p2 =
403
+ :p2`: every argument a placeholder with a declared parameter, no literal,
404
+ `OUTPUT`, option or dynamic SQL (`procedure_call_form`; on another dialect
405
+ `not_select`). `cavelon validate` warns of both. Put fixed values inside the
406
+ procedure. The model gets the first result set. The instance saves, enables
407
+ and runs such a query only while the connection's last test found no write
408
+ privileges, acknowledged or not (`write_privileges_block_procedure`), and
409
+ only for a procedure whose definition the login may read and that only
410
+ reads (`procedure_definition_unreadable`, `procedure_definition_writes`):
411
+ ask the person for a read-only login with `EXECUTE` and `VIEW DEFINITION`
412
+ on procedures that read. Where a procedure is not needed, write a `SELECT`.
391
413
  - `cavelon explain <code>` explains every code the connector uses: what
392
414
  `validate` and the preview name, the codes of a failed call (`timeout`,
393
415
  `identity_required`, …) and of a connection test.
394
416
 
417
+ ### Authoring a write query
418
+
419
+ Read the instance's schema before using these fields. Set `kind: write`
420
+ explicitly, keep `max_affected_rows` small (default 1, at most 100), and keep
421
+ `requires_confirmation: true` (the default) so the signed-in person confirms
422
+ in chat before execution. `max_calls` takes 1–1000; omitted, the instance
423
+ uses 1 for a write and 5 for a read. For the example above, keep its
424
+ parameters and replace the SQL and write settings with:
425
+
426
+ ```yaml
427
+ kind: write
428
+ sql_text: UPDATE orders SET status = 'cancelled' WHERE number = :order_no AND email = :email
429
+ max_affected_rows: 1
430
+ requires_confirmation: true
431
+ max_calls: 1
432
+ ```
433
+
434
+ One `INSERT`, `UPDATE` or `DELETE`; `UPDATE`/`DELETE` need a parameterized
435
+ `WHERE`. Upserts and `RETURNING`/`OUTPUT` are allowed, a leading `WITH` and
436
+ multiple statements are not (`write_statement_refused`). On SQL Server one
437
+ `EXEC` of a writing procedure is allowed, subject to the instance's
438
+ `write_procedure_definition_refused` checks, including no transaction
439
+ control or `SET NOCOUNT ON`. Local validation cannot prove a procedure's
440
+ behavior; read the server's preview and test results.
441
+
442
+ Use a dedicated least-privilege write login. A tenant Owner or Admin enables
443
+ writes in the Admin with `database_connectors.allow_writes` from a tenant
444
+ membership; a global role alone does not grant it. `allows_writes`,
445
+ passwords and privilege acknowledgment remain person-only Admin actions,
446
+ never query or connection package fields. `db connections` displays the
447
+ published flag; validation warns on explicit false (`writes_not_allowed`)
448
+ and treats omission or an unreadable/offline list as unknown. Tokens get
449
+ `person_only_operation` and tenant API keys get `key_needs_a_person` on
450
+ the password and write-enable routes; follow `needs_a_person`.
451
+
452
+ The import/API approval of a query definition is separate from its
453
+ `requires_confirmation` chat execution prompt. Test writes against a test
454
+ database: `db test-run` is a dry run that rolls back and prints only the
455
+ returned evidence. Never retry `write_outcome_unknown`; ask a person to
456
+ check the database before any repetition. `cavelon explain <code>` reads
457
+ the instance's published catalog.
458
+
459
+ ### Calling a query from a workflow
460
+
461
+ Where the instance's package schema supports it, a `tool_call` node names a
462
+ saved query with `tool_slug` and `tool_type: database_query`. Its incoming
463
+ payload is the query's arguments: only the model-sourced parameter names.
464
+ Map workflow data with a Transform before the node; there is no per-node
465
+ JSONPath argument mapping. Never include an identity parameter (such as
466
+ `email`) or an unknown name: the call answers `invalid_arguments` and runs
467
+ nothing. `config_overrides` do not apply to a query node.
468
+
469
+ For `order_status` above, add this fragment to
470
+ `package/registry_entities.yaml`, connect the workflow's entry to
471
+ `query_arguments`, and provide the `query_failed` and `show_order` agents.
472
+ Keep these nodes and edges in the same solution.
473
+
474
+ ```yaml
475
+ orchestration_nodes:
476
+ - slug: query_arguments
477
+ node_type: transform
478
+ config:
479
+ mode: json_mapping
480
+ mapping: { order_no: $.previous_output.order_number }
481
+ - slug: lookup_order
482
+ node_type: tool_call
483
+ config:
484
+ tool_slug: order_status
485
+ tool_type: database_query
486
+ input_schema:
487
+ type: object
488
+ properties: { order_no: { type: string, maxLength: 20 } }
489
+ required: [order_no]
490
+ additionalProperties: false
491
+ output_format: auto
492
+ - slug: query_result
493
+ node_type: router
494
+ config: { strategy: condition }
495
+ graph_edges:
496
+ - from_node_ref: { kind: orchestration, slug: query_arguments }
497
+ to_node_ref: { kind: orchestration, slug: lookup_order }
498
+ edge_type: pipeline
499
+ - from_node_ref: { kind: orchestration, slug: lookup_order }
500
+ to_node_ref: { kind: orchestration, slug: query_result }
501
+ edge_type: pipeline
502
+ - from_node_ref: { kind: orchestration, slug: query_result }
503
+ to_node_ref: { kind: agent, slug: query_failed }
504
+ edge_type: condition
505
+ config:
506
+ branch_key: failed
507
+ priority: 0
508
+ condition: { source: previous_output, path: error, operator: exists }
509
+ - from_node_ref: { kind: orchestration, slug: query_result }
510
+ to_node_ref: { kind: agent, slug: show_order }
511
+ edge_type: condition
512
+ config: { branch_key: answered, default: true }
513
+ ```
514
+
515
+ - **Output.** Success is `columns`, `rows` (each row an array in column
516
+ order), `returned_rows`, `truncated`, an optional `note`, and the query's
517
+ `source`. Read cells by position, e.g. `$.previous_output.rows[0][1]` for
518
+ the second column. Failure is `{error, message}` with a fixed message,
519
+ never database driver text; the node records the code as its failure and
520
+ keeps this output, so the Router branches on `error`. Read the published
521
+ output under `x-cavelon-output.database_query` on the Tool Call config.
522
+ - **Identity.** A conversation-bound run fills identity parameters from its
523
+ signed-in Chat User. A trigger, schedule or inbound-email run has none:
524
+ an identity-bound query, or one without `allows_anonymous: true`, answers
525
+ `identity_required`. `validate` warns on trigger paths that reach these
526
+ queries. A trigger execution identity is not a Chat User; use only a
527
+ public-data query with no identity parameters and `allows_anonymous: true`
528
+ in such a run.
529
+ - **Write confirmation and budget.** Every direct Tool Call node refuses a
530
+ write with `requires_confirmation: true` (`confirmation_unavailable`),
531
+ because it cannot wait for the person's click; `validate` warns. Turn it
532
+ off only for an intended unattended write. The shared workflow cap
533
+ counts the query's saved `max_calls` across a workflow run's Tool Call
534
+ nodes, Agent stages, `for_each` iterations and concurrent branches, and
535
+ persists on resume. The next call is refused with `tool_call_limit_reached`
536
+ and evidence records `refused`. A direct node fails with that code; an Agent
537
+ receives the tool's refusal. Read queries have no
538
+ run cap. Agent per-turn limits apply in addition to the shared run cap.
539
+ Ordinary chat per-turn limits stay as they are. Do not infer runtime acceptance
540
+ from kit fixtures, or raise a query's saved run cap with assignment `config_overrides`.
541
+ - **Validation.** `validate` checks argument names in `input_schema` and a
542
+ directly preceding Transform's flat JSON mapping, using the query's
543
+ parameters (or the remembered query when its definition is left out).
544
+ Dynamic arguments still need a test. If neither the package nor the
545
+ tenant's last tools list names the query, it warns with
546
+ `tool_call_database_query_missing`; `--strict` fails. The server's import
547
+ preview checks the reference again. `cavelon explain
548
+ tool_call_database_query_missing` explains the published code. On an
549
+ older instance the kit keeps the schema's rules and skips checks for query
550
+ nodes it does not publish.
551
+
395
552
  ## After each edit
396
553
 
397
554
  1. `cavelon validate` until it reports no errors (`--strict` before an apply
@@ -21,6 +21,10 @@ use it when you parse the result.
21
21
  enter Platform mode, which tenants it reaches, and what it may do there: its
22
22
  permissions (an API key's scopes too), whether it may activate and set
23
23
  variables, and the operations a person runs instead.
24
+ Its optional `needs_a_person_when` lists conditional identity choices
25
+ separately; `api list` and `api describe` show their reasons, and
26
+ `api list --usable` keeps these operations for ordinary requests. Never
27
+ read a reason as authority or treat the conditional list as unconditional.
24
28
  - **Offer only what the credential may do.** Over MCP, a tool whose
25
29
  description starts with "Not for this credential" is one the instance says
26
30
  this token or key may not use in this tenant; `api_list` marks such
@@ -92,23 +96,45 @@ use it when you parse the result.
92
96
  In their own terminal, a plain `cavelon init` asks them. Ask for the instance
93
97
  URL if you do not know it.
94
98
 
95
- - **Database connections are set up by a person.** A database query tool
99
+ - **Connect a database, leaving the password with a person.** A database query tool
96
100
  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
+ successfully, in every tenant it is applied to. A personal access token
102
+ holding `database_connectors.manage` (the tenant Owner, legacy Admin, or a
103
+ superadmin in Tenant mode) may run `cavelon db connections create|update|delete`
104
+ and upload a public CA with `cavelon db connections ca <connection> <file>`.
105
+ Create sends no password and prints the Admin step from `needs_a_person`;
106
+ a person enters it in Settings › Security & access › Databases. Never take
107
+ a password as an argument, environment value, stdin, file or tool input.
108
+ Private keys are refused by CA upload. Test with `cavelon db test <connection>`.
109
+ Use the same connection name in every tenant and environment
101
110
  (`env/test.yaml`, `env/prod.yaml`), each pointing at that environment's
102
111
  database, so one package serves them all. `cavelon db instance` says which
103
112
  dialects this instance runs and the addresses it connects from, which the
104
113
  customer allows through their database's firewall; tell the person both
105
- before they set up a connection. The dialects are `postgresql`, `mysql` and
114
+ before setting up a connection. `cavelon db login-script <dialect>` or
115
+ `cavelon db login-script --connection <connection>` returns the script this
116
+ build actually publishes (currently `read_only`), never an invented write
117
+ script. The DBA replaces its password placeholder locally. Explore only
118
+ the catalog with `cavelon db schema <connection> [schema]`, a read-only
119
+ operation requiring `database_connectors.manage`. The instance tutorial is
120
+ `cavelon docs get administration/database-connector-setup`.
121
+ Keep connection settings outside packages: the query names only name and
122
+ dialect. `allows_writes`, when published, is read-only kit output;
123
+ enabling it and acknowledging write privileges stay in the dashboard.
124
+ A password-bearing target's host, port or dialect change needs a person
125
+ in the Admin; preserve `credential_required_for_target_change`.
126
+ Older instances may lack these routes or keep management person-only;
127
+ follow their published gate and direct a person to their dashboard.
128
+ The dialects are `postgresql`, `mysql` and
106
129
  `mssql` (SQL Server). A SQL Server login that can write keeps the
107
130
  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
131
+ it may only read or the Owner acknowledges it in the Admin, so ask for a
132
+ read-only login. A stored-procedure query (`EXEC`, SQL Server only) needs
133
+ one without any write privileges, acknowledged or not
134
+ (`write_privileges_block_procedure`), and a procedure that only reads.
135
+ `cavelon db connections` shows which exist, whether their
110
136
  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
137
+ queries, or its stored-procedure queries, cannot be enabled. A pull writes each query's SQL into
112
138
  `package/tools.yaml`, so the repository holds it: review it like code.
113
139
 
114
140
  ## The loop
@@ -159,13 +185,18 @@ use it when you parse the result.
159
185
  code, package file and path, and hint; `cavelon explain <code>` says more.
160
186
  A preview that changes nothing says "Nothing to import" and stores no
161
187
  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
188
+ **Database query changes need manage permission and the person's yes.**
189
+ A PAT holding `database_connectors.manage` (the tenant Owner or a
190
+ superadmin in Tenant mode) may apply them. A nonempty
191
+ `database_queries.would_write` in the instance's preview needs person
192
+ approval even on a draft: over MCP the client asks; from an agent's shell
193
+ the person runs the printed confirm. A credential without that permission
194
+ gets `database_query_needs_superadmin`, which stops the whole import;
195
+ the blocker's hint names who this instance permits. To apply the other
196
+ changes now, leave the query as the instance holds it
166
197
  (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.
198
+ `database_query` block) and preview again. Matching definitions need no
199
+ query confirmation, and a no-op preview stores nothing.
169
200
  5. **Confirm** exactly that preview: `cavelon apply --confirm <preview-id>`
170
201
  (the line `apply` printed, with the same `--env` and `--tenant`). Exit 4
171
202
  means the preview is stale and nothing was imported: the target changed on
@@ -225,6 +256,17 @@ with one solution: its **default route**. A fresh tenant's default is an empty
225
256
  `cavelon harness list` marks the default (DEFAULT), and `cavelon activate`
226
257
  says when the solution it activated is not the default.
227
258
 
259
+ Activation can also take this route without `--make-default`. Read its
260
+ published preview: `takes_default_route: true` needs the person's yes,
261
+ including when `takes_default_route_from` and `_from_name` are both null
262
+ (assigning an unassigned route). False with null/null means no takeover.
263
+ An omitted flag is unknown, even if the schema declares a false default,
264
+ and still needs the person. Never infer the effect from instructions, a
265
+ default slug or other configuration. The preview reserves no state; the
266
+ successful activation's `took_default_route` and corresponding from/name
267
+ fields report the actual effect, which may differ. `status` shows the
268
+ preview too.
269
+
228
270
  - **Ask the person** whether the new solution should become the default. It
229
271
  changes live traffic; never decide it yourself.
230
272
  - With their yes: `cavelon activate --make-default` (or `cavelon harness
@@ -266,6 +308,9 @@ the person when:
266
308
  solution of the tenant, reaching the active solutions …`, after
267
309
  `--include-tenant-wide` or on an instance that imports them anyway): every
268
310
  solution of the tenant sees the change;
311
+ - the instance's preview lists query writes under
312
+ `database_queries.would_write`: its SQL changes what agents may read from
313
+ the tenant's database, even on a draft;
269
314
  - the preview lists target needs (secrets, grants, identities): only a person
270
315
  can provide them, with `cavelon secrets set <name>` or in the Admin, as the
271
316
  preview names it.
@@ -277,6 +322,7 @@ trigger whose solution is not a draft (a run acts as the person and spends
277
322
  budget), `limits set`, `models set-limit`, `trigger identity` (standing
278
323
  authority for a trigger), `harness default`, `activate --make-default`,
279
324
  `activate` of a solution its preview says a channel or trigger reaches,
325
+ whose activation takes the default route, or whose reach or route effect is unknown,
280
326
  `deactivate` (they move live traffic), and `api` for any operation that is
281
327
  not read-only, `cavelon` does not take your confirm as theirs. Their preview
282
328
  says how in `needs_person`:
@@ -292,8 +338,11 @@ says how in `needs_person`:
292
338
  in your session. Give them that command and wait; never run it yourself. A
293
339
  token is refused (`confirm_needs_person`, exit code 5).
294
340
 
295
- A new variable, and a draft solution no channel or trigger reaches, need no
296
- confirm.
341
+ A new variable needs no confirm. A solution needs none only when no channel
342
+ or active trigger reaches it and readiness explicitly publishes
343
+ `takes_default_route: false`. If the single read leaves `channel_count`
344
+ null, the kit reads the matching list row; an unreadable list, missing row
345
+ or missing count keeps reach unknown and needs the person.
297
346
 
298
347
  An instance that publishes `confirmations.enforced` checks the person's yes
299
348
  too: after it, `cavelon` asks the instance for a confirmation id for exactly
@@ -306,7 +355,8 @@ dialog or their own terminal), never retry on your own.
306
355
  `variables_set` where it replaces a value, `loop_start`, `limits_set`,
307
356
  `models_set_limit`, `loop_cancel`, `sandbox_seed`, `trigger_identity`,
308
357
  `harness_default`, `deactivate`, `activate` of a solution a channel or
309
- trigger reaches or with `make_default`, and
358
+ trigger reaches, whose activation takes the default route or whose reach or
359
+ route effect is unknown, or with `make_default`, and
310
360
  `kb_upload` where it would deactivate documents return a `confirm_token` with
311
361
  their preview. Show
312
362
  the preview, then call the tool again with the same arguments and `confirm`