feat: review_only input and an enumeration check in the monthly prompt
tests / unittest (push) Successful in 23s

review_only names listed documents the drafter may read but not edit. They stay
in stage 1, are listed separately in the prompt, and a change to one fails the
run like a change outside docs. Each entry must match a docs pattern.

The monthly prompt now makes checking every list and count in the top-level
documents against the repository the drafter's main job. Mode-specific text
moves to prompts/mode-pr.md and prompts/mode-monthly.md; the pr text is
unchanged.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
jaredandClaude Opus 5.5 committed 2026-11-12 15:40:09 -05:00
1 parent f39409e62c
commit 9dea56ce98
15 files changed
+223 -29

No files matched your search

+24 -1
View File
@@ -6,12 +6,15 @@ import json
import re
from collections.abc import Iterable
from dataclasses import dataclass
from pathlib import Path
from docs_review.flags import Flag
from docs_review.git import Commit
from docs_review.inputs import matches_any
from docs_review.report import render_sections
PROMPTS = Path(__file__).resolve().parent.parent / "prompts"
MODES = ("pr", "monthly")
DIFF_CAP_BYTES = 200_000
LAST_HEAD = "<!-- docs-review:last-head={sha} -->"
_LAST_HEAD_RE = re.compile(r"<!-- docs-review:last-head=([0-9a-f]{40}) -->")
@@ -31,6 +34,21 @@ GUIDE_NOTE = (
"purpose; write each edit for that reader."
)
NO_GUIDE_NOTE = "No guide is set; make the smallest edit and match the surrounding document's voice."
REVIEW_ONLY_NOTE = (
"\nDocuments you may read but not edit:\n\n{paths}\n\n"
"If one of them is stale, do not edit it; add an entry to the summary's `declined` "
"list, with its path as `flag`, saying what is stale.\n"
)
def load_template(mode: str) -> str:
"""prompts/task.md with this mode's instructions, prompts/mode-<mode>.md, in place
of its {mode_text} field."""
if mode not in MODES:
raise ValueError(f"unknown mode {mode!r}; expected one of {', '.join(MODES)}")
task = (PROMPTS / "task.md").read_text(encoding="utf-8")
mode_text = (PROMPTS / f"mode-{mode}.md").read_text(encoding="utf-8")
return task.replace("{mode_text}", mode_text, 1)
def diff_payload(diff_text: str, numstat: str) -> str:
@@ -47,9 +65,13 @@ def diff_payload(diff_text: str, numstat: str) -> str:
def build_prompt(
template: str, *, mode: str, pr: int | None, flags_json: str, payload: str,
docs: tuple[str, ...], top_level: tuple[str, ...], guide_path: str | None,
review_only: tuple[str, ...] = (),
) -> str:
"""Fill the template's named fields. Only the template is parsed for braces."""
"""Fill the template's named fields. Only the template is parsed for braces.
`docs` are the documents the drafter may edit; `review_only` the listed documents it
may only read, rendered as their own section or, when there are none, as nothing."""
note = GUIDE_NOTE.format(path=guide_path) if guide_path else NO_GUIDE_NOTE
read_only = REVIEW_ONLY_NOTE.format(paths="\n".join(review_only)) if review_only else ""
return template.format_map({
"mode": mode,
"pr": "none" if pr is None else pr,
@@ -58,6 +80,7 @@ def build_prompt(
"docs": "\n".join(docs),
"top_level": "\n".join(top_level),
"guide_note": note,
"review_only": read_only,
})
+9 -4
View File
@@ -124,12 +124,16 @@ def run_drafter(inputs: Inputs, prompt: str, cwd: Path, env: Mapping[str, str],
def disallowed(change: sandbox.TreeChange, listed: frozenset[str],
patterns: tuple[str, ...], root: Path) -> list[str]:
patterns: tuple[str, ...], root: Path,
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."""
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."""
bad = []
for p in change.paths:
ok = p in listed or (p in change.new and matches_any(p, patterns))
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:
@@ -176,10 +180,11 @@ def draft_in_sandbox(inputs: Inputs, prompt: str, cwd: Path,
if not result.ok:
return Drafted(result, (), f"drafter failed: {result.error}")
change = sandbox.compare(before, sandbox.snapshot(box))
bad = disallowed(change, listed, inputs.docs, box)
bad = disallowed(change, listed, inputs.docs, box, inputs.review_only)
if bad:
names = ", ".join(f"`{p}`" for p in bad)
return Drafted(result, (), f"drafter failed: it changed files outside `docs`: {names}")
where = "outside `docs`" + (" or in `review_only`" if inputs.review_only else "")
return Drafted(result, (), f"drafter failed: it changed files {where}: {names}")
if leaks_credential(change.new + change.changed, box, env):
return Drafted(result, (), CREDENTIAL_NOTE)
try:
+19
View File
@@ -25,6 +25,8 @@ class Inputs:
tracking_issue: int | None
doc_guide: str | None
model: str
# Listed documents the drafter may read but not edit; each entry is within docs.
review_only: tuple[str, ...] = ()
def normalize_drafter(raw: str | None) -> str:
@@ -48,6 +50,14 @@ def parse_inputs(env: Mapping[str, str]) -> Inputs:
if not docs:
raise ValueError("input 'docs' is required: list at least one document pattern")
review_only = _lines(env.get("INPUT_REVIEW_ONLY"))
for entry in review_only:
if not matches_any(entry, docs):
raise ValueError(
f"input 'review_only' entry {entry!r} matches no 'docs' pattern; "
"every review_only entry must also be a listed document"
)
issue_raw = _text(env, "INPUT_TRACKING_ISSUE")
try:
tracking_issue = int(issue_raw) if issue_raw else None
@@ -64,9 +74,18 @@ def parse_inputs(env: Mapping[str, str]) -> Inputs:
tracking_issue=tracking_issue,
doc_guide=_text(env, "INPUT_DOC_GUIDE") or None,
model=_text(env, "INPUT_MODEL") or DEFAULT_MODEL,
review_only=review_only,
)
def split_review_only(
paths: tuple[str, ...], review_only: tuple[str, ...]
) -> tuple[tuple[str, ...], tuple[str, ...]]:
"""The listed documents split into (editable, review-only), each in the given order."""
read_only = tuple(p for p in paths if matches_any(p, review_only))
return tuple(p for p in paths if p not in read_only), read_only
def _glob_files(pattern: str, repo_root: Path) -> list[str]:
"""Repository-relative POSIX paths of files matching one pattern."""
return [
+7 -5
View File
@@ -8,12 +8,12 @@ from collections.abc import Mapping
from pathlib import Path
from docs_review import git
from docs_review.draft import build_prompt, parse_summary, render_pr_body
from docs_review.draft import build_prompt, load_template, parse_summary, render_pr_body
from docs_review.drafter import draft_in_sandbox
from docs_review.flags import Flag, compute_flags, group_uncovered, whole_repo_changes
from docs_review.inputs import Inputs, expand_patterns
from docs_review.inputs import Inputs, expand_patterns, split_review_only
from docs_review.report import MONTHLY_MARKER, render_issue, stage1_json
from docs_review.run_pr import TASK_PROMPT, read_guide, read_texts
from docs_review.run_pr import read_guide, read_texts
MONTHLY_PREFIX = "docs-review/monthly-"
MONTH_PATTERN = re.compile(r"^\d{4}-(0[1-9]|1[0-2])$")
@@ -123,9 +123,11 @@ def run_monthly(inputs: Inputs, forge, env: Mapping[str, str], cwd: Path,
MERGE_CONFLICT_NOTE.format(branch=reuse["head"]["ref"], base=base))
return 0
flags_json = json.dumps(stage1_json(flags, mode="monthly", head_sha=month))
editable, read_only = split_review_only(docs, inputs.review_only)
prompt = build_prompt(
TASK_PROMPT.read_text(encoding="utf-8"), mode="monthly", pr=None,
flags_json=flags_json, payload=NO_DIFF_PAYLOAD, docs=docs,
load_template("monthly"), mode="monthly", pr=None,
flags_json=flags_json, payload=NO_DIFF_PAYLOAD, docs=editable,
review_only=read_only,
top_level=inputs.top_level, guide_path=inputs.doc_guide,
)
drafted = draft_in_sandbox(inputs, prompt, cwd, env)
+7 -6
View File
@@ -12,16 +12,15 @@ from pathlib import Path
from docs_review import git
from docs_review.changes import changed_names, parse_name_status
from docs_review.draft import (
DraftResult, build_prompt, diff_payload, parse_last_head, parse_summary,
render_pr_body, should_skip,
DraftResult, build_prompt, diff_payload, load_template, parse_last_head,
parse_summary, render_pr_body, should_skip,
)
from docs_review.drafter import draft_in_sandbox
from docs_review.flags import Flag, compute_flags
from docs_review.inputs import Inputs, expand_patterns
from docs_review.inputs import Inputs, expand_patterns, split_review_only
from docs_review.report import STAGE1_MARKER, render_clean, render_comment, stage1_json
from docs_review.tree import read_in_tree
TASK_PROMPT = Path(__file__).resolve().parent.parent / "prompts" / "task.md"
CLOSED_BRANCH_NOTE = (
"docs-review/pr-{n} was closed without merging; delete that branch to get new drafts."
)
@@ -210,9 +209,11 @@ def run_pr(inputs: Inputs, forge, env: Mapping[str, str], cwd: Path, args: PrArg
MERGE_CONFLICT_NOTE.format(n=args.number), docs_pr=pr_no)
return 0
editable, read_only = split_review_only(docs, inputs.review_only)
prompt = build_prompt(
TASK_PROMPT.read_text(encoding="utf-8"), mode="pr", pr=args.number,
flags_json=flags_json, payload=payload, docs=docs, top_level=inputs.top_level,
load_template("pr"), mode="pr", pr=args.number,
flags_json=flags_json, payload=payload, docs=editable, review_only=read_only,
top_level=inputs.top_level,
guide_path=inputs.doc_guide,
)
drafted = draft_in_sandbox(inputs, prompt, cwd, env)