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
@@ -4,6 +4,7 @@ import { resolveBaseBranch } from "@agentplaneorg/core";
4
4
  import { fileExists } from "../../../../cli/fs-utils.js";
5
5
  import { exitCodeForError } from "../../../../cli/exit-codes.js";
6
6
  import { unknownEntityMessage, workflowModeMessage } from "../../../../cli/output.js";
7
+ import { withDiagnosticContext } from "../../../../shared/diagnostics.js";
7
8
  import { CliError } from "../../../../shared/errors.js";
8
9
  import { ensureGitClean } from "../../../guard/index.js";
9
10
  import { gitDiffNames } from "../../../shared/git-diff.js";
@@ -52,13 +53,6 @@ export async function prepareIntegrate(opts) {
52
53
  });
53
54
  }
54
55
  const currentBranch = await gitCurrentBranch(resolved.gitRoot);
55
- if (currentBranch !== baseBranch) {
56
- throw new CliError({
57
- exitCode: exitCodeForError("E_GIT"),
58
- code: "E_GIT",
59
- message: `integrate must run on base branch ${baseBranch} (current: ${currentBranch})`,
60
- });
61
- }
62
56
  const { prDir, metaPath, diffstatPath, verifyLogPath } = await resolvePrPaths({
63
57
  ctx,
64
58
  cwd: opts.cwd,
@@ -92,6 +86,43 @@ export async function prepareIntegrate(opts) {
92
86
  message: unknownEntityMessage("branch", branch),
93
87
  });
94
88
  }
