Skip to content

chore(agents): port latest pr-review engine mechanism into .agents/#807

Open
0xbulma wants to merge 6 commits into
mainfrom
feat/agents-pr-review-engine-port
Open

chore(agents): port latest pr-review engine mechanism into .agents/#807
0xbulma wants to merge 6 commits into
mainfrom
feat/agents-pr-review-engine-port

Conversation

@0xbulma

@0xbulma 0xbulma commented Jun 19, 2026

Copy link
Copy Markdown
Contributor

Why this is strictly better

This is a Pareto upgrade of the in-repo review system: every capability the current .agents/
stack has is kept, a set of deterministic and stateful capabilities is added on top, and no
published-package source is touched
— zero blast radius on the shipped SDK (repo-metadata /
dev-tooling only, no changeset).

Strictly retained — no regression:

  • All 9 Morpho-specialised personas (morpho-protocol, the §2 forbidden-patterns calibration,
    the §10 CI/release lens, …) — the specialisation the repo's review quality depends on and that the
    generic upstream agents do not encode.
  • The §10 AGENTS.md contract structure and the > Applied by personas: backlinks.
  • The repo-only pr-review-ci verdict mode — which upstream is local-first and doesn't even have.

Strictly added — new functionality:

  • Determinism replaces prose. Line-math, scope-filtering, and dedup move from English the model
    re-derived every run to four bundled, unit-tested TypeScript scripts (build-changed-lines,
    validate-findings, findings-ledger, review-scope) gated by a new agents-engine Vitest
    project (124 tests) + tsc --noEmit + Biome. A regression now fails a gate instead of silently
    degrading review quality.
  • Sharper finding contract. WHAT/FIX schema, ±15-line snapping (snapped_line), INTENT_CONTEXT
    injection (commit message / PR title + body), and a doc-only fast path — findings land on the right
    line with the author's intent in scope.
  • Correctness fix. Merge-base recompute + base-merge warning stops a base-branch merge from
    ballooning the reviewed diff (the upstream case that jumped from 67 → 462 files). The old engine had
    no such guard.
  • Less re-review noise and token cost. The stateful findings ledger
    (net-new / recurring / resolved / suppressed) + idempotency cache make re-reviews on an evolving PR
    cheap and quiet. Both live outside the repo (~/.claude/facets/reviews/), so they add no
    statefulness to the reviewed tree and never trip a clean-tree guard.
  • New surface coverage. A repo-adapted skill-authoring persona on a new HAS_PLUGIN_SKILLS flag
    guards the engine roster ↔ §10 table ↔ persona-backlink invariants.
  • Cheap future re-syncs. Mirroring upstream's pr-review-engine/ layout turns improvements
    landing upstream into a cheap port rather than a divergent re-derivation.

In short: a strict superset of the prior mechanism, bought entirely with repo-metadata /
dev-tooling changes.

What

Brings the repo's in-repo agentic review system up to the latest facets mechanism. Hybrid mirror + full port: restructures .agents/ to mirror upstream's pr-review-engine/ layout (SKILL.md + agents/ + references/ + scripts/) while keeping the 9 Morpho-specialised personas as the agent set.

Decision doc: docs/tibs/TIB-2026-06-19-adopt-latest-facets-review-mechanism.md.

Changes

  • Engine.agents/pr-review-engine/SKILL.md supersedes the English .agents/lib/pr-review-base.md. Adds the WHAT/FIX finding schema, ±15-line snapping (snapped_line), INTENT_CONTEXT injection, merge-base recompute + base-merge warning, doc-only fast path, and EXCLUDE_AGENTS.
  • Deterministic scriptsbuild-changed-lines, validate-findings, findings-ledger (stateful ledger + idempotency cache), review-scope, ported from upstream and gated by a new agents-engine Vitest project (124 tests) + a strict tsconfig.
  • Agents — 9 personas moved to agents/ (+ relinked); new repo-adapted skill-authoring agent on a new HAS_PLUGIN_SKILLS flag; Fix-rubric sections + reference subset ported.
  • Callerspr-review-local gains the idempotency cache + findings ledger + commit-message intent + SSH→HTTPS fetch fallback; pr-review-gh gains PR-title/body intent + PR-keyed ledger + audit trail; pr-review-ci keeps the repo-only verdict mode (upstream has no CI variant); pr-fix wires Fix-rubric discovery.
  • DocsAGENTS.md §10 inventory + persona backlinks rewritten.

Scope / SemVer

Repo-metadata and dev-tooling only — no published-package source touched, no changeset (§7). The live engine invokes the scripts as node …/foo.ts, requiring Node ≥ 22.18 (native TS stripping); documented in SKILL.md rather than bumping the monorepo engines.node.

