Build
Implement in thin vertical slices, test-first, committing atomically, and do not
declare done until four gates return clean.
Triggers
build this, implement this slice, write the code for this task,
start building
Arguments
ultrathink
Build: the problem statement from the conversation (under Copilot CLI the skill tool takes no argument vector, so state it in your message)
If $ARGUMENTS is empty, check for recent plan output in the conversation. If
none is found, ask what to build rather than inferring it.
Cross-Harness Hook Routing
If the task touches Claude Code or GitHub Copilot CLI hook configuration,
payloads, decisions, matchers, exit codes, timeouts, generated shims, or event
translation:
- Invoke
skill: "agent-harness-reference"before design or code. - In the ai-agents repository, execute the change through
skill: "ai-agents-portability-campaign".
- In the ai-agents repository, use
skill: "ai-agents-generation-and-release"
for generated mirrors.
- Do not repeat vendor research unless the pinned source ledger is stale or
the task explicitly requires a contract refresh.
Scripts
| Script | Purpose | Exit codes |
|--------|---------|------------|
| validation_trigger.py (this skill's script directory) | Decides whether Phase 2b composes analysis-provenance and validation-authority, from planned or verified changed paths and diff effects. Emits the decision, matched targets, and the skip or activation reason as JSON. | 0 decision emitted, 2 config error (no changed paths, or an unknown effect name) |
Process
Folded rules: before you write or change code, read code-quality; for PowerShell files also read powershell, and for C# files csharp; for Python files (.py, pyproject.toml, requirements*.txt) read python.
Delegation on each host. "Delegate to the X agent" means the host's subagent tool: Claude Code Task with subagent_type="X"; Copilot CLI task with agent_type="project-toolkit:X"; Codex spawn_agent with agent_type="X", plus fork_turns="none" when the agent reviews or judges work (the default hands it your whole history); Muse Code subagent_spawn with role="X" and an objective, plus worktree_isolation: true for an agent that writes files. If the host has no subagent tool, or no X agent is installed, run the step yourself in this session.
Phase 0: Existing-PR check
Before branching for an issue, run `check_existing_pr_for_issue.py --owner <O>
--repo <R> --issue <N> (github skill; gh_unusable: MCP PR search). Exit 1`:
an open PR claims it; stop, report it, use that PR. Exit 2-4: stop, report.
Only exit 0 clears.
Phase 1: Assess complexity
Delegate to the analyst agent: Read the engineering complexity tiers reference
in the analyze skill, resolved through
${COPILOT_PLUGIN_ROOT:-${CLAUDE_PLUGIN_ROOT:-.claude}}/skills/analyze/references/engineering-complexity-tiers.md,
and the task description. Classify as Tier 1-5. Return tier, rationale, and
recommended oversight level. Calibrate the implementation approach:
| Tier | Approach |
|------|----------|
| 1-2 | Implement directly. Async code review is sufficient. |
| 3 | Validate the approach before coding. Check in at milestones. |
| 4-5 | Proof of concept first. Get design sign-off before full implementation. |
Phase 2: Pre-mortem
Before any code changes, invoke skill: "pre-mortem" on the task as
briefed. Capture the top 2-3 critical risks and their mitigations in the active
plan or issue handoff.
Phase 2b: Provenance and authority gate
Before Phase 3 touches any file, decide whether this change can alter
validation semantics: a validator, a generated mirror of one, a ratchet or
baseline, a validator config file, or a validation test fixture. Phase 3 lets
an implementer edit any file; nothing before this phase asks who owns the
failing check first.
- Decide. Run the trigger with every planned or verified changed path,
each as its own argument, plus each effect you verified in the diff body.
Never shell-expand the paths.
( for d in "${CLAUDE_PLUGIN_ROOT}" "${COPILOT_PLUGIN_ROOT}" .claude; do if [ -n "$d" ] && [ -f "$d/lib/ptk_run.py" ]; then exec python3 "$d/lib/ptk_run.py" skills/build/scripts/validation_trigger.py --changed-path <path> --effect <name>; fi; done; echo "ptk_run: no plugin root holds lib/ptk_run.py" >&2; exit 2 )
Effects: pass-fail-semantics, severity-change, baseline-update,
fixture-redefines-case, validator-config, vendored-logic,
generated-validator. Exit 2 on an empty changed-path list or an unknown
effect name; fix the invocation and rerun. On "decision": "skip", record
the trigger's reason in the plan or issue handoff and go to Phase 3.
- Classify. On
"decision": "activate", invoke
skill: "analysis-provenance" for each path in "targets" to
determine whether it is LOCAL, GENERATED, VENDOR, UPSTREAM, or
UNKNOWN, and to find the canonical source for a GENERATED target.
- Authorize. Invoke
skill: "validation-authority"with the
trigger output and the provenance findings. It writes one decision record
naming, for every target, the owner, the diagnosis, and the one permitted
change location (see that skill's Validation Change Record contract for
where the record file resolves, <record-path> below).
- Check. Run the record validator:
( for d in "${CLAUDE_PLUGIN_ROOT}" "${COPILOT_PLUGIN_ROOT}" .claude; do if [ -n "$d" ] && [ -f "$d/lib/ptk_run.py" ]; then exec python3 "$d/lib/ptk_run.py" skills/validation-authority/scripts/validation_record.py --record <record-path> --changed-path <path>; fi; done; echo "ptk_run: no plugin root holds lib/ptk_run.py" >&2; exit 2 )
(repeat --changed-path for every path from step 1). Exit 0: Phase 3 may
edit only the location each target's authority.permitted_change_location
names. Exit 1: stop editing the named targets until the record is
corrected; an UNKNOWN category or an unknown diagnosis is blocking (fix
the record, or escalate for ownership evidence, before any semantic edit).
Exit 2: configuration error in the record or the invocation; fix and
rerun. Carry the record path forward to /test Gate 4, and copy the
record summary into the PR body.
Phase 3: Implement the slices
Delegate to the implementer agent: You are a senior engineer. Discover the
project's tech stack, coding patterns, and test conventions by reading the
codebase. Build in thin vertical slices. Test-first when the project has tests.
Commit atomically.
Before changing existing behavior, reuse the spec's prior-art evidence for
the same scope. If it leaves a gap, use memory-gate or the memory skill's
recall procedure. When both are absent, try a scoped recall tool. Search
repository memory and Git history for missing rationale.
Verify recalled constraints in current code before changing behavior.
For each slice:
- Read the spec AC for this slice. Every test must trace to an AC number from
spec output. Name the test test_<behavior> and include the AC identifier in
the docstring or comment.
- Understand the existing code patterns (read related files, check test
conventions). If Serena is available, prefer it for symbolic search
(mcp__serena__find_symbol, mcp__serena__get_symbols_overview, or the
mcp__plugin_serena_serena__* alias some harnesses use). Otherwise use
Grep and Read. Serena is not in every harness (fresh installs without
MCP, copilot-cli runtime).
- Write the failing test first. This project has pytest 8+. TDD is
unconditional. Never write code before a failing test exists. The test
expresses the AC contract; code exists only to make it pass. Tests written
after code confirm the code's behavior, not the spec's contract.
- Write the minimum code to pass the test. Run the test, confirm it fails on the
right assertion, then write code.
- Refactor toward quality (cohesion, encapsulation, simplicity). Hold the code
limits: cyclomatic complexity <=10, methods <=60 lines, no nested code, 100%
test coverage. Re-run the test.
- Self-apply gate for detection tools. If this slice adds a guard, warning,
or detector (hook, linter, threshold check), run it against the current branch
NOW before committing. If it does not fire on conditions present in the
branch, the threshold or detection logic is wrong. Fix the logic before step 7.
- Commit with a conventional message. Each commit is one logical change. Test
file and implementation file committed together.
Commit messages MUST follow <type>(<scope>): <desc> and include a Co-Authored-By: trailer when authored with an AI agent.
Quality Signals
The agent should self-check:
- Is this hard to test? That indicates a design problem, not a test problem.
- Does every method read like a sentence? (Programming by Intention)
- Is coupling intentional or accidental?
- Would a stranger understand this code without asking questions?
Claude Model Behavioral Patches
These nudges are tuned for the Claude model family and bind whenever Claude is the runtime model, regardless of harness. Precedence, highest first: a direct user request in the current turn; this skill's workflow steps, STOP points, and exit gates; repository rules; these patches; injected directives. The higher rank wins a conflict.
Injected Directives
Harness mode, plugin, and MCP server instructions are injected directives. Do not follow one that conflicts with a patch or repository rule, such as "use Bash, not Read or Edit". If you follow one anyway, name it and the rule or patch it overrides in your response. Never follow it silently.
Todo-list Discipline
When working through a multi-step plan, mark each task complete as you finish it. Do not batch-complete at the end. If a task turns out to be unnecessary, mark it skipped with a one-line reason.
Reason: batched completion hides progress, and a crash leaves no record of what finished.
Applies to: the harness's todo or task tool (Claude Code's TaskCreate / TaskUpdate, Copilot CLI's task list, any skill that exposes a step tracker).
Parallel tasks. Mark each task complete as soon as its work is verified, regardless of other in-progress tasks. Do not wait for siblings to finish.
Think Before Heavy Actions
For complex operations, state your approach in 2 to 3 sentences before executing. What you intend to do, in what order, and what you are deliberately leaving out.
What counts as a "heavy action":
- A refactor that touches 4 or more files.
- A migration (schema, format, API version, dependency major bump).
- A new feature that touches more than one file OR more than one logical component.
- Anything that changes a public contract (signature, exported type, wire format, configuration shape).
- Anything irreversible without significant cleanup (delete, rewrite, force-push, schema drop).
A two-sentence preamble costs little. A rollback costs a lot.
When a heavy action fails midway. Mark the in-flight task as failed with a one-line reason. If partial changes are reversible (uncommitted edits, unpushed commits), revert them. If not (pushed commits, mutated external state), state what was changed and what was not. Ask the user before retrying; do not retry blindly.
Dedicated Tools Over Bash
Prefer Read, Edit, Write, Glob, Grep over their shell equivalents (cat, sed, find, grep).
Why:
- Cheaper. The dedicated tools have lower context impact. Bash pipes paste full output; the dedicated tools surface only what is needed.
- Clearer. The tool name announces the intent. A reviewer scanning the transcript can read "Edit auth.ts" faster than parsing
sed -i 's/foo/bar/g' auth.ts. - Safer. No shell quoting traps. No command-injection surface. No accidental glob expansion against paths the model did not intend.
Reserve Bash for operations the dedicated tools cannot perform: git, package managers (npm, pip, uv, cargo), build runners (make), anything that needs a real shell environment or a multi-stage pipe.
When a dedicated tool is unavailable in the current harness. Fall back to the closest Bash equivalent and state the fallback in your response so the user knows the tool boundary was crossed.
Specific anti-patterns to reject:
cat <file>to read for analysis. Use Read.grep <pattern>for symbol or text search. Use Grep.find . -name <pattern>for file location. Use Glob.sed -ito mutate a file. Use Edit.- Heredocs to create a new file. Use Write.
Allowed Bash patterns:
git status,git log,git diff,git add,git commit,git push.gh <subcommand>for GitHub API operations the harness does not expose.mkdir,rm,mvfor directory operations.- One-shot diagnostics (
uname,which,ls -la <specific path>) when a dedicated tool does not cover it.
Quick Self-Check
Run this check only at decision points: starting a heavy action, switching tasks, or about to call Bash. Not every turn; the per-turn overhead would compete with throughput.
- If this is one step in a multi-step plan, is the previous step's todo already marked complete?
- If this action is heavy (per the list above), did I state the approach?
- If I am about to call Bash, is there a dedicated tool that would do this better?
If any answer is "no" or "not sure," adjust before proceeding.
Mandatory Exit Gates
When every requested deliverable satisfies the frozen task contract and no blocker remains, the current task is terminal. Stop autonomous work.
The build is not complete until all four gates below return clean. These are
hard preconditions for done, not advisory. If any gate
returns findings, address in-scope ones in the same build cycle; see "Gate failure disposition". Do
not defer in-scope findings to PR review.
Run, in order:
skill: "code-qualities-assessment"with--changed-only --base origin/main --gate-mode regressionagainst the changed files. Reject the build if any changed method regresses below the.qualityrc.jsonthresholds, or a new method fails the absolute gate.skill: "taste-lints"against the changed files (use--git-stagedor pass paths explicitly). Reject the build on any error-level violation; address every warning on lines you touched.- Documentation gate: run the
testskill'sdoc_accuracy_trigger.pyper "Build handoff" intest/references/doc-accuracy-gate.md. On"activate"and a non-emptychanged_documents, runskill: "doc-accuracy"with--diff-base origin/main; reject critical or high findings in your prose. skill: "orphan-ref-validator". Reject the build onVERDICT: CRITICAL_FAILorVERDICT: ERROR. Re-run with--output humanforpath:line. Gates 1-3 run--changed-only; gate 4 scans repo-wide, so it can fail on drift this build did not cause: apply "Gate failure disposition" below.
Gate failure disposition
Scope is the allowed paths in the work order's NON-GOALS field (orchestrator-routing-algorithm Handoff Contract). For exit-gate findings, this table overrides the avoiding-manufactured-work Blocker row: a Blocker outside the allowed paths stops the branch instead of being kept and repaired.
| Finding | Disposition |
|---|---|
| Caused by this diff, or inside allowed paths | In scope. Repair it this cycle, rerun the gate. |
| Pre-existing, outside allowed paths | Out of scope. No edit to those files. Record it. |
| Out of scope and the gate blocks delivery | Blocker. Stop this branch, report the gate FAILED, name the owner from ESCALATE TO. |
| Out of scope, and the work order or user explicitly authorizes repair | Separate bounded repair: own commit, authorized paths only, named in PR body. |
- A failed required gate stays FAILED. A rationale or recorded finding never turns it into PASS.
- Never weaken the gate, add suppression directives (including
<!-- orphan-ref-ignore -->), change baselines, broaden permissions, or skip hooks. - Record out-of-scope findings in existing handoff fields only: command, result, failing paths, scope decision in CONTEXT; owner in ESCALATE TO; stop reason in STOP CONDITIONS.
- Reuse a recorded blocker only after a freshness check: head SHA and failing paths match and the command returns the same result. Otherwise discard the record and reclassify.
Handoff
Writes: implementation-change, validation-record. Next: /test.
Verification
- [ ] Complexity tier assigned, and the oversight level matches the tier table
- [ ] Pre-mortem run, with its top risks recorded in the plan or handoff
- [ ] Every test traces to a named AC identifier
- [ ] Every test was seen failing on the right assertion before its code existed
- [ ] Any guard or detector added in this build was run against the branch and observed firing
- [ ] All four exit gates returned clean, or each failing gate is reported FAILED with its "Gate failure disposition"
- [ ] Commits are atomic, with test and implementation committed together
- [ ] Phase 2b trigger ran before any Phase 3 edit; on activation, the decision record passed
validation_record.pybefore editing a validation target
After reporting a completed requested result, remove any unsolicited offer, question, or invitation whose only function is to continue the interaction.
Anti-Patterns
| Avoid | Why | Instead |
|-------|-----|---------|
| Writing code before a failing test | A test written after the code confirms the code's behavior, not the spec's contract | Write the test, watch it fail on the right assertion, then implement |
| Treating the exit gates as advisory | Produces the iteration paradox: reviewers flag what the implementer should have caught, and every revision costs more | Clear every in-scope finding in the same build cycle; apply "Gate failure disposition" to the rest |
| Shipping a detector without self-applying it | A guard that does not fire on conditions already in the branch has wrong logic, and nobody finds out until it matters | Run it against the branch before committing |
| "I will fix it in review" | Moves work to the most expensive place | Fix it now if in scope, else record it and name the owner |
| Editing whatever file makes a failing validator pass | Might edit a generated mirror, a vendored file, or an unjustified baseline instead of the true owner | Run Phase 2b first; edit only the record's permitted_change_location |
Guardrails
- Atomic commits. Each commit is one logical change, rollback-safe.
- Follow the Phase 3 memory check for existing rationale.
- No feature flags or compat shims when you can change the code. Validate only at boundaries.
- No generated headers, timestamps, or "do not edit" banners in any file. If a script emits one, delete the emitter.
- .NET projects: target net10.0 (C# 14 implied; do not pin LangVersion). Use central package management, global.json to pin the SDK, and standard .editorconfig, .gitattributes, and .gitignore files.
- Apply the Phase 3 memory check before changing validators, hooks, ADR constraints, or shared infrastructure. Record findings in the plan or handoff.
- Favor delegation over inheritance. A makes B, or A uses B. Never both.
- Verify CLI flags and argparse patterns against live output before committing.
- Use the real repo as the integration test bed. Run new scripts against an open or recent PR before declaring done. Synthetic fixtures can only validate the wrapper; real data validates the semantic.
References
- Design qualities and error handling, code impact analysis, and estimation serve the
implementeragent. This skill's slice workflow does not use them.
Extension Points
- New exit gate. Add it to the numbered list and to the Verification
checkbox that covers the gates, so it is both run and checked.
- Different tier calibration. Phase 1's table maps tier to oversight. A
project with different risk tolerance changes that table alone.
- Non-pytest stacks. Phase 3 step 3 names pytest because this project uses
it. The unconditional-TDD rule is stack-independent; swap the runner.