@haaaiawd/anws 1.0.0

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 (43) hide show
  1. package/README.md +96 -0
  2. package/bin/cli.js +76 -0
  3. package/lib/copy.js +38 -0
  4. package/lib/index.js +8 -0
  5. package/lib/init.js +139 -0
  6. package/lib/manifest.js +53 -0
  7. package/lib/output.js +74 -0
  8. package/lib/update.js +85 -0
  9. package/package.json +36 -0
  10. package/templates/.agent/rules/agents.md +90 -0
  11. package/templates/.agent/skills/build-inspector/SKILL.md +83 -0
  12. package/templates/.agent/skills/complexity-guard/SKILL.md +71 -0
  13. package/templates/.agent/skills/complexity-guard/references/anti_patterns.md +21 -0
  14. package/templates/.agent/skills/concept-modeler/SKILL.md +112 -0
  15. package/templates/.agent/skills/concept-modeler/prompts/GLOSSARY_PROMPT.md +40 -0
  16. package/templates/.agent/skills/concept-modeler/references/ENTITY_EXTRACTION_PROMPT.md +299 -0
  17. package/templates/.agent/skills/concept-modeler/scripts/glossary_gen.py +66 -0
  18. package/templates/.agent/skills/git-forensics/SKILL.md +74 -0
  19. package/templates/.agent/skills/git-forensics/references/ANALYSIS_METHODOLOGY.md +193 -0
  20. package/templates/.agent/skills/git-forensics/scripts/git_forensics.py +615 -0
  21. package/templates/.agent/skills/git-forensics/scripts/git_hotspots.py +118 -0
  22. package/templates/.agent/skills/report-template/SKILL.md +88 -0
  23. package/templates/.agent/skills/report-template/references/REPORT_TEMPLATE.md +100 -0
  24. package/templates/.agent/skills/runtime-inspector/SKILL.md +93 -0
  25. package/templates/.agent/skills/spec-writer/SKILL.md +58 -0
  26. package/templates/.agent/skills/spec-writer/references/prd_template.md +174 -0
  27. package/templates/.agent/skills/system-architect/SKILL.md +620 -0
  28. package/templates/.agent/skills/system-architect/references/rfc_template.md +59 -0
  29. package/templates/.agent/skills/system-designer/SKILL.md +439 -0
  30. package/templates/.agent/skills/system-designer/references/system-design-template.md +533 -0
  31. package/templates/.agent/skills/task-planner/SKILL.md +474 -0
  32. package/templates/.agent/skills/task-planner/references/TASK_TEMPLATE.md +133 -0
  33. package/templates/.agent/skills/tech-evaluator/SKILL.md +135 -0
  34. package/templates/.agent/skills/tech-evaluator/references/ADR_TEMPLATE.md +68 -0
  35. package/templates/.agent/workflows/blueprint.md +185 -0
  36. package/templates/.agent/workflows/challenge.md +467 -0
  37. package/templates/.agent/workflows/change.md +294 -0
  38. package/templates/.agent/workflows/craft.md +626 -0
  39. package/templates/.agent/workflows/design-system.md +497 -0
  40. package/templates/.agent/workflows/explore.md +307 -0
  41. package/templates/.agent/workflows/forge.md +354 -0
  42. package/templates/.agent/workflows/genesis.md +265 -0
  43. package/templates/.agent/workflows/scout.md +130 -0
