@cavelon/cli 0.1.8 → 0.1.9

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/dist/mcp.js CHANGED
@@ -5,6 +5,7 @@ import { MCP_MAX_WAIT_MS } from "./commands/async.js";
5
5
  import { createContext, withWarnings } from "./context.js";
6
6
  import { asCavelonError, CavelonError, ExitCode, usageError } from "./errors.js";
7
7
  import { closest } from "./package-references.js";
8
+ import { startSessionUpdateCheck } from "./update-check.js";
8
9
  import { KIT_VERSION } from "./version.js";
9
10
  const INSTRUCTIONS = "Tools for one Cavelon instance, acting with the token a person stored with `cavelon login` " +
10
11
  "(or CAVELON_TOKEN). You never see or pass the token. Tools that start work (kb_upload, test_run, " +
@@ -40,7 +41,9 @@ const INSTRUCTIONS = "Tools for one Cavelon instance, acting with the token a pe
40
41
  "values are set, never a value: a person sets a secret, so tell them the exact `cavelon secrets set <name>` command " +
41
42
  "to run in their terminal, and never ask for, read or pass a secret value. Never approve or decide an approval; " +
42
43
  "that stays with a person. Use docs_search before guessing, " +
43
- "and api_list/api_describe/api for anything without its own tool.";
44
+ "and api_list/api_describe/api for anything without its own tool. " +
45
+ "The first result of a session may carry a warning that cavelon, the Cavelon plugin or this folder's skills are behind " +
46
+ "the latest release, with the commands that update them: pass it on to the person, who runs them; do not run them yourself.";
44
47
  const TOKEN_DESCRIPTION = "Over MCP: the confirm_token this tool's preview returned, which confirms exactly the change it showed; true is refused.";
