tryharness 0.7.45 → 0.7.53

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 (99) hide show
  1. package/README.md +232 -12
  2. package/cli.mjs +406 -184
  3. package/lib/actorRoster.mjs +28 -5
  4. package/lib/adapters.mjs +9 -1
  5. package/lib/agentRuntimeConfig.mjs +36 -0
  6. package/lib/agentRuntimes.mjs +560 -0
  7. package/lib/atlas.mjs +7 -2
  8. package/lib/boardCommands.mjs +5 -10
  9. package/lib/boardFileCommands.mjs +2 -1
  10. package/lib/boardMirror.mjs +459 -0
  11. package/lib/boardProtocol.json +206 -6
  12. package/lib/boardTools.mjs +2 -6
  13. package/lib/bridge.mjs +25 -3
  14. package/lib/browserWake.mjs +60 -0
  15. package/lib/cards.mjs +35 -2
  16. package/lib/commands.mjs +20 -5
  17. package/lib/connectionTools.d.ts +13 -0
  18. package/lib/connectionTools.js +45 -0
  19. package/lib/connectorAuth.mjs +309 -0
  20. package/lib/connectorCatalog.json +41 -0
  21. package/lib/connectorCommands.mjs +121 -0
  22. package/lib/connectorGoogle.mjs +513 -0
  23. package/lib/connectors.mjs +805 -0
  24. package/lib/coordinator.mjs +8 -1
  25. package/lib/coreModels.mjs +78 -0
  26. package/lib/daemon.mjs +643 -45
  27. package/lib/desktop.mjs +7 -2
  28. package/lib/digest.mjs +32 -0
  29. package/lib/directLink.mjs +283 -0
  30. package/lib/environments.mjs +595 -0
  31. package/lib/folders.mjs +2 -2
  32. package/lib/goalCommands.mjs +58 -14
  33. package/lib/inference.mjs +263 -152
  34. package/lib/lessons.mjs +6 -0
  35. package/lib/lineup.mjs +324 -0
  36. package/lib/localmodels.mjs +10 -0
  37. package/lib/machineIdentity.mjs +3 -0
  38. package/lib/machineRoutes.mjs +40 -2
  39. package/lib/machineRuns.mjs +30 -3
  40. package/lib/machineSeal.mjs +69 -10
  41. package/lib/mcp-stdio.mjs +121 -118
  42. package/lib/mcpRelay.mjs +119 -0
  43. package/lib/members.json +12 -0
  44. package/lib/members.mjs +33 -0
  45. package/lib/modelMemory.mjs +100 -0
  46. package/lib/modelTiers.json +1183 -0
  47. package/lib/modelTiers.mjs +133 -0
  48. package/lib/models.mjs +41 -8
  49. package/lib/museSession.mjs +119 -0
  50. package/lib/nativeHost.mjs +203 -0
  51. package/lib/network.mjs +7 -2
  52. package/lib/nudge.mjs +10 -2
  53. package/lib/onboard.mjs +430 -1
  54. package/lib/oneclawLocal.mjs +150 -0
  55. package/lib/ownMachines.mjs +521 -36
  56. package/lib/pairing.mjs +165 -0
  57. package/lib/paths.mjs +4 -0
  58. package/lib/phones.mjs +61 -0
  59. package/lib/placeCommands.mjs +27 -0
  60. package/lib/places.mjs +10 -2
  61. package/lib/plans.mjs +151 -27
  62. package/lib/profile.mjs +152 -0
  63. package/lib/projects.mjs +624 -137
  64. package/lib/readiness.mjs +283 -0
  65. package/lib/repoLinks.mjs +354 -0
  66. package/lib/roomChannels.mjs +641 -0
  67. package/lib/runBrief.mjs +32 -2
  68. package/lib/runRequests.mjs +157 -0
  69. package/lib/runWorker.mjs +20 -7
  70. package/lib/runner.mjs +67 -8
  71. package/lib/secretPatterns.json +55 -0
  72. package/lib/secrets.mjs +10 -27
  73. package/lib/seen.mjs +102 -0
  74. package/lib/service.mjs +11 -6
  75. package/lib/sessionControl.mjs +10 -8
  76. package/lib/sessionIndex.mjs +5 -3
  77. package/lib/store.mjs +546 -29
  78. package/lib/subagents.mjs +8 -4
  79. package/lib/swarm.mjs +367 -37
  80. package/lib/swarmMemory.mjs +947 -0
  81. package/lib/t3.mjs +43 -13
  82. package/lib/taskCommands.mjs +56 -5
  83. package/lib/taskRuns.mjs +61 -11
  84. package/lib/team.json +17 -15
  85. package/lib/team.mjs +68 -18
  86. package/lib/threadRuns.mjs +3 -1
  87. package/lib/threadView.mjs +51 -14
  88. package/lib/tokenizer.mjs +405 -0
  89. package/lib/ui.mjs +16 -2
  90. package/lib/usageTotals.mjs +148 -0
  91. package/lib/vault.mjs +1144 -0
  92. package/lib/vaultCloud.mjs +117 -0
  93. package/lib/vaultCommands.mjs +201 -0
  94. package/lib/vaultTools.d.ts +12 -0
  95. package/lib/vaultTools.js +42 -0
  96. package/lib/windowAsks.mjs +42 -0
  97. package/lib/workFocus.mjs +59 -0
  98. package/lib/workLinks.mjs +90 -0
  99. package/package.json +9 -4
