@leocm/flowcraft 2.1.0 → 2.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 (96) hide show
  1. package/README.md +19 -2
  2. package/bin/cli.js +108 -108
  3. package/flowcraft.yaml +30 -30
  4. package/install.sh +24 -24
  5. package/lib/args.js +38 -38
  6. package/lib/config.js +20 -20
  7. package/lib/copy.js +131 -131
  8. package/lib/fix.js +110 -110
  9. package/lib/fsutil.js +104 -104
  10. package/lib/global.js +229 -229
  11. package/lib/init.js +43 -43
  12. package/lib/runtime.js +84 -84
  13. package/lib/version.js +55 -55
  14. package/lib/wizard.js +125 -125
  15. package/package.json +33 -33
  16. package/presets/backend.yaml +20 -20
  17. package/presets/default.yaml +15 -15
  18. package/presets/frontend.yaml +20 -20
  19. package/presets/quick-fix.yaml +15 -15
  20. package/setup/.claude/hooks/check-phase-test.py +152 -152
  21. package/setup/.claude/hooks/check-phase-write.py +235 -235
  22. package/setup/.claude/hooks/dispatch.py +67 -67
  23. package/setup/.claude/hooks/file-suggestion.py +45 -45
  24. package/setup/.claude/hooks/flowcraft_env.py +162 -137
  25. package/setup/.claude/hooks/permission-request.py +132 -125
  26. package/setup/.claude/hooks/post-tool-failure.py +36 -36
  27. package/setup/.claude/hooks/pre-compact.py +66 -66
  28. package/setup/.claude/hooks/review-runner.py +846 -846
  29. package/setup/.claude/hooks/setup-keys.py +282 -282
  30. package/setup/.claude/hooks/statusline.py +63 -63
  31. package/setup/.claude/hooks/stop-check.py +186 -171
  32. package/setup/.claude/hooks/subagent-start.py +50 -50
  33. package/setup/.claude/hooks/subagent-stop.py +63 -63
  34. package/setup/.claude/hooks/task-completed.py +57 -57
  35. package/setup/.claude/hooks/task_manager.py +592 -592
  36. package/setup/.claude/hooks/user-prompt-submit.py +91 -85
  37. package/setup/.claude/settings.json +233 -237
  38. package/setup/.claude/skills/Pstatus/SKILL.md +68 -68
  39. package/setup/.claude/skills/archive/SKILL.md +195 -195
  40. package/setup/.claude/skills/brainstorming/SKILL.md +5 -5
  41. package/setup/.claude/skills/brainstorming/scripts/server.cjs +723 -723
  42. package/setup/.claude/skills/brainstorming/scripts/start-server.py +245 -245
  43. package/setup/.claude/skills/brainstorming/scripts/stop-server.py +178 -178
  44. package/setup/.claude/skills/brainstorming/visual-companion.md +298 -298
  45. package/setup/.claude/skills/chrome-integration/SKILL.md +66 -66
  46. package/setup/.claude/skills/code-review/SKILL.md +264 -264
  47. package/setup/.claude/skills/executing-plans/SKILL.md +1 -1
  48. package/setup/.claude/skills/gitnexus/gitnexus-cli/SKILL.md +67 -67
  49. package/setup/.claude/skills/gitnexus/gitnexus-debugging/SKILL.md +1 -1
  50. package/setup/.claude/skills/gitnexus/gitnexus-exploring/SKILL.md +1 -1
  51. package/setup/.claude/skills/gitnexus/gitnexus-guide/SKILL.md +1 -1
  52. package/setup/.claude/skills/gitnexus/gitnexus-impact-analysis/SKILL.md +1 -1
  53. package/setup/.claude/skills/gitnexus/gitnexus-refactoring/SKILL.md +1 -1
  54. package/setup/.claude/skills/methodology/SKILL.md +124 -0
  55. package/setup/.claude/skills/phase/SKILL.md +62 -62
  56. package/setup/.claude/skills/playwright/SKILL.md +85 -85
  57. package/setup/.claude/skills/review/SKILL.md +97 -97
  58. package/setup/.claude/skills/task/SKILL.md +26 -26
  59. package/setup/.claude/skills/test-driven-development/SKILL.md +1 -1
  60. package/setup/.claude/skills/ui-ux-pro-max/SKILL.md +1 -1
  61. package/setup/.claude/skills/verification-before-completion/SKILL.md +1 -1
  62. package/setup/.claude/skills/writing-plans/SKILL.md +1 -1
  63. package/setup/.codex/.agents/skills/archive/SKILL.md +195 -195
  64. package/setup/.codex/.agents/skills/brainstorming/SKILL.md +5 -5
  65. package/setup/.codex/.agents/skills/brainstorming/scripts/server.cjs +723 -723
  66. package/setup/.codex/.agents/skills/brainstorming/scripts/start-server.py +245 -245
  67. package/setup/.codex/.agents/skills/brainstorming/scripts/stop-server.py +178 -178
  68. package/setup/.codex/.agents/skills/brainstorming/visual-companion.md +298 -298
  69. package/setup/.codex/.agents/skills/chrome-integration/SKILL.md +66 -66
  70. package/setup/.codex/.agents/skills/code-review/SKILL.md +264 -264
  71. package/setup/.codex/.agents/skills/executing-plans/SKILL.md +1 -1
  72. package/setup/.codex/.agents/skills/gitnexus/gitnexus-cli/SKILL.md +67 -67
  73. package/setup/.codex/.agents/skills/gitnexus/gitnexus-debugging/SKILL.md +1 -1
  74. package/setup/.codex/.agents/skills/gitnexus/gitnexus-exploring/SKILL.md +1 -1
  75. package/setup/.codex/.agents/skills/gitnexus/gitnexus-guide/SKILL.md +1 -1
  76. package/setup/.codex/.agents/skills/gitnexus/gitnexus-impact-analysis/SKILL.md +1 -1
  77. package/setup/.codex/.agents/skills/gitnexus/gitnexus-refactoring/SKILL.md +1 -1
  78. package/setup/.codex/.agents/skills/methodology/SKILL.md +124 -0
  79. package/setup/.codex/.agents/skills/phase/SKILL.md +62 -62
  80. package/setup/.codex/.agents/skills/playwright/SKILL.md +85 -85
  81. package/setup/.codex/.agents/skills/review/SKILL.md +97 -97
  82. package/setup/.codex/.agents/skills/task/SKILL.md +27 -27
  83. package/setup/.codex/.agents/skills/test-driven-development/SKILL.md +1 -1
  84. package/setup/.codex/.agents/skills/ui-ux-pro-max/SKILL.md +1 -1
  85. package/setup/.codex/.agents/skills/verification-before-completion/SKILL.md +1 -1
  86. package/setup/.codex/.agents/skills/writing-plans/SKILL.md +1 -1
  87. package/setup/.codex/hooks/review-runner.py +851 -851
  88. package/setup/.codex/hooks/setup-keys.py +287 -287
  89. package/setup/AGENTS.md +11 -1
  90. package/setup/CLAUDE.md +11 -1
  91. package/setup/install.sh +24 -24
  92. package/setup/tests/test_decision_timeout.py +241 -241
  93. package/setup/tests/test_hook_guards.py +357 -357
  94. package/setup/tests/test_sdlc_bootstrap.py +167 -167
  95. package/setup/tests/test_sessionlog_switch.py +199 -0
  96. package/setup/tests/test_task_manager.py +148 -148
