@codeconductorai/harmony-mcp 1.0.28 → 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 +10 -8
- package/package.json +1 -1
- package/src/fileWatcher.js +186 -26
- package/src/harmonyClient.js +35 -0
- package/src/server.js +11 -1
- package/src/telemetry.js +17 -9
- package/src/toolSchemas.js +13 -3
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.
|
|
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.
|
|
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.
|
|
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.
|
|
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.
|
|
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.
|
|
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.
|
|
98
|
+
"args": ["-y", "@codeconductorai/harmony-mcp@1.0.30"]
|
|
99
99
|
}
|
|
100
100
|
}
|
|
101
101
|
}
|
|
@@ -159,7 +159,9 @@ Given a natural-language query or exact identifier, returns lightweight symbol c
|
|
|
159
159
|
|
|
160
160
|
## Observability (OpenObserve)
|
|
161
161
|
|
|
162
|
-
|
|
162
|
+
**Telemetry export is disabled by default.** Set `HARMONY_TELEMETRY_ENABLED=true` in the server's environment to turn it on; otherwise no logs, traces, or metrics are sent and no trace headers are added to backend requests. Local file logging is unaffected.
|
|
163
|
+
|
|
164
|
+
When enabled, the server ships its own logs, traces, and metrics over OTLP/HTTP using OpenTelemetry, and forwards the active trace id to every request it makes to the harmony backend (as a W3C `traceparent` header plus a plain `X-Trace-Id` header) so backend-side logs can be correlated with the MCP session that triggered them.
|
|
163
165
|
|
|
164
166
|
Telemetry is exported to the harmony backend's `/api/v1/otel/{traces,metrics,logs}` endpoints rather than straight to [OpenObserve](https://openobserve.codeconductor.ai/) — the backend forwards it on to OpenObserve using a server-side-only ingestion credential. This package holds no OpenObserve credential of its own: it authenticates to the backend with whichever Bearer session or workspace token it already uses for every other API call, so nothing extra needs to be configured, and a plain `npx` install never needs (or can leak) an ingestion secret. If neither token is available yet (e.g. before `login`/`setup_workspace`), export calls simply fail unauthenticated against the backend and are logged, without affecting normal server operation.
|
|
165
167
|
|
package/package.json
CHANGED
package/src/fileWatcher.js
CHANGED
|
@@ -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
|
-
|
|
9
|
+
const DEBOUNCE_MS = 50;
|
|
10
|
+
const MAX_TRACKED_SYNC_FAILURES = 20;
|
|
10
11
|
|
|
11
|
-
//
|
|
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
|
|
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
|
-
|
|
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
|
-
|
|
37
|
-
|
|
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,
|
|
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
|
-
|
|
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
|
-
|
|
69
|
-
|
|
70
|
-
if (
|
|
71
|
-
|
|
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 (
|
|
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
|
-
|
|
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
|
-
|
|
97
|
-
|
|
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(),
|
|
210
|
+
watchDirectoryTree(process.cwd(), false);
|
|
102
211
|
|
|
103
|
-
if (
|
|
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 (${
|
|
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
|
|
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
|
}
|
package/src/harmonyClient.js
CHANGED
|
@@ -293,6 +293,10 @@ export async function callHarmonySearchEndpoint(endpointPath, args, workspaceId)
|
|
|
293
293
|
prompt,
|
|
294
294
|
file_path: args.file_path,
|
|
295
295
|
limit: args.limit,
|
|
296
|
+
// context_search returns code by default so the agent need not re-read the files; locate stays coordinates-only
|
|
297
|
+
include_code_snippets: args.include_code_snippets ?? (endpointPath === "context-search" ? true : undefined),
|
|
298
|
+
// context_search answers in the compact LLM format (llm-context-format-guide.md); locate keeps its own format
|
|
299
|
+
response_format: endpointPath === "context-search" ? "compact" : undefined,
|
|
296
300
|
workspaceMetadata: buildWorkspaceMetadata(workspaceId),
|
|
297
301
|
};
|
|
298
302
|
|
|
@@ -384,6 +388,8 @@ export async function sendFileUpdate(filePath, workspaceId, language, buildTool)
|
|
|
384
388
|
form.append("buildTool", buildTool);
|
|
385
389
|
}
|
|
386
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");
|
|
387
393
|
|
|
388
394
|
// Field names must match @RequestPart("files") and @RequestParam("paths")
|
|
389
395
|
form.append("files", fs.createReadStream(filePath), { filename: path.basename(filePath) });
|
|
@@ -399,7 +405,36 @@ export async function sendFileUpdate(filePath, workspaceId, language, buildTool)
|
|
|
399
405
|
if (!response.ok) {
|
|
400
406
|
log(`[fileWatcher] Index failed: ${body}${traceSuffix()}`);
|
|
401
407
|
}
|
|
408
|
+
return { ok: response.ok, status: response.status, body };
|
|
402
409
|
} catch (error) {
|
|
403
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 };
|
|
404
439
|
}
|
|
405
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) {
|
package/src/telemetry.js
CHANGED
|
@@ -61,13 +61,21 @@ const sdk = new NodeSDK({
|
|
|
61
61
|
logRecordProcessors: [new BatchLogRecordProcessor({ exporter: logExporter })],
|
|
62
62
|
});
|
|
63
63
|
|
|
64
|
+
// Export to OpenObserve is opt-in. Without a started SDK the @opentelemetry/api calls below are
|
|
65
|
+
// no-ops, so no logs, metrics, or traces leave the process.
|
|
66
|
+
const TELEMETRY_ENABLED = process.env.HARMONY_TELEMETRY_ENABLED === "true";
|
|
67
|
+
|
|
64
68
|
let started = false;
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
69
|
+
if (TELEMETRY_ENABLED) {
|
|
70
|
+
try {
|
|
71
|
+
sdk.start();
|
|
72
|
+
started = true;
|
|
73
|
+
log(`[telemetry] OpenTelemetry started — exporting via backend proxy at ${OTLP_BASE}`);
|
|
74
|
+
} catch (err) {
|
|
75
|
+
log(`[telemetry] Failed to start OpenTelemetry SDK: ${err?.message || err}`);
|
|
76
|
+
}
|
|
77
|
+
} else {
|
|
78
|
+
log("[telemetry] OpenTelemetry export disabled (set HARMONY_TELEMETRY_ENABLED=true to enable)");
|
|
71
79
|
}
|
|
72
80
|
|
|
73
81
|
export async function shutdownTelemetry() {
|
|
@@ -123,12 +131,12 @@ export async function tracedFetch(url, options = {}) {
|
|
|
123
131
|
const traceId = getActiveTraceId();
|
|
124
132
|
span.setAttribute("http.request.method", method);
|
|
125
133
|
span.setAttribute("url.full", url);
|
|
126
|
-
log(`[telemetry] trace id ${traceId} for ${method} ${path}`);
|
|
134
|
+
if (traceId) log(`[telemetry] trace id ${traceId} for ${method} ${path}`);
|
|
127
135
|
const startedAt = Date.now();
|
|
128
136
|
try {
|
|
129
137
|
const response = await fetch(url, { ...options, headers: injectTraceHeaders(options.headers || {}) });
|
|
130
138
|
span.setAttribute("http.response.status_code", response.status);
|
|
131
|
-
log(`[telemetry] trace id ${traceId} for ${method} ${path} -> ${response.status}` +
|
|
139
|
+
if (traceId) log(`[telemetry] trace id ${traceId} for ${method} ${path} -> ${response.status}` +
|
|
132
140
|
(response.ok ? "" : " (backend X-Trace-Id: " + (response.headers.get("x-trace-id") || "none") + ")"));
|
|
133
141
|
if (!response.ok) {
|
|
134
142
|
span.setStatus({ code: SpanStatusCode.ERROR, message: `HTTP ${response.status}` });
|
|
@@ -139,7 +147,7 @@ export async function tracedFetch(url, options = {}) {
|
|
|
139
147
|
span.recordException(error);
|
|
140
148
|
span.setStatus({ code: SpanStatusCode.ERROR, message: error?.message });
|
|
141
149
|
backendRequestErrors.add(1, { "url.path": path });
|
|
142
|
-
log(`[telemetry] trace id ${traceId} for ${method} ${path} -> request error: ${error?.message}`);
|
|
150
|
+
if (traceId) log(`[telemetry] trace id ${traceId} for ${method} ${path} -> request error: ${error?.message}`);
|
|
143
151
|
throw error;
|
|
144
152
|
} finally {
|
|
145
153
|
backendRequestDuration.record(Date.now() - startedAt, { "url.path": path });
|
package/src/toolSchemas.js
CHANGED
|
@@ -70,12 +70,16 @@ export const TOOLS = [
|
|
|
70
70
|
},
|
|
71
71
|
{
|
|
72
72
|
name: "context_search",
|
|
73
|
+
_meta: { "anthropic/alwaysLoad": true },
|
|
73
74
|
description:
|
|
74
75
|
"PREFERRED FIRST CHOICE for any code discovery/comprehension need — Harmony's newest and best-ranked " +
|
|
75
76
|
"search endpoint. Given a natural language query or exact identifier, returns ranked matching symbols " +
|
|
76
|
-
"
|
|
77
|
-
"
|
|
78
|
-
"
|
|
77
|
+
"in a compact format: one root with relative paths; verbatim code (exact=\"true\", safe to use for an " +
|
|
78
|
+
"Edit) for the top hits, limited to the members that match the question; the remaining hits as one line " +
|
|
79
|
+
"each with member signatures and line ranges; other members named so you can tell what was left out; " +
|
|
80
|
+
"flow questions answered as a one-line-per-step trace. Code marked exact=\"false\" has collapsed or cut " +
|
|
81
|
+
"lines, named in the block. The answer usually needs no follow-up file reads — read a file only for " +
|
|
82
|
+
"lines it names as not shown, or before editing. Try this BEFORE locate; only fall back to locate if context_search's " +
|
|
79
83
|
"result is empty, insufficient, or you specifically need its line-number-only anchors for a targeted " +
|
|
80
84
|
"edit. Treat context_search as the always-on default " +
|
|
81
85
|
"entry point for every new discovery/comprehension need that comes up during a task — call it again " +
|
|
@@ -100,6 +104,12 @@ export const TOOLS = [
|
|
|
100
104
|
type: "number",
|
|
101
105
|
description: "Optional maximum number of results to return; the backend applies its own default if omitted.",
|
|
102
106
|
},
|
|
107
|
+
include_code_snippets: {
|
|
108
|
+
type: "boolean",
|
|
109
|
+
description:
|
|
110
|
+
"Optional, default true. Each returned symbol (and each step of a traced flow) includes its source " +
|
|
111
|
+
"excerpt (method or class body, capped at 50 lines). Set false to get file paths and line numbers only.",
|
|
112
|
+
},
|
|
103
113
|
workspaceId: WORKSPACE_ID_PROPERTY,
|
|
104
114
|
},
|
|
105
115
|
required: ["prompt"],
|