@gordon.gan/specflow 1.3.3-beta → 1.4.1

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 (85) hide show
  1. package/README.md +6 -2
  2. package/dist/integrations/shared/capability-evidence.js +37 -1
  3. package/dist/integrations/shared/command-catalog.js +1 -0
  4. package/dist/integrations/shared/parity-manifest.js +6 -0
  5. package/package.json +1 -1
  6. package/prompts/approval/database-guidance.md +79 -0
  7. package/prompts/approval/generate.md +1191 -0
  8. package/skills/database/LICENSE +405 -0
  9. package/skills/database/ORIGIN.md +6 -0
  10. package/skills/database/README.md +30 -0
  11. package/skills/database/elasticsearch/LICENSE.txt +202 -0
  12. package/skills/database/elasticsearch/SKILL.md +199 -0
  13. package/skills/database/elasticsearch/examples/01-fulltext-search.md +215 -0
  14. package/skills/database/elasticsearch/examples/02-aggregation-report.md +206 -0
  15. package/skills/database/elasticsearch/examples/03-reindex-zero-downtime.md +200 -0
  16. package/skills/database/elasticsearch/examples/04-cluster-monitoring.md +204 -0
  17. package/skills/database/elasticsearch/references/01-query-dsl-fulltext.md +162 -0
  18. package/skills/database/elasticsearch/references/02-query-dsl-term.md +210 -0
  19. package/skills/database/elasticsearch/references/03-aggregations-metric.md +161 -0
  20. package/skills/database/elasticsearch/references/04-aggregations-bucket.md +236 -0
  21. package/skills/database/elasticsearch/references/05-mapping-types.md +134 -0
  22. package/skills/database/elasticsearch/references/06-analyzers.md +187 -0
  23. package/skills/database/elasticsearch/references/07-cluster-ops.md +225 -0
  24. package/skills/database/elasticsearch/references/08-elk-integration.md +170 -0
  25. package/skills/database/mysql/SKILL.md +195 -0
  26. package/skills/database/mysql/examples/01-connection-pool.md +75 -0
  27. package/skills/database/mysql/examples/02-slow-query-optimization.md +98 -0
  28. package/skills/database/mysql/examples/03-master-slave-setup.md +144 -0
  29. package/skills/database/mysql/examples/04-backup-strategy.md +212 -0
  30. package/skills/database/mysql/references/01-functions-string.md +103 -0
  31. package/skills/database/mysql/references/02-functions-date.md +152 -0
  32. package/skills/database/mysql/references/03-functions-aggregate-window.md +167 -0
  33. package/skills/database/mysql/references/04-functions-json.md +129 -0
  34. package/skills/database/mysql/references/05-sql-ddl-types.md +235 -0
  35. package/skills/database/mysql/references/06-index-optimization.md +232 -0
  36. package/skills/database/mysql/references/07-replication-ha.md +213 -0
  37. package/skills/database/mysql/references/08-backup-restore.md +207 -0
  38. package/skills/database/mysql/references/09-advanced-features.md +345 -0
  39. package/skills/database/oracle/LICENSE.txt +202 -0
  40. package/skills/database/oracle/SKILL.md +238 -0
  41. package/skills/database/oracle/examples/01-plsql-procedure.md +90 -0
  42. package/skills/database/oracle/examples/02-awr-analysis.md +99 -0
  43. package/skills/database/oracle/examples/03-rman-backup.md +108 -0
  44. package/skills/database/oracle/examples/04-dataguard-setup.md +146 -0
  45. package/skills/database/oracle/references/01-functions-string.md +91 -0
  46. package/skills/database/oracle/references/02-functions-date.md +71 -0
  47. package/skills/database/oracle/references/03-analytic-functions.md +103 -0
  48. package/skills/database/oracle/references/04-plsql-guide.md +303 -0
  49. package/skills/database/oracle/references/05-performance-tuning.md +164 -0
  50. package/skills/database/oracle/references/06-backup-recovery.md +115 -0
  51. package/skills/database/oracle/references/07-dataguard-rac.md +76 -0
  52. package/skills/database/oracle/references/08-security.md +170 -0
  53. package/skills/database/oracle/references/09-sql-syntax.md +152 -0
  54. package/skills/database/oracle/references/10-features.md +174 -0
  55. package/skills/database/postgresql/LICENSE.txt +202 -0
  56. package/skills/database/postgresql/SKILL.md +182 -0
  57. package/skills/database/postgresql/examples/.gitkeep +0 -0
  58. package/skills/database/postgresql/examples/01-jsonb-query.md +72 -0
  59. package/skills/database/postgresql/examples/02-cte-recursive.md +110 -0
  60. package/skills/database/postgresql/examples/03-performance-tuning.md +114 -0
  61. package/skills/database/postgresql/examples/04-streaming-replication.md +113 -0
  62. package/skills/database/postgresql/references/.gitkeep +0 -0
  63. package/skills/database/postgresql/references/01-functions-string.md +174 -0
  64. package/skills/database/postgresql/references/02-functions-datetime.md +54 -0
  65. package/skills/database/postgresql/references/03-functions-aggregate-window.md +142 -0
  66. package/skills/database/postgresql/references/04-functions-jsonb.md +117 -0
  67. package/skills/database/postgresql/references/05-fulltext-search.md +109 -0
  68. package/skills/database/postgresql/references/06-index-types.md +95 -0
  69. package/skills/database/postgresql/references/07-partition-fdw.md +133 -0
  70. package/skills/database/postgresql/references/08-replication-backup.md +215 -0
  71. package/skills/database/redis/LICENSE.txt +202 -0
  72. package/skills/database/redis/SKILL.md +922 -0
  73. package/skills/database/redis/examples/01-cache-usage.md +104 -0
  74. package/skills/database/redis/examples/02-session-storage.md +72 -0
  75. package/skills/database/redis/examples/03-leaderboard.md +63 -0
  76. package/skills/database/redis/examples/04-redis-cluster-setup.md +70 -0
  77. package/skills/database/redis/examples/05-stream-queue.md +65 -0
  78. package/skills/database/redis/references/command-quick-ref.md +180 -0
  79. package/skills/database/redis/references/commands-admin-key.md +413 -0
  80. package/skills/database/redis/references/commands-set-sorted-advanced.md +539 -0
  81. package/skills/database/redis/references/commands-string-hash-list.md +458 -0
  82. package/skills/database/redis/references/memory-optimization.md +150 -0
  83. package/skills/database/redis/references/redis-conf-production.md +139 -0
  84. package/skills/specflow-approval/SKILL.md +427 -0
  85. package/templates/approval.md +464 -0
