O3: task sources and result sinks (#11)

This commit was merged in pull request #11.
This commit is contained in:
hermes committed 2026-11-12 23:25:08 +00:00
1 parent 2f79b69977
commit afafc41376
10 files changed
+594 -76

No files matched your search

+55
View File
@@ -0,0 +1,55 @@
# `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), 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.
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).
+45
View File
@@ -0,0 +1,45 @@
{
"$schema": "https://json-schema.org/draft/2020-12/schema",
"title": "orch cmd adapter protocol",
"$defs": {
"Task": {
"type": "object",
"required": ["id", "title", "body"],
"properties": {
"id": {"type": "string", "minLength": 1},
"title": {"type": "string"},
"body": {"type": "string"},
"repo": {"type": "string", "description": "local clone path"}
},
"additionalProperties": true
},
"Run": {
"type": "object",
"required": ["id", "status", "branch", "repo"],
"properties": {
"id": {"type": "string"},
"status": {"enum": ["queued", "running", "gating", "done", "failed", "needs-human"]},
"reason": {"type": ["string", "null"]},
"branch": {"type": "string"},
"repo": {"type": "string"},
"worktree": {"type": "string"},
"attempts": {"type": "integer"},
"input_tokens": {"type": "integer"},
"output_tokens": {"type": "integer"},
"published": {"type": ["string", "null"]}
}
}
},
"oneOf": [
{"title": "list: stdin", "type": "object", "maxProperties": 0},
{"title": "list: stdout", "type": "object", "required": ["tasks"],
"properties": {"tasks": {"type": "array", "items": {"$ref": "#/$defs/Task"}}}},
{"title": "claim: stdin", "type": "object", "required": ["task"],
"properties": {"task": {"$ref": "#/$defs/Task"}}},
{"title": "claim: stdout", "type": "object", "required": ["claimed"],
"properties": {"claimed": {"type": "boolean"}}},
{"title": "report/publish: stdin", "type": "object", "required": ["task", "run"],
"properties": {"task": {"$ref": "#/$defs/Task"}, "run": {"$ref": "#/$defs/Run"}}},
{"title": "publish: stdout", "type": "object", "properties": {"url": {"type": "string"}}}
]
}