@dtt_siye/atool 1.2.0 → 1.3.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 (79) hide show
  1. package/README.md +30 -10
  2. package/VERSION +1 -1
  3. package/hooks/session-start +9 -12
  4. package/lib/export-analysis.sh +100 -0
  5. package/lib/install-kiro.sh +11 -6
  6. package/lib/knowledge-graph.sh +7 -2
  7. package/package.json +1 -1
  8. package/skills/doc-standards-enforcer/SKILL.md +200 -220
  9. package/skills/doc-standards-enforcer/examples/valid-document-example.md +5 -5
  10. package/skills/doc-standards-enforcer/references/101-standards-summary.md +17 -17
  11. package/skills/project-analyze/SKILL.md +138 -124
  12. package/skills/project-analyze/phases/{phase0-discovery.md → archive/phase0-discovery.md} +6 -2
  13. package/skills/project-analyze/phases/{phase1-inventory.md → archive/phase1-inventory.md} +10 -0
  14. package/skills/project-analyze/phases/{phase2-deep-analysis.md → archive/phase2-deep-analysis.md} +20 -0
  15. package/skills/project-analyze/phases/{phase3-knowledge-graph.md → archive/phase3-knowledge-graph.md} +31 -0
  16. package/skills/project-analyze/phases/{phase3a-multi-dimensional.md → archive/phase3a-multi-dimensional.md} +13 -0
  17. package/skills/project-analyze/phases/{phase5-synthesis.md → archive/phase5-synthesis.md} +20 -0
  18. package/skills/project-analyze/phases/phase1-setup.md +182 -0
  19. package/skills/project-analyze/phases/phase2-understand.md +108 -0
  20. package/skills/project-analyze/phases/phase3-graph.md +77 -0
  21. package/skills/project-analyze/phases/phase4-synthesize.md +260 -0
  22. package/skills/project-analyze/phases/phase5-export.md +161 -0
  23. package/skills/project-analyze/prompts/{deep-analysis-agent.md → archive/deep-analysis-agent.md} +14 -1
  24. package/skills/project-analyze/prompts/understand-agent.md +407 -0
  25. package/skills/requirements-writer/README.md +1 -1
  26. package/skills/requirements-writer/SKILL.md +378 -284
  27. package/skills/requirements-writer/examples/prd-outline-example.md +5 -5
  28. package/skills/requirements-writer/templates/module-prd-template.md +15 -15
  29. package/skills/requirements-writer/templates/prd-outline-template.md +3 -3
  30. package/skills/requirements-writer/templates/user-story-template.md +23 -23
  31. package/skills/software-architecture/SKILL.md +248 -17
  32. package/templates/CLAUDE.md.android +17 -0
  33. package/templates/CLAUDE.md.devops +17 -0
  34. package/templates/CLAUDE.md.generic +17 -0
  35. package/templates/CLAUDE.md.go +17 -0
  36. package/templates/CLAUDE.md.harmony +17 -0
  37. package/templates/CLAUDE.md.java +17 -0
  38. package/templates/CLAUDE.md.mobile-flutter +17 -0
  39. package/templates/CLAUDE.md.mobile-react-native +17 -0
  40. package/templates/CLAUDE.md.mobile-swift +17 -0
  41. package/templates/CLAUDE.md.python +17 -0
  42. package/templates/CLAUDE.md.rust +17 -0
  43. package/templates/CLAUDE.md.rust-tauri +17 -0
  44. package/templates/CLAUDE.md.web +17 -0
  45. package/templates/cursor-rules.android.mdc +17 -0
  46. package/templates/cursor-rules.devops.mdc +17 -0
  47. package/templates/cursor-rules.generic.mdc +17 -0
  48. package/templates/cursor-rules.go.mdc +17 -0
  49. package/templates/cursor-rules.harmony.mdc +17 -0
  50. package/templates/cursor-rules.java.mdc +17 -0
  51. package/templates/cursor-rules.mobile-flutter.mdc +17 -0
  52. package/templates/cursor-rules.mobile-react-native.mdc +17 -0
  53. package/templates/cursor-rules.mobile-swift.mdc +17 -0
  54. package/templates/cursor-rules.python.mdc +17 -0
  55. package/templates/cursor-rules.rust-tauri.mdc +17 -0
  56. package/templates/cursor-rules.rust.mdc +17 -0
  57. package/templates/cursor-rules.web.mdc +17 -0
  58. package/templates/kiro-steering.android.md +6 -0
  59. package/templates/kiro-steering.devops.md +6 -0
  60. package/templates/kiro-steering.generic.md +6 -0
  61. package/templates/kiro-steering.go.md +6 -0
  62. package/templates/kiro-steering.harmony.md +6 -0
  63. package/templates/kiro-steering.java.md +6 -0
  64. package/templates/kiro-steering.mobile-flutter.md +6 -0
  65. package/templates/kiro-steering.mobile-react-native.md +6 -0
  66. package/templates/kiro-steering.mobile-swift.md +6 -0
  67. package/templates/kiro-steering.python.md +6 -0
  68. package/templates/kiro-steering.rust-tauri.md +6 -0
  69. package/templates/kiro-steering.rust.md +6 -0
  70. package/templates/kiro-steering.web.md +6 -0
  71. package/templates/shared/hard-rules.md +21 -0
  72. /package/skills/project-analyze/phases/{phase0.5-prescan.md → archive/phase0.5-prescan.md} +0 -0
  73. /package/skills/project-analyze/phases/{phase2a-l4-analysis.md → archive/phase2a-l4-analysis.md} +0 -0
  74. /package/skills/project-analyze/phases/{phase2b-l5-analysis.md → archive/phase2b-l5-analysis.md} +0 -0
  75. /package/skills/project-analyze/phases/{phase4-code-quality.md → archive/phase4-code-quality.md} +0 -0
  76. /package/skills/project-analyze/phases/{phase6-validation.md → archive/phase6-validation.md} +0 -0
  77. /package/skills/project-analyze/prompts/{code-review-agent.md → archive/code-review-agent.md} +0 -0
  78. /package/skills/project-analyze/prompts/{inventory-agent.md → archive/inventory-agent.md} +0 -0
  79. /package/skills/project-analyze/prompts/{l4-analysis-agent.md → archive/l4-analysis-agent.md} +0 -0
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  name: project-analyze
3
3
  description: "Deep project analysis v5.0 — 7-phase pipeline with five-dimensional analysis framework, 14 node types, 24 edge types, 5-level granularity zooming, interactive visualization (Cytoscape.js), and query system. 5 depth levels (L1-L5): Discovery → Pre-Scan → Inventory → Deep Analysis → Knowledge Graph → Multi-Dimensional Analysis → Code Quality → Document Synthesis → Validation. Checkpoint/resume, incremental docs, large-module decomposition. Zero-KT standard, Chinese output. 触发:分析项目/生成文档/analyze project/generate docs/project analysis"
