Buckets:
AnonymousSpottedToad/candidate_bucket / codebase /python /promptdriven_pdd /context /checkup_review_loop_example.py
| """Example interfaces and artifact contract for `pdd.checkup_review_loop`. | |
| This file documents the public contract that callers and downstream verdict | |
| adapters depend on. The runtime implementation lives in | |
| `pdd/checkup_review_loop.py`; here we only spell out shapes, filenames, and | |
| example payloads so other modules' prompts and tests can reason about the | |
| interface without importing the real code. | |
| """ | |
| from __future__ import annotations | |
| import os | |
| import sys | |
| from dataclasses import dataclass, field | |
| from pathlib import Path | |
| from typing import Any, Callable, Dict, List, Optional, Sequence, Tuple | |
| sys.path.insert(0, os.path.join(os.path.dirname(__file__), "..")) | |
| # --------------------------------------------------------------------------- | |
| # Dataclasses (shape contract) | |
| # --------------------------------------------------------------------------- | |
| class ReviewFinding: | |
| """One actionable finding produced by a reviewer.""" | |
| severity: str # blocker | critical | medium | low | nit | info | |
| reviewer: str # role that produced it (e.g., "codex", "claude") | |
| area: str # file | module | workflow | prompt | example | architecture | test | security | billing | api | ux | maintainability | |
| evidence: str # specific evidence text | |
| finding: str # what is wrong | |
| required_fix: str # what must change | |
| location: str = "" # path:line or empty | |
| status: str = "open" # "open" | "fixed" | |
| round_number: int = 0 | |
| class ReviewResult: | |
| """Normalized output from a single reviewer invocation.""" | |
| reviewer: str | |
| status: str # "clean" | "findings" | "failed" | "degraded" | "missing" | |
| issue_aligned: Optional[bool] | |
| findings: List[ReviewFinding] = field(default_factory=list) | |
| summary: str = "" | |
| raw_output: str = "" | |
| # Diagnostics surfaced on the final report when the reviewer fails or | |
| # degrades. ``status_classification`` is a short best-effort tag | |
| # (``auth``/``network``/``timeout``/``rate-limit``/``crash``/``unknown``). | |
| # ``status_exit_code`` is parsed best-effort from ``raw_output`` | |
| # (``"no exit code"`` when absent). ``status_reason`` is the last | |
| # ~20 lines of stderr/stdout for operator triage. | |
| status_classification: str = "" | |
| status_exit_code: str = "" | |
| status_reason: str = "" | |
| class FixResult: | |
| """Output of one fixer pass for a reviewer's findings. | |
| ``success`` is the bare fixer-subprocess return flag. It MUST NOT | |
| be rendered as a leading ``success``/``fixed`` token in the final | |
| report (issue #1088). The verification-boundary fields are | |
| populated by the loop around ``_commit_and_push_if_changed`` so the | |
| rendered ``### Fixes Attempted`` bullet can lead with the | |
| structured triple ``fixer_result=… push_status=… verification=…`` | |
| rather than the untrusted prose. | |
| """ | |
| fixer: str | |
| success: bool | |
| summary: str | |
| changed_files: List[str] = field(default_factory=list) | |
| raw_output: str = "" | |
| dispositions: Dict[str, str] = field(default_factory=dict) | |
| rationales: Dict[str, str] = field(default_factory=dict) | |
| # SHA-backed verification trust boundary (issue #1088). | |
| # ``fixer_result``: ``"attempted" | "skipped" | "failed"``. | |
| # ``push_status``: ``"pushed" | "push_failed" | "not_attempted"``. | |
| # SHAs come from ``git rev-parse HEAD`` in the worktree; the loop | |
| # MUST NOT infer them from fixer prose. | |
| fixer_result: Optional[str] = None | |
| push_status: Optional[str] = None | |
| local_fixer_commit_sha: Optional[str] = None | |
| pushed_head_sha: Optional[str] = None | |
| round_number: int = 0 | |
| class ReviewLoopConfig: | |
| """Configurable knobs for the loop. All have safe defaults.""" | |
| reviewers: Sequence[str] = ("codex", "claude") | |
| reviewer: Optional[str] = None | |
| fixer: Optional[str] = None | |
| reviewer_fallback: Optional[str] = None | |
| review_only: bool = False | |
| max_rounds: int = 5 | |
| max_cost: float = 50.0 | |
| max_minutes: float = 90.0 | |
| require_all_reviewers_clean: bool = True | |
| continue_on_reviewer_limit: bool = False | |
| require_final_fresh_review: bool = True | |
| timeout_adder: float = 0.0 | |
| reasoning_time: Optional[float] = None | |
| blocking_severities: Tuple[str, ...] = ("blocker", "critical", "medium") | |
| clean_reviewer_states: Tuple[str, ...] = ("clean",) | |
| # APPENDED — when the primary reviewer ends in ``failed`` or | |
| # ``missing`` (NOT ``degraded`` — that means reduced quality, | |
| # don't silently lose signal), run a second review pass using the | |
| # fixer's identity as a fallback reviewer. The fallback's result | |
| # is recorded as a real reviewer row so the cloud verdict adapter | |
| # sees a clean real-reviewer entry rather than the legacy | |
| # ``fixer`` sentinel. The primary's original failure is preserved | |
| # in ``ReviewLoopState.reviewer_status_details`` with a | |
| # ``superseded_by_fallback="true"`` marker so the Reviewer | |
| # Diagnostics block in the rendered report still shows what | |
| # failed. MUST stay at the end of the field list so positional | |
| # callers (e.g., ``ReviewLoopConfig(reviewers, reviewer, fixer, …, | |
| # clean_reviewer_states)``) keep working unchanged — this contract | |
| # example mirrors the live dataclass at | |
| # ``pdd/checkup_review_loop.py``. Off by default. | |
| fallback_reviewer_on_failure: bool = False | |
| # Optional secondary fixer invoked at most once across the loop when | |
| # the primary fixer fails (e.g., subscription-tier credential exhausted). | |
| # Must differ from the primary fixer and the active reviewer. Kept at | |
| # the end of the field list so positional callers stay stable. | |
| fixer_fallback: Optional[str] = None | |
| # Issue #1092 deterministic-gate enforcement. ``enable_gates`` toggles | |
| # the gate layer at every clean-exit site (CLI: ``--no-gates`` flips | |
| # this to False). ``gate_timeout`` is the per-gate wall-clock cap in | |
| # seconds (CLI: ``--gate-timeout``). ``gate_allow`` is the | |
| # forward-compatibility hook plumbed from the repeatable | |
| # ``--gate-allow`` CLI flag. Gate failures convert into synthetic | |
| # ``ReviewFinding`` rows with ``reviewer=f"gate:{name}"`` and | |
| # ``area="deterministic-gate"`` and are routed through the normal | |
| # fixer path. The gate module is ``pdd/checkup_gates.py`` (registered | |
| # in ``architecture.json`` under ``checkup_gates_python.prompt``). | |
| enable_gates: bool = True | |
| gate_timeout: float = 60.0 | |
| gate_allow: Tuple[str, ...] = () | |
| # Issue #2047 source-of-truth repair. Kept in the appended field block so | |
| # positional callers stay stable. | |
| enable_source_of_truth_repair: bool = True | |
| # Final appended config field: explicit opt-in for single-role review/fix | |
| # mode. Off by default so reviewer/fixer independence remains the normal | |
| # contract. | |
| allow_same_reviewer_fixer: bool = False | |
| # APPENDED: agentic-review-loop knobs — issue #1788 | |
| adversarial_prompt: Optional[str] = None | |
| agentic_mode: bool = False | |
| fresh_final_review_role: Optional[str] = None | |
| agentic_artifact_path: Optional[str] = None | |
| reviewer_commands: Dict[str, str] = field(default_factory=dict) | |
| no_fix: bool = False | |
| # Hosted fallback/mirror commands serialized as artifact metadata only; | |
| # canonical reviewer prompts consume ``reviewer_commands`` above. | |
| artifact_reviewer_commands: Dict[str, str] = field(default_factory=dict) | |
| # Hosted callers can retain final artifact bytes in trusted parent memory. | |
| agentic_artifact_sink: Optional[Callable[[bytes], None]] = field( | |
| default=None, repr=False | |
| ) | |
| # Bounded Codex-only Terra/Sol convergence. The configured positive | |
| # ``max_rounds`` is authoritative; clean Sol may finish early. | |
| terra_sol: bool = False | |
| class ReviewLoopContext: | |
| """Issue and PR context passed into reviewer prompts.""" | |
| issue_url: str | |
| issue_content: str | |
| repo_owner: str | |
| repo_name: str | |
| issue_number: int | |
| issue_title: str | |
| architecture_json: str | |
| pddrc_content: str | |
| pr_url: str | |
| pr_owner: str | |
| pr_repo: str | |
| pr_number: int | |
| project_root: Path | |
| pr_content: str = "" | |
| has_issue: bool = True | |
| full_suite_source: str = "local" | |
| test_scope: str = "full" | |
| layer1_step5_evidence: str = "" | |
| final_gate_canonical_status: str = "" | |
| class ReviewLoopState: | |
| """Mutable state accumulated across review-loop rounds.""" | |
| total_cost: float = 0.0 | |
| last_model: str = "unknown" | |
| reviewer_status: Dict[str, str] = field(default_factory=dict) | |
| active_reviewer: Optional[str] = None | |
| findings_by_key: Dict[str, ReviewFinding] = field(default_factory=dict) | |
| raw_outputs: List[Tuple[str, str]] = field(default_factory=list) | |
| fixes: List[FixResult] = field(default_factory=list) | |
| stop_reason: str = "" | |
| issue_aligned: Optional[bool] = None | |
| fresh_final_status: str = "missing" | |
| max_rounds_reached: bool = False | |
| max_cost_reached: bool = False | |
| max_duration_reached: bool = False | |
| fix_attempts_by_key: Dict[str, int] = field(default_factory=dict) | |
| dispute_notes_by_key: Dict[str, str] = field(default_factory=dict) | |
| reviewer_feedback_by_key: Dict[str, str] = field(default_factory=dict) | |
| reviewer_status_details: Dict[str, Dict[str, str]] = field(default_factory=dict) | |
| # Set lazily once ``fixer_fallback`` runs and succeeds; from that point on | |
| # every subsequent round drives the fix step with this role instead of the | |
| # exhausted primary. Parallel to ``active_reviewer``. | |
| active_fixer: Optional[str] = None | |
| # Originally configured primary reviewer captured at loop init and never | |
| # reassigned. ``active_reviewer`` rotates after a reviewer-fallback takeover; | |
| # this field preserves the original so the fixer-fallback exclusion check | |
| # can enforce the documented "must differ from --reviewer" rule even after | |
| # the active reviewer has rotated. | |
| original_reviewer: Optional[str] = None | |
| # SHA-backed verification trust boundary (issue #1088). | |
| # ``verified_head_sha``: PR head SHA the verifier most recently | |
| # reviewed as clean. Updated only when the verifier returns clean | |
| # on the SHA the fixer just pushed. | |
| # ``remote_pr_head_sha``: PR head SHA observed at final-report | |
| # render time via a single ``_fetch_pr_metadata`` re-fetch (R-V5). | |
| # ``verification_status_by_round``: per-round verifier outcome, | |
| # values in ``{"verified", "unverified", "stale", "skipped"}``. | |
| # ``reviewed_head_sha``: PR head SHA observed in the worktree at | |
| # the time the reviewer (primary, fallback, or review-only) ran. | |
| # Recorded directly from ``git rev-parse HEAD`` in the worktree | |
| # rather than from PR metadata, so a PR that advances between | |
| # checkout and the metadata fetch cannot poison the comparison | |
| # target ``_finalize`` uses at the R-V5 re-fetch. | |
| # ``final_refetch_attempted``: True when ``_finalize`` actually | |
| # ran the render-time remote-head re-fetch. Lets the render layer | |
| # distinguish a missing re-fetch (``remote-pr-head-sha: none``) | |
| # from a failed re-fetch (``remote-pr-head-sha: unknown``). | |
| verified_head_sha: Optional[str] = None | |
| remote_pr_head_sha: Optional[str] = None | |
| verification_status_by_round: Dict[int, str] = field(default_factory=dict) | |
| reviewed_head_sha: Optional[str] = None | |
| final_refetch_attempted: bool = False | |
| gate_runs: List[Dict[str, Any]] = field(default_factory=list) | |
| source_of_truth: Optional[Dict[str, Any]] = None | |
| # True when the resolved reviewer and fixer are the same role — either an | |
| # explicit ``allow_same_reviewer_fixer`` run OR a runtime auto-degrade | |
| # (issue #1941) when a provider family was unavailable. | |
| same_role_review_fix: bool = False | |
| # Explicit fresh-final sessions are distinct from the primary provider's | |
| # review artifacts/status, even when both use the same role. | |
| fresh_final_review_invocations: int = 0 | |
| fresh_final_findings: List[ReviewFinding] = field(default_factory=list) | |
| # Actual consumption used to recompute mirror budget state at serialization | |
| # time rather than trusting potentially stale in-loop flags. | |
| rounds_completed: int = 0 | |
| elapsed_minutes: float = 0.0 | |
| started_monotonic: Optional[float] = None | |
| # Set when the render-time remote-head check invalidates prior validation. | |
| validation_stale: bool = False | |
| # ``"independent"`` for the normal cross-family loop and for a deliberate | |
| # config-time same-role run; ``"degraded (<role> unavailable)"`` only when | |
| # role independence was relaxed at runtime because a family was down. | |
| role_independence: str = "independent" | |
| # Terra/Sol audit state. Role observations are distinct so missing Sol | |
| # evidence can never inherit a valid Terra model. | |
| terra_sol_mode: bool = False | |
| max_rounds: Optional[int] = None | |
| sol_model: str = "" | |
| terra_model: str = "" | |
| # --------------------------------------------------------------------------- | |
| # Public API (signature contract) | |
| # --------------------------------------------------------------------------- | |
| def _scrub_secrets(text: str) -> str: | |
| """Redact tokens and secrets from free-text before storing or logging. | |
| Applies pattern-based redaction for bearer tokens, API keys, OAuth | |
| payloads, and other known secret patterns. Returns the redacted string. | |
| The caller MUST use this before persisting any raw reviewer/fixer output | |
| to disk or emitting it in the structured JSON artifact. | |
| """ | |
| return text | |
| def parse_reviewer_commands(value) -> Dict[str, str]: | |
| """Parse ``role:/slash-command`` reviewer spec into a mapping. | |
| Accepts a comma-separated string or list of ``role:/command`` pairs and | |
| returns a ``{role: command}`` dict. For example:: | |
| parse_reviewer_commands("codex:/review,claude:/code-review") | |
| # -> {"codex": "/review", "claude": "/code-review"} | |
| Unknown or malformed entries are dropped. An empty result means no | |
| reviewer commands were resolved. | |
| """ | |
| return {} | |
| def parse_reviewers(value): | |
| """Parse legacy `--reviewers` CLI value into normalized role order. | |
| Aliases: chatgpt|openai -> codex; anthropic -> claude; google -> gemini. | |
| Unknown role names are dropped. An empty result falls back to | |
| `("codex", "claude")`. | |
| """ | |
| return ("codex", "claude") | |
| def run_checkup_review_loop( | |
| *, | |
| context: ReviewLoopContext, | |
| config: ReviewLoopConfig, | |
| cwd: Path, | |
| verbose: bool = False, | |
| quiet: bool = False, | |
| use_github_state: bool = True, | |
| ) -> Tuple[bool, str, float, str]: | |
| """Run a primary-reviewer/fixer PR loop and return final report data. | |
| Returns `(success, report_md, total_cost_usd, last_model)`. `success` is | |
| `True` whenever the loop produced a report. Ship/not-ready classification | |
| is the caller's job, derived from the `reviewer-status:` line in the | |
| report header. When `config.review_only` is true, this runs only the | |
| primary reviewer first pass and never invokes the fixer, commits, or pushes. | |
| """ | |
| return True, "## Step 7/8: Review Loop Final Report", 0.0, "codex" | |
| def load_final_state( | |
| cwd: Path, issue_number: int, pr_number: int | |
| ) -> Optional[Dict[str, Any]]: | |
| """Load the canonical ``final-state.json`` verdict for a review-loop run. | |
| Returns the parsed mapping, or ``None`` when the artifact is absent or | |
| unreadable (``OSError``/``json.JSONDecodeError``). The canonical final gate | |
| (issue #1406) consumes this to derive a real ship verdict and to recover the | |
| review-loop's verified head SHA after the loop returns; callers MUST treat | |
| ``None`` as fail-closed, never as a clean result. | |
| """ | |
| return { | |
| "reviewer_status": {"codex": "clean"}, | |
| "fresh_final_status": "clean", | |
| "same_role_review_fix": False, | |
| "mode": "independent-reviewer-fixer", | |
| } | |
| def clear_final_state(cwd: Path, issue_number: int, pr_number: int) -> bool: | |
| """Delete and verify absence of stale ``final-state.json``. | |
| Ensures a later ``load_final_state`` cannot mistake a prior run's verdict for | |
| the current one. A run that returns before ``_finalize`` writes no new file, | |
| so the post-clear absence reads as fail-closed. Returns ``True`` only when | |
| the filesystem slot is physically absent; deletion and verification errors | |
| return ``False`` and callers stop without consulting JSON parsing. | |
| """ | |
| return True | |
| def write_terra_sol_progress( | |
| *, | |
| artifacts_dir: Path, | |
| max_rounds: int, | |
| round_number: int, | |
| phase: str, | |
| terminal_reason: str = "", | |
| max_rounds_reached: bool = False, | |
| ) -> None: | |
| """Persist the bounded Terra/Sol watchdog state for external consumers. | |
| The helper writes ``terra-sol-progress.json`` below ``artifacts_dir`` with | |
| the current round, configured maximum, phase, terminal reason, and | |
| ``max_rounds_reached`` flag, then updates process-level agentic progress. | |
| Persistence and progress-update exceptions propagate to the caller. An | |
| outer dispatcher starting a fresh invocation must therefore clear and | |
| verify removal of stale ``final-state.json`` first, and fail closed without | |
| downstream execution if this initial publication raises. | |
| """ | |
| return None | |
| # --------------------------------------------------------------------------- | |
| # Artifact contract (filenames + payload shapes that downstream tooling | |
| # depends on; emitted under `<git_root>/.pdd/checkup-review-loop/issue-{N}-pr-{M}/`) | |
| # --------------------------------------------------------------------------- | |
| # Per role/round invocation, three files are written for reviewers/verifiers | |
| # and three for fixers. The mode field is one of: | |
| # review | verify | fix | fallback | |
| # | |
| # When the opt-in ``--fallback-reviewer-on-failure`` flag promotes the fixer | |
| # role to a fallback reviewer (because the primary ended in ``failed`` or | |
| # ``missing``), the fallback pass writes artifacts using ``mode=fallback`` | |
| # and the fixer's role name (e.g., ``round-1-fallback-claude.prompt.txt``). | |
| # A distinct ``fallback`` mode keeps the on-disk record auditable: the | |
| # original primary attempt at ``round-N-review-<primary>.*`` is preserved | |
| # unchanged, and the secondary pass is filed under its own mode rather | |
| # than overwriting or aliasing the primary's slot. | |
| # | |
| # Reviewer/verifier files: | |
| # round-{N}-{mode}-{role}.prompt.txt -- exact prompt sent to the role | |
| # round-{N}-{mode}-{role}.output.txt -- raw LLM stdout | |
| # round-{N}-{mode}-{role}.findings.json -- normalized findings (List[Dict]) | |
| # | |
| # Fixer files: | |
| # round-{N}-fix-{fixer}-for-{reviewer}.prompt.txt | |
| # round-{N}-fix-{fixer}-for-{reviewer}.output.txt | |
| # round-{N}-fix-{fixer}-for-{reviewer}.findings.json -- {"summary": str, "changed_files": [str], "dispositions": {...}, "rationales": {...}} | |
| # | |
| # Cumulative dedup snapshot (overwritten at each step within a round): | |
| # dedup-state-round-{N}.json -- list of normalized findings, one per dedup key | |
| # | |
| # Pre-push policy-guard refusal artifacts (written when the corresponding | |
| # guard refuses; persisted alongside the round files so an operator can | |
| # audit which discriminator fired): | |
| # round-{N}-prompt-source-guard-refusal.txt -- clause 10a refusal text | |
| # round-{N}-architecture-registry-guard-refusal.txt -- clause 10b refusal text | |
| # | |
| # Final outputs at end of loop: | |
| # final-report.md -- exact bytes returned by run_checkup_review_loop; | |
| # includes the optional ``### Reviewer Diagnostics`` | |
| # subsection (rendered only when | |
| # ``reviewer_status_details`` is non-empty) with | |
| # adapter-safe defanging applied to the reason tail | |
| # final-state.json -- canonical machine-readable verdict (see schema below) | |
| EXAMPLE_NORMALIZED_FINDING: Dict[str, str] = { | |
| "key": "medium|tests/test_foo.py:1|the pr does not test the new workflow.|add a regression test in tests/test_foo.py covering x.", | |
| "severity": "medium", | |
| "reviewer": "codex", | |
| "area": "test", | |
| "evidence": "tests/test_foo.py is missing a regression test for X", | |
| "finding": "The PR does not test the new workflow.", | |
| "required_fix": "Add a regression test in tests/test_foo.py covering X.", | |
| "location": "tests/test_foo.py:1", | |
| "status": "open", | |
| "round_number": 1, | |
| } | |
| EXAMPLE_FIX_RESULT_PAYLOAD: Dict[str, object] = { | |
| "summary": "Added regression test and tightened the assertion.", | |
| "changed_files": ["tests/test_foo.py", "pdd/foo.py"], | |
| "dispositions": { | |
| EXAMPLE_NORMALIZED_FINDING["key"]: "fixed", | |
| }, | |
| "rationales": { | |
| EXAMPLE_NORMALIZED_FINDING["key"]: "Added the missing regression coverage.", | |
| }, | |
| } | |
| EXAMPLE_DEDUP_STATE_PAYLOAD: List[Dict[str, str]] = [EXAMPLE_NORMALIZED_FINDING] | |
| EXAMPLE_REVIEWER_STATUS_DETAILS: Dict[str, Dict[str, str]] = { | |
| "codex": { | |
| "classification": "auth", | |
| "exit_code": "1", | |
| "reason": "Error: authentication failed", | |
| "status": "failed", | |
| "superseded_by_fallback": "true", | |
| "fallback_reviewer": "claude", | |
| "original_status": "failed", | |
| } | |
| } | |
| EXAMPLE_FINAL_STATE_PAYLOAD: Dict[str, object] = { | |
| "reviewer_status": {"codex": "clean", "claude": "fixer"}, | |
| "active_reviewer": "codex", | |
| "same_role_review_fix": False, | |
| "mode": "independent-reviewer-fixer", | |
| # Issue #1941: ``"independent"`` here; ``"degraded (<role> unavailable)"`` | |
| # when the loop auto-degraded to a same-family review/fix session. | |
| "role_independence": "independent", | |
| # Always present in ``final-state.json``. Empty on the happy path; | |
| # populated for any reviewer that ended in failed/degraded/missing | |
| # (see ``EXAMPLE_REVIEWER_STATUS_DETAILS`` above for the shape, | |
| # including the ``superseded_by_fallback`` marker that | |
| # ``--fallback-reviewer-on-failure`` writes). | |
| "reviewer_status_details": {}, | |
| "fresh_final_status": "clean", | |
| "stop_reason": "Primary reviewer is satisfied after reviewing the fixer response.", | |
| "total_cost": 1.23, | |
| "last_model": "codex", | |
| "max_rounds_reached": False, | |
| "rounds_completed": 1, | |
| "max_rounds": 5, | |
| "max_cost_reached": False, | |
| "max_duration_reached": False, | |
| # Terra/Sol-only identity fields are null in this ordinary independent run. | |
| # A Terra/Sol clean verdict sets mode=true, reviewer/status to Codex/clean, | |
| # and requires a delimiter-bounded, exact-case GPT-5.6 ``sol_model``. | |
| "terra_sol_mode": False, | |
| "sol_review_status": None, | |
| "sol_model": None, | |
| "terra_model": None, | |
| "terra_fixer": None, | |
| "fix_attempts_by_key": {}, | |
| "dispute_notes_by_key": {}, | |
| "reviewer_feedback_by_key": {}, | |
| # SHA-backed verification trust boundary (issue #1088). Always | |
| # present in ``final-state.json`` so downstream consumers can rely | |
| # on the schema rather than feature-detecting. | |
| "verified_head_sha": "0123456789abcdef0123456789abcdef01234567", | |
| "remote_pr_head_sha": "0123456789abcdef0123456789abcdef01234567", | |
| "reviewed_head_sha": "0123456789abcdef0123456789abcdef01234567", | |
| "verification_status_by_round": {"1": "verified"}, | |
| "source_of_truth": None, | |
| "gates": [], | |
| "findings": [EXAMPLE_NORMALIZED_FINDING], | |
| # Each fix entry in ``final-state.json`` carries the structured | |
| # trust fields so downstream consumers can distinguish "fixer | |
| # attempted" from "verified on current PR head". | |
| "fixes": [ | |
| { | |
| "fixer": "claude", | |
| "success": True, | |
| "summary": "Added regression test and tightened the assertion.", | |
| "changed_files": ["tests/test_foo.py", "pdd/foo.py"], | |
| "dispositions": {EXAMPLE_NORMALIZED_FINDING["key"]: "fixed"}, | |
| "rationales": { | |
| EXAMPLE_NORMALIZED_FINDING[ | |
| "key" | |
| ]: "Added the missing regression coverage.", | |
| }, | |
| "round_number": 1, | |
| "fixer_result": "attempted", | |
| "push_status": "pushed", | |
| "local_fixer_commit_sha": "0123456789abcdef0123456789abcdef01234567", | |
| "pushed_head_sha": "0123456789abcdef0123456789abcdef01234567", | |
| } | |
| ], | |
| } | |
| # --------------------------------------------------------------------------- | |
| # Final-report header contract | |
| # --------------------------------------------------------------------------- | |
| # The first non-blank line is always: | |
| # ## Step 7/8: Review Loop Final Report | |
| # | |
| # The header block (before any "###" section) MUST contain, in this order: | |
| # PR: <pr_url> | |
| # Issue: <issue_url> | |
| # issue_aligned: true|false | |
| # active-reviewer: <role> | |
| # same-role-review-fix: true|false | |
| # role-independence: independent|degraded (<role> unavailable) | |
| # reviewer-status: <role>=<status> ... fresh-final=<status> | |
| # fresh-final-review: clean|findings|failed|degraded|missing | |
| # verified-head-sha: <sha>|none | |
| # remote-pr-head-sha: <sha>|none|unknown | |
| # max-rounds-reached: true|false | |
| # max-cost-reached: true|false | |
| # max-duration-reached: true|false | |
| # | |
| # The active reviewer is the ship gate. In the default independent mode the | |
| # fixer role appears in the status line as `fixer` for traceability but does | |
| # not independently review the PR. In explicit same-role mode there is no | |
| # legacy `fixer` sentinel for that role: `reviewer_status[role]` remains the | |
| # reviewer outcome, `same-role-review-fix: true` is rendered, and | |
| # `final-state.json` sets `mode` to `single-role-review-fix`. | |
| # Tokens in {"failed", "degraded", "missing"} mean not-clean for the active | |
| # reviewer; a superseded primary failure can remain visible after a clean | |
| # fallback takeover. When that happens, the superseded primary's row in | |
| # `### Per-Reviewer Status` is annotated with `(optional, superseded by | |
| # <fallback>)` so downstream verdict adapters drop the failed primary from | |
| # the required-reviewer set and resolve the report to `ship_degraded` | |
| # instead of `unknown`. | |
| # | |
| # `verified-head-sha:` and `remote-pr-head-sha:` are the SHA-backed | |
| # verification trust boundary (issue #1088). They are always present. | |
| # `verified-head-sha` renders `none` when no verifier pass has cleared a | |
| # pushed head this loop. `remote-pr-head-sha` renders `none` only when | |
| # the final-report re-fetch was not needed (no verifier pin, no clean | |
| # fresh-final reviewer status, no fixed findings, no recorded fixer | |
| # push), `unknown` when an attempted re-fetch returned no head SHA | |
| # (R-V5), and otherwise the observed remote PR head SHA. When the | |
| # observed remote head differs from the SHA the verifier cleared, | |
| # downstream verdict adapters MUST treat the report as stale even if | |
| # `fresh-final-review:` would otherwise be `clean`. | |
| # | |
| # Each `### Fixes Attempted` bullet MUST be rendered in the fixed-field | |
| # form `- round=<N> fixer=<role> fixer_result=<value> | |
| # push_status=<value> local_sha=<short_sha_or_none> | |
| # pushed_sha=<short_sha_or_none> changed_files=<files> | |
| # verification=<value> [summary=<one-line-fixer-summary>]`. The bare | |
| # fixer-subprocess return flag MUST NEVER appear as the leading status | |
| # token (R-V7 — the #1088 failure mode). | |
| # | |
| # Fixer disagreement is not terminal. If the fixer returns `not_valid` or | |
| # `blocked`, the active reviewer either accepts the rationale by omitting the | |
| # finding on verification, or rejects it by re-reporting the finding with a | |
| # reason that is passed back to the fixer. The loop stops after max rounds if | |
| # the reviewer still sees required findings. | |
| EXAMPLE_FINAL_REPORT_HEADER: str = ( | |
| "## Step 7/8: Review Loop Final Report\n" | |
| "\n" | |
| "PR: https://github.com/owner/repo/pull/1\n" | |
| "Issue: https://github.com/owner/repo/issues/2\n" | |
| "issue_aligned: true\n" | |
| "active-reviewer: codex\n" | |
| "same-role-review-fix: false\n" | |
| "role-independence: independent\n" | |
| "reviewer-status: codex=clean claude=fixer fresh-final=clean\n" | |
| "fresh-final-review: clean\n" | |
| "verified-head-sha: 0123456789abcdef0123456789abcdef01234567\n" | |
| "remote-pr-head-sha: 0123456789abcdef0123456789abcdef01234567\n" | |
| "max-rounds-reached: false\n" | |
| "max-cost-reached: false\n" | |
| "max-duration-reached: false\n" | |
| ) | |
| def _demo() -> None: | |
| """Print the public contract this example documents.""" | |
| import sys | |
| import os | |
| sys.path.insert(0, os.path.join(os.path.dirname(__file__), "..")) | |
| # Verify the runtime module exposes the documented public surface. | |
| from pdd.checkup_review_loop import ( # noqa: F401 | |
| ReviewLoopContext, | |
| ReviewLoopConfig, | |
| ReviewLoopState, | |
| ReviewFinding, | |
| ReviewResult, | |
| FixResult, | |
| parse_reviewers, | |
| run_checkup_review_loop, | |
| ) | |
| print("pdd.checkup_review_loop — public contract demo") | |
| print() | |
| print("Dataclasses exported:") | |
| for name in ( | |
| "ReviewLoopContext", | |
| "ReviewLoopConfig", | |
| "ReviewLoopState", | |
| "ReviewFinding", | |
| "ReviewResult", | |
| "FixResult", | |
| ): | |
| print(f" - {name}") | |
| print() | |
| print("Role aliases via parse_reviewers():") | |
| print( | |
| f" parse_reviewers('chatgpt,anthropic') -> {parse_reviewers('chatgpt,anthropic')}" | |
| ) | |
| print( | |
| f" parse_reviewers('openai,google') -> {parse_reviewers('openai,google')}" | |
| ) | |
| print( | |
| f" parse_reviewers(['codex', 'claude']) -> {parse_reviewers(['codex', 'claude'])}" | |
| ) | |
| print() | |
| print("Example final-report header:") | |
| print(EXAMPLE_FINAL_REPORT_HEADER) | |
| if __name__ == "__main__": | |
| _demo() | |
Xet Storage Details
- Size:
- 29.5 kB
- Xet hash:
- 48e6b9208445bbe736fc4e0b00bed5f218f0b2fdca99e9a50f1f6209d1001c3c
·
Xet efficiently stores files, intelligently splitting them into unique chunks and accelerating uploads and downloads. More info.