codex-dsh-bridge
by ironessi
README.md
# codex-dsh-bridge
**Let OpenAI Codex hand real tasks to DeepSeek Harness (DSH) — and watch everything DSH is doing.**
Codex can start a DSH task, wait for it or poll it, continue the *same* DSH session with
follow-ups, list the DSH sessions it can resume, and cancel running work. Since v1.1.0 it
also sees sessions **you** start in the DSH desktop app: titles, live state, per-session
turn/tool counters and an event tail. Every task runs inside a genuine, persisted DSH
session, so it shows up in the DSH GUI, can use DSH tools with DSH approvals, and
survives restarts.
[](https://github.com/ironessi/codex-dsh_plugin/actions/workflows/ci.yml)
[](https://github.com/ironessi/codex-dsh_plugin/releases)
[](LICENSE)
[](https://nodejs.org)
English · [简体中文](README.zh-CN.md)
```mermaid
flowchart LR
subgraph Codex["OpenAI Codex"]
A[Agent] --> B["MCP tools<br/>dsh_run_task / dsh_task / …"]
end
B -- "stdio (MCP)" --> C["codex-dsh-bridge<br/>Codex plugin · zero-dependency MCP server"]
C -- "HTTP + Bearer token<br/>127.0.0.1 only" --> D["dsh-codex-bridge<br/>DSH Host plugin"]
D -- "ctx.agents.create / resume<br/>+ session observation" --> E["Real DSH sessions<br/>(bridge tasks and GUI-started work)"]
```
## Why a bridge plugin
DSH authenticates its own Web/API surface with a token that only ever lives inside the
running DSH host process — the desktop shell receives the ready URL over IPC, and nothing
outside that process can mint the URL again. So an external agent cannot simply call the
DSH Web API. The bridge closes that gap from the inside:
- the **DSH Host plugin** runs a small loopback HTTP server, writes `~/.dsh/codex-bridge.json`
(`url` + random `token`), and drives real sessions through the DSH `agents` service;
- the **Codex plugin** reads that discovery file and exposes MCP tools that proxy to it.
No DSH token is ever copied into Codex, and nothing is exposed outside `127.0.0.1`.
## Install
Two halves, both required.
### 1. DSH side (the Host plugin)
Install `dsh-host-plugin/` into your DSH profile:
- **GUI**: DSH → Plugins → **Add plugin** → choose the `dsh-host-plugin` directory, then restart DSH.
- **Agent-assisted**: ask a DSH agent to call
`plugin_manager install_bundle` with the absolute path of `dsh-host-plugin/`, then reload/restart DSH.
After DSH starts, check that the bridge is alive:
```powershell
Get-Content $env:USERPROFILE\.dsh\codex-bridge.json
Invoke-RestMethod http://127.0.0.1:45871/health
# ok service=dsh-codex-bridge version=1.3.0 port=45871
```
### 2. Codex side (the plugin)
```powershell
cd <this repo>
powershell.exe -NoProfile -ExecutionPolicy Bypass -File .\install.ps1
```
The installer (idempotent):
1. copies `codex-plugin/` into `%USERPROFILE%\.codex\local-marketplaces\dsh-local\plugins\codex-dsh-bridge\`
and writes an absolute-path `.mcp.json`;
2. registers the local marketplace at `…\dsh-local\.agents\plugins\marketplace.json`;
3. updates `%USERPROFILE%\.codex\config.toml` (backup first) with `[marketplaces.dsh-local]`,
`[plugins."codex-dsh-bridge@dsh-local"] enabled = true` and a compatibility
`[mcp_servers.dsh]` entry;
4. copies `skills/dsh-tasks` into `%USERPROFILE%\.codex\skills\`.
Then **fully quit Codex (tray included) and relaunch**, and confirm:
```powershell
codex mcp list
# dsh C:\Program Files\nodejs\node.exe …\server\index.mjs enabled
```
Ask Codex: *"check the DSH bridge with dsh_status"* — you should see
`DSH bridge dsh-codex-bridge v1.3.1 — ok on port 45871`.
Uninstall Codex side: `powershell.exe -NoProfile -ExecutionPolicy Bypass -File .\uninstall.ps1`
## Usage
Just talk to Codex, or name the tools explicitly:
> Run the test suite in `C:\work\project` with DSH and summarize the failures.
> Start a long refactor in DSH, don't wait — poll it while I keep working here.
> Continue the DSH task you started: now also update the changelog.
> Which DSH sessions can you resume for this workspace?
> What is running in DSH right now? Watch the `train-v3` session and tell me when it finishes.
> Cancel the stuck session in `C:\work\project`.
## Seeing everything in DSH, not just bridge tasks
Since v1.1.0 the DSH-side plugin observes **every** session in the DSH process — including
the ones *you* start in the DSH desktop app. That closes the usual blind spot: Codex no
longer only sees tasks it started itself. Since v1.3.0 it also reads DSH's **managed job ledger**, so
background work that outlives the tool call — training runs, dev servers, detached shell jobs — stays
visible with its live status, progress line and output tail.
| MCP tool | What it does |
| --- | --- |
| `dsh_run_task` | Start a DSH task (new session, or an existing resumable `session_id`); `wait` until it finishes or `timeout_seconds` elapses |
| `dsh_send_task` | Fire-and-forget variant of `dsh_run_task` |
| `dsh_task` | Fetch one task, optionally waiting; returns assistant output + tool trail |
| `dsh_task_list` | List tasks known to the bridge |
| `dsh_continue_task` | Send a follow-up instruction to the **same** DSH session |
| `dsh_cancel_task` | Cancel a running task |
| `dsh_sessions` | List **all** DSH sessions (`running: true` for live ones) with title, cwd, live state, turn/tool counters and last activity |
| `dsh_session` | Read one session by id — GUI-started or bridge-started — optionally blocking while it runs |
| `dsh_session_events` | Cheap event tail of one session (turn starts/ends, tool calls/results, approvals, errors) for progress polling |
| `dsh_cancel_session` | Cancel the live turn of any session by id |
| `dsh_jobs` | List DSH **managed jobs** (live `running` / `stopping`, plus finished ones), optionally per session |
| `dsh_job` | One managed job: status, progress, detail and output tail |
| `dsh_job_cancel` | Stop a managed job |
| `dsh_watch` | Add / list / remove a **background watch** over a file (with `progress` = rows / JSON length / regex) and/or a process, for work DSH did not wrap in a managed job |
| `dsh_status` / `dsh_health` | Connectivity check, default model, task counts, currently running sessions |
Task results contain: state (`starting` / `running` / `completed` / `error` / `cancelled`
/ `interrupted`), session id, model, turn count, tool calls with args/result previews,
`waiting_for_approval` and idle duration.
Sessions that are not running any more are read back from the DSH session log, so
`dsh_session` still returns their title and last answer — the "what was that experiment
doing?" case works after the fact too.
### Background work: session idle does not mean it stopped
A DSH session going `idle` only means its turn ended; a job it started keeps running.
Since v1.3.0 the bridge subscribes to DSH's job registry and to the `job/registered` /
`job/settled` session events, so `dsh_jobs` answers "is it still running" from the job
ledger instead of from the session state:
- `dsh_jobs {session_id: "session-…", live: true}` — live jobs of one session
- `dsh_job {job_id: "pwsh-…"}` — status, progress, detail, and the tail of job output
- `dsh_job_cancel {job_id: "pwsh-…"}` — stop it from Codex
For detached work that is **not** a managed job, use `dsh_watch`. It reports three separate
facts and never merges them into a guess:
- **process** — `matched` (a pid or command line is alive; a pid is only accepted when its
creation time matches, so a recycled pid cannot fake liveness), `not_found`, `unavailable`
(the query itself failed — absence then means nothing) or `not_configured`;
- **file** — size, `updated_at`, and `progress`, computed as `{kind: "lines", skip: 1}` for a
JSONL checkpoint (`rows` = lines − skip), `{kind: "json_rows", key?}` for a JSON array/object,
or `{kind: "regex", regex: "(\d+/\d+)"}` for a log line. Mixed-encoding logs (Windows
PowerShell UTF-16LE, cmd/GBK, Python UTF-8 appended into one file) are decoded from their BOM
and a NUL-byte sniff instead of assuming UTF-8;
- **verdict** — `alive` only when a matching process is confirmed; `active_but_unconfirmed` when
files moved but liveness is unproven; `unconfirmed` otherwise. A *quiet* file or a missing
process is reported as `quiet`/`unknown` with an explicit "this alone does not prove it
stopped", never as "stopped".
Manual watches have **no start-time restriction**, so you can attach one to an experiment that
has been running for hours; only the watches auto-created from a `Start-Process`/`nohup`
launch are bounded by that launch. Limit worth knowing: the job ledger covers work DSH itself
launched — every shell tool call is a job, so short foreground commands show up too. A process
started outside DSH, or a script whose launcher exited, is not in the ledger; give that one a
`dsh_watch` on its log/checkpoint and process.
## HTTP API (DSH Host plugin)
All routes require `Authorization: Bearer <token>` except `/health`.
| Method | Path | Description |
| --- | --- | --- |
| GET | `/health` | Unauthenticated liveness probe (`ok`, `version`, `port`) |
| GET | `/v1/status` | Bridge version, port, default model, task counts |
| GET | `/v1/tasks?limit=50` | Task list (newest first) |
| POST | `/v1/tasks?wait=1&timeout_seconds=…` | Create and run a task |
| GET | `/v1/tasks/:id?wait=1&timeout_seconds=…` | Task detail / wait for terminal state (accepts a `session-…` id too) |
| POST | `/v1/tasks/:id/continue` | Follow-up instruction in the same session |
| POST | `/v1/tasks/:id/cancel` | Cancel the task |
| GET | `/v1/sessions?cwd=…&running=1&text=1&tail=20&limit=30` | All DSH sessions: live state, title, counters, optional event tail |
| GET | `/v1/sessions/:id?wait=1&timeout_seconds=…&text=1&tail=20` | One session (any origin); blocks while running when `wait=1` |
| POST | `/v1/sessions/:id/cancel` | Cancel the live turn of any session |
| GET | `/v1/jobs?session=…&live=1&limit=50` | Managed DSH jobs, live first |
| GET | `/v1/jobs/:id` | One job: status, progress, output tail |
| POST | `/v1/jobs/:id/cancel` | Stop a job |
| GET | `/v1/watches` | Background watches with live state |
| POST | `/v1/watches` | Add a watch (`name`, `files`, `progress_regex`, `process`, `stale_seconds`, `session_id`) |
| GET \| DELETE | `/v1/watches/:id` | Read or remove one watch |
`POST /v1/tasks` body:
```jsonc
{
"prompt": "Run the tests and summarize failures", // or "message"
"cwd": "C:\\work\\project", // workspace, default = plugin defaultCwd
"session_id": "session-…", // optional: resume an existing session
"title": "nightly tests", // optional label
"preset": "default", // optional DSH agent preset id
"model": "deepseek-flash", // optional, default = DSH default-model
"reasoning_effort": "high", // optional
"auto_approve": false, // default false
"wait": true,
"timeout_seconds": 120
}
```
## Security
- The bridge listens on **127.0.0.1 only** and authenticates with a random 32-byte token,
compared in constant time. The token + URL live in `~/.dsh/codex-bridge.json`.
- `auto_approve` defaults to **false**: any tool that needs approval parks the task in
`waiting_for_approval` and you approve it in the DSH GUI, like any other DSH session.
Set `auto_approve: true` only for automations you explicitly trust.
- When the DSH plugin is disabled or reloaded, agents it created are cancelled and disposed;
reloading rotates the token, and the Codex side re-discovers it automatically.
## Compatibility
| Piece | Requirement |
| --- | --- |
| Codex | Desktop build with local marketplaces + MCP support (tested on 26.1120 / CLI 0.110.0). This build has **no `codex plugin` CLI**, hence the file-based install. |
| DSH | `>= 0.2.2-rc.2` (desktop profile tested) |
| Node.js | `>= 18` (the MCP server uses only built-ins) |
| OS | Windows 10/11 (PowerShell 5.1 or 7). The DSH host plugin itself is OS-agnostic. |
## Troubleshooting
| Symptom | Fix |
| --- | --- |
| `dsh_health` says "no discovery file was found" | The DSH Host plugin is not installed/enabled, or DSH was not restarted. Check `~/.dsh/codex-bridge.json`. |
| `401 unauthorized` | Discovery file is stale (DSH reloaded). The server re-reads it automatically; restart Codex if it persists. |
| `unclosed table, expected ]` in `config.toml` | Your PowerShell 5.1 wrote a BOM or re-encoded non-ASCII paths. Restore the `config.toml.bak-*` backup; `install.ps1` now reads/writes UTF-8 without BOM. |
| Tools not visible in Codex | Restart Codex Desktop (tray included). The running session does not hot-reload MCP servers. |
| `The '<model>' model is not supported when using Codex with a ChatGPT account` | Codex CLI model/account mismatch — unrelated to this plugin. Pick a model your account can use, or use the desktop app. |
## Development
```powershell
npm test # offline MCP protocol tests (node --test, no DSH needed)
node scripts\e2e-bridge.cjs # end-to-end against the running DSH bridge (creates a real session)
node scripts\e2e-async.cjs # async / continue / cancel flows
node scripts\e2e-session-observe.cjs # live + historical session observation, cancel by session id
node scripts\e2e-watch.mjs # background watch over a detached process + progress file
node scripts\e2e-jobs.mjs # managed DSH jobs: live state, detail, cancel
node scripts\mcp-smoke.mjs <abs path to codex-plugin\server\index.mjs>
```
Layout:
```
codex-plugin/ Codex side: portable plugin.json, .codex-plugin/plugin.json,
mcp.json + .mcp.json, skills/dsh-tasks/SKILL.md, server/index.mjs
dsh-host-plugin/ DSH side: cordis.patch.yml, index.js (loopback HTTP + agent runtime)
scripts/ manual end-to-end probes
tests/ offline MCP protocol tests
install.ps1 install Codex plugin + config
uninstall.ps1 remove them again
```
## Releases
| Version | Date | Highlights |
| --- | --- | --- |
| [v1.3.1](https://github.com/ironessi/codex-dsh_plugin/releases/tag/v1.3.1) | 2026-12-04 | Truthful watches: manual watches have no start-time limit, checkpoint progress (`lines` / `json_rows` / `regex`), encoding-robust log decoding, `alive` / `active_but_unconfirmed` / `unconfirmed` verdicts — quiet files no longer read as "stopped" |
| [v1.3.0](https://github.com/ironessi/codex-dsh_plugin/releases/tag/v1.3.0) | 2026-12-03 | DSH **managed jobs**: `dsh_jobs` / `dsh_job` / `dsh_job_cancel` with live status, progress and output tail — a session going idle no longer looks like stopped work |
| [v1.1.0](https://github.com/ironessi/codex-dsh_plugin/releases/tag/v1.1.0) | 2026-12-03 | See **every** DSH session: `dsh_sessions` / `dsh_session` / `dsh_session_events` / `dsh_cancel_session`, live state + titles + counters for GUI-started work |
| [v1.0.2](https://github.com/ironessi/codex-dsh_plugin/releases/tag/v1.0.2) | 2026-12-02 | Idempotent `config.toml` registration (`lib/codex-config.ps1`), installer regression test |
| [v1.0.1](https://github.com/ironessi/codex-dsh_plugin/releases/tag/v1.0.1) | 2026-12-02 | Session create-fallback, UTF-8-without-BOM install scripts, Chinese/English docs |
| [v1.0.0](https://github.com/ironessi/codex-dsh_plugin/releases/tag/v1.0.0) | 2026-12-02 | First public release: DSH Host bridge + Codex MCP plugin + installers |
See the [full changelog](CHANGELOG.md) for details.
## Roadmap
- [x] observe sessions started directly in the DSH desktop app (v1.1.0)
- [x] follow DSH managed jobs and file/process watches for background work (v1.3.0)
- [ ] one-click install through `codex plugin` / a Codex UI marketplace entry, once that surface ships
- [ ] `dsh_task` streaming notifications so Codex can react to progress instead of polling
- [ ] per-task token scoping and an audit log
- [ ] macOS / Linux installer script
## Related
- [Model Context Protocol](https://modelcontextprotocol.io) — the stdio transport Codex uses to reach this plugin
- [Agent Plugins 1.0](https://agent-plugins.org) — the portable `plugin.json` / `mcp.json` specification this plugin follows
- DeepSeek Harness (DSH) — the local agent runtime the bridge drives
## License
MIT — see [LICENSE](LICENSE). Contributions welcome; see [CONTRIBUTING.md](CONTRIBUTING.md).
This server cannot be deployed
Maintenance
ActivityMaintained
ResponsivenessNo recent community issues