agentplane 0.3.9 → 0.3.11

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 (404) hide show
  1. package/assets/AGENTS.md +4 -2
  2. package/assets/agents/CODER.json +1 -1
  3. package/assets/policy/dod.core.md +1 -1
  4. package/assets/policy/governance.md +5 -3
  5. package/assets/policy/incidents.md +19 -77
  6. package/assets/policy/workflow.branch_pr.md +2 -0
  7. package/assets/policy/workflow.direct.md +3 -1
  8. package/bin/agentplane.js +56 -1
  9. package/bin/runtime-watch.js +1 -0
  10. package/bin/stale-dist-policy.d.ts +1 -1
  11. package/bin/stale-dist-policy.js +13 -0
  12. package/dist/.build-manifest.json +462 -202
  13. package/dist/cli/bootstrap-guide.d.ts +1 -0
  14. package/dist/cli/bootstrap-guide.d.ts.map +1 -1
  15. package/dist/cli/bootstrap-guide.js +20 -1
  16. package/dist/cli/command-guide.d.ts.map +1 -1
  17. package/dist/cli/command-guide.js +2 -1
  18. package/dist/cli/command-invocations.d.ts.map +1 -1
  19. package/dist/cli/command-invocations.js +6 -1
  20. package/dist/cli/command-snippets.d.ts +2 -0
  21. package/dist/cli/command-snippets.d.ts.map +1 -1
  22. package/dist/cli/command-snippets.js +2 -0
  23. package/dist/cli/run-cli/command-catalog/core.d.ts +1 -1
  24. package/dist/cli/run-cli/command-catalog/core.d.ts.map +1 -1
  25. package/dist/cli/run-cli/command-catalog/core.js +10 -0
  26. package/dist/cli/run-cli/command-catalog/project.d.ts +1 -1
  27. package/dist/cli/run-cli/command-catalog/project.d.ts.map +1 -1
  28. package/dist/cli/run-cli/command-catalog/project.js +3 -1
  29. package/dist/cli/run-cli/command-catalog/task.d.ts +1 -1
  30. package/dist/cli/run-cli/command-catalog/task.d.ts.map +1 -1
  31. package/dist/cli/run-cli/command-catalog/task.js +10 -0
  32. package/dist/cli/run-cli/command-catalog.d.ts +1 -1
  33. package/dist/cli/run-cli/command-catalog.d.ts.map +1 -1
  34. package/dist/cli/run-cli/commands/config.d.ts.map +1 -1
  35. package/dist/cli/run-cli/commands/config.js +13 -0
  36. package/dist/cli/run-cli/commands/core/preflight.d.ts.map +1 -1
  37. package/dist/cli/run-cli/commands/core/preflight.js +44 -1
  38. package/dist/cli/run-cli.js +2 -2
  39. package/dist/cli/run-cli.test-helpers.d.ts.map +1 -1
  40. package/dist/cli/run-cli.test-helpers.js +12 -0
  41. package/dist/commands/backend.d.ts.map +1 -1
  42. package/dist/commands/backend.js +4 -0
  43. package/dist/commands/branch/cleanup-merged.d.ts +2 -0
  44. package/dist/commands/branch/cleanup-merged.d.ts.map +1 -1
  45. package/dist/commands/branch/cleanup-merged.js +132 -28
  46. package/dist/commands/branch/work-start.d.ts.map +1 -1
  47. package/dist/commands/branch/work-start.js +60 -1
  48. package/dist/commands/cleanup/merged.command.d.ts +2 -0
  49. package/dist/commands/cleanup/merged.command.d.ts.map +1 -1
  50. package/dist/commands/cleanup/merged.command.js +24 -0
  51. package/dist/commands/doctor/branch-pr.d.ts +4 -0
  52. package/dist/commands/doctor/branch-pr.d.ts.map +1 -0
  53. package/dist/commands/doctor/branch-pr.js +96 -0
  54. package/dist/commands/doctor/fixes.d.ts +5 -0
  55. package/dist/commands/doctor/fixes.d.ts.map +1 -1
  56. package/dist/commands/doctor/fixes.js +70 -0
  57. package/dist/commands/doctor.run.d.ts.map +1 -1
  58. package/dist/commands/doctor.run.js +6 -1
  59. package/dist/commands/finish.run.d.ts.map +1 -1
  60. package/dist/commands/finish.run.js +11 -0
  61. package/dist/commands/finish.spec.d.ts +11 -0
  62. package/dist/commands/finish.spec.d.ts.map +1 -1
  63. package/dist/commands/finish.spec.js +51 -0
  64. package/dist/commands/guard/impl/close-message.d.ts.map +1 -1
  65. package/dist/commands/guard/impl/close-message.js +23 -6
  66. package/dist/commands/guard/impl/commands.d.ts.map +1 -1
  67. package/dist/commands/guard/impl/commands.js +24 -2
  68. package/dist/commands/guard/impl/env.d.ts +1 -0
  69. package/dist/commands/guard/impl/env.d.ts.map +1 -1
  70. package/dist/commands/guard/impl/env.js +1 -0
  71. package/dist/commands/hooks/index.d.ts.map +1 -1
  72. package/dist/commands/hooks/index.js +98 -1
  73. package/dist/commands/incidents/advise.command.d.ts +15 -0
  74. package/dist/commands/incidents/advise.command.d.ts.map +1 -0
  75. package/dist/commands/incidents/advise.command.js +139 -0
  76. package/dist/commands/incidents/collect.command.d.ts +11 -0
  77. package/dist/commands/incidents/collect.command.d.ts.map +1 -0
  78. package/dist/commands/incidents/collect.command.js +72 -0
  79. package/dist/commands/incidents/incidents.command.d.ts +5 -0
  80. package/dist/commands/incidents/incidents.command.d.ts.map +1 -0
  81. package/dist/commands/incidents/incidents.command.js +21 -0
  82. package/dist/commands/incidents/shared.d.ts +76 -0
  83. package/dist/commands/incidents/shared.d.ts.map +1 -0
  84. package/dist/commands/incidents/shared.js +261 -0
  85. package/dist/commands/pr/check.d.ts.map +1 -1
  86. package/dist/commands/pr/check.js +249 -75
  87. package/dist/commands/pr/close-superseded.d.ts +9 -0
  88. package/dist/commands/pr/close-superseded.d.ts.map +1 -0
  89. package/dist/commands/pr/close-superseded.js +129 -0
  90. package/dist/commands/pr/close.d.ts +11 -0
  91. package/dist/commands/pr/close.d.ts.map +1 -0
  92. package/dist/commands/pr/close.js +116 -0
  93. package/dist/commands/pr/index.d.ts +2 -0
  94. package/dist/commands/pr/index.d.ts.map +1 -1
  95. package/dist/commands/pr/index.js +2 -0
  96. package/dist/commands/pr/integrate/artifacts.d.ts +7 -0
  97. package/dist/commands/pr/integrate/artifacts.d.ts.map +1 -1
  98. package/dist/commands/pr/integrate/artifacts.js +66 -1
  99. package/dist/commands/pr/integrate/cmd.d.ts.map +1 -1
  100. package/dist/commands/pr/integrate/cmd.js +20 -0
  101. package/dist/commands/pr/integrate/internal/bootstrap-guidance.d.ts +8 -0
  102. package/dist/commands/pr/integrate/internal/bootstrap-guidance.d.ts.map +1 -0
  103. package/dist/commands/pr/integrate/internal/bootstrap-guidance.js +59 -0
  104. package/dist/commands/pr/integrate/internal/finalize.d.ts.map +1 -1
  105. package/dist/commands/pr/integrate/internal/finalize.js +40 -12
  106. package/dist/commands/pr/integrate/internal/merge.d.ts +4 -0
  107. package/dist/commands/pr/integrate/internal/merge.d.ts.map +1 -1
  108. package/dist/commands/pr/integrate/internal/merge.js +59 -15
  109. package/dist/commands/pr/integrate/internal/post-integrate-bootstrap.d.ts +13 -0
  110. package/dist/commands/pr/integrate/internal/post-integrate-bootstrap.d.ts.map +1 -0
  111. package/dist/commands/pr/integrate/internal/post-integrate-bootstrap.js +25 -0
  112. package/dist/commands/pr/integrate/internal/prepare.d.ts +3 -2
  113. package/dist/commands/pr/integrate/internal/prepare.d.ts.map +1 -1
  114. package/dist/commands/pr/integrate/internal/prepare.js +107 -19
  115. package/dist/commands/pr/internal/freshness.d.ts +20 -0
  116. package/dist/commands/pr/internal/freshness.d.ts.map +1 -0
  117. package/dist/commands/pr/internal/freshness.js +50 -0
  118. package/dist/commands/pr/internal/gh-api.d.ts +6 -0
  119. package/dist/commands/pr/internal/gh-api.d.ts.map +1 -0
  120. package/dist/commands/pr/internal/gh-api.js +80 -0
  121. package/dist/commands/pr/internal/note-store.d.ts +18 -0
  122. package/dist/commands/pr/internal/note-store.d.ts.map +1 -0
  123. package/dist/commands/pr/internal/note-store.js +66 -0
  124. package/dist/commands/pr/internal/pr-paths.d.ts +13 -0
  125. package/dist/commands/pr/internal/pr-paths.d.ts.map +1 -1
  126. package/dist/commands/pr/internal/pr-paths.js +13 -0
  127. package/dist/commands/pr/internal/review-template.d.ts +24 -4
  128. package/dist/commands/pr/internal/review-template.d.ts.map +1 -1
  129. package/dist/commands/pr/internal/review-template.js +221 -33
  130. package/dist/commands/pr/internal/sync.d.ts +41 -0
  131. package/dist/commands/pr/internal/sync.d.ts.map +1 -0
  132. package/dist/commands/pr/internal/sync.js +598 -0
  133. package/dist/commands/pr/note.d.ts.map +1 -1
  134. package/dist/commands/pr/note.js +37 -4
  135. package/dist/commands/pr/open.d.ts +1 -0
  136. package/dist/commands/pr/open.d.ts.map +1 -1
  137. package/dist/commands/pr/open.js +18 -54
  138. package/dist/commands/pr/pr.command.d.ts +15 -0
  139. package/dist/commands/pr/pr.command.d.ts.map +1 -1
  140. package/dist/commands/pr/pr.command.js +124 -5
  141. package/dist/commands/pr/update.d.ts.map +1 -1
  142. package/dist/commands/pr/update.js +58 -74
  143. package/dist/commands/recipes/impl/commands/cache-prune.d.ts.map +1 -1
  144. package/dist/commands/recipes/impl/commands/cache-prune.js +14 -0
  145. package/dist/commands/recipes/impl/commands/install.js +1 -1
  146. package/dist/commands/recipes/impl/commands/list-remote.d.ts.map +1 -1
  147. package/dist/commands/recipes/impl/commands/list-remote.js +1 -0
  148. package/dist/commands/recipes/impl/commands/remove.d.ts.map +1 -1
  149. package/dist/commands/recipes/impl/commands/remove.js +9 -1
  150. package/dist/commands/release/apply.command.d.ts.map +1 -1
  151. package/dist/commands/release/apply.command.js +12 -17
  152. package/dist/commands/release/apply.preflight.d.ts.map +1 -1
  153. package/dist/commands/release/apply.preflight.js +1 -1
  154. package/dist/commands/shared/approval-requirements.d.ts +5 -7
  155. package/dist/commands/shared/approval-requirements.d.ts.map +1 -1
  156. package/dist/commands/shared/approval-requirements.js +3 -73
  157. package/dist/commands/shared/gh-transport.d.ts +16 -0
  158. package/dist/commands/shared/gh-transport.d.ts.map +1 -0
  159. package/dist/commands/shared/gh-transport.js +71 -0
  160. package/dist/commands/shared/git-diff.d.ts +3 -1
  161. package/dist/commands/shared/git-diff.d.ts.map +1 -1
  162. package/dist/commands/shared/git-diff.js +10 -2
  163. package/dist/commands/shared/git-ops.d.ts +1 -0
  164. package/dist/commands/shared/git-ops.d.ts.map +1 -1
  165. package/dist/commands/shared/git-ops.js +15 -0
  166. package/dist/commands/shared/git-worktree.d.ts +2 -0
  167. package/dist/commands/shared/git-worktree.d.ts.map +1 -1
  168. package/dist/commands/shared/git-worktree.js +22 -2
  169. package/dist/commands/shared/network-approval.d.ts +2 -0
  170. package/dist/commands/shared/network-approval.d.ts.map +1 -1
  171. package/dist/commands/shared/network-approval.js +1 -1
  172. package/dist/commands/shared/post-commit-pr-artifacts.d.ts +9 -0
  173. package/dist/commands/shared/post-commit-pr-artifacts.d.ts.map +1 -0
  174. package/dist/commands/shared/post-commit-pr-artifacts.js +22 -0
  175. package/dist/commands/shared/pr-meta.d.ts +29 -0
  176. package/dist/commands/shared/pr-meta.d.ts.map +1 -1
  177. package/dist/commands/shared/pr-meta.js +152 -3
  178. package/dist/commands/shared/task-backend.d.ts +9 -0
  179. package/dist/commands/shared/task-backend.d.ts.map +1 -1
  180. package/dist/commands/shared/task-backend.js +34 -22
  181. package/dist/commands/shared/task-local-freshness.d.ts +13 -0
  182. package/dist/commands/shared/task-local-freshness.d.ts.map +1 -0
  183. package/dist/commands/shared/task-local-freshness.js +20 -0
  184. package/dist/commands/shared/task-mutation.d.ts +2 -0
  185. package/dist/commands/shared/task-mutation.d.ts.map +1 -1
  186. package/dist/commands/shared/task-mutation.js +7 -0
  187. package/dist/commands/task/block.d.ts.map +1 -1
  188. package/dist/commands/task/block.js +1 -0
  189. package/dist/commands/task/close-duplicate.d.ts.map +1 -1
  190. package/dist/commands/task/close-duplicate.js +34 -1
  191. package/dist/commands/task/close-shared.d.ts.map +1 -1
  192. package/dist/commands/task/close-shared.js +1 -0
  193. package/dist/commands/task/derive.js +1 -1
  194. package/dist/commands/task/doc-template.d.ts.map +1 -1
  195. package/dist/commands/task/doc-template.js +7 -11
  196. package/dist/commands/task/findings-add.command.d.ts +20 -0
  197. package/dist/commands/task/findings-add.command.d.ts.map +1 -0
  198. package/dist/commands/task/findings-add.command.js +165 -0
  199. package/dist/commands/task/findings.command.d.ts +7 -0
  200. package/dist/commands/task/findings.command.d.ts.map +1 -0
  201. package/dist/commands/task/findings.command.js +20 -0
  202. package/dist/commands/task/findings.d.ts +63 -0
  203. package/dist/commands/task/findings.d.ts.map +1 -0
  204. package/dist/commands/task/findings.js +188 -0
  205. package/dist/commands/task/finish-shared.d.ts +1 -0
  206. package/dist/commands/task/finish-shared.d.ts.map +1 -1
  207. package/dist/commands/task/finish-shared.js +60 -3
  208. package/dist/commands/task/finish.d.ts +10 -0
  209. package/dist/commands/task/finish.d.ts.map +1 -1
  210. package/dist/commands/task/finish.js +143 -0
  211. package/dist/commands/task/hosted-close-pr.command.d.ts +11 -0
  212. package/dist/commands/task/hosted-close-pr.command.d.ts.map +1 -0
  213. package/dist/commands/task/hosted-close-pr.command.js +414 -0
  214. package/dist/commands/task/hosted-close.command.d.ts.map +1 -1
  215. package/dist/commands/task/hosted-close.command.js +49 -1
  216. package/dist/commands/task/hosted-merge-sync.d.ts +38 -0
  217. package/dist/commands/task/hosted-merge-sync.d.ts.map +1 -1
  218. package/dist/commands/task/hosted-merge-sync.js +249 -17
  219. package/dist/commands/task/index.d.ts +1 -0
  220. package/dist/commands/task/index.d.ts.map +1 -1
  221. package/dist/commands/task/index.js +1 -0
  222. package/dist/commands/task/new.d.ts +1 -0
  223. package/dist/commands/task/new.d.ts.map +1 -1
  224. package/dist/commands/task/new.js +140 -30
  225. package/dist/commands/task/new.spec.d.ts.map +1 -1
  226. package/dist/commands/task/new.spec.js +7 -0
  227. package/dist/commands/task/normalize.command.d.ts +2 -0
  228. package/dist/commands/task/normalize.command.d.ts.map +1 -1
  229. package/dist/commands/task/normalize.command.js +45 -0
  230. package/dist/commands/task/normalize.d.ts +2 -0
  231. package/dist/commands/task/normalize.d.ts.map +1 -1
  232. package/dist/commands/task/normalize.js +85 -8
  233. package/dist/commands/task/plan.d.ts.map +1 -1
  234. package/dist/commands/task/plan.js +7 -10
  235. package/dist/commands/task/set-status.d.ts.map +1 -1
  236. package/dist/commands/task/set-status.js +1 -0
  237. package/dist/commands/task/shared/docs.d.ts +6 -0
  238. package/dist/commands/task/shared/docs.d.ts.map +1 -1
  239. package/dist/commands/task/shared/docs.js +14 -0
  240. package/dist/commands/task/shared/transition-command.d.ts +2 -0
  241. package/dist/commands/task/shared/transition-command.d.ts.map +1 -1
  242. package/dist/commands/task/shared/transition-command.js +1 -0
  243. package/dist/commands/task/shared/transitions.d.ts.map +1 -1
  244. package/dist/commands/task/shared/transitions.js +11 -1
  245. package/dist/commands/task/shared.d.ts +1 -1
  246. package/dist/commands/task/shared.d.ts.map +1 -1
  247. package/dist/commands/task/shared.js +1 -1
  248. package/dist/commands/task/start-ready.d.ts.map +1 -1
  249. package/dist/commands/task/start-ready.js +98 -1
  250. package/dist/commands/task/start.d.ts.map +1 -1
  251. package/dist/commands/task/start.js +18 -10
  252. package/dist/commands/task/task.command.d.ts.map +1 -1
  253. package/dist/commands/task/task.command.js +4 -0
  254. package/dist/commands/task/verify-command-shared.d.ts +19 -0
  255. package/dist/commands/task/verify-command-shared.d.ts.map +1 -1
  256. package/dist/commands/task/verify-command-shared.js +152 -1
  257. package/dist/commands/task/verify-ok.command.d.ts.map +1 -1
  258. package/dist/commands/task/verify-ok.command.js +15 -2
  259. package/dist/commands/task/verify-record.d.ts +36 -0
  260. package/dist/commands/task/verify-record.d.ts.map +1 -1
  261. package/dist/commands/task/verify-record.js +193 -11
  262. package/dist/commands/task/verify-rework.command.d.ts.map +1 -1
  263. package/dist/commands/task/verify-rework.command.js +15 -2
  264. package/dist/commands/task/verify-show.command.d.ts +1 -1
  265. package/dist/commands/task/verify-show.command.d.ts.map +1 -1
  266. package/dist/commands/task/verify-show.command.js +28 -1
  267. package/dist/commands/upgrade.d.ts.map +1 -1
  268. package/dist/commands/upgrade.js +6 -1
  269. package/dist/commands/verify.run.d.ts.map +1 -1
  270. package/dist/commands/verify.run.js +12 -0
  271. package/dist/commands/verify.spec.d.ts +2 -6
  272. package/dist/commands/verify.spec.d.ts.map +1 -1
  273. package/dist/commands/verify.spec.js +30 -3
  274. package/dist/policy/engine.d.ts +3 -1
  275. package/dist/policy/engine.d.ts.map +1 -1
  276. package/dist/policy/engine.js +5 -6
  277. package/dist/policy/taxonomy.d.ts +17 -0
  278. package/dist/policy/taxonomy.d.ts.map +1 -0
  279. package/dist/policy/taxonomy.js +302 -0
  280. package/dist/policy/types.d.ts +2 -1
  281. package/dist/policy/types.d.ts.map +1 -1
  282. package/dist/runner/artifacts.d.ts.map +1 -1
  283. package/dist/runner/artifacts.js +2 -0
  284. package/dist/runner/context/base-prompts.d.ts +25 -0
  285. package/dist/runner/context/base-prompts.d.ts.map +1 -1
  286. package/dist/runner/context/base-prompts.js +182 -54
  287. package/dist/runner/context/recipe-context.d.ts.map +1 -1
  288. package/dist/runner/context/recipe-context.js +5 -0
  289. package/dist/runner/types.d.ts +12 -0
  290. package/dist/runner/types.d.ts.map +1 -1
  291. package/dist/runner/usecases/scenario-materialize-task.d.ts.map +1 -1
  292. package/dist/runner/usecases/scenario-materialize-task.js +81 -11
  293. package/dist/runner/usecases/task-run-inspect.d.ts.map +1 -1
  294. package/dist/runner/usecases/task-run-inspect.js +9 -7
  295. package/dist/runner/usecases/task-run-lifecycle-shared.d.ts.map +1 -1
  296. package/dist/runner/usecases/task-run-lifecycle-shared.js +8 -6
  297. package/dist/runner/usecases/task-run.d.ts.map +1 -1
  298. package/dist/runner/usecases/task-run.js +59 -12
  299. package/dist/runtime/approvals/index.d.ts +3 -0
  300. package/dist/runtime/approvals/index.d.ts.map +1 -0
  301. package/dist/runtime/approvals/index.js +1 -0
  302. package/dist/runtime/approvals/runtime.d.ts +12 -0
  303. package/dist/runtime/approvals/runtime.d.ts.map +1 -0
  304. package/dist/runtime/approvals/runtime.js +154 -0
  305. package/dist/runtime/approvals/types.d.ts +31 -0
  306. package/dist/runtime/approvals/types.d.ts.map +1 -0
  307. package/dist/runtime/approvals/types.js +1 -0
  308. package/dist/runtime/behavior/index.d.ts +3 -0
  309. package/dist/runtime/behavior/index.d.ts.map +1 -0
  310. package/dist/runtime/behavior/index.js +1 -0
  311. package/dist/runtime/behavior/resolve.d.ts +7 -0
  312. package/dist/runtime/behavior/resolve.d.ts.map +1 -0
  313. package/dist/runtime/behavior/resolve.js +66 -0
  314. package/dist/runtime/behavior/types.d.ts +25 -0
  315. package/dist/runtime/behavior/types.d.ts.map +1 -0
  316. package/dist/runtime/behavior/types.js +1 -0
  317. package/dist/runtime/capabilities/backend.d.ts +7 -0
  318. package/dist/runtime/capabilities/backend.d.ts.map +1 -0
  319. package/dist/runtime/capabilities/backend.js +104 -0
  320. package/dist/runtime/capabilities/index.d.ts +6 -0
  321. package/dist/runtime/capabilities/index.d.ts.map +1 -0
  322. package/dist/runtime/capabilities/index.js +4 -0
  323. package/dist/runtime/capabilities/recipe.d.ts +10 -0
  324. package/dist/runtime/capabilities/recipe.d.ts.map +1 -0
  325. package/dist/runtime/capabilities/recipe.js +123 -0
  326. package/dist/runtime/capabilities/registry.d.ts +6 -0
  327. package/dist/runtime/capabilities/registry.d.ts.map +1 -0
  328. package/dist/runtime/capabilities/registry.js +69 -0
  329. package/dist/runtime/capabilities/runner.d.ts +8 -0
  330. package/dist/runtime/capabilities/runner.d.ts.map +1 -0
  331. package/dist/runtime/capabilities/runner.js +73 -0
  332. package/dist/runtime/capabilities/types.d.ts +28 -0
  333. package/dist/runtime/capabilities/types.d.ts.map +1 -0
  334. package/dist/runtime/capabilities/types.js +1 -0
  335. package/dist/runtime/execution-profile/index.d.ts +3 -0
  336. package/dist/runtime/execution-profile/index.d.ts.map +1 -0
  337. package/dist/runtime/execution-profile/index.js +1 -0
  338. package/dist/runtime/execution-profile/resolve.d.ts +9 -0
  339. package/dist/runtime/execution-profile/resolve.d.ts.map +1 -0
  340. package/dist/runtime/execution-profile/resolve.js +80 -0
  341. package/dist/runtime/execution-profile/types.d.ts +27 -0
  342. package/dist/runtime/execution-profile/types.d.ts.map +1 -0
  343. package/dist/runtime/execution-profile/types.js +1 -0
  344. package/dist/runtime/explain/index.d.ts +3 -0
  345. package/dist/runtime/explain/index.d.ts.map +1 -0
  346. package/dist/runtime/explain/index.js +1 -0
  347. package/dist/runtime/explain/resolve.d.ts +14 -0
  348. package/dist/runtime/explain/resolve.d.ts.map +1 -0
  349. package/dist/runtime/explain/resolve.js +50 -0
  350. package/dist/runtime/explain/types.d.ts +28 -0
  351. package/dist/runtime/explain/types.d.ts.map +1 -0
  352. package/dist/runtime/explain/types.js +1 -0
  353. package/dist/runtime/harness/index.d.ts +4 -0
  354. package/dist/runtime/harness/index.d.ts.map +1 -0
  355. package/dist/runtime/harness/index.js +2 -0
  356. package/dist/runtime/harness/resolve-from-command-context.d.ts +4 -0
  357. package/dist/runtime/harness/resolve-from-command-context.d.ts.map +1 -0
  358. package/dist/runtime/harness/resolve-from-command-context.js +11 -0
  359. package/dist/runtime/harness/resolve.d.ts +13 -0
  360. package/dist/runtime/harness/resolve.d.ts.map +1 -0
  361. package/dist/runtime/harness/resolve.js +146 -0
  362. package/dist/runtime/harness/types.d.ts +65 -0
  363. package/dist/runtime/harness/types.d.ts.map +1 -0
  364. package/dist/runtime/harness/types.js +1 -0
  365. package/dist/runtime/incidents/index.d.ts +3 -0
  366. package/dist/runtime/incidents/index.d.ts.map +1 -0
  367. package/dist/runtime/incidents/index.js +1 -0
  368. package/dist/runtime/incidents/resolve.d.ts +26 -0
  369. package/dist/runtime/incidents/resolve.d.ts.map +1 -0
  370. package/dist/runtime/incidents/resolve.js +683 -0
  371. package/dist/runtime/incidents/types.d.ts +84 -0
  372. package/dist/runtime/incidents/types.d.ts.map +1 -0
  373. package/dist/runtime/incidents/types.js +1 -0
  374. package/dist/runtime/protocol/index.d.ts +3 -0
  375. package/dist/runtime/protocol/index.d.ts.map +1 -0
  376. package/dist/runtime/protocol/index.js +2 -0
  377. package/dist/runtime/protocol/resolve.d.ts +16 -0
  378. package/dist/runtime/protocol/resolve.d.ts.map +1 -0
  379. package/dist/runtime/protocol/resolve.js +36 -0
  380. package/dist/runtime/protocol/types.d.ts +36 -0
  381. package/dist/runtime/protocol/types.d.ts.map +1 -0
  382. package/dist/runtime/protocol/types.js +1 -0
  383. package/dist/runtime/task-intake/index.d.ts +3 -0
  384. package/dist/runtime/task-intake/index.d.ts.map +1 -0
  385. package/dist/runtime/task-intake/index.js +1 -0
  386. package/dist/runtime/task-intake/resolve.d.ts +48 -0
  387. package/dist/runtime/task-intake/resolve.d.ts.map +1 -0
  388. package/dist/runtime/task-intake/resolve.js +316 -0
  389. package/dist/runtime/task-intake/types.d.ts +117 -0
  390. package/dist/runtime/task-intake/types.d.ts.map +1 -0
  391. package/dist/runtime/task-intake/types.js +1 -0
  392. package/dist/shared/env.d.ts +1 -0
  393. package/dist/shared/env.d.ts.map +1 -1
  394. package/dist/shared/env.js +22 -1
  395. package/dist/shared/protected-paths.d.ts +4 -0
  396. package/dist/shared/protected-paths.d.ts.map +1 -1
  397. package/dist/shared/protected-paths.js +8 -4
  398. package/dist/usecases/context/resolve-context.d.ts +55 -6
  399. package/dist/usecases/context/resolve-context.d.ts.map +1 -1
  400. package/dist/usecases/context/resolve-context.js +96 -6
  401. package/dist/usecases/task/task-list-usecase.d.ts.map +1 -1
  402. package/dist/usecases/task/task-list-usecase.js +8 -2
  403. package/dist/usecases/task/task-new-usecase.js +4 -4
  404. package/package.json +2 -2
