@dedesfr/prompter 0.6.14 → 0.7.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 (379) hide show
  1. package/CHANGELOG.md +15 -0
  2. package/dist/cli/index.js +144 -12
  3. package/dist/cli/index.js.map +1 -1
  4. package/dist/commands/archive.d.ts +11 -0
  5. package/dist/commands/archive.d.ts.map +1 -0
  6. package/dist/commands/archive.js +280 -0
  7. package/dist/commands/archive.js.map +1 -0
  8. package/dist/commands/change.d.ts +35 -0
  9. package/dist/commands/change.d.ts.map +1 -0
  10. package/dist/commands/change.js +277 -0
  11. package/dist/commands/change.js.map +1 -0
  12. package/dist/commands/config.d.ts +8 -0
  13. package/dist/commands/config.d.ts.map +1 -0
  14. package/dist/commands/config.js +198 -0
  15. package/dist/commands/config.js.map +1 -0
  16. package/dist/commands/guide.d.ts.map +1 -1
  17. package/dist/commands/guide.js +4 -0
  18. package/dist/commands/guide.js.map +1 -1
  19. package/dist/commands/list.d.ts +2 -2
  20. package/dist/commands/list.d.ts.map +1 -1
  21. package/dist/commands/list.js +153 -47
  22. package/dist/commands/list.js.map +1 -1
  23. package/dist/commands/show.d.ts +14 -0
  24. package/dist/commands/show.d.ts.map +1 -0
  25. package/dist/commands/show.js +132 -0
  26. package/dist/commands/show.js.map +1 -0
  27. package/dist/commands/spec.d.ts +15 -0
  28. package/dist/commands/spec.d.ts.map +1 -0
  29. package/dist/commands/spec.js +225 -0
  30. package/dist/commands/spec.js.map +1 -0
  31. package/dist/commands/validate.d.ts +24 -0
  32. package/dist/commands/validate.d.ts.map +1 -0
  33. package/dist/commands/validate.js +294 -0
  34. package/dist/commands/validate.js.map +1 -0
  35. package/dist/core/artifact-graph/graph.d.ts +56 -0
  36. package/dist/core/artifact-graph/graph.d.ts.map +1 -0
  37. package/dist/core/artifact-graph/graph.js +141 -0
  38. package/dist/core/artifact-graph/graph.js.map +1 -0
  39. package/dist/core/artifact-graph/index.d.ts +7 -0
  40. package/dist/core/artifact-graph/index.d.ts.map +1 -0
  41. package/dist/core/artifact-graph/index.js +13 -0
  42. package/dist/core/artifact-graph/index.js.map +1 -0
  43. package/dist/core/artifact-graph/instruction-loader.d.ts +130 -0
  44. package/dist/core/artifact-graph/instruction-loader.d.ts.map +1 -0
  45. package/dist/core/artifact-graph/instruction-loader.js +173 -0
  46. package/dist/core/artifact-graph/instruction-loader.js.map +1 -0
  47. package/dist/core/artifact-graph/resolver.d.ts +61 -0
  48. package/dist/core/artifact-graph/resolver.d.ts.map +1 -0
  49. package/dist/core/artifact-graph/resolver.js +187 -0
  50. package/dist/core/artifact-graph/resolver.js.map +1 -0
  51. package/dist/core/artifact-graph/schema.d.ts +13 -0
  52. package/dist/core/artifact-graph/schema.d.ts.map +1 -0
  53. package/dist/core/artifact-graph/schema.js +108 -0
  54. package/dist/core/artifact-graph/schema.js.map +1 -0
  55. package/dist/core/artifact-graph/state.d.ts +12 -0
  56. package/dist/core/artifact-graph/state.d.ts.map +1 -0
  57. package/dist/core/artifact-graph/state.js +54 -0
  58. package/dist/core/artifact-graph/state.js.map +1 -0
  59. package/dist/core/artifact-graph/types.d.ts +45 -0
  60. package/dist/core/artifact-graph/types.d.ts.map +1 -0
  61. package/dist/core/artifact-graph/types.js +43 -0
  62. package/dist/core/artifact-graph/types.js.map +1 -0
  63. package/dist/core/completions/command-registry.d.ts +7 -0
  64. package/dist/core/completions/command-registry.d.ts.map +1 -0
  65. package/dist/core/completions/command-registry.js +380 -0
  66. package/dist/core/completions/command-registry.js.map +1 -0
  67. package/dist/core/completions/completion-provider.d.ts +60 -0
  68. package/dist/core/completions/completion-provider.d.ts.map +1 -0
  69. package/dist/core/completions/completion-provider.js +102 -0
  70. package/dist/core/completions/completion-provider.js.map +1 -0
  71. package/dist/core/completions/generators/bash-generator.d.ts +32 -0
  72. package/dist/core/completions/generators/bash-generator.d.ts.map +1 -0
  73. package/dist/core/completions/generators/bash-generator.js +174 -0
  74. package/dist/core/completions/generators/bash-generator.js.map +1 -0
  75. package/dist/core/completions/generators/fish-generator.d.ts +32 -0
  76. package/dist/core/completions/generators/fish-generator.d.ts.map +1 -0
  77. package/dist/core/completions/generators/fish-generator.js +157 -0
  78. package/dist/core/completions/generators/fish-generator.js.map +1 -0
  79. package/dist/core/completions/generators/powershell-generator.d.ts +33 -0
  80. package/dist/core/completions/generators/powershell-generator.d.ts.map +1 -0
  81. package/dist/core/completions/generators/powershell-generator.js +207 -0
  82. package/dist/core/completions/generators/powershell-generator.js.map +1 -0
  83. package/dist/core/completions/generators/zsh-generator.d.ts +44 -0
  84. package/dist/core/completions/generators/zsh-generator.d.ts.map +1 -0
  85. package/dist/core/completions/generators/zsh-generator.js +250 -0
  86. package/dist/core/completions/generators/zsh-generator.js.map +1 -0
  87. package/dist/core/completions/templates/bash-templates.d.ts +6 -0
  88. package/dist/core/completions/templates/bash-templates.d.ts.map +1 -0
  89. package/dist/core/completions/templates/bash-templates.js +24 -0
  90. package/dist/core/completions/templates/bash-templates.js.map +1 -0
  91. package/dist/core/completions/templates/fish-templates.d.ts +7 -0
  92. package/dist/core/completions/templates/fish-templates.d.ts.map +1 -0
  93. package/dist/core/completions/templates/fish-templates.js +39 -0
  94. package/dist/core/completions/templates/fish-templates.js.map +1 -0
  95. package/dist/core/completions/templates/powershell-templates.d.ts +6 -0
  96. package/dist/core/completions/templates/powershell-templates.d.ts.map +1 -0
  97. package/dist/core/completions/templates/powershell-templates.js +25 -0
  98. package/dist/core/completions/templates/powershell-templates.js.map +1 -0
  99. package/dist/core/completions/templates/zsh-templates.d.ts +6 -0
  100. package/dist/core/completions/templates/zsh-templates.d.ts.map +1 -0
  101. package/dist/core/completions/templates/zsh-templates.js +36 -0
  102. package/dist/core/completions/templates/zsh-templates.js.map +1 -0
  103. package/dist/core/completions/types.d.ts +78 -0
  104. package/dist/core/completions/types.d.ts.map +1 -0
  105. package/dist/core/completions/types.js +2 -0
  106. package/dist/core/completions/types.js.map +1 -0
  107. package/dist/core/config-schema.d.ts +76 -0
  108. package/dist/core/config-schema.d.ts.map +1 -0
  109. package/dist/core/config-schema.js +200 -0
  110. package/dist/core/config-schema.js.map +1 -0
  111. package/dist/core/config.d.ts.map +1 -1
  112. package/dist/core/config.js +18 -0
  113. package/dist/core/config.js.map +1 -1
  114. package/dist/core/configurators/slash/antigravity.d.ts.map +1 -1
  115. package/dist/core/configurators/slash/antigravity.js +6 -0
  116. package/dist/core/configurators/slash/antigravity.js.map +1 -1
  117. package/dist/core/configurators/slash/base.js +1 -1
  118. package/dist/core/configurators/slash/base.js.map +1 -1
  119. package/dist/core/configurators/slash/claude.d.ts.map +1 -1
  120. package/dist/core/configurators/slash/claude.js +6 -0
  121. package/dist/core/configurators/slash/claude.js.map +1 -1
  122. package/dist/core/configurators/slash/codex.d.ts.map +1 -1
  123. package/dist/core/configurators/slash/codex.js +6 -0
  124. package/dist/core/configurators/slash/codex.js.map +1 -1
  125. package/dist/core/configurators/slash/github-copilot.d.ts.map +1 -1
  126. package/dist/core/configurators/slash/github-copilot.js +6 -0
  127. package/dist/core/configurators/slash/github-copilot.js.map +1 -1
  128. package/dist/core/configurators/slash/kilocode.d.ts.map +1 -1
  129. package/dist/core/configurators/slash/kilocode.js +6 -0
  130. package/dist/core/configurators/slash/kilocode.js.map +1 -1
  131. package/dist/core/configurators/slash/opencode.d.ts.map +1 -1
  132. package/dist/core/configurators/slash/opencode.js +6 -0
  133. package/dist/core/configurators/slash/opencode.js.map +1 -1
  134. package/dist/core/converters/json-converter.d.ts +6 -0
  135. package/dist/core/converters/json-converter.d.ts.map +1 -0
  136. package/dist/core/converters/json-converter.js +51 -0
  137. package/dist/core/converters/json-converter.js.map +1 -0
  138. package/dist/core/global-config.d.ts +39 -0
  139. package/dist/core/global-config.d.ts.map +1 -0
  140. package/dist/core/global-config.js +115 -0
  141. package/dist/core/global-config.js.map +1 -0
  142. package/dist/core/parsers/change-parser.d.ts +13 -0
  143. package/dist/core/parsers/change-parser.d.ts.map +1 -0
  144. package/dist/core/parsers/change-parser.js +193 -0
  145. package/dist/core/parsers/change-parser.js.map +1 -0
  146. package/dist/core/parsers/markdown-parser.d.ts +22 -0
  147. package/dist/core/parsers/markdown-parser.d.ts.map +1 -0
  148. package/dist/core/parsers/markdown-parser.js +187 -0
  149. package/dist/core/parsers/markdown-parser.js.map +1 -0
  150. package/dist/core/parsers/requirement-blocks.d.ts +37 -0
  151. package/dist/core/parsers/requirement-blocks.d.ts.map +1 -0
  152. package/dist/core/parsers/requirement-blocks.js +201 -0
  153. package/dist/core/parsers/requirement-blocks.js.map +1 -0
  154. package/dist/core/prompt-templates.d.ts +3 -0
  155. package/dist/core/prompt-templates.d.ts.map +1 -1
  156. package/dist/core/prompt-templates.js +66 -0
  157. package/dist/core/prompt-templates.js.map +1 -1
  158. package/dist/core/schemas/base.schema.d.ts +13 -0
  159. package/dist/core/schemas/base.schema.d.ts.map +1 -0
  160. package/dist/core/schemas/base.schema.js +13 -0
  161. package/dist/core/schemas/base.schema.js.map +1 -0
  162. package/dist/core/schemas/change.schema.d.ts +73 -0
  163. package/dist/core/schemas/change.schema.d.ts.map +1 -0
  164. package/dist/core/schemas/change.schema.js +31 -0
  165. package/dist/core/schemas/change.schema.js.map +1 -0
  166. package/dist/core/schemas/index.d.ts +4 -0
  167. package/dist/core/schemas/index.d.ts.map +1 -0
  168. package/dist/core/schemas/index.js +4 -0
  169. package/dist/core/schemas/index.js.map +1 -0
  170. package/dist/core/schemas/spec.schema.d.ts +18 -0
  171. package/dist/core/schemas/spec.schema.d.ts.map +1 -0
  172. package/dist/core/schemas/spec.schema.js +15 -0
  173. package/dist/core/schemas/spec.schema.js.map +1 -0
  174. package/dist/core/specs-apply.d.ts +73 -0
  175. package/dist/core/specs-apply.d.ts.map +1 -0
  176. package/dist/core/specs-apply.js +384 -0
  177. package/dist/core/specs-apply.js.map +1 -0
  178. package/dist/core/styles/palette.d.ts +7 -0
  179. package/dist/core/styles/palette.d.ts.map +1 -0
  180. package/dist/core/styles/palette.js +8 -0
  181. package/dist/core/styles/palette.js.map +1 -0
  182. package/dist/core/templates/slash-command-templates.d.ts +1 -1
  183. package/dist/core/templates/slash-command-templates.d.ts.map +1 -1
  184. package/dist/core/templates/slash-command-templates.js +4 -1
  185. package/dist/core/templates/slash-command-templates.js.map +1 -1
  186. package/dist/core/validation/constants.d.ts +34 -0
  187. package/dist/core/validation/constants.d.ts.map +1 -0
  188. package/dist/core/validation/constants.js +40 -0
  189. package/dist/core/validation/constants.js.map +1 -0
  190. package/dist/core/validation/types.d.ts +18 -0
  191. package/dist/core/validation/types.d.ts.map +1 -0
  192. package/dist/core/validation/types.js +2 -0
  193. package/dist/core/validation/types.js.map +1 -0
  194. package/dist/core/validation/validator.d.ts +33 -0
  195. package/dist/core/validation/validator.d.ts.map +1 -0
  196. package/dist/core/validation/validator.js +409 -0
  197. package/dist/core/validation/validator.js.map +1 -0
  198. package/dist/core/view.d.ts +8 -0
  199. package/dist/core/view.d.ts.map +1 -0
  200. package/dist/core/view.js +168 -0
  201. package/dist/core/view.js.map +1 -0
  202. package/dist/utils/change-metadata.d.ts +47 -0
  203. package/dist/utils/change-metadata.d.ts.map +1 -0
  204. package/dist/utils/change-metadata.js +130 -0
  205. package/dist/utils/change-metadata.js.map +1 -0
  206. package/dist/utils/change-utils.d.ts +51 -0
  207. package/dist/utils/change-utils.d.ts.map +1 -0
  208. package/dist/utils/change-utils.js +100 -0
  209. package/dist/utils/change-utils.js.map +1 -0
  210. package/dist/utils/file-system.d.ts +25 -0
  211. package/dist/utils/file-system.d.ts.map +1 -0
  212. package/dist/utils/file-system.js +218 -0
  213. package/dist/utils/file-system.js.map +1 -0
  214. package/dist/utils/index.d.ts +4 -0
  215. package/dist/utils/index.d.ts.map +1 -0
  216. package/dist/utils/index.js +5 -0
  217. package/dist/utils/index.js.map +1 -0
  218. package/dist/utils/interactive.d.ts +18 -0
  219. package/dist/utils/interactive.d.ts.map +1 -0
  220. package/dist/utils/interactive.js +21 -0
  221. package/dist/utils/interactive.js.map +1 -0
  222. package/dist/utils/item-discovery.d.ts +4 -0
  223. package/dist/utils/item-discovery.d.ts.map +1 -0
  224. package/dist/utils/item-discovery.js +72 -0
  225. package/dist/utils/item-discovery.js.map +1 -0
  226. package/dist/utils/match.d.ts +3 -0
  227. package/dist/utils/match.d.ts.map +1 -0
  228. package/dist/utils/match.js +22 -0
  229. package/dist/utils/match.js.map +1 -0
  230. package/dist/utils/shell-detection.d.ts +20 -0
  231. package/dist/utils/shell-detection.d.ts.map +1 -0
  232. package/dist/utils/shell-detection.js +41 -0
  233. package/dist/utils/shell-detection.js.map +1 -0
  234. package/dist/utils/task-progress.d.ts +8 -0
  235. package/dist/utils/task-progress.d.ts.map +1 -0
  236. package/dist/utils/task-progress.js +36 -0
  237. package/dist/utils/task-progress.js.map +1 -0
  238. package/docs/tasks.md +1 -1
  239. package/package.json +6 -2
  240. package/prompt/apply.md +17 -0
  241. package/prompt/archive.md +21 -0
  242. package/prompt/proposal.md +22 -0
  243. package/src/cli/index.ts +151 -16
  244. package/src/commands/archive.ts +302 -0
  245. package/src/commands/change.ts +292 -0
  246. package/src/commands/config.ts +233 -0
  247. package/src/commands/guide.ts +5 -0
  248. package/src/commands/list.ts +176 -66
  249. package/src/commands/show.ts +138 -0
  250. package/src/commands/spec.ts +251 -0
  251. package/src/commands/validate.ts +326 -0
  252. package/src/core/artifact-graph/graph.ts +167 -0
  253. package/src/core/artifact-graph/index.ts +44 -0
  254. package/src/core/artifact-graph/instruction-loader.ts +302 -0
  255. package/src/core/artifact-graph/resolver.ts +226 -0
  256. package/src/core/artifact-graph/schema.ts +124 -0
  257. package/src/core/artifact-graph/state.ts +64 -0
  258. package/src/core/artifact-graph/types.ts +65 -0
  259. package/src/core/completions/command-registry.ts +382 -0
  260. package/src/core/completions/completion-provider.ts +128 -0
  261. package/src/core/completions/generators/bash-generator.ts +191 -0
  262. package/src/core/completions/generators/fish-generator.ts +188 -0
  263. package/src/core/completions/generators/powershell-generator.ts +223 -0
  264. package/src/core/completions/generators/zsh-generator.ts +281 -0
  265. package/src/core/completions/templates/bash-templates.ts +24 -0
  266. package/src/core/completions/templates/fish-templates.ts +40 -0
  267. package/src/core/completions/templates/powershell-templates.ts +25 -0
  268. package/src/core/completions/templates/zsh-templates.ts +36 -0
  269. package/src/core/completions/types.ts +90 -0
  270. package/src/core/config-schema.ts +230 -0
  271. package/src/core/config.ts +18 -0
  272. package/src/core/configurators/slash/antigravity.ts +6 -0
  273. package/src/core/configurators/slash/base.ts +1 -1
  274. package/src/core/configurators/slash/claude.ts +6 -0
  275. package/src/core/configurators/slash/codex.ts +6 -0
  276. package/src/core/configurators/slash/github-copilot.ts +6 -0
  277. package/src/core/configurators/slash/kilocode.ts +6 -0
  278. package/src/core/configurators/slash/opencode.ts +6 -0
  279. package/src/core/converters/json-converter.ts +62 -0
  280. package/src/core/global-config.ts +136 -0
  281. package/src/core/parsers/change-parser.ts +234 -0
  282. package/src/core/parsers/markdown-parser.ts +237 -0
  283. package/src/core/parsers/requirement-blocks.ts +234 -0
  284. package/src/core/prompt-templates.ts +69 -0
  285. package/src/core/schemas/base.schema.ts +20 -0
  286. package/src/core/schemas/change.schema.ts +42 -0
  287. package/src/core/schemas/index.ts +20 -0
  288. package/src/core/schemas/spec.schema.ts +17 -0
  289. package/src/core/specs-apply.ts +483 -0
  290. package/src/core/styles/palette.ts +8 -0
  291. package/src/core/templates/slash-command-templates.ts +7 -1
  292. package/src/core/validation/constants.ts +48 -0
  293. package/src/core/validation/types.ts +19 -0
  294. package/src/core/validation/validator.ts +449 -0
  295. package/src/core/view.ts +219 -0
  296. package/src/utils/change-metadata.ts +171 -0
  297. package/src/utils/change-utils.ts +131 -0
  298. package/src/utils/file-system.ts +252 -0
  299. package/src/utils/index.ts +12 -0
  300. package/src/utils/interactive.ts +29 -0
  301. package/src/utils/item-discovery.ts +66 -0
  302. package/src/utils/match.ts +26 -0
  303. package/src/utils/shell-detection.ts +62 -0
  304. package/src/utils/task-progress.ts +43 -0
  305. package/dist/commands/ai-humanizer.d.ts +0 -11
  306. package/dist/commands/ai-humanizer.d.ts.map +0 -1
  307. package/dist/commands/ai-humanizer.js +0 -97
  308. package/dist/commands/ai-humanizer.js.map +0 -1
  309. package/dist/commands/api-contract-generator.d.ts +0 -11
  310. package/dist/commands/api-contract-generator.d.ts.map +0 -1
  311. package/dist/commands/api-contract-generator.js +0 -97
  312. package/dist/commands/api-contract-generator.js.map +0 -1
  313. package/dist/commands/design-system.d.ts +0 -11
  314. package/dist/commands/design-system.d.ts.map +0 -1
  315. package/dist/commands/design-system.js +0 -97
  316. package/dist/commands/design-system.js.map +0 -1
  317. package/dist/commands/document-explainer.d.ts +0 -11
  318. package/dist/commands/document-explainer.d.ts.map +0 -1
  319. package/dist/commands/document-explainer.js +0 -97
  320. package/dist/commands/document-explainer.js.map +0 -1
  321. package/dist/commands/epic-generator.d.ts +0 -11
  322. package/dist/commands/epic-generator.d.ts.map +0 -1
  323. package/dist/commands/epic-generator.js +0 -97
  324. package/dist/commands/epic-generator.js.map +0 -1
  325. package/dist/commands/erd-generator.d.ts +0 -11
  326. package/dist/commands/erd-generator.d.ts.map +0 -1
  327. package/dist/commands/erd-generator.js +0 -97
  328. package/dist/commands/erd-generator.js.map +0 -1
  329. package/dist/commands/fsd-generator.d.ts +0 -11
  330. package/dist/commands/fsd-generator.d.ts.map +0 -1
  331. package/dist/commands/fsd-generator.js +0 -97
  332. package/dist/commands/fsd-generator.js.map +0 -1
  333. package/dist/commands/prd-agent-generator.d.ts +0 -11
  334. package/dist/commands/prd-agent-generator.d.ts.map +0 -1
  335. package/dist/commands/prd-agent-generator.js +0 -95
  336. package/dist/commands/prd-agent-generator.js.map +0 -1
  337. package/dist/commands/prd-generator.d.ts +0 -11
  338. package/dist/commands/prd-generator.d.ts.map +0 -1
  339. package/dist/commands/prd-generator.js +0 -97
  340. package/dist/commands/prd-generator.js.map +0 -1
  341. package/dist/commands/product-brief.d.ts +0 -11
  342. package/dist/commands/product-brief.d.ts.map +0 -1
  343. package/dist/commands/product-brief.js +0 -97
  344. package/dist/commands/product-brief.js.map +0 -1
  345. package/dist/commands/skill-creator.d.ts +0 -11
  346. package/dist/commands/skill-creator.d.ts.map +0 -1
  347. package/dist/commands/skill-creator.js +0 -101
  348. package/dist/commands/skill-creator.js.map +0 -1
  349. package/dist/commands/story-generator.d.ts +0 -11
  350. package/dist/commands/story-generator.d.ts.map +0 -1
  351. package/dist/commands/story-generator.js +0 -97
  352. package/dist/commands/story-generator.js.map +0 -1
  353. package/dist/commands/tdd-generator.d.ts +0 -11
  354. package/dist/commands/tdd-generator.d.ts.map +0 -1
  355. package/dist/commands/tdd-generator.js +0 -97
  356. package/dist/commands/tdd-generator.js.map +0 -1
  357. package/dist/commands/tdd-lite-generator.d.ts +0 -11
  358. package/dist/commands/tdd-lite-generator.d.ts.map +0 -1
  359. package/dist/commands/tdd-lite-generator.js +0 -97
  360. package/dist/commands/tdd-lite-generator.js.map +0 -1
  361. package/dist/commands/wireframe-generator.d.ts +0 -11
  362. package/dist/commands/wireframe-generator.d.ts.map +0 -1
  363. package/dist/commands/wireframe-generator.js +0 -97
  364. package/dist/commands/wireframe-generator.js.map +0 -1
  365. package/src/commands/ai-humanizer.ts +0 -118
  366. package/src/commands/api-contract-generator.ts +0 -118
  367. package/src/commands/design-system.ts +0 -118
  368. package/src/commands/document-explainer.ts +0 -118
  369. package/src/commands/epic-generator.ts +0 -118
  370. package/src/commands/erd-generator.ts +0 -118
  371. package/src/commands/fsd-generator.ts +0 -118
  372. package/src/commands/prd-agent-generator.ts +0 -115
  373. package/src/commands/prd-generator.ts +0 -118
  374. package/src/commands/product-brief.ts +0 -118
  375. package/src/commands/skill-creator.ts +0 -123
  376. package/src/commands/story-generator.ts +0 -118
  377. package/src/commands/tdd-generator.ts +0 -118
  378. package/src/commands/tdd-lite-generator.ts +0 -118
  379. package/src/commands/wireframe-generator.ts +0 -118
