tryharness 0.7.78 → 0.7.82

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 (63) hide show
  1. package/README.md +4 -3
  2. package/assets/install.sh +104 -0
  3. package/cli.mjs +203 -321
  4. package/lib/adapters.mjs +7 -6
  5. package/lib/agentRuntimes.mjs +2 -1
  6. package/lib/backupSetup.mjs +0 -52
  7. package/lib/boardProtocol.json +21 -1
  8. package/lib/browserPage.mjs +30 -0
  9. package/lib/coordinator.mjs +0 -2
  10. package/lib/daemon.mjs +117 -7
  11. package/lib/desktop.mjs +7 -1
  12. package/lib/dispatcher.mjs +12 -2
  13. package/lib/environments.mjs +4 -11
  14. package/lib/goalCommands.mjs +18 -8
  15. package/lib/hookDialects.mjs +2 -1
  16. package/lib/jobAnswers.mjs +2 -1
  17. package/lib/kanban.mjs +217 -48
  18. package/lib/localStack.mjs +24 -9
  19. package/lib/machineRoutes.mjs +9 -0
  20. package/lib/machineRuns.mjs +9 -1
  21. package/lib/manager.mjs +60 -2
  22. package/lib/mcp-stdio.mjs +9 -3
  23. package/lib/museSession.mjs +2 -1
  24. package/lib/nativeHost.mjs +11 -2
  25. package/lib/network.mjs +20 -0
  26. package/lib/notify.mjs +48 -16
  27. package/lib/onboard.mjs +71 -366
  28. package/lib/ownMachines.mjs +95 -44
  29. package/lib/pairing.mjs +0 -84
  30. package/lib/paths.mjs +17 -0
  31. package/lib/peopleBoard.mjs +131 -0
  32. package/lib/personNotices.mjs +9 -25
  33. package/lib/phones.mjs +1 -0
  34. package/lib/profile.mjs +0 -109
  35. package/lib/projectBoard.mjs +219 -0
  36. package/lib/projectPieces.mjs +26 -0
  37. package/lib/projects.mjs +37 -4
  38. package/lib/removeHarness.mjs +91 -0
  39. package/lib/roomChannels.mjs +2 -0
  40. package/lib/runAuthority.mjs +23 -9
  41. package/lib/runBrief.mjs +20 -14
  42. package/lib/runner.mjs +3 -3
  43. package/lib/runtime-install.mjs +22 -2
  44. package/lib/screen.mjs +133 -0
  45. package/lib/selfUpdate.mjs +6 -6
  46. package/lib/service.mjs +120 -7
  47. package/lib/sessionControl.mjs +10 -0
  48. package/lib/setupChoices.mjs +400 -0
  49. package/lib/setupMode.mjs +137 -0
  50. package/lib/store.mjs +6 -3
  51. package/lib/swarm.mjs +181 -61
  52. package/lib/t3.mjs +23 -14
  53. package/lib/taskCommands.mjs +25 -15
  54. package/lib/taskRooms.mjs +2 -4
  55. package/lib/threadActions.mjs +16 -4
  56. package/lib/threadAuthority.mjs +28 -10
  57. package/lib/threadRuns.mjs +162 -74
  58. package/lib/toolCheck.mjs +136 -0
  59. package/lib/ui.mjs +15 -1
  60. package/lib/wakes.mjs +3 -3
  61. package/npm-shrinkwrap.json +14 -14
  62. package/package.json +4 -4
  63. package/release.json +64 -55
