ai-engineering-init 1.13.0 → 1.14.1

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.
@@ -1,8 +1,8 @@
1
1
  ---
2
2
  name: collaborating-with-codex
3
3
  description: |
4
- OpenAI Codex CLI 协同开发。支持 MCP 原生集成和桥接脚本两种模式。
5
- 默认模型:gpt-5.3-codex
4
+ 与 Codex MCP 协同开发。通过 GuDaStudio/codexmcp 集成,使用 mcp__codex__codex 工具。
5
+ 默认沙箱:read-only(严禁 codex 修改真实代码)。
6
6
 
7
7
  触发场景:
8
8
  - 需要算法实现或复杂逻辑分析
@@ -14,110 +14,128 @@ description: |
14
14
  触发词:Codex、协作、多模型、原型、Diff、算法分析、代码审查、codex协同
15
15
 
16
16
  前置要求:
17
- - 已安装 Codex CLI (npm install -g @openai/codex)
18
- - 已配置 OpenAI API Key (codex auth login)
17
+ - 已通过 `claude mcp add codex -s user --transport stdio -- uvx --from git+https://github.com/GuDaStudio/codexmcp.git codexmcp` 注册
18
+ - ~/.claude/settings.json permissions.allow 已加入 mcp__codex__codex
19
19
  ---
20
20
 
21
- # 与 Codex CLI 协同开发
21
+ # 与 Codex MCP 协同开发
22
22
 
23
- > 两种调用方式:**MCP 原生集成**(推荐)和桥接脚本。默认模型 `gpt-5.3-codex`。
23
+ > 通过 `mcp__codex__codex` 工具直接调用,无需命令行。始终使用 `read-only` 沙箱,要求 codex 只输出 unified diff patch。
24
24
 
25
25
  ---
26
26
 
27
- ## 方式一:MCP 原生集成(推荐)
27
+ ## MCP 工具说明
28
28
 
29
- 已通过 `codex-mcp-server` 注册为 Claude Code 的 MCP 工具,可直接在对话中使用。
29
+ ### 工具名
30
+ `mcp__codex__codex`
30
31
 
31
- ### MCP 工具列表
32
+ ### 参数
32
33
 
33
- | 工具 | 用途 | 示例指令 |
34
- |------|------|---------|
35
- | `codex` | AI 编码助手,支持会话、模型选择 | "用 codex 分析这个函数" |
36
- | `review` | 代码审查(未提交代码、分支、提交) | "用 codex review 检查 main 分支差异" |
37
- | `listSessions` | 查看活跃会话 | "列出 codex 会话" |
38
- | `ping` | 测试连接 | "ping codex" |
39
-
40
- ### MCP 使用示例
34
+ | 参数 | 类型 | 必填 | 默认值 | 说明 |
35
+ |------|------|------|--------|------|
36
+ | `PROMPT` | string | | - | 发送给 Codex 的任务指令(建议用英语) |
37
+ | `cd` | Path | | - | 工作目录根路径(必须存在) |
38
+ | `sandbox` | string | | `read-only` | `read-only` / `workspace-write` / `danger-full-access` |
39
+ | `SESSION_ID` | UUID | | None | 继续之前的会话,保持上下文 |
40
+ | `return_all_messages` | bool | ❌ | False | 是否返回推理过程和工具调用详情 |
41
+ | `model` | string | ❌ | None | 指定模型(None 使用用户默认配置) |
42
+ | `image` | List[Path] | ❌ | None | 附加图片文件 |
43
+ | `yolo` | bool | ❌ | False | 跳过沙箱审批(危险,不推荐) |
44
+ | `profile` | string | ❌ | None | 从 `~/.codex/config.toml` 加载的配置名 |
45
+ | `skip_git_repo_check` | bool | ❌ | False | 允许在非 Git 仓库中运行 |
46
+
47
+ ### 返回值
48
+
49
+ ```json
50
+ // 成功
51
+ {
52
+ "success": true,
53
+ "SESSION_ID": "uuid-string", // 必须保存,用于多轮交互
54
+ "agent_messages": "codex回复内容"
55
+ }
56
+
57
+ // 失败
58
+ {
59
+ "success": false,
60
+ "error": "错误信息"
61
+ }
62
+ ```
41
63
 
