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,147 @@
1
+ import { readFileSync } from "node:fs";
2
+ import { nameOf } from "./members.mjs";
3
+ import { notifyDesktop } from "./notify.mjs";
4
+ import { underperforming as fromRecord } from "./record.mjs";
5
+
6
+ // When an agent is not living up to a specialty it carries (docs/swarm-organization.md): three or more runs with a
7
+ // verdict in it on its model, more rejected than accepted. The liaison tells the person once per agent, specialty and
8
+ // model, in the facts: a needs-you item of kind "agent" that opens the agent in the Swarm map, a notice on this
9
+ // computer and one on their phone. The item waits until the person keeps the specialty or removes it; the notice is
10
+ // never sent again for the same agent, specialty and model, kept or not.
11
+
12
+ const LIST = JSON.parse(
13
+ readFileSync(new URL("./specialties.json", import.meta.url), "utf8")
14
+ );
15
+ const NAMES = new Map(
16
+ LIST.headings.flatMap((heading) =>
17
+ heading.specialties.map((specialty) => [specialty.id, specialty.name])
18
+ )
19
+ );
20
+
21
+ // How often the record is read again for a step down. A verdict changes the record a few times a day at most.
22
+ const CHECK_EVERY_MS = 60_000;
23
+
24
+ // An item's id names the agent, specialty and model, in the characters a phone notice's address allows
25
+ // (src/server/runtime/pushSender.ts).
26
+ const idPart = (text) => String(text).replace(/[^a-zA-Z0-9._-]/g, "_");
27
+ export const noticeIdOf = ({ agent, specialty, model }) =>
28
+ `agent:${idPart(agent)}:${idPart(specialty)}:${idPart(model)}`;
29
+
30
+ // "flint-local/flint" reads "flint": the model, not the provider it is reached through.
31
+ const modelName = (model) => String(model).split("/").at(-1);
32
+
33
+ /** The facts, as every surface says them: "Pi has had 1 of 4 debugging runs accepted on flint. Keep its …?" */
34
+ export function noticeWords({ agent, model, specialty, accepted, judged }) {
35
+ const name = NAMES.get(specialty) ?? specialty;
36
+ return `${nameOf(agent)} has had ${accepted} of ${judged} ${name} runs accepted on ${modelName(model)}. Keep its ${name} specialty?`;
37
+ }
38
+
39
+ export function createSpecialtyNotice({
40
+ store,
41
+ log = () => {},
42
+ // The record's step downs (record.mjs).
43
+ underperforming = fromRecord,
44
+ // Whether the agent still carries the specialty on that model: one the person removed waits on nobody.
45
+ carries = () => true,
46
+ // A notice on this computer: the daemon's, which the buddy posts itself while it runs, so a click opens the item
47
+ // ("agent:<id>" opens the agent in the Swarm map).
48
+ desktop = (title, line) => notifyDesktop(`${title}: ${line}`),
49
+ // Whether this computer may show a notice now (the person's notifications on, the lid not closed).
50
+ speaks = () => true,
51
+ // A message to Harness's server for the person's phone: ids only, never words.
52
+ phone = () => {},
53
+ now = () => new Date(),
54
+ }) {
55
+ /** Said once: on this computer in words, and to the phone as only the kind, the agent and the item. */
56
+ function tell(item) {
57
+ if (speaks())
58
+ desktop("Your swarm", item.text, `agent:${item.agent}`, item.id);
59
+ phone({
60
+ type: "needs_you",
61
+ kind: "agent",
62
+ agent: item.agent,
63
+ item: item.id,
64
+ });
65
+ }
66
+
67
+ const keptKey = (id) => `specialty-kept:${id}`;
68
+ const toldKey = (id) => `told:${id}`;
69
+
70
+ /** Each step down the person has not answered, as a needs-you item. */
71
+ function current() {
72
+ let found = [];
73
+ try {
74
+ found = underperforming(store);
75
+ } catch (error) {
76
+ log(`specialty notice: the record could not be read: ${error.message}`);
77
+ }
78
+ return found
79
+ .filter((step) => carries(step.agent, step.model, step.specialty))
80
+ .map((step) => {
81
+ const id = noticeIdOf(step);
82
+ return {
83
+ id,
84
+ kind: "agent",
85
+ agent: step.agent,
86
+ specialty: step.specialty,
87
+ specialtyName: NAMES.get(step.specialty) ?? step.specialty,
88
+ model: step.model,
89
+ accepted: step.accepted,
90
+ judged: step.judged,
91
+ text: noticeWords(step),
92
+ at: store.meta(toldKey(id)) || now().toISOString(),
93
+ };
94
+ })
95
+ .filter((item) => !store.meta(keptKey(item.id)));
96
+ }
97
+
98
+ /** Tells each step down not told before; marked told first, so a failure to say it never says it twice. */
99
+ function check() {
100
+ for (const item of current()) {
101
+ if (store.meta(toldKey(item.id))) continue;
102
+ store.meta(toldKey(item.id), item.at);
103
+ try {
104
+ tell(item);
105
+ } catch (error) {
106
+ log(`specialty notice: ${item.id} not told: ${error.message}`);
107
+ }
108
+ }
109
+ }
110
+
111
+ /** The person keeps the specialty: the item goes, and the notice is not sent again. Only the person answers. */
112
+ function command(request, agent) {
113
+ if (agent !== "user")
114
+ return {
115
+ ok: false,
116
+ error: "only the person keeps or removes an agent's specialty",
117
+ };
118
+ const id = String(request.item || "");
119
+ if (request.answer !== "keep")
120
+ return {
121
+ ok: false,
122
+ error:
123
+ 'answer "keep"; to remove the specialty, remove it from the agent in the Swarm map',
124
+ };
125
+ const item = current().find((each) => each.id === id);
126
+ if (!item) return { ok: false, error: "that is no longer waiting on you" };
127
+ store.meta(keptKey(id), now().toISOString());
128
+ return { ok: true, item: id };
129
+ }
130
+
131
+ let timer = null;
132
+ return {
133
+ /** What waits on the person now, oldest first. */
134
+ needs: () => current().sort((a, b) => a.at.localeCompare(b.at)),
135
+ check,
136
+ command,
137
+ start() {
138
+ check();
139
+ timer ??= setInterval(check, CHECK_EVERY_MS);
140
+ timer.unref?.();
141
+ },
142
+ stop() {
143
+ clearInterval(timer);
144
+ timer = null;
145
+ },
146
+ };
147
+ }
@@ -0,0 +1,138 @@
1
+ import { effortKey, modelKey } from "./specialtyKeys.js";
2
+
3
+ // What public benchmarks show each agent's model does well, as Harness's server last sent it: the weekly specialty job's
4
+ // snapshot (src/server/specialties/), fetched with the `specialties` bridge message when the server connects and once a
5
+ // day, the way harnessModel.mjs fetches Harness's catalog. The last good copy is kept in the board's meta, so a relay
6
+ // that cannot reach Harness still reads it, and a server with no snapshot or a failed fetch never empties it.
7
+ //
8
+ // The snapshot keeps results for a harness and model together and for the model alone; reading it for an agent prefers
9
+ // the agent's own harness, then the model alone (docs/swarm-organization.md, "The weekly job").
10
+
11
+ const STORE_KEY = "specialty-snapshot";
12
+ const DAY_MS = 24 * 60 * 60 * 1000;
13
+
14
+ const parsed = (text) => {
15
+ try {
16
+ return JSON.parse(text || "null");
17
+ } catch {
18
+ return null;
19
+ }
20
+ };
21
+
22
+ const isSnapshot = (value) =>
23
+ Boolean(value) &&
24
+ Number.isFinite(value.version) &&
25
+ Array.isArray(value.entries) &&
26
+ Array.isArray(value.sources);
27
+
28
+ // The relay's one snapshot, for readers that have no handle on it (specialties.mjs reads it through snapshotFor).
29
+ let current = null;
30
+
31
+ /**
32
+ * `ask()` sends the `specialties` bridge message and resolves with Harness's answer ({ ok, list, snapshot }), or with
33
+ * null when this Harness does not offer it (an older server, or not connected).
34
+ */
35
+ export function createSpecialtySnapshot({ ask, store, log }) {
36
+ /** { at, list, snapshot } as last fetched, plus the last fetch's error. */
37
+ let copy = parsed(store.meta(STORE_KEY));
38
+
39
+ const keep = (next) => {
40
+ copy = next;
41
+ store.meta(STORE_KEY, JSON.stringify(next));
42
+ };
43
+ const noteError = (message) => {
44
+ log(`Specialties from Harness: ${message}`);
45
+ keep({ ...(copy ?? {}), error: String(message).slice(0, 300) });
46
+ };
47
+
48
+ /** Fetches the snapshot; true when a new copy was kept. A failure or an empty answer keeps the last copy. */
49
+ async function refresh() {
50
+ let reply;
51
+ try {
52
+ reply = await ask();
53
+ } catch (error) {
54
+ noteError(error.message);
55
+ return false;
56
+ }
57
+ if (reply == null) return false;
58
+ if (!reply.ok) {
59
+ noteError(reply.error || "Harness refused the request");
60
+ return false;
61
+ }
62
+ // Harness has had no good run yet: whatever this relay kept stays.
63
+ if (reply.snapshot == null) return false;
64
+ if (!isSnapshot(reply.snapshot)) {
65
+ noteError("the snapshot Harness sent is malformed");
66
+ return false;
67
+ }
68
+ keep({
69
+ at: new Date().toISOString(),
70
+ list: reply.list ?? copy?.list ?? null,
71
+ snapshot: reply.snapshot,
72
+ });
73
+ return true;
74
+ }
75
+
76
+ /**
77
+ * An agent's benchmark specialties on its model: [{ specialty, source, score, url, takenAt }], one per specialty and
78
+ * source. A result for this harness wins over the model alone; an effort-specific one over one with no effort named.
79
+ * [] before the first fetch, and for a model no source covers.
80
+ */
81
+ function snapshotFor({ harness = null, model = null, effort = null } = {}) {
82
+ const entries = copy?.snapshot?.entries ?? [];
83
+ const key = modelKey(model);
84
+ if (!key) return [];
85
+ const level = effortKey(effort);
86
+ const fits = entries.filter(
87
+ (entry) =>
88
+ entry.model === key &&
89
+ (entry.harness === null || entry.harness === harness) &&
90
+ (entry.effort === null || entry.effort === level)
91
+ );
92
+ const closeness = (entry) =>
93
+ (entry.harness === harness && harness !== null ? 2 : 0) +
94
+ (entry.effort !== null ? 1 : 0);
95
+ const best = new Map();
96
+ for (const entry of fits) {
97
+ const slot = `${entry.specialty}\u0000${entry.source}`;
98
+ const held = best.get(slot);
99
+ if (!held || closeness(entry) > closeness(held)) best.set(slot, entry);
100
+ }
101
+ return [...best.values()].map((entry) => ({
102
+ specialty: entry.specialty,
103
+ source: entry.sourceName ?? entry.source,
104
+ score: entry.score,
105
+ url: entry.url,
106
+ takenAt: entry.takenAt,
107
+ }));
108
+ }
109
+
110
+ let timer = null;
111
+ /** Fetches once a day from now on. */
112
+ function start() {
113
+ if (timer) return;
114
+ timer = setInterval(() => void refresh(), DAY_MS);
115
+ timer.unref?.();
116
+ }
117
+ function stop() {
118
+ clearInterval(timer);
119
+ timer = null;
120
+ }
121
+
122
+ /** For the buddy: the snapshot's version and date, when it was fetched and the last error. */
123
+ const view = () => ({
124
+ version: copy?.snapshot?.version ?? null,
125
+ takenAt: copy?.snapshot?.takenAt ?? null,
126
+ fetchedAt: copy?.at ?? null,
127
+ ...(copy?.error ? { error: copy.error } : {}),
128
+ });
129
+
130
+ const instance = { refresh, start, stop, snapshotFor, view };
131
+ current = instance;
132
+ return instance;
133
+ }
134
+
135
+ /** snapshotFor of the relay's snapshot; [] before one is created or fetched. */
136
+ export function snapshotFor(query) {
137
+ return current ? current.snapshotFor(query) : [];
138
+ }
package/lib/store.mjs CHANGED
@@ -2,6 +2,7 @@ import { randomUUID } from "node:crypto";
2
2
  import sqliteWasm from "node-sqlite3-wasm";
