tryharness 0.7.53 → 0.7.57

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (167) hide show
  1. package/README.md +23 -19
  2. package/assets/dsh-plugin.mjs +72 -0
  3. package/assets/opencode-plugin.js +4 -3
  4. package/cli.mjs +484 -90
  5. package/lib/activity.mjs +10 -10
  6. package/lib/adapters.mjs +173 -222
  7. package/lib/agentBinaries.mjs +71 -0
  8. package/lib/agentRuntimeConfig.mjs +1 -1
  9. package/lib/agentRuntimes.mjs +34 -18
  10. package/lib/agentSignIn.mjs +456 -0
  11. package/lib/answers.mjs +5 -5
  12. package/lib/archetypes.d.ts +64 -0
  13. package/lib/archetypes.js +989 -0
  14. package/lib/asks.mjs +4 -4
  15. package/lib/audit.mjs +666 -0
  16. package/lib/backupSetup.mjs +143 -0
  17. package/lib/boardAccess.mjs +24 -11
  18. package/lib/boardBackup.mjs +283 -0
  19. package/lib/boardFileCommands.mjs +6 -6
  20. package/lib/boardFiles.mjs +13 -12
  21. package/lib/boardMirror.mjs +124 -25
  22. package/lib/boardProtocol.json +88 -2
  23. package/lib/boardWaits.mjs +101 -0
  24. package/lib/book.mjs +659 -0
  25. package/lib/bridge.mjs +6 -6
  26. package/lib/cards.mjs +138 -28
  27. package/lib/cloudAgents.mjs +216 -0
  28. package/lib/cloudAi.mjs +1312 -0
  29. package/lib/cloudAssistants.mjs +242 -0
  30. package/lib/cloudBoot.mjs +119 -0
  31. package/lib/cloudSave.mjs +197 -0
  32. package/lib/cloudSsh.mjs +178 -0
  33. package/lib/commands.mjs +7 -2
  34. package/lib/context.mjs +19 -5
  35. package/lib/contractGate.mjs +399 -0
  36. package/lib/control-client.mjs +9 -1
  37. package/lib/controlSocket.mjs +86 -0
  38. package/lib/coordinator.mjs +252 -144
  39. package/lib/daemon.mjs +1351 -2767
  40. package/lib/desk.mjs +240 -0
  41. package/lib/desktop.mjs +178 -74
  42. package/lib/directLink.mjs +16 -5
  43. package/lib/environment.mjs +2 -1
  44. package/lib/environments.mjs +247 -9
  45. package/lib/firewall.mjs +9 -9
  46. package/lib/folders.mjs +20 -16
  47. package/lib/frames.mjs +2 -3
  48. package/lib/gitHost.mjs +174 -0
  49. package/lib/goalCommands.mjs +25 -7
  50. package/lib/goals.mjs +7 -7
  51. package/lib/guestRequests.mjs +94 -0
  52. package/lib/handoffs.mjs +8 -7
  53. package/lib/handover.mjs +4 -4
  54. package/lib/harnessModel.mjs +6 -6
  55. package/lib/harnessOffers.mjs +266 -0
  56. package/lib/hookDialects.mjs +298 -0
  57. package/lib/inference.mjs +26 -8
  58. package/lib/jobAnswers.mjs +190 -0
  59. package/lib/landed.mjs +887 -0
  60. package/lib/lane.mjs +42 -11
  61. package/lib/lessons.mjs +16 -16
  62. package/lib/library.mjs +3 -3
  63. package/lib/lineup.mjs +3 -0
  64. package/lib/linkRelay.mjs +574 -0
  65. package/lib/live.mjs +284 -13
  66. package/lib/localAgentAsk.mjs +74 -0
  67. package/lib/localStack.mjs +536 -0
  68. package/lib/localmodels.mjs +6 -4
  69. package/lib/loopBackstop.mjs +4 -4
  70. package/lib/machineIdentity.mjs +9 -1
  71. package/lib/machineRoutes.mjs +181 -2
  72. package/lib/machineRuns.mjs +76 -1
  73. package/lib/machineSeal.mjs +39 -12
  74. package/lib/mcp-stdio.mjs +163 -27
  75. package/lib/mcpRelay.mjs +1 -1
  76. package/lib/members.json +29 -2
  77. package/lib/members.mjs +1 -1
  78. package/lib/models.mjs +85 -31
  79. package/lib/museSession.mjs +21 -13
  80. package/lib/nativeHost.mjs +36 -8
  81. package/lib/neovim.mjs +126 -0
  82. package/lib/network.mjs +50 -5
  83. package/lib/notify.mjs +7 -5
  84. package/lib/nudge.mjs +50 -19
  85. package/lib/ocr.mjs +9 -9
  86. package/lib/onboard.mjs +26 -20
  87. package/lib/oneLine.mjs +7 -7
  88. package/lib/ownMachines.mjs +1223 -140
  89. package/lib/pairing.mjs +60 -16
  90. package/lib/paths.mjs +19 -1
  91. package/lib/peerProcess.mjs +124 -0
  92. package/lib/personModel.mjs +89 -0
  93. package/lib/personNotices.mjs +151 -0
  94. package/lib/phones.mjs +538 -31
  95. package/lib/placeCommands.mjs +4 -4
  96. package/lib/places.mjs +400 -12
  97. package/lib/profile.mjs +67 -14
  98. package/lib/projectGit.mjs +158 -14
  99. package/lib/projectPieces.mjs +902 -0
  100. package/lib/projectSettings.mjs +7 -4
  101. package/lib/projects.mjs +384 -62
  102. package/lib/provenance.mjs +5 -1
  103. package/lib/proxyLinks.mjs +267 -0
  104. package/lib/reactions.mjs +7 -5
  105. package/lib/readiness.mjs +145 -23
  106. package/lib/record.mjs +128 -0
  107. package/lib/redact.mjs +4 -4
  108. package/lib/relayLimits.mjs +62 -0
  109. package/lib/release.mjs +170 -0
  110. package/lib/releaseKeys.json +6 -0
  111. package/lib/repoLinks.mjs +4 -4
  112. package/lib/roomChannels.mjs +24 -0
  113. package/lib/roomPage.mjs +1 -1
  114. package/lib/runAuthority.mjs +101 -0
  115. package/lib/runBrief.mjs +19 -8
  116. package/lib/runWorker.mjs +31 -7
  117. package/lib/runner.mjs +223 -29
  118. package/lib/runtime-install.mjs +143 -9
  119. package/lib/schedules.mjs +2 -2
  120. package/lib/screens.mjs +1 -1
  121. package/lib/sealed.mjs +11 -2
  122. package/lib/sealedThreads.mjs +671 -0
  123. package/lib/secretPatterns.json +1 -1
  124. package/lib/secrets.mjs +4 -4
  125. package/lib/seen.mjs +6 -6
  126. package/lib/serverWords.mjs +175 -0
  127. package/lib/service.mjs +22 -12
  128. package/lib/sessionControl.mjs +378 -90
  129. package/lib/specialties.json +74 -0
  130. package/lib/specialties.mjs +477 -0
  131. package/lib/specialtyKeys.d.ts +3 -0
  132. package/lib/specialtyKeys.js +57 -0
  133. package/lib/specialtyNotice.mjs +147 -0
  134. package/lib/specialtySnapshot.mjs +138 -0
  135. package/lib/speech.mjs +5 -5
  136. package/lib/store.mjs +420 -36
  137. package/lib/stuck.mjs +1 -1
  138. package/lib/swarm.mjs +304 -37
  139. package/lib/swarmDevices.mjs +319 -0
  140. package/lib/swarmMemory.mjs +27 -25
  141. package/lib/t3.mjs +24 -15
  142. package/lib/taskCommands.mjs +80 -20
  143. package/lib/taskRooms.mjs +125 -0
  144. package/lib/taskRuns.mjs +45 -3
  145. package/lib/team.json +255 -148
  146. package/lib/team.mjs +554 -190
  147. package/lib/threadActions.mjs +315 -0
  148. package/lib/threadAuthority.mjs +101 -0
  149. package/lib/threadBriefs.mjs +178 -0
  150. package/lib/threadLine.mjs +116 -0
  151. package/lib/threadRuns.mjs +209 -50
  152. package/lib/threadView.mjs +20 -7
  153. package/lib/usageTotals.mjs +2 -3
  154. package/lib/vault.mjs +101 -10
  155. package/lib/vaultCloud.mjs +2 -2
  156. package/lib/vaultCommands.mjs +15 -6
  157. package/lib/vaultTools.js +2 -2
  158. package/lib/verdicts.mjs +328 -0
  159. package/lib/wakes.mjs +1 -1
  160. package/lib/watches.mjs +2 -2
  161. package/lib/windowAsks.mjs +13 -5
  162. package/lib/worktrees.mjs +157 -25
  163. package/npm-shrinkwrap.json +1093 -0
  164. package/package.json +12 -11
  165. package/release.json +220 -0
  166. package/lib/modelTiers.json +0 -1183
  167. package/lib/modelTiers.mjs +0 -133
