tryharness 0.7.81 → 0.7.83

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 (48) hide show
  1. package/README.md +4 -3
  2. package/assets/install.sh +104 -0
  3. package/cli.mjs +203 -321
  4. package/lib/adapters.mjs +7 -6
  5. package/lib/agentRuntimes.mjs +2 -1
  6. package/lib/backupSetup.mjs +0 -52
  7. package/lib/boardProtocol.json +19 -1
  8. package/lib/browserPage.mjs +30 -0
  9. package/lib/cards.mjs +5 -2
  10. package/lib/daemon.mjs +103 -5
  11. package/lib/desktop.mjs +7 -1
  12. package/lib/dispatcher.mjs +12 -2
  13. package/lib/environments.mjs +4 -11
  14. package/lib/goalCommands.mjs +2 -1
  15. package/lib/hookDialects.mjs +2 -1
  16. package/lib/jobAnswers.mjs +2 -1
  17. package/lib/localStack.mjs +24 -9
  18. package/lib/mcp-stdio.mjs +6 -0
  19. package/lib/members.json +1 -1
  20. package/lib/museSession.mjs +2 -1
  21. package/lib/nativeHost.mjs +11 -2
  22. package/lib/network.mjs +1 -0
  23. package/lib/notify.mjs +48 -16
  24. package/lib/onboard.mjs +71 -366
  25. package/lib/ownMachines.mjs +4 -1
  26. package/lib/pairing.mjs +0 -84
  27. package/lib/paths.mjs +17 -0
  28. package/lib/personNotices.mjs +9 -25
  29. package/lib/profile.mjs +0 -109
  30. package/lib/projects.mjs +18 -4
  31. package/lib/removeHarness.mjs +91 -0
  32. package/lib/roomChannels.mjs +2 -0
  33. package/lib/runner.mjs +3 -3
  34. package/lib/runtime-install.mjs +22 -2
  35. package/lib/screen.mjs +133 -0
  36. package/lib/selfUpdate.mjs +6 -6
  37. package/lib/service.mjs +120 -7
  38. package/lib/sessionControl.mjs +10 -0
  39. package/lib/setupChoices.mjs +400 -0
  40. package/lib/setupMode.mjs +137 -0
  41. package/lib/t3.mjs +23 -14
  42. package/lib/threadActions.mjs +2 -1
  43. package/lib/toolCheck.mjs +136 -0
  44. package/lib/ui.mjs +15 -1
  45. package/lib/wakes.mjs +3 -3
  46. package/npm-shrinkwrap.json +14 -14
  47. package/package.json +4 -4
  48. package/release.json +49 -42
package/cli.mjs CHANGED
@@ -5,35 +5,21 @@ import fs from "node:fs";
5
5
  import os from "node:os";
6
6
  import path from "node:path";
7
7
  import { fileURLToPath } from "node:url";
8
- import {
9
- configureAgents,
10
- AGENTS,
11
- MCP_CLIENTS,
12
- detectMcpClients,
13
- mcpClientSnippet,
14
- removeAgentConfigurations,
15
- } from "./lib/adapters.mjs";
8
+ import { configureAgents, AGENTS } from "./lib/adapters.mjs";
16
9
  import {
17
10
  addAgents,
18
11
  banner,
19
- checkAgents,
20
12
  removeAgent,
21
13
  showLineup,
22
- setupChosen,
23
- setupElsewhere,
24
- setupT3,
25
14
  setupSwarm,
26
15
  testAgent,
27
- walkThrough,
28
16
  } from "./lib/onboard.mjs";
29
- import { agentsHere, createLineup, lineupOf } from "./lib/lineup.mjs";
17
+ import { agentsHere, createLineup } from "./lib/lineup.mjs";
30
18
  import { confirmAgentBinary } from "./lib/agentBinaries.mjs";
31
- import { CHECKABLE, createAgentReadiness } from "./lib/readiness.mjs";
32
- import { writeBrowserOffer } from "./lib/phones.mjs";
33
- import { createUi } from "./lib/ui.mjs";
34
- import { backupCommand, offerBackup } from "./lib/backupSetup.mjs";
19
+ import { createUi, stopSpinner } from "./lib/ui.mjs";
20
+ import { backupCommand } from "./lib/backupSetup.mjs";
35
21
  import pc from "picocolors";
36
- import { removeLocalWakes } from "./lib/wakes.mjs";
22
+ import { chosenAgents, removeHarnessHere } from "./lib/removeHarness.mjs";
37
23
  import { detectAgents } from "./lib/commands.mjs";
38
24
  import { PROPOSERS, nameOf } from "./lib/members.mjs";
39
25
  import { describeDispatcher } from "./lib/dispatcher.mjs";
@@ -41,15 +27,8 @@ import { daemonRequest } from "./lib/control-client.mjs";
41
27
  import { ensureDir, readJson, writeJsonAtomic } from "./lib/files.mjs";
42
28
  import { hostApp, processTable } from "./lib/live.mjs";
43
29
  import { noteSetupTerminal } from "./lib/places.mjs";
44
- import { paths } from "./lib/paths.mjs";
45
- import {
46
- joinSwarm,
47
- keepJoinCode,
48
- setupPageUrl,
49
- startPairing,
50
- waitForApproval,
51
- } from "./lib/pairing.mjs";
52
- import { setupProfile } from "./lib/profile.mjs";
30
+ import { readScreenFacts, whereSetupShows } from "./lib/screen.mjs";
31
+ import { harnessNode, paths } from "./lib/paths.mjs";
53
32
  import { cloudEnroll } from "./lib/cloudBoot.mjs";
54
33
  import { ownPublicKey, sshCommand } from "./lib/cloudSsh.mjs";
