@miniidealab/openlogos 0.2.0 → 0.3.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.
Files changed (36) hide show
  1. package/dist/commands/init.d.ts +9 -2
  2. package/dist/commands/init.d.ts.map +1 -1
  3. package/dist/commands/init.js +219 -8
  4. package/dist/commands/init.js.map +1 -1
  5. package/dist/commands/sync.d.ts.map +1 -1
  6. package/dist/commands/sync.js +9 -41
  7. package/dist/commands/sync.js.map +1 -1
  8. package/dist/i18n.d.ts.map +1 -1
  9. package/dist/i18n.js +14 -0
  10. package/dist/i18n.js.map +1 -1
  11. package/dist/index.js +1 -1
  12. package/package.json +5 -2
  13. package/skills/api-designer/SKILL.en.md +209 -0
  14. package/skills/api-designer/SKILL.md +209 -0
  15. package/skills/architecture-designer/SKILL.en.md +181 -0
  16. package/skills/architecture-designer/SKILL.md +181 -0
  17. package/skills/change-writer/SKILL.en.md +146 -0
  18. package/skills/change-writer/SKILL.md +146 -0
  19. package/skills/code-reviewer/SKILL.en.md +204 -0
  20. package/skills/code-reviewer/SKILL.md +204 -0
  21. package/skills/db-designer/SKILL.en.md +212 -0
  22. package/skills/db-designer/SKILL.md +212 -0
  23. package/skills/merge-executor/SKILL.en.md +84 -0
  24. package/skills/merge-executor/SKILL.md +84 -0
  25. package/skills/prd-writer/SKILL.en.md +171 -0
  26. package/skills/prd-writer/SKILL.md +171 -0
  27. package/skills/product-designer/SKILL.en.md +228 -0
  28. package/skills/product-designer/SKILL.md +228 -0
  29. package/skills/project-init/SKILL.en.md +163 -0
  30. package/skills/project-init/SKILL.md +163 -0
  31. package/skills/scenario-architect/SKILL.en.md +214 -0
  32. package/skills/scenario-architect/SKILL.md +214 -0
  33. package/skills/test-orchestrator/SKILL.en.md +142 -0
  34. package/skills/test-orchestrator/SKILL.md +142 -0
  35. package/skills/test-writer/SKILL.en.md +247 -0
  36. package/skills/test-writer/SKILL.md +247 -0
