tryharness 0.7.72 → 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 (47) hide show
  1. package/assets/opencode-plugin.js +70 -3
  2. package/lib/asks.mjs +2 -0
  3. package/lib/boardCommands.mjs +9 -1
  4. package/lib/boardProtocol.json +23 -19
  5. package/lib/bridge.mjs +2 -0
  6. package/lib/capabilityCheck.mjs +86 -0
  7. package/lib/computerAddress.mjs +6 -14
  8. package/lib/coordinator.mjs +207 -26
  9. package/lib/daemon.mjs +150 -125
  10. package/lib/dispatchContract.json +1 -31
  11. package/lib/dispatchTools.js +8 -39
  12. package/lib/dispatches.mjs +27 -285
  13. package/lib/goalCommands.mjs +7 -3
  14. package/lib/herdr.mjs +159 -0
  15. package/lib/hookDialects.mjs +36 -2
  16. package/lib/jobAnswers.mjs +3 -0
  17. package/lib/kanban.mjs +256 -0
  18. package/lib/localAgentAsk.mjs +20 -29
  19. package/lib/machineRoutes.mjs +1 -5
  20. package/lib/manager.mjs +254 -0
  21. package/lib/mcp-stdio.mjs +58 -39
  22. package/lib/moves.mjs +365 -0
  23. package/lib/nudge.mjs +13 -3
  24. package/lib/ownMachines.mjs +43 -6
  25. package/lib/places.mjs +29 -2
  26. package/lib/runAuthority.mjs +2 -14
  27. package/lib/runBrief.mjs +14 -1
  28. package/lib/runWorker.mjs +4 -10
  29. package/lib/runner.mjs +1 -49
  30. package/lib/sessionControl.mjs +65 -1
  31. package/lib/steerHook.mjs +124 -0
  32. package/lib/steerQueue.mjs +176 -0
  33. package/lib/store.mjs +9 -23
  34. package/lib/subagentSteering.mjs +363 -0
  35. package/lib/subagents.mjs +138 -29
  36. package/lib/swarm.mjs +13 -3
  37. package/lib/taskCommands.mjs +0 -62
  38. package/lib/threadActions.mjs +4 -2
  39. package/lib/threadBriefs.mjs +9 -3
  40. package/lib/threadRuns.mjs +13 -0
  41. package/npm-shrinkwrap.json +14 -14
  42. package/package.json +4 -4
  43. package/release.json +44 -40
  44. package/lib/comfyExecution.mjs +0 -545
  45. package/lib/promptDecider.mjs +0 -471
  46. package/lib/promptFlow.mjs +0 -597
  47. package/lib/promptScopes.mjs +0 -670
@@ -71,7 +71,7 @@ export const speakerOf = (store, thread, post) =>
71
71
  // Harness's part with no Harness window open waits on the board for one (daemon.mjs offerToServer); the thread goes on.
72
72
  const waitsForWindow = (run) =>
73
73
  run.status === "open" && run.target_agent === "harness";
74
- const going = (run) =>
74
+ export const going = (run) =>
75
75
  ["open", "claimed", "running"].includes(run.status) && !waitsForWindow(run);
76
76
 
77
77
  // The privacy setting: the round's facts go to an agent on this machine with its tools off, which answers in the
