@ai-content-space/loopx 0.2.9 → 0.2.10

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 (99) hide show
  1. package/README.md +10 -6
  2. package/README.zh-CN.md +10 -6
  3. package/docs/loopx/design/loopx-skill-suite-v1-design.md +12 -0
  4. package/docs/loopx/plans/2026-06-15-support-lens-skills-migration.md +1153 -0
  5. package/package.json +6 -1
  6. package/plugins/loopx/.codex-plugin/plugin.json +1 -1
  7. package/plugins/loopx/skills/api-designer/SKILL.md +232 -0
  8. package/plugins/loopx/skills/api-designer/references/error-handling.md +541 -0
  9. package/plugins/loopx/skills/api-designer/references/openapi.md +824 -0
  10. package/plugins/loopx/skills/api-designer/references/pagination.md +494 -0
  11. package/plugins/loopx/skills/api-designer/references/rest-patterns.md +335 -0
  12. package/plugins/loopx/skills/api-designer/references/versioning.md +391 -0
  13. package/plugins/loopx/skills/architecture-designer/SKILL.md +117 -0
  14. package/plugins/loopx/skills/architecture-designer/references/adr-template.md +116 -0
  15. package/plugins/loopx/skills/architecture-designer/references/architecture-patterns.md +346 -0
  16. package/plugins/loopx/skills/architecture-designer/references/database-selection.md +102 -0
  17. package/plugins/loopx/skills/architecture-designer/references/nfr-checklist.md +212 -0
  18. package/plugins/loopx/skills/architecture-designer/references/system-design.md +313 -0
  19. package/plugins/loopx/skills/clarify/SKILL.md +1 -1
  20. package/plugins/loopx/skills/cli-developer/SKILL.md +124 -0
  21. package/plugins/loopx/skills/cli-developer/references/design-patterns.md +221 -0
  22. package/plugins/loopx/skills/cli-developer/references/go-cli.md +540 -0
  23. package/plugins/loopx/skills/cli-developer/references/node-cli.md +383 -0
  24. package/plugins/loopx/skills/cli-developer/references/python-cli.md +422 -0
  25. package/plugins/loopx/skills/cli-developer/references/ux-patterns.md +448 -0
  26. package/plugins/loopx/skills/debug/SKILL.md +1 -1
  27. package/plugins/loopx/skills/doc-readability/SKILL.md +1 -1
  28. package/plugins/loopx/skills/exec/SKILL.md +1 -1
  29. package/plugins/loopx/skills/final-review/SKILL.md +1 -1
  30. package/plugins/loopx/skills/finish/SKILL.md +1 -1
  31. package/plugins/loopx/skills/fix-review/SKILL.md +1 -1
  32. package/plugins/loopx/skills/go-style/SKILL.md +1 -1
  33. package/plugins/loopx/skills/kratos/SKILL.md +2 -1
  34. package/plugins/loopx/skills/plan-to-exec/SKILL.md +1 -1
  35. package/plugins/loopx/skills/refactor-plan/SKILL.md +1 -1
  36. package/plugins/loopx/skills/requirement-analyzer/SKILL.md +161 -0
  37. package/plugins/loopx/skills/requirement-analyzer/references/example-reports.md +170 -0
  38. package/plugins/loopx/skills/requirement-analyzer/references/prd-gap-checklist.md +167 -0
  39. package/plugins/loopx/skills/requirement-analyzer/references/readiness-rubric.md +70 -0
  40. package/plugins/loopx/skills/requirement-analyzer/references/report-template.md +83 -0
  41. package/plugins/loopx/skills/review/SKILL.md +1 -1
  42. package/plugins/loopx/skills/spec/SKILL.md +1 -1
  43. package/plugins/loopx/skills/sql-style/SKILL.md +108 -0
  44. package/plugins/loopx/skills/sql-style/references/database-design.md +402 -0
  45. package/plugins/loopx/skills/sql-style/references/dialect-differences.md +419 -0
  46. package/plugins/loopx/skills/sql-style/references/optimization.md +384 -0
  47. package/plugins/loopx/skills/sql-style/references/query-patterns.md +285 -0
  48. package/plugins/loopx/skills/sql-style/references/window-functions.md +328 -0
  49. package/plugins/loopx/skills/subagent-exec/SKILL.md +1 -1
  50. package/plugins/loopx/skills/tdd/SKILL.md +1 -1
  51. package/plugins/loopx/skills/verify/SKILL.md +1 -1
  52. package/scripts/verify-skills.mjs +0 -2
  53. package/skills/RESOLVER.md +8 -1
  54. package/skills/api-designer/SKILL.md +232 -0
  55. package/skills/api-designer/references/error-handling.md +541 -0
  56. package/skills/api-designer/references/openapi.md +824 -0
  57. package/skills/api-designer/references/pagination.md +494 -0
  58. package/skills/api-designer/references/rest-patterns.md +335 -0
  59. package/skills/api-designer/references/versioning.md +391 -0
  60. package/skills/architecture-designer/SKILL.md +117 -0
  61. package/skills/architecture-designer/references/adr-template.md +116 -0
  62. package/skills/architecture-designer/references/architecture-patterns.md +346 -0
  63. package/skills/architecture-designer/references/database-selection.md +102 -0
  64. package/skills/architecture-designer/references/nfr-checklist.md +212 -0
  65. package/skills/architecture-designer/references/system-design.md +313 -0
  66. package/skills/clarify/SKILL.md +1 -1
  67. package/skills/cli-developer/SKILL.md +124 -0
  68. package/skills/cli-developer/references/design-patterns.md +221 -0
  69. package/skills/cli-developer/references/go-cli.md +540 -0
  70. package/skills/cli-developer/references/node-cli.md +383 -0
  71. package/skills/cli-developer/references/python-cli.md +422 -0
  72. package/skills/cli-developer/references/ux-patterns.md +448 -0
  73. package/skills/debug/SKILL.md +1 -1
  74. package/skills/doc-readability/SKILL.md +1 -1
  75. package/skills/exec/SKILL.md +1 -1
  76. package/skills/final-review/SKILL.md +1 -1
  77. package/skills/finish/SKILL.md +1 -1
  78. package/skills/fix-review/SKILL.md +1 -1
  79. package/skills/go-style/SKILL.md +1 -1
  80. package/skills/kratos/SKILL.md +2 -1
  81. package/skills/plan-to-exec/SKILL.md +1 -1
  82. package/skills/refactor-plan/SKILL.md +1 -1
  83. package/skills/requirement-analyzer/SKILL.md +161 -0
  84. package/skills/requirement-analyzer/references/example-reports.md +170 -0
  85. package/skills/requirement-analyzer/references/prd-gap-checklist.md +167 -0
  86. package/skills/requirement-analyzer/references/readiness-rubric.md +70 -0
  87. package/skills/requirement-analyzer/references/report-template.md +83 -0
  88. package/skills/review/SKILL.md +1 -1
  89. package/skills/spec/SKILL.md +1 -1
  90. package/skills/sql-style/SKILL.md +108 -0
  91. package/skills/sql-style/references/database-design.md +402 -0
  92. package/skills/sql-style/references/dialect-differences.md +419 -0
  93. package/skills/sql-style/references/optimization.md +384 -0
  94. package/skills/sql-style/references/query-patterns.md +285 -0
  95. package/skills/sql-style/references/window-functions.md +328 -0
  96. package/skills/subagent-exec/SKILL.md +1 -1
  97. package/skills/tdd/SKILL.md +1 -1
  98. package/skills/verify/SKILL.md +1 -1
  99. package/src/install-discovery.mjs +5 -0
