|
| 1 | +--- |
| 2 | +name: speckit-analyze |
| 3 | +description: Perform a non-destructive cross-artifact consistency and quality analysis |
| 4 | + across spec.md, plan.md, and tasks.md after task generation. |
| 5 | +compatibility: Requires spec-kit project structure with .specify/ directory |
| 6 | +metadata: |
| 7 | + author: github-spec-kit |
| 8 | + source: templates/commands/analyze.md |
| 9 | +disable-model-invocation: true |
| 10 | +--- |
| 11 | + |
| 12 | +## User Input |
| 13 | + |
| 14 | +```text |
| 15 | +$ARGUMENTS |
| 16 | +``` |
| 17 | + |
| 18 | +You **MUST** consider the user input before proceeding (if not empty). |
| 19 | + |
| 20 | +## Goal |
| 21 | + |
| 22 | +Identify inconsistencies, duplications, ambiguities, and underspecified items across the three core artifacts (`spec.md`, `plan.md`, `tasks.md`) before implementation. This command MUST run only after `/speckit.tasks` has successfully produced a complete `tasks.md`. |
| 23 | + |
| 24 | +## Operating Constraints |
| 25 | + |
| 26 | +**STRICTLY READ-ONLY**: Do **not** modify any files. Output a structured analysis report. Offer an optional remediation plan (user must explicitly approve before any follow-up editing commands would be invoked manually). |
| 27 | + |
| 28 | +**Constitution Authority**: The project constitution (`.specify/memory/constitution.md`) is **non-negotiable** within this analysis scope. Constitution conflicts are automatically CRITICAL and require adjustment of the spec, plan, or tasks—not dilution, reinterpretation, or silent ignoring of the principle. If a principle itself needs to change, that must occur in a separate, explicit constitution update outside `/speckit.analyze`. |
| 29 | + |
| 30 | +## Execution Steps |
| 31 | + |
| 32 | +### 1. Initialize Analysis Context |
| 33 | + |
| 34 | +Run `.specify/scripts/bash/check-prerequisites.sh --json --require-tasks --include-tasks` once from repo root and parse JSON for FEATURE_DIR and AVAILABLE_DOCS. Derive absolute paths: |
| 35 | + |
| 36 | +- SPEC = FEATURE_DIR/spec.md |
| 37 | +- PLAN = FEATURE_DIR/plan.md |
| 38 | +- TASKS = FEATURE_DIR/tasks.md |
| 39 | + |
| 40 | +Abort with an error message if any required file is missing (instruct the user to run missing prerequisite command). |
| 41 | +For single quotes in args like "I'm Groot", use escape syntax: e.g 'I'\''m Groot' (or double-quote if possible: "I'm Groot"). |
| 42 | + |
| 43 | +### 2. Load Artifacts (Progressive Disclosure) |
| 44 | + |
| 45 | +Load only the minimal necessary context from each artifact: |
| 46 | + |
| 47 | +**From spec.md:** |
| 48 | + |
| 49 | +- Overview/Context |
| 50 | +- Functional Requirements |
| 51 | +- Success Criteria (measurable outcomes — e.g., performance, security, availability, user success, business impact) |
| 52 | +- User Stories |
| 53 | +- Edge Cases (if present) |
| 54 | + |
| 55 | +**From plan.md:** |
| 56 | + |
| 57 | +- Architecture/stack choices |
| 58 | +- Data Model references |
| 59 | +- Phases |
| 60 | +- Technical constraints |
| 61 | + |
| 62 | +**From tasks.md:** |
| 63 | + |
| 64 | +- Task IDs |
| 65 | +- Descriptions |
| 66 | +- Phase grouping |
| 67 | +- Parallel markers [P] |
| 68 | +- Referenced file paths |
| 69 | + |
| 70 | +**From constitution:** |
| 71 | + |
| 72 | +- Load `.specify/memory/constitution.md` for principle validation |
| 73 | + |
| 74 | +### 3. Build Semantic Models |
| 75 | + |
| 76 | +Create internal representations (do not include raw artifacts in output): |
| 77 | + |
| 78 | +- **Requirements inventory**: For each Functional Requirement (FR-###) and Success Criterion (SC-###), record a stable key. Use the explicit FR-/SC- identifier as the primary key when present, and optionally also derive an imperative-phrase slug for readability (e.g., "User can upload file" → `user-can-upload-file`). Include only Success Criteria items that require buildable work (e.g., load-testing infrastructure, security audit tooling), and exclude post-launch outcome metrics and business KPIs (e.g., "Reduce support tickets by 50%"). |
| 79 | +- **User story/action inventory**: Discrete user actions with acceptance criteria |
| 80 | +- **Task coverage mapping**: Map each task to one or more requirements or stories (inference by keyword / explicit reference patterns like IDs or key phrases) |
| 81 | +- **Constitution rule set**: Extract principle names and MUST/SHOULD normative statements |
| 82 | + |
| 83 | +### 4. Detection Passes (Token-Efficient Analysis) |
| 84 | + |
| 85 | +Focus on high-signal findings. Limit to 50 findings total; aggregate remainder in overflow summary. |
| 86 | + |
| 87 | +#### A. Duplication Detection |
| 88 | + |
| 89 | +- Identify near-duplicate requirements |
| 90 | +- Mark lower-quality phrasing for consolidation |
| 91 | + |
| 92 | +#### B. Ambiguity Detection |
| 93 | + |
| 94 | +- Flag vague adjectives (fast, scalable, secure, intuitive, robust) lacking measurable criteria |
| 95 | +- Flag unresolved placeholders (TODO, TKTK, ???, `<placeholder>`, etc.) |
| 96 | + |
| 97 | +#### C. Underspecification |
| 98 | + |
| 99 | +- Requirements with verbs but missing object or measurable outcome |
| 100 | +- User stories missing acceptance criteria alignment |
| 101 | +- Tasks referencing files or components not defined in spec/plan |
| 102 | + |
| 103 | +#### D. Constitution Alignment |
| 104 | + |
| 105 | +- Any requirement or plan element conflicting with a MUST principle |
| 106 | +- Missing mandated sections or quality gates from constitution |
| 107 | + |
| 108 | +#### E. Coverage Gaps |
| 109 | + |
| 110 | +- Requirements with zero associated tasks |
| 111 | +- Tasks with no mapped requirement/story |
| 112 | +- Success Criteria requiring buildable work (performance, security, availability) not reflected in tasks |
| 113 | + |
| 114 | +#### F. Inconsistency |
| 115 | + |
| 116 | +- Terminology drift (same concept named differently across files) |
| 117 | +- Data entities referenced in plan but absent in spec (or vice versa) |
| 118 | +- Task ordering contradictions (e.g., integration tasks before foundational setup tasks without dependency note) |
| 119 | +- Conflicting requirements (e.g., one requires Next.js while other specifies Vue) |
| 120 | + |
| 121 | +### 5. Severity Assignment |
| 122 | + |
| 123 | +Use this heuristic to prioritize findings: |
| 124 | + |
| 125 | +- **CRITICAL**: Violates constitution MUST, missing core spec artifact, or requirement with zero coverage that blocks baseline functionality |
| 126 | +- **HIGH**: Duplicate or conflicting requirement, ambiguous security/performance attribute, untestable acceptance criterion |
| 127 | +- **MEDIUM**: Terminology drift, missing non-functional task coverage, underspecified edge case |
| 128 | +- **LOW**: Style/wording improvements, minor redundancy not affecting execution order |
| 129 | + |
| 130 | +### 6. Produce Compact Analysis Report |
| 131 | + |
| 132 | +Output a Markdown report (no file writes) with the following structure: |
| 133 | + |
| 134 | +## Specification Analysis Report |
| 135 | + |
| 136 | +| ID | Category | Severity | Location(s) | Summary | Recommendation | |
| 137 | +|----|----------|----------|-------------|---------|----------------| |
| 138 | +| A1 | Duplication | HIGH | spec.md:L120-134 | Two similar requirements ... | Merge phrasing; keep clearer version | |
| 139 | + |
| 140 | +(Add one row per finding; generate stable IDs prefixed by category initial.) |
| 141 | + |
| 142 | +**Coverage Summary Table:** |
| 143 | + |
| 144 | +| Requirement Key | Has Task? | Task IDs | Notes | |
| 145 | +|-----------------|-----------|----------|-------| |
| 146 | + |
| 147 | +**Constitution Alignment Issues:** (if any) |
| 148 | + |
| 149 | +**Unmapped Tasks:** (if any) |
| 150 | + |
| 151 | +**Metrics:** |
| 152 | + |
| 153 | +- Total Requirements |
| 154 | +- Total Tasks |
| 155 | +- Coverage % (requirements with >=1 task) |
| 156 | +- Ambiguity Count |
| 157 | +- Duplication Count |
| 158 | +- Critical Issues Count |
| 159 | + |
| 160 | +### 7. Provide Next Actions |
| 161 | + |
| 162 | +At end of report, output a concise Next Actions block: |
| 163 | + |
| 164 | +- If CRITICAL issues exist: Recommend resolving before `/speckit.implement` |
| 165 | +- If only LOW/MEDIUM: User may proceed, but provide improvement suggestions |
| 166 | +- Provide explicit command suggestions: e.g., "Run /speckit.specify with refinement", "Run /speckit.plan to adjust architecture", "Manually edit tasks.md to add coverage for 'performance-metrics'" |
| 167 | + |
| 168 | +### 8. Offer Remediation |
| 169 | + |
| 170 | +Ask the user: "Would you like me to suggest concrete remediation edits for the top N issues?" (Do NOT apply them automatically.) |
| 171 | + |
| 172 | +## Operating Principles |
| 173 | + |
| 174 | +### Context Efficiency |
| 175 | + |
| 176 | +- **Minimal high-signal tokens**: Focus on actionable findings, not exhaustive documentation |
| 177 | +- **Progressive disclosure**: Load artifacts incrementally; don't dump all content into analysis |
| 178 | +- **Token-efficient output**: Limit findings table to 50 rows; summarize overflow |
| 179 | +- **Deterministic results**: Rerunning without changes should produce consistent IDs and counts |
| 180 | + |
| 181 | +### Analysis Guidelines |
| 182 | + |
| 183 | +- **NEVER modify files** (this is read-only analysis) |
| 184 | +- **NEVER hallucinate missing sections** (if absent, report them accurately) |
| 185 | +- **Prioritize constitution violations** (these are always CRITICAL) |
| 186 | +- **Use examples over exhaustive rules** (cite specific instances, not generic patterns) |
| 187 | +- **Report zero issues gracefully** (emit success report with coverage statistics) |
| 188 | + |
| 189 | +## Context |
| 190 | + |
| 191 | +$ARGUMENTS |
0 commit comments