@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
@@ -7,6 +7,11 @@ import { isGenerated, removeBlock, removeJsonEntry, upsertBlock, upsertJsonEntry
7
7
  import { cacheDir, homeDir } from "./paths.js";
8
8
  import { runProgram } from "./run-program.js";
9
9
  import { KIT_VERSION } from "./version.js";
10
+ import { NATIVE_CLIENTS, nativeClient, hasNativeApprovalAdapter, readNativeMcp, resolveNativeMcp } from "./native-clients.js";
11
+ import { decodeMcpEntry, encodeMcpEntry, isKitMcpEntry } from "./mcp-entry.js";
12
+ import { removeJsoncEntry, upsertJsoncEntry } from "./jsonc-config.js";
13
+ import { removeYamlEntry, upsertYamlEntry } from "./yaml-config.js";
14
+ import { applyNativeInstallation, checkNativeInstallation, planNativeInstallation, removeNativeInstallation } from "./native-install.js";
10
15
  export const MARKETPLACE_SOURCE = "goodguys-gmbh/cavelon-dev-kit";
11
16
  export const MARKETPLACE = "cavelon-dev-kit";
12
17
  export const PLUGIN_ID = "cavelon@cavelon-dev-kit";
@@ -82,12 +87,13 @@ export function setupAgents(env, platform = process.platform) {
82
87
  mcp: json(path.join(home, ".kiro", "settings", "mcp.json")),
83
88
  skills: path.join(home, ".kiro", "skills"),
84
89
  },
90
+ ...NATIVE_CLIENTS.map(client => ({ name: client.name, label: client.label, commands: client.commands, ...client.user(env, platform), notes: client.notes })),
85
91
  ];
86
92
  }
87
93
  const ALIASES = { "claude-code": "claude", vscode: "copilot", "vs-code": "copilot", "gemini-cli": "gemini", "cursor-agent": "cursor" };
88
94
  export function agentByName(agents, raw) {
89
95
  const name = raw.trim().toLowerCase();
90
- return agents.find((a) => a.name === (ALIASES[name] ?? name));
96
+ return agents.find((a) => a.name === (ALIASES[name] ?? nativeClient(name)?.name ?? name));
91
97
  }
92
98
  const WINDOWS_EXTENSIONS = [".exe", ".cmd", ".bat"];
93
99
  export async function findAgent(agent, env, platform = process.platform) {
@@ -202,7 +208,7 @@ function pluginCommands(kind) {
202
208
  uninstall: kind === "claude" ? ["plugin", "uninstall", PLUGIN_ID, "--scope", "user"] : ["plugin", "remove", PLUGIN_ID],
203
209
  };
204
210
  }
205
- export async function planAgent(agent, found, env, command, skills, platform = process.platform) {
211
+ export async function planAgent(agent, found, env, command, skills, platform = process.platform, record) {
206
212
  const usePlugin = Boolean(agent.plugin && found.program);
207
213
  const state = usePlugin ? await pluginState(agent.plugin, found.program, env) : undefined;
208
214
  const plan = { agent, found, method: usePlugin ? "plugin" : "files", changes: [] };
@@ -226,7 +232,12 @@ export async function planAgent(agent, found, env, command, skills, platform = p
226
232
  ...(state.installed && !state.enabled ? { reason: `it is installed but turned off; turn it on in ${agent.label}` } : {}),
227
233
  });
228
234
  }
229
- if (!usePlugin || platform === "win32")
235
+ if (agent.mcp.format === "native" && hasNativeApprovalAdapter(agent.mcp)) {
236
+ plan.native = await planNativeInstallation(agent.mcp, command, env, { directory: record?.native?.directory, mcpRecord: record?.mcp });
237
+ plan.changes.push({ kind: "native", summary: "install the Cavelon native tools and person dialogs in", target: plan.native.directory,
238
+ outcome: plan.native.outcome, ...(plan.native.reason ? { reason: plan.native.reason } : {}) });
239
+ }
240
+ else if (!usePlugin || platform === "win32")
230
241
  plan.changes.push(await mcpChange(agent.mcp, command, false));
