tryharness 0.7.54 → 0.7.58

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 (156) hide show
  1. package/README.md +15 -16
  2. package/cli.mjs +384 -62
  3. package/lib/activity.mjs +10 -10
  4. package/lib/adapters.mjs +16 -0
  5. package/lib/agentBinaries.mjs +71 -0
  6. package/lib/agentRuntimeConfig.mjs +1 -1
  7. package/lib/agentRuntimes.mjs +9 -3
  8. package/lib/agentSignIn.mjs +271 -41
  9. package/lib/answers.mjs +5 -5
  10. package/lib/archetypes.d.ts +64 -0
  11. package/lib/archetypes.js +989 -0
  12. package/lib/asks.mjs +4 -4
  13. package/lib/audit.mjs +36 -13
  14. package/lib/backupSetup.mjs +4 -2
  15. package/lib/boardAccess.mjs +17 -11
  16. package/lib/boardBackup.mjs +6 -6
  17. package/lib/boardFileCommands.mjs +6 -6
  18. package/lib/boardFiles.mjs +13 -12
  19. package/lib/boardMirror.mjs +82 -47
  20. package/lib/boardProtocol.json +30 -1
  21. package/lib/boardWaits.mjs +2 -3
  22. package/lib/book.mjs +6 -6
  23. package/lib/bridge.mjs +5 -5
  24. package/lib/cards.mjs +2 -2
  25. package/lib/cloudAgents.mjs +216 -0
  26. package/lib/cloudAi.mjs +1312 -0
  27. package/lib/cloudAssistants.mjs +242 -0
  28. package/lib/cloudBoot.mjs +81 -86
  29. package/lib/cloudSave.mjs +197 -0
  30. package/lib/cloudSsh.mjs +178 -0
  31. package/lib/context.mjs +3 -3
  32. package/lib/contractGate.mjs +34 -12
  33. package/lib/control-client.mjs +9 -1
  34. package/lib/controlSocket.mjs +86 -0
  35. package/lib/coordinator.mjs +103 -101
  36. package/lib/daemon.mjs +1128 -2865
  37. package/lib/desk.mjs +7 -6
  38. package/lib/desktop.mjs +72 -68
  39. package/lib/directLink.mjs +16 -5
  40. package/lib/environment.mjs +2 -1
  41. package/lib/environments.mjs +14 -6
  42. package/lib/firewall.mjs +9 -9
  43. package/lib/folders.mjs +18 -14
  44. package/lib/frames.mjs +2 -3
  45. package/lib/gitHost.mjs +3 -3
  46. package/lib/goalCommands.mjs +25 -7
  47. package/lib/goals.mjs +7 -7
  48. package/lib/guestRequests.mjs +94 -0
  49. package/lib/handoffs.mjs +8 -7
  50. package/lib/handover.mjs +4 -4
  51. package/lib/harnessModel.mjs +6 -6
  52. package/lib/harnessOffers.mjs +266 -0
  53. package/lib/inference.mjs +26 -8
  54. package/lib/jobAnswers.mjs +190 -0
  55. package/lib/landed.mjs +1 -1
  56. package/lib/lane.mjs +42 -11
  57. package/lib/lessons.mjs +16 -16
  58. package/lib/library.mjs +3 -3
  59. package/lib/lineup.mjs +3 -0
  60. package/lib/linkRelay.mjs +574 -0
  61. package/lib/localAgentAsk.mjs +74 -0
  62. package/lib/localStack.mjs +536 -0
  63. package/lib/localmodels.mjs +6 -4
  64. package/lib/loopBackstop.mjs +4 -4
  65. package/lib/machineIdentity.mjs +9 -1
  66. package/lib/machineRoutes.mjs +181 -2
  67. package/lib/machineRuns.mjs +76 -1
  68. package/lib/machineSeal.mjs +39 -12
  69. package/lib/mcp-stdio.mjs +96 -26
  70. package/lib/mcpRelay.mjs +1 -1
  71. package/lib/members.json +13 -0
  72. package/lib/members.mjs +1 -1
  73. package/lib/models.mjs +77 -23
  74. package/lib/museSession.mjs +6 -1
  75. package/lib/nativeHost.mjs +35 -7
  76. package/lib/network.mjs +50 -5
  77. package/lib/notify.mjs +7 -5
  78. package/lib/nudge.mjs +3 -3
  79. package/lib/ocr.mjs +9 -9
  80. package/lib/onboard.mjs +141 -50
  81. package/lib/oneLine.mjs +7 -7
  82. package/lib/ownMachines.mjs +928 -149
  83. package/lib/pairing.mjs +39 -8
  84. package/lib/paths.mjs +15 -1
  85. package/lib/peerProcess.mjs +124 -0
  86. package/lib/personModel.mjs +3 -3
  87. package/lib/personNotices.mjs +151 -0
  88. package/lib/phones.mjs +490 -38
  89. package/lib/placeCommands.mjs +4 -4
  90. package/lib/places.mjs +70 -2
  91. package/lib/profile.mjs +67 -14
  92. package/lib/projectGit.mjs +158 -14
  93. package/lib/projectPieces.mjs +902 -0
  94. package/lib/projectSettings.mjs +7 -4
  95. package/lib/projects.mjs +384 -62
  96. package/lib/provenance.mjs +5 -1
  97. package/lib/proxyLinks.mjs +267 -0
  98. package/lib/reactions.mjs +7 -5
  99. package/lib/readiness.mjs +12 -7
  100. package/lib/record.mjs +19 -6
  101. package/lib/redact.mjs +4 -4
  102. package/lib/relayLimits.mjs +62 -0
  103. package/lib/release.mjs +170 -0
  104. package/lib/releaseKeys.json +6 -0
  105. package/lib/repoLinks.mjs +4 -4
  106. package/lib/roomChannels.mjs +24 -0
  107. package/lib/roomPage.mjs +1 -1
  108. package/lib/runAuthority.mjs +101 -0
  109. package/lib/runBrief.mjs +19 -8
  110. package/lib/runWorker.mjs +14 -5
  111. package/lib/runner.mjs +215 -25
  112. package/lib/runtime-install.mjs +143 -9
  113. package/lib/schedules.mjs +2 -2
  114. package/lib/screens.mjs +1 -1
  115. package/lib/sealed.mjs +11 -2
  116. package/lib/sealedThreads.mjs +671 -0
  117. package/lib/secretPatterns.json +1 -1
  118. package/lib/secrets.mjs +4 -4
  119. package/lib/seen.mjs +6 -6
  120. package/lib/serverWords.mjs +175 -0
  121. package/lib/service.mjs +22 -12
  122. package/lib/sessionControl.mjs +6 -6
  123. package/lib/specialties.mjs +6 -6
  124. package/lib/specialtyKeys.js +4 -5
  125. package/lib/specialtyNotice.mjs +7 -7
  126. package/lib/specialtySnapshot.mjs +5 -5
  127. package/lib/speech.mjs +5 -5
  128. package/lib/store.mjs +140 -39
  129. package/lib/stuck.mjs +1 -1
  130. package/lib/swarm.mjs +167 -16
  131. package/lib/swarmDevices.mjs +319 -0
  132. package/lib/swarmMemory.mjs +27 -25
  133. package/lib/t3.mjs +13 -13
  134. package/lib/taskCommands.mjs +44 -11
  135. package/lib/taskRooms.mjs +125 -0
  136. package/lib/taskRuns.mjs +36 -1
  137. package/lib/team.mjs +41 -18
  138. package/lib/threadActions.mjs +315 -0
  139. package/lib/threadAuthority.mjs +101 -0
  140. package/lib/threadBriefs.mjs +178 -0
  141. package/lib/threadLine.mjs +2 -2
  142. package/lib/threadRuns.mjs +138 -43
  143. package/lib/threadView.mjs +5 -5
  144. package/lib/usageTotals.mjs +2 -3
  145. package/lib/vault.mjs +101 -10
  146. package/lib/vaultCloud.mjs +2 -2
  147. package/lib/vaultCommands.mjs +15 -6
  148. package/lib/vaultTools.js +2 -2
  149. package/lib/verdicts.mjs +328 -0
  150. package/lib/wakes.mjs +1 -1
  151. package/lib/watches.mjs +2 -2
  152. package/lib/windowAsks.mjs +13 -5
  153. package/lib/worktrees.mjs +112 -18
  154. package/npm-shrinkwrap.json +1093 -0
  155. package/package.json +11 -10
  156. package/release.json +220 -0
