@dtt_siye/atool 1.4.0 → 1.6.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 (42) hide show
  1. package/README.md +97 -214
  2. package/README.md.atool-backup.20260410_114701 +299 -0
  3. package/VERSION +1 -1
  4. package/bin/atool.js +55 -9
  5. package/install.sh +14 -4
  6. package/lib/install-cursor.sh +22 -0
  7. package/lib/install-kiro.sh +26 -2
  8. package/lib/pre-scan.sh +3 -1
  9. package/lib/project-init.sh +28 -9
  10. package/package.json +1 -1
  11. package/skills/ai-project-architecture/SKILL.md +33 -534
  12. package/skills/ai-project-architecture/rules/architecture-validation.md +200 -0
  13. package/skills/ai-project-architecture/rules/compliance-check.md +83 -0
  14. package/skills/ai-project-architecture/rules/iron-laws.md +188 -0
  15. package/skills/ai-project-architecture/rules/migration.md +94 -0
  16. package/skills/ai-project-architecture/rules/refactoring.md +91 -0
  17. package/skills/ai-project-architecture/rules/testing.md +249 -0
  18. package/skills/ai-project-architecture/rules/verification.md +111 -0
  19. package/skills/atool-init/SKILL.md +24 -4
  20. package/skills/clarify-before-build/SKILL.md +33 -0
  21. package/skills/development-pipeline/SKILL.md +168 -0
  22. package/skills/project-analyze/SKILL.md +29 -8
  23. package/skills/project-analyze/phases/phase1-setup.md +61 -4
  24. package/skills/project-analyze/phases/phase2-understand.md +129 -27
  25. package/skills/project-analyze/phases/phase3-graph.md +32 -4
  26. package/skills/project-analyze/prompts/understand-agent.md +156 -298
  27. package/skills/project-analyze/rules/java.md +69 -1
  28. package/skills/project-query/SKILL.md +64 -734
  29. package/skills/project-query/rules/aggregate-stats.md +301 -0
  30. package/skills/project-query/rules/data-lineage.md +228 -0
  31. package/skills/project-query/rules/impact-analysis.md +218 -0
  32. package/skills/project-query/rules/neighborhood.md +234 -0
  33. package/skills/project-query/rules/node-lookup.md +97 -0
  34. package/skills/project-query/rules/path-query.md +135 -0
  35. package/skills/software-architecture/SKILL.md +39 -501
  36. package/skills/software-architecture/rules/concurrency-ha.md +346 -0
  37. package/skills/software-architecture/rules/ddd.md +450 -0
  38. package/skills/software-architecture/rules/decision-workflow.md +155 -0
  39. package/skills/software-architecture/rules/deployment.md +508 -0
  40. package/skills/software-architecture/rules/styles.md +232 -0
  41. package/skills/ui-ux-pro/SKILL.md +69 -0
  42. package/skills/writing-plans/SKILL.md +104 -0
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  name: project-query
3
3
  description: 在需要查询项目分析结果时使用 — 支持节点查找、调用链追踪、影响分析、数据血缘、邻域查询、聚合统计,支持 G1-G5 五级粒度缩放。Use when querying analysis results — supports node lookup, call chain tracing, impact analysis, data lineage, neighborhood queries, aggregate statistics with G1-G5 granularity zooming.
4
- version: 0.2.0
4
+ version: 0.3.0
5
5
  category: quality
6
6
  ---
7
7
 
@@ -9,7 +9,7 @@ category: quality
9
9
 
10
10
  ## 概述
11
11
 
12
- 本 skill 提供对已完成 `project-analyze` 分析的项目进行 **深度交互式查询**。基于 knowledge-graph.json 的完整节点和边数据,支持 6 类强大的查询能力、5 级粒度缩放(G1-G5)、丰富的可视化输出(Mermaid 图、ASCII 树、结构化表格)。
12
+ 本 skill 提供 `/project-analyze` 完成分析后的 **深度交互式查询**。基于 knowledge-graph.json,支持 6 类查询能力、5 级粒度缩放(G1-G5),丰富的可视化输出。
13
13
 
14
14
  **核心价值**:快速回答关于代码结构的复杂问题,无需手工扫描源码。
15
15
 
@@ -20,543 +20,82 @@ category: quality
20
20
  - ✅ L2+ 深度的分析(推荐)— 更多节点和边信息,查询结果更丰富
21
21
  - ⚠️ L1 深度可用但结果只包含模块级节点(无函数、API 等细粒度)
22
22
 
23
- ## 工作原理
23
+ ## When to Use
24
24
 
25
- ```
26
- user query (自然语言或 /command)
27
-
28
- parse query intent (识别查询类型 + 参数)
29
-
30
- load knowledge-graph.json
31
-
32
- apply jq template (执行对应的图查询模板)
33
-
34
- generate output (结构化摘要 + Mermaid 图 + ASCII 视图 + 表格)
35
-
36
- display result (支持 Claude Code / Cursor / 终端)
37
- ```
25
+ - **节点查找**:寻找特定函数、类、模块、API 端点
26
+ - `/find functions named createUser`
27
+ - `/find classes in auth module`
28
+ - `/find modules with importance > 0.7`
38
29
 