3
3
  import { parseSession } from "./parsers.mjs";
4
4
  import { provenanceFor } from "./provenance.mjs";
5
+ import { BOOK_TABLES } from "./book.mjs";
5
6
 
6
7
  const SCHEMA_VERSION = 11;
7
8
  const INDEX_FORMAT_VERSION = 2;
@@ -139,6 +140,10 @@ export function openStore(file) {
139
140
  failure text,
140
141
  target_machine text,
141
142
  claimed_machine text,
143
+ specialty text,
144
+ step text,
145
+ checked text,
146
+ audit text,
142
147
  created_at text not null,
143
148
  updated_at text not null
144
149
  );
@@ -354,7 +359,46 @@ export function openStore(file) {
354
359
  at text not null
355
360
  );
356
361
  create index if not exists board_wakes_agent_idx on board_wakes(agent, id);
362
+ -- The person's choices about what each agent is good at (specialties.mjs), kept in the board so the encrypted board
363
+ -- backup carries them: a specialty they added or removed for an agent on a model ('' when its model is not known),
364
+ -- each agent's primary, who holds a specialty when a step asks for it (pins) and who holds each office.
365
+ create table if not exists board_specialty_choices (
366
+ agent text not null,
367
+ model text not null,
368
+ specialty text not null,
369
+ choice text not null,
370
+ set_at text not null,
371
+ primary key (agent, model, specialty)
372
+ );
373
+ create table if not exists board_specialty_primary (
374
+ agent text primary key,
375
+ specialty text not null,
376
+ set_at text not null
377
+ );
378
+ create table if not exists board_pins (
379
+ specialty text primary key,
380
+ agent text not null,
381
+ set_at text not null
382
+ );
383
+ create table if not exists board_offices (
384
+ office text primary key,
385
+ agent text not null,
386
+ set_at text not null
387
+ );
388
+ -- Each specialty the benchmark snapshot gave an agent on a model and effort, so one a newer snapshot no longer
389
+ -- supports stays on its card, marked, for the person to keep or remove.
390
+ create table if not exists board_specialty_benchmarks (
391
+ agent text not null,
392
+ model text not null,
393
+ effort text not null,
394
+ specialty text not null,
395
+ source text not null,
396
+ seen_at text not null,
397
+ primary key (agent, model, effort, specialty)
398
+ );
357
399
  `);
400
+ // The onchain desk's book (book.mjs): board tables, so the board's copies and its backup carry it.
401
+ db.exec(BOOK_TABLES);
358
402
  const sessionColumns = new Set(
359
403
  db.all("pragma table_info(sessions)").map((column) => column.name)
360
404
  );
@@ -460,6 +504,14 @@ export function openStore(file) {
460
504
  db.exec(
461
505
  "alter table board_tasks add column target_machine text; alter table board_tasks add column claimed_machine text"
462
506
  );
507
+ // The step of its thread's route a run worked in and the specialty that step asked for (team.mjs), and the check of
508
+ // it by another agent (record.mjs reads them).
509
+ for (const column of ["specialty", "step", "checked"])
510
+ if (!boardColumns.has(column) && boardColumns.size)
511
+ db.exec(`alter table board_tasks add column ${column} text`);
512
+ // What the auditor's code found comparing a report's claims with its receipts (audit.mjs).
513
+ if (!boardColumns.has("audit") && boardColumns.size)
514
+ db.exec("alter table board_tasks add column audit text");
463
515
 
464
516
  const statements = [];
465
517
  const prepare = (sql) => {
@@ -998,6 +1050,136 @@ export function openStore(file) {
998
1050
  String(value)
999
1051
  );
1000
1052
  },
1053
+ // The person's choices about what each agent is good at (specialties.mjs owns the rules; these keep the rows).
1054
+ specialtyChoices(agent) {
1055
+ return execute(
1056
+ "all",
1057
+ "select model, specialty, choice, set_at from board_specialty_choices where agent = ? order by set_at",
1058
+ agent
1059
+ );
1060
+ },
1061
+ // 'add' or 'remove' for one agent on one model. Each takes out the other's rows for that agent and specialty on any
1062
+ // model: the person's latest word on it stands.
1063
+ setSpecialtyChoice({ agent, model, specialty, choice }) {
1064
+ execute(
1065
+ "run",
1066
+ "delete from board_specialty_choices where agent = ? and specialty = ? and choice = ?",
1067
+ agent,
1068
+ specialty,
1069
+ choice === "remove" ? "add" : "remove"
1070
+ );
1071
+ execute(
1072
+ "run",
1073
+ `insert into board_specialty_choices(agent, model, specialty, choice, set_at) values(?, ?, ?, ?, ?)
1074
+ on conflict(agent, model, specialty) do update set choice = excluded.choice, set_at = excluded.set_at`,
1075
+ agent,
1076
+ model,
1077
+ specialty,
1078
+ choice,
1079
+ new Date().toISOString()
1080
+ );
1081
+ },
1082
+ primarySpecialty(agent) {
1083
+ return (
1084
+ execute(
1085
+ "get",
1086
+ "select specialty from board_specialty_primary where agent = ?",
1087
+ agent
1088
+ )?.specialty ?? null
1089
+ );
1090
+ },
1091
+ setPrimarySpecialty(agent, specialty) {
1092
+ if (!specialty) {
1093
+ execute(
1094
+ "run",
1095
+ "delete from board_specialty_primary where agent = ?",
1096
+ agent
1097
+ );
1098
+ return;
1099
+ }
1100
+ execute(
1101
+ "run",
1102
+ `insert into board_specialty_primary(agent, specialty, set_at) values(?, ?, ?)
1103
+ on conflict(agent) do update set specialty = excluded.specialty, set_at = excluded.set_at`,
1104
+ agent,
1105
+ specialty,
1106
+ new Date().toISOString()
1107
+ );
1108
+ },
1109
+ pins() {
1110
+ return execute(
1111
+ "all",
1112
+ "select specialty, agent, set_at from board_pins order by specialty"
1113
+ );
1114
+ },
1115
+ setPin(specialty, agent) {
1116
+ if (!agent) {
1117
+ execute("run", "delete from board_pins where specialty = ?", specialty);
1118
+ return;
1119
+ }
1120
+ execute(
1121
+ "run",
1122
+ `insert into board_pins(specialty, agent, set_at) values(?, ?, ?)
1123
+ on conflict(specialty) do update set agent = excluded.agent, set_at = excluded.set_at`,
1124
+ specialty,
1125
+ agent,
1126
+ new Date().toISOString()
1127
+ );
1128
+ },
1129
+ appointments() {
1130
+ return execute(
1131
+ "all",
1132
+ "select office, agent, set_at from board_offices order by office"
1133
+ );
1134
+ },
1135
+ setAppointment(office, agent) {
1136
+ if (!agent) {
1137
+ execute("run", "delete from board_offices where office = ?", office);
1138
+ return;
1139
+ }
1140
+ execute(
1141
+ "run",
1142
+ `insert into board_offices(office, agent, set_at) values(?, ?, ?)
1143
+ on conflict(office) do update set agent = excluded.agent, set_at = excluded.set_at`,
1144
+ office,
1145
+ agent,
1146
+ new Date().toISOString()
1147
+ );
1148
+ },
1149
+ // The benchmark specialties an agent was ever given on one model and effort, by source.
1150
+ benchmarksSeen(agent, model, effort) {
1151
+ return execute(
1152
+ "all",
1153
+ "select specialty, source from board_specialty_benchmarks where agent = ? and model = ? and effort = ?",
1154
+ agent,
1155
+ model,
1156
+ effort
1157
+ );
1158
+ },
1159
+ // Kept once: a row already there is left as it is, so reading a card writes nothing after the first time.
1160
+ noteBenchmarks(agent, model, effort, entries) {
1161
+ const at = new Date().toISOString();
1162
+ for (const { specialty, source } of entries)
1163
+ execute(
1164
+ "run",
1165
+ "insert or ignore into board_specialty_benchmarks(agent, model, effort, specialty, source, seen_at) values(?, ?, ?, ?, ?, ?)",
1166
+ agent,
1167
+ model,
1168
+ effort,
1169
+ specialty,
1170
+ source,
1171
+ at
1172
+ );
1173
+ },
1174
+ // Every model an agent's runs on this board named, for the specialties it earned on each.
1175
+ runModels(agent) {
1176
+ return execute(
1177
+ "all",
1178
+ `select distinct json_extract(run_model, '$.model') as model from board_tasks
1179
+ where coalesce(claimed_by, target_agent) = ? and json_extract(run_model, '$.model') is not null`,
1180
+ agent
1181
+ ).map((row) => row.model);
1182
+ },
1001
1183
  // A goal: one objective the owner set for a team of agents, worked in its room (the goal's contributions). The goal
1002
1184
  // is a board task of kind 'goal'; its team, facilitator, folder and backstops live beside it. Jobs and wakes are its
1003
1185
  // children, authorized by the goal (run_authorized_by 'goal') and counted in its spend.
@@ -2163,15 +2345,78 @@ export function openStore(file) {
2163
2345
  threadRuns(goalId) {
2164
2346
  return execute(
2165
2347
  "all",
2166
- `select id, kind, objective, origin_agent, target_agent, claimed_by, claimed_at, status, holder, result, failure, session_id, run_workspace, run_authorized_at, usage, run_model, created_at, updated_at, reported_at
2348
+ `select id, kind, objective, origin_agent, target_agent, claimed_by, claimed_at, status, holder, result, failure, session_id, run_workspace, run_authorized_at, usage, run_model, specialty, step, checked, created_at, updated_at, reported_at
2167
2349
  from board_tasks where parent_id = ? and kind in ('wake', 'task') order by created_at asc`,
