@rucher/carnet 0.2.0-beta.6 → 0.2.0-beta.8
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-MC9WeQ6h.d.mts} +162 -42
- package/dist/carnet-MC9WeQ6h.d.mts.map +1 -0
- package/dist/index.d.mts +33 -8
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs +165 -7
- 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 +337 -27
- package/dist/mcp.mjs.map +1 -1
- package/dist/{steps-4ZTrBzcd.mjs → steps-xzr8iVWn.mjs} +644 -137
- package/dist/steps-xzr8iVWn.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 { E as renderTableLine,
|
|
2
|
-
import { copyFileSync, existsSync, mkdirSync } from "node:fs";
|
|
1
|
+
import { E as renderAgentLine, Jt as renderQuestions, K as memoryHalfLife, N as renderTableLine, Nn as OPEN_AGENT_STATUSES, Pn as USER_ACTION_STATUSES, Qt as renderFindings, Rn as EVENT_TYPES, Tn as EMOJI, V as NOTE_KINDS, Vn as CarnetError, Xt as FINDING_SEVERITIES, Yt as FINDING_DECISIONS, Zt as formatFinding, a as formatEventLine, bn as statusAfterAnswers, hn as FINAL_ACTIONS, in as reportsDirectory, l as openCarnet, lt as hostById, n as stepAgent, o as resumeContext, pn as AGENT_KINDS, rn as reportPath, s as sessionLabel, st as DEFAULT_HOST, t as AGENT_STEPS, yn as mainTargetRange } from "./steps-xzr8iVWn.mjs";
|
|
2
|
+
import { appendFileSync, copyFileSync, existsSync, mkdirSync, readFileSync } 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, analyze, implement, review), then launch it in a later message.
|
|
12
12
|
- Each step of a fork's work: agent_step (answered, applying, applied, tested, committed, dropped).
|
|
13
|
-
-
|
|
13
|
+
- Final actions, only when the human asks: agent_inject (research), agent_questions then agent_answer then agent_promote (analyze), review_findings then review_decide (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) }) {
|
|
@@ -42,6 +43,185 @@ function createSessionResolver({ carnet, env = process.env, ppid = process.ppid,
|
|
|
42
43
|
return id;
|
|
43
44
|
} };
|
|
44
45
|
}
|
|
46
|
+
// src/report.ts
|
|
47
|
+
const HEADING = /^##\s+(.+?)\s*$/;
|
|
48
|
+
function normalize(text) {
|
|
49
|
+
return text.toLowerCase().normalize("NFD").replace(/[̀-ͯ]/g, "");
|
|
50
|
+
}
|
|
51
|
+
function hasSection(markdown, names) {
|
|
52
|
+
return extractSection(markdown, names) !== void 0;
|
|
53
|
+
}
|
|
54
|
+
function extractSection(markdown, names) {
|
|
55
|
+
const wanted = names.map(normalize);
|
|
56
|
+
const lines = markdown.split("\n");
|
|
57
|
+
const start = lines.findIndex((line) => {
|
|
58
|
+
const heading = HEADING.exec(line)?.[1];
|
|
59
|
+
return heading !== void 0 && wanted.some((name) => normalize(heading).includes(name));
|
|
60
|
+
});
|
|
61
|
+
if (start === -1) return void 0;
|
|
62
|
+
const rest = lines.slice(start + 1);
|
|
63
|
+
const end = rest.findIndex((line) => HEADING.test(line));
|
|
64
|
+
return (end === -1 ? rest : rest.slice(0, end)).join("\n").trim();
|
|
65
|
+
}
|
|
66
|
+
function readReport(path) {
|
|
67
|
+
return path && existsSync(path) ? readFileSync(path, "utf8") : void 0;
|
|
68
|
+
}
|
|
69
|
+
function appendToReport(path, markdown) {
|
|
70
|
+
const current = readReport(path);
|
|
71
|
+
if (current === void 0 || !path) return;
|
|
72
|
+
const separator = current.endsWith("\n\n") ? "" : current.endsWith("\n") ? "\n" : "\n\n";
|
|
73
|
+
appendFileSync(path, `${separator}${markdown.trimEnd()}\n`);
|
|
74
|
+
}
|
|
75
|
+
function planPath(report) {
|
|
76
|
+
return report.replace(/(\.md)?$/, ".plan.md");
|
|
77
|
+
}
|
|
78
|
+
// src/kinds.ts
|
|
79
|
+
function finalAction(agent) {
|
|
80
|
+
return FINAL_ACTIONS[agent.kind];
|
|
81
|
+
}
|
|
82
|
+
function finishWithItems(carnet, session, name, input) {
|
|
83
|
+
const agent = requireAgent(carnet, session, name);
|
|
84
|
+
if (input.findings?.length && agent.kind !== "review") throw new CarnetError("INVALID_KIND", `Only a review agent reports findings; ${name} is ${agent.kind}`);
|
|
85
|
+
const report = readReport(input.reportPath);
|
|
86
|
+
if (input.questions?.length) {
|
|
87
|
+
const open = carnet.questions.add(session, name, input.questions).filter((question) => question.answer === null);
|
|
88
|
+
if (report !== void 0 && !hasSection(report, ["questions"])) appendToReport(input.reportPath, renderQuestions(open));
|
|
89
|
+
}
|
|
90
|
+
if (input.findings?.length) {
|
|
91
|
+
const findings = carnet.findings.replace(session, name, input.findings);
|
|
92
|
+
if (report !== void 0 && !hasSection(report, ["findings"])) appendToReport(input.reportPath, renderFindings(findings));
|
|
93
|
+
}
|
|
94
|
+
const openQuestions = carnet.questions.list(session, name, true).length;
|
|
95
|
+
return carnet.agents.finish(session, name, {
|
|
96
|
+
reportPath: input.reportPath,
|
|
97
|
+
hasQuestions: openQuestions > 0 || input.hasQuestions === true
|
|
98
|
+
});
|
|
99
|
+
}
|
|
100
|
+
function requireAgent(carnet, session, name) {
|
|
101
|
+
const agent = carnet.agents.get(session, name);
|
|
102
|
+
if (!agent) throw new CarnetError("AGENT_NOT_FOUND", `No agent "${name}" in this session`);
|
|
103
|
+
return agent;
|
|
104
|
+
}
|
|
105
|
+
function formatQuestion(question) {
|
|
106
|
+
const lines = [`${question.n}/${question.total} ${question.text}`];
|
|
107
|
+
if (question.context) lines.push(` context: ${question.context}`);
|
|
108
|
+
lines.push(` recommended: ${question.recommendation}`);
|
|
109
|
+
if (question.alternatives.length) lines.push(` alternatives: ${question.alternatives.join(" | ")}`);
|
|
110
|
+
return lines.join("\n");
|
|
111
|
+
}
|
|
112
|
+
function openQuestionsText(carnet, session, name) {
|
|
113
|
+
requireAgent(carnet, session, name);
|
|
114
|
+
const open = carnet.questions.list(session, name, true);
|
|
115
|
+
if (!open.length) return `${name}: no open questions`;
|
|
116
|
+
const total = open[0]?.total ?? open.length;
|
|
117
|
+
return [`${name}: ${open.length} of ${total} open`, ...open.map(formatQuestion)].join("\n");
|
|
118
|
+
}
|
|
119
|
+
function today(carnet) {
|
|
120
|
+
return carnet.now().toISOString().slice(0, 10);
|
|
121
|
+
}
|
|
122
|
+
function answerQuestionsText(carnet, session, name, answers) {
|
|
123
|
+
const agent = requireAgent(carnet, session, name);
|
|
124
|
+
const questions = carnet.questions.answer(session, name, answers);
|
|
125
|
+
const lines = [...answers].sort((a, b) => a.n - b.n).map((answer) => `${answer.n}. ${answer.answer.trim()}`);
|
|
126
|
+
appendToReport(agent.reportPath, `## Answers (${today(carnet)})\n\n${lines.join("\n")}`);
|
|
127
|
+
const open = questions.filter((question) => question.answer === null).length;
|
|
128
|
+
if (open) return `answered ${answers.length} · ${open} of ${questions.length} open`;
|
|
129
|
+
const next = statusAfterAnswers(agent.kind);
|
|
130
|
+
carnet.events.log(session, {
|
|
131
|
+
type: "answered",
|
|
132
|
+
agent: name
|
|
133
|
+
});
|
|
134
|
+
carnet.agents.update(session, name, {
|
|
135
|
+
status: next,
|
|
136
|
+
note: null
|
|
137
|
+
});
|
|
138
|
+
return `all ${questions.length} answered · ${EMOJI[next]} ${name} ${next}`;
|
|
139
|
+
}
|
|
140
|
+
const FOR_MAIN = ["for the main", "pour le main"];
|
|
141
|
+
const PLAN = ["plan"];
|
|
142
|
+
function injectReport(carnet, session, name, input) {
|
|
143
|
+
const agent = requireAgent(carnet, session, name);
|
|
144
|
+
const report = readReport(agent.reportPath);
|
|
145
|
+
if (report === void 0) throw new CarnetError("REPORT_MISSING", `${name} has no report to inject yet`);
|
|
146
|
+
const names = input.section ? [input.section] : agent.kind === "analyze" || agent.promotedFrom === "analyze" ? PLAN : FOR_MAIN;
|
|
147
|
+
const text = input.full ? report.trim() : extractSection(report, names);
|
|
148
|
+
if (text === void 0) throw new CarnetError("SECTION_NOT_FOUND", `No "## ${names[0]}" section in ${name}'s report; pass section or full`);
|
|
149
|
+
const lineCount = text.split("\n").length;
|
|
150
|
+
const note = `${input.full ? "full report" : names[0]}, ${lineCount} lines`;
|
|
151
|
+
if (agent.kind === "research" && agent.status !== "closed") carnet.agents.close(session, name, {
|
|
152
|
+
type: "injected",
|
|
153
|
+
note,
|
|
154
|
+
link: agent.reportPath ?? void 0
|
|
155
|
+
});
|
|
156
|
+
else carnet.events.log(session, {
|
|
157
|
+
type: "injected",
|
|
158
|
+
agent: name,
|
|
159
|
+
note
|
|
160
|
+
});
|
|
161
|
+
return `${name} injected (${lineCount} lines)\n${text}`;
|
|
162
|
+
}
|
|
163
|
+
function promoteText(carnet, session, name, input) {
|
|
164
|
+
const current = requireAgent(carnet, session, name);
|
|
165
|
+
const agent = carnet.agents.promote(session, name, input);
|
|
166
|
+
const lines = [`${EMOJI.running} ${name} promoted to implement`];
|
|
167
|
+
if (current.reportPath && existsSync(current.reportPath)) {
|
|
168
|
+
const plan = planPath(current.reportPath);
|
|
169
|
+
copyFileSync(current.reportPath, plan);
|
|
170
|
+
lines.push(`plan kept: ${plan}`);
|
|
171
|
+
}
|
|
172
|
+
if (agent.worktree) lines.push(`worktree: ${agent.worktree}`);
|
|
173
|
+
if (agent.baseCommit) lines.push(`base: ${agent.baseCommit}`);
|
|
174
|
+
return lines.join("\n");
|
|
175
|
+
}
|
|
176
|
+
function reviewContext(carnet, session, target) {
|
|
177
|
+
const range = mainTargetRange(target);
|
|
178
|
+
if (range !== void 0) return range ? `target main, commits ${range}` : "target main, the uncommitted changes of the main repo";
|
|
179
|
+
const agent = requireAgent(carnet, session, target);
|
|
180
|
+
if (agent.kind !== "implement") throw new CarnetError("INVALID_TARGET", `${target} is ${agent.kind}, not implement`);
|
|
181
|
+
const lines = [`target ${target} (implement${agent.promotedFrom ? `, promoted from ${agent.promotedFrom}` : ""}, ${agent.status})`];
|
|
182
|
+
if (agent.task) lines.push(`task: ${agent.task}`);
|
|
183
|
+
if (agent.reportPath) lines.push(`report: ${agent.reportPath}`);
|
|
184
|
+
if (agent.worktree) lines.push(`worktree: ${agent.worktree}`);
|
|
185
|
+
if (agent.baseCommit) lines.push(`base: ${agent.baseCommit}`);
|
|
186
|
+
if (agent.reportPath && existsSync(planPath(agent.reportPath))) lines.push(`plan: ${planPath(agent.reportPath)}`);
|
|
187
|
+
const answered = carnet.questions.list(session, target).filter((question) => question.answer);
|
|
188
|
+
if (answered.length) {
|
|
189
|
+
lines.push("answers:");
|
|
190
|
+
for (const question of answered) lines.push(` ${question.n}. ${question.text} → ${question.answer}`);
|
|
191
|
+
}
|
|
192
|
+
return lines.join("\n");
|
|
193
|
+
}
|
|
194
|
+
function findingsText(carnet, session, name, pendingOnly) {
|
|
195
|
+
const agent = requireAgent(carnet, session, name);
|
|
196
|
+
const findings = carnet.findings.list(session, name, pendingOnly);
|
|
197
|
+
const all = carnet.findings.list(session, name);
|
|
198
|
+
if (!findings.length) return `${name}: ${all.length ? "no pending findings" : "no findings"}`;
|
|
199
|
+
const pending = all.filter((finding) => finding.decision === null).length;
|
|
200
|
+
const target = agent.target ? ` · target ${agent.target}` : "";
|
|
201
|
+
return [`${name}: ${pending} of ${all.length} pending${target}`, ...findings.map((finding) => {
|
|
202
|
+
const decided = finding.decision ? ` → ${finding.decision}` : "";
|
|
203
|
+
return `${formatFinding(finding)}${decided}`;
|
|
204
|
+
})].join("\n");
|
|
205
|
+
}
|
|
206
|
+
function decideText(carnet, session, name, decisions) {
|
|
207
|
+
const agent = requireAgent(carnet, session, name);
|
|
208
|
+
if (agent.kind !== "review") throw new CarnetError("INVALID_KIND", `${name} is ${agent.kind}, not review`);
|
|
209
|
+
if (decisions.some((item) => item.decision === "sent") && agent.target && mainTargetRange(agent.target) !== void 0) throw new CarnetError("INVALID_TARGET", `${name} reviews main: there is no agent to send findings to; fix or ignore them`);
|
|
210
|
+
const findings = carnet.findings.decide(session, name, decisions);
|
|
211
|
+
const pending = findings.filter((finding) => finding.decision === null).length;
|
|
212
|
+
if (pending) return `decided ${decisions.length} · ${pending} of ${findings.length} pending`;
|
|
213
|
+
const count = (decision) => findings.filter((finding) => finding.decision === decision).length;
|
|
214
|
+
const note = `${count("sent")} sent, ${count("fixed")} fixed, ${count("ignored")} ignored`;
|
|
215
|
+
carnet.agents.close(session, name, {
|
|
216
|
+
type: "triaged",
|
|
217
|
+
note,
|
|
218
|
+
link: agent.reportPath ?? void 0
|
|
219
|
+
});
|
|
220
|
+
const lines = [`${name} triaged: ${note}, closed`];
|
|
221
|
+
const sent = findings.filter((finding) => finding.decision === "sent");
|
|
222
|
+
if (sent.length && agent.target) lines.push(`send to ${agent.target}:`, ...sent.map(formatFinding));
|
|
223
|
+
return lines.join("\n");
|
|
224
|
+
}
|
|
45
225
|
// src/mcp/tools.ts
|
|
46
226
|
function defineTool(definition) {
|
|
47
227
|
return definition;
|
|
@@ -54,6 +234,8 @@ const agentStart = defineTool({
|
|
|
54
234
|
schema: z.object({
|
|
55
235
|
name: agentName,
|
|
56
236
|
task: z.string().min(1).describe("One-line task given to the fork"),
|
|
237
|
+
kind: z.enum(AGENT_KINDS).optional().describe("Agent type, always pass it: research (reads, reports for the main), analyze (plan and questions), implement (writes code), review (reads a diff, reports findings)"),
|
|
238
|
+
target: z.string().optional().describe("Review only, required there: the implement agent it reviews, or main[:<range>]"),
|
|
57
239
|
base_commit: z.string().optional().describe("Commit the fork starts from"),
|
|
58
240
|
worktree: z.string().optional().describe("Worktree path when the fork has one"),
|
|
59
241
|
session
|
|
@@ -63,6 +245,8 @@ const agentStart = defineTool({
|
|
|
63
245
|
const agent = carnet.agents.start(sessionId, {
|
|
64
246
|
name: args.name,
|
|
65
247
|
task: args.task,
|
|
248
|
+
kind: args.kind,
|
|
249
|
+
target: args.target,
|
|
66
250
|
baseCommit: args.base_commit,
|
|
67
251
|
worktree: args.worktree
|
|
68
252
|
});
|
|
@@ -73,23 +257,27 @@ const agentStart = defineTool({
|
|
|
73
257
|
});
|
|
74
258
|
const agentUpdate = defineTool({
|
|
75
259
|
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.",
|
|
260
|
+
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
261
|
schema: z.object({
|
|
78
262
|
name: agentName,
|
|
79
263
|
status: z.enum(OPEN_AGENT_STATUSES).describe("Next action: running means the fork is working"),
|
|
80
264
|
note: z.string().optional().describe("Under 60 characters, no paths, no backticks"),
|
|
81
265
|
report_path: z.string().optional().describe("New absolute path of the report, when it moved"),
|
|
266
|
+
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
267
|
session
|
|
83
268
|
}),
|
|
84
269
|
run: (carnet, sessionId, args) => {
|
|
85
270
|
const agent = carnet.agents.update(sessionId, args.name, {
|
|
86
271
|
status: args.status,
|
|
87
272
|
note: args.note,
|
|
88
|
-
reportPath: args.report_path
|
|
273
|
+
reportPath: args.report_path,
|
|
274
|
+
blockedOn: args.blocked_on
|
|
89
275
|
});
|
|
90
276
|
return { text: renderAgentLine({
|
|
91
277
|
name: agent.name,
|
|
278
|
+
kind: agent.kind,
|
|
92
279
|
status: agent.status,
|
|
280
|
+
action: agent.blockedOn ? `→ ${agent.blockedOn}` : null,
|
|
93
281
|
emoji: agent.status === "closed" ? "" : EMOJI[agent.status],
|
|
94
282
|
note: agent.note
|
|
95
283
|
}) };
|
|
@@ -103,21 +291,46 @@ function copyReport(carnet, name, reportFile) {
|
|
|
103
291
|
copyFileSync(reportFile, destination);
|
|
104
292
|
return destination;
|
|
105
293
|
}
|
|
294
|
+
const questionInput = z.object({
|
|
295
|
+
text: z.string().min(1),
|
|
296
|
+
context: z.string().optional().describe("One short line"),
|
|
297
|
+
recommendation: z.string().min(1),
|
|
298
|
+
alternatives: z.array(z.string().min(1)).max(3).optional().describe(`At most 3; list more in the text`)
|
|
299
|
+
});
|
|
300
|
+
const findingInput = z.object({
|
|
301
|
+
severity: z.enum(FINDING_SEVERITIES),
|
|
302
|
+
location: z.string().optional().describe("file:line"),
|
|
303
|
+
text: z.string().min(1),
|
|
304
|
+
fix: z.string().optional().describe("Proposed fix, short")
|
|
305
|
+
});
|
|
306
|
+
const DONE_WORDS = {
|
|
307
|
+
answer: "needs answers",
|
|
308
|
+
review: "ready for review",
|
|
309
|
+
apply: "ready to apply"
|
|
310
|
+
};
|
|
311
|
+
function doneOutcome(name, status) {
|
|
312
|
+
if (status === "closed") return `${name} closed`;
|
|
313
|
+
return `${EMOJI[status]} ${name} ${DONE_WORDS[status] ?? status}`;
|
|
314
|
+
}
|
|
106
315
|
const agentDone = defineTool({
|
|
107
316
|
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
|
|
317
|
+
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
318
|
schema: z.object({
|
|
110
319
|
name: agentName,
|
|
111
320
|
report_path: z.string().min(1).describe("Absolute path of the markdown report"),
|
|
112
|
-
|
|
321
|
+
questions: z.array(questionInput).optional().describe("Choices left to the human, each with a recommendation"),
|
|
322
|
+
findings: z.array(findingInput).optional().describe("Review agents only"),
|
|
323
|
+
has_questions: z.boolean().optional().describe("Only when the report asks something outside questions"),
|
|
113
324
|
session
|
|
114
325
|
}),
|
|
115
326
|
run: (carnet, sessionId, args) => {
|
|
116
|
-
const agent = carnet
|
|
327
|
+
const agent = finishWithItems(carnet, sessionId, args.name, {
|
|
117
328
|
reportPath: copyReport(carnet, args.name, args.report_path),
|
|
329
|
+
questions: args.questions,
|
|
330
|
+
findings: args.findings,
|
|
118
331
|
hasQuestions: args.has_questions
|
|
119
332
|
});
|
|
120
|
-
const outcome =
|
|
333
|
+
const outcome = doneOutcome(agent.name, agent.pendingStatus ?? agent.status);
|
|
121
334
|
return { text: agent.status === "running" ? `${outcome} once you stop; reply now with one line that carries no results` : outcome };
|
|
122
335
|
}
|
|
123
336
|
});
|
|
@@ -135,18 +348,107 @@ const agentDrop = defineTool({
|
|
|
135
348
|
});
|
|
136
349
|
const agentList = defineTool({
|
|
137
350
|
name: "agent_list",
|
|
138
|
-
description: "List the open agents of the session
|
|
139
|
-
schema: z.object({
|
|
140
|
-
|
|
141
|
-
|
|
351
|
+
description: "List the open agents of the session: kind, status, final action, note, task and report path.",
|
|
352
|
+
schema: z.object({
|
|
353
|
+
kind: z.enum(AGENT_KINDS).optional().describe("Only agents of this kind"),
|
|
354
|
+
session
|
|
355
|
+
}),
|
|
356
|
+
run: (carnet, sessionId, args) => {
|
|
357
|
+
const lines = carnet.agents.list(sessionId).filter((agent) => !args.kind || agent.kind === args.kind).map((agent) => {
|
|
142
358
|
const emoji = agent.status === "closed" ? "" : EMOJI[agent.status];
|
|
359
|
+
const action = agent.status === "running" ? "" : ` → ${finalAction(agent)}`;
|
|
360
|
+
const target = agent.target ? ` on ${agent.target}` : "";
|
|
361
|
+
const blocked = agent.blockedOn ? ` blocked on ${agent.blockedOn}` : "";
|
|
143
362
|
const note = agent.note ? ` — ${agent.note}` : "";
|
|
144
363
|
const report = agent.reportPath ? ` (report: ${agent.reportPath})` : "";
|
|
145
|
-
return `${emoji} ${agent.name} [${agent.status}]${note}${report}`;
|
|
364
|
+
return `${emoji} ${agent.name} ${agent.kind}${target} [${agent.status}]${blocked}${action}${note}${report}`;
|
|
146
365
|
});
|
|
147
366
|
return { text: lines.length ? lines.join("\n") : "no open agents" };
|
|
148
367
|
}
|
|
149
368
|
});
|
|
369
|
+
const agentQuestions = defineTool({
|
|
370
|
+
name: "agent_questions",
|
|
371
|
+
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.",
|
|
372
|
+
schema: z.object({
|
|
373
|
+
name: agentName,
|
|
374
|
+
session
|
|
375
|
+
}),
|
|
376
|
+
run: (carnet, sessionId, args) => ({ text: openQuestionsText(carnet, sessionId, args.name) })
|
|
377
|
+
});
|
|
378
|
+
const agentAnswer = defineTool({
|
|
379
|
+
name: "agent_answer",
|
|
380
|
+
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: an analyze to 👀 review with its plan to validate, an implement to 📥 apply.",
|
|
381
|
+
schema: z.object({
|
|
382
|
+
name: agentName,
|
|
383
|
+
answers: z.array(z.object({
|
|
384
|
+
n: z.number().int().min(1),
|
|
385
|
+
answer: z.string().min(1)
|
|
386
|
+
})).min(1),
|
|
387
|
+
session
|
|
388
|
+
}),
|
|
389
|
+
run: (carnet, sessionId, args) => ({ text: answerQuestionsText(carnet, sessionId, args.name, args.answers) })
|
|
390
|
+
});
|
|
391
|
+
const agentInject = defineTool({
|
|
392
|
+
name: "agent_inject",
|
|
393
|
+
description: "Main agent only, when the human asks. Returns a report section for your context: 'For the main' by default, the plan for an analyze or promoted agent. Logs injected; closes a research agent. Works on closed agents.",
|
|
394
|
+
schema: z.object({
|
|
395
|
+
name: agentName,
|
|
396
|
+
section: z.string().optional().describe("Heading to extract instead of the default"),
|
|
397
|
+
full: z.boolean().optional().describe("The whole report, only when the human asks"),
|
|
398
|
+
session
|
|
399
|
+
}),
|
|
400
|
+
run: (carnet, sessionId, args) => ({ text: injectReport(carnet, sessionId, args.name, {
|
|
401
|
+
section: args.section,
|
|
402
|
+
full: args.full
|
|
403
|
+
}) })
|
|
404
|
+
});
|
|
405
|
+
const agentPromote = defineTool({
|
|
406
|
+
name: "agent_promote",
|
|
407
|
+
description: "Main agent only, when the human validates a plan. Turns an analyze agent into implement (same agent, running) and keeps its plan next to the report. Create the worktree first and pass it, then resume the fork with the answers.",
|
|
408
|
+
schema: z.object({
|
|
409
|
+
name: agentName,
|
|
410
|
+
worktree: z.string().optional().describe("Worktree created for the implementation"),
|
|
411
|
+
base_commit: z.string().optional().describe("Commit the worktree starts from"),
|
|
412
|
+
session
|
|
413
|
+
}),
|
|
414
|
+
run: (carnet, sessionId, args) => ({ text: promoteText(carnet, sessionId, args.name, {
|
|
415
|
+
worktree: args.worktree,
|
|
416
|
+
baseCommit: args.base_commit
|
|
417
|
+
}) })
|
|
418
|
+
});
|
|
419
|
+
const reviewContextTool = defineTool({
|
|
420
|
+
name: "review_context",
|
|
421
|
+
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.",
|
|
422
|
+
schema: z.object({
|
|
423
|
+
target: z.string().min(1).describe("Implement agent name, or main[:<range>]"),
|
|
424
|
+
session
|
|
425
|
+
}),
|
|
426
|
+
run: (carnet, sessionId, args) => ({ text: reviewContext(carnet, sessionId, args.target) })
|
|
427
|
+
});
|
|
428
|
+
const reviewFindings = defineTool({
|
|
429
|
+
name: "review_findings",
|
|
430
|
+
description: "Main agent only. A review's findings, blocking first, numbered n/total. Pending ones only by default.",
|
|
431
|
+
schema: z.object({
|
|
432
|
+
name: agentName,
|
|
433
|
+
all: z.boolean().optional().describe("Also the findings already decided"),
|
|
434
|
+
session
|
|
435
|
+
}),
|
|
436
|
+
run: (carnet, sessionId, args) => ({ text: findingsText(carnet, sessionId, args.name, args.all !== true) })
|
|
437
|
+
});
|
|
438
|
+
const reviewDecide = defineTool({
|
|
439
|
+
name: "review_decide",
|
|
440
|
+
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), ignored (reason required). With the last one, logs triaged, closes the review and lists the findings to send to the target.",
|
|
441
|
+
schema: z.object({
|
|
442
|
+
name: agentName,
|
|
443
|
+
decisions: z.array(z.object({
|
|
444
|
+
n: z.number().int().min(1),
|
|
445
|
+
decision: z.enum(FINDING_DECISIONS),
|
|
446
|
+
reason: z.string().optional()
|
|
447
|
+
})).min(1),
|
|
448
|
+
session
|
|
449
|
+
}),
|
|
450
|
+
run: (carnet, sessionId, args) => ({ text: decideText(carnet, sessionId, args.name, args.decisions) })
|
|
451
|
+
});
|
|
150
452
|
const queueReorder = defineTool({
|
|
151
453
|
name: "queue_reorder",
|
|
152
454
|
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).",
|
|
@@ -162,17 +464,15 @@ const queueReorder = defineTool({
|
|
|
162
464
|
});
|
|
163
465
|
const tableSet = defineTool({
|
|
164
466
|
name: "table_set",
|
|
165
|
-
description: "Main agent only. Set the
|
|
467
|
+
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
468
|
schema: z.object({
|
|
167
469
|
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"),
|
|
470
|
+
status: z.enum(USER_ACTION_STATUSES).optional().describe("Next human action once the turn ends; defaults to discussing"),
|
|
170
471
|
session
|
|
171
472
|
}),
|
|
172
473
|
run: (carnet, sessionId, args) => {
|
|
173
474
|
const item = carnet.table.set(sessionId, {
|
|
174
475
|
text: args.text,
|
|
175
|
-
mainWorking: args.main_working,
|
|
176
476
|
status: args.status
|
|
177
477
|
});
|
|
178
478
|
return { text: renderTableLine(item) };
|
|
@@ -180,7 +480,7 @@ const tableSet = defineTool({
|
|
|
180
480
|
});
|
|
181
481
|
const agentStep = defineTool({
|
|
182
482
|
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
|
|
483
|
+
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
484
|
schema: z.object({
|
|
185
485
|
name: agentName,
|
|
186
486
|
step: z.enum(AGENT_STEPS),
|
|
@@ -193,11 +493,11 @@ const agentStep = defineTool({
|
|
|
193
493
|
});
|
|
194
494
|
const tableClear = defineTool({
|
|
195
495
|
name: "table_clear",
|
|
196
|
-
description: "Main agent only. Empty the
|
|
496
|
+
description: "Main agent only. Empty the Main line.",
|
|
197
497
|
schema: z.object({ session }),
|
|
198
498
|
run: (carnet, sessionId) => {
|
|
199
499
|
carnet.table.clear(sessionId);
|
|
200
|
-
return { text: "
|
|
500
|
+
return { text: "Main line cleared" };
|
|
201
501
|
}
|
|
202
502
|
});
|
|
203
503
|
const logEvent = defineTool({
|
|
@@ -281,7 +581,7 @@ const sessionResumeInfo = defineTool({
|
|
|
281
581
|
}),
|
|
282
582
|
run: (carnet, sessionId, args) => {
|
|
283
583
|
const target = args.name ? carnet.sessions.find(args.name) : carnet.sessions.require(sessionId);
|
|
284
|
-
const resume = `rucher resume ${target.name ?? target.id}`;
|
|
584
|
+
const resume = `rucher resume ${target.name ?? target.id} --ws ${target.workspace}`;
|
|
285
585
|
return { text: `${resumeContext(carnet, target)}\n\nResume with: ${resume}` };
|
|
286
586
|
}
|
|
287
587
|
});
|
|
@@ -309,6 +609,13 @@ const TOOLS = [
|
|
|
309
609
|
agentDrop,
|
|
310
610
|
agentStep,
|
|
311
611
|
agentList,
|
|
612
|
+
agentQuestions,
|
|
613
|
+
agentAnswer,
|
|
614
|
+
agentInject,
|
|
615
|
+
agentPromote,
|
|
616
|
+
reviewContextTool,
|
|
617
|
+
reviewFindings,
|
|
618
|
+
reviewDecide,
|
|
312
619
|
queueReorder,
|
|
313
620
|
tableSet,
|
|
314
621
|
tableClear,
|
|
@@ -438,9 +745,11 @@ function createCarnetServer(options) {
|
|
|
438
745
|
try {
|
|
439
746
|
const { carnet, resolver } = open();
|
|
440
747
|
const sessionId = resolver.resolve(args.session);
|
|
748
|
+
const out = tool.run(carnet, sessionId, args);
|
|
749
|
+
options.afterTool?.(carnet, sessionId);
|
|
441
750
|
return { content: [{
|
|
442
751
|
type: "text",
|
|
443
|
-
text:
|
|
752
|
+
text: out.text
|
|
444
753
|
}] };
|
|
445
754
|
} catch (error) {
|
|
446
755
|
if (error instanceof CarnetError) return errorResult(error);
|
|
@@ -455,7 +764,8 @@ function serveCarnet(options = {}) {
|
|
|
455
764
|
carnet,
|
|
456
765
|
env: options.env,
|
|
457
766
|
ppid: options.ppid,
|
|
458
|
-
cwd: options.cwd
|
|
767
|
+
cwd: options.cwd,
|
|
768
|
+
afterTool: options.afterTool
|
|
459
769
|
}), { onerror: (error) => console.error(`[carnet] ${error.message}`) });
|
|
460
770
|
}
|
|
461
771
|
export { INSTRUCTIONS, SERVER_NAME, SERVER_VERSION, TOOLS, createCarnetServer, createSessionResolver, serveCarnet };
|