@rucher/carnet 0.2.0 → 0.3.0-beta.1
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/README.md +2 -2
- package/dist/{carnet-DHw_oXJs.d.mts → carnet-BFA2yya4.d.mts} +194 -44
- package/dist/carnet-BFA2yya4.d.mts.map +1 -0
- package/dist/index.d.mts +129 -8
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs +987 -21
- package/dist/index.mjs.map +1 -1
- package/dist/mcp.d.mts +4 -2
- package/dist/mcp.d.mts.map +1 -1
- package/dist/mcp.mjs +199 -33
- package/dist/mcp.mjs.map +1 -1
- package/dist/{steps-4ZTrBzcd.mjs → steps-DhCnOGCU.mjs} +1512 -187
- package/dist/steps-DhCnOGCU.mjs.map +1 -0
- package/package.json +1 -1
- package/dist/carnet-DHw_oXJs.d.mts.map +0 -1
- package/dist/steps-4ZTrBzcd.mjs.map +0 -1
package/dist/mcp.mjs
CHANGED
|
@@ -1,22 +1,23 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { B as renderAgentLine, C as openCarnet, Dn as reportsDirectory, Dt as DEFAULT_HOST, En as reportPath, Jn as EMOJI, Ln as AGENT_KINDS, Rn as KIND_REQUIRED, X as sandboxRemovedSuffix, _ as openQuestionsText, a as formatEventLine, b as reportSummary, bn as FINDING_SEVERITIES, c as answerQuestionsText, d as findingsText, f as finishWithItems, g as nextAgent, kt as hostById, l as decideText, m as kindAction, n as stepAgent, nr as OPEN_AGENT_STATUSES, nt as NOTE_KINDS, o as resumeContext, p as injectReport, q as renderTableLine, rr as USER_ACTION_STATUSES, s as sessionLabel, sr as EVENT_TYPES, st as memoryHalfLife, t as AGENT_STEPS, u as findingsBrief, ur as CarnetError, v as promoteText, x as reviewContext, xn as SPAWN_KINDS, yn as FINDING_DECISIONS, zn as PROMOTE_KIND_REQUIRED } from "./steps-DhCnOGCU.mjs";
|
|
2
2
|
import { copyFileSync, existsSync, mkdirSync } from "node:fs";
|
|
3
3
|
import { resolve } from "node:path";
|
|
4
4
|
import { McpServer } from "@modelcontextprotocol/server";
|
|
5
5
|
import { serveStdio } from "@modelcontextprotocol/server/stdio";
|
|
6
6
|
import * as z from "zod/v4";
|
|
7
7
|
// src/mcp/instructions.ts
|
|
8
|
-
const INSTRUCTIONS = `Carnet holds the forks, the
|
|
8
|
+
const INSTRUCTIONS = `Carnet holds the forks, the Main line, sessions, the journal and the workspace 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 launching agents or handling their results.
|
|
9
9
|
|
|
10
10
|
Which tool, when:
|
|
11
|
-
-
|
|
11
|
+
- Launch: agent_start with the agent's kind (research, plan, implement, review), then launch it in a later message with Agent, subagent_type fork (or the kind's cold agent), description = the agent name. A plan agent is always a Rucher fork, never the built-in Plan subagent or plan mode.
|
|
12
12
|
- Each step of a fork's work: agent_step (answered, applying, applied, tested, committed, dropped).
|
|
13
|
-
-
|
|
13
|
+
- Next actions, only when the human asks (/rucher:next): agent_report, then agent_inject or agent_promote (research), agent_questions then agent_answer then agent_promote (plan), review_findings then review_decide, then review_brief for each agent started from the findings (review). review_context before launching a review.
|
|
14
|
+
- Main line text for work of your own: table_set, table_clear.
|
|
14
15
|
- Other moves: agent_update, agent_drop, queue_reorder. Recall: agent_list, log_read, session_resume_info, session_list.
|
|
15
16
|
- 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
17
|
- Session: session_new when the human names it, session_drop only when asked.
|
|
17
18
|
- Fork: agent_update (running, short note) at progress, agent_done last.
|
|
18
19
|
|
|
19
|
-
Statuses (the NEXT action): running ⏳ · discussing 💬 · answer ❓ · review 👀 · apply 📥 · test
|
|
20
|
+
Statuses (the NEXT action): running ⏳ · discussing 💬 · answer ❓ · review 👀 · apply 📥 · test 🧪. Notes and table text: under 60 characters, no paths, no backticks.`;
|
|
20
21
|
// src/mcp/session.ts
|
|
21
22
|
const FULL_ID = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
|
|
22
23
|
function createSessionResolver({ carnet, env = process.env, ppid = process.ppid, cwd = process.cwd(), host = hostById(DEFAULT_HOST) }) {
|
|
@@ -54,8 +55,11 @@ const agentStart = defineTool({
|
|
|
54
55
|
schema: z.object({
|
|
55
56
|
name: agentName,
|
|
56
57
|
task: z.string().min(1).describe("One-line task given to the fork"),
|
|
58
|
+
kind: z.enum(AGENT_KINDS, { error: KIND_REQUIRED }).describe("Agent type, required: research (reads, reports for the main), plan (plans a wanted change and asks its questions; a Rucher fork, never the built-in Plan subagent), implement (writes code, the only kind with a worktree), review (reads a diff, reports findings)"),
|
|
59
|
+
target: z.string().optional().describe("Review only, required there: the implement agent it reviews, or main[:<range>]"),
|
|
57
60
|
base_commit: z.string().optional().describe("Commit the fork starts from"),
|
|
58
|
-
worktree: z.string().optional().describe("
|
|
61
|
+
worktree: z.string().optional().describe("Implement only: worktree path when the fork has one"),
|
|
62
|
+
sandbox: z.string().optional().describe("Research or plan only: throwaway folder under the run directory's sandboxes folder, created empty, writable by the agent, removed when it closes"),
|
|
59
63
|
session
|
|
60
64
|
}),
|
|
61
65
|
run: (carnet, sessionId, args) => {
|
|
@@ -63,35 +67,44 @@ const agentStart = defineTool({
|
|
|
63
67
|
const agent = carnet.agents.start(sessionId, {
|
|
64
68
|
name: args.name,
|
|
65
69
|
task: args.task,
|
|
70
|
+
kind: args.kind,
|
|
71
|
+
target: args.target,
|
|
66
72
|
baseCommit: args.base_commit,
|
|
67
|
-
worktree: args.worktree
|
|
73
|
+
worktree: args.worktree,
|
|
74
|
+
sandbox: args.sandbox
|
|
68
75
|
});
|
|
69
|
-
|
|
76
|
+
const sandbox = agent.sandbox ? `\nSandbox: ${agent.sandbox}` : "";
|
|
77
|
+
if (!workspace) return { text: `${EMOJI.running} ${agent.name} started outside any workspace\nNo report destination: the report stays where the fork writes it${sandbox}` };
|
|
70
78
|
mkdirSync(reportsDirectory(workspace), { recursive: true });
|
|
71
|
-
return { text: `${EMOJI.running} ${agent.name} started in workspace ${workspace.name}\nReport destination: ${reportPath(workspace, agent.name)}` };
|
|
79
|
+
return { text: `${EMOJI.running} ${agent.name} started in workspace ${workspace.name}\nReport destination: ${reportPath(workspace, agent.name)}${sandbox}` };
|
|
72
80
|
}
|
|
73
81
|
});
|
|
74
82
|
const agentUpdate = defineTool({
|
|
75
83
|
name: "agent_update",
|
|
76
|
-
description: "Set an agent's status and note. Forks: status running at progress. Main agent: only for moves agent_step does not cover.",
|
|
84
|
+
description: "Set an agent's status and note. Forks: status running at progress. Main agent: only for moves agent_step does not cover, and blocked_on when an agent waits on another agent (never 💬 discussing for that).",
|
|
77
85
|
schema: z.object({
|
|
78
86
|
name: agentName,
|
|
79
87
|
status: z.enum(OPEN_AGENT_STATUSES).describe("Next action: running means the fork is working"),
|
|
80
88
|
note: z.string().optional().describe("Under 60 characters, no paths, no backticks"),
|
|
81
89
|
report_path: z.string().optional().describe("New absolute path of the report, when it moved"),
|
|
90
|
+
blocked_on: z.string().nullable().optional().describe("Open agent of this session it waits on: it leaves Waiting on you until that agent closes. null clears it"),
|
|
82
91
|
session
|
|
83
92
|
}),
|
|
84
93
|
run: (carnet, sessionId, args) => {
|
|
85
94
|
const agent = carnet.agents.update(sessionId, args.name, {
|
|
86
95
|
status: args.status,
|
|
87
96
|
note: args.note,
|
|
88
|
-
reportPath: args.report_path
|
|
97
|
+
reportPath: args.report_path,
|
|
98
|
+
blockedOn: args.blocked_on
|
|
89
99
|
});
|
|
90
100
|
return { text: renderAgentLine({
|
|
91
101
|
name: agent.name,
|
|
102
|
+
kind: agent.kind,
|
|
92
103
|
status: agent.status,
|
|
104
|
+
action: agent.blockedOn ? `→ ${agent.blockedOn}` : null,
|
|
93
105
|
emoji: agent.status === "closed" ? "" : EMOJI[agent.status],
|
|
94
|
-
note: agent.note
|
|
106
|
+
note: agent.note,
|
|
107
|
+
pinned: agent.queueOrder !== null
|
|
95
108
|
}) };
|
|
96
109
|
}
|
|
97
110
|
});
|
|
@@ -103,21 +116,46 @@ function copyReport(carnet, name, reportFile) {
|
|
|
103
116
|
copyFileSync(reportFile, destination);
|
|
104
117
|
return destination;
|
|
105
118
|
}
|
|
119
|
+
const questionInput = z.object({
|
|
120
|
+
text: z.string().min(1),
|
|
121
|
+
context: z.string().optional().describe("One short line"),
|
|
122
|
+
recommendation: z.string().min(1),
|
|
123
|
+
alternatives: z.array(z.string().min(1)).max(3).optional().describe(`At most 3; list more in the text`)
|
|
124
|
+
});
|
|
125
|
+
const findingInput = z.object({
|
|
126
|
+
severity: z.enum(FINDING_SEVERITIES),
|
|
127
|
+
location: z.string().optional().describe("file:line"),
|
|
128
|
+
text: z.string().min(1),
|
|
129
|
+
fix: z.string().optional().describe("Proposed fix, short")
|
|
130
|
+
});
|
|
131
|
+
const DONE_WORDS = {
|
|
132
|
+
answer: "needs answers",
|
|
133
|
+
review: "ready for review",
|
|
134
|
+
apply: "ready to apply"
|
|
135
|
+
};
|
|
136
|
+
function doneOutcome(name, status) {
|
|
137
|
+
if (status === "closed") return `${name} closed`;
|
|
138
|
+
return `${EMOJI[status]} ${name} ${DONE_WORDS[status] ?? status}`;
|
|
139
|
+
}
|
|
106
140
|
const agentDone = defineTool({
|
|
107
141
|
name: "agent_done",
|
|
108
|
-
description: "Forks call this as their LAST tool action, then reply with one line that carries no results. Copies the report to the workspace report destination and
|
|
142
|
+
description: "Forks call this as their LAST tool action, then reply with one line that carries no results. Copies the report to the workspace report destination. Pass questions (and findings for a review) here only, never in the report: Carnet writes them into it. The agent then waits on ❓ answer when questions are open, else 📥 apply (implement) or 👀 review.",
|
|
109
143
|
schema: z.object({
|
|
110
144
|
name: agentName,
|
|
111
145
|
report_path: z.string().min(1).describe("Absolute path of the markdown report"),
|
|
112
|
-
|
|
146
|
+
questions: z.array(questionInput).optional().describe("Choices left to the human, each with a recommendation"),
|
|
147
|
+
findings: z.array(findingInput).optional().describe("Review agents only"),
|
|
148
|
+
has_questions: z.boolean().optional().describe("Only when the report asks something outside questions"),
|
|
113
149
|
session
|
|
114
150
|
}),
|
|
115
151
|
run: (carnet, sessionId, args) => {
|
|
116
|
-
const agent = carnet
|
|
152
|
+
const agent = finishWithItems(carnet, sessionId, args.name, {
|
|
117
153
|
reportPath: copyReport(carnet, args.name, args.report_path),
|
|
154
|
+
questions: args.questions,
|
|
155
|
+
findings: args.findings,
|
|
118
156
|
hasQuestions: args.has_questions
|
|
119
157
|
});
|
|
120
|
-
const outcome =
|
|
158
|
+
const outcome = doneOutcome(agent.name, agent.pendingStatus ?? agent.status);
|
|
121
159
|
return { text: agent.status === "running" ? `${outcome} once you stop; reply now with one line that carries no results` : outcome };
|
|
122
160
|
}
|
|
123
161
|
});
|
|
@@ -130,26 +168,144 @@ const agentDrop = defineTool({
|
|
|
130
168
|
session
|
|
131
169
|
}),
|
|
132
170
|
run: (carnet, sessionId, args) => {
|
|
133
|
-
|
|
171
|
+
const agent = carnet.agents.drop(sessionId, args.name, args.reason);
|
|
172
|
+
return { text: `${agent.name} closed${sandboxRemovedSuffix(agent.sandboxRemoved)}` };
|
|
134
173
|
}
|
|
135
174
|
});
|
|
136
175
|
const agentList = defineTool({
|
|
137
176
|
name: "agent_list",
|
|
138
|
-
description: "List the open agents of the session
|
|
139
|
-
schema: z.object({
|
|
140
|
-
|
|
141
|
-
|
|
177
|
+
description: "List the open agents of the session: kind, status, next action, note, task and report path.",
|
|
178
|
+
schema: z.object({
|
|
179
|
+
kind: z.enum(AGENT_KINDS).optional().describe("Only agents of this kind"),
|
|
180
|
+
session
|
|
181
|
+
}),
|
|
182
|
+
run: (carnet, sessionId, args) => {
|
|
183
|
+
const lines = carnet.agents.list(sessionId).filter((agent) => !args.kind || agent.kind === args.kind).map((agent) => {
|
|
142
184
|
const emoji = agent.status === "closed" ? "" : EMOJI[agent.status];
|
|
185
|
+
const action = agent.status === "running" ? "" : ` → ${kindAction(agent)}`;
|
|
186
|
+
const target = agent.target ? ` on ${agent.target}` : "";
|
|
187
|
+
const blocked = agent.blockedOn ? ` blocked on ${agent.blockedOn}` : "";
|
|
143
188
|
const note = agent.note ? ` — ${agent.note}` : "";
|
|
144
189
|
const report = agent.reportPath ? ` (report: ${agent.reportPath})` : "";
|
|
145
|
-
|
|
190
|
+
const sandbox = agent.sandbox ? ` (sandbox: ${agent.sandbox})` : "";
|
|
191
|
+
return `${emoji} ${agent.name} ${agent.kind}${target} [${agent.status}]${blocked}${action}${note}${report}${sandbox}`;
|
|
146
192
|
});
|
|
147
193
|
return { text: lines.length ? lines.join("\n") : "no open agents" };
|
|
148
194
|
}
|
|
149
195
|
});
|
|
196
|
+
const agentQuestions = defineTool({
|
|
197
|
+
name: "agent_questions",
|
|
198
|
+
description: "Main agent only. An agent's open questions, numbered n/total, each with its recommendation and alternatives. Ask them one at a time unless the human wants them as text.",
|
|
199
|
+
schema: z.object({
|
|
200
|
+
name: agentName,
|
|
201
|
+
session
|
|
202
|
+
}),
|
|
203
|
+
run: (carnet, sessionId, args) => ({ text: openQuestionsText(carnet, sessionId, args.name) })
|
|
204
|
+
});
|
|
205
|
+
const agentAnswer = defineTool({
|
|
206
|
+
name: "agent_answer",
|
|
207
|
+
description: "Main agent only. Record the human's answers, one or several at once. Appends them to the report. With the last answer, logs answered and moves the agent on: a plan agent to 👀 review with its plan to validate, an implement to 📥 apply.",
|
|
208
|
+
schema: z.object({
|
|
209
|
+
name: agentName,
|
|
210
|
+
answers: z.array(z.object({
|
|
211
|
+
n: z.number().int().min(1),
|
|
212
|
+
answer: z.string().min(1)
|
|
213
|
+
})).min(1),
|
|
214
|
+
session
|
|
215
|
+
}),
|
|
216
|
+
run: (carnet, sessionId, args) => ({ text: answerQuestionsText(carnet, sessionId, args.name, args.answers) })
|
|
217
|
+
});
|
|
218
|
+
const agentInject = defineTool({
|
|
219
|
+
name: "agent_inject",
|
|
220
|
+
description: "Main agent only, when the human asks. Returns a report section for your context: 'For the main' by default, the plan for a plan or promoted agent. Logs injected; closes a research agent. Works on closed agents.",
|
|
221
|
+
schema: z.object({
|
|
222
|
+
name: agentName,
|
|
223
|
+
section: z.string().optional().describe("Heading to extract instead of the default"),
|
|
224
|
+
full: z.boolean().optional().describe("The whole report, only when the human asks"),
|
|
225
|
+
echo: z.boolean().optional().describe("false: only confirm, when agent_report already showed the section"),
|
|
226
|
+
session
|
|
227
|
+
}),
|
|
228
|
+
run: (carnet, sessionId, args) => ({ text: injectReport(carnet, sessionId, args.name, {
|
|
229
|
+
section: args.section,
|
|
230
|
+
full: args.full,
|
|
231
|
+
echo: args.echo
|
|
232
|
+
}) })
|
|
233
|
+
});
|
|
234
|
+
const agentReport = defineTool({
|
|
235
|
+
name: "agent_report",
|
|
236
|
+
description: "Main agent only, when the human asks to handle an agent (/rucher:next): picks it (the named one, else the first of Waiting on you) and returns a short summary of its report by kind, read-only. Show it as is, then run the kind's next action.",
|
|
237
|
+
schema: z.object({
|
|
238
|
+
name: z.string().min(1).optional().describe("Agent name or its start; omit for the first agent of Waiting on you"),
|
|
239
|
+
session
|
|
240
|
+
}),
|
|
241
|
+
run: (carnet, sessionId, args) => {
|
|
242
|
+
const name = nextAgent(carnet, sessionId, args.name);
|
|
243
|
+
return { text: name ? reportSummary(carnet, sessionId, name) : "Nothing waiting on you." };
|
|
244
|
+
}
|
|
245
|
+
});
|
|
246
|
+
const agentPromote = defineTool({
|
|
247
|
+
name: "agent_promote",
|
|
248
|
+
description: "Main agent only, when the human asks. Continues the same agent under another kind: a research into plan or implement, a plan into implement, keeping the previous report beside the new one. For implement, create the worktree first and pass it. Then resume the fork under the new kind's contract.",
|
|
249
|
+
schema: z.object({
|
|
250
|
+
name: agentName,
|
|
251
|
+
kind: z.enum(["plan", "implement"], { error: PROMOTE_KIND_REQUIRED }).describe("Kind the agent becomes: plan or implement"),
|
|
252
|
+
worktree: z.string().optional().describe("Worktree created for the implementation"),
|
|
253
|
+
base_commit: z.string().optional().describe("Commit the worktree starts from"),
|
|
254
|
+
session
|
|
255
|
+
}),
|
|
256
|
+
run: (carnet, sessionId, args) => ({ text: promoteText(carnet, sessionId, args.name, {
|
|
257
|
+
kind: args.kind,
|
|
258
|
+
worktree: args.worktree,
|
|
259
|
+
baseCommit: args.base_commit
|
|
260
|
+
}) })
|
|
261
|
+
});
|
|
262
|
+
const reviewContextTool = defineTool({
|
|
263
|
+
name: "review_context",
|
|
264
|
+
description: "Main agent only, before launching a review. What the reviewer needs about its target: task, report, worktree, base, plan and answers, or the main repo range.",
|
|
265
|
+
schema: z.object({
|
|
266
|
+
target: z.string().min(1).describe("Implement agent name, or main[:<range>]"),
|
|
267
|
+
session
|
|
268
|
+
}),
|
|
269
|
+
run: (carnet, sessionId, args) => ({ text: reviewContext(carnet, sessionId, args.target) })
|
|
270
|
+
});
|
|
271
|
+
const reviewFindings = defineTool({
|
|
272
|
+
name: "review_findings",
|
|
273
|
+
description: "Main agent only. A review's findings, blocking first, numbered n/total, each pending one with its recommended route (send back, in main, implement, plan, research). Pending ones only by default.",
|
|
274
|
+
schema: z.object({
|
|
275
|
+
name: agentName,
|
|
276
|
+
all: z.boolean().optional().describe("Also the findings already decided"),
|
|
277
|
+
session
|
|
278
|
+
}),
|
|
279
|
+
run: (carnet, sessionId, args) => ({ text: findingsText(carnet, sessionId, args.name, args.all !== true) })
|
|
280
|
+
});
|
|
281
|
+
const reviewDecide = defineTool({
|
|
282
|
+
name: "review_decide",
|
|
283
|
+
description: "Main agent only. Record the human's decision on findings, one or several at once: sent (back to the implement agent), fixed (in main, or by a new agent: reason '<kind> agent <name>'), ignored (reason required). A finding left for later stays pending. With the last one, logs triaged, closes the review and lists the findings to send to the target.",
|
|
284
|
+
schema: z.object({
|
|
285
|
+
name: agentName,
|
|
286
|
+
decisions: z.array(z.object({
|
|
287
|
+
n: z.number().int().min(1),
|
|
288
|
+
decision: z.enum(FINDING_DECISIONS),
|
|
289
|
+
reason: z.string().optional()
|
|
290
|
+
})).min(1),
|
|
291
|
+
session
|
|
292
|
+
}),
|
|
293
|
+
run: (carnet, sessionId, args) => ({ text: decideText(carnet, sessionId, args.name, args.decisions) })
|
|
294
|
+
});
|
|
295
|
+
const reviewBrief = defineTool({
|
|
296
|
+
name: "review_brief",
|
|
297
|
+
description: "Main agent only, after triage. The brief of an agent started for some of a review's findings: the review, its target and the findings with their location and proposed fix. Put it in the agent's prompt as is, after its kind's contract. Read-only.",
|
|
298
|
+
schema: z.object({
|
|
299
|
+
name: agentName.describe("The review agent"),
|
|
300
|
+
findings: z.array(z.number().int().min(1)).min(1).describe("Finding numbers of this agent"),
|
|
301
|
+
kind: z.enum(SPAWN_KINDS).describe("Kind of the agent started for them"),
|
|
302
|
+
session
|
|
303
|
+
}),
|
|
304
|
+
run: (carnet, sessionId, args) => ({ text: findingsBrief(carnet, sessionId, args.name, args.findings, args.kind) })
|
|
305
|
+
});
|
|
150
306
|
const queueReorder = defineTool({
|
|
151
307
|
name: "queue_reorder",
|
|
152
|
-
description: "Main agent only.
|
|
308
|
+
description: "Main agent only, when the human asks. Pin the order of 'Waiting on you': the named agents come first in the given order, each pin lasting until that agent's status changes. The others follow the default order: test, answer, validate, triage, apply, inject, the rest, longest waiting first.",
|
|
153
309
|
schema: z.object({
|
|
154
310
|
names: z.array(agentName).min(1).describe("Agent names in handling order"),
|
|
155
311
|
session
|
|
@@ -162,17 +318,15 @@ const queueReorder = defineTool({
|
|
|
162
318
|
});
|
|
163
319
|
const tableSet = defineTool({
|
|
164
320
|
name: "table_set",
|
|
165
|
-
description: "Main agent only. Set the
|
|
321
|
+
description: "Main agent only. Set the Main line: what the main agent is handling, and the next human action once its turn ends. The hooks show ⚙️ while the main agent works, whatever this line says.",
|
|
166
322
|
schema: z.object({
|
|
167
323
|
text: z.string().min(1).describe("Under 60 characters, no paths, no backticks"),
|
|
168
|
-
|
|
169
|
-
status: z.enum(USER_ACTION_STATUSES).optional().describe("Next human action when main_working is false; defaults to discussing"),
|
|
324
|
+
status: z.enum(USER_ACTION_STATUSES).optional().describe("Next human action once the turn ends; defaults to discussing"),
|
|
170
325
|
session
|
|
171
326
|
}),
|
|
172
327
|
run: (carnet, sessionId, args) => {
|
|
173
328
|
const item = carnet.table.set(sessionId, {
|
|
174
329
|
text: args.text,
|
|
175
|
-
mainWorking: args.main_working,
|
|
176
330
|
status: args.status
|
|
177
331
|
});
|
|
178
332
|
return { text: renderTableLine(item) };
|
|
@@ -180,7 +334,7 @@ const tableSet = defineTool({
|
|
|
180
334
|
});
|
|
181
335
|
const agentStep = defineTool({
|
|
182
336
|
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
|
|
337
|
+
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 Main line in sync; the note replaces the agent's note. answered → apply (implement) or review, applying → Main line (implement only), applied → test, tested (optional) stays on test, committed (commit required) → closed, dropped (note = reason) → closed.",
|
|
184
338
|
schema: z.object({
|
|
185
339
|
name: agentName,
|
|
186
340
|
step: z.enum(AGENT_STEPS),
|
|
@@ -193,11 +347,11 @@ const agentStep = defineTool({
|
|
|
193
347
|
});
|
|
194
348
|
const tableClear = defineTool({
|
|
195
349
|
name: "table_clear",
|
|
196
|
-
description: "Main agent only. Empty the
|
|
350
|
+
description: "Main agent only. Empty the Main line.",
|
|
197
351
|
schema: z.object({ session }),
|
|
198
352
|
run: (carnet, sessionId) => {
|
|
199
353
|
carnet.table.clear(sessionId);
|
|
200
|
-
return { text: "
|
|
354
|
+
return { text: "Main line cleared" };
|
|
201
355
|
}
|
|
202
356
|
});
|
|
203
357
|
const logEvent = defineTool({
|
|
@@ -281,7 +435,7 @@ const sessionResumeInfo = defineTool({
|
|
|
281
435
|
}),
|
|
282
436
|
run: (carnet, sessionId, args) => {
|
|
283
437
|
const target = args.name ? carnet.sessions.find(args.name) : carnet.sessions.require(sessionId);
|
|
284
|
-
const resume = `rucher resume ${target.name ?? target.id}`;
|
|
438
|
+
const resume = `rucher resume ${target.name ?? target.id} --ws ${target.workspace}`;
|
|
285
439
|
return { text: `${resumeContext(carnet, target)}\n\nResume with: ${resume}` };
|
|
286
440
|
}
|
|
287
441
|
});
|
|
@@ -309,6 +463,15 @@ const TOOLS = [
|
|
|
309
463
|
agentDrop,
|
|
310
464
|
agentStep,
|
|
311
465
|
agentList,
|
|
466
|
+
agentQuestions,
|
|
467
|
+
agentAnswer,
|
|
468
|
+
agentInject,
|
|
469
|
+
agentReport,
|
|
470
|
+
agentPromote,
|
|
471
|
+
reviewContextTool,
|
|
472
|
+
reviewFindings,
|
|
473
|
+
reviewDecide,
|
|
474
|
+
reviewBrief,
|
|
312
475
|
queueReorder,
|
|
313
476
|
tableSet,
|
|
314
477
|
tableClear,
|
|
@@ -438,9 +601,11 @@ function createCarnetServer(options) {
|
|
|
438
601
|
try {
|
|
439
602
|
const { carnet, resolver } = open();
|
|
440
603
|
const sessionId = resolver.resolve(args.session);
|
|
604
|
+
const out = tool.run(carnet, sessionId, args);
|
|
605
|
+
options.afterTool?.(carnet, sessionId);
|
|
441
606
|
return { content: [{
|
|
442
607
|
type: "text",
|
|
443
|
-
text:
|
|
608
|
+
text: out.text
|
|
444
609
|
}] };
|
|
445
610
|
} catch (error) {
|
|
446
611
|
if (error instanceof CarnetError) return errorResult(error);
|
|
@@ -455,7 +620,8 @@ function serveCarnet(options = {}) {
|
|
|
455
620
|
carnet,
|
|
456
621
|
env: options.env,
|
|
457
622
|
ppid: options.ppid,
|
|
458
|
-
cwd: options.cwd
|
|
623
|
+
cwd: options.cwd,
|
|
624
|
+
afterTool: options.afterTool
|
|
459
625
|
}), { onerror: (error) => console.error(`[carnet] ${error.message}`) });
|
|
460
626
|
}
|
|
461
627
|
export { INSTRUCTIONS, SERVER_NAME, SERVER_VERSION, TOOLS, createCarnetServer, createSessionResolver, serveCarnet };
|
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 holds the forks, the \"On the table\" line, sessions, the journal and the workspace 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 workspace, 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 workspace = carnet.workspace;\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 (!workspace) {\n return {\n text: `${EMOJI.running} ${agent.name} started outside any workspace\\nNo report destination: the report stays where the fork writes it`,\n };\n }\n mkdirSync(reportsDirectory(workspace), { recursive: true });\n return {\n text: `${EMOJI.running} ${agent.name} started in workspace ${workspace.name}\\nReport destination: ${reportPath(workspace, 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.workspace) return reportFile;\n const destination = reportPath(carnet.workspace, name);\n if (resolve(reportFile) === destination || !existsSync(reportFile)) return reportFile;\n mkdirSync(reportsDirectory(carnet.workspace), { 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 workspace 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 workspace'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 workspace 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 workspace'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 workspace; 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 workspace's active notes, dead ends first, then decisions, then learnings, most cited first. Filter by kind, repo, general (notes without repo) or a substring query. Check it before trying an approach.\",\n schema: z.object({\n kind: z.enum(NOTE_KINDS).optional(),\n repo: z.string().optional().describe('Notes of this repo'),\n general: z.boolean().optional().describe('Only notes without repo'),\n query: z.string().optional().describe('Substring of the text'),\n include_dropped: z.boolean().optional(),\n session,\n }),\n run: (carnet, _sessionId, args) => {\n const notes = carnet.notes.list({\n kind: args.kind,\n repo: args.repo,\n general: args.general,\n query: args.query,\n includeDropped: args.include_dropped,\n halfLifeDays: memoryHalfLife(process.env['RUCHER_MEMORY_HALF_LIFE_DAYS']),\n });\n const lines = notes.map(\n (note) => `${noteLine(note)}${note.droppedAt ? ` (dropped: ${note.droppedReason})` : ''}`,\n );\n return { text: lines.length ? lines.join('\\n') : 'no notes' };\n },\n});\n\nconst noteDrop = defineTool({\n name: 'note_drop',\n description:\n 'Main agent only. Close a note that proved wrong or outdated: it stays in the history, marked dropped with the reason. Pass replaced_by when a corrected note replaces it.',\n schema: z.object({\n id: noteId,\n reason: z.string().min(1).describe('Why the note is no longer true'),\n replaced_by: z.number().int().positive().optional().describe('Id of the note replacing it'),\n session,\n }),\n run: (carnet, sessionId, args) => {\n const note = carnet.notes.drop(args.id, {\n reason: args.reason,\n replacedBy: args.replaced_by,\n session: sessionId,\n });\n const replaced = note.replacedBy ? `, replaced by #${note.replacedBy}` : '';\n return { text: `dropped #${note.id}${replaced}` };\n },\n});\n\nconst noteCite = defineTool({\n name: 'note_cite',\n description:\n 'Cite a note that changed what you did (avoided, followed or adjusted something), with what it changed. Never for a plain read. Citations decide which notes come first.',\n schema: z.object({\n id: noteId,\n why: z.string().min(1).describe('What the note changed, short'),\n agent: z.string().optional().describe('Fork citing it, when not the main agent'),\n session,\n }),\n run: (carnet, sessionId, args) => {\n const citation = carnet.notes.cite(args.id, {\n why: args.why,\n agent: args.agent,\n session: sessionId,\n });\n return { text: `cited #${citation.note}: ${citation.why}` };\n },\n});\n\nexport const TOOLS: readonly ToolDefinition[] = [\n agentStart,\n agentUpdate,\n agentDone,\n agentDrop,\n agentStep,\n agentList,\n queueReorder,\n tableSet,\n tableClear,\n logEvent,\n logRead,\n sessionNew,\n sessionList,\n sessionDrop,\n sessionResumeInfo,\n noteAdd,\n noteList,\n noteDrop,\n noteCite,\n] as readonly ToolDefinition[];\n","import { type CallToolResult, McpServer } from '@modelcontextprotocol/server';\nimport { serveStdio, type StdioServerHandle } from '@modelcontextprotocol/server/stdio';\nimport type { Carnet } from '../carnet.ts';\nimport { openCarnet, type OpenCarnetOptions } from '../carnet.ts';\nimport { CarnetError } from '../errors.ts';\nimport { INSTRUCTIONS } from './instructions.ts';\nimport {\n createSessionResolver,\n type SessionResolver,\n type SessionResolverOptions,\n} from './session.ts';\nimport { TOOLS } from './tools.ts';\n\nexport const SERVER_NAME = 'carnet';\nexport const SERVER_VERSION = '0.0.0';\n\nexport interface CarnetServerOptions extends Omit<SessionResolverOptions, 'carnet'> {\n carnet: Carnet | (() => Carnet);\n}\n\nfunction errorResult(error: CarnetError): CallToolResult {\n return { isError: true, content: [{ type: 'text', text: `${error.code}: ${error.message}` }] };\n}\n\nexport function createCarnetServer(options: CarnetServerOptions): McpServer {\n let carnet: Carnet | undefined;\n let resolver: SessionResolver | undefined;\n const open = (): { carnet: Carnet; resolver: SessionResolver } => {\n carnet ??= typeof options.carnet === 'function' ? options.carnet() : options.carnet;\n resolver ??= createSessionResolver({ ...options, carnet });\n return { carnet, resolver };\n };\n const server = new McpServer(\n { name: SERVER_NAME, version: SERVER_VERSION },\n { instructions: INSTRUCTIONS },\n );\n for (const tool of TOOLS) {\n server.registerTool(\n tool.name,\n { description: tool.description, inputSchema: tool.schema },\n (args: Record<string, unknown>): CallToolResult => {\n try {\n const { carnet, resolver } = open();\n const sessionId = resolver.resolve(args.session as string | undefined);\n const out = tool.run(carnet, sessionId, args);\n return { content: [{ type: 'text', text: out.text }] };\n } catch (error) {\n if (error instanceof CarnetError) return errorResult(error);\n throw error;\n }\n },\n );\n }\n return server;\n}\n\nexport interface ServeCarnetOptions extends OpenCarnetOptions {\n carnet?: Carnet;\n ppid?: number;\n}\n\nexport function serveCarnet(options: ServeCarnetOptions = {}): StdioServerHandle {\n const carnet = options.carnet ?? (() => openCarnet(options));\n return serveStdio(\n () => createCarnetServer({ carnet, env: options.env, ppid: options.ppid, cwd: options.cwd }),\n { onerror: (error) => console.error(`[carnet] ${error.message}`) },\n );\n}\n"],"mappings":";;;;;;;AAAA,MAAa,eAAe;;;;;;;;;;;;;ACI5B,MAAM,UAAU;AAchB,SAAgB,sBAAsB,EACpC,QACA,MAAM,QAAQ,KACd,OAAO,QAAQ,MACf,MAAM,QAAQ,IAAI,GAClB,OAAO,SAAS,YAAY,KACc;CAG1C,SAAS,aAAqB;EAC5B,MAAM,SAAS,OAAO,SAAS,cAAc,KAAK,IAAI,IAAI;EAC1D,IAAI,QAAQ,OAAO,OAAO;EAC1B,MAAM,kBAAkB,KAAK,yBAAyB,GAAG;EACzD,IAAI,iBAAiB,OAAO,OAAO,SAAS,OAAO,iBAAiB,GAAG,CAAC,CAAC;EACzE,MAAM,IAAI,YACR,cACA,qBAAqB,KAAK,YAAY,4EACxC;CACF;CAEA,SAAS,gBAAgB,UAA0B;EACjD,IAAI;GACF,OAAO,OAAO,SAAS,KAAK,QAAQ,CAAC,CAAC;EACxC,SAAS,OAAO;GACd,IAAI,EAAE,iBAAiB,gBAAgB,MAAM,SAAS,qBAAqB,MAAM;GAEjF,IAAI,QAAQ,KAAK,QAAQ,GAAG,OAAO,OAAO,SAAS,OAAO,UAAU,GAAG,CAAC,CAAC;GACzE,MAAM;EACR;CACF;CAEA,OAAO,EACL,QAAQ,UAAU;EAChB,MAAM,KAAK,WAAW,gBAAgB,QAAQ,IAAI,WAAW;EAC7D,OAAO,SAAS,MAAM,EAAE;EACxB,OAAO;CACT,EACF;AACF;;AChCA,SAAS,WACP,YACwB;CACxB,OAAO;AACT;A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KAAK,MACL;EAAE,aAAa,KAAK;EAAa,aAAa,KAAK;CAAO,IACzD,SAAkD;EACjD,IAAI;GACF,MAAM,EAAE,QAAQ,aAAa,KAAK;GAClC,MAAM,YAAY,SAAS,QAAQ,KAAK,OAA6B;GAErE,OAAO,EAAE,SAAS,CAAC;IAAE,MAAM;IAAQ,MADvB,KAAK,IAAI,QAAQ,WAAW,IACG,CAAC,CAAC;GAAK,CAAC,EAAE;EACvD,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 Main line, sessions, the journal and the workspace 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 launching agents or handling their results.\n\nWhich tool, when:\n- Launch: agent_start with the agent's kind (research, plan, implement, review), then launch it in a later message with Agent, subagent_type fork (or the kind's cold agent), description = the agent name. A plan agent is always a Rucher fork, never the built-in Plan subagent or plan mode.\n- Each step of a fork's work: agent_step (answered, applying, applied, tested, committed, dropped).\n- Next actions, only when the human asks (/rucher:next): agent_report, then agent_inject or agent_promote (research), agent_questions then agent_answer then agent_promote (plan), review_findings then review_decide, then review_brief for each agent started from the findings (review). review_context before launching a review.\n- Main line text for work of your own: 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 🧪. 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 { AGENT_KINDS, KIND_REQUIRED, PROMOTE_KIND_REQUIRED } from '../agents.ts';\nimport { EVENT_TYPES } from '../events.ts';\nimport { FINDING_DECISIONS, FINDING_SEVERITIES, SPAWN_KINDS } from '../findings.ts';\nimport {\n answerQuestionsText,\n decideText,\n kindAction,\n findingsBrief,\n findingsText,\n finishWithItems,\n injectReport,\n nextAgent,\n reportSummary,\n openQuestionsText,\n promoteText,\n reviewContext,\n} from '../kinds.ts';\nimport { MAX_ALTERNATIVES } from '../questions.ts';\nimport { reportPath, reportsDirectory } from '../paths.ts';\nimport { sandboxRemovedSuffix } from '../sandbox.ts';\nimport { hostById } from '../hosts/host.ts';\nimport { memoryHalfLife, type Note, NOTE_KINDS } from '../notes.ts';\nimport { formatEventLine, resumeContext, sessionLabel } from '../resume.ts';\nimport {\n type AgentStatus,\n EMOJI,\n OPEN_AGENT_STATUSES,\n USER_ACTION_STATUSES,\n} 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 workspace, 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 kind: z\n .enum(AGENT_KINDS, { error: KIND_REQUIRED })\n .describe(\n 'Agent type, required: research (reads, reports for the main), plan (plans a wanted change and asks its questions; a Rucher fork, never the built-in Plan subagent), implement (writes code, the only kind with a worktree), review (reads a diff, reports findings)',\n ),\n target: z\n .string()\n .optional()\n .describe('Review only, required there: the implement agent it reviews, or main[:<range>]'),\n base_commit: z.string().optional().describe('Commit the fork starts from'),\n worktree: z.string().optional().describe('Implement only: worktree path when the fork has one'),\n sandbox: z\n .string()\n .optional()\n .describe(\n \"Research or plan only: throwaway folder under the run directory's sandboxes folder, created empty, writable by the agent, removed when it closes\",\n ),\n session,\n }),\n run: (carnet, sessionId, args) => {\n const workspace = carnet.workspace;\n const agent = carnet.agents.start(sessionId, {\n name: args.name,\n task: args.task,\n kind: args.kind,\n target: args.target,\n baseCommit: args.base_commit,\n worktree: args.worktree,\n sandbox: args.sandbox,\n });\n const sandbox = agent.sandbox ? `\\nSandbox: ${agent.sandbox}` : '';\n if (!workspace) {\n return {\n text: `${EMOJI.running} ${agent.name} started outside any workspace\\nNo report destination: the report stays where the fork writes it${sandbox}`,\n };\n }\n mkdirSync(reportsDirectory(workspace), { recursive: true });\n return {\n text: `${EMOJI.running} ${agent.name} started in workspace ${workspace.name}\\nReport destination: ${reportPath(workspace, agent.name)}${sandbox}`,\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, and blocked_on when an agent waits on another agent (never 💬 discussing for that).\",\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 blocked_on: z\n .string()\n .nullable()\n .optional()\n .describe(\n 'Open agent of this session it waits on: it leaves Waiting on you until that agent closes. null clears it',\n ),\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 blockedOn: args.blocked_on,\n });\n const text = renderAgentLine({\n name: agent.name,\n kind: agent.kind,\n status: agent.status,\n action: agent.blockedOn ? `→ ${agent.blockedOn}` : null,\n emoji: agent.status === 'closed' ? '' : EMOJI[agent.status],\n note: agent.note,\n pinned: agent.queueOrder !== null,\n });\n return { text };\n },\n});\n\nfunction copyReport(carnet: Carnet, name: string, reportFile: string): string {\n if (!carnet.workspace) return reportFile;\n const destination = reportPath(carnet.workspace, name);\n if (resolve(reportFile) === destination || !existsSync(reportFile)) return reportFile;\n mkdirSync(reportsDirectory(carnet.workspace), { recursive: true });\n copyFileSync(reportFile, destination);\n return destination;\n}\n\nconst questionInput = z.object({\n text: z.string().min(1),\n context: z.string().optional().describe('One short line'),\n recommendation: z.string().min(1),\n alternatives: z\n .array(z.string().min(1))\n .max(MAX_ALTERNATIVES)\n .optional()\n .describe(`At most ${MAX_ALTERNATIVES}; list more in the text`),\n});\n\nconst findingInput = z.object({\n severity: z.enum(FINDING_SEVERITIES),\n location: z.string().optional().describe('file:line'),\n text: z.string().min(1),\n fix: z.string().optional().describe('Proposed fix, short'),\n});\n\nconst DONE_WORDS: Partial<Record<AgentStatus, string>> = {\n answer: 'needs answers',\n review: 'ready for review',\n apply: 'ready to apply',\n};\n\nfunction doneOutcome(name: string, status: AgentStatus): string {\n if (status === 'closed') return `${name} closed`;\n return `${EMOJI[status]} ${name} ${DONE_WORDS[status] ?? status}`;\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 workspace report destination. Pass questions (and findings for a review) here only, never in the report: Carnet writes them into it. The agent then waits on ❓ answer when questions are open, else 📥 apply (implement) or 👀 review.',\n schema: z.object({\n name: agentName,\n report_path: z.string().min(1).describe('Absolute path of the markdown report'),\n questions: z\n .array(questionInput)\n .optional()\n .describe('Choices left to the human, each with a recommendation'),\n findings: z.array(findingInput).optional().describe('Review agents only'),\n has_questions: z\n .boolean()\n .optional()\n .describe('Only when the report asks something outside questions'),\n session,\n }),\n run: (carnet, sessionId, args) => {\n const agent = finishWithItems(carnet, sessionId, args.name, {\n reportPath: copyReport(carnet, args.name, args.report_path),\n questions: args.questions,\n findings: args.findings,\n hasQuestions: args.has_questions,\n });\n const outcome = doneOutcome(agent.name, agent.pendingStatus ?? agent.status);\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${sandboxRemovedSuffix(agent.sandboxRemoved)}` };\n },\n});\n\nconst agentList = defineTool({\n name: 'agent_list',\n description:\n 'List the open agents of the session: kind, status, next action, note, task and report path.',\n schema: z.object({\n kind: z.enum(AGENT_KINDS).optional().describe('Only agents of this kind'),\n session,\n }),\n run: (carnet, sessionId, args) => {\n const agents = carnet.agents\n .list(sessionId)\n .filter((agent) => !args.kind || agent.kind === args.kind);\n const lines = agents.map((agent) => {\n const emoji = agent.status === 'closed' ? '' : EMOJI[agent.status];\n const action = agent.status === 'running' ? '' : ` → ${kindAction(agent)}`;\n const target = agent.target ? ` on ${agent.target}` : '';\n const blocked = agent.blockedOn ? ` blocked on ${agent.blockedOn}` : '';\n const note = agent.note ? ` — ${agent.note}` : '';\n const report = agent.reportPath ? ` (report: ${agent.reportPath})` : '';\n const sandbox = agent.sandbox ? ` (sandbox: ${agent.sandbox})` : '';\n return `${emoji} ${agent.name} ${agent.kind}${target} [${agent.status}]${blocked}${action}${note}${report}${sandbox}`;\n });\n return { text: lines.length ? lines.join('\\n') : 'no open agents' };\n },\n});\n\nconst agentQuestions = defineTool({\n name: 'agent_questions',\n description:\n \"Main agent only. An agent's open questions, numbered n/total, each with its recommendation and alternatives. Ask them one at a time unless the human wants them as text.\",\n schema: z.object({ name: agentName, session }),\n run: (carnet, sessionId, args) => ({\n text: openQuestionsText(carnet, sessionId, args.name),\n }),\n});\n\nconst agentAnswer = defineTool({\n name: 'agent_answer',\n description:\n \"Main agent only. Record the human's answers, one or several at once. Appends them to the report. With the last answer, logs answered and moves the agent on: a plan agent to 👀 review with its plan to validate, an implement to 📥 apply.\",\n schema: z.object({\n name: agentName,\n answers: z.array(z.object({ n: z.number().int().min(1), answer: z.string().min(1) })).min(1),\n session,\n }),\n run: (carnet, sessionId, args) => ({\n text: answerQuestionsText(carnet, sessionId, args.name, args.answers),\n }),\n});\n\nconst agentInject = defineTool({\n name: 'agent_inject',\n description:\n \"Main agent only, when the human asks. Returns a report section for your context: 'For the main' by default, the plan for a plan or promoted agent. Logs injected; closes a research agent. Works on closed agents.\",\n schema: z.object({\n name: agentName,\n section: z.string().optional().describe('Heading to extract instead of the default'),\n full: z.boolean().optional().describe('The whole report, only when the human asks'),\n echo: z\n .boolean()\n .optional()\n .describe('false: only confirm, when agent_report already showed the section'),\n session,\n }),\n run: (carnet, sessionId, args) => ({\n text: injectReport(carnet, sessionId, args.name, {\n section: args.section,\n full: args.full,\n echo: args.echo,\n }),\n }),\n});\n\nconst agentReport = defineTool({\n name: 'agent_report',\n description:\n \"Main agent only, when the human asks to handle an agent (/rucher:next): picks it (the named one, else the first of Waiting on you) and returns a short summary of its report by kind, read-only. Show it as is, then run the kind's next action.\",\n schema: z.object({\n name: z\n .string()\n .min(1)\n .optional()\n .describe('Agent name or its start; omit for the first agent of Waiting on you'),\n session,\n }),\n run: (carnet, sessionId, args) => {\n const name = nextAgent(carnet, sessionId, args.name);\n return { text: name ? reportSummary(carnet, sessionId, name) : 'Nothing waiting on you.' };\n },\n});\n\nconst agentPromote = defineTool({\n name: 'agent_promote',\n description:\n \"Main agent only, when the human asks. Continues the same agent under another kind: a research into plan or implement, a plan into implement, keeping the previous report beside the new one. For implement, create the worktree first and pass it. Then resume the fork under the new kind's contract.\",\n schema: z.object({\n name: agentName,\n kind: z\n .enum(['plan', 'implement'], { error: PROMOTE_KIND_REQUIRED })\n .describe('Kind the agent becomes: plan or implement'),\n worktree: z.string().optional().describe('Worktree created for the implementation'),\n base_commit: z.string().optional().describe('Commit the worktree starts from'),\n session,\n }),\n run: (carnet, sessionId, args) => ({\n text: promoteText(carnet, sessionId, args.name, {\n kind: args.kind,\n worktree: args.worktree,\n baseCommit: args.base_commit,\n }),\n }),\n});\n\nconst reviewContextTool = defineTool({\n name: 'review_context',\n description:\n 'Main agent only, before launching a review. What the reviewer needs about its target: task, report, worktree, base, plan and answers, or the main repo range.',\n schema: z.object({\n target: z.string().min(1).describe('Implement agent name, or main[:<range>]'),\n session,\n }),\n run: (carnet, sessionId, args) => ({ text: reviewContext(carnet, sessionId, args.target) }),\n});\n\nconst reviewFindings = defineTool({\n name: 'review_findings',\n description:\n \"Main agent only. A review's findings, blocking first, numbered n/total, each pending one with its recommended route (send back, in main, implement, plan, research). Pending ones only by default.\",\n schema: z.object({\n name: agentName,\n all: z.boolean().optional().describe('Also the findings already decided'),\n session,\n }),\n run: (carnet, sessionId, args) => ({\n text: findingsText(carnet, sessionId, args.name, args.all !== true),\n }),\n});\n\nconst reviewDecide = defineTool({\n name: 'review_decide',\n description:\n \"Main agent only. Record the human's decision on findings, one or several at once: sent (back to the implement agent), fixed (in main, or by a new agent: reason '<kind> agent <name>'), ignored (reason required). A finding left for later stays pending. With the last one, logs triaged, closes the review and lists the findings to send to the target.\",\n schema: z.object({\n name: agentName,\n decisions: z\n .array(\n z.object({\n n: z.number().int().min(1),\n decision: z.enum(FINDING_DECISIONS),\n reason: z.string().optional(),\n }),\n )\n .min(1),\n session,\n }),\n run: (carnet, sessionId, args) => ({\n text: decideText(carnet, sessionId, args.name, args.decisions),\n }),\n});\n\nconst reviewBrief = defineTool({\n name: 'review_brief',\n description:\n \"Main agent only, after triage. The brief of an agent started for some of a review's findings: the review, its target and the findings with their location and proposed fix. Put it in the agent's prompt as is, after its kind's contract. Read-only.\",\n schema: z.object({\n name: agentName.describe('The review agent'),\n findings: z.array(z.number().int().min(1)).min(1).describe('Finding numbers of this agent'),\n kind: z.enum(SPAWN_KINDS).describe('Kind of the agent started for them'),\n session,\n }),\n run: (carnet, sessionId, args) => ({\n text: findingsBrief(carnet, sessionId, args.name, args.findings, args.kind),\n }),\n});\n\nconst queueReorder = defineTool({\n name: 'queue_reorder',\n description:\n \"Main agent only, when the human asks. Pin the order of 'Waiting on you': the named agents come first in the given order, each pin lasting until that agent's status changes. The others follow the default order: test, answer, validate, triage, apply, inject, the rest, longest waiting first.\",\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 Main line: what the main agent is handling, and the next human action once its turn ends. The hooks show ⚙️ while the main agent works, whatever this line says.',\n schema: z.object({\n text: z.string().min(1).describe('Under 60 characters, no paths, no backticks'),\n status: z\n .enum(USER_ACTION_STATUSES)\n .optional()\n .describe('Next human action once the turn ends; defaults to discussing'),\n session,\n }),\n run: (carnet, sessionId, args) => {\n const item = carnet.table.set(sessionId, { text: args.text, status: args.status });\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 Main line in sync; the note replaces the agent's note. answered → apply (implement) or review, applying → Main line (implement only), applied → test, tested (optional) stays on test, 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 Main line.',\n schema: z.object({ session }),\n run: (carnet, sessionId) => {\n carnet.table.clear(sessionId);\n return { text: 'Main line 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 workspace'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} --ws ${target.workspace}`;\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 workspace 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 workspace'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 workspace; 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 workspace'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 agentQuestions,\n agentAnswer,\n agentInject,\n agentReport,\n agentPromote,\n reviewContextTool,\n reviewFindings,\n reviewDecide,\n reviewBrief,\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 afterTool?: ((carnet: Carnet, sessionId: string) => void) | undefined;\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 options.afterTool?.(carnet, sessionId);\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 afterTool?: CarnetServerOptions['afterTool'];\n}\n\nexport function serveCarnet(options: ServeCarnetOptions = {}): StdioServerHandle {\n const carnet = options.carnet ?? (() => openCarnet(options));\n return serveStdio(\n () =>\n createCarnetServer({\n carnet,\n env: options.env,\n ppid: options.ppid,\n cwd: options.cwd,\n afterTool: options.afterTool,\n }),\n { onerror: (error) => console.error(`[carnet] ${error.message}`) },\n );\n}\n"],"mappings":";;;;;;;AAAA,MAAa,eAAe;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