@mrciphersmith/keryx 0.4.29 → 0.4.31
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/dist/cli.js +2446 -1391
- package/dist/core.js +90 -27
- package/dist/keryx-general-worker-entry.js +82 -25
- package/package.json +1 -1
- package/src/gdskills/bundled/install-manifest.json +2 -0
- package/src/gdskills/bundled/rules/core/api-contracts.mdc +21 -136
- package/src/gdskills/bundled/rules/core/async-patterns.mdc +18 -171
- package/src/gdskills/bundled/rules/core/clean-architecture.mdc +21 -3
- package/src/gdskills/bundled/rules/core/cli-interface-design.mdc +63 -194
- package/src/gdskills/bundled/rules/core/code-style-patterns.mdc +36 -49
- package/src/gdskills/bundled/rules/core/concurrency-patterns.mdc +32 -0
- package/src/gdskills/bundled/rules/core/database-patterns.mdc +26 -148
- package/src/gdskills/bundled/rules/core/error-handling.mdc +7 -8
- package/src/gdskills/bundled/rules/core/frontend-assistant.mdc +14 -29
- package/src/gdskills/bundled/rules/core/layout-rendering.mdc +51 -0
- package/src/gdskills/bundled/rules/core/mobx-store-template.mdc +69 -511
- package/src/gdskills/bundled/rules/core/nestjs-dto.mdc +18 -36
- package/src/gdskills/bundled/rules/core/playwright-testing.mdc +35 -308
- package/src/gdskills/bundled/rules/core/security-baseline.mdc +18 -140
- package/src/gdskills/bundled/rules/core/solid-principles.mdc +31 -7
- package/src/gdskills/bundled/rules/core/storybook-guidelines.mdc +20 -22
- package/src/gdskills/bundled/rules/core/tdd-workflow.mdc +37 -74
- package/src/gdskills/bundled/rules/core/ui-anti-slop.mdc +48 -37
- package/src/gdskills/bundled/skills/quality/deprecation-path/SKILL.md +1 -1
- package/src/gdskills/bundled/skills/review/review-architecture/SKILL.md +24 -60
- package/src/gdskills/bundled/skills/review/review-backend/SKILL.md +13 -65
- package/src/gdskills/bundled/skills/review/review-clean-code/SKILL.md +22 -35
- package/src/gdskills/bundled/skills/review/review-frontend/SKILL.md +16 -309
- package/src/gdskills/bundled/skills/review/review-frontend-conventions/SKILL.md +7 -21
- package/src/gdskills/bundled/skills/review/review-highload/SKILL.md +83 -227
- package/src/gdskills/bundled/skills/review/review-layout/SKILL.md +22 -28
- package/src/gdskills/bundled/skills/review/review-logic/SKILL.md +8 -8
- package/src/gdskills/bundled/skills/review/review-performance/SKILL.md +15 -37
- package/src/gdskills/bundled/skills/review/review-security-code/SKILL.md +7 -7
- package/src/gdskills/bundled/skills/review/review-style/SKILL.md +31 -66
- package/src/gdskills/bundled/skills/review/review-testing-practices/SKILL.md +21 -39
- package/src/gdskills/bundled/skills/review/review-ui-ux/SKILL.md +42 -82
- package/src/gdskills/bundled/stacks/angular/rules/coding-style.mdc +15 -57
- package/src/gdskills/bundled/stacks/angular/rules/patterns.mdc +16 -60
- package/src/gdskills/bundled/stacks/angular/rules/security.mdc +11 -49
- package/src/gdskills/bundled/stacks/angular/rules/testing.mdc +13 -52
- package/src/gdskills/bundled/stacks/c-cpp/rules/coding-style.mdc +33 -57
- package/src/gdskills/bundled/stacks/c-cpp/rules/patterns.mdc +35 -62
- package/src/gdskills/bundled/stacks/c-cpp/rules/security.mdc +35 -62
- package/src/gdskills/bundled/stacks/c-cpp/rules/testing.mdc +34 -54
- package/src/gdskills/bundled/stacks/ci-github-gitlab/rules/patterns.mdc +27 -56
- package/src/gdskills/bundled/stacks/ci-github-gitlab/rules/security.mdc +51 -119
- package/src/gdskills/bundled/stacks/csharp-dotnet/rules/coding-style.mdc +42 -74
- package/src/gdskills/bundled/stacks/csharp-dotnet/rules/patterns.mdc +45 -84
- package/src/gdskills/bundled/stacks/csharp-dotnet/rules/security.mdc +34 -59
- package/src/gdskills/bundled/stacks/csharp-dotnet/rules/testing.mdc +33 -62
- package/src/gdskills/bundled/stacks/django/rules/coding-style.mdc +15 -56
- package/src/gdskills/bundled/stacks/django/rules/patterns.mdc +16 -68
- package/src/gdskills/bundled/stacks/django/rules/security.mdc +13 -71
- package/src/gdskills/bundled/stacks/django/rules/testing.mdc +16 -62
- package/src/gdskills/bundled/stacks/docker-k8s-terraform/rules/coding-style.mdc +30 -53
- package/src/gdskills/bundled/stacks/docker-k8s-terraform/rules/patterns.mdc +20 -56
- package/src/gdskills/bundled/stacks/docker-k8s-terraform/rules/security.mdc +52 -122
- package/src/gdskills/bundled/stacks/docker-k8s-terraform/rules/testing.mdc +23 -42
- package/src/gdskills/bundled/stacks/fastapi/rules/coding-style.mdc +13 -47
- package/src/gdskills/bundled/stacks/fastapi/rules/patterns.mdc +18 -81
- package/src/gdskills/bundled/stacks/fastapi/rules/security.mdc +13 -75
- package/src/gdskills/bundled/stacks/fastapi/rules/testing.mdc +14 -58
- package/src/gdskills/bundled/stacks/flutter-dart/rules/coding-style.mdc +36 -74
- package/src/gdskills/bundled/stacks/flutter-dart/rules/patterns.mdc +30 -66
- package/src/gdskills/bundled/stacks/flutter-dart/rules/security.mdc +33 -67
- package/src/gdskills/bundled/stacks/flutter-dart/rules/testing.mdc +41 -73
- package/src/gdskills/bundled/stacks/go/rules/coding-style.mdc +36 -57
- package/src/gdskills/bundled/stacks/go/rules/patterns.mdc +27 -42
- package/src/gdskills/bundled/stacks/go/rules/security.mdc +26 -43
- package/src/gdskills/bundled/stacks/go/rules/testing.mdc +23 -41
- package/src/gdskills/bundled/stacks/java-kotlin-spring/rules/coding-style.mdc +18 -37
- package/src/gdskills/bundled/stacks/java-kotlin-spring/rules/patterns.mdc +26 -43
- package/src/gdskills/bundled/stacks/java-kotlin-spring/rules/security.mdc +25 -37
- package/src/gdskills/bundled/stacks/java-kotlin-spring/rules/testing.mdc +34 -50
- package/src/gdskills/bundled/stacks/kotlin-android/rules/coding-style.mdc +28 -65
- package/src/gdskills/bundled/stacks/kotlin-android/rules/patterns.mdc +34 -78
- package/src/gdskills/bundled/stacks/kotlin-android/rules/security.mdc +35 -68
- package/src/gdskills/bundled/stacks/kotlin-android/rules/testing.mdc +34 -68
- package/src/gdskills/bundled/stacks/mobx/rules/coding-style.mdc +18 -64
- package/src/gdskills/bundled/stacks/mobx/rules/patterns.mdc +13 -66
- package/src/gdskills/bundled/stacks/mobx/rules/security.mdc +8 -35
- package/src/gdskills/bundled/stacks/mobx/rules/testing.mdc +10 -39
- package/src/gdskills/bundled/stacks/nestjs/rules/coding-style.mdc +32 -45
- package/src/gdskills/bundled/stacks/nestjs/rules/patterns.mdc +40 -60
- package/src/gdskills/bundled/stacks/nestjs/rules/security.mdc +30 -50
- package/src/gdskills/bundled/stacks/nestjs/rules/testing.mdc +27 -47
- package/src/gdskills/bundled/stacks/nextjs-nuxt/rules/coding-style.mdc +14 -48
- package/src/gdskills/bundled/stacks/nextjs-nuxt/rules/patterns.mdc +15 -67
- package/src/gdskills/bundled/stacks/nextjs-nuxt/rules/security.mdc +12 -50
- package/src/gdskills/bundled/stacks/nextjs-nuxt/rules/testing.mdc +11 -43
- package/src/gdskills/bundled/stacks/php-laravel/rules/coding-style.mdc +17 -58
- package/src/gdskills/bundled/stacks/php-laravel/rules/patterns.mdc +15 -56
- package/src/gdskills/bundled/stacks/php-laravel/rules/security.mdc +13 -50
- package/src/gdskills/bundled/stacks/php-laravel/rules/testing.mdc +14 -55
- package/src/gdskills/bundled/stacks/python/rules/coding-style.mdc +13 -41
- package/src/gdskills/bundled/stacks/python/rules/patterns.mdc +20 -61
- package/src/gdskills/bundled/stacks/python/rules/security.mdc +15 -57
- package/src/gdskills/bundled/stacks/python/rules/testing.mdc +16 -50
- package/src/gdskills/bundled/stacks/react/rules/coding-style.mdc +14 -40
- package/src/gdskills/bundled/stacks/react/rules/patterns.mdc +15 -55
- package/src/gdskills/bundled/stacks/react/rules/security.mdc +13 -49
- package/src/gdskills/bundled/stacks/react/rules/testing.mdc +10 -37
- package/src/gdskills/bundled/stacks/ruby-rails/rules/coding-style.mdc +12 -45
- package/src/gdskills/bundled/stacks/ruby-rails/rules/patterns.mdc +18 -67
- package/src/gdskills/bundled/stacks/ruby-rails/rules/security.mdc +11 -60
- package/src/gdskills/bundled/stacks/ruby-rails/rules/testing.mdc +14 -65
- package/src/gdskills/bundled/stacks/rust/rules/coding-style.mdc +39 -65
- package/src/gdskills/bundled/stacks/rust/rules/patterns.mdc +33 -60
- package/src/gdskills/bundled/stacks/rust/rules/security.mdc +35 -57
- package/src/gdskills/bundled/stacks/rust/rules/testing.mdc +29 -52
- package/src/gdskills/bundled/stacks/sql-db/rules/coding-style.mdc +12 -48
- package/src/gdskills/bundled/stacks/sql-db/rules/patterns.mdc +22 -113
- package/src/gdskills/bundled/stacks/sql-db/rules/security.mdc +11 -56
- package/src/gdskills/bundled/stacks/sql-db/rules/testing.mdc +14 -59
- package/src/gdskills/bundled/stacks/swift-ios/rules/coding-style.mdc +29 -65
- package/src/gdskills/bundled/stacks/swift-ios/rules/patterns.mdc +41 -88
- package/src/gdskills/bundled/stacks/swift-ios/rules/security.mdc +28 -53
- package/src/gdskills/bundled/stacks/swift-ios/rules/testing.mdc +32 -65
- package/src/gdskills/bundled/stacks/vue/rules/coding-style.mdc +17 -52
- package/src/gdskills/bundled/stacks/vue/rules/patterns.mdc +17 -63
- package/src/gdskills/bundled/stacks/vue/rules/security.mdc +11 -41
- package/src/gdskills/bundled/stacks/vue/rules/testing.mdc +16 -48
|
@@ -1,185 +1,32 @@
|
|
|
1
1
|
---
|
|
2
|
-
description: "Async patterns
|
|
2
|
+
description: "Async patterns standard shared by code writers and reviewers, with the severities reviewers use: independent awaits run in parallel, a timeout on every external call, bounded fan-out, no event-loop blocking. Use when writing or reviewing async/await code, parallel operations, or queue consumers."
|
|
3
3
|
alwaysApply: false
|
|
4
4
|
---
|
|
5
5
|
|
|
6
6
|
# Async Patterns
|
|
7
7
|
|
|
8
|
-
|
|
9
|
-
Prevent common async pitfalls: sequential execution where parallel is safe, unhandled promise rejections, missing timeouts, and event loop blockage.
|
|
10
|
-
|
|
11
|
-
## When To Apply
|
|
12
|
-
Apply when writing any `async`/`await` code, calling external services, processing queues, or coordinating multiple async operations.
|
|
13
|
-
|
|
14
|
-
---
|
|
8
|
+
Canon applies: `Promise.all` / `allSettled` semantics (MDN), the Node.js "Don't Block the Event Loop" guide, `@typescript-eslint/no-floating-promises`. This rule holds only this project's decisions.
|
|
15
9
|
|
|
16
10
|
## Rules
|
|
17
11
|
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
// BAD — sequential: takes 300ms (100 + 100 + 100)
|
|
24
|
-
const user = await fetchUser(id);
|
|
25
|
-
const orders = await fetchOrders(id);
|
|
26
|
-
const prefs = await fetchPreferences(id);
|
|
27
|
-
|
|
28
|
-
// GOOD — parallel: takes 100ms (max of 100, 100, 100)
|
|
29
|
-
const [user, orders, prefs] = await Promise.all([
|
|
30
|
-
fetchUser(id),
|
|
31
|
-
fetchOrders(id),
|
|
32
|
-
fetchPreferences(id),
|
|
33
|
-
]);
|
|
34
|
-
```
|
|
35
|
-
|
|
36
|
-
**Rule:** If operation B does not depend on the result of operation A, they MUST run in parallel.
|
|
37
|
-
|
|
38
|
-
### Rule 2: Use Promise.allSettled When Partial Failure is Acceptable
|
|
39
|
-
|
|
40
|
-
```typescript
|
|
41
|
-
// BAD — one failure cancels all
|
|
42
|
-
const results = await Promise.all([criticalOp(), optionalOp()]); // if optionalOp rejects, criticalOp result is lost
|
|
43
|
-
|
|
44
|
-
// GOOD — each result handled independently
|
|
45
|
-
const [critical, optional] = await Promise.allSettled([criticalOp(), optionalOp()]);
|
|
46
|
-
if (critical.status === 'rejected') throw critical.reason;
|
|
47
|
-
if (optional.status === 'rejected') logger.warn('optional failed', optional.reason);
|
|
48
|
-
```
|
|
49
|
-
|
|
50
|
-
Use `Promise.all` when ALL operations are required. Use `Promise.allSettled` when SOME can fail gracefully.
|
|
51
|
-
|
|
52
|
-
### Rule 3: Every External Call Has a Timeout
|
|
53
|
-
|
|
54
|
-
Network calls without timeouts hang indefinitely, blocking resources.
|
|
55
|
-
|
|
56
|
-
```typescript
|
|
57
|
-
// BAD — hangs forever if service is down
|
|
58
|
-
const response = await fetch('https://api.external.com/data');
|
|
59
|
-
|
|
60
|
-
// GOOD — fails fast after 5 seconds
|
|
61
|
-
const controller = new AbortController();
|
|
62
|
-
const timeout = setTimeout(() => controller.abort(), 5_000);
|
|
63
|
-
try {
|
|
64
|
-
const response = await fetch('https://api.external.com/data', { signal: controller.signal });
|
|
65
|
-
// ...
|
|
66
|
-
} finally {
|
|
67
|
-
clearTimeout(timeout);
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
// GOOD — with a utility wrapper
|
|
71
|
-
const response = await fetchWithTimeout('https://api.external.com/data', { timeout: 5_000 });
|
|
72
|
-
```
|
|
73
|
-
|
|
74
|
-
**Default timeouts:**
|
|
75
|
-
- Internal service calls: 3s
|
|
76
|
-
- External API calls: 10s
|
|
77
|
-
- Long-running operations (file processing, ML): 60s with progress events
|
|
78
|
-
- Database queries: configure at connection pool level
|
|
79
|
-
|
|
80
|
-
### Rule 4: No Unhandled Promise Rejections
|
|
81
|
-
|
|
82
|
-
Every promise must have a `.catch()` or be `await`-ed inside a `try/catch`.
|
|
83
|
-
|
|
84
|
-
```typescript
|
|
85
|
-
// BAD — fire-and-forget without error handling
|
|
86
|
-
sendNotification(userId, message); // rejection is swallowed silently
|
|
87
|
-
|
|
88
|
-
// BAD — floating promise in Express handler
|
|
89
|
-
app.get('/data', (req, res) => {
|
|
90
|
-
loadData(); // not awaited, errors don't propagate to response
|
|
91
|
-
res.json({ ok: true });
|
|
92
|
-
});
|
|
93
|
-
|
|
94
|
-
// GOOD — fire-and-forget with explicit error handling
|
|
95
|
-
sendNotification(userId, message).catch(err => {
|
|
96
|
-
logger.error('notification failed', { userId, err });
|
|
97
|
-
});
|
|
98
|
-
|
|
99
|
-
// GOOD — awaited in async handler
|
|
100
|
-
app.get('/data', async (req, res) => {
|
|
101
|
-
const data = await loadData();
|
|
102
|
-
res.json(data);
|
|
103
|
-
});
|
|
104
|
-
```
|
|
105
|
-
|
|
106
|
-
### Rule 5: No CPU-Blocking Operations on the Event Loop
|
|
107
|
-
|
|
108
|
-
Operations that block the event loop starve all other concurrent requests:
|
|
109
|
-
- `JSON.parse` / `JSON.stringify` on payloads > 1MB → use streaming
|
|
110
|
-
- Synchronous file reads in hot paths → use `fs.promises.*`
|
|
111
|
-
- CPU-intensive loops → offload to worker threads
|
|
112
|
-
- Synchronous crypto operations → use `crypto.subtle` or async equivalents
|
|
113
|
-
|
|
114
|
-
```typescript
|
|
115
|
-
// BAD — blocks event loop for large payload
|
|
116
|
-
app.post('/import', (req, res) => {
|
|
117
|
-
const data = JSON.parse(req.body.payload); // synchronous, large payload blocks
|
|
118
|
-
});
|
|
119
|
-
|
|
120
|
-
// GOOD — streaming parse
|
|
121
|
-
import { pipeline } from 'stream/promises';
|
|
122
|
-
app.post('/import', async (req, res) => {
|
|
123
|
-
await pipeline(req, new JSONStreamParser(), new DataProcessor());
|
|
124
|
-
});
|
|
125
|
-
```
|
|
126
|
-
|
|
127
|
-
### Rule 6: Batch Async Operations with Controlled Concurrency
|
|
128
|
-
|
|
129
|
-
Running N async operations at once can overwhelm downstream services. Use a concurrency limiter:
|
|
130
|
-
|
|
131
|
-
```typescript
|
|
132
|
-
// BAD — 1000 parallel requests to an API
|
|
133
|
-
await Promise.all(items.map(item => processItem(item)));
|
|
134
|
-
|
|
135
|
-
// GOOD — max 10 concurrent operations
|
|
136
|
-
import PLimit from 'p-limit';
|
|
137
|
-
const limit = PLimit(10);
|
|
138
|
-
await Promise.all(items.map(item => limit(() => processItem(item))));
|
|
139
|
-
```
|
|
140
|
-
|
|
141
|
-
### Rule 7: Async Initialization Pattern
|
|
142
|
-
|
|
143
|
-
Classes with async setup must not use the constructor for initialization:
|
|
144
|
-
|
|
145
|
-
```typescript
|
|
146
|
-
// BAD — constructor cannot be async
|
|
147
|
-
class DatabasePool {
|
|
148
|
-
constructor() {
|
|
149
|
-
this.pool = await createPool(); // syntax error
|
|
150
|
-
}
|
|
151
|
-
}
|
|
152
|
-
|
|
153
|
-
// GOOD — factory method pattern
|
|
154
|
-
class DatabasePool {
|
|
155
|
-
private constructor(private readonly pool: Pool) {}
|
|
156
|
-
|
|
157
|
-
static async create(): Promise<DatabasePool> {
|
|
158
|
-
const pool = await createPool();
|
|
159
|
-
return new DatabasePool(pool);
|
|
160
|
-
}
|
|
161
|
-
}
|
|
162
|
-
const db = await DatabasePool.create();
|
|
163
|
-
```
|
|
164
|
-
|
|
165
|
-
---
|
|
166
|
-
|
|
167
|
-
## Iron Laws
|
|
168
|
-
|
|
169
|
-
**IRON LAW 1: Sequential await for independent operations is a performance bug. Use Promise.all.**
|
|
170
|
-
**IRON LAW 2: Every external HTTP call must have an explicit timeout configured.**
|
|
171
|
-
**IRON LAW 3: A floating promise (not awaited, no .catch) is an unhandled rejection waiting to crash the process.**
|
|
12
|
+
1. **Independent awaits run in parallel.** If B does not depend on A, use `Promise.all`; use `Promise.allSettled` when some results are optional, and handle each rejection.
|
|
13
|
+
2. **Every external call has a timeout**, set with `AbortSignal.timeout(ms)`. Defaults: internal service 3s, external API 10s, long-running work 60s with progress events; database queries at the connection-pool level.
|
|
14
|
+
3. **Bound fan-out.** Mapping a large collection to promises uses a concurrency limit; default 10.
|
|
15
|
+
4. **Do not block the event loop.** `JSON.parse` / `JSON.stringify` of a payload over 1MB, sync file reads in hot paths and CPU-heavy loops go to a stream, `fs.promises` or a worker thread.
|
|
16
|
+
5. **Rejections** are handled per `error-handling.mdc` Rule 4.
|
|
172
17
|
|
|
173
18
|
---
|
|
174
19
|
|
|
175
|
-
##
|
|
20
|
+
## Review severities (shared with reviewers)
|
|
176
21
|
|
|
177
|
-
|
|
178
|
-
|---|---|
|
|
179
|
-
| "I'll add a timeout later if it's needed" | Missing timeouts are invisible until a downstream service hangs — add them when the call is written |
|
|
180
|
-
| "The operation is fast, sequential await is fine" | Sequential operations that are "fast" become bottlenecks under load |
|
|
181
|
-
| "I don't need to await this, it's just a side effect" | Fire-and-forget without `.catch` silently loses errors that may indicate data corruption |
|
|
182
|
-
| "Promise.allSettled is verbose, I'll use Promise.all and handle errors in each function" | Promise.all cancels all operations on first rejection — allSettled gives you full control |
|
|
183
|
-
| "Concurrency limiting adds complexity" | Uncontrolled concurrency causes rate limit errors, OOM, and cascading failures downstream |
|
|
22
|
+
`review-logic` rates these patterns by this table. Change a row here, never in a reviewer.
|
|
184
23
|
|
|
185
|
-
|
|
24
|
+
| Signal | A finding when | Default | Not a finding |
|
|
25
|
+
|---|---|---|---|
|
|
26
|
+
| Sequential independent awaits (Rule 1) | always | `minor`; `major` on a hot path or when the calls are many | an ordering the code depends on |
|
|
27
|
+
| `Promise.all` where an optional result's failure discards a required one (Rule 1) | a named optional call can reject | `major` | all results required |
|
|
28
|
+
| External call with no timeout (Rule 2) | the call can hang a request or worker | `major` | a timeout set at the client or pool |
|
|
29
|
+
| Timeout built from `AbortController` + `setTimeout` (Rule 2) | always | `minor` | — |
|
|
30
|
+
| Unbounded fan-out over a caller-sized collection (Rule 3) | the size is not fixed small | `major` on a hot path, else `minor` | a collection of known small size |
|
|
31
|
+
| Event-loop blocking on a request path (Rule 4) | a named input size or path reaches it | `major` | startup or one-off scripts |
|
|
32
|
+
| Unhandled rejection (Rule 5) | per `error-handling.mdc` **Review severities** | as there | as there |
|
|
@@ -18,14 +18,14 @@ Apply to backend code when creating new modules, services, or features; when dec
|
|
|
18
18
|
- **Business rules live in domain entities and domain services**, not in use cases. A use
|
|
19
19
|
case coordinates repositories and domain services and owns the transaction; a controller
|
|
20
20
|
parses input, calls one use case and formats the output.
|
|
21
|
-
- **A controller that queries the database is a violation
|
|
22
|
-
thin-controller exception.
|
|
21
|
+
- **A controller that queries the database is a layer violation**: there is no
|
|
22
|
+
thin-controller exception, and it is rated by Review severities below.
|
|
23
23
|
- **A repository is the I/O boundary that gets an interface** (`solid-principles.mdc`,
|
|
24
24
|
D): the interface is declared in the domain, the implementation lives in infrastructure.
|
|
25
25
|
- **Each boundary maps its own types.** A persistence row never reaches a controller, and a
|
|
26
26
|
request DTO never enters a domain entity. Request DTOs belong to presentation, use-case
|
|
27
27
|
input and output to application, persistence models to infrastructure.
|
|
28
|
-
- **A
|
|
28
|
+
- **A use case or transaction that changes more than 2 domain aggregates is split.**
|
|
29
29
|
- **A module's public API is its index exports.** Importing another module's internal files
|
|
30
30
|
(`b/internal/...`) crosses its boundary.
|
|
31
31
|
- **Project size is not an exemption**: the layers apply to a small service too.
|
|
@@ -33,3 +33,21 @@ Apply to backend code when creating new modules, services, or features; when dec
|
|
|
33
33
|
`src/{domain,application,infrastructure,presentation}/<module>/`.
|
|
34
34
|
|
|
35
35
|
The check for a change: replacing the database or the transport changes no domain file.
|
|
36
|
+
|
|
37
|
+
---
|
|
38
|
+
|
|
39
|
+
## Review severities (shared with reviewers)
|
|
40
|
+
|
|
41
|
+
`review-architecture` rates layer and dependency-direction findings by this table; `review-backend` uses the same rating for the same condition. Change a row here, never in a reviewer. A layer violation is a maintenance cost, so it is `minor`; `major` needs a named defect (a trigger and a wrong outcome), never size or a project preference.
|
|
42
|
+
|
|
43
|
+
| Signal | A finding when | Default | Not a finding |
|
|
44
|
+
|---|---|---|---|
|
|
45
|
+
| Controller queries the database or holds business rules | always | `minor`; `major` only with a named defect | parsing input, calling one use case, formatting output |
|
|
46
|
+
| Business rule added to a use case instead of the domain | the change adds the rule to a use case | `minor` | coordination and transaction ownership |
|
|
47
|
+
| Domain imports infrastructure, framework, ORM or SDK | always | `minor`; `major` only with a named defect | — |
|
|
48
|
+
| Persistence row reaches a controller, or a request DTO enters a domain entity | always | `minor`; `major` only with a named defect | — |
|
|
49
|
+
| Repository without a domain interface, or an interface with no I/O or substitution boundary | the repository is an I/O boundary with no interface, or the interface has one internal implementation | `minor` | a plain helper or value object |
|
|
50
|
+
| Use case or transaction changes more than 2 domain aggregates | always | `minor`; `major` only with a named defect (for example lost consistency) | — |
|
|
51
|
+
| Another module's internal files imported instead of its index exports | the path bypasses the index | `minor`; `major` only with a named defect | — |
|
|
52
|
+
| Core or shared module imports feature code | always | `minor`; `major` only with a named defect | — |
|
|
53
|
+
| Circular import between modules | always | `minor`; `blocker` when an import resolves to `undefined` on a path the change reaches | — |
|
|
@@ -1,237 +1,106 @@
|
|
|
1
1
|
---
|
|
2
|
-
description: "CLI
|
|
2
|
+
description: "keryx CLI decisions: exit codes (0 clean, 1 found something, 2 cannot tell), machine-readable output on stdout and diagnostics on stderr, versioned --json shapes, unknown flags refused, and flags renamed by alias with one notice or removed by refusing them by name. Use when adding, changing, or retiring a command, subcommand, flag, or --json payload that people already run."
|
|
3
3
|
alwaysApply: false
|
|
4
|
+
stack_requires: "cli"
|
|
4
5
|
---
|
|
5
6
|
|
|
6
7
|
# CLI Interface Design
|
|
7
8
|
|
|
8
9
|
## Purpose
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
10
|
+
Once a script reads an exit code, pipes stdout, or parses a `--json` payload,
|
|
11
|
+
every later edit is compatible or a silent breakage in someone else's CI. This
|
|
12
|
+
rule records keryx's decisions for those channels, not general CLI practice, and
|
|
13
|
+
no list of current defects: known gaps live in the issue tracker.
|
|
13
14
|
|
|
14
15
|
## When To Apply
|
|
15
16
|
Apply when adding a command or subcommand, adding or renaming a flag, changing
|
|
16
17
|
what a command exits with, or changing the shape of anything it prints for a
|
|
17
|
-
machine. It governs keryx's own CLI (`src/cli.ts
|
|
18
|
-
`rules/core/api-contracts.mdc` governs HTTP surfaces
|
|
19
|
-
discipline there is the same discipline stated for a different transport.
|
|
18
|
+
machine. It governs keryx's own CLI (`src/cli.ts`, `src/commands/**`);
|
|
19
|
+
`rules/core/api-contracts.mdc` governs HTTP surfaces.
|
|
20
20
|
|
|
21
21
|
---
|
|
22
22
|
|
|
23
|
-
##
|
|
23
|
+
## Decisions
|
|
24
24
|
|
|
25
|
-
### 1.
|
|
25
|
+
### 1. Exit codes: three values, three meanings
|
|
26
26
|
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
- **0** — the command ran and the answer is clean.
|
|
31
|
-
- **1** — the command ran and found something the caller should act on: a
|
|
27
|
+
- **0**: the command ran and the answer is clean.
|
|
28
|
+
- **1**: the command ran and found something the caller should act on: a
|
|
32
29
|
broken link, a failing gate, a finding, a refusal.
|
|
33
|
-
- **2
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
The reason 2 exists is written into that code: *"a script that treats 1 as
|
|
37
|
-
'gone' would otherwise read an unreadable registry as a deletion."*
|
|
38
|
-
`keryx memory search` adopted it deliberately and says so
|
|
39
|
-
(`src/commands/memory.ts:182-196`), calling it *"reserved for 'cannot tell',
|
|
40
|
-
distinct from both a completed search and a validation error."*
|
|
41
|
-
|
|
42
|
-
**Two shipped commands do not honour it, and converging them is this rule's
|
|
43
|
-
reason to exist:**
|
|
44
|
-
|
|
45
|
-
- `keryx health run` folds `incomplete` — *"a required check that is missing,
|
|
46
|
-
skipped, unparsed or unfinished"* — into **1**, the same code as an
|
|
47
|
-
established threshold violation (`src/commands/health.ts:120-132`, with the
|
|
48
|
-
justification at `:103-112`). "Nobody ran eslint" and "eslint found 40
|
|
49
|
-
errors" are indistinguishable to a caller reading the code.
|
|
50
|
-
- `keryx review` goes the other way and exits **0** on the same class of
|
|
51
|
-
answer: `reportCrossFamilyReviewProblems` and `reportFilterStatsProblems`
|
|
52
|
-
(both in `src/commands/review.ts`; cited by name because that file moves
|
|
53
|
-
under every review change, and a line number here has already gone stale
|
|
54
|
-
once) filter `not-recorded` out before failing, on the stated grounds that an
|
|
55
|
-
absence is honest. It is honest — and it is still not a pass.
|
|
56
|
-
|
|
57
|
-
Three commands, one binary, three answers to "I could not tell". A new command
|
|
58
|
-
uses 0/1/2 as defined above. An existing one moves toward it only with its
|
|
59
|
-
consumers named, because narrowing 1 into 1-or-2 is itself a breaking change.
|
|
30
|
+
- **2**: the command could not tell (unreadable store, unparseable input,
|
|
31
|
+
unresolvable ref), so a script never reads "unreadable" as "gone".
|
|
60
32
|
|
|
61
|
-
|
|
33
|
+
A new command uses 0/1/2. An existing command moves toward it only with its
|
|
34
|
+
consumers named, because narrowing 1 into 1-or-2 is itself a breaking change.
|
|
35
|
+
Corollaries:
|
|
62
36
|
|
|
63
|
-
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
- **A wrapper forwards its child's code unchanged.** `keryx ctx run` sets
|
|
67
|
-
`process.exitCode = result.exitCode` (`src/commands/ctx.ts:210`); a wrapper
|
|
68
|
-
that collapsed every child failure to 1 would make the wrapped command
|
|
69
|
-
unusable under `set -e`.
|
|
37
|
+
- A checker that reports defects and exits 0 cannot be gated on. Zero items
|
|
38
|
+
evaluated is not a pass.
|
|
39
|
+
- A wrapper forwards its child's exit code unchanged, as `keryx ctx run` does.
|
|
70
40
|
|
|
71
41
|
### 2. stdout is the answer, stderr is everything else
|
|
72
42
|
|
|
73
|
-
|
|
74
|
-
goes to
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
writes parseable JSON to stdout and its diagnostic to stderr, and still exits
|
|
84
|
-
1 (`src/commands/skills.ts:934-947`). Verified: stdout parses, stderr is
|
|
85
|
-
empty on the clean path.
|
|
86
|
-
- Progress, warnings, deprecation notices, usage errors go to **stderr**.
|
|
87
|
-
- Under `--json`, a failure is *data on stdout*, not prose on stderr:
|
|
88
|
-
`keryx memory search --json` emits `{ outcome: "store-unreadable", … }` on
|
|
89
|
-
stdout and exits 2, where the plain mode prints to stderr
|
|
90
|
-
(`src/commands/memory.ts:190-195`). A machine reader gets a discriminated
|
|
91
|
-
result either way.
|
|
92
|
-
- **Where this is broken today:** an unrecognised command prints its one-line
|
|
93
|
-
diagnostic to stderr and then dumps the full help to **stdout**
|
|
94
|
-
(`src/cli.ts:147-149`, `printHelp` at `:152`). Measured: `keryx bogusverb`
|
|
95
|
-
writes 9,503 bytes of help to stdout; `keryx wiki check --bogus` writes
|
|
96
|
-
4,150. Both numbers are the help text's own size and move whenever a command
|
|
97
|
-
is added — a later reading that differs is growth, not a correction to this
|
|
98
|
-
paragraph. A caller piping stdout for JSON receives a help screen instead, and
|
|
99
|
-
only the exit code says otherwise. **Help printed because of an error belongs
|
|
100
|
-
on stderr. Help printed because `--help` was asked for belongs on stdout.**
|
|
43
|
+
- Structured output (`--json` payloads, rendered reports, whatever a pipe is for)
|
|
44
|
+
goes to stdout, alone.
|
|
45
|
+
- Progress, warnings, deprecation notices and usage errors go to stderr. A bare
|
|
46
|
+
`keryx mcp` is the stdio MCP server, so a notice on stdout corrupts its frames.
|
|
47
|
+
- Under `--json`, a failure is data on stdout, not prose on stderr: a
|
|
48
|
+
discriminated object such as `{ outcome: "store-unreadable", ... }` with the
|
|
49
|
+
exit code the failure earns (2 for "could not tell").
|
|
50
|
+
- Help printed because of an error goes to stderr. Help printed because `--help`
|
|
51
|
+
was asked for goes to stdout. A new flag appears in that command's help text in
|
|
52
|
+
the same change.
|
|
101
53
|
|
|
102
54
|
### 3. A `--json` shape is versioned, deterministic, and pinned
|
|
103
55
|
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
and stays at its own `schemaVersion: 1` (`src/gdskills/export-plugin.ts:153`) —
|
|
111
|
-
versions are per-shape, not per-repo. A test pins the number
|
|
112
|
-
(`src/gdskills/export-runtime-builds.test.ts:108`).
|
|
113
|
-
|
|
114
|
-
`keryx modules status --json` carries the other half: a `schemaVersion`, a
|
|
115
|
-
deterministic key order sorted independently of authoring order *"which is what
|
|
116
|
-
makes it safe to diff and to consume from a harness"*
|
|
117
|
-
(`src/commands/modules.ts:197-210`), and a test that pins the version
|
|
118
|
-
(`src/commands/modules.test.ts:26`).
|
|
119
|
-
|
|
120
|
-
So the standard for any new machine-readable payload is:
|
|
121
|
-
|
|
122
|
-
1. A top-level **object** with a `schemaVersion`. Not an array — an array
|
|
123
|
-
cannot grow a field. `rules/core/skills-storage-workflow.mdc` has said "One
|
|
124
|
-
top-level JSON object only" since it was written.
|
|
125
|
-
2. Deterministic ordering, so two runs of an unchanged tree are byte-identical.
|
|
126
|
-
3. A test that asserts the version and the required keys, in the same change.
|
|
127
|
-
4. Adding an optional field is compatible. **Removing or renaming one bumps the
|
|
128
|
-
version**, in the same commit as the removal.
|
|
129
|
-
|
|
130
|
-
**Where this is inconsistent today:** `keryx skills` serialises internal
|
|
131
|
-
TypeScript objects straight to stdout at eleven call sites
|
|
132
|
-
(`src/commands/skills.ts:222`, `:288`, `:398`, `:693`, `:735`, `:785`, `:822`,
|
|
133
|
-
`:883`, `:935`, `:989`, `:1101`). Three of the eleven print a type that
|
|
134
|
-
declares one — `LearningProposal` (`src/gdskills/learn.ts:17`, set at `:100`)
|
|
135
|
-
at `:785`, and `ProjectSkillVerificationReport` (`src/gdskills/verify.ts:25`,
|
|
136
|
-
set at `:96`) at `:883` and `:989`. The other eight carry no version at all.
|
|
137
|
-
|
|
138
|
-
**The gap is the envelope, and it is the worse half.** `verify --bundled
|
|
139
|
-
--json` emits an unversioned object (`root`, `skills`, `documents`,
|
|
140
|
-
`skillNames`, `findings`); `verify --all --json` emits a bare array — `[]` when
|
|
141
|
-
the registry is empty (`:973`), a list of reports otherwise (`:989`). So
|
|
142
|
-
`keryx skills verify --all --json` ships `[{ "schemaVersion": 1, … }]`: each
|
|
143
|
-
element versioned, the payload a caller actually parses not. That is standard 1
|
|
144
|
-
failing in the direction it warns about — an array cannot grow a field, so the
|
|
145
|
-
envelope can never be versioned later without the breaking change the version
|
|
146
|
-
existed to avoid, however carefully each element inside it is versioned. One
|
|
147
|
-
test pins one field of one of them
|
|
148
|
-
(`src/commands/skills.bundled-verify.test.ts:58` asserts `findings` is `[]`). A
|
|
149
|
-
rename inside any of the eight unversioned types is a CLI breaking change that
|
|
150
|
-
nothing in the repository would catch.
|
|
56
|
+
1. A top-level object with a `schemaVersion`, per shape. Never a bare array: it
|
|
57
|
+
cannot grow a field, so its envelope could never be versioned later.
|
|
58
|
+
2. Deterministic key order, so two runs on an unchanged tree are byte-identical.
|
|
59
|
+
3. A test asserts the version and the required keys, in the same change.
|
|
60
|
+
4. Adding an optional field is compatible. Removing or renaming one bumps the
|
|
61
|
+
version in the same commit.
|
|
151
62
|
|
|
152
63
|
### 4. An unknown flag is refused, never ignored
|
|
153
64
|
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
typo two different ways.
|
|
175
|
-
|
|
176
|
-
A new command validates its flags. A flag that takes a fixed set of values
|
|
177
|
-
validates the value too.
|
|
178
|
-
|
|
179
|
-
### 5. A flag is renamed by aliasing it, and removed by refusing it out loud
|
|
180
|
-
|
|
181
|
-
keryx has never deleted a spelling. Three patterns, all shipped, all correct:
|
|
182
|
-
|
|
183
|
-
- **Rename → alias + one notice.** `keryx mcp install|uninstall` became
|
|
184
|
-
`keryx integrate` and the old spelling still works: one module translates the
|
|
185
|
-
old argument shape and calls the new implementation, so there is *"one
|
|
186
|
-
implementation and nothing to drift"* (`src/commands/mcp.ts:1-14`). It prints
|
|
187
|
-
exactly one line, on stderr, per invocation — *"A line a reader sees three
|
|
188
|
-
times in one command is a line they learn to skip, which is how deprecation
|
|
189
|
-
notices stop working at all"* (`:78-92`). A contract test asserts the retired
|
|
190
|
-
spellings still work, still write the same files, and name the replacement
|
|
191
|
-
**once** (`src/commands/mcp-naming.test.ts:453`, `:470`, `:490`).
|
|
192
|
-
- **Removal → refuse by name, with the reason.** `keryx workspace handoff
|
|
193
|
-
--from` was removed because a caller could not be allowed to state it. It is
|
|
194
|
-
refused by name rather than as a generic unknown option, *"so anyone who
|
|
195
|
-
scripted it learns why it is gone instead of reading it as a typo"*
|
|
196
|
-
(`src/commands/workspace.ts:221-231`).
|
|
197
|
-
- **A wrapper's own flag is consumed, not forwarded.** `keryx ctx rg --json` is
|
|
198
|
-
keryx's flag, stripped before the child command is built, because `rg --json`
|
|
199
|
-
means something else (`src/commands/ctx.ts:213-219`). Check the namespace
|
|
200
|
-
before claiming a flag name a wrapped tool already owns.
|
|
201
|
-
|
|
202
|
-
**Where this is inconsistent today:** `keryx review` accepts both `--ref` and
|
|
203
|
-
`--target-ref` for the same value, `--ref` winning
|
|
204
|
-
(`src/commands/review.ts:147`, `:409`). There is no notice, and `--target-ref`
|
|
205
|
-
appears nowhere in `keryx review --help`. An unannounced, undocumented alias is
|
|
206
|
-
indistinguishable from an accidental duplicate: nothing tells a caller to
|
|
207
|
-
migrate, so nothing will ever justify retiring it.
|
|
208
|
-
|
|
209
|
-
A rename therefore ships four things in one change: the new spelling, the old
|
|
210
|
-
one still working through the same implementation, one stderr notice naming the
|
|
211
|
-
replacement, and a test that asserts both.
|
|
65
|
+
- A command refuses an unrecognised flag: it names the flag, lists what is
|
|
66
|
+
accepted, and exits 1. A dropped flag writes nothing and reports success.
|
|
67
|
+
- A flag with a fixed value set refuses an unknown value and lists the valid
|
|
68
|
+
ones, rather than silently keeping the default.
|
|
69
|
+
- A new command validates its flags with the shared refusal, not a private copy.
|
|
70
|
+
|
|
71
|
+
### 5. A flag is renamed by aliasing, and removed by refusing it out loud
|
|
72
|
+
|
|
73
|
+
keryx does not delete a published spelling.
|
|
74
|
+
|
|
75
|
+
- **Rename**: the old spelling keeps working through the same implementation (no
|
|
76
|
+
second implementation to drift) and prints exactly one stderr line per
|
|
77
|
+
invocation naming the replacement. A contract test asserts both.
|
|
78
|
+
- **Removal**: refuse by name with the reason, never as a generic unknown
|
|
79
|
+
option, so a script that used it learns why it is gone instead of reading it
|
|
80
|
+
as a typo.
|
|
81
|
+
- **Wrapper flags**: a wrapper's own flag is consumed, not forwarded. Check the
|
|
82
|
+
wrapped tool's namespace before claiming a flag name it already owns.
|
|
83
|
+
- An alias is documented in `--help`; an undocumented one reads as an
|
|
84
|
+
accidental duplicate and can never be retired.
|
|
212
85
|
|
|
213
86
|
---
|
|
214
87
|
|
|
215
88
|
## The three that are not negotiable
|
|
216
89
|
|
|
217
90
|
A nonzero exit never means "I could not tell" in a command that also uses
|
|
218
|
-
nonzero to mean "I found something"
|
|
91
|
+
nonzero to mean "I found something": pick 2 for the first. A `--json` payload
|
|
219
92
|
never loses or renames a field without a `schemaVersion` bump in the same
|
|
220
93
|
commit. An old flag spelling is never deleted: it is aliased with a notice, or
|
|
221
94
|
refused by name with the reason.
|
|
222
95
|
|
|
223
96
|
---
|
|
224
97
|
|
|
225
|
-
## Red Flags
|
|
98
|
+
## Red Flags: stop and re-read this rule if you are thinking
|
|
226
99
|
|
|
227
100
|
| Rationalization | Why it's wrong |
|
|
228
101
|
|---|---|
|
|
229
|
-
| "Exit 1 is fine, the message
|
|
230
|
-
| "Nobody parses this `--json` yet, so I can change the shape freely" | You cannot observe who parses a published CLI's output
|
|
231
|
-
| "
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
| "It's just a help screen on stdout, who cares" | Nine kilobytes of it, where the caller expected JSON. Error output is error output regardless of how friendly it reads |
|
|
235
|
-
| "I'll add the schemaVersion when the shape actually changes" | The first change is the one that needs it, and by then the unversioned readers already exist |
|
|
236
|
-
|
|
237
|
-
**IRON LAW: ONCE A COMMAND IS PUBLISHED, ITS EXIT CODE, ITS STDOUT, AND ITS `--json` SHAPE ARE A CONTRACT — CHANGE THEM THE WAY YOU WOULD CHANGE AN API, OR NOT AT ALL.**
|
|
102
|
+
| "Exit 1 is fine, the message says which kind of failure it was" | Scripts read the code, not the message |
|
|
103
|
+
| "Nobody parses this `--json` yet, so I can change the shape freely" | You cannot observe who parses a published CLI's output |
|
|
104
|
+
| "The old flag is unused, I'll just delete it" | "Unused" means no usage you can see |
|
|
105
|
+
|
|
106
|
+
**IRON LAW: ONCE A COMMAND IS PUBLISHED, ITS EXIT CODE, ITS STDOUT, AND ITS `--json` SHAPE ARE A CONTRACT. CHANGE THEM THE WAY YOU WOULD CHANGE AN API, OR NOT AT ALL.**
|