From 628065433257acd32d7642f791ac3497536a9b6e Mon Sep 17 00:00:00 2001 From: kiskaadee Date: Wed, 25 Nov 2026 14:50:27 -0500 Subject: [PATCH] feat(implement): add GitHub slice implementation skill - Add skills/implement/SKILL.md orchestrator loop (<= 80 lines, skeleton-compliant) covering preflight, Step 1 delta-test decomposition, adaptive worker execution, and Draft PR publishing - Add references/preflight.md owning working-tree classifications, --dry-run zero-mutation contract, git-common-dir plain-text todo.txt checkpointing, and repo-scoped documentation boundaries - Add references/decomposition-and-roles.md defining delta-test seam states, <= 2-file fast path with bailout, test-writer/code-writer hygiene contracts, recycling/deadlock breakers, and setsid timeout non-interactive wrapping - Add references/pr-and-drift.md owning the Draft PR template, rework sync rules, fixed-format Contract Drift marker, and Work in Progress / review-publishing boundaries --- skills/implement/SKILL.md | 78 +++++++++++ .../references/decomposition-and-roles.md | 132 ++++++++++++++++++ skills/implement/references/pr-and-drift.md | 92 ++++++++++++ skills/implement/references/preflight.md | 103 ++++++++++++++ 4 files changed, 405 insertions(+) create mode 100644 skills/implement/SKILL.md create mode 100644 skills/implement/references/decomposition-and-roles.md create mode 100644 skills/implement/references/pr-and-drift.md create mode 100644 skills/implement/references/preflight.md diff --git a/skills/implement/SKILL.md b/skills/implement/SKILL.md new file mode 100644 index 0000000..31b6d37 --- /dev/null +++ b/skills/implement/SKILL.md @@ -0,0 +1,78 @@ +--- +name: implement +description: >- + Execute a GitHub vertical-slice issue end-to-end with preflight checks, + delta-test decomposition, adaptive test-writer/code-writer subagents, 1:1 + commits, and Draft PR publishing. Use when implementing a ready GitHub issue + or addressing code-review rework. Not for planning (use projects), static + review (use code-review), or runtime QA and merge (use verify). +--- + +# Implement + +## Use when +- Delivering a ready GitHub issue slice on a non-default branch or worktree. +- Executing rework passes routed back from `code-review` on an open Draft PR. +- Not for decomposing epics or creating issues: use `projects`. +- Not for static diff review or PR review publishing: use `code-review`. +- Not for black-box runtime QA, PR promotion, or merge: use `verify`. + +## Steps +Pure orchestrator invariant: mutate only your branch-scoped checkpoint file +directly. Never write production code, never write tests, never perform code +review, and never publish PR review comments (`code-review` owns review +publishing). + +1. **Preflight and board transition.** Before preflight or checkpointing, read + [references/preflight.md](references/preflight.md). Verify GitHub repo + identity via `gh repo view --json url` per + [planning-contract.md](../projects/references/planning-contract.md). + Classify the working tree (`CLEAN_BASE`, `EXISTING_SLICE_BRANCH`, + `ADOPTABLE_DIFF`, `CONFLICTING_STATE`, `WRONG_BASE`). Halt immediately on + `CONFLICTING_STATE` or `WRONG_BASE`. Otherwise create or switch to a + non-`main` branch or worktree via `git-manager`, and move the issue card + `Ready -> Work in Progress` per + [github-projects-v2.md](../projects/references/github-projects-v2.md). +2. **Step 1 delta-test decomposition.** Before decomposing tasks or spawning + workers, read + [references/decomposition-and-roles.md](references/decomposition-and-roles.md). + Inspect existing tests on affected seams (`covered`, `partial/weak`, + `missing`). Auto-skip Step 1 for trivial `<= 2`-file localized fixes with no + new test seam. If `--dry-run`, print the plan and halt with zero mutations. + Otherwise write slice tasks directly in plain `todo.txt` format inside + `$(git rev-parse --git-common-dir)/implement-state/.txt` + without invoking `tuxedo`. +3. **Adaptive execution loop.** Dispatch subagents with embedded OS-level + non-interactive timeout wrapping (`1-worker` fast path for auto-skipped + trivial fixes, or `test-writer` -> `code-writer` with 3-4 task worker + recycling and a 2-turn deadlock breaker). Commit 1:1 per completed + deliverable via `git-manager`, and mark completed tasks done in + `"$state_file"`. +4. **Draft PR and state cleanup.** Before opening or syncing a Draft PR, read + [references/pr-and-drift.md](references/pr-and-drift.md). Push via + `git-manager`, open or sync a Draft PR (`gh pr create --draft`, `Closes #`, + `Contract Drift: none | `), delete `"$state_file"`, and keep the + board card in `Work in Progress`. + +## Your call +- **Branch adoption (`ADOPTABLE_DIFF`) or re-branching (`WRONG_BASE`)**: confirm + how to handle existing working-tree changes or diverged branches. +- **Deadlock escalation**: resolve 2-turn `test-writer`/`code-writer` deadlocks + or approve routing to `diagnose`. +- **Scope or contract drift**: confirm whether unexpected contract changes stay + in-slice or split into a follow-up issue via `projects`. + +## Done when +- Every slice task is implemented, tested, and committed 1:1 on a non-`main` + branch. +- A Draft PR is open or synced with `Closes #` and `Contract Drift: ...`. +- The branch-scoped `"$state_file"` is deleted and the board card remains in + `Work in Progress`. + +## Hands off to +- `code-review`: to audit the Draft PR (`Suggested Next Step: /code-review`). +- `diagnose`: when a 2-turn deadlock or unexpected failure needs root-cause + debugging (`Suggested Next Step: /diagnose`). +- `projects`: when scope splits or an explicit abort requires replanning. +- Emit one outcome-matched `Suggested Next Step:` on standalone turns; suppress + when delegated to a subagent per [skeleton.md](../build-skill/references/skeleton.md). diff --git a/skills/implement/references/decomposition-and-roles.md b/skills/implement/references/decomposition-and-roles.md new file mode 100644 index 0000000..1061d72 --- /dev/null +++ b/skills/implement/references/decomposition-and-roles.md @@ -0,0 +1,132 @@ +# Step 1 Delta-Test Decomposition & Worker Roles + +Defines Step 1 delta-test classification, the `<= 2`-file fast path, worker role +contracts, recycling and deadlock circuit breakers, and mandatory OS-level +non-interactive command wrapping. + +--- + +## 1. Step 1 Delta-Test Decomposition + +Before writing tasks or spawning workers, inspect the repository's existing test +suite on every seam affected by the target issue or rework finding. Classify +each affected seam into one of three states: + +| Seam State | Meaning | Required Task Ordering | +| :--- | :--- | :--- | +| `covered (keep green)` | Existing tests already assert the target behavior and edge cases. | Do not add redundant tests; keep existing tests green after production edits. | +| `partial/weak (harden)` | Tests touch the seam but miss edge cases, error paths, or falsifiable assertions. | `test-writer` hardens tests first (observing failure on missing behavior), then `code-writer` satisfies them. | +| `missing (new Red test)` | No test covers the new behavior or bug reproduction. | `test-writer` writes a new failing Red test first, then `code-writer` implements the minimal Green fix. | + +Record the resulting ordered deliverables directly in +`$(git rev-parse --git-common-dir)/implement-state/.txt` per +[preflight.md](preflight.md) (unless `--dry-run` is active or the fast path +applies). + +--- + +## 2. `<= 2`-File Fast-Path Criteria & Bailout + +Auto-skip Step 1 decomposition and checkpoint file creation when **all** of the +following hold: +- The change is a localized fix or localized `code-review` rework item touching + `<= 2` files. +- No new test seam is introduced (existing tests cover the behavior or a single + localized assertion suffices). +- No public interface, schema, or architecture contract changes. + +### Fast-Path Bailout Rule +If execution reveals that scope exceeds 2 files, requires a new test seam, or +impacts a public contract, stop the `1-worker` fast path immediately, run Step 1 +delta-test decomposition, initialize `"$state_file"`, and switch to the +multi-task `test-writer` -> `code-writer` loop. + +--- + +## 3. Worker Role Contracts + +`implement` is a pure orchestrator: it never edits production code, never edits +tests, never performs code review, and never publishes PR review comments. + +### Shared Invariants (All Workers) +- **Anti-recursion**: Never invoke `implement` or spawn nested workers. +- **Footer suppression**: Suppress any standalone `Suggested Next Step:` footer; + return only a compact handoff summary (touched files, verification commands + and exit codes, observed contract drift or blockers). +- **Mandatory non-interactive wrapping**: Execute all shell commands using the + Section 5 wrapper and tiered timeouts. +- **No git history rewrites**: Leave commits and branch management to the + orchestrator (`git-manager`), unless explicitly instructed to run read-only + `git diff` / `git status`. + +### `test-writer` Contract +- Owns Red tests and seam hardening for `missing` and `partial/weak` seams. +- Never implements production logic beyond minimal type/compilation stubs when a + statically typed language requires them to compile the Red test. +- Runs targeted test commands to confirm the new or hardened test fails for the + expected reason (Red) before returning. +- Runs repository lint/typecheck on touched test files and adds brief `Why:` + comments for non-obvious test invariants or fixtures. + +### `code-writer` Contract +- Owns the minimal production implementation that turns Red tests Green while + keeping `covered` seams green. +- **Per-task hygiene** (mandatory before returning): + - Run repository lint, formatter check, and typecheck on touched files. + - Add or update docstrings on all new or modified public symbols. + - Add concise `Why:` comments for non-obvious invariants, edge-case guards, or + trade-offs (never narrating obvious code mechanics). + - Update directly affected local markdown (such as adjacent module READMEs or + inline usage docs impacted by the change). +- Report any detected Contract Drift (deviation from issue acceptance criteria, + public interfaces/schemas, `ARCHITECTURE.md`, or `ROADMAP.md`) in the handoff + packet so the orchestrator can record it in the Draft PR. + +### `1-worker` Fast-Path Contract +- Used only when Section 2 fast-path criteria hold. +- Applies the localized fix and targeted verification in a single worker turn, + enforcing all `code-writer` hygiene rules (lint/typecheck, docstrings, `Why:` + comments, affected local markdown) and shared invariants. + +--- + +## 4. Worker Recycling & Deadlock Circuit Breaker + +- **3-4 Task Worker Recycling**: After every 3-4 completed tasks in a multi-task + slice, retire the current `test-writer` and `code-writer` instances and spawn + fresh workers. This prevents quadratic context growth and stale-file + assumptions across long slices. +- **2-Turn Deadlock Circuit Breaker**: If `test-writer` and `code-writer` fail + to converge on a single task after 2 back-and-forth turns (for example, + disputed test seam, flaky environment, or ambiguous specification): + 1. Stop dispatching further retries on that task. + 2. Preserve `"$state_file"` untouched. + 3. Escalate to the human owner with the exact failure output and options to + clarify the spec or hand off to `diagnose`. + +--- + +## 5. Mandatory OS-Level Non-Interactive Command Wrapping + +Embed this execution rule verbatim in every `test-writer`, `code-writer`, and +`1-worker` prompt: + +```bash +CI=true GIT_TERMINAL_PROMPT=0 PAGER=cat setsid timeout -k 10 s < /dev/null +``` + +### Why This Wrapper Is Required +- `setsid` detaches the command from any controlling `/dev/tty` so interactive + prompts cannot hang waiting for terminal input. +- `< /dev/null` closes stdin immediately. +- `CI=true`, `GIT_TERMINAL_PROMPT=0`, and `PAGER=cat` disable interactive CLI + wizards, credential prompts, and pagers. +- `timeout -k 10 s` sends `SIGTERM` after `` seconds and escalates to + `SIGKILL` 10 seconds later if the process ignores `SIGTERM`. + +### Tiered Timeouts (``) +| Tier | Timeout | Applies To | +| :--- | :--- | :--- | +| Fast CLI | `60s` | Git commands, `gh` CLI queries, linters, formatters, typecheckers, quick scripts | +| Unit Tests | `180s` | Targeted unit test runs and local test suites | +| Cold Builds | `600s` | Cold compilation, container/Nix builds, and heavy fixture builds | diff --git a/skills/implement/references/pr-and-drift.md b/skills/implement/references/pr-and-drift.md new file mode 100644 index 0000000..de6129e --- /dev/null +++ b/skills/implement/references/pr-and-drift.md @@ -0,0 +1,92 @@ +# Draft PR Publishing & Contract Drift Marker + +Sole owner of the Draft PR body template, rework sync rules, and the fixed-format +`Contract Drift` marker read by `verify`. + +--- + +## 1. Board & Review Publishing Boundaries + +- **Card stays in `Work in Progress`**: After opening or syncing a Draft PR, + `implement` leaves the GitHub Projects v2 card in `Work in Progress`. Never + move the card to `Review` here; `verify` owns `Work in Progress -> Review` + when promoting the PR with `gh pr ready` per + [planning-contract.md](../../projects/references/planning-contract.md). +- **No PR review comments**: `implement` never publishes PR reviews or inline + review comments. `code-review` is the sole owner of PR review publishing. +- **Checkpoint cleanup**: Immediately after the Draft PR is opened or synced, + delete `"$state_file"` + (`$(git rev-parse --git-common-dir)/implement-state/.txt`) per + [preflight.md](preflight.md). + +--- + +## 2. Draft PR Open & Rework Sync Rules + +1. Push the non-`main` slice branch via `git-manager` (`git push -u origin `). +2. Check for an existing PR on the current branch (`gh pr view --json number,url,isDraft`). +3. **New Draft PR** (no PR exists yet): + ```bash + gh pr create --draft --title "" --body-file + ``` + - Never open a ready-for-review PR directly from `implement`; always pass + `--draft`. +4. **Rework Sync** (an open Draft PR already exists): + - Push the new 1:1 rework commits to the existing branch. + - Update the Draft PR body with `gh pr edit --body-file ` + whenever scope, verification commands, linked issues, or the + `Contract Drift` status changed. + - If the rework pass resolved localized findings with no change to scope or + `Contract Drift`, pushing the commits is sufficient. + +--- + +## 3. Draft PR Body Template + +Use this structure when creating or syncing a Draft PR body: + +```markdown +Closes # + +## Scope Summary +- +- + +## Verification +- `` (exit 0) +- `` (exit 0) + +Contract Drift: none +``` + +*(Replace `none` with a concise single-line summary when drift occurred.)* + +--- + +## 4. Fixed-Format `Contract Drift` Marker + +`verify` parses the Draft PR body during Phase 3 closeout to decide whether to +chain `reconcile-docs` and `projects` after merge. + +### Format +```text +Contract Drift: none +``` +or +```text +Contract Drift: +``` + +### What Counts as Contract Drift +Record non-`none` drift whenever implementation deviates from any of: +- Target GitHub issue acceptance criteria. +- Public interfaces, CLI flags, API payloads, or data schemas. +- Canonical architecture or planning documents (`ARCHITECTURE.md`, `ROADMAP.md`, + or active `docs/designs/*.md` specs). + +### Rules +- Include exactly one `Contract Drift:` line at the bottom of the PR body. +- Do not invent alternate labels (such as `Drift:` or `Spec Deviations:`). +- Keep the value on the same line (`Contract Drift: none` or + `Contract Drift: `) so downstream tooling and `verify` can read it + unambiguously. diff --git a/skills/implement/references/preflight.md b/skills/implement/references/preflight.md new file mode 100644 index 0000000..c2c6992 --- /dev/null +++ b/skills/implement/references/preflight.md @@ -0,0 +1,103 @@ +# Preflight & Branch-Scoped Checkpoint Lifecycle + +Sole owner of working-tree classifications, the `--dry-run` zero-mutation +contract, and the `implement` branch-scoped checkpoint lifecycle. + +--- + +## 1. GitHub Remote & Board Guard + +Before mutating git state or moving board cards: +1. Verify GitHub repository identity with `gh repo view --json url` per + [planning-contract.md](../../projects/references/planning-contract.md). If + the command fails or `AGENTS.md` contains a legacy Gitea planning contract, + halt and advise migrating to GitHub or using standalone `gt-usage`. +2. After branch/worktree preflight passes (and only when not in `--dry-run`), + move the target issue card `Ready -> Work in Progress` using `issue.projectItems` + per [github-projects-v2.md](../../projects/references/github-projects-v2.md). + If the card is already in `Work in Progress` (resumed slice or rework pass), + leave it there idempotently. + +--- + +## 2. Working-Tree Classifications + +Inspect `git status --porcelain`, `git branch --show-current`, merge/rebase +sentinel files under `$(git rev-parse --git-dir)`, and any open Draft PR or +existing checkpoint file for the target slice. Classify into exactly one state: + +| Classification | Condition | Required Action | +| :--- | :--- | :--- | +| `CLEAN_BASE` | Clean working tree on the default base branch (e.g. `main`). | Create and switch to a dedicated non-`main` slice branch or worktree via `git-manager`. | +| `EXISTING_SLICE_BRANCH` | Clean working tree on the target slice's own non-`main` branch with an active checkpoint file or an open Draft PR. | Proceed directly to resume remaining tasks or execute a `code-review` rework pass without re-branching. | +| `ADOPTABLE_DIFF` | Uncommitted changes present, all scoped cleanly to the target slice, with no merge/rebase in progress. | Ask the user to confirm adopting the diff onto a dedicated non-`main` slice branch via `git-manager` before proceeding. | +| `CONFLICTING_STATE` | Unrelated dirty changes, untracked conflicting files, or an active merge, rebase, or cherry-pick. | Halt immediately. Report the exact dirty paths or operation and leave all working-tree and checkpoint files untouched. | +| `WRONG_BASE` | Current branch is neither the base branch nor the target slice's branch, or has diverged unexpectedly from the expected base. | Halt immediately. Ask the user whether to switch or re-branch via `git-manager`, leaving existing checkpoint files untouched. | + +--- + +## 3. `--dry-run` Zero-Mutation Contract + +When invoked with `--dry-run`: +- Execute read-only preflight inspection (`gh repo view --json url`, working-tree + classification, issue acceptance criteria read) and Step 1 delta-test + decomposition. +- Print the proposed branch name, working-tree classification, seam coverage map + (`covered`, `partial/weak`, `missing`), execution mode (`1-worker` fast path vs. + multi-task `test-writer`/`code-writer`), and ordered task list. +- Halt with **zero mutations**: + - Do not create or switch branches or worktrees. + - Do not move GitHub Projects v2 cards. + - Do not create, modify, or delete any checkpoint file. + - Do not spawn implementation workers, create commits, or touch Draft PRs. + +--- + +## 4. Branch-Scoped Checkpoint Lifecycle + +Multi-task slices store resume state inside the shared git common directory so +checkpoints stay isolated per branch across git worktrees and never pollute the +working tree or root `todo.txt`. + +### Path & Branch Slug +```bash +git_common_dir="$(git rev-parse --git-common-dir)" +branch="$(git branch --show-current)" +branch_slug="${branch//\//__}" +state_file="${git_common_dir}/implement-state/${branch_slug}.txt" +``` + +### Plain-Text `todo.txt` Line Format (Direct I/O Only) +- Read and write `"$state_file"` directly (e.g., standard file/shell I/O). Never + invoke `tuxedo` to read, append, or complete checkpoint tasks. +- Use plain-text `todo.txt` line conventions so external `todo.sh` or `tuxedo` + can inspect the file if desired: + - Pending task: `` + - Completed task: `x YYYY-MM-DD ` + +### Lifecycle Rules +1. **Create / Resume**: Create `"$state_file"` (and its parent directory + `implement-state/`) after Step 1 decomposition for multi-task slices. On + `EXISTING_SLICE_BRANCH` resume, read existing pending lines and continue from + the first uncompleted task. Auto-skipped `<= 2`-file fast-path fixes skip + checkpoint creation unless they bail out to Step 1. +2. **Update**: After each 1:1 deliverable commit via `git-manager`, prefix the + completed task line in `"$state_file"` with `x YYYY-MM-DD `. +3. **Delete**: Remove `"$state_file"` (`rm -f "$state_file"`) immediately after + opening or syncing the Draft PR, or on explicit slice abort / escalation back + to `projects`. +4. **Preserve on Halt**: Halting on `CONFLICTING_STATE`, `WRONG_BASE`, or a + recoverable worker pause leaves any existing `"$state_file"` untouched so the + user can resume cleanly. + +--- + +## 5. Repo-Scoped Documentation Boundaries + +- Durable engineering documentation (designs, ADRs, architecture notes, roadmaps) + belongs in repo-scoped `docs/` (`docs/designs/*.md`, `docs/adr/`, + `ARCHITECTURE.md`, `ROADMAP.md`). +- Ephemeral agent artifacts and personal practice notes belong in gitignored + `.internal/` at the repository root. +- Never hardcode external vault directories or user home paths in checkpoints, + worker prompts, or repository files.