tryharness 0.7.71 → 0.7.73

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 (57) hide show
  1. package/README.md +13 -8
  2. package/assets/opencode-plugin.js +70 -3
  3. package/cli.mjs +27 -12
  4. package/lib/asks.mjs +4 -0
  5. package/lib/boardCommands.mjs +9 -1
  6. package/lib/boardProtocol.json +23 -19
  7. package/lib/bridge.mjs +2 -0
  8. package/lib/capabilityCheck.mjs +86 -0
  9. package/lib/computerAddress.mjs +6 -14
  10. package/lib/coordinator.mjs +259 -30
  11. package/lib/daemon.mjs +164 -133
  12. package/lib/dispatchContract.json +1 -31
  13. package/lib/dispatchTools.js +8 -39
  14. package/lib/dispatches.mjs +27 -285
  15. package/lib/goalCommands.mjs +21 -38
  16. package/lib/herdr.mjs +159 -0
  17. package/lib/hookDialects.mjs +36 -2
  18. package/lib/jobAnswers.mjs +3 -0
  19. package/lib/kanban.mjs +256 -0
  20. package/lib/live.mjs +25 -3
  21. package/lib/localAgentAsk.mjs +20 -29
  22. package/lib/machineRoutes.mjs +1 -5
  23. package/lib/machineRuns.mjs +42 -22
  24. package/lib/manager.mjs +254 -0
  25. package/lib/mcp-stdio.mjs +58 -39
  26. package/lib/moves.mjs +365 -0
  27. package/lib/nudge.mjs +13 -3
  28. package/lib/ownMachines.mjs +122 -12
  29. package/lib/places.mjs +29 -2
  30. package/lib/plans.mjs +7 -1
  31. package/lib/projectSettings.mjs +11 -1
  32. package/lib/projects.mjs +20 -4
  33. package/lib/runAuthority.mjs +104 -35
  34. package/lib/runBrief.mjs +14 -1
  35. package/lib/runWorker.mjs +48 -24
  36. package/lib/runner.mjs +184 -75
  37. package/lib/selfUpdate.mjs +41 -0
  38. package/lib/serverWords.mjs +11 -11
  39. package/lib/sessionControl.mjs +68 -3
  40. package/lib/steerHook.mjs +124 -0
  41. package/lib/steerQueue.mjs +176 -0
  42. package/lib/store.mjs +34 -34
  43. package/lib/subagentSteering.mjs +363 -0
  44. package/lib/subagents.mjs +138 -29
  45. package/lib/swarm.mjs +16 -3
  46. package/lib/taskCommands.mjs +36 -71
  47. package/lib/threadActions.mjs +13 -3
  48. package/lib/threadAuthority.mjs +21 -14
  49. package/lib/threadBriefs.mjs +9 -3
  50. package/lib/threadRuns.mjs +35 -8
  51. package/npm-shrinkwrap.json +14 -14
  52. package/package.json +4 -4
  53. package/release.json +54 -49
  54. package/lib/comfyExecution.mjs +0 -545
  55. package/lib/promptDecider.mjs +0 -471
  56. package/lib/promptFlow.mjs +0 -562
  57. package/lib/promptScopes.mjs +0 -670
@@ -14,10 +14,20 @@ export const SETTINGS = {
14
14
  },
15
15
  start: {
16
16
  // Consent to code running on this computer from the other person's words (security audit P2, October 25): Claude
17
- // Code runs it restricted in a copy, any other agent still waits for the person's Start.
17
+ // Code or Codex runs it restricted in a copy (none of the person's credentials, no network, only the board and its
18
+ // own folder), any other agent still waits for the person's Start. On from the start: the person connected their
19
+ // swarm to a collaborator to get work done (owner, October 31: "if hes connecting his AI to another persons, they
20
+ // are a trusted party doing collaborative work"); either person turns it off at once.
18
21
  label:
19
22
  "Agents start work the other side asks for (this runs code on your computer)",
20
23
  values: [false, true],
24
+ initial: true,
25
+ },
26
+ // Harness works on this person's credits, so it answers the other side only when both let it: money stays behind
27
+ // consent (owner, October 31), apart from the agents starting each other's work above.
28
+ harness: {
29
+ label: "Harness answers the other side (on your Harness credits)",
30
+ values: [false, true],
21
31
  initial: false,
22
32
  },
