@rucher/carnet 0.0.0-stage → 0.2.0-beta.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +20 -2
- package/dist/carnet-CsFtIv2C.d.mts +447 -0
- package/dist/carnet-CsFtIv2C.d.mts.map +1 -0
- package/dist/index.d.mts +91 -0
- package/dist/index.d.mts.map +1 -0
- package/dist/index.mjs +189 -0
- package/dist/index.mjs.map +1 -0
- package/dist/mcp.d.mts +40 -0
- package/dist/mcp.d.mts.map +1 -0
- package/dist/mcp.mjs +513 -0
- package/dist/mcp.mjs.map +1 -0
- package/dist/resume-CQRf2jIa.mjs +1764 -0
- package/dist/resume-CQRf2jIa.mjs.map +1 -0
- package/package.json +54 -3
package/dist/mcp.mjs
ADDED
|
@@ -0,0 +1,513 @@
|
|
|
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";
|
|
3
|
+
import { McpServer } from "@modelcontextprotocol/server";
|
|
4
|
+
import { serveStdio } from "@modelcontextprotocol/server/stdio";
|
|
5
|
+
import * as z from "zod/v4";
|
|
6
|
+
// 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
|
+
|
|
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.
|
|
17
|
+
|
|
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.`;
|
|
24
|
+
// src/mcp/session.ts
|
|
25
|
+
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
|
+
function createSessionResolver({ carnet, env = process.env, ppid = process.ppid, cwd = process.cwd(), host = hostById(DEFAULT_HOST) }) {
|
|
27
|
+
function resolveOwn() {
|
|
28
|
+
const hooked = carnet.sessions.byHostProcess(host.id, ppid);
|
|
29
|
+
if (hooked) return hooked.id;
|
|
30
|
+
const fromEnvironment = host.sessionIdFromEnvironment(env);
|
|
31
|
+
if (fromEnvironment) return carnet.sessions.ensure(fromEnvironment, cwd).id;
|
|
32
|
+
throw new CarnetError("NO_SESSION", `Cannot tell which ${host.displayName} session this is: pass \`session\`, or install the rucher SessionStart hook`);
|
|
33
|
+
}
|
|
34
|
+
function resolveOverride(override) {
|
|
35
|
+
try {
|
|
36
|
+
return carnet.sessions.find(override).id;
|
|
37
|
+
} catch (error) {
|
|
38
|
+
if (!(error instanceof CarnetError) || error.code !== "SESSION_NOT_FOUND") throw error;
|
|
39
|
+
if (FULL_ID.test(override)) return carnet.sessions.ensure(override, cwd).id;
|
|
40
|
+
throw error;
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
return { resolve(override) {
|
|
44
|
+
const id = override ? resolveOverride(override) : resolveOwn();
|
|
45
|
+
carnet.sessions.touch(id);
|
|
46
|
+
return id;
|
|
47
|
+
} };
|
|
48
|
+
}
|
|
49
|
+
// src/mcp/tools.ts
|
|
50
|
+
function defineTool(definition) {
|
|
51
|
+
return definition;
|
|
52
|
+
}
|
|
53
|
+
const session = z.string().optional().describe("Session to target (name, id or id prefix). Omit for the current session.");
|
|
54
|
+
const agentName = z.string().min(1).describe("Short agent name, no paths");
|
|
55
|
+
const agentStart = defineTool({
|
|
56
|
+
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.",
|
|
58
|
+
schema: z.object({
|
|
59
|
+
name: agentName,
|
|
60
|
+
task: z.string().min(1).describe("One-line task given to the fork"),
|
|
61
|
+
base_commit: z.string().optional().describe("Commit the fork starts from"),
|
|
62
|
+
worktree: z.string().optional().describe("Worktree path when the fork has one"),
|
|
63
|
+
session
|
|
64
|
+
}),
|
|
65
|
+
run: (carnet, sessionId, args) => {
|
|
66
|
+
const agent = carnet.agents.start(sessionId, {
|
|
67
|
+
name: args.name,
|
|
68
|
+
task: args.task,
|
|
69
|
+
baseCommit: args.base_commit,
|
|
70
|
+
worktree: args.worktree
|
|
71
|
+
});
|
|
72
|
+
mkdirSync(reportsDirectoryOf(carnet.group), { recursive: true });
|
|
73
|
+
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
|
+
};
|
|
81
|
+
}
|
|
82
|
+
});
|
|
83
|
+
const agentUpdate = defineTool({
|
|
84
|
+
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.",
|
|
86
|
+
schema: z.object({
|
|
87
|
+
name: agentName,
|
|
88
|
+
status: z.enum(OPEN_AGENT_STATUSES).describe("Next action: running means the fork is working"),
|
|
89
|
+
note: z.string().optional().describe("Under 60 characters, no paths, no backticks"),
|
|
90
|
+
report_path: z.string().optional().describe("New absolute path of the report, when it moved"),
|
|
91
|
+
session
|
|
92
|
+
}),
|
|
93
|
+
run: (carnet, sessionId, args) => {
|
|
94
|
+
const agent = carnet.agents.update(sessionId, args.name, {
|
|
95
|
+
status: args.status,
|
|
96
|
+
note: args.note,
|
|
97
|
+
reportPath: args.report_path
|
|
98
|
+
});
|
|
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
|
+
};
|
|
108
|
+
}
|
|
109
|
+
});
|
|
110
|
+
const agentDone = defineTool({
|
|
111
|
+
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.",
|
|
113
|
+
schema: z.object({
|
|
114
|
+
name: agentName,
|
|
115
|
+
report_path: z.string().min(1).describe("Absolute path of the markdown report"),
|
|
116
|
+
has_questions: z.boolean().describe("true when the report asks the human something"),
|
|
117
|
+
session
|
|
118
|
+
}),
|
|
119
|
+
run: (carnet, sessionId, args) => {
|
|
120
|
+
const agent = carnet.agents.finish(sessionId, args.name, {
|
|
121
|
+
reportPath: args.report_path,
|
|
122
|
+
hasQuestions: args.has_questions
|
|
123
|
+
});
|
|
124
|
+
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
|
+
};
|
|
129
|
+
}
|
|
130
|
+
});
|
|
131
|
+
const agentDrop = defineTool({
|
|
132
|
+
name: "agent_drop",
|
|
133
|
+
description: "Main agent only. Close an agent once its work is committed or abandoned. It leaves the status view; history stays in the journal.",
|
|
134
|
+
schema: z.object({
|
|
135
|
+
name: agentName,
|
|
136
|
+
reason: z.string().optional().describe("Why it is closed, for the journal"),
|
|
137
|
+
session
|
|
138
|
+
}),
|
|
139
|
+
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
|
+
};
|
|
145
|
+
}
|
|
146
|
+
});
|
|
147
|
+
const agentList = defineTool({
|
|
148
|
+
name: "agent_list",
|
|
149
|
+
description: "List the open agents of the session with status, note, task and report path.",
|
|
150
|
+
schema: z.object({ session }),
|
|
151
|
+
run: (carnet, sessionId) => {
|
|
152
|
+
const agents = carnet.agents.list(sessionId);
|
|
153
|
+
const lines = agents.map((agent) => {
|
|
154
|
+
const emoji = agent.status === "closed" ? "" : EMOJI[agent.status];
|
|
155
|
+
const note = agent.note ? ` — ${agent.note}` : "";
|
|
156
|
+
const report = agent.reportPath ? ` (report: ${agent.reportPath})` : "";
|
|
157
|
+
return `${emoji} ${agent.name} [${agent.status}]${note}${report}`;
|
|
158
|
+
});
|
|
159
|
+
return {
|
|
160
|
+
text: lines.length ? lines.join("\n") : "no open agents",
|
|
161
|
+
data: { agents }
|
|
162
|
+
};
|
|
163
|
+
}
|
|
164
|
+
});
|
|
165
|
+
const queueReorder = defineTool({
|
|
166
|
+
name: "queue_reorder",
|
|
167
|
+
description: "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).",
|
|
168
|
+
schema: z.object({
|
|
169
|
+
names: z.array(agentName).min(1).describe("Agent names in handling order"),
|
|
170
|
+
session
|
|
171
|
+
}),
|
|
172
|
+
run: (carnet, sessionId, args) => {
|
|
173
|
+
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
|
+
};
|
|
180
|
+
}
|
|
181
|
+
});
|
|
182
|
+
const tableSet = defineTool({
|
|
183
|
+
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.",
|
|
185
|
+
schema: z.object({
|
|
186
|
+
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"),
|
|
188
|
+
status: z.enum(USER_ACTION_STATUSES).optional().describe("Next human action when main_working is false; defaults to discussing"),
|
|
189
|
+
session
|
|
190
|
+
}),
|
|
191
|
+
run: (carnet, sessionId, args) => {
|
|
192
|
+
const item = carnet.table.set(sessionId, {
|
|
193
|
+
text: args.text,
|
|
194
|
+
mainWorking: args.main_working,
|
|
195
|
+
status: args.status
|
|
196
|
+
});
|
|
197
|
+
return {
|
|
198
|
+
text: renderTableLine(item),
|
|
199
|
+
data: { table: item }
|
|
200
|
+
};
|
|
201
|
+
}
|
|
202
|
+
});
|
|
203
|
+
const tableClear = defineTool({
|
|
204
|
+
name: "table_clear",
|
|
205
|
+
description: "Main agent only. Empty the 'On the table' line.",
|
|
206
|
+
schema: z.object({ session }),
|
|
207
|
+
run: (carnet, sessionId) => {
|
|
208
|
+
carnet.table.clear(sessionId);
|
|
209
|
+
return { text: "On the table cleared" };
|
|
210
|
+
}
|
|
211
|
+
});
|
|
212
|
+
const logEvent = defineTool({
|
|
213
|
+
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).",
|
|
215
|
+
schema: z.object({
|
|
216
|
+
type: z.enum(EVENT_TYPES),
|
|
217
|
+
agent: z.string().optional().describe("Agent concerned"),
|
|
218
|
+
commit: z.string().optional().describe("Commit sha"),
|
|
219
|
+
link: z.string().optional().describe("Report path or URL"),
|
|
220
|
+
note: z.string().optional(),
|
|
221
|
+
session
|
|
222
|
+
}),
|
|
223
|
+
run: (carnet, sessionId, args) => {
|
|
224
|
+
const event = carnet.events.log(sessionId, {
|
|
225
|
+
type: args.type,
|
|
226
|
+
agent: args.agent,
|
|
227
|
+
commit: args.commit,
|
|
228
|
+
link: args.link,
|
|
229
|
+
note: args.note
|
|
230
|
+
});
|
|
231
|
+
return {
|
|
232
|
+
text: [
|
|
233
|
+
"logged",
|
|
234
|
+
event.type,
|
|
235
|
+
event.agent,
|
|
236
|
+
event.commit
|
|
237
|
+
].filter(Boolean).join(" "),
|
|
238
|
+
data: { event }
|
|
239
|
+
};
|
|
240
|
+
}
|
|
241
|
+
});
|
|
242
|
+
const sessionName = z.string().trim().min(1).describe("Short session name, used by rucher resume");
|
|
243
|
+
const sessionNew = defineTool({
|
|
244
|
+
name: "session_new",
|
|
245
|
+
description: "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.",
|
|
246
|
+
schema: z.object({
|
|
247
|
+
name: sessionName,
|
|
248
|
+
purpose: z.string().optional().describe("One line: what this session is for"),
|
|
249
|
+
session
|
|
250
|
+
}),
|
|
251
|
+
run: (carnet, sessionId, args) => {
|
|
252
|
+
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
|
+
};
|
|
257
|
+
}
|
|
258
|
+
});
|
|
259
|
+
const sessionList = defineTool({
|
|
260
|
+
name: "session_list",
|
|
261
|
+
description: "List the group's sessions, most recently active first. Temp and archived ones are hidden unless asked.",
|
|
262
|
+
schema: z.object({
|
|
263
|
+
include_temp: z.boolean().optional(),
|
|
264
|
+
include_archived: z.boolean().optional(),
|
|
265
|
+
session
|
|
266
|
+
}),
|
|
267
|
+
run: (carnet, sessionId, args) => {
|
|
268
|
+
const sessions = carnet.sessions.list({
|
|
269
|
+
includeTemp: args.include_temp,
|
|
270
|
+
includeArchived: args.include_archived
|
|
271
|
+
});
|
|
272
|
+
const lines = sessions.map((listed) => {
|
|
273
|
+
const current = listed.id === sessionId ? " (current)" : "";
|
|
274
|
+
return `${sessionLabel(listed)} [${listed.kind}, ${listed.status}]${current}`;
|
|
275
|
+
});
|
|
276
|
+
return {
|
|
277
|
+
text: lines.length ? lines.join("\n") : "no sessions",
|
|
278
|
+
data: { sessions }
|
|
279
|
+
};
|
|
280
|
+
}
|
|
281
|
+
});
|
|
282
|
+
const sessionDrop = defineTool({
|
|
283
|
+
name: "session_drop",
|
|
284
|
+
description: "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.",
|
|
285
|
+
schema: z.object({
|
|
286
|
+
name: z.string().trim().min(1).describe("Session name, id or id prefix"),
|
|
287
|
+
session
|
|
288
|
+
}),
|
|
289
|
+
run: (carnet, _sessionId, args) => {
|
|
290
|
+
const dropped = carnet.sessions.drop(carnet.sessions.find(args.name).id);
|
|
291
|
+
return {
|
|
292
|
+
text: `Session ${sessionLabel(dropped)} archived`,
|
|
293
|
+
data: { session: dropped }
|
|
294
|
+
};
|
|
295
|
+
}
|
|
296
|
+
});
|
|
297
|
+
const sessionResumeInfo = defineTool({
|
|
298
|
+
name: "session_resume_info",
|
|
299
|
+
description: "What a session was doing: its status view and last events, plus the command to resume it. Defaults to the current session.",
|
|
300
|
+
schema: z.object({
|
|
301
|
+
name: z.string().trim().min(1).optional().describe("Session name, id or id prefix"),
|
|
302
|
+
session
|
|
303
|
+
}),
|
|
304
|
+
run: (carnet, sessionId, args) => {
|
|
305
|
+
const target = args.name ? carnet.sessions.find(args.name) : carnet.sessions.require(sessionId);
|
|
306
|
+
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
|
+
};
|
|
314
|
+
}
|
|
315
|
+
});
|
|
316
|
+
const logRead = defineTool({
|
|
317
|
+
name: "log_read",
|
|
318
|
+
description: "Read the last journal events of the session, oldest first.",
|
|
319
|
+
schema: z.object({
|
|
320
|
+
limit: z.number().int().min(1).max(200).optional().describe("Number of events, default 20"),
|
|
321
|
+
session
|
|
322
|
+
}),
|
|
323
|
+
run: (carnet, sessionId, args) => {
|
|
324
|
+
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
|
+
};
|
|
329
|
+
}
|
|
330
|
+
});
|
|
331
|
+
const noteId = z.number().int().positive().describe("Note id, as shown by note_list (#14 is 14)");
|
|
332
|
+
function noteLine(note) {
|
|
333
|
+
const repos = note.repos.length ? ` [${note.repos.join(", ")}]` : "";
|
|
334
|
+
return `#${note.id} ${note.kind}${repos} ${note.text}`;
|
|
335
|
+
}
|
|
336
|
+
const TOOLS = [
|
|
337
|
+
agentStart,
|
|
338
|
+
agentUpdate,
|
|
339
|
+
agentDone,
|
|
340
|
+
agentDrop,
|
|
341
|
+
agentList,
|
|
342
|
+
queueReorder,
|
|
343
|
+
tableSet,
|
|
344
|
+
tableClear,
|
|
345
|
+
logEvent,
|
|
346
|
+
logRead,
|
|
347
|
+
sessionNew,
|
|
348
|
+
sessionList,
|
|
349
|
+
sessionDrop,
|
|
350
|
+
sessionResumeInfo,
|
|
351
|
+
defineTool({
|
|
352
|
+
name: "note_add",
|
|
353
|
+
description: "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.",
|
|
354
|
+
schema: z.object({
|
|
355
|
+
kind: z.enum(NOTE_KINDS),
|
|
356
|
+
text: z.string().min(1).describe("One claim with its reason, under 200 characters"),
|
|
357
|
+
repos: z.array(z.string().min(1)).optional().describe("Repo names of the group; omit for a general note"),
|
|
358
|
+
agent: z.string().optional().describe("Fork the note comes from"),
|
|
359
|
+
session
|
|
360
|
+
}),
|
|
361
|
+
run: (carnet, sessionId, args) => {
|
|
362
|
+
const { note, similar } = carnet.notes.add({
|
|
363
|
+
kind: args.kind,
|
|
364
|
+
text: args.text,
|
|
365
|
+
repos: args.repos,
|
|
366
|
+
agent: args.agent,
|
|
367
|
+
session: sessionId
|
|
368
|
+
});
|
|
369
|
+
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
|
+
};
|
|
377
|
+
}
|
|
378
|
+
}),
|
|
379
|
+
defineTool({
|
|
380
|
+
name: "note_list",
|
|
381
|
+
description: "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.",
|
|
382
|
+
schema: z.object({
|
|
383
|
+
kind: z.enum(NOTE_KINDS).optional(),
|
|
384
|
+
repo: z.string().optional().describe("Notes of this repo"),
|
|
385
|
+
general: z.boolean().optional().describe("Only notes without repo"),
|
|
386
|
+
query: z.string().optional().describe("Substring of the text"),
|
|
387
|
+
include_dropped: z.boolean().optional(),
|
|
388
|
+
session
|
|
389
|
+
}),
|
|
390
|
+
run: (carnet, _sessionId, args) => {
|
|
391
|
+
const notes = carnet.notes.list({
|
|
392
|
+
kind: args.kind,
|
|
393
|
+
repo: args.repo,
|
|
394
|
+
general: args.general,
|
|
395
|
+
query: args.query,
|
|
396
|
+
includeDropped: args.include_dropped,
|
|
397
|
+
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
|
+
};
|
|
404
|
+
}
|
|
405
|
+
}),
|
|
406
|
+
defineTool({
|
|
407
|
+
name: "note_drop",
|
|
408
|
+
description: "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.",
|
|
409
|
+
schema: z.object({
|
|
410
|
+
id: noteId,
|
|
411
|
+
reason: z.string().min(1).describe("Why the note is no longer true"),
|
|
412
|
+
replaced_by: z.number().int().positive().optional().describe("Id of the note replacing it"),
|
|
413
|
+
session
|
|
414
|
+
}),
|
|
415
|
+
run: (carnet, sessionId, args) => {
|
|
416
|
+
const note = carnet.notes.drop(args.id, {
|
|
417
|
+
reason: args.reason,
|
|
418
|
+
replacedBy: args.replaced_by,
|
|
419
|
+
session: sessionId
|
|
420
|
+
});
|
|
421
|
+
const replaced = note.replacedBy ? `, replaced by #${note.replacedBy}` : "";
|
|
422
|
+
return {
|
|
423
|
+
text: `dropped #${note.id}${replaced}`,
|
|
424
|
+
data: { note }
|
|
425
|
+
};
|
|
426
|
+
}
|
|
427
|
+
}),
|
|
428
|
+
defineTool({
|
|
429
|
+
name: "note_cite",
|
|
430
|
+
description: "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.",
|
|
431
|
+
schema: z.object({
|
|
432
|
+
id: noteId,
|
|
433
|
+
why: z.string().min(1).describe("What the note changed, short"),
|
|
434
|
+
agent: z.string().optional().describe("Fork citing it, when not the main agent"),
|
|
435
|
+
session
|
|
436
|
+
}),
|
|
437
|
+
run: (carnet, sessionId, args) => {
|
|
438
|
+
const citation = carnet.notes.cite(args.id, {
|
|
439
|
+
why: args.why,
|
|
440
|
+
agent: args.agent,
|
|
441
|
+
session: sessionId
|
|
442
|
+
});
|
|
443
|
+
return {
|
|
444
|
+
text: `cited #${citation.note}: ${citation.why}`,
|
|
445
|
+
data: { citation }
|
|
446
|
+
};
|
|
447
|
+
}
|
|
448
|
+
})
|
|
449
|
+
];
|
|
450
|
+
// src/mcp/server.ts
|
|
451
|
+
const SERVER_NAME = "carnet";
|
|
452
|
+
const SERVER_VERSION = "0.0.0";
|
|
453
|
+
function errorResult(error) {
|
|
454
|
+
return {
|
|
455
|
+
isError: true,
|
|
456
|
+
content: [{
|
|
457
|
+
type: "text",
|
|
458
|
+
text: `${error.code}: ${error.message}`
|
|
459
|
+
}]
|
|
460
|
+
};
|
|
461
|
+
}
|
|
462
|
+
function createCarnetServer(options) {
|
|
463
|
+
let carnet;
|
|
464
|
+
let resolver;
|
|
465
|
+
const open = () => {
|
|
466
|
+
carnet ??= typeof options.carnet === "function" ? options.carnet() : options.carnet;
|
|
467
|
+
resolver ??= createSessionResolver({
|
|
468
|
+
...options,
|
|
469
|
+
carnet
|
|
470
|
+
});
|
|
471
|
+
return {
|
|
472
|
+
carnet,
|
|
473
|
+
resolver
|
|
474
|
+
};
|
|
475
|
+
};
|
|
476
|
+
const server = new McpServer({
|
|
477
|
+
name: SERVER_NAME,
|
|
478
|
+
version: SERVER_VERSION
|
|
479
|
+
}, { instructions: INSTRUCTIONS });
|
|
480
|
+
for (const tool of TOOLS) server.registerTool(tool.name, {
|
|
481
|
+
description: tool.description,
|
|
482
|
+
inputSchema: tool.schema
|
|
483
|
+
}, (args) => {
|
|
484
|
+
try {
|
|
485
|
+
const { carnet, resolver } = open();
|
|
486
|
+
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
|
+
};
|
|
495
|
+
} catch (error) {
|
|
496
|
+
if (error instanceof CarnetError) return errorResult(error);
|
|
497
|
+
throw error;
|
|
498
|
+
}
|
|
499
|
+
});
|
|
500
|
+
return server;
|
|
501
|
+
}
|
|
502
|
+
function serveCarnet(options = {}) {
|
|
503
|
+
const carnet = options.carnet ?? (() => openCarnet(options));
|
|
504
|
+
return serveStdio(() => createCarnetServer({
|
|
505
|
+
carnet,
|
|
506
|
+
env: options.env,
|
|
507
|
+
ppid: options.ppid,
|
|
508
|
+
cwd: options.cwd
|
|
509
|
+
}), { onerror: (error) => console.error(`[carnet] ${error.message}`) });
|
|
510
|
+
}
|
|
511
|
+
export { INSTRUCTIONS, SERVER_NAME, SERVER_VERSION, TOOLS, createCarnetServer, createSessionResolver, serveCarnet };
|
|
512
|
+
|
|
513
|
+
//# sourceMappingURL=mcp.mjs.map
|
package/dist/mcp.mjs.map
ADDED
|
@@ -0,0 +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,O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