universal-dev-standards 3.0.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.
- package/LICENSE +21 -0
- package/README.md +248 -0
- package/bin/uds.js +56 -0
- package/package.json +63 -0
- package/src/commands/check.js +149 -0
- package/src/commands/configure.js +221 -0
- package/src/commands/init.js +665 -0
- package/src/commands/list.js +100 -0
- package/src/commands/update.js +186 -0
- package/src/index.js +7 -0
- package/src/prompts/init.js +702 -0
- package/src/prompts/integrations.js +453 -0
- package/src/utils/copier.js +143 -0
- package/src/utils/detector.js +159 -0
- package/src/utils/github.js +508 -0
- package/src/utils/integration-generator.js +1694 -0
- package/src/utils/registry.js +207 -0
- package/standards-registry.json +658 -0
|
@@ -0,0 +1,1694 @@
|
|
|
1
|
+
import { existsSync, readFileSync, writeFileSync, mkdirSync } from 'fs';
|
|
2
|
+
import { dirname, join } from 'path';
|
|
3
|
+
import { getLanguageRules } from '../prompts/integrations.js';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Rule templates for different categories
|
|
7
|
+
*/
|
|
8
|
+
const RULE_TEMPLATES = {
|
|
9
|
+
'spec-driven-development': {
|
|
10
|
+
minimal: {
|
|
11
|
+
en: `## Spec-Driven Development (SDD) Priority
|
|
12
|
+
- When SDD tools (OpenSpec, Spec Kit) are installed, use their slash commands first
|
|
13
|
+
- Commands like \`/openspec\` or \`/spec\` take priority over manual file editing`,
|
|
14
|
+
'zh-tw': `## 規格驅動開發 (SDD) 優先
|
|
15
|
+
- 當 SDD 工具(OpenSpec、Spec Kit)已安裝時,優先使用其斜線命令
|
|
16
|
+
- \`/openspec\` 或 \`/spec\` 等命令優先於手動編輯檔案`
|
|
17
|
+
},
|
|
18
|
+
standard: {
|
|
19
|
+
en: `## Spec-Driven Development (SDD) Priority
|
|
20
|
+
Reference: .standards/spec-driven-development.md
|
|
21
|
+
|
|
22
|
+
**Rule**: When an SDD tool (such as OpenSpec, Spec Kit, etc.) is integrated in this project and provides specific commands (e.g., slash commands like \`/openspec\` or \`/spec\`), you MUST prioritize using these commands over manual file editing.
|
|
23
|
+
|
|
24
|
+
**Detection**:
|
|
25
|
+
- OpenSpec: Check for \`openspec/\` directory or \`openspec.json\`
|
|
26
|
+
- Spec Kit: Check for \`specs/\` directory or \`.speckit\` configuration
|
|
27
|
+
|
|
28
|
+
**Rationale**:
|
|
29
|
+
- **Consistency**: Tools ensure spec structure follows strict schemas
|
|
30
|
+
- **Traceability**: Commands handle logging, IDs, and linking automatically
|
|
31
|
+
- **Safety**: Tools have built-in validation preventing invalid states`,
|
|
32
|
+
'zh-tw': `## 規格驅動開發 (SDD) 優先
|
|
33
|
+
參考: .standards/spec-driven-development.md
|
|
34
|
+
|
|
35
|
+
**規則**:當專案整合了 SDD 工具(如 OpenSpec、Spec Kit 等)並提供特定命令(如 \`/openspec\` 或 \`/spec\` 斜線命令)時,你必須優先使用這些命令,而非手動編輯檔案。
|
|
36
|
+
|
|
37
|
+
**偵測方式**:
|
|
38
|
+
- OpenSpec: 檢查 \`openspec/\` 目錄或 \`openspec.json\`
|
|
39
|
+
- Spec Kit: 檢查 \`specs/\` 目錄或 \`.speckit\` 設定
|
|
40
|
+
|
|
41
|
+
**原因**:
|
|
42
|
+
- **一致性**: 工具確保規格結構遵循嚴格的 schema
|
|
43
|
+
- **可追蹤性**: 命令自動處理日誌、ID 和連結
|
|
44
|
+
- **安全性**: 工具有內建驗證防止無效狀態`
|
|
45
|
+
},
|
|
46
|
+
comprehensive: {
|
|
47
|
+
en: `## Spec-Driven Development (SDD) Priority
|
|
48
|
+
Reference: .standards/spec-driven-development.md
|
|
49
|
+
|
|
50
|
+
### Core Principle
|
|
51
|
+
When an SDD tool (such as OpenSpec, Spec Kit, etc.) is integrated in this project and provides specific commands (e.g., slash commands like \`/openspec\` or \`/spec\`), you MUST prioritize using these commands over manual file editing.
|
|
52
|
+
|
|
53
|
+
### SDD Tool Detection
|
|
54
|
+
Before making changes that require specifications, check if SDD tools are present:
|
|
55
|
+
|
|
56
|
+
| Tool | Detection Method | Primary Command |
|
|
57
|
+
|------|------------------|-----------------|
|
|
58
|
+
| OpenSpec | \`openspec/\` directory or \`openspec.json\` | \`/openspec proposal\` |
|
|
59
|
+
| Spec Kit | \`specs/\` directory or \`.speckit\` config | \`/spec create\` |
|
|
60
|
+
|
|
61
|
+
### Why Prioritize SDD Commands
|
|
62
|
+
1. **Consistency**: Tools ensure spec structure follows strict schemas
|
|
63
|
+
2. **Traceability**: Commands handle logging, IDs, and linking automatically
|
|
64
|
+
3. **Safety**: Tools have built-in validation preventing invalid states
|
|
65
|
+
4. **Workflow Integration**: Commands integrate with approval and review workflows
|
|
66
|
+
|
|
67
|
+
### SDD Workflow
|
|
68
|
+
\`\`\`
|
|
69
|
+
Proposal → Review → Implementation → Verification → Archive
|
|
70
|
+
\`\`\`
|
|
71
|
+
|
|
72
|
+
### Command Priority Examples
|
|
73
|
+
- ✅ Use \`/openspec proposal "Add Login"\` instead of manually creating \`changes/add-login/proposal.md\`
|
|
74
|
+
- ✅ Use \`/spec create "New Feature"\` instead of manually creating \`specs/SPEC-XXX.md\`
|
|
75
|
+
|
|
76
|
+
### Exceptions
|
|
77
|
+
SDD commands may be skipped for:
|
|
78
|
+
- Critical hotfixes (restore service immediately, document later)
|
|
79
|
+
- Trivial changes (typos, comments, formatting)
|
|
80
|
+
- Bug fixes (restore intended behavior)`,
|
|
81
|
+
'zh-tw': `## 規格驅動開發 (SDD) 優先
|
|
82
|
+
參考: .standards/spec-driven-development.md
|
|
83
|
+
|
|
84
|
+
### 核心原則
|
|
85
|
+
當專案整合了 SDD 工具(如 OpenSpec、Spec Kit 等)並提供特定命令(如 \`/openspec\` 或 \`/spec\` 斜線命令)時,你必須優先使用這些命令,而非手動編輯檔案。
|
|
86
|
+
|
|
87
|
+
### SDD 工具偵測
|
|
88
|
+
在進行需要規格的變更前,檢查是否有 SDD 工具:
|
|
89
|
+
|
|
90
|
+
| 工具 | 偵測方式 | 主要命令 |
|
|
91
|
+
|------|----------|----------|
|
|
92
|
+
| OpenSpec | \`openspec/\` 目錄或 \`openspec.json\` | \`/openspec proposal\` |
|
|
93
|
+
| Spec Kit | \`specs/\` 目錄或 \`.speckit\` 設定 | \`/spec create\` |
|
|
94
|
+
|
|
95
|
+
### 為何優先使用 SDD 命令
|
|
96
|
+
1. **一致性**: 工具確保規格結構遵循嚴格的 schema
|
|
97
|
+
2. **可追蹤性**: 命令自動處理日誌、ID 和連結
|
|
98
|
+
3. **安全性**: 工具有內建驗證防止無效狀態
|
|
99
|
+
4. **工作流程整合**: 命令與審核和審查流程整合
|
|
100
|
+
|
|
101
|
+
### SDD 工作流程
|
|
102
|
+
\`\`\`
|
|
103
|
+
提案 → 審查 → 實作 → 驗證 → 歸檔
|
|
104
|
+
\`\`\`
|
|
105
|
+
|
|
106
|
+
### 命令優先範例
|
|
107
|
+
- ✅ 使用 \`/openspec proposal "新增登入"\` 而非手動建立 \`changes/add-login/proposal.md\`
|
|
108
|
+
- ✅ 使用 \`/spec create "新功能"\` 而非手動建立 \`specs/SPEC-XXX.md\`
|
|
109
|
+
|
|
110
|
+
### 例外情況
|
|
111
|
+
以下情況可跳過 SDD 命令:
|
|
112
|
+
- 緊急修復(立即恢復服務,稍後記錄)
|
|
113
|
+
- 微小變更(錯字、註解、格式)
|
|
114
|
+
- 錯誤修復(恢復預期行為)`
|
|
115
|
+
}
|
|
116
|
+
},
|
|
117
|
+
|
|
118
|
+
'anti-hallucination': {
|
|
119
|
+
minimal: {
|
|
120
|
+
en: `## Anti-Hallucination Protocol
|
|
121
|
+
- Read files before analyzing them
|
|
122
|
+
- Cite sources: [Source: Code] path/file:line
|
|
123
|
+
- Use certainty tags: [Confirmed], [Inferred], [Assumption], [Unknown]
|
|
124
|
+
- Always provide a recommended option when presenting choices`,
|
|
125
|
+
'zh-tw': `## 反幻覺協議
|
|
126
|
+
- 分析前必須先讀取檔案
|
|
127
|
+
- 引用來源: [Source: Code] path/file:line
|
|
128
|
+
- 使用確定性標籤: [確認], [推斷], [假設], [未知]
|
|
129
|
+
- 提供選項時務必標明建議選項`
|
|
130
|
+
},
|
|
131
|
+
standard: {
|
|
132
|
+
en: `## Anti-Hallucination Protocol
|
|
133
|
+
Reference: .standards/anti-hallucination.md
|
|
134
|
+
|
|
135
|
+
### Evidence-Based Analysis
|
|
136
|
+
1. **File Reading**: You must read files before analyzing them.
|
|
137
|
+
2. **No Guessing**: Do not guess APIs, class names, or library versions.
|
|
138
|
+
3. **Explicit Uncertainty**: If you haven't seen the code, state "I need to read [file] to confirm".
|
|
139
|
+
|
|
140
|
+
### Source Attribution
|
|
141
|
+
- Every factual claim about the code must cite sources.
|
|
142
|
+
- Format: \`[Source: Code] path/to/file:line\`
|
|
143
|
+
- External docs: \`[Source: External] http://url (Accessed: Date)\`
|
|
144
|
+
|
|
145
|
+
### Certainty Classification
|
|
146
|
+
Use tags to indicate confidence:
|
|
147
|
+
- \`[Confirmed]\` - Verified from code/docs
|
|
148
|
+
- \`[Inferred]\` - Logical deduction from evidence
|
|
149
|
+
- \`[Assumption]\` - Reasonable guess, needs verification
|
|
150
|
+
- \`[Unknown]\` - Cannot determine
|
|
151
|
+
|
|
152
|
+
### Recommendations
|
|
153
|
+
When presenting options, YOU MUST explicitly state a "Recommended" choice with reasoning.`,
|
|
154
|
+
'zh-tw': `## 反幻覺協議
|
|
155
|
+
參考: .standards/anti-hallucination.md
|
|
156
|
+
|
|
157
|
+
### 實證分析
|
|
158
|
+
1. **讀取檔案**: 分析前必須先讀取檔案
|
|
159
|
+
2. **禁止猜測**: 不得猜測 API、類別名稱或函式庫版本
|
|
160
|
+
3. **明確不確定性**: 若未看過程式碼,需說明「我需要讀取 [檔案] 來確認」
|
|
161
|
+
|
|
162
|
+
### 來源標註
|
|
163
|
+
- 關於程式碼的每項事實陳述必須引用來源
|
|
164
|
+
- 格式: \`[Source: Code] path/to/file:line\`
|
|
165
|
+
- 外部文件: \`[Source: External] http://url (存取日期: Date)\`
|
|
166
|
+
|
|
167
|
+
### 確定性分類
|
|
168
|
+
使用標籤表示信心程度:
|
|
169
|
+
- \`[確認]\` - 已從程式碼/文件驗證
|
|
170
|
+
- \`[推斷]\` - 從證據邏輯推導
|
|
171
|
+
- \`[假設]\` - 合理猜測,需驗證
|
|
172
|
+
- \`[未知]\` - 無法確定
|
|
173
|
+
|
|
174
|
+
### 建議
|
|
175
|
+
提供選項時,必須明確標明「建議」選項並說明理由。`
|
|
176
|
+
},
|
|
177
|
+
comprehensive: {
|
|
178
|
+
en: `## Anti-Hallucination Protocol
|
|
179
|
+
Reference: .standards/anti-hallucination.md
|
|
180
|
+
|
|
181
|
+
### Core Principle
|
|
182
|
+
You are an AI assistant that prioritizes accuracy over confidence. Never fabricate information.
|
|
183
|
+
|
|
184
|
+
### Evidence-Based Analysis
|
|
185
|
+
1. **File Reading Requirement**
|
|
186
|
+
- You MUST read files before analyzing them
|
|
187
|
+
- Do not guess APIs, class names, or library versions
|
|
188
|
+
- If you haven't seen the code, state "I need to read [file] to confirm"
|
|
189
|
+
- When referencing files, use exact paths from the project
|
|
190
|
+
|
|
191
|
+
2. **Source Attribution Requirements**
|
|
192
|
+
- Every factual claim about the code must cite sources
|
|
193
|
+
- Code references: \`[Source: Code] path/to/file:line\`
|
|
194
|
+
- External documentation: \`[Source: External] http://url (Accessed: Date)\`
|
|
195
|
+
- Multiple sources: List all relevant sources
|
|
196
|
+
|
|
197
|
+
3. **Certainty Classification System**
|
|
198
|
+
Use these tags to indicate confidence level:
|
|
199
|
+
|
|
200
|
+
| Tag | Meaning | When to Use |
|
|
201
|
+
|-----|---------|-------------|
|
|
202
|
+
| \`[Confirmed]\` | Verified from code/docs | Direct evidence exists |
|
|
203
|
+
| \`[Inferred]\` | Logical deduction | Evidence supports conclusion |
|
|
204
|
+
| \`[Assumption]\` | Reasonable guess | Needs verification |
|
|
205
|
+
| \`[Unknown]\` | Cannot determine | Insufficient information |
|
|
206
|
+
|
|
207
|
+
4. **Recommendation Protocol**
|
|
208
|
+
When presenting options:
|
|
209
|
+
- ALWAYS identify a "Recommended" choice
|
|
210
|
+
- Explain the reasoning for the recommendation
|
|
211
|
+
- List trade-offs of alternatives
|
|
212
|
+
- Consider project context and constraints
|
|
213
|
+
|
|
214
|
+
### Error Correction
|
|
215
|
+
If you realize you made an incorrect statement:
|
|
216
|
+
1. Immediately acknowledge the error
|
|
217
|
+
2. Provide the corrected information with sources
|
|
218
|
+
3. Explain what led to the initial mistake`,
|
|
219
|
+
'zh-tw': `## 反幻覺協議
|
|
220
|
+
參考: .standards/anti-hallucination.md
|
|
221
|
+
|
|
222
|
+
### 核心原則
|
|
223
|
+
您是一個優先重視準確性而非自信的 AI 助手。絕不捏造資訊。
|
|
224
|
+
|
|
225
|
+
### 實證分析
|
|
226
|
+
1. **讀取檔案要求**
|
|
227
|
+
- 分析前必須先讀取檔案
|
|
228
|
+
- 不得猜測 API、類別名稱或函式庫版本
|
|
229
|
+
- 若未看過程式碼,需說明「我需要讀取 [檔案] 來確認」
|
|
230
|
+
- 引用檔案時使用專案中的確切路徑
|
|
231
|
+
|
|
232
|
+
2. **來源標註要求**
|
|
233
|
+
- 關於程式碼的每項事實陳述必須引用來源
|
|
234
|
+
- 程式碼引用: \`[Source: Code] path/to/file:line\`
|
|
235
|
+
- 外部文件: \`[Source: External] http://url (存取日期: Date)\`
|
|
236
|
+
- 多個來源: 列出所有相關來源
|
|
237
|
+
|
|
238
|
+
3. **確定性分類系統**
|
|
239
|
+
使用這些標籤表示信心程度:
|
|
240
|
+
|
|
241
|
+
| 標籤 | 意義 | 使用時機 |
|
|
242
|
+
|------|------|----------|
|
|
243
|
+
| \`[確認]\` | 已從程式碼/文件驗證 | 有直接證據 |
|
|
244
|
+
| \`[推斷]\` | 邏輯推導 | 證據支持結論 |
|
|
245
|
+
| \`[假設]\` | 合理猜測 | 需要驗證 |
|
|
246
|
+
| \`[未知]\` | 無法確定 | 資訊不足 |
|
|
247
|
+
|
|
248
|
+
4. **建議協議**
|
|
249
|
+
提供選項時:
|
|
250
|
+
- 務必標明「建議」選項
|
|
251
|
+
- 解釋建議的理由
|
|
252
|
+
- 列出替代方案的利弊
|
|
253
|
+
- 考慮專案背景和限制
|
|
254
|
+
|
|
255
|
+
### 錯誤更正
|
|
256
|
+
如果發現自己做出錯誤陳述:
|
|
257
|
+
1. 立即承認錯誤
|
|
258
|
+
2. 提供附帶來源的更正資訊
|
|
259
|
+
3. 解釋導致初始錯誤的原因`
|
|
260
|
+
}
|
|
261
|
+
},
|
|
262
|
+
|
|
263
|
+
'commit-standards': {
|
|
264
|
+
minimal: {
|
|
265
|
+
en: `## Commit Standards
|
|
266
|
+
- Format: \`<type>(<scope>): <subject>\`
|
|
267
|
+
- Types: feat, fix, docs, style, refactor, test, chore
|
|
268
|
+
- Keep subject under 72 characters`,
|
|
269
|
+
'zh-tw': `## 提交標準
|
|
270
|
+
- 格式: \`<type>(<scope>): <subject>\`
|
|
271
|
+
- 類型: feat, fix, docs, style, refactor, test, chore
|
|
272
|
+
- 主題保持在 72 字元內`
|
|
273
|
+
},
|
|
274
|
+
standard: {
|
|
275
|
+
en: `## Commit Message Standards
|
|
276
|
+
Reference: .standards/commit-message-guide.md
|
|
277
|
+
|
|
278
|
+
### Format
|
|
279
|
+
\`\`\`
|
|
280
|
+
<type>(<scope>): <subject>
|
|
281
|
+
|
|
282
|
+
<body>
|
|
283
|
+
|
|
284
|
+
<footer>
|
|
285
|
+
\`\`\`
|
|
286
|
+
|
|
287
|
+
### Types
|
|
288
|
+
- \`feat\`: New feature
|
|
289
|
+
- \`fix\`: Bug fix
|
|
290
|
+
- \`docs\`: Documentation only
|
|
291
|
+
- \`style\`: Formatting (no code change)
|
|
292
|
+
- \`refactor\`: Code restructuring
|
|
293
|
+
- \`test\`: Adding/updating tests
|
|
294
|
+
- \`chore\`: Maintenance tasks
|
|
295
|
+
|
|
296
|
+
### Rules
|
|
297
|
+
- Subject line: max 72 characters
|
|
298
|
+
- Use imperative mood: "add" not "added"
|
|
299
|
+
- Body: explain what and why, not how`,
|
|
300
|
+
'zh-tw': `## 提交訊息標準
|
|
301
|
+
參考: .standards/commit-message-guide.md
|
|
302
|
+
|
|
303
|
+
### 格式
|
|
304
|
+
\`\`\`
|
|
305
|
+
<type>(<scope>): <subject>
|
|
306
|
+
|
|
307
|
+
<body>
|
|
308
|
+
|
|
309
|
+
<footer>
|
|
310
|
+
\`\`\`
|
|
311
|
+
|
|
312
|
+
### 類型
|
|
313
|
+
- \`feat\`: 新功能
|
|
314
|
+
- \`fix\`: 錯誤修復
|
|
315
|
+
- \`docs\`: 僅文件更新
|
|
316
|
+
- \`style\`: 格式調整(無程式碼變更)
|
|
317
|
+
- \`refactor\`: 程式碼重構
|
|
318
|
+
- \`test\`: 新增/更新測試
|
|
319
|
+
- \`chore\`: 維護任務
|
|
320
|
+
|
|
321
|
+
### 規則
|
|
322
|
+
- 主題行: 最多 72 字元
|
|
323
|
+
- 使用祈使語氣: 「add」而非「added」
|
|
324
|
+
- 本文: 說明做了什麼及為什麼,而非如何做`
|
|
325
|
+
},
|
|
326
|
+
comprehensive: {
|
|
327
|
+
en: `## Commit Message Standards
|
|
328
|
+
Reference: .standards/commit-message-guide.md
|
|
329
|
+
|
|
330
|
+
### Format Structure
|
|
331
|
+
\`\`\`
|
|
332
|
+
<type>(<scope>): <subject>
|
|
333
|
+
|
|
334
|
+
<body>
|
|
335
|
+
|
|
336
|
+
<footer>
|
|
337
|
+
\`\`\`
|
|
338
|
+
|
|
339
|
+
### Commit Types
|
|
340
|
+
| Type | Description | Example |
|
|
341
|
+
|------|-------------|---------|
|
|
342
|
+
| \`feat\` | New feature | feat(auth): add OAuth2 login |
|
|
343
|
+
| \`fix\` | Bug fix | fix(api): handle null response |
|
|
344
|
+
| \`docs\` | Documentation | docs(readme): update setup guide |
|
|
345
|
+
| \`style\` | Formatting | style(lint): fix indentation |
|
|
346
|
+
| \`refactor\` | Code restructure | refactor(user): extract validation |
|
|
347
|
+
| \`test\` | Tests | test(cart): add checkout tests |
|
|
348
|
+
| \`chore\` | Maintenance | chore(deps): update packages |
|
|
349
|
+
| \`perf\` | Performance | perf(query): optimize database |
|
|
350
|
+
| \`ci\` | CI/CD changes | ci(github): add deploy workflow |
|
|
351
|
+
|
|
352
|
+
### Subject Line Rules
|
|
353
|
+
- Maximum 72 characters
|
|
354
|
+
- Use imperative mood: "add" not "added"
|
|
355
|
+
- No period at the end
|
|
356
|
+
- Capitalize first letter
|
|
357
|
+
|
|
358
|
+
### Body Guidelines
|
|
359
|
+
- Wrap at 72 characters
|
|
360
|
+
- Explain WHAT and WHY, not HOW
|
|
361
|
+
- Separate from subject with blank line
|
|
362
|
+
|
|
363
|
+
### Footer Format
|
|
364
|
+
- Breaking changes: \`BREAKING CHANGE: description\`
|
|
365
|
+
- Issue references: \`Fixes #123\`, \`Closes #456\`
|
|
366
|
+
- Co-authors: \`Co-authored-by: Name <email>\``,
|
|
367
|
+
'zh-tw': `## 提交訊息標準
|
|
368
|
+
參考: .standards/commit-message-guide.md
|
|
369
|
+
|
|
370
|
+
### 格式結構
|
|
371
|
+
\`\`\`
|
|
372
|
+
<type>(<scope>): <subject>
|
|
373
|
+
|
|
374
|
+
<body>
|
|
375
|
+
|
|
376
|
+
<footer>
|
|
377
|
+
\`\`\`
|
|
378
|
+
|
|
379
|
+
### 提交類型
|
|
380
|
+
| 類型 | 說明 | 範例 |
|
|
381
|
+
|------|------|------|
|
|
382
|
+
| \`feat\` | 新功能 | feat(auth): 新增 OAuth2 登入 |
|
|
383
|
+
| \`fix\` | 錯誤修復 | fix(api): 處理空值回應 |
|
|
384
|
+
| \`docs\` | 文件更新 | docs(readme): 更新安裝指南 |
|
|
385
|
+
| \`style\` | 格式調整 | style(lint): 修正縮排 |
|
|
386
|
+
| \`refactor\` | 程式碼重構 | refactor(user): 抽取驗證邏輯 |
|
|
387
|
+
| \`test\` | 測試相關 | test(cart): 新增結帳測試 |
|
|
388
|
+
| \`chore\` | 維護任務 | chore(deps): 更新套件 |
|
|
389
|
+
| \`perf\` | 效能改善 | perf(query): 優化資料庫查詢 |
|
|
390
|
+
| \`ci\` | CI/CD 變更 | ci(github): 新增部署流程 |
|
|
391
|
+
|
|
392
|
+
### 主題行規則
|
|
393
|
+
- 最多 72 字元
|
|
394
|
+
- 使用祈使語氣: 「add」而非「added」
|
|
395
|
+
- 結尾不加句點
|
|
396
|
+
- 首字母大寫
|
|
397
|
+
|
|
398
|
+
### 本文指引
|
|
399
|
+
- 每行 72 字元換行
|
|
400
|
+
- 說明做了什麼及為什麼,而非如何做
|
|
401
|
+
- 與主題以空行分隔
|
|
402
|
+
|
|
403
|
+
### 頁腳格式
|
|
404
|
+
- 破壞性變更: \`BREAKING CHANGE: 說明\`
|
|
405
|
+
- Issue 引用: \`Fixes #123\`, \`Closes #456\`
|
|
406
|
+
- 共同作者: \`Co-authored-by: Name <email>\``
|
|
407
|
+
}
|
|
408
|
+
},
|
|
409
|
+
|
|
410
|
+
'code-review': {
|
|
411
|
+
minimal: {
|
|
412
|
+
en: `## Code Review Checklist
|
|
413
|
+
Before committing, verify:
|
|
414
|
+
- [ ] Code compiles without errors
|
|
415
|
+
- [ ] All tests pass
|
|
416
|
+
- [ ] No hardcoded secrets
|
|
417
|
+
- [ ] Changes are focused and complete`,
|
|
418
|
+
'zh-tw': `## 程式碼審查清單
|
|
419
|
+
提交前確認:
|
|
420
|
+
- [ ] 程式碼編譯無錯誤
|
|
421
|
+
- [ ] 所有測試通過
|
|
422
|
+
- [ ] 無寫死的密鑰
|
|
423
|
+
- [ ] 變更專注且完整`
|
|
424
|
+
},
|
|
425
|
+
standard: {
|
|
426
|
+
en: `## Code Review Checklist
|
|
427
|
+
Reference: .standards/checkin-standards.md
|
|
428
|
+
|
|
429
|
+
### Before Every Commit
|
|
430
|
+
1. **Build Verification**
|
|
431
|
+
- [ ] Code compiles successfully
|
|
432
|
+
- [ ] All dependencies satisfied
|
|
433
|
+
|
|
434
|
+
2. **Test Verification**
|
|
435
|
+
- [ ] All existing tests pass
|
|
436
|
+
- [ ] New code has tests
|
|
437
|
+
- [ ] Test coverage not decreased
|
|
438
|
+
|
|
439
|
+
3. **Code Quality**
|
|
440
|
+
- [ ] Follows coding standards
|
|
441
|
+
- [ ] No hardcoded secrets
|
|
442
|
+
- [ ] No security vulnerabilities
|
|
443
|
+
|
|
444
|
+
4. **Documentation**
|
|
445
|
+
- [ ] API docs updated (if applicable)
|
|
446
|
+
- [ ] CHANGELOG updated for user-facing changes
|
|
447
|
+
|
|
448
|
+
### Never Commit When
|
|
449
|
+
- Build has errors
|
|
450
|
+
- Tests are failing
|
|
451
|
+
- Contains debugging code (console.log, etc.)`,
|
|
452
|
+
'zh-tw': `## 程式碼審查清單
|
|
453
|
+
參考: .standards/checkin-standards.md
|
|
454
|
+
|
|
455
|
+
### 每次提交前
|
|
456
|
+
1. **建置驗證**
|
|
457
|
+
- [ ] 程式碼編譯成功
|
|
458
|
+
- [ ] 所有相依套件已滿足
|
|
459
|
+
|
|
460
|
+
2. **測試驗證**
|
|
461
|
+
- [ ] 所有現有測試通過
|
|
462
|
+
- [ ] 新程式碼有對應測試
|
|
463
|
+
- [ ] 測試覆蓋率未下降
|
|
464
|
+
|
|
465
|
+
3. **程式碼品質**
|
|
466
|
+
- [ ] 遵循編碼標準
|
|
467
|
+
- [ ] 無寫死的密鑰
|
|
468
|
+
- [ ] 無安全漏洞
|
|
469
|
+
|
|
470
|
+
4. **文件**
|
|
471
|
+
- [ ] API 文件已更新(如適用)
|
|
472
|
+
- [ ] 使用者可見變更已更新 CHANGELOG
|
|
473
|
+
|
|
474
|
+
### 禁止提交情況
|
|
475
|
+
- 建置有錯誤
|
|
476
|
+
- 測試失敗
|
|
477
|
+
- 包含除錯程式碼(console.log 等)`
|
|
478
|
+
},
|
|
479
|
+
comprehensive: {
|
|
480
|
+
en: `## Code Review Checklist
|
|
481
|
+
Reference: .standards/checkin-standards.md
|
|
482
|
+
|
|
483
|
+
### Core Philosophy
|
|
484
|
+
Every commit should:
|
|
485
|
+
- ✅ Be a complete logical unit of work
|
|
486
|
+
- ✅ Leave the codebase in a working state
|
|
487
|
+
- ✅ Be reversible without breaking functionality
|
|
488
|
+
- ✅ Contain its own tests (for new features)
|
|
489
|
+
|
|
490
|
+
### Mandatory Verification Checklist
|
|
491
|
+
|
|
492
|
+
#### 1. Build Verification
|
|
493
|
+
- [ ] Code compiles successfully (zero errors)
|
|
494
|
+
- [ ] All dependencies satisfied
|
|
495
|
+
- [ ] No new compiler warnings introduced
|
|
496
|
+
|
|
497
|
+
#### 2. Test Verification
|
|
498
|
+
- [ ] All existing tests pass (100% pass rate)
|
|
499
|
+
- [ ] New code has corresponding tests
|
|
500
|
+
- [ ] Test coverage not decreased
|
|
501
|
+
- [ ] Edge cases considered
|
|
502
|
+
|
|
503
|
+
#### 3. Code Quality
|
|
504
|
+
- [ ] Follows project coding standards
|
|
505
|
+
- [ ] No hardcoded secrets (passwords, API keys)
|
|
506
|
+
- [ ] No security vulnerabilities (OWASP Top 10)
|
|
507
|
+
- [ ] Proper error handling
|
|
508
|
+
- [ ] No duplicate code
|
|
509
|
+
|
|
510
|
+
#### 4. Documentation
|
|
511
|
+
- [ ] API documentation updated (if applicable)
|
|
512
|
+
- [ ] CHANGELOG updated for user-facing changes
|
|
513
|
+
- [ ] Comments for complex logic
|
|
514
|
+
- [ ] README updated if needed
|
|
515
|
+
|
|
516
|
+
#### 5. Workflow Compliance
|
|
517
|
+
- [ ] Branch naming correct
|
|
518
|
+
- [ ] Commit message follows format
|
|
519
|
+
- [ ] Synchronized with target branch
|
|
520
|
+
|
|
521
|
+
### ❌ Never Commit When
|
|
522
|
+
- Build has errors
|
|
523
|
+
- Tests are failing
|
|
524
|
+
- Feature is incomplete and would break functionality
|
|
525
|
+
- Contains WIP/TODO comments for critical logic
|
|
526
|
+
- Contains debugging code
|
|
527
|
+
- Contains commented-out code blocks
|
|
528
|
+
|
|
529
|
+
### Quick Verification Commands
|
|
530
|
+
\`\`\`bash
|
|
531
|
+
npm run lint # Check code style
|
|
532
|
+
npm test # Run all tests
|
|
533
|
+
npm run build # Verify build
|
|
534
|
+
\`\`\``,
|
|
535
|
+
'zh-tw': `## 程式碼審查清單
|
|
536
|
+
參考: .standards/checkin-standards.md
|
|
537
|
+
|
|
538
|
+
### 核心理念
|
|
539
|
+
每次提交應該:
|
|
540
|
+
- ✅ 是完整的邏輯工作單元
|
|
541
|
+
- ✅ 讓程式碼庫保持可運作狀態
|
|
542
|
+
- ✅ 可回滾而不破壞功能
|
|
543
|
+
- ✅ 包含自己的測試(針對新功能)
|
|
544
|
+
|
|
545
|
+
### 強制驗證清單
|
|
546
|
+
|
|
547
|
+
#### 1. 建置驗證
|
|
548
|
+
- [ ] 程式碼編譯成功(零錯誤)
|
|
549
|
+
- [ ] 所有相依套件已滿足
|
|
550
|
+
- [ ] 無新增編譯器警告
|
|
551
|
+
|
|
552
|
+
#### 2. 測試驗證
|
|
553
|
+
- [ ] 所有現有測試通過(100% 通過率)
|
|
554
|
+
- [ ] 新程式碼有對應測試
|
|
555
|
+
- [ ] 測試覆蓋率未下降
|
|
556
|
+
- [ ] 已考慮邊界情況
|
|
557
|
+
|
|
558
|
+
#### 3. 程式碼品質
|
|
559
|
+
- [ ] 遵循專案編碼標準
|
|
560
|
+
- [ ] 無寫死的密鑰(密碼、API 金鑰)
|
|
561
|
+
- [ ] 無安全漏洞(OWASP Top 10)
|
|
562
|
+
- [ ] 適當的錯誤處理
|
|
563
|
+
- [ ] 無重複程式碼
|
|
564
|
+
|
|
565
|
+
#### 4. 文件
|
|
566
|
+
- [ ] API 文件已更新(如適用)
|
|
567
|
+
- [ ] 使用者可見變更已更新 CHANGELOG
|
|
568
|
+
- [ ] 複雜邏輯有註解
|
|
569
|
+
- [ ] 如需要已更新 README
|
|
570
|
+
|
|
571
|
+
#### 5. 工作流程合規
|
|
572
|
+
- [ ] 分支命名正確
|
|
573
|
+
- [ ] 提交訊息遵循格式
|
|
574
|
+
- [ ] 已與目標分支同步
|
|
575
|
+
|
|
576
|
+
### ❌ 禁止提交情況
|
|
577
|
+
- 建置有錯誤
|
|
578
|
+
- 測試失敗
|
|
579
|
+
- 功能不完整且會破壞功能
|
|
580
|
+
- 關鍵邏輯包含 WIP/TODO 註解
|
|
581
|
+
- 包含除錯程式碼
|
|
582
|
+
- 包含被註解的程式碼區塊
|
|
583
|
+
|
|
584
|
+
### 快速驗證指令
|
|
585
|
+
\`\`\`bash
|
|
586
|
+
npm run lint # 檢查程式碼風格
|
|
587
|
+
npm test # 執行所有測試
|
|
588
|
+
npm run build # 驗證建置
|
|
589
|
+
\`\`\``
|
|
590
|
+
}
|
|
591
|
+
},
|
|
592
|
+
|
|
593
|
+
'testing': {
|
|
594
|
+
minimal: {
|
|
595
|
+
en: `## Testing Standards
|
|
596
|
+
- Unit tests: 70% coverage
|
|
597
|
+
- Integration tests: 20%
|
|
598
|
+
- E2E tests: 10%
|
|
599
|
+
- Run tests before committing`,
|
|
600
|
+
'zh-tw': `## 測試標準
|
|
601
|
+
- 單元測試: 70% 覆蓋率
|
|
602
|
+
- 整合測試: 20%
|
|
603
|
+
- E2E 測試: 10%
|
|
604
|
+
- 提交前執行測試`
|
|
605
|
+
},
|
|
606
|
+
standard: {
|
|
607
|
+
en: `## Testing Standards
|
|
608
|
+
Reference: .standards/testing-standards.md
|
|
609
|
+
|
|
610
|
+
### Test Pyramid Distribution
|
|
611
|
+
- Unit Tests: 70% (base)
|
|
612
|
+
- Integration Tests: 20%
|
|
613
|
+
- E2E/System Tests: 10% (top)
|
|
614
|
+
|
|
615
|
+
### Test Requirements
|
|
616
|
+
1. All new features must have tests
|
|
617
|
+
2. Bug fixes should include regression tests
|
|
618
|
+
3. Critical paths require E2E coverage
|
|
619
|
+
|
|
620
|
+
### Naming Convention
|
|
621
|
+
\`\`\`
|
|
622
|
+
test_[method]_[scenario]_[expected]
|
|
623
|
+
\`\`\`
|
|
624
|
+
|
|
625
|
+
### Before Committing
|
|
626
|
+
- All tests must pass
|
|
627
|
+
- Coverage should not decrease`,
|
|
628
|
+
'zh-tw': `## 測試標準
|
|
629
|
+
參考: .standards/testing-standards.md
|
|
630
|
+
|
|
631
|
+
### 測試金字塔分佈
|
|
632
|
+
- 單元測試: 70%(基底)
|
|
633
|
+
- 整合測試: 20%
|
|
634
|
+
- E2E/系統測試: 10%(頂端)
|
|
635
|
+
|
|
636
|
+
### 測試要求
|
|
637
|
+
1. 所有新功能必須有測試
|
|
638
|
+
2. 錯誤修復應包含回歸測試
|
|
639
|
+
3. 關鍵路徑需要 E2E 覆蓋
|
|
640
|
+
|
|
641
|
+
### 命名慣例
|
|
642
|
+
\`\`\`
|
|
643
|
+
test_[方法]_[情境]_[預期結果]
|
|
644
|
+
\`\`\`
|
|
645
|
+
|
|
646
|
+
### 提交前
|
|
647
|
+
- 所有測試必須通過
|
|
648
|
+
- 覆蓋率不應下降`
|
|
649
|
+
},
|
|
650
|
+
comprehensive: {
|
|
651
|
+
en: `## Testing Standards
|
|
652
|
+
Reference: .standards/testing-standards.md
|
|
653
|
+
|
|
654
|
+
### Test Pyramid
|
|
655
|
+
\`\`\`
|
|
656
|
+
/\\
|
|
657
|
+
/ \\ E2E (10%)
|
|
658
|
+
/ \\ System tests, UI tests
|
|
659
|
+
/──────\\
|
|
660
|
+
/ \\ Integration (20%)
|
|
661
|
+
/ \\ API tests, DB tests
|
|
662
|
+
/────────────\\
|
|
663
|
+
/ \\ Unit (70%)
|
|
664
|
+
/________________\\ Pure logic, fast feedback
|
|
665
|
+
\`\`\`
|
|
666
|
+
|
|
667
|
+
### Test Levels
|
|
668
|
+
| Level | Coverage | Focus |
|
|
669
|
+
|-------|----------|-------|
|
|
670
|
+
| Unit | 70% | Individual functions/methods |
|
|
671
|
+
| Integration | 20% | Component interactions |
|
|
672
|
+
| E2E | 10% | User workflows |
|
|
673
|
+
|
|
674
|
+
### Test Requirements by Feature Type
|
|
675
|
+
- **New Feature**: Unit + Integration tests required
|
|
676
|
+
- **Bug Fix**: Regression test required
|
|
677
|
+
- **Refactor**: Existing tests must pass
|
|
678
|
+
- **Critical Path**: E2E test required
|
|
679
|
+
|
|
680
|
+
### Naming Convention
|
|
681
|
+
\`\`\`
|
|
682
|
+
// Format: test_[method]_[scenario]_[expected]
|
|
683
|
+
test_calculateTotal_withDiscount_returnsDiscountedPrice()
|
|
684
|
+
test_login_invalidCredentials_throwsAuthError()
|
|
685
|
+
\`\`\`
|
|
686
|
+
|
|
687
|
+
### Test Quality Checklist
|
|
688
|
+
- [ ] Tests are independent (no shared state)
|
|
689
|
+
- [ ] Tests are deterministic (no flaky tests)
|
|
690
|
+
- [ ] Tests have clear assertions
|
|
691
|
+
- [ ] Edge cases are covered
|
|
692
|
+
- [ ] Error scenarios are tested`,
|
|
693
|
+
'zh-tw': `## 測試標準
|
|
694
|
+
參考: .standards/testing-standards.md
|
|
695
|
+
|
|
696
|
+
### 測試金字塔
|
|
697
|
+
\`\`\`
|
|
698
|
+
/\\
|
|
699
|
+
/ \\ E2E (10%)
|
|
700
|
+
/ \\ 系統測試、UI 測試
|
|
701
|
+
/──────\\
|
|
702
|
+
/ \\ 整合測試 (20%)
|
|
703
|
+
/ \\ API 測試、DB 測試
|
|
704
|
+
/────────────\\
|
|
705
|
+
/ \\ 單元測試 (70%)
|
|
706
|
+
/________________\\ 純邏輯、快速回饋
|
|
707
|
+
\`\`\`
|
|
708
|
+
|
|
709
|
+
### 測試層級
|
|
710
|
+
| 層級 | 覆蓋率 | 重點 |
|
|
711
|
+
|------|--------|------|
|
|
712
|
+
| 單元 | 70% | 個別函式/方法 |
|
|
713
|
+
| 整合 | 20% | 元件互動 |
|
|
714
|
+
| E2E | 10% | 使用者流程 |
|
|
715
|
+
|
|
716
|
+
### 依功能類型的測試要求
|
|
717
|
+
- **新功能**: 需要單元 + 整合測試
|
|
718
|
+
- **錯誤修復**: 需要回歸測試
|
|
719
|
+
- **重構**: 現有測試必須通過
|
|
720
|
+
- **關鍵路徑**: 需要 E2E 測試
|
|
721
|
+
|
|
722
|
+
### 命名慣例
|
|
723
|
+
\`\`\`
|
|
724
|
+
// 格式: test_[方法]_[情境]_[預期結果]
|
|
725
|
+
test_calculateTotal_withDiscount_returnsDiscountedPrice()
|
|
726
|
+
test_login_invalidCredentials_throwsAuthError()
|
|
727
|
+
\`\`\`
|
|
728
|
+
|
|
729
|
+
### 測試品質清單
|
|
730
|
+
- [ ] 測試獨立(無共享狀態)
|
|
731
|
+
- [ ] 測試確定性(無不穩定測試)
|
|
732
|
+
- [ ] 測試有明確斷言
|
|
733
|
+
- [ ] 涵蓋邊界情況
|
|
734
|
+
- [ ] 測試錯誤情境`
|
|
735
|
+
}
|
|
736
|
+
},
|
|
737
|
+
|
|
738
|
+
'documentation': {
|
|
739
|
+
minimal: {
|
|
740
|
+
en: `## Documentation Standards
|
|
741
|
+
- Every public API needs docs
|
|
742
|
+
- README must have: Install, Usage, Examples
|
|
743
|
+
- Keep docs in sync with code`,
|
|
744
|
+
'zh-tw': `## 文件標準
|
|
745
|
+
- 每個公開 API 需要文件
|
|
746
|
+
- README 必須有: 安裝、使用、範例
|
|
747
|
+
- 保持文件與程式碼同步`
|
|
748
|
+
},
|
|
749
|
+
standard: {
|
|
750
|
+
en: `## Documentation Standards
|
|
751
|
+
Reference: .standards/documentation-guide.md
|
|
752
|
+
|
|
753
|
+
### README Requirements
|
|
754
|
+
1. Project name and description
|
|
755
|
+
2. Installation instructions
|
|
756
|
+
3. Quick start / Usage examples
|
|
757
|
+
4. Configuration options
|
|
758
|
+
5. Contributing guidelines
|
|
759
|
+
|
|
760
|
+
### API Documentation
|
|
761
|
+
- All public functions documented
|
|
762
|
+
- Include parameters, return types
|
|
763
|
+
- Provide usage examples
|
|
764
|
+
|
|
765
|
+
### Keep in Sync
|
|
766
|
+
- Update docs with code changes
|
|
767
|
+
- Review docs during code review`,
|
|
768
|
+
'zh-tw': `## 文件標準
|
|
769
|
+
參考: .standards/documentation-guide.md
|
|
770
|
+
|
|
771
|
+
### README 要求
|
|
772
|
+
1. 專案名稱和描述
|
|
773
|
+
2. 安裝說明
|
|
774
|
+
3. 快速開始 / 使用範例
|
|
775
|
+
4. 配置選項
|
|
776
|
+
5. 貢獻指南
|
|
777
|
+
|
|
778
|
+
### API 文件
|
|
779
|
+
- 所有公開函式有文件
|
|
780
|
+
- 包含參數、回傳類型
|
|
781
|
+
- 提供使用範例
|
|
782
|
+
|
|
783
|
+
### 保持同步
|
|
784
|
+
- 隨程式碼變更更新文件
|
|
785
|
+
- 在程式碼審查時審查文件`
|
|
786
|
+
},
|
|
787
|
+
comprehensive: {
|
|
788
|
+
en: `## Documentation Standards
|
|
789
|
+
Reference: .standards/documentation-guide.md
|
|
790
|
+
|
|
791
|
+
### README Structure
|
|
792
|
+
\`\`\`markdown
|
|
793
|
+
# Project Name
|
|
794
|
+
|
|
795
|
+
Brief description of what the project does.
|
|
796
|
+
|
|
797
|
+
## Features
|
|
798
|
+
- Feature 1
|
|
799
|
+
- Feature 2
|
|
800
|
+
|
|
801
|
+
## Installation
|
|
802
|
+
\\\`\\\`\\\`bash
|
|
803
|
+
npm install project-name
|
|
804
|
+
\\\`\\\`\\\`
|
|
805
|
+
|
|
806
|
+
## Quick Start
|
|
807
|
+
\\\`\\\`\\\`javascript
|
|
808
|
+
// Example code
|
|
809
|
+
\\\`\\\`\\\`
|
|
810
|
+
|
|
811
|
+
## Configuration
|
|
812
|
+
| Option | Default | Description |
|
|
813
|
+
|--------|---------|-------------|
|
|
814
|
+
| opt1 | value | What it does |
|
|
815
|
+
|
|
816
|
+
## API Reference
|
|
817
|
+
[Link to full API docs]
|
|
818
|
+
|
|
819
|
+
## Contributing
|
|
820
|
+
[Link to CONTRIBUTING.md]
|
|
821
|
+
|
|
822
|
+
## License
|
|
823
|
+
[License type]
|
|
824
|
+
\`\`\`
|
|
825
|
+
|
|
826
|
+
### API Documentation Format
|
|
827
|
+
\`\`\`javascript
|
|
828
|
+
/**
|
|
829
|
+
* Brief description of the function
|
|
830
|
+
*
|
|
831
|
+
* @param {string} param1 - Description of param1
|
|
832
|
+
* @param {Object} options - Configuration options
|
|
833
|
+
* @param {boolean} options.flag - What this flag does
|
|
834
|
+
* @returns {Promise<Result>} Description of return value
|
|
835
|
+
* @throws {Error} When something goes wrong
|
|
836
|
+
* @example
|
|
837
|
+
* const result = await myFunction('value', { flag: true });
|
|
838
|
+
*/
|
|
839
|
+
\`\`\`
|
|
840
|
+
|
|
841
|
+
### Documentation Checklist
|
|
842
|
+
- [ ] README is complete and accurate
|
|
843
|
+
- [ ] All public APIs documented
|
|
844
|
+
- [ ] Examples are working
|
|
845
|
+
- [ ] CHANGELOG is up to date
|
|
846
|
+
- [ ] No broken links`,
|
|
847
|
+
'zh-tw': `## 文件標準
|
|
848
|
+
參考: .standards/documentation-guide.md
|
|
849
|
+
|
|
850
|
+
### README 結構
|
|
851
|
+
\`\`\`markdown
|
|
852
|
+
# 專案名稱
|
|
853
|
+
|
|
854
|
+
專案功能的簡短描述。
|
|
855
|
+
|
|
856
|
+
## 功能特色
|
|
857
|
+
- 功能 1
|
|
858
|
+
- 功能 2
|
|
859
|
+
|
|
860
|
+
## 安裝
|
|
861
|
+
\\\`\\\`\\\`bash
|
|
862
|
+
npm install project-name
|
|
863
|
+
\\\`\\\`\\\`
|
|
864
|
+
|
|
865
|
+
## 快速開始
|
|
866
|
+
\\\`\\\`\\\`javascript
|
|
867
|
+
// 範例程式碼
|
|
868
|
+
\\\`\\\`\\\`
|
|
869
|
+
|
|
870
|
+
## 配置
|
|
871
|
+
| 選項 | 預設值 | 說明 |
|
|
872
|
+
|------|--------|------|
|
|
873
|
+
| opt1 | value | 用途 |
|
|
874
|
+
|
|
875
|
+
## API 參考
|
|
876
|
+
[完整 API 文件連結]
|
|
877
|
+
|
|
878
|
+
## 貢獻
|
|
879
|
+
[CONTRIBUTING.md 連結]
|
|
880
|
+
|
|
881
|
+
## 授權
|
|
882
|
+
[授權類型]
|
|
883
|
+
\`\`\`
|
|
884
|
+
|
|
885
|
+
### API 文件格式
|
|
886
|
+
\`\`\`javascript
|
|
887
|
+
/**
|
|
888
|
+
* 函式的簡短說明
|
|
889
|
+
*
|
|
890
|
+
* @param {string} param1 - param1 的說明
|
|
891
|
+
* @param {Object} options - 配置選項
|
|
892
|
+
* @param {boolean} options.flag - 此旗標的用途
|
|
893
|
+
* @returns {Promise<Result>} 回傳值說明
|
|
894
|
+
* @throws {Error} 發生錯誤時
|
|
895
|
+
* @example
|
|
896
|
+
* const result = await myFunction('value', { flag: true });
|
|
897
|
+
*/
|
|
898
|
+
\`\`\`
|
|
899
|
+
|
|
900
|
+
### 文件清單
|
|
901
|
+
- [ ] README 完整且準確
|
|
902
|
+
- [ ] 所有公開 API 有文件
|
|
903
|
+
- [ ] 範例可正常運作
|
|
904
|
+
- [ ] CHANGELOG 已更新
|
|
905
|
+
- [ ] 無失效連結`
|
|
906
|
+
}
|
|
907
|
+
},
|
|
908
|
+
|
|
909
|
+
'git-workflow': {
|
|
910
|
+
minimal: {
|
|
911
|
+
en: `## Git Workflow
|
|
912
|
+
- Branch format: type/description
|
|
913
|
+
- Types: feature/, fix/, docs/, chore/
|
|
914
|
+
- Always create PR for review`,
|
|
915
|
+
'zh-tw': `## Git 工作流程
|
|
916
|
+
- 分支格式: type/description
|
|
917
|
+
- 類型: feature/, fix/, docs/, chore/
|
|
918
|
+
- 務必建立 PR 審查`
|
|
919
|
+
},
|
|
920
|
+
standard: {
|
|
921
|
+
en: `## Git Workflow
|
|
922
|
+
Reference: .standards/git-workflow.md
|
|
923
|
+
|
|
924
|
+
### Branch Naming
|
|
925
|
+
\`\`\`
|
|
926
|
+
<type>/<ticket>-<description>
|
|
927
|
+
\`\`\`
|
|
928
|
+
Examples:
|
|
929
|
+
- feature/PROJ-123-add-login
|
|
930
|
+
- fix/PROJ-456-null-pointer
|
|
931
|
+
- docs/update-readme
|
|
932
|
+
|
|
933
|
+
### Branch Types
|
|
934
|
+
| Prefix | Purpose |
|
|
935
|
+
|--------|---------|
|
|
936
|
+
| feature/ | New features |
|
|
937
|
+
| fix/ | Bug fixes |
|
|
938
|
+
| docs/ | Documentation |
|
|
939
|
+
| chore/ | Maintenance |
|
|
940
|
+
| refactor/ | Code restructure |
|
|
941
|
+
|
|
942
|
+
### Workflow
|
|
943
|
+
1. Create branch from main
|
|
944
|
+
2. Commit with conventional messages
|
|
945
|
+
3. Push and create PR
|
|
946
|
+
4. Get review approval
|
|
947
|
+
5. Squash merge to main`,
|
|
948
|
+
'zh-tw': `## Git 工作流程
|
|
949
|
+
參考: .standards/git-workflow.md
|
|
950
|
+
|
|
951
|
+
### 分支命名
|
|
952
|
+
\`\`\`
|
|
953
|
+
<type>/<ticket>-<description>
|
|
954
|
+
\`\`\`
|
|
955
|
+
範例:
|
|
956
|
+
- feature/PROJ-123-add-login
|
|
957
|
+
- fix/PROJ-456-null-pointer
|
|
958
|
+
- docs/update-readme
|
|
959
|
+
|
|
960
|
+
### 分支類型
|
|
961
|
+
| 前綴 | 用途 |
|
|
962
|
+
|------|------|
|
|
963
|
+
| feature/ | 新功能 |
|
|
964
|
+
| fix/ | 錯誤修復 |
|
|
965
|
+
| docs/ | 文件更新 |
|
|
966
|
+
| chore/ | 維護任務 |
|
|
967
|
+
| refactor/ | 程式碼重構 |
|
|
968
|
+
|
|
969
|
+
### 工作流程
|
|
970
|
+
1. 從 main 建立分支
|
|
971
|
+
2. 使用規範格式提交
|
|
972
|
+
3. 推送並建立 PR
|
|
973
|
+
4. 獲得審查核准
|
|
974
|
+
5. Squash merge 到 main`
|
|
975
|
+
},
|
|
976
|
+
comprehensive: {
|
|
977
|
+
en: `## Git Workflow Standards
|
|
978
|
+
Reference: .standards/git-workflow.md
|
|
979
|
+
|
|
980
|
+
### Branch Strategy: GitHub Flow
|
|
981
|
+
\`\`\`
|
|
982
|
+
main ────────────────────────────────────>
|
|
983
|
+
\\ /
|
|
984
|
+
feature ─
|
|
985
|
+
\`\`\`
|
|
986
|
+
|
|
987
|
+
### Branch Naming Convention
|
|
988
|
+
\`\`\`
|
|
989
|
+
<type>/<ticket-id>-<short-description>
|
|
990
|
+
\`\`\`
|
|
991
|
+
|
|
992
|
+
| Type | Purpose | Example |
|
|
993
|
+
|------|---------|---------|
|
|
994
|
+
| feature/ | New functionality | feature/PROJ-123-user-auth |
|
|
995
|
+
| fix/ | Bug fixes | fix/PROJ-456-login-crash |
|
|
996
|
+
| docs/ | Documentation | docs/api-reference |
|
|
997
|
+
| chore/ | Maintenance | chore/update-deps |
|
|
998
|
+
| refactor/ | Code improvement | refactor/user-service |
|
|
999
|
+
| test/ | Test additions | test/auth-coverage |
|
|
1000
|
+
|
|
1001
|
+
### Pull Request Process
|
|
1002
|
+
1. **Create Branch**
|
|
1003
|
+
\`\`\`bash
|
|
1004
|
+
git checkout -b feature/PROJ-123-description
|
|
1005
|
+
\`\`\`
|
|
1006
|
+
|
|
1007
|
+
2. **Make Commits**
|
|
1008
|
+
- Follow conventional commit format
|
|
1009
|
+
- Keep commits atomic and focused
|
|
1010
|
+
|
|
1011
|
+
3. **Push & Create PR**
|
|
1012
|
+
\`\`\`bash
|
|
1013
|
+
git push -u origin feature/PROJ-123-description
|
|
1014
|
+
\`\`\`
|
|
1015
|
+
|
|
1016
|
+
4. **PR Requirements**
|
|
1017
|
+
- Descriptive title
|
|
1018
|
+
- Link to issue/ticket
|
|
1019
|
+
- Summary of changes
|
|
1020
|
+
- Test instructions
|
|
1021
|
+
|
|
1022
|
+
5. **Review & Merge**
|
|
1023
|
+
- At least 1 approval required
|
|
1024
|
+
- All CI checks must pass
|
|
1025
|
+
- Squash merge preferred
|
|
1026
|
+
|
|
1027
|
+
### Protected Branch Rules
|
|
1028
|
+
- Direct commits to main blocked
|
|
1029
|
+
- PR required for all changes
|
|
1030
|
+
- Status checks must pass`,
|
|
1031
|
+
'zh-tw': `## Git 工作流程標準
|
|
1032
|
+
參考: .standards/git-workflow.md
|
|
1033
|
+
|
|
1034
|
+
### 分支策略: GitHub Flow
|
|
1035
|
+
\`\`\`
|
|
1036
|
+
main ────────────────────────────────────>
|
|
1037
|
+
\\ /
|
|
1038
|
+
feature ─
|
|
1039
|
+
\`\`\`
|
|
1040
|
+
|
|
1041
|
+
### 分支命名慣例
|
|
1042
|
+
\`\`\`
|
|
1043
|
+
<type>/<ticket-id>-<short-description>
|
|
1044
|
+
\`\`\`
|
|
1045
|
+
|
|
1046
|
+
| 類型 | 用途 | 範例 |
|
|
1047
|
+
|------|------|------|
|
|
1048
|
+
| feature/ | 新功能 | feature/PROJ-123-user-auth |
|
|
1049
|
+
| fix/ | 錯誤修復 | fix/PROJ-456-login-crash |
|
|
1050
|
+
| docs/ | 文件更新 | docs/api-reference |
|
|
1051
|
+
| chore/ | 維護任務 | chore/update-deps |
|
|
1052
|
+
| refactor/ | 程式碼改進 | refactor/user-service |
|
|
1053
|
+
| test/ | 新增測試 | test/auth-coverage |
|
|
1054
|
+
|
|
1055
|
+
### Pull Request 流程
|
|
1056
|
+
1. **建立分支**
|
|
1057
|
+
\`\`\`bash
|
|
1058
|
+
git checkout -b feature/PROJ-123-description
|
|
1059
|
+
\`\`\`
|
|
1060
|
+
|
|
1061
|
+
2. **進行提交**
|
|
1062
|
+
- 遵循規範提交格式
|
|
1063
|
+
- 保持提交原子性和專注
|
|
1064
|
+
|
|
1065
|
+
3. **推送並建立 PR**
|
|
1066
|
+
\`\`\`bash
|
|
1067
|
+
git push -u origin feature/PROJ-123-description
|
|
1068
|
+
\`\`\`
|
|
1069
|
+
|
|
1070
|
+
4. **PR 要求**
|
|
1071
|
+
- 描述性標題
|
|
1072
|
+
- 連結到 issue/ticket
|
|
1073
|
+
- 變更摘要
|
|
1074
|
+
- 測試說明
|
|
1075
|
+
|
|
1076
|
+
5. **審查與合併**
|
|
1077
|
+
- 至少需要 1 個核准
|
|
1078
|
+
- 所有 CI 檢查必須通過
|
|
1079
|
+
- 建議使用 Squash merge
|
|
1080
|
+
|
|
1081
|
+
### 受保護分支規則
|
|
1082
|
+
- 禁止直接提交到 main
|
|
1083
|
+
- 所有變更需要 PR
|
|
1084
|
+
- 狀態檢查必須通過`
|
|
1085
|
+
}
|
|
1086
|
+
},
|
|
1087
|
+
|
|
1088
|
+
'error-handling': {
|
|
1089
|
+
minimal: {
|
|
1090
|
+
en: `## Error Handling
|
|
1091
|
+
- Use structured error codes
|
|
1092
|
+
- Log errors with context
|
|
1093
|
+
- Never expose internal errors to users`,
|
|
1094
|
+
'zh-tw': `## 錯誤處理
|
|
1095
|
+
- 使用結構化錯誤碼
|
|
1096
|
+
- 記錄錯誤時包含上下文
|
|
1097
|
+
- 永不向使用者暴露內部錯誤`
|
|
1098
|
+
},
|
|
1099
|
+
standard: {
|
|
1100
|
+
en: `## Error Handling Standards
|
|
1101
|
+
|
|
1102
|
+
### Error Code Format
|
|
1103
|
+
\`\`\`
|
|
1104
|
+
E[CATEGORY][NUMBER]
|
|
1105
|
+
\`\`\`
|
|
1106
|
+
Example: EAUTH001, EDATA002
|
|
1107
|
+
|
|
1108
|
+
### Logging Requirements
|
|
1109
|
+
- Include timestamp, level, message
|
|
1110
|
+
- Add context: user ID, request ID
|
|
1111
|
+
- Structured format (JSON preferred)
|
|
1112
|
+
|
|
1113
|
+
### Error Response
|
|
1114
|
+
- User-friendly message
|
|
1115
|
+
- Error code for debugging
|
|
1116
|
+
- No stack traces in production`,
|
|
1117
|
+
'zh-tw': `## 錯誤處理標準
|
|
1118
|
+
|
|
1119
|
+
### 錯誤碼格式
|
|
1120
|
+
\`\`\`
|
|
1121
|
+
E[CATEGORY][NUMBER]
|
|
1122
|
+
\`\`\`
|
|
1123
|
+
範例: EAUTH001, EDATA002
|
|
1124
|
+
|
|
1125
|
+
### 日誌要求
|
|
1126
|
+
- 包含時間戳記、層級、訊息
|
|
1127
|
+
- 加入上下文: 使用者 ID、請求 ID
|
|
1128
|
+
- 結構化格式(建議 JSON)
|
|
1129
|
+
|
|
1130
|
+
### 錯誤回應
|
|
1131
|
+
- 使用者友善的訊息
|
|
1132
|
+
- 供除錯的錯誤碼
|
|
1133
|
+
- 生產環境不顯示堆疊追蹤`
|
|
1134
|
+
},
|
|
1135
|
+
comprehensive: {
|
|
1136
|
+
en: `## Error Handling Standards
|
|
1137
|
+
Reference: .standards/error-code-standards.md, .standards/logging-standards.md
|
|
1138
|
+
|
|
1139
|
+
### Error Code System
|
|
1140
|
+
\`\`\`
|
|
1141
|
+
E[CATEGORY][SUBCATEGORY][NUMBER]
|
|
1142
|
+
\`\`\`
|
|
1143
|
+
|
|
1144
|
+
| Category | Code Range | Description |
|
|
1145
|
+
|----------|------------|-------------|
|
|
1146
|
+
| AUTH | EAUTH001-099 | Authentication errors |
|
|
1147
|
+
| DATA | EDATA001-099 | Data validation errors |
|
|
1148
|
+
| SYS | ESYS001-099 | System errors |
|
|
1149
|
+
| NET | ENET001-099 | Network errors |
|
|
1150
|
+
| BIZ | EBIZ001-099 | Business logic errors |
|
|
1151
|
+
|
|
1152
|
+
### Error Object Structure
|
|
1153
|
+
\`\`\`javascript
|
|
1154
|
+
{
|
|
1155
|
+
code: "EAUTH001",
|
|
1156
|
+
message: "User-friendly message",
|
|
1157
|
+
details: "Technical details (dev only)",
|
|
1158
|
+
timestamp: "ISO-8601",
|
|
1159
|
+
requestId: "uuid"
|
|
1160
|
+
}
|
|
1161
|
+
\`\`\`
|
|
1162
|
+
|
|
1163
|
+
### Logging Standards
|
|
1164
|
+
\`\`\`javascript
|
|
1165
|
+
// Structured log format
|
|
1166
|
+
{
|
|
1167
|
+
timestamp: "2024-01-15T10:30:00Z",
|
|
1168
|
+
level: "error",
|
|
1169
|
+
message: "Authentication failed",
|
|
1170
|
+
context: {
|
|
1171
|
+
userId: "user-123",
|
|
1172
|
+
requestId: "req-456",
|
|
1173
|
+
action: "login"
|
|
1174
|
+
},
|
|
1175
|
+
error: {
|
|
1176
|
+
code: "EAUTH001",
|
|
1177
|
+
stack: "..." // dev only
|
|
1178
|
+
}
|
|
1179
|
+
}
|
|
1180
|
+
\`\`\`
|
|
1181
|
+
|
|
1182
|
+
### Log Levels
|
|
1183
|
+
| Level | Usage |
|
|
1184
|
+
|-------|-------|
|
|
1185
|
+
| error | Failures requiring action |
|
|
1186
|
+
| warn | Potential issues |
|
|
1187
|
+
| info | Significant events |
|
|
1188
|
+
| debug | Development details |
|
|
1189
|
+
|
|
1190
|
+
### Security Rules
|
|
1191
|
+
- Never log passwords or tokens
|
|
1192
|
+
- Mask PII in logs
|
|
1193
|
+
- No stack traces in production responses`,
|
|
1194
|
+
'zh-tw': `## 錯誤處理標準
|
|
1195
|
+
參考: .standards/error-code-standards.md, .standards/logging-standards.md
|
|
1196
|
+
|
|
1197
|
+
### 錯誤碼系統
|
|
1198
|
+
\`\`\`
|
|
1199
|
+
E[CATEGORY][SUBCATEGORY][NUMBER]
|
|
1200
|
+
\`\`\`
|
|
1201
|
+
|
|
1202
|
+
| 類別 | 代碼範圍 | 說明 |
|
|
1203
|
+
|------|----------|------|
|
|
1204
|
+
| AUTH | EAUTH001-099 | 認證錯誤 |
|
|
1205
|
+
| DATA | EDATA001-099 | 資料驗證錯誤 |
|
|
1206
|
+
| SYS | ESYS001-099 | 系統錯誤 |
|
|
1207
|
+
| NET | ENET001-099 | 網路錯誤 |
|
|
1208
|
+
| BIZ | EBIZ001-099 | 商業邏輯錯誤 |
|
|
1209
|
+
|
|
1210
|
+
### 錯誤物件結構
|
|
1211
|
+
\`\`\`javascript
|
|
1212
|
+
{
|
|
1213
|
+
code: "EAUTH001",
|
|
1214
|
+
message: "使用者友善訊息",
|
|
1215
|
+
details: "技術細節(僅開發環境)",
|
|
1216
|
+
timestamp: "ISO-8601",
|
|
1217
|
+
requestId: "uuid"
|
|
1218
|
+
}
|
|
1219
|
+
\`\`\`
|
|
1220
|
+
|
|
1221
|
+
### 日誌標準
|
|
1222
|
+
\`\`\`javascript
|
|
1223
|
+
// 結構化日誌格式
|
|
1224
|
+
{
|
|
1225
|
+
timestamp: "2024-01-15T10:30:00Z",
|
|
1226
|
+
level: "error",
|
|
1227
|
+
message: "認證失敗",
|
|
1228
|
+
context: {
|
|
1229
|
+
userId: "user-123",
|
|
1230
|
+
requestId: "req-456",
|
|
1231
|
+
action: "login"
|
|
1232
|
+
},
|
|
1233
|
+
error: {
|
|
1234
|
+
code: "EAUTH001",
|
|
1235
|
+
stack: "..." // 僅開發環境
|
|
1236
|
+
}
|
|
1237
|
+
}
|
|
1238
|
+
\`\`\`
|
|
1239
|
+
|
|
1240
|
+
### 日誌層級
|
|
1241
|
+
| 層級 | 用途 |
|
|
1242
|
+
|------|------|
|
|
1243
|
+
| error | 需要處理的失敗 |
|
|
1244
|
+
| warn | 潛在問題 |
|
|
1245
|
+
| info | 重要事件 |
|
|
1246
|
+
| debug | 開發細節 |
|
|
1247
|
+
|
|
1248
|
+
### 安全規則
|
|
1249
|
+
- 永不記錄密碼或令牌
|
|
1250
|
+
- 在日誌中遮蔽個人資料
|
|
1251
|
+
- 生產環境回應不包含堆疊追蹤`
|
|
1252
|
+
}
|
|
1253
|
+
},
|
|
1254
|
+
|
|
1255
|
+
'project-structure': {
|
|
1256
|
+
minimal: {
|
|
1257
|
+
en: `## Project Structure
|
|
1258
|
+
- src/ for source code
|
|
1259
|
+
- tests/ for test files
|
|
1260
|
+
- docs/ for documentation
|
|
1261
|
+
- Keep related files together`,
|
|
1262
|
+
'zh-tw': `## 專案結構
|
|
1263
|
+
- src/ 放原始碼
|
|
1264
|
+
- tests/ 放測試檔案
|
|
1265
|
+
- docs/ 放文件
|
|
1266
|
+
- 相關檔案放在一起`
|
|
1267
|
+
},
|
|
1268
|
+
standard: {
|
|
1269
|
+
en: `## Project Structure Standards
|
|
1270
|
+
|
|
1271
|
+
### Standard Layout
|
|
1272
|
+
\`\`\`
|
|
1273
|
+
project/
|
|
1274
|
+
├── src/ # Source code
|
|
1275
|
+
├── tests/ # Test files
|
|
1276
|
+
├── docs/ # Documentation
|
|
1277
|
+
├── config/ # Configuration
|
|
1278
|
+
├── scripts/ # Build/utility scripts
|
|
1279
|
+
└── .standards/ # Project standards
|
|
1280
|
+
\`\`\`
|
|
1281
|
+
|
|
1282
|
+
### Principles
|
|
1283
|
+
- Group by feature, not by type
|
|
1284
|
+
- Keep related code close
|
|
1285
|
+
- Flat is better than nested
|
|
1286
|
+
- Consistent naming conventions`,
|
|
1287
|
+
'zh-tw': `## 專案結構標準
|
|
1288
|
+
|
|
1289
|
+
### 標準配置
|
|
1290
|
+
\`\`\`
|
|
1291
|
+
project/
|
|
1292
|
+
├── src/ # 原始碼
|
|
1293
|
+
├── tests/ # 測試檔案
|
|
1294
|
+
├── docs/ # 文件
|
|
1295
|
+
├── config/ # 配置
|
|
1296
|
+
├── scripts/ # 建置/工具腳本
|
|
1297
|
+
└── .standards/ # 專案標準
|
|
1298
|
+
\`\`\`
|
|
1299
|
+
|
|
1300
|
+
### 原則
|
|
1301
|
+
- 依功能分組,非依類型
|
|
1302
|
+
- 相關程式碼放在一起
|
|
1303
|
+
- 扁平優於巢狀
|
|
1304
|
+
- 一致的命名慣例`
|
|
1305
|
+
},
|
|
1306
|
+
comprehensive: {
|
|
1307
|
+
en: `## Project Structure Standards
|
|
1308
|
+
Reference: .standards/project-structure.md
|
|
1309
|
+
|
|
1310
|
+
### Universal Layout
|
|
1311
|
+
\`\`\`
|
|
1312
|
+
project/
|
|
1313
|
+
├── src/ # Source code
|
|
1314
|
+
│ ├── components/ # Reusable components
|
|
1315
|
+
│ ├── services/ # Business logic
|
|
1316
|
+
│ ├── utils/ # Utility functions
|
|
1317
|
+
│ └── types/ # Type definitions
|
|
1318
|
+
├── tests/ # Test files
|
|
1319
|
+
│ ├── unit/ # Unit tests
|
|
1320
|
+
│ └── integration/ # Integration tests
|
|
1321
|
+
├── docs/ # Documentation
|
|
1322
|
+
├── config/ # Configuration files
|
|
1323
|
+
├── scripts/ # Build/utility scripts
|
|
1324
|
+
├── .standards/ # Project standards
|
|
1325
|
+
├── .github/ # GitHub workflows
|
|
1326
|
+
├── README.md
|
|
1327
|
+
├── CHANGELOG.md
|
|
1328
|
+
└── package.json # (or equivalent)
|
|
1329
|
+
\`\`\`
|
|
1330
|
+
|
|
1331
|
+
### Organization Principles
|
|
1332
|
+
|
|
1333
|
+
#### 1. Feature-Based Organization
|
|
1334
|
+
\`\`\`
|
|
1335
|
+
src/
|
|
1336
|
+
├── auth/
|
|
1337
|
+
│ ├── components/
|
|
1338
|
+
│ ├── services/
|
|
1339
|
+
│ └── types/
|
|
1340
|
+
├── users/
|
|
1341
|
+
│ ├── components/
|
|
1342
|
+
│ ├── services/
|
|
1343
|
+
│ └── types/
|
|
1344
|
+
\`\`\`
|
|
1345
|
+
|
|
1346
|
+
#### 2. Naming Conventions
|
|
1347
|
+
| Type | Convention | Example |
|
|
1348
|
+
|------|------------|---------|
|
|
1349
|
+
| Files | kebab-case | user-service.js |
|
|
1350
|
+
| Classes | PascalCase | UserService |
|
|
1351
|
+
| Functions | camelCase | getUser() |
|
|
1352
|
+
| Constants | UPPER_SNAKE | MAX_RETRIES |
|
|
1353
|
+
|
|
1354
|
+
#### 3. File Size Guidelines
|
|
1355
|
+
- Components: < 300 lines
|
|
1356
|
+
- Modules: < 500 lines
|
|
1357
|
+
- Split when exceeding limits
|
|
1358
|
+
|
|
1359
|
+
### Anti-Patterns to Avoid
|
|
1360
|
+
- Deep nesting (> 4 levels)
|
|
1361
|
+
- Circular dependencies
|
|
1362
|
+
- Mixed concerns in one file
|
|
1363
|
+
- Inconsistent naming`,
|
|
1364
|
+
'zh-tw': `## 專案結構標準
|
|
1365
|
+
參考: .standards/project-structure.md
|
|
1366
|
+
|
|
1367
|
+
### 通用配置
|
|
1368
|
+
\`\`\`
|
|
1369
|
+
project/
|
|
1370
|
+
├── src/ # 原始碼
|
|
1371
|
+
│ ├── components/ # 可重用元件
|
|
1372
|
+
│ ├── services/ # 商業邏輯
|
|
1373
|
+
│ ├── utils/ # 工具函式
|
|
1374
|
+
│ └── types/ # 類型定義
|
|
1375
|
+
├── tests/ # 測試檔案
|
|
1376
|
+
│ ├── unit/ # 單元測試
|
|
1377
|
+
│ └── integration/ # 整合測試
|
|
1378
|
+
├── docs/ # 文件
|
|
1379
|
+
├── config/ # 配置檔案
|
|
1380
|
+
├── scripts/ # 建置/工具腳本
|
|
1381
|
+
├── .standards/ # 專案標準
|
|
1382
|
+
├── .github/ # GitHub 工作流程
|
|
1383
|
+
├── README.md
|
|
1384
|
+
├── CHANGELOG.md
|
|
1385
|
+
└── package.json # (或同等檔案)
|
|
1386
|
+
\`\`\`
|
|
1387
|
+
|
|
1388
|
+
### 組織原則
|
|
1389
|
+
|
|
1390
|
+
#### 1. 依功能組織
|
|
1391
|
+
\`\`\`
|
|
1392
|
+
src/
|
|
1393
|
+
├── auth/
|
|
1394
|
+
│ ├── components/
|
|
1395
|
+
│ ├── services/
|
|
1396
|
+
│ └── types/
|
|
1397
|
+
├── users/
|
|
1398
|
+
│ ├── components/
|
|
1399
|
+
│ ├── services/
|
|
1400
|
+
│ └── types/
|
|
1401
|
+
\`\`\`
|
|
1402
|
+
|
|
1403
|
+
#### 2. 命名慣例
|
|
1404
|
+
| 類型 | 慣例 | 範例 |
|
|
1405
|
+
|------|------|------|
|
|
1406
|
+
| 檔案 | kebab-case | user-service.js |
|
|
1407
|
+
| 類別 | PascalCase | UserService |
|
|
1408
|
+
| 函式 | camelCase | getUser() |
|
|
1409
|
+
| 常數 | UPPER_SNAKE | MAX_RETRIES |
|
|
1410
|
+
|
|
1411
|
+
#### 3. 檔案大小指引
|
|
1412
|
+
- 元件: < 300 行
|
|
1413
|
+
- 模組: < 500 行
|
|
1414
|
+
- 超過時進行拆分
|
|
1415
|
+
|
|
1416
|
+
### 避免的反模式
|
|
1417
|
+
- 過深巢狀(> 4 層)
|
|
1418
|
+
- 循環相依
|
|
1419
|
+
- 單一檔案混合關注點
|
|
1420
|
+
- 不一致的命名`
|
|
1421
|
+
}
|
|
1422
|
+
}
|
|
1423
|
+
};
|
|
1424
|
+
|
|
1425
|
+
/**
|
|
1426
|
+
* Tool-specific file headers
|
|
1427
|
+
*/
|
|
1428
|
+
const TOOL_HEADERS = {
|
|
1429
|
+
cursor: {
|
|
1430
|
+
en: `# Cursor Rules
|
|
1431
|
+
# Generated by Universal Dev Standards CLI
|
|
1432
|
+
# https://github.com/AsiaOstrich/universal-dev-standards
|
|
1433
|
+
|
|
1434
|
+
You are an expert software engineer assistant. Follow these project standards:`,
|
|
1435
|
+
'zh-tw': `# Cursor 規則
|
|
1436
|
+
# 由 Universal Dev Standards CLI 生成
|
|
1437
|
+
# https://github.com/AsiaOstrich/universal-dev-standards
|
|
1438
|
+
|
|
1439
|
+
您是專業的軟體工程助手。請遵循以下專案標準:`,
|
|
1440
|
+
bilingual: `# Cursor Rules | Cursor 規則
|
|
1441
|
+
# Generated by Universal Dev Standards CLI
|
|
1442
|
+
# 由 Universal Dev Standards CLI 生成
|
|
1443
|
+
# https://github.com/AsiaOstrich/universal-dev-standards
|
|
1444
|
+
|
|
1445
|
+
You are an expert software engineer assistant. Follow these project standards.
|
|
1446
|
+
您是專業的軟體工程助手。請遵循以下專案標準。`
|
|
1447
|
+
},
|
|
1448
|
+
windsurf: {
|
|
1449
|
+
en: `# Windsurf Rules
|
|
1450
|
+
# Generated by Universal Dev Standards CLI
|
|
1451
|
+
# https://github.com/AsiaOstrich/universal-dev-standards
|
|
1452
|
+
|
|
1453
|
+
You are an expert software engineer assistant. Follow these project standards:`,
|
|
1454
|
+
'zh-tw': `# Windsurf 規則
|
|
1455
|
+
# 由 Universal Dev Standards CLI 生成
|
|
1456
|
+
# https://github.com/AsiaOstrich/universal-dev-standards
|
|
1457
|
+
|
|
1458
|
+
您是專業的軟體工程助手。請遵循以下專案標準:`,
|
|
1459
|
+
bilingual: `# Windsurf Rules | Windsurf 規則
|
|
1460
|
+
# Generated by Universal Dev Standards CLI
|
|
1461
|
+
# 由 Universal Dev Standards CLI 生成
|
|
1462
|
+
# https://github.com/AsiaOstrich/universal-dev-standards
|
|
1463
|
+
|
|
1464
|
+
You are an expert software engineer assistant. Follow these project standards.
|
|
1465
|
+
您是專業的軟體工程助手。請遵循以下專案標準。`
|
|
1466
|
+
},
|
|
1467
|
+
cline: {
|
|
1468
|
+
en: `# Cline Rules
|
|
1469
|
+
# Generated by Universal Dev Standards CLI
|
|
1470
|
+
# https://github.com/AsiaOstrich/universal-dev-standards
|
|
1471
|
+
|
|
1472
|
+
You are an expert software engineer assistant. Follow these project standards:`,
|
|
1473
|
+
'zh-tw': `# Cline 規則
|
|
1474
|
+
# 由 Universal Dev Standards CLI 生成
|
|
1475
|
+
# https://github.com/AsiaOstrich/universal-dev-standards
|
|
1476
|
+
|
|
1477
|
+
您是專業的軟體工程助手。請遵循以下專案標準:`,
|
|
1478
|
+
bilingual: `# Cline Rules | Cline 規則
|
|
1479
|
+
# Generated by Universal Dev Standards CLI
|
|
1480
|
+
# 由 Universal Dev Standards CLI 生成
|
|
1481
|
+
# https://github.com/AsiaOstrich/universal-dev-standards
|
|
1482
|
+
|
|
1483
|
+
You are an expert software engineer assistant. Follow these project standards.
|
|
1484
|
+
您是專業的軟體工程助手。請遵循以下專案標準。`
|
|
1485
|
+
},
|
|
1486
|
+
copilot: {
|
|
1487
|
+
en: `# GitHub Copilot Instructions
|
|
1488
|
+
# Generated by Universal Dev Standards CLI
|
|
1489
|
+
# https://github.com/AsiaOstrich/universal-dev-standards
|
|
1490
|
+
|
|
1491
|
+
You are an expert software engineer assistant. Follow these project standards:`,
|
|
1492
|
+
'zh-tw': `# GitHub Copilot 說明
|
|
1493
|
+
# 由 Universal Dev Standards CLI 生成
|
|
1494
|
+
# https://github.com/AsiaOstrich/universal-dev-standards
|
|
1495
|
+
|
|
1496
|
+
您是專業的軟體工程助手。請遵循以下專案標準:`,
|
|
1497
|
+
bilingual: `# GitHub Copilot Instructions | GitHub Copilot 說明
|
|
1498
|
+
# Generated by Universal Dev Standards CLI
|
|
1499
|
+
# 由 Universal Dev Standards CLI 生成
|
|
1500
|
+
# https://github.com/AsiaOstrich/universal-dev-standards
|
|
1501
|
+
|
|
1502
|
+
You are an expert software engineer assistant. Follow these project standards.
|
|
1503
|
+
您是專業的軟體工程助手。請遵循以下專案標準。`
|
|
1504
|
+
},
|
|
1505
|
+
antigravity: {
|
|
1506
|
+
en: `# Antigravity System Instructions
|
|
1507
|
+
# Generated by Universal Dev Standards CLI
|
|
1508
|
+
# https://github.com/AsiaOstrich/universal-dev-standards
|
|
1509
|
+
|
|
1510
|
+
Recommended system instructions for Google Antigravity (Gemini Advanced Agent).
|
|
1511
|
+
Follow these project standards:`,
|
|
1512
|
+
'zh-tw': `# Antigravity 系統指令
|
|
1513
|
+
# 由 Universal Dev Standards CLI 生成
|
|
1514
|
+
# https://github.com/AsiaOstrich/universal-dev-standards
|
|
1515
|
+
|
|
1516
|
+
Google Antigravity (Gemini Advanced Agent) 的推薦系統指令。
|
|
1517
|
+
請遵循以下專案標準:`,
|
|
1518
|
+
bilingual: `# Antigravity System Instructions | Antigravity 系統指令
|
|
1519
|
+
# Generated by Universal Dev Standards CLI
|
|
1520
|
+
# 由 Universal Dev Standards CLI 生成
|
|
1521
|
+
# https://github.com/AsiaOstrich/universal-dev-standards
|
|
1522
|
+
|
|
1523
|
+
Recommended system instructions for Google Antigravity (Gemini Advanced Agent).
|
|
1524
|
+
Google Antigravity (Gemini Advanced Agent) 的推薦系統指令。`
|
|
1525
|
+
}
|
|
1526
|
+
};
|
|
1527
|
+
|
|
1528
|
+
/**
|
|
1529
|
+
* Generate integration file content
|
|
1530
|
+
* @param {Object} config - Integration configuration
|
|
1531
|
+
* @returns {string} Generated content
|
|
1532
|
+
*/
|
|
1533
|
+
export function generateIntegrationContent(config) {
|
|
1534
|
+
const {
|
|
1535
|
+
tool,
|
|
1536
|
+
categories = [],
|
|
1537
|
+
languages = [],
|
|
1538
|
+
exclusions = [],
|
|
1539
|
+
customRules = [],
|
|
1540
|
+
detailLevel = 'standard',
|
|
1541
|
+
language = 'en'
|
|
1542
|
+
} = config;
|
|
1543
|
+
|
|
1544
|
+
const sections = [];
|
|
1545
|
+
|
|
1546
|
+
// Add header
|
|
1547
|
+
const header = TOOL_HEADERS[tool]?.[language] || TOOL_HEADERS[tool]?.en || '';
|
|
1548
|
+
sections.push(header);
|
|
1549
|
+
sections.push('\n---\n');
|
|
1550
|
+
|
|
1551
|
+
// Add rule sections based on selected categories
|
|
1552
|
+
for (const categoryId of categories) {
|
|
1553
|
+
const template = RULE_TEMPLATES[categoryId];
|
|
1554
|
+
if (template && template[detailLevel]) {
|
|
1555
|
+
if (language === 'bilingual') {
|
|
1556
|
+
sections.push(template[detailLevel].en);
|
|
1557
|
+
sections.push('\n');
|
|
1558
|
+
sections.push(template[detailLevel]['zh-tw']);
|
|
1559
|
+
} else {
|
|
1560
|
+
sections.push(template[detailLevel][language] || template[detailLevel].en);
|
|
1561
|
+
}
|
|
1562
|
+
sections.push('\n---\n');
|
|
1563
|
+
}
|
|
1564
|
+
}
|
|
1565
|
+
|
|
1566
|
+
// Add language-specific rules
|
|
1567
|
+
const langRules = getLanguageRules();
|
|
1568
|
+
for (const lang of languages) {
|
|
1569
|
+
if (langRules[lang]) {
|
|
1570
|
+
sections.push(`## ${langRules[lang].name} Guidelines`);
|
|
1571
|
+
sections.push(langRules[lang].rules.map(r => `- ${r}`).join('\n'));
|
|
1572
|
+
sections.push('\n');
|
|
1573
|
+
}
|
|
1574
|
+
}
|
|
1575
|
+
|
|
1576
|
+
// Add custom rules
|
|
1577
|
+
if (customRules.length > 0) {
|
|
1578
|
+
sections.push('## Project-Specific Rules');
|
|
1579
|
+
sections.push(customRules.map(r => `- ${r}`).join('\n'));
|
|
1580
|
+
sections.push('\n');
|
|
1581
|
+
}
|
|
1582
|
+
|
|
1583
|
+
// Add exclusions
|
|
1584
|
+
if (exclusions.length > 0) {
|
|
1585
|
+
sections.push('## Exclusions');
|
|
1586
|
+
sections.push('The following patterns/files are excluded from these rules:');
|
|
1587
|
+
sections.push(exclusions.map(e => `- ${e}`).join('\n'));
|
|
1588
|
+
sections.push('\n');
|
|
1589
|
+
}
|
|
1590
|
+
|
|
1591
|
+
return sections.join('\n').trim() + '\n';
|
|
1592
|
+
}
|
|
1593
|
+
|
|
1594
|
+
/**
|
|
1595
|
+
* Merge existing rules with new rules
|
|
1596
|
+
* @param {string} existingContent - Existing file content
|
|
1597
|
+
* @param {string} newContent - New content to merge
|
|
1598
|
+
* @param {string} strategy - Merge strategy ('append', 'merge', 'overwrite')
|
|
1599
|
+
* @returns {string} Merged content
|
|
1600
|
+
*/
|
|
1601
|
+
export function mergeRules(existingContent, newContent, strategy) {
|
|
1602
|
+
if (strategy === 'overwrite') {
|
|
1603
|
+
return newContent;
|
|
1604
|
+
}
|
|
1605
|
+
|
|
1606
|
+
if (strategy === 'keep') {
|
|
1607
|
+
return existingContent;
|
|
1608
|
+
}
|
|
1609
|
+
|
|
1610
|
+
if (strategy === 'append') {
|
|
1611
|
+
return existingContent.trim() + '\n\n---\n\n# Added by Universal Dev Standards\n\n' + newContent;
|
|
1612
|
+
}
|
|
1613
|
+
|
|
1614
|
+
// 'merge' strategy - try to avoid duplicates
|
|
1615
|
+
const existingSections = new Set(
|
|
1616
|
+
existingContent.match(/^## .+$/gm)?.map(s => s.toLowerCase()) || []
|
|
1617
|
+
);
|
|
1618
|
+
|
|
1619
|
+
const newSections = newContent.split(/(?=^## )/m);
|
|
1620
|
+
const filteredSections = newSections.filter(section => {
|
|
1621
|
+
const header = section.match(/^## .+$/m)?.[0]?.toLowerCase();
|
|
1622
|
+
return !header || !existingSections.has(header);
|
|
1623
|
+
});
|
|
1624
|
+
|
|
1625
|
+
if (filteredSections.length === 0) {
|
|
1626
|
+
return existingContent;
|
|
1627
|
+
}
|
|
1628
|
+
|
|
1629
|
+
return existingContent.trim() + '\n\n---\n\n# Added by Universal Dev Standards\n\n' + filteredSections.join('\n');
|
|
1630
|
+
}
|
|
1631
|
+
|
|
1632
|
+
/**
|
|
1633
|
+
* Write integration file
|
|
1634
|
+
* @param {string} tool - Tool name
|
|
1635
|
+
* @param {Object} config - Integration configuration
|
|
1636
|
+
* @param {string} projectPath - Project root path
|
|
1637
|
+
* @returns {Object} Result with success status
|
|
1638
|
+
*/
|
|
1639
|
+
export function writeIntegrationFile(tool, config, projectPath) {
|
|
1640
|
+
const TOOL_FILES = {
|
|
1641
|
+
cursor: '.cursorrules',
|
|
1642
|
+
windsurf: '.windsurfrules',
|
|
1643
|
+
cline: '.clinerules',
|
|
1644
|
+
copilot: '.github/copilot-instructions.md',
|
|
1645
|
+
antigravity: 'INSTRUCTIONS.md'
|
|
1646
|
+
};
|
|
1647
|
+
|
|
1648
|
+
const fileName = TOOL_FILES[tool];
|
|
1649
|
+
if (!fileName) {
|
|
1650
|
+
return { success: false, error: `Unknown tool: ${tool}` };
|
|
1651
|
+
}
|
|
1652
|
+
|
|
1653
|
+
const filePath = join(projectPath, fileName);
|
|
1654
|
+
const dirPath = dirname(filePath);
|
|
1655
|
+
|
|
1656
|
+
// Ensure directory exists
|
|
1657
|
+
if (!existsSync(dirPath)) {
|
|
1658
|
+
mkdirSync(dirPath, { recursive: true });
|
|
1659
|
+
}
|
|
1660
|
+
|
|
1661
|
+
try {
|
|
1662
|
+
let content = generateIntegrationContent({ ...config, tool });
|
|
1663
|
+
|
|
1664
|
+
// Handle merge if file exists
|
|
1665
|
+
if (existsSync(filePath) && config.mergeStrategy) {
|
|
1666
|
+
const existingContent = readFileSync(filePath, 'utf-8');
|
|
1667
|
+
content = mergeRules(existingContent, content, config.mergeStrategy);
|
|
1668
|
+
}
|
|
1669
|
+
|
|
1670
|
+
writeFileSync(filePath, content);
|
|
1671
|
+
return { success: true, path: filePath };
|
|
1672
|
+
} catch (error) {
|
|
1673
|
+
return { success: false, error: error.message };
|
|
1674
|
+
}
|
|
1675
|
+
}
|
|
1676
|
+
|
|
1677
|
+
/**
|
|
1678
|
+
* Check if integration file exists
|
|
1679
|
+
* @param {string} tool - Tool name
|
|
1680
|
+
* @param {string} projectPath - Project root path
|
|
1681
|
+
* @returns {boolean} True if file exists
|
|
1682
|
+
*/
|
|
1683
|
+
export function integrationFileExists(tool, projectPath) {
|
|
1684
|
+
const TOOL_FILES = {
|
|
1685
|
+
cursor: '.cursorrules',
|
|
1686
|
+
windsurf: '.windsurfrules',
|
|
1687
|
+
cline: '.clinerules',
|
|
1688
|
+
copilot: '.github/copilot-instructions.md',
|
|
1689
|
+
antigravity: 'INSTRUCTIONS.md'
|
|
1690
|
+
};
|
|
1691
|
+
|
|
1692
|
+
const fileName = TOOL_FILES[tool];
|
|
1693
|
+
return fileName && existsSync(join(projectPath, fileName));
|
|
1694
|
+
}
|