cohvu 2.17.0 → 2.19.0

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/proxy.js CHANGED
@@ -1,137 +1,233 @@
1
1
  // MCP proxy — thin stateless translator.
2
2
  //
3
- // Agent speaks MCP on stdin. Proxy speaks REST to the backend.
4
- // No sessions. No state. No reconnection. Each tool call is
5
- // an independent HTTP request.
3
+ // Agent speaks MCP on stdin. Proxy speaks REST to the backend. No sessions,
4
+ // no state beyond a cached manifest (TTL'd), each tool call is an independent
5
+ // HTTP request.
6
+ //
7
+ // Behaviors worth knowing:
8
+ // - Pause is re-checked on every tool call and list, not just at startup,
9
+ // so `cohvu pause` takes effect mid-session.
10
+ // - The manifest is cached for ~60s and also re-fetched on the first 401/402
11
+ // (permissions may have changed since the editor started).
12
+ // - Error payloads from the backend are parsed to extract `error.message`
13
+ // before being returned to the agent; network errors are translated to a
14
+ // human-readable "server unreachable" message.
15
+ // - Per-editor identity rides on an optional `--agent <name>` CLI arg that
16
+ // platform setup writes into each editor's MCP config. The proxy forwards
17
+ // it as `X-Cohvu-Agent` on every tool call so contribution attribution
18
+ // carries "which of this user's agents acted."
6
19
  import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
7
20
  import { getApiKey } from "./auth.js";
8
21
  import { isPaused } from "./pause.js";
9
22
  import { refreshInstructions } from "./setup.js";