@@ -0,0 +1,226 @@
1
+ import * as fs from 'node:fs';
2
+ import * as path from 'node:path';
3
+ import { fileURLToPath } from 'node:url';
4
+ import { getGlobalDataDir } from '../global-config.js';
5
+ import { parseSchema, SchemaValidationError } from './schema.js';
6
+ import type { SchemaYaml } from './types.js';
7
+
8
+ /**
9
+ * Error thrown when loading a schema fails.
10
+ */
11
+ export class SchemaLoadError extends Error {
12
+ constructor(
13
+ message: string,
14
+ public readonly schemaPath: string,
15
+ public readonly cause?: Error
16
+ ) {
17
+ super(message);
18
+ this.name = 'SchemaLoadError';
19
+ }
20
+ }
21
+
22
+ /**
23
+ * Gets the package's built-in schemas directory path.
24
+ * Uses import.meta.url to resolve relative to the current module.
25
+ */
26
+ export function getPackageSchemasDir(): string {
27
+ const currentFile = fileURLToPath(import.meta.url);
28
+ // Navigate from dist/core/artifact-graph/ to package root's schemas/
29
+ return path.join(path.dirname(currentFile), '..', '..', '..', 'schemas');
30
+ }
31
+
32
+ /**
33
+ * Gets the user's schema override directory path.
34
+ */
35
+ export function getUserSchemasDir(): string {
36
+ return path.join(getGlobalDataDir(), 'schemas');
37
+ }
38
+
39
+ /**
40
+ * Resolves a schema name to its directory path.
41
+ *
42
+ * Resolution order:
43
+ * 1. User override: ${XDG_DATA_HOME}/prompter/schemas/<name>/schema.yaml
44
+ * 2. Package built-in: <package>/schemas/<name>/schema.yaml
45
+ *
46
+ * @param name - Schema name (e.g., "spec-driven")
47
+ * @returns The path to the schema directory, or null if not found
48
+ */
49
+ export function getSchemaDir(name: string): string | null {
50
+ // 1. Check user override directory
51
+ const userDir = path.join(getUserSchemasDir(), name);
52
+ const userSchemaPath = path.join(userDir, 'schema.yaml');
53
+ if (fs.existsSync(userSchemaPath)) {
54
+ return userDir;
55
+ }
56
+
57
+ // 2. Check package built-in directory
58
+ const packageDir = path.join(getPackageSchemasDir(), name);
59
+ const packageSchemaPath = path.join(packageDir, 'schema.yaml');
60
+ if (fs.existsSync(packageSchemaPath)) {
61
+ return packageDir;
62
+ }
63
+
64
+ return null;
65
+ }
66
+
67
+ /**
68
+ * Resolves a schema name to a SchemaYaml object.
69
+ *
70
+ * Resolution order:
71
+ * 1. User override: ${XDG_DATA_HOME}/prompter/schemas/<name>/schema.yaml
72
+ * 2. Package built-in: <package>/schemas/<name>/schema.yaml
73
+ *
74
+ * @param name - Schema name (e.g., "spec-driven")
75
+ * @returns The resolved schema object
76
+ * @throws Error if schema is not found in any location
77
+ */
78
+ export function resolveSchema(name: string): SchemaYaml {
79
+ // Normalize name (remove .yaml extension if provided)
80
+ const normalizedName = name.replace(/\.ya?ml$/, '');
81
+
82
+ const schemaDir = getSchemaDir(normalizedName);
83
+ if (!schemaDir) {
84
+ const availableSchemas = listSchemas();
85
+ throw new Error(
86
+ `Schema '${normalizedName}' not found. Available schemas: ${availableSchemas.join(', ')}`
87
+ );
88
+ }
89
+
90
+ const schemaPath = path.join(schemaDir, 'schema.yaml');
91
+
92
+ // Load and parse the schema
93
+ let content: string;
94
+ try {
95
+ content = fs.readFileSync(schemaPath, 'utf-8');
96
+ } catch (err) {
97
+ const ioError = err instanceof Error ? err : new Error(String(err));
98
+ throw new SchemaLoadError(
99
+ `Failed to read schema at '${schemaPath}': ${ioError.message}`,
100
+ schemaPath,
101
+ ioError
102
+ );
103
+ }
104
+
105
+ try {
106
+ return parseSchema(content);
107
+ } catch (err) {
108
+ if (err instanceof SchemaValidationError) {
109
+ throw new SchemaLoadError(
110
+ `Invalid schema at '${schemaPath}': ${err.message}`,
111
+ schemaPath,
112
+ err
113
+ );
114
+ }
115
+ const parseError = err instanceof Error ? err : new Error(String(err));
116
+ throw new SchemaLoadError(
117
+ `Failed to parse schema at '${schemaPath}': ${parseError.message}`,
118
+ schemaPath,
119
+ parseError
120
+ );
121
+ }
122
+ }
123
+
124
+ /**
125
+ * Lists all available schema names.
126
+ * Combines user override and package built-in schemas.
127
+ */
128
+ export function listSchemas(): string[] {
129
+ const schemas = new Set<string>();
130
+
131
+ // Add package built-in schemas
132
+ const packageDir = getPackageSchemasDir();
133
+ if (fs.existsSync(packageDir)) {
134
+ for (const entry of fs.readdirSync(packageDir, { withFileTypes: true })) {
135
+ if (entry.isDirectory()) {
136
+ const schemaPath = path.join(packageDir, entry.name, 'schema.yaml');
137
+ if (fs.existsSync(schemaPath)) {
138
+ schemas.add(entry.name);
139
+ }
140
+ }
141
+ }
142
+ }
143
+
144
+ // Add user override schemas (may override package schemas)
145
+ const userDir = getUserSchemasDir();
146
+ if (fs.existsSync(userDir)) {
147
+ for (const entry of fs.readdirSync(userDir, { withFileTypes: true })) {
148
+ if (entry.isDirectory()) {
149
+ const schemaPath = path.join(userDir, entry.name, 'schema.yaml');
150
+ if (fs.existsSync(schemaPath)) {
151
+ schemas.add(entry.name);
152
+ }
153
+ }
154
+ }
155
+ }
156
+
157
+ return Array.from(schemas).sort();
158
+ }
159
+
160
+ /**
161
+ * Schema info with metadata (name, description, artifacts).
162
+ */
163
+ export interface SchemaInfo {
164
+ name: string;
165
+ description: string;
166
+ artifacts: string[];
167
+ source: 'package' | 'user';
168
+ }
169
+
170
+ /**
171
+ * Lists all available schemas with their descriptions and artifact lists.
172
+ * Useful for agent skills to present schema selection to users.
173
+ */
174
+ export function listSchemasWithInfo(): SchemaInfo[] {
175
+ const schemas: SchemaInfo[] = [];
176
+ const seenNames = new Set<string>();
177
+
178
+ // Add user override schemas first (they take precedence)
179
+ const userDir = getUserSchemasDir();
180
+ if (fs.existsSync(userDir)) {
181
+ for (const entry of fs.readdirSync(userDir, { withFileTypes: true })) {
182
+ if (entry.isDirectory()) {
183
+ const schemaPath = path.join(userDir, entry.name, 'schema.yaml');
184
+ if (fs.existsSync(schemaPath)) {
185
+ try {
186
+ const schema = parseSchema(fs.readFileSync(schemaPath, 'utf-8'));
187
+ schemas.push({
188
+ name: entry.name,
189
+ description: schema.description || '',
190
+ artifacts: schema.artifacts.map((a) => a.id),
191
+ source: 'user',
192
+ });
193
+ seenNames.add(entry.name);
194
+ } catch {
195
+ // Skip invalid schemas
196
+ }
197
+ }
198
+ }
199
+ }
200
+ }
201
+
202
+ // Add package built-in schemas (if not overridden)
203
+ const packageDir = getPackageSchemasDir();
204
+ if (fs.existsSync(packageDir)) {
205
+ for (const entry of fs.readdirSync(packageDir, { withFileTypes: true })) {
206
+ if (entry.isDirectory() && !seenNames.has(entry.name)) {
207
+ const schemaPath = path.join(packageDir, entry.name, 'schema.yaml');
208
+ if (fs.existsSync(schemaPath)) {
209
+ try {
210
+ const schema = parseSchema(fs.readFileSync(schemaPath, 'utf-8'));
211
+ schemas.push({
212
+ name: entry.name,
213
+ description: schema.description || '',
214
+ artifacts: schema.artifacts.map((a) => a.id),
215
+ source: 'package',
216
+ });
217
+ } catch {
218
+ // Skip invalid schemas
219
+ }
220
+ }
221
+ }
222
+ }
223
+ }
224
+
225
+ return schemas.sort((a, b) => a.name.localeCompare(b.name));
226
+ }
@@ -0,0 +1,124 @@
1
+ import * as fs from 'node:fs';
2
+ import { parse as parseYaml } from 'yaml';
3
+ import { SchemaYamlSchema, type SchemaYaml, type Artifact } from './types.js';
4
+
5
+ export class SchemaValidationError extends Error {
6
+ constructor(message: string) {
7
+ super(message);
8
+ this.name = 'SchemaValidationError';
9
+ }
10
+ }
11
+
12
+ /**
13
+ * Loads and validates an artifact schema from a YAML file.
14
+ */
15
+ export function loadSchema(filePath: string): SchemaYaml {
16
+ const content = fs.readFileSync(filePath, 'utf-8');
17
+ return parseSchema(content);
18
+ }
19
+
20
+ /**
21
+ * Parses and validates an artifact schema from YAML content.
22
+ */
23
+ export function parseSchema(yamlContent: string): SchemaYaml {
24
+ const parsed = parseYaml(yamlContent);
25
+
26
+ // Validate with Zod
27
+ const result = SchemaYamlSchema.safeParse(parsed);
28
+ if (!result.success) {
29
+ const errors = result.error.issues.map(e => `${e.path.join('.')}: ${e.message}`).join(', ');
30
+ throw new SchemaValidationError(`Invalid schema: ${errors}`);
31
+ }
32
+
33
+ const schema = result.data;
34
+
35
+ // Check for duplicate artifact IDs
36
+ validateNoDuplicateIds(schema.artifacts);
37
+
38
+ // Check that all requires references are valid
39
+ validateRequiresReferences(schema.artifacts);
40
+
41
+ // Check for cycles
42
+ validateNoCycles(schema.artifacts);
43
+
44
+ return schema;
45
+ }
46
+
47
+ /**
48
+ * Validates that there are no duplicate artifact IDs.
49
+ */
50
+ function validateNoDuplicateIds(artifacts: Artifact[]): void {
51
+ const seen = new Set<string>();
52
+ for (const artifact of artifacts) {
53
+ if (seen.has(artifact.id)) {
54
+ throw new SchemaValidationError(`Duplicate artifact ID: ${artifact.id}`);
55
+ }
56
+ seen.add(artifact.id);
57
+ }
58
+ }
59
+
60
+ /**
61
+ * Validates that all `requires` references point to valid artifact IDs.
62
+ */
63
+ function validateRequiresReferences(artifacts: Artifact[]): void {
64
+ const validIds = new Set(artifacts.map(a => a.id));
65
+
66
+ for (const artifact of artifacts) {
67
+ for (const req of artifact.requires) {
68
+ if (!validIds.has(req)) {
69
+ throw new SchemaValidationError(
70
+ `Invalid dependency reference in artifact '${artifact.id}': '${req}' does not exist`
71
+ );
72
+ }
73
+ }
74
+ }
75
+ }
76
+
77
+ /**
78
+ * Validates that there are no cyclic dependencies.
79
+ * Uses DFS to detect cycles and reports the full cycle path.
80
+ */
81
+ function validateNoCycles(artifacts: Artifact[]): void {
82
+ const artifactMap = new Map(artifacts.map(a => [a.id, a]));
83
+ const visited = new Set<string>();
84
+ const inStack = new Set<string>();
85
+ const parent = new Map<string, string>();
86
+
87
+ function dfs(id: string): string | null {
88
+ visited.add(id);
89
+ inStack.add(id);
90
+
91
+ const artifact = artifactMap.get(id);
92
+ if (!artifact) return null;
93
+
94
+ for (const dep of artifact.requires) {
95
+ if (!visited.has(dep)) {
96
+ parent.set(dep, id);
97
+ const cycle = dfs(dep);
98
+ if (cycle) return cycle;
99
+ } else if (inStack.has(dep)) {
100
+ // Found a cycle - reconstruct the path
101
+ const cyclePath = [dep];
102
+ let current = id;
103
+ while (current !== dep) {
104
+ cyclePath.unshift(current);
105
+ current = parent.get(current)!;
106
+ }
107
+ cyclePath.unshift(dep);
108
+ return cyclePath.join(' → ');
109
+ }
110
+ }
111
+
112
+ inStack.delete(id);
113
+ return null;
114
+ }
115
+
116
+ for (const artifact of artifacts) {
117
+ if (!visited.has(artifact.id)) {
118
+ const cycle = dfs(artifact.id);
119
+ if (cycle) {
120
+ throw new SchemaValidationError(`Cyclic dependency detected: ${cycle}`);
121
+ }
122
+ }
123
+ }
124
+ }
@@ -0,0 +1,64 @@
1
+ import * as fs from 'node:fs';
2
+ import * as path from 'node:path';
3
+ import fg from 'fast-glob';
4
+ import type { CompletedSet } from './types.js';
5
+ import type { ArtifactGraph } from './graph.js';
6
+ import { FileSystemUtils } from '../../utils/file-system.js';
7
+
8
+ /**
9
+ * Detects which artifacts are completed by checking file existence in the change directory.
10
+ * Returns a Set of completed artifact IDs.
11
+ *
12
+ * @param graph - The artifact graph to check
13
+ * @param changeDir - The change directory to scan for files
14
+ * @returns Set of artifact IDs whose generated files exist
15
+ */
16
+ export function detectCompleted(graph: ArtifactGraph, changeDir: string): CompletedSet {
17
+ const completed = new Set<string>();
18
+
19
+ // Handle missing change directory gracefully
20
+ if (!fs.existsSync(changeDir)) {
21
+ return completed;
22
+ }
23
+
24
+ for (const artifact of graph.getAllArtifacts()) {
25
+ if (isArtifactComplete(artifact.generates, changeDir)) {
26
+ completed.add(artifact.id);
27
+ }
28
+ }
29
+
30
+ return completed;
31
+ }
32
+
33
+ /**
34
+ * Checks if an artifact is complete by checking if its generated file(s) exist.
35
+ * Supports both simple paths and glob patterns.
36
+ */
37
+ function isArtifactComplete(generates: string, changeDir: string): boolean {
38
+ const fullPattern = path.join(changeDir, generates);
39
+
40
+ // Check if it's a glob pattern
41
+ if (isGlobPattern(generates)) {
42
+ return hasGlobMatches(fullPattern);
43
+ }
44
+
45
+ // Simple file path - check if file exists
46
+ return fs.existsSync(fullPattern);
47
+ }
48
+
49
+ /**
50
+ * Checks if a path contains glob pattern characters.
51
+ */
52
+ function isGlobPattern(pattern: string): boolean {
53
+ return pattern.includes('*') || pattern.includes('?') || pattern.includes('[');
54
+ }
55
+
56
+ /**
57
+ * Checks if a glob pattern has any matches.
58
+ * Normalizes Windows backslashes to forward slashes for cross-platform glob compatibility.
59
+ */
60
+ function hasGlobMatches(pattern: string): boolean {
61
+ const normalizedPattern = FileSystemUtils.toPosixPath(pattern);
62
+ const matches = fg.sync(normalizedPattern, { onlyFiles: true });
63
+ return matches.length > 0;
64
+ }
@@ -0,0 +1,65 @@
1
+ import { z } from 'zod';
2
+
3
+ // Artifact definition schema
4
+ export const ArtifactSchema = z.object({
5
+ id: z.string().min(1, { error: 'Artifact ID is required' }),
6
+ generates: z.string().min(1, { error: 'generates field is required' }),
7
+ description: z.string(),
8
+ template: z.string().min(1, { error: 'template field is required' }),
9
+ instruction: z.string().optional(),
10
+ requires: z.array(z.string()).default([]),
11
+ });
12
+
13
+ // Apply phase configuration for schema-aware apply instructions
14
+ export const ApplyPhaseSchema = z.object({
15
+ // Artifact IDs that must exist before apply is available
16
+ requires: z.array(z.string()).min(1, { error: 'At least one required artifact' }),
17
+ // Path to file with checkboxes for progress (relative to change dir), or null if no tracking
18
+ tracks: z.string().nullable().optional(),
19
+ // Custom guidance for the apply phase
20
+ instruction: z.string().optional(),
21
+ });
22
+
23
+ // Full schema YAML structure
24
+ export const SchemaYamlSchema = z.object({
25
+ name: z.string().min(1, { error: 'Schema name is required' }),
26
+ version: z.number().int().positive({ error: 'Version must be a positive integer' }),
27
+ description: z.string().optional(),
28
+ artifacts: z.array(ArtifactSchema).min(1, { error: 'At least one artifact required' }),
29
+ // Optional apply phase configuration (for schema-aware apply instructions)
30
+ apply: ApplyPhaseSchema.optional(),
31
+ });
32
+
33
+ // Derived TypeScript types
34
+ export type Artifact = z.infer<typeof ArtifactSchema>;
35
+ export type ApplyPhase = z.infer<typeof ApplyPhaseSchema>;
36
+ export type SchemaYaml = z.infer<typeof SchemaYamlSchema>;
37
+
38
+ // Per-change metadata schema
39
+ // Note: schema field is validated at parse time against available schemas
40
+ // using a lazy import to avoid circular dependencies
41
+ export const ChangeMetadataSchema = z.object({
42
+ // Required: which workflow schema this change uses
43
+ schema: z.string().min(1, { message: 'schema is required' }),
44
+
45
+ // Optional: creation timestamp (ISO date string)
46
+ created: z
47
+ .string()
48
+ .regex(/^\d{4}-\d{2}-\d{2}$/, {
49
+ message: 'created must be YYYY-MM-DD format',
50
+ })
51
+ .optional(),
52
+ });
53
+
54
+ export type ChangeMetadata = z.infer<typeof ChangeMetadataSchema>;
55
+
56
+ // Runtime state types (not Zod - internal only)
57
+
58
+ // Slice 1: Simple completion tracking via filesystem
59
+ export type CompletedSet = Set<string>;
60
+
61
+ // Return type for blocked query
62
+ export interface BlockedArtifacts {
63
+ [artifactId: string]: string[];
64
+ }
65
+