tryharness 0.7.53 → 0.7.57

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 (167) hide show
  1. package/README.md +23 -19
  2. package/assets/dsh-plugin.mjs +72 -0
  3. package/assets/opencode-plugin.js +4 -3
  4. package/cli.mjs +484 -90
  5. package/lib/activity.mjs +10 -10
  6. package/lib/adapters.mjs +173 -222
  7. package/lib/agentBinaries.mjs +71 -0
  8. package/lib/agentRuntimeConfig.mjs +1 -1
  9. package/lib/agentRuntimes.mjs +34 -18
  10. package/lib/agentSignIn.mjs +456 -0
  11. package/lib/answers.mjs +5 -5
  12. package/lib/archetypes.d.ts +64 -0
  13. package/lib/archetypes.js +989 -0
  14. package/lib/asks.mjs +4 -4
  15. package/lib/audit.mjs +666 -0
  16. package/lib/backupSetup.mjs +143 -0
  17. package/lib/boardAccess.mjs +24 -11
  18. package/lib/boardBackup.mjs +283 -0
  19. package/lib/boardFileCommands.mjs +6 -6
  20. package/lib/boardFiles.mjs +13 -12
  21. package/lib/boardMirror.mjs +124 -25
  22. package/lib/boardProtocol.json +88 -2
  23. package/lib/boardWaits.mjs +101 -0
  24. package/lib/book.mjs +659 -0
  25. package/lib/bridge.mjs +6 -6
  26. package/lib/cards.mjs +138 -28
  27. package/lib/cloudAgents.mjs +216 -0
  28. package/lib/cloudAi.mjs +1312 -0
  29. package/lib/cloudAssistants.mjs +242 -0
  30. package/lib/cloudBoot.mjs +119 -0
  31. package/lib/cloudSave.mjs +197 -0
  32. package/lib/cloudSsh.mjs +178 -0
  33. package/lib/commands.mjs +7 -2
  34. package/lib/context.mjs +19 -5
  35. package/lib/contractGate.mjs +399 -0
  36. package/lib/control-client.mjs +9 -1
  37. package/lib/controlSocket.mjs +86 -0
  38. package/lib/coordinator.mjs +252 -144
  39. package/lib/daemon.mjs +1351 -2767
  40. package/lib/desk.mjs +240 -0
  41. package/lib/desktop.mjs +178 -74
  42. package/lib/directLink.mjs +16 -5
  43. package/lib/environment.mjs +2 -1
  44. package/lib/environments.mjs +247 -9
  45. package/lib/firewall.mjs +9 -9
  46. package/lib/folders.mjs +20 -16
  47. package/lib/frames.mjs +2 -3
  48. package/lib/gitHost.mjs +174 -0
  49. package/lib/goalCommands.mjs +25 -7
  50. package/lib/goals.mjs +7 -7
  51. package/lib/guestRequests.mjs +94 -0
  52. package/lib/handoffs.mjs +8 -7
  53. package/lib/handover.mjs +4 -4
  54. package/lib/harnessModel.mjs +6 -6
  55. package/lib/harnessOffers.mjs +266 -0
  56. package/lib/hookDialects.mjs +298 -0
  57. package/lib/inference.mjs +26 -8
  58. package/lib/jobAnswers.mjs +190 -0
  59. package/lib/landed.mjs +887 -0
  60. package/lib/lane.mjs +42 -11
  61. package/lib/lessons.mjs +16 -16
  62. package/lib/library.mjs +3 -3
  63. package/lib/lineup.mjs +3 -0
  64. package/lib/linkRelay.mjs +574 -0
  65. package/lib/live.mjs +284 -13
  66. package/lib/localAgentAsk.mjs +74 -0
  67. package/lib/localStack.mjs +536 -0
  68. package/lib/localmodels.mjs +6 -4
  69. package/lib/loopBackstop.mjs +4 -4
  70. package/lib/machineIdentity.mjs +9 -1
  71. package/lib/machineRoutes.mjs +181 -2
  72. package/lib/machineRuns.mjs +76 -1
  73. package/lib/machineSeal.mjs +39 -12
  74. package/lib/mcp-stdio.mjs +163 -27
  75. package/lib/mcpRelay.mjs +1 -1
  76. package/lib/members.json +29 -2
  77. package/lib/members.mjs +1 -1
  78. package/lib/models.mjs +85 -31
  79. package/lib/museSession.mjs +21 -13
  80. package/lib/nativeHost.mjs +36 -8
  81. package/lib/neovim.mjs +126 -0
  82. package/lib/network.mjs +50 -5
  83. package/lib/notify.mjs +7 -5
  84. package/lib/nudge.mjs +50 -19
  85. package/lib/ocr.mjs +9 -9
  86. package/lib/onboard.mjs +26 -20
  87. package/lib/oneLine.mjs +7 -7
  88. package/lib/ownMachines.mjs +1223 -140
  89. package/lib/pairing.mjs +60 -16
  90. package/lib/paths.mjs +19 -1
  91. package/lib/peerProcess.mjs +124 -0
  92. package/lib/personModel.mjs +89 -0
  93. package/lib/personNotices.mjs +151 -0
  94. package/lib/phones.mjs +538 -31
  95. package/lib/placeCommands.mjs +4 -4
  96. package/lib/places.mjs +400 -12
  97. package/lib/profile.mjs +67 -14
  98. package/lib/projectGit.mjs +158 -14
  99. package/lib/projectPieces.mjs +902 -0
  100. package/lib/projectSettings.mjs +7 -4
  101. package/lib/projects.mjs +384 -62
  102. package/lib/provenance.mjs +5 -1
  103. package/lib/proxyLinks.mjs +267 -0
  104. package/lib/reactions.mjs +7 -5
  105. package/lib/readiness.mjs +145 -23
  106. package/lib/record.mjs +128 -0
  107. package/lib/redact.mjs +4 -4
  108. package/lib/relayLimits.mjs +62 -0
  109. package/lib/release.mjs +170 -0
  110. package/lib/releaseKeys.json +6 -0
  111. package/lib/repoLinks.mjs +4 -4
  112. package/lib/roomChannels.mjs +24 -0
  113. package/lib/roomPage.mjs +1 -1
  114. package/lib/runAuthority.mjs +101 -0
  115. package/lib/runBrief.mjs +19 -8
  116. package/lib/runWorker.mjs +31 -7
  117. package/lib/runner.mjs +223 -29
  118. package/lib/runtime-install.mjs +143 -9
  119. package/lib/schedules.mjs +2 -2
  120. package/lib/screens.mjs +1 -1
  121. package/lib/sealed.mjs +11 -2
  122. package/lib/sealedThreads.mjs +671 -0
  123. package/lib/secretPatterns.json +1 -1
  124. package/lib/secrets.mjs +4 -4
  125. package/lib/seen.mjs +6 -6
  126. package/lib/serverWords.mjs +175 -0
  127. package/lib/service.mjs +22 -12
  128. package/lib/sessionControl.mjs +378 -90
  129. package/lib/specialties.json +74 -0
  130. package/lib/specialties.mjs +477 -0
  131. package/lib/specialtyKeys.d.ts +3 -0
  132. package/lib/specialtyKeys.js +57 -0
  133. package/lib/specialtyNotice.mjs +147 -0
  134. package/lib/specialtySnapshot.mjs +138 -0
  135. package/lib/speech.mjs +5 -5
  136. package/lib/store.mjs +420 -36
  137. package/lib/stuck.mjs +1 -1
  138. package/lib/swarm.mjs +304 -37
  139. package/lib/swarmDevices.mjs +319 -0
  140. package/lib/swarmMemory.mjs +27 -25
  141. package/lib/t3.mjs +24 -15
  142. package/lib/taskCommands.mjs +80 -20
  143. package/lib/taskRooms.mjs +125 -0
  144. package/lib/taskRuns.mjs +45 -3
  145. package/lib/team.json +255 -148
  146. package/lib/team.mjs +554 -190
  147. package/lib/threadActions.mjs +315 -0
  148. package/lib/threadAuthority.mjs +101 -0
  149. package/lib/threadBriefs.mjs +178 -0
  150. package/lib/threadLine.mjs +116 -0
  151. package/lib/threadRuns.mjs +209 -50
  152. package/lib/threadView.mjs +20 -7
  153. package/lib/usageTotals.mjs +2 -3
  154. package/lib/vault.mjs +101 -10
  155. package/lib/vaultCloud.mjs +2 -2
  156. package/lib/vaultCommands.mjs +15 -6
  157. package/lib/vaultTools.js +2 -2
  158. package/lib/verdicts.mjs +328 -0
  159. package/lib/wakes.mjs +1 -1
  160. package/lib/watches.mjs +2 -2
  161. package/lib/windowAsks.mjs +13 -5
  162. package/lib/worktrees.mjs +157 -25
  163. package/npm-shrinkwrap.json +1093 -0
  164. package/package.json +12 -11
  165. package/release.json +220 -0
  166. package/lib/modelTiers.json +0 -1183
  167. package/lib/modelTiers.mjs +0 -133
