@codeconductorai/harmony-mcp 1.0.30 → 1.0.32
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 +92 -8
- package/package.json +1 -1
- package/src/agentsGuide.js +38 -0
- package/src/fileWatcher.js +51 -4
- package/src/harmonyClient.js +124 -29
- package/src/index.js +11 -30
- package/src/installer.js +295 -0
- package/src/server.js +95 -30
- package/src/serverInstructions.js +82 -26
- package/src/serverMain.js +32 -0
- package/src/sessionIdentity.js +152 -0
- package/src/toolSchemas.js +185 -38
|
@@ -75,27 +75,23 @@ to act on — it doesn't replace them, and it doesn't apply to the setup/auth to
|
|
|
75
75
|
|
|
76
76
|
const ROUTING_RULES = `
|
|
77
77
|
Choosing among Harmony's tools — once Harmony is the right move for a lookup, pick the narrowest fit:
|
|
78
|
-
- \`
|
|
79
|
-
token-budgeted architectural overview (the most structurally important files by call-graph
|
|
80
|
-
centrality and subsystem clustering, with their top symbols) in one call, instead of directory
|
|
81
|
-
traversals or a string of unscoped context_search calls just to build a mental model. Pass
|
|
82
|
-
focus_files when specific files are already known to be relevant (open in the editor, mentioned by
|
|
83
|
-
the user) to rank them first. This is orientation, not a substitute for the targeted lookups below
|
|
84
|
-
— move on to context_search/locate once you have specific symbols or files in mind.
|
|
85
|
-
- \`context_search\` — usually the best starting point for open-ended discovery/comprehension: ranked
|
|
78
|
+
- \`context_search\` — open-ended discovery (which files and modules a concept spans): ranked
|
|
86
79
|
matching symbols with code snippets, file paths, and relevance for a natural language query or
|
|
87
80
|
exact identifier.
|
|
88
81
|
- \`locate\` — "which file(s) handle X" / "where is X" for a task you're about to edit. Returns every
|
|
89
82
|
matching symbol occurrence (definitions and references) with exact line numbers, optionally scoped
|
|
90
83
|
to a file_path once you already know the file.
|
|
91
|
-
- \`
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
84
|
+
- \`investigate\` — like context_search, but answers as edit-ready code slices with handles (@s1, @t1)
|
|
85
|
+
you can refer back to; \`inspect_trace\` — one execution flow (a route, entry method or @t handle)
|
|
86
|
+
with the code of each hop.
|
|
87
|
+
- \`preflight\` — before changing a shared file or public method: dependents, impacted tests, traces
|
|
88
|
+
and security findings it touches.
|
|
89
|
+
- \`security_audit\` / \`security_finding_action\` — findings grouped by root cause as @g/@f handles;
|
|
90
|
+
delta_only after a fix; inspect or mute a handle. \`compress_build_log\` — pass a long build/test log
|
|
91
|
+
instead of reading it. \`session_checkpoint\` — a ~500-token snapshot to keep before context is cleared.
|
|
92
|
+
Within a session, Harmony returns code it already sent as \`[In context: path:Lx-Ly]\` /
|
|
93
|
+
\`<in_context .../>\` references — that code is earlier in your context. If it is not (after /clear or
|
|
94
|
+
compaction, or as a subagent), repeat the call with \`force_refresh: true\`.
|
|
99
95
|
|
|
100
96
|
If context_search's result is empty or insufficient, or you specifically need locate's line-number-
|
|
101
97
|
only anchors, fall back to that narrower tool rather than retrying context_search. Composing that
|
|
@@ -128,12 +124,11 @@ First try whichever other Harmony tool is the next-best fit for that same lookup
|
|
|
128
124
|
anything the failed call already surfaced (a symbol name, a file path) into the new call rather than
|
|
129
125
|
starting from scratch:
|
|
130
126
|
- \`context_search\` came up empty/insufficient → try \`locate\` with the same (or refined) prompt for
|
|
131
|
-
its line-number anchors, or \`
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
instead of assuming the symbol isn't there.
|
|
127
|
+
its line-number anchors, or \`investigate\` with the question in plain words.
|
|
128
|
+
- \`locate\` came up empty for a file you already know → try \`investigate\` with that file in
|
|
129
|
+
\`focus_files\` instead of assuming the symbol isn't there.
|
|
135
130
|
- A coupling/"what depends on this" question came up empty from \`context_search\`/\`locate\` → try
|
|
136
|
-
\`
|
|
131
|
+
\`preflight\` on the file in question (it lists dependents, impacted tests and traces).
|
|
137
132
|
- Any symbol-shaped query came up empty as a natural-language \`prompt\` → retry it as \`locate\` with
|
|
138
133
|
the exact identifier instead, in case the phrasing (not the index) was the problem.
|
|
139
134
|
Only once that alternate Harmony tool has also failed to turn up anything relevant should you fall
|
|
@@ -164,6 +159,27 @@ calls fast and non-redundant:
|
|
|
164
159
|
general-purpose ranking pass again.
|
|
165
160
|
`.trim();
|
|
166
161
|
|
|
162
|
+
const ANSWER_IN_FEWEST_STEPS = `
|
|
163
|
+
Getting the answer in the fewest steps — every extra tool call re-reads the whole conversation, so
|
|
164
|
+
use Harmony INSTEAD of opening files, not as well as:
|
|
165
|
+
1. Start with ONE Harmony call chosen by the question:
|
|
166
|
+
- "How does X work / where is X handled / what happens when ..." → \`investigate\` with the
|
|
167
|
+
question in plain words; it returns the relevant method bodies as code slices with path and line
|
|
168
|
+
numbers, usually enough to answer.
|
|
169
|
+
- An HTTP route → \`inspect_trace\` with the route as \`VERB /path\` (never a class or method name).
|
|
170
|
+
- Where a named class/method is defined or used → \`locate\` with the exact name.
|
|
171
|
+
- Which files/modules a concept spans → \`context_search\`.
|
|
172
|
+
- Before changing shared or public code → \`preflight\`.
|
|
173
|
+
2. Treat code Harmony returned as already read. Do not Read, cat or Grep the same file or line range
|
|
174
|
+
again to confirm it.
|
|
175
|
+
3. If something is still missing, fill only that gap, in ONE step: one more Harmony call using the
|
|
176
|
+
exact names you saw, or a Read with offset/limit on just the missing lines. Issue independent
|
|
177
|
+
follow-ups in parallel in the same turn. Never read a whole file Harmony already covered.
|
|
178
|
+
4. Use Grep/Glob directly (not Harmony) for exact strings, config/properties files, templates and
|
|
179
|
+
file names.
|
|
180
|
+
5. Stop and answer as soon as the evidence covers the question, citing path:line from the results.
|
|
181
|
+
`.trim();
|
|
182
|
+
|
|
167
183
|
const SETUP_INSTRUCTIONS = `
|
|
168
184
|
Workspace setup — before the first search/locate/context call in a project:
|
|
169
185
|
- Call \`setup_workspace\` once with the project's language and build tool (infer from
|
|
@@ -185,11 +201,26 @@ Workspace setup — before the first search/locate/context call in a project:
|
|
|
185
201
|
after a short wait to re-check — repeat until \`ready\` is true. If it instead reports only
|
|
186
202
|
partially finished (symbols failed/skipped — the symbol-level tools may return incomplete or no
|
|
187
203
|
results) or failed outright, relay that instead of retrying blindly.
|
|
204
|
+
- If it returns error "secrets_detected", the backend found potential hardcoded secrets and stored
|
|
205
|
+
nothing. Show the user the listed findings (file, line, type, masked snippet) and ask whether to
|
|
206
|
+
move the secrets out of the code first, or index the workspace with them anyway. Only after the
|
|
207
|
+
user explicitly agrees in chat to index with the secrets, call \`setup_workspace\` again with
|
|
208
|
+
allowSecrets: true. Never set allowSecrets on your own initiative or before asking. If the
|
|
209
|
+
response says bypass is not allowed, the server forbids it: the secrets must be removed first.
|
|
210
|
+
`.trim();
|
|
211
|
+
|
|
212
|
+
// Ready state: setup is done, so the full setup guide above is dead weight in every session's
|
|
213
|
+
// prompt. Keep only the re-sync hint; secrets-consent rules travel in the secrets_detected
|
|
214
|
+
// response itself and security_scan guidance in that tool's (deferred) description.
|
|
215
|
+
const READY_SETUP_NOTE = `
|
|
216
|
+
Workspace is set up and indexed. If the code changed outside the file watcher (e.g. a branch
|
|
217
|
+
switch), call \`setup_workspace\` again — it only re-uploads when something changed. If it returns
|
|
218
|
+
"secrets_detected", follow that response's nextStep exactly.
|
|
188
219
|
`.trim();
|
|
189
220
|
|
|
190
221
|
const AUTH_INSTRUCTIONS = `
|
|
191
|
-
Auth gate — context_search, locate,
|
|
192
|
-
|
|
222
|
+
Auth gate — context_search, locate, security_scan, investigate, inspect_trace, preflight, security_audit,
|
|
223
|
+
security_finding_action, compress_build_log and session_checkpoint all
|
|
193
224
|
return a "not authenticated" error until login has succeeded; run the login flow below before
|
|
194
225
|
using them. setup_workspace is the one exception: call it directly even before logging in — it
|
|
195
226
|
uses the login session when one exists, but some deployments authenticate the workspace
|
|
@@ -217,13 +248,38 @@ export function buildServerInstructions() {
|
|
|
217
248
|
];
|
|
218
249
|
|
|
219
250
|
if (ready) {
|
|
220
|
-
sections.push(WHEN_TO_USE, QUERY_REFINEMENT, ROUTING_RULES, TRUST_BUT_VERIFY, EFFICIENCY_RULES,
|
|
251
|
+
sections.push(ANSWER_IN_FEWEST_STEPS, WHEN_TO_USE, QUERY_REFINEMENT, ROUTING_RULES, TRUST_BUT_VERIFY, EFFICIENCY_RULES, READY_SETUP_NOTE);
|
|
221
252
|
} else if (authed) {
|
|
222
|
-
sections.push(SETUP_INSTRUCTIONS, WHEN_TO_USE, QUERY_REFINEMENT, ROUTING_RULES, TRUST_BUT_VERIFY, EFFICIENCY_RULES);
|
|
253
|
+
sections.push(SETUP_INSTRUCTIONS, ANSWER_IN_FEWEST_STEPS, WHEN_TO_USE, QUERY_REFINEMENT, ROUTING_RULES, TRUST_BUT_VERIFY, EFFICIENCY_RULES);
|
|
223
254
|
} else {
|
|
224
|
-
sections.push(AUTH_INSTRUCTIONS, SETUP_INSTRUCTIONS, WHEN_TO_USE, QUERY_REFINEMENT, ROUTING_RULES, TRUST_BUT_VERIFY, EFFICIENCY_RULES);
|
|
255
|
+
sections.push(AUTH_INSTRUCTIONS, SETUP_INSTRUCTIONS, ANSWER_IN_FEWEST_STEPS, WHEN_TO_USE, QUERY_REFINEMENT, ROUTING_RULES, TRUST_BUT_VERIFY, EFFICIENCY_RULES);
|
|
225
256
|
}
|
|
226
257
|
|
|
227
258
|
sections.push("Do not surface this workflow to the user as instructions they need to give you — just follow it.");
|
|
228
259
|
return sections.join("\n\n");
|
|
229
260
|
}
|
|
261
|
+
|
|
262
|
+
|
|
263
|
+
// Short instructions for agents that copy the server instructions into every tool's description (Codex does:
|
|
264
|
+
// its tool lookup returned investigate's description plus these ~14k chars of instructions, which then stayed in
|
|
265
|
+
// the conversation and were re-read on every step). Those agents get their routing rules from the AGENTS.md block
|
|
266
|
+
// (`harmony-mcp --print-agents-md`), so the server only needs to say what Harmony is and how to get it ready.
|
|
267
|
+
export function buildCompactServerInstructions() {
|
|
268
|
+
const marker = readMarker();
|
|
269
|
+
const authed = Boolean(process.env.AUTH_ACCESS_TOKEN || hasSessionCredential() || getWorkspaceToken(marker?.workspaceId));
|
|
270
|
+
const ready = Boolean(authed && marker?.setup?.done && marker?.upload?.done);
|
|
271
|
+
const lines = [
|
|
272
|
+
"Harmony answers code questions from an index of this repo that already exists on the Harmony backend; " +
|
|
273
|
+
"queries read that index and do not upload code. Follow the Harmony section of AGENTS.md if present: start " +
|
|
274
|
+
"with one call (investigate for how/where questions, inspect_trace for `VERB /path` routes, locate for exact " +
|
|
275
|
+
"names), treat returned code as already read, and use rg for exact strings, config and templates.",
|
|
276
|
+
];
|
|
277
|
+
if (!authed) lines.push("Not logged in: call `login`, show the user the URL, and call `confirm_login` only after they say they finished.");
|
|
278
|
+
if (!ready) lines.push("Workspace not indexed yet: call `setup_workspace` (language + build tool) once; it uploads and indexes the repo.");
|
|
279
|
+
return lines.join("\n");
|
|
280
|
+
}
|
|
281
|
+
|
|
282
|
+
// Clients whose MCP integration inlines server instructions into tool descriptions.
|
|
283
|
+
export function prefersCompactInstructions(clientInfo) {
|
|
284
|
+
return /codex/i.test(String(clientInfo?.name || ""));
|
|
285
|
+
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import "./telemetry.js";
|
|
2
|
+
import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
|
|
3
|
+
|
|
4
|
+
import { log } from "./log.js";
|
|
5
|
+
import { shutdownTelemetry } from "./telemetry.js";
|
|
6
|
+
import { getCurrentUsername } from "./workspaceIdentity.js";
|
|
7
|
+
import { startFileWatcher, stopFileWatcher } from "./fileWatcher.js";
|
|
8
|
+
import { buildMcpServer } from "./server.js";
|
|
9
|
+
import { currentSessionId, sessionIdSource } from "./sessionIdentity.js";
|
|
10
|
+
|
|
11
|
+
process.on("exit", stopFileWatcher);
|
|
12
|
+
process.on("SIGINT", async () => {
|
|
13
|
+
stopFileWatcher();
|
|
14
|
+
await shutdownTelemetry();
|
|
15
|
+
process.exit(0);
|
|
16
|
+
});
|
|
17
|
+
process.on("SIGTERM", async () => {
|
|
18
|
+
stopFileWatcher();
|
|
19
|
+
await shutdownTelemetry();
|
|
20
|
+
process.exit(0);
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
const transport = new StdioServerTransport();
|
|
24
|
+
const server = buildMcpServer();
|
|
25
|
+
await server.connect(transport);
|
|
26
|
+
log(`Harmony MCP started (stdio) | user: ${getCurrentUsername()} | session: ${currentSessionId()} (${sessionIdSource()})`);
|
|
27
|
+
|
|
28
|
+
try {
|
|
29
|
+
startFileWatcher();
|
|
30
|
+
} catch (err) {
|
|
31
|
+
log(`[workspace] Bootstrap skipped: ${err?.message || err}`);
|
|
32
|
+
}
|
|
@@ -0,0 +1,152 @@
|
|
|
1
|
+
// Which agent session a Harmony request belongs to (sent as X-Mcp-Session-Id).
|
|
2
|
+
//
|
|
3
|
+
// The backend keeps per-session state under this id: handles (@s1, @g1, ...), security-audit baselines, and the
|
|
4
|
+
// code slices already sent, which it later replaces with short "[In context: ...]" back-references. So the id must
|
|
5
|
+
// change whenever the agent's context is reset, or the agent gets references to code it can no longer see.
|
|
6
|
+
//
|
|
7
|
+
// Resolution order, checked on every request:
|
|
8
|
+
// 1. HARMONY_SESSION_ID env — explicit override for any agent.
|
|
9
|
+
// 2. The latest session recorded by the Claude Code / Codex SessionStart hook (`harmony-mcp --session-hook`).
|
|
10
|
+
// SessionStart fires on startup, resume, /clear (new session id) and compaction (same id), so this tracks
|
|
11
|
+
// /clear, and a compaction count is appended ("<id>#compact-2") so compacted-away code is never referenced.
|
|
12
|
+
// 3. CLAUDE_CODE_SESSION_ID env — Claude Code's session id at the time this MCP process was started.
|
|
13
|
+
// 4. A UUID generated for this MCP process — for agents that expose no session id.
|
|
14
|
+
import fs from "fs";
|
|
15
|
+
import os from "os";
|
|
16
|
+
import path from "path";
|
|
17
|
+
import { execFileSync } from "child_process";
|
|
18
|
+
|
|
19
|
+
import { SESSION_ID as PROCESS_SESSION_ID } from "./log.js";
|
|
20
|
+
|
|
21
|
+
export const SESSION_HOOK_DIR = path.join(os.homedir(), ".harmony-mcp", "claude-sessions");
|
|
22
|
+
|
|
23
|
+
// Agent CLIs whose SessionStart hook can run `harmony-mcp --session-hook` (same stdin payload in both).
|
|
24
|
+
const AGENT_PROCESS_NAMES = new Set(["claude", "codex"]);
|
|
25
|
+
const MAX_ANCESTOR_DEPTH = 6;
|
|
26
|
+
|
|
27
|
+
// { ppid, name } of a process, or null if it can't be read.
|
|
28
|
+
function processInfo(pid) {
|
|
29
|
+
try {
|
|
30
|
+
const stat = fs.readFileSync(`/proc/${pid}/stat`, "utf8");
|
|
31
|
+
// Field 2 (comm) is in parens and may contain spaces; field 4 is the parent pid.
|
|
32
|
+
const name = stat.slice(stat.indexOf("(") + 1, stat.lastIndexOf(")"));
|
|
33
|
+
return { ppid: Number(stat.slice(stat.lastIndexOf(")") + 2).split(" ")[1]), name };
|
|
34
|
+
} catch {
|
|
35
|
+
try {
|
|
36
|
+
const out = execFileSync("ps", ["-o", "ppid=,comm=", "-p", String(pid)], { encoding: "utf8" }).trim();
|
|
37
|
+
const [, ppid, comm] = out.match(/^(\d+)\s+(.*)$/) || [];
|
|
38
|
+
return ppid ? { ppid: Number(ppid), name: path.basename(comm) } : null;
|
|
39
|
+
} catch {
|
|
40
|
+
return null;
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
// Ancestor pids of this process, nearest first.
|
|
46
|
+
function ancestors() {
|
|
47
|
+
const pids = [];
|
|
48
|
+
let pid = process.ppid;
|
|
49
|
+
for (let depth = 0; pid && pid > 1 && depth < MAX_ANCESTOR_DEPTH; depth++) {
|
|
50
|
+
const info = processInfo(pid);
|
|
51
|
+
pids.push({ pid: String(pid), name: info?.name || "" });
|
|
52
|
+
pid = info?.ppid;
|
|
53
|
+
}
|
|
54
|
+
return pids;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
// The agent CLI (Claude Code or Codex) this process runs under. The hook process and the MCP server are both
|
|
58
|
+
// spawned by it, but through different wrappers (sh, npx, npm), so their direct parents never match; the nearest
|
|
59
|
+
// agent ancestor does. CLAUDE_PID is exported by Claude Code to both; Codex sets no equivalent.
|
|
60
|
+
function agentPid() {
|
|
61
|
+
if (process.env.CLAUDE_PID) return String(process.env.CLAUDE_PID);
|
|
62
|
+
return ancestors().find((a) => AGENT_PROCESS_NAMES.has(a.name))?.pid || null;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
// Pids a hook record for this MCP process may be filed under: the agent ancestor, then the raw ancestry (records
|
|
66
|
+
// written by an older hook keyed by its direct parent).
|
|
67
|
+
let candidatePids = null;
|
|
68
|
+
function claudeProcessCandidates() {
|
|
69
|
+
if (candidatePids) return candidatePids;
|
|
70
|
+
candidatePids = [...new Set([agentPid(), ...ancestors().map((a) => a.pid)].filter(Boolean))];
|
|
71
|
+
return candidatePids;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
function hookRecordedSession() {
|
|
75
|
+
for (const pid of claudeProcessCandidates()) {
|
|
76
|
+
try {
|
|
77
|
+
const record = JSON.parse(fs.readFileSync(path.join(SESSION_HOOK_DIR, `${pid}.json`), "utf8"));
|
|
78
|
+
if (record?.sessionId) {
|
|
79
|
+
return record.compactions > 0 ? `${record.sessionId}#compact-${record.compactions}` : record.sessionId;
|
|
80
|
+
}
|
|
81
|
+
} catch {
|
|
82
|
+
// no record for this pid
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
return null;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
export function currentSessionId() {
|
|
89
|
+
return (
|
|
90
|
+
process.env.HARMONY_SESSION_ID ||
|
|
91
|
+
hookRecordedSession() ||
|
|
92
|
+
process.env.CLAUDE_CODE_SESSION_ID ||
|
|
93
|
+
PROCESS_SESSION_ID
|
|
94
|
+
);
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
export function sessionIdSource() {
|
|
98
|
+
if (process.env.HARMONY_SESSION_ID) return "env:HARMONY_SESSION_ID";
|
|
99
|
+
if (hookRecordedSession()) return "agent:session-start-hook";
|
|
100
|
+
if (process.env.CLAUDE_CODE_SESSION_ID) return "env:CLAUDE_CODE_SESSION_ID";
|
|
101
|
+
return "generated";
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
// `harmony-mcp --session-hook`: run as a Claude Code or Codex SessionStart hook. Reads the hook JSON from stdin
|
|
105
|
+
// ({session_id, source: startup|resume|clear|compact} in both) and records the session for the agent process that
|
|
106
|
+
// ran it (CLAUDE_PID, else the nearest claude/codex ancestor, else the hook's parent).
|
|
107
|
+
export async function runSessionHook() {
|
|
108
|
+
let raw = "";
|
|
109
|
+
for await (const chunk of process.stdin) raw += chunk;
|
|
110
|
+
let input = {};
|
|
111
|
+
try {
|
|
112
|
+
input = JSON.parse(raw || "{}");
|
|
113
|
+
} catch {
|
|
114
|
+
process.exit(0);
|
|
115
|
+
}
|
|
116
|
+
const sessionId = input.session_id;
|
|
117
|
+
if (!sessionId) process.exit(0);
|
|
118
|
+
const claudePid = agentPid() || String(process.ppid);
|
|
119
|
+
const file = path.join(SESSION_HOOK_DIR, `${claudePid}.json`);
|
|
120
|
+
let previous = null;
|
|
121
|
+
try {
|
|
122
|
+
previous = JSON.parse(fs.readFileSync(file, "utf8"));
|
|
123
|
+
} catch {
|
|
124
|
+
// first record for this process
|
|
125
|
+
}
|
|
126
|
+
const compactions =
|
|
127
|
+
input.source === "compact" && previous?.sessionId === sessionId ? (previous.compactions || 0) + 1 : 0;
|
|
128
|
+
fs.mkdirSync(SESSION_HOOK_DIR, { recursive: true });
|
|
129
|
+
fs.writeFileSync(
|
|
130
|
+
file,
|
|
131
|
+
JSON.stringify({ sessionId, source: input.source || null, compactions, updatedAt: new Date().toISOString() }),
|
|
132
|
+
);
|
|
133
|
+
pruneStaleRecords();
|
|
134
|
+
process.exit(0);
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
// Drop records of Claude processes that no longer exist, so the directory doesn't grow forever.
|
|
138
|
+
function pruneStaleRecords() {
|
|
139
|
+
try {
|
|
140
|
+
for (const name of fs.readdirSync(SESSION_HOOK_DIR)) {
|
|
141
|
+
const pid = Number(name.replace(/\.json$/, ""));
|
|
142
|
+
if (!pid) continue;
|
|
143
|
+
try {
|
|
144
|
+
process.kill(pid, 0);
|
|
145
|
+
} catch (e) {
|
|
146
|
+
if (e.code === "ESRCH") fs.rmSync(path.join(SESSION_HOOK_DIR, name), { force: true });
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
} catch {
|
|
150
|
+
// best effort
|
|
151
|
+
}
|
|
152
|
+
}
|
package/src/toolSchemas.js
CHANGED
|
@@ -7,6 +7,16 @@ const WORKSPACE_ID_PROPERTY = {
|
|
|
7
7
|
"local workspace set up by setup_workspace.",
|
|
8
8
|
};
|
|
9
9
|
|
|
10
|
+
// Harmony remembers which code each MCP session already received and sends repeats as short
|
|
11
|
+
// back-references. This flag turns that off for one call.
|
|
12
|
+
const FORCE_REFRESH_PROPERTY = {
|
|
13
|
+
type: "boolean",
|
|
14
|
+
description:
|
|
15
|
+
"Optional, default false. Code this session already received comes back as a short back-reference. " +
|
|
16
|
+
"Set true when that earlier output is no longer in your context (context cleared or compacted, or you " +
|
|
17
|
+
"are a subagent that did not see the parent's results) to get every slice in full.",
|
|
18
|
+
};
|
|
19
|
+
|
|
10
20
|
export const TOOLS = [
|
|
11
21
|
{
|
|
12
22
|
name: "login",
|
|
@@ -64,6 +74,13 @@ export const TOOLS = [
|
|
|
64
74
|
"Build tool (e.g. MAVEN, GRADLE, NPM). Required the first time; can be omitted on a retry, since " +
|
|
65
75
|
"it's remembered from the workspace's prior setup call.",
|
|
66
76
|
},
|
|
77
|
+
allowSecrets: {
|
|
78
|
+
type: "boolean",
|
|
79
|
+
description:
|
|
80
|
+
"Index the workspace even though the backend detected hardcoded secrets in it. Only set to true " +
|
|
81
|
+
"after a previous call returned error \"secrets_detected\" AND the user has explicitly agreed in " +
|
|
82
|
+
"chat to index the code with those secrets. Never set it otherwise.",
|
|
83
|
+
},
|
|
67
84
|
},
|
|
68
85
|
required: [],
|
|
69
86
|
},
|
|
@@ -110,6 +127,7 @@ export const TOOLS = [
|
|
|
110
127
|
"Optional, default true. Each returned symbol (and each step of a traced flow) includes its source " +
|
|
111
128
|
"excerpt (method or class body, capped at 50 lines). Set false to get file paths and line numbers only.",
|
|
112
129
|
},
|
|
130
|
+
force_refresh: FORCE_REFRESH_PROPERTY,
|
|
113
131
|
workspaceId: WORKSPACE_ID_PROPERTY,
|
|
114
132
|
},
|
|
115
133
|
required: ["prompt"],
|
|
@@ -160,80 +178,209 @@ export const TOOLS = [
|
|
|
160
178
|
},
|
|
161
179
|
},
|
|
162
180
|
{
|
|
163
|
-
name: "
|
|
181
|
+
name: "security_scan",
|
|
164
182
|
description:
|
|
165
|
-
"
|
|
166
|
-
"
|
|
167
|
-
"
|
|
168
|
-
"
|
|
183
|
+
"Scans the indexed workspace's code on the backend for security and code-quality issues and returns " +
|
|
184
|
+
"findings sorted most severe first (rule, severity, CWE/OWASP, file:line, message, snippet, " +
|
|
185
|
+
"recommendation). Checks: SECRETS (hardcoded passwords/API keys/tokens/private keys, every language), " +
|
|
186
|
+
"SECURITY (Java SQL injection, command injection, insecure deserialization, XXE, weak crypto, insecure " +
|
|
187
|
+
"Random), ENDPOINT_AUTH (Spring routes reachable without authentication, or privileged routes left " +
|
|
188
|
+
"public), DATA_EXPOSURE (Java sensitive values in logs/console, stack traces sent to clients), " +
|
|
189
|
+
"UNUSED_CODE (Java unused imports/private fields/private methods), DEPENDENCIES (third-party libraries " +
|
|
190
|
+
"in pom.xml/build.gradle/package(-lock).json/requirements.txt/poetry.lock/*.csproj/go.mod with known " +
|
|
191
|
+
"vulnerabilities from OSV.dev, each with the version that fixes it). Use it when the user asks to scan, " +
|
|
192
|
+
"audit or review the code for security issues or vulnerable/outdated dependencies, and again after fixing " +
|
|
193
|
+
"to confirm. Read the response's warnings (e.g. dependencies not checked). Findings are " +
|
|
194
|
+
"static-analysis heuristics: verify each in the code before changing it. Secret values are always " +
|
|
195
|
+
"masked; never try to recover them. Covers the code as last uploaded/synced to the backend. " +
|
|
196
|
+
"Reporting: summarise by severity, then list findings most severe first (rule, path:line, message); " +
|
|
197
|
+
"narrow follow-ups with checks / min_severity / file_path instead of re-running everything; say when a " +
|
|
198
|
+
"finding looks like a false positive. Fixing: move a secret to an environment variable or secrets " +
|
|
199
|
+
"manager reference (e.g. ${DB_PASSWORD}) rather than deleting the configuration, and tell the user to " +
|
|
200
|
+
"rotate it since it was committed. For VULNERABLE_DEPENDENCY, change the declared version (or the " +
|
|
201
|
+
"parent/BOM/lockfile that controls it), flag possible breaking changes on major-version jumps, and " +
|
|
202
|
+
"suggest rebuilding and running tests. After edits, give the file watcher a moment (or call " +
|
|
203
|
+
"setup_workspace) before re-scanning to confirm the findings are gone.",
|
|
169
204
|
inputSchema: {
|
|
170
205
|
type: "object",
|
|
171
206
|
properties: {
|
|
172
207
|
file_path: {
|
|
173
208
|
type: "string",
|
|
174
|
-
description:
|
|
209
|
+
description:
|
|
210
|
+
"Optional case-insensitive path substring restricting reported findings to a subdirectory, module, " +
|
|
211
|
+
"or file (e.g. 'src/main/java/com/acme/web'). Endpoint auth still reads the whole project's " +
|
|
212
|
+
"security config.",
|
|
213
|
+
},
|
|
214
|
+
checks: {
|
|
215
|
+
type: "array",
|
|
216
|
+
items: { type: "string", enum: ["SECRETS", "SECURITY", "ENDPOINT_AUTH", "DATA_EXPOSURE", "UNUSED_CODE", "DEPENDENCIES"] },
|
|
217
|
+
description: "Optional subset of checks to run. Omit to run all.",
|
|
218
|
+
},
|
|
219
|
+
min_severity: {
|
|
220
|
+
type: "string",
|
|
221
|
+
enum: ["CRITICAL", "HIGH", "MEDIUM", "LOW", "INFO"],
|
|
222
|
+
description: "Optional lowest severity to report, e.g. HIGH to skip MEDIUM/LOW findings.",
|
|
175
223
|
},
|
|
176
|
-
|
|
224
|
+
limit: {
|
|
177
225
|
type: "number",
|
|
178
|
-
description:
|
|
179
|
-
"Traversal depth: 1 (default) for direct dependencies only, 2 for one further transitive hop.",
|
|
226
|
+
description: "Maximum findings to list (default 50, max 500). Totals by severity and rule are always returned.",
|
|
180
227
|
},
|
|
181
228
|
workspaceId: WORKSPACE_ID_PROPERTY,
|
|
182
229
|
},
|
|
183
|
-
required: [
|
|
230
|
+
required: [],
|
|
184
231
|
},
|
|
185
232
|
},
|
|
186
233
|
{
|
|
187
|
-
name: "
|
|
234
|
+
name: "investigate",
|
|
188
235
|
description:
|
|
189
|
-
"
|
|
190
|
-
"line
|
|
191
|
-
"
|
|
192
|
-
"
|
|
236
|
+
"Answers a code question with a token-budgeted Markdown brief: the best-matching methods/types as " +
|
|
237
|
+
"edit-ready code slices (every line prefixed L<n>:), each given a short handle (@s1, @s2, ...), plus the " +
|
|
238
|
+
"execution traces (@t<N>) they take part in. Ranked by Harmony's search. Code this session already " +
|
|
239
|
+
"received comes back as a one-line [In context: path:Lx-Ly] reference instead of being resent — that code " +
|
|
240
|
+
"is still in your context above; if it isn't (context was cleared or compacted, or you are a subagent), " +
|
|
241
|
+
"call again with force_refresh: true. Use it like context_search when you want the answer as slices " +
|
|
242
|
+
"with handles you can refer back to in later calls.",
|
|
193
243
|
inputSchema: {
|
|
194
244
|
type: "object",
|
|
195
245
|
properties: {
|
|
196
|
-
|
|
246
|
+
query: { type: "string", description: "REQUIRED. The question or identifier to investigate." },
|
|
247
|
+
focus_files: {
|
|
248
|
+
type: "array",
|
|
249
|
+
items: { type: "string" },
|
|
250
|
+
description: "Optional relative file paths to rank first (files already known to be relevant).",
|
|
251
|
+
},
|
|
252
|
+
max_slices: { type: "number", description: "Maximum code slices (default 4, max 10)." },
|
|
253
|
+
max_tokens: { type: "number", description: "Token budget for the brief (default 2200)." },
|
|
254
|
+
force_refresh: FORCE_REFRESH_PROPERTY,
|
|
255
|
+
workspaceId: WORKSPACE_ID_PROPERTY,
|
|
256
|
+
},
|
|
257
|
+
required: ["query"],
|
|
258
|
+
},
|
|
259
|
+
},
|
|
260
|
+
{
|
|
261
|
+
name: "inspect_trace",
|
|
262
|
+
description:
|
|
263
|
+
"Shows one execution flow end to end — entry route, call chain, security posture (authenticated or " +
|
|
264
|
+
"not, roles) — with the code of each hop as an edit-ready slice. Use it for 'what happens when X is " +
|
|
265
|
+
"called' / 'trace the request for <route>' questions. Pass a route (e.g. 'POST /loans'), an entry " +
|
|
266
|
+
"method, or a trace handle like @t3 from an earlier investigate result.",
|
|
267
|
+
inputSchema: {
|
|
268
|
+
type: "object",
|
|
269
|
+
properties: {
|
|
270
|
+
trace_query: {
|
|
271
|
+
type: "string",
|
|
272
|
+
description: "REQUIRED. A route, entry-point name, keywords, or an @t<N> handle from this session.",
|
|
273
|
+
},
|
|
274
|
+
max_tokens: { type: "number", description: "Token budget (default 2400)." },
|
|
275
|
+
force_refresh: FORCE_REFRESH_PROPERTY,
|
|
276
|
+
workspaceId: WORKSPACE_ID_PROPERTY,
|
|
277
|
+
},
|
|
278
|
+
required: ["trace_query"],
|
|
279
|
+
},
|
|
280
|
+
},
|
|
281
|
+
{
|
|
282
|
+
name: "security_audit",
|
|
283
|
+
description:
|
|
284
|
+
"Security posture of the workspace as a compact Markdown report: findings grouped by root cause " +
|
|
285
|
+
"(rule + OWASP/CWE), each group a handle @g<N> and its first findings @f<N>, most severe first. " +
|
|
286
|
+
"Covers the same checks as security_scan plus findings from execution-flow analysis. With " +
|
|
287
|
+
"delta_only: true it reports only what changed since this session's previous audit — use that " +
|
|
288
|
+
"after fixing to confirm. Expand or mute a group with security_finding_action.",
|
|
289
|
+
inputSchema: {
|
|
290
|
+
type: "object",
|
|
291
|
+
properties: {
|
|
292
|
+
severity_filter: {
|
|
197
293
|
type: "string",
|
|
198
|
-
|
|
294
|
+
enum: ["CRITICAL", "HIGH", "MEDIUM", "LOW", "INFO"],
|
|
295
|
+
description: "Optional lowest severity to include.",
|
|
199
296
|
},
|
|
200
|
-
|
|
297
|
+
delta_only: {
|
|
201
298
|
type: "boolean",
|
|
202
|
-
description:
|
|
203
|
-
"Whether to include symbols that look private/unexported. Default false (exported-only) " +
|
|
204
|
-
"to preserve token economy.",
|
|
299
|
+
description: "Report only findings new or resolved since this session's last audit (default false).",
|
|
205
300
|
},
|
|
301
|
+
max_tokens: { type: "number", description: "Token budget (default 2000)." },
|
|
206
302
|
workspaceId: WORKSPACE_ID_PROPERTY,
|
|
207
303
|
},
|
|
208
|
-
required: [
|
|
304
|
+
required: [],
|
|
209
305
|
},
|
|
210
306
|
},
|
|
211
307
|
{
|
|
212
|
-
name: "
|
|
308
|
+
name: "security_finding_action",
|
|
213
309
|
description:
|
|
214
|
-
"
|
|
215
|
-
"
|
|
216
|
-
"
|
|
217
|
-
"understand project layout and find relevant modules, INSTEAD of manual directory traversals " +
|
|
218
|
-
"or a string of unscoped context_search calls.",
|
|
310
|
+
"Acts on a finding handle from security_audit: 'inspect' expands a group (@g<N>) or finding (@f<N>) " +
|
|
311
|
+
"into every member with file:line and remediation; 'mute' suppresses it for later audits (give a " +
|
|
312
|
+
"reason). Only mute what the user agreed is a false positive or accepted risk.",
|
|
219
313
|
inputSchema: {
|
|
220
314
|
type: "object",
|
|
221
315
|
properties: {
|
|
222
|
-
|
|
316
|
+
handle: { type: "string", description: "REQUIRED. A handle from security_audit, e.g. @g1 or @f3." },
|
|
317
|
+
action: { type: "string", enum: ["inspect", "mute"], description: "Default inspect." },
|
|
318
|
+
reason: { type: "string", description: "Why the finding is muted (required in practice for mute)." },
|
|
319
|
+
workspaceId: WORKSPACE_ID_PROPERTY,
|
|
320
|
+
},
|
|
321
|
+
required: ["handle"],
|
|
322
|
+
},
|
|
323
|
+
},
|
|
324
|
+
{
|
|
325
|
+
name: "preflight",
|
|
326
|
+
description:
|
|
327
|
+
"Before editing, shows the blast radius of changing given files or symbols: dependent production " +
|
|
328
|
+
"files, impacted tests, entry-point traces that pass through them, and security findings they touch, " +
|
|
329
|
+
"plus slices of the target code. Use it before changing a shared class, a public method signature, or " +
|
|
330
|
+
"anything security-sensitive, instead of grepping for usages.",
|
|
331
|
+
inputSchema: {
|
|
332
|
+
type: "object",
|
|
333
|
+
properties: {
|
|
334
|
+
target_files: {
|
|
223
335
|
type: "array",
|
|
224
336
|
items: { type: "string" },
|
|
225
|
-
description:
|
|
226
|
-
"Optional list of relative file paths to prioritize (e.g. files currently open or " +
|
|
227
|
-
"mentioned in the user's prompt) — ranked ahead of everything else.",
|
|
337
|
+
description: "Relative paths of the files you intend to change.",
|
|
228
338
|
},
|
|
229
|
-
|
|
230
|
-
type: "
|
|
231
|
-
|
|
339
|
+
target_symbols: {
|
|
340
|
+
type: "array",
|
|
341
|
+
items: { type: "string" },
|
|
342
|
+
description: "Optional symbol names you intend to change (class or method names).",
|
|
232
343
|
},
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
344
|
+
include_slices: { type: "boolean", description: "Include code slices of the targets (default true)." },
|
|
345
|
+
max_tokens: { type: "number", description: "Token budget (default 1800)." },
|
|
346
|
+
workspaceId: WORKSPACE_ID_PROPERTY,
|
|
347
|
+
},
|
|
348
|
+
required: [],
|
|
349
|
+
},
|
|
350
|
+
},
|
|
351
|
+
{
|
|
352
|
+
name: "compress_build_log",
|
|
353
|
+
description:
|
|
354
|
+
"Turns raw build or test output into a short diagnosis: unique compiler errors, failed tests grouped " +
|
|
355
|
+
"by cause, and deduplicated stack traces (noise, ANSI codes and repeated frames removed). Pass the log " +
|
|
356
|
+
"text instead of reading a long build log into context.",
|
|
357
|
+
inputSchema: {
|
|
358
|
+
type: "object",
|
|
359
|
+
properties: {
|
|
360
|
+
raw_log: { type: "string", description: "REQUIRED. The raw stdout/stderr of the build or test run." },
|
|
361
|
+
command: { type: "string", description: "Optional command that produced it, e.g. './gradlew test'." },
|
|
362
|
+
max_tokens: { type: "number", description: "Token budget (default 1200)." },
|
|
363
|
+
workspaceId: WORKSPACE_ID_PROPERTY,
|
|
364
|
+
},
|
|
365
|
+
required: ["raw_log"],
|
|
366
|
+
},
|
|
367
|
+
},
|
|
368
|
+
{
|
|
369
|
+
name: "session_checkpoint",
|
|
370
|
+
description:
|
|
371
|
+
"Returns a compact (about 500 tokens) snapshot of this Harmony session: current goal, recorded " +
|
|
372
|
+
"invariants, files targeted, and the active @s/@t/@g handles. Call it before the conversation is " +
|
|
373
|
+
"cleared or compacted and keep the result, so work can resume with the same handles.",
|
|
374
|
+
inputSchema: {
|
|
375
|
+
type: "object",
|
|
376
|
+
properties: {
|
|
377
|
+
current_goal: { type: "string", description: "One line on what you are working on." },
|
|
378
|
+
notes: {
|
|
379
|
+
type: "array",
|
|
380
|
+
items: { type: "string" },
|
|
381
|
+
description: "Invariants or decisions to carry over (e.g. 'keep LoanApi response shape stable').",
|
|
236
382
|
},
|
|
383
|
+
max_tokens: { type: "number", description: "Token budget (default 500)." },
|
|
237
384
|
workspaceId: WORKSPACE_ID_PROPERTY,
|
|
238
385
|
},
|
|
239
386
|
required: [],
|