@rucher/carnet 0.1.0 → 0.2.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 +1 -1
- package/dist/carnet--axAq8FF.d.mts +451 -0
- package/dist/carnet--axAq8FF.d.mts.map +1 -0
- package/dist/index.d.mts +48 -8
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs +209 -7
- package/dist/index.mjs.map +1 -1
- package/dist/mcp.d.mts +2 -2
- package/dist/mcp.d.mts.map +1 -1
- package/dist/mcp.mjs +137 -41
- package/dist/mcp.mjs.map +1 -1
- package/dist/resume-D2FFakCl.mjs +1792 -0
- package/dist/resume-D2FFakCl.mjs.map +1 -0
- package/package.json +1 -1
- package/dist/carnet-CSdqWDas.d.mts +0 -261
- package/dist/carnet-CSdqWDas.d.mts.map +0 -1
- package/dist/resume-Daotqfdq.mjs +0 -985
- package/dist/resume-Daotqfdq.mjs.map +0 -1
package/dist/index.mjs
CHANGED
|
@@ -1,6 +1,91 @@
|
|
|
1
|
-
import { $ as
|
|
2
|
-
import { existsSync, mkdirSync, writeFileSync } from "node:fs";
|
|
1
|
+
import { $ as repoNameFor, A as renderMemory, At as MAIN_WORKING_EMOJI, B as sessionNoteActivity, C as renderTableLine, Ct as PUBLISH_FALLBACK_MILLISECONDS, D as shortId, Dt as AGENT_STATUSES, E as MINIMUM_ID_PREFIX, Et as sanitizeNote, F as STALE_AFTER_ACTIVE_DAYS, Ft as EVENT_TYPES, G as REPORTS_DIRECTORY, H as DB_FILE, I as groupRepoNames, It as SESSION_EVENT_TYPES, J as isGroupRoot, K as ambiguousGroupContext, L as isNoteKind, Lt as isEventType, M as DUPLICATE_SIMILARITY, Mt as USER_ACTION_STATUSES, N as NOTE_KINDS, Nt as isAgentStatus, O as MEMORY_MAX_CHARACTERS, Ot as EMOJI, P as NOTE_TEXT_LIMIT, Pt as isUserActionStatus, Q as pinnedGroup, R as localDay, Rt as CarnetError, S as renderStatus, St as schemaVersion, T as purgeDays, Tt as NOTE_MAX, U as GROUP_DIRECTORY, V as similarity, W as GROUP_FILE, X as loadGroup, Y as isInside, Z as locateGroup, _ as renderAgentLine, _t as transcriptTitle, a as sessionLabel, at as rucherHome, b as renderNotesSummary, bt as migrate, c as openGroupCarnet, ct as allHosts, d as buildStatusView, dt as REPOS_START, et as repoPathFor, f as formatClock, ft as claudeCode, g as SIMILAR_PREFIX, gt as reposBlock, h as NOTES_HEADER, ht as replaceReposBlock, i as resumeContext, it as registerGroup, j as DEFAULT_HALF_LIFE_DAYS, k as memoryMaxCharacters, kt as LEGEND, l as PAIRING_WINDOW_MILLISECONDS, lt as hostById, m as NOTES_FOLD_LINES, mt as groupSettings, n as RESUME_MAX_CHARACTERS, nt as reportsDirectoryOf, o as Carnet, ot as unregisterGroups, p as MAIN_WORKING_SUFFIX, pt as groupInstructions, q as findGroupRoot, r as formatEventLine, rt as readRegistry, s as openCarnet, st as DEFAULT_HOST, t as RESUME_EVENTS, tt as reportPathFor, u as STOPPED_NOTE, ut as REPOS_END, v as renderNoteLine, vt as MEMORY_DB, w as DEFAULT_PURGE_DAYS, wt as REPORTING_NOTE, x as renderSections, xt as migrations, y as renderNotes, yt as openDatabase, z as memoryHalfLife } from "./resume-D2FFakCl.mjs";
|
|
2
|
+
import { existsSync, mkdirSync, readFileSync, writeFileSync } from "node:fs";
|
|
3
3
|
import { basename, join, resolve } from "node:path";
|
|
4
|
+
import { createHash } from "node:crypto";
|
|
5
|
+
// src/move.ts
|
|
6
|
+
function rows(db, sql, ...parameters) {
|
|
7
|
+
return db.prepare(sql).all(...parameters);
|
|
8
|
+
}
|
|
9
|
+
function count(db, sql, ...parameters) {
|
|
10
|
+
return Number(db.prepare(sql).get(...parameters).total);
|
|
11
|
+
}
|
|
12
|
+
function insert(db, table, row) {
|
|
13
|
+
const columns = Object.keys(row);
|
|
14
|
+
db.prepare(`INSERT INTO ${table} (${columns.join(", ")}) VALUES (${columns.map(() => "?").join(", ")})`).run(...columns.map((column) => row[column] ?? null));
|
|
15
|
+
}
|
|
16
|
+
function inTransaction(db, run) {
|
|
17
|
+
db.exec("BEGIN");
|
|
18
|
+
try {
|
|
19
|
+
run();
|
|
20
|
+
db.exec("COMMIT");
|
|
21
|
+
} catch (error) {
|
|
22
|
+
db.exec("ROLLBACK");
|
|
23
|
+
throw error;
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
function existingTarget(target, session, merge) {
|
|
27
|
+
const sameId = target.sessions.get(session.id);
|
|
28
|
+
const [named] = session.name ? rows(target.db, "SELECT id FROM sessions WHERE name = ?", session.name) : [];
|
|
29
|
+
const existing = sameId ?? (named ? target.sessions.get(named.id) : null) ?? null;
|
|
30
|
+
if (existing && !merge) throw new CarnetError(sameId ? "SESSION_EXISTS" : "SESSION_NAME_TAKEN", `Group ${target.group.name} already has session ${existing.name ?? existing.id}: pass --merge to merge into it`);
|
|
31
|
+
return existing;
|
|
32
|
+
}
|
|
33
|
+
function moveSession(source, sessionId, target, options = {}) {
|
|
34
|
+
if (source.group.root === target.group.root) throw new CarnetError("SESSION_MOVE_INVALID", "The session is already in this group");
|
|
35
|
+
const session = source.sessions.require(sessionId);
|
|
36
|
+
const into = existingTarget(target, session, options.merge === true);
|
|
37
|
+
const intoId = into?.id ?? session.id;
|
|
38
|
+
const takenNames = new Set(rows(target.db, "SELECT name FROM agents WHERE session = ?", intoId).map((row) => row.name));
|
|
39
|
+
const agents = rows(source.db, "SELECT * FROM agents WHERE session = ? ORDER BY started_at, rowid", session.id);
|
|
40
|
+
const movedAgents = agents.filter((agent) => !takenNames.has(agent.name));
|
|
41
|
+
const events = rows(source.db, "SELECT * FROM events WHERE session = ? ORDER BY id", session.id);
|
|
42
|
+
const [table] = rows(source.db, "SELECT * FROM table_items WHERE session = ?", session.id);
|
|
43
|
+
const targetHasTable = rows(target.db, "SELECT 1 FROM table_items WHERE session = ?", intoId).length > 0;
|
|
44
|
+
const movedTable = table !== void 0 && !targetHasTable;
|
|
45
|
+
const unlinkedNotes = count(source.db, "SELECT COUNT(*) AS total FROM notes WHERE session = ? OR dropped_session = ?", session.id, session.id);
|
|
46
|
+
const result = {
|
|
47
|
+
session,
|
|
48
|
+
into,
|
|
49
|
+
movedAgents: movedAgents.map((agent) => agent.name),
|
|
50
|
+
skippedAgents: agents.filter((agent) => takenNames.has(agent.name)).map((agent) => agent.name),
|
|
51
|
+
movedEvents: events.length,
|
|
52
|
+
movedTable,
|
|
53
|
+
unlinkedNotes
|
|
54
|
+
};
|
|
55
|
+
if (options.dryRun) return result;
|
|
56
|
+
inTransaction(target.db, () => {
|
|
57
|
+
if (!into) {
|
|
58
|
+
const [row] = rows(source.db, "SELECT * FROM sessions WHERE id = ?", session.id);
|
|
59
|
+
if (row) insert(target.db, "sessions", {
|
|
60
|
+
...row,
|
|
61
|
+
parent_id: null
|
|
62
|
+
});
|
|
63
|
+
} else if (into.name === null && session.name !== null) target.db.prepare("UPDATE sessions SET name = ?, kind = 'active' WHERE id = ?").run(session.name, intoId);
|
|
64
|
+
for (const agent of movedAgents) insert(target.db, "agents", {
|
|
65
|
+
...agent,
|
|
66
|
+
session: intoId
|
|
67
|
+
});
|
|
68
|
+
for (const { id: _id, ...event } of events) insert(target.db, "events", {
|
|
69
|
+
...event,
|
|
70
|
+
session: intoId
|
|
71
|
+
});
|
|
72
|
+
if (table && movedTable) insert(target.db, "table_items", {
|
|
73
|
+
...table,
|
|
74
|
+
session: intoId
|
|
75
|
+
});
|
|
76
|
+
for (const repo of rows(source.db, "SELECT * FROM session_repos WHERE session = ?", session.id)) target.db.prepare("INSERT OR IGNORE INTO session_repos (session, repo, injected_at) VALUES (?, ?, ?)").run(intoId, repo.repo ?? null, repo.injected_at ?? null);
|
|
77
|
+
});
|
|
78
|
+
inTransaction(source.db, () => {
|
|
79
|
+
for (const table of [
|
|
80
|
+
"agents",
|
|
81
|
+
"events",
|
|
82
|
+
"table_items"
|
|
83
|
+
]) source.db.prepare(`DELETE FROM ${table} WHERE session = ?`).run(session.id);
|
|
84
|
+
source.db.prepare("UPDATE sessions SET parent_id = NULL WHERE parent_id = ?").run(session.id);
|
|
85
|
+
source.db.prepare("DELETE FROM sessions WHERE id = ?").run(session.id);
|
|
86
|
+
});
|
|
87
|
+
return result;
|
|
88
|
+
}
|
|
4
89
|
// src/group/init.ts
|
|
5
90
|
function writeGroupFile(root, file) {
|
|
6
91
|
writeFileSync(join(root, GROUP_DIRECTORY, GROUP_FILE), `${JSON.stringify(file, null, 2)}\n`);
|
|
@@ -15,7 +100,10 @@ function initGroup(directory, options = {}) {
|
|
|
15
100
|
const groupDirectory = join(root, GROUP_DIRECTORY);
|
|
16
101
|
if (existsSync(groupDirectory)) throw new CarnetError("GROUP_EXISTS", `${root} is already a Rucher group`);
|
|
17
102
|
const name = options.name ?? basename(root);
|
|
18
|
-
const repos = (options.repos ?? []).map((repo) => resolveRepo(root, repo));
|
|
103
|
+
const repos = [...new Set((options.repos ?? []).map((repo) => resolveRepo(root, repo)))];
|
|
104
|
+
const names = repos.map((repo) => basename(repo));
|
|
105
|
+
const shared = names.find((repoName, index) => names.indexOf(repoName) !== index);
|
|
106
|
+
if (shared) throw new CarnetError("REPO_NAME_TAKEN", `Two repos are named ${shared}: give them distinct names`);
|
|
19
107
|
const hosts = (options.hosts?.length ? options.hosts : [DEFAULT_HOST]).map((id) => hostById(id).id);
|
|
20
108
|
mkdirSync(join(groupDirectory, REPORTS_DIRECTORY), { recursive: true });
|
|
21
109
|
writeGroupFile(root, {
|
|
@@ -33,6 +121,8 @@ function initGroup(directory, options = {}) {
|
|
|
33
121
|
function addGroupRepo(root, repo) {
|
|
34
122
|
const group = loadGroup(resolve(root));
|
|
35
123
|
const path = resolveRepo(group.root, repo);
|
|
124
|
+
const sameName = group.repos.find((existing) => existing !== path && basename(existing) === basename(path));
|
|
125
|
+
if (sameName) throw new CarnetError("REPO_NAME_TAKEN", `${group.name} already has a repo named ${basename(path)}: ${sameName}`);
|
|
36
126
|
if (!group.repos.includes(path)) writeGroupFile(group.root, {
|
|
37
127
|
name: group.name,
|
|
38
128
|
repos: [...group.repos, path],
|
|
@@ -51,21 +141,133 @@ function removeGroupRepo(root, repo) {
|
|
|
51
141
|
});
|
|
52
142
|
return loadGroup(group.root);
|
|
53
143
|
}
|
|
144
|
+
// src/hook/session-end.ts
|
|
145
|
+
function handleSessionEnd(carnet, payload) {
|
|
146
|
+
if (!carnet.sessions.get(payload.session_id)) return void 0;
|
|
147
|
+
return carnet.sessions.end(payload.session_id);
|
|
148
|
+
}
|
|
149
|
+
// src/prompt/core-rules.ts
|
|
150
|
+
const CORE_RULES = `- Work can be parallel, review stays sequential: forks work at the same time, the human handles their results one at a time.
|
|
151
|
+
- The human keeps the hand: only the human launches forks, applies, tests and commits. Agents propose, they never push.
|
|
152
|
+
- Status lives in Carnet: agent statuses, the "On the table" line and the journal go through the Carnet tools, never into status files nor chat updates. Update before and after each piece of work.
|
|
153
|
+
- When a fork finishes, say only "<name> finished, report ready". Never summarise, quote or act on its report or final message until the human asks for that fork's report, even when answering about something else.
|
|
154
|
+
- Forks never commit, push, stash or record notes. A fork writes its report to a file, ending with a Learnings section, calls agent_done as its last tool action, then replies with one line that carries no results, such as "<name> done, report written". Only the main agent records notes, at the end of a step.
|
|
155
|
+
- To dispatch, apply or review forks, load the rucher skill: it holds the full workflow.`;
|
|
156
|
+
// src/prompt/prompt.ts
|
|
157
|
+
const PROMPT_FILE = "prompt.md";
|
|
158
|
+
const PROMPTS_DIRECTORY = "prompts";
|
|
159
|
+
function readIfPresent(path) {
|
|
160
|
+
if (!existsSync(path)) return void 0;
|
|
161
|
+
return readFileSync(path, "utf8").trim() || void 0;
|
|
162
|
+
}
|
|
163
|
+
function baseRules(env = process.env) {
|
|
164
|
+
return readIfPresent(join(rucherHome(env), "prompt.md")) ?? "- Work can be parallel, review stays sequential: forks work at the same time, the human handles their results one at a time.\n- The human keeps the hand: only the human launches forks, applies, tests and commits. Agents propose, they never push.\n- Status lives in Carnet: agent statuses, the \"On the table\" line and the journal go through the Carnet tools, never into status files nor chat updates. Update before and after each piece of work.\n- When a fork finishes, say only \"<name> finished, report ready\". Never summarise, quote or act on its report or final message until the human asks for that fork's report, even when answering about something else.\n- Forks never commit, push, stash or record notes. A fork writes its report to a file, ending with a Learnings section, calls agent_done as its last tool action, then replies with one line that carries no results, such as \"<name> done, report written\". Only the main agent records notes, at the end of a step.\n- To dispatch, apply or review forks, load the rucher skill: it holds the full workflow.";
|
|
165
|
+
}
|
|
166
|
+
function groupRules(group) {
|
|
167
|
+
return readIfPresent(join(group.root, GROUP_DIRECTORY, PROMPT_FILE));
|
|
168
|
+
}
|
|
169
|
+
function rulesText(group, env = process.env) {
|
|
170
|
+
const extra = groupRules(group);
|
|
171
|
+
const base = `Rucher rules:\n${baseRules(env)}`;
|
|
172
|
+
return extra ? `${base}\n\nRules of the ${group.name} group:\n${extra}` : base;
|
|
173
|
+
}
|
|
174
|
+
function rulesVersion(group, env = process.env) {
|
|
175
|
+
return createHash("sha256").update(rulesText(group, env)).digest("hex").slice(0, 12);
|
|
176
|
+
}
|
|
177
|
+
function assemblePrompt(group, session, env = process.env) {
|
|
178
|
+
const identity = `This is the Rucher session ${session.name ?? shortId(session.id)} (${session.kind}) of the ${group.name} group.`;
|
|
179
|
+
return {
|
|
180
|
+
text: `${rulesText(group, env)}\n\n${identity}\n`,
|
|
181
|
+
version: rulesVersion(group, env)
|
|
182
|
+
};
|
|
183
|
+
}
|
|
184
|
+
function appendPromptFile(group, session, env = process.env) {
|
|
185
|
+
const { text, version } = assemblePrompt(group, session, env);
|
|
186
|
+
const directory = join(group.root, GROUP_DIRECTORY, PROMPTS_DIRECTORY);
|
|
187
|
+
mkdirSync(directory, { recursive: true });
|
|
188
|
+
const path = join(directory, `${session.id}.md`);
|
|
189
|
+
writeFileSync(path, text);
|
|
190
|
+
return {
|
|
191
|
+
path,
|
|
192
|
+
version
|
|
193
|
+
};
|
|
194
|
+
}
|
|
195
|
+
function compactReminder(group, env = process.env) {
|
|
196
|
+
return `The conversation was just compacted and this session was not started by rucher, so its system prompt no longer holds the Rucher rules. ${rulesText(group, env)}`;
|
|
197
|
+
}
|
|
198
|
+
const OUTSIDE_RUCHER_CONTEXT = "This session was started without rucher, so the Rucher rules are not in its system prompt. Follow the Carnet server instructions and load the rucher skill before dispatching or applying forks.";
|
|
199
|
+
const OUTSIDE_RUCHER_NOTICE = "rucher: session started without rucher, the Rucher rules are not in its system prompt (use rucher new, tmp or resume)";
|
|
200
|
+
const RULES_UPDATED_NOTICE = "rucher: rules updated, will apply after the next compaction or in a new session";
|
|
201
|
+
const SUBAGENT_RULES = "Rucher rules for sub-agents: never commit, push or stash. When your task asks for a report, write it to the file it names. If your prompt names you as a Carnet agent, call agent_update at meaningful progress and agent_done as your last tool action, then reply with one line.";
|
|
54
202
|
// src/hook/session-start.ts
|
|
203
|
+
const SOURCE_EVENTS = {
|
|
204
|
+
startup: "session.started",
|
|
205
|
+
resume: "session.resumed",
|
|
206
|
+
fork: "session.forked"
|
|
207
|
+
};
|
|
208
|
+
function adoptFork(carnet, session, env) {
|
|
209
|
+
const parentId = env.RUCHER_SESSION_ID;
|
|
210
|
+
if (!parentId || parentId === session.id || !carnet.sessions.get(parentId)) return session;
|
|
211
|
+
let fork = carnet.sessions.setParent(session.id, parentId);
|
|
212
|
+
carnet.memory.copyRepos(parentId, session.id);
|
|
213
|
+
const kind = env.RUCHER_SESSION_KIND;
|
|
214
|
+
if (kind === "active" || kind === "temp") fork = carnet.sessions.setKind(session.id, kind, env.RUCHER_SESSION_NAME || null);
|
|
215
|
+
return fork;
|
|
216
|
+
}
|
|
217
|
+
function startMemory(carnet, session, source, env) {
|
|
218
|
+
const options = {
|
|
219
|
+
maxCharacters: memoryMaxCharacters(env.RUCHER_MEMORY_MAX_CHARACTERS),
|
|
220
|
+
halfLifeDays: memoryHalfLife(env.RUCHER_MEMORY_HALF_LIFE_DAYS)
|
|
221
|
+
};
|
|
222
|
+
if (source === "startup" || source === "clear") return carnet.memory.atStart(session, options);
|
|
223
|
+
if (source === "resume" || source === "compact") return carnet.memory.ofSession(session, options);
|
|
224
|
+
}
|
|
55
225
|
function handleSessionStart(carnet, payload, env) {
|
|
56
|
-
|
|
226
|
+
let session = carnet.sessions.upsertFromHook(payload, env);
|
|
227
|
+
const source = payload.source ?? "";
|
|
228
|
+
if (source === "fork") session = adoptFork(carnet, session, env);
|
|
229
|
+
const event = SOURCE_EVENTS[source];
|
|
230
|
+
if (event) carnet.events.log(session.id, { type: event });
|
|
231
|
+
session = carnet.sessions.setStatus(session.id, "running");
|
|
57
232
|
carnet.sessions.purge(session.id, purgeDays(env.RUCHER_PURGE_DAYS));
|
|
58
|
-
|
|
233
|
+
const promptEnv = { RUCHER_HOME: env.RUCHER_HOME };
|
|
234
|
+
const launchedVersion = env.RUCHER_PROMPT_VERSION || null;
|
|
235
|
+
const contextParts = [];
|
|
236
|
+
const notices = [];
|
|
237
|
+
if (hostById(session.host).rendersSystemPrompt(source)) session = carnet.sessions.recordPromptVersion(session.id, launchedVersion);
|
|
238
|
+
if (source === "resume") contextParts.push(resumeContext(carnet, session));
|
|
239
|
+
const memory = startMemory(carnet, session, source, env);
|
|
240
|
+
if (memory) contextParts.push(memory);
|
|
241
|
+
if (source === "compact" && !launchedVersion) contextParts.push(compactReminder(carnet.group, promptEnv));
|
|
242
|
+
else if (!env.RUCHER_SESSION_ID && !session.promptVersion) {
|
|
243
|
+
contextParts.push(OUTSIDE_RUCHER_CONTEXT);
|
|
244
|
+
notices.push(OUTSIDE_RUCHER_NOTICE);
|
|
245
|
+
} else if (session.promptVersion && session.promptVersion !== rulesVersion(carnet.group, promptEnv)) notices.push(RULES_UPDATED_NOTICE);
|
|
246
|
+
const additionalContext = contextParts.length ? contextParts.join("\n\n") : void 0;
|
|
59
247
|
return {
|
|
60
248
|
session,
|
|
61
|
-
|
|
249
|
+
contextParts,
|
|
250
|
+
notices,
|
|
251
|
+
...additionalContext ? { additionalContext } : {}
|
|
62
252
|
};
|
|
63
253
|
}
|
|
64
254
|
// src/hook/user-prompt-submit.ts
|
|
65
255
|
function handleUserPromptSubmit(carnet, host, payload) {
|
|
66
256
|
carnet.sessions.ensure(payload.session_id, payload.cwd);
|
|
257
|
+
carnet.notes.recordActiveDay();
|
|
67
258
|
return carnet.sessions.adoptTitle(payload.session_id, host.promptTitle(payload));
|
|
68
259
|
}
|
|
69
|
-
|
|
260
|
+
// src/hook/post-tool-use.ts
|
|
261
|
+
function handleToolUse(carnet, payload, env) {
|
|
262
|
+
if (payload.agent_id) return void 0;
|
|
263
|
+
const repo = repoNameFor(carnet.group, payload.path);
|
|
264
|
+
if (!repo) return void 0;
|
|
265
|
+
const session = carnet.sessions.ensure(payload.session_id, payload.cwd);
|
|
266
|
+
return carnet.memory.forRepo(session, repo, {
|
|
267
|
+
maxCharacters: memoryMaxCharacters(env.RUCHER_MEMORY_MAX_CHARACTERS),
|
|
268
|
+
halfLifeDays: memoryHalfLife(env.RUCHER_MEMORY_HALF_LIFE_DAYS)
|
|
269
|
+
});
|
|
270
|
+
}
|
|
271
|
+
export { AGENT_STATUSES, CORE_RULES, Carnet, CarnetError, DB_FILE, DEFAULT_HALF_LIFE_DAYS, DEFAULT_HOST, DEFAULT_PURGE_DAYS, DUPLICATE_SIMILARITY, EMOJI, EVENT_TYPES, GROUP_DIRECTORY, GROUP_FILE, LEGEND, MAIN_WORKING_EMOJI, MAIN_WORKING_SUFFIX, MEMORY_DB, MEMORY_MAX_CHARACTERS, MINIMUM_ID_PREFIX, NOTES_FOLD_LINES, NOTES_HEADER, NOTE_KINDS, NOTE_MAX, NOTE_TEXT_LIMIT, OUTSIDE_RUCHER_CONTEXT, OUTSIDE_RUCHER_NOTICE, PAIRING_WINDOW_MILLISECONDS, PROMPTS_DIRECTORY, PROMPT_FILE, PUBLISH_FALLBACK_MILLISECONDS, REPORTING_NOTE, REPORTS_DIRECTORY, REPOS_END, REPOS_START, RESUME_EVENTS, RESUME_MAX_CHARACTERS, RULES_UPDATED_NOTICE, SESSION_EVENT_TYPES, SIMILAR_PREFIX, STALE_AFTER_ACTIVE_DAYS, STOPPED_NOTE, SUBAGENT_RULES, USER_ACTION_STATUSES, addGroupRepo, allHosts, ambiguousGroupContext, appendPromptFile, assemblePrompt, baseRules, buildStatusView, claudeCode, compactReminder, findGroupRoot, formatClock, formatEventLine, groupInstructions, groupRepoNames, groupRules, groupSettings, handleSessionEnd, handleSessionStart, handleToolUse, handleUserPromptSubmit, hostById, initGroup, isAgentStatus, isEventType, isGroupRoot, isInside, isNoteKind, isUserActionStatus, loadGroup, localDay, locateGroup, memoryHalfLife, memoryMaxCharacters, migrate, migrations, moveSession, openCarnet, openDatabase, openGroupCarnet, pinnedGroup, purgeDays, readRegistry, registerGroup, removeGroupRepo, renderAgentLine, renderMemory, renderNoteLine, renderNotes, renderNotesSummary, renderSections, renderStatus, renderTableLine, replaceReposBlock, repoNameFor, repoPathFor, reportPathFor, reportsDirectoryOf, reposBlock, resumeContext, rucherHome, rulesText, rulesVersion, sanitizeNote, schemaVersion, sessionLabel, sessionNoteActivity, shortId, similarity, transcriptTitle, unregisterGroups };
|
|
70
272
|
|
|
71
273
|
//# sourceMappingURL=index.mjs.map
|
package/dist/index.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.mjs","names":[],"sources":["../src/group/init.ts","../src/hook/session-start.ts","../src/hook/user-prompt-submit.ts"],"sourcesContent":["import { existsSync, mkdirSync, writeFileSync } from 'node:fs';\nimport { basename, join, resolve } from 'node:path';\nimport { CarnetError } from '../errors.ts';\nimport { openDatabase } from '../db/open.ts';\nimport { DEFAULT_HOST, hostById } from '../hosts/host.ts';\nimport {\n DB_FILE,\n GROUP_DIRECTORY,\n GROUP_FILE,\n REPORTS_DIRECTORY,\n type Group,\n type GroupFile,\n loadGroup,\n} from './locate.ts';\nimport { registerGroup } from './registry.ts';\n\nexport interface InitOptions {\n name?: string | undefined;\n repos?: string[] | undefined;\n hosts?: string[] | undefined;\n env?: NodeJS.ProcessEnv | undefined;\n}\n\nfunction writeGroupFile(root: string, file: GroupFile): void {\n writeFileSync(join(root, GROUP_DIRECTORY, GROUP_FILE), `${JSON.stringify(file, null, 2)}\\n`);\n}\n\nfunction resolveRepo(root: string, repo: string): string {\n const path = resolve(root, repo);\n if (!existsSync(path))\n throw new CarnetError('REPO_NOT_FOUND', `Repo path does not exist: ${path}`);\n return path;\n}\n\nexport function initGroup(directory: string, options: InitOptions = {}): Group {\n const root = resolve(directory);\n const groupDirectory = join(root, GROUP_DIRECTORY);\n if (existsSync(groupDirectory)) {\n throw new CarnetError('GROUP_EXISTS', `${root} is already a Rucher group`);\n }\n const name = options.name ?? basename(root);\n const repos = (options.repos ?? []).map((repo) => resolveRepo(root, repo));\n const hosts = (options.hosts?.length ? options.hosts : [DEFAULT_HOST]).map(\n (id) => hostById(id).id,\n );\n mkdirSync(join(groupDirectory, REPORTS_DIRECTORY), { recursive: true });\n writeGroupFile(root, { name, repos, hosts });\n openDatabase(join(groupDirectory, DB_FILE)).close();\n registerGroup({ name, path: root }, options.env);\n return loadGroup(root);\n}\n\nexport function addGroupRepo(root: string, repo: string): Group {\n const group = loadGroup(resolve(root));\n const path = resolveRepo(group.root, repo);\n if (!group.repos.includes(path)) {\n writeGroupFile(group.root, {\n name: group.name,\n repos: [...group.repos, path],\n hosts: group.hosts,\n });\n }\n return loadGroup(group.root);\n}\n\nexport function removeGroupRepo(root: string, repo: string): Group {\n const group = loadGroup(resolve(root));\n const path = resolve(group.root, repo);\n if (!group.repos.includes(path)) {\n throw new CarnetError('REPO_NOT_FOUND', `${path} is not a repo of ${group.name}`);\n }\n writeGroupFile(group.root, {\n name: group.name,\n repos: group.repos.filter((repo) => repo !== path),\n hosts: group.hosts,\n });\n return loadGroup(group.root);\n}\n","import type { Carnet } from '../carnet.ts';\nimport { purgeDays } from '../purge.ts';\nimport { resumeContext } from '../resume.ts';\nimport type { HookEnv, HookSessionPayload, Session } from '../sessions.ts';\n\nexport interface SessionStartResult {\n session: Session;\n additionalContext?: string;\n}\n\nexport function handleSessionStart(\n carnet: Carnet,\n payload: HookSessionPayload,\n env: HookEnv,\n): SessionStartResult {\n const session = carnet.sessions.upsertFromHook(payload, env);\n carnet.sessions.purge(session.id, purgeDays(env.RUCHER_PURGE_DAYS));\n if (payload.source !== 'resume') return { session };\n return { session, additionalContext: resumeContext(carnet, session) };\n}\n","import type { Carnet } from '../carnet.ts';\nimport type { Host, HostPromptPayload } from '../hosts/host.ts';\nimport type { Session } from '../sessions.ts';\n\nexport function handleUserPromptSubmit(\n carnet: Carnet,\n host: Host,\n payload: HostPromptPayload,\n): Session {\n carnet.sessions.ensure(payload.session_id, payload.cwd);\n return carnet.sessions.adoptTitle(payload.session_id, host.promptTitle(payload));\n}\n"],"mappings":";;;;AAuBA,SAAS,eAAe,MAAc,MAAuB;CAC3D,cAAc,KAAK,MAAM,iBAAiB,UAAU,GAAG,GAAG,KAAK,UAAU,MAAM,MAAM,CAAC,EAAE,GAAG;AAC7F;AAEA,SAAS,YAAY,MAAc,MAAsB;CACvD,MAAM,OAAO,QAAQ,MAAM,IAAI;CAC/B,IAAI,CAAC,WAAW,IAAI,GAClB,MAAM,IAAI,YAAY,kBAAkB,6BAA6B,MAAM;CAC7E,OAAO;AACT;AAEA,SAAgB,UAAU,WAAmB,UAAuB,CAAC,GAAU;CAC7E,MAAM,OAAO,QAAQ,SAAS;CAC9B,MAAM,iBAAiB,KAAK,MAAM,eAAe;CACjD,IAAI,WAAW,cAAc,GAC3B,MAAM,IAAI,YAAY,gBAAgB,GAAG,KAAK,2BAA2B;CAE3E,MAAM,OAAO,QAAQ,QAAQ,SAAS,IAAI;CAC1C,MAAM,SAAS,QAAQ,SAAS,CAAC,EAAA,CAAG,KAAK,SAAS,YAAY,MAAM,IAAI,CAAC;CACzE,MAAM,SAAS,QAAQ,OAAO,SAAS,QAAQ,QAAQ,CAAC,YAAY,EAAA,CAAG,KACpE,OAAO,SAAS,EAAE,CAAC,CAAC,EACv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,SAAgB,uBACd,QACA,MACA,SACS;CACT,OAAO,SAAS,OAAO,QAAQ,YAAY,QAAQ,GAAG;CACtD,OAAO,OAAO,SAAS,WAAW,QAAQ,YAAY,KAAK,YAAY,OAAO,CAAC;AACjF"}
|
|
1
|
+
{"version":3,"file":"index.mjs","names":[],"sources":["../src/move.ts","../src/group/init.ts","../src/hook/session-end.ts","../src/prompt/core-rules.ts","../src/prompt/prompt.ts","../src/hook/session-start.ts","../src/hook/user-prompt-submit.ts","../src/hook/post-tool-use.ts"],"sourcesContent":["import type { DatabaseSync, SQLInputValue } from 'node:sqlite';\nimport type { Carnet } from './carnet.ts';\nimport { CarnetError } from './errors.ts';\nimport type { Session } from './sessions.ts';\n\nexport interface MoveOptions {\n merge?: boolean | undefined;\n dryRun?: boolean | undefined;\n}\n\nexport interface MoveResult {\n session: Session;\n into: Session | null;\n movedAgents: string[];\n skippedAgents: string[];\n movedEvents: number;\n movedTable: boolean;\n unlinkedNotes: number;\n}\n\ntype Row = Record<string, SQLInputValue>;\n\nfunction rows(db: DatabaseSync, sql: string, ...parameters: SQLInputValue[]): Row[] {\n return db.prepare(sql).all(...parameters) as Row[];\n}\n\nfunction count(db: DatabaseSync, sql: string, ...parameters: SQLInputValue[]): number {\n return Number((db.prepare(sql).get(...parameters) as { total: number }).total);\n}\n\nfunction insert(db: DatabaseSync, table: string, row: Row): void {\n const columns = Object.keys(row);\n db.prepare(\n `INSERT INTO ${table} (${columns.join(', ')}) VALUES (${columns.map(() => '?').join(', ')})`,\n ).run(...columns.map((column) => row[column] ?? null));\n}\n\nfunction inTransaction(db: DatabaseSync, run: () => void): void {\n db.exec('BEGIN');\n try {\n run();\n db.exec('COMMIT');\n } catch (error) {\n db.exec('ROLLBACK');\n throw error;\n }\n}\n\nfunction existingTarget(target: Carnet, session: Session, merge: boolean): Session | null {\n const sameId = target.sessions.get(session.id);\n const [named] = session.name\n ? rows(target.db, 'SELECT id FROM sessions WHERE name = ?', session.name)\n : [];\n const existing = sameId ?? (named ? target.sessions.get(named.id as string) : null) ?? null;\n if (existing && !merge) {\n throw new CarnetError(\n sameId ? 'SESSION_EXISTS' : 'SESSION_NAME_TAKEN',\n `Group ${target.group.name} already has session ${existing.name ?? existing.id}: pass --merge to merge into it`,\n );\n }\n return existing;\n}\n\nexport function moveSession(\n source: Carnet,\n sessionId: string,\n target: Carnet,\n options: MoveOptions = {},\n): MoveResult {\n if (source.group.root === target.group.root) {\n throw new CarnetError('SESSION_MOVE_INVALID', 'The session is already in this group');\n }\n const session = source.sessions.require(sessionId);\n const into = existingTarget(target, session, options.merge === true);\n const intoId = into?.id ?? session.id;\n const takenNames = new Set(\n rows(target.db, 'SELECT name FROM agents WHERE session = ?', intoId).map((row) => row.name),\n );\n const agents = rows(\n source.db,\n 'SELECT * FROM agents WHERE session = ? ORDER BY started_at, rowid',\n session.id,\n );\n const movedAgents = agents.filter((agent) => !takenNames.has(agent.name));\n const events = rows(source.db, 'SELECT * FROM events WHERE session = ? ORDER BY id', session.id);\n const [table] = rows(source.db, 'SELECT * FROM table_items WHERE session = ?', session.id);\n const targetHasTable =\n rows(target.db, 'SELECT 1 FROM table_items WHERE session = ?', intoId).length > 0;\n const movedTable = table !== undefined && !targetHasTable;\n const unlinkedNotes = count(\n source.db,\n 'SELECT COUNT(*) AS total FROM notes WHERE session = ? OR dropped_session = ?',\n session.id,\n session.id,\n );\n const result: MoveResult = {\n session,\n into,\n movedAgents: movedAgents.map((agent) => agent.name as string),\n skippedAgents: agents\n .filter((agent) => takenNames.has(agent.name))\n .map((agent) => agent.name as string),\n movedEvents: events.length,\n movedTable,\n unlinkedNotes,\n };\n if (options.dryRun) return result;\n\n inTransaction(target.db, () => {\n if (!into) {\n const [row] = rows(source.db, 'SELECT * FROM sessions WHERE id = ?', session.id);\n // The parent is a session of the source group, unknown here.\n if (row) insert(target.db, 'sessions', { ...row, parent_id: null });\n } else if (into.name === null && session.name !== null) {\n target.db\n .prepare(\"UPDATE sessions SET name = ?, kind = 'active' WHERE id = ?\")\n .run(session.name, intoId);\n }\n for (const agent of movedAgents) insert(target.db, 'agents', { ...agent, session: intoId });\n for (const { id: _id, ...event } of events) {\n insert(target.db, 'events', { ...event, session: intoId });\n }\n if (table && movedTable) insert(target.db, 'table_items', { ...table, session: intoId });\n for (const repo of rows(\n source.db,\n 'SELECT * FROM session_repos WHERE session = ?',\n session.id,\n )) {\n target.db\n .prepare(\n 'INSERT OR IGNORE INTO session_repos (session, repo, injected_at) VALUES (?, ?, ?)',\n )\n .run(intoId, repo.repo ?? null, repo.injected_at ?? null);\n }\n });\n\n // Notes belong to their group: they stay, only their link to the moved session goes.\n inTransaction(source.db, () => {\n for (const table of ['agents', 'events', 'table_items']) {\n source.db.prepare(`DELETE FROM ${table} WHERE session = ?`).run(session.id);\n }\n source.db.prepare('UPDATE sessions SET parent_id = NULL WHERE parent_id = ?').run(session.id);\n source.db.prepare('DELETE FROM sessions WHERE id = ?').run(session.id);\n });\n return result;\n}\n","import { existsSync, mkdirSync, writeFileSync } from 'node:fs';\nimport { basename, join, resolve } from 'node:path';\nimport { CarnetError } from '../errors.ts';\nimport { openDatabase } from '../db/open.ts';\nimport { DEFAULT_HOST, hostById } from '../hosts/host.ts';\nimport {\n DB_FILE,\n GROUP_DIRECTORY,\n GROUP_FILE,\n REPORTS_DIRECTORY,\n type Group,\n type GroupFile,\n loadGroup,\n} from './locate.ts';\nimport { registerGroup } from './registry.ts';\n\nexport interface InitOptions {\n name?: string | undefined;\n repos?: string[] | undefined;\n hosts?: string[] | undefined;\n env?: NodeJS.ProcessEnv | undefined;\n}\n\nfunction writeGroupFile(root: string, file: GroupFile): void {\n writeFileSync(join(root, GROUP_DIRECTORY, GROUP_FILE), `${JSON.stringify(file, null, 2)}\\n`);\n}\n\nfunction resolveRepo(root: string, repo: string): string {\n const path = resolve(root, repo);\n if (!existsSync(path))\n throw new CarnetError('REPO_NOT_FOUND', `Repo path does not exist: ${path}`);\n return path;\n}\n\nexport function initGroup(directory: string, options: InitOptions = {}): Group {\n const root = resolve(directory);\n const groupDirectory = join(root, GROUP_DIRECTORY);\n if (existsSync(groupDirectory)) {\n throw new CarnetError('GROUP_EXISTS', `${root} is already a Rucher group`);\n }\n const name = options.name ?? basename(root);\n const repos = [...new Set((options.repos ?? []).map((repo) => resolveRepo(root, repo)))];\n const names = repos.map((repo) => basename(repo));\n const shared = names.find((repoName, index) => names.indexOf(repoName) !== index);\n if (shared) {\n throw new CarnetError(\n 'REPO_NAME_TAKEN',\n `Two repos are named ${shared}: give them distinct names`,\n );\n }\n const hosts = (options.hosts?.length ? options.hosts : [DEFAULT_HOST]).map(\n (id) => hostById(id).id,\n );\n mkdirSync(join(groupDirectory, REPORTS_DIRECTORY), { recursive: true });\n writeGroupFile(root, { name, repos, hosts });\n openDatabase(join(groupDirectory, DB_FILE)).close();\n registerGroup({ name, path: root }, options.env);\n return loadGroup(root);\n}\n\nexport function addGroupRepo(root: string, repo: string): Group {\n const group = loadGroup(resolve(root));\n const path = resolveRepo(group.root, repo);\n const sameName = group.repos.find(\n (existing) => existing !== path && basename(existing) === basename(path),\n );\n // Notes reference repos by name, so two repos cannot share one.\n if (sameName) {\n throw new CarnetError(\n 'REPO_NAME_TAKEN',\n `${group.name} already has a repo named ${basename(path)}: ${sameName}`,\n );\n }\n if (!group.repos.includes(path)) {\n writeGroupFile(group.root, {\n name: group.name,\n repos: [...group.repos, path],\n hosts: group.hosts,\n });\n }\n return loadGroup(group.root);\n}\n\nexport function removeGroupRepo(root: string, repo: string): Group {\n const group = loadGroup(resolve(root));\n const path = resolve(group.root, repo);\n if (!group.repos.includes(path)) {\n throw new CarnetError('REPO_NOT_FOUND', `${path} is not a repo of ${group.name}`);\n }\n writeGroupFile(group.root, {\n name: group.name,\n repos: group.repos.filter((repo) => repo !== path),\n hosts: group.hosts,\n });\n return loadGroup(group.root);\n}\n","import type { Carnet } from '../carnet.ts';\nimport type { HostSessionEndPayload } from '../hosts/host.ts';\nimport type { Session } from '../sessions.ts';\n\nexport function handleSessionEnd(\n carnet: Carnet,\n payload: HostSessionEndPayload,\n): Session | undefined {\n if (!carnet.sessions.get(payload.session_id)) return undefined;\n return carnet.sessions.end(payload.session_id);\n}\n","// Generated from docs/workflow.md by pnpm run build. Do not edit.\nexport const CORE_RULES = `- Work can be parallel, review stays sequential: forks work at the same time, the human handles their results one at a time.\n- The human keeps the hand: only the human launches forks, applies, tests and commits. Agents propose, they never push.\n- Status lives in Carnet: agent statuses, the \"On the table\" line and the journal go through the Carnet tools, never into status files nor chat updates. Update before and after each piece of work.\n- When a fork finishes, say only \"<name> finished, report ready\". Never summarise, quote or act on its report or final message until the human asks for that fork's report, even when answering about something else.\n- Forks never commit, push, stash or record notes. A fork writes its report to a file, ending with a Learnings section, calls agent_done as its last tool action, then replies with one line that carries no results, such as \"<name> done, report written\". Only the main agent records notes, at the end of a step.\n- To dispatch, apply or review forks, load the rucher skill: it holds the full workflow.`;\n","import { createHash } from 'node:crypto';\nimport { existsSync, mkdirSync, readFileSync, writeFileSync } from 'node:fs';\nimport { join } from 'node:path';\nimport { GROUP_DIRECTORY, type Group } from '../group/locate.ts';\nimport { rucherHome } from '../group/registry.ts';\nimport { shortId, type SessionKind } from '../sessions.ts';\nimport { CORE_RULES } from './core-rules.ts';\n\nexport const PROMPT_FILE = 'prompt.md';\nexport const PROMPTS_DIRECTORY = 'prompts';\n\nexport interface PromptSession {\n id: string;\n name: string | null;\n kind: SessionKind;\n}\n\nexport interface AssembledPrompt {\n text: string;\n version: string;\n}\n\nexport interface AppendPromptFile {\n path: string;\n version: string;\n}\n\nfunction readIfPresent(path: string): string | undefined {\n if (!existsSync(path)) return undefined;\n const content = readFileSync(path, 'utf8').trim();\n return content || undefined;\n}\n\nexport function baseRules(env: NodeJS.ProcessEnv = process.env): string {\n return readIfPresent(join(rucherHome(env), PROMPT_FILE)) ?? CORE_RULES;\n}\n\nexport function groupRules(group: Group): string | undefined {\n return readIfPresent(join(group.root, GROUP_DIRECTORY, PROMPT_FILE));\n}\n\nexport function rulesText(group: Group, env: NodeJS.ProcessEnv = process.env): string {\n const extra = groupRules(group);\n const base = `Rucher rules:\\n${baseRules(env)}`;\n return extra ? `${base}\\n\\nRules of the ${group.name} group:\\n${extra}` : base;\n}\n\n// The identity block is left out so that renaming a session doesn't read as a rules change.\nexport function rulesVersion(group: Group, env: NodeJS.ProcessEnv = process.env): string {\n return createHash('sha256').update(rulesText(group, env)).digest('hex').slice(0, 12);\n}\n\nexport function assemblePrompt(\n group: Group,\n session: PromptSession,\n env: NodeJS.ProcessEnv = process.env,\n): AssembledPrompt {\n const label = session.name ?? shortId(session.id);\n const identity = `This is the Rucher session ${label} (${session.kind}) of the ${group.name} group.`;\n return { text: `${rulesText(group, env)}\\n\\n${identity}\\n`, version: rulesVersion(group, env) };\n}\n\nexport function appendPromptFile(\n group: Group,\n session: PromptSession,\n env: NodeJS.ProcessEnv = process.env,\n): AppendPromptFile {\n const { text, version } = assemblePrompt(group, session, env);\n const directory = join(group.root, GROUP_DIRECTORY, PROMPTS_DIRECTORY);\n mkdirSync(directory, { recursive: true });\n const path = join(directory, `${session.id}.md`);\n writeFileSync(path, text);\n return { path, version };\n}\n\nexport function compactReminder(group: Group, env: NodeJS.ProcessEnv = process.env): string {\n return `The conversation was just compacted and this session was not started by rucher, so its system prompt no longer holds the Rucher rules. ${rulesText(group, env)}`;\n}\n\nexport const OUTSIDE_RUCHER_CONTEXT =\n 'This session was started without rucher, so the Rucher rules are not in its system prompt. Follow the Carnet server instructions and load the rucher skill before dispatching or applying forks.';\n\nexport const OUTSIDE_RUCHER_NOTICE =\n 'rucher: session started without rucher, the Rucher rules are not in its system prompt (use rucher new, tmp or resume)';\n\nexport const RULES_UPDATED_NOTICE =\n 'rucher: rules updated, will apply after the next compaction or in a new session';\n\nexport const SUBAGENT_RULES =\n 'Rucher rules for sub-agents: never commit, push or stash. When your task asks for a report, write it to the file it names. If your prompt names you as a Carnet agent, call agent_update at meaningful progress and agent_done as your last tool action, then reply with one line.';\n","import type { Carnet } from '../carnet.ts';\nimport type { SessionEventType } from '../events.ts';\nimport {\n compactReminder,\n OUTSIDE_RUCHER_CONTEXT,\n OUTSIDE_RUCHER_NOTICE,\n RULES_UPDATED_NOTICE,\n rulesVersion,\n} from '../prompt/prompt.ts';\nimport { hostById } from '../hosts/host.ts';\nimport { memoryMaxCharacters } from '../memory.ts';\nimport { memoryHalfLife } from '../notes.ts';\nimport { purgeDays } from '../purge.ts';\nimport { resumeContext } from '../resume.ts';\nimport type { HookEnv, HookSessionPayload, Session } from '../sessions.ts';\n\nexport interface SessionStartResult {\n session: Session;\n additionalContext?: string;\n contextParts: string[];\n notices: string[];\n}\n\nconst SOURCE_EVENTS: Readonly<Record<string, SessionEventType>> = {\n startup: 'session.started',\n resume: 'session.resumed',\n fork: 'session.forked',\n};\n\n// A fork gets a new id from the host; the launcher's env still carries the parent's.\nfunction adoptFork(carnet: Carnet, session: Session, env: HookEnv): Session {\n const parentId = env.RUCHER_SESSION_ID;\n if (!parentId || parentId === session.id || !carnet.sessions.get(parentId)) return session;\n let fork = carnet.sessions.setParent(session.id, parentId);\n carnet.memory.copyRepos(parentId, session.id);\n const kind = env.RUCHER_SESSION_KIND;\n if (kind === 'active' || kind === 'temp') {\n fork = carnet.sessions.setKind(session.id, kind, env.RUCHER_SESSION_NAME || null);\n }\n return fork;\n}\n\n// A fork inherits its parent's conversation, notes included.\nfunction startMemory(\n carnet: Carnet,\n session: Session,\n source: string,\n env: HookEnv,\n): string | undefined {\n const options = {\n maxCharacters: memoryMaxCharacters(env.RUCHER_MEMORY_MAX_CHARACTERS),\n halfLifeDays: memoryHalfLife(env.RUCHER_MEMORY_HALF_LIFE_DAYS),\n };\n if (source === 'startup' || source === 'clear') return carnet.memory.atStart(session, options);\n if (source === 'resume' || source === 'compact') return carnet.memory.ofSession(session, options);\n return undefined;\n}\n\nexport function handleSessionStart(\n carnet: Carnet,\n payload: HookSessionPayload,\n env: HookEnv,\n): SessionStartResult {\n let session = carnet.sessions.upsertFromHook(payload, env);\n const source = payload.source ?? '';\n if (source === 'fork') session = adoptFork(carnet, session, env);\n const event = SOURCE_EVENTS[source];\n if (event) carnet.events.log(session.id, { type: event });\n session = carnet.sessions.setStatus(session.id, 'running');\n carnet.sessions.purge(session.id, purgeDays(env.RUCHER_PURGE_DAYS));\n\n const promptEnv = { RUCHER_HOME: env.RUCHER_HOME };\n const launchedVersion = env.RUCHER_PROMPT_VERSION || null;\n const contextParts: string[] = [];\n const notices: string[] = [];\n if (hostById(session.host).rendersSystemPrompt(source)) {\n session = carnet.sessions.recordPromptVersion(session.id, launchedVersion);\n }\n if (source === 'resume') contextParts.push(resumeContext(carnet, session));\n const memory = startMemory(carnet, session, source, env);\n if (memory) contextParts.push(memory);\n if (source === 'compact' && !launchedVersion) {\n contextParts.push(compactReminder(carnet.group, promptEnv));\n } else if (!env.RUCHER_SESSION_ID && !session.promptVersion) {\n contextParts.push(OUTSIDE_RUCHER_CONTEXT);\n notices.push(OUTSIDE_RUCHER_NOTICE);\n } else if (\n session.promptVersion &&\n session.promptVersion !== rulesVersion(carnet.group, promptEnv)\n ) {\n notices.push(RULES_UPDATED_NOTICE);\n }\n const additionalContext = contextParts.length ? contextParts.join('\\n\\n') : undefined;\n return { session, contextParts, notices, ...(additionalContext ? { additionalContext } : {}) };\n}\n","import type { Carnet } from '../carnet.ts';\nimport type { Host, HostPromptPayload } from '../hosts/host.ts';\nimport type { Session } from '../sessions.ts';\n\nexport function handleUserPromptSubmit(\n carnet: Carnet,\n host: Host,\n payload: HostPromptPayload,\n): Session {\n carnet.sessions.ensure(payload.session_id, payload.cwd);\n carnet.notes.recordActiveDay();\n return carnet.sessions.adoptTitle(payload.session_id, host.promptTitle(payload));\n}\n","import type { Carnet } from '../carnet.ts';\nimport { repoNameFor } from '../group/locate.ts';\nimport type { HostToolPayload } from '../hosts/host.ts';\nimport { memoryMaxCharacters } from '../memory.ts';\nimport { memoryHalfLife } from '../notes.ts';\nimport type { HookEnv } from '../sessions.ts';\n\nexport function handleToolUse(\n carnet: Carnet,\n payload: HostToolPayload,\n env: HookEnv,\n): string | undefined {\n // session_repos tracks the main conversation; a subagent's context is not it.\n if (payload.agent_id) return undefined;\n const repo = repoNameFor(carnet.group, payload.path);\n if (!repo) return undefined;\n const session = carnet.sessions.ensure(payload.session_id, payload.cwd);\n return carnet.memory.forRepo(session, repo, {\n maxCharacters: memoryMaxCharacters(env.RUCHER_MEMORY_MAX_CHARACTERS),\n halfLifeDays: memoryHalfLife(env.RUCHER_MEMORY_HALF_LIFE_DAYS),\n });\n}\n"],"mappings":";;;;;AAsBA,SAAS,KAAK,IAAkB,KAAa,GAAG,YAAoC;CAClF,OAAO,GAAG,QAAQ,GAAG,CAAC,CAAC,IAAI,GAAG,UAAU;AAC1C;AAEA,SAAS,MAAM,IAAkB,KAAa,GAAG,YAAqC;CACpF,OAAO,OAAQ,GAAG,QAAQ,GAAG,CAAC,CAAC,IAAI,GAAG,UAAU,CAAC,CAAuB,KAAK;AAC/E;AAEA,SAAS,OAAO,IAAkB,OAAe,KAAgB;CAC/D,MAAM,UAAU,OAAO,KAAK,GAAG;CAC/B,GAAG,QACD,eAAe,MAAM,IAAI,QAAQ,KAAK,IAAI,EAAE,YAAY,QAAQ,UAAU,GAAG,CAAC,CAAC,KAAK,IAAI,EAAE,EAC5F,CAAC,CAAC,IAAI,GAAG,QAAQ,KAAK,WAAW,IAAI,WAAW,IAAI,CAAC;AACvD;AAEA,SAAS,cAAc,IAAkB,KAAuB;CAC9D,GAAG,KAAK,OAAO;CACf,IAAI;EACF,IAAI;EACJ,GAAG,KAAK,QAAQ;CAClB,SAAS,OAAO;EACd,GAAG,KAAK,UAAU;EAClB,MAAM;CACR;AACF;AAEA,SAAS,eAAe,QAAgB,SAAkB,OAAgC;CACxF,MAAM,SAAS,OAAO,SAAS,IAAI,QAAQ,EAAE;CAC7C,MAAM,CAAC,SAAS,QAAQ,OACpB,KAAK,OAAO,IAAI,0CAA0C,QAAQ,IAAI,IACtE,CAAC;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
|
package/dist/mcp.d.mts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { r as OpenCarnetOptions, t as Carnet, yt as Host } from "./carnet--axAq8FF.mjs";
|
|
2
2
|
import { McpServer } from "@modelcontextprotocol/server";
|
|
3
3
|
import { StdioServerHandle } from "@modelcontextprotocol/server/stdio";
|
|
4
4
|
import * as z from "zod/v4";
|
|
5
|
-
export declare const INSTRUCTIONS = "Carnet tracks
|
|
5
|
+
export declare const INSTRUCTIONS = "Carnet tracks sub-agents (forks), the \"On the table\" line, sessions, the journal and the group memory, in a shared database the `rucher` CLI renders. Status goes through these tools only: never status files, never status updates in the chat. Your session is resolved automatically; pass `session` only to target another one. The full workflow is the rucher skill: load it before dispatching, applying or reviewing forks.\n\nMain agent:\n- agent_start before dispatching a fork (name, task), in an earlier message than the launch. Launch it with the agent name as the Agent description and a prompt starting with \"You are fork `<name>`.\" Names are short, no paths.\n- table_set with main_working=true before applying, testing or fixing yourself; table_set with a status, or table_clear, when done.\n- log_event when a step is answered, applied, tested, committed or dropped.\n- When a fork finishes: say only \"<name> finished, report ready\", copy its report to the destination agent_start gave and call agent_update with that report_path. Present a fork's report only when the human asks for it: never summarise or act on it, or on the fork's final message, before.\n- agent_update to move an agent to the next human action; agent_drop once committed or abandoned; queue_reorder to change the order; agent_list to recall where things stand.\n- note_add at the end of a step for what was learned, decided or ruled out; note_drop with the reason when a note proves wrong; promote the Learnings of fork reports.\n- session_new when the human names this session; session_list, session_resume_info and log_read to recall sessions or the journal; session_drop only when the human asks.\n\nForks:\n- agent_update (status running, short note) at meaningful progress.\n- agent_done with the report path as your LAST tool action, has_questions=true when the report asks the human something, then reply with one line that carries no results (\"<name> done, report written\").\n- Never agent_start, table_set or note_add: end the report with a Learnings section. Both roles: note_cite when a note changed what you did.\n\nStatuses (the NEXT action): running ⏳ fork working · discussing 💬 · answer ❓ · review 👀 · apply 📥 · test 🧪 · commit ✅ · branch 🌿. Notes and table text: under 60 characters, no paths, no backticks.";
|
|
6
6
|
interface SessionResolverOptions {
|
|
7
7
|
carnet: Carnet;
|
|
8
8
|
env?: NodeJS.ProcessEnv | undefined;
|
package/dist/mcp.d.mts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mcp.d.mts","names":[],"sources":["../src/mcp/instructions.ts","../src/mcp/session.ts","../src/mcp/server.ts","../src/mcp/tools.ts"],"mappings":";;;;qBAAa;UCMI;EACf,QAAQ;EACR,MAAM,OAAO;EACb;EACA;EACA,OAAO;;UAGQ;EACf,QAAQ;;wBAGM,wBACd,QACA,KACA,MACA,KACA,QACC,yBAAyB;qBCXf;qBACA;UAEI,4BAA4B,KAAK;EAChD,QAAQ,gBAAgB;;wBAOV,mBAAmB,SAAS,sBAAsB;UAgCjD,2BAA2B;EAC1C,SAAS;EACT;;wBAGc,YAAY,UAAS,qBAA0B;
|
|
1
|
+
{"version":3,"file":"mcp.d.mts","names":[],"sources":["../src/mcp/instructions.ts","../src/mcp/session.ts","../src/mcp/server.ts","../src/mcp/tools.ts"],"mappings":";;;;qBAAa;UCMI;EACf,QAAQ;EACR,MAAM,OAAO;EACb;EACA;EACA,OAAO;;UAGQ;EACf,QAAQ;;wBAGM,wBACd,QACA,KACA,MACA,KACA,QACC,yBAAyB;qBCXf;qBACA;UAEI,4BAA4B,KAAK;EAChD,QAAQ,gBAAgB;;wBAOV,mBAAmB,SAAS,sBAAsB;UAgCjD,2BAA2B;EAC1C,SAAS;EACT;;wBAGc,YAAY,UAAS,qBAA0B;UClD9C;EACf;EACA,OAAO;;UAGQ,eAAe,eAAe,EAAE,YAAY,EAAE;EAC7D;EACA;EACA,QAAQ;EACR,MAAM,QAAQ,QAAQ,mBAAmB,MAAM,EAAE,MAAM,YAAY;;qBA+YxD,gBAAgB"}
|