42
- **基础调用**:直接在 Claude Code 对话中说:
43
- - "用 codex 工具分析 OrderInfoService 的业务逻辑"
44
- - "用 codex review 检查当前未提交的代码变更"
45
- - "用 codex 生成这个方法的单元测试,模型用 gpt-5.3-codex"
64
+ ---
46
65
 
47
- **多轮会话**:codex 工具支持 `sessionId` 参数,自动维持上下文。
66
+ ## 标准协作流程
48
67
 
49
- **模型指定**:调用时传入 `model: "gpt-5.3-codex"` 参数(已配置为默认)。
68
+ ```
69
+ 1. 需求分析阶段
70
+ Claude 形成初步分析 → 告知 codex → codex 完善方案
50
71
 
51
- ### MCP 配置位置
72
+ 2. 编码前(原型阶段)
73
+ 调用 codex(read-only)→ 要求输出 unified diff patch
74
+ Claude 以 diff 为逻辑参考 → 重写为生产级代码
52
75
 
53
- ```
54
- ~/.claude.json projects mcpServers codex-cli
55
- ~/.codex/config.toml → profiles(review/analyze/prototype)
76
+ 3. 编码后(审查阶段)
77
+ 调用 codex review 改动验证需求完成度和代码质量
56
78
  ```
57
79
 
58
80
  ---
59
81
 
60
- ## 方式二:桥接脚本
82
+ ## 调用示例
61
83
 
62
- 适用于需要精细控制参数或后台批量执行的场景。
84
+ ### 场景一:需求分析完善
63
85
 
64
- ### 快速开始
86
+ ```
87
+ PROMPT: "Here is my requirement: [需求描述]. My initial approach: [初步思路].
88
+ Please review and improve the analysis and implementation plan.
89
+ Output: structured analysis with potential risks."
65
90
 
66
- ```bash
67
- python .claude/skills/collaborating-with-codex/scripts/codex_bridge.py \
68
- --cd . --model gpt-5.3-codex --PROMPT "Your task"
91
+ cd: /path/to/project
92
+ sandbox: read-only
69
93
  ```
70
94
 
71
- ### 参数说明
95
+ ### 场景二:获取代码原型(Diff)
72
96
 
73
- | 参数 | 类型 | 必填 | 默认值 | 说明 |
74
- |------|------|------|--------|------|
75
- | `--PROMPT` | str | ✅ | - | 发送给 Codex 的任务指令(使用英语) |
76
- | `--cd` | Path | ✅ | - | 工作目录根路径 |
77
- | `--model` | str | ❌ | `gpt-5.3-codex` | 指定模型 |
78
- | `--sandbox` | Literal | ❌ | `read-only` | 沙箱策略 |
79
- | `--SESSION_ID` | UUID | ❌ | `None` | 会话 ID(继续之前的对话) |
80
- | `--profile` | str | ❌ | `None` | Codex profile(review/analyze/prototype) |
81
- | `--return-all-messages` | bool | ❌ | `False` | 返回完整推理信息 |
82
- | `--image` | List[Path] | ❌ | `None` | 附加图片 |
83
- | `--yolo` | bool | ❌ | `False` | 跳过审批(危险) |
84
-
85
- ### 使用示例
97
+ ```
98
+ PROMPT: "Generate a unified diff patch to implement [功能描述].
99
+ File: [目标文件路径]
100
+ Requirements:
101
+ - [要求1]
102
+ - [要求2]
86
103
 
87
- ```bash
88
- # 代码分析(只读)
89
- python .claude/skills/collaborating-with-codex/scripts/codex_bridge.py \
90
- --cd . --model gpt-5.3-codex --profile analyze \
91
- --PROMPT "Analyze the four-layer architecture in OrderInfoWebController"
92
-
93
- # 代码审查
94
- python .claude/skills/collaborating-with-codex/scripts/codex_bridge.py \
95
- --cd . --model gpt-5.3-codex --profile review \
96
- --PROMPT "Review OrderWebBusiness.java for bugs. OUTPUT: Review with line numbers."
97
-
98
- # 生成 Diff 补丁
99
- python .claude/skills/collaborating-with-codex/scripts/codex_bridge.py \
100
- --cd . --model gpt-5.3-codex \
101
- --PROMPT "Generate unified diff to add logging. OUTPUT: Unified Diff Patch ONLY."
102
-
103
- # 多轮会话
104
- python .claude/skills/collaborating-with-codex/scripts/codex_bridge.py \
105
- --cd . --model gpt-5.3-codex \
106
- --SESSION_ID "uuid-from-previous" \
107
- --PROMPT "Now write unit tests for the method we discussed"
104
+ IMPORTANT: Output unified diff patch ONLY. Do NOT modify any real files.
105
+ IMPORTANT: All Java comments and SQL COMMENTs MUST be in Chinese."
106
+
107
+ cd: /path/to/project
108
+ sandbox: read-only
108
109
  ```
109
110
 
110
- ---
111
+ ### 场景三:代码审查
112
+
113
+ ```
114
+ PROMPT: "Review the following code changes for correctness, performance, and security.
115
+ [粘贴代码或说明文件路径]
116
+
117
+ Check:
118
+ 1. Logic correctness
119
+ 2. Edge cases
120
+ 3. Performance issues
121
+ 4. Security vulnerabilities
122
+
123
+ Output: review with line numbers and severity (CRITICAL/WARNING/INFO)."
124
+
125
+ cd: /path/to/project
126
+ sandbox: read-only
127
+ ```
111
128
 
112
- ## Codex Profile 配置
129
+ ### 场景四:多轮交互(继续会话)
113
130
 
114
- 已在 `~/.codex/config.toml` 中预设 3 个 profile:
131
+ ```
132
+ // 第一轮
133
+ SESSION_ID: None → 保存返回的 SESSION_ID
115
134
 