@@ -6,10 +6,16 @@ import { fileExists } from "../../cli/fs-utils.js";
6
6
  import { createCliEmitter, workflowModeMessage } from "../../cli/output.js";
7
7
  import { CliError } from "../../shared/errors.js";
8
8
  import { parsePrMeta } from "../shared/pr-meta.js";
9
- import { gitListTaskBranches, parseTaskIdFromBranch } from "../shared/git-worktree.js";
9
+ import { findWorktreeForBranch, gitListTaskBranches, parseTaskIdFromBranch, } from "../shared/git-worktree.js";
10
+ import { gitRevParse } from "../shared/git-ops.js";
10
11
  import { loadBackendTask, loadCommandContext, } from "../shared/task-backend.js";
11
- import { readPrArtifact, resolvePrPaths } from "./internal/pr-paths.js";
12
- import { validateReviewContents } from "./internal/review-template.js";
12
+ import { readPrArtifactFromBranch, resolvePrPaths } from "./internal/pr-paths.js";
13
+ import { validateGithubPrBodyContents, validateReviewContents, } from "./internal/review-template.js";
14
+ import { assessPrArtifactFreshness } from "./internal/freshness.js";
15
+ function isUnknownRevisionError(err) {
16
+ const message = err instanceof Error ? err.message : String(err);
17
+ return /unknown revision or path not in the working tree/i.test(message);
18
+ }
13
19
  async function resolveArtifactBranch(opts) {
14
20
  const prefix = opts.ctx.config.branch.task_prefix;
15
21
  const branches = await gitListTaskBranches(opts.resolved.gitRoot, prefix);
@@ -25,26 +31,101 @@ async function resolveArtifactBranch(opts) {
25
31
  }
26
32
  return null;
27
33
  }