Verification

  • biome check clean on all changed paths (and under biome.ci.json).
  • agents-engine Vitest project: 124/124 pass; tsc --noEmit clean; jsdoc:coverage:check 41/0.
  • Deterministic dogfood on this branch's real diff: build-changed-lines maps the changed files; ledger round-trip gives net_new → cache_hit → recurring.
  • The 59 pnpm lint (dev-config) errors are pre-existing in frozen deprecated packages — none in this changeset.

🤖 Generated with Claude Code

Restructure the in-repo review system to mirror upstream facets'
pr-review-engine/ layout (hybrid mirror, full port), keeping the 9
Morpho-specialised personas as the agent set.

- new engine spec .agents/pr-review-engine/SKILL.md supersedes the
  English .agents/lib/pr-review-base.md; adds the WHAT/FIX finding
  schema, +/-15 line snapping, INTENT_CONTEXT injection, merge-base
  recompute + base-merge warning, doc-only fast path, EXCLUDE_AGENTS
- deterministic TS scripts (build-changed-lines, validate-findings,
  findings-ledger + idempotency cache, review-scope) under scripts/,
  gated by a new agents-engine Vitest project (124 tests) + strict
  tsconfig
- 9 personas moved to agents/ + new skill-authoring agent
  (HAS_PLUGIN_SKILLS); references subset ported and adapted
- callers repointed: pr-review-local gains Step 2c cache + Step 6b
  ledger + commit-message intent + SSH->HTTPS fetch fallback;
  pr-review-gh gains PR-title/body intent + PR-keyed ledger + audit
  trail; pr-review-ci keeps the repo-only verdict mode; pr-fix wires
  Fix-rubric discovery
- AGENTS.md section 10 inventory + persona backlinks rewritten
- docs/tibs/TIB-2026-06-19 records the decision

Repo-metadata/tooling only - no published-package source touched, no
changeset. Gates: biome clean on changed paths (biome.ci.json too),
agents-engine 124 tests pass, tsc --noEmit clean, jsdoc:coverage 41/0.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@0xbulma 0xbulma self-assigned this Jun 19, 2026
@0xbulma 0xbulma changed the title chore(agents): port latest facets pr-review mechanism into .agents/ chore(agents): port latest pr-review engine mechanism into .agents/ Jun 19, 2026
0xbulma and others added 3 commits June 19, 2026 14:56
list-fix-rubric-agents.sh: drop the CLAUDE_PLUGIN_ROOT branch. It pointed
at the upstream plugin-cache layout (${CLAUDE_PLUGIN_ROOT}/skills/
pr-review-engine/agents), which does not exist in this in-repo port —
with the var set in a plugin host the script resolved to a missing dir
and exited 1, silently breaking /pr-fix's fix-rubric discovery. The
engine's agents/ is always a fixed sibling of scripts/, so the
SCRIPT_DIR-relative fallback is the single correct resolution. Also drop
the stale bats-invariant reference from the usage comment (no bats suite
in this repo).

Verified: with CLAUDE_PLUGIN_ROOT set, the script now lists the 3
fix-rubric agents and exits 0 (was exit 1).

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Closes the parity gap between the repo's own /pr-review-local and the
upstream plugin command. Ports the autonomous review->fix->re-review
loop (--goal, --max-iters) and the --fast cut, adapted to this repo:

- --fast excludes the `documentation` agent (repo's name; upstream's is
  `docs`) via the engine's <EXCLUDE_AGENTS>.
- --goal: pre-flight gates (dirty tree / detached HEAD / red base gate),
  the loop (review -> partition -> stuck/success checks -> batched fix ->
  re-gate -> commit), leaving-the-branch-clean rollback, and a single
  post-convergence ledger stamp. GOAL_CLEAN/ABORTED/STUCK/MAXED sentinels.
- Re-gate is pinned to repo-scoped, non-watch commands (biome check on
  changed files, tsc on the touched tsconfig, `vitest run --project
  <affected>`) — NOT bare `pnpm lint` (pre-existing-red on frozen
  deprecated pkgs) or `pnpm test` (watch mode / fork suite needs RPC).
- No runtime stage / --no-runtime: headless SDK, HAS_ROUTE_UI always
  false, so no GOAL_RUNTIME_RED path.

TIB Future Considerations updated: only pr-review-gh's local->GitHub
ledger reuse remains deferred. Repo-metadata/tooling only — no changeset.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
…w-local

