@codeconductorai/harmony-mcp 1.0.32 → 1.0.34

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 (47) hide show
  1. package/README.md +210 -15
  2. package/package.json +4 -2
  3. package/src/{deviceAuth.js → auth/deviceAuth.js} +2 -2
  4. package/src/{harmonyClient.js → backend/harmonyClient.js} +186 -15
  5. package/src/doctor/doctorCommand.js +382 -0
  6. package/src/index.js +18 -5
  7. package/src/{telemetry.js → observability/telemetry.js} +3 -3
  8. package/src/rsi/bundleHints.js +181 -0
  9. package/src/rsi/bundleRefresher.js +95 -0
  10. package/src/rsi/callContext.js +49 -0
  11. package/src/rsi/causalState.js +103 -0
  12. package/src/rsi/clientAgent.js +58 -0
  13. package/src/rsi/hooks/eventBuilder.js +126 -0
  14. package/src/rsi/hooks/fileHash.js +33 -0
  15. package/src/rsi/hooks/hmacSigner.js +39 -0
  16. package/src/rsi/hooks/hookEventCommand.js +196 -0
  17. package/src/rsi/hooks/normalizers.js +329 -0
  18. package/src/rsi/hooks/offlineSpooler.js +104 -0
  19. package/src/rsi/hooks/secretScrubber.js +50 -0
  20. package/src/rsi/hooks/shellCommandScrubber.js +449 -0
  21. package/src/rsi/hooks/spoolDrainer.js +73 -0
  22. package/src/rsi/hooks/toolEventsClient.js +70 -0
  23. package/src/rsi/localState.js +53 -0
  24. package/src/rsi/serveTelemetry.js +85 -0
  25. package/src/rsi/workspaceRegistry.js +63 -0
  26. package/src/{server.js → server/server.js} +107 -17
  27. package/src/{serverInstructions.js → server/serverInstructions.js} +2 -2
  28. package/src/server/serverMain.js +46 -0
  29. package/src/{sessionIdentity.js → session/sessionIdentity.js} +10 -6
  30. package/src/setup/agentCapabilityMatrix.js +425 -0
  31. package/src/setup/agentsGuide.js +28 -0
  32. package/src/setup/configMergers.js +272 -0
  33. package/src/{installer.js → setup/installer.js} +1 -1
  34. package/src/setup/setupAgentsCommand.js +192 -0
  35. package/src/setup/shim.js +80 -0
  36. package/src/sync/managedMarkdownInjector.js +103 -0
  37. package/src/sync/syncWorkspaceCommand.js +143 -0
  38. package/src/sync/workspaceSync.js +88 -0
  39. package/src/{fileWatcher.js → workspace/fileWatcher.js} +2 -2
  40. package/src/{workspaceIdentity.js → workspace/workspaceIdentity.js} +1 -1
  41. package/src/{workspaceMarker.js → workspace/workspaceMarker.js} +1 -1
  42. package/src/agentsGuide.js +0 -38
  43. package/src/serverMain.js +0 -32
  44. /package/src/{log.js → observability/log.js} +0 -0
  45. /package/src/{toolSchemas.js → server/toolSchemas.js} +0 -0
  46. /package/src/{fileFilters.js → workspace/fileFilters.js} +0 -0
  47. /package/src/{repoIdentity.js → workspace/repoIdentity.js} +0 -0
