@rucher/carnet 0.2.0-beta.0 → 0.2.0-beta.2

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.mjs CHANGED
@@ -1,26 +1,22 @@
1
- import { $ as reportsDirectoryOf, Ft as CarnetError, M as NOTE_KINDS, Mt as EVENT_TYPES, Ot as OPEN_AGENT_STATUSES, Q as reportPathFor, R as memoryHalfLife, S as renderTableLine, Tt as EMOJI, a as sessionLabel, g as renderAgentLine, i as resumeContext, it as DEFAULT_HOST, kt as USER_ACTION_STATUSES, ot as hostById, r as formatEventLine, s as openCarnet } from "./resume-CQRf2jIa.mjs";
2
- import { mkdirSync } from "node:fs";
1
+ import { At as EMOJI, Bt as CarnetError, F as NOTE_KINDS, Lt as EVENT_TYPES, Nt as OPEN_AGENT_STATUSES, Pt as USER_ACTION_STATUSES, T as renderTableLine, V as memoryHalfLife, a as formatEventLine, dt as hostById, it as reportsDirectoryOf, l as openCarnet, lt as DEFAULT_HOST, n as stepAgent, o as resumeContext, rt as reportPathFor, s as sessionLabel, t as AGENT_STEPS, y as renderAgentLine } from "./steps-CIQ9Nay1.mjs";
2
+ import { copyFileSync, existsSync, mkdirSync } from "node:fs";
3
+ import { resolve } from "node:path";
3
4
  import { McpServer } from "@modelcontextprotocol/server";
4
5
  import { serveStdio } from "@modelcontextprotocol/server/stdio";
5
6
  import * as z from "zod/v4";
6
7
  // src/mcp/instructions.ts