@@ -0,0 +1,328 @@
1
+ # Window Functions
2
+
3
+ ## Ranking Functions
4
+
5
+ ```sql
6
+ -- ROW_NUMBER: Sequential numbering within partition
7
+ SELECT
8
+ customer_id,
9
+ order_date,
10
+ total,
11
+ ROW_NUMBER() OVER (PARTITION BY customer_id ORDER BY order_date DESC) as row_num
12
+ FROM orders;
13
+
14
+ -- Get most recent order per customer
15
+ SELECT *
16
+ FROM (
17
+ SELECT
18
+ customer_id,
19
+ order_id,
20
+ order_date,
21
+ total,
22
+ ROW_NUMBER() OVER (PARTITION BY customer_id ORDER BY order_date DESC) as rn
23
+ FROM orders
24
+ ) ranked
25
+ WHERE rn = 1;
26
+
27
+ -- RANK: Same values get same rank, gaps in sequence
28
+ SELECT
29
+ student_id,
30
+ score,
31
+ RANK() OVER (ORDER BY score DESC) as rank,
32
+ DENSE_RANK() OVER (ORDER BY score DESC) as dense_rank,
33
+ ROW_NUMBER() OVER (ORDER BY score DESC) as row_num
34
+ FROM exam_results;
35
+ /*
36
+ score=100: rank=1, dense_rank=1, row_num=1
37
+ score=100: rank=1, dense_rank=1, row_num=2
38
+ score=95: rank=3, dense_rank=2, row_num=3
39
+ */
40
+
41
+ -- NTILE: Divide into N buckets
42
+ SELECT
43
+ customer_id,
44
+ total_spent,
45
+ NTILE(4) OVER (ORDER BY total_spent DESC) as quartile
46
+ FROM customer_lifetime_value;
47
+ ```
48
+
49
+ ## Aggregate Window Functions
50
+
51
+ ```sql
52
+ -- Running totals and cumulative sums
53
+ SELECT
54
+ order_date,
55
+ daily_revenue,
56
+ SUM(daily_revenue) OVER (ORDER BY order_date) as cumulative_revenue,
57
+ AVG(daily_revenue) OVER (
58
+ ORDER BY order_date
59
+ ROWS BETWEEN 6 PRECEDING AND CURRENT ROW
60
+ ) as rolling_7day_avg
61
+ FROM daily_sales;
62
+
63
+ -- Moving average with RANGE
64
+ SELECT
65
+ sale_date,
66
+ amount,
67
+ AVG(amount) OVER (
68
+ ORDER BY sale_date
69
+ RANGE BETWEEN INTERVAL '7 days' PRECEDING AND CURRENT ROW
70
+ ) as avg_last_7_days
71
+ FROM sales;
72
+
73
+ -- Partition-specific aggregates
74
+ SELECT
75
+ product_id,
76
+ sale_date,
77
+ quantity,
78
+ SUM(quantity) OVER (PARTITION BY product_id ORDER BY sale_date) as cumulative_qty,
79
+ AVG(quantity) OVER (PARTITION BY product_id) as avg_qty_for_product,
80
+ quantity::FLOAT / SUM(quantity) OVER (PARTITION BY product_id) as pct_of_total
81
+ FROM product_sales;
82
+ ```
83
+
84
+ ## LAG and LEAD Functions
85
+
86
+ ```sql
87
+ -- Compare with previous/next row
88
+ SELECT
89
+ order_date,
90
+ total,
91
+ LAG(total) OVER (ORDER BY order_date) as previous_day_total,
92
+ LEAD(total) OVER (ORDER BY order_date) as next_day_total,
93
+ total - LAG(total) OVER (ORDER BY order_date) as day_over_day_change
94
+ FROM daily_orders;
95
+
96
+ -- Find gaps in time series
97
+ SELECT
98
+ event_date,
99
+ LAG(event_date) OVER (ORDER BY event_date) as prev_date,
100
+ event_date - LAG(event_date) OVER (ORDER BY event_date) as days_since_last
101
+ FROM events
102
+ WHERE event_date - LAG(event_date) OVER (ORDER BY event_date) > 7;
103
+
104
+ -- Session analysis with time gaps
105
+ SELECT
106
+ user_id,
107
+ action_time,
108
+ LAG(action_time) OVER (PARTITION BY user_id ORDER BY action_time) as prev_action,
109
+ EXTRACT(EPOCH FROM (
110
+ action_time - LAG(action_time) OVER (PARTITION BY user_id ORDER BY action_time)
111
+ )) / 60 as minutes_since_last_action,
112
+ CASE
113
+ WHEN EXTRACT(EPOCH FROM (
114
+ action_time - LAG(action_time) OVER (PARTITION BY user_id ORDER BY action_time)
115
+ )) / 60 > 30 THEN 1
116
+ ELSE 0
117
+ END as new_session
118
+ FROM user_actions;
119
+ ```
120
+
121
+ ## FIRST_VALUE and LAST_VALUE
122
+
123
+ ```sql
124
+ -- Compare each row to first/last in partition
125
+ SELECT
126
+ product_id,
127
+ price_date,
128
+ price,
129
+ FIRST_VALUE(price) OVER (
130
+ PARTITION BY product_id
131
+ ORDER BY price_date
132
+ ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING
133
+ ) as initial_price,
134
+ LAST_VALUE(price) OVER (
135
+ PARTITION BY product_id
136
+ ORDER BY price_date
137
+ ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING
138
+ ) as current_price,
139
+ price - FIRST_VALUE(price) OVER (
140
+ PARTITION BY product_id
141
+ ORDER BY price_date
142
+ ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING
143
+ ) as price_change_from_start
144
+ FROM product_price_history;
145
+
146
+ -- NTH_VALUE: Get specific positioned value
147
+ SELECT
148
+ sale_date,
149
+ amount,
150
+ NTH_VALUE(amount, 2) OVER (
151
+ ORDER BY sale_date
152
+ ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING
153
+ ) as second_day_amount
154
+ FROM daily_sales;
155
+ ```
156
+
157
+ ## Frame Specifications
158
+
159
+ ```sql
160
+ -- ROWS vs RANGE difference
161
+ SELECT
162
+ order_date,
163
+ amount,
164
+ -- ROWS: Physical row offset
165
+ SUM(amount) OVER (
166
+ ORDER BY order_date
167
+ ROWS BETWEEN 2 PRECEDING AND 2 FOLLOWING
168
+ ) as sum_5_rows,
169
+ -- RANGE: Logical value range
170
+ SUM(amount) OVER (
171
+ ORDER BY order_date
172
+ RANGE BETWEEN INTERVAL '2 days' PRECEDING AND INTERVAL '2 days' FOLLOWING
173
+ ) as sum_5_day_range
174
+ FROM orders;
175
+
176
+ -- Common frame patterns
177
+ SELECT
178
+ sale_date,
179
+ revenue,
180
+ -- All preceding rows
181
+ SUM(revenue) OVER (
182
+ ORDER BY sale_date
183
+ ROWS UNBOUNDED PRECEDING
184
+ ) as running_total,
185
+ -- Last 3 rows including current
186
+ AVG(revenue) OVER (
187
+ ORDER BY sale_date
188
+ ROWS BETWEEN 2 PRECEDING AND CURRENT ROW
189
+ ) as ma_3,
190
+ -- Entire partition
191
+ SUM(revenue) OVER (
192
+ PARTITION BY EXTRACT(YEAR FROM sale_date)
193
+ ) as yearly_total,
194
+ -- Centered window
195
+ AVG(revenue) OVER (
196
+ ORDER BY sale_date
197
+ ROWS BETWEEN 3 PRECEDING AND 3 FOLLOWING
198
+ ) as centered_ma_7
199
+ FROM sales;
200
+ ```
201
+
202
+ ## Advanced Analytics
203
+
204
+ ```sql
205
+ -- Percentile calculations
206
+ SELECT
207
+ employee_id,
208
+ salary,
209
+ PERCENT_RANK() OVER (ORDER BY salary) as pct_rank,
210
+ CUME_DIST() OVER (ORDER BY salary) as cumulative_dist,
211
+ PERCENTILE_CONT(0.5) WITHIN GROUP (ORDER BY salary) OVER () as median_salary,
212
+ PERCENTILE_DISC(0.9) WITHIN GROUP (ORDER BY salary) OVER () as p90_salary
213
+ FROM employees;
214
+
215
+ -- Cohort retention analysis
216
+ WITH user_cohorts AS (
217
+ SELECT
218
+ user_id,
219
+ DATE_TRUNC('month', signup_date) as cohort_month,
220
+ DATE_TRUNC('month', activity_date) as activity_month
221
+ FROM user_activity
222
+ ),
223
+ cohort_sizes AS (
224
+ SELECT
225
+ cohort_month,
226
+ COUNT(DISTINCT user_id) as cohort_size
227
+ FROM user_cohorts
228
+ GROUP BY cohort_month
229
+ )
230
+ SELECT
231
+ uc.cohort_month,
232
+ uc.activity_month,
233
+ EXTRACT(MONTH FROM AGE(uc.activity_month, uc.cohort_month)) as months_since_signup,
234
+ COUNT(DISTINCT uc.user_id) as active_users,
235
+ cs.cohort_size,
236
+ ROUND(100.0 * COUNT(DISTINCT uc.user_id) / cs.cohort_size, 2) as retention_pct
237
+ FROM user_cohorts uc
238
+ JOIN cohort_sizes cs ON uc.cohort_month = cs.cohort_month
239
+ GROUP BY uc.cohort_month, uc.activity_month, cs.cohort_size
240
+ ORDER BY uc.cohort_month, months_since_signup;
241
+
242
+ -- Time-series gap filling
243
+ SELECT
244
+ date_series.date,
245
+ COALESCE(s.revenue, 0) as revenue,
246
+ AVG(s.revenue) OVER (
247
+ ORDER BY date_series.date
248
+ ROWS BETWEEN 6 PRECEDING AND CURRENT ROW
249
+ ) as ma_7day
250
+ FROM generate_series(
251
+ '2024-01-01'::DATE,
252
+ '2024-12-31'::DATE,
253
+ '1 day'::INTERVAL
254
+ ) AS date_series(date)
255
+ LEFT JOIN sales s ON date_series.date = s.sale_date;
256
+ ```
257
+
258
+ ## Conditional Aggregation with Windows
259
+
260
+ ```sql
261
+ -- Filter within window function
262
+ SELECT
263
+ product_id,
264
+ sale_date,
265
+ quantity,
266
+ SUM(quantity) FILTER (WHERE quantity > 10) OVER (
267
+ PARTITION BY product_id
268
+ ORDER BY sale_date
269
+ ) as cumulative_large_orders,
270
+ COUNT(*) FILTER (WHERE quantity > 100) OVER (
271
+ PARTITION BY product_id
272
+ ) as total_bulk_orders
273
+ FROM sales;
274
+
275
+ -- Multiple conditions
276
+ SELECT
277
+ customer_id,
278
+ order_date,
279
+ total,
280
+ COUNT(*) FILTER (WHERE total > 1000) OVER (
281
+ PARTITION BY customer_id
282
+ ) as high_value_order_count,
283
+ AVG(total) FILTER (WHERE total < 100) OVER (
284
+ PARTITION BY customer_id
285
+ ) as avg_small_order_value
286
+ FROM orders;
287
+ ```
288
+
289
+ ## Performance Considerations
290
+
291
+ ```sql
292
+ -- Avoid multiple window passes - combine into one
293
+ -- Bad: Multiple scans
294
+ SELECT
295
+ product_id,
296
+ (SELECT AVG(price) FROM products) as avg_price,
297
+ (SELECT MAX(price) FROM products) as max_price
298
+ FROM products;
299
+
300
+ -- Good: Single window pass
301
+ SELECT DISTINCT
302
+ AVG(price) OVER () as avg_price,
303
+ MAX(price) OVER () as max_price
304
+ FROM products;
305
+
306
+ -- Materialize expensive windows
307
+ CREATE MATERIALIZED VIEW product_rankings AS
308
+ SELECT
309
+ product_id,
310
+ category,
311
+ sales_count,
312
+ RANK() OVER (PARTITION BY category ORDER BY sales_count DESC) as category_rank,
313
+ PERCENT_RANK() OVER (ORDER BY sales_count DESC) as overall_percentile
314
+ FROM product_sales_summary;
315
+
316
+ CREATE INDEX idx_product_rankings_category ON product_rankings(category, category_rank);
317
+ ```
318
+
319
+ ## Common Patterns
320
+
321
+ 1. **Top N per Group**: Use ROW_NUMBER() with WHERE rn <= N
322
+ 2. **Running Totals**: SUM() OVER (ORDER BY date)
323
+ 3. **Moving Averages**: AVG() with ROWS BETWEEN N PRECEDING
324
+ 4. **Session Analysis**: LAG() to detect time gaps
325
+ 5. **Deduplication**: ROW_NUMBER() OVER (PARTITION BY key ORDER BY priority) WHERE rn = 1
326
+ 6. **Percentiles**: PERCENT_RANK() or PERCENTILE_CONT()
327
+ 7. **Year-over-Year**: LAG(value, 12) OVER (ORDER BY month)
328
+ 8. **Cohort Analysis**: PARTITION BY cohort_date, aggregate over activity periods
@@ -3,7 +3,7 @@ name: subagent-exec
3
3
  description: "Executes approved loopx implementation plans with fresh subagents per independent task and staged review. Not for planning, unclear requirements, or tightly coupled edits."
