sumulige-claude 1.2.1 → 1.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.
- package/.claude/.kickoff-hint.txt +1 -1
- package/.claude/AGENTS.md +6 -6
- package/.claude/USAGE.md +175 -0
- package/.claude/commands/audit.md +147 -0
- package/.claude/commands/fix.md +83 -0
- package/.claude/commands/gha.md +136 -0
- package/.claude/commands/handoff.md +93 -0
- package/.claude/commands/plan.md +88 -0
- package/.claude/commands/refactor.md +102 -0
- package/.claude/hooks/pre-push.cjs +3 -2
- package/.claude/rules/coding-style.md +119 -0
- package/.claude/rules/hooks.md +288 -0
- package/.claude/rules/performance.md +78 -0
- package/.claude/rules/security.md +56 -0
- package/.claude/rules/testing.md +89 -0
- package/.claude/settings.local.json +24 -1
- package/.claude/skills/design-brain/SKILL.md +190 -0
- package/.claude/skills/design-brain/metadata.yaml +26 -0
- package/.claude/skills/quality-guard/SKILL.md +138 -0
- package/.claude/skills/quality-guard/metadata.yaml +27 -0
- package/.claude/skills/quick-fix/SKILL.md +138 -0
- package/.claude/skills/quick-fix/metadata.yaml +26 -0
- package/.claude/skills/test-master/SKILL.md +186 -0
- package/.claude/skills/test-master/metadata.yaml +29 -0
- package/AGENTS.md +25 -7
- package/CHANGELOG.md +64 -3
- package/README.md +57 -0
- package/cli.js +4 -0
- package/config/official-skills.json +1 -1
- package/development/knowledge-base/.index.clean.json +1 -0
- package/lib/commands.js +51 -0
- package/lib/permission-audit.js +255 -0
- package/package.json +1 -1
- package/.claude/skills/123-skill/SKILL.md +0 -61
- package/.claude/skills/123-skill/examples/basic.md +0 -3
- package/.claude/skills/123-skill/metadata.yaml +0 -30
- package/.claude/skills/123-skill/templates/default.md +0 -3
- package/.claude/skills/api-tester/SKILL.md +0 -90
- package/.claude/skills/api-tester/examples/basic.md +0 -3
- package/.claude/skills/api-tester/metadata.yaml +0 -30
- package/.claude/skills/api-tester/templates/default.md +0 -3
- package/.claude/skills/code-reviewer-123/SKILL.md +0 -61
- package/.claude/skills/code-reviewer-123/examples/basic.md +0 -3
- package/.claude/skills/code-reviewer-123/metadata.yaml +0 -30
- package/.claude/skills/code-reviewer-123/templates/default.md +0 -3
- package/.claude/skills/my-skill/SKILL.md +0 -61
- package/.claude/skills/my-skill/examples/basic.md +0 -3
- package/.claude/skills/my-skill/metadata.yaml +0 -30
- package/.claude/skills/my-skill/templates/default.md +0 -3
- package/.claude/skills/template/SKILL.md +0 -6
- package/.claude/skills/template/metadata.yaml +0 -30
- package/.claude/skills/test-skill-name/SKILL.md +0 -61
- package/.claude/skills/test-skill-name/examples/basic.md +0 -3
- package/.claude/skills/test-skill-name/metadata.yaml +0 -30
- package/.claude/skills/test-skill-name/templates/default.md +0 -3
|
@@ -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
|
-
|
|
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: '
|
|
89
|
+
severity: 'error' // Only block on errors, not warnings
|
|
89
90
|
});
|
|
90
91
|
|
|
91
92
|
if (!result.passed) {
|
|
@@ -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` - 重构清理
|
|
@@ -0,0 +1,288 @@
|
|
|
1
|
+
# Hooks 最佳实践
|
|
2
|
+
|
|
3
|
+
> 自动化钩子使用指南 - 融合自 everything-claude-code
|
|
4
|
+
|
|
5
|
+
## Hook 类型
|
|
6
|
+
|
|
7
|
+
| 类型 | 触发时机 | 用途 |
|
|
8
|
+
|------|---------|------|
|
|
9
|
+
| PreToolUse | 工具执行前 | 验证、准备、确认 |
|
|
10
|
+
| PostToolUse | 工具执行后 | 格式化、检查、通知 |
|
|
11
|
+
| Stop | 会话结束时 | 总结、清理、保存 |
|
|
12
|
+
|
|
13
|
+
## 推荐的 Hook 配置
|
|
14
|
+
|
|
15
|
+
### PreToolUse Hooks
|
|
16
|
+
|
|
17
|
+
**1. Git Push 审查**
|
|
18
|
+
|
|
19
|
+
在 `git push` 前确认分支和状态:
|
|
20
|
+
|
|
21
|
+
```javascript
|
|
22
|
+
// hooks/git-push-review.cjs
|
|
23
|
+
module.exports = {
|
|
24
|
+
event: 'PreToolUse',
|
|
25
|
+
condition: (input) => {
|
|
26
|
+
return input.tool === 'Bash' &&
|
|
27
|
+
input.input?.command?.includes('git push')
|
|
28
|
+
},
|
|
29
|
+
action: async (input, context) => {
|
|
30
|
+
// 获取当前分支
|
|
31
|
+
const branch = execSync('git branch --show-current').toString().trim()
|
|
32
|
+
|
|
33
|
+
// 检查是否推送到 main/master
|
|
34
|
+
if (branch === 'main' || branch === 'master') {
|
|
35
|
+
return {
|
|
36
|
+
decision: 'ask',
|
|
37
|
+
message: `即将推送到 ${branch} 分支,确认继续?`
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
return { decision: 'allow' }
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
**2. 敏感文件保护**
|
|
47
|
+
|
|
48
|
+
防止修改关键配置文件:
|
|
49
|
+
|
|
50
|
+
```javascript
|
|
51
|
+
// hooks/protect-sensitive.cjs
|
|
52
|
+
const PROTECTED_PATTERNS = [
|
|
53
|
+
'.env',
|
|
54
|
+
'credentials',
|
|
55
|
+
'secrets',
|
|
56
|
+
'*.pem',
|
|
57
|
+
'*.key'
|
|
58
|
+
]
|
|
59
|
+
|
|
60
|
+
module.exports = {
|
|
61
|
+
event: 'PreToolUse',
|
|
62
|
+
condition: (input) => {
|
|
63
|
+
return ['Write', 'Edit'].includes(input.tool)
|
|
64
|
+
},
|
|
65
|
+
action: async (input, context) => {
|
|
66
|
+
const filePath = input.input?.file_path || ''
|
|
67
|
+
|
|
68
|
+
for (const pattern of PROTECTED_PATTERNS) {
|
|
69
|
+
if (filePath.includes(pattern) ||
|
|
70
|
+
filePath.endsWith(pattern.replace('*', ''))) {
|
|
71
|
+
return {
|
|
72
|
+
decision: 'ask',
|
|
73
|
+
message: `即将修改敏感文件 ${filePath},确认继续?`
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
return { decision: 'allow' }
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
```
|
|
82
|
+
|
|
83
|
+
### PostToolUse Hooks
|
|
84
|
+
|
|
85
|
+
**1. 自动格式化**
|
|
86
|
+
|
|
87
|
+
写入文件后自动运行 Prettier:
|
|
88
|
+
|
|
89
|
+
```javascript
|
|
90
|
+
// hooks/auto-format.cjs
|
|
91
|
+
const { execSync } = require('child_process')
|
|
92
|
+
|
|
93
|
+
const FORMATTABLE_EXTENSIONS = [
|
|
94
|
+
'.js', '.jsx', '.ts', '.tsx',
|
|
95
|
+
'.json', '.md', '.css', '.scss'
|
|
96
|
+
]
|
|
97
|
+
|
|
98
|
+
module.exports = {
|
|
99
|
+
event: 'PostToolUse',
|
|
100
|
+
condition: (input, output) => {
|
|
101
|
+
if (!['Write', 'Edit'].includes(input.tool)) return false
|
|
102
|
+
|
|
103
|
+
const filePath = input.input?.file_path || ''
|
|
104
|
+
return FORMATTABLE_EXTENSIONS.some(ext => filePath.endsWith(ext))
|
|
105
|
+
},
|
|
106
|
+
action: async (input, output, context) => {
|
|
107
|
+
const filePath = input.input?.file_path
|
|
108
|
+
|
|
109
|
+
try {
|
|
110
|
+
execSync(`npx prettier --write "${filePath}"`, {
|
|
111
|
+
stdio: 'pipe'
|
|
112
|
+
})
|
|
113
|
+
return { message: `已格式化: ${filePath}` }
|
|
114
|
+
} catch (error) {
|
|
115
|
+
// Prettier 未安装或格式化失败,静默处理
|
|
116
|
+
return null
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
```
|
|
121
|
+
|
|
122
|
+
**2. TypeScript 类型检查**
|
|
123
|
+
|
|
124
|
+
编辑 TS 文件后检查类型:
|
|
125
|
+
|
|
126
|
+
```javascript
|
|
127
|
+
// hooks/type-check.cjs
|
|
128
|
+
const { execSync } = require('child_process')
|
|
129
|
+
|
|
130
|
+
module.exports = {
|
|
131
|
+
event: 'PostToolUse',
|
|
132
|
+
condition: (input, output) => {
|
|
133
|
+
if (!['Write', 'Edit'].includes(input.tool)) return false
|
|
134
|
+
|
|
135
|
+
const filePath = input.input?.file_path || ''
|
|
136
|
+
return filePath.endsWith('.ts') || filePath.endsWith('.tsx')
|
|
137
|
+
},
|
|
138
|
+
action: async (input, output, context) => {
|
|
139
|
+
try {
|
|
140
|
+
execSync('npx tsc --noEmit', {
|
|
141
|
+
stdio: 'pipe',
|
|
142
|
+
timeout: 30000
|
|
143
|
+
})
|
|
144
|
+
return { message: '类型检查通过' }
|
|
145
|
+
} catch (error) {
|
|
146
|
+
const stderr = error.stderr?.toString() || ''
|
|
147
|
+
if (stderr.includes('error')) {
|
|
148
|
+
return {
|
|
149
|
+
message: `类型错误:\n${stderr.slice(0, 500)}`
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
return null
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
```
|
|
157
|
+
|
|
158
|
+
**3. Console.log 警告**
|
|
159
|
+
|
|
160
|
+
检测遗留的调试语句:
|
|
161
|
+
|
|
162
|
+
```javascript
|
|
163
|
+
// hooks/console-warning.cjs
|
|
164
|
+
const fs = require('fs')
|
|
165
|
+
|
|
166
|
+
module.exports = {
|
|
167
|
+
event: 'PostToolUse',
|
|
168
|
+
condition: (input, output) => {
|
|
169
|
+
if (!['Write', 'Edit'].includes(input.tool)) return false
|
|
170
|
+
|
|
171
|
+
const filePath = input.input?.file_path || ''
|
|
172
|
+
return filePath.endsWith('.ts') ||
|
|
173
|
+
filePath.endsWith('.tsx') ||
|
|
174
|
+
filePath.endsWith('.js') ||
|
|
175
|
+
filePath.endsWith('.jsx')
|
|
176
|
+
},
|
|
177
|
+
action: async (input, output, context) => {
|
|
178
|
+
const filePath = input.input?.file_path
|
|
179
|
+
|
|
180
|
+
try {
|
|
181
|
+
const content = fs.readFileSync(filePath, 'utf-8')
|
|
182
|
+
const consoleMatches = content.match(/console\.(log|debug|info)\(/g)
|
|
183
|
+
|
|
184
|
+
if (consoleMatches && consoleMatches.length > 0) {
|
|
185
|
+
return {
|
|
186
|
+
message: `警告: 文件中有 ${consoleMatches.length} 个 console 语句,提交前请移除`
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
} catch (error) {
|
|
190
|
+
// 文件读取失败,静默处理
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
return null
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
```
|
|
197
|
+
|
|
198
|
+
### Stop Hooks
|
|
199
|
+
|
|
200
|
+
**会话总结**
|
|
201
|
+
|
|
202
|
+
会话结束时生成进度总结:
|
|
203
|
+
|
|
204
|
+
```javascript
|
|
205
|
+
// hooks/session-summary.cjs
|
|
206
|
+
module.exports = {
|
|
207
|
+
event: 'Stop',
|
|
208
|
+
action: async (context) => {
|
|
209
|
+
const summary = {
|
|
210
|
+
timestamp: new Date().toISOString(),
|
|
211
|
+
filesModified: context.modifiedFiles || [],
|
|
212
|
+
tasksCompleted: context.completedTasks || [],
|
|
213
|
+
pendingTasks: context.pendingTasks || []
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
// 保存到会话日志
|
|
217
|
+
const logPath = '.claude/session-logs/latest.json'
|
|
218
|
+
fs.writeFileSync(logPath, JSON.stringify(summary, null, 2))
|
|
219
|
+
|
|
220
|
+
return {
|
|
221
|
+
message: `会话已保存,修改了 ${summary.filesModified.length} 个文件`
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
```
|
|
226
|
+
|
|
227
|
+
## Hook 编写原则
|
|
228
|
+
|
|
229
|
+
### 1. 快速执行
|
|
230
|
+
|
|
231
|
+
```
|
|
232
|
+
Hook 不应阻塞主流程超过 2 秒
|
|
233
|
+
使用超时保护
|
|
234
|
+
异步操作不要等待
|
|
235
|
+
```
|
|
236
|
+
|
|
237
|
+
### 2. 静默失败
|
|
238
|
+
|
|
239
|
+
```
|
|
240
|
+
Hook 失败不应中断主流程
|
|
241
|
+
记录错误但继续执行
|
|
242
|
+
提供有意义的错误信息
|
|
243
|
+
```
|
|
244
|
+
|
|
245
|
+
### 3. 最小权限
|
|
246
|
+
|
|
247
|
+
```
|
|
248
|
+
只请求必要的权限
|
|
249
|
+
不修改不相关的文件
|
|
250
|
+
不执行危险命令
|
|
251
|
+
```
|
|
252
|
+
|
|
253
|
+
### 4. 可配置
|
|
254
|
+
|
|
255
|
+
```
|
|
256
|
+
支持通过环境变量配置
|
|
257
|
+
允许禁用特定 hook
|
|
258
|
+
提供合理的默认值
|
|
259
|
+
```
|
|
260
|
+
|
|
261
|
+
## 现有 Hooks 清单
|
|
262
|
+
|
|
263
|
+
当前项目 `.claude/hooks/` 已有:
|
|
264
|
+
|
|
265
|
+
| Hook | 功能 |
|
|
266
|
+
|------|------|
|
|
267
|
+
| code-formatter.cjs | 代码格式化 |
|
|
268
|
+
| multi-session.cjs | 多会话管理 |
|
|
269
|
+
| project-kickoff.cjs | 项目初始化 |
|
|
270
|
+
| rag-skill-loader.cjs | RAG 技能加载 |
|
|
271
|
+
| session-restore.cjs | 会话恢复 |
|
|
272
|
+
| session-save.cjs | 会话保存 |
|
|
273
|
+
| todo-manager.cjs | TODO 管理 |
|
|
274
|
+
| verify-work.cjs | 工作验证 |
|
|
275
|
+
|
|
276
|
+
## 调试 Hooks
|
|
277
|
+
|
|
278
|
+
```bash
|
|
279
|
+
# 启用 hook 调试日志
|
|
280
|
+
export CLAUDE_HOOK_DEBUG=true
|
|
281
|
+
|
|
282
|
+
# 查看 hook 执行日志
|
|
283
|
+
tail -f .claude/logs/hooks.log
|
|
284
|
+
```
|
|
285
|
+
|
|
286
|
+
---
|
|
287
|
+
|
|
288
|
+
**记住**:Hooks 是强大的自动化工具,但要谨慎使用。过多的 hooks 会影响性能,过于激进的 hooks 会干扰正常工作流程。
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
# Performance Rules
|
|
2
|
+
|
|
3
|
+
> 性能和资源管理规则
|
|
4
|
+
|
|
5
|
+
## 模型选择策略
|
|
6
|
+
|
|
7
|
+
根据任务复杂度选择合适的模型:
|
|
8
|
+
|
|
9
|
+
| 模型 | 适用场景 | 成本 |
|
|
10
|
+
|------|---------|------|
|
|
11
|
+
| **Haiku** | 简单任务、高频调用、轻量 agent | 最低 |
|
|
12
|
+
| **Sonnet** | 主要开发、代码生成、工作流编排 | 中等 |
|
|
13
|
+
| **Opus** | 复杂架构决策、深度推理、研究分析 | 最高 |
|
|
14
|
+
|
|
15
|
+
### 推荐配置
|
|
16
|
+
|
|
17
|
+
```
|
|
18
|
+
Conductor → Sonnet (需要全局理解)
|
|
19
|
+
Architect → Opus (需要深度思考)
|
|
20
|
+
Builder → Sonnet (主要编码工作)
|
|
21
|
+
Reviewer → Opus (需要严谨分析)
|
|
22
|
+
Librarian → Haiku (文档整理)
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
## Context Window 管理
|
|
26
|
+
|
|
27
|
+
**关键原则**:避免在 context 的最后 20% 进行复杂操作
|
|
28
|
+
|
|
29
|
+
### 高 Context 敏感任务(避免在 context 末尾)
|
|
30
|
+
- 大规模重构
|
|
31
|
+
- 跨多文件的功能实现
|
|
32
|
+
- 复杂交互调试
|
|
33
|
+
|
|
34
|
+
### 低 Context 敏感任务(可在任何时候)
|
|
35
|
+
- 单文件编辑
|
|
36
|
+
- 独立工具创建
|
|
37
|
+
- 文档更新
|
|
38
|
+
- 简单 bug 修复
|
|
39
|
+
|
|
40
|
+
## MCP 管理
|
|
41
|
+
|
|
42
|
+
**关键**:不要同时启用所有 MCP
|
|
43
|
+
|
|
44
|
+
- 200k context 可能被压缩到 70k
|
|
45
|
+
- 建议配置 20-30 个 MCP
|
|
46
|
+
- 每个项目启用不超过 10 个
|
|
47
|
+
- 活跃工具保持在 80 个以下
|
|
48
|
+
|
|
49
|
+
### 禁用不需要的 MCP
|
|
50
|
+
|
|
51
|
+
在项目 `settings.json` 中:
|
|
52
|
+
|
|
53
|
+
```json
|
|
54
|
+
{
|
|
55
|
+
"disabledMcpServers": [
|
|
56
|
+
"unused-mcp-1",
|
|
57
|
+
"unused-mcp-2"
|
|
58
|
+
]
|
|
59
|
+
}
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
## 构建故障排除
|
|
63
|
+
|
|
64
|
+
构建失败时:
|
|
65
|
+
|
|
66
|
+
1. 使用 **build-error-resolver** skill
|
|
67
|
+
2. 分析错误信息
|
|
68
|
+
3. 增量修复
|
|
69
|
+
4. 每次修复后验证
|
|
70
|
+
|
|
71
|
+
## 复杂任务策略
|
|
72
|
+
|
|
73
|
+
对于需要深度推理的任务:
|
|
74
|
+
|
|
75
|
+
1. 使用 `ultrathink` 模式增强思考
|
|
76
|
+
2. 启用 **Plan Mode** 进行结构化方案
|
|
77
|
+
3. 多轮自我批判优化
|
|
78
|
+
4. 使用分角色 sub-agents 进行多角度分析
|