4
- version: 5.0.0
4
+ version: 5.1.0
5
5
  ---
6
6
 
7
7
  # Project Analyzer v5.0
@@ -40,83 +40,94 @@ version: 5.0.0
40
40
  | L4 | 函数级分析:L3 + 逐函数调用链追踪 + 性能热点识别 + 安全审计点 + 数据流路径 | 质量审查、性能优化 |
41
41
  | L5 | 跨模块行为推断:L4 + 时序图 + 状态机 + 异常路径追踪 + 数据血缘 | 架构重构、完整技术文档 |
42
42
 
43
- **选择规则**:用户未指定 → 默认 L2;<50 文件 → 建议提升到 L3L3/L4/L5 对所有项目规模可用(通过多批次执行)。**L1 特殊**:Phase 0.5 完全替代 Phase 1(0 AI agents,纯 bash 提取)。
43
+ **选择规则**:用户未指定 → 默认 L2;<50 文件 → 建议提升到 L3。**L1-L5 所有深度对任何项目规模均可用**(L3+ 通过多批次执行)。Phase 1 确认时**必须向用户展示全部 L1-L5 五个选项**。**L1 特殊**:Phase 1 pre-scan 完全替代 Phase 2 AI 分析(0 AI agents,纯 bash 提取)。
44
44
 
45
- ---
46
-
47
- ## Pipeline Controller
48
-
49
- ### Execution Flow
45
+ ### AI 调用设计原则
50
46
 
51
- 1. **Detect IDE** set execution_mode (parallel/sequential/compressed)
52
- 2. **Read `analysis-state.json`** (if exists) → determine resume point (see `phases/phase0-discovery.md` 0.5a)
53
- 3. **Execute Phase 0**: Read `phases/phase0-discovery.md` → detect stack, evaluate scale, compute importance, get user confirmation → write `analysis-state.json`
54
- 4. **Execute Phase 0.5 (Pre-Scan)**: Run `source lib/pre-scan.sh && pre_scan_project "$PROJECT_ROOT" "$PRESCAN_DIR"` → pure bash structural extraction → output `.atool-docs/pre-scan/{module-slug}.json` + `manifest.json` → write checkpoint `phase0_5_prescan = "completed"`
55
- 5. Based on Phase 0 + Phase 0.5 pre-scan data → set depth, scale, module list
56
- 6. **For each phase in pipeline order**:
57
- - Check preconditions in `analysis-state.json`
58
- - If not completed:
59
- - **Read `phases/phase{N}-{name}.md`** for detailed instructions
60
- - Execute phase → write checkpoint to `analysis-state.json`
61
- 6. **Phase 6**: Read `phases/phase6-validation.md` → validate all outputs → write summary
47
+ Pipeline AI bash 工具的分工遵循核心原则:**确定性操作用 bash,语义理解用 AI**。
62
48
 
63
- ### Pipeline Order
64
-
65
- ```
66
- Phase 0 → phases/phase0-discovery.md (always)
67
- Phase 0.5→ phases/phase0.5-prescan.md (always, pure bash, no AI)
68
- Phase 1 → phases/phase1-inventory.md (always; L1 depth: skip, use Phase 0.5 data)
69
- Phase 2 → phases/phase2-deep-analysis.md (skip if Kiro)
70
- Phase 2a → phases/phase2a-l4-analysis.md (only if depth >= L4, skip if Kiro)
71
- Phase 2b → phases/phase2b-l5-analysis.md (only if depth >= L5, skip if Kiro)
72
- Phase 3 → phases/phase3-knowledge-graph.md (always, main agent only)
73
- Phase 3a → phases/phase3a-multi-dimensional.md (always, Kiro: structure only)
74
- Phase 4 → phases/phase4-code-quality.md (skip if Kiro)
75
- Phase 5 → phases/phase5-synthesis.md (always)
76
- Phase 6 → phases/phase6-validation.md (always)
77
- ```
49
+ | Phase | AI 调用 | 方式 | 原因 |
50
+ |-------|---------|------|------|
51
+ | Phase 1 SETUP | 否 | bash 脚本 | 栈检测、文件计数、重要性排序、pre-scan 语法提取 = 确定性操作 |
52
+ | Phase 2 UNDERSTAND | 是 | Sub-agent × N | 核心分析 — 业务逻辑、设计意图、Zero-KT 三层文档 |
53
+ | Phase 3 GRAPH | **否** | bash `knowledge-graph.sh` + `multi-dimensional-analysis.sh` | 图组装 + 五维分析 = 确定性算法 |
54
+ | Phase 4 SYNTHESIZE | 是 | 主 agent + Sub-agent | 项目级文档综合 + Mermaid 图表 + 质量报告 |
55
+ | Phase 5 EXPORT | 否 | bash 脚本 | 文件整理 + 项目注册 = 确定性操作 |
78
56
 
