diff --git a/README.md b/README.md index b9ffe7bc..6c60e7c2 100644 --- a/README.md +++ b/README.md @@ -812,6 +812,8 @@ REST over Fastify — **~190 handlers across 20 route modules**, plus an SSE str | `POST` | `/api/clipboard` | Push text to all connected browsers (`{text}`) | | `GET` | `/api/sessions/:id/run-summary` | Timeline + stats | +> **Building something on top of Codeman?** [`docs/extending-codeman.md`](docs/extending-codeman.md) is the integration guide: render your own UI as a tab, subscribe to the SSE event stream to react when an agent needs you, drive Codeman from a script, and the traps worth knowing before you start. Codeman has no plugin runtime on purpose, so an integration is just your own process talking HTTP. + --- ## Architecture diff --git a/README.zh-CN.md b/README.zh-CN.md index dce47137..d310a1f7 100644 --- a/README.zh-CN.md +++ b/README.zh-CN.md @@ -802,6 +802,8 @@ Codeman 会注册 Claude Code hook,它们 `POST /api/hook-event`(`permission | `POST` | `/api/clipboard` | 把文本推送到所有已连接浏览器(`{text}`) | | `GET` | `/api/sessions/:id/run-summary` | 时间线 + 统计 | +> **想在 Codeman 之上做集成?**[`docs/extending-codeman.md`](docs/extending-codeman.md)(英文)是集成指南:把你自己的界面作为标签页嵌入、订阅 SSE 事件流以便在 agent 需要你时做出响应、用脚本驱动 Codeman,以及动手前值得先了解的那些坑。Codeman 刻意不提供插件运行时,所以一个集成就是你自己的进程在讲 HTTP。 + --- ## 架构 diff --git a/docs/extending-codeman.md b/docs/extending-codeman.md index 24f95e58..9e2b3dee 100644 --- a/docs/extending-codeman.md +++ b/docs/extending-codeman.md @@ -40,6 +40,17 @@ curl -u admin:$CODEMAN_PASSWORD http://127.0.0.1:3000/api/v1/sessions or `body.success`, then read `body.data`. The full `errorCode` to status mapping is in [`api-reference.md`](api-reference.md). +⚠️ A few legacy GETs (`/api/away-digest` among them) return a bare-ish body with +the payload at the top level rather than under `data`. Read defensively with +`body.data ?? body`. + +**Already driving Codeman from an agent?** The README's +[Programmatic Guide](../README.md#driving-codeman-from-an-agent--programmatic-guide) +covers the in-session case: the `CODEMAN_MUX`, `CODEMAN_API_URL`, +`CODEMAN_SESSION_ID` and `CODEMAN_HOOK_SECRET_FILE` variables that let a CLI +running inside Codeman find the API and avoid acting on itself. This page is for +code running *outside* a session. + ## Seam 1: Web tabs The highest-leverage seam. Any web app you can serve locally becomes a tab beside @@ -156,12 +167,17 @@ curl -u admin:$PASS -X POST http://127.0.0.1:3000/api/v1/sessions \ -H 'Content-Type: application/json' \ -d '{"workingDir":"/home/me/project","mode":"claude"}' -# Send a prompt (single-line only, "\r" submits) +# Send a prompt (single-line only) curl -u admin:$PASS -X POST http://127.0.0.1:3000/api/v1/sessions/$ID/input \ -H 'Content-Type: application/json' \ - -d '{"input":"run the tests","useScreen":true}' + -d '{"input":"run the tests","useMux":true}' ``` +`POST .../input` also accepts `clientId` (stable per client, max 128 chars) and +`seq` (monotonic per session). Send both and the server applies each pair +at-most-once, so retrying after a dropped connection cannot type the prompt +twice. Omit them entirely rather than sending `null`. + For shell scripting, the `codeman` CLI is the same surface without the HTTP plumbing: @@ -205,8 +221,10 @@ Every one of these has cost somebody real time. shipped bugs more than once. - **`text/plain` bodies stay raw.** Auto-parsing them as JSON enabled simple-request CSRF, so it is deliberate. Send `application/json`. -- **Prompts are single-line.** Input is delivered as text plus a separate Enter; - a multi-line string breaks the agent's input handling. Send `\r` to submit. +- **Prompts are single-line.** With `useMux: true` the server delivers your text + and then Enter as two separate writes, so you do not append `\r` yourself. A + multi-line string breaks the agent's Ink-based input handling: send one line, + or split it across calls. - **Unwrap the envelope** before reading fields. `data` is not the response body. ## Publishing your integration