tryharness 0.7.82 → 0.7.86

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 (216) hide show
  1. package/README.md +21 -19
  2. package/assets/dsh-plugin.mjs +75 -4
  3. package/assets/herdr-mod/harness/main.js +367 -0
  4. package/assets/herdr-mod/harness/mod.json +6 -0
  5. package/assets/opencode-plugin.js +87 -22
  6. package/assets/pi-extension.ts +81 -2
  7. package/cli.mjs +544 -208
  8. package/lib/adapters.mjs +62 -27
  9. package/lib/agentBinaries.mjs +6 -8
  10. package/lib/agentClaims.mjs +168 -0
  11. package/lib/agentReadTools.json +415 -0
  12. package/lib/agentSignIn.mjs +17 -18
  13. package/lib/agentWiring.mjs +114 -0
  14. package/lib/archetypes.js +10 -11
  15. package/lib/attention.mjs +100 -0
  16. package/lib/audit.mjs +1 -1
  17. package/lib/backupSetup.mjs +6 -28
  18. package/lib/bankrApprovals.mjs +86 -0
  19. package/lib/boardAccess.mjs +40 -66
  20. package/lib/boardBackup.mjs +86 -85
  21. package/lib/boardCommands.mjs +28 -0
  22. package/lib/boardFileCommands.mjs +29 -36
  23. package/lib/boardFiles.mjs +83 -15
  24. package/lib/boardMirror.mjs +78 -11
  25. package/lib/boardProtocol.json +193 -123
  26. package/lib/boardThreads.mjs +19 -37
  27. package/lib/boardTools.mjs +22 -15
  28. package/lib/boardWatches.mjs +43 -15
  29. package/lib/bridge.mjs +7 -3
  30. package/lib/browserAgentTools.mjs +59 -0
  31. package/lib/browserWake.mjs +0 -6
  32. package/lib/cards.mjs +57 -2
  33. package/lib/circling.mjs +189 -0
  34. package/lib/cleanup.mjs +234 -0
  35. package/lib/cloudBoot.mjs +21 -4
  36. package/lib/cloudSave.mjs +46 -5
  37. package/lib/compaction.mjs +8 -1
  38. package/lib/completion.mjs +358 -0
  39. package/lib/computerDevices.mjs +853 -0
  40. package/lib/connectionStatus.mjs +34 -0
  41. package/lib/connectors.mjs +139 -1
  42. package/lib/coordinator.mjs +108 -14
  43. package/lib/coreModels.mjs +36 -12
  44. package/lib/daemon.mjs +2435 -333
  45. package/lib/daemonLock.mjs +103 -0
  46. package/lib/deviceDoor.mjs +308 -0
  47. package/lib/deviceIdentity.mjs +114 -0
  48. package/lib/deviceList.mjs +172 -0
  49. package/lib/deviceSeal.mjs +74 -0
  50. package/lib/dispatcher.mjs +497 -26
  51. package/lib/dispatches.mjs +3 -3
  52. package/lib/environment.mjs +2 -1
  53. package/lib/environments.mjs +67 -41
  54. package/lib/events.mjs +318 -0
  55. package/lib/facts.mjs +170 -0
  56. package/lib/fileSource.mjs +540 -0
  57. package/lib/files.mjs +47 -2
  58. package/lib/gitHost.mjs +39 -1
  59. package/lib/goalCommands.mjs +12 -80
  60. package/lib/handover.mjs +21 -16
  61. package/lib/harnessOffers.mjs +140 -15
  62. package/lib/herdr.mjs +100 -15
  63. package/lib/herdrAppCall.mjs +19 -0
  64. package/lib/herdrCore.mjs +59 -0
  65. package/lib/herdrRuns.mjs +1126 -0
  66. package/lib/hookDialects.mjs +235 -50
  67. package/lib/identityLink.mjs +81 -0
  68. package/lib/inference.mjs +31 -2
  69. package/lib/jamAccess.mjs +82 -0
  70. package/lib/{projectBoard.mjs → jamBoard.mjs} +5 -4
  71. package/lib/{projectGit.mjs → jamGit.mjs} +53 -15
  72. package/lib/jamKey.mjs +274 -0
  73. package/lib/{projectPieces.mjs → jamPieces.mjs} +35 -29
  74. package/lib/{projectSettings.mjs → jamSettings.mjs} +12 -22
  75. package/lib/jamStore.mjs +973 -0
  76. package/lib/jamUpgrade.mjs +112 -0
  77. package/lib/jams.mjs +3079 -0
  78. package/lib/kanban.mjs +13 -7
  79. package/lib/landed.mjs +5 -1
  80. package/lib/library.mjs +41 -22
  81. package/lib/limits.mjs +91 -0
  82. package/lib/lineDiff.mjs +97 -0
  83. package/lib/lineup.mjs +18 -13
  84. package/lib/link.mjs +584 -0
  85. package/lib/localStack.mjs +75 -16
  86. package/lib/localmodels.mjs +58 -78
  87. package/lib/loopBackstop.mjs +2 -1
  88. package/lib/machine.mjs +544 -0
  89. package/lib/machineLink.mjs +446 -0
  90. package/lib/machineRoutes.mjs +68 -19
  91. package/lib/machineRuns.mjs +85 -4
  92. package/lib/machineSeal.mjs +6 -31
  93. package/lib/manager.mjs +134 -12
  94. package/lib/mcp-stdio.mjs +492 -215
  95. package/lib/mcpRelay.mjs +34 -35
  96. package/lib/members.json +2 -2
  97. package/lib/modelRoute.mjs +162 -0
  98. package/lib/nativeHost.mjs +81 -90
  99. package/lib/nativeSenses.mjs +258 -0
  100. package/lib/nerves.mjs +523 -0
  101. package/lib/network.mjs +117 -278
  102. package/lib/networkPlaces.mjs +578 -0
  103. package/lib/nextStep.mjs +95 -0
  104. package/lib/notify.mjs +2 -2
  105. package/lib/nudge.mjs +116 -10
  106. package/lib/onboard.mjs +6 -6
  107. package/lib/originals.mjs +216 -0
  108. package/lib/outsideEvents.mjs +383 -0
  109. package/lib/outsideRuns.mjs +230 -0
  110. package/lib/ownMachines.mjs +674 -256
  111. package/lib/pain.mjs +215 -0
  112. package/lib/pairing.mjs +91 -11
  113. package/lib/paths.mjs +42 -3
  114. package/lib/peerProcess.mjs +21 -7
  115. package/lib/peopleLink.mjs +268 -0
  116. package/lib/personNotices.mjs +3 -2
  117. package/lib/phones.mjs +252 -542
  118. package/lib/placeCards.mjs +282 -0
  119. package/lib/placeChecks.mjs +95 -0
  120. package/lib/placeCommands.mjs +8 -17
  121. package/lib/placeRequests.mjs +152 -0
  122. package/lib/placeStore.mjs +295 -0
  123. package/lib/placeTool.d.ts +12 -0
  124. package/lib/placeTool.js +40 -0
  125. package/lib/places.mjs +63 -14
  126. package/lib/plans.mjs +53 -8
  127. package/lib/presence.mjs +270 -0
  128. package/lib/privateNetwork.d.ts +2 -0
  129. package/lib/privateNetwork.js +93 -0
  130. package/lib/proposals.mjs +300 -0
  131. package/lib/publicFetch.d.ts +32 -0
  132. package/lib/publicFetch.js +248 -0
  133. package/lib/reach.mjs +128 -0
  134. package/lib/rebuildable.mjs +72 -0
  135. package/lib/recall.mjs +216 -0
  136. package/lib/record.mjs +13 -0
  137. package/lib/reflexes.mjs +392 -0
  138. package/lib/relayLimits.mjs +31 -2
  139. package/lib/releaseNotice.mjs +198 -0
  140. package/lib/removeHarness.mjs +15 -4
  141. package/lib/repoLinks.mjs +204 -35
  142. package/lib/runAuthority.mjs +102 -39
  143. package/lib/runBrief.mjs +93 -40
  144. package/lib/runRequests.mjs +52 -14
  145. package/lib/runUsage.mjs +31 -0
  146. package/lib/runWorker.mjs +74 -25
  147. package/lib/runner.mjs +289 -45
  148. package/lib/runtime-install.mjs +37 -8
  149. package/lib/schedules.mjs +171 -47
  150. package/lib/screenWatches.mjs +221 -0
  151. package/lib/sealed.mjs +12 -30
  152. package/lib/sealedThreads.mjs +198 -392
  153. package/lib/secretStore.mjs +178 -0
  154. package/lib/secrets.mjs +11 -0
  155. package/lib/seen.mjs +3 -9
  156. package/lib/selfUpdate.mjs +51 -15
  157. package/lib/senseCall.mjs +1514 -0
  158. package/lib/senseHook.mjs +114 -0
  159. package/lib/senseTools.mjs +1298 -0
  160. package/lib/sessionBriefs.mjs +87 -0
  161. package/lib/sessionControl.mjs +63 -13
  162. package/lib/sessionFiles.mjs +85 -0
  163. package/lib/setupChoices.mjs +12 -3
  164. package/lib/setupMode.mjs +70 -25
  165. package/lib/sharedKeys.mjs +166 -0
  166. package/lib/sleep.mjs +396 -0
  167. package/lib/sources.mjs +306 -0
  168. package/lib/speech.mjs +166 -411
  169. package/lib/spoken.mjs +210 -0
  170. package/lib/steerHook.mjs +3 -1
  171. package/lib/steerQueue.mjs +40 -11
  172. package/lib/store.mjs +323 -130
  173. package/lib/stuck.mjs +85 -7
  174. package/lib/swarm.mjs +157 -49
  175. package/lib/swarmDevices.mjs +25 -85
  176. package/lib/swarmMemory.mjs +93 -9
  177. package/lib/t3.mjs +73 -3
  178. package/lib/taskCommands.mjs +51 -60
  179. package/lib/taskRooms.mjs +30 -4
  180. package/lib/taskRules.json +29 -0
  181. package/lib/taskRules.mjs +21 -0
  182. package/lib/taskRuns.mjs +74 -11
  183. package/lib/team.mjs +2 -1
  184. package/lib/threadActions.mjs +37 -9
  185. package/lib/threadAuthority.mjs +4 -4
  186. package/lib/threadBriefs.mjs +173 -43
  187. package/lib/threadNotes.mjs +320 -0
  188. package/lib/threadRecord.mjs +491 -0
  189. package/lib/threadRuns.mjs +216 -108
  190. package/lib/threadView.mjs +27 -30
  191. package/lib/threadWatches.mjs +1962 -0
  192. package/lib/timeSense.mjs +839 -0
  193. package/lib/tripwires.mjs +454 -0
  194. package/lib/ui.mjs +1 -1
  195. package/lib/vault.mjs +560 -45
  196. package/lib/vaultCommands.mjs +5 -3
  197. package/lib/vaultPeers.mjs +165 -0
  198. package/lib/vaultTools.d.ts +4 -1
  199. package/lib/vaultTools.js +22 -1
  200. package/lib/verdicts.mjs +12 -26
  201. package/lib/versions.mjs +117 -0
  202. package/lib/waitTool.mjs +278 -0
  203. package/lib/wakePicture.mjs +268 -0
  204. package/lib/wakeQueue.mjs +108 -0
  205. package/lib/watchResponses.mjs +533 -0
  206. package/lib/watches.mjs +290 -145
  207. package/lib/windowAsks.mjs +80 -17
  208. package/lib/worktrees.mjs +159 -9
  209. package/npm-shrinkwrap.json +138 -631
  210. package/package.json +7 -6
  211. package/release.json +212 -130
  212. package/lib/callSessions.mjs +0 -51
  213. package/lib/directLink.mjs +0 -349
  214. package/lib/peopleBoard.mjs +0 -131
  215. package/lib/projects.mjs +0 -2917
  216. package/lib/roomChannels.mjs +0 -667