55
34
  import {
@@ -58,20 +37,21 @@ import {
58
37
  fetchRelease,
59
38
  installRuntime,
60
39
  relayCommand,
40
+ updateHarnessNode,
61
41
  } from "./lib/runtime-install.mjs";
62
- import { installNativeHost, removeNativeHost } from "./lib/nativeHost.mjs";
63
- import { CORE, coreSizeMb } from "./lib/coreModels.mjs";
42
+ import { installNativeHost } from "./lib/nativeHost.mjs";
64
43
  import { MODELS, modelsPresent } from "./lib/localmodels.mjs";
65
44
  import {
66
45
  installService,
67
46
  launcherMissing,
68
47
  serviceInfo,
48
+ serviceRunning,
69
49
  uninstallService,
70
50
  } from "./lib/service.mjs";
71
51
  import {
72
52
  canShowDesktop,
53
+ desktopInstalled,
73
54
  openDesktop,
74
- uninstallDesktop,
75
55
  setupDesktop,
76
56
  } from "./lib/desktop.mjs";
77
57
 
@@ -134,49 +114,6 @@ const canOpenBrowser = () =>
134
114
  (process.platform !== "linux" ||
135
115
  Boolean(process.env.DISPLAY || process.env.WAYLAND_DISPLAY));
136
116
 
137
- // One page in the browser approves this computer and links that browser to it in the same click: the address fragment,
138
- // which no server sees, carries the approval (never the code, which is also the join secret) and a browser link setup
139
- // made for the daemon (phones.mjs, pairing.mjs setupPageUrl).
140
- async function pair(pairOrigin, agents, ui) {
141
- const { pairId, code, own } = await startPairing(pairOrigin, agents);
142
- if (own) keepJoinCode(paths.machine, code);
143
- const browser = own && canOpenBrowser();
144
- const link = browser
145
- ? await writeBrowserOffer({
146
- identityFile: paths.phoneIdentity,
147
- offerFile: paths.browserOffer,
148
- })
149
- : null;
150
- const opened =
151
- browser && openUrl(await setupPageUrl(pairOrigin, { code, own }, link));
152
- // With no browser here, the person opens the approval link on another computer: setup's code itself is typed only
153
- // into Harness on one of their own computers, never into a web page.
154
- const approve = opened
155
- ? "Your browser just opened. Sign in with your email if it asks, then press Connect. No account yet? Signing in makes one."
156
- : own
157
- ? `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 })}`
158
- : `Open ${pairOrigin}/pair in a browser, sign in with your email, and enter this code. No account yet? Signing in makes one.`;
159
- const elsewhere = own
160
- ? "\nAlready use Harness on another computer? Click the Harness icon in its menu bar, choose Add a Computer, and type this code there instead."
161
- : "";
162
- ui.note(
163
- `${pc.bold(code)}\n\n${pc.dim(approve + elsewhere)}`,
164
- "Sign in to Harness"
165
- );
166
- const spin = ui.spinner();
167
- spin.start(
168
- "Waiting for you to press Connect (the code works for 10 minutes)"
169
- );
170
- try {
171
- const token = await waitForApproval(pairOrigin, pairId);
172
- spin.stop("Connected to your Harness account");
173
- return { token, code: own ? code : null, linkOffered: Boolean(link) };
174
- } catch (error) {
175
- spin.stop("Pairing did not finish", 2);
176
- throw error;
177
- }
178
- }
179
-
180
117
  async function waitForDaemon(timeoutMs = 12_000) {
181
118
  const deadline = Date.now() + timeoutMs;
182
119
  let lastError;
@@ -197,37 +134,89 @@ async function waitForDaemon(timeoutMs = 12_000) {
197
134
  );
198
135
  }
199
136
 
137
+ // While this computer is not signed in, its daemon holds a sign-in open (setupMode.mjs): wait for it to answer with
138
+ // the code and link, or for it to be signed in already (another computer took the code first).
139
+ async function setupState(timeoutMs = 12_000) {
140
+ const deadline = Date.now() + timeoutMs;
141
+ let last;
142
+ while (Date.now() < deadline) {
143
+ try {
144
+ const state = await daemonRequest({ command: "setup.state" }, 1_000);
145
+ if (state.ok && (state.code || state.url)) return state;
146
+ if (state.code === "unknown command" || state.error === "unknown command")
147
+ return null;
148
+ last = state.error;
149
+ } catch (error) {
150
+ last = error.message;
151
+ }
152
+ await new Promise((resolve) => setTimeout(resolve, 250));
153
+ }
154
+ throw new Error(
155
+ `Harness started but could not hold a sign-in: ${last || "no answer"}. Run: ${relayCommand()} doctor`
156
+ );
157
+ }
158
+
159
+ // Signed in on the screen or with the code on another computer, whichever came first; or setup stopped from the
160
+ // Harness app (Remove Harness), which takes the background service with it.
161
+ async function untilSignedIn() {
162
+ for (;;) {
163
+ const status = await daemonRequest({ command: "status" }, 1_000).catch(
164
+ () => null
165
+ );
166
+ if (status && !status.setup) return "signed in";
167
+ if (!status && !serviceRunning()) return "stopped";
168
+ await new Promise((resolve) => setTimeout(resolve, 1_000));
169
+ }
170
+ }
171
+
172
+ // Backing out before signing in (Ctrl-C) takes back everything setup added, so nothing is left running. Ctrl-C comes as
173
+ // a signal, or, while clack's spinner holds the terminal, as a key clack answers by exiting with code 0 (seen
174
+ // November 3: the spinner said "Canceled" and the app stayed): both end here. A failed setup exits with an error code
175
+ // and keeps what it made, for doctor to look at.
176
+ function stopSetupOnCtrlC() {
177
+ let stopped = false;
178
+ const takeBack = () => {
179
+ if (stopped) return;
180
+ stopped = true;
181
+ const { folderRemoved } = removeHarnessHere({
182
+ paths,
183
+ agents: chosenAgents(paths),
184
+ stopService: true,
185
+ });
186
+ const line = stoppedLine(folderRemoved);
187
+ if (!stopSpinner(line)) console.log(`\n${line}`);
188
+ };
189
+ const onSignal = () => {
190
+ takeBack();
191
+ process.exit(130);
192
+ };
193
+ const onExit = (code) => {
194
+ if (code === 0 && !process.exitCode) takeBack();
195
+ };
196
+ process.on("SIGINT", onSignal);
197
+ process.on("exit", onExit);
198
+ return () => {
199
+ process.removeListener("SIGINT", onSignal);
200
+ process.removeListener("exit", onExit);
201
+ };
202
+ }
203
+
204
+ const stoppedLine = (folderRemoved) =>
205
+ folderRemoved
206
+ ? "Setup stopped. Nothing from Harness is left on this computer."
207
+ : `Setup stopped. Harness is off this computer; your board and history from before are kept in ${paths.home.replace(os.homedir(), "~")}.`;
208
+
200
209
  async function connect() {
201
210
  ensureDir(paths.home);
202
- // A release this computer's Harness would refuse is refused before pairing or anything else changes.
211
+ // A release this computer's Harness would refuse is refused before anything else changes.
203
212
  checkRuntime({
204
213
  sourceRoot: SOURCE_ROOT,
205
214
  version: VERSION,
206
215
  allowUnsigned: has("--local-build"),
207
216
  });
208
- // The agents installed here (lineup.mjs). Each coding agent gets its one-line prompt now (readiness.mjs), so the
209
- // answers come in while the person signs in.
210
- const here = agentsHere();
211
- const requested = argv.flatMap((value, index) =>
212
- value === "--agent" && argv[index + 1] ? [argv[index + 1]] : []
213
- );
214
- for (const agent of requested)
215
- if (![...AGENTS, "openclaw", "hermes"].includes(agent))
216
- throw new Error(`unknown agent '${agent}'`);
217
- const removed = readJson(paths.config, {}).swarmRemoved ?? [];
218
- const readiness = createAgentReadiness();
219
- const checks = new Map(
220
- here
221
- .filter(
222
- (entry) =>
223
- CHECKABLE.includes(entry.id) &&
224
- (requested.length
225
- ? requested.includes(entry.id)
226
- : !removed.includes(entry.id))
227
- )
228
- .map((entry) => [entry.id, readiness.check(entry.id)])
229
- );
230
- const found = here
217
+ // Setup asks nothing here: signing in, agents, folders and where threads open are chosen on this computer's screen
218
+ // in the Harness app, or from another computer's when this one has none (screen.mjs).
219
+ const found = agentsHere()
231
220
  .filter((entry) => AGENTS.includes(entry.id))
232
221
  .map((entry) => entry.id);
233
222
  const ui = createUi();
@@ -245,49 +234,24 @@ async function connect() {
245
234
  const pairOrigin = origin();
246
235
  let config = readJson(paths.config, {});
247
236
  const connection =
248
- !has("--reconnect") && config.origin === pairOrigin
237
+ !has("--reconnect") && config.origin === pairOrigin && config.token
249
238
  ? await checkConnection(config, { version: VERSION })
250
239
  : "rejected";
251
- const reusable = connection !== "rejected";
252
- if (connection === "ok")
253
- ui.success(
254
- `Connected to Harness ${pc.dim(`· ${new URL(pairOrigin).host}`)}`
255
- );
256
- else if (connection === "unreachable")
240
+ if (connection === "unreachable")
257
241
  ui.warn(
258
242
  `Harness did not answer just now, so this computer keeps its connection ${pc.dim(`· ${new URL(pairOrigin).host}`)}. If it really stopped working: ${relayCommand()} --reconnect`
259
243
  );
260
- let setupCode = null;
261
- let linkOffered = false;
262
- if (!reusable) {
263
- const paired = await pair(pairOrigin, found, ui);
264
- setupCode = paired.code;
265
- linkOffered = paired.linkOffered;
266
- config = { ...config, origin: pairOrigin, token: paired.token };
244
+ const signedIn = connection !== "rejected";
245
+ // Not signed in: the daemon starts without a token and holds a sign-in open for the screen or the code.
246
+ const endCtrlCStop = signedIn ? () => {} : stopSetupOnCtrlC();
247
+ if (!signedIn) {
248
+ const { token: _dropped, ...rest } = config;
249
+ config = { ...rest, origin: pairOrigin };
267
250
  writeJsonAtomic(paths.config, config);
268
251
  }
269
252
 
270
- // The order is the person's: Harness starts with the agents that answered, so the browser they pressed Connect in
271
- // links and lists them at once, and only then are they walked through the rest, which join as each answers.
272
- const before = readJson(paths.config, {});
273
- const previous = lineupOf(before);
274
- const { ready, waiting } = await checkAgents({
275
- ui,
276
- here,
277
- checks,
278
- readiness,
279
- requested,
280
- removed,
281
- });
282
- // Agents that live elsewhere stay as they were: in a swarm from before the lineup, all of them (they were in it).
283
- const kept = previous
284
- ? previous.filter((agent) => !here.some((entry) => entry.id === agent))
285
- : before.agentStates
286
- ? ["grok-bot", "bankr", "quotient", "muse"]
287
- : [];
288
-
289
- // The persistent runtime is version-pinned; neither MCP clients nor the login service
290
- // point into npm's temporary npx cache.
253
+ // The persistent runtime is version-pinned, so the agents the person already chose are pointed at this release; a
254
+ // first setup has none, and the person turns each one on in the Harness app (the daemon's swarm.add).
291
255
  const spin = ui.spinner();
292
256
  spin.start("Starting Harness on this computer");
293
257
  const runtimeRoot = installRuntime({
@@ -295,31 +259,28 @@ async function connect() {
295
259
  version: VERSION,
296
260
  allowUnsigned: has("--local-build"),
297
261
  });
298
- const selected = ready.filter((agent) => AGENTS.includes(agent));
299
- const states = configureAgents({ runtimeRoot, selected });
300
- // The program each agent runs as, as this terminal finds it: the daemon starts that one and no other
301
- // (agentBinaries.mjs).
302
- const moved = selected.flatMap((agent) => {
303
- const confirmed = confirmAgentBinary(agent);
304
- return confirmed?.previous
305
- ? [
306
- `${agent} now runs from ${confirmed.path} (it ran from ${confirmed.previous})`,
307
- ]
308
- : [];
309
- });
310
- const stateMap = Object.fromEntries(
311
- states.map((state) => [state.agent, state])
262
+ const chosen = (config.swarmAgents ?? []).filter(
263
+ (agent) => AGENTS.includes(agent) && found.includes(agent)
312
264
  );
265
+ const states = configureAgents({ runtimeRoot, selected: chosen });
266
+ for (const agent of chosen) confirmAgentBinary(agent);
313
267
  config = {
314
268
  ...readJson(paths.config, config),
315
269
  version: VERSION,
316
270
  runtimeRoot,
317
- agentStates: stateMap,
318
- swarmAgents: [...new Set([...ready, ...kept])],
319
- // The daemon downloads the relay's core local models in the background (coreModels.mjs).
320
- localModels: "download",
271
+ agentStates: {
272
+ ...config.agentStates,
273
+ ...Object.fromEntries(states.map((state) => [state.agent, state])),
274
+ },
275
+ swarmAgents: config.swarmAgents ?? [],
321
276
  };
322
277
  writeJsonAtomic(paths.config, config);
278
+ // The app goes in before the background service, so the service starts through the app's launcher from the first:
279
+ // started by Node, macOS announced it as "Software from Node.js Foundation" (seen November 3).
280
+ const where = whereSetupShows(readScreenFacts({ table }));
281
+ const onScreen = where.show === "screen" && !has("--no-desktop");
282
+ if (!signedIn && onScreen)
283
+ await setupDesktop({ sourceRoot: SOURCE_ROOT }).catch(() => null);
323
284
  const service = installService({ runtimeRoot });
324
285
  // The Harness extension in this computer's browsers finds this daemon by itself, so its window links here.
325
286
  try {
@@ -329,136 +290,107 @@ async function connect() {
329
290
  `The extension cannot find this computer by itself (${error.message}); link the browser with ${relayCommand()} link`
330
291
  );
331
292
  }
332
- try {
333
- await waitForDaemon();
334
- } catch (error) {
335
- spin.stop("Harness did not connect", 2);
336
- throw error;
337
- }
338
- spin.stop(
339
- `Harness is running on this computer ${pc.dim(`· ${service.manager}`)}`
340
- );
341
- for (const line of moved) ui.info(line);
342
- // Harness already runs, so the browser lists the agents while the person tells them who they work for.
343
- await setupProfile({ ui, origin: pairOrigin, token: config.token });
344
- const joined = await walkThrough({
345
- ui,
346
- waiting,
347
- readiness,
348
- join: (agent) =>
349
- daemonRequest({ command: "swarm.add", target: agent }).catch((error) => ({
350
- ok: false,
351
- error: error.message,
352
- })),
353
- });
354
- const chosen = [...ready, ...joined];
355
- // An agent that joined during the walkthrough was connected by the daemon (lineup.mjs joinAgent), which saved its state.
356
- const saved = readJson(paths.config, {}).agentStates ?? {};
357
- await setupChosen({
358
- chosen,
359
- here,
360
- states: states.map((state) => saved[state.agent] ?? state),
361
- runtimeRoot,
362
- daemonRequest,
363
- ui,
364
- });
365
- await setupElsewhere({
366
- daemonRequest,
367
- ui,
368
- fresh: !previous && !before.agentStates,
369
- removed,
370
- });
371
- await setupT3({
372
- ui,
373
- daemonRequest,
374
- open: (url) => !has("--print") && canOpenBrowser() && openUrl(url),
375
- });
376
- if (!has("--no-desktop")) {
377
- const spin = ui.spinner();
378
- spin.start("Getting the Harness desktop app");
379
- const shown = await desktop();
380
- spin.stop(shown.text, shown.ok ? 0 : 2);
381
- // The app brings the daemon's launcher: the daemon starts through it from now on (service.mjs).
382
- if (launcherMissing()) {
383
- installService({ runtimeRoot });
384
- await waitForDaemon().catch(() => {});
385
- }
386
- }
293
+ // Only the agents the person chose are set up here; the rest wait for the Harness app, so they are not failures.
387
294
  const failed = states.filter(
388
295
  (state) =>
389
- selected.includes(state.agent) && state.installed && !state.configured
296
+ chosen.includes(state.agent) && state.installed && !state.configured
390
297
  );
391
298
  if (failed.length) {
299
+ spin.stop("Harness could not set up every agent", 2);
392
300
  throw new Error(
393
301
  `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.`
394
302
  );
395
303
  }
396
- // The browser you use Harness in on this computer links to this computer; on an added one it works the board home
397
- // keeps through it, and the agents here can ask it what is on this screen. The page that approved this computer links
398
- // its browser itself once Harness runs here (pair above), which has had the whole walkthrough to happen.
399
- try {
400
- const devices = await daemonRequest({ command: "phone.list" });
401
- const linked =
402
- devices.ok &&
403
- devices.phones.some(
404
- (device) => device.kind === "browser" && !device.revoked_at
405
- );
406
- if (linked) ui.success("Your browser is linked to this computer");
407
- else if (linkOffered)
408
- ui.success(
409
- "Your browser links to this computer from the page you pressed Connect on"
410
- );
411
- else if (devices.ok) {
412
- const offer = await browserLink();
413
- ui.info(
414
- offer.opened
415
- ? "Opened Harness in your browser to link it to this computer. The link works once, for 10 minutes."
416
- : `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}`
417
- );
304
+
305
+ if (signedIn) {
306
+ try {
307
+ await waitForDaemon();
308
+ } catch (error) {
309
+ spin.stop("Harness did not connect", 2);
310
+ throw error;
418
311
  }
419
- } catch (error) {
420
- ui.warn(
421
- `Browser not linked (${error.message}). Run: ${relayCommand()} link`
312
+ spin.stop(
313
+ `Harness is running on this computer ${pc.dim(`· ${service.manager}`)}`
422
314
  );
315
+ // An upgrade keeps an installed app on the same release.
316
+ if (!has("--no-desktop") && desktopInstalled())
317
+ await showApp(ui, runtimeRoot);
318
+ ui.outro("Done.");
319
+ return;
423
320
  }
424
- // Last, so nothing else waits on it: an added computer works on its own until its code is typed on home.
425
- const role = await joinSwarm({ ui, code: setupCode, daemonRequest });
426
- // A Resident coming back gets their board back; one without a backup may start one.
427
- const onBoard = await daemonRequest({
428
- command: "board.list",
429
- agent: "user",
430
- all: true,
431
- limit: 1,
432
- }).catch(() => null);
433
- await offerBackup({
434
- ui,
435
- daemonRequest,
436
- role,
437
- boardIsEmpty: onBoard?.ok === true && !onBoard.tasks?.length,
321
+
322
+ const state = await setupState().catch((error) => {
323
+ spin.stop("Harness did not start", 2);
324
+ throw error;
438
325
  });
439
- const library = !readJson(paths.config, {}).libraryOff;
440
- const modelsHere = modelsPresent(path.join(paths.home, "local"), CORE);
441
- ui.note(
442
- [
443
- ...(modelsHere
444
- ? []
445
- : [
446
- `Harness downloads its local models (about ${coreSizeMb()} MB) in the background. Your agents work while it does.`,
447
- ]),
448
- ...(library
449
- ? [
450
- `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`)}`,
451
- ]
452
- : []),
453
- `Your coding agents start the tasks you and your own agents ask for, in any folder below your home, without a Start. Work someone else's agents ask for runs held in its own folder: it reads nothing else of yours and has no network until you press Start. ${pc.dim(`Change it: ${relayCommand()} board standing`)}`,
454
- ].join("\n\n"),
455
- "Good to know"
326
+ spin.stop(
327
+ `Harness is running on this computer ${pc.dim(`· ${service.manager}`)}`
456
328
  );
329
+ const shown = onScreen ? await showApp(ui, runtimeRoot) : { ok: false };
330
+ const code = state.code ? pc.bold(state.code) : null;
331
+ const otherComputer = code
332
+ ? `type ${code} into Add a Computer in Harness on a computer that already has it`
333
+ : null;
334
+ if (shown.ok)
335
+ ui.note(
336
+ [
337
+ "Harness opened on this computer's screen. Sign in there to finish setup.",
338
+ pc.dim(
339
+ `Not at this computer? Open this link in any browser to sign in${otherComputer ? `, or ${otherComputer}` : ""}:`
340
+ ),
341
+ state.url,
342
+ ].join("\n"),
343
+ "Sign in"
344
+ );
345
+ else
346
+ ui.note(
347
+ [
348
+ `Open this link in any browser to sign in${otherComputer ? `, or ${otherComputer}` : ""}:`,
349
+ state.url,
350
+ ...(where.show === "code-first"
351
+ ? [
352
+ pc.dim(
353
+ `To set up on this computer's screen instead: ${relayCommand()} --screen`
354
+ ),
355
+ ]
356
+ : []),
357
+ ].join("\n"),
358
+ "Sign in"
359
+ );
360
+ const waiting = ui.spinner();
361
+ waiting.start("Waiting for you to sign in");
362
+ const ended = await untilSignedIn();
363
+ endCtrlCStop();
364
+ if (ended === "stopped") {
365
+ waiting.stop("Setup stopped in the Harness app");
366
+ ui.outro(stoppedLine(!fs.existsSync(paths.home)));
367
+ return;
368
+ }
369
+ try {
370
+ await waitForDaemon();
371
+ } catch (error) {
372
+ waiting.stop("Signed in, but Harness did not connect", 2);
373
+ throw error;
374
+ }
375
+ waiting.stop("Signed in");
457
376
  ui.outro(
458
- `Done. Talk to your agents from Harness in your browser: ${pairOrigin}/dashboard`
377
+ shown.ok
378
+ ? "Finish setup on this computer's screen."
379
+ : "Done. Turn on this computer's agents in Harness on your other computer."
459
380
  );
460
381
  }
461
382
 
383
+ // Open the Harness app, installing or updating it first, and bring the daemon under its launcher. Never fatal.
384
+ async function showApp(ui, runtimeRoot) {
385
+ const shown = await desktop();
386
+ if (!shown.ok) ui.warn(shown.text);
387
+ if (launcherMissing()) {
388
+ installService({ runtimeRoot });
389
+ await waitForDaemon().catch(() => {});
390
+ }
391
+ return shown;
392
+ }
393
+
462
394
  // The desktop app: the newest build for this machine, installed and opened. Never fatal; the
463
395
  // daemon works without it.
464
396
  async function desktop() {
@@ -1034,31 +966,6 @@ async function peers() {
1034
966
  );
1035
967
  }
1036
968
 
1037
- async function mcpSnippet() {
1038
- const client = argv[0];
1039
- if (!MCP_CLIENTS.includes(client))
1040
- throw new Error(`usage: tryharness mcp <${MCP_CLIENTS.join("|")}>`);
1041
- const config = readJson(paths.config, {});
1042
- const runtimeRoot = config.runtimeRoot || currentRuntime();
1043
- if (!runtimeRoot)
1044
- throw new Error(
1045
- "no Harness runtime is installed yet; run npx tryharness first"
1046
- );
1047
- const found = detectMcpClients().find((entry) => entry.client === client);
1048
- console.log(
1049
- `${client}: ${found?.path ? `found at ${found.path}` : "not found on this machine; the snippet still works once it is installed"}`
1050
- );
1051
- console.log(
1052
- `In ${client === "grok-bot" ? "Grok Bot, open Settings, MCP, add a server" : client} and paste this:\n`
1053
- );
1054
- console.log(
1055
- JSON.stringify(mcpClientSnippet({ runtimeRoot, client }), null, 2)
1056
- );
1057
- console.log(
1058
- `\nIt then sees the board through list_tasks, get_task, post_task, claim_task and report_task as "${client}".`
1059
- );
1060
- }
1061
-
1062
969
  // One line per section (its priority, name, source, whole size and what was sent), the budget decision, the session,
1063
970
  // and for a dry run the brief itself.
1064
971
  function printBrief({ task, agent, report, prompt }, dryRun) {
@@ -2053,16 +1960,6 @@ async function cloudStart() {
2053
1960
  await startDaemon();
2054
1961
  }
2055
1962
 
2056
- // What setup downloaded into ~/.harness (the daemon's runtime, local models and their engine): uninstall takes it out
2057
- // and keeps what is the person's, their board, history and keys, unless they ask for everything.
2058
- const downloadedParts = () => [
2059
- paths.runtime,
2060
- // The installed command (runtime-install.mjs), which runs the runtime above.
2061
- path.join(paths.home, "bin"),
2062
- paths.models,
2063
- path.join(paths.home, "local"),
2064
- ];
2065
-
2066
1963
  function folderBytes(target) {
2067
1964
  let stat;
2068
1965
  try {
@@ -2089,28 +1986,12 @@ async function uninstall() {
2089
1986
  try {
2090
1987
  await daemonRequest({ command: "shutdown" }, 2_000);
2091
1988
  } catch {}
2092
- removeNativeHost();
2093
- uninstallDesktop();
2094
- removeAgentConfigurations();
2095
- removeLocalWakes();
2096
- const removed = everything
2097
- ? [paths.home]
2098
- : [...downloadedParts(), paths.status, paths.socket];
2099
- for (const target of removed)
2100
- try {
2101
- fs.rmSync(target, { recursive: true, force: true });
2102
- } catch {}
2103
- // The pairing goes; the person's choices stay (who is in their swarm, who they took out), so setting up again
2104
- // keeps their swarm (a reinstall once came back without Bankr, Quotient, Grok Bot and Muse).
2105
- if (!everything) {
2106
- const { token: _token, ...choices } = readJson(paths.config, {});
2107
- if (Object.keys(choices).length) writeJsonAtomic(paths.config, choices);
2108
- }
1989
+ const { folderRemoved } = removeHarnessHere({ paths, everything });
2109
1990
  if (!left?.ok)
2110
1991
  console.log(
2111
1992
  "Harness could not be told this computer is gone (it was not connected). Setting Harness up again on it still makes it home."
2112
1993
  );
2113
- if (everything) {
1994
+ if (folderRemoved) {
2114
1995
  console.log(
2115
1996
  "Harness is uninstalled, and everything it kept on this computer is deleted."
2116
1997
  );
@@ -2714,7 +2595,8 @@ async function t3() {
2714
2595
  }
2715
2596
 
2716
2597
  // `tryharness upgrade [version]`: this computer's Harness fetches the release, checks its signature before any of it
2717
- // runs (runtime-install.mjs fetchRelease), and only then runs that release's setup.
2598
+ // runs (runtime-install.mjs fetchRelease), brings the Node it pins when Harness has its own, and only then runs that
2599
+ // release's setup, on that Node.
2718
2600
  function upgrade() {
2719
2601
  const spec = argv[0] && !argv[0].startsWith("-") ? argv.shift() : "latest";
2720
2602
  const fetched = fetchRelease({ spec });
@@ -2724,8 +2606,9 @@ function upgrade() {
2724
2606
  ? `tryharness ${fetched.version} is signed with Harness's release key (${fetched.key}). Setting it up.`
2725
2607
  : `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.`
2726
2608
  );
2609
+ updateHarnessNode(fetched.root);
2727
2610
  const setup = spawnSync(
2728
- process.execPath,
2611
+ harnessNode(),
2729
2612
  [path.join(fetched.root, "cli.mjs"), "setup", ...argv],
2730
2613
  { stdio: "inherit" }
2731
2614
  );
@@ -2745,7 +2628,7 @@ function installedLine() {
2745
2628
 
2746
2629
  function help() {
2747
2630
  console.log(
2748
- `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: Jev, 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 swarm dispatcher [models | local [file.gguf] | surplus <model> | agent <agent> [model] | endpoint <url> [model]]\n what words your threads and checks results: the relay's LFM3-Omni or your own model, a Surplus model, one of your agents, or your endpoint\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 | update <name> [version] | 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`
2631
+ `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: Jev, 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 swarm dispatcher [models | local [file.gguf] | surplus <model> | agent <agent> [model] | endpoint <url> [model]]\n what words your threads and checks results: the relay's LFM3-Omni or your own model, a Surplus model, one of your agents, or your endpoint\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 | update <name> [version] | 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 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`
2749
2632
  );
2750
2633
  }
2751
2634
 
@@ -2776,7 +2659,6 @@ try {
2776
2659
  else if (command === "goal") await goal();
2777
2660
  else if (command === "room") await room();
2778
2661
  else if (command === "swarm") await swarm();
2779
- else if (command === "mcp") await mcpSnippet();
2780
2662
  else if (command === "connections" && ["on", "off"].includes(argv[0])) {
2781
2663
  // Apps (connected outside accounts) are off until the person turns them on; agents see the connection tool in
2782
2664
  // the sessions they start after that (mcp-stdio.mjs).