tryharness 0.7.42 → 0.7.44

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.
Files changed (46) hide show
  1. package/cli.mjs +118 -5
  2. package/lib/actorRoster.mjs +16 -2
  3. package/lib/adapters.mjs +2 -1
  4. package/lib/answers.mjs +30 -0
  5. package/lib/boardCommands.mjs +9 -1
  6. package/lib/boardFiles.mjs +1 -1
  7. package/lib/boardProtocol.json +1 -0
  8. package/lib/bridge.mjs +49 -9
  9. package/lib/cards.mjs +22 -4
  10. package/lib/compaction.mjs +90 -0
  11. package/lib/context.mjs +19 -11
  12. package/lib/coordinator.mjs +176 -12
  13. package/lib/daemon.mjs +435 -49
  14. package/lib/fit.mjs +65 -0
  15. package/lib/folders.mjs +20 -0
  16. package/lib/frames.mjs +3 -2
  17. package/lib/goalCommands.mjs +12 -0
  18. package/lib/handover.mjs +128 -0
  19. package/lib/loopBackstop.mjs +104 -0
  20. package/lib/machineIdentity.mjs +43 -0
  21. package/lib/machineRoutes.mjs +97 -0
  22. package/lib/machineRuns.mjs +133 -0
  23. package/lib/machineSeal.mjs +157 -0
  24. package/lib/mcp-stdio.mjs +54 -11
  25. package/lib/nudge.mjs +211 -44
  26. package/lib/oneLine.mjs +27 -0
  27. package/lib/ownMachines.mjs +748 -0
  28. package/lib/paths.mjs +1 -0
  29. package/lib/plans.mjs +3 -2
  30. package/lib/provenance.mjs +4 -1
  31. package/lib/runBrief.mjs +346 -0
  32. package/lib/runWorker.mjs +24 -173
  33. package/lib/runner.mjs +26 -2
  34. package/lib/store.mjs +232 -16
  35. package/lib/stuck.mjs +198 -0
  36. package/lib/swarm.mjs +3 -1
  37. package/lib/taskCommands.mjs +268 -31
  38. package/lib/taskRuns.mjs +9 -0
  39. package/lib/team.json +192 -0
  40. package/lib/team.mjs +417 -0
  41. package/lib/threadRuns.mjs +24 -9
  42. package/lib/threadView.mjs +13 -0
  43. package/lib/trails.mjs +49 -0
  44. package/lib/wakes.mjs +201 -69
  45. package/lib/worktrees.mjs +9 -0
  46. package/package.json +1 -1
package/lib/runner.mjs CHANGED
@@ -118,11 +118,35 @@ const modelFlags = ({ agent, model, effort }) => [
118
118
  ...(effort ? (MODEL_FLAGS[agent]?.effort(effort) ?? []) : []),
119
119
  ];
120
120
 
