specpro-cli 0.1.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (76) hide show
  1. specpro_cli/__init__.py +16 -0
  2. specpro_cli/assets/commands/specpro.analyze.md +1102 -0
  3. specpro_cli/assets/commands/specpro.checklist.md +335 -0
  4. specpro_cli/assets/commands/specpro.clarify.md +581 -0
  5. specpro_cli/assets/commands/specpro.constitution.md +488 -0
  6. specpro_cli/assets/commands/specpro.feature.md +115 -0
  7. specpro_cli/assets/commands/specpro.implement.md +1881 -0
  8. specpro_cli/assets/commands/specpro.manual-test.md +206 -0
  9. specpro_cli/assets/commands/specpro.plan.md +3284 -0
  10. specpro_cli/assets/commands/specpro.qc.md +1489 -0
  11. specpro_cli/assets/commands/specpro.scenarios.md +154 -0
  12. specpro_cli/assets/commands/specpro.specify.md +1449 -0
  13. specpro_cli/assets/commands/specpro.status.md +863 -0
  14. specpro_cli/assets/commands/specpro.tasks.md +1207 -0
  15. specpro_cli/assets/commands/specpro.test-implement.md +462 -0
  16. specpro_cli/assets/commands/specpro.test-plan.md +383 -0
  17. specpro_cli/assets/commands/specpro.user-manual.md +178 -0
  18. specpro_cli/assets/scripts/bash/check-anti-coupling.sh +293 -0
  19. specpro_cli/assets/scripts/bash/check-prerequisites.sh +176 -0
  20. specpro_cli/assets/scripts/bash/common.sh +88 -0
  21. specpro_cli/assets/scripts/bash/create-new-feature.sh +336 -0
  22. specpro_cli/assets/scripts/bash/qc-auto-fix.sh +121 -0
  23. specpro_cli/assets/scripts/bash/setup-plan.sh +60 -0
  24. specpro_cli/assets/scripts/bash/verify-cumulative-records.sh +203 -0
  25. specpro_cli/assets/scripts/bash/verify-deliverables-tracked.sh +147 -0
  26. specpro_cli/assets/scripts/bash/verify-deployment.sh +239 -0
  27. specpro_cli/assets/scripts/bash/verify-frontmatter-yaml.sh +63 -0
  28. specpro_cli/assets/scripts/bash/verify-ledger.sh +376 -0
  29. specpro_cli/assets/scripts/bash/verify-shapes.sh +1082 -0
  30. specpro_cli/assets/scripts/git-hooks/pre-commit +243 -0
  31. specpro_cli/assets/scripts/install-git-hooks.sh +67 -0
  32. specpro_cli/assets/scripts/powershell/check-anti-coupling.ps1 +249 -0
  33. specpro_cli/assets/scripts/powershell/check-prerequisites.ps1 +148 -0
  34. specpro_cli/assets/scripts/powershell/common.ps1 +95 -0
  35. specpro_cli/assets/scripts/powershell/create-new-feature.ps1 +229 -0
  36. specpro_cli/assets/scripts/powershell/qc-auto-fix.ps1 +110 -0
  37. specpro_cli/assets/scripts/powershell/setup-plan.ps1 +61 -0
  38. specpro_cli/assets/scripts/powershell/verify-cumulative-records.ps1 +133 -0
  39. specpro_cli/assets/scripts/powershell/verify-deliverables-tracked.ps1 +112 -0
  40. specpro_cli/assets/scripts/powershell/verify-deployment.ps1 +278 -0
  41. specpro_cli/assets/scripts/powershell/verify-frontmatter-yaml.ps1 +56 -0
  42. specpro_cli/assets/scripts/powershell/verify-ledger.ps1 +383 -0
  43. specpro_cli/assets/scripts/powershell/verify-shapes.ps1 +978 -0
  44. specpro_cli/assets/templates/agent-context-template.md +49 -0
  45. specpro_cli/assets/templates/assumptions-template.md +248 -0
  46. specpro_cli/assets/templates/checklist-template.md +40 -0
  47. specpro_cli/assets/templates/clarifications-template.md +155 -0
  48. specpro_cli/assets/templates/constitution-template.md +50 -0
  49. specpro_cli/assets/templates/feature-spec-template.md +66 -0
  50. specpro_cli/assets/templates/plan-overview-template.md +150 -0
  51. specpro_cli/assets/templates/plan-template.md +387 -0
  52. specpro_cli/assets/templates/protocol-golden-bytes-guide.md +195 -0
  53. specpro_cli/assets/templates/requirements-template.md +356 -0
  54. specpro_cli/assets/templates/spec-template.md +267 -0
  55. specpro_cli/assets/templates/tasks-template.md +252 -0
  56. specpro_cli/assets/templates/test-tasks-template.md +174 -0
  57. specpro_cli/cli/__init__.py +5 -0
  58. specpro_cli/cli/cmd_init.py +416 -0
  59. specpro_cli/cli/cmd_remove.py +122 -0
  60. specpro_cli/cli/entry.py +181 -0
  61. specpro_cli/integrations/__init__.py +36 -0
  62. specpro_cli/integrations/base.py +601 -0
  63. specpro_cli/integrations/claude/__init__.py +101 -0
  64. specpro_cli/integrations/copilot/__init__.py +153 -0
  65. specpro_cli/integrations/cursor_agent/__init__.py +51 -0
  66. specpro_cli/integrations/gemini/__init__.py +44 -0
  67. specpro_cli/integrations/opencode/__init__.py +48 -0
  68. specpro_cli/integrations/qodercli/__init__.py +54 -0
  69. specpro_cli/integrations/registry.py +88 -0
  70. specpro_cli/packaged/__init__.py +5 -0
  71. specpro_cli/packaged/sync.py +106 -0
  72. specpro_cli-0.1.0.dist-info/METADATA +117 -0
  73. specpro_cli-0.1.0.dist-info/RECORD +76 -0
  74. specpro_cli-0.1.0.dist-info/WHEEL +4 -0
  75. specpro_cli-0.1.0.dist-info/entry_points.txt +2 -0
  76. specpro_cli-0.1.0.dist-info/licenses/LICENSE +21 -0
