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/cli.mjs CHANGED
@@ -193,7 +193,8 @@ async function waitForDaemon(timeoutMs = 12_000) {
193
193
  try {
194
194
  lastStatus = await daemonRequest({ command: "status" }, 1_000);
195
195
  if (lastStatus.connected) return lastStatus;
196
- if (lastStatus.lastError) lastError = new Error(lastStatus.lastError);
196
+ const why = lastStatus.heldElsewhere || lastStatus.lastError;
197
+ if (why) lastError = new Error(why);
197
198
  } catch (error) {
198
199
  lastError = error;
199
200
  }
@@ -421,8 +422,13 @@ async function status() {
421
422
  `Harness daemon ${current.version || "unknown"}: ${current.ok === false ? "not responding" : "running"} (pid ${current.pid || "?"})`
422
423
  );
423
424
  console.log(
424
- `Harness bridge: ${current.connected ? "connected" : "disconnected"}`
425
+ `Harness bridge: ${current.connected ? "connected" : `disconnected${current.heldElsewhere ? ` — ${current.heldElsewhere}` : ""}`}`
425
426
  );
427
+ const machine = current.machine;
428
+ if (machine?.label)
429
+ console.log(
430
+ `this computer: ${machine.label}, ${machine.role === "worker" ? `a worker${machine.home ? ` for ${machine.home.label} (${machine.home.connected ? "online" : "offline"}${machine.home.confirmed ? "" : ", not confirmed yet: npx tryharness machines"})` : ""}${machine.waiting ? `, ${machine.waiting} waiting to send` : ""}` : "home, holds the board"}`
431
+ );
426
432
  console.log(
427
433
  `history: ${current.indexing ? "indexing" : "ready"}${current.lastIndexedAt ? ` · last scan ${current.lastIndexedAt}` : ""}`
428
434
  );
@@ -590,7 +596,7 @@ async function doctor() {
590
596
  const report = await daemonRequest({ command: "doctor" });
591
597
  console.log(`daemon: running (pid ${report.status.pid})`);
592
598
  console.log(
593
- `bridge: ${report.status.connected ? "connected" : `disconnected${report.status.lastError ? ` — ${report.status.lastError}` : ""}`}`
599
+ `bridge: ${report.status.connected ? "connected" : `disconnected${report.status.heldElsewhere || report.status.lastError ? ` — ${report.status.heldElsewhere || report.status.lastError}` : ""}`}`
594
600
  );
595
601
  console.log(`database: ${report.database}`);
596
602
  console.log(`control socket: ${report.socket}`);
@@ -669,6 +675,67 @@ async function connectAgent() {
669
675
  );
670
676
  }
671
677
 
678
+ // The person's own computers: which one holds the board (home), the others that work through it, and the join code a
679
+ // new one shows until the person types it on home.
680
+ async function machines() {
681
+ const sub = argv[0];
682
+ if (sub === "confirm") {
683
+ const response = await daemonRequest(
684
+ { command: "machines.confirm", code: String(argv[1] || "") },
685
+ 30_000
686
+ );
687
+ if (!response.ok) throw new Error(response.error || "not confirmed");
688
+ console.log(
689
+ `Confirmed ${response.machine || "the computer"} (key ${response.fingerprint}). Its agents now work on this computer's board, sealed end to end between the two; Harness carries the calls and cannot read them.`
690
+ );
691
+ return;
692
+ }
693
+ if (sub === "name") {
694
+ const response = await daemonRequest({
695
+ command: "machines.name",
696
+ label: argv.slice(1).join(" "),
697
+ });
698
+ if (!response.ok) throw new Error(response.error || "not renamed");
699
+ console.log(`This computer is now called ${response.label}.`);
700
+ return;
701
+ }
702
+ if (sub === "home") {
703
+ const response = await daemonRequest({ command: "machines.home" }, 20_000);
704
+ if (!response.ok) throw new Error(response.error || "not moved");
705
+ console.log(
706
+ "This computer is home now: it holds the board from here on. The board on the computer that was home stays there; work it held is not moved."
707
+ );
708
+ return;
709
+ }
710
+ if (sub)
711
+ throw new Error(
712
+ "usage: tryharness machines [confirm <code> | name <name> | home]"
713
+ );
714
+ const response = await daemonRequest({ command: "machines.list" });
715
+ if (!response.ok)
716
+ throw new Error(response.error || "the daemon could not list computers");
717
+ const { self, joinCode } = response;
718
+ console.log(
719
+ `This computer: ${self.label} (${self.role === "worker" ? "worker" : "home, holds the board"})${self.fingerprint ? `, key ${self.fingerprint}` : ""}`
720
+ );
721
+ if (joinCode) {
722
+ const home = response.machines.find((machine) => machine.role === "home");
723
+ console.log(
724
+ `Join code: ${joinCode}\nOn your home computer${home?.label ? ` (${home.label})` : ""}, run: npx tryharness machines confirm ${joinCode}`
725
+ );
726
+ }
727
+ if (!response.machines.length) {
728
+ console.log(
729
+ "No other computers yet. Run npx tryharness on another computer with the same account; it joins as a worker."
730
+ );
731
+ return;
732
+ }
733
+ for (const machine of response.machines)
734
+ console.log(
735
+ `${String(machine.label || machine.id).padEnd(20)} ${machine.role.padEnd(7)} ${(machine.connected ? "online" : "offline").padEnd(8)} ${machine.confirmed ? "confirmed" : "waiting to join"}${machine.fingerprint ? ` key ${machine.fingerprint}` : ""}${machine.agents?.length ? ` ${machine.agents.join(", ")}` : ""}`
736
+ );
737
+ }
738
+
672
739
  // The keys of other people's computers this one has worked with, pinned the first time, and its own.
673
740
  async function peers() {
674
741
  const response = await daemonRequest({ command: "relay.peers" });
@@ -715,6 +782,31 @@ async function mcpSnippet() {
715
782
  );
716
783
  }
717
784
 
785
+ // One line per section (its priority, name, source, whole size and what was sent), the budget decision, the session,
786
+ // and for a dry run the brief itself.
787
+ function printBrief({ task, agent, report, prompt }, dryRun) {
788
+ const number = (value) => Number(value).toLocaleString("en-US");
789
+ const session = report.session.t3
790
+ ? "goes into its T3 Code thread"
791
+ : report.session.resumes
792
+ ? `resumes session ${report.session.resumes}`
793
+ : report.session.replaces
794
+ ? `starts a fresh session in place of ${report.session.replaces}: ${report.session.why}`
795
+ : "starts a new session";
796
+ console.log(
797
+ `${dryRun ? "Brief a run would get now" : `Brief the run got at ${report.at}`}: task ${task} for ${agent}; ${session}.`
798
+ );
799
+ console.log(
800
+ `${number(report.whole)} characters whole, ${number(report.sent)} sent; budget ${number(report.budget)}: ${report.over ? "over budget even with every section that can give way replaced (core sections are always sent)" : report.sent < report.whole ? "sections replaced to fit, lowest priority and largest first" : "everything fits whole"}.`
801
+ );
802
+ for (const section of report.sections)
803
+ console.log(
804
+ ` ${section.priority.padEnd(11)} ${section.name.padEnd(32)} ${number(section.chars).padStart(7)} -> ${number(section.sent).padStart(7)} ${section.form.padEnd(9)} ${section.source}`
805
+ );
806
+ if (prompt !== undefined)
807
+ console.log(`\n${pc.dim("── as sent ──")}\n${prompt}`);
808
+ }
809
+
718
810
  async function board() {
719
811
  const sub = argv.find((value) => !value.startsWith("--")) || "list";
720
812
  const agent = arg("--as", "user");
@@ -972,6 +1064,26 @@ async function board() {
972
1064
  );
973
1065
  return;
974
1066
  }
1067
+ if (sub === "brief") {
1068
+ // A board run's brief, section by section: with --dry-run as a run would get it now, without starting the agent;
1069
+ // without, as the task's last run got it.
1070
+ const id = String(argv[argv.indexOf(sub) + 1] || "");
1071
+ if (!id || id.startsWith("--"))
1072
+ throw new Error("usage: tryharness board brief <task id> [--dry-run]");
1073
+ const dryRun = has("--dry-run");
1074
+ // A dry run does what a run's start does before its agent starts. Measured on the owner's daemon log, September 1 to
1075
+ // October 20, 2026: context packs took up to 7,349 ms (215 packs, median 859), task frames up to 875 ms (216, median
1076
+ // 230); claude-mem is cut off at 2,000 ms (CLAUDE_MEM_TIMEOUT_MS); reading the largest session file here (147 MB)
1077
+ // took 499 ms. That is 10.7 s at worst; the deadline gives it over twice that, for a session the relay must index
1078
+ // first (not measured).
1079
+ const response = await daemonRequest(
1080
+ { command: "runs.brief", id, dryRun },
1081
+ 25_000
1082
+ );
1083
+ if (!response.ok) throw new Error(response.error || "no brief");
1084
+ printBrief(response, dryRun);
1085
+ return;
1086
+ }
975
1087
  if (sub === "watch" || has("--watch")) {
976
1088
  // The terminal view that follows the board: one line per change, no Harness window needed.
977
1089
  const seen = new Map();
@@ -1102,7 +1214,7 @@ async function board() {
1102
1214
  }
1103
1215
  if (sub !== "list")
1104
1216
  throw new Error(
1105
- "usage: tryharness board [list --all | show <id> | trace <id> | post --for <agent> --objective <text> [--file <brief.md>] [--run --workspace <dir>] | run <id> | release <id> | standing [<agent> <folder>... --cap <n> | <agent> off | <agent> on] | agents]"
1217
+ "usage: tryharness board [list --all | show <id> | trace <id> | brief <id> [--dry-run] | post --for <agent> --objective <text> [--file <brief.md>] [--run --workspace <dir>] | run <id> | release <id> | standing [<agent> <folder>... --cap <n> | <agent> off | <agent> on] | agents]"
1106
1218
  );
1107
1219
  const response = await daemonRequest({
1108
1220
  command: "board.list",
@@ -1972,7 +2084,7 @@ async function t3() {
1972
2084
 
1973
2085
  function help() {
1974
2086
  console.log(
1975
- `tryharness ${VERSION}\n\nCommands:\n tryharness set up everything and start the daemon\n tryharness desktop open the Harness desktop app (setup opens it too; --no-desktop skips it)\n tryharness status show daemon, bridge, agent, and index health\n tryharness doctor diagnose the complete connection\n tryharness local [learn] the relay's local models, where they run, what is indexed and the last learning\n tryharness local on|off search over your Desktop, Documents and Downloads by what is in the files (on by default)\n tryharness local add|remove <folder> another folder to search the same way\n tryharness watch [add <name> --run <command> [--every 5m] [--field f | --age f | --count text] [--above n] [--below n] | start <id> | remove <id>]\n watches the relay checks and says out loud only when they are off\n tryharness sync [--agent] rescan local coding history in the background\n tryharness task <id> --follow\n follow a delegated agent run in this terminal\n tryharness board [--all] list open work on the machine's task board\n tryharness board post --for <agent> --objective <text> [--file <brief.md>]\n tryharness board show <id>\n tryharness board post --for codex --objective <text> --run --workspace <dir>\n the daemon runs it and reports back on the task\n tryharness board run <id> authorize a run an agent asked for\n tryharness board release <id>\n tryharness board agents when each agent last read the board\n tryharness board --watch follow the board in this terminal\n tryharness notify on|off desktop notifications for what waits on you\n tryharness board send <task> <message> send a held reply to another person's agent\n tryharness board snippet [<id> share|keep] code an agent elsewhere asked to see; nothing leaves until you share it\n tryharness board auto <task> on|off auto-send replies on that thread\n tryharness board end <task> --outcome <text>\n tryharness board context <task> <query> search everything written about a task\n tryharness goal set --objective <text> [--team a,b] [--workspace <dir>] a goal your agents work together in one room\n tryharness goal [list | show <id> | stop <id> | resume <id>]\n tryharness room <goal> | room post <goal> <text> [--ask agent,agent]\n tryharness swarm rounds [<thread>] what the coordinator saw, chose and cost each round\n tryharness swarm health [<thread>] who decided each day's rounds: Harness, a backup, or no one\n tryharness swarm ceiling <thread> <dollars|off> what a thread may spend of your Harness credits\n tryharness swarm checkin <thread> "<what>" (--in 2h | --at 14:30 | --every 30m | --daily 09:00 [--days mon-fri]) [--wake codex] [--times n] [--until <date>]\n the thread comes back on its own then, waking those agents or its lead\n tryharness swarm checkins [<thread>] [--all] | swarm checkin remove <id>\n tryharness swarm coordinator [harness|local] who coordinates your threads\n tryharness connect <handle/agent> --about <text> ask another person's agent to work an issue with yours, sealed to their computer\n tryharness peers the keys of other people's computers this one has worked with, to compare\n tryharness agents how Harness wakes each of your agents, and set up the rest\n tryharness agents setup <agent> | agents test <agent>\n tryharness agents cards what each of your agents is told about the others\n tryharness agents note <agent> <text> [--clear] your own note on an agent's card, told to every other agent\n tryharness lessons [--replaced] | lessons remove <id> | lessons edit <id> "<text>"\n what your swarm learned from your words, to read, change or take out\n tryharness agents models [<agent>] [--refresh] the models each coding agent lists and the one it runs on\n tryharness agents model <agent> <model> [--effort <level>] | auto | default the model it runs on; auto lets Harness pick per run\n tryharness agents routing "<text>" [--clear] how Auto picks models for your swarm\n tryharness mcp grok-bot print the MCP snippet that puts Grok Bot on the board\n tryharness link connect the browser you use Harness in to this computer, end to end (--print shows the link)\n tryharness phone pair show a QR code that pairs your phone with this computer\n tryharness phone list | revoke <id>\n tryharness t3 approve Harness in T3 Code once, so your messages go into its threads (t3 status | t3 forget)\n tryharness logs [--follow]\n tryharness disconnect\n`
2087
+ `tryharness ${VERSION}\n\nCommands:\n tryharness set up everything and start the daemon\n tryharness desktop open the Harness desktop app (setup opens it too; --no-desktop skips it)\n tryharness status show daemon, bridge, agent, and index health\n tryharness doctor diagnose the complete connection\n tryharness local [learn] the relay's local models, where they run, what is indexed and the last learning\n tryharness local on|off search over your Desktop, Documents and Downloads by what is in the files (on by default)\n tryharness local add|remove <folder> another folder to search the same way\n tryharness watch [add <name> --run <command> [--every 5m] [--field f | --age f | --count text] [--above n] [--below n] | start <id> | remove <id>]\n watches the relay checks and says out loud only when they are off\n tryharness sync [--agent] rescan local coding history in the background\n tryharness task <id> --follow\n follow a delegated agent run in this terminal\n tryharness board [--all] list open work on the machine's task board\n tryharness board post --for <agent> --objective <text> [--file <brief.md>]\n tryharness board show <id>\n tryharness board post --for codex --objective <text> --run --workspace <dir>\n the daemon runs it and reports back on the task\n tryharness board run <id> authorize a run an agent asked for\n tryharness board release <id>\n tryharness board agents when each agent last read the board\n tryharness board --watch follow the board in this terminal\n tryharness notify on|off desktop notifications for what waits on you\n tryharness board send <task> <message> send a held reply to another person's agent\n tryharness board snippet [<id> share|keep] code an agent elsewhere asked to see; nothing leaves until you share it\n tryharness board auto <task> on|off auto-send replies on that thread\n tryharness board end <task> --outcome <text>\n tryharness board context <task> <query> search everything written about a task\n tryharness goal set --objective <text> [--team a,b] [--workspace <dir>] a goal your agents work together in one room\n tryharness goal [list | show <id> | stop <id> | resume <id>]\n tryharness room <goal> | room post <goal> <text> [--ask agent,agent]\n tryharness swarm rounds [<thread>] what the coordinator saw, chose and cost each round\n tryharness swarm health [<thread>] who decided each day's rounds: Harness, a backup, or no one\n tryharness swarm ceiling <thread> <dollars|off> what a thread may spend of your Harness credits\n tryharness swarm checkin <thread> "<what>" (--in 2h | --at 14:30 | --every 30m | --daily 09:00 [--days mon-fri]) [--wake codex] [--times n] [--until <date>]\n the thread comes back on its own then, waking those agents or its lead\n tryharness swarm checkins [<thread>] [--all] | swarm checkin remove <id>\n tryharness swarm coordinator [harness|local] who coordinates your threads\n tryharness connect <handle/agent> --about <text> ask another person's agent to work an issue with yours, sealed to their computer\n tryharness peers the keys of other people's computers this one has worked with, to compare\n tryharness machines your computers: which holds the board (home) and which work through it; machines confirm <code> | name <name> | home\n tryharness agents how Harness wakes each of your agents, and set up the rest\n tryharness agents setup <agent> | agents test <agent>\n tryharness agents cards what each of your agents is told about the others\n tryharness agents note <agent> <text> [--clear] your own note on an agent's card, told to every other agent\n tryharness lessons [--replaced] | lessons remove <id> | lessons edit <id> "<text>"\n what your swarm learned from your words, to read, change or take out\n tryharness agents models [<agent>] [--refresh] the models each coding agent lists and the one it runs on\n tryharness agents model <agent> <model> [--effort <level>] | auto | default the model it runs on; auto lets Harness pick per run\n tryharness agents routing "<text>" [--clear] how Auto picks models for your swarm\n tryharness mcp grok-bot print the MCP snippet that puts Grok Bot on the board\n tryharness link connect the browser you use Harness in to this computer, end to end (--print shows the link)\n tryharness phone pair show a QR code that pairs your phone with this computer\n tryharness phone list | revoke <id>\n tryharness t3 approve Harness in T3 Code once, so your messages go into its threads (t3 status | t3 forget)\n tryharness logs [--follow]\n tryharness disconnect\n`
1976
2088
  );
1977
2089
  }
1978
2090
 
@@ -2001,6 +2113,7 @@ try {
2001
2113
  else if (command === "link") await link();
2002
2114
  else if (command === "t3") await t3();
2003
2115
  else if (command === "peers") await peers();
2116
+ else if (command === "machines") await machines();
2004
2117
  else if (command === "connect") await connectAgent();
2005
2118
  else if (command === "desktop") {
2006
2119
  const shown = await desktop();
@@ -9,6 +9,8 @@ export function createActorRoster({
9
9
  authority,
10
10
  localWaker,
11
11
  connected,
12
+ // The person's computers that have this agent, this one included: [{ label, online, here }] (ownMachines.mjs).
13
+ computersWith = () => [],
12
14
  }) {
13
15
  const RUNNERS = authority.RUNNERS;
14
16
  const CLOUD_AGENTS = new Set(CLOUD_HOMED);
@@ -59,7 +61,8 @@ export function createActorRoster({
59
61
  (agent) =>
60
62
  agent === "harness" ||
61
63
  (RUNNERS.has(agent)
62
- ? installedAgents.includes(agent)
64
+ ? installedAgents.includes(agent) ||
65
+ computersWith(agent).some((computer) => !computer.here)
63
66
  : CLOUD_AGENTS.has(agent)
64
67
  ? connected()
65
68
  : seen.has(agent) || Boolean(woken[agent]) || cloudSetup.has(agent))
@@ -67,12 +70,22 @@ export function createActorRoster({
67
70
  };
68
71
  // Each agent's card (cards.mjs) as every other agent is told it, its setup included; `lessons`: what the person said
69
72
  // about each, for a reader on this computer or Harness only.
73
+ // A coding agent on more than one of the person's computers, or on another one, says which: "Codex (Mac)".
74
+ const withMachines = (card) => {
75
+ const computers = RUNNERS.has(card.id) ? computersWith(card.id) : [];
76
+ return computers.some((computer) => !computer.here)
77
+ ? {
78
+ ...card,
79
+ machines: computers.map(({ label, online }) => ({ label, online })),
80
+ }
81
+ : card;
82
+ };
70
83
  const cardsFor = (ids, { lessons = true } = {}) =>
71
84
  swarmCards(
72
85
  store,
73
86
  ids.map((id) => ({ id, setup: setupOf(id) })),
74
87
  { lessons }
75
- );
88
+ ).map(withMachines);
76
89
  // The person's words from other threads (lessons.mjs) stay with the agents on this computer and Harness.
77
90
  const readsLessonsHere = (agent) => RUNNERS.has(agent) || agent === "harness";
78
91
 
@@ -100,6 +113,7 @@ export function createActorRoster({
100
113
  setupNote,
101
114
  available,
102
115
  cardsFor,
116
+ withMachines,
103
117
  readsLessonsHere,
104
118
  updateCloudSetup,
105
119
  };
package/lib/adapters.mjs CHANGED
@@ -222,8 +222,9 @@ export function installCodexHooks({
222
222
  const starts = (
223
223
  Array.isArray(hooks.SessionStart) ? hooks.SessionStart : []
224
224
  ).filter((entry) => !isHarnessHook(entry));
225
+ // After a compaction too: the hook tells the session its work again (compaction.mjs).
225
226
  starts.push({
226
- matcher: "startup|resume",
227
+ matcher: "startup|resume|compact",
227
228
  hooks: [
228
229
  {
229
230
  type: "command",
@@ -0,0 +1,30 @@
1
+ import { TAGGED_ONLY } from "./members.mjs";
2
+
3
+ // Who hears a task's outcome. One rule for the whole swarm (owner, October 20: "behavior like this should be consistent
4
+ // across the swarm"): when a task finishes, fails or asks back, the agent that posted it gets a turn, whatever it is,
5
+ // wherever it runs and whether or not the task opened its own thread. How the turn reaches it differs by where the agent
6
+ // runs (a coding agent's turn in the task's thread, OpenClaw's and Hermes's gateway, Grok Bot's and Muse's wake from
7
+ // Harness, Harness's conversation or its thread); who gets one does not.
8
+ //
9
+ // Never the person (their surfaces show the outcome), never the agent that did the work itself, and never an agent
10
+ // that moves money or takes positions (Bankr, Quotient): an answer coming back does not start one of them; only the
11
+ // person's name for it or another agent's ask does.
12
+
13
+ const ANSWERED = ["done", "failed", "needs_input"];
14
+
15
+ /** The agent that gets a turn for this task's outcome, or null. */
16
+ export const askerOf = (task) => {
17
+ const asker = task?.origin_agent;
18
+ const didItItself =
19
+ asker === task?.claimed_by || asker === task?.target_agent;
20
+ if (
21
+ !asker ||
22
+ asker === "user" ||
23
+ didItItself ||
24
+ TAGGED_ONLY.includes(asker) ||
25
+ ["wake", "goal"].includes(task.kind) ||
26
+ !ANSWERED.includes(task.status)
27
+ )
28
+ return null;
29
+ return asker;
30
+ };
@@ -8,6 +8,7 @@ export function createBoardCommands({
8
8
  touchListener,
9
9
  handlers,
10
10
  task,
11
+ machineOf = () => null,
11
12
  }) {
12
13
  return (request) => {
13
14
  if (!validAgent(request.agent))
@@ -20,7 +21,14 @@ export function createBoardCommands({
20
21
  const expected = Number.isInteger(request.expectedVersion)
21
22
  ? request.expectedVersion
22
23
  : null;
23
- const context = { agent, lastLooked, id, expected };
24
+ // The computer the call came from: this one, or a worker whose call home opened (ownMachines.mjs).
25
+ const context = {
26
+ agent,
27
+ lastLooked,
28
+ id,
29
+ expected,
30
+ machine: machineOf(request),
31
+ };
24
32
  const owner = boardCommandOwner(String(request.command));
25
33
  const handler = Object.hasOwn(handlers, owner) ? handlers[owner] : task;
26
34
  return handler(request, context);
@@ -44,7 +44,7 @@ export const MAX_FILE_BYTES = Math.max(
44
44
  ...FILE_LIMITS.map((limit) => limit.bytes)
45
45
  );
46
46
  // One part of a file read through the sealed channel: 512 KiB is 683 KiB as base64, inside a sealed answer's 1 MB.
47
- const FILE_PART_BYTES = 512 * 1024;
47
+ export const FILE_PART_BYTES = 512 * 1024;
48
48
  // The most files one search across the person's threads answers with.
49
49
  const FOUND_FILES = 20;
50
50
  const fileLimit = (mime, bytes) =>
@@ -50,6 +50,7 @@
50
50
  "board.release": "task",
51
51
  "board.remove": "task",
52
52
  "board.report": "task",
53
+ "board.room.learn": "goals",
53
54
  "board.room.post": "goals",
54
55
  "board.room.read": "goals",
55
56
  "board.room.search": "goals",
package/lib/bridge.mjs CHANGED
@@ -4,6 +4,16 @@ import WebSocket from "ws";
4
4
  import { scrubDeep, restoreDeep } from "./firewall.mjs";
5
5
  // The bridge ping interval; smoke tests shorten it.
6
6
  const HEARTBEAT_MS = Number(process.env.HARNESS_HEARTBEAT_MS) || 30_000;
7
+ // A dropped connection dials again after about a second (give or take a fifth), doubling up to 30 s.
8
+ export const RECONNECT_FIRST_MS = 1_000;
9
+ export const RECONNECT_JITTER = 0.2;
10
+ // Harness's answer when another computer paired to this account is connected (HELD_ELSEWHERE in
11
+ // src/server/bridge/bridgeHub.ts): 409 on the dial, or close code 4409 when two dials crossed.
12
+ const HELD_ELSEWHERE = {
13
+ status: 409,
14
+ code: 4409,
15
+ text: "Another computer is connected to this Harness account and holds its board, so this one stays offline. Disconnect that computer (npx tryharness disconnect there), then run npx tryharness setup here.",
16
+ };
7
17
  // This machine's IPv4 addresses: they change when it moves between networks. IPv6 privacy addresses rotate on their own.
8
18
  const networkAddresses = () =>
9
19
  Object.values(os.networkInterfaces())
@@ -38,6 +48,7 @@ const DECIDE_ONLY = new Set([
38
48
  /** One connection owns request settlement, feature negotiation, outages and reconnects. */
39
49
  export function createBridge({
40
50
  config,
51
+ machineId = null,
41
52
  state,
42
53
  saveStatus,
43
54
  log,
@@ -129,13 +140,26 @@ export function createBridge({
129
140
  send({ type, requestId, input });
130
141
  });
131
142
 
132
- let retry = 1_000;
143
+ let retry = RECONNECT_FIRST_MS;
133
144
  let reconnectTimer = null;
134
145
  let awaitingPong = 0;
146
+ // Another computer paired to this account holds its board. Dialing again would only be refused again, so this
147
+ // one stays off until the person acts (disconnects that computer, then starts Harness here again).
148
+ let heldElsewhere = false;
149
+ const holdElsewhere = () => {
150
+ if (heldElsewhere) return;
151
+ heldElsewhere = true;
152
+ state.connected = false;
153
+ state.heldElsewhere = HELD_ELSEWHERE.text;
154
+ state.lastError = HELD_ELSEWHERE.text;
155
+ log(HELD_ELSEWHERE.text);
156
+ saveStatus();
157
+ };
135
158
  // Drops the connection and dials again in about a second, whatever the backoff had grown to.
136
159
  const reconnectNow = (reason) => {
160
+ if (heldElsewhere) return;
137
161
  log(`${reason}; reconnecting`);
138
- retry = 1_000;
162
+ retry = RECONNECT_FIRST_MS;
139
163
  if (reconnectTimer) {
140
164
  clearTimeout(reconnectTimer);
141
165
  reconnectTimer = null;
@@ -144,8 +168,9 @@ export function createBridge({
144
168
  else connect();
145
169
  };
146
170
  const scheduleReconnect = () => {
147
- if (stopped || reconnectTimer) return;
148
- const delay = Math.round(retry * (0.8 + Math.random() * 0.4));
171
+ if (stopped || heldElsewhere || reconnectTimer) return;
172
+ const jitter = 1 - RECONNECT_JITTER + Math.random() * 2 * RECONNECT_JITTER;
173
+ const delay = Math.round(retry * jitter);
149
174
  retry = Math.min(30_000, retry * 2);
150
175
  reconnectTimer = setTimeout(() => {
151
176
  reconnectTimer = null;
@@ -153,17 +178,28 @@ export function createBridge({
153
178
  }, delay);
154
179
  };
155
180
  const connect = () => {
156
- if (stopped) return;
181
+ if (stopped || heldElsewhere) return;
157
182
  try {
158
183
  const origin = new URL(config.origin);
159
184
  origin.protocol = origin.protocol === "https:" ? "wss:" : "ws:";
160
185
  origin.pathname = "/api/bridge/ws";
161
186
  origin.search = "";
187
+ // Naming the computer on the dial lets Harness take it as a worker beside another home (machineRelay.ts).
162
188
  socket = new WebSocket(origin, {
163
- headers: { authorization: "Bearer " + config.token },
189
+ headers: {
190
+ authorization: "Bearer " + config.token,
191
+ ...(machineId ? { "x-harness-machine": machineId } : {}),
192
+ },
193
+ });
194
+ // A dial Harness answered with something other than an upgrade: the status says why.
195
+ let refusal = null;
196
+ socket.on("unexpected-response", (_request, response) => {
197
+ if (response.statusCode === HELD_ELSEWHERE.status) holdElsewhere();
198
+ refusal = `Unexpected server response: ${response.statusCode}`;
199
+ socket.terminate();
164
200
  });
165
201
  socket.on("open", () => {
166
- retry = 1_000;
202
+ retry = RECONNECT_FIRST_MS;
167
203
  awaitingPong = 0;
168
204
  if (offlineSince)
169
205
  outages.push({ start: offlineSince, end: Date.now() });
@@ -222,11 +258,15 @@ export function createBridge({
222
258
  relayWaiters.delete(requestId);
223
259
  waiter.reject?.(new Error("the connection to Harness dropped"));
224
260
  }
225
- if (error?.message) state.lastError = error.message;
261
+ if (error?.message && !heldElsewhere)
262
+ state.lastError = refusal || error.message;
226
263
  saveStatus();
227
264
  scheduleReconnect();
228
265
  };
229
- socket.on("close", () => dropped());
266
+ socket.on("close", (code) => {
267
+ if (code === HELD_ELSEWHERE.code) holdElsewhere();
268
+ dropped();
269
+ });
230
270
  socket.on("error", dropped);
231
271
  } catch (error) {
232
272
  state.connected = false;
package/lib/cards.mjs CHANGED
@@ -1,6 +1,7 @@
1
1
  import { createHash } from "node:crypto";
2
2
  import { member } from "./members.mjs";
3
3
  import { describeAgentModel } from "./models.mjs";
4
+ import { oneLine } from "./oneLine.mjs";
4
5
 
5
6
  // Each of the person's agents as the others see it: one card, written the same way for every reader (the block an agent
6
7
  // is told when its session starts, list_agents, a thread's brief, the coordinator's round), so work goes to the agent
@@ -153,9 +154,14 @@ export function cardLine(card, now = Date.now()) {
153
154
  ? "Can review without changing files."
154
155
  : "Has no review-only mode: its runs may change files."
155
156
  );
157
+ // The model is read from the agent's own settings, so it is one line like every other agent-written field here.
156
158
  if (card.where)
157
159
  parts.push(
158
- `Runs ${card.where}${card.model ? `, model ${card.model}` : ""}.`
160
+ `Runs ${card.where}${card.model ? `, model ${oneLine(card.model)}` : ""}.`
161
+ );
162
+ if (card.machines?.length)
163
+ parts.push(
164
+ `On the person's computers: ${card.machines.map((computer) => `${card.name} (${computer.label}${computer.online ? "" : ", offline"})`).join(", ")}; name one with target_machine.`
159
165
  );
160
166
  parts.push(sentence(card.answers));
161
167
  const { done, failed, ended, medianMinutes } = card.record;
@@ -186,14 +192,24 @@ export function cardLine(card, now = Date.now()) {
186
192
  ? `Last checked the board ${span((now - Date.parse(card.lastSeen)) / 60_000)} ago.`
187
193
  : "Has not checked the board yet."
188
194
  );
189
- if (card.note) parts.push(`The person says: ${sentence(card.note)}`);
195
+ if (card.note)
196
+ parts.push(`The person says: ${sentence(oneLine(card.note, NOTE_LIMIT))}`);
190
197
  if (card.lessons?.length)
191
198
  parts.push(
192
- `What the person has said about it before: ${card.lessons.map(sentence).join(" ")}`
199
+ `What the person has said about it before: ${card.lessons.map((lesson) => sentence(oneLine(lesson, NOTE_LIMIT))).join(" ")}`
193
200
  );
194
201
  return `- ${parts.join(" ")}`;
195
202
  }
196
203
 
204
+ /** One card in short form, for a session start short of room: who it is and what it is for. list_agents has the rest. */
205
+ export function shortCardLine(card) {
206
+ const unset = card.setup ? ` ${sentence(card.answers)}` : "";
207
+ return `- @${card.id} (${card.name}): ${sentence(card.about)}${unset}`;
208
+ }
209
+
210
+ export const SWARM_HEADER =
211
+ "Your swarm, the person's other agents. Hand one work with post_task (target_agent) or ask one in a thread with post_to_room (ask).";
212
+
197
213
  // How often the person has said it, when more than once; and whether they had to after agents were told it.
198
214
  const saidAgain = (lesson) => {
199
215
  const times = lesson.evidence?.length ?? 1;
@@ -217,7 +233,7 @@ export const toldBlock = (told) =>
217
233
  export function swarmBlock(cards, now = Date.now(), told = []) {
218
234
  if (!cards.length) return toldBlock(told);
219
235
  return [
220
- "Your swarm, the person's other agents. Hand one work with post_task (target_agent) or ask one in a thread with post_to_room (ask).",
236
+ SWARM_HEADER,
221
237
  ...cards.map((card) => cardLine(card, now)),
222
238
  ...(told.length ? ["", toldBlock(told)] : []),
223
239
  ].join("\n");
@@ -238,6 +254,8 @@ export const swarmDigest = (cards, told = []) =>
238
254
  card.model ?? null,
239
255
  card.note,
240
256
  card.setup ?? null,
257
+ // Only when there are some, so a swarm on one computer keeps the digest it had.
258
+ ...(card.machines ? [card.machines] : []),
241
259
  // Only when there are some, so a swarm with no lessons keeps the digest it had and is not told again.
242
260
  ...(card.lessons ? [card.lessons] : []),
243
261
  ])
@@ -0,0 +1,90 @@
1
+ import { oneLine } from "./oneLine.mjs";
2
+
3
+ // After an agent's context is compacted, its summary may have dropped what the work is for. The session-start hook
4
+ // (nudge.mjs), which Claude Code and Codex run again after a compaction, asks here and tells the agent its work again:
5
+ // the task it holds, the thread's goal with which checks are met, and three questions to put to itself before going on.
6
+
7
+ // The board's own caps (taskCommands.mjs cuts an objective at 500, goals.mjs a check at 500), so each is told whole.
8
+ const FIELD_LIMIT = 500;
9
+
10
+ const QUESTIONS = [
11
+ "Before your next step, answer these for yourself:",
12
+ "1. What is the person actually after?",
13
+ "2. Does your current step move that forward?",
14
+ "3. What have you concluded without checking it?",
15
+ ];
16
+
17
+ export function createCompaction({ store, goals }) {
18
+ // The work a session holds: the run working in it, else the thread that resumes it, else what its agent claimed.
19
+ const workOf = (agent, sessionId) => {
20
+ const run = sessionId ? store.runHoldingSession(agent, sessionId) : null;
21
+ if (run) {
22
+ const task = store.getTask(run.id);
23
+ const parent = run.parent_id ? store.getTask(run.parent_id) : null;
24
+ return {
25
+ task: task?.kind === "wake" ? null : task,
26
+ thread: parent?.kind === "goal" ? parent : null,
27
+ };
28
+ }
29
+ const threadId = sessionId
30
+ ? store.threadForSession(agent, sessionId)
31
+ : null;
32
+ if (threadId) return { task: null, thread: store.getTask(threadId) };
33
+ const claimed = store
34
+ .listTasks({ agent })
35
+ .find(
36
+ (task) =>
37
+ task.claimed_by === agent &&
38
+ ["claimed", "running", "needs_input"].includes(task.status)
39
+ );
40
+ if (!claimed) return null;
41
+ const parent = claimed.parent_id ? store.getTask(claimed.parent_id) : null;
42
+ return {
43
+ task: store.getTask(claimed.id),
44
+ thread: parent?.kind === "goal" ? parent : null,
45
+ };
46
+ };
47
+
48
+ const goalLines = (threadId) => {
49
+ const goal = goals.view(threadId);
50
+ if (!goal) return [];
51
+ const met = goal.criteria.filter((check) => check.status === "met");
52
+ const open = goal.criteria.filter((check) => check.status === "open");
53
+ const listed = (checks) =>
54
+ checks.map((check) => ` - ${oneLine(check.text, FIELD_LIMIT)}`);
55
+ return [
56
+ `- The thread's goal: ${oneLine(goal.statement, FIELD_LIMIT)}`,
57
+ ...(met.length
58
+ ? ["- Checks met:", ...listed(met)]
59
+ : ["- Checks met: none yet."]),
60
+ ...(open.length ? ["- Still to show:", ...listed(open)] : []),
61
+ ];
62
+ };
63
+
64
+ /** What a session is told after its compaction; empty when it holds no work on the board. */
65
+ const recall = ({ agent, sessionId }) => {
66
+ const work = workOf(agent, sessionId);
67
+ if (!work || (!work.task && !work.thread)) return "";
68
+ const { task, thread } = work;
69
+ const lines = [
70
+ "Your context was just compacted. Your work, as the Harness board has it:",
71
+ ];
72
+ if (task)
73
+ lines.push(
74
+ `- Your task: ${oneLine(task.objective, FIELD_LIMIT)} (task ${task.id})`
75
+ );
76
+ if (thread) {
77
+ lines.push(
78
+ `- The thread: "${oneLine(thread.objective)}" (thread ${thread.id})`
79
+ );
80
+ if (thread.brief)
81
+ lines.push(
82
+ `- The person's words: ${oneLine(thread.brief, FIELD_LIMIT)}`
83
+ );
84
+ lines.push(...goalLines(thread.id));
85
+ }
86
+ return [...lines, "", ...QUESTIONS].join("\n");
87
+ };
88
+
89
+ return { recall };
90
+ }