@rucher/carnet 0.2.0-beta.5 → 0.2.0-beta.7
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/dist/{carnet-v6FelCYZ.d.mts → carnet-jmxAmm-u.d.mts} +146 -39
- package/dist/carnet-jmxAmm-u.d.mts.map +1 -0
- package/dist/index.d.mts +23 -6
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs +100 -2
- 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 +329 -22
- package/dist/mcp.mjs.map +1 -1
- package/dist/{steps-CzJOqsBI.mjs → steps-Bd8FlgLs.mjs} +532 -118
- package/dist/steps-Bd8FlgLs.mjs.map +1 -0
- package/package.json +1 -1
- package/dist/carnet-v6FelCYZ.d.mts.map +0 -1
- package/dist/steps-CzJOqsBI.mjs.map +0 -1
|
@@ -24,7 +24,10 @@ const EVENT_TYPES = [
|
|
|
24
24
|
"applied",
|
|
25
25
|
"tested",
|
|
26
26
|
"committed",
|
|
27
|
-
"dropped"
|
|
27
|
+
"dropped",
|
|
28
|
+
"injected",
|
|
29
|
+
"promoted",
|
|
30
|
+
"triaged"
|
|
28
31
|
];
|
|
29
32
|
const SESSION_EVENT_TYPES = [
|
|
30
33
|
"session.started",
|
|
@@ -53,9 +56,10 @@ function logEvent(ctx, session, input) {
|
|
|
53
56
|
const result = ctx.db.prepare("INSERT INTO events (session, at, type, agent, commit_sha, link, note) VALUES (?, ?, ?, ?, ?, ?, ?)").run(session, nowIso(ctx), input.type, input.agent ?? null, input.commit ?? null, input.link ?? null, input.note ?? null);
|
|
54
57
|
return toEvent(ctx.db.prepare("SELECT * FROM events WHERE id = ?").get(result.lastInsertRowid));
|
|
55
58
|
}
|
|
56
|
-
function readEvents(ctx, { session, limit = 20, agentOnly = false }) {
|
|
57
|
-
const
|
|
58
|
-
|
|
59
|
+
function readEvents(ctx, { session, limit = 20, agentOnly = false, kind }) {
|
|
60
|
+
const filters = [agentOnly ? "AND type NOT LIKE 'session.%'" : "", kind ? "AND agent IN (SELECT name FROM agents WHERE session = events.session AND kind = ?)" : ""].join(" ");
|
|
61
|
+
const parameters = kind ? [session, kind] : [session];
|
|
62
|
+
return ctx.db.prepare(`SELECT * FROM (SELECT * FROM events WHERE session = ? ${filters} ORDER BY at DESC, id DESC LIMIT ?) ORDER BY at, id`).all(...parameters, limit).map(toEvent);
|
|
59
63
|
}
|
|
60
64
|
// src/status/model.ts
|
|
61
65
|
const AGENT_STATUSES = [
|
|
@@ -89,7 +93,16 @@ const EMOJI = {
|
|
|
89
93
|
branch: "🌿"
|
|
90
94
|
};
|
|
91
95
|
const MAIN_WORKING_EMOJI = "⚙️";
|
|
92
|
-
const
|
|
96
|
+
const MAIN_WAITING_EMOJI = "⏸";
|
|
97
|
+
const MAIN_FAILED_EMOJI = "⚠";
|
|
98
|
+
const LEGEND = "⚙️ main working · ⏸ waiting on you · ⚠ turn failed · 💬 discussing · ❓ answer · 👀 review · 📥 apply · 🧪 test · ✅ commit · 🌿 branch · ⏳ running";
|
|
99
|
+
const KIND_ABBREVIATIONS = {
|
|
100
|
+
research: "rs",
|
|
101
|
+
analyze: "an",
|
|
102
|
+
implement: "im",
|
|
103
|
+
review: "rv"
|
|
104
|
+
};
|
|
105
|
+
const KIND_LEGEND = "rs research · an analyze · im implement · rv review";
|
|
93
106
|
function isAgentStatus(value) {
|
|
94
107
|
return typeof value === "string" && AGENT_STATUSES.includes(value);
|
|
95
108
|
}
|
|
@@ -112,10 +125,34 @@ function sanitizeNote(text) {
|
|
|
112
125
|
return `${cleaned.slice(0, 59).trimEnd()}…`;
|
|
113
126
|
}
|
|
114
127
|
// src/agents.ts
|
|
128
|
+
const AGENT_KINDS = [
|
|
129
|
+
"research",
|
|
130
|
+
"analyze",
|
|
131
|
+
"implement",
|
|
132
|
+
"review"
|
|
133
|
+
];
|
|
134
|
+
const DEFAULT_AGENT_KIND = "analyze";
|
|
135
|
+
const FINAL_ACTIONS = {
|
|
136
|
+
research: "inject",
|
|
137
|
+
analyze: "validate",
|
|
138
|
+
implement: "apply",
|
|
139
|
+
review: "triage"
|
|
140
|
+
};
|
|
141
|
+
function isAgentKind(value) {
|
|
142
|
+
return typeof value === "string" && AGENT_KINDS.includes(value);
|
|
143
|
+
}
|
|
144
|
+
const MAIN_TARGET = /^main(?::(.+))?$/;
|
|
145
|
+
function mainTargetRange(target) {
|
|
146
|
+
const match = MAIN_TARGET.exec(target);
|
|
147
|
+
return match ? match[1]?.trim() ?? null : void 0;
|
|
148
|
+
}
|
|
115
149
|
function toAgent(row) {
|
|
116
150
|
return {
|
|
117
151
|
session: row.session,
|
|
118
152
|
name: row.name,
|
|
153
|
+
kind: row.kind,
|
|
154
|
+
promotedFrom: row.promoted_from,
|
|
155
|
+
target: row.target,
|
|
119
156
|
task: row.task,
|
|
120
157
|
status: row.status,
|
|
121
158
|
note: row.note,
|
|
@@ -157,14 +194,27 @@ function requireAgent(ctx, session, name) {
|
|
|
157
194
|
if (!agent) throw new CarnetError("AGENT_NOT_FOUND", `No agent "${name}" in this session`);
|
|
158
195
|
return agent;
|
|
159
196
|
}
|
|
197
|
+
function checkReviewTarget(ctx, session, target) {
|
|
198
|
+
if (mainTargetRange(target) !== void 0) return;
|
|
199
|
+
const agent = getAgent(ctx, session, target);
|
|
200
|
+
if (!agent || agent.kind !== "implement") throw new CarnetError("INVALID_TARGET", `Target "${target}" is not an implement agent of this session; use its name, or main[:<range>]`);
|
|
201
|
+
if (agent.status === "running") throw new CarnetError("INVALID_TARGET", `Target "${target}" is still running`);
|
|
202
|
+
if (agent.status === "closed") throw new CarnetError("INVALID_TARGET", `Target "${target}" is closed; review main[:<range>] instead`);
|
|
203
|
+
}
|
|
160
204
|
function startAgent(ctx, session, input) {
|
|
161
205
|
const name = sanitizeNote(input.name);
|
|
206
|
+
const kind = input.kind ?? "analyze";
|
|
207
|
+
const target = input.target?.trim() || null;
|
|
208
|
+
if (kind === "review" && !target) throw new CarnetError("INVALID_TARGET", "A review needs a target: an implement agent name, or main[:<range>]");
|
|
209
|
+
if (kind !== "review" && target) throw new CarnetError("INVALID_TARGET", "Only a review agent takes a target");
|
|
210
|
+
if (target) checkReviewTarget(ctx, session, target);
|
|
162
211
|
const existing = getAgent(ctx, session, name);
|
|
163
212
|
if (existing && existing.status !== "closed") throw new CarnetError("AGENT_EXISTS", `Agent "${name}" is already open in this session`);
|
|
164
213
|
if (existing) ctx.db.prepare("DELETE FROM agents WHERE session = ? AND name = ?").run(session, name);
|
|
165
214
|
const at = nowIso(ctx);
|
|
166
|
-
ctx.db.prepare(`INSERT INTO agents (session, name, task, status, base_commit, worktree,
|
|
167
|
-
|
|
215
|
+
ctx.db.prepare(`INSERT INTO agents (session, name, kind, target, task, status, base_commit, worktree,
|
|
216
|
+
started_at, updated_at)
|
|
217
|
+
VALUES (?, ?, ?, ?, ?, 'running', ?, ?, ?, ?)`).run(session, name, kind, target, input.task, input.baseCommit ?? null, input.worktree ?? null, at, at);
|
|
168
218
|
logEvent(ctx, session, {
|
|
169
219
|
type: "started",
|
|
170
220
|
agent: name,
|
|
@@ -175,27 +225,55 @@ function startAgent(ctx, session, input) {
|
|
|
175
225
|
function updateAgent(ctx, session, name, input) {
|
|
176
226
|
const current = requireAgent(ctx, session, name);
|
|
177
227
|
if (!isAgentStatus(input.status) || input.status === "closed") throw new CarnetError("INVALID_STATUS", `Invalid agent status "${input.status}"; use agent_drop to close`);
|
|
178
|
-
|
|
228
|
+
let note;
|
|
229
|
+
if (input.note !== void 0) note = input.note === null ? null : sanitizeNote(input.note);
|
|
230
|
+
else note = current.status === "running" && input.status !== "running" ? null : current.note;
|
|
179
231
|
if (current.pendingStatus) publishPending(ctx, session, name);
|
|
180
|
-
ctx.db.prepare("UPDATE agents SET note =
|
|
232
|
+
ctx.db.prepare("UPDATE agents SET note = ?, status = ?, report_path = COALESCE(?, report_path), updated_at = ? WHERE session = ? AND name = ?").run(note, input.status, input.reportPath ?? null, nowIso(ctx), session, name);
|
|
181
233
|
return requireAgent(ctx, session, name);
|
|
182
234
|
}
|
|
235
|
+
function statusWhenDone(kind, hasQuestions) {
|
|
236
|
+
if (hasQuestions) return "answer";
|
|
237
|
+
return kind === "implement" ? "apply" : "review";
|
|
238
|
+
}
|
|
183
239
|
function finishAgent(ctx, session, name, input) {
|
|
184
240
|
const agent = requireAgent(ctx, session, name);
|
|
185
|
-
const status = input.hasQuestions
|
|
241
|
+
const status = statusWhenDone(agent.kind, input.hasQuestions);
|
|
186
242
|
const at = nowIso(ctx);
|
|
187
243
|
ctx.db.prepare("UPDATE agents SET pending_status = ?, note = ?, report_path = ?, done_at = ?, updated_at = ? WHERE session = ? AND name = ?").run(status, REPORTING_NOTE, input.reportPath, at, at, session, name);
|
|
188
244
|
if (!agent.hostAgentId) publishPending(ctx, session, name);
|
|
189
245
|
return requireAgent(ctx, session, name);
|
|
190
246
|
}
|
|
191
|
-
function
|
|
247
|
+
function statusAfterAnswers(kind) {
|
|
248
|
+
return kind === "implement" ? "apply" : "review";
|
|
249
|
+
}
|
|
250
|
+
function closeAgent(ctx, session, name, event) {
|
|
192
251
|
requireAgent(ctx, session, name);
|
|
193
|
-
ctx.db.prepare("UPDATE agents SET status = 'closed', queue_order = NULL, updated_at = ? WHERE session = ? AND name = ?").run(nowIso(ctx), session, name);
|
|
252
|
+
ctx.db.prepare("UPDATE agents SET status = 'closed', pending_status = NULL, queue_order = NULL, updated_at = ? WHERE session = ? AND name = ?").run(nowIso(ctx), session, name);
|
|
194
253
|
logEvent(ctx, session, {
|
|
254
|
+
...event,
|
|
255
|
+
agent: name
|
|
256
|
+
});
|
|
257
|
+
return requireAgent(ctx, session, name);
|
|
258
|
+
}
|
|
259
|
+
function dropAgent(ctx, session, name, reason) {
|
|
260
|
+
return closeAgent(ctx, session, name, {
|
|
195
261
|
type: "dropped",
|
|
196
|
-
agent: name,
|
|
197
262
|
note: reason
|
|
198
263
|
});
|
|
264
|
+
}
|
|
265
|
+
function promoteAgent(ctx, session, name, input) {
|
|
266
|
+
const agent = requireAgent(ctx, session, name);
|
|
267
|
+
if (agent.kind !== "analyze") throw new CarnetError("INVALID_KIND", `Only an analyze agent is promoted; ${name} is ${agent.kind}`);
|
|
268
|
+
ctx.db.prepare(`UPDATE agents SET kind = 'implement', promoted_from = 'analyze', status = 'running',
|
|
269
|
+
pending_status = NULL, note = NULL, worktree = COALESCE(?, worktree),
|
|
270
|
+
base_commit = COALESCE(?, base_commit), updated_at = ?
|
|
271
|
+
WHERE session = ? AND name = ?`).run(input.worktree ?? null, input.baseCommit ?? null, nowIso(ctx), session, name);
|
|
272
|
+
logEvent(ctx, session, {
|
|
273
|
+
type: "promoted",
|
|
274
|
+
agent: name,
|
|
275
|
+
note: "analyze to implement"
|
|
276
|
+
});
|
|
199
277
|
return requireAgent(ctx, session, name);
|
|
200
278
|
}
|
|
201
279
|
function listAgents(ctx, session, options = {}) {
|
|
@@ -213,6 +291,14 @@ function reorderQueue(ctx, session, names) {
|
|
|
213
291
|
return listAgents(ctx, session);
|
|
214
292
|
}
|
|
215
293
|
// src/db/schema.ts
|
|
294
|
+
const DISPOSABLE_SESSION = `workspace IS NULL
|
|
295
|
+
AND NOT EXISTS (SELECT 1 FROM agents WHERE agents.session = sessions.id)
|
|
296
|
+
AND NOT EXISTS (
|
|
297
|
+
SELECT 1 FROM events WHERE events.session = sessions.id AND events.type NOT LIKE 'session.%'
|
|
298
|
+
)
|
|
299
|
+
AND NOT EXISTS (SELECT 1 FROM notes WHERE notes.session = sessions.id OR notes.dropped_session = sessions.id)
|
|
300
|
+
AND NOT EXISTS (SELECT 1 FROM note_citations WHERE note_citations.session = sessions.id)
|
|
301
|
+
AND NOT EXISTS (SELECT 1 FROM sessions AS child WHERE child.parent_id = sessions.id)`;
|
|
216
302
|
const migrations = [
|
|
217
303
|
`
|
|
218
304
|
CREATE TABLE sessions (
|
|
@@ -449,8 +535,111 @@ CREATE INDEX sessions_workspace_status ON sessions(workspace, status, last_activ
|
|
|
449
535
|
CREATE UNIQUE INDEX sessions_workspace_name ON sessions(workspace, name)
|
|
450
536
|
WHERE workspace IS NOT NULL AND name IS NOT NULL;
|
|
451
537
|
CREATE UNIQUE INDEX notes_workspace_number ON notes(workspace, number);
|
|
538
|
+
`,
|
|
539
|
+
`
|
|
540
|
+
DELETE FROM events WHERE session IN (SELECT id FROM sessions WHERE ${DISPOSABLE_SESSION});
|
|
541
|
+
DELETE FROM table_items WHERE session IN (SELECT id FROM sessions WHERE ${DISPOSABLE_SESSION});
|
|
542
|
+
DELETE FROM session_repos WHERE session IN (SELECT id FROM sessions WHERE ${DISPOSABLE_SESSION});
|
|
543
|
+
DELETE FROM sessions WHERE ${DISPOSABLE_SESSION};
|
|
544
|
+
|
|
545
|
+
CREATE TABLE sessions_new (
|
|
546
|
+
id TEXT PRIMARY KEY,
|
|
547
|
+
workspace TEXT NOT NULL,
|
|
548
|
+
name TEXT,
|
|
549
|
+
purpose TEXT,
|
|
550
|
+
kind TEXT NOT NULL DEFAULT 'temp' CHECK (kind IN ('active', 'temp')),
|
|
551
|
+
status TEXT NOT NULL DEFAULT 'idle' CHECK (status IN ('running', 'idle', 'archived')),
|
|
552
|
+
cwd TEXT,
|
|
553
|
+
repo TEXT,
|
|
554
|
+
host TEXT NOT NULL DEFAULT 'claude-code',
|
|
555
|
+
host_pid INTEGER,
|
|
556
|
+
hooked_at TEXT,
|
|
557
|
+
last_title TEXT,
|
|
558
|
+
parent_id TEXT REFERENCES sessions(id),
|
|
559
|
+
prompt_version TEXT,
|
|
560
|
+
created_at TEXT NOT NULL,
|
|
561
|
+
last_active_at TEXT NOT NULL,
|
|
562
|
+
ended_at TEXT,
|
|
563
|
+
turn TEXT CHECK (turn IN ('working', 'waiting', 'failed')),
|
|
564
|
+
turn_started_at TEXT,
|
|
565
|
+
CHECK (kind = 'temp' OR name IS NOT NULL)
|
|
566
|
+
);
|
|
567
|
+
INSERT INTO sessions_new (id, workspace, name, purpose, kind, status, cwd, repo, host, host_pid,
|
|
568
|
+
hooked_at, last_title, parent_id, prompt_version, created_at, last_active_at, ended_at)
|
|
569
|
+
SELECT id, workspace, name, purpose, kind, status, cwd, repo, host, host_pid,
|
|
570
|
+
hooked_at, last_title, parent_id, prompt_version, created_at, last_active_at, ended_at
|
|
571
|
+
FROM sessions;
|
|
572
|
+
DROP TABLE sessions;
|
|
573
|
+
ALTER TABLE sessions_new RENAME TO sessions;
|
|
574
|
+
CREATE INDEX sessions_host_pid ON sessions(host, host_pid, hooked_at);
|
|
575
|
+
CREATE INDEX sessions_workspace_status ON sessions(workspace, status, last_active_at);
|
|
576
|
+
CREATE UNIQUE INDEX sessions_workspace_name ON sessions(workspace, name) WHERE name IS NOT NULL;
|
|
577
|
+
|
|
578
|
+
ALTER TABLE table_items DROP COLUMN main_working;
|
|
579
|
+
|
|
580
|
+
ALTER TABLE agents ADD COLUMN kind TEXT NOT NULL DEFAULT 'analyze'
|
|
581
|
+
CHECK (kind IN ('research', 'analyze', 'implement', 'review'));
|
|
582
|
+
ALTER TABLE agents ADD COLUMN promoted_from TEXT
|
|
583
|
+
CHECK (promoted_from IN ('research', 'analyze', 'implement', 'review'));
|
|
584
|
+
ALTER TABLE agents ADD COLUMN target TEXT;
|
|
585
|
+
-- Older agents waiting on code steps, or given a worktree, wrote code.
|
|
586
|
+
UPDATE agents SET kind = 'implement'
|
|
587
|
+
WHERE (status IN ('apply', 'test', 'commit')) OR worktree IS NOT NULL;
|
|
588
|
+
|
|
589
|
+
CREATE TABLE agent_questions (
|
|
590
|
+
session TEXT NOT NULL,
|
|
591
|
+
agent TEXT NOT NULL,
|
|
592
|
+
n INTEGER NOT NULL CHECK (n >= 1),
|
|
593
|
+
text TEXT NOT NULL,
|
|
594
|
+
context TEXT,
|
|
595
|
+
recommendation TEXT NOT NULL,
|
|
596
|
+
alternatives TEXT NOT NULL DEFAULT '[]',
|
|
597
|
+
answer TEXT,
|
|
598
|
+
answered_at TEXT,
|
|
599
|
+
PRIMARY KEY (session, agent, n),
|
|
600
|
+
FOREIGN KEY (session, agent) REFERENCES agents(session, name) ON UPDATE CASCADE ON DELETE CASCADE
|
|
601
|
+
);
|
|
602
|
+
|
|
603
|
+
CREATE TABLE review_findings (
|
|
604
|
+
session TEXT NOT NULL,
|
|
605
|
+
agent TEXT NOT NULL,
|
|
606
|
+
n INTEGER NOT NULL CHECK (n >= 1),
|
|
607
|
+
severity TEXT NOT NULL CHECK (severity IN ('blocking', 'to_fix', 'suggestion')),
|
|
608
|
+
location TEXT,
|
|
609
|
+
text TEXT NOT NULL,
|
|
610
|
+
fix TEXT,
|
|
611
|
+
decision TEXT CHECK (decision IN ('sent', 'fixed', 'ignored')),
|
|
612
|
+
reason TEXT,
|
|
613
|
+
decided_at TEXT,
|
|
614
|
+
PRIMARY KEY (session, agent, n),
|
|
615
|
+
FOREIGN KEY (session, agent) REFERENCES agents(session, name) ON UPDATE CASCADE ON DELETE CASCADE
|
|
616
|
+
);
|
|
617
|
+
|
|
618
|
+
CREATE TABLE events_new (
|
|
619
|
+
id INTEGER PRIMARY KEY,
|
|
620
|
+
session TEXT NOT NULL REFERENCES sessions(id),
|
|
621
|
+
at TEXT NOT NULL,
|
|
622
|
+
type TEXT NOT NULL
|
|
623
|
+
CHECK (type IN ('started', 'finished', 'answered', 'applied', 'tested', 'committed', 'dropped',
|
|
624
|
+
'injected', 'promoted', 'triaged',
|
|
625
|
+
'session.started', 'session.resumed', 'session.ended', 'session.forked')),
|
|
626
|
+
agent TEXT,
|
|
627
|
+
commit_sha TEXT,
|
|
628
|
+
link TEXT,
|
|
629
|
+
note TEXT
|
|
630
|
+
);
|
|
631
|
+
INSERT INTO events_new SELECT id, session, at, type, agent, commit_sha, link, note FROM events;
|
|
632
|
+
DROP TABLE events;
|
|
633
|
+
ALTER TABLE events_new RENAME TO events;
|
|
634
|
+
CREATE INDEX events_session_at ON events(session, at);
|
|
452
635
|
`
|
|
453
636
|
];
|
|
637
|
+
const preconditions = { 11: (db) => {
|
|
638
|
+
const kept = db.prepare(`SELECT id, name FROM sessions WHERE workspace IS NULL AND NOT (${DISPOSABLE_SESSION})`).all();
|
|
639
|
+
if (kept.length === 0) return;
|
|
640
|
+
const list = kept.map((row) => row.name ?? row.id).join(", ");
|
|
641
|
+
throw new Error(`Every session now needs a workspace, and these sessions without one hold agents, notes or forks: ${list}. Give each one a workspace with the previous rucher (rucher sessions move), or in SQL: UPDATE sessions SET workspace = '<name>' WHERE id = '<id>'`);
|
|
642
|
+
} };
|
|
454
643
|
function schemaVersion(db) {
|
|
455
644
|
return db.prepare("PRAGMA user_version").get().user_version;
|
|
456
645
|
}
|
|
@@ -467,6 +656,7 @@ function migrate(db) {
|
|
|
467
656
|
if (version < current) continue;
|
|
468
657
|
db.exec("BEGIN");
|
|
469
658
|
try {
|
|
659
|
+
preconditions[version + 1]?.(db);
|
|
470
660
|
db.exec(migration);
|
|
471
661
|
if (foreignKeyViolations(db) > 0) throw new Error(`Migration ${version + 1} broke foreign keys`);
|
|
472
662
|
db.exec(`PRAGMA user_version = ${version + 1}`);
|
|
@@ -537,6 +727,101 @@ function reportsDirectory(workspace) {
|
|
|
537
727
|
function reportPath(workspace, agentName) {
|
|
538
728
|
return join(reportsDirectory(workspace), `${agentName}.md`);
|
|
539
729
|
}
|
|
730
|
+
// src/findings.ts
|
|
731
|
+
const FINDING_SEVERITIES = [
|
|
732
|
+
"blocking",
|
|
733
|
+
"to_fix",
|
|
734
|
+
"suggestion"
|
|
735
|
+
];
|
|
736
|
+
const FINDING_DECISIONS = [
|
|
737
|
+
"sent",
|
|
738
|
+
"fixed",
|
|
739
|
+
"ignored"
|
|
740
|
+
];
|
|
741
|
+
function listFindings(ctx, session, agent, pendingOnly = false) {
|
|
742
|
+
const rows = ctx.db.prepare("SELECT * FROM review_findings WHERE session = ? AND agent = ? ORDER BY n").all(session, agent);
|
|
743
|
+
const total = rows.length;
|
|
744
|
+
return rows.filter((row) => !pendingOnly || row.decision === null).map((row) => ({
|
|
745
|
+
...row,
|
|
746
|
+
total
|
|
747
|
+
}));
|
|
748
|
+
}
|
|
749
|
+
function replaceFindings(ctx, session, agent, inputs) {
|
|
750
|
+
const sorted = [...inputs].sort((a, b) => FINDING_SEVERITIES.indexOf(a.severity) - FINDING_SEVERITIES.indexOf(b.severity));
|
|
751
|
+
ctx.db.prepare("DELETE FROM review_findings WHERE session = ? AND agent = ?").run(session, agent);
|
|
752
|
+
const insert = ctx.db.prepare(`INSERT INTO review_findings (session, agent, n, severity, location, text, fix)
|
|
753
|
+
VALUES (?, ?, ?, ?, ?, ?, ?)`);
|
|
754
|
+
sorted.forEach((input, index) => {
|
|
755
|
+
insert.run(session, agent, index + 1, input.severity, input.location?.trim() || null, input.text.trim(), input.fix?.trim() || null);
|
|
756
|
+
});
|
|
757
|
+
return listFindings(ctx, session, agent);
|
|
758
|
+
}
|
|
759
|
+
function decideFindings(ctx, session, agent, decisions) {
|
|
760
|
+
const known = new Set(listFindings(ctx, session, agent).map((finding) => finding.n));
|
|
761
|
+
const missing = decisions.filter((item) => !known.has(item.n)).map((item) => item.n);
|
|
762
|
+
if (missing.length) throw new CarnetError("FINDING_NOT_FOUND", `No finding ${missing.join(", ")} for ${agent}; review_findings lists them`);
|
|
763
|
+
const unexplained = decisions.filter((item) => item.decision === "ignored" && !item.reason?.trim());
|
|
764
|
+
if (unexplained.length) throw new CarnetError("REASON_REQUIRED", `Ignoring finding ${unexplained.map((item) => item.n).join(", ")} needs a short reason`);
|
|
765
|
+
const at = nowIso(ctx);
|
|
766
|
+
const update = ctx.db.prepare("UPDATE review_findings SET decision = ?, reason = ?, decided_at = ? WHERE session = ? AND agent = ? AND n = ?");
|
|
767
|
+
for (const item of decisions) update.run(item.decision, item.reason?.trim() || null, at, session, agent, item.n);
|
|
768
|
+
return listFindings(ctx, session, agent);
|
|
769
|
+
}
|
|
770
|
+
function formatFinding(finding) {
|
|
771
|
+
const location = finding.location ? ` ${finding.location}` : "";
|
|
772
|
+
const fix = finding.fix ? ` (fix: ${finding.fix})` : "";
|
|
773
|
+
return `${finding.n}/${finding.total} [${finding.severity}]${location} — ${finding.text}${fix}`;
|
|
774
|
+
}
|
|
775
|
+
function renderFindings(findings) {
|
|
776
|
+
return `## Findings\n\n${findings.map((finding) => {
|
|
777
|
+
const location = finding.location ? ` \`${finding.location}\`` : "";
|
|
778
|
+
const fix = finding.fix ? `\n Fix: ${finding.fix}` : "";
|
|
779
|
+
return `${finding.n}. **${finding.severity}**${location}: ${finding.text}${fix}`;
|
|
780
|
+
}).join("\n")}`;
|
|
781
|
+
}
|
|
782
|
+
function listQuestions(ctx, session, agent, openOnly = false) {
|
|
783
|
+
const rows = ctx.db.prepare("SELECT * FROM agent_questions WHERE session = ? AND agent = ? ORDER BY n").all(session, agent);
|
|
784
|
+
const total = rows.length;
|
|
785
|
+
return rows.filter((row) => !openOnly || row.answer === null).map((row) => ({
|
|
786
|
+
n: row.n,
|
|
787
|
+
total,
|
|
788
|
+
text: row.text,
|
|
789
|
+
context: row.context,
|
|
790
|
+
recommendation: row.recommendation,
|
|
791
|
+
alternatives: JSON.parse(row.alternatives),
|
|
792
|
+
answer: row.answer,
|
|
793
|
+
answeredAt: row.answered_at
|
|
794
|
+
}));
|
|
795
|
+
}
|
|
796
|
+
function addQuestions(ctx, session, agent, inputs) {
|
|
797
|
+
for (const input of inputs) if ((input.alternatives?.length ?? 0) > 3) throw new CarnetError("INVALID_QUESTIONS", `A question takes at most 3 alternatives; list more in its text`);
|
|
798
|
+
ctx.db.prepare("DELETE FROM agent_questions WHERE session = ? AND agent = ? AND answer IS NULL").run(session, agent);
|
|
799
|
+
const last = ctx.db.prepare("SELECT COALESCE(MAX(n), 0) AS n FROM agent_questions WHERE session = ? AND agent = ?").get(session, agent);
|
|
800
|
+
const insert = ctx.db.prepare(`INSERT INTO agent_questions (session, agent, n, text, context, recommendation, alternatives)
|
|
801
|
+
VALUES (?, ?, ?, ?, ?, ?, ?)`);
|
|
802
|
+
inputs.forEach((input, index) => {
|
|
803
|
+
insert.run(session, agent, last.n + index + 1, input.text.trim(), input.context?.trim() || null, input.recommendation.trim(), JSON.stringify(input.alternatives ?? []));
|
|
804
|
+
});
|
|
805
|
+
return listQuestions(ctx, session, agent);
|
|
806
|
+
}
|
|
807
|
+
function answerQuestions(ctx, session, agent, answers) {
|
|
808
|
+
const known = new Set(listQuestions(ctx, session, agent).map((question) => question.n));
|
|
809
|
+
const missing = answers.filter((answer) => !known.has(answer.n)).map((answer) => answer.n);
|
|
810
|
+
if (missing.length) throw new CarnetError("QUESTION_NOT_FOUND", `No question ${missing.join(", ")} for ${agent}; agent_questions lists them`);
|
|
811
|
+
const at = nowIso(ctx);
|
|
812
|
+
const update = ctx.db.prepare("UPDATE agent_questions SET answer = ?, answered_at = ? WHERE session = ? AND agent = ? AND n = ?");
|
|
813
|
+
for (const answer of answers) update.run(answer.answer.trim(), at, session, agent, answer.n);
|
|
814
|
+
return listQuestions(ctx, session, agent);
|
|
815
|
+
}
|
|
816
|
+
function renderQuestions(questions) {
|
|
817
|
+
return `## Questions\n\n${questions.map((question) => {
|
|
818
|
+
const lines = [`${question.n}. ${question.text}`];
|
|
819
|
+
if (question.context) lines.push(` Context: ${question.context}`);
|
|
820
|
+
lines.push(` Recommendation: ${question.recommendation}`);
|
|
821
|
+
if (question.alternatives.length) lines.push(` Alternatives: ${question.alternatives.join(" · ")}`);
|
|
822
|
+
return lines.join("\n");
|
|
823
|
+
}).join("\n")}`;
|
|
824
|
+
}
|
|
540
825
|
// src/workspace/workspace.ts
|
|
541
826
|
const WORKSPACE_FILE = "workspace.json";
|
|
542
827
|
const INSTRUCTIONS_FILE = "CLAUDE.md";
|
|
@@ -693,6 +978,10 @@ function toSession(row) {
|
|
|
693
978
|
endedAt: row.ended_at
|
|
694
979
|
};
|
|
695
980
|
}
|
|
981
|
+
function workspaceOf(ctx) {
|
|
982
|
+
if (ctx.workspace !== null) return ctx.workspace;
|
|
983
|
+
throw new CarnetError("NO_WORKSPACE", "A session belongs to a workspace: there is none here");
|
|
984
|
+
}
|
|
696
985
|
function getSession(ctx, id) {
|
|
697
986
|
const row = ctx.db.prepare(`SELECT ${COLUMNS} FROM sessions WHERE id = ?`).get(id);
|
|
698
987
|
return row && toSession(row);
|
|
@@ -706,7 +995,7 @@ function ensureSession(ctx, id, cwd, workspace) {
|
|
|
706
995
|
const existing = getSession(ctx, id);
|
|
707
996
|
if (existing) return existing;
|
|
708
997
|
const at = nowIso(ctx);
|
|
709
|
-
ctx.db.prepare("INSERT INTO sessions (id, workspace, cwd, repo, created_at, last_active_at) VALUES (?, ?, ?, ?, ?, ?)").run(id, ctx
|
|
998
|
+
ctx.db.prepare("INSERT INTO sessions (id, workspace, cwd, repo, created_at, last_active_at) VALUES (?, ?, ?, ?, ?, ?)").run(id, workspaceOf(ctx), cwd ?? null, workspace ? repoNameFor(workspace, cwd) : null, at, at);
|
|
710
999
|
return requireSession(ctx, id);
|
|
711
1000
|
}
|
|
712
1001
|
function nameTaken(error, name) {
|
|
@@ -719,7 +1008,7 @@ function createSession(ctx, input) {
|
|
|
719
1008
|
try {
|
|
720
1009
|
ctx.db.prepare(`INSERT INTO sessions (id, workspace, name, kind, status, cwd, repo, host, last_title,
|
|
721
1010
|
created_at, last_active_at)
|
|
722
|
-
VALUES (?, ?, ?, ?, 'running', ?, ?, ?, ?, ?, ?)`).run(input.id, ctx
|
|
1011
|
+
VALUES (?, ?, ?, ?, 'running', ?, ?, ?, ?, ?, ?)`).run(input.id, workspaceOf(ctx), input.name ?? null, input.kind, input.cwd, input.repo ?? null, input.host ?? "claude-code", input.name ?? null, at, at);
|
|
723
1012
|
} catch (error) {
|
|
724
1013
|
nameTaken(error, input.name);
|
|
725
1014
|
}
|
|
@@ -766,7 +1055,7 @@ function upsertFromHook(ctx, workspace, payload, env = {}) {
|
|
|
766
1055
|
const existing = getSession(ctx, payload.session_id);
|
|
767
1056
|
if (!existing) ctx.db.prepare(`INSERT INTO sessions (id, workspace, cwd, repo, host, host_pid, hooked_at, created_at,
|
|
768
1057
|
last_active_at)
|
|
769
|
-
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)`).run(payload.session_id, ctx
|
|
1058
|
+
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)`).run(payload.session_id, workspaceOf(ctx), payload.cwd ?? null, repo, host, hostPid, at, at, at);
|
|
770
1059
|
else ctx.db.prepare(`UPDATE sessions
|
|
771
1060
|
SET last_active_at = ?, hooked_at = ?, cwd = ?, repo = ?, host = ?, host_pid = ?
|
|
772
1061
|
WHERE id = ?`).run(at, at, existing.cwd ?? payload.cwd ?? null, existing.cwd ? existing.repo : repo ?? existing.repo, host, hostPid ?? existing.hostPid, payload.session_id);
|
|
@@ -789,7 +1078,7 @@ function nameSession(ctx, id, name, purpose) {
|
|
|
789
1078
|
return requireSession(ctx, id);
|
|
790
1079
|
}
|
|
791
1080
|
function listSessions(ctx, options = {}) {
|
|
792
|
-
const conditions = ["workspace
|
|
1081
|
+
const conditions = ["workspace = ?"];
|
|
793
1082
|
if (!options.includeTemp) conditions.push("kind != 'temp'");
|
|
794
1083
|
if (!options.includeArchived) conditions.push("status != 'archived'");
|
|
795
1084
|
return ctx.db.prepare(`SELECT ${COLUMNS} FROM sessions WHERE ${conditions.join(" AND ")} ORDER BY last_active_at DESC`).all(ctx.workspace).map(toSession);
|
|
@@ -802,12 +1091,12 @@ function dropSession(ctx, id) {
|
|
|
802
1091
|
return requireSession(ctx, id);
|
|
803
1092
|
}
|
|
804
1093
|
function defaultSession(ctx) {
|
|
805
|
-
const row = ctx.db.prepare(`SELECT ${COLUMNS} FROM sessions WHERE workspace
|
|
1094
|
+
const row = ctx.db.prepare(`SELECT ${COLUMNS} FROM sessions WHERE workspace = ? AND status != 'archived'
|
|
806
1095
|
ORDER BY last_active_at DESC LIMIT 1`).get(ctx.workspace);
|
|
807
1096
|
return row && toSession(row);
|
|
808
1097
|
}
|
|
809
1098
|
function sessionByName(ctx, name) {
|
|
810
|
-
const row = ctx.db.prepare(`SELECT ${COLUMNS} FROM sessions WHERE workspace
|
|
1099
|
+
const row = ctx.db.prepare(`SELECT ${COLUMNS} FROM sessions WHERE workspace = ? AND name = ?`).get(ctx.workspace, name);
|
|
811
1100
|
return row && toSession(row);
|
|
812
1101
|
}
|
|
813
1102
|
const MINIMUM_ID_PREFIX = 4;
|
|
@@ -821,7 +1110,7 @@ function findSession(ctx, reference) {
|
|
|
821
1110
|
if (byId) return byId;
|
|
822
1111
|
const isIdPrefix = /^[0-9a-f-]+$/i.test(reference);
|
|
823
1112
|
if (isIdPrefix && reference.length >= 4) {
|
|
824
|
-
const rows = ctx.db.prepare(`SELECT ${COLUMNS} FROM sessions WHERE workspace
|
|
1113
|
+
const rows = ctx.db.prepare(`SELECT ${COLUMNS} FROM sessions WHERE workspace = ? AND id LIKE ?
|
|
825
1114
|
ORDER BY last_active_at DESC`).all(ctx.workspace, `${reference.toLowerCase()}%`);
|
|
826
1115
|
const [only, ...others] = rows;
|
|
827
1116
|
if (only && others.length === 0) return toSession(only);
|
|
@@ -889,7 +1178,7 @@ function demoteSession(ctx, id) {
|
|
|
889
1178
|
function staleTempSessions(ctx, olderThanMilliseconds) {
|
|
890
1179
|
const before = new Date(ctx.now().getTime() - olderThanMilliseconds).toISOString();
|
|
891
1180
|
return ctx.db.prepare(`SELECT ${COLUMNS} FROM sessions
|
|
892
|
-
WHERE workspace
|
|
1181
|
+
WHERE workspace = ? AND kind = 'temp' AND status = 'idle' AND last_active_at < ?
|
|
893
1182
|
ORDER BY last_active_at ASC`).all(ctx.workspace, before).map(toSession);
|
|
894
1183
|
}
|
|
895
1184
|
function resetDeadSessions(ctx, isAlive) {
|
|
@@ -897,11 +1186,11 @@ function resetDeadSessions(ctx, isAlive) {
|
|
|
897
1186
|
}
|
|
898
1187
|
// src/prompt/core-rules.ts
|
|
899
1188
|
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.
|
|
900
|
-
- The human keeps the hand: only the human launches
|
|
901
|
-
- Status lives in Carnet: agent statuses, the
|
|
902
|
-
- When
|
|
903
|
-
-
|
|
904
|
-
- To
|
|
1189
|
+
- The human keeps the hand: only the human launches agents, triggers their final action (inject, validate, apply, triage), applies, tests and commits. Agents propose, they never push.
|
|
1190
|
+
- Status lives in Carnet: agent statuses, the Main line and the journal go through the Carnet tools, never into status files nor chat updates. Update before and after each piece of work.
|
|
1191
|
+
- When an agent finishes, say only "<name> finished, report ready". Never summarise, quote or act on its report or final message until the human asks for that report or its final action, even when answering about something else.
|
|
1192
|
+
- Agents never commit, push, stash or record notes. An agent follows its kind's contract, 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.
|
|
1193
|
+
- To launch agents or handle their results, load the rucher skill: it holds the full workflow.`;
|
|
905
1194
|
// src/prompt/prompt.ts
|
|
906
1195
|
const PROMPT_FILE = "prompt.md";
|
|
907
1196
|
function readIfPresent(path) {
|
|
@@ -909,7 +1198,7 @@ function readIfPresent(path) {
|
|
|
909
1198
|
return readFileSync(path, "utf8").trim() || void 0;
|
|
910
1199
|
}
|
|
911
1200
|
function baseRules(env = process.env) {
|
|
912
|
-
return readIfPresent(corePromptPath(env)) ?? "- 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
|
|
1201
|
+
return readIfPresent(corePromptPath(env)) ?? "- 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 agents, triggers their final action (inject, validate, apply, triage), applies, tests and commits. Agents propose, they never push.\n- Status lives in Carnet: agent statuses, the Main 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 an agent finishes, say only \"<name> finished, report ready\". Never summarise, quote or act on its report or final message until the human asks for that report or its final action, even when answering about something else.\n- Agents never commit, push, stash or record notes. An agent follows its kind's contract, 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 launch agents or handle their results, load the rucher skill: it holds the full workflow.";
|
|
913
1202
|
}
|
|
914
1203
|
function workspaceRules(workspace) {
|
|
915
1204
|
return workspace ? readIfPresent(join(workspace.definition, PROMPT_FILE)) : void 0;
|
|
@@ -949,7 +1238,7 @@ function outsideRucherContext(workspace, env = process.env) {
|
|
|
949
1238
|
}
|
|
950
1239
|
const OUTSIDE_RUCHER_NOTICE = "rucher: session started without rucher, the Rucher rules are not in its system prompt (use rucher new, tmp or resume)";
|
|
951
1240
|
const RULES_UPDATED_NOTICE = "rucher: rules updated, will apply after the next compaction or in a new session";
|
|
952
|
-
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.";
|
|
1241
|
+
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, follow the contract of its kind, call agent_update at meaningful progress and agent_done as your last tool action, then reply with one line.";
|
|
953
1242
|
// src/run-directory-files.ts
|
|
954
1243
|
const GENERATED_MARKER = "generated by rucher, do not edit";
|
|
955
1244
|
function refuse(path) {
|
|
@@ -1012,7 +1301,7 @@ function mergeSettings(base, extra) {
|
|
|
1012
1301
|
// src/hosts/claude-code.ts
|
|
1013
1302
|
const TRANSCRIPT_TAIL_BYTES = 262144;
|
|
1014
1303
|
const TITLE_PATTERN = /"type":"custom-title","customTitle":("(?:[^"\\]|\\.)*")/g;
|
|
1015
|
-
const FORK_NAME_PATTERN = /You are fork `([^`]+)`/;
|
|
1304
|
+
const FORK_NAME_PATTERN = /You are (?:agent|fork) `([^`]+)`/;
|
|
1016
1305
|
function payloadObject(json) {
|
|
1017
1306
|
const data = JSON.parse(json);
|
|
1018
1307
|
if (typeof data.session_id !== "string" || !data.session_id) throw new TypeError("Hook payload has no session_id");
|
|
@@ -1131,6 +1420,9 @@ const RENDERING_SOURCES = /* @__PURE__ */ new Set([
|
|
|
1131
1420
|
"compact",
|
|
1132
1421
|
"fork"
|
|
1133
1422
|
]);
|
|
1423
|
+
function projectsDirectory(env) {
|
|
1424
|
+
return join(env.CLAUDE_CONFIG_DIR || join(homedir(), ".claude"), "projects");
|
|
1425
|
+
}
|
|
1134
1426
|
const claudeCode = {
|
|
1135
1427
|
id: "claude-code",
|
|
1136
1428
|
displayName: "Claude Code",
|
|
@@ -1153,6 +1445,14 @@ const claudeCode = {
|
|
|
1153
1445
|
session_title: text(data, "session_title")
|
|
1154
1446
|
};
|
|
1155
1447
|
},
|
|
1448
|
+
parseStopPayload(json) {
|
|
1449
|
+
const data = payloadObject(json);
|
|
1450
|
+
return {
|
|
1451
|
+
session_id: data.session_id,
|
|
1452
|
+
cwd: text(data, "cwd"),
|
|
1453
|
+
failed: data.hook_event_name === "StopFailure"
|
|
1454
|
+
};
|
|
1455
|
+
},
|
|
1156
1456
|
parsePromptPayload(json) {
|
|
1157
1457
|
const data = payloadObject(json);
|
|
1158
1458
|
return {
|
|
@@ -1187,12 +1487,16 @@ const claudeCode = {
|
|
|
1187
1487
|
const data = payloadObject(json);
|
|
1188
1488
|
const toolName = text(data, "tool_name");
|
|
1189
1489
|
const cwd = text(data, "cwd");
|
|
1490
|
+
const toolInput = typeof data.tool_input === "object" && data.tool_input !== null ? data.tool_input : {};
|
|
1190
1491
|
return {
|
|
1191
1492
|
session_id: data.session_id,
|
|
1192
1493
|
cwd,
|
|
1193
1494
|
tool_name: toolName,
|
|
1194
1495
|
agent_id: text(data, "agent_id"),
|
|
1195
|
-
|
|
1496
|
+
agent_type: text(data, "agent_type"),
|
|
1497
|
+
path: touchedPath(toolName, data.tool_input, cwd),
|
|
1498
|
+
file_path: text(toolInput, "file_path") ?? text(toolInput, "notebook_path"),
|
|
1499
|
+
command: text(toolInput, "command")
|
|
1196
1500
|
};
|
|
1197
1501
|
},
|
|
1198
1502
|
subagentInheritsContext(payload) {
|
|
@@ -1249,10 +1553,14 @@ const claudeCode = {
|
|
|
1249
1553
|
},
|
|
1250
1554
|
transcriptFiles(session, env = process.env) {
|
|
1251
1555
|
if (!session.cwd) return [];
|
|
1252
|
-
const
|
|
1253
|
-
const project = join(root, "projects", session.cwd.replace(/[^a-zA-Z0-9]/g, "-"));
|
|
1556
|
+
const project = join(projectsDirectory(env), session.cwd.replace(/[^a-zA-Z0-9]/g, "-"));
|
|
1254
1557
|
return [join(project, `${session.id}.jsonl`), join(project, session.id)].filter((path) => existsSync(path));
|
|
1255
1558
|
},
|
|
1559
|
+
hasConversation(session, env = process.env) {
|
|
1560
|
+
const projects = projectsDirectory(env);
|
|
1561
|
+
if (!existsSync(projects)) return false;
|
|
1562
|
+
return readdirSync(projects).some((project) => existsSync(join(projects, project, `${session.id}.jsonl`)));
|
|
1563
|
+
},
|
|
1256
1564
|
renameInstruction(name) {
|
|
1257
1565
|
return `Ask the human to run /rename ${name} in Claude Code so the titles match.`;
|
|
1258
1566
|
},
|
|
@@ -1282,8 +1590,7 @@ function inTransaction(db, run) {
|
|
|
1282
1590
|
}
|
|
1283
1591
|
}
|
|
1284
1592
|
function sessionWorkspaceName(db, sessionId) {
|
|
1285
|
-
|
|
1286
|
-
return row ? row.workspace : void 0;
|
|
1593
|
+
return db.prepare("SELECT workspace FROM sessions WHERE id = ?").get(sessionId)?.workspace;
|
|
1287
1594
|
}
|
|
1288
1595
|
function archiveWorkspaceSessions(db, name, at) {
|
|
1289
1596
|
return inTransaction(db, () => {
|
|
@@ -1298,9 +1605,13 @@ function deleteWorkspaceNotes(db, name) {
|
|
|
1298
1605
|
}
|
|
1299
1606
|
function workspaceSessionCounts(db) {
|
|
1300
1607
|
const rows = db.prepare(`SELECT workspace, COUNT(*) AS count FROM sessions
|
|
1301
|
-
WHERE
|
|
1608
|
+
WHERE status != 'archived' GROUP BY workspace`).all();
|
|
1302
1609
|
return new Map(rows.map((row) => [row.workspace, Number(row.count)]));
|
|
1303
1610
|
}
|
|
1611
|
+
function workspaceLastActive(db) {
|
|
1612
|
+
const rows = db.prepare("SELECT workspace, MAX(last_active_at) AS at FROM sessions GROUP BY workspace").all();
|
|
1613
|
+
return new Map(rows.map((row) => [row.workspace, row.at]));
|
|
1614
|
+
}
|
|
1304
1615
|
// src/workspace/locate.ts
|
|
1305
1616
|
function isInside(directory, path) {
|
|
1306
1617
|
const relativePath = relative(directory, path);
|
|
@@ -1327,31 +1638,9 @@ function namedWorkspace(name, env) {
|
|
|
1327
1638
|
function byRunDirectory(workspaces, directories) {
|
|
1328
1639
|
return workspaces.find((workspace) => directories.some((directory) => isInside(workspace.runDirectory, directory)));
|
|
1329
1640
|
}
|
|
1330
|
-
function byRepo(workspaces, directory) {
|
|
1331
|
-
let best = [];
|
|
1332
|
-
for (const workspace of workspaces) for (const repo of workspace.repos) {
|
|
1333
|
-
if (!isInside(repo.path, directory)) continue;
|
|
1334
|
-
const length = best[0]?.repo.path.length ?? -1;
|
|
1335
|
-
if (repo.path.length > length) best = [{
|
|
1336
|
-
workspace,
|
|
1337
|
-
repo
|
|
1338
|
-
}];
|
|
1339
|
-
else if (repo.path.length === length) best.push({
|
|
1340
|
-
workspace,
|
|
1341
|
-
repo
|
|
1342
|
-
});
|
|
1343
|
-
}
|
|
1344
|
-
const names = [...new Set(best.map((match) => match.workspace.name))];
|
|
1345
|
-
if (names.length > 1) throw new CarnetError("WORKSPACE_AMBIGUOUS", `${directory} is in repos of several workspaces (${names.join(", ")}): pass --ws`);
|
|
1346
|
-
return best[0];
|
|
1347
|
-
}
|
|
1348
1641
|
function resolveWorkspace({ db, sessionId, workspace, cwd = process.cwd(), env = process.env } = {}) {
|
|
1349
1642
|
if (db && sessionId) {
|
|
1350
1643
|
const name = sessionWorkspaceName(db, sessionId);
|
|
1351
|
-
if (name === null) return {
|
|
1352
|
-
workspace: null,
|
|
1353
|
-
origin: "session"
|
|
1354
|
-
};
|
|
1355
1644
|
if (name !== void 0 && workspaceExists(name, env)) return {
|
|
1356
1645
|
workspace: loadWorkspace(name, env),
|
|
1357
1646
|
origin: "session"
|
|
@@ -1367,20 +1656,11 @@ function resolveWorkspace({ db, sessionId, workspace, cwd = process.cwd(), env =
|
|
|
1367
1656
|
};
|
|
1368
1657
|
const projectDirectories = allHosts().map((host) => host.projectDirectory(env)).filter((directory) => directory !== void 0);
|
|
1369
1658
|
const directories = [resolve(cwd), ...projectDirectories.map((directory) => resolve(directory))];
|
|
1370
|
-
const
|
|
1371
|
-
const runDirectoryWorkspace = byRunDirectory(workspaces, directories);
|
|
1659
|
+
const runDirectoryWorkspace = byRunDirectory(listWorkspaces(env), directories);
|
|
1372
1660
|
if (runDirectoryWorkspace) return {
|
|
1373
1661
|
workspace: runDirectoryWorkspace,
|
|
1374
1662
|
origin: "run-directory"
|
|
1375
1663
|
};
|
|
1376
|
-
for (const directory of directories) {
|
|
1377
|
-
const match = byRepo(workspaces, directory);
|
|
1378
|
-
if (match) return {
|
|
1379
|
-
workspace: match.workspace,
|
|
1380
|
-
origin: "repo",
|
|
1381
|
-
repo: match.repo
|
|
1382
|
-
};
|
|
1383
|
-
}
|
|
1384
1664
|
return {
|
|
1385
1665
|
workspace: null,
|
|
1386
1666
|
origin: "none"
|
|
@@ -1391,10 +1671,7 @@ function workspaceLabel(workspace) {
|
|
|
1391
1671
|
}
|
|
1392
1672
|
function requireWorkspace(workspace) {
|
|
1393
1673
|
if (workspace) return workspace;
|
|
1394
|
-
throw new CarnetError("NO_WORKSPACE", "No Rucher workspace here: pass --ws
|
|
1395
|
-
}
|
|
1396
|
-
function ambiguousWorkspaceContext(reason) {
|
|
1397
|
-
return `Rucher could not tell which workspace this session belongs to, so Carnet records nothing for it: ${reason}.`;
|
|
1674
|
+
throw new CarnetError("NO_WORKSPACE", "No Rucher workspace here: pass --ws <name>, or run this from a workspace's run directory");
|
|
1398
1675
|
}
|
|
1399
1676
|
// src/notes.ts
|
|
1400
1677
|
const NOTE_KINDS = [
|
|
@@ -1822,7 +2099,7 @@ function purgeDays(value) {
|
|
|
1822
2099
|
return Number.isFinite(days) && days > 0 ? days : 3;
|
|
1823
2100
|
}
|
|
1824
2101
|
const PURGEABLE = `
|
|
1825
|
-
workspace
|
|
2102
|
+
workspace = ? AND id != ? AND last_active_at < ?
|
|
1826
2103
|
AND NOT EXISTS (
|
|
1827
2104
|
SELECT 1 FROM events WHERE events.session = sessions.id AND events.type NOT LIKE 'session.%'
|
|
1828
2105
|
)
|
|
@@ -1853,13 +2130,42 @@ function purgeSessions(ctx, keepId, days) {
|
|
|
1853
2130
|
}
|
|
1854
2131
|
}
|
|
1855
2132
|
// src/status/render.ts
|
|
1856
|
-
const
|
|
2133
|
+
const MAIN_HEADER = "Main";
|
|
2134
|
+
const MAIN_WORKING_SUFFIX = "(main working)";
|
|
2135
|
+
const MAIN_WAITING_SUFFIX = "(waiting on you)";
|
|
2136
|
+
const MAIN_FAILED_SUFFIX = "(turn failed)";
|
|
1857
2137
|
function renderTableLine(item) {
|
|
1858
|
-
if (item.mainWorking) return `${MAIN_WORKING_EMOJI} ${item.text} ${MAIN_WORKING_SUFFIX}`;
|
|
1859
2138
|
return `${EMOJI[item.status ?? "discussing"]} ${item.text}`;
|
|
1860
2139
|
}
|
|
1861
|
-
|
|
1862
|
-
|
|
2140
|
+
const TURN_MARKS = {
|
|
2141
|
+
working: {
|
|
2142
|
+
emoji: MAIN_WORKING_EMOJI,
|
|
2143
|
+
suffix: MAIN_WORKING_SUFFIX,
|
|
2144
|
+
alone: "main working"
|
|
2145
|
+
},
|
|
2146
|
+
waiting: {
|
|
2147
|
+
emoji: "⏸",
|
|
2148
|
+
suffix: MAIN_WAITING_SUFFIX,
|
|
2149
|
+
alone: "waiting on you"
|
|
2150
|
+
},
|
|
2151
|
+
failed: {
|
|
2152
|
+
emoji: "⚠",
|
|
2153
|
+
suffix: MAIN_FAILED_SUFFIX,
|
|
2154
|
+
alone: "turn failed"
|
|
2155
|
+
}
|
|
2156
|
+
};
|
|
2157
|
+
function renderMainLine(item, turn) {
|
|
2158
|
+
if (!turn) return item ? renderTableLine(item) : null;
|
|
2159
|
+
const mark = TURN_MARKS[turn];
|
|
2160
|
+
return item ? `${mark.emoji} ${item.text} ${mark.suffix}` : `${mark.emoji} ${mark.alone}`;
|
|
2161
|
+
}
|
|
2162
|
+
function renderAgentLine(line, nameWidth = 0) {
|
|
2163
|
+
const head = `${line.emoji} ${KIND_ABBREVIATIONS[line.kind]} ${line.name}`;
|
|
2164
|
+
const action = line.action ? ` ${" ".repeat(Math.max(nameWidth - line.name.length, 0))} ${line.action}` : "";
|
|
2165
|
+
return line.note ? `${head}${action} — ${line.note}` : `${head}${action}`;
|
|
2166
|
+
}
|
|
2167
|
+
function nameWidth(lines) {
|
|
2168
|
+
return Math.max(0, ...lines.map((line) => line.name.length));
|
|
1863
2169
|
}
|
|
1864
2170
|
const NOTES_HEADER = "Notes";
|
|
1865
2171
|
const NOTES_FOLD_LINES = 5;
|
|
@@ -1870,7 +2176,7 @@ const ACTIVITY_MARK = {
|
|
|
1870
2176
|
};
|
|
1871
2177
|
const LABEL_WIDTH = 8;
|
|
1872
2178
|
const SIMILAR_PREFIX = "similar to ";
|
|
1873
|
-
function plural(count, word) {
|
|
2179
|
+
function plural$1(count, word) {
|
|
1874
2180
|
return `${count} ${word}${count > 1 ? "s" : ""}`;
|
|
1875
2181
|
}
|
|
1876
2182
|
function renderNotesSummary(notes) {
|
|
@@ -1880,7 +2186,7 @@ function renderNotesSummary(notes) {
|
|
|
1880
2186
|
count("added") && `${count("added")} added`,
|
|
1881
2187
|
count("cited") && `${count("cited")} cited`,
|
|
1882
2188
|
count("dropped") && `${count("dropped")} dropped`,
|
|
1883
|
-
duplicates && plural(duplicates, "possible duplicate")
|
|
2189
|
+
duplicates && plural$1(duplicates, "possible duplicate")
|
|
1884
2190
|
].filter(Boolean);
|
|
1885
2191
|
return `${NOTES_HEADER} ${parts.join(" · ")}`;
|
|
1886
2192
|
}
|
|
@@ -1900,15 +2206,18 @@ function renderNotes(notes, mode = "full") {
|
|
|
1900
2206
|
}
|
|
1901
2207
|
function renderSections(view, options = {}) {
|
|
1902
2208
|
const out = [];
|
|
1903
|
-
|
|
2209
|
+
const main = renderMainLine(view.table, view.turn);
|
|
2210
|
+
if (main) out.push(MAIN_HEADER, ` ${main}`, "");
|
|
1904
2211
|
out.push("Waiting on you");
|
|
1905
2212
|
if (view.waiting.length === 0) out.push(" nothing");
|
|
2213
|
+
const waitingWidth = nameWidth(view.waiting);
|
|
1906
2214
|
view.waiting.forEach((line, index) => {
|
|
1907
|
-
out.push(` ${index + 1}. ${renderAgentLine(line)}`);
|
|
2215
|
+
out.push(` ${index + 1}. ${renderAgentLine(line, waitingWidth)}`);
|
|
1908
2216
|
});
|
|
1909
2217
|
out.push("", "Running");
|
|
1910
2218
|
if (view.running.length === 0) out.push(" nothing");
|
|
1911
|
-
|
|
2219
|
+
const runningWidth = nameWidth(view.running);
|
|
2220
|
+
for (const line of view.running) out.push(` ${renderAgentLine(line, runningWidth)}`);
|
|
1912
2221
|
const notes = renderNotes(view.notes, options.notes);
|
|
1913
2222
|
if (notes.length > 0) out.push("", ...notes);
|
|
1914
2223
|
return out.join("\n");
|
|
@@ -1919,6 +2228,7 @@ function renderStatus(view, options) {
|
|
|
1919
2228
|
"",
|
|
1920
2229
|
renderSections(view, options),
|
|
1921
2230
|
"",
|
|
2231
|
+
KIND_LEGEND,
|
|
1922
2232
|
LEGEND
|
|
1923
2233
|
].join("\n");
|
|
1924
2234
|
}
|
|
@@ -1928,33 +2238,106 @@ function toItem(row) {
|
|
|
1928
2238
|
session: row.session,
|
|
1929
2239
|
text: row.text,
|
|
1930
2240
|
status: row.status,
|
|
1931
|
-
mainWorking: row.main_working === 1,
|
|
1932
2241
|
updatedAt: row.updated_at
|
|
1933
2242
|
};
|
|
1934
2243
|
}
|
|
2244
|
+
function tableIsAbout(item, name) {
|
|
2245
|
+
const text = item?.text;
|
|
2246
|
+
return text?.startsWith(name) === true && !/[\w-]/.test(text.charAt(name.length));
|
|
2247
|
+
}
|
|
1935
2248
|
function getTable(ctx, session) {
|
|
1936
2249
|
const row = ctx.db.prepare("SELECT * FROM table_items WHERE session = ?").get(session);
|
|
1937
2250
|
return row && toItem(row);
|
|
1938
2251
|
}
|
|
1939
2252
|
function setTable(ctx, session, input) {
|
|
1940
|
-
const mainWorking = input.mainWorking ?? (input.status ? false : getTable(ctx, session)?.mainWorking ?? false);
|
|
1941
|
-
if (mainWorking && input.status) throw new CarnetError("TABLE_STATUS_WITH_MAIN_WORKING", "A user-action status cannot be set while main is working");
|
|
1942
2253
|
if (input.status !== void 0 && !isUserActionStatus(input.status)) throw new CarnetError("INVALID_STATUS", `Invalid table status "${String(input.status)}"`);
|
|
1943
|
-
ctx.db.prepare(`INSERT INTO table_items (session, text, status,
|
|
2254
|
+
ctx.db.prepare(`INSERT INTO table_items (session, text, status, updated_at) VALUES (?, ?, ?, ?)
|
|
1944
2255
|
ON CONFLICT(session) DO UPDATE SET text = excluded.text, status = excluded.status,
|
|
1945
|
-
|
|
2256
|
+
updated_at = excluded.updated_at`).run(session, sanitizeNote(input.text), input.status ?? null, nowIso(ctx));
|
|
1946
2257
|
return getTable(ctx, session);
|
|
1947
2258
|
}
|
|
1948
2259
|
function clearTable(ctx, session) {
|
|
1949
2260
|
ctx.db.prepare("DELETE FROM table_items WHERE session = ?").run(session);
|
|
1950
2261
|
}
|
|
2262
|
+
// src/turn.ts
|
|
2263
|
+
const TURNS = [
|
|
2264
|
+
"working",
|
|
2265
|
+
"waiting",
|
|
2266
|
+
"failed"
|
|
2267
|
+
];
|
|
2268
|
+
function getTurn(ctx, session) {
|
|
2269
|
+
return ctx.db.prepare("SELECT turn FROM sessions WHERE id = ?").get(session)?.turn ?? null;
|
|
2270
|
+
}
|
|
2271
|
+
function setTurn(ctx, session, turn) {
|
|
2272
|
+
ctx.db.prepare(`UPDATE sessions SET turn = ?1,
|
|
2273
|
+
turn_started_at = CASE
|
|
2274
|
+
WHEN ?1 IS NULL THEN NULL
|
|
2275
|
+
WHEN ?1 <> 'failed' AND turn IN ('working', 'waiting') THEN turn_started_at
|
|
2276
|
+
ELSE ?2 END
|
|
2277
|
+
WHERE id = ?3 AND turn IS NOT ?1`).run(turn, nowIso(ctx), session);
|
|
2278
|
+
}
|
|
2279
|
+
function startTurn(ctx, session) {
|
|
2280
|
+
setTurn(ctx, session, "working");
|
|
2281
|
+
}
|
|
2282
|
+
function waitTurn(ctx, session) {
|
|
2283
|
+
setTurn(ctx, session, "waiting");
|
|
2284
|
+
}
|
|
2285
|
+
function failTurn(ctx, session) {
|
|
2286
|
+
setTurn(ctx, session, "failed");
|
|
2287
|
+
}
|
|
2288
|
+
function endTurn(ctx, session) {
|
|
2289
|
+
setTurn(ctx, session, null);
|
|
2290
|
+
}
|
|
1951
2291
|
// src/status/view.ts
|
|
1952
|
-
const
|
|
1953
|
-
|
|
1954
|
-
|
|
2292
|
+
const ACTION_RANK = {
|
|
2293
|
+
validate: 1,
|
|
2294
|
+
triage: 2,
|
|
2295
|
+
inject: 3,
|
|
2296
|
+
apply: 4,
|
|
2297
|
+
test: 5,
|
|
2298
|
+
commit: 6
|
|
1955
2299
|
};
|
|
1956
|
-
function
|
|
1957
|
-
return
|
|
2300
|
+
function plural(count, word) {
|
|
2301
|
+
return `${count} ${word}${count === 1 ? "" : "s"}`;
|
|
2302
|
+
}
|
|
2303
|
+
function actionWord(agent) {
|
|
2304
|
+
const { kind, status } = agent;
|
|
2305
|
+
if (status === "answer") return kind === "analyze" ? "validate" : "answer";
|
|
2306
|
+
if (status === "review" && kind !== "implement") return FINAL_ACTIONS[kind];
|
|
2307
|
+
if (status === "apply" && kind === "implement") return "apply";
|
|
2308
|
+
if (status === "test" || status === "commit" || status === "branch") return status;
|
|
2309
|
+
return status === "discussing" ? "discuss" : status;
|
|
2310
|
+
}
|
|
2311
|
+
function actionDetail(ctx, agent, word) {
|
|
2312
|
+
if (word === "validate" || word === "answer") {
|
|
2313
|
+
const open = listQuestions(ctx, agent.session, agent.name, true).length;
|
|
2314
|
+
if (open > 0) return plural(open, "question");
|
|
2315
|
+
if (agent.status === "answer") return "questions";
|
|
2316
|
+
return "plan";
|
|
2317
|
+
}
|
|
2318
|
+
if (word === "triage") {
|
|
2319
|
+
const pending = listFindings(ctx, agent.session, agent.name, true);
|
|
2320
|
+
const blocking = pending.filter((finding) => finding.severity === "blocking").length;
|
|
2321
|
+
const parts = [
|
|
2322
|
+
pending.length > 0 ? plural(pending.length, "finding") : null,
|
|
2323
|
+
blocking > 0 ? `(${blocking} blocking)` : null,
|
|
2324
|
+
agent.target ? `→ ${agent.target}` : null
|
|
2325
|
+
].filter(Boolean);
|
|
2326
|
+
return parts.length > 0 ? parts.join(" ") : null;
|
|
2327
|
+
}
|
|
2328
|
+
return null;
|
|
2329
|
+
}
|
|
2330
|
+
function waitingAction(ctx, agent) {
|
|
2331
|
+
const word = actionWord(agent);
|
|
2332
|
+
const detail = actionDetail(ctx, agent, word);
|
|
2333
|
+
return detail ? `${word} · ${detail}` : word;
|
|
2334
|
+
}
|
|
2335
|
+
function runningAction(agent) {
|
|
2336
|
+
return agent.promotedFrom ? `promoted from ${agent.promotedFrom}` : null;
|
|
2337
|
+
}
|
|
2338
|
+
function rankOf(agent) {
|
|
2339
|
+
if (agent.status === "answer") return 0;
|
|
2340
|
+
return ACTION_RANK[actionWord(agent)] ?? Object.keys(ACTION_RANK).length + 1;
|
|
1958
2341
|
}
|
|
1959
2342
|
function compareWaiting(left, right) {
|
|
1960
2343
|
if (left.queueOrder !== null || right.queueOrder !== null) {
|
|
@@ -1962,27 +2345,31 @@ function compareWaiting(left, right) {
|
|
|
1962
2345
|
if (right.queueOrder === null) return -1;
|
|
1963
2346
|
return left.queueOrder - right.queueOrder;
|
|
1964
2347
|
}
|
|
1965
|
-
return
|
|
2348
|
+
return rankOf(left) - rankOf(right) || left.startedAt.localeCompare(right.startedAt);
|
|
1966
2349
|
}
|
|
1967
|
-
function toLine(agent) {
|
|
2350
|
+
function toLine(agent, action) {
|
|
1968
2351
|
return {
|
|
1969
2352
|
name: agent.name,
|
|
2353
|
+
kind: agent.kind,
|
|
1970
2354
|
status: agent.status,
|
|
1971
2355
|
emoji: agent.status === "closed" ? "" : EMOJI[agent.status],
|
|
2356
|
+
action,
|
|
1972
2357
|
note: agent.note
|
|
1973
2358
|
};
|
|
1974
2359
|
}
|
|
1975
2360
|
function formatClock(date) {
|
|
1976
2361
|
return `${String(date.getHours()).padStart(2, "0")}:${String(date.getMinutes()).padStart(2, "0")}`;
|
|
1977
2362
|
}
|
|
1978
|
-
function buildStatusView(ctx, session) {
|
|
1979
|
-
const agents = listAgents(ctx, session.id);
|
|
1980
|
-
const
|
|
1981
|
-
const
|
|
2363
|
+
function buildStatusView(ctx, session, options = {}) {
|
|
2364
|
+
const agents = listAgents(ctx, session.id).filter((agent) => !options.kind || agent.kind === options.kind);
|
|
2365
|
+
const table = getTable(ctx, session.id) ?? null;
|
|
2366
|
+
const waiting = agents.filter((agent) => isUserActionStatus(agent.status) && !tableIsAbout(table, agent.name)).sort(compareWaiting).map((agent) => toLine(agent, waitingAction(ctx, agent)));
|
|
2367
|
+
const running = agents.filter((agent) => agent.status === "running").map((agent) => toLine(agent, runningAction(agent)));
|
|
1982
2368
|
return {
|
|
1983
2369
|
time: formatClock(ctx.now()),
|
|
1984
2370
|
sessionName: session.name,
|
|
1985
|
-
table
|
|
2371
|
+
table,
|
|
2372
|
+
turn: getTurn(ctx, session.id),
|
|
1986
2373
|
waiting,
|
|
1987
2374
|
running,
|
|
1988
2375
|
notes: sessionNoteActivity(ctx, session.id)
|
|
@@ -2050,6 +2437,9 @@ var Carnet = class {
|
|
|
2050
2437
|
workspace: workspace?.name ?? null
|
|
2051
2438
|
};
|
|
2052
2439
|
}
|
|
2440
|
+
now() {
|
|
2441
|
+
return this.ctx.now();
|
|
2442
|
+
}
|
|
2053
2443
|
requireWorkspace() {
|
|
2054
2444
|
return requireWorkspace(this.workspace);
|
|
2055
2445
|
}
|
|
@@ -2087,22 +2477,43 @@ var Carnet = class {
|
|
|
2087
2477
|
update: (session, name, input) => updateAgent(this.ctx, session, name, input),
|
|
2088
2478
|
finish: (session, name, input) => finishAgent(this.ctx, session, name, input),
|
|
2089
2479
|
drop: (session, name, reason) => dropAgent(this.ctx, session, name, reason),
|
|
2480
|
+
close: (session, name, event) => closeAgent(this.ctx, session, name, event),
|
|
2481
|
+
promote: (session, name, input) => promoteAgent(this.ctx, session, name, input),
|
|
2090
2482
|
list: (session, options) => listAgents(this.ctx, session, options),
|
|
2091
2483
|
reorderQueue: (session, names) => reorderQueue(this.ctx, session, names),
|
|
2484
|
+
byHostAgentId: (session, hostAgentId) => byHostAgentId(this.ctx, session, hostAgentId),
|
|
2092
2485
|
pairSubagent: (session, hostAgentId) => pairSubagent(this.ctx, session, hostAgentId),
|
|
2093
2486
|
stopSubagent: (session, hostAgentId, names) => stopSubagent(this.ctx, session, hostAgentId, names)
|
|
2094
2487
|
};
|
|
2488
|
+
questions = {
|
|
2489
|
+
list: (session, agent, openOnly) => listQuestions(this.ctx, session, agent, openOnly),
|
|
2490
|
+
add: (session, agent, inputs) => addQuestions(this.ctx, session, agent, inputs),
|
|
2491
|
+
answer: (session, agent, answers) => answerQuestions(this.ctx, session, agent, answers)
|
|
2492
|
+
};
|
|
2493
|
+
findings = {
|
|
2494
|
+
list: (session, agent, pendingOnly) => listFindings(this.ctx, session, agent, pendingOnly),
|
|
2495
|
+
replace: (session, agent, inputs) => replaceFindings(this.ctx, session, agent, inputs),
|
|
2496
|
+
decide: (session, agent, decisions) => decideFindings(this.ctx, session, agent, decisions)
|
|
2497
|
+
};
|
|
2095
2498
|
table = {
|
|
2096
2499
|
get: (session) => getTable(this.ctx, session),
|
|
2097
2500
|
set: (session, input) => setTable(this.ctx, session, input),
|
|
2098
2501
|
clear: (session) => clearTable(this.ctx, session)
|
|
2099
2502
|
};
|
|
2503
|
+
turn = {
|
|
2504
|
+
get: (session) => getTurn(this.ctx, session),
|
|
2505
|
+
start: (session) => startTurn(this.ctx, session),
|
|
2506
|
+
wait: (session) => waitTurn(this.ctx, session),
|
|
2507
|
+
fail: (session) => failTurn(this.ctx, session),
|
|
2508
|
+
end: (session) => endTurn(this.ctx, session)
|
|
2509
|
+
};
|
|
2100
2510
|
events = {
|
|
2101
2511
|
log: (session, input) => logEvent(this.ctx, session, input),
|
|
2102
|
-
read: (session, limit, agentOnly) => readEvents(this.ctx, {
|
|
2512
|
+
read: (session, limit, agentOnly, kind) => readEvents(this.ctx, {
|
|
2103
2513
|
session,
|
|
2104
2514
|
limit,
|
|
2105
|
-
agentOnly
|
|
2515
|
+
agentOnly,
|
|
2516
|
+
kind
|
|
2106
2517
|
})
|
|
2107
2518
|
};
|
|
2108
2519
|
notes = {
|
|
@@ -2123,8 +2534,8 @@ var Carnet = class {
|
|
|
2123
2534
|
copyRepos: (from, into) => copyInjectedRepos(this.ctx, from, into)
|
|
2124
2535
|
};
|
|
2125
2536
|
status = {
|
|
2126
|
-
view: (session) => buildStatusView(this.ctx, session),
|
|
2127
|
-
render: (session, options) => renderStatus(buildStatusView(this.ctx, session), options),
|
|
2537
|
+
view: (session, options) => buildStatusView(this.ctx, session, options),
|
|
2538
|
+
render: (session, options) => renderStatus(buildStatusView(this.ctx, session, options), options),
|
|
2128
2539
|
sections: (session) => renderSections(buildStatusView(this.ctx, session))
|
|
2129
2540
|
};
|
|
2130
2541
|
close() {
|
|
@@ -2195,27 +2606,27 @@ const AGENT_STEPS = [
|
|
|
2195
2606
|
"dropped"
|
|
2196
2607
|
];
|
|
2197
2608
|
const DEFAULT_NEXT = {
|
|
2198
|
-
answered: "apply",
|
|
2199
2609
|
applied: "test",
|
|
2200
2610
|
tested: "commit"
|
|
2201
2611
|
};
|
|
2202
|
-
function tableIsAbout(carnet, session, name) {
|
|
2203
|
-
const text = carnet.table.get(session)?.text;
|
|
2204
|
-
return text?.startsWith(name) === true && !/[\w-]/.test(text.charAt(name.length));
|
|
2205
|
-
}
|
|
2206
2612
|
function clearTableOf(carnet, session, name) {
|
|
2207
|
-
if (tableIsAbout(carnet
|
|
2613
|
+
if (tableIsAbout(carnet.table.get(session), name)) carnet.table.clear(session);
|
|
2208
2614
|
}
|
|
2209
2615
|
function stepAgent(carnet, session, input) {
|
|
2210
2616
|
const { name, step, commit, note } = input;
|
|
2211
|
-
|
|
2617
|
+
const agent = carnet.agents.get(session, name);
|
|
2618
|
+
if (!agent) throw new CarnetError("AGENT_NOT_FOUND", `No agent "${name}" in this session`);
|
|
2212
2619
|
switch (step) {
|
|
2213
|
-
case "applying":
|
|
2214
|
-
|
|
2215
|
-
|
|
2216
|
-
|
|
2620
|
+
case "applying": {
|
|
2621
|
+
if (agent.kind !== "implement") throw new CarnetError("INVALID_KIND", `${name} is ${agent.kind}: only an implement agent is applied`);
|
|
2622
|
+
carnet.table.set(session, { text: `${name} applying` });
|
|
2623
|
+
carnet.agents.update(session, name, {
|
|
2624
|
+
status: agent.status,
|
|
2625
|
+
note: note ?? null
|
|
2217
2626
|
});
|
|
2218
|
-
|
|
2627
|
+
const reviews = carnet.agents.list(session).filter((other) => other.kind === "review" && other.target === name);
|
|
2628
|
+
return `⚙️ ${name} applying${reviews.length ? `\nwarning: review ${reviews.map((review) => review.name).join(", ")} not triaged yet` : ""}`;
|
|
2629
|
+
}
|
|
2219
2630
|
case "committed":
|
|
2220
2631
|
if (!commit) throw new CarnetError("COMMIT_REQUIRED", "The committed step needs the commit");
|
|
2221
2632
|
carnet.events.log(session, {
|
|
@@ -2232,13 +2643,16 @@ function stepAgent(carnet, session, input) {
|
|
|
2232
2643
|
clearTableOf(carnet, session, name);
|
|
2233
2644
|
return `${name} dropped, closed`;
|
|
2234
2645
|
default: {
|
|
2235
|
-
const next = input.next ?? DEFAULT_NEXT[step];
|
|
2646
|
+
const next = input.next ?? (step === "answered" ? statusAfterAnswers(agent.kind) : DEFAULT_NEXT[step]);
|
|
2236
2647
|
carnet.events.log(session, {
|
|
2237
2648
|
type: step,
|
|
2238
2649
|
agent: name,
|
|
2239
2650
|
note
|
|
2240
2651
|
});
|
|
2241
|
-
carnet.agents.update(session, name, {
|
|
2652
|
+
carnet.agents.update(session, name, {
|
|
2653
|
+
status: next,
|
|
2654
|
+
note: note ?? null
|
|
2655
|
+
});
|
|
2242
2656
|
if (next === "running") clearTableOf(carnet, session, name);
|
|
2243
2657
|
else if (step !== "answered") carnet.table.set(session, {
|
|
2244
2658
|
text: `${name} ${step}, ${next} next`,
|
|
@@ -2248,6 +2662,6 @@ function stepAgent(carnet, session, input) {
|
|
|
2248
2662
|
}
|
|
2249
2663
|
}
|
|
2250
2664
|
}
|
|
2251
|
-
export {
|
|
2665
|
+
export { workspaceLabel as $, defaultRunDirectory as $t, renderStatus as A, OPEN_AGENT_STATUSES as An, MINIMUM_ID_PREFIX as At, NOTE_TEXT_LIMIT as B, isWorkspaceName as Bt, SIMILAR_PREFIX as C, EMOJI as Cn, baseRules as Ct, renderNotes as D, MAIN_FAILED_EMOJI as Dn, rulesVersion as Dt, renderNoteLine as E, LEGEND as En, rulesText as Et, memoryMaxCharacters as F, SESSION_EVENT_TYPES as Fn, addWorkspaceRepo as Ft, sessionNoteActivity as G, workspaceHosts as Gt, isNoteKind as H, loadWorkspace as Ht, renderMemory as I, isEventType as In, createWorkspace as It, isInside as J, FINDING_SEVERITIES as Jt, similarity as K, renderQuestions as Kt, DEFAULT_HALF_LIFE_DAYS as L, CarnetError as Ln, definitionInstructions as Lt, DEFAULT_PURGE_DAYS as M, isAgentStatus as Mn, AGENTS_FILE as Mt, purgeDays as N, isUserActionStatus as Nn, INSTRUCTIONS_FILE as Nt, renderNotesSummary as O, MAIN_WAITING_EMOJI as On, workspaceRules as Ot, MEMORY_MAX_CHARACTERS as P, EVENT_TYPES as Pn, WORKSPACE_FILE as Pt, resolveWorkspace as Q, databasePath as Qt, DUPLICATE_SIMILARITY as R, dropWorkspace as Rt, NOTES_HEADER as S, AGENT_STATUSES as Sn, assemblePrompt as St, renderMainLine as T, KIND_LEGEND as Tn, outsideRucherContext as Tt, localDay as U, removeWorkspaceRepo as Ut, STALE_AFTER_ACTIVE_DAYS as V, listWorkspaces as Vt, memoryHalfLife as W, workspaceExists as Wt, repoPathFor as X, renderFindings as Xt, repoNameFor as Y, formatFinding as Yt, requireWorkspace as Z, corePromptPath as Zt, MAIN_FAILED_SUFFIX as _, mainTargetRange as _n, OUTSIDE_RUCHER_NOTICE as _t, formatEventLine as a, workspacesDirectory as an, DEFAULT_HOST as at, MAIN_WORKING_SUFFIX as b, NOTE_MAX as bn, SUBAGENT_RULES as bt, Carnet as c, migrate as cn, claudeCode as ct, openWorkspaceCarnet as d, AGENT_KINDS as dn, GENERATED_MARKER as dt, promptsDirectory as en, archiveWorkspaceSessions as et, PAIRING_WINDOW_MILLISECONDS as f, DEFAULT_AGENT_KIND as fn, MARKDOWN_MARKER as ft, TURNS as g, isAgentKind as gn, writeGenerated as gt, formatClock as h, REPORTING_NOTE as hn, removeStaleCopies as ht, RESUME_MAX_CHARACTERS as i, workspaceDefinition as in, workspaceSessionCounts as it, renderTableLine as j, USER_ACTION_STATUSES as jn, shortId as jt, renderSections as k, MAIN_WORKING_EMOJI as kn, CORE_RULES as kt, openCarnet as l, migrations as ln, transcriptTitle as lt, buildStatusView as m, PUBLISH_FALLBACK_MILLISECONDS as mn, mergeSettings as mt, stepAgent as n, reportsDirectory as nn, sessionWorkspaceName as nt, resumeContext as o, MEMORY_DB as on, allHosts as ot, STOPPED_NOTE as p, FINAL_ACTIONS as pn, markdownCopy as pt, workspaceRepoNames as q, FINDING_DECISIONS as qt, RESUME_EVENTS as r, rucherPaths as rn, workspaceLastActive as rt, sessionLabel as s, openDatabase as sn, hostById as st, AGENT_STEPS as t, reportPath as tn, deleteWorkspaceNotes as tt, openResolvedCarnet as u, schemaVersion as un, workspaceSettings as ut, MAIN_HEADER as v, statusAfterAnswers as vn, PROMPT_FILE as vt, renderAgentLine as w, KIND_ABBREVIATIONS as wn, compactReminder as wt, NOTES_FOLD_LINES as x, sanitizeNote as xn, appendPromptFile as xt, MAIN_WAITING_SUFFIX as y, statusWhenDone as yn, RULES_UPDATED_NOTICE as yt, NOTE_KINDS as z, expandHome as zt };
|
|
2252
2666
|
|
|
2253
|
-
//# sourceMappingURL=steps-
|
|
2667
|
+
//# sourceMappingURL=steps-Bd8FlgLs.mjs.map
|