Pr finish pass

From burin-labs/harn · View interactive version

Pr finish pass is an AI agent skill from the GitHub repository burin-labs/harn. Final-polish pass on the current PR or feature branch before it lands. Rebases on origin/main, force-pushes, drives CI to green, then reviews the diff for correctness/perf/security/reliability bugs, flaky test patterns banned by `make lint-test-patterns`, sloppy comments a senior engineer would not

How to use this skill

Skill file

pr-finish-pass

Final-polish sweep on whatever work is currently in flight. That is

usually a named PR, but it works equally well on an unpushed feature

branch or a session's accumulated diff. The goal is to get the change to

a state a senior reviewer would land without comments.

The sweep is not a generic code review. It targets the recurring

issues this repo accumulates between "the feature works" and "the PR is

landable."

When to use

before opening the PR.

If there is no current branch worth polishing — say so and stop.

Phase 0 — identify the work

Determine the scope before touching anything:

git status --short
git rev-parse --abbrev-ref HEAD                    # current branch
git log --oneline origin/main..HEAD                # commits to ship
gh pr view --json number,state,headRefName,mergeStateStatus 2>/dev/null

If gh pr view returns a PR, you are in PR mode. Otherwise you are

in branch mode — the rebase / CI phases are skipped and you go

straight to the review sweep.

Read the full diff before doing anything else:

git diff origin/main...HEAD

For PRs in PR mode, also read gh pr view --json title,body,comments

and skim review comments — sometimes the easiest finding is one a

reviewer already left.

Phase 1 — rebase on origin/main (PR mode only)

git fetch origin main
git rebase origin/main

Resolve conflicts inline. Common conflict rules in this repo:

owns the generated CHANGELOG.md.