39
- ## 查询类别
30
+ - **路径查询**:追踪两个节点之间的调用链或依赖链
31
+ - `/show call path from A to B`
32
+ - `/show dependency path from module-auth to module-api`
40
33
 
41
- ### 1. 节点查找 (Node Lookup)
34
+ - **影响分析**:评估修改某个节点的风险和影响范围
35
+ - `/what if I modify User entity`
36
+ - `/impact of changing AuthService`
37
+ - `/change analysis for database schema`
42
38
 
43
- 快速查找特定的函数、类、模块、API 端点等。
39
+ - **数据血缘**:追踪数据实体从源头到终点的完整流向
40
+ - `/trace data lineage of Order entity`
41
+ - `/where does User data flow`
44
42
 
45
- **用户指令**:
46
- ```
47
- /find functions named createUser
48
- /find classes in auth module
49
- /find all API endpoints
50
- /find modules with importance > 0.7
51
- /find data_entity named User
52
- ```
43
+ - **邻域查询**:查看某个节点周围 N 跳的所有直接和间接关联
44
+ - `/neighbors of AuthService within 2 hops`
45
+ - `/what's connected to UserController`
53
46
 
54
- **执行步骤**:
55
- 1. 解析查询中的 **type** **label** 约束
56
- 2. 读取 `knowledge-graph.json` `nodes` 数组
57
- 3. `type`(精确或模糊)和 `label`(子串匹配,不分大小写)过滤
58
- 4. 按 `importance` 降序排序,限制 top 20(避免过多结果)
59
- 5. 生成输出表格
47
+ - **聚合查询**:按各种度量指标排序和统计节点
48
+ - `/top 10 most complex functions`
49
+ - `/modules ranked by importance`
50
+ - `/functions with cyclomatic_complexity > 10`
60
51
 
61
- **输出示例**:
62
- ```
63
- ## Query Result: Node Lookup
52
+ ## Quick Workflow
64
53
 
65
- Found 5 nodes matching: type=function, label contains "create"
54
+ 1. **识别查询类型** 确定要执行的查询:节点、路径、影响、数据流、邻域或聚合
55
+ 2. **准备输入参数** — 确定查询的源节点、目标节点、过滤条件、粒度级别(G1-G5)
56
+ 3. **执行查询** — 读取 knowledge-graph.json,应用对应查询模板
57
+ 4. **生成结果** — 返回结构化摘要 + Mermaid 图 + ASCII 视图 + 详细表格
58
+ 5. **解释洞察** — 提供分析建议和下一步操作
66
59
 
67
- | ID | Label | Path | Type | Importance | Metrics |
68
- |----|-------|------|------|------------|---------|
69
- | func:UserService.createUser | createUser | src/services/UserService.ts | function | 0.85 | CC: 3, Lines: 42 |
70
- | func:OrderService.createOrder | createOrder | src/services/OrderService.ts | function | 0.72 | CC: 5, Lines: 68 |
71
- | ... | | | | | |
72
- ```
60
+ ## File Reference Map
73
61
 
74
- **jq 实现**:参考 `rules/query-templates.md` Template 1
62
+ | File | When to Read | Content |
63
+ |------|-------------|---------|
64
+ | `rules/node-lookup.md` | 查找特定代码元素时 | 节点查找的详细步骤、jq 实现、用户指令示例 |
65
+ | `rules/path-query.md` | 追踪调用链或依赖链时 | 路径查询算法、边类型支持、调用链可视化 |
66
+ | `rules/impact-analysis.md` | 评估修改风险时 | 风险评分公式、影响范围统计、测试建议 |
67
+ | `rules/data-lineage.md` | 理解数据流向时 | 数据流追踪算法、流向图生成、流量计算 |
68
+ | `rules/neighborhood.md` | 分析节点关联时 | BFS 邻域算法、粒度级别过滤、关系统计 |
69
+ | `rules/aggregate-stats.md` | 按指标排序统计时 | 支持的度量指标、过滤条件、风险等级判断 |
75
70
 
76
- ### 2. 路径查询 (Path Query)
71
+ ## Constraints
77
72
 
78
- 追踪两个节点之间的调用链或依赖链。
73
+ - 必须先运行 `/project-analyze` 生成 knowledge-graph.json
74
+ - 查询失败时使用 `/find` 确认节点存在
75
+ - 复杂查询(如 G5)可能需要长时间,建议降低粒度
76
+ - 某些度量需要 L2+ 深度,如结果缺失请重新运行更深的分析
79
77
 
