tryharness 0.7.40 → 0.7.42

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/notify.mjs CHANGED
@@ -1,4 +1,5 @@
1
1
  import { spawn } from "node:child_process";
2
+ import { nameOf } from "./members.mjs";
2
3
 
3
4
  // A desktop notification from the daemon, for the person who does not have Harness open:
4
5
  // work that needs them (an agent asks to run something, a question, a stale claim, a request
@@ -72,18 +73,18 @@ export function notificationFor(task, { previous = null } = {}) {
72
73
  !previous.run_authorized_at
73
74
  )
74
75
  ) {
75
- return `${task.origin_agent} wants ${task.target_agent} to run: ${objective}. Authorize with tryharness board run ${String(task.id).slice(0, 8)}`;
76
+ return `${nameOf(task.origin_agent)} wants ${nameOf(task.target_agent)} to start: ${objective}. Start it from the buddy or your phone.`;
76
77
  }
77
78
  if (
78
79
  task.status === "needs_input" &&
79
80
  (task.holder === "user" || task.origin_agent === "user") &&
80
81
  previous?.status !== "needs_input"
81
82
  ) {
82
- return `${task.claimed_by} has a question on: ${objective}`;
83
+ return `${nameOf(task.claimed_by)} asks you about ${objective}: ${String(task.result || "").slice(0, 120)}`;
83
84
  }
84
85
  if (task.status === "unknown" && previous?.status !== "unknown")
85
- return `The outcome of ${task.target_agent}'s run is unknown: ${objective}`;
86
+ return `It is not known how ${nameOf(task.target_agent)}'s run ended: ${objective}`;
86
87
  if (task.status === "open" && task.target_agent === "harness" && !previous)
87
- return `${task.origin_agent} posted for Harness: ${objective}`;
88
+ return `${nameOf(task.origin_agent)} asked Harness: ${objective}`;
88
89
  return null;
89
90
  }
package/lib/onboard.mjs CHANGED
@@ -84,6 +84,7 @@ export async function testAgent({
84
84
  brief:
85
85
  "Harness is checking that it can wake you. Claim this task and report it done with the single word: ready. Do nothing else.",
86
86
  targetAgent: agent,
87
+ check: true,
87
88
  });
