@codeconductorai/harmony-mcp 1.0.31 → 1.0.33

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 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.31`) 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.
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.33`) 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
- claude mcp add harmony -- npx -y @codeconductorai/harmony-mcp@1.0.31
35
+ npx -y @codeconductorai/harmony-mcp@1.0.33 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.33`.
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.31"]
55
+ "args": ["-y", "@codeconductorai/harmony-mcp@1.0.33"]
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
- codex mcp add harmony -- npx -y @codeconductorai/harmony-mcp@1.0.31
68
+ npx -y @codeconductorai/harmony-mcp@1.0.33 install codex
62
69
  ```
63
70
 
64
- This writes the entry to `~/.codex/config.toml`. To add it by hand instead:
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.33` 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.31"]
89
+ args = ["-y", "@codeconductorai/harmony-mcp@1.0.33"]
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.33 --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.31"]
120
+ "args": ["-y", "@codeconductorai/harmony-mcp@1.0.33"]
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.31"]
137
+ "args": ["-y", "@codeconductorai/harmony-mcp@1.0.33"]
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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@codeconductorai/harmony-mcp",
3
- "version": "1.0.31",
3
+ "version": "1.0.33",
4
4
  "type": "module",
5
5
  "main": "src/index.js",
6
6
  "bin": {
@@ -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();
@@ -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
- const debounceMap = new Map();
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
- syncQueue = syncQueue
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})`)
@@ -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",
@@ -322,8 +327,11 @@ export async function callHarmonySearchEndpoint(endpointPath, args, workspaceId)
322
327
  limit: args.limit,
323
328
  // context_search returns code by default so the agent need not re-read the files; locate stays coordinates-only
324
329
  include_code_snippets: args.include_code_snippets ?? (endpointPath === "context-search" ? true : undefined),
325
- // context_search answers in the compact LLM format (llm-context-format-guide.md); locate keeps its own format
326
- response_format: endpointPath === "context-search" ? "compact" : undefined,
330
+ // Both endpoints answer in the compact LLM format: context_search per llm-context-format-guide.md, locate as one
331
+ // line per symbol grouped by file. Older backends ignore the flag for locate-symbol and keep the XML list.
332
+ response_format: "compact",
333
+ // true = send all code in full even if this session already received it (cleared/compacted context, subagent)
334
+ force_refresh: args.force_refresh,
327
335
  workspaceMetadata: buildWorkspaceMetadata(workspaceId),
328
336
  };
329
337
 
@@ -334,6 +342,7 @@ export async function callHarmonySearchEndpoint(endpointPath, args, workspaceId)
334
342
  headers: {
335
343
  "Content-Type": "application/json",
336
344
  Accept: "application/xml",
345
+ ...sessionHeader(),
337
346
  ...(await authHeader(workspaceId)),
338
347
  },
339
348
  body: JSON.stringify(requestBody),
@@ -355,6 +364,7 @@ async function callHarmonyJsonEndpoint(endpointPath, requestBody, workspaceId, a
355
364
  headers: {
356
365
  "Content-Type": "application/json",
357
366
  Accept: accept,
367
+ ...sessionHeader(),
358
368
  ...(await authHeader(workspaceId)),
359
369
  },
360
370
  body: JSON.stringify(requestBody),
@@ -366,38 +376,6 @@ async function callHarmonyJsonEndpoint(endpointPath, requestBody, workspaceId, a
366
376
  return body;
367
377
  }
368
378
 
369
- // POST /api/code-workspace/{workspaceId}/query-module-dependencies — a file's directed
370
- // import/inheritance dependencies.
371
- export async function callHarmonyModuleDependencies(args, workspaceId) {
372
- if (!args.file_path) throw new Error("file_path is required.");
373
- return callHarmonyJsonEndpoint("query-module-dependencies", {
374
- file_path: args.file_path,
375
- depth: args.depth,
376
- workspaceMetadata: buildWorkspaceMetadata(workspaceId),
377
- }, workspaceId);
378
- }
379
-
380
- // POST /api/code-workspace/{workspaceId}/outline-file-symbols — a file's structural skeleton.
381
- export async function callHarmonyFileOutline(args, workspaceId) {
382
- if (!args.file_path) throw new Error("file_path is required.");
383
- return callHarmonyJsonEndpoint("outline-file-symbols", {
384
- file_path: args.file_path,
385
- include_private: args.include_private,
386
- workspaceMetadata: buildWorkspaceMetadata(workspaceId),
387
- }, workspaceId);
388
- }
389
-
390
- // POST /api/code-workspace/{workspaceId}/get-repository-map — ranked, token-budgeted architectural
391
- // map of the workspace.
392
- export async function callHarmonyRepositoryMap(args, workspaceId) {
393
- return callHarmonyJsonEndpoint("get-repository-map", {
394
- focus_files: args.focus_files,
395
- max_tokens: args.max_tokens,
396
- directory_filter: args.directory_filter,
397
- workspaceMetadata: buildWorkspaceMetadata(workspaceId),
398
- }, workspaceId);
399
- }
400
-
401
379
  // POST /api/code-workspace/{workspaceId}/security-scan — on-demand scan of the workspace's uploaded
402
380
  // code (secrets, Java security patterns, endpoint auth, data exposure, unused code). JSON in/out;
403
381
  // findings already have secret values masked.
@@ -411,6 +389,84 @@ export async function callHarmonySecurityScan(args, workspaceId) {
411
389
  }, workspaceId, "application/json");
