@cavelon/cli 0.1.16 → 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.
@@ -1,7 +1,11 @@
1
+ import { ompConfig, ompDirectory, ompPolicy } from "./omp-config.js";
1
2
  import path from "node:path";
3
+ import os from "node:os";
4
+ import { promises as fs } from "node:fs";
2
5
  import { parseTree } from "jsonc-parser";
3
6
  import { readTextFile } from "./fsutil.js";
4
7
  import { readJsoncEntry } from "./jsonc-config.js";
8
+ import { readYamlEntry } from "./yaml-config.js";
5
9
  import { isKitMcpEntry } from "./mcp-entry.js";
6
10
  import { homeDir } from "./paths.js";
7
11
  const openCodeConfig = (file, files, blocked) => ({
@@ -12,6 +16,63 @@ const piConfig = (file) => ({
12
16
  client: "pi", format: "native", file, files: [file], syntax: "json", keys: ["mcpServers", "cavelon"], entryFormat: "command-args", extra: {},
13
17
  });
14
18
  const piDir = (env) => env.PI_CODING_AGENT_DIR || path.join(homeDir(env), ".pi", "agent");
19
+ function gooseConfigDir(env, platform) {
20
+ if (env.GOOSE_PATH_ROOT && path.isAbsolute(env.GOOSE_PATH_ROOT))
21
+ return path.join(env.GOOSE_PATH_ROOT, "config");
22
+ const home = homeDir(env);
23
+ if (platform === "win32")
24
+ return path.join(env.APPDATA || path.join(home, "AppData", "Roaming"), "Block", "goose", "config");
25
+ const xdg = env.XDG_CONFIG_HOME;
26
+ return path.join(xdg && path.isAbsolute(xdg) ? xdg : path.join(home, ".config"), "goose");
27
+ }
28
+ function gooseAdditionalPaths(value, platform) {
29
+ if (value === undefined)
30
+ return [];
31
+ const paths = [];
32
+ let segment = "";
33
+ let quoted = false;
34
+ const separator = platform === "win32" ? ";" : ":";
35
+ for (const char of value) {
36
+ if (platform === "win32" && char === '"')
37
+ quoted = !quoted;
38
+ else if (char === separator && !quoted) {
39
+ paths.push(segment);
40
+ segment = "";
41
+ }
42
+ else
43
+ segment += char;
44
+ }
45
+ paths.push(segment);
46
+ return paths;
47
+ }
48
+ function gooseUser(env, platform = process.platform) {
49
+ const dir = gooseConfigDir(env, platform);
50
+ const system = platform === "win32" ? path.join(env.PROGRAMDATA || String.raw `C:\ProgramData`, "goose", "config.yaml") : "/etc/goose/config.yaml";
51
+ const additional = gooseAdditionalPaths(env.GOOSE_ADDITIONAL_CONFIG_FILES, platform);
52
+ const file = path.join(dir, "config.yaml");
53
+ let blocked;
54
+ if (additional.some(file => !file))
55
+ blocked = "GOOSE_ADDITIONAL_CONFIG_FILES contains an empty path; review it before setup";
56
+ else if (env.GOOSE_ALLOWLIST)
57
+ blocked = "Goose's extension allowlist is active; ask the operator to review Cavelon's binding in that policy";
58
+ return {
59
+ mcp: { client: "goose", format: "native", file, files: [file], syntax: "yaml", keys: ["extensions", "cavelon"], entryFormat: "goose-stdio",
60
+ extra: { type: "stdio", name: "cavelon", enabled: true }, managedFiles: [...new Set([system, ...additional])], ...(blocked ? { blocked } : {}) },
61
+ skills: path.join(dir, "skills"), folders: [dir],
62
+ };
63
+ }
64
+ function clineUser(env) {
65
+ const candidate = env.HOME?.trim();
66
+ const profile = env.USERPROFILE?.trim() || (env.HOMEDRIVE?.trim() && env.HOMEPATH?.trim() ? `${env.HOMEDRIVE.trim()}${env.HOMEPATH.trim()}` : undefined);
67
+ const home = homeDir({ HOME: candidate && candidate !== "~" ? candidate : undefined, USERPROFILE: profile });
68
+ const dir = env.CLINE_DIR?.trim() || path.join(home, ".cline");
69
+ const data = env.CLINE_DATA_DIR?.trim() || path.join(dir, "data");
70
+ const file = env.CLINE_MCP_SETTINGS_PATH?.trim() || path.join(data, "settings", "cline_mcp_settings.json");
71
+ return {
72
+ mcp: { client: "cline", format: "native", file, files: [file], syntax: "json", keys: ["mcpServers", "cavelon"], entryFormat: "command-args", extra: { type: "stdio" } },
73
+ skills: path.join(dir, "skills"), folders: [...new Set([dir, data])],
74
+ };
75
+ }
15
76
  function qwenDir(env) {
16
77
  const raw = env.QWEN_HOME;
17
78
  if (!raw)
@@ -30,13 +91,80 @@ const qwenConfig = (file, env, platform = process.platform) => ({
30
91
  entryFormat: "command-args", extra: {}, managedFiles: qwenManagedFiles(env, platform),
31
92
  });
32
93
  export function hasNativeApprovalAdapter(config) {
33
- return config.client === "opencode" || config.client === "pi";
94
+ return config.client === "opencode" || config.client === "pi" || config.client === "kilo" || config.client === "omp";
95
+ }
96
+ const kiloNames = ["kilo.json", "kilo.jsonc", "opencode.json", "opencode.jsonc"];
97
+ const kiloFiles = (dir) => kiloNames.map(name => path.join(dir, name));
98
+ const kiloCompatibility = (files) => files.filter(file => ["opencode.json", "opencode.jsonc"].includes(path.basename(file)));
99
+ async function kiloAncestorFiles(root) {
100
+ const files = [];
101
+ let dir = path.resolve(root);
102
+ while (path.dirname(dir) !== dir && !await fs.stat(path.join(dir, ".git")).then(() => true, () => false)) {
103
+ dir = path.dirname(dir);
104
+ files.push(...kiloFiles(dir), ...kiloFiles(path.join(dir, ".kilocode")), ...kiloFiles(path.join(dir, ".kilo")));
105
+ }
106
+ return files;
107
+ }
108
+ function kiloUser(env) {
109
+ const home = (env.KILO_TEST_HOME ?? homeDir(env)).trim();
110
+ const xdg = env.XDG_CONFIG_HOME && path.isAbsolute(env.XDG_CONFIG_HOME) ? env.XDG_CONFIG_HOME : path.join(homeDir(env), ".config");
111
+ const global = path.join(xdg.replace(/[\r\n]/g, ""), "kilo");
112
+ const dir = env.KILO_CONFIG_DIR || global;
113
+ const files = [...new Set([path.join(global, "config.json"), ...kiloFiles(global), ...(env.KILO_CONFIG ? [env.KILO_CONFIG] : []),
114
+ ...kiloFiles(path.join(home, ".kilocode")), ...kiloFiles(path.join(home, ".kilo")), ...(dir !== global ? kiloFiles(dir) : [])])];
115
+ return { dir, global, files, compatibilityFiles: kiloCompatibility(files) };
116
+ }
117
+ function kiloConfig(file, files, env, platform, blocked) {
118
+ const managed = env.KILO_TEST_MANAGED_CONFIG_DIR || (platform === "darwin" ? "/Library/Application Support/kilo"
119
+ : platform === "win32" ? path.join(env.ProgramData || "C:\\ProgramData", "kilo") : "/etc/kilo");
120
+ return {
121
+ client: "kilo", format: "native", file, files, syntax: "jsonc", keys: ["mcp", "cavelon"], entryFormat: "command-array", extra: { type: "local" },
122
+ compatibilityFiles: kiloCompatibility(files), managedFiles: kiloFiles(managed),
123
+ managedOpaqueFiles: platform === "darwin" ? [path.join("/Library/Managed Preferences", os.userInfo().username, "ai.opencode.managed.plist"),
124
+ "/Library/Managed Preferences/ai.opencode.managed.plist"] : [],
125
+ ...(blocked ? { blocked } : env.KILO_CONFIG_CONTENT ? { blocked: "KILO_CONFIG_CONTENT overrides file settings; configure Cavelon in that managed configuration" } : {}),
126
+ };
34
127
  }
35
128
  function openCodeUserFiles(env) {
36
129
  const dir = path.join(env.XDG_CONFIG_HOME || path.join(homeDir(env), ".config"), "opencode");
37
130
  return [path.join(dir, "config.json"), path.join(dir, "opencode.json"), path.join(dir, "opencode.jsonc"), ...(env.OPENCODE_CONFIG ? [env.OPENCODE_CONFIG] : [])];
38
131
  }
39
132
  export const NATIVE_CLIENTS = [
133
+ {
134
+ name: "omp", label: "OMP (Oh My Pi)", aliases: ["oh-my-pi", "ohmypi"], commands: ["omp"], projectSkills: [".omp/skills"],
135
+ project: (env = {}) => ompConfig(env, true),
136
+ user: env => {
137
+ const { directory } = ompDirectory(env);
138
+ return { mcp: ompConfig(env), skills: path.join(directory, "skills"), folders: [directory] };
139
+ },
140
+ notes: [
141
+ "OMP is a separate client from Pi. Setup follows OMP_PROFILE / PI_PROFILE, PI_CONFIG_DIR and its default PI_CODING_AGENT_DIR override; use the same profile environment when launching OMP.",
142
+ "Setup installs an owned native autoload extension without rewriting YAML or legacy settings. It disables only the duplicate Cavelon MCP entry and preserves compatible client bindings and deny/force-enable policies.",
143
+ "The native TUI asks the person afresh for each guarded change. Print/RPC modes return an exact command for the person's own terminal. Launch OMP with CAVELON_AGENT=1; file checks cannot qualify actual UI loading or custom extension policies.",
144
+ ],
145
+ },
146
+ {
147
+ name: "goose", label: "Goose", aliases: ["goose-cli"], commands: ["goose"], projectSkills: [],
148
+ project: () => undefined, user: gooseUser,
149
+ notes: [
150
+ "Goose uses user YAML extension settings and native skills; project init copies .agents/skills only. Run cavelon setup --agents goose for the MCP entry. System and additional config layers are inspected without overriding their Cavelon binding. Keep GOOSE_PATH_ROOT, XDG_CONFIG_HOME and GOOSE_ADDITIONAL_CONFIG_FILES the same for setup and the client.",
151
+ "Goose CLI's interactive MCP form can ask the person for the exact change; headless clients must refuse or return the person's terminal route. Automatic tool permissions cannot answer that form. Launch Goose with CAVELON_AGENT=1 to guard shells in modes that do not set a session marker. Actual UI qualification is separate from setup checks.",
152
+ ],
153
+ },
154
+ {
155
+ name: "kilo", label: "Kilo CLI / current VS Code extension", aliases: ["kilocode", "kilo-code"], commands: ["kilo", "kilocode"], projectSkills: [".kilo/skills"],
156
+ project: (env = {}) => ({ ...kiloConfig("kilo.json", [...kiloFiles("."), ...kiloFiles(".kilocode"), ...kiloFiles(".kilo")], env, process.platform, env.KILO_DISABLE_PROJECT_CONFIG === "true" || env.KILO_DISABLE_PROJECT_CONFIG === "1" ? "Kilo project configuration is disabled" :
157
+ env.KILO_CONFIG_DIR ? "KILO_CONFIG_DIR may override project settings; use user setup for that directory" : undefined), shadowFiles: kiloUser(env).files }),
158
+ user: (env, platform = process.platform) => {
159
+ const { dir, global, files } = kiloUser(env);
160
+ return { mcp: kiloConfig(env.KILO_CONFIG || path.join(dir, "kilo.json"), files, env, platform), skills: path.join(dir, "skills"), folders: [...new Set([global, dir])] };
161
+ },
162
+ notes: [
163
+ "Kilo CLI and current VS Code extension 7.8.8 use Kilo's own MCP settings and skills. Compatible OpenCode files are inspected and preserved; setup does not migrate another client's binding.",
164
+ "Setup installs separate Kilo server/TUI plugins and disables only the duplicate Cavelon MCP entry. CLI TUI approval requires a fresh person dialog; the editor and headless modes return a command for the person's own terminal.",
165
+ "Start Kilo with CAVELON_AGENT=1 scoped to its process, including a fresh VS Code process for the editor. A separate person's terminal must not inherit that marker. Check effective cloud/organization policies in Kilo; file checks cannot certify remote settings or actual UI loading.",
166
+ ],
167
+ },
40
168
  {
41
169
  name: "opencode", label: "OpenCode", aliases: ["opencode-ai"], commands: ["opencode"], projectSkills: [],
42
170
  project: (env = {}) => ({ ...openCodeConfig("opencode.json", ["opencode.json", "opencode.jsonc", ".opencode/opencode.json", ".opencode/opencode.jsonc"], env.OPENCODE_CONFIG_CONTENT ? "OPENCODE_CONFIG_CONTENT overrides file settings; configure Cavelon in that managed configuration" :
@@ -80,9 +208,21 @@ export const NATIVE_CLIENTS = [
80
208
  "This client does not advertise MCP form elicitation. Guarded changes return a preview and a command for the person's own terminal; tool permission approval and automatic modes cannot confirm the Cavelon change.",
81
209
  ],
82
210
  },
211
+ {
212
+ name: "cline", label: "Cline CLI / current VS Code extension", aliases: ["cline-cli", "cline-vscode"], commands: ["cline"], projectSkills: [".cline/skills"],
213
+ project: () => undefined,
214
+ user: clineUser,
215
+ notes: [
216
+ "Cline CLI 3.0.70 and VS Code extension 4.1.23 use shared user MCP settings; project init copies native skills only. Run cavelon setup --agents cline for the MCP entry. Older editor profiles and other surfaces require separate verification.",
217
+ "Set the same absolute CLINE_DIR, CLINE_DATA_DIR and CLINE_MCP_SETTINGS_PATH overrides for setup and the CLI. Mirror CLI --config / --data-dir in setup's environment. The editor's compatibility UI retains legacy path handling: use default shared paths and check its settings and skills independently. Setup does not migrate older editor profiles.",
218
+ "This client's MCP transport does not advertise form elicitation. Guarded changes return an exact command for the person's own terminal; automatic tool approval cannot confirm the change. Launch the coding client with CAVELON_AGENT=1 so its shell commands keep the kit's person-only guards.",
219
+ ],
220
+ },
83
221
  ];
84
222
  export const nativeClient = (name) => NATIVE_CLIENTS.find(client => client.name === name || client.aliases.includes(name));
85
223
  export function readNativeMcp(text, config) {
224
+ if (config.syntax === "yaml")
225
+ return readYamlEntry(text, config.keys);
86
226
  if (text !== undefined && config.syntax === "json") {
87
227
  try {
88
228
  JSON.parse(text);
@@ -145,10 +285,84 @@ async function qwenPolicy(config, full) {
145
285
  }
146
286
  return undefined;
147
287
  }
288
+ function gooseExtensionName(key, value) {
289
+ const name = value && typeof value === "object" && !Array.isArray(value) ? value.name : undefined;
290
+ const equivalent = (name) => name.replace(/\s/g, "").toLowerCase() === "cavelon";
291
+ const cavelon = equivalent(key) || (typeof name === "string" && equivalent(name));
292
+ return { cavelon, conflicting: key !== "cavelon" || (name !== undefined && name !== "cavelon") };
293
+ }
294
+ function gooseExtensionsPolicy(value, managed, file) {
295
+ if (value === undefined)
296
+ return undefined;
297
+ if (!value || typeof value !== "object" || Array.isArray(value))
298
+ return `the extensions in ${file} are not a mapping; review them manually`;
299
+ for (const [key, entry] of Object.entries(value)) {
300
+ const name = gooseExtensionName(key, entry);
301
+ if (!name.cavelon)
302
+ continue;
303
+ if (managed)
304
+ return `a system or additional Cavelon extension in ${file} is preserved; review its binding with the operator`;
305
+ if (name.conflicting)
306
+ return `another Cavelon extension name in ${file} would conflict; review that binding manually`;
307
+ }
308
+ return undefined;
309
+ }
310
+ async function goosePolicy(config, full) {
311
+ for (const candidate of new Set([...(config.managedFiles ?? []), ...config.files])) {
312
+ const file = full(candidate);
313
+ const text = await readTextFile(file);
314
+ if (text === undefined)
315
+ continue;
316
+ const extensions = readYamlEntry(text, ["extensions"]);
317
+ if ("error" in extensions)
318
+ return `${file}: ${extensions.error}`;
319
+ const error = gooseExtensionsPolicy(extensions.value, config.managedFiles?.includes(candidate) ?? false, file);
320
+ if (error)
321
+ return error;
322
+ const allowlist = readYamlEntry(text, ["GOOSE_ALLOWLIST"]);
323
+ if ("error" in allowlist)
324
+ return `${file}: ${allowlist.error}`;
325
+ if (allowlist.value)
326
+ return `Goose's extension allowlist in ${file} requires operator review before Cavelon setup`;
327
+ }
328
+ return undefined;
329
+ }
148
330
  export async function resolveNativeMcp(config, root) {
149
331
  const full = (file) => root ? path.resolve(root, file) : path.resolve(file);
150
332
  if (config.blocked)
151
333
  return { file: full(config.file), error: config.blocked };
334
+ if (config.client === "omp") {
335
+ const error = await ompPolicy(config, full);
336
+ if (error)
337
+ return { file: full(config.file), error };
338
+ }
339
+ if (config.client === "goose") {
340
+ const error = await goosePolicy(config, full);
341
+ if (error)
342
+ return { file: full(config.file), error };
343
+ }
344
+ if (config.client === "kilo") {
345
+ for (const file of config.managedOpaqueFiles ?? []) {
346
+ if (await readTextFile(file) !== undefined)
347
+ return { file: full(config.file), error: `managed preferences in ${file} may override Cavelon; review the binding with the operator` };
348
+ }
349
+ for (const candidate of [...(config.managedFiles ?? []), ...(config.compatibilityFiles ?? [])]) {
350
+ const file = full(candidate);
351
+ const selected = readNativeMcp(await readTextFile(file), config);
352
+ if ("error" in selected)
353
+ return { file, error: selected.error };
354
+ if (selected.value !== undefined)
355
+ return { file, error: `a managed or OpenCode-compatible Cavelon server in ${file} is preserved; review its binding before Kilo setup` };
356
+ }
357
+ if (root)
358
+ for (const file of await kiloAncestorFiles(root)) {
359
+ const selected = readNativeMcp(await readTextFile(file), config);
360
+ if ("error" in selected)
361
+ return { file, error: selected.error };
362
+ if (selected.value !== undefined)
363
+ return { file, error: `an inherited Cavelon server in ${file} would be shadowed; review its binding before project setup` };
364
+ }
365
+ }
152
366
  if (config.client === "qwen") {
153
367
  const error = await qwenPolicy(config, full);
154
368
  if (error)
@@ -164,6 +378,8 @@ export async function resolveNativeMcp(config, root) {
164
378
  }
165
379
  const found = [];
166
380
  for (const candidate of config.files) {
381
+ if (config.compatibilityFiles?.includes(candidate))
382
+ continue;
167
383
  const file = full(candidate);
168
384
  const text = await readTextFile(file);
169
385
  if (text === undefined)
@@ -52,12 +52,12 @@ async function readInstallation(directory) {
52
52
  catch {
53
53
  throw new Error("Invalid native ownership record; inspect the installation before repeating setup.");
54
54
  }
55
- if (record.format !== 1 || !["opencode", "pi"].includes(record.client) || !["user", "project"].includes(record.scope)
55
+ if (record.format !== 1 || !["opencode", "pi", "kilo", "omp"].includes(record.client) || !["user", "project"].includes(record.scope)
56
56
  || typeof record.version !== "string" || !record.files || typeof record.files !== "object" || Array.isArray(record.files)
57
57
  || !record.mcp || typeof record.mcp.file !== "string" || !/^[a-f0-9]{64}$/.test(record.mcp.hash)
58
58
  || typeof record.mcp.created !== "boolean" || !Number.isInteger(record.mcp.kept) || record.mcp.kept < 0 || record.mcp.kept > 1
59
59
  || !Array.isArray(record.references) || !record.references.length
60
- || record.references.some(ref => !ref || typeof ref.file !== "string" || !["plugin", "extensions"].includes(ref.key) || typeof ref.member !== "string"
60
+ || record.references.some(ref => !ref || typeof ref.file !== "string" || !["plugin", "extensions", "autoload"].includes(ref.key) || typeof ref.member !== "string"
61
61
  || typeof ref.created !== "boolean" || typeof ref.kept !== "boolean")
62
62
  || (record.scope === "project" && record.projectRoot !== "../..")) {
63
63
  throw new Error("Invalid native ownership record; inspect the installation before repeating setup.");
@@ -112,6 +112,11 @@ async function verify(directory, record) {
112
112
  for (const ref of record.references) {
113
113
  const file = fileOf(directory, ref.file);
114
114
  await safeFile(file, root);
115
+ if (ref.key === "autoload") {
116
+ if (await readTextFile(file) !== ref.member)
117
+ throw new Error("The native autoload entry was edited; personal changes are preserved.");
118
+ continue;
119
+ }
115
120
  const entry = readJsoncEntry(await readTextFile(file), [ref.key]);
116
121
  if ("error" in entry || !Array.isArray(entry.value) || entry.value.filter(member => isDeepStrictEqual(member, ref.member)).length !== 1
117
122
  || await referenceCount(file, entry.value, ref.member) !== 1) {
@@ -127,27 +132,32 @@ async function chooseFile(files, fallback) {
127
132
  return present.at(-1) ?? fallback;
128
133
  }
129
134
  async function references(client, directory, mcpFile, env, root) {
135
+ if (client === "omp")
136
+ return [{ file: path.join(path.dirname(directory), "extensions", "cavelon.js"), key: "autoload", member: 'export { default } from "../cavelon/omp-extension.mjs";\n' }];
130
137
  if (client === "pi")
131
138
  return [{ file: path.join(path.dirname(directory), "settings.json"), key: "extensions", member: memberPath(path.join(path.dirname(directory), "settings.json"), path.join(directory, "pi-extension.mjs")) }];
132
- const global = path.dirname(nativeClient(client).user({ ...env, OPENCODE_CONFIG_DIR: undefined }).skills);
133
- const configDir = env.OPENCODE_CONFIG_DIR;
134
- const files = root ? [path.join(root, "tui.json"), path.join(root, "tui.jsonc"), path.join(root, ".opencode", "tui.json"), path.join(root, ".opencode", "tui.jsonc")] :
135
- [path.join(global, "tui.json"), path.join(global, "tui.jsonc"), ...(env.OPENCODE_TUI_CONFIG ? [env.OPENCODE_TUI_CONFIG] : []),
139
+ const prefix = client.toUpperCase();
140
+ const global = path.dirname(nativeClient(client).user({ ...env, [`${prefix}_CONFIG_DIR`]: undefined }).skills);
141
+ const configDir = env[`${prefix}_CONFIG_DIR`];
142
+ const tuiConfig = env[`${prefix}_TUI_CONFIG`];
143
+ const projectDirs = client === "kilo" ? [".kilocode", ".kilo"] : [".opencode"];
144
+ const files = root ? [path.join(root, "tui.json"), path.join(root, "tui.jsonc"), ...projectDirs.flatMap(dir => [path.join(root, dir, "tui.json"), path.join(root, dir, "tui.jsonc")])] :
145
+ [path.join(global, "tui.json"), path.join(global, "tui.jsonc"), ...(tuiConfig ? [tuiConfig] : []),
136
146
  ...(configDir ? [path.join(configDir, "tui.json"), path.join(configDir, "tui.jsonc")] : [])];
137
- if (root && env.OPENCODE_TUI_CONFIG)
138
- throw new Error("OPENCODE_TUI_CONFIG overrides project UI settings; use user setup for that configuration.");
139
- const fallback = !root && configDir ? path.join(configDir, "tui.json") : !root && env.OPENCODE_TUI_CONFIG ? env.OPENCODE_TUI_CONFIG : path.join(root ?? global, "tui.json");
147
+ if (root && tuiConfig)
148
+ throw new Error(`${prefix}_TUI_CONFIG overrides project UI settings; use user setup for that configuration.`);
149
+ const fallback = !root && configDir ? path.join(configDir, "tui.json") : !root && tuiConfig ? tuiConfig : path.join(root ?? global, "tui.json");
140
150
  const tuiFile = await chooseFile(files, fallback);
141
151
  return [
142
- { file: mcpFile, key: "plugin", member: memberPath(mcpFile, path.join(directory, "opencode-server-entry.mjs")) },
143
- { file: tuiFile, key: "plugin", member: memberPath(tuiFile, path.join(directory, "opencode-tui-entry.mjs")) },
152
+ { file: mcpFile, key: "plugin", member: memberPath(mcpFile, path.join(directory, `${client}-server-entry.mjs`)) },
153
+ { file: tuiFile, key: "plugin", member: memberPath(tuiFile, path.join(directory, `${client}-tui-entry.mjs`)) },
144
154
  ];
145
155
  }
146
156
  export async function planNativeInstallation(config, command, env, options = {}) {
147
157
  if (!hasNativeApprovalAdapter(config))
148
158
  throw new Error("This client has no native person-dialog adapter.");
149
159
  const root = options.root;
150
- const expectedDirectory = root ? path.join(root, config.client === "pi" ? ".pi" : ".opencode", "cavelon") : path.join(path.dirname(nativeClient(config.client).user(env).skills), "cavelon");
160
+ const expectedDirectory = root ? path.join(root, `.${config.client}`, "cavelon") : path.join(path.dirname(nativeClient(config.client).user(env).skills), "cavelon");
151
161
  const directory = options.directory ?? expectedDirectory;
152
162
  const skipped = (reason) => ({ directory, outcome: "skipped", reason, writes: [] });
153
163
  try {
@@ -188,9 +198,9 @@ export async function planNativeInstallation(config, command, env, options = {})
188
198
  client: config.client, version: KIT_VERSION, scope: root ? "project" : "user", configFile: root ? portable(directory, selected.file) : selected.file, entryHash: nativeEntryHash(disabled) };
189
199
  const contents = new Map(assets.map(asset => [asset.path, asset.content]));
190
200
  contents.set("profile.json", json(profile));
191
- if (config.client === "opencode")
201
+ if (config.client !== "pi" && config.client !== "omp")
192
202
  for (const surface of ["server", "tui"]) {
193
- contents.set(`opencode-${surface}-entry.mjs`, `import adapter from "./opencode-${surface}.mjs";\nexport default { ...adapter, id: "cavelon.native-approval.${root ? "project" : "user"}" };\n`);
203
+ contents.set(`${config.client}-${surface}-entry.mjs`, `import adapter from "./${config.client}-${surface}.mjs";\nexport default { ...adapter, id: "cavelon.native-approval.${config.client === "kilo" ? "kilo." : ""}${root ? "project" : "user"}" };\n`);
194
204
  }
195
205
  const writes = new Map();
196
206
  const replace = async (file, after) => {
@@ -206,6 +216,13 @@ export async function planNativeInstallation(config, command, env, options = {})
206
216
  const refs = [];
207
217
  for (const ref of await references(config.client, directory, selected.file, env, root)) {
208
218
  const before = writes.get(ref.file)?.after ?? await readTextFile(ref.file);
219
+ if (ref.key === "autoload") {
220
+ if (before !== undefined && !previous)
221
+ return skipped("The native autoload entry belongs to a personal extension; it is preserved.");
222
+ await replace(ref.file, ref.member);
223
+ refs.push({ file: root ? portable(directory, ref.file) : ref.file, key: ref.key, member: ref.member, created: true, kept: false });
224
+ continue;
225
+ }
209
226
  if (config.client === "pi" && before !== undefined) {
210
227
  try {
211
228
  JSON.parse(before);
@@ -214,7 +231,8 @@ export async function planNativeInstallation(config, command, env, options = {})
214
231
  return skipped("Pi settings require plain JSON; correct the file before native installation.");
215
232
  }
216
233
  }
217
- for (const id of ["cavelon.native-approval", `cavelon.native-approval.${root ? "project" : "user"}`]) {
234
+ for (const id of ["cavelon.native-approval", `cavelon.native-approval.${root ? "project" : "user"}`,
235
+ ...(config.client === "kilo" ? ["cavelon.native-approval.kilo", `cavelon.native-approval.kilo.${root ? "project" : "user"}`] : [])]) {
218
236
  const enabled = readJsoncEntry(before, ["plugin_enabled", id]);
219
237
  if ("error" in enabled)
220
238
  return skipped(enabled.error);
@@ -308,8 +326,11 @@ export async function checkNativeInstallation(directory) {
308
326
  throw new Error("No recorded native installation exists.");
309
327
  await verify(directory, record);
310
328
  for (const ref of record.references) {
329
+ if (ref.key === "autoload")
330
+ continue;
311
331
  const text = await readTextFile(fileOf(directory, ref.file));
312
- for (const id of ["cavelon.native-approval", `cavelon.native-approval.${record.scope}`]) {
332
+ for (const id of ["cavelon.native-approval", `cavelon.native-approval.${record.scope}`,
333
+ ...(record.client === "kilo" ? ["cavelon.native-approval.kilo", `cavelon.native-approval.kilo.${record.scope}`] : [])]) {
313
334
  const enabled = readJsoncEntry(text, ["plugin_enabled", id]);
314
335
  if ("error" in enabled)
315
336
  throw new Error(enabled.error);
@@ -341,6 +362,10 @@ export async function removeNativeInstallation(directory) {
341
362
  for (const ref of record.references) {
342
363
  const file = fileOf(directory, ref.file);
343
364
  const before = writes.get(file)?.after ?? await readTextFile(file);
365
+ if (ref.key === "autoload") {
366
+ await replace(file, undefined);
367
+ continue;
368
+ }
344
369
  const removed = removeJsoncMember(before, [ref.key], ref.member, { removeEmpty: !ref.kept });
345
370
  if (removed.outcome === "skipped")
346
371
  throw new Error(removed.reason);
@@ -0,0 +1,85 @@
1
+ import path from "node:path";
2
+ import { homeDir } from "./paths.js";
3
+ import { readTextFile } from "./fsutil.js";
4
+ import { readJsoncEntry } from "./jsonc-config.js";
5
+ export function ompDirectory(env) {
6
+ const home = homeDir(env);
7
+ const root = path.join(home, env.PI_CONFIG_DIR || ".omp");
8
+ const profile = (env.OMP_PROFILE !== undefined ? env.OMP_PROFILE : env.PI_PROFILE)?.trim();
9
+ if (profile && profile !== "default") {
10
+ if (!/^[a-z0-9][a-z0-9._-]{0,63}$/.test(profile) || profile === ".." || profile.endsWith(".") || /^(?:con|prn|aux|nul|com[0-9]|lpt[0-9])(?:\..*)?$/i.test(profile)) {
11
+ return { directory: path.join(root, "agent"), blocked: "Invalid OMP profile; select a valid profile before setup." };
12
+ }
13
+ return { directory: path.join(root, "profiles", profile, "agent") };
14
+ }
15
+ return { directory: env.PI_CODING_AGENT_DIR ? path.resolve(env.PI_CODING_AGENT_DIR) : path.join(root, "agent") };
16
+ }
17
+ const nativeFiles = (directory) => [path.join(directory, "mcp.json"), path.join(directory, ".mcp.json")];
18
+ const compatibleFiles = (directory) => [
19
+ ".claude.json", ".mcp.json", "mcp.json", ".claude/.mcp.json", ".cursor/mcp.json", ".vscode/mcp.json",
20
+ ".gemini/settings.json", ".qwen/settings.json", ".opencode/opencode.json", ".opencode/opencode.jsonc",
21
+ "opencode.json", "opencode.jsonc", ".codex/config.toml",
22
+ ].map(file => path.join(directory, file));
23
+ export function ompConfig(env, project = false) {
24
+ const user = ompDirectory(env);
25
+ const directory = project ? ".omp" : user.directory;
26
+ return {
27
+ client: "omp", format: "native", file: path.join(directory, "mcp.json"), files: nativeFiles(directory),
28
+ syntax: "json", keys: ["mcpServers", "cavelon"], entryFormat: "command-args", extra: {},
29
+ compatibilityFiles: compatibleFiles(project ? "." : homeDir(env)),
30
+ ...(project ? { shadowFiles: nativeFiles(user.directory), managedFiles: [path.join(user.directory, "mcp.json")] } : {}),
31
+ ...(user.blocked ? { blocked: user.blocked } : {}),
32
+ };
33
+ }
34
+ export function ompListPolicy(text) {
35
+ for (const key of ["disabledServers", "enabledServers"]) {
36
+ const selected = readJsoncEntry(text, [key]);
37
+ if ("error" in selected)
38
+ return selected.error;
39
+ if (selected.value === undefined)
40
+ continue;
41
+ if (!Array.isArray(selected.value) || !selected.value.every(value => typeof value === "string"))
42
+ return `The OMP ${key} policy is invalid; review it manually.`;
43
+ if (selected.value.includes("cavelon"))
44
+ return `The OMP ${key} policy names Cavelon; review it in OMP before native setup.`;
45
+ }
46
+ return undefined;
47
+ }
48
+ export async function ompRuntimePolicy(configFile, env) {
49
+ const files = new Set([...nativeFiles(path.dirname(configFile)), path.join(ompDirectory(env).directory, "mcp.json")]);
50
+ for (const file of files) {
51
+ const error = ompListPolicy(await readTextFile(file));
52
+ if (error)
53
+ return `${file}: ${error}`;
54
+ }
55
+ return undefined;
56
+ }
57
+ export async function ompPolicy(config, full) {
58
+ for (const file of new Set([...(config.managedFiles ?? []), ...config.files.map(full)])) {
59
+ const error = ompListPolicy(await readTextFile(file));
60
+ if (error)
61
+ return `${file}: ${error}`;
62
+ }
63
+ for (const candidate of config.compatibilityFiles ?? []) {
64
+ const file = full(candidate);
65
+ const error = compatiblePolicy(await readTextFile(file), file);
66
+ if (error)
67
+ return error;
68
+ }
69
+ return undefined;
70
+ }
71
+ function compatiblePolicy(text, file) {
72
+ if (text === undefined)
73
+ return undefined;
74
+ if (file.endsWith(".toml")) {
75
+ return /cavelon/i.test(text) ? `A compatible Cavelon binding may exist in ${file}; inspect its TOML before OMP setup.` : undefined;
76
+ }
77
+ for (const key of ["mcpServers", "mcp", "servers"]) {
78
+ const selected = readJsoncEntry(text, [key, "cavelon"]);
79
+ if ("error" in selected)
80
+ return `${file}: ${selected.error}`;
81
+ if (selected.value !== undefined)
82
+ return `A compatible Cavelon server in ${file} is preserved; review that binding before OMP setup.`;
83
+ }
84
+ return undefined;
85
+ }
@@ -10,6 +10,7 @@ import { KIT_VERSION } from "./version.js";
10
10
  import { NATIVE_CLIENTS, nativeClient, hasNativeApprovalAdapter, readNativeMcp, resolveNativeMcp } from "./native-clients.js";
11
11
  import { decodeMcpEntry, encodeMcpEntry, isKitMcpEntry } from "./mcp-entry.js";
12
12
  import { removeJsoncEntry, upsertJsoncEntry } from "./jsonc-config.js";
13
+ import { removeYamlEntry, upsertYamlEntry } from "./yaml-config.js";
13
14
  import { applyNativeInstallation, checkNativeInstallation, planNativeInstallation, removeNativeInstallation } from "./native-install.js";
14
15
  export const MARKETPLACE_SOURCE = "goodguys-gmbh/cavelon-dev-kit";
15
16
  export const MARKETPLACE = "cavelon-dev-kit";
@@ -248,7 +249,8 @@ async function mcpChange(mcp, command, apply, state) {
248
249
  const selected = await resolveNativeMcp(mcp);
249
250
  if ("error" in selected)
250
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))}` };
251
- const result = upsertJsoncEntry(selected.text, mcp.keys, encodeMcpEntry(command, mcp.entryFormat, mcp.extra), { matches: value => isKitMcpEntry(value, 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) });
252
254
  if (result.outcome === "skipped" || result.outcome === "unchanged")
253
255
  return { kind: "mcp", summary, target: selected.file, outcome: result.outcome, ...(result.reason ? { reason: result.reason } : {}) };
254
256
  if (!apply)
@@ -463,11 +465,16 @@ async function removeMcp(mcp, record) {
463
465
  const existing = await readTextFile(mcp.file);
464
466
  if (existing === undefined)
465
467
  return { kind: "mcp", summary, target: mcp.file, outcome: "unchanged" };
466
- const result = mcp.format === "native"
467
- ? removeJsoncEntry(existing, mcp.keys, value => isKitMcpEntry(value, mcp.entryFormat, mcp.extra), record.kept ?? mcp.keys.length - 1)
468
- : mcp.format === "json"
469
- ? removeJsonEntry(existing, mcp.keys, (value) => isOwnJsonEntry(mcp, value), record.kept ?? mcp.keys.length - 1)
470
- : 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");
471
478
  if (result.outcome === "unchanged")
472
479
  return { kind: "mcp", summary, target: mcp.file, outcome: "unchanged" };
473
480
  if (result.outcome === "skipped")
@@ -606,6 +613,8 @@ async function readEntry(mcp) {
606
613
  const value = entry.value;
607
614
  if (value?.enabled === false || value?.disabled === true)
608
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` };
609
618
  const server = decodeMcpEntry(value, mcp.entryFormat);
610
619
  return server ? { server, file: selected.file } : { problem: `${selected.file} has no readable "cavelon" tools server` };
611
620
  }