side. Resolve the editable spec/chapters/*.md sources, then run

make sync-language-spec.

in the worktree.

/ make fmt-harn / portal lint as appropriate.

Then force-push with lease:

git push --force-with-lease

Never --force without --with-lease — co-authors may have pushed.

Phase 2 — drive CI to green (PR mode only)

gh pr checks
gh run list --branch "$(git branch --show-current)" --limit 5

For each failing check, fetch the actual log and read it:

gh run view <run-id> --log-failed

Address failures comprehensively — do not paper over them with retries

or continue-on-error. Common categories:

make lint-harn, make fmt-harn and commit the fixes.

HARN_TEST_ONE_NAME and HARN_TEST_ONE_PACKAGE variables. Use

make test-affected when the failure spans a changed crate.

Read the test, read the code under test, and fix the root cause.

--filter <name> reproduces a single case. If a .expected` file

needs updating because user-visible behavior intentionally changed,

do that explicitly — don't blindly accept new output.

npm run portal:lint / npm run portal:build / npm test locally.

make check-trigger-quickref:** these are drift checks. Re-run the

generators and commit the regenerated outputs.

Phase 3.

no longer parses or type-checks. Fix the snippet, not the parser.

Push fixes incrementally; let CI re-run between iterations rather than

batching every guess at once.

If a failure is a known-flaky test unrelated to the diff, re-run the

specific job (gh run rerun <run-id> --failed). Do not silence it.

Phase 3 — the review sweep

This is the substance of the skill. Walk the diff and look for each of

the following classes of finding. Fix every material one inline; note

non-material findings in your end-of-turn summary so the user can

decide whether to address them.

3.1 correctness, performance, security, privacy, reliability

integer overflow on user-controlled arithmetic.

iterator chains over network responses, recursive structures with no

depth cap).

from nested locks, cancellation safety on select! arms.

This crate writes a lot of structured logs — check whether anything

user-controlled or token-shaped can hit them.

invoked from agents — prefer worktree-backed execution.

applied, partial reads handled.

3.2 flaky test patterns

The deflake epic ([#1057]) removed wall-clock polling from the fast

suite. make lint-test-patterns enforces the bans, but it only catches

the literal patterns. Look for the spirit too:

[#1057]: https://github.com/burin-labs/harn/issues/1057

| Pattern | Replacement |

|---|---|

| std::thread::sleep | tokio::time::pause() + advance() |

| tokio::time::sleep outside start_paused = true | start_paused runtime + advance() |

| while … Instant::now() polling loops | EventLog::subscribe() + tokio::time::timeout |

| SystemTime::now() in tests | MockClock / injected timestamp |

| recv_timeout(Duration::from_millis(50)) | tokio::time::timeout on event channel |

| Sleep-then-assert ("wait long enough that the thing happened") | Subscribe to the event the thing emits and wait for it |

| Hand-rolled tokio::spawn + sleep + flag check | OrchestratorHarness / MockProcess |

Also flag:

flag." Even if the lint passes (e.g. it's in an allowlisted file),

this is a deflake liability.

constant or comment justifying the magnitude.

parallel execution will race them.

Reference: docs/src/dev/testing.md has the canonical patterns.

3.3 sloppy comments

Strip every comment that a senior engineer would not have written:

"this used to live in foo.rs", "removed the old fallback path".

Git blame is the historical record.

items, // return the result`. If the comment paraphrases the line

below it, delete it.

open-source, and external integrators read this code. Replace

downstream repository names, internal organization paths, or internal product names with

neutral phrasing. Use "a Harn integrator", "a Harn host", "a Harn

Cloud workspace", or "a downstream Harn consumer."

PR #4567", "needed by the foo flow". Move the rationale to the

commit message / PR description and delete the comment.

docstrings explaining architecture are fine; a 12-line docstring

on a one-line helper is noise.

When in doubt: delete it. The bar is "would removing this comment

confuse a future reader." If the answer is no, it goes.

3.4 cross-crate drift

Changes that look local often silently leave another crate stale. Walk

the checklist for every public-surface change:

(tree-sitter-harn/), VS Code grammar (editors/vscode/),

conformance tests, the owning spec/chapters/*.md source, generated

language-spec projections, and highlight keywords.

but check harn-lint builtin awareness, harn-fmt formatting,

harn-lsp completion, docs (docs/src/), the relevant

docs/llm/harn-quickref*.md, conformance coverage.

diagnostics, portal display of run records.

eval, DAP variable inspection, ACP/A2A surface if exposed, and a

changelog.d/<id>.<category>.md fragment.

options table, conformance, transcripts.

is the one parser; do not add a second. Plus

docs/src/prompt-templating.md, the prompt section of

harn-quickref.md, and conformance/tests/template_*. New

keywords/filters/sections go in

crates/harn-vm/src/stdlib/template/vocabulary.rs; regenerate the

VS Code grammar with make gen-prompt-grammar rather than editing it.

If the diff touches behavior the portal renders, run the portal

locally and check that the affected view still works. Unit tests miss

UI drift.

3.5 DRY / polish

do. (Three near-identical functions: definitely.)

const.

appropriate.

.collect::<Vec<_>>()` round-trips.

But: do not invent abstractions for hypothetical second uses. Three

similar lines is not a refactor opportunity.

3.6 Rust → Harn opportunities

Look for Rust code the diff added that resembles agent orchestration

plumbing. That means sequencing LLM calls, retrying with different

prompts, collecting structured outputs, or branching on tool-use

results. Ask whether it could be a .harn script that composes

primitive host capabilities.

Heuristics:

retries → likely a Harn script with parallel settle /

schema_retries.

parallel each.

function.

If the answer is yes, prefer the Harn script form. The Rust side

should be the primitive host capability, not the orchestration. This

is the trust boundary the repo is built on.

If a refactor is too large for the current PR, file an issue naming the

surface to migrate. Link that issue from the PR description.

3.7 prompt prose that belongs in `.harn.prompt` files

Long prompt strings embedded in Rust, or in .harn scripts as inline

literals, should usually live in .harn.prompt files instead. Render

them via template.render / render_prompt(...). Reasons:

Look for:

model.

Move them to .harn.prompt files with a clear name, expose an

override hook, and replace the inline string with a render call.

3.8 overly long files

Files past ~800 lines that span multiple concerns are a refactor

target. Split candidates:

comments → three mod foo files.

formatting, executing) → split it into impl blocks in separate

files. Or break the struct up by concern.

sibling.

Don't split for the sake of splitting; split when the file no longer

fits in a single mental model.

3.9 interpreter perf wins

If the diff touches crates/harn-vm execution paths, look for

patterns that bundle naturally:

scans (or vice versa for large ones).

effectively Copy-sized.

Bundle these only when they touch code already in the diff. Don't open

a "while I'm here" perf rabbit hole that doubles the PR scope.

Phase 4 — re-validate

After making fixes:

make fmt
make lint-harn fmt-harn
./scripts/cargo_with_worktree_build_dir.sh nextest run -p <crate>

For wider changes:

make test
./scripts/harn_bin.sh -- test conformance --filter <relevant>

Then push (git push --force-with-lease if you rewrote history

during the sweep, plain git push otherwise) and let CI run.

Phase 5 — land

Once CI is green and the diff looks landable:

gh pr merge --auto       # let the merge queue land it

Do not pass --squash / --merge / --rebase — branch protection

chooses the strategy.

Anti-patterns

the code.

pattern.

co-author's pushes.

gates; you'll just fail later.

for. Note them in your summary, file follow-ups, move on.

spec/HARN_SPEC.md, docs/theme/harn-keywords.js, or CHANGELOG.md).

Edit spec/chapters/*.md, vocabulary sources, or changelog.d/*, then

regenerate through the owning Make target or release workflow.

Source-of-truth references

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.