tryharness 0.7.44 → 0.7.53

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 (101) hide show
  1. package/README.md +232 -12
  2. package/cli.mjs +406 -184
  3. package/lib/actorRoster.mjs +28 -5
  4. package/lib/adapters.mjs +9 -1
  5. package/lib/agentRuntimeConfig.mjs +36 -0
  6. package/lib/agentRuntimes.mjs +560 -0
  7. package/lib/atlas.mjs +7 -2
  8. package/lib/boardCommands.mjs +5 -10
  9. package/lib/boardFileCommands.mjs +2 -1
  10. package/lib/boardMirror.mjs +459 -0
  11. package/lib/boardProtocol.json +259 -6
  12. package/lib/boardTools.mjs +2 -6
  13. package/lib/bridge.mjs +27 -3
  14. package/lib/browserWake.mjs +60 -0
  15. package/lib/cards.mjs +35 -2
  16. package/lib/commands.mjs +20 -5
  17. package/lib/connectionTools.d.ts +13 -0
  18. package/lib/connectionTools.js +45 -0
  19. package/lib/connectorAuth.mjs +309 -0
  20. package/lib/connectorCatalog.json +41 -0
  21. package/lib/connectorCommands.mjs +121 -0
  22. package/lib/connectorGoogle.mjs +513 -0
  23. package/lib/connectors.mjs +805 -0
  24. package/lib/coordinator.mjs +16 -2
  25. package/lib/coreModels.mjs +78 -0
  26. package/lib/daemon.mjs +775 -46
  27. package/lib/desktop.mjs +7 -2
  28. package/lib/digest.mjs +32 -0
  29. package/lib/directLink.mjs +283 -0
  30. package/lib/environments.mjs +595 -0
  31. package/lib/folders.mjs +2 -2
  32. package/lib/goalCommands.mjs +61 -12
  33. package/lib/inference.mjs +263 -152
  34. package/lib/lessons.mjs +6 -0
  35. package/lib/lineup.mjs +324 -0
  36. package/lib/localmodels.mjs +10 -0
  37. package/lib/machineIdentity.mjs +3 -0
  38. package/lib/machineRoutes.mjs +40 -2
  39. package/lib/machineRuns.mjs +30 -3
  40. package/lib/machineSeal.mjs +69 -10
  41. package/lib/mcp-stdio.mjs +180 -98
  42. package/lib/mcpRelay.mjs +119 -0
  43. package/lib/members.json +12 -0
  44. package/lib/members.mjs +33 -0
  45. package/lib/modelMemory.mjs +100 -0
  46. package/lib/modelTiers.json +1183 -0
  47. package/lib/modelTiers.mjs +133 -0
  48. package/lib/models.mjs +41 -8
  49. package/lib/museSession.mjs +119 -0
  50. package/lib/nativeHost.mjs +203 -0
  51. package/lib/network.mjs +38 -1
  52. package/lib/nudge.mjs +10 -2
  53. package/lib/onboard.mjs +430 -1
  54. package/lib/oneclawLocal.mjs +150 -0
  55. package/lib/ownMachines.mjs +521 -36
  56. package/lib/pairing.mjs +165 -0
  57. package/lib/paths.mjs +4 -0
  58. package/lib/phones.mjs +61 -0
  59. package/lib/placeCommands.mjs +27 -0
  60. package/lib/places.mjs +10 -2
  61. package/lib/plans.mjs +151 -27
  62. package/lib/profile.mjs +152 -0
  63. package/lib/projectGit.mjs +328 -0
  64. package/lib/projectSettings.mjs +120 -0
  65. package/lib/projects.mjs +2539 -0
  66. package/lib/readiness.mjs +283 -0
  67. package/lib/repoLinks.mjs +354 -0
  68. package/lib/roomChannels.mjs +641 -0
  69. package/lib/runBrief.mjs +32 -2
  70. package/lib/runRequests.mjs +157 -0
  71. package/lib/runWorker.mjs +20 -7
  72. package/lib/runner.mjs +67 -8
  73. package/lib/secretPatterns.json +55 -0
  74. package/lib/secrets.mjs +10 -27
  75. package/lib/seen.mjs +102 -0
  76. package/lib/service.mjs +11 -6
  77. package/lib/sessionControl.mjs +10 -8
  78. package/lib/sessionIndex.mjs +5 -3
  79. package/lib/store.mjs +559 -30
  80. package/lib/subagents.mjs +8 -4
  81. package/lib/swarm.mjs +379 -38
  82. package/lib/swarmMemory.mjs +947 -0
  83. package/lib/t3.mjs +43 -13
  84. package/lib/taskCommands.mjs +58 -5
  85. package/lib/taskRuns.mjs +61 -11
  86. package/lib/team.json +17 -15
  87. package/lib/team.mjs +68 -18
  88. package/lib/threadRuns.mjs +50 -7
  89. package/lib/threadView.mjs +68 -15
  90. package/lib/tokenizer.mjs +405 -0
  91. package/lib/ui.mjs +16 -2
  92. package/lib/usageTotals.mjs +148 -0
  93. package/lib/vault.mjs +1144 -0
  94. package/lib/vaultCloud.mjs +117 -0
  95. package/lib/vaultCommands.mjs +201 -0
  96. package/lib/vaultTools.d.ts +12 -0
  97. package/lib/vaultTools.js +42 -0
  98. package/lib/windowAsks.mjs +42 -0
  99. package/lib/workFocus.mjs +59 -0
  100. package/lib/workLinks.mjs +90 -0
  101. package/package.json +9 -4