7
- const INSTRUCTIONS = `Carnet tracks sub-agents (forks), the "On the table" line, sessions, the journal and the group memory, in a shared database the \`rucher\` CLI renders. Status goes through these tools only: never status files, never status updates in the chat. Your session is resolved automatically; pass \`session\` only to target another one. The full workflow is the rucher skill: load it before dispatching, applying or reviewing forks.
8
+ const INSTRUCTIONS = `Carnet holds the forks, the "On the table" line, sessions, the journal and the group memory that the \`rucher\` CLI renders. The session is resolved automatically; pass \`session\` only to target another one. The workflow rules are in the system prompt and the rucher skill: load the skill before dispatching, applying or reviewing forks.
8
9
 
9
- Main agent:
10
- - agent_start before dispatching a fork (name, task), in an earlier message than the launch. Launch it with the agent name as the Agent description and a prompt starting with "You are fork \`<name>\`." Names are short, no paths.
11
- - table_set with main_working=true before applying, testing or fixing yourself; table_set with a status, or table_clear, when done.
12
- - log_event when a step is answered, applied, tested, committed or dropped.
13
- - When a fork finishes: say only "<name> finished, report ready", copy its report to the destination agent_start gave and call agent_update with that report_path. Present a fork's report only when the human asks for it: never summarise or act on it, or on the fork's final message, before.
14
- - agent_update to move an agent to the next human action; agent_drop once committed or abandoned; queue_reorder to change the order; agent_list to recall where things stand.
15
- - note_add at the end of a step for what was learned, decided or ruled out; note_drop with the reason when a note proves wrong; promote the Learnings of fork reports.
16
- - session_new when the human names this session; session_list, session_resume_info and log_read to recall sessions or the journal; session_drop only when the human asks.
10
+ Which tool, when:
11
+ - Dispatch: agent_start, then launch the fork in a later message.
12
+ - Each step of a fork's work: agent_step (answered, applying, applied, tested, committed, dropped).
13
+ - Main agent working on something else: table_set, table_clear.
14
+ - Other moves: agent_update, agent_drop, queue_reorder. Recall: agent_list, log_read, session_resume_info, session_list.
15
+ - Memory: note_list before an approach, note_add and note_drop at the end of a step (main agent), note_cite when a note changed what you did.
16
+ - Session: session_new when the human names it, session_drop only when asked.
17
+ - Fork: agent_update (running, short note) at progress, agent_done last.
17
18
 
18
- Forks:
19
- - agent_update (status running, short note) at meaningful progress.
20
- - agent_done with the report path as your LAST tool action, has_questions=true when the report asks the human something, then reply with one line that carries no results ("<name> done, report written").
21
- - Never agent_start, table_set or note_add: end the report with a Learnings section. Both roles: note_cite when a note changed what you did.
22
-
23
- Statuses (the NEXT action): running ⏳ fork working · discussing 💬 · answer ❓ · review 👀 · apply 📥 · test 🧪 · commit ✅ · branch 🌿. Notes and table text: under 60 characters, no paths, no backticks.`;
19
+ Statuses (the NEXT action): running ⏳ · discussing 💬 · answer ❓ · review 👀 · apply 📥 · test 🧪 · commit ✅ · branch 🌿. Notes and table text: under 60 characters, no paths, no backticks.`;
24
20
  // src/mcp/session.ts
25
21
  const FULL_ID = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
26
22
  function createSessionResolver({ carnet, env = process.env, ppid = process.ppid, cwd = process.cwd(), host = hostById(DEFAULT_HOST) }) {
@@ -54,7 +50,7 @@ const session = z.string().optional().describe("Session to target (name, id or i
54
50
  const agentName = z.string().min(1).describe("Short agent name, no paths");
55
51
  const agentStart = defineTool({
56
52
  name: "agent_start",
57
- description: "Main agent only. Register a fork before dispatching it (launch it in a later message). The agent appears as ⏳ running and a `started` event is logged. The result gives the report destination: where main copies the fork report once it finishes, in the group meta directory, outside the repos.",
53
+ description: "Main agent only. Register a fork before dispatching it (launch it in a later message). Logs `started`. The result gives the report destination in the group, where agent_done copies the report.",
58
54
  schema: z.object({
59
55
  name: agentName,
60
56
  task: z.string().min(1).describe("One-line task given to the fork"),
@@ -71,18 +67,12 @@ const agentStart = defineTool({
71
67
  });
72
68
  mkdirSync(reportsDirectoryOf(carnet.group), { recursive: true });
73
69
  const reportDestination = reportPathFor(carnet.group, agent.name);
74
- return {
75
- text: `${EMOJI.running} ${agent.name} started\nReport destination: ${reportDestination}`,
76
- data: {
77
- agent,
78
- reportDestination
79
- }
80
- };
70
+ return { text: `${EMOJI.running} ${agent.name} started in group ${carnet.group.name}\nReport destination: ${reportDestination}` };
81
71
  }
82
72
  });
83
73
  const agentUpdate = defineTool({
84
74
  name: "agent_update",
85
- description: "Change an agent's status and displayed note. Forks use it with status `running` to show progress; the main agent uses user-action statuses (discussing, answer, review, apply, test, commit, branch) as the next step moves, and sets report_path after copying a report to its final place. Use agent_drop to close.",
75
+ description: "Set an agent's status and note. Forks: status running at progress. Main agent: only for moves agent_step does not cover.",
86
76
  schema: z.object({
87
77
  name: agentName,
88
78
  status: z.enum(OPEN_AGENT_STATUSES).describe("Next action: running means the fork is working"),
@@ -96,20 +86,24 @@ const agentUpdate = defineTool({
96
86
  note: args.note,
97
87
  reportPath: args.report_path
98
88
  });
99
- return {
100
- text: renderAgentLine({
101
- name: agent.name,
102
- status: agent.status,
103
- emoji: agent.status === "closed" ? "" : EMOJI[agent.status],
104
- note: agent.note
105
- }),
106
- data: { agent }
107
- };
89
+ return { text: renderAgentLine({
90
+ name: agent.name,
91
+ status: agent.status,
92
+ emoji: agent.status === "closed" ? "" : EMOJI[agent.status],
93
+ note: agent.note
94
+ }) };
108
95
  }
109
96
  });
97
+ function copyReport(carnet, name, reportPath) {
98
+ const destination = reportPathFor(carnet.group, name);
99
+ if (resolve(reportPath) === destination || !existsSync(reportPath)) return reportPath;
100
+ mkdirSync(reportsDirectoryOf(carnet.group), { recursive: true });
101
+ copyFileSync(reportPath, destination);
102
+ return destination;
103
+ }
110
104
  const agentDone = defineTool({
111
105
  name: "agent_done",
112
- description: "Forks call this as their LAST tool action, then reply with one line that carries no results (the report holds them). Records the report path and the outcome: ❓ answer (has_questions=true) or 👀 review, shown once the fork has really stopped. Logs a `finished` event then.",
106
+ description: "Forks call this as their LAST tool action, then reply with one line that carries no results. Copies the report to the group report destination and marks the agent ❓ answer (has_questions) or 👀 review once the fork stops.",
113
107
  schema: z.object({
114
108
  name: agentName,
115
109
  report_path: z.string().min(1).describe("Absolute path of the markdown report"),
@@ -118,14 +112,11 @@ const agentDone = defineTool({
118
112
  }),
119
113
  run: (carnet, sessionId, args) => {
120
114
  const agent = carnet.agents.finish(sessionId, args.name, {
121
- reportPath: args.report_path,
115
+ reportPath: copyReport(carnet, args.name, args.report_path),
122
116
  hasQuestions: args.has_questions
123
117
  });
124
118
  const outcome = args.has_questions ? `${EMOJI.answer} ${agent.name} needs answers` : `${EMOJI.review} ${agent.name} ready for review`;
125
- return {
126
- text: agent.status === "running" ? `${outcome} once you stop; reply now with one line that carries no results` : outcome,
127
- data: { agent }
128
- };
119
+ return { text: agent.status === "running" ? `${outcome} once you stop; reply now with one line that carries no results` : outcome };
129
120
  }
130
121
  });
131
122
  const agentDrop = defineTool({
@@ -137,11 +128,7 @@ const agentDrop = defineTool({
137
128
  session
138
129
  }),
139
130
  run: (carnet, sessionId, args) => {
140
- const agent = carnet.agents.drop(sessionId, args.name, args.reason);
141
- return {
142
- text: `${agent.name} closed`,
143
- data: { agent }
144
- };
131
+ return { text: `${carnet.agents.drop(sessionId, args.name, args.reason).name} closed` };
145
132
  }
146
133
  });
147
134
  const agentList = defineTool({
@@ -149,17 +136,13 @@ const agentList = defineTool({
149
136
  description: "List the open agents of the session with status, note, task and report path.",
150
137
  schema: z.object({ session }),
151
138
  run: (carnet, sessionId) => {
152
- const agents = carnet.agents.list(sessionId);
153
- const lines = agents.map((agent) => {
139
+ const lines = carnet.agents.list(sessionId).map((agent) => {
154
140
  const emoji = agent.status === "closed" ? "" : EMOJI[agent.status];
155
141
  const note = agent.note ? ` — ${agent.note}` : "";
156
142
  const report = agent.reportPath ? ` (report: ${agent.reportPath})` : "";
157
143
  return `${emoji} ${agent.name} [${agent.status}]${note}${report}`;
158
144
  });
159
- return {
160
- text: lines.length ? lines.join("\n") : "no open agents",
161
- data: { agents }
162
- };
145
+ return { text: lines.length ? lines.join("\n") : "no open agents" };
163
146
  }
164
147
  });
165
148
  const queueReorder = defineTool({
@@ -171,20 +154,16 @@ const queueReorder = defineTool({
171
154
  }),
172
155
  run: (carnet, sessionId, args) => {
173
156
  carnet.agents.reorderQueue(sessionId, args.names);
174
- const view = carnet.status.view(carnet.sessions.require(sessionId));
175
- const order = view.waiting.map((line) => line.name).join(", ");
176
- return {
177
- text: order ? `Waiting order: ${order}` : "nothing waiting",
178
- data: { waiting: view.waiting }
179
- };
157
+ const order = carnet.status.view(carnet.sessions.require(sessionId)).waiting.map((line) => line.name).join(", ");
158
+ return { text: order ? `Waiting order: ${order}` : "nothing waiting" };
180
159
  }
181
160
  });
182
161
  const tableSet = defineTool({
183
162
  name: "table_set",
184
- description: "Main agent only. Set the 'On the table' line: what the main agent is handling now. main_working=true while you apply, test or fix yourself (shown ⚙️, not ready for the human). Otherwise give the status of the next human action.",
163
+ description: "Main agent only. Set the 'On the table' line: what the main agent is handling now. main_working=true while you work yourself (⚙️); otherwise the status of the next human action.",
185
164
  schema: z.object({
186
165
  text: z.string().min(1).describe("Under 60 characters, no paths, no backticks"),
187
- main_working: z.boolean().describe("true while the main agent itself is working on it"),
166
+ main_working: z.boolean().optional().describe("Omitted: false when a status is given, else unchanged"),
188
167
  status: z.enum(USER_ACTION_STATUSES).optional().describe("Next human action when main_working is false; defaults to discussing"),
189
168
  session
190
169
  }),
@@ -194,12 +173,22 @@ const tableSet = defineTool({
194
173
  mainWorking: args.main_working,
195
174
  status: args.status
196
175
  });
197
- return {
198
- text: renderTableLine(item),
199
- data: { table: item }
200
- };
176
+ return { text: renderTableLine(item) };
201
177
  }
202
178
  });
179
+ const agentStep = defineTool({
180
+ name: "agent_step",
181
+ description: "Main agent only. One call per step of a fork's work: logs the event, moves the agent to the next human action and keeps the 'On the table' line in sync. answered → apply, applying → ⚙️ table line, applied → test, tested → commit, committed (commit required) → closed, dropped (note = reason) → closed.",
182
+ schema: z.object({
183
+ name: agentName,
184
+ step: z.enum(AGENT_STEPS),
185
+ commit: z.string().optional().describe("Commit sha, for committed"),
186
+ note: z.string().optional().describe("Short note for the journal; the reason for dropped"),
187
+ next: z.enum(OPEN_AGENT_STATUSES).optional().describe("Override the next status, e.g. running when the fork resumes"),
188
+ session
189
+ }),
190
+ run: (carnet, sessionId, args) => ({ text: stepAgent(carnet, sessionId, args) })
191
+ });
203
192
  const tableClear = defineTool({
204
193
  name: "table_clear",
205
194
  description: "Main agent only. Empty the 'On the table' line.",
@@ -211,7 +200,7 @@ const tableClear = defineTool({
211
200
  });
212
201
  const logEvent = defineTool({
213
202
  name: "log_event",
214
- description: "Append a journal event: started, finished, answered, applied, tested, committed, dropped. agent_start, agent_done and agent_drop already log theirs; use this for the human's steps (answered, applied, tested, committed).",
203
+ description: "Append a journal event. agent_start, agent_done, agent_drop and agent_step already log theirs: use this only for events outside them.",
215
204
  schema: z.object({
216
205
  type: z.enum(EVENT_TYPES),
217
206
  agent: z.string().optional().describe("Agent concerned"),
@@ -228,15 +217,12 @@ const logEvent = defineTool({
228
217
  link: args.link,
229
218
  note: args.note
230
219
  });
231
- return {
232
- text: [
233
- "logged",
234
- event.type,
235
- event.agent,
236
- event.commit
237
- ].filter(Boolean).join(" "),
238
- data: { event }
239
- };
220
+ return { text: [
221
+ "logged",
222
+ event.type,
223
+ event.agent,
224
+ event.commit
225
+ ].filter(Boolean).join(" ") };
240
226
  }
241
227
  });
242
228
  const sessionName = z.string().trim().min(1).describe("Short session name, used by rucher resume");
@@ -250,10 +236,7 @@ const sessionNew = defineTool({
250
236
  }),
251
237
  run: (carnet, sessionId, args) => {
252
238
  const named = carnet.sessions.name(sessionId, args.name, args.purpose);
253
- return {
254
- text: `Session named ${named.name}. ${hostById(named.host).renameInstruction(named.name ?? args.name)}`,
255
- data: { session: named }
256
- };
239
+ return { text: `Session named ${named.name}. ${hostById(named.host).renameInstruction(named.name ?? args.name)}` };
257
240
  }
258
241
  });
259
242
  const sessionList = defineTool({
@@ -265,18 +248,14 @@ const sessionList = defineTool({
265
248
  session
266
249
  }),
267
250
  run: (carnet, sessionId, args) => {
268
- const sessions = carnet.sessions.list({
251
+ const lines = carnet.sessions.list({
269
252
  includeTemp: args.include_temp,
270
253
  includeArchived: args.include_archived
271
- });
272
- const lines = sessions.map((listed) => {
254
+ }).map((listed) => {
273
255
  const current = listed.id === sessionId ? " (current)" : "";
274
256
  return `${sessionLabel(listed)} [${listed.kind}, ${listed.status}]${current}`;
275
257
  });
276
- return {
277
- text: lines.length ? lines.join("\n") : "no sessions",
278
- data: { sessions }
279
- };
258
+ return { text: lines.length ? lines.join("\n") : "no sessions" };
280
259
  }
281
260
  });
282
261
  const sessionDrop = defineTool({
@@ -288,10 +267,7 @@ const sessionDrop = defineTool({
288
267
  }),
289
268
  run: (carnet, _sessionId, args) => {
290
269
  const dropped = carnet.sessions.drop(carnet.sessions.find(args.name).id);
291
- return {
292
- text: `Session ${sessionLabel(dropped)} archived`,
293
- data: { session: dropped }
294
- };
270
+ return { text: `Session ${sessionLabel(dropped)} archived` };
295
271
  }
296
272
  });
297
273
  const sessionResumeInfo = defineTool({
@@ -304,13 +280,7 @@ const sessionResumeInfo = defineTool({
304
280
  run: (carnet, sessionId, args) => {
305
281
  const target = args.name ? carnet.sessions.find(args.name) : carnet.sessions.require(sessionId);
306
282
  const resume = `rucher resume ${target.name ?? target.id}`;
307
- return {
308
- text: `${resumeContext(carnet, target)}\n\nResume with: ${resume}`,
309
- data: {
310
- session: target,
311
- resume
312
- }
313
- };
283
+ return { text: `${resumeContext(carnet, target)}\n\nResume with: ${resume}` };
314
284
  }
315
285
  });
316
286
  const logRead = defineTool({
@@ -322,10 +292,7 @@ const logRead = defineTool({
322
292
  }),
323
293
  run: (carnet, sessionId, args) => {
324
294
  const events = carnet.events.read(sessionId, args.limit ?? 20);
325
- return {
326
- text: events.length ? events.map(formatEventLine).join("\n") : "no events yet",
327
- data: { events }
328
- };
295
+ return { text: events.length ? events.map(formatEventLine).join("\n") : "no events yet" };
329
296
  }
330
297
  });
331
298
  const noteId = z.number().int().positive().describe("Note id, as shown by note_list (#14 is 14)");
@@ -338,6 +305,7 @@ const TOOLS = [
338
305
  agentUpdate,
339
306
  agentDone,
340
307
  agentDrop,
308
+ agentStep,
341
309
  agentList,
342
310
  queueReorder,
343
311
  tableSet,
@@ -367,13 +335,7 @@ const TOOLS = [
367
335
  session: sessionId
368
336
  });
369
337
  const warning = similar.length ? `\nSimilar active notes, possible duplicate:\n${similar.map(noteLine).join("\n")}` : "";
370
- return {
371
- text: `added ${noteLine(note)}${warning}`,
372
- data: {
373
- note,
374
- similar
375
- }
376
- };
338
+ return { text: `added ${noteLine(note)}${warning}` };
377
339
  }
378
340
  }),
379
341
  defineTool({
@@ -388,19 +350,15 @@ const TOOLS = [
388
350
  session
389
351
  }),
390
352
  run: (carnet, _sessionId, args) => {
391
- const notes = carnet.notes.list({
353
+ const lines = carnet.notes.list({
392
354
  kind: args.kind,
393
355
  repo: args.repo,
394
356
  general: args.general,
395
357
  query: args.query,
396
358
  includeDropped: args.include_dropped,
397
359
  halfLifeDays: memoryHalfLife(process.env["RUCHER_MEMORY_HALF_LIFE_DAYS"])
398
- });
399
- const lines = notes.map((note) => `${noteLine(note)}${note.droppedAt ? ` (dropped: ${note.droppedReason})` : ""}`);
400
- return {
401
- text: lines.length ? lines.join("\n") : "no notes",
402
- data: { notes }
403
- };
360
+ }).map((note) => `${noteLine(note)}${note.droppedAt ? ` (dropped: ${note.droppedReason})` : ""}`);
361
+ return { text: lines.length ? lines.join("\n") : "no notes" };
404
362
  }
405
363
  }),
406
364
  defineTool({
@@ -419,10 +377,7 @@ const TOOLS = [
419
377
  session: sessionId
420
378
  });
421
379
  const replaced = note.replacedBy ? `, replaced by #${note.replacedBy}` : "";