80
- **用户指令**:
81
- ```
82
- /show call path from UserController.createUser to Database.save
83
- /show dependency path from module-auth to module-api
84
- /show import chain from A to B
85
- ```
86
-
87
- **执行步骤**:
88
- 1. 解析 source 和 target 节点标识符
89
- 2. 在 knowledge-graph 中定位两个节点 ID
90
- 3. 根据查询类型选择遍历的边类型:
91
- - `call path` → 沿 `calls` + `calls_async` 边
92
- - `dependency path` → 沿 `depends_on` 边
93
- - 其他 → 沿所有相关边类型
94
- 4. 执行有向 BFS(广度优先搜索)找到最短路径
95
- 5. 如有多条路径,返回所有(最多 5 条,按路径长度排序)
96
- 6. 生成 Mermaid `graph LR` 有向图
97
-
98
- **输出示例**:
99
- ```
100
- ## Query Result: Call Path
101
-
102
- Source: UserController.createUser
103
- Target: Database.save
104
-
105
- ### Path 1 (3 hops) ✅ SHORTEST
106
-
107
- UserController.createUser
108
- --calls--> UserService.validateData
109
- --calls--> Validator.checkEmail
110
- --calls--> Database.save
111
-
112
- ### Mermaid Diagram
113
-
114
- graph LR
115
- A["UserController.createUser"] -->|calls| B["UserService.validateData"]
116
- B -->|calls| C["Validator.checkEmail"]
117
- C -->|calls| D["Database.save"]
118
- style A fill:#90EE90
119
- style D fill:#FFB6C1
120
- ```
121
-
122
- **jq 实现**:参考 `rules/query-templates.md` Template 2
123
-
124
- ### 3. 影响分析 (Impact Analysis)
125
-
126
- 分析修改某个节点可能影响的其他部分,以及风险等级。
127
-
128
- **用户指令**:
129
- ```
130
- /what if I modify User entity
131
- /impact of changing AuthService
132
- /change analysis for database schema
133
- ```
134
-
135
- **执行步骤**:
136
- 1. 定位目标节点 X
137
- 2. 反向查询所有指向 X 的边(反向依赖):
138
- - `depends_on`、`calls`、`reads_from`、`reads_state`、`implements`、`extends`
139
- 3. 对找到的每个直接依赖节点 D,继续反向追踪(递归,最多 3 层)
140
- 4. 计算风险评分公式:
141
- ```
142
- risk_score = Σ (importance(D) × edge_weight(D→X)) 对所有直接依赖者
143
- ```
144
- 5. 风险等级判断:
145
- - `risk_score > 0.7` → **🔴 HIGH RISK**(红色)
146
- - `0.3 < risk_score ≤ 0.7` → **🟠 MEDIUM RISK**(橙色)
147
- - `risk_score ≤ 0.3` → **🟢 LOW RISK**(绿色)
148
- 6. 统计影响范围:受影响的模块数、函数数、API 端点数、数据实体数
149
- 7. 按粒度级别生成 Mermaid 图
150
- 8. 输出建议的测试范围(涉及的单元测试、集成测试、E2E 测试)
151
-
152
- **输出示例**:
153
- ```
154
- ## Query Result: Impact Analysis
155
-
156
- Target: data_entity:User
157
-
158
- **Risk Assessment**: 🔴 HIGH (0.84)
159
-
160
- ### Direct Dependents (1-hop)
161
- - func:AuthService.validateUser (importance: 0.9, risk: HIGH)
162
- - func:OrderService.processOrder (importance: 0.8, risk: HIGH)
163
-
164
- ### Transitive Dependents (2-hop)
165
- - module:api (affected functions: 4)
166
- - module:payment (affected functions: 2)
167
-
168
- ### Impact Summary
169
- | Category | Count | Risk Level |
170
- |----------|-------|-----------|
171
- | Modules | 5 | HIGH |
172
- | Functions | 23 | HIGH |
173
- | API Endpoints | 3 | MEDIUM |
174
- | Data Entities | 2 | LOW |
175
-
176
- ### Recommended Testing
177
- - [ ] Unit tests for AuthService, OrderService
178
- - [ ] Integration tests for api module
179
- - [ ] E2E tests for user creation, order flow
180
- ```
181
-
182
- **jq 实现**:参考 `rules/query-templates.md` Template 3
183
-
184
- ### 4. 数据血缘 (Data Lineage)
185
-
186
- 追踪某个数据实体从源头到终点的完整流向。
187
-
188
- **用户指令**:
189
- ```
190
- /trace data lineage of Order entity
191
- /where does User data flow
192
- /data flow for Payment status
193
- ```
194
-
195
- **执行步骤**:
196
- 1. 定位数据实体节点 D(type = `data_entity`)
197
- 2. **反向追踪**(来源 Upstream):
198
- - 沿 `writes_to`、`writes_state` 边反向查找所有写入 D 的函数
199
- - 继续追踪这些函数的输入来源
200
- - 直到找到边界节点(API、user_input、scheduled_task)
201
- 3. **正向追踪**(去向 Downstream):
202
- - 沿 `reads_from`、`reads_state`、`transforms` 边正向查找所有读取 D 的函数
203
- - 继续追踪这些函数的输出流向
204
- - 直到找到最终汇聚点(database、external_api、log)
205
- 4. 计算数据流速率(flow_rate):
206
- ```
207
- flow_rate = count(writers) × count(readers) × avg_transformation_steps
208
- ```
209
- 5. 生成 Mermaid `graph TD` 数据流图,包括:
210
- - 数据节点(蓝色高亮)
211
- - 处理函数(绿色)
212
- - 外部系统(灰色)
213
- - 每条边标注操作类型(read/write/transform/persist)
214
-
215
- **输出示例**:
216
- ```
217
- ## Query Result: Data Lineage
218
-
219
- Target: data_entity:Order
220
-
221
- ### Upstream (Data Sources)
222
- api:POST/orders
223
- --creates--> func:OrderService.createOrder
224
- --writes_to--> data_entity:Order
225
-
226
- ### Processing (Transformations)
227
- func:OrderService.createOrder
228
- --transforms--> func:PaymentService.calculateTotal
229
- --transforms--> func:ShippingService.estimateDelivery
230
-
231
- ### Downstream (Data Sinks)
232
- data_entity:Order
233
- --reads_from--> func:OrderService.getOrders
234
- --returns--> api:GET/orders/{id}
235
-
236
- --persists_to--> database:PostgreSQL
237
-
238
- ### Data Flow Metrics
239
- - Writers: 2 functions
240
- - Readers: 5 functions
241
- - Transformations: 3 steps
242
- - Flow Rate: 30 (very high activity)
243
- ```
244
-
245
- **jq 实现**:参考 `rules/query-templates.md` Template 4
246
-
247
- ### 5. 邻域查询 (Neighborhood)
248
-
249
- 查看某个节点周围 N 跳的所有直接和间接关联。
250
-
251
- **用户指令**:
252
- ```
253
- /neighbors of AuthService within 2 hops
254
- /what's connected to UserController
255
- /neighborhood of Order module (depth=3)
256
- ```
257
-
258
- **执行步骤**:
259
- 1. 定位焦点节点 F
260
- 2. 构建双向邻接表(边无向化,忽略方向)
261
- 3. 迭代 BFS 展开 N 跳(默认 2,最大 5):
262
- - Hop 0:焦点节点 F 本身
263
- - Hop 1:F 的直接邻居
264
- - Hop 2:邻居的邻居(排除已访问)
265
- - Hop 3:再往外一层
266
- - ...
267
- 4. 按粒度级别过滤节点/边类型(G1-G5)
268
- 5. 按关系类型分组统计邻域结构
269
-
270
- **输出示例**:
271
- ```
272
- ## Query Result: Neighborhood Query
273
-
274
- Focus: module:auth
275
- Depth: 2 hops
276
-
277
- ### Hop 1 - Direct Neighbors (4 nodes)
278
- - module:core (depends_on, depends_on)
279
- - module:user (implements, depends_on)
280
- - service:jwt (uses)
281
-
282
- ### Hop 2 - Secondary Neighbors (6 nodes)
283
- - module:api (depends_on via core)
284
- - module:database (depends_on via core)
285
- - function:validateToken (calls via jwt)
286
-
287
- ### Relationship Summary
288
- | Relationship Type | Count | Nodes Affected |
289
- |------------------|-------|----------------|
290
- | depends_on | 3 | 4 |
291
- | calls | 2 | 3 |
292
- | implements | 1 | 2 |
293
- | uses | 1 | 1 |
294
-
295
- ### Neighborhood Graph (Mermaid)
296
- graph TD
297
- auth[("🎯 module:auth")]
298
- core["module:core"]
299
- user["module:user"]
300
- jwt["service:jwt"]
301
-
302
- auth -->|depends_on| core
303
- auth -->|implements| user
304
- auth -->|uses| jwt
305
-
306
- core -->|depends_on| api["module:api"]
307
- core -->|depends_on| db["module:database"]
308
- ```
309
-
310
- **jq 实现**:参考 `rules/query-templates.md` Template 5
311
-
312
- ### 6. 聚合查询 (Aggregate)
313
-
314
- 按各种度量指标排序和统计节点。用于快速识别高风险、高复杂度、高耦合等关键问题点。
315
-
316
- **用户指令**:
317
- ```
318
- /top 10 most complex functions
319
- /modules ranked by importance
320
- /which module has highest coupling
321
- /functions with cyclomatic_complexity > 10
322
- /show all nodes with criticality CRITICAL
323
- ```
324
-
325
- **支持的度量指标**:
326
-
327
- | 度量类别 | 可用指标 | 解释 |
328
- |---------|---------|------|
329
- | **复杂度** | cyclomatic_complexity | 圈复杂度(>10 为高风险) |
330
- | | halstead_volume | 代码体积(>8 为大) |
331
- | | lines_of_code | 函数行数 |
332
- | **耦合** | coupling (Ca) | 传入耦合(有多少依赖我) |
333
- | | coupling (Ce) | 传出耦合(我依赖多少) |
334
- | | instability (I) | 不稳定性 (Ce/(Ca+Ce)) |
335
- | **重要性** | importance | 综合重要性评分 (0-1) |
336
- | **质量** | maintainability_index | 可维护性指数 |
337
- | | technical_debt_ratio | 技术债占比 |
338
- | **中心性** | betweenness_centrality | 介数中心性(关键路由节点) |
339
- | | in_degree | 入度(被依赖次数) |
340
- | | out_degree | 出度(依赖他人次数) |
341
- | **数据流** | flow_rate | 数据流量 |
342
- | | schema_coupling | 数据耦合度 |
343
-
344
- **执行步骤**:
345
- 1. 解析查询条件:目标度量、排序方向(升/降)、数量限制(top N)、过滤条件
346
- 2. 从 knowledge-graph.json 加载所有节点及其 metrics
347
- 3. 应用过滤条件(如 complexity > 10)
348
- 4. 按指定度量排序
349
- 5. 取 top N(默认 10,最大 50)
350
- 6. 生成柱状图(ASCII 或 Mermaid)和排序表格
351
-
352
- **输出示例**:
353
- ```
354
- ## Query Result: Aggregate Metrics
355
-
356
- Query: Top 10 Functions by Cyclomatic Complexity
357
-
358
- ### Results (Sorted by cyclomatic_complexity DESC)
359
-
360
- | Rank | Function | CC | Lines | Risk Level |
361
- |------|----------|----|----|------------|
362
- | 1 | OrderService.processOrder | 23 | 342 | 🔴 CRITICAL |
363
- | 2 | PaymentService.validatePayment | 18 | 267 | 🔴 HIGH |
364
- | 3 | AuthService.authenticate | 14 | 198 | 🟠 MEDIUM |
365
- | 4 | UserService.createUser | 9 | 156 | 🟢 LOW |
366
- | ... | | | | |
367
-
368
- ### ASCII Chart
369
-
370
- cyclomatic_complexity distribution:
371
- OrderService.processOrder |██████████████████████ 23
372
- PaymentService.validatePayment |██████████████████ 18
373
- AuthService.authenticate |██████████████ 14
374
- UserService.createUser |█████████ 9
375
- ShippingService.estimateDelivery |████████ 8
376
- ...
377
-
378
- ### Statistics
379
- - Mean CC: 8.2
380
- - Median CC: 7
381
- - Max CC: 23 (OrderService.processOrder)
382
- - Functions with CC > 10: 3 (HIGH RISK)
383
-
384
- ### Recommendations
385
- - Refactor OrderService.processOrder (consider splitting into 3-4 functions)
386
- - Add comprehensive tests for PaymentService.validatePayment
387
- - Monitor AuthService.authenticate for future complexity growth
388
- ```
389
-
390
- **jq 实现**:参考 `rules/query-templates.md` Template 6
391
-
392
- ## 粒度缩放 (Zoom Level G1-G5)
393
-
394
- 查询时通过 `zoom` 或 `G` 参数控制结果粒度,从高层架构到低层细节:
395
-
396
- | 缩放级别 | 可见节点类型 | 可见边类型 | 用途 | 典型查询 |
397
- |---------|------------|-----------|------|---------|
398
- | **G1** (System) | `module`、`layer` | `depends_on` | 高层架构视图 | /top modules by importance (G1) |
399
- | **G2** (Module) | G1 + `class`、`service`、`store`、`interface` | G1 + `implements`、`extends`、`belongs_to` | 模块内部结构 | /neighborhood of auth module (G2) |
400
- | **G3** (Function) | G2 + `function`、`api_endpoint`、`route`、`hook` | G2 + `calls`、`calls_async`、`returns`、`sends_http` | 调用链追踪 | /show call path from A to B (G3) |
401
- | **G4** (Data) | G3 + `data_entity` | G3 + `reads_from`、`writes_to`、`transforms`、`validates`、`reads_state`、`writes_state` | 数据流分析 | /trace data lineage of User (G4) |
402
- | **G5** (Cross-cutting) | 所有 14 种节点类型 | 所有 24 种边类型 | 全景分析 | /impact analysis of core module (G5) |
403
-
404
- **缩放机制**:
405
- 1. 用户指定粒度(默认 G2)
406
- 2. 根据粒度级别过滤 nodes 类型集合
407
- 3. 根据粒度级别过滤 edges 类型集合
408
- 4. 应用 BFS 或 DFS 算法
409
- 5. 返回过滤后的子图
410
-
411
- **使用示例**:
412
- ```bash
413
- # 系统级概览(只看模块和层)
414
- /top modules by importance (zoom=G1)
415
-
416
- # 模块级细节(看类和接口)
417
- /neighborhood of auth (zoom=G2)
418
-
419
- # 函数级调用链
420
- /show call path from UserController.create to UserService.save (zoom=G3)
421
-
422
- # 数据流(包括数据实体)
423
- /trace data lineage of Order (zoom=G4)
424
-
425
- # 完整全景
426
- /impact analysis of User entity (zoom=G5)
427
- ```
78
+ > IMPORTANT: When this skill is invoked, you MUST read the relevant
79
+ > subdirectory files based on the user's query type. Do NOT attempt to execute
80
+ > this skill using only this SKILL.md content.
428
81
 