package/README.md CHANGED
@@ -126,7 +126,7 @@ socket and authenticated bridge. Features own their state and command handling:
126
126
  | `runWorker.mjs` | Authorized board execution, workspace slots, holds, requeues and receipts |
127
127
  | `boardFiles.mjs` | File storage, disclosure, redaction and file commands; `boardFileCommands.mjs` is its private command adapter |
128
128
  | `goalCommands.mjs`, `taskCommands.mjs` | Goal/room operations and task lifecycle operations |
129
- | `boardThreads.mjs`, `boardWatches.mjs`, `boardTools.mjs` | Relay-thread messages, watch/digest commands and local tool commands |
129
+ | `boardThreads.mjs`, `boardWatches.mjs`, `boardTools.mjs` | Messages between friends, watch/digest commands and local tool commands |
130
130
  | `boardAccess.mjs` | Plain hosted-call policy and metadata-only responses |
131
131
  | `connectors.mjs`, `connectorAuth.mjs` | Local app credentials, OAuth, discovered tools, scoped agent grants and durable operation receipts |
132
132
 
@@ -157,6 +157,10 @@ intended surface grants, then exercise that caller's runtime path.
157
157
 
158
158
  ## Operations
159
159
 
160
+ When a newer release is published, home tells you once, naming every computer behind it. The buddy's Settings shows
161
+ each computer's version with an Update button under Your devices, and `tryharness status` gives the command. Nothing
162
+ is fetched until you ask: Update runs the signed `tryharness upgrade` on that computer.
163
+
160
164
  ```sh
161
165
  npx tryharness status
162
166
  npx tryharness doctor
@@ -293,8 +297,7 @@ EmbeddingGemma 2's text part (one search space for code, agent sessions and boar
293
297
  two injection guards (one reads long stretches and holds, one reads short ones and flags), a
294
298
  credential detector and a screenshot text reader (PP-OCR), plus llama.cpp's own server build
295
299
  (about 860 MB of models). Two more come down the first time they are used: speech for the buddy's
296
- Talk (Silero VAD, 1.3 MB, and on a Mac with macOS 26 Apple's own on-device transcriber through
297
- the buddy; elsewhere NVIDIA's Parakeet TDT 0.6B v3, 672 MB) and the search model's image and audio part
300
+ Talk (on a Mac with macOS 26 Apple's own on-device transcriber through the buddy, which downloads nothing here; elsewhere LFM3-Omni, 1.4 GB, already on the computer holding the board) and the search model's image and audio part
298
301
  (555 MB) when you first add a folder of recordings or screenshots. The search model runs on the
299
302
  GPU when this machine's check finds it faster, the CPU otherwise; the classifiers run in native
300
303
  ONNX Runtime. Background work runs at the OS's background priority and waits in Low Power Mode,
@@ -310,7 +313,7 @@ What they do:
310
313
  repository, and each run's receipt. Agents can call `search_code`, `search_files`,
311
314
  `compare_screens` (two screenshots of UI work, before and after: what changed and which text)
312
315
  and `search_screen` (what you saw in tabs shared with Harness, asked of your own Harness window
313
- sealed over the `tryharness link` line, so Harness's server carries it unread; your Allow in
316
+ sealed over that browser's line from your device list, so Harness's server carries it unread; your Allow in
314
317
  that window comes first).
315
318
  - **Checks:** a finished run gets a receipt from its own session file; the coordinator hands an
316
319
  untested "tests pass" to an agent to check. An agent's post that reads like orders to the
@@ -358,7 +361,7 @@ daily cap; instead, past 10 hand-offs in a row between your agents with no word
358
361
  reads as orders aimed at your agents, or words through Harness's server it could not read, also wait; a flag is only
359
362
  a label. A task with no folder runs in its thread's scratch folder, and your Start always works on one that waits.
360
363
  Different agents work in one folder side by side; one agent takes one turn at a time there. A task Claude Code or
361
- Codex posts from a session you typed in counts as yours. Work another person's agents ask for runs held in: Claude
364
+ Codex posts from a session you typed in counts as yours. Work another person's agents ask for in a jam runs held in: Claude
362
365
  Code or Codex in restricted mode in a copy of the folder, with none of your credentials, screen, memory,
363
366
  conversations, library, wallet or secrets in reach and no network. It reads only its own folder, git's folder for
364
367
  its repository and the programs it builds with, nothing else of yours, until you press Start; Pi and OpenCode wait
@@ -388,7 +391,7 @@ MCP client, gets it from its extension, which launches it and gives pi its tools
388
391
  Work stays where the agent lives. Bankr, Quotient and Muse live in Harness, not on any machine,
389
392
  so a task posted for one of them (`tryharness board post --for bankr`, or `post_task` from any
390
393
  agent here) goes up the bridge and waits on the server, where Bankr takes it under the limits
391
- the user set in Harness and Quotient answers it with one search over its tracked markets; the
394
+ the user set in Harness and Quotient answers it with research over its tracked markets, assets and forecasts; the
392
395
  daemon must be connected to post it, and `get_task` (or `tryharness board show <id>`) with its
393
396
  id reads it back. A task for a coding agent or Grok Bot waits here. A task for several agents
394
397
  at once is for agents in one place.
@@ -420,20 +423,22 @@ waits on the worker and reaches home when it is back. Only the computer holding
420
423
  tasks, rounds and sweeps. When the copy has to start over, the old one is kept in
421
424
  `~/.harness/board-backups`.
422
425
 
423
- Once home confirms a worker, the two also link directly (HyperDHT), each admitting only the
424
- other's key, so a worker's agents reach home's board even when its line to Harness is down. A call
425
- that gets no answer over the link goes through Harness instead.
426
+ Once home confirms a worker, the two link over WebRTC, introduced through Harness and each
427
+ admitting only the other's key. Their calls, questions and views go over that channel alone, so a
428
+ worker's agents reach home's board even when its line to Harness is down. Harness carries only the
429
+ introduction and, for a worker with no channel, home's notices, which it keeps while the worker is
430
+ away and which wake a cloud computer that sleeps. The worker dials again when its channel ends.
426
431
 
427
432
  A worker can stand in for home when home has been away past `standInAfterMs` in
428
433
  `~/.harness/config.json`. That is unset, so off, until its deadline is measured. While it stands in,
429
434
  the worker holds the board; once home is back it takes the board back with the stand-in's changes
430
435
  and the worker follows it again.
431
436
 
432
- The browser you use Harness in links to this computer, end to end. Setup installs a native
433
- messaging host (`ai.tryharness.daemon`); once the extension is allowed to reach it ("Harness on
434
- this computer" in its setup, an optional permission), the Harness window links by itself. Without
435
- it, `tryharness link` does the same. Each browser is paired with the computer it linked to;
436
- Settings lists every computer's and revokes each where it lives.
437
+ The browser you use Harness in reaches this computer end to end once the browser is approved on
438
+ your device list: you open Harness in it and approve it from a device you already use, and every
439
+ computer on the list answers it. Setup also installs a native messaging host
440
+ (`ai.tryharness.daemon`) so the Harness extension hears this computer and can open a Harness page
441
+ for work that waits on one. Settings lists your devices and removes any of them.
437
442
 
438
443
  Each agent's card names its model and effort and its specialties on that model, each with its
439
444
  evidence: a specialist agent's fixed role (Bankr, Quotient), benchmarks, its record on this board and
@@ -448,9 +453,6 @@ standing functions, held by Harness or by the agent the person appoints.
448
453
  room. Agents read and post in the room with `read_room` and `post_to_room`, and search it, the whole swarm's memory or add to it with `swarm_memory`; mentioning `@codex` or
449
454
  `@claude` wakes that agent with a run in the goal's folder, and jobs they post with the goal as parent run without a
450
455
  Start. Harness facilitates and answers once. `tryharness goal show <id>` prints the room, `goal stop <id>` ends
451
- everything, `goal resume <id>` reopens a room that paused at a backstop, and `goal invite <id> handle/agent` asks another
452
- person's agent to join as a guest over a relay thread. `tryharness room post <goal> <text> [--guests]` posts as you.
456
+ everything, and `goal resume <id>` reopens a room that paused at a backstop. `tryharness room post <goal> <text>` posts as you.
457
+ Work with other people's agents happens only in a jam (PRODUCT.md, "Working with other people").
453
458
 
454
- Parakeet TDT 0.6B v3 is by NVIDIA, licensed under CC BY 4.0
455
- (https://creativecommons.org/licenses/by/4.0/); the relay uses the 8-bit ONNX export by
456
- istupakov (https://huggingface.co/istupakov/parakeet-tdt-0.6b-v3-onnx), unmodified.
@@ -15,6 +15,12 @@ const harness = () =>
15
15
  () => null
16
16
  );
17
17
 
18
+ // The senses at a tool call (senseCall.mjs): what the session read, and the tripwire on what it writes.
19
+ const sensing = () =>
20
+ import(pathToFileURL(path.join(RUNTIME, "lib", "senseCall.mjs")).href).catch(
21
+ () => null
22
+ );
23
+
18
24
  export const name = "tryharness";
19
25
 
20
26
  const pids = [process.pid, process.ppid];
@@ -51,9 +57,15 @@ export function apply(ctx) {
51
57
  if (!board || !where(agent).session_id) return downstream;
52
58
  await board.notePrompt(AGENT, where(agent), pids);
53
59
  const waiting = await board.takeMessages(AGENT, where(agent).session_id);
60
+ let edge = "";
61
+ try {
62
+ edge = (await sensing())?.edgeAtPause(where(agent).session_id) ?? "";
63
+ } catch {}
54
64
  const text = [
55
65
  waiting.length ? board.messagesText(waiting) : "",
56
66
  await board.boardNudgeIfChanged(AGENT),
67
+ // The edge line waits for the session's pause: its next turn (senseCall.mjs).
68
+ edge,
57
69
  ]
58
70
  .filter(Boolean)
59
71
  .join("\n\n");
@@ -61,12 +73,71 @@ export function apply(ctx) {
61
73
  ? { ...downstream, messages: [...downstream.messages, message(text)] }
62
74
  : downstream;
63
75
  });
64
- // A turn about to end: a message waiting from Harness keeps it going; otherwise the session waits for the person.
76
+ // Before a tool call: a write that would undo a change the session has not seen is denied, with the change, until it
77
+ // reads it. Another policy's denial stands.
78
+ ctx.on("tools/pre-execute", async (exec, next) => {
79
+ const downstream = await next();
80
+ const session = exec?.agent?.session?.header?.id;
81
+ if (downstream?.kind !== "allow" || !session) return downstream;
82
+ const sense = await sensing();
83
+ let held = null;
84
+ try {
85
+ held = sense?.beforeCall({
86
+ session,
87
+ cwd: process.cwd(),
88
+ tool: exec?.name,
89
+ input: exec?.arguments,
90
+ });
91
+ } catch {}
92
+ return held?.hold ? { kind: "deny", reason: held.hold } : downstream;
93
+ });
94
+ // After a tool call: what it read and wrote, and what Harness noticed for this session while it works, read with the
95
+ // tool's result, as every other agent's after-call hook gives it (senseHook.mjs --after). DeepSeek Harness adds it
96
+ // before the next request.
97
+ ctx.on("tools/post-execute", async (exec, _result, next) => {
98
+ const downstream = await next();
99
+ const session = exec?.agent?.session?.header?.id;
100
+ const sense = session ? await sensing() : null;
101
+ const said = [];
102
+ try {
103
+ said.push(
104
+ sense?.afterCall({
105
+ session,
106
+ agent: AGENT,
107
+ cwd: process.cwd(),
108
+ tool: exec?.name,
109
+ input: exec?.arguments,
110
+ // The agent's process is this one: its MCP server finds the session by it.
111
+ agentPid: process.pid,
112
+ output: _result?.content ?? _result,
113
+ })
114
+ );
115
+ said.push(sense?.notesAtStep(session, exec?.name ?? null));
116
+ } catch {}
117
+ const text = said.filter(Boolean).join("\n\n");
118
+ if (!text) return downstream;
119
+ return {
120
+ ...downstream,
121
+ additionalContexts: [
122
+ message(text),
123
+ ...(downstream?.additionalContexts ?? []),
124
+ ],
125
+ };
126
+ });
127
+ // A turn about to end: a message waiting from Harness, the person's words or a reading that would have woken it keep
128
+ // it going (nudge.mjs steersAtTurnEnd); otherwise the session waits for the person.
65
129
  ctx.on("agent/turn-stopping", async ({ agent }) => {
66
130
  const board = await harness();
67
- if (!board || !where(agent).session_id) return;
68
- const waiting = await board.takeMessages(AGENT, where(agent).session_id);
69
- if (waiting.length) agent.steer(message(board.messagesText(waiting)));
131
+ const session = where(agent).session_id;
132
+ if (!board || !session) return;
133
+ const waiting = await board.takeMessages(AGENT, session);
134
+ const text = [
135
+ waiting.length ? board.messagesText(waiting) : "",
136
+ board.steersAtTurnEnd(session),
137
+ ]
138
+ .filter(Boolean)
139
+ .join("\n\n");
140
+ if (text) agent.steer(message(text));
70
141
  else await board.noteTurn(AGENT, where(agent), pids);
71
142
  });
72
143
  }
@@ -0,0 +1,367 @@
1
+ // Harness inside Herdr: your swarm's threads beside your agents. Each thread says who works, what it is on, and what
2
+ // waits on you; clicking one goes to its Herdr space, where its agents' turns run. Asking here starts a thread in the
3
+ // focused terminal's folder. Everything comes from `tryharness herdr` (Harness's CLI), so the panel holds no logic.
4
+ import { View, div, svg } from "gpui-kit";
5
+ import { v_flex, h_flex, InputState, Input } from "gpui-base";
6
+ import { exec, focused, nextCommand, notify, run, spaces, theme } from "herdr";
7
+
8
+ // Threads change at the speed of agents' turns: a read every few seconds is enough, and costs one CLI call.
9
+ const READ_EVERY_MS = 4000;
10
+
11
+ /** Where a thread asked here works: the focused terminal's folder, else the shown space's (the panel itself focused). */
12
+ const askFolder = () =>
13
+ focused()?.cwd || spaces().find((space) => space.active)?.folder || null;
14
+
15
+ const order = (a, b) =>
16
+ b.needsYou - a.needsYou ||
17
+ b.working.length - a.working.length ||
18
+ String(b.at ?? "").localeCompare(String(a.at ?? ""));
19
+
20
+ export default class Harness extends View {
21
+ init(_props, cx) {
22
+ this.threads = [];
23
+ this.problem = null;
24
+ this.sending = false;
25
+ this.needs = new Map();
26
+ this.showing = new Set();
27
+ this.posts = new Map();
28
+ this.input = InputState.new({ placeholder: "Ask your swarm…" });
29
+ this.input.on("submit", (_e, cx) => this.ask(cx));
30
+ this.replyTo = null;
31
+ cx.timer.every(READ_EVERY_MS, (cx) => this.read(cx));
32
+ this.read(cx);
33
+ // Its commands, for keys bound in Herdr's keys.json ("harness.next", "harness.ask") or `herdr-app do harness.next`.
34
+ cx.spawn(async (cx) => {
35
+ for (;;) {
36
+ const command = await nextCommand();
37
+ if (command === "next") this.next();
38
+ if (command === "ask") this.input.focus();
39
+ cx.notify();
40
+ }
41
+ });
42
+ }
43
+
44
+ replying() {
45
+ return this.threads.find((thread) => thread.id === this.replyTo) ?? null;
46
+ }
47
+
48
+ /** To the space of the thread that most wants the person: waiting on them, else working, else the latest. */
49
+ next() {
50
+ const shown = this.threads.find((thread) => thread.space);
51
+ if (shown) this.open(shown);
52
+ }
53
+
54
+ read(cx) {
55
+ cx.spawn(async (cx) => {
56
+ try {
57
+ const out = await exec("tryharness", ["herdr", "board"]);
58
+ if (out.code !== 0)
59
+ throw new Error(out.stderr.trim().split("\n").at(-1) || "no answer");
60
+ this.threads = JSON.parse(out.stdout).threads.sort(order);
61
+ for (const id of this.showing) this.readPosts(id, cx);
62
+ this.problem = null;
63
+ this.tell();
64
+ } catch {
65
+ // What failed is in Harness's own logs; here, what to do about it.
66
+ this.problem =
67
+ "Harness isn't running on this computer. Start it with: npx tryharness";
68
+ }
69
+ cx.notify();
70
+ });
71
+ }
72
+
73
+ /** A thread that starts waiting on you says so once, with a way to its space. */
74
+ tell() {
75
+ for (const thread of this.threads) {
76
+ const before = this.needs.get(thread.id) ?? 0;
77
+ if (thread.needsYou > before)
78
+ notify({
79
+ title: `${thread.title} needs you`,
80
+ body: thread.line ?? undefined,
81
+ level: "warning",
82
+ ...(thread.space
83
+ ? { action: { name: "space.select", args: { id: thread.space } } }
84
+ : {}),
85
+ });
86
+ this.needs.set(thread.id, thread.needsYou);
87
+ }
88
+ }
89
+
90
+ /** Enter: into the thread being replied to, else a new thread in the shown folder. */
91
+ ask(cx) {
92
+ const text = this.input.value().trim();
93
+ if (!text || this.sending) return;
94
+ const reply = this.threads.find((thread) => thread.id === this.replyTo);
95
+ const folder = askFolder();
96
+ if (!reply && !folder) {
97
+ this.problem =
98
+ "Open a space in the folder the thread should work in, then ask.";
99
+ return cx.notify();
100
+ }
101
+ this.sending = true;
102
+ cx.notify();
103
+ const args = reply
104
+ ? ["herdr", "post", reply.id, text]
105
+ : ["herdr", "start", folder, text];
106
+ cx.spawn(async (cx) => {
107
+ const out = await exec("tryharness", args).catch((error) => ({
108
+ code: 1,
109
+ stderr: String(error.message ?? error),
110
+ }));
111
+ this.sending = false;
112
+ if (out.code === 0) this.input.set_value("");
113
+ else
114
+ this.problem = `Harness didn't take it: ${out.stderr.trim().split("\n").at(-1)}`;
115
+ this.read(cx);
116
+ });
117
+ }
118
+
119
+ /** A thread clicked: its space shown, and what is typed next goes into it. */
120
+ open(thread) {
121
+ this.replyTo = thread.id;
122
+ if (thread.space) run("space.select", { id: thread.space });
123
+ else exec("tryharness", ["desktop"]).catch(() => null);
124
+ }
125
+
126
+ mark(thread, t) {
127
+ if (thread.needsYou)
128
+ return div()
129
+ .flex_none()
130
+ .px(6)
131
+ .h(18)
132
+ .rounded(5)
133
+ .bg(t.blocked + "26")
134
+ .text_size(10.5)
135
+ .font_semibold()
136
+ .text_color(t.blocked)
137
+ .flex()
138
+ .items_center()
139
+ .child("Needs you");
140
+ if (thread.working.length)
141
+ return svg("mods/workspace-chrome/spinner.svg")
142
+ .size(12)
143
+ .mx(1)
144
+ .flex_none()
145
+ .text_color(t.working)
146
+ .spin(900);
147
+ return div()
148
+ .size(7)
149
+ .mx(3)
150
+ .flex_none()
151
+ .rounded(4)
152
+ .border(1.5)
153
+ .border_color(t.idle ?? t.dim);
154
+ }
155
+
156
+ render() {
157
+ const t = theme();
158
+ const rows = this.threads.map((thread) =>
159
+ v_flex().child(this.row(thread, t)).child(this.shown(thread, t))
160
+ );
161
+ return this.frame(rows, t);
162
+ }
163
+
164
+ /** A thread's line: click to go to its space and reply into it. */
165
+ row(thread, t) {
166
+ return v_flex()
167
+ .id(`hs-${thread.id}`)
168
+ .gap(2)
169
+ .px(10)
170
+ .py(7)
171
+ .rounded(7)
172
+ .cursor_pointer()
173
+ .hover((s) => s.bg(t.hover ?? t.raised))
174
+ .on_click(() => this.open(thread))
175
+ .child(
176
+ h_flex()
177
+ .gap(7)
178
+ .items_center()
179
+ .child(this.mark(thread, t))
180
+ .child(
181
+ div()
182
+ .flex_1()
183
+ .min_w(0)
184
+ .truncate()
185
+ .text_size(12.5)
186
+ .text_color(t.foreground)
187
+ .child(thread.title)
188
+ )
189
+ )
190
+ .when(Boolean(thread.line), (el) =>
191
+ el.child(
192
+ div()
193
+ .pl(20)
194
+ .truncate()
195
+ .text_size(11.5)
196
+ .text_color(t.muted)
197
+ .child(thread.line)
198
+ )
199
+ )
200
+ .when(thread.working.length > 0, (el) =>
201
+ el.child(
202
+ div()
203
+ .pl(20)
204
+ .truncate()
205
+ .text_size(11)
206
+ .text_color(t.dim)
207
+ .child(`${thread.working.join(", ")} working`)
208
+ )
209
+ );
210
+ }
211
+
212
+ /** Under a thread: its latest posts when shown, read through tryharness herdr read. */
213
+ shown(thread, t) {
214
+ const open = this.showing.has(thread.id);
215
+ const posts = this.posts.get(thread.id) ?? [];
216
+ return v_flex()
217
+ .pl(30)
218
+ .pr(10)
219
+ .pb(6)
220
+ .gap(4)
221
+ .child(
222
+ div()
223
+ .id(`hs-show-${thread.id}`)
224
+ .text_size(11)
225
+ .text_color(t.accent)
226
+ .cursor_pointer()
227
+ .on_click((_e, cx) => this.toggle(thread, cx))
228
+ .child(open ? "Hide posts" : "Show latest posts")
229
+ )
230
+ .when(open, (el) =>
231
+ el.children(
232
+ posts.map((post, index) =>
233
+ v_flex()
234
+ .id(`hs-post-${thread.id}-${index}`)
235
+ .gap(1)
236
+ .child(div().text_size(11).text_color(t.dim).child(post.by))
237
+ .child(
238
+ div().text_size(12).text_color(t.foreground).child(post.text)
239
+ )
240
+ )
241
+ )
242
+ );
243
+ }
244
+
245
+ toggle(thread, cx) {
246
+ if (this.showing.has(thread.id)) this.showing.delete(thread.id);
247
+ else {
248
+ this.showing.add(thread.id);
249
+ this.readPosts(thread.id, cx);
250
+ }
251
+ cx.notify();
252
+ }
253
+
254
+ /** A shown thread's posts, read again with the board. */
255
+ readPosts(id, cx) {
256
+ cx.spawn(async (cx) => {
257
+ const out = await exec("tryharness", ["herdr", "read", id]).catch(
258
+ () => null
259
+ );
260
+ try {
261
+ if (out?.code === 0) this.posts.set(id, JSON.parse(out.stdout).posts);
262
+ } catch {}
263
+ cx.notify();
264
+ });
265
+ }
266
+
267
+ frame(rows, t) {
268
+ return v_flex()
269
+ .id("harness")
270
+ .size_full()
271
+ .min_h(0)
272
+ .bg(t.chrome ?? t.surface)
273
+ .text_color(t.foreground)
274
+ .child(
275
+ h_flex()
276
+ .px(12)
277
+ .pt(12)
278
+ .pb(8)
279
+ .items_center()
280
+ .child(div().flex_1().text_size(13).font_semibold().child("Harness"))
281
+ .child(
282
+ div()
283
+ .text_size(11)
284
+ .text_color(t.dim)
285
+ .child(
286
+ `${this.threads.length} ${this.threads.length === 1 ? "thread" : "threads"}`
287
+ )
288
+ )
289
+ )
290
+ .child(
291
+ div()
292
+ .px(10)
293
+ .pb(8)
294
+ .child(
295
+ Input.new(this.input)
296
+ .h(32)
297
+ .px(9)
298
+ .rounded(8)
299
+ .border_1()
300
+ .border_color(t.input)
301
+ .bg(t.background)
302
+ .text_size(12.5)
303
+ .text_color(t.foreground)
304
+ )
305
+ )
306
+ .child(
307
+ div()
308
+ .px(12)
309
+ .pb(6)
310
+ .text_size(11)
311
+ .text_color(t.dim)
312
+ .child(
313
+ this.sending
314
+ ? "Sending…"
315
+ : this.replying()
316
+ ? `Enter posts to ${this.replying().title}.`
317
+ : `Enter starts a thread in ${askFolder() ?? "this space's folder"}.`
318
+ )
319
+ )
320
+ .when(Boolean(this.replying()) && !this.sending, (el) =>
321
+ el.child(
322
+ div()
323
+ .id("hs-new-thread")
324
+ .px(12)
325
+ .pb(8)
326
+ .text_size(11)
327
+ .text_color(t.accent)
328
+ .cursor_pointer()
329
+ .on_click((_e, cx) => {
330
+ this.replyTo = null;
331
+ cx.notify();
332
+ })
333
+ .child("Start a new thread instead")
334
+ )
335
+ )
336
+ .when(Boolean(this.problem), (el) =>
337
+ el.child(
338
+ div()
339
+ .px(12)
340
+ .pb(8)
341
+ .text_size(11.5)
342
+ .text_color(t.blocked)
343
+ .child(this.problem)
344
+ )
345
+ )
346
+ .when(!this.problem && this.threads.length === 0, (el) =>
347
+ el.child(
348
+ div()
349
+ .px(12)
350
+ .text_size(12)
351
+ .text_color(t.dim)
352
+ .child(
353
+ "No threads yet. Ask above, and your agents take it from there."
354
+ )
355
+ )
356
+ )
357
+ .child(
358
+ v_flex()
359
+ .id("hs-list")
360
+ .flex_1()
361
+ .min_h(0)
362
+ .px(4)
363
+ .overflow_y_scrollbar()
364
+ .children(rows)
365
+ );
366
+ }
367
+ }
@@ -0,0 +1,6 @@
1
+ {
2
+ "place": "right",
3
+ "size": 300,
4
+ "title": "Harness",
5
+ "overlay": { "width": 420, "height": 560 }
6
+ }