tryharness 0.7.45 → 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.
Files changed (99) hide show
  1. package/README.md +232 -12
  2. package/cli.mjs +406 -184
  3. package/lib/actorRoster.mjs +28 -5
  4. package/lib/adapters.mjs +9 -1
  5. package/lib/agentRuntimeConfig.mjs +36 -0
  6. package/lib/agentRuntimes.mjs +560 -0
  7. package/lib/atlas.mjs +7 -2
  8. package/lib/boardCommands.mjs +5 -10
  9. package/lib/boardFileCommands.mjs +2 -1
  10. package/lib/boardMirror.mjs +459 -0
  11. package/lib/boardProtocol.json +206 -6
  12. package/lib/boardTools.mjs +2 -6
  13. package/lib/bridge.mjs +25 -3
  14. package/lib/browserWake.mjs +60 -0
  15. package/lib/cards.mjs +35 -2
  16. package/lib/commands.mjs +20 -5
  17. package/lib/connectionTools.d.ts +13 -0
  18. package/lib/connectionTools.js +45 -0
  19. package/lib/connectorAuth.mjs +309 -0
  20. package/lib/connectorCatalog.json +41 -0
  21. package/lib/connectorCommands.mjs +121 -0
  22. package/lib/connectorGoogle.mjs +513 -0
  23. package/lib/connectors.mjs +805 -0
  24. package/lib/coordinator.mjs +8 -1
  25. package/lib/coreModels.mjs +78 -0
  26. package/lib/daemon.mjs +643 -45
  27. package/lib/desktop.mjs +7 -2
  28. package/lib/digest.mjs +32 -0
  29. package/lib/directLink.mjs +283 -0
  30. package/lib/environments.mjs +595 -0
  31. package/lib/folders.mjs +2 -2
  32. package/lib/goalCommands.mjs +58 -14
  33. package/lib/inference.mjs +263 -152
  34. package/lib/lessons.mjs +6 -0
  35. package/lib/lineup.mjs +324 -0
  36. package/lib/localmodels.mjs +10 -0
  37. package/lib/machineIdentity.mjs +3 -0
  38. package/lib/machineRoutes.mjs +40 -2
  39. package/lib/machineRuns.mjs +30 -3
  40. package/lib/machineSeal.mjs +69 -10
  41. package/lib/mcp-stdio.mjs +121 -118
  42. package/lib/mcpRelay.mjs +119 -0
  43. package/lib/members.json +12 -0
  44. package/lib/members.mjs +33 -0
  45. package/lib/modelMemory.mjs +100 -0
  46. package/lib/modelTiers.json +1183 -0
  47. package/lib/modelTiers.mjs +133 -0
  48. package/lib/models.mjs +41 -8
  49. package/lib/museSession.mjs +119 -0
  50. package/lib/nativeHost.mjs +203 -0
  51. package/lib/network.mjs +7 -2
  52. package/lib/nudge.mjs +10 -2
  53. package/lib/onboard.mjs +430 -1
  54. package/lib/oneclawLocal.mjs +150 -0
  55. package/lib/ownMachines.mjs +521 -36
  56. package/lib/pairing.mjs +165 -0
  57. package/lib/paths.mjs +4 -0
  58. package/lib/phones.mjs +61 -0
  59. package/lib/placeCommands.mjs +27 -0
  60. package/lib/places.mjs +10 -2
  61. package/lib/plans.mjs +151 -27
  62. package/lib/profile.mjs +152 -0
  63. package/lib/projects.mjs +624 -137
  64. package/lib/readiness.mjs +283 -0
  65. package/lib/repoLinks.mjs +354 -0
  66. package/lib/roomChannels.mjs +641 -0
  67. package/lib/runBrief.mjs +32 -2
  68. package/lib/runRequests.mjs +157 -0
  69. package/lib/runWorker.mjs +20 -7
  70. package/lib/runner.mjs +67 -8
  71. package/lib/secretPatterns.json +55 -0
  72. package/lib/secrets.mjs +10 -27
  73. package/lib/seen.mjs +102 -0
  74. package/lib/service.mjs +11 -6
  75. package/lib/sessionControl.mjs +10 -8
  76. package/lib/sessionIndex.mjs +5 -3
  77. package/lib/store.mjs +546 -29
  78. package/lib/subagents.mjs +8 -4
  79. package/lib/swarm.mjs +367 -37
  80. package/lib/swarmMemory.mjs +947 -0
  81. package/lib/t3.mjs +43 -13
  82. package/lib/taskCommands.mjs +56 -5
  83. package/lib/taskRuns.mjs +61 -11
  84. package/lib/team.json +17 -15
  85. package/lib/team.mjs +68 -18
  86. package/lib/threadRuns.mjs +3 -1
  87. package/lib/threadView.mjs +51 -14
  88. package/lib/tokenizer.mjs +405 -0
  89. package/lib/ui.mjs +16 -2
  90. package/lib/usageTotals.mjs +148 -0
  91. package/lib/vault.mjs +1144 -0
  92. package/lib/vaultCloud.mjs +117 -0
  93. package/lib/vaultCommands.mjs +201 -0
  94. package/lib/vaultTools.d.ts +12 -0
  95. package/lib/vaultTools.js +42 -0
  96. package/lib/windowAsks.mjs +42 -0
  97. package/lib/workFocus.mjs +59 -0
  98. package/lib/workLinks.mjs +90 -0
  99. 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 path from "node:path";
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:
@@ -386,20 +399,6 @@ const LOCAL_TOOLS = [
386
399
  additionalProperties: false,
387
400
  },