422
- return {
423
- text: `dropped #${note.id}${replaced}`,
424
- data: { note }
425
- };
380
+ return { text: `dropped #${note.id}${replaced}` };
426
381
  }
427
382
  }),
428
383
  defineTool({
@@ -440,10 +395,7 @@ const TOOLS = [
440
395
  agent: args.agent,
441
396
  session: sessionId
442
397
  });
443
- return {
444
- text: `cited #${citation.note}: ${citation.why}`,
445
- data: { citation }
446
- };
398
+ return { text: `cited #${citation.note}: ${citation.why}` };
447
399
  }
448
400
  })
449
401
  ];
@@ -484,14 +436,10 @@ function createCarnetServer(options) {
484
436
  try {
485
437
  const { carnet, resolver } = open();
486
438
  const sessionId = resolver.resolve(args.session);
487
- const out = tool.run(carnet, sessionId, args);
488
- return {
489
- content: [{
490
- type: "text",
491
- text: out.text
492
- }],
493
- structuredContent: out.data
494
- };
439
+ return { content: [{
440
+ type: "text",
441
+ text: tool.run(carnet, sessionId, args).text
442
+ }] };
495
443
  } catch (error) {
496
444
  if (error instanceof CarnetError) return errorResult(error);
497
445
  throw error;
package/dist/mcp.mjs.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"mcp.mjs","names":[],"sources":["../src/mcp/instructions.ts","../src/mcp/session.ts","../src/mcp/tools.ts","../src/mcp/server.ts"],"sourcesContent":["export const INSTRUCTIONS = `Carnet tracks sub-agents (forks), the \"On the table\" line, sessions, the journal and the group memory, in a shared database the \\`rucher\\` CLI renders. Status goes through these tools only: never status files, never status updates in the chat. Your session is resolved automatically; pass \\`session\\` only to target another one. The full workflow is the rucher skill: load it before dispatching, applying or reviewing forks.\n\nMain agent:\n- agent_start before dispatching a fork (name, task), in an earlier message than the launch. Launch it with the agent name as the Agent description and a prompt starting with \"You are fork \\`<name>\\`.\" Names are short, no paths.\n- table_set with main_working=true before applying, testing or fixing yourself; table_set with a status, or table_clear, when done.\n- log_event when a step is answered, applied, tested, committed or dropped.\n- When a fork finishes: say only \"<name> finished, report ready\", copy its report to the destination agent_start gave and call agent_update with that report_path. Present a fork's report only when the human asks for it: never summarise or act on it, or on the fork's final message, before.\n- agent_update to move an agent to the next human action; agent_drop once committed or abandoned; queue_reorder to change the order; agent_list to recall where things stand.\n- note_add at the end of a step for what was learned, decided or ruled out; note_drop with the reason when a note proves wrong; promote the Learnings of fork reports.\n- session_new when the human names this session; session_list, session_resume_info and log_read to recall sessions or the journal; session_drop only when the human asks.\n\nForks:\n- agent_update (status running, short note) at meaningful progress.\n- agent_done with the report path as your LAST tool action, has_questions=true when the report asks the human something, then reply with one line that carries no results (\"<name> done, report written\").\n- Never agent_start, table_set or note_add: end the report with a Learnings section. Both roles: note_cite when a note changed what you did.\n\nStatuses (the NEXT action): running ⏳ fork working · discussing 💬 · answer ❓ · review 👀 · apply 📥 · test 🧪 · commit ✅ · branch 🌿. Notes and table text: under 60 characters, no paths, no backticks.`;\n","import type { Carnet } from '../carnet.ts';\nimport { CarnetError } from '../errors.ts';\nimport { DEFAULT_HOST, type Host, hostById } from '../hosts/host.ts';\n\nconst FULL_ID = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;\n\nexport interface SessionResolverOptions {\n carnet: Carnet;\n env?: NodeJS.ProcessEnv | undefined;\n ppid?: number | undefined;\n cwd?: string | undefined;\n host?: Host | undefined;\n}\n\nexport interface SessionResolver {\n resolve(override?: string): string;\n}\n\nexport function createSessionResolver({\n carnet,\n env = process.env,\n ppid = process.ppid,\n cwd = process.cwd(),\n host = hostById(DEFAULT_HOST),\n}: SessionResolverOptions): SessionResolver {\n // Not cached: after --continue or the resume picker, the server env keeps a provisional\n // startup id, and the hook that records the real one can arrive after the server starts.\n function resolveOwn(): string {\n const hooked = carnet.sessions.byHostProcess(host.id, ppid);\n if (hooked) return hooked.id;\n const fromEnvironment = host.sessionIdFromEnvironment(env);\n if (fromEnvironment) return carnet.sessions.ensure(fromEnvironment, cwd).id;\n throw new CarnetError(\n 'NO_SESSION',\n `Cannot tell which ${host.displayName} session this is: pass \\`session\\`, or install the rucher SessionStart hook`,\n );\n }\n\n function resolveOverride(override: string): string {\n try {\n return carnet.sessions.find(override).id;\n } catch (error) {\n if (!(error instanceof CarnetError) || error.code !== 'SESSION_NOT_FOUND') throw error;\n // A full session id the hook never recorded still gets its row.\n if (FULL_ID.test(override)) return carnet.sessions.ensure(override, cwd).id;\n throw error;\n }\n }\n\n return {\n resolve(override) {\n const id = override ? resolveOverride(override) : resolveOwn();\n carnet.sessions.touch(id);\n return id;\n },\n };\n}\n","import { mkdirSync } from 'node:fs';\nimport * as z from 'zod/v4';\nimport type { Carnet } from '../carnet.ts';\nimport { EVENT_TYPES } from '../events.ts';\nimport { reportPathFor, reportsDirectoryOf } from '../group/locate.ts';\nimport { hostById } from '../hosts/host.ts';\nimport { memoryHalfLife, type Note, NOTE_KINDS } from '../notes.ts';\nimport { formatEventLine, resumeContext, sessionLabel } from '../resume.ts';\nimport { EMOJI, OPEN_AGENT_STATUSES, USER_ACTION_STATUSES } from '../status/model.ts';\nimport { renderAgentLine, renderTableLine } from '../status/render.ts';\n\nexport interface ToolOutput {\n text: string;\n data?: Record<string, unknown>;\n}\n\nexport interface ToolDefinition<Schema extends z.ZodObject = z.ZodObject> {\n name: string;\n description: string;\n schema: Schema;\n run: (carnet: Carnet, sessionId: string, args: z.infer<Schema>) => ToolOutput;\n}\n\nfunction defineTool<Schema extends z.ZodObject>(\n definition: ToolDefinition<Schema>,\n): ToolDefinition<Schema> {\n return definition;\n}\n\nconst session = z\n .string()\n .optional()\n .describe('Session to target (name, id or id prefix). Omit for the current session.');\n\nconst agentName = z.string().min(1).describe('Short agent name, no paths');\n\nconst agentStart = defineTool({\n name: 'agent_start',\n description:\n 'Main agent only. Register a fork before dispatching it (launch it in a later message). The agent appears as ⏳ running and a `started` event is logged. The result gives the report destination: where main copies the fork report once it finishes, in the group meta directory, outside the repos.',\n schema: z.object({\n name: agentName,\n task: z.string().min(1).describe('One-line task given to the fork'),\n base_commit: z.string().optional().describe('Commit the fork starts from'),\n worktree: z.string().optional().describe('Worktree path when the fork has one'),\n session,\n }),\n run: (carnet, sessionId, args) => {\n const agent = carnet.agents.start(sessionId, {\n name: args.name,\n task: args.task,\n baseCommit: args.base_commit,\n worktree: args.worktree,\n });\n mkdirSync(reportsDirectoryOf(carnet.group), { recursive: true });\n const reportDestination = reportPathFor(carnet.group, agent.name);\n return {\n text: `${EMOJI.running} ${agent.name} started\\nReport destination: ${reportDestination}`,\n data: { agent, reportDestination },\n };\n },\n});\n\nconst agentUpdate = defineTool({\n name: 'agent_update',\n description:\n \"Change an agent's status and displayed note. Forks use it with status `running` to show progress; the main agent uses user-action statuses (discussing, answer, review, apply, test, commit, branch) as the next step moves, and sets report_path after copying a report to its final place. Use agent_drop to close.\",\n schema: z.object({\n name: agentName,\n status: z.enum(OPEN_AGENT_STATUSES).describe('Next action: running means the fork is working'),\n note: z.string().optional().describe('Under 60 characters, no paths, no backticks'),\n report_path: z.string().optional().describe('New absolute path of the report, when it moved'),\n session,\n }),\n run: (carnet, sessionId, args) => {\n const agent = carnet.agents.update(sessionId, args.name, {\n status: args.status,\n note: args.note,\n reportPath: args.report_path,\n });\n const text = renderAgentLine({\n name: agent.name,\n status: agent.status,\n emoji: agent.status === 'closed' ? '' : EMOJI[agent.status],\n note: agent.note,\n });\n return { text, data: { agent } };\n },\n});\n\nconst agentDone = defineTool({\n name: 'agent_done',\n description:\n 'Forks call this as their LAST tool action, then reply with one line that carries no results (the report holds them). Records the report path and the outcome: ❓ answer (has_questions=true) or 👀 review, shown once the fork has really stopped. Logs a `finished` event then.',\n schema: z.object({\n name: agentName,\n report_path: z.string().min(1).describe('Absolute path of the markdown report'),\n has_questions: z.boolean().describe('true when the report asks the human something'),\n session,\n }),\n run: (carnet, sessionId, args) => {\n const agent = carnet.agents.finish(sessionId, args.name, {\n reportPath: args.report_path,\n hasQuestions: args.has_questions,\n });\n const outcome = args.has_questions\n ? `${EMOJI.answer} ${agent.name} needs answers`\n : `${EMOJI.review} ${agent.name} ready for review`;\n const text =\n agent.status === 'running'\n ? `${outcome} once you stop; reply now with one line that carries no results`\n : outcome;\n return { text, data: { agent } };\n },\n});\n\nconst agentDrop = defineTool({\n name: 'agent_drop',\n description:\n 'Main agent only. Close an agent once its work is committed or abandoned. It leaves the status view; history stays in the journal.',\n schema: z.object({\n name: agentName,\n reason: z.string().optional().describe('Why it is closed, for the journal'),\n session,\n }),\n run: (carnet, sessionId, args) => {\n const agent = carnet.agents.drop(sessionId, args.name, args.reason);\n return { text: `${agent.name} closed`, data: { agent } };\n },\n});\n\nconst agentList = defineTool({\n name: 'agent_list',\n description: 'List the open agents of the session with status, note, task and report path.',\n schema: z.object({ session }),\n run: (carnet, sessionId) => {\n const agents = carnet.agents.list(sessionId);\n const lines = agents.map((agent) => {\n const emoji = agent.status === 'closed' ? '' : EMOJI[agent.status];\n const note = agent.note ? ` — ${agent.note}` : '';\n const report = agent.reportPath ? ` (report: ${agent.reportPath})` : '';\n return `${emoji} ${agent.name} [${agent.status}]${note}${report}`;\n });\n return { text: lines.length ? lines.join('\\n') : 'no open agents', data: { agents } };\n },\n});\n\nconst queueReorder = defineTool({\n name: 'queue_reorder',\n description:\n \"Main agent only. Set the order of the 'Waiting on you' list. Named agents come first in the given order, the others follow the default order (answer, review, rest).\",\n schema: z.object({\n names: z.array(agentName).min(1).describe('Agent names in handling order'),\n session,\n }),\n run: (carnet, sessionId, args) => {\n carnet.agents.reorderQueue(sessionId, args.names);\n const view = carnet.status.view(carnet.sessions.require(sessionId));\n const order = view.waiting.map((line) => line.name).join(', ');\n return {\n text: order ? `Waiting order: ${order}` : 'nothing waiting',\n data: { waiting: view.waiting },\n };\n },\n});\n\nconst tableSet = defineTool({\n name: 'table_set',\n description:\n \"Main agent only. Set the 'On the table' line: what the main agent is handling now. main_working=true while you apply, test or fix yourself (shown ⚙️, not ready for the human). Otherwise give the status of the next human action.\",\n schema: z.object({\n text: z.string().min(1).describe('Under 60 characters, no paths, no backticks'),\n main_working: z.boolean().describe('true while the main agent itself is working on it'),\n status: z\n .enum(USER_ACTION_STATUSES)\n .optional()\n .describe('Next human action when main_working is false; defaults to discussing'),\n session,\n }),\n run: (carnet, sessionId, args) => {\n const item = carnet.table.set(sessionId, {\n text: args.text,\n mainWorking: args.main_working,\n status: args.status,\n });\n return { text: renderTableLine(item), data: { table: item } };\n },\n});\n\nconst tableClear = defineTool({\n name: 'table_clear',\n description: \"Main agent only. Empty the 'On the table' line.\",\n schema: z.object({ session }),\n run: (carnet, sessionId) => {\n carnet.table.clear(sessionId);\n return { text: 'On the table cleared' };\n },\n});\n\nconst logEvent = defineTool({\n name: 'log_event',\n description:\n \"Append a journal event: started, finished, answered, applied, tested, committed, dropped. agent_start, agent_done and agent_drop already log theirs; use this for the human's steps (answered, applied, tested, committed).\",\n schema: z.object({\n type: z.enum(EVENT_TYPES),\n agent: z.string().optional().describe('Agent concerned'),\n commit: z.string().optional().describe('Commit sha'),\n link: z.string().optional().describe('Report path or URL'),\n note: z.string().optional(),\n session,\n }),\n run: (carnet, sessionId, args) => {\n const event = carnet.events.log(sessionId, {\n type: args.type,\n agent: args.agent,\n commit: args.commit,\n link: args.link,\n note: args.note,\n });\n const parts = ['logged', event.type, event.agent, event.commit].filter(Boolean);\n return { text: parts.join(' '), data: { event } };\n },\n});\n\nconst sessionName = z.string().trim().min(1).describe('Short session name, used by rucher resume');\n\nconst sessionNew = defineTool({\n name: 'session_new',\n description:\n 'Name the current session (or rename it) so it can be resumed later with `rucher resume <name>`. Makes it an active session, kept by the cleanups.',\n schema: z.object({\n name: sessionName,\n purpose: z.string().optional().describe('One line: what this session is for'),\n session,\n }),\n run: (carnet, sessionId, args) => {\n const named = carnet.sessions.name(sessionId, args.name, args.purpose);\n return {\n text: `Session named ${named.name}. ${hostById(named.host).renameInstruction(named.name ?? args.name)}`,\n data: { session: named },\n };\n },\n});\n\nconst sessionList = defineTool({\n name: 'session_list',\n description:\n \"List the group's sessions, most recently active first. Temp and archived ones are hidden unless asked.\",\n schema: z.object({\n include_temp: z.boolean().optional(),\n include_archived: z.boolean().optional(),\n session,\n }),\n run: (carnet, sessionId, args) => {\n const sessions = carnet.sessions.list({\n includeTemp: args.include_temp,\n includeArchived: args.include_archived,\n });\n const lines = sessions.map((listed) => {\n const current = listed.id === sessionId ? ' (current)' : '';\n return `${sessionLabel(listed)} [${listed.kind}, ${listed.status}]${current}`;\n });\n return { text: lines.length ? lines.join('\\n') : 'no sessions', data: { sessions } };\n },\n});\n\nconst sessionDrop = defineTool({\n name: 'session_drop',\n description:\n 'Main agent only. Archive a session by name, id or id prefix: its open agents are closed and it leaves the lists. History stays in the journal.',\n schema: z.object({\n name: z.string().trim().min(1).describe('Session name, id or id prefix'),\n session,\n }),\n run: (carnet, _sessionId, args) => {\n const dropped = carnet.sessions.drop(carnet.sessions.find(args.name).id);\n return { text: `Session ${sessionLabel(dropped)} archived`, data: { session: dropped } };\n },\n});\n\nconst sessionResumeInfo = defineTool({\n name: 'session_resume_info',\n description:\n 'What a session was doing: its status view and last events, plus the command to resume it. Defaults to the current session.',\n schema: z.object({\n name: z.string().trim().min(1).optional().describe('Session name, id or id prefix'),\n session,\n }),\n run: (carnet, sessionId, args) => {\n const target = args.name ? carnet.sessions.find(args.name) : carnet.sessions.require(sessionId);\n const resume = `rucher resume ${target.name ?? target.id}`;\n return {\n text: `${resumeContext(carnet, target)}\\n\\nResume with: ${resume}`,\n data: { session: target, resume },\n };\n },\n});\n\nconst logRead = defineTool({\n name: 'log_read',\n description: 'Read the last journal events of the session, oldest first.',\n schema: z.object({\n limit: z.number().int().min(1).max(200).optional().describe('Number of events, default 20'),\n session,\n }),\n run: (carnet, sessionId, args) => {\n const events = carnet.events.read(sessionId, args.limit ?? 20);\n return {\n text: events.length ? events.map(formatEventLine).join('\\n') : 'no events yet',\n data: { events },\n };\n },\n});\n\nconst noteId = z.number().int().positive().describe('Note id, as shown by note_list (#14 is 14)');\n\nexport function noteLine(note: Note): string {\n const repos = note.repos.length ? ` [${note.repos.join(', ')}]` : '';\n return `#${note.id} ${note.kind}${repos} ${note.text}`;\n}\n\nconst noteAdd = defineTool({\n name: 'note_add',\n description:\n \"Main agent only. Record what the group learned (learning), decided (decision) or tried and gave up (dead_end), at the end of a step. One claim under 200 characters with its reason, no markdown. `repos` only when it applies to some of the group's repos; omit it for a general note. A result listing similar notes means a likely duplicate: drop or replace instead of piling up.\",\n schema: z.object({\n kind: z.enum(NOTE_KINDS),\n text: z.string().min(1).describe('One claim with its reason, under 200 characters'),\n repos: z\n .array(z.string().min(1))\n .optional()\n .describe('Repo names of the group; omit for a general note'),\n agent: z.string().optional().describe('Fork the note comes from'),\n session,\n }),\n run: (carnet, sessionId, args) => {\n const { note, similar } = carnet.notes.add({\n kind: args.kind,\n text: args.text,\n repos: args.repos,\n agent: args.agent,\n session: sessionId,\n });\n const warning = similar.length\n ? `\\nSimilar active notes, possible duplicate:\\n${similar.map(noteLine).join('\\n')}`\n : '';\n return { text: `added ${noteLine(note)}${warning}`, data: { note, similar } };\n },\n});\n\nconst noteList = defineTool({\n name: 'note_list',\n description:\n \"The group's active notes, dead ends first, then decisions, then learnings, most cited first. Filter by kind, repo, general (notes without repo) or a substring query. Check it before trying an approach.\",\n schema: z.object({\n kind: z.enum(NOTE_KINDS).optional(),\n repo: z.string().optional().describe('Notes of this repo'),\n general: z.boolean().optional().describe('Only notes without repo'),\n query: z.string().optional().describe('Substring of the text'),\n include_dropped: z.boolean().optional(),\n session,\n }),\n run: (carnet, _sessionId, args) => {\n const notes = carnet.notes.list({\n kind: args.kind,\n repo: args.repo,\n general: args.general,\n query: args.query,\n includeDropped: args.include_dropped,\n halfLifeDays: memoryHalfLife(process.env['RUCHER_MEMORY_HALF_LIFE_DAYS']),\n });\n const lines = notes.map(\n (note) => `${noteLine(note)}${note.droppedAt ? ` (dropped: ${note.droppedReason})` : ''}`,\n );\n return { text: lines.length ? lines.join('\\n') : 'no notes', data: { notes } };\n },\n});\n\nconst noteDrop = defineTool({\n name: 'note_drop',\n description:\n 'Main agent only. Close a note that proved wrong or outdated: it stays in the history, marked dropped with the reason. Pass replaced_by when a corrected note replaces it.',\n schema: z.object({\n id: noteId,\n reason: z.string().min(1).describe('Why the note is no longer true'),\n replaced_by: z.number().int().positive().optional().describe('Id of the note replacing it'),\n session,\n }),\n run: (carnet, sessionId, args) => {\n const note = carnet.notes.drop(args.id, {\n reason: args.reason,\n replacedBy: args.replaced_by,\n session: sessionId,\n });\n const replaced = note.replacedBy ? `, replaced by #${note.replacedBy}` : '';\n return { text: `dropped #${note.id}${replaced}`, data: { note } };\n },\n});\n\nconst noteCite = defineTool({\n name: 'note_cite',\n description:\n 'Cite a note that changed what you did (avoided, followed or adjusted something), with what it changed. Never for a plain read. Citations decide which notes come first.',\n schema: z.object({\n id: noteId,\n why: z.string().min(1).describe('What the note changed, short'),\n agent: z.string().optional().describe('Fork citing it, when not the main agent'),\n session,\n }),\n run: (carnet, sessionId, args) => {\n const citation = carnet.notes.cite(args.id, {\n why: args.why,\n agent: args.agent,\n session: sessionId,\n });\n return { text: `cited #${citation.note}: ${citation.why}`, data: { citation } };\n },\n});\n\nexport const TOOLS: readonly ToolDefinition[] = [\n agentStart,\n agentUpdate,\n agentDone,\n agentDrop,\n agentList,\n queueReorder,\n tableSet,\n tableClear,\n logEvent,\n logRead,\n sessionNew,\n sessionList,\n sessionDrop,\n sessionResumeInfo,\n noteAdd,\n noteList,\n noteDrop,\n noteCite,\n] as readonly ToolDefinition[];\n","import { type CallToolResult, McpServer } from '@modelcontextprotocol/server';\nimport { serveStdio, type StdioServerHandle } from '@modelcontextprotocol/server/stdio';\nimport type { Carnet } from '../carnet.ts';\nimport { openCarnet, type OpenCarnetOptions } from '../carnet.ts';\nimport { CarnetError } from '../errors.ts';\nimport { INSTRUCTIONS } from './instructions.ts';\nimport {\n createSessionResolver,\n type SessionResolver,\n type SessionResolverOptions,\n} from './session.ts';\nimport { TOOLS } from './tools.ts';\n\nexport const SERVER_NAME = 'carnet';\nexport const SERVER_VERSION = '0.0.0';\n\nexport interface CarnetServerOptions extends Omit<SessionResolverOptions, 'carnet'> {\n carnet: Carnet | (() => Carnet);\n}\n\nfunction errorResult(error: CarnetError): CallToolResult {\n return { isError: true, content: [{ type: 'text', text: `${error.code}: ${error.message}` }] };\n}\n\nexport function createCarnetServer(options: CarnetServerOptions): McpServer {\n let carnet: Carnet | undefined;\n let resolver: SessionResolver | undefined;\n const open = (): { carnet: Carnet; resolver: SessionResolver } => {\n carnet ??= typeof options.carnet === 'function' ? options.carnet() : options.carnet;\n resolver ??= createSessionResolver({ ...options, carnet });\n return { carnet, resolver };\n };\n const server = new McpServer(\n { name: SERVER_NAME, version: SERVER_VERSION },\n { instructions: INSTRUCTIONS },\n );\n for (const tool of TOOLS) {\n server.registerTool(\n tool.name,\n { description: tool.description, inputSchema: tool.schema },\n (args: Record<string, unknown>): CallToolResult => {\n try {\n const { carnet, resolver } = open();\n const sessionId = resolver.resolve(args.session as string | undefined);\n const out = tool.run(carnet, sessionId, args);\n return { content: [{ type: 'text', text: out.text }], structuredContent: out.data };\n } catch (error) {\n if (error instanceof CarnetError) return errorResult(error);\n throw error;\n }\n },\n );\n }\n return server;\n}\n\nexport interface ServeCarnetOptions extends OpenCarnetOptions {\n carnet?: Carnet;\n ppid?: number;\n}\n\nexport function serveCarnet(options: ServeCarnetOptions = {}): StdioServerHandle {\n const carnet = options.carnet ?? (() => openCarnet(options));\n return serveStdio(\n () => createCarnetServer({ carnet, env: options.env, ppid: options.ppid, cwd: options.cwd }),\n { onerror: (error) => console.error(`[carnet] ${error.message}`) },\n );\n}\n"],"mappings":";;;;;;AAAA,MAAa,eAAe;;;;;;;;;;;;;;;;;;ACI5B,MAAM,UAAU;AAchB,SAAgB,sBAAsB,EACpC,QACA,MAAM,QAAQ,KACd,OAAO,QAAQ,MACf,MAAM,QAAQ,IAAI,GAClB,OAAO,SAAS,YAAY,KACc;CAG1C,SAAS,aAAqB;EAC5B,MAAM,SAAS,OAAO,SAAS,cAAc,KAAK,IAAI,IAAI;EAC1D,IAAI,QAAQ,OAAO,OAAO;EAC1B,MAAM,kBAAkB,KAAK,yBAAyB,GAAG;EACzD,IAAI,iBAAiB,OAAO,OAAO,SAAS,OAAO,iBAAiB,GAAG,CAAC,CAAC;EACzE,MAAM,IAAI,YACR,cACA,qBAAqB,KAAK,YAAY,4EACxC;CACF;CAEA,SAAS,gBAAgB,UAA0B;EACjD,IAAI;GACF,OAAO,OAAO,SAAS,KAAK,QAAQ,CAAC,CAAC;EACxC,SAAS,OAAO;GACd,IAAI,EAAE,iBAAiB,gBAAgB,MAAM,SAAS,qBAAqB,MAAM;GAEjF,IAAI,QAAQ,KAAK,QAAQ,GAAG,OAAO,OAAO,SAAS,OAAO,UAAU,GAAG,CAAC,CAAC;GACzE,MAAM;EACR;CACF;CAEA,OAAO,EACL,QAAQ,UAAU;EAChB,MAAM,KAAK,WAAW,gBAAgB,QAAQ,IAAI,WAAW;EAC7D,OAAO,SAAS,MAAM,EAAE;EACxB,OAAO;CACT,EACF;AACF;;ACjCA,SAAS,WACP,YACwB;CACxB,OAAO;AACT;AAEA,MAAM,UAAU,E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Aa,OAAO,YAAY,KAAK;GAC1D,MAAM;EACR;CACF,CACF;CAEF,OAAO;AACT;AAOA,SAAgB,YAAY,UAA8B,CAAC,GAAsB;CAC/E,MAAM,SAAS,QAAQ,iBAAiB,WAAW,OAAO;CAC1D,OAAO,iBACC,mBAAmB;EAAE;EAAQ,KAAK,QAAQ;EAAK,MAAM,QAAQ;EAAM,KAAK,QAAQ;CAAI,CAAC,GAC3F,EAAE,UAAU,UAAU,QAAQ,MAAM,YAAY,MAAM,SAAS,EAAE,CACnE;AACF"}
1
+ {"version":3,"file":"mcp.mjs","names":[],"sources":["../src/mcp/instructions.ts","../src/mcp/session.ts","../src/mcp/tools.ts","../src/mcp/server.ts"],"sourcesContent":["export const INSTRUCTIONS = `Carnet holds the forks, the \"On the table\" line, sessions, the journal and the group memory that the \\`rucher\\` CLI renders. The session is resolved automatically; pass \\`session\\` only to target another one. The workflow rules are in the system prompt and the rucher skill: load the skill before dispatching, applying or reviewing forks.\n\nWhich tool, when:\n- Dispatch: agent_start, then launch the fork in a later message.\n- Each step of a fork's work: agent_step (answered, applying, applied, tested, committed, dropped).\n- Main agent working on something else: table_set, table_clear.\n- Other moves: agent_update, agent_drop, queue_reorder. Recall: agent_list, log_read, session_resume_info, session_list.\n- Memory: note_list before an approach, note_add and note_drop at the end of a step (main agent), note_cite when a note changed what you did.\n- Session: session_new when the human names it, session_drop only when asked.\n- Fork: agent_update (running, short note) at progress, agent_done last.\n\nStatuses (the NEXT action): running ⏳ · discussing 💬 · answer ❓ · review 👀 · apply 📥 · test 🧪 · commit ✅ · branch 🌿. Notes and table text: under 60 characters, no paths, no backticks.`;\n","import type { Carnet } from '../carnet.ts';\nimport { CarnetError } from '../errors.ts';\nimport { DEFAULT_HOST, type Host, hostById } from '../hosts/host.ts';\n\nconst FULL_ID = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;\n\nexport interface SessionResolverOptions {\n carnet: Carnet;\n env?: NodeJS.ProcessEnv | undefined;\n ppid?: number | undefined;\n cwd?: string | undefined;\n host?: Host | undefined;\n}\n\nexport interface SessionResolver {\n resolve(override?: string): string;\n}\n\nexport function createSessionResolver({\n carnet,\n env = process.env,\n ppid = process.ppid,\n cwd = process.cwd(),\n host = hostById(DEFAULT_HOST),\n}: SessionResolverOptions): SessionResolver {\n // Not cached: after --continue or the resume picker, the server env keeps a provisional\n // startup id, and the hook that records the real one can arrive after the server starts.\n function resolveOwn(): string {\n const hooked = carnet.sessions.byHostProcess(host.id, ppid);\n if (hooked) return hooked.id;\n const fromEnvironment = host.sessionIdFromEnvironment(env);\n if (fromEnvironment) return carnet.sessions.ensure(fromEnvironment, cwd).id;\n throw new CarnetError(\n 'NO_SESSION',\n `Cannot tell which ${host.displayName} session this is: pass \\`session\\`, or install the rucher SessionStart hook`,\n );\n }\n\n function resolveOverride(override: string): string {\n try {\n return carnet.sessions.find(override).id;\n } catch (error) {\n if (!(error instanceof CarnetError) || error.code !== 'SESSION_NOT_FOUND') throw error;\n // A full session id the hook never recorded still gets its row.\n if (FULL_ID.test(override)) return carnet.sessions.ensure(override, cwd).id;\n throw error;\n }\n }\n\n return {\n resolve(override) {\n const id = override ? resolveOverride(override) : resolveOwn();\n carnet.sessions.touch(id);\n return id;\n },\n };\n}\n","import { copyFileSync, existsSync, mkdirSync } from 'node:fs';\nimport { resolve } from 'node:path';\nimport * as z from 'zod/v4';\nimport type { Carnet } from '../carnet.ts';\nimport { EVENT_TYPES } from '../events.ts';\nimport { reportPathFor, reportsDirectoryOf } from '../group/locate.ts';\nimport { hostById } from '../hosts/host.ts';\nimport { memoryHalfLife, type Note, NOTE_KINDS } from '../notes.ts';\nimport { formatEventLine, resumeContext, sessionLabel } from '../resume.ts';\nimport { EMOJI, OPEN_AGENT_STATUSES, USER_ACTION_STATUSES } from '../status/model.ts';\nimport { renderAgentLine, renderTableLine } from '../status/render.ts';\nimport { AGENT_STEPS, stepAgent } from '../steps.ts';\n\nexport interface ToolOutput {\n text: string;\n}\n\nexport interface ToolDefinition<Schema extends z.ZodObject = z.ZodObject> {\n name: string;\n description: string;\n schema: Schema;\n run: (carnet: Carnet, sessionId: string, args: z.infer<Schema>) => ToolOutput;\n}\n\nfunction defineTool<Schema extends z.ZodObject>(\n definition: ToolDefinition<Schema>,\n): ToolDefinition<Schema> {\n return definition;\n}\n\nconst session = z\n .string()\n .optional()\n .describe('Session to target (name, id or id prefix). Omit for the current session.');\n\nconst agentName = z.string().min(1).describe('Short agent name, no paths');\n\nconst agentStart = defineTool({\n name: 'agent_start',\n description:\n 'Main agent only. Register a fork before dispatching it (launch it in a later message). Logs `started`. The result gives the report destination in the group, where agent_done copies the report.',\n schema: z.object({\n name: agentName,\n task: z.string().min(1).describe('One-line task given to the fork'),\n base_commit: z.string().optional().describe('Commit the fork starts from'),\n worktree: z.string().optional().describe('Worktree path when the fork has one'),\n session,\n }),\n run: (carnet, sessionId, args) => {\n const agent = carnet.agents.start(sessionId, {\n name: args.name,\n task: args.task,\n baseCommit: args.base_commit,\n worktree: args.worktree,\n });\n mkdirSync(reportsDirectoryOf(carnet.group), { recursive: true });\n const reportDestination = reportPathFor(carnet.group, agent.name);\n return {\n text: `${EMOJI.running} ${agent.name} started in group ${carnet.group.name}\\nReport destination: ${reportDestination}`,\n };\n },\n});\n\nconst agentUpdate = defineTool({\n name: 'agent_update',\n description:\n \"Set an agent's status and note. Forks: status running at progress. Main agent: only for moves agent_step does not cover.\",\n schema: z.object({\n name: agentName,\n status: z.enum(OPEN_AGENT_STATUSES).describe('Next action: running means the fork is working'),\n note: z.string().optional().describe('Under 60 characters, no paths, no backticks'),\n report_path: z.string().optional().describe('New absolute path of the report, when it moved'),\n session,\n }),\n run: (carnet, sessionId, args) => {\n const agent = carnet.agents.update(sessionId, args.name, {\n status: args.status,\n note: args.note,\n reportPath: args.report_path,\n });\n const text = renderAgentLine({\n name: agent.name,\n status: agent.status,\n emoji: agent.status === 'closed' ? '' : EMOJI[agent.status],\n note: agent.note,\n });\n return { text };\n },\n});\n\nfunction copyReport(carnet: Carnet, name: string, reportPath: string): string {\n const destination = reportPathFor(carnet.group, name);\n if (resolve(reportPath) === destination || !existsSync(reportPath)) return reportPath;\n mkdirSync(reportsDirectoryOf(carnet.group), { recursive: true });\n copyFileSync(reportPath, destination);\n return destination;\n}\n\nconst agentDone = defineTool({\n name: 'agent_done',\n description:\n 'Forks call this as their LAST tool action, then reply with one line that carries no results. Copies the report to the group report destination and marks the agent ❓ answer (has_questions) or 👀 review once the fork stops.',\n schema: z.object({\n name: agentName,\n report_path: z.string().min(1).describe('Absolute path of the markdown report'),\n has_questions: z.boolean().describe('true when the report asks the human something'),\n session,\n }),\n run: (carnet, sessionId, args) => {\n const agent = carnet.agents.finish(sessionId, args.name, {\n reportPath: copyReport(carnet, args.name, args.report_path),\n hasQuestions: args.has_questions,\n });\n const outcome = args.has_questions\n ? `${EMOJI.answer} ${agent.name} needs answers`\n : `${EMOJI.review} ${agent.name} ready for review`;\n const text =\n agent.status === 'running'\n ? `${outcome} once you stop; reply now with one line that carries no results`\n : outcome;\n return { text };\n },\n});\n\nconst agentDrop = defineTool({\n name: 'agent_drop',\n description:\n 'Main agent only. Close an agent once its work is committed or abandoned. It leaves the status view; history stays in the journal.',\n schema: z.object({\n name: agentName,\n reason: z.string().optional().describe('Why it is closed, for the journal'),\n session,\n }),\n run: (carnet, sessionId, args) => {\n const agent = carnet.agents.drop(sessionId, args.name, args.reason);\n return { text: `${agent.name} closed` };\n },\n});\n\nconst agentList = defineTool({\n name: 'agent_list',\n description: 'List the open agents of the session with status, note, task and report path.',\n schema: z.object({ session }),\n run: (carnet, sessionId) => {\n const agents = carnet.agents.list(sessionId);\n const lines = agents.map((agent) => {\n const emoji = agent.status === 'closed' ? '' : EMOJI[agent.status];\n const note = agent.note ? ` — ${agent.note}` : '';\n const report = agent.reportPath ? ` (report: ${agent.reportPath})` : '';\n return `${emoji} ${agent.name} [${agent.status}]${note}${report}`;\n });\n return { text: lines.length ? lines.join('\\n') : 'no open agents' };\n },\n});\n\nconst queueReorder = defineTool({\n name: 'queue_reorder',\n description:\n \"Main agent only. Set the order of the 'Waiting on you' list. Named agents come first in the given order, the others follow the default order (answer, review, rest).\",\n schema: z.object({\n names: z.array(agentName).min(1).describe('Agent names in handling order'),\n session,\n }),\n run: (carnet, sessionId, args) => {\n carnet.agents.reorderQueue(sessionId, args.names);\n const view = carnet.status.view(carnet.sessions.require(sessionId));\n const order = view.waiting.map((line) => line.name).join(', ');\n return {\n text: order ? `Waiting order: ${order}` : 'nothing waiting',\n };\n },\n});\n\nconst tableSet = defineTool({\n name: 'table_set',\n description:\n \"Main agent only. Set the 'On the table' line: what the main agent is handling now. main_working=true while you work yourself (⚙️); otherwise the status of the next human action.\",\n schema: z.object({\n text: z.string().min(1).describe('Under 60 characters, no paths, no backticks'),\n main_working: z\n .boolean()\n .optional()\n .describe('Omitted: false when a status is given, else unchanged'),\n status: z\n .enum(USER_ACTION_STATUSES)\n .optional()\n .describe('Next human action when main_working is false; defaults to discussing'),\n session,\n }),\n run: (carnet, sessionId, args) => {\n const item = carnet.table.set(sessionId, {\n text: args.text,\n mainWorking: args.main_working,\n status: args.status,\n });\n return { text: renderTableLine(item) };\n },\n});\n\nconst agentStep = defineTool({\n name: 'agent_step',\n description:\n \"Main agent only. One call per step of a fork's work: logs the event, moves the agent to the next human action and keeps the 'On the table' line in sync. answered → apply, applying → ⚙️ table line, applied → test, tested → commit, committed (commit required) → closed, dropped (note = reason) → closed.\",\n schema: z.object({\n name: agentName,\n step: z.enum(AGENT_STEPS),\n commit: z.string().optional().describe('Commit sha, for committed'),\n note: z.string().optional().describe('Short note for the journal; the reason for dropped'),\n next: z\n .enum(OPEN_AGENT_STATUSES)\n .optional()\n .describe('Override the next status, e.g. running when the fork resumes'),\n session,\n }),\n run: (carnet, sessionId, args) => ({ text: stepAgent(carnet, sessionId, args) }),\n});\n\nconst tableClear = defineTool({\n name: 'table_clear',\n description: \"Main agent only. Empty the 'On the table' line.\",\n schema: z.object({ session }),\n run: (carnet, sessionId) => {\n carnet.table.clear(sessionId);\n return { text: 'On the table cleared' };\n },\n});\n\nconst logEvent = defineTool({\n name: 'log_event',\n description:\n 'Append a journal event. agent_start, agent_done, agent_drop and agent_step already log theirs: use this only for events outside them.',\n schema: z.object({\n type: z.enum(EVENT_TYPES),\n agent: z.string().optional().describe('Agent concerned'),\n commit: z.string().optional().describe('Commit sha'),\n link: z.string().optional().describe('Report path or URL'),\n note: z.string().optional(),\n session,\n }),\n run: (carnet, sessionId, args) => {\n const event = carnet.events.log(sessionId, {\n type: args.type,\n agent: args.agent,\n commit: args.commit,\n link: args.link,\n note: args.note,\n });\n const parts = ['logged', event.type, event.agent, event.commit].filter(Boolean);\n return { text: parts.join(' ') };\n },\n});\n\nconst sessionName = z.string().trim().min(1).describe('Short session name, used by rucher resume');\n\nconst sessionNew = defineTool({\n name: 'session_new',\n description:\n 'Name the current session (or rename it) so it can be resumed later with `rucher resume <name>`. Makes it an active session, kept by the cleanups.',\n schema: z.object({\n name: sessionName,\n purpose: z.string().optional().describe('One line: what this session is for'),\n session,\n }),\n run: (carnet, sessionId, args) => {\n const named = carnet.sessions.name(sessionId, args.name, args.purpose);\n return {\n text: `Session named ${named.name}. ${hostById(named.host).renameInstruction(named.name ?? args.name)}`,\n };\n },\n});\n\nconst sessionList = defineTool({\n name: 'session_list',\n description:\n \"List the group's sessions, most recently active first. Temp and archived ones are hidden unless asked.\",\n schema: z.object({\n include_temp: z.boolean().optional(),\n include_archived: z.boolean().optional(),\n session,\n }),\n run: (carnet, sessionId, args) => {\n const sessions = carnet.sessions.list({\n includeTemp: args.include_temp,\n includeArchived: args.include_archived,\n });\n const lines = sessions.map((listed) => {\n const current = listed.id === sessionId ? ' (current)' : '';\n return `${sessionLabel(listed)} [${listed.kind}, ${listed.status}]${current}`;\n });\n return { text: lines.length ? lines.join('\\n') : 'no sessions' };\n },\n});\n\nconst sessionDrop = defineTool({\n name: 'session_drop',\n description:\n 'Main agent only. Archive a session by name, id or id prefix: its open agents are closed and it leaves the lists. History stays in the journal.',\n schema: z.object({\n name: z.string().trim().min(1).describe('Session name, id or id prefix'),\n session,\n }),\n run: (carnet, _sessionId, args) => {\n const dropped = carnet.sessions.drop(carnet.sessions.find(args.name).id);\n return { text: `Session ${sessionLabel(dropped)} archived` };\n },\n});\n\nconst sessionResumeInfo = defineTool({\n name: 'session_resume_info',\n description:\n 'What a session was doing: its status view and last events, plus the command to resume it. Defaults to the current session.',\n schema: z.object({\n name: z.string().trim().min(1).optional().describe('Session name, id or id prefix'),\n session,\n }),\n run: (carnet, sessionId, args) => {\n const target = args.name ? carnet.sessions.find(args.name) : carnet.sessions.require(sessionId);\n const resume = `rucher resume ${target.name ?? target.id}`;\n return {\n text: `${resumeContext(carnet, target)}\\n\\nResume with: ${resume}`,\n };\n },\n});\n\nconst logRead = defineTool({\n name: 'log_read',\n description: 'Read the last journal events of the session, oldest first.',\n schema: z.object({\n limit: z.number().int().min(1).max(200).optional().describe('Number of events, default 20'),\n session,\n }),\n run: (carnet, sessionId, args) => {\n const events = carnet.events.read(sessionId, args.limit ?? 20);\n return {\n text: events.length ? events.map(formatEventLine).join('\\n') : 'no events yet',\n };\n },\n});\n\nconst noteId = z.number().int().positive().describe('Note id, as shown by note_list (#14 is 14)');\n\nexport function noteLine(note: Note): string {\n const repos = note.repos.length ? ` [${note.repos.join(', ')}]` : '';\n return `#${note.id} ${note.kind}${repos} ${note.text}`;\n}\n\nconst noteAdd = defineTool({\n name: 'note_add',\n description:\n \"Main agent only. Record what the group learned (learning), decided (decision) or tried and gave up (dead_end), at the end of a step. One claim under 200 characters with its reason, no markdown. `repos` only when it applies to some of the group's repos; omit it for a general note. A result listing similar notes means a likely duplicate: drop or replace instead of piling up.\",\n schema: z.object({\n kind: z.enum(NOTE_KINDS),\n text: z.string().min(1).describe('One claim with its reason, under 200 characters'),\n repos: z\n .array(z.string().min(1))\n .optional()\n .describe('Repo names of the group; omit for a general note'),\n agent: z.string().optional().describe('Fork the note comes from'),\n session,\n }),\n run: (carnet, sessionId, args) => {\n const { note, similar } = carnet.notes.add({\n kind: args.kind,\n text: args.text,\n repos: args.repos,\n agent: args.agent,\n session: sessionId,\n });\n const warning = similar.length\n ? `\\nSimilar active notes, possible duplicate:\\n${similar.map(noteLine).join('\\n')}`\n : '';\n return { text: `added ${noteLine(note)}${warning}` };\n },\n});\n\nconst noteList = defineTool({\n name: 'note_list',\n description:\n \"The group's active notes, dead ends first, then decisions, then learnings, most cited first. Filter by kind, repo, general (notes without repo) or a substring query. Check it before trying an approach.\",\n schema: z.object({\n kind: z.enum(NOTE_KINDS).optional(),\n repo: z.string().optional().describe('Notes of this repo'),\n general: z.boolean().optional().describe('Only notes without repo'),\n query: z.string().optional().describe('Substring of the text'),\n include_dropped: z.boolean().optional(),\n session,\n }),\n run: (carnet, _sessionId, args) => {\n const notes = carnet.notes.list({\n kind: args.kind,\n repo: args.repo,\n general: args.general,\n query: args.query,\n includeDropped: args.include_dropped,\n halfLifeDays: memoryHalfLife(process.env['RUCHER_MEMORY_HALF_LIFE_DAYS']),\n });\n const lines = notes.map(\n (note) => `${noteLine(note)}${note.droppedAt ? ` (dropped: ${note.droppedReason})` : ''}`,\n );\n return { text: lines.length ? lines.join('\\n') : 'no notes' };\n },\n});\n\nconst noteDrop = defineTool({\n name: 'note_drop',\n description:\n 'Main agent only. Close a note that proved wrong or outdated: it stays in the history, marked dropped with the reason. Pass replaced_by when a corrected note replaces it.',\n schema: z.object({\n id: noteId,\n reason: z.string().min(1).describe('Why the note is no longer true'),\n replaced_by: z.number().int().positive().optional().describe('Id of the note replacing it'),\n session,\n }),\n run: (carnet, sessionId, args) => {\n const note = carnet.notes.drop(args.id, {\n reason: args.reason,\n replacedBy: args.replaced_by,\n session: sessionId,\n });\n const replaced = note.replacedBy ? `, replaced by #${note.replacedBy}` : '';\n return { text: `dropped #${note.id}${replaced}` };\n },\n});\n\nconst noteCite = defineTool({\n name: 'note_cite',\n description:\n 'Cite a note that changed what you did (avoided, followed or adjusted something), with what it changed. Never for a plain read. Citations decide which notes come first.',\n schema: z.object({\n id: noteId,\n why: z.string().min(1).describe('What the note changed, short'),\n agent: z.string().optional().describe('Fork citing it, when not the main agent'),\n session,\n }),\n run: (carnet, sessionId, args) => {\n const citation = carnet.notes.cite(args.id, {\n why: args.why,\n agent: args.agent,\n session: sessionId,\n });\n return { text: `cited #${citation.note}: ${citation.why}` };\n },\n});\n\nexport const TOOLS: readonly ToolDefinition[] = [\n agentStart,\n agentUpdate,\n agentDone,\n agentDrop,\n agentStep,\n agentList,\n queueReorder,\n tableSet,\n tableClear,\n logEvent,\n logRead,\n sessionNew,\n sessionList,\n sessionDrop,\n sessionResumeInfo,\n noteAdd,\n noteList,\n noteDrop,\n noteCite,\n] as readonly ToolDefinition[];\n","import { type CallToolResult, McpServer } from '@modelcontextprotocol/server';\nimport { serveStdio, type StdioServerHandle } from '@modelcontextprotocol/server/stdio';\nimport type { Carnet } from '../carnet.ts';\nimport { openCarnet, type OpenCarnetOptions } from '../carnet.ts';\nimport { CarnetError } from '../errors.ts';\nimport { INSTRUCTIONS } from './instructions.ts';\nimport {\n createSessionResolver,\n type SessionResolver,\n type SessionResolverOptions,\n} from './session.ts';\nimport { TOOLS } from './tools.ts';\n\nexport const SERVER_NAME = 'carnet';\nexport const SERVER_VERSION = '0.0.0';\n\nexport interface CarnetServerOptions extends Omit<SessionResolverOptions, 'carnet'> {\n carnet: Carnet | (() => Carnet);\n}\n\nfunction errorResult(error: CarnetError): CallToolResult {\n return { isError: true, content: [{ type: 'text', text: `${error.code}: ${error.message}` }] };\n}\n\nexport function createCarnetServer(options: CarnetServerOptions): McpServer {\n let carnet: Carnet | undefined;\n let resolver: SessionResolver | undefined;\n const open = (): { carnet: Carnet; resolver: SessionResolver } => {\n carnet ??= typeof options.carnet === 'function' ? options.carnet() : options.carnet;\n resolver ??= createSessionResolver({ ...options, carnet });\n return { carnet, resolver };\n };\n const server = new McpServer(\n { name: SERVER_NAME, version: SERVER_VERSION },\n { instructions: INSTRUCTIONS },\n );\n for (const tool of TOOLS) {\n server.registerTool(\n tool.name,\n { description: tool.description, inputSchema: tool.schema },\n (args: Record<string, unknown>): CallToolResult => {\n try {\n const { carnet, resolver } = open();\n const sessionId = resolver.resolve(args.session as string | undefined);\n const out = tool.run(carnet, sessionId, args);\n return { content: [{ type: 'text', text: out.text }] };\n } catch (error) {\n if (error instanceof CarnetError) return errorResult(error);\n throw error;\n }\n },\n );\n }\n return server;\n}\n\nexport interface ServeCarnetOptions extends OpenCarnetOptions {\n carnet?: Carnet;\n ppid?: number;\n}\n\nexport function serveCarnet(options: ServeCarnetOptions = {}): StdioServerHandle {\n const carnet = options.carnet ?? (() => openCarnet(options));\n return serveStdio(\n () => createCarnetServer({ carnet, env: options.env, ppid: options.ppid, cwd: options.cwd }),\n { onerror: (error) => console.error(`[carnet] ${error.message}`) },\n );\n}\n"],"mappings":";;;;;;;AAAA,MAAa,eAAe;;;;;;;;;;;;;ACI5B,MAAM,UAAU;AAchB,SAAgB,sBAAsB,EACpC,QACA,MAAM,QAAQ,KACd,OAAO,QAAQ,MACf,MAAM,QAAQ,IAAI,GAClB,OAAO,SAAS,YAAY,KACc;CAG1C,SAAS,aAAqB;EAC5B,MAAM,SAAS,OAAO,SAAS,cAAc,KAAK,IAAI,IAAI;EAC1D,IAAI,QAAQ,OAAO,OAAO;EAC1B,MAAM,kBAAkB,KAAK,yBAAyB,GAAG;EACzD,IAAI,iBAAiB,OAAO,OAAO,SAAS,OAAO,iBAAiB,GAAG,CAAC,CAAC;EACzE,MAAM,IAAI,YACR,cACA,qBAAqB,KAAK,YAAY,4EACxC;CACF;CAEA,SAAS,gBAAgB,UAA0B;EACjD,IAAI;GACF,OAAO,OAAO,SAAS,KAAK,QAAQ,CAAC,CAAC;EACxC,SAAS,OAAO;GACd,IAAI,EAAE,iBAAiB,gBAAgB,MAAM,SAAS,qBAAqB,MAAM;GAEjF,IAAI,QAAQ,KA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