tryharness 0.7.67 → 0.7.69

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 (54) hide show
  1. package/lib/boardFileCommands.mjs +5 -7
  2. package/lib/boardFiles.mjs +5 -0
  3. package/lib/boardProtocol.json +50 -64
  4. package/lib/boardWaits.mjs +6 -0
  5. package/lib/cards.mjs +13 -1
  6. package/lib/comfyExecution.mjs +545 -0
  7. package/lib/context.mjs +34 -20
  8. package/lib/contextWorker.mjs +199 -0
  9. package/lib/coordinator.mjs +224 -22
  10. package/lib/daemon.mjs +196 -14
  11. package/lib/dispatchContract.json +313 -0
  12. package/lib/dispatchTools.js +87 -0
  13. package/lib/dispatches.mjs +975 -0
  14. package/lib/environment.mjs +54 -69
  15. package/lib/files.mjs +35 -0
  16. package/lib/frames.mjs +5 -9
  17. package/lib/goalCommands.mjs +13 -10
  18. package/lib/kept.mjs +131 -0
  19. package/lib/landed.mjs +1 -34
  20. package/lib/library.mjs +18 -11
  21. package/lib/live.mjs +30 -11
  22. package/lib/localAgentAsk.mjs +27 -4
  23. package/lib/localStack.mjs +17 -13
  24. package/lib/machineRoutes.mjs +5 -0
  25. package/lib/machineRuns.mjs +2 -1
  26. package/lib/mcp-stdio.mjs +42 -1
  27. package/lib/openHere.mjs +36 -0
  28. package/lib/openRequests.mjs +56 -0
  29. package/lib/ownMachines.mjs +232 -24
  30. package/lib/phones.mjs +29 -4
  31. package/lib/places.mjs +44 -11
  32. package/lib/portCalls.mjs +54 -0
  33. package/lib/promptDecider.mjs +471 -0
  34. package/lib/promptFlow.mjs +562 -0
  35. package/lib/promptScopes.mjs +670 -0
  36. package/lib/provenance.mjs +3 -2
  37. package/lib/runAuthority.mjs +14 -2
  38. package/lib/runBrief.mjs +2 -2
  39. package/lib/runWorker.mjs +25 -5
  40. package/lib/runner.mjs +62 -6
  41. package/lib/sealed.mjs +37 -0
  42. package/lib/sessionControl.mjs +47 -14
  43. package/lib/sessionIndex.mjs +11 -3
  44. package/lib/store.mjs +362 -40
  45. package/lib/swarm.mjs +85 -34
  46. package/lib/swarmMemory.mjs +39 -16
  47. package/lib/taskCommands.mjs +125 -1
  48. package/lib/team.json +10 -0
  49. package/lib/team.mjs +287 -26
  50. package/lib/threadBriefs.mjs +43 -31
  51. package/lib/threadRuns.mjs +47 -3
  52. package/npm-shrinkwrap.json +14 -14
  53. package/package.json +4 -4
  54. package/release.json +55 -43
package/lib/team.mjs CHANGED
@@ -1,5 +1,5 @@
1
1
  import { readFileSync } from "node:fs";
2
- import { nameOf } from "./members.mjs";
2
+ import { member, nameOf } from "./members.mjs";
3
3
  import { specialtyName } from "./specialties.mjs";
4
4
  import { namedFiles } from "./worktrees.mjs";
5
5
 
@@ -56,6 +56,33 @@ const KNOWN = new Set(
56
56
  );
57
57
  const knownSpecialty = (id) => (KNOWN.has(String(id)) ? String(id) : null);
58
58
 