231
242
  if (!usePlugin)
232
243
  plan.changes.push(await skillsChange(agent.skills, skills, false));
@@ -234,6 +245,22 @@ export async function planAgent(agent, found, env, command, skills, platform = p
234
245
  }
235
246
  async function mcpChange(mcp, command, apply, state) {
236
247
  const summary = 'add the "cavelon" tools server to';
248
+ if (mcp.format === "native") {
249
+ const selected = await resolveNativeMcp(mcp);
250
+ if ("error" in selected)
251
+ return { kind: "mcp", summary, target: selected.file, outcome: "skipped", reason: `${selected.error}; the Cavelon entry is "${mcp.keys.join(".")}": ${JSON.stringify(encodeMcpEntry(command, mcp.entryFormat, mcp.extra))}` };
252
+ const upsert = mcp.syntax === "yaml" ? upsertYamlEntry : upsertJsoncEntry;
253
+ const result = upsert(selected.text, mcp.keys, encodeMcpEntry(command, mcp.entryFormat, mcp.extra), { matches: value => isKitMcpEntry(value, mcp.entryFormat, mcp.extra) });
254
+ if (result.outcome === "skipped" || result.outcome === "unchanged")
255
+ return { kind: "mcp", summary, target: selected.file, outcome: result.outcome, ...(result.reason ? { reason: result.reason } : {}) };
256
+ if (!apply)
257
+ return { kind: "mcp", summary, target: selected.file, outcome: "planned" };
258
+ const createdDir = await topmostMissing(path.dirname(selected.file));
259
+ await writeKeepingMode(selected.file, result.content);
260
+ if (state && !state.mcp)
261
+ state.mcp = { file: selected.file, created: selected.text === undefined, kept: selected.kept, ...(createdDir ? { created_dir: createdDir } : {}) };
262
+ return { kind: "mcp", summary, target: selected.file, outcome: "done" };
263
+ }
237
264
  const existing = await readTextFile(mcp.file);
238
265
  let result;
239
266
  if (mcp.format === "json") {
@@ -330,6 +357,8 @@ export async function applyPlan(plan, env, command, skills, record) {
330
357
  const done = [];
331
358
  for (const change of plan.changes) {
332
359
  if (change.outcome !== "planned") {
360
+ if (change.kind === "native" && change.outcome === "unchanged")
361
+ record.native = { directory: plan.native.directory };
333
362
  done.push(change);
334
363
  continue;
335
364
  }
@@ -358,6 +387,12 @@ export async function applyPlan(plan, env, command, skills, record) {
358
387
  if (kind === "gemini" && change.kind === "plugin")
359
388
  done.push(...(await removeFiles(plan.agent, record, skills, new Set())));
360
389
  }
390
+ else if (change.kind === "native") {
391
+ await applyNativeInstallation(plan.native);
392
+ record.native = { directory: plan.native.directory };
393
+ delete record.mcp;
394
+ done.push({ ...change, outcome: "done" });
395
+ }
361
396
  else if (change.kind === "mcp") {
362
397
  done.push(await mcpChange(plan.agent.mcp, command, true, record));
363
398
  }
@@ -402,6 +437,15 @@ export async function removeAgent(agent, record, env, skills, sharedSkillDirs) {
402
437
  }
403
438
  async function removeFiles(agent, record, skills, sharedSkillDirs) {
404
439
  const changes = [];
440
+ if (record.native) {
441
+ const result = await removeNativeInstallation(record.native.directory);
442
+ changes.push({ kind: "native", summary: "remove the recorded Cavelon native integration from", target: record.native.directory,
443
+ outcome: result.removed ? "removed" : "skipped", ...(result.reason ? { reason: result.reason } : {}) });
444
+ if (result.removed)
445
+ delete record.native;
446
+ else
447
+ return changes;
448
+ }
405
449
  if (record.mcp) {
406
450
  const change = await removeMcp(agent.mcp, record.mcp);
407
451
  if (change.outcome !== "failed" && change.outcome !== "skipped")
@@ -416,13 +460,21 @@ async function removeFiles(agent, record, skills, sharedSkillDirs) {
416
460
  return changes;
417
461
  }
418
462
  async function removeMcp(mcp, record) {
463
+ mcp = { ...mcp, file: record.file };
419
464
  const summary = 'remove the "cavelon" tools server from';
420
465
  const existing = await readTextFile(mcp.file);
421
466
  if (existing === undefined)
422
467
  return { kind: "mcp", summary, target: mcp.file, outcome: "unchanged" };
423
- const result = mcp.format === "json"
424
- ? removeJsonEntry(existing, mcp.keys, (value) => isOwnJsonEntry(mcp, value), record.kept ?? mcp.keys.length - 1)
425
- : removeBlock(existing, "hash");
468
+ let result;
469
+ if (mcp.format === "native") {
470
+ const remove = mcp.syntax === "yaml" ? removeYamlEntry : removeJsoncEntry;
471
+ result = remove(existing, mcp.keys, value => isKitMcpEntry(value, mcp.entryFormat, mcp.extra), record.kept ?? mcp.keys.length - 1);
472
+ }
473
+ else if (mcp.format === "json") {
474
+ result = removeJsonEntry(existing, mcp.keys, value => isOwnJsonEntry(mcp, value), record.kept ?? mcp.keys.length - 1);
475
+ }
476
+ else
477
+ result = removeBlock(existing, "hash");
426
478
  if (result.outcome === "unchanged")
427
479
  return { kind: "mcp", summary, target: mcp.file, outcome: "unchanged" };
428
480
  if (result.outcome === "skipped")
@@ -488,6 +540,7 @@ async function topmostMissing(dir) {
488
540
  export async function checkAgent(agent, env, record, platform = process.platform) {
489
541
  const found = await findAgent(agent, env, platform);
490
542
  const check = { name: agent.name, label: agent.label, found: Boolean(found.program || found.folder), method: null, ok: true, details: [], servers: [] };
543
+ check.details.push(...(agent.notes ?? []));
491
544
  const state = agent.plugin && found.program ? await pluginState(agent.plugin, found.program, env) : undefined;
492
545
  const viaFiles = !state || (agent.plugin === "gemini" && ("error" in state || !state.installed));
493
546
  const what = agent.plugin === "gemini" ? "extension" : "plugin";
@@ -516,9 +569,15 @@ export async function checkAgent(agent, env, record, platform = process.platform
516
569
  else {
517
570
  check.method = "files";
518
571
  }
519
- const entry = await readEntry(agent.mcp);
572
+ const nativeDirectory = record?.native?.directory ?? (agent.mcp.format === "native" && hasNativeApprovalAdapter(agent.mcp) ? path.join(path.dirname(agent.skills), "cavelon") : undefined);
573
+ const native = nativeDirectory && (record?.native || await readTextFile(path.join(nativeDirectory, "installation.json"))) ? await checkNativeInstallation(nativeDirectory) : undefined;
574
+ if (record?.native && agent.mcp.format === "native" && record.native.directory !== path.join(path.dirname(agent.skills), "cavelon")) {
575
+ check.ok = false;
576
+ check.details.push("The native config directory override changed; remove the recorded integration before setting up the new location.");
577
+ }
578
+ const entry = native ? { server: native.command, problem: native.reason, file: nativeDirectory } : await readEntry(agent.mcp);
520
579
  if (entry.server) {
521
- check.details.push(`the "cavelon" tools server is in ${agent.mcp.file}`);
580
+ check.details.push(native ? `the Cavelon native tools and person-dialog files are in ${nativeDirectory}; actual UI loading must be checked in the client` : `the "cavelon" tools server is in ${entry.file ?? agent.mcp.file}`);
522
581
  check.servers.push(entry.server);
523
582
  }
524
583
  else {
@@ -544,6 +603,21 @@ export async function checkAgent(agent, env, record, platform = process.platform
544
603
  return check;
545
604
  }
546
605
  async function readEntry(mcp) {
606
+ if (mcp.format === "native") {
607
+ const selected = await resolveNativeMcp(mcp);
608
+ if ("error" in selected)
609
+ return { problem: `${selected.file}: ${selected.error}` };
610
+ const entry = readNativeMcp(selected.text, mcp);
611
+ if ("error" in entry)
612
+ return { problem: `${selected.file}: ${entry.error}` };
613
+ const value = entry.value;
614
+ if (value?.enabled === false || value?.disabled === true)
615
+ return { problem: `the Cavelon server in ${selected.file} is disabled` };
616
+ if (mcp.client === "goose" && value && (value.type !== "stdio" || value.name !== "cavelon" || value.enabled !== true))
617
+ return { problem: `the Cavelon extension in ${selected.file} is not an enabled stdio binding` };
618
+ const server = decodeMcpEntry(value, mcp.entryFormat);
619
+ return server ? { server, file: selected.file } : { problem: `${selected.file} has no readable "cavelon" tools server` };
620
+ }
547
621
  const text = await readTextFile(mcp.file);
548
622
  if (text === undefined)
549
623
  return { problem: `${mcp.file} does not exist` };
@@ -13,6 +13,13 @@ use it when you parse the result.
13
13
 
14
14
  ## Before anything
15
15
 
16
+ - **Select the local solution folder.** In a repository with several solutions,
17
+ pass `solution_dir`, such as `solutions/review`, on MCP calls. It resolves
18
+ inside the server's startup workspace and selects that folder's
19
+ `cavelon.yaml`, `env/`, package, tests and saved previews. Use the same folder
20
+ for preview, confirmation and follow-up calls; `harness` selects the solution
21
+ on the instance and does not locate its files. Without `solution_dir`, tools
22
+ keep using the startup folder. From a shell, run in the solution folder.
16
23
  - `cavelon status` says which instance, tenant and solution this folder is
17
24
  bound to, the solution's state (draft, active, or inactive after a
18
25
  deactivate; whether it is ready to
@@ -0,0 +1,215 @@
1
+ import { isDeepStrictEqual } from "node:util";
2
+ import { isAlias, isMap, isNode, isPair, isScalar, parseDocument, visit } from "yaml";
3
+ function document(text) {
4
+ const doc = parseDocument(text, { keepSourceTokens: true, uniqueKeys: true });
5
+ if (doc.errors.length || doc.warnings.length)
6
+ return { error: "it has a YAML syntax error or unsupported tag" };
7
+ if (doc.contents !== null && !isMap(doc.contents))
8
+ return { error: "it is not a YAML mapping" };
9
+ let ambiguous = false;
10
+ visit(doc, (_key, node) => {
11
+ if (isAlias(node) || (isNode(node) && (node.anchor || node.tag)))
12
+ ambiguous = true;
13
+ if (isPair(node) && (!isScalar(node.key) || typeof node.key.value !== "string" || node.key.value === "<<"))
14
+ ambiguous = true;
15
+ });
16
+ if (ambiguous)
17
+ return { error: "YAML aliases, anchors, tags, merge keys or complex keys require manual configuration" };
18
+ return { doc };
19
+ }
20
+ function validPath(keys) {
21
+ return keys.length > 0 && keys.every(key => key.length > 0 && !["__proto__", "constructor", "prototype"].includes(key));
22
+ }
23
+ export function readYamlEntry(text, keys) {
24
+ if (!validPath(keys))
25
+ return { error: "the configuration entry path is invalid" };
26
+ if (text === undefined)
27
+ return { value: undefined, kept: 0 };
28
+ const parsed = document(text);
29
+ if ("error" in parsed)
30
+ return parsed;
31
+ if (parsed.doc.contents === null)
32
+ return { value: undefined, kept: 0 };
33
+ let map = parsed.doc.contents;
34
+ let kept = 0;
35
+ for (const key of keys) {
36
+ if (!isMap(map))
37
+ return { error: `its "${keys.slice(0, kept).join(".")}" is not a mapping` };
38
+ if (!map.has(key))
39
+ return { value: undefined, kept };
40
+ const node = map.get(key, true);
41
+ kept++;
42
+ if (kept === keys.length)
43
+ return { value: isNode(node) ? node.toJSON() : node, kept };
44
+ map = node;
45
+ }
46
+ return { value: undefined, kept };
47
+ }
48
+ function hasComments(node) {
49
+ let found = false;
50
+ visit(node, (_key, child) => {
51
+ if (isNode(child) && (child.comment || child.commentBefore))
52
+ found = true;
53
+ });
54
+ return found;
55
+ }
56
+ function editRange(text, start, end, content) {
57
+ const updated = text.slice(0, start) + content + text.slice(end);
58
+ const checked = document(updated);
59
+ if ("error" in checked)
60
+ return { outcome: "skipped", reason: "this YAML cannot be edited safely; configure it manually" };
61
+ const before = document(text);
62
+ if ("error" in before)
63
+ return { outcome: "skipped", reason: before.error };
64
+ const comments = (doc) => {
65
+ const found = [];
66
+ for (const value of [doc.comment, doc.commentBefore])
67
+ if (typeof value === "string")
68
+ found.push(value);
69
+ visit(doc, (_key, node) => { if (isNode(node))
70
+ for (const value of [node.comment, node.commentBefore])
71
+ if (typeof value === "string")
72
+ found.push(value); });
73
+ return found.sort((left, right) => left.localeCompare(right));
74
+ };
75
+ if (!isDeepStrictEqual(comments(before.doc), comments(checked.doc)))
76
+ return { outcome: "skipped", reason: "changing this entry would remove a personal comment; edit it manually" };
77
+ return { outcome: "updated", content: updated };
78
+ }
79
+ function suffix(text, start, end) {
80
+ if (!text.slice(start, end).endsWith("\n"))
81
+ return "";
82
+ return text.includes("\r\n") ? "\r\n" : "\n";
83
+ }
84
+ function lineStart(text, offset) {
85
+ const start = text.lastIndexOf("\n", offset - 1) + 1;
86
+ return text.slice(start, offset).trim() ? offset : start;
87
+ }
88
+ function nestedValue(keys, value) {
89
+ let nested = value;
90
+ for (let index = keys.length - 1; index >= 0; index--)
91
+ nested = { [keys[index]]: nested };
92
+ return nested;
93
+ }
94
+ function appendValue(existing, parent, keys, depth, value) {
95
+ if (!parent.range)
96
+ return { outcome: "skipped", reason: "this YAML mapping cannot be edited safely" };
97
+ const property = `${JSON.stringify(keys[depth])}: ${JSON.stringify(nestedValue(keys.slice(depth + 1), value))}`;
98
+ let result;
99
+ if (parent.flow) {
100
+ const end = existing.lastIndexOf("}", parent.range[1] - 1);
101
+ result = editRange(existing, end, end, `${parent.items.length ? ", " : ""}${property}`);
102
+ }
103
+ else {
104
+ const firstKey = parent.items[0]?.key;
105
+ const offset = isNode(firstKey) && firstKey.range ? firstKey.range[0] : parent.range[0];
106
+ const indent = " ".repeat(offset - lineStart(existing, offset));
107
+ const end = parent.range[1];
108
+ const newline = existing.includes("\r\n") ? "\r\n" : "\n";
109
+ const leading = end && !existing.slice(0, end).endsWith("\n") ? newline : "";
110
+ result = editRange(existing, end, end, `${leading}${indent}${property}${newline}`);
111
+ }
112
+ return result.outcome === "updated" ? { ...result, outcome: "appended" } : result;
113
+ }
114
+ function updateValue(existing, node, value) {
115
+ if (!isNode(node) || !node.range || hasComments(node))
116
+ return { outcome: "skipped", reason: "changing this entry would remove a personal comment; edit it manually" };
117
+ return editRange(existing, node.range[0], node.range[1], JSON.stringify(value) + suffix(existing, node.range[0], node.range[1]));
118
+ }
119
+ function appendToEmpty(existing, keys, value) {
120
+ const newline = existing.includes("\r\n") ? "\r\n" : "\n";
121
+ const leading = existing && !existing.endsWith("\n") ? newline : "";
122
+ const result = editRange(existing, existing.length, existing.length, `${leading}${JSON.stringify(keys[0])}: ${JSON.stringify(nestedValue(keys.slice(1), value))}${newline}`);
123
+ return result.outcome === "updated" ? { ...result, outcome: "appended" } : result;
124
+ }
125
+ export function upsertYamlEntry(existing, keys, value, options = {}) {
126
+ const current = readYamlEntry(existing, keys);
127
+ if ("error" in current)
128
+ return { outcome: "skipped", reason: current.error };
129
+ if (isDeepStrictEqual(current.value, value))
130
+ return { outcome: "unchanged" };
131
+ if (current.value === undefined && options.onlyExisting)
132
+ return { outcome: "skipped", reason: "it has no Cavelon entry" };
133
+ if (current.value !== undefined && !options.matches?.(current.value))
134
+ return { outcome: "skipped", reason: `its "${keys.join(".")}" is a personal or conflicting entry` };
135
+ if (existing === undefined)
136
+ return { outcome: "created", content: JSON.stringify(nestedValue(keys, value), null, 2) + "\n" };
137
+ const parsed = document(existing);
138
+ if ("error" in parsed)
139
+ return { outcome: "skipped", reason: parsed.error };
140
+ if (parsed.doc.contents === null)
141
+ return appendToEmpty(existing, keys, value);
142
+ if (current.value !== undefined)
143
+ return updateValue(existing, parsed.doc.getIn(keys, true), value);
144
+ const parent = current.kept ? parsed.doc.getIn(keys.slice(0, current.kept), true) : parsed.doc.contents;
145
+ if (!isMap(parent))
146
+ return { outcome: "skipped", reason: "this YAML mapping cannot be edited safely" };
147
+ return appendValue(existing, parent, keys, current.kept, value);
148
+ }
149
+ function removalParent(doc, keys, keep) {
150
+ let removing = keys;
151
+ let parent = doc.getIn(removing.slice(0, -1), true);
152
+ while (isMap(parent) && parent.items.length === 1 && removing.length - 1 > keep && !hasComments(parent)) {
153
+ removing = removing.slice(0, -1);
154
+ parent = doc.getIn(removing.slice(0, -1), true);
155
+ }
156
+ return { removing, parent };
157
+ }
158
+ function pairRanges(pair) {
159
+ if (!pair || !isNode(pair.key) || !pair.key.range || !isNode(pair.value) || !pair.value.range || pair.key.comment || hasComments(pair.value))
160
+ return undefined;
161
+ return { key: pair.key.range, value: pair.value.range };
162
+ }
163
+ function removeFlowPair(existing, parent, index, ranges) {
164
+ let start = ranges.key[0];
165
+ let end = ranges.value[1];
166
+ if (index < parent.items.length - 1) {
167
+ const comma = existing.indexOf(",", end);
168
+ if (comma < 0 || comma >= parent.range[1])
169
+ return { outcome: "skipped", reason: "this YAML separator cannot be edited safely" };
170
+ end = comma + 1;
171
+ }
172
+ else {
173
+ start = existing.lastIndexOf(",", start);
174
+ if (start < parent.range[0])
175
+ return { outcome: "skipped", reason: "this YAML separator cannot be edited safely" };
176
+ }
177
+ return editRange(existing, start, end, "");
178
+ }
179
+ function removePair(existing, parent, key) {
180
+ if (!parent.range)
181
+ return { outcome: "skipped", reason: "this YAML mapping cannot be edited safely" };
182
+ const index = parent.items.findIndex(pair => isScalar(pair.key) && pair.key.value === key);
183
+ const ranges = pairRanges(parent.items[index]);
184
+ if (!ranges)
185
+ return { outcome: "skipped", reason: "removing this entry would remove a personal comment; edit it manually" };
186
+ if (parent.items.length === 1)
187
+ return editRange(existing, parent.range[0], parent.range[1], "{}" + suffix(existing, parent.range[0], parent.range[1]));
188
+ if (parent.flow)
189
+ return removeFlowPair(existing, parent, index, ranges);
190
+ return editRange(existing, lineStart(existing, ranges.key[0]), ranges.value[2], "");
191
+ }
192
+ function emptyDocument(text) {
193
+ const final = document(text);
194
+ if ("error" in final)
195
+ return false;
196
+ const doc = final.doc;
197
+ return isMap(doc.contents) && !doc.contents.items.length && !hasComments(doc.contents) && !doc.comment && !doc.commentBefore;
198
+ }
199
+ export function removeYamlEntry(existing, keys, matches, keep = 0) {
200
+ const current = readYamlEntry(existing, keys);
201
+ if ("error" in current)
202
+ return { outcome: "skipped", reason: current.error };
203
+ if (current.value === undefined || existing === undefined)
204
+ return { outcome: "unchanged" };
205
+ if (!matches(current.value))
206
+ return { outcome: "skipped", reason: `its "${keys.join(".")}" was changed since cavelon wrote it` };
207
+ const parsed = document(existing);
208
+ if ("error" in parsed)
209
+ return { outcome: "skipped", reason: parsed.error };
210
+ const { removing, parent } = removalParent(parsed.doc, keys, keep);
211
+ if (!isMap(parent))
212
+ return { outcome: "skipped", reason: "this YAML mapping cannot be edited safely" };
213
+ const result = removePair(existing, parent, removing.at(-1));
214
+ return result.outcome === "updated" ? { ...result, empty: emptyDocument(result.content) } : result;
215
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cavelon/cli",
3
- "version": "0.1.15",
3
+ "version": "0.1.17",
4
4
  "description": "The cavelon binary: CLI and local MCP server for building Cavelon solutions with a coding agent.",
5
5
  "license": "Apache-2.0",
6
6
  "homepage": "https://github.com/goodguys-gmbh/cavelon-dev-kit",
@@ -22,7 +22,7 @@
22
22
  "node": ">=20.3"
23
23
  },
24
24
  "scripts": {
25
- "build": "tsc -p tsconfig.build.json && node scripts/copy-skills.mjs",
25
+ "build": "tsc -p tsconfig.build.json && node scripts/copy-skills.mjs && node scripts/build-native-assets.mjs",
26
26
  "typecheck": "tsc -p tsconfig.json --noEmit",
27
27
  "lint": "eslint .",
28
28
  "test": "vitest run",
@@ -35,6 +35,7 @@
35
35
  "@modelcontextprotocol/sdk": "^1.31.0",
36
36
  "ajv": "^8.20.0",
37
37
  "ajv-formats": "^3.0.1",
38
+ "jsonc-parser": "3.3.1",
38
39
  "yaml": "^2.9.1"
39
40
  },
40
41
  "optionalDependencies": {
@@ -43,9 +44,12 @@
43
44
  "devDependencies": {
44
45
  "@eslint/js": "^10.0.1",
45
46
  "@types/node": "^20.19.0",
47
+ "esbuild": "0.28.2",
46
48
  "eslint": "^10.12.0",
49
+ "typebox": "1.3.27",
47
50
  "typescript": "~6.0.3",
48
51
  "typescript-eslint": "^8.71.0",
49
- "vitest": "^4.0.0"
52
+ "vitest": "^4.0.0",
53
+ "zod": "4.6.5"
50
54
  }
51
55
  }