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
@@ -0,0 +1,377 @@
1
+ import { createHash, randomUUID } from "node:crypto";
2
+ import { MACHINE_RUNNERS, nameOf } from "./members.mjs";
3
+ import { onchainExecutors, treasurerOf } from "./book.mjs";
4
+
5
+ // The gate between building a contract and deploying it (docs/swarm-organization.md, "Contracts", Decision 34). Bankr
6
+ // builds and deploys as two asks, so its maker is not its only check:
7
+ //
8
+ // 1. Build: Bankr returns the source and the compiled code; the treasurer (or the person) files them in the book and
9
+ // code hashes the runtime code. Every verdict below is bound to that hash, so code filed again after a review is
10
+ // reviewed again.
11
+ // 2. Check: a coding agent tests it on a fork with no real funds.
12
+ // 3. Judge: a reviewer on a model other than the checker's; then the grant or the person approves.
13
+ // 4. Deploy: Bankr is asked to deploy exactly that code, and code reads what the chain holds at the address it reports
14
+ // and compares it with the code reviewed.
15
+ //
16
+ // Deploying needs the grant's code_deployment and financial_onchain classes, both off by default, as the person
17
+ // recorded them in the book. The gate before the action itself stays the mandate's reservation on Harness's server:
18
+ // nothing here moves money or widens what Harness's server allows. If Bankr can only build and deploy in one go, the
19
+ // first deploy goes to a testnet (`oneGo`), and the testnet's code is what is reviewed.
20
+
21
+ export const DEPLOY_CLASSES = ["code_deployment", "financial_onchain"];
22
+ // Test networks a one-go build may deploy to. Harness's server reads code on the ones it knows (chainReceipts.ts).
23
+ export const TESTNETS = ["base-sepolia", "sepolia"];
24
+
25
+ const now = () => new Date().toISOString();
26
+ const short = (value, limit) =>
27
+ typeof value === "string" ? value.trim().slice(0, limit) : "";
28
+
29
+ /** Runtime code as hex (with or without 0x), normalized, or null when it is not hex. */
30
+ function hexOf(code) {
31
+ const hex = short(code, 200_000).toLowerCase().replace(/^0x/, "");
32
+ return hex && hex.length % 2 === 0 && /^[0-9a-f]+$/.test(hex) ? hex : null;
33
+ }
34
+
35
+ /** The SHA-256 of runtime code's bytes, as Harness's server hashes the code it reads at an address. */
36
+ export const codeSha256 = (hex) =>
37
+ createHash("sha256").update(Buffer.from(hex, "hex")).digest("hex");
38
+
39
+ const contractRow = (store, id) =>
40
+ store.db.get("select * from book_contracts where id = ?", [String(id || "")]);
41
+
42
+ const strategyOf = (store, id) =>
43
+ store.db.get("select * from book_strategies where id = ?", [
44
+ String(id || ""),
45
+ ]);
46
+
47
+ // The classes the person recorded for the strategy's grant; an agent's record of a grant counts for nothing here.
48
+ const grantClasses = (strategy) =>
49
+ strategy?.grant_set_by === "user"
50
+ ? JSON.parse(strategy.grant_classes || "[]")
51
+ : [];
52
+
53
+ const keeps = (store, agent) =>
54
+ agent === "user" || treasurerOf(store).agent === agent;
55
+
56
+ const update = (store, id, fields) => {
57
+ const names = Object.keys(fields);
58
+ store.db.run(
59
+ `update book_contracts set ${names.map((name) => `${name} = ?`).join(", ")}, version = version + 1, updated_at = ?
60
+ where id = ?`,
61
+ [...names.map((name) => fields[name]), now(), id]
62
+ );
63
+ return view(contractRow(store, id));
64
+ };
65
+
66
+ /** A contract as agents and the person read it, without its source and code. */
67
+ export const view = (row) =>
68
+ row && {
69
+ id: row.id,
70
+ strategy: row.strategy_id,
71
+ name: row.name,
72
+ chain: row.chain,
73
+ oneGo: Boolean(row.one_go),
74
+ buildChain: row.build_chain,
75
+ status: row.status,
76
+ codeSha256: row.code_sha256,
77
+ codeBytes: row.code_bytes == null ? null : Number(row.code_bytes),
78
+ check: row.check_by
79
+ ? {
80
+ by: row.check_by,
81
+ model: row.check_model,
82
+ sha256: row.check_sha256,
83
+ passed: Boolean(row.check_passed),
84
+ }
85
+ : null,
86
+ judge: row.judge_by
87
+ ? {
88
+ by: row.judge_by,
89
+ model: row.judge_model,
90
+ sha256: row.judge_sha256,
91
+ accepted: Boolean(row.judge_accepted),
92
+ }
93
+ : null,
94
+ approvedBy: row.approved_by,
95
+ deployTask: row.deploy_task,
96
+ address: row.address,
97
+ deployedSha256: row.deployed_sha256,
98
+ };
99
+
100
+ /** A contract the desk will build: under a strategy in the book, for one chain. The treasurer or the person. */
101
+ export function startContract(
102
+ store,
103
+ agent,
104
+ { strategy, name, chain, oneGo = false, buildChain = null }
105
+ ) {
106
+ if (!keeps(store, agent))
107
+ return {
108
+ ok: false,
109
+ error: "the treasurer or the person starts a contract",
110
+ };
111
+ if (!strategyOf(store, strategy))
112
+ return { ok: false, error: "name the strategy in the book it is for" };
113
+ const title = short(name, 120);
114
+ const target = short(chain, 40).toLowerCase();
115
+ if (!title || !target)
116
+ return {
117
+ ok: false,
118
+ error: "a contract has a name and the chain it is for",
119
+ };
120
+ const testnet = short(buildChain, 40).toLowerCase() || null;
121
+ if (oneGo && !TESTNETS.includes(testnet))
122
+ return {
123
+ ok: false,
124
+ error: `Bankr builds and deploys in one go here, so its first deploy goes to a testnet: one of ${TESTNETS.join(", ")}`,
125
+ };
126
+ const id = randomUUID();
127
+ const at = now();
128
+ store.db.run(
129
+ `insert into book_contracts(id, strategy_id, name, chain, one_go, build_chain, status, written_by, version, created_at, updated_at)
130
+ values(?, ?, ?, ?, ?, ?, 'drafting', ?, 1, ?, ?)`,
131
+ [
132
+ id,
133
+ String(strategy),
134
+ title,
135
+ target,
136
+ oneGo ? 1 : 0,
137
+ oneGo ? testnet : null,
138
+ agent,
139
+ at,
140
+ at,
141
+ ]
142
+ );
143
+ return { ok: true, contract: view(contractRow(store, id)) };
144
+ }
145
+
146
+ /** The words of Bankr's build ask: source and compiled code back, and no deploy except to a testnet in one go. */
147
+ export function buildAsk(store, id) {
148
+ const row = contractRow(store, id);
149
+ if (!row) return null;
150
+ return row.one_go
151
+ ? `Build the contract "${row.name}" and deploy it to ${row.build_chain} only, never to a main network. Return the full source, the compiled runtime bytecode as hex, the testnet address and the deploy transaction hash.`
152
+ : `Build the contract "${row.name}" for ${row.chain}. Do not deploy it. Return the full source and the compiled runtime bytecode as hex.`;
153
+ }
154
+
155
+ /**
156
+ * Bankr's build, filed by the treasurer or the person: the source and runtime code it returned. Code hashes the code;
157
+ * code filed again under a different hash clears every verdict given for the old one.
158
+ */
159
+ export function fileBuild(
160
+ store,
161
+ agent,
162
+ { contract, source, runtimeCode, buildTask = null, address = null }
163
+ ) {
164
+ const row = contractRow(store, contract);
165
+ if (!row) return { ok: false, error: "no contract in the book has that id" };
166
+ if (!keeps(store, agent))
167
+ return {
168
+ ok: false,
169
+ error: "the treasurer or the person files Bankr's build",
170
+ };
171
+ if (row.deploy_task)
172
+ return {
173
+ ok: false,
174
+ error: "this contract was already asked to deploy; start a new one",
175
+ };
176
+ const hex = hexOf(runtimeCode);
177
+ if (!hex)
178
+ return {
179
+ ok: false,
180
+ error: "the runtime code is hex, as the compiler gives it",
181
+ };
182
+ const sha256 = codeSha256(hex);
183
+ const same = sha256 === row.code_sha256;
184
+ return {
185
+ ok: true,
186
+ contract: update(store, row.id, {
187
+ source: short(source, 200_000),
188
+ runtime_code: hex,
189
+ code_sha256: sha256,
190
+ code_bytes: hex.length / 2,
191
+ build_task: short(buildTask, 120) || row.build_task,
192
+ ...(row.one_go && address
193
+ ? { address: short(address, 64).toLowerCase() }
194
+ : {}),
195
+ ...(same
196
+ ? {}
197
+ : {
198
+ check_by: null,
199
+ check_model: null,
200
+ check_sha256: null,
201
+ check_passed: null,
202
+ judge_by: null,
203
+ judge_model: null,
204
+ judge_sha256: null,
205
+ judge_accepted: null,
206
+ approved_by: null,
207
+ approved_sha256: null,
208
+ }),
209
+ status: "built",
210
+ }),
211
+ };
212
+ }
213
+
214
+ // Who may give a verdict on a contract: never the agent that executes onchain, and a verdict names the code it is for.
215
+ function verdictRefusal(row, agent, sha256) {
216
+ if (!row) return "no contract in the book has that id";
217
+ if (!row.code_sha256)
218
+ return "nothing is built yet; Bankr's build is filed first";
219
+ if (onchainExecutors().includes(agent))
220
+ return `${nameOf(agent)} built it, so it does not check or judge it`;
221
+ if (short(sha256, 64).toLowerCase() !== row.code_sha256)
222
+ return `that verdict is for other code: the code filed now has SHA-256 ${row.code_sha256}`;
223
+ return null;
224
+ }
225
+
226
+ /** The Check: a coding agent tested exactly this code on a fork with no real funds. */
227
+ export function fileCheck(store, agent, { contract, model, sha256, passed }) {
228
+ const row = contractRow(store, contract);
229
+ const refusal = verdictRefusal(row, agent, sha256);
230
+ if (refusal) return { ok: false, error: refusal };
231
+ if (!MACHINE_RUNNERS.includes(agent))
232
+ return {
233
+ ok: false,
234
+ error: "a coding agent on the person's computers checks a contract",
235
+ };
236
+ if (!short(model, 100))
237
+ return { ok: false, error: "a check names the model it ran on" };
238
+ return {
239
+ ok: true,
240
+ contract: update(store, row.id, {
241
+ check_by: agent,
242
+ check_model: short(model, 100),
243
+ check_sha256: row.code_sha256,
244
+ check_passed: passed === true ? 1 : 0,
245
+ judge_by: null,
246
+ judge_model: null,
247
+ judge_sha256: null,
248
+ judge_accepted: null,
249
+ status: passed === true ? "checked" : "sent_back",
250
+ }),
251
+ };
252
+ }
253
+
254
+ /** The Judge: a reviewer on a model other than the checker's accepted exactly this code, or sent it back. */
255
+ export function fileJudge(store, agent, { contract, model, sha256, accepted }) {
256
+ const row = contractRow(store, contract);
257
+ const refusal = verdictRefusal(row, agent, sha256);
258
+ if (refusal) return { ok: false, error: refusal };
259
+ if (!row.check_passed || row.check_sha256 !== row.code_sha256)
260
+ return {
261
+ ok: false,
262
+ error: "it is judged after a check passes on this code",
263
+ };
264
+ const judgeModel = short(model, 100);
265
+ if (agent === row.check_by)
266
+ return { ok: false, error: "the checker does not judge its own check" };
267
+ if (
268
+ !judgeModel ||
269
+ judgeModel.toLowerCase() === String(row.check_model).toLowerCase()
270
+ )
271
+ return {
272
+ ok: false,
273
+ error: `the judge runs on a model other than the checker's (${row.check_model})`,
274
+ };
275
+ return {
276
+ ok: true,
277
+ contract: update(store, row.id, {
278
+ judge_by: agent,
279
+ judge_model: judgeModel,
280
+ judge_sha256: row.code_sha256,
281
+ judge_accepted: accepted === true ? 1 : 0,
282
+ status: accepted === true ? "judged" : "sent_back",
283
+ }),
284
+ };
285
+ }
286
+
287
+ /** The person's own approval of deploying exactly this code, kept with the contract as who approved it. */
288
+ export function approveDeploy(store, agent, { contract, sha256 }) {
289
+ const row = contractRow(store, contract);
290
+ if (!row) return { ok: false, error: "no contract in the book has that id" };
291
+ if (agent !== "user")
292
+ return { ok: false, error: "only the person approves a deploy" };
293
+ if (short(sha256, 64).toLowerCase() !== row.code_sha256)
294
+ return {
295
+ ok: false,
296
+ error: `that approval is for other code: the code filed now has SHA-256 ${row.code_sha256}`,
297
+ };
298
+ return {
299
+ ok: true,
300
+ contract: update(store, row.id, {
301
+ approved_by: "user",
302
+ approved_sha256: row.code_sha256,
303
+ }),
304
+ };
305
+ }
306
+
307
+ /**
308
+ * Whether the reviewed code may be deployed now, and Bankr's deploy ask when it may: every step passed on the code
309
+ * filed now, approved by the grant or the person, under a grant the person recorded with both deploy classes.
310
+ */
311
+ export function deployRequest(store, { contract }) {
312
+ const row = contractRow(store, contract);
313
+ if (!row)
314
+ return { ok: false, refusals: ["no contract in the book has that id"] };
315
+ const strategy = strategyOf(store, row.strategy_id);
316
+ const classes = grantClasses(strategy);
317
+ const hash = row.code_sha256;
318
+ const refusals = [
319
+ !hash && "nothing is built yet",
320
+ hash &&
321
+ !(row.check_passed && row.check_sha256 === hash) &&
322
+ "no check passed on the code filed now",
323
+ hash &&
324
+ !(row.judge_accepted && row.judge_sha256 === hash) &&
325
+ "no judge accepted the code filed now",
326
+ // The grant approves within its classes; Harness's server still asks the person when the grant says to.
327
+ !DEPLOY_CLASSES.every((name) => classes.includes(name)) &&
328
+ `the person's grant for this strategy does not allow ${DEPLOY_CLASSES.join(" and ")}`,
329
+ row.deploy_task && "it was already asked to deploy",
330
+ ].filter(Boolean);
331
+ if (refusals.length) return { ok: false, refusals };
332
+ const from = row.build_task
333
+ ? ` from your build in task ${row.build_task}`
334
+ : "";
335
+ return {
336
+ ok: true,
337
+ chain: row.chain,
338
+ sha256: hash,
339
+ ask: `Deploy the contract "${row.name}" on ${row.chain}: exactly the compiled runtime code${from}, ${row.code_bytes} bytes with SHA-256 ${hash}, as reviewed. Do not rebuild or change it. Report the deployed address and the transaction hash.`,
340
+ };
341
+ }
342
+
343
+ /** The deploy ask went to Bankr as this task. */
344
+ export const markDeployAsked = (store, contract, taskId) =>
345
+ update(store, contract, { deploy_task: String(taskId), status: "deploying" });
346
+
347
+ /** The contract Bankr's deploy task was for, or null. */
348
+ export const contractOfDeploy = (store, taskId) =>
349
+ view(
350
+ store.db.get("select * from book_contracts where deploy_task = ?", [
351
+ String(taskId || ""),
352
+ ])
353
+ );
354
+
355
+ /**
356
+ * What the chain holds at the deployed address against the code reviewed: `deployed` when its SHA-256 is the reviewed
357
+ * code's, `mismatch` otherwise, and `unread` while the chain cannot be read.
358
+ */
359
+ export function verifyDeployment(store, { contract, address, deployedSha256 }) {
360
+ const row = contractRow(store, contract);
361
+ if (!row) return { ok: false, error: "no contract in the book has that id" };
362
+ const read = short(deployedSha256, 64).toLowerCase() || null;
363
+ const status = !read
364
+ ? "unread"
365
+ : read === row.code_sha256
366
+ ? "deployed"
367
+ : "mismatch";
368
+ return {
369
+ ok: status === "deployed",
370
+ status,
371
+ contract: update(store, row.id, {
372
+ address: short(address, 64).toLowerCase() || row.address,
373
+ deployed_sha256: read,
374
+ status: status === "unread" ? row.status : status,
375
+ }),
376
+ };
377
+ }
@@ -1,7 +1,10 @@
1
1
  import os from "node:os";
