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
package/lib/activity.mjs CHANGED
@@ -13,8 +13,8 @@ import { runningPids } from "./runner.mjs";
13
13
  // only while it uses CPU. An open turn with nothing running and nothing written is waiting,
14
14
  // most often at a permission prompt that nobody can answer with the lid closed.
15
15
 
16
- // Measured 2026-10-10 on the owner's transcripts, from a prompt or tool result to the model's next
17
- // write: p99.9 131 s for Claude Code (n=14,783), 310 s for Codex (n=3,673); 9 of 18,456 exceed 5 min.
16
+ // Measured on real transcripts, from a prompt or tool result to the model's next write: p99.9 131 s for Claude Code
17
+ // (n=14,783), 310 s for Codex (n=3,673); 9 of 18,456 exceed 5 min.
18
18
  export const QUIET_MS = 5 * 60_000;
19
19
  // Measured 2026-10-10 with ps: an idle server with a file watcher reads 0.0-0.1 %, a working process 99.9-100 %.
20
20
  export const CPU_BUSY = 5;
@@ -32,10 +32,10 @@ const SHELLS = new Set(["sh", "bash", "zsh", "fish", "dash", "ksh"]);
32
32
  // Started by Codex or pi during a turn without being a command it ran. A shell may exec the command itself, so any other child counts.
33
33
  const HELPERS = new Set(["caffeinate"]);
34
34
  const TAIL_BYTES = 256 << 10;
35
- // How far back a turn is looked for when the tail holds no row of one, its newest rows all being huge (a tool result,
36
- // a request). Measured 2026-10-16 on the owner's transcripts (Claude Code for a week, Codex for two): at the 2,435
37
- // moments in an open turn when the tail held none, the newest row of the turn began at most 2.3 MB (Claude Code) and
38
- // 4.5 MB (Codex, a single item) from the end.
35
+ // How far back a turn is looked for when the tail holds no row of one, its newest rows all being huge (a tool result, a
36
+ // request). Measured on real transcripts (Claude Code for a week, Codex for two): at the 2,435 moments in an open turn
37
+ // when the tail held none, the newest row of the turn began at most 2.3 MB (Claude Code) and 4.5 MB (Codex, a single
38
+ // item) from the end.
39
39
  const FAR_TAIL_BYTES = 8 << 20;
40
40
 
41
41
  const base = (token) => path.basename(String(token || "")).replace(/^-/, "");
