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
@@ -1,6 +1,5 @@
1
1
  import fs from "node:fs";
2
2
  import path from "node:path";
3
- import { randomUUID } from "node:crypto";
4
3
  import { stopAgentTask } from "./runner.mjs";
5
4
  import { notifyDesktop } from "./notify.mjs";
6
5
  import { secretReason } from "./secrets.mjs";
@@ -10,6 +9,7 @@ import { picksIn } from "./models.mjs";
10
9
  import { roomPage } from "./roomPage.mjs";
11
10
  import { fromCloud, withComputer } from "./machineRoutes.mjs";
12
11
  import { callerLimit, HOSTED_CALLER } from "./runAuthority.mjs";
12
+ import { withoutNextStep } from "./nextStep.mjs";
13
13
 
14
14
  export function createGoalCommands({
15
15
  DEFAULT_MAX_POSTS,
@@ -18,7 +18,6 @@ export function createGoalCommands({
18
18
  ROOM_AGENTS,
19
19
  available,
20
20
  getActiveRuns,
21
- endGuestThreads,
22
21
  getFirewall,
23
22
  flagNote,
24
23
  // A post's words as an agent reads them (serverWords.mjs agentText); the person reads every post as written.
@@ -33,11 +32,8 @@ export function createGoalCommands({
33
32
  mentionsIn,
34
33
  notifyBoard,
35
34
  pauseGoal,
36
- relayRequest,
37
35
  replaceHeld,
38
- sendThreadMessage,
39
36
  setupNote,
40
- state,
41
37
  store,
42
38
  swarmCommand,
43
39
  validAgent,
@@ -48,7 +44,7 @@ export function createGoalCommands({
48
44
  files: boardFiles,
49
45
  // The thread's team (team.mjs): an agent's note on what it learned in its role.
50
46
  teams = null,
51
- // A note saved in a shared project's room is the project's too (projects.mjs).
47
+ // A note saved in a jam's room is the jam's too (jams.mjs).
52
48
  learned = () => {},
53
49
  // A note is pushed to the swarm's memory (swarmMemory.mjs push), for every agent to pull.
54
50
  remembered = () => {},
@@ -249,9 +245,17 @@ export function createGoalCommands({
249
245
  return { ok: false, error: `${agent} is not on this goal's team` };
250
246
  if (goal.status !== "open")
251
247
  return { ok: false, error: `the goal is ${goal.status}` };
252
- // The person's own words are kept whole; anyone else's post is cut at 20,000 characters.
248
+ // The person's own words are kept whole; anyone else's post is cut at 20,000 characters, and an agent's "Next:"
249
+ // line is its own, for its last message, not the thread's (nextStep.mjs).
253
250
  const said = String(request.text || "").trim();
254
- const text = agent === "user" ? said : said.slice(0, 20000);
251
+ const text =
252
+ agent === "user" ? said : withoutNextStep(said).slice(0, 20000);
253
+ if (!text && said)
254
+ return {
255
+ ok: false,
256
+ error:
257
+ 'a post needs more than a "Next:" line; end your last message with that line instead',
258
+ };
255
259
  if (!text) return { ok: false, error: "a post needs text" };
256
260
  // A model named for an agent (`@codex:gpt-6-luna/high`) must be one it lists, or the post is refused saying why.
257
261
  const picked = picksIn(store, text, ROOM_AGENTS);
@@ -366,25 +370,6 @@ export function createGoalCommands({
366
370
  else if (request.personSaid === true) heardRelayed(goal, post);
367
371
  if (verdict?.verdict === "flag" || verdict?.verdict === "hold")
368
372
  store.meta(`flagged:${post.id}`, String(verdict.score));
369
- // Shared with guests: the post goes out on each guest's thread, held for the owner unless that thread auto-sends.
370
- if (request.shareWithGuests === true)
371
- for (const guest of goal.goal.guests) {
372
- if (
373
- !store.getThread(guest.thread) ||
374
- store.getThread(guest.thread).closed_at
375
- )
376
- continue;
377
- const sent = store.postMessage({
378
- id: randomUUID(),
379
- taskId: guest.thread,
380
- sender: agent,
381
- text,
382
- refs: [],
383
- flagReason: null,
384
- });
385
- if (sent.ok && sent.message.state === "sent")
386
- sendThreadMessage(sent.message);
387
- }
388
373
  if (store.roomCount(goal.id) >= goal.goal.max_posts) {
389
374
  pauseGoal(goal.id, `the room reached ${goal.goal.max_posts} posts`);
390
375
  return { ok: true, post, paused: true };
@@ -481,62 +466,10 @@ export function createGoalCommands({
481
466
  kind: "answer",
482
467
  text: result,
483
468
  });
484
- endGuestThreads(goal, "The goal is done. Thank you.");
485
469
  const task = store.setGoalState(goal.id, { status: "done", result });
486
470
  notifyBoard(task);
487
471
  return { ok: true, task };
488
472
  }
489
- if (request.command === "board.goal.invite") {
490
- // Another person's agent joins as a guest over a relay thread: it sees only what the room shares with guests,
491
- // its words arrive as a stranger's, and it never starts anything on this machine.
492
- if (agent !== "user")
493
- return { ok: false, error: "only the owner invites a guest" };
494
- if (goal.status !== "open")
495
- return { ok: false, error: `the goal is ${goal.status}` };
496
- const to = String(request.to || "").toLowerCase();
497
- if (!/^[a-z0-9-]{3,20}\/(claude-code|codex|pi|opencode)$/.test(to))
498
- return {
499
- ok: false,
500
- error: "invite a guest as handle/agent, for example bob/codex",
501
- };
502
- if (!state.connected)
503
- return { ok: false, error: "the daemon is not connected to Harness" };
504
- const brief = [
505
- `You are invited as a guest to help with a goal: ${goal.objective}`,
506
- goal.brief || "",
507
- "Reply on this thread with findings and results. You see only what the team shares with guests.",
508
- ]
509
- .filter(Boolean)
510
- .join("\n\n");
511
- return {
512
- ok: true,
513
- pending: relayRequest({
514
- to,
515
- fromAgent: "harness",
516
- about: `Goal: ${goal.objective}`.slice(0, 500),
517
- brief,
518
- refs: [],
519
- // A guest whose computer has no key gets a readable invitation only when the person said so (--readable).
520
- readable: request.readable === true,
521
- }).then((response) => {
522
- if (!response.ok)
523
- throw new Error(response.error || "the invitation was refused");
524
- store.addGuest(goal.id, String(response.threadId), to);
525
- store.roomPost({
526
- goalId: goal.id,
527
- author: "user",
528
- kind: "note",
529
- text: `Invited ${to} as a guest. They join once they accept.`,
530
- });
531
- notifyBoard(store.getTask(goal.id));
532
- return {
533
- task: store.getTask(goal.id),
534
- threadId: response.threadId,
535
- status: response.status,
536
- };
537
- }),
538
- };
539
- }
540
473
  if (
541
474
  ["board.goal.stop", "board.goal.resume", "board.goal.folder"].includes(
542
475
  request.command
@@ -560,7 +493,6 @@ export function createGoalCommands({
560
493
  kind: "note",
561
494
  text: "Stopped by the owner.",
562
495
  });
563
- endGuestThreads(goal, "The goal was stopped.");
564
496
  const task = store.setGoalState(goal.id, {
565
497
  status: "failed",
566
498
  result: "Stopped by the owner.",
package/lib/handover.mjs CHANGED
@@ -22,6 +22,26 @@ export const lineFor = (window) =>
22
22
 
23
23
  const count = (value) => Number(value).toLocaleString("en-US");
24
24
 
25
+ /**
26
+ * The window a session's model has: the one the agent itself reported for the session (Codex), else its model's in the
27
+ * lists the agents keep. Claude Code lists none of its own, so its model is found among the Anthropic models Pi and
28
+ * OpenCode list. `{ window, from }`, or null when no list knows it.
29
+ */
30
+ export function windowFor(store, agent, trail) {
31
+ if (trail.window) return { window: trail.window, from: "the session" };
32
+ const model = String(trail.model || "").toLowerCase();
33
+ if (!model) return null;
34
+ for (const lister of [agent, "pi", "opencode"]) {
35
+ const entry = catalogOf(store, lister).find((each) => {
36
+ const id = each.id.toLowerCase();
37
+ return id === model || id.endsWith(`/${model}`);
38
+ });
39
+ if (entry?.context)
40
+ return { window: entry.context, from: `${nameOf(lister)}'s list` };
41
+ }
42
+ return null;
43
+ }
44
+
25
45
  export function createHandover({ store, log, sync }) {
26
46
  const fileOf = async (agent, sessionId, folder) => {
27
47
  const found = () =>
@@ -30,22 +50,7 @@ export function createHandover({ store, log, sync }) {
30
50
  await sync(agent);
31
51
  return found();
32
52
  };
33
- // The window the agent itself reported for the session (Codex), else its model's in the lists the agents keep: Claude
34
- // Code lists none of its own, so its model is found among the Anthropic models Pi and OpenCode list.
35
- const windowOf = (agent, trail) => {
36
- if (trail.window) return { window: trail.window, from: "the session" };
37
- const model = String(trail.model || "").toLowerCase();
38
- if (!model) return null;
39
- for (const lister of [agent, "pi", "opencode"]) {
40
- const entry = catalogOf(store, lister).find((each) => {
41
- const id = each.id.toLowerCase();
42
- return id === model || id.endsWith(`/${model}`);
43
- });
44
- if (entry?.context)
45
- return { window: entry.context, from: `${nameOf(lister)}'s list` };
46
- }
47
- return null;
48
- };
53
+ const windowOf = (agent, trail) => windowFor(store, agent, trail);
49
54
  const replayed = (said) =>
50
55
  said.map(
51
56
  (entry) =>
@@ -8,17 +8,23 @@ const ASKED_WORDS =
8
8
  const said = (post) => !["note", "held", "round"].includes(post.kind);
9
9
 
10
10
  /**
11
- * Harness's server takes a task given to Harness in a thread while no Harness window is open, only while this
12
- * computer's coordinator runs on Harness: on the privacy setting the thread's words stay here and the task waits for a
13
- * window. Harness holds the task meanwhile, so a window that opens does not take it too; what the server leaves for the
14
- * browser goes back on the board, and the window takes it over when it next opens.
11
+ * Harness's server takes a task given to Harness in a thread, only while this computer's coordinator runs on Harness:
12
+ * on the privacy setting the thread's words stay here and the task waits for a window. Harness holds the task
13
+ * meanwhile, so a window does not take it too. Its turn reads and drives the person's browser itself, through the
14
+ * browser's owner (device redesign 3.2), so nothing is handed to a browser from here.
15
15
  *
16
- * `boardCommand()` and `asks()` are made after this module. `serverHas(feature)` says what the connected Harness
16
+ * A read Harness's turn asked of a browser that was not open is held on Harness's server; when the browser answers,
17
+ * the answer comes here (`heldAnswer`), and only for a read this computer was told of with the task's outcome: it is
18
+ * posted as a new ask of Harness in that thread, so Harness's server never puts words in a thread on its own say
19
+ * (owner, November 11: "by my computer but shouldnt rely on the browser").
20
+ *
21
+ * `boardCommand()`, `asks()` and `postAsk()` are made after this module. `serverHas(feature)` says what the connected Harness
17
22
  * supports; `lane` and `model` are the person's own model lane (lane.mjs) and their pick for Harness
18
23
  * (harnessModel.mjs).
19
24
  */
20
25
  export function createHarnessOffers({
21
26
  store,
27
+ approvedCall = () => {},
22
28
  askHarness,
23
29
  connected,
24
30
  serverHas,
@@ -29,9 +35,14 @@ export function createHarnessOffers({
29
35
  lane,
30
36
  model,
31
37
  files,
38
+ postAsk,
39
+ runRequests,
40
+ send,
32
41
  }) {
33
42
  // Harness's tasks its server is working, by task, with their thread: an ask for Harness there goes into that turn.
34
43
  const turns = new Map();
44
+ // What ends the permissions each of those turns is asking the person for, when the turn ends.
45
+ const asking = new Map();
35
46
 
36
47
  // What the person let a thread spend of their Harness credits, for a Harness that checks it.
37
48
  const ceiling = (goalId) => {
@@ -105,7 +116,9 @@ export function createHarnessOffers({
105
116
  ? null
106
117
  : {
107
118
  kind: "note",
108
- text: `This waits for your Harness window: ${why}.`,
119
+ // Since device redesign 3.2 a window takes a thread's task only in fully private mode, so the reason says
120
+ // what is missing, not where to look (copy for the owner's review, November 12).
121
+ text: `Harness can't take this yet: ${why}.`,
109
122
  }
110
123
  );
111
124
  };
@@ -157,6 +170,8 @@ export function createHarnessOffers({
157
170
  // The asks its turn read are answered with it; whoever made them hears its answer as the task's asker does.
158
171
  const turnEnded = (outcome) => {
159
172
  turns.delete(taskId);
173
+ asking.get(taskId)?.abort();
174
+ asking.delete(taskId);
160
175
  const read = outcome?.status === "done" ? (outcome.read ?? []) : [];
161
176
  const askers = asks().turnEnded(goal.id, taskId, read);
162
177
  if (askers.length)
@@ -187,6 +202,12 @@ export function createHarnessOffers({
187
202
  );
188
203
  // Its words are Harness's server's, not the window's: they carry the person's go only on the guard's clean
189
204
  // reading (jobAnswers.mjs).
205
+ // Its reads held for a browser that was not open: their answers are taken from Harness's server only for these.
206
+ for (const read of outcome.held ?? [])
207
+ store.meta(
208
+ `harness-held:${read.id}`,
209
+ JSON.stringify({ goalId: goal.id, taskId, tool: read.tool })
210
+ );
190
211
  if (outcome.status === "done")
191
212
  store.meta(`harness-served:${taskId}`, "1");
192
213
  if (outcome.status === "done")
@@ -197,14 +218,6 @@ export function createHarnessOffers({
197
218
  status: "done",
198
219
  result: outcome.text,
199
220
  });
200
- if (outcome.status === "window") {
201
- // What is left needs the browser: offered to Harness's server again it would only be handed back.
202
- store.meta(`harness-window:${taskId}`, "1");
203
- return back({
204
- kind: "post",
205
- text: `${outcome.text}\n\nThe rest needs your browser: ${outcome.windowOpen ? "your Harness window is taking it over" : "Harness takes it over when your Harness window next opens"}.`,
206
- });
207
- }
208
221
  waits(
209
222
  `Harness could not finish it here${outcome.text ? ` (${outcome.text.slice(0, 300)})` : ""}`
210
223
  );
@@ -259,9 +272,121 @@ export function createHarnessOffers({
259
272
  }
260
273
  };
261
274
 
275
+ /**
276
+ * A tool call Harness's turn on its server parked on the person's approval (an app's write): shown wherever they
277
+ * are, as their agents' own permissions are (runRequests.mjs), and their answer goes back to the turn. Only for a
278
+ * task this computer offered and whose turn still runs.
279
+ */
280
+ const permission = (message) => {
281
+ const taskId = String(message.taskId ?? "");
282
+ if (!turns.has(taskId) || typeof message.requestId !== "string") return;
283
+ const ended = asking.get(taskId) ?? new AbortController();
284
+ asking.set(taskId, ended);
285
+ const tool = String(message.tool ?? "a tool").slice(0, 200);
286
+ const money = message.kind === "money";
287
+ void runRequests()
288
+ .request({
289
+ runId: taskId,
290
+ agent: "harness",
291
+ approval: {
292
+ approvalId: message.requestId,
293
+ currentRequirementId: message.requestId,
294
+ toolName: tool,
295
+ rawArgs: String(message.details ?? ""),
296
+ // A spend past the thread's limit is worded by Harness (src/server/swarm/threadSpend.ts).
297
+ summary: money
298
+ ? String(message.summary ?? "").slice(0, 400)
299
+ : `Harness asks to use ${tool}.`,
300
+ availableChoices: money
301
+ ? [
302
+ {
303
+ choiceId: "once",
304
+ label: "Go ahead",
305
+ decision: "approved",
306
+ scope: "once",
307
+ },
308
+ {
309
+ choiceId: "reject",
310
+ label: "Not now",
311
+ decision: "denied",
312
+ scope: "once",
313
+ },
314
+ ]
315
+ : [
316
+ {
317
+ choiceId: "once",
318
+ label: "Allow",
319
+ decision: "approved",
320
+ scope: "once",
321
+ },
322
+ {
323
+ choiceId: "always",
324
+ label: "Allow for this task",
325
+ decision: "approved",
326
+ scope: "once",
327
+ },
328
+ {
329
+ choiceId: "reject",
330
+ label: "Don't allow",
331
+ decision: "denied",
332
+ scope: "once",
333
+ },
334
+ ],
335
+ },
336
+ signal: ended.signal,
337
+ })
338
+ .then(
339
+ ({ choiceId }) => {
340
+ // Allowed here: if it is a call to one of the person's apps on this computer, that exact call may go ahead.
341
+ if (!money && choiceId !== "reject") {
342
+ let input = null;
343
+ try {
344
+ input = JSON.parse(String(message.details ?? ""));
345
+ } catch {}
346
+ if (input && typeof input === "object") approvedCall(tool, input);
347
+ }
348
+ send({
349
+ type: "harness_permission_answer",
350
+ requestId: message.requestId,
351
+ reply: choiceId,
352
+ });
353
+ },
354
+ // Ended with the turn: Harness's server refuses what is still parked.
355
+ () => {}
356
+ );
357
+ };
358
+
359
+ /** A held read's answer from Harness's server: a new ask of Harness in the thread it was held for. */
360
+ const heldAnswer = (message) => {
361
+ if (typeof message.heldId !== "string") return false;
362
+ let held = null;
363
+ try {
364
+ held = JSON.parse(store.meta(`harness-held:${message.heldId}`) || "null");
365
+ } catch {}
366
+ // Not a read this computer was told of: the server's word alone starts nothing in a thread.
367
+ if (!held) return false;
368
+ store.meta(`harness-held:${message.heldId}`, "");
369
+ const goal = store.getTask(held.goalId);
370
+ if (!goal || goal.kind !== "goal" || goal.status !== "open") return false;
371
+ const from = String(message.browser ?? "the browser").slice(0, 100);
372
+ const words = [
373
+ `${held.tool} on ${from}, held since the browser was closed, ${message.ok ? "answered" : "could not be answered"}:`,
374
+ String(message.text ?? "").slice(0, 18_000),
375
+ ].join("\n\n");
376
+ return Boolean(
377
+ postAsk()(goal, {
378
+ agent: "harness",
379
+ reason: `the read it held came back from ${from}`,
380
+ asker: "harness",
381
+ words,
382
+ offerAs: "held_read",
383
+ })?.ok
384
+ );
385
+ };
386
+
262
387
  /** The task Harness's server is working in a thread now, if any. */
263
388
  const turnOf = (threadId) =>
264
389
  [...turns].find(([, thread]) => thread === threadId)?.[0] ?? null;
265
390
 
266
- return { offerAsk, reofferAll, turnOf };
391
+ return { offerAsk, reofferAll, turnOf, heldAnswer, permission };
267
392
  }
package/lib/herdr.mjs CHANGED
@@ -3,6 +3,7 @@ import os from "node:os";
3
3
  import path from "node:path";
4
4
  import { spawnSync } from "node:child_process";
5
5
  import { hostApp, processTable, tmuxPlace } from "./live.mjs";
6
+ import { appDirs } from "./places.mjs";
6
7
 
7
8
  // A session in a herdr pane (herdr.dev, a terminal workspace for coding agents), opened there. herdr's own server owns
8
9
  // its panes, so the process tree of a session in one leads up to that server, not to a terminal app. Every pane carries
@@ -19,11 +20,12 @@ const DEFAULT_SOCKET = path.join(
19
20
  );
20
21
  const isHerdr = (comm) => path.basename(comm || "") === "herdr";
21
22
 
22
- /** The herdr to speak to a server with: the one its panes name, one running now, else a usual install. */
23
- function herdrBinary(place, table) {
24
- const running = [...table.values()]
25
- .map((row) => row.comm)
26
- .filter((comm) => path.isAbsolute(comm) && isHerdr(comm));
23
+ /**
24
+ * The herdr to speak to a server with: an install where herdr is put, on the daemon's own PATH or the usual folders.
25
+ * Never the binary a pane's environment names (HERDR_BIN_PATH) or a process that only calls itself herdr: anything an
26
+ * agent runs can set the one or start the other, and Open would run it.
27
+ */
28
+ function herdrBinary() {
27
29
  const usual = [
28
30
  ...(process.env.PATH || "").split(path.delimiter),
29
31
  "/opt/homebrew/bin",
@@ -35,10 +37,7 @@ function herdrBinary(place, table) {
35
37
  ]
36
38
  .filter(Boolean)
37
39
  .map((dir) => path.join(dir, "herdr"));
38
- const named = place?.bin ? [place.bin] : [];
39
- return (
40
- [...named, ...running, ...usual].find((file) => fs.existsSync(file)) ?? null
41
- );
40
+ return usual.find((file) => fs.existsSync(file)) ?? null;
42
41
  }
43
42
 
44
43
  /** The socket of the herdr a place belongs to; null when that herdr is not running (its socket is gone). */
@@ -48,9 +47,9 @@ function socketOf(place) {
48
47
  }
49
48
 
50
49
  /** One herdr command against a place's server: its JSON answer, or null when herdr is not there or refused. */
51
- function herdr(place, args, table) {
50
+ function herdr(place, args) {
52
51
  const socket = socketOf(place);
53
- const binary = socket ? herdrBinary(place, table) : null;
52
+ const binary = socket ? herdrBinary() : null;
54
53
  if (!binary) return null;
55
54
  // Not yet measured against a real herdr: the same limit as the other terminals' controls (live.mjs run).
56
55
  const ran = spawnSync(binary, args, {
@@ -108,9 +107,10 @@ export function herdrClient(table = processTable()) {
108
107
  /**
109
108
  * Brings up the pane a running session is in: by the agent herdr sees there, else its tab. The terminal herdr is attached
110
109
  * in ({ pid, tty, host }, to come forward as any terminal does), `{ attach: true }` when herdr runs with no client
111
- * attached, or null when that herdr does not answer. The process table is read now: a client may have just attached.
110
+ * attached, `{ app, herdrApp: true }` for the Herdr app's window, or null when that herdr does not answer. The process table is read now: a client may have just attached.
112
111
  */
113
112
  export function showInHerdr(place, table = processTable({ fresh: true })) {
113
+ if (place?.client === "app") return showInHerdrApp(place);
114
114
  const shown =
115
115
  (place?.pane && herdr(place, ["agent", "focus", place.pane], table)) ||
116
116
  (place?.tab && herdr(place, ["tab", "focus", place.tab], table));
@@ -129,6 +129,7 @@ export function resumeInHerdr(
129
129
  label,
130
130
  table = processTable({ fresh: true })
131
131
  ) {
132
+ if (place?.client === "app") return resumeInHerdrApp(command, folder, label);
132
133
  const where = folder && path.isAbsolute(folder) ? ["--cwd", folder] : [];
133
134
  const named = label ? ["--label", label] : [];
134
135
  const tab =
@@ -153,7 +154,91 @@ export function resumeInHerdr(
153
154
  return herdrClient(table) ?? { attach: true };
154
155
  }
155
156
 
157
+ // ── The Herdr app ─────────────────────────────────────────────────────────────────────────────────────────────────
158
+ // The newer Herdr is a window (herdr-app) over a terminal server (herdr-core). Its terminals carry HC_TERMINAL_ID, their
159
+ // address on the core, and the window takes commands on its own socket, one JSON line each way: `{"do": <command>,
160
+ // "args": {...}}` (agent.focus shows an agent, tab.new opens a tab running a program) and `{"raise": true}` brings it
161
+ // forward. Only the window shows anything; with it closed the terminals keep running in the core.
162
+
163
+ const HERDR_APP = "Herdr.app";
164
+ // The window answers every request within 5 s or says it did not (herdr-app src/control.rs, `recv_timeout`); the rest is
165
+ // starting the node that asks.
166
+ const APP_ANSWER_MS = 6_000;
167
+
168
+ /** The folder the window serves its socket in: HERDR_APP_HOME, else herdr-app under the config folder. */
169
+ function herdrAppHome() {
170
+ if (process.env.HERDR_APP_HOME) return process.env.HERDR_APP_HOME;
171
+ const config =
172
+ process.env.XDG_CONFIG_HOME || path.join(os.homedir(), ".config");
173
+ return path.join(config, "herdr-app");
174
+ }
175
+ const appSocket = () => {
176
+ const socket = path.join(herdrAppHome(), "herdr-app.sock");
177
+ return fs.existsSync(socket) ? socket : null;
178
+ };
179
+ /** Herdr.app where apps are put (the window's own install); null on a computer without it. */
180
+ export const herdrApp = () =>
181
+ appDirs()
182
+ .map((dir) => path.join(dir, HERDR_APP))
183
+ .find((app) => fs.existsSync(app)) ?? null;
184
+
185
+ const CALL = path.join(import.meta.dirname, "herdrAppCall.mjs");
186
+ /** One request to the running window: its answer, or null when no window runs or it refused (`{ "error": ... }`). */
187
+ function askWindow(request) {
188
+ const socket = appSocket();
189
+ if (!socket) return null;
190
+ const ran = spawnSync(
191
+ process.execPath,
192
+ [CALL, socket, JSON.stringify(request)],
193
+ {
194
+ encoding: "utf8",
195
+ timeout: APP_ANSWER_MS,
196
+ stdio: ["ignore", "pipe", "ignore"],
197
+ }
198
+ );
199
+ if (ran.status !== 0) return null;
200
+ try {
201
+ const answer = JSON.parse(ran.stdout);
202
+ return answer && typeof answer === "object" && !answer.error
203
+ ? answer
204
+ : null;
205
+ } catch {
206
+ return null;
207
+ }
208
+ }
209
+
210
+ /** One of the window's commands (herdr-app docs/commands.md): what it made (`{ space, tab, terminal }`), or null. */
211
+ export const herdrAppDo = (command, args) => askWindow({ do: command, args });
212
+
213
+ /** What the buddy brings forward once the window shows something: the app itself, which a raise alone may not activate. */
214
+ const appShown = () => ({ app: herdrApp(), herdrApp: true });
215
+
216
+ function showInHerdrApp(place) {
217
+ if (!askWindow({ do: "agent.focus", args: { terminal: place.terminal } }))
218
+ return null;
219
+ askWindow({ raise: true });
220
+ return appShown();
221
+ }
222
+
223
+ /**
224
+ * A new tab in the window's selected space, on `folder`, running `command` (an agent's resume line or the agent itself:
225
+ * plain words, as places.mjs writes them), named for the agent.
226
+ */
227
+ function resumeInHerdrApp(command, folder, label) {
228
+ const args = {
229
+ argv: command.split(" ").filter(Boolean),
230
+ ...(folder && path.isAbsolute(folder) ? { folder } : {}),
231
+ ...(label ? { name: label } : {}),
232
+ };
233
+ if (!askWindow({ do: "tab.new", args })) return null;
234
+ askWindow({ raise: true });
235
+ return appShown();
236
+ }
237
+
156
238
  /** Whether herdr is on this computer, for an agent's home there; and whether the place's herdr is running now. */
157
- export const herdrInstalled = (place, table = processTable()) =>
158
- Boolean(herdrBinary(place, table));
159
- export const herdrRunning = (place) => Boolean(socketOf(place));
239
+ export const herdrInstalled = (place) =>
240
+ place?.client === "app"
241
+ ? Boolean(herdrApp() || appSocket())
242
+ : Boolean(herdrBinary());
243
+ export const herdrRunning = (place) =>
244
+ place?.client === "app" ? Boolean(appSocket()) : Boolean(socketOf(place));
@@ -0,0 +1,19 @@
1
+ // One request to a running Herdr window, run as its own process so Open can wait for it as it waits for any terminal's
2
+ // command line: node herdrAppCall.mjs <socket> <json>. The window answers one JSON line per request (herdr-app
3
+ // src/control.rs); that line is printed as it came.
4
+ import net from "node:net";
5
+
6
+ const [socket, request] = process.argv.slice(2);
7
+ const connection = net.createConnection(socket, () =>
8
+ connection.write(`${request}\n`)
9
+ );
10
+ let answer = "";
11
+ connection.setEncoding("utf8");
12
+ connection.on("data", (chunk) => {
13
+ answer += chunk;
14
+ if (!answer.includes("\n")) return;
15
+ process.stdout.write(answer.split("\n")[0]);
16
+ connection.end();
17
+ });
18
+ connection.on("error", () => process.exit(1));
19
+ connection.on("close", () => process.exit(answer ? 0 : 1));
@@ -0,0 +1,59 @@
1
+ import net from "node:net";
2
+
3
+ // herdr-core (`hc`), the server that owns the Herdr app's terminals: JSON-RPC 2.0, one message per line, on the socket
4
+ // every terminal it runs names (HC_TERMINAL_SOCKET). No handshake for plain calls (herdr-core schema/README.md). Its
5
+ // errors carry a stable kind (`data.kind`: not_found, finished, ...).
6
+
7
+ class CoreError extends Error {
8
+ constructor(kind, message) {
9
+ super(message);
10
+ this.kind = kind;
11
+ }
12
+ }
13
+
14
+ /**
15
+ * One call on a core: its result, or a CoreError (kind `unreachable` when the core is not there). No deadline of its
16
+ * own: the core bounds its waits itself (a send waits at most 60 s for a person's draft, herdr-core SKILL.md), and none
17
+ * of these calls has been measured against a real core to set one by.
18
+ */
19
+ export function callCore(socket, method, params) {
20
+ return new Promise((resolve, reject) => {
21
+ if (!socket)
22
+ return reject(new CoreError("unreachable", "no herdr-core socket"));
23
+ const connection = net.createConnection(socket);
24
+ let buffer = "";
25
+ const settle = (fn, value) => {
26
+ connection.destroy();
27
+ fn(value);
28
+ };
29
+ connection.setEncoding("utf8");
30
+ connection.on("connect", () =>
31
+ connection.write(
32
+ `${JSON.stringify({ jsonrpc: "2.0", id: 1, method, params })}\n`
33
+ )
34
+ );
35
+ connection.on("data", (chunk) => {
36
+ buffer += chunk;
37
+ const end = buffer.indexOf("\n");
38
+ if (end < 0) return;
39
+ let reply;
40
+ try {
41
+ reply = JSON.parse(buffer.slice(0, end));
42
+ } catch {
43
+ return settle(
44
+ reject,
45
+ new CoreError("protocol", "herdr-core sent bad JSON")
46
+ );
47
+ }
48
+ if (reply.error)
49
+ return settle(
50
+ reject,
51
+ new CoreError(reply.error.data?.kind ?? "error", reply.error.message)
52
+ );
53
+ settle(resolve, reply.result);
54
+ });
55
+ connection.on("error", () =>
56
+ settle(reject, new CoreError("unreachable", "herdr-core is not running"))
57
+ );
58
+ });
59
+ }