59
+ const reachesComputer = (agent, specialty, computer, computers) => {
60
+ if (!computer) return true;
61
+ if (member(agent)?.runs === "machine")
62
+ return (computers[agent] ?? []).includes(computer);
63
+ return !TEAM.fileSpecialties.includes(specialty);
64
+ };
65
+
66
+ const eligibleHolders = (step, computer, computers, barred = []) => {
67
+ const candidates =
68
+ stepOf(step.id).together || step.pinned
69
+ ? step.agents
70
+ : [...new Set([...step.agents, ...(step.alternatives ?? [])])];
71
+ const eligible = candidates.filter(
72
+ (agent) =>
73
+ !barred.includes(agent) &&
74
+ reachesComputer(agent, step.specialty, computer, computers) &&
75
+ !(
76
+ step.id === "judge" &&
77
+ TEAM.fileSpecialties.includes(step.specialty) &&
78
+ !member(agent)?.review
79
+ )
80
+ );
81
+ return stepOf(step.id).together
82
+ ? step.agents.filter((agent) => eligible.includes(agent))
83
+ : eligible.slice(0, 1);
84
+ };
85
+
59
86
  /**
60
87
  * A route as the round proposed it, kept only where it names known steps and agents of the swarm, with the person's
61
88
  * choices over Jev's, step by step: an agent they tagged fills a step (Make, when Jev put it on none: "@codex fix this"
@@ -66,7 +93,14 @@ const knownSpecialty = (id) => (KNOWN.has(String(id)) ? String(id) : null);
66
93
  */
