@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,167 @@
1
+ import type { Artifact, SchemaYaml, CompletedSet, BlockedArtifacts } from './types.js';
2
+ import { loadSchema, parseSchema } from './schema.js';
3
+
4
+ /**
5
+ * Represents an artifact dependency graph.
6
+ * Provides methods for querying build order, ready artifacts, and completion status.
7
+ */
8
+ export class ArtifactGraph {
9
+ private artifacts: Map<string, Artifact>;
10
+ private schema: SchemaYaml;
11
+
12
+ private constructor(schema: SchemaYaml) {
13
+ this.schema = schema;
14
+ this.artifacts = new Map(schema.artifacts.map(a => [a.id, a]));
15
+ }
16
+
17
+ /**
18
+ * Creates an ArtifactGraph from a YAML file path.
19
+ */
20
+ static fromYaml(filePath: string): ArtifactGraph {
21
+ const schema = loadSchema(filePath);
22
+ return new ArtifactGraph(schema);
23
+ }
24
+
25
+ /**
26
+ * Creates an ArtifactGraph from YAML content string.
27
+ */
28
+ static fromYamlContent(yamlContent: string): ArtifactGraph {
29
+ const schema = parseSchema(yamlContent);
30
+ return new ArtifactGraph(schema);
31
+ }
32
+
33
+ /**
34
+ * Creates an ArtifactGraph from a pre-validated schema object.
35
+ */
36
+ static fromSchema(schema: SchemaYaml): ArtifactGraph {
37
+ return new ArtifactGraph(schema);
38
+ }
39
+
40
+ /**
41
+ * Gets a single artifact by ID.
42
+ */
43
+ getArtifact(id: string): Artifact | undefined {
44
+ return this.artifacts.get(id);
45
+ }
46
+
47
+ /**
48
+ * Gets all artifacts in the graph.
49
+ */
50
+ getAllArtifacts(): Artifact[] {
51
+ return Array.from(this.artifacts.values());
52
+ }
53
+
54
+ /**
55
+ * Gets the schema name.
56
+ */
57
+ getName(): string {
58
+ return this.schema.name;
59
+ }
60
+
61
+ /**
62
+ * Gets the schema version.
63
+ */
64
+ getVersion(): number {
65
+ return this.schema.version;
66
+ }
67
+
68
+ /**
69
+ * Computes the topological build order using Kahn's algorithm.
70
+ * Returns artifact IDs in the order they should be built.
71
+ */
72
+ getBuildOrder(): string[] {
73
+ const inDegree = new Map<string, number>();
74
+ const dependents = new Map<string, string[]>();
75
+
76
+ // Initialize all artifacts
77
+ for (const artifact of this.artifacts.values()) {
78
+ inDegree.set(artifact.id, artifact.requires.length);
79
+ dependents.set(artifact.id, []);
80
+ }
81
+
82
+ // Build reverse adjacency (who depends on whom)
83
+ for (const artifact of this.artifacts.values()) {
84
+ for (const req of artifact.requires) {
85
+ dependents.get(req)!.push(artifact.id);
86
+ }
87
+ }
88
+
89
+ // Start with roots (in-degree 0), sorted for determinism
90
+ const queue = [...this.artifacts.keys()]
91
+ .filter(id => inDegree.get(id) === 0)
92
+ .sort();
93
+
94
+ const result: string[] = [];
95
+
96
+ while (queue.length > 0) {
97
+ const current = queue.shift()!;
98
+ result.push(current);
99
+
100
+ // Collect newly ready artifacts, then sort before adding
101
+ const newlyReady: string[] = [];
102
+ for (const dep of dependents.get(current)!) {
103
+ const newDegree = inDegree.get(dep)! - 1;
104
+ inDegree.set(dep, newDegree);
105
+ if (newDegree === 0) {
106
+ newlyReady.push(dep);
107
+ }
108
+ }
109
+ queue.push(...newlyReady.sort());
110
+ }
111
+
112
+ return result;
113
+ }
114
+
115
+ /**
116
+ * Gets artifacts that are ready to be created (all dependencies completed).
117
+ */
118
+ getNextArtifacts(completed: CompletedSet): string[] {
119
+ const ready: string[] = [];
120
+
121
+ for (const artifact of this.artifacts.values()) {
122
+ if (completed.has(artifact.id)) {
123
+ continue; // Already completed
124
+ }
125
+
126
+ const allDepsCompleted = artifact.requires.every(req => completed.has(req));
127
+ if (allDepsCompleted) {
128
+ ready.push(artifact.id);
129
+ }
130
+ }
131
+
132
+ // Sort for deterministic ordering
133
+ return ready.sort();
134
+ }
135
+
136
+ /**
137
+ * Checks if all artifacts in the graph are completed.
138
+ */
139
+ isComplete(completed: CompletedSet): boolean {
140
+ for (const artifact of this.artifacts.values()) {
141
+ if (!completed.has(artifact.id)) {
142
+ return false;
143
+ }
144
+ }
145
+ return true;
146
+ }
147
+
148
+ /**
149
+ * Gets blocked artifacts and their unmet dependencies.
150
+ */
151
+ getBlocked(completed: CompletedSet): BlockedArtifacts {
152
+ const blocked: BlockedArtifacts = {};
153
+
154
+ for (const artifact of this.artifacts.values()) {
155
+ if (completed.has(artifact.id)) {
156
+ continue; // Already completed
157
+ }
158
+
159
+ const unmetDeps = artifact.requires.filter(req => !completed.has(req));
160
+ if (unmetDeps.length > 0) {
161
+ blocked[artifact.id] = unmetDeps.sort();
162
+ }
163
+ }
164
+
165
+ return blocked;
166
+ }
167
+ }
@@ -0,0 +1,44 @@
1
+ // Types
2
+ export {
3
+ ArtifactSchema,
4
+ SchemaYamlSchema,
5
+ type Artifact,
6
+ type SchemaYaml,
7
+ type CompletedSet,
8
+ type BlockedArtifacts,
9
+ } from './types.js';
10
+
11
+ // Schema loading and validation
12
+ export { loadSchema, parseSchema, SchemaValidationError } from './schema.js';
13
+
14
+ // Graph operations
15
+ export { ArtifactGraph } from './graph.js';
16
+
17
+ // State detection
18
+ export { detectCompleted } from './state.js';
19
+
20
+ // Schema resolution
21
+ export {
22
+ resolveSchema,
23
+ listSchemas,
24
+ listSchemasWithInfo,
25
+ getSchemaDir,
26
+ getPackageSchemasDir,
27
+ getUserSchemasDir,
28
+ SchemaLoadError,
29
+ type SchemaInfo,
30
+ } from './resolver.js';
31
+
32
+ // Instruction loading
33
+ export {
34
+ loadTemplate,
35
+ loadChangeContext,
36
+ generateInstructions,
37
+ formatChangeStatus,
38
+ TemplateLoadError,
39
+ type ChangeContext,
40
+ type ArtifactInstructions,
41
+ type DependencyInfo,
42
+ type ArtifactStatus,
43
+ type ChangeStatus,
44
+ } from './instruction-loader.js';
@@ -0,0 +1,302 @@
1
+ import * as fs from 'node:fs';
2
+ import * as path from 'node:path';
3
+ import { getSchemaDir, resolveSchema } from './resolver.js';
4
+ import { ArtifactGraph } from './graph.js';
5
+ import { detectCompleted } from './state.js';
6
+ import { resolveSchemaForChange } from '../../utils/change-metadata.js';
7
+ import type { Artifact, CompletedSet } from './types.js';
8
+
9
+ /**
10
+ * Error thrown when loading a template fails.
11
+ */
12
+ export class TemplateLoadError extends Error {
13
+ constructor(
14
+ message: string,
15
+ public readonly templatePath: string
16
+ ) {
17
+ super(message);
18
+ this.name = 'TemplateLoadError';
19
+ }
20
+ }
21
+
22
+ /**
23
+ * Change context containing graph, completion state, and metadata.
24
+ */
25
+ export interface ChangeContext {
26
+ /** The artifact dependency graph */
27
+ graph: ArtifactGraph;
28
+ /** Set of completed artifact IDs */
29
+ completed: CompletedSet;
30
+ /** Schema name being used */
31
+ schemaName: string;
32
+ /** Change name */
33
+ changeName: string;
34
+ /** Path to the change directory */
35
+ changeDir: string;
36
+ }
37
+
38
+ /**
39
+ * Enriched instructions for creating an artifact.
40
+ */
41
+ export interface ArtifactInstructions {
42
+ /** Change name */
43
+ changeName: string;
44
+ /** Artifact ID */
45
+ artifactId: string;
46
+ /** Schema name */
47
+ schemaName: string;
48
+ /** Full path to change directory */
49
+ changeDir: string;
50
+ /** Output path pattern (e.g., "proposal.md") */
51
+ outputPath: string;
52
+ /** Artifact description */
53
+ description: string;
54
+ /** Guidance on how to create this artifact (from schema instruction field) */
55
+ instruction: string | undefined;
56
+ /** Template content (structure to follow) */
57
+ template: string;
58
+ /** Dependencies with completion status and paths */
59
+ dependencies: DependencyInfo[];
60
+ /** Artifacts that become available after completing this one */
61
+ unlocks: string[];
62
+ }
63
+
64
+ /**
65
+ * Dependency information including path and description.
66
+ */
67
+ export interface DependencyInfo {
68
+ /** Artifact ID */
69
+ id: string;
70
+ /** Whether the dependency is completed */
71
+ done: boolean;
72
+ /** Relative output path of the dependency (e.g., "proposal.md") */
73
+ path: string;
74
+ /** Description of the dependency artifact */
75
+ description: string;
76
+ }
77
+
78
+ /**
79
+ * Status of a single artifact in the workflow.
80
+ */
81
+ export interface ArtifactStatus {
82
+ /** Artifact ID */
83
+ id: string;
84
+ /** Output path pattern */
85
+ outputPath: string;
86
+ /** Status: done, ready, or blocked */
87
+ status: 'done' | 'ready' | 'blocked';
88
+ /** Missing dependencies (only for blocked) */
89
+ missingDeps?: string[];
90
+ }
91
+
92
+ /**
93
+ * Formatted change status.
94
+ */
95
+ export interface ChangeStatus {
96
+ /** Change name */
97
+ changeName: string;
98
+ /** Schema name */
99
+ schemaName: string;
100
+ /** Whether all artifacts are complete */
101
+ isComplete: boolean;
102
+ /** Artifact IDs required before apply phase (from schema's apply.requires) */
103
+ applyRequires: string[];
104
+ /** Status of each artifact */
105
+ artifacts: ArtifactStatus[];
106
+ }
107
+
108
+ /**
109
+ * Loads a template from a schema's templates directory.
110
+ *
111
+ * @param schemaName - Schema name (e.g., "spec-driven")
112
+ * @param templatePath - Relative path within the templates directory (e.g., "proposal.md")
113
+ * @returns The template content
114
+ * @throws TemplateLoadError if the template cannot be loaded
115
+ */
116
+ export function loadTemplate(schemaName: string, templatePath: string): string {
117
+ const schemaDir = getSchemaDir(schemaName);
118
+ if (!schemaDir) {
119
+ throw new TemplateLoadError(
120
+ `Schema '${schemaName}' not found`,
121
+ templatePath
122
+ );
123
+ }
124
+
125
+ const fullPath = path.join(schemaDir, 'templates', templatePath);
126
+
127
+ if (!fs.existsSync(fullPath)) {
128
+ throw new TemplateLoadError(
129
+ `Template not found: ${fullPath}`,
130
+ fullPath
131
+ );
132
+ }
133
+
134
+ try {
135
+ return fs.readFileSync(fullPath, 'utf-8');
136
+ } catch (err) {
137
+ const ioError = err instanceof Error ? err : new Error(String(err));
138
+ throw new TemplateLoadError(
139
+ `Failed to read template: ${ioError.message}`,
140
+ fullPath
141
+ );
142
+ }
143
+ }
144
+
145
+ /**
146
+ * Loads change context combining graph and completion state.
147
+ *
148
+ * Schema resolution order:
149
+ * 1. Explicit schemaName parameter (if provided)
150
+ * 2. Schema from .prompter.yaml metadata (if exists in change directory)
151
+ * 3. Default 'spec-driven'
152
+ *
153
+ * @param projectRoot - Project root directory
154
+ * @param changeName - Change name
155
+ * @param schemaName - Optional schema name override. If not provided, auto-detected from metadata.
156
+ * @returns Change context with graph, completed set, and metadata
157
+ */
158
+ export function loadChangeContext(
159
+ projectRoot: string,
160
+ changeName: string,
161
+ schemaName?: string
162
+ ): ChangeContext {
163
+ const changeDir = path.join(projectRoot, 'prompter', 'changes', changeName);
164
+
165
+ // Resolve schema: explicit > metadata > default
166
+ const resolvedSchemaName = resolveSchemaForChange(changeDir, schemaName);
167
+
168
+ const schema = resolveSchema(resolvedSchemaName);
169
+ const graph = ArtifactGraph.fromSchema(schema);
170
+ const completed = detectCompleted(graph, changeDir);
171
+
172
+ return {
173
+ graph,
174
+ completed,
175
+ schemaName: resolvedSchemaName,
176
+ changeName,
177
+ changeDir,
178
+ };
179
+ }
180
+
181
+ /**
182
+ * Generates enriched instructions for creating an artifact.
183
+ *
184
+ * @param context - Change context
185
+ * @param artifactId - Artifact ID to generate instructions for
186
+ * @returns Enriched artifact instructions
187
+ * @throws Error if artifact not found
188
+ */
189
+ export function generateInstructions(
190
+ context: ChangeContext,
191
+ artifactId: string
192
+ ): ArtifactInstructions {
193
+ const artifact = context.graph.getArtifact(artifactId);
194
+ if (!artifact) {
195
+ throw new Error(`Artifact '${artifactId}' not found in schema '${context.schemaName}'`);
196
+ }
197
+
198
+ const template = loadTemplate(context.schemaName, artifact.template);
199
+ const dependencies = getDependencyInfo(artifact, context.graph, context.completed);
200
+ const unlocks = getUnlockedArtifacts(context.graph, artifactId);
201
+
202
+ return {
203
+ changeName: context.changeName,
204
+ artifactId: artifact.id,
205
+ schemaName: context.schemaName,
206
+ changeDir: context.changeDir,
207
+ outputPath: artifact.generates,
208
+ description: artifact.description,
209
+ instruction: artifact.instruction,
210
+ template,
211
+ dependencies,
212
+ unlocks,
213
+ };
214
+ }
215
+
216
+ /**
217
+ * Gets dependency info including paths and descriptions.
218
+ */
219
+ function getDependencyInfo(
220
+ artifact: Artifact,
221
+ graph: ArtifactGraph,
222
+ completed: CompletedSet
223
+ ): DependencyInfo[] {
224
+ return artifact.requires.map(id => {
225
+ const depArtifact = graph.getArtifact(id);
226
+ return {
227
+ id,
228
+ done: completed.has(id),
229
+ path: depArtifact?.generates ?? id,
230
+ description: depArtifact?.description ?? '',
231
+ };
232
+ });
233
+ }
234
+
235
+ /**
236
+ * Gets artifacts that become available after completing the given artifact.
237
+ */
238
+ function getUnlockedArtifacts(graph: ArtifactGraph, artifactId: string): string[] {
239
+ const unlocks: string[] = [];
240
+
241
+ for (const artifact of graph.getAllArtifacts()) {
242
+ if (artifact.requires.includes(artifactId)) {
243
+ unlocks.push(artifact.id);
244
+ }
245
+ }
246
+
247
+ return unlocks.sort();
248
+ }
249
+
250
+ /**
251
+ * Formats the status of all artifacts in a change.
252
+ *
253
+ * @param context - Change context
254
+ * @returns Formatted change status
255
+ */
256
+ export function formatChangeStatus(context: ChangeContext): ChangeStatus {
257
+ // Load schema to get apply phase configuration
258
+ const schema = resolveSchema(context.schemaName);
259
+ const applyRequires = schema.apply?.requires ?? schema.artifacts.map(a => a.id);
260
+
261
+ const artifacts = context.graph.getAllArtifacts();
262
+ const ready = new Set(context.graph.getNextArtifacts(context.completed));
263
+ const blocked = context.graph.getBlocked(context.completed);
264
+
265
+ const artifactStatuses: ArtifactStatus[] = artifacts.map(artifact => {
266
+ if (context.completed.has(artifact.id)) {
267
+ return {
268
+ id: artifact.id,
269
+ outputPath: artifact.generates,
270
+ status: 'done' as const,
271
+ };
272
+ }
273
+
274
+ if (ready.has(artifact.id)) {
275
+ return {
276
+ id: artifact.id,
277
+ outputPath: artifact.generates,
278
+ status: 'ready' as const,
279
+ };
280
+ }
281
+
282
+ return {
283
+ id: artifact.id,
284
+ outputPath: artifact.generates,
285
+ status: 'blocked' as const,
286
+ missingDeps: blocked[artifact.id] ?? [],
287
+ };
288
+ });
289
+
290
+ // Sort by build order for consistent output
291
+ const buildOrder = context.graph.getBuildOrder();
292
+ const orderMap = new Map(buildOrder.map((id, idx) => [id, idx]));
293
+ artifactStatuses.sort((a, b) => (orderMap.get(a.id) ?? 0) - (orderMap.get(b.id) ?? 0));
294
+
295
+ return {
296
+ changeName: context.changeName,
297
+ schemaName: context.schemaName,
298
+ isComplete: context.graph.isComplete(context.completed),
299
+ applyRequires,
300
+ artifacts: artifactStatuses,
301
+ };
302
+ }