universal-dev-standards 6.14.0-beta.3 → 6.14.0-beta.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (39) hide show
  1. package/bundled/ai/standards/ai-response-navigation.ai.yaml +43 -3
  2. package/bundled/ai/standards/checkin-standards.ai.yaml +25 -6
  3. package/bundled/ai/standards/pipeline-security-gates.ai.yaml +5 -1
  4. package/bundled/core/ai-response-navigation.md +128 -12
  5. package/bundled/extensions/frameworks/fat-free-patterns.md +937 -0
  6. package/bundled/extensions/languages/csharp-style.md +464 -0
  7. package/bundled/extensions/languages/php/fat-free-patterns.md +915 -0
  8. package/bundled/extensions/languages/php/php-style.md +693 -0
  9. package/bundled/extensions/languages/php-style.md +700 -0
  10. package/bundled/extensions/locales/zh-cn.md +717 -0
  11. package/bundled/extensions/locales/zh-tw.md +717 -0
  12. package/bundled/locales/COVERAGE.md +5 -4
  13. package/bundled/locales/zh-CN/CHANGELOG.md +27 -3
  14. package/bundled/locales/zh-CN/README.md +2 -2
  15. package/bundled/locales/zh-CN/SECURITY.md +1 -1
  16. package/bundled/locales/zh-CN/core/ai-response-navigation.md +110 -12
  17. package/bundled/locales/zh-CN/skills/README.md +1 -0
  18. package/bundled/locales/zh-CN/skills/comprehension-ladder/SKILL.md +289 -0
  19. package/bundled/locales/zh-CN/skills/comprehension-ladder/eval-cases.md +261 -0
  20. package/bundled/locales/zh-TW/CHANGELOG.md +27 -3
  21. package/bundled/locales/zh-TW/README.md +2 -2
  22. package/bundled/locales/zh-TW/SECURITY.md +1 -1
  23. package/bundled/locales/zh-TW/core/ai-response-navigation.md +110 -12
  24. package/bundled/locales/zh-TW/skills/README.md +1 -0
  25. package/bundled/locales/zh-TW/skills/comprehension-ladder/SKILL.md +289 -0
  26. package/bundled/locales/zh-TW/skills/comprehension-ladder/eval-cases.md +261 -0
  27. package/bundled/skills/README.md +1 -0
  28. package/bundled/skills/comprehension-ladder/SKILL.md +283 -0
  29. package/bundled/skills/comprehension-ladder/eval-cases.md +255 -0
  30. package/package.json +2 -2
  31. package/src/commands/init.js +29 -9
  32. package/src/commands/update.js +3 -2
  33. package/src/installers/standards-installer.js +16 -23
  34. package/src/reconciler/plan-executor.js +10 -11
  35. package/src/uninstallers/hook-uninstaller.js +5 -3
  36. package/src/utils/copier.js +57 -0
  37. package/src/utils/git-hooks.js +8 -4
  38. package/src/utils/locale.js +19 -0
  39. package/standards-registry.json +21 -7