429
82
  ## 输出格式
430
83
 
431
- 每个查询结果包含以下部分(根据查询类型有所不同):
432
-
433
- ### 1. 结构化摘要
434
- ```markdown
435
- ## Query Result: Impact Analysis on User entity
436
-
437
- **Risk Level**: 🔴 HIGH (0.82)
438
- **Affected Modules**: 5
439
- **Affected Functions**: 23
440
- **Affected APIs**: 3
441
- **Affected Data Entities**: 2
442
-
443
- ### Key Insights
444
- - Most critical: AuthService, OrderService
445
- - Highest risk path: User → AuthService → PaymentService
446
- ```
447
-
448
- ### 2. Mermaid 可视化
449
- 根据查询类型生成对应的图表:
450
- - **路径查询** → `graph LR`(从左到右的有向链)
451
- - **影响分析** → `graph TD`(从上到下的辐射树,颜色表示风险等级)
452
- - **数据血缘** → `graph TD`(数据流向图,高亮数据节点)
453
- - **邻域查询** → `graph TD`(星形或树形拓扑)
454
- - **聚合查询** → ASCII 柱状图 + 表格
455
-
456
- ### 3. ASCII 视图(终端兼容)
457
- ```
458
- UserController.create()
459
- --[calls]--> UserService.createUser()
460
- --[calls]--> UserRepository.save()
461
- --[persists_to]--> [DB: users]
462
-
463
- Tree format:
464
- ┌─ UserController.create() [importance: 0.8, CC: 5]
465
- │ └─ UserService.createUser() [importance: 0.7, CC: 8]
466
- │ └─ UserRepository.save() [importance: 0.6, CC: 3]
467
- ```
84
+ 每个查询结果包含:
85
+ - **结构化摘要**:查询类型、关键指标、数量统计
86
+ - **Mermaid 可视化**:根据查询类型生成相应图表
87
+ - **ASCII 视图**:终端兼容的文本视图
88
+ - **详细表格**:完整数据表格
89
+ - **建议和洞察**:风险提示、优化建议、下一步行动
468
90
 