79
- ### IMPORTANT RULE
57
+ **Pre-scan 效率基石**:Phase 1 的 pre-scan 一次 bash 提取(~5秒/150文件)→ Phase 2 所有 AI sub-agent 复用数据。跳过 pre-scan → 每个 AI sub-agent 都要重新全量读取源文件(5-10x token 浪费)。
80
58
 
81
- **Before executing ANY phase, you MUST read the corresponding phase file from `phases/phase{N}-{name}.md`. Do not execute from memory. Each phase file contains critical details not duplicated here.**
59
+ ### 深度等级 AI 使用差异
82
60
 
83
- ### Phase 0.5: Pre-Scan (纯 Bash,无 AI)
61
+ | 维度 | L1 | L2 | L3 | L4 | L5 |
62
+ |------|-----|-----|-----|-----|-----|
63
+ | 执行 Phase | 1→3→5 | 1→2→3→4→5 | 同 L2 | 同 L2(Phase 2 追加 L4 指令) | 同 L2(Phase 2 追加 L5 指令) |
64
+ | AI Sub-agent | **0 个** | Phase 2 + Phase 4 | 同 L2 | 同 L2(更深指令)| 同 L2(最深指令)|
65
+ | 源文件 AI 读取 | 无 | 分层策略* | 同 L2,提取更多细节 | +函数体定向行范围 | +跨模块推断(不重读源文件) |
66
+ | Sub-agent Prompt | N/A | 标准模板 | +L3 追加指令(签名/模式/ADR)| +L4 追加指令(调用链/性能/安全)| +L5 追加指令(时序图/状态机/数据血缘) |
67
+ | 独特产出 | overview + modules(lite) | +quality + diagrams | +实现细节+设计决策 | +调用链分析+性能报告 | +时序图+状态机+数据血缘 |
68
+ | Token 估算 | ~10K | ~50K | ~100K | ~200K | ~350K |
84
69
 
85
- **目标**:使用 grep/awk/jq 秒级提取所有语法元数据,消除 AI 重复读取。
70
+ \* 分层策略:小文件(<100行)用 pre-scan 数据不重读;中文件(100-500行)全文;大文件(>500行)仅读关键行范围
86
71
 
87
- **执行**:
88
- 1. 读取 `analysis-state.json` 获取模块列表和技术栈
89
- 2. 执行 `source lib/pre-scan.sh && pre_scan_project "$PROJECT_ROOT" "$PRESCAN_DIR"`
90
- 3. 输出 `.atool-docs/pre-scan/{module-slug}.json` + `manifest.json`
91
- 4. 写入检查点 `phase0_5_prescan = "completed"`
72
+ **递增原则**:每级深度在上一级基础上通过 sub-agent prompt 追加指令增加分析维度,不重新读取已分析过的文件。L1 完全零 AI(Phase 1 bash 替代 Phase 2),是最快但最浅的扫描。
92
73
 
93
- **支持语言**:Python, Java/Kotlin, TypeScript/JavaScript/Vue/Svelte, Go, Rust, 通用 fallback
94
-
95
- **性能目标**:152 文件/10 模块 < 10 秒(vs AI Phase 1 的 2-4 分钟)
74
+ ---
96
75
 
97
- **增量扫描**:比对文件 MD5 hash,仅重新扫描变更文件。
76
+ ## Pipeline Controller
98
77
 
99
- **降级**:pre-scan 失败时,Phase 1 自动回退到全量 AI 提取(v5.0 行为)。
78
+ ### 5-Phase 架构
100
79
 
101
- 详细指令:`phases/phase0.5-prescan.md`
80
+ ```
81
+ Phase 1: SETUP → phases/phase1-setup.md (bash only, no AI, ~30秒)
82
+ Phase 2: UNDERSTAND → phases/phase2-understand.md (AI sub-agents ≤5并行)
83
+ Phase 3: GRAPH → phases/phase3-graph.md (bash only, no AI, ~30秒)
84
+ Phase 4: SYNTHESIZE → phases/phase4-synthesize.md (main agent + sub-agents)
85
+ Phase 5: EXPORT → phases/phase5-export.md (bash only, no AI, ~10秒)
86
+ ```
102
87
 
103
- ### Sub-Agent Prompts
88
+ ### 执行规则(硬性)
89
+
90
+ 1. **每个 Phase 开始前必须读取对应的 phase 文件**,不可从记忆执行
91
+ 2. **bash Phase(1/3/5)必须通过 Bash 工具调用**,禁止 AI 模拟执行或用 Write 工具写脚本代替
92
+ 3. **每个 Phase 完成后立即写 `.atool-docs/analysis-state.json`**
93
+ 4. **Phase 2 并发上限 5 个 sub-agent**,超出部分按 importance 降序分批排队
94
+ 5. **Phase 3 bash 调用失败时**:在 state.json 记录 `phase3_graph: "failed"`,继续 Phase 4(跳过图谱相关文档,Phase 4 检查此标记)
95
+ 6. **断点续传**:先读 state.json,跳过 `status: "completed"` 的 phase
96
+
97
+ ### 状态管理(简化版)
98
+
99
+ `analysis-state.json` 最小结构:
100
+ ```json
101
+ {
102
+ "version": "5.1",
103
+ "project_root": "/path/to/project",
104
+ "stack": "java-spring",
105
+ "depth": "L2",
106
+ "scale": "MEDIUM",
107
+ "modules": ["user-service", "order-service"],
108
+ "phases": {
109
+ "phase1_setup": "completed",
110
+ "phase2_understand": "in_progress",
111
+ "phase3_graph": "pending",
112
+ "phase4_synthesize": "pending",
113
+ "phase5_export": "pending"
114
+ },
115
+ "module_status": {
116
+ "user-service": { "phase2": "completed" },
117
+ "order-service": { "phase2": "in_progress" }
118
+ },
119
+ "updated_at": "2026-04-04T10:00:00Z"
120
+ }
121
+ ```
104
122
 
