rafcode 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (370) hide show
  1. package/.claude/settings.local.json +32 -0
  2. package/CLAUDE.md +187 -0
  3. package/LICENSE +21 -0
  4. package/RAF/001-raf-task-improvements/input.md +9 -0
  5. package/RAF/001-raf-task-improvements/outcomes/001-add-decisions-folder.md +21 -0
  6. package/RAF/001-raf-task-improvements/outcomes/002-fix-write-error-on-shutdown.md +22 -0
  7. package/RAF/001-raf-task-improvements/outcomes/003-stash-changes-on-failure.md +34 -0
  8. package/RAF/001-raf-task-improvements/outcomes/004-add-project-name-to-commits.md +28 -0
  9. package/RAF/001-raf-task-improvements/outcomes/005-add-running-time-display.md +36 -0
  10. package/RAF/001-raf-task-improvements/outcomes/006-add-task-name-to-logs.md +22 -0
  11. package/RAF/001-raf-task-improvements/outcomes/007-show-model-at-task-start.md +52 -0
  12. package/RAF/001-raf-task-improvements/outcomes/009-remove-editor-placeholder-text.md +20 -0
  13. package/RAF/001-raf-task-improvements/outcomes/SUMMARY.md +83 -0
  14. package/RAF/001-raf-task-improvements/plans/001-add-decisions-folder.md +38 -0
  15. package/RAF/001-raf-task-improvements/plans/002-fix-write-error-on-shutdown.md +33 -0
  16. package/RAF/001-raf-task-improvements/plans/003-stash-changes-on-failure.md +37 -0
  17. package/RAF/001-raf-task-improvements/plans/004-add-project-name-to-commits.md +34 -0
  18. package/RAF/001-raf-task-improvements/plans/005-add-running-time-display.md +39 -0
  19. package/RAF/001-raf-task-improvements/plans/006-add-task-name-to-logs.md +37 -0
  20. package/RAF/001-raf-task-improvements/plans/009-remove-editor-placeholder-text.md +34 -0
  21. package/RAF/002-raf-task-improvements-execution/decisions/DECISIONS.md +13 -0
  22. package/RAF/002-raf-task-improvements-execution/input.md +3 -0
  23. package/RAF/002-raf-task-improvements-execution/outcomes/001-commit-show-model-at-task-start.md +17 -0
  24. package/RAF/002-raf-task-improvements-execution/outcomes/002-delete-skipped-plan.md +23 -0
  25. package/RAF/002-raf-task-improvements-execution/outcomes/SUMMARY.md +32 -0
  26. package/RAF/002-raf-task-improvements-execution/plans/001-commit-show-model-at-task-start.md +37 -0
  27. package/RAF/002-raf-task-improvements-execution/plans/002-delete-skipped-plan.md +23 -0
  28. package/RAF/003-multi-project-execution/decisions/DECISIONS.md +68 -0
  29. package/RAF/003-multi-project-execution/input.md +6 -0
  30. package/RAF/003-multi-project-execution/outcomes/001-remove-state-json.md +52 -0
  31. package/RAF/003-multi-project-execution/outcomes/002-update-raf-status.md +50 -0
  32. package/RAF/003-multi-project-execution/outcomes/003-simplify-git-logic.md +35 -0
  33. package/RAF/003-multi-project-execution/outcomes/004-auto-commit-planning.md +43 -0
  34. package/RAF/003-multi-project-execution/outcomes/005-rerun-failed-tasks.md +43 -0
  35. package/RAF/003-multi-project-execution/outcomes/006-multi-project-execution.md +42 -0
  36. package/RAF/003-multi-project-execution/outcomes/007-verify-timeout.md +54 -0
  37. package/RAF/003-multi-project-execution/outcomes/008-move-decisions-file.md +38 -0
  38. package/RAF/003-multi-project-execution/outcomes/SUMMARY.md +79 -0
  39. package/RAF/003-multi-project-execution/plans/001-remove-state-json.md +71 -0
  40. package/RAF/003-multi-project-execution/plans/002-update-raf-status.md +65 -0
  41. package/RAF/003-multi-project-execution/plans/003-simplify-git-logic.md +74 -0
  42. package/RAF/003-multi-project-execution/plans/004-auto-commit-planning.md +57 -0
  43. package/RAF/003-multi-project-execution/plans/005-rerun-failed-tasks.md +69 -0
  44. package/RAF/003-multi-project-execution/plans/006-multi-project-execution.md +81 -0
  45. package/RAF/003-multi-project-execution/plans/007-verify-timeout.md +63 -0
  46. package/RAF/003-multi-project-execution/plans/008-move-decisions-file.md +78 -0
  47. package/RAF/004-task-naming-optimization/decisions.md +22 -0
  48. package/RAF/004-task-naming-optimization/input.md +6 -0
  49. package/RAF/004-task-naming-optimization/outcomes/001-remove-summary-file.md +17 -0
  50. package/RAF/004-task-naming-optimization/outcomes/002-base36-project-numbering.md +32 -0
  51. package/RAF/004-task-naming-optimization/outcomes/003-improve-haiku-prompt.md +20 -0
  52. package/RAF/004-task-naming-optimization/outcomes/SUMMARY.md +28 -0
  53. package/RAF/004-task-naming-optimization/plans/001-remove-summary-file.md +34 -0
  54. package/RAF/004-task-naming-optimization/plans/002-base36-project-numbering.md +56 -0
  55. package/RAF/004-task-naming-optimization/plans/003-improve-haiku-prompt.md +50 -0
  56. package/RAF/005-task-naming-improvements/decisions.md +60 -0
  57. package/RAF/005-task-naming-improvements/input.md +2 -0
  58. package/RAF/005-task-naming-improvements/outcomes/001-enhance-identifier-resolution.md +42 -0
  59. package/RAF/005-task-naming-improvements/outcomes/002-add-identifier-support-to-status.md +38 -0
  60. package/RAF/005-task-naming-improvements/outcomes/003-update-do-for-full-folder-names.md +44 -0
  61. package/RAF/005-task-naming-improvements/outcomes/004-implement-amend-flag-for-plan.md +55 -0
  62. package/RAF/005-task-naming-improvements/outcomes/005-commit-outcomes-on-complete.md +47 -0
  63. package/RAF/005-task-naming-improvements/outcomes/006-update-execution-prompt-commit-schema.md +40 -0
  64. package/RAF/005-task-naming-improvements/outcomes/007-allow-pending-task-amendments.md +38 -0
  65. package/RAF/005-task-naming-improvements/outcomes/008-fix-timeout-label.md +24 -0
  66. package/RAF/005-task-naming-improvements/plans/001-enhance-identifier-resolution.md +46 -0
  67. package/RAF/005-task-naming-improvements/plans/002-add-identifier-support-to-status.md +36 -0
  68. package/RAF/005-task-naming-improvements/plans/003-update-do-for-full-folder-names.md +38 -0
  69. package/RAF/005-task-naming-improvements/plans/004-implement-amend-flag-for-plan.md +67 -0
  70. package/RAF/005-task-naming-improvements/plans/005-commit-outcomes-on-complete.md +86 -0
  71. package/RAF/005-task-naming-improvements/plans/006-update-execution-prompt-commit-schema.md +60 -0
  72. package/RAF/005-task-naming-improvements/plans/007-allow-pending-task-amendments.md +60 -0
  73. package/RAF/005-task-naming-improvements/plans/008-fix-timeout-label.md +31 -0
  74. package/RAF/006-fix-double-summary-headers/decisions.md +28 -0
  75. package/RAF/006-fix-double-summary-headers/input.md +3 -0
  76. package/RAF/006-fix-double-summary-headers/outcomes/001-fix-double-summary-headers.md +29 -0
  77. package/RAF/006-fix-double-summary-headers/outcomes/002-update-readme-for-npm.md +31 -0
  78. package/RAF/006-fix-double-summary-headers/outcomes/003-npm-publish-instructions.md +30 -0
  79. package/RAF/006-fix-double-summary-headers/outcomes/004-flexible-project-lookup.md +47 -0
  80. package/RAF/006-fix-double-summary-headers/plans/001-fix-double-summary-headers.md +42 -0
  81. package/RAF/006-fix-double-summary-headers/plans/002-update-readme-for-npm.md +44 -0
  82. package/RAF/006-fix-double-summary-headers/plans/003-npm-publish-instructions.md +45 -0
  83. package/RAF/006-fix-double-summary-headers/plans/004-flexible-project-lookup.md +40 -0
  84. package/RAF/007-improve-outcome-format/decisions.md +28 -0
  85. package/RAF/007-improve-outcome-format/input.md +2 -0
  86. package/RAF/007-improve-outcome-format/outcomes/001-update-execution-prompt.md +10 -0
  87. package/RAF/007-improve-outcome-format/outcomes/002-update-state-derivation.md +17 -0
  88. package/RAF/007-improve-outcome-format/outcomes/003-update-do-command-outcome-handling.md +16 -0
  89. package/RAF/007-improve-outcome-format/outcomes/004-implement-failure-analysis.md +16 -0
  90. package/RAF/007-improve-outcome-format/outcomes/005-update-documentation.md +15 -0
  91. package/RAF/007-improve-outcome-format/plans/001-update-execution-prompt.md +36 -0
  92. package/RAF/007-improve-outcome-format/plans/002-update-state-derivation.md +35 -0
  93. package/RAF/007-improve-outcome-format/plans/003-update-do-command-outcome-handling.md +37 -0
  94. package/RAF/007-improve-outcome-format/plans/004-implement-failure-analysis.md +44 -0
  95. package/RAF/007-improve-outcome-format/plans/005-update-documentation.md +33 -0
  96. package/RAF/008-beautiful-do/decisions.md +31 -0
  97. package/RAF/008-beautiful-do/input.md +1 -0
  98. package/RAF/008-beautiful-do/outcomes/001-terminal-symbols.md +55 -0
  99. package/RAF/008-beautiful-do/outcomes/002-refactor-do-output.md +95 -0
  100. package/RAF/008-beautiful-do/outcomes/003-refactor-status-output.md +71 -0
  101. package/RAF/008-beautiful-do/outcomes/004-simplify-logger.md +53 -0
  102. package/RAF/008-beautiful-do/outcomes/005-add-tests.md +41 -0
  103. package/RAF/008-beautiful-do/plans/001-terminal-symbols.md +41 -0
  104. package/RAF/008-beautiful-do/plans/002-refactor-do-output.md +44 -0
  105. package/RAF/008-beautiful-do/plans/003-refactor-status-output.md +37 -0
  106. package/RAF/008-beautiful-do/plans/004-simplify-logger.md +32 -0
  107. package/RAF/008-beautiful-do/plans/005-add-tests.md +40 -0
  108. package/RAF/009-system-promt-ammend/decisions.md +13 -0
  109. package/RAF/009-system-promt-ammend/input.md +9 -0
  110. package/RAF/009-system-promt-ammend/outcomes/001-model-override.md +79 -0
  111. package/RAF/009-system-promt-ammend/outcomes/002-system-prompt-append.md +51 -0
  112. package/RAF/009-system-promt-ammend/outcomes/003-retry-context.md +60 -0
  113. package/RAF/009-system-promt-ammend/plans/001-model-override.md +61 -0
  114. package/RAF/009-system-promt-ammend/plans/002-system-prompt-append.md +56 -0
  115. package/RAF/009-system-promt-ammend/plans/003-retry-context.md +76 -0
  116. package/RAF/010-outcome-marker-fallback/decisions.md +19 -0
  117. package/RAF/010-outcome-marker-fallback/input.md +1 -0
  118. package/RAF/010-outcome-marker-fallback/outcomes/001-outcome-file-marker-fallback.md +35 -0
  119. package/RAF/010-outcome-marker-fallback/outcomes/002-creative-project-naming.md +47 -0
  120. package/RAF/010-outcome-marker-fallback/plans/001-outcome-file-marker-fallback.md +58 -0
  121. package/RAF/010-outcome-marker-fallback/plans/002-creative-project-naming.md +68 -0
  122. package/RAF/011-do-task-in-commit/decisions.md +22 -0
  123. package/RAF/011-do-task-in-commit/input.md +1 -0
  124. package/RAF/011-do-task-in-commit/outcomes/001-update-execution-prompt.md +54 -0
  125. package/RAF/011-do-task-in-commit/outcomes/002-update-tests.md +61 -0
  126. package/RAF/011-do-task-in-commit/outcomes/003-update-documentation.md +51 -0
  127. package/RAF/011-do-task-in-commit/plans/001-update-execution-prompt.md +46 -0
  128. package/RAF/011-do-task-in-commit/plans/002-update-tests.md +51 -0
  129. package/RAF/011-do-task-in-commit/plans/003-update-documentation.md +45 -0
  130. package/RAF/012-name-picker-buffet/decisions.md +40 -0
  131. package/RAF/012-name-picker-buffet/input.md +6 -0
  132. package/RAF/012-name-picker-buffet/outcomes/001-name-picker-for-raf-plan.md +49 -0
  133. package/RAF/012-name-picker-buffet/outcomes/002-interactive-project-picker-for-raf-do.md +49 -0
  134. package/RAF/012-name-picker-buffet/outcomes/003-raf-status-truncation.md +55 -0
  135. package/RAF/012-name-picker-buffet/outcomes/004-failure-reason-details.md +65 -0
  136. package/RAF/012-name-picker-buffet/outcomes/005-remove-raf-commits.md +57 -0
  137. package/RAF/012-name-picker-buffet/outcomes/006-update-execution-prompt-for-commits.md +47 -0
  138. package/RAF/012-name-picker-buffet/outcomes/007-fix-plan-mode-user-prompt.md +83 -0
  139. package/RAF/012-name-picker-buffet/outcomes/008-add-auto-flag-for-plan-mode.md +77 -0
  140. package/RAF/012-name-picker-buffet/plans/001-name-picker-for-raf-plan.md +47 -0
  141. package/RAF/012-name-picker-buffet/plans/002-interactive-project-picker-for-raf-do.md +43 -0
  142. package/RAF/012-name-picker-buffet/plans/003-raf-status-truncation.md +36 -0
  143. package/RAF/012-name-picker-buffet/plans/004-failure-reason-details.md +46 -0
  144. package/RAF/012-name-picker-buffet/plans/005-remove-raf-commits.md +42 -0
  145. package/RAF/012-name-picker-buffet/plans/006-update-execution-prompt-for-commits.md +47 -0
  146. package/RAF/012-name-picker-buffet/plans/007-fix-plan-mode-user-prompt.md +55 -0
  147. package/RAF/012-name-picker-buffet/plans/008-add-auto-flag-for-plan-mode.md +49 -0
  148. package/RAF/013-dependencies-watchdog/decisions.md +37 -0
  149. package/RAF/013-dependencies-watchdog/input.md +1 -0
  150. package/RAF/013-dependencies-watchdog/outcomes/001-define-dependency-syntax.md +56 -0
  151. package/RAF/013-dependencies-watchdog/outcomes/002-update-planning-prompts.md +60 -0
  152. package/RAF/013-dependencies-watchdog/outcomes/003-parse-dependencies-update-state.md +81 -0
  153. package/RAF/013-dependencies-watchdog/outcomes/004-implement-dependency-checking-in-do.md +116 -0
  154. package/RAF/013-dependencies-watchdog/outcomes/005-update-execution-prompts.md +75 -0
  155. package/RAF/013-dependencies-watchdog/outcomes/006-add-tests.md +100 -0
  156. package/RAF/013-dependencies-watchdog/outcomes/007-add-act-alias.md +46 -0
  157. package/RAF/013-dependencies-watchdog/outcomes/008-add-exit-message.md +52 -0
  158. package/RAF/013-dependencies-watchdog/plans/001-define-dependency-syntax.md +32 -0
  159. package/RAF/013-dependencies-watchdog/plans/002-update-planning-prompts.md +38 -0
  160. package/RAF/013-dependencies-watchdog/plans/003-parse-dependencies-update-state.md +46 -0
  161. package/RAF/013-dependencies-watchdog/plans/004-implement-dependency-checking-in-do.md +48 -0
  162. package/RAF/013-dependencies-watchdog/plans/005-update-execution-prompts.md +44 -0
  163. package/RAF/013-dependencies-watchdog/plans/006-add-tests.md +54 -0
  164. package/RAF/013-dependencies-watchdog/plans/007-add-act-alias.md +26 -0
  165. package/RAF/013-dependencies-watchdog/plans/008-add-exit-message.md +31 -0
  166. package/RAF/014-watchdog/decisions.md +16 -0
  167. package/RAF/014-watchdog/input.md +2 -0
  168. package/RAF/014-watchdog/outcomes/001-amend-flag-position.md +50 -0
  169. package/RAF/014-watchdog/outcomes/002-details-only-on-failure.md +58 -0
  170. package/RAF/014-watchdog/plans/001-amend-flag-position.md +34 -0
  171. package/RAF/014-watchdog/plans/002-details-only-on-failure.md +46 -0
  172. package/RAF/015-name-lottery/decisions.md +14 -0
  173. package/RAF/015-name-lottery/input.md +3 -0
  174. package/RAF/015-name-lottery/outcomes/001-auto-pick-project-name.md +31 -0
  175. package/RAF/015-name-lottery/outcomes/002-mention-plan-files-in-commit.md +23 -0
  176. package/RAF/015-name-lottery/outcomes/003-fix-input-md-in-amend-flow.md +44 -0
  177. package/RAF/015-name-lottery/plans/001-auto-pick-project-name.md +38 -0
  178. package/RAF/015-name-lottery/plans/002-mention-plan-files-in-commit.md +32 -0
  179. package/RAF/015-name-lottery/plans/003-fix-input-md-in-amend-flow.md +44 -0
  180. package/README.md +116 -0
  181. package/dist/commands/do.d.ts +12 -0
  182. package/dist/commands/do.d.ts.map +1 -0
  183. package/dist/commands/do.js +684 -0
  184. package/dist/commands/do.js.map +1 -0
  185. package/dist/commands/plan.d.ts +3 -0
  186. package/dist/commands/plan.d.ts.map +1 -0
  187. package/dist/commands/plan.js +345 -0
  188. package/dist/commands/plan.js.map +1 -0
  189. package/dist/commands/status.d.ts +3 -0
  190. package/dist/commands/status.d.ts.map +1 -0
  191. package/dist/commands/status.js +117 -0
  192. package/dist/commands/status.js.map +1 -0
  193. package/dist/core/claude-runner.d.ts +78 -0
  194. package/dist/core/claude-runner.d.ts.map +1 -0
  195. package/dist/core/claude-runner.js +297 -0
  196. package/dist/core/claude-runner.js.map +1 -0
  197. package/dist/core/editor.d.ts +10 -0
  198. package/dist/core/editor.d.ts.map +1 -0
  199. package/dist/core/editor.js +77 -0
  200. package/dist/core/editor.js.map +1 -0
  201. package/dist/core/failure-analyzer.d.ts +28 -0
  202. package/dist/core/failure-analyzer.d.ts.map +1 -0
  203. package/dist/core/failure-analyzer.js +305 -0
  204. package/dist/core/failure-analyzer.js.map +1 -0
  205. package/dist/core/git.d.ts +42 -0
  206. package/dist/core/git.d.ts.map +1 -0
  207. package/dist/core/git.js +148 -0
  208. package/dist/core/git.js.map +1 -0
  209. package/dist/core/project-manager.d.ts +72 -0
  210. package/dist/core/project-manager.d.ts.map +1 -0
  211. package/dist/core/project-manager.js +193 -0
  212. package/dist/core/project-manager.js.map +1 -0
  213. package/dist/core/retry-handler.d.ts +19 -0
  214. package/dist/core/retry-handler.d.ts.map +1 -0
  215. package/dist/core/retry-handler.js +51 -0
  216. package/dist/core/retry-handler.js.map +1 -0
  217. package/dist/core/shutdown-handler.d.ts +30 -0
  218. package/dist/core/shutdown-handler.d.ts.map +1 -0
  219. package/dist/core/shutdown-handler.js +79 -0
  220. package/dist/core/shutdown-handler.js.map +1 -0
  221. package/dist/core/state-derivation.d.ts +82 -0
  222. package/dist/core/state-derivation.d.ts.map +1 -0
  223. package/dist/core/state-derivation.js +271 -0
  224. package/dist/core/state-derivation.js.map +1 -0
  225. package/dist/core/state-manager.d.ts +54 -0
  226. package/dist/core/state-manager.d.ts.map +1 -0
  227. package/dist/core/state-manager.js +198 -0
  228. package/dist/core/state-manager.js.map +1 -0
  229. package/dist/index.d.ts +3 -0
  230. package/dist/index.d.ts.map +1 -0
  231. package/dist/index.js +16 -0
  232. package/dist/index.js.map +1 -0
  233. package/dist/parsers/output-parser.d.ts +19 -0
  234. package/dist/parsers/output-parser.d.ts.map +1 -0
  235. package/dist/parsers/output-parser.js +137 -0
  236. package/dist/parsers/output-parser.js.map +1 -0
  237. package/dist/prompts/amend.d.ts +20 -0
  238. package/dist/prompts/amend.d.ts.map +1 -0
  239. package/dist/prompts/amend.js +166 -0
  240. package/dist/prompts/amend.js.map +1 -0
  241. package/dist/prompts/execution.d.ts +30 -0
  242. package/dist/prompts/execution.d.ts.map +1 -0
  243. package/dist/prompts/execution.js +179 -0
  244. package/dist/prompts/execution.js.map +1 -0
  245. package/dist/prompts/planning.d.ts +15 -0
  246. package/dist/prompts/planning.d.ts.map +1 -0
  247. package/dist/prompts/planning.js +163 -0
  248. package/dist/prompts/planning.js.map +1 -0
  249. package/dist/types/config.d.ts +26 -0
  250. package/dist/types/config.d.ts.map +1 -0
  251. package/dist/types/config.js +7 -0
  252. package/dist/types/config.js.map +1 -0
  253. package/dist/types/state.d.ts +33 -0
  254. package/dist/types/state.d.ts.map +1 -0
  255. package/dist/types/state.js +28 -0
  256. package/dist/types/state.js.map +1 -0
  257. package/dist/ui/name-picker-subprocess.d.ts +11 -0
  258. package/dist/ui/name-picker-subprocess.d.ts.map +1 -0
  259. package/dist/ui/name-picker-subprocess.js +83 -0
  260. package/dist/ui/name-picker-subprocess.js.map +1 -0
  261. package/dist/ui/name-picker.d.ts +19 -0
  262. package/dist/ui/name-picker.d.ts.map +1 -0
  263. package/dist/ui/name-picker.js +173 -0
  264. package/dist/ui/name-picker.js.map +1 -0
  265. package/dist/ui/project-picker.d.ts +27 -0
  266. package/dist/ui/project-picker.d.ts.map +1 -0
  267. package/dist/ui/project-picker.js +58 -0
  268. package/dist/ui/project-picker.js.map +1 -0
  269. package/dist/utils/config.d.ts +24 -0
  270. package/dist/utils/config.d.ts.map +1 -0
  271. package/dist/utils/config.js +63 -0
  272. package/dist/utils/config.js.map +1 -0
  273. package/dist/utils/logger.d.ts +32 -0
  274. package/dist/utils/logger.d.ts.map +1 -0
  275. package/dist/utils/logger.js +60 -0
  276. package/dist/utils/logger.js.map +1 -0
  277. package/dist/utils/name-generator.d.ts +20 -0
  278. package/dist/utils/name-generator.d.ts.map +1 -0
  279. package/dist/utils/name-generator.js +183 -0
  280. package/dist/utils/name-generator.js.map +1 -0
  281. package/dist/utils/paths.d.ts +132 -0
  282. package/dist/utils/paths.d.ts.map +1 -0
  283. package/dist/utils/paths.js +412 -0
  284. package/dist/utils/paths.js.map +1 -0
  285. package/dist/utils/status-line.d.ts +14 -0
  286. package/dist/utils/status-line.d.ts.map +1 -0
  287. package/dist/utils/status-line.js +36 -0
  288. package/dist/utils/status-line.js.map +1 -0
  289. package/dist/utils/terminal-symbols.d.ts +50 -0
  290. package/dist/utils/terminal-symbols.d.ts.map +1 -0
  291. package/dist/utils/terminal-symbols.js +97 -0
  292. package/dist/utils/terminal-symbols.js.map +1 -0
  293. package/dist/utils/timer.d.ts +17 -0
  294. package/dist/utils/timer.d.ts.map +1 -0
  295. package/dist/utils/timer.js +56 -0
  296. package/dist/utils/timer.js.map +1 -0
  297. package/dist/utils/validation.d.ts +17 -0
  298. package/dist/utils/validation.d.ts.map +1 -0
  299. package/dist/utils/validation.js +106 -0
  300. package/dist/utils/validation.js.map +1 -0
  301. package/dist/utils/version.d.ts +2 -0
  302. package/dist/utils/version.d.ts.map +1 -0
  303. package/dist/utils/version.js +12 -0
  304. package/dist/utils/version.js.map +1 -0
  305. package/jest.config.ts +30 -0
  306. package/package.json +55 -0
  307. package/src/commands/do.ts +829 -0
  308. package/src/commands/plan.ts +422 -0
  309. package/src/commands/status.ts +146 -0
  310. package/src/core/claude-runner.ts +374 -0
  311. package/src/core/editor.ts +85 -0
  312. package/src/core/failure-analyzer.ts +372 -0
  313. package/src/core/git.ts +166 -0
  314. package/src/core/project-manager.ts +243 -0
  315. package/src/core/retry-handler.ts +72 -0
  316. package/src/core/shutdown-handler.ts +93 -0
  317. package/src/core/state-derivation.ts +343 -0
  318. package/src/index.ts +20 -0
  319. package/src/parsers/output-parser.ts +164 -0
  320. package/src/prompts/amend.ts +194 -0
  321. package/src/prompts/execution.ts +223 -0
  322. package/src/prompts/planning.ts +175 -0
  323. package/src/types/config.ts +35 -0
  324. package/src/ui/name-picker-subprocess.ts +96 -0
  325. package/src/ui/name-picker.ts +198 -0
  326. package/src/ui/project-picker.ts +80 -0
  327. package/src/utils/config.ts +69 -0
  328. package/src/utils/logger.ts +81 -0
  329. package/src/utils/name-generator.ts +211 -0
  330. package/src/utils/paths.ts +497 -0
  331. package/src/utils/status-line.ts +45 -0
  332. package/src/utils/terminal-symbols.ts +124 -0
  333. package/src/utils/timer.ts +64 -0
  334. package/src/utils/validation.ts +132 -0
  335. package/src/utils/version.ts +12 -0
  336. package/tests/unit/claude-runner-interactive.test.ts +343 -0
  337. package/tests/unit/claude-runner.test.ts +629 -0
  338. package/tests/unit/command-output.test.ts +295 -0
  339. package/tests/unit/config.test.ts +72 -0
  340. package/tests/unit/dependency-integration.test.ts +559 -0
  341. package/tests/unit/do-blocked-tasks.test.ts +323 -0
  342. package/tests/unit/do-command.test.ts +198 -0
  343. package/tests/unit/do-multiproject.test.ts +270 -0
  344. package/tests/unit/do-rerun.test.ts +270 -0
  345. package/tests/unit/execution-prompt.test.ts +406 -0
  346. package/tests/unit/failure-analyzer.test.ts +276 -0
  347. package/tests/unit/failure-history.test.ts +143 -0
  348. package/tests/unit/git-stash.test.ts +138 -0
  349. package/tests/unit/git.test.ts +80 -0
  350. package/tests/unit/logger.test.ts +132 -0
  351. package/tests/unit/name-generator.test.ts +283 -0
  352. package/tests/unit/name-picker.test.ts +179 -0
  353. package/tests/unit/outcome-content.test.ts +166 -0
  354. package/tests/unit/output-parser.test.ts +178 -0
  355. package/tests/unit/paths.test.ts +741 -0
  356. package/tests/unit/plan-command-amend-flag.test.ts +115 -0
  357. package/tests/unit/plan-command-amend-input.test.ts +156 -0
  358. package/tests/unit/plan-command-auto-flag.test.ts +112 -0
  359. package/tests/unit/plan-command.test.ts +580 -0
  360. package/tests/unit/planning-prompt.test.ts +137 -0
  361. package/tests/unit/project-manager.test.ts +265 -0
  362. package/tests/unit/project-picker.test.ts +338 -0
  363. package/tests/unit/retry-handler.test.ts +89 -0
  364. package/tests/unit/state-derivation.test.ts +714 -0
  365. package/tests/unit/status-command.test.ts +271 -0
  366. package/tests/unit/status-line.test.ts +92 -0
  367. package/tests/unit/terminal-symbols.test.ts +214 -0
  368. package/tests/unit/timer.test.ts +102 -0
  369. package/tests/unit/validation.test.ts +118 -0
  370. package/tsconfig.json +26 -0
