@rucher/carnet 0.2.0-beta.7 → 0.2.0-beta.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +2 -2
- package/dist/{carnet-jmxAmm-u.d.mts → carnet-DcHESFRd.d.mts} +46 -16
- package/dist/carnet-DcHESFRd.d.mts.map +1 -0
- package/dist/index.d.mts +27 -6
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs +152 -18
- package/dist/index.mjs.map +1 -1
- package/dist/mcp.d.mts +4 -2
- package/dist/mcp.d.mts.map +1 -1
- package/dist/mcp.mjs +132 -45
- package/dist/mcp.mjs.map +1 -1
- package/dist/{steps-Bd8FlgLs.mjs → steps-wNm8GU_c.mjs} +388 -87
- package/dist/steps-wNm8GU_c.mjs.map +1 -0
- package/package.json +1 -1
- package/dist/carnet-jmxAmm-u.d.mts.map +0 -1
- package/dist/steps-Bd8FlgLs.mjs.map +0 -1
|
@@ -69,8 +69,6 @@ const AGENT_STATUSES = [
|
|
|
69
69
|
"review",
|
|
70
70
|
"apply",
|
|
71
71
|
"test",
|
|
72
|
-
"commit",
|
|
73
|
-
"branch",
|
|
74
72
|
"closed"
|
|
75
73
|
];
|
|
76
74
|
const USER_ACTION_STATUSES = [
|
|
@@ -78,9 +76,7 @@ const USER_ACTION_STATUSES = [
|
|
|
78
76
|
"answer",
|
|
79
77
|
"review",
|
|
80
78
|
"apply",
|
|
81
|
-
"test"
|
|
82
|
-
"commit",
|
|
83
|
-
"branch"
|
|
79
|
+
"test"
|
|
84
80
|
];
|
|
85
81
|
const EMOJI = {
|
|
86
82
|
running: "⏳",
|
|
@@ -88,21 +84,23 @@ const EMOJI = {
|
|
|
88
84
|
answer: "❓",
|
|
89
85
|
review: "👀",
|
|
90
86
|
apply: "📥",
|
|
91
|
-
test: "🧪"
|
|
92
|
-
commit: "✅",
|
|
93
|
-
branch: "🌿"
|
|
87
|
+
test: "🧪"
|
|
94
88
|
};
|
|
95
89
|
const MAIN_WORKING_EMOJI = "⚙️";
|
|
96
90
|
const MAIN_WAITING_EMOJI = "⏸";
|
|
97
91
|
const MAIN_FAILED_EMOJI = "⚠";
|
|
98
|
-
const LEGEND = "⚙️ main working · ⏸ waiting on you · ⚠ turn failed · 💬 discussing · ❓ answer · 👀 review · 📥 apply · 🧪 test ·
|
|
92
|
+
const LEGEND = "⚙️ main working · ⏸ waiting on you · ⚠ turn failed · 💬 discussing · ❓ answer · 👀 review · 📥 apply · 🧪 test · ⏳ running";
|
|
99
93
|
const KIND_ABBREVIATIONS = {
|
|
100
94
|
research: "rs",
|
|
101
|
-
|
|
95
|
+
plan: "pl",
|
|
102
96
|
implement: "im",
|
|
103
97
|
review: "rv"
|
|
104
98
|
};
|
|
105
|
-
|
|
99
|
+
function kindTag(kind) {
|
|
100
|
+
return `[${KIND_ABBREVIATIONS[kind]}]`;
|
|
101
|
+
}
|
|
102
|
+
const KIND_TAG_PATTERN = /\[(?:rs|pl|im|rv)\]/;
|
|
103
|
+
const KIND_LEGEND = "[rs] research · [pl] plan · [im] implement · [rv] review";
|
|
106
104
|
function isAgentStatus(value) {
|
|
107
105
|
return typeof value === "string" && AGENT_STATUSES.includes(value);
|
|
108
106
|
}
|
|
@@ -127,14 +125,14 @@ function sanitizeNote(text) {
|
|
|
127
125
|
// src/agents.ts
|
|
128
126
|
const AGENT_KINDS = [
|
|
129
127
|
"research",
|
|
130
|
-
"
|
|
128
|
+
"plan",
|
|
131
129
|
"implement",
|
|
132
130
|
"review"
|
|
133
131
|
];
|
|
134
|
-
const
|
|
135
|
-
const
|
|
132
|
+
const KIND_REQUIRED = "kind is required: research, plan, implement or review";
|
|
133
|
+
const KIND_ACTIONS = {
|
|
136
134
|
research: "inject",
|
|
137
|
-
|
|
135
|
+
plan: "validate",
|
|
138
136
|
implement: "apply",
|
|
139
137
|
review: "triage"
|
|
140
138
|
};
|
|
@@ -146,6 +144,7 @@ function mainTargetRange(target) {
|
|
|
146
144
|
const match = MAIN_TARGET.exec(target);
|
|
147
145
|
return match ? match[1]?.trim() ?? null : void 0;
|
|
148
146
|
}
|
|
147
|
+
const SANDBOX_KINDS = ["research", "plan"];
|
|
149
148
|
function toAgent(row) {
|
|
150
149
|
return {
|
|
151
150
|
session: row.session,
|
|
@@ -153,26 +152,41 @@ function toAgent(row) {
|
|
|
153
152
|
kind: row.kind,
|
|
154
153
|
promotedFrom: row.promoted_from,
|
|
155
154
|
target: row.target,
|
|
155
|
+
blockedOn: row.blocked_on,
|
|
156
156
|
task: row.task,
|
|
157
157
|
status: row.status,
|
|
158
158
|
note: row.note,
|
|
159
159
|
reportPath: row.report_path,
|
|
160
160
|
baseCommit: row.base_commit,
|
|
161
161
|
worktree: row.worktree,
|
|
162
|
+
sandbox: row.sandbox,
|
|
162
163
|
queueOrder: row.queue_order,
|
|
163
164
|
hostAgentId: row.host_agent_id,
|
|
164
165
|
pendingStatus: row.pending_status,
|
|
165
166
|
doneAt: row.done_at,
|
|
166
167
|
startedAt: row.started_at,
|
|
167
|
-
updatedAt: row.updated_at
|
|
168
|
+
updatedAt: row.updated_at,
|
|
169
|
+
statusSince: row.status_since ?? row.updated_at
|
|
168
170
|
};
|
|
169
171
|
}
|
|
170
172
|
const REPORTING_NOTE = "reporting";
|
|
171
173
|
const PUBLISH_FALLBACK_MILLISECONDS = 12e4;
|
|
174
|
+
function statusChangeSql(next) {
|
|
175
|
+
return `status_since = CASE WHEN status = ${next} THEN status_since ELSE ? END,
|
|
176
|
+
queue_order = CASE WHEN status = ${next} THEN queue_order ELSE NULL END`;
|
|
177
|
+
}
|
|
178
|
+
function statusChangeArgs(next, at) {
|
|
179
|
+
return [
|
|
180
|
+
next,
|
|
181
|
+
at,
|
|
182
|
+
next
|
|
183
|
+
];
|
|
184
|
+
}
|
|
172
185
|
function publishPending(ctx, session, name) {
|
|
173
186
|
const row = ctx.db.prepare("SELECT pending_status, report_path FROM agents WHERE session = ? AND name = ?").get(session, name);
|
|
174
187
|
if (!row?.pending_status) return;
|
|
175
|
-
ctx.db.prepare(
|
|
188
|
+
ctx.db.prepare(`UPDATE agents SET status = pending_status, pending_status = NULL, note = NULL,
|
|
189
|
+
${statusChangeSql("pending_status")}, updated_at = ? WHERE session = ? AND name = ?`).run(nowIso(ctx), nowIso(ctx), session, name);
|
|
176
190
|
logEvent(ctx, session, {
|
|
177
191
|
type: "finished",
|
|
178
192
|
agent: name,
|
|
@@ -203,18 +217,21 @@ function checkReviewTarget(ctx, session, target) {
|
|
|
203
217
|
}
|
|
204
218
|
function startAgent(ctx, session, input) {
|
|
205
219
|
const name = sanitizeNote(input.name);
|
|
206
|
-
const kind = input.kind
|
|
220
|
+
const kind = input.kind;
|
|
221
|
+
if (!isAgentKind(kind)) throw new CarnetError("INVALID_KIND", KIND_REQUIRED);
|
|
222
|
+
if (input.worktree && kind !== "implement") throw new CarnetError("INVALID_KIND", `A worktree means an implement agent: start ${name} with kind implement, or promote a research or plan agent with agent_promote`);
|
|
207
223
|
const target = input.target?.trim() || null;
|
|
208
224
|
if (kind === "review" && !target) throw new CarnetError("INVALID_TARGET", "A review needs a target: an implement agent name, or main[:<range>]");
|
|
209
225
|
if (kind !== "review" && target) throw new CarnetError("INVALID_TARGET", "Only a review agent takes a target");
|
|
210
226
|
if (target) checkReviewTarget(ctx, session, target);
|
|
227
|
+
if (input.sandbox) checkSandbox(ctx, session, name, kind, input.sandbox);
|
|
211
228
|
const existing = getAgent(ctx, session, name);
|
|
212
229
|
if (existing && existing.status !== "closed") throw new CarnetError("AGENT_EXISTS", `Agent "${name}" is already open in this session`);
|
|
213
230
|
if (existing) ctx.db.prepare("DELETE FROM agents WHERE session = ? AND name = ?").run(session, name);
|
|
214
231
|
const at = nowIso(ctx);
|
|
215
232
|
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);
|
|
233
|
+
sandbox, started_at, updated_at, status_since)
|
|
234
|
+
VALUES (?, ?, ?, ?, ?, 'running', ?, ?, ?, ?, ?, ?)`).run(session, name, kind, target, input.task, input.baseCommit ?? null, input.worktree ?? null, input.sandbox ?? null, at, at, at);
|
|
218
235
|
logEvent(ctx, session, {
|
|
219
236
|
type: "started",
|
|
220
237
|
agent: name,
|
|
@@ -222,14 +239,46 @@ function startAgent(ctx, session, input) {
|
|
|
222
239
|
});
|
|
223
240
|
return requireAgent(ctx, session, name);
|
|
224
241
|
}
|
|
242
|
+
function checkSandbox(ctx, session, name, kind, sandbox) {
|
|
243
|
+
if (!SANDBOX_KINDS.includes(kind)) throw new CarnetError("INVALID_KIND", `Only a research or plan agent gets a sandbox; ${name} is ${kind}`);
|
|
244
|
+
const holder = ctx.db.prepare(`SELECT agents.name FROM agents JOIN sessions ON sessions.id = agents.session
|
|
245
|
+
WHERE agents.sandbox = ? AND sessions.workspace = (SELECT workspace FROM sessions WHERE id = ?)
|
|
246
|
+
AND NOT (agents.session = ? AND agents.name = ?)`).get(sandbox, session, session, name);
|
|
247
|
+
if (holder) throw new CarnetError("INVALID_SANDBOX", `${sandbox} is already the sandbox of ${holder.name}`);
|
|
248
|
+
}
|
|
249
|
+
function clearSandbox(ctx, session, name) {
|
|
250
|
+
ctx.db.prepare("UPDATE agents SET sandbox = NULL WHERE session = ? AND name = ?").run(session, name);
|
|
251
|
+
}
|
|
252
|
+
function closedSandboxes(ctx, session) {
|
|
253
|
+
const where = session ? "agents.session = ?" : "agents.session IN (SELECT id FROM sessions WHERE workspace = ?)";
|
|
254
|
+
return ctx.db.prepare(`SELECT session, name, sandbox FROM agents
|
|
255
|
+
WHERE ${where} AND status = 'closed' AND sandbox IS NOT NULL`).all(session ?? ctx.workspace);
|
|
256
|
+
}
|
|
257
|
+
function checkBlocker(ctx, session, name, blocker) {
|
|
258
|
+
if (blocker === name) throw new CarnetError("INVALID_BLOCKER", `Agent "${name}" can't wait on itself`);
|
|
259
|
+
const seen = /* @__PURE__ */ new Set([name]);
|
|
260
|
+
let current = getAgent(ctx, session, blocker);
|
|
261
|
+
if (!current || current.status === "closed") throw new CarnetError("INVALID_BLOCKER", `"${blocker}" is not an open agent of this session`);
|
|
262
|
+
while (current?.blockedOn && current.status !== "closed") {
|
|
263
|
+
if (seen.has(current.blockedOn)) throw new CarnetError("INVALID_BLOCKER", `"${blocker}" already waits on "${name}", directly or through another agent`);
|
|
264
|
+
seen.add(current.name);
|
|
265
|
+
current = getAgent(ctx, session, current.blockedOn);
|
|
266
|
+
}
|
|
267
|
+
}
|
|
225
268
|
function updateAgent(ctx, session, name, input) {
|
|
226
269
|
const current = requireAgent(ctx, session, name);
|
|
227
270
|
if (!isAgentStatus(input.status) || input.status === "closed") throw new CarnetError("INVALID_STATUS", `Invalid agent status "${input.status}"; use agent_drop to close`);
|
|
228
271
|
let note;
|
|
229
272
|
if (input.note !== void 0) note = input.note === null ? null : sanitizeNote(input.note);
|
|
230
273
|
else note = current.status === "running" && input.status !== "running" ? null : current.note;
|
|
274
|
+
let blockedOn = current.blockedOn;
|
|
275
|
+
if (input.blockedOn !== void 0) {
|
|
276
|
+
blockedOn = input.blockedOn === null ? null : sanitizeNote(input.blockedOn);
|
|
277
|
+
if (blockedOn) checkBlocker(ctx, session, name, blockedOn);
|
|
278
|
+
}
|
|
231
279
|
if (current.pendingStatus) publishPending(ctx, session, name);
|
|
232
|
-
ctx.db.prepare(
|
|
280
|
+
ctx.db.prepare(`UPDATE agents SET note = ?, ${statusChangeSql("?")}, status = ?,
|
|
281
|
+
report_path = COALESCE(?, report_path), blocked_on = ?, updated_at = ? WHERE session = ? AND name = ?`).run(note, ...statusChangeArgs(input.status, nowIso(ctx)), input.status, input.reportPath ?? null, blockedOn, nowIso(ctx), session, name);
|
|
233
282
|
return requireAgent(ctx, session, name);
|
|
234
283
|
}
|
|
235
284
|
function statusWhenDone(kind, hasQuestions) {
|
|
@@ -249,7 +298,7 @@ function statusAfterAnswers(kind) {
|
|
|
249
298
|
}
|
|
250
299
|
function closeAgent(ctx, session, name, event) {
|
|
251
300
|
requireAgent(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);
|
|
301
|
+
ctx.db.prepare("UPDATE agents SET status = 'closed', pending_status = NULL, queue_order = NULL, blocked_on = NULL, status_since = ?, updated_at = ? WHERE session = ? AND name = ?").run(nowIso(ctx), nowIso(ctx), session, name);
|
|
253
302
|
logEvent(ctx, session, {
|
|
254
303
|
...event,
|
|
255
304
|
agent: name
|
|
@@ -262,17 +311,26 @@ function dropAgent(ctx, session, name, reason) {
|
|
|
262
311
|
note: reason
|
|
263
312
|
});
|
|
264
313
|
}
|
|
314
|
+
const PROMOTIONS = {
|
|
315
|
+
research: ["plan", "implement"],
|
|
316
|
+
plan: ["implement"]
|
|
317
|
+
};
|
|
318
|
+
const PROMOTE_KIND_REQUIRED = "kind is required: plan or implement for a research agent, implement for a plan one";
|
|
265
319
|
function promoteAgent(ctx, session, name, input) {
|
|
266
320
|
const agent = requireAgent(ctx, session, name);
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
321
|
+
const target = input.kind;
|
|
322
|
+
if (!isAgentKind(target)) throw new CarnetError("INVALID_KIND", PROMOTE_KIND_REQUIRED);
|
|
323
|
+
const allowed = PROMOTIONS[agent.kind] ?? [];
|
|
324
|
+
if (!allowed.includes(target)) throw new CarnetError("INVALID_KIND", allowed.length === 0 ? `A ${agent.kind} agent is never promoted; only research and plan are` : `${name} is ${agent.kind}: it is promoted to ${allowed.join(" or ")}, not ${target}`);
|
|
325
|
+
if (input.worktree && target !== "implement") throw new CarnetError("INVALID_KIND", `A worktree means an implement agent: promote ${name} with kind implement`);
|
|
326
|
+
ctx.db.prepare(`UPDATE agents SET kind = ?, promoted_from = ?, status = 'running',
|
|
327
|
+
pending_status = NULL, note = NULL, blocked_on = NULL, worktree = COALESCE(?, worktree),
|
|
328
|
+
base_commit = COALESCE(?, base_commit), queue_order = NULL, status_since = ?, updated_at = ?
|
|
329
|
+
WHERE session = ? AND name = ?`).run(target, agent.kind, input.worktree ?? null, input.baseCommit ?? null, nowIso(ctx), nowIso(ctx), session, name);
|
|
272
330
|
logEvent(ctx, session, {
|
|
273
331
|
type: "promoted",
|
|
274
332
|
agent: name,
|
|
275
|
-
note:
|
|
333
|
+
note: `${agent.kind} to ${target}`
|
|
276
334
|
});
|
|
277
335
|
return requireAgent(ctx, session, name);
|
|
278
336
|
}
|
|
@@ -632,6 +690,94 @@ INSERT INTO events_new SELECT id, session, at, type, agent, commit_sha, link, no
|
|
|
632
690
|
DROP TABLE events;
|
|
633
691
|
ALTER TABLE events_new RENAME TO events;
|
|
634
692
|
CREATE INDEX events_session_at ON events(session, at);
|
|
693
|
+
`,
|
|
694
|
+
`
|
|
695
|
+
-- Testing and committing are one human step, and no step ever led to branch.
|
|
696
|
+
UPDATE agents SET status = 'test' WHERE status IN ('commit', 'branch');
|
|
697
|
+
UPDATE agents SET pending_status = 'test' WHERE pending_status IN ('commit', 'branch');
|
|
698
|
+
UPDATE table_items SET status = 'test' WHERE status IN ('commit', 'branch');
|
|
699
|
+
CREATE TABLE agents_new (
|
|
700
|
+
session TEXT NOT NULL REFERENCES sessions(id),
|
|
701
|
+
name TEXT NOT NULL,
|
|
702
|
+
task TEXT,
|
|
703
|
+
status TEXT NOT NULL
|
|
704
|
+
CHECK (status IN ('running', 'discussing', 'answer', 'review', 'apply', 'test', 'closed')),
|
|
705
|
+
note TEXT,
|
|
706
|
+
report_path TEXT,
|
|
707
|
+
base_commit TEXT,
|
|
708
|
+
worktree TEXT,
|
|
709
|
+
queue_order INTEGER,
|
|
710
|
+
started_at TEXT NOT NULL,
|
|
711
|
+
updated_at TEXT NOT NULL,
|
|
712
|
+
host_agent_id TEXT,
|
|
713
|
+
pending_status TEXT,
|
|
714
|
+
done_at TEXT,
|
|
715
|
+
kind TEXT NOT NULL DEFAULT 'analyze'
|
|
716
|
+
CHECK (kind IN ('research', 'analyze', 'implement', 'review')),
|
|
717
|
+
promoted_from TEXT CHECK (promoted_from IN ('research', 'analyze', 'implement', 'review')),
|
|
718
|
+
target TEXT,
|
|
719
|
+
blocked_on TEXT,
|
|
720
|
+
PRIMARY KEY (session, name)
|
|
721
|
+
);
|
|
722
|
+
INSERT INTO agents_new (session, name, task, status, note, report_path, base_commit, worktree,
|
|
723
|
+
queue_order, started_at, updated_at, host_agent_id, pending_status, done_at, kind, promoted_from, target)
|
|
724
|
+
SELECT session, name, task, status, note, report_path, base_commit, worktree,
|
|
725
|
+
queue_order, started_at, updated_at, host_agent_id, pending_status, done_at, kind, promoted_from, target
|
|
726
|
+
FROM agents;
|
|
727
|
+
DROP TABLE agents;
|
|
728
|
+
ALTER TABLE agents_new RENAME TO agents;
|
|
729
|
+
CREATE INDEX agents_session_status ON agents(session, status);
|
|
730
|
+
-- The CLI and the plugin update separately; the pane warns when the hooks lag behind.
|
|
731
|
+
ALTER TABLE sessions ADD COLUMN plugin_version TEXT;
|
|
732
|
+
`,
|
|
733
|
+
`
|
|
734
|
+
-- A research or analyze agent's throwaway folder under the run directory, writable through the guard.
|
|
735
|
+
ALTER TABLE agents ADD COLUMN sandbox TEXT;
|
|
736
|
+
`,
|
|
737
|
+
`
|
|
738
|
+
-- The analyze kind is now plan. launch_requested_at marks the Agent call that launches an agent,
|
|
739
|
+
-- so the next subagent pairs with it rather than with an older registered one.
|
|
740
|
+
CREATE TABLE agents_new (
|
|
741
|
+
session TEXT NOT NULL REFERENCES sessions(id),
|
|
742
|
+
name TEXT NOT NULL,
|
|
743
|
+
task TEXT,
|
|
744
|
+
status TEXT NOT NULL
|
|
745
|
+
CHECK (status IN ('running', 'discussing', 'answer', 'review', 'apply', 'test', 'closed')),
|
|
746
|
+
note TEXT,
|
|
747
|
+
report_path TEXT,
|
|
748
|
+
base_commit TEXT,
|
|
749
|
+
worktree TEXT,
|
|
750
|
+
queue_order INTEGER,
|
|
751
|
+
started_at TEXT NOT NULL,
|
|
752
|
+
updated_at TEXT NOT NULL,
|
|
753
|
+
host_agent_id TEXT,
|
|
754
|
+
pending_status TEXT,
|
|
755
|
+
done_at TEXT,
|
|
756
|
+
kind TEXT NOT NULL CHECK (kind IN ('research', 'plan', 'implement', 'review')),
|
|
757
|
+
promoted_from TEXT CHECK (promoted_from IN ('research', 'plan', 'implement', 'review')),
|
|
758
|
+
target TEXT,
|
|
759
|
+
blocked_on TEXT,
|
|
760
|
+
sandbox TEXT,
|
|
761
|
+
launch_requested_at TEXT,
|
|
762
|
+
PRIMARY KEY (session, name)
|
|
763
|
+
);
|
|
764
|
+
INSERT INTO agents_new (session, name, task, status, note, report_path, base_commit, worktree,
|
|
765
|
+
queue_order, started_at, updated_at, host_agent_id, pending_status, done_at, kind, promoted_from,
|
|
766
|
+
target, blocked_on, sandbox)
|
|
767
|
+
SELECT session, name, task, status, note, report_path, base_commit, worktree,
|
|
768
|
+
queue_order, started_at, updated_at, host_agent_id, pending_status, done_at,
|
|
769
|
+
CASE kind WHEN 'analyze' THEN 'plan' ELSE kind END,
|
|
770
|
+
CASE promoted_from WHEN 'analyze' THEN 'plan' ELSE promoted_from END,
|
|
771
|
+
target, blocked_on, sandbox
|
|
772
|
+
FROM agents;
|
|
773
|
+
DROP TABLE agents;
|
|
774
|
+
ALTER TABLE agents_new RENAME TO agents;
|
|
775
|
+
CREATE INDEX agents_session_status ON agents(session, status);
|
|
776
|
+
`,
|
|
777
|
+
`
|
|
778
|
+
-- When the status last changed; rows from before it start from their last update.
|
|
779
|
+
ALTER TABLE agents ADD COLUMN status_since TEXT;
|
|
780
|
+
UPDATE agents SET status_since = updated_at;
|
|
635
781
|
`
|
|
636
782
|
];
|
|
637
783
|
const preconditions = { 11: (db) => {
|
|
@@ -724,6 +870,9 @@ function corePromptPath(env) {
|
|
|
724
870
|
function reportsDirectory(workspace) {
|
|
725
871
|
return join(workspace.runDirectory, "reports");
|
|
726
872
|
}
|
|
873
|
+
function sandboxesDirectory(workspace) {
|
|
874
|
+
return join(workspace.runDirectory, "sandboxes");
|
|
875
|
+
}
|
|
727
876
|
function reportPath(workspace, agentName) {
|
|
728
877
|
return join(reportsDirectory(workspace), `${agentName}.md`);
|
|
729
878
|
}
|
|
@@ -956,7 +1105,7 @@ function dropWorkspace(name, options = {}) {
|
|
|
956
1105
|
}
|
|
957
1106
|
// src/sessions.ts
|
|
958
1107
|
const COLUMNS = `id, workspace, name, purpose, kind, status, cwd, repo, host, host_pid, hooked_at, last_title,
|
|
959
|
-
parent_id, prompt_version, created_at, last_active_at, ended_at`;
|
|
1108
|
+
parent_id, prompt_version, plugin_version, created_at, last_active_at, ended_at`;
|
|
960
1109
|
function toSession(row) {
|
|
961
1110
|
return {
|
|
962
1111
|
id: row.id,
|
|
@@ -973,6 +1122,7 @@ function toSession(row) {
|
|
|
973
1122
|
lastTitle: row.last_title,
|
|
974
1123
|
parentId: row.parent_id,
|
|
975
1124
|
promptVersion: row.prompt_version,
|
|
1125
|
+
pluginVersion: row.plugin_version,
|
|
976
1126
|
createdAt: row.created_at,
|
|
977
1127
|
lastActiveAt: row.last_active_at,
|
|
978
1128
|
endedAt: row.ended_at
|
|
@@ -1124,6 +1274,9 @@ function sessionByHostProcess(ctx, host, processId) {
|
|
|
1124
1274
|
ORDER BY hooked_at DESC LIMIT 1`).get(host, processId);
|
|
1125
1275
|
return row && toSession(row);
|
|
1126
1276
|
}
|
|
1277
|
+
function recordPluginVersion(ctx, id, version) {
|
|
1278
|
+
ctx.db.prepare("UPDATE sessions SET plugin_version = ? WHERE id = ?").run(version, id);
|
|
1279
|
+
}
|
|
1127
1280
|
function recordPromptVersion(ctx, id, version) {
|
|
1128
1281
|
requireSession(ctx, id);
|
|
1129
1282
|
ctx.db.prepare("UPDATE sessions SET prompt_version = ? WHERE id = ?").run(version, id);
|
|
@@ -1186,9 +1339,9 @@ function resetDeadSessions(ctx, isAlive) {
|
|
|
1186
1339
|
}
|
|
1187
1340
|
// src/prompt/core-rules.ts
|
|
1188
1341
|
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.
|
|
1189
|
-
- The human keeps the hand: only the human launches agents,
|
|
1342
|
+
- The human keeps the hand: only the human launches agents, asks for their report and its next action (inject, validate, apply, triage), applies, tests and commits. Agents propose, they never push.
|
|
1190
1343
|
- 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
|
|
1344
|
+
- 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 (/rucher:report), even when answering about something else.
|
|
1192
1345
|
- 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
1346
|
- To launch agents or handle their results, load the rucher skill: it holds the full workflow.`;
|
|
1194
1347
|
// src/prompt/prompt.ts
|
|
@@ -1198,7 +1351,7 @@ function readIfPresent(path) {
|
|
|
1198
1351
|
return readFileSync(path, "utf8").trim() || void 0;
|
|
1199
1352
|
}
|
|
1200
1353
|
function baseRules(env = process.env) {
|
|
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,
|
|
1354
|
+
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, asks for their report and its next 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 (/rucher:report), 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.";
|
|
1202
1355
|
}
|
|
1203
1356
|
function workspaceRules(workspace) {
|
|
1204
1357
|
return workspace ? readIfPresent(join(workspace.definition, PROMPT_FILE)) : void 0;
|
|
@@ -1300,6 +1453,7 @@ function mergeSettings(base, extra) {
|
|
|
1300
1453
|
}
|
|
1301
1454
|
// src/hosts/claude-code.ts
|
|
1302
1455
|
const TRANSCRIPT_TAIL_BYTES = 262144;
|
|
1456
|
+
const TRANSCRIPT_HEAD_BYTES = 65536;
|
|
1303
1457
|
const TITLE_PATTERN = /"type":"custom-title","customTitle":("(?:[^"\\]|\\.)*")/g;
|
|
1304
1458
|
const FORK_NAME_PATTERN = /You are (?:agent|fork) `([^`]+)`/;
|
|
1305
1459
|
function payloadObject(json) {
|
|
@@ -1330,6 +1484,11 @@ function subagentMetadataDescription(transcriptPath) {
|
|
|
1330
1484
|
return;
|
|
1331
1485
|
}
|
|
1332
1486
|
}
|
|
1487
|
+
function launchedNames(toolInput) {
|
|
1488
|
+
const prompt = text(toolInput, "prompt");
|
|
1489
|
+
const found = [text(toolInput, "description"), prompt && FORK_NAME_PATTERN.exec(prompt)?.[1]].filter((name) => Boolean(name));
|
|
1490
|
+
return found.length > 0 ? [...new Set(found)] : void 0;
|
|
1491
|
+
}
|
|
1333
1492
|
function subagentPromptName(transcriptPath) {
|
|
1334
1493
|
try {
|
|
1335
1494
|
const firstLine = readFileSync(transcriptPath, "utf8").split("\n", 1)[0] ?? "";
|
|
@@ -1338,22 +1497,41 @@ function subagentPromptName(transcriptPath) {
|
|
|
1338
1497
|
return;
|
|
1339
1498
|
}
|
|
1340
1499
|
}
|
|
1341
|
-
function
|
|
1500
|
+
function readSlice(path, from, bytes) {
|
|
1342
1501
|
let descriptor;
|
|
1343
1502
|
try {
|
|
1344
1503
|
descriptor = openSync(path, "r");
|
|
1345
1504
|
const size = fstatSync(descriptor).size;
|
|
1346
|
-
const length = Math.min(size,
|
|
1505
|
+
const length = Math.min(size, bytes);
|
|
1347
1506
|
const buffer = Buffer.alloc(length);
|
|
1348
|
-
readSync(descriptor, buffer, 0, length, size - length);
|
|
1349
|
-
|
|
1350
|
-
return last === void 0 ? void 0 : JSON.parse(last);
|
|
1507
|
+
readSync(descriptor, buffer, 0, length, from === "end" ? size - length : 0);
|
|
1508
|
+
return buffer.toString("utf8");
|
|
1351
1509
|
} catch {
|
|
1352
1510
|
return;
|
|
1353
1511
|
} finally {
|
|
1354
1512
|
if (descriptor !== void 0) closeSync(descriptor);
|
|
1355
1513
|
}
|
|
1356
1514
|
}
|
|
1515
|
+
function transcriptTitle(path) {
|
|
1516
|
+
const tail = readSlice(path, "end", TRANSCRIPT_TAIL_BYTES);
|
|
1517
|
+
if (tail === void 0) return void 0;
|
|
1518
|
+
const last = [...tail.matchAll(TITLE_PATTERN)].at(-1)?.[1];
|
|
1519
|
+
return last === void 0 ? void 0 : JSON.parse(last);
|
|
1520
|
+
}
|
|
1521
|
+
function records(text) {
|
|
1522
|
+
return (text ?? "").split("\n").flatMap((line) => {
|
|
1523
|
+
try {
|
|
1524
|
+
const value = JSON.parse(line);
|
|
1525
|
+
return value && typeof value === "object" ? [value] : [];
|
|
1526
|
+
} catch {
|
|
1527
|
+
return [];
|
|
1528
|
+
}
|
|
1529
|
+
});
|
|
1530
|
+
}
|
|
1531
|
+
function continuesConversation(parentFile, childFile, parentId, childId) {
|
|
1532
|
+
if (records(readSlice(parentFile, "end", TRANSCRIPT_TAIL_BYTES)).some((record) => record.type === "continued-in" && record.continuedInSessionId === childId)) return true;
|
|
1533
|
+
return records(readSlice(childFile, "start", TRANSCRIPT_HEAD_BYTES)).some((record) => record.type === "derived-from" && Array.isArray(record.sessions) && record.sessions.some((source) => !!source && typeof source === "object" && source.id === parentId && source.via === "resume"));
|
|
1534
|
+
}
|
|
1357
1535
|
const SETTINGS_FILE = join(".claude", "settings.json");
|
|
1358
1536
|
const BACKEND_NOTES = "backends/claude.md";
|
|
1359
1537
|
function instructionFiles(workspace) {
|
|
@@ -1496,7 +1674,9 @@ const claudeCode = {
|
|
|
1496
1674
|
agent_type: text(data, "agent_type"),
|
|
1497
1675
|
path: touchedPath(toolName, data.tool_input, cwd),
|
|
1498
1676
|
file_path: text(toolInput, "file_path") ?? text(toolInput, "notebook_path"),
|
|
1499
|
-
command: text(toolInput, "command")
|
|
1677
|
+
command: text(toolInput, "command"),
|
|
1678
|
+
subagent_type: text(toolInput, "subagent_type"),
|
|
1679
|
+
launched_names: launchedNames(toolInput)
|
|
1500
1680
|
};
|
|
1501
1681
|
},
|
|
1502
1682
|
subagentInheritsContext(payload) {
|
|
@@ -1561,6 +1741,11 @@ const claudeCode = {
|
|
|
1561
1741
|
if (!existsSync(projects)) return false;
|
|
1562
1742
|
return readdirSync(projects).some((project) => existsSync(join(projects, project, `${session.id}.jsonl`)));
|
|
1563
1743
|
},
|
|
1744
|
+
continues(parent, childId, env = process.env) {
|
|
1745
|
+
if (!parent.cwd) return false;
|
|
1746
|
+
const project = join(projectsDirectory(env), parent.cwd.replace(/[^a-zA-Z0-9]/g, "-"));
|
|
1747
|
+
return continuesConversation(join(project, `${parent.id}.jsonl`), join(project, `${childId}.jsonl`), parent.id, childId);
|
|
1748
|
+
},
|
|
1564
1749
|
renameInstruction(name) {
|
|
1565
1750
|
return `Ask the human to run /rename ${name} in Claude Code so the titles match.`;
|
|
1566
1751
|
},
|
|
@@ -2073,7 +2258,7 @@ function mergeSessions(ctx, fromId, intoId) {
|
|
|
2073
2258
|
const movedTable = !(ctx.db.prepare("SELECT 1 FROM table_items WHERE session = ?").get(intoId) !== void 0) && Number(ctx.db.prepare("UPDATE table_items SET session = ? WHERE session = ?").run(intoId, fromId).changes) > 0;
|
|
2074
2259
|
ctx.db.prepare("DELETE FROM table_items WHERE session = ?").run(fromId);
|
|
2075
2260
|
const keepName = into.name === null && from.name !== null;
|
|
2076
|
-
ctx.db.prepare("UPDATE sessions SET status = 'archived', kind = 'temp', name = NULL, last_active_at = ? WHERE id = ?").run(at, fromId);
|
|
2261
|
+
ctx.db.prepare("UPDATE sessions SET status = 'archived', kind = 'temp', name = NULL, turn = NULL, turn_started_at = NULL, last_active_at = ? WHERE id = ?").run(at, fromId);
|
|
2077
2262
|
ctx.db.prepare(`UPDATE sessions
|
|
2078
2263
|
SET name = COALESCE(?, name), purpose = COALESCE(purpose, ?), last_active_at = ?,
|
|
2079
2264
|
kind = CASE WHEN ? THEN ? ELSE kind END
|
|
@@ -2091,6 +2276,38 @@ function mergeSessions(ctx, fromId, intoId) {
|
|
|
2091
2276
|
throw error;
|
|
2092
2277
|
}
|
|
2093
2278
|
}
|
|
2279
|
+
// src/sandbox.ts
|
|
2280
|
+
function strictlyInside(path, folder) {
|
|
2281
|
+
const rest = relative(folder, path);
|
|
2282
|
+
return rest !== "" && !rest.startsWith("..") && !isAbsolute(rest);
|
|
2283
|
+
}
|
|
2284
|
+
function resolveSandbox(workspace, path) {
|
|
2285
|
+
if (!workspace) throw new CarnetError("INVALID_SANDBOX", "A sandbox needs a workspace: none is resolved");
|
|
2286
|
+
const root = sandboxesDirectory(workspace);
|
|
2287
|
+
const expanded = path.startsWith("~/") ? join(homedir(), path.slice(2)) : path;
|
|
2288
|
+
const resolved = resolve(workspace.runDirectory, expanded);
|
|
2289
|
+
if (!strictlyInside(resolved, root)) throw new CarnetError("INVALID_SANDBOX", `${path} is not a folder under ${root}: a sandbox lives in the workspace's sandboxes folder`);
|
|
2290
|
+
if (existsSync(resolved)) {
|
|
2291
|
+
if (!lstatSync(resolved).isDirectory() || readdirSync(resolved).length > 0) throw new CarnetError("INVALID_SANDBOX", `${resolved} already exists and is not empty`);
|
|
2292
|
+
}
|
|
2293
|
+
return resolved;
|
|
2294
|
+
}
|
|
2295
|
+
function sandboxRemovedSuffix(removed) {
|
|
2296
|
+
return removed ? ", sandbox removed" : "";
|
|
2297
|
+
}
|
|
2298
|
+
function createSandbox(path) {
|
|
2299
|
+
mkdirSync(path, { recursive: true });
|
|
2300
|
+
}
|
|
2301
|
+
function removeSandbox(workspace, path) {
|
|
2302
|
+
if (!workspace || !path) return false;
|
|
2303
|
+
const resolved = resolve(path);
|
|
2304
|
+
if (!strictlyInside(resolved, sandboxesDirectory(workspace)) || !existsSync(resolved)) return false;
|
|
2305
|
+
rmSync(resolved, {
|
|
2306
|
+
recursive: true,
|
|
2307
|
+
force: true
|
|
2308
|
+
});
|
|
2309
|
+
return true;
|
|
2310
|
+
}
|
|
2094
2311
|
// src/purge.ts
|
|
2095
2312
|
const DEFAULT_PURGE_DAYS = 3;
|
|
2096
2313
|
const DAY_MILLISECONDS = 864e5;
|
|
@@ -2132,6 +2349,7 @@ function purgeSessions(ctx, keepId, days) {
|
|
|
2132
2349
|
// src/status/render.ts
|
|
2133
2350
|
const MAIN_HEADER = "Main";
|
|
2134
2351
|
const MAIN_WORKING_SUFFIX = "(main working)";
|
|
2352
|
+
const BLOCKED_HEADER = "Waiting on agents";
|
|
2135
2353
|
const MAIN_WAITING_SUFFIX = "(waiting on you)";
|
|
2136
2354
|
const MAIN_FAILED_SUFFIX = "(turn failed)";
|
|
2137
2355
|
function renderTableLine(item) {
|
|
@@ -2154,13 +2372,14 @@ const TURN_MARKS = {
|
|
|
2154
2372
|
alone: "turn failed"
|
|
2155
2373
|
}
|
|
2156
2374
|
};
|
|
2375
|
+
const MAIN_IDLE = "idle";
|
|
2157
2376
|
function renderMainLine(item, turn) {
|
|
2158
|
-
if (!turn) return item ? renderTableLine(item) :
|
|
2377
|
+
if (!turn) return item ? renderTableLine(item) : MAIN_IDLE;
|
|
2159
2378
|
const mark = TURN_MARKS[turn];
|
|
2160
2379
|
return item ? `${mark.emoji} ${item.text} ${mark.suffix}` : `${mark.emoji} ${mark.alone}`;
|
|
2161
2380
|
}
|
|
2162
2381
|
function renderAgentLine(line, nameWidth = 0) {
|
|
2163
|
-
const head = `${line.emoji} ${
|
|
2382
|
+
const head = `${line.emoji} ${kindTag(line.kind)} ${line.name}`;
|
|
2164
2383
|
const action = line.action ? ` ${" ".repeat(Math.max(nameWidth - line.name.length, 0))} ${line.action}` : "";
|
|
2165
2384
|
return line.note ? `${head}${action} — ${line.note}` : `${head}${action}`;
|
|
2166
2385
|
}
|
|
@@ -2206,14 +2425,18 @@ function renderNotes(notes, mode = "full") {
|
|
|
2206
2425
|
}
|
|
2207
2426
|
function renderSections(view, options = {}) {
|
|
2208
2427
|
const out = [];
|
|
2209
|
-
|
|
2210
|
-
if (main) out.push(MAIN_HEADER, ` ${main}`, "");
|
|
2428
|
+
out.push(MAIN_HEADER, ` ${renderMainLine(view.table, view.turn)}`, "");
|
|
2211
2429
|
out.push("Waiting on you");
|
|
2212
2430
|
if (view.waiting.length === 0) out.push(" nothing");
|
|
2213
2431
|
const waitingWidth = nameWidth(view.waiting);
|
|
2214
2432
|
view.waiting.forEach((line, index) => {
|
|
2215
|
-
out.push(` ${index + 1}. ${renderAgentLine(line, waitingWidth)}`);
|
|
2433
|
+
out.push(` ${index + 1}.${line.pinned ? "📌" : ""} ${renderAgentLine(line, waitingWidth)}`);
|
|
2216
2434
|
});
|
|
2435
|
+
if (view.blocked.length > 0) {
|
|
2436
|
+
out.push("", BLOCKED_HEADER);
|
|
2437
|
+
const blockedWidth = nameWidth(view.blocked);
|
|
2438
|
+
for (const line of view.blocked) out.push(` ${renderAgentLine(line, blockedWidth)}`);
|
|
2439
|
+
}
|
|
2217
2440
|
out.push("", "Running");
|
|
2218
2441
|
if (view.running.length === 0) out.push(" nothing");
|
|
2219
2442
|
const runningWidth = nameWidth(view.running);
|
|
@@ -2290,22 +2513,22 @@ function endTurn(ctx, session) {
|
|
|
2290
2513
|
}
|
|
2291
2514
|
// src/status/view.ts
|
|
2292
2515
|
const ACTION_RANK = {
|
|
2293
|
-
|
|
2294
|
-
|
|
2295
|
-
|
|
2516
|
+
test: 0,
|
|
2517
|
+
answer: 1,
|
|
2518
|
+
validate: 2,
|
|
2519
|
+
triage: 3,
|
|
2296
2520
|
apply: 4,
|
|
2297
|
-
|
|
2298
|
-
commit: 6
|
|
2521
|
+
inject: 5
|
|
2299
2522
|
};
|
|
2300
2523
|
function plural(count, word) {
|
|
2301
2524
|
return `${count} ${word}${count === 1 ? "" : "s"}`;
|
|
2302
2525
|
}
|
|
2303
2526
|
function actionWord(agent) {
|
|
2304
2527
|
const { kind, status } = agent;
|
|
2305
|
-
if (status === "answer") return kind === "
|
|
2306
|
-
if (status === "review" && kind !== "implement") return
|
|
2528
|
+
if (status === "answer") return kind === "plan" ? "validate" : "answer";
|
|
2529
|
+
if (status === "review" && kind !== "implement") return KIND_ACTIONS[kind];
|
|
2307
2530
|
if (status === "apply" && kind === "implement") return "apply";
|
|
2308
|
-
if (status === "test"
|
|
2531
|
+
if (status === "test") return status;
|
|
2309
2532
|
return status === "discussing" ? "discuss" : status;
|
|
2310
2533
|
}
|
|
2311
2534
|
function actionDetail(ctx, agent, word) {
|
|
@@ -2336,8 +2559,8 @@ function runningAction(agent) {
|
|
|
2336
2559
|
return agent.promotedFrom ? `promoted from ${agent.promotedFrom}` : null;
|
|
2337
2560
|
}
|
|
2338
2561
|
function rankOf(agent) {
|
|
2339
|
-
if (agent.status === "answer") return
|
|
2340
|
-
return ACTION_RANK[actionWord(agent)] ?? Object.keys(ACTION_RANK).length
|
|
2562
|
+
if (agent.status === "answer") return ACTION_RANK.answer;
|
|
2563
|
+
return ACTION_RANK[actionWord(agent)] ?? Object.keys(ACTION_RANK).length;
|
|
2341
2564
|
}
|
|
2342
2565
|
function compareWaiting(left, right) {
|
|
2343
2566
|
if (left.queueOrder !== null || right.queueOrder !== null) {
|
|
@@ -2345,7 +2568,7 @@ function compareWaiting(left, right) {
|
|
|
2345
2568
|
if (right.queueOrder === null) return -1;
|
|
2346
2569
|
return left.queueOrder - right.queueOrder;
|
|
2347
2570
|
}
|
|
2348
|
-
return rankOf(left) - rankOf(right) || left.
|
|
2571
|
+
return rankOf(left) - rankOf(right) || left.statusSince.localeCompare(right.statusSince) || left.name.localeCompare(right.name);
|
|
2349
2572
|
}
|
|
2350
2573
|
function toLine(agent, action) {
|
|
2351
2574
|
return {
|
|
@@ -2354,23 +2577,29 @@ function toLine(agent, action) {
|
|
|
2354
2577
|
status: agent.status,
|
|
2355
2578
|
emoji: agent.status === "closed" ? "" : EMOJI[agent.status],
|
|
2356
2579
|
action,
|
|
2357
|
-
note: agent.note
|
|
2580
|
+
note: agent.note,
|
|
2581
|
+
pinned: agent.queueOrder !== null
|
|
2358
2582
|
};
|
|
2359
2583
|
}
|
|
2360
2584
|
function formatClock(date) {
|
|
2361
2585
|
return `${String(date.getHours()).padStart(2, "0")}:${String(date.getMinutes()).padStart(2, "0")}`;
|
|
2362
2586
|
}
|
|
2363
2587
|
function buildStatusView(ctx, session, options = {}) {
|
|
2364
|
-
const
|
|
2588
|
+
const all = listAgents(ctx, session.id);
|
|
2589
|
+
const open = new Set(all.map((agent) => agent.name));
|
|
2590
|
+
const isBlocked = (agent) => agent.blockedOn !== null && open.has(agent.blockedOn);
|
|
2591
|
+
const agents = all.filter((agent) => !options.kind || agent.kind === options.kind);
|
|
2365
2592
|
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
|
|
2593
|
+
const waiting = agents.filter((agent) => isUserActionStatus(agent.status)).filter((agent) => !isBlocked(agent) && !tableIsAbout(table, agent.name)).sort(compareWaiting).map((agent) => toLine(agent, waitingAction(ctx, agent)));
|
|
2594
|
+
const blocked = agents.filter(isBlocked).map((agent) => toLine(agent, `→ ${agent.blockedOn}`));
|
|
2595
|
+
const running = agents.filter((agent) => agent.status === "running" && !isBlocked(agent)).map((agent) => toLine(agent, runningAction(agent)));
|
|
2368
2596
|
return {
|
|
2369
2597
|
time: formatClock(ctx.now()),
|
|
2370
2598
|
sessionName: session.name,
|
|
2371
2599
|
table,
|
|
2372
2600
|
turn: getTurn(ctx, session.id),
|
|
2373
2601
|
waiting,
|
|
2602
|
+
blocked,
|
|
2374
2603
|
running,
|
|
2375
2604
|
notes: sessionNoteActivity(ctx, session.id)
|
|
2376
2605
|
};
|
|
@@ -2382,15 +2611,39 @@ function byHostAgentId(ctx, session, hostAgentId) {
|
|
|
2382
2611
|
const row = ctx.db.prepare("SELECT * FROM agents WHERE session = ? AND host_agent_id = ?").get(session, hostAgentId);
|
|
2383
2612
|
return row && toAgent(row);
|
|
2384
2613
|
}
|
|
2385
|
-
function
|
|
2614
|
+
function unpairedByName(ctx, session, names) {
|
|
2615
|
+
for (const name of names) {
|
|
2616
|
+
const row = ctx.db.prepare(`SELECT * FROM agents
|
|
2617
|
+
WHERE session = ? AND name = ? AND status != 'closed' AND host_agent_id IS NULL`).get(session, name);
|
|
2618
|
+
if (row) return row;
|
|
2619
|
+
}
|
|
2620
|
+
}
|
|
2621
|
+
function unpairedAgent(ctx, session, names) {
|
|
2622
|
+
const row = unpairedByName(ctx, session, names);
|
|
2623
|
+
return row && toAgent(row);
|
|
2624
|
+
}
|
|
2625
|
+
function pendingPlanAgent(ctx, session) {
|
|
2626
|
+
const row = ctx.db.prepare(`SELECT * FROM agents
|
|
2627
|
+
WHERE session = ? AND kind = 'plan' AND status = 'running' AND host_agent_id IS NULL
|
|
2628
|
+
ORDER BY started_at ASC, rowid ASC LIMIT 1`).get(session);
|
|
2629
|
+
return row && toAgent(row);
|
|
2630
|
+
}
|
|
2631
|
+
function requestLaunch(ctx, session, name) {
|
|
2632
|
+
ctx.db.prepare("UPDATE agents SET launch_requested_at = ? WHERE session = ? AND name = ?").run(nowIso(ctx), session, name);
|
|
2633
|
+
}
|
|
2634
|
+
function pairSubagent(ctx, session, hostAgentId, names = []) {
|
|
2386
2635
|
const paired = byHostAgentId(ctx, session, hostAgentId);
|
|
2387
2636
|
if (paired) return paired;
|
|
2388
2637
|
const since = (/* @__PURE__ */ new Date(ctx.now().getTime() - PAIRING_WINDOW_MILLISECONDS)).toISOString();
|
|
2389
|
-
const row = ctx.db.prepare(`SELECT * FROM agents
|
|
2390
|
-
|
|
2391
|
-
|
|
2638
|
+
const row = unpairedByName(ctx, session, names) ?? ctx.db.prepare(`SELECT * FROM agents
|
|
2639
|
+
WHERE session = ? AND status != 'closed' AND host_agent_id IS NULL
|
|
2640
|
+
AND launch_requested_at >= ?
|
|
2641
|
+
ORDER BY launch_requested_at ASC, rowid ASC LIMIT 1`).get(session, since) ?? ctx.db.prepare(`SELECT * FROM agents
|
|
2642
|
+
WHERE session = ? AND status = 'running' AND host_agent_id IS NULL AND blocked_on IS NULL
|
|
2643
|
+
AND started_at >= ?
|
|
2644
|
+
ORDER BY started_at ASC, rowid ASC LIMIT 1`).get(session, since);
|
|
2392
2645
|
if (!row) return void 0;
|
|
2393
|
-
ctx.db.prepare("UPDATE agents SET host_agent_id =
|
|
2646
|
+
ctx.db.prepare("UPDATE agents SET host_agent_id = ?, launch_requested_at = NULL WHERE session = ? AND name = ?").run(hostAgentId, session, row.name);
|
|
2394
2647
|
return byHostAgentId(ctx, session, hostAgentId);
|
|
2395
2648
|
}
|
|
2396
2649
|
function byName(ctx, session, name) {
|
|
@@ -2450,15 +2703,25 @@ var Carnet = class {
|
|
|
2450
2703
|
ensure: (id, cwd) => ensureSession(this.ctx, id, cwd, this.workspace ?? void 0),
|
|
2451
2704
|
upsertFromHook: (payload, env) => upsertFromHook(this.ctx, this.workspace, payload, env),
|
|
2452
2705
|
touch: (id) => touchSession(this.ctx, id),
|
|
2453
|
-
merge: (fromId, intoId) =>
|
|
2706
|
+
merge: (fromId, intoId) => {
|
|
2707
|
+
const result = mergeSessions(this.ctx, fromId, intoId);
|
|
2708
|
+
this.releaseClosedSandboxes(fromId);
|
|
2709
|
+
this.releaseClosedSandboxes(intoId);
|
|
2710
|
+
return result;
|
|
2711
|
+
},
|
|
2454
2712
|
purge: (keepId, days) => purgeSessions(this.ctx, keepId, days),
|
|
2455
2713
|
name: (id, name, purpose) => nameSession(this.ctx, id, name, purpose),
|
|
2456
2714
|
adoptTitle: (id, title) => adoptTitle(this.ctx, id, title),
|
|
2457
2715
|
list: (options) => listSessions(this.ctx, options),
|
|
2458
|
-
drop: (id) =>
|
|
2716
|
+
drop: (id) => {
|
|
2717
|
+
const session = dropSession(this.ctx, id);
|
|
2718
|
+
this.releaseClosedSandboxes(id);
|
|
2719
|
+
return session;
|
|
2720
|
+
},
|
|
2459
2721
|
default: () => defaultSession(this.ctx),
|
|
2460
2722
|
byName: (name) => sessionByName(this.ctx, name),
|
|
2461
2723
|
byHostProcess: (host, processId) => sessionByHostProcess(this.ctx, host, processId),
|
|
2724
|
+
recordPluginVersion: (id, version) => recordPluginVersion(this.ctx, id, version),
|
|
2462
2725
|
recordPromptVersion: (id, version) => recordPromptVersion(this.ctx, id, version),
|
|
2463
2726
|
setParent: (id, parentId) => setParent(this.ctx, id, parentId),
|
|
2464
2727
|
setStatus: (id, status) => setSessionStatus(this.ctx, id, status),
|
|
@@ -2471,18 +2734,56 @@ var Carnet = class {
|
|
|
2471
2734
|
staleTemp: (olderThanMilliseconds) => staleTempSessions(this.ctx, olderThanMilliseconds),
|
|
2472
2735
|
resetDead: (isAlive) => resetDeadSessions(this.ctx, isAlive)
|
|
2473
2736
|
};
|
|
2737
|
+
releaseSandbox(agent) {
|
|
2738
|
+
if (!agent.sandbox) return {
|
|
2739
|
+
...agent,
|
|
2740
|
+
sandboxRemoved: false
|
|
2741
|
+
};
|
|
2742
|
+
const sandboxRemoved = removeSandbox(this.workspace, agent.sandbox);
|
|
2743
|
+
clearSandbox(this.ctx, agent.session, agent.name);
|
|
2744
|
+
return {
|
|
2745
|
+
...agent,
|
|
2746
|
+
sandbox: null,
|
|
2747
|
+
sandboxRemoved
|
|
2748
|
+
};
|
|
2749
|
+
}
|
|
2750
|
+
releaseClosedSandboxes(session) {
|
|
2751
|
+
let removed = 0;
|
|
2752
|
+
for (const row of closedSandboxes(this.ctx, session)) {
|
|
2753
|
+
if (removeSandbox(this.workspace, row.sandbox)) removed += 1;
|
|
2754
|
+
clearSandbox(this.ctx, row.session, row.name);
|
|
2755
|
+
}
|
|
2756
|
+
return removed;
|
|
2757
|
+
}
|
|
2474
2758
|
agents = {
|
|
2475
2759
|
get: (session, name) => getAgent(this.ctx, session, name),
|
|
2476
|
-
start: (session, input) =>
|
|
2760
|
+
start: (session, input) => {
|
|
2761
|
+
const sandbox = input.sandbox ? resolveSandbox(this.workspace, input.sandbox) : void 0;
|
|
2762
|
+
const agent = startAgent(this.ctx, session, {
|
|
2763
|
+
...input,
|
|
2764
|
+
sandbox
|
|
2765
|
+
});
|
|
2766
|
+
if (sandbox) createSandbox(sandbox);
|
|
2767
|
+
return agent;
|
|
2768
|
+
},
|
|
2477
2769
|
update: (session, name, input) => updateAgent(this.ctx, session, name, input),
|
|
2478
2770
|
finish: (session, name, input) => finishAgent(this.ctx, session, name, input),
|
|
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) =>
|
|
2771
|
+
drop: (session, name, reason) => this.releaseSandbox(dropAgent(this.ctx, session, name, reason)),
|
|
2772
|
+
close: (session, name, event) => this.releaseSandbox(closeAgent(this.ctx, session, name, event)),
|
|
2773
|
+
promote: (session, name, input) => {
|
|
2774
|
+
const agent = promoteAgent(this.ctx, session, name, input);
|
|
2775
|
+
return agent.kind === "implement" ? this.releaseSandbox(agent) : {
|
|
2776
|
+
...agent,
|
|
2777
|
+
sandboxRemoved: false
|
|
2778
|
+
};
|
|
2779
|
+
},
|
|
2482
2780
|
list: (session, options) => listAgents(this.ctx, session, options),
|
|
2483
2781
|
reorderQueue: (session, names) => reorderQueue(this.ctx, session, names),
|
|
2484
2782
|
byHostAgentId: (session, hostAgentId) => byHostAgentId(this.ctx, session, hostAgentId),
|
|
2485
|
-
pairSubagent: (session, hostAgentId) => pairSubagent(this.ctx, session, hostAgentId),
|
|
2783
|
+
pairSubagent: (session, hostAgentId, names) => pairSubagent(this.ctx, session, hostAgentId, names),
|
|
2784
|
+
unpaired: (session, names) => unpairedAgent(this.ctx, session, names),
|
|
2785
|
+
pendingPlan: (session) => pendingPlanAgent(this.ctx, session),
|
|
2786
|
+
requestLaunch: (session, name) => requestLaunch(this.ctx, session, name),
|
|
2486
2787
|
stopSubagent: (session, hostAgentId, names) => stopSubagent(this.ctx, session, hostAgentId, names)
|
|
2487
2788
|
};
|
|
2488
2789
|
questions = {
|
|
@@ -2607,7 +2908,7 @@ const AGENT_STEPS = [
|
|
|
2607
2908
|
];
|
|
2608
2909
|
const DEFAULT_NEXT = {
|
|
2609
2910
|
applied: "test",
|
|
2610
|
-
tested: "
|
|
2911
|
+
tested: "test"
|
|
2611
2912
|
};
|
|
2612
2913
|
function clearTableOf(carnet, session, name) {
|
|
2613
2914
|
if (tableIsAbout(carnet.table.get(session), name)) carnet.table.clear(session);
|
|
@@ -2622,12 +2923,13 @@ function stepAgent(carnet, session, input) {
|
|
|
2622
2923
|
carnet.table.set(session, { text: `${name} applying` });
|
|
2623
2924
|
carnet.agents.update(session, name, {
|
|
2624
2925
|
status: agent.status,
|
|
2625
|
-
note: note ?? null
|
|
2926
|
+
note: note ?? null,
|
|
2927
|
+
blockedOn: null
|
|
2626
2928
|
});
|
|
2627
2929
|
const reviews = carnet.agents.list(session).filter((other) => other.kind === "review" && other.target === name);
|
|
2628
2930
|
return `⚙️ ${name} applying${reviews.length ? `\nwarning: review ${reviews.map((review) => review.name).join(", ")} not triaged yet` : ""}`;
|
|
2629
2931
|
}
|
|
2630
|
-
case "committed":
|
|
2932
|
+
case "committed": {
|
|
2631
2933
|
if (!commit) throw new CarnetError("COMMIT_REQUIRED", "The committed step needs the commit");
|
|
2632
2934
|
carnet.events.log(session, {
|
|
2633
2935
|
type: "committed",
|
|
@@ -2635,13 +2937,15 @@ function stepAgent(carnet, session, input) {
|
|
|
2635
2937
|
commit,
|
|
2636
2938
|
note
|
|
2637
2939
|
});
|
|
2638
|
-
carnet.agents.drop(session, name, `committed ${commit}`);
|
|
2940
|
+
const closed = carnet.agents.drop(session, name, `committed ${commit}`);
|
|
2639
2941
|
clearTableOf(carnet, session, name);
|
|
2640
|
-
return
|
|
2641
|
-
|
|
2642
|
-
|
|
2942
|
+
return `✅ ${name} committed ${commit}, closed${sandboxRemovedSuffix(closed.sandboxRemoved)}`;
|
|
2943
|
+
}
|
|
2944
|
+
case "dropped": {
|
|
2945
|
+
const closed = carnet.agents.drop(session, name, note);
|
|
2643
2946
|
clearTableOf(carnet, session, name);
|
|
2644
|
-
return `${name} dropped, closed`;
|
|
2947
|
+
return `${name} dropped, closed${sandboxRemovedSuffix(closed.sandboxRemoved)}`;
|
|
2948
|
+
}
|
|
2645
2949
|
default: {
|
|
2646
2950
|
const next = input.next ?? (step === "answered" ? statusAfterAnswers(agent.kind) : DEFAULT_NEXT[step]);
|
|
2647
2951
|
carnet.events.log(session, {
|
|
@@ -2651,17 +2955,14 @@ function stepAgent(carnet, session, input) {
|
|
|
2651
2955
|
});
|
|
2652
2956
|
carnet.agents.update(session, name, {
|
|
2653
2957
|
status: next,
|
|
2654
|
-
note: note ?? null
|
|
2655
|
-
|
|
2656
|
-
if (next === "running") clearTableOf(carnet, session, name);
|
|
2657
|
-
else if (step !== "answered") carnet.table.set(session, {
|
|
2658
|
-
text: `${name} ${step}, ${next} next`,
|
|
2659
|
-
status: next
|
|
2958
|
+
note: note ?? null,
|
|
2959
|
+
blockedOn: null
|
|
2660
2960
|
});
|
|
2961
|
+
if (next === "running" || step !== "answered") clearTableOf(carnet, session, name);
|
|
2661
2962
|
return `logged ${step} · ${EMOJI[next]} ${name} ${next}`;
|
|
2662
2963
|
}
|
|
2663
2964
|
}
|
|
2664
2965
|
}
|
|
2665
|
-
export {
|
|
2966
|
+
export { repoPathFor as $, renderFindings as $t, renderNotesSummary as A, KIND_ABBREVIATIONS as An, rulesVersion as At, DEFAULT_HALF_LIFE_DAYS as B, isUserActionStatus as Bn, definitionInstructions as Bt, NOTES_FOLD_LINES as C, mainTargetRange as Cn, SUBAGENT_RULES as Ct, renderMainLine as D, sanitizeNote as Dn, compactReminder as Dt, renderAgentLine as E, NOTE_MAX as En, baseRules as Et, purgeDays as F, MAIN_WAITING_EMOJI as Fn, AGENTS_FILE as Ft, isNoteKind as G, CarnetError as Gn, loadWorkspace as Gt, NOTE_KINDS as H, EVENT_TYPES as Hn, expandHome as Ht, sandboxRemovedSuffix as I, MAIN_WORKING_EMOJI as In, INSTRUCTIONS_FILE as It, sessionNoteActivity as J, workspaceHosts as Jt, localDay as K, removeWorkspaceRepo as Kt, MEMORY_MAX_CHARACTERS as L, OPEN_AGENT_STATUSES as Ln, WORKSPACE_FILE as Lt, renderStatus as M, KIND_TAG_PATTERN as Mn, CORE_RULES as Mt, renderTableLine as N, LEGEND as Nn, MINIMUM_ID_PREFIX as Nt, renderNoteLine as O, AGENT_STATUSES as On, outsideRucherContext as Ot, DEFAULT_PURGE_DAYS as P, MAIN_FAILED_EMOJI as Pn, shortId as Pt, repoNameFor as Q, formatFinding as Qt, memoryMaxCharacters as R, USER_ACTION_STATUSES as Rn, addWorkspaceRepo as Rt, MAIN_WORKING_SUFFIX as S, isAgentKind as Sn, RULES_UPDATED_NOTICE as St, SIMILAR_PREFIX as T, statusWhenDone as Tn, assemblePrompt as Tt, NOTE_TEXT_LIMIT as U, SESSION_EVENT_TYPES as Un, isWorkspaceName as Ut, DUPLICATE_SIMILARITY as V, kindTag as Vn, dropWorkspace as Vt, STALE_AFTER_ACTIVE_DAYS as W, isEventType as Wn, listWorkspaces as Wt, workspaceRepoNames as X, FINDING_DECISIONS as Xt, similarity as Y, renderQuestions as Yt, isInside as Z, FINDING_SEVERITIES as Zt, BLOCKED_HEADER as _, KIND_REQUIRED as _n, mergeSettings as _t, formatEventLine as a, reportsDirectory as an, sessionWorkspaceName as at, MAIN_IDLE as b, REPORTING_NOTE as bn, OUTSIDE_RUCHER_NOTICE as bt, Carnet as c, workspaceDefinition as cn, DEFAULT_HOST as ct, openWorkspaceCarnet as d, openDatabase as dn, claudeCode as dt, corePromptPath as en, requireWorkspace as et, PAIRING_WINDOW_MILLISECONDS as f, migrate as fn, transcriptTitle as ft, TURNS as g, KIND_ACTIONS as gn, markdownCopy as gt, formatClock as h, AGENT_KINDS as hn, MARKDOWN_MARKER as ht, RESUME_MAX_CHARACTERS as i, reportPath as in, deleteWorkspaceNotes as it, renderSections as j, KIND_LEGEND as jn, workspaceRules as jt, renderNotes as k, EMOJI as kn, rulesText as kt, openCarnet as l, workspacesDirectory as ln, allHosts as lt, buildStatusView as m, schemaVersion as mn, GENERATED_MARKER as mt, stepAgent as n, defaultRunDirectory as nn, workspaceLabel as nt, resumeContext as o, rucherPaths as on, workspaceLastActive as ot, STOPPED_NOTE as p, migrations as pn, workspaceSettings as pt, memoryHalfLife as q, workspaceExists as qt, RESUME_EVENTS as r, promptsDirectory as rn, archiveWorkspaceSessions as rt, sessionLabel as s, sandboxesDirectory as sn, workspaceSessionCounts as st, AGENT_STEPS as t, databasePath as tn, resolveWorkspace as tt, openResolvedCarnet as u, MEMORY_DB as un, hostById as ut, MAIN_FAILED_SUFFIX as v, PROMOTE_KIND_REQUIRED as vn, removeStaleCopies as vt, NOTES_HEADER as w, statusAfterAnswers as wn, appendPromptFile as wt, MAIN_WAITING_SUFFIX as x, SANDBOX_KINDS as xn, PROMPT_FILE as xt, MAIN_HEADER as y, PUBLISH_FALLBACK_MILLISECONDS as yn, writeGenerated as yt, renderMemory as z, isAgentStatus as zn, createWorkspace as zt };
|
|
2666
2967
|
|
|
2667
|
-
//# sourceMappingURL=steps-
|
|
2968
|
+
//# sourceMappingURL=steps-wNm8GU_c.mjs.map
|