4
4
  when_to_use: "approved implementation plan, independent tasks, subagent execution, staged spec review, code quality review, parallel-capable execution"
5
5
  metadata:
6
- version: "0.2.9"
6
+ version: "0.2.10"
7
7
  ---
8
8
 
9
9
  # Subagent Exec
@@ -3,7 +3,7 @@ name: tdd
3
3
  description: "Guides feature and bugfix implementation through a failing test before production code and red-green-refactor discipline. Not for generated files or throwaway prototypes."
4
4
  when_to_use: "tdd, failing test first, feature implementation, bugfix, regression test, red green refactor, 测试先行"
5
5
  metadata:
6
- version: "0.2.9"
6
+ version: "0.2.10"
7
7
  ---
8
8
 
9
9
  # Test-Driven Development (TDD)
@@ -3,7 +3,7 @@ name: verify
3
3
  description: "Requires fresh verification evidence before claiming work is complete, fixed, passing, review-ready, or ready to commit. Not for speculative confidence or stale results."
4
4
  when_to_use: "verify, completion claim, fixed claim, tests pass, review-ready, commit, fresh evidence, 验证, 完成前检查"
5
5
  metadata:
6
- version: "0.2.9"
6
+ version: "0.2.10"
7
7
  ---
8
8
 
9
9
  # Verification Before Completion
