universal-dev-standards 5.1.0-beta.6 → 5.1.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.
Files changed (108) hide show
  1. package/README.md +6 -0
  2. package/bin/uds.js +14 -0
  3. package/bundled/ai/standards/agent-communication-protocol.ai.yaml +34 -0
  4. package/bundled/ai/standards/anti-sycophancy-prompting.ai.yaml +111 -0
  5. package/bundled/ai/standards/capability-declaration.ai.yaml +113 -0
  6. package/bundled/ai/standards/circuit-breaker.ai.yaml +93 -0
  7. package/bundled/ai/standards/developer-memory.ai.yaml +13 -0
  8. package/bundled/ai/standards/dual-phase-output.ai.yaml +108 -0
  9. package/bundled/ai/standards/failure-source-taxonomy.ai.yaml +115 -0
  10. package/bundled/ai/standards/frontend-design-standards.ai.yaml +305 -0
  11. package/bundled/ai/standards/health-check-standards.ai.yaml +140 -0
  12. package/bundled/ai/standards/immutability-first.ai.yaml +112 -0
  13. package/bundled/ai/standards/model-selection.ai.yaml +111 -3
  14. package/bundled/ai/standards/packaging-standards.ai.yaml +142 -0
  15. package/bundled/ai/standards/recovery-recipe-registry.ai.yaml +200 -0
  16. package/bundled/ai/standards/retry-standards.ai.yaml +134 -0
  17. package/bundled/ai/standards/security-decision.ai.yaml +87 -0
  18. package/bundled/ai/standards/skill-standard-alignment-check.ai.yaml +119 -0
  19. package/bundled/ai/standards/standard-admission-criteria.ai.yaml +107 -0
  20. package/bundled/ai/standards/standard-lifecycle-management.ai.yaml +144 -0
  21. package/bundled/ai/standards/timeout-standards.ai.yaml +104 -0
  22. package/bundled/ai/standards/token-budget.ai.yaml +108 -0
  23. package/bundled/ai/standards/translation-lifecycle-standards.ai.yaml +145 -0
  24. package/bundled/core/anti-sycophancy-prompting.md +184 -0
  25. package/bundled/core/capability-declaration.md +59 -0
  26. package/bundled/core/circuit-breaker.md +58 -0
  27. package/bundled/core/developer-memory.md +29 -1
  28. package/bundled/core/dual-phase-output.md +56 -0
  29. package/bundled/core/failure-source-taxonomy.md +72 -0
  30. package/bundled/core/frontend-design-standards.md +474 -0
  31. package/bundled/core/health-check-standards.md +72 -0
  32. package/bundled/core/immutability-first.md +105 -0
  33. package/bundled/core/model-selection.md +80 -0
  34. package/bundled/core/packaging-standards.md +216 -0
  35. package/bundled/core/recovery-recipe-registry.md +69 -0
  36. package/bundled/core/retry-standards.md +62 -0
  37. package/bundled/core/security-decision.md +65 -0
  38. package/bundled/core/skill-standard-alignment-check.md +79 -0
  39. package/bundled/core/standard-admission-criteria.md +84 -0
  40. package/bundled/core/standard-lifecycle-management.md +94 -0
  41. package/bundled/core/timeout-standards.md +63 -0
  42. package/bundled/core/token-budget.md +58 -0
  43. package/bundled/core/translation-lifecycle-standards.md +162 -0
  44. package/bundled/locales/zh-CN/CHANGELOG.md +51 -3
  45. package/bundled/locales/zh-CN/README.md +1 -1
  46. package/bundled/locales/zh-CN/core/anti-hallucination.md +22 -3
  47. package/bundled/locales/zh-CN/core/anti-sycophancy-prompting.md +192 -0
  48. package/bundled/locales/zh-CN/core/capability-declaration.md +123 -0
  49. package/bundled/locales/zh-CN/core/circuit-breaker.md +106 -0
  50. package/bundled/locales/zh-CN/core/dual-phase-output.md +103 -0
  51. package/bundled/locales/zh-CN/core/failure-source-taxonomy.md +99 -0
  52. package/bundled/locales/zh-CN/core/frontend-design-standards.md +289 -0
  53. package/bundled/locales/zh-CN/core/health-check-standards.md +144 -0
  54. package/bundled/locales/zh-CN/core/immutability-first.md +96 -0
  55. package/bundled/locales/zh-CN/core/packaging-standards.md +224 -0
  56. package/bundled/locales/zh-CN/core/recovery-recipe-registry.md +146 -0
  57. package/bundled/locales/zh-CN/core/retry-standards.md +131 -0
  58. package/bundled/locales/zh-CN/core/security-decision.md +104 -0
  59. package/bundled/locales/zh-CN/core/skill-standard-alignment-check.md +112 -0
  60. package/bundled/locales/zh-CN/core/standard-admission-criteria.md +104 -0
  61. package/bundled/locales/zh-CN/core/standard-lifecycle-management.md +116 -0
  62. package/bundled/locales/zh-CN/core/timeout-standards.md +117 -0
  63. package/bundled/locales/zh-CN/core/token-budget.md +108 -0
  64. package/bundled/locales/zh-CN/core/translation-lifecycle-standards.md +159 -0
  65. package/bundled/locales/zh-TW/CHANGELOG.md +51 -3
  66. package/bundled/locales/zh-TW/README.md +1 -1
  67. package/bundled/locales/zh-TW/core/anti-sycophancy-prompting.md +192 -0
  68. package/bundled/locales/zh-TW/core/capability-declaration.md +111 -0
  69. package/bundled/locales/zh-TW/core/circuit-breaker.md +111 -0
  70. package/bundled/locales/zh-TW/core/dual-phase-output.md +132 -0
  71. package/bundled/locales/zh-TW/core/failure-source-taxonomy.md +146 -0
  72. package/bundled/locales/zh-TW/core/frontend-design-standards.md +460 -0
  73. package/bundled/locales/zh-TW/core/health-check-standards.md +144 -0
  74. package/bundled/locales/zh-TW/core/immutability-first.md +159 -0
  75. package/bundled/locales/zh-TW/core/packaging-standards.md +224 -0
  76. package/bundled/locales/zh-TW/core/recovery-recipe-registry.md +146 -0
  77. package/bundled/locales/zh-TW/core/retry-standards.md +140 -0
  78. package/bundled/locales/zh-TW/core/security-decision.md +120 -0
  79. package/bundled/locales/zh-TW/core/skill-standard-alignment-check.md +112 -0
  80. package/bundled/locales/zh-TW/core/standard-admission-criteria.md +104 -0
  81. package/bundled/locales/zh-TW/core/standard-lifecycle-management.md +116 -0
  82. package/bundled/locales/zh-TW/core/timeout-standards.md +117 -0
  83. package/bundled/locales/zh-TW/core/token-budget.md +143 -0
  84. package/bundled/locales/zh-TW/core/translation-lifecycle-standards.md +159 -0
  85. package/bundled/skills/e2e-assistant/SKILL.md +19 -5
  86. package/bundled/skills/testing-guide/SKILL.md +5 -0
  87. package/bundled/skills/testing-guide/test-skeleton-templates.md +316 -0
  88. package/package.json +2 -1
  89. package/src/commands/check.js +6 -0
  90. package/src/commands/config.js +9 -0
  91. package/src/commands/init.js +97 -46
  92. package/src/commands/mcp.js +26 -0
  93. package/src/commands/run-intent.js +66 -0
  94. package/src/commands/update.js +41 -4
  95. package/src/core/command-router.js +85 -0
  96. package/src/core/project-config.js +91 -0
  97. package/src/flows/init-flow.js +6 -1
  98. package/src/i18n/messages.js +6 -6
  99. package/src/mcp/__tests__/server.test.js +251 -0
  100. package/src/mcp/server.js +352 -0
  101. package/src/prompts/init.js +157 -1
  102. package/src/reconciler/actual-state-scanner.js +24 -0
  103. package/src/uninstallers/hook-uninstaller.js +32 -1
  104. package/src/utils/detect-self-adoption.js +173 -0
  105. package/src/utils/e2e-analyzer.js +88 -5
  106. package/src/utils/e2e-detector.js +73 -1
  107. package/src/utils/integration-generator.js +22 -3
  108. package/standards-registry.json +203 -4