@@ -0,0 +1,74 @@
1
+ {
2
+ "version": 1,
3
+ "headings": [
4
+ {
5
+ "id": "general",
6
+ "name": "General",
7
+ "specialties": [
8
+ { "id": "planning", "name": "planning and coordination" },
9
+ { "id": "computer-use", "name": "browser and computer use" },
10
+ { "id": "summarizing", "name": "summarizing" },
11
+ { "id": "everyday-questions", "name": "everyday questions" }
12
+ ]
13
+ },
14
+ {
15
+ "id": "software",
16
+ "name": "Software",
17
+ "specialties": [
18
+ { "id": "building-features", "name": "building features" },
19
+ { "id": "debugging", "name": "debugging" },
20
+ { "id": "code-review", "name": "code review" },
21
+ { "id": "testing", "name": "testing" },
22
+ { "id": "frontend", "name": "frontend and UI" },
23
+ { "id": "infrastructure", "name": "infrastructure and terminal work" },
24
+ { "id": "data-sql", "name": "data and SQL" }
25
+ ]
26
+ },
27
+ {
28
+ "id": "onchain",
29
+ "name": "Onchain",
30
+ "specialties": [
31
+ { "id": "onchain-trading", "name": "onchain trading" },
32
+ { "id": "market-analysis", "name": "market analysis" },
33
+ { "id": "prediction-markets", "name": "prediction markets" },
34
+ { "id": "defi", "name": "DeFi" },
35
+ { "id": "nfts", "name": "NFTs" },
36
+ { "id": "smart-contracts", "name": "smart contracts" },
37
+ { "id": "portfolio-risk", "name": "portfolio and risk watching" }
38
+ ]
39
+ },
40
+ {
41
+ "id": "content",
42
+ "name": "Content generation",
43
+ "specialties": [
44
+ { "id": "creative-direction", "name": "creative direction" },
45
+ { "id": "images", "name": "images" },
46
+ { "id": "video", "name": "video" },
47
+ { "id": "audio", "name": "voice and audio" },
48
+ { "id": "design-mockups", "name": "design mockups" },
49
+ { "id": "media-editing", "name": "media editing" }
50
+ ]
51
+ },
52
+ {
53
+ "id": "writing",
54
+ "name": "Writing and editing",
55
+ "specialties": [
56
+ { "id": "long-form", "name": "long-form drafting" },
57
+ { "id": "marketing-copy", "name": "marketing copy" },
58
+ { "id": "social-posts", "name": "social posts" },
59
+ { "id": "editing", "name": "editing and proofreading" }
60
+ ]
61
+ },
62
+ {
63
+ "id": "research",
64
+ "name": "Research",
65
+ "specialties": [
66
+ { "id": "web-research", "name": "web research" },
67
+ { "id": "x-research", "name": "X and social research" },
68
+ { "id": "papers", "name": "papers and technical sources" },
69
+ { "id": "data-analysis", "name": "data analysis" },
70
+ { "id": "synthesis", "name": "synthesis" }
71
+ ]
72
+ }
73
+ ]
74
+ }
@@ -0,0 +1,477 @@
1
+ import { readFileSync } from "node:fs";
2
+ import { MEMBERS, member, nameOf } from "./members.mjs";
3
+ import { effortKey, modelKey } from "./specialtyKeys.js";
4
+ import { earned, recordFor } from "./record.mjs";
5
+ import { snapshotFor } from "./specialtySnapshot.mjs";
6
+
7
+ // What each agent, on its model, is shown to do well, and the person's standing choices about it: their specialties,
8
+ // pins and appointments. A specialty comes from four sources: the agent's fixed role (only specialist agents have one,
9
+ // declared in members.json), the benchmark snapshot for its model, its record on this board, and the person. Nothing
10
+ // here ranks one agent above another: each specialty carries its evidence, and the record corrects a claim instead of
11
+ // deleting it.
12
+
13
+ const LIST = JSON.parse(
14
+ readFileSync(new URL("./specialties.json", import.meta.url), "utf8")
15
+ );
16
+
17
+ /** Every specialty in the list's order: `{ id, name, heading }`, heading being its archetype's id. */
18
+ export const SPECIALTIES = LIST.headings.flatMap((heading) =>
19
+ heading.specialties.map((specialty) => ({
20
+ id: specialty.id,
21
+ name: specialty.name,
22
+ heading: heading.id,
23
+ }))
24
+ );
25
+ const byId = new Map(SPECIALTIES.map((specialty) => [specialty.id, specialty]));
26
+ const HEADINGS = new Map(
27
+ LIST.headings.map((heading) => [
28
+ heading.id,
29
+ { id: heading.id, name: heading.name },
30
+ ])
31
+ );
32
+
33
+ /** A specialty's name as cards and the Swarm map show it ("code review"), or null for an id not on the list. */
34
+ export const specialtyName = (id) => byId.get(id)?.name ?? null;
35
+ /** The archetype heading a specialty sits under: `{ id, name }`, or null. */
36
+ export const headingOf = (id) => HEADINGS.get(byId.get(id)?.heading) ?? null;
37
+
38
+ const fixedRoleOf = (agent) => {
39
+ const fixed = member(agent)?.fixedRole;
40
+ return fixed && byId.has(fixed.specialty) ? fixed : null;
41
+ };
42
+ // The agent whose fixed role executes a specialty's work, as Bankr executes onchain trading: no other agent holds it.
43
+ const executorOf = (specialty) =>
44
+ MEMBERS.find(
45
+ (entry) =>
46
+ entry.fixedRole?.role === "executor" &&
47
+ entry.fixedRole.specialty === specialty
48
+ )?.id ?? null;
49
+ const executesOnchain = (agent) => {
50
+ const fixed = fixedRoleOf(agent);
51
+ return (
52
+ fixed?.role === "executor" && headingOf(fixed.specialty)?.id === "onchain"
53
+ );
54
+ };
55
+
56
+ const MONTHS = [
57
+ "Jan",
58
+ "Feb",
59
+ "Mar",
60
+ "Apr",
61
+ "May",
62
+ "Jun",
63
+ "Jul",
64
+ "Aug",
65
+ "Sep",
66
+ "Oct",
67
+ "Nov",
68
+ "Dec",
69
+ ];
70
+ const monthOf = (iso) => {
71
+ const date = new Date(iso);
72
+ return Number.isNaN(date.getTime())
73
+ ? null
74
+ : `${MONTHS[date.getUTCMonth()]} ${date.getUTCFullYear()}`;
75
+ };
76
+ const benchmarkEvidence = (entry) => {
77
+ const month = monthOf(entry.takenAt);
78
+ return month ? `${entry.source}, ${month}` : String(entry.source);
79
+ };
80
+ const acceptedHere = (record, model) =>
81
+ `${record.accepted} of ${record.judged} accepted here${model ? ` on ${model}` : ""}`;
82
+
83
+ // Sources in the order a specialty's evidence names them; the person's own add counts last, as it brings no evidence.
84
+ const SOURCE_ORDER = ["fixed", "record", "benchmark", "person"];
85
+
86
+ /**
87
+ * The rules that turn what each source says into an agent's specialty views, primary first. Pure: specialtiesOf gathers
88
+ * the inputs. `model` is the model key the person's choices are kept under (specialtyKeys.js modelKey).
89
+ *
90
+ * - A fixed role is always carried. The person's add is carried until they remove it.
91
+ * - The person's removal is final for that agent and model: the snapshot and the record on it never bring it back, and
92
+ * what the agent earned on another model stops carrying over.
93
+ * - What the agent earned on an earlier model stays with it ("earnedOn"); its record here restarts.
94
+ * - A benchmark specialty the snapshot no longer gives stays, marked `unsupported`, for the person to keep or remove.
95
+ * - The primary is the person's pick; else the fixed role; else the most accepted work in the record; else the best
96
+ * benchmark score; else the first carried.
97
+ */
98
+ export function resolveSpecialties({
99
+ model = "",
100
+ fixed = null,
101
+ benchmarks = [],
102
+ seen = [],
103
+ record = new Map(),
104
+ earnedHere = [],
105
+ carried = [],
106
+ choices = [],
107
+ primary = null,
108
+ }) {
109
+ const removedHere = new Set(
110
+ choices
111
+ .filter((row) => row.choice === "remove" && row.model === model)
112
+ .map((row) => row.specialty)
113
+ );
114
+ const removedAnywhere = new Set(
115
+ choices.filter((row) => row.choice === "remove").map((row) => row.specialty)
116
+ );
117
+ const added = new Set(
118
+ choices.filter((row) => row.choice === "add").map((row) => row.specialty)
119
+ );
120
+ const benchmarked = new Map();
121
+ for (const entry of benchmarks)
122
+ benchmarked.set(entry.specialty, [
123
+ ...(benchmarked.get(entry.specialty) ?? []),
124
+ entry,
125
+ ]);
126
+ const dropped = new Map(
127
+ seen
128
+ .filter((entry) => !benchmarked.has(entry.specialty))
129
+ .map((entry) => [entry.specialty, entry.source])
130
+ );
131
+ const earnedSet = new Set(earnedHere);
132
+ const carriedOver = new Map();
133
+ for (const entry of carried)
134
+ if (
135
+ !earnedSet.has(entry.specialty) &&
136
+ !removedAnywhere.has(entry.specialty) &&
137
+ !carriedOver.has(entry.specialty)
138
+ )
139
+ carriedOver.set(entry.specialty, entry);
140
+
141
+ const views = [];
142
+ for (const { id, name } of SPECIALTIES) {
143
+ const isFixed = id === fixed;
144
+ const isAdded = added.has(id);
145
+ const kept = isFixed || isAdded || !removedHere.has(id);
146
+ const fromRecord = earnedSet.has(id) || carriedOver.has(id);
147
+ const fromBenchmark = benchmarked.has(id);
148
+ const wasBenchmarked = dropped.has(id);
149
+ if (
150
+ !kept ||
151
+ !(isFixed || isAdded || fromRecord || fromBenchmark || wasBenchmarked)
152
+ )
153
+ continue;
154
+ const here = record.get(id) ?? null;
155
+ const over = carriedOver.get(id);
156
+ const evidence = [
157
+ ...(isFixed ? ["its fixed role"] : []),
158
+ ...(benchmarked.get(id) ?? []).map(benchmarkEvidence),
159
+ ...(here?.judged ? [acceptedHere(here)] : []),
160
+ ...(over?.record?.judged ? [acceptedHere(over.record, over.model)] : []),
161
+ ];
162
+ // Kept by the person, a benchmark that no longer supports it is theirs now and is not marked.
163
+ const unsupported =
164
+ wasBenchmarked && !isAdded && !isFixed && !fromRecord && !fromBenchmark
165
+ ? `no longer supported by ${dropped.get(id)}`
166
+ : null;
167
+ if (unsupported) evidence.push(unsupported);
168
+ if (!evidence.length && isAdded) evidence.push("added by the person");
169
+ if (over && !evidence.some((text) => text.endsWith(` on ${over.model}`)))
170
+ evidence.push(`earned here on ${over.model}`);
171
+ const source = isFixed
172
+ ? "fixed"
173
+ : fromRecord
174
+ ? "record"
175
+ : fromBenchmark
176
+ ? "benchmark"
177
+ : isAdded
178
+ ? "person"
179
+ : "benchmark";
180
+ views.push({
181
+ id,
182
+ name,
183
+ source,
184
+ evidence: evidence.join("; "),
185
+ primary: false,
186
+ record: here,
187
+ ...(unsupported ? { unsupported } : {}),
188
+ ...(over ? { earnedOn: over.model } : {}),
189
+ });
190
+ }
191
+
192
+ const carriedIds = new Set(views.map((view) => view.id));
193
+ const acceptedOf = (view) =>
194
+ view.record?.accepted ?? carriedOver.get(view.id)?.record?.accepted ?? 0;
195
+ const mostAccepted = views
196
+ .filter((view) => view.source === "record" && acceptedOf(view) > 0)
197
+ .sort((a, b) => acceptedOf(b) - acceptedOf(a))[0]?.id;
198
+ const bestBenchmark = benchmarks
199
+ .filter((entry) => carriedIds.has(entry.specialty))
200
+ .map((entry, index) => ({ entry, index }))
201
+ .sort(
202
+ (a, b) =>
203
+ (Number(b.entry.score) || 0) - (Number(a.entry.score) || 0) ||
204
+ a.index - b.index
205
+ )[0]?.entry.specialty;
206
+ const primaryId =
207
+ (primary && carriedIds.has(primary) ? primary : null) ??
208
+ (fixed && carriedIds.has(fixed) ? fixed : null) ??
209
+ mostAccepted ??
210
+ bestBenchmark ??
211
+ views[0]?.id;
212
+ const rank = (view) =>
213
+ view.id === primaryId
214
+ ? -1
215
+ : view.unsupported
216
+ ? SOURCE_ORDER.length
217
+ : SOURCE_ORDER.indexOf(view.source);
218
+ return views
219
+ .map((view) => ({ ...view, primary: view.id === primaryId }))
220
+ .sort((a, b) => rank(a) - rank(b));
221
+ }
222
+
223
+ /**
224
+ * An agent's specialties on the model and effort it runs on now, primary first: `{ id, name, source, evidence, primary,
225
+ * record, unsupported?, earnedOn? }`. `harness` is the agent the model runs in, for benchmarks that score the two
226
+ * together; it defaults to the agent itself. Reading a card notes the snapshot's specialties for the agent once, so a
227
+ * later snapshot that drops one leaves it marked rather than gone.
228
+ */
229
+ export function specialtiesOf(
230
+ store,
231
+ agentId,
232
+ { model = null, effort = null, harness = null } = {}
233
+ ) {
234
+ const key = modelKey(model);
235
+ const level = effortKey(effort) ?? "";
236
+ const benchmarks = model
237
+ ? snapshotFor({
238
+ harness: harness ?? agentId,
239
+ model,
240
+ effort: effortKey(effort),
241
+ }).filter((entry) => byId.has(entry.specialty))
242
+ : [];
243
+ if (benchmarks.length) store.noteBenchmarks(agentId, key, level, benchmarks);
244
+ const carried = store
245
+ .runModels(agentId)
246
+ .filter((other) => modelKey(other) !== key)
247
+ .flatMap((other) => {
248
+ const otherRecord = recordFor(store, agentId, other);
249
+ return earned(store, agentId, other).map((specialty) => ({
250
+ specialty,
251
+ model: other,
252
+ record: otherRecord.get(specialty) ?? null,
253
+ }));
254
+ });
255
+ return resolveSpecialties({
256
+ model: key,
257
+ fixed: fixedRoleOf(agentId)?.specialty ?? null,
258
+ benchmarks,
259
+ seen: model ? store.benchmarksSeen(agentId, key, level) : [],
260
+ record: model ? recordFor(store, agentId, model) : new Map(),
261
+ earnedHere: model ? earned(store, agentId, model) : [],
262
+ carried,
263
+ choices: store.specialtyChoices(agentId),
264
+ primary: store.primarySpecialty(agentId),
265
+ });
266
+ }
267
+
268
+ const refuse = (error) => ({ ok: false, error });
269
+ const unknownSpecialty = (id) =>
270
+ refuse(`"${id}" is not a specialty Harness knows`);
271
+ const unknownAgent = (id) => refuse(`no agent called "${id}"`);
272
+
273
+ /** The person adds a specialty to an agent; it stays until they remove it, whatever model the agent moves to. */
274
+ export function addSpecialty(store, agentId, specialtyId, model = null) {
275
+ if (!member(agentId)) return unknownAgent(agentId);
276
+ if (!byId.has(specialtyId)) return unknownSpecialty(specialtyId);
277
+ store.setSpecialtyChoice({
278
+ agent: agentId,
279
+ model: modelKey(model),
280
+ specialty: specialtyId,
281
+ choice: "add",
282
+ });
283
+ return { ok: true };
284
+ }
285
+
286
+ /**
287
+ * The person removes a specialty from an agent on its model. Final for that agent and model: no snapshot or record puts
288
+ * it back. A fixed role is not removed: it is the one kind of work the agent exists for.
289
+ */
290
+ export function removeSpecialty(store, agentId, specialtyId, model = null) {
291
+ if (!member(agentId)) return unknownAgent(agentId);
292
+ if (!byId.has(specialtyId)) return unknownSpecialty(specialtyId);
293
+ if (fixedRoleOf(agentId)?.specialty === specialtyId)
294
+ return refuse(
295
+ `${specialtyName(specialtyId)} is ${nameOf(agentId)}'s fixed role, the one kind of work it exists for, so it stays`
296
+ );
297
+ store.setSpecialtyChoice({
298
+ agent: agentId,
299
+ model: modelKey(model),
300
+ specialty: specialtyId,
301
+ choice: "remove",
302
+ });
303
+ if (store.primarySpecialty(agentId) === specialtyId)
304
+ store.setPrimarySpecialty(agentId, null);
305
+ return { ok: true };
306
+ }
307
+
308
+ /** The person's pick of an agent's primary specialty, which it then carries too; null goes back to the rule's. */
309
+ export function setPrimary(store, agentId, specialtyId, model = null) {
310
+ if (!member(agentId)) return unknownAgent(agentId);
311
+ if (specialtyId === null) {
312
+ store.setPrimarySpecialty(agentId, null);
313
+ return { ok: true };
314
+ }
315
+ const added = addSpecialty(store, agentId, specialtyId, model);
316
+ if (!added.ok) return added;
317
+ store.setPrimarySpecialty(agentId, specialtyId);
318
+ return { ok: true };
319
+ }
320
+
321
+ /** The person's pins: who holds each pinned specialty when a step asks for it, `[{ specialty, name, agent }]`. */
322
+ export const pins = (store) =>
323
+ store
324
+ .pins()
325
+ .filter((row) => byId.has(row.specialty))
326
+ .map((row) => ({
327
+ specialty: row.specialty,
328
+ name: specialtyName(row.specialty),
329
+ agent: row.agent,
330
+ }));
331
+
332
+ /** The agent pinned for a specialty, or null when the person pinned none. */
333
+ export const pinnedFor = (store, specialtyId) =>
334
+ pins(store).find((pin) => pin.specialty === specialtyId)?.agent ?? null;
335
+
336
+ // An agent that can hold a pin or an office: one of the person's agents that work can be handed to.
337
+ const holderError = (agentId) => {
338
+ const entry = member(agentId);
339
+ if (!entry) return `no agent called "${agentId}"`;
340
+ if (!entry.target)
341
+ return `${entry.name} cannot be handed work, so it cannot hold this`;
342
+ return null;
343
+ };
344
+
345
+ /** The person pins an agent for a specialty, or takes the pin off with null. */
346
+ export function setPin(store, specialtyId, agentId) {
347
+ if (!byId.has(specialtyId)) return unknownSpecialty(specialtyId);
348
+ if (agentId === null) {
349
+ store.setPin(specialtyId, null);
350
+ return { ok: true, pins: pins(store) };
351
+ }
352
+ const notHolder = holderError(agentId);
353
+ if (notHolder) return refuse(notHolder);
354
+ const executor = executorOf(specialtyId);
355
+ if (executor && executor !== agentId)
356
+ return refuse(
357
+ `${nameOf(executor)} is the only agent that executes ${specialtyName(specialtyId)}: it is its fixed role`
358
+ );
359
+ store.setPin(specialtyId, agentId);
360
+ return { ok: true, pins: pins(store) };
361
+ }
362
+
363
+ // The swarm's offices, its standing functions. `harness`: Harness holds it until the person appoints an agent;
364
+ // `jev`: Harness's Jev always holds it and no agent is appointed to it.
365
+ const OFFICES = [
366
+ {
367
+ id: "dispatcher",
368
+ name: "dispatcher",
369
+ holds:
370
+ "triage (how careful each goal and piece must be, whether it needs framing) and routing (who holds each step)",
371
+ byDefault: "Harness (Jev), always",
372
+ jev: true,
373
+ },
374
+ {
375
+ id: "auditor",
376
+ name: "auditor",
377
+ holds:
378
+ "whether work said to be done was done, across threads, the dispatcher's routing included",
379
+ byDefault:
380
+ "code checks every report; each week, until the person appoints one, an agent on this computer that was not among the week's main makers or on their models",
381
+ },
382
+ {
383
+ id: "clerk",
384
+ name: "clerk",
385
+ holds:
386
+ "the record of decisions, swarm memory and what each handoff carries",
387
+ byDefault: "Harness (the board, swarm memory, lessons)",
388
+ harness: true,
389
+ },
390
+ {
391
+ id: "treasurer",
392
+ name: "treasurer",
393
+ holds:
394
+ "the desk's book: balance sheet, positions and why each was opened, strategies, decisions, research, reconciliation",
395
+ byDefault:
396
+ "routed each time to an agent carrying portfolio and risk watching",
397
+ },
398
+ {
399
+ id: "gatekeeper",
400
+ name: "gatekeeper",
401
+ holds:
402
+ "what enters the swarm, what leaves it, and what agents pass each other from outside content",
403
+ byDefault: "Harness (its firewall and the privacy lane)",
404
+ harness: true,
405
+ },
406
+ {
407
+ id: "liaison",
408
+ name: "liaison",
409
+ holds: "what reaches the person, and when",
410
+ byDefault: "Harness (Jev), always",
411
+ jev: true,
412
+ },
413
+ {
414
+ id: "standards-keeper",
415
+ name: "standards keeper",
416
+ holds:
417
+ "turning what the person says repeatedly into rules, and keeping specialties current",
418
+ byDefault: "Harness (lessons, dreaming, the weekly specialty job)",
419
+ harness: true,
420
+ },
421
+ ];
422
+ const officeById = new Map(OFFICES.map((office) => [office.id, office]));
423
+
424
+ /**
425
+ * Every office and who holds it: `[{ id, name, holds, holder, appointed, byDefault, appointable }]`. `holder` is the
426
+ * appointed agent, else "harness" for an office Harness holds by default, else null.
427
+ */
428
+ export function offices(store) {
429
+ const appointed = new Map(
430
+ store.appointments().map((row) => [row.office, row.agent])
431
+ );
432
+ return OFFICES.map((office) => {
433
+ const agent = office.jev ? null : (appointed.get(office.id) ?? null);
434
+ return {
435
+ id: office.id,
436
+ name: office.name,
437
+ holds: office.holds,
438
+ holder: agent ?? (office.jev || office.harness ? "harness" : null),
439
+ appointed: Boolean(agent),
440
+ byDefault: office.byDefault,
441
+ appointable: !office.jev,
442
+ };
443
+ });
444
+ }
445
+
446
+ /**
447
+ * The person appoints an agent to an office, or null for its default. Refused, with the reason, where the rules forbid
448
+ * it: the dispatcher and the liaison are always Jev's; the dispatcher is never the auditor; whoever executes onchain
449
+ * never keeps its own book.
450
+ */
451
+ export function appoint(store, officeId, agentId) {
452
+ const office = officeById.get(officeId);
453
+ if (!office)
454
+ return refuse(
455
+ `no office called "${officeId}"; the offices are ${OFFICES.map((each) => each.name).join(", ")}`
456
+ );
457
+ if (office.jev)
458
+ return refuse(
459
+ `The ${office.name} is always Harness (Jev): no agent is appointed to it`
460
+ );
461
+ if (agentId === null || (agentId === "harness" && office.harness)) {
462
+ store.setAppointment(office.id, null);
463
+ return { ok: true, offices: offices(store) };
464
+ }
465
+ const notHolder = holderError(agentId);
466
+ if (notHolder) return refuse(notHolder);
467
+ if (office.id === "auditor" && agentId === "harness")
468
+ return refuse(
469
+ "The auditor checks the dispatcher's routing, and Harness (Jev) is the dispatcher: appoint another agent"
470
+ );
471
+ if (office.id === "treasurer" && executesOnchain(agentId))
472
+ return refuse(
473
+ `${nameOf(agentId)} executes onchain, and whoever executes never keeps its own book: appoint another agent as treasurer`
474
+ );
475
+ store.setAppointment(office.id, agentId);
476
+ return { ok: true, offices: offices(store) };
477
+ }
@@ -0,0 +1,3 @@
1
+ export declare function modelKey(name: unknown): string;
2
+ export declare const EFFORTS: readonly string[];
3
+ export declare function effortKey(effort: unknown): string | null;
@@ -0,0 +1,57 @@
1
+ // One spelling for a model and an effort, so the server's weekly specialty job and the relay's copy of its snapshot
2
+ // (specialtySnapshot.mjs) name the same model the same way. Leaderboards write "Claude Opus 4.7" or "GPT-5.5 (high)",
3
+ // an agent's settings "claude-opus-4-7[1m]" or "openai/gpt-5.5", Harness's catalog "venice/claude-opus-4-7"; all of
4
+ // them become one key. Plain JavaScript so the app and the published cli/ share it.
5
+
6
+ // Vendor names some ids carry in front of the model's own name ("zai-org-glm-5-1", "openai-gpt-5.5").
7
+ const VENDOR_PREFIX =
8
+ /^(?:zai-org|z-ai|openai|anthropic|google|x-ai|xai|meta-llama|deepseek-ai|moonshotai|mistralai|dot)-/;
9
+
10
+ /** A model's comparable key: no provider, vendor, context mark, ":free", release date or effort in parentheses. */
11
+ export function modelKey(name) {
12
+ const lowered = String(name ?? "")
13
+ .trim()
14
+ .toLowerCase();
15
+ const own = lowered.split("/").pop() ?? "";
16
+ const bare = own
17
+ .replace(/\[[^\]]*\]$/, "")
18
+ .replace(/:[a-z0-9-]+$/, "")
19
+ .replace(/\s*\([^)]*\)\s*$/, "");
20
+ const dashed = bare
21
+ .replace(/[\s._]+/g, "-")
22
+ .replace(/-+/g, "-")
23
+ .replace(/^-|-$/g, "");
24
+ const undated = dashed.replace(/-20\d{6}$/, "").replace(VENDOR_PREFIX, "");
25
+ // "qwen-3-7-max" and "qwen3.7 max" are one model: a letter and the number after it are written together.
26
+ return undated.replace(/([a-z])-(\d)/g, "$1$2");
27
+ }
28
+
29
+ // Lowest first, as the agents' own settings name them.
30
+ export const EFFORTS = [
31
+ "none",
32
+ "minimal",
33
+ "low",
34
+ "medium",
35
+ "high",
36
+ "xhigh",
37
+ "max",
38
+ ];
39
+ // What the agents and leaderboards call the same settings.
40
+ const EFFORT_NAMES = {
41
+ off: "none",
42
+ "non-reasoning": "none",
43
+ "no reasoning": "none",
44
+ "extra high": "xhigh",
45
+ "extra-high": "xhigh",
46
+ "x-high": "xhigh",
47
+ maximum: "max",
48
+ };
49
+
50
+ /** An effort's one name, or null when none is named or the name is not an effort. */
51
+ export function effortKey(effort) {
52
+ const named = String(effort ?? "")
53
+ .trim()
54
+ .toLowerCase();
55
+ const level = EFFORT_NAMES[named] ?? named;
56
+ return EFFORTS.includes(level) ? level : null;
57
+ }