@rucher/carnet 0.2.0-beta.1 → 0.2.0-beta.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/mcp.mjs CHANGED
@@ -1,26 +1,22 @@
1
- import { C as renderTableLine, Ft as EVENT_TYPES, Mt as USER_ACTION_STATUSES, N as NOTE_KINDS, Ot as EMOJI, Rt as CarnetError, _ as renderAgentLine, a as sessionLabel, i as resumeContext, jt as OPEN_AGENT_STATUSES, lt as hostById, nt as reportsDirectoryOf, r as formatEventLine, s as openCarnet, st as DEFAULT_HOST, tt as reportPathFor, z as memoryHalfLife } from "./resume-D2FFakCl.mjs";
2
- import { mkdirSync } from "node:fs";
1
+ import { B as memoryHalfLife, E as renderTableLine, Jt as reportsDirectory, P as NOTE_KINDS, a as formatEventLine, b as renderAgentLine, gn as CarnetError, gt as hostById, l as openCarnet, ln as OPEN_AGENT_STATUSES, mt as DEFAULT_HOST, n as stepAgent, o as resumeContext, on as EMOJI, pn as EVENT_TYPES, qt as reportPath, s as sessionLabel, t as AGENT_STEPS, un as USER_ACTION_STATUSES } from "./steps-U_Ge5YFh.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"),
@@ -63,26 +59,21 @@ const agentStart = defineTool({
63
59
  session
64
60
  }),
65
61
  run: (carnet, sessionId, args) => {
62
+ const group = carnet.group;
66
63
  const agent = carnet.agents.start(sessionId, {
67
64
  name: args.name,
68
65
  task: args.task,
69
66
  baseCommit: args.base_commit,
70
67
  worktree: args.worktree
71
68
  });
72
- mkdirSync(reportsDirectoryOf(carnet.group), { recursive: true });
73
- const reportDestination = reportPathFor(carnet.group, agent.name);
74
- return {
75
- text: `${EMOJI.running} ${agent.name} started in group ${carnet.group.name}\nReport destination: ${reportDestination}`,
76
- data: {
77
- agent,
78
- reportDestination
79
- }
80
- };
69
+ if (!group) return { text: `${EMOJI.running} ${agent.name} started outside any group\nNo report destination: the report stays where the fork writes it` };
70
+ mkdirSync(reportsDirectory(group), { recursive: true });
71
+ return { text: `${EMOJI.running} ${agent.name} started in group ${group.name}\nReport destination: ${reportPath(group, agent.name)}` };
81
72
  }
82
73
  });
83
74
  const agentUpdate = defineTool({
84
75
  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.",
76
+ description: "Set an agent's status and note. Forks: status running at progress. Main agent: only for moves agent_step does not cover.",
86
77
  schema: z.object({
87
78
  name: agentName,
88
79
  status: z.enum(OPEN_AGENT_STATUSES).describe("Next action: running means the fork is working"),
@@ -96,20 +87,25 @@ const agentUpdate = defineTool({
96
87
  note: args.note,
97
88
  reportPath: args.report_path
98
89
  });
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
- };
90
+ return { text: renderAgentLine({
91
+ name: agent.name,
92
+ status: agent.status,
93
+ emoji: agent.status === "closed" ? "" : EMOJI[agent.status],
94
+ note: agent.note
95
+ }) };
108
96
  }
109
97
  });
