@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
package/README.md
CHANGED
|
@@ -27,14 +27,19 @@ Re-run `node -v` afterwards to confirm before continuing.
|
|
|
27
27
|
|
|
28
28
|
## Installation
|
|
29
29
|
|
|
30
|
-
The server is published as `@codeconductorai/harmony-mcp` and run via `npx`, so no local build step is required. The commands below pin an exact version (`@1.0.
|
|
30
|
+
The server is published as `@codeconductorai/harmony-mcp` and run via `npx`, so no local build step is required. The commands below pin an exact version (`@1.0.32`) rather than a floating tag — this lets `npx` reuse its local cache instead of re-resolving the package from the registry on every agent startup, which otherwise makes MCP initialization noticeably slower (and occasionally hang). Bump the pinned version deliberately when you want to upgrade.
|
|
31
31
|
|
|
32
32
|
### Claude Code
|
|
33
33
|
|
|
34
34
|
```bash
|
|
35
|
-
|
|
35
|
+
npx -y @codeconductorai/harmony-mcp@1.0.32 install claude
|
|
36
36
|
```
|
|
37
37
|
|
|
38
|
+
This registers the server for all your projects (`claude mcp add harmony --scope user ...`) and adds the session
|
|
39
|
+
hook from [Session id](#session-id) to `~/.claude/settings.json`. Claude Code reads Harmony's guidance (when to use
|
|
40
|
+
which tool, and to treat returned code as already read) from the server's instructions, so nothing is added to your
|
|
41
|
+
project. To register only the server: `claude mcp add harmony -- npx -y @codeconductorai/harmony-mcp@1.0.32`.
|
|
42
|
+
|
|
38
43
|
### Antigravity
|
|
39
44
|
|
|
40
45
|
Open **MCP Servers → Manage MCP Servers → View raw config** from the agent panel, or edit the config file directly:
|
|
@@ -47,7 +52,7 @@ Open **MCP Servers → Manage MCP Servers → View raw config** from the agent p
|
|
|
47
52
|
"mcpServers": {
|
|
48
53
|
"harmony": {
|
|
49
54
|
"command": "npx",
|
|
50
|
-
"args": ["-y", "@codeconductorai/harmony-mcp@1.0.
|
|
55
|
+
"args": ["-y", "@codeconductorai/harmony-mcp@1.0.32"]
|
|
51
56
|
}
|
|
52
57
|
}
|
|
53
58
|
}
|
|
@@ -57,18 +62,52 @@ Restart Antigravity (or reload MCP servers) after saving.
|
|
|
57
62
|
|
|
58
63
|
### Codex CLI
|
|
59
64
|
|
|
65
|
+
Run this in your project:
|
|
66
|
+
|
|
60
67
|
```bash
|
|
61
|
-
|
|
68
|
+
npx -y @codeconductorai/harmony-mcp@1.0.32 install codex
|
|
62
69
|
```
|
|
63
70
|
|
|
64
|
-
|
|
71
|
+
It does the three things Codex needs to actually use Harmony, and is safe to run again:
|
|
72
|
+
|
|
73
|
+
1. Adds `[mcp_servers.harmony]` to `~/.codex/config.toml` with Harmony's tools pre-approved (an existing entry is
|
|
74
|
+
kept; only the missing approval setting is added).
|
|
75
|
+
2. Adds the session hook from [Session id](#session-id) to `~/.codex/hooks.json`.
|
|
76
|
+
3. After asking you, adds Harmony's guidance to the project's `AGENTS.md` between `<!-- harmony-mcp:start -->` and
|
|
77
|
+
`<!-- harmony-mcp:end -->` markers (later runs update that block in place). Codex only follows Harmony's routing
|
|
78
|
+
rules from `AGENTS.md`; without them it ignored Harmony in our tests.
|
|
79
|
+
|
|
80
|
+
Each file is backed up once (`*.harmony-bak`) before its first change. Options: `--yes` (no prompt), `--no-agents-md`,
|
|
81
|
+
`--project <dir>`, `--env API_URL=...`, `--dry-run`. If you skip it, `setup_workspace` reminds Codex to offer it.
|
|
82
|
+
|
|
83
|
+
To set it up by hand instead, `codex mcp add harmony -- npx -y @codeconductorai/harmony-mcp@1.0.32` writes the entry
|
|
84
|
+
to `~/.codex/config.toml`, or add:
|
|
65
85
|
|
|
66
86
|
```toml
|
|
67
87
|
[mcp_servers.harmony]
|
|
68
88
|
command = "npx"
|
|
69
|
-
args = ["-y", "@codeconductorai/harmony-mcp@1.0.
|
|
89
|
+
args = ["-y", "@codeconductorai/harmony-mcp@1.0.32"]
|
|
90
|
+
# Harmony's query tools only read the index; pre-approving them avoids an approval prompt (or, with
|
|
91
|
+
# --approve-for-me, an automatic reviewer that costs extra model requests and can reject the calls).
|
|
92
|
+
default_tools_approval_mode = "approve"
|
|
70
93
|
```
|
|
71
94
|
|
|
95
|
+
Harmony detects Codex and sends it short server instructions: Codex copies server instructions into every tool
|
|
96
|
+
description it looks up, so the full text would be re-read on every step. The routing rules come from `AGENTS.md`
|
|
97
|
+
instead (step 2 below).
|
|
98
|
+
|
|
99
|
+
The installer's other two steps, by hand:
|
|
100
|
+
|
|
101
|
+
1. **Session tracking.** Add the `SessionStart` hook from [Session id](#session-id) to `~/.codex/hooks.json`. The
|
|
102
|
+
server sends `X-Mcp-Session-Id` to the backend itself, and Codex config can only set static headers, so the hook
|
|
103
|
+
is what makes the id follow each Codex session through `/clear` and compaction.
|
|
104
|
+
2. **Tool guidance.** Codex follows `AGENTS.md`, so append Harmony's "when to use which tool, and when `rg` is
|
|
105
|
+
better" section to the project's `AGENTS.md`:
|
|
106
|
+
|
|
107
|
+
```bash
|
|
108
|
+
npx -y @codeconductorai/harmony-mcp@1.0.32 --print-agents-md >> AGENTS.md
|
|
109
|
+
```
|
|
110
|
+
|
|
72
111
|
### Aria
|
|
73
112
|
|
|
74
113
|
In the Aria Code panel, click the settings icon → **MCP Servers**, then scroll down and click **Edit Global MCP** (applies everywhere, via `mcp_settings.json`) or **Edit Project MCP** (this project only, writes `.Aria/mcp.json`). Add:
|
|
@@ -78,7 +117,7 @@ In the Aria Code panel, click the settings icon → **MCP Servers**, then scroll
|
|
|
78
117
|
"mcpServers": {
|
|
79
118
|
"harmony": {
|
|
80
119
|
"command": "npx",
|
|
81
|
-
"args": ["-y", "@codeconductorai/harmony-mcp@1.0.
|
|
120
|
+
"args": ["-y", "@codeconductorai/harmony-mcp@1.0.32"]
|
|
82
121
|
}
|
|
83
122
|
}
|
|
84
123
|
}
|
|
@@ -95,7 +134,7 @@ Any client that reads a `command`/`args` style config (e.g. Claude Desktop's `cl
|
|
|
95
134
|
"mcpServers": {
|
|
96
135
|
"harmony": {
|
|
97
136
|
"command": "npx",
|
|
98
|
-
"args": ["-y", "@codeconductorai/harmony-mcp@1.0.
|
|
137
|
+
"args": ["-y", "@codeconductorai/harmony-mcp@1.0.32"]
|
|
99
138
|
}
|
|
100
139
|
}
|
|
101
140
|
}
|
|
@@ -171,3 +210,48 @@ Telemetry is exported to the harmony backend's `/api/v1/otel/{traces,metrics,log
|
|
|
171
210
|
npm install
|
|
172
211
|
npm start
|
|
173
212
|
```
|
|
213
|
+
|
|
214
|
+
## Session id
|
|
215
|
+
|
|
216
|
+
Every request carries an `X-Mcp-Session-Id` header. Harmony keeps per-session state under it: handles such as
|
|
217
|
+
`@s1`/`@g1`, security-audit baselines, and the code slices already sent, which it later returns as short
|
|
218
|
+
`[In context: ...]` references instead of resending them.
|
|
219
|
+
|
|
220
|
+
The id is chosen per request, first match wins:
|
|
221
|
+
|
|
222
|
+
1. `HARMONY_SESSION_ID` environment variable, an explicit override for any agent.
|
|
223
|
+
2. The session recorded by the optional Claude Code / Codex hook below. It follows `/clear` (new id) and compaction
|
|
224
|
+
(`<id>#compact-N`), so Harmony never refers back to code that left the agent's context.
|
|
225
|
+
3. `CLAUDE_CODE_SESSION_ID`, Claude Code's session id when it started this server.
|
|
226
|
+
4. A UUID generated for this server process, for agents that don't expose a session id.
|
|
227
|
+
|
|
228
|
+
To follow `/clear` and compaction in Claude Code, add this `SessionStart` hook to `~/.claude/settings.json`:
|
|
229
|
+
|
|
230
|
+
```json
|
|
231
|
+
{
|
|
232
|
+
"hooks": {
|
|
233
|
+
"SessionStart": [
|
|
234
|
+
{ "hooks": [{ "type": "command", "command": "npx -y @codeconductorai/harmony-mcp --session-hook" }] }
|
|
235
|
+
]
|
|
236
|
+
}
|
|
237
|
+
}
|
|
238
|
+
```
|
|
239
|
+
|
|
240
|
+
For OpenAI Codex CLI, add the same hook to `~/.codex/hooks.json` (Codex asks you to review new hooks once before
|
|
241
|
+
they run):
|
|
242
|
+
|
|
243
|
+
```json
|
|
244
|
+
{
|
|
245
|
+
"hooks": {
|
|
246
|
+
"SessionStart": [
|
|
247
|
+
{ "hooks": [{ "type": "command", "command": "npx -y @codeconductorai/harmony-mcp --session-hook" }] }
|
|
248
|
+
]
|
|
249
|
+
}
|
|
250
|
+
}
|
|
251
|
+
```
|
|
252
|
+
|
|
253
|
+
Codex exposes no session id to MCP servers, so without this hook every Codex session falls back to a per-process id
|
|
254
|
+
that survives `/clear` and compaction.
|
|
255
|
+
|
|
256
|
+
Without the hook, after `/clear` the agent can ask for full code again with `force_refresh: true`.
|
|
257
|
+
|
package/package.json
CHANGED
|
@@ -0,0 +1,38 @@
|
|
|
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
|
+
export const AGENTS_MD_GUIDE = `
|
|
9
|
+
## Code search: Harmony MCP first, then stop
|
|
10
|
+
|
|
11
|
+
This repo is indexed by the \`harmony\` MCP server. Its answers already contain the relevant code with file paths
|
|
12
|
+
and line numbers. Every extra step re-reads the whole conversation, so the goal is the right answer in the fewest
|
|
13
|
+
steps: aim for 4 or fewer tool calls.
|
|
14
|
+
|
|
15
|
+
1. **Start with ONE Harmony call, chosen by the question:**
|
|
16
|
+
| Question | First call |
|
|
17
|
+
|---|---|
|
|
18
|
+
| How does X work / where is X handled / what happens when ... | \`investigate\` with the question in plain words |
|
|
19
|
+
| What happens on an HTTP route | \`inspect_trace\` with the route exactly as \`VERB /path\` |
|
|
20
|
+
| Where is a named class/method defined or used | \`locate\` with the exact name |
|
|
21
|
+
| Which files/modules are involved in a concept | \`context_search\` |
|
|
22
|
+
| What breaks if I change this file/symbol | \`preflight\` |
|
|
23
|
+
\`inspect_trace\` only matches HTTP routes or \`@t\` handles from earlier results; never pass it a class or
|
|
24
|
+
method name.
|
|
25
|
+
2. **Treat code Harmony returned as already read.** Do not open the same file or line range again with
|
|
26
|
+
\`sed\`, \`cat\`, \`nl\` or \`rg\`.
|
|
27
|
+
3. **Fill a gap in ONE step.** If something is still missing, either make one more Harmony call using the exact
|
|
28
|
+
class/method names you saw, or run ONE shell command that prints every range you need at once, e.g.
|
|
29
|
+
\`sed -n '120,180p' A.java; sed -n '40,90p' B.java\`. Never print whole files; never one command per file.
|
|
30
|
+
4. **Use \`rg\` directly, not Harmony,** for exact strings, config and properties files, templates
|
|
31
|
+
(\`.jte\`, \`.html\`) and file names.
|
|
32
|
+
5. **Stop when the evidence covers the question** and answer, citing \`path:line\` from the results.
|
|
33
|
+
6. \`[In context: path:Lx-Ly — unchanged]\` means that code was sent earlier in this session; call again with
|
|
34
|
+
\`force_refresh: true\` only if it is no longer in your context.
|
|
35
|
+
7. Other tools: \`security_audit\` (\`delta_only: true\` after a fix) and \`security_finding_action\` for security
|
|
36
|
+
findings; \`compress_build_log\` instead of reading a long build or test log. If a tool says the workspace is not
|
|
37
|
+
set up, call \`setup_workspace\` once, then retry.
|
|
38
|
+
`.trim();
|
package/src/fileWatcher.js
CHANGED
|
@@ -26,6 +26,16 @@ let onFileChange = null;
|
|
|
26
26
|
// Sync calls run one at a time, in event order: a rename's delete lands before the new path's add,
|
|
27
27
|
// and the backend never sees overlapping passes for this workspace.
|
|
28
28
|
let syncQueue = Promise.resolve();
|
|
29
|
+
// filePath -> debounce timer for changes seen but not yet queued for sync.
|
|
30
|
+
const debounceMap = new Map();
|
|
31
|
+
// Queues one path's sync; set by startFileWatcher (needs the marker's workspace/language/buildTool).
|
|
32
|
+
let enqueueSync = null;
|
|
33
|
+
// Syncs queued or in flight. A query issued meanwhile would read the pre-edit index, and since the slice
|
|
34
|
+
// hash still matches what the session was sent, the backend would answer "[In context: …] — unchanged".
|
|
35
|
+
let inFlightSyncs = 0;
|
|
36
|
+
let unreportedStaleWait = null;
|
|
37
|
+
|
|
38
|
+
const SYNC_WAIT_MS = Number(process.env.HARMONY_SYNC_WAIT_MS) || 15_000;
|
|
29
39
|
|
|
30
40
|
// Close every active watcher handle, called on process shutdown.
|
|
31
41
|
export function stopFileWatcher() {
|
|
@@ -39,7 +49,34 @@ export function stopFileWatcher() {
|
|
|
39
49
|
watchedDirs.clear();
|
|
40
50
|
unwatchedDirs.clear();
|
|
41
51
|
knownFiles.clear();
|
|
52
|
+
for (const timer of debounceMap.values()) clearTimeout(timer);
|
|
53
|
+
debounceMap.clear();
|
|
42
54
|
onFileChange = null;
|
|
55
|
+
enqueueSync = null;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
export async function waitForPendingSync(timeoutMs = SYNC_WAIT_MS) {
|
|
59
|
+
if (enqueueSync) {
|
|
60
|
+
for (const [filePath, timer] of debounceMap) {
|
|
61
|
+
clearTimeout(timer);
|
|
62
|
+
debounceMap.delete(filePath);
|
|
63
|
+
enqueueSync(filePath);
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
if (inFlightSyncs === 0) return true;
|
|
67
|
+
|
|
68
|
+
const pending = inFlightSyncs;
|
|
69
|
+
const startedAt = Date.now();
|
|
70
|
+
let timer;
|
|
71
|
+
const finished = await Promise.race([
|
|
72
|
+
syncQueue.then(() => true),
|
|
73
|
+
new Promise((resolve) => { timer = setTimeout(() => resolve(false), timeoutMs); }),
|
|
74
|
+
]);
|
|
75
|
+
clearTimeout(timer);
|
|
76
|
+
log(`[fileWatcher] Waited ${Date.now() - startedAt}ms for ${pending} pending sync(s)` +
|
|
77
|
+
(finished ? "" : ` — timed out, ${inFlightSyncs} still running`) + ".");
|
|
78
|
+
if (!finished) unreportedStaleWait = inFlightSyncs;
|
|
79
|
+
return finished;
|
|
43
80
|
}
|
|
44
81
|
|
|
45
82
|
function relative(filePath) {
|
|
@@ -192,7 +229,14 @@ export function startFileWatcher() {
|
|
|
192
229
|
return;
|
|
193
230
|
}
|
|
194
231
|
const { workspaceId, language, buildTool } = marker;
|
|
195
|
-
|
|
232
|
+
|
|
233
|
+
enqueueSync = (filePath) => {
|
|
234
|
+
inFlightSyncs++;
|
|
235
|
+
syncQueue = syncQueue
|
|
236
|
+
.then(() => syncPath(filePath, workspaceId, language, buildTool))
|
|
237
|
+
.catch((error) => log(`[fileWatcher] Sync of ${relative(filePath)} failed: ${error.message}`))
|
|
238
|
+
.finally(() => { inFlightSyncs--; });
|
|
239
|
+
};
|
|
196
240
|
|
|
197
241
|
onFileChange = (filePath) => {
|
|
198
242
|
if (debounceMap.has(filePath)) clearTimeout(debounceMap.get(filePath));
|
|
@@ -200,9 +244,7 @@ export function startFileWatcher() {
|
|
|
200
244
|
filePath,
|
|
201
245
|
setTimeout(() => {
|
|
202
246
|
debounceMap.delete(filePath);
|
|
203
|
-
|
|
204
|
-
.then(() => syncPath(filePath, workspaceId, language, buildTool))
|
|
205
|
-
.catch((error) => log(`[fileWatcher] Sync of ${relative(filePath)} failed: ${error.message}`));
|
|
247
|
+
enqueueSync?.(filePath);
|
|
206
248
|
}, DEBOUNCE_MS)
|
|
207
249
|
);
|
|
208
250
|
};
|
|
@@ -244,6 +286,11 @@ function describeUnwatched() {
|
|
|
244
286
|
// or null when there is nothing new to report. Keeps search responses unchanged in the normal case.
|
|
245
287
|
export function takeSyncWarning() {
|
|
246
288
|
const parts = [];
|
|
289
|
+
if (unreportedStaleWait) {
|
|
290
|
+
parts.push(`${unreportedStaleWait} recent local change(s) were still being indexed when this answer was built; ` +
|
|
291
|
+
`code from those files may predate your edits — verify with Read, or retry with force_refresh: true.`);
|
|
292
|
+
unreportedStaleWait = null;
|
|
293
|
+
}
|
|
247
294
|
if (unreportedFailures > 0) {
|
|
248
295
|
const recent = syncFailures.slice(-Math.min(unreportedFailures, 3))
|
|
249
296
|
.map((f) => `${f.action} ${f.path} (${f.status})`)
|
package/src/harmonyClient.js
CHANGED
|
@@ -5,6 +5,7 @@ import archiver from "archiver";
|
|
|
5
5
|
import FormData from "form-data";
|
|
6
6
|
|
|
7
7
|
import { log } from "./log.js";
|
|
8
|
+
import { currentSessionId } from "./sessionIdentity.js";
|
|
8
9
|
import { tracedFetch as fetch, getActiveTraceId } from "./telemetry.js";
|
|
9
10
|
import {
|
|
10
11
|
getSessionToken,
|
|
@@ -20,6 +21,10 @@ import { buildZipIgnoreGlobs } from "./fileFilters.js";
|
|
|
20
21
|
|
|
21
22
|
export const API_URL = (process.env.API_URL || "https://harmony.codeconductor.ai/").replace(/\/+$/, "");
|
|
22
23
|
|
|
24
|
+
function sessionHeader() {
|
|
25
|
+
return { "X-Mcp-Session-Id": currentSessionId() };
|
|
26
|
+
}
|
|
27
|
+
|
|
23
28
|
async function refreshWorkspaceToken(workspaceId, refreshToken) {
|
|
24
29
|
const response = await fetch(`${API_URL}/api/code-workspace/${workspaceId}/refresh-token`, {
|
|
25
30
|
method: "POST",
|
|
@@ -124,7 +129,27 @@ export async function setupWorkspace(workspaceId, language, buildTool) {
|
|
|
124
129
|
}
|
|
125
130
|
|
|
126
131
|
// POST /api/v1/index/zip — upload a zipped snapshot of the workspace for full indexing.
|
|
127
|
-
|
|
132
|
+
// Thrown when the backend rejects an upload because it contains hardcoded secrets (HTTP 422
|
|
133
|
+
// SECRETS_DETECTED). `details` is the backend's response body: masked findings + how to proceed.
|
|
134
|
+
export class SecretsDetectedError extends Error {
|
|
135
|
+
constructor(details) {
|
|
136
|
+
super(details?.message || "Upload blocked: potential hardcoded secrets detected.");
|
|
137
|
+
this.name = "SecretsDetectedError";
|
|
138
|
+
this.details = details;
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
function parseSecretsDetected(status, body) {
|
|
143
|
+
if (status !== 422) return null;
|
|
144
|
+
try {
|
|
145
|
+
const parsed = JSON.parse(body);
|
|
146
|
+
return parsed?.error === "SECRETS_DETECTED" ? parsed : null;
|
|
147
|
+
} catch {
|
|
148
|
+
return null;
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
export async function uploadWorkspace(zipPath, workspaceId, language, buildTool, phase = "LEXICAL", allowSecrets = false) {
|
|
128
153
|
try {
|
|
129
154
|
const form = new FormData();
|
|
130
155
|
|
|
@@ -138,6 +163,8 @@ export async function uploadWorkspace(zipPath, workspaceId, language, buildTool,
|
|
|
138
163
|
form.append("language", language);
|
|
139
164
|
if (buildTool) form.append("buildTool", buildTool);
|
|
140
165
|
form.append("phase", phase);
|
|
166
|
+
// Only ever true after the user agreed to index despite detected secrets.
|
|
167
|
+
if (allowSecrets) form.append("allowSecrets", "true");
|
|
141
168
|
|
|
142
169
|
// Field name must be "file" per @RequestPart("file")
|
|
143
170
|
form.append("file", fs.createReadStream(zipPath), { filename: "workspace.zip", contentType: "application/zip" });
|
|
@@ -153,6 +180,10 @@ export async function uploadWorkspace(zipPath, workspaceId, language, buildTool,
|
|
|
153
180
|
const body = await response.text();
|
|
154
181
|
log("Upload status:", response.status);
|
|
155
182
|
log("Upload response:", body);
|
|
183
|
+
const secretsDetected = parseSecretsDetected(response.status, body);
|
|
184
|
+
if (secretsDetected) {
|
|
185
|
+
throw new SecretsDetectedError(secretsDetected);
|
|
186
|
+
}
|
|
156
187
|
if (!response.ok) {
|
|
157
188
|
throw new Error(`Upload failed: ${response.status} ${body}${traceSuffix()}`);
|
|
158
189
|
}
|
|
@@ -162,6 +193,7 @@ export async function uploadWorkspace(zipPath, workspaceId, language, buildTool,
|
|
|
162
193
|
response: body,
|
|
163
194
|
};
|
|
164
195
|
} catch (error) {
|
|
196
|
+
if (error instanceof SecretsDetectedError) throw error;
|
|
165
197
|
log("Upload Error:", error);
|
|
166
198
|
let msg = error?.message || "Unknown upload error";
|
|
167
199
|
if (error.code) msg += `\nError code: ${error.code}`;
|
|
@@ -170,7 +202,7 @@ export async function uploadWorkspace(zipPath, workspaceId, language, buildTool,
|
|
|
170
202
|
}
|
|
171
203
|
|
|
172
204
|
// Ensure the workspace is set up and uploaded, re-uploading if the local commit has moved on since the last upload.
|
|
173
|
-
export async function ensureWorkspaceUploaded(language, buildTool) {
|
|
205
|
+
export async function ensureWorkspaceUploaded(language, buildTool, allowSecrets = false) {
|
|
174
206
|
let marker = readMarker();
|
|
175
207
|
let workspaceId;
|
|
176
208
|
|
|
@@ -215,7 +247,7 @@ export async function ensureWorkspaceUploaded(language, buildTool) {
|
|
|
215
247
|
// Indexing is lexical-only — no embedding/semantic pass on the backend.
|
|
216
248
|
const phase = "LEXICAL";
|
|
217
249
|
const zipFile = await zipWorkspace();
|
|
218
|
-
const result = await uploadWorkspace(zipFile, workspaceId, lang, tool, phase);
|
|
250
|
+
const result = await uploadWorkspace(zipFile, workspaceId, lang, tool, phase, allowSecrets);
|
|
219
251
|
marker.upload = { done: true, phase, status: result.status, response: result.response };
|
|
220
252
|
marker.commitHash = currentCommit;
|
|
221
253
|
writeMarker(marker);
|
|
@@ -297,6 +329,8 @@ export async function callHarmonySearchEndpoint(endpointPath, args, workspaceId)
|
|
|
297
329
|
include_code_snippets: args.include_code_snippets ?? (endpointPath === "context-search" ? true : undefined),
|
|
298
330
|
// context_search answers in the compact LLM format (llm-context-format-guide.md); locate keeps its own format
|
|
299
331
|
response_format: endpointPath === "context-search" ? "compact" : undefined,
|
|
332
|
+
// true = send all code in full even if this session already received it (cleared/compacted context, subagent)
|
|
333
|
+
force_refresh: args.force_refresh,
|
|
300
334
|
workspaceMetadata: buildWorkspaceMetadata(workspaceId),
|
|
301
335
|
};
|
|
302
336
|
|
|
@@ -307,6 +341,7 @@ export async function callHarmonySearchEndpoint(endpointPath, args, workspaceId)
|
|
|
307
341
|
headers: {
|
|
308
342
|
"Content-Type": "application/json",
|
|
309
343
|
Accept: "application/xml",
|
|
344
|
+
...sessionHeader(),
|
|
310
345
|
...(await authHeader(workspaceId)),
|
|
311
346
|
},
|
|
312
347
|
body: JSON.stringify(requestBody),
|
|
@@ -320,14 +355,15 @@ export async function callHarmonySearchEndpoint(endpointPath, args, workspaceId)
|
|
|
320
355
|
|
|
321
356
|
// Shared POST caller for the newer single-purpose endpoints (query-module-dependencies,
|
|
322
357
|
// outline-file-symbols, get-repository-map) — identical JSON-in/XML-out shape, different path/body.
|
|
323
|
-
async function callHarmonyJsonEndpoint(endpointPath, requestBody, workspaceId) {
|
|
358
|
+
async function callHarmonyJsonEndpoint(endpointPath, requestBody, workspaceId, accept = "application/xml") {
|
|
324
359
|
log(`[${endpointPath}] Request body:`, JSON.stringify(requestBody, null, 2));
|
|
325
360
|
|
|
326
361
|
const response = await fetch(`${API_URL}/api/code-workspace/${workspaceId}/${endpointPath}`, {
|
|
327
362
|
method: "POST",
|
|
328
363
|
headers: {
|
|
329
364
|
"Content-Type": "application/json",
|
|
330
|
-
Accept:
|
|
365
|
+
Accept: accept,
|
|
366
|
+
...sessionHeader(),
|
|
331
367
|
...(await authHeader(workspaceId)),
|
|
332
368
|
},
|
|
333
369
|
body: JSON.stringify(requestBody),
|
|
@@ -339,36 +375,95 @@ async function callHarmonyJsonEndpoint(endpointPath, requestBody, workspaceId) {
|
|
|
339
375
|
return body;
|
|
340
376
|
}
|
|
341
377
|
|
|
342
|
-
// POST /api/code-workspace/{workspaceId}/
|
|
343
|
-
//
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
return callHarmonyJsonEndpoint("
|
|
378
|
+
// POST /api/code-workspace/{workspaceId}/security-scan — on-demand scan of the workspace's uploaded
|
|
379
|
+
// code (secrets, Java security patterns, endpoint auth, data exposure, unused code). JSON in/out;
|
|
380
|
+
// findings already have secret values masked.
|
|
381
|
+
export async function callHarmonySecurityScan(args, workspaceId) {
|
|
382
|
+
return callHarmonyJsonEndpoint("security-scan", {
|
|
347
383
|
file_path: args.file_path,
|
|
348
|
-
|
|
384
|
+
checks: args.checks,
|
|
385
|
+
min_severity: args.min_severity,
|
|
386
|
+
limit: args.limit,
|
|
349
387
|
workspaceMetadata: buildWorkspaceMetadata(workspaceId),
|
|
350
|
-
}, workspaceId);
|
|
388
|
+
}, workspaceId, "application/json");
|
|
351
389
|
}
|
|
352
390
|
|
|
353
|
-
//
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
391
|
+
// ---- Session-aware Markdown endpoints (#101). Each returns text/markdown that goes to the agent as-is. ----
|
|
392
|
+
const MARKDOWN = "text/markdown";
|
|
393
|
+
|
|
394
|
+
// POST /api/code-workspace/{workspaceId}/investigate — ranked symbol slices for a question, as @s<N> handles.
|
|
395
|
+
export async function callHarmonyInvestigate(args, workspaceId) {
|
|
396
|
+
if (!args.query) throw new Error("query is required.");
|
|
397
|
+
return callHarmonyJsonEndpoint("investigate", {
|
|
398
|
+
query: args.query,
|
|
399
|
+
focusFiles: args.focus_files,
|
|
400
|
+
maxSlices: args.max_slices,
|
|
401
|
+
maxTokens: args.max_tokens,
|
|
402
|
+
forceRefresh: args.force_refresh,
|
|
403
|
+
}, workspaceId, MARKDOWN);
|
|
361
404
|
}
|
|
362
405
|
|
|
363
|
-
// POST /api/code-workspace/{workspaceId}/
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
406
|
+
// POST /api/code-workspace/{workspaceId}/traces/inspect — one execution flow with per-hop code slices.
|
|
407
|
+
export async function callHarmonyInspectTrace(args, workspaceId) {
|
|
408
|
+
// Agents often name the argument after what they pass (route, entry, query); accept those instead of failing a turn.
|
|
409
|
+
const traceQuery = args.trace_query || args.route || args.entry || args.entry_point || args.query;
|
|
410
|
+
if (!traceQuery) throw new Error("trace_query is required: an HTTP route like `POST /api/orders` or a @t handle.");
|
|
411
|
+
return callHarmonyJsonEndpoint("traces/inspect", {
|
|
412
|
+
traceQuery,
|
|
413
|
+
maxTokens: args.max_tokens,
|
|
414
|
+
forceRefresh: args.force_refresh,
|
|
415
|
+
}, workspaceId, MARKDOWN);
|
|
416
|
+
}
|
|
417
|
+
|
|
418
|
+
// POST /api/code-workspace/{workspaceId}/security/audit — findings clustered by root cause (@g<N>/@f<N>).
|
|
419
|
+
export async function callHarmonySecurityAudit(args, workspaceId) {
|
|
420
|
+
return callHarmonyJsonEndpoint("security/audit", {
|
|
421
|
+
severityFilter: args.severity_filter,
|
|
422
|
+
deltaOnly: args.delta_only,
|
|
423
|
+
maxTokens: args.max_tokens,
|
|
424
|
+
}, workspaceId, MARKDOWN);
|
|
425
|
+
}
|
|
426
|
+
|
|
427
|
+
// POST /api/code-workspace/{workspaceId}/security/findings/action — inspect or mute a finding handle.
|
|
428
|
+
export async function callHarmonySecurityFindingAction(args, workspaceId) {
|
|
429
|
+
if (!args.handle) throw new Error("handle is required.");
|
|
430
|
+
return callHarmonyJsonEndpoint("security/findings/action", {
|
|
431
|
+
handle: args.handle,
|
|
432
|
+
action: args.action,
|
|
433
|
+
reason: args.reason,
|
|
434
|
+
}, workspaceId, MARKDOWN);
|
|
435
|
+
}
|
|
436
|
+
|
|
437
|
+
// POST /api/code-workspace/{workspaceId}/preflight — blast radius of editing files/symbols.
|
|
438
|
+
export async function callHarmonyPreflight(args, workspaceId) {
|
|
439
|
+
if (!(args.target_files?.length || args.target_symbols?.length)) {
|
|
440
|
+
throw new Error("target_files or target_symbols is required.");
|
|
441
|
+
}
|
|
442
|
+
return callHarmonyJsonEndpoint("preflight", {
|
|
443
|
+
targetFiles: args.target_files,
|
|
444
|
+
targetSymbols: args.target_symbols,
|
|
445
|
+
includeSlices: args.include_slices,
|
|
446
|
+
maxTokens: args.max_tokens,
|
|
447
|
+
}, workspaceId, MARKDOWN);
|
|
448
|
+
}
|
|
449
|
+
|
|
450
|
+
// POST /api/code-workspace/{workspaceId}/build-log/compress — compiler errors and failure clusters of a log.
|
|
451
|
+
export async function callHarmonyCompressBuildLog(args, workspaceId) {
|
|
452
|
+
if (!args.raw_log) throw new Error("raw_log is required.");
|
|
453
|
+
return callHarmonyJsonEndpoint("build-log/compress", {
|
|
454
|
+
rawLog: args.raw_log,
|
|
455
|
+
command: args.command,
|
|
456
|
+
maxTokens: args.max_tokens,
|
|
457
|
+
}, workspaceId, MARKDOWN);
|
|
458
|
+
}
|
|
459
|
+
|
|
460
|
+
// POST /api/code-workspace/{workspaceId}/session/checkpoint — compact snapshot of this session's state.
|
|
461
|
+
export async function callHarmonySessionCheckpoint(args, workspaceId) {
|
|
462
|
+
return callHarmonyJsonEndpoint("session/checkpoint", {
|
|
463
|
+
currentGoal: args.current_goal,
|
|
464
|
+
additionalNotes: args.notes,
|
|
465
|
+
maxTokens: args.max_tokens,
|
|
466
|
+
}, workspaceId, MARKDOWN);
|
|
372
467
|
}
|
|
373
468
|
|
|
374
469
|
// POST /api/v1/index/files — used by the file watcher for incremental updates.
|
package/src/index.js
CHANGED
|
@@ -1,32 +1,13 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
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()}`);
|
|
27
|
-
|
|
28
|
-
try {
|
|
29
|
-
startFileWatcher();
|
|
30
|
-
} catch (err) {
|
|
31
|
-
log(`[workspace] Bootstrap skipped: ${err?.message || err}`);
|
|
2
|
+
if (process.argv[2] === "install") {
|
|
3
|
+
const { runInstall } = await import("./installer.js");
|
|
4
|
+
await runInstall(process.argv.slice(3));
|
|
5
|
+
} else if (process.argv.includes("--session-hook")) {
|
|
6
|
+
const { runSessionHook } = await import("./sessionIdentity.js");
|
|
7
|
+
await runSessionHook();
|
|
8
|
+
} else if (process.argv.includes("--print-agents-md")) {
|
|
9
|
+
const { AGENTS_MD_GUIDE } = await import("./agentsGuide.js");
|
|
10
|
+
process.stdout.write(`${AGENTS_MD_GUIDE}\n`);
|
|
11
|
+
} else {
|
|
12
|
+
await import("./serverMain.js");
|
|
32
13
|
}
|