@dtt_siye/atool 1.3.1 → 1.5.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 (56) 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/hooks/doc-sync-reminder +4 -4
  6. package/hooks/hooks-cursor.json +20 -0
  7. package/hooks/hooks.json +21 -1
  8. package/hooks/pre-commit +191 -0
  9. package/hooks/prompt-guard +84 -35
  10. package/hooks/session-start +34 -12
  11. package/hooks/task-state-tracker +145 -0
  12. package/install.sh +14 -4
  13. package/lib/common.sh +36 -23
  14. package/lib/compute-importance.sh +73 -0
  15. package/lib/install-cursor.sh +24 -2
  16. package/lib/install-hooks.sh +64 -0
  17. package/lib/install-kiro.sh +26 -2
  18. package/lib/install-skills.sh +5 -2
  19. package/lib/pre-scan.sh +13 -1
  20. package/lib/project-init.sh +28 -9
  21. package/package.json +1 -1
  22. package/skills/agent-audit/SKILL.md +180 -0
  23. package/skills/ai-project-architecture/SKILL.md +33 -534
  24. package/skills/ai-project-architecture/rules/architecture-validation.md +200 -0
  25. package/skills/ai-project-architecture/rules/compliance-check.md +83 -0
  26. package/skills/ai-project-architecture/rules/iron-laws.md +188 -0
  27. package/skills/ai-project-architecture/rules/migration.md +94 -0
  28. package/skills/ai-project-architecture/rules/refactoring.md +91 -0
  29. package/skills/ai-project-architecture/rules/testing.md +249 -0
  30. package/skills/ai-project-architecture/rules/verification.md +111 -0
  31. package/skills/architecture-guard/SKILL.md +164 -0
  32. package/skills/architecture-guard/rules/violation-detection.md +90 -0
  33. package/skills/atool-init/SKILL.md +24 -4
  34. package/skills/ci-feedback/SKILL.md +165 -0
  35. package/skills/project-analyze/SKILL.md +129 -19
  36. package/skills/project-analyze/phases/phase1-setup.md +76 -5
  37. package/skills/project-analyze/phases/phase2-understand.md +137 -26
  38. package/skills/project-analyze/phases/phase2.5-refine.md +32 -23
  39. package/skills/project-analyze/phases/phase3-graph.md +39 -5
  40. package/skills/project-analyze/phases/phase4-synthesize.md +17 -1
  41. package/skills/project-analyze/phases/phase5-export.md +42 -4
  42. package/skills/project-analyze/prompts/understand-agent.md +156 -298
  43. package/skills/project-analyze/rules/java.md +69 -1
  44. package/skills/project-query/SKILL.md +91 -200
  45. package/skills/project-query/rules/aggregate-stats.md +301 -0
  46. package/skills/project-query/rules/data-lineage.md +228 -0
  47. package/skills/project-query/rules/impact-analysis.md +218 -0
  48. package/skills/project-query/rules/neighborhood.md +234 -0
  49. package/skills/project-query/rules/node-lookup.md +97 -0
  50. package/skills/project-query/rules/path-query.md +135 -0
  51. package/skills/software-architecture/SKILL.md +39 -501
  52. package/skills/software-architecture/rules/concurrency-ha.md +346 -0
  53. package/skills/software-architecture/rules/ddd.md +450 -0
  54. package/skills/software-architecture/rules/decision-workflow.md +155 -0
  55. package/skills/software-architecture/rules/deployment.md +508 -0
  56. package/skills/software-architecture/rules/styles.md +232 -0
