tryharness 0.7.82 → 0.7.86

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 (216) hide show
  1. package/README.md +21 -19
  2. package/assets/dsh-plugin.mjs +75 -4
  3. package/assets/herdr-mod/harness/main.js +367 -0
  4. package/assets/herdr-mod/harness/mod.json +6 -0
  5. package/assets/opencode-plugin.js +87 -22
  6. package/assets/pi-extension.ts +81 -2
  7. package/cli.mjs +544 -208
  8. package/lib/adapters.mjs +62 -27
  9. package/lib/agentBinaries.mjs +6 -8
  10. package/lib/agentClaims.mjs +168 -0
  11. package/lib/agentReadTools.json +415 -0
  12. package/lib/agentSignIn.mjs +17 -18
  13. package/lib/agentWiring.mjs +114 -0
  14. package/lib/archetypes.js +10 -11
  15. package/lib/attention.mjs +100 -0
  16. package/lib/audit.mjs +1 -1
  17. package/lib/backupSetup.mjs +6 -28
  18. package/lib/bankrApprovals.mjs +86 -0
  19. package/lib/boardAccess.mjs +40 -66
  20. package/lib/boardBackup.mjs +86 -85
  21. package/lib/boardCommands.mjs +28 -0
  22. package/lib/boardFileCommands.mjs +29 -36
  23. package/lib/boardFiles.mjs +83 -15
  24. package/lib/boardMirror.mjs +78 -11
  25. package/lib/boardProtocol.json +193 -123
  26. package/lib/boardThreads.mjs +19 -37
  27. package/lib/boardTools.mjs +22 -15
  28. package/lib/boardWatches.mjs +43 -15
  29. package/lib/bridge.mjs +7 -3
  30. package/lib/browserAgentTools.mjs +59 -0
  31. package/lib/browserWake.mjs +0 -6
  32. package/lib/cards.mjs +57 -2
  33. package/lib/circling.mjs +189 -0
  34. package/lib/cleanup.mjs +234 -0
  35. package/lib/cloudBoot.mjs +21 -4
  36. package/lib/cloudSave.mjs +46 -5
  37. package/lib/compaction.mjs +8 -1
  38. package/lib/completion.mjs +358 -0
  39. package/lib/computerDevices.mjs +853 -0
  40. package/lib/connectionStatus.mjs +34 -0
  41. package/lib/connectors.mjs +139 -1
  42. package/lib/coordinator.mjs +108 -14
  43. package/lib/coreModels.mjs +36 -12
  44. package/lib/daemon.mjs +2435 -333
  45. package/lib/daemonLock.mjs +103 -0
  46. package/lib/deviceDoor.mjs +308 -0
  47. package/lib/deviceIdentity.mjs +114 -0
  48. package/lib/deviceList.mjs +172 -0
  49. package/lib/deviceSeal.mjs +74 -0
  50. package/lib/dispatcher.mjs +497 -26
  51. package/lib/dispatches.mjs +3 -3
  52. package/lib/environment.mjs +2 -1
  53. package/lib/environments.mjs +67 -41
  54. package/lib/events.mjs +318 -0
  55. package/lib/facts.mjs +170 -0
  56. package/lib/fileSource.mjs +540 -0
  57. package/lib/files.mjs +47 -2
  58. package/lib/gitHost.mjs +39 -1
  59. package/lib/goalCommands.mjs +12 -80
  60. package/lib/handover.mjs +21 -16
  61. package/lib/harnessOffers.mjs +140 -15
  62. package/lib/herdr.mjs +100 -15
  63. package/lib/herdrAppCall.mjs +19 -0
  64. package/lib/herdrCore.mjs +59 -0
  65. package/lib/herdrRuns.mjs +1126 -0
  66. package/lib/hookDialects.mjs +235 -50
  67. package/lib/identityLink.mjs +81 -0
  68. package/lib/inference.mjs +31 -2
  69. package/lib/jamAccess.mjs +82 -0
  70. package/lib/{projectBoard.mjs → jamBoard.mjs} +5 -4
  71. package/lib/{projectGit.mjs → jamGit.mjs} +53 -15
  72. package/lib/jamKey.mjs +274 -0
  73. package/lib/{projectPieces.mjs → jamPieces.mjs} +35 -29
  74. package/lib/{projectSettings.mjs → jamSettings.mjs} +12 -22
  75. package/lib/jamStore.mjs +973 -0
  76. package/lib/jamUpgrade.mjs +112 -0
  77. package/lib/jams.mjs +3079 -0
  78. package/lib/kanban.mjs +13 -7
  79. package/lib/landed.mjs +5 -1
  80. package/lib/library.mjs +41 -22
  81. package/lib/limits.mjs +91 -0
  82. package/lib/lineDiff.mjs +97 -0
  83. package/lib/lineup.mjs +18 -13
  84. package/lib/link.mjs +584 -0
  85. package/lib/localStack.mjs +75 -16
  86. package/lib/localmodels.mjs +58 -78
  87. package/lib/loopBackstop.mjs +2 -1
  88. package/lib/machine.mjs +544 -0
  89. package/lib/machineLink.mjs +446 -0
  90. package/lib/machineRoutes.mjs +68 -19
  91. package/lib/machineRuns.mjs +85 -4
  92. package/lib/machineSeal.mjs +6 -31
  93. package/lib/manager.mjs +134 -12
  94. package/lib/mcp-stdio.mjs +492 -215
  95. package/lib/mcpRelay.mjs +34 -35
  96. package/lib/members.json +2 -2
  97. package/lib/modelRoute.mjs +162 -0
  98. package/lib/nativeHost.mjs +81 -90
  99. package/lib/nativeSenses.mjs +258 -0
  100. package/lib/nerves.mjs +523 -0
  101. package/lib/network.mjs +117 -278
  102. package/lib/networkPlaces.mjs +578 -0
  103. package/lib/nextStep.mjs +95 -0
  104. package/lib/notify.mjs +2 -2
  105. package/lib/nudge.mjs +116 -10
  106. package/lib/onboard.mjs +6 -6
  107. package/lib/originals.mjs +216 -0
  108. package/lib/outsideEvents.mjs +383 -0
  109. package/lib/outsideRuns.mjs +230 -0
  110. package/lib/ownMachines.mjs +674 -256
  111. package/lib/pain.mjs +215 -0
  112. package/lib/pairing.mjs +91 -11
  113. package/lib/paths.mjs +42 -3
  114. package/lib/peerProcess.mjs +21 -7
  115. package/lib/peopleLink.mjs +268 -0
  116. package/lib/personNotices.mjs +3 -2
  117. package/lib/phones.mjs +252 -542
  118. package/lib/placeCards.mjs +282 -0
  119. package/lib/placeChecks.mjs +95 -0
  120. package/lib/placeCommands.mjs +8 -17
  121. package/lib/placeRequests.mjs +152 -0
  122. package/lib/placeStore.mjs +295 -0
  123. package/lib/placeTool.d.ts +12 -0
  124. package/lib/placeTool.js +40 -0
  125. package/lib/places.mjs +63 -14
  126. package/lib/plans.mjs +53 -8
  127. package/lib/presence.mjs +270 -0
  128. package/lib/privateNetwork.d.ts +2 -0
  129. package/lib/privateNetwork.js +93 -0
  130. package/lib/proposals.mjs +300 -0
  131. package/lib/publicFetch.d.ts +32 -0
  132. package/lib/publicFetch.js +248 -0
  133. package/lib/reach.mjs +128 -0
  134. package/lib/rebuildable.mjs +72 -0
  135. package/lib/recall.mjs +216 -0
  136. package/lib/record.mjs +13 -0
  137. package/lib/reflexes.mjs +392 -0
  138. package/lib/relayLimits.mjs +31 -2
  139. package/lib/releaseNotice.mjs +198 -0
  140. package/lib/removeHarness.mjs +15 -4
  141. package/lib/repoLinks.mjs +204 -35
  142. package/lib/runAuthority.mjs +102 -39
  143. package/lib/runBrief.mjs +93 -40
  144. package/lib/runRequests.mjs +52 -14
  145. package/lib/runUsage.mjs +31 -0
  146. package/lib/runWorker.mjs +74 -25
  147. package/lib/runner.mjs +289 -45
  148. package/lib/runtime-install.mjs +37 -8
  149. package/lib/schedules.mjs +171 -47
  150. package/lib/screenWatches.mjs +221 -0
  151. package/lib/sealed.mjs +12 -30
  152. package/lib/sealedThreads.mjs +198 -392
  153. package/lib/secretStore.mjs +178 -0
  154. package/lib/secrets.mjs +11 -0
  155. package/lib/seen.mjs +3 -9
  156. package/lib/selfUpdate.mjs +51 -15
  157. package/lib/senseCall.mjs +1514 -0
  158. package/lib/senseHook.mjs +114 -0
  159. package/lib/senseTools.mjs +1298 -0
  160. package/lib/sessionBriefs.mjs +87 -0
  161. package/lib/sessionControl.mjs +63 -13
  162. package/lib/sessionFiles.mjs +85 -0
  163. package/lib/setupChoices.mjs +12 -3
  164. package/lib/setupMode.mjs +70 -25
  165. package/lib/sharedKeys.mjs +166 -0
  166. package/lib/sleep.mjs +396 -0
  167. package/lib/sources.mjs +306 -0
  168. package/lib/speech.mjs +166 -411
  169. package/lib/spoken.mjs +210 -0
  170. package/lib/steerHook.mjs +3 -1
  171. package/lib/steerQueue.mjs +40 -11
  172. package/lib/store.mjs +323 -130
  173. package/lib/stuck.mjs +85 -7
  174. package/lib/swarm.mjs +157 -49
  175. package/lib/swarmDevices.mjs +25 -85
  176. package/lib/swarmMemory.mjs +93 -9
  177. package/lib/t3.mjs +73 -3
  178. package/lib/taskCommands.mjs +51 -60
  179. package/lib/taskRooms.mjs +30 -4
  180. package/lib/taskRules.json +29 -0
  181. package/lib/taskRules.mjs +21 -0
  182. package/lib/taskRuns.mjs +74 -11
  183. package/lib/team.mjs +2 -1
  184. package/lib/threadActions.mjs +37 -9
  185. package/lib/threadAuthority.mjs +4 -4
  186. package/lib/threadBriefs.mjs +173 -43
  187. package/lib/threadNotes.mjs +320 -0
  188. package/lib/threadRecord.mjs +491 -0
  189. package/lib/threadRuns.mjs +216 -108
  190. package/lib/threadView.mjs +27 -30
  191. package/lib/threadWatches.mjs +1962 -0
  192. package/lib/timeSense.mjs +839 -0
  193. package/lib/tripwires.mjs +454 -0
  194. package/lib/ui.mjs +1 -1
  195. package/lib/vault.mjs +560 -45
  196. package/lib/vaultCommands.mjs +5 -3
  197. package/lib/vaultPeers.mjs +165 -0
  198. package/lib/vaultTools.d.ts +4 -1
  199. package/lib/vaultTools.js +22 -1
  200. package/lib/verdicts.mjs +12 -26
  201. package/lib/versions.mjs +117 -0
  202. package/lib/waitTool.mjs +278 -0
  203. package/lib/wakePicture.mjs +268 -0
  204. package/lib/wakeQueue.mjs +108 -0
  205. package/lib/watchResponses.mjs +533 -0
  206. package/lib/watches.mjs +290 -145
  207. package/lib/windowAsks.mjs +80 -17
  208. package/lib/worktrees.mjs +159 -9
  209. package/npm-shrinkwrap.json +138 -631
  210. package/package.json +7 -6
  211. package/release.json +212 -130
  212. package/lib/callSessions.mjs +0 -51
  213. package/lib/directLink.mjs +0 -349
  214. package/lib/peopleBoard.mjs +0 -131
  215. package/lib/projects.mjs +0 -2917
  216. package/lib/roomChannels.mjs +0 -667