116
- | Profile | 模型 | 沙箱 | 推理强度 | 适用场景 |
117
- |---------|------|------|---------|---------|
118
- | `review` | gpt-5.3-codex | read-only | medium | 快速代码审查 |
119
- | `analyze` | gpt-5.3-codex | read-only | high | 深度逻辑分析 |
120
- | `prototype` | gpt-5.3-codex | workspace-write | high | 原型生成 |
135
+ // 第二轮
136
+ SESSION_ID: "上一轮返回的 uuid"
137
+ PROMPT: "Now refine the diff based on the feedback: [反馈内容]"
138
+ ```
121
139
 
122
140
  ---
123
141
 
@@ -125,24 +143,18 @@ python .claude/skills/collaborating-with-codex/scripts/codex_bridge.py \
125
143
 
126
144
  | 角色 | Claude Code 负责 | Codex 负责 |
127
145
  |------|-----------------|-----------|
128
- | **架构** | 设计、决策、审校 | 分析现有代码 |
129
- | **开发** | 规范重构、最终代码 | 原型生成(Diff) |
130
- | **审查** | 规范检查、最终判定 | 逐文件审查、安全扫描 |
131
- | **调试** | 日志分析、定位 | 深度代码分析、补丁 |
146
+ | **架构** | 设计决策、规范审校 | 分析现有代码结构 |
147
+ | **开发** | 规范重写、最终代码实施 | 输出原型 diff(只读参考) |
148
+ | **审查** | 规范检查、最终判定 | 逐文件逻辑审查 |
149
+ | **调试** | 日志分析、问题定位 | 深度代码分析、补丁建议 |
132
150
 
133
151
  ### 重要约束
134
152
 
135
- 1. **只读优先**: 默认 `read-only`,仅原型生成用 `workspace-write`
136
- 2. **英语 Prompt**: Codex 交互用英语
137
- 3. **中文强制**: 每次 PROMPT 末尾追加:
138
- ```
139
- IMPORTANT LANGUAGE RULES:
140
- - All SQL COMMENT values MUST be in Chinese
141
- - All Java/code comments MUST be in Chinese
142
- - Variable names and class names remain in English
143
- ```
144
- 4. **脏原型思维**: Codex 输出视为草稿,Claude 按项目规范重构
145
- 5. **后台运行**: 长时间任务用 subagent `run_in_background`
153
+ 1. **只读优先**:始终使用 `sandbox="read-only"`
154
+ 2. **英语 Prompt**:与 codex 交互用英语,代码注释要求中文
155
+ 3. **脏原型思维**:codex 输出视为草稿,Claude 按项目规范重构
156
+ 4. **保存 SESSION_ID**:每次调用后记录,多轮对话时传入
157
+ 5. **质疑 codex**:codex 仅供参考,必须有独立判断
146
158
 
147
159
  ---
148
160
 
@@ -150,8 +162,19 @@ python .claude/skills/collaborating-with-codex/scripts/codex_bridge.py \
150
162
 
151
163
  | 问题 | 解决方案 |
152
164
  |------|---------|
153
- | MCP 工具未出现 | 重启 Claude Code 会话,检查 `~/.claude.json` |
154
- | `codex: command not found` | `npm i -g @openai/codex` 并确认 PATH |
155
- | 模型不对 | 调用时显式传 `model: "gpt-5.3-codex"` |
156
- | MCP 连接超时 | `npx -y codex-mcp-server` 手动测试 |
157
- | 桥接脚本 SESSION_ID 失败 | 检查网络和 API Key |
165
+ | 工具未出现 | 重启 Claude Code,检查 `~/.claude.json` 中 codex 配置 |
166
+ | `cd` 参数报错 | 确认目录存在,使用绝对路径 |
167
+ | 连接超时 | 检查网络,`uvx --from git+https://github.com/GuDaStudio/codexmcp.git codexmcp` 手动测试 |
168
+ | SESSION_ID 失效 | 重新开启新会话(不传 SESSION_ID) |
169
+ | codex 修改了文件 | 确认 `sandbox="read-only"` 已设置 |
170
+
171
+ ## 安装验证
172
+
173
+ ```bash
174
+ # 查看 MCP 配置
175
+ cat ~/.claude.json | python3 -c "import json,sys; d=json.load(sys.stdin); print(d.get('mcpServers', {}).get('codex', 'not found'))"
176
+
177
+ # 重启后运行
178
+ claude mcp list
179
+ # 期望看到: codex: uvx ... - ✓ Connected
180
+ ```
@@ -394,9 +394,186 @@ public class OrderService {
394
394
  }