@@ -176,7 +176,6 @@ async function assertPublicDocsAligned() {
176
176
  'LOOPX_SKIP_POSTINSTALL=1',
177
177
  'LOOPX_POSTINSTALL=0',
178
178
  'LOOPX_HOOKS=0',
179
- 'Archive compatibility',
180
179
  ]) {
181
180
  assertContains(readme, required, 'README.md');
182
181
  }
@@ -187,7 +186,6 @@ async function assertPublicDocsAligned() {
187
186
  'LOOPX_SKIP_POSTINSTALL=1',
188
187
  'LOOPX_POSTINSTALL=0',
189
188
  'LOOPX_HOOKS=0',
190
- 'Archive 兼容性',
191
189
  ]) {
192
190
  assertContains(readmeZh, required, 'README.zh-CN.md');
193
191
  }
@@ -27,8 +27,13 @@ Read the selected skill file before acting. If multiple skills match, read every
27
27
  | Bug, test failure, build failure, regression, unexpected behavior, root-cause investigation | `skills/debug/SKILL.md` |
28
28
  | Completion, fixed, passing, review-ready, commit, or handoff claims need fresh evidence | `skills/verify/SKILL.md` |
29
29
  | Document readability, PRD assessment, requirements gaps, unclear viewpoint, AI-like prose, or document rewriting | `skills/doc-readability/SKILL.md` |