88
89
  if (!posted?.ok) {
89
90
  ui.warn(
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 = [
package/lib/swarm.mjs CHANGED
@@ -6,6 +6,7 @@ import { readRunSteps } from "./runner.mjs";
6
6
  import { createSubagents } from "./subagents.mjs";
7
7
  import { nameOf, resolveMember } from "./members.mjs";
8
8
  import { setNote, swarmBlock, swarmCards, swarmDigest } from "./cards.mjs";
9
+ import { askOfRun } from "./threadView.mjs";
9
10
  import {
10
11
  DEFAULT_ROUTING,
11
12
  PICKABLE,
@@ -33,6 +34,8 @@ const SAY_LIMIT = 4_000;
33
34
  // `@swarm` in the person's message: written to their whole swarm, not to one agent.
34
35
  const SWARM = /(^|\s)@swarm\b/;
35
36
  const UUID = /[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}/i;
37
+ // A setup check's own room, from before checks stopped opening one (onboard.mjs): never a thread for the person.
38
+ const SETUP_CHECK = /^Setup check from Harness: reply ready$/;
36
39
 
37
40
  // The id an agent resumes a session by: the index keys sessions by their file name.
38
41
  export function nativeSessionId(agent, sessionId) {
@@ -111,6 +114,8 @@ export function createSwarm({
111
114
  subagents = createSubagents(),
112
115
  // Work wired to wait for other work in the thread (plans.mjs).
113
116
  plansOf = () => [],
117
+ // The thread as the person reads it on every surface (threadView.mjs).
118
+ threadView = null,
114
119
  }) {
115
120
  // What the person let a thread spend of their Harness credits, in dollars, or null for no limit of its own.
116
121
  const ceilingOf = (threadId) => {
@@ -211,9 +216,13 @@ export function createSwarm({
211
216
  const last = posts.at(-1);
212
217
  const live = runs.find((run) => run.status === "running");
213
218
  const step = live ? readRunSteps(runLog(live.id), 1)[0] : null;
219
+ const view = threadView?.row(thread, posts) ?? null;
214
220
  return {
215
221
  id: thread.id,
216
- title: thread.objective,
222
+ title: view?.title ?? thread.objective,
223
+ objective: thread.objective,
224
+ // The same title, state, line and needs-you items on every surface (threadView.mjs).
225
+ view,
217
226
  status: thread.status,
218
227
  agents: agentsOf(thread),
219
228
  coordinator: thread.goal.facilitator,
@@ -356,22 +365,20 @@ export function createSwarm({
356
365
  : [],
357
366
  });
358
367
 
359
- // Who handed a run its work and what they asked: a task names its poster; a wake, whoever woke it (threadRuns.mjs),
360
- // read back from the words it was woken with for wakes from before the asker was kept.
361
- const askOf = (run) => {
362
- if (run.kind !== "wake")
363
- return { askedBy: run.origin_agent, ask: run.objective };
364
- let why = null;
365
- try {
366
- why = JSON.parse(store.meta(`wake-reason:${run.id}`) || "null");
367
- } catch {}
368
- const said = /^(\S+) (?:mentioned|asked) you: ([^]*)$/.exec(
369
- why?.reason ?? ""
368
+ const askOf = (run) => askOfRun(store, run);
369
+ const linkThreads = (from, to, agent) => {
370
+ const note = (goalId, text) =>
371
+ store.roomPost({ goalId, author: "harness", kind: "note", text });
372
+ note(
373
+ from.id,
374
+ `${nameOf(agent)} started a thread for part of this: ${to.objective}`
370
375
  );
371
- return {
372
- askedBy: why?.asker ?? said?.[1] ?? run.origin_agent,
373
- ask: said?.[2] ?? why?.reason ?? run.objective,
374
- };
376
+ note(
377
+ to.id,
378
+ `Started by ${nameOf(agent)} from the thread: ${from.objective}`
379
+ );
380
+ store.meta(`thread-from:${to.id}`, from.id);
381
+ notifyBoard(store.getTask(from.id));
375
382
  };
376
383
 
377
384
  const read = (thread, hostedCaller = false) => {
@@ -403,10 +410,13 @@ export function createSwarm({
403
410
  endedAt: run.reported_at,
404
411
  }),
405
412
  }));
413
+ const posts = store.roomPosts(thread.id, 0, 500);
406
414
  return {
407
415
  ok: true,
408
416
  thread: summary(thread),
409
- posts: store.roomPosts(thread.id, 0, 500),
417
+ posts,
418
+ // The thread in order as the person reads it: messages, steps gathered into groups, files (threadView.mjs).
419
+ timeline: threadView?.timeline(thread, posts) ?? [],
410
420
  // What each of the person's posts changed in what the swarm keeps (lessons.mjs), for the line under the post.
411
421
  kept: store.lessonsFromThread?.(thread.id) ?? [],
412
422
  runs,
@@ -469,7 +479,10 @@ export function createSwarm({
469
479
  };
470
480
  return {
471
481
  ok: true,
472
- threads: store.goals({ all: request.all === true }).map(summary),
482
+ threads: store
483
+ .goals({ all: request.all === true })
484
+ .filter((thread) => !SETUP_CHECK.test(thread.objective))
485
+ .map(summary),
473
486
  sessions: request.sessions === false ? [] : sessions(),
474
487
  agents: roster(),
475
488
  };
@@ -607,6 +620,10 @@ export function createSwarm({
607
620
  maxWakes: defaults.maxWakes,
608
621
  });
609
622
  if (request.hostedCaller) store.meta(`hosted-thread:${thread.id}`, "1");
623
+ // A thread an agent starts from another says so in both, so neither is a dead end for the person.
624
+ const [from] = store.threadsWorkedIn(agent);
625
+ if (from)
626
+ linkThreads(store.getTask(from), store.getTask(thread.id), agent);
610
627
  const first = store.roomPost({
611
628
  goalId: thread.id,
612
629
  author: agent,
@@ -1053,6 +1070,66 @@ export function createSwarm({
1053
1070
  stopThreadRuns(thread.id);
1054
1071
  return { ok: true, thread: summary(store.getTask(thread.id)) };
1055
1072
  }
1073
+ // A post held for the person (it looked like a secret, or like orders to the agents): they read it, then send it into
1074
+ // the thread as its author wrote it or throw it away (owner, October 19: "yes" to Send and Discard). Its words
1075
+ // reach only the person's own sealed surfaces (boardProtocol.json).
1076
+ if (command === "board.swarm.held") {
1077
+ const held = store.heldPost(thread.id, String(request.post || ""));
1078
+ if (!held || store.meta(`held-replaced:${held.id}`))
1079
+ return { ok: false, error: "that post is not held any more" };
1080
+ if (request.action === "show")
1081
+ return { ok: true, author: held.author, text: held.text };
1082
+ const note = (text) =>
1083
+ store.roomPost({
1084
+ goalId: thread.id,
1085
+ author: "user",
1086
+ kind: "note",
1087
+ text,
1088
+ });
1089
+ if (request.action === "discard") {
1090
+ store.meta(`held-replaced:${held.id}`, "discarded");
1091
+ note(`Discarded by you: ${nameOf(held.author)}'s held post.`);
1092
+ } else if (request.action === "send") {
1093
+ const sent = store.roomPost({
1094
+ goalId: thread.id,
1095
+ author: held.author,
1096
+ kind: "post",
1097
+ text: held.text,
1098
+ mentions: mentionsIn(held.text, thread.goal.team),
1099
+ });
1100
+ store.meta(`held-replaced:${held.id}`, sent.id);
1101
+ note(`Sent by you: ${nameOf(held.author)}'s held post.`);
1102
+ if (thread.status === "open") wakeFor(thread.id, sent, held.author);
1103
+ } else return { ok: false, error: "action is show, send or discard" };
1104
+ notifyBoard(store.getTask(thread.id));
1105
+ return { ok: true, thread: summary(store.getTask(thread.id)) };
1106
+ }
1107
+ // The person's Done, or the thread back in their list, kept here so every surface agrees. Accepting work that is
1108
+ // ready for review is Done too, and closes the thread's goal.
1109
+ if (command === "board.swarm.file") {
1110
+ if (!threadView)
1111
+ return { ok: false, error: "this computer cannot file threads" };
1112
+ if (request.accept === true && thread.status === "open") {
1113
+ store.roomPost({
1114
+ goalId: thread.id,
1115
+ author: "user",
1116
+ kind: "note",
1117
+ text: "Accepted by you.",
1118
+ });
1119
+ store.setGoalState(thread.id, {
1120
+ status: "done",
1121
+ result: "Accepted by you.",
1122
+ });
1123
+ }
1124
+ threadView.file(thread.id, request.done !== false);
1125
+ // What Harness's server left for the browser is not taken over once the person says the thread is done.
1126
+ if (request.done !== false)
1127
+ for (const run of store.threadRuns(thread.id))
1128
+ if (run.status === "open" && store.meta(`harness-window:${run.id}`))
1129
+ store.removeTask(run.id);
1130
+ notifyBoard(store.getTask(thread.id));
1131
+ return { ok: true, thread: summary(store.getTask(thread.id)) };
1132
+ }
1056
1133
  // What the thread may spend of the person's Harness credits, set or cleared by the person; a task waiting on the old
1057
1134
  // limit is offered again.
1058
1135
  if (command === "board.swarm.ceiling") {
@@ -4,11 +4,25 @@ import { randomUUID } from "node:crypto";
4
4
  import { readRunSteps, stopAgentTask } from "./runner.mjs";
5
5
  import { provenanceFor } from "./provenance.mjs";
6
6
  import { LOCAL_WAKE_AGENTS } from "./wakes.mjs";
7
- import { aboutOf, member, nameOf, resolveMember } from "./members.mjs";
7
+ import {
8
+ TAGGED_ONLY,
9
+ aboutOf,
10
+ member,
11
+ nameOf,
12
+ resolveMember,
13
+ } from "./members.mjs";
8
14
  import { LIVE_AGENTS, sessionOfProcess } from "./live.mjs";
9
15
  import { swarmBlock, swarmDigest } from "./cards.mjs";
10
16
  import { PICKABLE, resolvePick, setRunPick } from "./models.mjs";
11
17
 
18
+ // An agent working in a thread may bring another agent in for part of the work there, as Harness does when it names
19
+ // one; an agent that moves money or takes positions joins only when the person names it (members.mjs TAGGED_ONLY).
20
+ const joinsThread = (thread, target, roomAgents) =>
21
+ !target ||
22
+ thread.goal.team.includes(String(target)) ||
23
+ (roomAgents.includes(String(target)) &&
24
+ !TAGGED_ONLY.includes(String(target)));
25
+
12
26
  export function createTaskCommands({
13
27
  CLOUD_TARGETS,
14
28
  OPENED,
@@ -48,6 +62,14 @@ export function createTaskCommands({
48
62
  actors,
49
63
  files: boardFiles,
50
64
  }) {
65
+ // The one open thread an agent is working in now, when the work it hands on may join it there.
66
+ const soleThreadOf = (agent, target) => {
67
+ const working = store.threadsWorkedIn(agent);
68
+ const thread = working.length === 1 ? store.getTask(working[0]) : null;
69
+ return thread && joinsThread(thread, target, ROOM_AGENTS)
70
+ ? thread.id
71
+ : null;
72
+ };
51
73
  return (request, { agent, id, expected, lastLooked }) => {
52
74
  let outcome;
53
75
  if (
@@ -129,6 +151,13 @@ export function createTaskCommands({
129
151
  if (!resolved.ok) return { ok: false, error: resolved.error };
130
152
  pick = resolved.pick;
131
153
  }
154
+ // Work an agent hands on while it works in one thread is placed in that thread, not a new one (owner, October 19:
155
+ // "new threads get spun up when the agents hand work off"). It is placed after it is posted, so whether it waits
156
+ // for the person's Start is decided exactly as for work outside any thread: placing it grants nothing.
157
+ const workingThread =
158
+ !request.parentId && !request.thread && agent !== "user"
159
+ ? soleThreadOf(agent, request.targetAgent)
160
+ : null;
132
161
  // Provenance is code's: the local parent's label and what Harness sent from above the poster can only tighten it.
133
162
  const parentTask = request.parentId
134
163
  ? store.getTask(String(request.parentId))
@@ -402,7 +431,9 @@ export function createTaskCommands({
402
431
  : restrictedWait(String(task.target_agent)),
403
432
  }
404
433
  : authority.applyStanding(task);
405
- if (
434
+ // A setup check is never a thread: it is only there to be answered, and goes if it is not (handoffs.mjs).
435
+ if (request.check === true) store.meta(`setup-check:${task.id}`, "1");
436
+ else if (
406
437
  !thread &&
407
438
  !goalParent &&
408
439
  !request.parentId &&
@@ -412,6 +443,7 @@ export function createTaskCommands({
412
443
  )
413
444
  openTaskRoom(store.getTask(task.id), agent, provenance, {
414
445
  hosted: Boolean(request.hostedCaller),
446
+ into: workingThread,
415
447
  });
416
448
  const note = task.target_agent
417
449
  ? actors.setupNote(task.target_agent)