Files
orch/docs/cmd-protocol.md
T
johannesandClaude Opus 5.5 5a80bc9fe1 Update README, add markdownlint and lychee via devenv
- README: list all subcommands, document orch session --resume, name the
  example machines, drop the missing ORCHESTRATOR.md reference
- Add markdownlint-cli and lychee to devenv.nix
- Add .markdownlint.json and .markdownlintignore; fix table lint errors in
  docs/safety.md and docs/cmd-protocol.md

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-14 15:27:18 +01:00

59 lines
2.7 KiB
Markdown

# `cmd` adapter protocol
A `cmd` adapter is any executable. orch runs `COMMAND OP` (COMMAND is split on whitespace, OP is appended),
writes one JSON object to stdin, and expects one JSON object on stdout and exit code 0. Anything else
(non-zero exit, non-JSON stdout, no answer within 120 s) is an adapter error. stderr is passed through.
Profile:
```toml
repo = "/work/myrepo" # default repo for tasks without `repo`
[source]
kind = "cmd"
command = "python3 /path/to/adapter.py"
[sink]
kind = "cmd" # or "local-branch" (default)
command = "python3 /path/to/adapter.py"
```
Schema: [`cmd-protocol.schema.json`](cmd-protocol.schema.json).
## Task
`{"id", "title", "body", "repo"?, ...}`. `id` is unique per source and becomes the run and branch name (orch
sanitizes it). `repo` is a local clone path. Every other field is adapter-private (issue number, URL, ...) and
is echoed back verbatim in later calls, so adapters stay stateless.
## Operations
| op | stdin | stdout |
| --- | --- | --- |
| `list` (source) | `{}` | `{"tasks": [Task, ...]}` |
| `claim` (source) | `{"task": Task}` | `{"claimed": bool}`; false = someone else took it, orch skips it |
| `report` (source) | `{"task": Task, "run": Run}` | `{}`; called when a run ends in any state |
| `publish` (sink) | `{"task": Task, "run": Run}` | `{"url": "..."}` (url optional); only for runs that ended `done` |
`Run`: `id, status (done|failed|needs-human|requeued), reason, branch, repo, worktree, attempts, input_tokens,
output_tokens, published`. The work is on local branch `branch` in `repo`; a sink pushes it and opens a PR/MR,
posts a comment, or whatever the host needs. Host credentials live in the adapter, never in orch.
`requeued` (provider quota used up) means the task was not attempted to completion: `report` should put it back in
the queue (the `dir` source does) so a later `pull` runs it again once the account's window resets.
A failing `publish` or `report` never fails the run: the error is printed and, for publish, stored in the run's
`published` field as `publish-failed: ...`.
## Built-ins
- source `dir`: `[source] kind = "dir"`, `path = "/tasks"`. Each `*.md` file is a task (first `#` heading = title,
rest = prompt). Claim moves it to `.running/`, report to `.done/` or `.failed/`.
- sink `local-branch`: nothing to publish, the branch stays in the local clone.
## Example
`examples/gitea_adapter.py`: source = open issues with label `orch`, claim swaps the label to `orch-running`,
report comments and sets `orch-done` / `orch-failed`, publish pushes the branch and opens a PR. Auth comes from
`git credential fill`. Env: `ORCH_GITEA_HOST`, `ORCH_GITEA_REPO` (`owner/name`), `ORCH_GITEA_CLONE` (local clone).