@rucher/carnet 0.2.0-beta.7 → 0.2.0-beta.9
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-jmxAmm-u.d.mts → carnet-DcHESFRd.d.mts} +46 -16
- package/dist/carnet-DcHESFRd.d.mts.map +1 -0
- package/dist/index.d.mts +27 -6
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs +152 -18
- 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 +132 -45
- package/dist/mcp.mjs.map +1 -1
- package/dist/{steps-Bd8FlgLs.mjs → steps-wNm8GU_c.mjs} +388 -87
- package/dist/steps-wNm8GU_c.mjs.map +1 -0
- package/package.json +1 -1
- package/dist/carnet-jmxAmm-u.d.mts.map +0 -1
- package/dist/steps-Bd8FlgLs.mjs.map +0 -1
package/dist/mcp.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { $t as renderFindings, Cn as mainTargetRange, E as renderAgentLine, Gn as CarnetError, H as NOTE_KINDS, Hn as EVENT_TYPES, I as sandboxRemovedSuffix, Ln as OPEN_AGENT_STATUSES, N as renderTableLine, Qt as formatFinding, Rn as USER_ACTION_STATUSES, Vn as kindTag, Xt as FINDING_DECISIONS, Yt as renderQuestions, Zt as FINDING_SEVERITIES, _n as KIND_REQUIRED, a as formatEventLine, an as reportsDirectory, ct as DEFAULT_HOST, gn as KIND_ACTIONS, hn as AGENT_KINDS, in as reportPath, kn as EMOJI, l as openCarnet, n as stepAgent, o as resumeContext, q as memoryHalfLife, s as sessionLabel, t as AGENT_STEPS, ut as hostById, vn as PROMOTE_KIND_REQUIRED, wn as statusAfterAnswers } from "./steps-wNm8GU_c.mjs";
|
|
2
2
|
import { appendFileSync, copyFileSync, existsSync, mkdirSync, readFileSync } from "node:fs";
|
|
3
3
|
import { resolve } from "node:path";
|
|
4
4
|
import { McpServer } from "@modelcontextprotocol/server";
|
|
@@ -8,16 +8,16 @@ import * as z from "zod/v4";
|
|
|
8
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
|
-
- Launch: agent_start with the agent's kind (research,
|
|
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
|
+
- Reports, only when the human asks: agent_report, then agent_inject or agent_promote (research), agent_questions then agent_answer then agent_promote (plan), review_findings then review_decide (review). review_context before launching a review.
|
|
14
14
|
- Main line text for work of your own: table_set, table_clear.
|
|
15
15
|
- Other moves: agent_update, agent_drop, queue_reorder. Recall: agent_list, log_read, session_resume_info, session_list.
|
|
16
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.
|
|
17
17
|
- Session: session_new when the human names it, session_drop only when asked.
|
|
18
18
|
- Fork: agent_update (running, short note) at progress, agent_done last.
|
|
19
19
|
|
|
20
|
-
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.`;
|
|
21
21
|
// src/mcp/session.ts
|
|
22
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;
|
|
23
23
|
function createSessionResolver({ carnet, env = process.env, ppid = process.ppid, cwd = process.cwd(), host = hostById(DEFAULT_HOST) }) {
|
|
@@ -72,12 +72,12 @@ function appendToReport(path, markdown) {
|
|
|
72
72
|
const separator = current.endsWith("\n\n") ? "" : current.endsWith("\n") ? "\n" : "\n\n";
|
|
73
73
|
appendFileSync(path, `${separator}${markdown.trimEnd()}\n`);
|
|
74
74
|
}
|
|
75
|
-
function
|
|
76
|
-
return report.replace(/(\.md)?$/, ".plan.md");
|
|
75
|
+
function keptReportPath(report, kind) {
|
|
76
|
+
return report.replace(/(\.md)?$/, kind === "plan" ? ".plan.md" : ".research.md");
|
|
77
77
|
}
|
|
78
78
|
// src/kinds.ts
|
|
79
|
-
function
|
|
80
|
-
return
|
|
79
|
+
function kindAction(agent) {
|
|
80
|
+
return KIND_ACTIONS[agent.kind];
|
|
81
81
|
}
|
|
82
82
|
function finishWithItems(carnet, session, name, input) {
|
|
83
83
|
const agent = requireAgent(carnet, session, name);
|
|
@@ -127,18 +127,15 @@ function answerQuestionsText(carnet, session, name, answers) {
|
|
|
127
127
|
const open = questions.filter((question) => question.answer === null).length;
|
|
128
128
|
if (open) return `answered ${answers.length} · ${open} of ${questions.length} open`;
|
|
129
129
|
const next = statusAfterAnswers(agent.kind);
|
|
130
|
-
const note = agent.kind === "analyze" ? "plan to validate" : void 0;
|
|
131
130
|
carnet.events.log(session, {
|
|
132
131
|
type: "answered",
|
|
133
|
-
agent: name
|
|
134
|
-
note
|
|
132
|
+
agent: name
|
|
135
133
|
});
|
|
136
134
|
carnet.agents.update(session, name, {
|
|
137
135
|
status: next,
|
|
138
|
-
note
|
|
136
|
+
note: null
|
|
139
137
|
});
|
|
140
|
-
|
|
141
|
-
return `all ${questions.length} answered · ${EMOJI[next]} ${name} ${next}${detail}`;
|
|
138
|
+
return `all ${questions.length} answered · ${EMOJI[next]} ${name} ${next}`;
|
|
142
139
|
}
|
|
143
140
|
const FOR_MAIN = ["for the main", "pour le main"];
|
|
144
141
|
const PLAN = ["plan"];
|
|
@@ -146,34 +143,95 @@ function injectReport(carnet, session, name, input) {
|
|
|
146
143
|
const agent = requireAgent(carnet, session, name);
|
|
147
144
|
const report = readReport(agent.reportPath);
|
|
148
145
|
if (report === void 0) throw new CarnetError("REPORT_MISSING", `${name} has no report to inject yet`);
|
|
149
|
-
const names = input.section ? [input.section] : agent.kind === "
|
|
146
|
+
const names = input.section ? [input.section] : agent.kind === "plan" || agent.promotedFrom === "plan" ? PLAN : FOR_MAIN;
|
|
150
147
|
const text = input.full ? report.trim() : extractSection(report, names);
|
|
151
148
|
if (text === void 0) throw new CarnetError("SECTION_NOT_FOUND", `No "## ${names[0]}" section in ${name}'s report; pass section or full`);
|
|
152
149
|
const lineCount = text.split("\n").length;
|
|
153
150
|
const note = `${input.full ? "full report" : names[0]}, ${lineCount} lines`;
|
|
154
|
-
|
|
151
|
+
let removed = false;
|
|
152
|
+
if (agent.kind === "research" && agent.status !== "closed") removed = carnet.agents.close(session, name, {
|
|
155
153
|
type: "injected",
|
|
156
154
|
note,
|
|
157
155
|
link: agent.reportPath ?? void 0
|
|
158
|
-
});
|
|
156
|
+
}).sandboxRemoved;
|
|
159
157
|
else carnet.events.log(session, {
|
|
160
158
|
type: "injected",
|
|
161
159
|
agent: name,
|
|
162
160
|
note
|
|
163
161
|
});
|
|
164
|
-
|
|
162
|
+
const confirmation = `${name} injected (${lineCount} lines)${sandboxRemovedSuffix(removed)}`;
|
|
163
|
+
return input.echo === false ? confirmation : `${confirmation}\n${text}`;
|
|
164
|
+
}
|
|
165
|
+
function firstLines(text, max) {
|
|
166
|
+
if (!text) return [];
|
|
167
|
+
const lines = text.split("\n").filter((line) => line.trim() !== "");
|
|
168
|
+
return lines.length > max ? [...lines.slice(0, max), "…"] : lines;
|
|
169
|
+
}
|
|
170
|
+
function firstParagraph(text, max) {
|
|
171
|
+
return firstLines(text?.split(/\n\s*\n/)[0], max);
|
|
172
|
+
}
|
|
173
|
+
const TOP_LEVEL_ITEM = /^(-|\*|\d+\.)\s|^\*\*/;
|
|
174
|
+
function topLevelItems(text, max) {
|
|
175
|
+
return firstLines(text?.split("\n").filter((line) => TOP_LEVEL_ITEM.test(line)).join("\n"), max);
|
|
176
|
+
}
|
|
177
|
+
function planSteps(plan) {
|
|
178
|
+
if (!plan) return [];
|
|
179
|
+
const headings = plan.split("\n").filter((line) => /^###\s/.test(line));
|
|
180
|
+
return (headings.length > 0 ? headings : plan.split("\n").filter((line) => /^\d+\.\s/.test(line))).map((line) => line.replace(/^###\s+/, "").trim());
|
|
181
|
+
}
|
|
182
|
+
function block(title, lines) {
|
|
183
|
+
return lines.length > 0 ? [`${title}:`, ...lines] : [];
|
|
184
|
+
}
|
|
185
|
+
function reportSummary(carnet, session, name) {
|
|
186
|
+
const agent = requireAgent(carnet, session, name);
|
|
187
|
+
const report = readReport(agent.reportPath);
|
|
188
|
+
if (report === void 0) throw new CarnetError("REPORT_MISSING", `${name} has no report yet`);
|
|
189
|
+
const section = (...names) => extractSection(report, names);
|
|
190
|
+
const emoji = agent.status === "closed" ? "" : `${EMOJI[agent.status]} `;
|
|
191
|
+
const lines = [`${name} ${kindTag(agent.kind)} ${emoji}→ ${kindAction(agent)}`];
|
|
192
|
+
if (agent.kind === "research") lines.push(...block("For the main", firstLines(section(...FOR_MAIN), 15)), ...block("Gaps", firstLines(section("gaps"), 3)));
|
|
193
|
+
else if (agent.kind === "plan") {
|
|
194
|
+
const plan = section(...PLAN);
|
|
195
|
+
const steps = planSteps(plan);
|
|
196
|
+
const open = carnet.questions.list(session, name, true).length;
|
|
197
|
+
const understanding = section("understanding");
|
|
198
|
+
lines.push(...block("Understanding", steps.length > 0 ? firstParagraph(understanding, 5) : firstLines(understanding, 15)), ...steps.length > 0 ? block(`Plan, ${steps.length} steps`, steps) : [`Plan: ${firstLines(plan, 1)[0] ?? "none"}`], `Questions: ${open} open`);
|
|
199
|
+
} else if (agent.kind === "implement") lines.push(...block("Done", topLevelItems(section("done"), 8)), ...block("Deviations", firstLines(section("deviations"), 6)), ...block("Risks", firstLines(section("risks"), 6)), ...block("Commit message", firstLines(section("commit message")?.replace(/```\w*/g, ""), 1)));
|
|
200
|
+
else {
|
|
201
|
+
const pending = carnet.findings.list(session, name, true);
|
|
202
|
+
const bySeverity = [
|
|
203
|
+
"blocking",
|
|
204
|
+
"to_fix",
|
|
205
|
+
"suggestion"
|
|
206
|
+
].map((severity) => [severity, pending.filter((f) => f.severity === severity).length]).filter(([, count]) => count > 0).map(([severity, count]) => `${count} ${severity.replace("_", " ")}`);
|
|
207
|
+
lines.push(...block("Verdict", firstLines(section("verdict"), 1)), `Findings: ${bySeverity.length > 0 ? bySeverity.join(", ") : "none pending"}`, ...block("Not verified", firstLines(section("not verified"), 3)));
|
|
208
|
+
}
|
|
209
|
+
if (!hasSection(report, [
|
|
210
|
+
...FOR_MAIN,
|
|
211
|
+
...PLAN,
|
|
212
|
+
"understanding",
|
|
213
|
+
"done",
|
|
214
|
+
"verdict"
|
|
215
|
+
])) lines.push(...block("Report", firstLines(report.replace(/^#[^\n]*\n/, ""), 10)));
|
|
216
|
+
lines.push(`report: ${agent.reportPath}`);
|
|
217
|
+
return lines.join("\n");
|
|
165
218
|
}
|
|
166
219
|
function promoteText(carnet, session, name, input) {
|
|
167
220
|
const current = requireAgent(carnet, session, name);
|
|
168
221
|
const agent = carnet.agents.promote(session, name, input);
|
|
169
|
-
const lines = [`${EMOJI.running} ${name} promoted to
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
222
|
+
const lines = [`${EMOJI.running} ${name} promoted to ${agent.kind}`];
|
|
223
|
+
const from = current.kind;
|
|
224
|
+
if ((from === "research" || from === "plan") && current.reportPath) {
|
|
225
|
+
if (existsSync(current.reportPath)) {
|
|
226
|
+
const kept = keptReportPath(current.reportPath, from);
|
|
227
|
+
copyFileSync(current.reportPath, kept);
|
|
228
|
+
lines.push(`${from === "plan" ? "plan" : "research"} kept: ${kept}`);
|
|
229
|
+
}
|
|
174
230
|
}
|
|
175
231
|
if (agent.worktree) lines.push(`worktree: ${agent.worktree}`);
|
|
176
232
|
if (agent.baseCommit) lines.push(`base: ${agent.baseCommit}`);
|
|
233
|
+
if (agent.sandbox) lines.push(`sandbox kept: ${agent.sandbox}`);
|
|
234
|
+
if (agent.sandboxRemoved) lines.push("sandbox removed");
|
|
177
235
|
return lines.join("\n");
|
|
178
236
|
}
|
|
179
237
|
function reviewContext(carnet, session, target) {
|
|
@@ -186,7 +244,10 @@ function reviewContext(carnet, session, target) {
|
|
|
186
244
|
if (agent.reportPath) lines.push(`report: ${agent.reportPath}`);
|
|
187
245
|
if (agent.worktree) lines.push(`worktree: ${agent.worktree}`);
|
|
188
246
|
if (agent.baseCommit) lines.push(`base: ${agent.baseCommit}`);
|
|
189
|
-
|
|
247
|
+
for (const kind of ["research", "plan"]) {
|
|
248
|
+
const kept = agent.reportPath ? keptReportPath(agent.reportPath, kind) : null;
|
|
249
|
+
if (kept && existsSync(kept)) lines.push(`${kind === "plan" ? "plan" : "research"}: ${kept}`);
|
|
250
|
+
}
|
|
190
251
|
const answered = carnet.questions.list(session, target).filter((question) => question.answer);
|
|
191
252
|
if (answered.length) {
|
|
192
253
|
lines.push("answers:");
|
|
@@ -237,10 +298,11 @@ const agentStart = defineTool({
|
|
|
237
298
|
schema: z.object({
|
|
238
299
|
name: agentName,
|
|
239
300
|
task: z.string().min(1).describe("One-line task given to the fork"),
|
|
240
|
-
kind: z.enum(AGENT_KINDS).
|
|
301
|
+
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)"),
|
|
241
302
|
target: z.string().optional().describe("Review only, required there: the implement agent it reviews, or main[:<range>]"),
|
|
242
303
|
base_commit: z.string().optional().describe("Commit the fork starts from"),
|
|
243
|
-
worktree: z.string().optional().describe("
|
|
304
|
+
worktree: z.string().optional().describe("Implement only: worktree path when the fork has one"),
|
|
305
|
+
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"),
|
|
244
306
|
session
|
|
245
307
|
}),
|
|
246
308
|
run: (carnet, sessionId, args) => {
|
|
@@ -251,36 +313,41 @@ const agentStart = defineTool({
|
|
|
251
313
|
kind: args.kind,
|
|
252
314
|
target: args.target,
|
|
253
315
|
baseCommit: args.base_commit,
|
|
254
|
-
worktree: args.worktree
|
|
316
|
+
worktree: args.worktree,
|
|
317
|
+
sandbox: args.sandbox
|
|
255
318
|
});
|
|
256
|
-
|
|
319
|
+
const sandbox = agent.sandbox ? `\nSandbox: ${agent.sandbox}` : "";
|
|
320
|
+
if (!workspace) return { text: `${EMOJI.running} ${agent.name} started outside any workspace\nNo report destination: the report stays where the fork writes it${sandbox}` };
|
|
257
321
|
mkdirSync(reportsDirectory(workspace), { recursive: true });
|
|
258
|
-
return { text: `${EMOJI.running} ${agent.name} started in workspace ${workspace.name}\nReport destination: ${reportPath(workspace, agent.name)}` };
|
|
322
|
+
return { text: `${EMOJI.running} ${agent.name} started in workspace ${workspace.name}\nReport destination: ${reportPath(workspace, agent.name)}${sandbox}` };
|
|
259
323
|
}
|
|
260
324
|
});
|
|
261
325
|
const agentUpdate = defineTool({
|
|
262
326
|
name: "agent_update",
|
|
263
|
-
description: "Set an agent's status and note. Forks: status running at progress. Main agent: only for moves agent_step does not cover.",
|
|
327
|
+
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).",
|
|
264
328
|
schema: z.object({
|
|
265
329
|
name: agentName,
|
|
266
330
|
status: z.enum(OPEN_AGENT_STATUSES).describe("Next action: running means the fork is working"),
|
|
267
331
|
note: z.string().optional().describe("Under 60 characters, no paths, no backticks"),
|
|
268
332
|
report_path: z.string().optional().describe("New absolute path of the report, when it moved"),
|
|
333
|
+
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"),
|
|
269
334
|
session
|
|
270
335
|
}),
|
|
271
336
|
run: (carnet, sessionId, args) => {
|
|
272
337
|
const agent = carnet.agents.update(sessionId, args.name, {
|
|
273
338
|
status: args.status,
|
|
274
339
|
note: args.note,
|
|
275
|
-
reportPath: args.report_path
|
|
340
|
+
reportPath: args.report_path,
|
|
341
|
+
blockedOn: args.blocked_on
|
|
276
342
|
});
|
|
277
343
|
return { text: renderAgentLine({
|
|
278
344
|
name: agent.name,
|
|
279
345
|
kind: agent.kind,
|
|
280
346
|
status: agent.status,
|
|
281
|
-
action: null,
|
|
347
|
+
action: agent.blockedOn ? `→ ${agent.blockedOn}` : null,
|
|
282
348
|
emoji: agent.status === "closed" ? "" : EMOJI[agent.status],
|
|
283
|
-
note: agent.note
|
|
349
|
+
note: agent.note,
|
|
350
|
+
pinned: agent.queueOrder !== null
|
|
284
351
|
}) };
|
|
285
352
|
}
|
|
286
353
|
});
|
|
@@ -344,12 +411,13 @@ const agentDrop = defineTool({
|
|
|
344
411
|
session
|
|
345
412
|
}),
|
|
346
413
|
run: (carnet, sessionId, args) => {
|
|
347
|
-
|
|
414
|
+
const agent = carnet.agents.drop(sessionId, args.name, args.reason);
|
|
415
|
+
return { text: `${agent.name} closed${sandboxRemovedSuffix(agent.sandboxRemoved)}` };
|
|
348
416
|
}
|
|
349
417
|
});
|
|
350
418
|
const agentList = defineTool({
|
|
351
419
|
name: "agent_list",
|
|
352
|
-
description: "List the open agents of the session: kind, status,
|
|
420
|
+
description: "List the open agents of the session: kind, status, next action, note, task and report path.",
|
|
353
421
|
schema: z.object({
|
|
354
422
|
kind: z.enum(AGENT_KINDS).optional().describe("Only agents of this kind"),
|
|
355
423
|
session
|
|
@@ -357,11 +425,13 @@ const agentList = defineTool({
|
|
|
357
425
|
run: (carnet, sessionId, args) => {
|
|
358
426
|
const lines = carnet.agents.list(sessionId).filter((agent) => !args.kind || agent.kind === args.kind).map((agent) => {
|
|
359
427
|
const emoji = agent.status === "closed" ? "" : EMOJI[agent.status];
|
|
360
|
-
const action = agent.status === "running" ? "" : ` → ${
|
|
428
|
+
const action = agent.status === "running" ? "" : ` → ${kindAction(agent)}`;
|
|
361
429
|
const target = agent.target ? ` on ${agent.target}` : "";
|
|
430
|
+
const blocked = agent.blockedOn ? ` blocked on ${agent.blockedOn}` : "";
|
|
362
431
|
const note = agent.note ? ` — ${agent.note}` : "";
|
|
363
432
|
const report = agent.reportPath ? ` (report: ${agent.reportPath})` : "";
|
|
364
|
-
|
|
433
|
+
const sandbox = agent.sandbox ? ` (sandbox: ${agent.sandbox})` : "";
|
|
434
|
+
return `${emoji} ${agent.name} ${agent.kind}${target} [${agent.status}]${blocked}${action}${note}${report}${sandbox}`;
|
|
365
435
|
});
|
|
366
436
|
return { text: lines.length ? lines.join("\n") : "no open agents" };
|
|
367
437
|
}
|
|
@@ -377,7 +447,7 @@ const agentQuestions = defineTool({
|
|
|
377
447
|
});
|
|
378
448
|
const agentAnswer = defineTool({
|
|
379
449
|
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:
|
|
450
|
+
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.",
|
|
381
451
|
schema: z.object({
|
|
382
452
|
name: agentName,
|
|
383
453
|
answers: z.array(z.object({
|
|
@@ -390,28 +460,41 @@ const agentAnswer = defineTool({
|
|
|
390
460
|
});
|
|
391
461
|
const agentInject = defineTool({
|
|
392
462
|
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
|
|
463
|
+
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.",
|
|
394
464
|
schema: z.object({
|
|
395
465
|
name: agentName,
|
|
396
466
|
section: z.string().optional().describe("Heading to extract instead of the default"),
|
|
397
467
|
full: z.boolean().optional().describe("The whole report, only when the human asks"),
|
|
468
|
+
echo: z.boolean().optional().describe("false: only confirm, when agent_report already showed the section"),
|
|
398
469
|
session
|
|
399
470
|
}),
|
|
400
471
|
run: (carnet, sessionId, args) => ({ text: injectReport(carnet, sessionId, args.name, {
|
|
401
472
|
section: args.section,
|
|
402
|
-
full: args.full
|
|
473
|
+
full: args.full,
|
|
474
|
+
echo: args.echo
|
|
403
475
|
}) })
|
|
404
476
|
});
|
|
477
|
+
const agentReport = defineTool({
|
|
478
|
+
name: "agent_report",
|
|
479
|
+
description: "Main agent only, when the human asks for an agent's report: a short summary built from its report by kind, read-only. Show it as is, then run the kind's next action.",
|
|
480
|
+
schema: z.object({
|
|
481
|
+
name: agentName,
|
|
482
|
+
session
|
|
483
|
+
}),
|
|
484
|
+
run: (carnet, sessionId, args) => ({ text: reportSummary(carnet, sessionId, args.name) })
|
|
485
|
+
});
|
|
405
486
|
const agentPromote = defineTool({
|
|
406
487
|
name: "agent_promote",
|
|
407
|
-
description: "Main agent only, when the human
|
|
488
|
+
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.",
|
|
408
489
|
schema: z.object({
|
|
409
490
|
name: agentName,
|
|
491
|
+
kind: z.enum(["plan", "implement"], { error: PROMOTE_KIND_REQUIRED }).describe("Kind the agent becomes: plan or implement"),
|
|
410
492
|
worktree: z.string().optional().describe("Worktree created for the implementation"),
|
|
411
493
|
base_commit: z.string().optional().describe("Commit the worktree starts from"),
|
|
412
494
|
session
|
|
413
495
|
}),
|
|
414
496
|
run: (carnet, sessionId, args) => ({ text: promoteText(carnet, sessionId, args.name, {
|
|
497
|
+
kind: args.kind,
|
|
415
498
|
worktree: args.worktree,
|
|
416
499
|
baseCommit: args.base_commit
|
|
417
500
|
}) })
|
|
@@ -451,7 +534,7 @@ const reviewDecide = defineTool({
|
|
|
451
534
|
});
|
|
452
535
|
const queueReorder = defineTool({
|
|
453
536
|
name: "queue_reorder",
|
|
454
|
-
description: "Main agent only.
|
|
537
|
+
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.",
|
|
455
538
|
schema: z.object({
|
|
456
539
|
names: z.array(agentName).min(1).describe("Agent names in handling order"),
|
|
457
540
|
session
|
|
@@ -480,7 +563,7 @@ const tableSet = defineTool({
|
|
|
480
563
|
});
|
|
481
564
|
const agentStep = defineTool({
|
|
482
565
|
name: "agent_step",
|
|
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
|
|
566
|
+
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.",
|
|
484
567
|
schema: z.object({
|
|
485
568
|
name: agentName,
|
|
486
569
|
step: z.enum(AGENT_STEPS),
|
|
@@ -612,6 +695,7 @@ const TOOLS = [
|
|
|
612
695
|
agentQuestions,
|
|
613
696
|
agentAnswer,
|
|
614
697
|
agentInject,
|
|
698
|
+
agentReport,
|
|
615
699
|
agentPromote,
|
|
616
700
|
reviewContextTool,
|
|
617
701
|
reviewFindings,
|
|
@@ -745,9 +829,11 @@ function createCarnetServer(options) {
|
|
|
745
829
|
try {
|
|
746
830
|
const { carnet, resolver } = open();
|
|
747
831
|
const sessionId = resolver.resolve(args.session);
|
|
832
|
+
const out = tool.run(carnet, sessionId, args);
|
|
833
|
+
options.afterTool?.(carnet, sessionId);
|
|
748
834
|
return { content: [{
|
|
749
835
|
type: "text",
|
|
750
|
-
text:
|
|
836
|
+
text: out.text
|
|
751
837
|
}] };
|
|
752
838
|
} catch (error) {
|
|
753
839
|
if (error instanceof CarnetError) return errorResult(error);
|
|
@@ -762,7 +848,8 @@ function serveCarnet(options = {}) {
|
|
|
762
848
|
carnet,
|
|
763
849
|
env: options.env,
|
|
764
850
|
ppid: options.ppid,
|
|
765
|
-
cwd: options.cwd
|
|
851
|
+
cwd: options.cwd,
|
|
852
|
+
afterTool: options.afterTool
|
|
766
853
|
}), { onerror: (error) => console.error(`[carnet] ${error.message}`) });
|
|
767
854
|
}
|
|
768
855
|
export { INSTRUCTIONS, SERVER_NAME, SERVER_VERSION, TOOLS, createCarnetServer, createSessionResolver, serveCarnet };
|