tryharness 0.7.83 → 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 (215) 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 +191 -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 +52 -0
  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 +2426 -338
  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 +1 -1
  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/originals.mjs +216 -0
  107. package/lib/outsideEvents.mjs +383 -0
  108. package/lib/outsideRuns.mjs +230 -0
  109. package/lib/ownMachines.mjs +674 -256
  110. package/lib/pain.mjs +215 -0
  111. package/lib/pairing.mjs +91 -11
  112. package/lib/paths.mjs +42 -3
  113. package/lib/peerProcess.mjs +21 -7
  114. package/lib/peopleLink.mjs +268 -0
  115. package/lib/personNotices.mjs +3 -2
  116. package/lib/phones.mjs +252 -542
  117. package/lib/placeCards.mjs +282 -0
  118. package/lib/placeChecks.mjs +95 -0
  119. package/lib/placeCommands.mjs +8 -17
  120. package/lib/placeRequests.mjs +152 -0
  121. package/lib/placeStore.mjs +295 -0
  122. package/lib/placeTool.d.ts +12 -0
  123. package/lib/placeTool.js +40 -0
  124. package/lib/places.mjs +63 -14
  125. package/lib/plans.mjs +53 -8
  126. package/lib/presence.mjs +270 -0
  127. package/lib/privateNetwork.d.ts +2 -0
  128. package/lib/privateNetwork.js +93 -0
  129. package/lib/proposals.mjs +300 -0
  130. package/lib/publicFetch.d.ts +32 -0
  131. package/lib/publicFetch.js +248 -0
  132. package/lib/reach.mjs +128 -0
  133. package/lib/rebuildable.mjs +72 -0
  134. package/lib/recall.mjs +216 -0
  135. package/lib/record.mjs +13 -0
  136. package/lib/reflexes.mjs +392 -0
  137. package/lib/relayLimits.mjs +31 -2
  138. package/lib/releaseNotice.mjs +198 -0
  139. package/lib/removeHarness.mjs +15 -4
  140. package/lib/repoLinks.mjs +204 -35
  141. package/lib/runAuthority.mjs +102 -39
  142. package/lib/runBrief.mjs +93 -40
  143. package/lib/runRequests.mjs +52 -14
  144. package/lib/runUsage.mjs +31 -0
  145. package/lib/runWorker.mjs +74 -25
  146. package/lib/runner.mjs +289 -45
  147. package/lib/runtime-install.mjs +37 -8
  148. package/lib/schedules.mjs +171 -47
  149. package/lib/screenWatches.mjs +221 -0
  150. package/lib/sealed.mjs +12 -30
  151. package/lib/sealedThreads.mjs +198 -392
  152. package/lib/secretStore.mjs +178 -0
  153. package/lib/secrets.mjs +11 -0
  154. package/lib/seen.mjs +3 -9
  155. package/lib/selfUpdate.mjs +51 -15
  156. package/lib/senseCall.mjs +1514 -0
  157. package/lib/senseHook.mjs +114 -0
  158. package/lib/senseTools.mjs +1298 -0
  159. package/lib/sessionBriefs.mjs +87 -0
  160. package/lib/sessionControl.mjs +63 -13
  161. package/lib/sessionFiles.mjs +85 -0
  162. package/lib/setupChoices.mjs +12 -3
  163. package/lib/setupMode.mjs +70 -25
  164. package/lib/sharedKeys.mjs +166 -0
  165. package/lib/sleep.mjs +396 -0
  166. package/lib/sources.mjs +306 -0
  167. package/lib/speech.mjs +166 -411
  168. package/lib/spoken.mjs +210 -0
  169. package/lib/steerHook.mjs +3 -1
  170. package/lib/steerQueue.mjs +40 -11
  171. package/lib/store.mjs +323 -130
  172. package/lib/stuck.mjs +85 -7
  173. package/lib/swarm.mjs +157 -49
  174. package/lib/swarmDevices.mjs +25 -85
  175. package/lib/swarmMemory.mjs +93 -9
  176. package/lib/t3.mjs +73 -3
  177. package/lib/taskCommands.mjs +51 -60
  178. package/lib/taskRooms.mjs +30 -4
  179. package/lib/taskRules.json +29 -0
  180. package/lib/taskRules.mjs +21 -0
  181. package/lib/taskRuns.mjs +74 -11
  182. package/lib/team.mjs +2 -1
  183. package/lib/threadActions.mjs +37 -9
  184. package/lib/threadAuthority.mjs +4 -4
  185. package/lib/threadBriefs.mjs +173 -43
  186. package/lib/threadNotes.mjs +320 -0
  187. package/lib/threadRecord.mjs +491 -0
  188. package/lib/threadRuns.mjs +216 -108
  189. package/lib/threadView.mjs +27 -30
  190. package/lib/threadWatches.mjs +1962 -0
  191. package/lib/timeSense.mjs +839 -0
  192. package/lib/tripwires.mjs +454 -0
  193. package/lib/ui.mjs +1 -1
  194. package/lib/vault.mjs +560 -45
  195. package/lib/vaultCommands.mjs +5 -3
  196. package/lib/vaultPeers.mjs +165 -0
  197. package/lib/vaultTools.d.ts +4 -1
  198. package/lib/vaultTools.js +22 -1
  199. package/lib/verdicts.mjs +12 -26
  200. package/lib/versions.mjs +117 -0
  201. package/lib/waitTool.mjs +278 -0
  202. package/lib/wakePicture.mjs +268 -0
  203. package/lib/wakeQueue.mjs +108 -0
  204. package/lib/watchResponses.mjs +533 -0
  205. package/lib/watches.mjs +290 -145
  206. package/lib/windowAsks.mjs +80 -17
  207. package/lib/worktrees.mjs +159 -9
  208. package/npm-shrinkwrap.json +138 -631
  209. package/package.json +7 -6
  210. package/release.json +211 -129
  211. package/lib/callSessions.mjs +0 -51
  212. package/lib/directLink.mjs +0 -349
  213. package/lib/peopleBoard.mjs +0 -131
  214. package/lib/projects.mjs +0 -2917
  215. package/lib/roomChannels.mjs +0 -667
