@cavelon/cli 0.1.1 → 0.1.3
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.
- package/README.md +50 -20
- package/dist/agents.js +43 -19
- package/dist/choose.js +112 -0
- package/dist/command.js +1 -1
- package/dist/commands/api.js +76 -6
- package/dist/commands/index.js +2 -0
- package/dist/commands/init.js +196 -29
- package/dist/commands/limits-set.js +17 -8
- package/dist/commands/limits.js +2 -2
- package/dist/commands/loops.js +12 -6
- package/dist/commands/sandboxes.js +27 -20
- package/dist/commands/session.js +179 -45
- package/dist/commands/setup.js +426 -0
- package/dist/commands/solution.js +137 -91
- package/dist/commands/tenants.js +33 -22
- package/dist/commands/values.js +8 -5
- package/dist/commands/work.js +33 -16
- package/dist/context.js +5 -1
- package/dist/contracts.js +83 -38
- package/dist/embedded.js +7 -0
- package/dist/features.js +15 -0
- package/dist/fsutil.js +3 -0
- package/dist/git.js +14 -9
- package/dist/harness-ref.js +54 -0
- package/dist/http.js +44 -18
- package/dist/install.js +94 -0
- package/dist/invoke.js +17 -13
- package/dist/limits.js +9 -1
- package/dist/local-state.js +18 -0
- package/dist/main.js +31 -2
- package/dist/markers.js +53 -0
- package/dist/mcp.js +9 -2
- package/dist/openapi.js +10 -0
- package/dist/operations.js +1 -1
- package/dist/package-check.js +1 -1
- package/dist/package-files.js +103 -38
- package/dist/paths.js +53 -4
- package/dist/principal.js +43 -0
- package/dist/project.js +23 -4
- package/dist/prompt.js +55 -11
- package/dist/results.js +47 -9
- package/dist/run-program.js +92 -0
- package/dist/session.js +100 -19
- package/dist/setup-agents.js +544 -0
- package/dist/skills/cavelon-authoring/SKILL.md +13 -3
- package/dist/skills/cavelon-long-running/SKILL.md +5 -1
- package/dist/skills/cavelon-loop/SKILL.md +15 -9
- package/dist/skills/cavelon-testing/SKILL.md +9 -2
- package/dist/tenant-choice.js +93 -0
- package/dist/update-check.js +118 -0
- package/dist/version.js +2 -1
- package/package.json +5 -2
|
@@ -0,0 +1,544 @@
|
|
|
1
|
+
import { promises as fs } from "node:fs";
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
import { bundledSkills, generatedCopy, INSTALLED_MCP_COMMAND, mcpCommand } from "./agents.js";
|
|
4
|
+
import { readTextFile, writeFileAtomic } from "./fsutil.js";
|
|
5
|
+
import { findProgram } from "./git.js";
|
|
6
|
+
import { isGenerated, removeBlock, removeJsonEntry, upsertBlock, upsertJsonEntry } from "./markers.js";
|
|
7
|
+
import { homeDir } from "./paths.js";
|
|
8
|
+
import { runProgram } from "./run-program.js";
|
|
9
|
+
export const MARKETPLACE_SOURCE = "goodguys-gmbh/cavelon-dev-kit";
|
|
10
|
+
export const MARKETPLACE = "cavelon-dev-kit";
|
|
11
|
+
export const PLUGIN_ID = "cavelon@cavelon-dev-kit";
|
|
12
|
+
function vscodeUserDir(env, platform) {
|
|
13
|
+
const home = homeDir(env);
|
|
14
|
+
if (platform === "win32")
|
|
15
|
+
return path.join(env.APPDATA || path.join(home, "AppData", "Roaming"), "Code", "User");
|
|
16
|
+
if (platform === "darwin")
|
|
17
|
+
return path.join(home, "Library", "Application Support", "Code", "User");
|
|
18
|
+
return path.join(env.XDG_CONFIG_HOME || path.join(home, ".config"), "Code", "User");
|
|
19
|
+
}
|
|
20
|
+
const json = (file, key = "mcpServers", extra = {}) => ({ file, format: "json", keys: [key, "cavelon"], extra });
|
|
21
|
+
export function setupAgents(env, platform = process.platform) {
|
|
22
|
+
const home = homeDir(env);
|
|
23
|
+
const claudeDir = env.CLAUDE_CONFIG_DIR || path.join(home, ".claude");
|
|
24
|
+
const codexDir = env.CODEX_HOME || path.join(home, ".codex");
|
|
25
|
+
const geminiDir = path.join(env.GEMINI_CLI_HOME || home, ".gemini");
|
|
26
|
+
const vscode = vscodeUserDir(env, platform);
|
|
27
|
+
return [
|
|
28
|
+
{
|
|
29
|
+
name: "claude",
|
|
30
|
+
label: "Claude Code",
|
|
31
|
+
commands: ["claude"],
|
|
32
|
+
folders: [claudeDir],
|
|
33
|
+
plugin: "claude",
|
|
34
|
+
mcp: json(env.CLAUDE_CONFIG_DIR ? path.join(env.CLAUDE_CONFIG_DIR, ".claude.json") : path.join(home, ".claude.json")),
|
|
35
|
+
skills: path.join(claudeDir, "skills"),
|
|
36
|
+
},
|
|
37
|
+
{
|
|
38
|
+
name: "codex",
|
|
39
|
+
label: "Codex",
|
|
40
|
+
commands: ["codex"],
|
|
41
|
+
folders: [codexDir],
|
|
42
|
+
plugin: "codex",
|
|
43
|
+
mcp: { file: path.join(codexDir, "config.toml"), format: "toml" },
|
|
44
|
+
skills: path.join(home, ".agents", "skills"),
|
|
45
|
+
},
|
|
46
|
+
{
|
|
47
|
+
name: "cursor",
|
|
48
|
+
label: "Cursor",
|
|
49
|
+
commands: ["cursor", "cursor-agent"],
|
|
50
|
+
folders: [path.join(home, ".cursor")],
|
|
51
|
+
mcp: json(path.join(home, ".cursor", "mcp.json")),
|
|
52
|
+
skills: path.join(home, ".cursor", "skills"),
|
|
53
|
+
},
|
|
54
|
+
{
|
|
55
|
+
name: "copilot",
|
|
56
|
+
label: "VS Code with GitHub Copilot",
|
|
57
|
+
commands: ["code"],
|
|
58
|
+
folders: [vscode],
|
|
59
|
+
mcp: json(path.join(vscode, "mcp.json"), "servers", { type: "stdio" }),
|
|
60
|
+
skills: path.join(home, ".copilot", "skills"),
|
|
61
|
+
},
|
|
62
|
+
{
|
|
63
|
+
name: "gemini",
|
|
64
|
+
label: "Gemini CLI",
|
|
65
|
+
commands: ["gemini"],
|
|
66
|
+
folders: [geminiDir],
|
|
67
|
+
mcp: json(path.join(geminiDir, "settings.json")),
|
|
68
|
+
skills: path.join(geminiDir, "skills"),
|
|
69
|
+
},
|
|
70
|
+
{
|
|
71
|
+
name: "kiro",
|
|
72
|
+
label: "Kiro",
|
|
73
|
+
commands: ["kiro", "kiro-cli"],
|
|
74
|
+
folders: [path.join(home, ".kiro")],
|
|
75
|
+
mcp: json(path.join(home, ".kiro", "settings", "mcp.json")),
|
|
76
|
+
skills: path.join(home, ".kiro", "skills"),
|
|
77
|
+
},
|
|
78
|
+
];
|
|
79
|
+
}
|
|
80
|
+
const ALIASES = { "claude-code": "claude", vscode: "copilot", "vs-code": "copilot", "gemini-cli": "gemini", "cursor-agent": "cursor" };
|
|
81
|
+
export function agentByName(agents, raw) {
|
|
82
|
+
const name = raw.trim().toLowerCase();
|
|
83
|
+
return agents.find((a) => a.name === (ALIASES[name] ?? name));
|
|
84
|
+
}
|
|
85
|
+
const WINDOWS_EXTENSIONS = [".exe", ".cmd", ".bat"];
|
|
86
|
+
export async function findAgent(agent, env, platform = process.platform) {
|
|
87
|
+
const found = {};
|
|
88
|
+
for (const command of agent.commands) {
|
|
89
|
+
found.program = await findProgram(command, env, platform, WINDOWS_EXTENSIONS);
|
|
90
|
+
if (found.program)
|
|
91
|
+
break;
|
|
92
|
+
}
|
|
93
|
+
for (const folder of agent.folders) {
|
|
94
|
+
if (await isDirectory(folder)) {
|
|
95
|
+
found.folder = folder;
|
|
96
|
+
break;
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
return found;
|
|
100
|
+
}
|
|
101
|
+
async function isDirectory(dir) {
|
|
102
|
+
return fs.stat(dir).then((st) => st.isDirectory(), () => false);
|
|
103
|
+
}
|
|
104
|
+
export async function serverCommand(env, platform = process.platform) {
|
|
105
|
+
return (await findProgram("cavelon", env, platform, [".exe"])) ? INSTALLED_MCP_COMMAND : mcpCommand(platform);
|
|
106
|
+
}
|
|
107
|
+
function knownCommands() {
|
|
108
|
+
return [INSTALLED_MCP_COMMAND, mcpCommand("linux"), mcpCommand("win32")];
|
|
109
|
+
}
|
|
110
|
+
function jsonEntry(mcp, command) {
|
|
111
|
+
return { ...mcp.extra, command: command.command, args: command.args };
|
|
112
|
+
}
|
|
113
|
+
function isOwnJsonEntry(mcp, value) {
|
|
114
|
+
return knownCommands().some((c) => JSON.stringify(jsonEntry(mcp, c)) === JSON.stringify(value));
|
|
115
|
+
}
|
|
116
|
+
function tomlBlock(command) {
|
|
117
|
+
return ["[mcp_servers.cavelon]", `command = ${JSON.stringify(command.command)}`, `args = [${command.args.map((a) => JSON.stringify(a)).join(", ")}]`].join("\n");
|
|
118
|
+
}
|
|
119
|
+
function hasOwnTomlServer(text) {
|
|
120
|
+
let inBlock = false;
|
|
121
|
+
for (const line of text.split(/\r?\n/)) {
|
|
122
|
+
const trimmed = line.trim();
|
|
123
|
+
if (trimmed === "# cavelon:begin")
|
|
124
|
+
inBlock = true;
|
|
125
|
+
else if (trimmed === "# cavelon:end")
|
|
126
|
+
inBlock = false;
|
|
127
|
+
else if (!inBlock && /^\[\s*mcp_servers\s*\.\s*"?cavelon"?\s*\]/.test(trimmed))
|
|
128
|
+
return true;
|
|
129
|
+
}
|
|
130
|
+
return false;
|
|
131
|
+
}
|
|
132
|
+
const RUN_TIMEOUT_MS = 180_000;
|
|
133
|
+
const LIST_TIMEOUT_MS = 60_000;
|
|
134
|
+
function display(program, args) {
|
|
135
|
+
return [path.basename(program).replace(/\.(exe|cmd|bat)$/i, ""), ...args].join(" ");
|
|
136
|
+
}
|
|
137
|
+
async function pluginState(kind, program, env) {
|
|
138
|
+
const read = async (args) => {
|
|
139
|
+
const result = await runProgram(program, args, { env, timeoutMs: LIST_TIMEOUT_MS });
|
|
140
|
+
if (result.code !== 0)
|
|
141
|
+
return { error: result.error ?? `\`${display(program, args)}\` failed: ${firstLine(result.stderr || result.stdout)}` };
|
|
142
|
+
try {
|
|
143
|
+
return { value: JSON.parse(result.stdout) };
|
|
144
|
+
}
|
|
145
|
+
catch {
|
|
146
|
+
return { error: `\`${display(program, args)}\` did not answer in JSON` };
|
|
147
|
+
}
|
|
148
|
+
};
|
|
149
|
+
const plugins = await read(["plugin", "list", "--json"]);
|
|
150
|
+
if ("error" in plugins)
|
|
151
|
+
return { error: plugins.error };
|
|
152
|
+
const markets = await read(["plugin", "marketplace", "list", "--json"]);
|
|
153
|
+
if ("error" in markets)
|
|
154
|
+
return { error: markets.error };
|
|
155
|
+
if (kind === "claude") {
|
|
156
|
+
const list = Array.isArray(plugins.value) ? plugins.value : [];
|
|
157
|
+
const mine = list.find((p) => p.id === PLUGIN_ID && p.scope === "user");
|
|
158
|
+
const names = Array.isArray(markets.value) ? markets.value.map((m) => m.name) : [];
|
|
159
|
+
return { marketplace: names.includes(MARKETPLACE), installed: Boolean(mine), enabled: mine?.enabled !== false };
|
|
160
|
+
}
|
|
161
|
+
const installed = (plugins.value?.installed ?? []).find((p) => p.pluginId === PLUGIN_ID && p.installed !== false);
|
|
162
|
+
const names = (markets.value?.marketplaces ?? []).map((m) => m.name);
|
|
163
|
+
return { marketplace: names.includes(MARKETPLACE), installed: Boolean(installed), enabled: installed?.enabled !== false };
|
|
164
|
+
}
|
|
165
|
+
function firstLine(text) {
|
|
166
|
+
return (text.split(/\r?\n/).find((l) => l.trim()) ?? "").trim().slice(0, 300);
|
|
167
|
+
}
|
|
168
|
+
function pluginCommands(kind) {
|
|
169
|
+
return {
|
|
170
|
+
marketplaceAdd: ["plugin", "marketplace", "add", MARKETPLACE_SOURCE],
|
|
171
|
+
marketplaceRemove: ["plugin", "marketplace", "remove", MARKETPLACE],
|
|
172
|
+
install: kind === "claude" ? ["plugin", "install", PLUGIN_ID, "--scope", "user"] : ["plugin", "add", PLUGIN_ID],
|
|
173
|
+
uninstall: kind === "claude" ? ["plugin", "uninstall", PLUGIN_ID, "--scope", "user"] : ["plugin", "remove", PLUGIN_ID],
|
|
174
|
+
};
|
|
175
|
+
}
|
|
176
|
+
export async function planAgent(agent, found, env, command, skills, platform = process.platform) {
|
|
177
|
+
const usePlugin = Boolean(agent.plugin && found.program);
|
|
178
|
+
const plan = { agent, found, method: usePlugin ? "plugin" : "files", changes: [] };
|
|
179
|
+
if (usePlugin) {
|
|
180
|
+
const kind = agent.plugin;
|
|
181
|
+
const program = found.program;
|
|
182
|
+
const commands = pluginCommands(kind);
|
|
183
|
+
const state = await pluginState(kind, program, env);
|
|
184
|
+
if ("error" in state) {
|
|
185
|
+
plan.changes.push({ kind: "plugin", summary: "install the Cavelon plugin", target: display(program, commands.install), outcome: "failed", reason: state.error });
|
|
186
|
+
return plan;
|
|
187
|
+
}
|
|
188
|
+
plan.plugin = state;
|
|
189
|
+
if (!state.marketplace) {
|
|
190
|
+
plan.changes.push({ kind: "marketplace", summary: "add the Cavelon plugin marketplace", target: display(program, commands.marketplaceAdd), outcome: "planned" });
|
|
191
|
+
}
|
|
192
|
+
plan.changes.push({
|
|
193
|
+
kind: "plugin",
|
|
194
|
+
summary: "install the Cavelon plugin (skills and tools)",
|
|
195
|
+
target: display(program, commands.install),
|
|
196
|
+
outcome: state.installed ? "unchanged" : "planned",
|
|
197
|
+
...(state.installed && !state.enabled ? { reason: `it is installed but turned off; turn it on in ${agent.label}` } : {}),
|
|
198
|
+
});
|
|
199
|
+
}
|
|
200
|
+
if (!usePlugin || platform === "win32")
|
|
201
|
+
plan.changes.push(await mcpChange(agent.mcp, command, false));
|
|
202
|
+
if (!usePlugin)
|
|
203
|
+
plan.changes.push(await skillsChange(agent.skills, skills, false));
|
|
204
|
+
return plan;
|
|
205
|
+
}
|
|
206
|
+
async function mcpChange(mcp, command, apply, state) {
|
|
207
|
+
const summary = 'add the "cavelon" tools server to';
|
|
208
|
+
const existing = await readTextFile(mcp.file);
|
|
209
|
+
let result;
|
|
210
|
+
if (mcp.format === "json") {
|
|
211
|
+
let current;
|
|
212
|
+
try {
|
|
213
|
+
current = existing ? mcp.keys.reduce((node, key) => (node && typeof node === "object" ? node[key] : undefined), JSON.parse(existing)) : undefined;
|
|
214
|
+
}
|
|
215
|
+
catch {
|
|
216
|
+
current = undefined;
|
|
217
|
+
}
|
|
218
|
+
if (current !== undefined && !isOwnJsonEntry(mcp, current)) {
|
|
219
|
+
return { kind: "mcp", summary, target: mcp.file, outcome: "skipped", reason: `it already has a "cavelon" server of its own; left as it is` };
|
|
220
|
+
}
|
|
221
|
+
result = upsertJsonEntry(existing, mcp.keys, jsonEntry(mcp, command));
|
|
222
|
+
if (result.outcome === "skipped")
|
|
223
|
+
result.reason = `${result.reason}; add "${mcp.keys.join(".")}": ${JSON.stringify(jsonEntry(mcp, command))} yourself`;
|
|
224
|
+
}
|
|
225
|
+
else {
|
|
226
|
+
if (existing !== undefined && hasOwnTomlServer(existing)) {
|
|
227
|
+
return { kind: "mcp", summary, target: mcp.file, outcome: "skipped", reason: "it already has an [mcp_servers.cavelon] table of its own; left as it is" };
|
|
228
|
+
}
|
|
229
|
+
result = upsertBlock(existing, tomlBlock(command), "hash");
|
|
230
|
+
}
|
|
231
|
+
if (result.outcome === "unchanged")
|
|
232
|
+
return { kind: "mcp", summary, target: mcp.file, outcome: "unchanged" };
|
|
233
|
+
if (result.outcome === "skipped")
|
|
234
|
+
return { kind: "mcp", summary, target: mcp.file, outcome: "skipped", reason: result.reason };
|
|
235
|
+
if (!apply)
|
|
236
|
+
return { kind: "mcp", summary: result.outcome === "updated" ? 'update the "cavelon" tools server in' : summary, target: mcp.file, outcome: "planned" };
|
|
237
|
+
const createdDir = await topmostMissing(path.dirname(mcp.file));
|
|
238
|
+
await writeKeepingMode(mcp.file, result.content);
|
|
239
|
+
if (state && !state.mcp) {
|
|
240
|
+
state.mcp = {
|
|
241
|
+
file: mcp.file,
|
|
242
|
+
created: existing === undefined,
|
|
243
|
+
...(mcp.format === "json" ? { kept: existing ? keptDepth(existing, mcp.keys) : 0 } : {}),
|
|
244
|
+
...(createdDir ? { created_dir: createdDir } : {}),
|
|
245
|
+
};
|
|
246
|
+
}
|
|
247
|
+
return { kind: "mcp", summary, target: mcp.file, outcome: "done" };
|
|
248
|
+
}
|
|
249
|
+
function keptDepth(text, keys) {
|
|
250
|
+
let node;
|
|
251
|
+
try {
|
|
252
|
+
node = JSON.parse(text);
|
|
253
|
+
}
|
|
254
|
+
catch {
|
|
255
|
+
return keys.length;
|
|
256
|
+
}
|
|
257
|
+
let depth = 0;
|
|
258
|
+
for (const key of keys.slice(0, -1)) {
|
|
259
|
+
if (!node || typeof node !== "object" || !(key in node))
|
|
260
|
+
break;
|
|
261
|
+
node = node[key];
|
|
262
|
+
depth++;
|
|
263
|
+
}
|
|
264
|
+
return depth;
|
|
265
|
+
}
|
|
266
|
+
async function writeKeepingMode(file, content) {
|
|
267
|
+
const target = await fs.realpath(file).catch(() => file);
|
|
268
|
+
const mode = await fs.stat(target).then((st) => st.mode & 0o777, () => 0o600);
|
|
269
|
+
await writeFileAtomic(target, content, mode, 0o700);
|
|
270
|
+
}
|
|
271
|
+
async function skillsChange(dir, skills, apply, state) {
|
|
272
|
+
const summary = `copy the ${skills.length} Cavelon skills to`;
|
|
273
|
+
const target = dir + path.sep;
|
|
274
|
+
const createdDir = await topmostMissing(dir);
|
|
275
|
+
let changed = 0;
|
|
276
|
+
const foreign = [];
|
|
277
|
+
for (const skill of skills) {
|
|
278
|
+
for (const file of skill.files) {
|
|
279
|
+
const full = path.join(dir, skill.name, ...file.path.split("/"));
|
|
280
|
+
const content = generatedCopy(file, "setup");
|
|
281
|
+
const existing = await readTextFile(full);
|
|
282
|
+
if (existing === content)
|
|
283
|
+
continue;
|
|
284
|
+
if (existing !== undefined && !isGenerated(existing)) {
|
|
285
|
+
foreign.push(`${skill.name}/${file.path}`);
|
|
286
|
+
continue;
|
|
287
|
+
}
|
|
288
|
+
changed++;
|
|
289
|
+
if (apply)
|
|
290
|
+
await writeFileAtomic(full, content);
|
|
291
|
+
}
|
|
292
|
+
}
|
|
293
|
+
if (apply && changed && state && !state.skills)
|
|
294
|
+
state.skills = { dir, ...(createdDir ? { created_dir: createdDir } : {}) };
|
|
295
|
+
const reason = foreign.length ? `${foreign.join(", ")} ${foreign.length === 1 ? "is" : "are"} not cavelon's; left as ${foreign.length === 1 ? "it is" : "they are"}` : undefined;
|
|
296
|
+
if (!changed)
|
|
297
|
+
return { kind: "skills", summary, target, outcome: foreign.length ? "skipped" : "unchanged", ...(reason ? { reason } : {}) };
|
|
298
|
+
return { kind: "skills", summary, target, outcome: apply ? "done" : "planned", ...(reason ? { reason } : {}) };
|
|
299
|
+
}
|
|
300
|
+
export async function applyPlan(plan, env, command, skills, record) {
|
|
301
|
+
const done = [];
|
|
302
|
+
for (const change of plan.changes) {
|
|
303
|
+
if (change.outcome !== "planned") {
|
|
304
|
+
done.push(change);
|
|
305
|
+
continue;
|
|
306
|
+
}
|
|
307
|
+
try {
|
|
308
|
+
if (change.kind === "marketplace" || change.kind === "plugin") {
|
|
309
|
+
const commands = pluginCommands(plan.agent.plugin);
|
|
310
|
+
const args = change.kind === "marketplace" ? commands.marketplaceAdd : commands.install;
|
|
311
|
+
const result = await runProgram(plan.found.program, args, { env, timeoutMs: RUN_TIMEOUT_MS });
|
|
312
|
+
if (result.code !== 0) {
|
|
313
|
+
done.push({ ...change, outcome: "failed", reason: result.error ?? firstLine(result.stderr || result.stdout) ?? `exit ${result.code}` });
|
|
314
|
+
break;
|
|
315
|
+
}
|
|
316
|
+
if (change.kind === "marketplace")
|
|
317
|
+
record.marketplace_added = true;
|
|
318
|
+
else
|
|
319
|
+
record.plugin_installed = true;
|
|
320
|
+
done.push({ ...change, outcome: "done" });
|
|
321
|
+
}
|
|
322
|
+
else if (change.kind === "mcp") {
|
|
323
|
+
done.push(await mcpChange(plan.agent.mcp, command, true, record));
|
|
324
|
+
}
|
|
325
|
+
else {
|
|
326
|
+
done.push(await skillsChange(plan.agent.skills, skills, true, record));
|
|
327
|
+
}
|
|
328
|
+
}
|
|
329
|
+
catch (error) {
|
|
330
|
+
done.push({ ...change, outcome: "failed", reason: error instanceof Error ? error.message : String(error) });
|
|
331
|
+
break;
|
|
332
|
+
}
|
|
333
|
+
}
|
|
334
|
+
return done;
|
|
335
|
+
}
|
|
336
|
+
export async function removeAgent(agent, record, env, skills, sharedSkillDirs) {
|
|
337
|
+
const changes = [];
|
|
338
|
+
if (record.plugin_installed || record.marketplace_added) {
|
|
339
|
+
const found = await findAgent(agent, env);
|
|
340
|
+
const commands = pluginCommands(agent.plugin);
|
|
341
|
+
const steps = [];
|
|
342
|
+
if (record.plugin_installed)
|
|
343
|
+
steps.push(["plugin", commands.uninstall, "uninstall the Cavelon plugin", "plugin_installed"]);
|
|
344
|
+
if (record.marketplace_added)
|
|
345
|
+
steps.push(["marketplace", commands.marketplaceRemove, "remove the Cavelon plugin marketplace", "marketplace_added"]);
|
|
346
|
+
for (const [kind, args, summary, key] of steps) {
|
|
347
|
+
if (!found.program) {
|
|
348
|
+
changes.push({ kind, summary, target: [agent.commands[0], ...args].join(" "), outcome: "failed", reason: `${agent.commands[0]} is not on the PATH; run it yourself` });
|
|
349
|
+
continue;
|
|
350
|
+
}
|
|
351
|
+
const result = await runProgram(found.program, args, { env, timeoutMs: RUN_TIMEOUT_MS });
|
|
352
|
+
if (result.code === 0) {
|
|
353
|
+
delete record[key];
|
|
354
|
+
changes.push({ kind, summary, target: display(found.program, args), outcome: "removed" });
|
|
355
|
+
}
|
|
356
|
+
else {
|
|
357
|
+
changes.push({ kind, summary, target: display(found.program, args), outcome: "failed", reason: result.error ?? firstLine(result.stderr || result.stdout) });
|
|
358
|
+
}
|
|
359
|
+
}
|
|
360
|
+
}
|
|
361
|
+
if (record.mcp) {
|
|
362
|
+
const change = await removeMcp(agent.mcp, record.mcp);
|
|
363
|
+
if (change.outcome !== "failed" && change.outcome !== "skipped")
|
|
364
|
+
delete record.mcp;
|
|
365
|
+
changes.push(change);
|
|
366
|
+
}
|
|
367
|
+
if (record.skills) {
|
|
368
|
+
const change = await removeSkills(record.skills, skills, sharedSkillDirs.has(record.skills.dir));
|
|
369
|
+
delete record.skills;
|
|
370
|
+
changes.push(change);
|
|
371
|
+
}
|
|
372
|
+
return changes;
|
|
373
|
+
}
|
|
374
|
+
async function removeMcp(mcp, record) {
|
|
375
|
+
const summary = 'remove the "cavelon" tools server from';
|
|
376
|
+
const existing = await readTextFile(mcp.file);
|
|
377
|
+
if (existing === undefined)
|
|
378
|
+
return { kind: "mcp", summary, target: mcp.file, outcome: "unchanged" };
|
|
379
|
+
const result = mcp.format === "json"
|
|
380
|
+
? removeJsonEntry(existing, mcp.keys, (value) => isOwnJsonEntry(mcp, value), record.kept ?? mcp.keys.length - 1)
|
|
381
|
+
: removeBlock(existing, "hash");
|
|
382
|
+
if (result.outcome === "unchanged")
|
|
383
|
+
return { kind: "mcp", summary, target: mcp.file, outcome: "unchanged" };
|
|
384
|
+
if (result.outcome === "skipped")
|
|
385
|
+
return { kind: "mcp", summary, target: mcp.file, outcome: "skipped", reason: result.reason };
|
|
386
|
+
if (result.empty && record.created) {
|
|
387
|
+
await fs.rm(mcp.file, { force: true });
|
|
388
|
+
if (record.created_dir)
|
|
389
|
+
await removeEmptyDirs(path.dirname(mcp.file), record.created_dir);
|
|
390
|
+
}
|
|
391
|
+
else {
|
|
392
|
+
await writeKeepingMode(mcp.file, result.content);
|
|
393
|
+
}
|
|
394
|
+
return { kind: "mcp", summary, target: mcp.file, outcome: "removed" };
|
|
395
|
+
}
|
|
396
|
+
async function removeSkills(record, skills, stillUsed) {
|
|
397
|
+
const summary = "remove the Cavelon skills from";
|
|
398
|
+
const target = record.dir + path.sep;
|
|
399
|
+
if (stillUsed)
|
|
400
|
+
return { kind: "skills", summary, target, outcome: "unchanged", reason: "another agent set up by cavelon still uses them" };
|
|
401
|
+
let removed = 0;
|
|
402
|
+
for (const skill of skills) {
|
|
403
|
+
const folder = path.join(record.dir, skill.name);
|
|
404
|
+
for (const file of skill.files) {
|
|
405
|
+
const full = path.join(folder, ...file.path.split("/"));
|
|
406
|
+
if (isGenerated(await readTextFile(full).catch(() => undefined))) {
|
|
407
|
+
await fs.rm(full, { force: true });
|
|
408
|
+
removed++;
|
|
409
|
+
}
|
|
410
|
+
}
|
|
411
|
+
await fs.rmdir(folder).catch(() => undefined);
|
|
412
|
+
}
|
|
413
|
+
if (record.created_dir)
|
|
414
|
+
await removeEmptyDirs(record.dir, record.created_dir);
|
|
415
|
+
return { kind: "skills", summary, target, outcome: removed ? "removed" : "unchanged" };
|
|
416
|
+
}
|
|
417
|
+
async function removeEmptyDirs(dir, top) {
|
|
418
|
+
const last = path.resolve(top);
|
|
419
|
+
let current = path.resolve(dir);
|
|
420
|
+
while (current.startsWith(last)) {
|
|
421
|
+
try {
|
|
422
|
+
await fs.rmdir(current);
|
|
423
|
+
}
|
|
424
|
+
catch {
|
|
425
|
+
return;
|
|
426
|
+
}
|
|
427
|
+
if (current === last)
|
|
428
|
+
return;
|
|
429
|
+
current = path.dirname(current);
|
|
430
|
+
}
|
|
431
|
+
}
|
|
432
|
+
async function topmostMissing(dir) {
|
|
433
|
+
let missing;
|
|
434
|
+
let current = path.resolve(dir);
|
|
435
|
+
while (!(await fs.stat(current).then(() => true, () => false))) {
|
|
436
|
+
missing = current;
|
|
437
|
+
const parent = path.dirname(current);
|
|
438
|
+
if (parent === current)
|
|
439
|
+
break;
|
|
440
|
+
current = parent;
|
|
441
|
+
}
|
|
442
|
+
return missing;
|
|
443
|
+
}
|
|
444
|
+
export async function checkAgent(agent, env, record, platform = process.platform) {
|
|
445
|
+
const found = await findAgent(agent, env, platform);
|
|
446
|
+
const check = { name: agent.name, label: agent.label, found: Boolean(found.program || found.folder), method: null, ok: true, details: [], servers: [] };
|
|
447
|
+
if (agent.plugin && found.program) {
|
|
448
|
+
check.method = "plugin";
|
|
449
|
+
const state = await pluginState(agent.plugin, found.program, env);
|
|
450
|
+
if ("error" in state) {
|
|
451
|
+
check.ok = false;
|
|
452
|
+
check.details.push(`could not ask ${agent.label} about its plugins: ${state.error}`);
|
|
453
|
+
}
|
|
454
|
+
else if (!state.installed) {
|
|
455
|
+
check.ok = false;
|
|
456
|
+
check.details.push("the Cavelon plugin is not installed");
|
|
457
|
+
}
|
|
458
|
+
else if (!state.enabled) {
|
|
459
|
+
check.ok = false;
|
|
460
|
+
check.details.push(`the Cavelon plugin is installed but turned off; turn it on in ${agent.label}`);
|
|
461
|
+
}
|
|
462
|
+
else {
|
|
463
|
+
check.details.push("the Cavelon plugin is installed");
|
|
464
|
+
if (platform !== "win32")
|
|
465
|
+
check.servers.push(await serverCommand(env, platform));
|
|
466
|
+
}
|
|
467
|
+
if (platform !== "win32")
|
|
468
|
+
return check;
|
|
469
|
+
}
|
|
470
|
+
else {
|
|
471
|
+
check.method = "files";
|
|
472
|
+
}
|
|
473
|
+
const entry = await readEntry(agent.mcp);
|
|
474
|
+
if (entry.server) {
|
|
475
|
+
check.details.push(`the "cavelon" tools server is in ${agent.mcp.file}`);
|
|
476
|
+
check.servers.push(entry.server);
|
|
477
|
+
}
|
|
478
|
+
else {
|
|
479
|
+
check.ok = false;
|
|
480
|
+
check.details.push(entry.problem ?? `${agent.mcp.file} has no "cavelon" tools server`);
|
|
481
|
+
}
|
|
482
|
+
if (check.method === "files") {
|
|
483
|
+
const missing = [];
|
|
484
|
+
for (const skill of await bundledSkills()) {
|
|
485
|
+
if ((await readTextFile(path.join(agent.skills, skill.name, "SKILL.md"))) === undefined)
|
|
486
|
+
missing.push(skill.name);
|
|
487
|
+
}
|
|
488
|
+
if (missing.length) {
|
|
489
|
+
check.ok = false;
|
|
490
|
+
check.details.push(`skills missing in ${agent.skills}: ${missing.join(", ")}`);
|
|
491
|
+
}
|
|
492
|
+
else {
|
|
493
|
+
check.details.push(`the Cavelon skills are in ${agent.skills}`);
|
|
494
|
+
}
|
|
495
|
+
}
|
|
496
|
+
if (!record && !check.found)
|
|
497
|
+
check.ok = false;
|
|
498
|
+
return check;
|
|
499
|
+
}
|
|
500
|
+
async function readEntry(mcp) {
|
|
501
|
+
const text = await readTextFile(mcp.file);
|
|
502
|
+
if (text === undefined)
|
|
503
|
+
return { problem: `${mcp.file} does not exist` };
|
|
504
|
+
if (mcp.format === "toml") {
|
|
505
|
+
const lines = text.split(/\r?\n/);
|
|
506
|
+
const start = lines.findIndex((l) => /^\[\s*mcp_servers\s*\.\s*"?cavelon"?\s*\]/.test(l.trim()));
|
|
507
|
+
if (start < 0)
|
|
508
|
+
return { problem: `${mcp.file} has no [mcp_servers.cavelon]` };
|
|
509
|
+
const value = (key) => {
|
|
510
|
+
for (const line of lines.slice(start + 1)) {
|
|
511
|
+
const trimmed = line.trim();
|
|
512
|
+
if (trimmed.startsWith("["))
|
|
513
|
+
break;
|
|
514
|
+
const equals = trimmed.indexOf("=");
|
|
515
|
+
if (equals > 0 && trimmed.slice(0, equals).trim() === key)
|
|
516
|
+
return trimmed.slice(equals + 1).trim();
|
|
517
|
+
}
|
|
518
|
+
return undefined;
|
|
519
|
+
};
|
|
520
|
+
try {
|
|
521
|
+
const command = JSON.parse(value("command") ?? "null");
|
|
522
|
+
const args = JSON.parse(value("args") ?? "[]");
|
|
523
|
+
if (typeof command === "string" && Array.isArray(args))
|
|
524
|
+
return { server: { command, args: args.map(String) } };
|
|
525
|
+
}
|
|
526
|
+
catch {
|
|
527
|
+
}
|
|
528
|
+
return { problem: `the [mcp_servers.cavelon] table in ${mcp.file} is not in a form setup can read` };
|
|
529
|
+
}
|
|
530
|
+
let value;
|
|
531
|
+
try {
|
|
532
|
+
value = mcp.keys.reduce((node, key) => (node && typeof node === "object" ? node[key] : undefined), JSON.parse(text));
|
|
533
|
+
}
|
|
534
|
+
catch {
|
|
535
|
+
return { problem: `${mcp.file} is not plain JSON, so setup cannot read it` };
|
|
536
|
+
}
|
|
537
|
+
const entry = value;
|
|
538
|
+
if (!entry || typeof entry.command !== "string")
|
|
539
|
+
return { problem: `${mcp.file} has no "cavelon" tools server` };
|
|
540
|
+
return { server: { command: entry.command, args: Array.isArray(entry.args) ? entry.args.map(String) : [] } };
|
|
541
|
+
}
|
|
542
|
+
export async function loadSkills() {
|
|
543
|
+
return bundledSkills();
|
|
544
|
+
}
|
|
@@ -51,7 +51,9 @@ for a public widget), **propose the change; the person decides.**
|
|
|
51
51
|
without `confirm`). It changes nothing and shows the old and the new value,
|
|
52
52
|
the operation it would send and the permissions it needs. Show that to the
|
|
53
53
|
person with your reason (what fails or waits now), and wait for their answer.
|
|
54
|
-
- Only after they agreed, run
|
|
54
|
+
- Only after they agreed, run the confirm command it printed (the `confirm`
|
|
55
|
+
field in `--json`) as it stands: it keeps the `--env` and `--tenant` of the
|
|
56
|
+
preview, so it changes the limit the preview showed. Never raise a limit on
|
|
55
57
|
your own, never pick a value higher than the need you named, and never change
|
|
56
58
|
one without telling them.
|
|
57
59
|
- The same goes for the tenant's monthly inference budget
|
|
@@ -168,6 +170,14 @@ version; leave it as `pull` wrote it.
|
|
|
168
170
|
(`cavelon docs get reference/builtin-tools` names it). Without one the agent
|
|
169
171
|
answers from memory; `cavelon validate` warns
|
|
170
172
|
(`knowledge_base_without_search_tool`).
|
|
173
|
+
- **Who approves goes on the Approval node, not into the memo.** When the
|
|
174
|
+
brief says who approves, or that nobody approves their own request, set the
|
|
175
|
+
node's `approvers` (tenant roles or access groups, directly or in `tiers`
|
|
176
|
+
chosen by a number at `by`, such as the amount) and `forbid_self_approval:
|
|
177
|
+
true`, where the package schema publishes them; the instance then refuses
|
|
178
|
+
anyone else. Read the approval node in the schema and the human-in-the-loop
|
|
179
|
+
docs for the shape. A test only shows the approval is reached; a person
|
|
180
|
+
decides once per branch.
|
|
171
181
|
|
|
172
182
|
## Variables and secrets the solution needs
|
|
173
183
|
|
|
@@ -198,8 +208,8 @@ schema has them: `cavelon validate` reports an unknown section):
|
|
|
198
208
|
`variables_set` tool) when the value is not a credential and you know it;
|
|
199
209
|
ask the person otherwise. `cavelon variables list` shows them.
|
|
200
210
|
- **Secrets are set by a person, never by you.** Tell the person the exact
|
|
201
|
-
command `apply` printed, `cavelon secrets set <name>` (with `--env
|
|
202
|
-
|
|
211
|
+
command `apply` printed, `cavelon secrets set <name>` (with the `--env` and
|
|
212
|
+
`--tenant` it printed), to run in their own terminal; it asks for the value
|
|
203
213
|
without echoing it. Never ask for the value, never put it into a file,
|
|
204
214
|
an argument or a message, and never put a credential into a variable.
|
|
205
215
|
`cavelon secrets list` (the `secrets_list` tool) shows which are set,
|
|
@@ -62,7 +62,11 @@ cavelon wait <operation-id> --timeout 90s # exit 0 done, 1 failed, 5
|
|
|
62
62
|
```
|
|
63
63
|
|
|
64
64
|
A loop started from `cavelon` runs **as the person whose token it is**, checked
|
|
65
|
-
again on every iteration.
|
|
65
|
+
again on every iteration. If `loop start` exits 8 (a timeout, a cut
|
|
66
|
+
connection), the run may have started: retry only with the
|
|
67
|
+
`--idempotency-key <key>` its error names, never without it, or a second run
|
|
68
|
+
starts and spends the budget again. `cavelon trace <operation-id>` reads the
|
|
69
|
+
run's traces. Keep each `watch` or `wait` under your shell's time
|
|
66
70
|
limit and run it again to resume (exit 6 means still running). Over MCP, use the
|
|
67
71
|
`loop_iterations` and `operation_status` tools; they never block.
|
|
68
72
|
|
|
@@ -23,7 +23,7 @@ use it when you parse the result.
|
|
|
23
23
|
- **Secrets are set by a person.** When a preview or `cavelon secrets list`
|
|
24
24
|
names a secret that is not set, tell the person the exact command to run in
|
|
25
25
|
their terminal, `cavelon secrets set <name>` (as `apply` prints it, with its
|
|
26
|
-
`--env`). Never ask for the value, never pipe or pass one yourself; there is
|
|
26
|
+
`--env` and `--tenant`). Never ask for the value, never pipe or pass one yourself; there is
|
|
27
27
|
no MCP tool for it. Plain-text variables you may set with `cavelon variables
|
|
28
28
|
set <name> <value>` when the value is not a credential.
|
|
29
29
|
- **Read the limits before you plan a solution:** `cavelon limits` (the
|
|
@@ -38,29 +38,35 @@ use it when you parse the result.
|
|
|
38
38
|
or tell the person who to ask instead of working around it. `cavelon status`
|
|
39
39
|
says when a quota is close to full.
|
|
40
40
|
- No `cavelon.yaml` here or above: for a new solution run
|
|
41
|
-
`cavelon init --instance <url> --tenant <tenant> --harness <
|
|
42
|
-
|
|
43
|
-
package file (a blueprint, an
|
|
41
|
+
`cavelon init --instance <url> --tenant <tenant> --harness <solution>`, where
|
|
42
|
+
the tenant and the solution are each a name, slug or id; for an existing one
|
|
43
|
+
add `cavelon pull` after it. To start from a package file (a blueprint, an
|
|
44
|
+
export from another instance), run
|
|
44
45
|
`cavelon init --instance <url> --tenant <tenant> --from <file>` instead of
|
|
45
|
-
splitting it by hand or importing it in the Admin.
|
|
46
|
-
|
|
46
|
+
splitting it by hand or importing it in the Admin. Never guess a tenant or a
|
|
47
|
+
solution, and never ask the person for an id they would have to look up:
|
|
48
|
+
`cavelon tenant list --json` and `cavelon harness list --json` list the
|
|
49
|
+
names, slugs and ids to choose from, and the person names one by its name.
|
|
50
|
+
In their own terminal, a plain `cavelon init` asks them. Ask for the instance
|
|
51
|
+
URL if you do not know it.
|
|
47
52
|
|
|
48
53
|
## The loop
|
|
49
54
|
|
|
50
55
|
1. **Pull** what is live: `cavelon pull`. It refuses when `package/` has
|
|
51
|
-
uncommitted changes
|
|
56
|
+
uncommitted changes (outside git: files changed since the last pull);
|
|
57
|
+
commit or apply them first. `git diff` then shows what someone changed
|
|
52
58
|
in the Admin.
|
|
53
59
|
2. **Edit** the files in `package/` (one file per schema section) and `tests/`
|
|
54
60
|
(one file per test suite). See the cavelon-authoring skill.
|
|
55
61
|
3. **Validate** offline: `cavelon validate`. Fix every error; `cavelon explain
|
|
56
62
|
<code>` says what a code means and how to fix it.
|
|
57
|
-
4. **Preview**: `cavelon apply --env test` (or `--harness <slug>`). Nothing is
|
|
63
|
+
4. **Preview**: `cavelon apply --env test` (or `--harness <name or slug>`). Nothing is
|
|
58
64
|
imported yet. Read the preview: what is created, updated or deleted, which
|
|
59
65
|
active solutions it reaches, what the target still needs (variables and
|
|
60
66
|
secrets with the command that sets each, OAuth grants, runtime bindings,
|
|
61
67
|
trigger identities), loop budgets, and what the instance ignores.
|
|
62
68
|
5. **Confirm** exactly that preview: `cavelon apply --confirm <preview-id>`
|
|
63
|
-
(with the same `--env`). Exit 4 means the target changed since the preview:
|
|
69
|
+
(the line `apply` printed, with the same `--env` and `--tenant`). Exit 4 means the target changed since the preview:
|
|
64
70
|
preview again and confirm the new id. When the error lists `blockers`, the
|
|
65
71
|
import's own check found them as it applied: fix what each names (the hint
|
|
66
72
|
says how for a code the kit knows), then preview again.
|