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
+20
-1
@@ -3,6 +3,7 @@
|
||||
from __future__ import annotations
|
||||
|
||||
import re
|
||||
import urllib.parse
|
||||
from collections.abc import Iterable, Mapping
|
||||
from dataclasses import dataclass
|
||||
from pathlib import Path
|
||||
@@ -27,6 +28,8 @@ class Inputs:
|
||||
model: str
|
||||
# Listed documents the drafter may read but not edit; each entry is within docs.
|
||||
review_only: tuple[str, ...] = ()
|
||||
# The local drafter's OpenAI-compatible base URL; set only when drafter is local.
|
||||
local_url: str | None = None
|
||||
|
||||
|
||||
def normalize_drafter(raw: str | None) -> str:
|
||||
@@ -35,6 +38,18 @@ def normalize_drafter(raw: str | None) -> str:
|
||||
return value if value in DRAFTERS else "none"
|
||||
|
||||
|
||||
def parse_local_url(raw: str | None) -> str:
|
||||
"""The local_url input without a trailing slash. Raises ValueError unless it is an
|
||||
http(s) URL with a host."""
|
||||
url = (raw or "").strip().rstrip("/")
|
||||
if not url:
|
||||
raise ValueError("input 'local_url' is required when drafter is local")
|
||||
parts = urllib.parse.urlsplit(url)
|
||||
if parts.scheme not in ("http", "https") or not parts.hostname:
|
||||
raise ValueError(f"input 'local_url' must be an http or https URL, got {url!r}")
|
||||
return url
|
||||
|
||||
|
||||
def _lines(raw: str | None) -> tuple[str, ...]:
|
||||
"""Split a newline-separated input, trimming and dropping blank lines."""
|
||||
return tuple(line.strip() for line in (raw or "").splitlines() if line.strip())
|
||||
@@ -64,8 +79,11 @@ def parse_inputs(env: Mapping[str, str]) -> Inputs:
|
||||
except ValueError:
|
||||
raise ValueError(f"input 'tracking_issue' must be an integer, got {issue_raw!r}") from None
|
||||
|
||||
drafter = normalize_drafter(env.get("INPUT_DRAFTER"))
|
||||
local_url = parse_local_url(env.get("INPUT_LOCAL_URL")) if drafter == "local" else None
|
||||
|
||||
return Inputs(
|
||||
drafter=normalize_drafter(env.get("INPUT_DRAFTER")),
|
||||
drafter=drafter,
|
||||
docs=docs,
|
||||
generated=_lines(env.get("INPUT_GENERATED")),
|
||||
top_level=_lines(env.get("INPUT_TOP_LEVEL")) or DEFAULT_TOP_LEVEL,
|
||||
@@ -75,6 +93,7 @@ def parse_inputs(env: Mapping[str, str]) -> Inputs:
|
||||
doc_guide=_text(env, "INPUT_DOC_GUIDE") or None,
|
||||
model=_text(env, "INPUT_MODEL") or DEFAULT_MODEL,
|
||||
review_only=review_only,
|
||||
local_url=local_url,
|
||||
)
|
||||
|
||||
|
||||
|
||||
Reference in new issue
Block a user