tryharness 0.7.78 → 0.7.82

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 (63) 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 +21 -1
  8. package/lib/browserPage.mjs +30 -0
  9. package/lib/coordinator.mjs +0 -2
  10. package/lib/daemon.mjs +117 -7
  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 +18 -8
  15. package/lib/hookDialects.mjs +2 -1
  16. package/lib/jobAnswers.mjs +2 -1
  17. package/lib/kanban.mjs +217 -48
  18. package/lib/localStack.mjs +24 -9
  19. package/lib/machineRoutes.mjs +9 -0
  20. package/lib/machineRuns.mjs +9 -1
  21. package/lib/manager.mjs +60 -2
  22. package/lib/mcp-stdio.mjs +9 -3
  23. package/lib/museSession.mjs +2 -1
  24. package/lib/nativeHost.mjs +11 -2
  25. package/lib/network.mjs +20 -0
  26. package/lib/notify.mjs +48 -16
  27. package/lib/onboard.mjs +71 -366
  28. package/lib/ownMachines.mjs +95 -44
  29. package/lib/pairing.mjs +0 -84
  30. package/lib/paths.mjs +17 -0
  31. package/lib/peopleBoard.mjs +131 -0
  32. package/lib/personNotices.mjs +9 -25
  33. package/lib/phones.mjs +1 -0
  34. package/lib/profile.mjs +0 -109
  35. package/lib/projectBoard.mjs +219 -0
  36. package/lib/projectPieces.mjs +26 -0
  37. package/lib/projects.mjs +37 -4
  38. package/lib/removeHarness.mjs +91 -0
  39. package/lib/roomChannels.mjs +2 -0
  40. package/lib/runAuthority.mjs +23 -9
  41. package/lib/runBrief.mjs +20 -14
  42. package/lib/runner.mjs +3 -3
  43. package/lib/runtime-install.mjs +22 -2
  44. package/lib/screen.mjs +133 -0
  45. package/lib/selfUpdate.mjs +6 -6
  46. package/lib/service.mjs +120 -7
  47. package/lib/sessionControl.mjs +10 -0
  48. package/lib/setupChoices.mjs +400 -0
  49. package/lib/setupMode.mjs +137 -0
  50. package/lib/store.mjs +6 -3
  51. package/lib/swarm.mjs +181 -61
  52. package/lib/t3.mjs +23 -14
  53. package/lib/taskCommands.mjs +25 -15
  54. package/lib/taskRooms.mjs +2 -4
  55. package/lib/threadActions.mjs +16 -4
  56. package/lib/threadAuthority.mjs +28 -10
  57. package/lib/threadRuns.mjs +162 -74
  58. package/lib/toolCheck.mjs +136 -0
  59. package/lib/ui.mjs +15 -1
  60. package/lib/wakes.mjs +3 -3
  61. package/npm-shrinkwrap.json +14 -14
  62. package/package.json +4 -4
  63. package/release.json +64 -55
@@ -1,7 +1,7 @@
1
1
  import fs from "node:fs";
2
2
  import os from "node:os";
3
3
  import path from "node:path";
4
- import { paths } from "./paths.mjs";
4
+ import { harnessNode, paths } from "./paths.mjs";
5
5
 
6
6
  // The Harness extension finds the daemon on its own computer through Chrome's native messaging: Chrome starts this
7
7
  // host for the extension, one message in and one answer out, so the Harness window links to the computer it runs on
