dbt-databricks PR-readiness driver
Input is a URL or bare number for databricks/dbt-databricks, plus optional
--auto. If no PR is supplied, run gh pr view without --repo from the
current branch and use the result only when it resolves exactly one PR in
databricks/dbt-databricks; otherwise ask for the URL or number. For an
explicit URL or number, use gh pr view <input> --repo databricks/dbt-databricks.
--auto selects recommended gaps only. It never authorizes a commit or push.
The deliverable is an assessment report and, only when the caller can write the
PR head branch and approves each gate, verified commits on that branch.
Hard rules
- Never merge, comment on, label, retarget, or create a PR.
- Never rewrite history, rebase silently, or discard local work.
- Never commit or push without explicit user approval after showing the changes
and verification evidence.
--auto does not bypass either approval.
- Run and read every selected test and lint command. Commit only verified work.
- Stop if the PR head moves after the run starts. Never overwrite a contributor's
newer head.
- Never make tracked repairs in the repository's shared primary checkout. Do
writable work in a git worktree that is not that checkout. Use the worktree
the active harness already supplied, or create one; its location does not
matter. Keep the run report under the primary checkout's ignored
.agents/pr-ready/ directory.
- Do not put run reports, generated evaluation output, personal paths, accounts,
or local tooling details into committed files. The co-located
eval-spec.md
is a checked-in behavioral contract, not run output.
Phase 1 — Resolve the PR, write scope, and worktree
Set ACTIVE_ROOT to git rev-parse --show-toplevel, COMMON_GIT_DIR to
git -C "$ACTIVE_ROOT" rev-parse --git-common-dir resolved against
ACTIVE_ROOT when the result is relative, PRIMARY_ROOT to the parent of
COMMON_GIT_DIR, and REPO to databricks/dbt-databricks. Require a
non-bare repository whose common Git directory is PRIMARY_ROOT/.git, and
require at least one configured remote whose normalized GitHub slug is
exactly REPO; otherwise stop before any mutation.
Set REPORT to $PRIMARY_ROOT/.agents/pr-ready/pr-<N>/report.md. Do not
use PRIMARY_ROOT as the repair worktree.
Confirm gh auth status, capture ME with gh api user -q .login, and
fetch PR metadata including its state, draft status, author, base branch,
head branch, head SHA, head repository, head repository owner,
isCrossRepository, maintainerCanModify, mergeable,
statusCheckRollup, closingIssuesReferences, and files.
Re-query an initially UNKNOWN mergeability result before treating it as a
verdict. Stop for a closed or merged PR, a missing head repository, or a
missing head ref. Draft PRs are valid inputs.
Record SOURCE_SHA=headRefOid. Derive HEAD_SLUG from
headRepositoryOwner.login and headRepository.name; do not use
headRepository.nameWithOwner. Prefer an existing Git remote whose URL
normalizes to that exact slug. Otherwise use
https://github.com/<HEAD_SLUG>.git directly without adding a persistent
remote or guessing from the branch name.
Classify branch write access before proposing repairs:
| PR head |
Write mode |
Head repository owner is ME |
owner — the contributor may update their own fork branch. |
PR is in REPO and the caller has ADMIN, MAINTAIN, or WRITE viewer permission |
repository — update the in-repository head branch. |
Fork PR, maintainerCanModify is true, and the caller has upstream ADMIN, MAINTAIN, or WRITE permission |
maintainer — update that contributor's fork head branch. |
| Any other case |
read-only — assess only; do not edit, commit, or push. |
Obtain upstream viewer permission with gh repo view "$REPO" --json viewerPermission. The PR author is never a hard stop. maintainerCanModify
controls only the third row; it is not required for an in-repository PR or
for the contributor's own fork.
For owner, repository, or maintainer mode, fetch the exact source ref
into refs/pr-ready/<N>/head and verify it equals SOURCE_SHA. Do not use
gh pr checkout: it does not provide a stable, unambiguous push target for
this workflow.
- If
ACTIVE_ROOT differs from PRIMARY_ROOT, set WT to ACTIVE_ROOT.
Require it to use COMMON_GIT_DIR and to have an empty
git status --porcelain (do not pass --ignored). If HEAD equals the
fetched source ref, keep it. If HEAD differs and the current commit is
detached and not reachable from any local branch or remote-tracking ref,
do not check out into that worktree; create a different detached worktree
at the fetched ref using the host's usual worktree location and set WT
to that path. Otherwise check out the exact fetched ref detached.
- If
ACTIVE_ROOT equals PRIMARY_ROOT, create a detached worktree at the
fetched ref using the host's usual worktree location and set WT to that
path. When creating a worktree, if the chosen path already exists and
diverges, pick another path or stop; never discard its work.
- Do not create symlinks or shared configuration inside the worktree.
- In
read-only mode, do not create, check out, edit, or configure WT.
Gather assessment evidence from PR metadata, the PR diff, public check
output, and other non-mutating reads instead.
After WT is final in a writable mode, require
git -C "$WT" rev-parse --show-toplevel to equal WT and to differ from
PRIMARY_ROOT, then verify HEAD equals SOURCE_SHA before edits. Run
every later edit, test, and git command with WT as the working directory.
If the host can retarget the visible workspace root, do that immediately;
if it cannot, keep using explicit paths under WT and do not edit
PRIMARY_ROOT.
In a writable mode only, install pre-commit hooks in WT when
core.hooksPath is unset. When it is set, record that hooks are configured
externally. Never install or run pre-commit hooks in read-only mode; hooks
may mutate files. The explicit all-files pre-commit run in Phase 5 remains
mandatory for writable runs.
Create the report skeleton at REPORT, noting PR URL, SOURCE_SHA, write
mode, resolved head slug, and worktree path.
Phase 2 — Assessment
Read references/rubric.md and evaluate every item against the PR metadata and
diff. The report must contain one met, gap, or n-a row per item;
each gap needs evidence, a one-line fix, rough effort, and its recommended or
optional status. If there are no gaps, mark the PR merge-ready as-is and stop.
Phase 3 — Selection
- Interactive mode: present each gap as a selectable option, recommended items
first, and record the user's selection.
--auto: select every recommended gap and record optional gaps as
skipped-by-policy.
Selection authorizes edits and verification only. It does not authorize a
commit or push. In read-only mode, report the selected fixes but do not start
an edit; explain that the PR head is not writable by the current caller,
finalize the assessment and selection report, and stop immediately. Do not
enter Phase 4 or Phase 5, edit a worktree, or invoke a mutating hook.
Phase 4 — Repair selected gaps
Work selected items in this order: code and test changes, lint, then changelog.
For every item, follow the rubric's fix recipe and read the resulting test
output. Review the run's additions for unnecessary complexity, show the exact
diff and test evidence, and obtain explicit commit approval. After approval and
immediately before the commit, re-check that the PR head still equals
SOURCE_SHA. Commit only that verified item and never add attribution footers.
After three unsuccessful repair attempts or an unavailable required service,
mark the item blocked. If the run created a partial diff, preserve it with
untracked files in a clearly named stash, for example:
git stash push --include-untracked \
-m "pr-ready #<N>: blocked <rubric-item> partial repair"
Record the stash reference and name in the report, then require
git status --porcelain to be empty. If the stash cannot be created or the
worktree cannot be made clean without discarding work, stop the entire run.
Only after successful preservation and cleanup may independent selected items
continue. Apply the same preservation rule before any hard stop that leaves
run-created changes, including a moved-head stop; never apply a blocked-item
stash during final verification.
Phase 5 — Final verification and push
Require git status --porcelain to be empty, record
VERIFIED_SHA=$(git rev-parse HEAD), and confirm the index and worktree have
no diff from HEAD. From WT, run
hatch run pre-commit run --all-files; it must pass without changing the
worktree. If it creates a diff, final verification fails; handle that diff
as a separately approved repair or preserve it and stop.
Re-run every test touched by the selected repairs and read the output.
Require HEAD still to equal VERIFIED_SHA and the worktree still to be
clean afterward. This verification covers committed HEAD only; results
from a leftover partial diff do not count.
Finalize REPORT with the assessment table, selection method, write mode,
per-item outcome and evidence, blocked items, and pre-existing noise.
If no local commits were created, stop after the report.
Before pushing, show the exact destination and ask for explicit approval.
After approval and immediately before the push:
- Re-query
CURRENT_ME=$(gh api user -q .login) and require it to equal the
captured ME.
- Re-fetch the PR's head SHA, head ref, head repository and owner,
isCrossRepository, and maintainerCanModify, plus the upstream
viewerPermission.
- Recompute the Phase 1 write mode from those fresh values. Require the
applicable ownership, repository permission, or opted-in maintainer
condition still to hold, the result still to equal the captured writable
mode, and the resolved head repository and branch still to match the
approved destination.
- Require the fresh remote head SHA to equal
SOURCE_SHA, local HEAD to
equal VERIFIED_SHA, and the worktree to remain clean.
If any check fails, do not push. Otherwise push only to the resolved head
repository and branch with the exact-SHA lease:
git push --force-with-lease="refs/heads/<headRefName>:<SOURCE_SHA>" \
<resolved-head-remote-or-url> HEAD:refs/heads/<headRefName>
If the lease or permission check fails, do not retry with a broader force
option; leave commits local and report the failure. After a successful push,
verify that the PR head equals local HEAD and record that SHA in REPORT.
1---2name: dbt-databricks-pr-ready3description: Use for an open dbt-databricks pull request, including your own PR or a fork PR, to assess merge readiness and optionally repair selected gaps on the PR head branch. Accepts a PR link or number and optional --auto.4---56# dbt-databricks PR-readiness driver78Input is a URL or bare number for `databricks/dbt-databricks`, plus optional9`--auto`. If no PR is supplied, run `gh pr view` without `--repo` from the10current branch and use the result only when it resolves exactly one PR in11`databricks/dbt-databricks`; otherwise ask for the URL or number. For an12explicit URL or number, use `gh pr view <input> --repo databricks/dbt-databricks`.13`--auto` selects recommended gaps only. It never authorizes a commit or push.1415The deliverable is an assessment report and, only when the caller can write the16PR head branch and approves each gate, verified commits on that branch.1718## Hard rules1920- Never merge, comment on, label, retarget, or create a PR.21- Never rewrite history, rebase silently, or discard local work.22- Never commit or push without explicit user approval after showing the changes23 and verification evidence. `--auto` does not bypass either approval.24- Run and read every selected test and lint command. Commit only verified work.25- Stop if the PR head moves after the run starts. Never overwrite a contributor's26 newer head.27- Never make tracked repairs in the repository's shared primary checkout. Do28 writable work in a git worktree that is not that checkout. Use the worktree29 the active harness already supplied, or create one; its location does not30 matter. Keep the run report under the primary checkout's ignored31 `.agents/pr-ready/` directory.32- Do not put run reports, generated evaluation output, personal paths, accounts,33 or local tooling details into committed files. The co-located `eval-spec.md`34 is a checked-in behavioral contract, not run output.3536## Phase 1 — Resolve the PR, write scope, and worktree37381. Set `ACTIVE_ROOT` to `git rev-parse --show-toplevel`, `COMMON_GIT_DIR` to39 `git -C "$ACTIVE_ROOT" rev-parse --git-common-dir` resolved against40 `ACTIVE_ROOT` when the result is relative, `PRIMARY_ROOT` to the parent of41 `COMMON_GIT_DIR`, and `REPO` to `databricks/dbt-databricks`. Require a42 non-bare repository whose common Git directory is `PRIMARY_ROOT/.git`, and43 require at least one configured remote whose normalized GitHub slug is44 exactly `REPO`; otherwise stop before any mutation.4546 Set `REPORT` to `$PRIMARY_ROOT/.agents/pr-ready/pr-<N>/report.md`. Do not47 use `PRIMARY_ROOT` as the repair worktree.482. Confirm `gh auth status`, capture `ME` with `gh api user -q .login`, and49 fetch PR metadata including its state, draft status, author, base branch,50 head branch, head SHA, head repository, head repository owner,51 `isCrossRepository`, `maintainerCanModify`, `mergeable`,52 `statusCheckRollup`, `closingIssuesReferences`, and `files`.53 Re-query an initially `UNKNOWN` mergeability result before treating it as a54 verdict. Stop for a closed or merged PR, a missing head repository, or a55 missing head ref. Draft PRs are valid inputs.563. Record `SOURCE_SHA=headRefOid`. Derive `HEAD_SLUG` from57 `headRepositoryOwner.login` and `headRepository.name`; do not use58 `headRepository.nameWithOwner`. Prefer an existing Git remote whose URL59 normalizes to that exact slug. Otherwise use60 `https://github.com/<HEAD_SLUG>.git` directly without adding a persistent61 remote or guessing from the branch name.624. Classify branch write access before proposing repairs:6364 | PR head | Write mode |65 |---|---|66 | Head repository owner is `ME` | `owner` — the contributor may update their own fork branch. |67 | PR is in `REPO` and the caller has `ADMIN`, `MAINTAIN`, or `WRITE` viewer permission | `repository` — update the in-repository head branch. |68 | Fork PR, `maintainerCanModify` is true, and the caller has upstream `ADMIN`, `MAINTAIN`, or `WRITE` permission | `maintainer` — update that contributor's fork head branch. |69 | Any other case | `read-only` — assess only; do not edit, commit, or push. |7071 Obtain upstream viewer permission with `gh repo view "$REPO" --json72 viewerPermission`. The PR author is never a hard stop. `maintainerCanModify`73 controls only the third row; it is not required for an in-repository PR or74 for the contributor's own fork.755. For `owner`, `repository`, or `maintainer` mode, fetch the exact source ref76 into `refs/pr-ready/<N>/head` and verify it equals `SOURCE_SHA`. Do not use77 `gh pr checkout`: it does not provide a stable, unambiguous push target for78 this workflow.79 - If `ACTIVE_ROOT` differs from `PRIMARY_ROOT`, set `WT` to `ACTIVE_ROOT`.80 Require it to use `COMMON_GIT_DIR` and to have an empty81 `git status --porcelain` (do not pass `--ignored`). If `HEAD` equals the82 fetched source ref, keep it. If `HEAD` differs and the current commit is83 detached and not reachable from any local branch or remote-tracking ref,84 do not check out into that worktree; create a different detached worktree85 at the fetched ref using the host's usual worktree location and set `WT`86 to that path. Otherwise check out the exact fetched ref detached.87 - If `ACTIVE_ROOT` equals `PRIMARY_ROOT`, create a detached worktree at the88 fetched ref using the host's usual worktree location and set `WT` to that89 path. When creating a worktree, if the chosen path already exists and90 diverges, pick another path or stop; never discard its work.91 - Do not create symlinks or shared configuration inside the worktree.92 - In `read-only` mode, do not create, check out, edit, or configure `WT`.93 Gather assessment evidence from PR metadata, the PR diff, public check94 output, and other non-mutating reads instead.95 After `WT` is final in a writable mode, require96 `git -C "$WT" rev-parse --show-toplevel` to equal `WT` and to differ from97 `PRIMARY_ROOT`, then verify `HEAD` equals `SOURCE_SHA` before edits. Run98 every later edit, test, and git command with `WT` as the working directory.99 If the host can retarget the visible workspace root, do that immediately;100 if it cannot, keep using explicit paths under `WT` and do not edit101 `PRIMARY_ROOT`.1026. In a writable mode only, install pre-commit hooks in `WT` when103 `core.hooksPath` is unset. When it is set, record that hooks are configured104 externally. Never install or run pre-commit hooks in `read-only` mode; hooks105 may mutate files. The explicit all-files pre-commit run in Phase 5 remains106 mandatory for writable runs.1077. Create the report skeleton at `REPORT`, noting PR URL, `SOURCE_SHA`, write108 mode, resolved head slug, and worktree path.109110## Phase 2 — Assessment111112Read `references/rubric.md` and evaluate every item against the PR metadata and113diff. The report must contain one **met**, **gap**, or **n-a** row per item;114each gap needs evidence, a one-line fix, rough effort, and its recommended or115optional status. If there are no gaps, mark the PR merge-ready as-is and stop.116117## Phase 3 — Selection118119- Interactive mode: present each gap as a selectable option, recommended items120 first, and record the user's selection.121- `--auto`: select every recommended gap and record optional gaps as122 skipped-by-policy.123124Selection authorizes edits and verification only. It does not authorize a125commit or push. In `read-only` mode, report the selected fixes but do not start126an edit; explain that the PR head is not writable by the current caller,127finalize the assessment and selection report, and stop immediately. Do not128enter Phase 4 or Phase 5, edit a worktree, or invoke a mutating hook.129130## Phase 4 — Repair selected gaps131132Work selected items in this order: code and test changes, lint, then changelog.133For every item, follow the rubric's fix recipe and read the resulting test134output. Review the run's additions for unnecessary complexity, show the exact135diff and test evidence, and obtain explicit commit approval. After approval and136immediately before the commit, re-check that the PR head still equals137`SOURCE_SHA`. Commit only that verified item and never add attribution footers.138139After three unsuccessful repair attempts or an unavailable required service,140mark the item blocked. If the run created a partial diff, preserve it with141untracked files in a clearly named stash, for example:142143```bash144git stash push --include-untracked \145 -m "pr-ready #<N>: blocked <rubric-item> partial repair"146```147148Record the stash reference and name in the report, then require149`git status --porcelain` to be empty. If the stash cannot be created or the150worktree cannot be made clean without discarding work, stop the entire run.151Only after successful preservation and cleanup may independent selected items152continue. Apply the same preservation rule before any hard stop that leaves153run-created changes, including a moved-head stop; never apply a blocked-item154stash during final verification.155156## Phase 5 — Final verification and push1571581. Require `git status --porcelain` to be empty, record159 `VERIFIED_SHA=$(git rev-parse HEAD)`, and confirm the index and worktree have160 no diff from `HEAD`. From `WT`, run161 `hatch run pre-commit run --all-files`; it must pass without changing the162 worktree. If it creates a diff, final verification fails; handle that diff163 as a separately approved repair or preserve it and stop.1642. Re-run every test touched by the selected repairs and read the output.165 Require `HEAD` still to equal `VERIFIED_SHA` and the worktree still to be166 clean afterward. This verification covers committed `HEAD` only; results167 from a leftover partial diff do not count.1683. Finalize `REPORT` with the assessment table, selection method, write mode,169 per-item outcome and evidence, blocked items, and pre-existing noise.1704. If no local commits were created, stop after the report.1715. Before pushing, show the exact destination and ask for explicit approval.172 After approval and immediately before the push:173 - Re-query `CURRENT_ME=$(gh api user -q .login)` and require it to equal the174 captured `ME`.175 - Re-fetch the PR's head SHA, head ref, head repository and owner,176 `isCrossRepository`, and `maintainerCanModify`, plus the upstream177 `viewerPermission`.178 - Recompute the Phase 1 write mode from those fresh values. Require the179 applicable ownership, repository permission, or opted-in maintainer180 condition still to hold, the result still to equal the captured writable181 mode, and the resolved head repository and branch still to match the182 approved destination.183 - Require the fresh remote head SHA to equal `SOURCE_SHA`, local `HEAD` to184 equal `VERIFIED_SHA`, and the worktree to remain clean.185186 If any check fails, do not push. Otherwise push only to the resolved head187 repository and branch with the exact-SHA lease:188189 ```bash190 git push --force-with-lease="refs/heads/<headRefName>:<SOURCE_SHA>" \191 <resolved-head-remote-or-url> HEAD:refs/heads/<headRefName>192 ```193194 If the lease or permission check fails, do not retry with a broader force195 option; leave commits local and report the failure. After a successful push,196 verify that the PR head equals local `HEAD` and record that SHA in `REPORT`.