MultiHarnessHub
by qhchen31
README.md
# MultiHarnessHub
[中文说明 (README.zh-CN.md)](./README.zh-CN.md) | [Agent Usage Guide (agent.md)](./agent.md)
**MultiHarnessHub** is a lightweight, local-only collaboration hub for Linux and Windows. It connects **Google Antigravity (`agy`)** and **OpenAI Codex (`codex`)** on both platforms, plus **DeepSeek Harness (`dsh`)** on Windows. On Linux, **Claude Code** can also connect as an MCP host and delegate to Codex or Antigravity.
| Platform | MCP hosts and `--caller` values | Delegation targets |
| --- | --- | --- |
| [Linux](#local-setup-on-linux) | Antigravity (`agy`), Codex (`codex`), Claude Code (`claude`) | `agy`, `codex` |
| [Windows 11](#local-setup-on-windows-11) | Antigravity (`agy`), Codex (`codex`), DeepSeek Harness (`dsh`) | `agy`, `codex`, `dsh` |
---
## Why This Exists (In Plain Terms)
If you use more than one AI coding assistant on the same computer, connecting them with one-off wrapper scripts usually breaks down in three ways:
1. **No memory**: Every call starts a fresh blank chat, so you cannot pick up an existing conversation you already had in another app's GUI.
2. **Slow repeated startup**: Spawning a full CLI process on every question adds 10–15+ seconds of cold-start overhead.
3. **Safety & cleanup headaches**: Sub-agents can accidentally call back into each other in a loop, edit files without asking, or leave zombie background processes behind if something crashes.
**MultiHarnessHub** solves this with a **star-shaped local hub**: every AI assistant connects to one shared local background service (using the standard **MCP** tool interface), and the hub manages persistent sessions, concurrency, permissions, and process cleanup underneath.
---
## What Is Implemented
- **Dynamic Orchestrator-Worker**: A connected MCP host can delegate to the native workers available on its platform, either one-to-one or in **parallel broadcast**.
- **Native Session Discovery & Resume**: Browse existing historical conversations from each app (`hub_list_sessions`), resume them directly, and keep new turns saved in each app's own history so you can inspect or take over in the desktop GUI later.
- **Warm On-Demand Background Service (Mode 1)**: Starts automatically when your first assistant connects, stays warm so follow-up questions avoid repeated cold starts, and shuts down cleanly after idle timeout when all assistants disconnect.
- **Safety First**:
- **Read-only by default**. Codex and DSH enforce read-only mode through their native sandboxes. Antigravity provides best-effort read-only behavior. Native approval requests are surfaced to the MCP host.
- **OS-level recursion & orphan protection**: Windows uses Job Objects. Linux uses a systemd user service and per-worker cgroups with credential-checked Unix sockets. These isolate worker lifecycles, clean up descendants after daemon exit or failure, and reject recursive Hub calls from workers.
- **Directory allowlist**. Hub sessions require a working directory under `allowed_roots`. Workspace access within the worker is governed by its native sandbox.
- **Lightweight Read-Only Web Observer**: A local `127.0.0.1` web page (protected by a 5-minute one-time login code) showing online/busy status, main-sub conversation logs, one-click native resume commands, and `.jsonl` / `.md` log export (with 30-day automatic cleanup).
- **Minimal Footprint**: Single TypeScript/Node 26 repo with only 4 runtime dependencies (`@modelcontextprotocol/sdk`, `@agentclientprotocol/sdk`, `koffi`, `yaml`) and Node's built-in `node:sqlite`.
---
## Local Setup on Linux
### 1. Prerequisites and build
Use Node.js `>=26.13.1 <27` and a regular login session with a running systemd user manager and delegated cgroup v2 with `cgroup.kill`. The migration was exercised on Ubuntu 22.04 x86-64 with kernel 5.15 and systemd 249, using Codex `0.171.0-alpha.13.2` and Antigravity `1.5.12`. Install and sign in to the native workers you need. Codex needs a `0.171.x` executable with `app-server`. Antigravity needs `agy acp` with `--sandbox` and `--process-per-session`.
Run from the checkout as the same Linux user who runs the MCP hosts. The filesystem check should print `cgroup2fs`.
```sh
node --version
systemctl --user is-system-running
stat -fc %T /sys/fs/cgroup
npm ci
npm run build
```
### 2. Configure allowed workspaces
Create `~/.multi-harness-hub/config.json` with absolute Linux paths. Use `chmod 700 ~/.multi-harness-hub` and `chmod 600 ~/.multi-harness-hub/config.json` after creating them.
```json
{
"allowed_roots": ["/home/you/Documents/writing-project"],
"max_permission": "manual-approval",
"idle_timeout_ms": 1200000
}
```
The Hub checks `PATH` and then `/usr/lib/chatgpt/resources/codex` or `~/.local/bin/agy`. Set absolute `codex_exe` or `agy_exe` paths when discovery needs an override. `MHH_CODEX_EXE` and `MHH_AGY_EXE` take precedence when set in the environment of the host that starts the daemon. If you use `--runtime` for a separate instance, give its hosts and token command the same absolute runtime path. Linux uses its own local state and native session histories.
### 3. Register the MCP server
Replace the example paths with the absolute paths to Node and your checkout. Use the same compiled shim for each host.
- **Codex**. Add this entry to `~/.codex/config.toml` (or `config.toml` under `CODEX_HOME` if set). As a CLI alternative, run `codex mcp add multi-harness-hub -- /absolute/path/to/node /absolute/path/to/HarnessHub/dist/src/mcp-shim/main.js --caller codex`. Check the result with `codex mcp get multi-harness-hub`.
```toml
[mcp_servers.multi-harness-hub]
command = "/absolute/path/to/node"
args = ["/absolute/path/to/HarnessHub/dist/src/mcp-shim/main.js", "--caller", "codex"]
tool_timeout_sec = 310
```
- **Antigravity**. Merge this example into the existing `mcpServers` object in `~/.gemini/config/mcp_config.json`. Check the CLI registration with `agy mcp list`.
```json
{
"mcpServers": {
"multi-harness-hub": {
"command": "/absolute/path/to/node",
"args": ["/absolute/path/to/HarnessHub/dist/src/mcp-shim/main.js", "--caller", "agy"],
"timeoutSeconds": 310
}
}
}
```
- **Claude Code**. Register it as a host with `--caller claude`. Use `--scope local` for a project-specific entry.
```sh
claude mcp add --transport stdio --scope user multi-harness-hub -- \
/absolute/path/to/node /absolute/path/to/HarnessHub/dist/src/mcp-shim/main.js --caller claude
claude mcp get multi-harness-hub
```
Check `/mcp` in a fresh Claude Code session. The Linux migration verified the `claude` caller through the shim. Native Claude Code client acceptance is pending.
### 4. Verify the connection
1. Reload MCP or open a fresh host session. Confirm the server exposes seven tools and call `hub_list_harnesses`. Linux should list `agy` and `codex`. The call starts available workers on demand.
2. Open a different harness with `hub_open_session`, an allowed absolute `working_dir`, and `permission: "read-only"`. Send a short prompt with `hub_send`, use `hub_wait` if the turn is still running, then release the session with `hub_control` and `action: "close"`. Aim for async send and polling when the host timeout is shorter than the desired wait.
3. On an Antigravity build that reports unknown occupancy, confirm the native conversation is idle before using `force_resume: true`. Linux Antigravity workers are reused per workspace so native history records the authorized folder.
If a worker is offline, check its executable, version and sign-in. For startup failures, check the systemd user manager and the unit journal from the same user's login session. The cgroup guard supervises managed descendants. Processes with unrestricted access as the same Linux user share access to that user's systemd session.
```sh
systemctl --user is-system-running
journalctl --user -u 'multi-harness-hub-*.service' -n 40
```
## Local Setup on Windows 11
### 1. Prerequisites
- **Windows 11** (x64)
- **Node.js `>= 26.13.1 < 27`** (uses built-in `node:sqlite`)
- One or more supported local assistants installed:
- **Antigravity (`agy`)** with `agy acp --sandbox --process-per-session` (tested with `1.5.18`)
- **OpenAI Codex Desktop** (WindowsApps executable on the `0.171.x` protocol line, with `codex app-server`)
- **DeepSeek Harness (`dsh`)** (Desktop app with `--profile acp`; OpenRouter models configured in DSH Desktop are auto-discovered)
### 2. Install & Build
Run in PowerShell from the repository root (use `npm.cmd` on Windows if PowerShell script execution policy blocks `npm.ps1`):
```powershell
npm.cmd ci
npm.cmd run build
```
### 3. Configure Allowed Folders
Create `%USERPROFILE%\.multi-harness-hub\config.json` and list the project directories you want sub-agents to access:
```json
{
"allowed_roots": [
"E:\\Project",
"C:\\Users\\<YourUser>\\Downloads"
],
"max_permission": "allow-all",
"idle_timeout_ms": 1200000
}
```
- `allowed_roots` (**required for real tasks**): Absolute folder paths sub-agents are allowed to work in.
- `max_permission` (optional): `"allow-all"` (default) or `"manual-approval"` (hard ceiling preventing agents from switching to auto-approve).
- `idle_timeout_ms` (optional): How long the hub stays warm after all assistants disconnect.
- Set `codex_exe` or `agy_exe` to an absolute executable path to override auto-discovery. `MHH_CODEX_EXE` and `MHH_AGY_EXE` take precedence when set in the environment of the host that starts the daemon.
- Set `web_port` to a fixed loopback port or leave it at `0` for automatic selection.
### 4. Connect Your AI Assistants (MCP Config)
Point each assistant's MCP server configuration to the same compiled shim, changing only `--caller <agy|codex|dsh>`:
- **Antigravity** (`~/.gemini/config/mcp_config.json`):
```json
{
"mcpServers": {
"multi-harness-hub": {
"command": "C:/Program Files/nodejs/node.exe",
"args": ["E:/Project/MultiHarnessHub/dist/src/mcp-shim/main.js", "--caller", "agy"],
"timeoutSeconds": 600
}
}
}
```
- **Codex** (`~/.codex/config.toml`):
```toml
[mcp_servers.multi-harness-hub]
command = "C:/Program Files/nodejs/node.exe"
args = ["E:/Project/MultiHarnessHub/dist/src/mcp-shim/main.js", "--caller", "codex"]
tool_timeout_sec = 600
```
- **DeepSeek Harness (DSH)**: Register the same `node.exe` command with `["E:/Project/MultiHarnessHub/dist/src/mcp-shim/main.js", "--caller", "dsh"]` in your `desktop` profile only (keep `profiles/acp/` clean).
Reload MCP or open a fresh host session. Check that the server exposes seven tools and that `hub_list_harnesses` lists `agy`, `codex`, and `dsh`. Workers that are installed and ready should report `online: true`. The [agent guide](agent.md#1-the-7-mcp-tools) covers individual tool arguments.
---
## Viewing Logs in the Read-Only Web Panel
While at least one assistant is connected to the hub, run `npm run web:token` on Linux or the following in Windows PowerShell.
```powershell
npm.cmd run web:token
```
It prints a local `http://127.0.0.1:<port>` URL and a **5-minute single-use login code**. Open the URL in your browser and paste the code to view live status, inspect prompts/replies, copy native resume commands, or export `.jsonl` / `.md` logs.
From outside the checkout, run `web-token.sh` on Linux or `web-token.cmd` on Windows by absolute path with Node available on `PATH`. For a custom Hub runtime, pass the same `--runtime <absolute-path>` to the token command.
---
## Verification & Project Layout
On Linux, run these from a regular user session with the systemd user bus available.
```sh
npm run test:phase1
npm run test:edge -- dist/test/web.test.js
npm run smoke:p2
npm run smoke:p1 -- --discover agy
npm run smoke:p1 -- --full
```
The full smoke sends short live prompts to the native harnesses. The deterministic suite and Web smoke use synthetic data. On Windows, run the corresponding commands in PowerShell.
```powershell
npm.cmd run test:phase1 # Core deterministic tests (zero LLM cost)
npm.cmd run test:edge -- dist/test/web.test.js # Web security & 30-day retention tests
npm.cmd run smoke:p2 # Read-only Web panel HTTP smoke test
npm.cmd run smoke:p1 -- --full # Live smoke across Codex, AGY and DSH
```
- `src/daemon/` — Local hub daemon, Mode 1 lifecycle, SQLite store, session leases, task & approval state machine
- `src/mcp-shim/` — Thin MCP stdio entrypoint and 7 frozen tool schemas
- `src/adapters/` — `CodexAdapter` (`codex app-server`), `AgyAcpAdapter` (`agy acp`), `DshAcpAdapter` (`dsh --profile acp`)
- `src/platform/` — Linux Unix sockets, per-worker cgroups and systemd startup, plus Windows pipes, election and Job Objects
- `src/web/` — Authenticated read-only local observer panel
- `agent.md` — Concise operational instructions for AI agents using the hub
- `docs/` — Local, Git-ignored architecture report and Phase 1–2 SOP & acceptance records
This server cannot be deployed
Maintenance
ActivityMaintained
ResponsivenessNo recent community issues