98
+ function copyReport(carnet, name, reportFile) {
99
+ if (!carnet.group) return reportFile;
100
+ const destination = reportPath(carnet.group, name);
101
+ if (resolve(reportFile) === destination || !existsSync(reportFile)) return reportFile;
102
+ mkdirSync(reportsDirectory(carnet.group), { recursive: true });
103
+ copyFileSync(reportFile, destination);
104
+ return destination;
105
+ }
110
106
  const agentDone = defineTool({
111
107
  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.",
108
+ 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
109
  schema: z.object({
114
110
  name: agentName,
115
111
  report_path: z.string().min(1).describe("Absolute path of the markdown report"),
@@ -118,14 +114,11 @@ const agentDone = defineTool({
118
114
  }),
119
115
  run: (carnet, sessionId, args) => {
120
116
  const agent = carnet.agents.finish(sessionId, args.name, {
121
- reportPath: args.report_path,
117
+ reportPath: copyReport(carnet, args.name, args.report_path),
122
118
  hasQuestions: args.has_questions
123
119
  });
124
120
  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
- };
121
+ return { text: agent.status === "running" ? `${outcome} once you stop; reply now with one line that carries no results` : outcome };
129
122
  }
130
123
  });
131
124
  const agentDrop = defineTool({
@@ -137,11 +130,7 @@ const agentDrop = defineTool({
137
130
  session
138
131
  }),
139
132
  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
- };
133
+ return { text: `${carnet.agents.drop(sessionId, args.name, args.reason).name} closed` };
145
134
  }
146
135
  });