30
+ | Existing requirement, PRD, spec, or feature brief needs ambiguity, gap, impact, feasibility, or readiness analysis | `skills/requirement-analyzer/SKILL.md` |
30
31
  | Editing `.go` files or reviewing Go style | `skills/go-style/SKILL.md` |
31
32
  | Go-Kratos proto, service, biz, data, middleware, auth, config, or troubleshooting | `skills/kratos/SKILL.md` |
33
+ | REST/GraphQL API design, resource modeling, OpenAPI, pagination, versioning, or API error model discipline | `skills/api-designer/SKILL.md` |
34
+ | System architecture, ADRs, NFRs, scalability, failure modes, or technology tradeoff discipline | `skills/architecture-designer/SKILL.md` |
35
+ | SQL queries, schema changes, indexes, migrations, database dialects, or query performance discipline | `skills/sql-style/SKILL.md` |
36
+ | CLI command design, flags, human/JSON output, interactive vs non-interactive behavior, help text, or CLI UX discipline | `skills/cli-developer/SKILL.md` |
32
37
 
33
38
  ## Disambiguation
34
39
 
@@ -44,7 +49,9 @@ Read the selected skill file before acting. If multiple skills match, read every
44
49
  10. Use `finish` only after implementation, final review, and verification are complete.
45
50
  11. Use `refactor-plan` for behavior-preserving refactor planning. If the refactor changes external behavior or contracts, route to `clarify` or `spec`.
