tryharness 0.7.45 → 0.7.54
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +239 -14
- package/assets/dsh-plugin.mjs +72 -0
- package/assets/opencode-plugin.js +4 -3
- package/cli.mjs +497 -196
- package/lib/actorRoster.mjs +28 -5
- package/lib/adapters.mjs +165 -222
- package/lib/agentRuntimeConfig.mjs +36 -0
- package/lib/agentRuntimes.mjs +570 -0
- package/lib/agentSignIn.mjs +226 -0
- package/lib/atlas.mjs +7 -2
- package/lib/audit.mjs +643 -0
- package/lib/backupSetup.mjs +141 -0
- package/lib/boardAccess.mjs +8 -1
- package/lib/boardBackup.mjs +283 -0
- package/lib/boardCommands.mjs +5 -10
- package/lib/boardFileCommands.mjs +2 -1
- package/lib/boardMirror.mjs +523 -0
- package/lib/boardProtocol.json +263 -6
- package/lib/boardTools.mjs +2 -6
- package/lib/boardWaits.mjs +102 -0
- package/lib/book.mjs +659 -0
- package/lib/bridge.mjs +26 -4
- package/lib/browserWake.mjs +60 -0
- package/lib/cards.mjs +159 -16
- package/lib/cloudBoot.mjs +124 -0
- package/lib/commands.mjs +25 -5
- package/lib/connectionTools.d.ts +13 -0
- package/lib/connectionTools.js +45 -0
- package/lib/connectorAuth.mjs +309 -0
- package/lib/connectorCatalog.json +41 -0
- package/lib/connectorCommands.mjs +121 -0
- package/lib/connectorGoogle.mjs +513 -0
- package/lib/connectors.mjs +805 -0
- package/lib/context.mjs +18 -4
- package/lib/contractGate.mjs +377 -0
- package/lib/coordinator.mjs +152 -39
- package/lib/coreModels.mjs +78 -0
- package/lib/daemon.mjs +973 -54
- package/lib/desk.mjs +239 -0
- package/lib/desktop.mjs +113 -8
- package/lib/digest.mjs +32 -0
- package/lib/directLink.mjs +283 -0
- package/lib/environments.mjs +825 -0
- package/lib/folders.mjs +4 -4
- package/lib/gitHost.mjs +174 -0
- package/lib/goalCommands.mjs +58 -14
- package/lib/hookDialects.mjs +298 -0
- package/lib/inference.mjs +263 -152
- package/lib/landed.mjs +887 -0
- package/lib/lessons.mjs +6 -0
- package/lib/lineup.mjs +324 -0
- package/lib/live.mjs +284 -13
- package/lib/localmodels.mjs +10 -0
- package/lib/machineIdentity.mjs +3 -0
- package/lib/machineRoutes.mjs +40 -2
- package/lib/machineRuns.mjs +30 -3
- package/lib/machineSeal.mjs +69 -10
- package/lib/mcp-stdio.mjs +189 -120
- package/lib/mcpRelay.mjs +119 -0
- package/lib/members.json +26 -0
- package/lib/members.mjs +33 -0
- package/lib/modelMemory.mjs +100 -0
- package/lib/models.mjs +48 -15
- package/lib/museSession.mjs +122 -0
- package/lib/nativeHost.mjs +203 -0
- package/lib/neovim.mjs +126 -0
- package/lib/network.mjs +7 -2
- package/lib/nudge.mjs +57 -18
- package/lib/onboard.mjs +430 -1
- package/lib/oneclawLocal.mjs +150 -0
- package/lib/ownMachines.mjs +828 -39
- package/lib/pairing.mjs +182 -0
- package/lib/paths.mjs +8 -0
- package/lib/personModel.mjs +89 -0
- package/lib/phones.mjs +119 -3
- package/lib/placeCommands.mjs +27 -0
- package/lib/places.mjs +337 -9
- package/lib/plans.mjs +151 -27
- package/lib/profile.mjs +152 -0
- package/lib/projects.mjs +624 -137
- package/lib/readiness.mjs +400 -0
- package/lib/record.mjs +115 -0
- package/lib/repoLinks.mjs +354 -0
- package/lib/roomChannels.mjs +641 -0
- package/lib/runBrief.mjs +32 -2
- package/lib/runRequests.mjs +157 -0
- package/lib/runWorker.mjs +37 -9
- package/lib/runner.mjs +74 -11
- package/lib/secretPatterns.json +55 -0
- package/lib/secrets.mjs +10 -27
- package/lib/seen.mjs +102 -0
- package/lib/service.mjs +11 -6
- package/lib/sessionControl.mjs +386 -96
- package/lib/sessionIndex.mjs +5 -3
- package/lib/specialties.json +74 -0
- package/lib/specialties.mjs +477 -0
- package/lib/specialtyKeys.d.ts +3 -0
- package/lib/specialtyKeys.js +58 -0
- package/lib/specialtyNotice.mjs +147 -0
- package/lib/specialtySnapshot.mjs +138 -0
- package/lib/store.mjs +829 -29
- package/lib/subagents.mjs +8 -4
- package/lib/swarm.mjs +483 -37
- package/lib/swarmMemory.mjs +947 -0
- package/lib/t3.mjs +56 -17
- package/lib/taskCommands.mjs +91 -13
- package/lib/taskRuns.mjs +68 -11
- package/lib/team.json +253 -144
- package/lib/team.mjs +538 -147
- package/lib/threadLine.mjs +116 -0
- package/lib/threadRuns.mjs +78 -12
- package/lib/threadView.mjs +66 -16
- package/lib/tokenizer.mjs +405 -0
- package/lib/ui.mjs +16 -2
- package/lib/usageTotals.mjs +148 -0
- package/lib/vault.mjs +1144 -0
- package/lib/vaultCloud.mjs +117 -0
- package/lib/vaultCommands.mjs +201 -0
- package/lib/vaultTools.d.ts +12 -0
- package/lib/vaultTools.js +42 -0
- package/lib/windowAsks.mjs +42 -0
- package/lib/workFocus.mjs +59 -0
- package/lib/workLinks.mjs +90 -0
- package/lib/worktrees.mjs +51 -13
- package/package.json +10 -5
package/lib/onboard.mjs
CHANGED
|
@@ -7,6 +7,7 @@ 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";
|
|
10
11
|
|
|
11
12
|
// "Your swarm" in setup: every agent class with how Harness reaches it, the recommended way already chosen, and a real
|
|
12
13
|
// test at the end that passes only when the agent claims and reports a task. Also reachable on its own as
|
|
@@ -125,7 +126,14 @@ export async function testAgent({
|
|
|
125
126
|
return false;
|
|
126
127
|
}
|
|
127
128
|
|
|
128
|
-
async function setupLocal({
|
|
129
|
+
async function setupLocal({
|
|
130
|
+
entry,
|
|
131
|
+
runtimeRoot,
|
|
132
|
+
ui,
|
|
133
|
+
daemonRequest,
|
|
134
|
+
// false once the person ticked it into their swarm: they already said yes.
|
|
135
|
+
ask = true,
|
|
136
|
+
}) {
|
|
129
137
|
const name = LABEL[entry.agent];
|
|
130
138
|
const run = async () => {
|
|
131
139
|
const result = SETUP[entry.agent]({ runtimeRoot });
|
|
@@ -160,6 +168,10 @@ async function setupLocal({ entry, runtimeRoot, ui, daemonRequest }) {
|
|
|
160
168
|
await run();
|
|
161
169
|
return;
|
|
162
170
|
}
|
|
171
|
+
if (!ask) {
|
|
172
|
+
await run();
|
|
173
|
+
return;
|
|
174
|
+
}
|
|
163
175
|
if (!ui.interactive) {
|
|
164
176
|
ui.info(`${name} found. ${later(entry.agent)}`);
|
|
165
177
|
return;
|
|
@@ -431,3 +443,420 @@ export async function setupSwarm({
|
|
|
431
443
|
`Bankr and Quotient run on Harness ${pc.dim("· nothing to set up")}`
|
|
432
444
|
);
|
|
433
445
|
}
|
|
446
|
+
|
|
447
|
+
const ADD_LATER = `Add another agent any time: ${pc.cyan("npx tryharness agents add")}, or Settings, then Your swarm, in the Harness app.`;
|
|
448
|
+
const JOINS_LATER = `Install or sign in another agent any time: it joins your swarm by itself once it answers. ${pc.dim(`Or: npx tryharness agents add`)}`;
|
|
449
|
+
|
|
450
|
+
const COMMAND = {
|
|
451
|
+
"claude-code": "claude",
|
|
452
|
+
codex: "codex",
|
|
453
|
+
pi: "pi",
|
|
454
|
+
opencode: "opencode",
|
|
455
|
+
};
|
|
456
|
+
const why = (check) =>
|
|
457
|
+
check.state === "signed_out"
|
|
458
|
+
? "is not signed in yet"
|
|
459
|
+
: check.state === "slow"
|
|
460
|
+
? "did not answer within a minute"
|
|
461
|
+
: `did not answer${check.detail ? `: ${check.detail}` : ""}`;
|
|
462
|
+
const fix = (agent, check) =>
|
|
463
|
+
check.state === "signed_out" && SIGN_IN[agent]
|
|
464
|
+
? `Sign it in from another terminal window:\n ${pc.cyan(SIGN_IN[agent])}`
|
|
465
|
+
: `Open it once in another terminal window to see what it needs:\n ${pc.cyan(COMMAND[agent] ?? agent)}`;
|
|
466
|
+
|
|
467
|
+
/**
|
|
468
|
+
* Which of the agents found here can take a prompt now. Every coding agent gets one real prompt (readiness.mjs; `checks`
|
|
469
|
+
* holds the ones setup started while the person signed in), and the answers are shown in one list. Returns the ready
|
|
470
|
+
* ones, which join with no list to tick, OpenClaw and Hermes when found, and the coding agents that did not answer, for
|
|
471
|
+
* `walkThrough` once Harness runs. Agents Harness cannot check (Cursor, Grok Build) join only when the person adds them.
|
|
472
|
+
* `--agent` limits setup to the agents named.
|
|
473
|
+
*/
|
|
474
|
+
export async function checkAgents({
|
|
475
|
+
ui = createUi(),
|
|
476
|
+
here,
|
|
477
|
+
checks,
|
|
478
|
+
readiness,
|
|
479
|
+
requested = [],
|
|
480
|
+
removed = [],
|
|
481
|
+
}) {
|
|
482
|
+
const wanted = here.filter((entry) =>
|
|
483
|
+
requested.length
|
|
484
|
+
? requested.includes(entry.id)
|
|
485
|
+
: !removed.includes(entry.id)
|
|
486
|
+
);
|
|
487
|
+
if (!wanted.length) {
|
|
488
|
+
ui.step(
|
|
489
|
+
`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.")}`
|
|
490
|
+
);
|
|
491
|
+
return { ready: [], waiting: [] };
|
|
492
|
+
}
|
|
493
|
+
const checkable = wanted.filter((entry) => CHECKABLE.includes(entry.id));
|
|
494
|
+
const results = new Map();
|
|
495
|
+
if (checkable.length) {
|
|
496
|
+
const spin = ui.spinner();
|
|
497
|
+
spin.start("Sending each of your agents a one-line prompt");
|
|
498
|
+
for (const [id, check] of await Promise.all(
|
|
499
|
+
checkable.map(async (entry) => [
|
|
500
|
+
entry.id,
|
|
501
|
+
await (checks.get(entry.id) ?? readiness.check(entry.id)),
|
|
502
|
+
])
|
|
503
|
+
))
|
|
504
|
+
results.set(id, check);
|
|
505
|
+
spin.stop("Your agents answered");
|
|
506
|
+
ui.message(
|
|
507
|
+
checkable
|
|
508
|
+
.map((entry) =>
|
|
509
|
+
results.get(entry.id).state === "ready"
|
|
510
|
+
? `${pc.green("✓")} ${entry.name} ${pc.dim("ready")}`
|
|
511
|
+
: `${pc.yellow("!")} ${entry.name} ${pc.dim(why(results.get(entry.id)))}`
|
|
512
|
+
)
|
|
513
|
+
.join("\n")
|
|
514
|
+
);
|
|
515
|
+
}
|
|
516
|
+
const local = wanted
|
|
517
|
+
.filter((entry) => ["openclaw", "hermes"].includes(entry.id))
|
|
518
|
+
.map((entry) => entry.id);
|
|
519
|
+
return {
|
|
520
|
+
ready: [
|
|
521
|
+
...checkable
|
|
522
|
+
.filter((entry) => results.get(entry.id).state === "ready")
|
|
523
|
+
.map((entry) => entry.id),
|
|
524
|
+
...local,
|
|
525
|
+
],
|
|
526
|
+
waiting: checkable
|
|
527
|
+
.filter((entry) => results.get(entry.id).state !== "ready")
|
|
528
|
+
.map((entry) => ({ ...entry, check: results.get(entry.id) })),
|
|
529
|
+
};
|
|
530
|
+
}
|
|
531
|
+
|
|
532
|
+
/**
|
|
533
|
+
* Each coding agent that did not answer, one at a time, once Harness runs: what is wrong, the command that fixes it,
|
|
534
|
+
* then check again or skip. One that answers joins the swarm there and then (`join`, the daemon's swarm.add), so the
|
|
535
|
+
* browser shows it at once. A skipped one joins by itself once it answers (the daemon's agent watch), so skipping loses
|
|
536
|
+
* nothing. Without a terminal to answer in, nobody is walked through. Returns the agents that joined.
|
|
537
|
+
*/
|
|
538
|
+
export async function walkThrough({
|
|
539
|
+
ui = createUi(),
|
|
540
|
+
waiting,
|
|
541
|
+
readiness,
|
|
542
|
+
join,
|
|
543
|
+
}) {
|
|
544
|
+
const joined = [];
|
|
545
|
+
for (const entry of waiting) {
|
|
546
|
+
if (!ui.interactive) break;
|
|
547
|
+
let check = entry.check;
|
|
548
|
+
while (check.state !== "ready") {
|
|
549
|
+
ui.note(
|
|
550
|
+
`${entry.name} ${why(check)}.\n\n${fix(entry.id, check)}`,
|
|
551
|
+
entry.name
|
|
552
|
+
);
|
|
553
|
+
const next = await ui.select({
|
|
554
|
+
message: `When ${entry.name} is ready`,
|
|
555
|
+
options: [
|
|
556
|
+
{ value: "check", label: "Check again" },
|
|
557
|
+
{
|
|
558
|
+
value: "skip",
|
|
559
|
+
label: "Skip for now",
|
|
560
|
+
hint: "it joins your swarm by itself once it answers",
|
|
561
|
+
},
|
|
562
|
+
],
|
|
563
|
+
});
|
|
564
|
+
if (next === null) process.exit(130);
|
|
565
|
+
if (next === "skip") break;
|
|
566
|
+
const again = ui.spinner();
|
|
567
|
+
again.start(`Sending ${entry.name} a one-line prompt`);
|
|
568
|
+
check = await readiness.check(entry.id);
|
|
569
|
+
if (check.state !== "ready") {
|
|
570
|
+
again.stop(`${entry.name} ${why(check)}`, 2);
|
|
571
|
+
continue;
|
|
572
|
+
}
|
|
573
|
+
const added = await join(entry.id);
|
|
574
|
+
again.stop(
|
|
575
|
+
added?.ok
|
|
576
|
+
? `${entry.name} is ready and in your swarm`
|
|
577
|
+
: `${entry.name} is ready but could not join: ${added?.error ?? "no answer"}`,
|
|
578
|
+
added?.ok ? 0 : 2
|
|
579
|
+
);
|
|
580
|
+
if (added?.ok) joined.push(entry.id);
|
|
581
|
+
}
|
|
582
|
+
}
|
|
583
|
+
return joined;
|
|
584
|
+
}
|
|
585
|
+
|
|
586
|
+
/** After the daemon starts: the swarm as chosen, OpenClaw and Hermes set up (they were ticked), and how to add more. */
|
|
587
|
+
export async function setupChosen({
|
|
588
|
+
chosen,
|
|
589
|
+
here,
|
|
590
|
+
states = [],
|
|
591
|
+
runtimeRoot,
|
|
592
|
+
daemonRequest,
|
|
593
|
+
ui = createUi(),
|
|
594
|
+
}) {
|
|
595
|
+
const stateOf = new Map(states.map((state) => [state.agent, state]));
|
|
596
|
+
const rows = chosen.map((id) => {
|
|
597
|
+
const state = stateOf.get(id);
|
|
598
|
+
const name = here.find((entry) => entry.id === id)?.name ?? id;
|
|
599
|
+
return state && !state.configured
|
|
600
|
+
? `${pc.yellow("!")} ${name} ${pc.dim(state.detail)}`
|
|
601
|
+
: `${pc.green("✓")} ${name}`;
|
|
602
|
+
});
|
|
603
|
+
if (rows.length)
|
|
604
|
+
ui.step(
|
|
605
|
+
`Your swarm ${pc.dim("· Harness, plus your agents that are ready")}\n${rows.join("\n")}`
|
|
606
|
+
);
|
|
607
|
+
const local = detectLocalAgents().filter(
|
|
608
|
+
(entry) => entry.found && chosen.includes(entry.agent)
|
|
609
|
+
);
|
|
610
|
+
for (const entry of local)
|
|
611
|
+
await setupLocal({ entry, runtimeRoot, ui, daemonRequest, ask: false });
|
|
612
|
+
ui.info(JOINS_LATER);
|
|
613
|
+
}
|
|
614
|
+
|
|
615
|
+
const T3_LATER = `Later: ${pc.cyan("npx tryharness t3")}`;
|
|
616
|
+
const t3Line = (access) =>
|
|
617
|
+
access?.state === "send"
|
|
618
|
+
? {
|
|
619
|
+
ok: true,
|
|
620
|
+
line: `Harness follows your T3 Code threads and sends into them, until ${access.until.slice(0, 10)}`,
|
|
621
|
+
}
|
|
622
|
+
: access?.state === "read"
|
|
623
|
+
? {
|
|
624
|
+
ok: false,
|
|
625
|
+
line: "You approved read only: Harness follows your T3 Code threads but cannot send into them",
|
|
626
|
+
}
|
|
627
|
+
: {
|
|
628
|
+
ok: false,
|
|
629
|
+
line: "Not approved yet. Approving it on that page still counts",
|
|
630
|
+
};
|
|
631
|
+
|
|
632
|
+
/**
|
|
633
|
+
* T3 Code, when it has run on this computer. Approved there, Harness follows the person's T3 threads and the agents they
|
|
634
|
+
* start, and what they send a T3 session from Harness goes straight into its thread. T3 lets an outside agent in with a
|
|
635
|
+
* pairing code from its own Settings, then Connections; Harness never makes that code itself, so the person is the one
|
|
636
|
+
* who lets it in. The daemon keeps the sign-in open after this step moves on, so a later approval still counts.
|
|
637
|
+
*/
|
|
638
|
+
export async function setupT3({ ui = createUi(), daemonRequest, open }) {
|
|
639
|
+
const status = () =>
|
|
640
|
+
daemonRequest({ command: "t3.status" }).catch(() => null);
|
|
641
|
+
const first = await status();
|
|
642
|
+
if (!first?.installed) return;
|
|
643
|
+
if (first.t3?.state === "send") {
|
|
644
|
+
ui.success(`T3 Code ${pc.dim(`· ${t3Line(first.t3).line}`)}`);
|
|
645
|
+
return;
|
|
646
|
+
}
|
|
647
|
+
ui.step(
|
|
648
|
+
`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")}`
|
|
649
|
+
);
|
|
650
|
+
if (first.t3?.state === "read") ui.info(t3Line(first.t3).line);
|
|
651
|
+
if (first.t3?.state === "expired")
|
|
652
|
+
ui.info("Harness's approval in T3 Code ran out.");
|
|
653
|
+
if (!ui.interactive) {
|
|
654
|
+
ui.info(T3_LATER);
|
|
655
|
+
return;
|
|
656
|
+
}
|
|
657
|
+
const approve = await ui.select({
|
|
658
|
+
message: "Approve Harness in T3 Code?",
|
|
659
|
+
options: [
|
|
660
|
+
{
|
|
661
|
+
value: "approve",
|
|
662
|
+
label: "Approve it",
|
|
663
|
+
hint: "you need a pairing code from T3 Code",
|
|
664
|
+
},
|
|
665
|
+
{ value: "skip", label: "Not now" },
|
|
666
|
+
],
|
|
667
|
+
});
|
|
668
|
+
if (approve !== "approve") {
|
|
669
|
+
ui.info(`Skipped. ${T3_LATER}`);
|
|
670
|
+
return;
|
|
671
|
+
}
|
|
672
|
+
for (;;) {
|
|
673
|
+
const before = (await status())?.t3 ?? null;
|
|
674
|
+
const started = await daemonRequest({ command: "t3.connect" }, 20_000);
|
|
675
|
+
if (!started.ok) {
|
|
676
|
+
ui.warn(started.error || "Harness could not start the approval.");
|
|
677
|
+
if (started.code !== "not_running") {
|
|
678
|
+
ui.info(T3_LATER);
|
|
679
|
+
return;
|
|
680
|
+
}
|
|
681
|
+
const next = await ui.select({
|
|
682
|
+
message: "When T3 Code is open",
|
|
683
|
+
options: [
|
|
684
|
+
{ value: "check", label: "Check again" },
|
|
685
|
+
{ value: "skip", label: "Skip for now" },
|
|
686
|
+
],
|
|
687
|
+
});
|
|
688
|
+
if (next !== "check") {
|
|
689
|
+
ui.info(`Skipped. ${T3_LATER}`);
|
|
690
|
+
return;
|
|
691
|
+
}
|
|
692
|
+
continue;
|
|
693
|
+
}
|
|
694
|
+
const opened = open(started.url);
|
|
695
|
+
ui.note(
|
|
696
|
+
[
|
|
697
|
+
"1. In T3 Code, open Settings, then Connections, and copy a pairing code.",
|
|
698
|
+
opened
|
|
699
|
+
? "2. Paste it on the page that just opened in your browser."
|
|
700
|
+
: `2. Open this page in a browser on this computer and paste it there:\n${started.url}`,
|
|
701
|
+
"3. Choose what Harness may do. To message threads that run in Full access, choose Full access.",
|
|
702
|
+
].join("\n"),
|
|
703
|
+
"Approve Harness in T3 Code"
|
|
704
|
+
);
|
|
705
|
+
let settled = false;
|
|
706
|
+
const approved = waitFor(async () => {
|
|
707
|
+
if (settled) return true;
|
|
708
|
+
const now = (await status())?.t3 ?? null;
|
|
709
|
+
return Boolean(now) && JSON.stringify(now) !== JSON.stringify(before);
|
|
710
|
+
}).then(async (changed) =>
|
|
711
|
+
changed ? t3Line((await status())?.t3) : t3Line(null)
|
|
712
|
+
);
|
|
713
|
+
const answer = await ui.waitOrType({
|
|
714
|
+
message: "Waiting for your approval in T3 Code",
|
|
715
|
+
placeholder: "press Esc to stop waiting",
|
|
716
|
+
until: approved,
|
|
717
|
+
});
|
|
718
|
+
if (answer.cancelled) {
|
|
719
|
+
settled = true;
|
|
720
|
+
ui.info(
|
|
721
|
+
`Stopped waiting. Approving it on that page still counts. ${T3_LATER}`
|
|
722
|
+
);
|
|
723
|
+
return;
|
|
724
|
+
}
|
|
725
|
+
let outcome = answer.done;
|
|
726
|
+
if (!outcome) {
|
|
727
|
+
const spin = ui.spinner();
|
|
728
|
+
spin.start("Waiting for your approval in T3 Code");
|
|
729
|
+
outcome = await approved;
|
|
730
|
+
spin.stop(outcome.line, outcome.ok ? 0 : 2);
|
|
731
|
+
}
|
|
732
|
+
settled = true;
|
|
733
|
+
if ((await status())?.t3?.state !== "read") return;
|
|
734
|
+
const again = await ui.select({
|
|
735
|
+
message: "Approve it again with more access?",
|
|
736
|
+
options: [
|
|
737
|
+
{ value: "again", label: "Approve it again" },
|
|
738
|
+
{ value: "keep", label: "Keep read only" },
|
|
739
|
+
],
|
|
740
|
+
});
|
|
741
|
+
if (again !== "again") return;
|
|
742
|
+
}
|
|
743
|
+
}
|
|
744
|
+
|
|
745
|
+
const mark = (entry) =>
|
|
746
|
+
entry.inSwarm
|
|
747
|
+
? pc.green("✓")
|
|
748
|
+
: entry.state === "not_installed"
|
|
749
|
+
? pc.dim("–")
|
|
750
|
+
: pc.dim("+");
|
|
751
|
+
|
|
752
|
+
/** `npx tryharness agents`: who is in the swarm, and who can be added. */
|
|
753
|
+
export async function showLineup({ daemonRequest, ui = createUi() }) {
|
|
754
|
+
const lineup = await daemonRequest({ command: "swarm.lineup" });
|
|
755
|
+
if (!lineup?.ok) {
|
|
756
|
+
ui.warn(
|
|
757
|
+
lineup?.error || "Harness is not running here. Run: npx tryharness"
|
|
758
|
+
);
|
|
759
|
+
return;
|
|
760
|
+
}
|
|
761
|
+
const rows = lineup.agents.map(
|
|
762
|
+
(entry) =>
|
|
763
|
+
`${mark(entry)} ${entry.name}${entry.inSwarm ? "" : pc.dim(` ${entry.hint ?? "can be added"}`)}`
|
|
764
|
+
);
|
|
765
|
+
ui.step(
|
|
766
|
+
`Your swarm ${pc.dim("· ✓ in it, + can be added")}\n${rows.join("\n")}`
|
|
767
|
+
);
|
|
768
|
+
ui.info(ADD_LATER);
|
|
769
|
+
}
|
|
770
|
+
|
|
771
|
+
/**
|
|
772
|
+
* `npx tryharness agents add [agent…]`: put agents in the swarm. Without names it offers every agent that can be added
|
|
773
|
+
* now, ticked by the person. Grok Bot goes on to its wake setup; Muse is set up in Harness.
|
|
774
|
+
*/
|
|
775
|
+
export async function addAgents({
|
|
776
|
+
daemonRequest,
|
|
777
|
+
wanted = [],
|
|
778
|
+
ui = createUi(),
|
|
779
|
+
clipboard = copy,
|
|
780
|
+
}) {
|
|
781
|
+
const lineup = await daemonRequest({ command: "swarm.lineup" });
|
|
782
|
+
if (!lineup?.ok) {
|
|
783
|
+
ui.warn(
|
|
784
|
+
lineup?.error || "Harness is not running here. Run: npx tryharness"
|
|
785
|
+
);
|
|
786
|
+
return false;
|
|
787
|
+
}
|
|
788
|
+
const byId = new Map(lineup.agents.map((entry) => [entry.id, entry]));
|
|
789
|
+
const open = lineup.agents.filter(
|
|
790
|
+
(entry) => !entry.inSwarm && entry.state !== "not_installed"
|
|
791
|
+
);
|
|
792
|
+
let picked = wanted;
|
|
793
|
+
if (!picked.length) {
|
|
794
|
+
const missing = lineup.agents.filter(
|
|
795
|
+
(entry) => !entry.inSwarm && entry.state === "not_installed"
|
|
796
|
+
);
|
|
797
|
+
if (missing.length)
|
|
798
|
+
ui.message(
|
|
799
|
+
pc.dim(
|
|
800
|
+
`Not on this computer: ${missing.map((entry) => entry.name).join(", ")}. Install one, then add it here.`
|
|
801
|
+
)
|
|
802
|
+
);
|
|
803
|
+
if (!open.length) {
|
|
804
|
+
ui.success("Every agent you can add is already in your swarm.");
|
|
805
|
+
return true;
|
|
806
|
+
}
|
|
807
|
+
if (!ui.interactive) {
|
|
808
|
+
ui.info(
|
|
809
|
+
`Can be added: ${open.map((entry) => entry.id).join(", ")}. Run: npx tryharness agents add <agent>`
|
|
810
|
+
);
|
|
811
|
+
return true;
|
|
812
|
+
}
|
|
813
|
+
picked =
|
|
814
|
+
(await ui.multiselect({
|
|
815
|
+
message: `Which agents join your swarm? ${pc.dim("(space to tick, enter to go on)")}`,
|
|
816
|
+
options: open.map((entry) => ({
|
|
817
|
+
value: entry.id,
|
|
818
|
+
label: entry.name,
|
|
819
|
+
hint: entry.hint ?? undefined,
|
|
820
|
+
})),
|
|
821
|
+
})) ?? [];
|
|
822
|
+
}
|
|
823
|
+
let ok = true;
|
|
824
|
+
for (const id of picked) {
|
|
825
|
+
const entry = byId.get(id);
|
|
826
|
+
if (entry?.inSwarm) {
|
|
827
|
+
ui.success(`${entry.name} is already in your swarm.`);
|
|
828
|
+
continue;
|
|
829
|
+
}
|
|
830
|
+
const added = await daemonRequest({ command: "swarm.add", target: id });
|
|
831
|
+
if (!added?.ok) {
|
|
832
|
+
ok = false;
|
|
833
|
+
ui.warn(added?.error || `${entry?.name ?? id} could not be added.`);
|
|
834
|
+
continue;
|
|
835
|
+
}
|
|
836
|
+
ui.success(
|
|
837
|
+
`${added.name} is in your swarm${added.signedOut ? `. Sign in to ${added.name} before it takes work` : ""}.`
|
|
838
|
+
);
|
|
839
|
+
if (id === "grok-bot") await setupGrok({ ui, daemonRequest, clipboard });
|
|
840
|
+
if (id === "muse")
|
|
841
|
+
ui.info(
|
|
842
|
+
"Muse takes work once it is set up in Harness: open the dashboard, then Agents, then Muse."
|
|
843
|
+
);
|
|
844
|
+
}
|
|
845
|
+
return ok;
|
|
846
|
+
}
|
|
847
|
+
|
|
848
|
+
/** `npx tryharness agents remove <agent>`: out of the swarm; nothing on the computer is uninstalled. */
|
|
849
|
+
export async function removeAgent({ daemonRequest, agent, ui = createUi() }) {
|
|
850
|
+
const removed = await daemonRequest({
|
|
851
|
+
command: "swarm.remove",
|
|
852
|
+
target: agent,
|
|
853
|
+
});
|
|
854
|
+
if (!removed?.ok) {
|
|
855
|
+
ui.warn(removed?.error || `${agent} could not be removed.`);
|
|
856
|
+
return false;
|
|
857
|
+
}
|
|
858
|
+
ui.success(
|
|
859
|
+
`${removed.name} is out of your swarm. Add it back any time: npx tryharness agents add ${agent}`
|
|
860
|
+
);
|
|
861
|
+
return true;
|
|
862
|
+
}
|
|
@@ -0,0 +1,150 @@
|
|
|
1
|
+
// 1claw's local vault: its file format and its host rule, so the vault the relay keeps is a 1claw vault. Taken from
|
|
2
|
+
// the 1claw CLI (github.com/1clawAI/1claw-cli at 8200aee82e, src/local-vault.ts and src/local-policy.ts) under its MIT
|
|
3
|
+
// license:
|
|
4
|
+
//
|
|
5
|
+
// MIT License. Copyright (c) 2026 1Claw Contributors.
|
|
6
|
+
// Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
|
|
7
|
+
// documentation files (the "Software"), to deal in the Software without restriction, including without limitation
|
|
8
|
+
// the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and
|
|
9
|
+
// to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above
|
|
10
|
+
// copyright notice and this permission notice shall be included in all copies or substantial portions of the
|
|
11
|
+
// Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT
|
|
12
|
+
// LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT
|
|
13
|
+
// SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
|
|
14
|
+
// CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
|
|
15
|
+
// IN THE SOFTWARE.
|
|
16
|
+
//
|
|
17
|
+
// Changes from theirs: the key derivation runs off the event loop (the daemon answers everyone while it saves), the
|
|
18
|
+
// passphrase is a random key the relay keeps rather than one a person types, and a host rule may name a port (a
|
|
19
|
+
// local service is told apart from another on the same computer only by its port).
|
|
20
|
+
import {
|
|
21
|
+
createCipheriv,
|
|
22
|
+
createDecipheriv,
|
|
23
|
+
randomBytes,
|
|
24
|
+
scrypt,
|
|
25
|
+
pbkdf2,
|
|
26
|
+
} from "node:crypto";
|
|
27
|
+
import { promisify } from "node:util";
|
|
28
|
+
|
|
29
|
+
const scryptAsync = promisify(scrypt);
|
|
30
|
+
const pbkdf2Async = promisify(pbkdf2);
|
|
31
|
+
|
|
32
|
+
const ALGORITHM = "aes-256-gcm";
|
|
33
|
+
const IV_LENGTH = 12;
|
|
34
|
+
const TAG_LENGTH = 16;
|
|
35
|
+
const SALT_LENGTH = 16;
|
|
36
|
+
// Version 1 files (PBKDF2-SHA256, 100k rounds) still open; every write is version 2 (scrypt N=2^17, r=8).
|
|
37
|
+
const FILE_VERSION_PBKDF2 = 1;
|
|
38
|
+
const FILE_VERSION = 2;
|
|
39
|
+
const SCRYPT = { N: 1 << 17, r: 8, p: 1, maxmem: 256 * 1024 * 1024 };
|
|
40
|
+
|
|
41
|
+
const deriveKey = (passphrase, salt, version) =>
|
|
42
|
+
version === FILE_VERSION_PBKDF2
|
|
43
|
+
? pbkdf2Async(passphrase, salt, 100_000, 32, "sha256")
|
|
44
|
+
: scryptAsync(passphrase, salt, 32, SCRYPT);
|
|
45
|
+
|
|
46
|
+
/** A new, empty vault as 1claw writes one. */
|
|
47
|
+
export function emptyVault() {
|
|
48
|
+
const now = new Date().toISOString();
|
|
49
|
+
return {
|
|
50
|
+
version: FILE_VERSION,
|
|
51
|
+
created_at: now,
|
|
52
|
+
updated_at: now,
|
|
53
|
+
secrets: {},
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
/** The vault encrypted: [version:1][salt:16][iv:12][tag:16][ciphertext]. */
|
|
58
|
+
export async function sealVaultFile(vault, passphrase) {
|
|
59
|
+
const salt = randomBytes(SALT_LENGTH);
|
|
60
|
+
const key = await deriveKey(passphrase, salt, FILE_VERSION);
|
|
61
|
+
const iv = randomBytes(IV_LENGTH);
|
|
62
|
+
const cipher = createCipheriv(ALGORITHM, key, iv);
|
|
63
|
+
const plaintext = JSON.stringify({
|
|
64
|
+
...vault,
|
|
65
|
+
updated_at: new Date().toISOString(),
|
|
66
|
+
});
|
|
67
|
+
const encrypted = Buffer.concat([
|
|
68
|
+
cipher.update(plaintext, "utf8"),
|
|
69
|
+
cipher.final(),
|
|
70
|
+
]);
|
|
71
|
+
return Buffer.concat([
|
|
72
|
+
Buffer.from([FILE_VERSION]),
|
|
73
|
+
salt,
|
|
74
|
+
iv,
|
|
75
|
+
cipher.getAuthTag(),
|
|
76
|
+
encrypted,
|
|
77
|
+
]);
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
/** The vault in a file sealVaultFile (or 1claw's own CLI) wrote; throws when the key is wrong or the file damaged. */
|
|
81
|
+
export async function openVaultFile(data, passphrase) {
|
|
82
|
+
const version = data[0];
|
|
83
|
+
if (version !== FILE_VERSION && version !== FILE_VERSION_PBKDF2)
|
|
84
|
+
throw new Error(`Unsupported vault file version: ${version}`);
|
|
85
|
+
let offset = 1;
|
|
86
|
+
const salt = data.subarray(offset, (offset += SALT_LENGTH));
|
|
87
|
+
const iv = data.subarray(offset, (offset += IV_LENGTH));
|
|
88
|
+
const tag = data.subarray(offset, (offset += TAG_LENGTH));
|
|
89
|
+
const key = await deriveKey(passphrase, salt, version);
|
|
90
|
+
const decipher = createDecipheriv(ALGORITHM, key, iv);
|
|
91
|
+
decipher.setAuthTag(tag);
|
|
92
|
+
const plaintext = Buffer.concat([
|
|
93
|
+
decipher.update(data.subarray(offset)),
|
|
94
|
+
decipher.final(),
|
|
95
|
+
]);
|
|
96
|
+
return JSON.parse(plaintext.toString("utf8"));
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
/** A secret saved or changed, keeping when it was first saved; a change is not yet in any cloud copy. */
|
|
100
|
+
export function putSecret(vault, name, value, type, extra = {}) {
|
|
101
|
+
const now = new Date().toISOString();
|
|
102
|
+
const previous = vault.secrets[name];
|
|
103
|
+
vault.secrets[name] = {
|
|
104
|
+
...previous,
|
|
105
|
+
...extra,
|
|
106
|
+
value,
|
|
107
|
+
type,
|
|
108
|
+
created_at: previous?.created_at ?? now,
|
|
109
|
+
updated_at: now,
|
|
110
|
+
synced_to_cloud: false,
|
|
111
|
+
cloud_vault_id: previous?.cloud_vault_id ?? null,
|
|
112
|
+
cloud_path: previous?.cloud_path ?? null,
|
|
113
|
+
};
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
/**
|
|
117
|
+
* Whether a request to `targetUrl` may carry a secret allowed only at `hosts`. Fail closed: no hosts, no request.
|
|
118
|
+
* A rule is a host name (`api.fly.io`), a host name with its port (`127.0.0.1:8787`), or `*.` and a domain.
|
|
119
|
+
*/
|
|
120
|
+
export function hostAllowed(hosts, targetUrl) {
|
|
121
|
+
let url;
|
|
122
|
+
try {
|
|
123
|
+
url = new URL(targetUrl);
|
|
124
|
+
} catch {
|
|
125
|
+
return { allowed: false, reason: `"${targetUrl}" is not a URL.` };
|
|
126
|
+
}
|
|
127
|
+
const hostname = url.hostname.toLowerCase();
|
|
128
|
+
const withPort = url.port ? `${hostname}:${url.port}` : hostname;
|
|
129
|
+
if (!hosts?.length)
|
|
130
|
+
return {
|
|
131
|
+
allowed: false,
|
|
132
|
+
reason: "No website is named for this secret yet.",
|
|
133
|
+
};
|
|
134
|
+
for (const pattern of hosts.map((host) => String(host).toLowerCase())) {
|
|
135
|
+
if (pattern.startsWith("*.")) {
|
|
136
|
+
// "*.example.com:8443" names the port too; without one, any port.
|
|
137
|
+
const [suffix, port] = pattern.slice(2).split(":");
|
|
138
|
+
if (
|
|
139
|
+
(hostname === suffix || hostname.endsWith(`.${suffix}`)) &&
|
|
140
|
+
(!port || port === url.port)
|
|
141
|
+
)
|
|
142
|
+
return { allowed: true };
|
|
143
|
+
} else if (pattern === hostname || pattern === withPort)
|
|
144
|
+
return { allowed: true };
|
|
145
|
+
}
|
|
146
|
+
return {
|
|
147
|
+
allowed: false,
|
|
148
|
+
reason: `It may only go to ${hosts.join(", ")}, not ${withPort}.`,
|
|
149
|
+
};
|
|
150
|
+
}
|