sumulige-claude 1.2.1 → 1.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 (50) hide show
  1. package/.claude/.kickoff-hint.txt +1 -1
  2. package/.claude/AGENTS.md +6 -6
  3. package/.claude/USAGE.md +175 -0
  4. package/.claude/commands/fix.md +83 -0
  5. package/.claude/commands/plan.md +88 -0
  6. package/.claude/commands/refactor.md +102 -0
  7. package/.claude/hooks/pre-push.cjs +3 -2
  8. package/.claude/rag/skill-index.json +34 -15
  9. package/.claude/rules/coding-style.md +119 -0
  10. package/.claude/rules/hooks.md +288 -0
  11. package/.claude/rules/performance.md +78 -0
  12. package/.claude/rules/security.md +56 -0
  13. package/.claude/rules/testing.md +89 -0
  14. package/.claude/settings.local.json +19 -1
  15. package/.claude/skills/design-brain/SKILL.md +190 -0
  16. package/.claude/skills/design-brain/metadata.yaml +26 -0
  17. package/.claude/skills/quality-guard/SKILL.md +138 -0
  18. package/.claude/skills/quality-guard/metadata.yaml +27 -0
  19. package/.claude/skills/quick-fix/SKILL.md +138 -0
  20. package/.claude/skills/quick-fix/metadata.yaml +26 -0
  21. package/.claude/skills/test-master/SKILL.md +186 -0
  22. package/.claude/skills/test-master/metadata.yaml +29 -0
  23. package/AGENTS.md +25 -7
  24. package/CHANGELOG.md +39 -3
  25. package/README.md +57 -0
  26. package/config/official-skills.json +1 -1
  27. package/development/knowledge-base/.index.clean.json +1 -0
  28. package/package.json +1 -1
  29. package/.claude/skills/123-skill/SKILL.md +0 -61
  30. package/.claude/skills/123-skill/examples/basic.md +0 -3
  31. package/.claude/skills/123-skill/metadata.yaml +0 -30
  32. package/.claude/skills/123-skill/templates/default.md +0 -3
  33. package/.claude/skills/api-tester/SKILL.md +0 -90
  34. package/.claude/skills/api-tester/examples/basic.md +0 -3
  35. package/.claude/skills/api-tester/metadata.yaml +0 -30
  36. package/.claude/skills/api-tester/templates/default.md +0 -3
  37. package/.claude/skills/code-reviewer-123/SKILL.md +0 -61
  38. package/.claude/skills/code-reviewer-123/examples/basic.md +0 -3
  39. package/.claude/skills/code-reviewer-123/metadata.yaml +0 -30
  40. package/.claude/skills/code-reviewer-123/templates/default.md +0 -3
  41. package/.claude/skills/my-skill/SKILL.md +0 -61
  42. package/.claude/skills/my-skill/examples/basic.md +0 -3
  43. package/.claude/skills/my-skill/metadata.yaml +0 -30
  44. package/.claude/skills/my-skill/templates/default.md +0 -3
  45. package/.claude/skills/template/SKILL.md +0 -6
  46. package/.claude/skills/template/metadata.yaml +0 -30
  47. package/.claude/skills/test-skill-name/SKILL.md +0 -61
  48. package/.claude/skills/test-skill-name/examples/basic.md +0 -3
  49. package/.claude/skills/test-skill-name/metadata.yaml +0 -30
  50. package/.claude/skills/test-skill-name/templates/default.md +0 -3
@@ -49,4 +49,4 @@
49
49
 
50
50
  💡 提示: 你也可以直接说 "跳过启动" 使用传统开发模式
51
51
 
52
- 生成日期: 2026-01-18
52
+ 生成日期: 2026-01-22
package/.claude/AGENTS.md CHANGED
@@ -6,10 +6,6 @@
6
6
 
7
7
  This project uses **Sumulige Claude** for multi-agent collaboration.
8
8
 
9
- ### conductor
10
- - **Model**: claude-opus-4-5-20251101
11
- - **Role**: Task coordination and decomposition
12
-
13
9
  ### architect
14
10
  - **Model**: claude-opus-4-5-20251101