@@ -0,0 +1,581 @@
1
+ ---
2
+ description: Identify underspecified areas in the current feature spec by asking up to 5 highly targeted clarification questions and encoding answers back into the spec.
3
+ handoffs:
4
+ - label: Build Technical Plan
5
+ agent: specpro-plan
6
+ prompt: Create a plan for the spec. I am building with...
7
+ writes:
8
+ # This command's write surface: only what it produces AS THE PRODUCER of that
9
+ # (artifact, unit) pair. A write this command makes on a non-producer path is a
10
+ # boundary violation by definition (FR-051) and MUST NOT be declared here.
11
+ # The full ownership map is the UNION of every command's writes: block.
12
+ - artifact: specs/clarifications.md
13
+ unit: "whole file in scan mode; per-item Status / Answer / Resolution fields in interactive mode"
14
+ - artifact: specs/spec.md
15
+ unit: "## Requirements -> the FR entries it updates or adds from answers; plus the User Story / acceptance-scenario / data-model text rewritten from those answers"
16
+ ---
17
+
18
+ ## User Input
19
+
20
+ ```text
21
+ $ARGUMENTS
22
+ ```
23
+
24
+ You **MUST** consider the user input before proceeding (if not empty).
25
+
26
+ **Rerun safety — detect the artifact, default to incremental** ⚠️ [settled 2026-09-13]:
27
+
28
+ **Before writing `specs/clarifications.md`, detect whether it already exists.** Use the SAME check in every command:
29
+
30
+ ```bash
31
+ [ -s specs/clarifications.md ] && echo EXISTS || echo NEW # -s: exists AND non-empty (an empty placeholder counts as NEW)
32
+ ```
33
+
34
+ | Detection | Mode |
35
+ |-----------|------|
36
+ | **NEW** (absent or empty) | **Initial** — generate from scratch |
37
+ | **EXISTS** | **Incremental** — evolve it; **never silently regenerate from scratch** |
38
+
39
+ **Overwriting an existing artifact requires explicit, confirmed intent:**
40
+ 1. Only when the user *explicitly* asks (in their own words) does the initial path run on an existing artifact.
41
+ 2. **Even then, confirm once more before writing** — name the artifact that will be replaced and what will be lost; wait for the answer.
42
+ 3. **Silence is not consent.** An unspecified run on an existing artifact is ALWAYS incremental.
43
+
44
+ > **Why a shared rule rather than per-command courtesy**: nine of the twelve non-implementation commands already had some protection, but each wrote it its own way (`EXISTING_SPEC` check · "creates a NEW file" · `NEVER overwrite` · "incremental regeneration" · `AUTO_MODE=false`), and **three had none at all** — not by decision, but because the discipline had no shared carrier. Overwriting an artifact the user has been evolving is not recoverable within the session; the cost of asking is one prompt.
45
+
46
+
47
+ ### Scope Resolution 🆕 (FR-063 / T050 · v0.23)
48
+
49
+ 1. **作用域判定**: 当前工作目录位于 `specs/fNNN-简称/` 内 ⇒ **feature 作用域**(读写范围 = 本 feature 目录,由 `check-prerequisites.sh` 的作用域感知解析);位于仓库根或 `specs/` 根 ⇒ **母作用域**(读写母规格链)。feature 作用域内 MUST NOT 写母产物——唯一例外:**发现登记**(台账路由,`[specify]`/`[plan]` 分区)。
50
+ 2. **新会话首次执行**: 若 `specs/features.md` 存在且含 `active` 行、而用户未指明作用域 ⇒ **询问用户**在母作用域还是某个 feature 内工作,MUST NOT 自行挑选。
51
+ 3. 本命令的产物路径随之解析:feature 作用域下落 `<feature 目录>/`,母作用域下落 `specs/`。
52
+
53
+ ## Outline
54
+
55
+ Goal: Detect and reduce ambiguity or missing decision points in the active feature specification. This command has two modes:
56
+
57
+ 1. **--scan mode**: Scan spec.md for ambiguities, categorize questions, generate/update clarifications.md (no user interaction)
58
+ 2. **Interactive mode** (default): Load clarifications.md, ask questions one by one, integrate answers into spec.md
59
+
60
+ Note: This clarification workflow is expected to run (and be completed) BEFORE invoking `/specpro-plan`. The Plan stage will auto-invoke this command if [Must Clarify] items remain unresolved.
61
+
62
+ ## Mode Detection ✨ ENHANCED with Smart Recommendations
63
+
64
+ **Step 1: Check for user-provided flags**:
65
+
66
+ **Check $ARGUMENTS for --scan flag**:
67
+ - If `$ARGUMENTS` contains "--scan": Execute **SCAN MODE** (steps 2-4)
68
+ - If `$ARGUMENTS` is empty: **Interactive mode selection** (see below)
69
+ - Otherwise: Execute **INTERACTIVE MODE** (steps 5-10)
70
+
71
+ **Step 2: Interactive mode selection (if no flags provided)** ✨ NEW:
72
+
73
+ If `$ARGUMENTS` is empty, detect context and provide intelligent mode selection:
74
+
75
+ ```markdown
76
+ ## 🔍 Clarification Mode Selection
77
+
78
+ No clarification mode specified. Please choose the appropriate mode:
79
+
80
+ **Context Detection**:
81
+ - Clarifications file exists: [YES/NO]
82
+ - Previous clarifications: [N total, M Must, N Suggested, K Can Infer]
83
+ - Unresolved Must Clarify: [N remaining]
84
+
85
+ ---
86
+
87
+ ### Mode Options:
88
+
89
+ **1. Interactive Mode** (Recommended for most cases)
90
+ - Ask questions one by one interactively
91
+ - You control the pace
92
+ - Integrate answers into spec.md immediately
93
+ - Best for: Thorough clarification with user oversight
94
+
95
+ **2. Scan Mode Only** (Recommended to generate questions without answering)
96
+ - Scan spec.md for ambiguities
97
+ - Categorize questions (Must/Suggested/Can Infer)
98
+ - Generate/update clarifications.md
99
+ - No user interaction required
100
+ - Best for: Quick question generation, review questions later
101
+
102
+ **3. Scan + Auto-Infer** (Recommended if you want AI to resolve automatically)
103
+ - Scan spec.md for ambiguities
104
+ - Auto-infer [Can Infer] questions automatically
105
+ - Mark as [inferred] in clarifications.md
106
+ - Leave [Must] and [Suggested] for manual resolution
107
+ - Best for: Reduce question count, focus on critical issues
108
+
109
+ ---
110
+
111
+ **AI Recommendation**: [Mode Name]
112
+
113
+ **Reason**: [Why this mode is recommended based on current context]
114
+
115
+ Examples:
116
+ - "No clarifications file exists → Interactive Mode (1) - Start from scratch"
117
+ - "You have 5 Must Clarify unresolved → Interactive Mode (1) - Complete critical questions"
118
+ - "You have 20 Can Infer items → Scan + Auto-Infer (3) - Auto-resolve obvious questions"
119
+ - "This is your first clarification → Interactive Mode (1) - Understand your requirements"
120
+
121
+ ---
122
+
123
+ Your choice (1-3):
124
+ ```
125
+
126
+ **Step 3: Execute selected mode**:
127
+
128
+ After user selection:
129
+ - **Choice 1**: Execute INTERACTIVE MODE (steps 5-10)
130
+ - **Choice 2**: Execute SCAN MODE only (steps 2-4), then stop
131
+ - **Choice 3**: Execute SCAN MODE (steps 2-4) + Auto-infer all [Can Infer] items
132
+
133
+ **Context Detection Rules**:
134
+ - **No clarifications.md** exists: Recommend Interactive Mode (1) - "Start from scratch"
135
+ - **Must Clarify > 0**: Recommend Interactive Mode (1) - "Complete critical questions first"
136
+ - **Can Infer > 10**: Recommend Scan + Auto-Infer (3) - "Many questions AI can answer"
137
+ - **First-time clarification** (no file): Recommend Interactive Mode (1)
138
+ - **Review phase** (clarifications.md exists, reviewing): Recommend Scan Mode (2)
139
+
140
+ **Smart Recommendation Logic**:
141
+ ```markdown
142
+ IF clarifications.md does NOT exist THEN:
143
+ Recommend: Interactive Mode (1)
144
+ Reason: "This is your first clarification. Best to go through questions interactively to understand your requirements."
145
+
146
+ ELSE IF [Must Clarify] items > 0 THEN:
147
+ Recommend: Interactive Mode (1)
148
+ Reason: "You have N critical [Must Clarify] questions remaining. These should be resolved before planning."
149
+
150
+ ELSE IF [Can Infer] items > 10 THEN:
151
+ Recommend: Scan + Auto-Infer (3)
152
+ Reason: "You have N [Can Infer] questions that AI can answer automatically. This will reduce manual effort."
153
+
154
+ ELSE:
155
+ Recommend: Interactive Mode (1)
156
+ Reason: "Continue clarifying any remaining questions interactively."
157
+ END IF
158
+ ```
159
+
160
+ ---
161
+
162
+ ## SCAN MODE (Generate clarifications.md)
163
+
164
+ Execution steps for scan mode:
165
+
166
+ 1. Run `.specpro/scripts/bash/check-prerequisites.sh --json --paths-only` from repo root **once**. Parse minimal JSON payload fields:
167
+ - `FEATURE_DIR`
168
+ - `FEATURE_SPEC`
169
+ - If JSON parsing fails, abort and instruct user to re-run `/specpro-specify` or verify the setup.
170
+
171
+ 2. Load the current spec file (FEATURE_SPEC). Perform a structured ambiguity & coverage scan using this taxonomy. For each category, mark status: Clear / Partial / Missing. Produce an internal coverage map used for prioritization.
172
+
173
+ Functional Scope & Behavior:
174
+ - Core user goals & success criteria
175
+ - Explicit out-of-scope declarations
176
+ - User roles / personas differentiation
177
+
178
+ Domain & Data Model:
179
+ - Entities, attributes, relationships
180
+ - Identity & uniqueness rules
181
+ - Lifecycle/state transitions
182
+ - Data volume / scale assumptions
183
+
184
+ Interaction & UX Flow:
185
+ - Critical user journeys / sequences
186
+ - Error/empty/loading states
187
+ - Accessibility or localization notes
188
+
189
+ Non-Functional Quality Attributes:
190
+ - Performance (latency, throughput targets)
191
+ - Scalability (horizontal/vertical, limits)
192
+ - Reliability & availability (uptime, recovery expectations)
193
+ - Observability (logging, metrics, tracing signals)
194
+ - Security & privacy (authN/Z, data protection, threat assumptions)
195
+ - Compliance / regulatory constraints (if any)
196
+
197
+ Integration & External Dependencies:
198
+ - External services/APIs and failure modes
199
+ - Data import/export formats
200
+ - Protocol/versioning assumptions
201
+ ⚠️ **This category carries a MANDATORY trigger, and the carve-out below does
202
+ not reach it** — see "The `Integration & External Dependencies` trigger" that
203
+ follows the list.
204
+
205
+ Edge Cases & Failure Handling:
206
+ - Negative scenarios
207
+ - Rate limiting / throttling
208
+ - Conflict resolution (e.g., concurrent edits)
209
+
210
+ Constraints & Tradeoffs:
211
+ - Technical constraints (language, storage, hosting)
212
+ - Explicit tradeoffs or rejected alternatives
213
+
214
+ Terminology & Consistency:
215
+ - Canonical glossary terms
216
+ - Avoided synonyms / deprecated terms
217
+
218
+ Completion Signals:
219
+ - Acceptance criteria testability
220
+ - Measurable Definition of Done style indicators
221
+
222
+ Misc / Placeholders:
223
+ - TODO markers / unresolved decisions
224
+ - Ambiguous adjectives ("robust", "intuitive") lacking quantification
225
+
226
+ For each category with Partial or Missing status, add a candidate question opportunity unless:
227
+ - Clarification would not materially change implementation or validation strategy
228
+ - Information is better deferred to planning phase (note internally)
229
+
230
+ ⚠️ **The `Integration & External Dependencies` trigger** — TR002's enforcement
231
+ point, and the one category the carve-out just above does NOT reach:
232
+
233
+ - **Trigger**: the spec names an outside system the product MUST interoperate with. Read
234
+ this at the **FUNCTIONAL layer** — a system the *requirements* talk to — never at
235
+ the implementation stack (libraries, frameworks, language versions are not it).
236
+ ⚠️ **Triggering does not require the spec to LABEL it**: what the criterion is
237
+ about is "an outside object exists and its failure modes have not been considered", and
238
+ how the spec happens to name that object — a labelled form, or a bare functional one
239
+ such as "the payment gateway the checkout flow calls" — is immaterial to that.
240
+ ⚠️ **And that is why this enforcement point lands HERE rather than on a second
241
+ scanner.** The same-named check in `/specpro-qc` recognises an outside system only when
242
+ the spec **labels** it (`外部` / `第三方` / `external …` /
243
+ `third-party`); on an unlabelled functional-layer name it returns
244
+ `⊘ not decidable by this scan`, by design and on the record (`ISS-150`). That is a
245
+ declared limit of a *pattern scan* — not of this step, which is executed by a reader,
246
+ and reading for meaning is exactly what the recognition needs.
247
+ - **When the trigger fires, this category MUST NOT be marked Clear**, and it MUST yield a
248
+ question covering all three of its own bullets above: **failure modes** ·
249
+ **protocol / versioning assumptions** · **data import/export formats**.
250
+ - **That question MUST be categorised `[Must Clarify]`, not `[Suggested Clarify]`.**
251
+ ⚠️ **This categorisation IS the enforcement point** — it is what turns the
252
+ rule from advice into a stop: an unresolved `[Must Clarify]` item makes `/specpro-plan`
253
+ halt at `⛔ PLAN BLOCKED` (`commands/specpro.plan.md` → `### Step 3: Quality
254
+ Gates` → `#### 3.0 Clarifications Quality Gate`; the consumer is named there and is
255
+ not restated here).
256
+ ⚠️ **It diverges from step 3b's default, deliberately**: step 3b files
257
+ "Integration patterns (RESTful, GraphQL, etc.)" under `[Suggested Clarify]`. That default
258
+ covers an integration's **style**, where a reasonable default exists and the user may let
259
+ it stand. This trigger covers **an outside object whose failure modes nobody has looked
260
+ at** — no reasonable default is inferable, which is `[Must Clarify]`'s own fourth
261
+ scope ("No reasonable default exists").
262
+ - **Negative cases — the trigger MUST NOT fire**: the spec names no outside system it must
263
+ interoperate with ⇒ judge this category as usual (Clear is allowed; no question is
264
+ produced). ⚠️ **A sentence that DENIES external dependencies does not fire it**
265
+ (`本项目自包含,无外部依赖。`): the
266
+ trigger reads whether an outside object is *required to take part*, not which nouns appear.
267
+
268
+ 3. **Categorize clarification questions** into three types:
269
+
270
+ a. **[Must Clarify]**: Critical questions that MUST be answered by the user before implementation. Plan stage is BLOCKED until these are resolved.
271
+ - Scope: Affects feature boundaries or what's included/excluded
272
+ - Security/Privacy: Legal, financial, or compliance implications
273
+ - User Roles: Multiple conflicting interpretations possible
274
+ - Performance Targets: No reasonable default exists
275
+
276
+ b. **[Suggested Clarify]**: Important questions with reasonable defaults. User can choose to answer manually OR request AI auto-inference.
277
+ - Error handling strategies (user-friendly messages, fallbacks)
278
+ - Data retention policies (industry-standard defaults)
279
+ - Integration patterns (RESTful, GraphQL, etc.)
280
+ - Performance optimization priorities
281
+
282
+ c. **[Can Infer]**: Questions that AI can answer using context, industry standards, or logical inference. AI will auto-resolve these.
283
+ - Logging formats (JSON with timestamp, level, message, context)
284
+ - Testing coverage targets (>70% business logic, >90% protocols)
285
+ - Code style (language conventions, indentation width, max line length)
286
+ - Standard authentication patterns (session-based or OAuth2 for web)
287
+
288
+ 4. **Load clarifications template**: Read `.specpro/templates/clarifications-template.md` to understand the required format.
289
+
290
+ 5. **Generate or update clarifications.md**:
291
+ - Load existing `specs/clarifications.md` if it exists (for UPDATE_MODE)
292
+ - Assign sequential IDs to new questions (Q001, Q002, etc.)
293
+ - For each clarification question, create an entry following the template format:
294
+ ```markdown
295
+ ### [Tag] - [ID] - [Question Summary]
296
+
297
+ **Status**: [ ] Unanswered | [x] Answered | [inferred] Auto-inferred
298
+
299
+ **Related Section**: [spec.md section reference, e.g., "FR-xxx", "US2"]
300
+
301
+ **Question**:
302
+ [Clear, specific question about requirements]
303
+
304
+ **Options** (if applicable):
305
+ | Option | Description | Implications |
306
+ |--------|-------------|--------------|
307
+ | A | [First option] | [What this means] |
308
+ | B | [Second option] | [What this means] |
309
+ | Auto | Let AI infer from context | [What AI will do] |
310
+
311
+ **Answer** (when answered or inferred):
312
+ [Concise answer that resolves the question]
313
+
314
+ **Resolution** (when answered or inferred):
315
+ - Updated spec.md section: [section name]
316
+ - New/updated FR: [FR-XXX] (if applicable)
317
+ - Details: [how the answer was integrated]
318
+ ```
319
+ - For [Can Infer] items, pre-fill the "Auto-Inference" field with how AI will resolve it
320
+ - Write to `specs/clarifications.md`
321
+ - If updating existing file, preserve already-resolved items ([x] or [inferred])
322
+
323
+ 6. **Report scan completion**:
324
+ ```markdown
325
+ ✓ Clarification scan complete
326
+
327
+ **Clarifications File**: specs/clarifications.md
328
+ - [Must Clarify]: M items (must be resolved before Plan)
329
+ - [Suggested Clarify]: N items (can answer manually or auto-infer)
330
+ - [Can Infer]: K items (AI can auto-resolve)
331
+
332
+ **Next Steps**:
333
+ - Run /specpro-clarify to start interactive clarification
334
+ - Or review clarifications.md first, then run /specpro-clarify
335
+ - Note: /specpro-plan will auto-invoke clarification if [Must Clarify] items remain
336
+ ```
337
+
338
+ ---
339
+
340
+ ## INTERACTIVE MODE (Ask questions and integrate answers) ✨ ENHANCED (Incremental Processing)
341
+
342
+ Execution steps for interactive mode:
343
+
344
+ 1. Run `.specpro/scripts/bash/check-prerequisites.sh --json --paths-only` from repo root **once**. Parse minimal JSON payload fields:
345
+ - `FEATURE_DIR`
346
+ - `FEATURE_SPEC`
347
+ - If JSON parsing fails, abort and instruct user to re-run `/specpro-specify` or verify the setup.
348
+
349
+ 2. **Load clarifications.md** ✨ ENHANCED:
350
+ - Read `specs/clarifications.md`
351
+ - If file doesn't exist, warn user: "No clarifications.md found. Please run `/specpro-clarify --scan` first to generate clarification questions."
352
+ - Extract all clarification items with status `[ ]` (unanswered)
353
+
354
+ 2.5. **Filter for Modified/New items** ✨ NEW (Incremental Clarification):
355
+
356
+ **Purpose**: Only ask questions related to modified or new spec items, skip already-processed questions
357
+
358
+ a. **Parse spec.md for Lifecycle fields**:
359
+ ```markdown
360
+ Load spec.md and extract Lifecycle status for items referenced in clarifications.md:
361
+ - User Stories: SpecStatus, PlanStatus, TasksStatus
362
+ - Functional Requirements: SpecStatus, PlanStatus, TasksStatus
363
+
364
+ Create map:
365
+ clarification_id → spec_item_status
366
+ ```
367
+
368
+ b. **Filter clarification questions**:
369
+ ```markdown
370
+ For each clarification in clarifications.md:
371
+ - Find related spec item (from "Related Section" field)
372
+ - Check spec item's SpecStatus:
373
+ * `[specify:…]` ∈ {`create`, `update`} → **KEEP** (needs clarification) —— ⚠️ 本节此前认的是 `"Add"`/`"Modified"`(`T174`),而 **Lifecycle 的取值表里没有这两个词** ⇒ 该过滤器在本仓库的任何产物上都保留不了东西,**且不报错**。
374
+ * `[specify:delete]`,或 `[plan:deprecated]`/`[tasks:deprecated]` → **SKIP** (item deprecated, ignore)
375
+ * SpecStatus = "" (no Lifecycle) → **KEEP** (legacy, pre-Lifecycle item)
376
+ ⚠️ **Those three branches are the WHOLE filter — everything not deprecated and not Lifecycle-less is KEEP.** A fourth branch reading `[specify:processed]` → SKIP used to sit here; it is **removed, not fixed** (`T247` / `ISS-220`): no writer anywhere in the toolchain ever produces that value, so the branch was **unreachable from the day it was written** — it could never skip anything, and its presence made the filter *look* like it excluded already-processed items. ⚠️ **Do not restore it**, and do not "give it a writer": `FR-046` fixes the segment's meaning as *how an item entered* (not where it now is), and `/specpro-specify`'s own merge rule forbids touching the Lifecycle of an unchanged item ⇒ **that segment has no terminal moment to write.**
377
+
378
+ Filtered clarifications:
379
+ - Total clarifications: N
380
+ - From modified/new items: X (ASK THESE)
381
+ - From deprecated items: Y (SKIP - no longer relevant)
382
+ - From legacy items (no Lifecycle): Z (ASK THESE — nothing says they were resolved)
383
+ ```
384
+
385
+ c. **Report filtering statistics**:
386
+ ```markdown
387
+ ## Clarification Filtering Summary
388
+
389
+ **Total Questions**: 15
390
+ - **From Modified/New Items**: 3 (ASK) ⭐
391
+ - **From Processed Items**: 10 (SKIP - already clarified)
392
+ - **From Deprecated Items**: 2 (SKIP - no longer relevant)
393
+
394
+ Processing 3 questions from modified/new items...
395
+ ```
396
+
397
+ d. **Create filtered question list**:
398
+ - Replace original clarification list with filtered list
399
+ - Only include questions from modified/new items
400
+ - Preserve question IDs, options, and metadata
401
+
402
+ **Benefits**:
403
+ - ✅ Clarify time reduced by 50-70% (skip already processed)
404
+ - ✅ Focus on truly unclear content (modified/new items)
405
+ - ✅ Avoid re-clarifying already resolved issues
406
+ - ✅ Smoother incremental iteration experience
407
+
408
+ 3. **Prioritize questions** by category:
409
+ - Process ALL [Must Clarify] items first (in order Q001, Q002, etc.)
410
+ - Then [Suggested Clarify] items
411
+ - Then [Can Infer] items
412
+
413
+ 4. **Sequential questioning loop**:
414
+ - Present EXACTLY ONE question at a time.
415
+ - For each question, display:
416
+ ```markdown
417
+ ### Question [ID]: [Question Summary]
418
+
419
+ **Category**: [Must Clarify | Suggested Clarify | Can Infer]
420
+ **Related Section**: [spec.md reference]
421
+
422
+ **Question**:
423
+ [Full question text]
424
+
425
+ **Options** (if applicable):
426
+ | Option | Description | Implications |
427
+ |--------|-------------|--------------|
428
+ | A | [Option A] | [Implications] |
429
+ | B | [Option B] | [Implications] |
430
+ | Auto | Let AI infer from context | [What AI will do] |
431
+
432
+ Your answer (option letter, "Auto", or custom answer):
433
+ ```
434
+ - For multiple‑choice questions:
435
+ - **Analyze all options** and determine the **most suitable option** based on:
436
+ - Best practices for the project type
437
+ - Common patterns in similar implementations
438
+ - Risk reduction (security, performance, maintainability)
439
+ - Alignment with any explicit project goals or constraints visible in the spec
440
+ - Present your **recommended option prominently** at the top with clear reasoning (1-2 sentences)
441
+ - Format as: `**Recommended:** Option [X] - <reasoning>`
442
+ - After the user answers:
443
+ - If the user replies with "yes", "recommended", "suggested", or "auto", use the recommended/auto-inferred answer
444
+ - Otherwise, validate the answer maps to one option or is appropriate
445
+ - Once satisfactory, proceed to integration
446
+
447
+ 5. **Integration after EACH accepted answer** (incremental update approach):
448
+ - **Core Principle**: Convert clarifications into Functional Requirements, not separate records
449
+ - Maintain in-memory representation of the spec (loaded once at start) plus clarifications.md
450
+ - For each accepted answer, immediately convert it to Functional Requirements:
451
+ - **Functional ambiguity** → Update or add a Functional Requirement (FR) with "System MUST" format
452
+ - **User interaction / actor distinction** → Update User Story description or add new acceptance scenario
453
+ - **Data shape / entities** → Update Data Model entities (add fields, types, relationships)
454
+ - **Non-functional constraint** → Add/modify FR with measurable criteria (convert vague adjective to metric)
455
+ - **Edge case / negative flow** → Add new FR with "System MUST" format (not separate Edge Cases section)
456
+ - **Technical decision** → Convert decision into FR (e.g., "Use hybrid protocol" → "System MUST use hybrid protocol...")
457
+ - If the clarification invalidates an earlier ambiguous statement, replace that FR instead of duplicating
458
+ - Use the next available FR number — e.g., if the highest existing FR is `FR-xxx`, the new one takes the next integer in sequence (never reuse or renumber)
459
+ - **Update clarifications.md**:
460
+ - Mark item status as `[x]` (Answered)
461
+ - Fill in "Answer" field with the user's response
462
+ - Fill in "Resolution" field with what was updated in spec.md
463
+ - Save BOTH spec.md and clarifications.md AFTER each integration (atomic overwrite)
464
+ - Preserve formatting: do not reorder unrelated sections; keep heading hierarchy intact
465
+
466
+ 6. **Validation** (performed after EACH write plus final pass):
467
+ - Each accepted answer was converted to a Functional Requirement or User Story update
468
+ - Updated spec.md sections contain no lingering vague placeholders
469
+ - No contradictory earlier statement remains
470
+ - Markdown structure valid
471
+ - Terminology consistency: same canonical term used across all updated sections
472
+ - clarifications.md was updated with [x] status and resolution details
473
+
474
+ 7. **Stop conditions** for questioning loop:
475
+ - ALL [Must Clarify] items have been answered (status [x])
476
+ - Then prompt user:
477
+ ```markdown
478
+ ✓ All [Must Clarify] items resolved
479
+
480
+ **Remaining Items**:
481
+ - [Suggested Clarify]: N items unresolved
482
+ - [Can Infer]: M items unresolved
483
+
484
+ **Next Steps**:
485
+ 1. Continue answering [Suggested Clarify] questions (recommended) - improves spec quality
486
+ 2. Auto-infer all remaining items - AI will resolve [Suggested Clarify] and [Can Infer] automatically
487
+ 3. Skip for now - leave remaining items unresolved, you can run /specpro-clarify again later
488
+
489
+ Your choice (1/2/3):
490
+ ```
491
+
492
+ 8. **Process user choice**:
493
+
494
+ a. **If user chooses 1 (Continue - recommended)**:
495
+ - Continue questioning loop with [Suggested Clarify] items
496
+ - Ask each [Suggested Clarify] question one by one
497
+ - After each answer, integrate into spec.md and clarifications.md (same as Step 5)
498
+ - After all [Suggested Clarify] resolved, prompt again:
499
+ ```markdown
500
+ ✓ All [Suggested Clarify] items resolved
501
+
502
+ **Remaining Items**:
503
+ - [Can Infer]: N items unresolved
504
+
505
+ **Next Steps**:
506
+ 1. Auto-infer [Can Infer] items (recommended) - AI will resolve automatically
507
+ 2. Continue answering [Can Infer] questions - answer each question manually
508
+ 3. Skip for now - leave [Can Infer] items unresolved
509
+
510
+ Your choice (1/2/3):
511
+ ```
512
+ - If user chooses 1: Run auto-inference on [Can Infer] items (see step 8b)
513
+ - If user chooses 2: Continue questioning loop with [Can Infer] items (same as Step 4)
514
+ - After all [Can Infer] resolved, proceed to completion report (step 9)
515
+ - If user chooses 3: Proceed to completion report (step 9)
516
+
517
+ b. **If user chooses 2 (Auto-infer)**:
518
+ - Process ALL remaining [Suggested Clarify] and [Can Infer] items automatically
519
+ - For each item:
520
+ - Use context, industry standards, and logical inference to determine answer
521
+ - Convert answer to FR or update spec.md as needed
522
+ - Mark item as `[inferred]` in clarifications.md
523
+ - Fill in "Answer" and "Resolution" fields
524
+ - Save spec.md and clarifications.md after each item
525
+ - Report: "✓ Auto-inferred N items (M [Suggested Clarify], K [Can Infer])"
526
+ - Proceed to completion report (step 9)
527
+
528
+ c. **If user chooses 3 (Skip)**:
529
+ - Proceed directly to completion report (step 9)
530
+ - Leave remaining items as unresolved ([ ] status)
531
+
532
+ 9. **Report completion** (after questioning loop ends or auto-inference completes):
533
+ ```markdown
534
+ ✓ Clarification complete
535
+
536
+ **Questions Resolved**: N answered, M auto-inferred
537
+ **Spec File**: [path to spec.md]
538
+ **Clarifications File**: [path to clarifications.md]
539
+
540
+ **Resolution Summary**:
541
+ - [Must Clarify]: N/M resolved (all required items resolved ✓)
542
+ - [Suggested Clarify]: X/Y resolved or inferred
543
+ - [Can Infer]: P/Q resolved or inferred
544
+
545
+ **Sections Updated**: [list of spec.md sections modified]
546
+
547
+ **Important**: Your spec.md has been significantly updated with clarification answers.
548
+ Please review the changes before proceeding to planning.
549
+
550
+ **Next Steps**:
551
+ 1. Review specs/spec.md to verify the updates
552
+ 2. Run /specpro-plan to create technical plan (ready - all [Must Clarify] resolved ✓)
553
+ 3. Or run /specpro-clarify again if more clarifications needed
554
+ ```
555
+
556
+ 10. **Quality gates**:
557
+ - If any [Must Clarify] items remain unresolved ([ ] status), warn user:
558
+ "⚠️ WARNING: [Must Clarify] items remain unresolved. /specpro-plan will be blocked until these are resolved."
559
+
560
+ Behavior rules:
561
+
562
+ **For SCAN MODE**:
563
+ - If spec.md is missing, abort and instruct user to run `/specpro-specify` first
564
+ - If no meaningful ambiguities found, respond: "No critical ambiguities detected worth formal clarification. Clarifications file not created." and suggest proceeding to `/specpro-plan`
565
+ - Always generate clarifications.md even if only [Can Infer] items exist
566
+ - Preserve existing [x] or [inferred] items when updating
567
+
568
+ **For INTERACTIVE MODE**:
569
+ - If clarifications.md doesn't exist, instruct user to run `/specpro-clarify --scan` first
570
+ - If all items already resolved ([x] or [inferred]), report: "All clarifications resolved. Ready for `/specpro-plan`."
571
+ - Respect user early termination signals ("stop", "done", "proceed")
572
+ - After completing [Must Clarify], ALWAYS prompt about [Suggested Clarify] and [Can Infer] items (don't auto-advance)
573
+ - Auto-inference MUST process both [Suggested Clarify] and [Can Infer] items when requested
574
+ - Never skip unresolved [Must Clarify] items - these are hard blockers for Plan
575
+
576
+ **Common rules**:
577
+ - Clarifications are converted to Functional Requirements (not separate records)
578
+ - Each answer is immediately integrated into spec.md and clarifications.md
579
+ - Maintain traceability: every clarification should have a Resolution field linking to spec.md changes
580
+
581
+ Context for prioritization: $ARGUMENTS