@kb-labs/devkit 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (295) hide show
  1. package/.cursorrules +32 -0
  2. package/.github/CODEOWNERS +2 -0
  3. package/.github/actions/setup-node-pnpm/action.yml +47 -0
  4. package/.github/workflow-templates/ci.yml +13 -0
  5. package/.github/workflow-templates/drift-check.yml +10 -0
  6. package/.github/workflow-templates/profiles-validate.yml +16 -0
  7. package/.github/workflow-templates/release.yml +8 -0
  8. package/.github/workflows/ci-reusable.yml +131 -0
  9. package/.github/workflows/drift-check-reusable.yml +23 -0
  10. package/.github/workflows/fixtures.yml +74 -0
  11. package/.github/workflows/profiles-validate-reusable.yml +67 -0
  12. package/.github/workflows/release-reusable.yml +50 -0
  13. package/.vscode/settings.json +23 -0
  14. package/AGENTS.md +130 -0
  15. package/LICENSE +21 -0
  16. package/README.md +1542 -0
  17. package/agents/devkit-maintainer/context.globs +15 -0
  18. package/agents/devkit-maintainer/permissions.yml +17 -0
  19. package/agents/devkit-maintainer/prompt.md +28 -0
  20. package/agents/devkit-maintainer/runbook.md +31 -0
  21. package/agents/docs-crafter/prompt.md +24 -0
  22. package/agents/docs-crafter/runbook.md +18 -0
  23. package/agents/release-manager/context.globs +7 -0
  24. package/agents/release-manager/prompt.md +27 -0
  25. package/agents/release-manager/runbook.md +17 -0
  26. package/agents/test-generator/context.globs +7 -0
  27. package/agents/test-generator/prompt.md +27 -0
  28. package/agents/test-generator/runbook.md +18 -0
  29. package/bin/devkit-architecture.mjs +1225 -0
  30. package/bin/devkit-build-order.mjs +500 -0
  31. package/bin/devkit-check-build-readiness.mjs +222 -0
  32. package/bin/devkit-check-commands.mjs +394 -0
  33. package/bin/devkit-check-configs.mjs +461 -0
  34. package/bin/devkit-check-deprecated.mjs +532 -0
  35. package/bin/devkit-check-duplicates.mjs +431 -0
  36. package/bin/devkit-check-exports.mjs +561 -0
  37. package/bin/devkit-check-imports.mjs +712 -0
  38. package/bin/devkit-check-paths.mjs +670 -0
  39. package/bin/devkit-check-scripts.mjs +335 -0
  40. package/bin/devkit-check-structure.mjs +495 -0
  41. package/bin/devkit-check-types.mjs +450 -0
  42. package/bin/devkit-ci.mjs +261 -0
  43. package/bin/devkit-core-gate.mjs +225 -0
  44. package/bin/devkit-fix-deps.mjs +1169 -0
  45. package/bin/devkit-freshness.mjs +199 -0
  46. package/bin/devkit-health.mjs +489 -0
  47. package/bin/devkit-migrate-configs.mjs +370 -0
  48. package/bin/devkit-paths.mjs +192 -0
  49. package/bin/devkit-stats.mjs +453 -0
  50. package/bin/devkit-sync.mjs +12 -0
  51. package/bin/devkit-tsup-external.mjs +148 -0
  52. package/bin/devkit-types-audit.mjs +615 -0
  53. package/bin/devkit-types-order.mjs +637 -0
  54. package/bin/devkit-validate-naming.mjs +203 -0
  55. package/bin/devkit-visualize.mjs +452 -0
  56. package/bin/kb-devkit-qa-history.mjs +453 -0
  57. package/bin/kb-devkit-qa.mjs +915 -0
  58. package/eslint/node.js +134 -0
  59. package/eslint/react.js +260 -0
  60. package/package.json +186 -0
  61. package/prettier/index.json +10 -0
  62. package/sync/index.mjs +693 -0
  63. package/templates/configs/README.md +306 -0
  64. package/templates/configs/eslint.config.js +27 -0
  65. package/templates/configs/package.json.bin +25 -0
  66. package/templates/configs/package.json.lib +30 -0
  67. package/templates/configs/tsconfig.build.json +15 -0
  68. package/templates/configs/tsconfig.json +9 -0
  69. package/templates/configs/tsup.config.bin.ts +34 -0
  70. package/templates/configs/tsup.config.cli.ts +41 -0
  71. package/templates/configs/tsup.config.dual.ts +46 -0
  72. package/templates/configs/tsup.config.ts +36 -0
  73. package/templates/package-json/README.md +290 -0
  74. package/templates/package-json/package.json.bin.template +40 -0
  75. package/templates/package-json/package.json.template +45 -0
  76. package/tsconfig/base.json +21 -0
  77. package/tsconfig/cli.json +12 -0
  78. package/tsconfig/dist/__tests__/cache.spec.d.ts +6 -0
  79. package/tsconfig/dist/__tests__/cache.spec.d.ts.map +1 -0
  80. package/tsconfig/dist/__tests__/cache.spec.js +85 -0
  81. package/tsconfig/dist/__tests__/cache.spec.js.map +1 -0
  82. package/tsconfig/dist/__tests__/fs-atomic.spec.d.ts +6 -0
  83. package/tsconfig/dist/__tests__/fs-atomic.spec.d.ts.map +1 -0
  84. package/tsconfig/dist/__tests__/fs-atomic.spec.js +153 -0
  85. package/tsconfig/dist/__tests__/fs-atomic.spec.js.map +1 -0
  86. package/tsconfig/dist/__tests__/init-workspace.spec.d.ts +6 -0
  87. package/tsconfig/dist/__tests__/init-workspace.spec.d.ts.map +1 -0
  88. package/tsconfig/dist/__tests__/init-workspace.spec.js +99 -0
  89. package/tsconfig/dist/__tests__/init-workspace.spec.js.map +1 -0
  90. package/tsconfig/dist/__tests__/kb-error.spec.d.ts +6 -0
  91. package/tsconfig/dist/__tests__/kb-error.spec.d.ts.map +1 -0
  92. package/tsconfig/dist/__tests__/kb-error.spec.js +190 -0
  93. package/tsconfig/dist/__tests__/kb-error.spec.js.map +1 -0
  94. package/tsconfig/dist/__tests__/preset-lockfile.spec.d.ts +6 -0
  95. package/tsconfig/dist/__tests__/preset-lockfile.spec.d.ts.map +1 -0
  96. package/tsconfig/dist/__tests__/preset-lockfile.spec.js +142 -0
  97. package/tsconfig/dist/__tests__/preset-lockfile.spec.js.map +1 -0
  98. package/tsconfig/dist/__tests__/product-config-profiles.spec.d.ts +6 -0
  99. package/tsconfig/dist/__tests__/product-config-profiles.spec.d.ts.map +1 -0
  100. package/tsconfig/dist/__tests__/product-config-profiles.spec.js +100 -0
  101. package/tsconfig/dist/__tests__/product-config-profiles.spec.js.map +1 -0
  102. package/tsconfig/dist/__tests__/product-config.spec.d.ts +6 -0
  103. package/tsconfig/dist/__tests__/product-config.spec.d.ts.map +1 -0
  104. package/tsconfig/dist/__tests__/product-config.spec.js +298 -0
  105. package/tsconfig/dist/__tests__/product-config.spec.js.map +1 -0
  106. package/tsconfig/dist/__tests__/runtime.spec.d.ts +2 -0
  107. package/tsconfig/dist/__tests__/runtime.spec.d.ts.map +1 -0
  108. package/tsconfig/dist/__tests__/runtime.spec.js +127 -0
  109. package/tsconfig/dist/__tests__/runtime.spec.js.map +1 -0
  110. package/tsconfig/dist/__tests__/upsert-lockfile.spec.d.ts +6 -0
  111. package/tsconfig/dist/__tests__/upsert-lockfile.spec.d.ts.map +1 -0
  112. package/tsconfig/dist/__tests__/upsert-lockfile.spec.js +251 -0
  113. package/tsconfig/dist/__tests__/upsert-lockfile.spec.js.map +1 -0
  114. package/tsconfig/dist/__tests__/validate-config.spec.d.ts +2 -0
  115. package/tsconfig/dist/__tests__/validate-config.spec.d.ts.map +1 -0
  116. package/tsconfig/dist/__tests__/validate-config.spec.js +14 -0
  117. package/tsconfig/dist/__tests__/validate-config.spec.js.map +1 -0
  118. package/tsconfig/dist/api/init-workspace.d.ts +10 -0
  119. package/tsconfig/dist/api/init-workspace.d.ts.map +1 -0
  120. package/tsconfig/dist/api/init-workspace.js +191 -0
  121. package/tsconfig/dist/api/init-workspace.js.map +1 -0
  122. package/tsconfig/dist/api/product-config.d.ts +21 -0
  123. package/tsconfig/dist/api/product-config.d.ts.map +1 -0
  124. package/tsconfig/dist/api/product-config.js +192 -0
  125. package/tsconfig/dist/api/product-config.js.map +1 -0
  126. package/tsconfig/dist/api/read-config.d.ts +22 -0
  127. package/tsconfig/dist/api/read-config.d.ts.map +1 -0
  128. package/tsconfig/dist/api/read-config.js +105 -0
  129. package/tsconfig/dist/api/read-config.js.map +1 -0
  130. package/tsconfig/dist/api/upsert-lockfile.d.ts +10 -0
  131. package/tsconfig/dist/api/upsert-lockfile.d.ts.map +1 -0
  132. package/tsconfig/dist/api/upsert-lockfile.js +63 -0
  133. package/tsconfig/dist/api/upsert-lockfile.js.map +1 -0
  134. package/tsconfig/dist/cache/fs-cache.d.ts +38 -0
  135. package/tsconfig/dist/cache/fs-cache.d.ts.map +1 -0
  136. package/tsconfig/dist/cache/fs-cache.js +142 -0
  137. package/tsconfig/dist/cache/fs-cache.js.map +1 -0
  138. package/tsconfig/dist/errors/kb-error.d.ts +32 -0
  139. package/tsconfig/dist/errors/kb-error.d.ts.map +1 -0
  140. package/tsconfig/dist/errors/kb-error.js +54 -0
  141. package/tsconfig/dist/errors/kb-error.js.map +1 -0
  142. package/tsconfig/dist/fs/__tests__/fs.spec.d.ts +2 -0
  143. package/tsconfig/dist/fs/__tests__/fs.spec.d.ts.map +1 -0
  144. package/tsconfig/dist/fs/__tests__/fs.spec.js +22 -0
  145. package/tsconfig/dist/fs/__tests__/fs.spec.js.map +1 -0
  146. package/tsconfig/dist/fs/fs.d.ts +6 -0
  147. package/tsconfig/dist/fs/fs.d.ts.map +1 -0
  148. package/tsconfig/dist/fs/fs.js +12 -0
  149. package/tsconfig/dist/fs/fs.js.map +1 -0
  150. package/tsconfig/dist/fs/index.d.ts +2 -0
  151. package/tsconfig/dist/fs/index.d.ts.map +1 -0
  152. package/tsconfig/dist/fs/index.js +2 -0
  153. package/tsconfig/dist/fs/index.js.map +1 -0
  154. package/tsconfig/dist/hash/config-hash.d.ts +17 -0
  155. package/tsconfig/dist/hash/config-hash.d.ts.map +1 -0
  156. package/tsconfig/dist/hash/config-hash.js +55 -0
  157. package/tsconfig/dist/hash/config-hash.js.map +1 -0
  158. package/tsconfig/dist/index.d.ts +5 -0
  159. package/tsconfig/dist/index.d.ts.map +1 -0
  160. package/tsconfig/dist/index.js +5 -0
  161. package/tsconfig/dist/index.js.map +1 -0
  162. package/tsconfig/dist/lockfile/lockfile.d.ts +54 -0
  163. package/tsconfig/dist/lockfile/lockfile.d.ts.map +1 -0
  164. package/tsconfig/dist/lockfile/lockfile.js +141 -0
  165. package/tsconfig/dist/lockfile/lockfile.js.map +1 -0
  166. package/tsconfig/dist/logging/__tests__/logger.spec.d.ts +2 -0
  167. package/tsconfig/dist/logging/__tests__/logger.spec.d.ts.map +1 -0
  168. package/tsconfig/dist/logging/__tests__/logger.spec.js +65 -0
  169. package/tsconfig/dist/logging/__tests__/logger.spec.js.map +1 -0
  170. package/tsconfig/dist/logging/__tests__/redaction.spec.d.ts +2 -0
  171. package/tsconfig/dist/logging/__tests__/redaction.spec.d.ts.map +1 -0
  172. package/tsconfig/dist/logging/__tests__/redaction.spec.js +34 -0
  173. package/tsconfig/dist/logging/__tests__/redaction.spec.js.map +1 -0
  174. package/tsconfig/dist/logging/__tests__/sinks-and-env.spec.d.ts +2 -0
  175. package/tsconfig/dist/logging/__tests__/sinks-and-env.spec.d.ts.map +1 -0
  176. package/tsconfig/dist/logging/__tests__/sinks-and-env.spec.js +90 -0
  177. package/tsconfig/dist/logging/__tests__/sinks-and-env.spec.js.map +1 -0
  178. package/tsconfig/dist/logging/index.d.ts +6 -0
  179. package/tsconfig/dist/logging/index.d.ts.map +1 -0
  180. package/tsconfig/dist/logging/index.js +6 -0
  181. package/tsconfig/dist/logging/index.js.map +1 -0
  182. package/tsconfig/dist/logging/logger.d.ts +9 -0
  183. package/tsconfig/dist/logging/logger.d.ts.map +1 -0
  184. package/tsconfig/dist/logging/logger.js +101 -0
  185. package/tsconfig/dist/logging/logger.js.map +1 -0
  186. package/tsconfig/dist/logging/redaction.d.ts +7 -0
  187. package/tsconfig/dist/logging/redaction.d.ts.map +1 -0
  188. package/tsconfig/dist/logging/redaction.js +23 -0
  189. package/tsconfig/dist/logging/redaction.js.map +1 -0
  190. package/tsconfig/dist/logging/sinks/json.d.ts +4 -0
  191. package/tsconfig/dist/logging/sinks/json.d.ts.map +1 -0
  192. package/tsconfig/dist/logging/sinks/json.js +23 -0
  193. package/tsconfig/dist/logging/sinks/json.js.map +1 -0
  194. package/tsconfig/dist/logging/sinks/stdout.d.ts +3 -0
  195. package/tsconfig/dist/logging/sinks/stdout.d.ts.map +1 -0
  196. package/tsconfig/dist/logging/sinks/stdout.js +24 -0
  197. package/tsconfig/dist/logging/sinks/stdout.js.map +1 -0
  198. package/tsconfig/dist/logging/types/index.d.ts +2 -0
  199. package/tsconfig/dist/logging/types/index.d.ts.map +1 -0
  200. package/tsconfig/dist/logging/types/index.js +2 -0
  201. package/tsconfig/dist/logging/types/index.js.map +1 -0
  202. package/tsconfig/dist/logging/types/types.d.ts +37 -0
  203. package/tsconfig/dist/logging/types/types.d.ts.map +1 -0
  204. package/tsconfig/dist/logging/types/types.js +2 -0
  205. package/tsconfig/dist/logging/types/types.js.map +1 -0
  206. package/tsconfig/dist/merge/layered-merge.d.ts +16 -0
  207. package/tsconfig/dist/merge/layered-merge.d.ts.map +1 -0
  208. package/tsconfig/dist/merge/layered-merge.js +97 -0
  209. package/tsconfig/dist/merge/layered-merge.js.map +1 -0
  210. package/tsconfig/dist/preset/resolve-preset.d.ts +29 -0
  211. package/tsconfig/dist/preset/resolve-preset.d.ts.map +1 -0
  212. package/tsconfig/dist/preset/resolve-preset.js +104 -0
  213. package/tsconfig/dist/preset/resolve-preset.js.map +1 -0
  214. package/tsconfig/dist/repo/__tests__/repo.spec.d.ts +2 -0
  215. package/tsconfig/dist/repo/__tests__/repo.spec.d.ts.map +1 -0
  216. package/tsconfig/dist/repo/__tests__/repo.spec.js +25 -0
  217. package/tsconfig/dist/repo/__tests__/repo.spec.js.map +1 -0
  218. package/tsconfig/dist/repo/index.d.ts +2 -0
  219. package/tsconfig/dist/repo/index.d.ts.map +1 -0
  220. package/tsconfig/dist/repo/index.js +2 -0
  221. package/tsconfig/dist/repo/index.js.map +1 -0
  222. package/tsconfig/dist/repo/repo.d.ts +6 -0
  223. package/tsconfig/dist/repo/repo.d.ts.map +1 -0
  224. package/tsconfig/dist/repo/repo.js +25 -0
  225. package/tsconfig/dist/repo/repo.js.map +1 -0
  226. package/tsconfig/dist/runtime/index.d.ts +2 -0
  227. package/tsconfig/dist/runtime/index.d.ts.map +1 -0
  228. package/tsconfig/dist/runtime/index.js +2 -0
  229. package/tsconfig/dist/runtime/index.js.map +1 -0
  230. package/tsconfig/dist/runtime/runtime.d.ts +46 -0
  231. package/tsconfig/dist/runtime/runtime.d.ts.map +1 -0
  232. package/tsconfig/dist/runtime/runtime.js +126 -0
  233. package/tsconfig/dist/runtime/runtime.js.map +1 -0
  234. package/tsconfig/dist/tsconfig.tools.tsbuildinfo +1 -0
  235. package/tsconfig/dist/tsconfig.tsbuildinfo +1 -0
  236. package/tsconfig/dist/types/index.d.ts +2 -0
  237. package/tsconfig/dist/types/index.d.ts.map +1 -0
  238. package/tsconfig/dist/types/index.js +2 -0
  239. package/tsconfig/dist/types/index.js.map +1 -0
  240. package/tsconfig/dist/types/init.d.ts +34 -0
  241. package/tsconfig/dist/types/init.d.ts.map +1 -0
  242. package/tsconfig/dist/types/init.js +6 -0
  243. package/tsconfig/dist/types/init.js.map +1 -0
  244. package/tsconfig/dist/types/preset.d.ts +27 -0
  245. package/tsconfig/dist/types/preset.d.ts.map +1 -0
  246. package/tsconfig/dist/types/preset.js +6 -0
  247. package/tsconfig/dist/types/preset.js.map +1 -0
  248. package/tsconfig/dist/types/types.d.ts +6 -0
  249. package/tsconfig/dist/types/types.d.ts.map +1 -0
  250. package/tsconfig/dist/types/types.js +2 -0
  251. package/tsconfig/dist/types/types.js.map +1 -0
  252. package/tsconfig/dist/utils/__tests__/env.spec.d.ts +2 -0
  253. package/tsconfig/dist/utils/__tests__/env.spec.d.ts.map +1 -0
  254. package/tsconfig/dist/utils/__tests__/env.spec.js +33 -0
  255. package/tsconfig/dist/utils/__tests__/env.spec.js.map +1 -0
  256. package/tsconfig/dist/utils/env.d.ts +7 -0
  257. package/tsconfig/dist/utils/env.d.ts.map +1 -0
  258. package/tsconfig/dist/utils/env.js +25 -0
  259. package/tsconfig/dist/utils/env.js.map +1 -0
  260. package/tsconfig/dist/utils/fs-atomic.d.ts +15 -0
  261. package/tsconfig/dist/utils/fs-atomic.d.ts.map +1 -0
  262. package/tsconfig/dist/utils/fs-atomic.js +45 -0
  263. package/tsconfig/dist/utils/fs-atomic.js.map +1 -0
  264. package/tsconfig/dist/utils/index.d.ts +3 -0
  265. package/tsconfig/dist/utils/index.d.ts.map +1 -0
  266. package/tsconfig/dist/utils/index.js +3 -0
  267. package/tsconfig/dist/utils/index.js.map +1 -0
  268. package/tsconfig/dist/utils/paths.d.ts +21 -0
  269. package/tsconfig/dist/utils/paths.d.ts.map +1 -0
  270. package/tsconfig/dist/utils/paths.js +32 -0
  271. package/tsconfig/dist/utils/paths.js.map +1 -0
  272. package/tsconfig/dist/utils/product-normalize.d.ts +27 -0
  273. package/tsconfig/dist/utils/product-normalize.d.ts.map +1 -0
  274. package/tsconfig/dist/utils/product-normalize.js +45 -0
  275. package/tsconfig/dist/utils/product-normalize.js.map +1 -0
  276. package/tsconfig/dist/validation/validate-config.d.ts +7 -0
  277. package/tsconfig/dist/validation/validate-config.d.ts.map +1 -0
  278. package/tsconfig/dist/validation/validate-config.js +22 -0
  279. package/tsconfig/dist/validation/validate-config.js.map +1 -0
  280. package/tsconfig/lib.json +13 -0
  281. package/tsconfig/node.json +12 -0
  282. package/tsconfig/react-app.json +8 -0
  283. package/tsconfig/react-lib.json +8 -0
  284. package/tsconfig/test.json +15 -0
  285. package/tsup/bin.js +172 -0
  286. package/tsup/dual.js +155 -0
  287. package/tsup/external-sync.mjs +41 -0
  288. package/tsup/external.mjs +109 -0
  289. package/tsup/node.js +65 -0
  290. package/tsup/react-lib.js +18 -0
  291. package/tsup/sdk.js +118 -0
  292. package/vite/react-app.js +50 -0
  293. package/vitest/node.js +37 -0
  294. package/vitest/react.js +39 -0
  295. package/vitest/vitest-setup.ts +9 -0
