@tailor-platform/erp-kit 0.1.1 → 0.2.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 (342) hide show
  1. package/CHANGELOG.md +12 -0
  2. package/README.md +158 -62
  3. package/dist/cli.js +1010 -270
  4. package/package.json +11 -8
  5. package/schemas/module/command.yml +1 -0
  6. package/schemas/module/model.yml +14 -0
  7. package/schemas/module/query.yml +53 -0
  8. package/skills/{app-compose-1-requirement-analysis → erp-kit-app-1-requirements}/SKILL.md +2 -2
  9. package/skills/{app-compose-2-requirements-breakdown → erp-kit-app-2-breakdown}/SKILL.md +3 -3
  10. package/skills/{app-compose-3-doc-review → erp-kit-app-3-doc-review}/SKILL.md +2 -2
  11. package/skills/{app-compose-4-design-mock → erp-kit-app-4-design}/SKILL.md +3 -3
  12. package/skills/{app-compose-5-design-mock-review → erp-kit-app-5-design-review}/SKILL.md +4 -4
  13. package/skills/{app-compose-6-implementation-spec → erp-kit-app-6-impl-spec}/SKILL.md +3 -3
  14. package/skills/{mock-scenario → erp-kit-mock-scenario}/SKILL.md +1 -1
  15. package/skills/{1-module-docs → erp-kit-module-1-docs}/SKILL.md +2 -2
  16. package/skills/{2-module-feature-breakdown → erp-kit-module-2-feature-breakdown}/SKILL.md +13 -9
  17. package/skills/erp-kit-module-2-feature-breakdown/references/naming.md +59 -0
  18. package/skills/{3-module-doc-review → erp-kit-module-3-doc-review}/SKILL.md +83 -25
  19. package/skills/erp-kit-module-4-tdd/SKILL.md +94 -0
  20. package/skills/erp-kit-module-4-tdd/references/cross-module-dependency.md +133 -0
  21. package/skills/{4-module-tdd-implementation → erp-kit-module-4-tdd}/references/db-relations.md +5 -1
  22. package/skills/{4-module-tdd-implementation → erp-kit-module-4-tdd}/references/exports.md +1 -1
  23. package/skills/erp-kit-module-4-tdd/references/generated-code.md +32 -0
  24. package/skills/{5-module-implementation-review → erp-kit-module-5-impl-review}/SKILL.md +46 -44
  25. package/skills/erp-kit-module-5-impl-review/references/commands.md +62 -0
  26. package/skills/erp-kit-module-5-impl-review/references/errors.md +10 -0
  27. package/skills/{5-module-implementation-review → erp-kit-module-5-impl-review}/references/testing.md +1 -1
  28. package/skills/erp-kit-module-shared/SKILL.md +16 -0
  29. package/skills/erp-kit-module-shared/references/commands.md +203 -0
  30. package/skills/erp-kit-module-shared/references/errors.md +35 -0
  31. package/skills/erp-kit-module-shared/references/queries.md +168 -0
  32. package/skills/erp-kit-module-shared/references/structure.md +36 -0
  33. package/skills/{3-module-doc-review → erp-kit-module-shared}/references/testing.md +4 -3
  34. package/skills/erp-kit-update/SKILL.md +64 -0
  35. package/src/cli.doc.test.ts +65 -0
  36. package/src/cli.ts +3 -117
  37. package/src/commands/app/index.ts +74 -0
  38. package/src/commands/check.test.ts +3 -2
  39. package/src/commands/check.ts +3 -2
  40. package/src/commands/index.ts +73 -0
  41. package/src/commands/init.test.ts +22 -5
  42. package/src/commands/init.ts +25 -16
  43. package/src/commands/license.ts +193 -0
  44. package/src/commands/mock/index.ts +2 -2
  45. package/src/commands/mock/start.ts +1 -1
  46. package/src/commands/mock/validate.test.ts +1 -1
  47. package/src/commands/module/generate.ts +35 -0
  48. package/src/commands/module/index.ts +87 -0
  49. package/src/commands/module/list.test.ts +57 -0
  50. package/src/commands/module/list.ts +64 -0
  51. package/src/commands/scaffold-templates.ts +65 -0
  52. package/src/commands/scaffold.test.ts +97 -2
  53. package/src/commands/scaffold.ts +24 -3
  54. package/src/commands/sync-check.test.ts +88 -1
  55. package/src/commands/sync-check.ts +41 -2
  56. package/src/generator/generate-code.test.ts +200 -0
  57. package/src/generator/generate-code.ts +260 -0
  58. package/src/generator/parse-command-doc.test.ts +159 -0
  59. package/src/generator/parse-command-doc.ts +116 -0
  60. package/src/integration.test.ts +6 -8
  61. package/src/module.ts +10 -9
  62. package/src/modules/item-management/README.md +38 -0
  63. package/src/modules/item-management/command/activateItem.generated.ts +6 -0
  64. package/src/modules/item-management/command/activateItem.test.ts +76 -0
  65. package/src/modules/item-management/command/activateItem.ts +42 -0
  66. package/src/modules/item-management/command/assignItemToTaxonomy.generated.ts +6 -0
  67. package/src/modules/item-management/command/assignItemToTaxonomy.test.ts +88 -0
  68. package/src/modules/item-management/command/assignItemToTaxonomy.ts +63 -0
  69. package/src/modules/item-management/command/createItem.generated.ts +6 -0
  70. package/src/modules/item-management/command/createItem.test.ts +152 -0
  71. package/src/modules/item-management/command/createItem.ts +72 -0
  72. package/src/modules/item-management/command/createTaxonomyNode.generated.ts +6 -0
  73. package/src/modules/item-management/command/createTaxonomyNode.test.ts +126 -0
  74. package/src/modules/item-management/command/createTaxonomyNode.ts +70 -0
  75. package/src/modules/item-management/command/deactivateItem.generated.ts +6 -0
  76. package/src/modules/item-management/command/deactivateItem.test.ts +76 -0
  77. package/src/modules/item-management/command/deactivateItem.ts +42 -0
  78. package/src/modules/item-management/command/deleteItem.generated.ts +6 -0
  79. package/src/modules/item-management/command/deleteItem.test.ts +61 -0
  80. package/src/modules/item-management/command/deleteItem.ts +38 -0
  81. package/src/modules/item-management/command/deleteTaxonomyNode.generated.ts +6 -0
  82. package/src/modules/item-management/command/deleteTaxonomyNode.test.ts +73 -0
  83. package/src/modules/item-management/command/deleteTaxonomyNode.ts +50 -0
  84. package/src/modules/item-management/command/moveTaxonomyNode.generated.ts +6 -0
  85. package/src/modules/item-management/command/moveTaxonomyNode.test.ts +136 -0
  86. package/src/modules/item-management/command/moveTaxonomyNode.ts +85 -0
  87. package/src/modules/item-management/command/reactivateItem.generated.ts +6 -0
  88. package/src/modules/item-management/command/reactivateItem.test.ts +76 -0
  89. package/src/modules/item-management/command/reactivateItem.ts +42 -0
  90. package/src/modules/item-management/command/removeItemFromTaxonomy.generated.ts +6 -0
  91. package/src/modules/item-management/command/removeItemFromTaxonomy.test.ts +43 -0
  92. package/src/modules/item-management/command/removeItemFromTaxonomy.ts +30 -0
  93. package/src/modules/item-management/command/updateItem.generated.ts +6 -0
  94. package/src/modules/item-management/command/updateItem.test.ts +178 -0
  95. package/src/modules/item-management/command/updateItem.ts +103 -0
  96. package/src/modules/item-management/command/updateTaxonomyNode.generated.ts +6 -0
  97. package/src/modules/item-management/command/updateTaxonomyNode.test.ts +88 -0
  98. package/src/modules/item-management/command/updateTaxonomyNode.ts +62 -0
  99. package/src/modules/item-management/db/item.ts +47 -0
  100. package/src/modules/item-management/db/itemTaxonomyAssignment.ts +49 -0
  101. package/src/modules/item-management/db/taxonomyNode.ts +34 -0
  102. package/src/modules/item-management/docs/commands/ActivateItem.md +32 -0
  103. package/src/modules/item-management/docs/commands/AssignItemToTaxonomy.md +38 -0
  104. package/src/modules/item-management/docs/commands/CreateItem.md +44 -0
  105. package/src/modules/item-management/docs/commands/CreateTaxonomyNode.md +44 -0
  106. package/src/modules/item-management/docs/commands/DeactivateItem.md +34 -0
  107. package/src/modules/item-management/docs/commands/DeleteItem.md +35 -0
  108. package/src/modules/item-management/docs/commands/DeleteTaxonomyNode.md +39 -0
  109. package/src/modules/item-management/docs/commands/MoveTaxonomyNode.md +45 -0
  110. package/src/modules/item-management/docs/commands/ReactivateItem.md +34 -0
  111. package/src/modules/item-management/docs/commands/RemoveItemFromTaxonomy.md +30 -0
  112. package/src/modules/item-management/docs/commands/UpdateItem.md +55 -0
  113. package/src/modules/item-management/docs/commands/UpdateTaxonomyNode.md +36 -0
  114. package/src/modules/item-management/docs/features/item-lifecycle.md +60 -0
  115. package/src/modules/item-management/docs/features/item-taxonomy.md +65 -0
  116. package/src/modules/item-management/docs/models/ItemTaxonomyAssignment.md +36 -0
  117. package/src/modules/item-management/docs/models/TaxonomyNode.md +47 -0
  118. package/src/modules/item-management/docs/models/item.md +59 -0
  119. package/src/modules/item-management/docs/queries/CalculateNodeDepth.md +36 -0
  120. package/src/modules/item-management/docs/queries/CalculateSubtreeDepth.md +40 -0
  121. package/src/modules/item-management/docs/queries/DetectCircularReference.md +41 -0
  122. package/src/modules/item-management/docs/queries/GetItem.md +38 -0
  123. package/src/modules/item-management/docs/queries/GetItemTaxonomyAssignment.md +29 -0
  124. package/src/modules/item-management/docs/queries/GetTaxonomyNode.md +35 -0
  125. package/src/modules/item-management/docs/queries/GetTaxonomyNodeAssignments.md +29 -0
  126. package/src/modules/item-management/docs/queries/GetTaxonomyNodeChildren.md +29 -0
  127. package/src/modules/item-management/generated/enums.ts +9 -0
  128. package/src/modules/item-management/generated/kysely-tailordb.ts +62 -0
  129. package/src/modules/item-management/index.ts +53 -0
  130. package/src/modules/item-management/lib/_db_deps.ts +13 -0
  131. package/src/modules/item-management/lib/errors.generated.ts +117 -0
  132. package/src/modules/item-management/lib/permissions.generated.ts +17 -0
  133. package/src/modules/item-management/lib/types.ts +19 -0
  134. package/src/modules/item-management/module.ts +97 -0
  135. package/src/modules/item-management/query/calculateNodeDepth.generated.ts +5 -0
  136. package/src/modules/item-management/query/calculateNodeDepth.test.ts +56 -0
  137. package/src/modules/item-management/query/calculateNodeDepth.ts +28 -0
  138. package/src/modules/item-management/query/calculateSubtreeDepth.generated.ts +5 -0
  139. package/src/modules/item-management/query/calculateSubtreeDepth.test.ts +75 -0
  140. package/src/modules/item-management/query/calculateSubtreeDepth.ts +29 -0
  141. package/src/modules/item-management/query/detectCircularReference.generated.ts +5 -0
  142. package/src/modules/item-management/query/detectCircularReference.test.ts +61 -0
  143. package/src/modules/item-management/query/detectCircularReference.ts +32 -0
  144. package/src/modules/item-management/query/getItem.generated.ts +5 -0
  145. package/src/modules/item-management/query/getItem.test.ts +67 -0
  146. package/src/modules/item-management/query/getItem.ts +20 -0
  147. package/src/modules/item-management/query/getItemTaxonomyAssignment.generated.ts +5 -0
  148. package/src/modules/item-management/query/getItemTaxonomyAssignment.test.ts +25 -0
  149. package/src/modules/item-management/query/getItemTaxonomyAssignment.ts +18 -0
  150. package/src/modules/item-management/query/getTaxonomyNode.generated.ts +5 -0
  151. package/src/modules/item-management/query/getTaxonomyNode.test.ts +47 -0
  152. package/src/modules/item-management/query/getTaxonomyNode.ts +18 -0
  153. package/src/modules/item-management/query/getTaxonomyNodeAssignments.generated.ts +5 -0
  154. package/src/modules/item-management/query/getTaxonomyNodeAssignments.test.ts +25 -0
  155. package/src/modules/item-management/query/getTaxonomyNodeAssignments.ts +16 -0
  156. package/src/modules/item-management/query/getTaxonomyNodeChildren.generated.ts +5 -0
  157. package/src/modules/item-management/query/getTaxonomyNodeChildren.test.ts +34 -0
  158. package/src/modules/item-management/query/getTaxonomyNodeChildren.ts +16 -0
  159. package/src/modules/item-management/tailor.config.ts +11 -0
  160. package/src/modules/item-management/testing/fixtures.ts +81 -0
  161. package/src/modules/primitives/command/activateCategory.generated.ts +6 -0
  162. package/src/modules/primitives/command/activateCategory.test.ts +11 -29
  163. package/src/modules/primitives/command/activateCategory.ts +27 -34
  164. package/src/modules/primitives/command/activateCurrency.generated.ts +6 -0
  165. package/src/modules/primitives/command/activateCurrency.test.ts +11 -29
  166. package/src/modules/primitives/command/activateCurrency.ts +27 -34
  167. package/src/modules/primitives/command/activateUnit.generated.ts +6 -0
  168. package/src/modules/primitives/command/activateUnit.test.ts +11 -15
  169. package/src/modules/primitives/command/activateUnit.ts +27 -34
  170. package/src/modules/primitives/command/createCategory.generated.ts +6 -0
  171. package/src/modules/primitives/command/createCategory.test.ts +27 -39
  172. package/src/modules/primitives/command/createCategory.ts +53 -62
  173. package/src/modules/primitives/command/createCurrency.generated.ts +6 -0
  174. package/src/modules/primitives/command/createCurrency.test.ts +78 -71
  175. package/src/modules/primitives/command/createCurrency.ts +43 -48
  176. package/src/modules/primitives/command/createExchangeRate.generated.ts +6 -0
  177. package/src/modules/primitives/command/createExchangeRate.test.ts +101 -100
  178. package/src/modules/primitives/command/createExchangeRate.ts +50 -59
  179. package/src/modules/primitives/command/createUnit.generated.ts +6 -0
  180. package/src/modules/primitives/command/createUnit.test.ts +92 -95
  181. package/src/modules/primitives/command/createUnit.ts +54 -57
  182. package/src/modules/primitives/command/deactivateCategory.generated.ts +6 -0
  183. package/src/modules/primitives/command/deactivateCategory.test.ts +27 -28
  184. package/src/modules/primitives/command/deactivateCategory.ts +43 -50
  185. package/src/modules/primitives/command/deactivateCurrency.generated.ts +6 -0
  186. package/src/modules/primitives/command/deactivateCurrency.test.ts +23 -38
  187. package/src/modules/primitives/command/deactivateCurrency.ts +31 -38
  188. package/src/modules/primitives/command/deactivateUnit.generated.ts +6 -0
  189. package/src/modules/primitives/command/deactivateUnit.test.ts +27 -23
  190. package/src/modules/primitives/command/deactivateUnit.ts +39 -49
  191. package/src/modules/primitives/command/setBaseCurrency.generated.ts +6 -0
  192. package/src/modules/primitives/command/setBaseCurrency.test.ts +40 -33
  193. package/src/modules/primitives/command/setBaseCurrency.ts +43 -50
  194. package/src/modules/primitives/command/setReferenceUnit.generated.ts +6 -0
  195. package/src/modules/primitives/command/setReferenceUnit.test.ts +39 -35
  196. package/src/modules/primitives/command/setReferenceUnit.ts +46 -59
  197. package/src/modules/primitives/db/unit.ts +13 -3
  198. package/src/modules/primitives/docs/commands/ActivateCategory.md +1 -2
  199. package/src/modules/primitives/docs/commands/ActivateCurrency.md +1 -2
  200. package/src/modules/primitives/docs/commands/ActivateUnit.md +1 -2
  201. package/src/modules/primitives/docs/commands/CreateCategory.md +1 -4
  202. package/src/modules/primitives/docs/commands/CreateCurrency.md +3 -4
  203. package/src/modules/primitives/docs/commands/CreateExchangeRate.md +4 -5
  204. package/src/modules/primitives/docs/commands/CreateUnit.md +5 -5
  205. package/src/modules/primitives/docs/commands/DeactivateCategory.md +2 -3
  206. package/src/modules/primitives/docs/commands/DeactivateCurrency.md +2 -3
  207. package/src/modules/primitives/docs/commands/DeactivateUnit.md +2 -3
  208. package/src/modules/primitives/docs/commands/SetBaseCurrency.md +2 -3
  209. package/src/modules/primitives/docs/commands/SetReferenceUnit.md +2 -3
  210. package/src/modules/primitives/docs/models/Currency.md +4 -0
  211. package/src/modules/primitives/docs/models/ExchangeRate.md +4 -1
  212. package/src/modules/primitives/docs/models/Unit.md +4 -1
  213. package/src/modules/primitives/docs/models/UoMCategory.md +2 -0
  214. package/src/modules/primitives/docs/{commands → queries}/ConvertAmount.md +3 -5
  215. package/src/modules/primitives/docs/{commands → queries}/ConvertQuantity.md +3 -5
  216. package/src/modules/primitives/docs/queries/GetBaseCurrency.md +32 -0
  217. package/src/modules/primitives/docs/queries/GetCurrency.md +36 -0
  218. package/src/modules/primitives/docs/queries/GetUnit.md +36 -0
  219. package/src/modules/primitives/docs/queries/GetUoMCategory.md +36 -0
  220. package/src/modules/primitives/docs/queries/ListUnitsByCategory.md +26 -0
  221. package/src/modules/primitives/generated/kysely-tailordb.ts +24 -45
  222. package/src/modules/primitives/index.ts +17 -6
  223. package/src/modules/primitives/lib/errors.generated.ts +112 -0
  224. package/src/modules/primitives/{permissions.ts → lib/permissions.generated.ts} +9 -10
  225. package/src/modules/primitives/module.ts +39 -27
  226. package/src/modules/primitives/query/convertAmount.generated.ts +5 -0
  227. package/src/modules/primitives/{command → query}/convertAmount.test.ts +4 -21
  228. package/src/modules/primitives/query/convertAmount.ts +121 -0
  229. package/src/modules/primitives/query/convertQuantity.generated.ts +5 -0
  230. package/src/modules/primitives/{command → query}/convertQuantity.test.ts +8 -15
  231. package/src/modules/primitives/query/convertQuantity.ts +63 -0
  232. package/src/modules/primitives/query/getBaseCurrency.generated.ts +5 -0
  233. package/src/modules/primitives/query/getBaseCurrency.test.ts +28 -0
  234. package/src/modules/primitives/query/getBaseCurrency.ts +16 -0
  235. package/src/modules/primitives/query/getCurrency.generated.ts +5 -0
  236. package/src/modules/primitives/query/getCurrency.test.ts +47 -0
  237. package/src/modules/primitives/query/getCurrency.ts +18 -0
  238. package/src/modules/primitives/query/getUnit.generated.ts +5 -0
  239. package/src/modules/primitives/query/getUnit.test.ts +47 -0
  240. package/src/modules/primitives/query/getUnit.ts +18 -0
  241. package/src/modules/primitives/query/getUoMCategory.generated.ts +5 -0
  242. package/src/modules/primitives/query/getUoMCategory.test.ts +47 -0
  243. package/src/modules/primitives/query/getUoMCategory.ts +18 -0
  244. package/src/modules/primitives/query/listUnitsByCategory.generated.ts +5 -0
  245. package/src/modules/primitives/query/listUnitsByCategory.ts +16 -0
  246. package/src/modules/primitives/tailor.config.ts +3 -3
  247. package/src/modules/shared/defineCommand.test.ts +23 -10
  248. package/src/modules/shared/defineCommand.ts +23 -10
  249. package/src/modules/shared/defineQuery.test.ts +28 -0
  250. package/src/modules/shared/defineQuery.ts +16 -0
  251. package/src/modules/shared/internal.ts +3 -1
  252. package/src/modules/shared/requirePermission.test.ts +22 -21
  253. package/src/modules/shared/requirePermission.ts +8 -2
  254. package/src/modules/shared/result.ts +12 -0
  255. package/src/modules/shared/types.ts +8 -0
  256. package/src/modules/testing/index.ts +36 -11
  257. package/src/modules/user-management/command/activateUser.generated.ts +6 -0
  258. package/src/modules/user-management/command/activateUser.test.ts +27 -27
  259. package/src/modules/user-management/command/activateUser.ts +40 -48
  260. package/src/modules/user-management/command/assignPermissionToRole.generated.ts +6 -0
  261. package/src/modules/user-management/command/assignPermissionToRole.test.ts +42 -43
  262. package/src/modules/user-management/command/assignPermissionToRole.ts +59 -62
  263. package/src/modules/user-management/command/assignRoleToUser.generated.ts +6 -0
  264. package/src/modules/user-management/command/assignRoleToUser.test.ts +70 -63
  265. package/src/modules/user-management/command/assignRoleToUser.ts +63 -66
  266. package/src/modules/user-management/command/createPermission.generated.ts +6 -0
  267. package/src/modules/user-management/command/createPermission.test.ts +45 -38
  268. package/src/modules/user-management/command/createPermission.ts +42 -46
  269. package/src/modules/user-management/command/createRole.generated.ts +6 -0
  270. package/src/modules/user-management/command/createRole.test.ts +30 -29
  271. package/src/modules/user-management/command/createRole.ts +33 -33
  272. package/src/modules/user-management/command/createUser.generated.ts +6 -0
  273. package/src/modules/user-management/command/createUser.test.ts +64 -42
  274. package/src/modules/user-management/command/createUser.ts +54 -56
  275. package/src/modules/user-management/command/deactivateUser.generated.ts +6 -0
  276. package/src/modules/user-management/command/deactivateUser.test.ts +27 -27
  277. package/src/modules/user-management/command/deactivateUser.ts +40 -48
  278. package/src/modules/user-management/command/logAuditEvent.generated.ts +6 -0
  279. package/src/modules/user-management/command/logAuditEvent.test.ts +50 -42
  280. package/src/modules/user-management/command/logAuditEvent.ts +25 -28
  281. package/src/modules/user-management/command/reactivateUser.generated.ts +6 -0
  282. package/src/modules/user-management/command/reactivateUser.test.ts +31 -27
  283. package/src/modules/user-management/command/reactivateUser.ts +40 -48
  284. package/src/modules/user-management/command/revokePermissionFromRole.generated.ts +6 -0
  285. package/src/modules/user-management/command/revokePermissionFromRole.test.ts +52 -51
  286. package/src/modules/user-management/command/revokePermissionFromRole.ts +60 -57
  287. package/src/modules/user-management/command/revokeRoleFromUser.generated.ts +6 -0
  288. package/src/modules/user-management/command/revokeRoleFromUser.test.ts +53 -48
  289. package/src/modules/user-management/command/revokeRoleFromUser.ts +58 -57
  290. package/src/modules/user-management/docs/commands/CreatePermission.md +2 -2
  291. package/src/modules/user-management/docs/commands/CreateRole.md +1 -1
  292. package/src/modules/user-management/docs/models/AuditEvent.md +2 -0
  293. package/src/modules/user-management/docs/models/Permission.md +2 -0
  294. package/src/modules/user-management/docs/models/Role.md +2 -0
  295. package/src/modules/user-management/docs/models/RolePermission.md +2 -0
  296. package/src/modules/user-management/docs/models/User.md +2 -0
  297. package/src/modules/user-management/docs/models/UserRole.md +2 -0
  298. package/src/modules/user-management/generated/enums.ts +11 -11
  299. package/src/modules/user-management/generated/kysely-tailordb.ts +27 -56
  300. package/src/modules/user-management/index.ts +2 -2
  301. package/src/modules/user-management/lib/errors.generated.ts +67 -0
  302. package/src/modules/user-management/{permissions.ts → lib/permissions.generated.ts} +8 -7
  303. package/src/modules/user-management/module.ts +22 -22
  304. package/src/modules/user-management/tailor.config.ts +3 -3
  305. package/src/schemas.ts +2 -1
  306. package/skills/1-module-docs/references/structure.md +0 -22
  307. package/skills/2-module-feature-breakdown/references/commands.md +0 -48
  308. package/skills/2-module-feature-breakdown/references/structure.md +0 -22
  309. package/skills/3-module-doc-review/references/commands.md +0 -54
  310. package/skills/3-module-doc-review/references/models.md +0 -29
  311. package/skills/4-module-tdd-implementation/SKILL.md +0 -74
  312. package/skills/4-module-tdd-implementation/references/commands.md +0 -45
  313. package/skills/4-module-tdd-implementation/references/errors.md +0 -7
  314. package/skills/4-module-tdd-implementation/references/models.md +0 -30
  315. package/skills/4-module-tdd-implementation/references/structure.md +0 -22
  316. package/skills/4-module-tdd-implementation/references/testing.md +0 -37
  317. package/skills/5-module-implementation-review/references/commands.md +0 -45
  318. package/skills/5-module-implementation-review/references/errors.md +0 -7
  319. package/skills/5-module-implementation-review/references/exports.md +0 -8
  320. package/skills/5-module-implementation-review/references/models.md +0 -30
  321. package/src/modules/primitives/command/convertAmount.ts +0 -126
  322. package/src/modules/primitives/command/convertQuantity.ts +0 -73
  323. package/src/modules/primitives/lib/errors.ts +0 -138
  324. package/src/modules/user-management/lib/errors.ts +0 -81
  325. /package/skills/{app-compose-1-requirement-analysis → erp-kit-app-1-requirements}/references/structure.md +0 -0
  326. /package/skills/{app-compose-2-requirements-breakdown → erp-kit-app-2-breakdown}/references/screen-detailview.md +0 -0
  327. /package/skills/{app-compose-2-requirements-breakdown → erp-kit-app-2-breakdown}/references/screen-form.md +0 -0
  328. /package/skills/{app-compose-2-requirements-breakdown → erp-kit-app-2-breakdown}/references/screen-listview.md +0 -0
  329. /package/skills/{app-compose-2-requirements-breakdown → erp-kit-app-2-breakdown}/references/structure.md +0 -0
  330. /package/skills/{app-compose-3-doc-review → erp-kit-app-3-doc-review}/references/structure.md +0 -0
  331. /package/skills/{app-compose-4-design-mock → erp-kit-app-4-design}/references/component.md +0 -0
  332. /package/skills/{app-compose-4-design-mock → erp-kit-app-4-design}/references/screen-detailview.md +0 -0
  333. /package/skills/{app-compose-4-design-mock → erp-kit-app-4-design}/references/screen-form.md +0 -0
  334. /package/skills/{app-compose-4-design-mock → erp-kit-app-4-design}/references/screen-listview.md +0 -0
  335. /package/skills/{app-compose-4-design-mock → erp-kit-app-4-design}/references/structure.md +0 -0
  336. /package/skills/{app-compose-5-design-mock-review → erp-kit-app-5-design-review}/references/component.md +0 -0
  337. /package/skills/{app-compose-5-design-mock-review → erp-kit-app-5-design-review}/references/screen-detailview.md +0 -0
  338. /package/skills/{app-compose-5-design-mock-review → erp-kit-app-5-design-review}/references/screen-form.md +0 -0
  339. /package/skills/{app-compose-5-design-mock-review → erp-kit-app-5-design-review}/references/screen-listview.md +0 -0
  340. /package/skills/{app-compose-6-implementation-spec → erp-kit-app-6-impl-spec}/references/auth.md +0 -0
  341. /package/skills/{app-compose-6-implementation-spec → erp-kit-app-6-impl-spec}/references/structure.md +0 -0
  342. /package/skills/{2-module-feature-breakdown → erp-kit-module-4-tdd}/references/models.md +0 -0