package/lib/mcpRelay.mjs CHANGED
@@ -4,9 +4,11 @@ import { Readable } from "node:stream";
4
4
  import { pipeline } from "node:stream/promises";
5
5
  import { paths } from "./paths.mjs";
6
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 (an earlier mcp-stdio.mjs), kept as it was, not measured again.
7
+ // How long an agent's MCP server waits on this daemon for a read of the person's browser or a download: the deadline
8
+ // every agent call had when it went to Harness's /api/mcp (an earlier mcp-stdio.mjs), kept as it was, not measured
9
+ // again.
9
10
  export const MCP_CALL_DEADLINE_MS = 90_000;
11
+
10
12
  export const RELAY_NOT_RUNNING =
11
13
  "Harness relay is not running on this computer: run npx tryharness";
12
14
  // The only downloads this computer's key goes to: Harness's generated media and chat files.
@@ -25,42 +27,16 @@ export function generatedPath(name) {
25
27
  }
26
28
 
27
29
  /**
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
+ * What an agent's MCP server asks of this daemon beyond the board: its reads of the person's browsers, which this
31
+ * computer asks the browser for itself (`deviceDoor`, deviceDoor.mjs), and Harness's generated media saved to disk.
32
+ * Nothing an agent here calls goes to Harness's /api/mcp.
30
33
  */