package/lib/store.mjs CHANGED
@@ -1,3 +1,4 @@
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";
@@ -432,6 +433,16 @@ export function openStore(file) {
432
433
  .some((column) => column.name === "machine")
433
434
  )
434
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
+ );
435
446
  // Devices paired before browsers could pair were all phones.
436
447
  if (
437
448
  !db
@@ -441,6 +452,26 @@ export function openStore(file) {
441
452
  db.exec(
442
453
  "alter table phone_devices add column kind text not null default 'phone'"
443
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
+ }
444
475
  // A thread whose other side's computer holds a key: everything on it goes sealed to that key.
445
476
  if (
446
477
  !db
@@ -513,6 +544,18 @@ export function openStore(file) {
513
544
  if (!boardColumns.has("audit") && boardColumns.size)
514
545
  db.exec("alter table board_tasks add column audit text");
515
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
+ }
558
+
516
559
  const statements = [];
517
560
  const prepare = (sql) => {
518
561
  const raw = db.prepare(sql);
@@ -1401,7 +1444,7 @@ export function openStore(file) {
1401
1444
  },
1402
1445
  // The newest posts before `before` (every post when it is not given), oldest first, and the seq to read before
1403
1446
  // for the ones earlier still (null at the thread's start). roomPosts reads from the start, which in a thread past
1404
- // 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).
1405
1448
  recentRoomPosts(goalId, { before = null, limit = 30 } = {}) {
1406
1449
  const count = Math.max(1, Math.min(500, Number(limit) || 30));
1407
1450
  const rows = execute(
@@ -1770,7 +1813,7 @@ export function openStore(file) {
1770
1813
  // Every post, result, receipt and job in the person's threads and tasks, each with the thread it belongs to (a job's
1771
1814
  // thread is its parent). Briefs, context packs, coordinator notes and records are the swarm's plumbing, not what
1772
1815
  // 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
1816
+ // The first twelve words of a query, as searchThreads read them (measured with 24: long job results that
1774
1817
  // share many common words crowded out the person's own earlier posts).
1775
1818
  memoryWords(query, limit = 60) {
1776
1819
  const terms = [
@@ -2091,11 +2134,14 @@ export function openStore(file) {
2091
2134
  agent,
2092
2135
  verdict,
2093
2136
  judgments,
2137
+ runId = null,
2138
+ source = "said",
2139
+ reason = null,
2094
2140
  }) {
2095
2141
  execute(
2096
2142
  "run",
2097
- `insert or replace into board_reactions(post_id, goal_id, post_seq, about_seq, agent, verdict, judgments, at)
2098
- 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(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)`,
2099
2145
  postId,
2100
2146
  goalId,
2101
2147
  postSeq,
@@ -2103,7 +2149,10 @@ export function openStore(file) {
2103
2149
  agent,
2104
2150
  verdict,
2105
2151
  judgments ? JSON.stringify(judgments) : null,
2106
- new Date().toISOString()
2152
+ new Date().toISOString(),
2153
+ runId,
2154
+ source,
2155
+ reason
2107
2156
  );
2108
2157
  },
2109
2158
  // The person's approvals of agents' work recorded after a moment, oldest first (swarmMemory.mjs keeps each as a
@@ -2127,10 +2176,18 @@ export function openStore(file) {
2127
2176
  // The person's verdicts on each agent's work, for its card: { agent: { accepted, changes, rejected } }.
2128
2177
  verdictCounts() {
2129
2178
  const counts = {};
2130
- for (const row of execute(
2131
- "all",
2132
- "select agent, verdict, count(*) as n from board_reactions where verdict != 'neither' group by agent, verdict"
2133
- )) {
2179
+ const judged = [...verdictEntriesByRun(this).values()];
2180
+ const unmatched = execute(
2181
+ "all",
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]) {
2134
2191
  const entry = (counts[row.agent] ??= {
2135
2192
  accepted: 0,
2136
2193
  changes: 0,
@@ -2142,7 +2199,7 @@ export function openStore(file) {
2142
2199
  : row.verdict === "approves_with_changes"
2143
2200
  ? "changes"
2144
2201
  : "rejected";
2145
- entry[key] += Number(row.n);
2202
+ entry[key]++;
2146
2203
  }
2147
2204
  return counts;
2148
2205
  },
@@ -2241,20 +2298,25 @@ export function openStore(file) {
2241
2298
  );
2242
2299
  },
2243
2300
  // Stop: every open child closes; the caller stops what is running.
2244
- 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) {
2245
2303
  const now = new Date().toISOString();
2246
2304
  const running = execute(
2247
2305
  "all",
2248
- "select id, target_agent from board_tasks where parent_id = ? and status = 'running'",
2249
- 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
2250
2310
  );
2251
2311
  execute(
2252
2312
  "run",
2253
- "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 = ?)",
2254
2314
  reason,
2255
2315
  now,
2256
2316
  now,
2257
- goalId
2317
+ goalId,
2318
+ agent,
2319
+ agent
2258
2320
  );
2259
2321
  return running;
2260
2322
  },
@@ -2341,17 +2403,18 @@ export function openStore(file) {
2341
2403
  undecided: Number(row.undecided),
2342
2404
  }));
2343
2405
  },
2344
- // 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.
2345
2407
  threadRuns(goalId) {
2346
2408
  return execute(
2347
2409
  "all",
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
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
2349
2411
  from board_tasks where parent_id = ? and kind in ('wake', 'task') order by created_at asc`,
2350
2412
  goalId
2351
2413
  ).map((row) => ({
2352
2414
  ...row,
2353
2415
  usage: row.usage ? JSON.parse(row.usage) : null,
2354
2416
  run_model: row.run_model ? JSON.parse(row.run_model) : null,
2417
+ returned: row.returned ? JSON.parse(row.returned) : null,
2355
2418
  checked: row.checked ? JSON.parse(row.checked) : null,
2356
2419
  }));
2357
2420
  },
@@ -2365,6 +2428,14 @@ export function openStore(file) {
2365
2428
  id
2366
2429
  );
2367
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
+ },
2368
2439
  // Another agent's check of a run's work: { outcome: passed | sent_back, step, by: [{ agent, model }], at }.
2369
2440
  setRunChecked(id, checked) {
2370
2441
  execute(
@@ -2412,9 +2483,9 @@ export function openStore(file) {
2412
2483
  verdictsSaid() {
2413
2484
  return execute(
2414
2485
  "all",
2415
- `select r.goal_id, r.agent, r.verdict, coalesce(p.created_at, r.at) as said_at
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
2416
2487
  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`
2488
+ where r.verdict != 'neither' order by said_at asc, r.rowid asc`
2418
2489
  );
2419
2490
  },
2420
2491
  // The coding sessions on this machine, newest first: the person's own and the ones runs started.
@@ -2856,22 +2927,23 @@ export function openStore(file) {
2856
2927
  // The person's other computers whose keys the join handshake pinned here (machineSeal.mjs): only these may call or
2857
2928
  // be called through Harness.
2858
2929
  ownMachine(machineId) {
2859
- return (
2860
- execute(
2861
- "get",
2862
- "select machine_id, public_key, pinned_at, label from own_machines where machine_id = ?",
2863
- machineId
2864
- ) || 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
2865
2934
  );
2935
+ return row ? { ...row, hosted: Boolean(row.hosted) } : null;
2866
2936
  },
2867
- 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 } = {}) {
2868
2939
  execute(
2869
2940
  "run",
2870
- "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)",
2871
2942
  machineId,
2872
2943
  publicKey,
2873
2944
  new Date().toISOString(),
2874
- label
2945
+ label,
2946
+ hosted ? 1 : 0
2875
2947
  );
2876
2948
  return this.ownMachine(machineId);
2877
2949
  },
@@ -2885,8 +2957,8 @@ export function openStore(file) {
2885
2957
  ownMachines() {
2886
2958
  return execute(
2887
2959
  "all",
2888
- "select machine_id, public_key, pinned_at, label from own_machines order by pinned_at"
2889
- );
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) }));
2890
2962
  },
2891
2963
  // Files on a task. A file this machine has is present; one another person's computer is sending is named by its
2892
2964
  // message first or arrives first, and is matched by the id that computer gave it (remote_id), never by ours.
@@ -3367,15 +3439,16 @@ export function openStore(file) {
3367
3439
  ).map((row) => ({ ...row, count: Number(row.count) }));
3368
3440
  },
3369
3441
  // Phones (QR code) and browsers (link) paired with this machine. Only the public key is kept; a revoked one is refused at once.
3370
- addPhone({ id, label, publicKey, kind = "phone" }) {
3442
+ addPhone({ id, label, publicKey, kind = "phone", holder = "page" }) {
3371
3443
  execute(
3372
3444
  "run",
3373
- "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(?, ?, ?, ?, ?, ?)",
3374
3446
  id,
3375
3447
  label,
3376
3448
  publicKey,
3377
3449
  new Date().toISOString(),
3378
- kind
3450
+ kind,
3451
+ holder
3379
3452
  );
3380
3453
  return this.getPhone(id);
3381
3454
  },
@@ -3383,7 +3456,7 @@ export function openStore(file) {
3383
3456
  return (
3384
3457
  execute(
3385
3458
  "get",
3386
- "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 = ?",
3387
3460
  id
3388
3461
  ) || null
3389
3462
  );
@@ -3391,7 +3464,7 @@ export function openStore(file) {
3391
3464
  phones() {
3392
3465
  return execute(
3393
3466
  "all",
3394
- "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"
3395
3468
  );
3396
3469
  },
3397
3470
  // Once a browser is paired, Harness reaches the person's board, sessions and runs only sealed.
@@ -3404,7 +3477,11 @@ export function openStore(file) {
3404
3477
  );
3405
3478
  },
3406
3479
  // A request id is accepted once per phone, across restarts; ids older than the queue's 7 days are forgotten.
3407
- firstPhoneRequest(deviceId, requestId) {
3480
+ firstPhoneRequest(
3481
+ deviceId,
3482
+ requestId,
3483
+ { sealedBy = null, gesture = null } = {}
3484
+ ) {
3408
3485
  const now = new Date();
3409
3486
  execute(
3410
3487
  "run",
@@ -3422,13 +3499,35 @@ export function openStore(file) {
3422
3499
  return false;
3423
3500
  execute(
3424
3501
  "run",
3425
- "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(?, ?, ?, ?, ?)",
3426
3503
  deviceId,
3427
3504
  requestId,
3428
- now.toISOString()
3505
+ now.toISOString(),
3506
+ sealedBy,
3507
+ gesture === null ? null : gesture ? 1 : 0
3429
3508
  );
3430
3509
  return true;
3431
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
+ },
3432
3531
  touchPhone(id) {
3433
3532
  execute(
3434
3533
  "run",
@@ -3682,6 +3781,8 @@ export function openStore(file) {
3682
3781
  usage: row.usage ? JSON.parse(row.usage) : null,
3683
3782
  run_model: row.run_model ? JSON.parse(row.run_model) : null,
3684
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,
3685
3786
  stale:
3686
3787
  row.status === "claimed" &&
3687
3788
  Boolean(row.lease_until) &&
@@ -3718,7 +3819,7 @@ export function openStore(file) {
3718
3819
  "a task for several agents is worked through its parts; claim the part posted for you",
3719
3820
  };
3720
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
3721
- // could not be released (October 14, Codex in the keeper thread).
3822
+ // could not be released.
3722
3823
  if (this.getTask(id)?.kind === "goal")
3723
3824
  return {
3724
3825
  ok: false,
package/lib/stuck.mjs CHANGED
@@ -8,7 +8,7 @@ import { isSetupCheck } from "./handoffs.mjs";
8
8
  // Harness's notes never do. The daemon runs the sweep on board changes and on a timer, and says each finding where it
9
9
  // belongs (daemon.mjs): in the thread and to its coordinator, or to whoever posted loose work.
10
10
  //
11
- // The thresholds, from the owner's board on October 20 (a read-only copy; 60 threads, 373 tasks and wakes):
11
+ // The thresholds, from one real board (a read-only copy; 60 threads, 373 tasks and wakes):
12
12
  // - Pickup (claimMs, droppedMs): 367 pickups, from posting (or the person's Start) to claim: p50 0, p90 3.4, p95 11.2,
13
13
  // p99 224 min. The tail is the stuck kind this sweep is for: Grok Bot's 242 and 251 min and 13.9 days, Harness
14
14
  // waiting for a window up to 9.2 h. Every pickup of work Harness starts itself (277, queueing for a busy folder
package/lib/swarm.mjs CHANGED
@@ -160,6 +160,8 @@ export function createSwarm({
160
160
  pickable,
161
161
  listModels,
162
162
  harnessModel,
163
+ // The person chose a model for an agent here (an agent on Harness's AI also takes it as its default).
164
+ modelChosen = () => {},
163
165
  folders,
164
166
  runsIn,
165
167
  threadFiles = () => ({ files: [], rendering: [] }),
@@ -184,6 +186,8 @@ export function createSwarm({
184
186
  addressesPartner = () => false,
185
187
  environments = null,
186
188
  notifyFocus = () => {},
189
+ // What the person's words just did to a run they steered (threadRuns.mjs steered): a promise of the thread's note.
190
+ steered = () => null,
187
191
  }) {
188
192
  const focus = createWorkFocus({ store });
189
193
  const readWork = async (id, hostedCaller = false) => {
@@ -233,8 +237,8 @@ export function createSwarm({
233
237
 
234
238
  // Who a message is for: the agents it names, else whoever coordinates, which brings in every agent with a part in it.
235
239
  // Where the coordinator cannot assemble (the privacy setting, a Harness without it) the thread's only agent takes it.
236
- // `@swarm` is for the whole swarm: whoever coordinates brings in the rest, and the agents it names hear it from the post
237
- // itself (October 16: a message naming an orchestrator and a role for each agent reached none of them).
240
+ // `@swarm` is for the whole swarm: whoever coordinates brings in the rest, and the agents it names hear it from the
241
+ // post itself (a message naming an orchestrator and a role for each agent once reached none of them).
238
242
  const addressed = (thread, text) => {
239
243
  if (SWARM.test(text))
240
244
  return [
@@ -277,7 +281,7 @@ export function createSwarm({
277
281
  agent: asking.claimed_by || asking.target_agent,
278
282
  text: asking.result || "",
279
283
  };
280
- // Work another agent asked for that only the person's Start lets run (docs/member-runs.md).
284
+ // Work another agent asked for that only the person's Start lets run.
281
285
  const held = runs.find(awaitingStart);
282
286
  if (held)
283
287
  return {
@@ -365,6 +369,9 @@ export function createSwarm({
365
369
  .map((post) => ({ seq: post.seq, text: post.text })),
366
370
  coordination: {
367
371
  mode: coordinator.mode(),
372
+ // The coding agent here the person picked, and the ones they can pick.
373
+ pick: coordinator.pick(),
374
+ choices: coordinator.choices(),
368
375
  rounds: coordinator.state(thread.id).rounds,
369
376
  // Who decided this thread's rounds: Harness, a backup here after Harness could not, this computer, no one.
370
377
  decided: store.roundHealth(thread.id, 3650).reduce(
@@ -568,6 +575,113 @@ export function createSwarm({
568
575
  return posted;
569
576
  };
570
577
 
578
+ /**
579
+ * The person's steer: words for an agent while it works, named by its thread or its run (tryharness steer, also over
580
+ * SSH on a cloud computer). They go into the thread as the person's message to that agent, as from PiP or the
581
+ * phone, which is what steers its run (threadRuns.mjs). The answer says what became of them.
582
+ */
583
+ const steer = (request) => {
584
+ const text = String(request.text || "")
585
+ .trim()
586
+ .slice(0, 20_000);
587
+ if (!text) return { ok: false, error: "a steer needs words" };
588
+ const named = store.getTask(String(request.id || ""));
589
+ const run = named && named.kind !== "goal" ? named : null;
590
+ const thread = run?.parent_id ? store.getTask(run.parent_id) : named;
591
+ if (thread?.kind !== "goal")
592
+ return { ok: false, error: "no thread or run has that id" };
593
+ if (run && run.status !== "running")
594
+ return {
595
+ ok: false,
596
+ error: `That run of ${nameOf(run.target_agent)}'s is not going any more. Write in its thread instead.`,
597
+ };
598
+ const working = store
599
+ .threadRuns(thread.id)
600
+ .filter((each) => each.status === "running")
601
+ .map((each) => each.target_agent)
602
+ .filter((agent) => roomAgents.includes(agent));
603
+ const asked = recipient(request);
604
+ if (asked === false)
605
+ return {
606
+ ok: false,
607
+ error: `${request.to} can't be written to in a thread`,
608
+ };
609
+ const to =
610
+ run?.target_agent ??
611
+ asked ??
612
+ (new Set(working).size === 1 ? working[0] : null);
613
+ if (!to)
614
+ return {
615
+ ok: false,
616
+ error: working.length
617
+ ? `More than one agent is working in this thread. Name one: ${[...new Set(working)].join(", ")}.`
618
+ : "Nothing is working in this thread now. Write in it instead.",
619
+ };
620
+ const posted = post(thread, text, to);
621
+ if (!posted?.ok) return posted;
622
+ const told = steered(thread.id, to);
623
+ const answer = (note) => {
624
+ const now = summary(store.getTask(thread.id));
625
+ return {
626
+ ok: true,
627
+ steered: true,
628
+ agent: to,
629
+ note,
630
+ // What a chat outside the thread says of it, beside a link to the thread.
631
+ line: `Sent to ${nameOf(to)}, which is working in "${now.title}".`,
632
+ thread: now,
633
+ };
634
+ };
635
+ return told
636
+ ? { pending: told.then(answer) }
637
+ : answer(
638
+ `${nameOf(to)} is not working now, so your message starts its next turn.`
639
+ );
640
+ };
641
+
642
+ /**
643
+ * The person's words in a chat that is not a thread (the PiP chat, the extension, the buddy's box, the phone's New
644
+ * message), naming one agent that is working (owner, October 26: steering "from any chat interface"): they go into
645
+ * the thread it works in as the person's steer, as written. Working in several threads, the answer asks which
646
+ * (`choose`); none, null, and the chat goes on as it would have. Words for the whole swarm, or naming several agents,
647
+ * are never a steer.
648
+ */
649
+ const steerFromChat = (request) => {
650
+ const text = String(request.text || "");
651
+ if (/(^|\s)@swarm\b/.test(text)) return null;
652
+ const asked = recipient(request);
653
+ // Harness counts as a name like any agent: "@claude-code … for @harness" is for both, and is no steer.
654
+ const named = asked ? [asked] : mentionsIn(text, roomAgents);
655
+ if (named.length !== 1 || named[0] === "harness") return null;
656
+ const [agent] = named;
657
+ const threads = store
658
+ .goals({ all: false })
659
+ .filter(
660
+ (thread) =>
661
+ thread.status === "open" &&
662
+ store
663
+ .threadRuns(thread.id)
664
+ .some(
665
+ (run) => run.target_agent === agent && run.status === "running"
666
+ )
667
+ );
668
+ if (!threads.length) return null;
669
+ if (threads.length > 1)
670
+ return {
671
+ ok: true,
672
+ steered: false,
673
+ choose: {
674
+ agent,
675
+ question: `${nameOf(agent)} is working in ${threads.length} threads. Which one is this for?`,
676
+ threads: threads.map((thread) => ({
677
+ id: thread.id,
678
+ title: summary(thread).title,
679
+ })),
680
+ },
681
+ };
682
+ return steer({ ...request, id: threads[0].id, to: agent });
683
+ };
684
+
571
685
  // One of the person's agents as a command names it, or why not.
572
686
  const namedAgent = (target) => {
573
687
  const named = resolveMember(target);
@@ -858,9 +972,12 @@ export function createSwarm({
858
972
  id,
859
973
  name: nameOf(id),
860
974
  choice: choiceOf(store, id),
861
- ownModel: agentModelSettings(id).model,
975
+ // On Harness's AI its own settings are Harness's, so its default is Auto, in the list.
976
+ ownModel: listed?.harness ? null : agentModelSettings(id).model,
862
977
  listedAt: listed?.at ?? null,
863
978
  ...(listed?.error ? { error: listed.error } : {}),
979
+ // What pays for its models on Harness's AI, and the words for a pick that runs on Auto or the free model.
980
+ ...(listed?.harness ? { harness: listed.harness } : {}),
864
981
  models: listed?.models ?? [],
865
982
  };
866
983
  }),
@@ -905,7 +1022,9 @@ export function createSwarm({
905
1022
  const thread = store.createGoal({
906
1023
  objective,
907
1024
  originAgent: agent,
908
- provenance: provenanceFor(agent),
1025
+ provenance: provenanceFor(agent, null, null, {
1026
+ viaServer: request.hostedCaller === true,
1027
+ }),
909
1028
  team: [...team, agent, "harness"],
910
1029
  facilitator: "harness",
911
1030
  workspace: folder ? path.resolve(folder) : null,
@@ -1095,12 +1214,16 @@ export function createSwarm({
1095
1214
  ? { ok: true, agent: "harness", choice: set.choice }
1096
1215
  : set;
1097
1216
  }
1098
- if (!named.ok || !PICKABLE.has(named.id))
1217
+ if (
1218
+ !named.ok ||
1219
+ !(PICKABLE.has(named.id) || pickable().includes(named.id))
1220
+ )
1099
1221
  return {
1100
1222
  ok: false,
1101
1223
  error: `the relay sets the model of ${[...PICKABLE].join(", ")}, not "${request.target}"`,
1102
1224
  };
1103
1225
  const set = setChoice(store, named.id, request.model, request.effort);
1226
+ if (set.ok) modelChosen(named.id);
1104
1227
  return set.ok ? { ok: true, agent: named.id, choice: set.choice } : set;
1105
1228
  }
1106
1229
  // The person's words on how Auto picks models for swarm work; no text goes back to the default words.
@@ -1127,10 +1250,28 @@ export function createSwarm({
1127
1250
  request.days
1128
1251
  ),
1129
1252
  };
1253
+ // Who coordinates the threads: Harness (the default), or one of the coding agents here the person picks.
1130
1254
  if (command === "board.swarm.coordinator") {
1131
- if (request.mode === "harness" || request.mode === "local")
1132
- coordinator.setMode(request.mode);
1133
- return { ok: true, mode: coordinator.mode() };
1255
+ const choices = coordinator.choices();
1256
+ if (request.mode !== undefined) {
1257
+ const wanted = String(request.mode);
1258
+ if (
1259
+ wanted !== "harness" &&
1260
+ wanted !== "local" &&
1261
+ !choices.includes(wanted)
1262
+ )
1263
+ return {
1264
+ ok: false,
1265
+ error: `${wanted} cannot coordinate here: pick harness${choices.map((id) => `, ${id}`).join("")} or local`,
1266
+ };
1267
+ coordinator.setMode(wanted);
1268
+ }
1269
+ return {
1270
+ ok: true,
1271
+ mode: coordinator.mode(),
1272
+ pick: coordinator.pick(),
1273
+ choices,
1274
+ };
1134
1275
  }
1135
1276
  if (command === "board.swarm.stop_all") {
1136
1277
  const stopped = store
@@ -1147,7 +1288,11 @@ export function createSwarm({
1147
1288
  .trim()
1148
1289
  .slice(0, 20_000);
1149
1290
  if (!text) return { ok: false, error: "a thread starts with a message" };
1150
- // What it may spend of the person's Harness credits, set once as it starts (owner, October 15).
1291
+ // From a chat outside any thread (the buddy's box, the phone's New message): words for one agent already at work
1292
+ // steer it there rather than start it again somewhere new.
1293
+ const steering = request.steer === true ? steerFromChat(request) : null;
1294
+ if (steering) return steering;
1295
+ // What it may spend of the person's Harness credits, set once as it starts.
1151
1296
  const ceiling = ceilingFrom(request.ceilingUsd);
1152
1297
  if (ceiling === undefined)
1153
1298
  return { ok: false, error: "a limit is a number of dollars, or off" };
@@ -1289,7 +1434,7 @@ export function createSwarm({
1289
1434
  if (!removed)
1290
1435
  return { ok: false, error: "no lesson starts with that id" };
1291
1436
  // The words it came from stop coming back through search and briefs too, so the swarm does not learn it again
1292
- // from them (eval memory-swarm); they stay in their thread.
1437
+ // from them; they stay in their thread.
1293
1438
  memory?.forget({
1294
1439
  ids: removed.evidence.map((entry) => entry.postId).filter(Boolean),
1295
1440
  mode: "release",
@@ -1377,6 +1522,12 @@ export function createSwarm({
1377
1522
  if (removed.ok) notifyBoard(store.getTask(removed.schedule.threadId));
1378
1523
  return removed;
1379
1524
  }
1525
+ // With no thread or run named, the words come from a chat outside any thread: a steer only if they name one agent
1526
+ // that is working, else nothing is done and the chat goes on as before.
1527
+ if (command === "board.swarm.steer")
1528
+ return request.id
1529
+ ? steer(request)
1530
+ : (steerFromChat(request) ?? { ok: true, steered: false });
1380
1531
  const thread = store.getTask(String(request.id || ""));
1381
1532
  if (!thread || thread.kind !== "goal")
1382
1533
  return { ok: false, error: "thread not found" };
@@ -1464,8 +1615,8 @@ export function createSwarm({
1464
1615
  ? { ok: true, thread: summary(store.getTask(thread.id)) }
1465
1616
  : done;
1466
1617
  }
1467
- // The person lets Harness finish in their browser now what it left for the browser (owner, October 22: "right
1468
- // away, even if away"): their extension's hidden Harness page takes it, claiming it only once this is recorded.
1618
+ // The person lets Harness finish in their browser now what it left for the browser, right away, even while they are
1619
+ // away: their extension's hidden Harness page takes it, claiming it only once this is recorded.
1469
1620
  if (command === "board.swarm.use_browser") {
1470
1621
  if (agent !== "user")
1471
1622
  return { ok: false, error: "only you let Harness use your browser" };
@@ -1524,9 +1675,9 @@ export function createSwarm({
1524
1675
  stopThreadRuns(thread.id);
1525
1676
  return { ok: true, thread: summary(store.getTask(thread.id)) };
1526
1677
  }
1527
- // A post held for the person (it looked like a secret, or like orders to the agents): they read it, then send it into
1528
- // the thread as its author wrote it or throw it away (owner, October 19: "yes" to Send and Discard). Its words
1529
- // reach only the person's own sealed surfaces (boardProtocol.json).
1678
+ // A post held for the person (it looked like a secret, or like orders to the agents): they read it, then send it
1679
+ // into the thread as its author wrote it or throw it away (Send and Discard). Its words reach only the person's own
1680
+ // sealed surfaces (boardProtocol.json).
1530
1681
  if (command === "board.swarm.held") {
1531
1682
  const held = store.heldPost(thread.id, String(request.post || ""));
1532
1683
  if (!held || store.meta(`held-replaced:${held.id}`))