The --goal spec referenced <HAS_ROUTE_UI> in the engine-input angle-bracket
convention, but the ported engine defines only HAS_CI_RELEASE,
HAS_PLUGIN_SKILLS, and HAS_PROTOCOL_SURFACE — HAS_ROUTE_UI is an
upstream-only flag. Reword to plain prose ("headless SDK with no
route-reachable UI") so it no longer reads as a defined-but-missing flag.
Resolves the lone (low) finding from /pr-review-local --goal.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@0xbulma 0xbulma marked this pull request as ready for review June 19, 2026 13:42
@0xbulma 0xbulma requested a review from a team as a code owner June 19, 2026 13:42
Comment thread .agents/pr-review-engine/scripts/validate-findings.ts Outdated
Comment thread .agents/pr-review-engine/scripts/findings-ledger.ts
Comment thread .agents/pr-review-engine/scripts/findings-ledger.ts
Comment thread .agents/pr-review-engine/scripts/validate-findings.ts
Comment thread .agents/pr-review-engine/scripts/validate-findings.ts
Rubilmax
Rubilmax previously approved these changes Jun 19, 2026

@devin-ai-integration devin-ai-integration Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Devin Review found 2 potential issues.

View 1 additional finding in Devin Review.

Open in Devin Review

Comment thread .agents/pr-review-engine/scripts/findings-ledger.ts Outdated
Comment thread .agents/pr-review-engine/scripts/review-scope.ts Outdated

@Foulks-Plb Foulks-Plb left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LFG

Comment thread vitest.config.ts Outdated
Comment thread .agents/pr-review-engine/scripts/review-scope.ts Outdated
Comment thread .agents/pr-review-engine/scripts/review-scope.ts Outdated

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: f27fe459ed

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread .agents/commands/pr-review-local.md
Comment thread .agents/commands/pr-review-local.md Outdated
Comment thread .agents/pr-review-engine/scripts/validate-findings.ts Outdated
Comment thread .agents/commands/pr-review-gh.md
Comment thread .agents/pr-review-engine/scripts/findings-ledger.ts Outdated
Aikido SAST (PR #807) flagged the file reads in the ported review scripts
as potential path-traversal sinks. The diff-derived read in
validate-findings.ts (the markdown fenced-block check) reads
`join(repoRoot, norm)` where `norm` comes from the agent-emitted
finding.file. It is already scope-filtered against the git-produced
changed-files set (which never yields a `..` path), but add an explicit
repoRoot-containment guard as defense-in-depth: resolve the target and
skip the read if it escapes repoRoot (the finding is then kept, not
dropped as a doc-example).

The other flagged reads are operator/caller-controlled (the ledger path
and CLI args in findings-ledger.ts) — not attacker input — so they get
no code change; documented as such on the PR threads.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Scripts:
- findings-ledger.ts, review-scope.ts: fix the isMain guard — use
  `process.argv[1] === fileURLToPath(import.meta.url)` (matching the
  other two scripts) instead of hand-building `file://${process.argv[1]}`,
  which skips percent-encoding and so never matches import.meta.url on a
  checkout path containing spaces, silently no-op'ing main(). (devin, Foulques)
- findings-ledger.ts: a missing/unreadable --findings file now exits 2
  instead of being parsed as `[]` — the empty array would make --write
  mark every open ledger entry `resolved` and silently corrupt the ledger. (Codex)
- validate-findings.ts: write the normalized (repo-relative) path back
  into kept findings — PR/CI callers pass `file` into the GitHub review
  `comments[].path`, which must be repo-relative. (Codex)
- review-scope.ts: docstring pointed at a non-existent `pnpm verify`
  script; point at the `pnpm test` / agents-engine gate. (Foulques)

Caller specs:
- pr-review-local.md: don't stamp the idempotency-cache identity on a run
  with agent failures (would replay REVIEW_INCOMPLETE as REVIEW_CLEAN);
  gate --goal success on FAILED_AGENTS==0 (new GOAL_INCOMPLETE stop). (Codex)
- pr-review-gh.md: apply the PR-keyed findings ledger inside each --watch
  cycle so wontfix/seen findings aren't reposted on every new commit. (Codex)

Tooling:
- bump engines.node to >=22.18 + accurate agents-engine Vitest comment:
  the integration tests spawn `node <script>.ts`, so they need native
  type-stripping; 22.13-22.17 was advertised supported but ran red. (Foulques)

Repo-metadata/tooling only — no published-package source, no changeset.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Comment thread .agents/pr-review-engine/scripts/findings-ledger.ts
Comment thread .agents/pr-review-engine/scripts/findings-ledger.ts
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants