tryharness 0.7.53 → 0.7.54

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 (69) hide show
  1. package/README.md +10 -5
  2. package/assets/dsh-plugin.mjs +72 -0
  3. package/assets/opencode-plugin.js +4 -3
  4. package/cli.mjs +115 -36
  5. package/lib/adapters.mjs +157 -222
  6. package/lib/agentRuntimes.mjs +26 -16
  7. package/lib/agentSignIn.mjs +226 -0
  8. package/lib/audit.mjs +643 -0
  9. package/lib/backupSetup.mjs +141 -0
  10. package/lib/boardAccess.mjs +8 -1
  11. package/lib/boardBackup.mjs +283 -0
  12. package/lib/boardMirror.mjs +71 -7
  13. package/lib/boardProtocol.json +59 -2
  14. package/lib/boardWaits.mjs +102 -0
  15. package/lib/book.mjs +659 -0
  16. package/lib/bridge.mjs +1 -1
  17. package/lib/cards.mjs +138 -28
  18. package/lib/cloudBoot.mjs +124 -0
  19. package/lib/commands.mjs +7 -2
  20. package/lib/context.mjs +18 -4
  21. package/lib/contractGate.mjs +377 -0
  22. package/lib/coordinator.mjs +149 -43
  23. package/lib/daemon.mjs +349 -28
  24. package/lib/desk.mjs +239 -0
  25. package/lib/desktop.mjs +106 -6
  26. package/lib/environments.mjs +237 -7
  27. package/lib/folders.mjs +2 -2
  28. package/lib/gitHost.mjs +174 -0
  29. package/lib/hookDialects.mjs +298 -0
  30. package/lib/landed.mjs +887 -0
  31. package/lib/live.mjs +284 -13
  32. package/lib/mcp-stdio.mjs +68 -2
  33. package/lib/members.json +16 -2
  34. package/lib/models.mjs +8 -8
  35. package/lib/museSession.mjs +16 -13
  36. package/lib/nativeHost.mjs +1 -1
  37. package/lib/neovim.mjs +126 -0
  38. package/lib/nudge.mjs +47 -16
  39. package/lib/ownMachines.mjs +343 -39
  40. package/lib/pairing.mjs +27 -10
  41. package/lib/paths.mjs +4 -0
  42. package/lib/personModel.mjs +89 -0
  43. package/lib/phones.mjs +66 -11
  44. package/lib/places.mjs +330 -10
  45. package/lib/readiness.mjs +135 -18
  46. package/lib/record.mjs +115 -0
  47. package/lib/runWorker.mjs +17 -2
  48. package/lib/runner.mjs +8 -4
  49. package/lib/sessionControl.mjs +377 -89
  50. package/lib/specialties.json +74 -0
  51. package/lib/specialties.mjs +477 -0
  52. package/lib/specialtyKeys.d.ts +3 -0
  53. package/lib/specialtyKeys.js +58 -0
  54. package/lib/specialtyNotice.mjs +147 -0
  55. package/lib/specialtySnapshot.mjs +138 -0
  56. package/lib/store.mjs +284 -1
  57. package/lib/swarm.mjs +137 -21
  58. package/lib/t3.mjs +13 -4
  59. package/lib/taskCommands.mjs +36 -9
  60. package/lib/taskRuns.mjs +9 -2
  61. package/lib/team.json +255 -148
  62. package/lib/team.mjs +529 -188
  63. package/lib/threadLine.mjs +116 -0
  64. package/lib/threadRuns.mjs +75 -11
  65. package/lib/threadView.mjs +15 -2
  66. package/lib/worktrees.mjs +51 -13
  67. package/package.json +4 -4
  68. package/lib/modelTiers.json +0 -1183
  69. package/lib/modelTiers.mjs +0 -133
package/lib/swarm.mjs CHANGED
@@ -6,14 +6,24 @@ import { readRunSteps } from "./runner.mjs";
6
6
  import { createSubagents } from "./subagents.mjs";