105
- When dispatching sub-agents for phases 1, 2, 2a, 4:
106
- - Read the prompt template from `prompts/{name}-agent.md`
107
- - Fill in module-specific variables (module name, inventory data, rules content, etc.)
108
- - Dispatch with the filled prompt
123
+ status 枚举值:`"pending"` | `"in_progress"` | `"completed"` | `"failed"` | `"skipped"`
109
124
 
110
- | Phase | Prompt Template | Variables to Fill |
111
- |-------|----------------|-------------------|
112
- | Phase 1 | `prompts/inventory-agent.md` | file_list, module-slug |
113
- | Phase 2 | `prompts/deep-analysis-agent.md` | module_name, inventory_json_content, rules_content, stack, project_name, module_list, depth_specific_instructions |
114
- | Phase 2a | `prompts/l4-analysis-agent.md` | module_name, analysis_json_content, inventory_json_content, file_list |
115
- | Phase 4 | `prompts/code-review-agent.md` | module_name, inventory_json, relevant_graph_subtree, multi_dimensional_context, file_list |
125
+ ### HARD GATE bash Phase 执行验证
116
126
 
117
- ### Batch Dispatch Rule (Hard Limit)
127
+ Phase 1、3、5 执行前在对话中明确声明:
128
+ > "正在通过 Bash 工具执行 Phase N..."
118
129
 
119
- **Maximum 5 concurrent sub-agents at all times.** When modules > 5, dispatch in batches of 5 by importance descending order. Wait for all agents in current batch to complete before dispatching next batch.
130
+ 执行后检查输出文件是否存在以确认成功。不得跳过此验证。
120
131
 
121
132
  ---
122
133
 
@@ -139,23 +150,17 @@ else:
139
150
 
140
151
  | Phase | Claude | Cursor | Kiro | Notes |
141
152
  |-------|--------|--------|------|-------|
142
- | Phase 0 | full | full | full | All IDEs |
143
- | Phase 0.5 | full (bash) | full (bash) | full (bash) | Pure shell, no AI |
144
- | Phase 1 | parallel | sequential | compressed (file counts only) | |
145
- | Phase 2 | parallel | sequential | **skip** | Kiro uses inventory directly |
146
- | Phase 2a | parallel | sequential | **skip** | L4 function-level |
147
- | Phase 2b | parallel+aggregate | sequential | **skip** | L5 cross-module |
148
- | Phase 3 | main agent | main agent | main agent | No sub-agents |
149
- | Phase 3a | 5 dimensions | 5 dimensions | structure only | v5.0 |
150
- | Phase 4 | parallel | sequential | **skip** | |
151
- | Phase 5 | full | full | L1 quality from inventory | |
152
- | Phase 6 | full | full | full | All IDEs |
153
+ | Phase 1 SETUP | full (bash) | full (bash) | full (bash) | Pure shell, no AI |
154
+ | Phase 2 UNDERSTAND | parallel sub-agents | sequential | **skip** | Kiro uses pre-scan data directly |
155
+ | Phase 3 GRAPH | main agent (bash) | main agent (bash) | main agent (bash) | No sub-agents |
156
+ | Phase 4 SYNTHESIZE | parallel sub-agents | sequential | L1 quality from pre-scan | |
157
+ | Phase 5 EXPORT | full (bash) | full (bash) | full (bash) | All IDEs |
153
158
 
154
159
  ### Kiro Compressed Mode
155
- Phase 0.5: full pre-scan (bash, same as all IDEs). Phase 1: file counts + import/export counts only (no signatures). Phase 5: L1 quality docs from pre-scan inventory. No CODE_REVIEW.md.
160
+ Phase 1: full pre-scan (bash, same as all IDEs). Phase 2: skip (use pre-scan data). Phase 4: L1 quality docs from pre-scan data only. No quality/ reports.
156
161
 
157
162
  ### Cursor Sequential Mode
158
- Modules processed in importance order, one at a time. Progress line per module. Phase 3 and 6 execute normally.
163
+ Modules processed in importance order, one at a time. Progress line per module. Phase 3 and 5 execute normally.
159
164
 
160
165
  ---
161
166
 
@@ -173,13 +178,13 @@ write analysis-state.json
173
178
  ### Resume Flow
174
179
  1. Read `.atool-docs/analysis-state.json`
175
180
  2. If no state file → full analysis
176
- 3. If `phase0_5_prescan != "completed"` → execute Phase 0.5
181
+ 3. If `phases.phase1_setup != "completed"` → execute Phase 1
177
182
  4. Detect stale modules (file hash mismatch) → mark for re-analysis
178
183
  5. Determine resume point from checkpoint
179
184
  6. Execute pending phases, skip completed, rerun stale
180
185
  7. Update final state
181
186
 
182
- Detailed resume logic: see `phases/phase0-discovery.md` section 0.5a.
187
+ Detailed resume logic: see `phases/phase1-setup.md`.
183
188
 
184
189
  ### Incremental Document Recovery