@@ -55,40 +55,58 @@ export function createThreadAuthority({
55
55
  const readAsOrders = (guard) => guard?.verdict === "hold";
56
56
 
57
57
  // Whose asks carry the person's go on the guard's reading: the person's agents whose words come through Harness's
58
- // server, Harness's own among them while their window is closed.
59
- const readByGuard = (asker, hosted) =>
60
- fromElsewhere(asker) || (hosted && speaksThroughHarness(asker));
58
+ // server, Harness's own among them while their window is closed, and any of their agents on a cloud computer Harness
59
+ // runs for them (`cloud`).
60
+ const readByGuard = (asker, hosted, cloud = false) =>
61
+ fromElsewhere(asker) || cloud || (hosted && speaksThroughHarness(asker));
61
62
 
62
63
  // Whose asks carry the person's go as they are: the person's own agents whose words reached this computer from the
63
64
  // person's own computers or device, not through Harness's server. Read the same for every agent (owner, November 1:
64
- // "@harness is just another agent").
65
+ // "@harness is just another agent"), and the same from every computer the person drives (owner, November 2: agents
66
+ // handing work on should be seamless wherever they run).
65
67
  const fromPersonsSide = (asker, hosted) =>
66
68
  !hosted && speaksFromPersonsSide(asker);
67
69
 
68
- /** Whether `asker`'s request for `agent` carries the person's go. `hosted`: the request came through Harness. */
70
+ /**
71
+ * Whether `asker`'s request for `agent` carries the person's go. `hosted`: the request came through Harness, or from
72
+ * a cloud computer (`cloud`), whose words the guard reads.
73
+ */
69
74
  // A coding agent here asking from a restricted run or a review carries no go: that run had none to pass on.
70
75
  // `window`: Harness's call as a linked window sealed it (phones.mjs fromWindow). The page that window runs is served
71
76
  // by Harness, so its word for Harness is never the person's go, whatever it names.
72
77
  const personsGo = (
73
78
  asker,
74
79
  agent,
75
- { hosted = false, guard = null, limited = null, window = false } = {}
80
+ {
81
+ hosted = false,
82
+ cloud = false,
83
+ guard = null,
84
+ limited = null,
85
+ window = false,
86
+ } = {}
76
87
  ) =>
77
88
  asker === "user" ||
78
89
  (!window &&
79
90
  !readAsOrders(guard) &&
80
91
  // The dispatcher hands on the person's own work; every agent is read by where its words came from.
81
92
  ((asker === DISPATCHER && !hosted && !limited) ||
82
- (!limited && fromPersonsSide(asker, hosted)) ||
83
- (readByGuard(asker, hosted) && guardPasses(guard))) &&
93
+ (!limited && fromPersonsSide(asker, hosted || cloud)) ||
94
+ (!limited &&
95
+ readByGuard(asker, hosted, cloud) &&
96
+ guardPasses(guard))) &&
84
97
  !setToWait(agent));
85
98
 
86
99
  /** What the thread says when the guard keeps an agent's request from carrying the person's go; null otherwise. */
87
- const guardWait = (asker, agent, guard, { hosted = false } = {}) => {
100
+ const guardWait = (
101
+ asker,
102
+ agent,
103
+ guard,
104
+ { hosted = false, cloud = false } = {}
105
+ ) => {
88
106
  if (asker === "user" || setToWait(agent)) return null;
89
107
  if (readAsOrders(guard))
90
108
  return `The guard read ${nameOf(asker)}'s words as orders aimed at your agents, so ${nameOf(agent)} waits for your Start. Read them before you start it.`;
91
- if (!readByGuard(asker, hosted) || guardPasses(guard)) return null;
109
+ if (!readByGuard(asker, hosted, cloud) || guardPasses(guard)) return null;
92
110
  return `The guard that reads ${nameOf(asker)}'s words for planted instructions is not running on this computer, so ${nameOf(agent)} waits for your Start.`;
93
111
  };
94
112
 
@@ -56,6 +56,13 @@ export function createThreadRuns({
56
56
  checkBeforeStart = async () => true,
57
57
  }) {
58
58
  const { RUNNERS } = authority;
59
+ const folderAway = (goalId) => {
60
+ try {
61
+ return JSON.parse(store.meta(`thread-folder-on:${goalId}`) || "null");
62
+ } catch {
63
+ return null;
64
+ }
65
+ };
59
66
  const computerOf = (goalId) => {
60
67
  const held = store.meta(`thread-work-computer:${goalId}`);
61
68
  if (held) return held;
@@ -218,6 +225,40 @@ export function createThreadRuns({
218
225
  store.meta("pending-wake:" + key, "");
219
226
  },
220
227
  };
228
+ // The computer a run is on, by id: the one that took it, else the one it waits for, else this one.
229
+ const computerOfRun = (run) =>
230
+ run.claimed_machine ?? run.target_machine ?? computers?.self() ?? null;
231
+ // An agent's turns in a thread: one for each computer the person named (a lane), and one for words that named none.
232
+ const laneKey = (goalId, agent, lane = null) =>
233
+ lane ? `${goalId}:${agent}@${lane}` : `${goalId}:${agent}`;
234
+ const OPEN_WAKE = new Set(["open", "claimed", "running"]);
235
+ const openWakesOf = (goalId, agent) =>
236
+ store
237
+ .threadRuns(goalId)
238
+ .filter(
239
+ (run) =>
240
+ run.kind === "wake" &&
241
+ run.target_agent === agent &&
242
+ OPEN_WAKE.has(run.status)
243
+ );
244
+ // The agent's open turn in a lane: on that computer, else any.
245
+ const openWakeIn = (goalId, agent, lane = null) =>
246
+ lane
247
+ ? (openWakesOf(goalId, agent).find((run) => computerOfRun(run) === lane)
248
+ ?.id ?? null)
249
+ : store.openWake(goalId, agent);
250
+ // Every lane words for the agent may wait in: none, and each computer a turn of its here was placed on.
251
+ const laneKeys = (goalId, agent) => [
252
+ laneKey(goalId, agent),
253
+ ...new Set(
254
+ store
255
+ .threadRuns(goalId)
256
+ .filter((run) => run.target_agent === agent)
257
+ .map((run) => store.meta(`lane:${run.id}`))
258
+ .filter(Boolean)
259
+ .map((lane) => laneKey(goalId, agent, lane))
260
+ ),
261
+ ];
221
262
  // Turns waiting for the computer the person named to come back: { goalId, agent, reason, options, at }, kept on the
222
263
  // board so a restart keeps them.
223
264
  const COMPUTER_WAITS = "computer-waits";
@@ -298,7 +339,7 @@ export function createThreadRuns({
298
339
  // `only`: one agent's waiting turns, as when its piece of a shared project is released.
299
340
  const discard = (goalId, only = null) => {
300
341
  for (const agent of only ? [only] : RUNNERS)
301
- pendingWakes.delete(goalId + ":" + agent);
342
+ for (const key of laneKeys(goalId, agent)) pendingWakes.delete(key);
302
343
  };
303
344
  // go: the person's go for this turn (personsGo), their own post naming this agent or one of their agents here asking;
304
345
  // any other wake is work another agent asked for and runs restricted or waits.
@@ -311,11 +352,17 @@ export function createThreadRuns({
311
352
  // where it is and the wake kept for the words goes on from there, in the same session. Without their go it reads
312
353
  // them when its turn ends. The thread says which happened; the note is also what the steer's caller is told.
313
354
  const steers = new Map();
314
- const steerRunning = (goalId, agent, words, pending) => {
355
+ // `key`: the lane the words wait in (laneKey). Words naming a computer steer only the turn on it.
356
+ const steerRunning = (goalId, agent, words, pending, key) => {
315
357
  // The agent's turn that does the work, before a read-only review of its own beside it.
316
358
  const running = store
317
359
  .threadRuns(goalId)
318
- .filter((run) => run.target_agent === agent && run.status === "running")
360
+ .filter(
361
+ (run) =>
362
+ run.target_agent === agent &&
363
+ run.status === "running" &&
364
+ (!pending.on || computerOfRun(run) === pending.on)
365
+ )
319
366
  .sort(
320
367
  (a, b) =>
321
368
  Number(store.meta(`review:${a.id}`) === "1") -
@@ -330,16 +377,16 @@ export function createThreadRuns({
330
377
  };
331
378
  const told =
332
379
  store.meta(`t3-run:${running.id}`) === "1"
333
- ? steerT3(goalId, agent, words, pending, running).then(note)
380
+ ? steerT3(goalId, agent, words, pending, running, key).then(note)
334
381
  : Promise.resolve(note(stopToSteer(running, pending, who)));
335
382
  // Kept only until the call that sent the words reads it, which it does as it sends them (board.swarm.steer).
336
- const key = `${goalId}:${agent}`;
337
- steers.set(key, told);
383
+ const toldKey = `${goalId}:${agent}`;
384
+ steers.set(toldKey, told);
338
385
  void told.then(() => {
339
- if (steers.get(key) === told) steers.delete(key);
386
+ if (steers.get(toldKey) === told) steers.delete(toldKey);
340
387
  });
341
388
  };
342
- const steerT3 = async (goalId, agent, words, pending, running) => {
389
+ const steerT3 = async (goalId, agent, words, pending, running, key) => {
343
390
  const who = nameOf(agent);
344
391
  const thread = store.getTask(goalId);
345
392
  const delivery = await steerT3Run(
@@ -348,8 +395,7 @@ export function createThreadRuns({
348
395
  );
349
396
  if (!delivery)
350
397
  return `${who} reads your message when its current turn ends.`;
351
- if (pendingWakes.get(`${goalId}:${agent}`)?.id === pending.id)
352
- pendingWakes.delete(`${goalId}:${agent}`);
398
+ if (pendingWakes.get(key)?.id === pending.id) pendingWakes.delete(key);
353
399
  return delivery === "restarted"
354
400
  ? `${who} restarted its turn to take your message.`
355
401
  : `${who} has your message and reads it at its next step.`;
@@ -395,10 +441,10 @@ export function createThreadRuns({
395
441
  // The person's go reaches a turn another agent's ask left waiting for their Start, so it starts now rather than
396
442
  // after a turn that would never come (Grok Bot's mention once held Claude Code in the person's own folder, and
397
443
  // their @claude-code queued behind it). The pending call stays, so the turn's brief carries the person's words.
398
- const startHeldWake = (goalId, agent) => {
399
- const wake = store.getTask(store.openWake(goalId, agent));
444
+ const startHeldWake = (goalId, agent, lane = null) => {
445
+ const wake = store.getTask(openWakeIn(goalId, agent, lane));
400
446
  if (wake?.status !== "open" || wake.run_authorized_at) return;
401
- const pending = pendingWakes.get(`${goalId}:${agent}`);
447
+ const pending = pendingWakes.get(laneKey(goalId, agent, lane));
402
448
  const answer = Boolean(pending?.answer);
403
449
  const directlyAsked = pending?.asker === "user" && pending.go;
404
450
  if (!directlyAsked && !threadMayRun(store.getTask(goalId), { answer }))
@@ -598,27 +644,51 @@ export function createThreadRuns({
598
644
  : null);
599
645
  if (!installedAgents.includes(agent) && !elsewhere) return;
600
646
  const goal = task.goal;
601
- // A thread with no folder works in its own scratch folder on whichever computer takes the turn (scratch.mjs).
602
- const scratch = !goal.workspace;
603
- // A turn waiting for its Start on another computer than the one chosen now is taken back and placed again, so the
604
- // choice is not folded into a turn that would run elsewhere (a hosted agent's thread queued Claude Code on Home
605
- // before its ask named pop-os). One already started or let start keeps going; the call waits for it, still pinned.
606
- const waiting =
607
- on && chosen ? store.getTask(store.openWake(goalId, agent)) : null;
608
- if (
609
- waiting &&
610
- (waiting.target_machine ?? self) !== named &&
611
- waiting.status === "open" &&
612
- !waiting.claimed_by &&
613
- !waiting.run_authorized_at
614
- ) {
615
- store.removeTask(waiting.id);
616
- notifyBoard(store.getTask(waiting.id));
647
+ // A thread whose folder is on another computer (swarm.mjs setFolderAway) works there in it.
648
+ const away = folderAway(goalId);
649
+ const awayFolder =
650
+ away && elsewhere?.machine === away.machine ? away.path : null;
651
+ // A thread with no folder works in its own scratch folder on whichever computer takes the turn (scratch.mjs), as
652
+ // does a turn on a computer with no copy of the thread's folder.
653
+ const scratch =
654
+ !awayFolder &&
655
+ (!goal.workspace || Boolean(elsewhere && !elsewhere.folder));
656
+ if (scratch && (goal.workspace || away)) {
657
+ const where = elsewhere?.machine ?? computers?.self() ?? "here";
658
+ const label = computers?.labelOf(where) ?? "this computer";
659
+ noteOnce(
660
+ `scratch-fallback:${goalId}:${agent}:${where}`,
661
+ goal.workspace
662
+ ? `${nameOf(agent)} works on ${label} in a scratch folder: ${label} has no copy of ${goal.workspace}.`
663
+ : `${nameOf(agent)} works on ${label} in a scratch folder: the thread's folder is on ${computers?.labelOf(away.machine) ?? "another computer"}.`
664
+ );
617
665
  }
618
- if (store.openWake(goalId, agent)) {
666
+ // The computer the person named for this call is its lane: the agent's turn there, beside its turns on other
667
+ // computers, never folded into one of them (a "#pop-os" message once stopped Claude Code's video edit on the Mac,
668
+ // then waited for it to end, November 2).
669
+ const lane = on && chosen ? named : null;
670
+ // A turn waiting for its Start on another computer than the one chosen now, for a call that named none, is taken back
671
+ // and placed again, so the choice is not folded into a turn that would run elsewhere (a hosted agent's thread queued
672
+ // Claude Code on Home before its ask named pop-os). One already started or let start keeps going in its own lane, as
673
+ // does one the person placed on its computer.
674
+ if (lane)
675
+ for (const waiting of openWakesOf(goalId, agent))
676
+ if (
677
+ computerOfRun(waiting) !== lane &&
678
+ !store.meta(`lane:${waiting.id}`) &&
679
+ waiting.status === "open" &&
680
+ !waiting.claimed_by &&
681
+ !waiting.run_authorized_at
682
+ ) {
683
+ store.removeTask(waiting.id);
684
+ notifyBoard(store.getTask(waiting.id));
685
+ }
686
+ const openHere = openWakeIn(goalId, agent, lane);
687
+ if (openHere) {
688
+ const key = laneKey(goalId, agent, lane);
619
689
  if (fromAnotherPerson(asker))
620
- store.meta(`other-person-run:${store.openWake(goalId, agent)}`, "1");
621
- const prior = pendingWakes.get(`${goalId}:${agent}`);
690
+ store.meta(`other-person-run:${openHere}`, "1");
691
+ const prior = pendingWakes.get(key);
622
692
  // Words the guard read as orders keep the next turn waiting for the person, whatever go an earlier call carried;
623
693
  // the person's own call is their go.
624
694
  const flagged = asker === "user" ? null : (held ?? prior?.held ?? null);
@@ -638,11 +708,11 @@ export function createThreadRuns({
638
708
  on: on ?? prior?.on ?? null,
639
709
  at: new Date().toISOString(),
640
710
  };
641
- pendingWakes.set(`${goalId}:${agent}`, pending);
642
- if (pending.go) startHeldWake(goalId, agent);
711
+ pendingWakes.set(key, pending);
712
+ if (pending.go) startHeldWake(goalId, agent, lane);
643
713
  // An ask again for a turn already waiting: the same turn, admitted once at most, and never past words the guard
644
714
  // read as orders before.
645
- const waiting = store.getTask(store.openWake(goalId, agent));
715
+ const waiting = store.getTask(openHere);
646
716
  if (
647
717
  proposed &&
648
718
  !flagged &&
@@ -653,7 +723,7 @@ export function createThreadRuns({
653
723
  )
654
724
  notifyBoard(store.getTask(waiting.id));
655
725
  if (asker === "user" && words)
656
- steerRunning(goalId, agent, words, pending);
726
+ steerRunning(goalId, agent, words, pending, key);
657
727
  return;
658
728
  }
659
729
  // The limit guards against agents waking each other in a loop, so it counts from the thread's last check-in: a thread
@@ -710,7 +780,7 @@ export function createThreadRuns({
710
780
  text: `${nameOf(agent)} is working on this computer, not in T3 Code: ${gap}.`,
711
781
  });
712
782
  }
713
- let folder = elsewhere?.folder ?? goal.workspace;
783
+ let folder = awayFolder ?? elsewhere?.folder ?? goal.workspace;
714
784
  // Another computer makes its own scratch folder for the turn (machineRuns.mjs), so none is named for it here.
715
785
  if (scratch)
716
786
  folder = elsewhere ? null : prepareScratch(goalId, threadFiles(task));
@@ -762,6 +832,7 @@ export function createThreadRuns({
762
832
  if (!scratch && (elsewhere?.machine || self))
763
833
  store.meta(`thread-work-computer:${goalId}`, elsewhere?.machine ?? self);
764
834
  if (t3) store.meta(`t3-run:${wake.id}`, "1");
835
+ if (lane) store.meta(`lane:${wake.id}`, lane);
765
836
  if (fromAnotherPerson(asker))
766
837
  store.meta(`other-person-run:${wake.id}`, "1");
767
838
  store.meta(
@@ -825,7 +896,10 @@ export function createThreadRuns({
825
896
  woken = JSON.parse(store.meta(`wake-reason:${wake.id}`) || "null");
826
897
  } catch {}
827
898
  if (!thread || !woken) return wake.brief;
828
- const later = pendingWakes.get(`${thread.id}:${wake.target_agent}`);
899
+ const later =
900
+ pendingWakes.get(
901
+ laneKey(thread.id, wake.target_agent, store.meta(`lane:${wake.id}`))
902
+ ) ?? pendingWakes.get(laneKey(thread.id, wake.target_agent));
829
903
  const reason =
830
904
  later && later.at > wake.created_at
831
905
  ? `${woken.reason}\n\nSince then: ${later.reason}`
@@ -958,9 +1032,12 @@ export function createThreadRuns({
958
1032
  kind === "failed" &&
959
1033
  (store.getTask(goalId)?.status !== "open" ||
960
1034
  Boolean(store.meta(`steered:${task.id}`)));
1035
+ // The computer the turn ran on (runWorker.mjs claims it there): the same agent may have a turn on another computer
1036
+ // in this thread at once, and that turn's posts are not this one's.
1037
+ const ranOn = store.getTask(task.id)?.claimed_machine ?? null;
961
1038
  if (
962
1039
  !stopped &&
963
- !store.postsBy(goalId, task.target_agent, startedAt) &&
1040
+ !store.postsBy(goalId, task.target_agent, startedAt, ranOn) &&
964
1041
  text
965
1042
  )
966
1043
  store.roomPost({
@@ -968,21 +1045,30 @@ export function createThreadRuns({
968
1045
  author: task.target_agent,
969
1046
  kind: kind === "done" ? "post" : "failed",
970
1047
  text: kind === "done" ? text : `run failed: ${text}`,
971
- // The computer the turn ran on (runWorker.mjs claims it there).
972
- machine: store.getTask(task.id)?.claimed_machine ?? null,
1048
+ machine: ranOn,
973
1049
  });
974
- // Its report: the agent's newest post since the turn began, the one above or its own.
1050
+ // Its report: the agent's newest post from this turn's computer since the turn began, the one above or its own.
975
1051
  if (kind === "done" && !stopped) {
976
1052
  const report = store
977
- .roomPosts(goalId, 0, 500)
978
- .findLast(
1053
+ .recentRoomPosts(goalId, { limit: 500 })
1054
+ .posts.findLast(
979
1055
  (post) =>
980
- post.author === task.target_agent && post.created_at >= startedAt
1056
+ post.author === task.target_agent &&
1057
+ post.created_at >= startedAt &&
1058
+ (!ranOn || !post.machine || post.machine === ranOn)
981
1059
  );
982
1060
  const thread = store.getTask(goalId);
983
1061
  if (report && thread) reported(thread, report);
984
1062
  }
985
- const key = `${goalId}:${task.target_agent}`;
1063
+ // Words that wait in this turn's lane, else words that named no computer.
1064
+ const laned = laneKey(
1065
+ goalId,
1066
+ task.target_agent,
1067
+ store.meta(`lane:${task.id}`)
1068
+ );
1069
+ const key = pendingWakes.get(laned)
1070
+ ? laned
1071
+ : laneKey(goalId, task.target_agent);
986
1072
  const pending = pendingWakes.get(key);
987
1073
  // A call that came before this run's brief read the thread is in it: waking it again repeats its work (Codex was
988
1074
  // once woken a second time for an animatic it had just made). Only a later call wakes it again, as one posted while
@@ -1010,39 +1096,41 @@ export function createThreadRuns({
1010
1096
  const recover = () => {
1011
1097
  for (const goal of store.goals()) {
1012
1098
  if (goal.status !== "open") continue;
1013
- for (const agent of RUNNERS) {
1014
- const key = goal.id + ":" + agent;
1015
- const pending = pendingWakes.get(key);
1016
- if (!pending) continue;
1017
- // A waiting turn never started, so nothing of it is unknown: the person's go still starts it.
1018
- if (store.openWake(goal.id, agent)) {
1019
- if (pending.go) startHeldWake(goal.id, agent);
1020
- continue;
1099
+ for (const agent of RUNNERS)
1100
+ for (const key of laneKeys(goal.id, agent)) {
1101
+ const pending = pendingWakes.get(key);
1102
+ if (!pending) continue;
1103
+ const lane = key.includes("@") ? pending.on : null;
1104
+ // A waiting turn never started, so nothing of it is unknown: the person's go still starts it.
1105
+ if (openWakeIn(goal.id, agent, lane)) {
1106
+ if (pending.go) startHeldWake(goal.id, agent, lane);
1107
+ continue;
1108
+ }
1109
+ // The previous turn's effects are unknown. Preserve the new call, but let the person inspect before starting it.
1110
+ const wakeId = wakeAgent(goal.id, agent, pending.reason, {
1111
+ asker: pending.asker,
1112
+ pick: pending.pick,
1113
+ recovering: true,
1114
+ routeMachine: pending.routeMachine ?? null,
1115
+ on: pending.on ?? null,
1116
+ });
1117
+ if (!wakeId) continue;
1118
+ pendingWakes.delete(key);
1119
+ store.roomPost({
1120
+ goalId: goal.id,
1121
+ author: DISPATCHER,
1122
+ kind: "note",
1123
+ text:
1124
+ nameOf(agent) +
1125
+ "'s later call survived the restart and waits for your Start. Its interrupted turn's outcome is unknown; check the workspace before continuing.",
1126
+ });
1127
+ notifyBoard(store.getTask(goal.id));
1021
1128
  }
1022
- // The previous turn's effects are unknown. Preserve the new call, but let the person inspect before starting it.
1023
- const wakeId = wakeAgent(goal.id, agent, pending.reason, {
1024
- asker: pending.asker,
1025
- pick: pending.pick,
1026
- recovering: true,
1027
- routeMachine: pending.routeMachine ?? null,
1028
- on: pending.on ?? null,
1029
- });
1030
- if (!wakeId) continue;
1031
- pendingWakes.delete(key);
1032
- store.roomPost({
1033
- goalId: goal.id,
1034
- author: DISPATCHER,
1035
- kind: "note",
1036
- text:
1037
- nameOf(agent) +
1038
- "'s later call survived the restart and waits for your Start. Its interrupted turn's outcome is unknown; check the workspace before continuing.",
1039
- });
1040
- notifyBoard(store.getTask(goal.id));
1041
- }
1042
1129
  }
1043
1130
  };
1044
1131
  return {
1045
1132
  computerOf,
1133
+ computerOfRun,
1046
1134
  wake: wakeAgent,
1047
1135
  waitsForComputer,
1048
1136
  computersChanged,
@@ -0,0 +1,136 @@
1
+ import path from "node:path";
2
+ import { spawn } from "node:child_process";
3
+ import { ensureDir } from "./files.mjs";
4
+ import { paths } from "./paths.mjs";
5
+ import { nameOf } from "./members.mjs";
6
+
7
+ // Whether Harness's tools actually load inside an agent, not only whether the agent answers. An agent can be signed in
8
+ // and still never start Harness's MCP server (a guest's agent stuck "connecting" sent everyone to /mcp to paste
9
+ // things). This runs the agent headless with its MCP servers and passes once this computer's daemon hears that agent
10
+ // load Harness's tools (its server's tools/list) or call list_agents, which the prompt asks for. The load is what
11
+ // counts: a small local model (Pi on Flint) sometimes answered "ready" without calling anything.
12
+
13
+ const PROMPT =
14
+ "Call the harness tool list_agents once. Then reply with exactly one word: ready";
15
+
16
+ // Each agent's headless run with its own MCP servers loaded (unlike readiness.mjs, which leaves them out), allowed only
17
+ // Harness's list_agents, saving no session where the agent allows it, and running none of the person's hooks.
18
+ const RUNS = {
19
+ "claude-code": () => ({
20
+ command: "claude",
21
+ args: [
22
+ "-p",
23
+ PROMPT,
24
+ "--output-format",
25
+ "json",
26
+ "--no-session-persistence",
27
+ "--allowedTools",
28
+ "mcp__harness__list_agents",
29
+ "--settings",
30
+ '{"disableAllHooks":true}',
31
+ ],
32
+ }),
33
+ codex: () => ({
34
+ command: "codex",
35
+ args: [
36
+ "exec",
37
+ "--ephemeral",
38
+ "--skip-git-repo-check",
39
+ "-c",
40
+ 'sandbox_mode="read-only"',
41
+ "-c",
42
+ 'approval_policy="never"',
43
+ // With approvals off, Codex refuses every MCP call unless that tool is approved (Codex 0.166).
44
+ "-c",
45
+ 'mcp_servers.harness.tools.list_agents.approval_mode="approve"',
46
+ "-",
47
+ ],
48
+ stdin: PROMPT,
49
+ }),
50
+ pi: () => ({ command: "pi", args: ["--no-session", "-p", PROMPT] }),
51
+ opencode: () => ({
52
+ command: "opencode",
53
+ args: ["run", "--title", "Harness check", "--", PROMPT],
54
+ }),
55
+ };
56
+
57
+ export const TOOL_CHECKABLE = Object.keys(RUNS);
58
+
59
+ /**
60
+ * Measured November 3 on MacBook-Pro-3, the whole run with this prompt (spawn to exit; Harness hears the call before
61
+ * the reply): Claude Code 9.1, 7.2, 6.3 s; Codex 10.4, 18.0, 7.4 s (after allowing list_agents), every run calling
62
+ * Harness. 60 s is 3.3x the slowest of the six, and the same as readiness.mjs's check. Three runs per agent, warm, on
63
+ * one computer: a first start on a slow computer may need more, and Pi and OpenCode were not measured.
64
+ */
65
+ export const TOOL_CHECK_DEADLINE_MS = 60_000;
66
+
67
+ /**
68
+ * Run `agent` with the check prompt and say whether Harness heard its list_agents call: "loaded", "not_loaded"
69
+ * (it ran but never called Harness), "slow" (no call within `deadlineMs`), "not_installed" or "failed".
70
+ * `heardSince(agent, at)` is the daemon's word that a call came from that agent after `at`.
71
+ */
72
+ export function checkTools(
73
+ agent,
74
+ { heardSince, deadlineMs, cwd = path.join(paths.home, "checks"), run = spawn }
75
+ ) {
76
+ const invocation = RUNS[agent]?.();
77
+ if (!invocation)
78
+ return Promise.resolve({
79
+ state: "unchecked",
80
+ detail: `Harness cannot check ${nameOf(agent)}'s tools by itself`,
81
+ ms: 0,
82
+ });
83
+ ensureDir(cwd);
84
+ const started = Date.now();
85
+ return new Promise((resolve) => {
86
+ let output = "";
87
+ let settled = false;
88
+ const finish = (state, detail = null) => {
89
+ if (settled) return;
90
+ settled = true;
91
+ clearTimeout(timer);
92
+ clearInterval(listening);
93
+ resolve({ state, detail, ms: Date.now() - started });
94
+ };
95
+ const child = run(invocation.command, invocation.args, {
96
+ cwd,
97
+ stdio: ["pipe", "pipe", "pipe"],
98
+ });
99
+ // The call is what counts: once heard, the run need not finish its reply.
100
+ const listening = setInterval(() => {
101
+ if (heardSince(agent, started)) {
102
+ child.kill("SIGTERM");
103
+ finish("loaded");
104
+ }
105
+ }, 250);
106
+ const timer = setTimeout(() => {
107
+ child.kill("SIGKILL");
108
+ finish(
109
+ "slow",
110
+ `did not reach Harness within ${Math.round(deadlineMs / 1000)} seconds`
111
+ );
112
+ }, deadlineMs);
113
+ child.stdout?.on("data", (chunk) => (output += chunk));
114
+ child.stderr?.on("data", (chunk) => (output += chunk));
115
+ child.stdin?.on("error", () => {});
116
+ child.stdin?.end(invocation.stdin ?? "");
117
+ child.on("error", (error) =>
118
+ finish(
119
+ error.code === "ENOENT" ? "not_installed" : "failed",
120
+ error.message
121
+ )
122
+ );
123
+ child.on("close", () => {
124
+ if (heardSince(agent, started)) return finish("loaded");
125
+ finish("not_loaded", lastLine(output));
126
+ });
127
+ });
128
+ }
129
+
130
+ const lastLine = (text) =>
131
+ String(text)
132
+ .split("\n")
133
+ .map((line) => line.trim())
134
+ .filter(Boolean)
135
+ .at(-1)
136
+ ?.slice(0, 200) ?? null;
package/lib/ui.mjs CHANGED
@@ -18,6 +18,17 @@ const BAR = glyph("│", "|"),
18
18
  STOP = glyph("■", "x"),
19
19
  WARN = glyph("▲", "!");
20
20
 
21
+ // The spinner turning now, so a Ctrl-C handler can end it with its own words: left turning, clack ends it at exit
22
+ // with "Something went wrong".
23
+ let running = null;
24
+
25
+ /** End the spinner turning now with `text`; false when none is. */
26
+ export function stopSpinner(text, code = 0) {
27
+ if (!running) return false;
28
+ running.stop(text, code);
29
+ return true;
30
+ }
31
+
21
32
  const visible = (text) => text.replace(/\x1b\[[0-9;]*m/g, "").length;
22
33
 
23
34
  /** Lines of text wrapped to a width, each keeping its own indent. */
@@ -107,17 +118,20 @@ export function createUi({
107
118
  };
108
119
  const spin = p.spinner(),
109
120
  quit = () => process.exit(130);
110
- return {
121
+ const handle = {
111
122
  start: (text) => {
112
123
  spin.start(text);
124
+ running = handle;
113
125
  process.once("SIGINT", quit);
114
126
  },
115
127
  message: (text) => spin.message(text),
116
128
  stop: (text, code) => {
117
129
  process.removeListener("SIGINT", quit);
130
+ if (running === handle) running = null;
118
131
  spin.stop(text, code);
119
132
  },
120
133
  };
134
+ return handle;
121
135
  },
122
136
  waitOrType,
123
137
  };
package/lib/wakes.mjs CHANGED
@@ -5,7 +5,7 @@ import { createHmac, randomBytes, randomUUID } from "node:crypto";
5
5
  import { askerOf } from "./answers.mjs";
6
6
  import { resolveCommand, run } from "./commands.mjs";
7
7
  import { ensureDir, readJson, writeJsonAtomic } from "./files.mjs";
8
- import { paths } from "./paths.mjs";
8
+ import { harnessNode, paths } from "./paths.mjs";
9
9
 
10
10
  // Agent apps that run on this computer but are not started by Harness (OpenClaw, Hermes). Setup adds Harness to each
11
11
  // one's MCP servers and turns on its own local webhook with a secret made here; the daemon then wakes it when work is
@@ -61,7 +61,7 @@ const tail = (result) =>
61
61
  export function setupOpenClaw({
62
62
  runtimeRoot,
63
63
  homeDir = os.homedir(),
64
- nodePath = process.execPath,
64
+ nodePath = harnessNode(),
65
65
  execute = run,
66
66
  command = resolveCommand("openclaw"),
67
67
  }) {
@@ -139,7 +139,7 @@ export function setupOpenClaw({
139
139
  export function setupHermes({
140
140
  runtimeRoot,
141
141
  homeDir = os.homedir(),
142
- nodePath = process.execPath,
142
+ nodePath = harnessNode(),
143
143
  execute = run,
144
144
  command = resolveCommand("hermes"),
145
145
  }) {