@@ -0,0 +1,118 @@
1
+ import os
2
+ import argparse
3
+ import subprocess
4
+ import json
5
+ import csv
6
+ from datetime import datetime
7
+ try:
8
+ import lizard
9
+ except ImportError:
10
+ print("Error: lizard not installed. Run: pip install lizard")
11
+ exit(1)
12
+
13
+ def get_git_churn(repo_path: str, days: int) -> dict:
14
+ cmd = [
15
+ "git",
16
+ "-C", repo_path,
17
+ "log",
18
+ f"--since={days}.days.ago",
19
+ "--name-only",
20
+ "--format="
21
+ ]
22
+ try:
23
+ result = subprocess.check_output(cmd, encoding='utf-8')
24
+ except subprocess.CalledProcessError as e:
25
+ print(f"Git command failed: {e}")
26
+ return {}
27
+
28
+ churn_map = {}
29
+ for line in result.splitlines():
30
+ if line.strip():
31
+ file_path = line.strip()
32
+ churn_map[file_path] = churn_map.get(file_path, 0) + 1
33
+
34
+ return churn_map
35
+
36
+ def get_complexity(repo_path: str, files: list) -> dict:
37
+ complexity_map = {}
38
+ for file_rel_path in files:
39
+ full_path = os.path.join(repo_path, file_rel_path)
40
+ if not os.path.exists(full_path):
41
+ continue
42
+
43
+ try:
44
+ analysis = lizard.analyze_file(full_path)
45
+ # Use average cyclomatic complexity (CCN) or max CCN
46
+ # Max CCN is often a better indicator of "scary code"
47
+ max_ccn = 0
48
+ for func in analysis.function_list:
49
+ if func.cyclomatic_complexity > max_ccn:
50
+ max_ccn = func.cyclomatic_complexity
51
+
52
+ # File length is also a complexity factor
53
+ nloc = analysis.nloc
54
+
55
+ complexity_map[file_rel_path] = {
56
+ "max_ccn": max_ccn,
57
+ "nloc": nloc,
58
+ "avg_ccn": analysis.average_cyclomatic_complexity
59
+ }
60
+ except Exception as e:
61
+ # lizard might fail on non-code files
62
+ pass
63
+
64
+ return complexity_map
65
+
66
+ def analyze_hotspots(repo_path: str, days: int, output_file: str):
67
+ print(f"Analyzing git churn for past {days} days...")
68
+ churn_data = get_git_churn(repo_path, days)
69
+
70
+ print("Analyzing code complexity...")
71
+ # Only analyze files that exist and have churn
72
+ target_files = [f for f in churn_data.keys()]
73
+ complexity_data = get_complexity(repo_path, target_files)
74
+
75
+ hotspots = []
76
+ for file, churn in churn_data.items():
77
+ if file in complexity_data:
78
+ comp = complexity_data[file]
79
+ hotspots.append({
80
+ "file": file,
81
+ "churn": churn,
82
+ "max_ccn": comp["max_ccn"],
83
+ "nloc": comp["nloc"],
84
+ # Simple score: Churn * CCN.
85
+ # Prompts usually care about this metric.
86
+ "debt_score": churn * comp["max_ccn"]
87
+ })
88
+
89
+ # Sort by debt score descending
90
+ hotspots.sort(key=lambda x: x["debt_score"], reverse=True)
91
+
92
+ # Output
93
+ result = {
94
+ "analysis_date": datetime.now().isoformat(),
95
+ "period_days": days,
96
+ "total_files_analyzed": len(hotspots),
97
+ "hotspots": hotspots[:50] # Top 50
98
+ }
99
+
100
+ if output_file:
101
+ with open(output_file, 'w') as f:
102
+ json.dump(result, f, indent=2)
103
+ print(f"Hotspot analysis saved to {output_file}")
104
+ else:
105
+ print(json.dumps(result, indent=2))
106
+
107
+ def main():
108
+ parser = argparse.ArgumentParser(description="Git Hotspot Analysis (Churn vs Complexity)")
109
+ parser.add_argument("--repo", default=".", help="Repository path")
110
+ parser.add_argument("--days", type=int, default=180, help="Analysis period in days")
111
+ parser.add_argument("--output", "-o", help="Output JSON file")
112
+
113
+ args = parser.parse_args()
114
+
115
+ analyze_hotspots(args.repo, args.days, args.output)
116
+
117
+ if __name__ == "__main__":
118
+ main()
@@ -0,0 +1,88 @@
1
+ ---
2
+ name: report-template
3
+ description: 综合 Scout 阶段所有分析(build-inspector, runtime-inspector, git-forensics, concept-modeler),生成决策就绪的系统风险报告。
4
+ ---
5
+
6
+ # 综合者手册 (The Synthesizer's Manual)
7
+
8
+ > "数据不是信息。信息不是知识。知识不是智慧。" —— T.S. Eliot
9
+
10
+ 你的目标是将原始分析数据转化为**架构师可用的智慧**。
11
+
12
+ ---
13
+
14
+ ## ⚠️ 强制自检 (Mandatory Self-Correction)
15
+
16
+ > [!IMPORTANT]
17
+ > 在生成报告之前,你**必须**进行自我检查:
18
+ > 1. "build-inspector 发现的构建边界和 runtime-inspector 发现的 IPC 边界是否一致?"
19
+ > 2. "git-forensics 发现的高耦合文件对是否跨越了构建边界?"
20
+ > 3. "concept-modeler 识别的缺失组件是否与已发现的风险相关?"
21
+ > 4. "这份报告是否足够完整?"
22
+
23
+ ---
24
+
25
+ ## ⚡ Quick Start
26
+
27
+ 1. **读取模板 (MANDATORY)**: 使用 `view_file references/REPORT_TEMPLATE.md`。你的报告**必须**完全匹配此结构。
28
+ 2. **综合所有发现**: 汇总来自以下来源的输出:
29
+ * `build-inspector` → Build Roots, Topology
30
+ * `runtime-inspector` → IPC Surfaces, Contract Status
31
+ * `git-forensics` → Coupling Pairs, Hotspots
32
+ * `concept-modeler` → Entities, Missing Components
33
+ 3. **起草报告**: 按照模板组织逻辑连接。
34
+ 4. **发布 (CRITICAL)**: 你**必须**使用 `write_to_file` 保存到 `genesis/v{N}/00_SCOUT_REPORT.md`。**禁止**仅打印到聊天。确保 `genesis/v{N}/` 目录存在。
35
+
36
+ ---
37
+
38
+ ## ✅ 完成检查清单
39
+
40
+ 在进入下一阶段之前,验证:
41
+ - [ ] 输出文件已创建: `genesis/v{N}/00_SCOUT_REPORT.md`
42
+ - [ ] 包含: System Fingerprint, Component Map, Risk Matrix, Feature Landing Guide
43
+ - [ ] 用户已确认发现
44
+
45
+ ---
46
+
47
+ ## 🛠️ 综合仪式
48
+
49
+ ### 1. 执行摘要 (Executive Summary)
50
+ * **电梯演讲**: 用 30 秒描述系统的健康状况。
51
+ * **聚焦点**: 技术债务、关键风险、可靠性。
52
+
53
+ ### 2. 暗物质检测
54
+ * 不仅仅列出存在的东西。**列出缺失的东西**。
55
+ * 检查清单: 日志?错误处理?CI/CD?密钥管理?版本握手?
56
+
57
+ ### 3. 交叉验证 (Cross-Verification)
58
+ * **build-inspector** 说 "Workspace 统一管理"?
59
+ * **git-forensics** 说 "高耦合跨越构建根"?
60
+ * **结论**: 发现隐藏的逻辑耦合 → **重构目标**。
61
+
62
+ ### 4. 人工检查点
63
+ * 强制用户确认: "这份报告完整吗?"
64
+ * **在此报告签字前,禁止进入 Blueprint 阶段**。
65
+
66
+ ---
67
+
68
+ ## 🛡️ 老师傅守则
69
+
70
+ 1. **禁止幻觉**: 每个声明必须链接到源文件。
71
+ 2. **残酷诚实**: 直言不讳。如果是一团糟,就说是一团糟。
72
+ 3. **行动导向**: 列出的每个问题都必须暗示一个解决方案 (重构/重写/保留)。
73
+
74
+ ---
75
+
76
+ ## 🧰 工具箱
77
+
78
+ * `references/REPORT_TEMPLATE.md`: 报告主模板。
79
+
80
+ ---
81
+
82
+ ## Consumers (消费者)
83
+
84
+ 这份报告的直接消费者是 `/blueprint` 阶段的:
85
+ * **System Architect**: 依赖你的风险清单来设计规避策略。
86
+ * **Complexity Guard**: 依赖你的发现来审计 RFC 复杂度。
87
+
88
+ 你的分析质量**直接决定**下一阶段的设计质量。
@@ -0,0 +1,100 @@
1
+ # System Context Report
2
+
3
+ **Generated Date**: {{DATE}}
4
+ **Analysis Target**: {{SCOPE}}
5
+
6
+ ## Executive Summary
7
+ > [One sentence summary of the system's state, e.g., "A robust Python backend with some technical debt in the Auth module."]
8
+
9
+ ---
10
+
11
+ ## 1. Component Inventory
12
+
13
+ ### 1.1 Existing Components
14
+ | Component | Type | Path | Description |
15
+ |---|---|---|---|
16
+ | [Name] | [Service/UI/DB] | [Path] | [Brief Desc] |
17
+
18
+ ### 1.2 Missing Components (Dark Matter)
19
+ > [!WARNING]
20
+ > The following components are missing but critical for production readiness.
21
+
22
+ | Component | Category | Why Needed | Impact if Missing |
23
+ |---|---|---|---|
24
+ | Error Handling | Infrastructure | No central error boundary found | Debugging will be difficult |
25
+ | Logging | Observability | No structured logging | Blind in production |
26
+ | Config Mgmt | Ops | Hardcoded secrets detected | Security risk |
27
+
28
+ ---
29
+
30
+ ## 2. Dependency Topology
31
+
32
+ ### 2.1 Build Boundaries (Build Inspector)
33
+ > [Insert findings from `build-inspector`: Build Roots, Topology, Sidecar Warnings]
34
+
35
+ ```mermaid
36
+ graph TD
37
+ A[Module A] --> B[Module B]
38
+ ```
39
+
40
+ ### 2.2 Logical Coupling (Git Forensics)
41
+ > [Insert Hotspot Matrix or Coupling Table]
42
+
43
+ | File A | File B | Coupling | Risk |
44
+ |---|---|---|---|
45
+ | auth.py | user_db.py | 85% | HIGH |
46
+
47
+ ---
48
+
49
+ ## 3. Risks & Warnings
50
+
51
+ ### 3.1 IPC Contract Risks (Runtime Inspector)
52
+ > [!CAUTION]
53
+ > [List IPC surfaces with weak/no contracts found by `runtime-inspector`]
54
+
55
+ ### 3.2 God Modules
56
+ > [List modules with excessive Ca (Afferent Coupling)]
57
+
58
+ ### 3.3 Tech Debt Hotspots
59
+ > [List files with High Churn + High Complexity]
60
+
61
+ ---
62
+
63
+ ## 4. Implicit Constraints (Invariant Hunter)
64
+
65
+ ### 4.1 Business Invariants
66
+ > [Rules that must never be broken]
67
+ - Order total must be >= 0
68
+ - User must verify email before payment
69
+
70
+ ### 4.2 Assumptions
71
+ > [Unwritten assumptions found in code]
72
+ - "Network is always reliable" (No retry logic)
73
+ - "ID is always an integer"
74
+
75
+ ### 4.3 Hardcoded Values
76
+ - API Keys
77
+ - Timeout values
78
+
79
+ ---
80
+
81
+ ## 5. Conceptual Model (Concept Modeler)
82
+
83
+ ### 5.1 Ubiquitous Language
84
+ | Term | Definition |
85
+ |---|---|
86
+ | User | A registered end-user (not an admin) |
87
+ | Order | A purchase request |
88
+
89
+ ### 5.2 Data Flows
90
+ > [Describe key flows]
91
+
92
+ ---
93
+
94
+ ## 6. Human Checkpoints
95
+ > [!IMPORTANT]
96
+ > Please confirm the following before proceeding to Blueprint Phase:
97
+
98
+ - [ ] Is the Component Inventory complete?
99
+ - [ ] Are the identified Risks acceptable for now?
100
+ - [ ] Have all Invariants been captured?
@@ -0,0 +1,93 @@
1
+ ---
2
+ name: runtime-inspector
3
+ description: 分析运行时行为、进程边界和 IPC 机制,检测"协议漂移"风险和进程生命周期问题。
4
+ ---
5
+
6
+ # 窃听者手册 (The Wiretapper's Casebook)
7
+
8
+ > "代码会骗人,但进程不会。一个 `.spawn()` 暴露的比一千行注释还多。" —— 老窃听者箴言
9
+
10
+ 本技能的工作是**追踪进程间的通信线路**。
11
+
12
+ **老师傅核心定律**: 如果两个进程说话,但没人规定它们说什么语言、什么版本、什么格式,那就是一场等待爆发的**协议漂移 (Protocol Mismatch)** 灾难。
13
+
14
+ ---
15
+
16
+ ## ⚠️ 强制深度思考
17
+
18
+ > [!IMPORTANT]
19
+ > 在执行任何分析之前,你**必须**调用 `sequential thinking` 工具,视情况进行 **3—5 步**推理。
20
+ > 思考内容例如:
21
+ > 1. "这个项目有多少个入口点(`main` 函数)?它们是一个进程还是多个?"
22
+ > 2. "进程之间用什么通信?Pipe?HTTP?共享数据库?"
23
+ > 3. "如果我只更新了 A 进程的通信模块,B 进程会崩吗?有版本握手吗?"
24
+
25
+ ---
26
+
27
+ ## ⚡ 任务目标
28
+ 识别**运行时边界 (Runtime Boundaries)** 和 **通信契约 (Communication Contracts)**。
29
+
30
+ ---
31
+
32
+ ## 🧭 探索流程 (The Investigation)
33
+
34
+ ### 第一步:识别入口点 (Identify Entry Points)
35
+ 每个 `main` 函数可能代表一个独立的进程。
36
+ * **搜索目标**:
37
+ * Rust: `fn main()`, `#[tokio::main]`
38
+ * Python: `if __name__ == "__main__":`
39
+ * Node: `require.main === module`, package.json 的 `bin`
40
+ * Go: `func main()`
41
+ * **老师傅直觉**: 找到多个入口点?立刻问:"它们是独立运行的,还是被一个父进程管控的?"
42
+
43
+ ### 第二步:追踪生成链 (Trace Spawning)
44
+ 如果进程 A 拉起了进程 B,这就是一条"血缘线"。
45
+ * **搜索目标**:
46
+ * Rust: `Command::new(...)`, `std::process::Stdio`, `tauri-plugin-shell`
47
+ * Python: `subprocess.Popen`, `multiprocessing.Process`
48
+ * Node: `child_process.spawn`, `child_process.fork`
49
+ * **老师傅警报 (Lifecycle Risks)**:
50
+ * ⚠️ "父进程死了,子进程知道吗?有心跳吗?" -> **僵尸进程风险 (Zombie Child)**
51
+ * ⚠️ "子进程崩溃了,父进程会重启它吗?还是静默失败?" -> **静默故障风险**
52
+
53
+ ### 第三步:窃听通信 (Tap the Wire)
54
+ 进程之间用什么"说话"?协议在哪里定义?
55
+
56
+ * **搜索 Channels (通道)**:
57
+ * `Pipe`, `NamedPipe`, `unix_stream`, `zmq`
58
+ * `TcpListener`, `UdpSocket`, `websocket`, `http::server`
59
+ * **搜索 Protocols (协议)**:
60
+ * `Handshake`, `Version`, `MagicBytes`, `schema`
61
+ * `protobuf`, `serde_json`, `JSON.parse`, `enum Message`
62
+
63
+ * **老师傅核心判断 (Contract Status)**:
64
+
65
+ | 发现 | 状态 | 老师傅建议 |
66
+ | :--- | :---: | :--- |
67
+ | 找到 Channel + 找到 `enum Message` 或 Protobuf 定义 | 🟢 **Strong** | 契约存在,相对安全。 |
68
+ | 找到 Channel + 找到 `Version` 或 `Handshake` 检查 | 🟢 **Strong** | 有版本协商,很好。 |
69
+ | 找到 Channel + 只有 raw JSON/字符串 | 🟡 **Weak** | 无显式契约。改动一端可能炸另一端。 |
70
+ | 找到 Channel + 无任何协议定义 | 🔴 **None** | **通信黑洞!** 这是高危风险。 |
71
+
72
+ ---
73
+
74
+ ## 🛡️ IPC 风险模式速查 (来自安全研究)
75
+
76
+ | 风险模式 | 检测特征 | 老师傅建议 |
77
+ | :--- | :--- | :--- |
78
+ | **协议漂移 (Protocol Mismatch)** | Channel 存在,但无 Handshake/Version | 在新功能规划中**强制添加版本握手任务** |
79
+ | **僵尸进程 (Zombie Child)** | `spawn` 存在,但无 `Kill on Drop` 或心跳 | 标记进程生命周期管理风险 |
80
+ | **单点故障 (SPOF)** | 一个进程管控所有 IPC,无容错 | 建议添加重连/重启逻辑 |
81
+ | **Named Pipe 权限漏洞 (Windows)** | 使用 Named Pipe 但未显式设置 Security Descriptor | 🔴 高危:默认可能允许 Everyone 访问! |
82
+ | **竞态条件 (Race Condition)** | 多进程快速交互,无明确的消息顺序控制 | 建议添加消息序列号或锁机制 |
83
+
84
+ ---
85
+
86
+ ## 📤 输出清单
87
+
88
+ 1. **Process Roots**: 发现的入口点列表(文件路径、角色)。
89
+ 2. **Spawning Chains**: 进程生成关系 (A spawns B)。
90
+ 3. **IPC Surfaces**: 发现的通信通道(类型、关键词、位置)。
91
+ 4. **Contract Status**: `[Strong / Weak / None]`,并说明依据。
92
+ 5. **Lifecycle Risks**: 僵尸进程、静默崩溃等风险。
93
+ 6. **Security Flags (Windows)**: 如果是 Named Pipe,是否有 ACL 设置?
@@ -0,0 +1,58 @@
1
+ ---
2
+ name: spec-writer
3
+ description: Transforms ambiguous user requests into rigorous Product Requirements Documents (PRDs). Use when requirements are vague or high-level.
4
+ ---
5
+
6
+ # The Detective's Guide (需求侦探手册)
7
+
8
+ > "The hardest part of building software is deciding precisely what to build."
9
+
10
+ Your job is to kill ambiguity.
11
+
12
+ ## ⚡ Quick Start
13
+
14
+ 1. **Read Request (MANDATORY)**: Use `view_file` or context to identify "Vibe Words" (Fast, Modern, Easy).
15
+ 2. **Deep Think (CRITICAL)**: You MUST call `sequential thinking` with 3-7 reasoning steps (depending on complexity) to:
16
+ * Extract User Stories (As a X, I want Y, so that Z)
17
+ * Identify ambiguities
18
+ * Draft clarifying questions
19
+ 3. **Interrogate**: Present questions to user. DO NOT proceed without answers.
20
+ 4. **Draft PRD (MANDATORY)**: Use `view_file references/prd_template.md` then `write_to_file` to create `genesis/v{N}/01_PRD.md`.
21
+
22
+ ## 🛑 Mandatory Steps
23
+ Before creating the PRD, you MUST:
24
+ 1. Extract at least 3 clear User Stories.
25
+ 2. Define at least 3 Non-Goals (what we're NOT building).
26
+ 3. Clarify "Vibe Words" with the user (What does "Fast" mean to you? What does "Modern" imply?).
27
+ 4. Use `write_to_file` to save output. DO NOT just print to chat.
28
+
29
+ ## ✅ Completion Checklist
30
+ - [ ] PRD file created: `genesis/v{N}/01_PRD.md`
31
+ - [ ] Contains User Stories, Acceptance Criteria, Non-Goals
32
+ - [ ] Every requirement is testable/measurable
33
+ - [ ] User has approved the PRD
34
+
35
+ ## 🛠️ The Techniques
36
+
37
+ ### 1. Socratic Interrogation (苏格拉底追问)
38
+ * **User**: "I want it to be fast."
39
+ * **You**: "< 100ms p99? Or just UI optimistic updates?"
40
+ * *Goal*: Turn adjectives into numbers.
41
+
42
+ ### 2. Context Compression (上下文压缩)
43
+ * **Input**: 500 lines of chat history.
44
+ * **Action**: Extract the *User Stories*. "As a User, I want X, so that Y."
45
+ * **Discard**: Implementation details discussed too early (e.g., "Use Redis").
46
+
47
+ ### 3. Non-Goal Setting (画圈)
48
+ * Define what we are **NOT** doing.
49
+ * *Why*: Prevents scope creep. Prevents "What about X?" later.
50
+
51
+ ## ⚠️ Detective's Code
52
+
53
+ 1. **Contract First**: If you can't test it, don't write it.
54
+ 2. **No Solutions**: Describe *what*, not *how*. Leave *how* to the Architect.
55
+ 3. **User Centric**: Every requirement must trace back to a user value.
56
+
57
+ ## 🧰 The Toolkit
58
+ * `references/prd_template.md`: The Product Requirements Document template.
@@ -0,0 +1,174 @@
1
+ # Product Requirements Document (PRD) v2.0
2
+
3
+ **Project**: [Project Name]
4
+ **Title**: [Feature/Requirement Name]
5
+ **Status**: Draft | Review | Approved
6
+ **Version**: 1.0
7
+ **Author**: [Author Name or Agent]
8
+ **Date**: [YYYY-MM-DD]
9
+
10
+ ---
11
+
12
+ ## 1. Executive Summary
13
+ <!-- Context Compression: State the "Why" and "What" in < 50 words. -->
14
+ <!-- ⚠️ CRITICAL: This is the "elevator pitch". Must be < 50 words. -->
15
+
16
+ [Briefly describe the problem being solved and the proposed solution. Focus on value.]
17
+
18
+ ---
19
+
20
+ ## 2. Background & Context
21
+ <!-- ⭐ 新增: 提供充分背景,帮助后续System Design阶段理解 -->
22
+
23
+ ### 2.1 Problem Statement (问题陈述)
24
+ - **Current Pain Point**: [用户面临的具体问题]
25
+ - **Impact Scope**: [受影响的用户群体/业务范围]
26
+ - **Business Impact**: [对业务的影响,如收入、用户满意度、效率]
27
+
28
+ ### 2.2 Opportunity (机会)
29
+ [如果解决这个问题,能带来什么价值?定量描述]
30
+
31
+ ### 2.3 Reference & Competitors (参考与竞品) - 可选
32
+ <!-- 了解市场已有解决方案,避免重复造轮子 -->
33
+ - **Competitor A**: [特点、优缺点]
34
+ - **Competitor B**: [特点、优缺点]
35
+ - **Our Differentiation**: [我们的独特价值]
36
+
37
+ ---
38
+
39
+ ## 3. Goals & Non-Goals
40
+
41
+ ### 3.1 Goals
42
+ <!-- ⚠️ CRITICAL: 必须使用 SMART 原则 (Specific, Measurable, Achievable, Relevant, Time-bound) -->
43
+
44
+ - **[G1]**: [可衡量的目标,如: 用户登录成功率 > 95%]
45
+ - **[G2]**: [可衡量的目标,如: 页面加载时间 < 2s]
46
+
47
+ ### 3.2 Non-Goals (Out of Scope)
48
+ <!-- Crucial for preventing scope creep -->
49
+
50
+ - **[NG1]**: [暂不考虑的功能,如: 第三方OAuth登录]
51
+ - **[NG2]**: [未来版本的考虑,如: 多因素认证]
52
+
53
+ ---
54
+
55
+ ## 4. User Stories (The "What")
56
+ <!-- Format: As a [User], I want to [Action], so that [Benefit] -->
57
+ <!-- ⚠️ CRITICAL: 每个User Story必须有唯一ID [REQ-XXX],用于追溯链 -->
58
+
59
+ ### US01: [Title] [REQ-001]
60
+ * **Story**: As a [role], I want to [feature], so that [value].
61
+ * **Acceptance Criteria (AC)**:
62
+ * [ ] **Given** [context], **When** [action], **Then** [outcome].
63
+ * [ ] **Error Case**: When [failure condition], show [specific error message].
64
+ * **Priority**: P0 (Must Have) | P1 (Should Have) | P2 (Nice to Have)
65
+ * **Estimation**: [Story Points 或 天数] - 可选
66
+
67
+ ### US02: [Title] [REQ-002]
68
+ * **Story**: ...
69
+ * **Acceptance Criteria (AC)**:
70
+ * [ ] ...
71
+ * **Priority**: P0/P1/P2
72
+
73
+ <!-- 继续添加更多User Stories... -->
74
+
75
+ ---
76
+
77
+ ## 5. User Experience & Design (用户体验) - 可选
78
+ <!-- ⭐ 新增: 描述关键的UX流程,帮助前端系统设计 -->
79
+
80
+ ### 5.1 Key User Flows (关键用户流程)
81
+ <!-- 使用Mermaid流程图描述关键用户旅程 -->
82
+
83
+ ```mermaid
84
+ graph LR
85
+ A[用户访问登录页] --> B[输入邮箱密码]
86
+ B --> C{认证}
87
+ C -->|成功| D[跳转Dashboard]
88
+ C -->|失败| E[显示错误提示]
89
+ E --> B
90
+ ```
91
+
92
+ ### 5.2 Design Guidelines (设计规范)
93
+ - **UI Style**: [现代化、简洁、专业等]
94
+ - **Color Palette**: [主色调、辅助色]
95
+ - **Interactions**: [动画、反馈机制]
96
+
97
+ ---
98
+
99
+ ## 6. Constraint Analysis
100
+ <!-- Derived from /scout report or /challenge -->
101
+ <!-- ⭐ 增强: 分类更详细,便于后续System Design继承约束 -->
102
+
103
+ ### 6.1 Technical Constraints (技术约束)
104
+ * **Legacy Systems**: [e.g., Must work with existing Auth system]
105
+ * **Performance**: [e.g., API response time < 200ms (p95)]
106
+ * **Scalability**: [e.g., Support 100k concurrent users]
107
+
108
+ ### 6.2 Security & Compliance (安全与合规)
109
+ * **Security**: [e.g., No PII in logs, HTTPS only]
110
+ * **Privacy**: [e.g., GDPR compliance]
111
+ * **Compliance**: [e.g., SOC 2 Type II]
112
+
113
+ ### 6.3 Time & Budget (时间与预算)
114
+ * **Deadline**: [交付时间,如: 2026-03-01]
115
+ * **Budget**: [预算限制] - 可选
116
+ * **Team**: [团队规模和技能] - 可选
117
+
118
+ ---
119
+
120
+ ## 7. Success Metrics (成功指标)
121
+ <!-- ⭐ 新增: 如何衡量成功,便于后续验证 -->
122
+
123
+ | Metric | Target | Measurement Method |
124
+ |--------|--------|-------------------|
125
+ | 用户登录成功率 | > 95% | Google Analytics |
126
+ | 页面加载时间 (p95) | < 2s | Lighthouse/监控 |
127
+ | 用户满意度 (NPS) | > 4.5/5 | 用户调研 |
128
+
129
+ ---
130
+
131
+ ## 8. Definition of Done (完成标准)
132
+
133
+ * [ ] All Acceptance Criteria (AC) passed.
134
+ * [ ] Unit tests written and passing (coverage > 80%).
135
+ * [ ] Integration tests passing.
136
+ * [ ] No new lint errors.
137
+ * [ ] Documentation updated (API docs, user manual).
138
+ * [ ] Performance benchmarks met (if applicable).
139
+ * [ ] Security audit passed (if applicable).
140
+ * [ ] User acceptance testing (UAT) completed.
141
+
142
+ ---
143
+
144
+ ## 9. Appendix (附录) - 可选
145
+
146
+ ### 9.1 Glossary (术语表)
147
+ - **[Term 1]**: [Definition]
148
+ - **[Term 2]**: [Definition]
149
+
150
+ ### 9.2 References (参考资料)
151
+ - [Link 1]
152
+ - [Link 2]
153
+
154
+ ### 9.3 Change Log (变更日志)
155
+ | Version | Date | Changes | Author |
156
+ |---------|------|---------|--------|
157
+ | 1.0 | 2026-01-08 | Initial version | XXX |
158
+
159
+ ---
160
+
161
+ <!-- ⚠️ CRITICAL 使用指南 -->
162
+ <!--
163
+ **PRD撰写原则 (Amazon 6-pager风格)**:
164
+ 1. **精炼至上**: 总长度最多6页(约3000-4000字)
165
+ 2. **Executive Summary < 50字**: 电梯演讲
166
+ 3. **每个User Story < 100字**: 简洁清晰
167
+ 4. **数据驱动**: 所有目标和指标必须可衡量
168
+ 5. **追溯链**: 每个User Story有唯一ID [REQ-XXX]
169
+
170
+ **章节使用指南**:
171
+ - **必需章节**: 1, 2.1, 3, 4, 6, 8
172
+ - **可选章节**: 2.3 (竞品分析), 5 (UX设计), 7 (成功指标), 9 (附录)
173
+ - **小项目**: 可省略 2.3, 5, 9,但结构保持一致
174
+ -->