412
390
  }
413
391
 
392
+ // ---- Session-aware Markdown endpoints (#101). Each returns text/markdown that goes to the agent as-is. ----
393
+ const MARKDOWN = "text/markdown";
394
+
395
+ // POST /api/code-workspace/{workspaceId}/investigate — ranked symbol slices for a question, as @s<N> handles.
396
+ export async function callHarmonyInvestigate(args, workspaceId) {
397
+ if (!args.query) throw new Error("query is required.");
398
+ return callHarmonyJsonEndpoint("investigate", {
399
+ query: args.query,
400
+ focusFiles: args.focus_files,
401
+ maxSlices: args.max_slices,
402
+ maxTokens: args.max_tokens,
403
+ forceRefresh: args.force_refresh,
404
+ }, workspaceId, MARKDOWN);
405
+ }
406
+
407
+ // POST /api/code-workspace/{workspaceId}/traces/inspect — one execution flow with per-hop code slices.
408
+ export async function callHarmonyInspectTrace(args, workspaceId) {
409
+ // Agents often name the argument after what they pass (route, entry, query); accept those instead of failing a turn.
410
+ const traceQuery = args.trace_query || args.route || args.entry || args.entry_point || args.query;
411
+ if (!traceQuery) throw new Error("trace_query is required: an HTTP route like `POST /api/orders` or a @t handle.");
412
+ return callHarmonyJsonEndpoint("traces/inspect", {
413
+ traceQuery,
414
+ maxTokens: args.max_tokens,
415
+ forceRefresh: args.force_refresh,
416
+ }, workspaceId, MARKDOWN);
417
+ }
418
+
419
+ // POST /api/code-workspace/{workspaceId}/security/audit — findings clustered by root cause (@g<N>/@f<N>).
420
+ export async function callHarmonySecurityAudit(args, workspaceId) {
421
+ return callHarmonyJsonEndpoint("security/audit", {
422
+ severityFilter: args.severity_filter,
423
+ deltaOnly: args.delta_only,
424
+ maxTokens: args.max_tokens,
425
+ }, workspaceId, MARKDOWN);
426
+ }
427
+
428
+ // POST /api/code-workspace/{workspaceId}/security/findings/action — inspect or mute a finding handle.
429
+ export async function callHarmonySecurityFindingAction(args, workspaceId) {
430
+ if (!args.handle) throw new Error("handle is required.");
431
+ return callHarmonyJsonEndpoint("security/findings/action", {
432
+ handle: args.handle,
433
+ action: args.action,
434
+ reason: args.reason,
435
+ }, workspaceId, MARKDOWN);
436
+ }
437
+
438
+ // POST /api/code-workspace/{workspaceId}/preflight — blast radius of editing files/symbols.
439
+ export async function callHarmonyPreflight(args, workspaceId) {
440
+ if (!(args.target_files?.length || args.target_symbols?.length)) {
441
+ throw new Error("target_files or target_symbols is required.");
442
+ }
443
+ return callHarmonyJsonEndpoint("preflight", {
444
+ targetFiles: args.target_files,
445
+ targetSymbols: args.target_symbols,
446
+ includeSlices: args.include_slices,
447
+ maxTokens: args.max_tokens,
448
+ }, workspaceId, MARKDOWN);
449
+ }
450
+
451
+ // POST /api/code-workspace/{workspaceId}/build-log/compress — compiler errors and failure clusters of a log.
452
+ export async function callHarmonyCompressBuildLog(args, workspaceId) {
453
+ if (!args.raw_log) throw new Error("raw_log is required.");
454
+ return callHarmonyJsonEndpoint("build-log/compress", {
455
+ rawLog: args.raw_log,
456
+ command: args.command,
457
+ maxTokens: args.max_tokens,
458
+ }, workspaceId, MARKDOWN);
459
+ }
460
+
461
+ // POST /api/code-workspace/{workspaceId}/session/checkpoint — compact snapshot of this session's state.
462
+ export async function callHarmonySessionCheckpoint(args, workspaceId) {
463
+ return callHarmonyJsonEndpoint("session/checkpoint", {
464
+ currentGoal: args.current_goal,
465
+ additionalNotes: args.notes,
466
+ maxTokens: args.max_tokens,
467
+ }, workspaceId, MARKDOWN);
468
+ }
469
+
414
470
  // POST /api/v1/index/files — used by the file watcher for incremental updates.
415
471
  export async function sendFileUpdate(filePath, workspaceId, language, buildTool) {
416
472
  try {
package/src/index.js CHANGED
@@ -1,32 +1,13 @@
1
1
  #!/usr/bin/env node
2
- import "./telemetry.js";
3
- import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
4
-
5
- import { log } from "./log.js";
6
- import { shutdownTelemetry } from "./telemetry.js";
7
- import { getCurrentUsername } from "./workspaceIdentity.js";
8
- import { startFileWatcher, stopFileWatcher } from "./fileWatcher.js";
9
- import { buildMcpServer } from "./server.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()}`);
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
  }