395
395
  ```
396
396
 
397
- ## 通用代码规范
397
+ ## 数据类型规范
398
+
399
+ ### 布尔字段命名
400
+
401
+ ```java
402
+ // ❌ 错误:前缀冗余、类型错误
403
+ private Integer ifNarrow;
404
+ private Integer isEnabled;
405
+
406
+ // ✅ 正确:Boolean 类型,无前缀
407
+ private Boolean narrow; // getter → isNarrow()
408
+ private Boolean enabled; // getter → isEnabled()
409
+ ```
410
+
411
+ ### 枚举字段标注
412
+
413
+ ```java
414
+ // ❌ 错误:只靠注释 @see
415
+ /** @see AccTradeTypeEnum */
416
+ private Integer tradeType;
417
+
418
+ // ✅ 方案一:VO/DTO 用枚举类型(配合 @JsonValue)
419
+ private AccTradeTypeEnum tradeType;
420
+
421
+ // ✅ 方案二:@ApiModelProperty 标注合法值
422
+ @ApiModelProperty(value = "操作类型:1-充值 2-消费 3-退款", allowableValues = "1,2,3")
423
+ private Integer tradeType;
424
+ ```
425
+
426
+ ## MyBatis-Plus 安全规范
427
+
428
+ ### selectOne 必须有唯一保障
429
+
430
+ ```java
431
+ // ❌ 危险:多条记录时抛 TooManyResultsException
432
+ Entity entity = mapper.selectOne(wrapper);
433
+
434
+ // ✅ 方案一:LIMIT 1
435
+ Entity entity = mapper.selectOne(wrapper.last("LIMIT 1"));
436
+
437
+ // ✅ 方案二:selectList 取第一条
438
+ List<Entity> list = mapper.selectList(wrapper);
439
+ Entity entity = CollUtil.isNotEmpty(list) ? list.get(0) : null;
440
+
441
+ // ✅ 方案三:确保有唯一索引(注释说明)
442
+ // 唯一索引:UNIQUE KEY (order_no, del_flag)
443
+ Entity entity = mapper.selectOne(wrapper);
444
+ ```
445
+
446
+ ### 存在性判断用 EXISTS,禁用 selectCount
447
+
448
+ ```java
449
+ // ❌ 低效:100万行表 ~200ms
450
+ Long count = mapper.selectCount(wrapper);
451
+ if (count > 0) { ... }
452
+
453
+ // ✅ 高效:~2ms(MyBatis-Plus 3.5.4+)
454
+ boolean exists = mapper.exists(wrapper);
455
+
456
+ // ✅ 或 selectList + LIMIT 1
457
+ boolean exists = CollUtil.isNotEmpty(mapper.selectList(wrapper.last("LIMIT 1")));
458
+ ```
459
+
460
+ ### Wrapper 嵌套不超过 2 层
461
+
462
+ ```java
463
+ // ❌ 过于复杂的 Wrapper
464
+ wrapper.and(w -> w.eq(A::getType, type)
465
+ .or(q -> q.eq(A::getType, 0))
466
+ .or(!PersonTypeEnum.LABOUR.getKey().equals(type),
467
+ q -> q.eq(A::getType, PSN_TYPE_SHARED)));
468
+
469
+ // ✅ 复杂查询写到 XML 中
470
+ List<Entity> list = mapper.selectByTypeCondition(type, isLabour);
471
+ ```
472
+
473
+ ### 禁止 SELECT *
474
+
475
+ ```xml
476
+ <!-- ❌ 禁止 -->
477
+ <select id="selectAll">SELECT * FROM t_order WHERE del_flag = 2</select>
478
+
479
+ <!-- ✅ 明确列出字段 -->
480
+ <select id="selectAll">SELECT id, order_no, amount, status, crtime FROM t_order WHERE del_flag = 2</select>
481
+ ```
482
+
483
+ ## Redis 使用规范
484
+
485
+ ### 禁止 KEYS 命令
398
486
 
399
- 无论使用哪种项目架构,以下规范都是通用的:
487
+ ```java
488
+ // ❌ 严禁:KEYS 阻塞 Redis
489
+ Set<Object> keys = keysByPattern(pattern);
490
+ Set<Object> keys = redisTemplate.keys(pattern);
491
+
492
+ // ✅ 使用 Redisson deleteByPattern(内部 SCAN + UNLINK)
493
+ RedissonClient redisson = SpringUtil.getBean(RedissonClient.class);
494
+ redisson.getKeys().deleteByPattern(keyPattern);
495
+ ```
496
+
497
+ ## Optional 使用规范
498
+
499
+ ```java
500
+ // ❌ 错误:of() 不接受 null
501
+ Optional.of(value).orElse(defaultValue);
502
+
503
+ // ✅ 正确:ofNullable()
504
+ Optional.ofNullable(value).orElse(defaultValue);
505
+
506
+ // ✅ 链式安全转换
507
+ Optional.ofNullable(model.getReserveRate())
508
+ .map(BigDecimal::new)
509
+ .orElse(BigDecimal.ZERO);
510
+
511
+ // ❌ 禁止作为方法参数或类字段
512
+ // ✅ 允许作为方法返回值
513
+ ```
514
+
515
+ ## @Transactional 规范
516
+
517
+ ```java
518
+ // ❌ 默认只回滚 RuntimeException
519
+ @Transactional
520
+ public void createOrder() { ... }
521
+
522
+ // ✅ 显式指定 rollbackFor
523
+ @Transactional(rollbackFor = Exception.class)
524
+ public void createOrder() { ... }
525
+ ```
526
+
527
+ - 事务方法不要 try-catch 吞掉异常
528
+ - 只读查询不加 `@Transactional`
529
+
530
+ ## 业务逻辑分层规范
531
+
532
+ ```java
533
+ // ❌ 错误:业务判断混在数据操作中
534
+ public void processOrder(Long orderId) {
535
+ OrderInfo order = orderMapper.selectById(orderId);
536
+ if (order.getStatus() == 1 && order.getPayTime() != null
537
+ && ChronoUnit.HOURS.between(order.getPayTime(), LocalDateTime.now()) < 24) {
538
+ order.setStatus(2);
539
+ orderMapper.updateById(order);
540
+ accWalletService.deduct(order.getCustId(), order.getAmount());
541
+ }
542
+ }
543
+
544
+ // ✅ 正确:分层清晰
545
+ public void processOrder(Long orderId) {
546
+ OrderInfo order = orderMapper.selectById(orderId);
547
+ if (ObjectUtil.isNull(order)) {
548
+ throw new LeException(I18n.getMessage("order_not_found"));
549
+ }
550
+ checkCanProcess(order); // 业务校验(独立方法)
551
+ order.markAsProcessed(); // 状态变更(Entity 方法封装)
552
+ orderMapper.updateById(order);
553
+ afterOrderProcessed(order); // 后续动作(独立方法)
554
+ }
555
+ ```
556
+
557
+ | 层 | 职责 | 不应做的 |
558
+ |----|------|---------|
559
+ | Controller | 参数接收、格式转换 | 不含业务判断 |
560
+ | Business | 业务编排、跨 Service 协调 | 不直接操作 Mapper |
561
+ | Service | 单表 CRUD、单表事务 | 不含跨表业务逻辑 |
562
+ | Mapper | SQL 映射 | 不含业务逻辑 |
563
+
564
+ ## TODO 管理规范
565
+
566
+ ```java
567
+ // ❌ 错误
568
+ // TODO 修改一下
569
+
570
+ // ✅ 正确
571
+ // TODO(@陈沈杰, 2026-03-20, #TASK-1234): 移动端 AppId 赋值逻辑待产品确认
572
+ ```
573
+
574
+ - 不用的代码直接删除,不要注释保留
575
+
576
+ ## 通用代码规范
400
577
 
401
578
  1. **禁止使用 `SELECT *`**:明确指定字段
402
579
  2. **使用参数化查询**:`#{}` 而非 `${}`