7
7
  import { MACHINE_RUNNERS, member, nameOf, resolveMember } from "./members.mjs";
8
8
  import {
9
+ agentSpecialties,
9
10
  setNote,
10
- setTier,
11
11
  swarmBlock,
12
12
  swarmCards,
13
13
  swarmDigest,
14
14
  youLine,
15
15
  } from "./cards.mjs";
16
- import { TIERS } from "./modelTiers.mjs";
16
+ import {
17
+ SPECIALTIES,
18
+ addSpecialty,
19
+ appoint,
20
+ headingOf,
21
+ offices,
22
+ pins,
23
+ removeSpecialty,
24
+ setPin,
25
+ setPrimary,
26
+ } from "./specialties.mjs";
17
27
  import { askOfRun } from "./threadView.mjs";
18
28
  import { createWorkFocus } from "./workFocus.mjs";
19
29
  import { createWorkLinks } from "./workLinks.mjs";
@@ -39,10 +49,11 @@ export const PROCESS_NAMES = {
39
49
  codex: "codex",
40
50
  pi: "pi",
41
51
  opencode: "opencode",
52
+ // The command the person runs when it is not the protocol server Harness runs (Antigravity's `agy`).
42
53
  ...Object.fromEntries(
43
54
  MACHINE_RUNNERS.filter((id) => member(id)?.runtime).map((id) => [
44
55
  id,
45
- member(id).runtime.command,
56
+ member(id).cli ?? member(id).runtime.command,
46
57
  ])
47
58
  ),
48
59
  };
@@ -53,6 +64,30 @@ const UUID = /[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}/i;
53
64
  // A setup check's own room, from before checks stopped opening one (onboard.mjs): never a thread for the person.
54
65
  const SETUP_CHECK = /^Setup check from Harness: reply ready$/;
55
66
 
67
+ // A specialty as a command names it: its id, or its name as cards show it ("code review").
68
+ const specialtyIdOf = (text) => {
69
+ const wanted = String(text ?? "")
70
+ .trim()
71
+ .toLowerCase();
72
+ return (
73
+ SPECIALTIES.find(
74
+ (specialty) =>
75
+ specialty.id === wanted || specialty.name.toLowerCase() === wanted
76
+ )?.id ?? null
77
+ );
78
+ };
79
+ // Every specialty under its archetype's heading, in the list's order, for the Swarm map to offer.
80
+ const specialtyHeadings = () => {
81
+ const headings = new Map();
82
+ for (const specialty of SPECIALTIES) {
83
+ const heading = headingOf(specialty.id);
84
+ const entry = headings.get(heading.id) ?? { ...heading, specialties: [] };
85
+ entry.specialties.push({ id: specialty.id, name: specialty.name });
86
+ headings.set(heading.id, entry);
87
+ }
88
+ return [...headings.values()];
89
+ };
90
+
56
91
  // The id an agent resumes a session by: the index keys sessions by their file name.