2168
2350
  goalId
2169
2351
  ).map((row) => ({
2170
2352
  ...row,
2171
2353
  usage: row.usage ? JSON.parse(row.usage) : null,
2172
2354
  run_model: row.run_model ? JSON.parse(row.run_model) : null,
2355
+ checked: row.checked ? JSON.parse(row.checked) : null,
2173
2356
  }));
2174
2357
  },
2358
+ // The step of the thread's route a run works in and the specialty that step asks for (team.mjs).
2359
+ setRunStep(id, { step, specialty }) {
2360
+ execute(
2361
+ "run",
2362
+ "update board_tasks set step = ?, specialty = ? where id = ?",
2363
+ step,
2364
+ specialty ?? null,
2365
+ id
2366
+ );
2367
+ },
2368
+ // Another agent's check of a run's work: { outcome: passed | sent_back, step, by: [{ agent, model }], at }.
2369
+ setRunChecked(id, checked) {
2370
+ execute(
2371
+ "run",
2372
+ "update board_tasks set checked = ? where id = ?",
2373
+ JSON.stringify(checked),
2374
+ id
2375
+ );
2376
+ },
2377
+ // Whether an agent has a run going in another thread: work routed to it by a pin waits for it (team.mjs).
2378
+ busyElsewhere(agent, goalId) {
2379
+ return Boolean(
2380
+ execute(
2381
+ "get",
2382
+ "select 1 as hit from board_tasks where coalesce(claimed_by, target_agent) = ? and status in ('claimed', 'running') and kind in ('wake', 'task') and coalesce(parent_id, '') != ? and removed_at is null limit 1",
2383
+ agent,
2384
+ goalId
2385
+ )
2386
+ );
2387
+ },
2388
+ // Every run that worked a step of a route, with what judged it (record.mjs): its model, the check written on it and
2389
+ // the auditor's finding on its report (audit.mjs).
2390
+ routedRuns() {
2391
+ return execute(
2392
+ "all",
2393
+ `select id, parent_id as goal_id, coalesce(claimed_by, target_agent) as agent, json_extract(run_model, '$.model') as model,
2394
+ specialty, step, checked, audit, reported_at
2395
+ from board_tasks where specialty is not null and reported_at is not null and removed_at is null and kind in ('wake', 'task')`
2396
+ ).map((row) => ({
2397
+ ...row,
2398
+ checked: row.checked ? JSON.parse(row.checked) : null,
2399
+ audit: row.audit ? JSON.parse(row.audit) : null,
2400
+ }));
2401
+ },
2402
+ // Every run an agent reported in a thread, newest last, so a verdict can be matched to the run it judged.
2403
+ threadReports() {
2404
+ return execute(
2405
+ "all",
2406
+ `select id, parent_id as goal_id, coalesce(claimed_by, target_agent) as agent, reported_at from board_tasks
2407
+ where parent_id is not null and reported_at is not null and removed_at is null and kind in ('wake', 'task')
2408
+ order by reported_at asc`
2409
+ );
2410
+ },
2411
+ // The person's verdicts with when they said them (record.mjs), oldest first.
2412
+ verdictsSaid() {
2413
+ return execute(
2414
+ "all",
2415
+ `select r.goal_id, r.agent, r.verdict, coalesce(p.created_at, r.at) as said_at
2416
+ from board_reactions r left join board_contributions p on p.id = r.post_id
2417
+ where r.verdict != 'neither' order by said_at asc`
2418
+ );
2419
+ },
2175
2420
  // The coding sessions on this machine, newest first: the person's own and the ones runs started.