46
51
  12. Use `doc-readability` for document assessment or rewriting, especially PRDs, requirements docs, specs, meeting notes, and AI-like prose. If the document is a source artifact for implementation, assess or rewrite it first, then route clarified implementation work back through `clarify`, `spec`, or `plan-to-exec`.
47
- 13. Treat `tdd`, `debug`, `verify`, `doc-readability`, `go-style`, and `kratos` as support lenses unless the user explicitly invokes them directly.
52
+ 13. Treat `tdd`, `debug`, `verify`, `doc-readability`, `requirement-analyzer`, `go-style`, `kratos`, `api-designer`, `architecture-designer`, `sql-style`, and `cli-developer` as support lenses unless the user explicitly invokes them directly.
53
+ 14. `requirement-analyzer` may produce a requirements gap report, but it must not advance loopx workflow state. Use its output as source material for a later `clarify`, `spec`, or `plan-to-exec` step only when the user asks.
54
+ 15. `api-designer`, `architecture-designer`, `sql-style`, and `cli-developer` add domain discipline to `spec`, `exec`, `review`, and `final-review`; they do not replace workflow skills or create workflow states.
48
55
 
49
56
  ## Deterministic Guard
50
57
 
@@ -0,0 +1,232 @@
1
+ ---
2
+ name: api-designer
3
+ description: "Applies loopx API design discipline for REST, GraphQL, OpenAPI, resource modeling, pagination, versioning, compatibility, and error models. Not for replacing clarify, spec, implementation planning, code review, or workflow state transitions."
4
+ when_to_use: "api-designer, API design, REST, GraphQL, OpenAPI, resource modeling, pagination, versioning, API errors, compatibility, 接口设计"
5
+ license: MIT
6
+ metadata:
7
+ version: "0.2.10"
8
+ forked_from: https://github.com/Jeffallan/claude-skills/tree/main/skills/api-designer
9
+ maintained_by: loopx
10
+ ---
11
+
12
+ # API Designer
13
+
14
+ API design discipline for REST, GraphQL, and OpenAPI 3.1 contracts.
15
+
16
+ ## loopx Boundary
17
+
18
+ `api-designer` is a support lens, not a workflow state. Use it directly when the user asks for API design help, and use it from `spec`, `exec`, `review`, or `final-review` when work touches API contracts.
19
+
20
+ This skill does not replace `clarify`, `spec`, `plan-to-exec`, `review`, or `final-review`. If product behavior, permissions, compatibility, migration, or client contract decisions are unresolved, route those decisions through `clarify` or `spec` instead of deciding them inside this skill.
21
+
22
+ ## Core Workflow
23
+
24
+ 1. **Analyze domain** — Understand business requirements, data models, and client needs
25
+ 2. **Choose API style** — State whether the contract is REST, GraphQL, or mixed, and why that style fits the client and evolution needs
26
+ 3. **Model contract surface** — For REST, identify resources, relationships, URI patterns, HTTP methods, and request/response schemas. For GraphQL, identify object types, operations, inputs, resolver boundaries, and schema evolution rules.
27
+ 4. **Specify contract** — For REST, create OpenAPI 3.1 and validate with `npx @redocly/cli lint openapi.yaml`. For GraphQL, define the schema and run the project's schema validation or code generation checks.
28
+ 5. **Mock and verify** — For REST, use a mock server such as `npx @stoplight/prism-cli mock openapi.yaml`. For GraphQL, exercise representative operations against the project schema or a local GraphQL test server.
29
+ 6. **Plan evolution** — Design versioning, deprecation, and backward-compatibility strategy
30
+
31
+ ## Reference Guide
32
+
33
+ Load detailed guidance based on context:
34
+
35
+ | Topic | Reference | Load When |
36
+ |-------|-----------|-----------|
37
+ | REST Patterns | `references/rest-patterns.md` | Resource design, HTTP methods, HATEOAS |
38
+ | Versioning | `references/versioning.md` | API versions, deprecation, breaking changes |
39
+ | Pagination | `references/pagination.md` | Cursor, offset, keyset pagination |
40
+ | Error Handling | `references/error-handling.md` | Error responses, RFC 7807, status codes |
41
+ | OpenAPI | `references/openapi.md` | OpenAPI 3.1, documentation, code generation |
42
+
43
+ ## Constraints
44
+
45
+ ### MUST DO
46
+ - For REST contracts, follow REST principles: resource-oriented URIs, proper HTTP methods, and HTTP status semantics.
47
+ - For REST contracts, include a comprehensive OpenAPI 3.1 specification.
48
+ - For GraphQL contracts, include schema definitions, resolver boundaries, operation examples, and validation or code generation checks.
49
+ - Use consistent naming conventions within each contract style.
50
+ - Design proper error responses with actionable messages: RFC 7807 for REST, and explicit GraphQL error shape and partial-success rules for GraphQL.
51
+ - Implement pagination for all collection endpoints or collection fields.
52
+ - Version APIs with clear deprecation policies
53
+ - Document authentication and authorization
54
+ - Provide request/response examples
55
+
56
+ ### MUST NOT DO
57
+ - For REST contracts, use verb-style resource URIs (use `/users/{id}`, not `/getUser/{id}`)
58
+ - Return inconsistent response structures
59
+ - Skip error code documentation
60
+ - For REST contracts, ignore HTTP status code semantics.
61
+ - Design APIs without a versioning strategy
62
+ - Expose implementation details in the API surface
63
+ - Create breaking changes without a migration path
64
+ - Omit rate limiting considerations
65
+
66
+ ## GraphQL Discipline
67
+
68
+ When designing GraphQL APIs, provide the same contract rigor as REST:
69
+
70
+ - Model object types, input types, mutations, queries, and subscriptions around client use cases, not database tables.
71
+ - Define nullability, pagination, filtering, sorting, and authorization rules explicitly in the schema.
72
+ - Use stable node identifiers and connection-style pagination when clients need cursor traversal.
73
+ - Avoid unbounded nested queries; plan depth, complexity, batching, and caching controls.
74
+ - Version by additive schema evolution and documented deprecation, not parallel endpoint versions unless the product contract requires it.
75
+ - Specify error shape, partial-success behavior, and resolver-level authorization failures.
76
+
77
+ ## Templates
78
+
79
+ ### OpenAPI 3.1 Resource Endpoint (copy-paste starter)
80
+
81
+ ```yaml
82
+ openapi: "3.1.0"
83
+ info:
84
+ title: Example API
85
+ version: "1.1.0"
86
+ paths:
87
+ /users:
88
+ get:
89
+ summary: List users
90
+ operationId: listUsers
91
+ tags: [Users]
92
+ parameters:
93
+ - name: cursor
94
+ in: query
95
+ schema: { type: string }
96
+ description: Opaque cursor for pagination
97
+ - name: limit
98
+ in: query
99
+ schema: { type: integer, default: 20, maximum: 100 }
100
+ responses:
101
+ "200":
102
+ description: Paginated list of users
103
+ content:
104
+ application/json:
105
+ schema:
106
+ type: object
107
+ required: [data, pagination]
108
+ properties:
109
+ data:
110
+ type: array
111
+ items: { $ref: "#/components/schemas/User" }
112
+ pagination:
113
+ $ref: "#/components/schemas/CursorPage"
114
+ "400": { $ref: "#/components/responses/BadRequest" }
115
+ "401": { $ref: "#/components/responses/Unauthorized" }
116
+ "429": { $ref: "#/components/responses/TooManyRequests" }
117
+ /users/{id}:
118
+ get:
119
+ summary: Get a user
120
+ operationId: getUser
121
+ tags: [Users]
122
+ parameters:
123
+ - name: id
124
+ in: path
125
+ required: true
126
+ schema: { type: string, format: uuid }
127
+ responses:
128
+ "200":
129
+ description: User found
130
+ content:
131
+ application/json:
132
+ schema: { $ref: "#/components/schemas/User" }
133
+ "404": { $ref: "#/components/responses/NotFound" }
134
+
135
+ components:
136
+ schemas:
137
+ User:
138
+ type: object
139
+ required: [id, email, created_at]
140
+ properties:
141
+ id: { type: string, format: uuid, readOnly: true }
142
+ email: { type: string, format: email }
143
+ name: { type: string }
144
+ created_at: { type: string, format: date-time, readOnly: true }
145
+
146
+ CursorPage:
147
+ type: object
148
+ required: [next_cursor, has_more]
149
+ properties:
150
+ next_cursor: { type: string, nullable: true }
151
+ has_more: { type: boolean }
152
+
153
+ Problem: # RFC 7807 Problem Details
154
+ type: object
155
+ required: [type, title, status]
156
+ properties:
157
+ type: { type: string, format: uri, example: "https://api.example.com/errors/validation-error" }
158
+ title: { type: string, example: "Validation Error" }
159
+ status: { type: integer, example: 400 }
160
+ detail: { type: string, example: "The 'email' field must be a valid email address." }
161
+ instance: { type: string, format: uri, example: "/users/req-abc123" }
162
+
163
+ responses:
164
+ BadRequest:
165
+ description: Invalid request parameters
166
+ content:
167
+ application/problem+json:
168
+ schema: { $ref: "#/components/schemas/Problem" }
169
+ Unauthorized:
170
+ description: Missing or invalid authentication
171
+ content:
172
+ application/problem+json:
173
+ schema: { $ref: "#/components/schemas/Problem" }
174
+ NotFound:
175
+ description: Resource not found
176
+ content:
177
+ application/problem+json:
178
+ schema: { $ref: "#/components/schemas/Problem" }
179
+ TooManyRequests:
180
+ description: Rate limit exceeded
181
+ headers:
182
+ Retry-After: { schema: { type: integer } }
183
+ content:
184
+ application/problem+json:
185
+ schema: { $ref: "#/components/schemas/Problem" }
186
+
187
+ securitySchemes:
188
+ BearerAuth:
189
+ type: http
190
+ scheme: bearer
191
+ bearerFormat: JWT
192
+
193
+ security:
194
+ - BearerAuth: []
195
+ ```
196
+
197
+ ### RFC 7807 Error Response (copy-paste)
198
+
199
+ ```json
200
+ {
201
+ "type": "https://api.example.com/errors/validation-error",
202
+ "title": "Validation Error",
203
+ "status": 422,
204
+ "detail": "The 'email' field must be a valid email address.",
205
+ "instance": "/users/req-abc123",
206
+ "errors": [
207
+ { "field": "email", "message": "Must be a valid email address." }
208
+ ]
209
+ }
210
+ ```
211
+
212
+ - Always use `Content-Type: application/problem+json` for error responses.
213
+ - `type` must be a stable, documented URI — never a generic string.
214
+ - `detail` must be human-readable and actionable.
215
+ - Extend with `errors[]` for field-level validation failures.
216
+
217
+ ## Output Checklist
218
+
219
+ When delivering an API design, provide:
220
+ 1. Resource model and relationships (diagram or table)
221
+ 2. API style decision: REST, GraphQL, or mixed
222
+ 3. For REST, endpoint specifications with URIs, HTTP methods, and OpenAPI 3.1 YAML
223
+ 4. For GraphQL, schema types, operations, resolver boundaries, authorization rules, query limits, and deprecation policy
224
+ 5. Authentication and authorization flows
225
+ 6. Error response catalog: 4xx/5xx responses with stable `type` URIs for REST, or GraphQL error shape, partial-success behavior, and resolver authorization failures
226
+ 7. Pagination and filtering patterns
227
+ 8. Versioning and deprecation strategy
228
+ 9. Validation result: `npx @redocly/cli lint openapi.yaml` passes with no errors for OpenAPI contracts, or project GraphQL schema validation passes for GraphQL contracts
229
+
230
+ ## Knowledge Reference
231
+
232
+ REST architecture, OpenAPI 3.1, GraphQL, HTTP semantics, JSON:API, HATEOAS, OAuth 2.0, JWT, RFC 7807 Problem Details, API versioning patterns, pagination strategies, rate limiting, webhook design, SDK generation