feat: local drafter (pi against a self-run model server)
drafter: local runs the pi coding agent against the model resident on an OpenAI-compatible server at the new local_url input, keyed by the LOCAL_MODEL_API_KEY secret. It asks the server which model is loaded and names exactly that one, so it never evicts the resident model. An unreachable server or no loaded model posts the stage 1 flags with a note and exits 0; a drafter that ran and failed still exits 1. pi runs in the existing sandbox with read, ls, edit and write, every project-local pi file and AGENTS.md ignored, stdin from /dev/null, the task passed as an @file, and an allowlisted environment. As root with DOCS_REVIEW_DRAFTER_USER set, it runs as that unprivileged user, which owns only the sandbox and pi's temporary home. Both drafters now hash the checkout's .git/config and .git/hooks before drafting and stop with no further git command if either changed. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
9dea56ce98
commit
28b993cb23
14 files changed
+1042
-30
No files matched your search
@@ -1,8 +1,8 @@
|
||||
# docs-review
|
||||
|
||||
`docs_review` keeps living documents current. On each Gitea pull request it flags
|
||||
the documents the change makes stale. If the repository opts in, it also has Claude
|
||||
Code draft the edits. It is a Python package with no dependencies outside the standard
|
||||
the documents the change makes stale. If the repository opts in, it also has a coding
|
||||
agent draft the edits: Claude Code, or the pi agent on a model server you run. It is a Python package with no dependencies outside the standard
|
||||
library.
|
||||
|
||||
## What it does
|
||||
@@ -18,14 +18,14 @@ finds, and edits that comment on later runs:
|
||||
modified, where the change did not regenerate it.
|
||||
- **unguided**: a listed document that the doc guide does not describe.
|
||||
|
||||
Stage 2 runs only with `drafter: claude`. Claude Code reads the change, the flags and the
|
||||
listed documents, and decides which documents need edits; the flags are hints, not a
|
||||
Stage 2 runs only with `drafter: claude` or `drafter: local`. The drafter reads the change,
|
||||
the flags and the listed documents, and decides which documents need edits; the flags are hints, not a
|
||||
limit. The edits go into a second pull request into the feature branch, for the author to
|
||||
review and merge. Later runs add commits to that pull request rather than replacing it.
|
||||
|
||||
The monthly pass runs on a schedule. It treats every file as new and reports the
|
||||
uncovered and unguided flags for the whole repository in one issue. With
|
||||
`drafter: claude` it opens a pull request with proposed edits instead.
|
||||
uncovered and unguided flags for the whole repository in one issue. With a drafter set
|
||||
it opens a pull request with proposed edits instead.
|
||||
|
||||
## What it never does
|
||||
|
||||
@@ -53,6 +53,37 @@ Its environment is an allowlist: system basics and its own Claude credential. Th
|
||||
token never reaches it, drafted files are checked for credential values before they are
|
||||
committed, and everything posted to Gitea has credential values replaced with `***`.
|
||||
|
||||
## The local drafter
|
||||
|
||||
`drafter: local` runs the [pi](https://www.npmjs.com/package/@earendil-works/pi-coding-agent)
|
||||
coding agent (a pinned version) against an OpenAI-compatible model server that you run
|
||||
and that reports its loaded model the way Unsloth Studio does (below). Set `local_url` to the server's
|
||||
OpenAI-compatible base URL, for example `http://model-host:8888/v1`, and the
|
||||
`LOCAL_MODEL_API_KEY` secret to its key. The Actions runner must be able to reach that
|
||||
address.
|
||||
|
||||
- **One model is resident at a time, and the tool uses whichever one is loaded.** Before
|
||||
drafting it asks the server (`GET <server>/api/inference/loaded-models`, with the key in
|
||||
the `Authorization` header) which model is loaded, and names exactly that one. Naming any
|
||||
other model would make the server swap it in and evict the model for every other
|
||||
client, so the tool never does. There is no `model` input for `local`.
|
||||
- **The server is only reachable while it runs.** If it cannot be reached, or has no
|
||||
model loaded, the run posts the stage 1 flags with the note "local drafter unavailable:
|
||||
model server unreachable" (or "no model loaded") and succeeds. A drafter that ran and
|
||||
failed still fails the job, as does a key the server rejects.
|
||||
- The server must expose `/api/inference/loaded-models` returning `{"data": [{"id": ...}]}`
|
||||
at the root of `local_url` without its trailing `/v1`.
|
||||
- Nothing is sent to Anthropic. The same material as for `claude` goes to your server.
|
||||
|
||||
pi runs with the read, list, edit and write tools only, no shell, and with every
|
||||
project-local pi file (settings, extensions, skills, prompt templates) and `AGENTS.md`
|
||||
ignored, since those come from the pull request. Its tool allowlist limits tool types,
|
||||
not paths, so the workflow runs it as an unprivileged user that owns only the sandbox
|
||||
and pi's own temporary home; the checkout stays root-owned. The repository's
|
||||
`CLAUDE.md` and the doc guide reach it in the system prompt, as for `claude`. Its
|
||||
environment is the same allowlist with `LOCAL_MODEL_API_KEY` in place of the Claude
|
||||
credential, and the key is written into neither its command line nor its config file.
|
||||
|
||||
## Install
|
||||
|
||||
Add a workflow to the repository you want reviewed, at `.gitea/workflows/docs-review.yml`:
|
||||
@@ -85,7 +116,7 @@ jobs:
|
||||
- `closed` in the pull request types lets the workflow close a docs pull request whose
|
||||
feature pull request merged or closed first.
|
||||
- The `concurrency` block cancels a run when the pull request is pushed again. With
|
||||
`drafter: claude` the workflow waits three minutes between stage 1 and drafting, so a
|
||||
`drafter: claude` or `local` the workflow waits three minutes between stage 1 and drafting, so a
|
||||
quick re-push cancels a run before it has spent anything.
|
||||
- `tool_ref` must name the same version as the `@` in `uses:`. Gitea does not tell a
|
||||
called workflow which ref it was called at, so the workflow fetches the tool's code at
|
||||
@@ -96,8 +127,11 @@ The job runs in the `node:22` image. It clones the repository with the bot token
|
||||
it needs no checkout action, and it installs Claude Code
|
||||
(`@anthropic-ai/claude-code`, a pinned version) only when `drafter` is `claude` and a
|
||||
Claude credential is set. With `drafter: claude` and no credential, it posts the stage 1
|
||||
comment with a note saying so and fails. The drafter's cost and turn count are printed
|
||||
in the log and appended to `$GITHUB_STEP_SUMMARY`.
|
||||
comment with a note saying so and fails. With `drafter: local` it installs pi
|
||||
(`@earendil-works/pi-coding-agent`, a pinned version) and creates the unprivileged user
|
||||
when `LOCAL_MODEL_API_KEY` is set, and without it posts a note and fails in the same way.
|
||||
The drafter's turn count, and Claude's cost, are printed in the log and appended to
|
||||
`$GITHUB_STEP_SUMMARY`.
|
||||
|
||||
The package can also be run by hand: `python3 -m docs_review pr|closed|monthly --help`.
|
||||
|
||||
@@ -105,7 +139,7 @@ The package can also be run by hand: `python3 -m docs_review pr|closed|monthly -
|
||||
|
||||
| Input | Default | Meaning |
|
||||
|---|---|---|
|
||||
| `drafter` | `none` | `none` flags only. `claude` also drafts edits. `local` is accepted but not yet built: it fails the job with "local drafter not built yet". Any other value, including a misspelling, behaves as `none`. |
|
||||
| `drafter` | `none` | `none` flags only. `claude` also drafts edits with Claude Code; `local` drafts them with pi on your model server. Any other value, including a misspelling, behaves as `none`. |
|
||||
| `docs` | required | Newline-separated patterns for the living documents. |
|
||||
| `generated` | none | Patterns for generated files. |
|
||||
| `top_level` | `README.md` | The subset of `docs` the monthly pass re-reads in full. |
|
||||
@@ -115,6 +149,7 @@ The package can also be run by hand: `python3 -m docs_review pr|closed|monthly -
|
||||
| `tracking_issue` | none | Issue number the monthly pass's commit messages cite. |
|
||||
| `doc_guide` | none | Path to the document that says who reads each listed document and what it is for. The drafter writes for that reader. |
|
||||
| `model` | `claude-sonnet-5-5` | Model used when `drafter` is `claude`. |
|
||||
| `local_url` | none | Required when `drafter` is `local`: the model server's OpenAI-compatible base URL, such as `http://model-host:8888/v1`. Must be `http` or `https`. |
|
||||
| `tool_ref` | `v1` | The docs-review branch or tag to run; the same as the `@` in `uses:`. |
|
||||
|
||||
## Secrets
|
||||
@@ -124,7 +159,9 @@ The package can also be run by hand: `python3 -m docs_review pr|closed|monthly -
|
||||
`write:issue` and `read:user`. An organization secret serves every repository in the
|
||||
organization.
|
||||
- `CLAUDE_CODE_OAUTH_TOKEN` or `ANTHROPIC_API_KEY` is needed only for
|
||||
`drafter: claude`.
|
||||
`drafter: claude`, and reaches only that drafter.
|
||||
- `LOCAL_MODEL_API_KEY` is needed only for `drafter: local`, and reaches only that
|
||||
drafter.
|
||||
|
||||
## Tests
|
||||
|
||||
@@ -132,7 +169,7 @@ The package can also be run by hand: `python3 -m docs_review pr|closed|monthly -
|
||||
python3 -m unittest discover -s tests -v
|
||||
```
|
||||
|
||||
The tests use only the standard library and a fake `claude` executable. They need
|
||||
The tests use only the standard library and fake `claude` and `pi` executables. They need
|
||||
Python 3.11 or later and make no network calls.
|
||||
|
||||
## License
|
||||
|
||||
Reference in new issue
Block a user