23
33
  push: {
package/lib/projects.mjs CHANGED
@@ -580,9 +580,25 @@ export function createProjects({
580
580
  )
581
581
  .map(([side]) => ({ side, yes: true, at: proposal.at }))
582
582
  : [];
583
+ const answers = answersTo(p, proposal.id);
584
+ // An agreement this person joined with was accepted when they joined, though an answer to it from someone away
585
+ // since never reached this computer: once, a room's agreed setting read as still pending on the fourth person's,
586
+ // and an older narrowing won over it. It keeps its own time, so a narrowing after it still wins.
587
+ if (
588
+ !isFix(body) &&
589
+ group?.consents?.[p.me]?.[proposal.id] === agreementHash(body)
590
+ )
591
+ return {
592
+ state: "accepted",
593
+ waitingOn: [],
594
+ at: [proposal.at, ...answers.map((answer) => answer.at)]
595
+ .map(String)
596
+ .sort()
597
+ .at(-1),
598
+ };
583
599
  return proposalState(
584
600
  { ...body, needs: needsOf(p, body, proposal.side), at: proposal.at },
585
- [...implicit, ...answersTo(p, proposal.id)]
601
+ [...implicit, ...answers]
586
602
  );
587
603
  };
588
604
 
@@ -850,18 +866,18 @@ export function createProjects({
850
866
  String(event.id)
851
867
  );
852
868
  // The other side's words wake only the agents here they name; their unaddressed words are their own swarm's to sort.
853
- // Harness works on this person's credits, so the other side reaches it only when both let agents start their asks.
869
+ // Harness works on this person's credits, so the other side reaches it only when both let Harness answer them.
854
870
  const named = mentions.filter(
855
871
  (name) =>
856
872
  !name.includes("/") &&
857
873
  name !== "user" &&
858
874
  ownAgents(p).includes(name) &&
859
- (name !== "harness" || settingsOf(p).start)
875
+ (name !== "harness" || settingsOf(p).harness)
860
876
  );
861
877
  if (mentions.includes("harness") && !named.includes("harness"))
862
878
  note(
863
879
  p,
864
- `${display(p, event.author)} asked Harness. Harness answers the other side only once you both let agents start work the other side asks for.`
880
+ `${display(p, event.author)} asked Harness. Harness answers the other side only once you both let it, since it works on your Harness credits.`
865
881
  );
866
882
  // A clash the other side found with one of this side's pieces of work: the agent on it talks it out, read-only.
867
883
  const clash = Array.isArray(event.clash) ? event.clash.map(String) : [];
@@ -25,6 +25,10 @@ import {
25
25
  export const HOSTED_CALLER = Symbol("a board call Harness's server made");
26
26
  /** The run Harness started that made a socket call, set by checkCaller; no JSON a caller writes can set it. */
27
27
  export const RUN_CALLER = Symbol("the run that called");
28
+ // Work the person's agents hand on to each other starts without a Start (owner, October 31), so a run that posts work
29
+ // for an agent whose run posts work again could go on forever. Past this many hand-offs in a row with no word from the
30
+ // person, the next one waits for their Start. In place of a daily limit the person never set.
31
+ export const MAX_HANDOFFS = 10;
28
32
  /** How the run that made a call was held in, so what it asks for is held in too: "review", "restricted" or null. */
29
33
  export const callerLimit = (request) => {
30
34
  const run = request?.[RUN_CALLER];
@@ -72,6 +76,62 @@ const PERSON_READS = new Set([
72
76
  ]);
73
77
  export { PROPOSERS };
74
78
 
79
+ // What stays the person's when a run works for someone else (another person's agent asked for it) or is held in: their
80
+ // screen, what they heard and watched, their memory and past conversations, their file and code library, their money
81
+ // and their secrets. Such a run has the board, its own thread and its own folder (owner, October 31: collaborators are
82
+ // trusted to work, "especially ones that deal with secrets sensitive info or money" stay guarded).
83
+ const PRIVATE_COMMANDS = new Set([
84
+ "board.audio.listen",
85
+ "board.code.search",
86
+ "board.desk.book",
87
+ "board.desk.contract",
88
+ "board.desk.write",
89
+ "board.files.search",
90
+ "board.media.search",
91
+ "board.screen.search",
92
+ "board.screens.compare",
93
+ "board.swarm.memory",
94
+ "board.wallet",
95
+ "board.watch.add",
96
+ "mcp.download",
97
+ ]);
98
+ // Harness's own tools such a run may call through the relay: none that read the person's screen, memory or
99
+ // conversations, spend their credits or hold their secrets.
100
+ const OPEN_HARNESS_TOOLS = new Set(["archetype"]);
101
+ const PRIVATE_REFUSAL =
102
+ "Work done for someone else does not reach the person's screen, memory, conversations, files, money or secrets: only this thread and its folder.";
103
+ /** Why a run working for someone else (or held in) may not make this call, or null. `within(file, folder)`. */
104
+ export const privateReach = (command, request, run, within) => {
105
+ if (PRIVATE_COMMANDS.has(command)) return PRIVATE_REFUSAL;
106
+ if (command === "board.swarm.search" && !request.thread)
107
+ return PRIVATE_REFUSAL;
108
+ if (
109
+ command === "board.file.add" &&
110
+ request.path != null &&
111
+ !(
112
+ run.cwd &&
113
+ path.isAbsolute(String(request.path)) &&
114
+ within(String(request.path), run.cwd)
115
+ )
116
+ )
117
+ return "Work done for someone else attaches files from its own folder only.";
118
+ if (
119
+ command === "mcp.call" &&
120
+ request.rpc?.method === "tools/call" &&
121
+ !OPEN_HARNESS_TOOLS.has(String(request.rpc?.params?.name ?? ""))
122
+ )
123
+ return PRIVATE_REFUSAL;
124
+ if (
125
+ command === "mcp.call" &&
126
+ !["initialize", "tools/list", "tools/call"].includes(
127
+ String(request.rpc?.method)
128
+ ) &&
129
+ !String(request.rpc?.method ?? "").startsWith("notifications/")
130
+ )
131
+ return PRIVATE_REFUSAL;
132
+ return null;
133
+ };
134
+
75
135
  const runMayAsk = (command) =>
76
136
  command.startsWith("board.") ||
77
137
  command.startsWith("mcp.") ||
@@ -123,16 +183,24 @@ export function createRunAuthority({ store, installedAgents }) {
123
183
  const aboveHome = (dir) => within(os.homedir(), dir);
124
184
  // A coding agent's own scratch folder, for the person's tasks that name none: nothing of theirs is in it.
125
185
  const scratchFolder = (agent) => path.join(paths.home, "work", agent);
186
+ // The only limits on where and how often the person's agents start are the ones the person set: folders and a daily
187
+ // limit they named (mode 'named'). By default an agent runs in any folder below home, as the person would, and as
188
+ // often as asked (owner, October 31: "i never authorized any of that"); a thread's wake limit still stops a loop.
189
+ // Harness's own folders for the work: an agent's and a thread's scratch folders, and a thread's copy of a folder.
190
+ const harnessWork = (dir) =>
191
+ ["work", "worktrees"].some((place) =>
192
+ within(dir, path.join(paths.home, place))
193
+ );
126
194
  const covers = (rule, dir) =>
127
195
  realDir(dir) === realDir(scratchFolder(rule.agent)) ||
128
- rule.workspaces.some((root) =>
129
- rule.mode === "default" && aboveHome(root)
130
- ? realDir(root) === realDir(dir)
131
- : within(dir, root)
132
- );
196
+ (rule.mode === "named"
197
+ ? rule.workspaces.some((root) => within(dir, root))
198
+ : harnessWork(dir) || (within(dir, os.homedir()) && !aboveHome(dir)));
199
+ const pastLimit = (rule) =>
200
+ rule.mode === "named" && rule.runs_today >= rule.daily_cap;
133
201
  const standingRules = () => store.standing(runners(), startOfToday());
134
202
  // null when the run may start now; otherwise why it waits for the person.
135
- const standingVerdict = ({ trust, target, workspace, capacity = true }) => {
203
+ const standingVerdict = ({ trust, target, workspace }) => {
136
204
  if (trust !== "user")
137
205
  return "Another agent wrote it, so it never starts without the person.";
138
206
  const rule = standingRules().find((entry) => entry.agent === target);
@@ -141,11 +209,11 @@ export function createRunAuthority({ store, installedAgents }) {
141
209
  if (rule.mode === "off")
142
210
  return `${target} is set to wait for the person's Start.`;
143
211
  if (!covers(rule, workspace))
144
- return rule.mode === "default"
145
- ? `${target} has not worked in ${workspace} before, so its first run there waits for the person.`
146
- : `${workspace} is outside the folders ${target} may run in without asking (${rule.workspaces.join(", ")}).`;
147
- if (capacity && rule.runs_today >= rule.daily_cap)
148
- return `${target} already started ${rule.runs_today} runs today without asking, its daily limit.`;
212
+ return rule.mode === "named"
213
+ ? `${workspace} is outside the folders ${target} may run in without asking (${rule.workspaces.join(", ")}).`
214
+ : `${workspace} is not a folder below the home folder, where agents run without the person.`;
215
+ if (pastLimit(rule))
216
+ return `${target} already started ${rule.runs_today} runs today without asking, the daily limit the person set.`;
149
217
  return null;
150
218
  };
151
219
  const applyStanding = (task) => {
@@ -168,14 +236,18 @@ export function createRunAuthority({ store, installedAgents }) {
168
236
  ({
169
237
  off: "its standing permission is off.",
170
238
  "not-proposer": `you took ${nameOf(proposer)}'s asks off its standing permission. Let it again: npx tryharness board standing ${target} --from ${proposer}`,
171
- outside: `${folder} is outside the folders it may run in without asking.`,
172
- cap: "it already started its runs for today without asking, its daily limit.",
239
+ outside: `${folder} is outside the folders you let it run in without asking.`,
240
+ cap: "it already started today's runs up to the daily limit you set.",
173
241
  gone: "its turn could not be authorized.",
174
242
  })[why];
175
243
 
176
244
  // Why an ask from one of the person's own agents cannot use a standing permission at all, or null. `hosted`: it came
177
245
  // from Harness's server itself (HOSTED_CALLER), never a local process or another computer; `here`: from a process on
178
- // this computer, claiming no Harness origin. Each agent's ask must come the one way that agent speaks.
246
+ // this computer, claiming no Harness origin. Each agent's ask must come the one way that agent speaks. The guard's flag
247
+ // is a label for readers (it cannot tell the person's agents coordinating from planted orders); words it reads as
248
+ // orders aimed at the person's agents wait for the person, as do words through Harness's server it could not read
249
+ // (security audit S4): that is where planted instructions would reach for their secrets. An agent on this computer
250
+ // needs no reading, as in a thread (threadAuthority.mjs personsGo).
179
251
  const askRefusal = (ask) => {
180
252
  const proposer = String(ask?.proposer ?? "");
181
253
  return !PROPOSERS.includes(proposer)
@@ -187,9 +259,14 @@ export function createRunAuthority({ store, installedAgents }) {
187
259
  ? `${nameOf(proposer)}'s ask did not come from this computer as its asks do.`
188
260
  : ask.limited
189
261
  ? `${nameOf(proposer)} asked from a held-in run.`
190
- : ask.guard?.verdict !== "clean" || ask.guard.unavailable
191
- ? `the guard on this computer did not read ${nameOf(proposer)}'s words as clean.`
192
- : null;
262
+ : speaksThroughHarness(proposer) &&
263
+ (!ask.guard || ask.guard.unavailable)
264
+ ? `the guard on this computer could not read ${nameOf(proposer)}'s words.`
265
+ : ask.guard.verdict === "hold"
266
+ ? `the guard on this computer read ${nameOf(proposer)}'s words as orders aimed at your agents.`
267
+ : (ask.handoffs ?? 0) > MAX_HANDOFFS
268
+ ? `your agents have handed this work on ${MAX_HANDOFFS} times in a row without you, so a loop cannot run on its own.`
269
+ : null;
193
270
  };
194
271
  // Authorized on the rule in one transaction (store.mjs authorizeProposed), its receipt naming the folder checked
195
272
  // and the computer it is for, which proposedHold checks again before it starts.
@@ -199,6 +276,7 @@ export function createRunAuthority({ store, installedAgents }) {
199
276
  proposer,
200
277
  since: startOfToday(),
201
278
  covered: (rule) => !folder || covers(rule, folder),
279
+ pastLimit,
202
280
  folder,
203
281
  scratch,
204
282
  });
@@ -217,12 +295,13 @@ export function createRunAuthority({ store, installedAgents }) {
217
295
  /**
218
296
  * One of the person's own agents elsewhere (PROPOSERS) asked a coding agent here for a turn in a thread whose own work
219
297
  * does not run on the person's go (threadAuthority.mjs threadMayRun: another agent wrote it). The turn starts only
220
- * on the coding agent's standing permission, where the person named that asker on it: its words reached here through
221
- * Harness's server and the guard on this computer read them clean, from no restricted run, review or linked window.
222
- * It counts against the agent's daily limit like any standing run and keeps the agent-written label; the thread's
223
- * own folder is the one checked (null: a fresh scratch folder of the thread's, which holds nothing of the person's).
298
+ * on the coding agent's standing permission unless the person took that asker off it: its words reached here the way
299
+ * that agent speaks and the guard on this computer did not read them as orders (a flag is only a label), from no
300
+ * restricted run, review or linked window.
301
+ * It counts as one of the agent's standing runs and keeps the agent-written label; the thread's own folder is the one
302
+ * checked (null: a fresh scratch folder of the thread's, which holds nothing of the person's).
224
303
  *
225
- * `ask`: { proposer, hosted, guard, limited, window }, as the thread heard it. Returns { started } or { started:
304
+ * `ask`: { proposer, hosted, here, guard, limited, window, handoffs }, as the thread heard it. Returns { started } or { started:
226
305
  * false, reason }, the reason ending "<agent> waits for your Start: ".
227
306
  */
228
307
  const admitProposed = (wake, ask, folder) => {
@@ -275,7 +354,7 @@ export function createRunAuthority({ store, installedAgents }) {
275
354
  ? `you took ${nameOf(proposal.proposer)}'s asks off ${nameOf(task.target_agent)}'s standing permission.`
276
355
  : proposal.folder && !covers(rule, proposal.folder)
277
356
  ? `${proposal.folder} is no longer among the folders it may run in without asking.`
278
- : changed && rule.runs_today > rule.daily_cap
357
+ : changed && rule.mode === "named" && rule.runs_today > rule.daily_cap
279
358
  ? "you lowered its daily limit below the runs it already started today."
280
359
  : (Object.hasOwn(proposal, "machine") &&
281
360
  (task.target_machine ?? null) !== proposal.machine) ||
@@ -322,20 +401,10 @@ export function createRunAuthority({ store, installedAgents }) {
322
401
  request[RUN_CALLER] = run;
323
402
  if (!runMayAsk(command))
324
403
  return "A run Harness started cannot do that; only the person can.";
325
- if (
326
- run.dispatchScope &&
327
- !new Set([
328
- "board.dispatch.workspace",
329
- "board.dispatch.propose",
330
- "board.dispatch.view",
331
- "board.dispatch.apply",
332
- "board.dispatch.scope.list",
333
- "board.dispatch.scope.read",
334
- ]).has(command)
335
- )
336
- return "This run has only its scoped workspace and dispatch tools.";
337
404
  if (run.restricted && command.startsWith("mcp."))
338
405
  return "A restricted run reaches this computer's board, not the person's Harness.";
406
+ if (run.restricted || run.forAnotherPerson)
407
+ return privateReach(command, request, run, within);
339
408
  return null;
340
409
  }
341
410
  if (request.agent !== "user" && runMayAsk(command)) return null;
package/lib/runBrief.mjs CHANGED
@@ -38,6 +38,8 @@ export function createRunBriefs({
38
38
  threadFilesNote,
39
39
  t3CatchUp,
40
40
  wakeBrief,
41
+ // What a run in a thread is told of the thread's board of cards (kanban.mjs).
42
+ boardBrief = () => "",
41
43
  }) {
42
44
  // What claude-mem remembers about this folder joins the task's context and the brief, so an agent without claude-mem
43
45
  // starts from the same history one with it would. A wake resumes its own session.
@@ -203,7 +205,18 @@ export function createRunBriefs({
203
205
  text: refs.length ? `Context:\n${refs.join("\n")}` : "",
204
206
  pointer: `Context: ${refs.length} reference${refs.length === 1 ? "" : "s"}; get_task ${task.id} lists them.`,
205
207
  },
206
- ...(room?.kind === "goal" ? [roomSection(room, agent)] : []),
208
+ ...(room?.kind === "goal"
209
+ ? [
210
+ roomSection(room, agent),
211
+ {
212
+ name: "thread board",
213
+ priority: "recommended",
214
+ source: `thread ${room.id}`,
215
+ text: boardBrief(room.id),
216
+ pointer: `This thread has a board of cards the person follows its work on: keep yours current with update_board (thread ${room.id}).`,
217
+ },
218
+ ]
219
+ : []),
207
220
  // Who the agent works for, from the profile setup imported (profile.mjs); like lessons, only for agents here.
208
221
  {
209
222
  name: "the person",
package/lib/runWorker.mjs CHANGED
@@ -50,22 +50,42 @@ export function createRunWorker({
50
50
  const defaults = standingRules().filter((rule) => rule.mode === "default");
51
51
  if (defaults.length && !store.meta("standing_announced")) {
52
52
  const one = defaults.length === 1;
53
- const text = `${defaults.map((rule) => nameOf(rule.agent)).join(", ")} now ${one ? "starts" : "start"} the tasks you ask for in folders ${one ? "it has" : "they have"} worked in, up to ${defaults[0].daily_cap} a day${one ? "" : " each"}, without a Start.`;
53
+ const text = `${defaults.map((rule) => nameOf(rule.agent)).join(", ")} now ${one ? "starts" : "start"} the tasks you and your agents ask for, in any folder below your home, without a Start.`;
54
54
  log(text);
55
55
  notifyDesktop(text);
56
56
  store.meta("standing_announced", new Date().toISOString());
57
57
  }
58
- // Where a run works, one at a time: its folder, or for a turn T3 Code carries out, its thread (T3 keeps the checkout).
59
- // A review changes nothing (runner.mjs runs it read-only), so it goes beside whoever writes there: one review per
60
- // agent per thread, as its session is one (reviews once waited 168 min behind other agents' turns in 3 days).
58
+ // Where a run works, one at a time for each agent: its folder, or for a turn T3 Code carries out, its thread (T3 keeps
59
+ // the checkout). Different agents work in one folder side by side, as the person runs them (owner, October 31: Claude
60
+ // Code and OpenCode once waited 2 h 44 min behind Codex in one folder; "making me babysit my agents"); an agent keeps
61
+ // one turn at a time there, as its session is one. A review changes nothing (runner.mjs runs it read-only), so it
62
+ // goes beside whoever writes there: one review per agent per thread.
61
63
  const slotOf = (task) =>
62
64
  store.meta(`review:${task.id}`) === "1"
63
65
  ? `review:${task.target_agent}:${task.parent_id}`
64
66
  : store.meta(`t3-run:${task.id}`) === "1"
65
67
  ? `t3:${task.parent_id}`
66
68
  : task.run_workspace
67
- ? path.resolve(task.run_workspace)
69
+ ? `${path.resolve(task.run_workspace)}:${task.target_agent}`
68
70
  : task.target_agent;
71
+ // Who asked for a run: the agent whose post woke it in a thread, or that posted the task.
72
+ const askerOf = (task) => {
73
+ if (task.kind !== "wake") return task.origin_agent;
74
+ try {
75
+ return JSON.parse(store.meta(`wake-reason:${task.id}`) || "null")?.asker;
76
+ } catch {
77
+ return null;
78
+ }
79
+ };
80
+ // A hand-off waits for the turn of the agent that asked for it in the same folder, so it starts from that agent's
81
+ // finished work (a handoff posted while it waited reaches its brief); independent work there goes side by side.
82
+ const askerHolds = (task) => {
83
+ if (!task.run_workspace) return null;
84
+ const asker = askerOf(task);
85
+ return asker && asker !== task.target_agent
86
+ ? (activeRuns.get(`${path.resolve(task.run_workspace)}:${asker}`) ?? null)
87
+ : null;
88
+ };
69
89
  const runsInThread = (agent, threadId) =>
70
90
  [...activeRuns.values()].some(
71
91
  (held) =>
@@ -90,9 +110,13 @@ export function createRunWorker({
90
110
  if (refusal) return refusal;
91
111
  if (runsHeld)
92
112
  return `${who} starts when your Mac is no longer running with its lid closed.`;
93
- const holder = activeRuns.get(slotOf({ ...run, parent_id: goalId }));
94
- if (!holder) return null;
95
- return `${who} starts when ${nameOf(holder.agent)}'s turn ends: they work in the same folder, one at a time.`;
113
+ const own = activeRuns.get(slotOf({ ...run, parent_id: goalId }));
114
+ if (own)
115
+ return `${who} starts when its turn there now ends: an agent takes one turn at a time in a folder.`;
116
+ const asker = askerHolds(run);
117
+ return asker
118
+ ? `${who} starts when ${nameOf(asker.agent)}'s turn ends: they work in the same folder, one at a time.`
119
+ : null;
96
120
  };
97
121
  // A thread hears once why its agent did not start right away. Work an agent asked for while its own turn holds the
98
122
  // folder is not said: the asker was told when it asked, and the wait ends as it stops (the thread's waits still show it).
@@ -113,7 +137,7 @@ export function createRunWorker({
113
137
  };
114
138
  const runBoard = () => {
115
139
  if (runsHeld || !holdsBoard()) return;
116
- // One run per folder at a time: each thread's worktree is its own folder, so threads run side by side.
140
+ // One run per agent per folder at a time: other agents and other threads' worktrees run side by side.
117
141
  for (const task of store.runnableTasks(installedAgents, machineId(), {
118
142
  only: onlyItsOwn(),
119
143
  })) {
@@ -131,11 +155,14 @@ export function createRunWorker({
131
155
  noteWaiting(task, activeRuns.get(slot));
132
156
  continue;
133
157
  }
134
- // A task T3 carries out still waits for a run working in its folder, such as the turn of the agent that handed it
135
- // on: two runs never work one checkout at once.
158
+ if (!slot.startsWith("review:") && askerHolds(task)) {
159
+ noteWaiting(task, askerHolds(task));
160
+ continue;
161
+ }
162
+ // A task T3 carries out still waits for the same agent's run in its folder: one session there at a time.
136
163
  const folder =
137
164
  task.kind === "task" && slot.startsWith("t3:") && task.run_workspace
138
- ? path.resolve(task.run_workspace)
165
+ ? `${path.resolve(task.run_workspace)}:${agent}`
139
166
  : null;
140
167
  if (folder && activeRuns.has(folder)) continue;
141
168
  // An agent resumes one session per thread: its review waits while its own turn there runs.
@@ -168,22 +195,22 @@ export function createRunWorker({
168
195
  const startBoardRun = async (task, agent) => {
169
196
  const wake = task.kind === "wake";
170
197
  const room = !wake && task.parent_id ? store.getTask(task.parent_id) : null;
198
+ // Taken before the brief reads the thread: words posted while it is prepared, after it read them, are later than
199
+ // the start, so settleWake wakes the agent again for them instead of dropping them as already read.
200
+ const startedAt = new Date().toISOString();
171
201
  const {
172
202
  prompt,
173
203
  resumeSession,
174
204
  again,
175
205
  t3: inT3,
176
206
  } = dispatches?.briefFor(task) ?? (await briefs.prepare(task, agent));
177
- const startedAt = new Date().toISOString();
178
207
  const stoppedFor = Boolean(again);
179
208
  // The session it resumes is the run's from its first moment, so Open never resumes it beside the run before the
180
209
  // agent says which session it is in (OpenCode once said so only minutes into its turn).
181
210
  if (resumeSession && !task.session_id)
182
211
  store.setRunSession(task.id, resumeSession);
183
212
  const readOnly = store.meta(`review:${task.id}`) === "1";
184
- const dispatchOptions = dispatches?.optionsFor(task) ?? {};
185
- const restricted =
186
- restrictedRun(store, task) || Boolean(dispatchOptions.dispatchScope);
213
+ const restricted = restrictedRun(store, task);
187
214
  // Work another person asked for runs with only this person's own agent settings: the repository's own (its
188
215
  // .claude hooks, .pi, opencode.json) can be that person's, and would run here (security audit P4, October 25).
189
216
  const ownSettingsOnly = store.meta(`other-person-run:${task.id}`) === "1";
@@ -204,8 +231,9 @@ export function createRunWorker({
204
231
  // The person's environment grants (vault.mjs), never for a run they did not authorize: the values are in this
205
232
  // run's environment, and what it says is scrubbed of them.
206
233
  // Nor for a turn another of the person's agents asked for on standing permission: that grants a start, no secrets.
234
+ // Nor for work another person asked for, whoever started it: the person's secrets stay theirs.
207
235
  const secrets =
208
- restricted || store.standingProposal(task.id)
236
+ restricted || ownSettingsOnly || store.standingProposal(task.id)
209
237
  ? null
210
238
  : vaultEnv(task, agent);
211
239
  const granted = secrets && Object.keys(secrets.env).length ? secrets : null;
@@ -224,11 +252,7 @@ export function createRunWorker({
224
252
  ...(stoppedFor ? { again: true } : {}),
225
253
  ...(resumeSession && !t3 ? { resumeSession } : {}),
226
254
  ...(readOnly ? { readOnly } : {}),
227
- ...(dispatchOptions.dispatchScope
228
- ? dispatchOptions
229
- : restricted
230
- ? { restricted }
231
- : {}),
255
+ ...(restricted ? { restricted } : {}),
232
256
  ...(ownSettingsOnly ? { ownSettingsOnly } : {}),
233
257
  ...(t3 ? { t3 } : {}),
234
258
  ...(granted ? { env: granted.env, scrub: granted.values } : {}),
@@ -281,11 +305,11 @@ export function createRunWorker({
281
305
  setImmediate(runBoard);
282
306
  if (extra?.usage) store.setRunUsage(task.id, extra.usage);
283
307
  // Its changes are committed before it reports, so the audit of its report sees what was not.
284
- if (!dispatchOptions.dispatchScope) commitRun(task);
308
+ commitRun(task);
285
309
  // A run that failed without reaching its agent's own report ended early: the runner says why.
286
310
  const reported = store.reportTask(task.id, agent, {
287
311
  status: kind,
288
- result: dispatches?.resultFor(task, text || "") ?? (text || ""),
312
+ result: text || "",
289
313
  // Stopped for the person's steer (threadRuns.mjs): the person ended it, not the agent or its provider.
290
314
  failure: store.meta(`steered:${task.id}`)
291
315
  ? "person"