45
48
  export function toolName(spec) {
46
49
  return spec.mcpTool || undefined;
@@ -155,20 +158,17 @@ function missingRequired(spec, args) {
155
158
  function mcpIo(io) {
156
159
  return { ...io, stdout: { write: () => true, isTTY: false } };
157
160
  }
158
- export function createMcpServer(io, commands) {
161
+ export function createMcpServer(io, commands, updates = {}) {
159
162
  const tools = commands.filter((c) => c.mcpTool);
160
163
  const byName = new Map(tools.map((c) => [toolName(c), c]));
161
164
  const server = new Server({ name: "cavelon", version: KIT_VERSION }, { capabilities: { tools: {} }, instructions: INSTRUCTIONS });
165
+ const notice = startSessionUpdateCheck(io, updates);
162
166
  server.setRequestHandler(ListToolsRequestSchema, async () => ({ tools: tools.map(toolFor) }));
163
- server.setRequestHandler(CallToolRequestSchema, async (request) => {
164
- const spec = byName.get(request.params.name);
165
- const given = (request.params.arguments ?? {});
166
- const fail = (error) => ({
167
- isError: true,
168
- content: [{ type: "text", text: JSON.stringify({ error: asCavelonError(error).toJSON() }) }],
169
- });
167
+ async function call(name, given) {
168
+ const spec = byName.get(name);
169
+ const fail = (error) => ({ isError: true, body: { error: asCavelonError(error).toJSON() } });
170
170
  if (!spec)
171
- return fail(new Error(`Unknown tool ${request.params.name}.`));
171
+ return fail(new Error(`Unknown tool ${name}.`));
172
172
  const renamed = [];
173
173
  let args;
174
174
  try {
@@ -194,11 +194,24 @@ export function createMcpServer(io, commands) {
194
194
  if (result.exitCode)
195
195
  data.exit_code = result.exitCode;
196
196
  }
197
- return { content: [{ type: "text", text: JSON.stringify(data ?? null) }] };
197
+ return { body: data ?? null };
198
198
  }
199
199
  catch (error) {
200
200
  return fail(error);
201
201
  }
202
+ }
203
+ server.setRequestHandler(CallToolRequestSchema, async (request) => {
204
+ const warning = notice.forCall(() => server.getClientVersion()?.name);
205
+ const { body, isError } = await call(request.params.name, (request.params.arguments ?? {}));
206
+ let out = body;
207
+ const text = await warning;
208
+ if (text) {
209
+ if (out && typeof out === "object" && !Array.isArray(out))
210
+ out = withWarnings(out, [text]);
211
+ else
212
+ notice.keep();
213
+ }
214
+ return { ...(isError ? { isError } : {}), content: [{ type: "text", text: JSON.stringify(out) }] };
202
215
  });
203
216
  return server;
204
217
  }
@@ -29,6 +29,11 @@ use it when you parse the result.
29
29
  `--env` and `--tenant`). Never ask for the value, never pipe or pass one yourself; there is
30
30
  no MCP tool for it. Plain-text variables you may set with `cavelon variables
31
31
  set <name> <value>` when the value is not a credential.
32
+ - **Pass on an update warning.** The first MCP result of a session may warn
33
+ that `cavelon`, the Cavelon plugin or this folder's skills are behind the
34
+ latest release (`… is out; this is …`, `The Cavelon plugin is …`), with the
35
+ commands that update them. Tell the person, with those commands, before you
36
+ go on; they run them (an update takes effect in a new session), you do not.
32
37
  - **Read the limits before you plan a solution:** `cavelon limits` (the
33
38
  `limits` tool over MCP). It lists what this instance allows the tenant
34
39
  (upload size and file types, agent turns, tool calls, timeouts, rate limits,
@@ -1,11 +1,20 @@
1
+ import fs from "node:fs/promises";
1
2
  import path from "node:path";
2
- import { NPM_PACKAGE, REPOSITORY } from "./install.js";
3
- import { readJsonFile, writeFileAtomic } from "./fsutil.js";
3
+ import { SKILL_ROOTS } from "./agents.js";
4
+ import { currentInstall, NPM_PACKAGE, REPOSITORY } from "./install.js";
5
+ import { readJsonFile, readTextFile, writeFileAtomic } from "./fsutil.js";
6
+ import { isGenerated } from "./markers.js";
4
7
  import { cacheDir } from "./paths.js";
8
+ import { findProject } from "./project.js";
9
+ import { KIT_VERSION } from "./version.js";
5
10
  export const DAY_MS = 24 * 60 * 60 * 1000;
6
11
  export const CHECK_TIMEOUT_MS = 1500;
7
12
  const MAX_BODY = 1024 * 1024;
8
13
  const STATE_FILE = "update-check.json";
14
+ export const PLUGIN_VERSION_VARIABLE = "CAVELON_PLUGIN_VERSION";
15
+ export const CLAUDE_PLUGIN_ROOT_VARIABLE = "CLAUDE_PLUGIN_ROOT";
16
+ const PLUGIN_NAME = "cavelon";
17
+ const UPDATING_DOCS = `https://github.com/${REPOSITORY}/blob/main/docs/installation.md#updating`;
9
18
  const SOURCES = {
10
19
  github: { url: `https://api.github.com/repos/${REPOSITORY}/releases/latest`, field: "tag_name" },
11
20
  npm: { url: `https://registry.npmjs.org/${NPM_PACKAGE}/latest`, field: "version" },
@@ -37,7 +46,14 @@ export function startUpdateCheck(request) {
37
46
  }
38
47
  async function check(request) {
39
48
  const { io, install, version } = request;
40
- const source = install.source;
49
+ return withState(io, install.source, version, request.fetch ?? fetch, (state, now) => {
50
+ if (!state.latest || !newer(state.latest, version) || within(state.notified_at, now))
51
+ return undefined;
52
+ state.notified_at = now.toISOString();
53
+ return noticeText(state.latest, version, install);
54
+ });
55
+ }
56
+ async function withState(io, source, version, fetchImpl, use) {
41
57
  const file = path.join(cacheDir(io.env), STATE_FILE);
42
58
  const state = (await readJsonFile(file)) ?? {};
43
59
  const now = io.now();
@@ -49,18 +65,14 @@ async function check(request) {
49
65
  }
50
66
  if (!within(state.checked_at, now)) {
51
67
  state.checked_at = now.toISOString();
52
- const latest = await latestVersion(source, version, request.fetch ?? fetch).catch(() => undefined);
68
+ const latest = await latestVersion(source, version, fetchImpl).catch(() => undefined);
53
69
  if (latest)
54
70
  state.latest = latest;
55
71
  }
56
- let notice;
57
- if (state.latest && newer(state.latest, version) && !within(state.notified_at, now)) {
58
- notice = noticeText(state.latest, version, install);
59
- state.notified_at = now.toISOString();
60
- }
72
+ const result = use(state, now);
61
73
  if (JSON.stringify(state) !== before)
62
74
  await writeFileAtomic(file, `${JSON.stringify(state, null, 2)}\n`, 0o600, 0o700);
63
- return notice;
75
+ return result;
64
76
  }
65
77
  function within(stamp, now) {
66
78
  const at = stamp ? Date.parse(stamp) : NaN;
@@ -116,3 +128,137 @@ export function noticeText(latest, version, install) {
116
128
  return `${head} Update with:\n ${install.update}\n`;
117
129
  return `${head}${install.advice ? ` ${install.advice}` : ""}\n`;
118
130
  }
131
+ export function sessionQuietReason(io, install) {
132
+ if (setTo(io.env.CAVELON_NO_UPDATE_CHECK))
133
+ return "CAVELON_NO_UPDATE_CHECK";
134
+ if (CI_VARIABLES.some((name) => setTo(io.env[name])))
135
+ return "ci";
136
+ if (install.method === "source")
137
+ return "source";
138
+ return undefined;
139
+ }
140
+ export function startSessionUpdateCheck(io, options = {}) {
141
+ const install = options.install ?? currentInstall(io.env);
142
+ const version = options.version ?? KIT_VERSION;
143
+ if (sessionQuietReason(io, install))
144
+ return { forCall: async () => undefined, keep: () => undefined };
145
+ let facts;
146
+ let settled = false;
147
+ const gathered = Promise.all([
148
+ pluginVersion(io.env)
149
+ .catch(() => undefined)
150
+ .then((plugin) => {
151
+ const source = install.source ?? (plugin ? "github" : undefined);
152
+ const latest = source ? withState(io, source, version, options.fetch ?? fetch, (state) => state.latest).catch(() => undefined) : undefined;
153
+ return Promise.all([plugin, latest]);
154
+ }),
155
+ initSkillsVersion(io.cwd).catch(() => undefined),
156
+ ]).then(([[plugin, latest], skills]) => {
157
+ facts = { plugin, latest, skills };
158
+ settled = true;
159
+ });
160
+ let first = true;
161
+ let delivered = false;
162
+ return {
163
+ async forCall(client) {
164
+ if (delivered)
165
+ return undefined;
166
+ if (first) {
167
+ first = false;
168
+ await bounded(gathered, CHECK_TIMEOUT_MS);
169
+ }
170
+ if (delivered || !settled)
171
+ return undefined;
172
+ delivered = true;
173
+ return facts && sessionWarning({ ...facts, version, install, client: client() });
174
+ },
175
+ keep() {
176
+ delivered = false;
177
+ },
178
+ };
179
+ }
180
+ function bounded(promise, ms) {
181
+ let timer;
182
+ const timeout = new Promise((resolve) => {
183
+ timer = setTimeout(resolve, ms);
184
+ });
185
+ return Promise.race([promise.then(() => undefined), timeout]).finally(() => clearTimeout(timer));
186
+ }
187
+ export async function pluginVersion(env) {
188
+ const said = parseVersion(env[PLUGIN_VERSION_VARIABLE] ?? "")?.text;
189
+ if (said)
190
+ return said;
191
+ const root = env[CLAUDE_PLUGIN_ROOT_VARIABLE];
192
+ if (!root || !path.isAbsolute(root))
193
+ return undefined;
194
+ const manifest = await readJsonFile(path.join(root, ".claude-plugin", "plugin.json"));
195
+ if (manifest?.name !== PLUGIN_NAME || typeof manifest.version !== "string")
196
+ return undefined;
197
+ return parseVersion(manifest.version)?.text;
198
+ }
199
+ const INIT_MARK = /written by `cavelon init --agents` \(cavelon ([0-9][0-9A-Za-z.-]{0,80})\)/;
200
+ const SKILL_FOLDER = /^cavelon-[a-z0-9-]{1,64}$/;
201
+ async function initSkillsVersion(cwd) {
202
+ const root = (await findProject(cwd))?.root ?? cwd;
203
+ let oldest;
204
+ for (const skillRoot of SKILL_ROOTS) {
205
+ let names;
206
+ try {
207
+ names = await fs.readdir(path.join(root, skillRoot));
208
+ }
209
+ catch {
210
+ continue;
211
+ }
212
+ for (const name of names.filter((n) => SKILL_FOLDER.test(n))) {
213
+ const text = await readTextFile(path.join(root, skillRoot, name, "SKILL.md"));
214
+ if (!isGenerated(text))
215
+ continue;
216
+ const found = parseVersion(INIT_MARK.exec(text)?.[1] ?? "")?.text;
217
+ if (found && (!oldest || newer(oldest, found)))
218
+ oldest = found;
219
+ }
220
+ }
221
+ return oldest;
222
+ }
223
+ const PLUGIN_UPDATE = {
224
+ claude: "`claude plugin marketplace update cavelon-dev-kit` and `claude plugin update cavelon@cavelon-dev-kit`",
225
+ codex: "`codex plugin marketplace upgrade cavelon-dev-kit` and `codex plugin add cavelon@cavelon-dev-kit`",
226
+ };
227
+ function pluginUpdate(client) {
228
+ const name = client?.toLowerCase() ?? "";
229
+ if (name.includes("claude"))
230
+ return PLUGIN_UPDATE.claude;
231
+ if (name.includes("codex"))
232
+ return PLUGIN_UPDATE.codex;
233
+ return undefined;
234
+ }
235
+ export function sessionWarning(facts) {
236
+ const { version, install, plugin, skills } = facts;
237
+ const latest = facts.latest && install.source && newer(facts.latest, version) ? facts.latest : undefined;
238
+ const newest = facts.latest && newer(facts.latest, version) ? facts.latest : version;
239
+ const pluginBehind = plugin !== undefined && newer(newest, plugin);
240
+ const skillsBehind = skills !== undefined && newer(latest ?? version, skills);
241
+ if (!latest && !pluginBehind && !skillsBehind)
242
+ return undefined;
243
+ const said = [];
244
+ const asks = [];
245
+ if (latest) {
246
+ said.push(`cavelon ${latest} is out; this is ${version}.`);
247
+ asks.push(install.update ? `Update cavelon with \`${install.update}\`.` : (install.advice ?? `Update cavelon to ${latest}.`));
248
+ }
249
+ if (pluginBehind) {
250
+ said.push(`The Cavelon plugin is ${plugin}${latest ? "" : `, older than cavelon ${newest}`}.`);
251
+ const commands = pluginUpdate(facts.client);
252
+ asks.push(commands ? `Update the plugin with ${commands}.` : `Update the plugin: in Claude Code with ${PLUGIN_UPDATE.claude}; in Codex with ${PLUGIN_UPDATE.codex}.`);
253
+ }
254
+ else if (latest && plugin === undefined && pluginUpdate(facts.client)) {
255
+ asks.push(`If they use the Cavelon plugin, also update it with ${pluginUpdate(facts.client)}.`);
256
+ }
257
+ if (skillsBehind) {
258
+ said.push(`The skills \`cavelon init --agents\` wrote in this solution folder are from cavelon ${skills}.`);
259
+ asks.push(`Run \`cavelon init --update\` in it${latest ? " after updating cavelon" : ""}, and commit the result.`);
260
+ }
261
+ if (latest || pluginBehind)
262
+ asks.push("Then start a new agent session.");
263
+ return `${said.join(" ")} Tell the user: ${asks.join(" ")} More: ${UPDATING_DOCS}`;
264
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cavelon/cli",
3
- "version": "0.1.8",
3
+ "version": "0.1.9",
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",