@@ -0,0 +1,35 @@
1
+ import path from "node:path";
2
+ import { defineCommand, arg } from "politty";
3
+ import { z } from "zod";
4
+ import { runGenerateCode } from "../../generator/generate-code";
5
+
6
+ const cwd = process.cwd();
7
+
8
+ const codeCommand = defineCommand({
9
+ name: "code",
10
+ description: "Generate errors, permissions, command shells, and query shells from docs",
11
+ args: z.object({
12
+ root: arg(z.string(), {
13
+ alias: "r",
14
+ description: "Path to modules directory",
15
+ }),
16
+ module: arg(z.string(), {
17
+ positional: true,
18
+ description: "Module name (e.g., primitives, item-management)",
19
+ }),
20
+ }),
21
+ run: (args) => {
22
+ const modulePath = path.resolve(cwd, args.root, args.module);
23
+ console.log(`Generating code for ${args.module}...`);
24
+ const exitCode = runGenerateCode(modulePath, args.module);
25
+ process.exit(exitCode);
26
+ },
27
+ });
28
+
29
+ export const generateCommand = defineCommand({
30
+ name: "generate",
31
+ description: "Generate code from model definitions and docs",
32
+ subCommands: {
33
+ code: codeCommand,
34
+ },
35
+ });
@@ -0,0 +1,87 @@
1
+ import { z } from "zod";
2
+ import { defineCommand, arg } from "politty";
3
+ import { runCheck } from "../check";
4
+ import { runSyncCheck, formatSyncCheckReport } from "../sync-check";
5
+ import { runScaffold, MODULE_TYPES, type ScaffoldType } from "../scaffold";
6
+ import { runModuleList } from "./list";
7
+ import { generateCommand } from "./generate";
8
+
9
+ const cwd = process.cwd();
10
+
11
+ const rootArgs = z.object({
12
+ root: arg(z.string(), {
13
+ alias: "r",
14
+ description: "Path to modules directory",
15
+ }),
16
+ });
17
+
18
+ const listCommand = defineCommand({
19
+ name: "list",
20
+ description: "List available modules",
21
+ run: () => {
22
+ const exitCode = runModuleList();
23
+ process.exit(exitCode);
24
+ },
25
+ });
26
+
27
+ const checkCommand = defineCommand({
28
+ name: "check",
29
+ description: "Validate module docs against schemas",
30
+ args: rootArgs,
31
+ run: async (args) => {
32
+ const exitCode = await runCheck({ modulesRoot: args.root }, cwd);
33
+ process.exit(exitCode);
34
+ },
35
+ });
36
+
37
+ const syncCheckCommand = defineCommand({
38
+ name: "sync-check",
39
+ description: "Validate source <-> doc correspondence",
40
+ args: rootArgs,
41
+ run: async (args) => {
42
+ const result = await runSyncCheck({ modulesRoot: args.root }, cwd);
43
+ console.log(formatSyncCheckReport(result));
44
+ process.exit(result.exitCode);
45
+ },
46
+ });
47
+
48
+ const scaffoldCommand = defineCommand({
49
+ name: "scaffold",
50
+ description: "Generate module doc from schema template",
51
+ args: rootArgs.extend({
52
+ type: arg(z.enum(MODULE_TYPES as unknown as [string, ...string[]]), {
53
+ positional: true,
54
+ description: `Scaffold type (${MODULE_TYPES.join(", ")})`,
55
+ }),
56
+ parent: arg(z.string(), {
57
+ positional: true,
58
+ description: "Module name",
59
+ }),
60
+ name: arg(z.string().optional(), {
61
+ positional: true,
62
+ description: "Item name (required for feature, command, model)",
63
+ }),
64
+ }),
65
+ run: async (args) => {
66
+ const exitCode = await runScaffold(
67
+ args.type as ScaffoldType,
68
+ args.parent,
69
+ args.name,
70
+ args.root,
71
+ cwd,
72
+ );
73
+ process.exit(exitCode);
74
+ },
75
+ });
76
+
77
+ export const moduleCommand = defineCommand({
78
+ name: "module",
79
+ description: "Module management",
80
+ subCommands: {
81
+ list: listCommand,
82
+ check: checkCommand,
83
+ "sync-check": syncCheckCommand,
84
+ scaffold: scaffoldCommand,
85
+ generate: generateCommand,
86
+ },
87
+ });
@@ -0,0 +1,57 @@
1
+ import { describe, it, expect } from "vitest";
2
+ import { listModules, formatModuleList } from "./list";
3
+
4
+ describe("listModules", () => {
5
+ it("returns the built-in modules with counts", () => {
6
+ const modules = listModules();
7
+ expect(modules.length).toBeGreaterThan(0);
8
+
9
+ const primitives = modules.find((m) => m.name === "primitives");
10
+ expect(primitives).toBeDefined();
11
+ expect(primitives!.commands).toBeGreaterThan(0);
12
+ expect(primitives!.models).toBeGreaterThan(0);
13
+ expect(primitives!.features).toBeGreaterThan(0);
14
+ });
15
+
16
+ it("returns zero counts for stub modules", () => {
17
+ const modules = listModules();
18
+ const inventory = modules.find((m) => m.name === "inventory");
19
+ expect(inventory).toBeDefined();
20
+ expect(inventory!.commands).toBe(0);
21
+ expect(inventory!.models).toBe(0);
22
+ expect(inventory!.features).toBe(0);
23
+ });
24
+
25
+ it("excludes shared and testing directories", () => {
26
+ const modules = listModules();
27
+ const names = modules.map((m) => m.name);
28
+ expect(names).not.toContain("shared");
29
+ expect(names).not.toContain("testing");
30
+ });
31
+
32
+ it("returns modules in alphabetical order", () => {
33
+ const modules = listModules();
34
+ const names = modules.map((m) => m.name);
35
+ const sorted = [...names].sort();
36
+ expect(names).toEqual(sorted);
37
+ });
38
+ });
39
+
40
+ describe("formatModuleList", () => {
41
+ it("formats modules with counts", () => {
42
+ const output = formatModuleList([
43
+ { name: "primitives", commands: 14, models: 4, features: 4 },
44
+ { name: "inventory", commands: 0, models: 0, features: 0 },
45
+ ]);
46
+ expect(output).toContain("primitives");
47
+ expect(output).toContain("14 commands");
48
+ expect(output).toContain("4 models");
49
+ expect(output).toContain("4 features");
50
+ expect(output).toContain("inventory");
51
+ expect(output).toContain("2 modules");
52
+ });
53
+
54
+ it("handles empty list", () => {
55
+ expect(formatModuleList([])).toBe("No modules found.");
56
+ });
57
+ });
@@ -0,0 +1,64 @@
1
+ import { readdirSync, existsSync } from "node:fs";
2
+ import { join } from "node:path";
3
+ import chalk from "chalk";
4
+ import { PACKAGE_ROOT } from "../../util";
5
+
6
+ const MODULES_DIR = join(PACKAGE_ROOT, "src", "modules");
7
+ const EXCLUDED_DIRS = new Set(["shared", "testing"]);
8
+
9
+ export interface ModuleInfo {
10
+ name: string;
11
+ commands: number;
12
+ models: number;
13
+ features: number;
14
+ }
15
+
16
+ function countFiles(dir: string, pattern: RegExp, exclusions: RegExp[]): number {
17
+ if (!existsSync(dir)) return 0;
18
+ return readdirSync(dir).filter((f) => pattern.test(f) && !exclusions.some((p) => p.test(f)))
19
+ .length;
20
+ }
21
+
22
+ export function listModules(): ModuleInfo[] {
23
+ if (!existsSync(MODULES_DIR)) return [];
24
+ return readdirSync(MODULES_DIR, { withFileTypes: true })
25
+ .filter((d) => d.isDirectory() && !EXCLUDED_DIRS.has(d.name))
26
+ .map((d) => {
27
+ const modDir = join(MODULES_DIR, d.name);
28
+ return {
29
+ name: d.name,
30
+ commands: countFiles(join(modDir, "command"), /\.ts$/, [/\.test\.ts$/]),
31
+ models: countFiles(join(modDir, "db"), /\.ts$/, [/\.test\.ts$/, /^index\.ts$/]),
32
+ features: countFiles(join(modDir, "docs", "features"), /\.md$/, []),
33
+ };
34
+ })
35
+ .sort((a, b) => a.name.localeCompare(b.name));
36
+ }
37
+
38
+ export function formatModuleList(modules: ModuleInfo[]): string {
39
+ if (modules.length === 0) return "No modules found.";
40
+
41
+ const lines: string[] = [];
42
+ lines.push(chalk.bold("Modules:\n"));
43
+
44
+ const nameWidth = Math.max(...modules.map((m) => m.name.length), 4);
45
+
46
+ for (const mod of modules) {
47
+ const counts = [
48
+ `${mod.commands} commands`,
49
+ `${mod.models} models`,
50
+ `${mod.features} features`,
51
+ ].join(", ");
52
+ lines.push(` ${mod.name.padEnd(nameWidth)} ${counts}`);
53
+ }
54
+
55
+ lines.push("");
56
+ lines.push(`${modules.length} modules`);
57
+ return lines.join("\n");
58
+ }
59
+
60
+ export function runModuleList(): number {
61
+ const modules = listModules();
62
+ console.log(formatModuleList(modules));
63
+ return 0;
64
+ }
@@ -0,0 +1,65 @@
1
+ export type TemplateEntry =
2
+ | { type: "dir"; path: string }
3
+ | { type: "file"; path: string; content: (moduleName: string) => string };
4
+
5
+ export function getModuleSrcTemplates(): TemplateEntry[] {
6
+ return [
7
+ { type: "dir", path: "db" },
8
+ { type: "dir", path: "command" },
9
+ { type: "dir", path: "executor" },
10
+ { type: "dir", path: "generated" },
11
+ { type: "dir", path: "query" },
12
+ { type: "file", path: "module.ts", content: () => MODULE_TEMPLATE },
13
+ { type: "file", path: "index.ts", content: () => INDEX_TEMPLATE },
14
+ { type: "file", path: "permissions.ts", content: (n) => permissionsTemplate(n) },
15
+ { type: "file", path: "tailor.config.ts", content: (n) => tailorConfigTemplate(n) },
16
+ { type: "file", path: "lib/errors.ts", content: () => ERRORS_TEMPLATE },
17
+ { type: "file", path: "lib/types.ts", content: () => TYPES_TEMPLATE },
18
+ { type: "file", path: "testing/fixtures.ts", content: () => FIXTURES_TEMPLATE },
19
+ ];
20
+ }
21
+
22
+ const MODULE_TEMPLATE = `export const defineModule = () => {
23
+ return {
24
+ db: {},
25
+ commands: {},
26
+ queries: {},
27
+ };
28
+ };
29
+ `;
30
+
31
+ const INDEX_TEMPLATE = `export { defineModule } from "./module";
32
+ export { permissions, own, all } from "./permissions";
33
+ `;
34
+
35
+ const ERRORS_TEMPLATE = `import { createDomainError } from "../../shared/internal";\n`;
36
+
37
+ const TYPES_TEMPLATE = `import type { InferSchema, Selectable, Insertable, Updateable } from "../../shared/internal";
38
+ import type { DB } from "../generated/kysely-tailordb";
39
+
40
+ export type Schema = InferSchema<DB>;
41
+ `;
42
+
43
+ const FIXTURES_TEMPLATE = `// Add test fixtures here\n`;
44
+
45
+ function permissionsTemplate(moduleName: string): string {
46
+ return `import { definePermissions } from "../shared/internal";
47
+
48
+ export const { permissions, own, all } = definePermissions("${moduleName}", [] as const);
49
+ `;
50
+ }
51
+
52
+ function tailorConfigTemplate(moduleName: string): string {
53
+ return `import { defineConfig, defineGenerators } from "@tailor-platform/sdk";
54
+
55
+ export default defineConfig({
56
+ name: "${moduleName}",
57
+ db: { "main-db": { files: [\`./db/*.ts\`] } },
58
+ });
59
+
60
+ export const generators = defineGenerators(
61
+ ["@tailor-platform/kysely-type", { distPath: \`./generated/kysely-tailordb.ts\` }],
62
+ ["@tailor-platform/enum-constants", { distPath: "./generated/enums.ts" }],
63
+ );
64
+ `;
65
+ }
@@ -1,5 +1,17 @@
1
- import { describe, it, expect } from "vitest";
2
- import { resolveScaffoldPath } from "./scaffold.js";
1
+ import fs from "node:fs";
2
+ import os from "node:os";
3
+ import path from "node:path";
4
+ import {
5
+ type Diagnostic,
6
+ DiagnosticCategory,
7
+ flattenDiagnosticMessageText,
8
+ ModuleKind,
9
+ ScriptTarget,
10
+ transpileModule,
11
+ } from "typescript";
12
+ import { describe, it, expect, afterEach } from "vitest";
13
+ import { resolveScaffoldPath, scaffoldModuleSrc } from "./scaffold";
14
+ import { getModuleSrcTemplates } from "./scaffold-templates";
3
15
 