@@ -0,0 +1,305 @@
1
+ # Frontend Design Standards - AI Optimized
2
+ # Source: core/frontend-design-standards.md
3
+ # Based on: DEC-029 (awesome-design-md, MIT), DEC-030 (OpenAI Frontend Guide)
4
+ # Version: 1.0.0
5
+
6
+ id: frontend-design-standards
7
+ meta:
8
+ version: "1.0.0"
9
+ updated: "2026-04-13"
10
+ source: core/frontend-design-standards.md
11
+ description: |
12
+ DESIGN.md 前端設計標準:9 段結構、語義色彩 token、字體角色、
13
+ 間距比例、UI 硬性約束與 anti-pattern 清單。
14
+ 適用所有含前端介面的專案。
15
+
16
+ # DESIGN.md 必填 9 段結構
17
+ design_md_sections:
18
+ - id: visual-theme
19
+ name: Visual Theme & Mood
20
+ required: true
21
+ fields:
22
+ theme: "一行風格描述(例:Minimal, professional, data-dense)"
23
+ mood: "情感品質(例:Calm, focused, trustworthy)"
24
+ inspiration: "參考產品或設計風格(例:Linear, Stripe dashboard)"
25
+ dark_mode: "primary | secondary | unsupported"
26
+
27
+ - id: color-palette
28
+ name: Color Palette
29
+ required: true
30
+ description: "語義色彩 token 系統。所有 5 個核心 token 均為必填。"
31
+ required_tokens: [background, surface, primary-text, muted-text, accent]
32
+ optional_tokens: [error, warning, success, border, overlay]
33
+
34
+ - id: typography
35
+ name: Typography
36
+ required: true
37
+ description: "字體家族與排版角色層次。最多 2 個字體家族。"
38
+ required_roles: [display, headline, body, caption]
39
+ constraint: "max_font_families: 2"
40
+
41
+ - id: component-styling
42
+ name: Component Styling
43
+ required: true
44
+ description: "UI 元件視覺規則:邊框圓角、按鈕、輸入框、卡片"
45
+ required_fields: [border_radius_scale, button_variants, input_styling, card_styling]
46
+
47
+ - id: layout-spacing
48
+ name: Layout & Spacing
49
+ required: true
50
+ description: "間距比例(8px 基底,7 個步進值)與網格定義"
51
+ required_tokens: [space-1, space-2, space-3, space-4, space-5, space-6, space-8]
52
+ note: "space-7 不存在(刻意跳過以維持視覺節奏)"
53
+
54
+ - id: depth-shadow
55
+ name: Depth & Shadow System
56
+ required: true
57
+ description: "陰影層次系統,至少 3 個 elevation 層級"
58
+ min_elevation_levels: 3
59
+
60
+ - id: design-guidelines
61
+ name: Design Guidelines & Anti-patterns
62
+ required: true
63
+ description: "設計規則與禁止模式清單(約束式 prompting 核心)"
64
+ required_subsections:
65
+ - ui_hard_constraints: "至少 4 條硬性規則"
66
+ - anti_patterns: "至少 5 條禁止模式"
67
+
68
+ - id: responsive
69
+ name: Responsive Behavior
70
+ required: true
71
+ description: "斷點定義與響應式規則,Mobile-first 必填"
72
+ min_breakpoints: 3
73
+ required_approach: mobile-first
74
+
75
+ - id: agent-prompt-refs
76
+ name: Agent Prompt References
77
+ required: true
78
+ description: "AI Agent 快速讀取的設計意圖摘要"
79
+ required_fields: [style_summary, key_constraints, tone]
80
+
81
+ # 語義色彩 5 個必要 token
82
+ semantic_color_tokens:
83
+ required:
84
+ background:
85
+ role: "頁面/App 底色"
86
+ example_dark: "#0A0A0A"
87
+ example_light: "#FFFFFF"
88
+ surface:
89
+ role: "卡片、面板、Modal 底色"
90
+ example_dark: "#1A1A1A"
91
+ example_light: "#F9FAFB"
92
+ primary-text:
93
+ role: "主要正文文字"
94
+ example_dark: "#F5F5F5"
95
+ example_light: "#111827"
96
+ muted-text:
97
+ role: "次要文字、placeholder"
98
+ example_dark: "#888888"
99
+ example_light: "#6B7280"
100
+ accent:
101
+ role: "CTA 按鈕、連結、強調色"
102
+ note: "全站只能有 1 個 accent 色,禁止多個強調色"
103
+ example: "#6366F1"
104
+ naming_convention: kebab-case
105
+ format: hex_with_alpha_optional
106
+
107
+ # 字體角色 4 個必要角色
108
+ typography_roles:
109
+ required:
110
+ display:
111
+ size: "48px+"
112
+ weight: 700
113
+ line_height: 1.1
114
+ usage: "英雄標題、Splash 文字"
115
+ headline:
116
+ size: "24–32px"
117
+ weight: 600
118
+ line_height: 1.3
119
+ usage: "區段標題、卡片標題"
120
+ body:
121
+ size: "16px"
122
+ weight: 400
123
+ line_height: 1.6
124
+ usage: "段落、主要內容"
125
+ caption:
126
+ size: "12–14px"
127
+ weight: 400
128
+ line_height: 1.4
129
+ usage: "標籤、Metadata、輔助說明"
130
+ constraint:
131
+ max_font_families: 2
132
+ note: "display + headline 可共用一個字體家族;body + caption 共用另一個(或相同)"
133
+
134
+ # 間距比例(8px 基底,7 個步進值)
135
+ spacing_scale:
136
+ base: 8
137
+ tokens:
138
+ space-1: 4px
139
+ space-2: 8px
140
+ space-3: 16px
141
+ space-4: 24px
142
+ space-5: 32px
143
+ space-6: 48px
144
+ space-8: 64px
145
+ note: "space-7 不存在(刻意跳過)。所有元件間距必須使用這些 token,不得使用任意像素值。"
146
+
147
+ # UI 硬性約束清單(約束式 prompting)
148
+ ui_hard_constraints:
149
+ - id: single-h1
150
+ rule: "每頁最多 1 個 H1"
151
+ rationale: "清晰的內容層次,避免語義模糊"
152
+ - id: max-sections
153
+ rule: "頁面區段不超過 6 個"
154
+ rationale: "防止認知過載"
155
+ - id: max-font-families
156
+ rule: "字體家族最多 2 個"
157
+ rationale: "視覺一致性"
158
+ - id: single-accent
159
+ rule: "強調色最多 1 個,禁止混用多個 accent 色"
160
+ rationale: "防止視覺雜訊"
161
+ - id: max-nesting
162
+ rule: "視覺巢狀最多 3 層"
163
+ rationale: "可讀性與結構清晰度"
164
+ - id: info-hierarchy
165
+ rule: "資訊層次遵循 Hero → Support → Detail → CTA 順序"
166
+ rationale: "Narrative structure,引導使用者注意力"
167
+ - id: touch-targets
168
+ rule: "行動裝置觸控目標最小 44×44px"
169
+ rationale: "無障礙設計基本要求"
170
+
171
+ # 禁止的 UI 反模式
172
+ anti_patterns:
173
+ - id: floating-badge
174
+ name: "浮動徽章(floating badge)"
175
+ description: "徽章脫離內容浮動顯示,無明確歸屬"
176
+ preferred: "使用內嵌 label 或狀態指示器"
177
+ - id: generic-card-layout
178
+ name: "通用卡片堆疊(generic card layout)"
179
+ description: "完全相同的卡片作為主要內容結構,無差異化"
180
+ preferred: "帶有清晰層次的多樣化內容結構"
181
+ - id: dashboard-grid-as-homepage
182
+ name: "首頁儀表板化(dashboard grid as homepage)"
183
+ description: "行銷首頁設計成數據儀表板 Grid 佈局"
184
+ preferred: "敘事型首頁:Hero → Support → CTA 結構"
185
+ - id: competing-ctas
186
+ name: "競爭性 CTA(competing CTAs)"
187
+ description: "同一畫面有多個視覺權重相同的 CTA 按鈕"
188
+ preferred: "1 個主要 CTA,0–1 個次要 CTA"
189
+ - id: color-only-differentiation
190
+ name: "僅用顏色區分(color-only differentiation)"
191
+ description: "只用顏色區分狀態或分類,無其他視覺提示"
192
+ preferred: "顏色搭配圖示、文字標籤或圖案"
193
+ - id: decorative-overload
194
+ name: "裝飾性過載(decorative overload)"
195
+ description: "無資訊傳遞功能的插圖或動畫佔用視覺空間"
196
+ preferred: "移除裝飾元素;優先使用功能性視覺"
197
+ - id: triple-nesting
198
+ name: "三層以上巢狀(triple nesting)"
199
+ description: "視覺層次超過 3 層,導致結構難以閱讀"
200
+ preferred: "扁平化結構,用留白區隔"
201
+ - id: rainbow-accents
202
+ name: "多色強調系統(rainbow accents)"
203
+ description: "同時使用多個強調色(紫色 CTA、橘色徽章、綠色標籤)"
204
+ preferred: "單一 accent 色彩系統,統一視覺語言"
205
+
206
+ # DESIGN.md 存放位置規範
207
+ file_placement:
208
+ filename: "DESIGN.md"
209
+ filename_casing: "exact uppercase"
210
+ location: "project root"
211
+ same_level_as: ["README.md", "CLAUDE.md", "package.json"]
212
+ forbidden_locations: ["docs/", "src/", "assets/", "subdirectories"]
213
+ section_heading_level: "##"
214
+ version_required: true
215
+
216
+ # AI 行為規則
217
+ rules:
218
+ - id: require-design-md
219
+ trigger: "當 AI Agent 開始生成前端 UI 程式碼或設計規格時"
220
+ instruction: |
221
+ 先檢查專案根目錄是否存在 DESIGN.md。
222
+ 若存在,讀取 Section 9(Agent Prompt References)作為快速定向,
223
+ 再依需要讀取其他段落。
224
+ 若不存在,提示使用者先建立 DESIGN.md(可使用 templates/DESIGN.md 模板)。
225
+ priority: required
226
+
227
+ - id: semantic-tokens-only
228
+ trigger: "當 AI Agent 產生包含顏色的前端程式碼時"
229
+ instruction: |
230
+ 使用語義 token 名稱(background, surface, accent 等),
231
+ 不得直接在元件中硬編碼 hex 色值。
232
+ 例:用 `var(--color-accent)` 而非 `#6366F1`。
233
+ priority: required
234
+
235
+ - id: enforce-hard-constraints
236
+ trigger: "當 AI Agent 生成任何頁面或視圖時"
237
+ instruction: |
238
+ 強制執行 UI 硬性約束:
239
+ - 每頁只有 1 個 H1
240
+ - 最多 6 個頁面區段
241
+ - 最多 2 個字體家族
242
+ - 最多 1 個 accent 色
243
+ priority: required
244
+
245
+ - id: reject-anti-patterns
246
+ trigger: "當 AI Agent 生成 UI 結構或元件時"
247
+ instruction: |
248
+ 主動偵測並拒絕以下反模式:
249
+ floating-badge, generic-card-layout, dashboard-grid-as-homepage,
250
+ competing-ctas, color-only-differentiation。
251
+ 若偵測到,提出替代方案。
252
+ priority: required
253
+
254
+ - id: spacing-scale-only
255
+ trigger: "當 AI Agent 生成 CSS 或 layout 相關程式碼時"
256
+ instruction: |
257
+ 所有間距值必須使用標準 space-N token(space-1 到 space-8,無 space-7)。
258
+ 不得使用任意像素值(如 13px, 20px, 37px)。
259
+ priority: recommended
260
+
261
+ - id: narrative-structure
262
+ trigger: "當 AI Agent 生成首頁(Homepage/Landing Page)時"
263
+ instruction: |
264
+ 遵循 Narrative structure:Hero → Support → Detail → CTA。
265
+ 禁止將首頁設計成 Dashboard Grid。
266
+ priority: required
267
+
268
+ # 快速參考表
269
+ quick_reference:
270
+ semantic_tokens:
271
+ columns: ["Token", "角色", "明色範例", "暗色範例"]
272
+ rows:
273
+ - ["background", "頁面底色", "#FFFFFF", "#0A0A0A"]
274
+ - ["surface", "卡片/面板", "#F9FAFB", "#1A1A1A"]
275
+ - ["primary-text", "主要文字", "#111827", "#F5F5F5"]
276
+ - ["muted-text", "次要文字", "#6B7280", "#888888"]
277
+ - ["accent", "強調/CTA", "(專案自訂)", "(專案自訂)"]
278
+ typography_roles:
279
+ columns: ["角色", "大小", "Weight", "Line-height", "用途"]
280
+ rows:
281
+ - ["display", "48px+", "700", "1.1", "英雄標題"]
282
+ - ["headline", "24–32px", "600", "1.3", "區段標題"]
283
+ - ["body", "16px", "400", "1.6", "正文內容"]
284
+ - ["caption", "12–14px", "400", "1.4", "標籤/說明"]
285
+ spacing_scale:
286
+ columns: ["Token", "值", "主要用途"]
287
+ rows:
288
+ - ["space-1", "4px", "圖示內距、緊湊元素"]
289
+ - ["space-2", "8px", "預設元素內距"]
290
+ - ["space-3", "16px", "元件內部間距"]
291
+ - ["space-4", "24px", "區塊間距、網格欄距"]
292
+ - ["space-5", "32px", "元件之間"]
293
+ - ["space-6", "48px", "主要區段之間"]
294
+ - ["space-8", "64px", "頁面層級分隔"]
295
+ anti_patterns:
296
+ columns: ["禁止模式", "說明"]
297
+ rows:
298
+ - ["floating-badge", "浮動徽章,脫離內容無歸屬"]
299
+ - ["generic-card-layout", "無差異化卡片堆疊"]
300
+ - ["dashboard-grid-as-homepage", "首頁儀表板化"]
301
+ - ["competing-ctas", "多個等重 CTA"]
302
+ - ["color-only-differentiation", "僅用顏色區分狀態"]
303
+ - ["decorative-overload", "無功能的裝飾元素"]
304
+ - ["triple-nesting", "超過 3 層視覺巢狀"]
305
+ - ["rainbow-accents", "多色強調系統"]
@@ -0,0 +1,140 @@
1
+ # Health Check Standards - AI Optimized
2
+ # Source: XSPEC-067 (DEC-043 Wave 1 Reliability Pack)
3
+
4
+ standard:
5
+ id: health-check-standards
6
+ name: Health Check Standards
7
+ description: 健康檢查標準 — liveness / readiness / startup 三種 probe、深度 health check、結構化 JSON 回應
8
+
9
+ meta:
10
+ version: "1.0.0"
11
+ updated: "2026-04-17"
12
+ status: trial
13
+ since: "2026-04-17"
14
+ expires: "2026-10-17"
15
+ source: XSPEC-067
16
+ borrowed_from: DEC-043
17
+ description: >
18
+ 業界常見錯誤:把 liveness 和 readiness 混用(健康檢查檢查外部依賴導致連鎖重啟)。
19
+ 本標準明確三種 probe 語意分離、定義深度 health check 的檢查範圍(僅關鍵依賴)、
20
+ 並規範結構化 JSON 回應以便下游自動化處理。與 observability 整合為 RED metric 的 Error 來源之一。
21
+ scope: universal
22
+ industry_reference: "Kubernetes probes, Microsoft eShop health checks, Google SRE Book Ch.6"
23
+
24
+ guidelines:
25
+ - "Liveness probe 不得檢查外部依賴(DB、下游 API),否則會造成連鎖重啟"
26
+ - "Readiness probe 可檢查關鍵外部依賴,但僅關鍵(非全部依賴)"
27
+ - "慢啟動服務應使用 startup probe,啟動完成後交棒給 liveness"
28
+ - "Health check 端點必須回傳結構化 JSON,包含 status / dependencies / timestamp"
29
+ - "Health check 結果應作為 observability 的 Error signal 之一,連續 fail 觸發 incident"
30
+
31
+ probe_types:
32
+ liveness:
33
+ purpose: "服務是否還活著(process 是否卡死)"
34
+ endpoint_suggestion: "GET /health/live"
35
+ checks:
36
+ allowed:
37
+ - "process 是否能回應 HTTP"
38
+ - "內部 event loop 是否可用"
39
+ forbidden:
40
+ - "DB 連線(DB 壞時 liveness 失敗 → pod 重啟 → 啟動更多 client → DB 更壞)"
41
+ - "下游 API(會造成連鎖重啟)"
42
+ - "消息佇列"
43
+ on_fail: "重啟 pod / process"
44
+ failure_threshold: 3
45
+ period_seconds: 10
46
+
47
+ readiness:
48
+ purpose: "是否可接收流量"
49
+ endpoint_suggestion: "GET /health/ready"
50
+ checks:
51
+ allowed:
52
+ - "自身 API 可用"
53
+ - "DB 連線可用(若服務必須依賴 DB 才能工作)"
54
+ - "關鍵下游依賴可用(非全部下游)"
55
+ - "必要的設定 / 憑證已載入"
56
+ forbidden:
57
+ - "非關鍵依賴(避免非關鍵故障造成服務被移出負載均衡)"
58
+ on_fail: "移出負載均衡,不重啟"
59
+ failure_threshold: 3
60
+ period_seconds: 5
61
+
62
+ startup:
63
+ purpose: "啟動期專用,替代慢啟動服務的 liveness"
64
+ endpoint_suggestion: "GET /health/startup"
65
+ checks:
66
+ - "啟動過程所需資源(如快取預熱、index 載入)已完成"
67
+ on_fail: "重啟 pod(啟動超時)"
68
+ handover: "通過後停用,改由 liveness 接手"
69
+ failure_threshold: 30
70
+ period_seconds: 10
71
+
72
+ depth_rules:
73
+ shallow:
74
+ when: "liveness"
75
+ checks: "process 是否可回應,不碰任何外部依賴"
76
+ deep:
77
+ when: "readiness"
78
+ checks:
79
+ - "自身 API 路由可解析"
80
+ - "DB ping 成功(若必須 DB)"
81
+ - "關鍵下游 API ping 成功(非全部)"
82
+ note: "關鍵依賴的定義:沒有它服務就完全無法提供核心功能"
83
+
84
+ response_format:
85
+ content_type: "application/json"
86
+ status_codes:
87
+ "200": "healthy — 所有關鍵依賴正常"
88
+ "503": "unhealthy — 至少一個關鍵依賴失敗"
89
+ schema:
90
+ status: "healthy | degraded | unhealthy"
91
+ timestamp: "ISO-8601"
92
+ uptime_seconds: number
93
+ dependencies:
94
+ description: "每個被檢查的依賴的狀態(僅 readiness / deep check 回傳)"
95
+ example:
96
+ database:
97
+ status: "healthy | unhealthy"
98
+ latency_ms: number
99
+ last_check: "ISO-8601"
100
+ upstream_api:
101
+ status: "healthy | unhealthy"
102
+ latency_ms: number
103
+ version: "service version string"
104
+
105
+ observability_integration:
106
+ rule_1: "Health check 結果應作為 RED metric 的 Error 來源之一(Rate / Errors / Duration)"
107
+ rule_2: "連續 N 次 health check failed 應觸發 incident(對齊 incident-response)"
108
+ rule_3: "probe 延遲本身應被監控(異常緩慢可能是 resource_exhaustion 徵兆)"
109
+
110
+ scenarios:
111
+ scenario_1_liveness_not_checking_db:
112
+ given: "DB 暫時無法連線(連線池耗盡)"
113
+ when: "liveness probe 被呼叫"
114
+ then: "回傳 200 healthy(liveness 不檢查 DB)"
115
+ note: "避免 DB 連鎖故障導致所有 pod 重啟"
116
+
117
+ scenario_2_readiness_fails_on_critical_dep:
118
+ given: "關鍵下游 API 不可達(服務無法處理任何請求)"
119
+ when: "readiness probe 被呼叫"
120
+ then: "回傳 503 unhealthy,dependencies.upstream_api.status=unhealthy"
121
+ and: "pod 被移出負載均衡,但 process 不重啟"
122
+ note: "readiness fail → 不接流量;liveness 仍 healthy → 不重啟"
123
+
124
+ scenario_3_startup_then_liveness_handover:
125
+ given: "服務需 60s 預熱快取"
126
+ when: "pod 啟動"
127
+ then: "startup probe 檢查預熱狀態,前 60s 持續回 503"
128
+ and: "預熱完成後 startup 回 200,自此停用,改由 liveness 接手"
129
+ note: "避免慢啟動服務在預熱中被誤判為 crash 重啟"
130
+
131
+ error_codes:
132
+ HC-001: "HEALTH_CHECK_FAILED — 關鍵依賴失敗"
133
+ HC-002: "HEALTH_CHECK_TIMEOUT — probe 本身超時"
134
+ HC-003: "INVALID_DEPENDENCY_SET — readiness 檢查了非關鍵依賴(設計違規)"
135
+
136
+ integration_points:
137
+ - "observability-standards(XSPEC-063 規劃中)— health check 是 RED metric 的 Error 來源"
138
+ - "incident-response-assistant — 連續 health check failed 觸發 incident 流程"
139
+ - "circuit-breaker.ai.yaml — breaker OPEN 時 readiness 應回 degraded"
140
+ - "deployment-standards.ai.yaml — K8s probe 配置對應三種 probe 類型"
@@ -0,0 +1,112 @@
1
+ # immutability-first.ai.yaml
2
+ # 不可變性設計原則(Immutability-First Architecture)
3
+ # XSPEC-044 — 防止並行 Agent 環境競態條件的系統級設計標準
4
+
5
+ standard:
6
+ id: immutability-first
7
+ name: Immutability-First Architecture Standard
8
+ description: 系統級不可變性設計原則 — DTO/Value Object 欄位一律 readonly,防止並行 Agent 競態條件
9
+
10
+ meta:
11
+ version: "1.0.0"
12
+ updated: "2026-04-16"
13
+ source: XSPEC-044
14
+ description: >
15
+ 系統級不可變性設計原則。資料流介面(DTO / Value Object)的欄位
16
+ 一律宣告為 readonly,陣列欄位使用 ReadonlyArray<T>,物件修改透過
17
+ 展開語法建立新物件,防止並行 Agent 環境下的意外狀態共享與競態條件。
18
+ scope: universal
19
+ applies_to: [TypeScript, interfaces, concurrent-systems]
20
+
21
+ guidelines:
22
+ - "資料流介面(DTO / Value Object)的所有欄位必須宣告 readonly"
23
+ - "介面中的陣列型欄位使用 ReadonlyArray<T> 而非可變的 T[]"
24
+ - "修改物件時使用物件展開語法建立新物件,不直接賦值給 readonly 欄位"
25
+ - "跨並行邊界(Promise.all / Worker Thread)傳遞的物件必須為深層不可變"
26
+ - "介面中的嵌套物件欄位使用 Readonly<T> 包裝(防止淺層保護不足)"
27
+
28
+ rules:
29
+ - id: IMM-001
30
+ name: "DTO 欄位 readonly"
31
+ rule: "資料流介面(Data Transfer Objects、Value Objects)的所有欄位必須宣告 readonly"
32
+ rationale: "防止並行 Agent 環境下的意外狀態共享與競態條件"
33
+ severity: required
34
+ example_bad: |
35
+ interface TaskResult {
36
+ status: TaskStatus // ← 可被意外修改
37
+ cost_usd?: number
38
+ }
39
+ example_good: |
40
+ interface TaskResult {
41
+ readonly status: TaskStatus // ← 型別安全保護
42
+ readonly cost_usd?: number
43
+ }
44
+
45
+ - id: IMM-002
46
+ name: "陣列欄位 ReadonlyArray"
47
+ rule: "介面中的陣列型欄位使用 ReadonlyArray<T> 而非可變的 T[]"
48
+ rationale: "防止 push/splice/sort 等就地修改操作破壞共享陣列"
49
+ severity: required
50
+ example_bad: |
51
+ interface MemoryContext {
52
+ recentHistory: IterationRecord[] // ← 可被 push/splice
53
+ }
54
+ example_good: |
55
+ interface MemoryContext {
56
+ readonly recentHistory: ReadonlyArray<IterationRecord>
57
+ }
58
+
59
+ - id: IMM-003
60
+ name: "展開語法替代就地修改"
61
+ rule: "修改物件時使用物件展開語法建立新物件,不直接賦值給 readonly 欄位"
62
+ rationale: "保留原始物件不變,同時建立可追蹤的修改歷程"
63
+ severity: required
64
+ example_bad: |
65
+ options.sessionId = forkId // ← 直接修改,其他持有者看到改變
66
+ example_good: |
67
+ const taskOptions = { ...options, sessionId: forkId } // ← 新物件
68
+
69
+ - id: IMM-004
70
+ name: "並行邊界深層不可變"
71
+ rule: "跨並行邊界(Promise.all / Worker Thread)傳遞的物件必須為深層不可變"
72
+ rationale: "並行執行中無法預測存取順序,可變共享物件必然產生競態條件"
73
+ severity: required
74
+ applies_to: [orchestrateParallel, Promise.all, Worker]
75
+ example_good: |
76
+ // 每個並行任務持有自己的 options 快照
77
+ const batchResults = await Promise.all(
78
+ batch.map(task => {
79
+ const taskOptions = { ...baseOptions, sessionId: forkId }
80
+ return executeOneTask(task, adapter, taskOptions, ...)
81
+ })
82
+ )
83
+
84
+ - id: IMM-005
85
+ name: "嵌套物件 Readonly 包裝"
86
+ rule: "介面中的嵌套物件欄位使用 Readonly<T> 包裝"
87
+ rationale: "頂層 readonly 不防止嵌套物件欄位被修改(淺層保護不足)"
88
+ severity: recommended
89
+ example_bad: |
90
+ interface PipelineMemoryEntry {
91
+ readonly metadata: { score?: number } // ← metadata.score 仍可被修改
92
+ }
93
+ example_good: |
94
+ interface PipelineMemoryEntry {
95
+ readonly metadata: Readonly<{ score?: number; severity?: string }>
96
+ }
97
+
98
+ when_to_apply:
99
+ - "設計新的 DTO / Value Object / Config 介面時"
100
+ - "跨並行邊界傳遞物件時"
101
+ - "Agent 間共享狀態設計時"
102
+ - "Code Review 時檢查介面是否遺漏 readonly"
103
+
104
+ exceptions:
105
+ - "Builder Pattern 的 mutable builder 物件(在 build() 後回傳不可變結果)"
106
+ - "測試 fixture 的 mutable 建立步驟(建立後視為不可變)"
107
+ - "效能關鍵的熱路徑(需有明確的 benchmark 依據才可豁免)"
108
+
109
+ error_codes:
110
+ IMM-E001: "READONLY_VIOLATION — 嘗試修改 readonly 欄位(TypeScript 編譯期捕獲)"
111
+ IMM-E002: "SHARED_MUTATION — 跨並行邊界的就地修改導致競態條件"
112
+ IMM-E003: "SHALLOW_READONLY — 嵌套物件遺漏 Readonly<T> 包裝,淺層保護不足"
@@ -8,10 +8,10 @@ standard:
8
8
  description: AI 模型分級選擇策略
