Pg implement
Skill matejformanek/postgres-claude/.claude/skills/pg-implement
Execute a PostgreSQL `planning/<slug>/plan.md` phase-by-phase under upstream-grade discipline — Phase 3 of the PG planner suite. Per-phase commits, per-phase regress/iso/TAP runs, plan-linked commit messages, and a running notes log; enforces .claude/rules/pg-implement-discipline.md (R1-R12 — every commit references the plan slug + phase number; every code claim has a file:line cite; phase-end check must pass before the next phase starts). Use when the user says "/pg-implement <slug>", "implement the plan", "let's start implementing the X plan", "execute the planning/<slug>/plan.md", or has a finalized planning/<slug>/plan.md ready to execute. Skip for ad-hoc coding without a plan (no phase structure), non-PG implementation (app code, infra, scripts), the generic /implement flow (multi-project, doesn't enforce PG R1-R12 rules), and exploratory hacking where the plan is still being shaped (use pg-feature-plan instead).From its SKILL.md
npx -y skills add matejformanek/postgres-claude --skill pg-implementAssembled from the repository path, not quoted from the project. Check it against their README if it does not work.
One thing to look at
- 0 stars0 stars. Stars are a popularity signal and not a quality one, but at this level it is likely that nobody has read this closely except its author, and you would be relying on your own review.
SKILL.md
17.6 KB, ~4.3k tokens by cl100k_base, as published. Nobody here has run it
pg-implement — Phase 3 of the PG planner suite
The third stage. Brainstorm narrowed the design space; Plan made it implementable; Implement walks the plan phase-by-phase while enforcing the discipline rules.
The pairing:
- Phase 1 —
pg-feature-brainstorm(sketch) - Phase 2 —
pg-feature-plan(heavy plan) - Phase 3 —
pg-implement(this skill, executes the plan)
When to use vs the generic /implement
| Project | Use |
|---|---|
Anything PG-related with a planning/<slug>/plan.md | /pg-implement |
| Generic project plan, not PG | Generic /implement |
| Ad-hoc PG coding, no plan | Neither — write a plan first via /pg-plan |
The PG variant exists because PG implementation has unusual
constraints the generic /implement doesn't enforce:
- Per-phase test runs against the dev cluster
- File:line citation discipline (knowledge corpus must stay accurate)
- Plan-linked commit messages (commits reference the plan + phase)
- Upstream-vs-meta commit-message-style split
- Catalog/catversion/WAL-format pre-flight before any touching edit
/pg-restartcadence after backend code changes
Inputs
- Slug (required): the planning directory under
planning/<slug>/. Examples in this repo:sp2-pgstr-maxalloc,cb1-pgcrypto-bomb,sp7-tablefunc-quoting. Thedev/branch mirrors the slug (e.g.feature_sp2_pgstr_maxalloc,feature_server_side_vars). - Must contain
plan.mdproduced bypg-feature-plan. - May contain
brainstorm.md(Phase 1 sketch); read for context, not for procedure. - May contain
notes.md(running log; appended to during this run).
Output
- Code changes inside
dev/on a feature branch (NOT inpostgres-claude/'sknowledge/). planning/<slug>/notes.md— one section per phase, appended as we go: what was edited, what tests ran, what surprised us, what's deferred.- Per-phase commits with the plan-linked message format (§5 below).
- Optionally at the end: a draft commit / patch series under
dev/ready forpatch-submission.
Strict rules — see .claude/rules/pg-implement-discipline.md
This skill is the procedure. The rules file is the constitution. Read both. Where they disagree, the rules win. The non-negotiables:
- One phase at a time. No interleaving phases. Each phase is self-contained per the plan's "Phase-end check".
- Verify before edit (R2). Spot-check 3-5 file:line citations from
the plan against current source before phase 1. Drift signals:
citations off by more than ~20 lines, or naming a since-removed
symbol. If drift > 10% of the spot-checked sample, STOP — re-run
/pg-planto refresh; do not push through with a stale plan. - Phase-end check must pass before the next phase starts. Don't carry breakage forward.
- Per-phase commit. Each phase ends with a commit using the plan- linked message format. No phase ends uncommitted.
- Cite or don't claim applies to commit messages too — any "fixes" / "addresses" claim must point to a specific file:line or plan-section.
- No scope creep (R7). If a phase reveals a needed change outside
the plan's §3 file table, STOP and pick from R7's three paths
(small+coupled → update plan +
Sites:trailer; separate concern → defer to follow-up + record innotes.md; invalidates the phase boundary → escalate for re-plan). Never silently expand scope.
Why per-phase = per-commit + per-test
Two operational reasons every phase ends with a green-tested, plan- linked commit (not "WIP" or "TODO"):
- Bisectability.
git bisectacross a multi-phase patch series is only useful if every commit individually builds and passes the declared phase-end check. A broken commit in the middle of the series poisons bisect for the lifetime of this code. - Per-commit reviewability. When the series eventually goes to
pgsql-hackers via
format-patch, reviewers read commits one at a time. Upstream PG convention is that each commit in a posted series compiles and passes tests on its own — a known-broken "WIP" commit, even one tagged TODO, is grounds for the patch being bounced before review starts.
This is why R3 (no interleaving), R4 (phase-end check before commit),
and the anti-pattern list (no WIP commits, no --amend across
phases) act as one rule, not three.
Forbidden patterns (mirrors rules §Anti-patterns)
- "WIP" commits. Every commit in
dev/is a complete phase. Nowip: more of phase 3. --amendto fix a previous phase's commit. Use a NEW commit with aFixes: <sha>trailer if you genuinely need to correct.- Committing without a
Plan:trailer indev/. If you're committing indev/, you're implementing a plan — name it. - Cherry-picking individual phases. All phases or none.
- Mixing meta-repo +
dev/writes in one bash invocation (R10).
Method
For each phase in planning/<slug>/plan.md §8 "Phased implementation":
Step 0 — verify hooks installed (once per session)
Before phase 1, confirm dev/.git/hooks/pre-commit exists and contains
the # pg-precommit-guard v1 marker. If not, run /pg-install-hooks
(idempotent; safe to re-run). The hook is what enforces R4 +
R13's format-check + scoped-test gate automatically — without it, the
per-phase commit step still works but the guarantees in R4 are
back to "Claude remembers". Re-cloning dev/ (/pg-reclone-dev) wipes
dev/.git/hooks/ and the next /setup-pg reinstalls automatically.
Pre-phase (5 min)
- Read the phase's "Files this phase touches" + "5-10 concrete edits"
- "Phase-end check".
- Spot-check the file:line citations against current source. Grep for any function name or symbol cited; verify line numbers within ±20. If drift, escalate to user before continuing.
- Re-read the relevant subsystem doc (
knowledge/subsystems/X.md) and the per-file docs for files being edited. Note any invariants (INV-*tags) that the phase touches. - Confirm the dev cluster is stopped if a postmaster restart will be needed (catalog edits, GUC additions). Otherwise leave it running for fast feedback.
Edit (the main work)
- Make the 5-10 edits per the phase plan. Use
Edit(not Write) wherever possible — preserves surrounding context and reviews cleanly. - After each edit, run a quick build if the file is in
src/backend:cd dev/build-debug && ninja install 2>&1 | tail -5. Catch compile errors immediately, not at phase end. - Track every edit in
planning/<slug>/notes.mdas you go:- File + line range + one-sentence what.
- Anything that surprised you (e.g. "comment at line 234 mentioned a constraint I had to honor").
- Anything that drifted from the plan (e.g. "plan said 5 edits; I needed 6 because of helper X").
Phase-end check
- Run the test scope named in the plan's phase-end check:
- Most phases:
meson test --no-rebuild regress/regress. - Catalog/WAL phases: regress +
meson test --no-rebuild --suite isolation. - Replication phases: above + the relevant TAP test under
meson test --no-rebuild --suite recovery.
- Most phases:
- If anything fails, fix-in-place — DON'T commit the breakage and "follow up". Failures during this phase belong to this phase.
- Once green, run
git -C dev statusand verify the changed files match the plan's §3 file table for this phase. Flag any extras to the user before committing.
Per-phase commit
-
Stage the phase's files:
git -C dev add <files>. -
Compose the commit message per the format below.
-
Use
commit-message-style(upstream PG style — no Co-Authored-By, imperative, wrapped at 76 cols) since this commit lives indev/and may eventually be format-patched upstream.The pre-commit hook runs automatically: stage A runs
pg-format.sh --checkagainst every staged C/H/Perl file (commit fails on dirty; fix in place withbash .claude/hooks/pg-format.sh <file>), then stage B runsmeson test --no-rebuild --suite <X>for the R13 scopepg-phase-detect.shinfers from the staged paths and thePlan-phasetrailer innotes.md. On test red, inspectdev/build-debug/meson-logs/testlog.txt. Override scope only withPG_PRECOMMIT_SCOPE=regress(or rarelyskip);--no-verifyis forbidden per R4.
Plan-linked commit message format
<one-line imperative title, max ~72 cols, no prefix>
<wrapped paragraph body, explaining the WHY of this phase>
Plan: planning/<slug>/plan.md (phase <N>: <phase title>)
Sites: <file:line>, <file:line>, ...
- Title is for the phase, NOT for the whole feature.
- Body is one or two paragraphs, plain prose, no bullets.
Plan:trailer is required and points to the plan + phase.Sites:trailer lists the principal sites touched (3-5 max; don't enumerate every line).- No
Co-Authored-By(this is upstream style). - No emoji, no conventional-commits prefix, no ticket numbers.
Phase-end log
-
Append to
planning/<slug>/notes.md:## Phase <N> — <title> — <date> <time> **Status:** done | partial | deferred **Commit:** <short-sha> "<title>" **Tests run:** <scope> — <result> ### What changed - <one-line summary per site> ### Surprises / drift - <anything that wasn't in the plan> ### What this phase did NOT do - <items deferred to later phases> Plan-phase: <N>The trailing
Plan-phase: <N>line is parsed by.claude/hooks/pg-phase-detect.shto identify the current phase when the pre-commit hook scopes its meson test run. Keep thePlan-phase:token verbatim — that's the grep target.Status field values (R8):
done— phase-end check green, commit landed.partial— phase ended with known follow-ups inside the same phase scope (rare; requires user agreement per R7 path-1).deferred— phase stopped before its phase-end check could run green; branch parks here until the blocker is resolved. The next session reads this status first.
-
Tell the user the phase is done, name the next phase, ask whether to continue immediately or pause. Some phases naturally end the session.
End-of-implementation (after all phases done)
- Final
meson test --no-rebuild(full suite). Document any pre-existing flakes (e.g. macOSrecovery/040_*etc.). - Run
git -C dev log --oneline <base>..HEADand verify N commits for N phases, each with aPlan:trailer. - If destined upstream: hand off to
patch-submissionskill. - If staying local: tell the user, leave the branch, append a
final summary to
notes.md. - End-of-session: invoke
memory-keepingto updateprogress/STATE.mdwith the planning slug + status (done / deferred / abandoned).
Boundaries vs other skills
pg-feature-plan(Phase 2): the upstream. If scope shifts, escalate back — don't reshape the plan mid-implementation.commit-message-style(upstream PG style): used for every per-phase commit (since these may go upstream).meta-commit-style(meta-repo style): NOT used here. Reserved for commits insidepostgres-claude/. If implementation reveals a knowledge corpus gap, fix it in a SEPARATE meta-repo commit using that style.patch-submission: takes over at the end for upstream-bound work.review-checklist: pre-submission gate. Run at the end before format-patching.memory-keeping: end-of-session bookkeeping.testing: when adding test cases mid-phase, consult for the right flavor (regress vs isolation vs TAP).build-and-run+/pg-restart+/pg-test+/pg-psql: the dev-loop commands.
When to escalate to the user
- Plan drift > 10% (file:line citations significantly stale).
- A phase reveals a needed change outside §3 file table (scope creep).
- A test fails for reasons not in the plan's §13 risks.
- Catalog or WAL format change wasn't anticipated by the plan.
- The change touches an invariant tagged in a subsystem doc.
In every escalation: stop, propose the resolution path (update plan, defer to follow-up, abandon phase), ask. Don't push through.
Agent rate-limit recovery (when delegating phases)
For long multi-phase runs, each phase is often delegated to a focused subagent (Agent tool with a tight per-phase brief; main loop verifies the commit + writes notes). Subagents can hit Anthropic rate / quota limits mid-phase, leaving partial uncommitted work in the worktree. This is recoverable — treat it as a routine signal, not a failure.
Recovery protocol when a subagent reports a rate-limit or returns without a commit:
- Check
git statusin the worktree immediately. Staged but uncommitted state is the agent's progress — it's a recoverable asset. Files in the staging area + the agent's prior context are enough to finish. - Inspect the diff with
git diff --cached --stat+ key file diffs. Decide whether the agent's approach is sound. If yes: either resume the agent, or finish the work yourself (use the staged state as the starting point — the agent's intent is encoded there). - Resume the agent via
SendMessageto the agent ID returned in the prior spawn. The agent's prior context is preserved; pass a "continue from the staged state — here's what's left" message that names the specific remaining edits + the acceptance criteria. This is faster than starting a new agent from scratch. - Finish manually if the remaining work is bounded. When the agent has done ~70-80% of a phase and the remaining edits are well-scoped (e.g. just the executor side of a parser+executor phase), driving the rest from the main loop is often faster than round-tripping through another agent. Verify the build + run the phase-end check + commit per the normal R5 + R8 protocol.
- Don't roll back staged work without inspection. Even if the agent's approach has issues, the staged edits typically encode a sound design — fix the specific problem, don't blow it away.
Origin: sesvars_v3 phases 8 + FU#1, where both implementation agents
rate-limited mid-phase. Phase 8 finished manually from the agent's
~100-line gram.y staging; FU#1 resumed via SendMessage. Both landed
clean commits without re-planning. See F24 in
sessions/2026-06-22-sesvars-v3-retro.md.
Style
- Be terse in
notes.md. It's a working log, not a write-up. - Be specific in commit messages (R6). "fix bug" is forbidden; "set
dropPin = falsefor non-MVCC scans (plan phase 2, sitenbtree.c:421)" is right. Any "addresses" / "fixes" / "implements" claim must point to a file:line insource/(for plan-cited sites) or a specific plan section (§4 Catalog impact, etc.). - Cite the plan from the commit; cite the corpus from the plan; cite source from the corpus. The full chain stays linked.
Where the artifacts live
- Code:
dev/on a feature branch (e.g.feature_server_side_vars). - Working log:
planning/<slug>/notes.md(inpostgres-claude/). - Plan-linked commits: the
Plan:trailer is the link from commit back to plan.
Cross-references
.claude/rules/pg-implement-discipline.md— the binding constitution. This skill is the procedure; the rules are the invariants. R1–R12 win wherever they disagree with this skill..claude/skills/pg-feature-plan/SKILL.md— Phase 2 upstream. If scope shifts, escalate back; don't reshape the plan mid-implementation..claude/skills/pg-feature-brainstorm/SKILL.md— Phase 1 read for context, not procedure..claude/skills/commit-message-style/SKILL.md— per-phase commit format (upstream PG style; noCo-Authored-Bybecause these commits may go upstream)..claude/skills/meta-commit-style/SKILL.md— used for the separate meta-repo commit if implementation surfaces a corpus gap (R10 two-repo separation)..claude/skills/build-and-run/SKILL.md— dev-loop fundamentals (ninja install,/pg-restart, build profiles)..claude/skills/testing/SKILL.md— pick the right test flavor for each phase's phase-end check..claude/skills/patch-submission/SKILL.md— invoked at end-of-implementation if upstream-bound..claude/skills/review-checklist/SKILL.md— pre-submission gate (R12)..claude/skills/memory-keeping/SKILL.md— end-of-implementation STATE.md update (R12 invokes this explicitly)..claude/commands/pg-implement.md— slash-command wrapper.
What ships with it
Read from the repository
Just SKILL.md. No reference files, no scripts.
Gives 0 of the 12 instructions most quality gates skills give in ~4.3k tokens
Counted across 1,195 of the 2,094 authors here whose files we hold, read 2026-08-07
- Read the output and check the exit codein 54 of 1195, across 14 files
- Verify requirements using a line-by-line checklistin 53 of 1195, across 12 files
- Identify the verification command proving the claimin 51 of 1195, across 12 files
- Run the full verification commandin 50 of 1195, across 11 files
- Verify output confirms the claimin 49 of 1195, across 12 files
- Check version control diff after agent delegationin 46 of 1195, across 6 files
- State claim with evidencein 44 of 1195, across 4 files
- Run the test suitein 33 of 1195, across 26 files
- Keep state in memory by defaultin 27 of 1195, across 6 files
- Make prototype runnable with one commandin 26 of 1195, across 5 files
- Produce a verification reportin 25 of 1195, across 14 files
- Detect the package manager from lockfilesin 24 of 1195, across 5 files
Said here and by no other author read
- implement one plan phase at a time
- spot-check file citations before editing
- run the phase-end check before committing
- append running notes to notes.md per phase
- commit each phase using the linked plan format
- stop and escalate on significant plan drift
Grouped from the skills themselves: near-identical wordings counted once, and counted by distinct author, so one author publishing three of these counts once. Length counted with cl100k_base; the agent that loads this file may tokenize it differently.