@@ -1,67 +1,67 @@
1
- ---
2
- name: chrome-integration
3
- description: "Chrome browser integration: P1 prototype preview, P3 visual regression/E2E/responsive tests. | 触发词:原型预览/视觉回归/E2E/响应式"
4
- allowed-tools:
5
- - Read
6
- - Glob
7
- - Grep
8
- - Bash
9
- - Write
10
- ---
11
-
12
- Usage: `/chrome-integration <feature>`
13
-
14
- Arguments: $ARGUMENTS
15
-
16
- ---
17
-
18
- > **Note (说明)**: 浏览器交互工具层已由官方 `playwright-cli` 技能取代(R4);本技能保留 P1 原型预览与 P3 视觉回归/响应式封装。首次调用 playwright-cli 时若未安装,用 `npx @playwright/cli@latest {cmd}` 自动下载,或 `npm i -g @playwright/cli`;浏览器缺失时 `npx playwright install chromium`。
19
-
20
- ## Allowed phases (允许的阶段)
21
-
22
- | Phase | Chrome | Purpose |
23
- |------|--------|------|
24
- | P1 | **allowed** | UI prototype preview, design confirmation |
25
- | P3 | **allowed** | visual regression tests, E2E interaction verification, responsive tests |
26
- | Others | forbidden | — |
27
-
28
- ---
29
-
30
- ## P1 prototype demo flow (P1 原型展示流程)
31
-
32
- UI tasks must create a prototype in P1 and show it in Chrome for user confirmation:
33
-
34
- 1. **Create prototype HTML** — self-contained file (inline CSS + JS), may reference CDN component libraries
35
- 2. **Open preview in Chrome** — open locally so the user sees the design directly
36
- 3. **Screenshot records** — capture key pages as design references
37
- 4. **Iterate** — modify per user feedback, preview again, until satisfied
38
- 5. **After confirmation enter P2** — P2 coding uses this prototype as the visual baseline
39
-
40
- ---
41
-
42
- ## P3 usage (P3 使用规范)
43
-
44
- - Open the local dev server to verify the UI
45
- - Compare screenshots of rendered results
46
- - Verify interaction flows and responsive layout
47
-
48
- ---
49
-
50
- ## Feature parameters (功能参数)
51
-
52
- | Parameter | Description |
53
- |------|------|
54
- | prototype | create and open a prototype |
55
- | screenshot | capture a screenshot of the current page |
56
- | responsive | responsive tests (375/768/1440px) |
57
-
58
- ---
59
-
60
- ## Output format (输出格式)
61
-
62
- ```
63
- [Chrome integration (Chrome 集成)]
64
- - Phase: P1/P3
65
- - Feature: prototype preview / screenshot / responsive test
66
- - Status: done
1
+ ---
2
+ name: chrome-integration
3
+ description: "Chrome browser integration: P1 prototype preview, P3 visual regression/E2E/responsive tests. | 触发词:原型预览/视觉回归/E2E/响应式"
4
+ allowed-tools:
5
+ - Read
6
+ - Glob
7
+ - Grep
8
+ - Bash
9
+ - Write
10
+ ---
11
+
12
+ Usage: `/chrome-integration <feature>`
13
+
14
+ Arguments: $ARGUMENTS
15
+
16
+ ---
17
+
18
+ > **Note (说明)**: 浏览器交互工具层已由官方 `playwright-cli` 技能取代(R4);本技能保留 P1 原型预览与 P3 视觉回归/响应式封装。首次调用 playwright-cli 时若未安装,用 `npx @playwright/cli@latest {cmd}` 自动下载,或 `npm i -g @playwright/cli`;浏览器缺失时 `npx playwright install chromium`。
19
+
20
+ ## Allowed phases (允许的阶段)
21
+
22
+ | Phase | Chrome | Purpose |
23
+ |------|--------|------|
24
+ | P1 | **allowed** | UI prototype preview, design confirmation |
25
+ | P3 | **allowed** | visual regression tests, E2E interaction verification, responsive tests |
26
+ | Others | forbidden | — |
27
+
28
+ ---
29
+
30
+ ## P1 prototype demo flow (P1 原型展示流程)
31
+
32
+ UI tasks must create a prototype in P1 and show it in Chrome for user confirmation:
33
+
34
+ 1. **Create prototype HTML** — self-contained file (inline CSS + JS), may reference CDN component libraries
35
+ 2. **Open preview in Chrome** — open locally so the user sees the design directly
36
+ 3. **Screenshot records** — capture key pages as design references
37
+ 4. **Iterate** — modify per user feedback, preview again, until satisfied
38
+ 5. **After confirmation enter P2** — P2 coding uses this prototype as the visual baseline
39
+
40
+ ---
41
+
42
+ ## P3 usage (P3 使用规范)
43
+
44
+ - Open the local dev server to verify the UI
45
+ - Compare screenshots of rendered results
46
+ - Verify interaction flows and responsive layout
47
+
48
+ ---
49
+
50
+ ## Feature parameters (功能参数)
51
+
52
+ | Parameter | Description |
53
+ |------|------|
54
+ | prototype | create and open a prototype |
55
+ | screenshot | capture a screenshot of the current page |
56
+ | responsive | responsive tests (375/768/1440px) |
57
+
58
+ ---
59
+
60
+ ## Output format (输出格式)
61
+
62
+ ```
63
+ [Chrome integration (Chrome 集成)]
64
+ - Phase: P1/P3
65
+ - Feature: prototype preview / screenshot / responsive test
66
+ - Status: done
67
67
  ```
@@ -1,265 +1,265 @@
1
- ---
2
- name: code-review
3
- description: "AI code quality review (auto after P2; manual /code-review). | 触发词:代码审查/质量检查"
4
- allowed-tools:
5
- - Read
6
- - Glob
7
- - Write
8
- - Edit
9
- - AskUserQuestion
10
- ---
11
-
12
- Usage: `/code-review [file path]`
13
-
14
- Arguments: $ARGUMENTS
15
-
16
- ---
17
-
18
- ## Execution logic (执行逻辑)
19
-
20
- ### 1. Read project state
21
- Read from `project-state.md`:
22
- - `modified_files` list
23
- - `current_phase`, verify it is P2
24
-
25
- ### 2. Determine the review scope
26
- - If a file path argument is provided → review that file
27
- - Otherwise → use the `modified_files` list
28
-
29
- ### 3. AI-review each file
30
- Review standards (based on the Alibaba Java Development Manual):
31
-
32
- **Naming (命名规范):**
33
- - Class names: PascalCase (e.g. `UserService`)
34
- - Methods/variables: camelCase (e.g. `getUser`)
35
- - Constants: UPPER_SNAKE (e.g. `MAX_SIZE`)
36
- - Package names: all lowercase
37
-
38
- **Code style (代码风格):**
39
- - Indentation: 4 spaces
40
- - Braces: opening brace stays on the same line
41
- - Line length: ≤ 100
42
- - one statement per line
43
-
44
- **Method standards (方法规范):**
45
- - Method length: ≤ 80 lines
46
- - Parameter count: ≤ 5
47
- - returning null must be documented in a comment
48
-
49
- **Exception handling (异常处理):**
50
- - catch specific exceptions, not `catch Exception`
51
- - catch blocks must not be empty
52
- - handle or rethrow after catching
53
-
54
- **Resource management (资源管理):**
55
- - IO streams must be closed (use try-with-resources)
56
- - DB connections must be closed
57
-
58
- **Best practices (最佳实践):**
59
- - avoid magic values (use constants or enums)
60
- - avoid hardcoded config (put in config files)
61
- - String comparison uses `"abc".equals(str)` to avoid NPE
62
- - use `StringBuilder` for heavy string concatenation
63
-
64
- **Security (安全性):**
65
- - avoid SQL concatenation (use `PreparedStatement`)
66
- - mask sensitive data (passwords, tokens in logs)
67
- - avoid hardcoded secrets
68
-
69
- **Loop DB inserts (循环插入数据库, high risk - must fix):**
70
-
71
- | Check | Description |
72
- |--------|------|
73
- | **insert inside for/while loop** | `insert`/`update`/`delete` inside a loop body |
74
- | **batch insert not optimized** | loop inserts instead of batch insert |
75
- | **per-commit without transaction** | committing one by one in a loop, no batch transaction control |
76
-
77
- **Anti-patterns (反例, high-risk issues):**
78
- ```java
79
- // Anti-pattern: inserting one by one inside a for loop
80
- for (User user : userList) {
81
- jdbcTemplate.update("INSERT INTO user VALUES (?, ?)", user.getId(), user.getName());
82
- }
83
-
84
- // Anti-pattern: updating one by one inside a for loop
85
- for (Order order : orders) {
86
- orderDao.update(order);
87
- }
88
-
89
- // Anti-pattern: query-then-update inside a for loop
90
- for (Item item : items) {
91
- if (itemDao.findById(item.getId()) != null) {
92
- itemDao.update(item);
93
- }
94
- }
95
- ```
96
-
97
- **Good patterns (正例, recommended fix):**
98
- ```java
99
- // Good: JDBC Batch insert
100
- jdbcTemplate.batchUpdate("INSERT INTO user VALUES (?, ?)",
101
- userList, userList.size(),
102
- (ps, user) -> {
103
- ps.setLong(1, user.getId());
104
- ps.setString(2, user.getName());
105
- });
106
-
107
- // Good: MyBatis batch insert
108
- <insert id="batchInsert" useGeneratedKeys="true">
109
- INSERT INTO user (id, name) VALUES
110
- <foreach collection="list" item="user" separator=",">
111
- (#{user.id}, #{user.name})
112
- </foreach>
113
- </insert>
114
-
115
- // Good: batched processing + transaction control
116
- @Transactional
117
- public void processOrders(List<Order> orders) {
118
- // process in batches of 500
119
- List<List<Order>> batches = Lists.partition(orders, 500);
120
- for (List<Order> batch : batches) {
121
- orderDao.batchUpdate(batch);
122
- }
123
- }
124
- ```
125
-
126
- **Detection logic (判断逻辑):**
127
- 1. detect `for`/`while`/`do-while` loop keywords
128
- 2. detect DB operations in the loop body: `insert`/`update`/`delete`/`save`/`remove`/`find`/`query`
129
- 3. if DB operations are found inside a loop → mark as **high-risk issue**
130
- 4. further check whether batch APIs are used (`batchUpdate`/`batchInsert`/`partition`)
131
-
132
- **Severity definitions (严重程度定义):**
133
-
134
- | Level | Definition | Handling |
135
- |------|------|----------|
136
- | **High** | blocking issues: memory leaks, security holes, data inconsistency | must fix |
137
- | **Medium** | functional risks: NPE, unclosed resources, logic errors | suggested fix |
138
- | **Low** | code standards: unclear naming, format issues | optional fix |
139
-
140
- **Issue categories (问题分类):**
141
-
142
- | Category | Contains |
143
- |------|----------|
144
- | **Naming** | class names, method names, variable names, constant names, package names |
145
- | **Code style** | indentation, braces, line length, comment standards |
146
- | **Performance/security** | SQL injection, XSS, sensitive data, concurrency safety, loop batch operations |
147
- | **Best practices** | NPE protection, resource management, exception handling |
148
-
149
- **Multi-language support (多语言支持):**
150
-
151
- | Language | Extra checks |
152
- |------|-----------|
153
- | Java | thread safety, generics, wildcards, Stream API |
154
- | Python | indentation, type annotations, PEP8, list comprehensions |
155
- | Go | error handling, goroutine leaks, context usage |
156
- | JavaScript/TypeScript | callback hell, Promise, async/await, type checking |
157
-
158
- ### 4. Generate the review report
159
- Save to `.claude/code-review-report.md`:
160
-
161
- ```markdown
162
- # AI Code Review Report (AI 代码审查报告)
163
-
164
- - Review time (审查时间): {time}
165
- - Files reviewed (审查文件): {n}
166
- - Issues found (发现问题): {n} (high {h} / medium {m} / low {l})
167
- - Handling (处理方式): {pending/done/ignored (待处理/已处理/已忽略)}
168
-
169
- ## Issue summary (问题汇总)
170
-
171
- | Category | High | Medium | Low | Total |
172
- |------|------|------|------|------|
173
- | Naming | 0 | 0 | 0 | 0 |
174
- | Code style | 0 | 0 | 0 | 0 |
175
- | Performance/security | 0 | 0 | 0 | 0 |
176
- | Best practices | 0 | 0 | 0 | 0 |
177
-
178
- ## Issue list (问题列表)
179
-
180
- **Issue 1: {title}**
181
- - File (文件): {path}
182
- - Location (位置): line {n}
183
- - Category (分类): {naming/code style/performance-security/best practices}
184
- - Severity (严重性): {high/medium/low}
185
- - Current code (当前代码):
186
- ```java
187
- {snippet}
188
- ```
189
- - Suggested fix (建议修复): {description}
190
- - Status (状态): {unfixed/fixed/ignored (未修复/已修复/已忽略)}
191
- ```
192
-
193
- ### 5. Interaction handling (交互处理)
194
- If issues are found:
195
- - Show the issue list
196
- - Use AskUserQuestion to let the user choose:
197
- - **A. Auto-fix**: AI generates the fix; apply after user confirmation
198
- - **B. Manual fix**: return to P2
199
- - **C. Ignore**: record the exemption, continue to P3
200
-
201
- ### 6. Return result (返回结果)
202
- Output JSON:
203
- ```json
204
- {
205
- "passed": true/false,
206
- "issues_count": 3,
207
- "high_severity": 1,
208
- "action": "auto_fix/manual_fix/ignore",
209
- "message": "review complete (审查完成)"
210
- }
211
- ```
212
-
213
- **Judgment logic (判断逻辑):**
214
- - `passed = true`: no issues, or all issues fixed/ignored
215
- - `passed = false`: unresolved high/medium issues exist
216
-
217
- ### 7. Retry mechanism (重试机制)
218
-
219
- Based on `review_retry_count`:
220
-
221
- | Retries | Handling |
222
- |----------|----------|
223
- | 0 | first review; after issues found, wait for the user's choice |
224
- | 1-3 | re-review after fixes |
225
- | > 3 | force stop and ask the user to intervene |
226
-
227
- **When over the retry limit:**
228
- - stop auto-fixing
229
- - save the current review report
230
- - prompt the user to handle manually
231
-
232
- ### 8. GitNexus integration (GitNexus 集成, when indexed)
233
-
234
- **Before review**: use `gitnexus_impact` to analyze the change impact scope
235
- ```bash
236
- npx gitnexus impact {modified_symbol}
237
- ```
238
-
239
- **Review scope priority (审查范围优先):**
240
- 1. files marked HIGH/CRITICAL by `gitnexus_impact`
241
- 2. directly modified files in `modified_files`
242
- 3. dependency files marked MEDIUM by `gitnexus_impact`
243
-
244
- **Risk-level mapping (风险级别对应):**
245
-
246
- | GitNexus risk | Code review severity |
247
- |---------------|---------------|
248
- | CRITICAL | High |
249
- | HIGH | High |
250
- | MEDIUM | Medium |
251
- | LOW | Low |
252
-
253
- ---
254
-
255
- ## Hook invocation (Hook 调用方式)
256
-
257
- In `check-phase-advancement.py`:
258
-
259
- ```bash
260
- if [ "$old_phase" = "P2" ] && [ "$new_phase" = "P3" ]; then
261
- # invoke the code-review skill
262
- claude --skill code-review
263
- # decide whether to allow advancement based on the result
264
- fi
1
+ ---
2
+ name: code-review
3
+ description: "AI code quality review (auto after P2; manual /code-review). | 触发词:代码审查/质量检查"
4
+ allowed-tools:
5
+ - Read
6
+ - Glob
7
+ - Write
8
+ - Edit
9
+ - AskUserQuestion
10
+ ---
11
+
12
+ Usage: `/code-review [file path]`
13
+
14
+ Arguments: $ARGUMENTS
15
+
16
+ ---
17
+
18
+ ## Execution logic (执行逻辑)
19
+
20
+ ### 1. Read project state
21
+ Read from `project-state.md`:
22
+ - `modified_files` list
23
+ - `current_phase`, verify it is P2
24
+
25
+ ### 2. Determine the review scope
26
+ - If a file path argument is provided → review that file
27
+ - Otherwise → use the `modified_files` list
28
+
29
+ ### 3. AI-review each file
30
+ Review standards (based on the Alibaba Java Development Manual):
31
+
32
+ **Naming (命名规范):**
33
+ - Class names: PascalCase (e.g. `UserService`)
34
+ - Methods/variables: camelCase (e.g. `getUser`)
35
+ - Constants: UPPER_SNAKE (e.g. `MAX_SIZE`)
36
+ - Package names: all lowercase
37
+
38
+ **Code style (代码风格):**
39
+ - Indentation: 4 spaces
40
+ - Braces: opening brace stays on the same line
41
+ - Line length: ≤ 100
42
+ - one statement per line
43
+
44
+ **Method standards (方法规范):**
45
+ - Method length: ≤ 80 lines
46
+ - Parameter count: ≤ 5
47
+ - returning null must be documented in a comment
48
+
49
+ **Exception handling (异常处理):**
50
+ - catch specific exceptions, not `catch Exception`
51
+ - catch blocks must not be empty
52
+ - handle or rethrow after catching
53
+
54
+ **Resource management (资源管理):**
55
+ - IO streams must be closed (use try-with-resources)
56
+ - DB connections must be closed
57
+
58
+ **Best practices (最佳实践):**
59
+ - avoid magic values (use constants or enums)
60
+ - avoid hardcoded config (put in config files)
61
+ - String comparison uses `"abc".equals(str)` to avoid NPE
62
+ - use `StringBuilder` for heavy string concatenation
63
+
64
+ **Security (安全性):**
65
+ - avoid SQL concatenation (use `PreparedStatement`)
66
+ - mask sensitive data (passwords, tokens in logs)
67
+ - avoid hardcoded secrets
68
+
69
+ **Loop DB inserts (循环插入数据库, high risk - must fix):**
70
+
71
+ | Check | Description |
72
+ |--------|------|
73
+ | **insert inside for/while loop** | `insert`/`update`/`delete` inside a loop body |
74
+ | **batch insert not optimized** | loop inserts instead of batch insert |
75
+ | **per-commit without transaction** | committing one by one in a loop, no batch transaction control |
76
+
77
+ **Anti-patterns (反例, high-risk issues):**
78
+ ```java
79
+ // Anti-pattern: inserting one by one inside a for loop
80
+ for (User user : userList) {
81
+ jdbcTemplate.update("INSERT INTO user VALUES (?, ?)", user.getId(), user.getName());
82
+ }
83
+
84
+ // Anti-pattern: updating one by one inside a for loop
85
+ for (Order order : orders) {
86
+ orderDao.update(order);
87
+ }
88
+
89
+ // Anti-pattern: query-then-update inside a for loop
90
+ for (Item item : items) {
91
+ if (itemDao.findById(item.getId()) != null) {
92
+ itemDao.update(item);
93
+ }
94
+ }
95
+ ```
96
+
97
+ **Good patterns (正例, recommended fix):**
98
+ ```java
99
+ // Good: JDBC Batch insert
100
+ jdbcTemplate.batchUpdate("INSERT INTO user VALUES (?, ?)",
101
+ userList, userList.size(),
102
+ (ps, user) -> {
103
+ ps.setLong(1, user.getId());
104
+ ps.setString(2, user.getName());
105
+ });
106
+
107
+ // Good: MyBatis batch insert
108
+ <insert id="batchInsert" useGeneratedKeys="true">
109
+ INSERT INTO user (id, name) VALUES
110
+ <foreach collection="list" item="user" separator=",">
111
+ (#{user.id}, #{user.name})
112
+ </foreach>
113
+ </insert>
114
+
115
+ // Good: batched processing + transaction control
116
+ @Transactional
117
+ public void processOrders(List<Order> orders) {
118
+ // process in batches of 500
119
+ List<List<Order>> batches = Lists.partition(orders, 500);
120
+ for (List<Order> batch : batches) {
121
+ orderDao.batchUpdate(batch);
122
+ }
123
+ }
124
+ ```
125
+
126
+ **Detection logic (判断逻辑):**
127
+ 1. detect `for`/`while`/`do-while` loop keywords
128
+ 2. detect DB operations in the loop body: `insert`/`update`/`delete`/`save`/`remove`/`find`/`query`
129
+ 3. if DB operations are found inside a loop → mark as **high-risk issue**
130
+ 4. further check whether batch APIs are used (`batchUpdate`/`batchInsert`/`partition`)
131
+
132
+ **Severity definitions (严重程度定义):**
133
+
134
+ | Level | Definition | Handling |
135
+ |------|------|----------|
136
+ | **High** | blocking issues: memory leaks, security holes, data inconsistency | must fix |
137
+ | **Medium** | functional risks: NPE, unclosed resources, logic errors | suggested fix |
138
+ | **Low** | code standards: unclear naming, format issues | optional fix |
139
+
140
+ **Issue categories (问题分类):**
141
+
142
+ | Category | Contains |
143
+ |------|----------|
144
+ | **Naming** | class names, method names, variable names, constant names, package names |
145
+ | **Code style** | indentation, braces, line length, comment standards |
146
+ | **Performance/security** | SQL injection, XSS, sensitive data, concurrency safety, loop batch operations |
147
+ | **Best practices** | NPE protection, resource management, exception handling |
148
+
149
+ **Multi-language support (多语言支持):**
150
+
151
+ | Language | Extra checks |
152
+ |------|-----------|
153
+ | Java | thread safety, generics, wildcards, Stream API |
154
+ | Python | indentation, type annotations, PEP8, list comprehensions |
155
+ | Go | error handling, goroutine leaks, context usage |
156
+ | JavaScript/TypeScript | callback hell, Promise, async/await, type checking |
157
+
158
+ ### 4. Generate the review report
159
+ Save to `.claude/code-review-report.md`:
160
+
161
+ ```markdown
162
+ # AI Code Review Report (AI 代码审查报告)
163
+
164
+ - Review time (审查时间): {time}
165
+ - Files reviewed (审查文件): {n}
166
+ - Issues found (发现问题): {n} (high {h} / medium {m} / low {l})
167
+ - Handling (处理方式): {pending/done/ignored (待处理/已处理/已忽略)}
168
+
169
+ ## Issue summary (问题汇总)
170
+
171
+ | Category | High | Medium | Low | Total |
172
+ |------|------|------|------|------|
173
+ | Naming | 0 | 0 | 0 | 0 |
174
+ | Code style | 0 | 0 | 0 | 0 |
175
+ | Performance/security | 0 | 0 | 0 | 0 |
176
+ | Best practices | 0 | 0 | 0 | 0 |
177
+
178
+ ## Issue list (问题列表)
179
+
180
+ **Issue 1: {title}**
181
+ - File (文件): {path}
182
+ - Location (位置): line {n}
183
+ - Category (分类): {naming/code style/performance-security/best practices}
184
+ - Severity (严重性): {high/medium/low}
185
+ - Current code (当前代码):
186
+ ```java
187
+ {snippet}
188
+ ```
189
+ - Suggested fix (建议修复): {description}
190
+ - Status (状态): {unfixed/fixed/ignored (未修复/已修复/已忽略)}
191
+ ```
192
+
193
+ ### 5. Interaction handling (交互处理)
194
+ If issues are found:
195
+ - Show the issue list
196
+ - Use AskUserQuestion to let the user choose:
197
+ - **A. Auto-fix**: AI generates the fix; apply after user confirmation
198
+ - **B. Manual fix**: return to P2
199
+ - **C. Ignore**: record the exemption, continue to P3
200
+
201
+ ### 6. Return result (返回结果)
202
+ Output JSON:
203
+ ```json
204
+ {
205
+ "passed": true/false,
206
+ "issues_count": 3,
207
+ "high_severity": 1,
208
+ "action": "auto_fix/manual_fix/ignore",
209
+ "message": "review complete (审查完成)"
210
+ }
211
+ ```
212
+
213
+ **Judgment logic (判断逻辑):**
214
+ - `passed = true`: no issues, or all issues fixed/ignored
215
+ - `passed = false`: unresolved high/medium issues exist
216
+
217
+ ### 7. Retry mechanism (重试机制)
218
+
219
+ Based on `review_retry_count`:
220
+
221
+ | Retries | Handling |
222
+ |----------|----------|
223
+ | 0 | first review; after issues found, wait for the user's choice |
224
+ | 1-3 | re-review after fixes |
225
+ | > 3 | force stop and ask the user to intervene |
226
+
227
+ **When over the retry limit:**
228
+ - stop auto-fixing
229
+ - save the current review report
230
+ - prompt the user to handle manually
231
+
232
+ ### 8. GitNexus integration (GitNexus 集成, when indexed)
233
+
234
+ **Before review**: use `gitnexus_impact` to analyze the change impact scope
235
+ ```bash
236
+ npx gitnexus impact {modified_symbol}
237
+ ```
238
+
239
+ **Review scope priority (审查范围优先):**
240
+ 1. files marked HIGH/CRITICAL by `gitnexus_impact`
241
+ 2. directly modified files in `modified_files`
242
+ 3. dependency files marked MEDIUM by `gitnexus_impact`
243
+
244
+ **Risk-level mapping (风险级别对应):**
245
+
246
+ | GitNexus risk | Code review severity |
247
+ |---------------|---------------|
248
+ | CRITICAL | High |
249
+ | HIGH | High |
250
+ | MEDIUM | Medium |
251
+ | LOW | Low |
252
+
253
+ ---
254
+
255
+ ## Hook invocation (Hook 调用方式)
256
+
257
+ In `check-phase-advancement.py`:
258
+
259
+ ```bash
260
+ if [ "$old_phase" = "P2" ] && [ "$new_phase" = "P3" ]; then
261
+ # invoke the code-review skill
262
+ claude --skill code-review
263
+ # decide whether to allow advancement based on the result
264
+ fi
265
265
  ```
@@ -1,6 +1,6 @@
1
1
  ---
2
2
  name: executing-plans
3
- description: "Execute a written implementation plan in a separate session with review checkpoints. | 触发词:执行计划/按计划执行"
3
+ description: "Execute a written implementation plan in a separate session with review checkpoints. | 触发词:执行计划/按计划执行"
4
4
  ---
5
5
 
6
6
  # Executing Plans