@@ -0,0 +1,181 @@
1
+ # Skill: Architecture Designer
2
+
3
+ > 在逐场景的技术实现之前,建立项目的技术全局视图——系统架构、技术选型、部署拓扑和非功能性约束。确保后续的时序图、API 和代码生成在一致的架构约束下进行。
4
+
5
+ ## 触发条件
6
+
7
+ - 用户要求设计技术架构、做技术选型或规划系统架构
8
+ - 用户提到 "Phase 3 Step 0"、"架构设计"、"技术方案"
9
+ - Phase 2 产品设计文档已完成,需要开始 Phase 3
10
+ - 用户想要确定技术栈或部署方案
11
+
12
+ ## 核心能力
13
+
14
+ 1. 读取 Phase 1 需求文档和 Phase 2 产品设计文档,理解产品全貌
15
+ 2. 基于产品复杂度和场景特征,推荐适合的系统架构
16
+ 3. 为每项技术选型提供选型理由和替代方案对比
17
+ 4. 绘制系统架构图(Mermaid)和部署拓扑图
18
+ 5. 更新 `logos-project.yaml` 的 `tech_stack` 字段
19
+
20
+ ## 与 Phase 1/2 的衔接
21
+
22
+ 架构设计是 Phase 2(产品设计)到 Phase 3(技术实现)的桥梁。它的输入来自 Phase 1/2,输出影响 Phase 3 所有后续步骤:
23
+
24
+ | 输入(来自 Phase 1/2) | 输出(影响 Phase 3 后续步骤) |
25
+ |------------------------|------------------------------|
26
+ | 场景清单和复杂度 | 系统边界划分 → 时序图的参与方 |
27
+ | 非功能性需求(性能、安全) | 技术选型约束 → API 设计决策 |
28
+ | 产品交互方式(Web/Mobile/API) | 前端技术栈 → 原型实现方式 |
29
+ | 数据量和访问模式 | 数据库选型 → DB 设计 |
30
+ | 第三方服务依赖(支付、邮件等) | 集成方式 → 时序图中的外部参与方 |
31
+
32
+ ## 执行步骤
33
+
34
+ ### Step 1: 理解产品全貌
35
+
36
+ 读取以下文档,建立对项目的整体认知:
37
+
38
+ - **需求文档**(Phase 1):产品定位、核心场景、约束与边界
39
+ - **产品设计文档**(Phase 2):信息架构、页面结构、交互复杂度
40
+ - **已有的 `logos-project.yaml`**:当前 `tech_stack` 中是否已有初始选型
41
+
42
+ 重点提取:
43
+ - 核心场景数量和复杂度
44
+ - 是否有实时性需求(WebSocket、SSE)
45
+ - 是否有后台任务(定时任务、消息队列)
46
+ - 第三方服务依赖清单
47
+ - 用户规模预期
48
+
49
+ ### Step 2: 确定系统架构
50
+
51
+ 根据产品复杂度选择架构模式:
52
+
53
+ **简单项目**(个人 SaaS、工具类产品):
54
+ - 单体架构 + 单数据库
55
+ - 架构概要可以用一段文字 + 一张简图
56
+
57
+ **中等项目**(团队 SaaS、多角色系统):
58
+ - 前后端分离 + 单体后端 + 单数据库
59
+ - 可能需要对象存储、缓存等辅助服务
60
+
61
+ **复杂项目**(多服务、高并发、多端):
62
+ - 微服务 / 模块化单体
63
+ - 需要详细的架构决策记录(ADR)
64
+
65
+ 用 Mermaid 绘制系统架构图:
66
+
67
+ ```mermaid
68
+ graph TB
69
+ subgraph Frontend
70
+ Web[Web App - Next.js]
71
+ end
72
+ subgraph Backend
73
+ API[API Server - Node.js]
74
+ Worker[Background Worker]
75
+ end
76
+ subgraph Data
77
+ DB[(PostgreSQL)]
78
+ Cache[(Redis)]
79
+ S3[Object Storage]
80
+ end
81
+ subgraph External
82
+ Auth[Supabase Auth]
83
+ Email[SendGrid]
84
+ end
85
+
86
+ Web -->|REST API| API
87
+ API --> DB
88
+ API --> Cache
89
+ API --> S3
90
+ API --> Auth
91
+ Worker --> DB
92
+ Worker --> Email
93
+ ```
94
+
95
+ ### Step 3: 技术选型
96
+
97
+ 为每个技术维度给出选型和理由:
98
+
99
+ ```markdown
100
+ | 维度 | 选型 | 理由 | 备选方案 |
101
+ |------|------|------|---------|
102
+ | 语言 | TypeScript | 前后端统一、类型安全 | Go(性能优先时) |
103
+ | 前端框架 | Next.js 15 | SSR + RSC、生态成熟 | Astro(内容站)、Nuxt(Vue 生态) |
104
+ | 后端框架 | Hono | 轻量、边缘优先、TS 原生 | Express(生态)、Fastify(性能) |
105
+ | 数据库 | PostgreSQL | 功能丰富、JSONB、RLS | MySQL(简单场景) |
106
+ | 认证 | Supabase Auth | 开箱即用、RLS 集成 | NextAuth(自托管) |
107
+ | 部署 | Vercel + Supabase | 零运维、自动扩容 | AWS(自主控制) |
108
+ ```
109
+
110
+ **选型原则**:
111
+ - 优先选择团队已熟悉的技术
112
+ - 在无明显差异时,选择社区更大的方案
113
+ - 选型理由必须关联到具体的产品需求或约束
114
+
115
+ ### Step 4: 非功能性约束
116
+
117
+ 明确关键的非功能性要求:
118
+
119
+ - **性能目标**:核心 API 响应时间、页面加载时间
120
+ - **安全要求**:认证方式、数据加密、CORS 策略
121
+ - **可扩展性**:预期用户规模、数据增长估算
122
+ - **可观测性**:日志、监控、告警方案
123
+ - **开发体验**:本地开发环境、CI/CD 流程
124
+
125
+ ### Step 5: 外部依赖与测试策略
126
+
127
+ 梳理项目的所有外部服务依赖,为每个依赖确定编排测试阶段的隔离策略。此步骤的产出直接影响 Phase 3 Step 3(编排测试)能否顺利执行。
128
+
129
+ 1. 从架构图和时序图参与方中识别外部依赖(邮件、短信、验证码、支付、OAuth 等)
130
+ 2. 与用户确认每个依赖的测试策略
131
+
132
+ 可选的测试策略:
133
+
134
+ | 策略 | 说明 | 典型场景 |
135
+ |------|------|---------|
136
+ | `test-api` | 测试环境提供后门 API | 邮件/短信验证码 |
137
+ | `fixed-value` | 特定测试数据使用固定值 | 测试手机号固定验证码 |
138
+ | `env-disable` | 环境变量关闭该功能 | 图形验证码、滑块 |
139
+ | `mock-callback` | 编排中主动调用模拟回调 | 支付回调、Webhook |
140
+ | `mock-service` | 本地 mock 服务替代 | OAuth Provider |
141
+
142
+ 如果项目没有外部服务依赖(如纯 CLI 工具),可跳过此步骤。
143
+
144
+ ### Step 6: 更新 logos-project.yaml
145
+
146
+ 将确认的技术选型写入 `logos-project.yaml` 的 `tech_stack` 字段,将外部依赖和测试策略写入 `external_dependencies` 字段,确保后续所有 Skill 和 AI 工具都能读取到统一的技术栈和测试约定。
147
+
148
+ ```yaml
149
+ external_dependencies:
150
+ - name: "邮件服务"
151
+ provider: "SendGrid"
152
+ used_in: ["S01-用户注册", "S03-忘记密码"]
153
+ test_strategy: "test-api"
154
+ test_config: "GET /api/test/latest-email?to={email}"
155
+ ```
156
+
157
+ ## 输出规范
158
+
159
+ - 架构概要文档:`logos/resources/prd/3-technical-plan/1-architecture/01-architecture-overview.md`
160
+ - 架构图使用 Mermaid 格式
161
+ - 技术选型使用表格格式,每项必须有理由
162
+ - 更新 `logos-project.yaml` 的 `tech_stack` 和 `external_dependencies` 字段
163
+ - 简单项目允许精简输出(不强制所有章节)
164
+
165
+ ## 实践经验
166
+
167
+ - **不要过度设计**:独立开发者做 SaaS,单体 + PostgreSQL + Vercel 够用就行,不要上来就微服务
168
+ - **选型理由比选型本身重要**:写清楚"为什么选 X"比"选了 X"更有价值,因为项目演进时需要重新评估
169
+ - **架构图是时序图的前提**:架构图中的系统组件就是后续时序图的参与方,两者必须一致
170
+ - **tech_stack 是 AI 的锚**:后续 AI 生成代码时会读取 `logos-project.yaml` 的 `tech_stack`,选型不准确会导致生成的代码无法使用
171
+ - **非功能性约束宁可先宽后紧**:初期不要定太严格的性能目标,随着实际数据再收紧
172
+ - **测试策略必须在架构阶段决定**:验证码、支付等外部依赖的测试方案如果等到编排测试时才想,往往发现没有预留后门 API,导致编排测试无法全自动执行
173
+
174
+ ## 推荐提示词
175
+
176
+ 以下提示词可以直接复制给 AI 使用:
177
+
178
+ - `帮我设计技术架构`
179
+ - `基于产品设计帮我做技术选型`
180
+ - `帮我画系统架构图`
181
+ - `帮我确定技术栈并更新 logos-project.yaml`
@@ -0,0 +1,146 @@
1
+ # Skill: Change Writer
2
+
3
+ > Assist in writing change proposals — analyze the scope of change impact, generate a structured proposal.md and a phase-based tasks.md, ensuring changes are traceable and impact is controllable.
4
+
5
+ ## Trigger Conditions
6
+
7
+ - User has just run `openlogos change <slug>` and wants AI help filling in the proposal
8
+ - User describes a need to modify, add, or remove a scenario/feature
9
+ - User mentions "change proposal", "iteration", "requirement change"
10
+
11
+ ## Prerequisites
12
+
13
+ 1. Project is initialized (`logos/logos.config.json` exists)
14
+ 2. Change proposal directory has been created by CLI (`logos/changes/<slug>/` exists)
15
+ 3. Main documents are readable (effective documents exist in `logos/resources/`)
16
+
17
+ If prerequisites are not met, prompt the user to run `openlogos change <slug>` to create the proposal directory first.
18
+
19
+ ## Core Capabilities
20
+
21
+ 1. Understand the user's intended change
22
+ 2. Scan existing documents in `logos/resources/` to identify the affected scope
23
+ 3. Determine the change type based on change propagation rules (Requirement-level / Design-level / Interface-level / Code-level)
24
+ 4. Generate a compliant proposal.md
25
+ 5. Automatically break down tasks.md by change type
26
+
27
+ ## Execution Steps
28
+
29
+ ### Step 1: Understand the Change Intent
30
+
31
+ Confirm the following information with the user (ask follow-up questions if insufficient, up to 2 rounds):
32
+
33
+ - **What is the change**: What needs to be added, modified, or removed?
34
+ - **Reason for the change**: Why is this change needed? Is it from requirement feedback, a bug, or an optimization?
35
+ - **Related scenarios**: Which existing scenario IDs are involved (S01, S02...)?
36
+
37
+ ### Step 2: Analyze the Impact Scope
38
+
39
+ Scan documents in `logos/resources/` to determine the impact scope:
40
+
41
+ 1. Read requirement documents (`prd/1-product-requirements/`) to check related scenario definitions
42
+ 2. Read product design (`prd/2-product-design/`) to check related functional specs and prototypes
43
+ 3. Read technical plans (`prd/3-technical-plan/`) to check related sequence diagrams
44
+ 4. Read API documents (`api/`) to check related endpoints
45
+ 5. Read DB documents (`database/`) to check related table structures
46
+ 6. Read orchestration tests (`scenario/`) to check related test cases
47
+
48
+ ### Step 3: Determine the Change Type
49
+
50
+ Refer to change propagation rules to determine the change type and minimum update scope:
51
+
52
+ | Change Type | Minimum Updates Required |
53
+ |-------------|------------------------|
54
+ | Requirement-level change | Full chain (Requirements → Design → Architecture → API/DB → Orchestration → Code) |
55
+ | Design-level change | Prototypes + Scenarios + API/DB + Orchestration + Code |
56
+ | Interface-level change | API/DB + Orchestration + Code |
57
+ | Code-level fix | Code + Re-verification |
58
+
59
+ ### Step 4: Generate proposal.md
60
+
61
+ Generate using the following template and write to `logos/changes/<slug>/proposal.md`:
62
+
63
+ ```markdown
64
+ # Change Proposal: [Change Name]
65
+
66
+ ## Reason for Change
67
+ [Why is this change needed? What requirement/feedback/bug does it originate from?]
68
+
69
+ ## Change Type
70
+ [Requirement-level / Design-level / Interface-level / Code-level]
71
+
72
+ ## Change Scope
73
+ - Affected requirement documents: [List, down to filename and section]
74
+ - Affected functional specs: [List]
75
+ - Affected business scenarios: [Scenario ID list]
76
+ - Affected APIs: [Endpoint list]
77
+ - Affected DB tables: [Table name list]
78
+ - Affected orchestration tests: [List]
79
+
80
+ ## Change Summary
81
+ [Describe in 1-3 paragraphs what specifically will change]
82
+ ```
83
+
84
+ ### Step 5: Generate tasks.md
85
+
86
+ Automatically break down the task checklist based on the change type and impact scope. Only list the phases that need updating:
87
+
88
+ ```markdown
89
+ # Implementation Tasks
90
+
91
+ ## Phase 1: Document Changes
92
+ - [ ] Update acceptance criteria for S0x in requirement documents
93
+ - [ ] Add/modify scenario in the scenario overview table
94
+
95
+ ## Phase 2: Design Changes
96
+ - [ ] Update interaction design for S0x in functional specs
97
+ - [ ] Update prototypes
98
+
99
+ ## Phase 3: Technical Changes
100
+ - [ ] Update sequence diagram for S0x
101
+ - [ ] Update API YAML
102
+ - [ ] Update DB DDL
103
+ - [ ] Update orchestration test cases
104
+ - [ ] Implement code changes
105
+ ```
106
+
107
+ ### Step 6: Guide Follow-up Actions (Chain-driven)
108
+
109
+ Provide a ready-to-use prompt that allows the user to kick off chain execution of all tasks with a single command:
110
+
111
+ - **Requirement-level / Design-level changes** (multiple tasks): Suggest the user say "Follow tasks.md and help me progressively update all affected documents for S0x"
112
+ - **Code-level fixes** (fewer tasks): Suggest the user say "Help me fix the [issue description] for S0x and re-verify"
113
+
114
+ Chain execution behavior rules:
115
+ 1. AI reads `tasks.md` and executes items sequentially
116
+ 2. After completing each task, report a summary of changes and automatically prompt "Continue to the next item?"
117
+ 3. After the user says "Continue" or provides adjustments, proceed to the next item
118
+ 4. After all tasks are completed, remind the user to run `openlogos merge <slug>`
119
+
120
+ **Key principle**: Do not make the user manually track the task checklist — AI should proactively drive the process.
121
+
122
+ ## Output Specification
123
+
124
+ - File format: Markdown
125
+ - Storage location: `logos/changes/<slug>/`
126
+ - Filenames: `proposal.md` and `tasks.md` (overwrite the CLI-generated templates)
127
+
128
+ ## Best Practices
129
+
130
+ - **Overestimate the impact scope**: Missing an update in one link is more dangerous than double-checking
131
+ - **Change type determines workload**: Help users understand before they start that changing one requirement may require a full-chain update
132
+ - **tasks.md is the execution checklist**: Check off each item with `[x]` upon completion for easy progress tracking
133
+ - **Follow the process even for small changes**: A change that appears to be "just one API line" may affect orchestration tests and code
134
+
135
+ ## Recommended Prompts
136
+
137
+ The following prompts can be copied directly for use with AI:
138
+
139
+ **Fill in proposal**:
140
+ - `Help me fill in the change proposal <slug>`
141
+ - `I want to add a "remember password" feature to the S02 login scenario, help me analyze the impact scope`
142
+ - `This bug fix only involves the code layer, help me quickly write a proposal`
143
+
144
+ **Execute tasks (after proposal is completed)**:
145
+ - `Follow tasks.md and help me progressively update all affected documents for S02`
146
+ - `Help me fix the 500 error on the S02 login endpoint and re-verify`
@@ -0,0 +1,146 @@
1
+ # Skill: Change Writer
2
+
3
+ > 辅助填写变更提案——分析变更影响范围,生成结构化的 proposal.md 和按阶段拆解的 tasks.md,确保变更可追溯、影响可控。
4
+
5
+ ## 触发条件
6
+
7
+ - 用户刚运行完 `openlogos change <slug>` 并希望 AI 帮忙填写提案
8
+ - 用户描述需要修改、新增或删除某个场景/功能
9
+ - 用户提到"变更提案"、"change proposal"、"迭代"、"改需求"
10
+
11
+ ## 前置依赖
12
+
13
+ 1. 项目已初始化(`logos/logos.config.json` 存在)
14
+ 2. 变更提案目录已由 CLI 创建(`logos/changes/<slug>/` 存在)
15
+ 3. 主文档可读(`logos/resources/` 中有已生效的文档)
16
+
17
+ 如果前置条件不满足,提示用户先运行 `openlogos change <slug>` 创建提案目录。
18
+
19
+ ## 核心能力
20
+
21
+ 1. 理解用户描述的变更意图
22
+ 2. 扫描 `logos/resources/` 中的现有文档,定位受影响范围
23
+ 3. 根据变更传播规则判断变更类型(需求级 / 设计级 / 接口级 / 代码级)
24
+ 4. 生成符合规范的 proposal.md
25
+ 5. 按变更类型自动拆解 tasks.md
26
+
27
+ ## 执行步骤
28
+
29
+ ### Step 1: 理解变更意图
30
+
31
+ 与用户确认以下信息(信息不足则追问,最多 2 轮):
32
+
33
+ - **变更是什么**:要新增、修改还是删除什么?
34
+ - **变更原因**:为什么要做这个变更?来自需求反馈、Bug 还是优化?
35
+ - **关联场景**:涉及哪些已有场景编号(S01, S02...)?
36
+
37
+ ### Step 2: 分析影响范围
38
+
39
+ 扫描 `logos/resources/` 中的文档,确定影响范围:
40
+
41
+ 1. 读取需求文档(`prd/1-product-requirements/`),检查相关场景定义
42
+ 2. 读取产品设计(`prd/2-product-design/`),检查相关功能规格和原型
43
+ 3. 读取技术方案(`prd/3-technical-plan/`),检查相关时序图
44
+ 4. 读取 API 文档(`api/`),检查相关端点
45
+ 5. 读取 DB 文档(`database/`),检查相关表结构
46
+ 6. 读取编排测试(`scenario/`),检查相关测试用例
47
+
48
+ ### Step 3: 判断变更类型
49
+
50
+ 参照变更传播规则确定变更类型及最小更新范围:
51
+
52
+ | 变更类型 | 最少需要更新 |
53
+ |---------|------------|
54
+ | 需求级变更 | 全链路(需求 → 设计 → 架构 → API/DB → 编排 → 代码) |
55
+ | 设计级变更 | 原型 + 场景 + API/DB + 编排 + 代码 |
56
+ | 接口级变更 | API/DB + 编排 + 代码 |
57
+ | 代码级修复 | 代码 + 重新验收 |
58
+
59
+ ### Step 4: 生成 proposal.md
60
+
61
+ 按以下模板生成,写入 `logos/changes/<slug>/proposal.md`:
62
+
63
+ ```markdown
64
+ # 变更提案:[变更名称]
65
+
66
+ ## 变更原因
67
+ [为什么要做这个变更?来源于哪个需求/反馈/Bug?]
68
+
69
+ ## 变更类型
70
+ [需求级 / 设计级 / 接口级 / 代码级]
71
+
72
+ ## 变更范围
73
+ - 影响的需求文档:[列表,精确到文件名和章节]
74
+ - 影响的功能规格:[列表]
75
+ - 影响的业务场景:[场景编号列表]
76
+ - 影响的 API:[端点列表]
77
+ - 影响的 DB 表:[表名列表]
78
+ - 影响的编排测试:[列表]
79
+
80
+ ## 变更概述
81
+ [用 1-3 段话概述具体改什么]
82
+ ```
83
+
84
+ ### Step 5: 生成 tasks.md
85
+
86
+ 根据变更类型和影响范围,自动拆解任务清单。只列出需要更新的阶段:
87
+
88
+ ```markdown
89
+ # 实现任务
90
+
91
+ ## Phase 1: 文档变更
92
+ - [ ] 更新需求文档中 S0x 的验收条件
93
+ - [ ] 在场景总览表中新增/修改场景
94
+
95
+ ## Phase 2: 设计变更
96
+ - [ ] 更新功能规格中 S0x 的交互设计
97
+ - [ ] 更新原型
98
+
99
+ ## Phase 3: 技术变更
100
+ - [ ] 更新 S0x 的时序图
101
+ - [ ] 更新 API YAML
102
+ - [ ] 更新 DB DDL
103
+ - [ ] 更新编排测试用例
104
+ - [ ] 实现代码变更
105
+ ```
106
+
107
+ ### Step 6: 引导后续操作(链式驱动)
108
+
109
+ 提供一条可直接执行的提示词,让用户一句话启动全部任务的链式执行:
110
+
111
+ - **需求级 / 设计级变更**(多任务):建议用户说「按 tasks.md 帮我逐步更新 S0x 的所有受影响文档」
112
+ - **代码级修复**(少任务):建议用户说「帮我修复 S0x 的 [问题描述] 并重新验收」
113
+
114
+ 链式执行的行为规范:
115
+ 1. AI 读取 `tasks.md`,按顺序逐项执行
116
+ 2. 每完成一项任务,汇报修改摘要,并自动提示「继续下一项?」
117
+ 3. 用户说「继续」或给出调整意见后,执行下一项
118
+ 4. 全部任务完成后,提醒用户运行 `openlogos merge <slug>`
119
+
120
+ **关键原则**:不要让用户手动跟踪任务清单——AI 应主动驱动流程。
121
+
122
+ ## 输出规范
123
+
124
+ - 文件格式:Markdown
125
+ - 存放位置:`logos/changes/<slug>/`
126
+ - 文件名:`proposal.md` 和 `tasks.md`(覆盖 CLI 生成的模板)
127
+
128
+ ## 实践经验
129
+
130
+ - **宁可高估影响范围**:漏掉一个环节的更新比多检查一遍更危险
131
+ - **变更类型决定工作量**:帮助用户在动手前理解改一个需求可能需要全链路更新
132
+ - **tasks.md 是执行清单**:每完成一项打一个 `[x]`,方便追踪进度
133
+ - **小变更也走流程**:看似"只改一行 API"的变更,可能影响编排测试和代码
134
+
135
+ ## 推荐提示词
136
+
137
+ 以下提示词可以直接复制给 AI 使用:
138
+
139
+ **填写提案**:
140
+ - `帮我填写变更提案 <slug>`
141
+ - `我要给 S02 登录场景加一个记住密码功能,帮我分析影响范围`
142
+ - `这个 Bug 修复只涉及代码层,帮我快速写个提案`
143
+
144
+ **执行任务(提案填写完成后)**:
145
+ - `按 tasks.md 帮我逐步更新 S02 的所有受影响文档`
146
+ - `帮我修复 S02 登录接口的 500 错误并重新验收`
@@ -0,0 +1,204 @@
1
+ # Skill: Code Reviewer
2
+
3
+ > Review AI-generated code by performing systematic validation against the full OpenLogos specification chain (API YAML, sequence diagram EX cases, DB DDL), ensuring code is fully consistent with design documents, covers all exception paths, and meets security requirements.
4
+
5
+ ## Trigger Conditions
6
+
7
+ - User requests a code review or Code Review
8
+ - User mentions "Phase 3 Step 4", "code audit", "code review"
9
+ - AI has just generated code that needs quality verification
10
+ - Final check before deployment
11
+ - Need to locate code issues after orchestration test failures
12
+
13
+ ## Prerequisites
14
+
15
+ - `logos/resources/api/` contains API YAML specifications
16
+ - `logos/resources/prd/3-technical-plan/2-scenario-implementation/` contains scenario sequence diagrams (with EX cases)
17
+ - `logos/resources/database/` contains DB DDL
18
+ - The code to be reviewed is accessible
19
+
20
+ For projects without APIs (pure CLI / libraries), API consistency checks can be skipped; focus on sequence diagram coverage and exception handling instead.
21
+
22
+ ## Core Capabilities
23
+
24
+ 1. Validate code implementation consistency with API YAML specifications
25
+ 2. Check whether exception handling covers all EX cases
26
+ 3. Check whether DB operations conform to DDL design
27
+ 4. Check security policies (authentication, RLS, input validation)
28
+ 5. Check code style and best practices
29
+ 6. Output a structured review report
30
+
31
+ ## Execution Steps
32
+
33
+ ### Step 1: Load Specification Context
34
+
35
+ Read the following files to establish a "reference baseline" for the code review:
36
+
37
+ - **API YAML** (`logos/resources/api/*.yaml`): Extract endpoint inventory, record each endpoint's path, method, request body schema, response schema, and status codes
38
+ - **Scenario Sequence Diagrams** (`logos/resources/prd/3-technical-plan/2-scenario-implementation/`): Extract all EX exception case IDs and expected behaviors
39
+ - **DB DDL** (`logos/resources/database/`): Extract table structures, column types, constraints, and indexes
40
+ - **`logos-project.yaml`**: Read `tech_stack` to confirm the technology stack, `external_dependencies` to confirm external dependencies
41
+
42
+ Summarize into a review checklist:
43
+
44
+ ```markdown
45
+ Review scope: S01-related code
46
+ - API endpoints: 4 (auth.yaml)
47
+ - EX exception cases: 7 (EX-2.1 ~ EX-5.2)
48
+ - DB tables: 2 (users, profiles)
49
+ - Security policies: 2 RLS rules
50
+ ```
51
+
52
+ ### Step 2: API Consistency Review
53
+
54
+ Compare code implementation against API YAML specification endpoint by endpoint:
55
+
56
+ **Checklist**:
57
+
58
+ | Check Item | Description | Severity |
59
+ |------------|-------------|----------|
60
+ | Path Match | Whether route paths in code exactly match `paths` in YAML | Critical |
61
+ | HTTP Method | Whether GET/POST/PUT/DELETE matches | Critical |
62
+ | Request Body Fields | Whether code reads all required fields defined in YAML `requestBody.schema` | Critical |
63
+ | Request Body Validation | Whether field type, format (email/uuid), minLength and other constraints are validated in code | Warning |
64
+ | Response Fields | Whether JSON field names and types returned by code match YAML `responses.schema` | Critical |
65
+ | Status Codes | Whether HTTP status codes returned in normal and error cases match YAML definitions | Critical |
66
+ | Error Response Format | Whether error responses follow the unified `{ code, message, details? }` format | Warning |
67
+
68
+ **Output format**:
69
+
70
+ ```markdown
71
+ ### API Consistency
72
+
73
+ | Endpoint | Check Item | Status | Notes |
74
+ |----------|------------|--------|-------|
75
+ | POST /api/auth/register | Request body fields | ✅ | email, password both read |
76
+ | POST /api/auth/register | Response status code | ❌ Critical | Registration success returns 200, YAML defines 201 |
77
+ | POST /api/auth/register | Error code | ❌ Warning | Duplicate email returns generic 400, YAML defines 409 |
78
+ ```
79
+
80
+ ### Step 3: Exception Handling Coverage Review
81
+
82
+ Map all EX exception cases from sequence diagrams to error handling in code one by one:
83
+
84
+ 1. List all EX case IDs and their expected behaviors for the scenario
85
+ 2. Search for corresponding try/catch, if/else, error handlers in code
86
+ 3. Flag uncovered EX cases
87
+
88
+ **Key checks**:
89
+
90
+ - Whether each EX case has a corresponding code branch
91
+ - Whether the correct HTTP status code and error code are returned in exception scenarios
92
+ - Whether there are "silently swallowed exceptions" (empty catch blocks or catch blocks that only log without returning errors)
93
+ - Whether external service calls (DB, third-party APIs) all have timeout and error handling
94
+ - Whether there are exception handlers in code that don't exist in sequence diagrams (which may indicate sequence diagram omissions)
95
+
96
+ **Output format**:
97
+
98
+ ```markdown
99
+ ### Exception Handling Coverage
100
+
101
+ | EX ID | Exception Description | Code Coverage | Notes |
102
+ |-------|----------------------|---------------|-------|
103
+ | EX-2.1 | Email already registered | ✅ | Returns 409, format correct |
104
+ | EX-2.2 | Auth service unavailable | ❌ Critical | No try/catch wrapping the supabase.auth.signUp call |
105
+ | EX-4.1 | profiles write failure | ❌ Critical | auth.users record not rolled back after INSERT failure |
106
+ ```
107
+
108
+ ### Step 4: DB Operations Review
109
+
110
+ Check whether database operations in code conform to DDL design:
111
+
112
+ **Checklist**:
113
+
114
+ - **Table and column names**: Whether table/column names referenced in code match DDL (no typos, case differences)
115
+ - **Field types**: Whether value types passed in code match DDL definitions (e.g., for an `INTEGER` amount field in DDL, whether code passes cents instead of dollars)
116
+ - **Constraint compliance**: Whether NOT NULL fields always have values, whether UNIQUE fields have conflict handling, whether CHECK constraint enum values have corresponding constants in code
117
+ - **Transaction usage**: Whether multi-table write operations are wrapped in transactions
118
+ - **Migration consistency**: Whether the latest fields in DDL are used in code (avoid DDL being updated but code not following up)
119
+
120
+ ### Step 5: Security Review
121
+
122
+ Check the security implementation of the code:
123
+
124
+ | Check Item | Description | Severity |
125
+ |------------|-------------|----------|
126
+ | Authentication Check | Whether endpoints requiring authentication verify token/session before processing logic | Critical |
127
+ | Authorization Check | Whether users can only access their own data (owner check) | Critical |
128
+ | Input Validation | Whether user input has type validation and length limits (prevent injection, prevent XSS) | Critical |
129
+ | Sensitive Data | Whether responses leak password hashes, internal IDs, or stack traces | Critical |
130
+ | RLS Dependency | If relying on PostgreSQL RLS, whether code correctly sets the `auth.uid()` context | Warning |
131
+ | SQL Injection | Whether parameterized queries are used (string-concatenated SQL is prohibited) | Critical |
132
+ | Rate Limiting | Whether critical endpoints (login, registration) have rate limiting against brute force | Warning |
133
+
134
+ ### Step 6: Output Review Report
135
+
136
+ Summarize all findings by severity and generate a structured report:
137
+
138
+ ```markdown
139
+ # Code Review Report: S01 User Registration
140
+
141
+ ## Review Scope
142
+ - Scenario: S01
143
+ - Endpoints: 4
144
+ - EX cases: 7
145
+ - Code files: src/api/auth/register.ts, src/api/auth/login.ts
146
+
147
+ ## Review Summary
148
+
149
+ | Severity | Count |
150
+ |----------|-------|
151
+ | 🔴 Critical | 2 |
152
+ | 🟡 Warning | 3 |
153
+ | 🔵 Info | 1 |
154
+
155
+ ## Critical Findings
156
+
157
+ ### [C1] POST /api/auth/register status code mismatch
158
+ - **Spec source**: auth.yaml → register → responses.201
159
+ - **Issue**: Code returns 200, spec defines 201
160
+ - **Fix suggestion**: Change `res.status(200)` to `res.status(201)`
161
+
162
+ ### [C2] EX-2.2 unhandled: Auth service unavailable
163
+ - **Spec source**: S01 sequence diagram → EX-2.2
164
+ - **Issue**: `supabase.auth.signUp()` call is not wrapped in try/catch
165
+ - **Fix suggestion**: Add try/catch, return 503 on timeout or 5xx
166
+
167
+ ## Warning Findings
168
+ ...
169
+
170
+ ## Info Findings
171
+ ...
172
+ ```
173
+
174
+ **Report principles**:
175
+ - Critical issues must be fixed before proceeding to orchestration acceptance
176
+ - Warning issues are recommended to fix but do not block delivery
177
+ - Info items are improvement suggestions that can be addressed later
178
+ - Every finding must reference a spec source (API YAML, EX ID, DDL)
179
+
180
+ ## Output Specification
181
+
182
+ - Review report is output directly in the conversation (not written to a file)
183
+ - Categorized by severity: Critical / Warning / Info
184
+ - Each finding format: ID + spec source + issue description + fix suggestion
185
+ - End with a summary and next-step recommendation (e.g., "Fix 2 Critical issues, then run orchestration acceptance")
186
+
187
+ ## Best Practices
188
+
189
+ - **Consistency first**: Code must be fully consistent with API YAML — field names, types, and status codes must not deviate. Most production bugs come from subtle inconsistencies between code and specs
190
+ - **Exception handling is the focus**: Most bugs occur in exception paths; carefully check that every EX case has a corresponding catch/error handler
191
+ - **No shortcuts on security**: Authentication checks, RLS policies, input validation — any missing item is a Critical issue
192
+ - **Don't over-review**: Code style issues should be marked as Info and not block delivery. The core goal of the review is "code matches specs", not "code is perfect"
193
+ - **Run tests before reviewing**: If the code can run, execute orchestration tests first and use failing cases to pinpoint issues — this is more efficient than reading code line by line
194
+ - **Watch for compensation logic**: If multi-step writes (e.g., first creating an auth user then writing a profile) fail midway, check whether there is a rollback or compensation mechanism — this is the most commonly missed Critical issue
195
+
196
+ ## Recommended Prompts
197
+
198
+ The following prompts can be copied directly for use with AI:
199
+
200
+ - `Help me do a code review`
201
+ - `Help me check if this code conforms to the API YAML spec`
202
+ - `Review the code implementation related to S01`
203
+ - `Help me check if exception handling is complete`
204
+ - `Help me check if security policies are in place`