@@ -29,7 +29,7 @@ description: |
29
29
  │ - 用户已给出完整字段列表
30
30
 
31
31
  └─ 复杂需求? ──→ Agent 路径(启动 requirements-analyzer)
32
- - 提供了 Axure 原型链接或截图
32
+ - 提供了 Axure 原型截图
33
33
  - 提供了云效任务编号
34
34
  - 多页面/多模块联动
35
35
  - 业务流程复杂,需要状态流转设计
@@ -45,34 +45,12 @@ description: |
45
45
 
46
46
  ## Agent 路径(复杂需求)
47
47
 
48
- ### Axure 链接处理(重要)
49
-
50
- > **Axure 是 SPA 应用,WebFetch 必定失败(TLS/JS 渲染问题)。禁止用 WebFetch 访问 Axure 链接。**
51
-
52
- 当用户提供 Axure 链接时,必须用 Playwright 截图:
53
-
54
- ```bash
55
- # 1. 先用 Playwright 截图(每个页面单独截)
56
- npx playwright screenshot --wait-for-timeout 3000 "https://xxx.axure.cloud/page1" /tmp/axure-1.png
57
- npx playwright screenshot --wait-for-timeout 3000 "https://xxx.axure.cloud/page2" /tmp/axure-2.png
58
-
59
- # 2. 截图完成后,将文件路径传给 image-reader Agent 分析
60
- # 3. 如果原型有多个页面,URL 通常带 #page 参数,逐页截图
61
- ```
62
-
63
- **判断规则**:
64
- - URL 包含 `axure.cloud` 或 `.axshare.com` → Playwright 截图
65
- - 用户说"Axure 链接" → Playwright 截图
66
- - 本地截图文件(.png/.jpg) → 直接 image-reader 分析
67
-
68
- ### 完整流程
69
-
70
48
  ```
71
49
  步骤 1:收集信息(从用户消息中提取)
72
- - Axure 原型链接 → Playwright 截图 → image-reader 分析
73
- - Axure 原型截图文件 → 直接 image-reader 分析
74
- - 云效任务编号 → task-fetcher 获取详情
50
+ - Axure 原型截图路径
51
+ - 云效任务编号
75
52
  - 需求描述文字
53
+ - 关联模块信息
76
54
 
77
55
  步骤 2:启动 requirements-analyzer Agent
78
56
  └── requirements-analyzer(Opus) 内部自动编排:
@@ -91,23 +69,13 @@ npx playwright screenshot --wait-for-timeout 3000 "https://xxx.axure.cloud/page2
91
69
  |---------------|---------|
92
70
  | 只有文字描述 | 快速路径(不启动 Agent) |
93
71
  | 文字 + 原型截图 | requirements-analyzer → 内部调 image-reader |
94
- | 文字 + Axure 链接 | Playwright 截图 → requirements-analyzer → image-reader |
95
72
  | 文字 + 云效任务号 | requirements-analyzer → 内部调 task-fetcher |
96
73
  | 原型截图 + 云效任务号 | requirements-analyzer → 内部并行调 image-reader + task-fetcher |
97
74
 
98
75
  ### 启动示例
99
76
 
100
77
  ```
