Files
orch/README.md
T
Johannes KresnerandClaude Opus 5.5 20f88d88df
build / version (push) Successful in 1m20s
build / build (aarch64-apple-darwin) (push) Successful in 5m55s
build / build (x86_64-unknown-linux-musl) (push) Successful in 4m1s
build / release (push) Successful in 21s
feat: orch up starts issue sessions in existing worktrees
orch up MANIFEST reads an issue manifest (a path, or NAME in manifest_dir,
default <config>/manifests, set in <config>/config.toml) and starts one
detached session per listed worktree, across repos. Each worktree brings its
own machine, profile and .hx/task.md; the task text now reaches the agent.
Sessions live in <state>/issues.db; orch issues shows them grouped by issue.

Also: liveness checks use kill(pid, 0) instead of /proc (broken on macOS),
the same branch name in two repos no longer counts as the same place, and
the merge queue column ticket is renamed to issue (migrated on open).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-16 15:56:58 +01:00

146 lines
9.4 KiB
Markdown

# orch
Runs many [hx](https://git.jokresner.de/johannes/hx) coding agents on tasks, one git worktree each. Not tied to a
git host: tasks come from a folder or any JSON command, results go to a local branch or any JSON command.
orch run TASK.md --repo DIR --profile NAME one task
orch pull --profile NAME [--limit N] everything the profile's source lists, `workers` at a time
orch status [ID] orch logs ID runs and their raw logs
orch report [FILE] success rate, tokens, retries, duration per profile and hx version
orch bench eval --profile NAME --out A.jsonl run the eval cases; then: orch eval A.jsonl B.jsonl
orch audit [ID] every allowed/denied tool call
orch TUI: sessions, session detail, goal view
orch session --repo DIR --machine M --name N create a state-machine session and run it
[--profile P] [--after s1,s2] [--scope S]
orch session --repo DIR --resume sN continue an unfinished session from its saved state
orch session --repo DIR --restart sN continue a failed or escalated session where it stopped
orch goal [TEXT] [--export] show or set the goal (--export adds the checks)
orch check NAME CMD [--owner sN] add an acceptance check (pass = exit 0)
orch checks [--owner sN | --main] run acceptance checks here, or on a clean copy of main
orch up MANIFEST one detached session per worktree of an issue (any repos)
orch issues TUI on the sessions `orch up` started, grouped by issue
## How a run goes
queued, running (hx `-p --mode json`), gating (profile gate), retry with the gate output on the same session, then
done, failed, needs-human (gate still red, or the agent wanted something the allowlist forbids) or requeued
(provider quota used up, the account is paused until its window resets). The work always stays on branch
`orch/ID`. Every finished run appends one line to `<state>/telemetry.jsonl`.
## Profile (`~/.config/orch/profiles/NAME.toml`)
`--profile` defaults to `default`; if `default.toml` does not exist, built-in defaults apply (`hx` from PATH, your own
`~/.hx` login, 2 retries, no allowlist). Any other missing profile name is an error.
```toml
hx = "hx" # command
home = "/work/hxhome" # own HOME => own hx login
provider = "claude"
gate = "sh tests/all.sh" # exit 0 = pass
max_retries = 2
workers = 2
account = "work-claude" # profiles on one login share quota pause and max_concurrent
allow = ["read", "write", "edit", "readonly", "bash:cargo *"]
on_deny = "continue" # soft denies go back to the agent instead of ending the run
[budget]
wall_secs = 1800 # per attempt
max_turns = 40 # whole run
max_tokens = 400000
[source] # dir | cmd
kind = "dir"
path = "/work/tasks"
[sink] # local-branch | cmd
kind = "cmd"
command = "python3 /work/adapters/gitea.py"
```
## State-machine sessions and the TUI
`orch` without a subcommand opens the TUI: sessions overview (`enter` on a row opens the session detail, `esc` goes
back; `t` full test output, `d` diff, `l` event transcript, `o` open the session in hx, `hx --session sN` in its worktree). It reads `.hx/orch.db` of the
current directory. `orch session --repo . --machine task --name NAME [--profile P]` creates a session and runs it.
`orch session --repo . --resume s1` continues an unfinished session (for example after a crash or a closed terminal)
from its saved state; `--machine`, `--name` and `--after` are not allowed with it. Machines are TOML files in
`.hx/machines/` or `~/.hx/machines/`. `examples/machines/` has four: `task` (plan, code, build, test, review, merge),
`docs` (write, lint, links), `e2e` (stack-up, e2e, stack-down) and `migration` (up, down, test). A `computer` step
with `report = "junit"` writes its JUnit XML to `$ORCH_REPORT` (also available as `{{report}}` in `cmd`); orch parses
it into counts and failing tests.
`N` on the overview opens the new-session form: machine (`←→`), name, sessions to wait for, and where to work.
"Work in" takes a branch or the name or path of a worktree of the repo (`←→` picks a listed one); a branch that
exists is checked out, a new one is created from `HEAD`, and left empty you get `hx/sN-name` as before. orch never
deletes a worktree it did not create. The merge toggle ends the session at `done` where the machine would merge, so
the branch stays for a pull request. Sessions started this way run on threads of the TUI, at most `workers` of the
`default` profile at a time (the rest wait as `queued`; sessions waiting for `--after` take no slot). `q` while they
run asks for `yes` and suspends them; `u` on the overview resumes every suspended session and every one whose process died (it shows in the key bar
with a count); `orch session --resume sN` does the same for one session from a shell.
A session that ended `failed` or `escalated` is continued at the state where it stopped with `R` on its row (or the
session screen) or `orch session --repo . --restart sN`. Budgets and retry counts start again from that point.
On a permission request in the Needs-you box: `y` allow once, `Y` always for that session, `n` deny, `A` allow
once every pending request that asks for the same thing (any session), and `P` save an allow rule to the profile
`default`. `P` opens a line with a guess (`edit`, or `bash:<command>`) you can change; it is checked like a profile
entry and appended to `allow` with the rest of the file left alone, and the request is allowed. It refuses when the
profile has no file or no `allow` list (that means everything is allowed already). Running sessions keep the
policy they started with; the rule counts for sessions started afterwards.
A running session can be steered from the session screen, also when `orch session` runs in another terminal: `i`
interrupt (the agent stops, you reply with a hint), `m` message to the agent, `s` force a state, `k` kill (type
`yes`; goes to `on_abort`), and `r` re-plan from the start state while the loop detector box shows (the last test
runs failed on the same tests). On the goal screen `j/k` selects a decision and `v` vetoes it: the agent is told and
the session goes back to `code`. The commands go through the database (`commands` table) and the runner picks them
up within a fraction of a second, even in the middle of a shell command. A machine can set limits:
[budget]
wall_secs = 5400 # time spent working, waiting for you does not count
cost = 5.0 # US dollars
compact_at = 85 # percent of the context window; hx gets `hx/compact`
Passing wall time or cost sends the session to `on_budget` (or fails it when the machine has none).
The goal lives in the same database: `orch goal "sentence"`, `orch check NAME CMD [--owner sN]` (an acceptance
check: pass = exit 0), `orch checks [--owner sN | --main]`. `g` in the TUI opens the goal view (task graph, critical
path, decisions, checks; `e` edit goal, `+` add check, `R` run all checks on main). `orch session --after s1,s2` makes
a session wait until those have merged. Only one session at a time runs the state that ends in `merged` (first come,
first served); after each merge all checks run again on main in a clean worktree. Machine steps get `ORCH_DB`,
`ORCH_REPO` and `ORCH_SESSION`, and `{{repo}}` in `cmd`; the example machines merge with
`git -C {{repo}} merge --ff-only {{branch}}` in `mark-merged`.
## Issues: `orch up`
For work on an issue that spans worktrees you made yourself, in one repo or several. Each worktree has its own
machine, profile and task text in its `.hx/` (`.hx` should be git-ignored). A manifest lists them:
```toml
# <manifest_dir>/ABC-123.toml
issue = "ABC-123"
[[session]]
worktree = "~/Repos/api/.worktrees/abc-123" # an existing linked worktree; its repo follows from it
name = "api endpoint"
machine = "abc-123" # <worktree>/.hx/machines/, then the repo's .hx/machines/, then ~/.hx/machines/
profile = "abc-123" # <worktree>/.hx/profiles/, then <config>/profiles/
# task = ".hx/task.md" # default, relative to the worktree; given to the agent with every prompt
# merge = false # default: the session ends at `done` and the branch stays for a pull request
```
`orch up ABC-123` reads `<manifest_dir>/ABC-123.toml` (or takes a path), checks every entry first and starts nothing
when one is broken, then starts one detached session per worktree and returns. Logs go to
`<state>/logs/issue-sN.log`. Running it again is safe: sessions that run or are done are left alone, and ones that
stopped unfinished start again. The sessions of every repo live in one database, `<state>/issues.db`; `orch
issues` shows them grouped by issue, with the repo under each name. Steering and kill work as in the normal TUI;
`u` and `R` start sessions detached again. `manifest_dir` defaults to `<config>/manifests` and is set in
`<config>/config.toml` (`~/.config/orch/config.toml`):
```toml
manifest_dir = "~/notes/manifests"
```
## More
- [docs/cmd-protocol.md](docs/cmd-protocol.md): task sources and result sinks as external commands (+ JSON schema)
- [docs/safety.md](docs/safety.md): allowlist, credential separation, audit log
- [eval/README.md](eval/README.md): the regression case set
- `sh tests/all.sh`: the full local gate
- `spike/` is the throwaway Python O0 spike, kept for reference