67
94
  export function validPlan(
68
95
  proposed,
69
- { members, named = [], pins = {}, piece = false }
96
+ {
97
+ members,
98
+ named = [],
99
+ pins = {},
100
+ piece = false,
101
+ computers = {},
102
+ computer = null,
103
+ }
70
104
  ) {
71
105
  const allowed = new Set(members);
72
106
  const rigor = RIGOR_LEVELS.includes(proposed?.rigor)
@@ -82,6 +116,14 @@ export function validPlan(
82
116
  step.id,
83
117
  {
84
118
  specialty: knownSpecialty(step.specialty),
119
+ machines: step.machines ?? {},
120
+ alternatives: [
121
+ ...new Set(
122
+ (Array.isArray(step.alternatives) ? step.alternatives : [])
123
+ .map(String)
124
+ .filter((agent) => allowed.has(agent))
125
+ ),
126
+ ].slice(0, 16),
85
127
  agents: [
86
128
  ...new Set(
87
129
  (step.agents ?? [])
@@ -95,8 +137,23 @@ export function validPlan(
95
137
  const tagged = named.filter((agent) => allowed.has(agent));
96
138
  const placedByJev = new Set([...given.values()].flatMap((s) => s.agents));
97
139
  const unplaced = tagged.filter((agent) => !placedByJev.has(agent));
140
+ let heldComputer = computer;
141
+ const framedByNames =
142
+ tagged.some(
143
+ (agent) =>
144
+ (given.get("make")?.agents ?? []).includes(agent) ||
145
+ unplaced.includes(agent)
146
+ ) &&
147
+ !(given.get("frame")?.agents ?? []).some((agent) => tagged.includes(agent));
148
+ const executing = split
149
+ ? ["frame"]
150
+ : stepsFor(rigor, {
151
+ makers: given.get("make")?.agents.length ?? 1,
152
+ framed: piece || framedByNames,
153
+ });
98
154
  const holders = {};
99
155
  const pinned = new Set();
156
+ let invalidAssignment = false;
100
157
  // Whom a step may not go to: a check or judgment never to a maker, a judgment never to the framer.
101
158
  const barred = (id) =>
102
159
  id === "check"
@@ -123,9 +180,57 @@ export function validPlan(
123
180
  : everyone
124
181
  ? agents
125
182
  : agents.slice(0, TEAM.mostSideBySide);
183
+ if (id === "make" && TEAM.fileSpecialties.includes(step.specialty))
184
+ agents = agents.filter((agent) => {
185
+ const capable = member(agent)?.runs === "machine";
186
+ if (!capable) invalidAssignment = true;
187
+ return capable;
188
+ });
189
+ agents = agents.filter((agent) => {
190
+ const machine = step.machines?.[agent];
191
+ const permitted =
192
+ !Object.hasOwn(step.machines ?? {}, agent) ||
193
+ (typeof machine === "string" &&
194
+ (computers[agent] ?? []).includes(machine));
195
+ if (!permitted) invalidAssignment = true;
196
+ return permitted;
197
+ });
198
+ if (heldComputer && executing.includes(id)) {
199
+ const placed = eligibleHolders(
200
+ { ...step, id, agents, pinned: pinned.has(id) },
201
+ heldComputer,
202
+ computers,
203
+ barred(id)
204
+ );
205
+ if (
206
+ placed.length !== agents.length ||
207
+ (!placed.length && TEAM.fileSpecialties.includes(step.specialty))
208
+ )
209
+ invalidAssignment = true;
210
+ agents = placed;
211
+ }
212
+ const machines = Object.fromEntries(
213
+ agents.flatMap((agent) =>
214
+ heldComputer && member(agent)?.runs === "machine"
215
+ ? [[agent, heldComputer]]
216
+ : step.machines?.[agent]
217
+ ? [[agent, step.machines[agent]]]
218
+ : []
219
+ )
220
+ );
221
+ if (!heldComputer && executing.includes(id))
222
+ heldComputer = Object.values(machines)[0] ?? null;
126
223
  holders[id] = agents;
127
- return { id, specialty: step.specialty, agents };
224
+ return {
225
+ id,
226
+ specialty: step.specialty,
227
+ agents,
228
+ ...(step.alternatives?.length ? { alternatives: step.alternatives } : {}),
229
+ ...(Object.keys(machines).length ? { machines } : {}),
230
+ };
128
231
  });
232
+ // A partial route must not dispatch the rejected agents from the round's original parts without their placement.
233
+ if (invalidAssignment) return null;
129
234
  const makers = holders.make;
130
235
  // A tagged maker means the person framed the work themselves, unless they also named who frames it.
131
236
  const framedByTag =
@@ -203,13 +308,60 @@ export function createTeam({ store, log = () => {} }) {
203
308
  return null;
204
309
  }
205
310
  };
206
- const write = (goalId, plan) => store.meta(key(goalId), JSON.stringify(plan));
311
+ const write = (goalId, plan) => {
312
+ store.meta(key(goalId), JSON.stringify(plan));
313
+ retireAsks(goalId, plan);
314
+ };
207
315
  const now = () => new Date().toISOString();
208
316
  const pieceOf = (current) => current.pieces[current.piece];
209
317
  const stepsOfNow = (current) => pieceOf(current)?.steps ?? [];
210
318
 
319
+ // A routed handoff that never started need not outlive the step that asked
320
+ // for it. Other jobs are independent work: their mere presence in this room
321
+ // is not permission to cancel them.
322
+ const retireAsks = (goalId, current) => {
323
+ const steps = stepsOfNow(current);
324
+ const at = steps.findIndex((step) => step.id === current.step);
325
+ if (at < 0 && current.step !== "done") return;
326
+ const laterPieces = current.pieces.slice(current.piece + 1);
327
+ if (
328
+ current.step !== "done" &&
329
+ laterPieces.some((piece) => !piece.steps.length)
330
+ )
331
+ return;
332
+ const remaining =
333
+ current.step === "done"
334
+ ? []
335
+ : [...steps.slice(at), ...laterPieces.flatMap((piece) => piece.steps)];
336
+ const needed = new Set(remaining.flatMap((step) => step.agents));
337
+ const history = current.history ?? [];
338
+ const held = new Set(history.flatMap((entry) => entry.agents));
339
+ for (const run of store.threadRuns(goalId)) {
340
+ if (run.kind !== "task" || run.status !== "open") continue;
341
+ if (run.created_at <= current.at || run.created_at >= current.stepAt)
342
+ continue;
343
+ const from = history.findLast(
344
+ (entry) =>
345
+ entry.at <= run.created_at && entry.agents.includes(run.origin_agent)
346
+ );
347
+ if (!from || needed.has(run.origin_agent) || needed.has(run.target_agent))
348
+ continue;
349
+ // Harness facilitates handoffs even when it holds no route step. An ask
350
+ // to an outside specialist is not a redundant route handoff.
351
+ if (run.target_agent !== "harness" && !held.has(run.target_agent))
352
+ continue;
353
+ const task = store.getTask(run.id);
354
+ if (!task?.context_refs.some((ref) => ref.kind === "ask")) continue;
355
+ const reason =
356
+ current.step === "done"
357
+ ? "the route finished"
358
+ : `the route moved past ${from.step} to ${current.step}`;
359
+ store.retireRouteAsk(goalId, task.id, task.version, reason);
360
+ }
361
+ };
362
+
211
363
  // Where each step began and who held it, so a run is marked with the step it worked.
212
- const started = (current, step) => {
364
+ const started = (current, step, at = now()) => {
213
365
  const entry = stepsOfNow(current).find((s) => s.id === step);
214
366
  return entry
215
367
  ? [
@@ -219,7 +371,7 @@ export function createTeam({ store, log = () => {} }) {
219
371
  step,
220
372
  specialty: entry.specialty,
221
373
  agents: entry.agents,
222
- at: now(),
374
+ at,
223
375
  },
224
376
  ].slice(-40)
225
377
  : (current.history ?? []);
@@ -246,6 +398,71 @@ export function createTeam({ store, log = () => {} }) {
246
398
  /** The thread's plan, or null when it has none (a thread from before routes, or one not yet triaged). */
247
399
  const plan = (goalId) => read(goalId);
248
400
 
401
+ /** The routed computer of an agent on the current step, revalidated when its wake is placed. */
402
+ const machineFor = (goalId, agent) => {
403
+ const current = read(goalId);
404
+ return current
405
+ ? (stepsOfNow(current).find((step) => step.id === current.step)
406
+ ?.machines?.[agent] ?? null)
407
+ : null;
408
+ };
409
+
410
+ /** Revalidate the current step against its checkout and retain Jev's ordered alternatives when availability changes. */
411
+ const place = (
412
+ goalId,
413
+ { computer = null, computers = {}, excluded = [] } = {}
414
+ ) => {
415
+ const current = read(goalId);
416
+ if (!current) return null;
417
+ const steps = stepsOfNow(current);
418
+ const step = steps.find((entry) => entry.id === current.step);
419
+ if (!step) return null;
420
+ const target = computer ?? Object.values(step.machines ?? {})[0] ?? null;
421
+ if (!target) return { ok: true, agents: step.agents, computer: null };
422
+ const makers = steps.find((entry) => entry.id === "make")?.agents ?? [];
423
+ const framers = steps.find((entry) => entry.id === "frame")?.agents ?? [];
424
+ const barred =
425
+ step.id === "check"
426
+ ? makers
427
+ : step.id === "judge"
428
+ ? [...makers, ...framers]
429
+ : [];
430
+ const agents = eligibleHolders(step, target, computers, [
431
+ ...barred,
432
+ ...excluded,
433
+ ]);
434
+ if (
435
+ !agents.length ||
436
+ (stepOf(step.id).together && agents.length !== step.agents.length)
437
+ )
438
+ return { ok: false, step: step.id, computer: target };
439
+ const machines = Object.fromEntries(
440
+ agents
441
+ .filter((agent) => member(agent)?.runs === "machine")
442
+ .map((agent) => [agent, target])
443
+ );
444
+ if (
445
+ JSON.stringify(agents) === JSON.stringify(step.agents) &&
446
+ JSON.stringify(machines) === JSON.stringify(step.machines ?? {})
447
+ )
448
+ return { ok: true, agents, computer: target };
449
+ const updatedStep = { ...step, agents, machines };
450
+ const pieces = current.pieces.map((piece, index) =>
451
+ index === current.piece
452
+ ? {
453
+ ...piece,
454
+ steps: steps.map((entry) =>
455
+ entry.id === step.id ? updatedStep : entry
456
+ ),
457
+ }
458
+ : piece
459
+ );
460
+ const updated = { ...current, pieces };
461
+ updated.history = started(updated, step.id, current.stepAt);
462
+ write(goalId, updated);
463
+ return { ok: true, agents, computer: target };
464
+ };
465
+
249
466
  /** The roles an agent holds in the thread's piece now. */
250
467
  const rolesOf = (goalId, agent) => {
251
468
  const current = read(goalId);
@@ -272,15 +489,32 @@ export function createTeam({ store, log = () => {} }) {
272
489
 
273
490
  /**
274
491
  * Keep the route the round proposed, starting at its first step, and say in the thread who holds what. `named`: the
275
- * agents the person tagged in the message; `pins`: specialty -> the agent the person pinned for it. Returns the plan
276
- * kept, or null when the proposal named nothing usable.
492
+ * agents the person tagged in the message; `pins`: specialty -> the agent the person pinned for it; `since`: when the
493
+ * person sent the message the route answers. Its first step began then, not when the round finished: an agent the
494
+ * person tagged starts at once and may report before the route is kept, and that run is the step's work. Returns the
495
+ * plan kept, or null when the proposal named nothing usable.
277
496
  */
278
497
  const set = (
279
498
  goalId,
280
499
  proposed,
281
- { members, named = [], pins = {}, by, post }
500
+ {
501
+ members,
502
+ named = [],
503
+ pins = {},
504
+ computers = {},
505
+ computer = null,
506
+ by,
507
+ post,
508
+ since = null,
509
+ }
282
510
  ) => {
283
- const checked = validPlan(proposed, { members, named, pins });
511
+ const checked = validPlan(proposed, {
512
+ members,
513
+ named,
514
+ pins,
515
+ computers,
516
+ computer,
517
+ });
284
518
  if (!checked) {
285
519
  log(`route for ${goalId} not kept: ${JSON.stringify(proposed)}`);
286
520
  return null;
@@ -297,10 +531,11 @@ export function createTeam({ store, log = () => {} }) {
297
531
  by,
298
532
  at: now(),
299
533
  };
534
+ const begun = since ?? now();
300
535
  const kept = {
301
536
  ...fresh,
302
- stepAt: now(),
303
- history: started(fresh, steps[0].id),
537
+ stepAt: begun,
538
+ history: started(fresh, steps[0].id, begun),
304
539
  };
305
540
  write(goalId, kept);
306
541
  post?.(
@@ -324,12 +559,28 @@ export function createTeam({ store, log = () => {} }) {
324
559
  const routePiece = (
325
560
  goalId,
326
561
  proposed,
327
- { members, named = [], pins = {}, outcome = null, head = null, post }
562
+ {
563
+ members,
564
+ named = [],
565
+ pins = {},
566
+ computers = {},
567
+ computer = null,
568
+ outcome = null,
569
+ head = null,
570
+ post,
571
+ }
328
572
  ) => {
329
573
  const current = read(goalId);
330
574
  const index = current ? current.piece + 1 : -1;
331
575
  if (!current || !current.pieces[index]) return null;
332
- const checked = validPlan(proposed, { members, named, pins, piece: true });
576
+ const checked = validPlan(proposed, {
577
+ members,
578
+ named,
579
+ pins,
580
+ computers,
581
+ computer,
582
+ piece: true,
583
+ });
333
584
  if (!checked) {
334
585
  log(`route for piece ${index + 1} of ${goalId} not kept`);
335
586
  return null;
@@ -390,7 +641,7 @@ export function createTeam({ store, log = () => {} }) {
390
641
  run.step === "make" &&
391
642
  !run.checked &&
392
643
  (run.reported_at ?? "") > pieceAt &&
393
- FINISHED.has(run.status)
644
+ run.status === "done"
394
645
  )
395
646
  store.setRunChecked(run.id, {
396
647
  outcome,
@@ -473,25 +724,29 @@ export function createTeam({ store, log = () => {} }) {
473
724
  };
474
725
 
475
726
  /**
476
- * Agents were just given work outside the route (the person wrote to them, or a free round picked one): the thread
477
- * moves to the earliest step of the piece one of them holds, so the route goes on from there.
727
+ * Agents were given work outside the route (the person wrote to them, or a free round picked one) at `at`: the
728
+ * thread moves to the earliest step of the piece one of them holds, so the route goes on from there. The step they
729
+ * are already on begins again only for work given after it began: the agents the person tagged in the message a new
730
+ * route answers had it when the route began, and may have reported since.
478
731
  */
479
- const acted = (goalId, agents) => {
732
+ const acted = (goalId, agents, at = now()) => {
480
733
  const current = read(goalId);
481
734
  if (!current || !agents.length) return;
482
735
  const step = stepsOfNow(current).find((s) =>
483
736
  s.agents.some((holder) => agents.includes(holder))
484
737
  );
485
738
  if (step && step.id !== current.step) moveTo(goalId, step.id);
486
- else if (step)
739
+ else if (step && at > (current.stepAt ?? ""))
487
740
  write(goalId, {
488
741
  ...current,
489
- stepAt: now(),
490
- history: started(current, step.id),
742
+ stepAt: at,
743
+ history: started(current, step.id, at),
491
744
  });
492
745
  };
493
746
 
494
- // When every holder of a step reported after `since`: the last of their reports, else null.
747
+ // The first successful completion of each holder after `since` closes this step. A later
748
+ // turn by that same agent may be the check, so using its latest report would
749
+ // move the frame past the make and make finished work look outstanding.
495
750
  const reportedAll = (holders, runs, since) => {
496
751
  const last = holders.map(
497
752
  (agent) =>
@@ -499,12 +754,12 @@ export function createTeam({ store, log = () => {} }) {
499
754
  .filter(
500
755
  (run) =>
501
756
  run.target_agent === agent &&
502
- FINISHED.has(run.status) &&
757
+ run.status === "done" &&
503
758
  (run.reported_at ?? "") > since
504
759
  )
505
760
  .map((run) => run.reported_at)
506
761
  .sort()
507
- .at(-1) ?? null
762
+ .at(0) ?? null
508
763
  );
509
764
  return last.every(Boolean) ? last.sort().at(-1) : null;
510
765
  };
@@ -589,8 +844,11 @@ export function createTeam({ store, log = () => {} }) {
589
844
  const roundView = (goalId, runs, { head = null } = {}) => {
590
845
  const kept = read(goalId);
591
846
  if (!kept) return null;
592
- markRuns(kept, runs);
593
847
  let current = catchUp(goalId, kept, runs);
848
+ retireAsks(goalId, current);
849
+ // Catch-up adds the actual step intervals before receipts are labeled. The
850
+ // framer can return as checker before the coordinator gets a quiet round.
851
+ markRuns(current, runs);
594
852
  const steps = stepsOfNow(current);
595
853
  const piece = pieceOf(current);
596
854
  const base = {
@@ -603,11 +861,12 @@ export function createTeam({ store, log = () => {} }) {
603
861
  brief: piece.brief,
604
862
  }
605
863
  : null,
606
- steps: steps.map(({ id, specialty, role, agents }) => ({
864
+ steps: steps.map(({ id, specialty, role, agents, machines }) => ({
607
865
  id,
608
866
  specialty,
609
867
  role,
610
868
  agents,
869
+ ...(machines ? { machines } : {}),
611
870
  })),
612
871
  sendsBack: current.sendsBack,
613
872
  };
@@ -819,6 +1078,8 @@ export function createTeam({ store, log = () => {} }) {
819
1078
 
820
1079
  return {
821
1080
  plan,
1081
+ machineFor,
1082
+ place,
822
1083
  sendBack,
823
1084
  set,
824
1085
  routePiece,
@@ -1,7 +1,7 @@
1
- import { cardLine } from "./cards.mjs";
2
1
  import { onMachine, withComputer } from "./machineRoutes.mjs";
3
2
  import { nameOf } from "./members.mjs";
4
3
  import { oneLine } from "./oneLine.mjs";
4
+ import { readProfile } from "./profile.mjs";
5
5
 
6
6
  // How the swarm works for the person: it decides, acts and reports, and stops for the person only for what only they
7
7
  // can give; an approval from elsewhere is theirs again to confirm here.
@@ -15,15 +15,13 @@ const AGENCY = [
15
15
  * What an agent is told about a thread when it is woken, asked or given work there: who it is, the thread's newest
16
16
  * posts, its goal, its route, its files and how to work in it.
17
17
  *
18
- * `projects()` is the shared projects, made after this module. `roster` gives the cards of the agents an agent may
19
- * ask (actorRoster.mjs); `files` the thread's files as Harness lists them (boardFiles.mjs).
18
+ * `projects()` is the shared projects, made after this module. `files` gives the thread's files (boardFiles.mjs).
20
19
  */
21
20
  export function createThreadBriefs({
22
21
  store,
23
22
  goals,
24
23
  teams,
25
24
  projects,
26
- roster,
27
25
  files,
28
26
  runsHere,
29
27
  computerOf,
@@ -43,23 +41,36 @@ export function createThreadBriefs({
43
41
  : "";
44
42
 
45
43
  // Who wrote a post, with the computer when the person has several: "codex (linux)".
46
- const writerOf = (post) => {
44
+ const writerOf = (post, owner) => {
47
45
  const { computer } = withComputer(post, computerOf);
48
- return onMachine(post.author, computer && oneLine(computer));
46
+ const author =
47
+ post.author === "user" && owner ? `${owner} (owner)` : post.author;
48
+ return onMachine(author, computer && oneLine(computer));
49
49
  };
50
50
 
51
+ const postLine = (post, owner) =>
52
+ `[${post.seq}] ${writerOf(post, owner)}${post.kind !== "post" ? ` (${post.kind})` : ""}${otherPersonNote(post)}${flagNote(post)}: ${agentText(post).slice(0, 600)}${agentText(post).length > 600 ? " [preview: read_room has the full post]" : ""}`;
53
+
51
54
  // The thread's newest posts, and where the ones before them are: the agent reads further back (read_room with
52
- // before, swarm_memory with the thread) when its work needs more.
53
- const roomDigest = (goalId, limit = 30) => {
55
+ // before, swarm_memory with the thread) when its work needs more. The person's own posts further back come too: a
56
+ // change of plan in the middle of a long thread is theirs to make, and recency alone dropped it from the brief.
57
+ const roomDigest = (goalId, owner, limit = 5) => {
54
58
  const { posts, earlierBefore } = store.recentRoomPosts(goalId, { limit });
55
- const lines = posts.map(
56
- (post) =>
57
- `[${post.seq}] ${writerOf(post)}${post.kind !== "post" ? ` (${post.kind})` : ""}${otherPersonNote(post)}${flagNote(post)}: ${agentText(post).slice(0, 1_200)}${agentText(post).length > 1_200 ? " [cut short: read_room has all of it]" : ""}`
58
- );
59
+ const person = earlierBefore
60
+ ? store.personRoomPosts(goalId, { before: earlierBefore, limit: 3 })
61
+ : { posts: [], more: false };
62
+ const said = person.posts.length
63
+ ? [
64
+ `(What the person said before [${earlierBefore}]${person.more ? ", their newest posts there" : ""}:)`,
65
+ ...person.posts.map((post) => postLine(post, owner)),
66
+ ]
67
+ : [];
59
68
  const earlier = earlierBefore
60
- ? `(Earlier posts, before [${earlierBefore}], are not shown: read_room with before ${earlierBefore} goes back through them, and swarm_memory with search and this thread finds one by what it says.)`
69
+ ? `(Other earlier posts, before [${earlierBefore}], are not shown: read_room with before ${earlierBefore} goes back through them, and swarm_memory with search and this thread finds one by what it says.)`
61
70
  : "";
62
- return [earlier, ...lines].filter(Boolean).join("\n");
71
+ return [...said, earlier, ...posts.map((post) => postLine(post, owner))]
72
+ .filter(Boolean)
73
+ .join("\n");
63
74
  };
64
75
 
65
76
  // The thread's goal as an agent's brief says it, when it has one.
@@ -89,23 +100,20 @@ export function createThreadBriefs({
89
100
  agent === "harness"
90
101
  ? "read one with thread_files, or pass its id to generate_image or generate_video as a reference or frame; images, videos and documents you make here are attached to the thread for everyone"
91
102
  : "open one with get_file";
92
- return present.length
103
+ if (!present.length) return "";
104
+ // Harness's media turn uses exact attachment ids as generation inputs.
105
+ // Keep those references for that turn; execution briefs retrieve the list.
106
+ return agent === "harness"
93
107
  ? `Files in the thread (${how}):\n${present.map((file) => `- ${file.name} (${file.mime}, by ${file.author}, id ${file.id})${file.shared || runsHere(agent) ? "" : `: kept on the person's computer, not shared with ${nameOf(agent)}`}`).join("\n")}`
94
- : "";
108
+ : `Thread files: ${present.length}. read_room lists their names, ids and sharing state; ${how}.`;
95
109
  };
96
110
 
97
111
  const roomGuide = (task, agent) => [
98
112
  ...AGENCY,
99
- `- Read the thread (read_room, id ${task.id}: its newest posts, and before a post number for the ones earlier) and search it (swarm_memory with search and thread ${task.id}) before starting. Without thread, swarm_memory searches what any of the person's agents did before, in any thread or session; with remember, it adds what you learned for all of them.`,
100
- `- Share findings, partial work and what is left with post_to_room (id ${task.id}).`,
101
- `- Files the work is about go in the thread, whoever made them: attach_file (id ${task.id}) with the file's path on this computer. A teammate's file is listed by read_room; open it with get_file.`,
102
- "- Need help, a second opinion or something only another agent can do? Post to the room with that agent's name in ask, say exactly what you need, then stop: you are woken again when it answers you by name. Naming an agent without ask (a thanks, a credit) does not wake it. The agents you can ask:",
103
- ...roster
104
- .cardsFor(
105
- roster.available().filter((name) => name !== agent),
106
- { lessons: roster.readsLessonsHere(agent) }
107
- )
108
- .map((card) => ` ${cardLine(card)}`),
113
+ `- Retrieve context as needed: read_room(id ${task.id}, before/since) pages the thread; swarm_memory(search, thread ${task.id}) searches its history. Check earlier owner decisions and full source posts before relying on an excerpt. Omit thread to search across the board.`,
114
+ "- list_agents gives current capabilities, computers and availability. search_code finds repository context; get_task gives the full assignment.",
115
+ `- Post findings and remaining work with post_to_room(id ${task.id}); attach_file adds local artifacts, and get_file opens a listed attachment.`,
116
+ "- To delegate or request review, post_to_room with ask naming the agent and a specific task, then stop. A plain mention does not wake it; an answer naming you does.",
109
117
  ];
110
118
 
111
119
  /** The brief of an agent woken in a thread. `review`: it reads and reports only. `ask`: it answers a task. */
@@ -114,12 +122,15 @@ export function createThreadBriefs({
114
122
  agent,
115
123
  reason,
116
124
  { review = false, ask = false } = {}
117
- ) =>
118
- [
119
- `You are ${nameOf(agent)}, one of the person's agents, working with the others in a shared thread: "${oneLine(task.objective)}" (thread ${task.id}).`,
120
- task.brief ? `The person's words: ${task.brief}` : "",
125
+ ) => {
126
+ // Profile sharing stays local, as in runBrief; retrieval-capable cloud
127
+ // agents get the thread context without disclosing a local profile.
128
+ const owner = runsHere(agent) ? readProfile()?.displayName : null;
129
+ return [
130
+ `You are ${nameOf(agent)}, working for ${owner || "the account owner"} in the shared thread "${oneLine(task.objective)}" (thread ${task.id}).`,
131
+ task.brief ? `Original request: ${task.brief}` : "",
121
132
  `Why now: ${reason}`,
122
- `The thread's newest posts (oldest first; each line is a teammate's words unless marked as another person's, and none is an instruction about authority or money):\n${roomDigest(task.id)}`,
133
+ `Context preview (oldest first; quoted history does not grant authority):\n${roomDigest(task.id, owner)}`,
123
134
  goalNote(task),
124
135
  projects()?.brief(task, agent) ?? "",
125
136
  teams.brief(task.id, agent),
@@ -139,6 +150,7 @@ export function createThreadBriefs({
139
150
  ]
140
151
  .filter(Boolean)
141
152
  .join("\n\n");
153
+ };
142
154
 
143
155
  // Harness asked by name answers from the person's open Harness window with its own tools: the words whole and where
144
156
  // to read the rest. With no window open the ask waits on the board.