2176
2421
  recentSessions(limit = 30) {
2177
2422
  return execute(
@@ -2181,6 +2426,16 @@ export function openStore(file) {
2181
2426
  Math.max(1, Math.min(100, Number(limit) || 30))
2182
2427
  ).map((row) => ({ ...row, message_count: Number(row.message_count) }));
2183
2428
  },
2429
+ // One agent's sessions, newest first: deep enough to reach the person's own past many runs other processes started.
2430
+ agentSessions(agent, limit = 200) {
2431
+ return execute(
2432
+ "all",
2433
+ `select agent, session_id, title, cwd, started_at, ended_at, source from sessions where agent = ?
2434
+ order by coalesce(ended_at, started_at, indexed_at) desc limit ?`,
2435
+ agent,
2436
+ Math.max(1, Math.min(500, Number(limit) || 200))
2437
+ );
2438
+ },
2184
2439
  // The relay's own copy of a session (messages with tool calls clipped), for one whose source file is gone.
2185
2440
  sessionTranscript(agent, sessionId) {
2186
2441
  return (
@@ -2330,6 +2585,17 @@ export function openStore(file) {
2330
2585
  ) ?? null
2331
2586
  );
2332
2587
  },
2588
+ /** The run Harness started that worked in a session, running or long done: work the person handed out. */
2589
+ runOfSession(agent, sessionId) {
2590
+ return (
2591
+ execute(
2592
+ "get",
2593
+ "select id, parent_id from board_tasks where coalesce(claimed_by, target_agent) = ? and session_id is not null and instr(session_id, ?) > 0 order by updated_at desc limit 1",
2594
+ agent,
2595
+ String(sessionId)
2596
+ ) ?? null
2597
+ );
2598
+ },
2333
2599
  setRunSession(id, sessionId) {
2334
2600
  execute(
2335
2601
  "run",
@@ -2609,6 +2875,13 @@ export function openStore(file) {
2609
2875
  );
2610
2876
  return this.ownMachine(machineId);
2611
2877
  },
2878
+ unpinOwnMachine(machineId) {
2879
+ execute(
2880
+ "run",
2881
+ "delete from own_machines where machine_id = ?",
2882
+ machineId
2883
+ );
2884
+ },
2612
2885
  ownMachines() {
2613
2886
  return execute(
2614
2887
  "all",
@@ -3196,6 +3469,15 @@ export function openStore(file) {
3196
3469
  now
3197
3470
  );
3198
3471
  },
3472
+ // Which agents called the board from which computer since `since`: where an agent that runs itself (Hermes, OpenClaw)
3473
+ // lives, since the daemon never starts it.
3474
+ agentsSeenOnComputers(since) {
3475
+ return execute(
3476
+ "all",
3477
+ "select agent, machine from board_agent_computers where last_seen_at >= ? order by agent",
3478
+ since
3479
+ );
3480
+ },
3199
3481
  // When each agent last called the board, from any computer.
3200
3482
  agentsSeen() {
3201
3483
  return execute(
@@ -3399,6 +3681,7 @@ export function openStore(file) {
3399
3681
  origin_chain: JSON.parse(row.origin_chain || "[]"),
3400
3682
  usage: row.usage ? JSON.parse(row.usage) : null,
3401
3683
  run_model: row.run_model ? JSON.parse(row.run_model) : null,
3684
+ audit: row.audit ? JSON.parse(row.audit) : null,
3402
3685
  stale:
3403
3686
  row.status === "claimed" &&
3404
3687
  Boolean(row.lease_until) &&