Three defects the first sweep left behind, each caught by a rule the guard did not yet have. Statuses. RULES.md gives three; the tree had 25 values, and the free-text ones were carrying progress. "Implemented (wiring landed)" and "Ratified (rev. 2e). Rev. 2e adds the OpenTaskByPR lookup. Rev. 2d revised section 10..." were both changelogs living in the one field the other rules exempt. Every PRD now declares Draft, Approved or Finalised and nothing else; five that declared nothing now declare one. A revision number moves to **Revision:**, a pointer to the authoritative document to **Authority:**, and what a past revision changed to git. CLAUDE.md's citation of state-store-contract rev. 2e still resolves. Stale cross-references. "Supersedes the 2026-09-03 open question", "this bullet previously said", "an earlier draft of this document claimed" all point at text the reader cannot see, because it was replaced. A supersede marker survives only when it names a file, a section or a symbol that can be found. Temporal hedges. 100 uses of today, currently and right now across 31 files. Each dates its sentence to the day it was written: "[notify] today is one webhook URL, read in one place" stops being true the moment this design lands, while still reading as the premise it rests on. The header-field exemption was also too wide. "**Date:** 2026-09-03, Channel resolved 2026-09-22" smuggled a dated status into the one line the rules did not read; the exemption is now a Date holding only a date and a Status holding only one of the three.
84 lines
4.1 KiB
Markdown
84 lines
4.1 KiB
Markdown
# Operator-triggered PR review
|
|
|
|
**Status:** Draft
|
|
**Beads issue:** `archie-core-h019.8`
|
|
|
|
This PRD reuses the adversarial-self-review contract
|
|
(`docs/prds/adversarial-self-review.md`) and the `workflow.Reviewer` /
|
|
`workflow.ReviewReport` types from `internal/domain/workflow`. It decides
|
|
only what is new: how an operator asks for a review of an *existing* PR, and
|
|
how that PR's content reaches the reviewer.
|
|
|
|
## Problem
|
|
|
|
The adversarial reviewer (`StageReview`) runs automatically before `StageOpenPR`
|
|
and reviews the task's own worktree HEAD. There is no way to review a PR that
|
|
already exists: one archie opened, a human opened, or one whose findings the
|
|
operator wants re-checked after a push.
|
|
|
|
## Shape
|
|
|
|
One channel-neutral command — `review_pr` — accepts a repository and PR number
|
|
and returns the structured `ReviewReport`. The Web UI chat and Telegram invoke
|
|
the same command; neither duplicates review behaviour. The reviewer model is
|
|
`models.reviewer` (falling back to `models.builder`), already the rule the
|
|
workflow stage uses, so an operator configures it independently of
|
|
planner/builder.
|
|
|
|
## Decisions
|
|
|
|
1. **Forge read.** `GetPullRequest(owner, repo, number)` returns a
|
|
forge-neutral `PullRequest{Number, Title, Body, HeadRef, BaseRef, HeadSHA,
|
|
BaseSHA, State}`. Declared as a narrow `PullRequestReader` interface,
|
|
implemented by GitHub and Gitea; the noop forge does not implement it, so
|
|
the daemon type-asserts and refuses review with "forge does not support PR
|
|
review". Adding to the fat `Forge` interface would churn every test fake for
|
|
a capability the noop forge cannot honestly provide.
|
|
|
|
2. **Materialisation.** `worktree.Manager.CheckoutPR(owner, repo, headRef,
|
|
baseRef)` clones the repository fully and checks out `origin/<headRef>`.
|
|
`Diff(dir, baseRef)` and `Snapshot(dir, destDir)` then work unchanged:
|
|
`Diff` resolves `origin/<baseRef>` via the existing `resolveBase`, and
|
|
`Snapshot` strips `.git` exactly as the workflow stage does. The head must
|
|
already be pushed to the same repository — archie's own PRs always are; a
|
|
cross-repo or deleted head is refused with that reason, not half-reviewed.
|
|
|
|
3. **Reviewer reuse.** `agentworker.NewOperatorReviewer(models, providers)`
|
|
builds the same `subagentReviewer` the stage uses, from daemon-level config
|
|
rather than a `taskrun.Request`. It drops only the `Repo.ReviewEnabled`
|
|
gate (the operator asked explicitly) and the task-run scaffolding.
|
|
|
|
4. **Command.** A gateway tool `review_pr` (toolset `tasks`) bound to the
|
|
channel's identity at construction — the model never names an identity,
|
|
matching `task_spawn`/`task_action`. The daemon supplies `ChatPRReviewer`,
|
|
a narrow gateway interface; the daemon adapter maps `workflow.ReviewReport`
|
|
into a gateway-owned result shape (gateway states what it needs, the daemon
|
|
adapts — the `ChatTaskActor` pattern).
|
|
|
|
5. **Authorization.** Identity-scoped repository allow-list, the
|
|
`task_spawn` rule: a chat identity may only review a repo in its
|
|
`TaskProfile.Repos`. `identity == nil` denotes an authenticated dashboard
|
|
operator who may review any configured repository.
|
|
|
|
6. **Determinism.** One review per (owner, repo, number) at a time: the daemon
|
|
holds an in-flight set; a concurrent request for the same PR returns
|
|
"review already in progress" rather than launching a second reviewer and
|
|
racing on the snapshot.
|
|
|
|
## Files
|
|
|
|
- `internal/forge/forge.go`, `github.go`, `gitea.go` — `PullRequest`,
|
|
`PullRequestReader`, `GetPullRequest`.
|
|
- `internal/worktree/worktree.go` — `CheckoutPR`.
|
|
- `internal/app/agentworker/review.go` — `NewOperatorReviewer`.
|
|
- `internal/gateway/review_tools.go` — `ChatPRReviewer`, result shape, `review_pr`.
|
|
- `internal/gateway/turn.go`, `gateway.go` — tool wiring into the turn.
|
|
- `internal/app/archied/pr_review.go` — the `ChatPRReviewer` adapter.
|
|
- `internal/app/archied/{bootstrap.go,main.go,telegram_setup.go}` — composition.
|
|
|
|
## Not in scope
|
|
|
|
- Surfacing findings on the PR body or the dashboard (h019.6).
|
|
- Reviewer model per-invocation override: configuration via `models.reviewer`
|
|
is the selection surface; a per-call override is a later knob.
|