tryharness 0.7.53 → 0.7.57

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 (167) hide show
  1. package/README.md +23 -19
  2. package/assets/dsh-plugin.mjs +72 -0
  3. package/assets/opencode-plugin.js +4 -3
  4. package/cli.mjs +484 -90
  5. package/lib/activity.mjs +10 -10
  6. package/lib/adapters.mjs +173 -222
  7. package/lib/agentBinaries.mjs +71 -0
  8. package/lib/agentRuntimeConfig.mjs +1 -1
  9. package/lib/agentRuntimes.mjs +34 -18
  10. package/lib/agentSignIn.mjs +456 -0
  11. package/lib/answers.mjs +5 -5
  12. package/lib/archetypes.d.ts +64 -0
  13. package/lib/archetypes.js +989 -0
  14. package/lib/asks.mjs +4 -4
  15. package/lib/audit.mjs +666 -0
  16. package/lib/backupSetup.mjs +143 -0
  17. package/lib/boardAccess.mjs +24 -11
  18. package/lib/boardBackup.mjs +283 -0
  19. package/lib/boardFileCommands.mjs +6 -6
  20. package/lib/boardFiles.mjs +13 -12
  21. package/lib/boardMirror.mjs +124 -25
  22. package/lib/boardProtocol.json +88 -2
  23. package/lib/boardWaits.mjs +101 -0
  24. package/lib/book.mjs +659 -0
  25. package/lib/bridge.mjs +6 -6
  26. package/lib/cards.mjs +138 -28
  27. package/lib/cloudAgents.mjs +216 -0
  28. package/lib/cloudAi.mjs +1312 -0
  29. package/lib/cloudAssistants.mjs +242 -0
  30. package/lib/cloudBoot.mjs +119 -0
  31. package/lib/cloudSave.mjs +197 -0
  32. package/lib/cloudSsh.mjs +178 -0
  33. package/lib/commands.mjs +7 -2
  34. package/lib/context.mjs +19 -5
  35. package/lib/contractGate.mjs +399 -0
  36. package/lib/control-client.mjs +9 -1
  37. package/lib/controlSocket.mjs +86 -0
  38. package/lib/coordinator.mjs +252 -144
  39. package/lib/daemon.mjs +1351 -2767
  40. package/lib/desk.mjs +240 -0
  41. package/lib/desktop.mjs +178 -74
  42. package/lib/directLink.mjs +16 -5
  43. package/lib/environment.mjs +2 -1
  44. package/lib/environments.mjs +247 -9
  45. package/lib/firewall.mjs +9 -9
  46. package/lib/folders.mjs +20 -16
  47. package/lib/frames.mjs +2 -3
  48. package/lib/gitHost.mjs +174 -0
  49. package/lib/goalCommands.mjs +25 -7
  50. package/lib/goals.mjs +7 -7
  51. package/lib/guestRequests.mjs +94 -0
  52. package/lib/handoffs.mjs +8 -7
  53. package/lib/handover.mjs +4 -4
  54. package/lib/harnessModel.mjs +6 -6
  55. package/lib/harnessOffers.mjs +266 -0
  56. package/lib/hookDialects.mjs +298 -0
  57. package/lib/inference.mjs +26 -8
  58. package/lib/jobAnswers.mjs +190 -0
  59. package/lib/landed.mjs +887 -0
  60. package/lib/lane.mjs +42 -11
  61. package/lib/lessons.mjs +16 -16
  62. package/lib/library.mjs +3 -3
  63. package/lib/lineup.mjs +3 -0
  64. package/lib/linkRelay.mjs +574 -0
  65. package/lib/live.mjs +284 -13
  66. package/lib/localAgentAsk.mjs +74 -0
  67. package/lib/localStack.mjs +536 -0
  68. package/lib/localmodels.mjs +6 -4
  69. package/lib/loopBackstop.mjs +4 -4
  70. package/lib/machineIdentity.mjs +9 -1
  71. package/lib/machineRoutes.mjs +181 -2
  72. package/lib/machineRuns.mjs +76 -1
  73. package/lib/machineSeal.mjs +39 -12
  74. package/lib/mcp-stdio.mjs +163 -27
  75. package/lib/mcpRelay.mjs +1 -1
  76. package/lib/members.json +29 -2
  77. package/lib/members.mjs +1 -1
  78. package/lib/models.mjs +85 -31
  79. package/lib/museSession.mjs +21 -13
  80. package/lib/nativeHost.mjs +36 -8
  81. package/lib/neovim.mjs +126 -0
  82. package/lib/network.mjs +50 -5
  83. package/lib/notify.mjs +7 -5
  84. package/lib/nudge.mjs +50 -19
  85. package/lib/ocr.mjs +9 -9
  86. package/lib/onboard.mjs +26 -20
  87. package/lib/oneLine.mjs +7 -7
  88. package/lib/ownMachines.mjs +1223 -140
  89. package/lib/pairing.mjs +60 -16
  90. package/lib/paths.mjs +19 -1
  91. package/lib/peerProcess.mjs +124 -0
  92. package/lib/personModel.mjs +89 -0
  93. package/lib/personNotices.mjs +151 -0
  94. package/lib/phones.mjs +538 -31
  95. package/lib/placeCommands.mjs +4 -4
  96. package/lib/places.mjs +400 -12
  97. package/lib/profile.mjs +67 -14
  98. package/lib/projectGit.mjs +158 -14
  99. package/lib/projectPieces.mjs +902 -0
  100. package/lib/projectSettings.mjs +7 -4
  101. package/lib/projects.mjs +384 -62
  102. package/lib/provenance.mjs +5 -1
  103. package/lib/proxyLinks.mjs +267 -0
  104. package/lib/reactions.mjs +7 -5
  105. package/lib/readiness.mjs +145 -23
  106. package/lib/record.mjs +128 -0
  107. package/lib/redact.mjs +4 -4
  108. package/lib/relayLimits.mjs +62 -0
  109. package/lib/release.mjs +170 -0
  110. package/lib/releaseKeys.json +6 -0
  111. package/lib/repoLinks.mjs +4 -4
  112. package/lib/roomChannels.mjs +24 -0
  113. package/lib/roomPage.mjs +1 -1
  114. package/lib/runAuthority.mjs +101 -0
  115. package/lib/runBrief.mjs +19 -8
  116. package/lib/runWorker.mjs +31 -7
  117. package/lib/runner.mjs +223 -29
  118. package/lib/runtime-install.mjs +143 -9
  119. package/lib/schedules.mjs +2 -2
  120. package/lib/screens.mjs +1 -1
  121. package/lib/sealed.mjs +11 -2
  122. package/lib/sealedThreads.mjs +671 -0
  123. package/lib/secretPatterns.json +1 -1
  124. package/lib/secrets.mjs +4 -4
  125. package/lib/seen.mjs +6 -6
  126. package/lib/serverWords.mjs +175 -0
  127. package/lib/service.mjs +22 -12
  128. package/lib/sessionControl.mjs +378 -90
  129. package/lib/specialties.json +74 -0
  130. package/lib/specialties.mjs +477 -0
  131. package/lib/specialtyKeys.d.ts +3 -0
  132. package/lib/specialtyKeys.js +57 -0
  133. package/lib/specialtyNotice.mjs +147 -0
  134. package/lib/specialtySnapshot.mjs +138 -0
  135. package/lib/speech.mjs +5 -5
  136. package/lib/store.mjs +420 -36
  137. package/lib/stuck.mjs +1 -1
  138. package/lib/swarm.mjs +304 -37
  139. package/lib/swarmDevices.mjs +319 -0
  140. package/lib/swarmMemory.mjs +27 -25
  141. package/lib/t3.mjs +24 -15
  142. package/lib/taskCommands.mjs +80 -20
  143. package/lib/taskRooms.mjs +125 -0
  144. package/lib/taskRuns.mjs +45 -3
  145. package/lib/team.json +255 -148
  146. package/lib/team.mjs +554 -190
  147. package/lib/threadActions.mjs +315 -0
  148. package/lib/threadAuthority.mjs +101 -0
  149. package/lib/threadBriefs.mjs +178 -0
  150. package/lib/threadLine.mjs +116 -0
  151. package/lib/threadRuns.mjs +209 -50
  152. package/lib/threadView.mjs +20 -7
  153. package/lib/usageTotals.mjs +2 -3
  154. package/lib/vault.mjs +101 -10
  155. package/lib/vaultCloud.mjs +2 -2
  156. package/lib/vaultCommands.mjs +15 -6
  157. package/lib/vaultTools.js +2 -2
  158. package/lib/verdicts.mjs +328 -0
  159. package/lib/wakes.mjs +1 -1
  160. package/lib/watches.mjs +2 -2
  161. package/lib/windowAsks.mjs +13 -5
  162. package/lib/worktrees.mjs +157 -25
  163. package/npm-shrinkwrap.json +1093 -0
  164. package/package.json +12 -11
  165. package/release.json +220 -0
  166. package/lib/modelTiers.json +0 -1183
  167. package/lib/modelTiers.mjs +0 -133