package/lib/t3.mjs CHANGED
@@ -63,6 +63,10 @@ export async function findT3(home = t3Home(), hint = null) {
63
63
  return null;
64
64
  }
65
65
 
66
+ /** Whether T3 Code has run on this computer: it writes its environment id the first time it starts. */
67
+ export const t3Installed = (home = t3Home()) =>
68
+ fs.existsSync(path.join(home, "environment-id"));
69
+
66
70
  /** What Harness may do in T3 Code: "send", "read", "expired", or null before the person approves it. */
67
71
  export function t3Access() {
68
72
  const saved = readJson(file(), null);
@@ -76,6 +80,8 @@ export function t3Access() {
76
80
  ? "send"
77
81
  : "read",
78
82
  until: saved.expiresAt,
83
+ environmentId: saved.environmentId,
84
+ grantedAt: saved.approvedAt,
79
85
  };
80
86
  }
81
87
 
@@ -330,7 +336,14 @@ async function callTool(origin, token, name, args) {
330
336
  }
331
337
 
332
338
  /** One of T3's tools, as Harness was approved to use them, at T3's current address. */
333
- async function t3Tool(name, args) {
339
+ const READ_TOOLS = new Set([
340
+ "orchestrator_capabilities",
341
+ "t3_project_list",
342
+ "t3_thread_list",
343
+ "t3_thread_read",
344
+ ]);
345
+
346
+ export async function t3Tool(name, args) {
334
347
  const saved = readJson(file(), null);
335
348
  const access = t3Access();
336
349
  if (!access)
@@ -340,7 +353,7 @@ async function t3Tool(name, args) {
340
353
  );
341
354
  if (access.state === "expired")
342
355
  throw new T3Error("expired", "Harness's approval in T3 Code ran out.");
343
- if (access.state !== "send")
356
+ if (access.state !== "send" && !READ_TOOLS.has(name))
344
357
  throw new T3Error(
345
358
  "read_only",
346
359
  "Harness was approved in T3 Code to read only."
@@ -429,6 +442,9 @@ function stepOf(item) {
429
442
 
430
443
  // The option T3 gives each agent's effort under, by agent.
431
444
  const EFFORT_OPTIONS = new Set(["reasoningEffort", "effort"]);
445
+ // An option's choices: `values` since T3 #22889 (October 21), `options: [{ id }]` before.
446
+ const choicesOf = (option) =>
447
+ option.values ?? option.options?.map((level) => level.id) ?? [];
432
448
  const versionOf = (id) => (id.match(/\d+/g) ?? []).map(Number);
433
449
  const newerFirst = (a, b) => {
434
450
  const [left, right] = [versionOf(a.id), versionOf(b.id)];
@@ -437,6 +453,15 @@ const newerFirst = (a, b) => {
437
453
  return (right[i] ?? -1) - (left[i] ?? -1);
438
454
  return 0;
439
455
  };
456
+ const matching = (provider, model) => {
457
+ const offered = provider?.models ?? [];
458
+ return (
459
+ offered.find((entry) => entry.id === model) ??
460
+ offered
461
+ .filter((entry) => entry.id.startsWith(`claude-${model}-`))
462
+ .sort(newerFirst)[0]
463
+ );
464
+ };
440
465
 
441
466
  /**
442
467
  * The selection T3 Code runs an agent's turn with: the model and effort the buddy shows for it (the person's pick, else
@@ -444,26 +469,31 @@ const newerFirst = (a, b) => {
444
469
  * a short name (opus), which is the newest of that family T3 offers. Null when nothing names a model. A model or effort
445
470
  * T3 does not offer fails the turn rather than letting T3 run it on another (October 17: Codex ran on gpt-6-astra
446
471
  * for days while the buddy showed gpt-6.1-sol).
472
+ *
473
+ * Since T3 #22889 (October 21) T3 lists a short list of each agent's models and says how many it left out; a model not
474
+ * on it is looked up with T3's search. An older T3 lists every model and leaves out none, so it is never searched.
447
475
  */
448
476
  async function selectionFor({ instanceId, model, effort } = {}) {
449
477
  if (!model) return null;
450
- const { providers = [] } = await t3Tool("orchestrator_capabilities", {});
451
- const offered =
452
- providers.find((entry) => entry.providerInstanceId === instanceId)
453
- ?.models ?? [];
454
- const found =
455
- offered.find((entry) => entry.id === model) ??
456
- offered
457
- .filter((entry) => entry.id.startsWith(`claude-${model}-`))
458
- .sort(newerFirst)[0];
478
+ const offering = async (args) =>
479
+ (await t3Tool("orchestrator_capabilities", args)).providers?.find(
480
+ (entry) => entry.providerInstanceId === instanceId
481
+ );
482
+ const listed = await offering({});
483
+ const searched =
484
+ !matching(listed, model) && listed?.omittedModels
485
+ ? await offering({ search: model })
486
+ : null;
487
+ const provider = searched ?? listed;
488
+ const found = matching(provider, model);
459
489
  if (!found)
460
490
  throw new T3Error(
461
491
  "model",
462
- `T3 Code does not offer ${model} for this agent (it offers ${offered.map((entry) => entry.id).join(", ") || "none"}).`
492
+ `T3 Code does not offer ${model} for this agent (it offers ${(provider?.models ?? []).map((entry) => entry.id).join(", ") || "none"}).`
463
493
  );
464
494
  if (!effort) return { instanceId, model: found.id, options: [] };
465
495
  const option = found.options?.find((entry) => EFFORT_OPTIONS.has(entry.id));
466
- if (!option?.options?.some((level) => level.id === effort))
496
+ if (!option || !choicesOf(option).includes(effort))
467
497
  throw new T3Error(
468
498
  "model",
469
499
  `T3 Code does not offer effort ${effort} for ${found.id}.`
@@ -18,6 +18,7 @@ import {
18
18
  swarmBlock,
19
19
  swarmDigest,
20
20
  toldBlock,
21
+ youLine,
21
22
  } from "./cards.mjs";
22
23
  import { PICKABLE, resolvePick, setRunPick } from "./models.mjs";
23
24
  import { onMachine, placeTask } from "./machineRoutes.mjs";
@@ -117,6 +118,7 @@ export function createTaskCommands({
117
118
  hosted: Boolean(request.hostedCaller),
118
119
  into: opts.into,
119
120
  folder: opts.folder,
121
+ machine: opts.machine,
120
122
  }
121
123
  );
122
124
  const opened = room.id !== opts.into;
@@ -281,6 +283,7 @@ export function createTaskCommands({
281
283
  kind: "job",
282
284
  text: `Posted a job${request.targetAgent ? ` for ${request.targetAgent}` : ""}: ${objective}`,
283
285
  mentions: request.targetAgent ? [String(request.targetAgent)] : [],
286
+ machine,
284
287
  });
285
288
  }
286
289
  // The folder a coding agent posts from (its stdio MCP's, which each agent starts in the session's folder); never
@@ -309,6 +312,7 @@ export function createTaskCommands({
309
312
  objective,
310
313
  into: workingThread,
311
314
  folder: askerFolder,
315
+ machine,
312
316
  });
313
317
  }
314
318
  // Which of the person's computers the work is for: the one named, else the poster's own when it works there in a
@@ -554,6 +558,7 @@ export function createTaskCommands({
554
558
  hosted: Boolean(request.hostedCaller),
555
559
  into: workingThread,
556
560
  folder: askerFolder,
561
+ machine,
557
562
  });
558
563
  const note = task.target_agent
559
564
  ? actors.setupNote(task.target_agent)
@@ -588,13 +593,15 @@ export function createTaskCommands({
588
593
  { lessons: local }
589
594
  );
590
595
  const told = local ? lessons.told() : [];
591
- // Its parts too, so a session start short of room can send the cards in short form (nudge.mjs).
596
+ // Its parts too, so a session start short of room can send the cards in short form (nudge.mjs). `you`: who the
597
+ // caller is and the computer it runs on, the computer its call came from.
592
598
  extra.swarm = {
593
599
  text: swarmBlock(cards, Date.now(), told),
594
600
  digest: swarmDigest(cards, told),
595
601
  cards: cards.map((card) => cardLine(card)),
596
602
  short: cards.map(shortCardLine),
597
603
  told: toldBlock(told),
604
+ you: local ? youLine(agent, machines.whereIs(machine)) : "",
598
605
  };
599
606
  }
600
607
  // The goal rooms an agent is on, for list_tasks and a session start: a start short of room points here for them.
@@ -610,7 +617,7 @@ export function createTaskCommands({
610
617
  ok: true,
611
618
  tasks,
612
619
  ...extra,
613
- unread: store.unreadFor(agent),
620
+ unread: store.unreadFor(agent, machine),
614
621
  goals: rooms(),
615
622
  }
616
623
  : { ok: true, tasks, ...extra };
@@ -628,6 +635,7 @@ export function createTaskCommands({
628
635
  author: agent,
629
636
  text: String(request.text || "").slice(0, 20000),
630
637
  source: request.source ? String(request.source).slice(0, 1024) : null,
638
+ machine,
631
639
  });
632
640
  return entry
633
641
  ? { ok: true, entry, context: store.contextCount(id) }
@@ -802,6 +810,17 @@ export function createTaskCommands({
802
810
  error:
803
811
  "a task given to Harness is taken by an up-to-date Harness window by itself, as its own message; leave it open",
804
812
  };
813
+ // The extension's hidden Harness page takes only what the person let it finish in their browser (swarm.mjs
814
+ // board.swarm.use_browser): the message that woke it is no permission.
815
+ else if (
816
+ request.command === "board.claim" &&
817
+ request.browser === true &&
818
+ !store.meta(`harness-browser-allowed:${id}`)
819
+ )
820
+ return {
821
+ ok: false,
822
+ error: "the person has not let Harness use their browser for this",
823
+ };
805
824
  else if (request.command === "board.claim") {
806
825
  outcome = store.claimTask(
807
826
  id,
@@ -860,9 +879,32 @@ export function createTaskCommands({
860
879
  id,
861
880
  agent,
862
881
  String(request.answer || "").slice(0, 20000),
863
- expected
882
+ expected,
883
+ machine
864
884
  );
865
- else if (request.command === "board.release")
885
+ // The hidden Harness page stopped at a question for the person, who may be away: the task waits for them at
886
+ // their computer, saying what it would ask, and is not offered to the browser again until they open Harness. Given
887
+ // back for Harness as this daemon gives back what Harness's server left for the browser (daemon.mjs).
888
+ else if (
889
+ request.command === "board.release" &&
890
+ agent === "harness" &&
891
+ request.browser === true
892
+ ) {
893
+ const task = store.getTask(id);
894
+ if (task?.claimed_by !== "harness" || !store.meta(`harness-window:${id}`))
895
+ return {
896
+ ok: false,
897
+ error: "that is not Harness's work in your browser",
898
+ };
899
+ outcome = store.releaseTask(id, "user", expected);
900
+ if (outcome?.ok) {
901
+ store.meta(`harness-browser-allowed:${id}`, "");
902
+ store.meta(
903
+ `harness-browser-stopped:${id}`,
904
+ String(request.why || "a question for you").slice(0, 300)
905
+ );
906
+ }
907
+ } else if (request.command === "board.release")
866
908
  outcome = store.releaseTask(id, agent, expected);
867
909
  else if (request.command === "board.remove") {
868
910
  if (agent !== "user")
@@ -961,8 +1003,17 @@ export function createTaskCommands({
961
1003
  store.meta(`machine-step:${id}`, new Date().toISOString());
962
1004
  return { ok: true };
963
1005
  } else if (request.command === "board.machine.finish") {
964
- if (request.usage && store.getTask(id)?.claimed_machine === machine)
1006
+ const ran = store.getTask(id);
1007
+ if (request.usage && ran?.claimed_machine === machine)
965
1008
  store.setRunUsage(id, request.usage);
1009
+ // The run's session, when its own call did not reach home before the finish (machineRuns.mjs).
1010
+ if (
1011
+ typeof request.session === "string" &&
1012
+ ran?.claimed_machine === machine &&
1013
+ ran.holder === agent &&
1014
+ !ran.session_id
1015
+ )
1016
+ store.setRunSession(id, request.session.slice(0, 256));
966
1017
  outcome = store.reportTask(
967
1018
  id,
968
1019
  agent,
package/lib/taskRuns.mjs CHANGED
@@ -1,3 +1,4 @@
1
+ import { scrubValues } from "./vault.mjs";
1
2
  import fs from "node:fs";
2
3
  import path from "node:path";
3
4
  import { ensureDir, readJson, writeJsonAtomic } from "./files.mjs";
@@ -8,7 +9,36 @@ import { runInT3 } from "./t3.mjs";
8
9
 
9
10
  const TASK_LOG_PAGE = 64_000;
10
11
 
11
- export function createTaskRuns({ t3Missed }) {
12
+ /**
13
+ * What a run with secrets in its environment says, with their values replaced by markers (vault.mjs). An agent's
14
+ * output arrives in pieces, so each stream holds back the end of what it has seen that could begin a value; it is
15
+ * written once the rest arrives, or when the run ends.
16
+ */
17
+ function streamScrubber(values) {
18
+ if (!(values instanceof Map) || values.size === 0)
19
+ return { text: (text) => text, stream: (_, raw) => raw, flush: () => [] };
20
+ const longest = Math.max(
21
+ ...[...values.values()].map((value) => encodeURIComponent(value).length)
22
+ );
23
+ const held = new Map();
24
+ return {
25
+ text: (text) =>
26
+ typeof text === "string" ? scrubValues(text, values) : text,
27
+ stream: (stream, raw) => {
28
+ const clean = scrubValues((held.get(stream) ?? "") + raw, values);
29
+ const keep = Math.min(clean.length, longest - 1);
30
+ held.set(stream, clean.slice(clean.length - keep));
31
+ return clean.slice(0, clean.length - keep);
32
+ },
33
+ flush: () => {
34
+ const rest = [...held].filter(([, text]) => text);
35
+ held.clear();
36
+ return rest;
37
+ },
38
+ };
39
+ }
40
+
41
+ export function createTaskRuns({ t3Missed, nativeRequests = null }) {
12
42
  const taskRuns = new Map();
13
43
  const validRunId = (runId) =>
14
44
  typeof runId === "string" && /^[a-zA-Z0-9._-]{1,128}$/.test(runId);
@@ -128,13 +158,27 @@ export function createTaskRuns({ t3Missed }) {
128
158
  };
129
159
  taskRuns.set(message.runId, task);
130
160
  persistTask(task);
131
- const emit = (kind, text, extra) => {
161
+ const scrub = streamScrubber(message.scrub);
162
+ const appendLog = (stream, text) => {
163
+ try {
164
+ fs.appendFileSync(
165
+ files.log,
166
+ stream === "stderr" ? `\n[stderr] ${text}` : text,
167
+ { mode: 0o600 }
168
+ );
169
+ } catch {}
170
+ };
171
+ const emit = (kind, rawText, extra) => {
172
+ const text = scrub.text(rawText);
173
+ if (kind === "done" || kind === "failed")
174
+ for (const [stream, rest] of scrub.flush()) appendLog(stream, rest);
132
175
  if (kind === "accepted") task.status = "running";
133
176
  if (kind === "session") {
134
177
  task.sessionId = text || null;
135
178
  if (extra?.cwd) task.cwd = extra.cwd;
136
179
  }
137
180
  if (kind === "done" || kind === "failed") {
181
+ nativeRequests?.finish(message.runId);
138
182
  task.status = kind;
139
183
  task.finishedAt = new Date().toISOString();
140
184
  task.message = text || null;
@@ -146,14 +190,20 @@ export function createTaskRuns({ t3Missed }) {
146
190
  report(kind, text, extra);
147
191
  };
148
192
  const observe = (stream, raw) => {
149
- try {
150
- fs.appendFileSync(
151
- files.log,
152
- stream === "stderr" ? `\n[stderr] ${raw}` : raw,
153
- { mode: 0o600 }
154
- );
155
- } catch {}
193
+ const text = scrub.stream(stream, raw);
194
+ if (text) appendLog(stream, text);
156
195
  };
196
+ const hooks = nativeRequests
197
+ ? {
198
+ requestApproval: (approval, signal) =>
199
+ nativeRequests.request({
200
+ runId: message.runId,
201
+ agent: message.agent,
202
+ approval,
203
+ signal,
204
+ }),
205
+ }
206
+ : {};
157
207
  if (message.t3)
158
208
  runInT3(
159
209
  {
@@ -176,13 +226,13 @@ export function createTaskRuns({ t3Missed }) {
176
226
  `[${why} This turn runs on this computer instead, in ${checkout}.]\n`
177
227
  );
178
228
  t3Missed(message.runId, why);
179
- runAgentTask({ ...message, cwd: checkout }, emit, observe);
229
+ runAgentTask({ ...message, cwd: checkout }, emit, observe, hooks);
180
230
  },
181
231
  },
182
232
  emit,
183
233
  observe
184
234
  );
185
- else runAgentTask(message, emit, observe);
235
+ else runAgentTask(message, emit, observe, hooks);
186
236
  };
187
237
  const requeue = (id, reason) => {
188
238
  const record = taskRuns.get(id);
package/lib/team.json CHANGED
@@ -16,49 +16,57 @@
16
16
  "name": "builder",
17
17
  "owns": "Doing the piece of work: the change, the fix, the draft or the answer, whole rather than in small chunks.",
18
18
  "never": "Calls its own work checked, or reviews its own change.",
19
- "bringsBack": "What changed and where (files, commit or result), the commands run and what they showed, and what is not covered or not tested yet."
19
+ "bringsBack": "What changed and where (files, commit or result), the commands run and what they showed, and what is not covered or not tested yet.",
20
+ "floor": "middle"
20
21
  },
21
22
  "checker": {
22
23
  "name": "checker",
23
24
  "owns": "Comparing what was asked with what was delivered, by running it or opening it, not by reading the author's summary.",
24
25
  "never": "Fixes the work itself (that makes it an author), or passes work it did not run or open.",
25
- "bringsBack": "First line: passed, sent back, or could not tell. Then what was run or opened, what it showed, and for sent back exactly what to fix."
26
+ "bringsBack": "First line: passed, sent back, or could not tell. Then what was run or opened, what it showed, and for sent back exactly what to fix.",
27
+ "floor": "middle"
26
28
  },
27
29
  "reviewer": {
28
30
  "name": "reviewer",
29
31
  "owns": "A fresh read of the finished change: whether it does what the goal needs, fits how the code already works, and leaves no second way to do the same thing.",
30
32
  "never": "Changes files, reviews its own work, or invents findings: a clean review is a fine result.",
31
- "bringsBack": "First line: passed, sent back, or could not tell. Then each finding with its severity (must fix, should fix, later), the file and line or a way to reproduce it, and whether you checked it yourself."
33
+ "bringsBack": "First line: passed, sent back, or could not tell. Then each finding with its severity (must fix, should fix, later), the file and line or a way to reproduce it, and whether you checked it yourself.",
34
+ "floor": "top"
32
35
  },
33
36
  "researcher": {
34
37
  "name": "researcher",
35
38
  "owns": "One angle of the question, dug into deeply, with sources the others can open.",
36
39
  "never": "Repeats another researcher's angle, or turns findings into instructions for the builders.",
37
- "bringsBack": "Findings with their sources, facts kept apart from inferences, and what this angle could not answer."
40
+ "bringsBack": "Findings with their sources, facts kept apart from inferences, and what this angle could not answer.",
41
+ "floor": "any"
38
42
  },
39
43
  "synthesizer": {
40
44
  "name": "synthesizer",
41
45
  "owns": "Turning the researchers' findings into one answer: where they agree (counting methods, not votes), where they contradict and which evidence wins, and what nobody covered.",
42
46
  "never": "Just stacks the findings one after another, or drops who found what.",
43
- "bringsBack": "One answer with each point credited to who found it, the contradictions and how they were settled, a confidence (high, medium or low), and what the team should do next."
47
+ "bringsBack": "One answer with each point credited to who found it, the contradictions and how they were settled, a confidence (high, medium or low), and what the team should do next.",
48
+ "floor": "middle"
44
49
  },
45
50
  "director": {
46
51
  "name": "director",
47
52
  "owns": "The creative direction: what to make and why, the brief for the makers, and the judgment of each round against what the person asked for.",
48
53
  "never": "Makes the pieces another agent is there to make.",
49
- "bringsBack": "When directing: what to make, for whom, and what good looks like. When judging: first line passed or sent back, then what to change in the next round."
54
+ "bringsBack": "When directing: what to make, for whom, and what good looks like. When judging: first line passed or sent back, then what to change in the next round.",
55
+ "floor": "middle"
50
56
  },
51
57
  "maker": {
52
58
  "name": "maker",
53
59
  "owns": "Generating the pieces the direction asks for: images, video, sound, motion or copy, attached in the thread for everyone.",
54
60
  "never": "Changes the direction on its own; it says so in the thread instead.",
55
- "bringsBack": "The pieces attached in the thread, what each one is, and anything it could not make."
61
+ "bringsBack": "The pieces attached in the thread, what each one is, and anything it could not make.",
62
+ "floor": "any"
56
63
  },
57
64
  "editor": {
58
65
  "name": "editor",
59
66
  "owns": "Assembling the makers' pieces into the finished thing: the cut, the layout, the final file.",
60
67
  "never": "Remakes pieces another agent made; it asks for a new one instead.",
61
- "bringsBack": "The assembled result attached in the thread, and what is missing or rough."
68
+ "bringsBack": "The assembled result attached in the thread, and what is missing or rough.",
69
+ "floor": "any"
62
70
  }
63
71
  },
64
72
  "shapes": {
@@ -182,11 +190,5 @@
182
190
  "careful": "Someone other than the author checks it by running it, because a mistake would be costly or hard to see.",
183
191
  "thorough": "An independent check and a separate review of the finished change, because it is hard to undo, outward-facing or money is involved."
184
192
  },
185
- "sendBackLimit": 3,
186
- "goalLevelModels": [
187
- "opus",
188
- "fable",
189
- "sol",
190
- "astra"
191
- ]
193
+ "sendBackLimit": 3
192
194
  }
package/lib/team.mjs CHANGED
@@ -1,5 +1,6 @@
1
1
  import { readFileSync } from "node:fs";
2
2
  import { nameOf } from "./members.mjs";
3
+ import { meetsFloor } from "./modelTiers.mjs";
3
4
 
4
5
  // How the agents in a thread work as a team (team.json, read by the server too through src/shared/team.ts): the team's
5
6
  // shape, who holds each role, how careful the work must be, and the route the work takes between the roles. Without one,
@@ -22,28 +23,35 @@ export const RIGOR_LEVELS = Object.keys(TEAM.rigor);
22
23
  // Every runner's reported states that end a turn: a question to the person (needs_input) is not the step's end.
23
24
  const FINISHED = new Set(["done", "failed", "unknown"]);
24
25
 
25
- /** Whether a model takes a goal and finds its own route (the brief gives it intent), from its name. */
26
- export const goalLevel = (model) =>
27
- Boolean(model) &&
28
- TEAM.goalLevelModels.some((family) =>
29
- String(model).toLowerCase().includes(family)
30
- );
26
+ /** Whether an agent takes a goal and finds its own route (the brief gives it intent): a top-tier model. */
27
+ export const goalLevel = (tier) => tier === "top";
31
28
 
32
29
  const stepsOf = (plan) =>
33
30
  (SHAPES[plan.shape]?.steps ?? []).filter(
34
31
  (step) => (plan.roles[step.role] ?? []).length > 0
35
32
  );
36
33
 
37
- /** A plan as the round proposed it, kept only where it names a known shape, known roles and agents that may hold them. */
38
- export function validPlan(proposed, { members }) {
34
+ /**
35
+ * A plan as the round proposed it, kept only where it names a known shape, known roles and agents that may hold them:
36
+ * agents of the swarm whose tier meets the role's floor (`tiers`: agent id -> tier, from its card, modelTiers.mjs). Who
37
+ * was left out for the floor comes back in `leftOut`, so the thread says why.
38
+ */
39
+ export function validPlan(proposed, { members, tiers = {} }) {
39
40
  const shape = SHAPES[proposed?.shape];
40
41
  if (!shape) return null;
41
42
  const allowed = new Set(members);
42
43
  const roles = {};
44
+ const leftOut = [];
43
45
  for (const role of shape.roles) {
44
- const holders = [
46
+ const named = [
45
47
  ...new Set((proposed.roles?.[role] ?? []).map(String)),
46
48
  ].filter((agent) => allowed.has(agent));
49
+ const floor = TEAM.roles[role].floor ?? "any";
50
+ const holders = named.filter((agent) => {
51
+ const fits = meetsFloor(tiers[agent]?.level ?? "unknown", floor);
52
+ if (!fits) leftOut.push({ role, agent, floor, tier: tiers[agent] });
53
+ return fits;
54
+ });
47
55
  if (holders.length)
48
56
  roles[role] = TEAM.several.includes(role) ? holders : holders.slice(0, 1);
49
57
  }
@@ -56,9 +64,43 @@ export function validPlan(proposed, { members }) {
56
64
  rigor: RIGOR_LEVELS.includes(proposed.rigor) ? proposed.rigor : "standard",
57
65
  roles,
58
66
  };
59
- return stepsOf(plan).length ? plan : null;
67
+ // A role of the shape nobody holds because no agent here meets its floor: the thread says so, with who fell short.
68
+ const unfilled = shape.roles
69
+ .filter(
70
+ (role) => !roles[role] && (TEAM.roles[role].floor ?? "any") !== "any"
71
+ )
72
+ .map((role) => ({
73
+ role,
74
+ floor: TEAM.roles[role].floor,
75
+ short: members
76
+ .filter(
77
+ (agent) =>
78
+ !meetsFloor(
79
+ tiers[agent]?.level ?? "unknown",
80
+ TEAM.roles[role].floor
81
+ )
82
+ )
83
+ .map((agent) => ({ agent, level: tiers[agent]?.level ?? "unknown" })),
84
+ }))
85
+ .filter(
86
+ (each) => each.short.length && each.short.length === members.length
87
+ );
88
+ return stepsOf(plan).length ? { ...plan, leftOut, unfilled } : null;
60
89
  }
61
90
 
91
+ // Only the agents whose tier is known are named: an agent with no model on its card (Bankr, Grok Bot) says nothing here.
92
+ const unfilledLine = ({ role, floor, short }) => {
93
+ const known = short.filter(({ level }) => level !== "unknown");
94
+ const named = known.length
95
+ ? ` (${known.map(({ agent, level }) => `${nameOf(agent)} ${level}`).join(", ")})`
96
+ : "";
97
+ return `This team has no ${TEAM.roles[role].name}: a ${TEAM.roles[role].name} runs on a ${floor}-tier model, which no agent here does${named}. To change that: npx tryharness agents tier ${known[0]?.agent ?? "<agent>"} ${floor}.`;
98
+ };
99
+
100
+ // The thread's words for an agent kept off a role by its floor, with what the person can do about it.
101
+ const leftOutLine = ({ role, agent, floor, tier }) =>
102
+ `${nameOf(agent)} is not the ${TEAM.roles[role].name}: a ${TEAM.roles[role].name} runs on a ${floor}-tier model and ${nameOf(agent)}'s is ${tier?.level ?? "unknown"} (${tier?.because ?? "no tier"}). To change that: npx tryharness agents tier ${agent} ${floor}.`;
103
+
62
104
  // How old a note is, in the words a brief uses.
63
105
  const age = (iso) => {
64
106
  const days = Math.floor((Date.now() - Date.parse(iso)) / 86_400_000);
@@ -106,12 +148,13 @@ export function createTeam({ store, log = () => {} }) {
106
148
  * Keep the plan the round proposed, starting at its first step. Says in the thread who holds what. Returns the plan
107
149
  * kept, or null when the proposal named nothing usable.
108
150
  */
109
- const set = (goalId, proposed, { members, by, post }) => {
110
- const valid = validPlan(proposed, { members });
111
- if (!valid) {
151
+ const set = (goalId, proposed, { members, tiers, by, post }) => {
152
+ const checked = validPlan(proposed, { members, tiers });
153
+ if (!checked) {
112
154
  log(`team plan for ${goalId} not kept: ${JSON.stringify(proposed)}`);
113
155
  return null;
114
156
  }
157
+ const { leftOut, unfilled, ...valid } = checked;
115
158
  const kept = {
116
159
  ...valid,
117
160
  step: stepsOf(valid)[0].id,
@@ -122,7 +165,14 @@ export function createTeam({ store, log = () => {} }) {
122
165
  };
123
166
  write(goalId, kept);
124
167
  post?.(
125
- `The team for this thread (${SHAPES[kept.shape].name}, ${kept.rigor}): ${lineup(kept)}.`
168
+ [
169
+ `The team for this thread (${SHAPES[kept.shape].name}, ${kept.rigor}): ${lineup(kept)}.`,
170
+ // One line per role: why it has no holder at all, else who was kept off it.
171
+ ...leftOut
172
+ .filter(({ role }) => !unfilled.some((each) => each.role === role))
173
+ .map(leftOutLine),
174
+ ...unfilled.map(unfilledLine),
175
+ ].join(" ")
126
176
  );
127
177
  return kept;
128
178
  };
@@ -343,7 +393,7 @@ export function createTeam({ store, log = () => {} }) {
343
393
  );
344
394
 
345
395
  /** The brief's section on the team, for an agent woken in a thread with a plan. `model`: the agent's model, if known. */
346
- const brief = (goalId, agent, { model = null } = {}) => {
396
+ const brief = (goalId, agent, { tier = null } = {}) => {
347
397
  const current = read(goalId);
348
398
  if (!current) return "";
349
399
  const steps = stepsOf(current);
@@ -380,14 +430,14 @@ export function createTeam({ store, log = () => {} }) {
380
430
  lines.push(
381
431
  "You hold no role on this team: do what you were asked and hand anything else to the agent whose role it is."
382
432
  );
383
- // Goal-level models get the intent and find the route; others do their best work on smaller checked steps.
384
- if (!goalLevel(model))
433
+ // Agents on top-tier models get the intent and find the route; others do their best work on smaller checked steps.
434
+ if (!goalLevel(tier))
385
435
  lines.push(
386
436
  "Work in small steps: do one part, check that it works, then the next, and say which parts are done."
387
437
  );
388
438
  if (mine.length)
389
439
  lines.push(
390
- `Before you stop: if you learned something about this folder that the next ${TEAM.roles[mine[0]].name} here should know (a trap, a check that matters, how the code really works), save it with save_learning (id ${goalId}): what you learned and why it holds.`
440
+ `Before you stop: if you learned something about this folder that the next ${TEAM.roles[mine[0]].name} here should know (a trap, a check that matters, how the code really works), add it with swarm_memory (remember, why, thread ${goalId}): what you learned and why it holds.`
391
441
  );
392
442
  return [
393
443
  "Your part on the team:",
@@ -341,7 +341,7 @@ export function createThreadRuns({
341
341
  if (!t3 && !elsewhere)
342
342
  try {
343
343
  folder =
344
- (shared && !review ? shared.folderFor(task, agent) : null) ??
344
+ (shared ? shared.folderFor(task, agent, { review }) : null) ??
345
345
  worktrees.folderFor(task);
346
346
  } catch (error) {
347
347
  store.roomPost({
@@ -484,6 +484,8 @@ export function createThreadRuns({
484
484
  author: task.target_agent,
485
485
  kind: kind === "done" ? "post" : "failed",
486
486
  text: kind === "done" ? text : `run failed: ${text}`,
487
+ // The computer the turn ran on (runWorker.mjs claims it there).
488
+ machine: store.getTask(task.id)?.claimed_machine ?? null,
487
489
  });
488
490
  const key = `${goalId}:${task.target_agent}`;
489
491
  const pending = pendingWakes.get(key);