fix: local drafter review round 1
- Refuse to run pi as root when DOCS_REVIEW_DRAFTER_USER is unset. - Keep a record of the run: parse partial output on timeout, add the first redacted stderr line to failures, and report summed output and peak input tokens with turns in the log and step summary. - Delete top-level .pi* entries from the sandbox before drafting and refuse a draft that recreates one. - Probe: an HTTP error, redirect or non-JSON answer is a hard failure; only connection failures and an empty model list are soft. Refuse model ids starting with "-" and pass --model=<id>. - README: mid-run model swap note, hard-failure cases, rewrap. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
28b993cb23
commit
7095db060e
9 files changed
+330
-86
No files matched your search
+18
-6
@@ -88,13 +88,19 @@ def has_claude_credential(env: Mapping[str, str]) -> bool:
|
||||
|
||||
|
||||
def write_step_summary(result: DraftResult, env: Mapping[str, str]) -> None:
|
||||
"""Print the run's cost and turns, whichever Claude reported, and append them to
|
||||
$GITHUB_STEP_SUMMARY when the runner sets it."""
|
||||
"""Print the run's cost, turns and tokens, whichever the drafter reported, and
|
||||
append them to $GITHUB_STEP_SUMMARY when the runner sets it."""
|
||||
lines = []
|
||||
if result.drafted_by is not None:
|
||||
lines.append(f"- drafted_by: {result.drafted_by}")
|
||||
if result.cost_usd is not None:
|
||||
lines.append(f"- total_cost_usd: {result.cost_usd:.2f}")
|
||||
if result.turns is not None:
|
||||
lines.append(f"- num_turns: {result.turns}")
|
||||
if result.output_tokens is not None:
|
||||
lines.append(f"- output_tokens: {result.output_tokens}")
|
||||
if result.input_tokens is not None:
|
||||
lines.append(f"- max_input_tokens: {result.input_tokens}")
|
||||
if not lines:
|
||||
return
|
||||
print("drafter " + ", ".join(l[2:] for l in lines))
|
||||
@@ -168,16 +174,21 @@ def disallowed(change: sandbox.TreeChange, listed: frozenset[str],
|
||||
review_only: tuple[str, ...] = ()) -> list[str]:
|
||||
"""Changed paths the drafter may not touch. A listed document may change or go; a
|
||||
new file must match a docs pattern; anything written must be a regular file. Nothing
|
||||
matching a review_only pattern may change, appear or go."""
|
||||
matching a review_only pattern may change, appear or go, and nothing may recreate
|
||||
the pi configuration removed before drafting."""
|
||||
bad = []
|
||||
for p in change.paths:
|
||||
ok = p in listed or (p in change.new and matches_any(p, patterns))
|
||||
if ok and sandbox.is_pi_config(p):
|
||||
ok = False
|
||||
if ok and matches_any(p, review_only):
|
||||
ok = False
|
||||
if ok and p not in change.deleted and not sandbox.is_regular(root, p):
|
||||
ok = False
|
||||
if not ok:
|
||||
bad.append(p)
|
||||
bad += [name + "/" for name in sandbox.pi_config_entries(root)
|
||||
if (root / name).is_dir() and not any(p.startswith(name + "/") for p in bad)]
|
||||
return bad
|
||||
|
||||
|
||||
@@ -233,6 +244,7 @@ def draft_in_sandbox(inputs: Inputs, prompt: str, cwd: Path,
|
||||
except (git.GitError, subprocess.TimeoutExpired, OSError) as err:
|
||||
return Drafted(None, (), EXPORT_NOTE.format(reason=_short_reason(err)))
|
||||
sandbox.remove_symlinks(box)
|
||||
sandbox.remove_pi_config(box)
|
||||
listed = frozenset(expand_patterns(inputs.docs, box))
|
||||
before = sandbox.snapshot(box)
|
||||
prompt_file = write_system_prompt(box, inputs.doc_guide, env)
|
||||
@@ -241,11 +253,11 @@ def draft_in_sandbox(inputs: Inputs, prompt: str, cwd: Path,
|
||||
metadata = git_metadata(cwd)
|
||||
result = run_drafter(inputs, prompt, box, env, prompt_file, local_model=model,
|
||||
run_as=run_as)
|
||||
# Checked first, and on failure no further git command runs: a hook or a
|
||||
# config change would run on the next one.
|
||||
write_step_summary(result, env)
|
||||
# Checked before anything else, and on failure no further git command runs: a
|
||||
# hook or a config change would run on the next one.
|
||||
if git_metadata(cwd) != metadata:
|
||||
return Drafted(result, (), GIT_METADATA_NOTE)
|
||||
write_step_summary(result, env)
|
||||
if not result.ok:
|
||||
return Drafted(result, (), f"drafter failed: {result.error}")
|
||||
change = sandbox.compare(before, sandbox.snapshot(box))
|
||||
|
||||
Reference in new issue
Block a user