121
+ // A review or research turn reads and reports. Plan mode kept Claude Code from editing but also refused the Harness
122
+ // tools it reads the thread and posts with (October 20, live run: "plan mode blocks the room tools", the findings left
123
+ // in ~/.claude/plans). Instead: anything not allowed is refused, edits and writes are refused, Harness's tools and
124
+ // reading are allowed, and shell commands run only inside the operating system's sandbox, which the deny rule keeps
125
+ // from writing in the working folder (probed live October 20: Harness's tools answer, node and git run, a write in the
126
+ // folder is refused; denying edits everywhere also broke Claude Code's own scratch files under /tmp).
127
+ export const READ_ONLY_CLAUDE_SETTINGS = {
128
+ permissions: { deny: ["Edit(./**)"] },
129
+ sandbox: {
130
+ enabled: true,
131
+ autoAllowBashIfSandboxed: true,
132
+ allowUnsandboxedCommands: false,
133
+ },
134
+ };
135
+ const readOnlyClaude = () => [
136
+ "--permission-mode",
137
+ "dontAsk",
138
+ "--allowedTools",
139
+ "Read Grep Glob WebSearch WebFetch mcp__harness",
140
+ "--disallowedTools",
141
+ "Edit Write NotebookEdit",
142
+ "--settings",
143
+ JSON.stringify(READ_ONLY_CLAUDE_SETTINGS),
144
+ ];
145
+
121
146
  export function agentInvocation(task) {
122
147
  if (task.agent === "claude-code") {
123
148
  return {
124
149
  command: "claude",
125
- // A review reads and reports: plan mode lets Claude Code read and run read-only tools but never edit.
126
150
  args: [
127
151
  "-p",
128
152
  task.brief,
@@ -132,7 +156,7 @@ export function agentInvocation(task) {
132
156
  ...(task.restricted
133
157
  ? restrictedClaude(task)
134
158
  : task.readOnly
135
- ? ["--permission-mode", "plan"]
159
+ ? readOnlyClaude()
136
160
  : ["--dangerously-skip-permissions"]),
137
161
  "--name",
138
162
  `Harness: ${task.title}`,
package/lib/store.mjs CHANGED
@@ -3,7 +3,7 @@ import sqliteWasm from "node-sqlite3-wasm";
3
3
  import { parseSession } from "./parsers.mjs";
4
4
  import { provenanceFor } from "./provenance.mjs";
5
5
 
6
- const SCHEMA_VERSION = 10;
6
+ const SCHEMA_VERSION = 11;
7
7
  const INDEX_FORMAT_VERSION = 2;
8
8
  const { Database } = sqliteWasm;
9
9
 
@@ -102,6 +102,8 @@ export function openStore(file) {
102
102
  run_model text,
103
103
  removed_at text,
104
104
  failure text,
105
+ target_machine text,
106
+ claimed_machine text,
105
107
  created_at text not null,
106
108
  updated_at text not null
107
109
  );
@@ -188,6 +190,12 @@ export function openStore(file) {
188
190
  public_key text not null,
189
191
  pinned_at text not null
190
192
  );
193
+ create table if not exists own_machines (
194
+ machine_id text primary key,
195
+ public_key text not null,
196
+ pinned_at text not null,
197
+ label text not null default ''
198
+ );
191
199
  create table if not exists swarm_rounds (
192
200
  id integer primary key autoincrement,
193
201
  goal_id text not null,
@@ -230,6 +238,18 @@ export function openStore(file) {
230
238
  updated_at text not null
231
239
  );
232
240
  create virtual table if not exists board_lessons_fts using fts5(id unindexed, text, tokenize='unicode61');
241
+ create table if not exists team_notes (
242
+ id text primary key,
243
+ agent text not null,
244
+ role text,
245
+ folder text,
246
+ thread text,
247
+ text text not null,
248
+ reason text not null,
249
+ status text not null default 'active',
250
+ replaced_by text,
251
+ created_at text not null
252
+ );
233
253
  create table if not exists board_vectors (
234
254
  contribution_id text primary key,
235
255
  version text not null,
@@ -249,6 +269,17 @@ export function openStore(file) {
249
269
  created_at text not null
250
270
  );
251
271
  create index if not exists board_files_task_idx on board_files(task_id, created_at);
272
+ create table if not exists board_wakes (
273
+ id integer primary key autoincrement,
274
+ agent text not null,
275
+ task_id text not null,
276
+ about text,
277
+ holds integer not null,
278
+ outcome text not null,
279
+ detail text,
280
+ at text not null
281
+ );
282
+ create index if not exists board_wakes_agent_idx on board_wakes(agent, id);
252
283
  `);
253
284
  const sessionColumns = new Set(
254
285
  db.all("pragma table_info(sessions)").map((column) => column.name)
@@ -343,6 +374,11 @@ export function openStore(file) {
343
374
  db.exec(
344
375
  "alter table board_tasks add column trust text not null default 'agent'; alter table board_tasks add column origin_chain text not null default '[]'"
345
376
  );
377
+ // Which of the person's computers a task is for and which one took it (machineRoutes.mjs); null is any computer.
378
+ if (!boardColumns.has("target_machine") && boardColumns.size)
379
+ db.exec(
380
+ "alter table board_tasks add column target_machine text; alter table board_tasks add column claimed_machine text"
381
+ );
346
382
 
347
383
  const statements = [];
348
384
  const prepare = (sql) => {
@@ -592,19 +628,21 @@ export function openStore(file) {
592
628
  runWorkspace = null,
593
629
  runAuthorizedBy = null,
594
630
  kind = "task",
631
+ targetMachine = null,
595
632
  }) {
596
633
  const now = new Date().toISOString();
597
634
  execute(
598
635
  "run",
599
636
  `insert into board_tasks(id, objective, brief, origin_agent, target_agent, status, parent_id, context_refs, holder, version, kind,
600
- run_workspace, run_requested_at, run_authorized_by, run_authorized_at, trust, origin_chain, created_at, updated_at)
601
- values(@id, @objective, @brief, @originAgent, @targetAgent, 'open', @parentId, @contextRefs, @targetAgent, 1, @kind, @runWorkspace, @runRequestedAt, @runAuthorizedBy, @runAuthorizedAt, @trust, @chain, @now, @now)`,
637
+ run_workspace, run_requested_at, run_authorized_by, run_authorized_at, trust, origin_chain, target_machine, created_at, updated_at)
638
+ values(@id, @objective, @brief, @originAgent, @targetAgent, 'open', @parentId, @contextRefs, @targetAgent, 1, @kind, @runWorkspace, @runRequestedAt, @runAuthorizedBy, @runAuthorizedAt, @trust, @chain, @targetMachine, @now, @now)`,
602
639
  {
603
640
  id,
604
641
  objective,
605
642
  brief,
606
643
  originAgent,
607
644
  targetAgent,
645
+ targetMachine,
608
646
  parentId,
609
647
  kind,
610
648
  contextRefs: JSON.stringify(contextRefs),
@@ -1089,6 +1127,53 @@ export function openStore(file) {
1089
1127
  }
1090
1128
  return counts;
1091
1129
  },
1130
+ // What an agent learned doing its part on a team (team.mjs), in its own words with its reason, kept for the next
1131
+ // holder of the same role in the same folder. Apart from the person's lessons: an agent's note ranks below them.
1132
+ addTeamNote({
1133
+ agent,
1134
+ role,
1135
+ folder,
1136
+ thread,
1137
+ text,
1138
+ reason,
1139
+ replaces = null,
1140
+ }) {
1141
+ const id = randomUUID();
1142
+ execute(
1143
+ "run",
1144
+ `insert into team_notes(id, agent, role, folder, thread, text, reason, created_at)
1145
+ values(?, ?, ?, ?, ?, ?, ?, ?)`,
1146
+ id,
1147
+ agent,
1148
+ role ?? null,
1149
+ folder ?? null,
1150
+ thread ?? null,
1151
+ text,
1152
+ reason,
1153
+ new Date().toISOString()
1154
+ );
1155
+ // An agent may replace its own note, never another's.
1156
+ if (replaces)
1157
+ execute(
1158
+ "run",
1159
+ "update team_notes set status = 'superseded', replaced_by = ? where id = ? and agent = ? and status = 'active'",
1160
+ id,
1161
+ replaces,
1162
+ agent
1163
+ );
1164
+ return execute("get", "select * from team_notes where id = ?", id);
1165
+ },
1166
+ /** The active notes for a role in a folder, newest first. */
1167
+ teamNotes({ role, folder, limit = 5 }) {
1168
+ return execute(
1169
+ "all",
1170
+ `select * from team_notes where status = 'active' and role is ? and folder is ?
1171
+ order by created_at desc limit ?`,
1172
+ role ?? null,
1173
+ folder ?? null,
1174
+ Math.max(1, Math.min(50, Number(limit) || 5))
1175
+ );
1176
+ },
1092
1177
  // What the swarm learned (lessons.mjs): each lesson with the person's words it stands on (`evidence`: the thread,
1093
1178
  // post and quote), active until a later one replaces it.
1094
1179
  addLesson({ about, agent, text, scope, folder, evidence }) {
@@ -1667,15 +1752,20 @@ export function openStore(file) {
1667
1752
  );
1668
1753
  return written.changes === 1;
1669
1754
  },
1670
- // Tasks the daemon should run now: authorized, still open, for an agent installed here.
1671
- runnableTasks(agents) {
1755
+ // Tasks a computer should run now: authorized, still open, for an agent installed there. `machine`: that computer;
1756
+ // home runs the tasks meant for it and for no computer in particular, a worker (`only`) just those meant for it.
1757
+ runnableTasks(agents, machine = null, { only = false } = {}) {
1672
1758
  if (!agents.length) return [];
1673
1759
  return execute(
1674
1760
  "all",
1675
1761
  `select * from board_tasks where status = 'open' and run_authorized_at is not null and target_agent in (${agents.map(() => "?").join(", ")})
1676
1762
  and id not in (select task_id from board_threads)
1763
+ and (? is null or target_machine = ? or (? = 0 and target_machine is null))
1677
1764
  order by run_authorized_at asc`,
1678
- ...agents
1765
+ ...agents,
1766
+ machine,
1767
+ machine,
1768
+ only ? 1 : 0
1679
1769
  ).map((row) => ({
1680
1770
  ...row,
1681
1771
  version: Number(row.version),
@@ -1756,7 +1846,7 @@ export function openStore(file) {
1756
1846
  const now = new Date().toISOString();
1757
1847
  const written = execute(
1758
1848
  "run",
1759
- `update board_tasks set status = 'open', holder = target_agent, claimed_by = null, claimed_at = null, lease_until = null, updated_at = @now, version = version + 1
1849
+ `update board_tasks set status = 'open', holder = target_agent, claimed_by = null, claimed_machine = null, claimed_at = null, lease_until = null, updated_at = @now, version = version + 1
1760
1850
  where id = @id and status = 'running'`,
1761
1851
  { id, now }
1762
1852
  );
@@ -1990,6 +2080,34 @@ export function openStore(file) {
1990
2080
  "select handle, public_key, pinned_at from relay_peers order by pinned_at desc"
1991
2081
  );
1992
2082
  },
2083
+ // The person's other computers whose keys the join handshake pinned here (machineSeal.mjs): only these may call or
2084
+ // be called through Harness.
2085
+ ownMachine(machineId) {
2086
+ return (
2087
+ execute(
2088
+ "get",
2089
+ "select machine_id, public_key, pinned_at, label from own_machines where machine_id = ?",
2090
+ machineId
2091
+ ) || null
2092
+ );
2093
+ },
2094
+ pinOwnMachine(machineId, publicKey, label = "") {
2095
+ execute(
2096
+ "run",
2097
+ "insert into own_machines(machine_id, public_key, pinned_at, label) values(?, ?, ?, ?) on conflict(machine_id) do update set public_key = excluded.public_key, pinned_at = excluded.pinned_at, label = excluded.label",
2098
+ machineId,
2099
+ publicKey,
2100
+ new Date().toISOString(),
2101
+ label
2102
+ );
2103
+ return this.ownMachine(machineId);
2104
+ },
2105
+ ownMachines() {
2106
+ return execute(
2107
+ "all",
2108
+ "select machine_id, public_key, pinned_at, label from own_machines order by pinned_at"
2109
+ );
2110
+ },
1993
2111
  // Files on a task. A file this machine has is present; one another person's computer is sending is named by its
1994
2112
  // message first or arrives first, and is matched by the id that computer gave it (remote_id), never by ours.
1995
2113
  addFile({ taskId, name, mime, bytes, sha256, author, cloud = false }) {
@@ -2560,6 +2678,81 @@ export function openStore(file) {
2560
2678
  "select agent, last_seen_at from board_agents order by last_seen_at desc"
2561
2679
  );
2562
2680
  },
2681
+ // Wakes sent to an agent's own gateway (wakes.mjs), one row per attempt: `outcome` is sent, refused, unsure (it may
2682
+ // have landed), merged into one already out, or capped. `about` names the result a wake told the agent of.
2683
+ recordWake({ agent, taskId, about = null, holds, outcome, detail = null }) {
2684
+ execute(
2685
+ "run",
2686
+ "insert into board_wakes(agent, task_id, about, holds, outcome, detail, at) values(?, ?, ?, ?, ?, ?, ?)",
2687
+ agent,
2688
+ taskId,
2689
+ about,
2690
+ holds ? 1 : 0,
2691
+ outcome,
2692
+ detail,
2693
+ new Date().toISOString()
2694
+ );
2695
+ },
2696
+ // The agent's attempts since its last wake that went through, oldest first.
2697
+ wakesSinceSent(agent) {
2698
+ return execute(
2699
+ "all",
2700
+ `select task_id, about, holds, outcome, detail, at from board_wakes
2701
+ where agent = ? and id > coalesce((select max(id) from board_wakes where agent = ? and outcome = 'sent'), 0)
2702
+ order by id asc`,
2703
+ agent,
2704
+ agent
2705
+ ).map((row) => ({ ...row, holds: Boolean(row.holds) }));
2706
+ },
2707
+ // Wakes that went out to the agent's gateway since `since` (ISO): sent, refused or maybe landed.
2708
+ wakesTried(agent, since) {
2709
+ return Number(
2710
+ execute(
2711
+ "get",
2712
+ "select count(*) as n from board_wakes where agent = ? and at > ? and outcome in ('sent', 'refused', 'unsure')",
2713
+ agent,
2714
+ since
2715
+ ).n
2716
+ );
2717
+ },
2718
+ wakeTold(agent, about) {
2719
+ return Boolean(
2720
+ execute(
2721
+ "get",
2722
+ "select 1 from board_wakes where agent = ? and about = ? limit 1",
2723
+ agent,
2724
+ about
2725
+ )
2726
+ );
2727
+ },
2728
+ wakeAgents() {
2729
+ return execute("all", "select distinct agent from board_wakes").map(
2730
+ (row) => row.agent
2731
+ );
2732
+ },
2733
+ // Work not finished yet, with the status of the thread it is in (null outside one), for the stuck sweep (stuck.mjs).
2734
+ unfinishedWork() {
2735
+ return execute(
2736
+ "all",
2737
+ `select b.id, b.objective, b.kind, b.status, b.origin_agent, b.target_agent, b.claimed_by, b.holder, b.parent_id,
2738
+ b.run_workspace, b.run_authorized_at, b.lease_until, b.claimed_at, b.reported_at, b.created_at, b.updated_at,
2739
+ case when g.kind = 'goal' then g.status end as thread_status
2740
+ from board_tasks b left join board_tasks g on g.id = b.parent_id
2741
+ where b.kind in ('task', 'wake') and b.removed_at is null and b.status in ('open', 'claimed', 'running', 'needs_input')`
2742
+ );
2743
+ },
2744
+ // When the author last posted in a thread (its own words, files or results), or null. Notes are bookkeeping, not
2745
+ // posts.
2746
+ lastPostAt(goalId, author) {
2747
+ return (
2748
+ execute(
2749
+ "get",
2750
+ "select max(created_at) as at from board_contributions where task_id = ? and author = ? and kind not in ('held', 'note')",
2751
+ goalId,
2752
+ author
2753
+ )?.at ?? null
2754
+ );
2755
+ },
2563
2756
  // Each agent's work on the board, newest first, for its card (cards.mjs): what it holds and finished, and when it
2564
2757
  // could start (the person's Start, else the post) and reported.
2565
2758
  agentWork() {
@@ -2571,7 +2764,7 @@ export function openStore(file) {
2571
2764
  order by updated_at desc limit 5000`
2572
2765
  );
2573
2766
  },
2574
- listTasks({ agent, status, all = false, limit = 20 } = {}) {
2767
+ listTasks({ agent, status, all = false, limit = 20, machine = null } = {}) {
2575
2768
  const clauses = ["b.removed_at is null"];
2576
2769
  const params = { limit: Math.max(1, Math.min(100, Number(limit) || 20)) };
2577
2770
  if (status) {
@@ -2589,12 +2782,19 @@ export function openStore(file) {
2589
2782
  "b.kind not in ('group', 'goal', 'wake') and (b.target_agent is null or b.target_agent = @agent or b.origin_agent = @agent or b.claimed_by = @agent)"
2590
2783
  );
2591
2784
  params.agent = agent;
2785
+ // An agent on one of the person's computers sees the work meant for that computer or any; the person sees all.
2786
+ if (machine && agent !== "user") {
2787
+ clauses.push(
2788
+ "(b.target_machine is null or b.target_machine = @machine or b.claimed_machine = @machine or b.origin_agent = @agent)"
2789
+ );
2790
+ params.machine = machine;
2791
+ }
2592
2792
  }
2593
2793
  const now = new Date().toISOString();
2594
2794
  return execute(
2595
2795
  "all",
2596
2796
  `select b.id, b.objective, b.origin_agent, b.target_agent, b.status, b.parent_id, b.kind, b.claimed_by, b.holder, b.version, b.lease_until,
2597
- b.run_workspace, b.run_authorized_at, b.session_id, b.trust, b.origin_chain, b.created_at, b.updated_at, th.with_agent as thread_with, th.closed_at as thread_closed_at,
2797
+ b.run_workspace, b.run_authorized_at, b.session_id, b.trust, b.origin_chain, b.target_machine, b.claimed_machine, b.created_at, b.updated_at, th.with_agent as thread_with, th.closed_at as thread_closed_at,
2598
2798
  (select count(*) from board_messages m where m.task_id = b.id and m.state in ('held', 'flagged')) as held_messages,
2599
2799
  (select count(*) from board_tasks c where c.parent_id = b.id) as child_count,
2600
2800
  (select count(*) from board_tasks c where c.parent_id = b.id and c.status in ('done', 'failed', 'unknown')) as child_done,
@@ -2693,7 +2893,14 @@ export function openStore(file) {
2693
2893
  )
2694
2894
  );
2695
2895
  },
2696
- claimTask(id, agent, expectedVersion = null, leaseMinutes = 60) {
2896
+ // `machine`: the computer the caller is on; work meant for another computer is not taken here (machineRoutes.mjs).
2897
+ claimTask(
2898
+ id,
2899
+ agent,
2900
+ expectedVersion = null,
2901
+ leaseMinutes = 60,
2902
+ machine = null
2903
+ ) {
2697
2904
  if (this.getTask(id)?.kind === "group")
2698
2905
  return {
2699
2906
  ok: false,
@@ -2717,11 +2924,13 @@ export function openStore(file) {
2717
2924
  ).toISOString();
2718
2925
  const written = execute(
2719
2926
  "run",
2720
- `update board_tasks set status = 'claimed', claimed_by = @agent, holder = @agent, claimed_at = @now, lease_until = @leaseUntil, updated_at = @now, version = version + 1
2721
- where id = @id and status = 'open' and (holder is null or holder = @agent) and (@expected is null or version = @expected)`,
2927
+ `update board_tasks set status = 'claimed', claimed_by = @agent, holder = @agent, claimed_machine = @machine, claimed_at = @now, lease_until = @leaseUntil, updated_at = @now, version = version + 1
2928
+ where id = @id and status = 'open' and (holder is null or holder = @agent) and (@expected is null or version = @expected)
2929
+ and (@machine is null or target_machine is null or target_machine = @machine)`,
2722
2930
  {
2723
2931
  id,
2724
2932
  agent,
2933
+ machine,
2725
2934
  now,
2726
2935
  leaseUntil,
2727
2936
  expected: expectedVersion == null ? null : Number(expectedVersion),
@@ -2731,14 +2940,17 @@ export function openStore(file) {
2731
2940
  return conflict(this.getTask(id), agent, expectedVersion, (task) =>
2732
2941
  task.status !== "open"
2733
2942
  ? `task is ${task.status}${task.claimed_by ? ` by ${task.claimed_by}` : ""}`
2734
- : `task is for ${task.holder}`
2943
+ : machine && task.target_machine && task.target_machine !== machine
2944
+ ? `task is for ${task.holder} on another computer`
2945
+ : `task is for ${task.holder}`
2735
2946
  );
2736
2947
  },
2737
2948
  reportTask(
2738
2949
  id,
2739
2950
  agent,
2740
2951
  { status, result = "", failure = "agent" },
2741
- expectedVersion = null
2952
+ expectedVersion = null,
2953
+ machine = null
2742
2954
  ) {
2743
2955
  if (!["done", "failed", "needs_input"].includes(status))
2744
2956
  return {
@@ -2751,10 +2963,12 @@ export function openStore(file) {
2751
2963
  `update board_tasks set status = @status, result = @result, reported_at = @now, updated_at = @now, version = version + 1,
2752
2964
  holder = case when @status = 'needs_input' then origin_agent else null end,
2753
2965
  failure = case when @status = 'failed' then @failure else null end
2754
- where id = @id and status in ('claimed', 'running') and holder = @agent and (@expected is null or version = @expected)`,
2966
+ where id = @id and status in ('claimed', 'running') and holder = @agent and (@expected is null or version = @expected)
2967
+ and (@machine is null or claimed_machine is null or claimed_machine = @machine)`,
2755
2968
  {
2756
2969
  id,
2757
2970
  agent,
2971
+ machine,
2758
2972
  status,
2759
2973
  result,
2760
2974
  failure: FAILURE_CAUSES.includes(failure) ? failure : "agent",
@@ -2774,7 +2988,9 @@ export function openStore(file) {
2774
2988
  }
2775
2989
  return conflict(this.getTask(id), agent, expectedVersion, (task) =>
2776
2990
  ["claimed", "running"].includes(task.status)
2777
- ? `task is held by ${task.holder}`
2991
+ ? machine && task.claimed_machine && task.claimed_machine !== machine
2992
+ ? `task is held by ${task.holder} on another computer`
2993
+ : `task is held by ${task.holder}`
2778
2994
  : task.status === "open"
2779
2995
  ? "claim the task before reporting on it"
2780
2996
  : `task is ${task.status}`
package/lib/stuck.mjs ADDED
@@ -0,0 +1,198 @@
1
+ import { nameOf } from "./members.mjs";
2
+ import { isSetupCheck } from "./handoffs.mjs";
3
+
4
+ // Work that stopped moving, found from what the board keeps: work nobody picked up, a claim past its lease, a question
5
+ // nobody answered, a run with no new step, and work an agent still holds after its turn in the thread ended. Each finding
6
+ // is kept per task and kind (board meta `stuck-findings`), reported once, and let go when the condition goes away, so a
7
+ // restart neither repeats one nor forgets it. Only the agents' own posts and status changes count as the work moving;
8
+ // Harness's notes never do. The daemon runs the sweep on board changes and on a timer, and says each finding where it
9
+ // belongs (daemon.mjs): in the thread and to its coordinator, or to whoever posted loose work.
10
+ //
11
+ // The thresholds, from the owner's board on October 20 (a read-only copy; 60 threads, 373 tasks and wakes):
12
+ // - Pickup (claimMs, droppedMs): 367 pickups, from posting (or the person's Start) to claim: p50 0, p90 3.4, p95 11.2,
13
+ // p99 224 min. The tail is the stuck kind this sweep is for: Grok Bot's 242 and 251 min and 13.9 days, Harness
14
+ // waiting for a window up to 9.2 h. Every pickup of work Harness starts itself (277, queueing for a busy folder
15
+ // included) came within 27.7 min (p99 17.1). 30 min is past all of those and 2.7 times the board's p95. Work an
16
+ // agent still holds once its turn ended waits to be picked up again, so it gets the same 30 min.
17
+ // - Steps (stepMs): 52 runs whose sessions record each step's time, 1,578 waits between steps: the first step came
18
+ // within 0.6 min; the longest wait in a run was p95 9.6, p99 10.9, at most 11.9 min. 30 min is 2.5 times the
19
+ // longest. Turns run in T3 Code keep their steps' times in T3, not in a session file here, and are not in the sample.
20
+ // - Answers: 24 questions the person answered: p50 7.8, p90 238, p95 267 min, at most 650 min (two never answered).
21
+ // personAnswerMs is 6 h, past the p95. The board has one question an agent asked another (Codex of Harness, October
22
+ // 19), never answered, so there is no answer time to measure: an agent answering is the agent picking work up again,
23
+ // and gets the pickup's 30 min (agentAnswerMs).
24
+ // A claim past its lease uses the lease the agent took (60 min unless it said otherwise).
25
+ export const STUCK_THRESHOLDS = {
26
+ claimMs: 30 * 60_000,
27
+ stepMs: 30 * 60_000,
28
+ agentAnswerMs: 30 * 60_000,
29
+ personAnswerMs: 6 * 60 * 60_000,
30
+ droppedMs: 30 * 60_000,
31
+ };
32
+ const FINDINGS_KEY = "stuck-findings";
33
+ const ASKED_PREFIX = /^Asked in "[^"]*": /;
34
+
35
+ const minutes = (ms) => Math.max(1, Math.round(ms / 60_000));
36
+ const latest = (times) =>
37
+ times.filter(Boolean).reduce((a, b) => (a > b ? a : b), null);
38
+
39
+ /** What a finding says, in the thread or to whoever posted the work. */
40
+ function lineFor({ kind, task, agent, since }, at) {
41
+ const who = nameOf(agent);
42
+ const waited = minutes(at - Date.parse(since));
43
+ const turn = task.kind === "wake";
44
+ const quoted = `"${String(task.objective).replace(ASKED_PREFIX, "").slice(0, 80)}"`;
45
+ if (kind === "unclaimed")
46
+ return turn
47
+ ? `${who} hasn't started its turn here after ${waited} min.`
48
+ : `${who} hasn't picked up ${quoted} after ${waited} min.`;
49
+ if (kind === "no_step")
50
+ return `${who}'s turn${turn ? " here" : ` on ${quoted}`} has shown no new step for ${waited} min.`;
51
+ if (kind === "lease")
52
+ return `${who} took ${quoted} and stopped checking in ${waited} min ago.`;
53
+ if (kind === "unanswered")
54
+ return `${quoted} has waited ${waited} min for ${agent === "user" ? "your answer" : `${who}'s answer`}.`;
55
+ return `${who}'s turn ended ${waited} min ago while it still holds ${quoted}.`;
56
+ }
57
+
58
+ /**
59
+ * `lastStepAt(taskId)`: when a run last took a step (its run record), or null. `report(finding)` says a new finding:
60
+ * { key, kind, agent, since, task, thread (null outside one), text }.
61
+ */
62
+ export function createStuck({
63
+ store,
64
+ lastStepAt,
65
+ report,
66
+ log = () => {},
67
+ thresholds = STUCK_THRESHOLDS,
68
+ now = Date.now,
69
+ }) {
70
+ const kept = () => {
71
+ try {
72
+ return JSON.parse(store.meta(FINDINGS_KEY) || "{}");
73
+ } catch {
74
+ return {};
75
+ }
76
+ };
77
+ const waited = (since, limit, at) =>
78
+ Boolean(since) && at - Date.parse(since) >= limit;
79
+
80
+ // When an agent's turn in the thread ended while it held this task, and it has said nothing since: the time it last
81
+ // ended a task or posted there. Null while it still works there, or when no turn of its ended since it took the task.
82
+ const quietSince = (task, threadId) => {
83
+ const agent = task.claimed_by;
84
+ const its = store
85
+ .threadRuns(threadId)
86
+ .filter(
87
+ (run) =>
88
+ run.id !== task.id && (run.claimed_by ?? run.target_agent) === agent
89
+ );
90
+ const working = its.some(
91
+ (run) =>
92
+ run.status === "running" ||
93
+ (run.kind === "wake" && ["open", "claimed"].includes(run.status))
94
+ );
95
+ if (working) return null;
96
+ const ended = its
97
+ .map((run) => run.reported_at)
98
+ .filter((at) => at && at > task.claimed_at);
99
+ if (!ended.length) return null;
100
+ return latest([...ended, store.lastPostAt(threadId, agent)]);
101
+ };
102
+
103
+ const findingFor = (task, at) => {
104
+ const thread = task.thread_status ? task.parent_id : null;
105
+ if (thread && task.thread_status !== "open") return null;
106
+ if (task.status === "open") {
107
+ const waitsForPerson = task.run_workspace && !task.run_authorized_at;
108
+ // Harness's part waiting for a window: the thread already says why, as long as it waits.
109
+ const toldWait = store.meta(`harness-wait:${task.id}`);
110
+ if (
111
+ !task.target_agent ||
112
+ waitsForPerson ||
113
+ toldWait ||
114
+ isSetupCheck(store, task)
115
+ )
116
+ return null;
117
+ return waited(task.updated_at, thresholds.claimMs, at)
118
+ ? {
119
+ kind: "unclaimed",
120
+ agent: task.target_agent,
121
+ since: task.updated_at,
122
+ }
123
+ : null;
124
+ }
125
+ if (task.status === "running") {
126
+ const last = lastStepAt(task.id) ?? task.claimed_at ?? task.updated_at;
127
+ return waited(last, thresholds.stepMs, at)
128
+ ? { kind: "no_step", agent: task.claimed_by, since: last }
129
+ : null;
130
+ }
131
+ if (task.status === "needs_input") {
132
+ const limit =
133
+ task.holder === "user"
134
+ ? thresholds.personAnswerMs
135
+ : thresholds.agentAnswerMs;
136
+ return waited(task.reported_at, limit, at)
137
+ ? { kind: "unanswered", agent: task.holder, since: task.reported_at }
138
+ : null;
139
+ }
140
+ const quiet = thread ? quietSince(task, thread) : null;
141
+ if (waited(quiet, thresholds.droppedMs, at))
142
+ return { kind: "dropped", agent: task.claimed_by, since: quiet };
143
+ const leaseOver =
144
+ !quiet &&
145
+ task.lease_until &&
146
+ task.lease_until < new Date(at).toISOString();
147
+ return leaseOver
148
+ ? { kind: "lease", agent: task.claimed_by, since: task.lease_until }
149
+ : null;
150
+ };
151
+
152
+ /** Finds what is stuck now: reports each new finding once and lets go of those that cleared. */
153
+ const sweep = () => {
154
+ const at = now();
155
+ const before = kept();
156
+ const found = {};
157
+ const fresh = [];
158
+ for (const task of store.unfinishedWork()) {
159
+ const finding = findingFor(task, at);
160
+ if (!finding) continue;
161
+ const key = `${task.id}:${finding.kind}`;
162
+ const thread = task.thread_status ? task.parent_id : null;
163
+ found[key] = before[key] ?? {
164
+ kind: finding.kind,
165
+ taskId: task.id,
166
+ agent: finding.agent,
167
+ thread,
168
+ at: new Date(at).toISOString(),
169
+ };
170
+ if (!before[key])
171
+ fresh.push({
172
+ key,
173
+ ...finding,
174
+ task,
175
+ thread,
176
+ text: lineFor({ ...finding, task }, at),
177
+ });
178
+ }
179
+ const cleared = Object.keys(before).filter((key) => !found[key]);
180
+ // Kept before it is said, so the board change a report makes finds it already reported.
181
+ if (fresh.length || cleared.length)
182
+ store.meta(FINDINGS_KEY, JSON.stringify(found));
183
+ for (const key of cleared) log(`stuck: cleared ${key}`);
184
+ for (const finding of fresh) {
185
+ log(`stuck: ${finding.key}`);
186
+ report(finding);
187
+ }
188
+ return { reported: fresh.map((f) => f.key), cleared };
189
+ };
190
+
191
+ /** The findings open now, in one thread or on the whole board. */
192
+ const open = (threadId = null) =>
193
+ Object.entries(kept())
194
+ .filter(([, finding]) => !threadId || finding.thread === threadId)
195
+ .map(([key, finding]) => ({ key, ...finding }));
196
+
197
+ return { sweep, open };
198
+ }
package/lib/swarm.mjs CHANGED
@@ -96,6 +96,8 @@ export function createSwarm({
96
96
  coordinator,
97
97
  worktrees,
98
98
  roster,
99
+ // Which of the person's computers each coding agent is on (actorRoster.mjs), when there are several.
100
+ withMachines = (card) => card,
99
101
  authorizeRun,
100
102
  pickable,
101
103
  listModels,
@@ -525,7 +527,7 @@ export function createSwarm({
525
527
  store,
526
528
  roster().filter((entry) => entry.id !== agent),
527
529
  { lessons: local }
528
- );
530
+ ).map(withMachines);
529
531
  const told = local ? (lessons?.told() ?? []) : [];
530
532
  return {
531
533
  ok: true,