185
190
  When resuming Phase 5, incrementally update already-generated documents using `<!-- aTool-module-start:{slug} -->` markers. Only regenerate changed modules.
@@ -188,54 +193,62 @@ When resuming Phase 5, incrementally update already-generated documents using `<
188
193
 
189
194
  ## Output File Summary
190
195
 
191
- ### Final Deliverables (project directory)
192
-
193
- | File | Condition |
194
- |------|-----------|
195
- | `README.md` | always |
196
- | `COMPONENT.md` | always |
197
- | `CODE_REVIEW.md` | L2/L3/L4/L5 |
198
- | `UI_STYLE.md` | UI projects only |
199
- | `CLAUDE.md` | append project rules |
200
- | `.cursor/rules/atool-conventions.mdc` | always |
201
- | `.kiro/steering/atool-conventions.md` | always |
202
- | `docs/` (~15 files) | L2/L3/L4/L5 |
203
-
204
- ### Intermediate Artifacts (.atool-docs/)
205
-
206
- | File | Phase |
207
- |------|-------|
208
- | `analysis-state.json` | Phase 0 |
209
- | `pre-scan/{module-slug}.json` | Phase 0.5 |
210
- | `pre-scan/manifest.json` | Phase 0.5 |
211
- | `inventory/{module-slug}.json` | Phase 1 |
212
- | `modules/{module-slug}/MODULE-DOC.md` | Phase 2 |
213
- | `modules/{module-slug}/analysis.json` | Phase 2 |
214
- | `modules/{module-slug}/references.json` | Phase 2 |
215
- | `modules/{module-slug}/l4-analysis.json` | Phase 2a (L4+) |
216
- | `modules/{module-slug}/l5-analysis.json` | Phase 2b (L5) |
217
- | `cross-module-behavior.json` | Phase 2b (L5) |
218
- | `knowledge-graph.json` | Phase 3 |
219
- | `multi-dimensional-analysis.json` | Phase 3a |
220
- | `query-index.json` | Phase 3a |
221
- | `visualization/index.html` | Phase 3a |
222
- | `code-review/{module-slug}.json` | Phase 4 |
223
-
224
- ### Multi-Project Extra Outputs
225
-
226
- | File | Description |
227
- |------|-------------|
228
- | `.atool-docs/discovery.json` | Project discovery record |
229
- | `.atool-docs/summaries/{name}/summary.md` | Sub-project summary |
230
- | `.atool-docs/cross-project-analysis.md` | Cross-project relations |
196
+ ### 用户交付物(`atool-analysis/`)— 统一入口
197
+
198
+ | 路径 | 内容 | 生成阶段 |
199
+ |------|------|---------|
200
+ | `atool-analysis/manifest.json` | 元数据:分析时间/版本/栈 | Phase 5 |
201
+ | **overview/** | | |
202
+ | `atool-analysis/overview/summary.md` | 业务摘要(非技术人员友好)| Phase 4 |
203
+ | `atool-analysis/overview/architecture.md` | 架构说明 + Mermaid 图 + ADR | Phase 4 |
204
+ | `atool-analysis/overview/tech-stack.md` | 技术栈明细 | Phase 4 |
205
+ | `atool-analysis/overview/getting-started.md` | 新人上手指南(Zero-KT)| Phase 4 |
206
+ | **modules/{name}/** | | |
207
+ | `atool-analysis/modules/{name}/README.md` | 模块业务说明(非技术人员友好)| Phase 2 |
208
+ | `atool-analysis/modules/{name}/api.md` | 接口文档(字段级 Schema + 错误码表 + curl 示例)| Phase 2 |
209
+ | `atool-analysis/modules/{name}/data-model.md` | 数据模型(字段约束 + 枚举 + 级联 + ER 图)| Phase 2 |
210
+ | `atool-analysis/modules/{name}/dev-guide.md` | 开发指引(如何扩展/调试)| Phase 2 |
211
+ | `atool-analysis/modules/{name}/prd.md` | 模块级 PRD(按钮级交互定义 + 验收标准)| Phase 2 |
212
+ | `atool-analysis/modules/{name}/test-cases.md` | 测试用例(功能/边界/安全/集成)| Phase 2 |
213
+ | **quality/** | | |
214
+ | `atool-analysis/quality/code-review.md` | 代码质量(+重构优先级矩阵+迁移路线图+代码对比)| Phase 4 |
215
+ | `atool-analysis/quality/tech-debt.md` | 技术债清单 | Phase 4 |
216
+ | `atool-analysis/quality/recommendations.md` | 改进建议(+impact-vs-effort 矩阵)| Phase 4 |
217
+ | `atool-analysis/quality/security-audit.md` | 安全审计(OWASP Top 10 逐项检查)| Phase 4 |
218
+ | `atool-analysis/quality/performance-baseline.md` | 性能基准(延迟/内存/并发估算)| Phase 4 |
219
+ | **project/** | | |
220
+ | `atool-analysis/project/prd.md` | 项目级 PRD(全局用户流 + 功能矩阵 + 路线图)| Phase 4 |
221
+ | `atool-analysis/project/deployment.md` | 部署文档(环境/配置/检查清单/回滚)| Phase 4 |
222
+ | `atool-analysis/project/testing-strategy.md` | 测试策略(金字塔 + 覆盖率 + 自动化)| Phase 4 |
223
+ | `atool-analysis/project/runbook.md` | 运维手册(故障排查 + 监控 + 告警)| Phase 4 |
224
+ | **diagrams/** | | |
225
+ | `atool-analysis/diagrams/architecture.mmd` | Mermaid 整体架构图 | Phase 4 |
226
+ | `atool-analysis/diagrams/module-dependencies.mmd` | 模块依赖图 | Phase 4 |
227
+ | `atool-analysis/diagrams/data-flow.mmd` | 数据流向图 | Phase 4 |
228
+ | **data/** | | |
229
+ | `atool-analysis/data/knowledge-graph.json` | 完整知识图谱(供 aTool Monitor)| Phase 5 |
230
+ | `atool-analysis/data/modules.json` | 模块列表 + 指标 | Phase 5 |
231
+ | `atool-analysis/data/metrics.json` | 质量指标(五维分析)| Phase 5 |
232
+
233
+ ### 机器内部产物(`.atool-docs/`)— 用户无需关心
234
+
235
+ | 路径 | 内容 |
236
+ |------|------|
237
+ | `.atool-docs/analysis-state.json` | Pipeline 状态 |
238
+ | `.atool-docs/pre-scan/*.json` | bash 语法提取(Phase 1)|
239
+ | `.atool-docs/modules/{name}/data.json` | sub-agent 结构化数据(Phase 2)|
240
+ | `.atool-docs/knowledge-graph.json` | 图谱原始数据(Phase 3)|
241
+ | `.atool-docs/multi-dimensional-analysis.json` | 五维分析数据(Phase 3)|
242
+
243
+ **废弃**:不再生成 `docs/101-*.md`、`docs/201-*.md` 等数字命名文件。原 `README.md`、`COMPONENT.md`、`CODE_REVIEW.md` 等项目根目录文件也不再生成(改为 `atool-analysis/` 内对应文件)。
231
244
 
232
245
  ---
233
246
 
234
247
  ## Error Handling
235
248
 
236
249
  - Analysis state file corrupted → warn user, offer fresh start or manual recovery
237
- - Pre-scan failure → graceful degradation: skip Phase 0.5, Phase 1 falls back to full AI extraction (v5.0 behavior)
238
- - Sub-agent fails mid-analysis → mark module as "failed" in state, continue with next module, report in Phase 6
250
+ - Pre-scan failure → graceful degradation: Phase 2 sub-agents 回退到全量 AI 读取源文件
251
+ - Sub-agent fails mid-analysis → mark module as "failed" in state, continue with next module, report in Phase 5 completion summary
239
252
  - Source file read error → skip file, mark in inventory as "unreadable", continue
240
253
  - Disk space insufficient → warn immediately, offer partial save
241
254
  - Resume with changed state version → auto-migrate v3.0/v4.0 → v5.0 (add missing fields with defaults)
@@ -250,7 +263,7 @@ When resuming Phase 5, incrementally update already-generated documents using `<
250
263
  - Output summary report upon completion (modules, files, deliverables)
251
264
  - Each module document must be immediately readable (Zero-KT standard)
252
265
  - Existing CLAUDE.md: only append project rules section
253
- - docs/: only update aTool-numbered files (101, 201-801), never modify user-created docs
266
+ - `atool-analysis/`: only update files generated by aTool analysis, never modify user-created docs
254
267
  - All inferred content marked `[推断]`
255
268
  - UI wireframes: UI projects only (web/mobile)
256
269
  - **Never fabricate**: only record what is visible in code
@@ -261,10 +274,11 @@ When resuming Phase 5, incrementally update already-generated documents using `<
261
274
 
262
275
  | Collaborating Skill | Trigger Condition | Interaction |
263
276
  |---------------------|-------------------|-------------|
264
- | code-review | Phase 4 eight-dimension review | References rules/ files |
265
- | software-architecture | Phase 3a structural layer violation rate >30% | Suggest running |
266
- | {stack}-conventions | Phase 2 deep analysis | Load stack-level conventions |
267
- | doc-standards-enforcer | Phase 5 document generation | Validate frontmatter format |
277
+ | code-review | Phase 4 quality report generation | References rules/ files |
278
+ | software-architecture | Phase 3 structural layer violation rate >30% | Suggest running |
279
+ | {stack}-conventions | Phase 2 module analysis | Load stack-level conventions |
280
+ | doc-standards-enforcer | Phase 4 document generation | Validate frontmatter format |
268
281
  | smart-dispatch | LARGE/XLARGE projects | Batch parallel by module |
269
282
  | project-query | Need to query analysis results | User manually invokes /project-query |
270
- | clarify-before-build | Before Phase 0 user confirmation | Requirement clarification (auto-injected) |
283
+ | requirements-writer | Phase 4 PRD 覆盖率 < 70% | 建议运行,自动进入后向增强模式读取 atool-analysis/ |
284
+ | clarify-before-build | Before Phase 1 user confirmation | Requirement clarification (auto-injected) |
@@ -21,7 +21,7 @@
21
21
 
22
22
  统计源文件数(排除 node_modules, build, .git, vendor, target, dist),按规模选择策略:
23
23
 
24
- | 规模 | 文件数 | 建议深度 | 覆盖率 | 最大 Agent | 多批次 | 说明 |
24
+ | 规模 | 文件数 | 默认深度 | 覆盖率 | 最大 Agent | 多批次 | 说明 |
25
25
  |------|--------|---------|--------|-----------|--------|------|
26
26
  | TINY | 1-50 | L3 | 100% | 5 | 否 | 小项目全量深度分析 |
27
27
  | SMALL | 51-200 | L2 | 100% | 5 | L3+ 自动分批 | 中小项目,L3+ 按模块分批 |
@@ -30,7 +30,9 @@
30
30
  | XLARGE | 1501-5000 | L2 | Top 50% | 5 | L3+ 始终分批 | 核心 L3+,重要 L2,其余 L1 |
31
31
  | MEGA | 5001+ | L2 | 用户选择 | 5 | Wave 策略 | 多波策略,Wave 深度递增 |
32
32
 
33
- **深度覆盖规则**:建议深度为推荐值,用户可在 Phase 0.6 覆盖为任意深度。LARGE/XLARGE 的覆盖率仅影响 L4/L5 深度的模块范围,所有模块至少 L2。
33
+ > **所有项目规模均可使用 L1-L5 任意深度**。上表"默认深度"仅用于回车确认时的默认值,Phase 0.6 必须**始终向用户展示全部 L1-L5 五个选项**。
34
+
35
+ **深度覆盖规则**:上表"默认深度"仅作为回车确认默认值。**用户可在 Phase 0.6 选择 L1-L5 任意深度**。LARGE/XLARGE 的覆盖率仅影响 L4/L5 深度的模块范围,所有模块至少 L2。
34
36
 
35
37
  ### 0.2a 批量派发规则(硬性限制)
36
38
 
@@ -226,6 +228,8 @@ else (中断的分析):
226
228
 
227
229
  ### 0.6 用户确认(必须)
228
230
 
231
+ > **硬性规则:必须向用户展示全部 L1-L5 五个深度选项,不得省略或隐藏任何等级。** 即使项目规模很小,L4 和 L5 也必须出现在选项列表中,让用户做出知情选择。
232
+
229
233
  向用户展示分析计划并获得确认:
230
234
 
231
235
  ```
@@ -10,6 +10,16 @@ Phase 1 现在基于 Phase 0.5 pre-scan 数据工作。AI agent 接收 pre-scan
10
10
 
11
11
  - Phase 0 已完成(`analysis-state.json` 存在,模块列表和 importance 排序已确定)
12
12
 
13
+ ### 前置检查(硬性 — 禁止跳过)
14
+
15
+ 1. 读取 `analysis-state.json`,确认 `phase0_5_prescan.status == "completed"`
16
+ 2. 如果未完成 → **停止 Phase 1**,先执行 Phase 0.5:
17
+ ```bash
18
+ source lib/pre-scan.sh && pre_scan_project "$PROJECT_ROOT" "$PRESCAN_DIR"
19
+ ```
20
+ 3. 读取 `.atool-docs/pre-scan/{module-slug}.json`,确认数据存在
21
+ 4. 如果某个模块的 pre-scan 数据不存在 → 标记 warning,该模块回退到全量 AI 提取
22
+
13
23
  ## 输入数据
14
24
 
15
25
  1. Pre-scan JSON(来自 Phase 0.5)
@@ -6,6 +6,13 @@
6
6
 
7
7
  - Phase 1 已完成(所有 `inventory/{module-slug}.json` 已写入)
8
8
 
9
+ ### 前置检查(硬性)
10
+
11
+ 1. 读取 `analysis-state.json`,确认 `phase1_inventory.status == "completed"`
12
+ 2. 如果未完成 → **停止**,先完成 Phase 1
13
+ 3. 读取 `.atool-docs/inventory/{module-slug}.json`,确认数据存在
14
+ 4. **L1 深度例外**:Phase 1 被跳过(Phase 0.5 替代),此时直接使用 pre-scan 数据
15
+
9
16
  ## 输入数据
10
17
 
11
18
  - Phase 0.5 Pre-Scan 数据:每个文件的 imports/exports/classes/functions/decorators/api_endpoints 已由 grep+awk+jq 提取,AI agent 直接引用,无需重新读取
@@ -15,6 +22,17 @@
15
22
  - 中文件(100-500行):读取全文
16
23
  - 大文件(>500行):仅读取 pre-scan 标记的关键行范围
17
24
 
25
+ ### Pre-scan 降级规则
26
+
27
+ 当 pre-scan 数据或 inventory 数据缺失时(Phase 0.5/1 未执行),sub-agent prompt 必须降级:
28
+
29
+ 1. **pre-scan 数据存在** → 正常三层策略
30
+ 2. **pre-scan 数据缺失** → 全量读取降级:
31
+ - `small_files_list`/`medium_files_list`/`large_files_list` → 全部归入 medium(需全文读取)
32
+ - `prescan_summary_content` → 替换为 `"⚠️ Pre-scan data NOT available. Read ALL source files to extract structural information."`
33
+ - `inventory_semantic_content` → 替换为 `"⚠️ Inventory data NOT available. Extract business context from source files."`
34
+ - 在 sub-agent prompt 末尾追加:`"Pre-scan was skipped. You MUST read all source files first to extract structural info (imports, classes, functions), THEN perform deep analysis."`
35
+
18
36
  ## 详细步骤
19
37
 
20
38
  ### 2.0a 超大模块拆分策略
@@ -84,6 +102,8 @@ else: 按文件扩展名分组
84
102
 
85
103
  ### 2.2b 深度级别指令(追加到 sub-agent prompt 末尾)
86
104
 
105
+ > **硬性规则:必须将对应深度的完整指令内联展开到 `{depth_specific_instructions}` 变量中。禁止用 "执行 L3 分析" 等抽象标签替代具体指令 — sub-agent 不知道 "L3" 意味着什么。**
106
+
87
107
  根据当前分析深度级别,在 sub-agent prompt 模板末尾追加以下指令:
88
108
 
89
109
  #### L1 指令
@@ -9,12 +9,32 @@
9
9
  - Phase 2 已完成(所有 `MODULE-DOC.md` + `analysis.json` 已写入)
10
10
  - Phase 2a(如 depth ≥ L4)和 Phase 2b(如 depth ≥ L5)应已完成
11
11
 
12
+ ### 输入数据检查(硬性 — 禁止跳过)
13
+
14
+ Phase 3 不读取源文件,只处理 JSON 中间产物。开始前必须确认:
15
+
16
+ 1. 读取 `analysis-state.json`,确认 `phase2_deep_analysis.status == "completed"`
17
+ 2. 检查 `.atool-docs/inventory/*.json` 是否存在(Phase 1 输出)
18
+ 3. 检查 `.atool-docs/modules/*/analysis.json` 是否存在(Phase 2 输出)
19
+ 4. 如果以上文件缺失 → **停止 Phase 3**,先完成对应的 Phase 1 或 Phase 2
20
+ 5. **禁止**在缺失中间产物时回退到读取源文件 — 这会导致全量重复读取,违背 pipeline 设计
21
+ 6. 如果 `lib/knowledge-graph.sh` 不存在 → 标记 warning,跳过自动图谱构建,AI 手动从 JSON 数据构建
22
+
12
23
  ## 详细步骤
13
24
 
14
25
  ### 知识图谱构建 (v5.0: 6 步管线)
15
26
 
16
27
  v5.0 使用 `lib/knowledge-graph.sh` 的函数进行构建。**不要手动实现以下算法,全部通过库函数调用。**
17
28
 
29
+ > ⚠️ **硬性指令:必须通过 Bash 工具执行以下命令构建知识图谱。**
30
+ > **禁止用 AI/LLM 直接生成 knowledge-graph.json 内容。**
31
+ > AI 生成的 JSON 格式(如 `modules`/`dependency_edges`)与 `generate-visualization.sh` 期望的 `nodes`/`edges` 格式不兼容,会导致后续可视化、查询和多维分析全部失败。
32
+ >
33
+ > ```bash
34
+ > source lib/knowledge-graph.sh
35
+ > assemble_enhanced_graph "$DOCS_DIR" "$PROJECT_ROOT"
36
+ > ```
37
+
18
38
  1. **节点组装**: 调用 `assemble_enhanced_graph()` — 从 `inventory/*.json` 和 `analysis.json` 读取,支持 14 种节点类型(module, component, function, store, data_entity, api_endpoint, route, config, service, repository, middleware, event, test_suite, layer)
19
39
  2. **边组装**: `assemble_enhanced_graph()` 内部调用 `compute_edge_weights()` — 计算 `base_weight × frequency × confidence`,支持 24 种边类型
20
40
  3. **层确认**: 结合启发式(Phase 0.3a)+ LLM 验证(Phase 2 sub-agent 结果)
@@ -58,6 +78,17 @@ Instability(M) = Ce / (Ca + Ce) // 0=稳定(被依赖), 1=不稳定(依赖
58
78
 
59
79
  写入 `.atool-docs/knowledge-graph.json`:
60
80
 
81
+ **格式校验(硬性 — assemble_enhanced_graph() 完成后必须验证)**:
82
+
83
+ ```bash
84
+ jq '.nodes | length' .atool-docs/knowledge-graph.json # 必须 > 0
85
+ jq '.edges | type' .atool-docs/knowledge-graph.json # 必须是 "array"
86
+ jq '.layers | type' .atool-docs/knowledge-graph.json # 必须是 "object"
87
+ jq '.indexes | type' .atool-docs/knowledge-graph.json # 必须是 "object"
88
+ ```
89
+
90
+ 如果 `nodes` 数组长度为 0 → 说明 `inventory/` 或 `analysis.json` 数据缺失,回到输入数据检查步骤排查。**不要在此情况下用 AI 补充生成节点** — 应修复上游 Phase。
91
+
61
92
  ```json
62
93
  {
63
94
  "version": "5.0",
@@ -6,6 +6,19 @@
6
6
 
7
7
  ## 详细步骤
8
8
 
9
+ > ⚠️ **硬性指令:必须通过 Bash 工具执行以下命令运行五维分析。**
10
+ > **禁止用 AI/LLM 直接生成 multi-dimensional-analysis.json 内容。**
11
+ > AI 生成的格式与后续查询和可视化工具不兼容。
12
+ >
13
+ > ```bash
14
+ > source lib/multi-dimensional-analysis.sh
15
+ > analyze_structural "$DOCS_DIR"
16
+ > analyze_behavioral "$DOCS_DIR"
17
+ > analyze_data "$DOCS_DIR"
18
+ > analyze_quality "$DOCS_DIR"
19
+ > analyze_semantic "$DOCS_DIR"
20
+ > ```
21
+
9
22
  使用 `lib/multi-dimensional-analysis.sh` 执行 5 个独立分析维度:
10
23
 
11
24
  ### 3a.1 结构分析
@@ -83,6 +83,26 @@ Phase 5 incremental flow:
83
83
  g. Generate .atool-docs/visualization/index.html (Cytoscape.js)
84
84
  ```
85
85
 
86
+ > ⚠️ **可视化生成硬性指令(step 6.g)**:必须通过 Bash 工具执行,禁止用 AI/LLM 直接生成 HTML。
87
+ >
88
+ > 前置检查:
89
+ > ```bash
90
+ > jq '.nodes | length' .atool-docs/knowledge-graph.json
91
+ > ```
92
+ > 如果返回 0 → 可视化跳过(knowledge-graph.json 格式错误或数据缺失),在 Phase 6 报告此问题。
93
+ >
94
+ > 生成可视化:
95
+ > ```bash
96
+ > source lib/generate-visualization.sh
97
+ > generate_visualization "$DOCS_DIR"
98
+ > ```
99
+ >
100
+ > 验证输出:
101
+ > ```bash
102
+ > test -f .atool-docs/visualization/index.html && echo "OK" || echo "MISSING"
103
+ > wc -c < .atool-docs/visualization/index.html # 应 > 10KB
104
+ > ```
105
+
86
106
  #### COMPONENT.md 增量标记
87
107
 
88
108
  使用标记包裹每个模块段落,恢复时只替换对应标记内容: