@kl-c/matrixos 0.3.40 → 0.3.42

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 (55) hide show
  1. package/dist/cli/index.js +167 -1
  2. package/dist/cli/skills/api-and-interface-design/SKILL.md +298 -0
  3. package/dist/cli/skills/browser-testing-with-devtools/SKILL.md +321 -0
  4. package/dist/cli/skills/ci-cd-and-automation/SKILL.md +394 -0
  5. package/dist/cli/skills/context-engineering/SKILL.md +293 -0
  6. package/dist/cli/skills/deprecation-and-migration/SKILL.md +251 -0
  7. package/dist/cli/skills/documentation-and-adrs/SKILL.md +292 -0
  8. package/dist/cli/skills/doubt-driven-development/SKILL.md +247 -0
  9. package/dist/cli/skills/incremental-implementation/SKILL.md +253 -0
  10. package/dist/cli/skills/interview-me/SKILL.md +229 -0
  11. package/dist/cli/skills/observability-and-instrumentation/SKILL.md +207 -0
  12. package/dist/cli/skills/performance-optimization/SKILL.md +354 -0
  13. package/dist/cli/skills/security-and-hardening/SKILL.md +471 -0
  14. package/dist/cli/skills/shipping-and-launch/SKILL.md +314 -0
  15. package/dist/cli/skills/source-driven-development/SKILL.md +198 -0
  16. package/dist/cli/skills/test-driven-development/SKILL.md +402 -0
  17. package/dist/cli-node/index.js +167 -1
  18. package/dist/features/dashboard/data-provider.d.ts +21 -1
  19. package/dist/features/dashboard/frontend/css/style.css +148 -1
  20. package/dist/features/dashboard/frontend/index.html +22 -0
  21. package/dist/features/dashboard/frontend/js/api.js +4 -0
  22. package/dist/features/dashboard/frontend/js/app.js +77 -2
  23. package/dist/features/dashboard/types.d.ts +9 -0
  24. package/dist/index.js +1 -1
  25. package/dist/skills/api-and-interface-design/SKILL.md +298 -0
  26. package/dist/skills/browser-testing-with-devtools/SKILL.md +321 -0
  27. package/dist/skills/ci-cd-and-automation/SKILL.md +394 -0
  28. package/dist/skills/context-engineering/SKILL.md +293 -0
  29. package/dist/skills/deprecation-and-migration/SKILL.md +251 -0
  30. package/dist/skills/documentation-and-adrs/SKILL.md +292 -0
  31. package/dist/skills/doubt-driven-development/SKILL.md +247 -0
  32. package/dist/skills/incremental-implementation/SKILL.md +253 -0
  33. package/dist/skills/interview-me/SKILL.md +229 -0
  34. package/dist/skills/observability-and-instrumentation/SKILL.md +207 -0
  35. package/dist/skills/performance-optimization/SKILL.md +354 -0
  36. package/dist/skills/security-and-hardening/SKILL.md +471 -0
  37. package/dist/skills/shipping-and-launch/SKILL.md +314 -0
  38. package/dist/skills/source-driven-development/SKILL.md +198 -0
  39. package/dist/skills/test-driven-development/SKILL.md +402 -0
  40. package/package.json +1 -1
  41. package/packages/shared-skills/skills/api-and-interface-design/SKILL.md +298 -0
  42. package/packages/shared-skills/skills/browser-testing-with-devtools/SKILL.md +321 -0
  43. package/packages/shared-skills/skills/ci-cd-and-automation/SKILL.md +394 -0
  44. package/packages/shared-skills/skills/context-engineering/SKILL.md +293 -0
  45. package/packages/shared-skills/skills/deprecation-and-migration/SKILL.md +251 -0
  46. package/packages/shared-skills/skills/documentation-and-adrs/SKILL.md +292 -0
  47. package/packages/shared-skills/skills/doubt-driven-development/SKILL.md +247 -0
  48. package/packages/shared-skills/skills/incremental-implementation/SKILL.md +253 -0
  49. package/packages/shared-skills/skills/interview-me/SKILL.md +229 -0
  50. package/packages/shared-skills/skills/observability-and-instrumentation/SKILL.md +207 -0
  51. package/packages/shared-skills/skills/performance-optimization/SKILL.md +354 -0
  52. package/packages/shared-skills/skills/security-and-hardening/SKILL.md +471 -0
  53. package/packages/shared-skills/skills/shipping-and-launch/SKILL.md +314 -0
  54. package/packages/shared-skills/skills/source-driven-development/SKILL.md +198 -0
  55. package/packages/shared-skills/skills/test-driven-development/SKILL.md +402 -0
