tryharness 0.7.38 → 0.7.41

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/lib/plans.mjs ADDED
@@ -0,0 +1,538 @@
1
+ // Work wired to wait for other work in a thread, and templates of it. A plan node is an agent and what it is asked,
2
+ // waiting on the thread's tasks or other plan nodes ("after"). Once everything it waits on is done it is posted as an
3
+ // ordinary board task, so it starts, is authorized and runs where it would had it been posted then, with the answers
4
+ // it waited for in its brief. Work it waits on that stops or is removed stops it too, and the thread says why.
5
+ // The person wires nodes on the buddy's canvas; agents do it with post_task's `after`; a template is the same nodes
6
+ // and wires as JSON, with {{blanks}} filled in when it is used. A node can only wait on work that exists or on nodes
7
+ // given with it, so no wiring can loop.
8
+ import fs from "node:fs";
9
+ import path from "node:path";
10
+ import { randomUUID } from "node:crypto";
11
+
12
+ const MAX_NODES = 50;
13
+ const PROMPT_LIMIT = 8_000;
14
+ const ANSWER_LIMIT = 2_000;
15
+ const NAME_LIMIT = 80;
16
+ const BLANK = /\{\{\s*([A-Za-z][\w-]{0,40})\s*\}\}/g;
17
+ // Work that has ended without an answer to pass on.
18
+ const STOPPED = new Set(["failed", "unknown"]);
19
+
20
+ const words = (text) => String(text ?? "").trim();
21
+ const slugOf = (name) =>
22
+ words(name)
23
+ .toLowerCase()
24
+ .replace(/[^a-z0-9]+/g, "-")
25
+ .replace(/^-+|-+$/g, "")
26
+ .slice(0, 60);
27
+ const blanksIn = (texts) => [
28
+ ...new Set(
29
+ texts.flatMap((text) => [...String(text).matchAll(BLANK)].map((m) => m[1]))
30
+ ),
31
+ ];
32
+
33
+ /** Nodes in an order where each comes after everything it waits on, or null when the wiring loops. */
34
+ function ordered(nodes, waitsOn) {
35
+ const byKey = new Map(nodes.map((node) => [node.key, node]));
36
+ const done = new Set();
37
+ const visiting = new Set();
38
+ const out = [];
39
+ const visit = (node) => {
40
+ if (done.has(node.key)) return true;
41
+ if (visiting.has(node.key)) return false;
42
+ visiting.add(node.key);
43
+ for (const ref of waitsOn(node))
44
+ if (byKey.has(ref) && !visit(byKey.get(ref))) return false;
45
+ visiting.delete(node.key);
46
+ done.add(node.key);
47
+ out.push(node);
48
+ return true;
49
+ };
50
+ for (const node of nodes) if (!visit(node)) return null;
51
+ return out;
52
+ }
53
+
54
+ /**
55
+ * A template as the person or an agent gave it, checked and cut down to what a template carries: each node's agent,
56
+ * what it is asked and where it sat, and the wires. Nothing else in the JSON (keys, sessions, files) is kept.
57
+ */
58
+ export function checkTemplate(raw, { agents = null } = {}) {
59
+ let value = raw;
60
+ if (typeof raw === "string")
61
+ try {
62
+ value = JSON.parse(raw);
63
+ } catch {
64
+ return { ok: false, error: "that is not JSON" };
65
+ }
66
+ if (!value || typeof value !== "object" || !Array.isArray(value.nodes))
67
+ return { ok: false, error: "a template needs a list of nodes" };
68
+ if (!value.nodes.length)
69
+ return { ok: false, error: "a template needs at least one node" };
70
+ if (value.nodes.length > MAX_NODES)
71
+ return { ok: false, error: `a template holds at most ${MAX_NODES} nodes` };
72
+ const nodes = [];
73
+ for (const [i, node] of value.nodes.entries()) {
74
+ const key = words(node?.key) || `n${i + 1}`;
75
+ const agent = words(node?.agent);
76
+ const prompt = words(node?.prompt);
77
+ if (!agent) return { ok: false, error: `node ${key} names no agent` };
78
+ if (!prompt) return { ok: false, error: `node ${key} asks nothing` };
79
+ if (prompt.length > PROMPT_LIMIT)
80
+ return {
81
+ ok: false,
82
+ error: `node ${key}'s prompt is over ${PROMPT_LIMIT} characters`,
83
+ };
84
+ if (nodes.some((n) => n.key === key))
85
+ return { ok: false, error: `two nodes are called ${key}` };
86
+ const at =
87
+ Number.isFinite(node?.at?.x) && Number.isFinite(node?.at?.y)
88
+ ? { x: Math.round(node.at.x), y: Math.round(node.at.y) }
89
+ : null;
90
+ nodes.push({ key, agent, prompt, ...(at ? { at } : {}) });
91
+ }
92
+ const keys = new Set(nodes.map((n) => n.key));
93
+ const wires = [];
94
+ for (const wire of Array.isArray(value.wires) ? value.wires : []) {
95
+ const from = words(wire?.from),
96
+ to = words(wire?.to);
97
+ if (!keys.has(from) || !keys.has(to))
98
+ return {
99
+ ok: false,
100
+ error: `a wire joins ${from || "?"} to ${to || "?"}, which are not both nodes`,
101
+ };
102
+ if (from === to) return { ok: false, error: `${from} is wired to itself` };
103
+ if (!wires.some((w) => w.from === from && w.to === to))
104
+ wires.push({ from, to });
105
+ }
106
+ const waitsOn = (node) =>
107
+ wires.filter((w) => w.to === node.key).map((w) => w.from);
108
+ if (!ordered(nodes, waitsOn))
109
+ return { ok: false, error: "the wires go round in a loop" };
110
+ const template = {
111
+ harness: "template",
112
+ version: 1,
113
+ name: words(value.name).slice(0, NAME_LIMIT) || "Untitled",
114
+ ...(words(value.description)
115
+ ? { description: words(value.description).slice(0, 500) }
116
+ : {}),
117
+ nodes,
118
+ wires,
119
+ };
120
+ return {
121
+ ok: true,
122
+ template,
123
+ blanks: blanksIn(nodes.map((n) => n.prompt)),
124
+ // Agents this computer's swarm does not have: the template still loads, the person picks another.
125
+ missing: agents
126
+ ? [
127
+ ...new Set(
128
+ nodes.map((n) => n.agent).filter((a) => !agents.includes(a))
129
+ ),
130
+ ]
131
+ : [],
132
+ };
133
+ }
134
+
135
+ const fill = (text, values) =>
136
+ String(text).replace(BLANK, (whole, name) =>
137
+ Object.hasOwn(values, name) && words(values[name])
138
+ ? words(values[name])
139
+ : whole
140
+ );
141
+
142
+ /**
143
+ * `post(request)` posts a task the way any agent's post does (the daemon's own board command); `changed(task)` hears
144
+ * every task change in a thread.
145
+ */
146
+ export function createPlans({
147
+ store,
148
+ roomAgents,
149
+ post,
150
+ home,
151
+ log = () => {},
152
+ onPlanChange = () => {},
153
+ }) {
154
+ const folder = path.join(home, "templates");
155
+ const planOf = (threadId) => {
156
+ try {
157
+ return JSON.parse(store.meta(`plan:${threadId}`) || "[]");
158
+ } catch {
159
+ return [];
160
+ }
161
+ };
162
+ const savePlan = (threadId, plan) => {
163
+ store.meta(`plan:${threadId}`, JSON.stringify(plan));
164
+ onPlanChange(threadId);
165
+ };
166
+ const threadOf = (id) => {
167
+ const thread = store.getTask(String(id || ""));
168
+ return thread && thread.kind === "goal" ? thread : null;
169
+ };
170
+ // A plan node's id stands for the task it became once it was posted.
171
+ const taskFor = (plan, ref) =>
172
+ plan.find((node) => node.id === ref)?.taskId ?? ref;
173
+
174
+ // What each waiting node waits on now: everything done, something stopped, or still going.
175
+ function settle(threadId) {
176
+ const plan = planOf(threadId);
177
+ let changed = false;
178
+ for (let pass = 0; pass < MAX_NODES; pass++) {
179
+ let moved = false;
180
+ for (const node of plan) {
181
+ if (node.state !== "waiting") continue;
182
+ const inputs = node.after.map((ref) => {
183
+ const planned = plan.find((other) => other.id === ref);
184
+ if (planned && !planned.taskId)
185
+ return {
186
+ ref,
187
+ state: planned.state === "blocked" ? "stopped" : "waiting",
188
+ name: planned.agent,
189
+ };
190
+ const task = store.getTask(taskFor(plan, ref));
191
+ if (!task || task.removed_at)
192
+ return { ref, state: "stopped", name: "work that was removed" };
193
+ if (task.status === "done") return { ref, state: "done", task };
194
+ if (STOPPED.has(task.status))
195
+ return {
196
+ ref,
197
+ state: "stopped",
198
+ name: task.claimed_by || task.target_agent,
199
+ };
200
+ return { ref, state: "waiting" };
201
+ });
202
+ const stopped = inputs.find((input) => input.state === "stopped");
203
+ if (stopped) {
204
+ node.state = "blocked";
205
+ node.reason = `${stopped.name} stopped before it finished`;
206
+ moved = changed = true;
207
+ store.roomPost({
208
+ goalId: threadId,
209
+ author: "harness",
210
+ kind: "note",
211
+ text: `${node.agent}'s next step ("${node.objective.slice(0, 80)}") will not start: ${node.reason}.`,
212
+ });
213
+ continue;
214
+ }
215
+ if (inputs.some((input) => input.state === "waiting")) continue;
216
+ const answers = inputs
217
+ .filter((input) => input.task)
218
+ .map(
219
+ ({ task }) =>
220
+ `${task.claimed_by || task.target_agent} ("${task.objective.slice(0, 120)}"): ${String(task.result || "finished").slice(0, ANSWER_LIMIT)}`
221
+ );
222
+ const brief = [
223
+ node.brief,
224
+ answers.length
225
+ ? `This step was wired to wait for this work in the thread, now done:\n\n${answers.join("\n\n")}`
226
+ : "",
227
+ ]
228
+ .filter(Boolean)
229
+ .join("\n\n");
230
+ const posted = post({
231
+ command: "board.post",
232
+ agent: node.by,
233
+ objective: node.objective,
234
+ brief,
235
+ targetAgent: node.agent,
236
+ parentId: threadId,
237
+ });
238
+ if (posted?.ok && posted.task?.id) {
239
+ node.taskId = posted.task.id;
240
+ node.state = "posted";
241
+ } else {
242
+ node.state = "blocked";
243
+ node.reason = posted?.error || "it could not be posted";
244
+ log(`plan ${node.id} not posted: ${node.reason}`);
245
+ }
246
+ moved = changed = true;
247
+ }
248
+ if (!moved) break;
249
+ }
250
+ if (changed) savePlan(threadId, plan);
251
+ return plan;
252
+ }
253
+
254
+ /** Adds nodes to a thread's plan; those waiting on nothing (or only on finished work) start at once. */
255
+ function add(threadId, by, given) {
256
+ const thread = threadOf(threadId);
257
+ if (!thread) return { ok: false, error: "thread not found" };
258
+ if (!Array.isArray(given) || !given.length)
259
+ return { ok: false, error: "no nodes to add" };
260
+ const plan = planOf(thread.id);
261
+ if (plan.length + given.length > MAX_NODES * 4)
262
+ return { ok: false, error: "this thread's plan is full" };
263
+ const keys = new Set();
264
+ const nodes = [];
265
+ for (const [i, node] of given.entries()) {
266
+ const key = words(node?.key) || `n${i + 1}`;
267
+ if (keys.has(key))
268
+ return { ok: false, error: `two nodes are called ${key}` };
269
+ keys.add(key);
270
+ const agent = words(node?.agent);
271
+ if (!roomAgents.includes(agent))
272
+ return {
273
+ ok: false,
274
+ error: `${agent || "no one"} cannot be in a thread`,
275
+ };
276
+ const objective = words(node?.objective || node?.prompt)
277
+ .split("\n")[0]
278
+ .slice(0, 500);
279
+ const brief = words(
280
+ node?.brief ?? (words(node?.prompt).includes("\n") ? node.prompt : "")
281
+ );
282
+ if (!objective) return { ok: false, error: `node ${key} asks nothing` };
283
+ if ((objective + brief).length > PROMPT_LIMIT)
284
+ return {
285
+ ok: false,
286
+ error: `node ${key}'s prompt is over ${PROMPT_LIMIT} characters`,
287
+ };
288
+ nodes.push({
289
+ key,
290
+ agent,
291
+ objective,
292
+ brief,
293
+ after: Array.isArray(node?.after) ? node.after.map(String) : [],
294
+ });
295
+ }
296
+ // What a node may wait on: another node given with it, a node already planned here, or a task in this thread.
297
+ for (const node of nodes)
298
+ for (const ref of node.after) {
299
+ if (keys.has(ref) || plan.some((other) => other.id === ref)) continue;
300
+ const task = store.getTask(ref);
301
+ if (!task || task.parent_id !== thread.id)
302
+ return { ok: false, error: `${ref} is not work in this thread` };
303
+ }
304
+ const order = ordered(nodes, (node) =>
305
+ node.after.filter((ref) => keys.has(ref))
306
+ );
307
+ if (!order) return { ok: false, error: "the wires go round in a loop" };
308
+ const ids = new Map(
309
+ nodes.map((node) => [node.key, `plan_${randomUUID().slice(0, 12)}`])
310
+ );
311
+ const at = new Date().toISOString();
312
+ for (const node of order)
313
+ plan.push({
314
+ id: ids.get(node.key),
315
+ key: node.key,
316
+ by,
317
+ agent: node.agent,
318
+ objective: node.objective,
319
+ brief: node.brief,
320
+ after: node.after.map((ref) => ids.get(ref) ?? ref),
321
+ state: "waiting",
322
+ at,
323
+ });
324
+ savePlan(thread.id, plan);
325
+ const settled = settle(thread.id);
326
+ const mine = settled.filter((node) => [...ids.values()].includes(node.id));
327
+ return {
328
+ ok: true,
329
+ nodes: Object.fromEntries(
330
+ nodes.map((node) => [node.key, ids.get(node.key)])
331
+ ),
332
+ started: mine.filter((node) => node.taskId).map((node) => node.taskId),
333
+ waiting: mine
334
+ .filter((node) => node.state === "waiting")
335
+ .map((node) => node.id),
336
+ blocked: mine
337
+ .filter((node) => node.state === "blocked")
338
+ .map((node) => ({ id: node.id, reason: node.reason })),
339
+ };
340
+ }
341
+
342
+ // ── Templates, kept with the daemon so agents can use them too ────────────────
343
+ const templateFile = (name) => path.join(folder, `${slugOf(name)}.json`);
344
+ function templates() {
345
+ let names = [];
346
+ try {
347
+ names = fs.readdirSync(folder).filter((name) => name.endsWith(".json"));
348
+ } catch {
349
+ return [];
350
+ }
351
+ return names
352
+ .map((name) => {
353
+ const checked = checkTemplate(
354
+ fs.readFileSync(path.join(folder, name), "utf8")
355
+ );
356
+ return checked.ok
357
+ ? {
358
+ name: checked.template.name,
359
+ description: checked.template.description ?? null,
360
+ nodes: checked.template.nodes.length,
361
+ agents: [...new Set(checked.template.nodes.map((n) => n.agent))],
362
+ blanks: checked.blanks,
363
+ }
364
+ : null;
365
+ })
366
+ .filter(Boolean)
367
+ .sort((a, b) => a.name.localeCompare(b.name));
368
+ }
369
+ const templateNamed = (name) => {
370
+ const file = templateFile(name);
371
+ if (!slugOf(name) || !fs.existsSync(file)) return null;
372
+ const checked = checkTemplate(fs.readFileSync(file, "utf8"), {
373
+ agents: roomAgents,
374
+ });
375
+ return checked.ok ? checked : null;
376
+ };
377
+
378
+ /** Puts a template's nodes into a thread, its blanks filled; the nodes with nothing wired into them start now. */
379
+ function fromTemplate(threadId, by, checked, values = {}) {
380
+ const empty = checked.blanks.filter((name) => !words(values[name]));
381
+ if (empty.length)
382
+ return {
383
+ ok: false,
384
+ error: `fill in ${empty.map((name) => `{{${name}}}`).join(", ")} first`,
385
+ blanks: checked.blanks,
386
+ };
387
+ if (checked.missing.length)
388
+ return {
389
+ ok: false,
390
+ error: `this computer's swarm has no ${checked.missing.join(", ")}`,
391
+ };
392
+ return add(
393
+ threadId,
394
+ by,
395
+ checked.template.nodes.map((node) => ({
396
+ key: node.key,
397
+ agent: node.agent,
398
+ prompt: fill(node.prompt, values),
399
+ after: checked.template.wires
400
+ .filter((w) => w.to === node.key)
401
+ .map((w) => w.from),
402
+ }))
403
+ );
404
+ }
405
+
406
+ const personOnly = (agent) =>
407
+ agent === "user"
408
+ ? null
409
+ : { ok: false, error: "only the person can do that" };
410
+
411
+ return {
412
+ /** A thread's plan nodes as the canvas draws them. */
413
+ of: (threadId) =>
414
+ planOf(threadId).map(
415
+ ({
416
+ id,
417
+ key,
418
+ by,
419
+ agent,
420
+ objective,
421
+ after,
422
+ state,
423
+ reason,
424
+ taskId,
425
+ at,
426
+ }) => ({
427
+ id,
428
+ key,
429
+ by,
430
+ agent,
431
+ objective,
432
+ after,
433
+ state,
434
+ reason: reason ?? null,
435
+ taskId: taskId ?? null,
436
+ at,
437
+ })
438
+ ),
439
+ /** A task changed: plans in its thread may move on. */
440
+ changed(task) {
441
+ const threadId = task?.parent_id;
442
+ if (!threadId || !store.meta(`plan:${threadId}`)) return;
443
+ // After the change that called this has finished, not inside it.
444
+ setImmediate(() => {
445
+ try {
446
+ settle(threadId);
447
+ } catch (error) {
448
+ log(`plan settle failed for ${threadId}: ${error.message}`);
449
+ }
450
+ });
451
+ },
452
+ command(request, agent) {
453
+ const command = String(request.command);
454
+ if (command === "board.plan.add")
455
+ return add(request.id, agent, request.nodes);
456
+ if (command === "board.plan.remove") {
457
+ const refused = personOnly(agent);
458
+ if (refused) return refused;
459
+ const plan = planOf(String(request.id || ""));
460
+ const node = plan.find((n) => n.id === String(request.node || ""));
461
+ if (!node) return { ok: false, error: "no such step" };
462
+ if (node.taskId)
463
+ return {
464
+ ok: false,
465
+ error: "that step has started; stop it in the thread",
466
+ };
467
+ const waiting = plan.filter(
468
+ (n) => n.after.includes(node.id) && !n.taskId
469
+ );
470
+ if (waiting.length)
471
+ return {
472
+ ok: false,
473
+ error: "other steps wait for this one; remove them first",
474
+ };
475
+ savePlan(
476
+ String(request.id),
477
+ plan.filter((n) => n.id !== node.id)
478
+ );
479
+ return { ok: true };
480
+ }
481
+ if (command === "board.template.check")
482
+ return checkTemplate(request.template, { agents: roomAgents });
483
+ if (command === "board.template.list")
484
+ return { ok: true, templates: templates() };
485
+ if (command === "board.template.get") {
486
+ const found = templateNamed(String(request.name || ""));
487
+ return found ? found : { ok: false, error: "no template by that name" };
488
+ }
489
+ if (command === "board.template.save") {
490
+ const refused = personOnly(agent);
491
+ if (refused) return refused;
492
+ const checked = checkTemplate(request.template, { agents: roomAgents });
493
+ if (!checked.ok) return checked;
494
+ const name = words(request.name) || checked.template.name;
495
+ if (!slugOf(name))
496
+ return { ok: false, error: "a template needs a name" };
497
+ const template = {
498
+ ...checked.template,
499
+ name: name.slice(0, NAME_LIMIT),
500
+ };
501
+ fs.mkdirSync(folder, { recursive: true });
502
+ fs.writeFileSync(
503
+ templateFile(name),
504
+ JSON.stringify(template, null, 2) + "\n"
505
+ );
506
+ return { ok: true, template, blanks: checked.blanks };
507
+ }
508
+ if (command === "board.template.remove") {
509
+ const refused = personOnly(agent);
510
+ if (refused) return refused;
511
+ const file = templateFile(String(request.name || ""));
512
+ if (!slugOf(String(request.name || "")) || !fs.existsSync(file))
513
+ return { ok: false, error: "no template by that name" };
514
+ fs.rmSync(file);
515
+ return { ok: true };
516
+ }
517
+ if (command === "board.template.use") {
518
+ const checked = request.template
519
+ ? checkTemplate(request.template, { agents: roomAgents })
520
+ : templateNamed(String(request.name || ""));
521
+ if (!checked)
522
+ return {
523
+ ok: false,
524
+ error: "no template by that name",
525
+ templates: templates(),
526
+ };
527
+ if (!checked.ok) return checked;
528
+ return fromTemplate(
529
+ request.id,
530
+ agent,
531
+ checked,
532
+ request.fill && typeof request.fill === "object" ? request.fill : {}
533
+ );
534
+ }
535
+ return { ok: false, error: `unknown command ${command}` };
536
+ },
537
+ };
538
+ }
package/lib/runWorker.mjs CHANGED
@@ -50,18 +50,27 @@ export function createRunWorker({
50
50
  const defaults = standingRules().filter((rule) => rule.mode === "default");
51
51
  if (defaults.length && !store.meta("standing_announced")) {
52
52
  const one = defaults.length === 1;
53
- const text = `${defaults.map((rule) => rule.agent).join(", ")} now ${one ? "starts" : "start"} the tasks you ask for in folders ${one ? "it has" : "they have"} worked in, up to ${defaults[0].daily_cap} a day${one ? "" : " each"}, without a Start. Change it: npx tryharness board standing`;
53
+ const text = `${defaults.map((rule) => nameOf(rule.agent)).join(", ")} now ${one ? "starts" : "start"} the tasks you ask for in folders ${one ? "it has" : "they have"} worked in, up to ${defaults[0].daily_cap} a day${one ? "" : " each"}, without a Start.`;
54
54
  log(text);
55
55
  notifyDesktop(text);
56
56
  store.meta("standing_announced", new Date().toISOString());
57
57
  }
58
58
  // Where a run works, one at a time: its folder, or for a turn T3 Code carries out, its thread (T3 keeps the checkout).
59
+ // A review changes nothing (runner.mjs runs it read-only), so it goes beside whoever writes there: one review per
60
+ // agent per thread, as its session is one (October 19: reviews waited 168 min behind other agents' turns in 3 days).
59
61
  const slotOf = (task) =>
60
- store.meta(`t3-run:${task.id}`) === "1"
61
- ? `t3:${task.parent_id}`
62
- : task.run_workspace
63
- ? path.resolve(task.run_workspace)
64
- : task.target_agent;
62
+ store.meta(`review:${task.id}`) === "1"
63
+ ? `review:${task.target_agent}:${task.parent_id}`
64
+ : store.meta(`t3-run:${task.id}`) === "1"
65
+ ? `t3:${task.parent_id}`
66
+ : task.run_workspace
67
+ ? path.resolve(task.run_workspace)
68
+ : task.target_agent;
69
+ const runsInThread = (agent, threadId) =>
70
+ [...activeRuns.values()].some(
71
+ (held) =>
72
+ held.agent === agent && store.getTask(held.id)?.parent_id === threadId
73
+ );
65
74
  // Lid-Closed Mode holds new runs while the Mac runs warm with the lid closed; running ones go on.
66
75
  let runsHeld = false;
67
76
  // Why work given to an agent in a thread has not started, as the person reads it (the thread's waits, its notes);
@@ -113,6 +122,9 @@ export function createRunWorker({
113
122
  noteWaiting(task, activeRuns.get(slot));
114
123
  continue;
115
124
  }
125
+ // An agent resumes one session per thread: its review waits while its own turn there runs.
126
+ if (slot.startsWith("review:") && runsInThread(agent, task.parent_id))
127
+ continue;
116
128
  const claimed = store.claimTask(task.id, agent, task.version, null);
117
129
  if (!claimed.ok) continue;
118
130
  const started = store.startRun(task.id, agent);
package/lib/runner.mjs CHANGED
@@ -413,7 +413,12 @@ export function readRunSteps(file, limit = 200) {
413
413
 
414
414
  export function runAgentTask(task, emit, observe = () => {}) {
415
415
  // One run per folder: two agents in one checkout would trip over each other; a thread's worktree is its own folder.
416
- const slot = task.cwd ? path.resolve(task.cwd) : task.agent;
416
+ // A read-only review edits nothing, so it goes beside whoever writes there (runWorker.mjs keeps one per agent).
417
+ const slot = task.readOnly
418
+ ? `review:${task.agent}:${task.cwd || ""}`
419
+ : task.cwd
420
+ ? path.resolve(task.cwd)
421
+ : task.agent;
417
422
  if (running.has(slot)) {
418
423
  emit(
419
424
  "failed",
package/lib/store.mjs CHANGED
@@ -1399,6 +1399,17 @@ export function openStore(file) {
1399
1399
  goalId
1400
1400
  );
1401
1401
  },
1402
+ /** One held post with its words, for the person deciding whether it goes into the thread. */
1403
+ heldPost(goalId, id) {
1404
+ return (
1405
+ execute(
1406
+ "get",
1407
+ "select id, seq, author, text, created_at from board_contributions where task_id = ? and id = ? and kind = 'held'",
1408
+ goalId,
1409
+ id
1410
+ ) ?? null
1411
+ );
1412
+ },
1402
1413
  /** The room's contribution just before a post, held ones included. */
1403
1414
  lastContribution(goalId, beforeSeq) {
1404
1415
  return (
@@ -1568,7 +1579,7 @@ export function openStore(file) {
1568
1579
  threadRuns(goalId) {
1569
1580
  return execute(
1570
1581
  "all",
1571
- `select id, kind, objective, origin_agent, target_agent, claimed_by, status, holder, result, session_id, run_workspace, run_authorized_at, usage, run_model, created_at, updated_at, reported_at
1582
+ `select id, kind, objective, origin_agent, target_agent, claimed_by, claimed_at, status, holder, result, failure, session_id, run_workspace, run_authorized_at, usage, run_model, created_at, updated_at, reported_at
1572
1583
  from board_tasks where parent_id = ? and kind in ('wake', 'task') order by created_at asc`,
1573
1584
  goalId
1574
1585
  ).map((row) => ({
@@ -2604,6 +2615,16 @@ export function openStore(file) {
2604
2615
  }));
2605
2616
  },
2606
2617
  // Off the board for good, row kept: unfinished work and its parts close first, so nothing picks them up again.
2618
+ // The open threads an agent is working in right now: its claimed, running or asking work's threads.
2619
+ threadsWorkedIn(agent) {
2620
+ return execute(
2621
+ "all",
2622
+ `select distinct parent.id from board_tasks child join board_tasks parent on parent.id = child.parent_id
2623
+ where child.claimed_by = ? and child.status in ('claimed', 'running', 'needs_input')
2624
+ and parent.kind = 'goal' and parent.status = 'open' and parent.removed_at is null`,
2625
+ agent
2626
+ ).map((row) => row.id);
2627
+ },
2607
2628
  removeTask(id) {
2608
2629
  const now = new Date().toISOString();
2609
2630
  const ids = [