@@ -0,0 +1,200 @@
1
+ # Architecture Validation - 架构验证
2
+
3
+ ## 验证原则
4
+
5
+ 所有 AI 项目必须遵循 `PROJECT_STRUCTURE.md` 中定义的架构。偏差需要明确文档化和批准。
6
+
7
+ ## 关键架构检查点
8
+
9
+ ### 1. 目录结构验证
10
+ ```bash
11
+ # 必需目录
12
+ agents/
13
+ apps/
14
+ core/
15
+ configs/
16
+
17
+ # 条件目录(按需)
18
+ models/ # 仅当共享模型时
19
+ tests/ # 推荐
20
+ ```
21
+
22
+ ### 2. 代理结构验证
23
+ 每个 `agents/{agent_name}/` 必须:
24
+ - `nodes/` - 处理节点
25
+ - `services/` - 业务服务
26
+ - `models/api.py` - API 模型
27
+ - `tools/` - 工具函数
28
+
29
+ 条件必需(按需):
30
+ - `graph.py` - LangGraph 图定义
31
+ - `checkpoint.py` - 状态持久化
32
+ - `views.py` - HTTP 端点
33
+ - `models/orm.py` - ORM 模型
34
+ - `models/state.py` - 自定义状态
35
+
36
+ ### 3. 命名约定
37
+ - 目录:小写,kebab-case(`user-notifications`)
38
+ - 文件:小写,snake_case(`user_notifications.py`)
39
+ - 类:PascalCase(`UserNotifications`)
40
+ - 函数:snake_case(`send_notification`)
41
+ - 常量:UPPER_SNAKE_CASE
42
+
43
+ ### 4. 关注点分离
44
+ ```
45
+ core/ # 横切关注点(日志、异常等)
46
+ apps/ # 应用程序逻辑
47
+ agents/ # 业务代理
48
+ ├── nodes/ # 纯函数,无副作用
49
+ ├── services/ # 业务逻辑,可依赖 nodes
50
+ └── models/ # 数据模型和 API
51
+ configs/ # 配置管理
52
+ ```
53
+
54
+ ## 验证流程
55
+
56
+ ### 1. 结构扫描
57
+ ```bash
58
+ find . -type d -name "agents" | head -1
59
+ find . -type d -name "apps" | head -1
60
+ find . -type d -name "core" | head -1
61
+ find . -type d -name "configs" | head -1
62
+ ```
63
+
64
+ ### 2. 代理深度检查
65
+ 对每个代理:
66
+ ```bash
67
+ agent_path="agents/{agent_name}"
68
+ required_dirs=["nodes", "services", "tools"]
69
+ for dir in required_dirs; do
70
+ test -d "$agent_path/$dir" || echo "Missing: $dir"
71
+ done
72
+ ```
73
+
74
+ ### 3. 导入验证
75
+ ```bash
76
+ # 检查绝对导入
77
+ grep -r "from apps\." agents/
78
+ grep -r "from core\." agents/
79
+ grep -r "from agents\." agents/
80
+
81
+ # 检查相对导入
82
+ grep -r "from \.\." agents/
83
+ ```
84
+
85
+ ### 4. 依赖分析
86
+ ```bash
87
+ # 生成依赖图
88
+ grep -r "import.*agents\." . | grep -v "__pycache__" > dependencies.txt
89
+ grep -r "import.*apps\." . | grep -v "__pycache__" >> dependencies.txt
90
+ ```
91
+
92
+ ## 常见架构问题
93
+
94
+ ### 1. 循环依赖
95
+ ```python
96
+ # agents/user_agent/services.py
97
+ from agents/order_agent.services import OrderService
98
+
99
+ # agents/order_agent/services.py
100
+ from agents/user_agent.services import UserService # 循环!
101
+ ```
102
+
103
+ **解决方案**:提取共享服务到 `apps/`
104
+
105
+ ### 2. 关注点混合
106
+ ```python
107
+ # agents/chatbot/nodes.py
108
+ # 错误:包含业务逻辑
109
+ def process_message(message):
110
+ # 数据库操作
111
+ db.session.add(...)
112
+ # 业务逻辑
113
+ response = generate_response(...)
114
+ # 调用其他服务
115
+ payment_service.charge(...)
116
+ return response
117
+ ```
118
+
119
+ **解决方案**:
120
+ ```python
121
+ # agents/chatbot/nodes.py
122
+ def process_message(message):
123
+ # 仅协调逻辑
124
+ processed = message_processor.run(message)
125
+ response = responder.generate(processed)
126
+ return response
127
+
128
+ # agents/chatbot/services/message_processor.py
129
+ def run(message):
130
+ # 业务逻辑
131
+ # 数据库操作
132
+ # 调用其他服务
133
+ ```
134
+
135
+ ### 3. 配置硬编码
136
+ ```python
137
+ # 错误
138
+ API_KEY = "sk-123456"
139
+ ```
140
+
141
+ **解决方案**:
142
+ ```python
143
+ # 正确
144
+ from configs.app_config import get_config
145
+ API_KEY = get_config().openai_api_key
146
+ ```
147
+
148
+ ## 架构违规严重等级
149
+
150
+ | 等级 | 描述 | 行动 |
151
+ |------|------|------|
152
+ | CRITICAL | 缺少必需目录/结构 | 阻止开发,必须修复 |
153
+ | HIGH | 违反关注点分离 | 影响维护性,尽快修复 |
154
+ | MEDIUM | 命名约定违规 | 影响可读性,计划修复 |
155
+ | LOW | 次优结构 | 信息性,可选修复 |
156
+
157
+ ## 验证工具
158
+
159
+ ### 1. 结构验证脚本
160
+ ```python
161
+ #!/usr/bin/env python3
162
+ import os
163
+ from pathlib import Path
164
+
165
+ def validate_structure(root):
166
+ errors = []
167
+ required = ["agents", "apps", "core", "configs"]
168
+
169
+ for dir in required:
170
+ if not (root / dir).exists():
171
+ errors.append(f"Missing required directory: {dir}")
172
+
173
+ return errors
174
+ ```
175
+
176
+ ### 2. 导入验证脚本
177
+ ```python
178
+ #!/usr/bin/env python3
179
+ import ast
180
+ import sys
181
+
182
+ def check_imports(file_path):
183
+ with open(file_path) as f:
184
+ tree = ast.parse(f.read())
185
+
186
+ for node in ast.walk(tree):
187
+ if isinstance(node, ast.Import):
188
+ for alias in node.names:
189
+ print(f"Import: {alias.name}")
190
+ elif isinstance(node, ast.ImportFrom):
191
+ print(f"From: {node.module} names: {[alias.name for alias in node.names]}")
192
+ ```
193
+
194
+ ## 通过标准
195
+ - 无 CRITICAL 架构违规
196
+ - 所有必需目录存在
197
+ - 代理结构正确
198
+ - 无循环依赖
199
+ - 导入路径正确
200
+ - 关注点分离正确
@@ -0,0 +1,83 @@
1
+ # Compliance Assessment - 合规性评估
2
+
3
+ ## 执行步骤
4
+
5
+ ### 1. 组件分类(按需求层级)
6
+ **Tier 1(必需组件)** - 缺失 = CRITICAL
7
+ - 顶层:`agents/`, `apps/`, `core/`, `configs/`
8
+ - 每个代理:`nodes/`, `services/`, `models/api.py`, `tools/`
9
+
10
+ **Tier 2(条件必需组件)** - 条件满足时缺失 = HIGH
11
+ - `models/` 根目录(仅当跨代理共享 ORM 模型时)
12
+ - 代理的 `models/orm.py`(仅当代理有独立数据库表时)
13
+ - 代理的 `models/state.py`(仅当代理使用自定义 LangGraph 状态时)
14
+ - 代理的 `graph.py`(仅当代理使用 LangGraph 时)
15
+ - 代理的 `checkpoint.py`(仅当代理使用状态持久化时)
16
+ - 代理的 `views.py`(仅当代理暴露 HTTP 端点时)
17
+ - 代理的 `constants.py`(可选)
18
+
19
+ **Tier 3(可选组件)** - 缺失 = LOW(信息性)
20
+ - `tests/`, `bin/`, `docs/`, `logs/`, `temp/`
21
+
22
+ ### 2. Tier 2 组件条件检测
23
+ - 检查数据库操作 → 需要 `models/` 根目录
24
+ - 检查导入 StateGraph → 需要 `graph.py`
25
+ - 检查使用 @router 或 APIRouter → 需要 `views.py`
26
+ - 检查使用 checkpoint/checkpointer → 需要 `checkpoint.py`
27
+ - 检查有 ORM 模型 → 需要 `models/orm.py`
28
+ - 检查使用 TypedDict 或自定义状态 → 需要 `models/state.py`
29
+
30
+ ### 3. 目录结构扫描
31
+ - 检查 Tier 1 目录
32
+ - 检查 Tier 2 目录(条件满足时)
33
+ - 检查 Tier 3 目录
34
+
35
+ ### 4. 代理结构验证
36
+ 对每个 `agents/{agent_name}/`:
37
+ - Tier 1:`nodes/`, `services/`, `models/api.py`, `tools/`
38
+ - Tier 2:`graph.py`, `checkpoint.py`, `views.py`, `models/orm.py`, `models/state.py`
39
+ - Tier 3:`constants.py`
40
+
41
+ ### 5. 合规缺口识别
42
+ - 缺失 Tier 1 组件(CRITICAL)
43
+ - 缺失条件满足的 Tier 2 组件(HIGH)
44
+ - 命名约定违规
45
+ - 关注点混合
46
+
47
+ ### 6. 生成合规报告
48
+ - 整体合规得分(百分比)
49
+ - 严重等级:CRITICAL/HIGH/MEDIUM/LOW
50
+ - 组件分类
51
+ - 建议和优先级
52
+
53
+ ## 输出示例
54
+
55
+ ```
56
+ ## Compliance Report: AI Project Structure
57
+
58
+ ### Overall Score: 65%
59
+
60
+ ### Critical Issues (3)
61
+ - Missing `core/` directory
62
+ - Agent 'chatbot' missing required `tools/` directory
63
+ - Missing `configs/app_config.py`
64
+
65
+ ### High Issues (5)
66
+ - Agent 'chatbot' missing `graph.py` (uses LangGraph)
67
+ - Missing shared `models/` directory
68
+ - Agent 'payment' missing `views.py` (exposes API endpoints)
69
+ - Naming violation: 'Services' should be 'services'
70
+
71
+ ### Recommendations
72
+ 1. Create missing Tier 1 directories
73
+ 2. Add required agent components
74
+ 3. Fix naming conventions
75
+ ```
76
+
77
+ ## 质量检查清单
78
+ - [ ] 所有组件按 Tier 分类
79
+ - [ ] Tier 2 条件已检测
80
+ - [ ] 目录结构已扫描
81
+ - [ ] 代理结构已验证
82
+ - [ ] 合规缺口已识别
83
+ - [ ] 合规报告已生成
@@ -0,0 +1,188 @@
1
+ # Iron Laws - 铁律
2
+
3
+ ## 核心原则
4
+
5
+ 违反以下铁律即违反技能精神,必须立即停止。
6
+
7
+ ### Iron Law 1: NO FABRICATION
8
+ ```
9
+ 绝不假设或编造代码行为
10
+ 仅处理已验证、存在的代码
11
+ ```
12
+
13
+ **违规示例**:
14
+ ```python
15
+ # 错误:假设函数存在
16
+ def migrate_agent(agent_name):
17
+ # 假设 agent 有 settings 属性
18
+ if agent.settings.enabled: # 可能不存在!
19
+ migrate_features(agent)
20
+
21
+ # 正确:先验证
22
+ def migrate_agent(agent_name):
23
+ agent = load_agent(agent_name)
24
+ if hasattr(agent, 'settings') and agent.settings.enabled:
25
+ migrate_features(agent)
26
+ ```
27
+
28
+ ### Iron Law 2: NO NEW FEATURES DURING REFACTORING
29
+ ```
30
+ 重构 = 仅结构变更
31
+ 任何行为变更都是违规
32
+ ```
33
+
34
+ **违规示例**:
35
+ ```python
36
+ # 错误:重构时添加新功能
37
+ def old_process_data(data):
38
+ return data.strip()
39
+
40
+ def new_process_data(data):
41
+ # 重构时添加了新逻辑
42
+ cleaned = data.strip()
43
+ if not cleaned:
44
+ return "EMPTY" # 新增行为!
45
+ return cleaned
46
+
47
+ # 正确:仅结构变更
48
+ def new_process_data(data):
49
+ return data.strip() # 完全相同
50
+ ```
51
+
52
+ ### Iron Law 3: INCREMENTAL EXECUTION
53
+ ```
54
+ 分单代理批次执行
55
+ 每批后自检
56
+ ```
57
+
58
+ **违规示例**:
59
+ ```python
60
+ # 错误:一次性迁移所有代理
61
+ def migrate_all_agents():
62
+ # 同时迁移 10 个代理
63
+ migrate_user_agent()
64
+ migrate_order_agent()
65
+ migrate_payment_agent()
66
+ # ... 7 个更多
67
+ verify_all() # 太晚了!
68
+
69
+ # 正确:分批执行
70
+ def migrate_all_agents():
71
+ # 批次 1
72
+ migrate_user_agent()
73
+ verify_user_agent()
74
+
75
+ # 批次 2
76
+ migrate_order_agent()
77
+ verify_order_agent()
78
+ ```
79
+
80
+ ### Iron Law 4: MANDATORY QUALITY GATES
81
+ ```
82
+ systematic-debugging 审查是必需的
83
+ 每个代码完成阶段后必须调用
84
+ ```
85
+
86
+ **违规示例**:
87
+ ```python
88
+ # 错误:跳过质量检查
89
+ def migrate_agent(agent_name):
90
+ migrate_files(agent_name)
91
+ # 跳过检查!
92
+ return "done"
93
+
94
+ # 正确:必需调用
95
+ def migrate_agent(agent_name):
96
+ migrate_files(agent_name)
97
+ systematic_debugging.review("迁移完成", get_changes())
98
+ return "done"
99
+ ```
100
+
101
+ ### Iron Law 5: SKILL INTEGRATION
102
+ ```
103
+ 此技能不能独立运行
104
+ 必须在指定点调用所需技能
105
+ ```
106
+
107
+ **违规示例**:
108
+ ```python
109
+ # 错误:独立运行
110
+ def refactor_project():
111
+ # 未调用必需技能
112
+ scan_structure()
113
+ migrate_files()
114
+ return "done"
115
+
116
+ # 正确:调用必需技能
117
+ def refactor_project():
118
+ scan_structure()
119
+ software_architecture.validate()
120
+ migrate_files()
121
+ test_driven_development.write_tests()
122
+ ```
123
+
124
+ ## 红旗标志 - 停止并重新评估
125
+
126
+ 如果出现以下想法,立即停止:
127
+
128
+ | 想法 | 现实 | 行动 |
129
+ |------|------|------|
130
+ | "就这一次,我会添加这个小改进" | 违反 Iron Law 2 - 立即停止 | 删除改进,正确迁移 |
131
+ | "我以后会正确重构" | 以后永远不会 - 技术债务累积 | 现在就做对,或者不做 |
132
+ | "这个小功能不会影响迁移" | 违反精确迁移原则 | 功能蔓延 = 迁移失败 |
133
+ | "迁移后测试更快" | 未测试的迁移是未验证的迁移 | 使用 test-driven-development,无例外 |
134
+ | "systematic-debugging 太耗时" | 比调试生产问题更快 | 质量关卡不可协商 |
135
+
136
+ ## 质量关卡检查
137
+
138
+ ### 每个迁移批次后
139
+ 1. 自检清单完成
140
+ 2. **调用 systematic-debugging(必需)**
141
+ 3. 所有导入正确解析
142
+ 4. 无语法错误
143
+ 5. 现有测试通过
144
+
145
+ ### 迁移完成后
146
+ 1. **调用 systematic-debugging(必需)**
147
+ 2. 所有验证检查通过
148
+ 3. 无行为变更
149
+ 4. 所有交叉引用已更新
150
+
151
+ ## 违反处理
152
+
153
+ ### 发现违规时
154
+ 1. **立即停止**当前操作
155
+ 2. 记录违规行为
156
+ 3. 决定:
157
+ - 如果小错误:修复并继续
158
+ - 如果严重违规:回滚并重新开始
159
+
160
+ ### 回滚策略
161
+ ```bash
162
+ # 回滚单个代理
163
+ git checkout HEAD~1 # 回到上一个提交
164
+ rm -rf agents/new_agent # 删除新结构
165
+ git add agents/old_agent # 恢复旧结构
166
+ ```
167
+
168
+ ## 例外情况
169
+
170
+ **例外需要用户明确覆盖**:
171
+ ```python
172
+ # 仅当用户明确允许时
173
+ if user_explicit_override:
174
+ # 可以临时违反铁律
175
+ pass
176
+ else:
177
+ # 严格执行
178
+ raise ViolationError("Iron Law violated")
179
+ ```
180
+
181
+ ## 记录和报告
182
+
183
+ 所有违规必须记录:
184
+ - 违律的铁律编号
185
+ - 违规描述
186
+ - 如何检测到的
187
+ - 如何修复的
188
+ - 最终结果
@@ -0,0 +1,94 @@
1
+ # Structure Migration - 结构迁移
2
+
3
+ ## 核心原则(不可协商)
4
+
5
+ ### Iron Laws
6
+ 1. **NO FABRICATION** - 不假设或编造代码行为
7
+ 2. **NO NEW FEATURES** - 仅结构变更,无功能添加
8
+ 3. **INCREMENTAL EXECUTION** - 单代理批次执行
9
+ 4. **MANDATORY QUALITY GATES** - 每阶段后必须调用 systematic-debugging
10
+ 5. **SKILL INTEGRATION** - 必须调用必需技能
11
+
12
+ ## 执行步骤
13
+
14
+ ### 1. 创建新目录结构
15
+ - 按 `PROJECT_STRUCTURE.md` 创建标准目录
16
+ - 不要删除旧结构
17
+ - 使用并行结构:`new_agents/`, `new_apps/` 等
18
+
19
+ ### 2. 迁移共享组件(优先)
20
+ 迁移顺序:
21
+ 1. `apps/`(LLM 管理、utils、logs API)
22
+ 2. `core/`(异常、中间件、日志等)
23
+ 3. `models/`(共享 ORM 模型)
24
+ 4. `configs/`(所有配置文件)
25
+ 5. 更新所有导入语句
26
+
27
+ ### 3. 迁移代理(按优先级)
28
+ 对每个代理:
29
+ 1. 创建 `agents/{agent_name}/` 及子目录
30
+ 2. 迁移 `nodes/` → `agents/{agent_name}/nodes/`
31
+ 3. 迁移 `services/` → `agents/{agent_name}/services/`
32
+ 4. 迁移 `models/` → `agents/{agent_name}/models/`
33
+ 5. 迁移 `tools/` → `agents/{agent_name}/tools/`
34
+ 6. 迁移可选文件(graph.py, checkpoint.py, views.py, constants.py)
35
+ 7. 更新所有导入语句:
36
+ - 旧:`from old_apps.xyz import ABC`
37
+ - 新:`from apps.xyz import ABC`
38
+
39
+ ### 4. 更新交叉引用
40
+ - 更新所有迁移文件的导入
41
+ - 更新配置文件中的引用
42
+ - 更新文档中的引用
43
+ - 搜索旧路径并替换为新路径
44
+
45
+ ### 5. 验证每个批次
46
+ ```bash
47
+ # 语法检查
48
+ python -m py_compile
49
+
50
+ # 运行现有测试
51
+ pytest
52
+
53
+ # 验证导入解析
54
+ python -c "import agents.{agent_name}"
55
+ ```
56
+
57
+ ## 禁止事项(违反即停止)
58
+
59
+ | 禁止行为 | 原因 | 正确做法 |
60
+ |---------|------|---------|
61
+ | 添加新功能 | 违反 exact preservation | 仅做结构迁移 |
62
+ | "顺手修复" | 功能蔓延 | 保持原样,后期专门处理 |
63
+ | 优化代码 | 可能改变行为 | 完全保持原逻辑 |
64
+ | 跳过测试 | 无法验证正确性 | 必须运行测试 |
65
+ | 忽略导入更新 | 会导致运行时错误 | 立即更新并验证 |
66
+
67
+ ## 验证清单
68
+ - [ ] 新目录结构已创建
69
+ - [ ] 共享组件已迁移
70
+ - [ ] 代理按优先级迁移
71
+ - [ ] 所有导入已更新并验证
72
+ - [ ] 无语法错误
73
+ - [ ] 现有测试通过
74
+ - [ ] 无新功能添加
75
+ - [ ] 无行为变更
76
+ - [ ] 调用了 software-architecture 技能
77
+ - [ ] 调用了 test-driven-development 技能
78
+
79
+ ## 常见问题
80
+
81
+ ### Q: 遇到循环依赖怎么办?
82
+ A: 迁移被依赖的代理 first,然后依赖的代理
83
+
84
+ ### Q: 导入路径不明确怎么办?
85
+ A: 使用 `grep` 搜索所有导入,逐个验证
86
+
87
+ ### Q: 测试失败怎么办?
88
+ A: 立即停止,修复导入或路径问题,不要继续迁移
89
+
90
+ ## 紧急停止条件
91
+ - 发现任何功能改变
92
+ - 无法修复的导入错误
93
+ - 测试失败且无法快速修复
94
+ - 需要添加新功能
@@ -0,0 +1,91 @@
1
+ # Refactoring Planning - 重构规划
2
+
3
+ ## 执行步骤
4
+
5
+ ### 1. 记录当前结构
6
+ 创建 `old_structure.md` 包含:
7
+ - 当前目录树
8
+ - 当前代理列表
9
+ - 当前文件位置
10
+ - 导入依赖图
11
+
12
+ ### 2. 创建迁移映射
13
+ 文件/目录映射:old_path → new_path
14
+ - 识别共享/公共组件
15
+ - 识别代理特定组件
16
+ - 标记任何模糊情况
17
+
18
+ ### 3. 按优先级排序迁移
19
+ 顺序:
20
+ 1. 共享组件(apps/, core/, models/)
21
+ 2. 独立代理(不依赖其他代理)
22
+ 3. 依赖代理(依赖已迁移的代理)
23
+ 4. 代理特定配置和工具
24
+
25
+ ### 4. 定义迁移批次
26
+ - 每个批次 = 可独立验证单元
27
+ - 优先:每个代理一个批次
28
+ - 大型代理:拆分为 nodes/, services/, models/, tools/ 批次
29
+ - 每个批次必须有明确的入口/退出条件
30
+
31
+ ### 5. 创建回滚计划
32
+ - 每个批次:失败时如何回滚
33
+ - 检查点:每个成功批次后提交
34
+ - 验证:必须通过测试才能继续
35
+
36
+ ## 迁移映射示例
37
+
38
+ ```yaml
39
+ migration_mapping:
40
+ shared_components:
41
+ old/old_apps/ → new/apps/
42
+ old/old_core/ → new/core/
43
+ old/shared_models/ → new/models/
44
+
45
+ agents:
46
+ agent_chatbot:
47
+ old/chatbot/ → new/agents/chatbot/
48
+ old/chatbot_nodes/ → new/agents/chatbot/nodes/
49
+ old/chatbot_services/ → new/agents/chatbot/services/
50
+
51
+ dependencies:
52
+ old/chatbot_payment/ → new/agents/chatbot_payment/
53
+ # 依赖 chatbot 已先迁移
54
+ ```
55
+
56
+ ## 迁移批次示例
57
+
58
+ ```yaml
59
+ migration_batches:
60
+ batch_1:
61
+ components: ["apps", "core", "models"]
62
+ dependencies: []
63
+ rollback: "删除 new_ 前缀目录"
64
+
65
+ batch_2:
66
+ components: ["agents/chatbot"]
67
+ dependencies: ["batch_1"]
68
+ rollback: "删除 agents/chatbot,恢复旧导入"
69
+
70
+ batch_3:
71
+ components: ["agents/payment"]
72
+ dependencies: ["batch_1", "batch_2"]
73
+ rollback: "删除 agents/payment,恢复旧导入"
74
+ ```
75
+
76
+ ## 风险评估
77
+
78
+ | 风险级别 | 描述 | 应对措施 |
79
+ |---------|------|---------|
80
+ | HIGH | 跨代理依赖 | 提前识别依赖顺序,先迁移被依赖方 |
81
+ | MEDIUM | 导入路径更新 | 使用全局搜索替换,验证每个导入 |
82
+ | LOW | 配置文件引用 | 迁移后立即测试配置加载 |
83
+
84
+ ## 验证清单
85
+ - [ ] 当前结构已记录
86
+ - [ ] 迁移映射已创建
87
+ - [ ] 迁移顺序已定义
88
+ - [ ] 批次已识别
89
+ - [ ] 回滚计划已定义
90
+ - [ ] software-architecture 技能已咨询
91
+ - [ ] 用户批准已获得(必需)