2
2
  import { spawn } from "node:child_process";
3
+ import { roundFields } from "./cards.mjs";
3
4
  import { MACHINE_RUNNERS, MEMBERS, TAGGED_ONLY, nameOf } from "./members.mjs";
4
5
  import { LEAD_TIMES } from "./schedules.mjs";
6
+ import { SPECIALTIES, pinnedFor, specialtyName } from "./specialties.mjs";
7
+ import { TEAM } from "./team.mjs";
5
8
 
6
9
  // The swarm's coordinator, run from this machine whether or not a Harness window is open. When a thread goes quiet
7
10
  // (no run left going) and has new posts the coordinator has not looked at, it runs one round: it gathers the facts
@@ -81,7 +84,14 @@ In briefs, refer to earlier posts by their seq number instead of restating figur
81
84
  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.
82
85
  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.
83
86
  A check-in brings the thread back to you at that time with a post saying what to look at; checkIns lists the thread's check-ins already set.
84
- The thread's team, when \`team\` is given: who holds which role and the step of its route. When \`team.step.finished\` is true and \`team.exits\` lists where the work goes next, hand on along the route unless a question to the person is open: for a step that judges (\`team.step.judges\`), read the newest report and pick the exit whose \`outcome\` it shows (passed, or sent_back when it found something to fix); hand on to that exit's agents and add "team": {"step": the exit's step, "outcome": its outcome} to your answer. An exit to step "stop" means pause and tell the person the work was sent back as often as the team allows; one to step "done" means decide as usual and add "team": {"step": "done", "outcome": "done"}. Never hand a check or a review to the agent that did the work.`;
87
+ The thread's route, when \`team\` is given: its steps (frame, make, check, combine, judge), who holds each and the step it is at. When \`team.step.finished\` is true and \`team.exits\` lists where the work goes next, hand on along the route unless a question to the person is open: for a step that judges (\`team.step.judges\`), read the newest report and pick the exit whose \`outcome\` it shows (passed, or sent_back when it found something to fix); hand on to that exit's agents and add "team": {"step": the exit's step, "outcome": its outcome} to your answer. An exit to step "stop" means pause and tell the person the work was sent back as often as the route allows; one to step "done" means decide as usual and add "team": {"step": "done", "outcome": "done"}. An exit to step "piece" goes to the next piece in \`team.nextPiece\`: route it as below, hand on to its first step's agents and add "team": {"step": "piece", "outcome": the exit's outcome, "plan": its route}. Never hand a check or a review to the agent that made the work.
88
+ Routing, when \`team\` is null or \`team.nextPiece\` is given, and \`teamMembers\` lists who may hold a step: you choose, you never write the frame. Add "team": {"plan": {"rigor": "light" | "standard" | "careful" | "thorough", "split": true only when the goal needs a framer to split it into pieces for different kinds of agent or one after another (never for a piece), "steps": [{"id": "frame" | "make" | "check" | "combine" | "judge", "specialty": the one specialty id the step asks for, "agents": ids from teamMembers}]}}. Rigor picks the steps: ${Object.entries(
89
+ TEAM.rigor
90
+ )
91
+ .map(([level, rigor]) => `${level}: ${rigor.steps.join(", ")}`)
92
+ .join(
93
+ "; "
94
+ )}; combine also runs when several agents make. At light the work goes straight to one maker. Anything the person depends on, or that moves money, is careful at least. Make may have several agents side by side, only when its parts are independent; every other step has one. Check and judge never go to a maker, judge never to the framer, and combine is one agent, never a vote. An agent the person tagged fills a step, Make unless they said otherwise; a pin in \`pins\` (specialty: agent) holds the step that asks for that specialty. An agent with work running or waiting elsewhere is less available. When you route, hand on to the agents of the route's first step. Specialty ids: ${SPECIALTIES.map((specialty) => specialty.id).join(", ")}.`;
85
95
 
86
96
  function localDecision(agent, facts) {
87
97
  return new Promise((resolve, reject) => {
@@ -227,10 +237,18 @@ export function createCoordinator({
227
237
  // Lessons go to a coordinator that reads them: this computer's, or a Harness that has swarm_lessons.
228
238
  const readsLessons = () =>
229
239
  Boolean(lessons) && (mode() === "local" || serverHas("swarm_lessons"));
230
- // The team goes to a coordinator that keeps it: this computer's follows a route, and a Harness with swarm_team also
231
- // proposes one in the thread's first assembly.
240
+ // The route goes to a coordinator that keeps it: this computer's, or a Harness with swarm_routes, which triages the
241
+ // goal in the thread's first assembly and routes each piece a framer splits off.
232
242
  const keepsTeams = () =>
233
- Boolean(team) && (mode() === "local" || serverHas("swarm_team"));
243
+ Boolean(team) && (mode() === "local" || serverHas("swarm_routes"));
244
+ // The person's pins: specialty -> the agent that holds it when a step asks for it.
245
+ const pinsNow = () =>
246
+ Object.fromEntries(
247
+ SPECIALTIES.map((specialty) => [
248
+ specialty.id,
249
+ pinnedFor(store, specialty.id),
250
+ ]).filter(([, agent]) => agent)
251
+ );
234
252
  // The backups, in the order they are tried: coding agents on this computer, most finished work first, one whose last
235
253
  // turn as a backup failed after the others.
236
254
  const backups = () => {
@@ -326,7 +344,9 @@ export function createCoordinator({
326
344
  const causesTaken = mode() === "local" || serverHas("swarm_failure_causes");
327
345
  const verdictsTaken = mode() === "local" || serverHas("swarm_reactions");
328
346
  const machinesTaken = mode() === "local" || serverHas("machines");
329
- const tiersTaken = mode() === "local" || serverHas("team_tiers");
347
+ // Each card's specialties, pins and offices go only to a Harness that reads them (feature team_specialties).
348
+ const specialtiesTaken =
349
+ mode() === "local" || serverHas("team_specialties");
330
350
  // Who could hold a role on the thread's team: the candidates and the agents the person named.
331
351
  const eligible = roster()
332
352
  .filter(
@@ -354,22 +374,35 @@ export function createCoordinator({
354
374
  },
355
375
  }),
356
376
  lessons: readsLessons() ? candidate.lessons : undefined,
357
- tier: tiersTaken ? candidate.tier : undefined,
377
+ specialties: specialtiesTaken
378
+ ? roundFields(candidate).specialties
379
+ : undefined,
380
+ pinned: specialtiesTaken ? roundFields(candidate).pinned : undefined,
381
+ offices: specialtiesTaken ? roundFields(candidate).offices : undefined,
358
382
  machines: machinesTaken
359
383
  ? machinesOf(candidate.id, thread.goal.workspace)
360
384
  : undefined,
385
+ // Whether a coding agent took its readiness prompt is for the person's surfaces; the round's card schema does not
386
+ // have it, and a round carrying it was refused as malformed once an agent's check came back.
387
+ readiness: undefined,
361
388
  }));
362
389
  const candidates = eligible.filter(
363
390
  (candidate) => !asked?.named.includes(candidate.id)
364
391
  );
365
- // The team: where its route stands, or none yet, which the person's message to the swarm settles.
392
+ // The route: where it stands, or none yet, which the person's message to the swarm triages (on the privacy setting,
393
+ // this computer's next round). A round that starts the next piece a framer split off routes it with the same facts.
366
394
  const teamView = keepsTeams()
367
395
  ? team.roundView(thread.id, runs, { head: headOf(thread.id) })
368
396
  : null;
397
+ const pins = keepsTeams() ? pinsNow() : {};
398
+ const routing = {
399
+ teamMembers: eligible.slice(0, 16),
400
+ ...(Object.keys(pins).length ? { pins } : {}),
401
+ };
369
402
  const teamFacts = teamView
370
- ? { team: teamView }
371
- : keepsTeams() && asked && mode() !== "local"
372
- ? { team: null, teamMembers: eligible.slice(0, 16) }
403
+ ? { team: teamView, ...(teamView.nextPiece ? routing : {}) }
404
+ : keepsTeams() && (asked || mode() === "local")
405
+ ? { team: null, ...routing }
373
406
  : {};
374
407
  // Earlier words close in meaning to the newest post that the transcript no longer carries, from this thread and the
375
408
  // person's sessions on this machine.
@@ -639,30 +672,48 @@ export function createCoordinator({
639
672
  });
640
673
  return other ?? agent;
641
674
  };
642
- // The team's part of a decision: a plan for a thread that had none, said in the thread.
643
- const applyTeamPlan = (thread, decision, coordinator) => {
675
+ // The route's part of a decision: one for a thread that had none, said in the thread. The person's tags and pins win
676
+ // over the proposal step by step (team.mjs validPlan).
677
+ const routeFor = (thread, coordinator, named = []) => ({
678
+ members: roster().map((card) => card.id),
679
+ named,
680
+ pins: pinsNow(),
681
+ by: coordinator,
682
+ post: (text) =>
683
+ postAsCoordinator({
684
+ goalId: thread.id,
685
+ author: coordinator,
686
+ kind: "note",
687
+ text,
688
+ }),
689
+ });
690
+ const applyTeamPlan = (thread, decision, coordinator, asked = null) => {
644
691
  const proposed = decision.team?.plan;
645
- if (!proposed || !keepsTeams() || team.plan(thread.id)) return null;
646
- const cards = roster();
647
- return team.set(thread.id, proposed, {
648
- members: cards.map((card) => card.id),
649
- tiers: Object.fromEntries(cards.map((card) => [card.id, card.tier])),
650
- by: coordinator,
651
- post: (text) =>
652
- postAsCoordinator({
653
- goalId: thread.id,
654
- author: coordinator,
655
- kind: "note",
656
- text,
657
- }),
658
- });
692
+ if (
693
+ !proposed ||
694
+ decision.team?.step === "piece" ||
695
+ !keepsTeams() ||
696
+ team.plan(thread.id)
697
+ )
698
+ return null;
699
+ return team.set(
700
+ thread.id,
701
+ proposed,
702
+ routeFor(thread, coordinator, asked?.named ?? [])
703
+ );
659
704
  };
660
- // Where the work went: along the route to the step the round chose, or, handed outside it, to the step of the agents
661
- // who now have it.
662
- const moveTeam = (thread, decision, agents) => {
705
+ // Where the work went: along the route to the step the round chose, on to the next piece as the round routed it, or,
706
+ // handed outside the route, to the step of the agents who now have it.
707
+ const moveTeam = (thread, decision, agents, coordinator) => {
663
708
  if (!keepsTeams()) return;
664
709
  const step = decision.team?.step;
665
- if (step && step !== "done")
710
+ if (step === "piece")
711
+ team.routePiece(thread.id, decision.team.plan, {
712
+ ...routeFor(thread, coordinator ?? thread.goal.facilitator),
713
+ outcome: decision.team.outcome ?? null,
714
+ head: headOf(thread.id),
715
+ });
716
+ else if (step && step !== "done")
666
717
  team.moveTo(thread.id, step, {
667
718
  outcome: decision.team.outcome ?? null,
668
719
  head: headOf(thread.id),
@@ -679,6 +730,55 @@ export function createCoordinator({
679
730
  });
680
731
  };
681
732
 
733
+ // Work routed to an agent the person pinned for the step's specialty waits while that agent works in another thread,
734
+ // and the thread says so (decision 14); it is handed on once the agent is free (releaseHeld, at every round).
735
+ const HELD = "pin-waits";
736
+ const heldWork = () => {
737
+ try {
738
+ return JSON.parse(store.meta(HELD) || "[]");
739
+ } catch {
740
+ return [];
741
+ }
742
+ };
743
+ const handOnOrHold = (thread, agent, reason, options, coordinator) => {
744
+ const step = keepsTeams() ? team.pinnedStep(thread.id, agent) : null;
745
+ if (!step || !store.busyElsewhere(agent, thread.id)) {
746
+ handOn(thread.id, agent, reason, options);
747
+ return;
748
+ }
749
+ store.meta(
750
+ HELD,
751
+ JSON.stringify([
752
+ ...heldWork(),
753
+ {
754
+ goalId: thread.id,
755
+ agent,
756
+ reason,
757
+ options,
758
+ at: new Date().toISOString(),
759
+ },
760
+ ])
761
+ );
762
+ postAsCoordinator({
763
+ goalId: thread.id,
764
+ author: coordinator,
765
+ kind: "note",
766
+ text: `The ${step.id} step waits for ${nameOf(agent)}, which you pinned for ${specialtyName(step.specialty)}: it is working in another thread, and starts on this when that work ends.`,
767
+ });
768
+ };
769
+ const releaseHeld = () => {
770
+ const waiting = heldWork();
771
+ if (!waiting.length) return;
772
+ const still = [];
773
+ for (const held of waiting) {
774
+ const thread = store.getTask(held.goalId);
775
+ if (!thread || thread.status !== "open") continue;
776
+ if (store.busyElsewhere(held.agent, held.goalId)) still.push(held);
777
+ else handOn(held.goalId, held.agent, held.reason, held.options);
778
+ }
779
+ store.meta(HELD, JSON.stringify(still));
780
+ };
781
+
682
782
  const apply = (
683
783
  thread,
684
784
  given,
@@ -690,7 +790,7 @@ export function createCoordinator({
690
790
  endRoute(thread, given);
691
791
  if (applyGoal(thread, given, coordinator)) return;
692
792
  applyCheckIn(thread, given, coordinator);
693
- const planned = applyTeamPlan(thread, given, coordinator);
793
+ const planned = applyTeamPlan(thread, given, coordinator, asked);
694
794
  const decision = guardQuestion(thread, given, candidates, rules);
695
795
  // The person's message is never met with silence: a round that brings no one in and asks them nothing lets the
696
796
  // agents hear it as they wrote it, as with `@swarm` (owner, October 16: "it should never be silent if jev doesnt
@@ -732,7 +832,8 @@ export function createCoordinator({
732
832
  );
733
833
  if (!parts.length) {
734
834
  if (unheard) tellEveryone(thread, asked, null, { decided: true });
735
- else if (planned) moveTeam(thread, decision, asked?.named ?? []);
835
+ else if (planned)
836
+ moveTeam(thread, decision, asked?.named ?? [], coordinator);
736
837
  notifyBoard(store.getTask(thread.id));
737
838
  return;
738
839
  }
@@ -763,16 +864,19 @@ export function createCoordinator({
763
864
  .join("\n\n"),
764
865
  });
765
866
  // The team moves first, so each brief says the step its agent now acts in.
766
- moveTeam(thread, decision, [
767
- ...worded.map((part) => part.agent),
768
- ...(asked?.named ?? []),
769
- ]);
867
+ moveTeam(
868
+ thread,
869
+ decision,
870
+ [...worded.map((part) => part.agent), ...(asked?.named ?? [])],
871
+ coordinator
872
+ );
770
873
  for (const part of worded)
771
- handOn(
772
- thread.id,
874
+ handOnOrHold(
875
+ thread,
773
876
  part.agent,
774
877
  `${coordinator} asked you: ${part.text.slice(0, 300)}`,
775
- { review: part.review, words: part.text }
878
+ { review: part.review, words: part.text },
879
+ coordinator
776
880
  );
777
881
  notifyBoard(store.getTask(thread.id));
778
882
  return;
@@ -809,12 +913,13 @@ export function createCoordinator({
809
913
  kind: "post",
810
914
  text: `@${agent} ${review ? "(review, no changes) " : ""}${text}`,
811
915
  });
812
- moveTeam(thread, decision, [agent]);
813
- handOn(
814
- thread.id,
916
+ moveTeam(thread, decision, [agent], coordinator);
917
+ handOnOrHold(
918
+ thread,
815
919
  agent,
816
920
  `${coordinator} asked you: ${text.slice(0, 300)}`,
817
- { review, words: text }
921
+ { review, words: text },
922
+ coordinator
818
923
  );
819
924
  }
820
925
  notifyBoard(store.getTask(thread.id));
@@ -871,6 +976,7 @@ export function createCoordinator({
871
976
  };
872
977
 
873
978
  const round = async (goalId) => {
979
+ releaseHeld();
874
980
  const thread = store.getTask(goalId);
875
981
  if (!thread || thread.kind !== "goal" || thread.status !== "open") return;
876
982
  const state = stateOf(goalId);