@codeconductorai/harmony-mcp 1.0.29 → 1.0.30

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,12 +27,12 @@ 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.29`) 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.30`) 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.29
35
+ claude mcp add harmony -- npx -y @codeconductorai/harmony-mcp@1.0.30
36
36
  ```
37
37
 
38
38
  ### Antigravity
@@ -47,7 +47,7 @@ Open **MCP Servers → Manage MCP Servers → View raw config** from the agent p
47
47
  "mcpServers": {
48
48
  "harmony": {
49
49
  "command": "npx",
50
- "args": ["-y", "@codeconductorai/harmony-mcp@1.0.29"]
50
+ "args": ["-y", "@codeconductorai/harmony-mcp@1.0.30"]
51
51
  }
52
52
  }
53
53
  }
@@ -58,7 +58,7 @@ Restart Antigravity (or reload MCP servers) after saving.
58
58
  ### Codex CLI
59
59
 
60
60
  ```bash
61
- codex mcp add harmony -- npx -y @codeconductorai/harmony-mcp@1.0.29
61
+ codex mcp add harmony -- npx -y @codeconductorai/harmony-mcp@1.0.30
62
62
  ```
63
63
 
64
64
  This writes the entry to `~/.codex/config.toml`. To add it by hand instead:
@@ -66,7 +66,7 @@ This writes the entry to `~/.codex/config.toml`. To add it by hand instead:
66
66
  ```toml
67
67
  [mcp_servers.harmony]
68
68
  command = "npx"
69
- args = ["-y", "@codeconductorai/harmony-mcp@1.0.29"]
69
+ args = ["-y", "@codeconductorai/harmony-mcp@1.0.30"]
70
70
  ```
71
71
 
72
72
  ### Aria
@@ -78,7 +78,7 @@ In the Aria Code panel, click the settings icon → **MCP Servers**, then scroll
78
78
  "mcpServers": {
79
79
  "harmony": {
80
80
  "command": "npx",
81
- "args": ["-y", "@codeconductorai/harmony-mcp@1.0.29"]
81
+ "args": ["-y", "@codeconductorai/harmony-mcp@1.0.30"]
82
82
  }
83
83
  }
84
84
  }
@@ -95,7 +95,7 @@ Any client that reads a `command`/`args` style config (e.g. Claude Desktop's `cl
95
95
  "mcpServers": {
96
96
  "harmony": {
97
97
  "command": "npx",
98
- "args": ["-y", "@codeconductorai/harmony-mcp@1.0.29"]
98
+ "args": ["-y", "@codeconductorai/harmony-mcp@1.0.30"]
99
99
  }
100
100
  }
101
101
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@codeconductorai/harmony-mcp",
3
- "version": "1.0.29",
3
+ "version": "1.0.30",
4
4
  "type": "module",
5
5
  "main": "src/index.js",
