skills/ah-finalize-code/SKILL.md
Finalize code changes before a PR with the "ah" prefix. Use for "ah finalize code", "ah finalize changes", or "ah finalize". Runs a multi-step workflow: simplify code, write a retrospective, add tests, update JSDoc and docs, optimize/sync specs, code review, and create the PR -- committing after each step. Steps with no relevant changes are auto-skipped. Supports resuming runs and skipping steps by name (e.g. "ah finalize code skip docs").
npx skillsauth add arinhubcom/arinhub ah-finalize-codeInstall this skill globally with one command. Works with Claude Code, Cursor, and Windsurf.
3 of 9 scanners reported clean
Some scanners were skipped, did not run, or reported a non-clean status. Review each row below.
Orchestrate the full pre-PR finalization workflow for the current branch. Specialized subagents handle each aspect -- simplification, testing, documentation, specs, code review -- with a commit after every step that produces changes. The workflow ends by creating a pull request.
/commit. If a step was skipped or produced no file changes, skip the commit too. Applies to every step below; not repeated in each section.git diff "${MERGE_BASE}" before starting, so it always sees the latest state including commits from previous steps.Steps auto-skip when their input isn't relevant. The orchestrator evaluates these after computing the diff in step 0 and marks auto-skipped steps in the progress file.
| Step | Skips when |
|------|-----------|
| 4a JSDoc Updater | Diff contains no .ts, .tsx, .js, or .jsx files |
| 4b Tests Docs Updater | No docs/tests/ directory exists in the repo |
| 5a API Docs Updater | No docs:generate script in package.json, or diff touches only internal/private code |
Steps 1-3, 5b, 6-8 always run. Users can also skip steps manually -- see step 0.
Determine autonomy: if the user passed autonomous, set AUTONOMOUS=1, else AUTONOMOUS=0. When AUTONOMOUS=1, never prompt the user anywhere in this skill -- take the deterministic defaults / fail-fast noted at each decision point, and run the retrospective non-interactively (see step 2).
BRANCH_NAME=$(git branch --show-current)
REPO_NAME=$(basename -s .git "$(git remote get-url origin)")
SAFE_BRANCH_NAME=$(echo "${BRANCH_NAME}" | tr '/' '-')
SPEC_DIR="specs/${BRANCH_NAME}"
PROGRESS_DIR=~/.agents/arinhub/progresses
PROGRESS_FILE="${PROGRESS_DIR}/progress-pr-${REPO_NAME}-${SAFE_BRANCH_NAME}.md"
mkdir -p "${PROGRESS_DIR}"
Branch has changes: Compare against the expected base. If no commits ahead, abort: "Nothing to finalize."
git log --oneline -1
Spec directory exists: Verify ${SPEC_DIR}/spec.md exists. If missing, stop: "No spec found at ${SPEC_DIR}/spec.md. Run the task creation workflow first."
No uncommitted changes: Run git status --porcelain. If there are uncommitted changes, ask the user whether to stash, commit first, or abort. When AUTONOMOUS=1, do not ask -- fail fast with a clear error listing the uncommitted paths.
Read ${SPEC_DIR}/spec.md and extract:
BASE_BRANCH from the Base Branch metadata fieldISSUE_NUMBER from the Issue Number metadata fieldIf either is missing, ask the user before proceeding (or, when AUTONOMOUS=1, fail fast with a clear error naming the missing field).
Parse the user's prompt for skip instructions:
skip docs -- skips steps 4a, 4b, 5askip tests -- skips step 3skip specs -- skips step 5bskip <step-name> -- skips the named step (e.g., skip retrospective)only <steps> -- runs only the listed steps plus 0, 7, 8 (always required)Record user-skipped steps with progress_log "${PROGRESS_FILE}" <n> <name> "skipped(user)".
Progress is recorded as a deterministic append-only log written by a shell helper -- not an LLM-maintained markdown file. Source the helper (resolve path relative to this SKILL.md's directory) and initialize:
source "<skill_dir>/scripts/progress.sh"
progress_init "${PROGRESS_FILE}" "${BRANCH_NAME}" "${BASE_BRANCH}" "${ISSUE_NUMBER}"
progress_init writes the header only when the file does not yet exist, so a re-run leaves an existing log untouched.
If ${PROGRESS_FILE} already existed before this run:
grep '^step|' "${PROGRESS_FILE}". If some steps are logged done/skipped(...), show them and ask: "Resume from step N, or restart?" If resuming, skip completed steps and their commits. When AUTONOMOUS=1, do not ask -- default to resuming from the first incomplete step.rm "${PROGRESS_FILE}" and call progress_init again for a fresh log.Record each step with progress_log "${PROGRESS_FILE}" <n> <name> <status> [commit] (status: done, skipped(user), skipped(none), failed). The helper stamps timestamps itself.
git fetch origin "${BASE_BRANCH}" --quiet
MERGE_BASE=$(git merge-base "origin/${BASE_BRANCH}" HEAD)
Verify the branch has commits ahead:
AHEAD_COUNT=$(git rev-list --count "${MERGE_BASE}"..HEAD)
if [ "${AHEAD_COUNT}" -eq 0 ]; then
echo "No commits ahead of ${BASE_BRANCH}. Nothing to finalize."
exit 1
fi
Compute the diff file list and check each auto-skip condition from the table above. Record auto-skipped steps with progress_log "${PROGRESS_FILE}" <n> <name> "skipped(none)".
If the repository is a monorepo, identify the correct application from the changed file paths and scope all commands (preflight, test, lint) to that application.
Spawn subagent simplifier:
/simplify with prompt: Simplify changes in current diff only, then check "pnpm preflight"progress_log "${PROGRESS_FILE}" 1 simplifier done <commit>Spawn subagent retrospective:
/speckit.retrospective.analyzeAUTONOMOUS=1, prepend this directive to the subagent's prompt: "Run /speckit.retrospective.analyze non-interactively. Do NOT ask the user anything. Respect the command's default-NO confirmation policy: do NOT modify spec.md, and do NOT stop on the <50%-completion gate -- instead record findings and follow-up actions in retrospective.md and continue." This avoids the command's interactive STOP/<50% and spec-change y/N gates, which would otherwise deadlock a subagent with no user channel.progress_log "${PROGRESS_FILE}" 2 retrospective done <commit>Spawn subagent test-creator:
Run command "pnpm test:coverage", find the coverage file location from the test:coverage script configuration, read coverage file, add important tests for changes in current diff only, optimize count of tests to avoid redundancy, verify coverage improvements, then run "pnpm preflight"progress_log "${PROGRESS_FILE}" 3 test-creator done <commit>Spawn both subagents in parallel -- they modify non-overlapping file sets (source code JSDoc comments vs. docs/tests/ markdown). Skip either if its skip condition is met.
In JSDoc comments on the current diff, add/update spec references using shorthand "SXXX:FR-YYY" or "SXXX:SC-YYY" format (S001=001-minute-qset-react) with short descriptions, remove outdated refs and task numbers (e.g. T012), ensure standard JSDoc format, add missing shorthand to spec.md if needed, and run formatter + linter on modified files.progress_log "${PROGRESS_FILE}" 4a jsdoc-updater doneUpdate docs/tests/tests-*.md files to reflect changes in current diff only, ensure that each test file follows the established format and includes all necessary details. If no code changes are detected, do not make changes. Check if there are any redundant or unnecessary tests in changes in current diff -- if so, remove redundant tests.progress_log "${PROGRESS_FILE}" 4b tests-docs-updater doneAfter both complete (or the non-skipped one completes), commit.
Spawn both subagents in parallel -- they operate on completely independent file sets (docs/api/ vs. specs/<branch>/). Skip API Docs if its skip condition is met.
Run "pnpm docs:generate", then extract type definitions, interfaces, and function signatures from "docs/typedoc" output to create/update "docs/api/index.md" (overview + TOC) and topic files ("docs/api/api-components.md", "api-hooks.md", etc.) with one file per logical section, validate all index links resolve to existing files, and report progress -- do not generate code examples, tutorials, or document private APIs.progress_log "${PROGRESS_FILE}" 5a api-docs-updater doneThis step consolidates the spec directory (removing consumed planning artifacts), then updates the remaining essential files to reflect the actual implementation. Combined into one subagent because both phases operate on ${SPEC_DIR}/ and the update phase depends on the consolidation phase completing first.
references/spec-finalizer-prompt.md (substituting ${SPEC_DIR} with the actual path) and execute itprogress_log "${PROGRESS_FILE}" 5b spec-finalizer doneAfter both complete (or the non-skipped one completes), commit.
Spawn subagent code-reviewer:
/ah-review-code with prompt: base branch is ${BASE_BRANCH}, after code review read the code review file and fix all issues you find, then check "pnpm preflight"progress_log "${PROGRESS_FILE}" 6 code-reviewer done <commit>Runs last (before PR creation) so it reviews everything -- code, docs, and spec changes from all previous steps.
Spawn subagent pr-creator:
/ah-create-pr with prompt: base branch: ${BASE_BRANCH}, issue number: ${ISSUE_NUMBER} (when AUTONOMOUS=1, append , autonomous so the PR step also runs non-interactively)progress_log "${PROGRESS_FILE}" 7 pr-creator done "" "<PR URL>" then progress_done "${PROGRESS_FILE}" completedInteractive mode (AUTONOMOUS=0): Present a summary:
${PROGRESS_FILE} plus a compact rendering via progress_render "${PROGRESS_FILE}"Autonomous mode (AUTONOMOUS=1): skip the user-facing summary; return only the PR URL, the progress file path, and a one-line status to the caller. The retrospective follow-ups live in ${SPEC_DIR}/retrospective.md for the orchestrator to surface.
[0] Initialize & validate
|
v
[1] Simplify --> commit
|
v
[2] Retrospective --> commit
|
v
[3] Test Creator --> commit
|
v
[4] JSDoc Updater ----+
Tests Docs Updater-+--> commit (parallel, auto-skip eligible)
|
v
[5] API Docs Updater ---+
Spec Finalizer ------+--> commit (parallel, auto-skip eligible)
|
v
[6] Code Review --> commit
|
v
[7] Create PR
|
v
[8] Report to User
committer only creates a commit via /commit.${PROGRESS_FILE} is an append-only log written by scripts/progress.sh, not an LLM-maintained markdown file. Each step appends one progress_log line.grep '^step|' and offers to resume from the last incomplete step. Completed steps and their commits are skipped.date -- the model never supplies timestamps or durations.skipped(none)) and user-skipped (skipped(user)) steps are logged with the reason. Skipped steps don't trigger commits.specs/<branch-name>/.progress_log ... failed and report to the user. Do not silently skip steps.spec.md metadata -- if missing, ask the user (or, when AUTONOMOUS=1, fail fast with a clear error). All user-interaction points (uncommitted-changes, resume, retrospective gates) only apply when AUTONOMOUS=0; with the autonomous flag they take deterministic defaults / fail fast, as noted at each step.development
Use when: (1) building a skill/command that orchestrates other skills by spawning subagents, (2) a delegated sub-skill reads git working-tree state (e.g. `git branch --show-current`) instead of taking it as an argument, (3) a sub-skill is supposed to "reflect on this session" / capture session learnings (like revise-claude-md) but runs in a subagent, (4) base branch ends up wrong or a session-reflection step sees an empty/trivial context. Keywords: orchestrator, subagent isolated context, git branch --show-current, base branch checkout, revise-claude-md, this session.
development
Run the full ArinHub feature-development pipeline end-to-end with the "ah" prefix. Use for "ah workflow", "ah run workflow", "ah full workflow", a GitHub issue URL to take from issue to PR, or any request to run the whole ah pipeline at once. Takes a feature description + issue number + base branch, OR a GitHub issue URL (resolved via references/resolve-gh-issue.md). Sequentially launches subagents: ah-create-prd-adr -> ah-create-tasks -> ah-implement-tasks -> optional ah-check-qa verification -> ah-finalize-code (creates the PR), anchored with /goal and guarded by retry + escalation.
testing
Verify that a PR or local changes fully implement requirements from a linked GitHub issue, with the "ah" prefix. Use for "ah verify requirements coverage", "ah verify requirements coverage issue 42", "ah verify requirements coverage PR 123", or both ("PR 123, issue 42").
development
Submit a completed code review with line-specific comments and suggestions to a GitHub PR, with the "ah" prefix. Use for "ah submit code review 123".