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:
jaredandClaude Opus 5.5 committed 2026-11-12 16:28:21 -05:00
1 parent 9dea56ce98
commit 28b993cb23
14 files changed
+1042 -30

No files matched your search

+29 -4
View File
@@ -3,9 +3,10 @@
# caller and the inputs.
#
# Secrets reach only the steps that need them. The bot token is in the clone step and
# the two steps that run the tool. The Claude credentials are in the drafting step only,
# and that step runs only when `drafter` normalizes to `claude`. Every `if:` reads the
# normalized drafter, never the raw input.
# the two steps that run the tool. The Claude credentials and the local model key are in
# the drafting step only: the Claude ones only when `drafter` normalizes to `claude`, the
# local key only when it normalizes to `local`. Every `if:` and secret expression reads
# the normalized drafter, never the raw input.
name: docs-review
on:
@@ -55,6 +56,11 @@ on:
type: string
required: false
default: ""
local_url:
description: "OpenAI-compatible base URL of the model server for drafter: local, e.g. http://model-host:8888/v1"
type: string
required: false
default: ""
model:
description: "Model for drafter: claude"
type: string
@@ -75,6 +81,8 @@ on:
required: false
ANTHROPIC_API_KEY:
required: false
LOCAL_MODEL_API_KEY:
required: false
defaults:
run:
@@ -106,6 +114,7 @@ jobs:
INPUT_TRACKING_ISSUE: ${{ inputs.tracking_issue }}
INPUT_DOC_GUIDE: ${{ inputs.doc_guide }}
INPUT_MODEL: ${{ inputs.model }}
INPUT_LOCAL_URL: ${{ inputs.local_url }}
# The calling repository's files are untrusted. Every python3 call takes -P, so
# Python imports nothing from the working directory and a docs_review/ or os.py in
# a pull request cannot replace the tool.
@@ -201,7 +210,10 @@ jobs:
&& steps.drafter.outputs.drafter != 'none'
run: sleep 180
# `local` runs here too, without the Claude credentials and without the install.
# `claude` gets the Claude credentials and the Claude Code install; `local` gets the
# local model key, the pi install and an unprivileged user to run pi as. pi's tool
# allowlist limits tool types, not paths, so the user is what keeps it out of the
# checkout: the checkout is root-owned and not writable by that user.
- name: Draft
if: >-
steps.drafter.outputs.drafter != 'none'
@@ -212,7 +224,10 @@ jobs:
DOCS_REVIEW_BOT_TOKEN: ${{ secrets.DOCS_REVIEW_BOT_TOKEN }}
CLAUDE_CODE_OAUTH_TOKEN: ${{ steps.drafter.outputs.drafter == 'claude' && secrets.CLAUDE_CODE_OAUTH_TOKEN || '' }}
ANTHROPIC_API_KEY: ${{ steps.drafter.outputs.drafter == 'claude' && secrets.ANTHROPIC_API_KEY || '' }}
LOCAL_MODEL_API_KEY: ${{ steps.drafter.outputs.drafter == 'local' && secrets.LOCAL_MODEL_API_KEY || '' }}
DOCS_REVIEW_DRAFTER_USER: ${{ steps.drafter.outputs.drafter == 'local' && 'docs-review-drafter' || '' }}
CLAUDE_CODE_VERSION: 2.1.322
PI_VERSION: 1.5.2
DISABLE_UPDATES: "1"
CLAUDE_CODE_DISABLE_NONESSENTIAL_TRAFFIC: "1"
run: |
@@ -226,6 +241,16 @@ jobs:
npm install -g --no-fund --no-audit "@anthropic-ai/claude-code@$CLAUDE_CODE_VERSION"
claude --version
fi
# Without the key the tool posts the flags with a note and fails before pi runs.
if [ "$DRAFTER" = "local" ] && [ -n "$LOCAL_MODEL_API_KEY" ]; then
npm install -g --no-fund --no-audit "@earendil-works/pi-coding-agent@$PI_VERSION"
pi --version < /dev/null
id -u "$DOCS_REVIEW_DRAFTER_USER" >/dev/null 2>&1 \
|| useradd --create-home --shell /usr/sbin/nologin "$DOCS_REVIEW_DRAFTER_USER"
# The user's sandbox and HOME are created under RUNNER_TEMP; it needs to
# traverse it, not list it.
chmod o+x "$RUNNER_TEMP"
fi
export GIT_CONFIG_COUNT=1 GIT_CONFIG_KEY_0="http.${GITHUB_SERVER_URL}/.extraHeader" \
GIT_CONFIG_VALUE_0="Authorization: token $DOCS_REVIEW_BOT_TOKEN"
if [ "$EVENT" = "pull_request" ]; then