@@ -61,7 +61,7 @@ const manifestFor = (program) => ({
61
61
  */
62
62
  export function installNativeHost({
63
63
  runtimeRoot,
64
- nodePath = process.execPath,
64
+ nodePath = harnessNode(),
65
65
  platform = process.platform,
66
66
  home = os.homedir(),
67
67
  folders = browserFolders(platform, home),
@@ -142,6 +142,13 @@ export async function serveNativeHost({
142
142
  }
143
143
  return { ok: true, listening: true };
144
144
  }
145
+ // The page the person is on (the extension's computerPage.js), for the buddy's chip.
146
+ if (message?.type === "active-page") {
147
+ await daemon({ command: "browser.page.set", page: message.page }).catch(
148
+ () => null
149
+ );
150
+ return { ok: true };
151
+ }
145
152
  try {
146
153
  if (message?.type === "this-computer") {
147
154
  const found = await daemon({ command: "phone.identity" });
@@ -221,6 +228,8 @@ export async function serveNativeHost({
221
228
  }
222
229
  }
223
230
  closed = true;
231
+ // The browser went: no page is the one the person is on any more.
232
+ await daemon({ command: "browser.page.set", page: null }).catch(() => null);
224
233
  }
225
234
 
226
235
  export function writeMessage(output, message) {
package/lib/network.mjs CHANGED
@@ -4,6 +4,8 @@
4
4
  // read). A sealed request's subject is opened here, never at Harness. Only the person ("user") calls
5
5
  // these; another agent works a thread through board.thread.* on the task it holds.
6
6
 
7
+ import { peopleBoard } from "./peopleBoard.mjs";
8
+
7
9
  const SEEN = (id) => `relay_seen:${id}`;
8
10
  const AUTO_SEND_DEFAULT = "relay_auto_send_default";
9
11
  const DECISIONS = new Set(["accept", "decline", "block"]);
@@ -89,6 +91,7 @@ export function createNetwork({
89
91
  project,
90
92
  sender: peer.handle,
91
93
  fingerprint: keyPrint,
94
+ createdAt: thread.createdAt,
92
95
  });
93
96
  if (thread.role === "asker")
94
97
  sent.push({ id: thread.id, status: thread.status, project });
@@ -236,6 +239,23 @@ export function createNetwork({
236
239
  switch (request.command) {
237
240
  case "board.relay.list":
238
241
  return answered(conversations());
242
+ // The board of every ask between the person's swarm and one other person's (peopleBoard.mjs).
243
+ case "board.relay.board": {
244
+ const handle = String(request.handle || "")
245
+ .toLowerCase()
246
+ .replace(/^@/, "");
247
+ if (!handle) return { ok: false, error: "say whose board (handle)" };
248
+ return answered(
249
+ conversations().then((list) => ({
250
+ ok: true,
251
+ ...peopleBoard(list.items, {
252
+ handle,
253
+ messagesOf: (taskId) => store.threadMessages(taskId),
254
+ taskOf: (taskId) => store.getTask(taskId),
255
+ }),
256
+ }))
257
+ );
258
+ }
239
259
  // The server's half of Swarms (card, search, contacts, blocks): what the dashboard asks Harness directly.
240
260
  case "board.relay.network": {
241
261
  // Only the operation's own fields go to Harness, which refuses any other (a browser's call adds fromWindow and
package/lib/notify.mjs CHANGED
@@ -1,28 +1,25 @@
1
1
  import { spawn } from "node:child_process";
2
+ import { randomUUID } from "node:crypto";
2
3
  import { nameOf } from "./members.mjs";
4
+ import { readJson } from "./files.mjs";
5
+ import { paths } from "./paths.mjs";
3
6
 
4
7
  // A desktop notification from the daemon, for the person who does not have Harness open:
5
8
  // work that needs them (an agent asks to run something, a question, a stale claim, a request
6
- // from another person). Native on each platform, nothing installed. HARNESS_NOTIFY_COMMAND
7
- // replaces the native call (tests, or a person who wants their own notifier): it runs with
8
- // the title and body as its two arguments.
9
+ // from another person). HARNESS_NOTIFY_COMMAND replaces the native call (tests, or a person
10
+ // who wants their own notifier): it runs with the title and body as its two arguments.
11
+ //
12
+ // While the buddy collects them it posts every notice itself
13
+ // (packages/desktop/src-tauri/src/notices.rs), so the notice is Harness's and a click opens
14
+ // its place. On a Mac the daemon never posts one: a notice posted through osascript belongs
15
+ // to Script Editor, and a click opened Script Editor. While the buddy is not running there,
16
+ // the daemon keeps each notice for its next launch.
9
17
 
10
18
  const TITLE = "Harness";
11
19
 
12
20
  export function command(platform, title, body, env) {
13
21
  if (env.HARNESS_NOTIFY_COMMAND)
14
22
  return { command: env.HARNESS_NOTIFY_COMMAND, args: [title, body] };
15
- if (platform === "darwin") {
16
- const quote = (value) =>
17
- String(value).replaceAll("\\", "\\\\").replaceAll('"', '\\"');
18
- return {
19
- command: "osascript",
20
- args: [
21
- "-e",
22
- `display notification "${quote(body)}" with title "${quote(title)}"`,
23
- ],
24
- };
25
- }
26
23
  if (platform === "linux")
27
24
  return { command: "notify-send", args: [title, body] };
28
25
  // The words go in through the environment, never into the script: PowerShell also ends a quoted string at the
@@ -40,11 +37,40 @@ export function command(platform, title, body, env) {
40
37
  return null;
41
38
  }
42
39
 
40
+ // What the buddy has not collected yet. The oldest go first past this many.
41
+ const BUDDY_KEEPS = 50;
42
+ // How long since the buddy last collected before it counts as not running.
43
+ const BUDDY_GONE_MS = 10_000;
44
+ const forBuddy = { notices: [], collectedAt: 0 };
45
+
46
+ const buddyCollects = () => Date.now() - forBuddy.collectedAt < BUDDY_GONE_MS;
47
+
48
+ /**
49
+ * One notice. A click opens `thread` in the buddy at `item` ("app:", "devices:" and "agent:"
50
+ * open Settings and the Swarm map); with no thread it opens the board. A notice without an
51
+ * item gets one of its own; a second notice for the same item replaces the first.
52
+ */
43
53
  export function notifyDesktop(
44
54
  body,
45
- { title = TITLE, platform = process.platform, env = process.env } = {}
55
+ {
56
+ title = TITLE,
57
+ thread = "",
58
+ item = `notice:${randomUUID()}`,
59
+ platform = process.platform,
60
+ env = process.env,
61
+ } = {}
46
62
  ) {
47
- const call = command(platform, title, String(body).slice(0, 240), env);
63
+ // The person turned desktop notices off in setup ("Tell me when an agent needs me"); the board still shows all of it.
64
+ if (readJson(paths.config, {}).desktopNotices === false) return false;
65
+ const words = String(body).slice(0, 240);
66
+ const keepForMacBuddy = platform === "darwin" && !env.HARNESS_NOTIFY_COMMAND;
67
+ if (buddyCollects() || keepForMacBuddy) {
68
+ forBuddy.notices.push({ title, body: words, thread, item });
69
+ forBuddy.notices.splice(0, forBuddy.notices.length - BUDDY_KEEPS);
70
+ return true;
71
+ }
72
+ const line = title === TITLE ? words : `${title}: ${words}`;
73
+ const call = command(platform, TITLE, line, env);
48
74
  if (!call) return false;
49
75
  try {
50
76
  const child = spawn(call.command, call.args, {
@@ -60,6 +86,12 @@ export function notifyDesktop(
60
86
  }
61
87
  }
62
88
 
89
+ /** The buddy collects what it should post (board.notices.take). */
90
+ export function takeNotices() {
91
+ forBuddy.collectedAt = Date.now();
92
+ return forBuddy.notices.splice(0);
93
+ }
94
+
63
95
  // Which board changes deserve a desktop notification: only what waits on the person.
64
96
  export function notificationFor(task, { previous = null } = {}) {
65
97
  if (!task) return null;
package/lib/onboard.mjs CHANGED
@@ -7,7 +7,6 @@ import {
7
7
  localWakes,
8
8
  } from "./wakes.mjs";
9
9
  import { columns, createUi, wrap } from "./ui.mjs";
10
- import { CHECKABLE, SIGN_IN } from "./readiness.mjs";
11
10
  import { relayCommand } from "./runtime-install.mjs";
12
11
 
13
12
  // "Your swarm" in setup: every agent class with how Harness reaches it, the recommended way already chosen, and a real
@@ -223,6 +222,70 @@ async function waitFor(check, waitMs = 10 * 60_000, everyMs = 3_000) {
223
222
  return false;
224
223
  }
225
224
 
225
+ /**
226
+ * Muse, set up the way Grok Bot is: the message Harness writes goes on the clipboard, Muse opens Harness's approval
227
+ * page, and the person names the connection Muse. Harness cannot wake Muse, so there is no wake to choose and no test:
228
+ * Muse checks on the schedule the person gives it, and is answering once it has read the board.
229
+ */
230
+ async function setupMuse({ ui, daemonRequest, clipboard }) {
231
+ const list = () =>
232
+ daemonRequest({ command: "wake.server", input: { action: "list" } });
233
+ const listed = await list().catch((error) => ({
234
+ ok: false,
235
+ error: error.message,
236
+ }));
237
+ if (!listed.ok) {
238
+ ui.warn(`Harness could not be reached (${listed.error}). ${later("muse")}`);
239
+ return;
240
+ }
241
+ const museSetup = (listing) =>
242
+ (listing?.setup || []).find((entry) => entry.agent === "muse");
243
+ const current = museSetup(listed);
244
+ if (current?.state === "answering") {
245
+ ui.success("Muse is connected and checks Harness on its own schedule");
246
+ return;
247
+ }
248
+ if (current && !current.missing?.includes("connection")) {
249
+ ui.success(
250
+ `Muse is connected to Harness ${pc.dim("· it picks up work at its next check")}`
251
+ );
252
+ return;
253
+ }
254
+ if (!ui.interactive) {
255
+ ui.info(`Muse is not set up. ${later("muse")}`);
256
+ return;
257
+ }
258
+ const message = listed.messages?.muse?.schedule;
259
+ if (!message) {
260
+ ui.warn(
261
+ "Harness did not send the setup message. Update tryharness and try again."
262
+ );
263
+ return;
264
+ }
265
+ const copied = clipboard(message);
266
+ ui.note(
267
+ wrap(message, Math.max(40, columns() - 8)).join("\n"),
268
+ copied
269
+ ? "Paste this into Muse · it is on your clipboard"
270
+ : "Paste this into Muse"
271
+ );
272
+ ui.info(
273
+ "Muse opens Harness's approval page. Name the connection Muse and approve it."
274
+ );
275
+ const spin = ui.spinner();
276
+ spin.start("Waiting for you to approve Muse");
277
+ const connected = await waitFor(async () => {
278
+ const setup = museSetup(await list().catch(() => null));
279
+ return Boolean(setup) && !setup.missing?.includes("connection");
280
+ });
281
+ spin.stop(
282
+ connected
283
+ ? "Muse is connected. It picks up work at each check"
284
+ : `Muse has not connected yet. When it has: ${relayCommand()} agents setup muse`,
285
+ connected ? 0 : 2
286
+ );
287
+ }
288
+
226
289
  async function setupGrok({ ui, daemonRequest, clipboard }) {
227
290
  const list = () =>
228
291
  daemonRequest({ command: "wake.server", input: { action: "list" } });
@@ -464,6 +527,12 @@ export async function setupSwarm({
464
527
  );
465
528
  await setupGrok({ ui, daemonRequest, clipboard });
466
529
  }
530
+ if (only === "muse") {
531
+ ui.step(
532
+ `Muse ${pc.dim("· runs in Meta's cloud, checks Harness on its own schedule")}`
533
+ );
534
+ await setupMuse({ ui, daemonRequest, clipboard });
535
+ }
467
536
  if (!only)
468
537
  ui.info(
469
538
  `Bankr and Quotient run on Harness ${pc.dim("· nothing to set up")}`
@@ -475,367 +544,6 @@ export async function setupSwarm({
475
544
  const ADD_LATER = () =>
476
545
  `Add an agent any time: in the Harness app, Agents, then Add an agent, or run ${pc.cyan(`${relayCommand()} agents add`)}. A coding agent you install or sign in to later joins by itself once it answers.`;
477
546
 
478
- const COMMAND = {
479
- "claude-code": "claude",
480
- codex: "codex",
481
- pi: "pi",
482
- opencode: "opencode",
483
- };
484
- const why = (check) =>
485
- check.state === "signed_out"
486
- ? "is not signed in yet"
487
- : check.state === "slow"
488
- ? "did not answer within a minute"
489
- : `did not answer${check.detail ? `: ${check.detail}` : ""}`;
490
- const fix = (agent, check) =>
491
- check.state === "signed_out" && SIGN_IN[agent]
492
- ? `Sign it in from another terminal window:\n ${pc.cyan(SIGN_IN[agent])}`
493
- : `Open it once in another terminal window to see what it needs:\n ${pc.cyan(COMMAND[agent] ?? agent)}`;
494
-
495
- /**
496
- * Which of the agents found here can take a prompt now. Every coding agent gets one real prompt (readiness.mjs; `checks`
497
- * holds the ones setup started while the person signed in), and the answers are shown in one list. Returns the ready
498
- * ones, which join with no list to tick, OpenClaw and Hermes when found, and the coding agents that did not answer, for
499
- * `walkThrough` once Harness runs. Agents Harness cannot check (Cursor, Grok Build) join only when the person adds them.
500
- * `--agent` limits setup to the agents named.
501
- */
502
- export async function checkAgents({
503
- ui = createUi(),
504
- here,
505
- checks,
506
- readiness,
507
- requested = [],
508
- removed = [],
509
- }) {
510
- const wanted = here.filter((entry) =>
511
- requested.length
512
- ? requested.includes(entry.id)
513
- : !removed.includes(entry.id)
514
- );
515
- if (!wanted.length) {
516
- ui.step(
517
- `No agents found on this computer yet ${pc.dim("· Harness works with Claude Code, Codex, Pi, OpenCode, OpenClaw and Hermes")}\n${pc.dim("Install one any time: it joins your swarm by itself once it is signed in.")}`
518
- );
519
- return { ready: [], waiting: [] };
520
- }
521
- const checkable = wanted.filter((entry) => CHECKABLE.includes(entry.id));
522
- const results = new Map();
523
- if (checkable.length) {
524
- const spin = ui.spinner();
525
- spin.start("Sending each of your agents a one-line prompt");
526
- for (const [id, check] of await Promise.all(
527
- checkable.map(async (entry) => [
528
- entry.id,
529
- await (checks.get(entry.id) ?? readiness.check(entry.id)),
530
- ])
531
- ))
532
- results.set(id, check);
533
- spin.stop("Your agents answered");
534
- ui.message(
535
- checkable
536
- .map((entry) =>
537
- results.get(entry.id).state === "ready"
538
- ? `${pc.green("✓")} ${entry.name} ${pc.dim("ready")}`
539
- : `${pc.yellow("!")} ${entry.name} ${pc.dim(why(results.get(entry.id)))}`
540
- )
541
- .join("\n")
542
- );
543
- }
544
- const local = wanted
545
- .filter((entry) => ["openclaw", "hermes"].includes(entry.id))
546
- .map((entry) => entry.id);
547
- return {
548
- ready: [
549
- ...checkable
550
- .filter((entry) => results.get(entry.id).state === "ready")
551
- .map((entry) => entry.id),
552
- ...local,
553
- ],
554
- waiting: checkable
555
- .filter((entry) => results.get(entry.id).state !== "ready")
556
- .map((entry) => ({ ...entry, check: results.get(entry.id) })),
557
- };
558
- }
559
-
560
- /**
561
- * Each coding agent that did not answer, one at a time, once Harness runs: what is wrong, the command that fixes it,
562
- * then check again or skip. One that answers joins the swarm there and then (`join`, the daemon's swarm.add), so the
563
- * browser shows it at once. A skipped one joins by itself once it answers (the daemon's agent watch), so skipping loses
564
- * nothing. Without a terminal to answer in, nobody is walked through. Returns the agents that joined.
565
- */
566
- export async function walkThrough({
567
- ui = createUi(),
568
- waiting,
569
- readiness,
570
- join,
571
- }) {
572
- const joined = [];
573
- for (const entry of waiting) {
574
- if (!ui.interactive) break;
575
- let check = entry.check;
576
- while (check.state !== "ready") {
577
- ui.note(
578
- `${entry.name} ${why(check)}.\n\n${fix(entry.id, check)}`,
579
- entry.name
580
- );
581
- const next = await ui.select({
582
- message: `When ${entry.name} is ready`,
583
- options: [
584
- { value: "check", label: "Check again" },
585
- {
586
- value: "skip",
587
- label: "Skip for now",
588
- hint: "it joins your swarm by itself once it answers",
589
- },
590
- ],
591
- });
592
- if (next === null) process.exit(130);
593
- if (next === "skip") break;
594
- const again = ui.spinner();
595
- again.start(`Sending ${entry.name} a one-line prompt`);
596
- check = await readiness.check(entry.id);
597
- if (check.state !== "ready") {
598
- again.stop(`${entry.name} ${why(check)}`, 2);
599
- continue;
600
- }
601
- const added = await join(entry.id);
602
- again.stop(
603
- added?.ok
604
- ? `${entry.name} is ready and in your swarm`
605
- : `${entry.name} is ready but could not join: ${added?.error ?? "no answer"}`,
606
- added?.ok ? 0 : 2
607
- );
608
- if (added?.ok) joined.push(entry.id);
609
- }
610
- }
611
- return joined;
612
- }
613
-
614
- /** After the daemon starts: the swarm as chosen, OpenClaw and Hermes set up (they were ticked), and how to add more. */
615
- export async function setupChosen({
616
- chosen,
617
- here,
618
- states = [],
619
- runtimeRoot,
620
- daemonRequest,
621
- ui = createUi(),
622
- }) {
623
- const stateOf = new Map(states.map((state) => [state.agent, state]));
624
- const rows = chosen.map((id) => {
625
- const state = stateOf.get(id);
626
- const name = here.find((entry) => entry.id === id)?.name ?? id;
627
- return state && !state.configured
628
- ? `${pc.yellow("!")} ${name} ${pc.dim(state.detail)}`
629
- : `${pc.green("✓")} ${name}`;
630
- });
631
- if (rows.length)
632
- ui.step(
633
- `Your swarm ${pc.dim("· Harness, plus your agents that are ready")}\n${rows.join("\n")}`
634
- );
635
- const local = detectLocalAgents().filter(
636
- (entry) => entry.found && chosen.includes(entry.agent)
637
- );
638
- for (const entry of local)
639
- await setupLocal({ entry, runtimeRoot, ui, daemonRequest, ask: false });
640
- }
641
-
642
- // What each agent that runs elsewhere is, in the offer below.
643
- const ELSEWHERE_HINT = {
644
- "grok-bot": "Grok in its own cloud, woken by email or webhook: set up next",
645
- muse: "set up in Harness once added",
646
- bankr: "trades and wallets: set Bankr up in Harness so it can act",
647
- };
648
-
649
- /**
650
- * The agents that run elsewhere, at the end of setup, so a person finds them without knowing their names. Quotient has
651
- * nothing to set up and Bankr's setup is on the account, so on a first setup Quotient joins, and Bankr too once the
652
- * person set it up in Harness; Grok Bot and Muse each need their own setup, so they are offered. An agent the person
653
- * took out of their swarm (`removed`) is left out.
654
- */
655
- export async function setupElsewhere({
656
- daemonRequest,
657
- ui = createUi(),
658
- fresh,
659
- removed = [],
660
- clipboard = copy,
661
- }) {
662
- const lineup = await daemonRequest({ command: "swarm.lineup" }).catch(
663
- () => null
664
- );
665
- if (lineup?.ok) {
666
- const outside = (id) =>
667
- !removed.includes(id) &&
668
- lineup.agents.some((entry) => entry.id === id && !entry.inSwarm);
669
- const account = await daemonRequest({
670
- command: "wake.server",
671
- input: { action: "list" },
672
- }).catch(() => null);
673
- const joining = fresh
674
- ? ["quotient", ...(account?.bankrWallet ? ["bankr"] : [])].filter(outside)
675
- : [];
676
- const joined = [];
677
- for (const id of joining) {
678
- const added = await daemonRequest({
679
- command: "swarm.add",
680
- target: id,
681
- }).catch(() => null);
682
- if (added?.ok) joined.push({ id, name: added.name });
683
- }
684
- if (joined.length)
685
- ui.success(
686
- `${joined.map((agent) => agent.name).join(" and ")} ${joined.length > 1 ? "are" : "is"} in your swarm ${pc.dim(`· ${joined.length > 1 ? "they run" : "it runs"} on Harness, nothing to set up`)}`
687
- );
688
- const offered = ["grok-bot", "muse", "bankr"].filter(
689
- (id) => outside(id) && !joined.some((agent) => agent.id === id)
690
- );
691
- if (offered.length && ui.interactive) {
692
- const picked =
693
- (await ui.multiselect({
694
- message: `Agents that run elsewhere. Add any? ${pc.dim("(space to tick, enter to go on)")}`,
695
- options: offered.map((id) => ({
696
- value: id,
697
- label: lineup.agents.find((entry) => entry.id === id).name,
698
- hint: ELSEWHERE_HINT[id],
699
- })),
700
- })) ?? [];
701
- if (picked.length)
702
- await addAgents({ daemonRequest, wanted: picked, ui, clipboard });
703
- }
704
- }
705
- ui.info(ADD_LATER());
706
- }
707
-
708
- // A function, not a constant: the installed command only exists once setup has installed the runtime.
709
- const T3_LATER = () => `Later: ${pc.cyan(`${relayCommand()} t3`)}`;
710
- const t3Line = (access) =>
711
- access?.state === "send"
712
- ? {
713
- ok: true,
714
- line: `Harness follows your T3 Code threads and sends into them, until ${access.until.slice(0, 10)}`,
715
- }
716
- : access?.state === "read"
717
- ? {
718
- ok: false,
719
- line: "You approved read only: Harness follows your T3 Code threads but cannot send into them",
720
- }
721
- : {
722
- ok: false,
723
- line: "Not approved yet. Approving it on that page still counts",
724
- };
725
-
726
- /**
727
- * T3 Code, when it has run on this computer. Approved there, Harness follows the person's T3 threads and the agents they
728
- * start, and what they send a T3 session from Harness goes straight into its thread. T3 lets an outside agent in with a
729
- * pairing code from its own Settings, then Connections; Harness never makes that code itself, so the person is the one
730
- * who lets it in. The daemon keeps the sign-in open after this step moves on, so a later approval still counts.
731
- */
732
- export async function setupT3({ ui = createUi(), daemonRequest, open }) {
733
- const status = () =>
734
- daemonRequest({ command: "t3.status" }).catch(() => null);
735
- const first = await status();
736
- if (!first?.installed) return;
737
- if (first.t3?.state === "send") {
738
- ui.success(`T3 Code ${pc.dim(`· ${t3Line(first.t3).line}`)}`);
739
- return;
740
- }
741
- ui.step(
742
- `T3 Code ${pc.dim("· approve Harness there so you see your T3 threads in Harness, message them from anywhere, and Open always lands on the right thread")}`
743
- );
744
- if (first.t3?.state === "read") ui.info(t3Line(first.t3).line);
745
- if (first.t3?.state === "expired")
746
- ui.info("Harness's approval in T3 Code ran out.");
747
- if (!ui.interactive) {
748
- ui.info(T3_LATER());
749
- return;
750
- }
751
- const approve = await ui.select({
752
- message: "Approve Harness in T3 Code?",
753
- options: [
754
- {
755
- value: "approve",
756
- label: "Approve it",
757
- hint: "you need a pairing code from T3 Code",
758
- },
759
- { value: "skip", label: "Not now" },
760
- ],
761
- });
762
- if (approve !== "approve") {
763
- ui.info(`Skipped. ${T3_LATER()}`);
764
- return;
765
- }
766
- for (;;) {
767
- const before = (await status())?.t3 ?? null;
768
- const started = await daemonRequest({ command: "t3.connect" }, 20_000);
769
- if (!started.ok) {
770
- ui.warn(started.error || "Harness could not start the approval.");
771
- if (started.code !== "not_running") {
772
- ui.info(T3_LATER());
773
- return;
774
- }
775
- const next = await ui.select({
776
- message: "When T3 Code is open",
777
- options: [
778
- { value: "check", label: "Check again" },
779
- { value: "skip", label: "Skip for now" },
780
- ],
781
- });
782
- if (next !== "check") {
783
- ui.info(`Skipped. ${T3_LATER()}`);
784
- return;
785
- }
786
- continue;
787
- }
788
- const opened = open(started.url);
789
- ui.note(
790
- [
791
- "1. In T3 Code, open Settings, then Connections, and copy a pairing code.",
792
- opened
793
- ? "2. Paste it on the page that just opened in your browser."
794
- : `2. Open this page in a browser on this computer and paste it there:\n${started.url}`,
795
- "3. Choose what Harness may do. To message threads that run in Full access, choose Full access.",
796
- ].join("\n"),
797
- "Approve Harness in T3 Code"
798
- );
799
- let settled = false;
800
- const approved = waitFor(async () => {
801
- if (settled) return true;
802
- const now = (await status())?.t3 ?? null;
803
- return Boolean(now) && JSON.stringify(now) !== JSON.stringify(before);
804
- }).then(async (changed) =>
805
- changed ? t3Line((await status())?.t3) : t3Line(null)
806
- );
807
- const answer = await ui.waitOrType({
808
- message: "Waiting for your approval in T3 Code",
809
- placeholder: "press Esc to stop waiting",
810
- until: approved,
811
- });
812
- if (answer.cancelled) {
813
- settled = true;
814
- ui.info(
815
- `Stopped waiting. Approving it on that page still counts. ${T3_LATER()}`
816
- );
817
- return;
818
- }
819
- let outcome = answer.done;
820
- if (!outcome) {
821
- const spin = ui.spinner();
822
- spin.start("Waiting for your approval in T3 Code");
823
- outcome = await approved;
824
- spin.stop(outcome.line, outcome.ok ? 0 : 2);
825
- }
826
- settled = true;
827
- if ((await status())?.t3?.state !== "read") return;
828
- const again = await ui.select({
829
- message: "Approve it again with more access?",
830
- options: [
831
- { value: "again", label: "Approve it again" },
832
- { value: "keep", label: "Keep read only" },
833
- ],
834
- });
835
- if (again !== "again") return;
836
- }
837
- }
838
-
839
547
  const mark = (entry) =>
840
548
  entry.inSwarm
841
549
  ? pc.green("✓")
@@ -931,10 +639,7 @@ export async function addAgents({
931
639
  `${added.name} is in your swarm${added.signedOut ? `. Sign in to ${added.name} before it takes work` : ""}.`
932
640
  );
933
641
  if (id === "grok-bot") await setupGrok({ ui, daemonRequest, clipboard });
934
- if (id === "muse")
935
- ui.info(
936
- "Muse takes work once it is set up in Harness: open the dashboard, then Agents, then Muse."
937
- );
642
+ if (id === "muse") await setupMuse({ ui, daemonRequest, clipboard });
938
643
  }
939
644
  return ok;
940
645
  }