@vpxa/aikit 0.1.73 → 0.1.75

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 (142) hide show
  1. package/package.json +9 -1
  2. package/packages/cli/dist/index.js +2 -2
  3. package/packages/cli/dist/{init-D_OGLUN1.js → init-CuRXmyD9.js} +4 -4
  4. package/packages/cli/dist/scaffold-WMQ2uQ48.js +2 -0
  5. package/packages/cli/dist/{templates-DJ7EC5vw.js → templates-ArdAVWoY.js} +13 -3
  6. package/packages/cli/dist/user-vbJwa7x2.js +5 -0
  7. package/packages/dashboard/dist/assets/index-C6D-PCp0.js.map +1 -1
  8. package/packages/flows/dist/index.d.ts +29 -0
  9. package/packages/flows/dist/index.js +1 -1
  10. package/packages/server/dist/index.js +1 -1
  11. package/packages/server/dist/{server-B9Mx1aK-.js → server-CVhVH5cT.js} +127 -127
  12. package/packages/tools/dist/index.d.ts +19 -1
  13. package/packages/tools/dist/index.js +39 -39
  14. package/scaffold/dist/adapters/claude-code.mjs +4 -0
  15. package/scaffold/dist/adapters/copilot.mjs +75 -0
  16. package/scaffold/dist/adapters/flows.mjs +1 -0
  17. package/scaffold/dist/adapters/skills.mjs +1 -0
  18. package/scaffold/dist/compiled/flows-data.mjs +1429 -0
  19. package/scaffold/dist/compiled/skills-data.mjs +9951 -0
  20. package/scaffold/dist/definitions/agents.mjs +9 -0
  21. package/scaffold/{definitions → dist/definitions}/bodies.mjs +6 -229
  22. package/scaffold/dist/definitions/exclusions.mjs +1 -0
  23. package/scaffold/dist/definitions/hooks.mjs +1 -0
  24. package/scaffold/dist/definitions/models.mjs +1 -0
  25. package/scaffold/dist/definitions/plugins.mjs +1 -0
  26. package/scaffold/{definitions → dist/definitions}/prompts.mjs +9 -149
  27. package/scaffold/{definitions → dist/definitions}/protocols.mjs +9 -37
  28. package/scaffold/dist/definitions/tools.mjs +1 -0
  29. package/packages/cli/dist/scaffold-CJwkHf-q.js +0 -2
  30. package/packages/cli/dist/user-BEmVW8Tp.js +0 -5
  31. package/scaffold/adapters/claude-code.mjs +0 -73
  32. package/scaffold/adapters/copilot.mjs +0 -292
  33. package/scaffold/definitions/agents.mjs +0 -266
  34. package/scaffold/definitions/hooks.mjs +0 -43
  35. package/scaffold/definitions/models.mjs +0 -84
  36. package/scaffold/definitions/plugins.mjs +0 -147
  37. package/scaffold/definitions/tools.mjs +0 -250
  38. package/scaffold/flows/_epilogue/steps/docs-sync/README.md +0 -120
  39. package/scaffold/flows/aikit-advanced/README.md +0 -70
  40. package/scaffold/flows/aikit-advanced/flow.json +0 -69
  41. package/scaffold/flows/aikit-advanced/steps/design/README.md +0 -178
  42. package/scaffold/flows/aikit-advanced/steps/execute/README.md +0 -145
  43. package/scaffold/flows/aikit-advanced/steps/plan/README.md +0 -122
  44. package/scaffold/flows/aikit-advanced/steps/spec/README.md +0 -121
  45. package/scaffold/flows/aikit-advanced/steps/task/README.md +0 -119
  46. package/scaffold/flows/aikit-advanced/steps/verify/README.md +0 -145
  47. package/scaffold/flows/aikit-basic/README.md +0 -51
  48. package/scaffold/flows/aikit-basic/flow.json +0 -45
  49. package/scaffold/flows/aikit-basic/steps/assess/README.md +0 -109
  50. package/scaffold/flows/aikit-basic/steps/design/README.md +0 -116
  51. package/scaffold/flows/aikit-basic/steps/implement/README.md +0 -131
  52. package/scaffold/flows/aikit-basic/steps/verify/README.md +0 -123
  53. package/scaffold/general/agents/Architect-Reviewer-Alpha.agent.md +0 -132
  54. package/scaffold/general/agents/Architect-Reviewer-Beta.agent.md +0 -132
  55. package/scaffold/general/agents/Code-Reviewer-Alpha.agent.md +0 -112
  56. package/scaffold/general/agents/Code-Reviewer-Beta.agent.md +0 -112
  57. package/scaffold/general/agents/Debugger.agent.md +0 -412
  58. package/scaffold/general/agents/Documenter.agent.md +0 -468
  59. package/scaffold/general/agents/Explorer.agent.md +0 -76
  60. package/scaffold/general/agents/Frontend.agent.md +0 -440
  61. package/scaffold/general/agents/Implementer.agent.md +0 -425
  62. package/scaffold/general/agents/Orchestrator.agent.md +0 -452
  63. package/scaffold/general/agents/Planner.agent.md +0 -481
  64. package/scaffold/general/agents/README.md +0 -57
  65. package/scaffold/general/agents/Refactor.agent.md +0 -435
  66. package/scaffold/general/agents/Researcher-Alpha.agent.md +0 -151
  67. package/scaffold/general/agents/Researcher-Beta.agent.md +0 -152
  68. package/scaffold/general/agents/Researcher-Delta.agent.md +0 -153
  69. package/scaffold/general/agents/Researcher-Gamma.agent.md +0 -152
  70. package/scaffold/general/agents/Security.agent.md +0 -433
  71. package/scaffold/general/agents/_shared/architect-reviewer-base.md +0 -104
  72. package/scaffold/general/agents/_shared/code-agent-base.md +0 -366
  73. package/scaffold/general/agents/_shared/code-reviewer-base.md +0 -87
  74. package/scaffold/general/agents/_shared/decision-protocol.md +0 -27
  75. package/scaffold/general/agents/_shared/forge-protocol.md +0 -90
  76. package/scaffold/general/agents/_shared/researcher-base.md +0 -114
  77. package/scaffold/general/agents/templates/adr-template.md +0 -28
  78. package/scaffold/general/agents/templates/execution-state.md +0 -26
  79. package/scaffold/general/prompts/aikit-ask.prompt.md +0 -13
  80. package/scaffold/general/prompts/aikit-debug.prompt.md +0 -15
  81. package/scaffold/general/prompts/aikit-design.prompt.md +0 -15
  82. package/scaffold/general/prompts/aikit-flow-add.prompt.md +0 -84
  83. package/scaffold/general/prompts/aikit-flow-create.prompt.md +0 -80
  84. package/scaffold/general/prompts/aikit-flow-manage.prompt.md +0 -24
  85. package/scaffold/general/prompts/aikit-implement.prompt.md +0 -17
  86. package/scaffold/general/prompts/aikit-plan.prompt.md +0 -15
  87. package/scaffold/general/prompts/aikit-review.prompt.md +0 -24
  88. package/scaffold/general/skills/adr-skill/SKILL.md +0 -335
  89. package/scaffold/general/skills/adr-skill/assets/templates/adr-madr.md +0 -89
  90. package/scaffold/general/skills/adr-skill/assets/templates/adr-readme.md +0 -20
  91. package/scaffold/general/skills/adr-skill/assets/templates/adr-simple.md +0 -46
  92. package/scaffold/general/skills/adr-skill/references/adr-conventions.md +0 -95
  93. package/scaffold/general/skills/adr-skill/references/examples.md +0 -193
  94. package/scaffold/general/skills/adr-skill/references/review-checklist.md +0 -77
  95. package/scaffold/general/skills/adr-skill/references/template-variants.md +0 -52
  96. package/scaffold/general/skills/adr-skill/scripts/bootstrap_adr.js +0 -259
  97. package/scaffold/general/skills/adr-skill/scripts/new_adr.js +0 -391
  98. package/scaffold/general/skills/adr-skill/scripts/set_adr_status.js +0 -169
  99. package/scaffold/general/skills/aikit/SKILL.md +0 -754
  100. package/scaffold/general/skills/brainstorming/SKILL.md +0 -265
  101. package/scaffold/general/skills/brainstorming/spec-document-reviewer-prompt.md +0 -49
  102. package/scaffold/general/skills/c4-architecture/SKILL.md +0 -389
  103. package/scaffold/general/skills/c4-architecture/references/advanced-patterns.md +0 -552
  104. package/scaffold/general/skills/c4-architecture/references/c4-syntax.md +0 -510
  105. package/scaffold/general/skills/c4-architecture/references/common-mistakes.md +0 -437
  106. package/scaffold/general/skills/c4-architecture/references/html-design-system.md +0 -337
  107. package/scaffold/general/skills/c4-architecture/references/html-template.html +0 -627
  108. package/scaffold/general/skills/docs/SKILL.md +0 -553
  109. package/scaffold/general/skills/docs/references/diataxis-anti-patterns.md +0 -147
  110. package/scaffold/general/skills/docs/references/diataxis-compass.md +0 -123
  111. package/scaffold/general/skills/docs/references/diataxis-quadrants.md +0 -192
  112. package/scaffold/general/skills/docs/references/diataxis-quality.md +0 -76
  113. package/scaffold/general/skills/docs/references/diataxis-templates.md +0 -120
  114. package/scaffold/general/skills/docs/references/flow-artifacts-guide.md +0 -70
  115. package/scaffold/general/skills/docs/references/project-knowledge-gotchas.md +0 -32
  116. package/scaffold/general/skills/docs/references/project-knowledge-templates.md +0 -281
  117. package/scaffold/general/skills/docs/references/project-knowledge-workflow.md +0 -80
  118. package/scaffold/general/skills/frontend-design/SKILL.md +0 -237
  119. package/scaffold/general/skills/lesson-learned/SKILL.md +0 -113
  120. package/scaffold/general/skills/lesson-learned/references/anti-patterns.md +0 -55
  121. package/scaffold/general/skills/lesson-learned/references/se-principles.md +0 -109
  122. package/scaffold/general/skills/multi-agents-development/SKILL.md +0 -448
  123. package/scaffold/general/skills/multi-agents-development/architecture-review-prompt.md +0 -81
  124. package/scaffold/general/skills/multi-agents-development/code-quality-review-prompt.md +0 -91
  125. package/scaffold/general/skills/multi-agents-development/implementer-prompt.md +0 -93
  126. package/scaffold/general/skills/multi-agents-development/parallel-dispatch-example.md +0 -167
  127. package/scaffold/general/skills/multi-agents-development/spec-review-prompt.md +0 -81
  128. package/scaffold/general/skills/present/SKILL.md +0 -616
  129. package/scaffold/general/skills/react/SKILL.md +0 -309
  130. package/scaffold/general/skills/repo-access/SKILL.md +0 -178
  131. package/scaffold/general/skills/repo-access/references/error-patterns.md +0 -116
  132. package/scaffold/general/skills/repo-access/references/platform-matrix.md +0 -142
  133. package/scaffold/general/skills/requirements-clarity/SKILL.md +0 -333
  134. package/scaffold/general/skills/session-handoff/SKILL.md +0 -199
  135. package/scaffold/general/skills/session-handoff/references/handoff-template.md +0 -139
  136. package/scaffold/general/skills/session-handoff/references/resume-checklist.md +0 -80
  137. package/scaffold/general/skills/session-handoff/scripts/check_staleness.js +0 -269
  138. package/scaffold/general/skills/session-handoff/scripts/create_handoff.js +0 -299
  139. package/scaffold/general/skills/session-handoff/scripts/list_handoffs.js +0 -113
  140. package/scaffold/general/skills/session-handoff/scripts/validate_handoff.js +0 -241
  141. package/scaffold/general/skills/typescript/SKILL.md +0 -405
  142. package/scaffold/generate.mjs +0 -82
@@ -1,405 +0,0 @@
1
- ---
2
- name: typescript
3
- description: "Comprehensive TypeScript development patterns — type system performance, compiler configuration, advanced types, type safety, async patterns, module organization, and runtime optimization."
4
- metadata:
5
- category: domain
6
- domain: typescript
7
- applicability: on-demand
8
- inputs: [codebase, requirements]
9
- outputs: [type-patterns, code]
10
- relatedSkills: [react]
11
- ---
12
-
13
- # TypeScript
14
-
15
- > Comprehensive TypeScript development patterns — type system performance, compiler configuration, advanced types, type safety, async patterns, module organization, and runtime optimization. Synthesized from pproenca TypeScript rules, TypeScript 6.0 features, wshobson advanced types and modern JS patterns, and Jeffallan typescript-pro patterns.
16
-
17
- ## When to Use
18
-
19
- **MANDATORY** for the Implementer agent on every TypeScript task. Also use when:
20
- - Writing or reviewing TypeScript code
21
- - Configuring `tsconfig.json` or compiler options
22
- - Designing type-safe APIs, libraries, or utilities
23
- - Optimizing type-check performance or build times
24
-
25
- ## Type System Performance
26
-
27
- These rules prevent slow type-checking and IDE lag:
28
-
29
- ### Prefer Flat Unions Over Deep Conditionals
30
- ```tsx
31
- // BAD — O(n²) type checking with deep conditionals
32
- type DeepResolve<T> = T extends Promise<infer U> ? DeepResolve<U> : T extends Array<infer V> ? DeepResolve<V>[] : T;
33
-
34
- // GOOD — flat unions check in O(n)
35
- type Status = "idle" | "loading" | "success" | "error";
36
- type Result = SuccessResult | ErrorResult | PendingResult;
37
- ```
38
-
39
- ### Interface Extends Over Intersection
40
- ```tsx
41
- // BAD — intersection types are expensive to compute
42
- type Extended = BaseType & { extra: string } & { more: number };
43
-
44
- // GOOD — interface extends is cached by the compiler
45
- interface Extended extends BaseType {
46
- extra: string;
47
- more: number;
48
- }
49
- ```
50
-
51
- ### Rules
52
- - **Avoid recursive conditional types** deeper than 3 levels — use iterative mapped types instead
53
- - **Minimize computed types** in hot paths (function parameters, return types used in many places)
54
- - **Use `interface` for object shapes**, `type` for unions, intersections, and mapped types
55
- - **Annotate complex return types** explicitly — don't force the compiler to infer through 5 layers
56
- - **Avoid generic defaults that trigger deep inference** — provide explicit type arguments at call sites
57
- - **Break circular type references** — extract shared shapes into separate interfaces
58
-
59
- ## Compiler Configuration
60
-
61
- ### Strict Mode (all projects)
62
- ```jsonc
63
- {
64
- "compilerOptions": {
65
- "strict": true, // Enables ALL strict checks
66
- "noUncheckedIndexedAccess": true, // arr[0] is T | undefined
67
- "exactOptionalProperties": true, // undefined ≠ missing
68
- "noFallthroughCasesInSwitch": true,
69
- "forceConsistentCasingInFileNames": true,
70
- "isolatedModules": true, // Required for most bundlers
71
- "verbatimModuleSyntax": true // Explicit import/export type
72
- }
73
- }
74
- ```
75
-
76
- ### Build Performance
77
- ```jsonc
78
- {
79
- "compilerOptions": {
80
- "incremental": true, // Cache type-check results
81
- "tsBuildInfoFile": ".tsbuildinfo",
82
- "skipLibCheck": true // Skip .d.ts checking (safe for apps)
83
- }
84
- }
85
- ```
86
-
87
- ### Project References (monorepos)
88
- ```jsonc
89
- // tsconfig.json (root)
90
- {
91
- "references": [
92
- { "path": "packages/core" },
93
- { "path": "packages/server" },
94
- { "path": "packages/cli" }
95
- ]
96
- }
97
-
98
- // packages/core/tsconfig.json
99
- {
100
- "compilerOptions": {
101
- "composite": true,
102
- "declaration": true,
103
- "declarationMap": true
104
- }
105
- }
106
- ```
107
-
108
- ### TypeScript 6.0+ Features
109
- - **`#/` subpath imports**: `import { utils } from "#/lib/utils"` — no more `../../../` relative paths. Configure in `package.json` `"imports"` field.
110
- - **`es2025` target**: Set, Iterator, Promise.withResolvers, RegExp v flag
111
- - **`--noCheck`**: Skip type-checking in CI (when pre-checked) for faster builds
112
- - **`--stableTypeOrdering`**: Deterministic declaration output for reproducible builds
113
- - **`isolatedDeclarations`**: Generate `.d.ts` without type-checking — enables parallel builds
114
-
115
- ## Advanced Types
116
-
117
- ### Constrained Generics
118
- ```tsx
119
- // Constrain to ensure property exists
120
- function getProperty<T, K extends keyof T>(obj: T, key: K): T[K] {
121
- return obj[key];
122
- }
123
-
124
- // Constrain with interface
125
- function merge<T extends Record<string, unknown>>(target: T, source: Partial<T>): T {
126
- return { ...target, ...source };
127
- }
128
- ```
129
-
130
- ### Conditional Types
131
- ```tsx
132
- // Extract return type from async function
133
- type UnwrapPromise<T> = T extends Promise<infer U> ? U : T;
134
-
135
- // Distributive conditional
136
- type NonNullableDeep<T> = T extends null | undefined ? never : T extends object ? { [K in keyof T]: NonNullableDeep<T[K]> } : T;
137
-
138
- // Infer from function
139
- type Parameters<T> = T extends (...args: infer P) => unknown ? P : never;
140
- ```
141
-
142
- ### Mapped Types
143
- ```tsx
144
- // Make all properties optional recursively
145
- type DeepPartial<T> = { [P in keyof T]?: T[P] extends object ? DeepPartial<T[P]> : T[P] };
146
-
147
- // Remove readonly
148
- type Mutable<T> = { -readonly [P in keyof T]: T[P] };
149
-
150
- // Key remapping
151
- type Getters<T> = { [K in keyof T as `get${Capitalize<string & K>}`]: () => T[K] };
152
- ```
153
-
154
- ### Template Literal Types
155
- ```tsx
156
- // Event name typing
157
- type EventName<T extends string> = `on${Capitalize<T>}`;
158
- type Events = EventName<"click" | "focus" | "blur">; // "onClick" | "onFocus" | "onBlur"
159
-
160
- // Route parameter extraction
161
- type ExtractParams<T extends string> =
162
- T extends `${string}:${infer Param}/${infer Rest}`
163
- ? Param | ExtractParams<Rest>
164
- : T extends `${string}:${infer Param}`
165
- ? Param
166
- : never;
167
- type Params = ExtractParams<"/users/:id/posts/:postId">; // "id" | "postId"
168
- ```
169
-
170
- ### Utility Type Patterns
171
- ```tsx
172
- // Deep readonly
173
- type DeepReadonly<T> = { readonly [P in keyof T]: T[P] extends object ? DeepReadonly<T[P]> : T[P] };
174
-
175
- // Make specific keys required
176
- type RequireKeys<T, K extends keyof T> = T & Required<Pick<T, K>>;
177
-
178
- // Object paths as union
179
- type Paths<T, D extends number = 3> = [D] extends [never]
180
- ? never
181
- : T extends object
182
- ? { [K in keyof T]-?: K extends string ? `${K}` | `${K}.${Paths<T[K]>}` : never }[keyof T]
183
- : never;
184
- ```
185
-
186
- ## Type Safety Patterns
187
-
188
- ### Branded Types
189
- ```tsx
190
- // Prevent mixing IDs of different entities
191
- type UserId = string & { readonly __brand: "UserId" };
192
- type OrderId = string & { readonly __brand: "OrderId" };
193
-
194
- function createUserId(id: string): UserId { return id as UserId; }
195
- function createOrderId(id: string): OrderId { return id as OrderId; }
196
-
197
- function getUser(id: UserId) { /* ... */ }
198
- getUser(createOrderId("123")); // TS Error! OrderId is not UserId
199
- ```
200
-
201
- ### Discriminated Unions with Exhaustive Matching
202
- ```tsx
203
- type Shape =
204
- | { kind: "circle"; radius: number }
205
- | { kind: "rect"; width: number; height: number }
206
- | { kind: "triangle"; base: number; height: number };
207
-
208
- function area(shape: Shape): number {
209
- switch (shape.kind) {
210
- case "circle": return Math.PI * shape.radius ** 2;
211
- case "rect": return shape.width * shape.height;
212
- case "triangle": return 0.5 * shape.base * shape.height;
213
- default: {
214
- const _exhaustive: never = shape; // Compile error if case missed
215
- return _exhaustive;
216
- }
217
- }
218
- }
219
- ```
220
-
221
- ### Result Pattern
222
- ```tsx
223
- type Result<T, E = Error> = { ok: true; value: T } | { ok: false; error: E };
224
-
225
- function ok<T>(value: T): Result<T, never> { return { ok: true, value }; }
226
- function err<E>(error: E): Result<never, E> { return { ok: false, error }; }
227
-
228
- async function parseConfig(path: string): Promise<Result<Config, ParseError>> {
229
- try {
230
- const raw = await readFile(path, "utf-8");
231
- return ok(JSON.parse(raw));
232
- } catch (e) {
233
- return err(new ParseError(`Failed to parse ${path}`, { cause: e }));
234
- }
235
- }
236
-
237
- // Usage — forces error handling
238
- const result = await parseConfig("config.json");
239
- if (!result.ok) {
240
- console.error(result.error.message);
241
- process.exit(1);
242
- }
243
- const config = result.value; // Type-narrowed to Config
244
- ```
245
-
246
- ## Async Patterns
247
-
248
- ### Parallel Execution
249
- ```tsx
250
- // Promise.all — fail-fast on first rejection
251
- const [users, posts] = await Promise.all([getUsers(), getPosts()]);
252
-
253
- // Promise.allSettled — get all results regardless of failures
254
- const results = await Promise.allSettled([getUsers(), getPosts(), getComments()]);
255
- for (const r of results) {
256
- if (r.status === "fulfilled") process(r.value);
257
- else logError(r.reason);
258
- }
259
- ```
260
-
261
- ### AbortController
262
- ```tsx
263
- async function fetchWithTimeout(url: string, timeoutMs: number): Promise<Response> {
264
- const controller = new AbortController();
265
- const timeout = setTimeout(() => controller.abort(), timeoutMs);
266
- try {
267
- return await fetch(url, { signal: controller.signal });
268
- } finally {
269
- clearTimeout(timeout);
270
- }
271
- }
272
- ```
273
-
274
- ### Async Iterators
275
- ```tsx
276
- async function* paginate<T>(fetcher: (page: number) => Promise<T[]>): AsyncGenerator<T> {
277
- let page = 0;
278
- while (true) {
279
- const items = await fetcher(page++);
280
- if (items.length === 0) break;
281
- yield* items;
282
- }
283
- }
284
-
285
- // Usage
286
- for await (const user of paginate(fetchUsersPage)) {
287
- processUser(user);
288
- }
289
- ```
290
-
291
- ## Module Organization
292
-
293
- ### Barrel File Performance
294
- ```tsx
295
- // BAD — barrel files cause entire module tree to load
296
- // index.ts
297
- export * from "./userService";
298
- export * from "./orderService";
299
- export * from "./paymentService";
300
-
301
- // GOOD — direct imports skip barrel overhead
302
- import { UserService } from "./services/userService";
303
- ```
304
-
305
- ### Type-Only Imports
306
- ```tsx
307
- // Always use type-only imports for types
308
- import type { User, CreateUserDto } from "./types";
309
- import { UserService } from "./userService";
310
- // With verbatimModuleSyntax, this is enforced
311
- ```
312
-
313
- ### Re-export Patterns
314
- ```tsx
315
- // Public API surface — explicit re-exports
316
- export { UserService } from "./userService";
317
- export type { User, CreateUserDto } from "./types";
318
- // Don't export internal implementation details
319
- ```
320
-
321
- ## Memory & Runtime
322
-
323
- ### WeakRef for Caches
324
- ```tsx
325
- class WeakCache<K extends object, V> {
326
- private cache = new Map<K, WeakRef<V & object>>();
327
- private registry = new FinalizationRegistry<K>(key => this.cache.delete(key));
328
-
329
- set(key: K, value: V & object): void {
330
- this.cache.set(key, new WeakRef(value));
331
- this.registry.register(value, key);
332
- }
333
-
334
- get(key: K): V | undefined {
335
- return this.cache.get(key)?.deref();
336
- }
337
- }
338
- ```
339
-
340
- ### Efficient Data Structures
341
- ```tsx
342
- // Use Map/Set for frequent lookups
343
- const userIndex = new Map<string, User>(); // O(1) lookup
344
- const activeIds = new Set<string>(); // O(1) has/add/delete
345
-
346
- // NOT plain objects for dynamic keys
347
- const userIndex: Record<string, User> = {}; // Slower for frequent mutations
348
- ```
349
-
350
- ### Runtime Rules
351
- - Minimize `Reflect.metadata` and decorator reflection — adds runtime overhead
352
- - Prefer `structuredClone()` over `JSON.parse(JSON.stringify())` for deep cloning
353
- - Use `Object.freeze()` for truly immutable constants
354
- - Avoid `eval()`, `new Function()`, and dynamic `require()` — security + performance issues
355
-
356
- ## Modern JavaScript Patterns
357
-
358
- ### Nullish Handling
359
- ```tsx
360
- const port = config.port ?? 3000; // Only for null/undefined
361
- const name = user?.profile?.displayName; // Optional chaining
362
- const normalized = (input ??= defaultValue); // Nullish assignment
363
- ```
364
-
365
- ### Immutable Updates
366
- ```tsx
367
- // Object spread for shallow updates
368
- const updated = { ...user, name: "New Name" };
369
-
370
- // structuredClone for deep copy
371
- const deep = structuredClone(complexObject);
372
-
373
- // Array immutable operations
374
- const added = [...items, newItem];
375
- const removed = items.filter(i => i.id !== targetId);
376
- const updated = items.map(i => i.id === targetId ? { ...i, ...changes } : i);
377
- ```
378
-
379
- ### Pipe Pattern
380
- ```tsx
381
- function pipe<T>(value: T, ...fns: Array<(v: unknown) => unknown>): unknown {
382
- return fns.reduce((acc, fn) => fn(acc), value as unknown);
383
- }
384
-
385
- // Usage
386
- const result = pipe(
387
- rawData,
388
- validate,
389
- normalize,
390
- transform,
391
- serialize
392
- );
393
- ```
394
-
395
- ## Decision Flow
396
-
397
- When writing TypeScript:
398
-
399
- 1. **Interface or Type?** → Object shape = interface. Union/intersection/mapped = type.
400
- 2. **Generic needed?** → If the function works with multiple types and you need to preserve the type → yes. Otherwise keep it simple.
401
- 3. **Strict enough?** → Enable all strict flags. Use branded types for domain IDs. Use discriminated unions for variants.
402
- 4. **Performance?** → Check: Are there deep conditional types? Circular references? Massive unions? Simplify if so.
403
- 5. **Import style?** → `import type` for types. Direct imports, not barrel files. Named exports, not default.
404
- 6. **Error handling?** → Result pattern for expected errors. throw for unexpected/programmer errors.
405
- 7. **Async?** → Promise.all for parallel. AbortController for timeouts. AsyncGenerator for streams.
@@ -1,82 +0,0 @@
1
- #!/usr/bin/env node
2
- /**
3
- * Scaffold generator — reads definitions, picks adapter, writes files.
4
- *
5
- * Usage:
6
- * node scaffold/generate.mjs # Default: all adapters
7
- * node scaffold/generate.mjs --ide copilot # Copilot only
8
- * node scaffold/generate.mjs --ide claude-code # Claude Code only [stub]
9
- *
10
- * Architecture:
11
- * definitions/ — IDE-agnostic data (agents, models, tools, prompts, hooks, plugins)
12
- * adapters/ — IDE-specific generators (copilot, claude-code)
13
- * general/ — Output directory (agents, prompts, skills) — `aikit init` copies from here
14
- *
15
- * The copilot adapter writes directly to general/ since all IDEs currently
16
- * consume the same VS Code-format .agent.md files. When a future adapter
17
- * needs a different format, it gets its own output directory.
18
- */
19
-
20
- import { existsSync, mkdirSync, rmSync, writeFileSync } from 'node:fs';
21
- import { dirname, resolve } from 'node:path';
22
- import { fileURLToPath } from 'node:url';
23
- import { generateClaudeCode } from './adapters/claude-code.mjs';
24
- import { generateCopilot } from './adapters/copilot.mjs';
25
-
26
- const __dirname = dirname(fileURLToPath(import.meta.url));
27
-
28
- const ADAPTERS = {
29
- copilot: { generate: generateCopilot, outDir: 'general' },
30
- 'claude-code': { generate: generateClaudeCode, outDir: 'claude-code' },
31
- };
32
-
33
- // ─── Parse args ───────────────────────────────────────────────────────────
34
-
35
- const args = process.argv.slice(2);
36
- const ideIdx = args.indexOf('--ide');
37
- const targetIde = ideIdx >= 0 ? args[ideIdx + 1] : null;
38
-
39
- const idesToRun = targetIde ? [targetIde] : Object.keys(ADAPTERS);
40
-
41
- // ─── Generate ─────────────────────────────────────────────────────────────
42
-
43
- for (const ide of idesToRun) {
44
- const adapter = ADAPTERS[ide];
45
- if (!adapter) {
46
- console.error(`Unknown IDE: ${ide}. Available: ${Object.keys(ADAPTERS).join(', ')}`);
47
- process.exit(1);
48
- }
49
-
50
- const outDir = resolve(__dirname, adapter.outDir);
51
-
52
- // Clean only the subdirectories the generator manages (agents/, prompts/).
53
- // This avoids wiping hand-maintained files if they coexist in general/.
54
- for (const subdir of ['agents', 'prompts', 'commands']) {
55
- const sub = resolve(outDir, subdir);
56
- if (existsSync(sub)) {
57
- rmSync(sub, { recursive: true });
58
- }
59
- }
60
-
61
- console.log(`\n─── Generating ${ide} scaffold ───`);
62
-
63
- const files = adapter.generate();
64
-
65
- if (files.length === 0) {
66
- console.log(` (stub — no files generated)`);
67
- continue;
68
- }
69
-
70
- let count = 0;
71
- for (const { path, content } of files) {
72
- const fullPath = resolve(outDir, path);
73
- mkdirSync(dirname(fullPath), { recursive: true });
74
- writeFileSync(fullPath, content, 'utf-8');
75
- console.log(` ${path}`);
76
- count++;
77
- }
78
-
79
- console.log(` → ${count} files written to scaffold/${adapter.outDir}/`);
80
- }
81
-
82
- console.log('\nDone!');