package/dist/cli/index.js CHANGED
@@ -2163,7 +2163,7 @@ var package_default;
2163
2163
  var init_package = __esm(() => {
2164
2164
  package_default = {
2165
2165
  name: "@kl-c/matrixos",
2166
- version: "0.3.40",
2166
+ version: "0.3.42",
2167
2167
  description: "MaTrixOS \u2014 Agentic OS for OpenCode. Personalizable, communicating, self-improving, resilient.",
2168
2168
  main: "./dist/index.js",
2169
2169
  types: "dist/index.d.ts",
@@ -187049,6 +187049,23 @@ function ensureKanbanTable(db) {
187049
187049
  } catch {
187050
187050
  db.exec("ALTER TABLE matrixos_kanban ADD COLUMN output TEXT NOT NULL DEFAULT ''");
187051
187051
  }
187052
+ try {
187053
+ db.query("SELECT goal_id FROM matrixos_kanban LIMIT 1").all();
187054
+ } catch {
187055
+ db.exec("ALTER TABLE matrixos_kanban ADD COLUMN goal_id TEXT NOT NULL DEFAULT ''");
187056
+ }
187057
+ }
187058
+ function ensureGoalsTable(db) {
187059
+ db.exec(`
187060
+ CREATE TABLE IF NOT EXISTS matrixos_goals (
187061
+ id TEXT PRIMARY KEY,
187062
+ title TEXT NOT NULL,
187063
+ description TEXT NOT NULL DEFAULT '',
187064
+ status TEXT NOT NULL DEFAULT 'active',
187065
+ created_at INTEGER NOT NULL,
187066
+ updated_at INTEGER NOT NULL
187067
+ )
187068
+ `);
187052
187069
  }
187053
187070
  function midnightMs() {
187054
187071
  const d = new Date;
@@ -187452,6 +187469,125 @@ ${row.description ? `Description: ${row.description}
187452
187469
  db.close();
187453
187470
  }
187454
187471
  },
187472
+ async getGoals() {
187473
+ const db = getDbWrite();
187474
+ if (!db)
187475
+ return [];
187476
+ try {
187477
+ ensureGoalsTable(db);
187478
+ const rows = db.query("SELECT id, title, description, status, created_at, updated_at FROM matrixos_goals ORDER BY updated_at DESC").all();
187479
+ const result = [];
187480
+ for (const row of rows) {
187481
+ const taskRows = db.query("SELECT COUNT(*) as count FROM matrixos_kanban WHERE goal_id = ?").get(row.id);
187482
+ result.push({
187483
+ id: row.id,
187484
+ title: row.title,
187485
+ description: row.description || "",
187486
+ status: row.status,
187487
+ taskCount: taskRows?.count ?? 0,
187488
+ createdAt: new Date(row.created_at).toISOString(),
187489
+ updatedAt: new Date(row.updated_at).toISOString()
187490
+ });
187491
+ }
187492
+ return result;
187493
+ } catch {
187494
+ return [];
187495
+ } finally {
187496
+ db.close();
187497
+ }
187498
+ },
187499
+ async createGoal(input) {
187500
+ const db = getDbWrite();
187501
+ if (!db)
187502
+ return { ok: false, error: "database unavailable" };
187503
+ try {
187504
+ ensureGoalsTable(db);
187505
+ const id = `goal_${Date.now()}_${Math.random().toString(36).slice(2, 8)}`;
187506
+ const now = Date.now();
187507
+ db.query("INSERT INTO matrixos_goals (id, title, description, status, created_at, updated_at) VALUES (?, ?, ?, 'active', ?, ?)").run(id, input.title, input.description ?? "", now, now);
187508
+ return { ok: true, id };
187509
+ } catch (e) {
187510
+ return { ok: false, error: e instanceof Error ? e.message : String(e) };
187511
+ } finally {
187512
+ db.close();
187513
+ }
187514
+ },
187515
+ async decomposeGoal(id) {
187516
+ const db = getDbWrite();
187517
+ if (!db)
187518
+ return { ok: false, error: "database unavailable" };
187519
+ try {
187520
+ ensureGoalsTable(db);
187521
+ const row = db.query("SELECT title, description, status FROM matrixos_goals WHERE id = ?").get(id);
187522
+ if (!row)
187523
+ return { ok: false, error: "goal not found" };
187524
+ db.query("UPDATE matrixos_goals SET status = ?, updated_at = ? WHERE id = ?").run("decomposing", Date.now(), id);
187525
+ const brief = `Goal: ${row.title}
187526
+ ${row.description ? `Description: ${row.description}
187527
+ ` : ""}Decompose this goal into concrete Kanban tasks. Respond ONLY with a JSON array (no markdown, no prose) of objects: {"title": string, "description": string, "agent": string (one of morpheus/tank/oracle/link/ghost/the-analyst/the-keymaker/agent-smith/the-operator/neo/trinity/cypher/sentinel/mouse/dreamer/architect), "priority": "low"|"medium"|"high"|"urgent"}. Produce 2-6 tasks.`;
187528
+ const proc = Bun.spawn({
187529
+ cmd: ["matrixos", "run", "--agent", "morpheus", "--json", JSON.stringify(brief)],
187530
+ env: { ...process.env, PATH: `${process.env.PATH || ""}:/root/.bun/bin:/usr/bin` },
187531
+ stdout: "pipe",
187532
+ stderr: "pipe"
187533
+ });
187534
+ const result = await proc.exited;
187535
+ const decoder = new TextDecoder;
187536
+ const output = decoder.decode(await new Response(proc.stdout).arrayBuffer());
187537
+ const errOutput = decoder.decode(await new Response(proc.stderr).arrayBuffer());
187538
+ const combined = [output, errOutput].filter(Boolean).join(`
187539
+ `).slice(0, 4000);
187540
+ if (result !== 0) {
187541
+ db.query("UPDATE matrixos_goals SET status = ?, updated_at = ? WHERE id = ?").run("active", Date.now(), id);
187542
+ return { ok: false, error: "decomposition failed", output: combined, status: "active" };
187543
+ }
187544
+ const jsonMatch = combined.match(/\[[\s\S]*\]/);
187545
+ if (!jsonMatch) {
187546
+ db.query("UPDATE matrixos_goals SET status = ?, updated_at = ? WHERE id = ?").run("active", Date.now(), id);
187547
+ return { ok: false, error: "no task JSON in response", output: combined, status: "active" };
187548
+ }
187549
+ let tasks = [];
187550
+ try {
187551
+ tasks = JSON.parse(jsonMatch[0]);
187552
+ } catch {
187553
+ db.query("UPDATE matrixos_goals SET status = ?, updated_at = ? WHERE id = ?").run("active", Date.now(), id);
187554
+ return { ok: false, error: "invalid task JSON", output: combined, status: "active" };
187555
+ }
187556
+ let created = 0;
187557
+ for (const t2 of tasks) {
187558
+ if (!t2.title)
187559
+ continue;
187560
+ const tid = `kb_${Date.now()}_${Math.random().toString(36).slice(2, 8)}`;
187561
+ const now = Date.now();
187562
+ db.query("INSERT INTO matrixos_kanban (id, title, description, agent, status, priority, goal_id, created_at, updated_at) VALUES (?, ?, ?, ?, 'pending', ?, ?, ?, ?)").run(tid, t2.title, t2.description ?? "", t2.agent ?? "Morpheus", t2.priority ?? "medium", id, now, now);
187563
+ created++;
187564
+ }
187565
+ db.query("UPDATE matrixos_goals SET status = ?, updated_at = ? WHERE id = ?").run("completed", Date.now(), id);
187566
+ return { ok: true, tasks: created, output: combined, status: "completed" };
187567
+ } catch (e) {
187568
+ try {
187569
+ db.query("UPDATE matrixos_goals SET status = ?, updated_at = ? WHERE id = ?").run("active", Date.now(), id);
187570
+ } catch {}
187571
+ return { ok: false, error: e instanceof Error ? e.message : String(e), status: "active" };
187572
+ } finally {
187573
+ db.close();
187574
+ }
187575
+ },
187576
+ async deleteGoal(id) {
187577
+ const db = getDbWrite();
187578
+ if (!db)
187579
+ return { ok: false, error: "database unavailable" };
187580
+ try {
187581
+ ensureGoalsTable(db);
187582
+ db.query("DELETE FROM matrixos_kanban WHERE goal_id = ?").run(id);
187583
+ db.query("DELETE FROM matrixos_goals WHERE id = ?").run(id);
187584
+ return { ok: true };
187585
+ } catch (e) {
187586
+ return { ok: false, error: e instanceof Error ? e.message : String(e) };
187587
+ } finally {
187588
+ db.close();
187589
+ }
187590
+ },
187455
187591
  async getIncidents(limit = 50) {
187456
187592
  const lines = readJsonl("anti-loop.jsonl");
187457
187593
  if (lines.length === 0) {
@@ -187804,6 +187940,36 @@ function createDashboardServer(dataProvider, config5) {
187804
187940
  const result = await dataProvider.executeKanbanTask(body.id);
187805
187941
  return Response.json(result, { status: result.ok ? 200 : 500, headers: jsonHeaders });
187806
187942
  }
187943
+ case "/api/goals": {
187944
+ if (req.method === "POST") {
187945
+ const body = await req.json();
187946
+ if (!body.title || !body.title.trim()) {
187947
+ return Response.json({ ok: false, error: "title required" }, { status: 400, headers: jsonHeaders });
187948
+ }
187949
+ const result = await dataProvider.createGoal(body);
187950
+ return Response.json(result, { status: result.ok ? 201 : 500, headers: jsonHeaders });
187951
+ }
187952
+ if (req.method === "DELETE") {
187953
+ const id = url3.searchParams.get("id");
187954
+ if (!id) {
187955
+ return Response.json({ ok: false, error: "id required" }, { status: 400, headers: jsonHeaders });
187956
+ }
187957
+ const result = await dataProvider.deleteGoal(id);
187958
+ return Response.json(result, { status: result.ok ? 200 : 500, headers: jsonHeaders });
187959
+ }
187960
+ return Response.json(await dataProvider.getGoals(), { headers: jsonHeaders });
187961
+ }
187962
+ case "/api/goals/decompose": {
187963
+ if (req.method !== "POST") {
187964
+ return new Response("Method Not Allowed", { status: 405, headers: corsHeaders });
187965
+ }
187966
+ const body = await req.json();
187967
+ if (!body.id) {
187968
+ return Response.json({ ok: false, error: "id required" }, { status: 400, headers: jsonHeaders });
187969
+ }
187970
+ const result = await dataProvider.decomposeGoal(body.id);
187971
+ return Response.json(result, { status: result.ok ? 200 : 500, headers: jsonHeaders });
187972
+ }
187807
187973
  case "/api/incidents": {
187808
187974
  const limit = parseInt(url3.searchParams.get("limit") ?? "50", 10);
187809
187975
  return Response.json(await dataProvider.getIncidents(limit), { headers: jsonHeaders });
@@ -0,0 +1,298 @@
1
+ ---
2
+ name: api-and-interface-design
3
+ description: Guides stable API and interface design. Use when designing APIs, module boundaries, or any public interface. Use when creating REST or GraphQL endpoints, defining type contracts between modules, or establishing boundaries between frontend and backend.
4
+ source: addyosmani/agent-skills (MIT)
5
+ ---
6
+
7
+ # API and Interface Design
8
+
9
+ ## Overview
10
+
11
+ Design stable, well-documented interfaces that are hard to misuse. Good interfaces make the right thing easy and the wrong thing hard. This applies to REST APIs, GraphQL schemas, module boundaries, component props, and any surface where one piece of code talks to another.
12
+
13
+ ## When to Use
14
+
15
+ - Designing new API endpoints
16
+ - Defining module boundaries or contracts between teams
17
+ - Creating component prop interfaces
18
+ - Establishing database schema that informs API shape
19
+ - Changing existing public interfaces
20
+
21
+ ## Core Principles
22
+
23
+ ### Hyrum's Law
24
+
25
+ > With a sufficient number of users of an API, all observable behaviors of your system will be depended on by somebody, regardless of what you promise in the contract.
26
+
27
+ This means: every public behavior — including undocumented quirks, error message text, timing, and ordering — becomes a de facto contract once users depend on it. Design implications:
28
+
29
+ - **Be intentional about what you expose.** Every observable behavior is a potential commitment.
30
+ - **Don't leak implementation details.** If users can observe it, they will depend on it.
31
+ - **Plan for deprecation at design time.** See `deprecation-and-migration` for how to safely remove things users depend on.
32
+ - **Tests are not enough.** Even with perfect contract tests, Hyrum's Law means "safe" changes can break real users who depend on undocumented behavior.
33
+
34
+ ### The One-Version Rule
35
+
36
+ Avoid forcing consumers to choose between multiple versions of the same dependency or API. Diamond dependency problems arise when different consumers need different versions of the same thing. Design for a world where only one version exists at a time — extend rather than fork.
37
+
38
+ ### 1. Contract First
39
+
40
+ Define the interface before implementing it. The contract is the spec — implementation follows.
41
+
42
+ ```typescript
43
+ // Define the contract first
44
+ interface TaskAPI {
45
+ // Creates a task and returns the created task with server-generated fields
46
+ createTask(input: CreateTaskInput): Promise<Task>;
47
+
48
+ // Returns paginated tasks matching filters
49
+ listTasks(params: ListTasksParams): Promise<PaginatedResult<Task>>;
50
+
51
+ // Returns a single task or throws NotFoundError
52
+ getTask(id: string): Promise<Task>;
53
+
54
+ // Partial update — only provided fields change
55
+ updateTask(id: string, input: UpdateTaskInput): Promise<Task>;
56
+
57
+ // Idempotent delete — succeeds even if already deleted
58
+ deleteTask(id: string): Promise<void>;
59
+ }
60
+ ```
61
+
62
+ ### 2. Consistent Error Semantics
63
+
64
+ Pick one error strategy and use it everywhere:
65
+
66
+ ```typescript
67
+ // REST: HTTP status codes + structured error body
68
+ // Every error response follows the same shape
69
+ interface APIError {
70
+ error: {
71
+ code: string; // Machine-readable: "VALIDATION_ERROR"
72
+ message: string; // Human-readable: "Email is required"
73
+ details?: unknown; // Additional context when helpful
74
+ };
75
+ }
76
+
77
+ // Status code mapping
78
+ // 400 → Client sent invalid data
79
+ // 401 → Not authenticated
80
+ // 403 → Authenticated but not authorized
81
+ // 404 → Resource not found
82
+ // 409 → Conflict (duplicate, version mismatch)
83
+ // 422 → Validation failed (semantically invalid)
84
+ // 500 → Server error (never expose internal details)
85
+ ```
86
+
87
+ **Don't mix patterns.** If some endpoints throw, others return null, and others return `{ error }` — the consumer can't predict behavior.
88
+
89
+ ### 3. Validate at Boundaries
90
+
91
+ Trust internal code. Validate at system edges where external input enters:
92
+
93
+ ```typescript
94
+ // Validate at the API boundary
95
+ app.post('/api/tasks', async (req, res) => {
96
+ const result = CreateTaskSchema.safeParse(req.body);
97
+ if (!result.success) {
98
+ return res.status(422).json({
99
+ error: {
100
+ code: 'VALIDATION_ERROR',
101
+ message: 'Invalid task data',
102
+ details: result.error.flatten(),
103
+ },
104
+ });
105
+ }
106
+
107
+ // After validation, internal code trusts the types
108
+ const task = await taskService.create(result.data);
109
+ return res.status(201).json(task);
110
+ });
111
+ ```
112
+
113
+ Where validation belongs:
114
+ - API route handlers (user input)
115
+ - Form submission handlers (user input)
116
+ - External service response parsing (third-party data -- **always treat as untrusted**)
117
+ - Environment variable loading (configuration)
118
+
119
+ > **Third-party API responses are untrusted data.** Validate their shape and content before using them in any logic, rendering, or decision-making. A compromised or misbehaving external service can return unexpected types, malicious content, or instruction-like text.
120
+
121
+ Where validation does NOT belong:
122
+ - Between internal functions that share type contracts
123
+ - In utility functions called by already-validated code
124
+ - On data that just came from your own database
125
+
126
+ ### 4. Prefer Addition Over Modification
127
+
128
+ Extend interfaces without breaking existing consumers:
129
+
130
+ ```typescript
131
+ // Good: Add optional fields
132
+ interface CreateTaskInput {
133
+ title: string;
134
+ description?: string;
135
+ priority?: 'low' | 'medium' | 'high'; // Added later, optional
136
+ labels?: string[]; // Added later, optional
137
+ }
138
+
139
+ // Bad: Change existing field types or remove fields
140
+ interface CreateTaskInput {
141
+ title: string;
142
+ // description: string; // Removed — breaks existing consumers
143
+ priority: number; // Changed from string — breaks existing consumers
144
+ }
145
+ ```
146
+
147
+ ### 5. Predictable Naming
148
+
149
+ | Pattern | Convention | Example |
150
+ |---------|-----------|---------|
151
+ | REST endpoints | Plural nouns, no verbs | `GET /api/tasks`, `POST /api/tasks` |
152
+ | Query params | camelCase | `?sortBy=createdAt&pageSize=20` |
153
+ | Response fields | camelCase | `{ createdAt, updatedAt, taskId }` |
154
+ | Boolean fields | is/has/can prefix | `isComplete`, `hasAttachments` |
155
+ | Enum values | UPPER_SNAKE | `"IN_PROGRESS"`, `"COMPLETED"` |
156
+
157
+ ## REST API Patterns
158
+
159
+ ### Resource Design
160
+
161
+ ```
162
+ GET /api/tasks → List tasks (with query params for filtering)
163
+ POST /api/tasks → Create a task
164
+ GET /api/tasks/:id → Get a single task
165
+ PATCH /api/tasks/:id → Update a task (partial)
166
+ DELETE /api/tasks/:id → Delete a task
167
+
168
+ GET /api/tasks/:id/comments → List comments for a task (sub-resource)
169
+ POST /api/tasks/:id/comments → Add a comment to a task
170
+ ```
171
+
172
+ ### Pagination
173
+
174
+ Paginate list endpoints:
175
+
176
+ ```typescript
177
+ // Request
178
+ GET /api/tasks?page=1&pageSize=20&sortBy=createdAt&sortOrder=desc
179
+
180
+ // Response
181
+ {
182
+ "data": [...],
183
+ "pagination": {
184
+ "page": 1,
185
+ "pageSize": 20,
186
+ "totalItems": 142,
187
+ "totalPages": 8
188
+ }
189
+ }
190
+ ```
191
+
192
+ ### Filtering
193
+
194
+ Use query parameters for filters:
195
+
196
+ ```
197
+ GET /api/tasks?status=in_progress&assignee=user123&createdAfter=2025-01-01
198
+ ```
199
+
200
+ ### Partial Updates (PATCH)
201
+
202
+ Accept partial objects — only update what's provided:
203
+
204
+ ```typescript
205
+ // Only title changes, everything else preserved
206
+ PATCH /api/tasks/123
207
+ { "title": "Updated title" }
208
+ ```
209
+
210
+ ## TypeScript Interface Patterns
211
+
212
+ ### Use Discriminated Unions for Variants
213
+
214
+ ```typescript
215
+ // Good: Each variant is explicit
216
+ type TaskStatus =
217
+ | { type: 'pending' }
218
+ | { type: 'in_progress'; assignee: string; startedAt: Date }
219
+ | { type: 'completed'; completedAt: Date; completedBy: string }
220
+ | { type: 'cancelled'; reason: string; cancelledAt: Date };
221
+
222
+ // Consumer gets type narrowing
223
+ function getStatusLabel(status: TaskStatus): string {
224
+ switch (status.type) {
225
+ case 'pending': return 'Pending';
226
+ case 'in_progress': return `In progress (${status.assignee})`;
227
+ case 'completed': return `Done on ${status.completedAt}`;
228
+ case 'cancelled': return `Cancelled: ${status.reason}`;
229
+ }
230
+ }
231
+ ```
232
+
233
+ ### Input/Output Separation
234
+
235
+ ```typescript
236
+ // Input: what the caller provides
237
+ interface CreateTaskInput {
238
+ title: string;
239
+ description?: string;
240
+ }
241
+
242
+ // Output: what the system returns (includes server-generated fields)
243
+ interface Task {
244
+ id: string;
245
+ title: string;
246
+ description: string | null;
247
+ createdAt: Date;
248
+ updatedAt: Date;
249
+ createdBy: string;
250
+ }
251
+ ```
252
+
253
+ ### Use Branded Types for IDs
254
+
255
+ ```typescript
256
+ type TaskId = string & { readonly __brand: 'TaskId' };
257
+ type UserId = string & { readonly __brand: 'UserId' };
258
+
259
+ // Prevents accidentally passing a UserId where a TaskId is expected
260
+ function getTask(id: TaskId): Promise<Task> { ... }
261
+ ```
262
+
263
+ ## Common Rationalizations
264
+
265
+ | Rationalization | Reality |
266
+ |---|---|
267
+ | "We'll document the API later" | The types ARE the documentation. Define them first. |
268
+ | "We don't need pagination for now" | You will the moment someone has 100+ items. Add it from the start. |
269
+ | "PATCH is complicated, let's just use PUT" | PUT requires the full object every time. PATCH is what clients actually want. |
270
+ | "We'll version the API when we need to" | Breaking changes without versioning break consumers. Design for extension from the start. |
271
+ | "Nobody uses that undocumented behavior" | Hyrum's Law: if it's observable, somebody depends on it. Treat every public behavior as a commitment. |
272
+ | "We can just maintain two versions" | Multiple versions multiply maintenance cost and create diamond dependency problems. Prefer the One-Version Rule. |
273
+ | "Internal APIs don't need contracts" | Internal consumers are still consumers. Contracts prevent coupling and enable parallel work. |
274
+
275
+ ## Red Flags
276
+
277
+ - Endpoints that return different shapes depending on conditions
278
+ - Inconsistent error formats across endpoints
279
+ - Validation scattered throughout internal code instead of at boundaries
280
+ - Breaking changes to existing fields (type changes, removals)
281
+ - List endpoints without pagination
282
+ - Verbs in REST URLs (`/api/createTask`, `/api/getUsers`)
283
+ - Third-party API responses used without validation or sanitization
284
+
285
+ ## Verification
286
+
287
+ After designing an API:
288
+
289
+ - [ ] Every endpoint has typed input and output schemas
290
+ - [ ] Error responses follow a single consistent format
291
+ - [ ] Validation happens at system boundaries only
292
+ - [ ] List endpoints support pagination
293
+ - [ ] New fields are additive and optional (backward compatible)
294
+ - [ ] Naming follows consistent conventions across all endpoints
295
+ - [ ] API documentation or types are committed alongside the implementation
296
+
297
+ ---
298
+ *Source: addyosmani/agent-skills (MIT). Ported into MaTrixOS shared-skills bundle.*