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.
- package/README.md +23 -19
- package/assets/dsh-plugin.mjs +72 -0
- package/assets/opencode-plugin.js +4 -3
- package/cli.mjs +484 -90
- package/lib/activity.mjs +10 -10
- package/lib/adapters.mjs +173 -222
- package/lib/agentBinaries.mjs +71 -0
- package/lib/agentRuntimeConfig.mjs +1 -1
- package/lib/agentRuntimes.mjs +34 -18
- package/lib/agentSignIn.mjs +456 -0
- package/lib/answers.mjs +5 -5
- package/lib/archetypes.d.ts +64 -0
- package/lib/archetypes.js +989 -0
- package/lib/asks.mjs +4 -4
- package/lib/audit.mjs +666 -0
- package/lib/backupSetup.mjs +143 -0
- package/lib/boardAccess.mjs +24 -11
- package/lib/boardBackup.mjs +283 -0
- package/lib/boardFileCommands.mjs +6 -6
- package/lib/boardFiles.mjs +13 -12
- package/lib/boardMirror.mjs +124 -25
- package/lib/boardProtocol.json +88 -2
- package/lib/boardWaits.mjs +101 -0
- package/lib/book.mjs +659 -0
- package/lib/bridge.mjs +6 -6
- package/lib/cards.mjs +138 -28
- package/lib/cloudAgents.mjs +216 -0
- package/lib/cloudAi.mjs +1312 -0
- package/lib/cloudAssistants.mjs +242 -0
- package/lib/cloudBoot.mjs +119 -0
- package/lib/cloudSave.mjs +197 -0
- package/lib/cloudSsh.mjs +178 -0
- package/lib/commands.mjs +7 -2
- package/lib/context.mjs +19 -5
- package/lib/contractGate.mjs +399 -0
- package/lib/control-client.mjs +9 -1
- package/lib/controlSocket.mjs +86 -0
- package/lib/coordinator.mjs +252 -144
- package/lib/daemon.mjs +1351 -2767
- package/lib/desk.mjs +240 -0
- package/lib/desktop.mjs +178 -74
- package/lib/directLink.mjs +16 -5
- package/lib/environment.mjs +2 -1
- package/lib/environments.mjs +247 -9
- package/lib/firewall.mjs +9 -9
- package/lib/folders.mjs +20 -16
- package/lib/frames.mjs +2 -3
- package/lib/gitHost.mjs +174 -0
- package/lib/goalCommands.mjs +25 -7
- package/lib/goals.mjs +7 -7
- package/lib/guestRequests.mjs +94 -0
- package/lib/handoffs.mjs +8 -7
- package/lib/handover.mjs +4 -4
- package/lib/harnessModel.mjs +6 -6
- package/lib/harnessOffers.mjs +266 -0
- package/lib/hookDialects.mjs +298 -0
- package/lib/inference.mjs +26 -8
- package/lib/jobAnswers.mjs +190 -0
- package/lib/landed.mjs +887 -0
- package/lib/lane.mjs +42 -11
- package/lib/lessons.mjs +16 -16
- package/lib/library.mjs +3 -3
- package/lib/lineup.mjs +3 -0
- package/lib/linkRelay.mjs +574 -0
- package/lib/live.mjs +284 -13
- package/lib/localAgentAsk.mjs +74 -0
- package/lib/localStack.mjs +536 -0
- package/lib/localmodels.mjs +6 -4
- package/lib/loopBackstop.mjs +4 -4
- package/lib/machineIdentity.mjs +9 -1
- package/lib/machineRoutes.mjs +181 -2
- package/lib/machineRuns.mjs +76 -1
- package/lib/machineSeal.mjs +39 -12
- package/lib/mcp-stdio.mjs +163 -27
- package/lib/mcpRelay.mjs +1 -1
- package/lib/members.json +29 -2
- package/lib/members.mjs +1 -1
- package/lib/models.mjs +85 -31
- package/lib/museSession.mjs +21 -13
- package/lib/nativeHost.mjs +36 -8
- package/lib/neovim.mjs +126 -0
- package/lib/network.mjs +50 -5
- package/lib/notify.mjs +7 -5
- package/lib/nudge.mjs +50 -19
- package/lib/ocr.mjs +9 -9
- package/lib/onboard.mjs +26 -20
- package/lib/oneLine.mjs +7 -7
- package/lib/ownMachines.mjs +1223 -140
- package/lib/pairing.mjs +60 -16
- package/lib/paths.mjs +19 -1
- package/lib/peerProcess.mjs +124 -0
- package/lib/personModel.mjs +89 -0
- package/lib/personNotices.mjs +151 -0
- package/lib/phones.mjs +538 -31
- package/lib/placeCommands.mjs +4 -4
- package/lib/places.mjs +400 -12
- package/lib/profile.mjs +67 -14
- package/lib/projectGit.mjs +158 -14
- package/lib/projectPieces.mjs +902 -0
- package/lib/projectSettings.mjs +7 -4
- package/lib/projects.mjs +384 -62
- package/lib/provenance.mjs +5 -1
- package/lib/proxyLinks.mjs +267 -0
- package/lib/reactions.mjs +7 -5
- package/lib/readiness.mjs +145 -23
- package/lib/record.mjs +128 -0
- package/lib/redact.mjs +4 -4
- package/lib/relayLimits.mjs +62 -0
- package/lib/release.mjs +170 -0
- package/lib/releaseKeys.json +6 -0
- package/lib/repoLinks.mjs +4 -4
- package/lib/roomChannels.mjs +24 -0
- package/lib/roomPage.mjs +1 -1
- package/lib/runAuthority.mjs +101 -0
- package/lib/runBrief.mjs +19 -8
- package/lib/runWorker.mjs +31 -7
- package/lib/runner.mjs +223 -29
- package/lib/runtime-install.mjs +143 -9
- package/lib/schedules.mjs +2 -2
- package/lib/screens.mjs +1 -1
- package/lib/sealed.mjs +11 -2
- package/lib/sealedThreads.mjs +671 -0
- package/lib/secretPatterns.json +1 -1
- package/lib/secrets.mjs +4 -4
- package/lib/seen.mjs +6 -6
- package/lib/serverWords.mjs +175 -0
- package/lib/service.mjs +22 -12
- package/lib/sessionControl.mjs +378 -90
- package/lib/specialties.json +74 -0
- package/lib/specialties.mjs +477 -0
- package/lib/specialtyKeys.d.ts +3 -0
- package/lib/specialtyKeys.js +57 -0
- package/lib/specialtyNotice.mjs +147 -0
- package/lib/specialtySnapshot.mjs +138 -0
- package/lib/speech.mjs +5 -5
- package/lib/store.mjs +420 -36
- package/lib/stuck.mjs +1 -1
- package/lib/swarm.mjs +304 -37
- package/lib/swarmDevices.mjs +319 -0
- package/lib/swarmMemory.mjs +27 -25
- package/lib/t3.mjs +24 -15
- package/lib/taskCommands.mjs +80 -20
- package/lib/taskRooms.mjs +125 -0
- package/lib/taskRuns.mjs +45 -3
- package/lib/team.json +255 -148
- package/lib/team.mjs +554 -190
- package/lib/threadActions.mjs +315 -0
- package/lib/threadAuthority.mjs +101 -0
- package/lib/threadBriefs.mjs +178 -0
- package/lib/threadLine.mjs +116 -0
- package/lib/threadRuns.mjs +209 -50
- package/lib/threadView.mjs +20 -7
- package/lib/usageTotals.mjs +2 -3
- package/lib/vault.mjs +101 -10
- package/lib/vaultCloud.mjs +2 -2
- package/lib/vaultCommands.mjs +15 -6
- package/lib/vaultTools.js +2 -2
- package/lib/verdicts.mjs +328 -0
- package/lib/wakes.mjs +1 -1
- package/lib/watches.mjs +2 -2
- package/lib/windowAsks.mjs +13 -5
- package/lib/worktrees.mjs +157 -25
- package/npm-shrinkwrap.json +1093 -0
- package/package.json +12 -11
- package/release.json +220 -0
- package/lib/modelTiers.json +0 -1183
- 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
|
|
17
|
-
//
|
|
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
|
-
//
|
|
37
|
-
//
|
|
38
|
-
//
|
|
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
|
|
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
|
|
202
|
-
*
|
|
203
|
-
*
|
|
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
|
-
|
|
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
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
const
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
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
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
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
|
-
|
|
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
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
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
|
-
|
|
281
|
-
|
|
282
|
-
const
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
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
|
-
|
|
290
|
-
|
|
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
|
-
|
|
296
|
-
const
|
|
297
|
-
|
|
298
|
-
|
|
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
|
|
342
|
-
|
|
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
|
-
|
|
353
|
-
|
|
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
|
-
|
|
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
|
-
?
|
|
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
|
|
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
|
-
|
|
462
|
-
|
|
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
|
|
470
|
-
for (const
|
|
471
|
-
|
|
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
|
|
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;
|