@@ -62,20 +62,28 @@ export async function openMuseSession({
62
62
  session?.hostExited(exit);
63
63
  });
64
64
  const verb = task.sessionId ? "session/resume" : "session/start";
65
+ // A readiness check (readiness.mjs) runs without Harness's tools.
65
66
  const config = {
66
- mcpServers: {
67
- harness: {
68
- transport: "stdio",
69
- mode: "required",
70
- command: process.execPath,
71
- args: [
72
- fileURLToPath(new URL("./mcp-stdio.mjs", import.meta.url)),
73
- "--agent",
74
- task.agent,
75
- ],
76
- env: { HARNESS_RUN_ID: task.runId },
77
- },
78
- },
67
+ mcpServers: task.withoutHarnessTools
68
+ ? {}
69
+ : {
70
+ harness: {
71
+ transport: "stdio",
72
+ mode: "required",
73
+ command: process.execPath,
74
+ args: [
75
+ fileURLToPath(new URL("./mcp-stdio.mjs", import.meta.url)),
76
+ "--agent",
77
+ task.agent,
78
+ ],
79
+ env: {
80
+ HARNESS_RUN_ID: task.runId,
81
+ ...(task.capability
82
+ ? { HARNESS_RUN_TOKEN: task.capability }
83
+ : {}),
84
+ },
85
+ },
86
+ },
79
87
  };
