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
@@ -37,6 +37,7 @@ import {
37
37
  } from "./runAuthority.mjs";
38
38
  import { prepareScratch, threadScratch } from "./scratch.mjs";
39
39
  import { restrictedRun } from "./runWorker.mjs";
40
+ import { sessionOfPid, sessionReceipt } from "./senseCall.mjs";
40
41
 
41
42
  // An agent working in a thread may bring another agent in for part of the work there, as Harness does when it names
42
43
  // one; an agent that moves money or takes positions joins only when the person names it (members.mjs TAGGED_ONLY).
@@ -71,11 +72,11 @@ export function createTaskCommands({
71
72
  lastSeen,
72
73
  lessons,
73
74
  madeIn,
74
- getNetwork,
75
- getProjects = () => null,
76
75
  notifyBoard,
77
76
  openTaskRoom,
78
77
  openThreadPost,
78
+ // A friendship was taken here: its channel with that person opens now (peopleLink.mjs).
79
+ friendshipTaken = () => {},
79
80
  pauseGoal,
80
81
  placesOf,
81
82
  restrictable,
@@ -107,10 +108,12 @@ export function createTaskCommands({
107
108
  }),
108
109
  }) {
109
110
  // The one open thread an agent is working in now, when the work it hands on may join it there.
110
- const soleThreadOf = (agent, target, folder) => {
111
- const working = store.threadsWorkedIn(agent);
112
- const thread = working.length === 1 ? store.getTask(working[0]) : null;
113
- return thread &&
111
+ const threadOfRun = (request, target, folder) => {
112
+ const run = callerRun(request);
113
+ const parent = run ? store.getTask(run.id)?.parent_id : null;
114
+ const thread = parent ? store.getTask(parent) : null;
115
+ return thread?.kind === "goal" &&
116
+ thread.status === "open" &&
114
117
  joinsThread(thread, target, ROOM_AGENTS) &&
115
118
  sameFolder(thread, folder)
116
119
  ? thread.id
@@ -182,6 +185,7 @@ export function createTaskCommands({
182
185
  readOnly: store.meta(`review:${task.id}`) === "1",
183
186
  restricted: restrictedRun(store, task),
184
187
  ownSettingsOnly: store.meta(`other-person-run:${task.id}`) === "1",
188
+ jamThread: store.meta(`jam-run:${task.id}`) || null,
185
189
  });
186
190
  return (request, { agent, id, expected, machine }) => {
187
191
  if (request.command.startsWith("board.dispatch."))
@@ -200,20 +204,19 @@ export function createTaskCommands({
200
204
  fromCloud(store, request) &&
201
205
  !["user", "harness"].includes(agent);
202
206
  const noGo = Boolean(request.hostedCaller) || cloud;
207
+ // A friendship Harness posts: taken only once this computer has pinned the other person's key (sealedThreads.mjs).
203
208
  if (
204
209
  request.command === "board.post" &&
205
210
  request.thread &&
206
211
  typeof request.thread === "object" &&
207
- !request.thread[OPENED] &&
208
- (request.thread.sealed ||
209
- (request.thread.role === "asker" &&
210
- store.meta(`relay_pending:${String(request.id || "")}`)))
212
+ !request.thread[OPENED]
211
213
  ) {
212
214
  return {
213
215
  pending: openThreadPost(request).then((prepared) => {
214
216
  const posted = boardCommand(prepared);
215
217
  if (!posted?.ok)
216
218
  throw new Error(posted?.error || "the thread was not posted");
219
+ friendshipTaken();
217
220
  return posted;
218
221
  }),
219
222
  };
@@ -292,7 +295,7 @@ export function createTaskCommands({
292
295
  // for work outside any thread: placing it grants nothing.
293
296
  const workingThread =
294
297
  !request.parentId && !request.thread && agent !== "user"
295
- ? soleThreadOf(agent, request.targetAgent, request.runWorkspace)
298
+ ? threadOfRun(request, request.targetAgent, request.runWorkspace)
296
299
  : null;
297
300
  // Provenance is code's: the local parent's label and what Harness sent from above the poster can only tighten it.
298
301
  const parentTask = request.parentId
@@ -439,14 +442,15 @@ export function createTaskCommands({
439
442
  : null,
440
443
  });
441
444
  if (!placed.ok) return { ok: false, error: placed.error };
442
- const targetMachine = placed.machine;
443
- const elsewhere =
444
- Boolean(targetMachine) && targetMachine !== machines.self();
445
+ const placedMachine = placed.machine;
446
+ const placedAway =
447
+ Boolean(placedMachine) && placedMachine !== machines.self();
445
448
  // Left out, a task from a coding agent for a coding agent runs in the folder the poster works in (its stdio MCP's,
446
- // which each agent starts in the session's folder); never home or above it. A folder named on another computer is
447
- // that computer's.
449
+ // which each agent starts in the session's folder); never home or above it. That folder is on the poster's
450
+ // computer: work it sends to another computer has no folder, and runs in a scratch folder there. A folder named on
451
+ // another computer is that computer's.
448
452
  const posterFolder =
449
- (!fromElsewhere || targetMachine === machine) &&
453
+ (!fromElsewhere || placedMachine === machine) &&
450
454
  !request.thread &&
451
455
  !goalParent &&
452
456
  request.inSession !== true &&
@@ -457,7 +461,7 @@ export function createTaskCommands({
457
461
  // any covered run (same daily limit, same off switch) instead of waiting for a session to look at the board.
458
462
  const target = String(request.targetAgent || "");
459
463
  const scratch =
460
- !elsewhere &&
464
+ !placedAway &&
461
465
  !request.runWorkspace &&
462
466
  !goalParent &&
463
467
  !posterFolder &&
@@ -469,16 +473,28 @@ export function createTaskCommands({
469
473
  ? authority.scratchFolder(target)
470
474
  : null;
471
475
  if (scratch) fs.mkdirSync(scratch, { recursive: true });
472
- const runWorkspace = request.runWorkspace
476
+ const wantedFolder = request.runWorkspace
473
477
  ? String(request.runWorkspace)
474
478
  : goalParent?.goal.workspace && authority.RUNNERS.has(target)
475
479
  ? goalParent.goal.workspace
476
480
  : (posterFolder ?? scratch);
477
- if (runWorkspace && !path.isAbsolute(runWorkspace))
481
+ if (wantedFolder && !path.isAbsolute(wantedFolder))
478
482
  return {
479
483
  ok: false,
480
484
  error: "a run needs an absolute workspace directory",
481
485
  };
486
+ const { machine: targetMachine, folder: runWorkspace } =
487
+ machines.placeFolder({
488
+ agent: target,
489
+ folder: wantedFolder,
490
+ target: placedMachine,
491
+ named: Boolean(
492
+ address?.forAgent(recipient)?.id ?? request.targetMachine
493
+ ),
494
+ leftOut: !request.runWorkspace && wantedFolder === posterFolder,
495
+ });
496
+ const elsewhere =
497
+ Boolean(targetMachine) && targetMachine !== machines.self();
482
498
  if (
483
499
  runWorkspace &&
484
500
  !request.targetAgent &&
@@ -510,6 +526,7 @@ export function createTaskCommands({
510
526
  trust: provenance.trust,
511
527
  target: String(request.targetAgent),
512
528
  workspace: runWorkspace,
529
+ machine: targetMachine,
513
530
  });
514
531
  if (reason)
515
532
  return {
@@ -601,8 +618,6 @@ export function createTaskCommands({
601
618
  peerKey:
602
619
  thread[OPENED] && thread.peerKey ? String(thread.peerKey) : null,
603
620
  });
604
- getNetwork()?.opened(task.id);
605
- getProjects()?.channelOpened(task.id);
606
621
  }
607
622
  if (pick) setRunPick(store, task.id, pick, agent);
608
623
  // How many times the person's agents have handed this work on since the person last did (runAuthority.mjs
@@ -695,6 +710,7 @@ export function createTaskCommands({
695
710
  into: workingThread,
696
711
  folder: askerFolder,
697
712
  machine,
713
+ askedIn: posterCwd,
698
714
  });
699
715
  const note = task.target_agent
700
716
  ? actors.setupNote(task.target_agent)
@@ -718,7 +734,7 @@ export function createTaskCommands({
718
734
  const proposed =
719
735
  cameAsItSpeaks &&
720
736
  PROPOSERS.includes(agent) &&
721
- task.trust === "agent" &&
737
+ (task.trust === "agent" || (elsewhere && agent !== "user")) &&
722
738
  !thread &&
723
739
  (goalParent ||
724
740
  !request.parentId ||
@@ -1050,17 +1066,6 @@ export function createTaskCommands({
1050
1066
  error:
1051
1067
  "a task given to Harness is taken by an up-to-date Harness window by itself, as its own message; leave it open",
1052
1068
  };
1053
- // The extension's hidden Harness page takes only what the person let it finish in their browser (swarm.mjs
1054
- // board.swarm.use_browser): the message that woke it is no permission.
1055
- else if (
1056
- request.command === "board.claim" &&
1057
- request.browser === true &&
1058
- !store.meta(`harness-browser-allowed:${id}`)
1059
- )
1060
- return {
1061
- ok: false,
1062
- error: "the person has not let Harness use their browser for this",
1063
- };
1064
1069
  else if (request.command === "board.claim") {
1065
1070
  outcome = store.claimTask(
1066
1071
  id,
@@ -1105,6 +1110,12 @@ export function createTaskCommands({
1105
1110
  outcome = { ...outcome, task: store.getTask(id) };
1106
1111
  }
1107
1112
  } else if (request.command === "board.report") {
1113
+ // Work done in the agent's own session has no run receipt: what its hooks kept is its receipt (senseCall.mjs),
1114
+ // kept before the report so the auditor reads it with the claims.
1115
+ if (request.agentPid && !store.meta(`receipt:${id}`)) {
1116
+ const own = sessionReceipt(sessionOfPid(request.agentPid));
1117
+ if (own) store.meta(`receipt:${id}`, JSON.stringify(own));
1118
+ }
1108
1119
  outcome = store.reportTask(
1109
1120
  id,
1110
1121
  agent,
@@ -1130,29 +1141,7 @@ export function createTaskCommands({
1130
1141
  expected,
1131
1142
  machine
1132
1143
  );
1133
- // The hidden Harness page stopped at a question for the person, who may be away: the task waits for them at
1134
- // their computer, saying what it would ask, and is not offered to the browser again until they open Harness. Given
1135
- // back for Harness as this daemon gives back what Harness's server left for the browser (daemon.mjs).
1136
- else if (
1137
- request.command === "board.release" &&
1138
- agent === "harness" &&
1139
- request.browser === true
1140
- ) {
1141
- const task = store.getTask(id);
1142
- if (task?.claimed_by !== "harness" || !store.meta(`harness-window:${id}`))
1143
- return {
1144
- ok: false,
1145
- error: "that is not Harness's work in your browser",
1146
- };
1147
- outcome = store.releaseTask(id, "user", expected);
1148
- if (outcome?.ok) {
1149
- store.meta(`harness-browser-allowed:${id}`, "");
1150
- store.meta(
1151
- `harness-browser-stopped:${id}`,
1152
- String(request.why || "a question for you").slice(0, 300)
1153
- );
1154
- }
1155
- } else if (request.command === "board.release")
1144
+ else if (request.command === "board.release")
1156
1145
  outcome = store.releaseTask(id, agent, expected);
1157
1146
  else if (request.command === "board.remove") {
1158
1147
  if (agent !== "user")
@@ -1288,9 +1277,8 @@ export function createTaskCommands({
1288
1277
  return { ok: true };
1289
1278
  } else if (request.command === "board.machine.finish") {
1290
1279
  const ran = store.getTask(id);
1291
- if (request.usage && ran?.claimed_machine === machine)
1292
- store.setRunUsage(id, request.usage);
1293
- // The run's session, when its own call did not reach home before the finish (machineRuns.mjs).
1280
+ // The run's session, when its own call did not reach home before the finish (machineRuns.mjs). Before its usage,
1281
+ // which is read against the session's earlier runs.
1294
1282
  if (
1295
1283
  typeof request.session === "string" &&
1296
1284
  ran?.claimed_machine === machine &&
@@ -1298,6 +1286,8 @@ export function createTaskCommands({
1298
1286
  !ran.session_id
1299
1287
  )
1300
1288
  store.setRunSession(id, request.session.slice(0, 256));
1289
+ if (request.usage && ran?.claimed_machine === machine)
1290
+ store.setRunUsage(id, request.usage);
1301
1291
  outcome = store.reportTask(
1302
1292
  id,
1303
1293
  agent,
@@ -1338,6 +1328,7 @@ export function createTaskCommands({
1338
1328
  error: "worker inventory needs valid folder and repository entries",
1339
1329
  };
1340
1330
  machines.learn(machine, {
1331
+ home: request.home,
1341
1332
  request:
1342
1333
  typeof request.inventoryRequest === "string"
1343
1334
  ? request.inventoryRequest
package/lib/taskRooms.mjs CHANGED
@@ -19,7 +19,15 @@ export const conversationOf = (task) =>
19
19
  *
20
20
  * `runsHere(agent)` says whether an agent is a coding agent this daemon runs (runAuthority.mjs).
21
21
  */
22
- export function createTaskRooms({ store, worktrees, runsHere, notifyBoard }) {
22
+ export function createTaskRooms({
23
+ store,
24
+ worktrees,
25
+ runsHere,
26
+ self = () => null,
27
+ notifyBoard,
28
+ }) {
29
+ const runsAway = (task) =>
30
+ Boolean(task.target_machine) && task.target_machine !== self();
23
31
  const roomOfConversation = (conversation) => {
24
32
  const room = store.getTask(
25
33
  store.meta(`conversation-room:${conversation}`) || ""
@@ -57,6 +65,7 @@ export function createTaskRooms({ store, worktrees, runsHere, notifyBoard }) {
57
65
  // (threadRuns.mjs). Work in another repository never joins a thread that has one (taskCommands.mjs).
58
66
  const adopted =
59
67
  !room.goal.workspace &&
68
+ !runsAway(task) &&
60
69
  runsHere(task.target_agent) &&
61
70
  task.run_workspace &&
62
71
  offerable(task.run_workspace)
@@ -79,13 +88,14 @@ export function createTaskRooms({ store, worktrees, runsHere, notifyBoard }) {
79
88
  /**
80
89
  * The thread `task` is worked in, opened for it or joined. `into`: the thread the poster is working in, which the
81
90
  * task joins (taskCommands.mjs). `folder`: where a coding agent that asked works, so its turn on the answer runs
82
- * there (answers.mjs) when the task names no folder. `machine`: the computer the poster wrote from.
91
+ * there (answers.mjs) when the task names no folder. `machine`: the computer the poster wrote from. `askedIn`: the
92
+ * folder the poster works in on that computer, which its turn on the answer goes back to when the task runs elsewhere.
83
93
  */
84
94
  const open = (
85
95
  task,
86
96
  poster,
87
97
  provenance,
88
- { into = null, folder = null, machine = null } = {}
98
+ { into = null, folder = null, machine = null, askedIn = null } = {}
89
99
  ) => {
90
100
  const conversation = conversationOf(task);
91
101
  const joined = into
@@ -106,13 +116,29 @@ export function createTaskRooms({ store, worktrees, runsHere, notifyBoard }) {
106
116
  provenance,
107
117
  team,
108
118
  facilitator: DISPATCHER,
109
- workspace: task.run_workspace || folder,
119
+ workspace: runsAway(task) ? null : task.run_workspace || folder,
110
120
  maxPosts: DEFAULT_MAX_POSTS,
111
121
  maxWakes: DEFAULT_MAX_WAKES,
112
122
  });
113
123
  // Its agents work where the task does, as the task would have alone; work another agent asked for gets a copy.
114
124
  if (provenance?.trust === "user") worktrees.inPlace(room.id);
115
125
  store.meta(`task-room:${room.id}`, task.id);
126
+ // The folder is that computer's: the thread's turns go there (threadRuns.mjs), except the asker's, which stays where
127
+ // it asked.
128
+ if (runsAway(task)) {
129
+ if (task.run_workspace) {
130
+ store.meta(
131
+ `thread-folder-on:${room.id}`,
132
+ JSON.stringify({
133
+ machine: task.target_machine,
134
+ path: task.run_workspace,
135
+ })
136
+ );
137
+ store.meta(`thread-work-computer:${room.id}`, task.target_machine);
138
+ }
139
+ store.meta(`asked-from:${room.id}`, machine ?? self() ?? "");
140
+ if (askedIn) store.meta(`asked-in:${room.id}`, askedIn);
141
+ }
116
142
  if (conversation) store.meta(`conversation-room:${conversation}`, room.id);
117
143
  return postJob(room, task, poster, machine);
118
144
  };
@@ -0,0 +1,29 @@
1
+ {
2
+ "ended": ["done", "failed", "unknown"],
3
+ "live": ["open", "claimed", "running", "needs_input"],
4
+ "moves": {
5
+ "claim": { "from": ["open"], "to": ["claimed"] },
6
+ "start": { "from": ["claimed"], "to": ["running"] },
7
+ "report": {
8
+ "from": ["claimed", "running"],
9
+ "to": ["done", "failed", "needs_input"]
10
+ },
11
+ "answer": { "from": ["needs_input"], "to": ["claimed"] },
12
+ "release": { "from": ["claimed", "needs_input"], "to": ["open"] },
13
+ "requeue": { "from": ["running"], "to": ["open"] },
14
+ "lost": { "from": ["running"], "to": ["unknown"] },
15
+ "retire": { "from": ["open"], "to": ["failed"] },
16
+ "stop": {
17
+ "from": ["open", "claimed", "running", "needs_input"],
18
+ "to": ["failed"]
19
+ },
20
+ "close": {
21
+ "from": ["open", "claimed", "running", "needs_input", "unknown"],
22
+ "to": ["done"]
23
+ },
24
+ "rollup": {
25
+ "from": ["open", "claimed", "running", "needs_input"],
26
+ "to": ["done", "failed", "unknown"]
27
+ }
28
+ }
29
+ }
@@ -0,0 +1,21 @@
1
+ import { readFileSync } from "node:fs";
2
+
3
+ // What a board task may do next, for both boards: this computer's (store.mjs) and Harness's hosted one
4
+ // (src/server/relay/hostedBoard.ts). The table is taskRules.json, read by both, so they cannot drift. `unknown` is an
5
+ // ending: a run whose outcome was lost. Only `close` moves on from it, when the thread it belongs to is closed.
6
+ const rules = JSON.parse(
7
+ readFileSync(new URL("./taskRules.json", import.meta.url), "utf8")
8
+ );
9
+
10
+ export const TASK_ENDED = rules.ended;
11
+ export const TASK_REPORTS = rules.moves.report.to;
12
+ export const taskEnded = (status) => rules.ended.includes(status);
13
+ export const taskMay = (move, status) =>
14
+ rules.moves[move].from.includes(status);
15
+
16
+ const sqlList = (statuses) =>
17
+ `(${statuses.map((status) => `'${status}'`).join(", ")})`;
18
+ /** For `status in ${...}`: constants from the table, never anyone's input. */
19
+ export const SQL_ENDED = sqlList(rules.ended);
20
+ export const SQL_LIVE = sqlList(rules.live);
21
+ export const sqlFrom = (move) => sqlList(rules.moves[move].from);
package/lib/taskRuns.mjs CHANGED
@@ -6,6 +6,7 @@ import { paths } from "./paths.mjs";
6
6
  import { runAgentTask } from "./runner.mjs";
7
7
  import { t3TurnUsage } from "./places.mjs";
8
8
  import { runInT3 } from "./t3.mjs";
9
+ import { runInHerdr } from "./herdrRuns.mjs";
9
10
 
10
11
  const TASK_LOG_PAGE = 64_000;
11
12
 
@@ -49,6 +50,11 @@ export function createTaskRuns({
49
50
  // What a run ends saying when any of its agent's calls ran on Harness's AI in place of the person's own link or key
50
51
  // since it started (cloudAi.mjs noteFor), or null.
51
52
  inferenceNote = () => null,
53
+ // Hears each run end once, whatever ran it here (the agent's own process, a herdr tab, T3 Code): completion.mjs puts
54
+ // it in the log.
55
+ onEnded = () => {},
56
+ // Each command a run runs and each file its edit tools change (runner.mjs actsOf), for going in circles (circling.mjs).
57
+ onStep = () => {},
52
58
  }) {
53
59
  const taskRuns = new Map();
54
60
  const validRunId = (runId) =>
@@ -207,6 +213,19 @@ export function createTaskRuns({
207
213
  task.updatedAt = new Date().toISOString();
208
214
  persistTask(task);
209
215
  report(kind, text, extra);
216
+
217
+ if (kind === "done" || kind === "failed")
218
+ try {
219
+ onEnded({
220
+ runId: message.runId,
221
+ agent: message.agent,
222
+ // The run's own session, known here before any copy of the board has it (another computer's run).
223
+ sessionId: task.sessionId ?? null,
224
+ startedAt: task.startedAt,
225
+ kind,
226
+ failure: extra?.failure ?? null,
227
+ });
228
+ } catch {}
210
229
  };
211
230
  const observe = (stream, raw) => {
212
231
  const text = scrub.stream(stream, raw);
@@ -221,17 +240,33 @@ export function createTaskRuns({
221
240
  emit("failed", refused, { failure: "start" });
222
241
  return;
223
242
  }
224
- const hooks = nativeRequests
225
- ? {
226
- requestApproval: (approval, signal) =>
227
- nativeRequests.request({
243
+ const hooks = {
244
+ ...(nativeRequests
245
+ ? {
246
+ requestApproval: (approval, signal) =>
247
+ nativeRequests.request({
248
+ runId: message.runId,
249
+ agent: message.agent,
250
+ approval,
251
+ signal,
252
+ }),
253
+ }
254
+ : {}),
255
+ acted: (act) => {
256
+ try {
257
+ onStep(
258
+ {
228
259
  runId: message.runId,
229
260
  agent: message.agent,
230
- approval,
231
- signal,
232
- }),
233
- }
234
- : {};
261
+ sessionId: task.sessionId ?? null,
262
+ // A turn in T3 Code works in T3's checkout for the thread.
263
+ cwd: message.t3?.checkout || task.cwd || null,
264
+ },
265
+ act
266
+ );
267
+ } catch {}
268
+ },
269
+ };
235
270
  if (message.t3)
236
271
  runInT3(
237
272
  {
@@ -254,11 +289,39 @@ export function createTaskRuns({
254
289
  `[${why} This turn runs on this computer instead, in ${checkout}.]\n`
255
290
  );
256
291
  t3Missed(message.runId, why);
257
- runAgentTask({ ...message, cwd: checkout }, emit, observe, hooks);
292
+ // A fresh session here has none of what the T3 thread was told, so it gets the whole brief.
293
+ runAgentTask(
294
+ {
295
+ ...message,
296
+ cwd: checkout,
297
+ brief: message.t3.wholeBrief ?? message.brief,
298
+ },
299
+ emit,
300
+ observe,
301
+ hooks
302
+ );
303
+ },
304
+ },
305
+ emit,
306
+ observe,
307
+ hooks
308
+ );
309
+ else if (message.herdr)
310
+ runInHerdr(
311
+ {
312
+ ...message,
313
+ // Herdr did not open a tab: the turn runs here as it would have, and says so in its log.
314
+ fallback: (why) => {
315
+ observe(
316
+ "stdout",
317
+ `[${why} This turn runs on this computer instead.]\n`
318
+ );
319
+ runAgentTask(message, emit, observe, hooks);
258
320
  },
259
321
  },
260
322
  emit,
261
- observe
323
+ observe,
324
+ hooks
262
325
  );
263
326
  else runAgentTask(message, emit, observe, hooks);
264
327
  };
package/lib/team.mjs CHANGED
@@ -1,3 +1,4 @@
1
+ import { TASK_ENDED } from "./taskRules.mjs";
1
2
  import { readFileSync } from "node:fs";
2
3
  import { member, nameOf } from "./members.mjs";
3
4
  import { specialtyName } from "./specialties.mjs";
@@ -26,7 +27,7 @@ export const ROLE_IDS = Object.keys(TEAM.roles);
26
27
  export const RIGOR_LEVELS = Object.keys(TEAM.rigor);
27
28
  const stepOf = (id) => ROUTE.find((step) => step.id === id);
28
29
  // Every runner's reported states that end a turn: a question to the person (needs_input) is not the step's end.
29
- const FINISHED = new Set(["done", "failed", "unknown"]);
30
+ const FINISHED = new Set(TASK_ENDED);
30
31
  // The most pieces one framer's split is routed as; more read as one list.
31
32
  const MOST_PIECES = 4;
32
33
 
@@ -58,6 +58,8 @@ export function createThreadActions({
58
58
  threadRuns,
59
59
  asks,
60
60
  boardCommand,
61
+ // The values a thread's watches last read from sources Harness's server reads too, as lines (threadWatches.mjs).
62
+ readingsOf = () => [],
61
63
  ownMachines,
62
64
  threadView,
63
65
  }) {
@@ -86,9 +88,13 @@ export function createThreadActions({
86
88
  /**
87
89
  * Posts one ask as a task in the thread, in its asker's name, so its authority is the asker's (an agent's ask to
88
90
  * Bankr waits for the person). `id`: an agent on Harness's server gets the ask's own id, so a send that may have
89
- * reached Harness is found there rather than posted twice (asks.mjs).
91
+ * reached Harness is found there rather than posted twice (asks.mjs). `offerAs`: who Harness's server is told
92
+ * asked, when that is not the poster (a held read's answer, harnessOffers.mjs).
90
93
  */
91
- const postAsk = (task, { agent, reason, asker, words, id, resend }) => {
94
+ const postAsk = (
95
+ task,
96
+ { agent, reason, asker, words, id, resend, offerAs }
97
+ ) => {
92
98
  const from = inRoom(task, asker) ? asker : task.goal.facilitator;
93
99
  // Only the person's own ask carries the person's authority; an agent's or Harness's is labelled agent-written, so
94
100
  // Bankr holds a send to an address that agent supplied for the person, inside the person's limits.
@@ -110,17 +116,35 @@ export function createThreadActions({
110
116
  agent === "harness"
111
117
  ? briefs.harnessAsk(task, words)
112
118
  : onServer(agent)
113
- ? briefs.specialistHistory(task, words)
119
+ ? briefs.specialistHistory(task, words, agent)
114
120
  : briefs.swarmBrief(task, agent, reason, { ask: true }),
115
121
  targetAgent: agent,
116
122
  parentId: task.id,
117
123
  ...(onServer(agent)
118
- ? { contextRefs: [{ kind: "ask", ref: String(words) }] }
124
+ ? {
125
+ contextRefs: [
126
+ { kind: "ask", ref: String(words) },
127
+ // Quotient's data beside its question (S7.4): the values this thread's watches read from sources Harness's
128
+ // server already reads (Quotient, the person's Bankr wallet), each with its source and age.
129
+ ...(agent === "quotient" && readingsOf(task.id).length
130
+ ? [{ kind: "data", ref: readingsOf(task.id).join("\n") }]
131
+ : []),
132
+ // What the person let this thread spend: the server holds its own work to it.
133
+ ...(store.meta(`spend-ceiling:${task.id}`)
134
+ ? [
135
+ {
136
+ kind: "ceiling",
137
+ ref: String(store.meta(`spend-ceiling:${task.id}`)),
138
+ },
139
+ ]
140
+ : []),
141
+ ],
142
+ }
119
143
  : {}),
120
144
  ...written,
121
145
  });
122
146
  if (agent === "harness" && posted?.ok && posted.task)
123
- harness.offerAsk(task, posted.task.id, from, words);
147
+ harness.offerAsk(task, posted.task.id, offerAs ?? from, words);
124
148
  return posted;
125
149
  };
126
150
 
@@ -150,10 +174,11 @@ export function createThreadActions({
150
174
  /**
151
175
  * The agents a post names, woken. `why`: what they are told in place of "mentioned you" (the coordinator's word to
152
176
  * everyone in a thread). `guard`: the injection guard's reading of the words, where the caller had it read
153
- * (firewall.mjs inspect). `answering`: the agent whose turn is on its own task's answer. `go`: a shared project's go
154
- * for a wake the other side asked for (projects.mjs), in place of the person's own. `target`: the computer the post's
155
- * author chose for the agents it wakes, beside its words. Returns what each ask that did not go at once is waiting
156
- * for, or why it could not go, for the post's author.
177
+ * (firewall.mjs inspect). `answering`: the agent whose turn is on its own task's answer. `go`: a jam's go
178
+ * for a wake the other side asked for (jams.mjs), in place of the person's own. `target`: the computer the post's
179
+ * author chose for the agents it wakes, beside its words. `causes`: the log's numbers of what woke them, for a watch's
180
+ * or a wait's answer (wakePicture.mjs). Returns what each ask that did not go at once is waiting for, or why it could
181
+ * not go, for the post's author.
157
182
  */
158
183
  const wakeFor = (
159
184
  goalId,
@@ -174,6 +199,8 @@ export function createThreadActions({
174
199
  target = null,
175
200
  // The words came from Harness's server itself (runAuthority.mjs HOSTED_CALLER), not just through no local go.
176
201
  server = false,
202
+ // The log's numbers of what woke them, for a watch's or a wait's answer (wakePicture.mjs).
203
+ causes = [],
177
204
  } = {}
178
205
  ) => {
179
206
  const goal = store.goal(goalId);
@@ -218,6 +245,7 @@ export function createThreadActions({
218
245
  );
219
246
  else if (runsHere(agent)) {
220
247
  const assigned = threadRuns().wake(goalId, agent, reason, {
248
+ causes,
221
249
  go:
222
250
  projectGo ??
223
251
  authority.personsGo(author, agent, {
@@ -24,22 +24,22 @@ import {
24
24
  * restricted mode, in a copy of the folder this daemon made. Anything else waits.
25
25
  *
26
26
  * `standingRules()` and `within(folder, root)` come from the run authority (runAuthority.mjs); `worktreeRoot` is where
27
- * this daemon makes its copies of folders, and `projectRoot` where it makes a shared project's lanes (projects.mjs,
28
- * committed with hooks off by projectGit.mjs).
27
+ * this daemon makes its copies of folders, and `jamRoot` where it makes a jam's lanes (jams.mjs,
28
+ * committed with hooks off by jamGit.mjs).
29
29
  */
30
30
  export function createThreadAuthority({
31
31
  store,
32
32
  standingRules,
33
33
  within,
34
34
  worktreeRoot,
35
- projectRoot,
35
+ jamRoot,
36
36
  }) {
37
37
  // The agents with a restricted mode (runner.mjs): Claude Code and Codex.
38
38
  const restrictable = (agent, folder) =>
39
39
  (agent === "claude-code" || agent === "codex") &&
40
40
  Boolean(folder) &&
41
41
  (within(folder, worktreeRoot) ||
42
- (Boolean(projectRoot) && within(folder, projectRoot)));
42
+ (Boolean(jamRoot) && within(folder, jamRoot)));
43
43
 
44
44
  const setToWait = (agent) =>
45
45
  standingRules().find((rule) => rule.agent === agent)?.mode === "off";