tryharness 0.7.44 → 0.7.53
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 +232 -12
- package/cli.mjs +406 -184
- package/lib/actorRoster.mjs +28 -5
- package/lib/adapters.mjs +9 -1
- package/lib/agentRuntimeConfig.mjs +36 -0
- package/lib/agentRuntimes.mjs +560 -0
- package/lib/atlas.mjs +7 -2
- package/lib/boardCommands.mjs +5 -10
- package/lib/boardFileCommands.mjs +2 -1
- package/lib/boardMirror.mjs +459 -0
- package/lib/boardProtocol.json +259 -6
- package/lib/boardTools.mjs +2 -6
- package/lib/bridge.mjs +27 -3
- package/lib/browserWake.mjs +60 -0
- package/lib/cards.mjs +35 -2
- package/lib/commands.mjs +20 -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/coordinator.mjs +16 -2
- package/lib/coreModels.mjs +78 -0
- package/lib/daemon.mjs +775 -46
- package/lib/desktop.mjs +7 -2
- package/lib/digest.mjs +32 -0
- package/lib/directLink.mjs +283 -0
- package/lib/environments.mjs +595 -0
- package/lib/folders.mjs +2 -2
- package/lib/goalCommands.mjs +61 -12
- package/lib/inference.mjs +263 -152
- package/lib/lessons.mjs +6 -0
- package/lib/lineup.mjs +324 -0
- 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 +180 -98
- package/lib/mcpRelay.mjs +119 -0
- package/lib/members.json +12 -0
- package/lib/members.mjs +33 -0
- package/lib/modelMemory.mjs +100 -0
- package/lib/modelTiers.json +1183 -0
- package/lib/modelTiers.mjs +133 -0
- package/lib/models.mjs +41 -8
- package/lib/museSession.mjs +119 -0
- package/lib/nativeHost.mjs +203 -0
- package/lib/network.mjs +38 -1
- package/lib/nudge.mjs +10 -2
- package/lib/onboard.mjs +430 -1
- package/lib/oneclawLocal.mjs +150 -0
- package/lib/ownMachines.mjs +521 -36
- package/lib/pairing.mjs +165 -0
- package/lib/paths.mjs +4 -0
- package/lib/phones.mjs +61 -0
- package/lib/placeCommands.mjs +27 -0
- package/lib/places.mjs +10 -2
- package/lib/plans.mjs +151 -27
- package/lib/profile.mjs +152 -0
- package/lib/projectGit.mjs +328 -0
- package/lib/projectSettings.mjs +120 -0
- package/lib/projects.mjs +2539 -0
- package/lib/readiness.mjs +283 -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 +20 -7
- package/lib/runner.mjs +67 -8
- 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 +10 -8
- package/lib/sessionIndex.mjs +5 -3
- package/lib/store.mjs +559 -30
- package/lib/subagents.mjs +8 -4
- package/lib/swarm.mjs +379 -38
- package/lib/swarmMemory.mjs +947 -0
- package/lib/t3.mjs +43 -13
- package/lib/taskCommands.mjs +58 -5
- package/lib/taskRuns.mjs +61 -11
- package/lib/team.json +17 -15
- package/lib/team.mjs +68 -18
- package/lib/threadRuns.mjs +50 -7
- package/lib/threadView.mjs +68 -15
- 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/package.json +9 -4
package/lib/mcp-stdio.mjs
CHANGED
|
@@ -1,17 +1,30 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
import fs from "node:fs";
|
|
3
|
-
import
|
|
3
|
+
import { CONNECTION_TOOL, connectionRequest } from "./connectionTools.js";
|
|
4
|
+
import { USE_SECRET_TOOL, secretToolRequest } from "./vaultTools.js";
|
|
4
5
|
import { paths } from "./paths.mjs";
|
|
5
6
|
import { readJson } from "./files.mjs";
|
|
6
7
|
import { daemonRequest } from "./control-client.mjs";
|
|
8
|
+
import { WAKE_DEADLINE_MS } from "./windowAsks.mjs";
|
|
9
|
+
import {
|
|
10
|
+
generatedPath,
|
|
11
|
+
MCP_CALL_DEADLINE_MS,
|
|
12
|
+
RELAY_NOT_RUNNING,
|
|
13
|
+
} from "./mcpRelay.mjs";
|
|
7
14
|
import { boardNudge, HANDSHAKE_LIMIT } from "./nudge.mjs";
|
|
8
15
|
|
|
9
16
|
const agentIndex = process.argv.indexOf("--agent");
|
|
10
17
|
const agent = agentIndex >= 0 ? process.argv[agentIndex + 1] : "codex";
|
|
18
|
+
// The connection tool (the person's connected apps, connectors.mjs) is offered only once the person turned Apps on
|
|
19
|
+
// (`tryharness connections on`), and never to a restricted run: work another agent or another person's swarm asked
|
|
20
|
+
// for runs without the person's apps (runner.mjs restrictedMcpConfig).
|
|
21
|
+
const restricted = process.argv.includes("--restricted");
|
|
22
|
+
const appsOn = !restricted && readJson(paths.config, {}).connectedApps === true;
|
|
11
23
|
let input = "";
|
|
12
24
|
let chain = Promise.resolve();
|
|
13
25
|
|
|
14
26
|
const LOCAL_TOOLS = [
|
|
27
|
+
...(appsOn ? [CONNECTION_TOOL] : []),
|
|
15
28
|
{
|
|
16
29
|
name: "list_tasks",
|
|
17
30
|
description:
|
|
@@ -387,49 +400,98 @@ const LOCAL_TOOLS = [
|
|
|
387
400
|
},
|
|
388
401
|
},
|
|
389
402
|
{
|
|
390
|
-
name: "
|
|
403
|
+
name: "plan_work",
|
|
391
404
|
description:
|
|
392
|
-
"
|
|
405
|
+
"In a project shared with another person's swarm: say what you plan to build before you change code for it (summary, and the files or interfaces it touches), or that your piece is done. Your plan is checked against what the two people decided and the other side's work; the answer says whether to go ahead, or that it clashes and waits until the two sides agree a fix.",
|
|
393
406
|
inputSchema: {
|
|
394
407
|
type: "object",
|
|
395
408
|
properties: {
|
|
396
|
-
id: { type: "string", description: "the
|
|
397
|
-
|
|
409
|
+
id: { type: "string", description: "the thread id" },
|
|
410
|
+
summary: {
|
|
411
|
+
type: "string",
|
|
412
|
+
description: "what you will build, in a sentence or two",
|
|
413
|
+
},
|
|
414
|
+
touches: {
|
|
415
|
+
type: "array",
|
|
416
|
+
items: { type: "string" },
|
|
417
|
+
description: "the files, modules or interfaces it changes",
|
|
418
|
+
},
|
|
419
|
+
done: {
|
|
420
|
+
type: "boolean",
|
|
421
|
+
description: "true when your piece is ready to merge",
|
|
422
|
+
},
|
|
423
|
+
stopped: {
|
|
424
|
+
type: "boolean",
|
|
425
|
+
description: "true when you are dropping this piece",
|
|
426
|
+
},
|
|
398
427
|
},
|
|
399
|
-
required: ["id"
|
|
428
|
+
required: ["id"],
|
|
400
429
|
additionalProperties: false,
|
|
401
430
|
},
|
|
402
431
|
},
|
|
403
432
|
{
|
|
404
|
-
name: "
|
|
433
|
+
name: "propose",
|
|
405
434
|
description:
|
|
406
|
-
"
|
|
435
|
+
"In a project shared with another person's swarm: propose how two clashing pieces of work fit together, or a decision for the project (an interface, a rule, a split of the work). Agree it with the other agent in the thread first. A person OKs it before it counts: both people for a decision, the owner of each piece of work for a fix.",
|
|
407
436
|
inputSchema: {
|
|
408
437
|
type: "object",
|
|
409
438
|
properties: {
|
|
410
439
|
id: { type: "string", description: "the thread id" },
|
|
411
440
|
text: {
|
|
412
441
|
type: "string",
|
|
413
|
-
description: "what you
|
|
442
|
+
description: "what you propose, in plain words",
|
|
414
443
|
},
|
|
415
|
-
|
|
416
|
-
|
|
444
|
+
about: {
|
|
445
|
+
type: "array",
|
|
446
|
+
items: { type: "string" },
|
|
447
|
+
description: "the work ids this settles (from the clash post)",
|
|
448
|
+
},
|
|
449
|
+
changes: {
|
|
450
|
+
type: "array",
|
|
451
|
+
items: { type: "string" },
|
|
452
|
+
description:
|
|
453
|
+
"the work ids whose plan changes under this proposal; their owners OK it",
|
|
454
|
+
},
|
|
455
|
+
decision: {
|
|
417
456
|
type: "string",
|
|
418
|
-
description:
|
|
457
|
+
description:
|
|
458
|
+
"a decision both people OK, when this changes or adds to what they decided",
|
|
419
459
|
},
|
|
420
460
|
},
|
|
421
|
-
required: ["id", "text"
|
|
461
|
+
required: ["id", "text"],
|
|
422
462
|
additionalProperties: false,
|
|
423
463
|
},
|
|
424
464
|
},
|
|
425
465
|
{
|
|
426
|
-
name: "
|
|
466
|
+
name: "swarm_memory",
|
|
427
467
|
description:
|
|
428
|
-
"
|
|
468
|
+
"The swarm's shared memory: read it, or add to it, in one call. To read, give `search`: what any of the person's agents wrote in any thread (findings, answers, results, checked receipts), what the swarm kept from its work, what agents added here, and the person's coding sessions on this computer; with `thread`, only that thread. Search before starting work, to build on what another agent already did. To add what you learned doing your part in a thread (a trap, a check that matters, how the code really works), give `remember` with `why` (what showed it) and `thread`: every agent of the person's swarm, on any of their computers, gets it from this tool and in briefs for work it bears on, marked as yours and unchecked until later work bears it out. `replaces` names an earlier note of yours it replaces. A note holding a secret or reading like orders to agents is refused. Give `search` or `remember`, not both.",
|
|
429
469
|
inputSchema: {
|
|
430
470
|
type: "object",
|
|
431
|
-
properties: {
|
|
432
|
-
|
|
471
|
+
properties: {
|
|
472
|
+
search: {
|
|
473
|
+
type: "string",
|
|
474
|
+
description: "what you are looking for, in words",
|
|
475
|
+
},
|
|
476
|
+
remember: {
|
|
477
|
+
type: "string",
|
|
478
|
+
description: "what you learned, in one or two sentences",
|
|
479
|
+
},
|
|
480
|
+
why: {
|
|
481
|
+
type: "string",
|
|
482
|
+
description: "why it holds: what showed it (with remember)",
|
|
483
|
+
},
|
|
484
|
+
thread: {
|
|
485
|
+
type: "string",
|
|
486
|
+
description:
|
|
487
|
+
"a thread (goal) id: the one you learned it in (with remember), or the only one to search",
|
|
488
|
+
},
|
|
489
|
+
replaces: {
|
|
490
|
+
type: "string",
|
|
491
|
+
description:
|
|
492
|
+
"the id of an earlier note of yours this one replaces (with remember)",
|
|
493
|
+
},
|
|
494
|
+
},
|
|
433
495
|
additionalProperties: false,
|
|
434
496
|
},
|
|
435
497
|
},
|
|
@@ -661,6 +723,8 @@ const LOCAL_TOOLS = [
|
|
|
661
723
|
additionalProperties: false,
|
|
662
724
|
},
|
|
663
725
|
},
|
|
726
|
+
// The person's secrets (vault.mjs): used through the daemon, never read. Not for a restricted run, like the apps.
|
|
727
|
+
...(restricted ? [] : [USE_SECRET_TOOL]),
|
|
664
728
|
];
|
|
665
729
|
|
|
666
730
|
const postTask = (args) => ({
|
|
@@ -681,6 +745,7 @@ const postTask = (args) => ({
|
|
|
681
745
|
});
|
|
682
746
|
|
|
683
747
|
const BOARD_CALLS = {
|
|
748
|
+
connection: connectionRequest,
|
|
684
749
|
list_agents: () => ({ command: "board.swarm.agents" }),
|
|
685
750
|
list_models: (args) => ({
|
|
686
751
|
command: "board.swarm.models",
|
|
@@ -709,22 +774,44 @@ const BOARD_CALLS = {
|
|
|
709
774
|
ask: Array.isArray(args.ask) ? args.ask : [],
|
|
710
775
|
shareWithGuests: args.share_with_guests === true,
|
|
711
776
|
}),
|
|
712
|
-
|
|
713
|
-
command: "board.
|
|
777
|
+
plan_work: (args) => ({
|
|
778
|
+
command: "board.project.plan",
|
|
714
779
|
id: String(args.id || ""),
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
|
|
780
|
+
summary: args.summary,
|
|
781
|
+
touches: Array.isArray(args.touches) ? args.touches : undefined,
|
|
782
|
+
done: args.done === true,
|
|
783
|
+
stopped: args.stopped === true,
|
|
718
784
|
}),
|
|
719
|
-
|
|
720
|
-
command: "board.
|
|
785
|
+
propose: (args) => ({
|
|
786
|
+
command: "board.project.propose",
|
|
721
787
|
id: String(args.id || ""),
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
query: args.query,
|
|
788
|
+
text: args.text,
|
|
789
|
+
about: Array.isArray(args.about) ? args.about : [],
|
|
790
|
+
changes: Array.isArray(args.changes) ? args.changes : [],
|
|
791
|
+
decision: args.decision ?? null,
|
|
727
792
|
}),
|
|
793
|
+
// One tool for the swarm's memory, so an agent never weighs which of several near-identical tools to call (owner,
|
|
794
|
+
// October 22: "one tool"): `remember` adds a note (board.room.learn), `search` reads the whole swarm's memory, or
|
|
795
|
+
// one thread's with `thread`.
|
|
796
|
+
swarm_memory: (args) => {
|
|
797
|
+
const thread = String(args.thread || "");
|
|
798
|
+
if (Boolean(args.search) === Boolean(args.remember))
|
|
799
|
+
return {
|
|
800
|
+
error:
|
|
801
|
+
"give search to read the swarm's memory, or remember to add to it",
|
|
802
|
+
};
|
|
803
|
+
if (args.remember)
|
|
804
|
+
return {
|
|
805
|
+
command: "board.room.learn",
|
|
806
|
+
id: thread,
|
|
807
|
+
text: args.remember,
|
|
808
|
+
reason: args.why,
|
|
809
|
+
replaces: args.replaces ?? null,
|
|
810
|
+
};
|
|
811
|
+
return thread
|
|
812
|
+
? { command: "board.room.search", id: thread, query: args.search }
|
|
813
|
+
: { command: "board.swarm.search", query: args.search };
|
|
814
|
+
},
|
|
728
815
|
compare_screens: (args) => ({
|
|
729
816
|
command: "board.screens.compare",
|
|
730
817
|
before: args.before,
|
|
@@ -826,6 +913,13 @@ const BOARD_CALLS = {
|
|
|
826
913
|
rooms: true,
|
|
827
914
|
}),
|
|
828
915
|
get_task: (args) => ({ command: "board.get", id: String(args.id || "") }),
|
|
916
|
+
// The run this session serves, when the daemon started it (runner.mjs): a request for a secret waits in its thread.
|
|
917
|
+
use_secret: (args) => ({
|
|
918
|
+
...secretToolRequest(args),
|
|
919
|
+
...(process.env.HARNESS_RUN_ID
|
|
920
|
+
? { runId: process.env.HARNESS_RUN_ID }
|
|
921
|
+
: {}),
|
|
922
|
+
}),
|
|
829
923
|
wallet: (args) => ({
|
|
830
924
|
command: "board.wallet",
|
|
831
925
|
action: args.action,
|
|
@@ -957,20 +1051,16 @@ function write(message) {
|
|
|
957
1051
|
}
|
|
958
1052
|
|
|
959
1053
|
// Harness's generated media saved where this machine's agents can use it, under ~/.harness/files/generated.
|
|
960
|
-
const MEDIA_ROUTES = ["/api/mcp/media", "/api/mcp/file"];
|
|
961
1054
|
function saveGenerated(name, bytes) {
|
|
962
|
-
const
|
|
963
|
-
fs.mkdirSync(dir, { recursive: true });
|
|
964
|
-
const file = path.join(
|
|
965
|
-
dir,
|
|
966
|
-
path
|
|
967
|
-
.basename(name)
|
|
968
|
-
.replace(/[^\w.-]+/g, "-")
|
|
969
|
-
.replace(/^\.+/, "") || "harness-media"
|
|
970
|
-
);
|
|
1055
|
+
const file = generatedPath(name);
|
|
971
1056
|
fs.writeFileSync(file, bytes);
|
|
972
1057
|
return file;
|
|
973
1058
|
}
|
|
1059
|
+
// No daemon listening on this computer: nothing reaches Harness, as every call goes through it.
|
|
1060
|
+
const relayNotRunning = (error) =>
|
|
1061
|
+
error?.code === "ENOENT" || error?.code === "ECONNREFUSED";
|
|
1062
|
+
|
|
1063
|
+
// The daemon downloads it, streaming to disk, with this computer's key (mcpRelay.mjs).
|
|
974
1064
|
async function saveGeneratedMedia(request, download) {
|
|
975
1065
|
const config = readJson(paths.config, {});
|
|
976
1066
|
const reply = (body, isError = false) => ({
|
|
@@ -986,55 +1076,23 @@ async function saveGeneratedMedia(request, download) {
|
|
|
986
1076
|
{ ok: false, error: "Harness is not connected. Run: npx tryharness" },
|
|
987
1077
|
true
|
|
988
1078
|
);
|
|
989
|
-
let url;
|
|
990
1079
|
try {
|
|
991
|
-
|
|
992
|
-
|
|
993
|
-
|
|
994
|
-
}
|
|
995
|
-
// This computer's key goes only to its own Harness, and only for generated media.
|
|
996
|
-
if (
|
|
997
|
-
url.origin !== new URL(config.origin).origin ||
|
|
998
|
-
!MEDIA_ROUTES.includes(url.pathname)
|
|
999
|
-
)
|
|
1000
|
-
return reply(
|
|
1001
|
-
{ ok: false, error: "download must be a URL list_generated_media gave" },
|
|
1002
|
-
true
|
|
1080
|
+
const saved = await daemonRequest(
|
|
1081
|
+
{ command: "mcp.download", url: download },
|
|
1082
|
+
MCP_CALL_DEADLINE_MS
|
|
1003
1083
|
);
|
|
1004
|
-
|
|
1005
|
-
// The same deadline as every other call this server makes to Harness (relay below).
|
|
1006
|
-
const response = await fetch(url, {
|
|
1007
|
-
headers: { authorization: "Bearer " + config.token },
|
|
1008
|
-
signal: AbortSignal.timeout(90_000),
|
|
1009
|
-
});
|
|
1010
|
-
if (!response.ok)
|
|
1011
|
-
return reply(
|
|
1012
|
-
{ ok: false, error: `Harness answered ${response.status}` },
|
|
1013
|
-
true
|
|
1014
|
-
);
|
|
1015
|
-
const named =
|
|
1016
|
-
/filename="?([^";]+)"?/.exec(
|
|
1017
|
-
response.headers.get("content-disposition") || ""
|
|
1018
|
-
)?.[1] || url.pathname.split("/").filter(Boolean).at(-1);
|
|
1019
|
-
const bytes = Buffer.from(await response.arrayBuffer());
|
|
1020
|
-
return reply({
|
|
1021
|
-
ok: true,
|
|
1022
|
-
path: saveGenerated(named, bytes),
|
|
1023
|
-
mime: response.headers.get("content-type") || "",
|
|
1024
|
-
bytes: bytes.length,
|
|
1025
|
-
});
|
|
1084
|
+
return reply(saved, saved?.ok !== true);
|
|
1026
1085
|
} catch (error) {
|
|
1027
|
-
|
|
1028
|
-
|
|
1029
|
-
|
|
1030
|
-
);
|
|
1086
|
+
const reason = relayNotRunning(error)
|
|
1087
|
+
? RELAY_NOT_RUNNING
|
|
1088
|
+
: `the download failed: ${error.message}`;
|
|
1089
|
+
return reply({ ok: false, error: reason }, true);
|
|
1031
1090
|
}
|
|
1032
1091
|
}
|
|
1033
1092
|
|
|
1034
1093
|
const SEARCHES = [
|
|
1035
1094
|
"search_task_context",
|
|
1036
|
-
"
|
|
1037
|
-
"search_swarm",
|
|
1095
|
+
"swarm_memory",
|
|
1038
1096
|
"search_code",
|
|
1039
1097
|
"search_files",
|
|
1040
1098
|
"search_screen",
|
|
@@ -1049,6 +1107,12 @@ const MEDIA_DEADLINE_MS = 120_000;
|
|
|
1049
1107
|
/** How long a call waits for the daemon. */
|
|
1050
1108
|
function deadlineFor(name) {
|
|
1051
1109
|
if (name === "watch_video" || name === "listen") return MEDIA_DEADLINE_MS;
|
|
1110
|
+
// A website's answer takes what it takes and no deadline was measured for any (AGENTS.md): the agent's own call
|
|
1111
|
+
// deadline governs, and the daemon stops the website call when this one hangs up.
|
|
1112
|
+
if (name === "use_secret") return 0;
|
|
1113
|
+
// With no Harness window open, the computer wakes the hidden page and waits up to WAKE_DEADLINE_MS (the owner's one
|
|
1114
|
+
// minute), then the window answers within Harness's own deadline for it (src/server/bridge/sealedAsk.ts, 15 s).
|
|
1115
|
+
if (name === "search_screen") return WAKE_DEADLINE_MS + 15_000;
|
|
1052
1116
|
if (SEARCHES.includes(name)) return 20_000;
|
|
1053
1117
|
return 5_000;
|
|
1054
1118
|
}
|
|
@@ -1058,9 +1122,28 @@ async function localCall(request) {
|
|
|
1058
1122
|
const args = request.params?.arguments || {};
|
|
1059
1123
|
if (name === "save_generated_media")
|
|
1060
1124
|
return saveGeneratedMedia(request, args.download);
|
|
1125
|
+
const call = BOARD_CALLS[name](args);
|
|
1126
|
+
if (call.error)
|
|
1127
|
+
return {
|
|
1128
|
+
jsonrpc: "2.0",
|
|
1129
|
+
id: request.id,
|
|
1130
|
+
result: {
|
|
1131
|
+
content: [
|
|
1132
|
+
{
|
|
1133
|
+
type: "text",
|
|
1134
|
+
text: JSON.stringify({ ok: false, error: call.error }),
|
|
1135
|
+
},
|
|
1136
|
+
],
|
|
1137
|
+
isError: true,
|
|
1138
|
+
},
|
|
1139
|
+
};
|
|
1061
1140
|
try {
|
|
1062
1141
|
const result = await daemonRequest(
|
|
1063
|
-
{
|
|
1142
|
+
{
|
|
1143
|
+
...call,
|
|
1144
|
+
agent,
|
|
1145
|
+
...(restricted ? { restricted } : {}),
|
|
1146
|
+
},
|
|
1064
1147
|
deadlineFor(name)
|
|
1065
1148
|
);
|
|
1066
1149
|
if (name === "watch_video" && result?.ok)
|
|
@@ -1094,7 +1177,9 @@ async function localCall(request) {
|
|
|
1094
1177
|
content: [
|
|
1095
1178
|
{
|
|
1096
1179
|
type: "text",
|
|
1097
|
-
text:
|
|
1180
|
+
text: relayNotRunning(error)
|
|
1181
|
+
? RELAY_NOT_RUNNING
|
|
1182
|
+
: "Harness daemon unavailable: " + error.message,
|
|
1098
1183
|
},
|
|
1099
1184
|
],
|
|
1100
1185
|
isError: true,
|
|
@@ -1184,21 +1269,13 @@ async function relay(line) {
|
|
|
1184
1269
|
return;
|
|
1185
1270
|
}
|
|
1186
1271
|
try {
|
|
1187
|
-
|
|
1188
|
-
|
|
1189
|
-
{
|
|
1190
|
-
|
|
1191
|
-
// This server tells the agent who else is in the swarm itself (the handshake below), so Harness does not too.
|
|
1192
|
-
headers: {
|
|
1193
|
-
"content-type": "application/json",
|
|
1194
|
-
authorization: "Bearer " + config.token,
|
|
1195
|
-
"x-harness-swarm": "local",
|
|
1196
|
-
},
|
|
1197
|
-
body: JSON.stringify(request),
|
|
1198
|
-
signal: AbortSignal.timeout(90_000),
|
|
1199
|
-
}
|
|
1272
|
+
// Through this computer's daemon, which carries it to Harness on its own connection (mcpRelay.mjs).
|
|
1273
|
+
const answer = await daemonRequest(
|
|
1274
|
+
{ command: "mcp.call", rpc: request },
|
|
1275
|
+
MCP_CALL_DEADLINE_MS
|
|
1200
1276
|
);
|
|
1201
|
-
|
|
1277
|
+
if (!answer?.ok) throw new Error(answer?.error || "the relay refused");
|
|
1278
|
+
const body = String(answer.body ?? "");
|
|
1202
1279
|
if (!body.trim()) return;
|
|
1203
1280
|
const payload = JSON.parse(body);
|
|
1204
1281
|
// This computer's tools answer here (relay above), so the agent sees them as they work here: a file by its path.
|
|
@@ -1243,9 +1320,12 @@ async function relay(line) {
|
|
|
1243
1320
|
write(payload);
|
|
1244
1321
|
} catch (error) {
|
|
1245
1322
|
// Harness unreachable: the machine's own tools and queue still answer.
|
|
1323
|
+
const notRunning = relayNotRunning(error);
|
|
1246
1324
|
if (request.method === "initialize") {
|
|
1247
1325
|
const reply = localInitialize(request);
|
|
1248
|
-
reply.result.instructions = await handshakeInstructions(
|
|
1326
|
+
reply.result.instructions = await handshakeInstructions(
|
|
1327
|
+
notRunning ? RELAY_NOT_RUNNING : ""
|
|
1328
|
+
);
|
|
1249
1329
|
write(reply);
|
|
1250
1330
|
return;
|
|
1251
1331
|
}
|
|
@@ -1263,7 +1343,9 @@ async function relay(line) {
|
|
|
1263
1343
|
id: request.id,
|
|
1264
1344
|
error: {
|
|
1265
1345
|
code: -32000,
|
|
1266
|
-
message:
|
|
1346
|
+
message: notRunning
|
|
1347
|
+
? RELAY_NOT_RUNNING
|
|
1348
|
+
: "Harness is unreachable: " + error.message,
|
|
1267
1349
|
},
|
|
1268
1350
|
});
|
|
1269
1351
|
}
|
package/lib/mcpRelay.mjs
ADDED
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
import fs from "node:fs";
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
import { Readable } from "node:stream";
|
|
4
|
+
import { pipeline } from "node:stream/promises";
|
|
5
|
+
import { paths } from "./paths.mjs";
|
|
6
|
+
|
|
7
|
+
// How long an agent's call to Harness may take, end to end: the deadline every such call had when the agent's MCP
|
|
8
|
+
// server posted to /api/mcp itself (mcp-stdio.mjs before October 21), kept as it was, not measured again.
|
|
9
|
+
export const MCP_CALL_DEADLINE_MS = 90_000;
|
|
10
|
+
export const RELAY_NOT_RUNNING =
|
|
11
|
+
"Harness relay is not running on this computer: run npx tryharness";
|
|
12
|
+
// The only downloads this computer's key goes to: Harness's generated media and chat files.
|
|
13
|
+
const MEDIA_ROUTES = ["/api/mcp/media", "/api/mcp/file"];
|
|
14
|
+
|
|
15
|
+
/** Harness's generated media, saved where this machine's agents can use it: ~/.harness/files/generated. */
|
|
16
|
+
export function generatedPath(name) {
|
|
17
|
+
const dir = path.join(paths.files, "generated");
|
|
18
|
+
fs.mkdirSync(dir, { recursive: true });
|
|
19
|
+
const safeName =
|
|
20
|
+
path
|
|
21
|
+
.basename(name)
|
|
22
|
+
.replace(/[^\w.-]+/g, "-")
|
|
23
|
+
.replace(/^\.+/, "") || "harness-media";
|
|
24
|
+
return path.join(dir, safeName);
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* Everything an agent's MCP server asks of Harness goes through this daemon: a call rides the bridge's one
|
|
29
|
+
* authenticated connection and is answered by the same handler as /api/mcp, under the same token.
|
|
30
|
+
*/
|
|
31
|
+
export function createMcpRelay({ config, bridge, log }) {
|
|
32
|
+
const origin = String(config.origin).replace(/\/$/, "");
|
|
33
|
+
const authorization = "Bearer " + config.token;
|
|
34
|
+
|
|
35
|
+
// Straight to /api/mcp, from the daemon: while Harness has not said it carries calls on the bridge (an older
|
|
36
|
+
// Harness, or the moment between dialing and its server_features), and for a call whose browser session is held by
|
|
37
|
+
// another of Harness's servers, which only an HTTP request can be replayed to.
|
|
38
|
+
const postToHarness = async (rpc) => {
|
|
39
|
+
const response = await fetch(origin + "/api/mcp", {
|
|
40
|
+
method: "POST",
|
|
41
|
+
// This computer tells its agents who else is in the swarm itself (mcp-stdio.mjs), so Harness does not too.
|
|
42
|
+
headers: {
|
|
43
|
+
"content-type": "application/json",
|
|
44
|
+
authorization,
|
|
45
|
+
"x-harness-swarm": "local",
|
|
46
|
+
},
|
|
47
|
+
body: JSON.stringify(rpc),
|
|
48
|
+
signal: AbortSignal.timeout(MCP_CALL_DEADLINE_MS),
|
|
49
|
+
});
|
|
50
|
+
return { ok: true, status: response.status, body: await response.text() };
|
|
51
|
+
};
|
|
52
|
+
|
|
53
|
+
/** One JSON-RPC request to Harness's MCP server; the answer is its status and body as /api/mcp sends them. */
|
|
54
|
+
async function call(rpc) {
|
|
55
|
+
if (!bridge.has("mcp_call")) return postToHarness(rpc);
|
|
56
|
+
const answer = await bridge.ask("mcp_call", { rpc }, MCP_CALL_DEADLINE_MS);
|
|
57
|
+
if (!answer.ok) return answer;
|
|
58
|
+
if (answer.replay) return postToHarness(rpc);
|
|
59
|
+
return { ok: true, status: answer.status, body: answer.body };
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
/** A generated file list_generated_media named, streamed to disk; the answer is what the agent is told. */
|
|
63
|
+
async function download(link) {
|
|
64
|
+
let url;
|
|
65
|
+
try {
|
|
66
|
+
url = new URL(String(link || ""));
|
|
67
|
+
} catch {
|
|
68
|
+
return { ok: false, error: "download is not a URL" };
|
|
69
|
+
}
|
|
70
|
+
// This computer's key goes only to its own Harness, and only for generated media.
|
|
71
|
+
if (
|
|
72
|
+
url.origin !== new URL(origin).origin ||
|
|
73
|
+
!MEDIA_ROUTES.includes(url.pathname)
|
|
74
|
+
)
|
|
75
|
+
return {
|
|
76
|
+
ok: false,
|
|
77
|
+
error: "download must be a URL list_generated_media gave",
|
|
78
|
+
};
|
|
79
|
+
try {
|
|
80
|
+
const response = await fetch(url, {
|
|
81
|
+
headers: { authorization },
|
|
82
|
+
signal: AbortSignal.timeout(MCP_CALL_DEADLINE_MS),
|
|
83
|
+
});
|
|
84
|
+
if (!response.ok)
|
|
85
|
+
return { ok: false, error: `Harness answered ${response.status}` };
|
|
86
|
+
const disposition = response.headers.get("content-disposition") || "";
|
|
87
|
+
const named =
|
|
88
|
+
/filename="?([^";]+)"?/.exec(disposition)?.[1] ||
|
|
89
|
+
url.pathname.split("/").filter(Boolean).at(-1);
|
|
90
|
+
const file = generatedPath(named);
|
|
91
|
+
await pipeline(
|
|
92
|
+
Readable.fromWeb(response.body),
|
|
93
|
+
fs.createWriteStream(file)
|
|
94
|
+
);
|
|
95
|
+
return {
|
|
96
|
+
ok: true,
|
|
97
|
+
path: file,
|
|
98
|
+
mime: response.headers.get("content-type") || "",
|
|
99
|
+
bytes: fs.statSync(file).size,
|
|
100
|
+
};
|
|
101
|
+
} catch (error) {
|
|
102
|
+
log(`a generated-media download failed: ${error.message}`);
|
|
103
|
+
return { ok: false, error: `the download failed: ${error.message}` };
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
const COMMANDS = {
|
|
108
|
+
"mcp.call": (request) => call(request.rpc),
|
|
109
|
+
"mcp.download": (request) => download(request.url),
|
|
110
|
+
};
|
|
111
|
+
return {
|
|
112
|
+
handles: (command) => Object.hasOwn(COMMANDS, command),
|
|
113
|
+
run: (request) =>
|
|
114
|
+
COMMANDS[request.command](request).catch((error) => ({
|
|
115
|
+
ok: false,
|
|
116
|
+
error: error.message,
|
|
117
|
+
})),
|
|
118
|
+
};
|
|
119
|
+
}
|
package/lib/members.json
CHANGED
|
@@ -16,6 +16,18 @@
|
|
|
16
16
|
{ "id": "opencode", "name": "OpenCode", "aliases": ["open code"], "road": "local", "home": "machine", "runs": "machine", "target": true, "wake": "run",
|
|
17
17
|
"about": "reads and changes code in the thread's folder and runs commands",
|
|
18
18
|
"where": "on this computer", "limits": "Needs a folder on this computer to work in.", "review": false },
|
|
19
|
+
{"id": "cursor", "name": "Cursor", "aliases": ["cursor"], "road": "local", "home": "machine", "runs": "machine", "target": true, "wake": "run",
|
|
20
|
+
"about": "reads and changes code in the thread's folder and runs commands",
|
|
21
|
+
"where": "on this computer", "limits": "Needs a folder on this computer to work in.", "review": false, "runtime": {"protocol": "acp", "command": "cursor-agent", "args": ["acp"]}, "t3": "cursor"},
|
|
22
|
+
{"id": "grok-build", "name": "Grok Build", "aliases": ["grok build"], "road": "local", "home": "machine", "runs": "machine", "target": true, "wake": "run",
|
|
23
|
+
"about": "reads and changes code in the thread's folder and runs commands",
|
|
24
|
+
"where": "on this computer", "limits": "Needs a folder on this computer to work in.", "review": false, "runtime": {"protocol": "acp", "command": "grok", "args": ["agent", "stdio"]}, "t3": "grok"},
|
|
25
|
+
{"id": "antigravity", "name": "Antigravity", "aliases": ["antigravity"], "road": "local", "home": "machine", "runs": "machine", "target": true, "wake": "run",
|
|
26
|
+
"about": "reads and changes code in the thread's folder and runs commands",
|
|
27
|
+
"where": "on this computer", "limits": "Needs a folder on this computer to work in.", "review": false, "runtime": {"protocol": "acp", "command": "agy_acp_server.par", "args": []}, "t3": "antigravity"},
|
|
28
|
+
{"id": "muse-code", "name": "Muse Code", "aliases": ["muse code"], "road": "local", "home": "machine", "runs": "machine", "target": true, "wake": "run",
|
|
29
|
+
"about": "reads and changes code in the thread's folder and runs commands",
|
|
30
|
+
"where": "on this computer", "limits": "Needs a folder on this computer to work in.", "review": false, "runtime": {"protocol": "msp", "command": "muse", "args": ["serve"]}, "t3": "muse"},
|
|
19
31
|
{ "id": "grok-bot", "name": "Grok Bot", "aliases": ["grok", "grok bot"], "road": "hosted", "home": "machine", "runs": "self", "target": true, "wake": "email",
|
|
20
32
|
"about": "research on X and the web",
|
|
21
33
|
"where": "in its own cloud", "limits": "Cannot see files on this computer unless one is attached with share_with_cloud, and cannot run anything here." },
|
package/lib/members.mjs
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { readFileSync } from "node:fs";
|
|
2
|
+
import { paths } from "./paths.mjs";
|
|
2
3
|
|
|
3
4
|
// The swarm's members, one entry each (members.json): who they are, which road they call in on, where their tasks
|
|
4
5
|
// live (home), who runs their work (runs), whether others may hand them work (target) and how they are told work is
|
|
@@ -11,6 +12,38 @@ const ROSTER = JSON.parse(
|
|
|
11
12
|
|
|
12
13
|
export const ROSTER_VERSION = ROSTER.version;
|
|
13
14
|
export const MEMBERS = ROSTER.members;
|
|
15
|
+
// Custom ACP executables are local user configuration, never supplied by a task or a remote catalog.
|
|
16
|
+
try {
|
|
17
|
+
const configured = JSON.parse(readFileSync(paths.config, "utf8")).acpAgents;
|
|
18
|
+
for (const entry of Array.isArray(configured) ? configured : []) {
|
|
19
|
+
if (
|
|
20
|
+
!/^acp-[a-z0-9][a-z0-9-]{0,55}$/.test(entry.id) ||
|
|
21
|
+
MEMBERS.some((known) => known.id === entry.id) ||
|
|
22
|
+
typeof entry.command !== "string" ||
|
|
23
|
+
!entry.command.trim() ||
|
|
24
|
+
!Array.isArray(entry.args) ||
|
|
25
|
+
!entry.args.every((arg) => typeof arg === "string")
|
|
26
|
+
)
|
|
27
|
+
continue;
|
|
28
|
+
MEMBERS.push({
|
|
29
|
+
id: entry.id,
|
|
30
|
+
name: String(entry.name || entry.id),
|
|
31
|
+
aliases: [],
|
|
32
|
+
road: "local",
|
|
33
|
+
home: "machine",
|
|
34
|
+
runs: "machine",
|
|
35
|
+
target: true,
|
|
36
|
+
wake: "run",
|
|
37
|
+
review: false,
|
|
38
|
+
about:
|
|
39
|
+
"works in the thread's folder through its installed ACP executable",
|
|
40
|
+
where: "on this computer",
|
|
41
|
+
limits:
|
|
42
|
+
"Uses its own installed agent and authentication. Does not support restricted or read-only runs.",
|
|
43
|
+
runtime: { protocol: "acp", command: entry.command, args: entry.args },
|
|
44
|
+
});
|
|
45
|
+
}
|
|
46
|
+
} catch {}
|
|
14
47
|
const byId = new Map(MEMBERS.map((entry) => [entry.id, entry]));
|
|
15
48
|
|
|
16
49
|
export const member = (id) => byId.get(String(id)) ?? null;
|