147
136
  const agentList = defineTool({
@@ -149,17 +138,13 @@ const agentList = defineTool({
149
138
  description: "List the open agents of the session with status, note, task and report path.",
150
139
  schema: z.object({ session }),
151
140
  run: (carnet, sessionId) => {
152
- const agents = carnet.agents.list(sessionId);
153
- const lines = agents.map((agent) => {
141
+ const lines = carnet.agents.list(sessionId).map((agent) => {
154
142
  const emoji = agent.status === "closed" ? "" : EMOJI[agent.status];
155
143
  const note = agent.note ? ` — ${agent.note}` : "";
156
144
  const report = agent.reportPath ? ` (report: ${agent.reportPath})` : "";
157
145
  return `${emoji} ${agent.name} [${agent.status}]${note}${report}`;
158
146
  });
159
- return {
160
- text: lines.length ? lines.join("\n") : "no open agents",
161
- data: { agents }
162
- };
147
+ return { text: lines.length ? lines.join("\n") : "no open agents" };
163
148
  }
164
149
  });
165
150
  const queueReorder = defineTool({
@@ -171,20 +156,16 @@ const queueReorder = defineTool({
171
156
  }),
172
157
  run: (carnet, sessionId, args) => {
173
158
  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
- };
159
+ const order = carnet.status.view(carnet.sessions.require(sessionId)).waiting.map((line) => line.name).join(", ");
160
+ return { text: order ? `Waiting order: ${order}` : "nothing waiting" };
180
161
  }
181
162
  });
182
163
  const tableSet = defineTool({
183
164
  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.",
165
+ 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
166
  schema: z.object({
186
167
  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"),
168
+ main_working: z.boolean().optional().describe("Omitted: false when a status is given, else unchanged"),
188
169
  status: z.enum(USER_ACTION_STATUSES).optional().describe("Next human action when main_working is false; defaults to discussing"),
189
170
  session
190
171
  }),
@@ -194,12 +175,22 @@ const tableSet = defineTool({
194
175
  mainWorking: args.main_working,
195
176
  status: args.status
196
177
  });
197
- return {
198
- text: renderTableLine(item),
199
- data: { table: item }
200
- };
178
+ return { text: renderTableLine(item) };
201
179
  }
202
180
  });
181
+ const agentStep = defineTool({
182
+ name: "agent_step",
183
+ 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.",
184
+ schema: z.object({
185
+ name: agentName,
186
+ step: z.enum(AGENT_STEPS),
187
+ commit: z.string().optional().describe("Commit sha, for committed"),
188
+ note: z.string().optional().describe("Short note for the journal; the reason for dropped"),
189
+ next: z.enum(OPEN_AGENT_STATUSES).optional().describe("Override the next status, e.g. running when the fork resumes"),
190
+ session
191
+ }),
192
+ run: (carnet, sessionId, args) => ({ text: stepAgent(carnet, sessionId, args) })
193
+ });
203
194
  const tableClear = defineTool({
204
195
  name: "table_clear",
205
196
  description: "Main agent only. Empty the 'On the table' line.",
@@ -211,7 +202,7 @@ const tableClear = defineTool({
211
202
  });
212
203
  const logEvent = defineTool({
213
204
  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).",
205
+ 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
206
  schema: z.object({
216
207
  type: z.enum(EVENT_TYPES),
217
208
  agent: z.string().optional().describe("Agent concerned"),
@@ -228,15 +219,12 @@ const logEvent = defineTool({
228
219
  link: args.link,
229
220
  note: args.note
230
221
  });
231
- return {
232
- text: [
233
- "logged",
234
- event.type,
235
- event.agent,
236
- event.commit
237
- ].filter(Boolean).join(" "),
238
- data: { event }
239
- };
222
+ return { text: [
223
+ "logged",
224
+ event.type,
225
+ event.agent,
226
+ event.commit
227
+ ].filter(Boolean).join(" ") };
240
228
  }
241
229
  });
242
230
  const sessionName = z.string().trim().min(1).describe("Short session name, used by rucher resume");
@@ -250,10 +238,7 @@ const sessionNew = defineTool({
250
238
  }),
251
239
  run: (carnet, sessionId, args) => {
252
240
  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
- };
241
+ return { text: `Session named ${named.name}. ${hostById(named.host).renameInstruction(named.name ?? args.name)}` };
257
242
  }
258
243
  });
259
244
  const sessionList = defineTool({
@@ -265,18 +250,14 @@ const sessionList = defineTool({
265
250
  session
266
251
  }),
267
252
  run: (carnet, sessionId, args) => {
268
- const sessions = carnet.sessions.list({
253
+ const lines = carnet.sessions.list({
269
254
  includeTemp: args.include_temp,
270
255
  includeArchived: args.include_archived
271
- });
272
- const lines = sessions.map((listed) => {
256
+ }).map((listed) => {
273
257
  const current = listed.id === sessionId ? " (current)" : "";
274
258
  return `${sessionLabel(listed)} [${listed.kind}, ${listed.status}]${current}`;
275
259
  });
276
- return {
277
- text: lines.length ? lines.join("\n") : "no sessions",
278
- data: { sessions }
279
- };
260
+ return { text: lines.length ? lines.join("\n") : "no sessions" };
280
261
  }
281
262
  });
282
263
  const sessionDrop = defineTool({
@@ -288,10 +269,7 @@ const sessionDrop = defineTool({
288
269
  }),
289
270
  run: (carnet, _sessionId, args) => {
290
271
  const dropped = carnet.sessions.drop(carnet.sessions.find(args.name).id);
291
- return {
292
- text: `Session ${sessionLabel(dropped)} archived`,
293
- data: { session: dropped }
294
- };
272
+ return { text: `Session ${sessionLabel(dropped)} archived` };
295
273
  }
296
274
  });
297
275
  const sessionResumeInfo = defineTool({
@@ -304,13 +282,7 @@ const sessionResumeInfo = defineTool({
304
282
  run: (carnet, sessionId, args) => {
305
283
  const target = args.name ? carnet.sessions.find(args.name) : carnet.sessions.require(sessionId);
306
284
  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
- };
285
+ return { text: `${resumeContext(carnet, target)}\n\nResume with: ${resume}` };
314
286
  }
315
287
  });
316
288
  const logRead = defineTool({
@@ -322,10 +294,7 @@ const logRead = defineTool({
322
294
  }),
323
295
  run: (carnet, sessionId, args) => {
324
296
  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
- };
297
+ return { text: events.length ? events.map(formatEventLine).join("\n") : "no events yet" };
329
298
  }
330
299
  });
331
300
  const noteId = z.number().int().positive().describe("Note id, as shown by note_list (#14 is 14)");
@@ -338,6 +307,7 @@ const TOOLS = [
338
307
  agentUpdate,
339
308
  agentDone,
340
309
  agentDrop,
310
+ agentStep,
341
311
  agentList,
342
312
  queueReorder,
343
313
  tableSet,
@@ -367,13 +337,7 @@ const TOOLS = [
367
337
  session: sessionId
368
338
  });
369
339
  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
- };
340
+ return { text: `added ${noteLine(note)}${warning}` };
377
341
  }
378
342
  }),
