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
@@ -0,0 +1,298 @@
1
+ import fs from "node:fs";
2
+ import os from "node:os";
3
+ import path from "node:path";
4
+ import { ensureDir, readJson } from "./files.mjs";
5
+
6
+ // How each agent runs session hooks: the file it reads them from, that file's shape, and what it does with a hook's
7
+ // output. Harness hooks three moments, by the names Claude Code gave them: a session starting (its board notice, where it
8
+ // runs), the person's prompt (what changed, and a message from Harness), and a turn ending (a message from Harness keeps
9
+ // it going). Setup writes each agent's file from here (installSessionHooks); nudge.mjs answers each agent in its own
10
+ // words (hookDialect). Every other setting and hook in a file is kept; setup replaces Harness's entries and uninstall
11
+ // takes only them out. Read from each agent's own docs and source, October 2026.
12
+ export const HOOK_EVENTS = ["SessionStart", "UserPromptSubmit", "Stop"];
13
+
14
+ const isHarnessHook = (entry) =>
15
+ JSON.stringify(entry).includes("/lib/nudge.mjs");
16
+ const objectOr = (value) =>
17
+ value && typeof value === "object" && !Array.isArray(value) ? value : {};
18
+ const withOurs = (list, ours) => [
19
+ ...(Array.isArray(list) ? list : []).filter((entry) => !isHarnessHook(entry)),
20
+ ...(ours ? [ours] : []),
21
+ ];
22
+
23
+ // Claude Code's shape: settings.hooks[event] holds [{ matcher?, hooks: [{ type: "command", command, timeout }] }].
24
+ const claudeShape = ({ start = {}, startHook = {} } = {}) => ({
25
+ write: (settings, commands) => {
26
+ const hooks = objectOr(settings.hooks);
27
+ const next = { ...hooks };
28
+ for (const event of HOOK_EVENTS) {
29
+ const hook = { type: "command", command: commands[event] };
30
+ next[event] = withOurs(
31
+ hooks[event],
32
+ event === "SessionStart"
33
+ ? { ...start, hooks: [{ ...hook, ...startHook, timeout: 10 }] }
34
+ : { hooks: [{ ...hook, timeout: 10 }] }
35
+ );
36
+ }
37
+ return { ...settings, hooks: next };
38
+ },
39
+ erase: (settings) => {
40
+ if (!settings.hooks) return settings;
41
+ const hooks = { ...objectOr(settings.hooks) };
42
+ for (const event of HOOK_EVENTS)
43
+ if (Array.isArray(hooks[event])) hooks[event] = withOurs(hooks[event]);
44
+ return { ...settings, hooks };
45
+ },
46
+ });
47
+
48
+ // A versioned file of the agent's own event names, one flat entry per hook (Copilot, Cursor).
49
+ const flatShape = ({ names, entry }) => ({
50
+ write: (settings, commands) => {
51
+ const hooks = objectOr(settings.hooks);
52
+ const next = { ...hooks };
53
+ for (const event of HOOK_EVENTS)
54
+ next[names[event]] = withOurs(
55
+ hooks[names[event]],
56
+ entry(commands[event])
57
+ );
58
+ return { ...settings, version: settings.version ?? 1, hooks: next };
59
+ },
60
+ erase: (settings) => {
61
+ if (!settings.hooks) return settings;
62
+ const hooks = { ...objectOr(settings.hooks) };
63
+ for (const event of HOOK_EVENTS)
64
+ if (Array.isArray(hooks[names[event]]))
65
+ hooks[names[event]] = withOurs(hooks[names[event]]);
66
+ return { ...settings, hooks };
67
+ },
68
+ });
69
+
70
+ // Antigravity's file holds named sets of hooks; Harness's is the set named "harness".
71
+ const namedShape = ({ name, names }) => ({
72
+ write: (settings, commands) => ({
73
+ ...settings,
74
+ [name]: Object.fromEntries(
75
+ HOOK_EVENTS.map((event) => [
76
+ names[event],
77
+ [{ type: "command", command: commands[event], timeout: 10 }],
78
+ ])
79
+ ),
80
+ }),
81
+ erase: (settings) => {
82
+ if (!(name in settings)) return settings;
83
+ const { [name]: _ours, ...rest } = settings;
84
+ return rest;
85
+ },
86
+ });
87
+
88
+ const asText = (text) => text;
89
+ const claudeBlock = (text) =>
90
+ JSON.stringify({ decision: "block", reason: text });
91
+
92
+ const DIALECTS = {
93
+ // Other agents read Claude Code's files and run its hooks as their own: --check-host (nudge.mjs startedByAnother).
94
+ "claude-code": {
95
+ file: (home) => path.join(home, ".claude", "settings.json"),
96
+ shape: claudeShape(),
97
+ flags: ["--check-host"],
98
+ context: { SessionStart: asText, UserPromptSubmit: asText },
99
+ block: claudeBlock,
100
+ },
101
+ // Codex runs the session-start hook after a compaction too, so the session hears its work again (compaction.mjs).
102
+ // It asks the person to trust a new or changed hook once, with /hooks in its TUI, before it runs; setup says so.
103
+ codex: {
104
+ file: (home) => path.join(home, ".codex", "hooks.json"),
105
+ shape: claudeShape({
106
+ start: { matcher: "startup|resume|compact" },
107
+ startHook: { statusMessage: "Reading the Harness board" },
108
+ }),
109
+ context: { SessionStart: asText, UserPromptSubmit: asText },
110
+ block: claudeBlock,
111
+ },
112
+ // Grok Build reads every JSON file in ~/.grok/hooks, so Harness's hooks are a file of their own. It ignores what its
113
+ // session-start and prompt hooks print: its notice comes in the MCP server's instructions.
114
+ "grok-build": {
115
+ file: (home, env) =>
116
+ path.join(
117
+ env.GROK_HOME || path.join(home, ".grok"),
118
+ "hooks",
119
+ "harness.json"
120
+ ),
121
+ ownFile: true,
122
+ shape: claudeShape(),
123
+ context: {},
124
+ block: claudeBlock,
125
+ },
126
+ // Copilot's CLI reads every JSON file in ~/.copilot/hooks. Only JSON from its session-start hook reaches the model;
127
+ // its prompt hook's output is dropped.
128
+ copilot: {
129
+ file: (home, env) =>
130
+ path.join(
131
+ env.COPILOT_HOME || path.join(home, ".copilot"),
132
+ "hooks",
133
+ "harness.json"
134
+ ),
135
+ ownFile: true,
136
+ shape: flatShape({
137
+ names: {
138
+ SessionStart: "sessionStart",
139
+ UserPromptSubmit: "userPromptSubmitted",
140
+ Stop: "agentStop",
141
+ },
142
+ entry: (command) => ({ type: "command", bash: command, timeoutSec: 10 }),
143
+ }),
144
+ context: {
145
+ SessionStart: (text) => JSON.stringify({ additionalContext: text }),
146
+ },
147
+ block: claudeBlock,
148
+ },
149
+ // Cursor (its CLI and its app) reads ~/.cursor/hooks.json, which the person's own hooks share. Its prompt hook cannot
150
+ // add context; its stop hook hands back a follow-up the agent sends as the person's next message. Grok Build runs
151
+ // this file too: --check-host.
152
+ cursor: {
153
+ file: (home) => path.join(home, ".cursor", "hooks.json"),
154
+ shape: flatShape({
155
+ names: {
156
+ SessionStart: "sessionStart",
157
+ UserPromptSubmit: "beforeSubmitPrompt",
158
+ Stop: "stop",
159
+ },
160
+ entry: (command) => ({ command, timeout: 10 }),
161
+ }),
162
+ flags: ["--check-host"],
163
+ context: {
164
+ SessionStart: (text) => JSON.stringify({ additional_context: text }),
165
+ },
166
+ block: (text) => JSON.stringify({ followup_message: text }),
167
+ },
168
+ // Antigravity reads ~/.gemini/config/hooks.json (CLI, app and IDE). It has no prompt event: PreInvocation runs before
169
+ // each model call. Its session start does not run when a conversation is resumed, and a stop that continues adds the
170
+ // message as a system message.
171
+ antigravity: {
172
+ file: (home) => path.join(home, ".gemini", "config", "hooks.json"),
173
+ shape: namedShape({
174
+ name: "harness",
175
+ names: {
176
+ SessionStart: "SessionStart",
177
+ UserPromptSubmit: "PreInvocation",
178
+ Stop: "Stop",
179
+ },
180
+ }),
181
+ context: {
182
+ SessionStart: (text) =>
183
+ JSON.stringify({
184
+ injectSteps: [{ systemMessage: { systemMessage: text } }],
185
+ }),
186
+ },
187
+ block: (text) => JSON.stringify({ decision: "continue", reason: text }),
188
+ },
189
+ // Devin's CLI keeps its hooks in its config.json (beside its other settings), in Claude Code's shape, and takes
190
+ // context only as JSON. It also runs Claude Code's hooks, which stand down there (--check-host).
191
+ devin: {
192
+ file: (home) => path.join(home, ".config", "devin", "config.json"),
193
+ shape: claudeShape(),
194
+ context: {
195
+ SessionStart: (text) =>
196
+ JSON.stringify({
197
+ hookSpecificOutput: {
198
+ hookEventName: "SessionStart",
199
+ additionalContext: text,
200
+ },
201
+ }),
202
+ UserPromptSubmit: (text) =>
203
+ JSON.stringify({
204
+ hookSpecificOutput: {
205
+ hookEventName: "UserPromptSubmit",
206
+ additionalContext: text,
207
+ },
208
+ }),
209
+ },
210
+ block: claudeBlock,
211
+ },
212
+ };
213
+
214
+ /** The agents Harness writes session hooks for. */
215
+ export const HOOK_AGENTS = Object.keys(DIALECTS);
216
+
217
+ /** How an agent reads a hook's output; an agent Harness does not know is answered as Claude Code is. */
218
+ export function hookDialect(agent) {
219
+ return DIALECTS[agent] ?? DIALECTS["claude-code"];
220
+ }
221
+
222
+ /**
223
+ * What a hook hands nudge.mjs, whatever the agent called it: the session (session_id, sessionId, Cursor's
224
+ * conversation_id, Antigravity's conversationId), its folder (cwd, or the first workspace root), and whether this is a
225
+ * turn ending. Grok Build also runs its Stop hooks as a session closes (reason "channel_closed" or "shutdown") and
226
+ * ignores their answer there.
227
+ */
228
+ export function hookInput(raw) {
229
+ if (!raw || typeof raw !== "object") return null;
230
+ return {
231
+ ...raw,
232
+ session_id:
233
+ raw.conversation_id ??
234
+ raw.conversationId ??
235
+ raw.session_id ??
236
+ raw.sessionId,
237
+ cwd: raw.cwd ?? raw.workspace_roots?.[0] ?? raw.workspacePaths?.[0],
238
+ endsTurn: raw.reason === undefined || raw.reason === "end_turn",
239
+ };
240
+ }
241
+
242
+ /** The file an agent reads its session hooks from. */
243
+ export function sessionHooksPath(
244
+ agent,
245
+ homeDir = os.homedir(),
246
+ env = process.env
247
+ ) {
248
+ return DIALECTS[agent].file(homeDir, env);
249
+ }
250
+
251
+ export function installSessionHooks(
252
+ agent,
253
+ {
254
+ runtimeRoot,
255
+ homeDir = os.homedir(),
256
+ nodePath = process.execPath,
257
+ env = process.env,
258
+ }
259
+ ) {
260
+ const dialect = DIALECTS[agent];
261
+ const file = dialect.file(homeDir, env);
262
+ const nudge = [
263
+ JSON.stringify(nodePath),
264
+ JSON.stringify(path.join(runtimeRoot, "lib", "nudge.mjs")),
265
+ "--agent",
266
+ agent,
267
+ ...(dialect.flags ?? []),
268
+ ].join(" ");
269
+ const commands = {
270
+ SessionStart: nudge,
271
+ // Mid-session: on every prompt, one line only when the queue changed since the session last saw it.
272
+ UserPromptSubmit: `${nudge} --if-changed`,
273
+ Stop: `${nudge} --stop`,
274
+ };
275
+ const settings = dialect.ownFile ? {} : readJson(file, {});
276
+ ensureDir(path.dirname(file));
277
+ fs.writeFileSync(
278
+ file,
279
+ JSON.stringify(dialect.shape.write(settings, commands), null, 2) + "\n"
280
+ );
281
+ }
282
+
283
+ export function removeSessionHooks(
284
+ agent,
285
+ homeDir = os.homedir(),
286
+ env = process.env
287
+ ) {
288
+ const dialect = DIALECTS[agent];
289
+ const file = dialect.file(homeDir, env);
290
+ if (dialect.ownFile) {
291
+ fs.rmSync(file, { force: true });
292
+ return;
293
+ }
294
+ const settings = readJson(file, null);
295
+ const erased = settings && dialect.shape.erase(settings);
296
+ if (erased && erased !== settings)
297
+ fs.writeFileSync(file, JSON.stringify(erased, null, 2) + "\n");
298
+ }