4
16
  describe("resolveScaffoldPath", () => {
5
17
  // Module types
@@ -61,6 +73,11 @@ describe("resolveScaffoldPath", () => {
61
73
  expect(result).toBe("examples/my-app/docs/resolver/create-supplier.md");
62
74
  });
63
75
 
76
+ it("resolves query scaffold path", () => {
77
+ const result = resolveScaffoldPath("query", "inventory", "ConvertQuantity", "modules");
78
+ expect(result).toBe("modules/inventory/docs/queries/ConvertQuantity.md");
79
+ });
80
+
64
81
  // Validation
65
82
  it("throws when name is required but missing", () => {
66
83
  expect(() => resolveScaffoldPath("command", "inventory", undefined, "modules")).toThrow(
@@ -74,3 +91,81 @@ describe("resolveScaffoldPath", () => {
74
91
  );
75
92
  });
76
93
  });
94
+
95
+ describe("scaffoldModuleSrc", () => {
96
+ let tmpDir: string;
97
+
98
+ afterEach(() => {
99
+ if (tmpDir) {
100
+ fs.rmSync(tmpDir, { recursive: true, force: true });
101
+ }
102
+ });
103
+
104
+ it("creates expected directories and files", () => {
105
+ tmpDir = fs.mkdtempSync(path.join(os.tmpdir(), "scaffold-test-"));
106
+ const moduleDir = path.join(tmpDir, "test-module");
107
+ fs.mkdirSync(moduleDir, { recursive: true });
108
+
109
+ scaffoldModuleSrc(moduleDir, "test-module");
110
+
111
+ // Verify directories exist directly under module root (flat structure)
112
+ for (const dir of ["db", "command", "executor", "generated", "lib", "query", "testing"]) {
113
+ expect(fs.existsSync(path.join(moduleDir, dir))).toBe(true);
114
+ }
115
+
116
+ // Verify .gitkeep in empty directories
117
+ for (const dir of ["db", "command", "executor", "generated", "query"]) {
118
+ expect(fs.existsSync(path.join(moduleDir, dir, ".gitkeep"))).toBe(true);
119
+ }
120
+
121
+ // Verify starter files exist
122
+ const expectedFiles = [
123
+ "module.ts",
124
+ "index.ts",
125
+ "permissions.ts",
126
+ "tailor.config.ts",
127
+ "lib/errors.ts",
128
+ "lib/types.ts",
129
+ "testing/fixtures.ts",
130
+ ];
131
+ for (const file of expectedFiles) {
132
+ expect(fs.existsSync(path.join(moduleDir, file))).toBe(true);
133
+ }
134
+
135
+ // Verify module name is used in content
136
+ const permissions = fs.readFileSync(path.join(moduleDir, "permissions.ts"), "utf-8");
137
+ expect(permissions).toContain('definePermissions("test-module"');
138
+
139
+ const config = fs.readFileSync(path.join(moduleDir, "tailor.config.ts"), "utf-8");
140
+ expect(config).toContain('name: "test-module"');
141
+
142
+ const moduleFile = fs.readFileSync(path.join(moduleDir, "module.ts"), "utf-8");
143
+ expect(moduleFile).toContain("defineModule");
144
+ expect(moduleFile).toContain("commands");
145
+ expect(moduleFile).toContain("queries");
146
+ });
147
+
148
+ it("generates syntactically valid TypeScript for all file templates", () => {
149
+ const templates = getModuleSrcTemplates();
150
+ const fileTemplates = templates.filter((t) => t.type === "file");
151
+
152
+ for (const entry of fileTemplates) {
153
+ const source = entry.content("test-module");
154
+ const result = transpileModule(source, {
155
+ reportDiagnostics: true,
156
+ compilerOptions: { target: ScriptTarget.ESNext, module: ModuleKind.ESNext },
157
+ });
158
+ const errors = (result.diagnostics ?? []).filter(
159
+ (d) => d.category === DiagnosticCategory.Error,
160
+ );
161
+ expect(
162
+ errors,
163
+ `syntax errors in template "${entry.path}": ${formatDiagnostics(errors)}`,
164
+ ).toHaveLength(0);
165
+ }
166
+ });
167
+ });
168
+
169
+ function formatDiagnostics(diagnostics: Diagnostic[]): string {
170
+ return diagnostics.map((d) => flattenDiagnosticMessageText(d.messageText, "\n")).join("; ");
171
+ }
@@ -1,9 +1,10 @@
1
1
  import path from "node:path";
2
2
  import fs from "node:fs";
3
- import { runMdschema } from "../mdschema.js";
4
- import { ALL_SCHEMAS } from "../schemas.js";
3
+ import { runMdschema } from "../mdschema";
4
+ import { ALL_SCHEMAS } from "../schemas";
5
+ import { getModuleSrcTemplates } from "./scaffold-templates";
5
6
 
6
- export const MODULE_TYPES = ["module", "feature", "command", "model"] as const;
7
+ export const MODULE_TYPES = ["module", "feature", "command", "model", "query"] as const;
7
8
  export const APP_TYPES = [
8
9
  "requirements",
9
10
  "actors",
@@ -20,6 +21,7 @@ const MODULE_DIR_MAP: Record<string, string> = {
20
21
  feature: "docs/features",
21
22
  command: "docs/commands",
22
23
  model: "docs/models",
24
+ query: "docs/queries",
23
25
  };
24
26
 
25
27
  const APP_DIR_MAP: Record<string, string> = {
@@ -115,5 +117,24 @@ export async function runScaffold(
115
117
  if (stdout.trim()) console.log(stdout);
116
118
  if (stderr.trim()) console.error(stderr);
117
119
 
120
+ if (exitCode !== 0) return exitCode;
121
+
122
+ if (type === "module") {
123
+ scaffoldModuleSrc(path.dirname(absoluteOutput), parentName);
124
+ }
125
+
118
126
  return exitCode;
119
127
  }
128
+
129
+ export function scaffoldModuleSrc(moduleDir: string, moduleName: string): void {
130
+ for (const entry of getModuleSrcTemplates()) {
131
+ const fullPath = path.join(moduleDir, entry.path);
132
+ if (entry.type === "dir") {
133
+ fs.mkdirSync(fullPath, { recursive: true });
134
+ fs.writeFileSync(path.join(fullPath, ".gitkeep"), "");
135
+ } else {
136
+ fs.mkdirSync(path.dirname(fullPath), { recursive: true });
137
+ fs.writeFileSync(fullPath, entry.content(moduleName));
138
+ }
139
+ }
140
+ }
@@ -2,7 +2,7 @@ import path from "node:path";
2
2
  import os from "node:os";
3
3
  import fs from "node:fs";
4
4
  import { describe, it, expect, beforeEach, afterEach } from "vitest";
5
- import { runSyncCheck } from "./sync-check.js";
5
+ import { runSyncCheck, checkStaleness } from "./sync-check";
6
6
 
7
7
  describe("runSyncCheck", () => {
8
8
  let tmpDir: string;
@@ -103,6 +103,60 @@ describe("runSyncCheck", () => {
103
103
  expect(result.summary.totalSources).toBe(1);
104
104
  });
105
105
 
106
+ it("reports missing doc for query source without doc", async () => {
107
+ const srcDir = path.join(tmpDir, "modules", "foo", "query");
108
+ fs.mkdirSync(srcDir, { recursive: true });
109
+ fs.writeFileSync(path.join(srcDir, "convertAmount.ts"), "export {}");
110
+
111
+ const result = await runSyncCheck({ modulesRoot: "modules", appRoot: "examples" }, tmpDir);
112
+ expect(result.exitCode).toBe(1);
113
+ expect(result.errors).toContainEqual(
114
+ expect.objectContaining({
115
+ type: "missing-doc",
116
+ category: "query",
117
+ expectedBasename: "convertamount",
118
+ }),
119
+ );
120
+ });
121
+
122
+ it("returns 0 when query source and doc match", async () => {
123
+ const srcDir = path.join(tmpDir, "modules", "foo", "query");
124
+ const docDir = path.join(tmpDir, "modules", "foo", "docs", "queries");
125
+ fs.mkdirSync(srcDir, { recursive: true });
126
+ fs.mkdirSync(docDir, { recursive: true });
127
+ fs.writeFileSync(path.join(srcDir, "convertAmount.ts"), "export {}");
128
+ fs.writeFileSync(path.join(docDir, "convertAmount.md"), "# ConvertAmount");
129
+
130
+ const result = await runSyncCheck({ modulesRoot: "modules", appRoot: "examples" }, tmpDir);
131
+ expect(result.exitCode).toBe(0);
132
+ });
133
+
134
+ it("matches generated query files to docs by stripping .generated suffix", async () => {
135
+ const srcDir = path.join(tmpDir, "modules", "foo", "query");
136
+ const docDir = path.join(tmpDir, "modules", "foo", "docs", "queries");
137
+ fs.mkdirSync(srcDir, { recursive: true });
138
+ fs.mkdirSync(docDir, { recursive: true });
139
+ fs.writeFileSync(path.join(srcDir, "getCurrency.generated.ts"), "export {}");
140
+ fs.writeFileSync(path.join(docDir, "GetCurrency.md"), "# GetCurrency");
141
+
142
+ const result = await runSyncCheck({ modulesRoot: "modules", appRoot: "examples" }, tmpDir);
143
+ expect(result.exitCode).toBe(0);
144
+ expect(result.errors).toHaveLength(0);
145
+ });
146
+
147
+ it("excludes generated command files from source matching", async () => {
148
+ const srcDir = path.join(tmpDir, "modules", "foo", "command");
149
+ const docDir = path.join(tmpDir, "modules", "foo", "docs", "commands");
150
+ fs.mkdirSync(srcDir, { recursive: true });
151
+ fs.mkdirSync(docDir, { recursive: true });
152
+ fs.writeFileSync(path.join(srcDir, "createOrder.ts"), "export {}");
153
+ fs.writeFileSync(path.join(srcDir, "createOrder.generated.ts"), "export {}");
154
+ fs.writeFileSync(path.join(docDir, "createOrder.md"), "# CreateOrder");
155
+
156
+ const result = await runSyncCheck({ modulesRoot: "modules", appRoot: "examples" }, tmpDir);
157
+ expect(result.exitCode).toBe(0);
158
+ });
159
+
106
160
  it("checks only module patterns when appRoot is not set", async () => {
107
161
  const resolverSrcDir = path.join(
108
162
  tmpDir,
@@ -123,3 +177,36 @@ describe("runSyncCheck", () => {
123
177
  expect(result.errors).toHaveLength(0);
124
178
  });
125
179
  });
180
+
181
+ describe("checkStaleness", () => {
182
+ it("reports stale when doc mtime > generated mtime", () => {
183
+ const errors = checkStaleness(
184
+ [{ docPath: "docs/commands/CreateItem.md", docMtime: 2000 }],
185
+ [{ genPath: "lib/errors.generated.ts", genMtime: 1000 }],
186
+ );
187
+
188
+ expect(errors).toHaveLength(1);
189
+ expect(errors[0].type).toBe("stale-generation");
190
+ });
191
+
192
+ it("reports no staleness when generated is newer", () => {
193
+ const errors = checkStaleness(
194
+ [{ docPath: "docs/commands/CreateItem.md", docMtime: 1000 }],
195
+ [{ genPath: "lib/errors.generated.ts", genMtime: 2000 }],
196
+ );
197
+
198
+ expect(errors).toHaveLength(0);
199
+ });
200
+
201
+ it("returns empty when no generated files", () => {
202
+ const errors = checkStaleness([{ docPath: "docs/commands/CreateItem.md", docMtime: 1000 }], []);
203
+
204
+ expect(errors).toHaveLength(0);
205
+ });
206
+
207
+ it("returns empty when no doc files", () => {
208
+ const errors = checkStaleness([], [{ genPath: "lib/errors.generated.ts", genMtime: 1000 }]);
209
+
210
+ expect(errors).toHaveLength(0);
211
+ });
212
+ });
@@ -33,7 +33,7 @@ function moduleCategories(root: string): CategoryConfig[] {
33
33
  name: "command",
34
34
  sourcePattern: `${root}/*/command/*.ts`,
35
35
  docPattern: `${root}/*/docs/commands/*.md`,
36
- exclusions: [/\.test\.ts$/],
36
+ exclusions: [/\.test\.ts$/, /\.generated\.ts$/],
37
37
  },
38
38
  {
39
39
  name: "model",
@@ -41,6 +41,12 @@ function moduleCategories(root: string): CategoryConfig[] {
41
41
  docPattern: `${root}/*/docs/models/*.md`,
42
42
  exclusions: [/\.test\.ts$/, /^index\.ts$/],
43
43
  },
44
+ {
45
+ name: "query",
46
+ sourcePattern: `${root}/*/query/*.ts`,
47
+ docPattern: `${root}/*/docs/queries/*.md`,
48
+ exclusions: [/\.test\.ts$/],
49
+ },
44
50
  ];
45
51
  }
46
52
 
@@ -85,7 +91,10 @@ export async function runSyncCheck(
85
91
  for (const sourcePath of sources) {
86
92
  const fileName = path.basename(sourcePath);
87
93
  if (shouldExclude(fileName, category.exclusions)) continue;
88
- const basename = path.basename(sourcePath, path.extname(sourcePath));
94
+ let basename = path.basename(sourcePath, path.extname(sourcePath));
95
+ if (basename.endsWith(".generated")) {
96
+ basename = basename.slice(0, -".generated".length);
97
+ }
89
98
  sourceBasenames.set(basename.toLowerCase(), sourcePath);
90
99
  }
91
100
 
@@ -131,6 +140,36 @@ export async function runSyncCheck(
131
140
  };
132
141
  }
133
142
 
143
+ export interface StalenessError {
144
+ type: "stale-generation";
145
+ docPath: string;
146
+ genPath: string;
147
+ }
148
+
149
+ export function checkStaleness(
150
+ docs: { docPath: string; docMtime: number }[],
151
+ generated: { genPath: string; genMtime: number }[],
152
+ ): StalenessError[] {
153
+ const errors: StalenessError[] = [];
154
+
155
+ if (generated.length === 0 || docs.length === 0) return errors;
156
+
157
+ const latestDocMtime = Math.max(...docs.map((d) => d.docMtime));
158
+ const oldestGenMtime = Math.min(...generated.map((g) => g.genMtime));
159
+
160
+ if (latestDocMtime > oldestGenMtime) {
161
+ const newestDoc = docs.find((d) => d.docMtime === latestDocMtime)!;
162
+ const oldestGen = generated.find((g) => g.genMtime === oldestGenMtime)!;
163
+ errors.push({
164
+ type: "stale-generation",
165
+ docPath: newestDoc.docPath,
166
+ genPath: oldestGen.genPath,
167
+ });
168
+ }
169
+
170
+ return errors;
171
+ }
172
+
134
173
  export function formatSyncCheckReport(result: SyncCheckResult): string {
135
174
  const lines: string[] = [];
136
175
  lines.push(chalk.bold("docs-sync-check: Checking source-documentation correspondence...\n"));