@cavelon/cli 0.1.15 → 0.1.17

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 (51) hide show
  1. package/README.md +44 -1
  2. package/dist/agent-env.js +3 -0
  3. package/dist/agents.js +16 -7
  4. package/dist/approval-policy.js +1 -0
  5. package/dist/commands/db.js +6 -2
  6. package/dist/commands/init.js +46 -10
  7. package/dist/commands/limits-set.js +11 -1
  8. package/dist/commands/limits.js +7 -1
  9. package/dist/commands/session.js +3 -0
  10. package/dist/commands/setup.js +18 -5
  11. package/dist/confirm-token.js +2 -1
  12. package/dist/database-limits.js +46 -0
  13. package/dist/fsutil.js +24 -7
  14. package/dist/jsonc-config.js +223 -0
  15. package/dist/kit-codes.js +1 -0
  16. package/dist/mcp-command.js +5 -0
  17. package/dist/mcp-directory.js +32 -0
  18. package/dist/mcp-entry.js +21 -0
  19. package/dist/mcp.js +18 -2
  20. package/dist/native-approval/client.js +126 -0
  21. package/dist/native-approval/ipc.js +191 -0
  22. package/dist/native-approval/kilo-server.js +33 -0
  23. package/dist/native-approval/kilo-tui.js +13 -0
  24. package/dist/native-approval/omp-extension.js +8 -0
  25. package/dist/native-approval/opencode-server.js +74 -0
  26. package/dist/native-approval/opencode-tui.js +143 -0
  27. package/dist/native-approval/pi-extension.js +86 -0
  28. package/dist/native-approval/preview-pages.js +18 -0
  29. package/dist/native-approval/profile.js +120 -0
  30. package/dist/native-assets/JSONC-LICENSE +21 -0
  31. package/dist/native-assets/LICENSE +201 -0
  32. package/dist/native-assets/MCP-SDK-LICENSE +21 -0
  33. package/dist/native-assets/THIRD-PARTY-NOTICES +386 -0
  34. package/dist/native-assets/TYPEBOX-LICENSE +23 -0
  35. package/dist/native-assets/ZOD-LICENSE +21 -0
  36. package/dist/native-assets/kilo-server.mjs +39719 -0
  37. package/dist/native-assets/kilo-tui.mjs +26477 -0
  38. package/dist/native-assets/manifest.json +82 -0
  39. package/dist/native-assets/omp-extension.mjs +30729 -0
  40. package/dist/native-assets/opencode-server.mjs +39692 -0
  41. package/dist/native-assets/opencode-tui.mjs +26474 -0
  42. package/dist/native-assets/pi-extension.mjs +30726 -0
  43. package/dist/native-assets.js +44 -0
  44. package/dist/native-clients.js +397 -0
  45. package/dist/native-install.js +390 -0
  46. package/dist/omp-config.js +85 -0
  47. package/dist/printed.js +17 -5
  48. package/dist/setup-agents.js +82 -8
  49. package/dist/skills/cavelon-loop/SKILL.md +7 -0
  50. package/dist/yaml-config.js +215 -0
  51. package/package.json +7 -3
package/README.md CHANGED
@@ -21,6 +21,19 @@ in Windows PowerShell. With Python, `uvx cavelon` runs the same executable from
21
21
  PyPI, and `uv tool install cavelon` or `pipx install cavelon` installs it. Then
22
22
  `cavelon setup` sets up your coding agents and logs you in.
23
23
 
