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
package/lib/runner.mjs CHANGED
@@ -22,14 +22,20 @@ const issueCapability = (task) => {
22
22
  capabilities.set(token, {
23
23
  id: task.runId,
24
24
  agent: task.agent,
25
- restricted: task.restricted === true || Boolean(task.dispatchScope),
25
+ restricted: task.restricted === true,
26
26
  review: task.readOnly === true,
27
- dispatchScope: task.dispatchScope ?? null,
27
+ // Work another person asked for (runWorker.mjs ownSettingsOnly), and the folder it works in: such a run reaches
28
+ // none of the person's private things beyond that folder (runAuthority.mjs privateReach).
29
+ forAnotherPerson: task.ownSettingsOnly === true,
30
+ cwd: task.cwd ? path.resolve(task.cwd) : null,
28
31
  });
29
32
  return token;
30
33
  };
31
34
 
32
- /** The run a capability belongs to while that run goes on: its id, agent, and whether it is restricted or a review. */
35
+ /**
36
+ * The run a capability belongs to while that run goes on: its id, agent, whether it is restricted or a review, whether
37
+ * it works for another person, and its folder.
38
+ */
33
39
  export function runCapability(token) {
34
40
  return capabilities.get(String(token)) ?? null;
35
41
  }
@@ -159,29 +165,146 @@ const readDenials = (home) =>
159
165
  ? HARNESS_FILES.map((file) => `Read(/${path.join(place, file)})`)
160
166
  : [`Read(/${place})`, `Read(/${place}/**)`]
161
167
  );
168
+ // A run nobody pressed Start on reads only its own folder (owner, October 31: "nothing outside that without the consent
169
+ // of the user"). Denied: every home folder and the drives and shares mounted from outside, where people keep their
170
+ // files. Still readable: the operating system's own folders, the programs a run builds and tests with, git's settings,
171
+ // and the repository a worktree belongs to, whose history git reads.
172
+ const PERSONAL_ROOTS = ["/Volumes", "/media", "/mnt", "/run/media"];
173
+ const PROGRAM_PLACES = [
174
+ ".nvm",
175
+ ".volta",
176
+ ".bun",
177
+ ".deno",
178
+ ".cargo/bin",
179
+ ".rustup",
180
+ ".pyenv",
181
+ ".asdf",
182
+ ".local/bin",
183
+ ".local/share/mise",
184
+ "go/bin",
185
+ // Without its settings git refuses to run at all, and a commit has no author.
186
+ ".gitconfig",
187
+ ".config/git",
188
+ ];
189
+ // The shell snapshot each agent's shell tool sources before every command, kept in that agent's own folder.
190
+ const SHELL_SNAPSHOTS = {
191
+ "claude-code": ".claude/shell-snapshots",
192
+ codex: ".codex/shell_snapshots",
193
+ };
194
+ const personalRoots = (home) => [
195
+ ...new Set([path.dirname(home), ...PERSONAL_ROOTS]),
196
+ ];
197
+ // A worktree's `.git` is a file naming its git folder inside the checkout it came from; git reads both.
198
+ const gitFolders = (cwd) => {
199
+ let pointer = "";
200
+ try {
201
+ pointer = fs.readFileSync(path.join(cwd, ".git"), "utf8");
202
+ } catch {
203
+ return [];
204
+ }
205
+ const own = pointer.match(/^gitdir: (.+)$/m)?.[1]?.trim();
206
+ if (!own) return [];
207
+ const gitDir = path.resolve(cwd, own);
208
+ let common = gitDir;
209
+ try {
210
+ common = path.resolve(
211
+ gitDir,
212
+ fs.readFileSync(path.join(gitDir, "commondir"), "utf8").trim()
213
+ );
214
+ } catch {}
215
+ return [...new Set([gitDir, common])];
216
+ };
217
+ /** What `agent`'s run held to its folder still reads beneath the places it may not: its folder, git's, programs. */
218
+ export const confinedReads = (
219
+ cwd,
220
+ home = os.homedir(),
221
+ agent = "claude-code"
222
+ ) => [
223
+ ...(cwd ? [cwd, ...gitFolders(cwd)] : []),
224
+ ...[...PROGRAM_PLACES, SHELL_SNAPSHOTS[agent]].map((place) =>
225
+ path.join(home, place)
226
+ ),
227
+ ];
228
+ const within = (place, root) => {
229
+ const relative = path.relative(root, place);
230
+ return (
231
+ relative === "" ||
232
+ (!relative.startsWith("..") && !path.isAbsolute(relative))
233
+ );
234
+ };
235
+ /**
236
+ * Every place a run held to its folder may not read, as absolute paths. Not a whole home folder with the run's own let
237
+ * back in: git walks up the folders above its own and stops at one it cannot look at, and Claude Code's file tools
238
+ * take no exception inside a deny. So each entry beside the path down to a place it may read is named, as the run
239
+ * starts; the folders on that path show their entries' names and nothing in them. A secret place is denied even where
240
+ * it lies beside an open one.
241
+ */
242
+ export const fencedPlaces = (
243
+ cwd,
244
+ home = os.homedir(),
245
+ agent = "claude-code"
246
+ ) => {
247
+ const open = confinedReads(cwd, home, agent);
248
+ const fenced = [];
249
+ const fence = (place, secret = false) => {
250
+ if (!secret && open.some((root) => within(place, root))) return;
251
+ if (!open.some((root) => root !== place && within(root, place))) {
252
+ fenced.push(place);
253
+ return;
254
+ }
255
+ let entries = [];
256
+ try {
257
+ entries = fs.readdirSync(place);
258
+ } catch {
259
+ return;
260
+ }
261
+ for (const entry of entries) fence(path.join(place, entry));
262
+ };
263
+ for (const root of personalRoots(home)) if (fs.existsSync(root)) fence(root);
264
+ for (const place of secretPlaces(home)) fence(place, true);
265
+ return [...new Set(fenced)];
266
+ };
162
267
  // The sandbox holds shell commands to the same places. The run's own folder stays readable even inside Harness's home,