@@ -0,0 +1,425 @@
1
+ // Declarative per-agent capabilities and the install/uninstall steps for each (RSI MCP spec §6.1, §6.2).
2
+ //
3
+ // Hook formats are written only where this package has a normalizer for the agent's payload AND the agent's hook
4
+ // config format is documented: Claude Code, Codex, Cursor, Gemini CLI / Antigravity, GitHub Copilot CLI. Other agents
5
+ // get the MCP server entry where their config is plain JSON, or a manual instruction; they still contribute through
6
+ // Harmony's server-side join (spec's Tier-2/3). OpenCode / Kilo Code hook plugins are pending: OpenCode's plugin API
7
+ // changed and its post-tool event fields are not documented yet.
8
+ import fs from "fs";
9
+ import os from "os";
10
+ import path from "path";
11
+ import { execFileSync } from "child_process";
12
+
13
+ import { SERVER_NAME, codexHome, serverCommand, upsertCodexServer } from "./installer.js";
14
+ import {
15
+ ensureKey,
16
+ parseJsonc,
17
+ readText,
18
+ removeFile,
19
+ removeHarmonyHooks,
20
+ removeTomlBlock,
21
+ renderCodexTomlHooks,
22
+ tomlHasInlineHookArrays,
23
+ tomlHasInlineHooks,
24
+ upsertFlatHook,
25
+ upsertGroupedHook,
26
+ upsertMcpServer,
27
+ upsertSessionStartHook,
28
+ upsertTomlBlock,
29
+ } from "./configMergers.js";
30
+ import { hookCommand, sessionHookCommand } from "./shim.js";
31
+
32
+ const HOOK_TIMEOUT_S = 5;
33
+
34
+ // ---------- environment helpers (overridable for tests) ----------
35
+
36
+ function home() {
37
+ return os.homedir();
38
+ }
39
+
40
+ export function which(bin) {
41
+ const searchPath = process.env.HARMONY_SETUP_PATH ?? process.env.PATH ?? "";
42
+ for (const dir of searchPath.split(path.delimiter).filter(Boolean)) {
43
+ const candidate = path.join(dir, bin);
44
+ try {
45
+ fs.accessSync(candidate, fs.constants.X_OK);
46
+ return candidate;
47
+ } catch {
48
+ // keep looking
49
+ }
50
+ }
51
+ return null;
52
+ }
53
+
54
+ function exists(p) {
55
+ return fs.existsSync(p);
56
+ }
57
+
58
+ function claudeDir() {
59
+ return process.env.CLAUDE_CONFIG_DIR || path.join(home(), ".claude");
60
+ }
61
+
62
+ function copilotDir() {
63
+ return process.env.COPILOT_HOME || path.join(home(), ".copilot");
64
+ }
65
+
66
+ function mcpLaunch() {
67
+ const [command, ...args] = serverCommand({ env: {} });
68
+ return { command, args };
69
+ }
70
+
71
+ // ---------- step runner ----------
72
+
73
+ // A Step edits one file. `apply(text)` returns { text, status } and is pure; run() handles I/O and dry runs.
74
+ function jsonStep(ctx, file, what, apply) {
75
+ const before = readText(file);
76
+ let result;
77
+ try {
78
+ result = apply(before);
79
+ } catch (error) {
80
+ ctx.note("skipped", `${file}: ${error.message} (file left untouched)`);
81
+ return;
82
+ }
83
+ if (result.text !== before && result.text !== null) ctx.write(file, result.text);
84
+ ctx.note(result.status, `${file} ${what}`);
85
+ }
86
+
87
+ function removeStep(ctx, file, what, apply) {
88
+ const before = readText(file);
89
+ if (before === null) return;
90
+ let result;
91
+ try {
92
+ result = apply(before);
93
+ } catch (error) {
94
+ ctx.note("skipped", `${file}: ${error.message} (file left untouched)`);
95
+ return;
96
+ }
97
+ if (!result.removed) return;
98
+ ctx.write(file, result.text);
99
+ ctx.note("removed", `${file} ${what}`);
100
+ }
101
+
102
+ function groupedHooks(ctx, file, agent, entries) {
103
+ jsonStep(ctx, file, `${entries.map((e) => e.event).join(" + ")} hooks`, (text) => {
104
+ let current = text;
105
+ const statuses = [];
106
+ for (const { event, matcher, build } of entries) {
107
+ const r = upsertGroupedHook(current, file, event, matcher, build(hookCommand({ agent, event: event === "PostToolUse" || event === "AfterTool" ? null : event, scope: ctx.scope })));
108
+ current = r.text;
109
+ statuses.push(r.status);
110
+ }
111
+ return { text: current, status: summarize(statuses) };
112
+ });
113
+ }
114
+
115
+ function summarize(statuses) {
116
+ if (statuses.every((s) => s === "unchanged")) return "unchanged";
117
+ if (statuses.every((s) => s === "added")) return "added";
118
+ return "updated";
119
+ }
120
+
121
+ function mcpJsonServer(ctx, file, keyPath, entry) {
122
+ jsonStep(ctx, file, `MCP server "${SERVER_NAME}"`, (text) => upsertMcpServer(text, file, keyPath, entry));
123
+ }
124
+
125
+ function mcpStatusFromJson(file, keyPath) {
126
+ try {
127
+ let node = parseJsonc(readText(file), file);
128
+ for (const k of keyPath) node = node?.[k];
129
+ return node !== undefined;
130
+ } catch {
131
+ return false;
132
+ }
133
+ }
134
+
135
+ // Harmony-like MCP servers Claude Code already knows: user scope and per-project ("local") entries in
136
+ // ~/.claude.json, plus the project's .mcp.json. Matched by name (any case) or by a command that runs harmony-mcp.
137
+ export function claudeHarmonyServers(projectDir) {
138
+ const found = [];
139
+ const isHarmony = (name, server) =>
140
+ /^harmony$/i.test(name) || [server?.command, ...(Array.isArray(server?.args) ? server.args : [])].some((a) => typeof a === "string" && a.includes("harmony-mcp"));
141
+ const scan = (servers, where) => {
142
+ if (!servers || typeof servers !== "object") return;
143
+ for (const [name, server] of Object.entries(servers)) if (isHarmony(name, server)) found.push(`"${name}" in ${where}`);
144
+ };
145
+ try {
146
+ const data = parseJsonc(readText(path.join(home(), ".claude.json")), "~/.claude.json");
147
+ scan(data.mcpServers, "user scope");
148
+ for (const [proj, cfg] of Object.entries(data.projects || {})) scan(cfg?.mcpServers, proj);
149
+ } catch {
150
+ // no or unreadable ~/.claude.json
151
+ }
152
+ try {
153
+ scan(parseJsonc(readText(path.join(projectDir, ".mcp.json")), ".mcp.json").mcpServers, path.join(projectDir, ".mcp.json"));
154
+ } catch {
155
+ // none
156
+ }
157
+ return found;
158
+ }
159
+
160
+ // ---------- agents ----------
161
+
162
+ const CLAUDE_POST_TOOL_MATCHER = "Bash|Grep|Glob|Read|Edit|MultiEdit|Write|NotebookEdit";
163
+ const GEMINI_AFTER_TOOL_MATCHER =
164
+ "read_file|read_many_files|write_file|replace|edit|search_file_content|grep|grep_search|glob|run_shell_command";
165
+
166
+ const claudeHook = (command) => ({ type: "command", command, async: true, timeout: HOOK_TIMEOUT_S });
167
+
168
+ export const AGENTS = [
169
+ {
170
+ id: "claude-code",
171
+ name: "Claude Code",
172
+ tier: 1,
173
+ instructions: "server instructions / CLAUDE.md",
174
+ detect: () => exists(claudeDir()) || Boolean(which("claude")),
175
+ hookScopes: ["user", "project"],
176
+ hookFiles: (ctx) => [ctx.scope === "project" ? path.join(ctx.project, ".claude", "settings.json") : path.join(claudeDir(), "settings.json")],
177
+ installHooks(ctx) {
178
+ const file = this.hookFiles(ctx)[0];
179
+ groupedHooks(ctx, file, "claude-code", [
180
+ { event: "PostToolUse", matcher: CLAUDE_POST_TOOL_MATCHER, build: claudeHook },
181
+ { event: "PostToolUseFailure", matcher: "Bash", build: claudeHook },
182
+ { event: "PreCompact", matcher: undefined, build: claudeHook },
183
+ ]);
184
+ jsonStep(ctx, file, "SessionStart hook (follows /clear and compaction)", (text) =>
185
+ upsertSessionStartHook(text, file, { type: "command", command: sessionHookCommand({ scope: ctx.scope }), timeout: HOOK_TIMEOUT_S }));
186
+ },
187
+ installMcp(ctx) {
188
+ const { command, args } = mcpLaunch();
189
+ const addArgs = ["mcp", "add", SERVER_NAME, "--scope", "user", "--", command, ...args];
190
+ // Any existing Harmony server, in any scope and under any capitalisation, wins: a user-scope "harmony" next
191
+ // to a project's "Harmony" would show the agent two servers.
192
+ const existing = claudeHarmonyServers(ctx.project);
193
+ if (existing.length) {
194
+ return ctx.note("kept", `Claude Code already has a Harmony MCP server (${existing.slice(0, 3).join("; ")}${existing.length > 3 ? `; +${existing.length - 3} more` : ""}); not adding another`);
195
+ }
196
+ const claude = which("claude");
197
+ if (!claude) return ctx.note("manual", `Claude Code CLI not on PATH; run: claude ${addArgs.join(" ")}`);
198
+ if (!ctx.dryRun) execFileSync(claude, addArgs, { stdio: "ignore" });
199
+ ctx.note("added", `Claude Code MCP server "${SERVER_NAME}" (user scope)`);
200
+ },
201
+ },
202
+ {
203
+ id: "codex",
204
+ name: "OpenAI Codex",
205
+ tier: 1,
206
+ instructions: "AGENTS.md",
207
+ detect: () => exists(codexHome()) || Boolean(which("codex")),
208
+ hookScopes: ["user"],
209
+ hookFiles: () => [path.join(codexHome(), "config.toml"), path.join(codexHome(), "hooks.json")],
210
+ installHooks(ctx) {
211
+ const tomlFile = path.join(codexHome(), "config.toml");
212
+ const hooksFile = path.join(codexHome(), "hooks.json");
213
+ const toml = readText(tomlFile);
214
+ const entries = [
215
+ { event: "PostToolUse", matcher: undefined, hook: { type: "command", command: hookCommand({ agent: "codex", scope: "user" }), timeout: HOOK_TIMEOUT_S, async: true } },
216
+ { event: "PreCompact", matcher: undefined, hook: { type: "command", command: hookCommand({ agent: "codex", event: "PreCompact", scope: "user" }), timeout: HOOK_TIMEOUT_S, async: true } },
217
+ ];
218
+ // Codex gives the MCP server no session id of its own; this hook records it (see sessionIdentity.js).
219
+ const sessionHook = { type: "command", command: sessionHookCommand({ scope: "user" }), timeout: HOOK_TIMEOUT_S };
220
+ // Spec §6.2.3: if config.toml already defines hooks inline, add ours there; two formats make Codex warn.
221
+ if (tomlHasInlineHooks(toml)) {
222
+ if (tomlHasInlineHookArrays(toml)) {
223
+ return ctx.note("manual", `${tomlFile} defines hooks as inline arrays; add Harmony's PostToolUse/PreCompact hook there by hand (command: ${entries[0].hook.command})`);
224
+ }
225
+ const r = upsertTomlBlock(toml, renderCodexTomlHooks([...entries, { event: "SessionStart", matcher: undefined, hook: sessionHook }]));
226
+ if (r.text !== toml) ctx.write(tomlFile, r.text);
227
+ return ctx.note(r.status, `${tomlFile} PostToolUse + PreCompact + SessionStart hooks (inline [hooks] found, so not hooks.json); trust them once in Codex's /hooks`);
228
+ }
229
+ jsonStep(ctx, hooksFile, "PostToolUse + PreCompact + SessionStart hooks; trust them once in Codex's /hooks", (text) => {
230
+ let current = text;
231
+ const statuses = [];
232
+ for (const e of entries) {
233
+ const r = upsertGroupedHook(current, hooksFile, e.event, e.matcher, e.hook);
234
+ current = r.text;
235
+ statuses.push(r.status);
236
+ }
237
+ const s = upsertSessionStartHook(current, hooksFile, sessionHook);
238
+ statuses.push(s.status);
239
+ return { text: s.text, status: summarize(statuses) };
240
+ });
241
+ },
242
+ uninstallHooks(ctx) {
243
+ const tomlFile = path.join(codexHome(), "config.toml");
244
+ const toml = readText(tomlFile);
245
+ if (toml !== null) {
246
+ const r = removeTomlBlock(toml);
247
+ if (r.removed) {
248
+ ctx.write(tomlFile, r.text);
249
+ ctx.note("removed", `${tomlFile} Harmony hooks block`);
250
+ }
251
+ }
252
+ const hooksFile = path.join(codexHome(), "hooks.json");
253
+ removeStep(ctx, hooksFile, "Harmony hook entries", (text) => removeHarmonyHooks(text, hooksFile));
254
+ },
255
+ installMcp(ctx) {
256
+ const file = path.join(codexHome(), "config.toml");
257
+ const toml = readText(file) || "";
258
+ if (toml.split("\n").some((l) => l.trim() === `[mcp_servers.${SERVER_NAME}]`)) {
259
+ return ctx.note("kept", `${file} [mcp_servers.${SERVER_NAME}] (already present)`);
260
+ }
261
+ const r = upsertCodexServer(toml, { env: {} });
262
+ ctx.write(file, r.text);
263
+ ctx.note(r.status, `${file} [mcp_servers.${SERVER_NAME}]`);
264
+ },
265
+ },
266
+ {
267
+ id: "cursor",
268
+ name: "Cursor",
269
+ tier: 1,
270
+ instructions: "AGENTS.md",
271
+ detect: () => exists(path.join(home(), ".cursor")) || Boolean(which("cursor")),
272
+ hookScopes: ["user", "project"],
273
+ hookFiles: (ctx) => [ctx.scope === "project" ? path.join(ctx.project, ".cursor", "hooks.json") : path.join(home(), ".cursor", "hooks.json")],
274
+ installHooks(ctx) {
275
+ const file = this.hookFiles(ctx)[0];
276
+ jsonStep(ctx, file, "postToolUse + preCompact hooks", (text) => {
277
+ let current = ensureKey(text, file, "version", 1);
278
+ const statuses = [];
279
+ for (const event of ["postToolUse", "preCompact"]) {
280
+ const command = hookCommand({ agent: "cursor", event: event === "postToolUse" ? null : event, scope: ctx.scope });
281
+ const r = upsertFlatHook(current, file, event, { command, timeout: HOOK_TIMEOUT_S });
282
+ current = r.text;
283
+ statuses.push(r.status);
284
+ }
285
+ return { text: current, status: summarize(statuses) };
286
+ });
287
+ },
288
+ installMcp(ctx) {
289
+ const { command, args } = mcpLaunch();
290
+ mcpJsonServer(ctx, path.join(home(), ".cursor", "mcp.json"), ["mcpServers", SERVER_NAME], { command, args });
291
+ },
292
+ },
293
+ {
294
+ id: "antigravity",
295
+ name: "Gemini CLI / Antigravity",
296
+ tier: 1,
297
+ instructions: "AGENTS.md / GEMINI.md",
298
+ detect: () => exists(path.join(home(), ".gemini")) || Boolean(which("gemini")) || exists(path.join(home(), ".antigravity")),
299
+ hookScopes: ["user", "project"],
300
+ hookFiles: (ctx) => [ctx.scope === "project" ? path.join(ctx.project, ".gemini", "settings.json") : path.join(home(), ".gemini", "settings.json")],
301
+ installHooks(ctx) {
302
+ const geminiHook = (command) => ({ name: "harmony-rsi", type: "command", command, timeout: HOOK_TIMEOUT_S * 1000 });
303
+ groupedHooks(ctx, this.hookFiles(ctx)[0], "antigravity", [
304
+ { event: "AfterTool", matcher: GEMINI_AFTER_TOOL_MATCHER, build: geminiHook },
305
+ { event: "PreCompress", matcher: undefined, build: geminiHook },
306
+ ]);
307
+ },
308
+ installMcp(ctx) {
309
+ const { command, args } = mcpLaunch();
310
+ mcpJsonServer(ctx, path.join(home(), ".gemini", "settings.json"), ["mcpServers", SERVER_NAME], { command, args });
311
+ },
312
+ },
313
+ {
314
+ id: "copilot",
315
+ name: "GitHub Copilot CLI",
316
+ tier: 1,
317
+ instructions: "AGENTS.md / .github/copilot-instructions.md",
318
+ detect: () => exists(copilotDir()) || Boolean(which("copilot")),
319
+ hookScopes: ["user", "project"],
320
+ // A file of our own: written whole, removed whole.
321
+ hookFiles: (ctx) => [ctx.scope === "project" ? path.join(ctx.project, ".github", "hooks", "harmony-rsi.json") : path.join(copilotDir(), "hooks", "harmony-rsi.json")],
322
+ installHooks(ctx) {
323
+ const file = this.hookFiles(ctx)[0];
324
+ const command = hookCommand({ agent: "copilot", scope: ctx.scope });
325
+ const entry = { type: "command", [process.platform === "win32" ? "powershell" : "bash"]: command, timeoutSec: HOOK_TIMEOUT_S };
326
+ const content = `${JSON.stringify({ version: 1, hooks: { postToolUse: [entry] } }, null, 2)}\n`;
327
+ const before = readText(file);
328
+ if (before === content) return ctx.note("unchanged", `${file} postToolUse hook`);
329
+ ctx.write(file, content);
330
+ ctx.note(before === null ? "added" : "updated", `${file} postToolUse hook`);
331
+ },
332
+ uninstallHooks(ctx) {
333
+ const file = this.hookFiles(ctx)[0];
334
+ if (readText(file) === null) return;
335
+ if (!ctx.dryRun) removeFile(file);
336
+ ctx.note("removed", file);
337
+ },
338
+ installMcp(ctx) {
339
+ const { command, args } = mcpLaunch();
340
+ mcpJsonServer(ctx, path.join(copilotDir(), "mcp-config.json"), ["mcpServers", SERVER_NAME], { type: "local", command, args, tools: ["*"] });
341
+ },
342
+ },
343
+ {
344
+ id: "opencode",
345
+ name: "OpenCode",
346
+ tier: 2,
347
+ instructions: "AGENTS.md",
348
+ detect: () => exists(path.join(home(), ".config", "opencode")) || Boolean(which("opencode")),
349
+ hooksPending: "plugin pending (OpenCode's post-tool event fields are undocumented)",
350
+ installMcp(ctx) {
351
+ const dir = path.join(home(), ".config", "opencode");
352
+ const file = exists(path.join(dir, "opencode.jsonc")) ? path.join(dir, "opencode.jsonc") : path.join(dir, "opencode.json");
353
+ const { command, args } = mcpLaunch();
354
+ mcpJsonServer(ctx, file, ["mcp", SERVER_NAME], { type: "local", command: [command, ...args], enabled: true });
355
+ },
356
+ },
357
+ {
358
+ id: "kilo-code",
359
+ name: "Kilo Code",
360
+ tier: 2,
361
+ instructions: "AGENTS.md",
362
+ detect: () => exists(path.join(home(), ".config", "kilocode")) || exists(path.join(home(), ".kilocode")),
363
+ hooksPending: "plugin pending (same plugin API as OpenCode)",
364
+ },
365
+ {
366
+ id: "windsurf",
367
+ name: "Windsurf / Devin",
368
+ tier: 2,
369
+ instructions: "AGENTS.md / .windsurfrules",
370
+ detect: () => exists(path.join(home(), ".codeium", "windsurf")),
371
+ hooksPending: "no Cascade hook normalizer yet",
372
+ installMcp(ctx) {
373
+ const { command, args } = mcpLaunch();
374
+ mcpJsonServer(ctx, path.join(home(), ".codeium", "windsurf", "mcp_config.json"), ["mcpServers", SERVER_NAME], { command, args });
375
+ },
376
+ },
377
+ {
378
+ id: "amazon-q",
379
+ name: "Amazon Q Developer",
380
+ tier: 3,
381
+ instructions: "AGENTS.md",
382
+ detect: () => exists(path.join(home(), ".aws", "amazonq")) || Boolean(which("q")),
383
+ installMcp(ctx) {
384
+ const { command, args } = mcpLaunch();
385
+ mcpJsonServer(ctx, path.join(home(), ".aws", "amazonq", "mcp.json"), ["mcpServers", SERVER_NAME], { command, args });
386
+ },
387
+ },
388
+ ...[
389
+ ["cline", "Cline / Roo Code", 2, () => exists(path.join(home(), "Documents", "Cline")), "VS Code extension MCP settings"],
390
+ ["amp", "Amp", 2, () => exists(path.join(home(), ".config", "amp")) || Boolean(which("amp")), "~/.config/amp/settings.json"],
391
+ ["aider", "Aider", 3, () => exists(path.join(home(), ".aider.conf.yml")) || Boolean(which("aider")), "~/.aider.conf.yml (read: AGENTS.md)"],
392
+ ["continue", "Continue", 3, () => exists(path.join(home(), ".continue")), "~/.continue/config.yaml"],
393
+ ["goose", "Goose", 3, () => exists(path.join(home(), ".config", "goose")) || Boolean(which("goose")), "~/.config/goose/config.yaml"],
394
+ ["zed", "Zed", 3, () => exists(path.join(home(), ".config", "zed")), "~/.config/zed/settings.json context_servers"],
395
+ ["junie", "JetBrains Junie", 3, () => false, "JetBrains MCP settings + .junie/guidelines.md"],
396
+ ["factory", "Factory Droids", 3, () => exists(path.join(home(), ".factory")) || Boolean(which("droid")), "~/.factory MCP config"],
397
+ ].map(([id, name, tier, detect, where]) => ({ id, name, tier, detect, instructions: "AGENTS.md", manualMcp: where })),
398
+ ];
399
+
400
+ // Uninstall for JSON hook files (all agents that don't define their own).
401
+ export function defaultUninstallHooks(agent, ctx) {
402
+ for (const file of agent.hookFiles(ctx)) {
403
+ removeStep(ctx, file, "Harmony hook entries", (text) => removeHarmonyHooks(text, file));
404
+ }
405
+ }
406
+
407
+ // Read-only: is the Harmony MCP server configured for this agent? (true / false / null = unknown)
408
+ export function mcpConfigured(agent) {
409
+ switch (agent.id) {
410
+ case "codex":
411
+ return (readText(path.join(codexHome(), "config.toml")) || "").includes(`[mcp_servers.${SERVER_NAME}]`);
412
+ case "cursor":
413
+ return mcpStatusFromJson(path.join(home(), ".cursor", "mcp.json"), ["mcpServers", SERVER_NAME]);
414
+ case "antigravity":
415
+ return mcpStatusFromJson(path.join(home(), ".gemini", "settings.json"), ["mcpServers", SERVER_NAME]);
416
+ case "copilot":
417
+ return mcpStatusFromJson(path.join(copilotDir(), "mcp-config.json"), ["mcpServers", SERVER_NAME]);
418
+ case "windsurf":
419
+ return mcpStatusFromJson(path.join(home(), ".codeium", "windsurf", "mcp_config.json"), ["mcpServers", SERVER_NAME]);
420
+ case "amazon-q":
421
+ return mcpStatusFromJson(path.join(home(), ".aws", "amazonq", "mcp.json"), ["mcpServers", SERVER_NAME]);
422
+ default:
423
+ return null;
424
+ }
425
+ }
@@ -0,0 +1,28 @@
1
+ // Guidance block for a project's AGENTS.md (Codex, and other agents that read it). Agents such as Codex don't
2
+ // reliably surface MCP server instructions to the model, so the "Harmony vs. rg" decision has to live in the
3
+ // file they always load. Printed by `harmony-mcp --print-agents-md`; keep tool names in sync with toolSchemas.js.
4
+ //
5
+ // v2: written from Codex benchmark logs. Codex used Harmony *on top of* its usual shell reads (same number of
6
+ // shell commands, ~2x tokens), passed method names to inspect_trace (which only matches routes), re-read code
7
+ // Harmony had already returned, and opened files one command at a time. Every rule below targets one of those.
8
+ // v3: shorter; adds waiting for Harmony to load, checking results match the question, and "stop when every part
9
+ // is answered" (from the Fineract tests: Codex skipped Harmony while it was loading and trusted a wrong route).
10
+ export const AGENTS_MD_GUIDE = `
11
+ ## Code search: use Harmony first
12
+
13
+ This repo is indexed by the \`harmony\` MCP server. Its results include the relevant code with file paths and line numbers.
14
+
15
+ 1. **Wait for Harmony.** Its tools can take a few seconds to load. If they are missing, call \`setup_workspace\` or check again before using shell search.
16
+ 2. **Start with one Harmony call:**
17
+ - How something works → \`investigate\`
18
+ - An HTTP route → \`inspect_trace\` with \`VERB /path\`
19
+ - A named class or method → \`locate\`
20
+ - Files related to a topic → \`context_search\`
21
+ - Impact of a change → \`preflight\`
22
+ - Contents of one known file → read it directly with a shell command instead
23
+ 3. **Check the result.** If it does not match what you asked for (a different route, class or method), retry once with \`locate\`; if it still does not match, use \`rg\`.
24
+ 4. **Do not re-read code Harmony already returned.**
25
+ 5. **Fill gaps in at most two shell commands**, printing only the lines you need. Use \`rg\` for exact strings, config files and file names.
26
+ 6. **Stop when every part of the question is answered**, and cite \`path:line\`.
27
+ 7. \`[In context: path:Lx-Ly — unchanged]\` means Harmony already sent that code earlier; use it from context. Call again with \`force_refresh: true\` only if it is no longer in your context.
28
+ `.trim();