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
package/lib/store.mjs CHANGED
@@ -1,7 +1,9 @@
1
+ import { verdictEntriesByRun } from "./record.mjs";
1
2
  import { randomUUID } from "node:crypto";
2
3
  import sqliteWasm from "node-sqlite3-wasm";
3
4
  import { parseSession } from "./parsers.mjs";
4
5
  import { provenanceFor } from "./provenance.mjs";
6
+ import { BOOK_TABLES } from "./book.mjs";
5
7
 
6
8
  const SCHEMA_VERSION = 11;
7
9
  const INDEX_FORMAT_VERSION = 2;
@@ -139,6 +141,10 @@ export function openStore(file) {
139
141
  failure text,
140
142
  target_machine text,
141
143
  claimed_machine text,
144
+ specialty text,
145
+ step text,
146
+ checked text,
147
+ audit text,
142
148
  created_at text not null,
143
149
  updated_at text not null
144
150
  );
@@ -354,7 +360,46 @@ export function openStore(file) {
354
360
  at text not null
355
361
  );
356
362
  create index if not exists board_wakes_agent_idx on board_wakes(agent, id);
363
+ -- The person's choices about what each agent is good at (specialties.mjs), kept in the board so the encrypted board
364
+ -- backup carries them: a specialty they added or removed for an agent on a model ('' when its model is not known),
365
+ -- each agent's primary, who holds a specialty when a step asks for it (pins) and who holds each office.
366
+ create table if not exists board_specialty_choices (
367
+ agent text not null,
368
+ model text not null,
369
+ specialty text not null,
370
+ choice text not null,
371
+ set_at text not null,
372
+ primary key (agent, model, specialty)
373
+ );
374
+ create table if not exists board_specialty_primary (
375
+ agent text primary key,
376
+ specialty text not null,
377
+ set_at text not null
378
+ );
379
+ create table if not exists board_pins (
380
+ specialty text primary key,
381
+ agent text not null,
382
+ set_at text not null
383
+ );
384
+ create table if not exists board_offices (
385
+ office text primary key,
386
+ agent text not null,
387
+ set_at text not null
388
+ );
389
+ -- Each specialty the benchmark snapshot gave an agent on a model and effort, so one a newer snapshot no longer
390
+ -- supports stays on its card, marked, for the person to keep or remove.
391
+ create table if not exists board_specialty_benchmarks (
392
+ agent text not null,
393
+ model text not null,
394
+ effort text not null,
395
+ specialty text not null,
396
+ source text not null,
397
+ seen_at text not null,
398
+ primary key (agent, model, effort, specialty)
399
+ );
357
400
  `);
401
+ // The onchain desk's book (book.mjs): board tables, so the board's copies and its backup carry it.
402
+ db.exec(BOOK_TABLES);
358
403
  const sessionColumns = new Set(
359
404
  db.all("pragma table_info(sessions)").map((column) => column.name)
360
405
  );
@@ -388,6 +433,16 @@ export function openStore(file) {
388
433
  .some((column) => column.name === "machine")
389
434
  )
390
435
  db.exec("alter table board_contributions add column machine text");
436
+ // A computer Harness runs (a cloud computer), set up for agents only: its calls never act as the person
437
+ // (ownMachines.mjs tryCode).
438
+ if (
439
+ !db
440
+ .all("pragma table_info(own_machines)")
441
+ .some((column) => column.name === "hosted")
442
+ )
443
+ db.exec(
444
+ "alter table own_machines add column hosted integer not null default 0"
445
+ );
391
446
  // Devices paired before browsers could pair were all phones.
392
447
  if (
393
448
  !db
@@ -397,6 +452,26 @@ export function openStore(file) {
397
452
  db.exec(
398
453
  "alter table phone_devices add column kind text not null default 'phone'"
399
454
  );
455
+ // Where a device's private key lives: in a page Harness serves ("page", every device before October 26), or in the
456
+ // Harness extension, whose code Harness's server does not supply ("extension").
457
+ if (
458
+ !db
459
+ .all("pragma table_info(phone_devices)")
460
+ .some((column) => column.name === "holder")
461
+ )
462
+ db.exec(
463
+ "alter table phone_devices add column holder text not null default 'page'"
464
+ );
465
+ // Each sealed call's record says which kind of key sealed it, and whether the extension saw the person act in the
466
+ // page as it sealed (a "gesture"), so a rule can tell the two kinds apart later.
467
+ if (
468
+ !db
469
+ .all("pragma table_info(phone_requests)")
470
+ .some((column) => column.name === "sealed_by")
471
+ ) {
472
+ db.exec("alter table phone_requests add column sealed_by text");
473
+ db.exec("alter table phone_requests add column gesture integer");
474
+ }
400
475
  // A thread whose other side's computer holds a key: everything on it goes sealed to that key.
401
476
  if (
402
477
  !db
@@ -460,6 +535,26 @@ export function openStore(file) {
460
535
  db.exec(
461
536
  "alter table board_tasks add column target_machine text; alter table board_tasks add column claimed_machine text"
462
537
  );
538
+ // The step of its thread's route a run worked in and the specialty that step asked for (team.mjs), and the check of
539
+ // it by another agent (record.mjs reads them).
540
+ for (const column of ["specialty", "step", "checked"])
541
+ if (!boardColumns.has(column) && boardColumns.size)
542
+ db.exec(`alter table board_tasks add column ${column} text`);
543
+ // What the auditor's code found comparing a report's claims with its receipts (audit.mjs).
544
+ if (!boardColumns.has("audit") && boardColumns.size)
545
+ db.exec("alter table board_tasks add column audit text");
546
+
547
+ for (const [table, columns] of [
548
+ ["board_tasks", ["returned"]],
549
+ ["board_reactions", ["run_id", "source", "reason"]],
550
+ ]) {
551
+ const existing = new Set(
552
+ db.all(`pragma table_info(${table})`).map((c) => c.name)
553
+ );
554
+ for (const column of columns)
555
+ if (!existing.has(column))
556
+ db.exec(`alter table ${table} add column ${column} text`);
557
+ }
463
558
 
464
559
  const statements = [];
465
560
  const prepare = (sql) => {
@@ -998,6 +1093,136 @@ export function openStore(file) {
998
1093
  String(value)
999
1094
  );
1000
1095
  },
1096
+ // The person's choices about what each agent is good at (specialties.mjs owns the rules; these keep the rows).
1097
+ specialtyChoices(agent) {
1098
+ return execute(
1099
+ "all",
1100
+ "select model, specialty, choice, set_at from board_specialty_choices where agent = ? order by set_at",
1101
+ agent
1102
+ );
1103
+ },
1104
+ // 'add' or 'remove' for one agent on one model. Each takes out the other's rows for that agent and specialty on any
1105
+ // model: the person's latest word on it stands.
1106
+ setSpecialtyChoice({ agent, model, specialty, choice }) {
1107
+ execute(
1108
+ "run",
1109
+ "delete from board_specialty_choices where agent = ? and specialty = ? and choice = ?",
1110
+ agent,
1111
+ specialty,
1112
+ choice === "remove" ? "add" : "remove"
1113
+ );
1114
+ execute(
1115
+ "run",
1116
+ `insert into board_specialty_choices(agent, model, specialty, choice, set_at) values(?, ?, ?, ?, ?)
1117
+ on conflict(agent, model, specialty) do update set choice = excluded.choice, set_at = excluded.set_at`,
1118
+ agent,
1119
+ model,
1120
+ specialty,
1121
+ choice,
1122
+ new Date().toISOString()
1123
+ );
1124
+ },
1125
+ primarySpecialty(agent) {
1126
+ return (
1127
+ execute(
1128
+ "get",
1129
+ "select specialty from board_specialty_primary where agent = ?",
1130
+ agent
1131
+ )?.specialty ?? null
1132
+ );
1133
+ },
1134
+ setPrimarySpecialty(agent, specialty) {
1135
+ if (!specialty) {
1136
+ execute(
1137
+ "run",
1138
+ "delete from board_specialty_primary where agent = ?",
1139
+ agent
1140
+ );
1141
+ return;
1142
+ }
1143
+ execute(
1144
+ "run",
1145
+ `insert into board_specialty_primary(agent, specialty, set_at) values(?, ?, ?)
1146
+ on conflict(agent) do update set specialty = excluded.specialty, set_at = excluded.set_at`,
1147
+ agent,
1148
+ specialty,
1149
+ new Date().toISOString()
1150
+ );
1151
+ },
1152
+ pins() {
1153
+ return execute(
1154
+ "all",
1155
+ "select specialty, agent, set_at from board_pins order by specialty"
1156
+ );
1157
+ },
1158
+ setPin(specialty, agent) {
1159
+ if (!agent) {
1160
+ execute("run", "delete from board_pins where specialty = ?", specialty);
1161
+ return;
1162
+ }
1163
+ execute(
1164
+ "run",
1165
+ `insert into board_pins(specialty, agent, set_at) values(?, ?, ?)
1166
+ on conflict(specialty) do update set agent = excluded.agent, set_at = excluded.set_at`,
1167
+ specialty,
1168
+ agent,
1169
+ new Date().toISOString()
1170
+ );
1171
+ },
1172
+ appointments() {
1173
+ return execute(
1174
+ "all",
1175
+ "select office, agent, set_at from board_offices order by office"
1176
+ );
1177
+ },
1178
+ setAppointment(office, agent) {
1179
+ if (!agent) {
1180
+ execute("run", "delete from board_offices where office = ?", office);
1181
+ return;
1182
+ }
1183
+ execute(
1184
+ "run",
1185
+ `insert into board_offices(office, agent, set_at) values(?, ?, ?)
1186
+ on conflict(office) do update set agent = excluded.agent, set_at = excluded.set_at`,
1187
+ office,
1188
+ agent,
1189
+ new Date().toISOString()
1190
+ );
1191
+ },
1192
+ // The benchmark specialties an agent was ever given on one model and effort, by source.
1193
+ benchmarksSeen(agent, model, effort) {
1194
+ return execute(
1195
+ "all",
1196
+ "select specialty, source from board_specialty_benchmarks where agent = ? and model = ? and effort = ?",
1197
+ agent,
1198
+ model,
1199
+ effort
1200
+ );
1201
+ },
1202
+ // Kept once: a row already there is left as it is, so reading a card writes nothing after the first time.
1203
+ noteBenchmarks(agent, model, effort, entries) {
1204
+ const at = new Date().toISOString();
1205
+ for (const { specialty, source } of entries)
1206
+ execute(
1207
+ "run",
1208
+ "insert or ignore into board_specialty_benchmarks(agent, model, effort, specialty, source, seen_at) values(?, ?, ?, ?, ?, ?)",
1209
+ agent,
1210
+ model,
1211
+ effort,
1212
+ specialty,
1213
+ source,
1214
+ at
1215
+ );
1216
+ },
1217
+ // Every model an agent's runs on this board named, for the specialties it earned on each.
1218
+ runModels(agent) {
1219
+ return execute(
1220
+ "all",
1221
+ `select distinct json_extract(run_model, '$.model') as model from board_tasks
1222
+ where coalesce(claimed_by, target_agent) = ? and json_extract(run_model, '$.model') is not null`,
1223
+ agent
1224
+ ).map((row) => row.model);
1225
+ },
1001
1226
  // A goal: one objective the owner set for a team of agents, worked in its room (the goal's contributions). The goal
1002
1227
  // is a board task of kind 'goal'; its team, facilitator, folder and backstops live beside it. Jobs and wakes are its
1003
1228
  // children, authorized by the goal (run_authorized_by 'goal') and counted in its spend.
@@ -1219,7 +1444,7 @@ export function openStore(file) {
1219
1444
  },
1220
1445
  // The newest posts before `before` (every post when it is not given), oldest first, and the seq to read before
1221
1446
  // for the ones earlier still (null at the thread's start). roomPosts reads from the start, which in a thread past
1222
- // its limit is the oldest posts (October 17: Codex was woken with posts 172 to 201 of 294).
1447
+ // its limit is the oldest posts (Codex was once woken with posts 172 to 201 of 294).
1223
1448
  recentRoomPosts(goalId, { before = null, limit = 30 } = {}) {
1224
1449
  const count = Math.max(1, Math.min(500, Number(limit) || 30));
1225
1450
  const rows = execute(
@@ -1588,7 +1813,7 @@ export function openStore(file) {
1588
1813
  // Every post, result, receipt and job in the person's threads and tasks, each with the thread it belongs to (a job's
1589
1814
  // thread is its parent). Briefs, context packs, coordinator notes and records are the swarm's plumbing, not what
1590
1815
  // was said or done; posts the guard held never come back; nor does anything the person had forgotten or replaced.
1591
- // The first twelve words of a query, as searchThreads read them (eval memory-lane: with 24, long job results that
1816
+ // The first twelve words of a query, as searchThreads read them (measured with 24: long job results that
1592
1817
  // share many common words crowded out the person's own earlier posts).
1593
1818
  memoryWords(query, limit = 60) {
1594
1819
  const terms = [
@@ -1909,11 +2134,14 @@ export function openStore(file) {
1909
2134
  agent,
1910
2135
  verdict,
1911
2136
  judgments,
2137
+ runId = null,
2138
+ source = "said",
2139
+ reason = null,
1912
2140
  }) {
1913
2141
  execute(
1914
2142
  "run",
1915
- `insert or replace into board_reactions(post_id, goal_id, post_seq, about_seq, agent, verdict, judgments, at)
1916
- values(?, ?, ?, ?, ?, ?, ?, ?)`,
2143
+ `insert or replace into board_reactions(post_id, goal_id, post_seq, about_seq, agent, verdict, judgments, at, run_id, source, reason)
2144
+ values(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)`,
1917
2145
  postId,
1918
2146
  goalId,
1919
2147
  postSeq,
@@ -1921,7 +2149,10 @@ export function openStore(file) {
1921
2149
  agent,
1922
2150
  verdict,
1923
2151
  judgments ? JSON.stringify(judgments) : null,
1924
- new Date().toISOString()
2152
+ new Date().toISOString(),
2153
+ runId,
2154
+ source,
2155
+ reason
1925
2156
  );
1926
2157
  },
1927
2158
  // The person's approvals of agents' work recorded after a moment, oldest first (swarmMemory.mjs keeps each as a
@@ -1945,10 +2176,18 @@ export function openStore(file) {
1945
2176
  // The person's verdicts on each agent's work, for its card: { agent: { accepted, changes, rejected } }.
1946
2177
  verdictCounts() {
1947
2178
  const counts = {};
1948
- for (const row of execute(
2179
+ const judged = [...verdictEntriesByRun(this).values()];
2180
+ const unmatched = execute(
1949
2181
  "all",
1950
- "select agent, verdict, count(*) as n from board_reactions where verdict != 'neither' group by agent, verdict"
1951
- )) {
2182
+ `select r.agent, r.verdict from board_reactions r
2183
+ left join board_contributions p on p.id = r.post_id
2184
+ where r.verdict != 'neither' and r.run_id is null and not exists (
2185
+ select 1 from board_tasks t where t.parent_id = r.goal_id
2186
+ and coalesce(t.claimed_by, t.target_agent) = r.agent
2187
+ and t.reported_at <= coalesce(p.created_at, r.at) and t.removed_at is null
2188
+ and t.kind in ('wake', 'task'))`
2189
+ );
2190
+ for (const row of [...judged, ...unmatched]) {
1952
2191
  const entry = (counts[row.agent] ??= {
1953
2192
  accepted: 0,
1954
2193
  changes: 0,
@@ -1960,7 +2199,7 @@ export function openStore(file) {
1960
2199
  : row.verdict === "approves_with_changes"
1961
2200
  ? "changes"
1962
2201
  : "rejected";
1963
- entry[key] += Number(row.n);
2202
+ entry[key]++;
1964
2203
  }
1965
2204
  return counts;
1966
2205
  },
@@ -2059,20 +2298,25 @@ export function openStore(file) {
2059
2298
  );
2060
2299
  },
2061
2300
  // Stop: every open child closes; the caller stops what is running.
2062
- closeGoalChildren(goalId, reason) {
2301
+ // `agent`: only that agent's runs, the rest of the goal's work going on (a shared project's piece released).
2302
+ closeGoalChildren(goalId, reason, agent = null) {
2063
2303
  const now = new Date().toISOString();
2064
2304
  const running = execute(
2065
2305
  "all",
2066
- "select id, target_agent from board_tasks where parent_id = ? and status = 'running'",
2067
- goalId
2306
+ "select id, target_agent from board_tasks where parent_id = ? and status = 'running' and (? is null or target_agent = ?)",
2307
+ goalId,
2308
+ agent,
2309
+ agent
2068
2310
  );
2069
2311
  execute(
2070
2312
  "run",
2071
- "update board_tasks set status = 'failed', result = ?, failure = 'person', holder = null, reported_at = ?, updated_at = ?, version = version + 1 where parent_id = ? and status in ('open', 'claimed', 'needs_input', 'running')",
2313
+ "update board_tasks set status = 'failed', result = ?, failure = 'person', holder = null, reported_at = ?, updated_at = ?, version = version + 1 where parent_id = ? and status in ('open', 'claimed', 'needs_input', 'running') and (? is null or target_agent = ?)",
2072
2314
  reason,
2073
2315
  now,
2074
2316
  now,
2075
- goalId
2317
+ goalId,
2318
+ agent,
2319
+ agent
2076
2320
  );
2077
2321
  return running;
2078
2322
  },
@@ -2159,19 +2403,91 @@ export function openStore(file) {
2159
2403
  undecided: Number(row.undecided),
2160
2404
  }));
2161
2405
  },
2162
- // A thread's runs (wakes and jobs), oldest first, for its transcript.
2406
+ // A thread's runs (wakes and jobs), oldest first, for its transcript, with the computer each ran on.
2163
2407
  threadRuns(goalId) {
2164
2408
  return execute(
2165
2409
  "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
2410
+ `select id, kind, objective, origin_agent, target_agent, claimed_by, claimed_at, claimed_machine, status, holder, result, failure, session_id, run_workspace, run_authorized_at, usage, run_model, specialty, step, checked, returned, created_at, updated_at, reported_at
2167
2411
  from board_tasks where parent_id = ? and kind in ('wake', 'task') order by created_at asc`,
2168
2412
  goalId
2169
2413
  ).map((row) => ({
2170
2414
  ...row,
2171
2415
  usage: row.usage ? JSON.parse(row.usage) : null,
2172
2416
  run_model: row.run_model ? JSON.parse(row.run_model) : null,
2417
+ returned: row.returned ? JSON.parse(row.returned) : null,
2418
+ checked: row.checked ? JSON.parse(row.checked) : null,
2419
+ }));
2420
+ },
2421
+ // The step of the thread's route a run works in and the specialty that step asks for (team.mjs).
2422
+ setRunStep(id, { step, specialty }) {
2423
+ execute(
2424
+ "run",
2425
+ "update board_tasks set step = ?, specialty = ? where id = ?",
2426
+ step,
2427
+ specialty ?? null,
2428
+ id
2429
+ );
2430
+ },
2431
+ setRunReturned(id, returned) {
2432
+ execute(
2433
+ "run",
2434
+ "update board_tasks set returned = ? where id = ?",
2435
+ JSON.stringify(returned),
2436
+ id
2437
+ );
2438
+ },
2439
+ // Another agent's check of a run's work: { outcome: passed | sent_back, step, by: [{ agent, model }], at }.
2440
+ setRunChecked(id, checked) {
2441
+ execute(
2442
+ "run",
2443
+ "update board_tasks set checked = ? where id = ?",
2444
+ JSON.stringify(checked),
2445
+ id
2446
+ );
2447
+ },
2448
+ // Whether an agent has a run going in another thread: work routed to it by a pin waits for it (team.mjs).
2449
+ busyElsewhere(agent, goalId) {
2450
+ return Boolean(
2451
+ execute(
2452
+ "get",
2453
+ "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",
2454
+ agent,
2455
+ goalId
2456
+ )
2457
+ );
2458
+ },
2459
+ // Every run that worked a step of a route, with what judged it (record.mjs): its model, the check written on it and
2460
+ // the auditor's finding on its report (audit.mjs).
2461
+ routedRuns() {
2462
+ return execute(
2463
+ "all",
2464
+ `select id, parent_id as goal_id, coalesce(claimed_by, target_agent) as agent, json_extract(run_model, '$.model') as model,
2465
+ specialty, step, checked, audit, reported_at
2466
+ from board_tasks where specialty is not null and reported_at is not null and removed_at is null and kind in ('wake', 'task')`
2467
+ ).map((row) => ({
2468
+ ...row,
2469
+ checked: row.checked ? JSON.parse(row.checked) : null,
2470
+ audit: row.audit ? JSON.parse(row.audit) : null,
2173
2471
  }));
2174
2472
  },
2473
+ // Every run an agent reported in a thread, newest last, so a verdict can be matched to the run it judged.
2474
+ threadReports() {
2475
+ return execute(
2476
+ "all",
2477
+ `select id, parent_id as goal_id, coalesce(claimed_by, target_agent) as agent, reported_at from board_tasks
2478
+ where parent_id is not null and reported_at is not null and removed_at is null and kind in ('wake', 'task')
2479
+ order by reported_at asc`
2480
+ );
2481
+ },
2482
+ // The person's verdicts with when they said them (record.mjs), oldest first.
2483
+ verdictsSaid() {
2484
+ return execute(
2485
+ "all",
2486
+ `select r.goal_id, r.agent, r.verdict, r.run_id, r.source, r.reason, coalesce(p.created_at, r.at) as said_at
2487
+ from board_reactions r left join board_contributions p on p.id = r.post_id
2488
+ where r.verdict != 'neither' order by said_at asc, r.rowid asc`
2489
+ );
2490
+ },
2175
2491
  // The coding sessions on this machine, newest first: the person's own and the ones runs started.
2176
2492
  recentSessions(limit = 30) {
2177
2493
  return execute(
@@ -2181,6 +2497,16 @@ export function openStore(file) {
2181
2497
  Math.max(1, Math.min(100, Number(limit) || 30))
2182
2498
  ).map((row) => ({ ...row, message_count: Number(row.message_count) }));
2183
2499
  },
2500
+ // One agent's sessions, newest first: deep enough to reach the person's own past many runs other processes started.
2501
+ agentSessions(agent, limit = 200) {
2502
+ return execute(
2503
+ "all",
2504
+ `select agent, session_id, title, cwd, started_at, ended_at, source from sessions where agent = ?
2505
+ order by coalesce(ended_at, started_at, indexed_at) desc limit ?`,
2506
+ agent,
2507
+ Math.max(1, Math.min(500, Number(limit) || 200))
2508
+ );
2509
+ },
2184
2510
  // The relay's own copy of a session (messages with tool calls clipped), for one whose source file is gone.
2185
2511
  sessionTranscript(agent, sessionId) {
2186
2512
  return (
@@ -2330,6 +2656,17 @@ export function openStore(file) {
2330
2656
  ) ?? null
2331
2657
  );
2332
2658
  },
2659
+ /** The run Harness started that worked in a session, running or long done: work the person handed out. */
2660
+ runOfSession(agent, sessionId) {
2661
+ return (
2662
+ execute(
2663
+ "get",
2664
+ "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",
2665
+ agent,
2666
+ String(sessionId)
2667
+ ) ?? null
2668
+ );
2669
+ },
2333
2670
  setRunSession(id, sessionId) {
2334
2671
  execute(
2335
2672
  "run",
@@ -2590,30 +2927,38 @@ export function openStore(file) {
2590
2927
  // The person's other computers whose keys the join handshake pinned here (machineSeal.mjs): only these may call or
2591
2928
  // be called through Harness.
2592
2929
  ownMachine(machineId) {
2593
- return (
2594
- execute(
2595
- "get",
2596
- "select machine_id, public_key, pinned_at, label from own_machines where machine_id = ?",
2597
- machineId
2598
- ) || null
2930
+ const row = execute(
2931
+ "get",
2932
+ "select machine_id, public_key, pinned_at, label, hosted from own_machines where machine_id = ?",
2933
+ machineId
2599
2934
  );
2935
+ return row ? { ...row, hosted: Boolean(row.hosted) } : null;
2600
2936
  },
2601
- pinOwnMachine(machineId, publicKey, label = "") {
2937
+ // hosted: a computer Harness runs (a cloud computer), added from the person's window; never the person on home.
2938
+ pinOwnMachine(machineId, publicKey, label = "", { hosted = false } = {}) {
2602
2939
  execute(
2603
2940
  "run",
2604
- "insert into own_machines(machine_id, public_key, pinned_at, label) values(?, ?, ?, ?) on conflict(machine_id) do update set public_key = excluded.public_key, pinned_at = excluded.pinned_at, label = excluded.label",
2941
+ "insert into own_machines(machine_id, public_key, pinned_at, label, hosted) values(?, ?, ?, ?, ?) on conflict(machine_id) do update set public_key = excluded.public_key, pinned_at = excluded.pinned_at, label = excluded.label, hosted = max(own_machines.hosted, excluded.hosted)",
2605
2942
  machineId,
2606
2943
  publicKey,
2607
2944
  new Date().toISOString(),
2608
- label
2945
+ label,
2946
+ hosted ? 1 : 0
2609
2947
  );
2610
2948
  return this.ownMachine(machineId);
2611
2949
  },
2950
+ unpinOwnMachine(machineId) {
2951
+ execute(
2952
+ "run",
2953
+ "delete from own_machines where machine_id = ?",
2954
+ machineId
2955
+ );
2956
+ },
2612
2957
  ownMachines() {
2613
2958
  return execute(
2614
2959
  "all",
2615
- "select machine_id, public_key, pinned_at, label from own_machines order by pinned_at"
2616
- );
2960
+ "select machine_id, public_key, pinned_at, label, hosted from own_machines order by pinned_at"
2961
+ ).map((row) => ({ ...row, hosted: Boolean(row.hosted) }));
2617
2962
  },
2618
2963
  // Files on a task. A file this machine has is present; one another person's computer is sending is named by its
2619
2964
  // message first or arrives first, and is matched by the id that computer gave it (remote_id), never by ours.
@@ -3094,15 +3439,16 @@ export function openStore(file) {
3094
3439
  ).map((row) => ({ ...row, count: Number(row.count) }));
3095
3440
  },
3096
3441
  // Phones (QR code) and browsers (link) paired with this machine. Only the public key is kept; a revoked one is refused at once.
3097
- addPhone({ id, label, publicKey, kind = "phone" }) {
3442
+ addPhone({ id, label, publicKey, kind = "phone", holder = "page" }) {
3098
3443
  execute(
3099
3444
  "run",
3100
- "insert into phone_devices(id, label, public_key, paired_at, kind) values(?, ?, ?, ?, ?)",
3445
+ "insert into phone_devices(id, label, public_key, paired_at, kind, holder) values(?, ?, ?, ?, ?, ?)",
3101
3446
  id,
3102
3447
  label,
3103
3448
  publicKey,
3104
3449
  new Date().toISOString(),
3105
- kind
3450
+ kind,
3451
+ holder
3106
3452
  );
3107
3453
  return this.getPhone(id);
3108
3454
  },
@@ -3110,7 +3456,7 @@ export function openStore(file) {
3110
3456
  return (
3111
3457
  execute(
3112
3458
  "get",
3113
- "select id, label, public_key, kind, paired_at, last_seen_at, revoked_at from phone_devices where id = ?",
3459
+ "select id, label, public_key, kind, holder, paired_at, last_seen_at, revoked_at from phone_devices where id = ?",
3114
3460
  id
3115
3461
  ) || null
3116
3462
  );
@@ -3118,7 +3464,7 @@ export function openStore(file) {
3118
3464
  phones() {
3119
3465
  return execute(
3120
3466
  "all",
3121
- "select id, label, kind, paired_at, last_seen_at, revoked_at from phone_devices order by paired_at desc"
3467
+ "select id, label, kind, holder, paired_at, last_seen_at, revoked_at from phone_devices order by paired_at desc"
3122
3468
  );
3123
3469
  },
3124
3470
  // Once a browser is paired, Harness reaches the person's board, sessions and runs only sealed.
@@ -3131,7 +3477,11 @@ export function openStore(file) {
3131
3477
  );
3132
3478
  },
3133
3479
  // A request id is accepted once per phone, across restarts; ids older than the queue's 7 days are forgotten.
3134
- firstPhoneRequest(deviceId, requestId) {
3480
+ firstPhoneRequest(
3481
+ deviceId,
3482
+ requestId,
3483
+ { sealedBy = null, gesture = null } = {}
3484
+ ) {
3135
3485
  const now = new Date();
3136
3486
  execute(
3137
3487
  "run",
@@ -3149,13 +3499,35 @@ export function openStore(file) {
3149
3499
  return false;
3150
3500
  execute(
3151
3501
  "run",
3152
- "insert into phone_requests(device_id, request_id, received_at) values(?, ?, ?)",
3502
+ "insert into phone_requests(device_id, request_id, received_at, sealed_by, gesture) values(?, ?, ?, ?, ?)",
3153
3503
  deviceId,
3154
3504
  requestId,
3155
- now.toISOString()
3505
+ now.toISOString(),
3506
+ sealedBy,
3507
+ gesture === null ? null : gesture ? 1 : 0
3156
3508
  );
3157
3509
  return true;
3158
3510
  },
3511
+ // A device that moved its link to a new key: the old one opens nothing from now on.
3512
+ rekeyPhone(id, publicKey) {
3513
+ execute(
3514
+ "run",
3515
+ "update phone_devices set public_key = ? where id = ? and revoked_at is null",
3516
+ publicKey,
3517
+ id
3518
+ );
3519
+ },
3520
+ /** What sealed one call from a device: its kind of key and, for the extension's, whether the person was acting. */
3521
+ sealedCall(deviceId, requestId) {
3522
+ return (
3523
+ execute(
3524
+ "get",
3525
+ "select sealed_by, gesture from phone_requests where device_id = ? and request_id = ?",
3526
+ deviceId,
3527
+ requestId
3528
+ ) || null
3529
+ );
3530
+ },
3159
3531
  touchPhone(id) {
3160
3532
  execute(
3161
3533
  "run",
@@ -3196,6 +3568,15 @@ export function openStore(file) {
3196
3568
  now
3197
3569
  );
3198
3570
  },
3571
+ // Which agents called the board from which computer since `since`: where an agent that runs itself (Hermes, OpenClaw)
3572
+ // lives, since the daemon never starts it.
3573
+ agentsSeenOnComputers(since) {
3574
+ return execute(
3575
+ "all",
3576
+ "select agent, machine from board_agent_computers where last_seen_at >= ? order by agent",
3577
+ since
3578
+ );
3579
+ },
3199
3580
  // When each agent last called the board, from any computer.
3200
3581
  agentsSeen() {
3201
3582
  return execute(
@@ -3399,6 +3780,9 @@ export function openStore(file) {
3399
3780
  origin_chain: JSON.parse(row.origin_chain || "[]"),
3400
3781
  usage: row.usage ? JSON.parse(row.usage) : null,
3401
3782
  run_model: row.run_model ? JSON.parse(row.run_model) : null,
3783
+ audit: row.audit ? JSON.parse(row.audit) : null,
3784
+ checked: row.checked ? JSON.parse(row.checked) : null,
3785
+ returned: row.returned ? JSON.parse(row.returned) : null,
3402
3786
  stale:
3403
3787
  row.status === "claimed" &&
3404
3788
  Boolean(row.lease_until) &&
@@ -3435,7 +3819,7 @@ export function openStore(file) {
3435
3819
  "a task for several agents is worked through its parts; claim the part posted for you",
3436
3820
  };
3437
3821
  // A goal is a room the team works in, not a task to take: a claimed goal turned away the claimer's own posts and
3438
- // could not be released (October 14, Codex in the keeper thread).
3822
+ // could not be released.
3439
3823
  if (this.getTask(id)?.kind === "goal")
3440
3824
  return {
3441
3825
  ok: false,