163
- // where its worktree is, and so do the shell snapshots each agent's shell tool sources before every command.
164
- const sandboxReads = (cwd, home) => ({
165
- denyRead: secretPlaces(home),
166
- allowRead: [
167
- ...(cwd ? [cwd] : []),
168
- path.join(home, ".claude", "shell-snapshots"),
169
- ],
170
- });
268
+ // where its worktree is, and so do the shell snapshots each agent's shell tool sources before every command. A run
269
+ // held to its folder (`confined`) reads nothing else of the person's.
270
+ const sandboxReads = (cwd, home, confined = false) =>
271
+ confined
272
+ ? { denyRead: fencedPlaces(cwd, home), allowRead: confinedReads(cwd, home) }
273
+ : {
274
+ denyRead: secretPlaces(home),
275
+ allowRead: [
276
+ ...(cwd ? [cwd] : []),
277
+ path.join(home, ".claude", "shell-snapshots"),
278
+ ],
279
+ };
280
+ const confinedDenials = (cwd, home, confined) =>
281
+ confined
282
+ ? fencedPlaces(cwd, home).flatMap((place) => [
283
+ `Read(/${place})`,
284
+ `Read(/${place}/**)`,
285
+ ])
286
+ : [];
171
287
 
172
288
  // A run another agent started without the person's tap (docs/member-runs.md): anything that would ask is refused, file
173
289
  // edits only in its worktree, shell commands only inside the operating system's sandbox with no network, nothing read
174
290
  // where the person keeps credentials, and no hooks or settings from the repository. A review gets no edits at all.
175
291
  export const restrictedClaudeSettings = (cwd, home = os.homedir()) => ({
176
292
  disableAllHooks: true,
177
- permissions: { deny: ["WebFetch", "WebSearch", ...readDenials(home)] },
293
+ permissions: {
294
+ deny: [
295
+ "WebFetch",
296
+ "WebSearch",
297
+ ...readDenials(home),
298
+ ...confinedDenials(cwd, home, true),
299
+ ],
300
+ },
178
301
  sandbox: {
179
302
  enabled: true,
180
303
  autoAllowBashIfSandboxed: true,
181
304
  allowUnsandboxedCommands: false,
182
305
  failIfUnavailable: true,
183
306
  excludedCommands: [],
184
- filesystem: sandboxReads(cwd, home),
307
+ filesystem: sandboxReads(cwd, home, true),
185
308
  network: { allowedDomains: [], strictAllowlist: true },
186
309
  },
187
310
  });
