tryharness 0.7.45 → 0.7.54

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (125) hide show
  1. package/README.md +239 -14
  2. package/assets/dsh-plugin.mjs +72 -0
  3. package/assets/opencode-plugin.js +4 -3
  4. package/cli.mjs +497 -196
  5. package/lib/actorRoster.mjs +28 -5
  6. package/lib/adapters.mjs +165 -222
  7. package/lib/agentRuntimeConfig.mjs +36 -0
  8. package/lib/agentRuntimes.mjs +570 -0
  9. package/lib/agentSignIn.mjs +226 -0
  10. package/lib/atlas.mjs +7 -2
  11. package/lib/audit.mjs +643 -0
  12. package/lib/backupSetup.mjs +141 -0
  13. package/lib/boardAccess.mjs +8 -1
  14. package/lib/boardBackup.mjs +283 -0
  15. package/lib/boardCommands.mjs +5 -10
  16. package/lib/boardFileCommands.mjs +2 -1
  17. package/lib/boardMirror.mjs +523 -0
  18. package/lib/boardProtocol.json +263 -6
  19. package/lib/boardTools.mjs +2 -6
  20. package/lib/boardWaits.mjs +102 -0
  21. package/lib/book.mjs +659 -0
  22. package/lib/bridge.mjs +26 -4
  23. package/lib/browserWake.mjs +60 -0
  24. package/lib/cards.mjs +159 -16
  25. package/lib/cloudBoot.mjs +124 -0
  26. package/lib/commands.mjs +25 -5
  27. package/lib/connectionTools.d.ts +13 -0
  28. package/lib/connectionTools.js +45 -0
  29. package/lib/connectorAuth.mjs +309 -0
  30. package/lib/connectorCatalog.json +41 -0
  31. package/lib/connectorCommands.mjs +121 -0
  32. package/lib/connectorGoogle.mjs +513 -0
  33. package/lib/connectors.mjs +805 -0
  34. package/lib/context.mjs +18 -4
  35. package/lib/contractGate.mjs +377 -0
  36. package/lib/coordinator.mjs +152 -39
  37. package/lib/coreModels.mjs +78 -0
  38. package/lib/daemon.mjs +973 -54
  39. package/lib/desk.mjs +239 -0
  40. package/lib/desktop.mjs +113 -8
  41. package/lib/digest.mjs +32 -0
  42. package/lib/directLink.mjs +283 -0
  43. package/lib/environments.mjs +825 -0
  44. package/lib/folders.mjs +4 -4
  45. package/lib/gitHost.mjs +174 -0
  46. package/lib/goalCommands.mjs +58 -14
  47. package/lib/hookDialects.mjs +298 -0
  48. package/lib/inference.mjs +263 -152
  49. package/lib/landed.mjs +887 -0
  50. package/lib/lessons.mjs +6 -0
  51. package/lib/lineup.mjs +324 -0
  52. package/lib/live.mjs +284 -13
  53. package/lib/localmodels.mjs +10 -0
  54. package/lib/machineIdentity.mjs +3 -0
  55. package/lib/machineRoutes.mjs +40 -2
  56. package/lib/machineRuns.mjs +30 -3
  57. package/lib/machineSeal.mjs +69 -10
  58. package/lib/mcp-stdio.mjs +189 -120
  59. package/lib/mcpRelay.mjs +119 -0
  60. package/lib/members.json +26 -0
  61. package/lib/members.mjs +33 -0
  62. package/lib/modelMemory.mjs +100 -0
  63. package/lib/models.mjs +48 -15
  64. package/lib/museSession.mjs +122 -0
  65. package/lib/nativeHost.mjs +203 -0
  66. package/lib/neovim.mjs +126 -0
  67. package/lib/network.mjs +7 -2
  68. package/lib/nudge.mjs +57 -18
  69. package/lib/onboard.mjs +430 -1
  70. package/lib/oneclawLocal.mjs +150 -0
  71. package/lib/ownMachines.mjs +828 -39
  72. package/lib/pairing.mjs +182 -0
  73. package/lib/paths.mjs +8 -0
  74. package/lib/personModel.mjs +89 -0
  75. package/lib/phones.mjs +119 -3
  76. package/lib/placeCommands.mjs +27 -0
  77. package/lib/places.mjs +337 -9
  78. package/lib/plans.mjs +151 -27
  79. package/lib/profile.mjs +152 -0
  80. package/lib/projects.mjs +624 -137
  81. package/lib/readiness.mjs +400 -0
  82. package/lib/record.mjs +115 -0
  83. package/lib/repoLinks.mjs +354 -0
  84. package/lib/roomChannels.mjs +641 -0
  85. package/lib/runBrief.mjs +32 -2
  86. package/lib/runRequests.mjs +157 -0
  87. package/lib/runWorker.mjs +37 -9
  88. package/lib/runner.mjs +74 -11
  89. package/lib/secretPatterns.json +55 -0
  90. package/lib/secrets.mjs +10 -27
  91. package/lib/seen.mjs +102 -0
  92. package/lib/service.mjs +11 -6
  93. package/lib/sessionControl.mjs +386 -96
  94. package/lib/sessionIndex.mjs +5 -3
  95. package/lib/specialties.json +74 -0
  96. package/lib/specialties.mjs +477 -0
  97. package/lib/specialtyKeys.d.ts +3 -0
  98. package/lib/specialtyKeys.js +58 -0
  99. package/lib/specialtyNotice.mjs +147 -0
  100. package/lib/specialtySnapshot.mjs +138 -0
  101. package/lib/store.mjs +829 -29
  102. package/lib/subagents.mjs +8 -4
  103. package/lib/swarm.mjs +483 -37
  104. package/lib/swarmMemory.mjs +947 -0
  105. package/lib/t3.mjs +56 -17
  106. package/lib/taskCommands.mjs +91 -13
  107. package/lib/taskRuns.mjs +68 -11
  108. package/lib/team.json +253 -144
  109. package/lib/team.mjs +538 -147
  110. package/lib/threadLine.mjs +116 -0
  111. package/lib/threadRuns.mjs +78 -12
  112. package/lib/threadView.mjs +66 -16
  113. package/lib/tokenizer.mjs +405 -0
  114. package/lib/ui.mjs +16 -2
  115. package/lib/usageTotals.mjs +148 -0
  116. package/lib/vault.mjs +1144 -0
  117. package/lib/vaultCloud.mjs +117 -0
  118. package/lib/vaultCommands.mjs +201 -0
  119. package/lib/vaultTools.d.ts +12 -0
  120. package/lib/vaultTools.js +42 -0
  121. package/lib/windowAsks.mjs +42 -0
  122. package/lib/workFocus.mjs +59 -0
  123. package/lib/workLinks.mjs +90 -0
  124. package/lib/worktrees.mjs +51 -13
  125. package/package.json +10 -5
package/cli.mjs CHANGED
@@ -12,21 +12,43 @@ import {
12
12
  mcpClientSnippet,
13
13
  removeAgentConfigurations,
14
14
  } from "./lib/adapters.mjs";
15
- import { banner, setupSwarm, testAgent } from "./lib/onboard.mjs";
15
+ import {
16
+ addAgents,
17
+ banner,
18
+ checkAgents,
19
+ removeAgent,
20
+ showLineup,
21
+ setupChosen,
22
+ setupT3,
23
+ setupSwarm,
24
+ testAgent,
25
+ walkThrough,
26
+ } from "./lib/onboard.mjs";
27
+ import { agentsHere, createLineup, lineupOf } from "./lib/lineup.mjs";
28
+ import { CHECKABLE, createAgentReadiness } from "./lib/readiness.mjs";
29
+ import { writeBrowserOffer } from "./lib/phones.mjs";
16
30
  import { createUi } from "./lib/ui.mjs";
31
+ import { backupCommand, offerBackup } from "./lib/backupSetup.mjs";
17
32
  import pc from "picocolors";
18
33
  import { removeLocalWakes } from "./lib/wakes.mjs";
19
34
  import { detectAgents } from "./lib/commands.mjs";
20
35
  import { daemonRequest } from "./lib/control-client.mjs";
21
36
  import { ensureDir, readJson, writeJsonAtomic } from "./lib/files.mjs";
37
+ import { hostApp, processTable } from "./lib/live.mjs";
38
+ import { noteSetupTerminal } from "./lib/places.mjs";
22
39
  import { paths } from "./lib/paths.mjs";
