tryharness 0.7.81 → 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.
- package/README.md +4 -3
- package/assets/install.sh +104 -0
- package/cli.mjs +203 -321
- package/lib/adapters.mjs +7 -6
- package/lib/agentRuntimes.mjs +2 -1
- package/lib/backupSetup.mjs +0 -52
- package/lib/boardProtocol.json +17 -1
- package/lib/browserPage.mjs +30 -0
- package/lib/daemon.mjs +89 -5
- package/lib/desktop.mjs +7 -1
- package/lib/dispatcher.mjs +12 -2
- package/lib/environments.mjs +4 -11
- package/lib/goalCommands.mjs +2 -1
- package/lib/hookDialects.mjs +2 -1
- package/lib/jobAnswers.mjs +2 -1
- package/lib/localStack.mjs +24 -9
- package/lib/mcp-stdio.mjs +6 -0
- package/lib/museSession.mjs +2 -1
- package/lib/nativeHost.mjs +11 -2
- package/lib/network.mjs +1 -0
- package/lib/notify.mjs +48 -16
- package/lib/onboard.mjs +71 -366
- package/lib/ownMachines.mjs +4 -1
- package/lib/pairing.mjs +0 -84
- package/lib/paths.mjs +17 -0
- package/lib/personNotices.mjs +9 -25
- package/lib/profile.mjs +0 -109
- package/lib/projects.mjs +18 -4
- package/lib/removeHarness.mjs +91 -0
- package/lib/roomChannels.mjs +2 -0
- package/lib/runner.mjs +3 -3
- package/lib/runtime-install.mjs +22 -2
- package/lib/screen.mjs +133 -0
- package/lib/selfUpdate.mjs +6 -6
- package/lib/service.mjs +120 -7
- package/lib/sessionControl.mjs +10 -0
- package/lib/setupChoices.mjs +400 -0
- package/lib/setupMode.mjs +137 -0
- package/lib/t3.mjs +23 -14
- package/lib/threadActions.mjs +2 -1
- package/lib/toolCheck.mjs +136 -0
- package/lib/ui.mjs +15 -1
- package/lib/wakes.mjs +3 -3
- package/npm-shrinkwrap.json +14 -14
- package/package.json +4 -4
- package/release.json +47 -40
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).
|
|
7
|
-
//
|
|
8
|
-
//
|
|
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
|
-
{
|
|
55
|
+
{
|
|
56
|
+
title = TITLE,
|
|
57
|
+
thread = "",
|
|
58
|
+
item = `notice:${randomUUID()}`,
|
|
59
|
+
platform = process.platform,
|
|
60
|
+
env = process.env,
|
|
61
|
+
} = {}
|
|
46
62
|
) {
|
|
47
|
-
|
|
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
|
}
|
package/lib/ownMachines.mjs
CHANGED
|
@@ -2248,7 +2248,10 @@ export function createOwnMachines({
|
|
|
2248
2248
|
for (const { agent, machine: computer } of store.agentsSeenOnComputers(
|
|
2249
2249
|
since
|
|
2250
2250
|
)) {
|
|
2251
|
-
|
|
2251
|
+
const seen = member(agent);
|
|
2252
|
+
if (seen?.runs !== "self") continue;
|
|
2253
|
+
// One that can be handed work runs in its own cloud, wherever it last called the board from.
|
|
2254
|
+
if (seen.road === "hosted" && seen.target) continue;
|
|
2252
2255
|
(found[computer] ??= []).push(agent);
|
|
2253
2256
|
}
|
|
2254
2257
|
return found;
|
package/lib/pairing.mjs
CHANGED
|
@@ -127,87 +127,3 @@ export function hasBattery() {
|
|
|
127
127
|
}
|
|
128
128
|
return true;
|
|
129
129
|
}
|
|
130
|
-
|
|
131
|
-
// How long setup waits, at its end, for the person to type this computer's code on home. It works on its own meanwhile,
|
|
132
|
-
// so the wait only lets setup say it joined; the person may close it.
|
|
133
|
-
const JOIN_WAIT_MS = 10 * 60_000;
|
|
134
|
-
// How long a computer approved from home's buddy usually takes to be confirmed there, before setup says where to type.
|
|
135
|
-
const JOIN_QUIET_MS = 8_000;
|
|
136
|
-
|
|
137
|
-
const names = (labels) =>
|
|
138
|
-
labels.length > 1
|
|
139
|
-
? `${labels.slice(0, -1).join(", ")} and ${labels.at(-1)}`
|
|
140
|
-
: labels[0];
|
|
141
|
-
|
|
142
|
-
/**
|
|
143
|
-
* At the end of setup, once the daemon is connected: Harness has made this computer home or added it. An added one not
|
|
144
|
-
* confirmed yet works on its own board until the person types its code on home (ownMachines.mjs); setup says where and
|
|
145
|
-
* waits for it, then may offer home to a computer that suits that better. On home, the computers that still need their
|
|
146
|
-
* code typed here are named. Returns the role. `daemonRequest` reaches this computer's daemon.
|
|
147
|
-
*/
|
|
148
|
-
export async function joinSwarm({
|
|
149
|
-
ui,
|
|
150
|
-
code,
|
|
151
|
-
daemonRequest,
|
|
152
|
-
battery = hasBattery,
|
|
153
|
-
quietMs = JOIN_QUIET_MS,
|
|
154
|
-
waitMs = JOIN_WAIT_MS,
|
|
155
|
-
}) {
|
|
156
|
-
const read = () =>
|
|
157
|
-
daemonRequest({ command: "machines.list" }).catch(() => null);
|
|
158
|
-
let listed = await read();
|
|
159
|
-
if (!listed?.ok) return "home";
|
|
160
|
-
if (listed.self.role !== "worker") {
|
|
161
|
-
const waiting = listed.machines
|
|
162
|
-
.filter((machine) => machine.role === "worker" && !machine.confirmed)
|
|
163
|
-
.map((machine) => machine.label);
|
|
164
|
-
if (waiting.length)
|
|
165
|
-
ui.info(
|
|
166
|
-
`${names(waiting)} ${waiting.length > 1 ? "are" : "is"} on your account but not in your swarm here yet, and ${waiting.length > 1 ? "each works" : "works"} on its own meanwhile. To bring ${waiting.length > 1 ? "each" : "it"} in, run npx tryharness machines there and type the code it shows here: Add a Computer in the Harness menu.`
|
|
167
|
-
);
|
|
168
|
-
return "home";
|
|
169
|
-
}
|
|
170
|
-
const homeName = () =>
|
|
171
|
-
listed.machines.find((machine) => machine.role === "home")?.label ||
|
|
172
|
-
"your home computer";
|
|
173
|
-
if (listed.joinCode) {
|
|
174
|
-
const spin = ui.spinner();
|
|
175
|
-
spin.start(`Joining your swarm on ${homeName()}`);
|
|
176
|
-
const started = Date.now();
|
|
177
|
-
let told = false;
|
|
178
|
-
while (listed?.joinCode && Date.now() - started < waitMs) {
|
|
179
|
-
// The steps go above the spinner once: a spinner line wider than the terminal wraps, and every frame then
|
|
180
|
-
// prints it again.
|
|
181
|
-
if (!told && Date.now() - started > quietMs) {
|
|
182
|
-
told = true;
|
|
183
|
-
spin.stop(`Waiting for ${homeName()}`);
|
|
184
|
-
ui.info(
|
|
185
|
-
`On ${homeName()}, click the Harness icon in the menu bar, choose Add a Computer, and type ${listed.joinCode}${listed.joinCode === code ? " (the same code)" : ""}. Or run there: npx tryharness machines add ${listed.joinCode}. This computer already works on its own, so you can close this.`
|
|
186
|
-
);
|
|
187
|
-
spin.start(`Waiting for ${homeName()}`);
|
|
188
|
-
}
|
|
189
|
-
await new Promise((resolve) => setTimeout(resolve, 1_000));
|
|
190
|
-
listed = (await read()) ?? listed;
|
|
191
|
-
}
|
|
192
|
-
if (listed.joinCode) {
|
|
193
|
-
spin.stop(
|
|
194
|
-
`This computer works on its own until it joins your swarm. To bring it in, type ${listed.joinCode} on ${homeName()}: Add a Computer in the Harness menu there, or npx tryharness machines add ${listed.joinCode}. What it does meanwhile goes to ${homeName()} when it joins.`
|
|
195
|
-
);
|
|
196
|
-
return "worker";
|
|
197
|
-
}
|
|
198
|
-
spin.stop(`Joined your swarm. ${homeName()} holds the board.`);
|
|
199
|
-
} else ui.success(`In your swarm. ${homeName()} holds the board.`);
|
|
200
|
-
if (!ui.interactive || battery()) return "worker";
|
|
201
|
-
const move = await ui.confirm({
|
|
202
|
-
message: `This computer stays on, so work could go on here while ${homeName()} sleeps. Make it your main computer? Your threads and board come with it.`,
|
|
203
|
-
initialValue: false,
|
|
204
|
-
});
|
|
205
|
-
if (!move) return "worker";
|
|
206
|
-
const moved = await daemonRequest({ command: "machines.home" }, 20_000);
|
|
207
|
-
if (!moved.ok) {
|
|
208
|
-
ui.warn(`Not moved: ${moved.error}`);
|
|
209
|
-
return "worker";
|
|
210
|
-
}
|
|
211
|
-
ui.success("This is your main computer now.");
|
|
212
|
-
return "home";
|
|
213
|
-
}
|