@vincent119/go-copilot-rules 1.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.
@@ -0,0 +1,243 @@
1
+ # Go 開發規範(模組化版本)
2
+
3
+ ## 🚀 快速開始(1 分鐘)
4
+
5
+ ```bash
6
+ # 方法 1:NPX 一鍵安裝(推薦)✨
7
+ npx @vincent119/go-copilot-rules
8
+
9
+ # 方法 2:快速安裝腳本(無需 npm)
10
+ bash <(curl -s https://raw.githubusercontent.com/vincent119/copilot-rules-kit/main/scripts/quick-install.sh)
11
+
12
+ # 方法 3:進階安裝(支援更多選項)
13
+ git clone https://github.com/vincent119/copilot-rules-kit.git
14
+ cd copilot-rules-kit
15
+ ./scripts/install-skills.sh --vscode
16
+
17
+ # 方法 4:只安裝特定 Skills
18
+ npx @vincent119/go-copilot-rules --skills "go-ddd,go-grpc,go-testing-advanced"
19
+ ```
20
+
21
+ **測試安裝**:在 VS Code Copilot Chat 輸入「如何實作 DDD Aggregate Root?」應該會觸發 `go-ddd` Skill。
22
+
23
+ 📖 **完整安裝指南**:[INSTALLATION.md](INSTALLATION.md) - 包含 Git Submodule、Cursor、JetBrains 等方式
24
+
25
+ ---
26
+
27
+ ## 概述
28
+
29
+ 本目錄包含 **Go 開發規範的模組化拆分版本**,將原本的三個大型指南檔案(總計 ~7,500 tokens)拆分為:
30
+
31
+ - **1 個輕量核心規範**(~2,500 tokens,always-on)
32
+ - **12 個專業 Skills**(每個 500-1,500 tokens,按需載入)
33
+
34
+ **預期效益**:節省 **60-70% 的 token 消耗**,從 7,500 降至 2,000-4,500(視使用場景)。
35
+
36
+ ---
37
+
38
+ ## 目錄結構
39
+
40
+ ```
41
+ .agent_agy/
42
+ ├── README.md # 本文件
43
+ ├── INSTALLATION.md # 安裝指南(如何在不同 IDE/CLI 中使用)
44
+ ├── SKILLS_INDEX.md # Skills 索引與使用指南
45
+ ├── rules/
46
+ │ └── go-core.copilot-instructions.md # 核心規範(always-on)
47
+ └── skills/
48
+ ├── go-ddd/SKILL.md # DDD 架構設計
49
+ ├── go-grpc/SKILL.md # gRPC 完整規範
50
+ ├── go-testing-advanced/SKILL.md # 進階測試策略
51
+ ├── go-database/SKILL.md # Database Migration 與 ORM
52
+ ├── go-observability/SKILL.md # 日誌與可觀測性
53
+ ├── go-graceful-shutdown/SKILL.md # 優雅關機模式
54
+ ├── go-http-advanced/SKILL.md # HTTP 進階實作
55
+ ├── go-api-design/SKILL.md # API 設計與版本管理
56
+ ├── go-dependency-injection/SKILL.md # 依賴注入模式
57
+ ├── go-configuration/SKILL.md # 設定管理
58
+ ├── go-ci-tooling/SKILL.md # CI/CD 與工具配置
59
+ ├── go-domain-events/SKILL.md # Domain Events 實作
60
+ └── go-examples/SKILL.md # 實作範例庫
61
+ ```
62
+
63
+ ---
64
+
65
+ ## 核心概念
66
+
67
+ ### Always-On 核心規範
68
+
69
+ **檔案**:`rules/go-core.copilot-instructions.md`
70
+
71
+ **包含內容**:
72
+ - Copilot 產生守則(導入、錯誤處理、函式設計)
73
+ - 基礎錯誤處理模式(`fmt.Errorf` 與 `errors.Is/As`)
74
+ - Functional Options Pattern
75
+ - JSON/Struct Tag 規範
76
+ - 命名慣例與註解規範
77
+
78
+ **觸發時機**:所有 Go 程式碼編輯時自動載入
79
+
80
+ **Token 消耗**:~2,500 tokens
81
+
82
+ ---
83
+
84
+ ### 按需載入 Skills
85
+
86
+ **機制**:透過檔案中的 YAML frontmatter `description` 欄位(包含豐富的關鍵字)觸發載入
87
+
88
+ **範例**:
89
+ ```yaml
90
+ ---
91
+ description: |
92
+ Go DDD 架構設計:Bounded Context、Aggregate Root、Repository Pattern、
93
+ Entity、Value Object、Domain Service。
94
+
95
+ **適用場景**:設計 DDD 架構、建立 Aggregate、實作 Repository Pattern。
96
+
97
+ **關鍵字**:ddd, domain driven design, aggregate, entity, value object, repository
98
+ ---
99
+ ```
100
+
101
+ **觸發時機**:當你的問題或程式碼包含相關關鍵字時,Copilot 自動載入對應 Skill
102
+
103
+ ---
104
+
105
+ ## 使用指南
106
+
107
+ ### 何時使用核心規範?
108
+
109
+ **永遠啟用**,適用於所有 Go 程式碼:
110
+ - 撰寫任何 Go 函式、結構體
111
+ - 處理錯誤
112
+ - 設計 API(Functional Options)
113
+ - 定義 JSON 模型
114
+
115
+ ### 何時觸發 Skills?
116
+
117
+ | 場景 | 觸發的 Skills |
118
+ |-----------------------|----------------------------------------|
119
+ | 設計 DDD 架構 | `go-ddd` |
120
+ | 實作 gRPC 服務 | `go-grpc`、`go-graceful-shutdown` |
121
+ | 撰寫單元測試 | `go-testing-advanced` |
122
+ | Database Migration | `go-database` |
123
+ | 實作結構化日誌 | `go-observability` |
124
+ | HTTP Client 重試策略 | `go-http-advanced` |
125
+ | 設計 RESTful API | `go-api-design`、`go-http-advanced` |
126
+ | 使用 Fx/Wire | `go-dependency-injection` |
127
+ | 設定管理(Viper) | `go-configuration` |
128
+ | 撰寫 Makefile | `go-ci-tooling` |
129
+ | 實作 Domain Events | `go-domain-events`、`go-ddd` |
130
+ | 參考實作範例 | `go-examples` |
131
+
132
+ 💡 **提示**:查看 [SKILLS_INDEX.md](SKILLS_INDEX.md) 了解每個 Skill 的詳細觸發關鍵字
133
+
134
+ ---
135
+
136
+ ## Token 節省效益
137
+
138
+ ### 場景分析
139
+
140
+ | 場景 | 原始 Token | 模組化 Token | 節省比例 |
141
+ |-----------------------|------------|--------------|----------|
142
+ | 簡單函式撰寫 | 7,500 | 2,500 | 67% |
143
+ | DDD 架構設計 | 7,500 | 4,000 | 47% |
144
+ | gRPC + 測試 | 7,500 | 4,500 | 40% |
145
+ | HTTP API + Database | 7,500 | 5,000 | 33% |
146
+ | 完整專案(多場景) | 7,500 | 6,000 | 20% |
147
+
148
+ **平均節省**:**60-70%**(大部分場景)
149
+
150
+ ---
151
+
152
+ ## 遷移指南
153
+
154
+ ### 從原始檔案遷移
155
+
156
+ **原始檔案**(保持不動):
157
+ - `go.copilot-instructions.md`(~4,000 tokens)
158
+ - `go2.copilot-instructions.md`(~3,000 tokens)
159
+ - `go3.copilot-instructions.md`(~500 tokens)
160
+
161
+ **新架構**:
162
+ - `.agent_agy/rules/go-core.copilot-instructions.md`(核心)
163
+ - `.agent_agy/skills/...`(專業領域)
164
+
165
+ ### 並行使用(過渡期)
166
+
167
+ 你可以同時保留原始檔案與新架構:
168
+ 1. 原始檔案仍會載入(全部內容)
169
+ 2. 新 Skills 會在包含關鍵字時載入
170
+ 3. 若覺得新架構有效,可停用原始檔案(重新命名為 `.md.bak`)
171
+
172
+ ### 完全遷移
173
+
174
+ 停用原始檔案:
175
+ ```bash
176
+ cd /Users/vincent/Documents/git_home/vin/copilot-rules-kit
177
+ mv go.copilot-instructions.md go.copilot-instructions.md.bak
178
+ mv go2.copilot-instructions.md go2.copilot-instructions.md.bak
179
+ mv go3.copilot-instructions.md go3.copilot-instructions.md.bak
180
+ ```
181
+
182
+ ---
183
+
184
+ ## Skills 維護
185
+
186
+ ### 新增 Skill
187
+
188
+ 1. 建立目錄:`.agent_agy/skills/<skill-name>/`
189
+ 2. 建立檔案:`SKILL.md`
190
+ 3. 包含 YAML frontmatter(description 含豐富關鍵字)
191
+ 4. 更新 `SKILLS_INDEX.md`
192
+
193
+ ### 更新 Skill
194
+
195
+ - 直接編輯對應的 `SKILL.md`
196
+ - 若更改關鍵字,同步更新 `SKILLS_INDEX.md`
197
+
198
+ ### 刪除 Skill
199
+
200
+ - 刪除對應目錄
201
+ - 從 `SKILLS_INDEX.md` 移除
202
+
203
+ ---
204
+
205
+ ## 常見問題
206
+
207
+ ### Q: 核心規範會與 Skills 衝突嗎?
208
+
209
+ **A**: 不會。核心規範包含基礎規則,Skills 提供深入細節與進階主題。它們互補而非重複。
210
+
211
+ ### Q: 如何確保 Skill 被觸發?
212
+
213
+ **A**: 在你的問題或程式碼中包含 Skill 的關鍵字。例如:
214
+ - "如何設計 DDD Repository?" → 觸發 `go-ddd`
215
+ - "實作 gRPC Interceptor" → 觸發 `go-grpc`
216
+
217
+ ### Q: 可以手動指定載入 Skill 嗎?
218
+
219
+ **A**: 無法直接指定,但可以在問題中包含關鍵字引導 Copilot。例如:
220
+ - "使用 Outbox Pattern 實作 Domain Events"
221
+
222
+ ### Q: 為何不全部合併為一個檔案?
223
+
224
+ **A**: 單一大檔案會造成:
225
+ - 每次都載入全部內容(浪費 token)
226
+ - 難以維護與更新
227
+ - 難以針對特定場景優化
228
+
229
+ ---
230
+
231
+ ## 授權
232
+
233
+ 本規範遵循專案根目錄的 LICENSE 授權。
234
+
235
+ ---
236
+
237
+ ## 貢獻
238
+
239
+ 歡迎提交 Issue 或 Pull Request 改進規範!
240
+
241
+ **參考資源**:
242
+ - [VS Code Copilot Skills 文件](https://code.visualstudio.com/docs/copilot/copilot-customization)
243
+ - [原始 Go 指南](../go.copilot-instructions.md)