package/cli.mjs CHANGED
@@ -1,5 +1,5 @@
1
1
  #!/usr/bin/env node
2
- import { spawn } from "node:child_process";
2
+ import { spawn, spawnSync } from "node:child_process";
3
3
  import fs from "node:fs";
4
4
  import os from "node:os";
5
5
  import path from "node:path";
@@ -25,23 +25,37 @@ import {
25
25
  walkThrough,
26
26
  } from "./lib/onboard.mjs";
27
27
  import { agentsHere, createLineup, lineupOf } from "./lib/lineup.mjs";
28
+ import { confirmAgentBinary } from "./lib/agentBinaries.mjs";
28
29
  import { CHECKABLE, createAgentReadiness } from "./lib/readiness.mjs";
29
30
  import { writeBrowserOffer } from "./lib/phones.mjs";
30
31
  import { createUi } from "./lib/ui.mjs";
32
+ import { backupCommand, offerBackup } from "./lib/backupSetup.mjs";
31
33
  import pc from "picocolors";
32
34
  import { removeLocalWakes } from "./lib/wakes.mjs";
33
35
  import { detectAgents } from "./lib/commands.mjs";
36
+ import { nameOf } from "./lib/members.mjs";
34
37
  import { daemonRequest } from "./lib/control-client.mjs";
35
38
  import { ensureDir, readJson, writeJsonAtomic } from "./lib/files.mjs";
39
+ import { hostApp, processTable } from "./lib/live.mjs";
40
+ import { noteSetupTerminal } from "./lib/places.mjs";
36
41
  import { paths } from "./lib/paths.mjs";
37
42
  import {
38
43
  joinSwarm,
39
44
  keepJoinCode,
45
+ setupPageUrl,
40
46
  startPairing,
41
47
  waitForApproval,
42
48
  } from "./lib/pairing.mjs";
43
49
  import { setupProfile } from "./lib/profile.mjs";
44
- import { currentRuntime, installRuntime } from "./lib/runtime-install.mjs";
50
+ import { cloudEnroll } from "./lib/cloudBoot.mjs";
51
+ import { ownPublicKey, sshCommand } from "./lib/cloudSsh.mjs";
52
+ import {
53
+ checkRuntime,
54
+ currentRuntime,
55
+ fetchRelease,
56
+ installRuntime,
57
+ relayCommand,
58
+ } from "./lib/runtime-install.mjs";
45
59
  import { installNativeHost, removeNativeHost } from "./lib/nativeHost.mjs";
46
60
  import { CORE, coreSizeMb } from "./lib/coreModels.mjs";
47
61
  import { MODELS, modelsPresent } from "./lib/localmodels.mjs";
@@ -54,7 +68,7 @@ import {
54
68
  import {
55
69
  canShowDesktop,
56
70
  openDesktop,
57
- retireDesktop,
71
+ uninstallDesktop,
58
72
  setupDesktop,
59
73
  } from "./lib/desktop.mjs";
60
74
 
@@ -148,11 +162,11 @@ const canOpenBrowser = () =>
148
162
  Boolean(process.env.DISPLAY || process.env.WAYLAND_DISPLAY));
149
163
 
150
164
  // One page in the browser approves this computer and links that browser to it in the same click: the address fragment,