@@ -0,0 +1,1191 @@
1
+ <!-- SOURCE: SpecFlow original — integrates OpenSpec structural aggregation, arc42 design-review framework, ADR status fields, Superpowers challenge-behavior injection, and SpecFlow verify/review grounding patterns -->
2
+
3
+ # Approval Document Generation
4
+
5
+ > This prompt drives the `/specflow:approval` skill. It defines the 7-Pass closed-loop
6
+ > verification, design quality assessment, detailed design generation, implementability
7
+ > assessment, and the exact structure of `approval.md`. The calling SKILL.md owns phase
8
+ > gating, anchor-file extraction, and user confirmation; this prompt owns the analysis
9
+ > and document generation.
10
+
11
+ ## Entry Context
12
+
13
+ Before running this flow, the SKILL.md has confirmed:
14
+
15
+ - `phase: refined` in `.specflow.yaml`
16
+ - All four artifacts exist: `proposal.md`, `specs/**/*.md`, `design.md`, `tasks.md`
17
+ - `artifacts.language` resolved (default `en`)
18
+ - Tech stack detected (Node/Go/Python/Rust/unknown)
19
+ - Anchor files extracted from `design.md` + `tasks.md`
20
+ - Optional: `specflow/specs/` baseline exists (for Pass 7)
21
+
22
+ You MUST read, in this order, before any analysis:
23
+
24
+ 1. `specflow/changes/<name>/proposal.md` — the WHY and WHAT
25
+ 2. `specflow/changes/<name>/specs/**/*.md` — the behavioral contract (all delta specs)
26
+ 3. `specflow/changes/<name>/design.md` — the HOW (decisions, risks)
27
+ 4. `specflow/changes/<name>/tasks.md` — the implementation breakdown
28
+ 5. `specflow/changes/<name>/.specflow.yaml` — metadata (phase, created date)
29
+ 6. Optional: `specflow/changes/<name>/explore.md` — exploration context
30
+ 7. Optional: `specflow/specs/` baseline — for Pass 7 cross-check
31
+ 8. Anchor files (read in Pass 6, not here)
32
+
33
+ Do not skip any of the four required artifacts. If any is missing, stop and tell the
34
+ SKILL.md caller which are missing.
35
+
36
+ ---
37
+
38
+ ## Part A: Closed-Loop Verification (7 Passes)
39
+
40
+ Each Pass examines cross-artifact or artifact-to-reality coherence from one angle.
41
+ Every Pass MUST produce (for analysis / conversation):
42
+
43
+ 1. A **Verdict**: `PASS` | `WARNING` | `FAIL` | `SKIPPED`
44
+ 2. **Evidence**: concrete citations (keep brief; full matrices only when WARNING/FAIL)
45
+ 3. A brief **rationale** linking evidence to verdict
46
+
47
+ **Document output (§8)**: collapse all 7 Passes into **one table** — see Part E §8.
48
+ Do not paste per-Pass essays into `approval.md`.
49
+
50
+ Verdict calibration:
51
+
52
+ - `PASS` — no gaps found in this dimension.
53
+ - `WARNING` — gaps exist but are recoverable. The plan is still implementable but the approver should note the risk.
54
+ - `FAIL` — a structural break exists. The plan is not coherent or not grounded as-is.
55
+ - `SKIPPED` — the check does not apply (e.g., greenfield project for Pass 6/7). A `SKIPPED` Pass does not affect the overall verdict.
56
+
57
+ ### Pass 1 — Requirement Closure (proposal ↔ specs)
58
+
59
+ **AI self-prompt**: "Does every item in proposal's `## What Changes` have a corresponding
60
+ delta spec? Does every capability listed in `## Capabilities` have a `specs/<name>/spec.md`?
61
+ Does every impact area in `## Impact` have spec coverage? Is there a delta spec that the
62
+ proposal never mentioned (orphan spec)?"
63
+
64
+ **Check**:
65
+
66
+ 1. For each bullet in `## What Changes`, identify which capability/spec addresses it. If a change bullet has no corresponding spec, that is a `FAIL`.
67
+ 2. For each capability in `## Capabilities → New/Modified`, confirm `specs/<name>/spec.md` exists. Missing spec file is a `FAIL`.
68
+ 3. For each impact area in `## Impact`, assess whether the specs cover the behavioral consequences. Uncovered impact is a `WARNING`.
69
+ 4. For each delta spec file, confirm the proposal mentions its capability. Orphan spec is a `WARNING`.
70
+
71
+ **Evidence format**: a table mapping proposal items → spec files, with coverage status.
72
+
73
+ ### Pass 2 — Design Closure (design ↔ specs)
74
+
75
+ **AI self-prompt**: "Does every `### Decision N` in design.md point to at least one spec
76
+ Requirement it enables? Is there a spec Requirement that has no design decision supporting
77
+ it (orphan requirement)? Does any design decision contradict a spec scenario?"
78
+
79
+ **Check**:
80
+
81
+ 1. For each decision in `design.md` under `## Design Decisions` (or equivalent), identify which spec Requirements it enables. A decision with no traceable requirement is a `WARNING`.
82
+ 2. For each spec Requirement, identify which design decision(s) support its implementation. A requirement with no supporting decision is a `WARNING`.
83
+ 3. Scan for contradictions: does any design decision specify behavior that conflicts with a `WHEN/THEN` scenario? Contradiction is a `FAIL`.
84
+
85
+ **Evidence format**: a bidirectional table — decisions → requirements, and requirements → decisions.
86
+
87
+ ### Pass 3 — Spec Closure (scenario completeness + testability + delta integrity)
88
+
89
+ **AI self-prompt**: "Does every Requirement have at least one Scenario? Are WHEN/THEN clauses
90
+ testable? Are delta operations structurally complete?"
91
+
92
+ **Check**:
93
+
94
+ 1. Every `### Requirement:` has ≥1 `#### Scenario:`. Missing scenario is a `FAIL`.
95
+ 2. Every Scenario has at least one `- **WHEN**` and one `- **THEN**`. Missing clause is a `FAIL`.
96
+ 3. **3-level testability grading** for each Scenario:
97
+ - **Functional-testable** (✅): WHEN condition is reproducible (specific input/config/state), THEN is verifiable (specific output/behavior). Example: "config contains `artifacts.language: zh-CN`" → reproducible.
98
+ - **Document-testable** (⚠️): Tests existence/completeness but not behavior. Example: "a user reads the initialization documentation" → can only verify doc exists, not that a user "reads" it.
99
+ - **Untestable** (❌): WHEN or THEN uses vague terms ("appropriate", "reasonable", "fast", "适当", "合理", "快速") or describes an unverifiable state.
100
+ - Document-testable and Untestable are both `WARNING`.
101
+ 4. REMOVED Requirements have `**Reason**:` and `**Migration**:`. Missing is a `FAIL`.
102
+ 5. RENAMED Requirements have `FROM:` and `TO:`. Missing is a `FAIL`.
103
+ 6. MODIFIED Requirements reference names that exist in the main specs baseline (if baseline exists). Mismatched name is a `FAIL`.
104
+ 7. Run `specflow validate` on each delta spec file. Any validation error is a `FAIL`.
105
+ 8. **Detailed-design coverage** (cross-check with §4 方案详细设计): every spec Requirement
106
+ that involves data/interface/flow changes must have a corresponding detailed-design
107
+ element. A Requirement whose implementation needs a data structure, interface, or state
108
+ flow but has NO detailed-design element (or an element marked "待 refine 澄清") is a
109
+ `WARNING` — the plan describes WHAT but not HOW to build it.
110
+
111
+ **Evidence format**: per-spec-file, a Scenario table with columns: Scenario | WHEN | THEN | Testability (✅/⚠️/❌) | Notes.
112
+
113
+ ### Pass 4 — Implementation Closure (tasks ↔ specs)
114
+
115
+ **AI self-prompt**: "Does every spec Requirement have at least one task implementing it? Is
116
+ there a task that implements behavior not in any spec (scope creep)? Are tasks atomic enough?"
117
+
118
+ **Check**:
119
+
120
+ 1. For each spec Requirement, identify which task(s) implement it. A requirement with no covering task is a `FAIL`.
121
+ 2. For each task, identify which spec Requirement it implements. A task with no traceable requirement is a `WARNING` (scope creep).
122
+ 3. Scan tasks for placeholders: 'TBD', 'TODO', 'implement feature', '待定'. Each is a `WARNING`.
123
+ 4. Assess task granularity: tasks that bundle multiple unrelated changes, or are so vague an engineer cannot estimate them, are `WARNING`.
124
+
125
+ **Evidence format**: coverage matrix — requirements (rows) × tasks (columns), plus "scope creep" section.
126
+
127
+ ### Pass 5 — Risk Closure (risks ↔ mitigations + BREAKING migration + unidentified risks)
128
+
129
+ **AI self-prompt**: "Does every risk in design.md have a mitigation? Are there BREAKING
130
+ changes with no migration plan? Based on the change's nature, are there risks the design
131
+ did not identify?"
132
+
133
+ **Check**:
134
+
135
+ 1. For each risk in `design.md` under `## Risks / Trade-offs`, confirm a mitigation exists. Risk with no mitigation is a `WARNING`.
136
+ 2. For each `**BREAKING**` item in proposal's `## What Changes`, confirm a migration path. BREAKING with no migration is a `FAIL`.
137
+ 3. Reason about unidentified risks based on the change's nature: auth/security, data schema/migration, concurrency/race, external dependency supply-chain. Each unidentified risk is a `WARNING` with reasoning.
138
+
139
+ **Evidence format**: risk table with columns: Risk | Severity | Mitigation | Status (identified+mitigated / identified+unmitigated / AI-identified-new).
140
+
141
+ ### Pass 6 — Code Grounding (design/tasks ↔ existing project code)
142
+
143
+ > This Pass reads actual project code. It is the key difference between "self-consistency
144
+ > check" and "landing feasibility check".
145
+
146
+ **AI self-prompt**: "Do the files the plan says it will modify/extend actually exist? Is the
147
+ plan's extension approach compatible with the existing code structure? Does the plan's
148
+ tech choices match the project's actual tech stack?"
149
+
150
+ **Anchor files**: the SKILL.md has already extracted the set of file paths referenced in
151
+ `design.md` and `tasks.md`. Read each anchor file (the file itself only — do NOT follow
152
+ imports, do NOT recurse into dependencies).
153
+
154
+ **Greenfield handling**: If the project has no source code directory (e.g., no `src/`,
155
+ no `lib/`, no `cmd/`), emit `SKIPPED (greenfield — no existing code to ground against)`
156
+ and do not grade.
157
+
158
+ **Check** (for non-greenfield projects):
159
+
160
+ 1. **File existence**: For each anchor file path, check if the file exists in the project.
161
+ - All exist → this sub-check passes.
162
+ - Some missing → `FAIL` with the list of missing files. The plan references files that don't exist — either it's wrong about the codebase, or it's a greenfield file to be created (if the plan clearly says "create new file X", that's fine; if it says "extend existing file X" and X doesn't exist, that's a FAIL).
163
+ - Plan says "create new file" and file doesn't exist → OK (not a failure).
164
+
165
+ 2. **Structure compatibility**: For each existing anchor file, read it and assess:
166
+ - If the plan says "extend function X" — does function X exist? Is it structured to be extensible (e.g., has a clear signature, not a monolithic 500-line function)?
167
+ - If the plan says "add module Y" — does the parent directory's pattern support adding modules (e.g., are there sibling modules following a consistent pattern)?
168
+ - If the plan says "modify config schema" — does the current schema structure support the modification without breaking existing consumers?
169
+ - Incompatibility is a `WARNING` (not a `FAIL` — the plan might still work with adjustments, but the approver should know).
170
+
171
+ 3. **Tech-stack consistency**: Does the plan's technology approach match the detected tech stack?
172
+ - Plan uses patterns/libraries consistent with the project's `package.json`/`go.mod`/etc. → OK.
173
+ - Plan introduces a new library/ pattern not in the project → `WARNING` with reasoning (may be justified, but the approver should confirm).
174
+ - Plan contradicts the tech stack (e.g., plan says "use jest" but project uses vitest) → `WARNING` unless design.md explicitly justifies the switch.
175
+
176
+ **Evidence format**:
177
+ - Table: Anchor File | Exists? | Plan Action (extend/create/modify) | Compatibility Assessment
178
+ - Tech-stack consistency: one-line verdict with reasoning.
179
+ - For greenfield: the single `SKIPPED (greenfield)` line, verbatim.
180
+
181
+ ### Pass 7 — Baseline Cross-Check (delta specs ↔ `specflow/specs/` main baseline)
182
+
183
+ > This Pass checks whether the change's delta specs conflict with or duplicate existing
184
+ > main specs. It is the "plan-time regression check" — verify owns the "implementation-time
185
+ > regression check".
186
+
187
+ **AI self-prompt**: "Do the delta specs' ADDED requirements duplicate anything already in the
188
+ main specs? Do the MODIFIED requirements' names match existing main spec requirement names
189
+ (so delta merge will work at archive time)? Does the change claim to modify a capability that
190
+ doesn't exist in the baseline?"
191
+
192
+ **Baseline handling**: If `specflow/specs/` does not exist or contains no spec files, emit
193
+ `SKIPPED (no baseline — greenfield or no archived changes yet)` and do not grade. This is
194
+ the same pattern as verify Pass 2.
195
+
196
+ **Check** (when baseline exists):
197
+
198
+ 1. **Duplicate detection**: For each ADDED Requirement in the delta specs, check if a Requirement with the same name already exists in the main spec for the same capability. Duplicate is a `WARNING` (the archive merge would produce a duplicate header).
199
+ 2. **MODIFIED name matching**: For each MODIFIED Requirement, confirm a Requirement with the exact same name exists in the corresponding main spec. Mismatch is a `FAIL` (delta merge at archive time would fail with "Requirement not found").
200
+ 3. **REMOVED name matching**: For each REMOVED Requirement, confirm it exists in the main spec. Mismatch is a `FAIL`.
201
+ 4. **RENAMED FROM matching**: For each RENAMED Requirement's `FROM:` name, confirm it exists in the main spec. Mismatch is a `FAIL`.
202
+ 5. **Cross-capability conflict**: If the change modifies capability A's spec, does the change introduce behavior that conflicts with capability B's existing spec (if B exists in baseline)? Conflict is a `WARNING`.
203
+
204
+ **Evidence format**:
205
+ - For each delta operation (ADDED/MODIFIED/REMOVED/RENAMED), a row: Capability | Requirement Name | Operation | Baseline Status (exists/duplicate/not-found) | Verdict.
206
+ - For greenfield: the single `SKIPPED (no baseline)` line, verbatim.
207
+
208
+ ### Closed-Loop Overall Verdict
209
+
210
+ - `FAIL` if any non-SKIPPED Pass is `FAIL`
211
+ - `PASS WITH WARNINGS` if no `FAIL` but ≥1 non-SKIPPED Pass is `WARNING`
212
+ - `PASS` if all non-SKIPPED Passes are `PASS` (SKIPPED Passes do not affect the verdict)
213
+
214
+ ---
215
+
216
+ ## Part B: Design Quality Assessment
217
+
218
+ ### Over-Engineering Check
219
+
220
+ Scan `design.md` and `tasks.md` for 5 over-engineering signals. Each signal detected must
221
+ cite the specific design section or task.
222
+
223
+ | # | Signal | How to detect | Example |
224
+ |---|--------|--------------|---------|
225
+ | 1 | Interface for unrequested requirements | design defines interfaces/capabilities not in spec's Requirements | spec only requires `en`/`zh-CN`, design builds a `LocaleRegistry` |
226
+ | 2 | Unnecessary abstraction layer | single implementation gets an interface + factory + strategy | one reviewer type → `ReviewerFactory` + `ReviewerStrategy` |
227
+ | 3 | Pre-built unused infrastructure | tasks include infrastructure not required by any spec scenario | CLI option change → builds a plugin system |
228
+ | 4 | Config fields beyond current needs | YAML schema defines fields with no current consumer | `artifacts.language` + pre-built `artifacts.format`/`artifacts.tone` |
229
+ | 5 | Complexity exceeding problem scale | simple problem uses heavy pattern (state machine, event bus, middleware chain) for a boolean config |
230
+
231
+ **Verdict rule**:
232
+ - 0 signals → `PASS`
233
+ - 1-2 signals → `WARNING` (each must cite design section)
234
+ - 3+ signals → `FAIL` (the plan is over-engineered)
235
+
236
+ ### Extensibility Assessment
237
+
238
+ Scan `design.md` for 5 extensibility signals. Each signal detected must cite the specific
239
+ decision or section.
240
+
241
+ | # | Signal | How to detect | Example (from SpecFlow's own design D1) |
242
+ |---|--------|--------------|----------------------------------------|
243
+ | 1 | Namespace reservation | config uses nested key to leave room for siblings | `artifacts.language` not `artifactLanguage` |
244
+ | 2 | Stable interface, replaceable implementation | type/interface defined clearly but no pre-built multi-impl | `ArtifactLanguage` type with `en`/`zh-CN` only |
245
+ | 3 | Explicit Non-Goals | design has a Non-Goals section listing what's NOT done | "本变更不支持任意 BCP 47 语言" |
246
+ | 4 | Backward-compatibility path | design describes how existing behavior stays compatible | "缺省 `artifacts.language` 解析为 `en`" |
247
+ | 5 | Decision rationale mentions extensibility trade-off | a Decision block's rationale explicitly weighs extensibility | D1 rationale: "为未来 artifact 设置留命名空间" |
248
+
249
+ **Verdict rule**:
250
+ - 4-5 signals → `PASS`
251
+ - 2-3 signals → `WARNING`
252
+ - 0-1 signals → `WARNING` (the plan may be too rigid — approver should confirm extensibility was considered)
253
+
254
+ ### Combined Design Quality Verdict
255
+
256
+ - `FAIL` if over-engineering is `FAIL`
257
+ - `FAIL` (escalated) if over-engineering is `WARNING`/`FAIL` AND extensibility is `WARNING` — the plan is both bloated AND not extensible
258
+ - `WARNING` if either check is `WARNING` (without the escalation condition)
259
+ - `PASS` if both checks are `PASS`
260
+
261
+ ---
262
+
263
+ ## Part C: Implementability Assessment (7 Dimensions)
264
+
265
+ Each dimension produces a verdict: `READY` | `NEEDS REFINEMENT` | `BLOCKED`.
266
+
267
+ ### Dimension 1: Completeness
268
+ Scan all four artifacts for TODOs/placeholders/vague sections.
269
+ - `READY` if no placeholders. `NEEDS REFINEMENT` if non-critical. `BLOCKED` if in spec requirements or critical decisions.
270
+
271
+ ### Dimension 2: Spec Alignment
272
+ Tasks cover all spec requirements? Scope creep?
273
+ - `READY` if full coverage, no scope creep. `NEEDS REFINEMENT` if minor gaps/creep. `BLOCKED` if a core requirement has zero tasks.
274
+
275
+ ### Dimension 3: Task Actionability
276
+ Each task concrete and executable? Paths, commands, expected outputs defined?
277
+ - `READY` if all actionable. `NEEDS REFINEMENT` if some vague. `BLOCKED` if tasks are too coarse to start.
278
+
279
+ ### Dimension 4: Technical Feasibility
280
+ Design decisions achievable in the detected tech stack?
281
+ - `READY` if all feasible. `NEEDS REFINEMENT` if a new dependency/infra is plausible but unconfirmed. `BLOCKED` if a decision is technically infeasible.
282
+
283
+ ### Dimension 5: Dependency Clarity
284
+ Task dependencies and external dependencies explicit? Execution order derivable?
285
+ - `READY` if explicit and clear. `NEEDS REFINEMENT` if implicit but inferrable. `BLOCKED` if ambiguous and unsequenceable.
286
+
287
+ ### Dimension 6: Architecture Consistency
288
+ > Grounded in code reading from Pass 6. Reuse Pass 6's anchor-file findings.
289
+
290
+ Design choices match the project's existing patterns:
291
+ - **Tech stack**: plan's libraries/patterns match `package.json`/`go.mod`/etc.
292
+ - **Directory structure**: new modules placed where siblings live (e.g., `src/core/` not `src/utils/` if existing core modules are in `src/core/`)
293
+ - **Error handling**: plan uses the project's error pattern (e.g., `StoreError` with diagnostics, not bare `throw new Error`)
294
+ - **Test framework**: plan's test approach matches project's framework (vitest not jest, if vitest is in use)
295
+ - `READY` if all consistent. `NEEDS REFINEMENT` if 1-2 inconsistencies with justification. `BLOCKED` if fundamental mismatch (e.g., plan requires a framework the project doesn't use and can't easily add).
296
+
297
+ ### Dimension 7: Implementation Risk
298
+ Assess risk factors that could derail implementation:
299
+ - **Core module change**: does the plan modify high-risk modules (delta merge engine, parser, archive, validator)?
300
+ - **Data migration**: does the change require migrating existing data formats?
301
+ - **Concurrency**: does the change touch concurrent/transactional code?
302
+ - **External API break**: does the change break interfaces other consumers depend on?
303
+ - **Team tech-stack unfamiliarity**: does the plan use technologies the project doesn't already use (inferring from `package.json`/`go.mod`)?
304
+ - `READY` if no high-risk items. `NEEDS REFINEMENT` if high-risk items exist with mitigations. `BLOCKED` if high-risk items exist with no mitigation.
305
+
306
+ ### Implementability Overall Verdict
307
+
308
+ - `BLOCKED` if any dimension is `BLOCKED`
309
+ - `NEEDS REFINEMENT` if no `BLOCKED` but any dimension is `NEEDS REFINEMENT`
310
+ - `READY` if all 7 are `READY`
311
+
312
+ ---
313
+
314
+ ## Part D: AI Pre-Approval Recommendation
315
+
316
+ Based on all three verdicts:
317
+
318
+ | Closed-Loop | Design Quality | Implementability | Recommendation |
319
+ |-------------|---------------|-----------------|----------------|
320
+ | PASS | PASS | READY | **建议批准** (Recommend approval) |
321
+ | PASS | PASS | NEEDS REFINEMENT | **有条件批准** (Conditional — fix during apply) |
322
+ | PASS WITH WARNINGS | any non-FAIL | READY/NEEDS REFINEMENT | **有条件批准** (Conditional — acknowledge warnings) |
323
+ | any | WARNING | any non-BLOCKED | **有条件批准** (Conditional — design quality concerns) |
324
+ | FAIL | any | any | **退回 refine** (Return to refine) |
325
+ | any | FAIL | any | **退回 refine** (Return to refine — over-engineered or rigid) |
326
+ | any | any | BLOCKED | **退回 refine** (Return to refine — remove blockers) |
327
+
328
+ The recommendation must include a 1-2 sentence rationale citing the specific verdicts that drove it.
329
+
330
+ ---
331
+
332
+ ## Part E: approval.md Document Structure
333
+
334
+ Generate `approval.md` following this exact structure. Adapt narrative language to
335
+ `artifacts.language`; keep protocol markers, IDs, paths, commands, and code in English.
336
+
337
+ **Chapter order (implementer-first, aligned with scenario-job-compile readability)**:
338
+
339
+ 1. 绪论与边界 — proposal + optional explore + AI; absorbs What/Impact; **no 变更摘要 chapter**
340
+ 2. 技术方案评估 — decisions / risks / design quality
341
+ 3. 架构整体设计 — diagrams + **图要点说明** + components (before acceptance)
342
+ 4. 方案详细设计 — 设计要点 + Happy Path + 业务场景(+说明) + data/API/…
343
+ 5. 验收标准 — **after** architecture & detailed design
344
+ 6. 测试策略 → 7. 部署 → 8. 闭环 → 9. 可实施性 → 10. 审批
345
+
346
+ ### ⚠️ 质量红线 (Quality Gates) — 必须严格执行
347
+
348
+ 生成 `approval.md` 全文时下列红线**缺一不可**;违反则详细设计/接口/数据章节视为不合格,确认前必须补全。
349
+
350
+ | # | 红线 | 要求 |
351
+ |---|------|------|
352
+ | G1 | 一图胜千言 | 任何超过 **5 行**的文字流程描述,**必须**改为 Mermaid 代码块(`sequenceDiagram` / `flowchart` / `stateDiagram-v2`),禁止长段落散文流程 |
353
+ | G2 | 必须有「失败」示例 | §4.5 每个「新增/修改/行为扩展」接口:除成功请求/响应示例外,**必须**另附 ≥1 组**报错**请求或响应示例(如参数校验失败、租约过期、未认证);仅有错误码表、无 HTTP/正文示例 → 不合格 |
354
+ | G3 | 必须有「数据迁移方案」 | 凡涉及 **JSON 字段形状变更**或**新增列**:必须写明**存量数据的默认值填充策略**(回填脚本 / 读时默认 / 禁止空读等);零 DDL 但改 JSON 语义同样适用 |
355
+ | G4 | 必须有「回滚兼容」说明 | 若发布失败回滚:新代码已写入的数据,旧版代码是否能**安全跳过/忽略**?必须给出明确方案(如 `omitempty`、忽略未知字段、`schema_version` 分派、双写兼容窗口);禁止只写「回滚镜像」而无数据兼容结论 |
356
+
357
+ ### Style & Tone (文风要求) — 全文适用
358
+
359
+ 1. **通俗易懂**:面向要动手的开发同学;避免生僻英文缩写,**首次出现必须注解**(例:`DDL`(数据定义语言)、`RPC`(远程过程调用));协议字段名/路径/代码标识符保持原文。
360
+ 2. **逻辑严密**:拒绝模棱两可词 —— **禁止**使用「尽量」「大概」「一般情况下」「可能需要」「酌情」「视情况」等;应使用「**必须**」「**禁止**」「**采用 XX 方案**」「固定为…」。若确有分支,写成显式条件表(若 A → 做 X;若 B → 做 Y),不得用含糊副词搪塞。
361
+
362
+ ```markdown
363
+ # 技术方案审批文档: <change-name>
364
+
365
+ > 本文档由 `/specflow:approval` 基于 refine 收敛后的四件套 + 现有代码与 spec 基线生成,
366
+ > 经 AI 7 维闭环检查、架构整体设计、方案详细设计、测试策略、部署/发布/回滚、设计质量评估与可实施性评估,供人工审批使用。
367
+ > 生成时间: YYYY-MM-DD HH:MM | phase: refined | 产物语言: <lang> | 技术栈: <stack>
368
+
369
+ ---
370
+
371
+ ## 1. 绪论与边界 (Introduction & Boundaries)
372
+
373
+ > 本章以**业务叙事**说明"为什么做、做什么、影响面、做完后如何闭环、坚决不做什么"。
374
+ > **数据来源**:`proposal.md`(必选)+ `explore.md`(若存在且可用则吸收)+ **AI 提炼**。
375
+ > **不再单列「变更摘要」章**:原 Why / What Changes / Impact 并入本章 1.1–1.2。
376
+
377
+ ### 1.1 背景与痛点 (Background & Pain Points)
378
+
379
+ 用一段话说明当前现状,并用 **Mermaid 现状流程图** 直观呈现,痛点节点**用红色标注**。
380
+
381
+ **要求**:
382
+
383
+ 1. 描述当前业务/系统的实际流程(用户如何完成目标、经过了哪些步骤)
384
+ 2. 用 Mermaid `flowchart` 绘制现状流程
385
+ 3. **痛点节点用红色标注**:`classDef pain fill:#ffcccc,stroke:#cc0000,color:#000` + `:::pain` 或 `class X pain`
386
+ 4. 每个痛点一句话说明**它造成的代价**(返工/延迟/错误/成本)
387
+ 5. 痛点应可追溯到 proposal.md 的 `## Why`;若有 `explore.md`,吸收其中已确认的痛点/约束洞察(勿编造)
388
+
389
+ **痛点清单**(对应图中红色节点):
390
+
391
+ | 痛点 | 代价 |
392
+ |------|------|
393
+ | <痛点> | <代价> |
394
+
395
+ ### 1.2 做什么与影响面 (What & Impact)
396
+
397
+ AI 从 proposal `## What Changes` / `## Impact`(及 explore 相关结论)提炼,替代原「变更摘要」章。
398
+
399
+ **做什么**(按 新增/修改/移除/重命名;BREAKING 显式标注):
400
+
401
+ | 类别 | 内容 | BREAKING? |
402
+ |------|------|-----------|
403
+ | 新增 | | |
404
+ | 修改 | | |
405
+ | 移除 / 重命名 | | |
406
+
407
+ **影响面**:
408
+
409
+ | 影响区域 | 影响等级 | 说明 |
410
+ |---------|---------|------|
411
+ | | 高/中/低 | |
412
+
413
+ ### 1.3 业务闭环与目标 (Business Loop & Goals)
414
+
415
+ 说明"本次变更完成后,业务如何形成闭环",并给出 **用户操作路径(User Journey)**。
416
+
417
+ **要求**:
418
+
419
+ 1. 描述完成本次变更后,用户完成目标的完整路径
420
+ 2. 用 Mermaid `sequenceDiagram` 或 `flowchart` 绘制 User Journey
421
+ 3. 标注每一步的价值/产出
422
+ 4. Goals 应可验证,引用 **§5 验收标准**
423
+
424
+ **业务目标**(可验证):
425
+
426
+ | 目标 | 可验证方式(引用 §5) |
427
+ |------|---------------------|
428
+ | <目标> | §5 <Scenario 名> |
429
+
430
+ ### 1.4 非目标 (Non-Goals)
431
+
432
+ **必须明确列出本次迭代坚决不做的事项,并说明不做理由**(防止需求蔓延)。
433
+
434
+ 1. 从 proposal.md / design.md / explore.md 的 Non-Goals 提炼,必须补充"不做理由"
435
+ 2. 若确实没有,写明 `proposal/design 未声明 Non-Goals,建议在 refine 补充边界`
436
+
437
+ | 非目标 | 不做理由 |
438
+ |--------|---------|
439
+ | <非目标> | <理由> |
440
+
441
+ ---
442
+
443
+ ## 2. 技术方案评估 (Technical Design Review)
444
+
445
+ ### 2.1 现状与约束 (Context & Constraints)
446
+ [整合 design.md Context + AI 补充的隐含约束]
447
+
448
+ ### 2.2 目标与非目标 (Goals & Non-Goals)
449
+ [整合 design.md Goals/Non-Goals]
450
+
451
+ ### 2.3 决策评审表 (Decision Review)
452
+
453
+ | 决策 | 选定方案 | 备选方案 | 理由 | 影响评估 | 状态 |
454
+ |------|---------|---------|------|---------|------|
455
+ | D1: <name> | <方案> | <A/B> | <理由> | <评估> | Proposed |
456
+
457
+ ### 2.4 风险与权衡 (Risks & Trade-offs)
458
+
459
+ | 风险 | 严重等级 | 缓解措施 | 就绪度 |
460
+ |------|---------|---------|--------|
461
+ | <name> | 高/中/低 | <措施> | ✅/⚠️/❌ |
462
+
463
+ ### 2.5 设计质量评估 (Design Quality)
464
+
465
+ #### 过度设计检查
466
+ | # | 信号 | 检测到? | 证据(design/tasks 位置) |
467
+ |---|------|--------|----------------------|
468
+ | 1 | 为未提出的需求设计接口 | ✅是/❌否 | |
469
+ | 2 | 不必要的抽象层 | | |
470
+ | 3 | 预建未使用的基础设施 | | |
471
+ | 4 | 配置项超出当前需求 | | |
472
+ | 5 | 复杂度超出问题规模 | | |
473
+ **过度设计结论:** PASS (0 signals) / WARNING (1-2) / FAIL (3+)
474
+
475
+ #### 扩展性评估
476
+ | # | 信号 | 检测到? | 证据(design 位置) |
477
+ |---|------|--------|----------------|
478
+ | 1 | 命名空间预留 | | |
479
+ | 2 | 接口稳定,实现可替换 | | |
480
+ | 3 | 显式 Non-Goals | | |
481
+ | 4 | 向后兼容路径 | | |
482
+ | 5 | 决策理由提及扩展性权衡 | | |
483
+ **扩展性结论:** PASS (4-5) / WARNING (0-3)
484
+
485
+ **设计质量总评:** PASS / WARNING / FAIL
486
+
487
+ ---
488
+
489
+
490
+ ## 3. 架构整体设计 (Architecture Design)
491
+
492
+ > 本章回答"系统由哪些模块组成、模块间如何依赖与交互、每个模块的职责与边界是什么"。
493
+ > 聚焦**宏观结构**;与 §4 方案详细设计(模块内部实现 / 时序)互补。
494
+ > 质量标杆:`scenario-job-compile` §3 —— **图 + 图要点说明 + 核心组件表**。
495
+
496
+ ### 3.1 总体架构 (Architecture Overview)
497
+
498
+ 用 Mermaid 绘制 **模块依赖/分层图**(推荐),并可附加 **系统交互总览**。
499
+
500
+ **绘制要求**:
501
+
502
+ 1. 标注变更模块(`[新增]` / `[修改]`),影响面一眼可见
503
+ 2. 边标注依赖方向或交互消息
504
+ 3. CLI/库 → `src/core/*`、`src/cli/*`;Web → 服务/组件;多仓 → 仓库/服务
505
+ 4. 图与 **§2 决策**一致
506
+
507
+ **设计说明 / 图要点**(强制,紧跟每张架构图之后):
508
+
509
+ 用编号列表解释图中**读图关键点**(不是复述节点名),对齐标杆「设计说明(总体架构)」:
510
+
511
+ 1. 分层/边界怎么划、谁不直连谁
512
+ 2. 本迭代不变式(如零 DDL、双通道、一场景一作业)
513
+ 3. 复用 vs 新增的落点
514
+ 4. 与 §2 决策的对应关系
515
+
516
+ 若有第二张交互图,另写 **交互要点**(一段或短列表):谁感知、谁禁止直连 DB/绕过网关等。
517
+
518
+ ### 3.2 核心组件说明 (Core Components)
519
+
520
+ | 组件 | 职责 | 边界(做什么 / 不做什么) | 依赖 | 变更类型 |
521
+ |------|------|-------------------------|------|---------|
522
+ | `<组件名>` | 一句话职责 | 做什么;不做什么 | 依赖的组件 | 新增/修改/不变 |
523
+
524
+ **填写要求**:列出新增+修改组件;边界写「不做什么」;与 §3.1 图一一对应;边界可追溯到 §2 决策。
525
+
526
+ 可附 **组件边界总原则**(短列表:平台/Worker/控制台各做什么、禁止什么)。
527
+
528
+ **不涉及架构变更时写**:`不涉及架构变更(单模块/单文件调整,模块边界无变化)`。
529
+
530
+ ### 3.3 架构一致性自检(生成后检查)
531
+
532
+ - [ ] §3.1 图标注了新增/修改模块
533
+ - [ ] **每张架构图后有「设计说明 / 图要点」**(非空编号列表)
534
+ - [ ] §3.2 每个组件有「不做什么」边界
535
+ - [ ] 图与表一一对应
536
+ - [ ] 组件边界可追溯到 §2 决策
537
+ - [ ] 未涉及时显式标注「不涉及架构变更」
538
+
539
+ ---
540
+
541
+ ## 4. 方案详细设计 (Detailed Design)
542
+
543
+ > 将方案从宏观决策落到实现者可照写的细节。
544
+ > **只呈现本变更涉及的部分**;不涉及显式写「不涉及 X」。
545
+ > 每个元素可追溯到 **§5 验收标准**与 **§2 决策**。
546
+ > 质量标杆:`scenario-job-compile` §4 —— **设计要点一览 → 业务时序(含设计要点说明) → 表/接口**。
547
+
548
+ ### 4.1 设计要点一览(强制)
549
+
550
+ 从 design 决策提炼实现**不可随便推翻**的要点(P1…Pn):
551
+
552
+ | 编号 | 要点 | 说明 |
553
+ |------|------|------|
554
+ | P1 | <短名> | <一句话不变量/策略> |
555
+
556
+ ### 4.2 核心业务时序 · Happy Path(强制)
557
+
558
+ **必须**给出主成功路径的**完整** Mermaid `sequenceDiagram`(建议 `autonumber`),覆盖主角色从发起到成功终态的端到端调用;不得用一句话替代。
559
+
560
+ **结构**:
561
+
562
+ 1. **目的**:一句话
563
+ 2. **时序图**:Happy Path 全链路
564
+ 3. **设计要点**:图后强制说明(不变式、与 P1…Pn 对应、本图不展开的失败边界)
565
+
566
+ ```mermaid
567
+ sequenceDiagram
568
+ autonumber
569
+ %% Happy Path — 成功路径完整时序
570
+ ```
571
+
572
+ **设计要点**:
573
+
574
+ - …
575
+
576
+ ### 4.3 业务场景时序(强制有说明)
577
+
578
+ 对每个关键业务场景输出同构小节(对齐标杆「业务流程 A/B/C…」):
579
+
580
+ #### 场景 X · `<名称>`
581
+
582
+ 1. **目的**
583
+ 2. **时序/状态/流程开**(Mermaid `sequenceDiagram` / `flowchart` / `stateDiagram-v2`)
584
+ 3. **设计要点**(强制 — 禁止有图无说明;可用列表或小表)
585
+
586
+ 至少覆盖本变更的核心分支(如失败策略、幂等、兼容缺省、计划 vs 调试等)。纯单步无分支时可写:`不涉及多业务场景(主路径已由 §4.2 Happy Path 覆盖)`——但仍须保留 §4.2。
587
+
588
+ ### 4.4 数据结构 / 数据模型变更 (Data Structures)
589
+
590
+ **适用范围**:涉及持久化、状态存储、数据模型的变更。纯 CLI/库项目若无数据库,覆盖配置结构 / 状态文件 / 缓存结构 / YAML schema 等"数据模型"(走下方「非库表路径」)。
591
+
592
+ > **DB 技能路由(先于起草)**:执行 `prompts/approval/database-guidance.md`。
593
+ > - **命中** `mysql` / `postgresql` / `oracle`(及确需时的 redis/es):`Read`
594
+ > `skills/database/<stack>/SKILL.md` 与路由表中的 DDL/索引/JSON 参考,用其惯例补强类型、引擎、字符集、索引与 Gotchas。
595
+ > - **未命中**(`dbStack=none`):不硬套某厂商 skill,**交给大模型**按下方 SpecFlow 硬门槛生成。
596
+ > - 技能是 **Read 知识包**,不是 MCP tool;不得用「调 tool」替代读文件。
597
+ > - 在总则「DDL 来源」旁注明:`skills/database/<stack>`(本地) 或 `LLM-fallback`。
598
+
599
+ > **质量硬门槛(库表路径)**:只要本变更读写/依赖任何数据库表(含"零 DDL、只改读写语义"),§4.4 **必须**按下列结构输出,不得用一句话带过、不得省略 ER / DDL / 字段说明表。参考质量标杆:`scenario-job-compile` 类审批文档的「表与数据设计」章(总则结论表 → ER → 表一览 → 逐表 DDL+字段表 → 非表字段与回滚)。
600
+
601
+ #### A. 库表路径(MySQL / PostgreSQL / SQLite 等关系库)——强制结构
602
+
603
+ 按以下小节**顺序**生成。缺任一强制项 → 视为详细设计质量不合格,在确认摘要中报告用户并标记 `[待 refine 澄清]` 或补全后再写入。
604
+
605
+ ##### 4.4.1 总则与本迭代结构变更结论
606
+
607
+ 用结论表一眼说清本迭代对库结构做什么(即使结论是「零迁移」也要写明):
608
+
609
+ | 项 | 结论 |
610
+ |----|------|
611
+ | 数据库迁移(脚本/工具名) | 有 / **本迭代零迁移** |
612
+ | 新建表 | 表名列表 / **无** |
613
+ | 新增 / 修改 / 删除列 | 列清单 / **无** |
614
+ | 新增索引 | 索引清单 / **无** |
615
+ | DDL 来源 | 仓库基线路径 或 本迭代新增 |
616
+ | DB 技能 | `skills/database/<stack>`(本地) / `LLM-fallback` |
617
+
618
+ 紧接一段 **本迭代变更语句** 代码块:
619
+
620
+ - 有变更:给出可执行的 `CREATE` / `ALTER` / `DROP`(与下方逐表 DDL 一致)。
621
+ - **零变更**:显式写「无(明确不执行)」,并可用注释列出**禁止合入**的反例 `ALTER`/`CREATE`(防止实现时偷偷加列)。
622
+
623
+ ##### 4.4.2 ER 图(核心实体关系)——强制
624
+
625
+ 用 Mermaid `erDiagram` 画出**本变更涉及的核心实体**(新增 + 修改 + 本迭代强依赖的既有表),标注:
626
+
627
+ 1. 实体名(= 表名)与**中文表意**(可用实体注释或紧随其后的说明)。
628
+ 2. 关系基数(`||--o{` / `}o--||` 等)与关联键语义(如「作业 1 — N 逐步结果」)。
629
+ 3. 每个实体列出 **3–8 个关键属性**(主键、业务主键、外键、本迭代读写的关键列);勿堆砌全量字段(全量在字段说明表)。
630
+ 4. 与 §2 决策、§3 组件一致:图中实体必须在表一览与逐表章节出现。
631
+
632
+ ```mermaid
633
+ erDiagram
634
+ PARENT_TABLE ||--o{ CHILD_TABLE : "1:N 业务关系说明"
635
+ PARENT_TABLE {
636
+ char uid PK "业务主键"
637
+ varchar name "名称"
638
+ }
639
+ CHILD_TABLE {
640
+ char uid PK
641
+ char parent_uid FK
642
+ int step_order "本迭代幂等键之一"
643
+ }
644
+ ```
645
+
646
+ **图说明(强制,紧跟 ER 图)**:用表格描述图中每张表,提升可读性 —— 不是重复 ER 属性列表,而是回答「这张表是干什么的、本迭代怎么动」:
647
+
648
+ | 表名 | 中文名 | 职责(一句话) | 结构 | 本迭代动作 |
649
+ |------|--------|--------------|------|------------|
650
+ | `parent_table` | … | … | 不变 / 新增 / 改列 | 只读 / 写入 / 新建 |
651
+
652
+ ##### 4.4.3 逐表详设(强制骨架)
653
+
654
+ 对表一览中的**每一张表**输出同构小节 `#### \`table_name\`(中文名)`,顺序固定:
655
+
656
+ 1. **本迭代动作**:只读 / 写入(既有路径) / 新建 / 改结构(列清单) —— 一句话 + 关键不变量(如幂等键)。
657
+ 2. **本迭代变更语句**:`无` 或完整 `ALTER`/`CREATE` 片段(可执行)。
658
+ 3. **DDL(完整建表语句)** —— **硬门槛**:
659
+ - 必须是完整 `CREATE TABLE ...`(即使本迭代零 DDL,也给出**现网/目标**完整表定义,便于实现者对照)。
660
+ - **必须含存储引擎与字符集**(MySQL 示例:`ENGINE=InnoDB DEFAULT CHARSET=utf8mb4` [`COLLATE=...` 若项目有约定则写出];PostgreSQL 写明 schema / 关键扩展约定;SQLite 可省略 ENGINE,但须完整列定义与约束)。
661
+ - 含 PRIMARY KEY、UNIQUE、KEY/INDEX、必要时列 `COMMENT` / 表级 `COMMENT`。
662
+ - 首行注释标明 DDL 来源(迁移文件路径或「本迭代新增」)。
663
+ 4. **字段说明表** —— 强制列:
664
+
665
+ | 字段名称 | 字段类型 | 是否有默认值 | 字段说明 | 本迭代用法 |
666
+ |----------|----------|--------------|----------|------------|
667
+
668
+ - 「本迭代用法」写清:读 / 写 / 不涉及 / **固定赋值**(`job_type=scenario`)等;本迭代相关列可加粗语义说明。
669
+ - 索引在 DDL 中已声明即可;若新增索引,在变更语句与字段表或表下短注中说明**支撑的查询**。
670
+ 5. 若表含 JSON / 大字段契约:另开子节给出**非表列的 JSON 形状**(字段/类型/必填/说明),与参考文档 `runtime_payload` 写法一致。
671
+
672
+ ##### 4.4.4 非表字段、数据迁移与回滚兼容
673
+
674
+ | 项 | 说明 |
675
+ |----|------|
676
+ | 协议/计算字段(不落库) | 如列表聚合计数;说明计算方式 |
677
+ | **存量数据默认值填充策略**(G3) | JSON 形状变更或新增列时**必须**填写:回填 SQL/脚本、读路径默认值、是否允许空、上线顺序(先兼容读再写新形状等) |
678
+ | 结构回滚 | 有 DDL → 回滚脚本要点;无 DDL →「无结构可回滚,回滚应用即可」 |
679
+ | **回滚数据兼容**(G4) | 新版本已写入行/JSON,旧版本代码能否安全忽略未知字段或旧 `schema_version`?写明机制(`omitempty` / 忽略未知键 / version 分派等) |
680
+ | 数据保留 | 已写入行是否保留、是否需清洗 |
681
+
682
+ **零结构变更且不改 JSON 语义时**:在上表写明「无存量填充;无新形状回滚兼容问题」,不得整节留空。
683
+
684
+ #### B. 库表路径 —— 质量自检(生成后必过)
685
+
686
+ - [ ] 有总则结论表 + 本迭代变更语句(零变更也显式写「无」)
687
+ - [ ] 有 Mermaid `erDiagram`,且图后有「表名/中文名/职责/结构/本迭代动作」说明表
688
+ - [ ] 每张涉及表均有:动作、变更语句、**完整 CREATE TABLE(含引擎与字符集)**、字段说明表
689
+ - [ ] 字段说明表含「本迭代用法」列;幂等键 / 外键 / 枚举合法值写清
690
+ - [ ] **G3**:JSON 变更或新增列时有存量默认值填充策略;否则显式写「无存量填充」
691
+ - [ ] **G4**:回滚数据兼容有明确方案或显式「无新旧互读问题」
692
+ - [ ] 无「仅文字描述表结构、无 DDL」或「DDL 缺 ENGINE/CHARSET」的偷懒写法
693
+ - [ ] 零 DDL 迭代禁止假装「不涉及数据库」—— 只要读写表,仍走库表路径并展示现网 DDL
694
+
695
+ #### C. 非库表路径(CLI / 库 / 配置 / 状态文件)
696
+
697
+ 无关系库表时,覆盖配置结构 / 状态文件 / YAML schema / 缓存键:
698
+
699
+ | 元素 | 内容 |
700
+ |------|------|
701
+ | 配置或状态结构 | 键路径、类型、默认值、生效时机 |
702
+ | 约束 | 合法值、校验失败行为 |
703
+ | 迁移 | 缺省兼容、是否改写存量文件 |
704
+
705
+ 示例:
706
+ ```yaml
707
+ # specflow/config.yaml 新增
708
+ artifacts:
709
+ language: zh-CN # en | zh-CN,缺省 en
710
+ ```
711
+
712
+ **完全不涉及任何持久化/配置结构时写**:`不涉及数据库变更(纯逻辑/CLI 变更,无持久化数据模型)`。
713
+
714
+ #### D. 库表 DDL 示例(完整度标杆)
715
+
716
+ ```sql
717
+ -- 来源:migrations/example/ddl/orders.sql(或:本迭代新增)
718
+ CREATE TABLE `orders` (
719
+ `id` BIGINT NOT NULL AUTO_INCREMENT COMMENT '内部自增主键',
720
+ `uid` CHAR(36) NOT NULL COMMENT '业务主键',
721
+ `project_id` VARCHAR(64) NOT NULL,
722
+ `status` VARCHAR(32) NOT NULL DEFAULT 'pending',
723
+ `created_at` DATETIME(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3),
724
+ `updated_at` DATETIME(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3) ON UPDATE CURRENT_TIMESTAMP(3),
725
+ PRIMARY KEY (`id`),
726
+ UNIQUE KEY `uk_uid` (`uid`),
727
+ KEY `idx_project_status` (`project_id`, `status`)
728
+ ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci
729
+ COMMENT='订单';
730
+ ```
731
+
732
+ ### 4.5 接口设计 (Interface Design)
733
+
734
+ **适用范围**:暴露 API / RPC / CLI 命令 / 跨模块函数接口的变更(含「协议不变但本迭代新消费」)。
735
+ **项目类型适配**:Web/服务 → HTTP(+RPC);CLI → commander 等命令参数;库 → 导出函数签名。
736
+
737
+ > **质量硬门槛(对外/跨端接口路径)**:只要本变更新增、修改、行为扩展或**新消费**对外接口,§4.5 **必须**按下列结构输出。参考质量标杆:`scenario-job-compile`「接口设计」章(总览与约定 → 接口清单 → 通用错误码 → 逐接口字段表+HTTP 示例 → 调用关系)。禁止只有路径名、无字段表、无错误约定、无请求/响应示例。
738
+
739
+ #### A. 对外/跨端接口路径——强制结构
740
+
741
+ ##### 4.5.1 总览与约定
742
+
743
+ **1) 调用方与通道**(多通道时必填;单通道也建议写明鉴权):
744
+
745
+ | 通道 | 路径前缀 / 入口 | 调用方 | 鉴权 |
746
+ |------|-----------------|--------|------|
747
+ | 例:控制台 API | `/api/v1/...` | 前端经网关 | 用户/项目身份 |
748
+ | 例:内部 API | `/internal/v1/...` | Worker/服务 | 租约/服务身份 |
749
+
750
+ **2) 本迭代接口清单**(强制总表,编号稳定便于交叉引用):
751
+
752
+ | 编号 | 接口 | 变更类型 | 应用场景 |
753
+ |------|------|----------|----------|
754
+ | I1 | <短名> | **新增** / **修改** / **行为扩展**(请求体不变) / **不变**(本迭代消费) | 谁在什么时候用 |
755
+
756
+ 变更类型约定(优化自标杆文档,强制统一用语):
757
+
758
+ | 类型 | 含义 | §4.5 展开深度 |
759
+ |------|------|---------------|
760
+ | 新增 | 新路径或新 RPC | 完整展开(字段+示例+错误) |
761
+ | 修改 | 请求/响应形状变化(加字段、改语义) | 完整展开,并标明**本迭代变更点** |
762
+ | 行为扩展 | 消息形状不变,服务端认新取值/新分支 | 完整展开侧重点:行为差异与错误;可注明「请求/响应消息不变」 |
763
+ | 不变(本迭代消费) | 协议不动,本迭代开始依赖 | 可精简:场景+协议+关键字段/查询约定+为何本迭代需要;仍建议有成功响应要点 |
764
+ | 不变(不展开) | 已落地且本迭代不改、不新消费 | **清单可一句带过或不列入**,勿重复粘贴既有文档 |
765
+
766
+ **3) 通用错误码约定**(强制;按项目现网风格映射):
767
+
768
+ | 错误类别 / 状态 | 典型 HTTP 或退出码 | 含义(本迭代) |
769
+ |-----------------|-------------------|--------------|
770
+ | 参数非法 | 400 / 退出码 1 | … |
771
+ | 未找到 | 404 | … |
772
+ | 无权限 / 未认证 | 403 / 401 | … |
773
+ | 冲突 / 前置失败 | 409 / 412 | … |
774
+ | 内部错误 | 500 | … |
775
+
776
+ **约定**(按项目裁剪,至少覆盖命名与错误风格):
777
+
778
+ 1. **字段命名**:与现网一致(如 JSON 蛇形 `project_id`;proto `json_name`;CLI kebab-case 等)。
779
+ 2. **错误风格**:业务错误进 `message` / 状态详情;**禁止**「HTTP 200 + 业务错误码」混用(除非项目现网已是该风格且 design 显式沿用)。
780
+ 3. **幂等 / 终态语义**:若存在上报类接口,写清「成功 ≠ 资源终态」等不变量(对齐 §2 决策)。
781
+ 4. **兼容缺省**:可选字段缺省时的兼容行为写进字段表「默认」列。
782
+ 5. **与流程对齐**:接口编号可被 §4.2/§4.3 时序与 §6 测试引用。
783
+
784
+ ##### 4.5.2 逐接口详设(强制骨架)
785
+
786
+ 对清单中每个需展开的编号 `In`,输出同构小节 `#### In · <短名>(<变更类型>)`:
787
+
788
+ 1. **元信息表**(强制):
789
+
790
+ | 项 | 内容 |
791
+ |----|------|
792
+ | 应用场景 | 谁、在什么用户动作/系统时机下调用 |
793
+ | 协议 | 方法 + 路径(或 CLI 命令 / 导出函数签名) |
794
+ | Content-Type / 编码 | 如 `application/json`(若适用) |
795
+ | 对应 RPC / 内部名 | 若有(可写暂定名 +「实现时与 OpenAPI/proto 对齐」) |
796
+ | 鉴权 | 本接口鉴权要点(可引用通道表) |
797
+ | 本迭代变更 | 一句话(新增字段 / 行为扩展 / 不变仅消费 …) |
798
+
799
+ 2. **参数表**(有则分节:路径参数 / Query / 请求体 / CLI flags):
800
+
801
+ | 字段 | 类型 | 必填 | 默认 | 说明 |
802
+ |------|------|------|------|------|
803
+
804
+ - 合法值枚举、别名归一、与表字段差异(如「API 有 `step_uid`,表无此列」)写在「说明」。
805
+ - 互斥参数(二选一)在说明或表下用引用块写清。
806
+
807
+ 3. **请求示例**(强制至少 1 个主路径成功请求):
808
+ - Web:` ```http ` 完整请求行 + 头 + JSON 正文
809
+ - CLI:` ```text ` 或 shell 调用示例
810
+ - 库:调用伪代码 / TypeScript 签名调用示例
811
+
812
+ 4. **成功响应字段表** + **成功响应示例**(强制)
813
+
814
+ 5. **失败示例**(质量红线 G2 — 强制):每个「新增/修改/行为扩展」接口**必须**另附 ≥1 组报错示例(完整 HTTP 或等价),覆盖典型失败之一:参数校验失败、鉴权/租约失败、资源不存在、前置条件不满足等。示例正文须与错误表一致。
815
+
816
+ 6. **错误表**(强制;条件 → 状态/退出码 → 说明):
817
+
818
+ | 条件 | 状态 / 退出码 | 说明 |
819
+ |------|---------------|------|
820
+
821
+ 7. **处理顺序 / 合同**(可选但推荐):多步服务端合同用编号列表;与 §4.2/§4.3 流程、§4.4 落库对齐。
822
+
823
+ ##### 4.5.3 调用关系(推荐)
824
+
825
+ 用短文本或 Mermaid 概括调用方如何串起 `I1…In`(主路径一条线即可),便于实现与联调对照。
826
+
827
+ ```text
828
+ 调用方A: I3 → I1 → I4 → I7
829
+ 调用方B: … → I5 → I6
830
+ ```
831
+
832
+ #### B. 接口路径 —— 质量自检(生成后必过)
833
+
834
+ - [ ] 有通道/鉴权表(或多通道说明)+ 本迭代接口清单(编号+变更类型+场景)
835
+ - [ ] 有通用错误码约定 + 命名/错误风格约定
836
+ - [ ] 每个「新增/修改/行为扩展」接口具备:元信息、字段表、成功请求/响应示例、**失败示例(G2)**、错误表
837
+ - [ ] 「不变·本迭代消费」接口至少有场景+协议+关键消费约定,不假装不存在
838
+ - [ ] 无「只有路径、无字段/无示例/无错误」的偷懒写法;示例与字段表一致
839
+ - [ ] 接口编号可被 §4.2/§4.3 流程、§6 测试引用
840
+
841
+ #### C. CLI / 库项目路径(无 HTTP 时)
842
+
843
+ 无 HTTP 时仍用「清单 + 逐接口」骨架,将「协议」换为命令/导出签名;错误码换为退出码或抛错类型。示例:
844
+
845
+ ```text
846
+ specflow init --artifact-language <language>
847
+ 入参: language?: string 可选,默认 'en';合法值 en | zh-CN | zh(zh 别名→zh-CN)
848
+ 出参: { status: 'initialized' | 'already_initialized' | 'updated_assets', message: string }
849
+ 错误码:
850
+ E_INVALID_LANGUAGE 退出码 1 — 不支持的 language 值
851
+ E_PARITY_STRICT 退出码 1 — 资产生成后 parity 校验失败
852
+ ```
853
+
854
+ **完全不涉及接口变更时写**:`不涉及接口变更(内部实现调整,无对外/跨模块接口变化)`。
855
+
856
+ ### 4.6 核心算法 / 逻辑说明 (Core Logic)
857
+
858
+ **适用范围**:有非平凡算法或数据处理逻辑的变更。
859
+ | 元素 | 内容 |
860
+ |------|------|
861
+ | 输入输出 | 输入数据结构、输出数据结构 |
862
+ | 处理步骤 | 逐步逻辑(编号列表) |
863
+ | 复杂度 | 时间/空间复杂度,边界条件 |
864
+
865
+ **不涉及非平凡算法时写**:`不涉及非平凡算法(逻辑简单,无复杂数据处理)`。
866
+
867
+ ### 4.7 配置与运行环境 (Configuration & Runtime)
868
+
869
+ **适用范围**:新增配置项、环境变量、运行时依赖的变更。
870
+ | 元素 | 内容 |
871
+ |------|------|
872
+ | 配置项 | 名称、类型、默认值、生效时机 |
873
+ | 环境变量 | 新增变量、语义 |
874
+ | 运行时依赖 | 新增依赖、版本、用途 |
875
+
876
+ **不涉及配置变更时写**:`不涉及配置或运行环境变更`。
877
+
878
+ ### 4.8 兼容性与迁移 (Compatibility & Migration)
879
+
880
+ **适用范围**:破坏性变更、JSON/列变更、或任何「新版本写入、旧版本仍可能读」的发布窗口。
881
+
882
+ | 元素 | 内容 |
883
+ |------|------|
884
+ | 旧行为 → 新行为 | 映射表(禁止含糊「基本兼容」) |
885
+ | 迁移路径 | 存量用户如何升级、步骤顺序 |
886
+ | **存量默认值填充**(G3) | 与 §4.4.4 一致;JSON/新列必须写明填充策略 |
887
+ | **回滚数据兼容**(G4) | 发布失败回滚后:新代码已写数据,旧代码是否安全忽略/跳过?必须给出方案(`omitempty` / 忽略未知字段 / `schema_version` 等) |
888
+ | 应用回滚 | 镜像/包回退步骤 |
889
+
890
+ **完全无兼容风险时写**:`不涉及破坏性变更(向后兼容);无新形状写入,回滚仅回退应用即可` —— 仍须一句话点明「无新旧数据互读问题」。
891
+
892
+ ### 详细设计质量自检(生成后检查)
893
+
894
+ - [ ] 有 §4.1 设计要点一览(P1…Pn)
895
+ - [ ] 有 §4.2 Happy Path **完整**时序图 + 设计要点说明
896
+ - [ ] 每个 §4.3 业务场景均有图 + **设计要点说明**(无裸图)
897
+ - [ ] **G1**:超过 5 行的文字流程已改为 Mermaid,无长散文流程
898
+ - [ ] 每个详细设计元素可追溯到 §5 Requirement/Scenario 与 §2 决策
899
+ - [ ] 涉及数据/接口的均非留空;不涉及类别显式标注
900
+ - [ ] **§4.4**:ER + DDL + 字段说明;若 JSON/新列变更则有**存量填充策略(G3)**与回滚数据兼容(G4)
901
+ - [ ] **§4.5**:通道/清单/错误码 + 字段/成功示例 + **失败示例(G2)** + 错误表
902
+ - [ ] **§4.8**:回滚兼容结论明确(或显式声明无新旧数据互读问题)
903
+ - [ ] **文风**:无「尽量/大概/一般情况下」等含糊词;生僻缩写首次已注解
904
+ - [ ] 若无法写出实现级细节,标记 `[待 refine 澄清: <元素>]`
905
+
906
+ ---
907
+
908
+ ## 5. 验收标准 (Acceptance Criteria)
909
+
910
+ [按 capability 分组,完整列出所有 Requirement + Scenario,每个 Scenario 3 级可测试性标注]
911
+
912
+ ### 5.1 Capability: <name>
913
+ [Delta 操作类型: ADDED / MODIFIED / REMOVED / RENAMED]
914
+
915
+ #### Requirement: <name>
916
+ <描述>
917
+
918
+ | Scenario | WHEN | THEN | 可测试性 | 说明 |
919
+ |----------|------|------|---------|------|
920
+ | <name> | <条件> | <期望> | ✅ 功能可测试 / ⚠️ 文档可测试 / ❌ 不可测试 | <原因 if ⚠️/❌> |
921
+
922
+ ---
923
+
924
+ ## 6. 测试策略 (Test Strategy)
925
+
926
+ > 本章从"§5 验收标准可不可测"升级为"**用分层测试证明方案正确**"。它回答:
927
+ > 每个验收标准(WHEN/THEN)由哪一层测试覆盖、用什么工具、目标是证明什么。
928
+ > **选择性呈现**:只列出本变更实际需要的测试层级;不涉及的层级显式标注"不涉及"。
929
+
930
+ ### 6.1 分层测试矩阵
931
+
932
+ | 测试层级 | 覆盖对象 | 工具/框架 | 目标(证明什么) | 覆盖的验收标准 |
933
+ |---------|---------|----------|---------------|---------------|
934
+ | 单元测试 | 核心函数/类/模块内部逻辑 | <框架,如 vitest/jest/pytest> | 逻辑正确、边界处理 | 引用 §5 的 Scenario |
935
+ | 集成测试 | 模块间交互、接口契约、外部依赖 | <框架> | 模块协作正确、契约一致 | 引用 §5 的 Scenario |
936
+ | 验收测试 | spec 的 WHEN/THEN 行为 | <E2E/CLI 测试> | 逐 Scenario 验证用户可见行为 | §5 全部核心 Scenario |
937
+ | 回归测试 | 主 specs 基线 + 既有行为 | <框架> | 不破坏已有功能 | 主 specs(§5 基线对照) |
938
+ | 性能测试 | 关键路径/高并发 | <如 k6/jmeter/bench> | NFR 性能目标达成 | NFR 章节 |
939
+ | 安全测试 | 认证/授权/输入边界 | <SAST/渗透> | 无已知漏洞 | NFR 安全目标 |
940
+ | 兼容性测试 | 多平台/多版本/多浏览器 | <如 playwright> | 跨环境一致 | 兼容性 Requirement |
941
+
942
+ **填写要求**:
943
+
944
+ 1. 每个测试层级**映射到 §5 验收标准**(引用具体 Scenario 名)—— 这是"测试策略与验收标准闭环"的关键
945
+ 2. 每个层级标注**工具/框架**(呼应 full-stack-skills 的"阶段→技能映射":测试阶段→test-writer/playwright/pytest)
946
+ 3. **目标要可验证**("证明 P95 < 200ms" 而非 "测性能")
947
+ 4. 新增测试 vs 修改既有测试要区分
948
+
949
+ **示例**:
950
+
951
+ | 测试层级 | 覆盖对象 | 工具/框架 | 目标(证明什么) | 覆盖的验收标准 |
952
+ |---------|---------|----------|---------------|---------------|
953
+ | 单元测试 | `artifact-language.ts` 的 normalize/require/validate | vitest | `zh`→`zh-CN` 别名、非法值拒绝 | "Normalize the Chinese CLI alias" |
954
+ | 集成测试 | `init` 命令 + config 写入 + 资产生成 | vitest + tmpdir | init 后 config.yaml 含 `artifacts.language` | "Initialize a Simplified Chinese project" |
955
+ | 验收测试 | `specflow init --artifact-language zh-CN` 全流程 | CLI 测试 | 端到端产物符合预期 | "Reject an unsupported language" 等 |
956
+ | 回归测试 | 既有 init 行为(无语言参数) | vitest | 缺省仍为 en,不破坏既有 | "Initialize without an explicit language" |
957
+
958
+ ### 6.2 测试环境与数据
959
+
960
+ | 项 | 说明 |
961
+ |----|------|
962
+ | 测试环境 | 单元/集成用本地 tmpdir;验收用隔离环境(如 CI) |
963
+ | 测试数据 | 需要的 fixture/seed 数据、中文/英文样本 |
964
+ | 并行/隔离 | 测试间是否可并行、是否需要隔离(文件锁/独立目录) |
965
+ | 覆盖率目标 | 核心模块目标覆盖率(如 ≥80%) |
966
+
967
+ ### 6.3 测试策略自检
968
+
969
+ - [ ] 每个 §5 验收标准至少被一个测试层级覆盖(闭环)
970
+ - [ ] 每个测试层级有工具、有可验证目标
971
+ - [ ] 既有行为有回归测试保护(对应 Pass 7 基线)
972
+ - [ ] 新增测试与修改既有测试已区分
973
+
974
+ **不涉及测试变更时写**:`不涉及测试变更(纯文档/配置变更,无行为逻辑需要测试)`。
975
+
976
+ ---
977
+
978
+ ## 7. 部署/发布/回滚方案 (Deployment & Release)
979
+
980
+ > 本章回答"方案实现后如何上线、如何发布、出问题如何回滚、上线后如何监控"。
981
+ > **选择性呈现**:对有运行系统的项目必须;对纯库/CLI/文档项目可显式标注"不涉及运行时部署"。
982
+
983
+ ### 7.1 部署方案 (Deployment)
984
+
985
+ | 项 | 方案 |
986
+ |----|------|
987
+ | 部署目标 | 部署到哪里(生产/预发/多环境)、依赖的基础设施 |
988
+ | 部署方式 | 镜像/包发布/代码部署/配置下发;CI 流水线步骤 |
989
+ | 部署顺序 | 依赖部署的先后(如先迁移 DB 再部署应用) |
990
+ | 配置管理 | 新配置项如何在各环境生效、密钥管理 |
991
+ | 环境差异 | dev/staging/prod 的环境差异与处理 |
992
+
993
+ ### 7.2 发布策略 (Release Strategy)
994
+
995
+ | 项 | 方案 |
996
+ |----|------|
997
+ | 发布方式 | 蓝绿/金丝雀/滚动/直接替换;理由 |
998
+ | 发布窗口 | 是否需停机窗口、灰度比例 |
999
+ | 兼容性 | 新旧版本共存期间的兼容(如 API 版本化、DB 兼容) |
1000
+
1001
+ ### 7.3 回滚方案 (Rollback)
1002
+
1003
+ | 项 | 方案 |
1004
+ |----|------|
1005
+ | 回滚触发条件 | 什么情况下回滚(错误率/指标阈值) |
1006
+ | 回滚方式 | 镜像回退/代码回退/数据回滚;自动或手动 |
1007
+ | 回滚的数据一致性 | 数据迁移的回滚(若有)、缓存/队列的清理 |
1008
+ | 回滚验证 | 回滚后如何确认恢复正常 |
1009
+
1010
+ ### 7.4 监控与可观测性 (Monitoring & Observability)
1011
+
1012
+ | 项 | 方案 |
1013
+ |----|------|
1014
+ | 关键指标 | 上线后需监控的指标(错误率/延迟/资源) |
1015
+ | 日志/追踪 | 日志规范、链路追踪 |
1016
+ | 告警 | 告警阈值与负责人 |
1017
+
1018
+ ### 7.5 部署方案自检
1019
+
1020
+ - [ ] 部署目标/方式/顺序明确
1021
+ - [ ] 发布策略与兼容性说明
1022
+ - [ ] 回滚触发条件、方式、数据一致性、验证明确
1023
+ - [ ] 上线后监控指标与告警明确
1024
+
1025
+ **不涉及运行时部署时写**:`不涉及运行时部署(纯库/CLI/文档项目,无服务上线,变更通过包发布/版本发布交付)`。
1026
+
1027
+ ---
1028
+
1029
+ ## 8. 闭环性检查 (Closed-Loop Verification)
1030
+
1031
+ > **写法要简练**:内部仍跑完 Pass 1–7,但写入本文只保留下表。
1032
+ > - `PASS` / `SKIPPED`:「关键证据」一句话即可(不必贴大表)。
1033
+ > - `WARNING` / `FAIL`:「关键证据」写清缺口(文件/Requirement/Scenario/任务 ID),最多 2–3 条要点。
1034
+ > - **禁止**为每个 Pass 再开长小节、禁止重复贴总评表。
1035
+
1036
+ | Pass | 检查项 | 结论 | 关键证据(一句话;⚠️/❌ 可列 2–3 条要点) |
1037
+ |------|--------|------|--------------------------------------|
1038
+ | 1 | 需求闭环 proposal↔specs | ✅/⚠️/❌ | |
1039
+ | 2 | 方案闭环 design↔specs | ✅/⚠️/❌ | |
1040
+ | 3 | 规格闭环 场景/可测试性/delta | ✅/⚠️/❌ | |
1041
+ | 4 | 实施闭环 tasks↔specs | ✅/⚠️/❌ | |
1042
+ | 5 | 风险闭环 缓解/BREAKING | ✅/⚠️/❌ | |
1043
+ | 6 | 代码落地性 锚点/结构/栈 | ✅/⚠️/❌/⊘ | |
1044
+ | 7 | 基线对照 主 specs | ✅/⚠️/❌/⊘ | |
1045
+
1046
+ **整体闭环性:** PASS / PASS WITH WARNINGS / FAIL
1047
+
1048
+ 判定:任一 ❌ → FAIL;无 ❌ 但有 ⚠️ → PASS WITH WARNINGS;全 ✅(⊘ 不计)→ PASS。
1049
+
1050
+ ---
1051
+
1052
+ ## 9. 可实施性评估 (Implementability Assessment)
1053
+
1054
+ | 评估维度 | 结论 | 说明 |
1055
+ |---------|------|------|
1056
+ | 完整性 | READY / NEEDS REFINEMENT / BLOCKED | |
1057
+ | 规格对齐 | | |
1058
+ | 任务可执行性 | | |
1059
+ | 技术可行性 | | |
1060
+ | 依赖明确性 | | |
1061
+ | 架构一致性 | | <基于 Pass 6 代码读取> |
1062
+ | 实施风险 | | <核心模块/数据迁移/并发/外部接口> |
1063
+
1064
+ **可实施性总评:** READY / NEEDS REFINEMENT / BLOCKED
1065
+
1066
+ ---
1067
+
1068
+ ## 10. 审批意见 (Approval Decision)
1069
+
1070
+ ### 10.1 AI 预审建议
1071
+
1072
+ **建议:** 建议批准 / 有条件批准 / 退回 refine / 拒绝
1073
+ **理由:** <1-2 句话,引用具体 verdict>
1074
+
1075
+ ### 10.2 人工审批签字栏
1076
+
1077
+ | 角色 | 姓名 | 审批结论 | 日期 | 意见 |
1078
+ |------|------|---------|------|------|
1079
+ | 技术负责人 | | □ 批准 □ 退回 □ 拒绝 | | |
1080
+ | 产品负责人 | | □ 批准 □ 退回 □ 拒绝 | | |
1081
+ | 架构师 | | □ 批准 □ 退回 □ 拒绝 | | |
1082
+
1083
+ > 审批结论填写说明:批准 → 可执行 `/specflow:apply`;退回 → 执行 `/specflow:refine` 修复后重新审批;拒绝 → 废弃本次 change。
1084
+
1085
+ ---
1086
+
1087
+ ## 附录 A: 产物溯源
1088
+
1089
+ | 章节 | 数据来源 | 处理方式 |
1090
+ |------|---------|---------|
1091
+ | 绪论与边界 | proposal.md + explore.md(可选) + design Non-Goals | AI 提炼;痛点图 + What/Impact + User Journey + 非目标;**无变更摘要章** |
1092
+ | 技术方案评估 | design.md | 决策表 + 风险表 + 设计质量 |
1093
+ | 架构整体设计 | design + 锚点代码 + specs | Mermaid 图 + **图要点说明** + 组件边界表;追溯 §2 |
1094
+ | 方案详细设计 | design + specs + 锚点 + 现网 DDL/API | 设计要点 + Happy Path + 业务场景(+说明) + 数据/接口等;追溯 §5+§2 |
1095
+ | 验收标准 | specs/**/*.md | **置于设计之后**;3 级可测试性 |
1096
+ | 测试策略 | §5 验收标准 + 项目测试栈 | 分层矩阵映射验收标准 |
1097
+ | 部署/发布/回滚 | §2 决策 + 运行环境 | 部署/发布/回滚/监控 |
1098
+ | 闭环性检查 | 四件套 + 锚点 + 主 specs | 内部跑 Pass 1–7;**正文只输出一张结论表**(PASS 一句话;⚠️/❌ 要点化) |
1099
+ | 可实施性评估 | tasks + design + specs + 代码 | AI 推理 |
1100
+ | 审批意见 | 三重 verdict | AI 预审 + 人工签字栏 |
1101
+ ```
1102
+
1103
+ ### Generation Rules
1104
+
1105
+ 1. **§1 绪论 must be truthful and precise**: every pain point in the current-flow diagram
1106
+ must be grounded in proposal.md `## Why` / design.md Context / confirmed explore.md
1107
+ (do not invent pains). Absorb What Changes + Impact into §1.2 (no separate 变更摘要
1108
+ chapter). Every User Journey step must trace to a §5 acceptance criterion. Every
1109
+ Non-Goal must state its "不做理由".
1110
+
1111
+ 2. **Acceptance Criteria (§5) is exhaustive and placed after design**: include every
1112
+ Requirement and Scenario from every delta spec. Do not summarize or omit. Do NOT place
1113
+ acceptance before architecture/detailed design.
1114
+
1115
+ 3. **Pass 6 evidence must cite real code**: when Pass 6 is ⚠️/❌, §8「关键证据」must cite
1116
+ actual anchor paths and concrete findings. PASS may be one line
1117
+ (e.g. `锚点 N 个均存在,结构可扩展`). Greenfield → `⊘` with the SKIPPED reason.
1118
+
1119
+ 4. **Pass 7 evidence must cite baseline specs**: when ⚠️/❌, cite capability/requirement
1120
+ names compared. PASS → one line; no baseline → `⊘`.
1121
+
1122
+ 5. **Over-engineering evidence must cite design/tasks location**: "Signal 2 detected in
1123
+ `design.md` § D3, which defines a `ReviewerFactory` for a single reviewer type" — not
1124
+ just "over-engineered".
1125
+
1126
+ 6. **Language policy + Style & Tone**: narrative follows `artifacts.language`; protocol
1127
+ markers, IDs, paths, commands, code stay in original form. Apply Style & Tone hard
1128
+ rule (通俗 + 首次注解缩写 + 禁止含糊词) to all human-readable narrative.
1129
+
1130
+ 7. **No file modification**: this prompt only generates `approval.md`. Do not modify the
1131
+ four artifacts, project code, or main specs.
1132
+
1133
+ 8. **Sign-off table is empty**: human sign-off fields must be blank.
1134
+
1135
+ 9. **§4.4 database section quality (hard rule)**: if the change reads/writes any
1136
+ relational table (including zero-DDL semantic-only changes), §4.4 MUST include:
1137
+ (a) structure-change conclusion table + explicit change SQL (or explicit「无」),
1138
+ (b) Mermaid `erDiagram` of core entities + a table-description legend
1139
+ (表名/中文名/职责/结构/本迭代动作),
1140
+ (c) per-table complete `CREATE TABLE` with storage engine + charset (MySQL:
1141
+ `ENGINE=InnoDB DEFAULT CHARSET=utf8mb4` …), and
1142
+ (d) per-table field description table with「本迭代用法」.
1143
+ Do NOT substitute prose-only schema descriptions. Do NOT omit ENGINE/CHARSET on
1144
+ MySQL DDL. Zero-DDL iterations still show current-baseline DDL — never claim
1145
+ 「不涉及数据库」when tables are in the read/write path.
1146
+
1147
+ 10. **§4.5 interface section quality (hard rule)**: if the change adds, modifies,
1148
+ behavior-extends, or newly consumes external/cross-service interfaces, §4.5 MUST
1149
+ include: (a) caller/channel + auth overview, (b) numbered interface inventory with
1150
+ change type (新增/修改/行为扩展/不变·本迭代消费), (c) common error-code mapping and
1151
+ naming/error-style conventions, (d) per-interface meta table, field tables
1152
+ (name/type/required/default/description), at least one success request example and
1153
+ success response example, **(e) ≥1 failure request/response example (G2)**, and an
1154
+ error-condition table. Do NOT ship path-only stubs without fields/examples/errors.
1155
+ Unchanged APIs that this iteration does not consume need not be fully re-documented.
1156
+
1157
+ 11. **§3 architecture diagram key points (hard rule)**: every architecture Mermaid diagram
1158
+ MUST be followed by a numbered「设计说明 / 图要点」list (boundary/invariants/reuse) —
1159
+ not a mere restatement of node names. Component table alone is not enough.
1160
+
1161
+ 12. **§4 Happy Path + scenario design notes (hard rule)**: §4.1 design-points table, §4.2
1162
+ complete Happy Path `sequenceDiagram`, and each §4.3 business scenario MUST include
1163
+ post-diagram「设计要点」explanations. Bare diagrams without notes are a quality failure.
1164
+
1165
+ 13. **Quality Gates G1–G4 (hard rule)**:
1166
+ - **G1**: any process description longer than 5 prose lines MUST be a Mermaid
1167
+ `sequenceDiagram` / `flowchart` / `stateDiagram-v2` (no long prose flows).
1168
+ - **G2**: every added/modified/behavior-extended interface in §4.5 MUST include ≥1
1169
+ failure request/response example (validation failure, lease expiry, etc.), not only
1170
+ an error-code table.
1171
+ - **G3**: JSON shape changes or new columns MUST document存量数据默认值填充策略 in
1172
+ §4.4.4 / §4.8.
1173
+ - **G4**: MUST state rollback data compatibility — whether old code can safely
1174
+ ignore/skip data written by new code (`omitempty`, unknown-field ignore,
1175
+ `schema_version`, etc.). "Rollback the image" alone is insufficient.
1176
+
1177
+ 14. **Style & Tone (hard rule)**: plain language for implementers; obscure English
1178
+ abbreviations MUST be glossed on first use. Ban weasel words「尽量」「大概」
1179
+ 「一般情况下」「可能需要」「酌情」「视情况」; use「必须」「禁止」「采用 XX 方案」
1180
+ or explicit if/then tables instead.
1181
+
1182
+ 15. **§8 closed-loop must be concise (hard rule)**: write exactly one summary table
1183
+ (Pass | 检查项 | 结论 | 关键证据). Do NOT open seven Pass subsections or a second
1184
+ summary table. PASS/SKIPPED → one short phrase; WARNING/FAIL → ≤3 concrete bullets.
1185
+
1186
+ 16. **§4.4 database skill routing**: before drafting relational DDL, run
1187
+ `prompts/approval/database-guidance.md`. On stack hit, Read local
1188
+ `skills/database/<stack>/…` (in-repo, no remote fetch) and apply idioms; on miss,
1189
+ LLM-only SpecFlow §4.4 rules. Do not invent MCP tools; do not `npx skills add`.
1190
+ Record `skills/database/<stack>` or `LLM-fallback` in the §4.4.1 总则 table.
1191
+