57
92
  export function nativeSessionId(agent, sessionId) {
58
93
  const bare = String(sessionId).replace(/\.jsonl$/, "");
@@ -98,6 +133,7 @@ export function agentProcessCwds(exclude = new Set()) {
98
133
  }
99
134
 
100
135
  export function createSwarm({
136
+ landed = null,
101
137
  store,
102
138
  // What this computer hands the person's Harness page through the extension (browserWake.mjs).
103
139
  browserWake = null,
@@ -347,6 +383,8 @@ export function createSwarm({
347
383
  checkIns: schedules?.list({ threadId: thread.id }) ?? [],
348
384
  ceilingUsd: ceilingOf(thread.id),
349
385
  changes: worktrees.summary(thread.id),
386
+ // Whether it made anything that can land: its Landed view shows then (landed.mjs).
387
+ landed: landed?.produced(thread, posts) ?? false,
350
388
  // A project shared with another person's swarm (projects.mjs): which, and with whom.
351
389
  project: projectOf(thread.id),
352
390
  });
@@ -530,6 +568,18 @@ export function createSwarm({
530
568
  return posted;
531
569
  };
532
570
 
571
+ // One of the person's agents as a command names it, or why not.
572
+ const namedAgent = (target) => {
573
+ const named = resolveMember(target);
574
+ if (named.ok) return named;
575
+ return {
576
+ ok: false,
577
+ error: named.candidates?.length
578
+ ? `"${target}" could be ${named.candidates.join(" or ")}; name one`
579
+ : `no agent called "${target}"`,
580
+ };
581
+ };
582
+
533
583
  return function swarmCommand(request, agent, machine = null) {
534
584
  const command = String(request.command);
535
585
  if (command === "board.swarm.list") {
@@ -552,10 +602,12 @@ export function createSwarm({
552
602
  sessions: request.sessions === false ? [] : sessions(),
553
603
  agents: roster(),
554
604
  joining: request.hostedCaller ? [] : joining(),
605
+ // What waits on the person about an agent, outside any thread (threadView.mjs swarmNeeds).
606
+ needsYou: request.hostedCaller ? [] : (threadView?.swarmNeeds() ?? []),
555
607
  });
556
- return environments && !request.hostedCaller
557
- ? { pending: environments.refresh().then(listed) }
558
- : listed();
608
+ // The work in T3 Code beside the board as T3 Code last said it; only the first read waits for it.
609
+ const loading = request.hostedCaller ? null : environments?.ready();
610
+ return loading ? { pending: loading.then(listed) } : listed();
559
611
  }
560
612
  if (
561
613
  [
@@ -947,25 +999,89 @@ export function createSwarm({
947
999
  note: setNote(store, named.id, request.text),
948
1000
  };
949
1001
  }
950
- // The person's own tier for one agent, which wins over its model's benchmark tier for the roles with a floor
951
- // (team.json); "auto" goes back to the benchmark's.
952
- if (command === "board.swarm.tier") {
1002
+ // What one agent is good at on the model it runs on now (specialties.mjs), for the Swarm map: each specialty with
1003
+ // its source and evidence, primary first, the specialties the person pinned it for, and every specialty there is,
1004
+ // under its heading. The person's, like everything from here on: agents read the cards through list_agents.
1005
+ if (command === "board.swarm.specialties") {
1006
+ const named = namedAgent(request.target);
1007
+ if (!named.ok) return named;
1008
+ const { model, effort, specialties } = agentSpecialties(store, named.id);
1009
+ return {
1010
+ ok: true,
1011
+ agent: named.id,
1012
+ model,
1013
+ effort,
1014
+ specialties,
1015
+ pinned: pins(store).filter((pin) => pin.agent === named.id),
1016
+ headings: specialtyHeadings(),
1017
+ };
1018
+ }
1019
+ // The person adds or removes one of an agent's specialties, or makes it the primary. A removal is final for the
1020
+ // agent and the model it runs on now: no benchmark or record brings it back.
1021
+ if (command === "board.swarm.specialty") {
953
1022
  if (agent !== "user")
954
- return { ok: false, error: "only the person sets an agent's tier" };
955
- const named = resolveMember(request.target);
956
- if (!named.ok)
957
1023
  return {
958
1024
  ok: false,
959
- error: named.candidates.length
960
- ? `"${request.target}" could be ${named.candidates.join(" or ")}; name one`
961
- : `no agent called "${request.target}"`,
1025
+ error: "only the person changes an agent's specialties",
1026
+ };
1027
+ const named = namedAgent(request.target);
1028
+ if (!named.ok) return named;
1029
+ const specialty = specialtyIdOf(request.specialty);
1030
+ if (!specialty)
1031
+ return {
1032
+ ok: false,
1033
+ error: `"${request.specialty}" is not a specialty Harness knows`,
962
1034
  };
963
- const tier = String(request.tier || "").toLowerCase();
964
- if (![...TIERS, "auto"].includes(tier))
965
- return { ok: false, error: "a tier is top, middle, bottom or auto" };
966
- setTier(store, named.id, tier === "auto" ? null : tier);
967
- const card = swarmCards(store, [{ id: named.id }])[0];
968
- return { ok: true, agent: named.id, tier: card?.tier ?? null };
1035
+ const action = String(request.action || "");
1036
+ const change = {
1037
+ add: addSpecialty,
1038
+ remove: removeSpecialty,
1039
+ primary: setPrimary,
1040
+ }[action];
1041
+ if (!change)
1042
+ return { ok: false, error: "the action is add, remove or primary" };
1043
+ const { model } = agentSpecialties(store, named.id);
1044
+ const changed = change(store, named.id, specialty, model);
1045
+ if (!changed.ok) return changed;
1046
+ return {
1047
+ ok: true,
1048
+ agent: named.id,
1049
+ specialties: agentSpecialties(store, named.id).specialties,
1050
+ };
1051
+ }
1052
+ // The person pins an agent for a specialty: it holds that specialty whenever a step asks for it. No agent takes the
1053
+ // pin off.
1054
+ if (command === "board.swarm.pin") {
1055
+ if (agent !== "user")
1056
+ return { ok: false, error: "only the person pins an agent" };
1057
+ const specialty = specialtyIdOf(request.specialty);
1058
+ if (!specialty)
1059
+ return {
1060
+ ok: false,
1061
+ error: `"${request.specialty}" is not a specialty Harness knows`,
1062
+ };
1063
+ if (request.target === null || request.target === undefined)
1064
+ return setPin(store, specialty, null);
1065
+ const named = namedAgent(request.target);
1066
+ if (!named.ok) return named;
1067
+ return setPin(store, specialty, named.id);
1068
+ }
1069
+ // The swarm's offices and who holds each, for the home computer's panel.
1070
+ if (command === "board.swarm.offices")
1071
+ return { ok: true, offices: offices(store) };
1072
+ // The person appoints an agent to an office, or no agent for its default; the rules refuse some, saying why.
1073
+ if (command === "board.swarm.office") {
1074
+ if (agent !== "user")
1075
+ return { ok: false, error: "only the person appoints an office" };
1076
+ const office = String(request.office || "")
1077
+ .trim()
1078
+ .toLowerCase()
1079
+ .replace(/\s+/g, "-");
1080
+ if (request.target === null || request.target === undefined)
1081
+ return appoint(store, office, null);
1082
+ const named = namedAgent(request.target);
1083
+ if (!named.ok) return named;
1084
+ return appoint(store, office, named.id);
969
1085
  }
970
1086
  // The person's choice of model and effort for one agent: a model it lists, "auto", or "default" for its own settings.
971
1087
  if (command === "board.swarm.model") {
package/lib/t3.mjs CHANGED
@@ -42,6 +42,8 @@ export async function findT3(home = t3Home(), hint = null) {
42
42
  } catch {
43
43
  return null;
44
44
  }
45
+ // "late" when the limit ran out: either nothing answered in time, or this process was busy past the limit and its
46
+ // timer fired before it read an answer already waiting.
45
47
  const answers = async (origin) => {
46
48
  try {
47
49
  const response = await fetch(`${origin}/.well-known/t3/environment`, {
@@ -50,14 +52,21 @@ export async function findT3(home = t3Home(), hint = null) {
50
52
  return (
51
53
  response.ok && (await response.json())?.environmentId === environmentId
52
54
  );
53
- } catch {
54
- return false;
55
+ } catch (error) {
56
+ return error?.name === "TimeoutError" ? "late" : false;
55
57
  }
56
58
  };
57
- if (hint && (await answers(hint))) return { origin: hint, environmentId };
59
+ // The address T3 last answered on is asked again when it was late: the daemon's own work blocked it for up to 11 s
60
+ // during the context engine's pass (October 23, .harness-runs/measure/t3-probe) while T3 answered in under 50 ms,
61
+ // so a late answer there said "not running" and the T3 threads list emptied.
62
+ if (hint) {
63
+ const first = await answers(hint);
64
+ const found = first === "late" ? await answers(hint) : first;
65
+ if (found === true) return { origin: hint, environmentId };
66
+ }
58
67
  for (let port = FIRST_PORT; port < FIRST_PORT + PORTS; port++) {
59
68
  const origin = `http://127.0.0.1:${port}`;
60
- if (origin !== hint && (await answers(origin)))
69
+ if (origin !== hint && (await answers(origin)) === true)
61
70
  return { origin, environmentId };
62
71
  }
63
72
  return null;
@@ -22,6 +22,8 @@ import {
22
22
  } from "./cards.mjs";
23
23
  import { PICKABLE, resolvePick, setRunPick } from "./models.mjs";
24
24
  import { onMachine, placeTask } from "./machineRoutes.mjs";
25
+ import { within } from "./folders.mjs";
26
+ import { recordClaims } from "./audit.mjs";
25
27
 
26
28
  // An agent working in a thread may bring another agent in for part of the work there, as Harness does when it names
27
29
  // one; an agent that moves money or takes positions joins only when the person names it (members.mjs TAGGED_ONLY).
@@ -30,9 +32,17 @@ const joinsThread = (thread, target, roomAgents) =>
30
32
  thread.goal.team.includes(String(target)) ||
31
33
  (roomAgents.includes(String(target)) &&
32
34
  !TAGGED_ONLY.includes(String(target)));
35
+ // Work in another repository is its own thread: an agent's session, and its T3 thread, belong to the folder it ran in,
36
+ // so a thread's turns all run in the thread's folder. A thread with no folder yet takes the work's (daemon.mjs joinRoom).
37
+ const sameFolder = (thread, folder) =>
38
+ !folder ||
39
+ !thread.goal.workspace ||
40
+ within(path.resolve(String(folder)), thread.goal.workspace);
33
41
 
34
42
  export function createTaskCommands({
35
43
  CLOUD_TARGETS,
44
+ // The onchain desk (desk.mjs): a Bankr ask in a thread under a strategy carries its instructions, never the book.
45
+ desk = null,
36
46
  OPENED,
37
47
  machines,
38
48
  ROOM_AGENTS,
@@ -71,12 +81,16 @@ export function createTaskCommands({
71
81
  authority,
72
82
  actors,
73
83
  files: boardFiles,
84
+ // Threads mirrored from another app (environments.mjs), when the person reads them here.
85
+ outside = () => null,
74
86
  }) {
75
87
  // The one open thread an agent is working in now, when the work it hands on may join it there.
76
- const soleThreadOf = (agent, target) => {
88
+ const soleThreadOf = (agent, target, folder) => {
77
89
  const working = store.threadsWorkedIn(agent);
78
90
  const thread = working.length === 1 ? store.getTask(working[0]) : null;
79
- return thread && joinsThread(thread, target, ROOM_AGENTS)
91
+ return thread &&
92
+ joinsThread(thread, target, ROOM_AGENTS) &&
93
+ sameFolder(thread, folder)
80
94
  ? thread.id
81
95
  : null;
82
96
  };
@@ -223,7 +237,7 @@ export function createTaskCommands({
223
237
  // for the person's Start is decided exactly as for work outside any thread: placing it grants nothing.
224
238
  const workingThread =
225
239
  !request.parentId && !request.thread && agent !== "user"
226
- ? soleThreadOf(agent, request.targetAgent)
240
+ ? soleThreadOf(agent, request.targetAgent, request.runWorkspace)
227
241
  : null;
228
242
  // Provenance is code's: the local parent's label and what Harness sent from above the poster can only tighten it.
229
243
  const parentTask = request.parentId
@@ -306,7 +320,10 @@ export function createTaskCommands({
306
320
  error: `${request.targetAgent} lives in Harness, and the daemon is not connected to it right now`,
307
321
  };
308
322
  if (goalParent || request.parentId || agent === "user")
309
- return forwardToHarness({ ...request, provenance: upstream });
323
+ return forwardToHarness({
324
+ ...(desk ? desk.forBankr(request) : request),
325
+ provenance: upstream,
326
+ });
310
327
  return forwardIntoRoom(request, upstream, provenance, {
311
328
  agent,
312
329
  objective,
@@ -594,11 +611,14 @@ export function createTaskCommands({
594
611
  );
595
612
  const told = local ? lessons.told() : [];
596
613
  // 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.
614
+ // caller is and the computer it runs on, the computer its call came from. Specialties by name here; list_agents
615
+ // gives each one's evidence.
598
616
  extra.swarm = {
599
- text: swarmBlock(cards, Date.now(), told),
617
+ text: swarmBlock(cards, Date.now(), told, { evidence: false }),
600
618
  digest: swarmDigest(cards, told),
601
- cards: cards.map((card) => cardLine(card)),
619
+ cards: cards.map((card) =>
620
+ cardLine(card, Date.now(), { evidence: false })
621
+ ),
602
622
  short: cards.map(shortCardLine),
603
623
  told: toldBlock(told),
604
624
  you: local ? youLine(agent, machines.whereIs(machine)) : "",
@@ -863,7 +883,7 @@ export function createTaskCommands({
863
883
  store.setRunSession(id, session);
864
884
  outcome = { ...outcome, task: store.getTask(id) };
865
885
  }
866
- } else if (request.command === "board.report")
886
+ } else if (request.command === "board.report") {
867
887
  outcome = store.reportTask(
868
888
  id,
869
889
  agent,
@@ -874,7 +894,12 @@ export function createTaskCommands({
874
894
  expected,
875
895
  machine
876
896
  );
877
- else if (request.command === "board.answer")
897
+ // What the report claims in its structured fields, which the auditor's code compares with the receipts.
898
+ if (outcome?.ok && request.claims) {
899
+ recordClaims(store, id, request.claims);
900
+ outcome = { ...outcome, task: store.getTask(id) };
901
+ }
902
+ } else if (request.command === "board.answer")
878
903
  outcome = store.answerTask(
879
904
  id,
880
905
  agent,
@@ -912,6 +937,8 @@ export function createTaskCommands({
912
937
  ok: false,
913
938
  error: "only the person removes work from the board",
914
939
  };
940
+ // A thread mirrored from T3 Code leaves Harness's list; T3 keeps it.
941
+ if (outside()?.owns(id)) return outside().hide(id);
915
942
  const task = store.getTask(id);
916
943
  if (!task || task.removed_at)
917
944
  return { ok: false, error: "task not found" };
package/lib/taskRuns.mjs CHANGED
@@ -38,7 +38,12 @@ function streamScrubber(values) {
38
38
  };
39
39
  }
40
40
 
41
- export function createTaskRuns({ t3Missed, nativeRequests = null }) {
41
+ /** `onOutput` hears a run's output reach its log: the steps every surface shows from it moved. */
42
+ export function createTaskRuns({
43
+ t3Missed,
44
+ nativeRequests = null,
45
+ onOutput = () => {},
46
+ }) {
42
47
  const taskRuns = new Map();
43
48
  const validRunId = (runId) =>
44
49
  typeof runId === "string" && /^[a-zA-Z0-9._-]{1,128}$/.test(runId);
@@ -191,7 +196,9 @@ export function createTaskRuns({ t3Missed, nativeRequests = null }) {
191
196
  };
192
197
  const observe = (stream, raw) => {
193
198
  const text = scrub.stream(stream, raw);
194
- if (text) appendLog(stream, text);
199
+ if (!text) return;
200
+ appendLog(stream, text);
201
+ onOutput(message.runId);
195
202
  };
196
203
  const hooks = nativeRequests
197
204
  ? {