tryharness 0.7.53 → 0.7.54

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (69) hide show
  1. package/README.md +10 -5
  2. package/assets/dsh-plugin.mjs +72 -0
  3. package/assets/opencode-plugin.js +4 -3
  4. package/cli.mjs +115 -36
  5. package/lib/adapters.mjs +157 -222
  6. package/lib/agentRuntimes.mjs +26 -16
  7. package/lib/agentSignIn.mjs +226 -0
  8. package/lib/audit.mjs +643 -0
  9. package/lib/backupSetup.mjs +141 -0
  10. package/lib/boardAccess.mjs +8 -1
  11. package/lib/boardBackup.mjs +283 -0
  12. package/lib/boardMirror.mjs +71 -7
  13. package/lib/boardProtocol.json +59 -2
  14. package/lib/boardWaits.mjs +102 -0
  15. package/lib/book.mjs +659 -0
  16. package/lib/bridge.mjs +1 -1
  17. package/lib/cards.mjs +138 -28
  18. package/lib/cloudBoot.mjs +124 -0
  19. package/lib/commands.mjs +7 -2
  20. package/lib/context.mjs +18 -4
  21. package/lib/contractGate.mjs +377 -0
  22. package/lib/coordinator.mjs +149 -43
  23. package/lib/daemon.mjs +349 -28
  24. package/lib/desk.mjs +239 -0
  25. package/lib/desktop.mjs +106 -6
  26. package/lib/environments.mjs +237 -7
  27. package/lib/folders.mjs +2 -2
  28. package/lib/gitHost.mjs +174 -0
  29. package/lib/hookDialects.mjs +298 -0
  30. package/lib/landed.mjs +887 -0
  31. package/lib/live.mjs +284 -13
  32. package/lib/mcp-stdio.mjs +68 -2
  33. package/lib/members.json +16 -2
  34. package/lib/models.mjs +8 -8
  35. package/lib/museSession.mjs +16 -13
  36. package/lib/nativeHost.mjs +1 -1
  37. package/lib/neovim.mjs +126 -0
  38. package/lib/nudge.mjs +47 -16
  39. package/lib/ownMachines.mjs +343 -39
  40. package/lib/pairing.mjs +27 -10
  41. package/lib/paths.mjs +4 -0
  42. package/lib/personModel.mjs +89 -0
  43. package/lib/phones.mjs +66 -11
  44. package/lib/places.mjs +330 -10
  45. package/lib/readiness.mjs +135 -18
  46. package/lib/record.mjs +115 -0
  47. package/lib/runWorker.mjs +17 -2
  48. package/lib/runner.mjs +8 -4
  49. package/lib/sessionControl.mjs +377 -89
  50. package/lib/specialties.json +74 -0
  51. package/lib/specialties.mjs +477 -0
  52. package/lib/specialtyKeys.d.ts +3 -0
  53. package/lib/specialtyKeys.js +58 -0
  54. package/lib/specialtyNotice.mjs +147 -0
  55. package/lib/specialtySnapshot.mjs +138 -0
  56. package/lib/store.mjs +284 -1
  57. package/lib/swarm.mjs +137 -21
  58. package/lib/t3.mjs +13 -4
  59. package/lib/taskCommands.mjs +36 -9
  60. package/lib/taskRuns.mjs +9 -2
  61. package/lib/team.json +255 -148
  62. package/lib/team.mjs +529 -188
  63. package/lib/threadLine.mjs +116 -0
  64. package/lib/threadRuns.mjs +75 -11
  65. package/lib/threadView.mjs +15 -2
  66. package/lib/worktrees.mjs +51 -13
  67. package/package.json +4 -4
  68. package/lib/modelTiers.json +0 -1183
  69. package/lib/modelTiers.mjs +0 -133
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/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
@@ -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
  }