9
9
 
10
10
  meta:
11
- version: "1.0.0"
12
- updated: "2026-03-20"
11
+ version: "2.0.0"
12
+ updated: "2026-04-13"
13
13
  source: core/model-selection.md
14
- description: 三層模型分級選擇標準
14
+ description: "三層模型分級選擇策略 + 多模型池能力管理(XSPEC-027)"
15
15
  inspired_by: superpowers/subagent-driven-development
16
16
 
17
17
  guidelines:
@@ -70,6 +70,112 @@ standard:
70
70
  action: "從 standard 或更高層級開始"
71
71
  priority: medium
72
72
 
73
+ capability_dimensions:
74
+ description: "能力維度分類與評分說明(XSPEC-027, DEC-031, DEC-032)"
75
+ scoring_scale:
76
+ 5: "生產就緒 — 高準確率,可直接使用"
77
+ 4: "良好 — 偶有遺漏,可接受"
78
+ 3: "基本可用 — 需人工補充"
79
+ 2: "部分可用 — 僅供參考"
80
+ 1: "不可靠 — 不建議使用"
81
+ dimensions:
82
+ modality:
83
+ vision:
84
+ description: "圖片/截圖理解能力(UI 分析、圖表解讀)"
85
+ benchmark: "internal-vision-bench"
86
+ scoring_guide:
87
+ 5: "≥ 90% 準確,可萃取完整 DESIGN.md"
88
+ 4: "75-89%,偶有遺漏但可用"
89
+ 3: "60-74%,需人工補充"
90
+ 2: "40-59%,僅供參考"
91
+ 1: "< 40%,不可靠"
92
+ audio:
93
+ description: "語音理解能力"
94
+ benchmark: "future-audio-bench"
95
+ image_generation:
96
+ description: "圖片生成能力"
97
+ benchmark: "provider-specific"
98
+ reasoning:
99
+ code_reasoning:
100
+ description: "程式碼理解與生成品質"
101
+ benchmark: "humaneval-plus"
102
+ math_reasoning:
103
+ description: "數學推理準確率"
104
+ benchmark: "gsm8k"
105
+ instruction_following:
106
+ description: "複雜多步驟指令遵循率(VibeOps 最重視)"
107
+ benchmark: "internal-instruction-bench"
108
+ long_context_quality:
109
+ description: "長文件中間段資訊存取(Lost-in-the-Middle)"
110
+ benchmark: "needle-in-haystack"
111
+ output:
112
+ structured_output:
113
+ description: "JSON mode / Schema 格式輸出成功率"
114
+ benchmark: "internal-json-bench"
115
+ tool_use:
116
+ description: "Function Calling 正確率"
117
+ benchmark: "internal-tool-bench"
118
+ language:
119
+ multilingual_zh_tw:
120
+ description: "繁體中文品質(本系統優先語言)"
121
+ benchmark: "internal-zh-tw-bench"
122
+
123
+ capability_registry:
124
+ description: "模型能力登記表(DEC-031 D1)。各子專案依實際測試維護分數。"
125
+ format:
126
+ model_id: "provider/model-name"
127
+ version_pinned: "版本鎖定識別(SHA、日期戳或 model_version)"
128
+ pin_date: "鎖定日期(YYYY-MM-DD)"
129
+ eol_date: "預期淘汰日期(可選,YYYY-MM-DD)"
130
+ capabilities:
131
+ "<dimension>.<subdimension>": "<1-5 整數分>"
132
+ examples:
133
+ - model_id: "anthropic/claude-sonnet-4-6"
134
+ version_pinned: "claude-sonnet-4-6"
135
+ pin_date: "2026-04-13"
136
+ capabilities:
137
+ "modality.vision": 4
138
+ "reasoning.instruction_following": 5
139
+ "reasoning.code_reasoning": 5
140
+ "output.structured_output": 5
141
+ "output.tool_use": 5
142
+ "language.multilingual_zh_tw": 5
143
+ - model_id: "anthropic/claude-haiku-4-5"
144
+ version_pinned: "claude-haiku-4-5-20251001"
145
+ pin_date: "2026-04-13"
146
+ capabilities:
147
+ "modality.vision": 3
148
+ "reasoning.instruction_following": 4
149
+ "reasoning.code_reasoning": 4
150
+ "output.structured_output": 4
151
+ "output.tool_use": 4
152
+ "language.multilingual_zh_tw": 4
153
+
154
+ routing_rules:
155
+ description: "能力路由決策規則(DEC-031 D2, DEC-032 D3)"
156
+ selection_strategy: "pareto_weighted"
157
+ rules:
158
+ - id: CAP-001
159
+ condition: "任務需要 capability X,模型得分 ≥ min_score"
160
+ action: "SUPPORTED — 正常執行"
161
+ priority: high
162
+ - id: CAP-002
163
+ condition: "任務需要 capability X,模型得分 2-3(min_score 未達但 ≥ 2)"
164
+ action: "DEGRADED — 降級流程執行,產出標記 [DEGRADED]"
165
+ priority: medium
166
+ - id: CAP-003
167
+ condition: "任務需要 capability X,模型得分 ≤ 1 或未登記"
168
+ action: "UNSUPPORTED — 使用替代流程或提示用戶"
169
+ priority: high
170
+ - id: CAP-004
171
+ condition: "模型降智偵測(DEC-033)觸發 moderate 信號"
172
+ action: "啟動金絲雀測試,同時記錄降智警告"
173
+ priority: high
174
+ - id: CAP-005
175
+ condition: "模型降智偵測觸發 critical 信號"
176
+ action: "自動切換備用模型,上報 P1 Issue"
177
+ priority: critical
178
+
73
179
  physical_spec:
74
180
  type: checklist
75
181
  validator:
@@ -79,3 +185,5 @@ physical_spec:
79
185
  - "是否根據複雜度信號選擇模型等級"
80
186
  - "BLOCKED 時是否嘗試升級而非直接失敗"
81
187
  - "簡單任務是否避免使用過高等級模型"
188
+ - "能力登記表是否包含 version_pinned 與 pin_date"
189
+ - "路由決策是否依 SUPPORTED/DEGRADED/UNSUPPORTED 三態處理"