@codeconductorai/harmony-mcp 1.0.33 → 1.0.35
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 +217 -15
- package/package.json +4 -2
- package/src/{deviceAuth.js → auth/deviceAuth.js} +39 -8
- package/src/{harmonyClient.js → backend/harmonyClient.js} +183 -13
- package/src/doctor/doctorCommand.js +385 -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 +129 -0
- package/src/rsi/hooks/fileHash.js +33 -0
- package/src/rsi/hooks/hmacSigner.js +69 -0
- package/src/rsi/hooks/hookEventCommand.js +196 -0
- package/src/rsi/hooks/normalizers.js +329 -0
- package/src/rsi/hooks/offlineSpooler.js +142 -0
- package/src/rsi/hooks/secretScrubber.js +50 -0
- package/src/rsi/hooks/shellCommandScrubber.js +449 -0
- package/src/rsi/hooks/spoolDrainer.js +78 -0
- package/src/rsi/hooks/toolEventsClient.js +70 -0
- package/src/rsi/localState.js +53 -0
- package/src/rsi/serveTelemetry.js +101 -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.35`) 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.35 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.35`.
|
|
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.35"]
|
|
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.35 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.35` 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.35"]
|
|
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.35 --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.35"]
|
|
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.35"]
|
|
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.35 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.35 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,171 @@ 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.35 setup-agents # all detected agents, user scope
|
|
283
|
+
npx -y @codeconductorai/harmony-mcp@1.0.35 setup-agents --dry-run # show what would change
|
|
284
|
+
npx -y @codeconductorai/harmony-mcp@1.0.35 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.35 doctor # run inside the repo
|
|
315
|
+
npx -y @codeconductorai/harmony-mcp@1.0.35 doctor --json # machine-readable
|
|
316
|
+
npx -y @codeconductorai/harmony-mcp@1.0.35 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), including
|
|
325
|
+
whether this backend issued it.
|
|
326
|
+
- **Agent hooks:** which agents have them.
|
|
327
|
+
- **Hook telemetry:** the spool backlog, the last Harmony call, and hook errors in the last 24 h.
|
|
328
|
+
- **Value:** the organisation's token and time savings, from `/api/rsi/outcomes/summary`.
|
|
329
|
+
|
|
330
|
+
Every warning or failure comes with the command that fixes it, and the exit code is 1 if anything failed. Doctor
|
|
331
|
+
only talks to the backend the repo is bound to, or to `API_URL` if set; it never guesses one. Use
|
|
332
|
+
`--rotate-telemetry-key` to get a new hook-signing key; the old one keeps working for 24 h.
|
|
333
|
+
|
|
334
|
+
## Managed workspace instructions (`harmony-mcp sync-workspace`)
|
|
335
|
+
|
|
336
|
+
```bash
|
|
337
|
+
npx -y @codeconductorai/harmony-mcp@1.0.35 sync-workspace # current repo
|
|
338
|
+
npx -y @codeconductorai/harmony-mcp@1.0.35 sync-workspace --create-if-missing # also create AGENTS.md
|
|
339
|
+
npx -y @codeconductorai/harmony-mcp@1.0.35 sync-workspace --remove # take Harmony's text out again
|
|
340
|
+
```
|
|
341
|
+
|
|
342
|
+
It pulls the workspace's RSI bundle from the backend this repo is bound to (`~/.harmony/workspaces.json`, written by
|
|
343
|
+
the MCP server; there is no default endpoint) and writes:
|
|
344
|
+
|
|
345
|
+
- **AGENTS.md:** Harmony's evolved routing guidance, inside
|
|
346
|
+
`<!-- HARMONY:BEGIN bundle="…" sha256="…" --> … <!-- HARMONY:END -->`. This also goes in **CLAUDE.md** if the repo
|
|
347
|
+
has one. Text outside the markers is never changed.
|
|
348
|
+
- If the bundle and hash match, the file isn't rewritten, so build watchers don't fire.
|
|
349
|
+
- A `BEGIN` without an `END` makes it skip that file and warn.
|
|
350
|
+
- AGENTS.md is only created with `--create-if-missing`.
|
|
351
|
+
- **`.harmony/workspace-world-model.md`:** architectural facts about the workspace. The `.harmony/` folder ignores
|
|
352
|
+
itself in git. The same text is offered as the MCP resource `harmony://workspace/world-model`.
|
|
353
|
+
|
|
354
|
+
The MCP server does the same at startup, but only for blocks that already exist; it never adds one. Turn that off
|
|
355
|
+
with `HARMONY_SYNC_WORKSPACE=false`. If the backend can't be reached, the last cached bundle is used.
|
|
356
|
+
|
|
357
|
+
## Tool hooks (`harmony-mcp hook-event`)
|
|
358
|
+
|
|
359
|
+
An optional agent hook reports, without content, when the agent searched, read, edited or built locally instead of
|
|
360
|
+
asking Harmony. It helps Harmony learn where its answers fall short. `setup-agents` installs it (pointing at the
|
|
361
|
+
`~/.harmony/bin/harmony-mcp` launcher). To configure it by hand for Claude Code, add this to `~/.claude/settings.json`:
|
|
362
|
+
|
|
363
|
+
```json
|
|
364
|
+
{
|
|
365
|
+
"hooks": {
|
|
366
|
+
"PostToolUse": [{ "matcher": "Bash|Grep|Glob|Read|Edit|MultiEdit|Write|NotebookEdit",
|
|
367
|
+
"hooks": [{ "type": "command", "command": "npx -y @codeconductorai/harmony-mcp@1.0.35 hook-event --agent claude-code", "async": true, "timeout": 5 }] }],
|
|
368
|
+
"PostToolUseFailure": [{ "matcher": "Bash",
|
|
369
|
+
"hooks": [{ "type": "command", "command": "npx -y @codeconductorai/harmony-mcp@1.0.35 hook-event --agent claude-code --event PostToolUseFailure", "async": true, "timeout": 5 }] }],
|
|
370
|
+
"PreCompact": [{
|
|
371
|
+
"hooks": [{ "type": "command", "command": "npx -y @codeconductorai/harmony-mcp@1.0.35 hook-event --agent claude-code --event PreCompact", "async": true, "timeout": 5 }] }]
|
|
372
|
+
}
|
|
373
|
+
}
|
|
374
|
+
```
|
|
375
|
+
|
|
376
|
+
For Codex, `setup-agents` adds `PostToolUse`, `PreCompact` and `SessionStart` hooks to `~/.codex/hooks.json` (or to
|
|
377
|
+
`config.toml` if it already has inline `[hooks]`). Codex runs new hooks only after you trust them once in `/hooks`.
|
|
378
|
+
Shell commands are read from both Codex's normal shell tool and its code-mode `exec` tool.
|
|
379
|
+
|
|
380
|
+
How an action is linked to an answer:
|
|
381
|
+
|
|
382
|
+
- **Workspace:** taken from the command's working directory, or from absolute paths in it, so hooks fired from
|
|
383
|
+
another directory still find the repo. Only repos listed in `~/.harmony/workspaces.json` are reported.
|
|
384
|
+
- **Answer:** the last Harmony answer for that repo, recorded at most 15 minutes earlier, **from the same agent
|
|
385
|
+
session**. Actions in one Claude or Codex session are never linked to another session's answers. Nested agents
|
|
386
|
+
link through the nearest real `claude`/`codex` process, not an inherited one.
|
|
387
|
+
- With no matching answer the action is still sent, without a link; the backend counts it as work done without
|
|
388
|
+
Harmony.
|
|
389
|
+
|
|
390
|
+
Supported `--agent` values: `claude-code`, `codex`, `cursor`, `antigravity`, `copilot`, `opencode`, `kilo-code`.
|
|
391
|
+
|
|
392
|
+
What is sent: the kind of action (`SEARCH`, `READ`, `EDIT`, `BUILD`, `COMPACT`), the tool name, repo-relative paths, a
|
|
393
|
+
line span, an exit code, the SHA-256 of an edited file, and for searches only the shape of the pattern (an identifier
|
|
394
|
+
as-is, or the word tokens of a regex; anything that looks like a credential becomes `<REDACTED>`). It also links to
|
|
395
|
+
the Harmony request that came just before. Tool output, file contents, patch hunks, command arguments, and paths
|
|
396
|
+
outside the repo are never sent.
|
|
397
|
+
|
|
398
|
+
- The hook never writes to stdout, always exits 0, and waits at most 450 ms for the backend. A remote backend is
|
|
399
|
+
often slower than that (a new TLS connection alone can take over a second); the event is then queued and the MCP
|
|
400
|
+
server sends it, so nothing is lost and the agent is never slowed down.
|
|
401
|
+
- It sends only for repos that the MCP server has bound to a backend in `~/.harmony/workspaces.json`, and only to
|
|
402
|
+
that backend.
|
|
403
|
+
- Each request is signed with `~/.harmony/telemetry.key` (`X-Harmony-Hook-Signature`). The MCP server fetches the
|
|
404
|
+
key from the backend when it connects. Keys belong to the backend that issued them (recorded in
|
|
405
|
+
`~/.harmony/telemetry.key.endpoint`): after switching backends, for example from local to production, the old key
|
|
406
|
+
is not used and the server fetches the new backend's key.
|
|
407
|
+
- Events are sent only with your user login (from the `login` tool), never the workspace token, because the
|
|
408
|
+
signing key and the stored events belong to you and your organisation.
|
|
409
|
+
- When the key, a valid login, or the backend is missing or slow, events wait in `~/.harmony/spool/` (at most 2 MiB;
|
|
410
|
+
oldest dropped first). The MCP server sends them on connect and every minute, allowing 10 s per request
|
|
411
|
+
(`HARMONY_RSI_DRAIN_TIMEOUT_MS`), and tries once more when the agent exits. A queue file stays on disk until its
|
|
412
|
+
events are sent, so closing the agent mid-send never loses them; the backend drops duplicates.
|
|
413
|
+
- Problems are logged to `~/.harmony/logs/harmony-mcp.log` (set `HARMONY_HOOK_DEBUG=true` for one line per event).
|
|
414
|
+
`HARMONY_RSI_DISABLED=true` turns the hook off.
|
|
415
|
+
|
|
214
416
|
## Session id
|
|
215
417
|
|
|
216
418
|
Every request carries an `X-Mcp-Session-Id` header. Harmony keeps per-session state under it: handles such as
|
|
@@ -231,7 +433,7 @@ To follow `/clear` and compaction in Claude Code, add this `SessionStart` hook t
|
|
|
231
433
|
{
|
|
232
434
|
"hooks": {
|
|
233
435
|
"SessionStart": [
|
|
234
|
-
{ "hooks": [{ "type": "command", "command": "npx -y @codeconductorai/harmony-mcp --session-hook" }] }
|
|
436
|
+
{ "hooks": [{ "type": "command", "command": "npx -y @codeconductorai/harmony-mcp@1.0.35 --session-hook" }] }
|
|
235
437
|
]
|
|
236
438
|
}
|
|
237
439
|
}
|
|
@@ -244,7 +446,7 @@ they run):
|
|
|
244
446
|
{
|
|
245
447
|
"hooks": {
|
|
246
448
|
"SessionStart": [
|
|
247
|
-
{ "hooks": [{ "type": "command", "command": "npx -y @codeconductorai/harmony-mcp --session-hook" }] }
|
|
449
|
+
{ "hooks": [{ "type": "command", "command": "npx -y @codeconductorai/harmony-mcp@1.0.35 --session-hook" }] }
|
|
248
450
|
]
|
|
249
451
|
}
|
|
250
452
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@codeconductorai/harmony-mcp",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.35",
|
|
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
|
|
|
@@ -108,6 +108,14 @@ export async function initiateDeviceLogin() {
|
|
|
108
108
|
};
|
|
109
109
|
}
|
|
110
110
|
|
|
111
|
+
export function isTransientStatus(status) {
|
|
112
|
+
return status === 429 || (status >= 500 && status <= 599);
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
export function isTransientMessage(message) {
|
|
116
|
+
return typeof message === "string" && /<html|\b(429|50[0-4])\b|service unavailable|bad gateway|gateway time-?out|no server is available/i.test(message);
|
|
117
|
+
}
|
|
118
|
+
|
|
111
119
|
export async function pollDeviceLogin(timeoutSeconds = 300) {
|
|
112
120
|
if (!pendingDeviceCode) {
|
|
113
121
|
throw new Error("No pending login session. Call login first.");
|
|
@@ -121,18 +129,35 @@ export async function pollDeviceLogin(timeoutSeconds = 300) {
|
|
|
121
129
|
await sleep(intervalMs);
|
|
122
130
|
|
|
123
131
|
log(`[deviceAuth] pollDeviceLogin URL: ${API_URL}/api/apps/public/auth/confirm-login`);
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
132
|
+
let res;
|
|
133
|
+
try {
|
|
134
|
+
res = await fetch(`${API_URL}/api/apps/public/auth/confirm-login`, {
|
|
135
|
+
method: "POST",
|
|
136
|
+
headers: { "Content-Type": "application/json" },
|
|
137
|
+
body: JSON.stringify({ deviceCode, device_code: deviceCode }),
|
|
138
|
+
});
|
|
139
|
+
} catch (error) {
|
|
140
|
+
// Network blip: the device code is still valid, keep polling until the deadline.
|
|
141
|
+
log(`[deviceAuth] confirm-login unreachable, retrying: ${error.message}`);
|
|
142
|
+
continue;
|
|
143
|
+
}
|
|
129
144
|
|
|
130
145
|
if (!res.ok) {
|
|
131
146
|
const body = await res.text();
|
|
147
|
+
if (isTransientStatus(res.status)) {
|
|
148
|
+
log(`[deviceAuth] confirm-login HTTP ${res.status}, retrying`);
|
|
149
|
+
continue;
|
|
150
|
+
}
|
|
132
151
|
throw new Error(`confirm-login request failed (${res.status}): ${body}`);
|
|
133
152
|
}
|
|
134
153
|
|
|
135
|
-
|
|
154
|
+
let data;
|
|
155
|
+
try {
|
|
156
|
+
data = await res.json();
|
|
157
|
+
} catch {
|
|
158
|
+
log("[deviceAuth] confirm-login returned a non-JSON body, retrying");
|
|
159
|
+
continue;
|
|
160
|
+
}
|
|
136
161
|
const accessToken = field(data, "accessToken", "access_token");
|
|
137
162
|
const idToken = field(data, "idToken", "id_token");
|
|
138
163
|
const expiresIn = field(data, "expiresIn", "expires_in");
|
|
@@ -175,6 +200,12 @@ export async function pollDeviceLogin(timeoutSeconds = 300) {
|
|
|
175
200
|
throw new Error("Login session expired. Call login again to start a new one.");
|
|
176
201
|
}
|
|
177
202
|
|
|
203
|
+
// The backend relays upstream failures (a load balancer's 503 page, say) as a failed status; those pass.
|
|
204
|
+
if (isTransientMessage(data.message)) {
|
|
205
|
+
log("[deviceAuth] confirm-login reported a temporary upstream error, retrying");
|
|
206
|
+
continue;
|
|
207
|
+
}
|
|
208
|
+
|
|
178
209
|
throw new Error(`Login failed: ${data.message || "unknown error"}`);
|
|
179
210
|
}
|
|
180
211
|
|