agentplane 0.3.12 → 0.3.14

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 (376) hide show
  1. package/assets/RUNNER.md +1 -1
  2. package/assets/agents/ORCHESTRATOR.json +1 -1
  3. package/assets/agents/SKILL_EXTRACTOR.json +31 -0
  4. package/assets/codex-plugin/assets/header.png +0 -0
  5. package/assets/codex-plugin/assets/icon.svg +1 -0
  6. package/assets/codex-plugin/assets/logo.svg +1 -0
  7. package/assets/codex-plugin/skills/agentplane/SKILL.md +35 -0
  8. package/assets/framework.manifest.json +7 -0
  9. package/assets/policy/governance.md +4 -2
  10. package/assets/policy/incidents.md +4 -19
  11. package/assets/policy/workflow.branch_pr.md +10 -5
  12. package/assets/policy/workflow.release.md +5 -2
  13. package/dist/.build-manifest.json +409 -219
  14. package/dist/cli/exit-codes.d.ts.map +1 -1
  15. package/dist/cli/exit-codes.js +1 -0
  16. package/dist/cli/output.d.ts +29 -0
  17. package/dist/cli/output.d.ts.map +1 -1
  18. package/dist/cli/output.js +33 -0
  19. package/dist/cli/reason-codes.d.ts +1 -1
  20. package/dist/cli/reason-codes.d.ts.map +1 -1
  21. package/dist/cli/reason-codes.js +12 -0
  22. package/dist/cli/run-cli/command-catalog/core.d.ts +1 -1
  23. package/dist/cli/run-cli/command-catalog/core.d.ts.map +1 -1
  24. package/dist/cli/run-cli/command-catalog/core.js +36 -78
  25. package/dist/cli/run-cli/command-catalog/lifecycle.d.ts.map +1 -1
  26. package/dist/cli/run-cli/command-catalog/lifecycle.js +4 -12
  27. package/dist/cli/run-cli/command-catalog/project.d.ts +1 -1
  28. package/dist/cli/run-cli/command-catalog/project.d.ts.map +1 -1
  29. package/dist/cli/run-cli/command-catalog/project.js +27 -31
  30. package/dist/cli/run-cli/command-catalog/shared.d.ts +9 -6
  31. package/dist/cli/run-cli/command-catalog/shared.d.ts.map +1 -1
  32. package/dist/cli/run-cli/command-catalog/shared.js +23 -6
  33. package/dist/cli/run-cli/command-catalog/task.d.ts.map +1 -1
  34. package/dist/cli/run-cli/command-catalog/task.js +6 -18
  35. package/dist/cli/run-cli/command-catalog.d.ts +1 -1
  36. package/dist/cli/run-cli/command-catalog.d.ts.map +1 -1
  37. package/dist/cli/run-cli/commands/codex.d.ts +14 -0
  38. package/dist/cli/run-cli/commands/codex.d.ts.map +1 -0
  39. package/dist/cli/run-cli/commands/codex.js +100 -0
  40. package/dist/cli/run-cli/commands/core.d.ts +1 -0
  41. package/dist/cli/run-cli/commands/core.d.ts.map +1 -1
  42. package/dist/cli/run-cli/commands/core.js +1 -0
  43. package/dist/cli/run-cli/commands/init/recipes.d.ts +9 -1
  44. package/dist/cli/run-cli/commands/init/recipes.d.ts.map +1 -1
  45. package/dist/cli/run-cli/commands/init/recipes.js +33 -22
  46. package/dist/cli/run-cli/commands/init.d.ts.map +1 -1
  47. package/dist/cli/run-cli/commands/init.js +26 -21
  48. package/dist/cli/run-cli/error-guidance.js +20 -0
  49. package/dist/cli/run-cli.js +1 -1
  50. package/dist/cli/run-cli.test-helpers.d.ts +1 -74
  51. package/dist/cli/run-cli.test-helpers.d.ts.map +1 -1
  52. package/dist/cli/run-cli.test-helpers.js +1 -766
  53. package/dist/commands/branch/cleanup-merged.d.ts.map +1 -1
  54. package/dist/commands/branch/cleanup-merged.js +5 -9
  55. package/dist/commands/branch/work-start.command.d.ts.map +1 -1
  56. package/dist/commands/branch/work-start.command.js +1 -0
  57. package/dist/commands/codex/plugin-install.d.ts +26 -0
  58. package/dist/commands/codex/plugin-install.d.ts.map +1 -0
  59. package/dist/commands/codex/plugin-install.js +209 -0
  60. package/dist/commands/commit.spec.d.ts.map +1 -1
  61. package/dist/commands/commit.spec.js +2 -0
  62. package/dist/commands/doctor/branch-pr.d.ts +1 -1
  63. package/dist/commands/doctor/branch-pr.d.ts.map +1 -1
  64. package/dist/commands/doctor/branch-pr.js +5 -2
  65. package/dist/commands/guard/impl/commands.d.ts.map +1 -1
  66. package/dist/commands/guard/impl/commands.js +4 -1
  67. package/dist/commands/guard/impl/comment-commit.d.ts.map +1 -1
  68. package/dist/commands/guard/impl/comment-commit.js +2 -1
  69. package/dist/commands/guard/impl/env.d.ts +6 -0
  70. package/dist/commands/guard/impl/env.d.ts.map +1 -1
  71. package/dist/commands/guard/impl/env.js +41 -0
  72. package/dist/commands/pr/integrate/cmd.d.ts.map +1 -1
  73. package/dist/commands/pr/integrate/cmd.js +81 -5
  74. package/dist/commands/pr/integrate/internal/prepare.d.ts.map +1 -1
  75. package/dist/commands/pr/integrate/internal/prepare.js +38 -7
  76. package/dist/commands/pr/internal/auto-commit.d.ts.map +1 -1
  77. package/dist/commands/pr/internal/auto-commit.js +13 -7
  78. package/dist/commands/pr/internal/sync-branch.d.ts +36 -0
  79. package/dist/commands/pr/internal/sync-branch.d.ts.map +1 -0
  80. package/dist/commands/pr/internal/sync-branch.js +113 -0
  81. package/dist/commands/pr/internal/sync-github.d.ts +28 -0
  82. package/dist/commands/pr/internal/sync-github.d.ts.map +1 -0
  83. package/dist/commands/pr/internal/sync-github.js +178 -0
  84. package/dist/commands/pr/internal/sync-model.d.ts +36 -0
  85. package/dist/commands/pr/internal/sync-model.d.ts.map +1 -0
  86. package/dist/commands/pr/internal/sync-model.js +1 -0
  87. package/dist/commands/pr/internal/sync-open-step.d.ts +10 -0
  88. package/dist/commands/pr/internal/sync-open-step.d.ts.map +1 -0
  89. package/dist/commands/pr/internal/sync-open-step.js +128 -0
  90. package/dist/commands/pr/internal/sync-support.d.ts +7 -0
  91. package/dist/commands/pr/internal/sync-support.d.ts.map +1 -0
  92. package/dist/commands/pr/internal/sync-support.js +29 -0
  93. package/dist/commands/pr/internal/sync-update-step.d.ts +6 -0
  94. package/dist/commands/pr/internal/sync-update-step.d.ts.map +1 -0
  95. package/dist/commands/pr/internal/sync-update-step.js +68 -0
  96. package/dist/commands/pr/internal/sync.d.ts +2 -6
  97. package/dist/commands/pr/internal/sync.d.ts.map +1 -1
  98. package/dist/commands/pr/internal/sync.js +83 -525
  99. package/dist/commands/pr/open.d.ts.map +1 -1
  100. package/dist/commands/pr/open.js +62 -7
  101. package/dist/commands/pr/pr.command.d.ts.map +1 -1
  102. package/dist/commands/pr/pr.command.js +7 -2
  103. package/dist/commands/recipes/active.command.d.ts +7 -0
  104. package/dist/commands/recipes/active.command.d.ts.map +1 -0
  105. package/dist/commands/recipes/active.command.js +12 -0
  106. package/dist/commands/recipes/add.command.d.ts +8 -0
  107. package/dist/commands/recipes/add.command.d.ts.map +1 -0
  108. package/dist/commands/recipes/add.command.js +33 -0
  109. package/dist/commands/recipes/detach.command.d.ts +7 -0
  110. package/dist/commands/recipes/detach.command.d.ts.map +1 -0
  111. package/dist/commands/recipes/detach.command.js +19 -0
  112. package/dist/commands/recipes/disable.command.d.ts +7 -0
  113. package/dist/commands/recipes/disable.command.d.ts.map +1 -0
  114. package/dist/commands/recipes/disable.command.js +10 -0
  115. package/dist/commands/recipes/enable.command.d.ts +7 -0
  116. package/dist/commands/recipes/enable.command.d.ts.map +1 -0
  117. package/dist/commands/recipes/enable.command.js +10 -0
  118. package/dist/commands/recipes/explain-active.command.d.ts +5 -0
  119. package/dist/commands/recipes/explain-active.command.d.ts.map +1 -0
  120. package/dist/commands/recipes/explain-active.command.js +11 -0
  121. package/dist/commands/recipes/explain.command.d.ts.map +1 -1
  122. package/dist/commands/recipes/explain.command.js +4 -2
  123. package/dist/commands/recipes/impl/apply.d.ts +1 -1
  124. package/dist/commands/recipes/impl/apply.d.ts.map +1 -1
  125. package/dist/commands/recipes/impl/apply.js +34 -16
  126. package/dist/commands/recipes/impl/commands/active.d.ts +6 -0
  127. package/dist/commands/recipes/impl/commands/active.d.ts.map +1 -0
  128. package/dist/commands/recipes/impl/commands/active.js +47 -0
  129. package/dist/commands/recipes/impl/commands/add.d.ts +8 -0
  130. package/dist/commands/recipes/impl/commands/add.d.ts.map +1 -0
  131. package/dist/commands/recipes/impl/commands/add.js +105 -0
  132. package/dist/commands/recipes/impl/commands/detach.d.ts +6 -0
  133. package/dist/commands/recipes/impl/commands/detach.d.ts.map +1 -0
  134. package/dist/commands/recipes/impl/commands/detach.js +99 -0
  135. package/dist/commands/recipes/impl/commands/disable.d.ts +6 -0
  136. package/dist/commands/recipes/impl/commands/disable.d.ts.map +1 -0
  137. package/dist/commands/recipes/impl/commands/disable.js +23 -0
  138. package/dist/commands/recipes/impl/commands/enable.d.ts +6 -0
  139. package/dist/commands/recipes/impl/commands/enable.d.ts.map +1 -0
  140. package/dist/commands/recipes/impl/commands/enable.js +41 -0
  141. package/dist/commands/recipes/impl/commands/explain-active.d.ts +5 -0
  142. package/dist/commands/recipes/impl/commands/explain-active.d.ts.map +1 -0
  143. package/dist/commands/recipes/impl/commands/explain-active.js +20 -0
  144. package/dist/commands/recipes/impl/commands/explain.d.ts.map +1 -1
  145. package/dist/commands/recipes/impl/commands/explain.js +83 -36
  146. package/dist/commands/recipes/impl/commands/info.d.ts.map +1 -1
  147. package/dist/commands/recipes/impl/commands/info.js +39 -22
  148. package/dist/commands/recipes/impl/commands/install.d.ts +1 -1
  149. package/dist/commands/recipes/impl/commands/install.d.ts.map +1 -1
  150. package/dist/commands/recipes/impl/commands/install.js +35 -42
  151. package/dist/commands/recipes/impl/commands/list-remote.d.ts.map +1 -1
  152. package/dist/commands/recipes/impl/commands/list-remote.js +2 -3
  153. package/dist/commands/recipes/impl/commands/list.d.ts.map +1 -1
  154. package/dist/commands/recipes/impl/commands/list.js +13 -12
  155. package/dist/commands/recipes/impl/commands/remove.d.ts.map +1 -1
  156. package/dist/commands/recipes/impl/commands/remove.js +12 -2
  157. package/dist/commands/recipes/impl/commands/update.d.ts +7 -0
  158. package/dist/commands/recipes/impl/commands/update.d.ts.map +1 -0
  159. package/dist/commands/recipes/impl/commands/update.js +107 -0
  160. package/dist/commands/recipes/impl/commands.d.ts +7 -0
  161. package/dist/commands/recipes/impl/commands.d.ts.map +1 -1
  162. package/dist/commands/recipes/impl/commands.js +7 -0
  163. package/dist/commands/recipes/impl/constants.d.ts +1 -14
  164. package/dist/commands/recipes/impl/constants.d.ts.map +1 -1
  165. package/dist/commands/recipes/impl/constants.js +1 -18
  166. package/dist/commands/recipes/impl/index.d.ts +1 -1
  167. package/dist/commands/recipes/impl/index.d.ts.map +1 -1
  168. package/dist/commands/recipes/impl/installed-recipes.d.ts +1 -1
  169. package/dist/commands/recipes/impl/installed-recipes.d.ts.map +1 -1
  170. package/dist/commands/recipes/impl/installed-recipes.js +1 -2
  171. package/dist/commands/recipes/impl/mutation-transaction.d.ts +7 -0
  172. package/dist/commands/recipes/impl/mutation-transaction.d.ts.map +1 -0
  173. package/dist/commands/recipes/impl/mutation-transaction.js +47 -0
  174. package/dist/commands/recipes/impl/overlay-project.d.ts +48 -0
  175. package/dist/commands/recipes/impl/overlay-project.d.ts.map +1 -0
  176. package/dist/commands/recipes/impl/overlay-project.js +320 -0
  177. package/dist/commands/recipes/impl/paths.d.ts +17 -2
  178. package/dist/commands/recipes/impl/paths.d.ts.map +1 -1
  179. package/dist/commands/recipes/impl/paths.js +20 -5
  180. package/dist/commands/recipes/impl/project-installed-recipes.d.ts +5 -4
  181. package/dist/commands/recipes/impl/project-installed-recipes.d.ts.map +1 -1
  182. package/dist/commands/recipes/impl/project-installed-recipes.js +34 -76
  183. package/dist/commands/recipes/impl/project-recipe-state.d.ts +18 -0
  184. package/dist/commands/recipes/impl/project-recipe-state.d.ts.map +1 -0
  185. package/dist/commands/recipes/impl/project-recipe-state.js +94 -0
  186. package/dist/commands/recipes/impl/project-registry.d.ts +24 -0
  187. package/dist/commands/recipes/impl/project-registry.d.ts.map +1 -0
  188. package/dist/commands/recipes/impl/project-registry.js +124 -0
  189. package/dist/commands/recipes/impl/resolver.d.ts +1 -1
  190. package/dist/commands/recipes/impl/resolver.d.ts.map +1 -1
  191. package/dist/commands/recipes/impl/resolver.js +6 -4
  192. package/dist/commands/recipes/impl/types.d.ts +1 -240
  193. package/dist/commands/recipes/impl/types.d.ts.map +1 -1
  194. package/dist/commands/recipes/impl/version.d.ts +5 -0
  195. package/dist/commands/recipes/impl/version.d.ts.map +1 -0
  196. package/dist/commands/recipes/impl/version.js +9 -0
  197. package/dist/commands/recipes/info.command.js +2 -2
  198. package/dist/commands/recipes/install.spec.js +4 -4
  199. package/dist/commands/recipes/list.command.js +4 -4
  200. package/dist/commands/recipes/remove.command.js +2 -2
  201. package/dist/commands/recipes/update.command.d.ts +8 -0
  202. package/dist/commands/recipes/update.command.d.ts.map +1 -0
  203. package/dist/commands/recipes/update.command.js +35 -0
  204. package/dist/commands/recipes.d.ts +10 -6
  205. package/dist/commands/recipes.d.ts.map +1 -1
  206. package/dist/commands/recipes.js +8 -5
  207. package/dist/commands/recipes.test-helpers.d.ts +3 -3
  208. package/dist/commands/recipes.test-helpers.d.ts.map +1 -1
  209. package/dist/commands/recipes.test-helpers.js +105 -15
  210. package/dist/commands/release/apply.command.d.ts +1 -1
  211. package/dist/commands/release/apply.command.d.ts.map +1 -1
  212. package/dist/commands/release/apply.command.js +15 -379
  213. package/dist/commands/release/apply.mutation.d.ts +1 -0
  214. package/dist/commands/release/apply.mutation.d.ts.map +1 -1
  215. package/dist/commands/release/apply.mutation.js +24 -1
  216. package/dist/commands/release/apply.pipeline.d.ts +22 -0
  217. package/dist/commands/release/apply.pipeline.d.ts.map +1 -0
  218. package/dist/commands/release/apply.pipeline.js +371 -0
  219. package/dist/commands/release/apply.preflight.d.ts +2 -0
  220. package/dist/commands/release/apply.preflight.d.ts.map +1 -1
  221. package/dist/commands/release/apply.preflight.js +13 -4
  222. package/dist/commands/release/apply.types.d.ts +27 -0
  223. package/dist/commands/release/apply.types.d.ts.map +1 -1
  224. package/dist/commands/release.test-helpers.d.ts +4 -0
  225. package/dist/commands/release.test-helpers.d.ts.map +1 -1
  226. package/dist/commands/release.test-helpers.js +7 -0
  227. package/dist/commands/scenario/execute.command.js +4 -4
  228. package/dist/commands/scenario/impl/commands.js +4 -4
  229. package/dist/commands/scenario/info.command.js +4 -4
  230. package/dist/commands/scenario/list.command.js +3 -3
  231. package/dist/commands/scenario/run.command.js +5 -5
  232. package/dist/commands/scenario/scenario.command.js +7 -7
  233. package/dist/commands/shared/reconcile-check.d.ts.map +1 -1
  234. package/dist/commands/shared/reconcile-check.js +2 -2
  235. package/dist/commands/shared/task-backend.d.ts +6 -1
  236. package/dist/commands/shared/task-backend.d.ts.map +1 -1
  237. package/dist/commands/shared/task-backend.js +34 -2
  238. package/dist/commands/shared/task-handoff.d.ts +2 -1
  239. package/dist/commands/shared/task-handoff.d.ts.map +1 -1
  240. package/dist/commands/shared/task-handoff.js +15 -0
  241. package/dist/commands/shared/task-mutation.d.ts.map +1 -1
  242. package/dist/commands/shared/task-mutation.js +4 -4
  243. package/dist/commands/shared/task-store/intents.d.ts +34 -0
  244. package/dist/commands/shared/task-store/intents.d.ts.map +1 -0
  245. package/dist/commands/shared/task-store/intents.js +265 -0
  246. package/dist/commands/shared/task-store/readme.d.ts +28 -0
  247. package/dist/commands/shared/task-store/readme.d.ts.map +1 -0
  248. package/dist/commands/shared/task-store/readme.js +125 -0
  249. package/dist/commands/shared/task-store/store.d.ts +26 -0
  250. package/dist/commands/shared/task-store/store.d.ts.map +1 -0
  251. package/dist/commands/shared/task-store/store.js +105 -0
  252. package/dist/commands/shared/task-store/types.d.ts +94 -0
  253. package/dist/commands/shared/task-store/types.d.ts.map +1 -0
  254. package/dist/commands/shared/task-store/types.js +1 -0
  255. package/dist/commands/shared/task-store.d.ts +3 -109
  256. package/dist/commands/shared/task-store.d.ts.map +1 -1
  257. package/dist/commands/shared/task-store.js +2 -493
  258. package/dist/commands/task/block.d.ts.map +1 -1
  259. package/dist/commands/task/block.js +7 -2
  260. package/dist/commands/task/comment.d.ts.map +1 -1
  261. package/dist/commands/task/comment.js +7 -2
  262. package/dist/commands/task/finish-shared.d.ts.map +1 -1
  263. package/dist/commands/task/finish-shared.js +3 -3
  264. package/dist/commands/task/finish.d.ts.map +1 -1
  265. package/dist/commands/task/finish.js +102 -15
  266. package/dist/commands/task/handoff-show.command.d.ts.map +1 -1
  267. package/dist/commands/task/handoff-show.command.js +24 -0
  268. package/dist/commands/task/hosted-merge-sync.d.ts.map +1 -1
  269. package/dist/commands/task/hosted-merge-sync.js +9 -4
  270. package/dist/commands/task/list.run.d.ts.map +1 -1
  271. package/dist/commands/task/list.run.js +14 -4
  272. package/dist/commands/task/new.command.d.ts.map +1 -1
  273. package/dist/commands/task/new.command.js +16 -2
  274. package/dist/commands/task/new.js +2 -2
  275. package/dist/commands/task/show.d.ts.map +1 -1
  276. package/dist/commands/task/show.js +3 -3
  277. package/dist/commands/task/update.d.ts.map +1 -1
  278. package/dist/commands/task/update.js +11 -3
  279. package/dist/runner/adapters/codex.d.ts.map +1 -1
  280. package/dist/runner/adapters/codex.js +3 -33
  281. package/dist/runner/adapters/custom.d.ts.map +1 -1
  282. package/dist/runner/adapters/custom.js +3 -30
  283. package/dist/runner/adapters/runtime-shared.d.ts +14 -0
  284. package/dist/runner/adapters/runtime-shared.d.ts.map +1 -0
  285. package/dist/runner/adapters/runtime-shared.js +36 -0
  286. package/dist/runner/context/base-prompt-sources.d.ts +30 -0
  287. package/dist/runner/context/base-prompt-sources.d.ts.map +1 -0
  288. package/dist/runner/context/base-prompt-sources.js +144 -0
  289. package/dist/runner/context/base-prompts.d.ts +5 -23
  290. package/dist/runner/context/base-prompts.d.ts.map +1 -1
  291. package/dist/runner/context/base-prompts.js +10 -358
  292. package/dist/runner/context/overlay-prompt-blocks.d.ts +7 -0
  293. package/dist/runner/context/overlay-prompt-blocks.d.ts.map +1 -0
  294. package/dist/runner/context/overlay-prompt-blocks.js +72 -0
  295. package/dist/runner/context/prompt-block-shared.d.ts +54 -0
  296. package/dist/runner/context/prompt-block-shared.d.ts.map +1 -0
  297. package/dist/runner/context/prompt-block-shared.js +106 -0
  298. package/dist/runner/context/recipe-context.d.ts +2 -1
  299. package/dist/runner/context/recipe-context.d.ts.map +1 -1
  300. package/dist/runner/context/recipe-context.js +41 -8
  301. package/dist/runner/context/recipe-prompt-blocks.d.ts +6 -0
  302. package/dist/runner/context/recipe-prompt-blocks.d.ts.map +1 -0
  303. package/dist/runner/context/recipe-prompt-blocks.js +143 -0
  304. package/dist/runner/types.d.ts +4 -0
  305. package/dist/runner/types.d.ts.map +1 -1
  306. package/dist/runner/usecases/scenario-materialize-task.js +2 -2
  307. package/dist/runner/usecases/task-run-inspect.js +2 -2
  308. package/dist/runner/usecases/task-run-lifecycle-shared.js +2 -2
  309. package/dist/runner/usecases/task-run.d.ts.map +1 -1
  310. package/dist/runner/usecases/task-run.js +6 -3
  311. package/dist/runtime/behavior/resolve.d.ts +2 -1
  312. package/dist/runtime/behavior/resolve.d.ts.map +1 -1
  313. package/dist/runtime/behavior/resolve.js +25 -5
  314. package/dist/runtime/behavior/types.d.ts +1 -0
  315. package/dist/runtime/behavior/types.d.ts.map +1 -1
  316. package/dist/runtime/capabilities/recipe.d.ts +2 -1
  317. package/dist/runtime/capabilities/recipe.d.ts.map +1 -1
  318. package/dist/runtime/capabilities/recipe.js +88 -28
  319. package/dist/runtime/execution-context.d.ts +63 -0
  320. package/dist/runtime/execution-context.d.ts.map +1 -0
  321. package/dist/{usecases/context/resolve-context.js → runtime/execution-context.js} +23 -26
  322. package/dist/runtime/incidents/advice-strategy.d.ts +15 -0
  323. package/dist/runtime/incidents/advice-strategy.d.ts.map +1 -0
  324. package/dist/runtime/incidents/advice-strategy.js +54 -0
  325. package/dist/runtime/incidents/plan-strategy.d.ts +9 -0
  326. package/dist/runtime/incidents/plan-strategy.d.ts.map +1 -0
  327. package/dist/runtime/incidents/plan-strategy.js +205 -0
  328. package/dist/runtime/incidents/registry-strategy.d.ts +6 -0
  329. package/dist/runtime/incidents/registry-strategy.d.ts.map +1 -0
  330. package/dist/runtime/incidents/registry-strategy.js +280 -0
  331. package/dist/runtime/incidents/resolve.d.ts +3 -25
  332. package/dist/runtime/incidents/resolve.d.ts.map +1 -1
  333. package/dist/runtime/incidents/resolve.js +3 -683
  334. package/dist/runtime/incidents/shared.d.ts +34 -0
  335. package/dist/runtime/incidents/shared.d.ts.map +1 -0
  336. package/dist/runtime/incidents/shared.js +171 -0
  337. package/dist/shared/errors.d.ts +1 -1
  338. package/dist/shared/errors.d.ts.map +1 -1
  339. package/dist/shared/runtime-source.d.ts.map +1 -1
  340. package/dist/shared/runtime-source.js +8 -3
  341. package/dist/testing/cli-harness/recipe-archives.d.ts +28 -0
  342. package/dist/testing/cli-harness/recipe-archives.d.ts.map +1 -0
  343. package/dist/testing/cli-harness/recipe-archives.js +374 -0
  344. package/dist/testing/cli-harness/stdio.d.ts +26 -0
  345. package/dist/testing/cli-harness/stdio.d.ts.map +1 -0
  346. package/dist/testing/cli-harness/stdio.js +84 -0
  347. package/dist/testing/cli-harness.d.ts +25 -0
  348. package/dist/testing/cli-harness.d.ts.map +1 -0
  349. package/dist/testing/cli-harness.js +313 -0
  350. package/dist/testing/index.d.ts +2 -0
  351. package/dist/testing/index.d.ts.map +1 -0
  352. package/dist/testing/index.js +1 -0
  353. package/package.json +7 -3
  354. package/dist/cli/recipes-bundled.d.ts +0 -10
  355. package/dist/cli/recipes-bundled.d.ts.map +0 -1
  356. package/dist/cli/recipes-bundled.js +0 -36
  357. package/dist/commands/recipes/impl/manifest.d.ts +0 -4
  358. package/dist/commands/recipes/impl/manifest.d.ts.map +0 -1
  359. package/dist/commands/recipes/impl/manifest.js +0 -229
  360. package/dist/commands/recipes/impl/normalize.d.ts +0 -8
  361. package/dist/commands/recipes/impl/normalize.d.ts.map +0 -1
  362. package/dist/commands/recipes/impl/normalize.js +0 -54
  363. package/dist/commands/recipes/impl/scenario.d.ts +0 -16
  364. package/dist/commands/recipes/impl/scenario.d.ts.map +0 -1
  365. package/dist/commands/recipes/impl/scenario.js +0 -262
  366. package/dist/recipes/bundled-recipes.d.ts +0 -17
  367. package/dist/recipes/bundled-recipes.d.ts.map +0 -1
  368. package/dist/recipes/bundled-recipes.js +0 -15
  369. package/dist/usecases/context/resolve-context.d.ts +0 -68
  370. package/dist/usecases/context/resolve-context.d.ts.map +0 -1
  371. package/dist/usecases/task/task-list-usecase.d.ts +0 -9
  372. package/dist/usecases/task/task-list-usecase.d.ts.map +0 -1
  373. package/dist/usecases/task/task-list-usecase.js +0 -17
  374. package/dist/usecases/task/task-new-usecase.d.ts +0 -9
  375. package/dist/usecases/task/task-new-usecase.d.ts.map +0 -1
  376. package/dist/usecases/task/task-new-usecase.js +0 -17