388
401
  },
389
- {
390
- name: "search_room",
391
- description:
392
- "Search a goal's room by meaning before starting work, so you build on what teammates already found instead of repeating it.",
393
- inputSchema: {
394
- type: "object",
395
- properties: {
396
- id: { type: "string", description: "the goal id" },
397
- query: { type: "string" },
398
- },
399
- required: ["id", "query"],
400
- additionalProperties: false,
401
- },
402
- },
403
402
  {
404
403
  name: "plan_work",
405
404
  description:
@@ -464,35 +463,35 @@ const LOCAL_TOOLS = [
464
463
  },
465
464
  },
466
465
  {
467
- name: "save_learning",
466
+ name: "swarm_memory",
468
467
  description:
469
- "Save what you learned doing your part in a thread, for the next agent who holds your role in this folder: a trap, a check that matters, how the code really works. Say why it holds. Your note is yours, ranks below what the person said, and is shown to others as unchecked.",
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.",
470
469
  inputSchema: {
471
470
  type: "object",
472
471
  properties: {
473
- id: { type: "string", description: "the thread id" },
474
- text: {
472
+ search: {
473
+ type: "string",
474
+ description: "what you are looking for, in words",
475
+ },
476
+ remember: {
475
477
  type: "string",
476
478
  description: "what you learned, in one or two sentences",
477
479
  },
478
- reason: { type: "string", description: "why it holds: what showed it" },
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
+ },
479
489
  replaces: {
480
490
  type: "string",
481
- description: "the id of an earlier note of yours this one replaces",
491
+ description:
492
+ "the id of an earlier note of yours this one replaces (with remember)",
482
493
  },
483
494
  },
484
- required: ["id", "text", "reason"],
485
- additionalProperties: false,
486
- },
487
- },
488
- {
489
- name: "search_swarm",
490
- description:
491
- "Search the shared memory of the user's agents: everything any agent wrote in any thread (findings, answers, questions, results) and the user's coding sessions on this computer. Use it before starting work to build on what another agent already did, and when you need to know how something was done before.",
492
- inputSchema: {
493
- type: "object",
494
- properties: { query: { type: "string" } },
495
- required: ["query"],
496
495
  additionalProperties: false,
497
496
  },
498
497
  },
@@ -724,6 +723,8 @@ const LOCAL_TOOLS = [
724
723
  additionalProperties: false,
725
724
  },
726
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]),
727
728
  ];
728
729
 