@@ -0,0 +1,714 @@
1
+ import * as fs from 'node:fs';
2
+ import * as path from 'node:path';
3
+ import * as os from 'node:os';
4
+ import {
5
+ parseOutcomeStatus,
6
+ parseDependencies,
7
+ deriveProjectState,
8
+ deriveProjectStatus,
9
+ discoverProjects,
10
+ getNextPendingTask,
11
+ getNextExecutableTask,
12
+ getDerivedStats,
13
+ isProjectComplete,
14
+ hasProjectFailed,
15
+ type DerivedProjectStatus,
16
+ } from '../../src/core/state-derivation.js';
17
+
18
+ describe('state-derivation', () => {
19
+ let tempDir: string;
20
+ let projectPath: string;
21
+
22
+ beforeEach(() => {
23
+ tempDir = fs.mkdtempSync(path.join(os.tmpdir(), 'raf-test-'));
24
+ projectPath = path.join(tempDir, '001-test-project');
25
+ fs.mkdirSync(projectPath, { recursive: true });
26
+ fs.mkdirSync(path.join(projectPath, 'plans'), { recursive: true });
27
+ fs.mkdirSync(path.join(projectPath, 'outcomes'), { recursive: true });
28
+ });
29
+
30
+ afterEach(() => {
31
+ fs.rmSync(tempDir, { recursive: true, force: true });
32
+ });
33
+
34
+ describe('parseOutcomeStatus', () => {
35
+ it('should parse COMPLETE promise marker as completed', () => {
36
+ const content = `# Task 001 - Completed
37
+
38
+ ## Summary
39
+ Task was successful.
40
+
41
+ <promise>COMPLETE</promise>
42
+ `;
43
+ expect(parseOutcomeStatus(content)).toBe('completed');
44
+ });
45
+
46
+ it('should parse FAILED promise marker as failed', () => {
47
+ const content = `# Task 001 - Failed
48
+
49
+ ## Failure Reason
50
+ Something went wrong.
51
+
52
+ <promise>FAILED</promise>
53
+ `;
54
+ expect(parseOutcomeStatus(content)).toBe('failed');
55
+ });
56
+
57
+ it('should use last occurrence when multiple markers exist', () => {
58
+ const content = `# Task 001
59
+
60
+ <promise>FAILED</promise>
61
+
62
+ Retry was successful!
63
+
64
+ <promise>COMPLETE</promise>
65
+ `;
66
+ expect(parseOutcomeStatus(content)).toBe('completed');
67
+ });
68
+
69
+ it('should return null for missing promise marker', () => {
70
+ const content = `# Task 001 - Completed
71
+
72
+ ## Summary
73
+ Old format without promise marker.
74
+ `;
75
+ expect(parseOutcomeStatus(content)).toBeNull();
76
+ });
77
+
78
+ it('should return null for empty content', () => {
79
+ expect(parseOutcomeStatus('')).toBeNull();
80
+ });
81
+
82
+ it('should parse BLOCKED promise marker as blocked', () => {
83
+ const content = `# Task 001 - Blocked
84
+
85
+ ## Reason
86
+ Dependency failed.
87
+
88
+ <promise>BLOCKED</promise>
89
+ `;
90
+ expect(parseOutcomeStatus(content)).toBe('blocked');
91
+ });
92
+
93
+ it('should use last occurrence when BLOCKED is final marker', () => {
94
+ const content = `# Task 001
95
+
96
+ <promise>COMPLETE</promise>
97
+
98
+ Later it was blocked...
99
+
100
+ <promise>BLOCKED</promise>
101
+ `;
102
+ expect(parseOutcomeStatus(content)).toBe('blocked');
103
+ });
104
+ });
105
+
106
+ describe('parseDependencies', () => {
107
+ it('should parse single dependency', () => {
108
+ const content = `# Task
109
+
110
+ ## Dependencies
111
+ 001
112
+
113
+ ## Requirements
114
+ `;
115
+ expect(parseDependencies(content)).toEqual(['001']);
116
+ });
117
+
118
+ it('should parse multiple comma-separated dependencies', () => {
119
+ const content = `# Task
120
+
121
+ ## Dependencies
122
+ 001, 002, 003
123
+
124
+ ## Requirements
125
+ `;
126
+ expect(parseDependencies(content)).toEqual(['001', '002', '003']);
127
+ });
128
+
129
+ it('should handle extra whitespace around dependencies', () => {
130
+ const content = `# Task
131
+
132
+ ## Dependencies
133
+ 001 , 002 ,003
134
+
135
+ ## Requirements
136
+ `;
137
+ expect(parseDependencies(content)).toEqual(['001', '002', '003']);
138
+ });
139
+
140
+ it('should return empty array when no Dependencies section', () => {
141
+ const content = `# Task
142
+
143
+ ## Requirements
144
+ - Do something
145
+ `;
146
+ expect(parseDependencies(content)).toEqual([]);
147
+ });
148
+
149
+ it('should return empty array for empty Dependencies section', () => {
150
+ const content = `# Task
151
+
152
+ ## Dependencies
153
+
154
+ ## Requirements
155
+ `;
156
+ expect(parseDependencies(content)).toEqual([]);
157
+ });
158
+
159
+ it('should filter out invalid task IDs', () => {
160
+ const content = `# Task
161
+
162
+ ## Dependencies
163
+ 001, invalid, 002, 1, 0001, abc
164
+
165
+ ## Requirements
166
+ `;
167
+ expect(parseDependencies(content)).toEqual(['001', '002']);
168
+ });
169
+
170
+ it('should handle 3-digit task IDs', () => {
171
+ const content = `# Task
172
+
173
+ ## Dependencies
174
+ 099, 100, 999
175
+
176
+ ## Requirements
177
+ `;
178
+ expect(parseDependencies(content)).toEqual(['099', '100', '999']);
179
+ });
180
+ });
181
+
182
+ describe('discoverProjects', () => {
183
+ it('should return empty array for non-existent directory', () => {
184
+ const projects = discoverProjects('/non-existent-dir');
185
+ expect(projects).toEqual([]);
186
+ });
187
+
188
+ it('should return empty array for empty directory', () => {
189
+ const rafDir = path.join(tempDir, 'RAF');
190
+ fs.mkdirSync(rafDir);
191
+ const projects = discoverProjects(rafDir);
192
+ expect(projects).toEqual([]);
193
+ });
194
+
195
+ it('should discover projects matching NNN-name pattern', () => {
196
+ const rafDir = path.join(tempDir, 'RAF');
197
+ fs.mkdirSync(rafDir);
198
+ fs.mkdirSync(path.join(rafDir, '001-first-project'));
199
+ fs.mkdirSync(path.join(rafDir, '002-second-project'));
200
+ fs.mkdirSync(path.join(rafDir, 'not-a-project'));
201
+ fs.writeFileSync(path.join(rafDir, 'some-file.txt'), 'content');
202
+
203
+ const projects = discoverProjects(rafDir);
204
+ expect(projects).toHaveLength(2);
205
+ expect(projects[0]?.number).toBe(1);
206
+ expect(projects[0]?.name).toBe('first-project');
207
+ expect(projects[0]?.path).toBe(path.join(rafDir, '001-first-project'));
208
+ expect(projects[1]?.number).toBe(2);
209
+ expect(projects[1]?.name).toBe('second-project');
210
+ });
211
+
212
+ it('should sort projects by number', () => {
213
+ const rafDir = path.join(tempDir, 'RAF');
214
+ fs.mkdirSync(rafDir);
215
+ fs.mkdirSync(path.join(rafDir, '003-third'));
216
+ fs.mkdirSync(path.join(rafDir, '001-first'));
217
+ fs.mkdirSync(path.join(rafDir, '002-second'));
218
+
219
+ const projects = discoverProjects(rafDir);
220
+ expect(projects.map((p) => p.number)).toEqual([1, 2, 3]);
221
+ });
222
+ });
223
+
224
+ describe('deriveProjectStatus', () => {
225
+ it('should return planning when no plans exist', () => {
226
+ fs.rmSync(path.join(projectPath, 'plans'), { recursive: true });
227
+ const status = deriveProjectStatus(projectPath, []);
228
+ expect(status).toBe('planning');
229
+ });
230
+
231
+ it('should return planning when plans directory is empty', () => {
232
+ const status = deriveProjectStatus(projectPath, []);
233
+ expect(status).toBe('planning');
234
+ });
235
+
236
+ it('should return ready when all tasks are pending', () => {
237
+ const tasks = [
238
+ { id: '001', planFile: 'plans/001.md', status: 'pending' as const, dependencies: [] },
239
+ { id: '002', planFile: 'plans/002.md', status: 'pending' as const, dependencies: [] },
240
+ ];
241
+ const status = deriveProjectStatus(projectPath, tasks);
242
+ expect(status).toBe('ready');
243
+ });
244
+
245
+ it('should return executing when some tasks are completed', () => {
246
+ const tasks = [
247
+ { id: '001', planFile: 'plans/001.md', status: 'completed' as const, dependencies: [] },
248
+ { id: '002', planFile: 'plans/002.md', status: 'pending' as const, dependencies: [] },
249
+ ];
250
+ const status = deriveProjectStatus(projectPath, tasks);
251
+ expect(status).toBe('executing');
252
+ });
253
+
254
+ it('should return completed when all tasks are completed', () => {
255
+ const tasks = [
256
+ { id: '001', planFile: 'plans/001.md', status: 'completed' as const, dependencies: [] },
257
+ { id: '002', planFile: 'plans/002.md', status: 'completed' as const, dependencies: [] },
258
+ ];
259
+ const status = deriveProjectStatus(projectPath, tasks);
260
+ expect(status).toBe('completed');
261
+ });
262
+
263
+ it('should return failed when any task has failed', () => {
264
+ const tasks = [
265
+ { id: '001', planFile: 'plans/001.md', status: 'completed' as const, dependencies: [] },
266
+ { id: '002', planFile: 'plans/002.md', status: 'failed' as const, dependencies: [] },
267
+ { id: '003', planFile: 'plans/003.md', status: 'pending' as const, dependencies: [] },
268
+ ];
269
+ const status = deriveProjectStatus(projectPath, tasks);
270
+ expect(status).toBe('failed');
271
+ });
272
+ });
273
+
274
+ describe('deriveProjectState', () => {
275
+ it('should return empty tasks and planning status for empty project', () => {
276
+ const state = deriveProjectState(projectPath);
277
+ expect(state.tasks).toEqual([]);
278
+ expect(state.status).toBe('planning');
279
+ });
280
+
281
+ it('should derive tasks from plan files with ready status', () => {
282
+ fs.writeFileSync(path.join(projectPath, 'plans', '001-first-task.md'), '# Task 1');
283
+ fs.writeFileSync(path.join(projectPath, 'plans', '002-second-task.md'), '# Task 2');
284
+
285
+ const state = deriveProjectState(projectPath);
286
+ expect(state.tasks).toHaveLength(2);
287
+ expect(state.tasks[0]?.id).toBe('001');
288
+ expect(state.tasks[0]?.planFile).toBe('plans/001-first-task.md');
289
+ expect(state.tasks[0]?.status).toBe('pending');
290
+ expect(state.tasks[1]?.id).toBe('002');
291
+ expect(state.status).toBe('ready');
292
+ });
293
+
294
+ it('should match outcome statuses to tasks and derive failed status', () => {
295
+ // Create plan files
296
+ fs.writeFileSync(path.join(projectPath, 'plans', '001-task.md'), '# Task 1');
297
+ fs.writeFileSync(path.join(projectPath, 'plans', '002-task.md'), '# Task 2');
298
+ fs.writeFileSync(path.join(projectPath, 'plans', '003-task.md'), '# Task 3');
299
+
300
+ // Create outcome files with promise markers
301
+ fs.writeFileSync(
302
+ path.join(projectPath, 'outcomes', '001-task.md'),
303
+ '# Task 001 - Completed\n\n<promise>COMPLETE</promise>'
304
+ );
305
+ fs.writeFileSync(
306
+ path.join(projectPath, 'outcomes', '002-task.md'),
307
+ '# Task 002 - Failed\n\n<promise>FAILED</promise>'
308
+ );
309
+
310
+ const state = deriveProjectState(projectPath);
311
+ expect(state.tasks).toHaveLength(3);
312
+ expect(state.tasks[0]?.status).toBe('completed');
313
+ expect(state.tasks[1]?.status).toBe('failed');
314
+ expect(state.tasks[2]?.status).toBe('pending');
315
+ expect(state.status).toBe('failed');
316
+ });
317
+
318
+ it('should derive completed status when all tasks completed', () => {
319
+ fs.writeFileSync(path.join(projectPath, 'plans', '001-task.md'), '# Task 1');
320
+ fs.writeFileSync(path.join(projectPath, 'plans', '002-task.md'), '# Task 2');
321
+ fs.writeFileSync(
322
+ path.join(projectPath, 'outcomes', '001-task.md'),
323
+ '# Task 001 - Completed\n\n<promise>COMPLETE</promise>'
324
+ );
325
+ fs.writeFileSync(
326
+ path.join(projectPath, 'outcomes', '002-task.md'),
327
+ '# Task 002 - Completed\n\n<promise>COMPLETE</promise>'
328
+ );
329
+
330
+ const state = deriveProjectState(projectPath);
331
+ expect(state.status).toBe('completed');
332
+ });
333
+
334
+ it('should derive executing status when some tasks completed', () => {
335
+ fs.writeFileSync(path.join(projectPath, 'plans', '001-task.md'), '# Task 1');
336
+ fs.writeFileSync(path.join(projectPath, 'plans', '002-task.md'), '# Task 2');
337
+ fs.writeFileSync(
338
+ path.join(projectPath, 'outcomes', '001-task.md'),
339
+ '# Task 001 - Completed\n\n<promise>COMPLETE</promise>'
340
+ );
341
+
342
+ const state = deriveProjectState(projectPath);
343
+ expect(state.status).toBe('executing');
344
+ });
345
+
346
+ it('should ignore outcome files without promise marker', () => {
347
+ fs.writeFileSync(path.join(projectPath, 'plans', '001-task.md'), '# Task 1');
348
+ fs.writeFileSync(
349
+ path.join(projectPath, 'outcomes', '001-task.md'),
350
+ '# Task 001 - Completed (no promise marker)'
351
+ );
352
+
353
+ const state = deriveProjectState(projectPath);
354
+ expect(state.tasks[0]?.status).toBe('pending');
355
+ });
356
+
357
+ it('should ignore SUMMARY.md in outcomes', () => {
358
+ fs.writeFileSync(path.join(projectPath, 'plans', '001-task.md'), '# Task 1');
359
+ fs.writeFileSync(path.join(projectPath, 'outcomes', 'SUMMARY.md'), '# Summary');
360
+
361
+ const state = deriveProjectState(projectPath);
362
+ expect(state.tasks).toHaveLength(1);
363
+ expect(state.tasks[0]?.status).toBe('pending');
364
+ });
365
+
366
+ it('should return planning status when no plans directory exists', () => {
367
+ fs.rmSync(path.join(projectPath, 'plans'), { recursive: true });
368
+ const state = deriveProjectState(projectPath);
369
+ expect(state.tasks).toEqual([]);
370
+ expect(state.status).toBe('planning');
371
+ });
372
+
373
+ it('should parse dependencies from plan files', () => {
374
+ fs.writeFileSync(
375
+ path.join(projectPath, 'plans', '001-task.md'),
376
+ '# Task 1\n\n## Dependencies\n\n## Requirements\n'
377
+ );
378
+ fs.writeFileSync(
379
+ path.join(projectPath, 'plans', '002-task.md'),
380
+ '# Task 2\n\n## Dependencies\n001\n\n## Requirements\n'
381
+ );
382
+ fs.writeFileSync(
383
+ path.join(projectPath, 'plans', '003-task.md'),
384
+ '# Task 3\n\n## Dependencies\n001, 002\n\n## Requirements\n'
385
+ );
386
+
387
+ const state = deriveProjectState(projectPath);
388
+ expect(state.tasks[0]?.dependencies).toEqual([]);
389
+ expect(state.tasks[1]?.dependencies).toEqual(['001']);
390
+ expect(state.tasks[2]?.dependencies).toEqual(['001', '002']);
391
+ });
392
+
393
+ it('should derive blocked status when dependency fails', () => {
394
+ // Task 001 has no dependencies
395
+ fs.writeFileSync(
396
+ path.join(projectPath, 'plans', '001-task.md'),
397
+ '# Task 1\n\n## Requirements\n'
398
+ );
399
+ // Task 002 depends on 001
400
+ fs.writeFileSync(
401
+ path.join(projectPath, 'plans', '002-task.md'),
402
+ '# Task 2\n\n## Dependencies\n001\n\n## Requirements\n'
403
+ );
404
+ // Task 001 failed
405
+ fs.writeFileSync(
406
+ path.join(projectPath, 'outcomes', '001-task.md'),
407
+ '<promise>FAILED</promise>'
408
+ );
409
+
410
+ const state = deriveProjectState(projectPath);
411
+ expect(state.tasks[0]?.status).toBe('failed');
412
+ expect(state.tasks[1]?.status).toBe('blocked');
413
+ });
414
+
415
+ it('should derive transitive blocked status', () => {
416
+ // Task 001 has no dependencies
417
+ fs.writeFileSync(
418
+ path.join(projectPath, 'plans', '001-task.md'),
419
+ '# Task 1\n\n## Requirements\n'
420
+ );
421
+ // Task 002 depends on 001
422
+ fs.writeFileSync(
423
+ path.join(projectPath, 'plans', '002-task.md'),
424
+ '# Task 2\n\n## Dependencies\n001\n\n## Requirements\n'
425
+ );
426
+ // Task 003 depends on 002
427
+ fs.writeFileSync(
428
+ path.join(projectPath, 'plans', '003-task.md'),
429
+ '# Task 3\n\n## Dependencies\n002\n\n## Requirements\n'
430
+ );
431
+ // Task 001 failed
432
+ fs.writeFileSync(
433
+ path.join(projectPath, 'outcomes', '001-task.md'),
434
+ '<promise>FAILED</promise>'
435
+ );
436
+
437
+ const state = deriveProjectState(projectPath);
438
+ expect(state.tasks[0]?.status).toBe('failed');
439
+ expect(state.tasks[1]?.status).toBe('blocked');
440
+ expect(state.tasks[2]?.status).toBe('blocked');
441
+ });
442
+
443
+ it('should not block when all dependencies are completed', () => {
444
+ fs.writeFileSync(
445
+ path.join(projectPath, 'plans', '001-task.md'),
446
+ '# Task 1\n\n## Requirements\n'
447
+ );
448
+ fs.writeFileSync(
449
+ path.join(projectPath, 'plans', '002-task.md'),
450
+ '# Task 2\n\n## Dependencies\n001\n\n## Requirements\n'
451
+ );
452
+ fs.writeFileSync(
453
+ path.join(projectPath, 'outcomes', '001-task.md'),
454
+ '<promise>COMPLETE</promise>'
455
+ );
456
+
457
+ const state = deriveProjectState(projectPath);
458
+ expect(state.tasks[0]?.status).toBe('completed');
459
+ expect(state.tasks[1]?.status).toBe('pending');
460
+ });
461
+
462
+ it('should block when any dependency is blocked', () => {
463
+ // 001 fails, 002 depends on 001 (blocked), 003 depends on 002 (blocked)
464
+ fs.writeFileSync(
465
+ path.join(projectPath, 'plans', '001-task.md'),
466
+ '# Task 1\n\n## Requirements\n'
467
+ );
468
+ fs.writeFileSync(
469
+ path.join(projectPath, 'plans', '002-task.md'),
470
+ '# Task 2\n\n## Dependencies\n001\n\n## Requirements\n'
471
+ );
472
+ fs.writeFileSync(
473
+ path.join(projectPath, 'plans', '003-task.md'),
474
+ '# Task 3\n\n## Dependencies\n002\n\n## Requirements\n'
475
+ );
476
+ fs.writeFileSync(
477
+ path.join(projectPath, 'outcomes', '001-task.md'),
478
+ '<promise>FAILED</promise>'
479
+ );
480
+
481
+ const state = deriveProjectState(projectPath);
482
+ expect(state.tasks[2]?.status).toBe('blocked');
483
+ });
484
+
485
+ it('should recognize BLOCKED marker in outcome file', () => {
486
+ fs.writeFileSync(
487
+ path.join(projectPath, 'plans', '001-task.md'),
488
+ '# Task 1\n\n## Requirements\n'
489
+ );
490
+ fs.writeFileSync(
491
+ path.join(projectPath, 'outcomes', '001-task.md'),
492
+ '<promise>BLOCKED</promise>'
493
+ );
494
+
495
+ const state = deriveProjectState(projectPath);
496
+ expect(state.tasks[0]?.status).toBe('blocked');
497
+ });
498
+ });
499
+
500
+ describe('getNextPendingTask', () => {
501
+ it('should return first pending task', () => {
502
+ const state = {
503
+ status: 'executing' as DerivedProjectStatus,
504
+ tasks: [
505
+ { id: '001', planFile: 'plans/001.md', status: 'completed' as const, dependencies: [] },
506
+ { id: '002', planFile: 'plans/002.md', status: 'pending' as const, dependencies: [] },
507
+ { id: '003', planFile: 'plans/003.md', status: 'pending' as const, dependencies: [] },
508
+ ],
509
+ };
510
+ const task = getNextPendingTask(state);
511
+ expect(task?.id).toBe('002');
512
+ });
513
+
514
+ it('should return null when no pending tasks', () => {
515
+ const state = {
516
+ status: 'failed' as DerivedProjectStatus,
517
+ tasks: [
518
+ { id: '001', planFile: 'plans/001.md', status: 'completed' as const, dependencies: [] },
519
+ { id: '002', planFile: 'plans/002.md', status: 'failed' as const, dependencies: [] },
520
+ ],
521
+ };
522
+ const task = getNextPendingTask(state);
523
+ expect(task).toBeNull();
524
+ });
525
+
526
+ it('should skip blocked tasks', () => {
527
+ const state = {
528
+ status: 'failed' as DerivedProjectStatus,
529
+ tasks: [
530
+ { id: '001', planFile: 'plans/001.md', status: 'failed' as const, dependencies: [] },
531
+ { id: '002', planFile: 'plans/002.md', status: 'blocked' as const, dependencies: ['001'] },
532
+ { id: '003', planFile: 'plans/003.md', status: 'pending' as const, dependencies: [] },
533
+ ],
534
+ };
535
+ const task = getNextPendingTask(state);
536
+ expect(task?.id).toBe('003');
537
+ });
538
+ });
539
+
540
+ describe('getNextExecutableTask', () => {
541
+ it('should prefer pending tasks over failed', () => {
542
+ const state = {
543
+ status: 'failed' as DerivedProjectStatus,
544
+ tasks: [
545
+ { id: '001', planFile: 'plans/001.md', status: 'failed' as const, dependencies: [] },
546
+ { id: '002', planFile: 'plans/002.md', status: 'pending' as const, dependencies: [] },
547
+ ],
548
+ };
549
+ const task = getNextExecutableTask(state);
550
+ expect(task?.id).toBe('002');
551
+ });
552
+
553
+ it('should return failed task when no pending', () => {
554
+ const state = {
555
+ status: 'failed' as DerivedProjectStatus,
556
+ tasks: [
557
+ { id: '001', planFile: 'plans/001.md', status: 'completed' as const, dependencies: [] },
558
+ { id: '002', planFile: 'plans/002.md', status: 'failed' as const, dependencies: [] },
559
+ ],
560
+ };
561
+ const task = getNextExecutableTask(state);
562
+ expect(task?.id).toBe('002');
563
+ });
564
+
565
+ it('should skip blocked tasks when looking for pending', () => {
566
+ const state = {
567
+ status: 'failed' as DerivedProjectStatus,
568
+ tasks: [
569
+ { id: '001', planFile: 'plans/001.md', status: 'failed' as const, dependencies: [] },
570
+ { id: '002', planFile: 'plans/002.md', status: 'blocked' as const, dependencies: ['001'] },
571
+ { id: '003', planFile: 'plans/003.md', status: 'pending' as const, dependencies: [] },
572
+ ],
573
+ };
574
+ const task = getNextExecutableTask(state);
575
+ expect(task?.id).toBe('003');
576
+ });
577
+
578
+ it('should return null when only blocked tasks remain', () => {
579
+ const state = {
580
+ status: 'failed' as DerivedProjectStatus,
581
+ tasks: [
582
+ { id: '001', planFile: 'plans/001.md', status: 'completed' as const, dependencies: [] },
583
+ { id: '002', planFile: 'plans/002.md', status: 'blocked' as const, dependencies: ['003'] },
584
+ ],
585
+ };
586
+ const task = getNextExecutableTask(state);
587
+ expect(task).toBeNull();
588
+ });
589
+ });
590
+
591
+ describe('getDerivedStats', () => {
592
+ it('should calculate correct stats', () => {
593
+ const state = {
594
+ status: 'failed' as DerivedProjectStatus,
595
+ tasks: [
596
+ { id: '001', planFile: 'plans/001.md', status: 'completed' as const, dependencies: [] },
597
+ { id: '002', planFile: 'plans/002.md', status: 'failed' as const, dependencies: [] },
598
+ { id: '003', planFile: 'plans/003.md', status: 'pending' as const, dependencies: [] },
599
+ { id: '004', planFile: 'plans/004.md', status: 'pending' as const, dependencies: [] },
600
+ ],
601
+ };
602
+ const stats = getDerivedStats(state);
603
+ expect(stats.completed).toBe(1);
604
+ expect(stats.failed).toBe(1);
605
+ expect(stats.pending).toBe(2);
606
+ expect(stats.blocked).toBe(0);
607
+ expect(stats.total).toBe(4);
608
+ });
609
+
610
+ it('should count blocked tasks', () => {
611
+ const state = {
612
+ status: 'failed' as DerivedProjectStatus,
613
+ tasks: [
614
+ { id: '001', planFile: 'plans/001.md', status: 'failed' as const, dependencies: [] },
615
+ { id: '002', planFile: 'plans/002.md', status: 'blocked' as const, dependencies: ['001'] },
616
+ { id: '003', planFile: 'plans/003.md', status: 'blocked' as const, dependencies: ['002'] },
617
+ { id: '004', planFile: 'plans/004.md', status: 'pending' as const, dependencies: [] },
618
+ ],
619
+ };
620
+ const stats = getDerivedStats(state);
621
+ expect(stats.completed).toBe(0);
622
+ expect(stats.failed).toBe(1);
623
+ expect(stats.pending).toBe(1);
624
+ expect(stats.blocked).toBe(2);
625
+ expect(stats.total).toBe(4);
626
+ });
627
+ });
628
+
629
+ describe('isProjectComplete', () => {
630
+ it('should return true when all tasks completed', () => {
631
+ const state = {
632
+ status: 'completed' as DerivedProjectStatus,
633
+ tasks: [
634
+ { id: '001', planFile: 'plans/001.md', status: 'completed' as const, dependencies: [] },
635
+ { id: '002', planFile: 'plans/002.md', status: 'completed' as const, dependencies: [] },
636
+ ],
637
+ };
638
+ expect(isProjectComplete(state)).toBe(true);
639
+ });
640
+
641
+ it('should return false when some tasks pending', () => {
642
+ const state = {
643
+ status: 'executing' as DerivedProjectStatus,
644
+ tasks: [
645
+ { id: '001', planFile: 'plans/001.md', status: 'completed' as const, dependencies: [] },
646
+ { id: '002', planFile: 'plans/002.md', status: 'pending' as const, dependencies: [] },
647
+ ],
648
+ };
649
+ expect(isProjectComplete(state)).toBe(false);
650
+ });
651
+
652
+ it('should return false when some tasks failed', () => {
653
+ const state = {
654
+ status: 'failed' as DerivedProjectStatus,
655
+ tasks: [
656
+ { id: '001', planFile: 'plans/001.md', status: 'completed' as const, dependencies: [] },
657
+ { id: '002', planFile: 'plans/002.md', status: 'failed' as const, dependencies: [] },
658
+ ],
659
+ };
660
+ expect(isProjectComplete(state)).toBe(false);
661
+ });
662
+
663
+ it('should return false when some tasks blocked', () => {
664
+ const state = {
665
+ status: 'failed' as DerivedProjectStatus,
666
+ tasks: [
667
+ { id: '001', planFile: 'plans/001.md', status: 'completed' as const, dependencies: [] },
668
+ { id: '002', planFile: 'plans/002.md', status: 'blocked' as const, dependencies: ['003'] },
669
+ ],
670
+ };
671
+ expect(isProjectComplete(state)).toBe(false);
672
+ });
673
+
674
+ it('should return true for empty project', () => {
675
+ const state = { status: 'planning' as DerivedProjectStatus, tasks: [] };
676
+ expect(isProjectComplete(state)).toBe(true);
677
+ });
678
+ });
679
+
680
+ describe('hasProjectFailed', () => {
681
+ it('should return true when any task failed', () => {
682
+ const state = {
683
+ status: 'failed' as DerivedProjectStatus,
684
+ tasks: [
685
+ { id: '001', planFile: 'plans/001.md', status: 'completed' as const, dependencies: [] },
686
+ { id: '002', planFile: 'plans/002.md', status: 'failed' as const, dependencies: [] },
687
+ ],
688
+ };
689
+ expect(hasProjectFailed(state)).toBe(true);
690
+ });
691
+
692
+ it('should return false when no tasks failed', () => {
693
+ const state = {
694
+ status: 'executing' as DerivedProjectStatus,
695
+ tasks: [
696
+ { id: '001', planFile: 'plans/001.md', status: 'completed' as const, dependencies: [] },
697
+ { id: '002', planFile: 'plans/002.md', status: 'pending' as const, dependencies: [] },
698
+ ],
699
+ };
700
+ expect(hasProjectFailed(state)).toBe(false);
701
+ });
702
+
703
+ it('should return false when tasks are only blocked (not failed)', () => {
704
+ const state = {
705
+ status: 'failed' as DerivedProjectStatus,
706
+ tasks: [
707
+ { id: '001', planFile: 'plans/001.md', status: 'completed' as const, dependencies: [] },
708
+ { id: '002', planFile: 'plans/002.md', status: 'blocked' as const, dependencies: ['003'] },
709
+ ],
710
+ };
711
+ expect(hasProjectFailed(state)).toBe(false);
712
+ });
713
+ });
714
+ });