package/README.md ADDED
@@ -0,0 +1,1542 @@
1
+ # KB Labs DevKit (@kb-labs/devkit)
2
+
3
+ > **A cohesive set of presets and configurations for the `@kb-labs` ecosystem.** TypeScript `tsconfig`, ESLint, Prettier, Vitest, Tsup, and reusable GitHub Actions. The goal is to maximize automation, enforce consistent standards, and eliminate copy-paste across new projects.
4
+
5
+ [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](LICENSE)
6
+ [![Node.js](https://img.shields.io/badge/Node.js-18.18.0+-green.svg)](https://nodejs.org/)
7
+ [![pnpm](https://img.shields.io/badge/pnpm-9.0.0+-orange.svg)](https://pnpm.io/)
8
+
9
+ ## 🎯 Vision
10
+
11
+ KB Labs DevKit provides a cohesive set of presets and configurations for the `@kb-labs` ecosystem: TypeScript `tsconfig`, ESLint, Prettier, Vitest, Tsup, and reusable GitHub Actions. The goal is to maximize automation, enforce consistent standards, and eliminate copy-paste across new projects.
12
+
13
+ The project solves the problem of inconsistent tooling configurations across KB Labs projects by providing a single source of truth for all development tooling. Instead of copying configs between projects, developers can simply extend DevKit presets, ensuring consistency and reducing maintenance overhead.
14
+
15
+ This project is the foundation for all KB Labs tooling and is used by every project in the ecosystem. It includes a powerful sync system that automatically keeps projects up-to-date with the latest DevKit assets.
16
+
17
+ ## 🚀 Quick Start
18
+
19
+ ### Installation
20
+
21
+ ```bash
22
+ pnpm add -D @kb-labs/devkit
23
+ # or
24
+ npm i -D @kb-labs/devkit
25
+ ```
26
+
27
+ ### Basic Setup
28
+
29
+ #### Node Project (TS + Tsup + Vitest + ESLint + Prettier)
30
+
31
+ **tsconfig.json:**
32
+ ```json
33
+ {
34
+ "extends": "@kb-labs/devkit/tsconfig/node.json"
35
+ }
36
+ ```
37
+
38
+ **tsup.config.ts:**
39
+ ```typescript
40
+ import config from '@kb-labs/devkit/tsup/node.js'
41
+ export default config
42
+ ```
43
+
44
+ **vitest.config.ts:**
45
+ ```typescript
46
+ import config from '@kb-labs/devkit/vitest/node.js'
47
+ export default config
48
+ ```
49
+
50
+ **eslint.config.js** (ESLint 9 flat config):
51
+ ```javascript
52
+ import config from '@kb-labs/devkit/eslint/node.js'
53
+ export default config
54
+ ```
55
+
56
+ **.prettierrc.json:**
57
+ ```json
58
+ "@kb-labs/devkit/prettier/index.json"
59
+ ```
60
+
61
+ **package.json** (example):
62
+ ```json
63
+ {
64
+ "type": "module",
65
+ "main": "./dist/index.js",
66
+ "types": "./dist/index.d.ts",
67
+ "exports": {
68
+ ".": {
69
+ "import": "./dist/index.js",
70
+ "types": "./dist/index.d.ts"
71
+ }
72
+ },
73
+ "scripts": {
74
+ "build": "tsup",
75
+ "lint": "eslint .",
76
+ "test": "vitest",
77
+ "format": "prettier -w ."
78
+ }
79
+ }
80
+ ```
81
+
82
+ > **Build Convention**: All KB Labs packages use `"build": "tsup"` as the standard convention. The `tsup` preset handles both JavaScript bundling and TypeScript declaration generation (`dts: true`). TypeScript `tsconfig.json` with `references` is for IDE support and type-checking only, not for build orchestration. See [ADR-0009](./docs/adr/0009-unified-build-convention.md) for details.
83
+
84
+ ### Workspace Aliases
85
+
86
+ For monorepos, DevKit ships with `kb-devkit-paths` – a generator that scans the pnpm workspace and writes `tsconfig.paths.json` with all `@kb-labs/*` aliases. Recommended setup:
87
+
88
+ ```json
89
+ {
90
+ "extends": [
91
+ "@kb-labs/devkit/tsconfig/node.json",
92
+ "./tsconfig.paths.json"
93
+ ],
94
+ "compilerOptions": {
95
+ "baseUrl": "."
96
+ }
97
+ }
98
+ ```
99
+
100
+ Add scripts to your `package.json` so aliases stay fresh whenever DevKit sync runs:
101
+
102
+ ```json
103
+ {
104
+ "scripts": {
105
+ "devkit:paths": "pnpm exec kb-devkit-paths",
106
+ "predevkit:sync": "pnpm devkit:paths",
107
+ "predevkit:sync:ci": "pnpm devkit:paths",
108
+ "predevkit:check": "pnpm devkit:paths",
109
+ "predevkit:force": "pnpm devkit:paths"
110
+ }
111
+ }
112
+ ```
113
+
114
+ Then generate aliases once:
115
+
116
+ ```bash
117
+ pnpm run devkit:paths
118
+ ```
119
+
120
+ ### Repository Synchronization
121
+
122
+ Sync DevKit assets into your project:
123
+
124
+ ```bash
125
+ # Run sync (creates/updates files)
126
+ npx kb-devkit-sync
127
+
128
+ # Check for drift without making changes
129
+ npx kb-devkit-sync --check
130
+
131
+ # Force overwrite existing files
132
+ npx kb-devkit-sync --force
133
+ ```
134
+
135
+ ### Naming Convention Validation
136
+
137
+ Validate that all packages follow the **Pyramid Rule** (`@kb-labs/{repo}-{package}`):
138
+
139
+ ```bash
140
+ # Validate naming convention
141
+ npx kb-devkit-validate-naming
142
+
143
+ # Run from monorepo root (validates all kb-labs-* repos)
144
+ cd /path/to/kb-labs
145
+ npx kb-devkit-validate-naming
146
+ ```
147
+
148
+ **Output:**
149
+ - ✅ Lists all valid packages
150
+ - ❌ Reports violations with specific suggestions
151
+ - Exits with code 1 if violations found (CI-friendly)
152
+
153
+ See [docs/naming-convention.md](https://github.com/kb-labs/kb-labs-plugin-template/blob/main/docs/naming-convention.md) for the complete Pyramid Rule guide.
154
+
155
+ ### Import Checker
156
+
157
+ Check for broken imports, unused dependencies, and circular dependencies across all packages:
158
+
159
+ ```bash
160
+ # Check all packages for import issues
161
+ npx kb-devkit-check-imports
162
+
163
+ # Check specific package
164
+ npx kb-devkit-check-imports --package core-cli
165
+
166
+ # Show all packages (including clean ones)
167
+ npx kb-devkit-check-imports --verbose
168
+
169
+ # Auto-fix unused dependencies (coming soon)
170
+ npx kb-devkit-check-imports --fix
171
+ ```
172
+
173
+ **What it checks:**
174
+
175
+ 1. **Broken imports** (🔴): Files that are imported but don't exist
176
+ - Detects typos in import paths
177
+ - Finds missing files after refactoring
178
+ - Reports exact file and line number
179
+
180
+ 2. **Missing workspace dependencies** (🟡): Packages used in code but not in `package.json`
181
+ - Finds `@kb-labs/*` imports not declared as dependencies
182
+ - Shows which files use the missing package
183
+ - Critical for proper workspace resolution
184
+
185
+ 3. **Unused dependencies** (🟠): Dependencies in `package.json` but never imported
186
+ - Excludes build tools (`typescript`, `tsup`, `vitest`, etc.)
187
+ - Excludes type definitions (`@types/*`)
188
+ - Helps keep dependencies clean
189
+
190
+ 4. **Circular dependencies** (🔄): Packages that depend on each other in a cycle
191
+ - Detects circular dependency chains
192
+ - Shows full cycle path (A → B → C → A)
193
+ - Can cause build and runtime issues
194
+
195
+ **Output:**
196
+ - ✅ Clean packages (only with `--verbose`)
197
+ - ❌ Packages with issues
198
+ - 📊 Summary with counts by issue type
199
+ - Exits with code 1 if issues found (CI-friendly)
200
+
201
+ **Example output:**
202
+ ```
203
+ 🔍 KB Labs Import Checker
204
+
205
+ Found 188 package(s) to check
206
+
207
+ ❌ @kb-labs/core-cli
208
+ kb-labs-core/packages/core-cli
209
+
210
+ 🔴 Broken imports (2):
211
+ src/commands/run.ts:15
212
+ └─ Cannot resolve: ../utils/missing-file
213
+
214
+ 🟡 Missing workspace dependencies (1):
215
+ @kb-labs/core-config
216
+ └─ Used in 3 file(s)
217
+
218
+ 🟠 Unused dependencies (2):
219
+ lodash
220
+ axios
221
+
222
+ 🔄 Circular Dependencies (1):
223
+
224
+ 1. @kb-labs/cli-core → @kb-labs/cli-commands → @kb-labs/cli-core
225
+
226
+ 📊 Summary:
227
+ 🔴 2 broken import(s)
228
+ 🟡 1 missing workspace dep(s)
229
+ 🟠 2 unused dependency(ies)
230
+ 🔄 1 circular dependency cycle(s)
231
+ ```
232
+
233
+ ### Export Checker
234
+
235
+ Check for unused exports, dead code in public APIs, and package.json export inconsistencies:
236
+
237
+ ```bash
238
+ # Check all packages for export issues
239
+ npx kb-devkit-check-exports
240
+
241
+ # Check specific package
242
+ npx kb-devkit-check-exports --package core-cli
243
+
244
+ # Include internal exports (more thorough)
245
+ npx kb-devkit-check-exports --strict
246
+
247
+ # Show all packages (including clean ones)
248
+ npx kb-devkit-check-exports --verbose
249
+ ```
250
+
251
+ **What it checks:**
252
+
253
+ 1. **Unused exports** (🟠): Exports that are never imported by other packages
254
+ - Identifies dead code in public APIs
255
+ - Finds exports that can be safely removed
256
+ - Helps reduce API surface area
257
+ - Distinguishes between public (index.ts) and internal exports
258
+
259
+ 2. **Missing barrel exports** (🟡): Files with exports not re-exported from index.ts
260
+ - Only shown in `--strict` mode
261
+ - Finds files that may need to be added to public API
262
+ - Or identifies files that should be marked as internal
263
+
264
+ 3. **Inconsistent package.json exports** (🔴): Exports field pointing to non-existent files
265
+ - Validates package.json `exports` field
266
+ - Finds broken export paths
267
+ - Critical for package consumers
268
+
269
+ **Output:**
270
+ - ✅ Clean packages (only with `--verbose`)
271
+ - ❌ Packages with unused exports
272
+ - 📊 Summary with counts by issue type
273
+ - Exits with code 1 if issues found (CI-friendly)
274
+
275
+ **Example output:**
276
+ ```
277
+ 📤 KB Labs Export Checker
278
+
279
+ Found 188 package(s) to check
280
+
281
+ ❌ @kb-labs/core-cli
282
+ kb-labs-core/packages/core-cli
283
+
284
+ 🟠 Unused exports (3):
285
+ src/index.ts
286
+ └─ oldFunction (public API)
287
+ └─ deprecatedUtil (public API)
288
+ src/internal/helpers.ts
289
+ └─ internalHelper (internal)
290
+
291
+ 💡 These exports are never imported by other packages
292
+ 💡 Consider removing them to reduce API surface
293
+
294
+ 🔴 Inconsistent package.json exports (1):
295
+ "./utils" → ./dist/utils.js
296
+ └─ File does not exist
297
+
298
+ 💡 Update package.json exports field to match actual files
299
+
300
+ 📊 Summary:
301
+ 🟠 3 unused export(s)
302
+ 🔴 1 inconsistent package.json export(s)
303
+ ```
304
+
305
+ ### Duplicate Checker
306
+
307
+ Check for duplicate dependencies with different versions and code duplication patterns:
308
+
309
+ ```bash
310
+ # Check for duplicate dependencies
311
+ npx kb-devkit-check-duplicates
312
+
313
+ # Include code duplication analysis
314
+ npx kb-devkit-check-duplicates --code
315
+
316
+ # Show detailed info (outdated deps, full package lists)
317
+ npx kb-devkit-check-duplicates --verbose
318
+ ```
319
+
320
+ **What it checks:**
321
+ 1. **Duplicate dependencies** (🔴): Same package with multiple versions
322
+ 2. **Outdated common dependencies** (🟡): Packages using older versions (with `--verbose`)
323
+ 3. **Code duplication** (🟠): Similar file names across packages (with `--code`)
324
+
325
+ ### Structure Checker
326
+
327
+ Validate package structure, required files, and package.json fields:
328
+
329
+ ```bash
330
+ # Check all packages
331
+ npx kb-devkit-check-structure
332
+
333
+ # Include recommendations
334
+ npx kb-devkit-check-structure --strict
335
+
336
+ # Check specific package
337
+ npx kb-devkit-check-structure --package core-cli
338
+ ```
339
+
340
+ **What it checks:**
341
+ 1. Missing critical files (package.json, src/, tsconfig.json, README.md)
342
+ 2. Missing package.json fields (name, version, type, exports, etc.)
343
+ 3. Structure issues (missing index.ts, tests in src/, missing scripts)
344
+ 4. Documentation quality (README length, missing sections)
345
+ 5. Configuration consistency (tsconfig using devkit presets)
346
+
347
+ ### Path Validator
348
+
349
+ Validate all paths and references in package.json, tsconfig.json, and dependencies:
350
+
351
+ ```bash
352
+ # Check all paths
353
+ npx kb-devkit-check-paths
354
+
355
+ # Check specific package
356
+ npx kb-devkit-check-paths --package=cli-core
357
+
358
+ # JSON output for CI
359
+ npx kb-devkit-check-paths --json
360
+ ```
361
+
362
+ **What it validates:**
363
+ 1. **Workspace dependencies**: `workspace:*` references to non-existent packages
364
+ 2. **Link references**: `link:../path` pointing to non-existent directories
365
+ 3. **Package.json exports**: Export paths pointing to non-existent files
366
+ 4. **Bin scripts**: Bin entries pointing to non-existent scripts
367
+ 5. **Entry points**: `main`, `module`, `types` fields pointing to missing files
368
+ 6. **Files field**: Items in `files` array that don't exist
369
+ 7. **tsconfig.json**: Broken `extends`, `references`, and `paths` aliases
370
+
371
+ **Severity levels:**
372
+ - 🔴 **Errors**: Critical issues (broken links, missing workspace packages)
373
+ - ⚠️ **Warnings**: Build-dependent issues (`./dist/*` files that need `pnpm build`)
374
+
375
+ **Example output:**
376
+ ```
377
+ 🔗 KB Labs Path Validator
378
+
379
+ 📦 Missing Workspace Packages (2):
380
+ kb-labs-plugin/
381
+ @kb-labs/ai-docs-plugin
382
+ Workspace package "@kb-labs/setup-engine-operations" does not exist
383
+
384
+ 🔗 Broken Link References (1):
385
+ kb-labs-ai-docs/
386
+ @kb-labs/ai-docs-plugin
387
+ Link path does not exist: ../../../kb-labs-setup-engine/packages/setup-operations
388
+
389
+ 📊 Summary:
390
+ Packages checked: 91
391
+ ❌ Errors: 107
392
+ ⚠️ Warnings: 185
393
+ ```
394
+
395
+ ### Visualizer
396
+
397
+ Generate dependency graphs, statistics, and visualizations:
398
+
399
+ ```bash
400
+ # Show all visualizations
401
+ npx kb-devkit-visualize
402
+
403
+ # Show dependency graph only
404
+ npx kb-devkit-visualize --graph
405
+
406
+ # Show package statistics
407
+ npx kb-devkit-visualize --stats
408
+
409
+ # Show dependency tree for package
410
+ npx kb-devkit-visualize --tree --package cli-core
411
+ ```
412
+
413
+ **What it shows:**
414
+ 1. **Dependency graph**: Visual representation of dependencies
415
+ 2. **Package statistics**: By repository, most depended-on, largest packages
416
+ 3. **Dependency tree**: Hierarchical view with `--tree`
417
+
418
+ ### Quick Statistics
419
+
420
+ Get comprehensive monorepo statistics and health scores:
421
+
422
+ ```bash
423
+ # Show all statistics
424
+ npx kb-devkit-stats
425
+
426
+ # Show health score
427
+ npx kb-devkit-stats --health
428
+
429
+ # Output JSON for parsing
430
+ npx kb-devkit-stats --json
431
+
432
+ # Output Markdown table
433
+ npx kb-devkit-stats --md
434
+ ```
435
+
436
+ **What it shows:**
437
+ 1. **Overview**: Total packages, repositories, files, LOC, size
438
+ 2. **Dependencies**: Workspace vs external, duplicates count
439
+ 3. **By repository**: Package count, LOC breakdown
440
+ 4. **Health score**: Grade A-F based on issues
441
+ 5. **Largest packages**: Top 5 by lines of code
442
+
443
+ **Example output:**
444
+ ```
445
+ 📊 KB Labs Monorepo Statistics
446
+
447
+ 📦 Overview:
448
+ Packages: 90
449
+ Repositories: 18
450
+ Lines of Code: 226,514
451
+ Total Size: 6.22 MB
452
+
453
+ 🔗 Dependencies:
454
+ Total: 1,085
455
+ Workspace: 340
456
+ External: 745
457
+ Duplicates: 30 ⚠️
458
+
459
+ 💚 Health Score:
460
+ Score: 68/100 (Grade D)
461
+
462
+ Issues:
463
+ 🔴 30 duplicate dependencies (-20)
464
+ 🟡 12 packages missing README (-12)
465
+ ```
466
+
467
+ ### Dependency Auto-Fixer
468
+
469
+ Automatically fix common dependency issues and analyze dependency usage:
470
+
471
+ ```bash
472
+ # Show dependency statistics
473
+ npx kb-devkit-fix-deps --stats
474
+
475
+ # Remove unused dependencies (dry-run first!)
476
+ npx kb-devkit-fix-deps --remove-unused --dry-run
477
+ npx kb-devkit-fix-deps --remove-unused
478
+
479
+ # Add missing workspace dependencies
480
+ npx kb-devkit-fix-deps --add-missing
481
+
482
+ # Align duplicate dependency versions
483
+ npx kb-devkit-fix-deps --align-versions
484
+
485
+ # Apply all fixes
486
+ npx kb-devkit-fix-deps --all
487
+
488
+ # Fix specific package only
489
+ npx kb-devkit-fix-deps --remove-unused --package=core-cli
490
+
491
+ # Show why dependencies were kept (debug mode)
492
+ npx kb-devkit-fix-deps --remove-unused --dry-run --verbose
493
+ ```
494
+
495
+ **What it fixes:**
496
+ 1. **Removes unused dependencies**: Safely removes deps not found in source code
497
+ - Scans `src/`, `test/`, `tests/`, `__tests__/`, `scripts/` directories
498
+ - Checks config files (`tsup.config.ts`, `vitest.config.ts`, etc.)
499
+ - Respects peer dependencies
500
+ 2. **Adds missing workspace deps**: Adds `@kb-labs/*` packages imported but not declared
501
+ 3. **Aligns duplicate versions**: Picks most common version and aligns all packages
502
+
503
+ **Statistics mode (`--stats`):**
504
+ ```
505
+ 📊 Dependency Statistics
506
+
507
+ 📦 Total packages: 91
508
+ 📚 Total dependencies: 353
509
+ 🔧 Total devDependencies: 586
510
+ 🔗 Total peerDependencies: 4
511
+
512
+ 🔝 Top 10 Most Used Dependencies:
513
+ 1. tsup (91 packages)
514
+ 2. typescript (84 packages)
515
+ 3. @types/node (83 packages)
516
+ ...
517
+ ```
518
+
519
+ **Safety features:**
520
+ - Always use `--dry-run` first to preview changes
521
+ - Excludes build tools (typescript, tsup, vitest, esbuild, vite, rimraf, etc.)
522
+ - Excludes testing tools (vitest, jest, playwright, @vitest/*, @testing-library/*)
523
+ - Excludes type definitions (@types/*)
524
+ - Excludes linting tools (eslint-*, @eslint/*, @typescript-eslint/*, prettier-plugin-*)
525
+ - Respects peer dependencies (won't remove if listed in peerDependencies)
526
+ - Use `--verbose` to see why dependencies were kept
527
+ - Sorts dependencies alphabetically after changes
528
+
529
+ **Orphan packages analysis (`--orphans`):**
530
+
531
+ Find packages that no other package depends on (potential dead code):
532
+
533
+ ```bash
534
+ # Find orphan packages
535
+ npx kb-devkit-fix-deps --orphans
536
+
537
+ # JSON output for CI
538
+ npx kb-devkit-fix-deps --orphans --json
539
+ ```
540
+
541
+ Output categorizes orphans into:
542
+ - ✅ **CLI Entry Points** - Expected orphans (entry points like @kb-labs/cli-bin)
543
+ - ✅ **Plugin Packages** - Usually standalone (@kb-labs/plugin-*, *-plugin)
544
+ - ✅ **External Libraries** - Consumed externally (@kb-labs/*-core, ui-*, etc.)
545
+ - ⚠️ **Internal Packages** - Review needed (might be dead code!)
546
+
547
+ Example output:
548
+ ```
549
+ 👻 Orphan Packages Analysis
550
+
551
+ 📦 Total @kb-labs/* packages: 90
552
+ 🔗 Packages with dependents: 70
553
+ 👻 Orphan packages: 25
554
+
555
+ ✅ CLI Entry Points (4) - Expected orphans:
556
+ @kb-labs/cli-bin
557
+ @kb-labs/analytics-cli
558
+ ...
559
+
560
+ 📦 Plugin Packages (6) - Usually standalone:
561
+ @kb-labs/ai-docs-plugin
562
+ ...
563
+
564
+ 📤 External/Library Packages (9) - Consumed externally:
565
+ @kb-labs/devlink-core
566
+ ...
567
+
568
+ ⚠️ Internal Packages Without Dependents (6) - Review needed:
569
+ kb-labs-shared/
570
+ @kb-labs/shared-boundaries
571
+ @kb-labs/shared-repo
572
+ @kb-labs/shared-textops
573
+
574
+ 📊 Summary:
575
+ Expected orphans: 19
576
+ Review needed: 6
577
+ ```
578
+
579
+ ### CI Combo Tool
580
+
581
+ Run all DevKit checks in one command for CI/CD pipelines:
582
+
583
+ ```bash
584
+ # Run all checks
585
+ npx kb-devkit-ci
586
+
587
+ # Skip specific checks
588
+ npx kb-devkit-ci --skip=exports,duplicates
589
+
590
+ # Run only specific checks
591
+ npx kb-devkit-ci --only=naming,imports
592
+
593
+ # JSON output for CI parsing
594
+ npx kb-devkit-ci --json
595
+ ```
596
+
597
+ **Checks performed:**
598
+ 1. ✅ Naming convention validation
599
+ 2. ✅ Import analysis (broken imports, unused deps, circular deps)
600
+ 3. ✅ Export analysis (unused exports, dead code)
601
+ 4. ✅ Duplicate dependencies
602
+ 5. ✅ Package structure validation
603
+ 6. ✅ Path validation (workspace deps, exports, bin)
604
+ 7. ✅ TypeScript types (dts generation, types field)
605
+
606
+ **CI-friendly features:**
607
+ - Exits with code 1 on failures
608
+ - JSON output for parsing
609
+ - Per-check timing information
610
+ - Summary with passed/failed counts
611
+
612
+ **Example GitHub Actions integration:**
613
+ ```yaml
614
+ name: DevKit Checks
615
+ on: [pull_request]
616
+ jobs:
617
+ devkit:
618
+ runs-on: ubuntu-latest
619
+ steps:
620
+ - uses: actions/checkout@v4
621
+ - name: Run DevKit CI
622
+ run: npx kb-devkit-ci --json > devkit-report.json
623
+ - name: Upload Report
624
+ uses: actions/upload-artifact@v4
625
+ with:
626
+ name: devkit-report
627
+ path: devkit-report.json
628
+ ```
629
+
630
+ ### QA Runner
631
+
632
+ **⚡ NEW: Comprehensive quality assurance with incremental builds**
633
+
634
+ Run all quality checks across the entire monorepo (build, lint, type-check, tests):
635
+
636
+ ```bash
637
+ # Run all QA checks
638
+ npx kb-devkit-qa
639
+
640
+ # Skip specific checks
641
+ npx kb-devkit-qa --skip-build --skip-tests
642
+
643
+ # JSON mode for AI agents
644
+ npx kb-devkit-qa --json
645
+ ```
646
+
647
+ **What it checks:**
648
+ 1. **Build** - All packages in correct layer order (13 layers, 125 packages)
649
+ - ⚡ **Incremental**: Only rebuilds when `src/` is newer than `dist/`
650
+ - 🚀 **Speed**: ~10-20 seconds when up-to-date (vs 5-10 minutes full rebuild)
651
+ 2. **Lint** - ESLint on all packages
652
+ 3. **Type Check** - TypeScript type checking on all packages
653
+ 4. **Tests** - Vitest tests on all packages (with `--passWithNoTests`)
654
+
655
+ **Key features:**
656
+ - ✅ Continues on errors (shows all failures, not just first)
657
+ - ✅ Progress indicators: `.` = passed, `F` = failed, `-` = skipped (up-to-date)
658
+ - ✅ Comprehensive summary report at the end
659
+ - ✅ JSON mode for CI/CD and AI agents
660
+ - ⚡ **30x faster** with incremental builds
661
+
662
+ **Example output:**
663
+ ```
664
+ 🚀 KB Labs QA Runner
665
+
666
+ 🔨 Building all packages in correct dependency order...
667
+ Found 13 layers to build
668
+
669
+ 🔨 Building Layer 1/13 (21 packages)...
670
+ --------------------- (all skipped, up-to-date)
671
+
672
+ ✅ Build complete: 0 passed, 0 failed, 100 skipped (up-to-date)
673
+
674
+ 📊 QA Summary Report
675
+ ✅ Build: 100 skipped (up-to-date)
676
+ ❌ Lint: 70/125 passed (56%)
677
+ ❌ Type Check: 60/125 passed (48%)
678
+ ❌ Tests: 78/125 passed (62%)
679
+
680
+ Total: 208 passed, 167 failed, 100 skipped
681
+ ```
682
+
683
+ **Root commands (package.json):**
684
+ ```bash
685
+ pnpm qa # Run all checks
686
+ pnpm qa:quick # Skip tests
687
+ pnpm qa:full # With baseline comparison
688
+ ```
689
+
690
+ **How incremental builds work:**
691
+ - Compares modification times of `src/` vs `dist/`
692
+ - Rebuilds only if source is newer than build output
693
+ - Skips packages that are already up-to-date
694
+ - First run builds all, subsequent runs ~20 seconds
695
+
696
+ **JSON mode example:**
697
+ ```json
698
+ {
699
+ "status": "failed",
700
+ "summary": {
701
+ "build": { "passed": 0, "failed": 0, "skipped": 100 },
702
+ "lint": { "passed": 70, "failed": 55, "skipped": 0 }
703
+ },
704
+ "failures": {
705
+ "lint": ["@kb-labs/cli", "@kb-labs/core", ...]
706
+ }
707
+ }
708
+ ```
709
+
710
+ ### Build Order Calculator
711
+
712
+ Calculate the correct build order for packages based on dependencies:
713
+
714
+ ```bash
715
+ # Show sequential build order
716
+ npx kb-devkit-build-order
717
+
718
+ # Show parallel build layers
719
+ npx kb-devkit-build-order --layers
720
+
721
+ # Build order for specific package
722
+ npx kb-devkit-build-order --package=workflow-runtime
723
+
724
+ # Generate build script
725
+ npx kb-devkit-build-order --script > build.sh
726
+ npx kb-devkit-build-order --layers --script > build-parallel.sh
727
+
728
+ # JSON output
729
+ npx kb-devkit-build-order --json
730
+ ```
731
+
732
+ **What it does:**
733
+ 1. **Builds dependency graph**: Analyzes all workspace dependencies
734
+ 2. **Topological sort**: Determines correct build order using Kahn's algorithm
735
+ 3. **Detects circular dependencies**: Shows packages involved in cycles
736
+ 4. **Parallel build layers**: Groups packages that can build in parallel
737
+ 5. **Generates build scripts**: Creates executable bash scripts for automation
738
+
739
+ **Example output:**
740
+ ```
741
+ 📦 Build order for @kb-labs/workflow-runtime:
742
+
743
+ 1. @kb-labs/cli-contracts
744
+ 2. @kb-labs/shared-cli-ui
745
+ 3. @kb-labs/core-sys
746
+ ...
747
+ 16. @kb-labs/workflow-runtime ⬅ target
748
+ ```
749
+
750
+ **With --layers:**
751
+ ```
752
+ Layer 1 (15 packages):
753
+ @kb-labs/core-types
754
+ @kb-labs/cli-contracts
755
+ ...
756
+
757
+ Layer 2 (23 packages):
758
+ @kb-labs/core-sys
759
+ @kb-labs/plugin-manifest
760
+ ...
761
+
762
+ Total layers: 5
763
+ Max parallelism: 23 packages
764
+ ```
765
+
766
+ ### Command Health Checker
767
+
768
+ Automatically check all CLI commands in the ecosystem:
769
+
770
+ ```bash
771
+ # Check all commands
772
+ npx kb-devkit-check-commands
773
+
774
+ # Quick check (faster)
775
+ npx kb-devkit-check-commands --fast
776
+
777
+ # Verbose output
778
+ npx kb-devkit-check-commands --verbose
779
+
780
+ # Custom timeout
781
+ npx kb-devkit-check-commands --timeout=10
782
+
783
+ # JSON output for CI
784
+ npx kb-devkit-check-commands --json
785
+ ```
786
+
787
+ **What it checks:**
788
+ 1. **Command discovery**: Finds all commands from plugin manifests
789
+ 2. **Help output**: Tests each command with `--help`
790
+ 3. **Exit codes**: Verifies commands exit with code 0
791
+ 4. **Timeouts**: Detects slow or hanging commands
792
+ 5. **Error detection**: Identifies broken commands with detailed errors
793
+
794
+ **Example output:**
795
+ ```
796
+ 🔍 KB Labs Command Health Checker
797
+
798
+ Found 107 commands to check
799
+
800
+ ✅ Working commands (103):
801
+ kb plugins:list
802
+ kb workflow:run
803
+ ...
804
+
805
+ ❌ Broken commands (4):
806
+ kb ai:analyze --help
807
+ └─ Error: Cannot find module '@kb-labs/ai-core'
808
+
809
+ 📊 Summary:
810
+ ✅ 103 working (96%)
811
+ ❌ 4 broken (4%)
812
+ ```
813
+
814
+ ### TypeScript Types Checker
815
+
816
+ Ensure all packages properly generate TypeScript declaration files:
817
+
818
+ ```bash
819
+ # Check all packages for types generation
820
+ npx kb-devkit-check-types
821
+
822
+ # Auto-fix dts: false → dts: true
823
+ npx kb-devkit-check-types --fix
824
+
825
+ # Check specific package
826
+ npx kb-devkit-check-types --package=mind-engine
827
+
828
+ # Verbose output
829
+ npx kb-devkit-check-types --verbose
830
+
831
+ # Show types dependency graph
832
+ npx kb-devkit-check-types --graph
833
+
834
+ # JSON output for CI
835
+ npx kb-devkit-check-types --json
836
+ ```
837
+
838
+ **What it checks:**
839
+ 1. **Technical debt detection**: Finds `dts: false` in tsup configs (bad practice!)
840
+ 2. **Missing configuration**: Detects packages without dts settings
841
+ 3. **package.json types field**: Validates "types" field exists
842
+ 4. **Actual .d.ts files**: Checks if declaration files exist in dist/
843
+ 5. **Auto-fix capability**: Can automatically change `dts: false` to `dts: true`
844
+
845
+ **Example output:**
846
+ ```
847
+ 🔍 KB Labs TypeScript Types Checker
848
+
849
+ Found 90 packages to check
850
+
851
+ 🔴 Technical Debt: 7 package(s) with dts: false
852
+
853
+ @kb-labs/cli-core
854
+ /path/to/tsup.config.ts
855
+ └─ Has "dts: false" - types not being generated!
856
+ ✅ Fixed: Changed to "dts: true"
857
+
858
+ 📊 Summary:
859
+ Total packages: 90
860
+ With TypeScript: 90
861
+ ✅ Clean: 21
862
+ 🔴 dts: false: 7 (technical debt!)
863
+ ⚠️ Other issues: 62
864
+ ```
865
+
866
+ **Why this matters:**
867
+
868
+ In a monorepo, TypeScript types form a dependency chain:
869
+ ```
870
+ Project A uses type G from Package B
871
+ Package B uses type L from Package M
872
+ ...
873
+ ```
874
+
875
+ If any package in the chain has `dts: false` or missing types, TypeScript compilation breaks. This tool helps identify and fix those broken chains automatically.
876
+
877
+ ### TypeScript Types Order
878
+
879
+ Calculate the correct order for types generation (separate from build order):
880
+
881
+ ```bash
882
+ # Show types generation order
883
+ npx kb-devkit-types-order
884
+
885
+ # Show parallel generation layers
886
+ npx kb-devkit-types-order --layers
887
+
888
+ # Types order for specific package
889
+ npx kb-devkit-types-order --package=workflow-runtime
890
+
891
+ # Show only broken type chains
892
+ npx kb-devkit-types-order --broken
893
+
894
+ # JSON output
895
+ npx kb-devkit-types-order --json
896
+ ```
897
+
898
+ **What it does:**
899
+ 1. **Types dependency analysis**: Tracks which packages import types from which other packages
900
+ 2. **Broken chain detection**: Finds packages that import types from packages with `dts: false`
901
+ 3. **Circular type dependencies**: Detects cycles in type imports
902
+ 4. **Topological sort**: Determines correct order for .d.ts generation
903
+ 5. **Parallel layers**: Groups packages whose types can be generated in parallel
904
+
905
+ **Example output:**
906
+ ```
907
+ 📘 Types generation order for @kb-labs/workflow-runtime:
908
+
909
+ 1. ✅ @kb-labs/plugin-manifest
910
+ 2. ✅ @kb-labs/shared-cli-ui
911
+ 3. ✅ @kb-labs/core-types
912
+ ...
913
+ 18. ✅ @kb-labs/workflow-runtime ⬅ target
914
+ ```
915
+
916
+ **Difference from build-order:**
917
+ - `build-order`: Tracks **runtime** dependencies (what needs to be built first)
918
+ - `types-order`: Tracks **type** dependencies (what types are imported from where)
919
+
920
+ ### TypeScript Types Audit
921
+
922
+ Centralized type safety audit for entire monorepo using TypeScript Compiler API:
923
+
924
+ ```bash
925
+ # Full audit report
926
+ npx kb-devkit-types-audit
927
+
928
+ # Audit specific package
929
+ npx kb-devkit-types-audit --package=workflow-runtime
930
+
931
+ # Show only critical errors
932
+ npx kb-devkit-types-audit --errors-only
933
+
934
+ # Detailed coverage report
935
+ npx kb-devkit-types-audit --coverage
936
+
937
+ # JSON output
938
+ npx kb-devkit-types-audit --json
939
+ ```
940
+
941
+ **What it does:**
942
+ 1. **Deep type analysis**: Uses TypeScript Compiler API for semantic analysis
943
+ 2. **Type errors**: Finds all type errors across monorepo (what `tsc` would show)
944
+ 3. **Type coverage**: Calculates coverage % for each package
945
+ 4. **Impact analysis**: Shows which packages are affected by type errors
946
+ 5. **Safety issues**: Detects `any` usage, `@ts-ignore` comments, missing types
947
+
948
+ **Example output:**
949
+ ```
950
+ 📊 TypeScript Type Safety Audit Report
951
+
952
+ ❌ Critical Issues (12 packages with type errors):
953
+ @kb-labs/workflow-runtime
954
+ 45 error(s) - impacts 8 package(s)
955
+ └─ ./src/auth.ts:45:10
956
+ Type 'any' is not assignable to 'string[]'
957
+
958
+ 🔍 Type Safety Issues:
959
+ 127 usage(s) of 'any' type
960
+ 45 @ts-ignore comment(s)
961
+
962
+ 📈 Type Coverage:
963
+ ✅ Excellent (≥90%): 56 packages
964
+ ⚠️ Good (70-90%): 28 packages
965
+ ❌ Poor (<70%): 6 packages
966
+
967
+ 📊 Summary:
968
+ Total packages: 90
969
+ ❌ Type errors: 234
970
+ 📈 Avg coverage: 84.3%
971
+ ```
972
+
973
+ **Why this is powerful:**
974
+
975
+ Instead of running `tsc` in each package separately, you get:
976
+ - **Single centralized report** for entire monorepo
977
+ - **Impact analysis**: See which packages break if type X has errors
978
+ - **Type coverage metrics**: Track type safety over time
979
+ - **Dependency chains**: Understand type inheritance relationships
980
+
981
+ See [USAGE_GUIDE.md](./USAGE_GUIDE.md) for comprehensive usage examples, real-world use cases, and best practices.
982
+
983
+ **Automatic Build Configuration:**
984
+
985
+ After sync, DevKit automatically generates `tsconfig.build.json` for all packages with `tsup.config.ts`. This ensures proper bundling configuration without manual setup.
986
+
987
+ To generate `tsup.external.json` manually (if needed):
988
+
989
+ ```bash
990
+ npx kb-devkit-tsup-external --generate
991
+ ```
992
+
993
+ ## ✨ Features
994
+
995
+ - **TypeScript**: Ready-to-use `tsconfig` for libraries, Node services, and CLIs
996
+ - **ESLint**: ESLint 9 flat config with TypeScript support
997
+ - **Prettier**: Single opinionated formatting profile
998
+ - **Vitest**: Base test/coverage profile with lib/node overlays
999
+ - **Tsup**: Standard builds for libraries and Node services
1000
+ - **GitHub Actions**: Reusable CI/PR/Release workflows
1001
+ - **AI Agents**: Standardized Cursor agents for common development tasks
1002
+ - **Fixtures**: Validation fixtures to ensure DevKit changes don't break downstream consumers
1003
+ - **Repository Sync**: Automated synchronization system to keep projects up-to-date
1004
+
1005
+ ## 📁 Repository Structure
1006
+
1007
+ ```
1008
+ kb-labs-devkit/
1009
+ ├── agents/ # AI agent definitions
1010
+ │ ├── devkit-maintainer/ # DevKit maintainer agent
1011
+ │ ├── test-generator/ # Test generator agent
1012
+ │ ├── docs-crafter/ # Documentation drafter agent
1013
+ │ └── release-manager/ # Release manager agent
1014
+ ├── bin/ # Executable scripts
1015
+ │ └── devkit-sync.mjs # Sync tool binary
1016
+ ├── eslint/ # ESLint presets
1017
+ ├── fixtures/ # Validation fixtures
1018
+ │ ├── lib/ # Library fixture
1019
+ │ ├── cli/ # CLI fixture
1020
+ │ ├── web/ # Web app fixture
1021
+ │ └── monorepo/ # Monorepo fixture
1022
+ ├── prettier/ # Prettier config
1023
+ ├── scripts/ # Utility scripts
1024
+ ├── sync/ # Sync system
1025
+ ├── tsconfig/ # TypeScript configs
1026
+ ├── tsup/ # Tsup configs
1027
+ ├── vite/ # Vite configs
1028
+ ├── vitest/ # Vitest configs
1029
+ └── docs/ # Documentation
1030
+ └── adr/ # Architecture Decision Records
1031
+ ```
1032
+
1033
+ ### Directory Descriptions
1034
+
1035
+ - **`agents/`** - Pre-configured AI agent definitions for Cursor and other IDE assistants
1036
+ - **`bin/`** - Executable scripts (sync tool)
1037
+ - **`fixtures/`** - Validation fixtures that act as minimal, real-world consumer projects
1038
+ - **`docs/`** - Documentation including ADRs and guides
1039
+ - **Preset directories** (`tsconfig/`, `eslint/`, `prettier/`, `vitest/`, `tsup/`) - Tooling presets
1040
+
1041
+ ## 📦 Presets
1042
+
1043
+ ### TypeScript (`tsconfig`)
1044
+
1045
+ Available configs:
1046
+ - `base.json`: strict base (ES2022, NodeNext, strict typing, isolatedModules)
1047
+ - `cli.json`: CLI application preset
1048
+ - `lib.json`: library preset
1049
+ - `node.json`: Node service – declarations, source maps, `include: ["src"]`
1050
+ - `react-lib.json`: React library preset
1051
+ - `react-app.json`: React application preset
1052
+ - `test.json`: Test configuration preset
1053
+
1054
+ All configs use `module: "NodeNext"` and `moduleResolution: "NodeNext"` for proper ESM support.
1055
+
1056
+ **Usage:**
1057
+ ```json
1058
+ {
1059
+ "extends": "@kb-labs/devkit/tsconfig/node.json"
1060
+ }
1061
+ ```
1062
+
1063
+ ### ESLint
1064
+
1065
+ - `eslint/node.js`: ESLint 9 flat config with TypeScript support
1066
+ - `eslint/react.js`: ESLint 9 flat config with React support
1067
+
1068
+ Features:
1069
+ - Uses `typescript-eslint` recommended rules
1070
+ - Ignores `dist/`, `coverage/`, `node_modules/`, `.yalc/`
1071
+ - Allows unused variables with `_` prefix
1072
+ - Consistent type imports
1073
+
1074
+ ### Prettier
1075
+
1076
+ - `prettier/index.json`: shared style (no semicolons, single quotes, width 100)
1077
+
1078
+ ### Tsup
1079
+
1080
+ - `tsup/node.js`: ESM-only build (target ES2022, sourcemap, clean, treeshake)
1081
+ - `tsup/react-lib.js`: React library build preset
1082
+
1083
+ **Automatic Configuration:**
1084
+
1085
+ DevKit automatically handles bundling configuration to prevent workspace packages from being bundled:
1086
+
1087
+ 1. **`tsconfig.build.json`**: Automatically generated by `kb-devkit-sync` for all packages with `tsup.config.ts`. This file extends your base `tsconfig.json` but sets `paths: {}` to prevent tsup from resolving workspace packages to their source files.
1088
+
1089
+ 2. **`tsup.external.json`**: Automatically generated by `kb-devkit-tsup-external` (runs in `postinstall`). This file lists all workspace packages and dependencies that should be treated as external by tsup.
1090
+
1091
+ **Usage:**
1092
+
1093
+ Your `tsup.config.ts` should reference `tsconfig.build.json`:
1094
+
1095
+ ```typescript
1096
+ import { defineConfig } from 'tsup';
1097
+ import nodePreset from '@kb-labs/devkit/tsup/node.js';
1098
+
1099
+ export default defineConfig({
1100
+ ...nodePreset,
1101
+ entry: { index: "src/index.ts" },
1102
+ tsconfig: "tsconfig.build.json", // Use build-specific tsconfig without paths
1103
+ });
1104
+ ```
1105
+
1106
+ The `nodePreset` automatically reads `tsup.external.json` and marks all workspace packages as external, ensuring they are not bundled.
1107
+
1108
+ Features:
1109
+ - ESM format only
1110
+ - ES2022 target
1111
+ - Source maps enabled
1112
+ - Tree shaking enabled
1113
+ - Clean output directory
1114
+ - Automatic `external` list generated from `dependencies` + `peerDependencies`
1115
+
1116
+ ### Vitest
1117
+
1118
+ - `vitest/node.js`: Node environment with coverage support
1119
+ - `vitest/react.js`: React environment with coverage support
1120
+
1121
+ Features:
1122
+ - Node/React environment
1123
+ - Coverage with V8 provider (disabled by default)
1124
+ - Excludes `node_modules/`, `dist/`, etc.
1125
+ - Strict coverage thresholds when enabled
1126
+
1127
+ ## 🛠️ Available Scripts
1128
+
1129
+ | Script | Description |
1130
+ |--------|-------------|
1131
+ | `kb-devkit-health` | **⚡ NEW:** Comprehensive monorepo health check - detects missing deps, build failures, type errors |
1132
+ | `kb-devkit-ci` | Run all critical checks (naming, imports, exports, duplicates, paths, types) |
1133
+ | `kb-devkit-fix-deps` | Auto-fix dependency issues (unused deps, missing deps, version alignment) |
1134
+ | `kb-devkit-stats` | Get monorepo health score and statistics |
1135
+ | `kb-devkit-check-imports` | Check for broken imports, unused deps, circular deps |
1136
+ | `kb-devkit-check-exports` | Find unused exports and dead code |
1137
+ | `kb-devkit-types-audit` | Deep TypeScript type safety analysis for entire monorepo |
1138
+ | `pnpm fixtures:check` | Check all fixtures (recommended for CI) |
1139
+ | `pnpm fixtures:lint` | Lint all fixtures |
1140
+ | `pnpm fixtures:test` | Test all fixtures |
1141
+ | `pnpm fixtures:build` | Build all fixtures |
1142
+ | `pnpm fixtures:bootstrap` | Bootstrap all fixtures |
1143
+ | `pnpm fixtures:clean` | Clean all fixtures |
1144
+ | `pnpm fixtures:ci` | Run fixtures check for CI |
1145
+
1146
+ ### 🏥 Health Check Tool
1147
+
1148
+ The `kb-devkit-health` tool is a comprehensive monorepo health check that catches critical issues early:
1149
+
1150
+ ```bash
1151
+ # Full health check (recommended before major changes)
1152
+ npx kb-devkit-health
1153
+
1154
+ # Quick check (skips slow build and type checks)
1155
+ npx kb-devkit-health --quick
1156
+
1157
+ # JSON output for CI/CD or AI agents
1158
+ npx kb-devkit-health --json
1159
+
1160
+ # Check specific package
1161
+ npx kb-devkit-health --package cli-core
1162
+ ```
1163
+
1164
+ **What it checks:**
1165
+ - ✅ Missing runtime dependencies (imports not in package.json)
1166
+ - ✅ Cross-repo workspace vs link inconsistencies
1167
+ - ✅ Build failures across all packages
1168
+ - ✅ TypeScript type errors
1169
+ - ✅ Circular dependencies
1170
+ - ✅ Orphan packages
1171
+
1172
+ **Example output:**
1173
+ ```
1174
+ 🏥 KB Labs Monorepo Health Check
1175
+
1176
+ Analyzing 208 package(s)...
1177
+
1178
+ ❌ CRITICAL ISSUES (blocking)
1179
+ • 4 package(s) with missing runtime dependencies
1180
+ @kb-labs/cli-commands: @kb-labs/plugin-contracts, @kb-labs/devkit
1181
+
1182
+ • 2 cross-repo dep(s) using workspace:* instead of link:
1183
+ @kb-labs/core-sys → @kb-labs/shared-cli-ui
1184
+
1185
+ Health Score: 50/100 (Grade F)
1186
+
1187
+ Recommended Actions:
1188
+ 1. Fix missing runtime dependencies:
1189
+ kb-devkit-fix-deps --add-missing
1190
+ ```
1191
+
1192
+ ## 📋 Development Policies
1193
+
1194
+ - **Code Style**: ESLint + Prettier, TypeScript strict mode
1195
+ - **Testing**: Vitest with fixtures for integration testing
1196
+ - **Versioning**: SemVer with automated releases through Changesets
1197
+ - **Architecture**: Document decisions in ADRs (see `docs/adr/`)
1198
+ - **Preset Stability**: Presets maintain backward compatibility
1199
+ - **Sync System**: Automated drift detection and synchronization
1200
+
1201
+ ## 🔧 Requirements
1202
+
1203
+ - **Node.js**: >= 18.18.0
1204
+ - **pnpm**: >= 9.0.0
1205
+
1206
+ ## ⚙️ Configuration
1207
+
1208
+ ### Repository Synchronization
1209
+
1210
+ The DevKit includes a powerful sync system that allows you to keep your project up-to-date with the latest DevKit assets. This is especially useful for maintaining consistent tooling across KB Labs projects.
1211
+
1212
+ #### Quick Sync
1213
+
1214
+ ```bash
1215
+ # Run sync (creates/updates files)
1216
+ npx kb-devkit-sync
1217
+
1218
+ # Check for drift without making changes
1219
+ npx kb-devkit-sync --check
1220
+
1221
+ # Force overwrite existing files
1222
+ npx kb-devkit-sync --force
1223
+ ```
1224
+
1225
+ #### Sync Configuration
1226
+
1227
+ Create a `kb-labs.config.json` file in your project root to customize sync behavior:
1228
+
1229
+ ```json
1230
+ {
1231
+ "sync": {
1232
+ "enabled": true,
1233
+ "disabled": ["vscode"],
1234
+ "only": ["ci", "agents"],
1235
+ "scope": "managed-only",
1236
+ "force": false,
1237
+ "overrides": {
1238
+ "cursorrules": { "to": ".config/cursor/rules.json" }
1239
+ },
1240
+ "targets": {
1241
+ "workflows": {
1242
+ "from": ".github/workflows",
1243
+ "to": ".github/workflows",
1244
+ "type": "dir"
1245
+ }
1246
+ }
1247
+ }
1248
+ }
1249
+ ```
1250
+
1251
+ #### Configuration Options
1252
+
1253
+ - **`enabled`**: Boolean to enable/disable sync entirely (default: true)
1254
+ - **`disabled`**: Array of target names to skip during sync
1255
+ - **`only`**: Array of target names to sync (if empty, syncs all enabled targets)
1256
+ - **`scope`**: Drift detection mode: `"managed-only"` (default), `"strict"`, or `"all"`
1257
+ - **`force`**: Boolean to force overwrite existing files (can be set in config or via `--force` flag)
1258
+ - **`overrides`**: Override source paths, destination paths, or types for existing targets
1259
+ - **`targets`**: Add custom sync targets with `from`, `to`, and `type` properties
1260
+
1261
+ #### Available Targets
1262
+
1263
+ By default, the sync tool includes these targets:
1264
+ - **`agents`**: AI agent definitions → `.kb/devkit/agents/`
1265
+ - **`cursorrules`**: Cursor AI rules → `.cursorrules`
1266
+ - **`vscode`**: VS Code settings → `.vscode/settings.json`
1267
+
1268
+ #### Drift Detection Modes
1269
+
1270
+ The sync tool supports three drift detection modes:
1271
+
1272
+ - **`managed-only`** (default): Compare only files explicitly synced from DevKit. Safe for repositories with additional project-specific files.
1273
+ - **`strict`**: Compare entire target directories and flag unmanaged files as drift. Use when you want to ensure no extra files exist.
1274
+ - **`all`**: Legacy mode that combines strict checking with unmanaged file detection.
1275
+
1276
+ ### GitHub Actions Integration
1277
+
1278
+ Add a drift check to your CI to ensure your project stays in sync:
1279
+
1280
+ ```yaml
1281
+ name: CI
1282
+ on: [push, pull_request]
1283
+ jobs:
1284
+ ci:
1285
+ uses: kb-labs/devkit/.github/workflows/ci.yml@main
1286
+ with:
1287
+ enable-drift-check: true
1288
+ ```
1289
+
1290
+ Or use the dedicated drift check workflow:
1291
+
1292
+ ```yaml
1293
+ name: Drift Check
1294
+ on:
1295
+ workflow_dispatch: {}
1296
+ schedule:
1297
+ - cron: '0 3 * * *' # nightly
1298
+ jobs:
1299
+ drift:
1300
+ uses: kb-labs/devkit/.github/workflows/drift-check.yml@main
1301
+ ```
1302
+
1303
+ ## 🤖 AI Agents
1304
+
1305
+ This DevKit includes pre-configured AI agents that can be synced into any KB Labs project. These agents are opinionated around KB Labs workflows (pnpm, devkit presets, monorepo). Outside this ecosystem, adapt accordingly.
1306
+
1307
+ | Agent | Purpose |
1308
+ |-------|---------|
1309
+ | **DevKit Maintainer** | Enforce unified tooling (tsconfig, eslint, prettier, vitest, tsup, CI) |
1310
+ | **Test Generator** | Generate and maintain pragmatic unit tests |
1311
+ | **Docs Drafter** | Draft and update README/CONTRIBUTING/ADR docs |
1312
+ | **Release Manager** | Prepare release plans, changelog, and GitHub releases |
1313
+
1314
+ Each agent includes:
1315
+ - **Prompt**: AI instructions and context
1316
+ - **Runbook**: step-by-step procedures
1317
+ - **Context**: file patterns and permissions
1318
+
1319
+ To sync agents into your project:
1320
+ ```bash
1321
+ # Copy agent definitions from this DevKit
1322
+ npx kb-devkit-sync agents
1323
+ ```
1324
+
1325
+ They are designed for Cursor AI agents, but can also be adapted for GitHub Copilot Chat or other IDE assistants.
1326
+
1327
+ See [`AGENTS.md`](./AGENTS.md) for detailed agent documentation.
1328
+
1329
+ ## 🧪 Validation Fixtures
1330
+
1331
+ This DevKit includes fixtures (`/fixtures/*`) that act as minimal, real-world consumer projects to validate DevKit changes:
1332
+
1333
+ - **`fixtures/lib`**: A simple TypeScript library using DevKit presets
1334
+ - **`fixtures/cli`**: A CLI application with Commander.js
1335
+ - **`fixtures/web`**: A web application with DOM API and fetch
1336
+ - **`fixtures/monorepo`**: A monorepo with shared library and app packages
1337
+
1338
+ Each fixture has its own `package.json` and extends DevKit via imports/extends (no relative paths).
1339
+
1340
+ ### Fixture Management
1341
+
1342
+ Use the automated fixture management script:
1343
+
1344
+ ```bash
1345
+ # Check all fixtures (recommended for CI)
1346
+ pnpm fixtures:check
1347
+
1348
+ # Check specific fixture
1349
+ pnpm fixtures lib check
1350
+ pnpm fixtures cli test
1351
+ pnpm fixtures web build
1352
+ pnpm fixtures monorepo lint
1353
+
1354
+ # Run specific action on all fixtures
1355
+ pnpm fixtures:lint # Lint all fixtures
1356
+ pnpm fixtures:test # Test all fixtures
1357
+ pnpm fixtures:build # Build all fixtures
1358
+
1359
+ # Show help
1360
+ pnpm fixtures
1361
+ ```
1362
+
1363
+ The `fixtures:check` script runs all validation steps and is used in CI to ensure DevKit changes don't break downstream consumers.
1364
+
1365
+ See [`scripts/README.md`](./scripts/README.md) for detailed fixture management documentation.
1366
+
1367
+ ## 📚 Documentation
1368
+
1369
+ - [Documentation Standard](./docs/DOCUMENTATION.md) - Full documentation guidelines
1370
+ - [Contributing Guide](./CONTRIBUTING.md) - How to contribute
1371
+ - [Architecture Decisions](./docs/adr/) - ADRs for this project
1372
+
1373
+ **Guides:**
1374
+ - [AI Agents](./AGENTS.md) - AI agent documentation
1375
+ - [Fixture Management](./scripts/README.md) - Fixture management documentation
1376
+
1377
+ **Architecture:**
1378
+ - [ADR 0001: Repository Synchronization via DevKit](./docs/adr/0001-repo-synchronization-via-devkit.md) - Strategy for maintaining consistent tooling
1379
+ - [ADR 0002: ESM-only and NodeNext](./docs/adr/0002-esm-only-and-nodenext.md) - ESM-only modules with NodeNext resolution
1380
+ - [ADR 0003: Validation Fixtures Strategy](./docs/adr/0003-validation-fixtures-strategy.md) - Testing DevKit presets with realistic consumer projects
1381
+ - [ADR 0004: Testing Strategy and Quality Gates](./docs/adr/0004-testing-strategy-and-quality-gates.md) - Comprehensive testing approach
1382
+ - [ADR 0005: Build & Types Strategy](./docs/adr/0005-build-strategy.md) - Unified approach to build and type generation
1383
+ - [ADR 0006: Sequential Build & Type Safety](./docs/adr/0006-monorepo-build-and-types.md) - Build order and dependency resolution
1384
+ - [ADR 0007: Reusable Workflow Strategy](./docs/adr/0007-reusable-workflow-strategy.md) - Centralized CI workflows and drift check
1385
+ - [ADR 0008: Flexible Sync and Drift Management](./docs/adr/0008-flexible-sync-strategy.md) - Managed-only drift strategy with provenance tracking
1386
+ - [ADR 0011: Preventing Workspace Package Bundling](./docs/adr/0011-preventing-workspace-package-bundling.md) - Automatic externalization of workspace packages in tsup builds
1387
+
1388
+ ## Migration Guides
1389
+
1390
+ - [Migrating to Workspace External Bundling](./docs/guides/migrating-to-workspace-external-bundling.md) - Step-by-step guide for preventing workspace package bundling
1391
+
1392
+ ## 🔗 Related Packages
1393
+
1394
+ ### Dependencies
1395
+
1396
+ - None (devkit is a foundation package)
1397
+
1398
+ ### Used By
1399
+
1400
+ - [@kb-labs/core](https://github.com/KirillBaranov/kb-labs-core) - Core utilities
1401
+ - [@kb-labs/cli](https://github.com/KirillBaranov/kb-labs-cli) - CLI framework
1402
+ - [@kb-labs/audit](https://github.com/KirillBaranov/kb-labs-audit) - Audit framework
1403
+ - [@kb-labs/ai-review](https://github.com/KirillBaranov/kb-labs-ai-review) - AI Review
1404
+ - All other KB Labs projects
1405
+
1406
+ ### Ecosystem
1407
+
1408
+ - [KB Labs](https://github.com/KirillBaranov/kb-labs) - Main ecosystem repository
1409
+
1410
+ ## 💡 Use Cases
1411
+
1412
+ - Bootstrap new packages/services without copying configs
1413
+ - Enforce consistent style and rules across the ecosystem
1414
+ - Provide a single minimal CI for PRs and releases
1415
+ - Migrate existing projects to shared presets with minimal effort
1416
+ - Validate DevKit changes against real-world usage patterns
1417
+
1418
+ ## 📖 Migration Guide
1419
+
1420
+ ### Updating to Latest DevKit
1421
+
1422
+ To update your project to the latest DevKit version:
1423
+
1424
+ 1. **Update the package**:
1425
+ ```bash
1426
+ pnpm update @kb-labs/devkit
1427
+ ```
1428
+
1429
+ 2. **Check for drift**:
1430
+ ```bash
1431
+ npx kb-devkit-sync --check
1432
+ ```
1433
+
1434
+ 3. **Sync changes** (if drift found):
1435
+ ```bash
1436
+ npx kb-devkit-sync --force
1437
+ ```
1438
+
1439
+ 4. **Review and commit changes**:
1440
+ ```bash
1441
+ git add .
1442
+ git commit -m "chore: update devkit to latest version"
1443
+ ```
1444
+
1445
+ ### Migrating from Manual Setup
1446
+
1447
+ If you're migrating from manually copied configs to the sync system:
1448
+
1449
+ 1. **Install DevKit**:
1450
+ ```bash
1451
+ pnpm add -D @kb-labs/devkit
1452
+ ```
1453
+
1454
+ 2. **Create sync configuration**:
1455
+ ```json
1456
+ {
1457
+ "sync": {
1458
+ "disabled": ["vscode"],
1459
+ "overrides": {
1460
+ "cursorrules": { "to": ".cursorrules" }
1461
+ }
1462
+ }
1463
+ }
1464
+ ```
1465
+
1466
+ 3. **Run initial sync**:
1467
+ ```bash
1468
+ npx kb-devkit-sync --force
1469
+ ```
1470
+
1471
+ 4. **Remove old config files** and update imports to use DevKit presets
1472
+
1473
+ 5. **Add drift check to CI**:
1474
+ ```yaml
1475
+ jobs:
1476
+ ci:
1477
+ uses: kb-labs/devkit/.github/workflows/ci.yml@main
1478
+ with:
1479
+ enable-drift-check: true
1480
+ ```
1481
+
1482
+ ## ❓ FAQ
1483
+
1484
+ ### General
1485
+
1486
+ - **Can I override rules?** — Yes. Extend locally and add your overrides on top.
1487
+ - **How do I update?** — Bump `@kb-labs/devkit` and run `npx kb-devkit-sync --check` to see what changed.
1488
+ - **ESLint 9 flat config?** — Yes, all ESLint configs use the new flat config format.
1489
+ - **ESM only?** — Yes, all presets assume ESM. For CJS, add dual builds/transpilation in your project.
1490
+ - **TypeScript errors with module resolution?** — Ensure you're using `module: "NodeNext"` in your tsconfig.
1491
+ - **Importing specific files vs folders?** — Both are supported. Use `@kb-labs/devkit/tsconfig/node.json` for specific files or `
1492
+
1493
+
1494
+ ## 📦 Complete Tools Summary
1495
+
1496
+ DevKit provides **19 tools** for monorepo management and quality assurance:
1497
+
1498
+ ### Analysis Tools (8)
1499
+ 1. **Import Checker** - Find broken imports, unused dependencies, circular deps
1500
+ 2. **Export Checker** - Find unused exports and dead code
1501
+ 3. **Duplicate Checker** - Find duplicate dependencies
1502
+ 4. **Structure Checker** - Validate package structure
1503
+ 5. **Naming Validator** - Enforce Pyramid Rule naming convention
1504
+ 6. **Path Validator** - Validate workspace deps, exports, bin paths
1505
+ 7. **TypeScript Types Audit** - Deep type safety analysis across monorepo
1506
+ 8. **Visualizer** - Generate dependency graphs and stats
1507
+
1508
+ ### Automation Tools (8)
1509
+ 1. **⚡ QA Runner** - Comprehensive quality checks with incremental builds (NEW!)
1510
+ 2. **Quick Statistics** - Get health scores and metrics
1511
+ 3. **Dependency Auto-Fixer** - Auto-fix dependency issues
1512
+ 4. **CI Combo Tool** - Run all checks in one command
1513
+ 5. **Build Order Calculator** - Determine correct build order
1514
+ 6. **Types Order Calculator** - Calculate types generation order
1515
+ 7. **Command Health Checker** - Verify all CLI commands work
1516
+ 8. **TypeScript Types Checker** - Ensure all packages generate types
1517
+
1518
+ ### Infrastructure Tools (3)
1519
+ 1. **Repository Sync** - Sync DevKit assets across projects
1520
+ 2. **Path Aliases Generator** - Generate workspace path aliases
1521
+ 3. **Tsup External Generator** - Generate external dependencies list
1522
+
1523
+ ### Quick Access
1524
+ ```bash
1525
+ # Quality Assurance (recommended)
1526
+ npx kb-devkit-qa # ⚡ Incremental builds (~20s)
1527
+ npx kb-devkit-ci # All static checks
1528
+
1529
+ # Analysis
1530
+ npx kb-devkit-check-imports # Imports
1531
+ npx kb-devkit-check-exports # Exports
1532
+ npx kb-devkit-types-audit # Type safety
1533
+
1534
+ # Automation
1535
+ npx kb-devkit-fix-deps --dry-run # Fix dependencies
1536
+ npx kb-devkit-build-order --layers # Build order
1537
+ npx kb-devkit-stats --health # Health score
1538
+ ```
1539
+
1540
+ ## License
1541
+
1542
+ MIT License - see [LICENSE](LICENSE) for details.