sumulige-claude 1.5.1 → 1.5.2
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/hooks/hook-registry.json +0 -15
- package/.claude/rules/coding-style.md +18 -7
- package/.claude/rules/hooks.md +15 -4
- package/.claude/rules/performance.md +15 -5
- package/.claude/rules/security.md +140 -4
- package/.claude/rules/testing.md +138 -9
- package/.claude/rules/web-design-standard.md +16 -5
- package/.claude/skills/algorithmic-art/metadata.yaml +28 -0
- package/.claude/skills/api-tester/SKILL.md +61 -0
- package/.claude/skills/api-tester/examples/basic.md +3 -0
- package/.claude/skills/api-tester/metadata.yaml +30 -0
- package/.claude/skills/api-tester/templates/default.md +3 -0
- package/.claude/skills/brand-guidelines/metadata.yaml +26 -0
- package/.claude/skills/canvas-design/metadata.yaml +27 -0
- package/.claude/skills/code-reviewer-123/SKILL.md +61 -0
- package/.claude/skills/code-reviewer-123/examples/basic.md +3 -0
- package/.claude/skills/code-reviewer-123/metadata.yaml +30 -0
- package/.claude/skills/code-reviewer-123/templates/default.md +3 -0
- package/.claude/skills/doc-coauthoring/metadata.yaml +27 -0
- package/.claude/skills/docx/metadata.yaml +30 -0
- package/.claude/skills/frontend-design/metadata.yaml +28 -0
- package/.claude/skills/internal-comms/metadata.yaml +28 -0
- package/.claude/skills/mcp-builder/metadata.yaml +26 -0
- package/.claude/skills/my-skill/SKILL.md +61 -0
- package/.claude/skills/my-skill/examples/basic.md +3 -0
- package/.claude/skills/my-skill/metadata.yaml +30 -0
- package/.claude/skills/my-skill/templates/default.md +3 -0
- package/.claude/skills/pdf/metadata.yaml +29 -0
- package/.claude/skills/pptx/metadata.yaml +29 -0
- package/.claude/skills/react-best-practices/metadata.yaml +26 -0
- package/.claude/skills/react-node-practices/SKILL.md +409 -0
- package/.claude/skills/react-node-practices/metadata.yaml +56 -0
- package/.claude/skills/skill-creator/metadata.yaml +25 -0
- package/.claude/skills/slack-gif-creator/metadata.yaml +28 -0
- package/.claude/skills/test-skill-name/SKILL.md +61 -0
- package/.claude/skills/test-skill-name/examples/basic.md +3 -0
- package/.claude/skills/test-skill-name/metadata.yaml +30 -0
- package/.claude/skills/test-skill-name/templates/default.md +3 -0
- package/.claude/skills/test-workflow/metadata.yaml +32 -0
- package/.claude/skills/theme-factory/metadata.yaml +26 -0
- package/.claude/skills/threejs-fundamentals/metadata.yaml +27 -0
- package/.claude/skills/web-artifacts-builder/metadata.yaml +30 -0
- package/.claude/skills/web-design-guidelines/metadata.yaml +26 -0
- package/.claude/skills/webapp-testing/metadata.yaml +26 -0
- package/.claude/skills/xlsx/metadata.yaml +29 -0
- package/LICENSE +21 -0
- package/cli.js +1 -1
- package/package.json +25 -3
- package/.claude/.kickoff-hint.txt +0 -52
- package/.claude/.sumulige-claude-version +0 -1
- package/.claude/.version +0 -1
- package/.claude/AGENTS.md +0 -42
- package/.claude/ANCHORS.md +0 -40
- package/.claude/CLAUDE.md +0 -138
- package/.claude/MEMORY.md +0 -69
- package/.claude/PROJECT_LOG.md +0 -101
- package/.claude/THINKING_CHAIN_GUIDE.md +0 -287
- package/.claude/USAGE.md +0 -175
- package/.claude/boris-optimizations.md +0 -167
- package/.claude/handoffs/INDEX.md +0 -21
- package/.claude/handoffs/LATEST.md +0 -76
- package/.claude/handoffs/handoff_2026-01-22T13-07-04-757Z.md +0 -76
- package/.claude/quality-gate.json +0 -82
- package/.claude/rag/skill-index.json +0 -135
- package/.claude/settings.json +0 -99
- package/.claude/settings.local.json +0 -175
- package/.claude/templates/PROJECT_KICKOFF.md +0 -89
- package/.claude/templates/PROJECT_PROPOSAL.md +0 -227
- package/.claude/templates/TASK_PLAN.md +0 -121
- package/.claude/templates/hooks/README.md +0 -302
- package/.claude/templates/hooks/hook.sh.template +0 -94
- package/.claude/templates/hooks/user-prompt-submit.cjs.template +0 -116
- package/.claude/templates/hooks/user-response-submit.cjs.template +0 -94
- package/.claude/templates/hooks/validate.js +0 -173
- package/.claude/templates/tasks/develop.md +0 -69
- package/.claude/templates/tasks/research.md +0 -64
- package/.claude/templates/tasks/test.md +0 -96
- package/.claude/thinking-routes/.last-sync +0 -1
- package/.claude/thinking-routes/QUICKREF.md +0 -98
- package/.claude/workflow/document-scanner.js +0 -426
- package/.claude/workflow/knowledge-engine.js +0 -941
- package/.claude/workflow/notebooklm/browser.js +0 -1028
- package/.claude/workflow/phases/phase1-research.js +0 -578
- package/.claude/workflow/phases/phase1-research.ts +0 -465
- package/.claude/workflow/phases/phase2-approve.js +0 -722
- package/.claude/workflow/phases/phase3-plan.js +0 -1200
- package/.claude/workflow/phases/phase4-develop.js +0 -894
- package/.claude/workflow/search-cache.js +0 -230
- package/.claude/workflow/templates/approval.md +0 -315
- package/.claude/workflow/templates/development.md +0 -377
- package/.claude/workflow/templates/planning.md +0 -328
- package/.claude/workflow/templates/research.md +0 -250
- package/.claude/workflow/types.js +0 -37
- package/.claude/workflow/web-search.js +0 -278
- package/.claude-plugin/marketplace.json +0 -71
- package/.github/workflows/sync-skills.yml +0 -74
- package/.versionrc +0 -25
- package/AGENTS.md +0 -580
- package/CHANGELOG.md +0 -481
- package/CLAUDE-template.md +0 -114
- package/DEV_TOOLS_GUIDE.md +0 -190
- package/PROJECT_STRUCTURE.md +0 -266
- package/Q&A.md +0 -325
- package/config/defaults.json +0 -34
- package/config/official-skills.json +0 -183
- package/config/quality-gate.json +0 -67
- package/config/skill-categories.json +0 -40
- package/config/version-manifest.json +0 -85
- package/demos/power-3d-scatter.html +0 -683
- package/development/cache/web-search/search_1193d605f8eb364651fc2f2041b58a31.json +0 -36
- package/development/cache/web-search/search_3798bf06960edc125f744a1abb5b72c5.json +0 -36
- package/development/cache/web-search/search_37c7d4843a53f0d83f1122a6f908a2a3.json +0 -36
- package/development/cache/web-search/search_44166fa0153709ee168485a22aa0ab40.json +0 -36
- package/development/cache/web-search/search_4deaebb1f77e86a8ca066dc5a49c59fd.json +0 -36
- package/development/cache/web-search/search_94da91789466070a7f545612e73c7372.json +0 -36
- package/development/cache/web-search/search_dd5de8491b8b803a3cb01339cd210fb0.json +0 -36
- package/development/knowledge-base/.index.clean.json +0 -1
- package/development/knowledge-base/.index.json +0 -486
- package/development/knowledge-base/test-best-practices.md +0 -29
- package/development/projects/proj_mkh1pazz_ixmt1/phase1/feasibility-report.md +0 -160
- package/development/projects/proj_mkh4jvnb_z7rwf/phase1/feasibility-report.md +0 -160
- package/development/projects/proj_mkh4jxkd_ewz5a/phase1/feasibility-report.md +0 -160
- package/development/projects/proj_mkh4k84n_ni73k/phase1/feasibility-report.md +0 -160
- package/development/projects/proj_mkh4wfyd_u9w88/phase1/feasibility-report.md +0 -160
- package/development/projects/proj_mkh4wsbo_iahvf/development/projects/proj_mkh4xbpg_4na5w/phase1/feasibility-report.md +0 -160
- package/development/projects/proj_mkh4wsbo_iahvf/phase1/feasibility-report.md +0 -160
- package/development/projects/proj_mkh4xulg_1ka8x/phase1/feasibility-report.md +0 -160
- package/development/projects/proj_mkh4xwhj_gch8j/phase1/feasibility-report.md +0 -160
- package/development/projects/proj_mkh4y2qk_9lm8z/phase1/feasibility-report.md +0 -160
- package/development/projects/proj_mkh4y2qk_9lm8z/phase2/requirements.md +0 -226
- package/development/projects/proj_mkh4y2qk_9lm8z/phase3/PRD.md +0 -345
- package/development/projects/proj_mkh4y2qk_9lm8z/phase3/TASK_PLAN.md +0 -284
- package/development/projects/proj_mkh4y2qk_9lm8z/phase3/prototype/README.md +0 -14
- package/development/projects/proj_mkh4y2qk_9lm8z/phase4/DEVELOPMENT_LOG.md +0 -35
- package/development/projects/proj_mkh4y2qk_9lm8z/phase4/TASKS.md +0 -34
- package/development/projects/proj_mkh4y2qk_9lm8z/phase4/source/.env.example +0 -5
- package/development/projects/proj_mkh4y2qk_9lm8z/phase4/source/README.md +0 -60
- package/development/projects/proj_mkh4y2qk_9lm8z/phase4/source/package.json +0 -25
- package/development/projects/proj_mkh4y2qk_9lm8z/phase4/source/src/index.js +0 -70
- package/development/projects/proj_mkh4y2qk_9lm8z/phase4/source/src/routes/index.js +0 -48
- package/development/projects/proj_mkh4y2qk_9lm8z/phase4/source/tests/health.test.js +0 -20
- package/development/projects/proj_mkh4y2qk_9lm8z/phase4/source/tests/jest.config.js +0 -21
- package/development/projects/proj_mkh7veqg_3lypc/phase1/feasibility-report.md +0 -160
- package/development/projects/proj_mkh7veqg_3lypc/phase2/requirements.md +0 -226
- package/development/projects/proj_mkh7veqg_3lypc/phase3/PRD.md +0 -345
- package/development/projects/proj_mkh7veqg_3lypc/phase3/TASK_PLAN.md +0 -284
- package/development/projects/proj_mkh7veqg_3lypc/phase3/prototype/README.md +0 -14
- package/development/projects/proj_mkh8k8fo_rmqn5/phase1/feasibility-report.md +0 -160
- package/development/projects/proj_mkh8xyhy_1vshq/phase1/feasibility-report.md +0 -178
- package/development/projects/proj_mkh8zddd_dhamf/phase1/feasibility-report.md +0 -377
- package/development/projects/proj_mkh8zddd_dhamf/phase2/requirements.md +0 -442
- package/development/projects/proj_mkh8zddd_dhamf/phase3/api-design.md +0 -800
- package/development/projects/proj_mkh8zddd_dhamf/phase3/architecture.md +0 -625
- package/development/projects/proj_mkh8zddd_dhamf/phase3/data-model.md +0 -830
- package/development/projects/proj_mkh8zddd_dhamf/phase3/risks.md +0 -957
- package/development/projects/proj_mkh8zddd_dhamf/phase3/wbs.md +0 -381
- package/development/todos/.state.json +0 -19
- package/development/todos/INDEX.md +0 -63
- package/development/todos/active/_README.md +0 -49
- package/development/todos/archived/_README.md +0 -11
- package/development/todos/backlog/_README.md +0 -11
- package/development/todos/backlog/mcp-integration.md +0 -35
- package/development/todos/completed/_README.md +0 -11
- package/development/todos/completed/boris-optimizations.md +0 -39
- package/development/todos/completed/develop/local-knowledge-index.md +0 -85
- package/development/todos/completed/develop/todo-system.md +0 -47
- package/development/todos/completed/develop/web-search-integration.md +0 -83
- package/development/todos/completed/test/phase1-e2e-test.md +0 -103
- package/docs/DEVELOPMENT.md +0 -461
- package/docs/MARKETPLACE.md +0 -352
- package/docs/RELEASE.md +0 -93
- package/jest.config.js +0 -63
- package/lib/commands.js +0 -3588
- package/lib/config-manager.js +0 -441
- package/lib/config-schema.js +0 -408
- package/lib/config-validator.js +0 -330
- package/lib/config.js +0 -122
- package/lib/errors.js +0 -305
- package/lib/incremental-sync.js +0 -274
- package/lib/marketplace.js +0 -487
- package/lib/migrations.js +0 -154
- package/lib/permission-audit.js +0 -255
- package/lib/quality-gate.js +0 -431
- package/lib/quality-rules.js +0 -373
- package/lib/utils.js +0 -150
- package/lib/version-check.js +0 -169
- package/lib/version-manifest.js +0 -171
- package/project-paradigm.md +0 -313
- package/prompts/how-to-find.md +0 -163
- package/prompts/linus-architect.md +0 -71
- package/prompts/software-architect.md +0 -173
- package/prompts/web-designer.md +0 -249
- package/scripts/fix-hooks.mjs +0 -97
- package/scripts/sync-external.mjs +0 -298
- package/scripts/sync-to-home.sh +0 -108
- package/scripts/update-registry.mjs +0 -325
- package/sources.yaml +0 -83
- package/tests/README.md +0 -263
- package/tests/commands.test.js +0 -1086
- package/tests/config-manager.test.js +0 -677
- package/tests/config-schema.test.js +0 -425
- package/tests/config-validator.test.js +0 -436
- package/tests/config.test.js +0 -100
- package/tests/errors.test.js +0 -477
- package/tests/manual/phase1-e2e.sh +0 -389
- package/tests/manual/phase2-test-cases.md +0 -311
- package/tests/manual/phase3-test-cases.md +0 -309
- package/tests/manual/phase4-test-cases.md +0 -414
- package/tests/manual/test-cases.md +0 -417
- package/tests/marketplace.test.js +0 -420
- package/tests/migrations.test.js +0 -187
- package/tests/quality-gate.test.js +0 -679
- package/tests/quality-rules.test.js +0 -619
- package/tests/sync-external.test.js +0 -214
- package/tests/update-registry.test.js +0 -251
- package/tests/utils.test.js +0 -171
- package/tests/version-check.test.js +0 -75
- package/tests/web-search.test.js +0 -392
- package/thinkinglens-silent.md +0 -138
|
@@ -0,0 +1,409 @@
|
|
|
1
|
+
# React & Node.js Best Practices
|
|
2
|
+
|
|
3
|
+
> AI Agent 编写正确代码的知识包 - 灵感来自 Supabase Agent Skills
|
|
4
|
+
|
|
5
|
+
## 规则分类(按优先级)
|
|
6
|
+
|
|
7
|
+
| 优先级 | 类别 | 说明 |
|
|
8
|
+
|--------|------|------|
|
|
9
|
+
| 🔴 Critical | 安全 & 性能 | 必须遵守,违反将阻止提交 |
|
|
10
|
+
| 🟠 High | 架构 & 模式 | 应该遵守,影响可维护性 |
|
|
11
|
+
| 🟡 Medium | 代码质量 | 建议遵守,提升代码质量 |
|
|
12
|
+
| 🟢 Low | 风格偏好 | 可选遵守,团队约定 |
|
|
13
|
+
|
|
14
|
+
---
|
|
15
|
+
|
|
16
|
+
## 🔴 Critical: 安全规则
|
|
17
|
+
|
|
18
|
+
### SEC-001: 环境变量处理
|
|
19
|
+
|
|
20
|
+
```typescript
|
|
21
|
+
// ❌ 错误:硬编码密钥
|
|
22
|
+
const apiKey = "sk-proj-xxxxx"
|
|
23
|
+
const dbUrl = "postgres://user:pass@localhost/db"
|
|
24
|
+
|
|
25
|
+
// ✅ 正确:环境变量
|
|
26
|
+
const apiKey = process.env.API_KEY
|
|
27
|
+
if (!apiKey) throw new Error('API_KEY not configured')
|
|
28
|
+
|
|
29
|
+
// ✅ 正确:使用 zod 验证环境变量
|
|
30
|
+
import { z } from 'zod'
|
|
31
|
+
const envSchema = z.object({
|
|
32
|
+
API_KEY: z.string().min(1),
|
|
33
|
+
DATABASE_URL: z.string().url(),
|
|
34
|
+
})
|
|
35
|
+
const env = envSchema.parse(process.env)
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
### SEC-002: 用户输入验证
|
|
39
|
+
|
|
40
|
+
```typescript
|
|
41
|
+
// ❌ 错误:信任用户输入
|
|
42
|
+
app.post('/user', (req, res) => {
|
|
43
|
+
db.query(`SELECT * FROM users WHERE id = ${req.body.id}`)
|
|
44
|
+
})
|
|
45
|
+
|
|
46
|
+
// ✅ 正确:参数化查询 + 验证
|
|
47
|
+
import { z } from 'zod'
|
|
48
|
+
const userIdSchema = z.string().uuid()
|
|
49
|
+
|
|
50
|
+
app.post('/user', (req, res) => {
|
|
51
|
+
const id = userIdSchema.parse(req.body.id)
|
|
52
|
+
db.query('SELECT * FROM users WHERE id = $1', [id])
|
|
53
|
+
})
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
### SEC-003: 敏感数据不入日志
|
|
57
|
+
|
|
58
|
+
```typescript
|
|
59
|
+
// ❌ 错误:记录敏感信息
|
|
60
|
+
console.log('User login:', { email, password, token })
|
|
61
|
+
logger.info('Payment:', { cardNumber, cvv })
|
|
62
|
+
|
|
63
|
+
// ✅ 正确:脱敏处理
|
|
64
|
+
console.log('User login:', { email, password: '[REDACTED]' })
|
|
65
|
+
logger.info('Payment:', { cardLast4: card.slice(-4) })
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
### SEC-004: XSS 防护
|
|
69
|
+
|
|
70
|
+
```tsx
|
|
71
|
+
// ❌ 错误:直接渲染用户内容
|
|
72
|
+
<div dangerouslySetInnerHTML={{ __html: userContent }} />
|
|
73
|
+
|
|
74
|
+
// ✅ 正确:使用 DOMPurify 或避免 dangerouslySetInnerHTML
|
|
75
|
+
import DOMPurify from 'dompurify'
|
|
76
|
+
<div dangerouslySetInnerHTML={{ __html: DOMPurify.sanitize(userContent) }} />
|
|
77
|
+
|
|
78
|
+
// ✅ 更好:直接渲染文本
|
|
79
|
+
<div>{userContent}</div>
|
|
80
|
+
```
|
|
81
|
+
|
|
82
|
+
---
|
|
83
|
+
|
|
84
|
+
## 🔴 Critical: 性能规则
|
|
85
|
+
|
|
86
|
+
### PERF-001: 避免 useEffect 瀑布
|
|
87
|
+
|
|
88
|
+
```tsx
|
|
89
|
+
// ❌ 错误:串行请求
|
|
90
|
+
useEffect(() => {
|
|
91
|
+
fetchUser().then(user => {
|
|
92
|
+
fetchPosts(user.id).then(posts => {
|
|
93
|
+
fetchComments(posts[0].id)
|
|
94
|
+
})
|
|
95
|
+
})
|
|
96
|
+
}, [])
|
|
97
|
+
|
|
98
|
+
// ✅ 正确:并行请求
|
|
99
|
+
useEffect(() => {
|
|
100
|
+
Promise.all([
|
|
101
|
+
fetchUser(),
|
|
102
|
+
fetchPosts(),
|
|
103
|
+
fetchComments()
|
|
104
|
+
]).then(([user, posts, comments]) => {
|
|
105
|
+
// 处理数据
|
|
106
|
+
})
|
|
107
|
+
}, [])
|
|
108
|
+
|
|
109
|
+
// ✅ 更好:使用 React Query / SWR
|
|
110
|
+
const { data: user } = useQuery('user', fetchUser)
|
|
111
|
+
const { data: posts } = useQuery(['posts', user?.id], () => fetchPosts(user.id), {
|
|
112
|
+
enabled: !!user
|
|
113
|
+
})
|
|
114
|
+
```
|
|
115
|
+
|
|
116
|
+
### PERF-002: 大列表虚拟化
|
|
117
|
+
|
|
118
|
+
```tsx
|
|
119
|
+
// ❌ 错误:渲染 10000 条数据
|
|
120
|
+
{items.map(item => <ListItem key={item.id} {...item} />)}
|
|
121
|
+
|
|
122
|
+
// ✅ 正确:虚拟化
|
|
123
|
+
import { FixedSizeList } from 'react-window'
|
|
124
|
+
|
|
125
|
+
<FixedSizeList
|
|
126
|
+
height={600}
|
|
127
|
+
itemCount={items.length}
|
|
128
|
+
itemSize={50}
|
|
129
|
+
>
|
|
130
|
+
{({ index, style }) => (
|
|
131
|
+
<ListItem style={style} {...items[index]} />
|
|
132
|
+
)}
|
|
133
|
+
</FixedSizeList>
|
|
134
|
+
```
|
|
135
|
+
|
|
136
|
+
### PERF-003: 避免 N+1 查询
|
|
137
|
+
|
|
138
|
+
```typescript
|
|
139
|
+
// ❌ 错误:N+1 查询
|
|
140
|
+
const users = await db.query('SELECT * FROM users')
|
|
141
|
+
for (const user of users) {
|
|
142
|
+
user.posts = await db.query('SELECT * FROM posts WHERE user_id = $1', [user.id])
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
// ✅ 正确:JOIN 或批量查询
|
|
146
|
+
const users = await db.query(`
|
|
147
|
+
SELECT u.*, json_agg(p.*) as posts
|
|
148
|
+
FROM users u
|
|
149
|
+
LEFT JOIN posts p ON p.user_id = u.id
|
|
150
|
+
GROUP BY u.id
|
|
151
|
+
`)
|
|
152
|
+
```
|
|
153
|
+
|
|
154
|
+
---
|
|
155
|
+
|
|
156
|
+
## 🟠 High: 架构规则
|
|
157
|
+
|
|
158
|
+
### ARCH-001: 组件职责单一
|
|
159
|
+
|
|
160
|
+
```tsx
|
|
161
|
+
// ❌ 错误:组件做太多事
|
|
162
|
+
function UserDashboard() {
|
|
163
|
+
const [user, setUser] = useState(null)
|
|
164
|
+
const [posts, setPosts] = useState([])
|
|
165
|
+
const [loading, setLoading] = useState(true)
|
|
166
|
+
|
|
167
|
+
useEffect(() => {
|
|
168
|
+
// 请求数据...
|
|
169
|
+
}, [])
|
|
170
|
+
|
|
171
|
+
const handleSubmit = async (data) => {
|
|
172
|
+
// 提交表单...
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
return (
|
|
176
|
+
<div>
|
|
177
|
+
{/* 200 行 JSX */}
|
|
178
|
+
</div>
|
|
179
|
+
)
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
// ✅ 正确:拆分职责
|
|
183
|
+
// hooks/useUser.ts
|
|
184
|
+
function useUser(id: string) {
|
|
185
|
+
return useQuery(['user', id], () => fetchUser(id))
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
// components/UserDashboard.tsx
|
|
189
|
+
function UserDashboard({ userId }) {
|
|
190
|
+
const { data: user, isLoading } = useUser(userId)
|
|
191
|
+
|
|
192
|
+
if (isLoading) return <Skeleton />
|
|
193
|
+
|
|
194
|
+
return (
|
|
195
|
+
<div>
|
|
196
|
+
<UserHeader user={user} />
|
|
197
|
+
<UserPosts userId={userId} />
|
|
198
|
+
<UserStats userId={userId} />
|
|
199
|
+
</div>
|
|
200
|
+
)
|
|
201
|
+
}
|
|
202
|
+
```
|
|
203
|
+
|
|
204
|
+
### ARCH-002: 错误边界
|
|
205
|
+
|
|
206
|
+
```tsx
|
|
207
|
+
// ❌ 错误:无错误处理
|
|
208
|
+
function App() {
|
|
209
|
+
return <UserDashboard />
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
// ✅ 正确:添加错误边界
|
|
213
|
+
import { ErrorBoundary } from 'react-error-boundary'
|
|
214
|
+
|
|
215
|
+
function App() {
|
|
216
|
+
return (
|
|
217
|
+
<ErrorBoundary
|
|
218
|
+
fallback={<ErrorPage />}
|
|
219
|
+
onError={(error) => reportError(error)}
|
|
220
|
+
>
|
|
221
|
+
<UserDashboard />
|
|
222
|
+
</ErrorBoundary>
|
|
223
|
+
)
|
|
224
|
+
}
|
|
225
|
+
```
|
|
226
|
+
|
|
227
|
+
### ARCH-003: API 路由分层
|
|
228
|
+
|
|
229
|
+
```typescript
|
|
230
|
+
// ❌ 错误:路由中混合业务逻辑
|
|
231
|
+
app.post('/users', async (req, res) => {
|
|
232
|
+
const { email, password } = req.body
|
|
233
|
+
const hashedPassword = await bcrypt.hash(password, 10)
|
|
234
|
+
const user = await db.query('INSERT INTO users...')
|
|
235
|
+
await sendEmail(email, 'Welcome!')
|
|
236
|
+
res.json(user)
|
|
237
|
+
})
|
|
238
|
+
|
|
239
|
+
// ✅ 正确:分层架构
|
|
240
|
+
// routes/users.ts
|
|
241
|
+
router.post('/', validateBody(createUserSchema), userController.create)
|
|
242
|
+
|
|
243
|
+
// controllers/userController.ts
|
|
244
|
+
async create(req, res) {
|
|
245
|
+
const user = await userService.create(req.body)
|
|
246
|
+
res.status(201).json(user)
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
// services/userService.ts
|
|
250
|
+
async create(data: CreateUserDTO) {
|
|
251
|
+
const user = await userRepository.create(data)
|
|
252
|
+
await emailService.sendWelcome(user.email)
|
|
253
|
+
return user
|
|
254
|
+
}
|
|
255
|
+
```
|
|
256
|
+
|
|
257
|
+
---
|
|
258
|
+
|
|
259
|
+
## 🟡 Medium: 代码质量
|
|
260
|
+
|
|
261
|
+
### QUAL-001: 类型安全优先
|
|
262
|
+
|
|
263
|
+
```typescript
|
|
264
|
+
// ❌ 错误:any 类型
|
|
265
|
+
function processData(data: any) {
|
|
266
|
+
return data.items.map((item: any) => item.name)
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
// ✅ 正确:明确类型
|
|
270
|
+
interface DataResponse {
|
|
271
|
+
items: Array<{ id: string; name: string }>
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
function processData(data: DataResponse) {
|
|
275
|
+
return data.items.map(item => item.name)
|
|
276
|
+
}
|
|
277
|
+
```
|
|
278
|
+
|
|
279
|
+
### QUAL-002: 避免魔法值
|
|
280
|
+
|
|
281
|
+
```typescript
|
|
282
|
+
// ❌ 错误:魔法数字
|
|
283
|
+
if (status === 200) { ... }
|
|
284
|
+
if (user.role === 1) { ... }
|
|
285
|
+
setTimeout(fn, 86400000)
|
|
286
|
+
|
|
287
|
+
// ✅ 正确:常量
|
|
288
|
+
const HTTP_OK = 200
|
|
289
|
+
const ROLE_ADMIN = 1
|
|
290
|
+
const ONE_DAY_MS = 24 * 60 * 60 * 1000
|
|
291
|
+
|
|
292
|
+
if (status === HTTP_OK) { ... }
|
|
293
|
+
if (user.role === ROLE_ADMIN) { ... }
|
|
294
|
+
setTimeout(fn, ONE_DAY_MS)
|
|
295
|
+
```
|
|
296
|
+
|
|
297
|
+
### QUAL-003: 不可变更新
|
|
298
|
+
|
|
299
|
+
```typescript
|
|
300
|
+
// ❌ 错误:变异状态
|
|
301
|
+
function updateUser(user, name) {
|
|
302
|
+
user.name = name
|
|
303
|
+
return user
|
|
304
|
+
}
|
|
305
|
+
|
|
306
|
+
// ✅ 正确:不可变
|
|
307
|
+
function updateUser(user, name) {
|
|
308
|
+
return { ...user, name }
|
|
309
|
+
}
|
|
310
|
+
|
|
311
|
+
// ❌ 错误:变异数组
|
|
312
|
+
items.push(newItem)
|
|
313
|
+
items.sort()
|
|
314
|
+
|
|
315
|
+
// ✅ 正确:创建新数组
|
|
316
|
+
const newItems = [...items, newItem]
|
|
317
|
+
const sortedItems = [...items].sort()
|
|
318
|
+
```
|
|
319
|
+
|
|
320
|
+
---
|
|
321
|
+
|
|
322
|
+
## 🟢 Low: 风格偏好
|
|
323
|
+
|
|
324
|
+
### STYLE-001: 导入顺序
|
|
325
|
+
|
|
326
|
+
```typescript
|
|
327
|
+
// ✅ 推荐顺序
|
|
328
|
+
// 1. 外部依赖
|
|
329
|
+
import React from 'react'
|
|
330
|
+
import { useQuery } from '@tanstack/react-query'
|
|
331
|
+
|
|
332
|
+
// 2. 内部模块(绝对路径)
|
|
333
|
+
import { Button } from '@/components/ui'
|
|
334
|
+
import { useAuth } from '@/hooks/useAuth'
|
|
335
|
+
|
|
336
|
+
// 3. 相对路径
|
|
337
|
+
import { UserAvatar } from './UserAvatar'
|
|
338
|
+
import styles from './User.module.css'
|
|
339
|
+
|
|
340
|
+
// 4. 类型(单独)
|
|
341
|
+
import type { User } from '@/types'
|
|
342
|
+
```
|
|
343
|
+
|
|
344
|
+
### STYLE-002: 命名约定
|
|
345
|
+
|
|
346
|
+
| 类型 | 约定 | 示例 |
|
|
347
|
+
|------|------|------|
|
|
348
|
+
| 组件 | PascalCase | `UserProfile.tsx` |
|
|
349
|
+
| Hook | camelCase + use 前缀 | `useAuth.ts` |
|
|
350
|
+
| 工具函数 | camelCase | `formatDate.ts` |
|
|
351
|
+
| 常量 | SCREAMING_SNAKE | `MAX_RETRY_COUNT` |
|
|
352
|
+
| 类型/接口 | PascalCase | `UserResponse` |
|
|
353
|
+
|
|
354
|
+
---
|
|
355
|
+
|
|
356
|
+
## 检查清单
|
|
357
|
+
|
|
358
|
+
### 提交前必查(🔴 Critical)
|
|
359
|
+
|
|
360
|
+
- [ ] 无硬编码密钥/凭证
|
|
361
|
+
- [ ] 所有用户输入已验证
|
|
362
|
+
- [ ] 无 SQL 注入风险
|
|
363
|
+
- [ ] 无 XSS 漏洞
|
|
364
|
+
- [ ] 无 N+1 查询
|
|
365
|
+
- [ ] 大列表已虚拟化
|
|
366
|
+
|
|
367
|
+
### 代码审查(🟠 High)
|
|
368
|
+
|
|
369
|
+
- [ ] 组件职责单一
|
|
370
|
+
- [ ] 有错误边界
|
|
371
|
+
- [ ] API 分层清晰
|
|
372
|
+
- [ ] 异步错误处理完善
|
|
373
|
+
|
|
374
|
+
### 质量提升(🟡 Medium)
|
|
375
|
+
|
|
376
|
+
- [ ] 无 any 类型
|
|
377
|
+
- [ ] 无魔法值
|
|
378
|
+
- [ ] 使用不可变更新
|
|
379
|
+
|
|
380
|
+
---
|
|
381
|
+
|
|
382
|
+
## 相关工具
|
|
383
|
+
|
|
384
|
+
```bash
|
|
385
|
+
# 类型检查
|
|
386
|
+
npx tsc --noEmit
|
|
387
|
+
|
|
388
|
+
# 安全审计
|
|
389
|
+
npm audit
|
|
390
|
+
npx snyk test
|
|
391
|
+
|
|
392
|
+
# 代码质量
|
|
393
|
+
npx eslint . --ext .ts,.tsx
|
|
394
|
+
npx knip # 未使用代码检测
|
|
395
|
+
```
|
|
396
|
+
|
|
397
|
+
---
|
|
398
|
+
|
|
399
|
+
## 使用方式
|
|
400
|
+
|
|
401
|
+
AI Agent 在编写 React/Node.js 代码时应:
|
|
402
|
+
|
|
403
|
+
1. **优先检查 Critical 规则** - 违反则必须修复
|
|
404
|
+
2. **参考正确/错误示例** - 理解为什么这样做
|
|
405
|
+
3. **使用检查清单** - 提交前自查
|
|
406
|
+
|
|
407
|
+
---
|
|
408
|
+
|
|
409
|
+
**原则**:安全 > 性能 > 可维护性 > 风格
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
name: react-node-practices
|
|
2
|
+
version: 1.0.0
|
|
3
|
+
author: "@sumulige"
|
|
4
|
+
description: React & Node.js 最佳实践 - AI Agent 编写正确代码的知识包
|
|
5
|
+
|
|
6
|
+
tags:
|
|
7
|
+
- react
|
|
8
|
+
- nodejs
|
|
9
|
+
- typescript
|
|
10
|
+
- best-practices
|
|
11
|
+
- security
|
|
12
|
+
- performance
|
|
13
|
+
|
|
14
|
+
triggers:
|
|
15
|
+
- react
|
|
16
|
+
- node
|
|
17
|
+
- typescript
|
|
18
|
+
- frontend
|
|
19
|
+
- backend
|
|
20
|
+
- fullstack
|
|
21
|
+
|
|
22
|
+
dependencies: []
|
|
23
|
+
|
|
24
|
+
difficulty: intermediate
|
|
25
|
+
|
|
26
|
+
# 规则优先级分布
|
|
27
|
+
rule_categories:
|
|
28
|
+
critical:
|
|
29
|
+
- SEC-001 # 环境变量处理
|
|
30
|
+
- SEC-002 # 用户输入验证
|
|
31
|
+
- SEC-003 # 敏感数据不入日志
|
|
32
|
+
- SEC-004 # XSS 防护
|
|
33
|
+
- PERF-001 # 避免 useEffect 瀑布
|
|
34
|
+
- PERF-002 # 大列表虚拟化
|
|
35
|
+
- PERF-003 # 避免 N+1 查询
|
|
36
|
+
high:
|
|
37
|
+
- ARCH-001 # 组件职责单一
|
|
38
|
+
- ARCH-002 # 错误边界
|
|
39
|
+
- ARCH-003 # API 路由分层
|
|
40
|
+
medium:
|
|
41
|
+
- QUAL-001 # 类型安全优先
|
|
42
|
+
- QUAL-002 # 避免魔法值
|
|
43
|
+
- QUAL-003 # 不可变更新
|
|
44
|
+
low:
|
|
45
|
+
- STYLE-001 # 导入顺序
|
|
46
|
+
- STYLE-002 # 命名约定
|
|
47
|
+
|
|
48
|
+
# 兼容工具
|
|
49
|
+
compatible_with:
|
|
50
|
+
- claude-code
|
|
51
|
+
- cursor
|
|
52
|
+
- github-copilot
|
|
53
|
+
- windsurf
|
|
54
|
+
|
|
55
|
+
# 灵感来源
|
|
56
|
+
inspired_by: "https://supabase.com/blog/postgres-best-practices-for-ai-agents"
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
name: skill-creator
|
|
2
|
+
version: 1.0.0
|
|
3
|
+
author: "@sumulige"
|
|
4
|
+
description: |
|
|
5
|
+
Guide for creating effective skills that extend Claude's capabilities.
|
|
6
|
+
Use when users want to create a new skill or update an existing skill
|
|
7
|
+
with specialized knowledge, workflows, or tool integrations.
|
|
8
|
+
|
|
9
|
+
tags:
|
|
10
|
+
- skills
|
|
11
|
+
- development
|
|
12
|
+
- workflow
|
|
13
|
+
- meta
|
|
14
|
+
- tooling
|
|
15
|
+
|
|
16
|
+
triggers:
|
|
17
|
+
- create skill
|
|
18
|
+
- new skill
|
|
19
|
+
- update skill
|
|
20
|
+
- skill development
|
|
21
|
+
- extend capabilities
|
|
22
|
+
|
|
23
|
+
dependencies: []
|
|
24
|
+
|
|
25
|
+
difficulty: intermediate
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
name: slack-gif-creator
|
|
2
|
+
version: 1.0.0
|
|
3
|
+
author: "@sumulige"
|
|
4
|
+
description: |
|
|
5
|
+
Knowledge and utilities for creating animated GIFs optimized for Slack.
|
|
6
|
+
Provides constraints, validation tools, and animation concepts.
|
|
7
|
+
Use when users request animated GIFs for Slack like "make me a GIF of X doing Y".
|
|
8
|
+
|
|
9
|
+
tags:
|
|
10
|
+
- gif
|
|
11
|
+
- animation
|
|
12
|
+
- slack
|
|
13
|
+
- image
|
|
14
|
+
- creative
|
|
15
|
+
|
|
16
|
+
triggers:
|
|
17
|
+
- Slack GIF
|
|
18
|
+
- animated GIF
|
|
19
|
+
- emoji GIF
|
|
20
|
+
- create GIF
|
|
21
|
+
- GIF animation
|
|
22
|
+
|
|
23
|
+
dependencies:
|
|
24
|
+
- pillow
|
|
25
|
+
- imageio
|
|
26
|
+
- numpy
|
|
27
|
+
|
|
28
|
+
difficulty: intermediate
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
# Test Skill Name
|
|
2
|
+
|
|
3
|
+
> 简短描述这个技能的作用(一句话)
|
|
4
|
+
|
|
5
|
+
**版本**: 1.0.0
|
|
6
|
+
**作者**: @username
|
|
7
|
+
**标签**: [category1, category2]
|
|
8
|
+
**难度**: 初级/中级/高级
|
|
9
|
+
|
|
10
|
+
---
|
|
11
|
+
|
|
12
|
+
## 概述
|
|
13
|
+
|
|
14
|
+
详细描述这个技能的功能和用途。
|
|
15
|
+
|
|
16
|
+
## 适用场景
|
|
17
|
+
|
|
18
|
+
- 场景 1
|
|
19
|
+
- 场景 2
|
|
20
|
+
- 场景 3
|
|
21
|
+
|
|
22
|
+
## 触发关键词
|
|
23
|
+
|
|
24
|
+
```
|
|
25
|
+
keyword1, keyword2, "exact phrase"
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
## 使用方法
|
|
29
|
+
|
|
30
|
+
### 基础用法
|
|
31
|
+
|
|
32
|
+
```bash
|
|
33
|
+
# 示例命令
|
|
34
|
+
your-command-here
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
### 高级用法
|
|
38
|
+
|
|
39
|
+
```yaml
|
|
40
|
+
# 配置示例
|
|
41
|
+
key: value
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
## 输出格式
|
|
45
|
+
|
|
46
|
+
描述这个技能的输出结果格式。
|
|
47
|
+
|
|
48
|
+
## 注意事项
|
|
49
|
+
|
|
50
|
+
- 注意事项 1
|
|
51
|
+
- 注意事项 2
|
|
52
|
+
|
|
53
|
+
## 相关技能
|
|
54
|
+
|
|
55
|
+
- [related-skill](../related-skill/)
|
|
56
|
+
- [another-skill](../another-skill/)
|
|
57
|
+
|
|
58
|
+
## 更新日志
|
|
59
|
+
|
|
60
|
+
### 1.0.0 (YYYY-MM-DD)
|
|
61
|
+
- 初始版本
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
# Skill Metadata
|
|
2
|
+
# 这个文件定义技能的基本信息,用于自动发现和索引
|
|
3
|
+
|
|
4
|
+
name: test-skill-name
|
|
5
|
+
version: 1.0.0
|
|
6
|
+
author: @username
|
|
7
|
+
description: 简短描述技能功能
|
|
8
|
+
|
|
9
|
+
tags:
|
|
10
|
+
- category1
|
|
11
|
+
- category2
|
|
12
|
+
|
|
13
|
+
triggers:
|
|
14
|
+
- keyword1
|
|
15
|
+
- keyword2
|
|
16
|
+
- "exact phrase"
|
|
17
|
+
|
|
18
|
+
dependencies: [] # 依赖的其他技能
|
|
19
|
+
|
|
20
|
+
difficulty: beginner # beginner | intermediate | advanced
|
|
21
|
+
|
|
22
|
+
# 模板文件
|
|
23
|
+
templates:
|
|
24
|
+
- name: default
|
|
25
|
+
file: templates/default.md
|
|
26
|
+
|
|
27
|
+
# 示例文件
|
|
28
|
+
examples:
|
|
29
|
+
- name: basic
|
|
30
|
+
file: examples/basic.md
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
name: test-workflow
|
|
2
|
+
version: 1.0.0
|
|
3
|
+
author: "@sumulige"
|
|
4
|
+
description: |
|
|
5
|
+
Automated testing workflow that combines Playwright testing, Slack GIF recording,
|
|
6
|
+
and test report generation. Use when user mentions testing, QA workflows, or Playwright.
|
|
7
|
+
Automatically generates test execution, Slack-optimized GIF, screenshots, and Markdown report.
|
|
8
|
+
|
|
9
|
+
tags:
|
|
10
|
+
- testing
|
|
11
|
+
- automation
|
|
12
|
+
- playwright
|
|
13
|
+
- gif
|
|
14
|
+
- report
|
|
15
|
+
|
|
16
|
+
triggers:
|
|
17
|
+
- test
|
|
18
|
+
- Playwright
|
|
19
|
+
- QA workflow
|
|
20
|
+
- automated testing
|
|
21
|
+
- test report
|
|
22
|
+
|
|
23
|
+
dependencies:
|
|
24
|
+
- playwright
|
|
25
|
+
- pillow
|
|
26
|
+
|
|
27
|
+
difficulty: intermediate
|
|
28
|
+
|
|
29
|
+
see_also:
|
|
30
|
+
- webapp-testing
|
|
31
|
+
- slack-gif-creator
|
|
32
|
+
- doc-coauthoring
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
name: theme-factory
|
|
2
|
+
version: 1.0.0
|
|
3
|
+
author: "@sumulige"
|
|
4
|
+
description: |
|
|
5
|
+
Toolkit for styling artifacts with a theme. Supports slides, docs, reportings,
|
|
6
|
+
HTML landing pages, etc. Includes 10 pre-set themes with colors/fonts that can
|
|
7
|
+
be applied to any artifact, or generate a new theme on-the-fly.
|
|
8
|
+
|
|
9
|
+
tags:
|
|
10
|
+
- theme
|
|
11
|
+
- styling
|
|
12
|
+
- design
|
|
13
|
+
- colors
|
|
14
|
+
- fonts
|
|
15
|
+
- presentation
|
|
16
|
+
|
|
17
|
+
triggers:
|
|
18
|
+
- apply theme
|
|
19
|
+
- theme styling
|
|
20
|
+
- color palette
|
|
21
|
+
- font pairing
|
|
22
|
+
- presentation theme
|
|
23
|
+
|
|
24
|
+
dependencies: []
|
|
25
|
+
|
|
26
|
+
difficulty: beginner
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
name: threejs-fundamentals
|
|
2
|
+
version: 1.0.0
|
|
3
|
+
author: "@sumulige"
|
|
4
|
+
description: |
|
|
5
|
+
Three.js scene setup, cameras, renderer, Object3D hierarchy, coordinate systems.
|
|
6
|
+
Use when setting up 3D scenes, creating cameras, configuring renderers,
|
|
7
|
+
managing object hierarchies, or working with transforms.
|
|
8
|
+
|
|
9
|
+
tags:
|
|
10
|
+
- threejs
|
|
11
|
+
- 3d
|
|
12
|
+
- webgl
|
|
13
|
+
- graphics
|
|
14
|
+
- visualization
|
|
15
|
+
|
|
16
|
+
triggers:
|
|
17
|
+
- Three.js
|
|
18
|
+
- 3D scene
|
|
19
|
+
- WebGL
|
|
20
|
+
- 3D graphics
|
|
21
|
+
- camera setup
|
|
22
|
+
- 3D rendering
|
|
23
|
+
|
|
24
|
+
dependencies:
|
|
25
|
+
- three.js
|
|
26
|
+
|
|
27
|
+
difficulty: intermediate
|