24
+ Version 0.1.17 adds Cline, Kilo, Goose and OMP to the OpenCode, Pi and Qwen
25
+ Code integrations. Each has native settings and four skills; guarded changes
26
+ use the qualified client dialog or the person’s own terminal:
27
+
28
+ ```bash
29
+ cavelon setup --agents opencode,pi,qwen,cline,kilo,goose,omp
30
+ ```
31
+
32
+ See the [client install pages](https://github.com/goodguys-gmbh/cavelon-dev-kit/blob/main/docs/install/README.md)
33
+ and [qualification matrix](https://github.com/goodguys-gmbh/cavelon-dev-kit/blob/main/docs/coding-agent-qualification.md)
34
+ for pinned versions, tested platforms, updates and removal.
35
+
36
+
24
37
  The full documentation is in the repository's
25
38
  [`docs/`](https://github.com/goodguys-gmbh/cavelon-dev-kit/tree/main/docs):
26
39
  [installation](https://github.com/goodguys-gmbh/cavelon-dev-kit/blob/main/docs/installation.md)
@@ -110,7 +123,7 @@ Every command takes `--json` (one JSON document on stdout, errors included),
110
123
 
111
124
  | Command | Marked | What it does |
112
125
  |---|---|---|
113
- | `setup [--agents] [--yes] [--check] [--remove]` | changing (destructive) | Set up the coding agents on this computer (the plugin for Claude Code and Codex; the MCP server and skills in the user settings of Cursor, VS Code with GitHub Copilot, Gemini CLI and Kiro) and log in. `--check` reports what works, `--remove` undoes it. A person runs this; not an MCP tool. |
126
+ | `setup [--agents] [--yes] [--check] [--remove]` | changing (destructive) | Set up supported coding agents with their plugin or native MCP configuration and all four skills, then log in. `--check` reports what works, `--remove` undoes it. A person runs this; not an MCP tool. |
114
127
  | `login [--token-stdin]` | changing | Store a token for an instance. A person runs this. |
115
128
  | `logout [--all]` | changing | Delete the stored token. |
116
129
  | `whoami` | read-only | Owner or key, tenant (name, slug and id), role, where the credential came from, whether it may enter Platform mode and which tenants it reaches. |
@@ -192,6 +205,14 @@ release.
192
205
 
193
206
  ### Limits
194
207
 
208
+ `cavelon db instance` and `cavelon limits` show published database connection
209
+ and query caps, current counts, their source and platform defaults. Missing
210
+ counts on older instances are left out. An operator with `limits.manage`
211
+ uses a Platform-mode personal access token to preview an override with
212
+ `cavelon limits set database_queries_per_tenant 250 --tenant acme` and sends
213
+ it after the person's confirmation. `none` resets the override. Tenant Owners
214
+ cannot raise these caps. See [Database limits](https://github.com/goodguys-gmbh/cavelon-dev-kit/blob/main/docs/limits.md#database-connections-and-queries).
215
+
195
216
  `cavelon limits` shows what the instance allows this tenant, from the `limits`
196
217
  it publishes in `/api/v1/meta/capabilities`: upload size and file types, agent
197
218
  turns and tool calls, timeouts, rate limits, the licence's cap on solutions.
@@ -812,3 +833,25 @@ which copy of the package schema it used.
812
833
  In the working directory, only `init`, `pull` and `apply` write, as described
813
834
  in "Solution as code", and `artifacts export`, which writes the tar it
814
835
  downloads to a new file.
836
+
837
+ Version 0.1.17: `cavelon setup --agents cline` writes shared native user settings
838
+ and skills; `cavelon init --agents cline` copies project skills only. Guarded
839
+ changes use the person’s own terminal. See [Cline](../docs/install/cline.md)
840
+ for guarded launch, custom CLI paths and separate editor qualification.
841
+
842
+ Version 0.1.17: `cavelon setup --agents kilo` installs Kilo-native settings, skills
843
+ and bundled server/TUI plugins. CLI TUI changes ask a fresh native dialog;
844
+ editor/headless changes use the person’s terminal. See [Kilo](../docs/install/kilo.md)
845
+ for preserved configuration precedence, guarded launch and lifecycle.
846
+
847
+ Version 0.1.17: `cavelon setup --agents goose` writes Goose's native user YAML
848
+ extension and skills; project init copies shared skills only. The interactive
849
+ CLI uses its built-in person form. Headless runs cancel that form without a
850
+ change. System/additional config bindings and personal YAML are preserved.
851
+ See [Goose](../docs/install/goose.md) for paths, lifecycle and approval limits.
852
+
853
+ Version 0.1.17: `cavelon setup --agents omp` installs OMP's own native profile,
854
+ MCP entry, skills and bundled autoload extension. It preserves personal YAML
855
+ and supports fresh TUI approval; print/RPC calls use the person's terminal.
856
+ Use matching profile selection and a guarded launch. See
857
+ [OMP](../docs/install/omp.md) for lifecycle and qualification limits.
package/dist/agent-env.js CHANGED
@@ -7,11 +7,14 @@ export const AGENT_VARIABLES = [
7
7
  { variable: "CODEX_SANDBOX", agent: "Codex" },
8
8
  { variable: "CURSOR_AGENT", agent: "Cursor" },
9
9
  { variable: "GEMINI_CLI", agent: "Gemini CLI" },
10
+ { variable: "QWEN_CODE", agent: "Qwen Code" },
10
11
  { variable: "COPILOT_CLI", agent: "GitHub Copilot CLI" },
11
12
  { variable: "COPILOT_AGENT", agent: "GitHub Copilot in VS Code" },
12
13
  { variable: "AGENT_CONTEXT_OUT", agent: "Kiro CLI" },
13
14
  { variable: "TERM_PROGRAM", value: "kiro", agent: "Kiro" },
14
15
  { variable: "OPENCODE", agent: "OpenCode" },
16
+ { variable: "PI_SESSION_ID", agent: "Pi" },
17
+ { variable: "AGENT_SESSION_ID", agent: "Goose or another agent exposing its session" },
15
18
  { variable: "GROK_AGENT", agent: "Grok Build" },
16
19
  { variable: "AI_AGENT", agent: "an agent that follows the AI_AGENT convention" },
17
20
  ];
package/dist/agents.js CHANGED
@@ -5,11 +5,10 @@ import { embeddedContent } from "./embedded.js";
5
5
  import { usageError } from "./errors.js";
6
6
  import { GENERATED_TOKEN } from "./markers.js";
7
7
  import { KIT_VERSION } from "./version.js";
8
- export const MCP_COMMAND = { command: "npx", args: ["-y", "@cavelon/cli@0.1", "mcp"] };
9
- export const INSTALLED_MCP_COMMAND = { command: "cavelon", args: ["mcp"] };
10
- export function mcpCommand(platform = process.platform) {
11
- return platform === "win32" ? { command: "cmd", args: ["/c", MCP_COMMAND.command, ...MCP_COMMAND.args] } : MCP_COMMAND;
12
- }
8
+ import { INSTALLED_MCP_COMMAND, mcpCommand } from "./mcp-command.js";
9
+ import { encodeMcpEntry } from "./mcp-entry.js";
10
+ import { NATIVE_CLIENTS, nativeClient } from "./native-clients.js";
11
+ export { MCP_COMMAND, INSTALLED_MCP_COMMAND, mcpCommand } from "./mcp-command.js";
13
12
  const PLATFORMS = ["win32", "linux"];
14
13
  const otherPlatforms = () => PLATFORMS.filter((p) => (p === "win32") !== (process.platform === "win32"));
15
14
  const jsonServer = (file, key = "mcpServers", extra = {}) => ({
@@ -46,7 +45,13 @@ export const AGENTS = [
46
45
  agent("copilot", "GitHub Copilot in VS Code", () => jsonServer(".vscode/mcp.json", "servers", { type: "stdio" })),
47
46
  agent("gemini", "Gemini CLI", () => jsonServer(".gemini/settings.json")),
48
47
  agent("kiro", "Kiro", () => jsonServer(".kiro/settings/mcp.json")),
49
- agent("pi", "Pi"),
48
+ ...NATIVE_CLIENTS.map(client => agent(client.name, client.label, () => {
49
+ const config = client.project();
50
+ if (!config)
51
+ return undefined;
52
+ return { ...config, entry: encodeMcpEntry(mcpCommand(), config.entryFormat, config.extra),
53
+ others: [...otherPlatforms().map(p => encodeMcpEntry(mcpCommand(p), config.entryFormat, config.extra)), encodeMcpEntry(INSTALLED_MCP_COMMAND, config.entryFormat, config.extra)] };
54
+ })),
50
55
  agent("other", "any other agent with a shell"),
51
56
  ];
52
57
  const ALIASES = { "claude-code": "claude", vscode: "copilot", "gemini-cli": "gemini" };
@@ -56,7 +61,7 @@ export function parseAgents(values) {
56
61
  return AGENTS;
57
62
  const out = [];
58
63
  for (const raw of names) {
59
- const name = ALIASES[raw] ?? raw;
64
+ const name = ALIASES[raw] ?? nativeClient(raw)?.name ?? raw;
60
65
  const target = AGENTS.find((a) => a.name === name);
61
66
  if (!target)
62
67
  throw usageError(`Unknown agent "${raw}".`, `Known: ${AGENTS.map((a) => a.name).join(", ")}, or all.`);
@@ -66,6 +71,10 @@ export function parseAgents(values) {
66
71
  return out;
67
72
  }
68
73
  export const SKILL_ROOTS = [".agents/skills", ".claude/skills"];
74
+ export function skillRootsFor(agents) {
75
+ return [...new Set([...SKILL_ROOTS, ...agents.flatMap(agent => nativeClient(agent.name)?.projectSkills ?? [])])];
76
+ }
77
+ export const KNOWN_SKILL_ROOTS = [...new Set([...SKILL_ROOTS, ...NATIVE_CLIENTS.flatMap(client => client.projectSkills)])];
69
78
  export function skillsSource() {
70
79
  const here = path.dirname(fileURLToPath(import.meta.url));
71
80
  return [path.join(here, "skills"), path.resolve(here, "..", "..", "plugin", "skills")];
@@ -0,0 +1 @@
1
+ export const PERSON_WAIT_MS = 10 * 60_000;
@@ -7,6 +7,7 @@ import { callStable } from "../invoke.js";
7
7
  import { cavelonCommand, fill } from "../printed.js";
8
8
  import { isUuid } from "../session.js";
9
9
  import { accessFor, requirePersonForIdentityChoice } from "../access.js";
10
+ import { databaseLimitRows, databaseLimitsText } from "../database-limits.js";
10
11
  function reported(value) {
11
12
  if (value === undefined)
12
13
  return undefined;
@@ -156,10 +157,11 @@ function firewallSentence(offer) {
156
157
  }
157
158
  export const dbInstance = {
158
159
  name: "db instance",
159
- summary: "What this instance offers for database connections: dialects, firewall addresses and write-query support where published.",
160
+ summary: "Database dialects, firewall addresses, write-query support and the tenant's caps and counts where published.",
160
161
  description: "Read it before a database connection is set up: a connection of a dialect the instance does not run can be saved, but\n" +
161
162
  "its test and queries answer unavailable, and the customer's database must let the instance's egress addresses in. An\n" +
162
- "instance older than this route says only its dialects, in its capabilities.",
163
+ "instance older than this route says only its dialects, in its capabilities.\n" +
164
+ "Published limits show current connection/query counts, effective caps, their source and the platform default; missing counts stay missing.",
163
165
  readOnly: true,
164
166
  idempotent: true,
165
167
  mcpTool: "db_instance",
@@ -181,6 +183,7 @@ export const dbInstance = {
181
183
  };
182
184
  }
183
185
  const firewall = firewallSentence(offer);
186
+ const counts = databaseLimitRows(offer.limits);
184
187
  return {
185
188
  data: { published: true, ...offer, firewall },
186
189
  text: [
@@ -193,6 +196,7 @@ export const dbInstance = {
193
196
  ]),
194
197
  "",
195
198
  firewall,
199
+ ...(counts.length ? ["", databaseLimitsText(counts)] : []),
196
200
  ...(offer.runnable_dialects.length ? [] : ["", "This instance runs no database dialect: a connection can be saved, but its test and queries answer unavailable."]),
197
201
  ].join("\n"),
198
202
  };
@@ -2,7 +2,12 @@ import { promises as fs } from "node:fs";
2
2
  import path from "node:path";
3
3
  import { parseDocument } from "yaml";
4
4
  import { boolOption, listOption, stringOption } from "../command.js";
5
- import { AGENTS, bundledSkills, generatedCopy, parseAgents, SKILL_ROOTS } from "../agents.js";
5
+ import { AGENTS, bundledSkills, generatedCopy, parseAgents, KNOWN_SKILL_ROOTS, skillRootsFor } from "../agents.js";
6
+ import { nativeClient, resolveNativeMcp, hasNativeApprovalAdapter } from "../native-clients.js";
7
+ import { applyNativeInstallation, planNativeInstallation } from "../native-install.js";
8
+ import { serverCommand } from "../setup-agents.js";
9
+ import { encodeMcpEntry, isKitMcpEntry } from "../mcp-entry.js";
10
+ import { upsertJsoncEntry } from "../jsonc-config.js";
6
11
  import { CavelonError, ExitCode, usageError } from "../errors.js";
7
12
  import { confinedPath, realPath, within } from "../paths.js";
8
13
  import { readTextFile, withoutBom, writeFileAtomic } from "../fsutil.js";
@@ -192,7 +197,30 @@ async function writeSkills(root, roots) {
192
197
  }
193
198
  return actions;
194
199
  }
195
- async function writeMcp(root, target, onlyExisting) {
200
+ async function writeMcp(root, target, onlyExisting, env) {
201
+ if (target.format === "native") {
202
+ const config = { ...target, ...nativeClient(target.client)?.project(env) };
203
+ if (!hasNativeApprovalAdapter(config)) {
204
+ const selected = await resolveNativeMcp(config, root);
205
+ if ("error" in selected)
206
+ return { file: rel(root, selected.file), action: "skipped", reason: selected.error };
207
+ if (selected.current !== undefined && isKitMcpEntry(selected.current, config.entryFormat, config.extra))
208
+ return { file: rel(root, selected.file), action: "unchanged" };
209
+ const value = encodeMcpEntry(await serverCommand(env), config.entryFormat, config.extra);
210
+ return applyBlock(root, selected.file, upsertJsoncEntry(selected.text, config.keys, value, { onlyExisting, matches: current => isKitMcpEntry(current, config.entryFormat, config.extra) }));
211
+ }
212
+ if (onlyExisting) {
213
+ const selected = await resolveNativeMcp({ ...config, shadowFiles: [] }, root);
214
+ if (!("error" in selected) && selected.current === undefined)
215
+ return { file: rel(root, selected.file), action: "skipped", reason: "it has no cavelon entry" };
216
+ }
217
+ const plan = await planNativeInstallation(config, await serverCommand(env), env, { root });
218
+ if (plan.outcome !== "planned")
219
+ return { file: rel(root, plan.directory), action: plan.outcome, ...(plan.reason ? { reason: plan.reason } : {}) };
220
+ const exists = await fs.stat(plan.directory).then(() => true, () => false);
221
+ await applyNativeInstallation(plan);
222
+ return { file: rel(root, plan.directory), action: exists ? "updated" : "created" };
223
+ }
196
224
  const file = path.join(root, target.file);
197
225
  const existing = await readTextFile(file);
198
226
  if (existing !== undefined && holdsOtherForm(existing, target))
@@ -230,9 +258,9 @@ function holdsOtherForm(existing, target) {
230
258
  }
231
259
  return target.others.some((entry) => JSON.stringify(entry) === JSON.stringify(current));
232
260
  }
233
- async function installedFallback(root) {
261
+ async function installedFallback(root, env) {
234
262
  const skillRoots = [];
235
- for (const skillRoot of SKILL_ROOTS) {
263
+ for (const skillRoot of KNOWN_SKILL_ROOTS) {
236
264
  try {
237
265
  const names = await fs.readdir(path.join(root, skillRoot));
238
266
  for (const name of names.filter((n) => n.startsWith("cavelon-"))) {
@@ -249,6 +277,12 @@ async function installedFallback(root) {
249
277
  for (const agent of AGENTS) {
250
278
  if (!agent.mcp)
251
279
  continue;
280
+ if (agent.mcp.format === "native") {
281
+ const selected = await resolveNativeMcp({ ...agent.mcp, ...nativeClient(agent.name)?.project(env) }, root);
282
+ if ("error" in selected || selected.current !== undefined)
283
+ agents.push(agent);
284
+ continue;
285
+ }
252
286
  const text = await readTextFile(path.join(root, agent.mcp.file));
253
287
  if (text?.includes("cavelon"))
254
288
  agents.push(agent);
@@ -560,13 +594,13 @@ async function runInit(ctx, input) {
560
594
  actions.push(claude);
561
595
  actions.push(await block(root, ".gitignore", GITIGNORE_BLOCK, "hash", { onlyExisting: true }));
562
596
  actions.push(await installHook(root, !boolOption(input, "hook")));
563
- const installed = await installedFallback(root);
564
- const skillRoots = agents.length ? SKILL_ROOTS : installed.skillRoots;
597
+ const installed = await installedFallback(root, ctx.io.env);
598
+ const skillRoots = agents.length ? skillRootsFor(agents) : installed.skillRoots;
565
599
  if (skillRoots.length)
566
600
  actions.push(...(await writeSkills(root, skillRoots)));
567
601
  for (const agent of new Set([...installed.agents, ...agents])) {
568
602
  if (agent.mcp)
569
- actions.push(await writeMcp(root, agent.mcp, !agents.includes(agent)));
603
+ actions.push(await writeMcp(root, agent.mcp, !agents.includes(agent), ctx.io.env));
570
604
  }
571
605
  return { root, actions: actions.filter((a) => !(a.action === "skipped" && /does not exist|no cavelon (block|entry)/.test(a.reason ?? ""))), next, imported: undefined };
572
606
  }
@@ -641,10 +675,12 @@ async function runInit(ctx, input) {
641
675
  if (claude)
642
676
  actions.push(claude);
643
677
  if (agents.length) {
644
- actions.push(...(await writeSkills(root, SKILL_ROOTS)));
645
- for (const agent of agents)
678
+ actions.push(...(await writeSkills(root, skillRootsFor(agents))));
679
+ for (const agent of agents) {
646
680
  if (agent.mcp)
647
- actions.push(await writeMcp(root, agent.mcp, false));
681
+ actions.push(await writeMcp(root, agent.mcp, false, ctx.io.env));
682
+ next.push(...(nativeClient(agent.name)?.notes ?? []));
683
+ }
648
684
  }
649
685
  if (boolOption(input, "hook"))
650
686
  actions.push(await installHook(root, false));
@@ -83,6 +83,14 @@ function findTarget(published, key, explicitTenant) {
83
83
  return limitTarget(key, limit, limit.tenant_change);
84
84
  if (limit.change)
85
85
  return limitTarget(key, limit, limit.change);
86
+ if (limit.tenant_change) {
87
+ throw new CavelonError(ExitCode.usage, {
88
+ code: "tenant_required",
89
+ message: `${key} changes one tenant's override. Nothing was sent.`,
90
+ hint: "Pass --tenant <id|slug> and use a personal access token in Platform mode of the role the published change names.",
91
+ details: { key, sent: false },
92
+ });
93
+ }
86
94
  if (limit.changeable_by !== "tenant_admin")
87
95
  throw operatorRefusal(limit, switchFor(published, key));
88
96
  throw notPublished(`This instance does not publish how to change ${key}, so nothing was sent.`, `It runs an older Cavelon version. A tenant admin changes ${limit.setting} in the Admin's settings. ` +
@@ -262,6 +270,8 @@ function anyOf(names, none = "a permission the instance does not name") {
262
270
  function adminPage(target) {
263
271
  if (target.flag)
264
272
  return FEATURE_FLAGS_PAGE;
273
+ if (target.change.field.startsWith("max_database_"))
274
+ return "the tenant's Limits section (Database connections and Database queries)";
265
275
  return target.scope === "one_tenant" ? TENANT_LIMITS_PAGE : RUN_CAPS_PAGE;
266
276
  }
267
277
  function permissionRefusal(principal, target) {
@@ -469,7 +479,7 @@ export const limitsSet = {
469
479
  "before sending. Without --confirm, shows the old and new value, the operation and who may run it, and changes nothing.\n" +
470
480
  "Also changes the tenant quotas in tenant_quotas.changes (the inference budget, the monthly Processing Step cap).\n" +
471
481
  "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
- "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" +
482
+ "X-Tenant-Id; --tenant <id|slug> then sets one tenant's override, including database connection/query caps. An environment or licence limit, a value out of bounds,\n" +
473
483
  "an instance that does not publish how to change the limit, and a credential without the permission or the role are refused\n" +
474
484
  "before anything is sent. Propose the change to the person; never raise a limit on your own.\n" +
475
485
  PERSON_CONFIRMS_HELP,
@@ -5,6 +5,7 @@ import { table } from "../format.js";
5
5
  import { branchConcurrency, branchConcurrencyText } from "../branches.js";
6
6
  import { bindsNow, bindsWhenText, changedBy, docsPage, formatQuota, formatQuotaValue, formatValue, isOperatorChange, readLimits, readQuotas, } from "../limits.js";
7
7
  import { cavelonCommand, fill } from "../printed.js";
8
+ import { databaseLimitsText, readDatabaseLimits } from "../database-limits.js";
8
9
  const SOURCE_ORDER = ["tenant", "platform", "licence"];
9
10
  const SOURCE_TITLE = {
10
11
  tenant: "Set by this tenant (its own settings)",
@@ -41,6 +42,7 @@ export const limits = {
41
42
  "A limit that binds only while another is on says so (the archive caps apply while archive uploads are on).\n" +
42
43
  "Branch concurrency: the width per node, the ceiling per process, and whether branches run concurrently (and which switch is off).\n" +
43
44
  "The tenant quotas include the monthly Processing Step cap with this billing month's use, where the instance publishes it.\n" +
45
+ "Database connection/query limits include current counts from the connector where published, including counts above a lowered cap.\n" +
44
46
  "A limit the instance does not list does not bind there. An instance older than the published limits lists none.",
45
47
  readOnly: true,
46
48
  idempotent: true,
@@ -74,6 +76,7 @@ export const limits = {
74
76
  if (unknown.length)
75
77
  ctx.warn(`This instance lists no limit ${unknown.join(", ")}; it does not bind here.`);
76
78
  const groups = groupBySource(values);
79
+ const databaseLimits = await readDatabaseLimits(ctx, values.map(value => value.key));
77
80
  const quotas = keys.length || source ? undefined : await readQuotas(ctx, published);
78
81
  const quotaValues = keys.length || source ? [] : (published.tenantQuotas?.values ?? []);
79
82
  const near = [
@@ -109,6 +112,8 @@ export const limits = {
109
112
  text += `\n\nBranch concurrency (fan-outs and Map loops):\n${branchConcurrencyText(branches)}`;
110
113
  if (!groups.length)
111
114
  text = keys.length || source ? "No published limit matches." : "This instance publishes no binding limit.";
115
+ if (databaseLimits.length)
116
+ text += `\n\n${databaseLimitsText(databaseLimits)}`;
112
117
  if (quotas || quotaValues.length) {
113
118
  const rows = [
114
119
  ...(quotas?.items ?? []).map((q) => ({ quota: q.key, use: quotaUse(q), state: typeof q.details.state === "string" ? q.details.state : "", close: q.near ? "close to the quota" : "" })),
@@ -132,7 +137,7 @@ export const limits = {
132
137
  text += `; ${owner.join(", ")} only a Tenant Owner (settings.manage)`;
133
138
  }
134
139
  if (operatorChangeable.length) {
135
- text += `\n\nAn operator changes ${operatorChangeable.join(", ")} with the same command and a personal access token in Platform mode of the role the change names; --tenant <id|slug> sets the tenant (one tenant's own run cap, its flag).`;
140
+ text += `\n\nAn operator changes ${operatorChangeable.join(", ")} with the same command and a personal access token in Platform mode of the role the change names; --tenant <id|slug> selects one tenant's override or flag.`;
136
141
  }
137
142
  const pages = [...new Set(values.map((v) => docsPage(v.docs)).filter(Boolean))];
138
143
  if (pages.length)
@@ -150,6 +155,7 @@ export const limits = {
150
155
  quota_values: quotaValues.map(({ near: isNear, ratio, ...q }) => ({ ...q, ratio, near: isNear })),
151
156
  near: near.map(({ text: _text, ...q }) => q),
152
157
  branch_concurrency: branches ?? null,
158
+ ...(databaseLimits.length ? { database_limits: databaseLimits } : {}),
153
159
  },
154
160
  text,
155
161
  };
@@ -1,4 +1,5 @@
1
1
  import { capacityLimits, capacityNotes } from "../capacity.js";
2
+ import { refuseForAgent } from "../agent-env.js";
2
3
  import { boolOption, positional } from "../command.js";
3
4
  import { compareContracts, Contracts } from "../contracts.js";
4
5
  import { deleteToken, saveToken } from "../credentials.js";
@@ -76,6 +77,7 @@ export const login = {
76
77
  tenantless: true,
77
78
  summary: "Store a token for an instance (a person runs this, never the agent).",
78
79
  description: "Asks for the token without echoing it, or reads it from standard input with --token-stdin. It is never an argument.\n" +
80
+ "A coding agent's shell is refused before reading input or contacting the instance; log in from your own terminal.\n" +
79
81
  "Create a personal access token (cvpat_…) on /account/access-tokens; a tenant API key (cbp_…) also works.\n" +
80
82
  "The token is kept in the operating system's credential store, or in a file only you can read.\n" +
81
83
  "Without --tenant, login finds the tenants the token reaches: one is used; from several, a person chooses on a terminal by number or name; " +
@@ -93,6 +95,7 @@ export const login = {
93
95
  "op read op://dev/cavelon/token | cavelon login --token-stdin --tenant acme-support",
94
96
  ],
95
97
  async run(ctx, input) {
98
+ refuseForAgent(ctx, "Logging in with a token", cavelonCommand("login"));
96
99
  const session = await ctx.session();
97
100
  const url = session.url;
98
101
  if (!url)
@@ -69,12 +69,15 @@ function planJson(plan, changes = plan.changes) {
69
69
  label: plan.agent.label,
70
70
  found: { command: plan.found.program ?? null, folder: plan.found.folder ?? null },
71
71
  method: plan.method,
72
+ ...(plan.agent.notes ? { notes: plan.agent.notes } : {}),
72
73
  changes: changes.map((c) => ({ kind: c.kind, summary: c.summary, target: c.target, outcome: c.outcome, ...(c.reason ? { reason: c.reason } : {}) })),
73
74
  };
74
75
  }
75
76
  function planText(plans, notFound) {
76
77
  const lines = [];
77
78
  for (const plan of plans) {
79
+ for (const note of plan.agent.notes ?? [])
80
+ lines.push(` ${plan.agent.label}: ${note}`);
78
81
  const todo = plan.changes.filter((c) => c.outcome === "planned");
79
82
  const other = plan.changes.filter((c) => c.outcome !== "planned" && c.outcome !== "unchanged");
80
83
  if (!todo.length && !other.length) {
@@ -183,9 +186,10 @@ async function runSetup(ctx, input) {
183
186
  throw new CavelonError(ExitCode.failure, { code: "skills_missing", message: "This cavelon has no skills to install (its package is incomplete).", hint: "Reinstall @cavelon/cli." });
184
187
  }
185
188
  const command = await serverCommand(env);
189
+ const state = await loadState(env);
186
190
  const plans = [];
187
191
  for (const { agent, found: where } of chosen)
188
- plans.push(await planAgent(agent, where, env, command, skills));
192
+ plans.push(await planAgent(agent, where, env, command, skills, process.platform, state.agents[agent.name]));
189
193
  const pending = plans.some((p) => p.changes.some((c) => c.outcome === "planned"));
190
194
  let results = plans.map((plan) => ({ plan, changes: plan.changes }));
191
195
  let declined = false;
@@ -200,7 +204,6 @@ async function runSetup(ctx, input) {
200
204
  declined = !(await confirm(ctx, "Make these changes?", true));
201
205
  }
202
206
  if (!declined) {
203
- const state = await loadState(env);
204
207
  results = [];
205
208
  for (const plan of plans) {
206
209
  const record = (state.agents[plan.agent.name] ??= {});
@@ -209,6 +212,16 @@ async function runSetup(ctx, input) {
209
212
  }
210
213
  }
211
214
  }
215
+ let recovered = false;
216
+ if (!declined)
217
+ for (const { plan, changes } of results) {
218
+ if (plan.native && changes.some(change => change.kind === "native" && change.outcome === "unchanged") && !state.agents[plan.agent.name]?.native) {
219
+ (state.agents[plan.agent.name] ??= {}).native = { directory: plan.native.directory };
220
+ recovered = true;
221
+ }
222
+ }
223
+ if (recovered)
224
+ await saveState(env, state);
212
225
  const loginReport = declined ? undefined : await loginStep(ctx);
213
226
  const failed = results.some((r) => r.changes.some((c) => c.outcome === "failed"));
214
227
  const ready = results.filter((r) => r.changes.length && r.changes.every((c) => c.outcome === "done" || c.outcome === "unchanged"));
@@ -226,7 +239,7 @@ async function runSetup(ctx, input) {
226
239
  next.push(`Or start a solution yourself in an empty folder: ${cavelonCommand("init")}`);
227
240
  }
228
241
  else if (!chosen.length) {
229
- next.push("No coding agent was found. Install one (Claude Code, Codex, Cursor, VS Code with GitHub Copilot, Gemini CLI or Kiro) and run cavelon setup again,", ` or name yours: ${cavelonCommand("setup", "--agents", "cursor")}`);
242
+ next.push(`No coding agent was found. Install one (${setupAgents(env).map(agent => agent.label).join(", ")}) and run cavelon setup again,`, ` or name yours: ${cavelonCommand("setup", "--agents", "cursor")}`);
230
243
  }
231
244
  }
232
245
  const lines = [];
@@ -400,7 +413,7 @@ export const setup = {
400
413
  storesTarget: true,
401
414
  tenantless: true,
402
415
  summary: "Set up your coding agents for Cavelon and log in, in one guided step.",
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" +
416
+ description: "Finds Claude Code, Codex, Cursor, VS Code with GitHub Copilot, Gemini CLI, Kiro, OpenCode, Pi, Qwen, Cline, Kilo, Goose and OMP, shows what it will change for each, asks once\n" +
404
417
  "and does it: Claude Code and Codex get the Cavelon plugin through their own plugin command, Gemini CLI the extension of this\n" +
405
418
  "release (or the files, when the release has none); the others get the `cavelon` MCP server in their user MCP configuration\n" +
406
419
  "and the skills in their user skills folder. It touches nothing else in those files and\n" +
@@ -418,7 +431,7 @@ export const setup = {
418
431
  type: "string",
419
432
  value: "<list>",
420
433
  multiple: true,
421
- description: "Only these agents: claude, codex, cursor, copilot, gemini, kiro, or all (comma-separated). Default: every agent found.",
434
+ description: "Only these agents: claude, codex, cursor, copilot, gemini, kiro, opencode, pi, qwen, cline, kilo, or all (comma-separated). Default: every agent found.",
422
435
  },
423
436
  yes: { type: "boolean", short: "y", description: "Make the changes without asking." },
424
437
  check: { type: "boolean", description: "Report what is set up and working; change nothing." },
@@ -1,9 +1,11 @@
1
1
  import { createHash } from "node:crypto";
2
+ import { PERSON_WAIT_MS } from "./approval-policy.js";
2
3
  import { actingTarget, targetLine } from "./acting.js";
3
4
  import { drivenByAgent } from "./agent-env.js";
4
5
  import { CavelonError, ExitCode } from "./errors.js";
5
6
  import { canonical } from "./package-files.js";
6
7
  import { personCommand, PREVIEW_TOKEN } from "./printed.js";
8
+ export { PERSON_WAIT_MS } from "./approval-policy.js";
7
9
  export const CONFIRM_TOKEN = /^[0-9a-f]{12}$/;
8
10
  export function confirmToken(target, tool, change) {
9
11
  return createHash("sha256")
@@ -105,7 +107,6 @@ async function gateOf(ctx, input, tool, change, options) {
105
107
  export function personRoute(ctx, driven) {
106
108
  return driven.by === "mcp" && ctx.askPerson ? "client" : "terminal";
107
109
  }
108
- export const PERSON_WAIT_MS = 10 * 60_000;
109
110
  export async function personApproves(ctx, driven, change, target = {}) {
110
111
  if (personRoute(ctx, driven) === "terminal")
111
112
  throw needsPerson(change.command);
@@ -0,0 +1,46 @@
1
+ import { CavelonError } from "./errors.js";
2
+ import { table } from "./format.js";
3
+ const KEYS = {
4
+ connections: "database_connections_per_tenant",
5
+ queries: "database_queries_per_tenant",
6
+ };
7
+ function validLimit(value) {
8
+ if (!value || typeof value !== "object")
9
+ return false;
10
+ const item = value;
11
+ return Number.isInteger(item.limit) && item.limit >= 1 &&
12
+ Number.isInteger(item.current) && item.current >= 0 &&
13
+ Number.isInteger(item.platform_limit) && item.platform_limit >= 1 &&
14
+ (item.source === "platform" || item.source === "tenant");
15
+ }
16
+ export function databaseLimitRows(limits, keys) {
17
+ if (!limits || typeof limits !== "object")
18
+ return [];
19
+ const published = limits;
20
+ return Object.keys(KEYS).flatMap(name => {
21
+ const value = published[name];
22
+ const key = KEYS[name];
23
+ return validLimit(value) && (!keys || keys.includes(key)) ? [{ key, ...value }] : [];
24
+ });
25
+ }
26
+ export function databaseLimitsText(rows) {
27
+ return `Database limits and current counts:\n${table(rows.map(row => ({ ...row })), ["key", "current", "limit", "source", "platform_limit"])}`;
28
+ }
29
+ export async function readDatabaseLimits(ctx, keys) {
30
+ if (!keys.some(key => Object.values(KEYS).includes(key)))
31
+ return [];
32
+ try {
33
+ const response = await (await ctx.client()).get("/api/v1/database-connectors/instance", { allow: [403, 404] });
34
+ if (response.status !== 200) {
35
+ ctx.warn(`Database counts are unavailable (${response.status}); the published limits still stand.`);
36
+ return [];
37
+ }
38
+ return databaseLimitRows(response.data?.limits, keys);
39
+ }
40
+ catch (error) {
41
+ if (!(error instanceof CavelonError))
42
+ throw error;
43
+ ctx.warn("Database counts could not be read; the published limits still stand.");
44
+ return [];
45
+ }
46
+ }
package/dist/fsutil.js CHANGED
@@ -1,6 +1,7 @@
1
1
  import { promises as fs } from "node:fs";
2
2
  import path from "node:path";
3
3
  import { randomBytes } from "node:crypto";
4
+ import { setTimeout as delay } from "node:timers/promises";
4
5
  export async function readJsonFile(file) {
5
6
  try {
6
7
  return JSON.parse(await fs.readFile(file, "utf8"));
@@ -29,17 +30,33 @@ export function withoutBom(text) {
29
30
  export async function writeFileAtomic(file, content, mode = 0o644, dirMode = 0o755) {
30
31
  await fs.mkdir(path.dirname(file), { recursive: true, mode: dirMode });
31
32
  const tmp = `${file}.${randomBytes(6).toString("hex")}.tmp`;
32
- const handle = await fs.open(tmp, "w", mode);
33
33
  try {
34
- await handle.writeFile(content, "utf8");
34
+ const handle = await fs.open(tmp, "w", mode);
35
+ try {
36
+ await handle.writeFile(content, "utf8");
37
+ }
38
+ finally {
39
+ await handle.close();
40
+ }
41
+ const existing = await fs.stat(file).then((st) => st.mode & 0o777, () => undefined);
42
+ if (existing !== undefined)
43
+ await fs.chmod(tmp, existing & mode).catch(() => undefined);
44
+ for (let attempt = 0;; attempt++) {
45
+ try {
46
+ await fs.rename(tmp, file);
47
+ break;
48
+ }
49
+ catch (error) {
50
+ const code = error.code;
51
+ if (process.platform !== "win32" || attempt >= 5 || !["EPERM", "EACCES", "EBUSY"].includes(code ?? ""))
52
+ throw error;
53
+ await delay(10 * 2 ** attempt);
54
+ }
55
+ }
35
56
  }
36
57
  finally {
37
- await handle.close();
58
+ await fs.rm(tmp, { force: true }).catch(() => undefined);
38
59
  }
39
- const existing = await fs.stat(file).then((st) => st.mode & 0o777, () => undefined);
40
- if (existing !== undefined)
41
- await fs.chmod(tmp, existing & mode).catch(() => undefined);
42
- await fs.rename(tmp, file);
43
60
  }
44
61
  export async function writePrivateFile(base, file, content) {
45
62
  await writeFileAtomic(file, content, 0o600, 0o700);