@@ -88,6 +88,7 @@ Decide the next step and answer with one JSON object only:
88
88
  )}, "text": what to look at then, in one or two sentences} only when the thread must wait on something that is not ready yet (a render, a deploy, a reply, a market, work that runs for hours) or the person asked for work over a long period, and \`checkIns\` has none by the lead}
89
89
  hand_on: the request needs more work an agent can do and none is working; that includes a next step an agent's result names for another agent, and a choice an agent can make with a sensible default. ask_person: only for spending above what the thread may spend (category spend), something outward-facing or hard to undo such as deploying, publishing, moving money or changing production data (outward), a secret only the person has (secret), or changing what the goal is for (scope). Never ask the person a taste or technical choice, a fact an agent could find, or something already answered in the transcript: hand it to an agent to decide with its best default. Never ask for a password or key in the thread. wait: an agent is working, a question to the person is open, the request is answered, or what is left is in waitingForWindow. pause: nothing more can be done without the person.
90
90
  Work in progress.waitingForWindow is already Harness's and only waits for the person's Harness window to open: never hand it on. Image and video generation is Harness's.
91
+ When \`moves\` is given, the action may also be one of these, each only with what \`moves\` offers: "inspect" with "lookUp": one of moves.lookUps, to read more before deciding (you are asked again with moves.lookedUp); "continue" with "agent": an agent in moves.conversations, to send the person's newest message as they wrote it on in that agent's conversation here; "execute" with "ref": the id of a turn in moves.held that the person's newest message gives its go; "deliver" with "ref": the id of a result in moves.results the person asks to see or have again; "cancel" with "stop": ids from moves.running the person asked to stop or that their newest message makes pointless; "finish" only when moves.finishable is true and the request is done or the person said they are finished.
91
92
  In briefs, refer to earlier posts by their seq number instead of restating figures or ids, and never say the person approved something unless you quote their words.
92
93
  The goal: statement is the whole aim in the person's terms; criteria are one to five checks a person or code can verify. A criterion is met only when a post shows the result, not when an agent only says so. goalState met only when every criterion is met.
93
94
  If the same attempt or failure keeps coming back, say so in loop and ask the next agent for a different approach in the brief, naming what was tried.
@@ -167,6 +168,12 @@ export function createCoordinator({
167
168
  // (ownMachines.mjs), and whether one of them can take the thread's turn at all.
168
169
  machinesOf = () => undefined,
169
170
  placeable = () => true,
171
+ // Whether each of the person's computers can do a piece of work, an agent there looking (capabilityCheck.mjs).
172
+ capabilities = null,
173
+ // The moves beyond bringing agents in (moves.mjs): look up, continue, start a held turn, show a result, stop, close.
174
+ moves = null,
175
+ // The person's open asks in a thread (manager.mjs): while any is open, the goal is not met nor ready for review.
176
+ openAsks = () => [],
170
177
  computerOf = (goalId) => store.meta(`thread-work-computer:${goalId}`) || null,
171
178
  // A post from the other side of a shared project (projects.mjs): their own swarm sorts it, so it starts no round here.
172
179
  fromPartner = () => false,
@@ -223,6 +230,31 @@ export function createCoordinator({
223
230
  Boolean(team) && (mode() === "local" || serverHas("swarm_routes"));
224
231
  const keepsPlacement = () =>
225
232
  mode() === "local" || serverHas("swarm_placement");
233
+ // The moves go to a coordinator that takes them: this computer's, or a Harness with swarm_moves.
234
+ const movesTaken = () =>
235
+ Boolean(moves) && (mode() === "local" || serverHas("swarm_moves"));
236
+ // What each computer said it can do with the person's newest message to the swarm (capabilityCheck.mjs), by computer
237
+ // id: asked once per message, kept for the thread's rounds until the next one, sent to a coordinator that reads it.
238
+ const canDo = async (thread, posts, asked) => {
239
+ if (
240
+ !capabilities ||
241
+ !(mode() === "local" || serverHas("capability_checks"))
242
+ )
243
+ return new Map();
244
+ const key = `capabilities:${thread.id}`;
245
+ let kept = JSON.parse(store.meta(key) || "null");
246
+ const message = asked && posts.find((post) => post.seq === asked.seq);
247
+ if (message && kept?.seq !== message.seq) {
248
+ kept = {
249
+ seq: message.seq,
250
+ answers: await capabilities.check(message.text),
251
+ };
252
+ store.meta(key, JSON.stringify(kept));
253
+ }
254
+ return new Map(
255
+ (kept?.answers ?? []).map(({ id, answer, why }) => [id, { answer, why }])
256
+ );
257
+ };
226
258
  // The person's pins: specialty -> the agent that holds it when a step asks for it.
227
259
  const pinsNow = () =>
228
260
  Object.fromEntries(
@@ -284,7 +316,11 @@ export function createCoordinator({
284
316
  seq: post.seq,
285
317
  author: speakerOf(store, thread, post),
286
318
  kind: post.kind,
287
- text: (serverWords?.agentText(post) ?? post.text).slice(0, POST_CHARS),
319
+ // The person's own words whole; an agent's cut to the limit.
320
+ text:
321
+ post.author === "user"
322
+ ? post.text
323
+ : (serverWords?.agentText(post) ?? post.text).slice(0, POST_CHARS),
288
324
  }));
289
325
  const runs = store.threadRuns(thread.id);
290
326
  const since = state.lastRoundAt ?? "";
@@ -339,11 +375,11 @@ export function createCoordinator({
339
375
  // Each card's specialties, pins and offices go only to a Harness that reads them (feature team_specialties).
340
376
  const specialtiesTaken =
341
377
  mode() === "local" || serverHas("team_specialties");
378
+ const can = await canDo(thread, posts, asked);
342
379
  // Who could hold a role on the thread's team: the candidates and the agents the person named.
343
380
  const eligible = roster()
344
381
  .filter(
345
382
  (candidate) =>
346
- (!CODING.has(candidate.id) || thread.goal.workspace) &&
347
383
  !failedHereLately(thread.id, candidate.id) &&
348
384
  (!CODING.has(candidate.id) ||
349
385
  placeable(candidate.id, thread.goal.workspace)) &&
@@ -389,6 +425,7 @@ export function createCoordinator({
389
425
  ? { thread_repository }
390
426
  : {}),
391
427
  ...(keepsPlacement() ? { id } : {}),
428
+ ...(can.has(id) ? { can_do: can.get(id) } : {}),
392
429
  })
393
430
  )
394
431
  : undefined,
@@ -453,6 +490,7 @@ export function createCoordinator({
453
490
  const framed = await frame(thread.id);
454
491
  return {
455
492
  ...(framed ? { frame: framed } : {}),
493
+ ...(movesTaken() ? { moves: moves.offered(thread, { candidates }) } : {}),
456
494
  ...teamFacts,
457
495
  thread: {
458
496
  id: thread.id,
@@ -530,7 +568,6 @@ export function createCoordinator({
530
568
  (agent) =>
531
569
  agent !== "harness" &&
532
570
  !asked.named.includes(agent) &&
533
- (!CODING.has(agent) || thread.goal.workspace) &&
534
571
  (!TAGGED.has(agent) || inThread.includes(agent)) &&
535
572
  (reachable || CODING.has(agent))
536
573
  );
@@ -619,7 +656,8 @@ export function createCoordinator({
619
656
  // change since, or no passing check yet, leaves the goal working ("Ready for your review" was once posted
620
657
  // with 1 of 3 checks met).
621
658
  const unchecked =
622
- keepsTeams() && !team.checkedNow(thread.id, headOf(thread.id));
659
+ (keepsTeams() && !team.checkedNow(thread.id, headOf(thread.id))) ||
660
+ openAsks(thread.id).length > 0;
623
661
  const settles =
624
662
  decision.goalState === "met" ||
625
663
  decision.goalState === "ready_for_review" ||
@@ -827,9 +865,18 @@ export function createCoordinator({
827
865
  store.setGoalTeam(thread.id, [...thread.goal.team, agent]);
828
866
  }
829
867
  }
868
+ // The route's computer for its step, else the one Jev picked for this agent, when it is one of the agent's online
869
+ // computers.
870
+ const picked =
871
+ options.computer &&
872
+ (machinesOf(agent, thread.goal.workspace) ?? []).some(
873
+ (computer) => computer.id === options.computer && computer.online
874
+ )
875
+ ? options.computer
876
+ : null;
830
877
  options = {
831
878
  ...options,
832
- routeMachine: team?.machineFor(thread.id, agent) ?? null,
879
+ routeMachine: team?.machineFor(thread.id, agent) ?? picked,
833
880
  };
834
881
  const step = keepsTeams() ? team.pinnedStep(thread.id, agent) : null;
835
882
  if (!step || !store.busyElsewhere(agent, thread.id)) {
@@ -889,6 +936,8 @@ export function createCoordinator({
889
936
  endRoute(thread, given);
890
937
  if (applyGoal(thread, given, coordinator)) return;
891
938
  applyCheckIn(thread, given, coordinator);
939
+ // A move carries the person's own words or an agent's own result (moves.mjs), outside the route and the briefs.
940
+ if (moves?.apply(thread, given, coordinator)) return;
892
941
  const planned = applyTeamPlan(thread, given, coordinator, asked);
893
942
  if (
894
943
  given.team?.plan &&
@@ -1023,7 +1072,11 @@ export function createCoordinator({
1023
1072
  withheld
1024
1073
  ? part.text
1025
1074
  : `${coordinator} asked you: ${part.text.slice(0, 300)}`,
1026
- { review: part.review, words: part.text },
1075
+ {
1076
+ review: part.review,
1077
+ words: part.text,
1078
+ computer: part.computer ?? null,
1079
+ },
1027
1080
  coordinator
1028
1081
  );
1029
1082
  if (withheld)
@@ -1085,7 +1138,7 @@ export function createCoordinator({
1085
1138
  thread,
1086
1139
  agent,
1087
1140
  withheld ? text : `${coordinator} asked you: ${text.slice(0, 300)}`,
1088
- { review, words: text },
1141
+ { review, words: text, computer: decision.computer ?? null },
1089
1142
  coordinator
1090
1143
  );
1091
1144
  if (withheld) saidWithheld(thread, withheld, [agent]);
@@ -1167,6 +1220,98 @@ export function createCoordinator({
1167
1220
  store.meta(`goal-kept:${thread.id}`, String(newest));
1168
1221
  };
1169
1222
 
1223
+ // One coordinator's decision for the round's facts: Harness's server, or a coding agent here with its tools off.
1224
+ const decideWith = async (coordinator, gathered) => {
1225
+ if (coordinator !== "harness") return localDecision(coordinator, gathered);
1226
+ // No deadline of its own: the round ends when Harness answers or the connection drops.
1227
+ const reply = await askHarness("coordinate", gathered, null);
1228
+ if (!reply.ok)
1229
+ throw new Error(reply.error || "Harness did not coordinate this round");
1230
+ return reply.result ?? reply;
1231
+ };
1232
+
1233
+ // A decision being carried out, kept until it is (the contract's outbox): a restart in the middle finishes it once.
1234
+ const OUTBOX = "round-outbox";
1235
+ const outbox = () => {
1236
+ try {
1237
+ return JSON.parse(store.meta(OUTBOX) || "{}");
1238
+ } catch {
1239
+ return {};
1240
+ }
1241
+ };
1242
+ const keepIntent = (goalId, intent) =>
1243
+ store.meta(
1244
+ OUTBOX,
1245
+ JSON.stringify({ ...outbox(), [goalId]: intent ?? undefined })
1246
+ );
1247
+ // The agents a decision wakes, each with its own words.
1248
+ const wokenBy = (decision) =>
1249
+ decision.action === "assemble"
1250
+ ? (decision.parts ?? []).map((part) => part.agent)
1251
+ : ["hand_on", "continue"].includes(decision.action) && decision.agent
1252
+ ? [decision.agent]
1253
+ : [];
1254
+ // Whether an agent has work in the thread that began at or after `at`: its wake from this decision got out.
1255
+ const wokenSince = (goalId, agent, at) =>
1256
+ store
1257
+ .threadRuns(goalId)
1258
+ .some((run) => run.target_agent === agent && run.created_at >= at) ||
1259
+ store
1260
+ .roomPosts(goalId, 0, 500)
1261
+ .some(
1262
+ (post) =>
1263
+ post.kind === "job" &&
1264
+ post.mentions.includes(agent) &&
1265
+ post.created_at >= at
1266
+ );
1267
+ /**
1268
+ * After a restart: each decision that was being carried out. Not begun (nothing posted since), it is carried out
1269
+ * whole; begun, only the agents it woke that have nothing since are woken, with the words it gave them.
1270
+ */
1271
+ const recover = () => {
1272
+ for (const [goalId, intent] of Object.entries(outbox())) {
1273
+ keepIntent(goalId, null);
1274
+ const thread = store.getTask(goalId);
1275
+ if (!thread || thread.status !== "open") continue;
1276
+ const begun = store
1277
+ .roomPosts(goalId, 0, 500)
1278
+ .some(
1279
+ (post) =>
1280
+ post.created_at >= intent.at &&
1281
+ store.meta(`coordinator-post:${post.id}`)
1282
+ );
1283
+ if (!begun) {
1284
+ apply(
1285
+ thread,
1286
+ intent.decision,
1287
+ intent.coordinator,
1288
+ intent.candidates,
1289
+ intent.asked,
1290
+ intent.rules,
1291
+ intent.withheld
1292
+ );
1293
+ continue;
1294
+ }
1295
+ for (const agent of wokenBy(intent.decision)) {
1296
+ if (wokenSince(goalId, agent, intent.at)) continue;
1297
+ const words =
1298
+ intent.decision.action === "assemble"
1299
+ ? intent.decision.parts.find((part) => part.agent === agent)?.text
1300
+ : intent.decision.text;
1301
+ if (intent.decision.action === "continue")
1302
+ moves.apply(thread, intent.decision, intent.coordinator);
1303
+ else if (words)
1304
+ handOnOrHold(
1305
+ thread,
1306
+ agent,
1307
+ `${intent.coordinator} asked you: ${String(words).slice(0, 300)}`,
1308
+ { words, computer: intent.decision.computer ?? null },
1309
+ intent.coordinator
1310
+ );
1311
+ }
1312
+ }
1313
+ };
1314
+
1170
1315
  const round = async (goalId) => {
1171
1316
  releaseHeld();
1172
1317
  const thread = store.getTask(goalId);
@@ -1316,7 +1461,7 @@ export function createCoordinator({
1316
1461
  if (opening)
1317
1462
  gathered.thread = {
1318
1463
  ...gathered.thread,
1319
- opening: opening.text.slice(0, 3_800),
1464
+ opening: opening.text,
1320
1465
  };
1321
1466
  }
1322
1467
  const lastSeq = seenUpTo();
@@ -1329,20 +1474,11 @@ export function createCoordinator({
1329
1474
  const failures = [];
1330
1475
  for (const coordinator of chain) {
1331
1476
  try {
1332
- if (coordinator === "harness") {
1333
- // No deadline of its own: the round ends when Harness answers or the connection drops.
1334
- const reply = await askHarness("coordinate", gathered, null);
1335
- if (!reply.ok)
1336
- throw new Error(
1337
- reply.error || "Harness did not coordinate this round"
1338
- );
1339
- decision = reply.result ?? reply;
1340
- } else {
1341
- // A backup decides a plain round: an assembly is Harness's, and the person's message goes to everyone instead.
1342
- if (assembling) break;
1343
- decision = await localDecision(coordinator, gathered);
1477
+ // A backup decides a plain round: an assembly is Harness's, and the person's message goes to everyone instead.
1478
+ if (coordinator !== "harness" && assembling) break;
1479
+ decision = await decideWith(coordinator, gathered);
1480
+ if (coordinator !== "harness")
1344
1481
  store.meta(`coordinator-backup-failed:${coordinator}`, "");
1345
- }
1346
1482
  decidedBy = coordinator;
1347
1483
  break;
1348
1484
  } catch (failure) {
@@ -1351,6 +1487,32 @@ export function createCoordinator({
1351
1487
  store.meta(`coordinator-backup-failed:${coordinator}`, "1");
1352
1488
  }
1353
1489
  }
1490
+ // A look-up first: what it found goes into the same round, which the same coordinator decides once more, with no
1491
+ // look-up offered then.
1492
+ if (
1493
+ decision?.action === "inspect" &&
1494
+ gathered.moves?.lookUps.includes(decision.lookUp)
1495
+ ) {
1496
+ const request =
1497
+ store
1498
+ .roomPosts(goalId, 0, 500)
1499
+ .findLast((post) => post.author === "user" && post.kind === "post")
1500
+ ?.text ?? thread.objective;
1501
+ gathered.moves = moves.offered(thread, {
1502
+ candidates: gathered.candidates,
1503
+ looked: moves.lookUp(
1504
+ thread,
1505
+ decision.lookUp,
1506
+ request,
1507
+ decision.before ?? null
1508
+ ),
1509
+ });
1510
+ decision = await decideWith(decidedBy, gathered).catch((failure) => {
1511
+ failures.push({ coordinator: decidedBy, error: failure.message });
1512
+ return null;
1513
+ });
1514
+ if (!decision) decidedBy = null;
1515
+ }
1354
1516
  const error =
1355
1517
  failures.find((entry) => entry.coordinator === "harness")?.error ??
1356
1518
  failures[0]?.error ??
@@ -1419,15 +1581,26 @@ export function createCoordinator({
1419
1581
  withheld = { reason, asks, forPerson: stripped.forPerson };
1420
1582
  }
1421
1583
  }
1584
+ const intent = {
1585
+ at: new Date().toISOString(),
1586
+ decision,
1587
+ coordinator: thread.goal.facilitator,
1588
+ candidates: gathered.candidates,
1589
+ asked,
1590
+ rules: decidedBy === "harness" ? keepsGoals() : true,
1591
+ withheld,
1592
+ };
1593
+ keepIntent(goalId, intent);
1422
1594
  apply(
1423
1595
  store.getTask(goalId),
1424
1596
  decision,
1425
- thread.goal.facilitator,
1426
- gathered.candidates,
1597
+ intent.coordinator,
1598
+ intent.candidates,
1427
1599
  asked,
1428
- decidedBy === "harness" ? keepsGoals() : true,
1600
+ intent.rules,
1429
1601
  withheld
1430
1602
  );
1603
+ keepIntent(goalId, null);
1431
1604
  };
1432
1605
 
1433
1606
  // Why Harness did not decide, as one clause: its own words when it said why, else the failure behind it.
@@ -1489,5 +1662,13 @@ export function createCoordinator({
1489
1662
  })
1490
1663
  );
1491
1664
  };
1492
- return { poke, heard, resumed, assembles, state: stateOf };
1665
+ return {
1666
+ poke,
1667
+ heard,
1668
+ resumed,
1669
+ assembles,
1670
+ recover,
1671
+ hostedAtWork,
1672
+ state: stateOf,
1673
+ };
1493
1674
  }