89
+ if (currentBranch !== baseBranch) {
90
+ if (currentBranch === branch) {
91
+ const baseWorktreePath = await findWorktreeForBranch(resolved.gitRoot, baseBranch);
92
+ const rerunCommand = baseWorktreePath && baseWorktreePath.trim().length > 0
93
+ ? `agentplane integrate ${opts.taskId} --branch ${branch} --root ${baseWorktreePath}`
94
+ : `git checkout ${baseBranch} && agentplane integrate ${opts.taskId} --branch ${branch}`;
95
+ throw new CliError({
96
+ exitCode: exitCodeForError("E_GIT"),
97
+ code: "E_GIT",
98
+ message: `integrate must run from the ${baseBranch} base checkout, not from task branch ${branch}. ` +
99
+ `Rerun it against the base checkout after leaving this task worktree.`,
100
+ context: withDiagnosticContext({
101
+ command: "integrate",
102
+ task_id: opts.taskId,
103
+ branch,
104
+ base_branch: baseBranch,
105
+ current_branch: currentBranch,
106
+ ...(baseWorktreePath ? { base_worktree_path: baseWorktreePath } : {}),
107
+ reason_code: "integrate_base_checkout_required",
108
+ }, {
109
+ state: `integrate was invoked from task branch ${branch} instead of base branch ${baseBranch}`,
110
+ likelyCause: "the operator is inside the task worktree, but branch_pr integrate is only valid from the registered base checkout",
111
+ hint: "Use the base checkout/worktree for the resolved base branch, not the task branch worktree, when running integrate.",
112
+ nextAction: {
113
+ command: rerunCommand,
114
+ reason: "rerun integrate against the base checkout route",
115
+ reasonCode: "integrate_base_checkout_required",
116
+ },
117
+ }),
118
+ });
119
+ }
120
+ throw new CliError({
121
+ exitCode: exitCodeForError("E_GIT"),
122
+ code: "E_GIT",
123
+ message: `integrate must run on base branch ${baseBranch} (current: ${currentBranch})`,
124
+ });
125
+ }
95
126
  await ensureCommittedPrArtifactsOnBranch({
96
127
  resolved,
97
128
  prDir,
@@ -1 +1 @@
1
- {"version":3,"file":"auto-commit.d.ts","sourceRoot":"","sources":["../../../../src/commands/pr/internal/auto-commit.ts"],"names":[],"mappings":"AAQA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,8BAA8B,CAAC;AA6BnE,wBAAsB,8BAA8B,CAAC,IAAI,EAAE;IACzD,GAAG,EAAE,cAAc,CAAC;IACpB,MAAM,EAAE,MAAM,CAAC;IACf,MAAM,EAAE,MAAM,CAAC;CAChB,GAAG,OAAO,CAAC,OAAO,CAAC,CA8CnB"}
1
+ {"version":3,"file":"auto-commit.d.ts","sourceRoot":"","sources":["../../../../src/commands/pr/internal/auto-commit.ts"],"names":[],"mappings":"AAQA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,8BAA8B,CAAC;AAiCnE,wBAAsB,8BAA8B,CAAC,IAAI,EAAE;IACzD,GAAG,EAAE,cAAc,CAAC;IACpB,MAAM,EAAE,MAAM,CAAC;IACf,MAAM,EAAE,MAAM,CAAC;CAChB,GAAG,OAAO,CAAC,OAAO,CAAC,CA+CnB"}
@@ -1,14 +1,19 @@
1
1
  import path from "node:path";
2
2
  import { extractTaskSuffix } from "@agentplaneorg/core";
3
- import { buildGitCommitEnv } from "../../guard/impl/env.js";
3
+ import { buildGitCommitEnv, resolveCanonicalGitIdentity } from "../../guard/impl/env.js";
4
4
  import { toGitPath } from "../../shared/git-diff.js";
5
5
  import { execFileAsync, gitEnv } from "../../shared/git.js";
6
6
  import { gitCurrentBranch } from "../../shared/git-ops.js";
7
7
  function taskPrDirPrefix(workflowDir, taskId) {
8
8
  return `${toGitPath(path.join(workflowDir, taskId, "pr"))}/`;
9
9
  }
10
- function isTaskPrArtifactPath(opts) {
11
- return toGitPath(opts.relPath).startsWith(taskPrDirPrefix(opts.workflowDir, opts.taskId));
10
+ function taskReadmePath(workflowDir, taskId) {
11
+ return toGitPath(path.join(workflowDir, taskId, "README.md"));
12
+ }
13
+ function isTaskPacketPath(opts) {
14
+ const normalized = toGitPath(opts.relPath);
15
+ return (normalized === taskReadmePath(opts.workflowDir, opts.taskId) ||
16
+ normalized.startsWith(taskPrDirPrefix(opts.workflowDir, opts.taskId)));
12
17
  }
13
18
  async function readCachedPaths(gitRoot) {
14
19
  const { stdout } = await execFileAsync("git", ["diff", "--cached", "--name-only", "--relative"], {
@@ -31,22 +36,22 @@ export async function maybeAutoCommitTaskPrArtifacts(opts) {
31
36
  if (!currentBranch || currentBranch !== opts.branch.trim())
32
37
  return false;
33
38
  const changedPaths = await opts.ctx.git.statusChangedPaths();
34
- const prArtifactPaths = changedPaths.filter((relPath) => isTaskPrArtifactPath({
39
+ const taskPacketPaths = changedPaths.filter((relPath) => isTaskPacketPath({
35
40
  workflowDir: opts.ctx.config.paths.workflow_dir,
36
41
  taskId: opts.taskId,
37
42
  relPath,
38
43
  }));
39
- if (prArtifactPaths.length === 0)
44
+ if (taskPacketPaths.length === 0)
40
45
  return false;
41
46
  const cachedPaths = await readCachedPaths(opts.ctx.resolvedProject.gitRoot);
42
- if (cachedPaths.some((relPath) => !isTaskPrArtifactPath({
47
+ if (cachedPaths.some((relPath) => !isTaskPacketPath({
43
48
  workflowDir: opts.ctx.config.paths.workflow_dir,
44
49
  taskId: opts.taskId,
45
50
  relPath,
46
51
  }))) {
47
52
  return false;
48
53
  }
49
- await opts.ctx.git.stage(prArtifactPaths);
54
+ await opts.ctx.git.stage(taskPacketPaths);
50
55
  await opts.ctx.git.commit({
51
56
  message: taskPrArtifactRefreshMessage(opts.taskId),
52
57
  env: buildGitCommitEnv({
@@ -57,6 +62,7 @@ export async function maybeAutoCommitTaskPrArtifacts(opts) {
57
62
  allowConfig: false,
58
63
  allowHooks: false,
59
64
  allowCI: false,
65
+ gitIdentity: await resolveCanonicalGitIdentity(),
60
66
  }),
61
67
  });
62
68
  opts.ctx.git.invalidateStatus();
@@ -0,0 +1,36 @@
1
+ export type ResolvedPrSyncBranch = {
2
+ branch: string | null;
3
+ source: "explicit" | "meta" | "current" | "none";
4
+ };
5
+ export declare function isUnknownRevisionError(err: unknown): boolean;
6
+ export declare function taskPrArtifactRefreshMessage(taskId: string): string;
7
+ export declare function resolveBranchHeadSha(opts: {
8
+ gitRoot: string;
9
+ branch: string;
10
+ }): Promise<string | null>;
11
+ export declare function resolveRenderableBranchHead(opts: {
12
+ gitRoot: string;
13
+ taskId: string;
14
+ branch: string;
15
+ }): Promise<{
16
+ headSha: string | null;
17
+ artifactRefresh: boolean;
18
+ }>;
19
+ export declare function resolvePrDiffBaseRef(opts: {
20
+ gitRoot: string;
21
+ baseBranch: string;
22
+ }): Promise<string>;
23
+ export declare function computePrDiffstat(opts: {
24
+ gitRoot: string;
25
+ baseBranch: string;
26
+ branch: string;
27
+ prDir: string;
28
+ }): Promise<string>;
29
+ export declare function resolvePrSyncBranch(opts: {
30
+ gitRoot: string;
31
+ metaPath: string;
32
+ taskId: string;
33
+ branch?: string;
34
+ }): Promise<ResolvedPrSyncBranch>;
35
+ export declare function currentBranchMatchesTask(taskPrefix: string, branch: string, taskId: string): boolean;
36
+ //# sourceMappingURL=sync-branch.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"sync-branch.d.ts","sourceRoot":"","sources":["../../../../src/commands/pr/internal/sync-branch.ts"],"names":[],"mappings":"AAYA,MAAM,MAAM,oBAAoB,GAAG;IACjC,MAAM,EAAE,MAAM,GAAG,IAAI,CAAC;IACtB,MAAM,EAAE,UAAU,GAAG,MAAM,GAAG,SAAS,GAAG,MAAM,CAAC;CAClD,CAAC;AAEF,wBAAgB,sBAAsB,CAAC,GAAG,EAAE,OAAO,GAAG,OAAO,CAO5D;AAED,wBAAgB,4BAA4B,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,CAEnE;AAED,wBAAsB,oBAAoB,CAAC,IAAI,EAAE;IAC/C,OAAO,EAAE,MAAM,CAAC;IAChB,MAAM,EAAE,MAAM,CAAC;CAChB,GAAG,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC,CAWzB;AAED,wBAAsB,2BAA2B,CAAC,IAAI,EAAE;IACtD,OAAO,EAAE,MAAM,CAAC;IAChB,MAAM,EAAE,MAAM,CAAC;IACf,MAAM,EAAE,MAAM,CAAC;CAChB,GAAG,OAAO,CAAC;IAAE,OAAO,EAAE,MAAM,GAAG,IAAI,CAAC;IAAC,eAAe,EAAE,OAAO,CAAA;CAAE,CAAC,CAwBhE;AAED,wBAAsB,oBAAoB,CAAC,IAAI,EAAE;IAC/C,OAAO,EAAE,MAAM,CAAC;IAChB,UAAU,EAAE,MAAM,CAAC;CACpB,GAAG,OAAO,CAAC,MAAM,CAAC,CAclB;AAED,wBAAsB,iBAAiB,CAAC,IAAI,EAAE;IAC5C,OAAO,EAAE,MAAM,CAAC;IAChB,UAAU,EAAE,MAAM,CAAC;IACnB,MAAM,EAAE,MAAM,CAAC;IACf,KAAK,EAAE,MAAM,CAAC;CACf,GAAG,OAAO,CAAC,MAAM,CAAC,CAiBlB;AAED,wBAAsB,mBAAmB,CAAC,IAAI,EAAE;IAC9C,OAAO,EAAE,MAAM,CAAC;IAChB,QAAQ,EAAE,MAAM,CAAC;IACjB,MAAM,EAAE,MAAM,CAAC;IACf,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB,GAAG,OAAO,CAAC,oBAAoB,CAAC,CAqBhC;AAED,wBAAgB,wBAAwB,CACtC,UAAU,EAAE,MAAM,EAClB,MAAM,EAAE,MAAM,EACd,MAAM,EAAE,MAAM,GACb,OAAO,CAET"}
@@ -0,0 +1,113 @@
1
+ import { readFile } from "node:fs/promises";
2
+ import path from "node:path";
3
+ import { extractTaskSuffix } from "@agentplaneorg/core";
4
+ import { fileExists } from "../../../cli/fs-utils.js";
5
+ import { execFileAsync, gitEnv } from "../../shared/git.js";
6
+ import { gitBranchUpstream, gitCurrentBranch } from "../../shared/git-ops.js";
7
+ import { parseTaskIdFromBranch } from "../../shared/git-worktree.js";
8
+ import { gitDiffStat } from "../../shared/git-diff.js";
9
+ import { parsePrMeta } from "../../shared/pr-meta.js";
10
+ export function isUnknownRevisionError(err) {
11
+ const message = err instanceof Error ? err.message : String(err);
12
+ return (/unknown revision or path not in the working tree/i.test(message) ||
13
+ /bad revision/i.test(message) ||
14
+ /ambiguous argument/i.test(message));
15
+ }
16
+ export function taskPrArtifactRefreshMessage(taskId) {
17
+ return `📝 ${extractTaskSuffix(taskId)} task: refresh PR artifacts`;
18
+ }
19
+ export async function resolveBranchHeadSha(opts) {
20
+ try {
21
+ const { stdout } = await execFileAsync("git", ["rev-parse", opts.branch], {
22
+ cwd: opts.gitRoot,
23
+ env: gitEnv(),
24
+ });
25
+ return stdout.trim() || null;
26
+ }
27
+ catch (err) {
28
+ if (!isUnknownRevisionError(err))
29
+ throw err;
30
+ return null;
31
+ }
32
+ }
33
+ export async function resolveRenderableBranchHead(opts) {
34
+ const branchHeadSha = await resolveBranchHeadSha({
35
+ gitRoot: opts.gitRoot,
36
+ branch: opts.branch,
37
+ });
38
+ if (!branchHeadSha)
39
+ return { headSha: null, artifactRefresh: false };
40
+ try {
41
+ const { stdout: subjectStdout } = await execFileAsync("git", ["log", "-1", "--pretty=%s", branchHeadSha], {
42
+ cwd: opts.gitRoot,
43
+ env: gitEnv(),
44
+ });
45
+ const subject = subjectStdout.trim();
46
+ return {
47
+ headSha: branchHeadSha,
48
+ artifactRefresh: subject === taskPrArtifactRefreshMessage(opts.taskId),
49
+ };
50
+ }
51
+ catch {
52
+ return { headSha: branchHeadSha, artifactRefresh: false };
53
+ }
54
+ }
55
+ export async function resolvePrDiffBaseRef(opts) {
56
+ const upstreamRef = await gitBranchUpstream(opts.gitRoot, opts.baseBranch);
57
+ const candidate = upstreamRef?.trim() ?? "";
58
+ if (!candidate)
59
+ return opts.baseBranch;
60
+ try {
61
+ const { stdout } = await execFileAsync("git", ["rev-parse", "--verify", candidate], {
62
+ cwd: opts.gitRoot,
63
+ env: gitEnv(),
64
+ });
65
+ return stdout.trim() ? candidate : opts.baseBranch;
66
+ }
67
+ catch (err) {
68
+ if (!isUnknownRevisionError(err))
69
+ throw err;
70
+ return opts.baseBranch;
71
+ }
72
+ }
73
+ export async function computePrDiffstat(opts) {
74
+ const diffBaseRef = await resolvePrDiffBaseRef({
75
+ gitRoot: opts.gitRoot,
76
+ baseBranch: opts.baseBranch,
77
+ });
78
+ const taskDir = path.dirname(opts.prDir);
79
+ try {
80
+ return await gitDiffStat(opts.gitRoot, diffBaseRef, opts.branch, {
81
+ excludePaths: [
82
+ path.relative(opts.gitRoot, opts.prDir),
83
+ path.relative(opts.gitRoot, path.join(taskDir, "README.md")),
84
+ ],
85
+ });
86
+ }
87
+ catch (err) {
88
+ if (!isUnknownRevisionError(err))
89
+ throw err;
90
+ return "";
91
+ }
92
+ }
93
+ export async function resolvePrSyncBranch(opts) {
94
+ const explicitBranch = opts.branch?.trim() ?? "";
95
+ if (explicitBranch) {
96
+ return { branch: explicitBranch, source: "explicit" };
97
+ }
98
+ if (await fileExists(opts.metaPath)) {
99
+ const metaBranch = parsePrMeta(await readFile(opts.metaPath, "utf8"), opts.taskId).branch?.trim() ?? "";
100
+ if (metaBranch) {
101
+ return { branch: metaBranch, source: "meta" };
102
+ }
103
+ }
104
+ const currentBranchValue = await gitCurrentBranch(opts.gitRoot);
105
+ const currentBranch = currentBranchValue.trim();
106
+ if (currentBranch) {
107
+ return { branch: currentBranch, source: "current" };
108
+ }
109
+ return { branch: null, source: "none" };
110
+ }
111
+ export function currentBranchMatchesTask(taskPrefix, branch, taskId) {
112
+ return parseTaskIdFromBranch(taskPrefix, branch) === taskId;
113
+ }
@@ -0,0 +1,28 @@
1
+ export type ObservedGithubPr = {
2
+ prNumber: number;
3
+ prUrl: string | null;
4
+ status: "OPEN" | "CLOSED" | "MERGED";
5
+ mergedAt: string | null;
6
+ mergeCommit: string | null;
7
+ base: string | null;
8
+ headSha: string | null;
9
+ };
10
+ export declare function tryLookupExistingGithubPrByBranch(opts: {
11
+ gitRoot: string;
12
+ branch: string;
13
+ baseBranch?: string | null;
14
+ }): Promise<ObservedGithubPr | null>;
15
+ export declare function formatGithubPrLink(prNumber: number, prUrl: string | null, verb: "linked to" | "created"): string;
16
+ export declare function shouldPersistObservedGithubPrMeta(observed: ObservedGithubPr | null): boolean;
17
+ export declare function formatUnpublishedRemoteHeadReason(branch: string): string;
18
+ export declare function tryCreateGithubPr(opts: {
19
+ gitRoot: string;
20
+ branch: string;
21
+ baseBranch: string | null;
22
+ title: string;
23
+ body: string;
24
+ }): Promise<{
25
+ observed: ObservedGithubPr | null;
26
+ stagedReason: string | null;
27
+ }>;
28
+ //# sourceMappingURL=sync-github.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"sync-github.d.ts","sourceRoot":"","sources":["../../../../src/commands/pr/internal/sync-github.ts"],"names":[],"mappings":"AAsBA,MAAM,MAAM,gBAAgB,GAAG;IAC7B,QAAQ,EAAE,MAAM,CAAC;IACjB,KAAK,EAAE,MAAM,GAAG,IAAI,CAAC;IACrB,MAAM,EAAE,MAAM,GAAG,QAAQ,GAAG,QAAQ,CAAC;IACrC,QAAQ,EAAE,MAAM,GAAG,IAAI,CAAC;IACxB,WAAW,EAAE,MAAM,GAAG,IAAI,CAAC;IAC3B,IAAI,EAAE,MAAM,GAAG,IAAI,CAAC;IACpB,OAAO,EAAE,MAAM,GAAG,IAAI,CAAC;CACxB,CAAC;AAqDF,wBAAsB,iCAAiC,CAAC,IAAI,EAAE;IAC5D,OAAO,EAAE,MAAM,CAAC;IAChB,MAAM,EAAE,MAAM,CAAC;IACf,UAAU,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;CAC5B,GAAG,OAAO,CAAC,gBAAgB,GAAG,IAAI,CAAC,CAmCnC;AAED,wBAAgB,kBAAkB,CAChC,QAAQ,EAAE,MAAM,EAChB,KAAK,EAAE,MAAM,GAAG,IAAI,EACpB,IAAI,EAAE,WAAW,GAAG,SAAS,GAC5B,MAAM,CAIR;AAED,wBAAgB,iCAAiC,CAAC,QAAQ,EAAE,gBAAgB,GAAG,IAAI,GAAG,OAAO,CAG5F;AAED,wBAAgB,iCAAiC,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,CAKxE;AAqCD,wBAAsB,iBAAiB,CAAC,IAAI,EAAE;IAC5C,OAAO,EAAE,MAAM,CAAC;IAChB,MAAM,EAAE,MAAM,CAAC;IACf,UAAU,EAAE,MAAM,GAAG,IAAI,CAAC;IAC1B,KAAK,EAAE,MAAM,CAAC;IACd,IAAI,EAAE,MAAM,CAAC;CACd,GAAG,OAAO,CAAC;IACV,QAAQ,EAAE,gBAAgB,GAAG,IAAI,CAAC;IAClC,YAAY,EAAE,MAAM,GAAG,IAAI,CAAC;CAC7B,CAAC,CA8CD"}
@@ -0,0 +1,178 @@
1
+ import { execFileAsync } from "../../shared/git.js";
2
+ import { isTransientGhTransportError, normalizeGhTransportError, withGhTransportRetry, } from "../../shared/gh-transport.js";
3
+ import { ghEnv } from "./gh-api.js";
4
+ function parseGithubRepoFromRemoteUrl(remoteUrl) {
5
+ const trimmed = remoteUrl.trim();
6
+ if (!trimmed)
7
+ return null;
8
+ const httpsMatch = /^https?:\/\/github\.com\/([^/]+)\/([^/]+?)(?:\.git)?\/?$/.exec(trimmed);
9
+ if (httpsMatch)
10
+ return `${httpsMatch[1]}/${httpsMatch[2]}`;
11
+ const sshMatch = /^git@github\.com:([^/]+)\/([^/]+?)(?:\.git)?$/.exec(trimmed);
12
+ if (sshMatch)
13
+ return `${sshMatch[1]}/${sshMatch[2]}`;
14
+ return null;
15
+ }
16
+ async function resolveGithubRepoFromOrigin(gitRoot) {
17
+ try {
18
+ const { stdout } = await execFileAsync("git", ["remote", "get-url", "origin"], {
19
+ cwd: gitRoot,
20
+ env: process.env,
21
+ });
22
+ return parseGithubRepoFromRemoteUrl(stdout);
23
+ }
24
+ catch {
25
+ return null;
26
+ }
27
+ }
28
+ function normalizeObservedGithubPr(record) {
29
+ const number = Number(record.number);
30
+ if (!Number.isInteger(number) || number <= 0)
31
+ return null;
32
+ const state = record.state?.trim().toLowerCase() ?? "";
33
+ const mergedAt = record.merged_at?.trim() ?? null;
34
+ const status = mergedAt && mergedAt.length > 0
35
+ ? "MERGED"
36
+ : state === "open"
37
+ ? "OPEN"
38
+ : state === "closed"
39
+ ? "CLOSED"
40
+ : null;
41
+ if (!status)
42
+ return null;
43
+ const prUrl = record.html_url?.trim() ?? null;
44
+ const mergeCommit = record.merge_commit_sha?.trim() ?? null;
45
+ const base = record.base?.ref?.trim() ?? null;
46
+ const headSha = record.head?.sha?.trim() ?? null;
47
+ return {
48
+ prNumber: number,
49
+ prUrl,
50
+ status,
51
+ mergedAt,
52
+ mergeCommit,
53
+ base,
54
+ headSha,
55
+ };
56
+ }
57
+ export async function tryLookupExistingGithubPrByBranch(opts) {
58
+ const repo = await resolveGithubRepoFromOrigin(opts.gitRoot);
59
+ if (!repo)
60
+ return null;
61
+ const owner = repo.split("/")[0]?.trim() ?? "";
62
+ if (!owner)
63
+ return null;
64
+ const query = new URLSearchParams({ state: "all", head: `${owner}:${opts.branch}` });
65
+ const baseBranch = opts.baseBranch?.trim() ?? "";
66
+ if (baseBranch)
67
+ query.set("base", baseBranch);
68
+ const endpoint = `repos/${repo}/pulls?${query.toString()}`;
69
+ try {
70
+ const { stdout } = await withGhTransportRetry(() => execFileAsync("gh", ["api", endpoint], {
71
+ cwd: opts.gitRoot,
72
+ env: ghEnv(),
73
+ maxBuffer: 10 * 1024 * 1024,
74
+ }), { label: `running gh api ${endpoint}` });
75
+ const parsed = JSON.parse(stdout);
76
+ if (!Array.isArray(parsed) || parsed.length === 0)
77
+ return null;
78
+ for (const record of parsed) {
79
+ const observed = normalizeObservedGithubPr(record);
80
+ if (observed)
81
+ return observed;
82
+ }
83
+ return null;
84
+ }
85
+ catch (err) {
86
+ const code = err?.code;
87
+ if (code === "ENOENT")
88
+ return null;
89
+ const message = normalizeGhTransportError(err);
90
+ if (message.trim().length > 0)
91
+ return null;
92
+ return null;
93
+ }
94
+ }
95
+ export function formatGithubPrLink(prNumber, prUrl, verb) {
96
+ return prUrl?.trim()
97
+ ? `${verb} GitHub PR #${prNumber}: ${prUrl.trim()}`
98
+ : `${verb} GitHub PR #${prNumber}`;
99
+ }
100
+ export function shouldPersistObservedGithubPrMeta(observed) {
101
+ if (!observed)
102
+ return false;
103
+ return observed.status === "MERGED";
104
+ }
105
+ export function formatUnpublishedRemoteHeadReason(branch) {
106
+ return (`task branch ${branch} is not yet published on origin; push it with ` +
107
+ `\`git push -u origin ${branch}\` and rerun \`agentplane pr open\``);
108
+ }
109
+ function isMissingRemoteHeadCreateError(err) {
110
+ const text = normalizeGhTransportError(err);
111
+ if (!/\b422\b/i.test(text))
112
+ return false;
113
+ return (/head sha/i.test(text) ||
114
+ /head ref/i.test(text) ||
115
+ /head.*must be a branch/i.test(text) ||
116
+ /head.*not found/i.test(text) ||
117
+ /field["']?\s*:\s*["']head["']/i.test(text) ||
118
+ /field\s+head\b/i.test(text) ||
119
+ /no commits between/i.test(text));
120
+ }
121
+ function summarizeGithubPrCreateFailure(err) {
122
+ const text = normalizeGhTransportError(err);
123
+ if (err?.code === "ENOENT") {
124
+ return "gh CLI is unavailable";
125
+ }
126
+ if (/authentication required/i.test(text) ||
127
+ /not logged into github/i.test(text) ||
128
+ /bad credentials/i.test(text) ||
129
+ /permission denied/i.test(text) ||
130
+ /\b401\b/i.test(text) ||
131
+ /\b403\b/i.test(text)) {
132
+ return "GitHub auth or permissions unavailable";
133
+ }
134
+ if (isTransientGhTransportError(err)) {
135
+ return "GitHub transport failed; retry `agentplane pr open`";
136
+ }
137
+ return "GitHub PR creation failed";
138
+ }
139
+ export async function tryCreateGithubPr(opts) {
140
+ const repo = await resolveGithubRepoFromOrigin(opts.gitRoot);
141
+ if (!repo) {
142
+ return { observed: null, stagedReason: "GitHub origin repo unavailable" };
143
+ }
144
+ const baseBranch = opts.baseBranch?.trim() ?? "";
145
+ if (!baseBranch) {
146
+ return { observed: null, stagedReason: "base branch unresolved" };
147
+ }
148
+ try {
149
+ const { stdout } = await withGhTransportRetry(() => execFileAsync("gh", [
150
+ "api",
151
+ `repos/${repo}/pulls`,
152
+ "-X",
153
+ "POST",
154
+ "-f",
155
+ `title=${opts.title}`,
156
+ "-f",
157
+ `body=${opts.body}`,
158
+ "-f",
159
+ `head=${opts.branch}`,
160
+ "-f",
161
+ `base=${baseBranch}`,
162
+ ], {
163
+ cwd: opts.gitRoot,
164
+ env: ghEnv(),
165
+ maxBuffer: 10 * 1024 * 1024,
166
+ }), { label: `running gh api repos/${repo}/pulls` });
167
+ return {
168
+ observed: normalizeObservedGithubPr(JSON.parse(stdout)),
169
+ stagedReason: null,
170
+ };
171
+ }
172
+ catch (err) {
173
+ if (isMissingRemoteHeadCreateError(err)) {
174
+ return { observed: null, stagedReason: formatUnpublishedRemoteHeadReason(opts.branch) };
175
+ }
176
+ return { observed: null, stagedReason: summarizeGithubPrCreateFailure(err) };
177
+ }
178
+ }
@@ -0,0 +1,36 @@
1
+ import type { TaskData } from "../../../backends/task-backend.js";
2
+ import type { PrMeta } from "../../shared/pr-meta.js";
3
+ import type { readPrHandoffNotes } from "./note-store.js";
4
+ export type PrRemoteMode = "auto" | "sync-only";
5
+ export type PrOpenOutcome = {
6
+ action: "linked-existing" | "created" | "sync-only" | "staged";
7
+ message: string;
8
+ };
9
+ export type PrSyncResolved = {
10
+ gitRoot: string;
11
+ };
12
+ export type PrSyncCommonState = {
13
+ task: TaskData;
14
+ resolved: PrSyncResolved;
15
+ workflowDir: string;
16
+ tasksPath: string;
17
+ prDir: string;
18
+ metaPath: string;
19
+ diffstatPath: string;
20
+ notesPath: string;
21
+ verifyLogPath: string;
22
+ reviewPath: string;
23
+ githubTitlePath: string;
24
+ githubBodyPath: string;
25
+ existingMeta: PrMeta | null;
26
+ handoffNotes: Awaited<ReturnType<typeof readPrHandoffNotes>>;
27
+ now: string;
28
+ createdAt: string;
29
+ branch: string;
30
+ baseBranch: string | null;
31
+ headSha: string | null;
32
+ artifactRefresh: boolean;
33
+ renderedHeadSha: string | undefined;
34
+ renderUpdatedAt: string;
35
+ };
36
+ //# sourceMappingURL=sync-model.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"sync-model.d.ts","sourceRoot":"","sources":["../../../../src/commands/pr/internal/sync-model.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,mCAAmC,CAAC;AAClE,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,yBAAyB,CAAC;AACtD,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,iBAAiB,CAAC;AAE1D,MAAM,MAAM,YAAY,GAAG,MAAM,GAAG,WAAW,CAAC;AAEhD,MAAM,MAAM,aAAa,GAAG;IAC1B,MAAM,EAAE,iBAAiB,GAAG,SAAS,GAAG,WAAW,GAAG,QAAQ,CAAC;IAC/D,OAAO,EAAE,MAAM,CAAC;CACjB,CAAC;AAEF,MAAM,MAAM,cAAc,GAAG;IAAE,OAAO,EAAE,MAAM,CAAA;CAAE,CAAC;AAEjD,MAAM,MAAM,iBAAiB,GAAG;IAC9B,IAAI,EAAE,QAAQ,CAAC;IACf,QAAQ,EAAE,cAAc,CAAC;IACzB,WAAW,EAAE,MAAM,CAAC;IACpB,SAAS,EAAE,MAAM,CAAC;IAClB,KAAK,EAAE,MAAM,CAAC;IACd,QAAQ,EAAE,MAAM,CAAC;IACjB,YAAY,EAAE,MAAM,CAAC;IACrB,SAAS,EAAE,MAAM,CAAC;IAClB,aAAa,EAAE,MAAM,CAAC;IACtB,UAAU,EAAE,MAAM,CAAC;IACnB,eAAe,EAAE,MAAM,CAAC;IACxB,cAAc,EAAE,MAAM,CAAC;IACvB,YAAY,EAAE,MAAM,GAAG,IAAI,CAAC;IAC5B,YAAY,EAAE,OAAO,CAAC,UAAU,CAAC,OAAO,kBAAkB,CAAC,CAAC,CAAC;IAC7D,GAAG,EAAE,MAAM,CAAC;IACZ,SAAS,EAAE,MAAM,CAAC;IAClB,MAAM,EAAE,MAAM,CAAC;IACf,UAAU,EAAE,MAAM,GAAG,IAAI,CAAC;IAC1B,OAAO,EAAE,MAAM,GAAG,IAAI,CAAC;IACvB,eAAe,EAAE,OAAO,CAAC;IACzB,eAAe,EAAE,MAAM,GAAG,SAAS,CAAC;IACpC,eAAe,EAAE,MAAM,CAAC;CACzB,CAAC"}
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,10 @@
1
+ import { type PrMeta } from "../../shared/pr-meta.js";
2
+ import type { PrOpenOutcome, PrRemoteMode, PrSyncCommonState } from "./sync-model.js";
3
+ export declare function runPrOpenSync(common: PrSyncCommonState, opts: {
4
+ author?: string;
5
+ remoteMode: PrRemoteMode;
6
+ }): Promise<{
7
+ meta: PrMeta;
8
+ openOutcome?: PrOpenOutcome;
9
+ }>;
10
+ //# sourceMappingURL=sync-open-step.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"sync-open-step.d.ts","sourceRoot":"","sources":["../../../../src/commands/pr/internal/sync-open-step.ts"],"names":[],"mappings":"AAEA,OAAO,EAAgD,KAAK,MAAM,EAAE,MAAM,yBAAyB,CAAC;AAcpG,OAAO,KAAK,EAAE,aAAa,EAAE,YAAY,EAAE,iBAAiB,EAAE,MAAM,iBAAiB,CAAC;AAEtF,wBAAsB,aAAa,CACjC,MAAM,EAAE,iBAAiB,EACzB,IAAI,EAAE;IAAE,MAAM,CAAC,EAAE,MAAM,CAAC;IAAC,UAAU,EAAE,YAAY,CAAA;CAAE,GAClD,OAAO,CAAC;IACT,IAAI,EAAE,MAAM,CAAC;IACb,WAAW,CAAC,EAAE,aAAa,CAAC;CAC7B,CAAC,CA2HD"}