28
- async function readPrArtifactWithOptionalBranch(opts) {
29
- const localPath = path.join(opts.prDir, opts.fileName);
30
- if (await fileExists(localPath)) {
31
- return await readFile(localPath, "utf8");
34
+ async function readLocalPrArtifactText(prDir, fileName) {
35
+ const localPath = path.join(prDir, fileName);
36
+ if (!(await fileExists(localPath)))
37
+ return null;
38
+ return await readFile(localPath, "utf8");
39
+ }
40
+ function validateSnapshotContents(opts) {
41
+ const errors = [];
42
+ let meta = null;
43
+ if (opts.texts.metaText) {
44
+ try {
45
+ meta = parsePrMeta(opts.texts.metaText, opts.taskId);
46
+ }
47
+ catch (err) {
48
+ const message = err instanceof Error ? err.message : String(err);
49
+ errors.push(message);
50
+ }
32
51
  }
33
- if (opts.branchCache.value === undefined) {
34
- opts.branchCache.value = await resolveArtifactBranch({
35
- ctx: opts.ctx,
36
- resolved: opts.resolved,
37
- taskId: opts.taskId,
38
- });
52
+ else {
53
+ errors.push(`Missing PR directory: ${opts.relPrDir}`, `Missing ${opts.relMetaPath}`);
39
54
  }
40
- if (!opts.branchCache.value)
41
- return null;
42
- return await readPrArtifact({
43
- resolved: opts.resolved,
44
- prDir: opts.prDir,
45
- fileName: opts.fileName,
46
- branch: opts.branchCache.value,
55
+ if (opts.texts.diffstatText === null)
56
+ errors.push(`Missing ${opts.relDiffstatPath}`);
57
+ if (opts.texts.verifyLogText === null)
58
+ errors.push(`Missing ${opts.relVerifyLogPath}`);
59
+ if (opts.texts.reviewText) {
60
+ validateReviewContents(opts.texts.reviewText, errors);
61
+ }
62
+ else {
63
+ errors.push(`Missing ${opts.relReviewPath}`);
64
+ }
65
+ if (!opts.texts.githubTitleText?.trim()) {
66
+ errors.push(`Missing ${opts.relGithubTitlePath}`);
67
+ }
68
+ if (opts.texts.githubBodyText) {
69
+ validateGithubPrBodyContents(opts.texts.githubBodyText, errors);
70
+ }
71
+ else {
72
+ errors.push(`Missing ${opts.relGithubBodyPath}`);
73
+ }
74
+ return { meta, errors };
75
+ }
76
+ async function evaluateSnapshotFreshness(opts) {
77
+ if (!opts.snapshot.meta || !opts.branchHeadSha)
78
+ return;
79
+ const freshness = await assessPrArtifactFreshness({
80
+ gitRoot: opts.gitRoot,
81
+ workflowDir: opts.workflowDir,
82
+ taskId: opts.taskId,
83
+ branchHeadSha: opts.branchHeadSha,
84
+ metaHeadSha: opts.snapshot.meta.head_sha ?? null,
85
+ metaLastVerifiedSha: opts.snapshot.meta.last_verified_sha ?? null,
86
+ metaVerifyStatus: opts.snapshot.meta.verify?.status ?? null,
87
+ taskVerificationState: opts.taskVerificationState,
88
+ verifyLogText: opts.snapshot.texts.verifyLogText,
89
+ requiresVerify: opts.requiresVerify,
47
90
  });
91
+ opts.snapshot.freshnessEvaluated = true;
92
+ opts.snapshot.freshnessReviewFresh = freshness.reviewFresh;
93
+ opts.snapshot.freshnessVerifySatisfied = freshness.verifySatisfied;
94
+ opts.snapshot.freshnessVerifyFresh = freshness.verifyFresh;
95
+ opts.snapshot.freshnessVerifyLogSha = freshness.verifyLogSha;
96
+ }
97
+ function finalizeSnapshotErrors(opts) {
98
+ const errors = [...opts.snapshot.errors];
99
+ const meta = opts.snapshot.meta;
100
+ if (!meta)
101
+ return errors;
102
+ if (opts.branchHeadSha && opts.snapshot.freshnessEvaluated) {
103
+ if (!opts.snapshot.freshnessReviewFresh) {
104
+ errors.push(`PR artifacts stale: head_sha=${meta.head_sha ?? "<missing>"} current_head=${opts.branchHeadSha}`);
105
+ }
106
+ if (opts.requiresVerify && !opts.snapshot.freshnessVerifySatisfied) {
107
+ if (meta.verify?.status !== "pass") {
108
+ errors.push("Verify requirements not satisfied (meta.verify.status != pass)");
109
+ }
110
+ if ((!meta.last_verified_sha || !meta.last_verified_at) &&
111
+ !opts.snapshot.freshnessVerifyLogSha) {
112
+ errors.push("Verify metadata missing (last_verified_sha/last_verified_at)");
113
+ }
114
+ }
115
+ if (opts.requiresVerify && meta.last_verified_sha && !opts.snapshot.freshnessVerifyFresh) {
116
+ errors.push(`Verify state stale: last_verified_sha=${meta.last_verified_sha} current_head=${opts.branchHeadSha}`);
117
+ }
118
+ return errors;
119
+ }
120
+ if (opts.requiresVerify) {
121
+ if (meta.verify?.status !== "pass") {
122
+ errors.push("Verify requirements not satisfied (meta.verify.status != pass)");
123
+ }
124
+ if (!meta.last_verified_sha || !meta.last_verified_at) {
125
+ errors.push("Verify metadata missing (last_verified_sha/last_verified_at)");
126
+ }
127
+ }
128
+ return errors;
48
129
  }
49
130
  export async function cmdPrCheck(opts) {
50
131
  try {
@@ -57,7 +138,7 @@ export async function cmdPrCheck(opts) {
57
138
  rootOverride: opts.rootOverride,
58
139
  taskId: opts.taskId,
59
140
  });
60
- const { resolved, config, prDir, metaPath, diffstatPath, verifyLogPath, reviewPath } = await resolvePrPaths({ ...opts, ctx });
141
+ const { resolved, config, prDir, metaPath, diffstatPath, verifyLogPath, reviewPath, githubTitlePath, githubBodyPath, } = await resolvePrPaths({ ...opts, ctx });
61
142
  if (config.workflow_mode !== "branch_pr") {
62
143
  throw new CliError({
63
144
  exitCode: exitCodeForError("E_USAGE"),
@@ -71,72 +152,165 @@ export async function cmdPrCheck(opts) {
71
152
  const relDiffstatPath = path.relative(resolved.gitRoot, diffstatPath);
72
153
  const relVerifyLogPath = path.relative(resolved.gitRoot, verifyLogPath);
73
154
  const relReviewPath = path.relative(resolved.gitRoot, reviewPath);
155
+ const relGithubTitlePath = path.relative(resolved.gitRoot, githubTitlePath);
156
+ const relGithubBodyPath = path.relative(resolved.gitRoot, githubBodyPath);
74
157
  const branchCache = {};
75
- let meta = null;
76
- const metaText = await readPrArtifactWithOptionalBranch({
77
- ctx,
78
- resolved,
79
- prDir,
80
- fileName: "meta.json",
158
+ const requiresVerify = Boolean(task.verify && task.verify.length > 0);
159
+ const localTexts = {
160
+ metaText: await readLocalPrArtifactText(prDir, "meta.json"),
161
+ diffstatText: await readLocalPrArtifactText(prDir, "diffstat.txt"),
162
+ verifyLogText: await readLocalPrArtifactText(prDir, "verify.log"),
163
+ reviewText: await readLocalPrArtifactText(prDir, "review.md"),
164
+ githubTitleText: await readLocalPrArtifactText(prDir, "github-title.txt"),
165
+ githubBodyText: await readLocalPrArtifactText(prDir, "github-body.md"),
166
+ };
167
+ const localParsed = validateSnapshotContents({
168
+ texts: localTexts,
169
+ relPrDir,
170
+ relMetaPath,
171
+ relDiffstatPath,
172
+ relVerifyLogPath,
173
+ relReviewPath,
174
+ relGithubTitlePath,
175
+ relGithubBodyPath,
81
176
  taskId: task.id,
82
- branchCache,
83
177
  });
84
- if (metaText) {
178
+ const localSnapshot = {
179
+ source: "local",
180
+ texts: localTexts,
181
+ meta: localParsed.meta,
182
+ errors: localParsed.errors,
183
+ freshnessEvaluated: false,
184
+ freshnessReviewFresh: false,
185
+ freshnessVerifySatisfied: false,
186
+ freshnessVerifyFresh: false,
187
+ freshnessVerifyLogSha: null,
188
+ };
189
+ const localBranch = localSnapshot.meta?.branch?.trim() ?? "";
190
+ if (localBranch) {
191
+ branchCache.value = localBranch;
192
+ }
193
+ else if (branchCache.value === undefined) {
194
+ branchCache.value = await resolveArtifactBranch({
195
+ ctx,
196
+ resolved,
197
+ taskId: task.id,
198
+ });
199
+ }
200
+ const branchForFreshness = branchCache.value ?? null;
201
+ let branchHeadSha = null;
202
+ if (branchForFreshness) {
85
203
  try {
86
- meta = parsePrMeta(metaText, task.id);
204
+ branchHeadSha = await gitRevParse(resolved.gitRoot, [branchForFreshness]);
87
205
  }
88
206
  catch (err) {
89
- const message = err instanceof Error ? err.message : String(err);
90
- errors.push(message);
207
+ if (!isUnknownRevisionError(err))
208
+ throw err;
91
209
  }
92
210
  }
93
- else {
94
- errors.push(`Missing PR directory: ${relPrDir}`, `Missing ${relMetaPath}`);
95
- }
96
- const diffstatText = await readPrArtifactWithOptionalBranch({
97
- ctx,
98
- resolved,
99
- prDir,
100
- fileName: "diffstat.txt",
101
- taskId: task.id,
102
- branchCache,
103
- });
104
- if (diffstatText === null) {
105
- errors.push(`Missing ${relDiffstatPath}`);
106
- }
107
- const verifyLogText = await readPrArtifactWithOptionalBranch({
108
- ctx,
109
- resolved,
110
- prDir,
111
- fileName: "verify.log",
211
+ await evaluateSnapshotFreshness({
212
+ snapshot: localSnapshot,
213
+ gitRoot: resolved.gitRoot,
214
+ workflowDir: config.paths.workflow_dir,
112
215
  taskId: task.id,
113
- branchCache,
216
+ branchHeadSha,
217
+ taskVerificationState: task.verification?.state ?? null,
218
+ requiresVerify,
114
219
  });
115
- if (verifyLogText === null) {
116
- errors.push(`Missing ${relVerifyLogPath}`);
117
- }
118
- const reviewText = await readPrArtifactWithOptionalBranch({
119
- ctx,
120
- resolved,
121
- prDir,
122
- fileName: "review.md",
123
- taskId: task.id,
124
- branchCache,
125
- });
126
- if (reviewText) {
127
- validateReviewContents(reviewText, errors);
128
- }
129
- else {
130
- errors.push(`Missing ${relReviewPath}`);
131
- }
132
- if (task.verify && task.verify.length > 0) {
133
- if (meta?.verify?.status !== "pass") {
134
- errors.push("Verify requirements not satisfied (meta.verify.status != pass)");
135
- }
136
- if (!meta?.last_verified_sha || !meta.last_verified_at) {
137
- errors.push("Verify metadata missing (last_verified_sha/last_verified_at)");
220
+ let selectedSnapshot = localSnapshot;
221
+ if (branchForFreshness &&
222
+ branchHeadSha &&
223
+ (!localSnapshot.meta ||
224
+ !localSnapshot.freshnessReviewFresh ||
225
+ (requiresVerify && !localSnapshot.freshnessVerifySatisfied))) {
226
+ const worktreePath = await findWorktreeForBranch(resolved.gitRoot, branchForFreshness);
227
+ const branchTexts = {
228
+ metaText: await readPrArtifactFromBranch({
229
+ resolved,
230
+ prDir,
231
+ fileName: "meta.json",
232
+ branch: branchForFreshness,
233
+ worktreePath,
234
+ }),
235
+ diffstatText: await readPrArtifactFromBranch({
236
+ resolved,
237
+ prDir,
238
+ fileName: "diffstat.txt",
239
+ branch: branchForFreshness,
240
+ worktreePath,
241
+ }),
242
+ verifyLogText: await readPrArtifactFromBranch({
243
+ resolved,
244
+ prDir,
245
+ fileName: "verify.log",
246
+ branch: branchForFreshness,
247
+ worktreePath,
248
+ }),
249
+ reviewText: await readPrArtifactFromBranch({
250
+ resolved,
251
+ prDir,
252
+ fileName: "review.md",
253
+ branch: branchForFreshness,
254
+ worktreePath,
255
+ }),
256
+ githubTitleText: await readPrArtifactFromBranch({
257
+ resolved,
258
+ prDir,
259
+ fileName: "github-title.txt",
260
+ branch: branchForFreshness,
261
+ worktreePath,
262
+ }),
263
+ githubBodyText: await readPrArtifactFromBranch({
264
+ resolved,
265
+ prDir,
266
+ fileName: "github-body.md",
267
+ branch: branchForFreshness,
268
+ worktreePath,
269
+ }),
270
+ };
271
+ const branchParsed = validateSnapshotContents({
272
+ texts: branchTexts,
273
+ relPrDir,
274
+ relMetaPath,
275
+ relDiffstatPath,
276
+ relVerifyLogPath,
277
+ relReviewPath,
278
+ relGithubTitlePath,
279
+ relGithubBodyPath,
280
+ taskId: task.id,
281
+ });
282
+ const branchSnapshot = {
283
+ source: "branch",
284
+ texts: branchTexts,
285
+ meta: branchParsed.meta,
286
+ errors: branchParsed.errors,
287
+ freshnessEvaluated: false,
288
+ freshnessReviewFresh: false,
289
+ freshnessVerifySatisfied: false,
290
+ freshnessVerifyFresh: false,
291
+ freshnessVerifyLogSha: null,
292
+ };
293
+ await evaluateSnapshotFreshness({
294
+ snapshot: branchSnapshot,
295
+ gitRoot: resolved.gitRoot,
296
+ workflowDir: config.paths.workflow_dir,
297
+ taskId: task.id,
298
+ branchHeadSha,
299
+ taskVerificationState: task.verification?.state ?? null,
300
+ requiresVerify,
301
+ });
302
+ if (branchSnapshot.errors.length === 0 &&
303
+ branchSnapshot.meta &&
304
+ branchSnapshot.freshnessReviewFresh &&
305
+ (!requiresVerify || branchSnapshot.freshnessVerifySatisfied)) {
306
+ selectedSnapshot = branchSnapshot;
138
307
  }
139
308
  }
309
+ errors.push(...finalizeSnapshotErrors({
310
+ snapshot: selectedSnapshot,
311
+ branchHeadSha,
312
+ requiresVerify,
313
+ }));
140
314
  if (errors.length > 0) {
141
315
  throw new CliError({
142
316
  exitCode: exitCodeForError("E_VALIDATION"),
@@ -0,0 +1,9 @@
1
+ import { type CommandContext } from "../shared/task-backend.js";
2
+ export declare function cmdPrCloseSuperseded(opts: {
3
+ ctx?: CommandContext;
4
+ cwd: string;
5
+ rootOverride?: string;
6
+ taskId: string;
7
+ deleteRemoteBranch: boolean;
8
+ }): Promise<number>;
9
+ //# sourceMappingURL=close-superseded.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"close-superseded.d.ts","sourceRoot":"","sources":["../../../src/commands/pr/close-superseded.ts"],"names":[],"mappings":"AAOA,OAAO,EAGL,KAAK,cAAc,EACpB,MAAM,2BAA2B,CAAC;AAiCnC,wBAAsB,oBAAoB,CAAC,IAAI,EAAE;IAC/C,GAAG,CAAC,EAAE,cAAc,CAAC;IACrB,GAAG,EAAE,MAAM,CAAC;IACZ,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,MAAM,EAAE,MAAM,CAAC;IACf,kBAAkB,EAAE,OAAO,CAAC;CAC7B,GAAG,OAAO,CAAC,MAAM,CAAC,CAsHlB"}
@@ -0,0 +1,129 @@
1
+ import { readFile } from "node:fs/promises";
2
+ import { mapCoreError } from "../../cli/error-map.js";
3
+ import { exitCodeForError } from "../../cli/exit-codes.js";
4
+ import { createCliEmitter, infoMessage, workflowModeMessage } from "../../cli/output.js";
5
+ import { fileExists } from "../../cli/fs-utils.js";
6
+ import { CliError } from "../../shared/errors.js";
7
+ import { loadBackendTask, loadCommandContext, } from "../shared/task-backend.js";
8
+ import { parsePrMetaForwardCompatible } from "../shared/pr-meta.js";
9
+ import { cmdPrClose } from "./close.js";
10
+ import { isGhNotFound, resolveDefaultGithubRepo, runGhApiJson, runGhApiNoOutput, } from "./internal/gh-api.js";
11
+ import { resolvePrPaths } from "./internal/pr-paths.js";
12
+ async function deleteRemoteBranch(opts) {
13
+ const endpoint = `repos/${opts.repo}/git/refs/heads/${encodeURIComponent(opts.branch)}`;
14
+ try {
15
+ await runGhApiNoOutput(opts.cwd, [endpoint, "-X", "DELETE"]);
16
+ return "deleted";
17
+ }
18
+ catch (err) {
19
+ if (isGhNotFound(err))
20
+ return "already-absent";
21
+ throw err;
22
+ }
23
+ }
24
+ export async function cmdPrCloseSuperseded(opts) {
25
+ try {
26
+ const output = createCliEmitter();
27
+ const ctx = opts.ctx ??
28
+ (await loadCommandContext({ cwd: opts.cwd, rootOverride: opts.rootOverride ?? null }));
29
+ const { task } = await loadBackendTask({
30
+ ctx,
31
+ cwd: opts.cwd,
32
+ rootOverride: opts.rootOverride,
33
+ taskId: opts.taskId,
34
+ });
35
+ if (String(task.status ?? "")
36
+ .trim()
37
+ .toUpperCase() !== "DONE") {
38
+ throw new CliError({
39
+ exitCode: exitCodeForError("E_VALIDATION"),
40
+ code: "E_VALIDATION",
41
+ message: `Task ${opts.taskId} must be DONE before closing superseded PRs.`,
42
+ });
43
+ }
44
+ const { config, metaPath, resolved } = await resolvePrPaths({ ...opts, ctx });
45
+ if (config.workflow_mode !== "branch_pr") {
46
+ throw new CliError({
47
+ exitCode: exitCodeForError("E_USAGE"),
48
+ code: "E_USAGE",
49
+ message: workflowModeMessage(config.workflow_mode, "branch_pr"),
50
+ });
51
+ }
52
+ if (!(await fileExists(metaPath))) {
53
+ throw new CliError({
54
+ exitCode: exitCodeForError("E_VALIDATION"),
55
+ code: "E_VALIDATION",
56
+ message: `Missing PR metadata: ${metaPath}`,
57
+ });
58
+ }
59
+ const meta = parsePrMetaForwardCompatible(await readFile(metaPath, "utf8"), opts.taskId);
60
+ const branch = meta.branch?.trim() ?? "";
61
+ if (!branch) {
62
+ throw new CliError({
63
+ exitCode: exitCodeForError("E_VALIDATION"),
64
+ code: "E_VALIDATION",
65
+ message: `Missing PR branch for ${opts.taskId}`,
66
+ });
67
+ }
68
+ const repo = await resolveDefaultGithubRepo(resolved.gitRoot);
69
+ const owner = repo.split("/", 1)[0]?.trim() ?? "";
70
+ if (!owner) {
71
+ throw new CliError({
72
+ exitCode: exitCodeForError("E_VALIDATION"),
73
+ code: "E_VALIDATION",
74
+ message: "Could not derive GitHub owner from remote origin.",
75
+ });
76
+ }
77
+ const openPrs = await runGhApiJson(resolved.gitRoot, [
78
+ `repos/${repo}/pulls?head=${encodeURIComponent(`${owner}:${branch}`)}&state=open&per_page=100`,
79
+ ]);
80
+ if (openPrs.length === 0) {
81
+ const remoteBranchAction = opts.deleteRemoteBranch
82
+ ? await deleteRemoteBranch({ cwd: resolved.gitRoot, repo, branch })
83
+ : "skipped";
84
+ output.report([
85
+ { label: "task", value: opts.taskId },
86
+ { label: "branch", value: branch },
87
+ { label: "state", value: "skipped" },
88
+ { label: "reason", value: "no open task PR found" },
89
+ { label: "remote_branch_action", value: remoteBranchAction },
90
+ ], { header: infoMessage(`pr close-superseded ${opts.taskId}`) });
91
+ return 0;
92
+ }
93
+ if (openPrs.length > 1) {
94
+ throw new CliError({
95
+ exitCode: exitCodeForError("E_VALIDATION"),
96
+ code: "E_VALIDATION",
97
+ message: `Multiple open PRs match task ${opts.taskId} branch ${branch}: ${openPrs
98
+ .map((pr) => pr.number)
99
+ .filter((value) => typeof value === "number" && Number.isInteger(value) && value > 0)
100
+ .map((value) => `#${value}`)
101
+ .join(", ")}`,
102
+ });
103
+ }
104
+ const prNumber = Number(openPrs[0]?.number ?? 0);
105
+ if (!Number.isInteger(prNumber) || prNumber <= 0) {
106
+ throw new CliError({
107
+ exitCode: exitCodeForError("E_VALIDATION"),
108
+ code: "E_VALIDATION",
109
+ message: `Could not determine open PR number for task ${opts.taskId}.`,
110
+ });
111
+ }
112
+ return await cmdPrClose({
113
+ ctx,
114
+ cwd: opts.cwd,
115
+ rootOverride: opts.rootOverride,
116
+ prNumber,
117
+ comment: `Superseded by protected-main closure of task ${opts.taskId}.`,
118
+ deleteRemoteBranch: opts.deleteRemoteBranch,
119
+ });
120
+ }
121
+ catch (err) {
122
+ if (err instanceof CliError)
123
+ throw err;
124
+ throw mapCoreError(err, {
125
+ command: "pr close-superseded",
126
+ root: opts.rootOverride ?? null,
127
+ });
128
+ }
129
+ }
@@ -0,0 +1,11 @@
1
+ import { type CommandContext } from "../shared/task-backend.js";
2
+ export declare function cmdPrClose(opts: {
3
+ ctx?: CommandContext;
4
+ cwd: string;
5
+ rootOverride?: string;
6
+ prNumber: number;
7
+ repo?: string;
8
+ comment?: string;
9
+ deleteRemoteBranch: boolean;
10
+ }): Promise<number>;
11
+ //# sourceMappingURL=close.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"close.d.ts","sourceRoot":"","sources":["../../../src/commands/pr/close.ts"],"names":[],"mappings":"AAIA,OAAO,EAAsB,KAAK,cAAc,EAAE,MAAM,2BAA2B,CAAC;AA+CpF,wBAAsB,UAAU,CAAC,IAAI,EAAE;IACrC,GAAG,CAAC,EAAE,cAAc,CAAC;IACrB,GAAG,EAAE,MAAM,CAAC;IACZ,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,QAAQ,EAAE,MAAM,CAAC;IACjB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,kBAAkB,EAAE,OAAO,CAAC;CAC7B,GAAG,OAAO,CAAC,MAAM,CAAC,CAuGlB"}
@@ -0,0 +1,116 @@
1
+ import { mapCoreError } from "../../cli/error-map.js";
2
+ import { exitCodeForError } from "../../cli/exit-codes.js";
3
+ import { createCliEmitter, successMessage } from "../../cli/output.js";
4
+ import { CliError } from "../../shared/errors.js";
5
+ import { loadCommandContext } from "../shared/task-backend.js";
6
+ import { isGhNotFound, resolveDefaultGithubRepo, runGhApiJson, runGhApiNoOutput, } from "./internal/gh-api.js";
7
+ function ensureNonEmptyFlag(name, value) {
8
+ const trimmed = value.trim();
9
+ if (!trimmed) {
10
+ throw new CliError({
11
+ exitCode: exitCodeForError("E_USAGE"),
12
+ code: "E_USAGE",
13
+ message: `Invalid value for --${name}.`,
14
+ });
15
+ }
16
+ return trimmed;
17
+ }
18
+ export async function cmdPrClose(opts) {
19
+ try {
20
+ if (!Number.isInteger(opts.prNumber) || opts.prNumber <= 0) {
21
+ throw new CliError({
22
+ exitCode: exitCodeForError("E_USAGE"),
23
+ code: "E_USAGE",
24
+ message: "Invalid PR number.",
25
+ });
26
+ }
27
+ const output = createCliEmitter();
28
+ const ctx = opts.ctx ??
29
+ (await loadCommandContext({ cwd: opts.cwd, rootOverride: opts.rootOverride ?? null }));
30
+ const commandCwd = ctx.resolvedProject.gitRoot;
31
+ const repo = opts.repo
32
+ ? ensureNonEmptyFlag("repo", opts.repo)
33
+ : await resolveDefaultGithubRepo(commandCwd);
34
+ const comment = opts.comment?.trim() ? ensureNonEmptyFlag("comment", opts.comment) : null;
35
+ const pr = await runGhApiJson(commandCwd, [
36
+ `repos/${repo}/pulls/${opts.prNumber}`,
37
+ ]);
38
+ if (!pr.number) {
39
+ throw new CliError({
40
+ exitCode: exitCodeForError("E_VALIDATION"),
41
+ code: "E_VALIDATION",
42
+ message: `GitHub pull request #${opts.prNumber} was not found in ${repo}.`,
43
+ });
44
+ }
45
+ if (comment) {
46
+ await runGhApiNoOutput(commandCwd, [
47
+ `repos/${repo}/issues/${opts.prNumber}/comments`,
48
+ "-X",
49
+ "POST",
50
+ "-f",
51
+ `body=${comment}`,
52
+ ]);
53
+ }
54
+ const closed = await runGhApiJson(commandCwd, [
55
+ `repos/${repo}/pulls/${opts.prNumber}`,
56
+ "-X",
57
+ "PATCH",
58
+ "-f",
59
+ "state=closed",
60
+ ]);
61
+ const headRepo = closed.head?.repo?.full_name?.trim() ?? pr.head?.repo?.full_name?.trim() ?? null;
62
+ const headRef = closed.head?.ref?.trim() ?? pr.head?.ref?.trim() ?? null;
63
+ let remoteBranchAction = "skipped";
64
+ if (opts.deleteRemoteBranch) {
65
+ if (!headRef) {
66
+ remoteBranchAction = "skipped-missing-head";
67
+ }
68
+ else if (headRepo && headRepo !== repo) {
69
+ remoteBranchAction = "skipped-fork";
70
+ }
71
+ else {
72
+ try {
73
+ await runGhApiNoOutput(commandCwd, [
74
+ `repos/${repo}/git/refs/heads/${encodeURIComponent(headRef)}`,
75
+ "-X",
76
+ "DELETE",
77
+ ]);
78
+ remoteBranchAction = "deleted";
79
+ }
80
+ catch (err) {
81
+ if (isGhNotFound(err)) {
82
+ remoteBranchAction = "already-absent";
83
+ }
84
+ else {
85
+ throw err;
86
+ }
87
+ }
88
+ }
89
+ }
90
+ const result = {
91
+ repo,
92
+ prNumber: opts.prNumber,
93
+ url: closed.html_url?.trim() ?? pr.html_url?.trim() ?? null,
94
+ state: closed.state?.trim() ?? pr.state?.trim() ?? "closed",
95
+ comment: comment ? "added" : "skipped",
96
+ remoteBranch: headRef,
97
+ remoteBranchAction,
98
+ };
99
+ output.report([
100
+ { label: "repo", value: result.repo },
101
+ { label: "state", value: result.state },
102
+ { label: "url", value: result.url ?? "unknown" },
103
+ { label: "comment", value: result.comment },
104
+ { label: "remote_branch", value: result.remoteBranch ?? "unknown" },
105
+ { label: "remote_branch_action", value: result.remoteBranchAction },
106
+ ], {
107
+ header: successMessage("pr close", `#${result.prNumber}`),
108
+ });
109
+ return 0;
110
+ }
111
+ catch (err) {
112
+ if (err instanceof CliError)
113
+ throw err;
114
+ throw mapCoreError(err, { command: "pr close", root: opts.rootOverride ?? null });
115
+ }
116
+ }
@@ -2,5 +2,7 @@ export { cmdPrOpen } from "./open.js";
2
2
  export { cmdPrUpdate } from "./update.js";
3
3
  export { cmdPrCheck } from "./check.js";
4
4
  export { cmdPrNote } from "./note.js";
5
+ export { cmdPrClose } from "./close.js";
6
+ export { cmdPrCloseSuperseded } from "./close-superseded.js";
5
7
  export { cmdIntegrate } from "./integrate.js";
6
8
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/commands/pr/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,WAAW,CAAC;AACtC,OAAO,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAC1C,OAAO,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AACxC,OAAO,EAAE,SAAS,EAAE,MAAM,WAAW,CAAC;AACtC,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/commands/pr/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,WAAW,CAAC;AACtC,OAAO,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAC1C,OAAO,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AACxC,OAAO,EAAE,SAAS,EAAE,MAAM,WAAW,CAAC;AACtC,OAAO,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AACxC,OAAO,EAAE,oBAAoB,EAAE,MAAM,uBAAuB,CAAC;AAC7D,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC"}
@@ -2,4 +2,6 @@ export { cmdPrOpen } from "./open.js";
2
2
  export { cmdPrUpdate } from "./update.js";
3
3
  export { cmdPrCheck } from "./check.js";
4
4
  export { cmdPrNote } from "./note.js";
5
+ export { cmdPrClose } from "./close.js";
6
+ export { cmdPrCloseSuperseded } from "./close-superseded.js";
5
7
  export { cmdIntegrate } from "./integrate.js";