package/lib/runBrief.mjs CHANGED
@@ -3,6 +3,7 @@ import { DISPATCHER, nameOf } from "./members.mjs";
3
3
  import { claudeMemNotes } from "./claudemem.mjs";
4
4
  import { toldBlock } from "./cards.mjs";
5
5
  import { fitSections } from "./fit.mjs";
6
+ import { createSessionBriefs } from "./sessionBriefs.mjs";
6
7
  import { oneLine } from "./oneLine.mjs";
7
8
  import { profileBrief, readProfile } from "./profile.mjs";
8
9
 
@@ -41,6 +42,8 @@ export function createRunBriefs({
41
42
  // What a run in a thread is told of the thread's board of cards (kanban.mjs).
42
43
  boardBrief = () => "",
43
44
  }) {
45
+ const sessionBriefs = createSessionBriefs(store);
46
+
44
47
  // What claude-mem remembers about this folder joins the task's context and the brief, so an agent without claude-mem
45
48
  // starts from the same history one with it would. A wake resumes its own session.
46
49
  const memoryNotes = async (task, wake, dryRun) => {
@@ -173,7 +176,17 @@ export function createRunBriefs({
173
176
  };
174
177
  };
175
178
 
176
- const sectionsFor = ({ task, agent, wake, room, local, memory }) => {
179
+ const sectionsFor = ({
180
+ task,
181
+ agent,
182
+ wake,
183
+ room,
184
+ local,
185
+ memory,
186
+ told,
187
+ dryRun,
188
+ }) => {
189
+ const block = (text) => (told ? told.block(text) : text);
177
190
  const pack = local.pack?.parts ?? {};
178
191
  const person = RUNNERS.has(agent) ? readProfile() : null;
179
192
  const refs = task.context_refs.map(
@@ -186,7 +199,7 @@ export function createRunBriefs({
186
199
  name: "provenance",
187
200
  priority: "core",
188
201
  source: "who wrote the task",
189
- text: provenanceLine(task, person?.displayName),
202
+ text: block(provenanceLine(task, person?.displayName)),
190
203
  },
191
204
  ...(thread?.kind === "goal"
192
205
  ? [
@@ -194,7 +207,9 @@ export function createRunBriefs({
194
207
  name: "thread board",
195
208
  priority: "core",
196
209
  source: `thread ${thread.id}`,
197
- text: boardBrief(thread.id),
210
+ text: block(
211
+ boardBrief(thread.id, { starting: dryRun ? task.id : null })
212
+ ),
198
213
  },
199
214
  ]
200
215
  : []),
@@ -202,13 +217,13 @@ export function createRunBriefs({
202
217
  name: "objective",
203
218
  priority: "core",
204
219
  source: `task ${task.id}`,
205
- text: task.objective,
220
+ text: block(task.objective),
206
221
  },
207
222
  {
208
223
  name: wake ? "wake brief" : "brief",
209
224
  priority: "core",
210
225
  source: wake ? `thread ${task.parent_id}` : `task ${task.id}`,
211
- text: wake ? wakeBrief(task) : task.brief,
226
+ text: wake ? wakeBrief(task, told) : task.brief,
212
227
  },
213
228
  {
214
229
  name: "context refs",
@@ -320,6 +335,17 @@ export function createRunBriefs({
320
335
  })
321
336
  : null;
322
337
  if (handed) resumeSession = undefined;
338
+ // What the session this turn goes on in was already told. In T3 the session is the agent's T3 thread.
339
+ const told = wake
340
+ ? sessionBriefs.forWake(
341
+ task.parent_id,
342
+ agent,
343
+ t3
344
+ ? store.meta(`t3-thread:${task.parent_id}:${agent}`)
345
+ : resumeSession
346
+ )
347
+ : null;
348
+ let whole = null;
323
349
  const notes = [
324
350
  {
325
351
  name: "stopped note",
@@ -335,33 +361,56 @@ export function createRunBriefs({
335
361
  !wake && task.parent_id ? store.getTask(task.parent_id) : null;
336
362
  const memory = await memoryNotes(task, wake, dryRun);
337
363
  const local = await localContext(task, agent, { wake, room, dryRun });
338
- const body = sectionsFor({ task, agent, wake, room, local, memory });
339
- // The earlier session's words follow what the run is asked.
340
- const asked =
341
- body.findIndex((section) =>
342
- ["brief", "wake brief"].includes(section.name)
343
- ) + 1;
344
- sections = [
345
- {
346
- name: "T3 catch-up",
347
- priority: "core",
348
- source: `thread ${task.parent_id}`,
349
- text: t3 && task.parent_id ? t3CatchUp(task.parent_id, agent) : "",
350
- },
351
- ...notes,
352
- ...body.slice(0, asked),
353
- ...(handed
354
- ? [
355
- {
356
- name: "earlier session",
357
- priority: "recommended",
358
- source: handed.record.file,
359
- ...handed.section,
360
- },
361
- ]
362
- : []),
363
- ...body.slice(asked),
364
- ];
364
+ const sectionsWith = (toldNow) => {
365
+ const body = sectionsFor({
366
+ task,
367
+ agent,
368
+ wake,
369
+ room,
370
+ local,
371
+ memory,
372
+ told: toldNow,
373
+ dryRun,
374
+ });
375
+ // The earlier session's words follow what the run is asked.
376
+ const asked =
377
+ body.findIndex((section) =>
378
+ ["brief", "wake brief"].includes(section.name)
379
+ ) + 1;
380
+ return [
381
+ {
382
+ name: "T3 catch-up",
383
+ priority: "core",
384
+ source: `thread ${task.parent_id}`,
385
+ text: t3 && task.parent_id ? t3CatchUp(task.parent_id, agent) : "",
386
+ },
387
+ ...notes,
388
+ ...body.slice(0, asked),
389
+ ...(handed
390
+ ? [
391
+ {
392
+ name: "earlier session",
393
+ priority: "recommended",
394
+ source: handed.record.file,
395
+ ...handed.section,
396
+ },
397
+ ]
398
+ : []),
399
+ // What was found for this turn: a resumed session gets the lines it has not had.
400
+ ...body
401
+ .slice(asked)
402
+ .map((section) =>
403
+ toldNow
404
+ ? { ...section, text: toldNow.lines(section.text) }
405
+ : section
406
+ ),
407
+ ];
408
+ };
409
+ // A T3 turn T3 does not answer starts a fresh session here (taskRuns.mjs), which has been told nothing. Made first:
410
+ // wakeBrief notes when the thread was read, and the brief sent must be the last to read it.
411
+ if (t3 && told?.afterSeq)
412
+ whole = fitSections(sectionsWith(null), BRIEF_BUDGET).text;
413
+ sections = sectionsWith(told);
365
414
  }
366
415
  const fitted = fitSections(sections, BRIEF_BUDGET);
367
416
  const report = {
@@ -371,17 +420,21 @@ export function createRunBriefs({
371
420
  whole: fitted.whole,
372
421
  sent: fitted.sent,
373
422
  over: fitted.over,
374
- session: t3
375
- ? { t3: true }
376
- : resumeSession
377
- ? { resumes: resumeSession }
378
- : handed
379
- ? { fresh: true, replaces: handed.record.from, why: handed.why }
380
- : { fresh: true },
423
+ session: {
424
+ ...(t3
425
+ ? { t3: true }
426
+ : resumeSession
427
+ ? { resumes: resumeSession }
428
+ : handed
429
+ ? { fresh: true, replaces: handed.record.from, why: handed.why }
430
+ : { fresh: true }),
431
+ ...(told?.afterSeq ? { new_after_post: told.afterSeq } : {}),
432
+ },
381
433
  sections: fitted.sections,
382
434
  };
383
435
  if (!dryRun) {
384
436
  store.meta(`brief-sections:${task.id}`, JSON.stringify(report));
437
+ told?.remember({ run: task.id, sent: fitted.text });
385
438
  if (handed)
386
439
  handover.announce({
387
440
  threadId: task.parent_id,
@@ -390,7 +443,7 @@ export function createRunBriefs({
390
443
  handed,
391
444
  });
392
445
  }
393
- return { prompt: fitted.text, resumeSession, again, t3, report };
446
+ return { prompt: fitted.text, whole, resumeSession, again, t3, report };
394
447
  };
395
448
 
396
449
  /** What a run that started was told, section by section, or null. */
@@ -1,6 +1,12 @@
1
1
  import { createHash, randomUUID } from "node:crypto";
2
2
  import { nameOf } from "./members.mjs";
3
3
 
4
+ // A question Harness or Bankr words itself (a spend past a limit, an app's write, a Bankr proposal) left unanswered this
5
+ // long leaves the places that show what waits right now and waits in its thread's list (owner, November 11: "if i dont
6
+ // address it in an hour or so it goes to a notification menu in the thread or something for me to address later").
7
+ // It still waits for the answer: nothing times out.
8
+ const LATER_MS = 60 * 60 * 1000;
9
+
4
10
  /** Native permission choices for running, owned executions. A decision never starts or resumes a run. */
5
11
  export function createRunRequests({ store, notifyBoard }) {
6
12
  const pending = new Map();
@@ -10,14 +16,22 @@ export function createRunRequests({ store, notifyBoard }) {
10
16
  );
11
17
  const save = () => store.meta("native-run-requests", JSON.stringify(records));
12
18
  save();
19
+ // Harness's task on its server is claimed, never started here: its turn runs there while the task is held.
20
+ // A thread's own request (a Bankr proposal from a task on Harness's server, bankrApprovals.mjs) lives while its thread
21
+ // is open; there is no run here to be running.
13
22
  const running = (entry) => {
23
+ if (entry.threadId) return store.getTask(entry.threadId)?.status === "open";
14
24
  const task = store.getTask(entry.runId);
15
- return task?.status === "running" && task.target_agent === entry.agent;
25
+ return (
26
+ (task?.status === "running" ||
27
+ (task?.status === "claimed" && entry.agent === "harness")) &&
28
+ task.target_agent === entry.agent
29
+ );
16
30
  };
17
31
  const tell = (entry) => notifyBoard(store.getTask(entry.runId));
18
- const request = ({ runId, agent, approval, signal }) => {
32
+ const request = ({ runId, agent, threadId, approval, signal }) => {
19
33
  signal.throwIfAborted();
20
- if (!running({ runId, agent }))
34
+ if (!running({ runId, agent, threadId }))
21
35
  throw new Error(
22
36
  "This native permission does not belong to a running task."
23
37
  );
@@ -39,6 +53,7 @@ export function createRunRequests({ store, notifyBoard }) {
39
53
  id: randomUUID(),
40
54
  runId,
41
55
  agent,
56
+ ...(threadId ? { threadId } : {}),
42
57
  approvalId: approval.approvalId,
43
58
  requirement: approval.currentRequirementId,
44
59
  revision: createHash("sha256")
@@ -47,6 +62,8 @@ export function createRunRequests({ store, notifyBoard }) {
47
62
  text: `Requested action: ${approval.toolName}`,
48
63
  details,
49
64
  protectedWrite: approval.protectedWrite === true,
65
+ // What the item says on every surface, when the asker words it (Harness's app writes, harnessOffers.mjs).
66
+ ...(approval.summary ? { summary: String(approval.summary) } : {}),
50
67
  choices: choices.map(({ choiceId, label, decision }) => ({
51
68
  id: choiceId,
52
69
  label,
@@ -92,18 +109,39 @@ export function createRunRequests({ store, notifyBoard }) {
92
109
  if (signal.aborted) aborted();
93
110
  });
94
111
  };
112
+ // A worded question carries its choices, so a card shows them at once; an agent's own native request is reviewed first.
113
+ const itemOf = (entry) => ({
114
+ id: `permission:${entry.id}`,
115
+ kind: "permission",
116
+ agent: entry.agent,
117
+ runId: entry.runId,
118
+ requestId: entry.id,
119
+ text:
120
+ entry.summary ??
121
+ `${nameOf(entry.agent)} needs your permission to continue.`,
122
+ at: entry.at,
123
+ ...(entry.summary
124
+ ? {
125
+ choices: entry.choices,
126
+ revision: entry.revision,
127
+ ...(Date.now() - Date.parse(entry.at) > LATER_MS
128
+ ? { late: true }
129
+ : {}),
130
+ }
131
+ : {}),
132
+ });
95
133
  const needs = (runId) =>
96
134
  [...pending.values()]
97
- .filter(({ entry }) => entry.runId === runId && running(entry))
98
- .map(({ entry }) => ({
99
- id: `permission:${entry.id}`,
100
- kind: "permission",
101
- agent: entry.agent,
102
- runId,
103
- requestId: entry.id,
104
- text: `${nameOf(entry.agent)} needs your permission to continue.`,
105
- at: entry.at,
106
- }));
135
+ .filter(
136
+ ({ entry }) =>
137
+ entry.runId === runId && !entry.threadId && running(entry)
138
+ )
139
+ .map(({ entry }) => itemOf(entry));
140
+ // A thread's own requests, which belong to no run here.
141
+ const threadNeeds = (threadId) =>
142
+ [...pending.values()]
143
+ .filter(({ entry }) => entry.threadId === threadId && running(entry))
144
+ .map(({ entry }) => itemOf(entry));
107
145
  const finish = (runId) => {
108
146
  for (const held of pending.values())
109
147
  if (held.entry.runId === runId)
@@ -153,5 +191,5 @@ export function createRunRequests({ store, notifyBoard }) {
153
191
  held.close("submitted", null, choice.id);
154
192
  return { ok: true, status: "submitted" };
155
193
  };
156
- return { request, needs, command, finish };
194
+ return { request, needs, threadNeeds, command, finish };
157
195
  }
@@ -0,0 +1,31 @@
1
+ // What one run used. Some figures an agent reports count its whole session so far, so a resumed run reports its
2
+ // predecessors' again: Claude Code's dollars and Codex's tokens (a board once summed $360.62 for sessions that cost
3
+ // $78.42). The collector names those figures in `session_totals`; the run's own share is what they grew by.
4
+
5
+ const toOwnShare = (now, was) => {
6
+ // A counter that fell started over: all of it is this run's.
7
+ const grown = now >= was ? now - was : now;
8
+ return Math.round(grown * 1e6) / 1e6;
9
+ };
10
+
11
+ /** `before`: the usage kept for the session's previous run, or null when this run started it. */
12
+ export function ownUsage(reported, before) {
13
+ const totals = reported?.session_totals;
14
+ if (!totals) return reported;
15
+ // A run kept before session_totals existed holds its session's counters as its figures, Codex's input with cached
16
+ // tokens still inside it.
17
+ const earlier =
18
+ before?.session_totals ??
19
+ (before
20
+ ? {
21
+ ...before,
22
+ input_tokens:
23
+ (Number(before.input_tokens) || 0) -
24
+ (Number(before.cache_read_tokens) || 0),
25
+ }
26
+ : {});
27
+ const own = { ...reported };
28
+ for (const [field, total] of Object.entries(totals))
29
+ own[field] = toOwnShare(total, Number(earlier[field]) || 0);
30
+ return own;
31
+ }
package/lib/runWorker.mjs CHANGED
@@ -1,4 +1,5 @@
1
1
  import path from "node:path";
2
+ import { herdrTakes } from "./herdrRuns.mjs";
2
3
  import { stopAgentTask } from "./runner.mjs";
3
4
  import { notifyDesktop } from "./notify.mjs";
4
5
  import { receipt, receiptLine } from "./receipts.mjs";
@@ -36,16 +37,30 @@ export function createRunWorker({
36
37
  vaultEnv = () => null,
37
38
  // A run's receipt was just kept (audit.mjs audits the run's claims with it).
38
39
  onReceipt = () => {},
40
+ // What a turn that ended on a wait says, when its agent wrote nothing (threadRecord.mjs); null for no wait.
41
+ waitingLine = () => null,
39
42
  }) {
40
43
  const { RUNNERS, standingRules } = authority;
41
- const { startTurn, commitRun, settleWake, ranOutsideT3, t3Turn, taskInT3 } =
42
- threadRuns.worker;
44
+ const {
45
+ startTurn,
46
+ commitRun,
47
+ settleWake,
48
+ ranOutsideT3,
49
+ t3Turn,
50
+ taskInT3,
51
+ herdrTurn,
52
+ } = threadRuns.worker;
43
53
  const activeRuns = new Map();
44
54
  const lastStepNotice = new Map();
45
55
  // Runs the daemon is stopping for a safety rule, by task id, with the reason: they go back on the board.
46
56
  const interrupting = new Map();
47
- for (const id of store.settleInterruptedRuns())
48
- log(`board task ${id} was running when the daemon stopped; marked unknown`);
57
+ // Only on the board this computer keeps: a worker's tables are home's copy, and the runs it had going are reported to
58
+ // home by machineRuns.mjs.
59
+ if (holdsBoard())
60
+ for (const id of store.settleInterruptedRuns(machineId()))
61
+ log(
62
+ `board task ${id} was running when the daemon stopped; marked unknown`
63
+ );
49
64
  // Standing permission is on by default; the person hears so once, on the first start that has it.
50
65
  const defaults = standingRules().filter((rule) => rule.mode === "default");
51
66
  if (defaults.length && !store.meta("standing_announced")) {
@@ -91,8 +106,10 @@ export function createRunWorker({
91
106
  (held) =>
92
107
  held.agent === agent && store.getTask(held.id)?.parent_id === threadId
93
108
  );
94
- // Lid-Closed Mode holds new runs while the Mac runs warm with the lid closed; running ones go on.
95
- let runsHeld = false;
109
+ // Who holds new runs, and when they start again as the person reads it: Lid-Closed Mode while the Mac runs warm with
110
+ // the lid closed, a nearly full disk (machine.mjs), Harness stopping. Running ones go on; new ones start once none
111
+ // holds them.
112
+ const holders = new Map();
96
113
  // Why work given to an agent in a thread has not started, as the person reads it (the thread's waits, its notes);
97
114
  // null when nothing holds it back.
98
115
  const whyWaiting = (goalId, run) => {
@@ -100,16 +117,13 @@ export function createRunWorker({
100
117
  const who = nameOf(run.target_agent);
101
118
  if (run.target_agent === "harness") {
102
119
  const why = store.meta(`harness-wait:${run.id}`);
103
- return why
104
- ? `Harness's part waits for your Harness window: ${why}.`
105
- : null;
120
+ return why ? `Harness's part waits: ${why}.` : null;
106
121
  }
107
122
  if (!RUNNERS.has(run.target_agent) || !run.run_workspace) return null;
108
123
  if (!run.run_authorized_at) return `${who} waits for your Start.`;
109
124
  const refusal = dispatches?.refusal(run.id);
110
125
  if (refusal) return refusal;
111
- if (runsHeld)
112
- return `${who} starts when your Mac is no longer running with its lid closed.`;
126
+ if (holders.size) return `${who} starts when ${[...holders.values()][0]}.`;
113
127
  const own = activeRuns.get(slotOf({ ...run, parent_id: goalId }));
114
128
  if (own)
115
129
  return `${who} starts when its turn there now ends: an agent takes one turn at a time in a folder.`;
@@ -136,7 +150,7 @@ export function createRunWorker({
136
150
  notifyBoard(store.getTask(task.parent_id));
137
151
  };
138
152
  const runBoard = () => {
139
- if (runsHeld || !holdsBoard()) return;
153
+ if (holders.size || !holdsBoard()) return;
140
154
  // One run per agent per folder at a time: other agents and other threads' worktrees run side by side.
141
155
  for (const task of store.runnableTasks(installedAgents, machineId(), {
142
156
  only: onlyItsOwn(),
@@ -200,6 +214,7 @@ export function createRunWorker({
200
214
  const startedAt = new Date().toISOString();
201
215
  const {
202
216
  prompt,
217
+ whole,
203
218
  resumeSession,
204
219
  again,
205
220
  t3: inT3,
@@ -214,6 +229,8 @@ export function createRunWorker({
214
229
  // Work another person asked for runs with only this person's own agent settings: the repository's own (its
215
230
  // .claude hooks, .pi, opencode.json) can be that person's, and would run here (security audit P4, October 25).
216
231
  const ownSettingsOnly = store.meta(`other-person-run:${task.id}`) === "1";
232
+ // A run in a jam's room reaches that room alone (runAuthority.mjs privateReach).
233
+ const jamThread = store.meta(`jam-run:${task.id}`) || null;
217
234
  const chosen = await modelForRun(task, agent);
218
235
  store.setRunModel(task.id, chosen);
219
236
  const { model, effort } = chosen;
@@ -227,7 +244,11 @@ export function createRunWorker({
227
244
  notifyBoard(store.getTask(task.id));
228
245
  return;
229
246
  }
230
- const t3 = inT3 ? t3Turn(task, agent, { model, effort }) : null;
247
+ const folder = threadRuns.worker.folderForRun(task);
248
+ const t3 =
249
+ inT3 && folder === task.run_workspace
250
+ ? t3Turn(task, agent, { model, effort })
251
+ : null;
231
252
  // The person's environment grants (vault.mjs), never for a run they did not authorize: the values are in this
232
253
  // run's environment, and what it says is scrubbed of them.
233
254
  // Nor for a turn another of the person's agents asked for on standing permission: that grants a start, no secrets.
@@ -237,6 +258,22 @@ export function createRunWorker({
237
258
  ? null
238
259
  : vaultEnv(task, agent);
239
260
  const granted = secrets && Object.keys(secrets.env).length ? secrets : null;
261
+ // Shown in Herdr only where the turn needs no limits a tab can't hold: it runs in the person's own shell, with no run
262
+ // token and no granted secrets.
263
+ let herdr =
264
+ !t3 &&
265
+ !readOnly &&
266
+ !restricted &&
267
+ !ownSettingsOnly &&
268
+ !granted &&
269
+ folder === task.run_workspace
270
+ ? herdrTurn(task, agent)
271
+ : null;
272
+ // An agent a tab runs on its own settings goes there only when no model was picked for the run.
273
+ if (herdr && !herdrTakes(agent, { model })) herdr = null;
274
+ // The tab its session still runs in, for a turn on that same session.
275
+ if (herdr && herdr.tab?.session !== (resumeSession ?? null))
276
+ herdr.tab = null;
240
277
  startTurn(task);
241
278
  taskRuns.startTask(
242
279
  {
@@ -244,7 +281,7 @@ export function createRunWorker({
244
281
  agent,
245
282
  title: oneLine(task.objective),
246
283
  brief: prompt,
247
- cwd: task.run_workspace,
284
+ cwd: folder,
248
285
  ...(model ? { model } : {}),
249
286
  ...(effort ? { effort } : {}),
250
287
  // A model of Harness's AI says its window and longest answer, for an agent told them per run (runner.mjs).
@@ -254,7 +291,9 @@ export function createRunWorker({
254
291
  ...(readOnly ? { readOnly } : {}),
255
292
  ...(restricted ? { restricted } : {}),
256
293
  ...(ownSettingsOnly ? { ownSettingsOnly } : {}),
257
- ...(t3 ? { t3 } : {}),
294
+ ...(jamThread ? { jamThread } : {}),
295
+ ...(t3 ? { t3: { ...t3, wholeBrief: whole } } : {}),
296
+ ...(herdr ? { herdr } : {}),
258
297
  ...(granted ? { env: granted.env, scrub: granted.values } : {}),
259
298
  },
260
299
  (kind, text, extra) => {
@@ -279,6 +318,9 @@ export function createRunWorker({
279
318
  if (kind === "accepted" && stoppedFor)
280
319
  store.meta(`requeued:${task.id}`, "");
281
320
  if (kind === "done" || kind === "failed") {
321
+ // A turn that ended to wait, with nothing written, says what it waits for, not that it finished.
322
+ if (kind === "done" && extra?.nothingSaid && task.parent_id)
323
+ text = waitingLine(task.parent_id, agent, startedAt) ?? text;
282
324
  ranOutsideT3.delete(task.id);
283
325
  lastStepNotice.delete(task.id);
284
326
  activeRuns.delete(slotOf(task));
@@ -440,15 +482,22 @@ export function createRunWorker({
440
482
  log(`stopping ${stopped.length} board run(s) because ${reason}`);
441
483
  return stopped;
442
484
  };
443
- const hold = (on) => {
444
- runsHeld = on === true;
445
- log(
446
- runsHeld
447
- ? "new runs held: the Mac is warm with its lid closed"
448
- : "new runs start again"
449
- );
450
- if (!runsHeld) setImmediate(runBoard);
451
- return runsHeld;
485
+ const hold = (
486
+ on,
487
+ {
488
+ by = "lid",
489
+ why = "the Mac is warm with its lid closed",
490
+ until = "your Mac is no longer running with its lid closed",
491
+ } = {}
492
+ ) => {
493
+ const was = holders.size > 0;
494
+ if (on === true) holders.set(by, until);
495
+ else holders.delete(by);
496
+ const held = holders.size > 0;
497
+ if (on === true) log(`new runs held: ${why}`);
498
+ else if (was && !held) log("new runs start again");
499
+ if (!held) setImmediate(runBoard);
500
+ return held;
452
501
  };
453
502
  return {
454
503
  slotOf,
@@ -456,7 +505,7 @@ export function createRunWorker({
456
505
  runBoard,
457
506
  interruptAll,
458
507
  hold,
459
- held: () => runsHeld,
508
+ held: () => holders.size > 0,
460
509
  activeRuns: {
461
510
  get: (slot) => activeRuns.get(slot),
462
511
  values: () => activeRuns.values(),