101
- # 有 Axure 链接(先截图再分析)
102
- Bash: npx playwright screenshot --wait-for-timeout 3000 "https://xxx.axure.cloud/page1" /tmp/axure-1.png
103
- Bash: npx playwright screenshot --wait-for-timeout 3000 "https://xxx.axure.cloud/page2" /tmp/axure-2.png
104
-
105
- Agent(subagent_type="requirements-analyzer",
106
- prompt="分析以下 Axure 原型截图,输出需求分析报告和开发任务清单:
107
- 截图路径:/tmp/axure-1.png, /tmp/axure-2.png
108
- 需求描述:xxx")
109
-
110
- # 有原型截图文件
78
+ # 有原型截图
111
79
  Agent(subagent_type="requirements-analyzer",
112
80
  prompt="分析以下 Axure 原型截图,输出需求分析报告和开发任务清单:
113
81
  截图路径:/path/to/image1.png, /path/to/image2.png
@@ -142,4 +110,3 @@ Agent(subagent_type="requirements-analyzer",
142
110
  - 与 `bug-detective` / `fix-bug` 的区别:本技能面向**新功能开发前的需求分析**,不涉及 Bug 排查
143
111
  - 数据库设计必须遵循项目规范(雪花 ID、审计字段、del_flag=2 正常)
144
112
  - 如果需求信息不完整,主动列出需要确认的点,而不是猜测
145
- - **Axure 链接必须用 Playwright 截图,禁止 WebFetch**
@@ -101,6 +101,120 @@ feat(order): 新增订单导出功能
101
101
  Closes #123
102
102
  ```
103
103
 
104
+ ## 数据类型规范
105
+
106
+ ### 布尔语义字段必须使用 Boolean
107
+
108
+ ```java
109
+ // ❌ 错误
110
+ private Integer ifNarrow;
111
+ private Integer isEnabled;
112
+
113
+ // ✅ 正确
114
+ private Boolean narrow; // getter 自动生成 isNarrow()
115
+ private Boolean enabled; // getter 自动生成 isEnabled()
116
+ ```
117
+
118
+ **规则**:
119
+ - 语义为"是/否"的字段,类型必须为 `Boolean`
120
+ - 字段名不加 `if`/`is`/`has` 前缀(JavaBean 规范中 `Boolean` 的 getter 自动生成 `isXxx()`)
121
+ - 数据库字段使用 `TINYINT(1)` 或 `BIT(1)`
122
+
123
+ ### 枚举字段必须提供明确约束
124
+
125
+ ```java
126
+ // ❌ 错误:调用方无法知道合法值
127
+ @ApiModelProperty(value = "操作类型")
128
+ private Integer tradeType;
129
+
130
+ // ✅ 方案一:VO/DTO 层直接用枚举(推荐)
131
+ @ApiModelProperty(value = "操作类型")
132
+ private AccTradeTypeEnum tradeType;
133
+
134
+ // ✅ 方案二:保留 Integer 但标注合法值
135
+ @ApiModelProperty(value = "操作类型:1-充值 2-消费 3-退款", allowableValues = "1,2,3")
136
+ private Integer tradeType;
137
+ ```
138
+
139
+ ### 金额字段禁止使用浮点类型
140
+
141
+ ```java
142
+ // ❌ 错误
143
+ private Double amount;
144
+ private Float price;
145
+
146
+ // ✅ 正确:Entity/Service 层用 Long(分),VO 层展示用 BigDecimal(元)
147
+ private Long amountFen;
148
+ private BigDecimal amountYuan;
149
+ ```
150
+
151
+ ### 原始类型 vs 包装类型
152
+
153
+ | 场景 | 用原始类型 | 用包装类型 |
154
+ |------|----------|----------|
155
+ | Entity / VO / DTO 字段 | — | ✅ 统一用包装类型 |
156
+ | 方法参数(不允许 null) | ✅ `int count` | — |
157
+ | 方法参数(允许 null) | — | ✅ `Integer count` |
158
+ | 局部变量 | ✅ `int i = 0` | — |
159
+
160
+ ## Optional 使用规范
161
+
162
+ ```java
163
+ // ❌ 错误:of() 不接受 null,value 为 null 直接 NPE
164
+ Optional.of(value).orElse(defaultValue);
165
+
166
+ // ✅ 正确:ofNullable() 安全处理 null
167
+ Optional.ofNullable(value).orElse(defaultValue);
168
+
169
+ // ❌ 禁止:Optional 作为方法参数或类字段
170
+ public void process(Optional<String> name) { ... }
171
+ private Optional<String> name;
172
+
173
+ // ✅ 允许:Optional 作为方法返回值、链式处理
174
+ public Optional<Entity> findById(Long id) { ... }
175
+ Optional.ofNullable(entity).map(Entity::getConfig).orElse(DEFAULT_VALUE);
176
+ ```
177
+
178
+ ## @Transactional 规范
179
+
180
+ ```java
181
+ // ❌ 错误:默认只回滚 RuntimeException
182
+ @Transactional
183
+ public void createOrder() { ... }
184
+
185
+ // ✅ 正确:显式指定回滚异常
186
+ @Transactional(rollbackFor = Exception.class)
187
+ public void createOrder() { ... }
188
+ ```
189
+
190
+ - 所有 `@Transactional` 必须显式写 `rollbackFor = Exception.class`
191
+ - 只读查询不加 `@Transactional`(或用 `readOnly = true`)
192
+ - 事务方法不要 try-catch 吞掉异常,否则事务不回滚
193
+
194
+ ## TODO 管理规范
195
+
196
+ ```java
197
+ // ❌ 错误:无负责人、无日期、无跟踪
198
+ // TODO 修改一下
199
+
200
+ // ✅ 正确:完整 TODO 格式
201
+ // TODO(@陈沈杰, 2026-03-20, #TASK-1234): 移动端 AppId 赋值逻辑待产品确认
202
+ ```
203
+
204
+ - 每个 TODO 必须有对应的任务号
205
+ - 超过 2 个迭代未处理的 TODO 必须清理
206
+ - 不用的代码直接删除,不要注释保留
207
+
208
+ ## 代码格式化规范
209
+
210
+ | 项目 | 规范 |
211
+ |------|------|
212
+ | 缩进 | 4 个空格(不用 Tab) |
213
+ | 行宽 | 120 字符 |
214
+ | 大括号 | K&R 风格(同行开始) |
215
+ | 空行 | 方法间 1 个空行,逻辑块间 1 个空行 |
216
+ | import | 分组排序:java → jakarta → org → net → com,组间空行 |
217
+
104
218
  ## 代码示例
105
219
 
106
220
  ### 统一响应格式
@@ -161,3 +275,8 @@ public enum OrderStatusEnum {
161
275
  | Git 提交信息写"fix bug" | 写清楚修了什么:`fix(order): 修复金额计算精度丢失` |
162
276
  | Boolean 变量名:`flag` | 有意义的名字:`isActive`, `hasPermission` |
163
277
  | 缩写命名:`usr`, `mgr` | 完整命名:`user`, `manager` |
278
+ | `Optional.of(可能null值)` | `Optional.ofNullable(value)` |
279
+ | `@Transactional` 无 rollbackFor | `@Transactional(rollbackFor = Exception.class)` |
280
+ | TODO 无负责人和日期 | `// TODO(@负责人, 日期, #任务号): 描述` |
281
+ | 布尔字段用 `Integer` | 用 `Boolean` 类型 |
282
+ | 枚举字段无合法值说明 | `@ApiModelProperty` 标注合法值或直接用枚举类型 |