package/lib/store.mjs CHANGED
@@ -27,6 +27,41 @@ export const DEFAULT_DAILY_RUNS = 10;
27
27
  export const FAILURE_CAUSES = ["person", "start", "exit", "agent"];
28
28
  // An agent's record leaves out failures that say nothing about it: the person's stop and a run that never started.
29
29
  const AGENTS_OWN = "not (status = 'failed' and failure in ('person', 'start'))";
30
+ // What the swarm's memory can show (swarmMemory.mjs): what was said, made, checked or asked in the person's threads and
31
+ // tasks. A contribution's thread is its own task when that is a thread, else its task's parent thread.
32
+ export const MEMORY_KINDS = [
33
+ "post",
34
+ "result",
35
+ "receipt",
36
+ "failed",
37
+ "answer",
38
+ "question",
39
+ "goal",
40
+ "job",
41
+ "file",
42
+ ];
43
+ const MEMORY_SELECT = `select c.id, c.task_id, c.seq, c.kind, c.author, c.text, c.source, c.created_at,
44
+ case when t.kind = 'goal' then t.id when p.kind = 'goal' then p.id end as thread,
45
+ case when t.kind = 'goal' then t.objective when p.kind = 'goal' then p.objective else t.objective end as thread_title`;
46
+ const MEMORY_JOINS = `join board_tasks t on t.id = c.task_id left join board_tasks p on p.id = t.parent_id
47
+ left join board_memory_marks m on m.contribution_id = c.id`;
48
+ const MEMORY_WHERE = `c.kind in (${MEMORY_KINDS.map((kind) => `'${kind}'`).join(", ")}) and m.contribution_id is null`;
49
+ const PURGED = "[deleted at the person's request]";
50
+ // A full-text query for any of a text's words longer than two letters, or null with none.
51
+ const anyWordOf = (text) => {
52
+ const terms = [
53
+ ...new Set(
54
+ String(text)
55
+ .toLowerCase()
56
+ .match(/[\p{L}\p{N}_-]+/gu) || []
57
+ ),
58
+ ]
59
+ .filter((term) => term.length > 2)
60
+ .slice(0, 24);
61
+ return terms.length
62
+ ? terms.map((term) => `"${term.replaceAll('"', '""')}"`).join(" OR ")
63
+ : null;
64
+ };
30
65
  // A room post as readers get it. A file attached in the room names it, so a reader can show the file itself.
31
66
  const roomPostOf = ({ source, ...row }) => ({
32
67
  ...row,
@@ -134,6 +169,12 @@ export function openStore(file) {
134
169
  agent text primary key,
135
170
  last_seen_at text not null
136
171
  );
172
+ create table if not exists board_agent_computers (
173
+ agent text not null,
174
+ machine text not null,
175
+ last_seen_at text not null,
176
+ primary key (agent, machine)
177
+ );
137
178
  create table if not exists board_threads (
138
179
  task_id text primary key,
139
180
  with_agent text not null,
@@ -238,6 +279,39 @@ export function openStore(file) {
238
279
  updated_at text not null
239
280
  );
240
281
  create virtual table if not exists board_lessons_fts using fts5(id unindexed, text, tokenize='unicode61');
282
+ create table if not exists board_memory_marks (
283
+ contribution_id text primary key,
284
+ state text not null,
285
+ by text not null,
286
+ reason text,
287
+ replaced_by text,
288
+ at text not null
289
+ );
290
+ create table if not exists board_observations (
291
+ id text primary key,
292
+ kind text not null,
293
+ agent text,
294
+ folder text,
295
+ text text not null,
296
+ evidence text not null default '[]',
297
+ history text not null default '[]',
298
+ status text not null default 'active',
299
+ vector blob,
300
+ created_at text not null,
301
+ updated_at text not null
302
+ );
303
+ create virtual table if not exists board_observations_fts using fts5(id unindexed, text, tokenize='unicode61');
304
+ -- What the person saw, as their Harness window describes it (seen.mjs): read on this computer only, never sent on.
305
+ create table if not exists board_seen (
306
+ id text primary key,
307
+ window text not null,
308
+ frame_ref integer not null,
309
+ at text not null,
310
+ text text not null,
311
+ frames integer not null,
312
+ created_at text not null
313
+ );
314
+ create virtual table if not exists board_seen_fts using fts5(id unindexed, text, tokenize='unicode61');
241
315
  create table if not exists team_notes (
242
316
  id text primary key,
243
317
  agent text not null,
@@ -307,6 +381,13 @@ export function openStore(file) {
307
381
  .some((column) => column.name === "mentions")
308
382
  )
309
383
  db.exec("alter table board_contributions add column mentions text");
384
+ // The computer an agent wrote from, so readers can tell Codex on the Mac from Codex on the linux computer.
385
+ if (
386
+ !db
387
+ .all("pragma table_info(board_contributions)")
388
+ .some((column) => column.name === "machine")
389
+ )
390
+ db.exec("alter table board_contributions add column machine text");
310
391
  // Devices paired before browsers could pair were all phones.
311
392
  if (
312
393
  !db
@@ -461,6 +542,8 @@ export function openStore(file) {
461
542
  return { ok: false, error: describe(task), conflict: true, task };
462
543
  };
463
544
 
545
+ const roomPostListeners = [];
546
+
464
547
  return {
465
548
  db,
466
549
  needsIndex(agent, sessionId, mtime, size) {
@@ -517,6 +600,40 @@ export function openStore(file) {
517
600
  });
518
601
  return parsed.meta;
519
602
  },
603
+ // One UTC day of the board's work as counts by agent, for the anonymous daily totals
604
+ // (usageTotals.mjs). Only numbers and agent ids leave here, never text, ids or folders.
605
+ usageOfDay(day) {
606
+ const countBy = (sql) =>
607
+ execute("all", sql, day).map((row) => ({
608
+ name: row.name ?? null,
609
+ count: Number(row.count),
610
+ }));
611
+ const total = (sql) => Number(execute("get", sql, day).count);
612
+ return {
613
+ posted: countBy(
614
+ "select target_agent as name, count(*) as count from board_tasks where kind = 'task' and substr(created_at, 1, 10) = ? group by target_agent"
615
+ ),
616
+ handoffs: total(
617
+ "select count(*) as count from board_tasks where kind = 'task' and origin_agent != 'user' and substr(created_at, 1, 10) = ?"
618
+ ),
619
+ done: countBy(
620
+ "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"
621
+ ),
622
+ // A task the person removed is marked failed with failure 'person'; that is not a failure of the work.
623
+ failed: countBy(
624
+ "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"
625
+ ),
626
+ threadsStarted: total(
627
+ "select count(*) as count from board_tasks where kind = 'goal' and substr(created_at, 1, 10) = ?"
628
+ ),
629
+ posts: countBy(
630
+ "select author as name, count(*) as count from board_contributions where substr(created_at, 1, 10) = ? group by author"
631
+ ),
632
+ rounds: countBy(
633
+ "select action as name, count(*) as count from swarm_rounds where substr(at, 1, 10) = ? group by action"
634
+ ),
635
+ };
636
+ },
520
637
  endedSince(since) {
521
638
  const rows = execute(
522
639
  "all",
@@ -1056,13 +1173,21 @@ export function openStore(file) {
1056
1173
  spend.cost_usd = Math.round(spend.cost_usd * 1e6) / 1e6;
1057
1174
  return spend;
1058
1175
  },
1059
- roomPost({ goalId, author, kind = "post", text, mentions = [] }) {
1176
+ roomPost({
1177
+ goalId,
1178
+ author,
1179
+ kind = "post",
1180
+ text,
1181
+ mentions = [],
1182
+ machine = null,
1183
+ }) {
1060
1184
  const post = this.addContribution({
1061
1185
  taskId: goalId,
1062
1186
  kind,
1063
1187
  author,
1064
1188
  text,
1065
1189
  source: "room",
1190
+ machine,
1066
1191
  });
1067
1192
  if (post && mentions.length)
1068
1193
  execute(
@@ -1071,12 +1196,22 @@ export function openStore(file) {
1071
1196
  JSON.stringify(mentions),
1072
1197
  post.id
1073
1198
  );
1074
- return post ? { ...post, mentions } : null;
1199
+ const made = post ? { ...post, mentions } : null;
1200
+ // Whoever follows a room's posts (a shared project carries them to the other side) hears each one as it is made.
1201
+ if (made)
1202
+ for (const listener of roomPostListeners)
1203
+ try {
1204
+ listener(goalId, made);
1205
+ } catch {}
1206
+ return made;
1207
+ },
1208
+ onRoomPost(listener) {
1209
+ roomPostListeners.push(listener);
1075
1210
  },
1076
1211
  roomPosts(goalId, since = 0, limit = 200) {
1077
1212
  return execute(
1078
1213
  "all",
1079
- "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 ?",
1214
+ "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 ?",
1080
1215
  goalId,
1081
1216
  Number(since) || 0,
1082
1217
  Math.max(1, Math.min(500, Number(limit) || 200))
@@ -1089,7 +1224,7 @@ export function openStore(file) {
1089
1224
  const count = Math.max(1, Math.min(500, Number(limit) || 30));
1090
1225
  const rows = execute(
1091
1226
  "all",
1092
- "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 ?",
1227
+ "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 ?",
1093
1228
  goalId,
1094
1229
  Number(before) > 0 ? Number(before) : Number.MAX_SAFE_INTEGER,
1095
1230
  count + 1
@@ -1418,6 +1553,352 @@ export function openStore(file) {
1418
1553
  "select id, vector from board_lessons where status = 'active' and vector is not null"
1419
1554
  );
1420
1555
  },
1556
+ // A lesson the dream read as an instruction for one job (swarmMemory.mjs): out of the work, on record with why,
1557
+ // and back with restoreLesson.
1558
+ retireLesson(id, why) {
1559
+ const lesson = this.getLesson(id);
1560
+ if (!lesson || lesson.status !== "active") return null;
1561
+ execute(
1562
+ "run",
1563
+ "update board_lessons set status = 'retired', evidence = ?, updated_at = ? where id = ?",
1564
+ JSON.stringify(
1565
+ [
1566
+ ...lesson.evidence,
1567
+ { retired: why, at: new Date().toISOString() },
1568
+ ].slice(-20)
1569
+ ),
1570
+ new Date().toISOString(),
1571
+ id
1572
+ );
1573
+ execute("run", "delete from board_lessons_fts where id = ?", id);
1574
+ return this.getLesson(id);
1575
+ },
1576
+ // A lesson learned in one folder that holds for all the person's work.
1577
+ widenLesson(id) {
1578
+ execute(
1579
+ "run",
1580
+ "update board_lessons set scope = 'everywhere', folder = null, updated_at = ? where id = ? and status = 'active'",
1581
+ new Date().toISOString(),
1582
+ id
1583
+ );
1584
+ return this.getLesson(id);
1585
+ },
1586
+
1587
+ // ── The swarm's memory (swarmMemory.mjs) ──────────────────────────────────
1588
+ // Every post, result, receipt and job in the person's threads and tasks, each with the thread it belongs to (a job's
1589
+ // thread is its parent). Briefs, context packs, coordinator notes and records are the swarm's plumbing, not what
1590
+ // 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
1592
+ // share many common words crowded out the person's own earlier posts).
1593
+ memoryWords(query, limit = 60) {
1594
+ const terms = [
1595
+ ...new Set(
1596
+ String(query)
1597
+ .toLowerCase()
1598
+ .match(/[\p{L}\p{N}_-]+/gu) || []
1599
+ ),
1600
+ ]
1601
+ .filter((term) => term.length > 1)
1602
+ .slice(0, 12);
1603
+ if (!terms.length) return [];
1604
+ const match = terms
1605
+ .map((term) => `"${term.replaceAll('"', '""')}"`)
1606
+ .join(" OR ");
1607
+ return execute(
1608
+ "all",
1609
+ `${MEMORY_SELECT}, bm25(board_contributions_fts) as rank
1610
+ from board_contributions_fts f join board_contributions c on c.id = f.id ${MEMORY_JOINS}
1611
+ where board_contributions_fts match @match and ${MEMORY_WHERE}
1612
+ order by rank limit @limit`,
1613
+ { match, limit: Math.max(1, Math.min(200, limit)) }
1614
+ );
1615
+ },
1616
+ memoryPosts(ids) {
1617
+ if (!ids.length) return [];
1618
+ const wanted = [...new Set(ids)];
1619
+ const rows = execute(
1620
+ "all",
1621
+ `${MEMORY_SELECT} from board_contributions c ${MEMORY_JOINS}
1622
+ where c.id in (${wanted.map(() => "?").join(", ")}) and ${MEMORY_WHERE}`,
1623
+ ...wanted
1624
+ );
1625
+ const byId = new Map(rows.map((row) => [row.id, row]));
1626
+ return wanted.map((id) => byId.get(id)).filter(Boolean);
1627
+ },
1628
+ // The receipts of jobs and runs in these threads, newest first: written by code from each run's own session, they
1629
+ // come with any post of their thread that recall finds (a receipt names no subject of its own).
1630
+ memoryReceipts(threadIds, limit = 3) {
1631
+ if (!threadIds.length) return [];
1632
+ return execute(
1633
+ "all",
1634
+ `${MEMORY_SELECT} from board_contributions c ${MEMORY_JOINS}
1635
+ where c.kind = 'receipt' and t.parent_id in (${threadIds.map(() => "?").join(", ")}) and ${MEMORY_WHERE}
1636
+ order by c.created_at desc limit ${Math.max(1, Math.min(20, limit)) * threadIds.length}`,
1637
+ ...threadIds
1638
+ );
1639
+ },
1640
+ // What memory can show that was written after a moment, oldest first: the dream's new facts.
1641
+ memoryAfter(since = "", limit = 500) {
1642
+ return execute(
1643
+ "all",
1644
+ `${MEMORY_SELECT} from board_contributions c ${MEMORY_JOINS}
1645
+ where c.created_at > @since and ${MEMORY_WHERE} order by c.created_at limit @limit`,
1646
+ { since, limit: Math.max(1, Math.min(5000, limit)) }
1647
+ );
1648
+ },
1649
+ // The search model's vectors of what memory can show, written after a moment (newest last), for the module's cache.
1650
+ memoryVectors(version, since = "") {
1651
+ return execute(
1652
+ "all",
1653
+ `select c.id, c.created_at, v.vector from board_vectors v join board_contributions c on c.id = v.contribution_id
1654
+ ${MEMORY_JOINS} where v.version = @version and c.created_at > @since and ${MEMORY_WHERE}
1655
+ order by c.created_at`,
1656
+ { version, since }
1657
+ );
1658
+ },
1659
+ // Released (out of recall and briefs, still in the thread), purged (its words gone everywhere) or replaced (a
1660
+ // later post of the person's changed it).
1661
+ markMemory(id, { state, by, reason = null, replacedBy = null }) {
1662
+ execute(
1663
+ "run",
1664
+ `insert or replace into board_memory_marks(contribution_id, state, by, reason, replaced_by, at)
1665
+ values(?, ?, ?, ?, ?, ?)`,
1666
+ id,
1667
+ state,
1668
+ by,
1669
+ reason,
1670
+ replacedBy,
1671
+ new Date().toISOString()
1672
+ );
1673
+ },
1674
+ unmarkMemory(id) {
1675
+ const mark = execute(
1676
+ "get",
1677
+ "select * from board_memory_marks where contribution_id = ?",
1678
+ id
1679
+ );
1680
+ if (!mark || mark.state === "purged") return null;
1681
+ execute(
1682
+ "run",
1683
+ "delete from board_memory_marks where contribution_id = ?",
1684
+ id
1685
+ );
1686
+ return mark;
1687
+ },
1688
+ memoryMarks({ by = null } = {}) {
1689
+ return by
1690
+ ? execute("all", "select * from board_memory_marks where by = ?", by)
1691
+ : execute("all", "select * from board_memory_marks");
1692
+ },
1693
+ // Deleted for good at the person's request: the words leave the post, its search entry and its vector; the post
1694
+ // stays as a placeholder so the thread still reads in order.
1695
+ purgeMemory(id, { by, reason = null }) {
1696
+ execute(
1697
+ "run",
1698
+ "update board_contributions set text = ? where id = ?",
1699
+ PURGED,
1700
+ id
1701
+ );
1702
+ execute("run", "delete from board_contributions_fts where id = ?", id);
1703
+ execute("run", "delete from board_vectors where contribution_id = ?", id);
1704
+ this.markMemory(id, { state: "purged", by, reason });
1705
+ },
1706
+
1707
+ // What the dream (swarmMemory.mjs) keeps: beliefs consolidated from many posts, each standing on their exact words
1708
+ // (`evidence`, whose length is how often it was borne out) and keeping what it said before it changed (`history`).
1709
+ addObservation({ kind, agent = null, folder = null, text, evidence }) {
1710
+ const id = randomUUID();
1711
+ const now = new Date().toISOString();
1712
+ execute(
1713
+ "run",
1714
+ `insert into board_observations(id, kind, agent, folder, text, evidence, created_at, updated_at)
1715
+ values(?, ?, ?, ?, ?, ?, ?, ?)`,
1716
+ id,
1717
+ kind,
1718
+ agent,
1719
+ folder,
1720
+ text,
1721
+ JSON.stringify(evidence),
1722
+ now,
1723
+ now
1724
+ );
1725
+ execute(
1726
+ "run",
1727
+ "insert into board_observations_fts(id, text) values(?, ?)",
1728
+ id,
1729
+ text
1730
+ );
1731
+ return this.getObservation(id);
1732
+ },
1733
+ getObservation(id) {
1734
+ const row = execute(
1735
+ "get",
1736
+ "select * from board_observations where id = ?",
1737
+ id
1738
+ );
1739
+ if (!row) return null;
1740
+ const { vector, ...observation } = row;
1741
+ const evidence = JSON.parse(observation.evidence || "[]");
1742
+ return {
1743
+ ...observation,
1744
+ evidence,
1745
+ history: JSON.parse(observation.history || "[]"),
1746
+ proof: evidence.length,
1747
+ embedded: Boolean(vector),
1748
+ };
1749
+ },
1750
+ // Borne out again: the same belief gains the new words.
1751
+ confirmObservation(id, evidence) {
1752
+ const observation = this.getObservation(id);
1753
+ if (!observation || observation.status !== "active") return null;
1754
+ execute(
1755
+ "run",
1756
+ "update board_observations set evidence = ?, updated_at = ? where id = ?",
1757
+ JSON.stringify([...observation.evidence, ...evidence].slice(-30)),
1758
+ new Date().toISOString(),
1759
+ id
1760
+ );
1761
+ return this.getObservation(id);
1762
+ },
1763
+ // Changed by later words: the new belief takes its place, the old one stays in its history with when and why.
1764
+ reviseObservation(id, { text, evidence, why }) {
1765
+ const observation = this.getObservation(id);
1766
+ if (!observation || observation.status !== "active") return null;
1767
+ const now = new Date().toISOString();
1768
+ execute(
1769
+ "run",
1770
+ "update board_observations set text = ?, evidence = ?, history = ?, vector = null, updated_at = ? where id = ?",
1771
+ text,
1772
+ JSON.stringify([...observation.evidence, ...evidence].slice(-30)),
1773
+ JSON.stringify(
1774
+ [
1775
+ ...observation.history,
1776
+ { text: observation.text, until: now, why },
1777
+ ].slice(-20)
1778
+ ),
1779
+ now,
1780
+ id
1781
+ );
1782
+ execute("run", "delete from board_observations_fts where id = ?", id);
1783
+ execute(
1784
+ "run",
1785
+ "insert into board_observations_fts(id, text) values(?, ?)",
1786
+ id,
1787
+ text
1788
+ );
1789
+ return this.getObservation(id);
1790
+ },
1791
+ // Out of the work (`retired` by the dream, `removed` by the person), on record; back with restoreObservation.
1792
+ setObservationStatus(id, status) {
1793
+ const observation = this.getObservation(id);
1794
+ if (!observation) return null;
1795
+ execute(
1796
+ "run",
1797
+ "update board_observations set status = ?, updated_at = ? where id = ?",
1798
+ status,
1799
+ new Date().toISOString(),
1800
+ id
1801
+ );
1802
+ execute("run", "delete from board_observations_fts where id = ?", id);
1803
+ if (status === "active")
1804
+ execute(
1805
+ "run",
1806
+ "insert into board_observations_fts(id, text) values(?, ?)",
1807
+ id,
1808
+ observation.text
1809
+ );
1810
+ return this.getObservation(id);
1811
+ },
1812
+ observations({ status = "active", limit = 500 } = {}) {
1813
+ return execute(
1814
+ "all",
1815
+ "select id from board_observations where status = ? order by updated_at desc limit ?",
1816
+ status,
1817
+ Math.max(1, Math.min(5000, Number(limit) || 500))
1818
+ ).map((row) => this.getObservation(row.id));
1819
+ },
1820
+ observationsMatching(query, limit = 6) {
1821
+ const match = anyWordOf(query);
1822
+ if (!match) return [];
1823
+ return execute(
1824
+ "all",
1825
+ `select f.id from board_observations_fts f join board_observations o on o.id = f.id
1826
+ where board_observations_fts match ? and o.status = 'active' order by bm25(board_observations_fts) limit ?`,
1827
+ match,
1828
+ limit
1829
+ ).map((row) => this.getObservation(row.id));
1830
+ },
1831
+ setObservationVector(id, vector) {
1832
+ execute(
1833
+ "run",
1834
+ "update board_observations set vector = ? where id = ?",
1835
+ vector,
1836
+ id
1837
+ );
1838
+ },
1839
+ observationVectors() {
1840
+ return execute(
1841
+ "all",
1842
+ "select id, vector from board_observations where status = 'active' and vector is not null"
1843
+ );
1844
+ },
1845
+ // ── What the person saw (seen.mjs) ──
1846
+ addSeen({ window, ref, at, text, frames }) {
1847
+ const id = `${window}:${ref}`;
1848
+ if (execute("get", "select id from board_seen where id = ?", id))
1849
+ return false;
1850
+ execute(
1851
+ "run",
1852
+ `insert into board_seen(id, window, frame_ref, at, text, frames, created_at)
1853
+ values(?, ?, ?, ?, ?, ?, ?)`,
1854
+ id,
1855
+ window,
1856
+ ref,
1857
+ at,
1858
+ text,
1859
+ frames,
1860
+ new Date().toISOString()
1861
+ );
1862
+ execute(
1863
+ "run",
1864
+ "insert into board_seen_fts(id, text) values(?, ?)",
1865
+ id,
1866
+ text
1867
+ );
1868
+ return true;
1869
+ },
1870
+ seen({ limit = 200 } = {}) {
1871
+ return execute(
1872
+ "all",
1873
+ "select * from board_seen order by at desc limit ?",
1874
+ Math.max(1, Math.min(5000, Number(limit) || 200))
1875
+ );
1876
+ },
1877
+ seenRefs(window, limit = 200) {
1878
+ return execute(
1879
+ "all",
1880
+ "select frame_ref from board_seen where window = ? order by at desc limit ?",
1881
+ window,
1882
+ limit
1883
+ ).map((row) => row.frame_ref);
1884
+ },
1885
+ seenMatching(query, limit = 6) {
1886
+ const match = anyWordOf(query);
1887
+ if (!match) return [];
1888
+ return execute(
1889
+ "all",
1890
+ `select s.* from board_seen_fts f join board_seen s on s.id = f.id
1891
+ where board_seen_fts match ? order by bm25(board_seen_fts) limit ?`,
1892
+ match,
1893
+ limit
1894
+ );
1895
+ },
1896
+ removeSeen(id) {
1897
+ execute("run", "delete from board_seen_fts where id = ?", id);
1898
+ return (
1899
+ execute("run", "delete from board_seen where id = ?", id).changes > 0
1900
+ );
1901
+ },
1421
1902
  // The person's reaction to an agent's work (reactions.mjs): a verdict per post of theirs for each agent it is about;
1422
1903
  // `aboutSeq` is the agent's post, null when the post reacts to what the agents made together.
1423
1904
  recordReaction({
@@ -1443,6 +1924,24 @@ export function openStore(file) {
1443
1924
  new Date().toISOString()
1444
1925
  );
1445
1926
  },
1927
+ // The person's approvals of agents' work recorded after a moment, oldest first (swarmMemory.mjs keeps each as a
1928
+ // decision): their post, the agent and verdict, the thread, and the work approved when it was one post.
1929
+ approvalsAfter(since = "", limit = 200) {
1930
+ return execute(
1931
+ "all",
1932
+ `select r.post_id, r.goal_id, r.agent, r.verdict, r.at, p.text as said, p.created_at as said_at,
1933
+ t.objective as thread_title, w.id as work_id, w.text as work
1934
+ from board_reactions r
1935
+ join board_contributions p on p.id = r.post_id
1936
+ join board_tasks t on t.id = r.goal_id
1937
+ left join board_contributions w on w.task_id = r.goal_id and w.seq = r.about_seq
1938
+ left join board_memory_marks m on m.contribution_id = r.post_id
1939
+ where r.verdict in ('approves', 'approves_with_changes') and r.at > ? and m.contribution_id is null
1940
+ order by r.at limit ?`,
1941
+ since,
1942
+ Math.max(1, Math.min(1000, limit))
1943
+ );
1944
+ },
1446
1945
  // The person's verdicts on each agent's work, for its card: { agent: { accepted, changes, rejected } }.
1447
1946
  verdictCounts() {
1448
1947
  const counts = {};
@@ -1883,6 +2382,8 @@ export function openStore(file) {
1883
2382
  author,
1884
2383
  text,
1885
2384
  source = null,
2385
+ // The person's computer the author wrote from, when it is one of their agents on a computer.
2386
+ machine = null,
1886
2387
  }) {
1887
2388
  const body = String(text || "").trim();
1888
2389
  if (!body) return null;
@@ -1897,12 +2398,13 @@ export function openStore(file) {
1897
2398
  const now = new Date().toISOString();
1898
2399
  execute(
1899
2400
  "run",
1900
- "insert or ignore into board_contributions(id, task_id, seq, kind, author, text, source, created_at) values(?, ?, ?, ?, ?, ?, ?, ?)",
2401
+ "insert or ignore into board_contributions(id, task_id, seq, kind, author, machine, text, source, created_at) values(?, ?, ?, ?, ?, ?, ?, ?, ?)",
1901
2402
  id,
1902
2403
  taskId,
1903
2404
  seq,
1904
2405
  kind,
1905
2406
  author,
2407
+ machine,
1906
2408
  body.slice(0, 20_000),
1907
2409
  source,
1908
2410
  now
@@ -1971,7 +2473,8 @@ export function openStore(file) {
1971
2473
  vectorsFor(taskId, version) {
1972
2474
  return execute(
1973
2475
  "all",
1974
- "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 = ?",
2476
+ // Posts the guard held, and what the person released or purged, are never searched.
2477
+ "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",
1975
2478
  taskId,
1976
2479
  version
1977
2480
  );
@@ -2004,7 +2507,9 @@ export function openStore(file) {
2004
2507
  "all",
2005
2508
  `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
2006
2509
  from board_contributions_fts f join board_contributions c on c.id = f.id join board_tasks t on t.id = c.task_id
2007
- where board_contributions_fts match @match and t.kind = 'goal' order by rank limit 200`,
2510
+ left join board_memory_marks m on m.contribution_id = c.id
2511
+ where board_contributions_fts match @match and t.kind = 'goal' and c.kind != 'held' and m.contribution_id is null
2512
+ order by rank limit 200`,
2008
2513
  { match }
2009
2514
  )
2010
2515
  .filter((row) => !goalIds || goalIds.includes(row.thread))
@@ -2033,7 +2538,9 @@ export function openStore(file) {
2033
2538
  "all",
2034
2539
  `select c.id, c.kind, c.author, c.text, c.source, c.created_at, bm25(board_contributions_fts) as rank
2035
2540
  from board_contributions_fts f join board_contributions c on c.id = f.id
2036
- where board_contributions_fts match @match and f.task_id = @taskId order by rank limit @k`,
2541
+ left join board_memory_marks m on m.contribution_id = c.id
2542
+ where board_contributions_fts match @match and f.task_id = @taskId and c.kind != 'held' and m.contribution_id is null
2543
+ order by rank limit @k`,
2037
2544
  { match, taskId, k: Math.max(1, Math.min(50, k)) }
2038
2545
  ).map((row) => ({ ...row, score: -Number(row.rank) }));
2039
2546
  },
@@ -2542,14 +3049,22 @@ export function openStore(file) {
2542
3049
  task: this.getTask(taskId),
2543
3050
  };
2544
3051
  },
2545
- // Messages another person's agent sent on this agent's tasks since it last read the board.
2546
- lastSeenAt(agent) {
3052
+ // When this agent last called the board from `machine`, so Codex on the Mac and Codex on the linux computer each hear
3053
+ // what is new since they looked, not since the other did. An agent not yet seen there counts from when it last looked
3054
+ // anywhere, as it did before the board knew computers, so nothing old is told again.
3055
+ lastSeenAt(agent, machine = null) {
3056
+ const there = machine
3057
+ ? execute(
3058
+ "get",
3059
+ "select last_seen_at from board_agent_computers where agent = ? and machine = ?",
3060
+ agent,
3061
+ machine
3062
+ )?.last_seen_at
3063
+ : null;
2547
3064
  return (
2548
- execute(
2549
- "get",
2550
- "select last_seen_at from board_agents where agent = ?",
2551
- agent
2552
- )?.last_seen_at || null
3065
+ there ||
3066
+ this.agentsSeen().find((row) => row.agent === agent)?.last_seen_at ||
3067
+ null
2553
3068
  );
2554
3069
  },
2555
3070
  // Work an agent asked for that finished, failed or came back with a question since it last called the board: how an
@@ -2564,13 +3079,10 @@ export function openStore(file) {
2564
3079
  since || "1970-01-01T00:00:00.000Z"
2565
3080
  );
2566
3081
  },
2567
- unreadFor(agent) {
3082
+ // Messages another person's agent sent on this agent's tasks since it last read the board from `machine`.
3083
+ unreadFor(agent, machine = null) {
2568
3084
  const seen =
2569
- execute(
2570
- "get",
2571
- "select last_seen_at from board_agents where agent = ?",
2572
- agent
2573
- )?.last_seen_at || "1970-01-01T00:00:00.000Z";
3085
+ this.lastSeenAt(agent, machine) || "1970-01-01T00:00:00.000Z";
2574
3086
  return execute(
2575
3087
  "all",
2576
3088
  `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
@@ -2664,18 +3176,33 @@ export function openStore(file) {
2664
3176
  );
2665
3177
  return { ok: true, phone: this.getPhone(id) };
2666
3178
  },
2667
- touchAgent(agent) {
2668
- execute(
2669
- "run",
2670
- "insert into board_agents(agent, last_seen_at) values(?, ?) on conflict(agent) do update set last_seen_at = excluded.last_seen_at",
2671
- agent,
2672
- new Date().toISOString()
2673
- );
3179
+ // When an agent last called the board, from `machine` when the call says which computer (every daemon's does): one
3180
+ // row a call, the same writes as before computers. A row without a computer is from before.
3181
+ touchAgent(agent, machine = null) {
3182
+ const now = new Date().toISOString();
3183
+ if (machine)
3184
+ execute(
3185
+ "run",
3186
+ "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",
3187
+ agent,
3188
+ machine,
3189
+ now
3190
+ );
3191
+ else
3192
+ execute(
3193
+ "run",
3194
+ "insert into board_agents(agent, last_seen_at) values(?, ?) on conflict(agent) do update set last_seen_at = excluded.last_seen_at",
3195
+ agent,
3196
+ now
3197
+ );
2674
3198
  },
3199
+ // When each agent last called the board, from any computer.
2675
3200
  agentsSeen() {
2676
3201
  return execute(
2677
3202
  "all",
2678
- "select agent, last_seen_at from board_agents order by last_seen_at desc"
3203
+ `select agent, max(last_seen_at) as last_seen_at from (
3204
+ select agent, last_seen_at from board_agents union all select agent, last_seen_at from board_agent_computers
3205
+ ) group by agent order by last_seen_at desc`
2679
3206
  );
2680
3207
  },
2681
3208
  // Wakes sent to an agent's own gateway (wakes.mjs), one row per attempt: `outcome` is sent, refused, unsure (it may
@@ -2983,6 +3510,7 @@ export function openStore(file) {
2983
3510
  author: agent,
2984
3511
  text: result,
2985
3512
  source: `report:${status}`,
3513
+ machine: machine ?? this.getTask(id)?.claimed_machine ?? null,
2986
3514
  });
2987
3515
  return { ok: true, task: this.getTask(id) };
2988
3516
  }
@@ -3016,7 +3544,7 @@ export function openStore(file) {
3016
3544
  : `task is ${task.status}`
3017
3545
  );
3018
3546
  },
3019
- answerTask(id, agent, answer, expectedVersion = null) {
3547
+ answerTask(id, agent, answer, expectedVersion = null, machine = null) {
3020
3548
  if (!String(answer || "").trim())
3021
3549
  return { ok: false, error: "an answer is needed" };
3022
3550
  const now = new Date().toISOString();
@@ -3041,6 +3569,7 @@ export function openStore(file) {
3041
3569
  author: agent,
3042
3570
  text: answer,
3043
3571
  source: "answer",
3572
+ machine,
3044
3573
  });
3045
3574
  return { ok: true, task: this.getTask(id) };
3046
3575
  }