729
730
  const postTask = (args) => ({
@@ -744,6 +745,7 @@ const postTask = (args) => ({
744
745
  });
745
746
 
746
747
  const BOARD_CALLS = {
748
+ connection: connectionRequest,
747
749
  list_agents: () => ({ command: "board.swarm.agents" }),
748
750
  list_models: (args) => ({
749
751
  command: "board.swarm.models",
@@ -788,22 +790,28 @@ const BOARD_CALLS = {
788
790
  changes: Array.isArray(args.changes) ? args.changes : [],
789
791
  decision: args.decision ?? null,
790
792
  }),
791
- save_learning: (args) => ({
792
- command: "board.room.learn",
793
- id: String(args.id || ""),
794
- text: args.text,
795
- reason: args.reason,
796
- replaces: args.replaces ?? null,
797
- }),
798
- search_room: (args) => ({
799
- command: "board.room.search",
800
- id: String(args.id || ""),
801
- query: args.query,
802
- }),
803
- search_swarm: (args) => ({
804
- command: "board.swarm.search",
805
- query: args.query,
806
- }),
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
+ },
807
815
  compare_screens: (args) => ({
808
816
  command: "board.screens.compare",
809
817
  before: args.before,
@@ -905,6 +913,13 @@ const BOARD_CALLS = {
905
913
  rooms: true,
906
914
  }),
907
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
+ }),
908
923
  wallet: (args) => ({
909
924
  command: "board.wallet",
910
925
  action: args.action,
@@ -1036,20 +1051,16 @@ function write(message) {
1036
1051
  }
1037
1052
 
1038
1053
  // Harness's generated media saved where this machine's agents can use it, under ~/.harness/files/generated.
1039
- const MEDIA_ROUTES = ["/api/mcp/media", "/api/mcp/file"];
1040
1054
  function saveGenerated(name, bytes) {
1041
- const dir = path.join(paths.files, "generated");
1042
- fs.mkdirSync(dir, { recursive: true });
1043
- const file = path.join(
1044
- dir,
1045
- path
1046
- .basename(name)
1047
- .replace(/[^\w.-]+/g, "-")
1048
- .replace(/^\.+/, "") || "harness-media"
1049
- );
1055
+ const file = generatedPath(name);
1050
1056
  fs.writeFileSync(file, bytes);
1051
1057
  return file;
1052
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).
1053
1064
  async function saveGeneratedMedia(request, download) {
1054
1065
  const config = readJson(paths.config, {});
1055
1066
  const reply = (body, isError = false) => ({
@@ -1065,55 +1076,23 @@ async function saveGeneratedMedia(request, download) {
1065
1076
  { ok: false, error: "Harness is not connected. Run: npx tryharness" },
1066
1077
  true
1067
1078
  );
1068
- let url;
1069
1079
  try {
1070
- url = new URL(String(download || ""));
1071
- } catch {
1072
- return reply({ ok: false, error: "download is not a URL" }, true);
1073
- }
1074
- // This computer's key goes only to its own Harness, and only for generated media.
1075
- if (
1076
- url.origin !== new URL(config.origin).origin ||
1077
- !MEDIA_ROUTES.includes(url.pathname)
1078
- )
1079
- return reply(
1080
- { ok: false, error: "download must be a URL list_generated_media gave" },
1081
- true
1080
+ const saved = await daemonRequest(
1081
+ { command: "mcp.download", url: download },
1082
+ MCP_CALL_DEADLINE_MS
1082
1083
  );
1083
- try {
1084
- // The same deadline as every other call this server makes to Harness (relay below).
1085
- const response = await fetch(url, {
1086
- headers: { authorization: "Bearer " + config.token },
1087
- signal: AbortSignal.timeout(90_000),
1088
- });
1089
- if (!response.ok)
1090
- return reply(
1091
- { ok: false, error: `Harness answered ${response.status}` },
1092
- true
1093
- );
1094
- const named =
1095
- /filename="?([^";]+)"?/.exec(
1096
- response.headers.get("content-disposition") || ""
1097
- )?.[1] || url.pathname.split("/").filter(Boolean).at(-1);
1098
- const bytes = Buffer.from(await response.arrayBuffer());
1099
- return reply({
1100
- ok: true,
1101
- path: saveGenerated(named, bytes),
1102
- mime: response.headers.get("content-type") || "",
1103
- bytes: bytes.length,
1104
- });
1084
+ return reply(saved, saved?.ok !== true);
1105
1085
  } catch (error) {
1106
- return reply(
1107
- { ok: false, error: `the download failed: ${error.message}` },
1108
- true
1109
- );
1086
+ const reason = relayNotRunning(error)
1087
+ ? RELAY_NOT_RUNNING
1088
+ : `the download failed: ${error.message}`;
1089
+ return reply({ ok: false, error: reason }, true);
1110
1090
  }
1111
1091
  }
1112
1092
 
1113
1093
  const SEARCHES = [
1114
1094
  "search_task_context",
1115
- "search_room",
1116
- "search_swarm",
1095
+ "swarm_memory",
1117
1096
  "search_code",
1118
1097
  "search_files",
1119
1098
  "search_screen",
@@ -1128,6 +1107,12 @@ const MEDIA_DEADLINE_MS = 120_000;
1128
1107
  /** How long a call waits for the daemon. */
1129
1108
  function deadlineFor(name) {
1130
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;
1131
1116
  if (SEARCHES.includes(name)) return 20_000;
1132
1117
  return 5_000;
1133
1118
  }
@@ -1137,9 +1122,28 @@ async function localCall(request) {
1137
1122
  const args = request.params?.arguments || {};
1138
1123
  if (name === "save_generated_media")
1139
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
+ };
1140
1140
  try {
1141
1141
  const result = await daemonRequest(
1142
- { ...BOARD_CALLS[name](args), agent },
1142
+ {
1143
+ ...call,
1144
+ agent,
1145
+ ...(restricted ? { restricted } : {}),
1146
+ },
1143
1147
  deadlineFor(name)
1144
1148
  );
1145
1149
  if (name === "watch_video" && result?.ok)
@@ -1173,7 +1177,9 @@ async function localCall(request) {
1173
1177
  content: [
1174
1178
  {
1175
1179
  type: "text",
1176
- text: "Harness daemon unavailable: " + error.message,
1180
+ text: relayNotRunning(error)
1181
+ ? RELAY_NOT_RUNNING
1182
+ : "Harness daemon unavailable: " + error.message,
1177
1183
  },
1178
1184
  ],
1179
1185
  isError: true,
@@ -1263,21 +1269,13 @@ async function relay(line) {
1263
1269
  return;
1264
1270
  }
1265
1271
  try {
1266
- const response = await fetch(
1267
- String(config.origin).replace(/\/$/, "") + "/api/mcp",
1268
- {
1269
- method: "POST",
1270
- // This server tells the agent who else is in the swarm itself (the handshake below), so Harness does not too.
1271
- headers: {
1272
- "content-type": "application/json",
1273
- authorization: "Bearer " + config.token,
1274
- "x-harness-swarm": "local",
1275
- },
1276
- body: JSON.stringify(request),
1277
- signal: AbortSignal.timeout(90_000),
1278
- }
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
1279
1276
  );
1280
- const body = await response.text();
1277
+ if (!answer?.ok) throw new Error(answer?.error || "the relay refused");
1278
+ const body = String(answer.body ?? "");
1281
1279
  if (!body.trim()) return;
1282
1280
  const payload = JSON.parse(body);
1283
1281
  // This computer's tools answer here (relay above), so the agent sees them as they work here: a file by its path.
@@ -1322,9 +1320,12 @@ async function relay(line) {
1322
1320
  write(payload);
1323
1321
  } catch (error) {
1324
1322
  // Harness unreachable: the machine's own tools and queue still answer.
1323
+ const notRunning = relayNotRunning(error);
1325
1324
  if (request.method === "initialize") {
1326
1325
  const reply = localInitialize(request);
1327
- reply.result.instructions = await handshakeInstructions();
1326
+ reply.result.instructions = await handshakeInstructions(
1327
+ notRunning ? RELAY_NOT_RUNNING : ""
1328
+ );
1328
1329
  write(reply);
1329
1330
  return;
1330
1331
  }
@@ -1342,7 +1343,9 @@ async function relay(line) {
1342
1343
  id: request.id,
1343
1344
  error: {
1344
1345
  code: -32000,
1345
- message: "Harness is unreachable: " + error.message,
1346
+ message: notRunning
1347
+ ? RELAY_NOT_RUNNING
1348
+ : "Harness is unreachable: " + error.message,
1346
1349
  },
1347
1350
  });
1348
1351
  }
@@ -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;
@@ -0,0 +1,100 @@
1
+ import os from "node:os";
2
+
3
+ // The local models' share of the computer's memory. The relay sits beside everything else the person runs, a local
4
+ // agent model included, so its models together stay under a ceiling scaled to the machine: 6% of its memory, at least
5
+ // 500 MB (an 8 GB machine) and at most 2 GB. A model about to load makes room by unloading idle models, the least
6
+ // recently used first; a model in use is never unloaded, and a load waits for one to finish instead. A model larger than
7
+ // the ceiling loads only when nothing else is loaded.
8
+
9
+ const SHARE = 0.06;
10
+ const FLOOR_MB = 500;
11
+ const CAP_MB = 2_000;
12
+ // Models not yet measured are charged at one and a half times their files.
13
+ const UNMEASURED_FACTOR = 1.5;
14
+
15
+ export const memoryCeilingMb = (totalBytes = os.totalmem()) =>
16
+ Math.round(
17
+ Math.min(CAP_MB, Math.max(FLOOR_MB, (totalBytes / 2 ** 20) * SHARE))
18
+ );
19
+
20
+ /** What a model is charged: its measured peak (memoryMb in localmodels.mjs), or an allowance from its files' size. */
21
+ export function memoryCostMb(entry) {
22
+ if (entry.memoryMb) return entry.memoryMb;
23
+ const bytes = entry.files.reduce((sum, file) => sum + file.size, 0);
24
+ return Math.round((bytes / 2 ** 20) * UNMEASURED_FACTOR);
25
+ }
26
+
27
+ export function createModelMemory({ ceilingMb, log = () => {} }) {
28
+ const loaded = new Map();
29
+ const inUse = new Map();
30
+ let waiting = [];
31
+
32
+ const usedMb = () =>
33
+ [...loaded.values()].reduce((sum, model) => sum + model.mb, 0);
34
+ const wakeWaiting = () => {
35
+ const ready = waiting;
36
+ waiting = [];
37
+ for (const resolve of ready) resolve();
38
+ };
39
+ const leastRecentIdle = (except) =>
40
+ [...loaded.entries()]
41
+ .filter(([id]) => id !== except && !inUse.get(id))
42
+ .sort(([, a], [, b]) => a.usedAt - b.usedAt)[0];
43
+ const othersLoaded = (id) => [...loaded.keys()].some((other) => other !== id);
44
+
45
+ return {
46
+ ceilingMb,
47
+
48
+ /** Marks a model in use until the returned function is called. */
49
+ use(id) {
50
+ inUse.set(id, (inUse.get(id) ?? 0) + 1);
51
+ const model = loaded.get(id);
52
+ if (model) model.usedAt = performance.now();
53
+ let done = false;
54
+ return () => {
55
+ if (done) return;
56
+ done = true;
57
+ inUse.set(id, inUse.get(id) - 1);
58
+ wakeWaiting();
59
+ };
60
+ },
61
+
62
+ /**
63
+ * Makes room for a model about to load and counts it at mb; unload() takes it out of memory when room is needed.
64
+ * Admitting a loaded model again at a larger mb makes room for the difference (a server taking on another model).
65
+ */
66
+ async admit(id, mb, unload) {
67
+ const countedMb = () => loaded.get(id)?.mb ?? 0;
68
+ if (mb <= countedMb()) return;
69
+ for (;;) {
70
+ const fits = usedMb() - countedMb() + mb <= ceilingMb;
71
+ if (fits || !othersLoaded(id)) break;
72
+ const idle = leastRecentIdle(id);
73
+ if (idle) {
74
+ const [idleId, idleModel] = idle;
75
+ loaded.delete(idleId);
76
+ log(`local models: ${idleId} unloaded to make room for ${id}`);
77
+ await idleModel.unload();
78
+ continue;
79
+ }
80
+ await new Promise((resolve) => waiting.push(resolve));
81
+ }
82
+ if (mb > ceilingMb)
83
+ log(
84
+ `local models: ${id} needs ${mb} MB, over the ${ceilingMb} MB ceiling; it runs alone`
85
+ );
86
+ loaded.set(id, { mb, usedAt: performance.now(), unload });
87
+ },
88
+
89
+ /** A model that left on its own (idle, or its process exited). */
90
+ gone(id) {
91
+ if (loaded.delete(id)) wakeWaiting();
92
+ },
93
+
94
+ status: () => ({
95
+ ceilingMb,
96
+ usedMb: usedMb(),
97
+ models: [...loaded.keys()],
98
+ }),
99
+ };
100
+ }