10
- import { DEFAULT_BASE_URL } from "./constants.js";
23
+ import { DEFAULT_BASE_URL, CLI_VERSION } from "./constants.js";
24
+ import { log } from "./log.js";
25
+ const MANIFEST_TTL_MS = 60_000; // re-fetch at most every minute when cached
26
+ const MANIFEST_FETCH_TIMEOUT_MS = 8_000;
27
+ const TOOL_CALL_TIMEOUT_MS = 60_000;
28
+ /** Extract the `--agent <name>` arg out of process.argv if the platform
29
+ * setup injected it. Falls back to null. Used by every tool call to tell
30
+ * the server which editor initiated the request. */
31
+ function readAgentArg(argv) {
32
+ const idx = argv.indexOf("--agent");
33
+ if (idx === -1 || idx === argv.length - 1)
34
+ return null;
35
+ const value = argv[idx + 1]?.trim();
36
+ return value && value.length > 0 ? value : null;
37
+ }
38
+ /** Best-effort extraction of a user-friendly message from a backend error
39
+ * body. The canonical shape is `{error: {code, message}}`. We surface
40
+ * `message`; on parse failure we fall back to the raw body. */
41
+ function extractBackendErrorMessage(body) {
42
+ try {
43
+ const parsed = JSON.parse(body);
44
+ if (parsed.error?.message)
45
+ return parsed.error.message;
46
+ }
47
+ catch {
48
+ // not JSON; fall through
49
+ }
50
+ return body || "Unknown error";
51
+ }
52
+ /** Map a fetch-level failure (network error, DNS failure, connection
53
+ * refused) to something the agent can read. */
54
+ function translateNetworkError(err) {
55
+ if (err instanceof Error) {
56
+ const msg = err.message || "";
57
+ if (msg.includes("abort") || msg.includes("timeout") || err.name === "TimeoutError") {
58
+ return "Cohvu server didn't respond in time. Try again in a moment.";
59
+ }
60
+ if (msg.includes("fetch") || msg.includes("ECONNREFUSED") || msg.includes("ENOTFOUND")) {
61
+ return "Cohvu server unreachable. Check your connection and try again.";
62
+ }
63
+ return msg;
64
+ }
65
+ return "Cohvu server unreachable. Check your connection and try again.";
66
+ }
11
67
  export async function proxy() {
12
68
  const baseUrl = process.env.COHVU_API_URL ?? DEFAULT_BASE_URL;
13
- // API key auth — one string, never expires, no refresh
69
+ const agentName = readAgentArg(process.argv);
70
+ // Catch-all handlers so async faults leave a trail before the process
71
+ // exits. Without these, an unhandled rejection looks to the editor like
72
+ // "MCP server disconnected" with no explanation in our logs.
73
+ process.on("uncaughtException", (err) => {
74
+ log.error("proxy_uncaught_exception", { error: err.message, stack: err.stack });
75
+ });
76
+ process.on("unhandledRejection", (reason) => {
77
+ log.error("proxy_unhandled_rejection", { error: String(reason) });
78
+ });
79
+ // Always refresh editor instruction files — works whether or not we're
80
+ // signed in, so users who upgrade the CLI while paused or signed-out
81
+ // still get up-to-date rules/markdown on their editor's next read.
82
+ refreshInstructions();
83
+ log.info("proxy_start", { version: CLI_VERSION, agent: agentName ?? null });
14
84
  const apiKey = getApiKey();
15
85
  if (!apiKey) {
16
- const transport = new StdioServerTransport();
17
- transport.onmessage = async (message) => {
18
- const msg = message;
19
- if (msg.id === undefined)
20
- return;
21
- transport.send({
22
- jsonrpc: "2.0",
23
- id: msg.id,
24
- error: {
25
- code: -32600,
26
- message: "Cohvu is not connected. Run `cohvu` in your terminal to sign in.",
27
- },
28
- }).catch(() => { });
29
- };
30
- await transport.start();
86
+ log.info("proxy_unauthenticated");
87
+ await runSimpleResponder({
88
+ initResult: buildInitResult(null, "Cohvu is not connected. Run `cohvu` in your terminal to sign in."),
89
+ toolsListResult: { tools: [] },
90
+ callToolError: {
91
+ code: -32600,
92
+ message: "Cohvu is not connected. Run `cohvu` in your terminal to sign in.",
93
+ },
94
+ });
31
95
  return;
32
96
  }
33
- // Paused return a working MCP server with no tools
97
+ const authHeader = `Bearer ${apiKey}`;
34
98
  if (isPaused()) {
35
- const transport = new StdioServerTransport();
36
- const pausedInit = {
37
- protocolVersion: "2025-03-26",
38
- capabilities: { tools: {} },
39
- serverInfo: { name: "cohvu", version: "0.1.0" },
40
- instructions: "Cohvu is paused. The developer has temporarily disabled Cohvu. Do not attempt to use understand or contribute.",
41
- };
42
- transport.onmessage = async (message) => {
43
- const msg = message;
44
- if (msg.id === undefined)
45
- return;
46
- switch (msg.method) {
47
- case "initialize":
48
- await transport.send({ jsonrpc: "2.0", id: msg.id, result: pausedInit });
49
- break;
50
- case "tools/list":
51
- await transport.send({ jsonrpc: "2.0", id: msg.id, result: { tools: [] } });
52
- break;
53
- case "ping":
54
- await transport.send({ jsonrpc: "2.0", id: msg.id, result: {} });
55
- break;
56
- default:
57
- await transport.send({ jsonrpc: "2.0", id: msg.id, error: { code: -32600, message: "Cohvu is paused." } });
58
- }
59
- };
60
- transport.onclose = () => process.exit(0);
61
- await transport.start();
99
+ log.info("proxy_paused_at_start");
100
+ await runSimpleResponder({
101
+ initResult: buildInitResult(null, "Cohvu is paused. The developer has temporarily disabled Cohvu. Do not attempt to use understand or contribute."),
102
+ toolsListResult: { tools: [] },
103
+ callToolError: { code: -32600, message: "Cohvu is paused." },
104
+ });
62
105
  return;
63
106
  }
64
- const authHeader = `Bearer ${apiKey}`;
65
- // Silently update instruction files
66
- refreshInstructions();
67
- // Fetch manifest (tool list + instructions) — keep retrying until we get it
107
+ // Fetch manifest. Total wait across retries is capped around 15s so we
108
+ // respond inside the typical MCP client `initialize` timeout (~30s). If
109
+ // we blow past the cap, we still serve a fallback init response rather
110
+ // than keeping the editor hanging.
68
111
  let manifest = null;
112
+ let manifestFetchedAt = 0;
69
113
  async function fetchManifest() {
70
114
  try {
71
115
  const res = await fetch(`${baseUrl}/v1/tools/manifest`, {
72
116
  headers: { Authorization: authHeader },
73
- signal: AbortSignal.timeout(10_000),
117
+ signal: AbortSignal.timeout(MANIFEST_FETCH_TIMEOUT_MS),
74
118
  });
75
- if (res.ok)
76
- return (await res.json());
119
+ if (res.ok) {
120
+ const parsed = (await res.json());
121
+ manifestFetchedAt = Date.now();
122
+ return parsed;
123
+ }
124
+ log.warn("manifest_fetch_status", { status: res.status });
125
+ }
126
+ catch (err) {
127
+ log.warn("manifest_fetch_error", { error: String(err) });
77
128
  }
78
- catch { }
79
129
  return null;
80
130
  }
81
- for (let attempt = 0; attempt < 10; attempt++) {
131
+ /** Re-fetch if cache is stale OR we have no manifest OR caller wants
132
+ * a forced refresh (e.g., after a 401/402 suggesting permissions
133
+ * changed server-side). */
134
+ async function ensureManifest(reason, force = false) {
135
+ if (!force && manifest && Date.now() - manifestFetchedAt < MANIFEST_TTL_MS) {
136
+ return manifest;
137
+ }
138
+ const fresh = await fetchManifest();
139
+ if (fresh) {
140
+ manifest = fresh;
141
+ log.debug("manifest_refreshed", { tool_count: fresh.tools.length, reason });
142
+ }
143
+ return manifest;
144
+ }
145
+ // Startup retry loop with a hard cap on total wait. Backoff: 500ms, 1s,
146
+ // 2s, 4s, 7s → ~14.5s total across 5 attempts.
147
+ const startupDelays = [500, 1000, 2000, 4000, 7000];
148
+ for (let i = 0; i < startupDelays.length; i++) {
82
149
  manifest = await fetchManifest();
83
150
  if (manifest)
84
151
  break;
85
- await new Promise((r) => setTimeout(r, 1000 * Math.min(attempt + 1, 5)));
152
+ await new Promise((r) => setTimeout(r, startupDelays[i]));
153
+ }
154
+ if (!manifest) {
155
+ log.error("manifest_unavailable_at_start");
156
+ }
157
+ else {
158
+ log.info("manifest_ready", { tool_count: manifest.tools.length });
86
159
  }
87
- // Build MCP protocol responses (or error responses if manifest unavailable)
88
- const initializeResult = manifest
89
- ? {
90
- protocolVersion: "2025-03-26",
91
- capabilities: { tools: {} },
92
- serverInfo: manifest.serverInfo,
93
- instructions: manifest.instructions,
160
+ const fallbackInstructions = "Cohvu could not connect to the server. Restart your editor to retry.";
161
+ const initializeResult = buildInitResult(manifest, manifest ? manifest.instructions : fallbackInstructions);
162
+ // Call the backend tool endpoint. Inspects pause state first (so
163
+ // `cohvu pause` mid-session takes effect), parses backend error bodies,
164
+ // translates network failures, and re-fetches the manifest on 401/402
165
+ // so the agent's next tools/list reflects current permissions.
166
+ async function callTool(name, args) {
167
+ // Mid-session pause check — editors don't reconnect on pause, so the
168
+ // in-flight proxy has to honor it at call time.
169
+ if (isPaused()) {
170
+ log.info("tool_call_refused_paused", { tool: name });
171
+ return {
172
+ content: [{ type: "text", text: "Cohvu is paused." }],
173
+ isError: true,
174
+ };
94
175
  }
95
- : {
96
- protocolVersion: "2025-03-26",
97
- capabilities: { tools: {} },
98
- serverInfo: { name: "cohvu", version: "0.1.0" },
99
- instructions: "Cohvu could not connect to the server. Restart your editor to retry.",
100
- };
101
- const toolsListResult = manifest
102
- ? {
103
- tools: manifest.tools.map((t) => ({
104
- name: t.name,
105
- description: t.description,
106
- inputSchema: t.inputSchema,
107
- })),
176
+ const start = Date.now();
177
+ let res;
178
+ try {
179
+ res = await fetch(`${baseUrl}/v1/tools/call`, {
180
+ method: "POST",
181
+ headers: {
182
+ "Content-Type": "application/json",
183
+ Authorization: authHeader,
184
+ ...(agentName ? { "X-Cohvu-Agent": agentName } : {}),
185
+ },
186
+ body: JSON.stringify({ tool: name, arguments: args }),
187
+ signal: AbortSignal.timeout(TOOL_CALL_TIMEOUT_MS),
188
+ });
108
189
  }
109
- : { tools: [] };
110
- // Call backend tool endpoint
111
- async function callTool(name, args) {
112
- const res = await fetch(`${baseUrl}/v1/tools/call`, {
113
- method: "POST",
114
- headers: {
115
- "Content-Type": "application/json",
116
- Authorization: authHeader,
117
- },
118
- body: JSON.stringify({ tool: name, arguments: args }),
119
- signal: AbortSignal.timeout(60_000),
120
- });
190
+ catch (err) {
191
+ const message = translateNetworkError(err);
192
+ log.error("tool_call_network_error", { tool: name, error: String(err) });
193
+ return {
194
+ content: [{ type: "text", text: message }],
195
+ isError: true,
196
+ };
197
+ }
198
+ const durationMs = Date.now() - start;
121
199
  if (!res.ok) {
122
- const body = await res.text().catch(() => "Unknown error");
200
+ const body = await res.text().catch(() => "");
201
+ let message = extractBackendErrorMessage(body);
202
+ // Specific status-based UX messages. The agent relays these to the
203
+ // user, so they need to be human-actionable.
204
+ if (res.status === 401) {
205
+ message = "Cohvu session expired. Run `cohvu` in your terminal to sign in again.";
206
+ }
207
+ // Permissions may have changed — invalidate the cached manifest so
208
+ // the agent's next tools/list is accurate.
209
+ if (res.status === 401 || res.status === 402 || res.status === 403) {
210
+ void ensureManifest(`status_${res.status}`, true).catch((err) => {
211
+ log.debug("manifest_refresh_rejected", { error: String(err) });
212
+ });
213
+ }
214
+ log.warn("tool_call_backend_error", {
215
+ tool: name,
216
+ status: res.status,
217
+ duration_ms: durationMs,
218
+ message,
219
+ });
123
220
  return {
124
- content: [{ type: "text", text: body }],
221
+ content: [{ type: "text", text: message }],
125
222
  isError: true,
126
223
  };
127
224
  }
225
+ log.debug("tool_call_ok", { tool: name, duration_ms: durationMs });
128
226
  return await res.json();
129
227
  }
130
- // Start stdio transport and handle MCP messages
131
228
  const transport = new StdioServerTransport();
132
229
  transport.onmessage = async (message) => {
133
230
  const msg = message;
134
- // Notifications (no id) — acknowledge silently
135
231
  if (msg.id === undefined)
136
232
  return;
137
233
  try {
@@ -139,15 +235,36 @@ export async function proxy() {
139
235
  case "initialize":
140
236
  await transport.send({ jsonrpc: "2.0", id: msg.id, result: initializeResult });
141
237
  break;
142
- case "tools/list":
143
- await transport.send({ jsonrpc: "2.0", id: msg.id, result: toolsListResult });
238
+ case "tools/list": {
239
+ // Pause is live an editor asking for the tool list while the
240
+ // user is paused should see an empty list so the agent doesn't
241
+ // try to call anything and get rejections.
242
+ if (isPaused()) {
243
+ await transport.send({ jsonrpc: "2.0", id: msg.id, result: { tools: [] } });
244
+ break;
245
+ }
246
+ const m = await ensureManifest("tools_list");
247
+ await transport.send({
248
+ jsonrpc: "2.0",
249
+ id: msg.id,
250
+ result: {
251
+ tools: (m ?? manifest)?.tools.map((t) => ({
252
+ name: t.name,
253
+ description: t.description,
254
+ inputSchema: t.inputSchema,
255
+ })) ?? [],
256
+ },
257
+ });
144
258
  break;
259
+ }
145
260
  case "ping":
146
261
  await transport.send({ jsonrpc: "2.0", id: msg.id, result: {} });
147
262
  break;
148
263
  case "tools/call": {
264
+ // If we never got a manifest, try once more — the backend may
265
+ // have come back online since startup.
149
266
  if (!manifest) {
150
- manifest = await fetchManifest();
267
+ await ensureManifest("tools_call_no_manifest", true);
151
268
  }
152
269
  if (!manifest) {
153
270
  await transport.send({
@@ -166,6 +283,7 @@ export async function proxy() {
166
283
  break;
167
284
  }
168
285
  default:
286
+ log.warn("mcp_unknown_method", { method: msg.method });
169
287
  await transport.send({
170
288
  jsonrpc: "2.0",
171
289
  id: msg.id,
@@ -174,6 +292,7 @@ export async function proxy() {
174
292
  }
175
293
  }
176
294
  catch (err) {
295
+ log.error("message_handler_error", { method: msg.method, error: String(err) });
177
296
  await transport.send({
178
297
  jsonrpc: "2.0",
179
298
  id: msg.id,
@@ -181,12 +300,58 @@ export async function proxy() {
181
300
  code: -32603,
182
301
  message: err instanceof Error ? err.message : "Internal error",
183
302
  },
184
- }).catch(() => { });
303
+ }).catch((sendErr) => {
304
+ log.debug("error_response_send_failed", { method: msg.method, error: String(sendErr) });
305
+ });
185
306
  }
186
307
  };
187
308
  transport.onclose = () => {
309
+ log.info("proxy_close");
188
310
  process.exit(0);
189
311
  };
190
312
  await transport.start();
191
313
  }
314
+ /** Used by the paused and unauthenticated branches — the proxy still needs
315
+ * to speak valid MCP so the editor doesn't choke; we just return a
316
+ * working server with no tools plus a clear `initialize` message. */
317
+ async function runSimpleResponder(opts) {
318
+ const transport = new StdioServerTransport();
319
+ transport.onmessage = async (message) => {
320
+ const msg = message;
321
+ if (msg.id === undefined)
322
+ return;
323
+ switch (msg.method) {
324
+ case "initialize":
325
+ await transport.send({ jsonrpc: "2.0", id: msg.id, result: opts.initResult });
326
+ break;
327
+ case "tools/list":
328
+ await transport.send({ jsonrpc: "2.0", id: msg.id, result: opts.toolsListResult });
329
+ break;
330
+ case "ping":
331
+ await transport.send({ jsonrpc: "2.0", id: msg.id, result: {} });
332
+ break;
333
+ default:
334
+ // Only log as "unknown method" if it's NOT a tools/call — tools/call
335
+ // in the simple responder is the expected path for paused/unauth
336
+ // states and the rejection is deliberate, not an unknown method.
337
+ if (msg.method !== "tools/call") {
338
+ log.warn("mcp_unknown_method", { method: msg.method, state: "simple_responder" });
339
+ }
340
+ await transport.send({ jsonrpc: "2.0", id: msg.id, error: opts.callToolError });
341
+ }
342
+ };
343
+ transport.onclose = () => {
344
+ log.info("proxy_close");
345
+ process.exit(0);
346
+ };
347
+ await transport.start();
348
+ }
349
+ function buildInitResult(manifest, instructions) {
350
+ return {
351
+ protocolVersion: "2025-03-26",
352
+ capabilities: { tools: {} },
353
+ serverInfo: manifest?.serverInfo ?? { name: "cohvu", version: CLI_VERSION },
354
+ instructions,
355
+ };
356
+ }
192
357
  //# sourceMappingURL=proxy.js.map
package/dist/proxy.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"proxy.js","sour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AY;KACb,CAAC;AACJ,CAAC"}
package/dist/setup.js CHANGED
@@ -5,11 +5,29 @@ import { homedir } from "os";
5
5
  import { join, dirname } from "path";
6
6
  import { detectPlatforms } from "./platforms.js";
7
7
  import { markedSection, MARKER_START, MARKER_END, CURSOR_RULE } from "./instructions.js";
8
- const MCP_ENTRY = { command: "cohvu" };
9
8
  // ---------------------------------------------------------------------------
10
9
  // MCP config writers
10
+ //
11
+ // Each platform's entry is `{ command: "cohvu", args: ["--agent", <slug>] }`.
12
+ // The proxy reads the `--agent` value and forwards it as `X-Cohvu-Agent`
13
+ // on every tool call so the backend can record which editor initiated the
14
+ // contribution. We maintain two legacy migrations:
15
+ // 1. npx-based entries → direct binary (old install pattern)
16
+ // 2. direct-binary entries missing `args` → add the agent arg
17
+ // Both are idempotent — running setup on an up-to-date config returns "skipped".
11
18
  // ---------------------------------------------------------------------------
12
- function writeJsonMcpConfig(filePath, rootKey) {
19
+ function mcpEntry(agentSlug) {
20
+ return { command: "cohvu", args: ["--agent", agentSlug] };
21
+ }
22
+ function jsonEntryIsUpToDate(existing, agentSlug) {
23
+ if (existing.command !== "cohvu")
24
+ return false;
25
+ const args = Array.isArray(existing.args) ? existing.args : null;
26
+ if (!args)
27
+ return false;
28
+ return args.length === 2 && args[0] === "--agent" && args[1] === agentSlug;
29
+ }
30
+ function writeJsonMcpConfig(filePath, rootKey, agentSlug) {
13
31
  try {
14
32
  let config = {};
15
33
  if (existsSync(filePath)) {
@@ -21,27 +39,21 @@ function writeJsonMcpConfig(filePath, rootKey) {
21
39
  catch {
22
40
  // Malformed JSON — back up and start fresh with just cohvu
23
41
  copyFileSync(filePath, `${filePath}.cohvu-backup`);
24
- config = { [rootKey]: { cohvu: MCP_ENTRY } };
42
+ config = { [rootKey]: { cohvu: mcpEntry(agentSlug) } };
25
43
  ensureDir(dirname(filePath));
26
44
  writeFileSync(filePath, JSON.stringify(config, null, 2) + "\n");
27
- return "ok"; // recovered
45
+ return "ok";
28
46
  }
29
47
  }
30
48
  }
31
49
  const servers = (config[rootKey] ?? {});
32
- // Migrate existing npx entries to direct binary
33
- if (servers.cohvu) {
34
- const existing = servers.cohvu;
35
- if (existing.command === "npx") {
36
- servers.cohvu = MCP_ENTRY;
37
- config[rootKey] = servers;
38
- ensureDir(dirname(filePath));
39
- writeFileSync(filePath, JSON.stringify(config, null, 2) + "\n");
40
- return "ok";
41
- }
50
+ const existing = servers.cohvu;
51
+ if (existing && jsonEntryIsUpToDate(existing, agentSlug)) {
42
52
  return "skipped";
43
53
  }
44
- servers.cohvu = MCP_ENTRY;
54
+ // Any mismatch (legacy npx, direct binary without args, wrong slug,
55
+ // old command) gets overwritten with the current canonical shape.
56
+ servers.cohvu = mcpEntry(agentSlug);
45
57
  config[rootKey] = servers;
46
58
  ensureDir(dirname(filePath));
47
59
  writeFileSync(filePath, JSON.stringify(config, null, 2) + "\n");
@@ -54,26 +66,28 @@ function writeJsonMcpConfig(filePath, rootKey) {
54
66
  return { failed: msg.slice(0, 60) };
55
67
  }
56
68
  }
57
- function writeTomlMcpConfig(filePath) {
69
+ function writeTomlMcpConfig(filePath, agentSlug) {
58
70
  try {
59
71
  let content = "";
60
72
  if (existsSync(filePath)) {
61
73
  content = readFileSync(filePath, "utf-8");
62
74
  }
75
+ const canonicalSection = `[mcp_servers.cohvu]\ncommand = "cohvu"\nargs = ["--agent", "${agentSlug}"]\n`;
63
76
  if (content.includes("[mcp_servers.cohvu]")) {
64
- // Migrate existing npx entries to direct binary
65
- if (content.includes('command = "npx"') && content.includes('args = ["cohvu"]')) {
66
- content = content
67
- .replace('command = "npx"', 'command = "cohvu"')
68
- .replace(/\nargs = \["cohvu"\]\n/, "\n");
69
- writeFileSync(filePath, content);
70
- return "ok";
77
+ // Check if the existing section matches the canonical form.
78
+ const sectionRegex = /\[mcp_servers\.cohvu\]\n(?:[^\n\[]*\n?)*/;
79
+ const match = content.match(sectionRegex);
80
+ if (match && match[0].trim() === canonicalSection.trim()) {
81
+ return "skipped";
71
82
  }
72
- return "skipped";
83
+ // Replace the entire [mcp_servers.cohvu] block. We match from the
84
+ // header up to the next section header or EOF.
85
+ content = content.replace(/\[mcp_servers\.cohvu\][\s\S]*?(?=\n\[|\n*$)/, canonicalSection.trim());
86
+ writeFileSync(filePath, content);
87
+ return "ok";
73
88
  }
74
- const section = `\n[mcp_servers.cohvu]\ncommand = "cohvu"\n`;
75
89
  ensureDir(dirname(filePath));
76
- writeFileSync(filePath, content + section);
90
+ writeFileSync(filePath, content + "\n" + canonicalSection);
77
91
  return "ok";
78
92
  }
79
93
  catch (err) {
@@ -203,10 +217,10 @@ export async function runSetup() {
203
217
  if (def.mcp) {
204
218
  const filePath = resolve(def.mcp.path);
205
219
  if (def.mcp.format === "toml") {
206
- result.mcp = writeTomlMcpConfig(filePath);
220
+ result.mcp = writeTomlMcpConfig(filePath, def.agentSlug);
207
221
  }
208
222
  else {
209
- result.mcp = writeJsonMcpConfig(filePath, def.mcp.rootKey);
223
+ result.mcp = writeJsonMcpConfig(filePath, def.mcp.rootKey, def.agentSlug);
210
224
  }
211
225
  }
212
226
  // Write instruction file