@@ -0,0 +1,464 @@
1
+ # C# Coding Style Guide
2
+ # C# 程式碼風格指南
3
+
4
+ **Version**: 1.0.1
5
+ **Last Updated**: 2025-12-05
6
+ **Applicability**: All C# projects
7
+ **適用範圍**: 所有 C# 專案
8
+
9
+ ---
10
+
11
+ ## Purpose | 目的
12
+
13
+ This guide defines C# coding conventions to ensure consistent, readable, and maintainable code across the team.
14
+
15
+ 本指南定義 C# 編碼慣例,確保團隊程式碼的一致性、可讀性與可維護性。
16
+
17
+ ---
18
+
19
+ ## Naming Conventions | 命名慣例
20
+
21
+ ### Summary Table | 總覽表
22
+
23
+ | Element | Style | Example |
24
+ |---------|-------|---------|
25
+ | Namespace | PascalCase | `YourProject.Application` |
26
+ | Class | PascalCase | `UserService` |
27
+ | Interface | IPascalCase | `IUserRepository` |
28
+ | Method | PascalCase | `GetUserAsync` |
29
+ | Property | PascalCase | `UserName` |
30
+ | Event | PascalCase | `OnUserCreated` |
31
+ | Public Field | PascalCase | `MaxRetryCount` |
32
+ | Private Field | _camelCase | `_userRepository` |
33
+ | Parameter | camelCase | `userId` |
34
+ | Local Variable | camelCase | `currentUser` |
35
+ | Constant | UPPER_SNAKE_CASE | `MAX_RETRY_COUNT` |
36
+ | Enum Type | PascalCase | `UserRole` |
37
+ | Enum Value | PascalCase | `Administrator` |
38
+
39
+ ### Detailed Rules | 詳細規則
40
+
41
+ #### Classes & Interfaces | 類別與介面
42
+ ```csharp
43
+ // ✅ 正確
44
+ public class UserService { }
45
+ public interface IUserRepository { }
46
+ public abstract class BaseController { }
47
+
48
+ // ❌ 錯誤
49
+ public class userService { } // 應使用 PascalCase
50
+ public interface UserRepository { } // 介面應以 I 開頭
51
+ ```
52
+
53
+ #### Private Fields | 私有欄位
54
+ ```csharp
55
+ // ✅ 正確
56
+ private readonly IUserRepository _userRepository;
57
+ private int _retryCount;
58
+ private bool _isInitialized;
59
+
60
+ // ❌ 錯誤
61
+ private readonly IUserRepository userRepository; // 缺少底線前綴
62
+ private int m_retryCount; // 匈牙利命名法
63
+ private bool isInitialized; // 缺少底線前綴
64
+ ```
65
+
66
+ #### Constants | 常數
67
+ ```csharp
68
+ // ✅ 正確
69
+ public const int MAX_RETRY_COUNT = 3;
70
+ public const string DEFAULT_CONNECTION_STRING = "Server=...";
71
+ private const int CACHE_DURATION_SECONDS = 300;
72
+
73
+ // ❌ 錯誤
74
+ public const int MaxRetryCount = 3; // 應使用 UPPER_SNAKE_CASE
75
+ public const int maxRetryCount = 3; // 應使用 UPPER_SNAKE_CASE
76
+ ```
77
+
78
+ ---
79
+
80
+ ## Documentation | 文件註解
81
+
82
+ ### XML Documentation | XML 文件註解
83
+
84
+ All public APIs MUST have XML documentation.
85
+ 所有公開 API 必須有 XML 文件註解。
86
+
87
+ ```csharp
88
+ /// <summary>
89
+ /// 根據使用者 ID 取得使用者資訊
90
+ /// </summary>
91
+ /// <param name="userId">使用者的唯一識別碼</param>
92
+ /// <returns>使用者實體,若不存在則回傳 null</returns>
93
+ /// <exception cref="ArgumentException">當 userId 為空時拋出</exception>
94
+ /// <example>
95
+ /// <code>
96
+ /// var user = await userService.GetUserAsync(123);
97
+ /// if (user != null)
98
+ /// {
99
+ /// Console.WriteLine(user.Name);
100
+ /// }
101
+ /// </code>
102
+ /// </example>
103
+ public async Task<User?> GetUserAsync(int userId)
104
+ {
105
+ if (userId <= 0)
106
+ throw new ArgumentException("User ID must be positive", nameof(userId));
107
+
108
+ return await _userRepository.GetByIdAsync(userId);
109
+ }
110
+ ```
111
+
112
+ ### Comment Language | 註解語言
113
+
114
+ - **XML Documentation**: Traditional Chinese (繁體中文)
115
+ - **Inline Comments**: Traditional Chinese (繁體中文)
116
+ - **TODO/FIXME**: English with Traditional Chinese description
117
+
118
+ ```csharp
119
+ // ✅ 正確
120
+ /// <summary>驗證使用者權限</summary>
121
+ public bool HasPermission(string userId)
122
+ {
123
+ // 檢查使用者是否在白名單中
124
+ return _whitelist.Contains(userId);
125
+ }
126
+
127
+ // TODO: Implement caching - 需實作快取機制以提升效能
128
+ ```
129
+
130
+ ---
131
+
132
+ ## Code Structure | 程式碼結構
133
+
134
+ ### Method Length | 方法長度
135
+
136
+ - **Maximum**: 50 lines (excluding blank lines and comments)
137
+ - **Recommended**: 20-30 lines
138
+ - **最大**: 50 行(不含空行與註解)
139
+ - **建議**: 20-30 行
140
+
141
+ ```csharp
142
+ // ✅ 正確:拆分成多個小方法
143
+ public async Task<ReviewResult> ProcessReviewAsync(Message message)
144
+ {
145
+ ValidateMessage(message);
146
+ var whitelist = await LoadWhitelistAsync(message.CustId);
147
+ var matchResult = CheckWhitelistMatch(message, whitelist);
148
+ return CreateReviewResult(message, matchResult);
149
+ }
150
+
151
+ // ❌ 錯誤:方法過長,應該拆分
152
+ public async Task<ReviewResult> ProcessReviewAsync(Message message)
153
+ {
154
+ // ... 超過 50 行的程式碼 ...
155
+ }
156
+ ```
157
+
158
+ ### Nesting Depth | 巢狀深度
159
+
160
+ - **Maximum**: 3 levels
161
+ - **Recommended**: 2 levels
162
+ - **最大**: 3 層
163
+ - **建議**: 2 層
164
+
165
+ ```csharp
166
+ // ✅ 正確:使用 early return 減少巢狀
167
+ public async Task<User?> GetActiveUserAsync(int userId)
168
+ {
169
+ var user = await _repository.GetByIdAsync(userId);
170
+ if (user == null)
171
+ return null;
172
+
173
+ if (!user.IsActive)
174
+ return null;
175
+
176
+ return user;
177
+ }
178
+
179
+ // ❌ 錯誤:巢狀過深
180
+ public async Task<User?> GetActiveUserAsync(int userId)
181
+ {
182
+ var user = await _repository.GetByIdAsync(userId);
183
+ if (user != null)
184
+ {
185
+ if (user.IsActive)
186
+ {
187
+ if (user.IsVerified)
188
+ {
189
+ if (user.HasPermission) // 第 4 層巢狀
190
+ {
191
+ return user;
192
+ }
193
+ }
194
+ }
195
+ }
196
+ return null;
197
+ }
198
+ ```
199
+
200
+ ---
201
+
202
+ ## Async/Await | 非同步處理
203
+
204
+ ### Naming Convention | 命名慣例
205
+
206
+ Async methods MUST end with `Async` suffix.
207
+ 非同步方法必須以 `Async` 結尾。
208
+
209
+ ```csharp
210
+ // ✅ 正確
211
+ public async Task<User> GetUserAsync(int id) { }
212
+ public async Task SaveChangesAsync() { }
213
+ public async Task<IEnumerable<Message>> GetPendingMessagesAsync() { }
214
+
215
+ // ❌ 錯誤
216
+ public async Task<User> GetUser(int id) { } // 缺少 Async 後綴
217
+ ```
218
+
219
+ ### Best Practices | 最佳實踐
220
+
221
+ ```csharp
222
+ // ✅ 正確:使用 async/await
223
+ public async Task<User> GetUserAsync(int id)
224
+ {
225
+ return await _repository.GetByIdAsync(id);
226
+ }
227
+
228
+ // ✅ 正確:多個非同步操作並行
229
+ public async Task<(User User, List<Message> Messages)> GetUserDataAsync(int userId)
230
+ {
231
+ var userTask = _userRepository.GetByIdAsync(userId);
232
+ var messagesTask = _messageRepository.GetByUserIdAsync(userId);
233
+
234
+ await Task.WhenAll(userTask, messagesTask);
235
+
236
+ return (await userTask, await messagesTask);
237
+ }
238
+
239
+ // ❌ 錯誤:阻塞呼叫
240
+ public User GetUser(int id)
241
+ {
242
+ return _repository.GetByIdAsync(id).Result; // 可能造成死鎖
243
+ }
244
+ ```
245
+
246
+ ---
247
+
248
+ ## Resource Management | 資源管理
249
+
250
+ ### Using Statement | Using 語句
251
+
252
+ ```csharp
253
+ // ✅ 正確:使用 using 語句
254
+ await using var connection = new SqlConnection(connectionString);
255
+ await connection.OpenAsync();
256
+
257
+ // ✅ 正確:使用 using 宣告 (C# 8.0+)
258
+ using var reader = new StreamReader(path);
259
+ var content = await reader.ReadToEndAsync();
260
+
261
+ // ❌ 錯誤:未正確釋放資源
262
+ var connection = new SqlConnection(connectionString);
263
+ await connection.OpenAsync();
264
+ // ... 如果發生例外,connection 不會被釋放
265
+ ```
266
+
267
+ ---
268
+
269
+ ## Nullable Reference Types | 可空參考型別
270
+
271
+ ### Enable Nullable Context | 啟用可空內容
272
+
273
+ ```xml
274
+ <!-- In .csproj file -->
275
+ <PropertyGroup>
276
+ <Nullable>enable</Nullable>
277
+ </PropertyGroup>
278
+ ```
279
+
280
+ ### Usage | 使用方式
281
+
282
+ ```csharp
283
+ // ✅ 正確:明確標示可空性
284
+ public async Task<User?> GetUserAsync(int userId)
285
+ {
286
+ return await _repository.GetByIdAsync(userId);
287
+ }
288
+
289
+ public void ProcessUser(User user) // 不可為 null
290
+ {
291
+ // 不需要 null 檢查
292
+ Console.WriteLine(user.Name);
293
+ }
294
+
295
+ // ✅ 正確:使用 null 合併運算子
296
+ var userName = user?.Name ?? "Unknown";
297
+
298
+ // ✅ 正確:使用 null 條件運算子
299
+ var length = user?.Name?.Length ?? 0;
300
+ ```
301
+
302
+ ---
303
+
304
+ ## Prohibited Practices | 禁止行為
305
+
306
+ ### 1. Pinyin Naming | 拼音命名
307
+
308
+ ```csharp
309
+ // ❌ 絕對禁止
310
+ public class YongHuFuWu { } // 應為 UserService
311
+ public bool yanZhengQuanXian() { } // 應為 ValidatePermission
312
+ private string _baiMingDan; // 應為 _whitelist
313
+ ```
314
+
315
+ ### 2. Hungarian Notation | 匈牙利命名法
316
+
317
+ ```csharp
318
+ // ❌ 禁止
319
+ private string strUserName; // 應為 _userName
320
+ private int iCount; // 應為 _count
321
+ private bool bIsActive; // 應為 _isActive
322
+ ```
323
+
324
+ ### 3. Magic Numbers/Strings | 魔術數字/字串
325
+
326
+ ```csharp
327
+ // ❌ 錯誤
328
+ if (retryCount > 3) { }
329
+ if (status == "APPROVED") { }
330
+
331
+ // ✅ 正確
332
+ private const int MAX_RETRY_COUNT = 3;
333
+ private const string STATUS_APPROVED = "APPROVED";
334
+
335
+ if (retryCount > MAX_RETRY_COUNT) { }
336
+ if (status == STATUS_APPROVED) { }
337
+ ```
338
+
339
+ ### 4. Empty Catch Blocks | 空的 Catch 區塊
340
+
341
+ ```csharp
342
+ // ❌ 禁止
343
+ try
344
+ {
345
+ await ProcessAsync();
346
+ }
347
+ catch (Exception)
348
+ {
349
+ // 吞掉例外,不處理
350
+ }
351
+
352
+ // ✅ 正確
353
+ try
354
+ {
355
+ await ProcessAsync();
356
+ }
357
+ catch (Exception ex)
358
+ {
359
+ _logger.LogError(ex, "Failed to process");
360
+ throw; // 或適當處理
361
+ }
362
+ ```
363
+
364
+ ---
365
+
366
+ ## Code Organization | 程式碼組織
367
+
368
+ ### Class Member Order | 類別成員順序
369
+
370
+ ```csharp
371
+ public class UserService : IUserService
372
+ {
373
+ // 1. Constants | 常數
374
+ private const int MAX_RETRY_COUNT = 3;
375
+
376
+ // 2. Static fields | 靜態欄位
377
+ private static readonly object _lock = new();
378
+
379
+ // 3. Instance fields | 實例欄位
380
+ private readonly IUserRepository _userRepository;
381
+ private readonly ILogger<UserService> _logger;
382
+
383
+ // 4. Constructors | 建構子
384
+ public UserService(IUserRepository userRepository, ILogger<UserService> logger)
385
+ {
386
+ _userRepository = userRepository;
387
+ _logger = logger;
388
+ }
389
+
390
+ // 5. Properties | 屬性
391
+ public int RetryCount { get; private set; }
392
+
393
+ // 6. Public methods | 公開方法
394
+ public async Task<User?> GetUserAsync(int userId)
395
+ {
396
+ // ...
397
+ }
398
+
399
+ // 7. Private methods | 私有方法
400
+ private void ValidateUserId(int userId)
401
+ {
402
+ // ...
403
+ }
404
+ }
405
+ ```
406
+
407
+ ---
408
+
409
+ ## Related Standards | 相關標準
410
+
411
+ - [Anti-Hallucination Standard](../../core/anti-hallucination.md) - AI 協作防幻覺標準
412
+ - [Code Check-in Standards](../../core/checkin-standards.md) - 程式碼簽入檢查點標準
413
+ - [Commit Message Guide](../../core/commit-message-guide.md) - Commit 訊息規範
414
+ - [Traditional Chinese Language Guide](../locales/zh-tw.md) - 繁體中文語言規範
415
+
416
+ ---
417
+
418
+ ## Quick Reference Card | 快速參考卡
419
+
420
+ ```
421
+ ┌─────────────────────────────────────────────────────────┐
422
+ │ C# Naming Conventions │
423
+ ├─────────────────────────────────────────────────────────┤
424
+ │ Class/Method/Property │ PascalCase │ UserService │
425
+ │ Interface │ IPascalCase │ IRepository │
426
+ │ Private Field │ _camelCase │ _userId │
427
+ │ Parameter/Local │ camelCase │ userId │
428
+ │ Constant │ UPPER_SNAKE │ MAX_COUNT │
429
+ ├─────────────────────────────────────────────────────────┤
430
+ │ Limits │
431
+ ├─────────────────────────────────────────────────────────┤
432
+ │ Method Length │ ≤ 50 lines │
433
+ │ Nesting Depth │ ≤ 3 levels │
434
+ ├─────────────────────────────────────────────────────────┤
435
+ │ Prohibited │
436
+ ├─────────────────────────────────────────────────────────┤
437
+ │ ❌ Pinyin naming │ yanZhengQuanXian │
438
+ │ ❌ Hungarian notation │ strUserName, iCount │
439
+ │ ❌ Magic numbers │ if (x > 3) │
440
+ │ ❌ Empty catch │ catch { } │
441
+ └─────────────────────────────────────────────────────────┘
442
+ ```
443
+
444
+ ---
445
+
446
+ ## Version History | 版本歷史
447
+
448
+ | Version | Date | Changes |
449
+ |---------|------|---------|
450
+ | 1.0.1 | 2025-12-05 | Fix related standards paths 修正相關標準連結路徑 |
451
+ | 1.0.0 | 2025-11-25 | Initial C# style guide |
452
+
453
+ ---
454
+
455
+ ## License | 授權
456
+
457
+ This standard is released under [CC BY 4.0](https://creativecommons.org/licenses/by/4.0/).
458
+
459
+ 本標準以 [CC BY 4.0](https://creativecommons.org/licenses/by/4.0/) 授權發布。
460
+
461
+ ---
462
+
463
+ **Maintainer**: Development Team
464
+ **維護者**: 開發團隊