tryharness 0.7.71 → 0.7.72

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.
@@ -184,6 +184,14 @@ export function createOwnMachines({
184
184
  answerPrompt = null,
185
185
  // A cloud computer's own SSH keys (cloudSsh.mjs allow): { key, by } in, null on a computer that takes none.
186
186
  ownSsh = null,
187
+ // This computer updating itself to a published release (daemon.mjs): `tryharness upgrade <spec>`, which takes only a
188
+ // release signed with Harness's release key, started on its own so it outlives the daemon it restarts.
189
+ ownUpdate = () => ({
190
+ ok: false,
191
+ error: "this computer cannot update itself",
192
+ }),
193
+ // The release this computer runs, which an update never goes back from.
194
+ runningVersion = "0.0.0",
187
195
  }) {
188
196
  // On home: each worker's folders and the repository each holds, as it said them.
189
197
  const infos = new Map();
@@ -2104,12 +2112,14 @@ export function createOwnMachines({
2104
2112
  ? await ownLive(call.live)
2105
2113
  : call.ssh
2106
2114
  ? ownSshAllow(call.ssh)
2107
- : WINDOW_TOOLS.has(call.tool)
2108
- ? await askOwnWindows(call)
2109
- : {
2110
- ok: false,
2111
- error: `home cannot ask this computer's windows for ${call.tool}`,
2112
- };
2115
+ : call.update
2116
+ ? ownUpdateChecked(call.update)
2117
+ : WINDOW_TOOLS.has(call.tool)
2118
+ ? await askOwnWindows(call)
2119
+ : {
2120
+ ok: false,
2121
+ error: `home cannot ask this computer's windows for ${call.tool}`,
2122
+ };
2113
2123
  return {
2114
2124
  envelope: await sealAskAnswer(
2115
2125
  key,
@@ -2554,6 +2564,68 @@ export function createOwnMachines({
2554
2564
  );
2555
2565
  };
2556
2566
 
2567
+ // ---- updating another of the person's computers (tryharness machines update) ----
2568
+
2569
+ /**
2570
+ * The person updating one of their computers to a published release, from home: "latest" or a version, never an
2571
+ * older one than it runs, and never any other npm spec (a git address or a file would run code no release key
2572
+ * signed). The computer fetches and checks it itself; home only asks, over the pair's sealed line.
2573
+ */
2574
+ const update = async ({ computer: named, version = "latest" } = {}) => {
2575
+ const spec = String(version || "latest");
2576
+ if (spec !== "latest" && !/^\d+\.\d+\.\d+$/.test(spec))
2577
+ return {
2578
+ ok: false,
2579
+ error: `${spec} is not a release: give a version like 0.7.72, or latest`,
2580
+ };
2581
+ const target =
2582
+ findMachine(all(), named)?.id ??
2583
+ store.ownMachines().find((pinned) => pinned.label === named)
2584
+ ?.machine_id ??
2585
+ String(named || machine.id);
2586
+ if (target === machine.id) return ownUpdateChecked({ version: spec });
2587
+ if (!isHome())
2588
+ return {
2589
+ ok: false,
2590
+ error: "Ask home to update your other computers: it holds their keys.",
2591
+ };
2592
+ const worker = siblings.find((sibling) => sibling.id === target);
2593
+ if (!worker || !confirmed(worker))
2594
+ return {
2595
+ ok: false,
2596
+ error: "that computer is not one of yours confirmed on home",
2597
+ };
2598
+ return (
2599
+ (await askWorker(target, { update: { version: spec } })) ?? {
2600
+ ok: false,
2601
+ error: `${worker.label} did not answer; it may be asleep or offline`,
2602
+ }
2603
+ );
2604
+ };
2605
+ // Numbers only: a local build (0.7.71-local.abc) counts as its release.
2606
+ const releaseOf = (version) =>
2607
+ String(version)
2608
+ .split("-")[0]
2609
+ .split(".")
2610
+ .map((part) => Number(part) || 0);
2611
+ const older = (spec, than) => {
2612
+ const [a, b] = [releaseOf(spec), releaseOf(than)];
2613
+ for (let i = 0; i < 3; i++) if (a[i] !== b[i]) return a[i] < b[i];
2614
+ return false;
2615
+ };
2616
+ /** On the computer updated: the same checks again, as home's word is not taken for them. */
2617
+ const ownUpdateChecked = ({ version } = {}) => {
2618
+ const spec = String(version || "latest");
2619
+ if (spec !== "latest" && !/^\d+\.\d+\.\d+$/.test(spec))
2620
+ return { ok: false, error: `${spec} is not a release` };
2621
+ if (spec !== "latest" && older(spec, runningVersion))
2622
+ return {
2623
+ ok: false,
2624
+ error: `${labelOf(machine.id) ?? "This computer"} runs ${runningVersion}; it never moves back to ${spec}.`,
2625
+ };
2626
+ return ownUpdate(spec);
2627
+ };
2628
+
2557
2629
  // ---- the person's SSH key into a cloud computer (cloudSsh.mjs) ----
2558
2630
 
2559
2631
  const ownSshAllow = (ssh) =>
@@ -2929,6 +3001,7 @@ export function createOwnMachines({
2929
3001
  readSession,
2930
3002
  openSession,
2931
3003
  setModel,
3004
+ update,
2932
3005
  allowSsh,
2933
3006
  status,
2934
3007
  all,
package/lib/plans.mjs CHANGED
@@ -265,7 +265,13 @@ export function createPlans({
265
265
  targetAgent: node.agent,
266
266
  parentId: threadId,
267
267
  });
268
- if (posted?.ok && posted.task?.id) {
268
+ // While the guard reads its words, the post answers { pending, task }: the task is in, and only whether it may
269
+ // start waits (taskCommands.mjs). Read as no answer, a step was once marked "could not be posted".
270
+ if (posted?.pending)
271
+ void posted.pending.catch((error) =>
272
+ log(`plan ${node.id} start not decided: ${error.message}`)
273
+ );
274
+ if ((posted?.ok || posted?.pending) && posted.task?.id) {
269
275
  node.taskId = posted.task.id;
270
276
  node.state = "posted";
271
277
  } else {
@@ -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) : [];
@@ -69,6 +69,24 @@ export function createPromptFlow({
69
69
  notify(store.getTask(job.task_id));
70
70
  return next;
71
71
  };
72
+ // Words no typed work here can take go to Harness as any message to it does, and wait for its window: they were held
73
+ // behind a card that asked the person about the error ("Harness is asking: No registered execution capability is
74
+ // available").
75
+ const toHarness = (job, why) => {
76
+ if (job.state === "cancelled") return job;
77
+ const task = store.postTask({
78
+ objective: job.prompt.slice(0, 500),
79
+ brief: job.prompt,
80
+ originAgent: "user",
81
+ targetAgent: "harness",
82
+ });
83
+ store.meta(`prompt-flow-task:${task.id}`, job.id);
84
+ store.removeTask(job.task_id);
85
+ const next = { ...job, state: "harness", task_id: task.id, why };
86
+ save(next);
87
+ notify(store.getTask(task.id));
88
+ return next;
89
+ };
72
90
  const applyReceipt = async (job, receipt) => {
73
91
  job = read(job.id);
74
92
  if (job.state === "cancelled") return job;
@@ -140,7 +158,8 @@ export function createPromptFlow({
140
158
  };
141
159
  const status = async (job) => {
142
160
  if (active.has(job.id)) return response(job);
143
- if (["done", "held", "cancelled"].includes(job.state)) return response(job);
161
+ if (["done", "held", "cancelled", "harness"].includes(job.state))
162
+ return response(job);
144
163
  if (job.state === "interpreting" && !job.assignment && !job.file_task)
145
164
  return response(
146
165
  held(
@@ -296,6 +315,15 @@ export function createPromptFlow({
296
315
  workspace: folder,
297
316
  capability_ref: "capability:workspace-files@1",
298
317
  });
318
+ // Nothing here can run typed work and the words name no computer: they are a message for Harness. Words that
319
+ // name a computer that cannot take them still wait for the person, never routed elsewhere.
320
+ const namesComputer = computers().some((c) =>
321
+ job.prompt.toLowerCase().includes(c.label.toLowerCase())
322
+ );
323
+ if (!candidates.length && !namesComputer) {
324
+ toHarness(read(job.id), "no registered execution capability");
325
+ return;
326
+ }
299
327
  if (!candidates.length)
300
328
  throw new Error("No registered execution capability is available");
301
329
  const modelInfo = decider.info();
@@ -498,6 +526,13 @@ export function createPromptFlow({
498
526
  );
499
527
  if (!job) return { ok: false, error: "Prompt work not found" };
500
528
  if (job.state === "done") return response(job);
529
+ // Handed to Harness as a plain message: taking it back removes it, as for any message to Harness.
530
+ if (job.state === "harness") {
531
+ store.removeTask(job.task_id);
532
+ save({ ...job, state: "cancelled" });
533
+ notify(store.getTask(job.task_id));
534
+ return response(read(job.id));
535
+ }
501
536
  store.dispatchTransaction(() => {
502
537
  const task = store.getTask(job.task_id);
503
538
  if (task.status === "needs_input") {
@@ -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,13 +183,21 @@ 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
203
  const standingVerdict = ({ trust, target, workspace, capacity = true }) => {
@@ -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 (capacity && 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) ||
@@ -336,6 +415,8 @@ export function createRunAuthority({ store, installedAgents }) {
336
415
  return "This run has only its scoped workspace and dispatch tools.";
337
416
  if (run.restricted && command.startsWith("mcp."))
338
417
  return "A restricted run reaches this computer's board, not the person's Harness.";
418
+ if (run.restricted || run.forAnotherPerson)
419
+ return privateReach(command, request, run, within);
339
420
  return null;
340
421
  }
341
422
  if (request.agent !== "user" && runMayAsk(command)) return null;
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,13 +195,15 @@ 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).
@@ -204,8 +233,9 @@ export function createRunWorker({
204
233
  // The person's environment grants (vault.mjs), never for a run they did not authorize: the values are in this
205
234
  // run's environment, and what it says is scrubbed of them.
206
235
  // Nor for a turn another of the person's agents asked for on standing permission: that grants a start, no secrets.
236
+ // Nor for work another person asked for, whoever started it: the person's secrets stay theirs.
207
237
  const secrets =
208
- restricted || store.standingProposal(task.id)
238
+ restricted || ownSettingsOnly || store.standingProposal(task.id)
209
239
  ? null
210
240
  : vaultEnv(task, agent);
211
241
  const granted = secrets && Object.keys(secrets.env).length ? secrets : null;