379
343
  defineTool({
@@ -388,19 +352,15 @@ const TOOLS = [
388
352
  session
389
353
  }),
390
354
  run: (carnet, _sessionId, args) => {
391
- const notes = carnet.notes.list({
355
+ const lines = carnet.notes.list({
392
356
  kind: args.kind,
393
357
  repo: args.repo,
394
358
  general: args.general,
395
359
  query: args.query,
396
360
  includeDropped: args.include_dropped,
397
361
  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
- };
362
+ }).map((note) => `${noteLine(note)}${note.droppedAt ? ` (dropped: ${note.droppedReason})` : ""}`);
363
+ return { text: lines.length ? lines.join("\n") : "no notes" };
404
364
  }
405
365
  }),
406
366
  defineTool({
@@ -419,10 +379,7 @@ const TOOLS = [
419
379
  session: sessionId
420
380
  });
421
381
  const replaced = note.replacedBy ? `, replaced by #${note.replacedBy}` : "";
422
- return {
423
- text: `dropped #${note.id}${replaced}`,
424
- data: { note }
425
- };
382
+ return { text: `dropped #${note.id}${replaced}` };
426
383
  }
427
384
  }),
428
385
  defineTool({
@@ -440,10 +397,7 @@ const TOOLS = [
440
397
  agent: args.agent,
441
398
  session: sessionId
442
399
  });
443
- return {
444
- text: `cited #${citation.note}: ${citation.why}`,
445
- data: { citation }
446
- };
400
+ return { text: `cited #${citation.note}: ${citation.why}` };
447
401
  }
448
402
  })
449
403
  ];
@@ -484,14 +438,10 @@ function createCarnetServer(options) {
484
438
  try {
485
439
  const { carnet, resolver } = open();
486
440
  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
- };
441
+ return { content: [{
442
+ type: "text",
443
+ text: tool.run(carnet, sessionId, args).text
444
+ }] };
495
445
  } catch (error) {
496
446
  if (error instanceof CarnetError) return errorResult(error);
497
447
  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 in group ${carnet.group.name}\\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,IA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,KAAK;EAAa,aAAa,KAAK;CAAO,IACzD,SAAkD;EACjD,IAAI;GACF,MAAM,EAAE,QAAQ,aAAa,KAAK;GAClC,MAAM,YAAY,SAAS,QAAQ,KAAK,OAA6B;GACrE,MAAM,MAAM,KAAK,IAAI,QAAQ,WAAW,IAAI;GAC5C,OAAO;IAAE,SAAS,CAAC;KAAE,MAAM;KAAQ,MAAM,IAAI;IAAK,CAAC;IAAG,mBAAmB,IAAI;GAAK;EACpF,SAAS,OAAO;GACd,IAAI,iBAAiB,aAAa,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 { reportPath, reportsDirectory } from '../paths.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 group = carnet.group;\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 if (!group) {\n return {\n text: `${EMOJI.running} ${agent.name} started outside any group\\nNo report destination: the report stays where the fork writes it`,\n };\n }\n mkdirSync(reportsDirectory(group), { recursive: true });\n return {\n text: `${EMOJI.running} ${agent.name} started in group ${group.name}\\nReport destination: ${reportPath(group, agent.name)}`,\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, reportFile: string): string {\n if (!carnet.group) return reportFile;\n const destination = reportPath(carnet.group, name);\n if (resolve(reportFile) === destination || !existsSync(reportFile)) return reportFile;\n mkdirSync(reportsDirectory(carnet.group), { recursive: true });\n copyFileSync(reportFile, 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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