@@ -123,7 +123,7 @@ export function turnOf(agent, rows) {
123
123
  const content = row.message?.content;
124
124
  if (row.type === "assistant") {
125
125
  const stop = row.message?.stop_reason;
126
- // Claude Code retries a refused answer itself: in the owner's transcripts (2026-10-16), each of the 4 refusals
126
+ // Claude Code retries a refused answer itself: in a week of real transcripts, each of the 4 refusals
127
127
  // that was not its own error row was followed by more of the same turn.
128
128
  const retried = stop === "refusal" && !row.isApiErrorMessage;
129
129
  // Any other answer that calls no tool ends the turn: end_turn, max_tokens, or Claude Code's own error row
@@ -198,9 +198,9 @@ const stat = (file) => {
198
198
 
199
199
  /**
200
200
  * A recorded Claude Code session's transcript and its subagents'. A subagent writes its own transcript under the
201
- * session's folder, and one run in the background works on after the session's own turn has ended. Measured 2026-10-16
202
- * on the owner's 14 sessions with subagents: 42% of subagent rows were written while the session's transcript alone
203
- * read finished or quiet for 5 minutes. Subagent transcripts older than the process are an earlier run's.
201
+ * session's folder, and one run in the background works on after the session's own turn has ended. Measured on 14 real
202
+ * sessions with subagents: 42% of subagent rows were written while the session's transcript alone read finished or
203
+ * quiet for 5 minutes. Subagent transcripts older than the process are an earlier run's.
204
204
  */
205
205
  function recordedTranscripts(folder, sessionId, startedAt) {
206
206
  const own = stat(path.join(folder, `${sessionId}.jsonl`));
package/lib/adapters.mjs CHANGED
@@ -4,6 +4,12 @@ import path from "node:path";
4
4
  import { detectAgents, run } from "./commands.mjs";
5
5
  import { ensureDir, readJson } from "./files.mjs";
6
6
  import { MACHINE_RUNNERS } from "./members.mjs";
7
+ import {
8
+ HOOK_AGENTS,
9
+ installSessionHooks,
10
+ removeSessionHooks,
11
+ sessionHooksPath,
12
+ } from "./hookDialects.mjs";
7
13
 
8
14
  export const AGENTS = MACHINE_RUNNERS;
9
15
 
@@ -22,6 +28,22 @@ const MCP_CLIENT_APPS = {
22
28
  // Agents that run in their own cloud but have an app here, where Open brings them forward. The app is checked to be that
23
29
  // agent's (its bundle id is in Info.plist, binary or XML), so another app with the same name is never opened as it.
24
30
  const AGENT_APPS = {
31
+ "claude-app": {
32
+ name: "Claude",
33
+ bundle: "com.anthropic.claudefordesktop",
34
+ darwin: [
35
+ "/Applications/Claude.app",
36
+ path.join(os.homedir(), "Applications", "Claude.app"),
37
+ ],
38
+ },
39
+ chatgpt: {
40
+ name: "ChatGPT",
41
+ bundle: "com.openai.chat",
42
+ darwin: [
43
+ "/Applications/ChatGPT.app",
44
+ path.join(os.homedir(), "Applications", "ChatGPT.app"),
45
+ ],
46
+ },
25
47
  muse: {
26
48
  name: "Muse",
27
49
  bundle: "com.meta.endo",
@@ -93,13 +115,14 @@ export function mcpClientSnippet({
93
115
  function installAsset(
94
116
  source,
95
117
  target,
96
- { runtimeRoot, nodePath = process.execPath }
118
+ { runtimeRoot, nodePath = process.execPath, agent = "" }
97
119
  ) {
98
120
  ensureDir(path.dirname(target));
99
121
  const text = fs
100
122
  .readFileSync(source, "utf8")
101
123
  .replaceAll('"__HARNESS_RUNTIME__"', JSON.stringify(runtimeRoot))
102
- .replaceAll('"__HARNESS_NODE__"', JSON.stringify(nodePath));
124
+ .replaceAll('"__HARNESS_NODE__"', JSON.stringify(nodePath))
125
+ .replaceAll('"__HARNESS_AGENT__"', JSON.stringify(agent));
103
126
  fs.writeFileSync(target, text, { mode: 0o600 });
104
127
  try {
105
128
  fs.chmodSync(target, 0o600);
@@ -123,188 +146,136 @@ export function integrationAssets(homeDir = os.homedir()) {
123
146
  "plugins",
124
147
  "tryharness.js"
125
148
  ),
149
+ // Kilo, OpenCode's fork, reads plugins from its own folder only.
150
+ kilo: path.join(homeDir, ".config", "kilo", "plugins", "tryharness.js"),
151
+ // DeepSeek Harness loads a plugin named beside the patch file that names it.
152
+ dsh: path.join(dshHome(homeDir), "tryharness-dsh.mjs"),
126
153
  };
127
154
  }
128
155
 
129
- // Claude Code learns about waiting board work through a SessionStart hook whose stdout joins
130
- // its context. The hook is one entry in the user's settings, added once and removed on
131
- // disconnect; every other setting and hook is left as it was.
132
- export function claudeSettingsPath(homeDir = os.homedir()) {
133
- return path.join(homeDir, ".claude", "settings.json");
134
- }
135
- const isHarnessHook = (entry) =>
136
- JSON.stringify(entry).includes("/lib/nudge.mjs");
156
+ const dshHome = (homeDir) => process.env.DSH_HOME || path.join(homeDir, ".dsh");
137
157
 
138
- export function installClaudeSessionHook({
139
- runtimeRoot,
140
- homeDir = os.homedir(),
141
- nodePath = process.execPath,
142
- }) {
143
- const file = claudeSettingsPath(homeDir);
144
- const settings = readJson(file, {});
145
- const hooks =
146
- settings.hooks && typeof settings.hooks === "object" ? settings.hooks : {};
147
- const nudge = JSON.stringify(path.join(runtimeRoot, "lib", "nudge.mjs"));
148
- const starts = (
149
- Array.isArray(hooks.SessionStart) ? hooks.SessionStart : []
150
- ).filter((entry) => !isHarnessHook(entry));
151
- starts.push({
152
- hooks: [
153
- {
154
- type: "command",
155
- command: `${JSON.stringify(nodePath)} ${nudge} --agent claude-code`,
156
- timeout: 10,
157
- },
158
- ],
159
- });
160
- // Mid-session: on every prompt, one line only when the queue changed since the session last saw it.
161
- const prompts = (
162
- Array.isArray(hooks.UserPromptSubmit) ? hooks.UserPromptSubmit : []
163
- ).filter((entry) => !isHarnessHook(entry));
164
- prompts.push({
165
- hooks: [
166
- {
167
- type: "command",
168
- command: `${JSON.stringify(nodePath)} ${nudge} --agent claude-code --if-changed`,
169
- timeout: 10,
170
- },
171
- ],
172
- });
173
- // When a turn ends: a message the person sent this session from Harness keeps it going.
174
- const stops = (Array.isArray(hooks.Stop) ? hooks.Stop : []).filter(
175
- (entry) => !isHarnessHook(entry)
158
+ // DeepSeek Harness has no command that adds an MCP server or a plugin: both are rows in its home-level patch file
159
+ // (~/.dsh/cordis.patch.yml, a YAML list that applies to every profile and that people edit). Harness's rows are one
160
+ // marked block at its end, replaced by setup and taken out by uninstall; the rest of the file is kept as it is.
161
+ const DSH_BEGIN =
162
+ "# tryharness: begin (Harness's board; written and removed by npx tryharness)";
163
+ const DSH_END = "# tryharness: end";
164
+ function withoutDshBlock(text) {
165
+ const start = text.indexOf(DSH_BEGIN);
166
+ const end = text.indexOf(DSH_END);
167
+ if (start < 0 || end < start) return text;
168
+ return (text.slice(0, start) + text.slice(end + DSH_END.length)).replace(
169
+ /\n{3,}/g,
170
+ "\n\n"
176
171
  );
177
- stops.push({
178
- hooks: [
179
- {
180
- type: "command",
181
- command: `${JSON.stringify(nodePath)} ${nudge} --agent claude-code --stop`,
182
- timeout: 10,
183
- },
184
- ],
185
- });
172
+ }
173
+ function writeDshRows(homeDir, { mcpPath } = {}) {
174
+ const file = path.join(dshHome(homeDir), "cordis.patch.yml");
175
+ let text = "";
176
+ try {
177
+ text = fs.readFileSync(file, "utf8");
178
+ } catch {}
179
+ const kept = withoutDshBlock(text).trimEnd();
180
+ const block = mcpPath
181
+ ? [
182
+ DSH_BEGIN,
183
+ "- insert:",
184
+ " - id: harness",
185
+ " name: '@deepseek-ai/dsh-mcp-client'",
186
+ " config:",
187
+ " serverName: harness",
188
+ " transport: stdio",
189
+ ` command: ${JSON.stringify(process.execPath)}`,
190
+ ` args: ${JSON.stringify([mcpPath, "--agent", "dsh"])}`,
191
+ " env: {}",
192
+ " - id: tryharness",
193
+ " name: ./tryharness-dsh.mjs",
194
+ DSH_END,
195
+ ].join("\n")
196
+ : "";
197
+ const next = [kept, block].filter(Boolean).join("\n\n");
198
+ if (!next && !text) return;
186
199
  ensureDir(path.dirname(file));
187
- fs.writeFileSync(
188
- file,
189
- JSON.stringify(
190
- {
191
- ...settings,
192
- hooks: {
193
- ...hooks,
194
- SessionStart: starts,
195
- UserPromptSubmit: prompts,
196
- Stop: stops,
197
- },
198
- },
199
- null,
200
- 2
201
- ) + "\n"
202
- );
200
+ fs.writeFileSync(file, next ? next + "\n" : "");
203
201
  }
204
202
 
205
- // Codex reads the same hook shape from ~/.codex/hooks.json (SessionStart, UserPromptSubmit and Stop,
206
- // stdout added as developer context). Codex asks the person to trust a new or changed hook once,
207
- // with /hooks in its TUI, before it runs; setup says so.
208
- export function codexHooksPath(homeDir = os.homedir()) {
209
- return path.join(homeDir, ".codex", "hooks.json");
210
- }
203
+ export { installSessionHooks, removeSessionHooks, sessionHooksPath };
211
204
 
212
- export function installCodexHooks({
213
- runtimeRoot,
214
- homeDir = os.homedir(),
215
- nodePath = process.execPath,
216
- }) {
217
- const file = codexHooksPath(homeDir);
218
- const settings = readJson(file, {});
219
- const hooks =
220
- settings.hooks && typeof settings.hooks === "object" ? settings.hooks : {};
221
- const nudge = JSON.stringify(path.join(runtimeRoot, "lib", "nudge.mjs"));
222
- const starts = (
223
- Array.isArray(hooks.SessionStart) ? hooks.SessionStart : []
224
- ).filter((entry) => !isHarnessHook(entry));
225
- // After a compaction too: the hook tells the session its work again (compaction.mjs).
226
- starts.push({
227
- matcher: "startup|resume|compact",
228
- hooks: [
229
- {
230
- type: "command",
231
- command: `${JSON.stringify(nodePath)} ${nudge} --agent codex`,
232
- statusMessage: "Reading the Harness board",
233
- timeout: 10,
234
- },
235
- ],
236
- });
237
- const prompts = (
238
- Array.isArray(hooks.UserPromptSubmit) ? hooks.UserPromptSubmit : []
239
- ).filter((entry) => !isHarnessHook(entry));
240
- prompts.push({
241
- hooks: [
242
- {
243
- type: "command",
244
- command: `${JSON.stringify(nodePath)} ${nudge} --agent codex --if-changed`,
245
- timeout: 10,
246
- },
247
- ],
248
- });
249
- const stops = (Array.isArray(hooks.Stop) ? hooks.Stop : []).filter(
250
- (entry) => !isHarnessHook(entry)
251
- );
252
- stops.push({
253
- hooks: [
254
- {
255
- type: "command",
256
- command: `${JSON.stringify(nodePath)} ${nudge} --agent codex --stop`,
257
- timeout: 10,
258
- },
259
- ],
260
- });
205
+ // How Harness's MCP server goes into each hook agent's own config (its session hooks: hookDialects.mjs). By the
206
+ // agent's own command (`remove` first, so setup replaces an older entry), or, where it has no command for it, in its
207
+ // config file. Setup's line about it, when there is more to say than that it is configured.
208
+ const MCP_SETUP = {
209
+ // Other agents start the servers in Claude Code's config too (nudge.mjs startedByAnother).
210
+ "claude-code": {
211
+ remove: ["mcp", "remove", "--scope", "user", "harness"],
212
+ add: ["mcp", "add", "--scope", "user", "harness"],
213
+ flags: ["--check-host"],
214
+ },
215
+ codex: {
216
+ remove: ["mcp", "remove", "harness"],
217
+ add: ["mcp", "add", "harness"],
218
+ note: "in Codex run /hooks once to trust them",
219
+ },
220
+ "grok-build": {
221
+ remove: ["mcp", "remove", "--scope", "user", "harness"],
222
+ add: ["mcp", "add", "--scope", "user", "harness"],
223
+ },
224
+ copilot: {
225
+ remove: ["mcp", "remove", "harness"],
226
+ add: ["mcp", "add", "harness"],
227
+ },
228
+ devin: {
229
+ remove: ["mcp", "remove", "harness", "--scope", "user"],
230
+ add: ["mcp", "add", "--scope", "user", "harness"],
231
+ },
232
+ // Cursor's CLI documents no command to add one, and asks before a new server runs: `mcp enable` approves it. Grok
233
+ // Build starts the servers in Cursor's file too (nudge.mjs startedByAnother).
234
+ cursor: {
235
+ file: (home) => path.join(home, ".cursor", "mcp.json"),
236
+ entry: { type: "stdio" },
237
+ flags: ["--check-host"],
238
+ enable: ["mcp", "enable", "harness"],
239
+ },
240
+ antigravity: {
241
+ file: (home) => path.join(home, ".gemini", "config", "mcp_config.json"),
242
+ },
243
+ };
244
+
245
+ function writeMcpEntry(file, entry) {
246
+ const config = readJson(file, {});
247
+ const servers = { ...(config.mcpServers ?? {}) };
248
+ if (entry) servers.harness = entry;
249
+ else if (!servers.harness) return;
250
+ else delete servers.harness;
261
251
  ensureDir(path.dirname(file));
262
252
  fs.writeFileSync(
263
253
  file,
264
- JSON.stringify(
265
- {
266
- ...settings,
267
- hooks: {
268
- ...hooks,
269
- SessionStart: starts,
270
- UserPromptSubmit: prompts,
271
- Stop: stops,
272
- },
273
- },
274
- null,
275
- 2
276
- ) + "\n"
254
+ JSON.stringify({ ...config, mcpServers: servers }, null, 2) + "\n"
277
255
  );
278
256
  }
279
257
 
280
- export function removeCodexHooks(homeDir = os.homedir()) {
281
- const file = codexHooksPath(homeDir);
282
- const settings = readJson(file, null);
283
- if (!settings?.hooks) return;
284
- const hooks = { ...settings.hooks };
285
- for (const event of ["SessionStart", "UserPromptSubmit", "Stop"]) {
286
- if (Array.isArray(hooks[event]))
287
- hooks[event] = hooks[event].filter((entry) => !isHarnessHook(entry));
258
+ /** Harness's MCP server in a hook agent's own config: the command's result, or the file written. */
259
+ function addMcpServer(agent, executable, { mcpPath, homeDir, execute }) {
260
+ const setup = MCP_SETUP[agent];
261
+ const server = [mcpPath, "--agent", agent, ...(setup.flags ?? [])];
262
+ if (setup.file) {
263
+ writeMcpEntry(setup.file(homeDir), {
264
+ ...setup.entry,
265
+ command: process.execPath,
266
+ args: server,
267
+ });
268
+ if (setup.enable) execute(executable, setup.enable);
269
+ return { ok: true };
288
270
  }
289
- fs.writeFileSync(
290
- file,
291
- JSON.stringify({ ...settings, hooks }, null, 2) + "\n"
292
- );
271
+ execute(executable, setup.remove);
272
+ return execute(executable, [...setup.add, "--", process.execPath, ...server]);
293
273
  }
294
274
 
295
- export function removeClaudeSessionHook(homeDir = os.homedir()) {
296
- const file = claudeSettingsPath(homeDir);
297
- const settings = readJson(file, null);
298
- if (!settings?.hooks) return;
299
- const hooks = { ...settings.hooks };
300
- for (const event of ["SessionStart", "UserPromptSubmit", "Stop"]) {
301
- if (Array.isArray(hooks[event]))
302
- hooks[event] = hooks[event].filter((entry) => !isHarnessHook(entry));
303
- }
304
- fs.writeFileSync(
305
- file,
306
- JSON.stringify({ ...settings, hooks }, null, 2) + "\n"
307
- );
275
+ function removeMcpServer(agent, executable, { homeDir, execute }) {
276
+ const setup = MCP_SETUP[agent];
277
+ if (setup.file) writeMcpEntry(setup.file(homeDir), null);
278
+ else execute(executable, setup.remove);
308
279
  }
309
280
 
310
281
  export function configureAgents({
@@ -338,61 +309,26 @@ export function configureAgents({
338
309
  });
339
310
  continue;
340
311
  }
341
- if (agent === "claude-code") {
342
- execute(found.path, ["mcp", "remove", "--scope", "user", "harness"]);
343
- const added = execute(found.path, [
344
- "mcp",
345
- "add",
346
- "--scope",
347
- "user",
348
- "harness",
349
- "--",
350
- process.execPath,
312
+ if (HOOK_AGENTS.includes(agent)) {
313
+ const added = addMcpServer(agent, found.path, {
351
314
  mcpPath,
352
- "--agent",
353
- agent,
354
- ]);
355
- let hooked = true;
356
- try {
357
- installClaudeSessionHook({ runtimeRoot, homeDir });
358
- } catch {
359
- hooked = false;
360
- }
361
- states.push({
362
- agent,
363
- installed: true,
364
- configured: added.ok,
365
- detail: added.ok
366
- ? hooked
367
- ? "MCP and session-start nudge configured"
368
- : "MCP configured; the session-start hook could not be written"
369
- : diagnostic(added),
315
+ homeDir,
316
+ execute,
370
317
  });
371
- } else if (agent === "codex") {
372
- execute(found.path, ["mcp", "remove", "harness"]);
373
- const added = execute(found.path, [
374
- "mcp",
375
- "add",
376
- "harness",
377
- "--",
378
- process.execPath,
379
- mcpPath,
380
- "--agent",
381
- agent,
382
- ]);
383
318
  let hooked = true;
384
319
  try {
385
- installCodexHooks({ runtimeRoot, homeDir });
320
+ installSessionHooks(agent, { runtimeRoot, homeDir });
386
321
  } catch {
387
322
  hooked = false;
388
323
  }
324
+ const note = MCP_SETUP[agent].note;
389
325
  states.push({
390
326
  agent,
391
327
  installed: true,
392
328
  configured: added.ok,
393
329
  detail: added.ok
394
330
  ? hooked
395
- ? "MCP and session hooks configured; in Codex run /hooks once to trust them"
331
+ ? `MCP and session hooks configured${note ? `; ${note}` : ""}`
396
332
  : "MCP configured; the session hooks could not be written"
397
333
  : diagnostic(added),
398
334
  });
@@ -409,11 +345,11 @@ export function configureAgents({
409
345
  configured: fs.existsSync(assets.pi),
410
346
  detail: "extension installed",
411
347
  });
412
- } else if (agent === "opencode") {
348
+ } else if (agent === "opencode" || agent === "kilo") {
413
349
  installAsset(
414
350
  path.join(runtimeRoot, "assets", "opencode-plugin.js"),
415
- assets.opencode,
416
- { runtimeRoot }
351
+ assets[agent],
352
+ { runtimeRoot, agent }
417
353
  );
418
354
  // The same stdio server as Claude Code and Codex. opencode has no `mcp remove`; `mcp add` replaces the entry.
419
355
  const added = execute(found.path, [
@@ -434,6 +370,19 @@ export function configureAgents({
434
370
  ? "MCP and plugin configured"
435
371
  : `plugin installed; MCP: ${diagnostic(added)}`,
436
372
  });
373
+ } else if (agent === "dsh") {
374
+ installAsset(
375
+ path.join(runtimeRoot, "assets", "dsh-plugin.mjs"),
376
+ assets.dsh,
377
+ { runtimeRoot }
378
+ );
379
+ writeDshRows(homeDir, { mcpPath });
380
+ states.push({
381
+ agent,
382
+ installed: true,
383
+ configured: true,
384
+ detail: "MCP and plugin configured",
385
+ });
437
386
  } else {
438
387
  states.push({
439
388
  agent,
@@ -457,23 +406,25 @@ export function removeAgentConfigurations({
457
406
  execute = run,
458
407
  } = {}) {
459
408
  for (const found of detected) {
460
- if (!found.path) continue;
461
- if (found.agent === "claude-code") {
462
- execute(found.path, ["mcp", "remove", "--scope", "user", "harness"]);
463
- removeClaudeSessionHook(homeDir);
464
- } else if (found.agent === "codex") {
465
- execute(found.path, ["mcp", "remove", "harness"]);
466
- removeCodexHooks(homeDir);
467
- }
409
+ if (!found.path || !HOOK_AGENTS.includes(found.agent)) continue;
410
+ removeMcpServer(found.agent, found.path, { homeDir, execute });
411
+ removeSessionHooks(found.agent, homeDir);
468
412
  }
469
- // opencode has no `mcp remove`, so its entry comes out of the config file `mcp add` wrote it to.
470
- for (const name of ["opencode.json", "opencode.jsonc"]) {
471
- const file = path.join(homeDir, ".config", "opencode", name);
413
+ // opencode and Kilo have no `mcp remove`, so the entry comes out of the config file `mcp add` wrote it to.
414
+ for (const file of [
415
+ ...["opencode.json", "opencode.jsonc"].map((name) =>
416
+ path.join(homeDir, ".config", "opencode", name)
417
+ ),
418
+ ...["kilo.json", "kilo.jsonc", "opencode.json", "opencode.jsonc"].map(
419
+ (name) => path.join(homeDir, ".config", "kilo", name)
420
+ ),
421
+ ]) {
472
422
  const config = readJson(file, null);
473
423
  if (!config?.mcp?.harness) continue;
474
424
  delete config.mcp.harness;
475
425
  fs.writeFileSync(file, JSON.stringify(config, null, 2) + "\n");
476
426
  }
427
+ writeDshRows(homeDir);
477
428
  const assets = integrationAssets(homeDir);
478
429
  for (const target of Object.values(assets)) {
479
430
  try {
@@ -0,0 +1,71 @@
1
+ // The program Harness runs for each coding agent: the absolute path recorded when the person set the agent up (setup,
2
+ // agents add, agents confirm), never whatever the daemon's PATH finds first at run time. The service's PATH holds
3
+ // folders other programs can write to (Homebrew's, a Node version's), so a program planted there under an agent's
4
+ // name used to run in that agent's place, with the agent's unrestricted flags. Now it never runs; and when the
5
+ // recorded program is gone, the run is refused until the person confirms the one they have now.
6
+
7
+ import { AGENT_COMMANDS, resolveCommand } from "./commands.mjs";
8
+ import { runtimeOf } from "./agentRuntimeConfig.mjs";
9
+ import { readJson, writeJsonAtomic } from "./files.mjs";
10
+ import { paths } from "./paths.mjs";
11
+ import { relayCommand } from "./runtime-install.mjs";
12
+
13
+ /** The command an agent is started by: the person's configured executable, else its usual name. */
14
+ export function agentCommand(agent) {
15
+ return runtimeOf(agent)?.command || AGENT_COMMANDS[agent] || null;
16
+ }
17
+
18
+ /**
19
+ * Records the program `agent` runs as, found the way the person's own terminal finds it (`env`'s PATH). Returns
20
+ * { path, previous } (previous: the program recorded before, when it was another), or null when there is none.
21
+ */
22
+ export function confirmAgentBinary(
23
+ agent,
24
+ { env = process.env, file = paths.config } = {}
25
+ ) {
26
+ const command = agentCommand(agent);
27
+ const found = command && resolveCommand(command, env);
28
+ if (!found) return null;
29
+ const config = readJson(file, {});
30
+ const before = config.agentBinaries?.[agent]?.path ?? null;
31
+ writeJsonAtomic(file, {
32
+ ...config,
33
+ agentBinaries: {
34
+ ...config.agentBinaries,
35
+ [agent]: { command, path: found },
36
+ },
37
+ });
38
+ return { path: found, previous: before && before !== found ? before : null };
39
+ }
40
+
41
+ /**
42
+ * The absolute program to start for `agent`, whose command is `command`: the recorded one. An agent set up before
43
+ * Harness recorded programs, or whose command the person has since changed, is recorded at this first run. Null when
44
+ * the agent is not installed at all; throws when the recorded program is gone.
45
+ */
46
+ export function agentBinary(
47
+ agent,
48
+ command,
49
+ { env = process.env, file = paths.config } = {}
50
+ ) {
51
+ const recorded = readJson(file, {}).agentBinaries?.[agent];
52
+ if (!recorded || recorded.command !== command) {
53
+ const found = resolveCommand(command, env);
54
+ if (!found) return null;
55
+ const config = readJson(file, {});
56
+ writeJsonAtomic(file, {
57
+ ...config,
58
+ agentBinaries: {
59
+ ...config.agentBinaries,
60
+ [agent]: { command, path: found },
61
+ },
62
+ });
63
+ return found;
64
+ }
65
+ if (resolveCommand(recorded.path, env)) return recorded.path;
66
+ const now = resolveCommand(command, env);
67
+ throw new Error(
68
+ `Harness starts ${agent} only from ${recorded.path}, the program confirmed for it, and that is no longer there` +
69
+ `${now ? ` (${command} is now ${now})` : ""}. If you installed ${agent} again yourself, confirm it: ${relayCommand(`agents confirm ${agent}`)}`
70
+ );
71
+ }
@@ -2,7 +2,7 @@ import { readFileSync } from "node:fs";
2
2
  import { member } from "./members.mjs";
3
3
  import { paths } from "./paths.mjs";
4
4
 
5
- /** Installed agents only: the owner's executable selection never comes from a model or task. */
5
+ /** Installed agents only: the person's executable selection never comes from a model or task. */
6
6
  export function runtimeOf(agent) {
7
7
  const runtime = member(agent)?.runtime;
8
8
  if (!runtime) return null;