469
- ### 4. 详细表格
470
- ```markdown
471
- | 节点 ID | 节点名 | 类型 | 重要性 | 度量值 | 关系 |
472
- |--------|--------|------|--------|--------|------|
473
- | func:A.create | A.create | function | 0.8 | CC: 5 | calls |
474
- | func:B.validate | B.validate | function | 0.7 | CC: 8 | calls_async |
475
- ```
91
+ ## 粒度缩放
476
92
 
477
- ### 5. 建议和洞察
478
- ```markdown
479
- ### Recommendations
480
- - 🔴 CRITICAL: Refactor OrderService (CC=23)
481
- - 🟠 HIGH: Add integration tests for auth module
482
- - 🟢 LOW: Monitor UserService for future changes
483
- ```
484
-
485
- ## 多维分析查询(需要 Multi-Dimensional Analysis)
486
-
487
- 如果 `.atool-docs/multi-dimensional-analysis.json` 存在(project-analyze Phase 3 输出),还可以进行高级多维分析查询:
488
-
489
- ### 5 维分析框架
490
-
491
- | 维度 | 关注点 | 查询示例 |
492
- |------|--------|---------|
493
- | **结构维** | 模块划分、依赖拓扑、分层遵循 | `/show structural analysis results` |
494
- | **行为维** | 调用关系、数据流、控制流 | `/show call graph hotspots` |
495
- | **数据维** | 数据流向、数据耦合、数据质量 | `/show data flow hotspots` |
496
- | **质量维** | 复杂度、重复代码、技术债 | `/show quality metrics summary` |
497
- | **语义维** | 业务术语、领域对象、业务规则 | `/show domain vocabulary` |
498
-
499
- ### 查询命令
500
-
501
- ```bash
502
- # 结构分析
503
- /show structural analysis results
504
- /find layering violations
505
- /detect circular dependencies (depth=3)
506
-
507
- # 行为分析
508
- /show call graph hotspots (top=10)
509
- /trace control flow for OrderService
510
- /find execution bottlenecks
511
-
512
- # 数据分析
513
- /show data flow hotspots
514
- /trace data dependencies across modules
515
- /find schema coupling issues
516
-
517
- # 质量分析
518
- /show quality metrics summary
519
- /find code smell clusters
520
- /show technical debt hotspots (sorted=desc, limit=20)
521
-
522
- # 语义分析
523
- /show domain vocabulary
524
- /extract business concepts
525
- /map entity relationships
526
- ```
527
-
528
- ### 输出示例
529
-
530
- ```markdown
531
- ## Multi-Dimensional Analysis: Quality Metrics
532
-
533
- ### 质量维 Quality Dimension
534
- - Average Cyclomatic Complexity: 6.2
535
- - Hotspots (CC > 10): 5 functions
536
- - Duplicate Code Blocks: 23 instances (~12% code duplication)
537
- - Technical Debt Ratio: 15.3% (MEDIUM)
538
-
539
- ### 结构维 Structure Dimension
540
- - Modules: 8 (avg 3.2 imports per module)
541
- - Layering Violations: 0 ✅
542
- - Circular Dependencies: 0 ✅
543
- - Stability Index: 0.62 (MODERATE)
544
-
545
- ### 行为维 Behavior Dimension
546
- - Call Graph Diameter: 7 hops
547
- - Hottest Call Paths: OrderService → PaymentService → Database
548
- - Async Calls: 12% of total
549
-
550
- ### 数据维 Data Dimension
551
- - Data Entities: 14
552
- - Schema Coupling: 0.41 (MODERATE)
553
- - Data Flow Hotspots: User → Order → Payment (3-hop flow)
554
-
555
- ### 语义维 Semantic Dimension
556
- - Domain Concepts: auth, order, payment, shipping
557
- - Entity Mapping: User → Order (1:many), Order → Payment (1:1)
558
- - Business Rules: 23 detected
559
- ```
93
+ 通过 `zoom` 或 `G` 参数控制结果粒度:
94
+ - **G1** (System):模块、层的高层架构视图
95
+ - **G2** (Module):模块内部结构,包含类、服务
96
+ - **G3** (Function):调用链,包含函数、API 端点
97
+ - **G4** (Data):数据流,包含数据实体
98
+ - **G5** (Cross-cutting):全部分析,所有节点和边类型
560
99
 
