tryharness 0.7.45 → 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 (125) hide show
  1. package/README.md +239 -14
  2. package/assets/dsh-plugin.mjs +72 -0
  3. package/assets/opencode-plugin.js +4 -3
  4. package/cli.mjs +497 -196
  5. package/lib/actorRoster.mjs +28 -5
  6. package/lib/adapters.mjs +165 -222
  7. package/lib/agentRuntimeConfig.mjs +36 -0
  8. package/lib/agentRuntimes.mjs +570 -0
  9. package/lib/agentSignIn.mjs +226 -0
  10. package/lib/atlas.mjs +7 -2
  11. package/lib/audit.mjs +643 -0
  12. package/lib/backupSetup.mjs +141 -0
  13. package/lib/boardAccess.mjs +8 -1
  14. package/lib/boardBackup.mjs +283 -0
  15. package/lib/boardCommands.mjs +5 -10
  16. package/lib/boardFileCommands.mjs +2 -1
  17. package/lib/boardMirror.mjs +523 -0
  18. package/lib/boardProtocol.json +263 -6
  19. package/lib/boardTools.mjs +2 -6
  20. package/lib/boardWaits.mjs +102 -0
  21. package/lib/book.mjs +659 -0
  22. package/lib/bridge.mjs +26 -4
  23. package/lib/browserWake.mjs +60 -0
  24. package/lib/cards.mjs +159 -16
  25. package/lib/cloudBoot.mjs +124 -0
  26. package/lib/commands.mjs +25 -5
  27. package/lib/connectionTools.d.ts +13 -0
  28. package/lib/connectionTools.js +45 -0
  29. package/lib/connectorAuth.mjs +309 -0
  30. package/lib/connectorCatalog.json +41 -0
  31. package/lib/connectorCommands.mjs +121 -0
  32. package/lib/connectorGoogle.mjs +513 -0
  33. package/lib/connectors.mjs +805 -0
  34. package/lib/context.mjs +18 -4
  35. package/lib/contractGate.mjs +377 -0
  36. package/lib/coordinator.mjs +152 -39
  37. package/lib/coreModels.mjs +78 -0
  38. package/lib/daemon.mjs +973 -54
  39. package/lib/desk.mjs +239 -0
  40. package/lib/desktop.mjs +113 -8
  41. package/lib/digest.mjs +32 -0
  42. package/lib/directLink.mjs +283 -0
  43. package/lib/environments.mjs +825 -0
  44. package/lib/folders.mjs +4 -4
  45. package/lib/gitHost.mjs +174 -0
  46. package/lib/goalCommands.mjs +58 -14
  47. package/lib/hookDialects.mjs +298 -0
  48. package/lib/inference.mjs +263 -152
  49. package/lib/landed.mjs +887 -0
  50. package/lib/lessons.mjs +6 -0
  51. package/lib/lineup.mjs +324 -0
  52. package/lib/live.mjs +284 -13
  53. package/lib/localmodels.mjs +10 -0
  54. package/lib/machineIdentity.mjs +3 -0
  55. package/lib/machineRoutes.mjs +40 -2
  56. package/lib/machineRuns.mjs +30 -3
  57. package/lib/machineSeal.mjs +69 -10
  58. package/lib/mcp-stdio.mjs +189 -120
  59. package/lib/mcpRelay.mjs +119 -0
  60. package/lib/members.json +26 -0
  61. package/lib/members.mjs +33 -0
  62. package/lib/modelMemory.mjs +100 -0
  63. package/lib/models.mjs +48 -15
  64. package/lib/museSession.mjs +122 -0
  65. package/lib/nativeHost.mjs +203 -0
  66. package/lib/neovim.mjs +126 -0
  67. package/lib/network.mjs +7 -2
  68. package/lib/nudge.mjs +57 -18
  69. package/lib/onboard.mjs +430 -1
  70. package/lib/oneclawLocal.mjs +150 -0
  71. package/lib/ownMachines.mjs +828 -39
  72. package/lib/pairing.mjs +182 -0
  73. package/lib/paths.mjs +8 -0
  74. package/lib/personModel.mjs +89 -0
  75. package/lib/phones.mjs +119 -3
  76. package/lib/placeCommands.mjs +27 -0
  77. package/lib/places.mjs +337 -9
  78. package/lib/plans.mjs +151 -27
  79. package/lib/profile.mjs +152 -0
  80. package/lib/projects.mjs +624 -137
  81. package/lib/readiness.mjs +400 -0
  82. package/lib/record.mjs +115 -0
  83. package/lib/repoLinks.mjs +354 -0
  84. package/lib/roomChannels.mjs +641 -0
  85. package/lib/runBrief.mjs +32 -2
  86. package/lib/runRequests.mjs +157 -0
  87. package/lib/runWorker.mjs +37 -9
  88. package/lib/runner.mjs +74 -11
  89. package/lib/secretPatterns.json +55 -0
  90. package/lib/secrets.mjs +10 -27
  91. package/lib/seen.mjs +102 -0
  92. package/lib/service.mjs +11 -6
  93. package/lib/sessionControl.mjs +386 -96
  94. package/lib/sessionIndex.mjs +5 -3
  95. package/lib/specialties.json +74 -0
  96. package/lib/specialties.mjs +477 -0
  97. package/lib/specialtyKeys.d.ts +3 -0
  98. package/lib/specialtyKeys.js +58 -0
  99. package/lib/specialtyNotice.mjs +147 -0
  100. package/lib/specialtySnapshot.mjs +138 -0
  101. package/lib/store.mjs +829 -29
  102. package/lib/subagents.mjs +8 -4
  103. package/lib/swarm.mjs +483 -37
  104. package/lib/swarmMemory.mjs +947 -0
  105. package/lib/t3.mjs +56 -17
  106. package/lib/taskCommands.mjs +91 -13
  107. package/lib/taskRuns.mjs +68 -11
  108. package/lib/team.json +253 -144
  109. package/lib/team.mjs +538 -147
  110. package/lib/threadLine.mjs +116 -0
  111. package/lib/threadRuns.mjs +78 -12
  112. package/lib/threadView.mjs +66 -16
  113. package/lib/tokenizer.mjs +405 -0
  114. package/lib/ui.mjs +16 -2
  115. package/lib/usageTotals.mjs +148 -0
  116. package/lib/vault.mjs +1144 -0
  117. package/lib/vaultCloud.mjs +117 -0
  118. package/lib/vaultCommands.mjs +201 -0
  119. package/lib/vaultTools.d.ts +12 -0
  120. package/lib/vaultTools.js +42 -0
  121. package/lib/windowAsks.mjs +42 -0
  122. package/lib/workFocus.mjs +59 -0
  123. package/lib/workLinks.mjs +90 -0
  124. package/lib/worktrees.mjs +51 -13
  125. package/package.json +10 -5
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;
@@ -27,6 +28,41 @@ export const DEFAULT_DAILY_RUNS = 10;
27
28
  export const FAILURE_CAUSES = ["person", "start", "exit", "agent"];
28
29
  // An agent's record leaves out failures that say nothing about it: the person's stop and a run that never started.
29
30
  const AGENTS_OWN = "not (status = 'failed' and failure in ('person', 'start'))";
31
+ // What the swarm's memory can show (swarmMemory.mjs): what was said, made, checked or asked in the person's threads and
32
+ // tasks. A contribution's thread is its own task when that is a thread, else its task's parent thread.
33
+ export const MEMORY_KINDS = [
34
+ "post",
35
+ "result",
36
+ "receipt",
37
+ "failed",
38
+ "answer",
39
+ "question",
40
+ "goal",
41
+ "job",
42
+ "file",
43
+ ];
44
+ const MEMORY_SELECT = `select c.id, c.task_id, c.seq, c.kind, c.author, c.text, c.source, c.created_at,
45
+ case when t.kind = 'goal' then t.id when p.kind = 'goal' then p.id end as thread,
46
+ case when t.kind = 'goal' then t.objective when p.kind = 'goal' then p.objective else t.objective end as thread_title`;
47
+ const MEMORY_JOINS = `join board_tasks t on t.id = c.task_id left join board_tasks p on p.id = t.parent_id
48
+ left join board_memory_marks m on m.contribution_id = c.id`;
49
+ const MEMORY_WHERE = `c.kind in (${MEMORY_KINDS.map((kind) => `'${kind}'`).join(", ")}) and m.contribution_id is null`;
50
+ const PURGED = "[deleted at the person's request]";
51
+ // A full-text query for any of a text's words longer than two letters, or null with none.
52
+ const anyWordOf = (text) => {
53
+ const terms = [
54
+ ...new Set(
55
+ String(text)
56
+ .toLowerCase()
57
+ .match(/[\p{L}\p{N}_-]+/gu) || []
58
+ ),
59
+ ]
60
+ .filter((term) => term.length > 2)
61
+ .slice(0, 24);
62
+ return terms.length
63
+ ? terms.map((term) => `"${term.replaceAll('"', '""')}"`).join(" OR ")
64
+ : null;
65
+ };
30
66
  // A room post as readers get it. A file attached in the room names it, so a reader can show the file itself.
31
67
  const roomPostOf = ({ source, ...row }) => ({
32
68
  ...row,
@@ -104,6 +140,10 @@ export function openStore(file) {
104
140
  failure text,
105
141
  target_machine text,
106
142
  claimed_machine text,
143
+ specialty text,
144
+ step text,
145
+ checked text,
146
+ audit text,
107
147
  created_at text not null,
108
148
  updated_at text not null
109
149
  );
@@ -134,6 +174,12 @@ export function openStore(file) {
134
174
  agent text primary key,
135
175
  last_seen_at text not null
136
176
  );
177
+ create table if not exists board_agent_computers (
178
+ agent text not null,
179
+ machine text not null,
180
+ last_seen_at text not null,
181
+ primary key (agent, machine)
182
+ );
137
183
  create table if not exists board_threads (
138
184
  task_id text primary key,
139
185
  with_agent text not null,
@@ -238,6 +284,39 @@ export function openStore(file) {
238
284
  updated_at text not null
239
285
  );
240
286
  create virtual table if not exists board_lessons_fts using fts5(id unindexed, text, tokenize='unicode61');
287
+ create table if not exists board_memory_marks (
288
+ contribution_id text primary key,
289
+ state text not null,
290
+ by text not null,
291
+ reason text,
292
+ replaced_by text,
293
+ at text not null
294
+ );
295
+ create table if not exists board_observations (
296
+ id text primary key,
297
+ kind text not null,
298
+ agent text,
299
+ folder text,
300
+ text text not null,
301
+ evidence text not null default '[]',
302
+ history text not null default '[]',
303
+ status text not null default 'active',
304
+ vector blob,
305
+ created_at text not null,
306
+ updated_at text not null
307
+ );
308
+ create virtual table if not exists board_observations_fts using fts5(id unindexed, text, tokenize='unicode61');
309
+ -- What the person saw, as their Harness window describes it (seen.mjs): read on this computer only, never sent on.
310
+ create table if not exists board_seen (
311
+ id text primary key,
312
+ window text not null,
313
+ frame_ref integer not null,
314
+ at text not null,
315
+ text text not null,
316
+ frames integer not null,
317
+ created_at text not null
318
+ );
319
+ create virtual table if not exists board_seen_fts using fts5(id unindexed, text, tokenize='unicode61');
241
320
  create table if not exists team_notes (
242
321
  id text primary key,
243
322
  agent text not null,
@@ -280,7 +359,46 @@ export function openStore(file) {
280
359
  at text not null
281
360
  );
282
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
+ );
283
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);
284
402
  const sessionColumns = new Set(
285
403
  db.all("pragma table_info(sessions)").map((column) => column.name)
286
404
  );
@@ -307,6 +425,13 @@ export function openStore(file) {
307
425
  .some((column) => column.name === "mentions")
308
426
  )
309
427
  db.exec("alter table board_contributions add column mentions text");
428
+ // The computer an agent wrote from, so readers can tell Codex on the Mac from Codex on the linux computer.
429
+ if (
430
+ !db
431
+ .all("pragma table_info(board_contributions)")
432
+ .some((column) => column.name === "machine")
433
+ )
434
+ db.exec("alter table board_contributions add column machine text");
310
435
  // Devices paired before browsers could pair were all phones.
311
436
  if (
312
437
  !db
@@ -379,6 +504,14 @@ export function openStore(file) {
379
504
  db.exec(
380
505
  "alter table board_tasks add column target_machine text; alter table board_tasks add column claimed_machine text"
381
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");
382
515
 
383
516
  const statements = [];
384
517
  const prepare = (sql) => {
@@ -519,6 +652,40 @@ export function openStore(file) {
519
652
  });
520
653
  return parsed.meta;
521
654
  },
655
+ // One UTC day of the board's work as counts by agent, for the anonymous daily totals
656
+ // (usageTotals.mjs). Only numbers and agent ids leave here, never text, ids or folders.
657
+ usageOfDay(day) {
658
+ const countBy = (sql) =>
659
+ execute("all", sql, day).map((row) => ({
660
+ name: row.name ?? null,
661
+ count: Number(row.count),
662
+ }));
663
+ const total = (sql) => Number(execute("get", sql, day).count);
664
+ return {
665
+ posted: countBy(
666
+ "select target_agent as name, count(*) as count from board_tasks where kind = 'task' and substr(created_at, 1, 10) = ? group by target_agent"
667
+ ),
668
+ handoffs: total(
669
+ "select count(*) as count from board_tasks where kind = 'task' and origin_agent != 'user' and substr(created_at, 1, 10) = ?"
670
+ ),
671
+ done: countBy(
672
+ "select coalesce(target_agent, claimed_by) as name, count(*) as count from board_tasks where kind = 'task' and status = 'done' and substr(coalesce(reported_at, updated_at), 1, 10) = ? group by 1"
673
+ ),
674
+ // A task the person removed is marked failed with failure 'person'; that is not a failure of the work.
675
+ failed: countBy(
676
+ "select coalesce(target_agent, claimed_by) as name, count(*) as count from board_tasks where kind = 'task' and status = 'failed' and coalesce(failure, '') != 'person' and substr(coalesce(reported_at, updated_at), 1, 10) = ? group by 1"
677
+ ),
678
+ threadsStarted: total(
679
+ "select count(*) as count from board_tasks where kind = 'goal' and substr(created_at, 1, 10) = ?"
680
+ ),
681
+ posts: countBy(
682
+ "select author as name, count(*) as count from board_contributions where substr(created_at, 1, 10) = ? group by author"
683
+ ),
684
+ rounds: countBy(
685
+ "select action as name, count(*) as count from swarm_rounds where substr(at, 1, 10) = ? group by action"
686
+ ),
687
+ };
688
+ },
522
689
  endedSince(since) {
523
690
  const rows = execute(
524
691
  "all",
@@ -883,6 +1050,136 @@ export function openStore(file) {
883
1050
  String(value)
884
1051
  );
885
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
+ },
886
1183
  // A goal: one objective the owner set for a team of agents, worked in its room (the goal's contributions). The goal
887
1184
  // is a board task of kind 'goal'; its team, facilitator, folder and backstops live beside it. Jobs and wakes are its
888
1185
  // children, authorized by the goal (run_authorized_by 'goal') and counted in its spend.
@@ -1058,13 +1355,21 @@ export function openStore(file) {
1058
1355
  spend.cost_usd = Math.round(spend.cost_usd * 1e6) / 1e6;
1059
1356
  return spend;
1060
1357
  },
1061
- roomPost({ goalId, author, kind = "post", text, mentions = [] }) {
1358
+ roomPost({
1359
+ goalId,
1360
+ author,
1361
+ kind = "post",
1362
+ text,
1363
+ mentions = [],
1364
+ machine = null,
1365
+ }) {
1062
1366
  const post = this.addContribution({
1063
1367
  taskId: goalId,
1064
1368
  kind,
1065
1369
  author,
1066
1370
  text,
1067
1371
  source: "room",
1372
+ machine,
1068
1373
  });
1069
1374
  if (post && mentions.length)
1070
1375
  execute(
@@ -1088,7 +1393,7 @@ export function openStore(file) {
1088
1393
  roomPosts(goalId, since = 0, limit = 200) {
1089
1394
  return execute(
1090
1395
  "all",
1091
- "select id, seq, kind, author, text, mentions, source, created_at from board_contributions where task_id = ? and seq > ? and kind != 'held' order by seq asc limit ?",
1396
+ "select id, seq, kind, author, machine, text, mentions, source, created_at from board_contributions where task_id = ? and seq > ? and kind != 'held' order by seq asc limit ?",
1092
1397
  goalId,
1093
1398
  Number(since) || 0,
1094
1399
  Math.max(1, Math.min(500, Number(limit) || 200))
@@ -1101,7 +1406,7 @@ export function openStore(file) {
1101
1406
  const count = Math.max(1, Math.min(500, Number(limit) || 30));
1102
1407
  const rows = execute(
1103
1408
  "all",
1104
- "select id, seq, kind, author, text, mentions, source, created_at from board_contributions where task_id = ? and seq < ? and kind != 'held' order by seq desc limit ?",
1409
+ "select id, seq, kind, author, machine, text, mentions, source, created_at from board_contributions where task_id = ? and seq < ? and kind != 'held' order by seq desc limit ?",
1105
1410
  goalId,
1106
1411
  Number(before) > 0 ? Number(before) : Number.MAX_SAFE_INTEGER,
1107
1412
  count + 1
@@ -1430,6 +1735,352 @@ export function openStore(file) {
1430
1735
  "select id, vector from board_lessons where status = 'active' and vector is not null"
1431
1736
  );
1432
1737
  },
1738
+ // A lesson the dream read as an instruction for one job (swarmMemory.mjs): out of the work, on record with why,
1739
+ // and back with restoreLesson.
1740
+ retireLesson(id, why) {
1741
+ const lesson = this.getLesson(id);
1742
+ if (!lesson || lesson.status !== "active") return null;
1743
+ execute(
1744
+ "run",
1745
+ "update board_lessons set status = 'retired', evidence = ?, updated_at = ? where id = ?",
1746
+ JSON.stringify(
1747
+ [
1748
+ ...lesson.evidence,
1749
+ { retired: why, at: new Date().toISOString() },
1750
+ ].slice(-20)
1751
+ ),
1752
+ new Date().toISOString(),
1753
+ id
1754
+ );
1755
+ execute("run", "delete from board_lessons_fts where id = ?", id);
1756
+ return this.getLesson(id);
1757
+ },
1758
+ // A lesson learned in one folder that holds for all the person's work.
1759
+ widenLesson(id) {
1760
+ execute(
1761
+ "run",
1762
+ "update board_lessons set scope = 'everywhere', folder = null, updated_at = ? where id = ? and status = 'active'",
1763
+ new Date().toISOString(),
1764
+ id
1765
+ );
1766
+ return this.getLesson(id);
1767
+ },
1768
+
1769
+ // ── The swarm's memory (swarmMemory.mjs) ──────────────────────────────────
1770
+ // Every post, result, receipt and job in the person's threads and tasks, each with the thread it belongs to (a job's
1771
+ // thread is its parent). Briefs, context packs, coordinator notes and records are the swarm's plumbing, not what
1772
+ // was said or done; posts the guard held never come back; nor does anything the person had forgotten or replaced.
1773
+ // The first twelve words of a query, as searchThreads read them (eval memory-lane: with 24, long job results that
1774
+ // share many common words crowded out the person's own earlier posts).
1775
+ memoryWords(query, limit = 60) {
1776
+ const terms = [
1777
+ ...new Set(
1778
+ String(query)
1779
+ .toLowerCase()
1780
+ .match(/[\p{L}\p{N}_-]+/gu) || []
1781
+ ),
1782
+ ]
1783
+ .filter((term) => term.length > 1)
1784
+ .slice(0, 12);
1785
+ if (!terms.length) return [];
1786
+ const match = terms
1787
+ .map((term) => `"${term.replaceAll('"', '""')}"`)
1788
+ .join(" OR ");
1789
+ return execute(
1790
+ "all",
1791
+ `${MEMORY_SELECT}, bm25(board_contributions_fts) as rank
1792
+ from board_contributions_fts f join board_contributions c on c.id = f.id ${MEMORY_JOINS}
1793
+ where board_contributions_fts match @match and ${MEMORY_WHERE}
1794
+ order by rank limit @limit`,
1795
+ { match, limit: Math.max(1, Math.min(200, limit)) }
1796
+ );
1797
+ },
1798
+ memoryPosts(ids) {
1799
+ if (!ids.length) return [];
1800
+ const wanted = [...new Set(ids)];
1801
+ const rows = execute(
1802
+ "all",
1803
+ `${MEMORY_SELECT} from board_contributions c ${MEMORY_JOINS}
1804
+ where c.id in (${wanted.map(() => "?").join(", ")}) and ${MEMORY_WHERE}`,
1805
+ ...wanted
1806
+ );
1807
+ const byId = new Map(rows.map((row) => [row.id, row]));
1808
+ return wanted.map((id) => byId.get(id)).filter(Boolean);
1809
+ },
1810
+ // The receipts of jobs and runs in these threads, newest first: written by code from each run's own session, they
1811
+ // come with any post of their thread that recall finds (a receipt names no subject of its own).
1812
+ memoryReceipts(threadIds, limit = 3) {
1813
+ if (!threadIds.length) return [];
1814
+ return execute(
1815
+ "all",
1816
+ `${MEMORY_SELECT} from board_contributions c ${MEMORY_JOINS}
1817
+ where c.kind = 'receipt' and t.parent_id in (${threadIds.map(() => "?").join(", ")}) and ${MEMORY_WHERE}
1818
+ order by c.created_at desc limit ${Math.max(1, Math.min(20, limit)) * threadIds.length}`,
1819
+ ...threadIds
1820
+ );
1821
+ },
1822
+ // What memory can show that was written after a moment, oldest first: the dream's new facts.
1823
+ memoryAfter(since = "", limit = 500) {
1824
+ return execute(
1825
+ "all",
1826
+ `${MEMORY_SELECT} from board_contributions c ${MEMORY_JOINS}
1827
+ where c.created_at > @since and ${MEMORY_WHERE} order by c.created_at limit @limit`,
1828
+ { since, limit: Math.max(1, Math.min(5000, limit)) }
1829
+ );
1830
+ },
1831
+ // The search model's vectors of what memory can show, written after a moment (newest last), for the module's cache.
1832
+ memoryVectors(version, since = "") {
1833
+ return execute(
1834
+ "all",
1835
+ `select c.id, c.created_at, v.vector from board_vectors v join board_contributions c on c.id = v.contribution_id
1836
+ ${MEMORY_JOINS} where v.version = @version and c.created_at > @since and ${MEMORY_WHERE}
1837
+ order by c.created_at`,
1838
+ { version, since }
1839
+ );
1840
+ },
1841
+ // Released (out of recall and briefs, still in the thread), purged (its words gone everywhere) or replaced (a
1842
+ // later post of the person's changed it).
1843
+ markMemory(id, { state, by, reason = null, replacedBy = null }) {
1844
+ execute(
1845
+ "run",
1846
+ `insert or replace into board_memory_marks(contribution_id, state, by, reason, replaced_by, at)
1847
+ values(?, ?, ?, ?, ?, ?)`,
1848
+ id,
1849
+ state,
1850
+ by,
1851
+ reason,
1852
+ replacedBy,
1853
+ new Date().toISOString()
1854
+ );
1855
+ },
1856
+ unmarkMemory(id) {
1857
+ const mark = execute(
1858
+ "get",
1859
+ "select * from board_memory_marks where contribution_id = ?",
1860
+ id
1861
+ );
1862
+ if (!mark || mark.state === "purged") return null;
1863
+ execute(
1864
+ "run",
1865
+ "delete from board_memory_marks where contribution_id = ?",
1866
+ id
1867
+ );
1868
+ return mark;
1869
+ },
1870
+ memoryMarks({ by = null } = {}) {
1871
+ return by
1872
+ ? execute("all", "select * from board_memory_marks where by = ?", by)
1873
+ : execute("all", "select * from board_memory_marks");
1874
+ },
1875
+ // Deleted for good at the person's request: the words leave the post, its search entry and its vector; the post
1876
+ // stays as a placeholder so the thread still reads in order.
1877
+ purgeMemory(id, { by, reason = null }) {
1878
+ execute(
1879
+ "run",
1880
+ "update board_contributions set text = ? where id = ?",
1881
+ PURGED,
1882
+ id
1883
+ );
1884
+ execute("run", "delete from board_contributions_fts where id = ?", id);
1885
+ execute("run", "delete from board_vectors where contribution_id = ?", id);
1886
+ this.markMemory(id, { state: "purged", by, reason });
1887
+ },
1888
+
1889
+ // What the dream (swarmMemory.mjs) keeps: beliefs consolidated from many posts, each standing on their exact words
1890
+ // (`evidence`, whose length is how often it was borne out) and keeping what it said before it changed (`history`).
1891
+ addObservation({ kind, agent = null, folder = null, text, evidence }) {
1892
+ const id = randomUUID();
1893
+ const now = new Date().toISOString();
1894
+ execute(
1895
+ "run",
1896
+ `insert into board_observations(id, kind, agent, folder, text, evidence, created_at, updated_at)
1897
+ values(?, ?, ?, ?, ?, ?, ?, ?)`,
1898
+ id,
1899
+ kind,
1900
+ agent,
1901
+ folder,
1902
+ text,
1903
+ JSON.stringify(evidence),
1904
+ now,
1905
+ now
1906
+ );
1907
+ execute(
1908
+ "run",
1909
+ "insert into board_observations_fts(id, text) values(?, ?)",
1910
+ id,
1911
+ text
1912
+ );
1913
+ return this.getObservation(id);
1914
+ },
1915
+ getObservation(id) {
1916
+ const row = execute(
1917
+ "get",
1918
+ "select * from board_observations where id = ?",
1919
+ id
1920
+ );
1921
+ if (!row) return null;
1922
+ const { vector, ...observation } = row;
1923
+ const evidence = JSON.parse(observation.evidence || "[]");
1924
+ return {
1925
+ ...observation,
1926
+ evidence,
1927
+ history: JSON.parse(observation.history || "[]"),
1928
+ proof: evidence.length,
1929
+ embedded: Boolean(vector),
1930
+ };
1931
+ },
1932
+ // Borne out again: the same belief gains the new words.
1933
+ confirmObservation(id, evidence) {
1934
+ const observation = this.getObservation(id);
1935
+ if (!observation || observation.status !== "active") return null;
1936
+ execute(
1937
+ "run",
1938
+ "update board_observations set evidence = ?, updated_at = ? where id = ?",
1939
+ JSON.stringify([...observation.evidence, ...evidence].slice(-30)),
1940
+ new Date().toISOString(),
1941
+ id
1942
+ );
1943
+ return this.getObservation(id);
1944
+ },
1945
+ // Changed by later words: the new belief takes its place, the old one stays in its history with when and why.
1946
+ reviseObservation(id, { text, evidence, why }) {
1947
+ const observation = this.getObservation(id);
1948
+ if (!observation || observation.status !== "active") return null;
1949
+ const now = new Date().toISOString();
1950
+ execute(
1951
+ "run",
1952
+ "update board_observations set text = ?, evidence = ?, history = ?, vector = null, updated_at = ? where id = ?",
1953
+ text,
1954
+ JSON.stringify([...observation.evidence, ...evidence].slice(-30)),
1955
+ JSON.stringify(
1956
+ [
1957
+ ...observation.history,
1958
+ { text: observation.text, until: now, why },
1959
+ ].slice(-20)
1960
+ ),
1961
+ now,
1962
+ id
1963
+ );
1964
+ execute("run", "delete from board_observations_fts where id = ?", id);
1965
+ execute(
1966
+ "run",
1967
+ "insert into board_observations_fts(id, text) values(?, ?)",
1968
+ id,
1969
+ text
1970
+ );
1971
+ return this.getObservation(id);
1972
+ },
1973
+ // Out of the work (`retired` by the dream, `removed` by the person), on record; back with restoreObservation.
1974
+ setObservationStatus(id, status) {
1975
+ const observation = this.getObservation(id);
1976
+ if (!observation) return null;
1977
+ execute(
1978
+ "run",
1979
+ "update board_observations set status = ?, updated_at = ? where id = ?",
1980
+ status,
1981
+ new Date().toISOString(),
1982
+ id
1983
+ );
1984
+ execute("run", "delete from board_observations_fts where id = ?", id);
1985
+ if (status === "active")
1986
+ execute(
1987
+ "run",
1988
+ "insert into board_observations_fts(id, text) values(?, ?)",
1989
+ id,
1990
+ observation.text
1991
+ );
1992
+ return this.getObservation(id);
1993
+ },
1994
+ observations({ status = "active", limit = 500 } = {}) {
1995
+ return execute(
1996
+ "all",
1997
+ "select id from board_observations where status = ? order by updated_at desc limit ?",
1998
+ status,
1999
+ Math.max(1, Math.min(5000, Number(limit) || 500))
2000
+ ).map((row) => this.getObservation(row.id));
2001
+ },
2002
+ observationsMatching(query, limit = 6) {
2003
+ const match = anyWordOf(query);
2004
+ if (!match) return [];
2005
+ return execute(
2006
+ "all",
2007
+ `select f.id from board_observations_fts f join board_observations o on o.id = f.id
2008
+ where board_observations_fts match ? and o.status = 'active' order by bm25(board_observations_fts) limit ?`,
2009
+ match,
2010
+ limit
2011
+ ).map((row) => this.getObservation(row.id));
2012
+ },
2013
+ setObservationVector(id, vector) {
2014
+ execute(
2015
+ "run",
2016
+ "update board_observations set vector = ? where id = ?",
2017
+ vector,
2018
+ id
2019
+ );
2020
+ },
2021
+ observationVectors() {
2022
+ return execute(
2023
+ "all",
2024
+ "select id, vector from board_observations where status = 'active' and vector is not null"
2025
+ );
2026
+ },
2027
+ // ── What the person saw (seen.mjs) ──
2028
+ addSeen({ window, ref, at, text, frames }) {
2029
+ const id = `${window}:${ref}`;
2030
+ if (execute("get", "select id from board_seen where id = ?", id))
2031
+ return false;
2032
+ execute(
2033
+ "run",
2034
+ `insert into board_seen(id, window, frame_ref, at, text, frames, created_at)
2035
+ values(?, ?, ?, ?, ?, ?, ?)`,
2036
+ id,
2037
+ window,
2038
+ ref,
2039
+ at,
2040
+ text,
2041
+ frames,
2042
+ new Date().toISOString()
2043
+ );
2044
+ execute(
2045
+ "run",
2046
+ "insert into board_seen_fts(id, text) values(?, ?)",
2047
+ id,
2048
+ text
2049
+ );
2050
+ return true;
2051
+ },
2052
+ seen({ limit = 200 } = {}) {
2053
+ return execute(
2054
+ "all",
2055
+ "select * from board_seen order by at desc limit ?",
2056
+ Math.max(1, Math.min(5000, Number(limit) || 200))
2057
+ );
2058
+ },
2059
+ seenRefs(window, limit = 200) {
2060
+ return execute(
2061
+ "all",
2062
+ "select frame_ref from board_seen where window = ? order by at desc limit ?",
2063
+ window,
2064
+ limit
2065
+ ).map((row) => row.frame_ref);
2066
+ },
2067
+ seenMatching(query, limit = 6) {
2068
+ const match = anyWordOf(query);
2069
+ if (!match) return [];
2070
+ return execute(
2071
+ "all",
2072
+ `select s.* from board_seen_fts f join board_seen s on s.id = f.id
2073
+ where board_seen_fts match ? order by bm25(board_seen_fts) limit ?`,
2074
+ match,
2075
+ limit
2076
+ );
2077
+ },
2078
+ removeSeen(id) {
2079
+ execute("run", "delete from board_seen_fts where id = ?", id);
2080
+ return (
2081
+ execute("run", "delete from board_seen where id = ?", id).changes > 0
2082
+ );
2083
+ },
1433
2084
  // The person's reaction to an agent's work (reactions.mjs): a verdict per post of theirs for each agent it is about;
1434
2085
  // `aboutSeq` is the agent's post, null when the post reacts to what the agents made together.
1435
2086
  recordReaction({
@@ -1455,6 +2106,24 @@ export function openStore(file) {
1455
2106
  new Date().toISOString()
1456
2107
  );
1457
2108
  },
2109
+ // The person's approvals of agents' work recorded after a moment, oldest first (swarmMemory.mjs keeps each as a
2110
+ // decision): their post, the agent and verdict, the thread, and the work approved when it was one post.
2111
+ approvalsAfter(since = "", limit = 200) {
2112
+ return execute(
2113
+ "all",
2114
+ `select r.post_id, r.goal_id, r.agent, r.verdict, r.at, p.text as said, p.created_at as said_at,
2115
+ t.objective as thread_title, w.id as work_id, w.text as work
2116
+ from board_reactions r
2117
+ join board_contributions p on p.id = r.post_id
2118
+ join board_tasks t on t.id = r.goal_id
2119
+ left join board_contributions w on w.task_id = r.goal_id and w.seq = r.about_seq
2120
+ left join board_memory_marks m on m.contribution_id = r.post_id
2121
+ where r.verdict in ('approves', 'approves_with_changes') and r.at > ? and m.contribution_id is null
2122
+ order by r.at limit ?`,
2123
+ since,
2124
+ Math.max(1, Math.min(1000, limit))
2125
+ );
2126
+ },
1458
2127
  // The person's verdicts on each agent's work, for its card: { agent: { accepted, changes, rejected } }.
1459
2128
  verdictCounts() {
1460
2129
  const counts = {};
@@ -1676,15 +2345,78 @@ export function openStore(file) {
1676
2345
  threadRuns(goalId) {
1677
2346
  return execute(
1678
2347
  "all",
1679
- `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
1680
2349
  from board_tasks where parent_id = ? and kind in ('wake', 'task') order by created_at asc`,
1681
2350
  goalId
1682
2351
  ).map((row) => ({
1683
2352
  ...row,
1684
2353
  usage: row.usage ? JSON.parse(row.usage) : null,
1685
2354
  run_model: row.run_model ? JSON.parse(row.run_model) : null,
2355
+ checked: row.checked ? JSON.parse(row.checked) : null,
2356
+ }));
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,
1686
2400
  }));
1687
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
+ },
1688
2420
  // The coding sessions on this machine, newest first: the person's own and the ones runs started.
1689
2421
  recentSessions(limit = 30) {
1690
2422
  return execute(
@@ -1694,6 +2426,16 @@ export function openStore(file) {
1694
2426
  Math.max(1, Math.min(100, Number(limit) || 30))
1695
2427
  ).map((row) => ({ ...row, message_count: Number(row.message_count) }));
1696
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
+ },
1697
2439
  // The relay's own copy of a session (messages with tool calls clipped), for one whose source file is gone.
1698
2440
  sessionTranscript(agent, sessionId) {
1699
2441
  return (
@@ -1843,6 +2585,17 @@ export function openStore(file) {
1843
2585
  ) ?? null
1844
2586
  );
1845
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
+ },
1846
2599
  setRunSession(id, sessionId) {
1847
2600
  execute(
1848
2601
  "run",
@@ -1895,6 +2648,8 @@ export function openStore(file) {
1895
2648
  author,
1896
2649
  text,
1897
2650
  source = null,
2651
+ // The person's computer the author wrote from, when it is one of their agents on a computer.
2652
+ machine = null,
1898
2653
  }) {
1899
2654
  const body = String(text || "").trim();
1900
2655
  if (!body) return null;
@@ -1909,12 +2664,13 @@ export function openStore(file) {
1909
2664
  const now = new Date().toISOString();
1910
2665
  execute(
1911
2666
  "run",
1912
- "insert or ignore into board_contributions(id, task_id, seq, kind, author, text, source, created_at) values(?, ?, ?, ?, ?, ?, ?, ?)",
2667
+ "insert or ignore into board_contributions(id, task_id, seq, kind, author, machine, text, source, created_at) values(?, ?, ?, ?, ?, ?, ?, ?, ?)",
1913
2668
  id,
1914
2669
  taskId,
1915
2670
  seq,
1916
2671
  kind,
1917
2672
  author,
2673
+ machine,
1918
2674
  body.slice(0, 20_000),
1919
2675
  source,
1920
2676
  now
@@ -1983,7 +2739,8 @@ export function openStore(file) {
1983
2739
  vectorsFor(taskId, version) {
1984
2740
  return execute(
1985
2741
  "all",
1986
- "select v.contribution_id as id, v.vector from board_vectors v join board_contributions c on c.id = v.contribution_id where c.task_id = ? and v.version = ?",
2742
+ // Posts the guard held, and what the person released or purged, are never searched.
2743
+ "select v.contribution_id as id, v.vector from board_vectors v join board_contributions c on c.id = v.contribution_id left join board_memory_marks m on m.contribution_id = c.id where c.task_id = ? and v.version = ? and c.kind != 'held' and m.contribution_id is null",
1987
2744
  taskId,
1988
2745
  version
1989
2746
  );
@@ -2016,7 +2773,9 @@ export function openStore(file) {
2016
2773
  "all",
2017
2774
  `select c.id, c.task_id as thread, t.objective as thread_title, c.kind, c.author, c.text, c.created_at, bm25(board_contributions_fts) as rank
2018
2775
  from board_contributions_fts f join board_contributions c on c.id = f.id join board_tasks t on t.id = c.task_id
2019
- where board_contributions_fts match @match and t.kind = 'goal' order by rank limit 200`,
2776
+ left join board_memory_marks m on m.contribution_id = c.id
2777
+ where board_contributions_fts match @match and t.kind = 'goal' and c.kind != 'held' and m.contribution_id is null
2778
+ order by rank limit 200`,
2020
2779
  { match }
2021
2780
  )
2022
2781
  .filter((row) => !goalIds || goalIds.includes(row.thread))
@@ -2045,7 +2804,9 @@ export function openStore(file) {
2045
2804
  "all",
2046
2805
  `select c.id, c.kind, c.author, c.text, c.source, c.created_at, bm25(board_contributions_fts) as rank
2047
2806
  from board_contributions_fts f join board_contributions c on c.id = f.id
2048
- where board_contributions_fts match @match and f.task_id = @taskId order by rank limit @k`,
2807
+ left join board_memory_marks m on m.contribution_id = c.id
2808
+ where board_contributions_fts match @match and f.task_id = @taskId and c.kind != 'held' and m.contribution_id is null
2809
+ order by rank limit @k`,
2049
2810
  { match, taskId, k: Math.max(1, Math.min(50, k)) }
2050
2811
  ).map((row) => ({ ...row, score: -Number(row.rank) }));
2051
2812
  },
@@ -2114,6 +2875,13 @@ export function openStore(file) {
2114
2875
  );
2115
2876
  return this.ownMachine(machineId);
2116
2877
  },
2878
+ unpinOwnMachine(machineId) {
2879
+ execute(
2880
+ "run",
2881
+ "delete from own_machines where machine_id = ?",
2882
+ machineId
2883
+ );
2884
+ },
2117
2885
  ownMachines() {
2118
2886
  return execute(
2119
2887
  "all",
@@ -2554,14 +3322,22 @@ export function openStore(file) {
2554
3322
  task: this.getTask(taskId),
2555
3323
  };
2556
3324
  },
2557
- // Messages another person's agent sent on this agent's tasks since it last read the board.
2558
- lastSeenAt(agent) {
3325
+ // When this agent last called the board from `machine`, so Codex on the Mac and Codex on the linux computer each hear
3326
+ // what is new since they looked, not since the other did. An agent not yet seen there counts from when it last looked
3327
+ // anywhere, as it did before the board knew computers, so nothing old is told again.
3328
+ lastSeenAt(agent, machine = null) {
3329
+ const there = machine
3330
+ ? execute(
3331
+ "get",
3332
+ "select last_seen_at from board_agent_computers where agent = ? and machine = ?",
3333
+ agent,
3334
+ machine
3335
+ )?.last_seen_at
3336
+ : null;
2559
3337
  return (
2560
- execute(
2561
- "get",
2562
- "select last_seen_at from board_agents where agent = ?",
2563
- agent
2564
- )?.last_seen_at || null
3338
+ there ||
3339
+ this.agentsSeen().find((row) => row.agent === agent)?.last_seen_at ||
3340
+ null
2565
3341
  );
2566
3342
  },
2567
3343
  // Work an agent asked for that finished, failed or came back with a question since it last called the board: how an
@@ -2576,13 +3352,10 @@ export function openStore(file) {
2576
3352
  since || "1970-01-01T00:00:00.000Z"
2577
3353
  );
2578
3354
  },
2579
- unreadFor(agent) {
3355
+ // Messages another person's agent sent on this agent's tasks since it last read the board from `machine`.
3356
+ unreadFor(agent, machine = null) {
2580
3357
  const seen =
2581
- execute(
2582
- "get",
2583
- "select last_seen_at from board_agents where agent = ?",
2584
- agent
2585
- )?.last_seen_at || "1970-01-01T00:00:00.000Z";
3358
+ this.lastSeenAt(agent, machine) || "1970-01-01T00:00:00.000Z";
2586
3359
  return execute(
2587
3360
  "all",
2588
3361
  `select m.task_id, t.objective, m.sender, count(*) as count from board_messages m join board_tasks t on t.id = m.task_id
@@ -2676,18 +3449,42 @@ export function openStore(file) {
2676
3449
  );
2677
3450
  return { ok: true, phone: this.getPhone(id) };
2678
3451
  },
2679
- touchAgent(agent) {
2680
- execute(
2681
- "run",
2682
- "insert into board_agents(agent, last_seen_at) values(?, ?) on conflict(agent) do update set last_seen_at = excluded.last_seen_at",
2683
- agent,
2684
- new Date().toISOString()
3452
+ // When an agent last called the board, from `machine` when the call says which computer (every daemon's does): one
3453
+ // row a call, the same writes as before computers. A row without a computer is from before.
3454
+ touchAgent(agent, machine = null) {
3455
+ const now = new Date().toISOString();
3456
+ if (machine)
3457
+ execute(
3458
+ "run",
3459
+ "insert into board_agent_computers(agent, machine, last_seen_at) values(?, ?, ?) on conflict(agent, machine) do update set last_seen_at = excluded.last_seen_at",
3460
+ agent,
3461
+ machine,
3462
+ now
3463
+ );
3464
+ else
3465
+ execute(
3466
+ "run",
3467
+ "insert into board_agents(agent, last_seen_at) values(?, ?) on conflict(agent) do update set last_seen_at = excluded.last_seen_at",
3468
+ agent,
3469
+ now
3470
+ );
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
2685
3479
  );
2686
3480
  },
3481
+ // When each agent last called the board, from any computer.
2687
3482
  agentsSeen() {
2688
3483
  return execute(
2689
3484
  "all",
2690
- "select agent, last_seen_at from board_agents order by last_seen_at desc"
3485
+ `select agent, max(last_seen_at) as last_seen_at from (
3486
+ select agent, last_seen_at from board_agents union all select agent, last_seen_at from board_agent_computers
3487
+ ) group by agent order by last_seen_at desc`
2691
3488
  );
2692
3489
  },
2693
3490
  // Wakes sent to an agent's own gateway (wakes.mjs), one row per attempt: `outcome` is sent, refused, unsure (it may
@@ -2884,6 +3681,7 @@ export function openStore(file) {
2884
3681
  origin_chain: JSON.parse(row.origin_chain || "[]"),
2885
3682
  usage: row.usage ? JSON.parse(row.usage) : null,
2886
3683
  run_model: row.run_model ? JSON.parse(row.run_model) : null,
3684
+ audit: row.audit ? JSON.parse(row.audit) : null,
2887
3685
  stale:
2888
3686
  row.status === "claimed" &&
2889
3687
  Boolean(row.lease_until) &&
@@ -2995,6 +3793,7 @@ export function openStore(file) {
2995
3793
  author: agent,
2996
3794
  text: result,
2997
3795
  source: `report:${status}`,
3796
+ machine: machine ?? this.getTask(id)?.claimed_machine ?? null,
2998
3797
  });
2999
3798
  return { ok: true, task: this.getTask(id) };
3000
3799
  }
@@ -3028,7 +3827,7 @@ export function openStore(file) {
3028
3827
  : `task is ${task.status}`
3029
3828
  );
3030
3829
  },
3031
- answerTask(id, agent, answer, expectedVersion = null) {
3830
+ answerTask(id, agent, answer, expectedVersion = null, machine = null) {
3032
3831
  if (!String(answer || "").trim())
3033
3832
  return { ok: false, error: "an answer is needed" };
3034
3833
  const now = new Date().toISOString();
@@ -3053,6 +3852,7 @@ export function openStore(file) {
3053
3852
  author: agent,
3054
3853
  text: answer,
3055
3854
  source: "answer",
3855
+ machine,
3056
3856
  });
3057
3857
  return { ok: true, task: this.getTask(id) };
3058
3858
  }