@@ -1,333 +1,78 @@
1
- import { mkdir, readFile, rm } from "node:fs/promises";
1
+ import { mkdir, readFile } from "node:fs/promises";
2
2
  import path from "node:path";
3
- import { extractTaskSuffix, resolveBaseBranch } from "@agentplaneorg/core";
3
+ import { resolveBaseBranch } from "@agentplaneorg/core";
4
4
  import { mapBackendError } from "../../../cli/error-map.js";
5
5
  import { exitCodeForError } from "../../../cli/exit-codes.js";
6
6
  import { fileExists } from "../../../cli/fs-utils.js";
7
7
  import { workflowModeMessage } from "../../../cli/output.js";
8
8
  import { CliError } from "../../../shared/errors.js";
9
- import { writeJsonStableIfChanged, writeTextIfChanged } from "../../../shared/write-if-changed.js";
10
- import { execFileAsync, gitEnv } from "../../shared/git.js";
11
- import { gitDiffStat } from "../../shared/git-diff.js";
12
- import { gitBranchUpstream, gitCurrentBranch } from "../../shared/git-ops.js";
13
- import { parseTaskIdFromBranch } from "../../shared/git-worktree.js";
14
- import { isTransientGhTransportError, normalizeGhTransportError, withGhTransportRetry, } from "../../shared/gh-transport.js";
15
9
  import { INCIDENTS_POLICY_PATH } from "../../incidents/shared.js";