561
100
  ## Skill 协作
562
101
 
@@ -566,220 +105,11 @@ Tree format:
566
105
  | **code-review** | 影响分析显示代码质量问题 | 建议运行 — 用于深度代码质量评分 |
567
106
  | **software-architecture** | 影响分析显示架构违反 | 建议运行 — 用于架构重构或规范化 |
568
107
 
569
- ## 最佳实践和使用场景
570
-
571
- ### 场景 1: 新人快速上手(30 分钟)
572
- ```bash
573
- # Step 1: 了解项目全貌
574
- /top modules by importance (zoom=G1)
575
-
576
- # Step 2: 深入核心模块
577
- /neighborhood of core module (depth=2, zoom=G2)
578
-
579
- # Step 3: 追踪关键数据流
580
- /trace data lineage of User (zoom=G4)
581
- ```
582
-
583
- ### 场景 2: 评估修改风险
584
- ```bash
585
- # 修改某个函数前
586
- /impact of changing UserService.updateProfile
587
-
588
- # 修改某个数据模型前
589
- /what if I modify Order entity
590
-
591
- # 推荐的测试范围会自动生成
592
- ```
593
-
594
- ### 场景 3: 识别技术债
595
- ```bash
596
- # 查找最复杂的函数
597
- /top 20 functions by cyclomatic_complexity
598
-
599
- # 查找最高耦合的模块
600
- /modules ranked by coupling (sorted=desc, limit=10)
601
-
602
- # 查找技术债占比最高的
603
- /nodes with technical_debt_ratio > 0.3
604
- ```
605
-
606
- ### 场景 4: 架构审查
607
- ```bash
608
- # 整个系统的依赖拓扑
609
- /show all modules and dependencies (zoom=G1)
610
-
611
- # 检测循环依赖
612
- /find circular dependencies
613
-
614
- # 验证分层原则
615
- /check layering violations
616
- ```
617
-
618
- ## 错误处理和故障排除
108
+ ## 错误处理
619
109
 