151
- // which no server sees, carries the pairing code and a browser link setup made for the daemon (phones.mjs).
165
+ // which no server sees, carries the approval (never the code, which is also the join secret) and a browser link setup
166
+ // made for the daemon (phones.mjs, pairing.mjs setupPageUrl).
152
167
  async function pair(pairOrigin, agents, ui) {
153
168
  const { pairId, code, own } = await startPairing(pairOrigin, agents);
154
169
  if (own) keepJoinCode(paths.machine, code);
155
- const page = `${pairOrigin}/pair`;
156
170
  const browser = own && canOpenBrowser();
157
171
  const link = browser
158
172
  ? await writeBrowserOffer({
@@ -161,10 +175,14 @@ async function pair(pairOrigin, agents, ui) {
161
175
  })
162
176
  : null;
163
177
  const opened =
164
- browser && openUrl(`${page}#${new URLSearchParams({ c: code })}&${link}`);
178
+ browser && openUrl(await setupPageUrl(pairOrigin, { code, own }, link));
179
+ // With no browser here, the person opens the approval link on another computer: setup's code itself is typed only
180
+ // into Harness on one of their own computers, never into a web page.
165
181
  const approve = opened
166
182
  ? "Your browser just opened. Sign in with your email if it asks, then press Connect. No account yet? Signing in makes one."
167
- : `Open ${page} in a browser, sign in with your email, and enter this code. No account yet? Signing in makes one.`;
183
+ : own
184
+ ? `Open this link in a browser, sign in with your email, and press Connect. No account yet? Signing in makes one.\n${await setupPageUrl(pairOrigin, { code, own })}`
185
+ : `Open ${pairOrigin}/pair in a browser, sign in with your email, and enter this code. No account yet? Signing in makes one.`;
168
186
  const elsewhere = own
169
187
  ? "\nAlready use Harness on another computer? Click the Harness icon in its menu bar, choose Add a Computer, and type this code there instead."
170
188
  : "";
@@ -202,12 +220,18 @@ async function waitForDaemon(timeoutMs = 12_000) {
202
220
  await new Promise((resolve) => setTimeout(resolve, 250));
203
221
  }
204
222
  throw new Error(
205
- `daemon started but its authenticated Harness bridge did not become ready: ${lastError?.message || lastStatus?.lastError || "timeout"}. Run: npx tryharness doctor`
223
+ `daemon started but its authenticated Harness bridge did not become ready: ${lastError?.message || lastStatus?.lastError || "timeout"}. Run: ${relayCommand()} doctor`
206
224
  );
207
225
  }
208
226
 
209
227
  async function connect() {
210
228
  ensureDir(paths.home);
229
+ // A release this computer's Harness would refuse is refused before pairing or anything else changes.
230
+ checkRuntime({
231
+ sourceRoot: SOURCE_ROOT,
232
+ version: VERSION,
233
+ allowUnsigned: has("--local-build"),
234
+ });
211
235
  // The agents installed here (lineup.mjs). Each coding agent gets its one-line prompt now (readiness.mjs), so the
212
236
  // answers come in while the person signs in.
213
237
  const here = agentsHere();
@@ -234,6 +258,12 @@ async function connect() {
234
258
  .filter((entry) => AGENTS.includes(entry.id))
235
259
  .map((entry) => entry.id);
236
260
  const ui = createUi();
261
+ // Where the person works, for Open until it has seen their sessions (places.mjs).
262
+ const table = processTable();
263
+ noteSetupTerminal({
264
+ host: hostApp(table, process.pid),
265
+ tty: table.get(process.pid)?.tty ?? null,
266
+ });
237
267
  console.log(`\n${banner(VERSION)}\n`);
238
268
  ui.intro(
239
269
  `${pc.bgCyan(pc.black(" tryharness "))} Setting up Harness on this computer`
@@ -285,9 +315,20 @@ async function connect() {
285
315
  const runtimeRoot = installRuntime({
286
316
  sourceRoot: SOURCE_ROOT,
287
317
  version: VERSION,
318
+ allowUnsigned: has("--local-build"),
288
319
  });
289
320
  const selected = ready.filter((agent) => AGENTS.includes(agent));
290
321
  const states = configureAgents({ runtimeRoot, selected });
322
+ // The program each agent runs as, as this terminal finds it: the daemon starts that one and no other
323
+ // (agentBinaries.mjs).
324
+ const moved = selected.flatMap((agent) => {
325
+ const confirmed = confirmAgentBinary(agent);
326
+ return confirmed?.previous
327
+ ? [
328
+ `${agent} now runs from ${confirmed.path} (it ran from ${confirmed.previous})`,
329
+ ]
330
+ : [];
331
+ });
291
332
  const stateMap = Object.fromEntries(
292
333
  states.map((state) => [state.agent, state])
293
334
  );
@@ -307,7 +348,7 @@ async function connect() {
307
348
  installNativeHost({ runtimeRoot });
308
349
  } catch (error) {
309
350
  ui.warn(
310
- `The extension cannot find this computer by itself (${error.message}); link the browser with npx tryharness link`
351
+ `The extension cannot find this computer by itself (${error.message}); link the browser with ${relayCommand()} link`
311
352
  );
312
353
  }
313
354
  try {
@@ -319,7 +360,7 @@ async function connect() {
319
360
  spin.stop(
320
361
  `Harness is running on this computer ${pc.dim(`· ${service.manager}`)}`
321
362
  );
322
- await joinSwarm({ ui, code: setupCode, daemonRequest });
363
+ for (const line of moved) ui.info(line);
323
364
  // Harness already runs, so the browser lists the agents while the person tells them who they work for.
324
365
  await setupProfile({ ui, origin: pairOrigin, token: config.token });
325
366
  const joined = await walkThrough({
@@ -365,7 +406,7 @@ async function connect() {
365
406
  );
366
407
  if (failed.length) {
367
408
  throw new Error(
368
- `setup is incomplete for ${failed.map((state) => state.agent).join(", ")}. Nothing was hidden; run npx tryharness doctor after fixing the reported CLI error, then rerun setup.`
409
+ `setup is incomplete for ${failed.map((state) => state.agent).join(", ")}. Nothing was hidden; run ${relayCommand()} doctor after fixing the reported CLI error, then rerun setup.`
369
410
  );
370
411
  }
371
412
  // The browser you use Harness in on this computer links to this computer; on an added one it works the board home
@@ -392,8 +433,25 @@ async function connect() {
392
433
  );
393
434
  }
394
435
  } catch (error) {
395
- ui.warn(`Browser not linked (${error.message}). Run: npx tryharness link`);
436
+ ui.warn(
437
+ `Browser not linked (${error.message}). Run: ${relayCommand()} link`
438
+ );
396
439
  }
440
+ // Last, so nothing else waits on it: an added computer works on its own until its code is typed on home.
441
+ const role = await joinSwarm({ ui, code: setupCode, daemonRequest });
442
+ // A Resident coming back gets their board back; one without a backup may start one.
443
+ const onBoard = await daemonRequest({
444
+ command: "board.list",
445
+ agent: "user",
446
+ all: true,
447
+ limit: 1,
448
+ }).catch(() => null);
449
+ await offerBackup({
450
+ ui,
451
+ daemonRequest,
452
+ role,
453
+ boardIsEmpty: onBoard?.ok === true && !onBoard.tasks?.length,
454
+ });
397
455
  const library = !readJson(paths.config, {}).libraryOff;
398
456
  const modelsHere = modelsPresent(path.join(paths.home, "local"), CORE);
399
457
  ui.note(
@@ -405,10 +463,10 @@ async function connect() {
405
463
  ]),
406
464
  ...(library
407
465
  ? [
408
- `Your agents here can search your Desktop, Documents and Downloads. That stays on this computer${process.platform === "darwin" ? ", and your Mac asks you once" : ""}. ${pc.dim("Change it: npx tryharness local off")}`,
466
+ `Your agents here can search your Desktop, Documents and Downloads. That stays on this computer${process.platform === "darwin" ? ", and your Mac asks you once" : ""}. ${pc.dim(`Change it: ${relayCommand()} local off`)}`,
409
467
  ]
410
468
  : []),
411
- `Your coding agents start the tasks you ask for in folders they have worked in, up to 10 a day each. Tasks another agent wrote wait for your Start. ${pc.dim("Change it: npx tryharness board standing")}`,
469
+ `Your coding agents start the tasks you ask for in folders they have worked in, up to 10 a day each. Tasks another agent wrote wait for your Start. ${pc.dim(`Change it: ${relayCommand()} board standing`)}`,
412
470
  ].join("\n\n"),
413
471
  "Good to know"
414
472
  );
@@ -466,7 +524,7 @@ async function status() {
466
524
  const machine = current.machine;
467
525
  if (machine?.label)
468
526
  console.log(
469
- `this computer: ${machine.label}, ${machine.role === "worker" ? `a worker${machine.home ? ` for ${machine.home.label} (${machine.home.connected ? "online" : "offline"}${machine.home.confirmed ? "" : ", not confirmed yet: npx tryharness machines"})` : ""}${machine.waiting ? `, ${machine.waiting} waiting to send` : ""}` : "home, holds the board"}`
527
+ `this computer: ${machine.label}, ${machine.role === "worker" ? `a worker${machine.home ? ` for ${machine.home.label} (${machine.home.connected ? "online" : "offline"}${machine.home.confirmed ? "" : `, not confirmed yet: ${relayCommand()} machines`})` : ""}${machine.waiting ? `, ${machine.waiting} waiting to send` : ""}` : "home, holds the board"}`
470
528
  );
471
529
  console.log(
472
530
  `history: ${current.indexing ? "indexing" : "ready"}${current.lastIndexedAt ? ` · last scan ${current.lastIndexedAt}` : ""}`
@@ -704,7 +762,7 @@ async function connectAgent() {
704
762
  const to = String(argv[0] || "");
705
763
  if (!/^[a-z0-9][a-z0-9-]{1,19}\/[a-z0-9][a-z0-9._-]{0,63}$/.test(to))
706
764
  throw new Error(
707
- "usage: tryharness connect <handle/agent> --about <text> [--agent <your agent>] [--file <brief.md>]"
765
+ "usage: tryharness connect <handle/agent> --about <text> [--agent <your agent>] [--file <brief.md>] [--readable]"
708
766
  );
709
767
  const fromAgent = arg("--agent", "claude-code");
710
768
  if (!AGENTS.includes(fromAgent))
@@ -724,6 +782,7 @@ async function connectAgent() {
724
782
  about,
725
783
  brief,
726
784
  trustNewKey: has("--trust-new-key"),
785
+ readable: has("--readable"),
727
786
  },
728
787
  20_000
729
788
  );
@@ -733,25 +792,139 @@ async function connectAgent() {
733
792
  );
734
793
  console.log(
735
794
  response.sealed
736
- ? `Sealed end to end to ${to.split("/")[0]}'s computer (key ${response.fingerprint}); Harness carries it and cannot read it. Check the key with them once: npx tryharness peers`
795
+ ? `Sealed end to end to ${to.split("/")[0]}'s computer (key ${response.fingerprint}); Harness carries it and cannot read it. Check the key with them once: ${relayCommand()} peers`
737
796
  : `Not end to end: ${to.split("/")[0]}'s computer runs a Harness without sealed threads yet, so Harness can read this thread.`
738
797
  );
739
798
  }
740
799
 
800
+ // How often `tryharness ssh` asks again while a cloud computer wakes: as often as its card looks while one comes up
801
+ // (CloudComputerCard.tsx QUICK_MS). It waits as long as the wake takes, which is unmeasured; Ctrl-C stops it.
802
+ const SSH_WAKE_LOOK_MS = 3_000;
803
+
804
+ // SSH into one of the person's cloud computers (docs/cloud-swarm.md §7), from one of their own: woken if asleep, their
805
+ // own key allowed on it over the sealed line between their computers, then its address and host key as they are now.
806
+ async function ssh() {
807
+ const dashes = argv.indexOf("--");
808
+ const own = dashes >= 0 ? argv.slice(0, dashes) : argv;
809
+ const remote = dashes >= 0 ? argv.slice(dashes + 1) : [];
810
+ const named = own.find(
811
+ (value, index) => !value.startsWith("-") && own[index - 1] !== "--key"
812
+ );
813
+ const key = ownPublicKey(arg("--key"));
814
+ if (!key)
815
+ throw new Error(
816
+ "No SSH key found in ~/.ssh. Make one with ssh-keygen -t ed25519, or name yours with --key <file>."
817
+ );
818
+ let waking = false;
819
+ for (;;) {
820
+ // No deadline: the wake, the sealed line and the provider's answer are unmeasured.
821
+ const answer = await daemonRequest(
822
+ {
823
+ command: "machines.ssh",
824
+ agent: "user",
825
+ computer: named ?? null,
826
+ key: key.text,
827
+ },
828
+ 0
829
+ );
830
+ if (!answer.ok) throw new Error(answer.error || "SSH was refused");
831
+ if (answer.state === "ready" && answer.access) {
832
+ const args = sshCommand({
833
+ access: answer.access,
834
+ computer: answer.computer,
835
+ keyFile: fs.existsSync(key.privateFile) ? key.privateFile : key.file,
836
+ knownHostsDir: path.join(paths.home, "ssh"),
837
+ command: remote,
838
+ });
839
+ if (has("--print")) {
840
+ console.log(["ssh", ...args].map(shellQuote).join(" "));
841
+ return;
842
+ }
843
+ console.log(
844
+ `${answer.computer.label}: your key ${answer.fingerprint} is let in. You work there as the harness user, as your agents do.`
845
+ );
846
+ const session = spawn("ssh", args, { stdio: "inherit" });
847
+ process.exitCode = await new Promise((resolve) =>
848
+ session.on("close", (code) => resolve(code ?? 1))
849
+ );
850
+ return;
851
+ }
852
+ if (!waking)
853
+ console.log(`Waking ${answer.computer?.label ?? "your cloud computer"}…`);
854
+ waking = true;
855
+ await sleep(SSH_WAKE_LOOK_MS);
856
+ }
857
+ }
858
+
859
+ // Words for an agent while it works, by its thread or its run: they go into the thread as your message to it, which
860
+ // steers it (live where it takes words mid-run; otherwise it stops where it is and goes on with them).
861
+ async function steer() {
862
+ const to = arg("--agent");
863
+ const words = argv.filter(
864
+ (value, index, all) =>
865
+ !value.startsWith("--") && all[index - 1] !== "--agent"
866
+ );
867
+ const [id, ...text] = words;
868
+ if (!id || !text.length)
869
+ throw new Error(
870
+ 'usage: tryharness steer <thread or run> "<words>" [--agent <agent>]'
871
+ );
872
+ const answer = await daemonRequest(
873
+ {
874
+ command: "board.swarm.steer",
875
+ agent: "user",
876
+ id,
877
+ text: text.join(" "),
878
+ ...(to ? { to } : {}),
879
+ },
880
+ // Into a turn T3 Code carries the words wait for T3's answer, which has no measured deadline either.
881
+ 0
882
+ );
883
+ if (!answer.ok)
884
+ throw new Error(
885
+ answer.code === "not_allowed"
886
+ ? `${answer.error} Steer from one of your own computers, PiP or your phone.`
887
+ : answer.error || "the steer was not sent"
888
+ );
889
+ console.log(answer.note);
890
+ }
891
+
892
+ // What the agents on this computer are running now, with what to type to follow or steer each.
893
+ async function runs() {
894
+ const answer = await daemonRequest({ command: "runs.here", agent: "user" });
895
+ if (!answer.ok) throw new Error(answer.error || "runs unavailable");
896
+ if (!answer.runs.length) {
897
+ console.log("Nothing is running on this computer now.");
898
+ return;
899
+ }
900
+ for (const run of answer.runs)
901
+ console.log(
902
+ `${run.runId} ${nameOf(run.agent)} since ${new Date(run.startedAt).toLocaleTimeString()} ${run.title}${run.cwd ? `\n in ${run.cwd}` : ""}`
903
+ );
904
+ console.log(
905
+ `\nFollow one: ${relayCommand()} task <run> --follow\nSteer one: ${relayCommand()} steer <run> "<words>"`
906
+ );
907
+ }
908
+
741
909
  // The person's own computers: which one holds the board (home), the others that work through it, and the join code a
742
910
  // new one shows until the person types it on home.
743
911
  async function machines() {
744
912
  const sub = argv[0];
745
913
  if (sub === "add" || sub === "confirm") {
914
+ // --hosted: a computer the person does not drive from (a cloud computer): agents only, never acting as the person.
746
915
  const response = await daemonRequest(
747
- { command: "machines.add", code: String(argv[1] || "") },
916
+ {
917
+ command: "machines.add",
918
+ code: String(argv.slice(1).find((arg) => !arg.startsWith("--")) || ""),
919
+ hosted: argv.includes("--hosted"),
920
+ },
748
921
  30_000
749
922
  );
750
923
  if (!response.ok) throw new Error(response.error || "not added");
751
924
  if (response.state === "approved") console.log(response.note);
752
925
  else if (response.state === "waiting")
753
926
  console.log(
754
- `${response.machine || "The computer"} is connected to your account. It joins your swarm by itself as soon as it is online; npx tryharness machines shows when it has.`
927
+ `${response.machine || "The computer"} is connected to your account. It joins your swarm by itself as soon as it is online; ${relayCommand()} machines shows when it has.`
755
928
  );
756
929
  else
757
930
  console.log(
@@ -768,29 +941,62 @@ async function machines() {
768
941
  console.log(`This computer is now called ${response.label}.`);
769
942
  return;
770
943
  }
944
+ if (sub === "remove") {
945
+ const computer = argv.slice(1).join(" ").trim();
946
+ if (!computer) throw new Error("usage: tryharness machines remove <name>");
947
+ const response = await daemonRequest(
948
+ { command: "machines.remove", agent: "user", computer },
949
+ 20_000
950
+ );
951
+ if (!response.ok) throw new Error(response.error || "not removed");
952
+ console.log(
953
+ `${computer} is off your swarm: this computer no longer trusts it, and your other computers hear so from here.${response.note ? ` ${response.note}` : ""}`
954
+ );
955
+ return;
956
+ }
771
957
  if (sub === "home") {
772
- const response = await daemonRequest({ command: "machines.home" }, 20_000);
958
+ // `machines home <name>` makes another of the person's computers home, as the buddy's Make Home does.
959
+ const name = argv.slice(1).join(" ").trim();
960
+ let computer = null;
961
+ if (name) {
962
+ const listed = await daemonRequest({ command: "machines.list" });
963
+ const found = (listed.machines ?? []).find(
964
+ (machine) => machine.label === name || machine.id === name
965
+ );
966
+ if (!found && listed.self?.label !== name)
967
+ throw new Error(`no computer of yours is called ${name}`);
968
+ computer = found?.id ?? null;
969
+ }
970
+ const response = await daemonRequest(
971
+ {
972
+ command: "machines.home",
973
+ ...(computer ? { computer, agent: "user" } : {}),
974
+ },
975
+ 20_000
976
+ );
773
977
  if (!response.ok) throw new Error(response.error || "not moved");
774
978
  console.log(
775
- "This computer is home now: it holds the board from here on. The board on the computer that was home stays there; work it held is not moved."
979
+ computer
980
+ ? `${name} is home now: it holds the board from here on.`
981
+ : "This computer is home now: it holds the board from here on. What the computer that was home has and this one does not comes here once it is back."
776
982
  );
777
983
  return;
778
984
  }
779
985
  if (sub)
780
986
  throw new Error(
781
- "usage: tryharness machines [add <code> | name <name> | home]"
987
+ "usage: tryharness machines [add <code> [--hosted] | name <name> | home [<computer>] | remove <name>]"
782
988
  );
783
989
  const response = await daemonRequest({ command: "machines.list" });
784
990
  if (!response.ok)
785
991
  throw new Error(response.error || "the daemon could not list computers");
786
992
  const { self, joinCode } = response;
787
993
  console.log(
788
- `This computer: ${self.label} (${self.role === "worker" ? "worker" : self.standingInFor ? `standing in as home for ${self.standingInFor} until it is back` : "home, holds the board"})${self.fingerprint ? `, key ${self.fingerprint}` : ""}`
994
+ `This computer: ${self.label} (${self.role === "worker" ? (self.alone ? "worker, working on its own until it joins your swarm" : "worker") : self.standingInFor ? `standing in as home for ${self.standingInFor} until it is back` : "home, holds the board"})${self.fingerprint ? `, key ${self.fingerprint}` : ""}`
789
995
  );
790
996
  if (joinCode) {
791
997
  const home = response.machines.find((machine) => machine.role === "home");
792
998
  console.log(
793
- `Join code: ${joinCode}\nOn your home computer${home?.label ? ` (${home.label})` : ""}, choose Add a Computer in the Harness menu and type it, or run: npx tryharness machines add ${joinCode}`
999
+ `Join code: ${joinCode}\nOn your home computer${home?.label ? ` (${home.label})` : ""}, choose Add a Computer in the Harness menu and type it, or run: ${relayCommand()} machines add ${joinCode}. What this computer does meanwhile goes there when it joins.`
794
1000
  );
795
1001
  }
796
1002
  if (!response.machines.length) {
@@ -939,7 +1145,7 @@ async function board() {
939
1145
  );
940
1146
  else if (runWorkspace)
941
1147
  console.log(
942
- `Task ${response.task.id} is on the board and ${target} will run it in ${runWorkspace}. Follow it: npx tryharness task ${response.task.id} --follow`
1148
+ `Task ${response.task.id} is on the board and ${target} will run it in ${runWorkspace}. Follow it: ${relayCommand()} task ${response.task.id} --follow`
943
1149
  );
944
1150
  else
945
1151
  console.log(
@@ -1045,7 +1251,7 @@ async function board() {
1045
1251
  response.retrieval === "vectors"
1046
1252
  ? "meaning"
1047
1253
  : response.embedder === "absent"
1048
- ? "words (the local models are not downloaded yet; run npx tryharness)"
1254
+ ? `words (the local models are not downloaded yet; run ${relayCommand()})`
1049
1255
  : `words (${response.context?.embedded ?? 0} of ${response.context?.total ?? 0} entries embedded so far)`;
1050
1256
  console.log(
1051
1257
  `${response.entries.length} result${response.entries.length === 1 ? "" : "s"} by ${how}`
@@ -1102,7 +1308,7 @@ async function board() {
1102
1308
  for (const rule of response.standing) {
1103
1309
  if (rule.mode === "off") {
1104
1310
  console.log(
1105
- `${rule.agent} waits for your Start. Turn it on: npx tryharness board standing ${rule.agent} on`
1311
+ `${rule.agent} waits for your Start. Turn it on: ${relayCommand()} board standing ${rule.agent} on`
1106
1312
  );
1107
1313
  continue;
1108
1314
  }
@@ -1113,7 +1319,7 @@ async function board() {
1113
1319
  : "in folders you have used it in (none yet)"
1114
1320
  : `in ${rule.workspaces.join(", ")}`;
1115
1321
  console.log(
1116
- `${rule.agent} starts tasks from you or Harness without asking, ${where}; ${rule.runs_today} of ${rule.daily_cap} today. Turn it off: npx tryharness board standing ${rule.agent} off`
1322
+ `${rule.agent} starts tasks from you or Harness without asking, ${where}; ${rule.runs_today} of ${rule.daily_cap} today. Turn it off: ${relayCommand()} board standing ${rule.agent} off`
1117
1323
  );
1118
1324
  }
1119
1325
  return;
@@ -1128,7 +1334,7 @@ async function board() {
1128
1334
  if (!response.ok) throw new Error(response.error || `${sub} failed`);
1129
1335
  console.log(
1130
1336
  sub === "run"
1131
- ? `Run authorized; ${response.task.target_agent} starts it now. Follow it: npx tryharness task ${id} --follow`
1337
+ ? `Run authorized; ${response.task.target_agent} starts it now. Follow it: ${relayCommand()} task ${id} --follow`
1132
1338
  : `Task ${id} is open again.`
1133
1339
  );
1134
1340
  return;
@@ -1140,8 +1346,8 @@ async function board() {
1140
1346
  if (!id || id.startsWith("--"))
1141
1347
  throw new Error("usage: tryharness board brief <task id> [--dry-run]");
1142
1348
  const dryRun = has("--dry-run");
1143
- // A dry run does what a run's start does before its agent starts. Measured on the owner's daemon log, September 1 to
1144
- // October 20, 2026: context packs took up to 7,349 ms (215 packs, median 859), task frames up to 875 ms (216, median
1349
+ // A dry run does what a run's start does before its agent starts. Measured on one daemon's log over seven weeks of
1350
+ // real use: context packs took up to 7,349 ms (215 packs, median 859), task frames up to 875 ms (216, median
1145
1351
  // 230); claude-mem is cut off at 2,000 ms (CLAUDE_MEM_TIMEOUT_MS); reading the largest session file here (147 MB)
1146
1352
  // took 499 ms. That is 10.7 s at worst; the deadline gives it over twice that, for a session the relay must index
1147
1353
  // first (not measured).
@@ -1217,7 +1423,7 @@ async function board() {
1217
1423
  );
1218
1424
  if (t.run_workspace)
1219
1425
  console.log(
1220
- `run: ${t.run_authorized_at ? `authorized by ${t.run_authorized_by}` : "requested, waiting for: npx tryharness board run " + t.id} · ${t.run_workspace}${t.session_id ? `\nagent session: ${t.session_id}\nopen live session: ${resumeCommand(t.target_agent, t.session_id, t.run_workspace)}` : ""}\n`
1426
+ `run: ${t.run_authorized_at ? `authorized by ${t.run_authorized_by}` : `requested, waiting for: ${relayCommand()} board run ` + t.id} · ${t.run_workspace}${t.session_id ? `\nagent session: ${t.session_id}\nopen live session: ${resumeCommand(t.target_agent, t.session_id, t.run_workspace)}` : ""}\n`
1221
1427
  );
1222
1428
  if (t.brief) console.log(t.brief + "\n");
1223
1429
  if (t.result)
@@ -1335,7 +1541,7 @@ async function goal() {
1335
1541
  if (!response.ok) throw new Error(response.error || "the goal was not set");
1336
1542
  const g = response.task;
1337
1543
  console.log(
1338
- `Goal ${g.id} is set. ${g.goal.facilitator} facilitates; the team is ${g.goal.team.join(", ")}${g.goal.workspace ? `; coding agents work in ${g.goal.workspace}` : ""}. Follow it: npx tryharness goal show ${g.id}`
1544
+ `Goal ${g.id} is set. ${g.goal.facilitator} facilitates; the team is ${g.goal.team.join(", ")}${g.goal.workspace ? `; coding agents work in ${g.goal.workspace}` : ""}. Follow it: ${relayCommand()} goal show ${g.id}`
1339
1545
  );
1340
1546
  return;
1341
1547
  }
@@ -1377,7 +1583,13 @@ async function goal() {
1377
1583
  }
1378
1584
  if (sub === "invite") {
1379
1585
  const response = await daemonRequest(
1380
- { command: "board.goal.invite", agent, id, to: String(argv[2] || "") },
1586
+ {
1587
+ command: "board.goal.invite",
1588
+ agent,
1589
+ id,
1590
+ to: String(argv[2] || ""),
1591
+ readable: has("--readable"),
1592
+ },
1381
1593
  20_000
1382
1594
  );
1383
1595
  if (!response.ok)
@@ -1462,8 +1674,6 @@ async function swarm() {
1462
1674
  const sub = argv[0] || "rounds";
1463
1675
  if (sub === "coordinator") {
1464
1676
  const mode = argv[1];
1465
- if (mode && mode !== "harness" && mode !== "local")
1466
- throw new Error("usage: tryharness swarm coordinator [harness|local]");
1467
1677
  const response = await daemonRequest({
1468
1678
  command: "board.swarm.coordinator",
1469
1679
  agent: "user",
@@ -1475,9 +1685,13 @@ async function swarm() {
1475
1685
  );
1476
1686
  console.log(
1477
1687
  response.mode === "local"
1478
- ? "Threads are coordinated by an agent on this computer with its tools off; nothing in them goes to Harness."
1479
- : "Threads are coordinated by Harness: each round sends the thread's newest posts and its options to Harness, which decides and words the next step."
1688
+ ? `Threads are coordinated by ${response.pick ? `${nameOf(response.pick)}, on this computer with its tools off` : "an agent on this computer with its tools off"}; nothing in them goes to Harness.`
1689
+ : "Threads are coordinated by Harness: each round sends the thread's newest posts and its options to Harness, which decides and words the next step. This computer reads what it decided before an agent works on it."
1480
1690
  );
1691
+ if (!mode)
1692
+ console.log(
1693
+ `To change it: tryharness swarm coordinator ${["harness", ...response.choices].join(" | ")}`
1694
+ );
1481
1695
  return;
1482
1696
  }
1483
1697
  if (sub === "rounds") {
@@ -1733,24 +1947,96 @@ function logs() {
1733
1947
  );
1734
1948
  }
1735
1949
 
1736
- async function disconnect() {
1950
+ // A cloud computer's daemon, run by the harness-cloud service as the harness user once cloud-enroll has written its
1951
+ // config: the agents the boot script installed are connected to the swarm the first time, as setup connects them, and
1952
+ // then the daemon runs from the installed package itself.
1953
+ async function cloudStart() {
1954
+ const config = readJson(paths.config, {});
1955
+ if (!config.cloud || !config.token)
1956
+ throw new Error("this is not an enrolled cloud computer");
1957
+ if (!config.agentStates) {
1958
+ const states = configureAgents({ runtimeRoot: SOURCE_ROOT });
1959
+ writeJsonAtomic(paths.config, {
1960
+ ...readJson(paths.config, config),
1961
+ version: VERSION,
1962
+ runtimeRoot: SOURCE_ROOT,
1963
+ agentStates: Object.fromEntries(
1964
+ states.map((state) => [state.agent, state])
1965
+ ),
1966
+ });
1967
+ }
1968
+ const { startDaemon } = await import("./lib/daemon.mjs");
1969
+ await startDaemon();
1970
+ }
1971
+
1972
+ // What setup downloaded into ~/.harness (the daemon's runtime, local models and their engine): uninstall takes it out
1973
+ // and keeps what is the person's, their board, history and keys, unless they ask for everything.
1974
+ const downloadedParts = () => [
1975
+ paths.runtime,
1976
+ // The installed command (runtime-install.mjs), which runs the runtime above.
1977
+ path.join(paths.home, "bin"),
1978
+ paths.models,
1979
+ path.join(paths.home, "local"),
1980
+ ];
1981
+
1982
+ function folderBytes(target) {
1983
+ let stat;
1984
+ try {
1985
+ stat = fs.lstatSync(target);
1986
+ } catch {
1987
+ return 0;
1988
+ }
1989
+ if (!stat.isDirectory()) return stat.size;
1990
+ return fs
1991
+ .readdirSync(target)
1992
+ .reduce((total, name) => total + folderBytes(path.join(target, name)), 0);
1993
+ }
1994
+
1995
+ const megabytes = (bytes) => `${Math.max(1, Math.round(bytes / 1_000_000))} MB`;
1996
+
1997
+ async function uninstall() {
1998
+ const everything = has("--everything");
1999
+ // Harness first, while the daemon is still connected: this computer comes off the account and its pairing stops
2000
+ // working, so a computer set up later is not taken for a worker of this one.
2001
+ const left = await daemonRequest({ command: "machines.leave" }, 15_000).catch(
2002
+ () => null
2003
+ );
1737
2004
  uninstallService();
1738
- removeNativeHost();
1739
- retireDesktop({});
1740
2005
  try {
1741
2006
  await daemonRequest({ command: "shutdown" }, 2_000);
1742
2007
  } catch {}
2008
+ removeNativeHost();
2009
+ uninstallDesktop();
1743
2010
  removeAgentConfigurations();
1744
2011
  removeLocalWakes();
1745
- try {
1746
- fs.renameSync(paths.config, paths.config + `.disconnected-${Date.now()}`);
1747
- } catch {}
1748
- for (const target of [paths.status, paths.socket])
2012
+ const removed = everything
2013
+ ? [paths.home]
2014
+ : [...downloadedParts(), paths.status, paths.socket];
2015
+ for (const target of removed)
1749
2016
  try {
1750
- fs.unlinkSync(target);
2017
+ fs.rmSync(target, { recursive: true, force: true });
1751
2018
  } catch {}
2019
+ // The pairing goes; the person's choices stay (who is in their swarm, who they took out), so setting up again
2020
+ // keeps their swarm (a reinstall once came back without Bankr, Quotient, Grok Bot and Muse).
2021
+ if (!everything) {
2022
+ const { token: _token, ...choices } = readJson(paths.config, {});
2023
+ if (Object.keys(choices).length) writeJsonAtomic(paths.config, choices);
2024
+ }
2025
+ if (!left?.ok)
2026
+ console.log(
2027
+ "Harness could not be told this computer is gone (it was not connected). Setting Harness up again on it still makes it home."
2028
+ );
2029
+ if (everything) {
2030
+ console.log(
2031
+ "Harness is uninstalled, and everything it kept on this computer is deleted."
2032
+ );
2033
+ return;
2034
+ }
2035
+ const shown = paths.home.replace(os.homedir(), "~");
1752
2036
  console.log(
1753
- "Harness disconnected. The local history database was preserved."
2037
+ `Harness is uninstalled: the app, its background service and its setup in your agents are gone.\n` +
2038
+ `Your board, history and keys are kept in ${shown} (${megabytes(folderBytes(paths.home))}), so setting Harness up again picks up where you left off.\n` +
2039
+ `To delete them too: ${relayCommand()} uninstall --everything`
1754
2040
  );
1755
2041
  }
1756
2042
 
@@ -1926,6 +2212,19 @@ async function agents() {
1926
2212
  process.exitCode = (await removeAgent({ daemonRequest, agent })) ? 0 : 1;
1927
2213
  return;
1928
2214
  }
2215
+ // The program Harness starts for an agent, confirmed again after the person installed it somewhere new.
2216
+ if (sub === "confirm") {
2217
+ if (!agent) throw new Error("usage: tryharness agents confirm <agent>");
2218
+ const confirmed = confirmAgentBinary(agent);
2219
+ if (!confirmed)
2220
+ throw new Error(
2221
+ `${agent} is not installed where this terminal can find it`
2222
+ );
2223
+ console.log(
2224
+ `Harness starts ${agent} from ${confirmed.path}${confirmed.previous ? ` now, not ${confirmed.previous}` : ""}.`
2225
+ );
2226
+ return;
2227
+ }
1929
2228
  if (sub === "test" && agent) {
1930
2229
  process.exitCode = (await testAgent({ agent, daemonRequest })) ? 0 : 1;
1931
2230
  return;
@@ -1942,26 +2241,7 @@ async function agents() {
1942
2241
  );
1943
2242
  console.log(
1944
2243
  response.text ||
1945
- "No agents in your swarm yet. Set them up: npx tryharness agents"
1946
- );
1947
- return;
1948
- }
1949
- // The person's tier for one agent, over its model's benchmark tier: who may hold the team's important roles.
1950
- if (sub === "tier") {
1951
- const tier = argv[2];
1952
- if (!agent || !tier)
1953
- throw new Error(
1954
- "usage: tryharness agents tier <agent> top|middle|bottom|auto"
1955
- );
1956
- const response = await daemonRequest({
1957
- command: "board.swarm.tier",
1958
- agent: "user",
1959
- target: agent,
1960
- tier,
1961
- });
1962
- if (!response.ok) throw new Error(response.error);
1963
- console.log(
1964
- `${response.agent} is ${response.tier?.level ?? "unknown"} tier: ${response.tier?.because ?? ""}`
2244
+ `No agents in your swarm yet. Set them up: ${relayCommand()} agents`
1965
2245
  );
1966
2246
  return;
1967
2247
  }
@@ -2019,11 +2299,11 @@ async function agents() {
2019
2299
  );
2020
2300
  else
2021
2301
  console.log(
2022
- ` ${entry.models.length} models; list them with: npx tryharness agents models ${entry.id}`
2302
+ ` ${entry.models.length} models; list them with: ${relayCommand()} agents models ${entry.id}`
2023
2303
  );
2024
2304
  }
2025
2305
  console.log(
2026
- `\nAuto picks by: ${response.routing ?? `${response.defaultRouting} (the default; change it with: npx tryharness agents routing "<your words>")`}`
2306
+ `\nAuto picks by: ${response.routing ?? `${response.defaultRouting} (the default; change it with: ${relayCommand()} agents routing "<your words>")`}`
2027
2307
  );
2028
2308
  return;
2029
2309
  }
@@ -2132,47 +2412,123 @@ async function phone() {
2132
2412
  );
2133
2413
  return;
2134
2414
  }
2415
+ // What waits for the person on any of their computers: a Harness page asking to link, or a device Harness linked.
2416
+ // `swarm` is from a daemon that keeps the swarm's list; an older one lists only this computer's asks.
2417
+ const listed = () => daemonRequest({ command: "phone.list" });
2418
+ const swarmOf = (response) =>
2419
+ response.swarm ?? [
2420
+ ...(response.asks ?? []).map((ask) => ({
2421
+ ...ask,
2422
+ kind: "ask",
2423
+ state: "waiting",
2424
+ })),
2425
+ ...(response.phones ?? []).map((p) => ({
2426
+ ...p,
2427
+ at: p.paired_at,
2428
+ state: p.revoked_at ? "removed" : "listed",
2429
+ })),
2430
+ ];
2431
+ const where = (entry) =>
2432
+ entry.computerLabel ? ` on ${entry.computerLabel}` : "";
2433
+ const pick = (entries, prefix, none) => {
2434
+ const matches = entries.filter((entry) => entry.id.startsWith(prefix));
2435
+ if (matches.length === 1 || (!prefix && matches.length)) return matches[0];
2436
+ throw new Error(
2437
+ matches.length ? "that id matches more than one; type more of it" : none
2438
+ );
2439
+ };
2440
+ if (sub === "allow" || sub === "deny") {
2441
+ const response = await listed();
2442
+ const waiting = swarmOf(response).filter(
2443
+ (entry) => entry.state === "waiting"
2444
+ );
2445
+ if (!waiting.length) {
2446
+ console.log("Nothing is waiting for you on any of your computers.");
2447
+ return;
2448
+ }
2449
+ const entry = pick(
2450
+ waiting,
2451
+ String(argv[1] || ""),
2452
+ "nothing waiting has that id (see: tryharness phone list)"
2453
+ );
2454
+ const answer = await daemonRequest({
2455
+ command: "phone.link.answer",
2456
+ agent: "user",
2457
+ id: entry.id,
2458
+ allow: sub === "allow",
2459
+ });
2460
+ if (!answer.ok) throw new Error(answer.error);
2461
+ const browser = entry.kind === "ask";
2462
+ console.log(
2463
+ sub === "allow"
2464
+ ? browser
2465
+ ? `${entry.label} links to ${entry.computerLabel ?? "this computer"} now. See your devices: npx tryharness phone list`
2466
+ : `${entry.label}${where(entry)} works now. See your devices: npx tryharness phone list`
2467
+ : browser
2468
+ ? `${entry.label} was not linked. Harness pages will not ask again today; npx tryharness link links a browser any time.`
2469
+ : `${entry.label}${where(entry)} is disconnected and never worked.`
2470
+ );
2471
+ return;
2472
+ }
2135
2473
  if (sub === "list") {
2136
- const response = await daemonRequest({ command: "phone.list" });
2474
+ const response = await listed();
2137
2475
  if (!response.ok)
2138
2476
  throw new Error(response.error || "the daemon could not list phones");
2139
- if (!response.phones.length) {
2477
+ const entries = swarmOf(response);
2478
+ for (const entry of entries.filter(
2479
+ (item) => item.kind === "ask" && item.state === "waiting"
2480
+ ))
2140
2481
  console.log(
2141
- "Nothing paired. Pair a phone: npx tryharness phone pair; connect a browser: npx tryharness link"
2482
+ `${entry.label} asks to link to ${entry.computerLabel ?? "this computer"}. Allow it: npx tryharness phone allow ${entry.id.slice(0, 8)} (or deny)`
2483
+ );
2484
+ const devices = entries.filter((item) => item.kind !== "ask");
2485
+ if (!devices.length) {
2486
+ console.log(
2487
+ `Nothing paired. Pair a phone: ${relayCommand()} phone pair; connect a browser: ${relayCommand()} link`
2142
2488
  );
2143
2489
  return;
2144
2490
  }
2145
- for (const p of response.phones)
2491
+ const seen = new Map(
2492
+ (response.phones ?? []).map((p) => [p.id, p.last_seen_at])
2493
+ );
2494
+ for (const p of devices)
2146
2495
  console.log(
2147
- `${p.id.slice(0, 8)} ${(p.kind || "phone").padEnd(8)} ${p.label.padEnd(20)} paired ${p.paired_at.slice(0, 10)} ${p.revoked_at ? `disconnected ${p.revoked_at.slice(0, 10)}` : p.last_seen_at ? `last seen ${p.last_seen_at.slice(0, 16).replace("T", " ")}` : "not used yet"}`
2496
+ `${p.id.slice(0, 8)} ${(p.kind || "phone").padEnd(8)} ${p.label.padEnd(20)} ${(p.computerLabel ?? "this computer").padEnd(14)} paired ${String(p.at ?? "").slice(0, 10)} ${
2497
+ p.state === "removed"
2498
+ ? "disconnected"
2499
+ : p.state === "waiting"
2500
+ ? `waits for you: npx tryharness phone allow ${p.id.slice(0, 8)}`
2501
+ : seen.get(p.id)
2502
+ ? `last seen ${seen.get(p.id).slice(0, 16).replace("T", " ")}`
2503
+ : p.computerLabel
2504
+ ? "linked"
2505
+ : "not used yet"
2506
+ }`
2148
2507
  );
2149
2508
  return;
2150
2509
  }
2151
2510
  if (sub === "revoke") {
2152
2511
  const prefix = String(argv[1] || "");
2153
2512
  if (!prefix) throw new Error("usage: tryharness phone revoke <phone id>");
2154
- const listed = await daemonRequest({ command: "phone.list" });
2155
- const matches = (listed.phones || []).filter((p) =>
2156
- p.id.startsWith(prefix)
2513
+ const device = pick(
2514
+ swarmOf(await listed()).filter(
2515
+ (entry) => entry.kind !== "ask" && entry.state !== "removed"
2516
+ ),
2517
+ prefix,
2518
+ "no phone with that id (see: tryharness phone list)"
2157
2519
  );
2158
- if (matches.length !== 1)
2159
- throw new Error(
2160
- matches.length
2161
- ? "that id matches more than one phone; type more of it"
2162
- : "no phone with that id (see: tryharness phone list)"
2163
- );
2164
2520
  const response = await daemonRequest({
2165
2521
  command: "phone.revoke",
2166
- id: matches[0].id,
2522
+ id: device.id,
2167
2523
  });
2168
2524
  if (!response.ok) throw new Error(response.error);
2169
2525
  console.log(
2170
- `${matches[0].label} is disconnected. It can no longer reach this computer.`
2526
+ `${device.label}${where(device)} is disconnected. It can no longer reach ${device.computerLabel ?? "this computer"}.`
2171
2527
  );
2172
2528
  return;
2173
2529
  }
2174
2530
  throw new Error(
2175
- "usage: tryharness phone [pair [--link] | list | revoke <phone id>]"
2531
+ "usage: tryharness phone [pair [--link] | list | allow | deny | revoke <phone id>]"
2176
2532
  );
2177
2533
  }
2178
2534
 
@@ -2273,9 +2629,39 @@ async function t3() {
2273
2629
  }
2274
2630
  }
2275
2631
 
2632
+ // `tryharness upgrade [version]`: this computer's Harness fetches the release, checks its signature before any of it
2633
+ // runs (runtime-install.mjs fetchRelease), and only then runs that release's setup.
2634
+ function upgrade() {
2635
+ const spec = argv[0] && !argv[0].startsWith("-") ? argv.shift() : "latest";
2636
+ const fetched = fetchRelease({ spec });
2637
+ try {
2638
+ console.log(
2639
+ fetched.trusted
2640
+ ? `tryharness ${fetched.version} is signed with Harness's release key (${fetched.key}). Setting it up.`
2641
+ : `tryharness ${fetched.version}: Harness on this computer has no release key yet, so this release is trusted as npm sent it, the way a first install is. Setting it up.`
2642
+ );
2643
+ const setup = spawnSync(
2644
+ process.execPath,
2645
+ [path.join(fetched.root, "cli.mjs"), "setup", ...argv],
2646
+ { stdio: "inherit" }
2647
+ );
2648
+ process.exitCode = setup.status ?? 1;
2649
+ } finally {
2650
+ fs.rmSync(fetched.dir, { recursive: true, force: true });
2651
+ }
2652
+ }
2653
+
2654
+ // Once Harness is installed, its own command runs the release it checked; npx would fetch npm's newest.
2655
+ function installedLine() {
2656
+ const installed = relayCommand();
2657
+ return installed.startsWith("npx ")
2658
+ ? ""
2659
+ : `On this computer, run these as ${installed} <command>: it runs the release this computer checked and installed.\n\n`;
2660
+ }
2661
+
2276
2662
  function help() {
2277
2663
  console.log(
2278
- `tryharness ${VERSION}\n\nCommands:\n tryharness set up everything and start the daemon\n tryharness desktop open the Harness desktop app (setup opens it too; --no-desktop skips it)\n tryharness status show daemon, bridge, agent, and index health\n tryharness doctor diagnose the complete connection\n tryharness local [learn] the relay's local models, where they run, what is indexed and the last learning\n tryharness local on|off search over your Desktop, Documents and Downloads by what is in the files (on by default)\n tryharness local add|remove <folder> another folder to search the same way\n tryharness watch [add <name> --run <command> [--every 5m] [--field f | --age f | --count text] [--above n] [--below n] | start <id> | remove <id>]\n watches the relay checks and says out loud only when they are off\n tryharness sync [--agent] rescan local coding history in the background\n tryharness task <id> --follow\n follow a delegated agent run in this terminal\n tryharness board [--all] list open work on the machine's task board\n tryharness board post --for <agent> --objective <text> [--file <brief.md>]\n tryharness board show <id>\n tryharness board post --for codex --objective <text> --run --workspace <dir>\n the daemon runs it and reports back on the task\n tryharness board run <id> authorize a run an agent asked for\n tryharness board release <id>\n tryharness board agents when each agent last read the board\n tryharness board --watch follow the board in this terminal\n tryharness notify on|off desktop notifications for what waits on you\n tryharness usage-totals on|off daily counts of your swarm's work, without your account or any text (on by default)\n tryharness board send <task> <message> send a held reply to another person's agent\n tryharness board snippet [<id> share|keep] code an agent elsewhere asked to see; nothing leaves until you share it\n tryharness board auto <task> on|off auto-send replies on that thread\n tryharness board end <task> --outcome <text>\n tryharness board context <task> <query> search everything written about a task\n tryharness goal set --objective <text> [--team a,b] [--workspace <dir>] a goal your agents work together in one room\n tryharness goal [list | show <id> | stop <id> | resume <id>]\n tryharness room <goal> | room post <goal> <text> [--ask agent,agent]\n tryharness swarm rounds [<thread>] what the coordinator saw, chose and cost each round\n tryharness swarm health [<thread>] who decided each day's rounds: Harness, a backup, or no one\n tryharness swarm ceiling <thread> <dollars|off> what a thread may spend of your Harness credits\n tryharness swarm checkin <thread> "<what>" (--in 2h | --at 14:30 | --every 30m | --daily 09:00 [--days mon-fri]) [--wake codex] [--times n] [--until <date>]\n the thread comes back on its own then, waking those agents or its lead\n tryharness swarm checkins [<thread>] [--all] | swarm checkin remove <id>\n tryharness swarm coordinator [harness|local] who coordinates your threads\n tryharness connect <handle/agent> --about <text> ask another person's agent to work an issue with yours, sealed to their computer\n tryharness peers the keys of other people's computers this one has worked with, to compare\n tryharness machines your computers: which holds the board (home) and which work through it; machines add <code> | name <name> | home\n tryharness agents who is in your swarm, and who can be added\n tryharness agents add [<agent>…] put agents in your swarm; with no name, pick from the ones found here\n tryharness agents remove <agent> take an agent out of your swarm\n tryharness agents setup [<agent>] | agents test <agent> how Harness wakes each agent\n tryharness agents cards what each of your agents is told about the others\n tryharness agents note <agent> <text> [--clear] your own note on an agent's card, told to every other agent\n tryharness agents tier <agent> top|middle|bottom|auto who may hold the team's important roles; auto goes by its model's benchmark\n tryharness lessons [--replaced | --retired] | lessons remove <id> | lessons edit <id> "<text>"\n what your swarm learned from your words, to read, change or take out\n tryharness memory [dream | forget <id> | delete <post id> | back <id>]\n what your swarm keeps from its work, overnight; forget, delete or bring back\n tryharness agents models [<agent>] [--refresh] the models each coding agent lists and the one it runs on\n tryharness agents model <agent> <model> [--effort <level>] | auto | default the model it runs on; auto lets Harness pick per run\n tryharness agents routing "<text>" [--clear] how Auto picks models for your swarm\n tryharness connections on|off outside apps (Gmail, Calendar, Slack, Notion, Linear) for your agents; off by default\n tryharness connections connect apps, choose agent access and review approvals (connections catalog for providers)\n tryharness vault your secrets, kept on this computer: agents use them without seeing them (vault add <name> --hosts <host> | allow <agent> <name> | runs <agent> <name> <VARIABLE> | backup <email> | share <name>)\n tryharness mcp grok-bot print the MCP snippet that puts Grok Bot on the board\n tryharness link connect the browser you use Harness in to this computer, end to end (--print shows the link)\n tryharness phone pair show a QR code that pairs your phone with this computer\n tryharness phone list | revoke <id>\n tryharness t3 approve Harness in T3 Code once, so your messages go into its threads (t3 status | t3 forget)\n tryharness logs [--follow]\n tryharness disconnect\n`
2664
+ `tryharness ${VERSION}\n\n${installedLine()}Commands:\n tryharness set up everything and start the daemon\n tryharness upgrade [version] fetch a newer release, check it is signed with Harness's release key, then set it up\n tryharness desktop open the Harness desktop app (setup opens it too; --no-desktop skips it)\n tryharness status show daemon, bridge, agent, and index health\n tryharness doctor diagnose the complete connection\n tryharness local [learn] the relay's local models, where they run, what is indexed and the last learning\n tryharness local on|off search over your Desktop, Documents and Downloads by what is in the files (on by default)\n tryharness local add|remove <folder> another folder to search the same way\n tryharness watch [add <name> --run <command> [--every 5m] [--field f | --age f | --count text] [--above n] [--below n] | start <id> | remove <id>]\n watches the relay checks and says out loud only when they are off\n tryharness sync [--agent] rescan local coding history in the background\n tryharness task <id> --follow\n follow a delegated agent run in this terminal\n tryharness runs what your agents are running on this computer now\n tryharness steer <thread or run> "<words>" [--agent <agent>]\n tell an agent something while it works\n tryharness ssh [<cloud computer>] [--key <file>] [--print] [-- <command>]\n SSH into your cloud computer with your own key; it wakes if asleep\n tryharness board [--all] list open work on the machine's task board\n tryharness board post --for <agent> --objective <text> [--file <brief.md>]\n tryharness board show <id>\n tryharness board post --for codex --objective <text> --run --workspace <dir>\n the daemon runs it and reports back on the task\n tryharness board run <id> authorize a run an agent asked for\n tryharness board release <id>\n tryharness board agents when each agent last read the board\n tryharness board --watch follow the board in this terminal\n tryharness notify on|off desktop notifications for what waits on you\n tryharness usage-totals on|off daily counts of your swarm's work, without your account or any text (on by default)\n tryharness board send <task> <message> send a held reply to another person's agent\n tryharness board snippet [<id> share|keep] code an agent elsewhere asked to see; nothing leaves until you share it\n tryharness board auto <task> on|off auto-send replies on that thread\n tryharness board end <task> --outcome <text>\n tryharness board context <task> <query> search everything written about a task\n tryharness goal set --objective <text> [--team a,b] [--workspace <dir>] a goal your agents work together in one room\n tryharness goal [list | show <id> | stop <id> | resume <id>]\n tryharness room <goal> | room post <goal> <text> [--ask agent,agent]\n tryharness swarm rounds [<thread>] what the coordinator saw, chose and cost each round\n tryharness swarm health [<thread>] who decided each day's rounds: Harness, a backup, or no one\n tryharness swarm ceiling <thread> <dollars|off> what a thread may spend of your Harness credits\n tryharness swarm checkin <thread> "<what>" (--in 2h | --at 14:30 | --every 30m | --daily 09:00 [--days mon-fri]) [--wake codex] [--times n] [--until <date>]\n the thread comes back on its own then, waking those agents or its lead\n tryharness swarm checkins [<thread>] [--all] | swarm checkin remove <id>\n tryharness swarm coordinator [harness|local] who coordinates your threads\n tryharness connect <handle/agent> --about <text> ask another person's agent to work an issue with yours, sealed to their computer\n tryharness peers the keys of other people's computers this one has worked with, to compare\n tryharness machines your computers: which holds the board (home) and which work through it; machines add <code> [--hosted] | name <name> | home | remove <name>\n tryharness backup [on | now | restore | off] an encrypted backup of your board, for Residents; only your passphrase opens it\n tryharness agents who is in your swarm, and who can be added\n tryharness agents add [<agent>…] put agents in your swarm; with no name, pick from the ones found here\n tryharness agents remove <agent> take an agent out of your swarm\n tryharness agents confirm <agent> the program Harness starts for an agent, after you install it somewhere new\n tryharness agents setup [<agent>] | agents test <agent> how Harness wakes each agent\n tryharness agents cards what each of your agents is told about the others\n tryharness agents note <agent> <text> [--clear] your own note on an agent's card, told to every other agent\n tryharness lessons [--replaced | --retired] | lessons remove <id> | lessons edit <id> "<text>"\n what your swarm learned from your words, to read, change or take out\n tryharness memory [dream | forget <id> | delete <post id> | back <id>]\n what your swarm keeps from its work, overnight; forget, delete or bring back\n tryharness agents models [<agent>] [--refresh] the models each coding agent lists and the one it runs on\n tryharness agents model <agent> <model> [--effort <level>] | auto | default the model it runs on; auto lets Harness pick per run\n tryharness agents routing "<text>" [--clear] how Auto picks models for your swarm\n tryharness connections on|off outside apps (Gmail, Calendar, Slack, Notion, Linear) for your agents; off by default\n tryharness connections connect apps, choose agent access and review approvals (connections catalog for providers)\n tryharness vault your secrets, kept on this computer: agents use them without seeing them (vault add <name> --hosts <host> | allow <agent> <name> | runs <agent> <name> <VARIABLE> | backup <email> | share <name>)\n tryharness mcp grok-bot print the MCP snippet that puts Grok Bot on the board\n tryharness link connect the browser you use Harness in to this computer, end to end (--print shows the link)\n tryharness phone pair show a QR code that pairs your phone with this computer\n tryharness phone list | revoke <id>\n tryharness t3 approve Harness in T3 Code once, so your messages go into its threads (t3 status | t3 forget)\n tryharness logs [--follow]\n tryharness uninstall [--everything] take Harness off this computer; --everything also deletes your board and history\n`
2279
2665
  );
2280
2666
  }
2281
2667
 
@@ -2317,7 +2703,7 @@ try {
2317
2703
  });
2318
2704
  console.log(
2319
2705
  on
2320
- ? "Apps are on. Connect one with npx tryharness connections add; agents see them in sessions they start from now on."
2706
+ ? `Apps are on. Connect one with ${relayCommand()} connections add; agents see them in sessions they start from now on.`
2321
2707
  : "Apps are off. No agent can use a connected app until you turn them on again."
2322
2708
  );
2323
2709
  } else if (command === "connections") {
@@ -2336,17 +2722,25 @@ try {
2336
2722
  else if (command === "t3") await t3();
2337
2723
  else if (command === "peers") await peers();
2338
2724
  else if (command === "machines") await machines();
2725
+ else if (command === "ssh") await ssh();
2726
+ else if (command === "steer") await steer();
2727
+ else if (command === "runs") await runs();
2728
+ else if (command === "backup")
2729
+ await backupCommand({ argv, ui: createUi(), daemonRequest });
2339
2730
  else if (command === "connect") await connectAgent();
2340
2731
  else if (command === "desktop") {
2341
2732
  const shown = await desktop();
2342
2733
  console.log(shown.text);
2343
2734
  if (!shown.ok) process.exitCode = 1;
2344
2735
  } else if (command === "logs") logs();
2345
- else if (command === "disconnect") await disconnect();
2736
+ else if (command === "uninstall") await uninstall();
2346
2737
  else if (command === "daemon") {
2347
2738
  const { startDaemon } = await import("./lib/daemon.mjs");
2348
2739
  await startDaemon();
2349
- } else if (command === "version") console.log(VERSION);
2740
+ } else if (command === "cloud-enroll") await cloudEnroll();
2741
+ else if (command === "cloud-start") await cloudStart();
2742
+ else if (command === "upgrade") upgrade();
2743
+ else if (command === "version") console.log(VERSION);
2350
2744
  else if (["help", "--help", "-h"].includes(command)) help();
2351
2745
  else throw new Error(`unknown command '${command}' (run: tryharness help)`);
2352
2746
  } catch (error) {