23
- import { currentRuntime, installRuntime } from "./lib/runtime-install.mjs";
24
40
  import {
25
- MODELS,
26
- ensureLlama,
27
- ensureModels,
28
- modelsPresent,
29
- } from "./lib/localmodels.mjs";
41
+ joinSwarm,
42
+ keepJoinCode,
43
+ startPairing,
44
+ waitForApproval,
45
+ } from "./lib/pairing.mjs";
46
+ import { setupProfile } from "./lib/profile.mjs";
47
+ import { cloudEnroll } from "./lib/cloudBoot.mjs";
48
+ import { currentRuntime, installRuntime } from "./lib/runtime-install.mjs";
49
+ import { installNativeHost, removeNativeHost } from "./lib/nativeHost.mjs";
50
+ import { CORE, coreSizeMb } from "./lib/coreModels.mjs";
51
+ import { MODELS, modelsPresent } from "./lib/localmodels.mjs";
30
52
  import {
31
53
  installService,
32
54
  launcherMissing,
@@ -36,7 +58,7 @@ import {
36
58
  import {
37
59
  canShowDesktop,
38
60
  openDesktop,
39
- retireDesktop,
61
+ uninstallDesktop,
40
62
  setupDesktop,
41
63
  } from "./lib/desktop.mjs";
42
64
 
@@ -122,67 +144,50 @@ async function validateConnection(config) {
122
144
  }
123
145
  }
124
146
 
147
+ // Whether a browser can open here: not over SSH, and on Linux only with a display.
148
+ const canOpenBrowser = () =>
149
+ !process.env.SSH_CONNECTION &&
150
+ !process.env.SSH_TTY &&
151
+ (process.platform !== "linux" ||
152
+ Boolean(process.env.DISPLAY || process.env.WAYLAND_DISPLAY));
153
+
154
+ // One page in the browser approves this computer and links that browser to it in the same click: the address fragment,
155
+ // which no server sees, carries the pairing code and a browser link setup made for the daemon (phones.mjs).
125
156
  async function pair(pairOrigin, agents, ui) {
126
- const response = await fetch(pairOrigin + "/api/pair/start", {
127
- method: "POST",
128
- headers: { "content-type": "application/json" },
129
- body: JSON.stringify({ hostname: os.hostname().slice(0, 64), agents }),
130
- signal: AbortSignal.timeout(15_000),
131
- });
132
- if (!response.ok)
133
- throw new Error(`pairing unavailable (HTTP ${response.status})`);
134
- const { pairId, code } = await response.json();
157
+ const { pairId, code, own } = await startPairing(pairOrigin, agents);
158
+ if (own) keepJoinCode(paths.machine, code);
159
+ const page = `${pairOrigin}/pair`;
160
+ const browser = own && canOpenBrowser();
161
+ const link = browser
162
+ ? await writeBrowserOffer({
163
+ identityFile: paths.phoneIdentity,
164
+ offerFile: paths.browserOffer,
165
+ })
166
+ : null;
167
+ const opened =
168
+ browser && openUrl(`${page}#${new URLSearchParams({ c: code })}&${link}`);
169
+ const approve = opened
170
+ ? "Your browser just opened. Sign in with your email if it asks, then press Connect. No account yet? Signing in makes one."
171
+ : `Open ${page} in a browser, sign in with your email, and enter this code. No account yet? Signing in makes one.`;
172
+ const elsewhere = own
173
+ ? "\nAlready use Harness on another computer? Click the Harness icon in its menu bar, choose Add a Computer, and type this code there instead."
174
+ : "";
135
175
  ui.note(
136
- `${pc.bold(code)}\n\n${pc.dim("In Harness: Settings → Connections → Connect a machine, then enter this code.")}`,
137
- "Pair this computer"
176
+ `${pc.bold(code)}\n\n${pc.dim(approve + elsewhere)}`,
177
+ "Sign in to Harness"
138
178
  );
139
179
  const spin = ui.spinner();
140
- spin.start("Waiting for your approval (the code works for 10 minutes)");
141
- return new Promise((resolve, reject) => {
142
- fetch(pairOrigin + "/api/pair/wait/" + pairId, {
143
- headers: { accept: "text/event-stream" },
144
- })
145
- .then(async (waitResponse) => {
146
- if (!waitResponse.ok || !waitResponse.body)
147
- throw new Error("pairing stream failed");
148
- const reader = waitResponse.body.getReader();
149
- const decoder = new TextDecoder();
150
- let buffer = "";
151
- for (;;) {
152
- const { done, value } = await reader.read();
153
- if (done) break;
154
- buffer += decoder.decode(value, { stream: true });
155
- const frames = buffer.split("\n\n");
156
- buffer = frames.pop() || "";
157
- for (const frame of frames) {
158
- const line = frame
159
- .split("\n")
160
- .find((entry) => entry.startsWith("data: "));
161
- if (!line) continue;
162
- const payload = JSON.parse(line.slice(6));
163
- if (payload.token) {
164
- resolve(payload.token);
165
- return;
166
- }
167
- if (payload.error) {
168
- reject(new Error(payload.error));
169
- return;
170
- }
171
- }
172
- }
173
- reject(new Error("pairing stream ended without approval"));
174
- })
175
- .catch(reject);
176
- }).then(
177
- (token) => {
178
- spin.stop("Paired with Harness");
179
- return token;
180
- },
181
- (error) => {
182
- spin.stop("Pairing did not finish", 2);
183
- throw error;
184
- }
180
+ spin.start(
181
+ "Waiting for you to press Connect (the code works for 10 minutes)"
185
182
  );
183
+ try {
184
+ const token = await waitForApproval(pairOrigin, pairId);
185
+ spin.stop("Connected to your Harness account");
186
+ return { token, code: own ? code : null, linkOffered: Boolean(link) };
187
+ } catch (error) {
188
+ spin.stop("Pairing did not finish", 2);
189
+ throw error;
190
+ }
186
191
  }
187
192
 
188
193
  async function waitForDaemon(timeoutMs = 12_000) {
@@ -207,28 +212,42 @@ async function waitForDaemon(timeoutMs = 12_000) {
207
212
 
208
213
  async function connect() {
209
214
  ensureDir(paths.home);
210
- const detected = detectAgents();
211
- const installed = detected
212
- .filter((entry) => entry.path)
213
- .map((entry) => entry.agent);
215
+ // The agents installed here (lineup.mjs). Each coding agent gets its one-line prompt now (readiness.mjs), so the
216
+ // answers come in while the person signs in.
217
+ const here = agentsHere();
214
218
  const requested = argv.flatMap((value, index) =>
215
219
  value === "--agent" && argv[index + 1] ? [argv[index + 1]] : []
216
220
  );
217
221
  for (const agent of requested)
218
- if (!AGENTS.includes(agent)) throw new Error(`unknown agent '${agent}'`);
219
- const selected = requested.length
220
- ? installed.filter((agent) => requested.includes(agent))
221
- : installed;
222
+ if (![...AGENTS, "openclaw", "hermes"].includes(agent))
223
+ throw new Error(`unknown agent '${agent}'`);
224
+ const removed = readJson(paths.config, {}).swarmRemoved ?? [];
225
+ const readiness = createAgentReadiness();
226
+ const checks = new Map(
227
+ here
228
+ .filter(
229
+ (entry) =>
230
+ CHECKABLE.includes(entry.id) &&
231
+ (requested.length
232
+ ? requested.includes(entry.id)
233
+ : !removed.includes(entry.id))
234
+ )
235
+ .map((entry) => [entry.id, readiness.check(entry.id)])
236
+ );
237
+ const found = here
238
+ .filter((entry) => AGENTS.includes(entry.id))
239
+ .map((entry) => entry.id);
222
240
  const ui = createUi();
241
+ // Where the person works, for Open until it has seen their sessions (places.mjs).
242
+ const table = processTable();
243
+ noteSetupTerminal({
244
+ host: hostApp(table, process.pid),
245
+ tty: table.get(process.pid)?.tty ?? null,
246
+ });
223
247
  console.log(`\n${banner(VERSION)}\n`);
224
248
  ui.intro(
225
249
  `${pc.bgCyan(pc.black(" tryharness "))} Setting up Harness on this computer`
226
250
  );
227
- ui.step(
228
- installed.length
229
- ? `Found ${installed.join(", ")}`
230
- : "No supported coding agents found"
231
- );
232
251
 
233
252
  const pairOrigin = origin();
234
253
  let config = readJson(paths.config, {});
@@ -240,20 +259,44 @@ async function connect() {
240
259
  ui.success(
241
260
  `Connected to Harness ${pc.dim(`· ${new URL(pairOrigin).host}`)}`
242
261
  );
243
- else {
244
- const token = await pair(pairOrigin, selected, ui);
245
- config = { ...config, origin: pairOrigin, token };
262
+ let setupCode = null;
263
+ let linkOffered = false;
264
+ if (!reusable) {
265
+ const paired = await pair(pairOrigin, found, ui);
266
+ setupCode = paired.code;
267
+ linkOffered = paired.linkOffered;
268
+ config = { ...config, origin: pairOrigin, token: paired.token };
246
269
  writeJsonAtomic(paths.config, config);
247
270
  }
248
271
 
272
+ // The order is the person's: Harness starts with the agents that answered, so the browser they pressed Connect in
273
+ // links and lists them at once, and only then are they walked through the rest, which join as each answers.
274
+ const before = readJson(paths.config, {});
275
+ const previous = lineupOf(before);
276
+ const { ready, waiting } = await checkAgents({
277
+ ui,
278
+ here,
279
+ checks,
280
+ readiness,
281
+ requested,
282
+ removed,
283
+ });
284
+ // Agents that live elsewhere stay as they were: in a swarm from before the lineup, all of them (they were in it).
285
+ const kept = previous
286
+ ? previous.filter((agent) => !here.some((entry) => entry.id === agent))
287
+ : before.agentStates
288
+ ? ["grok-bot", "bankr", "quotient", "muse"]
289
+ : [];
290
+
249
291
  // The persistent runtime is version-pinned; neither MCP clients nor the login service
250
292
  // point into npm's temporary npx cache.
251
293
  const spin = ui.spinner();
252
- spin.start("Installing the Harness runtime and connecting your agents");
294
+ spin.start("Starting Harness on this computer");
253
295
  const runtimeRoot = installRuntime({
254
296
  sourceRoot: SOURCE_ROOT,
255
297
  version: VERSION,
256
298
  });
299
+ const selected = ready.filter((agent) => AGENTS.includes(agent));
257
300
  const states = configureAgents({ runtimeRoot, selected });
258
301
  const stateMap = Object.fromEntries(
259
302
  states.map((state) => [state.agent, state])
@@ -263,43 +306,60 @@ async function connect() {
263
306
  version: VERSION,
264
307
  runtimeRoot,
265
308
  agentStates: stateMap,
309
+ swarmAgents: [...new Set([...ready, ...kept])],
310
+ // The daemon downloads the relay's core local models in the background (coreModels.mjs).
311
+ localModels: "download",
266
312
  };
267
313
  writeJsonAtomic(paths.config, config);
268
314
  const service = installService({ runtimeRoot });
269
- spin.message("Starting the daemon");
315
+ // The Harness extension in this computer's browsers finds this daemon by itself, so its window links here.
316
+ try {
317
+ installNativeHost({ runtimeRoot });
318
+ } catch (error) {
319
+ ui.warn(
320
+ `The extension cannot find this computer by itself (${error.message}); link the browser with npx tryharness link`
321
+ );
322
+ }
270
323
  try {
271
324
  await waitForDaemon();
272
325
  } catch (error) {
273
- spin.stop("The daemon did not connect to Harness", 2);
326
+ spin.stop("Harness did not connect", 2);
274
327
  throw error;
275
328
  }
276
329
  spin.stop(
277
- `Daemon running ${pc.dim(`· ${service.manager}, connected to Harness`)}`
330
+ `Harness is running on this computer ${pc.dim(`· ${service.manager}`)}`
278
331
  );
279
- await setupSwarm({ runtimeRoot, states, daemonRequest, ui });
280
- try {
281
- const devices = await daemonRequest({ command: "phone.list" });
282
- if (
283
- devices.ok &&
284
- !devices.phones.some(
285
- (device) => device.kind === "browser" && !device.revoked_at
286
- )
287
- ) {
288
- const offer = await browserLink();
289
- ui.info(
290
- offer.opened
291
- ? "Opened Harness in your browser to connect it to this computer end to end. The link works once, for 10 minutes."
292
- : `Open this in the browser you use Harness in. It works once, for 10 minutes, and is the pairing secret:\n${offer.url}`
293
- );
294
- } else if (devices.ok) ui.success("Browser connected end to end");
295
- } catch (error) {
296
- ui.warn(
297
- `Browser not connected (${error.message}). Run: npx tryharness link`
298
- );
299
- }
332
+ // Harness already runs, so the browser lists the agents while the person tells them who they work for.
333
+ await setupProfile({ ui, origin: pairOrigin, token: config.token });
334
+ const joined = await walkThrough({
335
+ ui,
336
+ waiting,
337
+ readiness,
338
+ join: (agent) =>
339
+ daemonRequest({ command: "swarm.add", target: agent }).catch((error) => ({
340
+ ok: false,
341
+ error: error.message,
342
+ })),
343
+ });
344
+ const chosen = [...ready, ...joined];
345
+ // An agent that joined during the walkthrough was connected by the daemon (lineup.mjs joinAgent), which saved its state.
346
+ const saved = readJson(paths.config, {}).agentStates ?? {};
347
+ await setupChosen({
348
+ chosen,
349
+ here,
350
+ states: states.map((state) => saved[state.agent] ?? state),
351
+ runtimeRoot,
352
+ daemonRequest,
353
+ ui,
354
+ });
355
+ await setupT3({
356
+ ui,
357
+ daemonRequest,
358
+ open: (url) => !has("--print") && canOpenBrowser() && openUrl(url),
359
+ });
300
360
  if (!has("--no-desktop")) {
301
361
  const spin = ui.spinner();
302
- spin.start("Getting the newest desktop app");
362
+ spin.start("Getting the Harness desktop app");
303
363
  const shown = await desktop();
304
364
  spin.stop(shown.text, shown.ok ? 0 : 2);
305
365
  // The app brings the daemon's launcher: the daemon starts through it from now on (service.mjs).
@@ -308,56 +368,6 @@ async function connect() {
308
368
  await waitForDaemon().catch(() => {});
309
369
  }
310
370
  }
311
- // The relay's core local models (localmodels.mjs) and the server that runs them come down with setup, so agents get
312
- // context packs, code search, the handoff firewall and images checked before they leave from the first task. Each file
313
- // is checked against its pinned hash.
314
- const core = MODELS.filter((entry) => entry.tier === "core").map(
315
- (entry) => entry.id
316
- );
317
- const localRoot = path.join(paths.home, "local");
318
- if (modelsPresent(localRoot, core)) ui.success("Local models ready");
319
- else {
320
- const download = ui.spinner();
321
- const size = Math.round(
322
- MODELS.filter((entry) => core.includes(entry.id))
323
- .flatMap((entry) => entry.files)
324
- .reduce((sum, file) => sum + file.size, 0) / 1e6
325
- );
326
- download.start(`Downloading the local models (about ${size} MB, once)`);
327
- // The classifiers run without the model server, so one that cannot start here does not hold them back.
328
- const failures = [];
329
- for (const step of [
330
- () =>
331
- ensureLlama({
332
- root: localRoot,
333
- log: (line) =>
334
- download.message(
335
- `Downloading the local models · ${line.slice(0, 40)}`
336
- ),
337
- }),
338
- () =>
339
- ensureModels({
340
- root: localRoot,
341
- ids: core,
342
- log: (line) =>
343
- download.message(
344
- `Downloading the local models · ${line.slice(0, 40)}`
345
- ),
346
- }),
347
- ]) {
348
- try {
349
- await step();
350
- } catch (error) {
351
- failures.push(error.message);
352
- }
353
- }
354
- if (failures.length)
355
- download.stop(
356
- `Local models not ready (${failures.join("; ")}). Agents work as before until the next setup run`,
357
- 2
358
- );
359
- else download.stop("Local models ready");
360
- }
361
371
  const failed = states.filter(
362
372
  (state) =>
363
373
  selected.includes(state.agent) && state.installed && !state.configured
@@ -367,15 +377,68 @@ async function connect() {
367
377
  `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.`
368
378
  );
369
379
  }
370
- ui.info("History indexes locally in the background");
371
- if (!readJson(paths.config, {}).libraryOff)
372
- ui.info(
373
- `Your agents on this computer can search what is in your Desktop, Documents and Downloads. It stays on this computer${process.platform === "darwin" ? "; your Mac asks you once, when Harness first reads them" : ""}.\n${pc.dim("Change it: npx tryharness local off")}`
374
- );
375
- ui.info(
376
- `Your coding agents start the tasks you ask for in folders they have worked in, up to 10 a day each, without a Start. Tasks another agent wrote wait for you.\n${pc.dim("Change it: npx tryharness board standing")}`
380
+ // The browser you use Harness in on this computer links to this computer; on an added one it works the board home
381
+ // keeps through it, and the agents here can ask it what is on this screen. The page that approved this computer links
382
+ // its browser itself once Harness runs here (pair above), which has had the whole walkthrough to happen.
383
+ try {
384
+ const devices = await daemonRequest({ command: "phone.list" });
385
+ const linked =
386
+ devices.ok &&
387
+ devices.phones.some(
388
+ (device) => device.kind === "browser" && !device.revoked_at
389
+ );
390
+ if (linked) ui.success("Your browser is linked to this computer");
391
+ else if (linkOffered)
392
+ ui.success(
393
+ "Your browser links to this computer from the page you pressed Connect on"
394
+ );
395
+ else if (devices.ok) {
396
+ const offer = await browserLink();
397
+ ui.info(
398
+ offer.opened
399
+ ? "Opened Harness in your browser to link it to this computer. The link works once, for 10 minutes."
400
+ : `To talk to this computer's agents from your browser, open this link in it. It works once, for 10 minutes; keep it to yourself:\n${offer.url}`
401
+ );
402
+ }
403
+ } catch (error) {
404
+ ui.warn(`Browser not linked (${error.message}). Run: npx tryharness link`);
405
+ }
406
+ // Last, so nothing else waits on it: an added computer works on its own until its code is typed on home.
407
+ const role = await joinSwarm({ ui, code: setupCode, daemonRequest });
408
+ // A Resident coming back gets their board back; one without a backup may start one.
409
+ const onBoard = await daemonRequest({
410
+ command: "board.list",
411
+ agent: "user",
412
+ all: true,
413
+ limit: 1,
414
+ }).catch(() => null);
415
+ await offerBackup({
416
+ ui,
417
+ daemonRequest,
418
+ role,
419
+ boardIsEmpty: onBoard?.ok === true && !onBoard.tasks?.length,
420
+ });
421
+ const library = !readJson(paths.config, {}).libraryOff;
422
+ const modelsHere = modelsPresent(path.join(paths.home, "local"), CORE);
423
+ ui.note(
424
+ [
425
+ ...(modelsHere
426
+ ? []
427
+ : [
428
+ `Harness downloads its local models (about ${coreSizeMb()} MB) in the background. Your agents work while it does.`,
429
+ ]),
430
+ ...(library
431
+ ? [
432
+ `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")}`,
433
+ ]
434
+ : []),
435
+ `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")}`,
436
+ ].join("\n\n"),
437
+ "Good to know"
438
+ );
439
+ ui.outro(
440
+ `Done. Talk to your agents from Harness in your browser: ${pairOrigin}/dashboard`
377
441
  );
378
- ui.outro("Done. You can close this terminal.");
379
442
  }
380
443
 
381
444
  // The desktop app: the newest build for this machine, installed and opened. Never fatal; the
@@ -500,6 +563,12 @@ async function local() {
500
563
  );
501
564
  return;
502
565
  }
566
+ if (current.coreModels?.downloading)
567
+ console.log("core models: downloading in the background");
568
+ else if (current.coreModels?.error)
569
+ console.log(
570
+ `core models: the last download failed (${current.coreModels.error}); tried again when the daemon next starts`
571
+ );
503
572
  console.log(
504
573
  `runs on: ${current.device ? (current.device.gpu ? "GPU" : "CPU") : "not checked yet"}`
505
574
  );
@@ -636,6 +705,24 @@ async function notify() {
636
705
  );
637
706
  }
638
707
 
708
+ async function usageTotals() {
709
+ const mode = argv[0];
710
+ const config = readJson(paths.config, {});
711
+ if (!["on", "off"].includes(mode)) {
712
+ console.log(
713
+ `usage totals: ${config.usageTotals === false ? "off" : "on"} (tryharness usage-totals on|off)\n` +
714
+ "Once a day this computer tells Harness how much your swarm did the day before, as counts only: tasks posted, finished and failed, handoffs, threads, posts and coordinator rounds, by agent type. No task text, files, folders or computer details are sent, and Harness keeps the counts without your account."
715
+ );
716
+ return;
717
+ }
718
+ writeJsonAtomic(paths.config, { ...config, usageTotals: mode === "on" });
719
+ console.log(
720
+ mode === "on"
721
+ ? "usage totals on. Days from today are sent once they end."
722
+ : "usage totals off. Nothing more is sent, and days while it is off are never sent."
723
+ );
724
+ }
725
+
639
726
  async function connectAgent() {
640
727
  // Ask another person's listed agent to work an issue with one of ours: a request their Harness shows them.
641
728
  const to = String(argv[0] || "");
@@ -679,15 +766,21 @@ async function connectAgent() {
679
766
  // new one shows until the person types it on home.
680
767
  async function machines() {
681
768
  const sub = argv[0];
682
- if (sub === "confirm") {
769
+ if (sub === "add" || sub === "confirm") {
683
770
  const response = await daemonRequest(
684
- { command: "machines.confirm", code: String(argv[1] || "") },
771
+ { command: "machines.add", code: String(argv[1] || "") },
685
772
  30_000
686
773
  );
687
- if (!response.ok) throw new Error(response.error || "not confirmed");
688
- console.log(
689
- `Confirmed ${response.machine || "the computer"} (key ${response.fingerprint}). Its agents now work on this computer's board, sealed end to end between the two; Harness carries the calls and cannot read them.`
690
- );
774
+ if (!response.ok) throw new Error(response.error || "not added");
775
+ if (response.state === "approved") console.log(response.note);
776
+ else if (response.state === "waiting")
777
+ console.log(
778
+ `${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.`
779
+ );
780
+ else
781
+ console.log(
782
+ `Added ${response.machine || "the computer"} (key ${response.fingerprint}). Its agents now work on this computer's board, sealed end to end between the two; Harness carries the calls and cannot read them.`
783
+ );
691
784
  return;
692
785
  }
693
786
  if (sub === "name") {
@@ -703,25 +796,25 @@ async function machines() {
703
796
  const response = await daemonRequest({ command: "machines.home" }, 20_000);
704
797
  if (!response.ok) throw new Error(response.error || "not moved");
705
798
  console.log(
706
- "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."
799
+ "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."
707
800
  );
708
801
  return;
709
802
  }
710
803
  if (sub)
711
804
  throw new Error(
712
- "usage: tryharness machines [confirm <code> | name <name> | home]"
805
+ "usage: tryharness machines [add <code> | name <name> | home]"
713
806
  );
714
807
  const response = await daemonRequest({ command: "machines.list" });
715
808
  if (!response.ok)
716
809
  throw new Error(response.error || "the daemon could not list computers");
717
810
  const { self, joinCode } = response;
718
811
  console.log(
719
- `This computer: ${self.label} (${self.role === "worker" ? "worker" : "home, holds the board"})${self.fingerprint ? `, key ${self.fingerprint}` : ""}`
812
+ `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}` : ""}`
720
813
  );
721
814
  if (joinCode) {
722
815
  const home = response.machines.find((machine) => machine.role === "home");
723
816
  console.log(
724
- `Join code: ${joinCode}\nOn your home computer${home?.label ? ` (${home.label})` : ""}, run: npx tryharness machines confirm ${joinCode}`
817
+ `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}. What this computer does meanwhile goes there when it joins.`
725
818
  );
726
819
  }
727
820
  if (!response.machines.length) {
@@ -732,7 +825,7 @@ async function machines() {
732
825
  }
733
826
  for (const machine of response.machines)
734
827
  console.log(
735
- `${String(machine.label || machine.id).padEnd(20)} ${machine.role.padEnd(7)} ${(machine.connected ? "online" : "offline").padEnd(8)} ${machine.confirmed ? "confirmed" : "waiting to join"}${machine.fingerprint ? ` key ${machine.fingerprint}` : ""}${machine.agents?.length ? ` ${machine.agents.join(", ")}` : ""}`
828
+ `${String(machine.label || machine.id).padEnd(20)} ${(machine.standsInForThis ? "home (standing in for this computer)" : machine.role).padEnd(7)} ${(machine.connected ? "online" : "offline").padEnd(8)} ${machine.confirmed ? "confirmed" : "waiting to join"}${machine.connected && machine.confirmed ? (machine.direct ? " reached directly" : " reached through Harness") : ""}${machine.fingerprint ? ` key ${machine.fingerprint}` : ""}${machine.agents?.length ? ` ${machine.agents.join(", ")}` : ""}`
736
829
  );
737
830
  }
738
831
 
@@ -1664,23 +1757,94 @@ function logs() {
1664
1757
  );
1665
1758
  }
1666
1759
 
1667
- async function disconnect() {
1760
+ // A cloud computer's daemon (docs/cloud-swarm.md §5.3), run by the harness-cloud service as the harness user once
1761
+ // cloud-enroll has written its config: the agents the boot script installed are connected to the swarm the first
1762
+ // time, as setup connects them, and then the daemon runs from the installed package itself.
1763
+ async function cloudStart() {
1764
+ const config = readJson(paths.config, {});
1765
+ if (!config.cloud || !config.token)
1766
+ throw new Error("this is not an enrolled cloud computer");
1767
+ if (!config.agentStates) {
1768
+ const states = configureAgents({ runtimeRoot: SOURCE_ROOT });
1769
+ writeJsonAtomic(paths.config, {
1770
+ ...readJson(paths.config, config),
1771
+ version: VERSION,
1772
+ runtimeRoot: SOURCE_ROOT,
1773
+ agentStates: Object.fromEntries(
1774
+ states.map((state) => [state.agent, state])
1775
+ ),
1776
+ });
1777
+ }
1778
+ const { startDaemon } = await import("./lib/daemon.mjs");
1779
+ await startDaemon();
1780
+ }
1781
+
1782
+ // What setup downloaded into ~/.harness (the daemon's runtime, local models and their engine): uninstall takes it out
1783
+ // and keeps what is the person's, their board, history and keys, unless they ask for everything.
1784
+ const downloadedParts = () => [
1785
+ paths.runtime,
1786
+ paths.models,
1787
+ path.join(paths.home, "local"),
1788
+ ];
1789
+
1790
+ function folderBytes(target) {
1791
+ let stat;
1792
+ try {
1793
+ stat = fs.lstatSync(target);
1794
+ } catch {
1795
+ return 0;
1796
+ }
1797
+ if (!stat.isDirectory()) return stat.size;
1798
+ return fs
1799
+ .readdirSync(target)
1800
+ .reduce((total, name) => total + folderBytes(path.join(target, name)), 0);
1801
+ }
1802
+
1803
+ const megabytes = (bytes) => `${Math.max(1, Math.round(bytes / 1_000_000))} MB`;
1804
+
1805
+ async function uninstall() {
1806
+ const everything = has("--everything");
1807
+ // Harness first, while the daemon is still connected: this computer comes off the account and its pairing stops
1808
+ // working, so a computer set up later is not taken for a worker of this one.
1809
+ const left = await daemonRequest({ command: "machines.leave" }, 15_000).catch(
1810
+ () => null
1811
+ );
1668
1812
  uninstallService();
1669
- retireDesktop({});
1670
1813
  try {
1671
1814
  await daemonRequest({ command: "shutdown" }, 2_000);
1672
1815
  } catch {}
1816
+ removeNativeHost();
1817
+ uninstallDesktop();
1673
1818
  removeAgentConfigurations();
1674
1819
  removeLocalWakes();
1675
- try {
1676
- fs.renameSync(paths.config, paths.config + `.disconnected-${Date.now()}`);
1677
- } catch {}
1678
- for (const target of [paths.status, paths.socket])
1820
+ const removed = everything
1821
+ ? [paths.home]
1822
+ : [...downloadedParts(), paths.status, paths.socket];
1823
+ for (const target of removed)
1679
1824
  try {
1680
- fs.unlinkSync(target);
1825
+ fs.rmSync(target, { recursive: true, force: true });
1681
1826
  } catch {}
1827
+ // The pairing goes; the person's choices stay (who is in their swarm, who they took out), so setting up again
1828
+ // keeps their swarm (October 23: a reinstall came back without Bankr, Quotient, Grok Bot and Muse).
1829
+ if (!everything) {
1830
+ const { token: _token, ...choices } = readJson(paths.config, {});
1831
+ if (Object.keys(choices).length) writeJsonAtomic(paths.config, choices);
1832
+ }
1833
+ if (!left?.ok)
1834
+ console.log(
1835
+ "Harness could not be told this computer is gone (it was not connected). Setting Harness up again on it still makes it home."
1836
+ );
1837
+ if (everything) {
1838
+ console.log(
1839
+ "Harness is uninstalled, and everything it kept on this computer is deleted."
1840
+ );
1841
+ return;
1842
+ }
1843
+ const shown = paths.home.replace(os.homedir(), "~");
1682
1844
  console.log(
1683
- "Harness disconnected. The local history database was preserved."
1845
+ `Harness is uninstalled: the app, its background service and its setup in your agents are gone.\n` +
1846
+ `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` +
1847
+ `To delete them too: npx tryharness uninstall --everything`
1684
1848
  );
1685
1849
  }
1686
1850
 
@@ -1710,17 +1874,22 @@ async function lessons() {
1710
1874
  return;
1711
1875
  }
1712
1876
  const replaced = has("--replaced");
1877
+ // Lessons the dream read as instructions for one job (swarmMemory.mjs).
1878
+ const retired = has("--retired");
1713
1879
  const response = await daemonRequest({
1714
1880
  command: "board.swarm.lessons",
1715
1881
  agent: "user",
1716
1882
  replaced,
1883
+ retired,
1717
1884
  });
1718
1885
  if (!response.ok) throw new Error(response.error);
1719
1886
  if (!response.lessons.length) {
1720
1887
  console.log(
1721
- replaced
1722
- ? "No lesson has been replaced yet."
1723
- : "Your swarm has learned nothing from you yet. It learns from what you write in its threads."
1888
+ retired
1889
+ ? "No lesson has been retired."
1890
+ : replaced
1891
+ ? "No lesson has been replaced yet."
1892
+ : "Your swarm has learned nothing from you yet. It learns from what you write in its threads."
1724
1893
  );
1725
1894
  return;
1726
1895
  }
@@ -1731,9 +1900,11 @@ async function lessons() {
1731
1900
  ? "about the work"
1732
1901
  : "about you";
1733
1902
  console.log(
1734
- replaced
1735
- ? `Replaced by a later lesson (${response.lessons.length}):`
1736
- : `What your swarm has learned from you (${response.lessons.length}):`
1903
+ retired
1904
+ ? `Retired as instructions for one job (${response.lessons.length}); the dream read them after the work:`
1905
+ : replaced
1906
+ ? `Replaced by a later lesson (${response.lessons.length}):`
1907
+ : `What your swarm has learned from you (${response.lessons.length}):`
1737
1908
  );
1738
1909
  for (const lesson of response.lessons) {
1739
1910
  const where =
@@ -1754,9 +1925,101 @@ async function lessons() {
1754
1925
  );
1755
1926
  }
1756
1927
 
1928
+ // The swarm's long-running memory (cli/lib/swarmMemory.mjs): what the dream keeps from the work, what was forgotten or
1929
+ // replaced, and the last dream; forget or delete something, bring it back, or dream now.
1930
+ async function memoryCommand() {
1931
+ const [sub, id] = argv;
1932
+ const ask = async (payload) => {
1933
+ const response = await daemonRequest({ agent: "user", ...payload });
1934
+ if (!response.ok) throw new Error(response.error || response.why);
1935
+ return response;
1936
+ };
1937
+ if (sub === "forget" || sub === "delete") {
1938
+ if (!id)
1939
+ throw new Error(
1940
+ "usage: tryharness memory forget <id> | memory delete <post id>"
1941
+ );
1942
+ const { forgotten } = await ask({
1943
+ command: "board.swarm.forget",
1944
+ ids: [id],
1945
+ mode: sub === "delete" ? "purge" : "release",
1946
+ });
1947
+ console.log(
1948
+ sub === "delete"
1949
+ ? "Deleted for good: its words are gone from every search, brief and computer."
1950
+ : `Forgotten (${forgotten.map((item) => item.what).join(", ")}): no search or brief brings it back. tryharness memory back ${id} undoes it.`
1951
+ );
1952
+ return;
1953
+ }
1954
+ if (sub === "back") {
1955
+ if (!id) throw new Error("usage: tryharness memory back <post id>");
1956
+ await ask({ command: "board.swarm.unforget", id });
1957
+ console.log("Back in what your agents can find.");
1958
+ return;
1959
+ }
1960
+ if (sub === "dream") {
1961
+ const report = await ask({ command: "board.swarm.dream" });
1962
+ console.log(
1963
+ `Read ${report.read} new fact${report.read === 1 ? "" : "s"}: kept ${report.kept.length}, changed ${report.changed.length}, retired ${report.retired.length} one-job lesson${report.retired.length === 1 ? "" : "s"}, widened ${report.widened.length}.${report.more ? " More is waiting; the next dream reads on." : ""}`
1964
+ );
1965
+ return;
1966
+ }
1967
+ const response = await ask({ command: "board.swarm.memory" });
1968
+ if (!response.observations.length)
1969
+ console.log(
1970
+ "Your swarm keeps nothing from its work yet. It dreams overnight on the charger, or now with tryharness memory dream."
1971
+ );
1972
+ else {
1973
+ console.log(
1974
+ `What your swarm keeps from its work (${response.observations.length}):`
1975
+ );
1976
+ for (const item of response.observations) {
1977
+ const where = item.folder ? `in ${item.folder}` : "everywhere";
1978
+ console.log(
1979
+ ` ${item.id.slice(0, 8)} ${item.kind}${item.agent ? ` about ${item.agent}` : ""}, ${where}, borne out ${item.proof} time${item.proof === 1 ? "" : "s"}: ${item.text}`
1980
+ );
1981
+ if (item.quote) console.log(` from "${item.quote}"`);
1982
+ }
1983
+ }
1984
+ const forgotten = response.forgotten.filter(
1985
+ (mark) => mark.state !== "purged"
1986
+ );
1987
+ if (forgotten.length)
1988
+ console.log(
1989
+ `\n${forgotten.length} post${forgotten.length === 1 ? " is" : "s are"} out of what agents find (forgotten or replaced by a later post); tryharness memory back <id> brings one back.`
1990
+ );
1991
+ if (response.dream?.at)
1992
+ console.log(
1993
+ `\nLast dream ${response.dream.at.slice(0, 16).replace("T", " ")}: read ${response.dream.read}, kept ${response.dream.kept.length}, changed ${response.dream.changed.length}, retired ${response.dream.retired.length}, widened ${response.dream.widened.length}.`
1994
+ );
1995
+ console.log(
1996
+ "\nForget one: tryharness memory forget <id>. Delete a post's words for good: tryharness memory delete <post id>. Dream now: tryharness memory dream."
1997
+ );
1998
+ }
1999
+
1757
2000
  async function agents() {
1758
2001
  const config = readJson(paths.config, {});
1759
2002
  const [sub, agent] = argv;
2003
+ // Who is in the swarm, and putting agents in or taking them out (lineup.mjs).
2004
+ if (!sub) {
2005
+ await showLineup({ daemonRequest });
2006
+ return;
2007
+ }
2008
+ if (sub === "add") {
2009
+ const ui = createUi();
2010
+ ui.intro(
2011
+ `${pc.bgCyan(pc.black(" tryharness "))} Add agents to your swarm`
2012
+ );
2013
+ const ok = await addAgents({ daemonRequest, wanted: argv.slice(1), ui });
2014
+ ui.outro(ok ? "Done." : "Not everything was added.");
2015
+ process.exitCode = ok ? 0 : 1;
2016
+ return;
2017
+ }
2018
+ if (sub === "remove") {
2019
+ if (!agent) throw new Error("usage: tryharness agents remove <agent>");
2020
+ process.exitCode = (await removeAgent({ daemonRequest, agent })) ? 0 : 1;
2021
+ return;
2022
+ }
1760
2023
  if (sub === "test" && agent) {
1761
2024
  process.exitCode = (await testAgent({ agent, daemonRequest })) ? 0 : 1;
1762
2025
  return;
@@ -1895,6 +2158,8 @@ async function agents() {
1895
2158
  ui,
1896
2159
  only,
1897
2160
  });
2161
+ // An agent set up by name is in the swarm from now on (lineup.mjs); the daemon reads the change by itself.
2162
+ if (only) createLineup().add(only);
1898
2163
  ui.outro("Done.");
1899
2164
  }
1900
2165
 
@@ -2014,7 +2279,8 @@ async function browserLink() {
2014
2279
  throw new Error(response.error || "the daemon could not make a link");
2015
2280
  return {
2016
2281
  url: response.url,
2017
- opened: !has("--print") && openUrl(response.url),
2282
+ // openUrl cannot tell whether a browser opened (a missing xdg-open fails later), so a computer with none prints it.
2283
+ opened: !has("--print") && canOpenBrowser() && openUrl(response.url),
2018
2284
  };
2019
2285
  }
2020
2286
  async function link() {
@@ -2022,7 +2288,7 @@ async function link() {
2022
2288
  console.log(
2023
2289
  opened
2024
2290
  ? "Opened Harness in your browser to connect it to this computer end to end. The link works once, for 10 minutes."
2025
- : `Open this in the browser you use Harness in. It works once, for 10 minutes, and is the pairing secret:\n\n${url}`
2291
+ : `To talk to this computer's agents from your browser, open this link in it. It works once, for 10 minutes; keep it to yourself:\n\n${url}`
2026
2292
  );
2027
2293
  console.log(
2028
2294
  "Harness then carries what your browser and this computer say to each other sealed, and cannot read it."
@@ -2084,12 +2350,22 @@ async function t3() {
2084
2350
 
2085
2351
  function help() {
2086
2352
  console.log(
2087
- `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 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 confirm <code> | name <name> | home\n tryharness agents how Harness wakes each of your agents, and set up the rest\n tryharness agents setup <agent> | agents test <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] | lessons remove <id> | lessons edit <id> "<text>"\n what your swarm learned from your words, to read, change or take out\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 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`
2353
+ `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 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 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`
2088
2354
  );
2089
2355
  }
2090
2356
 
2091
2357
  try {
2092
- if (
2358
+ // Started by Chrome for the Harness extension (nativeHost.mjs); its stdout carries only the framed answers.
2359
+ if (command === "native-host") {
2360
+ const { serveNativeHost } = await import("./lib/nativeHost.mjs");
2361
+ await serveNativeHost({
2362
+ input: process.stdin,
2363
+ output: process.stdout,
2364
+ daemon: (request, timeoutMs) => daemonRequest(request, timeoutMs),
2365
+ });
2366
+ // Chrome closed the port: a listening host would otherwise keep waiting on the daemon.
2367
+ process.exit(0);
2368
+ } else if (
2093
2369
  command === "setup" ||
2094
2370
  (command === "connect" && (!argv[0] || argv[0].startsWith("-")))
2095
2371
  )
@@ -2106,25 +2382,50 @@ try {
2106
2382
  else if (command === "room") await room();
2107
2383
  else if (command === "swarm") await swarm();
2108
2384
  else if (command === "mcp") await mcpSnippet();
2109
- else if (command === "notify") await notify();
2385
+ else if (command === "connections" && ["on", "off"].includes(argv[0])) {
2386
+ // Apps (connected outside accounts) are off until the person turns them on; agents see the connection tool in
2387
+ // the sessions they start after that (mcp-stdio.mjs).
2388
+ const on = argv[0] === "on";
2389
+ writeJsonAtomic(paths.config, {
2390
+ ...readJson(paths.config, {}),
2391
+ connectedApps: on,
2392
+ });
2393
+ console.log(
2394
+ on
2395
+ ? "Apps are on. Connect one with npx tryharness connections add; agents see them in sessions they start from now on."
2396
+ : "Apps are off. No agent can use a connected app until you turn them on again."
2397
+ );
2398
+ } else if (command === "connections") {
2399
+ const { connectorCommands } = await import("./lib/connectorCommands.mjs");
2400
+ await connectorCommands(argv);
2401
+ } else if (command === "vault") {
2402
+ const { vaultCommands } = await import("./lib/vaultCommands.mjs");
2403
+ await vaultCommands(argv);
2404
+ } else if (command === "notify") await notify();
2405
+ else if (command === "usage-totals") await usageTotals();
2110
2406
  else if (command === "phone") await phone();
2111
2407
  else if (command === "agents") await agents();
2112
2408
  else if (command === "lessons") await lessons();
2409
+ else if (command === "memory") await memoryCommand();
2113
2410
  else if (command === "link") await link();
2114
2411
  else if (command === "t3") await t3();
2115
2412
  else if (command === "peers") await peers();
2116
2413
  else if (command === "machines") await machines();
2414
+ else if (command === "backup")
2415
+ await backupCommand({ argv, ui: createUi(), daemonRequest });
2117
2416
  else if (command === "connect") await connectAgent();
2118
2417
  else if (command === "desktop") {
2119
2418
  const shown = await desktop();
2120
2419
  console.log(shown.text);
2121
2420
  if (!shown.ok) process.exitCode = 1;
2122
2421
  } else if (command === "logs") logs();
2123
- else if (command === "disconnect") await disconnect();
2422
+ else if (command === "uninstall") await uninstall();
2124
2423
  else if (command === "daemon") {
2125
2424
  const { startDaemon } = await import("./lib/daemon.mjs");
2126
2425
  await startDaemon();
2127
- } else if (command === "version") console.log(VERSION);
2426
+ } else if (command === "cloud-enroll") await cloudEnroll();
2427
+ else if (command === "cloud-start") await cloudStart();
2428
+ else if (command === "version") console.log(VERSION);
2128
2429
  else if (["help", "--help", "-h"].includes(command)) help();
2129
2430
  else throw new Error(`unknown command '${command}' (run: tryharness help)`);
2130
2431
  } catch (error) {