620
110
  | 错误 | 原因 | 解决方案 |
621
111
  |------|------|--------|
622
- | `knowledge-graph.json not found` | 项目未分析 | 运行 `/project-analyze` 完成初始分析 |
623
- | `node not found` | 查询的节点不存在 | 使用 `/find` 查询节点确切名称,或用模糊搜索 |
112
+ | `knowledge-graph.json not found` | 项目未分析 | 运行 `/project-analyze` |
113
+ | `node not found` | 查询的节点不存在 | 使用 `/find` 查询节点确切名称 |
624
114
  | `no results` | 查询条件过严格 | 放松过滤条件,或提升分析深度(L3+) |
625
- | `metric not available` | 该度量在此分析深度不存在 | 某些度量需要 L2+ 深度,重新运行更深的分析 |
626
- | `timeout` | 查询太复杂(如 G5 的大图) | 降低粒度级别(G5 → G3),或限制查询范围 |
627
-
628
- **快速故障排除流程**:
629
- ```
630
- Query fails?
631
- ├─ Check if knowledge-graph.json exists
632
- │ └─ No → Run /project-analyze
633
- ├─ Check if node/metric names are correct
634
- │ └─ No → Use /find to search
635
- ├─ Check if analysis depth is sufficient
636
- │ └─ L1 → Rerun with L2+ for more detail
637
- └─ Check if zoom level is appropriate
638
- └─ Too detailed → Lower granularity
639
- ```
640
-
641
- ## 高级技巧
642
-
643
- ### 1. 导出查询结果
644
- 所有查询结果都支持导出为 JSON/CSV:
645
- ```bash
646
- /find functions named "create*" (export=json)
647
- # 输出标准 JSON,可用 jq 处理
648
- ```
649
-
650
- ### 2. 保存查询模板
651
- 频繁使用的查询可保存为别名:
652
- ```bash
653
- /alias weekly-review = "top 10 modules by importance (G1) + top 20 functions by cyclomatic_complexity"
654
- /weekly-review # 一键执行
655
- ```
656
-
657
- ### 3. 比较两个分析结果
658
- ```bash
659
- # 对比两个不同版本的项目
660
- /compare analysis v1 vs v2 (metric=cyclomatic_complexity)
661
- # 输出:哪些函数变得更复杂、哪些模块耦合度增加等
662
- ```
663
-
664
- ### 4. 生成质量报告
665
- ```bash
666
- /generate report (title="Project Quality Review", include=["complexity", "coupling", "risk"])
667
- # 输出一份综合报告,含图表和建议
668
- ```
669
-
670
- ---
671
-
672
- ## 快速参考表
673
-
674
- ### 6 类查询速查
675
-
676
- | 查询类型 | 命令示例 | 适用场景 | 输出 |
677
- |---------|---------|---------|------|
678
- | **节点查找** | `/find functions named "create*"` | 查找特定代码元素 | 表格 + 重要性排序 |
679
- | **路径查询** | `/show call path from A to B` | 追踪调用链或依赖链 | Mermaid 图 + ASCII 树 |
680
- | **影响分析** | `/what if I modify User entity` | 评估修改风险 | 风险评分 + 影响范围 + 测试建议 |
681
- | **数据血缘** | `/trace data lineage of Order` | 理解数据流向 | 上游/处理/下游 + Mermaid 图 |
682
- | **邻域查询** | `/neighbors of AuthService (depth=2)` | 理解节点关联 | 星形/树形拓扑 + 关系统计 |
683
- | **聚合查询** | `/top 10 functions by cyclomatic_complexity` | 识别风险点 | 排序表格 + ASCII 柱状图 |
684
-
685
- ### 粒度级别速查
686
-
687
- | 级别 | 用途 | 典型查询 |
688
- |------|------|---------|
689
- | **G1** | 系统级架构 | `/top modules by importance (G1)` |
690
- | **G2** | 模块结构 | `/neighborhood of core (G2)` |
691
- | **G3** | 调用链 | `/show call path A→B (G3)` |
692
- | **G4** | 数据流 | `/trace data lineage (G4)` |
693
- | **G5** | 全景分析 | `/impact analysis (G5)` |
694
-
695
- ### 常用度量指标速查
696
-
697
- | 度量 | 含义 | 高风险阈值 |
698
- |------|------|-----------|
699
- | `cyclomatic_complexity` | 圈复杂度 | > 10 |
700
- | `halstead_volume` | 代码体积 | > 8 |
701
- | `lines_of_code` | 代码行数 | > 200 |
702
- | `coupling (Ce)` | 传出耦合 | > 0.7 |
703
- | `instability (I)` | 不稳定性 | > 0.8 |
704
- | `importance` | 综合重要性 | > 0.8 |
705
- | `technical_debt_ratio` | 技术债占比 | > 0.2 |
706
- | `betweenness_centrality` | 关键度(枢纽) | > 0.5 |
707
-
708
- ---
709
-
710
- ## 完整工作流示例
711
-
712
- ### 场景:重构一个遗留项目
713
-
714
- ```bash
715
- # Step 1: 了解全局架构(5分钟)
716
- /top modules by importance (zoom=G1)
717
- # 识别核心模块和边界模块
718
-
719
- # Step 2: 深入高风险模块(10分钟)
720
- /top 10 functions by cyclomatic_complexity
721
- # 找出最复杂的函数,优先重构
722
-
723
- # Step 3: 分析重构影响范围(5分钟)
724
- /impact of changing OrderService.processOrder
725
- # 评估修改风险,确定测试范围
726
-
727
- # Step 4: 验证架构约束(3分钟)
728
- /find circular dependencies
729
- /find layering violations
730
- # 确保重构后不引入新的架构问题
731
-
732
- # Step 5: 生成交付物(2分钟)
733
- /generate report (title="Refactoring Plan", include=["complexity", "risk", "dependencies"])
734
- # 生成可交付的分析报告
735
- ```
736
-
737
- ### 场景:新人代码审查
738
-
739
- ```bash
740
- # 新人需要 review UserService,但不知道从何下手
741
-
742
- # Step 1: 理解 UserService 的职责
743
- /show definition of UserService
744
- /neighborhood of UserService (depth=1, G2)
745
- # 知道它依赖谁,谁依赖它
746
-
747
- # Step 2: 追踪关键调用链
748
- /show call path from UserController.createUser to UserRepository.save
749
- # 理解整个流程
750
-
751
- # Step 3: 确认数据流
752
- /trace data lineage of User entity
753
- # 知道 User 数据怎么来的、流向哪里
754
-
755
- # Step 4: 评估修改风险
756
- /impact of changing UserService.validateEmail
757
- # 确定这个修改会影响哪些测试用例
758
-
759
- # 现在新人可以自信地进行 review 了!
760
- ```
761
-
762
- ---
763
-
764
- ## FAQ
765
-
766
- **Q: 我的项目有 500+ 文件,是否支持?**
767
- A: 完全支持。使用 L1 分析快速了解全貌(<2分钟),或用粒度缩放(G1)查看模块级视图。
768
-
769
- **Q: Query Panel 和 code-review 有什么区别?**
770
- A: code-review 专注代码质量分析(8维度评分),project-query 专注**结构和关系分析**(路径、影响、数据流)。通常配合使用。
771
-
772
- **Q: 怎样处理查询结果太多的情况?**
773
- A: 使用 `limit`、`filter`、`zoom` 参数缩小范围。例如 `/top 50 functions ... (limit=10, zoom=G2)`。
774
-
775
- **Q: 支持导出为什么格式?**
776
- A: 支持 JSON(标准格式,可用 jq 处理)、CSV(电子表格)、HTML(报告)、PDF(文档)。
777
-
778
- ---
779
-
780
- ## 相关资源
781
-
782
- - **Project Analyze Guide**:`docs/14-project-analyze-guide.md`
783
- - **Query Templates**:`rules/query-templates.md`(jq 实现细节)
784
- - **Knowledge Graph Schema**:`lib/knowledge-graph.sh`(节点/边定义)
785
- - **Multi-Dimensional Analysis**:`lib/multi-dimensional-analysis.sh`(五维分析算法)
115
+ | `timeout` | 查询太复杂 | 降低粒度级别(G5 G3),限制查询范围 |