MoonSpec Implement
Use this skill to perform the MoonSpec implementation workflow.
When To Use
Use this skill after /moonspec.tasks has produced a complete tasks.md for one MoonSpec story.
Good triggers include:
- Run or reproduce
/moonspec.implement. - Execute the task breakdown in
tasks.md. - Build the current MoonSpec story from
spec.mdandplan.md. - Apply TDD to a MoonSpec task list.
- Add required unit and integration test evidence before final verification.
Do not use this skill to split a broad design, write a spec, create a plan, or generate tasks. Use moonspec-breakdown, moonspec-specify, moonspec-plan, or /moonspec.tasks for those steps.
Inputs
- Treat the user's text as optional implementation guidance.
- Work from the active feature directory resolved by the prerequisite script.
- Require
spec.md,plan.md, andtasks.md. - Read
AGENTS.mdwhen present for project principles, repo constraints, and test discipline. - When
artifacts/moonspec/acceptance-assessment.jsonexists and itsfeatureIdmatches the active feature, treatboundedBacklogas the authoritative implementation backlog. Do not add unrelated improvements unless they are required by a source acceptance row. - The spec must contain exactly one independently testable user story.
tasks.mdmust be specific enough to execute without inventing hidden product scope.- Use absolute paths in reports and cite files changed or validated.
Apply requirement statuses before all coverage and execution gates: unverified rows retain source IDs, reason and verifiableBy without executable tasks; needs_human rows retain the exact decision, owner, and action without executing it or claiming its completion. Only executable rows require code, tests, setup, and red-first evidence. Observed defects remain executable remediation; unavailable checks do not become defects. For all-Unverified stories, skip setup and code/test execution and run final verification with the disclosures.
If tasks.md is missing or lacks coverage for executable rows, stop and recommend /moonspec.tasks. If the source input is a broad technical or declarative design that has not been split into one-story specs, stop and recommend /moonspec.breakdown.
Pre-Implement Hooks
Before implementation, check for extension hooks:
- If
.specify/extensions.ymlexists, read it and look forhooks.before_implement. - If the YAML cannot be parsed or is invalid, skip hook checking silently.
- Ignore hooks where
enabledis explicitlyfalse; hooks withoutenabledare enabled. - Do not evaluate non-empty
conditionexpressions. Treat hooks with no condition, null condition, or empty condition as executable. Skip hooks with non-empty conditions. - For each executable hook:
- Optional hook (
optional: true): print:
## Extension Hooks
**Optional Pre-Hook**: {extension}
Command: `/{command}`
Description: {description}
Prompt: {prompt}
To execute: `/{command}`
- Mandatory hook (
optional: false): print:
## Extension Hooks
**Automatic Pre-Hook**: {extension}
Executing: `/{command}`
EXECUTE_COMMAND: {command}
Wait for the result of the hook command before proceeding to implementation.
If no hooks are registered or .specify/extensions.yml does not exist, skip silently.
Setup
Run the prerequisite script from the repository root:
.specify/scripts/bash/check-prerequisites.sh --json --require-tasks --include-tasks
Parse FEATURE_DIR and AVAILABLE_DOCS, then derive:
SPEC = FEATURE_DIR/spec.mdPLAN = FEATURE_DIR/plan.mdTASKS = FEATURE_DIR/tasks.md- optional docs from
AVAILABLE_DOCS REPO_GUIDANCE = AGENTS.mdwhen present
If shell arguments contain single quotes, use shell-safe escaping such as 'I'\''m Groot', or double quotes when possible.
Checklist Gate
If FEATURE_DIR/checklists/ exists, scan every checklist file:
- Total items: lines matching
- [ ],- [X], or- [x]. - Completed items: lines matching
- [X]or- [x]. - Incomplete items: lines matching
- [ ].
Report a table:
| Checklist | Total | Completed | Incomplete | Status |
|-----------|-------|-----------|------------|--------|
| requirements.md | 12 | 12 | 0 | PASS |
Match incomplete checklist items to requirement status before gating. Unverified checks remain disclosed and unchecked, not blocking; actual needs_human items preserve their authority handoff. For other unfinished executable prerequisites, stop and ask whether to proceed.
Load Context
Read enough context to implement without guessing:
tasks.md: task IDs, phases, dependencies, parallel markers, file paths, required test commands, and final verification task.plan.md: tech stack, architecture, project structure, test tooling, integration dependencies, Principles Check, and constraints.spec.md: preserved**Input**, the single story, independent test, acceptance scenarios, edge cases, functional requirements, success criteria, assumptions, and source design mappings.AGENTS.mdwhen present: project principles, repo constraints, quality gates, and TDD expectations.data-model.mdwhen present: entities, relationships, validation rules, and state transitions.contracts/when present: public interfaces and contract or integration test obligations.research.mdwhen present: technical decisions and constraints.quickstart.mdwhen present: executable integration scenarios and validation commands.specs/breakdown.mdwhen present: source design coverage and cross-spec dependency context for specs generated by/moonspec.breakdown.
Validate before editing code:
spec.mdhas exactly one independently testable user story.- Source mappings remain traceable to executable work, Unverified disclosures, or actual authority handoffs.
- Relevant
AGENTS.mdprinciples and testing discipline are represented in the plan or tasks when they affect implementation. - Executable rows include applicable unit/integration test tasks; non-executable rows do not require test tasks.
- Implementation tasks do not introduce scope outside the story, original request, source design constraints, or relevant repo guidance.
If the spec contains multiple stories, stop and tell the user to split the design with /moonspec.breakdown or regenerate a one-story spec with /moonspec.specify.
Project Setup Verification
Only when executable work needs setup, create or verify the relevant ignore files:
- If
git rev-parse --git-dirsucceeds, ensure.gitignoreexists and covers generated outputs, dependencies, local env files, logs, caches, and test artifacts. - If Dockerfiles or Docker usage are present, create or verify
.dockerignore. - If ESLint legacy config exists, create or verify
.eslintignore; ifeslint.config.*exists, ensureignorescovers required generated paths. - If Prettier config exists, create or verify
.prettierignore. - If package publishing is present, create or verify
.npmignore. - If Terraform files exist, create or verify
.terraformignore. - If Helm charts exist, create or verify
.helmignore.
Append only missing critical patterns. Do not rewrite existing ignore files wholesale.
Common patterns by stack:
- Node or TypeScript:
node_modules/,dist/,build/,coverage/,*.log,.env*. - Python:
__pycache__/,*.pyc,.venv/,venv/,dist/,*.egg-info/,.env*. - Java or Kotlin:
target/,.gradle/,build/,out/,*.class,*.jar,.env*. - .NET:
bin/,obj/,*.user,*.suo,packages/. - Go:
*.exe,*.test,vendor/,*.out. - Rust:
target/,debug/,release/,*.rs.bk,.env*. - C or C++:
build/,bin/,obj/,out/,*.o,*.so,*.a,*.exe,*.dll,*.log,.env*. - Universal:
.DS_Store,Thumbs.db,*.tmp,*.swp,.vscode/,.idea/.
Task Execution Model
Parse tasks.md into:
- Phases: Setup, Foundational, single-story work, Polish, Final Verification.
- Story scope: story goal, independent test criteria, acceptance scenarios, source design coverage, and out-of-scope constraints.
- Test tasks: unit tests for domain behavior and edge cases; integration tests for workflows, acceptance scenarios, persistence, contracts, external interfaces, CLI/API/UI wiring, or system interactions.
- Dependencies: sequential work, parallel
[P]tasks, file conflicts, and phase gates. - Final verification: the task that runs
/moonspec.verify, when present.
Execute only applicable planned work for executable rows; omit absent phases and never execute needs_human actions:
- Complete setup tasks.
- Complete foundational prerequisites before story work.
- Write unit tests and run them to confirm they fail for the expected reason.
- Write integration tests and run them to confirm they fail for the expected reason.
- Implement only enough production code to satisfy the failing tests and the single story.
- Run the relevant unit and integration test suites until they pass.
- Complete polish tasks without changing story scope.
- Run
/moonspec.verifyif it is present as a task; otherwise explicitly recommend it as the final MoonSpec check.
Rules:
- Respect sequential dependencies.
- Parallel
[P]tasks may run together only when they touch different files and have no unmet dependency. - Tasks affecting the same file must run sequentially.
- Keep implementation and test evidence mapped to
FR-*, acceptance scenarios, success criteria, and source design IDs. - Do not mark a task complete until the work is actually done and any required command has passed or has a documented blocker.
- Mark completed tasks as
[X]intasks.md. - Halt on failed non-parallel tasks. For failed parallel tasks, continue successful independent work and report the failures clearly.
Implementation Rules
- Follow the repository's existing architecture, naming, test style, and tooling.
- Prefer project-local helpers and established abstractions over new patterns.
- Keep the work scoped to the single story.
- Do not weaken requirements, delete source design mappings, or remove the preserved original request.
- Do not add hidden scope beyond the story, source design constraints, relevant repo guidance, or explicit user guidance.
- For executable rows, write applicable unit tests for required domain behavior and edge cases.
- For executable rows, write applicable integration tests for required workflows and boundaries.
- Confirm new tests fail before implementing production behavior, then make them pass.
- Refactor only after tests pass.
- Preserve unrelated user changes in the worktree.
- Review documentation relevant to the change: rewrite affected explanations in place, remove superseded or duplicated material, leave accurate documentation unchanged, and report the edited paths. Describe supported behavior without recording an unintended regression as intended design (see
docs/Workflows/MoonSpecDocumentModel.md).
Completion Validation
Before reporting completion:
- Verify every required task in
tasks.mdis complete. - Evaluate production behavior against the story using evidence or valid Unverified disclosures; never describe unavailable checks as passed.
- Verify the implementation remains aligned with the original feature request or declarative design preserved in
spec.md**Input**. - Account for every in-scope source row with evidence, an Unverified disclosure, or a pending authority handoff; do not claim an unauthorized operation complete.
- Verify relevant
AGENTS.mdprinciples and testing discipline were not violated. - Run feasible planned tests for executable rows; preserve unavailable-check disclosures.
- Run quickstart validation when present and feasible.
- Confirm no hidden scope or contradiction was introduced.
- Run the final
/moonspec.verifytask when present.
If a command cannot run because of missing credentials, services, tools, or unsafe side effects, record the exact reason and the smallest next step needed.
Report
Final response structure:
## MoonSpec Implementation
Implemented:
- [task IDs or story slice]: [short summary]
Tests:
- [command]: [PASS/FAIL/NOT RUN]
Verification:
- [/moonspec.verify result or recommendation]
Changed files:
- [path]
Remaining work:
- [blocking item or "None"]
Keep the report concise. Include blockers before summaries when implementation is incomplete.
Post-Implement Hooks
After completion validation, check .specify/extensions.yml for hooks.after_implement using the same parsing, filtering, and condition rules as pre-implement hooks. For each executable hook:
- Optional hook (
optional: true): print:
## Extension Hooks
**Optional Hook**: {extension}
Command: `/{command}`
Description: {description}
Prompt: {prompt}
To execute: `/{command}`
- Mandatory hook (
optional: false): print:
## Extension Hooks
**Automatic Hook**: {extension}
Executing: `/{command}`
EXECUTE_COMMAND: {command}
If no hooks are registered or .specify/extensions.yml does not exist, skip silently.
Key Rules
- Implement exactly one story from the active MoonSpec.
- TDD is the default strategy.
- Unit and integration tests are expected for applicable executable work, not for non-executable rows.
- Confirm tests fail for the intended reason before production code.
- Preserve traceability to the original request and source design mappings.
- Preserve relevant
AGENTS.mdprinciples and repo constraints. - Mark completed tasks
[X]only after real completion. - Update documentation the change makes inaccurate in the same change.
- Run or recommend
/moonspec.verifyas the final alignment check.