@@ -286,15 +409,26 @@ const modelWindow = ({ limits }) =>
286
409
  // folder is refused; denying edits everywhere also broke Claude Code's own scratch files under /tmp). It reads nothing
287
410
  // where the person keeps credentials, loads no settings or hooks from the repository it reviews, and has no web: what
288
411
  // it reviews is in the folder and the thread, and a fetch is a way out for what it read.
289
- export const readOnlyClaudeSettings = (cwd, home = os.homedir()) => ({
412
+ // A review nobody pressed Start on (`confined`) reads only its folder, as a restricted run does.
413
+ export const readOnlyClaudeSettings = (
414
+ cwd,
415
+ home = os.homedir(),
416
+ confined = false
417
+ ) => ({
290
418
  permissions: {
291
- deny: ["Edit(./**)", "WebFetch", "WebSearch", ...readDenials(home)],
419
+ deny: [
420
+ "Edit(./**)",
421
+ "WebFetch",
422
+ "WebSearch",
423
+ ...readDenials(home),
424
+ ...confinedDenials(cwd, home, confined),
425
+ ],
292
426
  },
293
427
  sandbox: {
294
428
  enabled: true,
295
429
  autoAllowBashIfSandboxed: true,
296
430
  allowUnsandboxedCommands: false,
297
- filesystem: sandboxReads(cwd, home),
431
+ filesystem: sandboxReads(cwd, home, confined),
298
432
  network: { allowedDomains: [], strictAllowlist: true },
299
433
  },
300
434
  });
@@ -309,20 +443,30 @@ const readOnlyClaude = (task) => [
309
443
  "user",
310
444
  "--settings",
311
445
  JSON.stringify({
312
- ...readOnlyClaudeSettings(task.cwd),
446
+ ...readOnlyClaudeSettings(task.cwd, os.homedir(), task.restricted === true),
313
447
  ...modelWindow(task),
314
448
  }),
315
449
  ];
316
450
 
317
451
  // Codex's review: its read-only permission profile, with the same places denied to every command it runs (the run's
318
452
  // own folder stays readable when it lies inside one) and no web search. Probed with `codex sandbox` 0.164: a denied
319
- // file is "Operation not permitted", the folder reads, writes and the daemon's socket are refused.
320
- const codexReview = (task, executable, home = os.homedir()) => {
453
+ // file is "Operation not permitted", the folder reads, writes and the daemon's socket are refused. A restricted run
454
+ // (`write`) has the same profile with its own folder writable: probed with `codex sandbox` 0.166, it writes there,
455
+ // ~/.ssh is denied and the network is refused, as for Claude Code's restricted run. A restricted run, or a review
456
+ // nobody pressed Start on, reads only its folder: the more specific place wins, so the folder, git's and the programs
457
+ // under a denied home stay readable.
458
+ const codexReview = (task, executable, home = os.homedir(), write = false) => {
459
+ const confined = write || task.restricted === true;
321
460
  const places = Object.fromEntries(
322
- secretPlaces(home).map((place) => [place, "deny"])
461
+ (confined ? fencedPlaces(task.cwd, home, "codex") : secretPlaces(home)).map(
462
+ (place) => [place, "deny"]
463
+ )
323
464
  );
465
+ if (confined)
466
+ for (const place of confinedReads(task.cwd, home, "codex"))
467
+ places[place] = "read";
324
468
  places[path.join(home, ".codex", "shell_snapshots")] = "read";
325
- if (task.cwd) places[task.cwd] = "read";
469
+ if (task.cwd) places[task.cwd] = write ? "write" : "read";
326
470
  // Standalone Codex lives inside its denied credential home and reexecutes
327
471
  // itself to load AGENTS.md. Only its confirmed, resolved file needs access.
328
472
  if (executable) places[executable] = "read";
@@ -347,53 +491,6 @@ const codexReview = (task, executable, home = os.homedir()) => {
347
491
  export const READ_ONLY_AGENTS = new Set(["claude-code", "codex"]);
348
492
 
349
493
  export function agentInvocation(task, { executable = null } = {}) {
350
- if (task.dispatchScope) {
351
- if (task.agent !== "claude-code")
352
- throw new Error(
353
- "No mediated workspace executor is registered for this agent"
354
- );
355
- const mcp = {
356
- mcpServers: {
357
- harness: {
358
- command: process.execPath,
359
- args: [
360
- fileURLToPath(new URL("./mcp-stdio.mjs", import.meta.url)),
361
- "--agent",
362
- "claude-code",
363
- "--restricted",
364
- "--scope",
365
- task.dispatchScope,
366
- ],
367
- },
368
- },
369
- };
370
- return {
371
- command: "claude",
372
- args: [
373
- "-p",
374
- task.brief,
375
- "--output-format",
376
- "stream-json",
377
- "--verbose",
378
- ...modelFlags(task),
379
- "--tools",
380
- "",
381
- "--bare",
382
- "--restricted",
383
- "--allowedTools",
384
- "mcp__harness__dispatch_work mcp__harness__scope_workspace",
385
- "--permission-mode",
386
- "dontAsk",
387
- "--strict-mcp-config",
388
- "--mcp-config",
389
- JSON.stringify(mcp),
390
- "--setting-sources",
391
- "",
392
- "--settings",
393
- JSON.stringify({ disableAllHooks: true }),
394
- ],
395
- };
396
- }
397
494
  if (task.agent === "claude-code") {
398
495
  return {
399
496
  command: "claude",
@@ -425,8 +522,9 @@ export function agentInvocation(task, { executable = null } = {}) {
425
522
  ],
426
523
  };
427
524
  }
428
- // Only Claude Code has a restricted mode; any other agent's restricted run is refused here, whatever let it start.
429
- if (task.restricted)
525
+ // Only Claude Code and Codex have a restricted mode; any other agent's restricted run is refused here, whatever let it
526
+ // start.
527
+ if (task.restricted && task.agent !== "codex")
430
528
  throw new Error(
431
529
  `${task.agent} has no restricted mode; it runs only after the person's Start`
432
530
  );
@@ -449,7 +547,18 @@ export function agentInvocation(task, { executable = null } = {}) {
449
547
  "-c",
450
548
  'mcp_servers.harness.default_tools_approval_mode="approve"',
451
549
  ]
452
- : ["--dangerously-bypass-approvals-and-sandbox"]),
550
+ : task.restricted
551
+ ? [
552
+ ...codexReview(task, executable, os.homedir(), true),
553
+ "-c",
554
+ 'approval_policy="never"',
555
+ // Only Harness's board, as for restricted Claude Code: none of the person's other MCP servers.
556
+ "-c",
557
+ `mcp_servers={harness={command=${JSON.stringify(process.execPath)},args=${JSON.stringify([fileURLToPath(new URL("./mcp-stdio.mjs", import.meta.url)), "--agent", "codex", "--restricted"])}}}`,
558
+ "-c",
559
+ 'mcp_servers.harness.default_tools_approval_mode="approve"',
560
+ ]
561
+ : ["--dangerously-bypass-approvals-and-sandbox"]),
453
562
  "--skip-git-repo-check",
454
563
  "-",
455
564
  ],
@@ -710,17 +819,17 @@ export function readRunSteps(file, limit = 200) {
710
819
  }
711
820
 
712
821
  export function runAgentTask(task, emit, observe = () => {}, hooks = {}) {
713
- // One run per folder: two agents in one checkout would trip over each other; a thread's worktree is its own folder.
714
- // A read-only review edits nothing, so it goes beside whoever writes there (runWorker.mjs keeps one per agent).
822
+ // One run per agent per folder: an agent's session there is one; other agents work beside it, as the person runs them
823
+ // (runWorker.mjs slotOf). A read-only review edits nothing, so it goes beside whoever writes there.
715
824
  const slot = task.readOnly
716
825
  ? `review:${task.agent}:${task.cwd || ""}`
717
826
  : task.cwd
718
- ? path.resolve(task.cwd)
827
+ ? `${path.resolve(task.cwd)}:${task.agent}`
719
828
  : task.agent;
720
829
  if (running.has(slot)) {
721
830
  emit(
722
831
  "failed",
723
- `Another run is already working in ${task.cwd || "that folder"}.`,
832
+ `${task.agent} is already working in ${task.cwd || "that folder"}.`,
724
833
  { failure: "start" }
725
834
  );
726
835
  return;
@@ -0,0 +1,41 @@
1
+ import fs from "node:fs";
2
+ import path from "node:path";
3
+ import { spawn } from "node:child_process";
4
+ import { fileURLToPath } from "node:url";
5
+ import { paths } from "./paths.mjs";
6
+
7
+ const CLI = fileURLToPath(new URL("../cli.mjs", import.meta.url));
8
+
9
+ /** What an update this computer started did, line by line: the upgrade's own words go here too. */
10
+ export const updateLog = () => path.join(paths.home, "update.log");
11
+
12
+ /**
13
+ * This computer updating itself to a published release, as the person asked from home (ownMachines.mjs update):
14
+ * `tryharness upgrade <spec>`, which fetches it, takes it only signed with Harness's release key and sets it up. It
15
+ * runs on its own, since setting up restarts the daemon that started it, and opens no window on a computer the person
16
+ * may not be at.
17
+ */
18
+ export function startUpdate(spec, { from, log = () => {} }) {
19
+ const out = fs.openSync(updateLog(), "a");
20
+ try {
21
+ fs.writeSync(
22
+ out,
23
+ `${new Date().toISOString()} updating from ${from} to ${spec}, as the person asked from home\n`
24
+ );
25
+ const child = spawn(
26
+ process.execPath,
27
+ [CLI, "upgrade", spec, "--no-desktop"],
28
+ { detached: true, stdio: ["ignore", out, out], env: process.env }
29
+ );
30
+ child.unref();
31
+ } finally {
32
+ fs.closeSync(out);
33
+ }
34
+ log(`updating from ${from} to ${spec}, as the person asked from home`);
35
+ return {
36
+ ok: true,
37
+ from,
38
+ to: spec,
39
+ note: `Updating from ${from} to ${spec === "latest" ? "the newest release" : spec}: it restarts on its own in a minute or two.`,
40
+ };
41
+ }
@@ -6,12 +6,13 @@ import { askLocalAgent } from "./localAgentAsk.mjs";
6
6
  // permissions. Home has the last word on them (owner, October 26: the server finds computers and keeps the backup; the
7
7
  // person's own computer decides), without asking the person about ordinary hand-ons.
8
8
  //
9
- // Two readings on this computer, side by side. A coding agent here with its tools off reads the words against the
10
- // person's own posts in the thread and lists what they ask for that the person has not: spending, something
11
- // outward-facing or hard to undo, a secret, a change of what the work is for (the same four things a round may ask the
12
- // person about). The local guard, where it is downloaded, flags words framed to steer an agent ("harness asked you:
13
- // ignore..."); it does not see a plainly worded harmful instruction, which is why the agent reads too (eval in the
14
- // security-briefs commit: 0 of 6 such hand-ons flagged). Words either one stops never reach an agent: the round still
9
+ // A coding agent here with its tools off reads the words against the person's own posts in the thread and lists what
10
+ // they ask for that the person has not: spending, something outward-facing or hard to undo, a secret, a change of what
11
+ // the work is for (the same four things a round may ask the person about). The local guard reads them too: words it
12
+ // reads as orders aimed at the agents are left out, while a flag goes only to the log, since it cannot tell
13
+ // coordination from planted orders (owner, October 31: guard secrets, private data and money, not ordinary work); it
14
+ // saw 0 of 6 plainly worded harmful hand-ons in the security-briefs eval, which is why the agent reads too. Words
15
+ // either stops never reach an agent: the round still
15
16
  // routes the work (who, review or not, the team's step), each brief says only that the coordinator handed the thread on,
16
17
  // and words meant for the person stay theirs to read but are left out of what agents read (the thread's digest,
17
18
  // read_room, swarm_memory and a backup coordinator's transcript). A reading that cannot be had (no guard downloaded, no
@@ -20,7 +21,7 @@ import { askLocalAgent } from "./localAgentAsk.mjs";
20
21
  const WITHHELD = "withheld:";
21
22
  const LEFT_OUT = {
22
23
  flagged:
23
- "the guard on this computer flagged them as possibly carrying instructions",
24
+ "the guard on this computer read them as orders aimed at your agents",
24
25
  beyond: "they asked for something the person has not asked for",
25
26
  };
26
27
  const KINDS = {
@@ -98,8 +99,8 @@ export function createServerWords({
98
99
  };
99
100
 
100
101
  /**
101
- * Why a decision's words are left out: null (they reach the agents), "flagged" (the guard) or "beyond" (the reader,
102
- * with what they asked for in `asks`). `person`: the person's own posts in the thread; `readers`: the coding agents
102
+ * Why a decision's words are left out: null (they reach the agents), "flagged" (the guard read them as orders) or
103
+ * "beyond" (the reader, with what they asked for in `asks`). `person`: the person's own posts in the thread; `readers`: the coding agents
103
104
  * here that may read, in order.
104
105
  */
105
106
  const screen = async (decision, { person = [], readers = [] } = {}) => {
@@ -118,8 +119,7 @@ export function createServerWords({
118
119
  `coordinator: the round's words were read in ${Date.now() - startedAt} ms (guard ${reading?.unavailable ? "not here" : (reading?.verdict ?? "clean")}, reader ${asks === null ? "not had" : `${asks.length} beyond`})`
119
120
  );
120
121
  if (asks?.length) return { reason: "beyond", asks };
121
- if (reading?.verdict === "flag" || reading?.verdict === "hold")
122
- return { reason: "flagged", asks: [] };
122
+ if (reading?.verdict === "hold") return { reason: "flagged", asks: [] };
123
123
  return { reason: null, asks: [] };
124
124
  };
125
125
 
@@ -46,6 +46,12 @@ import {
46
46
  terminalSessions,
47
47
  } from "./places.mjs";
48
48
  import { resumeInNeovim, showInNeovim } from "./neovim.mjs";
49
+ import {
50
+ herdrInstalled,
51
+ herdrRunning,
52
+ resumeInHerdr,
53
+ showInHerdr,
54
+ } from "./herdr.mjs";
49
55
  import { detectAgentApps, detectMcpClients } from "./adapters.mjs";
50
56
  import { resolveCommand } from "./commands.mjs";
51
57
  import { handedToT3, sendToT3, t3Access } from "./t3.mjs";
@@ -58,6 +64,8 @@ export function createSessionControl({
58
64
  activeRuns,
59
65
  // Every value in the person's vault out of what a live read shows (vault.mjs).
60
66
  scrub = (value) => value,
67
+ // A running session's subagents (subagentSteering.mjs ofSession).
68
+ subagentsOf = () => [],
61
69
  }) {
62
70
  const saidKey = (agent, sessionId) => `said:${agent}:${sessionId}`;
63
71
  const said = (agent, sessionId) => {
@@ -355,8 +363,9 @@ export function createSessionControl({
355
363
  reported: reportedSessions(),
356
364
  table,
357
365
  });
358
- // Who started each, when another agent's session or one of Harness's runs did: seen now, else as it started.
359
- const owners = ownersOf(found, table);
366
+ // Who started each, when another agent's session or one of Harness's runs did: seen now, else as it started. The
367
+ // table again: one a session just started was read into is the kept one now.
368
+ const owners = ownersOf(found, processTable());
360
369
  const sessions = found
361
370
  .map((session) => ({
362
371
  ...session,
@@ -503,6 +512,7 @@ export function createSessionControl({
503
512
  if (gone && place.kind === "nvim")
504
513
  return { ...place, app: lastResort().app };
505
514
  if (gone && place.kind === "codex-app") return null;
515
+ if (place.kind === "herdr") return herdrInstalled(place) ? place : null;
506
516
  return place;
507
517
  };
508
518
  const homeOf = (agentId) => {
@@ -563,6 +573,26 @@ export function createSessionControl({
563
573
  one.server && all.findIndex((x) => x.server === one.server) === index
564
574
  );
565
575
  };
576
+ /**
577
+ * What the buddy does once herdr shows a pane: the terminal a herdr client is attached in comes forward on its tab; with
578
+ * none attached, the person's terminal opens herdr itself, which shows the pane focused.
579
+ */
580
+ const herdrShown = (agentId, shown) => {
581
+ if (shown.attach)
582
+ return {
583
+ resume: {
584
+ agent: agentId,
585
+ session: null,
586
+ cwd: null,
587
+ app: lastResort().app,
588
+ within: "herdr",
589
+ },
590
+ };
591
+ const forward = focusTerminal(shown);
592
+ return forward.app
593
+ ? forward
594
+ : { note: `It's up in herdr, which runs outside any app here.` };
595
+ };
566
596
  /** Whether one of Harness's runs is still working in this session: it is not resumed beside it. */
567
597
  const runBusy = (sessionId) =>
568
598
  Boolean(sessionId) &&
@@ -682,6 +712,31 @@ export function createSessionControl({
682
712
  ...(fresh ? { note: freshNote(agentId, name) } : {}),
683
713
  };
684
714
  }
715
+ // In a new tab of the person's herdr, on the folder; when that herdr is not running, wherever else it opens.
716
+ if (place.kind === "herdr") {
717
+ if (!CODING_AGENTS.includes(agentId) || !herdrRunning(place)) return null;
718
+ if (busy) return { opensIn: "herdr", note: busy };
719
+ const fresh = startsFresh(agentId, sessionId);
720
+ if (!act)
721
+ return {
722
+ opensIn: "herdr",
723
+ ...(fresh ? { note: freshNote(agentId, "herdr") } : {}),
724
+ };
725
+ const command =
726
+ sessionId && !fresh
727
+ ? resumeLine(agentId, sessionId)
728
+ : agentCommand(agentId);
729
+ const shown = command
730
+ ? resumeInHerdr(place, command, folder, nameOf(agentId))
731
+ : null;
732
+ if (!shown) return null;
733
+ const opened = herdrShown(agentId, shown);
734
+ return {
735
+ opensIn: "herdr",
736
+ ...opened,
737
+ ...(fresh ? { note: freshNote(agentId, "herdr") } : {}),
738
+ };
739
+ }
685
740
  if (place.kind === "terminal") {
686
741
  if (!CODING_AGENTS.includes(agentId)) return null;
687
742
  if (busy)
@@ -705,6 +760,13 @@ export function createSessionControl({
705
760
  /** A running session, where it runs: its T3 thread, its panel, its editor's window, its terminal pane and tab. */
706
761
  const runningPlan = (live, act) => {
707
762
  const place = placesOf(live.agent)[live.sessionId] ?? null;
763
+ // Its pane in herdr, then the terminal herdr is attached in; before the app up its process tree, which is where
764
+ // herdr's server started (T3 Code's terminal, say), not where the session shows.
765
+ if (place?.kind === "herdr") {
766
+ const shown = act ? showInHerdr(place) : null;
767
+ if (shown) return { opensIn: "herdr", ...herdrShown(live.agent, shown) };
768
+ if (!act) return { opensIn: "herdr" };
769
+ }
708
770
  if (
709
771
  (live.host && /^T3 Code\b/.test(live.host.name)) ||
710
772
  place?.kind === "t3"
@@ -1008,7 +1070,10 @@ export function createSessionControl({
1008
1070
  error: "only the person reads or messages their sessions",
1009
1071
  };
1010
1072
  if (request.command === "board.live") {
1011
- const sessions = liveNow();
1073
+ const sessions = liveNow().map((session) => {
1074
+ const subagents = subagentsOf(session);
1075
+ return subagents.length ? { ...session, subagents } : session;
1076
+ });
1012
1077
  return {
1013
1078
  ok: true,
1014
1079
  sessions,