16
- import { buildObservedGithubPrMeta, buildOpenedPrMeta, buildUpdatedPrMeta, resolvePrArtifactHeadSha, parsePrMeta, } from "../../shared/pr-meta.js";
10
+ import { resolvePrArtifactHeadSha, parsePrMeta } from "../../shared/pr-meta.js";
17
11
  import { isTaskLocalOnlyAdvance } from "../../shared/task-local-freshness.js";
18
12
  import { loadBackendTask, loadCommandContext, } from "../../shared/task-backend.js";
19
13
  import { resolvePrPaths } from "./pr-paths.js";
20
14
  import { readPrHandoffNotes } from "./note-store.js";
21
- import { ghEnv } from "./gh-api.js";
22
- import { buildGithubPrTitle, renderGithubPrBody, renderPrAutoSummary, renderPrReviewDocument, } from "./review-template.js";
23
- function nowIso() {
24
- return new Date().toISOString();
25
- }
26
- async function readTextIfExists(filePath) {
27
- try {
28
- return await readFile(filePath, "utf8");
29
- }
30
- catch (err) {
31
- const code = err?.code;
32
- if (code === "ENOENT")
33
- return null;
34
- throw err;
35
- }
36
- }
37
- async function restoreIncidentRegistryIfNeeded(opts) {
38
- const incidentsPath = path.join(opts.gitRoot, INCIDENTS_POLICY_PATH);
39
- const nextText = await readTextIfExists(incidentsPath);
40
- if (nextText === opts.previousText)
41
- return;
42
- if (opts.previousText === null) {
43
- await rm(incidentsPath, { force: true });
44
- return;
45
- }
46
- await writeTextIfChanged(incidentsPath, opts.previousText);
47
- }
48
- function isUnknownRevisionError(err) {
49
- const message = err instanceof Error ? err.message : String(err);
50
- return (/unknown revision or path not in the working tree/i.test(message) ||
51
- /bad revision/i.test(message) ||
52
- /ambiguous argument/i.test(message));
53
- }
54
- function parseGithubRepoFromRemoteUrl(remoteUrl) {
55
- const trimmed = remoteUrl.trim();
56
- if (!trimmed)
57
- return null;
58
- const httpsMatch = /^https?:\/\/github\.com\/([^/]+)\/([^/]+?)(?:\.git)?\/?$/.exec(trimmed);
59
- if (httpsMatch)
60
- return `${httpsMatch[1]}/${httpsMatch[2]}`;
61
- const sshMatch = /^git@github\.com:([^/]+)\/([^/]+?)(?:\.git)?$/.exec(trimmed);
62
- if (sshMatch)
63
- return `${sshMatch[1]}/${sshMatch[2]}`;
64
- return null;
65
- }
66
- async function resolveGithubRepoFromOrigin(gitRoot) {
67
- try {
68
- const { stdout } = await execFileAsync("git", ["remote", "get-url", "origin"], {
69
- cwd: gitRoot,
70
- env: gitEnv(),
71
- });
72
- return parseGithubRepoFromRemoteUrl(stdout);
73
- }
74
- catch {
75
- return null;
76
- }
77
- }
78
- function normalizeObservedGithubPr(record) {
79
- const number = Number(record.number);
80
- if (!Number.isInteger(number) || number <= 0)
81
- return null;
82
- const state = record.state?.trim().toLowerCase() ?? "";
83
- const mergedAt = record.merged_at?.trim() ?? null;
84
- const status = mergedAt && mergedAt.length > 0
85
- ? "MERGED"
86
- : state === "open"
87
- ? "OPEN"
88
- : state === "closed"
89
- ? "CLOSED"
90
- : null;
91
- if (!status)
92
- return null;
93
- const prUrl = record.html_url?.trim() ?? null;
94
- const mergeCommit = record.merge_commit_sha?.trim() ?? null;
95
- const base = record.base?.ref?.trim() ?? null;
96
- const headSha = record.head?.sha?.trim() ?? null;
97
- return {
98
- prNumber: number,
99
- prUrl,
100
- status,
101
- mergedAt,
102
- mergeCommit,
103
- base,
104
- headSha,
105
- };
106
- }
107
- async function tryLookupExistingGithubPrByBranch(opts) {
108
- const repo = await resolveGithubRepoFromOrigin(opts.gitRoot);
109
- if (!repo)
110
- return null;
111
- const owner = repo.split("/")[0]?.trim() ?? "";
112
- if (!owner)
113
- return null;
114
- const query = new URLSearchParams({ state: "all", head: `${owner}:${opts.branch}` });
115
- const baseBranch = opts.baseBranch?.trim() ?? "";
116
- if (baseBranch)
117
- query.set("base", baseBranch);
118
- const endpoint = `repos/${repo}/pulls?${query.toString()}`;
119
- try {
120
- const { stdout } = await withGhTransportRetry(() => execFileAsync("gh", ["api", endpoint], {
121
- cwd: opts.gitRoot,
122
- env: ghEnv(),
123
- maxBuffer: 10 * 1024 * 1024,
124
- }), { label: `running gh api ${endpoint}` });
125
- const parsed = JSON.parse(stdout);
126
- if (!Array.isArray(parsed) || parsed.length === 0)
127
- return null;
128
- for (const record of parsed) {
129
- const observed = normalizeObservedGithubPr(record);
130
- if (observed)
131
- return observed;
132
- }
133
- return null;
134
- }
135
- catch (err) {
136
- const code = err?.code;
137
- if (code === "ENOENT")
138
- return null;
139
- const message = normalizeGhTransportError(err);
140
- if (message.trim().length > 0)
141
- return null;
142
- return null;
143
- }
144
- }
145
- function formatGithubPrLink(prNumber, prUrl, verb) {
146
- return prUrl?.trim()
147
- ? `${verb} GitHub PR #${prNumber}: ${prUrl.trim()}`
148
- : `${verb} GitHub PR #${prNumber}`;
149
- }
150
- function shouldPersistObservedGithubPrMeta(observed) {
151
- if (!observed)
152
- return false;
153
- return observed.status === "MERGED";
154
- }
155
- function taskPrArtifactRefreshMessage(taskId) {
156
- return `📝 ${extractTaskSuffix(taskId)} task: refresh PR artifacts`;
157
- }
158
- async function resolveRenderableBranchHead(opts) {
159
- const branchHeadSha = await resolveBranchHeadSha({
160
- gitRoot: opts.gitRoot,
15
+ import { currentBranchMatchesTask, resolvePrSyncBranch, resolveRenderableBranchHead, } from "./sync-branch.js";
16
+ import { runPrOpenSync } from "./sync-open-step.js";
17
+ import { nowIso, readTextIfExists, restoreIncidentRegistryIfNeeded } from "./sync-support.js";
18
+ import { runPrUpdateSync } from "./sync-update-step.js";
19
+ async function buildPrSyncCommonState(opts) {
20
+ const handoffNotes = await readPrHandoffNotes(opts.notesPath);
21
+ const now = nowIso();
22
+ const createdAt = opts.existingMeta?.created_at ?? now;
23
+ const { headSha, artifactRefresh } = await resolveRenderableBranchHead({
24
+ gitRoot: opts.resolved.gitRoot,
25
+ taskId: opts.task.id,
161
26
  branch: opts.branch,
162
27
  });
163
- if (!branchHeadSha)
164
- return { headSha: null, artifactRefresh: false };
165
- try {
166
- const { stdout: subjectStdout } = await execFileAsync("git", ["log", "-1", "--pretty=%s", branchHeadSha], {
167
- cwd: opts.gitRoot,
168
- env: gitEnv(),
169
- });
170
- const subject = subjectStdout.trim();
171
- return {
172
- headSha: branchHeadSha,
173
- artifactRefresh: subject === taskPrArtifactRefreshMessage(opts.taskId),
174
- };
175
- }
176
- catch {
177
- return { headSha: branchHeadSha, artifactRefresh: false };
178
- }
179
- }
180
- function formatUnpublishedRemoteHeadReason(branch) {
181
- return (`task branch ${branch} is not yet published on origin; push it with ` +
182
- `\`git push -u origin ${branch}\` and rerun \`agentplane pr open\``);
183
- }
184
- function isMissingRemoteHeadCreateError(err) {
185
- const text = normalizeGhTransportError(err);
186
- if (!/\b422\b/i.test(text))
187
- return false;
188
- return (/head sha/i.test(text) ||
189
- /head ref/i.test(text) ||
190
- /head.*must be a branch/i.test(text) ||
191
- /head.*not found/i.test(text) ||
192
- /field["']?\s*:\s*["']head["']/i.test(text) ||
193
- /field\s+head\b/i.test(text) ||
194
- /no commits between/i.test(text));
195
- }
196
- function summarizeGithubPrCreateFailure(err) {
197
- const text = normalizeGhTransportError(err);
198
- if (err?.code === "ENOENT") {
199
- return "gh CLI is unavailable";
200
- }
201
- if (/authentication required/i.test(text) ||
202
- /not logged into github/i.test(text) ||
203
- /bad credentials/i.test(text) ||
204
- /permission denied/i.test(text) ||
205
- /\b401\b/i.test(text) ||
206
- /\b403\b/i.test(text)) {
207
- return "GitHub auth or permissions unavailable";
208
- }
209
- if (isTransientGhTransportError(err)) {
210
- return "GitHub transport failed; retry `agentplane pr open`";
211
- }
212
- return "GitHub PR creation failed";
213
- }
214
- async function tryCreateGithubPr(opts) {
215
- const repo = await resolveGithubRepoFromOrigin(opts.gitRoot);
216
- if (!repo) {
217
- return {
218
- observed: null,
219
- stagedReason: "GitHub origin repo unavailable",
220
- };
221
- }
222
- const baseBranch = opts.baseBranch?.trim() ?? "";
223
- if (!baseBranch) {
224
- return {
225
- observed: null,
226
- stagedReason: "base branch unresolved",
227
- };
228
- }
229
- try {
230
- const { stdout } = await withGhTransportRetry(() => execFileAsync("gh", [
231
- "api",
232
- `repos/${repo}/pulls`,
233
- "-X",
234
- "POST",
235
- "-f",
236
- `title=${opts.title}`,
237
- "-f",
238
- `body=${opts.body}`,
239
- "-f",
240
- `head=${opts.branch}`,
241
- "-f",
242
- `base=${baseBranch}`,
243
- ], {
244
- cwd: opts.gitRoot,
245
- env: ghEnv(),
246
- maxBuffer: 10 * 1024 * 1024,
247
- }), { label: `running gh api repos/${repo}/pulls` });
248
- return {
249
- observed: normalizeObservedGithubPr(JSON.parse(stdout)),
250
- stagedReason: null,
251
- };
252
- }
253
- catch (err) {
254
- if (isMissingRemoteHeadCreateError(err)) {
255
- return {
256
- observed: null,
257
- stagedReason: formatUnpublishedRemoteHeadReason(opts.branch),
258
- };
259
- }
260
- return {
261
- observed: null,
262
- stagedReason: summarizeGithubPrCreateFailure(err),
263
- };
264
- }
265
- }
266
- async function resolveBranchHeadSha(opts) {
267
- try {
268
- const { stdout } = await execFileAsync("git", ["rev-parse", opts.branch], {
269
- cwd: opts.gitRoot,
270
- env: gitEnv(),
28
+ const preservePreviousHead = Boolean(opts.existingMeta?.head_sha) &&
29
+ Boolean(headSha) &&
30
+ (await isTaskLocalOnlyAdvance({
31
+ gitRoot: opts.resolved.gitRoot,
32
+ workflowDir: opts.workflowDir,
33
+ tasksPath: opts.tasksPath,
34
+ taskId: opts.task.id,
35
+ fromRef: opts.existingMeta?.head_sha ?? null,
36
+ toRef: headSha,
37
+ }));
38
+ const renderedHeadSha = artifactRefresh
39
+ ? (opts.existingMeta?.head_sha ?? undefined)
40
+ : resolvePrArtifactHeadSha({
41
+ previousHeadSha: opts.existingMeta?.head_sha ?? null,
42
+ currentHeadSha: headSha,
43
+ preservePrevious: preservePreviousHead,
271
44
  });
272
- return stdout.trim() || null;
273
- }
274
- catch (err) {
275
- if (!isUnknownRevisionError(err))
276
- throw err;
277
- return null;
278
- }
279
- }
280
- async function computePrDiffstat(opts) {
281
- const diffBaseRef = await resolvePrDiffBaseRef({
282
- gitRoot: opts.gitRoot,
45
+ const preservedRenderUpdatedAt = opts.existingMeta &&
46
+ (opts.existingMeta.branch ?? null) === opts.branch &&
47
+ (opts.existingMeta.base ?? null) === (opts.baseBranch ?? null) &&
48
+ (opts.existingMeta.head_sha ?? null) === (renderedHeadSha ?? null)
49
+ ? opts.existingMeta.updated_at
50
+ : null;
51
+ const renderUpdatedAt = preservedRenderUpdatedAt ?? now;
52
+ return {
53
+ task: opts.task,
54
+ resolved: opts.resolved,
55
+ workflowDir: opts.workflowDir,
56
+ tasksPath: opts.tasksPath,
57
+ prDir: opts.prDir,
58
+ metaPath: opts.metaPath,
59
+ diffstatPath: opts.diffstatPath,
60
+ notesPath: opts.notesPath,
61
+ verifyLogPath: opts.verifyLogPath,
62
+ reviewPath: opts.reviewPath,
63
+ githubTitlePath: opts.githubTitlePath,
64
+ githubBodyPath: opts.githubBodyPath,
65
+ existingMeta: opts.existingMeta,
66
+ handoffNotes,
67
+ now,
68
+ createdAt,
69
+ branch: opts.branch,
283
70
  baseBranch: opts.baseBranch,
284
- });
285
- try {
286
- return await gitDiffStat(opts.gitRoot, diffBaseRef, opts.branch, {
287
- excludePaths: [path.relative(opts.gitRoot, opts.prDir)],
288
- });
289
- }
290
- catch (err) {
291
- if (!isUnknownRevisionError(err))
292
- throw err;
293
- return "";
294
- }
295
- }
296
- async function resolvePrDiffBaseRef(opts) {
297
- const upstreamRef = await gitBranchUpstream(opts.gitRoot, opts.baseBranch);
298
- const candidate = upstreamRef?.trim() ?? "";
299
- if (!candidate)
300
- return opts.baseBranch;
301
- try {
302
- const { stdout } = await execFileAsync("git", ["rev-parse", "--verify", candidate], {
303
- cwd: opts.gitRoot,
304
- env: gitEnv(),
305
- });
306
- return stdout.trim() ? candidate : opts.baseBranch;
307
- }
308
- catch (err) {
309
- if (!isUnknownRevisionError(err))
310
- throw err;
311
- return opts.baseBranch;
312
- }
313
- }
314
- async function resolvePrSyncBranch(opts) {
315
- const explicitBranch = opts.branch?.trim() ?? "";
316
- if (explicitBranch) {
317
- return { branch: explicitBranch, source: "explicit" };
318
- }
319
- if (await fileExists(opts.metaPath)) {
320
- const metaBranch = parsePrMeta(await readFile(opts.metaPath, "utf8"), opts.taskId).branch?.trim() ?? "";
321
- if (metaBranch) {
322
- return { branch: metaBranch, source: "meta" };
323
- }
324
- }
325
- const currentBranchValue = await gitCurrentBranch(opts.resolved.gitRoot);
326
- const currentBranch = currentBranchValue.trim();
327
- if (currentBranch) {
328
- return { branch: currentBranch, source: "current" };
329
- }
330
- return { branch: null, source: "none" };
71
+ headSha,
72
+ artifactRefresh,
73
+ renderedHeadSha,
74
+ renderUpdatedAt,
75
+ };
331
76
  }
332
77
  export async function ensurePrArtifactsSynced(opts) {
333
78
  const ctx = opts.ctx ??
@@ -336,7 +81,7 @@ export async function ensurePrArtifactsSynced(opts) {
336
81
  if (config.workflow_mode !== "branch_pr")
337
82
  return null;
338
83
  const resolvedBranch = await resolvePrSyncBranch({
339
- resolved,
84
+ gitRoot: resolved.gitRoot,
340
85
  metaPath,
341
86
  taskId: opts.taskId,
342
87
  branch: opts.branch,
@@ -345,7 +90,7 @@ export async function ensurePrArtifactsSynced(opts) {
345
90
  if (!branch)
346
91
  return null;
347
92
  if (resolvedBranch.source === "current" &&
348
- parseTaskIdFromBranch(config.branch.task_prefix, branch) !== opts.taskId) {
93
+ !currentBranchMatchesTask(config.branch.task_prefix, branch, opts.taskId)) {
349
94
  return null;
350
95
  }
351
96
  const baseBranch = await resolveBaseBranch({
@@ -398,7 +143,7 @@ export async function syncPrArtifacts(opts) {
398
143
  });
399
144
  }
400
145
  const resolvedBranch = await resolvePrSyncBranch({
401
- resolved,
146
+ gitRoot: resolved.gitRoot,
402
147
  metaPath,
403
148
  taskId: task.id,
404
149
  branch: opts.branch,
@@ -429,226 +174,39 @@ export async function syncPrArtifacts(opts) {
429
174
  const existingMeta = metaExists && (await fileExists(metaPath))
430
175
  ? parsePrMeta(await readFile(metaPath, "utf8"), task.id)
431
176
  : null;
432
- const handoffNotes = await readPrHandoffNotes(notesPath);
433
- const now = nowIso();
434
- const createdAt = existingMeta?.created_at ?? now;
435
177
  const baseBranch = await resolveBaseBranch({
436
178
  cwd: opts.cwd,
437
179
  rootOverride: opts.rootOverride ?? null,
438
180
  cliBaseOpt: null,
439
181
  mode: config.workflow_mode,
440
182
  });
441
- const { headSha, artifactRefresh } = await resolveRenderableBranchHead({
442
- gitRoot: resolved.gitRoot,
443
- taskId: task.id,
183
+ const common = await buildPrSyncCommonState({
184
+ task,
185
+ resolved,
186
+ workflowDir: config.paths.workflow_dir,
187
+ tasksPath: config.paths.tasks_path,
188
+ prDir,
189
+ metaPath,
190
+ diffstatPath,
191
+ notesPath,
192
+ verifyLogPath,
193
+ reviewPath,
194
+ githubTitlePath,
195
+ githubBodyPath,
196
+ existingMeta,
444
197
  branch,
198
+ baseBranch,
445
199
  });
446
- const preservePreviousHead = Boolean(existingMeta?.head_sha) &&
447
- Boolean(headSha) &&
448
- (await isTaskLocalOnlyAdvance({
449
- gitRoot: resolved.gitRoot,
450
- workflowDir: config.paths.workflow_dir,
451
- tasksPath: config.paths.tasks_path,
452
- taskId: task.id,
453
- fromRef: existingMeta?.head_sha ?? null,
454
- toRef: headSha,
455
- }));
456
- const renderedHeadSha = artifactRefresh
457
- ? (existingMeta?.head_sha ?? undefined)
458
- : resolvePrArtifactHeadSha({
459
- previousHeadSha: existingMeta?.head_sha ?? null,
460
- currentHeadSha: headSha,
461
- preservePrevious: preservePreviousHead,
462
- });
463
- const preservedRenderUpdatedAt = existingMeta &&
464
- (existingMeta.branch ?? null) === branch &&
465
- (existingMeta.base ?? null) === (baseBranch ?? null) &&
466
- (existingMeta.head_sha ?? null) === (renderedHeadSha ?? null)
467
- ? existingMeta.updated_at
468
- : null;
469
- const renderUpdatedAt = preservedRenderUpdatedAt ?? now;
470
200
  if (opts.mode === "open") {
471
201
  const remoteMode = opts.remoteMode ?? "auto";
472
- const diffstat = baseBranch
473
- ? await computePrDiffstat({
474
- gitRoot: resolved.gitRoot,
475
- baseBranch,
476
- branch,
477
- prDir,
478
- })
479
- : "";
480
- const renderedSummaryHeadSha = artifactRefresh
481
- ? renderedHeadSha
482
- : (renderedHeadSha ?? headSha);
483
- let nextMeta = buildOpenedPrMeta({
484
- taskId: task.id,
485
- branch,
486
- at: now,
487
- previousMeta: existingMeta,
488
- base: baseBranch,
489
- headSha: renderedHeadSha,
490
- });
491
- const linkedExistingOutcome = typeof nextMeta.pr_number === "number" && nextMeta.pr_number > 0
492
- ? {
493
- action: "linked-existing",
494
- message: formatGithubPrLink(nextMeta.pr_number, nextMeta.pr_url ?? null, "linked to"),
495
- }
496
- : null;
497
- let openOutcome;
498
- const githubTitle = buildGithubPrTitle(task);
499
- const githubBody = renderGithubPrBody({
500
- task,
501
- handoffNotes,
502
- autoSummary: renderPrAutoSummary({
503
- updatedAt: renderUpdatedAt,
504
- branch,
505
- headSha: renderedSummaryHeadSha ?? null,
506
- diffstat,
507
- }),
508
- });
509
- const observedGithubPr = await tryLookupExistingGithubPrByBranch({
510
- gitRoot: resolved.gitRoot,
511
- branch,
512
- baseBranch,
513
- });
514
- if (observedGithubPr) {
515
- if (shouldPersistObservedGithubPrMeta(observedGithubPr)) {
516
- nextMeta = buildObservedGithubPrMeta({
517
- meta: nextMeta,
518
- observed: observedGithubPr,
519
- at: now,
520
- });
521
- }
522
- openOutcome = {
523
- action: "linked-existing",
524
- message: formatGithubPrLink(observedGithubPr.prNumber, observedGithubPr.prUrl, "linked to"),
525
- };
526
- }
527
- else if (remoteMode === "sync-only") {
528
- openOutcome = linkedExistingOutcome ?? {
529
- action: "sync-only",
530
- message: "local PR artifacts synced; remote PR creation skipped (--sync-only)",
531
- };
532
- }
533
- else {
534
- const createdGithubPr = await tryCreateGithubPr({
535
- gitRoot: resolved.gitRoot,
536
- branch,
537
- baseBranch,
538
- title: githubTitle,
539
- body: githubBody,
540
- });
541
- if (createdGithubPr.observed) {
542
- if (shouldPersistObservedGithubPrMeta(createdGithubPr.observed)) {
543
- nextMeta = buildObservedGithubPrMeta({
544
- meta: nextMeta,
545
- observed: createdGithubPr.observed,
546
- at: now,
547
- });
548
- }
549
- openOutcome = {
550
- action: "created",
551
- message: formatGithubPrLink(createdGithubPr.observed.prNumber, createdGithubPr.observed.prUrl, "created"),
552
- };
553
- }
554
- else {
555
- openOutcome = linkedExistingOutcome ?? {
556
- action: "staged",
557
- message: `local PR artifacts synced; remote PR creation staged (${createdGithubPr.stagedReason ?? "remote creation unavailable"})`,
558
- };
559
- }
560
- }
561
- const nextAutoSummary = renderPrAutoSummary({
562
- updatedAt: renderUpdatedAt,
563
- branch,
564
- headSha: renderedSummaryHeadSha ?? null,
565
- diffstat,
566
- });
567
- const nextReview = renderPrReviewDocument({
568
- task,
202
+ const { meta, openOutcome } = await runPrOpenSync(common, {
569
203
  author: opts.author,
570
- createdAt,
571
- branch,
572
- handoffNotes,
573
- autoSummary: nextAutoSummary,
574
- });
575
- const nextGithubBody = renderGithubPrBody({
576
- task,
577
- handoffNotes,
578
- autoSummary: nextAutoSummary,
579
- });
580
- await writeJsonStableIfChanged(metaPath, nextMeta);
581
- await writeTextIfChanged(diffstatPath, diffstat ? `${diffstat}\n` : "");
582
- if (!(await fileExists(notesPath))) {
583
- await writeTextIfChanged(notesPath, "");
584
- }
585
- if (!(await fileExists(verifyLogPath))) {
586
- await writeTextIfChanged(verifyLogPath, "");
587
- }
588
- await writeTextIfChanged(reviewPath, nextReview);
589
- await writeTextIfChanged(githubTitlePath, `${githubTitle}\n`);
590
- await writeTextIfChanged(githubBodyPath, nextGithubBody);
591
- return { meta: nextMeta, prDir, resolved, openOutcome };
592
- }
593
- if (!baseBranch) {
594
- throw new CliError({
595
- exitCode: exitCodeForError("E_USAGE"),
596
- code: "E_USAGE",
597
- message: "Base branch could not be resolved (use `agentplane branch base set`).",
204
+ remoteMode,
598
205
  });
206
+ return { meta, prDir, resolved, openOutcome };
599
207
  }
600
- const diffstat = await computePrDiffstat({
601
- gitRoot: resolved.gitRoot,
602
- baseBranch,
603
- branch,
604
- prDir,
605
- });
606
- let nextMeta = buildUpdatedPrMeta({
607
- meta: existingMeta,
608
- branch,
609
- at: now,
610
- base: baseBranch,
611
- headSha: renderedHeadSha,
612
- });
613
- const observedGithubPr = await tryLookupExistingGithubPrByBranch({
614
- gitRoot: resolved.gitRoot,
615
- branch,
616
- baseBranch,
617
- });
618
- if (shouldPersistObservedGithubPrMeta(observedGithubPr)) {
619
- nextMeta = buildObservedGithubPrMeta({
620
- meta: nextMeta,
621
- observed: observedGithubPr,
622
- at: now,
623
- });
624
- }
625
- const nextAutoSummary = renderPrAutoSummary({
626
- updatedAt: nextMeta.updated_at,
627
- branch,
628
- headSha: artifactRefresh
629
- ? (nextMeta.head_sha ?? renderedHeadSha ?? null)
630
- : (nextMeta.head_sha ?? renderedHeadSha ?? headSha ?? null),
631
- diffstat,
632
- });
633
- const nextReview = renderPrReviewDocument({
634
- task,
635
- createdAt,
636
- branch,
637
- handoffNotes,
638
- autoSummary: nextAutoSummary,
639
- });
640
- const githubTitle = buildGithubPrTitle(task);
641
- const githubBody = renderGithubPrBody({
642
- task,
643
- handoffNotes,
644
- autoSummary: nextAutoSummary,
645
- });
646
- await writeTextIfChanged(diffstatPath, diffstat ? `${diffstat}\n` : "");
647
- await writeTextIfChanged(reviewPath, nextReview);
648
- await writeTextIfChanged(githubTitlePath, `${githubTitle}\n`);
649
- await writeTextIfChanged(githubBodyPath, githubBody);
650
- await writeJsonStableIfChanged(metaPath, nextMeta);
651
- return { meta: nextMeta, prDir, resolved };
208
+ const { meta } = await runPrUpdateSync(common);
209
+ return { meta, prDir, resolved };
652
210
  }
653
211
  finally {
654
212
  await restoreIncidentRegistryIfNeeded({
@@ -1 +1 @@
1
- {"version":3,"file":"open.d.ts","sourceRoot":"","sources":["../../../src/commands/pr/open.ts"],"names":[],"mappings":"AAMA,OAAO,EAAsB,KAAK,cAAc,EAAE,MAAM,2BAA2B,CAAC;AAkBpF,wBAAsB,SAAS,CAAC,IAAI,EAAE;IACpC,GAAG,CAAC,EAAE,cAAc,CAAC;IACrB,GAAG,EAAE,MAAM,CAAC;IACZ,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,MAAM,EAAE,MAAM,CAAC;IACf,MAAM,EAAE,MAAM,CAAC;IACf,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,QAAQ,CAAC,EAAE,OAAO,CAAC;CACpB,GAAG,OAAO,CAAC,MAAM,CAAC,CA2ClB"}
1
+ {"version":3,"file":"open.d.ts","sourceRoot":"","sources":["../../../src/commands/pr/open.ts"],"names":[],"mappings":"AAQA,OAAO,EAAsB,KAAK,cAAc,EAAE,MAAM,2BAA2B,CAAC;AAuDpF,wBAAsB,SAAS,CAAC,IAAI,EAAE;IACpC,GAAG,CAAC,EAAE,cAAc,CAAC;IACrB,GAAG,EAAE,MAAM,CAAC;IACZ,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,MAAM,EAAE,MAAM,CAAC;IACf,MAAM,EAAE,MAAM,CAAC;IACf,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,QAAQ,CAAC,EAAE,OAAO,CAAC;CACpB,GAAG,OAAO,CAAC,MAAM,CAAC,CAgElB"}