@codeconductorai/harmony-mcp 1.0.33 → 1.0.34
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 +210 -15
- package/package.json +4 -2
- package/src/{deviceAuth.js → auth/deviceAuth.js} +2 -2
- package/src/{harmonyClient.js → backend/harmonyClient.js} +183 -13
- package/src/doctor/doctorCommand.js +382 -0
- package/src/index.js +18 -5
- package/src/{telemetry.js → observability/telemetry.js} +3 -3
- package/src/rsi/bundleHints.js +181 -0
- package/src/rsi/bundleRefresher.js +95 -0
- package/src/rsi/callContext.js +49 -0
- package/src/rsi/causalState.js +103 -0
- package/src/rsi/clientAgent.js +58 -0
- package/src/rsi/hooks/eventBuilder.js +126 -0
- package/src/rsi/hooks/fileHash.js +33 -0
- package/src/rsi/hooks/hmacSigner.js +39 -0
- package/src/rsi/hooks/hookEventCommand.js +196 -0
- package/src/rsi/hooks/normalizers.js +329 -0
- package/src/rsi/hooks/offlineSpooler.js +104 -0
- package/src/rsi/hooks/secretScrubber.js +50 -0
- package/src/rsi/hooks/shellCommandScrubber.js +449 -0
- package/src/rsi/hooks/spoolDrainer.js +73 -0
- package/src/rsi/hooks/toolEventsClient.js +70 -0
- package/src/rsi/localState.js +53 -0
- package/src/rsi/serveTelemetry.js +85 -0
- package/src/rsi/workspaceRegistry.js +63 -0
- package/src/{server.js → server/server.js} +107 -17
- package/src/{serverInstructions.js → server/serverInstructions.js} +2 -2
- package/src/server/serverMain.js +46 -0
- package/src/{sessionIdentity.js → session/sessionIdentity.js} +10 -6
- package/src/setup/agentCapabilityMatrix.js +425 -0
- package/src/setup/agentsGuide.js +28 -0
- package/src/setup/configMergers.js +272 -0
- package/src/{installer.js → setup/installer.js} +1 -1
- package/src/setup/setupAgentsCommand.js +192 -0
- package/src/setup/shim.js +80 -0
- package/src/sync/managedMarkdownInjector.js +103 -0
- package/src/sync/syncWorkspaceCommand.js +143 -0
- package/src/sync/workspaceSync.js +88 -0
- package/src/{fileWatcher.js → workspace/fileWatcher.js} +2 -2
- package/src/{workspaceIdentity.js → workspace/workspaceIdentity.js} +1 -1
- package/src/agentsGuide.js +0 -38
- package/src/serverMain.js +0 -32
- /package/src/{log.js → observability/log.js} +0 -0
- /package/src/{toolSchemas.js → server/toolSchemas.js} +0 -0
- /package/src/{fileFilters.js → workspace/fileFilters.js} +0 -0
- /package/src/{repoIdentity.js → workspace/repoIdentity.js} +0 -0
- /package/src/{workspaceMarker.js → workspace/workspaceMarker.js} +0 -0
package/README.md
CHANGED
|
@@ -27,18 +27,18 @@ 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.34`) 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
|
-
npx -y @codeconductorai/harmony-mcp@1.0.
|
|
35
|
+
npx -y @codeconductorai/harmony-mcp@1.0.34 install claude
|
|
36
36
|
```
|
|
37
37
|
|
|
38
38
|
This registers the server for all your projects (`claude mcp add harmony --scope user ...`) and adds the session
|
|
39
39
|
hook from [Session id](#session-id) to `~/.claude/settings.json`. Claude Code reads Harmony's guidance (when to use
|
|
40
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.
|
|
41
|
+
project. To register only the server: `claude mcp add harmony -- npx -y @codeconductorai/harmony-mcp@1.0.34`.
|
|
42
42
|
|
|
43
43
|
### Antigravity
|
|
44
44
|
|
|
@@ -52,7 +52,7 @@ Open **MCP Servers → Manage MCP Servers → View raw config** from the agent p
|
|
|
52
52
|
"mcpServers": {
|
|
53
53
|
"harmony": {
|
|
54
54
|
"command": "npx",
|
|
55
|
-
"args": ["-y", "@codeconductorai/harmony-mcp@1.0.
|
|
55
|
+
"args": ["-y", "@codeconductorai/harmony-mcp@1.0.34"]
|
|
56
56
|
}
|
|
57
57
|
}
|
|
58
58
|
}
|
|
@@ -65,7 +65,7 @@ Restart Antigravity (or reload MCP servers) after saving.
|
|
|
65
65
|
Run this in your project:
|
|
66
66
|
|
|
67
67
|
```bash
|
|
68
|
-
npx -y @codeconductorai/harmony-mcp@1.0.
|
|
68
|
+
npx -y @codeconductorai/harmony-mcp@1.0.34 install codex
|
|
69
69
|
```
|
|
70
70
|
|
|
71
71
|
It does the three things Codex needs to actually use Harmony, and is safe to run again:
|
|
@@ -80,13 +80,13 @@ It does the three things Codex needs to actually use Harmony, and is safe to run
|
|
|
80
80
|
Each file is backed up once (`*.harmony-bak`) before its first change. Options: `--yes` (no prompt), `--no-agents-md`,
|
|
81
81
|
`--project <dir>`, `--env API_URL=...`, `--dry-run`. If you skip it, `setup_workspace` reminds Codex to offer it.
|
|
82
82
|
|
|
83
|
-
To set it up by hand instead, `codex mcp add harmony -- npx -y @codeconductorai/harmony-mcp@1.0.
|
|
83
|
+
To set it up by hand instead, `codex mcp add harmony -- npx -y @codeconductorai/harmony-mcp@1.0.34` writes the entry
|
|
84
84
|
to `~/.codex/config.toml`, or add:
|
|
85
85
|
|
|
86
86
|
```toml
|
|
87
87
|
[mcp_servers.harmony]
|
|
88
88
|
command = "npx"
|
|
89
|
-
args = ["-y", "@codeconductorai/harmony-mcp@1.0.
|
|
89
|
+
args = ["-y", "@codeconductorai/harmony-mcp@1.0.34"]
|
|
90
90
|
# Harmony's query tools only read the index; pre-approving them avoids an approval prompt (or, with
|
|
91
91
|
# --approve-for-me, an automatic reviewer that costs extra model requests and can reject the calls).
|
|
92
92
|
default_tools_approval_mode = "approve"
|
|
@@ -105,7 +105,7 @@ The installer's other two steps, by hand:
|
|
|
105
105
|
better" section to the project's `AGENTS.md`:
|
|
106
106
|
|
|
107
107
|
```bash
|
|
108
|
-
npx -y @codeconductorai/harmony-mcp@1.0.
|
|
108
|
+
npx -y @codeconductorai/harmony-mcp@1.0.34 --print-agents-md >> AGENTS.md
|
|
109
109
|
```
|
|
110
110
|
|
|
111
111
|
### Aria
|
|
@@ -117,7 +117,7 @@ In the Aria Code panel, click the settings icon → **MCP Servers**, then scroll
|
|
|
117
117
|
"mcpServers": {
|
|
118
118
|
"harmony": {
|
|
119
119
|
"command": "npx",
|
|
120
|
-
"args": ["-y", "@codeconductorai/harmony-mcp@1.0.
|
|
120
|
+
"args": ["-y", "@codeconductorai/harmony-mcp@1.0.34"]
|
|
121
121
|
}
|
|
122
122
|
}
|
|
123
123
|
}
|
|
@@ -134,7 +134,7 @@ Any client that reads a `command`/`args` style config (e.g. Claude Desktop's `cl
|
|
|
134
134
|
"mcpServers": {
|
|
135
135
|
"harmony": {
|
|
136
136
|
"command": "npx",
|
|
137
|
-
"args": ["-y", "@codeconductorai/harmony-mcp@1.0.
|
|
137
|
+
"args": ["-y", "@codeconductorai/harmony-mcp@1.0.34"]
|
|
138
138
|
}
|
|
139
139
|
}
|
|
140
140
|
}
|
|
@@ -151,6 +151,37 @@ After adding the server and restarting your client:
|
|
|
151
151
|
|
|
152
152
|
Workspace state (workspace ID, language, build tool, setup/upload status) is cached in a `.harmony_workspace.json` marker file in the project root.
|
|
153
153
|
|
|
154
|
+
## Agent learning loop (RSI)
|
|
155
|
+
|
|
156
|
+
Harmony learns where its answers fall short by seeing what the agent does *after* an answer. If the agent moves on,
|
|
157
|
+
the answer was enough. If it immediately searches or reads files itself, the answer missed something, and the files
|
|
158
|
+
it looked for show what.
|
|
159
|
+
|
|
160
|
+
```
|
|
161
|
+
agent ──question──► MCP server ──► backend: answers, records it, returns an answer id (X-Harmony-Ledger-Id)
|
|
162
|
+
│
|
|
163
|
+
└─ saves the answer id in ~/.harmony/run/<repo-hash>.state
|
|
164
|
+
agent keeps working (rg, Read, Edit, gradle …)
|
|
165
|
+
└─ agent hook ──► harmony-mcp hook-event: links the action to that answer id, strips secrets,
|
|
166
|
+
signs it, sends it to the backend (or queues it in ~/.harmony/spool/)
|
|
167
|
+
backend joins answers + actions ──► "Agent insights" page per workspace in the Harmony web app
|
|
168
|
+
```
|
|
169
|
+
|
|
170
|
+
To turn it on for a machine:
|
|
171
|
+
|
|
172
|
+
1. `npx -y @codeconductorai/harmony-mcp@1.0.34 setup-agents`: adds Harmony and its hooks to every installed agent.
|
|
173
|
+
For Codex, trust the new hooks once in Codex's `/hooks`.
|
|
174
|
+
2. In each repo: `login` (hook events are sent with your user login, not the workspace token), then `setup_workspace`.
|
|
175
|
+
3. `npx -y @codeconductorai/harmony-mcp@1.0.34 doctor` in the repo: every check should be green.
|
|
176
|
+
4. Results: **My Workspaces → Agent insights** in the Harmony web app shows tokens saved, how often agents still
|
|
177
|
+
searched or read files after an answer, results per tool and agent, and the files agents had to find themselves.
|
|
178
|
+
|
|
179
|
+
The pieces are described below: [RSI bundle](#rsi-bundle-tool-hints-and-session-pinning),
|
|
180
|
+
[setup-agents](#set-up-every-installed-agent-harmony-mcp-setup-agents), [doctor](#health-check-harmony-mcp-doctor),
|
|
181
|
+
[sync-workspace](#managed-workspace-instructions-harmony-mcp-sync-workspace) and
|
|
182
|
+
[tool hooks](#tool-hooks-harmony-mcp-hook-event). The wire format is in the backend repo,
|
|
183
|
+
`docs/rsi/rsi-wire-contract.md`.
|
|
184
|
+
|
|
154
185
|
### Workspace-token auth and refresh
|
|
155
186
|
|
|
156
187
|
On deployments that skip login entirely (step 1 above), `setup_workspace`'s first call gets back two credentials instead of one: a short-lived access token (used as the Bearer on every API call) and a long-lived refresh token. Both are stored in `~/.harmony-mcp/workspace-tokens.json` — never in the project's `.harmony_workspace.json` marker, since that file has no guarantee of staying out of version control and these are bearer credentials.
|
|
@@ -196,6 +227,19 @@ Given a natural-language query or exact identifier, returns lightweight symbol c
|
|
|
196
227
|
- `limit` (optional): max results (default 40); the result list is never padded to this size.
|
|
197
228
|
- `workspaceId` (optional): target a specific workspace instead of the local project's. Defaults to the local `setup_workspace` workspace.
|
|
198
229
|
|
|
230
|
+
### Other tools
|
|
231
|
+
|
|
232
|
+
| Tool | What it does |
|
|
233
|
+
| :--- | :--- |
|
|
234
|
+
| `investigate` | Answers a code question with a token-budgeted brief of the best-matching methods and types. |
|
|
235
|
+
| `inspect_trace` | Shows one execution flow end to end: entry route, call chain, security posture. |
|
|
236
|
+
| `preflight` | Before an edit, shows the blast radius of changing given files or symbols. |
|
|
237
|
+
| `security_scan` | Scans the indexed code for security and code-quality issues. |
|
|
238
|
+
| `security_audit` | Security posture of the workspace, findings grouped by root cause. |
|
|
239
|
+
| `security_finding_action` | Inspects or acts on a finding handle from `security_audit`. |
|
|
240
|
+
| `compress_build_log` | Turns raw build or test output into a short diagnosis. |
|
|
241
|
+
| `session_checkpoint` | A compact (~500 token) snapshot of the current Harmony session. |
|
|
242
|
+
|
|
199
243
|
## Observability (OpenObserve)
|
|
200
244
|
|
|
201
245
|
**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.
|
|
@@ -204,13 +248,164 @@ When enabled, the server ships its own logs, traces, and metrics over OTLP/HTTP
|
|
|
204
248
|
|
|
205
249
|
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.
|
|
206
250
|
|
|
207
|
-
##
|
|
251
|
+
## RSI bundle (tool hints and session pinning)
|
|
252
|
+
|
|
253
|
+
Each workspace runs on an RSI bundle chosen by the backend (`global-base-v1.0` until the org has its own). The bundle
|
|
254
|
+
can add short usage hints to tool descriptions, so how agents use Harmony can improve without a new release.
|
|
255
|
+
|
|
256
|
+
- When the agent connects, the server pins this session to a bundle (`POST /api/code-workspace/{id}/rsi/pin`) and
|
|
257
|
+
downloads it if it changed (`GET /api/rsi/bundles/{bundleId}`). The agent's first `tools/list` waits up to a second
|
|
258
|
+
for this, otherwise it uses the hints cached in `~/.harmony/cache/bundles/ws-<workspaceId>-manifest.json`.
|
|
259
|
+
- The tool list then stays the same for the whole session: no `tools/list_changed`. Tool definitions sit at the top of
|
|
260
|
+
the agent's prompt, so changing them mid-session would make it rewrite its prompt cache, which is the main cost of a
|
|
261
|
+
session. A newer bundle applies from the next session.
|
|
262
|
+
- Hints only add text to descriptions. Tool names, parameters and types never change, and `login`, `confirm_login`
|
|
263
|
+
and `setup_workspace` are never hinted.
|
|
264
|
+
- Every query call sends `X-Harmony-Client-Agent` (e.g. `claude-code`, `codex-cli`), `X-Harmony-Mcp-Version`,
|
|
265
|
+
`X-Rsi-Bundle-Id` (the pinned bundle), and the agent's own `traceparent`/`tracestate`/`baggage` when it puts them
|
|
266
|
+
in `params._meta`.
|
|
267
|
+
- After a successful `investigate`, `context_search`, `inspect_trace`, `preflight` or `security_audit` call, the
|
|
268
|
+
server records the backend's answer id (`X-Harmony-Ledger-Id`), the agent session and the agent process in
|
|
269
|
+
`~/.harmony/run/<repo-hash>.state`, so a later local search or edit can be linked back to that answer.
|
|
270
|
+
- The backend sends the bundle's workspace guidance once per session, not with every answer.
|
|
271
|
+
|
|
272
|
+
| Variable | Effect |
|
|
273
|
+
| :--- | :--- |
|
|
274
|
+
| `HARMONY_RSI_DISABLED=true` | No pinning, no hints, no bundle cache. |
|
|
275
|
+
| `HARMONY_RSI_BUNDLE_ID` | Ask the backend for this bundle instead of its default (also `rsiBundleId` in `.harmony_workspace.json`). |
|
|
276
|
+
| `HARMONY_RSI_FIRST_LIST_WAIT_MS` | How long the first `tools/list` waits for the startup bundle pin (default 1000). |
|
|
277
|
+
| `HARMONY_HOME` | Root for local RSI state (default `~/.harmony`). Directories are created `0700`, files `0600`. |
|
|
278
|
+
|
|
279
|
+
## Set up every installed agent (`harmony-mcp setup-agents`)
|
|
280
|
+
|
|
281
|
+
```bash
|
|
282
|
+
npx -y @codeconductorai/harmony-mcp@1.0.34 setup-agents # all detected agents, user scope
|
|
283
|
+
npx -y @codeconductorai/harmony-mcp@1.0.34 setup-agents --dry-run # show what would change
|
|
284
|
+
npx -y @codeconductorai/harmony-mcp@1.0.34 setup-agents --uninstall
|
|
285
|
+
```
|
|
286
|
+
|
|
287
|
+
It finds the coding agents on this machine, adds the Harmony MCP server where it is missing, and installs the async
|
|
288
|
+
tool hooks described below. At the end it prints a table of what each agent now has.
|
|
289
|
+
|
|
290
|
+
| Agent | MCP server | Tool hooks |
|
|
291
|
+
| :--- | :--- | :--- |
|
|
292
|
+
| Claude Code | `claude mcp add` (skipped if any Harmony server already exists in any scope) | `~/.claude/settings.json` |
|
|
293
|
+
| OpenAI Codex | `~/.codex/config.toml` | `~/.codex/hooks.json`, or `config.toml` if it already has inline `[hooks]` |
|
|
294
|
+
| Cursor | `~/.cursor/mcp.json` | `~/.cursor/hooks.json` |
|
|
295
|
+
| Gemini CLI / Antigravity | `~/.gemini/settings.json` | `~/.gemini/settings.json` |
|
|
296
|
+
| GitHub Copilot CLI | `~/.copilot/mcp-config.json` | `~/.copilot/hooks/harmony-rsi.json` |
|
|
297
|
+
| OpenCode | `~/.config/opencode/opencode.json` | pending |
|
|
298
|
+
| Windsurf, Amazon Q | their `mcp*.json` | not supported yet |
|
|
299
|
+
| Cline, Amp, Aider, Continue, Goose, Zed, Junie, Factory | manual instructions | not supported yet |
|
|
300
|
+
|
|
301
|
+
- **Safe edits:** comments, formatting and your own hooks and servers are kept. Existing Harmony entries are updated
|
|
302
|
+
in place, never duplicated. Each file is backed up once to `<file>.harmony-bak`. Files that don't parse are left
|
|
303
|
+
untouched and reported.
|
|
304
|
+
- **Hook launcher:** hooks run `~/.harmony/bin/harmony-mcp`, a small launcher with an absolute path, so GUI agents with
|
|
305
|
+
a minimal `PATH` can still find it.
|
|
306
|
+
- **`--scope project`:** writes hooks into the repo (`.claude/`, `.cursor/`, `.gemini/`, `.github/hooks/`) using a
|
|
307
|
+
portable `npx` command.
|
|
308
|
+
- **`--uninstall`:** removes only Harmony's hooks, its own hook files and the launcher. MCP server entries stay.
|
|
309
|
+
- **`--agents a,b`:** picks agents explicitly; `--hooks-only` and `--mcp-only` limit what is added.
|
|
310
|
+
|
|
311
|
+
## Health check (`harmony-mcp doctor`)
|
|
208
312
|
|
|
209
313
|
```bash
|
|
210
|
-
|
|
211
|
-
|
|
314
|
+
npx -y @codeconductorai/harmony-mcp@1.0.34 doctor # run inside the repo
|
|
315
|
+
npx -y @codeconductorai/harmony-mcp@1.0.34 doctor --json # machine-readable
|
|
316
|
+
npx -y @codeconductorai/harmony-mcp@1.0.34 doctor --offline # local checks only
|
|
212
317
|
```
|
|
213
318
|
|
|
319
|
+
It checks, in order:
|
|
320
|
+
- **Install:** the version and the hook launcher.
|
|
321
|
+
- **Workspace:** whether the repo is set up, and which backend it is bound to.
|
|
322
|
+
- **Credentials:** login and workspace-token expiry. Tokens are never printed.
|
|
323
|
+
- **Backend:** whether it can be reached, how fast, and the index status.
|
|
324
|
+
- **RSI:** the pinned bundle, its tool hints and documents, and the telemetry key (only its id is shown).
|
|
325
|
+
- **Agent hooks:** which agents have them.
|
|
326
|
+
- **Hook telemetry:** the spool backlog, the last Harmony call, and hook errors in the last 24 h.
|
|
327
|
+
- **Value:** the organisation's token and time savings, from `/api/rsi/outcomes/summary`.
|
|
328
|
+
|
|
329
|
+
Every warning or failure comes with the command that fixes it, and the exit code is 1 if anything failed. Doctor
|
|
330
|
+
only talks to the backend the repo is bound to, or to `API_URL` if set; it never guesses one. Use
|
|
331
|
+
`--rotate-telemetry-key` to get a new hook-signing key; the old one keeps working for 24 h.
|
|
332
|
+
|
|
333
|
+
## Managed workspace instructions (`harmony-mcp sync-workspace`)
|
|
334
|
+
|
|
335
|
+
```bash
|
|
336
|
+
npx -y @codeconductorai/harmony-mcp@1.0.34 sync-workspace # current repo
|
|
337
|
+
npx -y @codeconductorai/harmony-mcp@1.0.34 sync-workspace --create-if-missing # also create AGENTS.md
|
|
338
|
+
npx -y @codeconductorai/harmony-mcp@1.0.34 sync-workspace --remove # take Harmony's text out again
|
|
339
|
+
```
|
|
340
|
+
|
|
341
|
+
It pulls the workspace's RSI bundle from the backend this repo is bound to (`~/.harmony/workspaces.json`, written by
|
|
342
|
+
the MCP server; there is no default endpoint) and writes:
|
|
343
|
+
|
|
344
|
+
- **AGENTS.md:** Harmony's evolved routing guidance, inside
|
|
345
|
+
`<!-- HARMONY:BEGIN bundle="…" sha256="…" --> … <!-- HARMONY:END -->`. This also goes in **CLAUDE.md** if the repo
|
|
346
|
+
has one. Text outside the markers is never changed.
|
|
347
|
+
- If the bundle and hash match, the file isn't rewritten, so build watchers don't fire.
|
|
348
|
+
- A `BEGIN` without an `END` makes it skip that file and warn.
|
|
349
|
+
- AGENTS.md is only created with `--create-if-missing`.
|
|
350
|
+
- **`.harmony/workspace-world-model.md`:** architectural facts about the workspace. The `.harmony/` folder ignores
|
|
351
|
+
itself in git. The same text is offered as the MCP resource `harmony://workspace/world-model`.
|
|
352
|
+
|
|
353
|
+
The MCP server does the same at startup, but only for blocks that already exist; it never adds one. Turn that off
|
|
354
|
+
with `HARMONY_SYNC_WORKSPACE=false`. If the backend can't be reached, the last cached bundle is used.
|
|
355
|
+
|
|
356
|
+
## Tool hooks (`harmony-mcp hook-event`)
|
|
357
|
+
|
|
358
|
+
An optional agent hook reports, without content, when the agent searched, read, edited or built locally instead of
|
|
359
|
+
asking Harmony. It helps Harmony learn where its answers fall short. `setup-agents` installs it (pointing at the
|
|
360
|
+
`~/.harmony/bin/harmony-mcp` launcher). To configure it by hand for Claude Code, add this to `~/.claude/settings.json`:
|
|
361
|
+
|
|
362
|
+
```json
|
|
363
|
+
{
|
|
364
|
+
"hooks": {
|
|
365
|
+
"PostToolUse": [{ "matcher": "Bash|Grep|Glob|Read|Edit|MultiEdit|Write|NotebookEdit",
|
|
366
|
+
"hooks": [{ "type": "command", "command": "npx -y @codeconductorai/harmony-mcp@1.0.34 hook-event --agent claude-code", "async": true, "timeout": 5 }] }],
|
|
367
|
+
"PostToolUseFailure": [{ "matcher": "Bash",
|
|
368
|
+
"hooks": [{ "type": "command", "command": "npx -y @codeconductorai/harmony-mcp@1.0.34 hook-event --agent claude-code --event PostToolUseFailure", "async": true, "timeout": 5 }] }],
|
|
369
|
+
"PreCompact": [{
|
|
370
|
+
"hooks": [{ "type": "command", "command": "npx -y @codeconductorai/harmony-mcp@1.0.34 hook-event --agent claude-code --event PreCompact", "async": true, "timeout": 5 }] }]
|
|
371
|
+
}
|
|
372
|
+
}
|
|
373
|
+
```
|
|
374
|
+
|
|
375
|
+
For Codex, `setup-agents` adds `PostToolUse`, `PreCompact` and `SessionStart` hooks to `~/.codex/hooks.json` (or to
|
|
376
|
+
`config.toml` if it already has inline `[hooks]`). Codex runs new hooks only after you trust them once in `/hooks`.
|
|
377
|
+
Shell commands are read from both Codex's normal shell tool and its code-mode `exec` tool.
|
|
378
|
+
|
|
379
|
+
How an action is linked to an answer:
|
|
380
|
+
|
|
381
|
+
- **Workspace:** taken from the command's working directory, or from absolute paths in it, so hooks fired from
|
|
382
|
+
another directory still find the repo. Only repos listed in `~/.harmony/workspaces.json` are reported.
|
|
383
|
+
- **Answer:** the last Harmony answer for that repo, recorded at most 15 minutes earlier, **from the same agent
|
|
384
|
+
session**. Actions in one Claude or Codex session are never linked to another session's answers. Nested agents
|
|
385
|
+
link through the nearest real `claude`/`codex` process, not an inherited one.
|
|
386
|
+
- With no matching answer the action is still sent, without a link; the backend counts it as work done without
|
|
387
|
+
Harmony.
|
|
388
|
+
|
|
389
|
+
Supported `--agent` values: `claude-code`, `codex`, `cursor`, `antigravity`, `copilot`, `opencode`, `kilo-code`.
|
|
390
|
+
|
|
391
|
+
What is sent: the kind of action (`SEARCH`, `READ`, `EDIT`, `BUILD`, `COMPACT`), the tool name, repo-relative paths, a
|
|
392
|
+
line span, an exit code, the SHA-256 of an edited file, and for searches only the shape of the pattern (an identifier
|
|
393
|
+
as-is, or the word tokens of a regex; anything that looks like a credential becomes `<REDACTED>`). It also links to
|
|
394
|
+
the Harmony request that came just before. Tool output, file contents, patch hunks, command arguments, and paths
|
|
395
|
+
outside the repo are never sent.
|
|
396
|
+
|
|
397
|
+
- The hook never writes to stdout, always exits 0, and waits at most 450 ms for the backend.
|
|
398
|
+
- It sends only for repos that the MCP server has bound to a backend in `~/.harmony/workspaces.json`, and only to
|
|
399
|
+
that backend.
|
|
400
|
+
- Each request is signed with `~/.harmony/telemetry.key` (`X-Harmony-Hook-Signature`). The MCP server fetches the
|
|
401
|
+
key from the backend.
|
|
402
|
+
- Events are sent only with your user login (from the `login` tool), never the workspace token, because the
|
|
403
|
+
signing key and the stored events belong to you and your organisation.
|
|
404
|
+
- When the key, a valid login, or the backend is missing, events wait in `~/.harmony/spool/` (at most 2 MiB; oldest
|
|
405
|
+
dropped first). The MCP server sends them on connect, every 5 minutes, and when the agent exits.
|
|
406
|
+
- Problems are logged to `~/.harmony/logs/harmony-mcp.log` (set `HARMONY_HOOK_DEBUG=true` for one line per event).
|
|
407
|
+
`HARMONY_RSI_DISABLED=true` turns the hook off.
|
|
408
|
+
|
|
214
409
|
## Session id
|
|
215
410
|
|
|
216
411
|
Every request carries an `X-Mcp-Session-Id` header. Harmony keeps per-session state under it: handles such as
|
|
@@ -231,7 +426,7 @@ To follow `/clear` and compaction in Claude Code, add this `SessionStart` hook t
|
|
|
231
426
|
{
|
|
232
427
|
"hooks": {
|
|
233
428
|
"SessionStart": [
|
|
234
|
-
{ "hooks": [{ "type": "command", "command": "npx -y @codeconductorai/harmony-mcp --session-hook" }] }
|
|
429
|
+
{ "hooks": [{ "type": "command", "command": "npx -y @codeconductorai/harmony-mcp@1.0.34 --session-hook" }] }
|
|
235
430
|
]
|
|
236
431
|
}
|
|
237
432
|
}
|
|
@@ -244,7 +439,7 @@ they run):
|
|
|
244
439
|
{
|
|
245
440
|
"hooks": {
|
|
246
441
|
"SessionStart": [
|
|
247
|
-
{ "hooks": [{ "type": "command", "command": "npx -y @codeconductorai/harmony-mcp --session-hook" }] }
|
|
442
|
+
{ "hooks": [{ "type": "command", "command": "npx -y @codeconductorai/harmony-mcp@1.0.34 --session-hook" }] }
|
|
248
443
|
]
|
|
249
444
|
}
|
|
250
445
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@codeconductorai/harmony-mcp",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.34",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"main": "src/index.js",
|
|
6
6
|
"bin": {
|
|
@@ -14,7 +14,8 @@
|
|
|
14
14
|
},
|
|
15
15
|
"scripts": {
|
|
16
16
|
"start": "node src/index.js",
|
|
17
|
-
"start:stdio": "node src/index.js"
|
|
17
|
+
"start:stdio": "node src/index.js",
|
|
18
|
+
"test": "node --test test/"
|
|
18
19
|
},
|
|
19
20
|
"keywords": [
|
|
20
21
|
"mcp",
|
|
@@ -43,6 +44,7 @@
|
|
|
43
44
|
"archiver": "^7.0.0",
|
|
44
45
|
"form-data": "^4.0.0",
|
|
45
46
|
"jose": "^6.2.3",
|
|
47
|
+
"jsonc-parser": "^3.3.1",
|
|
46
48
|
"minimatch": "^5.1.0",
|
|
47
49
|
"node-fetch": "^3.3.2"
|
|
48
50
|
}
|
|
@@ -2,8 +2,8 @@ import fs from "fs";
|
|
|
2
2
|
import os from "os";
|
|
3
3
|
import path from "path";
|
|
4
4
|
|
|
5
|
-
import { log } from "
|
|
6
|
-
import { tracedFetch as fetch } from "
|
|
5
|
+
import { log } from "../observability/log.js";
|
|
6
|
+
import { tracedFetch as fetch } from "../observability/telemetry.js";
|
|
7
7
|
|
|
8
8
|
export const API_URL = (process.env.API_URL || "https://harmony.codeconductor.ai/").replace(/\/+$/, "");
|
|
9
9
|
|
|
@@ -1,28 +1,66 @@
|
|
|
1
1
|
import fs from "fs";
|
|
2
2
|
import path from "path";
|
|
3
3
|
import crypto from "crypto";
|
|
4
|
+
import { createRequire } from "module";
|
|
4
5
|
import archiver from "archiver";
|
|
5
6
|
import FormData from "form-data";
|
|
6
7
|
|
|
7
|
-
import { log } from "
|
|
8
|
-
import { currentSessionId } from "
|
|
9
|
-
import { tracedFetch as fetch, getActiveTraceId } from "
|
|
8
|
+
import { log } from "../observability/log.js";
|
|
9
|
+
import { currentSessionId, sessionIdSource } from "../session/sessionIdentity.js";
|
|
10
|
+
import { tracedFetch as fetch, getActiveTraceId } from "../observability/telemetry.js";
|
|
10
11
|
import {
|
|
11
12
|
getSessionToken,
|
|
12
13
|
getWorkspaceToken,
|
|
13
14
|
getWorkspaceRefreshToken,
|
|
14
15
|
saveWorkspaceToken,
|
|
15
16
|
isJwtExpired,
|
|
16
|
-
} from "
|
|
17
|
-
import { buildWorkspaceMetadata, PRODUCT_ID, APP_ID, REPO_ID } from "
|
|
18
|
-
import { readMarker, writeMarker } from "
|
|
19
|
-
import { getGitCommitHash } from "
|
|
20
|
-
import { buildZipIgnoreGlobs } from "
|
|
17
|
+
} from "../auth/deviceAuth.js";
|
|
18
|
+
import { buildWorkspaceMetadata, PRODUCT_ID, APP_ID, REPO_ID } from "../workspace/workspaceIdentity.js";
|
|
19
|
+
import { readMarker, writeMarker } from "../workspace/workspaceMarker.js";
|
|
20
|
+
import { getGitCommitHash } from "../workspace/repoIdentity.js";
|
|
21
|
+
import { buildZipIgnoreGlobs } from "../workspace/fileFilters.js";
|
|
22
|
+
import { currentCallContext } from "../rsi/callContext.js";
|
|
23
|
+
import { activeBundleIdFor, requestedBundleId } from "../rsi/bundleHints.js";
|
|
24
|
+
import { recordCausalState } from "../rsi/causalState.js";
|
|
25
|
+
|
|
26
|
+
const MCP_VERSION = createRequire(import.meta.url)("../../package.json").version;
|
|
21
27
|
|
|
22
28
|
export const API_URL = (process.env.API_URL || "https://harmony.codeconductor.ai/").replace(/\/+$/, "");
|
|
23
29
|
|
|
24
|
-
|
|
25
|
-
|
|
30
|
+
// Session and RSI headers sent on every workspace call (RSI wire contract §1.1): which agent session this is,
|
|
31
|
+
// which agent and MCP version made it, which RSI bundle the session runs on, and the agent's own W3C trace
|
|
32
|
+
// context when it sent one (tracedFetch replaces traceparent with a child span's when OTel export is on).
|
|
33
|
+
function sessionHeader(workspaceId) {
|
|
34
|
+
const ctx = currentCallContext();
|
|
35
|
+
const headers = {
|
|
36
|
+
"X-Mcp-Session-Id": currentSessionId(),
|
|
37
|
+
"X-Harmony-Client-Agent": ctx.clientAgent,
|
|
38
|
+
"X-Harmony-Mcp-Version": MCP_VERSION,
|
|
39
|
+
...ctx.trace,
|
|
40
|
+
};
|
|
41
|
+
// An explicitly requested bundle wins from the very first call: the backend pins a session on its first request,
|
|
42
|
+
// and a cached id from an earlier session (or none) would pin the wrong bundle while the startup pin is in flight.
|
|
43
|
+
const bundleId = requestedBundleId(readMarker()) || activeBundleIdFor(workspaceId);
|
|
44
|
+
if (bundleId) headers["X-Rsi-Bundle-Id"] = bundleId;
|
|
45
|
+
return headers;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
// After a 200 from a query endpoint, record it as the parent for the next local tool hook. Never fails the call.
|
|
49
|
+
function noteBackendResponse(endpointPath, response, workspaceId) {
|
|
50
|
+
try {
|
|
51
|
+
recordCausalState({
|
|
52
|
+
endpointPath,
|
|
53
|
+
workspaceId,
|
|
54
|
+
mcpSessionId: currentSessionId(),
|
|
55
|
+
sessionSource: sessionIdSource(),
|
|
56
|
+
clientAgent: currentCallContext().clientAgent,
|
|
57
|
+
ledgerId: response.headers.get("x-harmony-ledger-id"),
|
|
58
|
+
traceId: response.headers.get("x-trace-id") || getActiveTraceId(),
|
|
59
|
+
bundleId: response.headers.get("x-harmony-bundle-id") || activeBundleIdFor(workspaceId),
|
|
60
|
+
});
|
|
61
|
+
} catch (error) {
|
|
62
|
+
log(`[rsi] could not write causal state: ${error.message}`);
|
|
63
|
+
}
|
|
26
64
|
}
|
|
27
65
|
|
|
28
66
|
async function refreshWorkspaceToken(workspaceId, refreshToken) {
|
|
@@ -42,7 +80,7 @@ async function refreshWorkspaceToken(workspaceId, refreshToken) {
|
|
|
42
80
|
return newAccessToken;
|
|
43
81
|
}
|
|
44
82
|
|
|
45
|
-
async function resolveToken(workspaceId) {
|
|
83
|
+
export async function resolveToken(workspaceId) {
|
|
46
84
|
const sessionToken = await getSessionToken();
|
|
47
85
|
if (sessionToken) return sessionToken;
|
|
48
86
|
|
|
@@ -342,7 +380,7 @@ export async function callHarmonySearchEndpoint(endpointPath, args, workspaceId)
|
|
|
342
380
|
headers: {
|
|
343
381
|
"Content-Type": "application/json",
|
|
344
382
|
Accept: "application/xml",
|
|
345
|
-
...sessionHeader(),
|
|
383
|
+
...sessionHeader(workspaceId),
|
|
346
384
|
...(await authHeader(workspaceId)),
|
|
347
385
|
},
|
|
348
386
|
body: JSON.stringify(requestBody),
|
|
@@ -351,6 +389,7 @@ export async function callHarmonySearchEndpoint(endpointPath, args, workspaceId)
|
|
|
351
389
|
if (!response.ok) {
|
|
352
390
|
throw new Error(`${endpointPath} request failed: ${response.status} ${body}${traceSuffix()}`);
|
|
353
391
|
}
|
|
392
|
+
noteBackendResponse(endpointPath, response, workspaceId);
|
|
354
393
|
return body;
|
|
355
394
|
}
|
|
356
395
|
|
|
@@ -364,7 +403,7 @@ async function callHarmonyJsonEndpoint(endpointPath, requestBody, workspaceId, a
|
|
|
364
403
|
headers: {
|
|
365
404
|
"Content-Type": "application/json",
|
|
366
405
|
Accept: accept,
|
|
367
|
-
...sessionHeader(),
|
|
406
|
+
...sessionHeader(workspaceId),
|
|
368
407
|
...(await authHeader(workspaceId)),
|
|
369
408
|
},
|
|
370
409
|
body: JSON.stringify(requestBody),
|
|
@@ -373,6 +412,7 @@ async function callHarmonyJsonEndpoint(endpointPath, requestBody, workspaceId, a
|
|
|
373
412
|
if (!response.ok) {
|
|
374
413
|
throw new Error(`${endpointPath} request failed: ${response.status} ${body}${traceSuffix()}`);
|
|
375
414
|
}
|
|
415
|
+
noteBackendResponse(endpointPath, response, workspaceId);
|
|
376
416
|
return body;
|
|
377
417
|
}
|
|
378
418
|
|
|
@@ -534,3 +574,133 @@ export async function sendFileDelete(filePath, workspaceId) {
|
|
|
534
574
|
return { ok: false, status: null, body: error.message };
|
|
535
575
|
}
|
|
536
576
|
}
|
|
577
|
+
|
|
578
|
+
// ---- RSI bundle (RSI MCP spec §4.4, against the backend's RsiController). ----
|
|
579
|
+
const RSI_REQUEST_TIMEOUT_MS = 5_000;
|
|
580
|
+
|
|
581
|
+
// Statuses meaning "this backend has no RSI for us" rather than a failure worth logging loudly.
|
|
582
|
+
const RSI_UNSUPPORTED_STATUSES = new Set([401, 403, 404, 405, 501]);
|
|
583
|
+
|
|
584
|
+
// POST /api/code-workspace/{workspaceId}/rsi/pin — pins this session to a bundle (the requested one, else the
|
|
585
|
+
// backend's choice) and returns its id. null when the backend has no RSI support or the call fails.
|
|
586
|
+
export async function callRsiPin(workspaceId, requestedBundleId) {
|
|
587
|
+
try {
|
|
588
|
+
const response = await fetch(`${API_URL}/api/code-workspace/${workspaceId}/rsi/pin`, {
|
|
589
|
+
method: "POST",
|
|
590
|
+
headers: {
|
|
591
|
+
"Content-Type": "application/json",
|
|
592
|
+
Accept: "application/json",
|
|
593
|
+
...sessionHeader(workspaceId),
|
|
594
|
+
...(await authHeader(workspaceId)),
|
|
595
|
+
},
|
|
596
|
+
body: JSON.stringify(requestedBundleId ? { bundleId: requestedBundleId } : {}),
|
|
597
|
+
signal: AbortSignal.timeout(RSI_REQUEST_TIMEOUT_MS),
|
|
598
|
+
});
|
|
599
|
+
if (!response.ok) {
|
|
600
|
+
if (!RSI_UNSUPPORTED_STATUSES.has(response.status)) log(`[rsi] pin failed: HTTP ${response.status}${traceSuffix()}`);
|
|
601
|
+
return null;
|
|
602
|
+
}
|
|
603
|
+
const json = await response.json();
|
|
604
|
+
return typeof json?.pinnedBundleId === "string" && json.pinnedBundleId ? json.pinnedBundleId : null;
|
|
605
|
+
} catch (error) {
|
|
606
|
+
log(`[rsi] pin failed: ${error.message}`);
|
|
607
|
+
return null;
|
|
608
|
+
}
|
|
609
|
+
}
|
|
610
|
+
|
|
611
|
+
// GET /api/rsi/bundles/{bundleId} — the bundle's tool hints and managed instructions. Throws on failure.
|
|
612
|
+
export async function fetchRsiBundle(workspaceId, bundleId) {
|
|
613
|
+
const response = await fetch(`${API_URL}/api/rsi/bundles/${encodeURIComponent(bundleId)}`, {
|
|
614
|
+
method: "GET",
|
|
615
|
+
headers: { Accept: "application/json", ...sessionHeader(workspaceId), ...(await authHeader(workspaceId)) },
|
|
616
|
+
signal: AbortSignal.timeout(RSI_REQUEST_TIMEOUT_MS),
|
|
617
|
+
});
|
|
618
|
+
if (!response.ok) throw new Error(`RSI bundle ${bundleId} fetch failed: HTTP ${response.status}${traceSuffix()}`);
|
|
619
|
+
return response.json();
|
|
620
|
+
}
|
|
621
|
+
|
|
622
|
+
// RSI telemetry (key, tool events) is keyed per (org, user), and only a user login identifies both: the backend
|
|
623
|
+
// treats a workspace token as the workspace id in org 1. So telemetry uses the user login only, never the
|
|
624
|
+
// workspace token. null when nobody is logged in.
|
|
625
|
+
export async function resolveUserToken() {
|
|
626
|
+
try {
|
|
627
|
+
return (await getSessionToken()) || null;
|
|
628
|
+
} catch {
|
|
629
|
+
return null;
|
|
630
|
+
}
|
|
631
|
+
}
|
|
632
|
+
|
|
633
|
+
// POST /api/code-workspace/{workspaceId}/rsi/telemetry-key (wire contract §4) — the HMAC key for tool-events.
|
|
634
|
+
// Returns the 64-hex key, or null when nobody is logged in or the backend does not issue keys. Never logs the key.
|
|
635
|
+
export async function fetchTelemetryKeyHex(workspaceId, { rotate = false } = {}) {
|
|
636
|
+
const userToken = await resolveUserToken();
|
|
637
|
+
if (!userToken) return null;
|
|
638
|
+
try {
|
|
639
|
+
const response = await fetch(`${API_URL}/api/code-workspace/${workspaceId}/rsi/telemetry-key`, {
|
|
640
|
+
method: "POST",
|
|
641
|
+
headers: {
|
|
642
|
+
"Content-Type": "application/json",
|
|
643
|
+
Accept: "application/json",
|
|
644
|
+
...sessionHeader(workspaceId),
|
|
645
|
+
Authorization: `Bearer ${userToken}`,
|
|
646
|
+
},
|
|
647
|
+
body: JSON.stringify(rotate ? { rotate: true } : {}),
|
|
648
|
+
signal: AbortSignal.timeout(RSI_REQUEST_TIMEOUT_MS),
|
|
649
|
+
});
|
|
650
|
+
if (!response.ok) {
|
|
651
|
+
if (!RSI_UNSUPPORTED_STATUSES.has(response.status) && response.status !== 503) {
|
|
652
|
+
log(`[rsi] telemetry key request failed: HTTP ${response.status}${traceSuffix()}`);
|
|
653
|
+
}
|
|
654
|
+
return null;
|
|
655
|
+
}
|
|
656
|
+
const json = await response.json();
|
|
657
|
+
return typeof json?.telemetryKeyHex === "string" && /^[0-9a-f]{64}$/.test(json.telemetryKeyHex) ? json.telemetryKeyHex : null;
|
|
658
|
+
} catch (error) {
|
|
659
|
+
log(`[rsi] telemetry key request failed: ${error.message}`);
|
|
660
|
+
return null;
|
|
661
|
+
}
|
|
662
|
+
}
|
|
663
|
+
|
|
664
|
+
// ---- Diagnostics (harmony-mcp doctor). Never throws; never returns tokens. ----
|
|
665
|
+
|
|
666
|
+
// One request with a short timeout: { ok, status, ms, json, text, error }. status null = backend unreachable.
|
|
667
|
+
// userAuth: send only the user login (RSI telemetry endpoints; see resolveUserToken).
|
|
668
|
+
export async function probeBackend(pathAndQuery, { method = "GET", body, workspaceId, timeoutMs = 3_000, auth = true, userAuth = false } = {}) {
|
|
669
|
+
const startedAt = Date.now();
|
|
670
|
+
try {
|
|
671
|
+
let authHeaders = {};
|
|
672
|
+
if (userAuth) {
|
|
673
|
+
const userToken = await resolveUserToken();
|
|
674
|
+
if (!userToken) return { ok: false, status: null, ms: 0, error: "not logged in (telemetry needs a user login, not the workspace token)" };
|
|
675
|
+
authHeaders = { Authorization: `Bearer ${userToken}` };
|
|
676
|
+
} else if (auth) {
|
|
677
|
+
authHeaders = await authHeader(workspaceId);
|
|
678
|
+
}
|
|
679
|
+
const response = await fetch(`${API_URL}${pathAndQuery}`, {
|
|
680
|
+
method,
|
|
681
|
+
headers: {
|
|
682
|
+
Accept: "application/json, application/xml;q=0.9, */*;q=0.8",
|
|
683
|
+
...(body !== undefined ? { "Content-Type": "application/json" } : {}),
|
|
684
|
+
...sessionHeader(workspaceId),
|
|
685
|
+
...authHeaders,
|
|
686
|
+
},
|
|
687
|
+
body: body === undefined ? undefined : JSON.stringify(body),
|
|
688
|
+
signal: AbortSignal.timeout(timeoutMs),
|
|
689
|
+
});
|
|
690
|
+
const text = await response.text();
|
|
691
|
+
let json = null;
|
|
692
|
+
try {
|
|
693
|
+
json = JSON.parse(text);
|
|
694
|
+
} catch {
|
|
695
|
+
// not JSON
|
|
696
|
+
}
|
|
697
|
+
return { ok: response.ok, status: response.status, ms: Date.now() - startedAt, json, text: text.slice(0, 2_000) };
|
|
698
|
+
} catch (error) {
|
|
699
|
+
return { ok: false, status: null, ms: Date.now() - startedAt, error: error?.name === "TimeoutError" ? "timed out" : error?.message };
|
|
700
|
+
}
|
|
701
|
+
}
|
|
702
|
+
|
|
703
|
+
export function workspaceStatusPath(workspaceId) {
|
|
704
|
+
const params = new URLSearchParams({ productId: PRODUCT_ID, appId: APP_ID, repoId: REPO_ID });
|
|
705
|
+
return `/api/code-workspace/${workspaceId}/status?${params}`;
|
|
706
|
+
}
|