15
11
  - **Role**: Architecture design and decisions
@@ -18,14 +14,18 @@ This project uses **Sumulige Claude** for multi-agent collaboration.
18
14
  - **Model**: claude-opus-4-5-20251101
19
15
  - **Role**: Code implementation and testing
20
16
 
21
- ### reviewer
17
+ ### conductor
22
18
  - **Model**: claude-opus-4-5-20251101
23
- - **Role**: Code review and quality check
19
+ - **Role**: Task coordination and decomposition
24
20
 
25
21
  ### librarian
26
22
  - **Model**: claude-opus-4-5-20251101
27
23
  - **Role**: Documentation and knowledge
28
24
 
25
+ ### reviewer
26
+ - **Model**: claude-opus-4-5-20251101
27
+ - **Role**: Code review and quality check
28
+
29
29
  ## Usage
30
30
 
31
31
  ```bash
@@ -0,0 +1,175 @@
1
+ # Skills 系统使用手册
2
+
3
+ > 版本: 2.0.0 | 更新日期: 2026-01-22
4
+
5
+ ---
6
+
7
+ ## 核心 Skills
8
+
9
+ | Skill | 命令 | 触发时机 | 作用 | 模型 |
10
+ |-------|------|---------|------|------|
11
+ | `quality-guard` | `/review` | 提交前、PR 审查 | 代码质量 + 安全检查 + 清理建议 | sonnet |
12
+ | `test-master` | `/test` | 实现功能后 | TDD + E2E + 覆盖率分析 | sonnet |
13
+ | `design-brain` | `/plan` | 开始新任务前 | 规划 + 架构设计 | opus |
14
+ | `quick-fix` | `/fix` | 构建失败时 | 快速修复错误 | haiku |
15
+
16
+ ---
17
+
18
+ ## 命令速查表
19
+
20
+ ### /review - 代码审查
21
+
22
+ ```bash
23
+ /review # 标准代码审查
24
+ /review --security # 安全深度扫描 (OWASP Top 10)
25
+ /review --clean # 死代码清理建议
26
+ /review --all # 完整审查
27
+ ```
28
+
29
+ **触发时机**:
30
+ - 准备提交代码前
31
+ - PR 审查时
32
+ - 怀疑有安全问题时
33
+
34
+ ### /test - 测试
35
+
36
+ ```bash
37
+ /test # 运行单元测试
38
+ /test --tdd # TDD 开发模式 (RED→GREEN→REFACTOR)
39
+ /test --e2e # E2E 测试 (Playwright)
40
+ /test --coverage # 覆盖率报告
41
+ /test --all # 完整测试套件
42
+ ```
43
+
44
+ **触发时机**:
45
+ - 完成功能实现后
46
+ - 修复 bug 后
47
+ - 提交前验证
48
+
49
+ ### /plan - 规划
50
+
51
+ ```bash
52
+ /plan # 快速规划(默认)
53
+ /plan --deep # 深度设计(架构决策)
54
+ /plan --arch # 仅架构设计
55
+ ```
56
+
57
+ **触发时机**:
58
+ - 开始新功能开发前
59
+ - 重大重构前
60
+ - 技术选型时
61
+
62
+ ### /fix - 快速修复
63
+
64
+ ```bash
65
+ /fix # 自动检测并修复
66
+ /fix --build # 修复构建错误
67
+ /fix --lint # 修复 lint 错误
68
+ /fix --type # 修复类型错误
69
+ /fix --all # 修复所有错误
70
+ ```
71
+
72
+ **触发时机**:
73
+ - `npm run build` 失败
74
+ - `tsc` 报类型错误
75
+ - ESLint 报错
76
+
77
+ ### /refactor - 重构
78
+
79
+ ```bash
80
+ /refactor # 分析并建议清理
81
+ /refactor --dead # 查找死代码
82
+ /refactor --deps # 查找未使用依赖
83
+ /refactor --duplicate # 查找重复代码
84
+ /refactor --execute # 执行清理(需确认)
85
+ ```
86
+
87
+ **触发时机**:
88
+ - 代码库变大需要清理
89
+ - 发现重复代码
90
+ - 依赖需要整理
91
+
92
+ ---
93
+
94
+ ## 模型成本策略
95
+
96
+ | 模型 | 使用场景 | 相对成本 | 速度 |
97
+ |------|---------|---------|------|
98
+ | **haiku** | `/fix` 快速修复 | 1x (最低) | 最快 |
99
+ | **sonnet** | `/review`, `/test` 标准任务 | 5x | 中等 |
100
+ | **opus** | `/plan --deep` 复杂架构 | 15x | 较慢 |
101
+
102
+ **自动选择规则**:
103
+ - 简单修复 → haiku(节省成本)
104
+ - 代码审查/测试 → sonnet(平衡性价比)
105
+ - 架构设计 → opus(仅在需要深度分析时)
106
+
107
+ ---
108
+
109
+ ## 工作流示例
110
+
111
+ ### 新功能开发
112
+
113
+ ```
114
+ 1. /plan # 规划实现步骤
115
+ 2. 编写代码 # 实现功能
116
+ 3. /fix # 修复编译错误
117
+ 4. /test --tdd # 补充测试
118
+ 5. /review # 代码审查
119
+ 6. /commit # 提交代码
120
+ ```
121
+
122
+ ### Bug 修复
123
+
124
+ ```
125
+ 1. /test # 确认失败的测试
126
+ 2. 修复代码 # 实现修复
127
+ 3. /fix # 确保编译通过
128
+ 4. /test # 验证测试通过
129
+ 5. /review --security # 安全检查
130
+ 6. /commit # 提交修复
131
+ ```
132
+
133
+ ### 代码清理
134
+
135
+ ```
136
+ 1. /refactor # 分析代码库
137
+ 2. /refactor --dead # 找死代码
138
+ 3. /refactor --deps # 找未用依赖
139
+ 4. /refactor --execute # 执行清理
140
+ 5. /test # 确保不破坏功能
141
+ 6. /commit # 提交清理
142
+ ```
143
+
144
+ ---
145
+
146
+ ## 自动加载
147
+
148
+ Skills 会根据用户输入自动加载:
149
+
150
+ ```json
151
+ {
152
+ "auto_load": {
153
+ "enabled": true,
154
+ "confidence_threshold": 0.7,
155
+ "max_skills_per_task": 3
156
+ }
157
+ }
158
+ ```
159
+
160
+ **关键词触发示例**:
161
+ - "review code" → `quality-guard`
162
+ - "fix build error" → `quick-fix`
163
+ - "plan architecture" → `design-brain`
164
+ - "run tests" → `test-master`
165
+
166
+ ---
167
+
168
+ ## 配置文件
169
+
170
+ | 文件 | 说明 |
171
+ |------|------|
172
+ | `.claude/rag/skill-index.json` | Skill 索引和模型策略 |
173
+ | `.claude/skills/*/metadata.yaml` | 各 Skill 配置 |
174
+ | `.claude/skills/*/SKILL.md` | Skill 详细指令 |
175
+ | `.claude/commands/*.md` | 命令定义 |
@@ -0,0 +1,83 @@
1
+ ---
2
+ description: Quick fix for build, lint, and type errors
3
+ ---
4
+
5
+ # /fix
6
+
7
+ 快速修复构建错误、lint 错误、类型错误。
8
+
9
+ ## 使用方式
10
+
11
+ ```bash
12
+ /fix # 自动检测并修复(默认)
13
+ /fix --build # 修复构建错误
14
+ /fix --lint # 修复 lint 错误
15
+ /fix --type # 修复类型错误
16
+ /fix --all # 修复所有错误
17
+ ```
18
+
19
+ ## 关联 Skill
20
+
21
+ 此命令加载 `quick-fix` skill(使用 haiku 模型,快速响应)。
22
+
23
+ ---
24
+
25
+ ## 工作流程
26
+
27
+ ### Step 1: 错误检测
28
+
29
+ ```bash
30
+ # 构建错误
31
+ npm run build 2>&1 | head -100
32
+
33
+ # 类型错误
34
+ npx tsc --noEmit 2>&1 | head -50
35
+
36
+ # Lint 错误
37
+ npx eslint . --format json 2>&1 | head -100
38
+ ```
39
+
40
+ ### Step 2: 错误分类
41
+
42
+ | 类型 | 示例 | 策略 |
43
+ |------|------|------|
44
+ | 类型错误 | `TS2345` | 添加类型或断言 |
45
+ | 导入错误 | `Cannot find module` | 检查路径 |
46
+ | 语法错误 | `Unexpected token` | 修复语法 |
47
+ | Lint 错误 | `no-unused-vars` | 删除或使用 |
48
+
49
+ ### Step 3: 增量修复
50
+
51
+ ```
52
+ 原则:每次只修复一个错误
53
+
54
+ 1. 读取第一个错误
55
+ 2. 定位文件和行号
56
+ 3. 应用最小修复
57
+ 4. 重新编译验证
58
+ 5. 重复直到全部修复
59
+ ```
60
+
61
+ ### Step 4: 输出报告
62
+
63
+ ```markdown
64
+ # Quick Fix Report
65
+
66
+ ## Errors Found: X
67
+ ## Fixed: Y
68
+ ## Remaining: Z
69
+
70
+ | File | Line | Error | Fix |
71
+ |------|------|-------|-----|
72
+
73
+ ## Build Status
74
+ ✅ SUCCESS / ❌ FAILED
75
+ ```
76
+
77
+ ---
78
+
79
+ ## 原则
80
+
81
+ - **快速** - 使用轻量模型
82
+ - **最小** - 只做必要修改
83
+ - **安全** - 不确定的不修复
@@ -0,0 +1,88 @@
1
+ ---
2
+ description: Plan implementation with architecture design
3
+ ---
4
+
5
+ # /plan
6
+
7
+ 为功能或任务创建实现计划,支持快速规划和深度设计。
8
+
9
+ ## 使用方式
10
+
11
+ ```bash
12
+ /plan # 快速规划(默认)
13
+ /plan --deep # 深度设计(架构决策)
14
+ /plan --arch # 仅架构设计
15
+ ```
16
+
17
+ ## 关联 Skill
18
+
19
+ 此命令加载 `design-brain` skill(复杂任务使用 opus)。
20
+
21
+ ---
22
+
23
+ ## 工作流程
24
+
25
+ ### 快速规划(默认)
26
+
27
+ ```markdown
28
+ # Plan: [功能名称]
29
+
30
+ ## Goal
31
+ [一句话描述]
32
+
33
+ ## Steps
34
+ 1. [ ] [步骤 1]
35
+ 2. [ ] [步骤 2]
36
+ 3. [ ] [步骤 3]
37
+
38
+ ## Files
39
+ - `path/to/file.ts` - [修改内容]
40
+
41
+ ## Risk
42
+ - [主要风险] → [缓解策略]
43
+ ```
44
+
45
+ ### 深度设计(--deep)
46
+
47
+ ```markdown
48
+ # Design: [系统名称]
49
+
50
+ ## Overview
51
+ [背景和目标]
52
+
53
+ ## Architecture
54
+ [组件图 + 数据流]
55
+
56
+ ## Technical Decisions
57
+ | Decision | Choice | Reason | Trade-offs |
58
+ |----------|--------|--------|------------|
59
+
60
+ ## Implementation Plan
61
+ ### Phase 1: [阶段名]
62
+ 1. [ ] Step 1
63
+ 2. [ ] Step 2
64
+
65
+ ## Risks
66
+ | Risk | Impact | Mitigation |
67
+ |------|--------|------------|
68
+
69
+ ## Success Criteria
70
+ - [ ] 标准 1
71
+ - [ ] 标准 2
72
+ ```
73
+
74
+ ---
75
+
76
+ ## 设计原则
77
+
78
+ 1. **简单优于复杂** - 能用简单方案就不要复杂化
79
+ 2. **最小变更** - 优先复用现有代码
80
+ 3. **可测试性** - 每个步骤都可验证
81
+
82
+ ## 使用场景
83
+
84
+ | 场景 | 推荐模式 |
85
+ |------|---------|
86
+ | 小功能/bug 修复 | 快速规划 |
87
+ | 新模块/系统 | 深度设计 |
88
+ | 技术选型 | --arch |
@@ -0,0 +1,102 @@
1
+ ---
2
+ description: Safe code refactoring and cleanup
3
+ ---
4
+
5
+ # /refactor
6
+
7
+ 安全的代码重构和清理。
8
+
9
+ ## 使用方式
10
+
11
+ ```bash
12
+ /refactor # 分析并建议清理(默认)
13
+ /refactor --dead # 查找死代码
14
+ /refactor --deps # 查找未使用依赖
15
+ /refactor --duplicate # 查找重复代码
16
+ /refactor --execute # 执行清理(需确认)
17
+ ```
18
+
19
+ ## 关联 Skill
20
+
21
+ 此命令加载 `quality-guard` skill(清理模式)。
22
+
23
+ ---
24
+
25
+ ## 工作流程
26
+
27
+ ### Step 1: 运行分析工具
28
+
29
+ ```bash
30
+ # 未使用的文件、导出、依赖
31
+ npx knip
32
+
33
+ # 未使用的 npm 依赖
34
+ npx depcheck
35
+
36
+ # 未使用的 TypeScript 导出
37
+ npx ts-prune
38
+
39
+ # 未使用的 eslint-disable
40
+ npx eslint . --report-unused-disable-directives
41
+ ```
42
+
43
+ ### Step 2: 风险分类
44
+
45
+ | 风险 | 类型 | 处理 |
46
+ |------|------|------|
47
+ | 🟢 SAFE | 未使用导出、测试文件 | 可直接删除 |
48
+ | 🟡 CAREFUL | 动态导入可能使用 | 需验证 |
49
+ | 🔴 RISKY | 公共 API、配置文件 | 谨慎处理 |
50
+
51
+ ### Step 3: 生成报告
52
+
53
+ ```markdown
54
+ # Refactor Report
55
+
56
+ ## Dead Code
57
+ | File | Type | Risk | Reason |
58
+ |------|------|------|--------|
59
+
60
+ ## Unused Dependencies
61
+ | Package | Size | Last Used |
62
+ |---------|------|-----------|
63
+
64
+ ## Duplicate Code
65
+ | Location 1 | Location 2 | Lines |
66
+ |------------|------------|-------|
67
+
68
+ ## Recommended Actions
69
+ 1. [ ] Remove unused-package (SAFE)
70
+ 2. [ ] Delete src/old.ts (SAFE)
71
+ 3. [ ] Review src/utils.ts (CAREFUL)
72
+
73
+ ## Impact
74
+ - Files to delete: X
75
+ - Dependencies to remove: Y
76
+ - Lines of code: -Z
77
+ ```
78
+
79
+ ### Step 4: 执行清理(--execute)
80
+
81
+ ```
82
+ ⚠️ 执行前:
83
+ 1. 创建备份分支
84
+ 2. 确保测试通过
85
+ 3. 逐个删除,每删一个运行测试
86
+ 4. 记录到 DELETION_LOG.md
87
+ ```
88
+
89
+ ---
90
+
91
+ ## 安全检查清单
92
+
93
+ 删除前:
94
+ - [ ] grep 所有引用
95
+ - [ ] 检查动态导入
96
+ - [ ] 查看 git 历史
97
+ - [ ] 运行所有测试
98
+
99
+ 删除后:
100
+ - [ ] 构建成功
101
+ - [ ] 测试通过
102
+ - [ ] 提交变更
@@ -41,7 +41,8 @@ async function main() {
41
41
  stdio: 'pipe'
42
42
  }).trim() || 'origin/main';
43
43
 
44
- const output = execSync(`git diff --name-only ${upstream}...HEAD`, {
44
+ // Use --diff-filter=ACMR to exclude deleted files (D)
45
+ const output = execSync(`git diff --name-only --diff-filter=ACMR ${upstream}...HEAD`, {
45
46
  encoding: 'utf-8',
46
47
  stdio: 'pipe'
47
48
  });
@@ -85,7 +86,7 @@ async function main() {
85
86
 
86
87
  const result = await gate.check({
87
88
  files: checkable.map(f => path.join(projectDir, f)),
88
- severity: 'warn' // Block on warnings too for push
89
+ severity: 'error' // Only block on errors, not warnings
89
90
  });
90
91
 
91
92
  if (!result.passed) {
@@ -1,6 +1,7 @@
1
1
  {
2
- "version": "1.0.0",
3
- "last_updated": "2026-01-11",
2
+ "version": "2.0.0",
3
+ "last_updated": "2026-01-22",
4
+ "description": "Optimized skill index - merged 9 skills into 4 core skills",
4
5
  "skills": [
5
6
  {
6
7
  "name": "frontend-design",
@@ -46,7 +47,7 @@
46
47
  },
47
48
  {
48
49
  "name": "webapp-testing",
49
- "keywords": ["test", "testing", "playwright", "browser", "automation", "e2e", "screenshot"],
50
+ "keywords": ["browser", "automation", "screenshot", "puppeteer", "scraping"],
50
51
  "description": "Toolkit for interacting with and testing local web applications using Playwright",
51
52
  "trigger": "when testing frontend functionality, debugging UI behavior, or capturing browser screenshots"
52
53
  },
@@ -105,22 +106,32 @@
105
106
  "trigger": "for complex artifacts requiring state management, routing, or shadcn/ui components"
106
107
  },
107
108
  {
108
- "name": "dev-browser",
109
- "keywords": ["browser", "scraping", "automation", "puppet", "playwright", "web"],
110
- "description": "Browser automation with persistent state for testing and scraping",
111
- "trigger": "when needing browser automation or web scraping capabilities"
109
+ "name": "quality-guard",
110
+ "keywords": ["review", "security", "quality", "lint", "code review", "vulnerability", "owasp", "dead code", "refactor", "cleanup"],
111
+ "description": "Code quality guardian - merged: code review + security check + dead code cleanup. Supports --security, --clean modes.",
112
+ "trigger": "when reviewing code, checking security, or cleaning up dead code",
113
+ "model": "sonnet"
112
114
  },
113
115
  {
114
- "name": "zai-cli",
115
- "keywords": ["z.ai", "vision", "search", "github", "exploration", "analysis"],
116
- "description": "Z.AI vision, search, and GitHub exploration CLI tools",
117
- "trigger": "when needing vision analysis, web search, or GitHub repository exploration"
116
+ "name": "test-master",
117
+ "keywords": ["test", "tdd", "e2e", "playwright", "coverage", "unit test", "jest", "vitest"],
118
+ "description": "Test master - merged: TDD workflow + E2E testing. Supports --tdd, --e2e, --coverage modes.",
119
+ "trigger": "when writing tests, doing TDD, running E2E tests, or checking coverage",
120
+ "model": "sonnet"
118
121
  },
119
122
  {
120
- "name": "gastown",
121
- "keywords": ["gastown", "multi-agent", "orchestrator", "coordination"],
122
- "description": "Multi-agent orchestrator for complex task coordination",
123
- "trigger": "when orchestrating multiple agents for complex workflows"
123
+ "name": "design-brain",
124
+ "keywords": ["plan", "design", "architecture", "system design", "technical decision", "strategy"],
125
+ "description": "Design brain - merged: planner + architect. Supports --quick (default) and --deep modes.",
126
+ "trigger": "when planning implementation or making architecture decisions",
127
+ "model": "opus"
128
+ },
129
+ {
130
+ "name": "quick-fix",
131
+ "keywords": ["fix", "build error", "compile error", "type error", "lint error", "tsc"],
132
+ "description": "Quick fixer - fast build/lint/type error resolution using haiku model for speed and cost efficiency.",
133
+ "trigger": "when build fails, type errors occur, or lint errors need fixing",
134
+ "model": "haiku"
124
135
  }
125
136
  ],
126
137
  "auto_load": {
@@ -131,5 +142,13 @@
131
142
  "fallback": {
132
143
  "enabled": true,
133
144
  "skill": "frontend-design"
145
+ },
146
+ "model_strategy": {
147
+ "description": "Cost-optimized model selection",
148
+ "rules": [
149
+ { "pattern": "quick-fix", "model": "haiku", "reason": "Fast, simple fixes" },
150
+ { "pattern": "quality-guard|test-master", "model": "sonnet", "reason": "Standard tasks" },
151
+ { "pattern": "design-brain", "model": "opus", "reason": "Complex architecture only" }
152
+ ]
134
153
  }
135
154
  }
@@ -0,0 +1,119 @@
1
+ # Coding Style Rules
2
+
3
+ > 代码风格规则 - 所有代码必须遵守
4
+
5
+ ## 不可变性 (CRITICAL)
6
+
7
+ **始终创建新对象,永不变异:**
8
+
9
+ ```javascript
10
+ // ❌ 错误:变异
11
+ function updateUser(user, name) {
12
+ user.name = name // 变异!
13
+ return user
14
+ }
15
+
16
+ // ✅ 正确:不可变
17
+ function updateUser(user, name) {
18
+ return {
19
+ ...user,
20
+ name
21
+ }
22
+ }
23
+ ```
24
+
25
+ ## 文件组织
26
+
27
+ **多个小文件 > 少数大文件:**
28
+
29
+ | 规则 | 阈值 |
30
+ |------|------|
31
+ | 典型文件 | 200-400 行 |
32
+ | 最大文件 | 800 行 |
33
+ | 组织方式 | 按功能/领域,而非按类型 |
34
+
35
+ 原则:高内聚,低耦合
36
+
37
+ ## 错误处理
38
+
39
+ **始终全面处理错误:**
40
+
41
+ ```typescript
42
+ try {
43
+ const result = await riskyOperation()
44
+ return result
45
+ } catch (error) {
46
+ console.error('Operation failed:', error)
47
+ throw new Error('用户友好的详细错误信息')
48
+ }
49
+ ```
50
+
51
+ ## 输入验证
52
+
53
+ **始终验证用户输入:**
54
+
55
+ ```typescript
56
+ import { z } from 'zod'
57
+
58
+ const schema = z.object({
59
+ email: z.string().email(),
60
+ age: z.number().int().min(0).max(150)
61
+ })
62
+
63
+ const validated = schema.parse(input)
64
+ ```
65
+
66
+ ## 代码质量检查清单
67
+
68
+ 完成工作前确认:
69
+
70
+ - [ ] 代码可读、命名良好
71
+ - [ ] 函数小(< 50 行)
72
+ - [ ] 文件聚焦(< 800 行)
73
+ - [ ] 无深嵌套(> 4 层)
74
+ - [ ] 适当的错误处理
75
+ - [ ] 无 console.log 语句
76
+ - [ ] 无硬编码值
77
+ - [ ] 无变异(使用不可变模式)
78
+
79
+ ## 命名规范
80
+
81
+ | 类型 | 规范 | 示例 |
82
+ |------|------|------|
83
+ | 变量 | camelCase | `userName`, `isActive` |
84
+ | 常量 | SCREAMING_SNAKE | `MAX_RETRY`, `API_URL` |
85
+ | 函数 | camelCase, 动词开头 | `getUserById`, `validateInput` |
86
+ | 类/组件 | PascalCase | `UserProfile`, `DataService` |
87
+ | 文件 | kebab-case 或 PascalCase | `user-service.ts`, `UserProfile.tsx` |
88
+
89
+ ## 禁止的模式
90
+
91
+ ```typescript
92
+ // ❌ 魔法数字
93
+ if (status === 200) { ... }
94
+
95
+ // ✅ 使用常量
96
+ const HTTP_OK = 200
97
+ if (status === HTTP_OK) { ... }
98
+
99
+ // ❌ 变量名不清晰
100
+ const x = getUser()
101
+ const tmp = process(data)
102
+
103
+ // ✅ 描述性命名
104
+ const currentUser = getUser()
105
+ const processedData = process(data)
106
+
107
+ // ❌ 直接变异数组
108
+ arr.push(item)
109
+ arr.sort()
110
+
111
+ // ✅ 创建新数组
112
+ const newArr = [...arr, item]
113
+ const sortedArr = [...arr].sort()
114
+ ```
115
+
116
+ ## 相关命令
117
+
118
+ - `/code-review` - 代码审查
119
+ - `/refactor-clean` - 重构清理