80
88
  signal.throwIfAborted();
81
89
  const result = await connection.command(verb, {
@@ -5,8 +5,8 @@ import { 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
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, makes a link
9
- // offer for this browser exactly as `tryharness link` does; the page pairs with it through Harness, sealed.
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.
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.
@@ -92,7 +92,7 @@ export function installNativeHost({
92
92
  return { installed, program };
93
93
  }
94
94
 
95
- /** Takes the host out of every browser and Harness's folder (`tryharness disconnect`). */
95
+ /** Takes the host out of every browser and Harness's folder (`tryharness uninstall`). */
96
96
  export function removeNativeHost({
97
97
  platform = process.platform,
98
98
  home = os.homedir(),
@@ -110,7 +110,7 @@ const shellQuote = (value) => `'${String(value).replaceAll("'", `'\\''`)}'`;
110
110
  /**
111
111
  * The host itself, run by Chrome: reads length-prefixed JSON messages on `input` and answers each on `output`.
112
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.
113
+ * `computer-offer` with a pairing link's fragment for this browser once the person allows it on this computer.
114
114
  */
115
115
  export async function serveNativeHost({
116
116
  input,
@@ -159,11 +159,39 @@ export async function serveNativeHost({
159
159
  }
160
160
  : { ok: false, error: found?.error || "the daemon did not say" };
161
161
  }
162
+ // The page asking is served by Harness, so its word alone makes no offer: the daemon asks the person on this
163
+ // computer, and the host waits for their answer (as long as the ask lasts, the offer's ten minutes).
162
164
  if (message?.type === "computer-offer") {
163
- const made = await daemon({ command: "phone.offer", kind: "browser" });
164
- if (!made?.ok || typeof made.url !== "string")
165
- return { ok: false, error: made?.error || "no offer was made" };
166
- return { ok: true, fragment: new URL(made.url).hash };
165
+ let asked = null;
166
+ do
167
+ asked = await daemon(
168
+ {
169
+ command: "phone.link.ask",
170
+ id: asked?.id ?? null,
171
+ label: String(message.label ?? "").slice(0, 60),
172
+ waitMs: 25_000,
173
+ },
174
+ 30_000
175
+ );
176
+ while (asked?.ok && asked.state === "waiting" && !closed);
177
+ if (asked?.ok && asked.state === "allowed" && asked.url)
178
+ return { ok: true, fragment: new URL(asked.url).hash };
179
+ return {
180
+ ok: false,
181
+ code: asked?.state ?? "failed",
182
+ error:
183
+ asked?.state === "refused" || asked?.state === "expired"
184
+ ? "the person did not allow this browser on this computer"
185
+ : asked?.error || "no offer was made",
186
+ };
187
+ }
188
+ // The extension itself asking to hold this browser's link (its deskKey.js), never a page's ask passed on: the
189
+ // background sends this on its own, and the key it pairs stays in the extension.
190
+ if (message?.type === "extension-link") {
191
+ const made = await daemon({ command: "phone.link.extension" });
192
+ return made?.ok && made.fragment
193
+ ? { ok: true, fragment: made.fragment }
194
+ : { ok: false, error: made?.error || "no offer was made" };
167
195
  }
168
196
  return { ok: false, error: "unknown message" };
169
197
  } catch (error) {
package/lib/neovim.mjs ADDED
@@ -0,0 +1,126 @@
1
+ import fs from "node:fs";
2
+ import os from "node:os";
3
+ import path from "node:path";
4
+ import { spawnSync } from "node:child_process";
5
+ import { hostApp, processTable, tmuxPlace } from "./live.mjs";
6
+
7
+ // A session in a Neovim terminal (:terminal), opened inside that Neovim. Neovim gives everything it runs in a terminal
8
+ // its own server's address ($NVIM), and answers there: any nvim can send it an expression (nvim --server <address>
9
+ // --remote-expr), which is how the session's terminal buffer is brought up, or a session resumed in a new tab. Neovim
10
+ // itself runs in a terminal app, whose tab (or tmux, WezTerm or kitty pane) then comes forward like any other's.
11
+
12
+ /** An nvim to speak to a server with: one running now (the daemon's PATH may not have it), else a usual install. */
13
+ function nvimBinary(table) {
14
+ const running = [...table.values()]
15
+ .map((row) => row.comm)
16
+ .filter((comm) => path.isAbsolute(comm) && path.basename(comm) === "nvim");
17
+ const usual = [
18
+ ...(process.env.PATH || "").split(path.delimiter),
19
+ "/opt/homebrew/bin",
20
+ "/usr/local/bin",
21
+ "/usr/bin",
22
+ "/snap/bin",
23
+ path.join(os.homedir(), ".local", "bin"),
24
+ path.join(os.homedir(), "bin"),
25
+ ]
26
+ .filter(Boolean)
27
+ .map((dir) => path.join(dir, "nvim"));
28
+ return [...running, ...usual].find((file) => fs.existsSync(file)) ?? null;
29
+ }
30
+
31
+ /**
32
+ * Runs a Lua chunk in the Neovim at `server`, with `data` as its argument; its answer as text, or null when no Neovim
33
+ * answers there. The chunk and data travel as one JSON value, which Vim script reads as its own list.
34
+ */
35
+ function inNeovim(server, code, data, table) {
36
+ if (typeof server !== "string" || !server) return null;
37
+ // A socket that is gone means a Neovim that closed: no nvim started to find that out.
38
+ if (path.isAbsolute(server) && !fs.existsSync(server)) return null;
39
+ const nvim = nvimBinary(table);
40
+ if (!nvim) return null;
41
+ const expr = `luaeval('(loadstring or load)(_A[1])(_A[2])', ${JSON.stringify([code, data])})`;
42
+ const ran = spawnSync(nvim, ["--server", server, "--remote-expr", expr], {
43
+ encoding: "utf8",
44
+ timeout: 3_000,
45
+ stdio: ["ignore", "pipe", "pipe"],
46
+ });
47
+ return ran.status === 0 ? ran.stdout.trim() : null;
48
+ }
49
+
50
+ /**
51
+ * The terminal Neovim shows in, from its server's process: the first process up from it on a terminal device (Neovim's
52
+ * own interface, since 0.10 a process of its own), with the app around it, or tmux's client for a Neovim in tmux.
53
+ */
54
+ function terminalOf(serverPid, table) {
55
+ for (let pid = serverPid, steps = 0; pid > 1 && steps < 8; steps++) {
56
+ const row = table.get(pid);
57
+ if (!row) return null;
58
+ if (row.tty)
59
+ return {
60
+ pid,
61
+ tty: row.tty,
62
+ host:
63
+ hostApp(table, pid) ??
64
+ tmuxPlace(table, row.tty)?.client?.host ??
65
+ null,
66
+ };
67
+ pid = row.ppid;
68
+ }
69
+ return null;
70
+ }
71
+
72
+ // The terminal buffer whose job is the session's process or one it runs under (a shell started with :terminal), shown
73
+ // in its window, else in a new tab, ready to type in.
74
+ const SHOW = `
75
+ local pids = ...
76
+ for _, buf in ipairs(vim.api.nvim_list_bufs()) do
77
+ local job = vim.bo[buf].buftype == "terminal" and vim.b[buf].terminal_job_pid
78
+ if job and pids[tostring(job)] then
79
+ local win = vim.fn.win_findbuf(buf)[1]
80
+ if win then vim.fn.win_gotoid(win) else vim.cmd("tab sbuffer " .. buf) end
81
+ vim.cmd.startinsert()
82
+ return vim.fn.getpid()
83
+ end
84
+ end
85
+ return 0`;
86
+
87
+ // A new tab on the folder, with the command in a terminal there, run by the person's own shell.
88
+ const RESUME = `
89
+ local command, cwd = (...)[1], (...)[2]
90
+ vim.cmd.tabnew()
91
+ if cwd ~= "" then vim.cmd.tcd(vim.fn.fnameescape(cwd)) end
92
+ if vim.fn.has("nvim-0.11") == 1 then vim.fn.jobstart(command, { term = true }) else vim.fn.termopen(command) end
93
+ vim.cmd.startinsert()
94
+ return vim.fn.getpid()`;
95
+
96
+ const shownAt = (answer, table) => {
97
+ const pid = Number(answer);
98
+ return Number.isInteger(pid) && pid > 1 ? terminalOf(pid, table) : null;
99
+ };
100
+
101
+ /**
102
+ * Brings up the terminal buffer a running session is in, in the Neovim at `server`: the terminal Neovim runs in
103
+ * ({ pid, tty, host }, to come forward as any terminal does), or null when that Neovim does not answer or has no such
104
+ * buffer.
105
+ */
106
+ export function showInNeovim(server, sessionPid, table = processTable()) {
107
+ const pids = {};
108
+ for (let pid = sessionPid, steps = 0; pid > 1 && steps < 16; steps++) {
109
+ pids[String(pid)] = 1;
110
+ pid = table.get(pid)?.ppid ?? 0;
111
+ }
112
+ return shownAt(inNeovim(server, SHOW, pids, table), table);
113
+ }
114
+
115
+ /** Runs `command` (a session's resume) in a new terminal tab of the Neovim at `server`; as showInNeovim. */
116
+ export function resumeInNeovim(
117
+ server,
118
+ command,
119
+ folder,
120
+ table = processTable()
121
+ ) {
122
+ return shownAt(
123
+ inNeovim(server, RESUME, [command, folder ?? ""], table),
124
+ table
125
+ );
126
+ }
package/lib/network.mjs CHANGED
@@ -22,6 +22,8 @@ export function createNetwork({
22
22
  myKey,
23
23
  // A relay thread that carries a shared project (projects.mjs): Swarms lists the project, not the thread under it.
24
24
  isChannel = () => false,
25
+ // The person blocked a handle: whatever is open with them on this computer ends (security audit P9).
26
+ blocked = () => {},
25
27
  }) {
26
28
  // Harness answers for the server's half; a refusal comes back as a plain error the person can read.
27
29
  const harness = async (input) => {
@@ -35,7 +37,21 @@ export function createNetwork({
35
37
  // One row per request or thread, grouped by what it needs: the person (a request to answer, a held reply,
36
38
  // a message from a person), nothing (open), the other side (a request not answered yet), or nobody (ended).
37
39
  const conversations = async () => {
38
- const server = await harness({ op: "threads" }).catch(() => null);
40
+ const [server, card] = await Promise.all([
41
+ harness({ op: "threads" }).catch(() => null),
42
+ harness({ op: "card" }).catch(() => null),
43
+ ]);
44
+ // A block made where this computer did not hear it (the dashboard while it was off) ends what is open here too.
45
+ for (const handle of Array.isArray(card?.blocks) ? card.blocks : [])
46
+ if (
47
+ store
48
+ .relayThreads()
49
+ .some(
50
+ (row) =>
51
+ !row.closed_at && handleOf(row.with_agent) === handleOf(handle)
52
+ )
53
+ )
54
+ blocked(handleOf(handle));
39
55
  const local = new Map(
40
56
  store.relayThreads().map((row) => [row.task_id, row])
41
57
  );
@@ -54,6 +70,7 @@ export function createNetwork({
54
70
  const opened = await openRelayRequest({
55
71
  sealed: thread.sealed,
56
72
  from: `${peer.handle}/${peer.agent}`,
73
+ id: thread.role === "target" ? thread.id : null,
57
74
  }).catch(() => null);
58
75
  if (opened) {
59
76
  about = opened.about;
@@ -221,14 +238,28 @@ export function createNetwork({
221
238
  return answered(conversations());
222
239
  // The server's half of Swarms (card, search, contacts, blocks): what the dashboard asks Harness directly.
223
240
  case "board.relay.network": {
224
- const { command: _command, agent: _agent, ...input } = request;
241
+ // Only the operation's own fields go to Harness, which refuses any other (a browser's call adds fromWindow and
242
+ // sealedBy, phones.mjs).
243
+ const {
244
+ command: _command,
245
+ agent: _agent,
246
+ fromWindow: _fromWindow,
247
+ hostedCaller: _hosted,
248
+ provenance: _provenance,
249
+ sealedBy: _sealedBy,
250
+ ...input
251
+ } = request;
225
252
  if (input.op === "decide" || input.op === "threads")
226
253
  return {
227
254
  ok: false,
228
255
  error: "use board.relay.decide and board.relay.list",
229
256
  };
230
257
  return answered(
231
- harness(input).then((answer) => ({ ok: true, ...answer }))
258
+ harness(input).then((answer) => {
259
+ if (input.op === "block" && input.on === true)
260
+ blocked(handleOf(input.handle));
261
+ return { ok: true, ...answer };
262
+ })
232
263
  );
233
264
  }
234
265
  case "board.relay.decide":
@@ -239,7 +270,11 @@ export function createNetwork({
239
270
  op: "decide",
240
271
  id,
241
272
  decision: String(request.decision),
242
- }).then((answer) => ({ ok: true, ...answer }))
273
+ }).then((answer) => {
274
+ if (request.decision === "block" && answer.thread?.asker?.handle)
275
+ blocked(handleOf(answer.thread.asker.handle));
276
+ return { ok: true, ...answer };
277
+ })
243
278
  );
244
279
  // A request from this computer: to one of their listed agents from one of the person's, or to the person themselves.
245
280
  case "board.relay.request": {
@@ -256,6 +291,7 @@ export function createNetwork({
256
291
  about: request.about,
257
292
  brief: request.brief,
258
293
  refs: request.refs,
294
+ readable: request.readable === true,
259
295
  }).then((made) => ({ ok: true, ...made }))
260
296
  );
261
297
  }
@@ -310,5 +346,14 @@ export function createNetwork({
310
346
  return answer.card?.handle ?? null;
311
347
  };
312
348
 
313
- return { command, opened, invites, sentProjects, decide, myHandle };
349
+ return {
350
+ command,
351
+ opened,
352
+ invites,
353
+ sentProjects,
354
+ decide,
355
+ myHandle,
356
+ // Harness says the person blocked a handle from another of their screens.
357
+ blockedElsewhere: (handle) => blocked(handleOf(handle)),
358
+ };
314
359
  }
package/lib/notify.mjs CHANGED
@@ -9,7 +9,7 @@ import { nameOf } from "./members.mjs";
9
9
 
10
10
  const TITLE = "Harness";
11
11
 
12
- function command(platform, title, body, env) {
12
+ export function command(platform, title, body, env) {
13
13
  if (env.HARNESS_NOTIFY_COMMAND)
14
14
  return { command: env.HARNESS_NOTIFY_COMMAND, args: [title, body] };
15
15
  if (platform === "darwin") {
@@ -25,17 +25,18 @@ function command(platform, title, body, env) {
25
25
  }
26
26
  if (platform === "linux")
27
27
  return { command: "notify-send", args: [title, body] };
28
- if (platform === "win32") {
29
- const quote = (value) => String(value).replaceAll("'", "''");
28
+ // The words go in through the environment, never into the script: PowerShell also ends a quoted string at the
29
+ // typographic quotes an agent's words can carry, so no escaping of them inside a script is safe.
30
+ if (platform === "win32")
30
31
  return {
31
32
  command: "powershell",
32
33
  args: [
33
34
  "-NoProfile",
34
35
  "-Command",
35
- `[void][System.Reflection.Assembly]::LoadWithPartialName('System.Windows.Forms'); $n = New-Object System.Windows.Forms.NotifyIcon; $n.Icon = [System.Drawing.SystemIcons]::Information; $n.Visible = $true; $n.ShowBalloonTip(8000, '${quote(title)}', '${quote(body)}', 'Info'); Start-Sleep -Seconds 9; $n.Dispose()`,
36
+ "[void][System.Reflection.Assembly]::LoadWithPartialName('System.Windows.Forms'); $n = New-Object System.Windows.Forms.NotifyIcon; $n.Icon = [System.Drawing.SystemIcons]::Information; $n.Visible = $true; $n.ShowBalloonTip(8000, $env:HARNESS_NOTICE_TITLE, $env:HARNESS_NOTICE_BODY, 'Info'); Start-Sleep -Seconds 9; $n.Dispose()",
36
37
  ],
38
+ env: { HARNESS_NOTICE_TITLE: title, HARNESS_NOTICE_BODY: body },
37
39
  };
38
- }
39
40
  return null;
40
41
  }
41
42
 
@@ -49,6 +50,7 @@ export function notifyDesktop(
49
50
  const child = spawn(call.command, call.args, {
50
51
  stdio: "ignore",
51
52
  detached: true,
53
+ ...(call.env ? { env: { ...env, ...call.env } } : {}),
52
54
  });
53
55
  child.on("error", () => {});
54
56
  child.unref();
package/lib/nudge.mjs CHANGED
@@ -8,6 +8,7 @@ import { placeEnv } from "./places.mjs";
8
8
  import { fitSections } from "./fit.mjs";
9
9
  import { oneLine } from "./oneLine.mjs";
10
10
  import { SWARM_HEADER } from "./cards.mjs";
11
+ import { hookDialect, hookInput } from "./hookDialects.mjs";
11
12
 
12
13
  // The session-start nudge: what an interactive agent is told when a session opens, so work
13
14
  // waiting on the board is not silent until someone asks. Claude Code runs this as a
@@ -15,9 +16,9 @@ import { SWARM_HEADER } from "./cards.mjs";
15
16
  // import this file from the runtime and call the same functions. Nothing waiting, or no daemon, prints nothing.
16
17
 
17
18
  // What a session start may carry. Claude Code 2.1.304 cuts an MCP server's instructions at 4,096 characters and ends
18
- // them "… [truncated]" (its CLAUDE_CODE_MAX_MCP_DESCRIPTION_LENGTH default); a session on the owner's machine on October
19
- // 20 got its handshake cut that way, the last agent cards lost. No client cut a shorter one, so the hook's text keeps to
20
- // the same budget, and the handshake to what is left of it after the server's own instructions (mcp-stdio.mjs).
19
+ // them "… [truncated]" (its CLAUDE_CODE_MAX_MCP_DESCRIPTION_LENGTH default); a real session got its handshake cut that
20
+ // way, the last agent cards lost. No client cut a shorter one, so the hook's text keeps to the same budget, and the
21
+ // handshake to what is left of it after the server's own instructions (mcp-stdio.mjs).
21
22
  export const HANDSHAKE_LIMIT = 4_096;
22
23
  // Each list names this many before saying how many more list_tasks has.
23
24
  const LISTED = 5;
@@ -327,11 +328,37 @@ export async function boardNudgeIfChanged(agent, homeDir = paths.home) {
327
328
  ).text;
328
329
  }
329
330
 
331
+ // Other agents read Claude Code's own config files: Devin CLI, Grok Build, Cursor, Cortex Code and Continue's cn run the
332
+ // hooks in ~/.claude/settings.json, and Devin, Cortex Code and Warp start the MCP servers in ~/.claude.json (their
333
+ // docs, October 23, 2026). The entries setup writes there would run inside them under Claude Code's name, so they carry
334
+ // --check-host and stand down unless Claude Code started them: Claude Code 2.1.309 sets CLAUDECODE=1 for every process
335
+ // it starts (hooks, MCP servers, shells). Grok Build likewise runs Cursor's hooks and starts the servers in Cursor's
336
+ // config: it marks every hook it runs (GROK_HOOK_EVENT), and a server it starts is its child. Harness's own runs name
337
+ // the agent they start and are not checked.
338
+ export const startedByAnother = (
339
+ agent,
340
+ env = process.env,
341
+ parent = () => processName(process.ppid)
342
+ ) => {
343
+ if (agent === "claude-code") return env.CLAUDECODE !== "1";
344
+ if (agent === "cursor")
345
+ return Boolean(env.GROK_HOOK_EVENT) || parent() === "grok";
346
+ return false;
347
+ };
348
+
330
349
  // The prompt hook also tells the daemon the person typed in this session: the agent process is the hook's parent, or
331
350
  // its grandparent when the hook runs through a shell.
332
351
  export const PS =
333
352
  ["/bin/ps", "/usr/bin/ps"].find((file) => fs.existsSync(file)) || "ps";
334
353
 
354
+ function processName(pid) {
355
+ return path.basename(
356
+ spawnSync(PS, ["-o", "comm=", "-p", String(pid)], {
357
+ encoding: "utf8",
358
+ }).stdout?.trim() ?? ""
359
+ );
360
+ }
361
+
335
362
  function agentPids() {
336
363
  const pids = [process.ppid];
337
364
  try {
@@ -425,8 +452,8 @@ export function messagesText(messages) {
425
452
  .join("\n\n");
426
453
  }
427
454
 
428
- // The JSON the agent hands every hook on stdin (session_id among it); null when there is none.
429
- async function hookInput() {
455
+ // The JSON the agent hands every hook on stdin, in its own words (hookDialects.mjs hookInput); null when there is none.
456
+ async function readHookInput() {
430
457
  if (process.stdin.isTTY) return null;
431
458
  let text = "";
432
459
  process.stdin.setEncoding("utf8");
@@ -443,7 +470,7 @@ async function hookInput() {
443
470
  ]);
444
471
  process.stdin.destroy();
445
472
  try {
446
- return JSON.parse(text);
473
+ return hookInput(JSON.parse(text));
447
474
  } catch {
448
475
  return null;
449
476
  }
@@ -452,34 +479,38 @@ async function hookInput() {
452
479
  if (import.meta.url === `file://${process.argv[1]}`) {
453
480
  const index = process.argv.indexOf("--agent");
454
481
  const agent = index >= 0 ? process.argv[index + 1] : "claude-code";
455
- const input = await hookInput();
482
+ if (process.argv.includes("--check-host") && startedByAnother(agent))
483
+ process.exit(0);
484
+ const dialect = hookDialect(agent);
485
+ const input = await readHookInput();
456
486
  const sessionId = input?.session_id;
487
+ const prompted = process.argv.includes("--if-changed");
457
488
  if (process.argv.includes("--stop")) {
489
+ // A stop that is not a turn ending (Grok's as a session closes) cannot keep anything going: a message taken then
490
+ // would be lost.
491
+ if (input && !input.endsTurn) process.exit(0);
458
492
  // The Stop hook: a message waiting for this session keeps the agent going with it.
459
493
  const messages = await takeMessages(agent, sessionId);
460
494
  if (messages.length)
461
- process.stdout.write(
462
- JSON.stringify({ decision: "block", reason: messagesText(messages) }) +
463
- "\n"
464
- );
495
+ process.stdout.write(dialect.block(messagesText(messages)) + "\n");
465
496
  else await noteTurn(agent, input);
466
497
  } else {
467
- if (process.argv.includes("--if-changed")) await notePrompt(agent, input);
498
+ if (prompted) await notePrompt(agent, input);
468
499
  else await notePlace(agent, input);
469
- const messages = process.argv.includes("--if-changed")
470
- ? await takeMessages(agent, sessionId)
471
- : [];
500
+ // An agent that does not read what this hook prints: nothing is taken or marked as told.
501
+ const speak =
502
+ dialect.context[prompted ? "UserPromptSubmit" : "SessionStart"];
503
+ if (!speak) process.exit(0);
504
+ const messages = prompted ? await takeMessages(agent, sessionId) : [];
472
505
  const compacted =
473
506
  input?.source === "compact" ? await compactionNote(agent, sessionId) : "";
474
507
  const text = [
475
508
  compacted,
476
509
  messages.length ? messagesText(messages) : "",
477
- process.argv.includes("--if-changed")
478
- ? await boardNudgeIfChanged(agent)
479
- : await boardNudge(agent),
510
+ prompted ? await boardNudgeIfChanged(agent) : await boardNudge(agent),
480
511
  ]
481
512
  .filter(Boolean)
482
513
  .join("\n\n");
483
- if (text) process.stdout.write(text + "\n");
514
+ if (text) process.stdout.write(speak(text) + "\n");
484
515
  }
485
516
  }
package/lib/ocr.mjs CHANGED
@@ -197,12 +197,12 @@ function regions(map, width, height) {
197
197
  return boxes;
198
198
  }
199
199
 
200
- // The detector's memory grows with its input (about 1 KB a pixel: 1.6 GB for a 2048x1280 screenshot, measured
201
- // October 14), and ONNX Runtime keeps memory for every input shape it has run. So the detector reads full-width bands
202
- // WINDOW rows tall, always the same shape (rows past the image and columns up to a multiple of 512 repeat its edge), and
203
- // the probability map is stitched from rows at least MARGIN from a band's edge. Lines are never cut: regions are found
204
- // on the whole map. On the image-redaction eval's screens this found what one pass did, and the OCR models' memory
205
- // levelled off at 544 MB instead of growing past 2 GB (160-row bands; 256 rows: 766 MB and about 10% faster).
200
+ // The detector's memory grows with its input (measured at about 1 KB a pixel: 1.6 GB for a 2048x1280 screenshot), and
201
+ // ONNX Runtime keeps memory for every input shape it has run. So the detector reads full-width bands WINDOW rows tall,
202
+ // always the same shape (rows past the image and columns up to a multiple of 512 repeat its edge), and the probability
203
+ // map is stitched from rows at least MARGIN from a band's edge. Lines are never cut: regions are found on the whole
204
+ // map. On a fixed set of test screenshots this found what one pass did, and the OCR models' memory levelled off at
205
+ // 544 MB instead of growing past 2 GB (160-row bands; 256 rows: 766 MB and about 10% faster).
206
206
  const BAND = 160,
207
207
  MARGIN = 32,
208
208
  WINDOW = BAND + 2 * MARGIN;
@@ -262,9 +262,9 @@ async function detect(image, { ort, graph }) {
262
262
  .filter(([x0, y0, x1, y1]) => x1 - x0 >= 4 && y1 - y0 >= 4);
263
263
  }
264
264
 
265
- // ONNX Runtime keeps memory for every input shape it has run (400 crop widths: 108 MB grew to 513 MB, October 14), so
266
- // crops are padded on the right to a few widths, with 0 after normalization as PaddleOCR's own batches pad. Over this
267
- // eval's screens that changed 16 of 845 lines, by spacing or a dash, none of a planted value.
265
+ // ONNX Runtime keeps memory for every input shape it has run (400 crop widths: 108 MB grew to 513 MB), so crops are
266
+ // padded on the right to a few widths, with 0 after normalization as PaddleOCR's own batches pad. Over the same test
267
+ // screenshots, that changed 16 of 845 lines, by spacing or a dash, none of a planted value.
268
268
  const bucket = (width) =>
269
269
  width <= 512 ? Math.ceil(width / 32) * 32 : Math.ceil(width / 64) * 64;
270
270