6
6
  "bin": {
@@ -4,24 +4,76 @@ import path from "path";
4
4
  import { log } from "./log.js";
5
5
  import { shouldIgnore } from "./fileFilters.js";
6
6
  import { readMarker } from "./workspaceMarker.js";
7
- import { sendFileUpdate } from "./harmonyClient.js";
7
+ import { sendFileUpdate, sendFileDelete } from "./harmonyClient.js";
8
8
 
9
- let fileWatchers = [];
9
+ const DEBOUNCE_MS = 50;
10
+ const MAX_TRACKED_SYNC_FAILURES = 20;
10
11
 
11
- // Close every active watcher handle, called on watcher error and process shutdown.
12
+ // dir -> fs.FSWatcher for every directory under watch.
13
+ const watchedDirs = new Map();
14
+ // Directories that could not be watched (usually ENOSPC: inotify watch limit) — edits there are missed.
15
+ const unwatchedDirs = new Set();
16
+ // Files the watcher knows exist, so a vanished directory (rm -rf, mv) can be turned into per-file deletes.
17
+ const knownFiles = new Set();
18
+ let lastWatchError = null;
19
+
20
+ // Recent failed sync calls, plus how many of them (and of unwatchedDirs) the agent hasn't been told about.
21
+ const syncFailures = [];
22
+ let unreportedFailures = 0;
23
+ let reportedUnwatchedCount = 0;
24
+
25
+ let onFileChange = null;
26
+ // Sync calls run one at a time, in event order: a rename's delete lands before the new path's add,
27
+ // and the backend never sees overlapping passes for this workspace.
28
+ let syncQueue = Promise.resolve();
29
+
30
+ // Close every active watcher handle, called on process shutdown.
12
31
  export function stopFileWatcher() {
13
- for (const watcher of fileWatchers) {
32
+ for (const watcher of watchedDirs.values()) {
33
+ try {
34
+ watcher.close();
35
+ } catch {
36
+ // already closed
37
+ }
38
+ }
39
+ watchedDirs.clear();
40
+ unwatchedDirs.clear();
41
+ knownFiles.clear();
42
+ onFileChange = null;
43
+ }
44
+
45
+ function relative(filePath) {
46
+ return path.relative(process.cwd(), filePath);
47
+ }
48
+
49
+ function isUnder(filePath, dir) {
50
+ return filePath === dir || filePath.startsWith(dir + path.sep);
51
+ }
52
+
53
+ // Stop watching a directory that no longer exists, and queue a delete for every known file under it
54
+ // (a renamed-away directory produces no per-file events).
55
+ function forgetDirectory(dir) {
56
+ for (const [watchedDir, watcher] of watchedDirs) {
57
+ if (!isUnder(watchedDir, dir)) continue;
14
58
  try {
15
59
  watcher.close();
16
60
  } catch {
17
61
  // already closed
18
62
  }
63
+ watchedDirs.delete(watchedDir);
64
+ }
65
+ for (const unwatched of [...unwatchedDirs]) {
66
+ if (isUnder(unwatched, dir)) unwatchedDirs.delete(unwatched);
67
+ }
68
+ for (const filePath of [...knownFiles]) {
69
+ if (isUnder(filePath, dir)) onFileChange?.(filePath);
19
70
  }
20
- fileWatchers = [];
21
71
  }
22
72
 
23
73
  // Watch one directory at a time so ignored subtrees (node_modules etc.) skip a watch handle — avoids EMFILE.
24
- function watchDirectoryTree(dir, onFileChange) {
74
+ // syncExisting: also push every file already present (a directory created or moved in after startup).
75
+ function watchDirectoryTree(dir, syncExisting) {
76
+ if (watchedDirs.has(dir)) return;
25
77
  let watcher;
26
78
  try {
27
79
  watcher = fs.watch(dir, { recursive: false }, (eventType, filename) => {
@@ -33,30 +85,37 @@ function watchDirectoryTree(dir, onFileChange) {
33
85
  try {
34
86
  stat = fs.statSync(filePath);
35
87
  } catch {
36
- if (eventType === "rename") {
37
- log(`[fileWatcher] Detected removal of ${path.relative(process.cwd(), filePath)} — ` +
38
- `not propagated to the backend (no delete endpoint available); remote index may be stale for this path.`);
39
- }
88
+ // Gone: a deleted/renamed-away file or directory; resolved when the debounce fires.
89
+ if (eventType === "rename") onFileChange?.(filePath);
40
90
  return;
41
91
  }
42
92
 
43
93
  if (stat.isDirectory()) {
44
- if (eventType === "rename") watchDirectoryTree(filePath, onFileChange);
94
+ if (eventType === "rename") watchDirectoryTree(filePath, true);
45
95
  return;
46
96
  }
47
97
 
48
- onFileChange(filePath);
98
+ onFileChange?.(filePath);
49
99
  });
50
100
  } catch (err) {
101
+ unwatchedDirs.add(dir);
102
+ lastWatchError = err.code || err.message;
51
103
  log(`[fileWatcher] Failed to watch ${dir}: ${err.message}`);
52
104
  return;
53
105
  }
54
106
 
55
107
  watcher.on("error", (err) => {
108
+ // A watched directory that was deleted can surface as an error; drop just that subtree.
109
+ if (!fs.existsSync(dir)) {
110
+ forgetDirectory(dir);
111
+ return;
112
+ }
56
113
  log(`[fileWatcher] Watcher error on ${dir}: ${err.message}. Stopping file watcher.`);
114
+ lastWatchError = err.code || err.message;
57
115
  stopFileWatcher();
58
116
  });
59
- fileWatchers.push(watcher);
117
+ watchedDirs.set(dir, watcher);
118
+ unwatchedDirs.delete(dir);
60
119
 
61
120
  let entries;
62
121
  try {
@@ -65,16 +124,64 @@ function watchDirectoryTree(dir, onFileChange) {
65
124
  return;
66
125
  }
67
126
  for (const entry of entries) {
68
- if (!entry.isDirectory()) continue;
69
- const subDir = path.join(dir, entry.name);
70
- if (shouldIgnore(subDir)) continue;
71
- watchDirectoryTree(subDir, onFileChange);
127
+ const entryPath = path.join(dir, entry.name);
128
+ if (shouldIgnore(entryPath)) continue;
129
+ if (entry.isDirectory()) {
130
+ watchDirectoryTree(entryPath, syncExisting);
131
+ } else if (entry.isFile()) {
132
+ knownFiles.add(entryPath);
133
+ if (syncExisting) onFileChange?.(entryPath);
134
+ }
135
+ }
136
+ }
137
+
138
+ function recordSyncResult(action, filePath, result) {
139
+ if (result?.ok) return;
140
+ syncFailures.push({
141
+ action,
142
+ path: relative(filePath),
143
+ status: result?.status ?? "network-error",
144
+ at: new Date().toISOString(),
145
+ });
146
+ if (syncFailures.length > MAX_TRACKED_SYNC_FAILURES) syncFailures.shift();
147
+ unreportedFailures++;
148
+ }
149
+
150
+ // Resolve a debounced path: update it if it still exists, delete it from the index if it doesn't.
151
+ async function syncPath(filePath, workspaceId, language, buildTool) {
152
+ let stat = null;
153
+ try {
154
+ stat = fs.statSync(filePath);
155
+ } catch {
156
+ // missing
157
+ }
158
+
159
+ if (stat?.isDirectory()) return;
160
+ if (stat) {
161
+ knownFiles.add(filePath);
162
+ recordSyncResult("update", filePath, await sendFileUpdate(filePath, workspaceId, language, buildTool));
163
+ return;
72
164
  }
165
+
166
+ if (watchedDirs.has(filePath) || [...watchedDirs.keys()].some((dir) => isUnder(dir, filePath))) {
167
+ forgetDirectory(filePath);
168
+ return;
169
+ }
170
+ if ([...unwatchedDirs].some((dir) => isUnder(dir, filePath))) {
171
+ // Nothing is known about the contents of a directory we never watched; don't guess.
172
+ log(`[fileWatcher] Removal of unwatched ${relative(filePath)} not propagated; its files may stay indexed.`);
173
+ return;
174
+ }
175
+ // Only files that existed are deleted: skips editor temp files that vanished before syncing and the
176
+ // self-events a moved/removed watched directory emits (reported as "<dir>/<basename of dir>").
177
+ if (!knownFiles.has(filePath)) return;
178
+ knownFiles.delete(filePath);
179
+ recordSyncResult("delete", filePath, await sendFileDelete(filePath, workspaceId));
73
180
  }
74
181
 
75
- // Watch the cwd for file changes and send incremental updates to the backend.
182
+ // Watch the cwd for file changes and send incremental updates and deletes to the backend.
76
183
  export function startFileWatcher() {
77
- if (fileWatchers.length > 0) {
184
+ if (watchedDirs.size > 0) {
78
185
  log("[fileWatcher] Already running.");
79
186
  return;
80
187
  }
@@ -87,27 +194,80 @@ export function startFileWatcher() {
87
194
  const { workspaceId, language, buildTool } = marker;
88
195
  const debounceMap = new Map();
89
196
 
90
- const onFileChange = (filePath) => {
197
+ onFileChange = (filePath) => {
91
198
  if (debounceMap.has(filePath)) clearTimeout(debounceMap.get(filePath));
92
199
  debounceMap.set(
93
200
  filePath,
94
201
  setTimeout(() => {
95
202
  debounceMap.delete(filePath);
96
- sendFileUpdate(filePath, workspaceId, language, buildTool);
97
- }, 50)
203
+ syncQueue = syncQueue
204
+ .then(() => syncPath(filePath, workspaceId, language, buildTool))
205
+ .catch((error) => log(`[fileWatcher] Sync of ${relative(filePath)} failed: ${error.message}`));
206
+ }, DEBOUNCE_MS)
98
207
  );
99
208
  };
100
209
 
101
- watchDirectoryTree(process.cwd(), onFileChange);
210
+ watchDirectoryTree(process.cwd(), false);
102
211
 
103
- if (fileWatchers.length === 0) {
212
+ if (watchedDirs.size === 0) {
104
213
  log("[fileWatcher] No watch handles could be created; incremental sync is unavailable this session.");
105
214
  return;
106
215
  }
107
- log(`[fileWatcher] Watching ${process.cwd()} for file changes (${fileWatchers.length} directories).`);
216
+ log(`[fileWatcher] Watching ${process.cwd()} for file changes (${watchedDirs.size} directories` +
217
+ (unwatchedDirs.size ? `, ${unwatchedDirs.size} could not be watched: ${lastWatchError}` : "") + ").");
108
218
  }
109
219
 
110
220
  // True if the incremental watcher has at least one active watch handle.
111
221
  export function isFileWatcherActive() {
112
- return fileWatchers.length > 0;
222
+ return watchedDirs.size > 0;
223
+ }
224
+
225
+ export function getFileWatcherStatus() {
226
+ return {
227
+ active: watchedDirs.size > 0,
228
+ watchedDirectories: watchedDirs.size,
229
+ unwatchedDirectories: unwatchedDirs.size,
230
+ lastWatchError,
231
+ recentSyncFailures: syncFailures.slice(-5),
232
+ };
233
+ }
234
+
235
+ function describeUnwatched() {
236
+ const reason = lastWatchError === "ENOSPC"
237
+ ? "the OS file-watch limit is exhausted (raise fs.inotify.max_user_watches)"
238
+ : `watching failed (${lastWatchError || "unknown error"})`;
239
+ return `${unwatchedDirs.size} director${unwatchedDirs.size === 1 ? "y is" : "ies are"} not watched because ${reason}; ` +
240
+ `edits there won't reach the index until setup_workspace re-uploads.`;
241
+ }
242
+
243
+ // One-line warning for the agent when local edits failed to reach the index since the last warning,
244
+ // or null when there is nothing new to report. Keeps search responses unchanged in the normal case.
245
+ export function takeSyncWarning() {
246
+ const parts = [];
247
+ if (unreportedFailures > 0) {
248
+ const recent = syncFailures.slice(-Math.min(unreportedFailures, 3))
249
+ .map((f) => `${f.action} ${f.path} (${f.status})`)
250
+ .join(", ");
251
+ parts.push(`${unreportedFailures} local file change(s) failed to sync to the index: ${recent}. ` +
252
+ `Results for those files may be stale — verify with Read/Grep.`);
253
+ unreportedFailures = 0;
254
+ }
255
+ if (unwatchedDirs.size > reportedUnwatchedCount) {
256
+ parts.push(describeUnwatched());
257
+ reportedUnwatchedCount = unwatchedDirs.size;
258
+ }
259
+ return parts.length ? `[harmony sync] ${parts.join(" ")}` : null;
260
+ }
261
+
262
+ export function describeFileWatcherProblem() {
263
+ if (watchedDirs.size === 0) {
264
+ return "File watching is unavailable this session" +
265
+ (lastWatchError ? ` (${lastWatchError})` : "") +
266
+ ", so local edits won't be synced to the index; re-run setup_workspace after changing files.";
267
+ }
268
+ if (unwatchedDirs.size > 0) {
269
+ reportedUnwatchedCount = unwatchedDirs.size;
270
+ return describeUnwatched();
271
+ }
272
+ return null;
113
273
  }
@@ -388,6 +388,8 @@ export async function sendFileUpdate(filePath, workspaceId, language, buildTool)
388
388
  form.append("buildTool", buildTool);
389
389
  }
390
390
  form.append("phase", "LEXICAL");
391
+ // Wait for the incremental pass so a failed pass comes back as an error instead of a silent 200.
392
+ form.append("waitForCompletion", "true");
391
393
 
392
394
  // Field names must match @RequestPart("files") and @RequestParam("paths")
393
395
  form.append("files", fs.createReadStream(filePath), { filename: path.basename(filePath) });
@@ -403,7 +405,36 @@ export async function sendFileUpdate(filePath, workspaceId, language, buildTool)
403
405
  if (!response.ok) {
404
406
  log(`[fileWatcher] Index failed: ${body}${traceSuffix()}`);
405
407
  }
408
+ return { ok: response.ok, status: response.status, body };
406
409
  } catch (error) {
407
410
  log(`[fileWatcher] Error sending file update:`, error.message);
411
+ return { ok: false, status: null, body: error.message };
412
+ }
413
+ }
414
+
415
+ // DELETE /api/v1/delete/files — used by the file watcher when a file is deleted or renamed away.
416
+ export async function sendFileDelete(filePath, workspaceId) {
417
+ const relativePath = path.relative(process.cwd(), filePath);
418
+ try {
419
+ const url = new URL("/api/v1/delete/files", API_URL);
420
+ for (const [key, value] of Object.entries(buildWorkspaceMetadata(workspaceId))) {
421
+ url.searchParams.set(key, value);
422
+ }
423
+ url.searchParams.append("paths", relativePath);
424
+ url.searchParams.set("waitForCompletion", "true");
425
+
426
+ const response = await fetch(url.toString(), {
427
+ method: "DELETE",
428
+ headers: await authHeader(workspaceId),
429
+ });
430
+ const body = await response.text();
431
+ log(`[fileWatcher] delete ${relativePath} -> ${response.status}`);
432
+ if (!response.ok) {
433
+ log(`[fileWatcher] Delete failed: ${body}${traceSuffix()}`);
434
+ }
435
+ return { ok: response.ok, status: response.status, body };
436
+ } catch (error) {
437
+ log(`[fileWatcher] Error sending file delete:`, error.message);
438
+ return { ok: false, status: null, body: error.message };
408
439
  }
409
440
  }
package/src/server.js CHANGED
@@ -19,7 +19,7 @@ import {
19
19
  import { getGitBranch, getGitCommitHash, getProjectName } from "./repoIdentity.js";
20
20
  import { getCurrentUsername, REPO_ID, REPO_IDENTITY } from "./workspaceIdentity.js";
21
21
  import { readMarker, writeMarker } from "./workspaceMarker.js";
22
- import { startFileWatcher, isFileWatcherActive } from "./fileWatcher.js";
22
+ import { startFileWatcher, isFileWatcherActive, describeFileWatcherProblem, takeSyncWarning } from "./fileWatcher.js";
23
23
  import {
24
24
  ensureWorkspaceUploaded,
25
25
  pollWorkspaceStatus,
@@ -218,6 +218,7 @@ async function handleSetupWorkspace(args, extra) {
218
218
  ready: outcome.ready,
219
219
  indexStatus,
220
220
  fileWatcherActive: isFileWatcherActive(),
221
+ fileWatcherWarning: describeFileWatcherProblem() ?? undefined,
221
222
  user: getCurrentUsername(),
222
223
  });
223
224
  }
@@ -264,6 +265,7 @@ async function handleSetupWorkspace(args, extra) {
264
265
  ready: outcome.ready,
265
266
  indexStatus,
266
267
  fileWatcherActive: isFileWatcherActive(),
268
+ fileWatcherWarning: describeFileWatcherProblem() ?? undefined,
267
269
  user: getCurrentUsername(),
268
270
  });
269
271
  }
@@ -398,6 +400,13 @@ function logToolError(name, args, error, durationMs) {
398
400
  });
399
401
  }
400
402
 
403
+ // Tell the agent, once, when local edits failed to reach the index — otherwise it would trust stale results.
404
+ function withSyncWarning(result) {
405
+ const warning = takeSyncWarning();
406
+ if (!warning || !Array.isArray(result?.content)) return result;
407
+ return { ...result, content: [...result.content, { type: "text", text: warning }] };
408
+ }
409
+
401
410
  // Build the MCP server: tool listing, and the tools/call dispatcher.
402
411
  export function buildMcpServer() {
403
412
  const server = new Server(
@@ -432,6 +441,7 @@ export function buildMcpServer() {
432
441
  return result;
433
442
  }
434
443
  result = await handler(args, extra);
444
+ if (!AUTH_EXEMPT_TOOLS.has(name)) result = withSyncWarning(result);
435
445
  if (result?.isError) span.setStatus({ code: SpanStatusCode.ERROR });
436
446
  return result;
437
447
  } catch (error) {