31
- export function createMcpRelay({ config, bridge, log }) {
34
+ export function createMcpRelay({ config, log, deviceDoor = null }) {
32
35
  const origin = String(config.origin).replace(/\/$/, "");
33
36
  const authorization = "Bearer " + config.token;
34
37
 
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
38
  /** A generated file list_generated_media named, streamed to disk; the answer is what the agent is told. */
63
- async function download(link) {
39
+ async function download(link, agent) {
64
40
  let url;
65
41
  try {
66
42
  url = new URL(String(link || ""));
@@ -76,6 +52,9 @@ export function createMcpRelay({ config, bridge, log }) {
76
52
  ok: false,
77
53
  error: "download must be a URL list_generated_media gave",
78
54
  };
55
+ // A document made in one of the person's browsers is asked of that browser by this computer, never Harness.
56
+ if (url.pathname === "/api/mcp/file" && deviceDoor)
57
+ return saveFromBrowser(url, agent);
79
58
  try {
80
59
  const response = await fetch(url, {
81
60
  headers: { authorization },
@@ -104,9 +83,29 @@ export function createMcpRelay({ config, bridge, log }) {
104
83
  }
105
84
  }
106
85
 
86
+ async function saveFromBrowser(url, agent) {
87
+ const file = await deviceDoor.fileFor({
88
+ id: url.searchParams.get("id") ?? "",
89
+ device: url.searchParams.get("device"),
90
+ agent,
91
+ });
92
+ if (file.error) return { ok: false, error: file.error };
93
+ const saved = generatedPath(file.filename);
94
+ fs.writeFileSync(saved, Buffer.from(file.data, "base64"));
95
+ return {
96
+ ok: true,
97
+ path: saved,
98
+ mime: file.mediaType,
99
+ bytes: fs.statSync(saved).size,
100
+ };
101
+ }
102
+
107
103
  const COMMANDS = {
108
- "mcp.call": (request) => call(request.rpc),
109
- "mcp.download": (request) => download(request.url),
104
+ "mcp.call": async (request) =>
105
+ deviceDoor
106
+ ? deviceDoor.forAgent(request.rpc, request.agent)
107
+ : { ok: false, error: "this computer reads no browser" },
108
+ "mcp.download": (request) => download(request.url, request.agent),
110
109
  };
111
110
  return {
112
111
  handles: (command) => Object.hasOwn(COMMANDS, command),
package/lib/members.json CHANGED
@@ -62,9 +62,9 @@
62
62
  "where": "on Harness's server, through Bankr", "limits": "Cannot see files on this computer. Reading balances or a transaction needs no task: an agent on this computer reads them with the wallet tool in seconds." },
63
63
  { "id": "quotient", "name": "Quotient", "aliases": [], "road": "server", "home": "cloud", "runs": "server", "target": true, "tagged": true, "wake": "run",
64
64
  "fixedRole": { "specialty": "prediction-markets", "role": "analyst" },
65
- "about": "prediction markets research: one search over the markets it tracks, with their odds and rules",
65
+ "about": "prediction market and asset research: searches the markets it tracks, with their odds and rules, and researches assets, portfolios, X and forecasts",
66
66
  "where": "on Harness's server", "limits": "Takes no positions from a task. Cannot see files on this computer." },
67
- { "id": "muse", "name": "Muse", "aliases": [], "road": "hosted", "home": "cloud", "runs": "self", "target": true, "wake": "schedule",
67
+ { "id": "muse", "name": "Muse", "aliases": [], "road": "hosted", "home": "cloud", "runs": "self", "target": true, "wake": "listen",
68
68
  "about": "writing and creative drafts",
69
69
  "where": "in Meta's cloud", "limits": "Cannot see files on this computer unless one is attached with share_with_cloud, and cannot run anything here." },
70
70
  { "id": "openclaw", "name": "OpenClaw", "aliases": ["open claw"], "road": "local", "home": "machine", "runs": "self", "target": true, "wake": "local-webhook",
@@ -0,0 +1,162 @@
1
+ import fs from "node:fs";
2
+ import http from "node:http";
3
+ import path from "node:path";
4
+ import { harnessHome } from "./paths.mjs";
5
+ import { notesAtStep, sessionsAtWork } from "./senseCall.mjs";
6
+
7
+ // The route at the model (docs/senses-plan.md S4.9, open item 8): for a model Harness serves on this computer, an
8
+ // OpenAI-style address an agent can be pointed at. Each request goes through to the model as it is, streamed or not;
9
+ // what Harness noticed for the agent's session (steerQueue.mjs SENSE, the notes its hooks give after a tool call)
10
+ // rides at the end of the request as one message from Harness, added after what the agent sent and never written into
11
+ // earlier turns, so the provider's cache of the conversation keeps working (spend and context, rule 7). It is the route
12
+ // for an agent with no hook of its own; one whose hooks already give the notes takes them there first, and a note is
13
+ // given once whichever way takes it. Nothing is put between an agent and its model unless the agent is pointed here.
14
+ //
15
+ // The session: the header `x-harness-session` or the request's `user`; else, under `/agent/<agent>/v1/…`, that agent's
16
+ // one session at work on this computer. With none, the request goes through untouched.
17
+
18
+ const AT_WORK_MS = 15 * 60_000;
19
+ const LARGEST_BODY = 20_000_000;
20
+
21
+ /** Where the route listens, for setup and an agent's settings: `{ url }`, or null while it is not running. */
22
+ export const routeFile = (home = harnessHome) =>
23
+ path.join(home, "senses", "model-route.json");
24
+
25
+ const readBody = (request) =>
26
+ new Promise((resolve, reject) => {
27
+ const parts = [];
28
+ let size = 0;
29
+ request.on("data", (chunk) => {
30
+ size += chunk.length;
31
+ if (size > LARGEST_BODY) {
32
+ reject(new Error("the request is too large"));
33
+ request.destroy();
34
+ return;
35
+ }
36
+ parts.push(chunk);
37
+ });
38
+ request.on("end", () => resolve(Buffer.concat(parts).toString("utf8")));
39
+ request.on("error", reject);
40
+ });
41
+
42
+ /**
43
+ * `serving(model)` resolves `{ base, headers }`, where a model Harness serves answers and what it asks of a request
44
+ * (its key; inference.mjs serving); `models()` the
45
+ * ids it serves. `start()` listens on this computer only and writes where; `stop()`.
46
+ */
47
+ export function createModelRoute({
48
+ serving,
49
+ models = () => [],
50
+ home = harnessHome,
51
+ port = 0,
52
+ log = () => {},
53
+ }) {
54
+ let server = null;
55
+
56
+ const sessionFor = (request, body, agentInPath) => {
57
+ const named = request.headers["x-harness-session"] ?? body?.user;
58
+ if (typeof named === "string" && named) return named;
59
+ if (!agentInPath) return null;
60
+ const working = sessionsAtWork(AT_WORK_MS, home).filter(
61
+ (each) => each.agent === agentInPath
62
+ );
63
+ return working.length === 1 ? working[0].session : null;
64
+ };
65
+
66
+ const answer = (response, status, value) => {
67
+ response.writeHead(status, { "content-type": "application/json" });
68
+ response.end(JSON.stringify(value));
69
+ };
70
+
71
+ const handle = async (request, response) => {
72
+ const url = new URL(request.url, "http://127.0.0.1");
73
+ const inPath = /^\/agent\/([\w.-]+)(\/v1\/.*)$/.exec(url.pathname);
74
+ const route = inPath ? inPath[2] : url.pathname;
75
+ if (request.method === "GET" && route === "/v1/models")
76
+ return answer(response, 200, {
77
+ object: "list",
78
+ data: models().map((id) => ({
79
+ id,
80
+ object: "model",
81
+ owned_by: "harness",
82
+ })),
83
+ });
84
+ if (request.method !== "POST" || route !== "/v1/chat/completions")
85
+ return answer(response, 404, { error: { message: "not here" } });
86
+ let body;
87
+ try {
88
+ body = JSON.parse(await readBody(request));
89
+ } catch (error) {
90
+ return answer(response, 400, { error: { message: error.message } });
91
+ }
92
+ const model = String(body.model ?? "");
93
+ if (!models().includes(model))
94
+ return answer(response, 404, {
95
+ error: {
96
+ message: `Harness does not serve ${model || "that model"} here`,
97
+ },
98
+ });
99
+ const session = sessionFor(request, body, inPath?.[1] ?? null);
100
+ const notes = session ? notesAtStep(session, null, home) : "";
101
+ const messages = Array.isArray(body.messages) ? body.messages : [];
102
+ const sent = notes
103
+ ? { ...body, messages: [...messages, { role: "user", content: notes }] }
104
+ : body;
105
+ let base;
106
+ let headers = {};
107
+ try {
108
+ ({ base, headers = {} } = await serving(model));
109
+ } catch (error) {
110
+ return answer(response, 503, { error: { message: error.message } });
111
+ }
112
+ const upstream = await fetch(`${base}/v1/chat/completions`, {
113
+ method: "POST",
114
+ headers: { "content-type": "application/json", ...headers },
115
+ body: JSON.stringify(sent),
116
+ }).catch((error) => ({ error }));
117
+ if (upstream.error)
118
+ return answer(response, 502, {
119
+ error: { message: upstream.error.message },
120
+ });
121
+ response.writeHead(upstream.status, {
122
+ "content-type":
123
+ upstream.headers.get("content-type") ?? "application/json",
124
+ });
125
+ // Streamed or whole, as the model sends it.
126
+ for await (const chunk of upstream.body) response.write(chunk);
127
+ response.end();
128
+ };
129
+
130
+ return {
131
+ start() {
132
+ if (server) return Promise.resolve(server.address());
133
+ server = http.createServer((request, response) => {
134
+ handle(request, response).catch((error) => {
135
+ log(`model route: ${error.message}`);
136
+ if (!response.headersSent)
137
+ answer(response, 500, { error: { message: error.message } });
138
+ else response.end();
139
+ });
140
+ });
141
+ return new Promise((resolve) => {
142
+ server.listen(port, "127.0.0.1", () => {
143
+ const { port: bound } = server.address();
144
+ const url = `http://127.0.0.1:${bound}/v1`;
145
+ fs.mkdirSync(path.dirname(routeFile(home)), {
146
+ recursive: true,
147
+ mode: 0o700,
148
+ });
149
+ fs.writeFileSync(routeFile(home), JSON.stringify({ url }), {
150
+ mode: 0o600,
151
+ });
152
+ resolve({ url });
153
+ });
154
+ });
155
+ },
156
+ stop() {
157
+ server?.close();
158
+ server = null;
159
+ fs.rmSync(routeFile(home), { force: true });
160
+ },
161
+ };
162
+ }
@@ -4,9 +4,9 @@ import path from "node:path";
4
4
  import { harnessNode, paths } from "./paths.mjs";
5
5
 
6
6
  // The Harness extension finds the daemon on its own computer through Chrome's native messaging: Chrome starts this
7
- // host for the extension, one message in and one answer out, so the Harness window links to the computer it runs on
8
- // with no `tryharness link`. The host says which computer this is (its public key and name) and, asked, gets a link
9
- // offer for this browser once the person allows it on this computer; the page pairs with it through Harness, sealed.
7
+ // host for the extension, which listens through it for what this computer hands the Harness page (it opens a hidden
8
+ // page to take it) and tells it which page the person is on. The page itself reaches the computer over its line from
9
+ // the person's signed device list, never through this host.
10
10
  //
11
11
  // Only the extension named in the manifest's allowed_origins can start the host (Chrome enforces it). Its ID is fixed
12
12
  // by the public key in packages/browser-extension/manifest.json, the Chrome Web Store item's.
@@ -17,38 +17,85 @@ export const EXTENSION_IDS = ["ekdjlnkjchjplkadglnaolilhpnokgok"];
17
17
  const MAX_MESSAGE_BYTES = 64 * 1024;
18
18
 
19
19
  // Where each Chromium browser reads a person's own host manifests: its user data folder's NativeMessagingHosts.
20
+ // The well-known browsers by name, and any other Chromium browser found on this computer (Arc, Opera and the rest):
21
+ // a user data folder holds a "Local State" file and, for a browser that runs extensions, a profile with an Extensions
22
+ // folder. Electron apps keep a "Local State" too but run no extensions, so they get nothing.
20
23
  // A browser that is not installed (its folder absent) gets none.
21
- function browserFolders(platform, home) {
22
- if (platform === "darwin") {
23
- const support = path.join(home, "Library", "Application Support");
24
- return [
25
- "Google/Chrome",
26
- "Google/Chrome Beta",
27
- "Google/Chrome Canary",
28
- "Chromium",
29
- "BraveSoftware/Brave-Browser",
30
- "Microsoft Edge",
31
- "Vivaldi",
32
- ].map((folder) => path.join(support, folder));
24
+ const KNOWN_BROWSERS = {
25
+ darwin: [
26
+ "Google/Chrome",
27
+ "Google/Chrome Beta",
28
+ "Google/Chrome Canary",
29
+ "Chromium",
30
+ "BraveSoftware/Brave-Browser",
31
+ "Microsoft Edge",
32
+ "Vivaldi",
33
+ ],
34
+ linux: [
35
+ "google-chrome",
36
+ "google-chrome-beta",
37
+ "chromium",
38
+ "BraveSoftware/Brave-Browser",
39
+ "microsoft-edge",
40
+ "vivaldi",
41
+ ],
42
+ };
43
+
44
+ const listDir = (folder) => {
45
+ try {
46
+ return fs.readdirSync(folder, { withFileTypes: true });
47
+ } catch {
48
+ return [];
33
49
  }
34
- if (platform === "linux") {
35
- const config = process.env.XDG_CONFIG_HOME || path.join(home, ".config");
36
- return [
37
- "google-chrome",
38
- "google-chrome-beta",
39
- "chromium",
40
- "BraveSoftware/Brave-Browser",
41
- "microsoft-edge",
42
- "vivaldi",
43
- ].map((folder) => path.join(config, folder));
50
+ };
51
+
52
+ /** A Chromium user data folder whose browser runs extensions. */
53
+ const isExtensionBrowser = (folder) =>
54
+ fs.existsSync(path.join(folder, "Local State")) &&
55
+ listDir(folder).some(
56
+ (entry) =>
57
+ entry.isDirectory() &&
58
+ fs.existsSync(path.join(folder, entry.name, "Extensions"))
59
+ );
60
+
61
+ /** Every extension-running Chromium user data folder up to two levels under `root` ("Arc/User Data", "Opera"). */
62
+ function discoverBrowsers(root) {
63
+ const found = [];
64
+ for (const entry of listDir(root)) {
65
+ if (!entry.isDirectory()) continue;
66
+ const folder = path.join(root, entry.name);
67
+ if (isExtensionBrowser(folder)) {
68
+ found.push(folder);
69
+ continue;
70
+ }
71
+ for (const inner of listDir(folder))
72
+ if (
73
+ inner.isDirectory() &&
74
+ isExtensionBrowser(path.join(folder, inner.name))
75
+ )
76
+ found.push(path.join(folder, inner.name));
44
77
  }
45
- return [];
78
+ return found;
79
+ }
80
+
81
+ function browserFolders(platform, home) {
82
+ const root =
83
+ platform === "darwin"
84
+ ? path.join(home, "Library", "Application Support")
85
+ : platform === "linux"
86
+ ? process.env.XDG_CONFIG_HOME || path.join(home, ".config")
87
+ : null;
88
+ if (!root) return [];
89
+ const known = (KNOWN_BROWSERS[platform] ?? []).map((folder) =>
90
+ path.join(root, folder)
91
+ );
92
+ return [...new Set([...known, ...discoverBrowsers(root)])];
46
93
  }
47
94
 
48
95
  const manifestFor = (program) => ({
49
96
  name: HOST_NAME,
50
97
  description:
51
- "Harness: links the Harness window to the daemon on this computer",
98
+ "Harness: lets the Harness extension hear the daemon on this computer",
52
99
  path: program,
53
100
  type: "stdio",
54
101
  allowed_origins: EXTENSION_IDS.map((id) => `chrome-extension://${id}/`),
@@ -57,7 +104,7 @@ const manifestFor = (program) => ({
57
104
  /**
58
105
  * Installs the host for every Chromium browser on this computer: a launcher in Harness's folder that runs this
59
106
  * runtime's CLI, and a manifest beside each browser's profiles. Windows registers hosts in the registry instead, which
60
- * this does not do yet; there the person links with `tryharness link`.
107
+ * this does not do yet; there the extension does not wake a Harness page for the computer.
61
108
  */
62
109
  export function installNativeHost({
63
110
  runtimeRoot,
@@ -109,8 +156,8 @@ const shellQuote = (value) => `'${String(value).replaceAll("'", `'\\''`)}'`;
109
156
 
110
157
  /**
111
158
  * The host itself, run by Chrome: reads length-prefixed JSON messages on `input` and answers each on `output`.
112
- * `daemon(request)` is the daemon's control socket. Answers: `this-computer` with {publicKey, hostname, label, role},
113
- * `computer-offer` with a pairing link's fragment for this browser once the person allows it on this computer.
159
+ * `daemon(request)` is the daemon's control socket. Messages: `listen`, after which what the daemon hands the Harness
160
+ * page is passed on as `for-harness`, and `active-page`, the page the person is on.
114
161
  */
115
162
  export async function serveNativeHost({
116
163
  input,
@@ -149,65 +196,7 @@ export async function serveNativeHost({
149
196
  );
150
197
  return { ok: true };
151
198
  }
152
- try {
153
- if (message?.type === "this-computer") {
154
- const found = await daemon({ command: "phone.identity" });
155
- return found?.ok
156
- ? {
157
- ok: true,
158
- computer: {
159
- publicKey: found.publicKey,
160
- hostname: found.hostname,
161
- label: found.label ?? null,
162
- role: found.role ?? null,
163
- joined: found.joined !== false,
164
- connected: found.connected !== false,
165
- },
166
- }
167
- : { ok: false, error: found?.error || "the daemon did not say" };
168
- }
169
- // The page asking is served by Harness, so its word alone makes no offer: the daemon asks the person on this
170
- // computer, and the host waits for their answer (as long as the ask lasts, the offer's ten minutes).
171
- if (message?.type === "computer-offer") {
172
- let asked = null;
173
- do
174
- asked = await daemon(
175
- {
176
- command: "phone.link.ask",
177
- id: asked?.id ?? null,
178
- label: String(message.label ?? "").slice(0, 60),
179
- waitMs: 25_000,
180
- },
181
- 30_000
182
- );
183
- while (asked?.ok && asked.state === "waiting" && !closed);
184
- if (asked?.ok && asked.state === "allowed" && asked.url)
185
- return { ok: true, fragment: new URL(asked.url).hash };
186
- return {
187
- ok: false,
188
- code: asked?.state ?? "failed",
189
- error:
190
- asked?.state === "refused" || asked?.state === "expired"
191
- ? "the person did not allow this browser on this computer"
192
- : asked?.error || "no offer was made",
193
- };
194
- }
195
- // The extension itself asking to hold this browser's link (its deskKey.js), never a page's ask passed on: the
196
- // background sends this on its own, and the key it pairs stays in the extension.
197
- if (message?.type === "extension-link") {
198
- const made = await daemon({ command: "phone.link.extension" });
199
- return made?.ok && made.fragment
200
- ? { ok: true, fragment: made.fragment }
201
- : { ok: false, error: made?.error || "no offer was made" };
202
- }
203
- return { ok: false, error: "unknown message" };
204
- } catch (error) {
205
- // The daemon not running is the common case: setup was never finished here, or it stopped.
206
- return {
207
- ok: false,
208
- error: `the Harness daemon on this computer is not running (${error.message})`,
209
- };
210
- }
199
+ return { ok: false, error: "unknown message" };
211
200
  };
212
201
  let buffered = Buffer.alloc(0);
213
202
  for await (const chunk of input) {
@@ -229,7 +218,9 @@ export async function serveNativeHost({
229
218
  }
230
219
  closed = true;
231
220
  // The browser went: no page is the one the person is on any more.
232
- await daemon({ command: "browser.page.set", page: null }).catch(() => null);
221
+ await daemon({ command: "browser.page.set", page: null, gone: true }).catch(
222
+ () => null
223
+ );
233
224
  }
234
225
 
235
226
  export function writeMessage(output, message) {