@ghx-dev/core 0.1.0 → 0.1.2

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 (494) hide show
  1. package/README.md +19 -7
  2. package/dist/agent.d.ts +32 -7
  3. package/dist/agent.js +27 -12
  4. package/dist/agent.js.map +1 -1
  5. package/dist/cards/project_v2.fields.list.yaml +2 -2
  6. package/dist/cards/project_v2.item.add_issue.yaml +2 -2
  7. package/dist/cards/project_v2.item.field.update.yaml +2 -2
  8. package/dist/cards/project_v2.items.list.yaml +2 -2
  9. package/dist/cards/project_v2.org.get.yaml +2 -2
  10. package/dist/cards/project_v2.user.get.yaml +2 -2
  11. package/dist/cards/repo.issue_types.list.yaml +2 -2
  12. package/dist/{chunk-4PLVKNCF.js → chunk-2FCPR3XZ.js} +14 -4
  13. package/dist/chunk-2FCPR3XZ.js.map +1 -0
  14. package/dist/chunk-RDUPMVHG.js +4139 -0
  15. package/dist/chunk-RDUPMVHG.js.map +1 -0
  16. package/dist/{chunk-JH6GM6XU.js → chunk-UN5YHUNK.js} +119 -7
  17. package/dist/chunk-UN5YHUNK.js.map +1 -0
  18. package/dist/cli/assets/skills/ghx/SKILL.md +57 -0
  19. package/dist/cli/index.js +373 -41
  20. package/dist/cli/index.js.map +1 -1
  21. package/dist/core/registry/cards/project_v2.fields.list.yaml +2 -2
  22. package/dist/core/registry/cards/project_v2.item.add_issue.yaml +2 -2
  23. package/dist/core/registry/cards/project_v2.item.field.update.yaml +2 -2
  24. package/dist/core/registry/cards/project_v2.items.list.yaml +2 -2
  25. package/dist/core/registry/cards/project_v2.org.get.yaml +2 -2
  26. package/dist/core/registry/cards/project_v2.user.get.yaml +2 -2
  27. package/dist/core/registry/cards/repo.issue_types.list.yaml +2 -2
  28. package/dist/{core/contracts/envelope.d.ts → envelope-BpF6MNCv.d.ts} +15 -3
  29. package/dist/index.d.ts +470 -22
  30. package/dist/index.js +6 -30
  31. package/package.json +13 -14
  32. package/dist/agent-interface/prompt/main-skill.d.ts +0 -3
  33. package/dist/agent-interface/prompt/main-skill.js +0 -7
  34. package/dist/agent-interface/prompt/main-skill.js.map +0 -1
  35. package/dist/agent-interface/tools/execute-tool.d.ts +0 -16
  36. package/dist/agent-interface/tools/execute-tool.js +0 -7
  37. package/dist/agent-interface/tools/execute-tool.js.map +0 -1
  38. package/dist/agent-interface/tools/explain-tool.d.ts +0 -11
  39. package/dist/agent-interface/tools/explain-tool.js +0 -9
  40. package/dist/agent-interface/tools/explain-tool.js.map +0 -1
  41. package/dist/agent-interface/tools/list-capabilities-tool.d.ts +0 -7
  42. package/dist/agent-interface/tools/list-capabilities-tool.js +0 -9
  43. package/dist/agent-interface/tools/list-capabilities-tool.js.map +0 -1
  44. package/dist/chunk-22WWCK6A.js +0 -92
  45. package/dist/chunk-22WWCK6A.js.map +0 -1
  46. package/dist/chunk-2W4L5YCC.js +0 -116
  47. package/dist/chunk-2W4L5YCC.js.map +0 -1
  48. package/dist/chunk-3MRJX72M.js +0 -209
  49. package/dist/chunk-3MRJX72M.js.map +0 -1
  50. package/dist/chunk-4PLVKNCF.js.map +0 -1
  51. package/dist/chunk-573MDG3I.js +0 -18
  52. package/dist/chunk-573MDG3I.js.map +0 -1
  53. package/dist/chunk-5JRLVOF2.js +0 -50
  54. package/dist/chunk-5JRLVOF2.js.map +0 -1
  55. package/dist/chunk-B6RLMKS4.js +0 -41
  56. package/dist/chunk-B6RLMKS4.js.map +0 -1
  57. package/dist/chunk-D746VR3B.js +0 -38
  58. package/dist/chunk-D746VR3B.js.map +0 -1
  59. package/dist/chunk-DJIEG6K7.js +0 -20
  60. package/dist/chunk-DJIEG6K7.js.map +0 -1
  61. package/dist/chunk-DLKIQBK6.js +0 -106
  62. package/dist/chunk-DLKIQBK6.js.map +0 -1
  63. package/dist/chunk-EBRDO4Y6.js +0 -31
  64. package/dist/chunk-EBRDO4Y6.js.map +0 -1
  65. package/dist/chunk-FXN6IIT5.js +0 -14
  66. package/dist/chunk-FXN6IIT5.js.map +0 -1
  67. package/dist/chunk-GMTG7X2L.js +0 -16
  68. package/dist/chunk-GMTG7X2L.js.map +0 -1
  69. package/dist/chunk-HQ2VRCH7.js +0 -42
  70. package/dist/chunk-HQ2VRCH7.js.map +0 -1
  71. package/dist/chunk-JH6GM6XU.js.map +0 -1
  72. package/dist/chunk-JLDU462R.js +0 -1352
  73. package/dist/chunk-JLDU462R.js.map +0 -1
  74. package/dist/chunk-MGNGSGMF.js +0 -203
  75. package/dist/chunk-MGNGSGMF.js.map +0 -1
  76. package/dist/chunk-NFF5VF4U.js +0 -28
  77. package/dist/chunk-NFF5VF4U.js.map +0 -1
  78. package/dist/chunk-QEAMC4IJ.js +0 -34
  79. package/dist/chunk-QEAMC4IJ.js.map +0 -1
  80. package/dist/chunk-QZZC53HF.js +0 -38
  81. package/dist/chunk-QZZC53HF.js.map +0 -1
  82. package/dist/chunk-RUQXGZ35.js +0 -34
  83. package/dist/chunk-RUQXGZ35.js.map +0 -1
  84. package/dist/chunk-SA2D4A5U.js +0 -1496
  85. package/dist/chunk-SA2D4A5U.js.map +0 -1
  86. package/dist/chunk-SD7U4BNA.js +0 -174
  87. package/dist/chunk-SD7U4BNA.js.map +0 -1
  88. package/dist/chunk-SJR2SACI.js +0 -30
  89. package/dist/chunk-SJR2SACI.js.map +0 -1
  90. package/dist/chunk-TCLMLVUQ.js +0 -38
  91. package/dist/chunk-TCLMLVUQ.js.map +0 -1
  92. package/dist/chunk-TDTKOJKN.js +0 -52
  93. package/dist/chunk-TDTKOJKN.js.map +0 -1
  94. package/dist/chunk-UGWIZ3RI.js +0 -7
  95. package/dist/chunk-UGWIZ3RI.js.map +0 -1
  96. package/dist/chunk-UOJWOHRM.js +0 -16
  97. package/dist/chunk-UOJWOHRM.js.map +0 -1
  98. package/dist/chunk-VD5NXQP7.js +0 -42
  99. package/dist/chunk-VD5NXQP7.js.map +0 -1
  100. package/dist/chunk-W2TKG2UL.js +0 -37
  101. package/dist/chunk-W2TKG2UL.js.map +0 -1
  102. package/dist/chunk-W6ROKCY5.js +0 -28
  103. package/dist/chunk-W6ROKCY5.js.map +0 -1
  104. package/dist/chunk-XNMM64WU.js +0 -221
  105. package/dist/chunk-XNMM64WU.js.map +0 -1
  106. package/dist/cli/commands/capabilities-explain.d.ts +0 -3
  107. package/dist/cli/commands/capabilities-explain.js +0 -10
  108. package/dist/cli/commands/capabilities-explain.js.map +0 -1
  109. package/dist/cli/commands/capabilities-list.d.ts +0 -3
  110. package/dist/cli/commands/capabilities-list.js +0 -10
  111. package/dist/cli/commands/capabilities-list.js.map +0 -1
  112. package/dist/cli/commands/doctor.d.ts +0 -3
  113. package/dist/cli/commands/doctor.js +0 -7
  114. package/dist/cli/commands/doctor.js.map +0 -1
  115. package/dist/cli/commands/routes.d.ts +0 -3
  116. package/dist/cli/commands/routes.js +0 -7
  117. package/dist/cli/commands/routes.js.map +0 -1
  118. package/dist/cli/commands/run.d.ts +0 -3
  119. package/dist/cli/commands/run.js +0 -31
  120. package/dist/cli/commands/run.js.map +0 -1
  121. package/dist/cli/commands/setup.d.ts +0 -3
  122. package/dist/cli/commands/setup.js +0 -7
  123. package/dist/cli/commands/setup.js.map +0 -1
  124. package/dist/cli/formatters/json.d.ts +0 -3
  125. package/dist/cli/formatters/json.js +0 -8
  126. package/dist/cli/formatters/json.js.map +0 -1
  127. package/dist/cli/formatters/table.d.ts +0 -3
  128. package/dist/cli/formatters/table.js +0 -8
  129. package/dist/cli/formatters/table.js.map +0 -1
  130. package/dist/core/contracts/envelope.js +0 -1
  131. package/dist/core/contracts/envelope.js.map +0 -1
  132. package/dist/core/contracts/task.d.ts +0 -7
  133. package/dist/core/contracts/task.js +0 -1
  134. package/dist/core/contracts/task.js.map +0 -1
  135. package/dist/core/contracts/tasks/check_run.annotations.list.d.ts +0 -5
  136. package/dist/core/contracts/tasks/check_run.annotations.list.js +0 -8
  137. package/dist/core/contracts/tasks/check_run.annotations.list.js.map +0 -1
  138. package/dist/core/contracts/tasks/issue.assignees.update.d.ts +0 -5
  139. package/dist/core/contracts/tasks/issue.assignees.update.js +0 -8
  140. package/dist/core/contracts/tasks/issue.assignees.update.js.map +0 -1
  141. package/dist/core/contracts/tasks/issue.blocked_by.add.d.ts +0 -5
  142. package/dist/core/contracts/tasks/issue.blocked_by.add.js +0 -8
  143. package/dist/core/contracts/tasks/issue.blocked_by.add.js.map +0 -1
  144. package/dist/core/contracts/tasks/issue.blocked_by.remove.d.ts +0 -5
  145. package/dist/core/contracts/tasks/issue.blocked_by.remove.js +0 -8
  146. package/dist/core/contracts/tasks/issue.blocked_by.remove.js.map +0 -1
  147. package/dist/core/contracts/tasks/issue.close.d.ts +0 -5
  148. package/dist/core/contracts/tasks/issue.close.js +0 -8
  149. package/dist/core/contracts/tasks/issue.close.js.map +0 -1
  150. package/dist/core/contracts/tasks/issue.comments.create.d.ts +0 -5
  151. package/dist/core/contracts/tasks/issue.comments.create.js +0 -8
  152. package/dist/core/contracts/tasks/issue.comments.create.js.map +0 -1
  153. package/dist/core/contracts/tasks/issue.comments.list.d.ts +0 -5
  154. package/dist/core/contracts/tasks/issue.comments.list.js +0 -8
  155. package/dist/core/contracts/tasks/issue.comments.list.js.map +0 -1
  156. package/dist/core/contracts/tasks/issue.create.d.ts +0 -5
  157. package/dist/core/contracts/tasks/issue.create.js +0 -8
  158. package/dist/core/contracts/tasks/issue.create.js.map +0 -1
  159. package/dist/core/contracts/tasks/issue.delete.d.ts +0 -5
  160. package/dist/core/contracts/tasks/issue.delete.js +0 -8
  161. package/dist/core/contracts/tasks/issue.delete.js.map +0 -1
  162. package/dist/core/contracts/tasks/issue.labels.update.d.ts +0 -5
  163. package/dist/core/contracts/tasks/issue.labels.update.js +0 -8
  164. package/dist/core/contracts/tasks/issue.labels.update.js.map +0 -1
  165. package/dist/core/contracts/tasks/issue.linked_prs.list.d.ts +0 -5
  166. package/dist/core/contracts/tasks/issue.linked_prs.list.js +0 -8
  167. package/dist/core/contracts/tasks/issue.linked_prs.list.js.map +0 -1
  168. package/dist/core/contracts/tasks/issue.list.d.ts +0 -5
  169. package/dist/core/contracts/tasks/issue.list.js +0 -8
  170. package/dist/core/contracts/tasks/issue.list.js.map +0 -1
  171. package/dist/core/contracts/tasks/issue.milestone.set.d.ts +0 -5
  172. package/dist/core/contracts/tasks/issue.milestone.set.js +0 -8
  173. package/dist/core/contracts/tasks/issue.milestone.set.js.map +0 -1
  174. package/dist/core/contracts/tasks/issue.parent.remove.d.ts +0 -5
  175. package/dist/core/contracts/tasks/issue.parent.remove.js +0 -8
  176. package/dist/core/contracts/tasks/issue.parent.remove.js.map +0 -1
  177. package/dist/core/contracts/tasks/issue.parent.set.d.ts +0 -5
  178. package/dist/core/contracts/tasks/issue.parent.set.js +0 -8
  179. package/dist/core/contracts/tasks/issue.parent.set.js.map +0 -1
  180. package/dist/core/contracts/tasks/issue.relations.get.d.ts +0 -5
  181. package/dist/core/contracts/tasks/issue.relations.get.js +0 -8
  182. package/dist/core/contracts/tasks/issue.relations.get.js.map +0 -1
  183. package/dist/core/contracts/tasks/issue.reopen.d.ts +0 -5
  184. package/dist/core/contracts/tasks/issue.reopen.js +0 -8
  185. package/dist/core/contracts/tasks/issue.reopen.js.map +0 -1
  186. package/dist/core/contracts/tasks/issue.update.d.ts +0 -5
  187. package/dist/core/contracts/tasks/issue.update.js +0 -8
  188. package/dist/core/contracts/tasks/issue.update.js.map +0 -1
  189. package/dist/core/contracts/tasks/issue.view.d.ts +0 -5
  190. package/dist/core/contracts/tasks/issue.view.js +0 -8
  191. package/dist/core/contracts/tasks/issue.view.js.map +0 -1
  192. package/dist/core/contracts/tasks/pr.assignees.update.d.ts +0 -5
  193. package/dist/core/contracts/tasks/pr.assignees.update.js +0 -8
  194. package/dist/core/contracts/tasks/pr.assignees.update.js.map +0 -1
  195. package/dist/core/contracts/tasks/pr.branch.update.d.ts +0 -5
  196. package/dist/core/contracts/tasks/pr.branch.update.js +0 -8
  197. package/dist/core/contracts/tasks/pr.branch.update.js.map +0 -1
  198. package/dist/core/contracts/tasks/pr.checks.get_failed.d.ts +0 -5
  199. package/dist/core/contracts/tasks/pr.checks.get_failed.js +0 -8
  200. package/dist/core/contracts/tasks/pr.checks.get_failed.js.map +0 -1
  201. package/dist/core/contracts/tasks/pr.checks.rerun_all.d.ts +0 -5
  202. package/dist/core/contracts/tasks/pr.checks.rerun_all.js +0 -8
  203. package/dist/core/contracts/tasks/pr.checks.rerun_all.js.map +0 -1
  204. package/dist/core/contracts/tasks/pr.checks.rerun_failed.d.ts +0 -5
  205. package/dist/core/contracts/tasks/pr.checks.rerun_failed.js +0 -8
  206. package/dist/core/contracts/tasks/pr.checks.rerun_failed.js.map +0 -1
  207. package/dist/core/contracts/tasks/pr.comment.reply.d.ts +0 -5
  208. package/dist/core/contracts/tasks/pr.comment.reply.js +0 -8
  209. package/dist/core/contracts/tasks/pr.comment.reply.js.map +0 -1
  210. package/dist/core/contracts/tasks/pr.comment.resolve.d.ts +0 -5
  211. package/dist/core/contracts/tasks/pr.comment.resolve.js +0 -8
  212. package/dist/core/contracts/tasks/pr.comment.resolve.js.map +0 -1
  213. package/dist/core/contracts/tasks/pr.comment.unresolve.d.ts +0 -5
  214. package/dist/core/contracts/tasks/pr.comment.unresolve.js +0 -8
  215. package/dist/core/contracts/tasks/pr.comment.unresolve.js.map +0 -1
  216. package/dist/core/contracts/tasks/pr.comments.list.d.ts +0 -5
  217. package/dist/core/contracts/tasks/pr.comments.list.js +0 -8
  218. package/dist/core/contracts/tasks/pr.comments.list.js.map +0 -1
  219. package/dist/core/contracts/tasks/pr.diff.list_files.d.ts +0 -5
  220. package/dist/core/contracts/tasks/pr.diff.list_files.js +0 -8
  221. package/dist/core/contracts/tasks/pr.diff.list_files.js.map +0 -1
  222. package/dist/core/contracts/tasks/pr.list.d.ts +0 -5
  223. package/dist/core/contracts/tasks/pr.list.js +0 -8
  224. package/dist/core/contracts/tasks/pr.list.js.map +0 -1
  225. package/dist/core/contracts/tasks/pr.merge.execute.d.ts +0 -5
  226. package/dist/core/contracts/tasks/pr.merge.execute.js +0 -8
  227. package/dist/core/contracts/tasks/pr.merge.execute.js.map +0 -1
  228. package/dist/core/contracts/tasks/pr.mergeability.view.d.ts +0 -5
  229. package/dist/core/contracts/tasks/pr.mergeability.view.js +0 -8
  230. package/dist/core/contracts/tasks/pr.mergeability.view.js.map +0 -1
  231. package/dist/core/contracts/tasks/pr.ready_for_review.set.d.ts +0 -5
  232. package/dist/core/contracts/tasks/pr.ready_for_review.set.js +0 -8
  233. package/dist/core/contracts/tasks/pr.ready_for_review.set.js.map +0 -1
  234. package/dist/core/contracts/tasks/pr.review.submit_approve.d.ts +0 -5
  235. package/dist/core/contracts/tasks/pr.review.submit_approve.js +0 -8
  236. package/dist/core/contracts/tasks/pr.review.submit_approve.js.map +0 -1
  237. package/dist/core/contracts/tasks/pr.review.submit_comment.d.ts +0 -5
  238. package/dist/core/contracts/tasks/pr.review.submit_comment.js +0 -8
  239. package/dist/core/contracts/tasks/pr.review.submit_comment.js.map +0 -1
  240. package/dist/core/contracts/tasks/pr.review.submit_request_changes.d.ts +0 -5
  241. package/dist/core/contracts/tasks/pr.review.submit_request_changes.js +0 -8
  242. package/dist/core/contracts/tasks/pr.review.submit_request_changes.js.map +0 -1
  243. package/dist/core/contracts/tasks/pr.reviewers.request.d.ts +0 -5
  244. package/dist/core/contracts/tasks/pr.reviewers.request.js +0 -8
  245. package/dist/core/contracts/tasks/pr.reviewers.request.js.map +0 -1
  246. package/dist/core/contracts/tasks/pr.reviews.list.d.ts +0 -5
  247. package/dist/core/contracts/tasks/pr.reviews.list.js +0 -8
  248. package/dist/core/contracts/tasks/pr.reviews.list.js.map +0 -1
  249. package/dist/core/contracts/tasks/pr.status.checks.d.ts +0 -5
  250. package/dist/core/contracts/tasks/pr.status.checks.js +0 -8
  251. package/dist/core/contracts/tasks/pr.status.checks.js.map +0 -1
  252. package/dist/core/contracts/tasks/pr.view.d.ts +0 -5
  253. package/dist/core/contracts/tasks/pr.view.js +0 -8
  254. package/dist/core/contracts/tasks/pr.view.js.map +0 -1
  255. package/dist/core/contracts/tasks/project_v2.fields.list.d.ts +0 -5
  256. package/dist/core/contracts/tasks/project_v2.fields.list.js +0 -8
  257. package/dist/core/contracts/tasks/project_v2.fields.list.js.map +0 -1
  258. package/dist/core/contracts/tasks/project_v2.item.add_issue.d.ts +0 -5
  259. package/dist/core/contracts/tasks/project_v2.item.add_issue.js +0 -8
  260. package/dist/core/contracts/tasks/project_v2.item.add_issue.js.map +0 -1
  261. package/dist/core/contracts/tasks/project_v2.item.field.update.d.ts +0 -5
  262. package/dist/core/contracts/tasks/project_v2.item.field.update.js +0 -8
  263. package/dist/core/contracts/tasks/project_v2.item.field.update.js.map +0 -1
  264. package/dist/core/contracts/tasks/project_v2.items.list.d.ts +0 -5
  265. package/dist/core/contracts/tasks/project_v2.items.list.js +0 -8
  266. package/dist/core/contracts/tasks/project_v2.items.list.js.map +0 -1
  267. package/dist/core/contracts/tasks/project_v2.org.get.d.ts +0 -5
  268. package/dist/core/contracts/tasks/project_v2.org.get.js +0 -8
  269. package/dist/core/contracts/tasks/project_v2.org.get.js.map +0 -1
  270. package/dist/core/contracts/tasks/project_v2.user.get.d.ts +0 -5
  271. package/dist/core/contracts/tasks/project_v2.user.get.js +0 -8
  272. package/dist/core/contracts/tasks/project_v2.user.get.js.map +0 -1
  273. package/dist/core/contracts/tasks/release.create_draft.d.ts +0 -5
  274. package/dist/core/contracts/tasks/release.create_draft.js +0 -8
  275. package/dist/core/contracts/tasks/release.create_draft.js.map +0 -1
  276. package/dist/core/contracts/tasks/release.get.d.ts +0 -5
  277. package/dist/core/contracts/tasks/release.get.js +0 -8
  278. package/dist/core/contracts/tasks/release.get.js.map +0 -1
  279. package/dist/core/contracts/tasks/release.list.d.ts +0 -5
  280. package/dist/core/contracts/tasks/release.list.js +0 -8
  281. package/dist/core/contracts/tasks/release.list.js.map +0 -1
  282. package/dist/core/contracts/tasks/release.publish_draft.d.ts +0 -5
  283. package/dist/core/contracts/tasks/release.publish_draft.js +0 -8
  284. package/dist/core/contracts/tasks/release.publish_draft.js.map +0 -1
  285. package/dist/core/contracts/tasks/release.update.d.ts +0 -5
  286. package/dist/core/contracts/tasks/release.update.js +0 -8
  287. package/dist/core/contracts/tasks/release.update.js.map +0 -1
  288. package/dist/core/contracts/tasks/repo.issue_types.list.d.ts +0 -5
  289. package/dist/core/contracts/tasks/repo.issue_types.list.js +0 -8
  290. package/dist/core/contracts/tasks/repo.issue_types.list.js.map +0 -1
  291. package/dist/core/contracts/tasks/repo.labels.list.d.ts +0 -5
  292. package/dist/core/contracts/tasks/repo.labels.list.js +0 -8
  293. package/dist/core/contracts/tasks/repo.labels.list.js.map +0 -1
  294. package/dist/core/contracts/tasks/repo.view.d.ts +0 -5
  295. package/dist/core/contracts/tasks/repo.view.js +0 -8
  296. package/dist/core/contracts/tasks/repo.view.js.map +0 -1
  297. package/dist/core/contracts/tasks/workflow.get.d.ts +0 -5
  298. package/dist/core/contracts/tasks/workflow.get.js +0 -8
  299. package/dist/core/contracts/tasks/workflow.get.js.map +0 -1
  300. package/dist/core/contracts/tasks/workflow.list.d.ts +0 -5
  301. package/dist/core/contracts/tasks/workflow.list.js +0 -8
  302. package/dist/core/contracts/tasks/workflow.list.js.map +0 -1
  303. package/dist/core/contracts/tasks/workflow_dispatch.run.d.ts +0 -5
  304. package/dist/core/contracts/tasks/workflow_dispatch.run.js +0 -8
  305. package/dist/core/contracts/tasks/workflow_dispatch.run.js.map +0 -1
  306. package/dist/core/contracts/tasks/workflow_job.logs.analyze.d.ts +0 -5
  307. package/dist/core/contracts/tasks/workflow_job.logs.analyze.js +0 -8
  308. package/dist/core/contracts/tasks/workflow_job.logs.analyze.js.map +0 -1
  309. package/dist/core/contracts/tasks/workflow_job.logs.get.d.ts +0 -5
  310. package/dist/core/contracts/tasks/workflow_job.logs.get.js +0 -8
  311. package/dist/core/contracts/tasks/workflow_job.logs.get.js.map +0 -1
  312. package/dist/core/contracts/tasks/workflow_run.artifacts.list.d.ts +0 -5
  313. package/dist/core/contracts/tasks/workflow_run.artifacts.list.js +0 -8
  314. package/dist/core/contracts/tasks/workflow_run.artifacts.list.js.map +0 -1
  315. package/dist/core/contracts/tasks/workflow_run.cancel.d.ts +0 -5
  316. package/dist/core/contracts/tasks/workflow_run.cancel.js +0 -8
  317. package/dist/core/contracts/tasks/workflow_run.cancel.js.map +0 -1
  318. package/dist/core/contracts/tasks/workflow_run.get.d.ts +0 -5
  319. package/dist/core/contracts/tasks/workflow_run.get.js +0 -8
  320. package/dist/core/contracts/tasks/workflow_run.get.js.map +0 -1
  321. package/dist/core/contracts/tasks/workflow_run.jobs.list.d.ts +0 -5
  322. package/dist/core/contracts/tasks/workflow_run.jobs.list.js +0 -8
  323. package/dist/core/contracts/tasks/workflow_run.jobs.list.js.map +0 -1
  324. package/dist/core/contracts/tasks/workflow_run.rerun_all.d.ts +0 -5
  325. package/dist/core/contracts/tasks/workflow_run.rerun_all.js +0 -8
  326. package/dist/core/contracts/tasks/workflow_run.rerun_all.js.map +0 -1
  327. package/dist/core/contracts/tasks/workflow_run.rerun_failed.d.ts +0 -5
  328. package/dist/core/contracts/tasks/workflow_run.rerun_failed.js +0 -8
  329. package/dist/core/contracts/tasks/workflow_run.rerun_failed.js.map +0 -1
  330. package/dist/core/contracts/tasks/workflow_runs.list.d.ts +0 -5
  331. package/dist/core/contracts/tasks/workflow_runs.list.js +0 -8
  332. package/dist/core/contracts/tasks/workflow_runs.list.js.map +0 -1
  333. package/dist/core/errors/codes.d.ts +0 -13
  334. package/dist/core/errors/codes.js +0 -7
  335. package/dist/core/errors/codes.js.map +0 -1
  336. package/dist/core/errors/map-error.d.ts +0 -5
  337. package/dist/core/errors/map-error.js +0 -8
  338. package/dist/core/errors/map-error.js.map +0 -1
  339. package/dist/core/errors/retryability.d.ts +0 -3
  340. package/dist/core/errors/retryability.js +0 -8
  341. package/dist/core/errors/retryability.js.map +0 -1
  342. package/dist/core/execute/execute.d.ts +0 -28
  343. package/dist/core/execute/execute.js +0 -11
  344. package/dist/core/execute/execute.js.map +0 -1
  345. package/dist/core/execution/adapters/cli-adapter.d.ts +0 -22
  346. package/dist/core/execution/adapters/cli-adapter.js +0 -69
  347. package/dist/core/execution/adapters/cli-adapter.js.map +0 -1
  348. package/dist/core/execution/adapters/cli-capability-adapter.d.ts +0 -16
  349. package/dist/core/execution/adapters/cli-capability-adapter.js +0 -11
  350. package/dist/core/execution/adapters/cli-capability-adapter.js.map +0 -1
  351. package/dist/core/execution/adapters/graphql-adapter.d.ts +0 -25
  352. package/dist/core/execution/adapters/graphql-adapter.js +0 -44
  353. package/dist/core/execution/adapters/graphql-adapter.js.map +0 -1
  354. package/dist/core/execution/adapters/graphql-capability-adapter.d.ts +0 -20
  355. package/dist/core/execution/adapters/graphql-capability-adapter.js +0 -11
  356. package/dist/core/execution/adapters/graphql-capability-adapter.js.map +0 -1
  357. package/dist/core/execution/adapters/rest-adapter.d.ts +0 -3
  358. package/dist/core/execution/adapters/rest-adapter.js +0 -8
  359. package/dist/core/execution/adapters/rest-adapter.js.map +0 -1
  360. package/dist/core/execution/cli/safe-runner.d.ts +0 -12
  361. package/dist/core/execution/cli/safe-runner.js +0 -7
  362. package/dist/core/execution/cli/safe-runner.js.map +0 -1
  363. package/dist/core/execution/normalizer.d.ts +0 -13
  364. package/dist/core/execution/normalizer.js +0 -9
  365. package/dist/core/execution/normalizer.js.map +0 -1
  366. package/dist/core/execution/preflight.d.ts +0 -24
  367. package/dist/core/execution/preflight.js +0 -8
  368. package/dist/core/execution/preflight.js.map +0 -1
  369. package/dist/core/registry/index.d.ts +0 -15
  370. package/dist/core/registry/index.js +0 -12
  371. package/dist/core/registry/index.js.map +0 -1
  372. package/dist/core/registry/operation-card-schema.d.ts +0 -167
  373. package/dist/core/registry/operation-card-schema.js +0 -7
  374. package/dist/core/registry/operation-card-schema.js.map +0 -1
  375. package/dist/core/registry/schema-validator.d.ts +0 -16
  376. package/dist/core/registry/schema-validator.js +0 -9
  377. package/dist/core/registry/schema-validator.js.map +0 -1
  378. package/dist/core/registry/types.d.ts +0 -51
  379. package/dist/core/registry/types.js +0 -1
  380. package/dist/core/registry/types.js.map +0 -1
  381. package/dist/core/routing/capability-registry.d.ts +0 -8
  382. package/dist/core/routing/capability-registry.js +0 -15
  383. package/dist/core/routing/capability-registry.js.map +0 -1
  384. package/dist/core/routing/engine.d.ts +0 -32
  385. package/dist/core/routing/engine.js +0 -23
  386. package/dist/core/routing/engine.js.map +0 -1
  387. package/dist/core/routing/policy.d.ts +0 -3
  388. package/dist/core/routing/policy.js +0 -7
  389. package/dist/core/routing/policy.js.map +0 -1
  390. package/dist/core/routing/reason-codes.d.ts +0 -4
  391. package/dist/core/routing/reason-codes.js +0 -15
  392. package/dist/core/routing/reason-codes.js.map +0 -1
  393. package/dist/core/telemetry/logger.d.ts +0 -8
  394. package/dist/core/telemetry/logger.js +0 -9
  395. package/dist/core/telemetry/logger.js.map +0 -1
  396. package/dist/core/telemetry/metrics.d.ts +0 -7
  397. package/dist/core/telemetry/metrics.js +0 -1
  398. package/dist/core/telemetry/metrics.js.map +0 -1
  399. package/dist/gql/client.d.ts +0 -314
  400. package/dist/gql/client.js +0 -19
  401. package/dist/gql/client.js.map +0 -1
  402. package/dist/gql/generated/common-types.d.ts +0 -36
  403. package/dist/gql/generated/common-types.js +0 -1
  404. package/dist/gql/generated/common-types.js.map +0 -1
  405. package/dist/gql/operations/issue-assignees-update.generated.d.ts +0 -33
  406. package/dist/gql/operations/issue-assignees-update.generated.js +0 -28
  407. package/dist/gql/operations/issue-assignees-update.generated.js.map +0 -1
  408. package/dist/gql/operations/issue-blocked-by-add.generated.d.ts +0 -30
  409. package/dist/gql/operations/issue-blocked-by-add.generated.js +0 -26
  410. package/dist/gql/operations/issue-blocked-by-add.generated.js.map +0 -1
  411. package/dist/gql/operations/issue-blocked-by-remove.generated.d.ts +0 -30
  412. package/dist/gql/operations/issue-blocked-by-remove.generated.js +0 -26
  413. package/dist/gql/operations/issue-blocked-by-remove.generated.js.map +0 -1
  414. package/dist/gql/operations/issue-close.generated.d.ts +0 -27
  415. package/dist/gql/operations/issue-close.generated.js +0 -25
  416. package/dist/gql/operations/issue-close.generated.js.map +0 -1
  417. package/dist/gql/operations/issue-comment-create.generated.d.ts +0 -31
  418. package/dist/gql/operations/issue-comment-create.generated.js +0 -27
  419. package/dist/gql/operations/issue-comment-create.generated.js.map +0 -1
  420. package/dist/gql/operations/issue-comments-list.generated.d.ts +0 -59
  421. package/dist/gql/operations/issue-comments-list.generated.js +0 -9
  422. package/dist/gql/operations/issue-comments-list.generated.js.map +0 -1
  423. package/dist/gql/operations/issue-create.generated.d.ts +0 -31
  424. package/dist/gql/operations/issue-create.generated.js +0 -27
  425. package/dist/gql/operations/issue-create.generated.js.map +0 -1
  426. package/dist/gql/operations/issue-delete.generated.d.ts +0 -22
  427. package/dist/gql/operations/issue-delete.generated.js +0 -21
  428. package/dist/gql/operations/issue-delete.generated.js.map +0 -1
  429. package/dist/gql/operations/issue-labels-update.generated.d.ts +0 -33
  430. package/dist/gql/operations/issue-labels-update.generated.js +0 -28
  431. package/dist/gql/operations/issue-labels-update.generated.js.map +0 -1
  432. package/dist/gql/operations/issue-linked-prs-list.generated.d.ts +0 -132
  433. package/dist/gql/operations/issue-linked-prs-list.generated.js +0 -39
  434. package/dist/gql/operations/issue-linked-prs-list.generated.js.map +0 -1
  435. package/dist/gql/operations/issue-list.generated.d.ts +0 -40
  436. package/dist/gql/operations/issue-list.generated.js +0 -9
  437. package/dist/gql/operations/issue-list.generated.js.map +0 -1
  438. package/dist/gql/operations/issue-milestone-set.generated.d.ts +0 -30
  439. package/dist/gql/operations/issue-milestone-set.generated.js +0 -26
  440. package/dist/gql/operations/issue-milestone-set.generated.js.map +0 -1
  441. package/dist/gql/operations/issue-parent-remove.generated.d.ts +0 -30
  442. package/dist/gql/operations/issue-parent-remove.generated.js +0 -26
  443. package/dist/gql/operations/issue-parent-remove.generated.js.map +0 -1
  444. package/dist/gql/operations/issue-parent-set.generated.d.ts +0 -30
  445. package/dist/gql/operations/issue-parent-set.generated.js +0 -26
  446. package/dist/gql/operations/issue-parent-set.generated.js.map +0 -1
  447. package/dist/gql/operations/issue-relations-get.generated.d.ts +0 -49
  448. package/dist/gql/operations/issue-relations-get.generated.js +0 -40
  449. package/dist/gql/operations/issue-relations-get.generated.js.map +0 -1
  450. package/dist/gql/operations/issue-reopen.generated.d.ts +0 -27
  451. package/dist/gql/operations/issue-reopen.generated.js +0 -25
  452. package/dist/gql/operations/issue-reopen.generated.js.map +0 -1
  453. package/dist/gql/operations/issue-update.generated.d.ts +0 -31
  454. package/dist/gql/operations/issue-update.generated.js +0 -27
  455. package/dist/gql/operations/issue-update.generated.js.map +0 -1
  456. package/dist/gql/operations/issue-view.generated.d.ts +0 -31
  457. package/dist/gql/operations/issue-view.generated.js +0 -9
  458. package/dist/gql/operations/issue-view.generated.js.map +0 -1
  459. package/dist/gql/operations/pr-comment-reply.generated.d.ts +0 -26
  460. package/dist/gql/operations/pr-comment-reply.generated.js +0 -25
  461. package/dist/gql/operations/pr-comment-reply.generated.js.map +0 -1
  462. package/dist/gql/operations/pr-comment-resolve.generated.d.ts +0 -26
  463. package/dist/gql/operations/pr-comment-resolve.generated.js +0 -24
  464. package/dist/gql/operations/pr-comment-resolve.generated.js.map +0 -1
  465. package/dist/gql/operations/pr-comment-unresolve.generated.d.ts +0 -26
  466. package/dist/gql/operations/pr-comment-unresolve.generated.js +0 -24
  467. package/dist/gql/operations/pr-comment-unresolve.generated.js.map +0 -1
  468. package/dist/gql/operations/pr-comments-list.generated.d.ts +0 -84
  469. package/dist/gql/operations/pr-comments-list.generated.js +0 -58
  470. package/dist/gql/operations/pr-comments-list.generated.js.map +0 -1
  471. package/dist/gql/operations/pr-diff-list-files.generated.d.ts +0 -42
  472. package/dist/gql/operations/pr-diff-list-files.generated.js +0 -9
  473. package/dist/gql/operations/pr-diff-list-files.generated.js.map +0 -1
  474. package/dist/gql/operations/pr-list.generated.d.ts +0 -40
  475. package/dist/gql/operations/pr-list.generated.js +0 -9
  476. package/dist/gql/operations/pr-list.generated.js.map +0 -1
  477. package/dist/gql/operations/pr-reviews-list.generated.d.ts +0 -64
  478. package/dist/gql/operations/pr-reviews-list.generated.js +0 -9
  479. package/dist/gql/operations/pr-reviews-list.generated.js.map +0 -1
  480. package/dist/gql/operations/pr-view.generated.d.ts +0 -31
  481. package/dist/gql/operations/pr-view.generated.js +0 -9
  482. package/dist/gql/operations/pr-view.generated.js.map +0 -1
  483. package/dist/gql/operations/repo-view.generated.d.ts +0 -33
  484. package/dist/gql/operations/repo-view.generated.js +0 -9
  485. package/dist/gql/operations/repo-view.generated.js.map +0 -1
  486. package/dist/shared/constants.d.ts +0 -3
  487. package/dist/shared/constants.js +0 -6
  488. package/dist/shared/constants.js.map +0 -1
  489. package/dist/shared/types.d.ts +0 -3
  490. package/dist/shared/types.js +0 -1
  491. package/dist/shared/types.js.map +0 -1
  492. package/dist/shared/utils.d.ts +0 -3
  493. package/dist/shared/utils.js +0 -8
  494. package/dist/shared/utils.js.map +0 -1
@@ -0,0 +1,4139 @@
1
+ import {
2
+ ajv,
3
+ getOperationCard
4
+ } from "./chunk-UN5YHUNK.js";
5
+
6
+ // src/core/execution/cli/safe-runner.ts
7
+ import { spawn } from "child_process";
8
+ var DEFAULT_MAX_OUTPUT_BYTES = 1e6;
9
+ function createSafeCliCommandRunner(options) {
10
+ const maxOutputBytes = options?.maxOutputBytes ?? DEFAULT_MAX_OUTPUT_BYTES;
11
+ return {
12
+ run(command, args, timeoutMs) {
13
+ if (timeoutMs <= 0) {
14
+ return Promise.reject(new Error("timeoutMs must be a positive number"));
15
+ }
16
+ return new Promise((resolve, reject) => {
17
+ const child = spawn(command, args, {
18
+ shell: false,
19
+ stdio: ["ignore", "pipe", "pipe"]
20
+ });
21
+ const stdoutChunks = [];
22
+ const stderrChunks = [];
23
+ let stdoutSize = 0;
24
+ let stderrSize = 0;
25
+ let failureReason = null;
26
+ let settled = false;
27
+ const timer = setTimeout(() => {
28
+ if (failureReason === null) {
29
+ failureReason = "timeout";
30
+ }
31
+ child.kill("SIGKILL");
32
+ }, timeoutMs);
33
+ function settleError(error) {
34
+ if (settled) {
35
+ return;
36
+ }
37
+ settled = true;
38
+ clearTimeout(timer);
39
+ reject(error);
40
+ }
41
+ function settleSuccess(stdout, stderr, exitCode) {
42
+ if (settled) {
43
+ return;
44
+ }
45
+ settled = true;
46
+ clearTimeout(timer);
47
+ resolve({ stdout, stderr, exitCode });
48
+ }
49
+ child.stdout?.on("data", (chunk) => {
50
+ if (failureReason === "overflow") {
51
+ return;
52
+ }
53
+ stdoutSize += chunk.length;
54
+ if (stdoutSize + stderrSize > maxOutputBytes) {
55
+ if (failureReason === null) {
56
+ failureReason = "overflow";
57
+ clearTimeout(timer);
58
+ child.kill("SIGKILL");
59
+ settleError(new Error(`CLI output exceeded ${maxOutputBytes} bytes`));
60
+ return;
61
+ }
62
+ child.kill("SIGKILL");
63
+ return;
64
+ }
65
+ stdoutChunks.push(chunk);
66
+ });
67
+ child.stderr?.on("data", (chunk) => {
68
+ if (failureReason === "overflow") {
69
+ return;
70
+ }
71
+ stderrSize += chunk.length;
72
+ if (stdoutSize + stderrSize > maxOutputBytes) {
73
+ if (failureReason === null) {
74
+ failureReason = "overflow";
75
+ clearTimeout(timer);
76
+ child.kill("SIGKILL");
77
+ settleError(new Error(`CLI output exceeded ${maxOutputBytes} bytes`));
78
+ return;
79
+ }
80
+ child.kill("SIGKILL");
81
+ return;
82
+ }
83
+ stderrChunks.push(chunk);
84
+ });
85
+ child.on("error", (error) => {
86
+ settleError(error);
87
+ });
88
+ child.on("close", (code) => {
89
+ if (failureReason === "timeout") {
90
+ settleError(new Error(`CLI command timed out after ${timeoutMs}ms`));
91
+ return;
92
+ }
93
+ if (failureReason === "overflow") {
94
+ settleError(new Error(`CLI output exceeded ${maxOutputBytes} bytes`));
95
+ return;
96
+ }
97
+ settleSuccess(
98
+ Buffer.concat(stdoutChunks).toString("utf8"),
99
+ Buffer.concat(stderrChunks).toString("utf8"),
100
+ code ?? 1
101
+ );
102
+ });
103
+ });
104
+ }
105
+ };
106
+ }
107
+
108
+ // src/core/errors/codes.ts
109
+ var errorCodes = {
110
+ Auth: "AUTH",
111
+ NotFound: "NOT_FOUND",
112
+ Validation: "VALIDATION",
113
+ RateLimit: "RATE_LIMIT",
114
+ Network: "NETWORK",
115
+ Server: "SERVER",
116
+ AdapterUnsupported: "ADAPTER_UNSUPPORTED",
117
+ Unknown: "UNKNOWN"
118
+ };
119
+
120
+ // src/core/execution/normalizer.ts
121
+ function buildMeta(route, options) {
122
+ const meta = {
123
+ capability_id: options.capabilityId,
124
+ route_used: route
125
+ };
126
+ if (options.reason !== void 0) {
127
+ meta.reason = options.reason;
128
+ }
129
+ if (options.pagination !== void 0) {
130
+ meta.pagination = options.pagination;
131
+ }
132
+ return meta;
133
+ }
134
+ function normalizeResult(data, route, options) {
135
+ return {
136
+ ok: true,
137
+ data,
138
+ meta: buildMeta(route, options)
139
+ };
140
+ }
141
+ function normalizeError(error, route, options) {
142
+ return {
143
+ ok: false,
144
+ error,
145
+ meta: buildMeta(route, options)
146
+ };
147
+ }
148
+
149
+ // src/core/registry/schema-validator.ts
150
+ var validatorCache = /* @__PURE__ */ new WeakMap();
151
+ function mapAjvErrors(errors) {
152
+ if (!errors) {
153
+ return [];
154
+ }
155
+ return errors.map((error) => ({
156
+ instancePath: error.instancePath,
157
+ message: error.message ?? "schema validation failed",
158
+ keyword: error.keyword,
159
+ params: error.params
160
+ }));
161
+ }
162
+ function getValidator(schema) {
163
+ const cached = validatorCache.get(schema);
164
+ if (cached) {
165
+ return cached;
166
+ }
167
+ const validator = ajv.compile(schema);
168
+ validatorCache.set(schema, validator);
169
+ return validator;
170
+ }
171
+ function validate(schema, payload) {
172
+ const validator = getValidator(schema);
173
+ const ok = validator(payload);
174
+ if (ok) {
175
+ return { ok: true };
176
+ }
177
+ return {
178
+ ok: false,
179
+ errors: mapAjvErrors(validator.errors)
180
+ };
181
+ }
182
+ function validateInput(inputSchema, params) {
183
+ return validate(inputSchema, params);
184
+ }
185
+ function validateOutput(outputSchema, data) {
186
+ return validate(outputSchema, data);
187
+ }
188
+
189
+ // src/core/telemetry/logger.ts
190
+ var SENSITIVE_KEY_PATTERN = /(token|authorization|cookie|secret|password|api[_-]?key)/i;
191
+ function redactValue(value) {
192
+ if (Array.isArray(value)) {
193
+ return value.map(redactValue);
194
+ }
195
+ if (value && typeof value === "object") {
196
+ const redacted = {};
197
+ for (const [key, nested] of Object.entries(value)) {
198
+ redacted[key] = SENSITIVE_KEY_PATTERN.test(key) ? "[REDACTED]" : redactValue(nested);
199
+ }
200
+ return redacted;
201
+ }
202
+ return value;
203
+ }
204
+ function sanitizeTelemetryContext(context) {
205
+ return redactValue(context);
206
+ }
207
+ function logMetric(name, value, context = {}) {
208
+ if (process.env.GHX_TELEMETRY_STDOUT !== "1") {
209
+ return;
210
+ }
211
+ const payload = {
212
+ timestamp: (/* @__PURE__ */ new Date()).toISOString(),
213
+ metric: name,
214
+ value,
215
+ context: sanitizeTelemetryContext(context)
216
+ };
217
+ process.stdout.write(`${JSON.stringify(payload)}
218
+ `);
219
+ }
220
+
221
+ // src/core/execute/execute.ts
222
+ function parsePredicateValue(raw) {
223
+ const value = raw.trim();
224
+ if (value === "true") {
225
+ return true;
226
+ }
227
+ if (value === "false") {
228
+ return false;
229
+ }
230
+ if (value === "null") {
231
+ return null;
232
+ }
233
+ const numeric = Number(value);
234
+ if (!Number.isNaN(numeric) && value.length > 0) {
235
+ return numeric;
236
+ }
237
+ return value.replace(/^['"]|['"]$/g, "");
238
+ }
239
+ function resolvePathValue(source, path) {
240
+ const segments = path.split(".").filter((segment) => segment.length > 0);
241
+ let current = source;
242
+ for (const segment of segments) {
243
+ if (typeof current !== "object" || current === null || Array.isArray(current)) {
244
+ return void 0;
245
+ }
246
+ current = current[segment];
247
+ }
248
+ return current;
249
+ }
250
+ function evaluateSuitabilityPreferred(card, params, routingContext) {
251
+ const rules = card.routing.suitability ?? [];
252
+ for (const rule of rules) {
253
+ const alwaysMatch = /^(cli|graphql|rest)$/i.exec(rule.predicate.trim());
254
+ const alwaysRoute = alwaysMatch?.[1];
255
+ if (rule.when === "always" && alwaysRoute) {
256
+ return alwaysRoute.toLowerCase();
257
+ }
258
+ const conditionalMatch = /^(cli|graphql|rest)\s+if\s+([a-zA-Z0-9_.]+)\s*(==|!=)\s*(.+)$/i.exec(
259
+ rule.predicate.trim()
260
+ );
261
+ if (!conditionalMatch) {
262
+ continue;
263
+ }
264
+ const [, targetRouteRaw = "", rawPath = "", operator = "==", rawExpected = ""] = conditionalMatch;
265
+ const targetRoute = targetRouteRaw.toLowerCase();
266
+ const source = rule.when === "env" ? routingContext : params;
267
+ const path = rawPath.startsWith("params.") || rawPath.startsWith("env.") ? rawPath.split(".").slice(1).join(".") : rawPath;
268
+ const actual = resolvePathValue(source, path);
269
+ const expected = parsePredicateValue(rawExpected);
270
+ const matches = operator === "==" ? actual === expected : actual !== expected;
271
+ if (matches) {
272
+ return targetRoute;
273
+ }
274
+ }
275
+ return card.routing.preferred;
276
+ }
277
+ function routePlan(card, params, routingContext) {
278
+ const preferred = evaluateSuitabilityPreferred(card, params, routingContext);
279
+ const planned = /* @__PURE__ */ new Set([preferred, ...card.routing.fallbacks]);
280
+ return [...planned];
281
+ }
282
+ async function execute(options) {
283
+ const inputValidation = validateInput(options.card.input_schema, options.params);
284
+ if (!inputValidation.ok) {
285
+ return normalizeError(
286
+ {
287
+ code: errorCodes.Validation,
288
+ message: "Input schema validation failed",
289
+ retryable: false,
290
+ details: { ajvErrors: inputValidation.errors }
291
+ },
292
+ options.card.routing.preferred,
293
+ {
294
+ capabilityId: options.card.capability_id,
295
+ reason: "INPUT_VALIDATION"
296
+ }
297
+ );
298
+ }
299
+ const attempts = [];
300
+ const maxAttemptsPerRoute = Math.max(1, options.retry?.maxAttemptsPerRoute ?? 1);
301
+ let lastError;
302
+ let firstError;
303
+ const routingContext = options.routingContext ?? {};
304
+ for (const route of routePlan(options.card, options.params, routingContext)) {
305
+ logMetric("route.plan", 1, {
306
+ capability_id: options.card.capability_id,
307
+ route
308
+ });
309
+ const preflight = await options.preflight(route);
310
+ if (!preflight.ok) {
311
+ logMetric("route.preflight_skipped", 1, {
312
+ capability_id: options.card.capability_id,
313
+ route,
314
+ error_code: preflight.code
315
+ });
316
+ attempts.push({ route, status: "skipped", error_code: preflight.code });
317
+ lastError = {
318
+ code: preflight.code,
319
+ message: preflight.message,
320
+ retryable: preflight.retryable,
321
+ ...preflight.details ? { details: preflight.details } : {}
322
+ };
323
+ firstError ??= lastError;
324
+ continue;
325
+ }
326
+ const routeHandler = options.routes[route];
327
+ if (typeof routeHandler !== "function") {
328
+ logMetric("route.missing_handler", 1, {
329
+ capability_id: options.card.capability_id,
330
+ route
331
+ });
332
+ const handlerError = {
333
+ code: errorCodes.AdapterUnsupported,
334
+ message: `No route handler configured for '${route}'`,
335
+ retryable: false,
336
+ details: { route }
337
+ };
338
+ attempts.push({ route, status: "skipped", error_code: errorCodes.AdapterUnsupported });
339
+ lastError = handlerError;
340
+ firstError ??= handlerError;
341
+ continue;
342
+ }
343
+ for (let attempt = 0; attempt < maxAttemptsPerRoute; attempt += 1) {
344
+ const result = await routeHandler(options.params);
345
+ logMetric("route.attempt", 1, {
346
+ capability_id: options.card.capability_id,
347
+ route,
348
+ ok: result.ok
349
+ });
350
+ const attemptRecord = {
351
+ route,
352
+ status: result.ok ? "success" : "error"
353
+ };
354
+ if (result.error?.code) {
355
+ attemptRecord.error_code = result.error.code;
356
+ }
357
+ attempts.push(attemptRecord);
358
+ if (result.ok) {
359
+ const outputValidation = validateOutput(options.card.output_schema, result.data);
360
+ if (!outputValidation.ok) {
361
+ const envelope2 = normalizeError(
362
+ {
363
+ code: errorCodes.Server,
364
+ message: "Output schema validation failed",
365
+ retryable: false,
366
+ details: { ajvErrors: outputValidation.errors }
367
+ },
368
+ route,
369
+ {
370
+ capabilityId: options.card.capability_id,
371
+ reason: "OUTPUT_VALIDATION"
372
+ }
373
+ );
374
+ if (options.trace) {
375
+ envelope2.meta.attempts = attempts;
376
+ }
377
+ return envelope2;
378
+ }
379
+ if (options.trace) {
380
+ result.meta.attempts = attempts;
381
+ }
382
+ return result;
383
+ }
384
+ lastError = result.error;
385
+ firstError ??= result.error;
386
+ if (!result.error?.retryable) {
387
+ if (result.error?.code !== errorCodes.AdapterUnsupported) {
388
+ if (options.trace) {
389
+ result.meta.attempts = attempts;
390
+ }
391
+ return result;
392
+ }
393
+ break;
394
+ }
395
+ }
396
+ }
397
+ const finalError = lastError ?? firstError ?? {
398
+ code: errorCodes.Unknown,
399
+ message: "No route produced a result",
400
+ retryable: false
401
+ };
402
+ const envelope = normalizeError(finalError, options.card.routing.preferred, {
403
+ capabilityId: options.card.capability_id,
404
+ reason: "CARD_FALLBACK"
405
+ });
406
+ if (options.trace) {
407
+ envelope.meta.attempts = attempts;
408
+ }
409
+ return envelope;
410
+ }
411
+
412
+ // src/core/errors/map-error.ts
413
+ function toMessage(error) {
414
+ if (error instanceof Error) {
415
+ return error.message;
416
+ }
417
+ return String(error);
418
+ }
419
+ function mapErrorToCode(error) {
420
+ const message = toMessage(error).toLowerCase();
421
+ if (message.includes("rate limit") || /\b429\b/.test(message) || message.includes("too many requests")) {
422
+ return errorCodes.RateLimit;
423
+ }
424
+ if (/\b(500|502|503|504)\b/.test(message)) {
425
+ return errorCodes.Server;
426
+ }
427
+ if (message.includes("timeout")) {
428
+ return errorCodes.Network;
429
+ }
430
+ if (message.includes("econn") || message.includes("enotfound") || message.includes("eai_again") || message.includes("network") || message.includes("connection reset")) {
431
+ return errorCodes.Network;
432
+ }
433
+ if (message.includes("not found") || /\b404\b/.test(message)) {
434
+ return errorCodes.NotFound;
435
+ }
436
+ if (message.includes("auth") || message.includes("forbidden") || message.includes("unauthorized")) {
437
+ return errorCodes.Auth;
438
+ }
439
+ if (message.includes("validation") || message.includes("invalid") || message.includes("required") || message.includes("positive integer")) {
440
+ return errorCodes.Validation;
441
+ }
442
+ return errorCodes.Unknown;
443
+ }
444
+
445
+ // src/core/errors/retryability.ts
446
+ var retryableCodes = /* @__PURE__ */ new Set([
447
+ errorCodes.Network,
448
+ errorCodes.RateLimit,
449
+ errorCodes.Server
450
+ ]);
451
+ function isRetryableErrorCode(code) {
452
+ return retryableCodes.has(code);
453
+ }
454
+
455
+ // src/core/execution/adapters/cli-capability-adapter.ts
456
+ var DEFAULT_TIMEOUT_MS = 1e4;
457
+ var DEFAULT_LIST_FIRST = 30;
458
+ var MAX_WORKFLOW_JOB_LOG_CHARS = 5e4;
459
+ var REDACTED_CLI_ERROR_MESSAGE = "gh command failed; stderr redacted for safety";
460
+ var NON_JSON_STDOUT_CAPABILITIES = /* @__PURE__ */ new Set([
461
+ "pr.checks.rerun_failed",
462
+ "pr.checks.rerun_all",
463
+ "pr.reviewers.request",
464
+ "pr.assignees.update",
465
+ "pr.branch.update",
466
+ "workflow_run.cancel",
467
+ "workflow_run.rerun_failed",
468
+ "workflow_run.rerun_all"
469
+ ]);
470
+ var REPO_ISSUE_TYPES_GRAPHQL_QUERY = "query($owner:String!,$name:String!,$first:Int!,$after:String){repository(owner:$owner,name:$name){issueTypes(first:$first,after:$after){nodes{id name color isEnabled} pageInfo{hasNextPage endCursor}}}}";
471
+ var ISSUE_COMMENTS_GRAPHQL_QUERY = "query($owner:String!,$name:String!,$issueNumber:Int!,$first:Int!,$after:String){repository(owner:$owner,name:$name){issue(number:$issueNumber){comments(first:$first,after:$after){nodes{id body createdAt url author{login}} pageInfo{hasNextPage endCursor}}}}}";
472
+ function containsSensitiveText(value) {
473
+ return /(gh[pousr]_[A-Za-z0-9_]+|github_pat_[A-Za-z0-9_]+|authorization:\s*bearer\s+\S+|bearer\s+[A-Za-z0-9._-]{20,}|(?:api[_-]?key|token|secret|password)\s*[=:]\s*\S+)/i.test(
474
+ value
475
+ );
476
+ }
477
+ function sanitizeCliErrorMessage(stderr, exitCode) {
478
+ const trimmed = stderr.trim();
479
+ if (!trimmed) {
480
+ return `gh exited with code ${exitCode}`;
481
+ }
482
+ if (containsSensitiveText(trimmed)) {
483
+ return REDACTED_CLI_ERROR_MESSAGE;
484
+ }
485
+ return trimmed;
486
+ }
487
+ function shouldFallbackRerunFailedToAll(stderr) {
488
+ const normalized = stderr.toLowerCase();
489
+ return normalized.includes("cannot be rerun") && normalized.includes("cannot be retried");
490
+ }
491
+ function parseStrictPositiveInt(value) {
492
+ return typeof value === "number" && Number.isInteger(value) && value > 0 ? value : null;
493
+ }
494
+ function parseListFirst(value) {
495
+ if (value === void 0) {
496
+ return DEFAULT_LIST_FIRST;
497
+ }
498
+ return parseStrictPositiveInt(value);
499
+ }
500
+ function parseNonEmptyString(value) {
501
+ if (typeof value !== "string") {
502
+ return null;
503
+ }
504
+ const trimmed = value.trim();
505
+ return trimmed.length > 0 ? trimmed : null;
506
+ }
507
+ function requireRepo(owner, name, capabilityId) {
508
+ if (!owner || !name) {
509
+ throw new Error(`Missing owner/name for ${capabilityId}`);
510
+ }
511
+ }
512
+ function commandTokens(card, fallbackCommand) {
513
+ const fromCard = card?.cli?.command;
514
+ const command = typeof fromCard === "string" && fromCard.trim().length > 0 ? fromCard : fallbackCommand;
515
+ return command.trim().split(/\s+/);
516
+ }
517
+ function jsonFieldsFromCard(card, fallbackFields) {
518
+ const fields = card?.cli?.jsonFields;
519
+ if (Array.isArray(fields) && fields.length > 0) {
520
+ return fields.join(",");
521
+ }
522
+ return fallbackFields;
523
+ }
524
+ function buildArgs(capabilityId, params, card) {
525
+ const owner = String(params.owner ?? "");
526
+ const name = String(params.name ?? "");
527
+ const repo = owner && name ? `${owner}/${name}` : "";
528
+ if (capabilityId === "repo.view") {
529
+ const args = commandTokens(card, "repo view");
530
+ if (repo) {
531
+ args.push(repo);
532
+ }
533
+ args.push(
534
+ "--json",
535
+ jsonFieldsFromCard(
536
+ card,
537
+ "id,name,nameWithOwner,isPrivate,stargazerCount,forkCount,url,defaultBranchRef"
538
+ )
539
+ );
540
+ return args;
541
+ }
542
+ if (capabilityId === "repo.labels.list") {
543
+ const first = parseListFirst(params.first);
544
+ if (first === null) {
545
+ throw new Error("Missing or invalid first for repo.labels.list");
546
+ }
547
+ const args = commandTokens(card, "label list");
548
+ if (repo) {
549
+ args.push("--repo", repo);
550
+ }
551
+ args.push(
552
+ "--limit",
553
+ String(first),
554
+ "--json",
555
+ jsonFieldsFromCard(card, "id,name,description,color,isDefault")
556
+ );
557
+ return args;
558
+ }
559
+ if (capabilityId === "repo.issue_types.list") {
560
+ const first = parseListFirst(params.first);
561
+ if (first === null) {
562
+ throw new Error("Missing or invalid first for repo.issue_types.list");
563
+ }
564
+ const after = params.after;
565
+ if (!(after === void 0 || after === null || typeof after === "string")) {
566
+ throw new Error("Invalid after cursor for repo.issue_types.list");
567
+ }
568
+ if (!owner || !name) {
569
+ throw new Error("Missing owner/name for repo.issue_types.list");
570
+ }
571
+ const args = [
572
+ ...commandTokens(card, "api graphql"),
573
+ "-f",
574
+ `query=${REPO_ISSUE_TYPES_GRAPHQL_QUERY}`,
575
+ "-f",
576
+ `owner=${owner}`,
577
+ "-f",
578
+ `name=${name}`,
579
+ "-F",
580
+ `first=${first}`
581
+ ];
582
+ if (typeof after === "string" && after.length > 0) {
583
+ args.push("-f", `after=${after}`);
584
+ }
585
+ return args;
586
+ }
587
+ if (capabilityId === "issue.view") {
588
+ const issueNumber = parseStrictPositiveInt(params.issueNumber);
589
+ if (issueNumber === null) {
590
+ throw new Error("Missing or invalid issueNumber for issue.view");
591
+ }
592
+ const args = [...commandTokens(card, "issue view"), String(issueNumber)];
593
+ if (repo) {
594
+ args.push("--repo", repo);
595
+ }
596
+ args.push("--json", jsonFieldsFromCard(card, "id,number,title,state,url"));
597
+ return args;
598
+ }
599
+ if (capabilityId === "issue.list") {
600
+ const first = parseListFirst(params.first);
601
+ if (first === null) {
602
+ throw new Error("Missing or invalid first for issue.list");
603
+ }
604
+ const args = commandTokens(card, "issue list");
605
+ if (repo) {
606
+ args.push("--repo", repo);
607
+ }
608
+ args.push(
609
+ "--limit",
610
+ String(first),
611
+ "--json",
612
+ jsonFieldsFromCard(card, "id,number,title,state,url")
613
+ );
614
+ return args;
615
+ }
616
+ if (capabilityId === "issue.comments.list") {
617
+ const issueNumber = parseStrictPositiveInt(params.issueNumber);
618
+ if (issueNumber === null) {
619
+ throw new Error("Missing or invalid issueNumber for issue.comments.list");
620
+ }
621
+ const first = parseStrictPositiveInt(params.first);
622
+ if (first === null) {
623
+ throw new Error("Missing or invalid first for issue.comments.list");
624
+ }
625
+ const after = params.after;
626
+ if (!(after === void 0 || after === null || typeof after === "string")) {
627
+ throw new Error("Invalid after cursor for issue.comments.list");
628
+ }
629
+ const args = [
630
+ ...commandTokens(card, "api graphql"),
631
+ "-f",
632
+ `query=${ISSUE_COMMENTS_GRAPHQL_QUERY}`,
633
+ "-f",
634
+ `owner=${owner}`,
635
+ "-f",
636
+ `name=${name}`,
637
+ "-F",
638
+ `issueNumber=${issueNumber}`,
639
+ "-F",
640
+ `first=${first}`
641
+ ];
642
+ if (typeof after === "string" && after.length > 0) {
643
+ args.push("-f", `after=${after}`);
644
+ }
645
+ return args;
646
+ }
647
+ if (capabilityId === "pr.view") {
648
+ const prNumber = parseStrictPositiveInt(params.prNumber);
649
+ if (prNumber === null) {
650
+ throw new Error("Missing or invalid prNumber for pr.view");
651
+ }
652
+ const args = [...commandTokens(card, "pr view"), String(prNumber)];
653
+ if (repo) {
654
+ args.push("--repo", repo);
655
+ }
656
+ args.push("--json", jsonFieldsFromCard(card, "id,number,title,state,url"));
657
+ return args;
658
+ }
659
+ if (capabilityId === "pr.list") {
660
+ const first = parseListFirst(params.first);
661
+ if (first === null) {
662
+ throw new Error("Missing or invalid first for pr.list");
663
+ }
664
+ const args = commandTokens(card, "pr list");
665
+ if (repo) {
666
+ args.push("--repo", repo);
667
+ }
668
+ args.push(
669
+ "--limit",
670
+ String(first),
671
+ "--json",
672
+ jsonFieldsFromCard(card, "id,number,title,state,url")
673
+ );
674
+ return args;
675
+ }
676
+ if (capabilityId === "pr.status.checks" || capabilityId === "pr.checks.get_failed") {
677
+ const prNumber = parseStrictPositiveInt(params.prNumber);
678
+ if (prNumber === null) {
679
+ throw new Error(`Missing or invalid prNumber for ${capabilityId}`);
680
+ }
681
+ const args = [...commandTokens(card, "pr checks"), String(prNumber)];
682
+ if (repo) {
683
+ args.push("--repo", repo);
684
+ }
685
+ args.push("--json", jsonFieldsFromCard(card, "name,state,bucket,workflow,link"));
686
+ return args;
687
+ }
688
+ if (capabilityId === "pr.mergeability.view") {
689
+ const prNumber = parseStrictPositiveInt(params.prNumber);
690
+ if (prNumber === null) {
691
+ throw new Error("Missing or invalid prNumber for pr.mergeability.view");
692
+ }
693
+ const args = [...commandTokens(card, "pr view"), String(prNumber)];
694
+ if (repo) {
695
+ args.push("--repo", repo);
696
+ }
697
+ args.push(
698
+ "--json",
699
+ jsonFieldsFromCard(card, "mergeable,mergeStateStatus,reviewDecision,isDraft,state")
700
+ );
701
+ return args;
702
+ }
703
+ if (capabilityId === "pr.ready_for_review.set") {
704
+ const prNumber = parseStrictPositiveInt(params.prNumber);
705
+ if (prNumber === null) {
706
+ throw new Error("Missing or invalid prNumber for pr.ready_for_review.set");
707
+ }
708
+ if (typeof params.ready !== "boolean") {
709
+ throw new Error("Missing or invalid ready for pr.ready_for_review.set");
710
+ }
711
+ const args = [...commandTokens(card, "pr ready"), String(prNumber)];
712
+ if (repo) {
713
+ args.push("--repo", repo);
714
+ }
715
+ if (!params.ready) {
716
+ args.push("--undo");
717
+ }
718
+ return args;
719
+ }
720
+ if (capabilityId === "pr.review.submit_approve" || capabilityId === "pr.review.submit_request_changes" || capabilityId === "pr.review.submit_comment") {
721
+ const prNumber = parseStrictPositiveInt(params.prNumber);
722
+ if (prNumber === null) {
723
+ throw new Error(`Missing or invalid prNumber for ${capabilityId}`);
724
+ }
725
+ const args = [...commandTokens(card, "pr review"), String(prNumber)];
726
+ if (repo) {
727
+ args.push("--repo", repo);
728
+ }
729
+ if (capabilityId === "pr.review.submit_approve") {
730
+ args.push("--approve");
731
+ const body2 = parseNonEmptyString(params.body);
732
+ if (body2) {
733
+ args.push("--body", body2);
734
+ }
735
+ return args;
736
+ }
737
+ const body = parseNonEmptyString(params.body);
738
+ if (body === null) {
739
+ throw new Error(`Missing or invalid body for ${capabilityId}`);
740
+ }
741
+ if (capabilityId === "pr.review.submit_request_changes") {
742
+ args.push("--request-changes", "--body", body);
743
+ return args;
744
+ }
745
+ args.push("--comment", "--body", body);
746
+ return args;
747
+ }
748
+ if (capabilityId === "pr.merge.execute") {
749
+ const prNumber = parseStrictPositiveInt(params.prNumber);
750
+ if (prNumber === null) {
751
+ throw new Error("Missing or invalid prNumber for pr.merge.execute");
752
+ }
753
+ const method = params.method === void 0 ? "merge" : params.method;
754
+ if (method !== "merge" && method !== "squash" && method !== "rebase") {
755
+ throw new Error("Missing or invalid method for pr.merge.execute");
756
+ }
757
+ if (params.deleteBranch !== void 0 && typeof params.deleteBranch !== "boolean") {
758
+ throw new Error("Missing or invalid deleteBranch for pr.merge.execute");
759
+ }
760
+ const args = [...commandTokens(card, "pr merge"), String(prNumber)];
761
+ if (repo) {
762
+ args.push("--repo", repo);
763
+ }
764
+ args.push(`--${method}`);
765
+ if (params.deleteBranch === true) {
766
+ args.push("--delete-branch");
767
+ }
768
+ return args;
769
+ }
770
+ if (capabilityId === "pr.checks.rerun_failed" || capabilityId === "pr.checks.rerun_all") {
771
+ const prNumber = parseStrictPositiveInt(params.prNumber);
772
+ if (prNumber === null) {
773
+ throw new Error(`Missing or invalid prNumber for ${capabilityId}`);
774
+ }
775
+ const runId = parseStrictPositiveInt(params.runId);
776
+ if (runId === null) {
777
+ throw new Error(`Missing or invalid runId for ${capabilityId}`);
778
+ }
779
+ const args = [...commandTokens(card, "run rerun"), String(runId)];
780
+ if (repo) {
781
+ args.push("--repo", repo);
782
+ }
783
+ if (capabilityId === "pr.checks.rerun_failed") {
784
+ args.push("--failed");
785
+ }
786
+ return args;
787
+ }
788
+ if (capabilityId === "pr.reviewers.request") {
789
+ const prNumber = parseStrictPositiveInt(params.prNumber);
790
+ if (prNumber === null) {
791
+ throw new Error("Missing or invalid prNumber for pr.reviewers.request");
792
+ }
793
+ const reviewers = Array.isArray(params.reviewers) ? params.reviewers.filter(
794
+ (value) => typeof value === "string" && value.trim().length > 0
795
+ ) : [];
796
+ if (reviewers.length === 0) {
797
+ throw new Error("Missing or invalid reviewers for pr.reviewers.request");
798
+ }
799
+ const args = [...commandTokens(card, "pr edit"), String(prNumber)];
800
+ if (repo) {
801
+ args.push("--repo", repo);
802
+ }
803
+ args.push("--add-reviewer", reviewers.join(","));
804
+ return args;
805
+ }
806
+ if (capabilityId === "pr.assignees.update") {
807
+ const prNumber = parseStrictPositiveInt(params.prNumber);
808
+ if (prNumber === null) {
809
+ throw new Error("Missing or invalid prNumber for pr.assignees.update");
810
+ }
811
+ const addAssignees = Array.isArray(params.add) ? params.add.filter(
812
+ (value) => typeof value === "string" && value.trim().length > 0
813
+ ) : [];
814
+ const removeAssignees = Array.isArray(params.remove) ? params.remove.filter(
815
+ (value) => typeof value === "string" && value.trim().length > 0
816
+ ) : [];
817
+ if (addAssignees.length === 0 && removeAssignees.length === 0) {
818
+ throw new Error("Missing or invalid add/remove assignees for pr.assignees.update");
819
+ }
820
+ const args = [...commandTokens(card, "pr edit"), String(prNumber)];
821
+ if (repo) {
822
+ args.push("--repo", repo);
823
+ }
824
+ if (addAssignees.length > 0) {
825
+ args.push("--add-assignee", addAssignees.join(","));
826
+ }
827
+ if (removeAssignees.length > 0) {
828
+ args.push("--remove-assignee", removeAssignees.join(","));
829
+ }
830
+ return args;
831
+ }
832
+ if (capabilityId === "pr.branch.update") {
833
+ const prNumber = parseStrictPositiveInt(params.prNumber);
834
+ if (prNumber === null) {
835
+ throw new Error("Missing or invalid prNumber for pr.branch.update");
836
+ }
837
+ const args = [...commandTokens(card, "pr update-branch"), String(prNumber)];
838
+ if (repo) {
839
+ args.push("--repo", repo);
840
+ }
841
+ return args;
842
+ }
843
+ if (capabilityId === "check_run.annotations.list") {
844
+ const checkRunId = parseStrictPositiveInt(params.checkRunId);
845
+ if (checkRunId === null) {
846
+ throw new Error("Missing or invalid checkRunId for check_run.annotations.list");
847
+ }
848
+ if (!owner || !name) {
849
+ throw new Error("Missing owner/name for check_run.annotations.list");
850
+ }
851
+ const args = [
852
+ ...commandTokens(card, "api"),
853
+ `repos/${owner}/${name}/check-runs/${checkRunId}/annotations`
854
+ ];
855
+ return args;
856
+ }
857
+ if (capabilityId === "workflow_runs.list") {
858
+ const first = parseListFirst(params.first);
859
+ if (first === null) {
860
+ throw new Error("Missing or invalid first for workflow_runs.list");
861
+ }
862
+ const args = commandTokens(card, "run list");
863
+ if (repo) {
864
+ args.push("--repo", repo);
865
+ }
866
+ if (typeof params.branch === "string" && params.branch.length > 0) {
867
+ args.push("--branch", params.branch);
868
+ }
869
+ if (typeof params.event === "string" && params.event.length > 0) {
870
+ args.push("--event", params.event);
871
+ }
872
+ if (typeof params.status === "string" && params.status.length > 0) {
873
+ args.push("--status", params.status);
874
+ }
875
+ args.push(
876
+ "--limit",
877
+ String(first),
878
+ "--json",
879
+ jsonFieldsFromCard(card, "databaseId,workflowName,status,conclusion,headBranch,url")
880
+ );
881
+ return args;
882
+ }
883
+ if (capabilityId === "workflow_run.jobs.list") {
884
+ const runId = parseStrictPositiveInt(params.runId);
885
+ if (runId === null) {
886
+ throw new Error("Missing or invalid runId for workflow_run.jobs.list");
887
+ }
888
+ const args = [...commandTokens(card, "run view"), String(runId)];
889
+ if (repo) {
890
+ args.push("--repo", repo);
891
+ }
892
+ args.push("--json", "jobs");
893
+ return args;
894
+ }
895
+ if (capabilityId === "workflow_job.logs.get" || capabilityId === "workflow_job.logs.analyze") {
896
+ const jobId = parseStrictPositiveInt(params.jobId);
897
+ if (jobId === null) {
898
+ throw new Error(`Missing or invalid jobId for ${capabilityId}`);
899
+ }
900
+ const args = [...commandTokens(card, "run view"), "--job", String(jobId), "--log"];
901
+ if (repo) {
902
+ args.push("--repo", repo);
903
+ }
904
+ return args;
905
+ }
906
+ if (capabilityId === "workflow.list") {
907
+ const first = parseListFirst(params.first);
908
+ if (first === null) {
909
+ throw new Error("Missing or invalid first for workflow.list");
910
+ }
911
+ const args = commandTokens(card, "workflow list");
912
+ if (repo) {
913
+ args.push("--repo", repo);
914
+ }
915
+ args.push("--limit", String(first), "--json", jsonFieldsFromCard(card, "id,name,path,state"));
916
+ return args;
917
+ }
918
+ if (capabilityId === "workflow.get") {
919
+ const workflowId = parseNonEmptyString(params.workflowId) ?? (typeof params.workflowId === "number" ? String(params.workflowId) : null);
920
+ if (workflowId === null) {
921
+ throw new Error("Missing or invalid workflowId for workflow.get");
922
+ }
923
+ const args = [...commandTokens(card, "workflow view"), workflowId];
924
+ if (repo) {
925
+ args.push("--repo", repo);
926
+ }
927
+ args.push("--json", jsonFieldsFromCard(card, "id,name,path,state,url"));
928
+ return args;
929
+ }
930
+ if (capabilityId === "workflow_run.get") {
931
+ const runId = parseStrictPositiveInt(params.runId);
932
+ if (runId === null) {
933
+ throw new Error("Missing or invalid runId for workflow_run.get");
934
+ }
935
+ const args = [...commandTokens(card, "run view"), String(runId)];
936
+ if (repo) {
937
+ args.push("--repo", repo);
938
+ }
939
+ args.push(
940
+ "--json",
941
+ jsonFieldsFromCard(
942
+ card,
943
+ "databaseId,workflowName,status,conclusion,headBranch,headSha,url,event,createdAt,updatedAt,startedAt"
944
+ )
945
+ );
946
+ return args;
947
+ }
948
+ if (capabilityId === "workflow_run.rerun_all" || capabilityId === "workflow_run.cancel") {
949
+ const runId = parseStrictPositiveInt(params.runId);
950
+ if (runId === null) {
951
+ throw new Error(`Missing or invalid runId for ${capabilityId}`);
952
+ }
953
+ const args = [
954
+ ...commandTokens(
955
+ card,
956
+ capabilityId === "workflow_run.rerun_all" ? "run rerun" : "run cancel"
957
+ ),
958
+ String(runId)
959
+ ];
960
+ if (repo) {
961
+ args.push("--repo", repo);
962
+ }
963
+ return args;
964
+ }
965
+ if (capabilityId === "workflow_run.artifacts.list") {
966
+ const runId = parseStrictPositiveInt(params.runId);
967
+ if (runId === null) {
968
+ throw new Error("Missing or invalid runId for workflow_run.artifacts.list");
969
+ }
970
+ const args = [...commandTokens(card, "run view"), String(runId)];
971
+ if (repo) {
972
+ args.push("--repo", repo);
973
+ }
974
+ args.push("--json", jsonFieldsFromCard(card, "artifacts"));
975
+ return args;
976
+ }
977
+ if (capabilityId === "project_v2.org.get" || capabilityId === "project_v2.user.get") {
978
+ const ownerParam = capabilityId === "project_v2.org.get" ? params.org : params.user;
979
+ const owner2 = parseNonEmptyString(ownerParam);
980
+ const projectNumber = parseStrictPositiveInt(params.projectNumber);
981
+ if (owner2 === null || projectNumber === null) {
982
+ throw new Error(`Missing or invalid owner/projectNumber for ${capabilityId}`);
983
+ }
984
+ const args = [
985
+ ...commandTokens(card, "project view"),
986
+ String(projectNumber),
987
+ "--owner",
988
+ owner2,
989
+ "--format",
990
+ "json"
991
+ ];
992
+ return args;
993
+ }
994
+ if (capabilityId === "project_v2.fields.list") {
995
+ const projectNumber = parseStrictPositiveInt(params.projectNumber);
996
+ const projectOwner = parseNonEmptyString(params.owner);
997
+ if (projectNumber === null || projectOwner === null) {
998
+ throw new Error("Missing or invalid owner/projectNumber for project_v2.fields.list");
999
+ }
1000
+ const args = [
1001
+ ...commandTokens(card, "project field-list"),
1002
+ String(projectNumber),
1003
+ "--owner",
1004
+ projectOwner,
1005
+ "--format",
1006
+ "json"
1007
+ ];
1008
+ return args;
1009
+ }
1010
+ if (capabilityId === "project_v2.items.list") {
1011
+ const projectNumber = parseStrictPositiveInt(params.projectNumber);
1012
+ const projectOwner = parseNonEmptyString(params.owner);
1013
+ const first = parseListFirst(params.first);
1014
+ if (projectNumber === null || projectOwner === null || first === null) {
1015
+ throw new Error("Missing or invalid owner/projectNumber/first for project_v2.items.list");
1016
+ }
1017
+ const args = [
1018
+ ...commandTokens(card, "project item-list"),
1019
+ String(projectNumber),
1020
+ "--owner",
1021
+ projectOwner,
1022
+ "--format",
1023
+ "json",
1024
+ "--limit",
1025
+ String(first)
1026
+ ];
1027
+ return args;
1028
+ }
1029
+ if (capabilityId === "release.list") {
1030
+ requireRepo(owner, name, capabilityId);
1031
+ const first = parseListFirst(params.first);
1032
+ if (first === null) {
1033
+ throw new Error("Missing or invalid first for release.list");
1034
+ }
1035
+ const args = [
1036
+ ...commandTokens(card, "api"),
1037
+ `repos/${owner}/${name}/releases`,
1038
+ "-F",
1039
+ `per_page=${first}`
1040
+ ];
1041
+ return args;
1042
+ }
1043
+ if (capabilityId === "release.get") {
1044
+ requireRepo(owner, name, capabilityId);
1045
+ const tagName = parseNonEmptyString(params.tagName);
1046
+ if (tagName === null) {
1047
+ throw new Error("Missing or invalid tagName for release.get");
1048
+ }
1049
+ const args = [
1050
+ ...commandTokens(card, "api"),
1051
+ `repos/${owner}/${name}/releases/tags/${encodeURIComponent(tagName)}`
1052
+ ];
1053
+ return args;
1054
+ }
1055
+ if (capabilityId === "release.create_draft") {
1056
+ requireRepo(owner, name, capabilityId);
1057
+ const tagName = parseNonEmptyString(params.tagName);
1058
+ if (tagName === null) {
1059
+ throw new Error("Missing or invalid tagName for release.create_draft");
1060
+ }
1061
+ const args = [
1062
+ ...commandTokens(card, "api"),
1063
+ `repos/${owner}/${name}/releases`,
1064
+ "--method",
1065
+ "POST",
1066
+ "-f",
1067
+ `tag_name=${tagName}`,
1068
+ "-F",
1069
+ "draft=true"
1070
+ ];
1071
+ const title = parseNonEmptyString(params.title);
1072
+ if (title) {
1073
+ args.push("-f", `name=${title}`);
1074
+ }
1075
+ const notes = parseNonEmptyString(params.notes);
1076
+ if (notes) {
1077
+ args.push("-f", `body=${notes}`);
1078
+ }
1079
+ const target = parseNonEmptyString(params.targetCommitish);
1080
+ if (target) {
1081
+ args.push("-f", `target_commitish=${target}`);
1082
+ }
1083
+ if (typeof params.prerelease === "boolean") {
1084
+ args.push("-F", `prerelease=${params.prerelease ? "true" : "false"}`);
1085
+ }
1086
+ return args;
1087
+ }
1088
+ if (capabilityId === "release.update") {
1089
+ requireRepo(owner, name, capabilityId);
1090
+ const releaseId = parseStrictPositiveInt(params.releaseId);
1091
+ if (releaseId === null) {
1092
+ throw new Error("Missing or invalid releaseId for release.update");
1093
+ }
1094
+ if (params.draft !== void 0 && params.draft !== true) {
1095
+ throw new Error(
1096
+ "release.update only supports draft=true; use release.publish_draft to publish"
1097
+ );
1098
+ }
1099
+ const args = [
1100
+ ...commandTokens(card, "api"),
1101
+ `repos/${owner}/${name}/releases/${releaseId}`,
1102
+ "--method",
1103
+ "PATCH",
1104
+ "-F",
1105
+ "draft=true"
1106
+ ];
1107
+ const tagName = parseNonEmptyString(params.tagName);
1108
+ if (tagName) {
1109
+ args.push("-f", `tag_name=${tagName}`);
1110
+ }
1111
+ const title = parseNonEmptyString(params.title);
1112
+ if (title) {
1113
+ args.push("-f", `name=${title}`);
1114
+ }
1115
+ const notes = parseNonEmptyString(params.notes);
1116
+ if (notes) {
1117
+ args.push("-f", `body=${notes}`);
1118
+ }
1119
+ const target = parseNonEmptyString(params.targetCommitish);
1120
+ if (target) {
1121
+ args.push("-f", `target_commitish=${target}`);
1122
+ }
1123
+ if (typeof params.prerelease === "boolean") {
1124
+ args.push("-F", `prerelease=${params.prerelease ? "true" : "false"}`);
1125
+ }
1126
+ return args;
1127
+ }
1128
+ if (capabilityId === "release.publish_draft") {
1129
+ requireRepo(owner, name, capabilityId);
1130
+ const releaseId = parseStrictPositiveInt(params.releaseId);
1131
+ if (releaseId === null) {
1132
+ throw new Error("Missing or invalid releaseId for release.publish_draft");
1133
+ }
1134
+ const args = [
1135
+ ...commandTokens(card, "api"),
1136
+ `repos/${owner}/${name}/releases/${releaseId}`,
1137
+ "--method",
1138
+ "PATCH",
1139
+ "-F",
1140
+ "draft=false"
1141
+ ];
1142
+ const title = parseNonEmptyString(params.title);
1143
+ if (title) {
1144
+ args.push("-f", `name=${title}`);
1145
+ }
1146
+ const notes = parseNonEmptyString(params.notes);
1147
+ if (notes) {
1148
+ args.push("-f", `body=${notes}`);
1149
+ }
1150
+ if (typeof params.prerelease === "boolean") {
1151
+ args.push("-F", `prerelease=${params.prerelease ? "true" : "false"}`);
1152
+ }
1153
+ return args;
1154
+ }
1155
+ if (capabilityId === "workflow_dispatch.run") {
1156
+ requireRepo(owner, name, capabilityId);
1157
+ const workflowId = parseNonEmptyString(params.workflowId);
1158
+ if (workflowId === null) {
1159
+ throw new Error("Missing or invalid workflowId for workflow_dispatch.run");
1160
+ }
1161
+ const ref = parseNonEmptyString(params.ref);
1162
+ if (ref === null) {
1163
+ throw new Error("Missing or invalid ref for workflow_dispatch.run");
1164
+ }
1165
+ const args = [
1166
+ ...commandTokens(card, "api"),
1167
+ `repos/${owner}/${name}/actions/workflows/${encodeURIComponent(workflowId)}/dispatches`,
1168
+ "--method",
1169
+ "POST",
1170
+ "-f",
1171
+ `ref=${ref}`
1172
+ ];
1173
+ if (params.inputs !== void 0) {
1174
+ if (typeof params.inputs !== "object" || params.inputs === null || Array.isArray(params.inputs)) {
1175
+ throw new Error("Missing or invalid inputs for workflow_dispatch.run");
1176
+ }
1177
+ const inputEntries = Object.entries(params.inputs);
1178
+ for (const [key, value] of inputEntries) {
1179
+ if (!key.trim()) {
1180
+ throw new Error("Missing or invalid inputs for workflow_dispatch.run");
1181
+ }
1182
+ if (!(typeof value === "string" || typeof value === "number" || typeof value === "boolean")) {
1183
+ throw new Error("Missing or invalid inputs for workflow_dispatch.run");
1184
+ }
1185
+ args.push("-f", `inputs[${key}]=${String(value)}`);
1186
+ }
1187
+ }
1188
+ return args;
1189
+ }
1190
+ if (capabilityId === "workflow_run.rerun_failed") {
1191
+ requireRepo(owner, name, capabilityId);
1192
+ const runId = parseStrictPositiveInt(params.runId);
1193
+ if (runId === null) {
1194
+ throw new Error("Missing or invalid runId for workflow_run.rerun_failed");
1195
+ }
1196
+ const args = [
1197
+ ...commandTokens(card, "api"),
1198
+ `repos/${owner}/${name}/actions/runs/${runId}/rerun-failed-jobs`,
1199
+ "--method",
1200
+ "POST"
1201
+ ];
1202
+ return args;
1203
+ }
1204
+ if (capabilityId === "project_v2.item.add_issue") {
1205
+ const projectNumber = parseStrictPositiveInt(params.projectNumber);
1206
+ const projectOwner = parseNonEmptyString(params.owner);
1207
+ const issueUrl = parseNonEmptyString(params.issueUrl);
1208
+ if (projectNumber === null || projectOwner === null || issueUrl === null) {
1209
+ throw new Error(
1210
+ "Missing or invalid owner/projectNumber/issueUrl for project_v2.item.add_issue"
1211
+ );
1212
+ }
1213
+ const args = [
1214
+ ...commandTokens(card, "project item-add"),
1215
+ String(projectNumber),
1216
+ "--owner",
1217
+ projectOwner,
1218
+ "--url",
1219
+ issueUrl,
1220
+ "--format",
1221
+ "json"
1222
+ ];
1223
+ return args;
1224
+ }
1225
+ if (capabilityId === "project_v2.item.field.update") {
1226
+ const projectId = parseNonEmptyString(params.projectId);
1227
+ const itemId = parseNonEmptyString(params.itemId);
1228
+ const fieldId = parseNonEmptyString(params.fieldId);
1229
+ if (projectId === null || itemId === null || fieldId === null) {
1230
+ throw new Error(
1231
+ "Missing or invalid projectId/itemId/fieldId for project_v2.item.field.update"
1232
+ );
1233
+ }
1234
+ const args = [
1235
+ ...commandTokens(card, "project item-edit"),
1236
+ "--project-id",
1237
+ projectId,
1238
+ "--id",
1239
+ itemId,
1240
+ "--field-id",
1241
+ fieldId
1242
+ ];
1243
+ const valueText = parseNonEmptyString(params.valueText);
1244
+ const valueDate = parseNonEmptyString(params.valueDate);
1245
+ const valueSingleSelectOptionId = parseNonEmptyString(params.valueSingleSelectOptionId);
1246
+ const valueIterationId = parseNonEmptyString(params.valueIterationId);
1247
+ const clear = params.clear === true;
1248
+ if (valueText !== null) {
1249
+ args.push("--text", valueText);
1250
+ } else if (typeof params.valueNumber === "number" && Number.isFinite(params.valueNumber)) {
1251
+ args.push("--number", String(params.valueNumber));
1252
+ } else if (valueDate !== null) {
1253
+ args.push("--date", valueDate);
1254
+ } else if (valueSingleSelectOptionId !== null) {
1255
+ args.push("--single-select-option-id", valueSingleSelectOptionId);
1256
+ } else if (valueIterationId !== null) {
1257
+ args.push("--iteration-id", valueIterationId);
1258
+ } else if (clear) {
1259
+ args.push("--clear");
1260
+ } else {
1261
+ throw new Error("Missing field value update for project_v2.item.field.update");
1262
+ }
1263
+ return args;
1264
+ }
1265
+ throw new Error(`Unsupported CLI capability: ${capabilityId}`);
1266
+ }
1267
+ function parseCliData(stdout) {
1268
+ const trimmed = stdout.trim();
1269
+ if (!trimmed) {
1270
+ return {};
1271
+ }
1272
+ return JSON.parse(trimmed);
1273
+ }
1274
+ function normalizeListItem(item) {
1275
+ if (typeof item !== "object" || item === null || Array.isArray(item)) {
1276
+ return {};
1277
+ }
1278
+ const input = item;
1279
+ return {
1280
+ id: input.id,
1281
+ number: input.number,
1282
+ title: input.title,
1283
+ state: input.state,
1284
+ url: input.url
1285
+ };
1286
+ }
1287
+ function normalizeWorkflowItem(item) {
1288
+ if (typeof item !== "object" || item === null || Array.isArray(item)) {
1289
+ return {
1290
+ id: 0,
1291
+ name: null,
1292
+ path: null,
1293
+ state: null
1294
+ };
1295
+ }
1296
+ const input = item;
1297
+ return {
1298
+ id: typeof input.id === "number" ? input.id : 0,
1299
+ name: typeof input.name === "string" ? input.name : null,
1300
+ path: typeof input.path === "string" ? input.path : null,
1301
+ state: typeof input.state === "string" ? input.state : null
1302
+ };
1303
+ }
1304
+ function normalizeProjectV2Summary(data) {
1305
+ const input = typeof data === "object" && data !== null && !Array.isArray(data) ? data : {};
1306
+ return {
1307
+ id: typeof input.id === "string" ? input.id : null,
1308
+ title: typeof input.title === "string" ? input.title : null,
1309
+ shortDescription: typeof input.shortDescription === "string" ? input.shortDescription : null,
1310
+ public: typeof input.public === "boolean" ? input.public : null,
1311
+ closed: typeof input.closed === "boolean" ? input.closed : null,
1312
+ url: typeof input.url === "string" ? input.url : null
1313
+ };
1314
+ }
1315
+ function normalizeCheckItem(item) {
1316
+ if (typeof item !== "object" || item === null || Array.isArray(item)) {
1317
+ return {
1318
+ name: null,
1319
+ state: null,
1320
+ bucket: null,
1321
+ workflow: null,
1322
+ link: null
1323
+ };
1324
+ }
1325
+ const input = item;
1326
+ return {
1327
+ name: typeof input.name === "string" ? input.name : null,
1328
+ state: typeof input.state === "string" ? input.state : null,
1329
+ bucket: typeof input.bucket === "string" ? input.bucket : null,
1330
+ workflow: typeof input.workflow === "string" ? input.workflow : null,
1331
+ link: typeof input.link === "string" ? input.link : null
1332
+ };
1333
+ }
1334
+ function normalizeCheckBucket(value) {
1335
+ if (typeof value !== "string") {
1336
+ return null;
1337
+ }
1338
+ return value.trim().toLowerCase();
1339
+ }
1340
+ function isCheckFailureBucket(bucket) {
1341
+ const normalized = normalizeCheckBucket(bucket);
1342
+ if (!normalized) {
1343
+ return false;
1344
+ }
1345
+ return normalized === "fail" || normalized === "cancel";
1346
+ }
1347
+ function isCheckPendingBucket(bucket) {
1348
+ const normalized = normalizeCheckBucket(bucket);
1349
+ if (!normalized) {
1350
+ return false;
1351
+ }
1352
+ return normalized === "pending";
1353
+ }
1354
+ function isCheckPassBucket(bucket) {
1355
+ const normalized = normalizeCheckBucket(bucket);
1356
+ if (!normalized) {
1357
+ return false;
1358
+ }
1359
+ return normalized === "pass";
1360
+ }
1361
+ function normalizeCliData(capabilityId, data, params, context) {
1362
+ const normalizeRelease = (input) => {
1363
+ if (typeof input !== "object" || input === null || Array.isArray(input)) {
1364
+ return {
1365
+ id: 0,
1366
+ tagName: null,
1367
+ name: null,
1368
+ isDraft: false,
1369
+ isPrerelease: false,
1370
+ url: null,
1371
+ targetCommitish: null,
1372
+ createdAt: null,
1373
+ publishedAt: null
1374
+ };
1375
+ }
1376
+ const record = input;
1377
+ return {
1378
+ id: typeof record.id === "number" ? record.id : 0,
1379
+ tagName: typeof record.tag_name === "string" ? record.tag_name : null,
1380
+ name: typeof record.name === "string" ? record.name : null,
1381
+ isDraft: typeof record.draft === "boolean" ? record.draft : false,
1382
+ isPrerelease: typeof record.prerelease === "boolean" ? record.prerelease : false,
1383
+ url: typeof record.html_url === "string" ? record.html_url : null,
1384
+ targetCommitish: typeof record.target_commitish === "string" ? record.target_commitish : null,
1385
+ createdAt: typeof record.created_at === "string" ? record.created_at : null,
1386
+ publishedAt: typeof record.published_at === "string" ? record.published_at : null
1387
+ };
1388
+ };
1389
+ if (capabilityId === "repo.view") {
1390
+ const input = typeof data === "object" && data !== null && !Array.isArray(data) ? data : {};
1391
+ const defaultBranchRef = typeof input.defaultBranchRef === "object" && input.defaultBranchRef !== null ? input.defaultBranchRef : null;
1392
+ return {
1393
+ id: input.id,
1394
+ name: input.name,
1395
+ nameWithOwner: input.nameWithOwner,
1396
+ isPrivate: input.isPrivate,
1397
+ stargazerCount: input.stargazerCount,
1398
+ forkCount: input.forkCount,
1399
+ url: input.url,
1400
+ defaultBranch: typeof defaultBranchRef?.name === "string" ? defaultBranchRef.name : null
1401
+ };
1402
+ }
1403
+ if (capabilityId === "repo.labels.list") {
1404
+ const labels = Array.isArray(data) ? data : [];
1405
+ return {
1406
+ items: labels.map((label) => {
1407
+ if (typeof label !== "object" || label === null || Array.isArray(label)) {
1408
+ return {
1409
+ id: null,
1410
+ name: null,
1411
+ description: null,
1412
+ color: null,
1413
+ isDefault: null
1414
+ };
1415
+ }
1416
+ const record = label;
1417
+ return {
1418
+ id: typeof record.id === "string" ? record.id : null,
1419
+ name: typeof record.name === "string" ? record.name : null,
1420
+ description: typeof record.description === "string" ? record.description : null,
1421
+ color: typeof record.color === "string" ? record.color : null,
1422
+ isDefault: typeof record.isDefault === "boolean" ? record.isDefault : null
1423
+ };
1424
+ }),
1425
+ pageInfo: {
1426
+ hasNextPage: false,
1427
+ endCursor: null
1428
+ }
1429
+ };
1430
+ }
1431
+ if (capabilityId === "repo.issue_types.list") {
1432
+ const root = typeof data === "object" && data !== null && !Array.isArray(data) ? data : {};
1433
+ const payload = typeof root.data === "object" && root.data !== null && !Array.isArray(root.data) ? root.data : {};
1434
+ const repository = typeof payload.repository === "object" && payload.repository !== null && !Array.isArray(payload.repository) ? payload.repository : {};
1435
+ const connection = typeof repository.issueTypes === "object" && repository.issueTypes !== null && !Array.isArray(repository.issueTypes) ? repository.issueTypes : {};
1436
+ const nodes = Array.isArray(connection.nodes) ? connection.nodes : [];
1437
+ const pageInfo = typeof connection.pageInfo === "object" && connection.pageInfo !== null && !Array.isArray(connection.pageInfo) ? connection.pageInfo : {};
1438
+ return {
1439
+ items: nodes.map((node) => {
1440
+ if (typeof node !== "object" || node === null || Array.isArray(node)) {
1441
+ return {
1442
+ id: null,
1443
+ name: null,
1444
+ color: null,
1445
+ isEnabled: null
1446
+ };
1447
+ }
1448
+ const record = node;
1449
+ return {
1450
+ id: typeof record.id === "string" ? record.id : null,
1451
+ name: typeof record.name === "string" ? record.name : null,
1452
+ color: typeof record.color === "string" ? record.color : null,
1453
+ isEnabled: typeof record.isEnabled === "boolean" ? record.isEnabled : null
1454
+ };
1455
+ }),
1456
+ pageInfo: {
1457
+ hasNextPage: typeof pageInfo.hasNextPage === "boolean" ? pageInfo.hasNextPage : false,
1458
+ endCursor: typeof pageInfo.endCursor === "string" ? pageInfo.endCursor : null
1459
+ }
1460
+ };
1461
+ }
1462
+ if (capabilityId === "issue.list" || capabilityId === "pr.list") {
1463
+ const items = Array.isArray(data) ? data.map((entry) => normalizeListItem(entry)) : [];
1464
+ return {
1465
+ items,
1466
+ pageInfo: {
1467
+ hasNextPage: false,
1468
+ endCursor: null
1469
+ }
1470
+ };
1471
+ }
1472
+ if (capabilityId === "issue.comments.list") {
1473
+ if (parseStrictPositiveInt(params.first) === null) {
1474
+ throw new Error("Missing or invalid first for issue.comments.list");
1475
+ }
1476
+ const input = typeof data === "object" && data !== null && !Array.isArray(data) ? data : {};
1477
+ const commentsConnection = typeof input.data === "object" && input.data !== null && !Array.isArray(input.data) ? input.data.repository : null;
1478
+ const repository = typeof commentsConnection === "object" && commentsConnection !== null && !Array.isArray(commentsConnection) ? commentsConnection : null;
1479
+ const issue = typeof repository?.issue === "object" && repository.issue !== null && !Array.isArray(repository.issue) ? repository.issue : null;
1480
+ const comments = typeof issue?.comments === "object" && issue.comments !== null && !Array.isArray(issue.comments) ? issue.comments : null;
1481
+ const nodes = Array.isArray(comments?.nodes) ? comments.nodes : null;
1482
+ const pageInfo = typeof comments?.pageInfo === "object" && comments.pageInfo !== null && !Array.isArray(comments.pageInfo) ? comments.pageInfo : null;
1483
+ if (nodes === null || pageInfo === null || typeof pageInfo.hasNextPage !== "boolean") {
1484
+ throw new Error("Invalid CLI payload: comments connection is malformed");
1485
+ }
1486
+ const normalizedItems = nodes.flatMap((comment) => {
1487
+ if (typeof comment !== "object" || comment === null || Array.isArray(comment)) {
1488
+ throw new Error("Invalid CLI payload: comment item must be an object");
1489
+ }
1490
+ const commentRecord = comment;
1491
+ const author = typeof commentRecord.author === "object" && commentRecord.author !== null ? commentRecord.author : null;
1492
+ if (typeof commentRecord.id !== "string" || typeof commentRecord.body !== "string" || typeof commentRecord.url !== "string" || typeof commentRecord.createdAt !== "string") {
1493
+ throw new Error("Invalid CLI payload: comment item has invalid field types");
1494
+ }
1495
+ return [
1496
+ {
1497
+ id: commentRecord.id,
1498
+ body: commentRecord.body,
1499
+ authorLogin: typeof author?.login === "string" ? author.login : null,
1500
+ url: commentRecord.url,
1501
+ createdAt: commentRecord.createdAt
1502
+ }
1503
+ ];
1504
+ });
1505
+ return {
1506
+ items: normalizedItems,
1507
+ pageInfo: {
1508
+ hasNextPage: pageInfo.hasNextPage,
1509
+ endCursor: typeof pageInfo.endCursor === "string" ? pageInfo.endCursor : null
1510
+ }
1511
+ };
1512
+ }
1513
+ if (capabilityId === "pr.status.checks" || capabilityId === "pr.checks.get_failed") {
1514
+ const checks = Array.isArray(data) ? data.map((entry) => normalizeCheckItem(entry)) : [];
1515
+ const failed = checks.filter((entry) => isCheckFailureBucket(entry.bucket));
1516
+ const pending = checks.filter((entry) => isCheckPendingBucket(entry.bucket));
1517
+ const passed = checks.filter((entry) => isCheckPassBucket(entry.bucket));
1518
+ return {
1519
+ items: capabilityId === "pr.checks.get_failed" ? failed : checks,
1520
+ summary: {
1521
+ total: checks.length,
1522
+ failed: failed.length,
1523
+ pending: pending.length,
1524
+ passed: passed.length
1525
+ }
1526
+ };
1527
+ }
1528
+ if (capabilityId === "pr.mergeability.view") {
1529
+ const input = typeof data === "object" && data !== null && !Array.isArray(data) ? data : {};
1530
+ return {
1531
+ mergeable: typeof input.mergeable === "string" ? input.mergeable : null,
1532
+ mergeStateStatus: typeof input.mergeStateStatus === "string" ? input.mergeStateStatus : null,
1533
+ reviewDecision: typeof input.reviewDecision === "string" ? input.reviewDecision : null,
1534
+ isDraft: Boolean(input.isDraft),
1535
+ state: typeof input.state === "string" ? input.state : "UNKNOWN"
1536
+ };
1537
+ }
1538
+ if (capabilityId === "pr.ready_for_review.set") {
1539
+ const prNumber = Number(params.prNumber);
1540
+ const ready = Boolean(params.ready);
1541
+ return {
1542
+ prNumber,
1543
+ isDraft: !ready
1544
+ };
1545
+ }
1546
+ if (capabilityId === "pr.review.submit_approve" || capabilityId === "pr.review.submit_request_changes" || capabilityId === "pr.review.submit_comment") {
1547
+ const prNumber = Number(params.prNumber);
1548
+ const event = capabilityId === "pr.review.submit_approve" ? "APPROVE" : capabilityId === "pr.review.submit_request_changes" ? "REQUEST_CHANGES" : "COMMENT";
1549
+ return {
1550
+ prNumber,
1551
+ event,
1552
+ submitted: true,
1553
+ body: typeof params.body === "string" ? params.body : null
1554
+ };
1555
+ }
1556
+ if (capabilityId === "pr.merge.execute") {
1557
+ const method = params.method === "squash" || params.method === "rebase" ? params.method : "merge";
1558
+ return {
1559
+ prNumber: Number(params.prNumber),
1560
+ method,
1561
+ queued: true,
1562
+ deleteBranch: params.deleteBranch === true
1563
+ };
1564
+ }
1565
+ if (capabilityId === "pr.checks.rerun_failed" || capabilityId === "pr.checks.rerun_all") {
1566
+ const effectiveMode = context?.effectiveRerunMode === "all" ? "all" : capabilityId === "pr.checks.rerun_failed" ? "failed" : "all";
1567
+ return {
1568
+ prNumber: Number(params.prNumber),
1569
+ runId: Number(params.runId),
1570
+ mode: effectiveMode,
1571
+ queued: true
1572
+ };
1573
+ }
1574
+ if (capabilityId === "pr.reviewers.request") {
1575
+ const reviewers = Array.isArray(params.reviewers) ? params.reviewers.filter(
1576
+ (value) => typeof value === "string" && value.trim().length > 0
1577
+ ) : [];
1578
+ return {
1579
+ prNumber: Number(params.prNumber),
1580
+ reviewers,
1581
+ updated: true
1582
+ };
1583
+ }
1584
+ if (capabilityId === "pr.assignees.update") {
1585
+ const add = Array.isArray(params.add) ? params.add.filter(
1586
+ (value) => typeof value === "string" && value.trim().length > 0
1587
+ ) : [];
1588
+ const remove = Array.isArray(params.remove) ? params.remove.filter(
1589
+ (value) => typeof value === "string" && value.trim().length > 0
1590
+ ) : [];
1591
+ return {
1592
+ prNumber: Number(params.prNumber),
1593
+ add,
1594
+ remove,
1595
+ updated: true
1596
+ };
1597
+ }
1598
+ if (capabilityId === "pr.branch.update") {
1599
+ return {
1600
+ prNumber: Number(params.prNumber),
1601
+ updated: true
1602
+ };
1603
+ }
1604
+ if (capabilityId === "check_run.annotations.list") {
1605
+ const annotations = Array.isArray(data) ? data : [];
1606
+ return {
1607
+ items: annotations.map((annotation) => {
1608
+ if (typeof annotation !== "object" || annotation === null || Array.isArray(annotation)) {
1609
+ return {
1610
+ path: null,
1611
+ startLine: null,
1612
+ endLine: null,
1613
+ level: null,
1614
+ message: null,
1615
+ title: null,
1616
+ details: null
1617
+ };
1618
+ }
1619
+ const record = annotation;
1620
+ return {
1621
+ path: typeof record.path === "string" ? record.path : null,
1622
+ startLine: typeof record.start_line === "number" ? record.start_line : null,
1623
+ endLine: typeof record.end_line === "number" ? record.end_line : null,
1624
+ level: typeof record.annotation_level === "string" ? record.annotation_level : null,
1625
+ message: typeof record.message === "string" ? record.message : null,
1626
+ title: typeof record.title === "string" ? record.title : null,
1627
+ details: typeof record.raw_details === "string" ? record.raw_details : null
1628
+ };
1629
+ })
1630
+ };
1631
+ }
1632
+ if (capabilityId === "workflow_runs.list") {
1633
+ const runs = Array.isArray(data) ? data : [];
1634
+ return {
1635
+ items: runs.map((run) => {
1636
+ if (typeof run !== "object" || run === null || Array.isArray(run)) {
1637
+ return {
1638
+ id: 0,
1639
+ workflowName: null,
1640
+ status: null,
1641
+ conclusion: null,
1642
+ headBranch: null,
1643
+ url: null
1644
+ };
1645
+ }
1646
+ const record = run;
1647
+ return {
1648
+ id: typeof record.databaseId === "number" ? record.databaseId : 0,
1649
+ workflowName: typeof record.workflowName === "string" ? record.workflowName : null,
1650
+ status: typeof record.status === "string" ? record.status : null,
1651
+ conclusion: typeof record.conclusion === "string" ? record.conclusion : null,
1652
+ headBranch: typeof record.headBranch === "string" ? record.headBranch : null,
1653
+ url: typeof record.url === "string" ? record.url : null
1654
+ };
1655
+ }),
1656
+ pageInfo: {
1657
+ hasNextPage: false,
1658
+ endCursor: null
1659
+ }
1660
+ };
1661
+ }
1662
+ if (capabilityId === "workflow_run.jobs.list") {
1663
+ const root = typeof data === "object" && data !== null && !Array.isArray(data) ? data : {};
1664
+ const jobs = Array.isArray(root.jobs) ? root.jobs : [];
1665
+ return {
1666
+ items: jobs.map((job) => {
1667
+ if (typeof job !== "object" || job === null || Array.isArray(job)) {
1668
+ return {
1669
+ id: 0,
1670
+ name: null,
1671
+ status: null,
1672
+ conclusion: null,
1673
+ startedAt: null,
1674
+ completedAt: null,
1675
+ url: null
1676
+ };
1677
+ }
1678
+ const record = job;
1679
+ return {
1680
+ id: typeof record.databaseId === "number" ? record.databaseId : 0,
1681
+ name: typeof record.name === "string" ? record.name : null,
1682
+ status: typeof record.status === "string" ? record.status : null,
1683
+ conclusion: typeof record.conclusion === "string" ? record.conclusion : null,
1684
+ startedAt: typeof record.startedAt === "string" ? record.startedAt : null,
1685
+ completedAt: typeof record.completedAt === "string" ? record.completedAt : null,
1686
+ url: typeof record.url === "string" ? record.url : null
1687
+ };
1688
+ })
1689
+ };
1690
+ }
1691
+ if (capabilityId === "workflow_job.logs.get") {
1692
+ const jobId = Number(params.jobId);
1693
+ const rawLog = typeof data === "string" ? data : String(data);
1694
+ const truncated = rawLog.length > MAX_WORKFLOW_JOB_LOG_CHARS;
1695
+ return {
1696
+ jobId,
1697
+ log: truncated ? rawLog.slice(0, MAX_WORKFLOW_JOB_LOG_CHARS) : rawLog,
1698
+ truncated
1699
+ };
1700
+ }
1701
+ if (capabilityId === "workflow_job.logs.analyze") {
1702
+ const jobId = Number(params.jobId);
1703
+ const rawLog = typeof data === "string" ? data : String(data);
1704
+ const truncated = rawLog.length > MAX_WORKFLOW_JOB_LOG_CHARS;
1705
+ const boundedLog = truncated ? rawLog.slice(0, MAX_WORKFLOW_JOB_LOG_CHARS) : rawLog;
1706
+ const lines = boundedLog.split(/\r?\n/);
1707
+ const errorLines = lines.filter((line) => /\berror\b/i.test(line));
1708
+ const topErrorLines = errorLines.slice(0, 10);
1709
+ const warningLines = lines.filter((line) => /\bwarn(ing)?\b/i.test(line));
1710
+ return {
1711
+ jobId,
1712
+ truncated,
1713
+ summary: {
1714
+ errorCount: errorLines.length,
1715
+ warningCount: warningLines.length,
1716
+ topErrorLines
1717
+ }
1718
+ };
1719
+ }
1720
+ if (capabilityId === "workflow.list") {
1721
+ const workflows = Array.isArray(data) ? data : [];
1722
+ return {
1723
+ items: workflows.map((workflow) => normalizeWorkflowItem(workflow)),
1724
+ pageInfo: {
1725
+ hasNextPage: false,
1726
+ endCursor: null
1727
+ }
1728
+ };
1729
+ }
1730
+ if (capabilityId === "release.list") {
1731
+ const items = Array.isArray(data) ? data.map((item) => normalizeRelease(item)) : [];
1732
+ return {
1733
+ items,
1734
+ pageInfo: {
1735
+ hasNextPage: false,
1736
+ endCursor: null
1737
+ }
1738
+ };
1739
+ }
1740
+ if (capabilityId === "workflow.get") {
1741
+ const input = normalizeWorkflowItem(data);
1742
+ const root = typeof data === "object" && data !== null && !Array.isArray(data) ? data : {};
1743
+ return {
1744
+ ...input,
1745
+ url: typeof root.url === "string" ? root.url : null
1746
+ };
1747
+ }
1748
+ if (capabilityId === "workflow_run.get") {
1749
+ const input = typeof data === "object" && data !== null && !Array.isArray(data) ? data : {};
1750
+ return {
1751
+ id: typeof input.databaseId === "number" ? input.databaseId : 0,
1752
+ workflowName: typeof input.workflowName === "string" ? input.workflowName : null,
1753
+ status: typeof input.status === "string" ? input.status : null,
1754
+ conclusion: typeof input.conclusion === "string" ? input.conclusion : null,
1755
+ headBranch: typeof input.headBranch === "string" ? input.headBranch : null,
1756
+ headSha: typeof input.headSha === "string" ? input.headSha : null,
1757
+ event: typeof input.event === "string" ? input.event : null,
1758
+ createdAt: typeof input.createdAt === "string" ? input.createdAt : null,
1759
+ updatedAt: typeof input.updatedAt === "string" ? input.updatedAt : null,
1760
+ startedAt: typeof input.startedAt === "string" ? input.startedAt : null,
1761
+ url: typeof input.url === "string" ? input.url : null
1762
+ };
1763
+ }
1764
+ if (capabilityId === "workflow_run.rerun_all") {
1765
+ return {
1766
+ runId: Number(params.runId),
1767
+ status: "requested"
1768
+ };
1769
+ }
1770
+ if (capabilityId === "workflow_run.cancel") {
1771
+ return {
1772
+ runId: Number(params.runId),
1773
+ status: "cancel_requested"
1774
+ };
1775
+ }
1776
+ if (capabilityId === "workflow_run.artifacts.list") {
1777
+ const root = typeof data === "object" && data !== null && !Array.isArray(data) ? data : {};
1778
+ const artifacts = Array.isArray(root.artifacts) ? root.artifacts : [];
1779
+ return {
1780
+ items: artifacts.map((artifact) => {
1781
+ if (typeof artifact !== "object" || artifact === null || Array.isArray(artifact)) {
1782
+ return {
1783
+ id: 0,
1784
+ name: null,
1785
+ sizeInBytes: null,
1786
+ archiveDownloadUrl: null
1787
+ };
1788
+ }
1789
+ const record = artifact;
1790
+ return {
1791
+ id: typeof record.id === "number" ? record.id : 0,
1792
+ name: typeof record.name === "string" ? record.name : null,
1793
+ sizeInBytes: typeof record.sizeInBytes === "number" ? record.sizeInBytes : null,
1794
+ archiveDownloadUrl: typeof record.archiveDownloadUrl === "string" ? record.archiveDownloadUrl : null
1795
+ };
1796
+ }),
1797
+ pageInfo: {
1798
+ hasNextPage: false,
1799
+ endCursor: null
1800
+ }
1801
+ };
1802
+ }
1803
+ if (capabilityId === "project_v2.org.get" || capabilityId === "project_v2.user.get") {
1804
+ return normalizeProjectV2Summary(data);
1805
+ }
1806
+ if (capabilityId === "project_v2.fields.list") {
1807
+ const root = typeof data === "object" && data !== null && !Array.isArray(data) ? data : {};
1808
+ const fields = Array.isArray(root.fields) ? root.fields : [];
1809
+ return {
1810
+ items: fields.map((field) => {
1811
+ if (typeof field !== "object" || field === null || Array.isArray(field)) {
1812
+ return {
1813
+ id: null,
1814
+ name: null,
1815
+ dataType: null
1816
+ };
1817
+ }
1818
+ const record = field;
1819
+ return {
1820
+ id: typeof record.id === "string" ? record.id : null,
1821
+ name: typeof record.name === "string" ? record.name : null,
1822
+ dataType: typeof record.dataType === "string" ? record.dataType : null
1823
+ };
1824
+ }),
1825
+ pageInfo: {
1826
+ hasNextPage: false,
1827
+ endCursor: null
1828
+ }
1829
+ };
1830
+ }
1831
+ if (capabilityId === "project_v2.items.list") {
1832
+ const root = typeof data === "object" && data !== null && !Array.isArray(data) ? data : {};
1833
+ const items = Array.isArray(root.items) ? root.items : [];
1834
+ return {
1835
+ items: items.map((item) => {
1836
+ if (typeof item !== "object" || item === null || Array.isArray(item)) {
1837
+ return {
1838
+ id: null,
1839
+ contentType: null,
1840
+ contentNumber: null,
1841
+ contentTitle: null
1842
+ };
1843
+ }
1844
+ const record = item;
1845
+ const content = typeof record.content === "object" && record.content !== null && !Array.isArray(record.content) ? record.content : {};
1846
+ return {
1847
+ id: typeof record.id === "string" ? record.id : null,
1848
+ contentType: typeof content.type === "string" ? content.type : null,
1849
+ contentNumber: typeof content.number === "number" ? content.number : null,
1850
+ contentTitle: typeof content.title === "string" ? content.title : null
1851
+ };
1852
+ }),
1853
+ pageInfo: {
1854
+ hasNextPage: false,
1855
+ endCursor: null
1856
+ }
1857
+ };
1858
+ }
1859
+ if (capabilityId === "project_v2.item.add_issue") {
1860
+ const root = typeof data === "object" && data !== null && !Array.isArray(data) ? data : {};
1861
+ return {
1862
+ itemId: typeof root.id === "string" ? root.id : null,
1863
+ added: true
1864
+ };
1865
+ }
1866
+ if (capabilityId === "project_v2.item.field.update") {
1867
+ return {
1868
+ itemId: parseNonEmptyString(params.itemId),
1869
+ updated: true
1870
+ };
1871
+ }
1872
+ if (capabilityId === "release.get" || capabilityId === "release.create_draft" || capabilityId === "release.update") {
1873
+ return normalizeRelease(data);
1874
+ }
1875
+ if (capabilityId === "release.publish_draft") {
1876
+ const release = normalizeRelease(data);
1877
+ return {
1878
+ ...release,
1879
+ wasDraft: Boolean(context?.wasDraft)
1880
+ };
1881
+ }
1882
+ if (capabilityId === "workflow_dispatch.run") {
1883
+ return {
1884
+ workflowId: String(params.workflowId),
1885
+ ref: String(params.ref),
1886
+ dispatched: true
1887
+ };
1888
+ }
1889
+ if (capabilityId === "workflow_run.rerun_failed") {
1890
+ return {
1891
+ runId: Number(params.runId),
1892
+ rerunFailed: true
1893
+ };
1894
+ }
1895
+ if (capabilityId === "issue.view" || capabilityId === "pr.view") {
1896
+ return normalizeListItem(data);
1897
+ }
1898
+ return data;
1899
+ }
1900
+ async function runCliCapability(runner, capabilityId, params, card) {
1901
+ try {
1902
+ if (capabilityId === "release.publish_draft") {
1903
+ const owner = String(params.owner ?? "");
1904
+ const name = String(params.name ?? "");
1905
+ const releaseId = parseStrictPositiveInt(params.releaseId);
1906
+ if (!owner || !name || releaseId === null) {
1907
+ throw new Error("Missing owner/name/releaseId for release.publish_draft");
1908
+ }
1909
+ const readArgs = [
1910
+ ...commandTokens(card, "api"),
1911
+ `repos/${owner}/${name}/releases/${releaseId}`
1912
+ ];
1913
+ const readResult = await runner.run("gh", readArgs, DEFAULT_TIMEOUT_MS);
1914
+ if (readResult.exitCode !== 0) {
1915
+ const code = mapErrorToCode(readResult.stderr);
1916
+ return normalizeError(
1917
+ {
1918
+ code,
1919
+ message: sanitizeCliErrorMessage(readResult.stderr, readResult.exitCode),
1920
+ retryable: isRetryableErrorCode(code),
1921
+ details: { capabilityId, exitCode: readResult.exitCode }
1922
+ },
1923
+ "cli",
1924
+ { capabilityId, reason: "CARD_FALLBACK" }
1925
+ );
1926
+ }
1927
+ const currentRelease = parseCliData(readResult.stdout);
1928
+ const currentDraftValue = typeof currentRelease === "object" && currentRelease !== null && !Array.isArray(currentRelease) ? currentRelease.draft : void 0;
1929
+ if (currentDraftValue !== true) {
1930
+ return normalizeError(
1931
+ {
1932
+ code: errorCodes.Validation,
1933
+ message: "release.publish_draft requires an existing draft release",
1934
+ retryable: false
1935
+ },
1936
+ "cli",
1937
+ { capabilityId, reason: "CARD_FALLBACK" }
1938
+ );
1939
+ }
1940
+ const args2 = buildArgs(capabilityId, params, card);
1941
+ const result2 = await runner.run("gh", args2, DEFAULT_TIMEOUT_MS);
1942
+ if (result2.exitCode !== 0) {
1943
+ const code = mapErrorToCode(result2.stderr);
1944
+ return normalizeError(
1945
+ {
1946
+ code,
1947
+ message: sanitizeCliErrorMessage(result2.stderr, result2.exitCode),
1948
+ retryable: isRetryableErrorCode(code),
1949
+ details: { capabilityId, exitCode: result2.exitCode }
1950
+ },
1951
+ "cli",
1952
+ { capabilityId, reason: "CARD_FALLBACK" }
1953
+ );
1954
+ }
1955
+ const normalized2 = normalizeCliData(capabilityId, parseCliData(result2.stdout), params, {
1956
+ wasDraft: true
1957
+ });
1958
+ return normalizeResult(normalized2, "cli", { capabilityId, reason: "CARD_FALLBACK" });
1959
+ }
1960
+ const args = buildArgs(capabilityId, params, card);
1961
+ const result = await runner.run("gh", args, DEFAULT_TIMEOUT_MS);
1962
+ let failureStderr = result.stderr;
1963
+ if (result.exitCode !== 0) {
1964
+ if (capabilityId === "pr.checks.rerun_failed" && shouldFallbackRerunFailedToAll(result.stderr)) {
1965
+ const rerunAllArgs = buildArgs("pr.checks.rerun_all", params, card);
1966
+ const rerunAllResult = await runner.run("gh", rerunAllArgs, DEFAULT_TIMEOUT_MS);
1967
+ if (rerunAllResult.exitCode === 0) {
1968
+ const rerunData = NON_JSON_STDOUT_CAPABILITIES.has(capabilityId) ? {} : parseCliData(rerunAllResult.stdout);
1969
+ const fallbackData = normalizeCliData(capabilityId, rerunData, params, {
1970
+ effectiveRerunMode: "all"
1971
+ });
1972
+ return normalizeResult(fallbackData, "cli", { capabilityId, reason: "CARD_FALLBACK" });
1973
+ }
1974
+ failureStderr = rerunAllResult.stderr || rerunAllResult.stdout || result.stderr;
1975
+ }
1976
+ const code = mapErrorToCode(failureStderr);
1977
+ return normalizeError(
1978
+ {
1979
+ code,
1980
+ message: sanitizeCliErrorMessage(failureStderr, result.exitCode),
1981
+ retryable: isRetryableErrorCode(code),
1982
+ details: { capabilityId, exitCode: result.exitCode }
1983
+ },
1984
+ "cli",
1985
+ { capabilityId, reason: "CARD_FALLBACK" }
1986
+ );
1987
+ }
1988
+ const data = capabilityId === "workflow_job.logs.get" || capabilityId === "workflow_job.logs.analyze" ? result.stdout : NON_JSON_STDOUT_CAPABILITIES.has(capabilityId) ? {} : parseCliData(result.stdout);
1989
+ const normalized = normalizeCliData(capabilityId, data, params);
1990
+ return normalizeResult(normalized, "cli", { capabilityId, reason: "CARD_FALLBACK" });
1991
+ } catch (error) {
1992
+ if (error instanceof SyntaxError) {
1993
+ return normalizeError(
1994
+ {
1995
+ code: errorCodes.Server,
1996
+ message: "Failed to parse CLI JSON output",
1997
+ retryable: false
1998
+ },
1999
+ "cli",
2000
+ { capabilityId, reason: "CARD_FALLBACK" }
2001
+ );
2002
+ }
2003
+ if (error instanceof Error && error.message.toLowerCase().includes("invalid cli payload")) {
2004
+ return normalizeError(
2005
+ {
2006
+ code: errorCodes.Server,
2007
+ message: error.message,
2008
+ retryable: false
2009
+ },
2010
+ "cli",
2011
+ { capabilityId, reason: "CARD_FALLBACK" }
2012
+ );
2013
+ }
2014
+ if (error instanceof Error && error.message.toLowerCase().includes("invalid after cursor")) {
2015
+ return normalizeError(
2016
+ {
2017
+ code: errorCodes.Validation,
2018
+ message: error.message,
2019
+ retryable: false
2020
+ },
2021
+ "cli",
2022
+ { capabilityId, reason: "CARD_FALLBACK" }
2023
+ );
2024
+ }
2025
+ if (error instanceof Error && error.message.toLowerCase().includes("only supports draft=true")) {
2026
+ return normalizeError(
2027
+ {
2028
+ code: errorCodes.Validation,
2029
+ message: error.message,
2030
+ retryable: false
2031
+ },
2032
+ "cli",
2033
+ { capabilityId, reason: "CARD_FALLBACK" }
2034
+ );
2035
+ }
2036
+ const code = mapErrorToCode(error);
2037
+ return normalizeError(
2038
+ {
2039
+ code,
2040
+ message: error instanceof Error ? error.message : String(error),
2041
+ retryable: isRetryableErrorCode(code)
2042
+ },
2043
+ "cli",
2044
+ { capabilityId, reason: "CARD_FALLBACK" }
2045
+ );
2046
+ }
2047
+ }
2048
+
2049
+ // src/core/execution/adapters/graphql-capability-adapter.ts
2050
+ var DEFAULT_LIST_FIRST2 = 30;
2051
+ function unsupportedGraphqlCapability(capabilityId) {
2052
+ return normalizeError(
2053
+ {
2054
+ code: errorCodes.AdapterUnsupported,
2055
+ message: `Unsupported GraphQL capability: ${capabilityId}`,
2056
+ retryable: false
2057
+ },
2058
+ "graphql",
2059
+ { capabilityId, reason: "CAPABILITY_LIMIT" }
2060
+ );
2061
+ }
2062
+ function withDefaultFirst(params) {
2063
+ if (params.first === void 0) {
2064
+ return {
2065
+ ...params,
2066
+ first: DEFAULT_LIST_FIRST2
2067
+ };
2068
+ }
2069
+ return params;
2070
+ }
2071
+ function requireNonEmptyString(params, field, capabilityId) {
2072
+ const value = params[field];
2073
+ if (typeof value !== "string" || value.trim().length === 0) {
2074
+ throw new Error(`Missing or invalid ${field} for ${capabilityId}`);
2075
+ }
2076
+ return value;
2077
+ }
2078
+ async function runGraphqlCapability(client, capabilityId, params) {
2079
+ try {
2080
+ if (capabilityId === "repo.view") {
2081
+ const data = await client.fetchRepoView(params);
2082
+ return normalizeResult(data, "graphql", { capabilityId, reason: "CARD_PREFERRED" });
2083
+ }
2084
+ if (capabilityId === "issue.view") {
2085
+ const data = await client.fetchIssueView(params);
2086
+ return normalizeResult(data, "graphql", { capabilityId, reason: "CARD_PREFERRED" });
2087
+ }
2088
+ if (capabilityId === "issue.list") {
2089
+ const data = await client.fetchIssueList(withDefaultFirst(params));
2090
+ return normalizeResult(data, "graphql", { capabilityId, reason: "CARD_PREFERRED" });
2091
+ }
2092
+ if (capabilityId === "issue.comments.list") {
2093
+ const data = await client.fetchIssueCommentsList(params);
2094
+ return normalizeResult(data, "graphql", { capabilityId, reason: "CARD_PREFERRED" });
2095
+ }
2096
+ if (capabilityId === "issue.create") {
2097
+ if (!client.createIssue) {
2098
+ return unsupportedGraphqlCapability(capabilityId);
2099
+ }
2100
+ const data = await client.createIssue(params);
2101
+ return normalizeResult(data, "graphql", { capabilityId, reason: "CARD_PREFERRED" });
2102
+ }
2103
+ if (capabilityId === "issue.update") {
2104
+ if (!client.updateIssue) {
2105
+ return unsupportedGraphqlCapability(capabilityId);
2106
+ }
2107
+ const data = await client.updateIssue(params);
2108
+ return normalizeResult(data, "graphql", { capabilityId, reason: "CARD_PREFERRED" });
2109
+ }
2110
+ if (capabilityId === "issue.close") {
2111
+ if (!client.closeIssue) {
2112
+ return unsupportedGraphqlCapability(capabilityId);
2113
+ }
2114
+ const data = await client.closeIssue(params);
2115
+ return normalizeResult(data, "graphql", { capabilityId, reason: "CARD_PREFERRED" });
2116
+ }
2117
+ if (capabilityId === "issue.reopen") {
2118
+ if (!client.reopenIssue) {
2119
+ return unsupportedGraphqlCapability(capabilityId);
2120
+ }
2121
+ const data = await client.reopenIssue(params);
2122
+ return normalizeResult(data, "graphql", { capabilityId, reason: "CARD_PREFERRED" });
2123
+ }
2124
+ if (capabilityId === "issue.delete") {
2125
+ if (!client.deleteIssue) {
2126
+ return unsupportedGraphqlCapability(capabilityId);
2127
+ }
2128
+ const data = await client.deleteIssue(params);
2129
+ return normalizeResult(data, "graphql", { capabilityId, reason: "CARD_PREFERRED" });
2130
+ }
2131
+ if (capabilityId === "issue.labels.update") {
2132
+ if (!client.updateIssueLabels) {
2133
+ return unsupportedGraphqlCapability(capabilityId);
2134
+ }
2135
+ const data = await client.updateIssueLabels(params);
2136
+ return normalizeResult(data, "graphql", { capabilityId, reason: "CARD_PREFERRED" });
2137
+ }
2138
+ if (capabilityId === "issue.assignees.update") {
2139
+ if (!client.updateIssueAssignees) {
2140
+ return unsupportedGraphqlCapability(capabilityId);
2141
+ }
2142
+ const data = await client.updateIssueAssignees(params);
2143
+ return normalizeResult(data, "graphql", { capabilityId, reason: "CARD_PREFERRED" });
2144
+ }
2145
+ if (capabilityId === "issue.milestone.set") {
2146
+ if (!client.setIssueMilestone) {
2147
+ return unsupportedGraphqlCapability(capabilityId);
2148
+ }
2149
+ const data = await client.setIssueMilestone(params);
2150
+ return normalizeResult(data, "graphql", { capabilityId, reason: "CARD_PREFERRED" });
2151
+ }
2152
+ if (capabilityId === "issue.comments.create") {
2153
+ if (!client.createIssueComment) {
2154
+ return unsupportedGraphqlCapability(capabilityId);
2155
+ }
2156
+ const data = await client.createIssueComment(params);
2157
+ return normalizeResult(data, "graphql", { capabilityId, reason: "CARD_PREFERRED" });
2158
+ }
2159
+ if (capabilityId === "issue.linked_prs.list") {
2160
+ if (!client.fetchIssueLinkedPrs) {
2161
+ return unsupportedGraphqlCapability(capabilityId);
2162
+ }
2163
+ const data = await client.fetchIssueLinkedPrs(params);
2164
+ return normalizeResult(data, "graphql", { capabilityId, reason: "CARD_PREFERRED" });
2165
+ }
2166
+ if (capabilityId === "issue.relations.get") {
2167
+ if (!client.fetchIssueRelations) {
2168
+ return unsupportedGraphqlCapability(capabilityId);
2169
+ }
2170
+ const data = await client.fetchIssueRelations(params);
2171
+ return normalizeResult(data, "graphql", { capabilityId, reason: "CARD_PREFERRED" });
2172
+ }
2173
+ if (capabilityId === "issue.parent.set") {
2174
+ if (!client.setIssueParent) {
2175
+ return unsupportedGraphqlCapability(capabilityId);
2176
+ }
2177
+ const data = await client.setIssueParent(params);
2178
+ return normalizeResult(data, "graphql", { capabilityId, reason: "CARD_PREFERRED" });
2179
+ }
2180
+ if (capabilityId === "issue.parent.remove") {
2181
+ if (!client.removeIssueParent) {
2182
+ return unsupportedGraphqlCapability(capabilityId);
2183
+ }
2184
+ const data = await client.removeIssueParent(params);
2185
+ return normalizeResult(data, "graphql", { capabilityId, reason: "CARD_PREFERRED" });
2186
+ }
2187
+ if (capabilityId === "issue.blocked_by.add") {
2188
+ if (!client.addIssueBlockedBy) {
2189
+ return unsupportedGraphqlCapability(capabilityId);
2190
+ }
2191
+ const data = await client.addIssueBlockedBy(params);
2192
+ return normalizeResult(data, "graphql", { capabilityId, reason: "CARD_PREFERRED" });
2193
+ }
2194
+ if (capabilityId === "issue.blocked_by.remove") {
2195
+ if (!client.removeIssueBlockedBy) {
2196
+ return unsupportedGraphqlCapability(capabilityId);
2197
+ }
2198
+ const data = await client.removeIssueBlockedBy(params);
2199
+ return normalizeResult(data, "graphql", { capabilityId, reason: "CARD_PREFERRED" });
2200
+ }
2201
+ if (capabilityId === "pr.view") {
2202
+ const data = await client.fetchPrView(params);
2203
+ return normalizeResult(data, "graphql", { capabilityId, reason: "CARD_PREFERRED" });
2204
+ }
2205
+ if (capabilityId === "pr.list") {
2206
+ const data = await client.fetchPrList(withDefaultFirst(params));
2207
+ return normalizeResult(data, "graphql", { capabilityId, reason: "CARD_PREFERRED" });
2208
+ }
2209
+ if (capabilityId === "pr.comments.list") {
2210
+ const data = await client.fetchPrCommentsList(withDefaultFirst(params));
2211
+ return normalizeResult(data, "graphql", { capabilityId, reason: "CARD_PREFERRED" });
2212
+ }
2213
+ if (capabilityId === "pr.reviews.list") {
2214
+ const data = await client.fetchPrReviewsList(withDefaultFirst(params));
2215
+ return normalizeResult(data, "graphql", { capabilityId, reason: "CARD_PREFERRED" });
2216
+ }
2217
+ if (capabilityId === "pr.diff.list_files") {
2218
+ const data = await client.fetchPrDiffListFiles(
2219
+ withDefaultFirst(params)
2220
+ );
2221
+ return normalizeResult(data, "graphql", { capabilityId, reason: "CARD_PREFERRED" });
2222
+ }
2223
+ if (capabilityId === "pr.comment.reply") {
2224
+ const threadId = requireNonEmptyString(params, "threadId", capabilityId);
2225
+ const body = requireNonEmptyString(params, "body", capabilityId);
2226
+ const data = await client.replyToReviewThread({ threadId, body });
2227
+ return normalizeResult(data, "graphql", { capabilityId, reason: "CARD_PREFERRED" });
2228
+ }
2229
+ if (capabilityId === "pr.comment.resolve") {
2230
+ const threadId = requireNonEmptyString(params, "threadId", capabilityId);
2231
+ const data = await client.resolveReviewThread({ threadId });
2232
+ return normalizeResult(data, "graphql", { capabilityId, reason: "CARD_PREFERRED" });
2233
+ }
2234
+ if (capabilityId === "pr.comment.unresolve") {
2235
+ const threadId = requireNonEmptyString(params, "threadId", capabilityId);
2236
+ const data = await client.unresolveReviewThread({ threadId });
2237
+ return normalizeResult(data, "graphql", { capabilityId, reason: "CARD_PREFERRED" });
2238
+ }
2239
+ return unsupportedGraphqlCapability(capabilityId);
2240
+ } catch (error) {
2241
+ const code = mapErrorToCode(error);
2242
+ return normalizeError(
2243
+ {
2244
+ code,
2245
+ message: error instanceof Error ? error.message : String(error),
2246
+ retryable: isRetryableErrorCode(code)
2247
+ },
2248
+ "graphql",
2249
+ { capabilityId, reason: "CARD_PREFERRED" }
2250
+ );
2251
+ }
2252
+ }
2253
+
2254
+ // src/core/execution/preflight.ts
2255
+ function preflightCheck(input) {
2256
+ if (input.route === "rest") {
2257
+ return {
2258
+ ok: false,
2259
+ code: errorCodes.AdapterUnsupported,
2260
+ message: "REST route is planned but not implemented in v1",
2261
+ retryable: false,
2262
+ details: { route: input.route }
2263
+ };
2264
+ }
2265
+ if (input.route === "cli" && input.ghCliAvailable === false) {
2266
+ return {
2267
+ ok: false,
2268
+ code: errorCodes.AdapterUnsupported,
2269
+ message: "GitHub CLI is required for cli route",
2270
+ retryable: false,
2271
+ details: { route: input.route }
2272
+ };
2273
+ }
2274
+ if (input.route === "cli" && input.ghAuthenticated === false) {
2275
+ return {
2276
+ ok: false,
2277
+ code: errorCodes.Auth,
2278
+ message: "GitHub CLI authentication is required for cli route",
2279
+ retryable: false,
2280
+ details: { route: input.route }
2281
+ };
2282
+ }
2283
+ if (input.route === "graphql") {
2284
+ const token = input.githubToken?.trim();
2285
+ if (!token) {
2286
+ return {
2287
+ ok: false,
2288
+ code: errorCodes.Auth,
2289
+ message: "GitHub token is required for graphql route",
2290
+ retryable: false,
2291
+ details: { route: input.route }
2292
+ };
2293
+ }
2294
+ }
2295
+ return { ok: true };
2296
+ }
2297
+
2298
+ // src/core/routing/policy.ts
2299
+ var routePreferenceOrder = ["cli", "graphql"];
2300
+
2301
+ // src/core/routing/engine.ts
2302
+ var DEFAULT_REASON = "DEFAULT_POLICY";
2303
+ var CLI_ENV_CACHE_TTL_MS = 3e4;
2304
+ var cliEnvironmentCache = /* @__PURE__ */ new WeakMap();
2305
+ var cliEnvironmentInFlight = /* @__PURE__ */ new WeakMap();
2306
+ var defaultCliRunner = createSafeCliCommandRunner();
2307
+ async function detectCliEnvironment(runner) {
2308
+ try {
2309
+ const version = await runner.run("gh", ["--version"], 1500);
2310
+ if (version.exitCode !== 0) {
2311
+ return {
2312
+ ghCliAvailable: false,
2313
+ ghAuthenticated: false
2314
+ };
2315
+ }
2316
+ const auth = await runner.run("gh", ["auth", "status"], 2500);
2317
+ return {
2318
+ ghCliAvailable: true,
2319
+ ghAuthenticated: auth.exitCode === 0
2320
+ };
2321
+ } catch {
2322
+ return {
2323
+ ghCliAvailable: false,
2324
+ ghAuthenticated: false
2325
+ };
2326
+ }
2327
+ }
2328
+ async function detectCliEnvironmentCached(runner) {
2329
+ const now = Date.now();
2330
+ const cached = cliEnvironmentCache.get(runner);
2331
+ if (cached && cached.expiresAt > now) {
2332
+ return cached.value;
2333
+ }
2334
+ const inFlight = cliEnvironmentInFlight.get(runner);
2335
+ if (inFlight) {
2336
+ return inFlight;
2337
+ }
2338
+ const probePromise = detectCliEnvironment(runner).then((value) => {
2339
+ cliEnvironmentCache.set(runner, {
2340
+ value,
2341
+ expiresAt: Date.now() + CLI_ENV_CACHE_TTL_MS
2342
+ });
2343
+ cliEnvironmentInFlight.delete(runner);
2344
+ return value;
2345
+ }).catch((error) => {
2346
+ cliEnvironmentInFlight.delete(runner);
2347
+ throw error;
2348
+ });
2349
+ cliEnvironmentInFlight.set(runner, probePromise);
2350
+ return probePromise;
2351
+ }
2352
+ async function executeTask(request, deps) {
2353
+ const reason = deps.reason ?? DEFAULT_REASON;
2354
+ const card = getOperationCard(request.task);
2355
+ if (!card) {
2356
+ return normalizeError(
2357
+ {
2358
+ code: errorCodes.Validation,
2359
+ message: `Unsupported task: ${request.task}`,
2360
+ retryable: false
2361
+ },
2362
+ routePreferenceOrder[0],
2363
+ { capabilityId: request.task, reason }
2364
+ );
2365
+ }
2366
+ const cliRunner = deps.cliRunner ?? defaultCliRunner;
2367
+ return execute({
2368
+ card,
2369
+ params: request.input,
2370
+ routingContext: {
2371
+ ghCliAvailable: deps.ghCliAvailable,
2372
+ ghAuthenticated: deps.ghAuthenticated,
2373
+ githubTokenPresent: Boolean(deps.githubToken)
2374
+ },
2375
+ retry: {
2376
+ maxAttemptsPerRoute: 2
2377
+ },
2378
+ preflight: async (route) => {
2379
+ const preflightInput = { route };
2380
+ if (deps.githubToken !== void 0) {
2381
+ preflightInput.githubToken = deps.githubToken;
2382
+ }
2383
+ if (route === "cli") {
2384
+ if (deps.ghCliAvailable !== void 0) {
2385
+ preflightInput.ghCliAvailable = deps.ghCliAvailable;
2386
+ }
2387
+ if (deps.ghAuthenticated !== void 0) {
2388
+ preflightInput.ghAuthenticated = deps.ghAuthenticated;
2389
+ }
2390
+ if (preflightInput.ghCliAvailable === void 0 || preflightInput.ghAuthenticated === void 0) {
2391
+ if (deps.skipGhPreflight === true) {
2392
+ if (preflightInput.ghCliAvailable === void 0) {
2393
+ preflightInput.ghCliAvailable = true;
2394
+ }
2395
+ if (preflightInput.ghAuthenticated === void 0) {
2396
+ preflightInput.ghAuthenticated = true;
2397
+ }
2398
+ } else {
2399
+ const detected = await detectCliEnvironmentCached(cliRunner);
2400
+ if (preflightInput.ghCliAvailable === void 0) {
2401
+ preflightInput.ghCliAvailable = detected.ghCliAvailable;
2402
+ }
2403
+ if (preflightInput.ghAuthenticated === void 0) {
2404
+ preflightInput.ghAuthenticated = detected.ghAuthenticated;
2405
+ }
2406
+ }
2407
+ }
2408
+ }
2409
+ return preflightCheck(preflightInput);
2410
+ },
2411
+ routes: {
2412
+ graphql: async () => runGraphqlCapability(
2413
+ deps.githubClient,
2414
+ request.task,
2415
+ request.input
2416
+ ),
2417
+ cli: async () => {
2418
+ return runCliCapability(
2419
+ cliRunner,
2420
+ request.task,
2421
+ request.input,
2422
+ card
2423
+ );
2424
+ },
2425
+ rest: async () => normalizeError(
2426
+ {
2427
+ code: errorCodes.AdapterUnsupported,
2428
+ message: `Route 'rest' is not implemented for task '${request.task}'`,
2429
+ retryable: false,
2430
+ details: { route: "rest", task: request.task }
2431
+ },
2432
+ "rest",
2433
+ { capabilityId: request.task, reason }
2434
+ )
2435
+ }
2436
+ });
2437
+ }
2438
+
2439
+ // src/gql/client.ts
2440
+ import { print } from "graphql";
2441
+
2442
+ // src/gql/operations/issue-comments-list.generated.ts
2443
+ var IssueCommentsListDocument = `
2444
+ query IssueCommentsList($owner: String!, $name: String!, $issueNumber: Int!, $first: Int!, $after: String) {
2445
+ repository(owner: $owner, name: $name) {
2446
+ issue(number: $issueNumber) {
2447
+ comments(first: $first, after: $after) {
2448
+ nodes {
2449
+ id
2450
+ body
2451
+ createdAt
2452
+ url
2453
+ author {
2454
+ login
2455
+ }
2456
+ }
2457
+ pageInfo {
2458
+ endCursor
2459
+ hasNextPage
2460
+ }
2461
+ }
2462
+ }
2463
+ }
2464
+ }
2465
+ `;
2466
+ var defaultWrapper = (action, _operationName, _operationType, _variables) => action();
2467
+ function getSdk(client, withWrapper = defaultWrapper) {
2468
+ return {
2469
+ IssueCommentsList(variables, requestHeaders, signal) {
2470
+ return withWrapper(
2471
+ (wrappedRequestHeaders) => client.request({
2472
+ document: IssueCommentsListDocument,
2473
+ variables,
2474
+ requestHeaders: { ...requestHeaders, ...wrappedRequestHeaders },
2475
+ signal
2476
+ }),
2477
+ "IssueCommentsList",
2478
+ "query",
2479
+ variables
2480
+ );
2481
+ }
2482
+ };
2483
+ }
2484
+
2485
+ // src/gql/operations/issue-list.generated.ts
2486
+ var IssueListDocument = `
2487
+ query IssueList($owner: String!, $name: String!, $first: Int!, $after: String) {
2488
+ repository(owner: $owner, name: $name) {
2489
+ issues(
2490
+ first: $first
2491
+ after: $after
2492
+ orderBy: {field: CREATED_AT, direction: DESC}
2493
+ ) {
2494
+ nodes {
2495
+ id
2496
+ number
2497
+ title
2498
+ state
2499
+ url
2500
+ }
2501
+ pageInfo {
2502
+ endCursor
2503
+ hasNextPage
2504
+ }
2505
+ }
2506
+ }
2507
+ }
2508
+ `;
2509
+ var defaultWrapper2 = (action, _operationName, _operationType, _variables) => action();
2510
+ function getSdk2(client, withWrapper = defaultWrapper2) {
2511
+ return {
2512
+ IssueList(variables, requestHeaders, signal) {
2513
+ return withWrapper(
2514
+ (wrappedRequestHeaders) => client.request({
2515
+ document: IssueListDocument,
2516
+ variables,
2517
+ requestHeaders: { ...requestHeaders, ...wrappedRequestHeaders },
2518
+ signal
2519
+ }),
2520
+ "IssueList",
2521
+ "query",
2522
+ variables
2523
+ );
2524
+ }
2525
+ };
2526
+ }
2527
+
2528
+ // src/gql/operations/issue-view.generated.ts
2529
+ var IssueViewDocument = `
2530
+ query IssueView($owner: String!, $name: String!, $issueNumber: Int!) {
2531
+ repository(owner: $owner, name: $name) {
2532
+ issue(number: $issueNumber) {
2533
+ id
2534
+ number
2535
+ title
2536
+ state
2537
+ url
2538
+ }
2539
+ }
2540
+ }
2541
+ `;
2542
+ var defaultWrapper3 = (action, _operationName, _operationType, _variables) => action();
2543
+ function getSdk3(client, withWrapper = defaultWrapper3) {
2544
+ return {
2545
+ IssueView(variables, requestHeaders, signal) {
2546
+ return withWrapper(
2547
+ (wrappedRequestHeaders) => client.request({
2548
+ document: IssueViewDocument,
2549
+ variables,
2550
+ requestHeaders: { ...requestHeaders, ...wrappedRequestHeaders },
2551
+ signal
2552
+ }),
2553
+ "IssueView",
2554
+ "query",
2555
+ variables
2556
+ );
2557
+ }
2558
+ };
2559
+ }
2560
+
2561
+ // src/gql/operations/pr-diff-list-files.generated.ts
2562
+ var PrDiffListFilesDocument = `
2563
+ query PrDiffListFiles($owner: String!, $name: String!, $prNumber: Int!, $first: Int!, $after: String) {
2564
+ repository(owner: $owner, name: $name) {
2565
+ pullRequest(number: $prNumber) {
2566
+ files(first: $first, after: $after) {
2567
+ nodes {
2568
+ path
2569
+ additions
2570
+ deletions
2571
+ }
2572
+ pageInfo {
2573
+ hasNextPage
2574
+ endCursor
2575
+ }
2576
+ }
2577
+ }
2578
+ }
2579
+ }
2580
+ `;
2581
+ var defaultWrapper4 = (action, _operationName, _operationType, _variables) => action();
2582
+ function getSdk4(client, withWrapper = defaultWrapper4) {
2583
+ return {
2584
+ PrDiffListFiles(variables, requestHeaders, signal) {
2585
+ return withWrapper(
2586
+ (wrappedRequestHeaders) => client.request({
2587
+ document: PrDiffListFilesDocument,
2588
+ variables,
2589
+ requestHeaders: { ...requestHeaders, ...wrappedRequestHeaders },
2590
+ signal
2591
+ }),
2592
+ "PrDiffListFiles",
2593
+ "query",
2594
+ variables
2595
+ );
2596
+ }
2597
+ };
2598
+ }
2599
+
2600
+ // src/gql/operations/pr-list.generated.ts
2601
+ var PrListDocument = `
2602
+ query PrList($owner: String!, $name: String!, $first: Int!, $after: String) {
2603
+ repository(owner: $owner, name: $name) {
2604
+ pullRequests(
2605
+ first: $first
2606
+ after: $after
2607
+ orderBy: {field: CREATED_AT, direction: DESC}
2608
+ ) {
2609
+ nodes {
2610
+ id
2611
+ number
2612
+ title
2613
+ state
2614
+ url
2615
+ }
2616
+ pageInfo {
2617
+ endCursor
2618
+ hasNextPage
2619
+ }
2620
+ }
2621
+ }
2622
+ }
2623
+ `;
2624
+ var defaultWrapper5 = (action, _operationName, _operationType, _variables) => action();
2625
+ function getSdk5(client, withWrapper = defaultWrapper5) {
2626
+ return {
2627
+ PrList(variables, requestHeaders, signal) {
2628
+ return withWrapper(
2629
+ (wrappedRequestHeaders) => client.request({
2630
+ document: PrListDocument,
2631
+ variables,
2632
+ requestHeaders: { ...requestHeaders, ...wrappedRequestHeaders },
2633
+ signal
2634
+ }),
2635
+ "PrList",
2636
+ "query",
2637
+ variables
2638
+ );
2639
+ }
2640
+ };
2641
+ }
2642
+
2643
+ // src/gql/operations/pr-reviews-list.generated.ts
2644
+ var PrReviewsListDocument = `
2645
+ query PrReviewsList($owner: String!, $name: String!, $prNumber: Int!, $first: Int!, $after: String) {
2646
+ repository(owner: $owner, name: $name) {
2647
+ pullRequest(number: $prNumber) {
2648
+ reviews(first: $first, after: $after) {
2649
+ nodes {
2650
+ id
2651
+ author {
2652
+ login
2653
+ }
2654
+ body
2655
+ state
2656
+ submittedAt
2657
+ url
2658
+ commit {
2659
+ oid
2660
+ }
2661
+ }
2662
+ pageInfo {
2663
+ hasNextPage
2664
+ endCursor
2665
+ }
2666
+ }
2667
+ }
2668
+ }
2669
+ }
2670
+ `;
2671
+ var defaultWrapper6 = (action, _operationName, _operationType, _variables) => action();
2672
+ function getSdk6(client, withWrapper = defaultWrapper6) {
2673
+ return {
2674
+ PrReviewsList(variables, requestHeaders, signal) {
2675
+ return withWrapper(
2676
+ (wrappedRequestHeaders) => client.request({
2677
+ document: PrReviewsListDocument,
2678
+ variables,
2679
+ requestHeaders: { ...requestHeaders, ...wrappedRequestHeaders },
2680
+ signal
2681
+ }),
2682
+ "PrReviewsList",
2683
+ "query",
2684
+ variables
2685
+ );
2686
+ }
2687
+ };
2688
+ }
2689
+
2690
+ // src/gql/operations/pr-view.generated.ts
2691
+ var PrViewDocument = `
2692
+ query PrView($owner: String!, $name: String!, $prNumber: Int!) {
2693
+ repository(owner: $owner, name: $name) {
2694
+ pullRequest(number: $prNumber) {
2695
+ id
2696
+ number
2697
+ title
2698
+ state
2699
+ url
2700
+ }
2701
+ }
2702
+ }
2703
+ `;
2704
+ var defaultWrapper7 = (action, _operationName, _operationType, _variables) => action();
2705
+ function getSdk7(client, withWrapper = defaultWrapper7) {
2706
+ return {
2707
+ PrView(variables, requestHeaders, signal) {
2708
+ return withWrapper(
2709
+ (wrappedRequestHeaders) => client.request({
2710
+ document: PrViewDocument,
2711
+ variables,
2712
+ requestHeaders: { ...requestHeaders, ...wrappedRequestHeaders },
2713
+ signal
2714
+ }),
2715
+ "PrView",
2716
+ "query",
2717
+ variables
2718
+ );
2719
+ }
2720
+ };
2721
+ }
2722
+
2723
+ // src/gql/operations/repo-view.generated.ts
2724
+ var RepoViewDocument = `
2725
+ query RepoView($owner: String!, $name: String!) {
2726
+ repository(owner: $owner, name: $name) {
2727
+ id
2728
+ name
2729
+ nameWithOwner
2730
+ isPrivate
2731
+ stargazerCount
2732
+ forkCount
2733
+ url
2734
+ defaultBranchRef {
2735
+ name
2736
+ }
2737
+ }
2738
+ }
2739
+ `;
2740
+ var defaultWrapper8 = (action, _operationName, _operationType, _variables) => action();
2741
+ function getSdk8(client, withWrapper = defaultWrapper8) {
2742
+ return {
2743
+ RepoView(variables, requestHeaders, signal) {
2744
+ return withWrapper(
2745
+ (wrappedRequestHeaders) => client.request({
2746
+ document: RepoViewDocument,
2747
+ variables,
2748
+ requestHeaders: { ...requestHeaders, ...wrappedRequestHeaders },
2749
+ signal
2750
+ }),
2751
+ "RepoView",
2752
+ "query",
2753
+ variables
2754
+ );
2755
+ }
2756
+ };
2757
+ }
2758
+
2759
+ // src/gql/client.ts
2760
+ function assertRepoInput(input) {
2761
+ if (input.owner.trim().length === 0 || input.name.trim().length === 0) {
2762
+ throw new Error("Repository owner and name are required");
2763
+ }
2764
+ }
2765
+ function assertIssueInput(input) {
2766
+ if (input.owner.trim().length === 0 || input.name.trim().length === 0) {
2767
+ throw new Error("Repository owner and name are required");
2768
+ }
2769
+ if (!Number.isInteger(input.issueNumber) || input.issueNumber <= 0) {
2770
+ throw new Error("Issue number must be a positive integer");
2771
+ }
2772
+ }
2773
+ function assertIssueListInput(input) {
2774
+ if (input.owner.trim().length === 0 || input.name.trim().length === 0) {
2775
+ throw new Error("Repository owner and name are required");
2776
+ }
2777
+ if (!Number.isInteger(input.first) || input.first <= 0) {
2778
+ throw new Error("List page size must be a positive integer");
2779
+ }
2780
+ }
2781
+ function assertIssueCommentsListInput(input) {
2782
+ if (input.owner.trim().length === 0 || input.name.trim().length === 0) {
2783
+ throw new Error("Repository owner and name are required");
2784
+ }
2785
+ if (!Number.isInteger(input.issueNumber) || input.issueNumber <= 0) {
2786
+ throw new Error("Issue number must be a positive integer");
2787
+ }
2788
+ if (!Number.isInteger(input.first) || input.first <= 0) {
2789
+ throw new Error("List page size must be a positive integer");
2790
+ }
2791
+ if (input.after !== void 0 && input.after !== null && typeof input.after !== "string") {
2792
+ throw new Error("After cursor must be a string");
2793
+ }
2794
+ }
2795
+ function assertNonEmptyString(value, fieldName) {
2796
+ if (typeof value !== "string" || value.trim().length === 0) {
2797
+ throw new Error(`${fieldName} is required`);
2798
+ }
2799
+ return value;
2800
+ }
2801
+ function assertOptionalString(value, fieldName) {
2802
+ if (value === void 0) {
2803
+ return void 0;
2804
+ }
2805
+ if (typeof value !== "string") {
2806
+ throw new Error(`${fieldName} must be a string`);
2807
+ }
2808
+ return value;
2809
+ }
2810
+ function assertStringArray(value, fieldName) {
2811
+ if (!Array.isArray(value) || value.some((entry) => typeof entry !== "string" || entry.trim().length === 0)) {
2812
+ throw new Error(`${fieldName} must be an array of non-empty strings`);
2813
+ }
2814
+ return value;
2815
+ }
2816
+ function assertIssueCreateInput(input) {
2817
+ assertRepoInput({ owner: input.owner, name: input.name });
2818
+ assertNonEmptyString(input.title, "Issue title");
2819
+ assertOptionalString(input.body, "Issue body");
2820
+ }
2821
+ function assertIssueUpdateInput(input) {
2822
+ assertNonEmptyString(input.issueId, "Issue id");
2823
+ if (input.title === void 0 && input.body === void 0) {
2824
+ throw new Error("Issue update requires at least one field");
2825
+ }
2826
+ if (input.title !== void 0) {
2827
+ assertOptionalString(input.title, "Issue title");
2828
+ }
2829
+ if (input.body !== void 0) {
2830
+ assertOptionalString(input.body, "Issue body");
2831
+ }
2832
+ }
2833
+ function assertIssueMutationInput(input) {
2834
+ assertNonEmptyString(input.issueId, "Issue id");
2835
+ }
2836
+ function assertIssueLabelsUpdateInput(input) {
2837
+ assertIssueMutationInput({ issueId: input.issueId });
2838
+ assertStringArray(input.labels, "Labels");
2839
+ }
2840
+ function assertIssueAssigneesUpdateInput(input) {
2841
+ assertIssueMutationInput({ issueId: input.issueId });
2842
+ assertStringArray(input.assignees, "Assignees");
2843
+ }
2844
+ function assertIssueMilestoneSetInput(input) {
2845
+ assertIssueMutationInput({ issueId: input.issueId });
2846
+ if (input.milestoneNumber !== null && (!Number.isInteger(input.milestoneNumber) || input.milestoneNumber <= 0)) {
2847
+ throw new Error("Milestone number must be a positive integer or null");
2848
+ }
2849
+ }
2850
+ function assertIssueCommentCreateInput(input) {
2851
+ assertIssueMutationInput({ issueId: input.issueId });
2852
+ assertNonEmptyString(input.body, "Issue comment body");
2853
+ }
2854
+ function assertIssueLinkedPrsListInput(input) {
2855
+ assertIssueInput(input);
2856
+ }
2857
+ function assertIssueRelationsGetInput(input) {
2858
+ assertIssueInput(input);
2859
+ }
2860
+ function assertIssueParentSetInput(input) {
2861
+ assertIssueMutationInput({ issueId: input.issueId });
2862
+ assertNonEmptyString(input.parentIssueId, "Parent issue id");
2863
+ }
2864
+ function assertIssueParentRemoveInput(input) {
2865
+ assertIssueMutationInput({ issueId: input.issueId });
2866
+ }
2867
+ function assertIssueBlockedByInput(input) {
2868
+ assertIssueMutationInput({ issueId: input.issueId });
2869
+ assertNonEmptyString(input.blockedByIssueId, "Blocked-by issue id");
2870
+ }
2871
+ function assertPrInput(input) {
2872
+ if (input.owner.trim().length === 0 || input.name.trim().length === 0) {
2873
+ throw new Error("Repository owner and name are required");
2874
+ }
2875
+ if (!Number.isInteger(input.prNumber) || input.prNumber <= 0) {
2876
+ throw new Error("PR number must be a positive integer");
2877
+ }
2878
+ }
2879
+ function assertPrListInput(input) {
2880
+ if (input.owner.trim().length === 0 || input.name.trim().length === 0) {
2881
+ throw new Error("Repository owner and name are required");
2882
+ }
2883
+ if (!Number.isInteger(input.first) || input.first <= 0) {
2884
+ throw new Error("List page size must be a positive integer");
2885
+ }
2886
+ }
2887
+ function assertPrReviewsListInput(input) {
2888
+ if (typeof input.owner !== "string" || typeof input.name !== "string" || input.owner.trim().length === 0 || input.name.trim().length === 0) {
2889
+ throw new Error("Repository owner and name are required");
2890
+ }
2891
+ if (!Number.isInteger(input.prNumber) || input.prNumber <= 0) {
2892
+ throw new Error("PR number must be a positive integer");
2893
+ }
2894
+ if (!Number.isInteger(input.first) || input.first <= 0) {
2895
+ throw new Error("List page size must be a positive integer");
2896
+ }
2897
+ }
2898
+ function assertPrDiffListFilesInput(input) {
2899
+ if (typeof input.owner !== "string" || typeof input.name !== "string" || input.owner.trim().length === 0 || input.name.trim().length === 0) {
2900
+ throw new Error("Repository owner and name are required");
2901
+ }
2902
+ if (!Number.isInteger(input.prNumber) || input.prNumber <= 0) {
2903
+ throw new Error("PR number must be a positive integer");
2904
+ }
2905
+ if (!Number.isInteger(input.first) || input.first <= 0) {
2906
+ throw new Error("List page size must be a positive integer");
2907
+ }
2908
+ }
2909
+ function assertPrCommentsListInput(input) {
2910
+ if (typeof input.owner !== "string" || typeof input.name !== "string" || input.owner.trim().length === 0 || input.name.trim().length === 0) {
2911
+ throw new Error("Repository owner and name are required");
2912
+ }
2913
+ if (!Number.isInteger(input.prNumber) || input.prNumber <= 0) {
2914
+ throw new Error("PR number must be a positive integer");
2915
+ }
2916
+ if (!Number.isInteger(input.first) || input.first <= 0) {
2917
+ throw new Error("List page size must be a positive integer");
2918
+ }
2919
+ if (input.unresolvedOnly !== void 0 && typeof input.unresolvedOnly !== "boolean") {
2920
+ throw new Error("unresolvedOnly must be a boolean");
2921
+ }
2922
+ if (input.includeOutdated !== void 0 && typeof input.includeOutdated !== "boolean") {
2923
+ throw new Error("includeOutdated must be a boolean");
2924
+ }
2925
+ if (input.after !== void 0 && input.after !== null && typeof input.after !== "string") {
2926
+ throw new Error("After cursor must be a string");
2927
+ }
2928
+ }
2929
+ var PR_COMMENTS_LIST_QUERY = `
2930
+ query PrCommentsList($owner: String!, $name: String!, $prNumber: Int!, $first: Int!, $after: String) {
2931
+ repository(owner: $owner, name: $name) {
2932
+ pullRequest(number: $prNumber) {
2933
+ reviewThreads(first: $first, after: $after) {
2934
+ edges {
2935
+ cursor
2936
+ node {
2937
+ id
2938
+ path
2939
+ line
2940
+ startLine
2941
+ diffSide
2942
+ subjectType
2943
+ isResolved
2944
+ isOutdated
2945
+ viewerCanReply
2946
+ viewerCanResolve
2947
+ viewerCanUnresolve
2948
+ resolvedBy {
2949
+ login
2950
+ }
2951
+ comments(first: 20) {
2952
+ nodes {
2953
+ id
2954
+ body
2955
+ createdAt
2956
+ url
2957
+ author {
2958
+ login
2959
+ }
2960
+ }
2961
+ }
2962
+ }
2963
+ }
2964
+ pageInfo {
2965
+ endCursor
2966
+ hasNextPage
2967
+ }
2968
+ }
2969
+ }
2970
+ }
2971
+ }
2972
+ `;
2973
+ var PR_COMMENT_REPLY_MUTATION = `
2974
+ mutation PrCommentReply($threadId: ID!, $body: String!) {
2975
+ addPullRequestReviewThreadReply(input: { pullRequestReviewThreadId: $threadId, body: $body }) {
2976
+ comment {
2977
+ id
2978
+ }
2979
+ }
2980
+ }
2981
+ `;
2982
+ var PR_COMMENT_RESOLVE_MUTATION = `
2983
+ mutation PrCommentResolve($threadId: ID!) {
2984
+ resolveReviewThread(input: { threadId: $threadId }) {
2985
+ thread {
2986
+ id
2987
+ isResolved
2988
+ }
2989
+ }
2990
+ }
2991
+ `;
2992
+ var PR_COMMENT_UNRESOLVE_MUTATION = `
2993
+ mutation PrCommentUnresolve($threadId: ID!) {
2994
+ unresolveReviewThread(input: { threadId: $threadId }) {
2995
+ thread {
2996
+ id
2997
+ isResolved
2998
+ }
2999
+ }
3000
+ }
3001
+ `;
3002
+ var REVIEW_THREAD_STATE_QUERY = `
3003
+ query ReviewThreadState($threadId: ID!) {
3004
+ node(id: $threadId) {
3005
+ ... on PullRequestReviewThread {
3006
+ id
3007
+ isResolved
3008
+ }
3009
+ }
3010
+ }
3011
+ `;
3012
+ var ISSUE_CREATE_REPOSITORY_ID_QUERY = `
3013
+ query IssueCreateRepositoryId($owner: String!, $name: String!) {
3014
+ repository(owner: $owner, name: $name) {
3015
+ id
3016
+ }
3017
+ }
3018
+ `;
3019
+ var ISSUE_CREATE_MUTATION = `
3020
+ mutation IssueCreate($repositoryId: ID!, $title: String!, $body: String) {
3021
+ createIssue(input: { repositoryId: $repositoryId, title: $title, body: $body }) {
3022
+ issue {
3023
+ id
3024
+ number
3025
+ title
3026
+ state
3027
+ url
3028
+ }
3029
+ }
3030
+ }
3031
+ `;
3032
+ var ISSUE_UPDATE_MUTATION = `
3033
+ mutation IssueUpdate($issueId: ID!, $title: String, $body: String) {
3034
+ updateIssue(input: { id: $issueId, title: $title, body: $body }) {
3035
+ issue {
3036
+ id
3037
+ number
3038
+ title
3039
+ state
3040
+ url
3041
+ }
3042
+ }
3043
+ }
3044
+ `;
3045
+ var ISSUE_CLOSE_MUTATION = `
3046
+ mutation IssueClose($issueId: ID!) {
3047
+ closeIssue(input: { issueId: $issueId }) {
3048
+ issue {
3049
+ id
3050
+ number
3051
+ state
3052
+ }
3053
+ }
3054
+ }
3055
+ `;
3056
+ var ISSUE_REOPEN_MUTATION = `
3057
+ mutation IssueReopen($issueId: ID!) {
3058
+ reopenIssue(input: { issueId: $issueId }) {
3059
+ issue {
3060
+ id
3061
+ number
3062
+ state
3063
+ }
3064
+ }
3065
+ }
3066
+ `;
3067
+ var ISSUE_DELETE_MUTATION = `
3068
+ mutation IssueDelete($issueId: ID!) {
3069
+ deleteIssue(input: { issueId: $issueId }) {
3070
+ clientMutationId
3071
+ }
3072
+ }
3073
+ `;
3074
+ var ISSUE_LABELS_UPDATE_MUTATION = `
3075
+ mutation IssueLabelsUpdate($issueId: ID!, $labelIds: [ID!]!) {
3076
+ updateIssue(input: { id: $issueId, labelIds: $labelIds }) {
3077
+ issue {
3078
+ id
3079
+ labels(first: 50) {
3080
+ nodes {
3081
+ name
3082
+ }
3083
+ }
3084
+ }
3085
+ }
3086
+ }
3087
+ `;
3088
+ var ISSUE_ASSIGNEES_UPDATE_MUTATION = `
3089
+ mutation IssueAssigneesUpdate($issueId: ID!, $assigneeIds: [ID!]!) {
3090
+ updateIssue(input: { id: $issueId, assigneeIds: $assigneeIds }) {
3091
+ issue {
3092
+ id
3093
+ assignees(first: 50) {
3094
+ nodes {
3095
+ login
3096
+ }
3097
+ }
3098
+ }
3099
+ }
3100
+ }
3101
+ `;
3102
+ var ISSUE_MILESTONE_SET_MUTATION = `
3103
+ mutation IssueMilestoneSet($issueId: ID!, $milestoneId: ID) {
3104
+ updateIssue(input: { id: $issueId, milestoneId: $milestoneId }) {
3105
+ issue {
3106
+ id
3107
+ milestone {
3108
+ number
3109
+ }
3110
+ }
3111
+ }
3112
+ }
3113
+ `;
3114
+ var ISSUE_LABELS_LOOKUP_QUERY = `
3115
+ query IssueLabelsLookup($issueId: ID!) {
3116
+ node(id: $issueId) {
3117
+ ... on Issue {
3118
+ repository {
3119
+ labels(first: 100) {
3120
+ nodes {
3121
+ id
3122
+ name
3123
+ }
3124
+ }
3125
+ }
3126
+ }
3127
+ }
3128
+ }
3129
+ `;
3130
+ var ISSUE_ASSIGNEES_LOOKUP_QUERY = `
3131
+ query IssueAssigneesLookup($issueId: ID!) {
3132
+ node(id: $issueId) {
3133
+ ... on Issue {
3134
+ repository {
3135
+ assignableUsers(first: 100) {
3136
+ nodes {
3137
+ id
3138
+ login
3139
+ }
3140
+ }
3141
+ }
3142
+ }
3143
+ }
3144
+ }
3145
+ `;
3146
+ var ISSUE_MILESTONE_LOOKUP_QUERY = `
3147
+ query IssueMilestoneLookup($issueId: ID!, $milestoneNumber: Int!) {
3148
+ node(id: $issueId) {
3149
+ ... on Issue {
3150
+ repository {
3151
+ milestone(number: $milestoneNumber) {
3152
+ id
3153
+ }
3154
+ }
3155
+ }
3156
+ }
3157
+ }
3158
+ `;
3159
+ var ISSUE_COMMENT_CREATE_MUTATION = `
3160
+ mutation IssueCommentCreate($issueId: ID!, $body: String!) {
3161
+ addComment(input: { subjectId: $issueId, body: $body }) {
3162
+ commentEdge {
3163
+ node {
3164
+ id
3165
+ body
3166
+ url
3167
+ }
3168
+ }
3169
+ }
3170
+ }
3171
+ `;
3172
+ var ISSUE_LINKED_PRS_LIST_QUERY = `
3173
+ query IssueLinkedPrsList($owner: String!, $name: String!, $issueNumber: Int!) {
3174
+ repository(owner: $owner, name: $name) {
3175
+ issue(number: $issueNumber) {
3176
+ timelineItems(first: 50, itemTypes: [CONNECTED_EVENT]) {
3177
+ nodes {
3178
+ __typename
3179
+ ... on ConnectedEvent {
3180
+ subject {
3181
+ __typename
3182
+ ... on PullRequest {
3183
+ id
3184
+ number
3185
+ title
3186
+ state
3187
+ url
3188
+ }
3189
+ }
3190
+ }
3191
+ }
3192
+ }
3193
+ }
3194
+ }
3195
+ }
3196
+ `;
3197
+ var ISSUE_RELATIONS_GET_QUERY = `
3198
+ query IssueRelationsGet($owner: String!, $name: String!, $issueNumber: Int!) {
3199
+ repository(owner: $owner, name: $name) {
3200
+ issue(number: $issueNumber) {
3201
+ id
3202
+ number
3203
+ parent {
3204
+ id
3205
+ number
3206
+ }
3207
+ subIssues(first: 50) {
3208
+ nodes {
3209
+ id
3210
+ number
3211
+ }
3212
+ }
3213
+ blockedBy(first: 50) {
3214
+ nodes {
3215
+ id
3216
+ number
3217
+ }
3218
+ }
3219
+ }
3220
+ }
3221
+ }
3222
+ `;
3223
+ var ISSUE_PARENT_LOOKUP_QUERY = `
3224
+ query IssueParentLookup($issueId: ID!) {
3225
+ node(id: $issueId) {
3226
+ ... on Issue {
3227
+ id
3228
+ parent {
3229
+ id
3230
+ }
3231
+ }
3232
+ }
3233
+ }
3234
+ `;
3235
+ var ISSUE_PARENT_SET_MUTATION = `
3236
+ mutation IssueParentSet($issueId: ID!, $parentIssueId: ID!) {
3237
+ addSubIssue(input: { issueId: $parentIssueId, subIssueId: $issueId }) {
3238
+ issue { id }
3239
+ subIssue { id }
3240
+ }
3241
+ }
3242
+ `;
3243
+ var ISSUE_PARENT_REMOVE_MUTATION = `
3244
+ mutation IssueParentRemove($issueId: ID!, $parentIssueId: ID!) {
3245
+ removeSubIssue(input: { issueId: $parentIssueId, subIssueId: $issueId }) {
3246
+ issue { id }
3247
+ subIssue { id }
3248
+ }
3249
+ }
3250
+ `;
3251
+ var ISSUE_BLOCKED_BY_ADD_MUTATION = `
3252
+ mutation IssueBlockedByAdd($issueId: ID!, $blockedByIssueId: ID!) {
3253
+ addBlockedBy(input: { issueId: $issueId, blockingIssueId: $blockedByIssueId }) {
3254
+ issue { id }
3255
+ blockingIssue { id }
3256
+ }
3257
+ }
3258
+ `;
3259
+ var ISSUE_BLOCKED_BY_REMOVE_MUTATION = `
3260
+ mutation IssueBlockedByRemove($issueId: ID!, $blockedByIssueId: ID!) {
3261
+ removeBlockedBy(input: { issueId: $issueId, blockingIssueId: $blockedByIssueId }) {
3262
+ issue { id }
3263
+ blockingIssue { id }
3264
+ }
3265
+ }
3266
+ `;
3267
+ function createSdkClients(transport) {
3268
+ const client = {
3269
+ request(documentOrOptions, ...variablesAndRequestHeaders) {
3270
+ const options = typeof documentOrOptions === "object" && documentOrOptions !== null && "document" in documentOrOptions ? documentOrOptions : {
3271
+ document: documentOrOptions,
3272
+ variables: variablesAndRequestHeaders[0]
3273
+ };
3274
+ const queryText = queryToString(options.document);
3275
+ assertQuery(queryText);
3276
+ return transport.execute(queryText, options.variables);
3277
+ }
3278
+ };
3279
+ const graphqlRequestClient = client;
3280
+ return {
3281
+ issueCommentsList: getSdk(graphqlRequestClient),
3282
+ issueList: getSdk2(graphqlRequestClient),
3283
+ issue: getSdk3(graphqlRequestClient),
3284
+ prDiffListFiles: getSdk4(graphqlRequestClient),
3285
+ prList: getSdk5(graphqlRequestClient),
3286
+ prReviewsList: getSdk6(graphqlRequestClient),
3287
+ pr: getSdk7(graphqlRequestClient),
3288
+ repo: getSdk8(graphqlRequestClient)
3289
+ };
3290
+ }
3291
+ async function runRepoView(sdk, input) {
3292
+ assertRepoInput(input);
3293
+ const result = await sdk.RepoView(input);
3294
+ if (!result.repository) {
3295
+ throw new Error("Repository not found");
3296
+ }
3297
+ return {
3298
+ id: result.repository.id,
3299
+ name: result.repository.name,
3300
+ nameWithOwner: result.repository.nameWithOwner,
3301
+ isPrivate: result.repository.isPrivate,
3302
+ stargazerCount: result.repository.stargazerCount,
3303
+ forkCount: result.repository.forkCount,
3304
+ url: result.repository.url,
3305
+ defaultBranch: result.repository.defaultBranchRef?.name ?? null
3306
+ };
3307
+ }
3308
+ async function runIssueView(sdk, input) {
3309
+ assertIssueInput(input);
3310
+ const result = await sdk.IssueView(input);
3311
+ const issue = result.repository?.issue;
3312
+ if (!issue) {
3313
+ throw new Error("Issue not found");
3314
+ }
3315
+ return {
3316
+ id: issue.id,
3317
+ number: issue.number,
3318
+ title: issue.title,
3319
+ state: issue.state,
3320
+ url: issue.url
3321
+ };
3322
+ }
3323
+ async function runIssueList(sdk, input) {
3324
+ assertIssueListInput(input);
3325
+ const result = await sdk.IssueList(input);
3326
+ const issues = result.repository?.issues;
3327
+ if (!issues) {
3328
+ throw new Error("Issues not found");
3329
+ }
3330
+ return {
3331
+ items: (issues.nodes ?? []).flatMap(
3332
+ (issue) => issue ? [
3333
+ {
3334
+ id: issue.id,
3335
+ number: issue.number,
3336
+ title: issue.title,
3337
+ state: issue.state,
3338
+ url: issue.url
3339
+ }
3340
+ ] : []
3341
+ ),
3342
+ pageInfo: {
3343
+ endCursor: issues.pageInfo.endCursor ?? null,
3344
+ hasNextPage: issues.pageInfo.hasNextPage
3345
+ }
3346
+ };
3347
+ }
3348
+ async function runIssueCommentsList(sdk, input) {
3349
+ assertIssueCommentsListInput(input);
3350
+ const result = await sdk.IssueCommentsList(input);
3351
+ const comments = result.repository?.issue?.comments;
3352
+ if (!comments) {
3353
+ throw new Error("Issue comments not found");
3354
+ }
3355
+ return {
3356
+ items: (comments.nodes ?? []).flatMap(
3357
+ (comment) => comment ? [
3358
+ {
3359
+ id: comment.id,
3360
+ body: comment.body,
3361
+ authorLogin: comment.author?.login ?? null,
3362
+ createdAt: comment.createdAt,
3363
+ url: String(comment.url)
3364
+ }
3365
+ ] : []
3366
+ ),
3367
+ pageInfo: {
3368
+ endCursor: comments.pageInfo.endCursor ?? null,
3369
+ hasNextPage: comments.pageInfo.hasNextPage
3370
+ }
3371
+ };
3372
+ }
3373
+ function parseIssueNode(issue) {
3374
+ const issueRecord = asRecord(issue);
3375
+ if (!issueRecord || typeof issueRecord.id !== "string" || typeof issueRecord.number !== "number") {
3376
+ throw new Error("Issue mutation failed");
3377
+ }
3378
+ const result = {
3379
+ id: issueRecord.id,
3380
+ number: issueRecord.number
3381
+ };
3382
+ if (typeof issueRecord.title === "string") {
3383
+ result.title = issueRecord.title;
3384
+ }
3385
+ if (typeof issueRecord.state === "string") {
3386
+ result.state = issueRecord.state;
3387
+ }
3388
+ if (typeof issueRecord.url === "string") {
3389
+ result.url = issueRecord.url;
3390
+ }
3391
+ return result;
3392
+ }
3393
+ async function runIssueCreate(graphqlClient, input) {
3394
+ assertIssueCreateInput(input);
3395
+ const repositoryLookupResult = await graphqlClient.query(
3396
+ ISSUE_CREATE_REPOSITORY_ID_QUERY,
3397
+ {
3398
+ owner: input.owner,
3399
+ name: input.name
3400
+ }
3401
+ );
3402
+ const repositoryId = asRecord(asRecord(repositoryLookupResult)?.repository)?.id;
3403
+ if (typeof repositoryId !== "string" || repositoryId.length === 0) {
3404
+ throw new Error("Repository not found");
3405
+ }
3406
+ const result = await graphqlClient.query(ISSUE_CREATE_MUTATION, {
3407
+ repositoryId,
3408
+ title: input.title,
3409
+ body: input.body
3410
+ });
3411
+ const issue = asRecord(asRecord(result)?.createIssue)?.issue;
3412
+ return parseIssueNode(issue);
3413
+ }
3414
+ async function runIssueUpdate(graphqlClient, input) {
3415
+ assertIssueUpdateInput(input);
3416
+ const result = await graphqlClient.query(ISSUE_UPDATE_MUTATION, {
3417
+ issueId: input.issueId,
3418
+ title: input.title,
3419
+ body: input.body
3420
+ });
3421
+ const issue = asRecord(asRecord(result)?.updateIssue)?.issue;
3422
+ return parseIssueNode(issue);
3423
+ }
3424
+ async function runIssueClose(graphqlClient, input) {
3425
+ assertIssueMutationInput(input);
3426
+ const result = await graphqlClient.query(ISSUE_CLOSE_MUTATION, {
3427
+ issueId: input.issueId
3428
+ });
3429
+ const issueData = parseIssueNode(asRecord(asRecord(result)?.closeIssue)?.issue);
3430
+ return {
3431
+ ...issueData,
3432
+ closed: issueData.state === "CLOSED"
3433
+ };
3434
+ }
3435
+ async function runIssueReopen(graphqlClient, input) {
3436
+ assertIssueMutationInput(input);
3437
+ const result = await graphqlClient.query(ISSUE_REOPEN_MUTATION, {
3438
+ issueId: input.issueId
3439
+ });
3440
+ const issueData = parseIssueNode(asRecord(asRecord(result)?.reopenIssue)?.issue);
3441
+ return {
3442
+ ...issueData,
3443
+ reopened: issueData.state === "OPEN"
3444
+ };
3445
+ }
3446
+ async function runIssueDelete(graphqlClient, input) {
3447
+ assertIssueMutationInput(input);
3448
+ const result = await graphqlClient.query(ISSUE_DELETE_MUTATION, {
3449
+ issueId: input.issueId
3450
+ });
3451
+ const mutation = asRecord(asRecord(result)?.deleteIssue);
3452
+ if (!mutation) {
3453
+ throw new Error("Issue deletion failed");
3454
+ }
3455
+ return {
3456
+ id: input.issueId,
3457
+ number: 0,
3458
+ deleted: true
3459
+ };
3460
+ }
3461
+ async function runIssueLabelsUpdate(graphqlClient, input) {
3462
+ assertIssueLabelsUpdateInput(input);
3463
+ const lookupResult = await graphqlClient.query(
3464
+ ISSUE_LABELS_LOOKUP_QUERY,
3465
+ {
3466
+ issueId: input.issueId
3467
+ }
3468
+ );
3469
+ const availableLabels = Array.isArray(
3470
+ asRecord(asRecord(asRecord(asRecord(lookupResult)?.node)?.repository)?.labels)?.nodes
3471
+ ) ? asRecord(asRecord(asRecord(asRecord(lookupResult)?.node)?.repository)?.labels)?.nodes : [];
3472
+ const labelIdsByName = /* @__PURE__ */ new Map();
3473
+ for (const label of availableLabels) {
3474
+ const labelRecord = asRecord(label);
3475
+ if (typeof labelRecord?.name === "string" && typeof labelRecord?.id === "string") {
3476
+ labelIdsByName.set(labelRecord.name.toLowerCase(), labelRecord.id);
3477
+ }
3478
+ }
3479
+ const labelIds = input.labels.map((labelName) => {
3480
+ const id = labelIdsByName.get(labelName.toLowerCase());
3481
+ if (!id) {
3482
+ throw new Error(`Label not found: ${labelName}`);
3483
+ }
3484
+ return id;
3485
+ });
3486
+ const result = await graphqlClient.query(
3487
+ ISSUE_LABELS_UPDATE_MUTATION,
3488
+ {
3489
+ issueId: input.issueId,
3490
+ labelIds
3491
+ }
3492
+ );
3493
+ const mutation = asRecord(asRecord(result)?.["updateIssue"]);
3494
+ const issue = asRecord(mutation?.["issue"]);
3495
+ const labels = asRecord(issue?.["labels"]);
3496
+ const labelNodes = Array.isArray(labels?.["nodes"]) ? labels["nodes"] : [];
3497
+ return {
3498
+ id: assertNonEmptyString(issue?.["id"], "Issue id"),
3499
+ labels: labelNodes.map((label) => asRecord(label)?.["name"]).filter((name) => typeof name === "string")
3500
+ };
3501
+ }
3502
+ async function runIssueAssigneesUpdate(graphqlClient, input) {
3503
+ assertIssueAssigneesUpdateInput(input);
3504
+ const lookupResult = await graphqlClient.query(
3505
+ ISSUE_ASSIGNEES_LOOKUP_QUERY,
3506
+ {
3507
+ issueId: input.issueId
3508
+ }
3509
+ );
3510
+ const availableAssignees = Array.isArray(
3511
+ asRecord(asRecord(asRecord(asRecord(lookupResult)?.node)?.repository)?.assignableUsers)?.nodes
3512
+ ) ? asRecord(asRecord(asRecord(asRecord(lookupResult)?.node)?.repository)?.assignableUsers)?.nodes : [];
3513
+ const assigneeIdsByLogin = /* @__PURE__ */ new Map();
3514
+ for (const assignee of availableAssignees) {
3515
+ const assigneeRecord = asRecord(assignee);
3516
+ if (typeof assigneeRecord?.login === "string" && typeof assigneeRecord?.id === "string") {
3517
+ assigneeIdsByLogin.set(assigneeRecord.login.toLowerCase(), assigneeRecord.id);
3518
+ }
3519
+ }
3520
+ const assigneeIds = input.assignees.map((login) => {
3521
+ const id = assigneeIdsByLogin.get(login.toLowerCase());
3522
+ if (!id) {
3523
+ throw new Error(`Assignee not found: ${login}`);
3524
+ }
3525
+ return id;
3526
+ });
3527
+ const result = await graphqlClient.query(
3528
+ ISSUE_ASSIGNEES_UPDATE_MUTATION,
3529
+ {
3530
+ issueId: input.issueId,
3531
+ assigneeIds
3532
+ }
3533
+ );
3534
+ const mutation = asRecord(asRecord(result)?.["updateIssue"]);
3535
+ const issue = asRecord(mutation?.["issue"]);
3536
+ const assignees = asRecord(issue?.["assignees"]);
3537
+ const assigneeNodes = Array.isArray(assignees?.["nodes"]) ? assignees["nodes"] : [];
3538
+ return {
3539
+ id: assertNonEmptyString(issue?.["id"], "Issue id"),
3540
+ assignees: assigneeNodes.map((assignee) => asRecord(assignee)?.["login"]).filter((login) => typeof login === "string")
3541
+ };
3542
+ }
3543
+ async function runIssueMilestoneSet(graphqlClient, input) {
3544
+ assertIssueMilestoneSetInput(input);
3545
+ let milestoneId = null;
3546
+ if (input.milestoneNumber !== null) {
3547
+ const lookupResult = await graphqlClient.query(
3548
+ ISSUE_MILESTONE_LOOKUP_QUERY,
3549
+ {
3550
+ issueId: input.issueId,
3551
+ milestoneNumber: input.milestoneNumber
3552
+ }
3553
+ );
3554
+ const resolvedId = asRecord(
3555
+ asRecord(asRecord(asRecord(lookupResult)?.node)?.repository)?.milestone
3556
+ )?.id;
3557
+ if (typeof resolvedId !== "string" || resolvedId.length === 0) {
3558
+ throw new Error(`Milestone not found: ${input.milestoneNumber}`);
3559
+ }
3560
+ milestoneId = resolvedId;
3561
+ }
3562
+ const result = await graphqlClient.query(
3563
+ ISSUE_MILESTONE_SET_MUTATION,
3564
+ {
3565
+ issueId: input.issueId,
3566
+ milestoneId
3567
+ }
3568
+ );
3569
+ const mutation = asRecord(asRecord(result)?.["updateIssue"]);
3570
+ const issue = asRecord(mutation?.["issue"]);
3571
+ const milestone = asRecord(issue?.["milestone"]);
3572
+ return {
3573
+ id: assertNonEmptyString(issue?.["id"], "Issue id"),
3574
+ milestoneNumber: typeof milestone?.["number"] === "number" ? milestone["number"] : null
3575
+ };
3576
+ }
3577
+ async function runIssueCommentCreate(graphqlClient, input) {
3578
+ assertIssueCommentCreateInput(input);
3579
+ const result = await graphqlClient.query(
3580
+ ISSUE_COMMENT_CREATE_MUTATION,
3581
+ {
3582
+ issueId: input.issueId,
3583
+ body: input.body
3584
+ }
3585
+ );
3586
+ const mutation = asRecord(asRecord(result)?.["addComment"]);
3587
+ const commentEdge = asRecord(mutation?.["commentEdge"]);
3588
+ const node = asRecord(commentEdge?.["node"]);
3589
+ if (!node || typeof node["id"] !== "string" || typeof node["body"] !== "string") {
3590
+ throw new Error("Issue comment creation failed");
3591
+ }
3592
+ return {
3593
+ id: node["id"],
3594
+ body: node["body"],
3595
+ url: typeof node["url"] === "string" ? node["url"] : ""
3596
+ };
3597
+ }
3598
+ async function runIssueLinkedPrsList(graphqlClient, input) {
3599
+ assertIssueLinkedPrsListInput(input);
3600
+ const result = await graphqlClient.query(ISSUE_LINKED_PRS_LIST_QUERY, {
3601
+ owner: input.owner,
3602
+ name: input.name,
3603
+ issueNumber: input.issueNumber
3604
+ });
3605
+ const issue = asRecord(asRecord(asRecord(result)?.repository)?.issue);
3606
+ const timelineItems = asRecord(issue?.timelineItems);
3607
+ const nodes = Array.isArray(timelineItems?.nodes) ? timelineItems.nodes : [];
3608
+ return {
3609
+ items: nodes.map((node) => asRecord(asRecord(node)?.["subject"])).filter(
3610
+ (subject) => Boolean(subject) && subject?.["__typename"] === "PullRequest"
3611
+ ).flatMap((subject) => {
3612
+ if (!subject) {
3613
+ return [];
3614
+ }
3615
+ if (typeof subject["id"] !== "string" || typeof subject["number"] !== "number" || typeof subject["title"] !== "string" || typeof subject["state"] !== "string" || typeof subject["url"] !== "string") {
3616
+ return [];
3617
+ }
3618
+ return [
3619
+ {
3620
+ id: subject["id"],
3621
+ number: subject["number"],
3622
+ title: subject["title"],
3623
+ state: subject["state"],
3624
+ url: subject["url"]
3625
+ }
3626
+ ];
3627
+ })
3628
+ };
3629
+ }
3630
+ function parseIssueRelationNode(node) {
3631
+ const record = asRecord(node);
3632
+ if (!record || typeof record.id !== "string" || typeof record.number !== "number") {
3633
+ return null;
3634
+ }
3635
+ return {
3636
+ id: record.id,
3637
+ number: record.number
3638
+ };
3639
+ }
3640
+ async function runIssueRelationsGet(graphqlClient, input) {
3641
+ assertIssueRelationsGetInput(input);
3642
+ const result = await graphqlClient.query(ISSUE_RELATIONS_GET_QUERY, {
3643
+ owner: input.owner,
3644
+ name: input.name,
3645
+ issueNumber: input.issueNumber
3646
+ });
3647
+ const issue = asRecord(asRecord(asRecord(result)?.repository)?.issue);
3648
+ const currentIssue = parseIssueRelationNode(issue);
3649
+ if (!currentIssue) {
3650
+ throw new Error("Issue relations not found");
3651
+ }
3652
+ const parent = parseIssueRelationNode(issue?.parent);
3653
+ const subIssues = asRecord(issue?.["subIssues"]);
3654
+ const blockedByConnection = asRecord(issue?.["blockedBy"]);
3655
+ const childrenNodes = Array.isArray(subIssues?.["nodes"]) ? subIssues["nodes"] : [];
3656
+ const blockedByNodes = Array.isArray(blockedByConnection?.["nodes"]) ? blockedByConnection["nodes"] : [];
3657
+ return {
3658
+ issue: currentIssue,
3659
+ parent,
3660
+ children: childrenNodes.map((node) => parseIssueRelationNode(node)).flatMap((node) => node ? [node] : []),
3661
+ blockedBy: blockedByNodes.map((node) => parseIssueRelationNode(node)).flatMap((node) => node ? [node] : [])
3662
+ };
3663
+ }
3664
+ async function runIssueParentSet(graphqlClient, input) {
3665
+ assertIssueParentSetInput(input);
3666
+ const result = await graphqlClient.query(ISSUE_PARENT_SET_MUTATION, {
3667
+ issueId: input.issueId,
3668
+ parentIssueId: input.parentIssueId
3669
+ });
3670
+ const mutation = asRecord(asRecord(result)?.addSubIssue);
3671
+ const parentIssue = asRecord(mutation?.issue);
3672
+ const subIssue = asRecord(mutation?.subIssue);
3673
+ if (typeof parentIssue?.id !== "string" || typeof subIssue?.id !== "string") {
3674
+ throw new Error("Issue parent update failed");
3675
+ }
3676
+ return {
3677
+ issueId: subIssue.id,
3678
+ parentIssueId: parentIssue.id
3679
+ };
3680
+ }
3681
+ async function runIssueParentRemove(graphqlClient, input) {
3682
+ assertIssueParentRemoveInput(input);
3683
+ const lookupResult = await graphqlClient.query(
3684
+ ISSUE_PARENT_LOOKUP_QUERY,
3685
+ {
3686
+ issueId: input.issueId
3687
+ }
3688
+ );
3689
+ const parentIssueId = asRecord(asRecord(asRecord(lookupResult)?.node)?.parent)?.id;
3690
+ if (typeof parentIssueId !== "string" || parentIssueId.length === 0) {
3691
+ throw new Error("Issue parent removal failed");
3692
+ }
3693
+ const result = await graphqlClient.query(
3694
+ ISSUE_PARENT_REMOVE_MUTATION,
3695
+ {
3696
+ issueId: input.issueId,
3697
+ parentIssueId
3698
+ }
3699
+ );
3700
+ const mutation = asRecord(asRecord(result)?.removeSubIssue);
3701
+ const parentIssue = asRecord(mutation?.issue);
3702
+ const subIssue = asRecord(mutation?.subIssue);
3703
+ if (typeof parentIssue?.id !== "string" || typeof subIssue?.id !== "string") {
3704
+ throw new Error("Issue parent removal failed");
3705
+ }
3706
+ return {
3707
+ issueId: subIssue.id,
3708
+ parentRemoved: true
3709
+ };
3710
+ }
3711
+ async function runIssueBlockedByAdd(graphqlClient, input) {
3712
+ assertIssueBlockedByInput(input);
3713
+ const result = await graphqlClient.query(
3714
+ ISSUE_BLOCKED_BY_ADD_MUTATION,
3715
+ {
3716
+ issueId: input.issueId,
3717
+ blockedByIssueId: input.blockedByIssueId
3718
+ }
3719
+ );
3720
+ const mutation = asRecord(asRecord(result)?.addBlockedBy);
3721
+ const issue = asRecord(mutation?.issue);
3722
+ const blockingIssue = asRecord(mutation?.blockingIssue);
3723
+ if (typeof issue?.id !== "string" || typeof blockingIssue?.id !== "string") {
3724
+ throw new Error("Issue dependency mutation failed");
3725
+ }
3726
+ return {
3727
+ issueId: issue.id,
3728
+ blockedByIssueId: blockingIssue.id
3729
+ };
3730
+ }
3731
+ async function runIssueBlockedByRemove(graphqlClient, input) {
3732
+ assertIssueBlockedByInput(input);
3733
+ const result = await graphqlClient.query(
3734
+ ISSUE_BLOCKED_BY_REMOVE_MUTATION,
3735
+ {
3736
+ issueId: input.issueId,
3737
+ blockedByIssueId: input.blockedByIssueId
3738
+ }
3739
+ );
3740
+ const mutation = asRecord(asRecord(result)?.removeBlockedBy);
3741
+ const issue = asRecord(mutation?.issue);
3742
+ const blockingIssue = asRecord(mutation?.blockingIssue);
3743
+ if (typeof issue?.id !== "string" || typeof blockingIssue?.id !== "string") {
3744
+ throw new Error("Issue dependency mutation failed");
3745
+ }
3746
+ return {
3747
+ issueId: issue.id,
3748
+ blockedByIssueId: blockingIssue.id,
3749
+ removed: true
3750
+ };
3751
+ }
3752
+ async function runPrView(sdk, input) {
3753
+ assertPrInput(input);
3754
+ const result = await sdk.PrView(input);
3755
+ const pr = result.repository?.pullRequest;
3756
+ if (!pr) {
3757
+ throw new Error("Pull request not found");
3758
+ }
3759
+ return {
3760
+ id: pr.id,
3761
+ number: pr.number,
3762
+ title: pr.title,
3763
+ state: pr.state,
3764
+ url: pr.url
3765
+ };
3766
+ }
3767
+ async function runPrList(sdk, input) {
3768
+ assertPrListInput(input);
3769
+ const result = await sdk.PrList(input);
3770
+ const prs = result.repository?.pullRequests;
3771
+ if (!prs) {
3772
+ throw new Error("Pull requests not found");
3773
+ }
3774
+ return {
3775
+ items: (prs.nodes ?? []).flatMap(
3776
+ (pr) => pr ? [
3777
+ {
3778
+ id: pr.id,
3779
+ number: pr.number,
3780
+ title: pr.title,
3781
+ state: pr.state,
3782
+ url: pr.url
3783
+ }
3784
+ ] : []
3785
+ ),
3786
+ pageInfo: {
3787
+ endCursor: prs.pageInfo.endCursor ?? null,
3788
+ hasNextPage: prs.pageInfo.hasNextPage
3789
+ }
3790
+ };
3791
+ }
3792
+ async function runPrReviewsList(sdk, input) {
3793
+ assertPrReviewsListInput(input);
3794
+ const result = await sdk.PrReviewsList(input);
3795
+ const reviews = result.repository?.pullRequest?.reviews;
3796
+ if (!reviews) {
3797
+ throw new Error("Pull request reviews not found");
3798
+ }
3799
+ return {
3800
+ items: (reviews.nodes ?? []).flatMap(
3801
+ (review) => review ? [
3802
+ {
3803
+ id: review.id,
3804
+ authorLogin: review.author?.login ?? null,
3805
+ body: review.body,
3806
+ state: review.state,
3807
+ submittedAt: review.submittedAt ?? null,
3808
+ url: review.url,
3809
+ commitOid: review.commit?.oid ?? null
3810
+ }
3811
+ ] : []
3812
+ ),
3813
+ pageInfo: {
3814
+ endCursor: reviews.pageInfo.endCursor ?? null,
3815
+ hasNextPage: reviews.pageInfo.hasNextPage
3816
+ }
3817
+ };
3818
+ }
3819
+ async function runPrDiffListFiles(sdk, input) {
3820
+ assertPrDiffListFilesInput(input);
3821
+ const result = await sdk.PrDiffListFiles(input);
3822
+ const files = result.repository?.pullRequest?.files;
3823
+ if (!files) {
3824
+ throw new Error("Pull request files not found");
3825
+ }
3826
+ return {
3827
+ items: (files.nodes ?? []).flatMap(
3828
+ (file) => file ? [
3829
+ {
3830
+ path: file.path,
3831
+ additions: file.additions,
3832
+ deletions: file.deletions
3833
+ }
3834
+ ] : []
3835
+ ),
3836
+ pageInfo: {
3837
+ endCursor: files.pageInfo.endCursor ?? null,
3838
+ hasNextPage: files.pageInfo.hasNextPage
3839
+ }
3840
+ };
3841
+ }
3842
+ var MAX_PR_REVIEW_THREAD_SCAN_PAGES = 5;
3843
+ function asRecord(value) {
3844
+ return typeof value === "object" && value !== null && !Array.isArray(value) ? value : null;
3845
+ }
3846
+ function normalizePrReviewThreadComment(comment) {
3847
+ const commentRecord = asRecord(comment);
3848
+ if (!commentRecord || typeof commentRecord.id !== "string") {
3849
+ return null;
3850
+ }
3851
+ const author = asRecord(commentRecord.author);
3852
+ const url = commentRecord.url;
3853
+ return {
3854
+ id: commentRecord.id,
3855
+ authorLogin: typeof author?.login === "string" ? author.login : null,
3856
+ body: typeof commentRecord.body === "string" ? commentRecord.body : "",
3857
+ createdAt: typeof commentRecord.createdAt === "string" ? commentRecord.createdAt : "",
3858
+ url: typeof url === "string" ? url : String(url ?? "")
3859
+ };
3860
+ }
3861
+ function normalizePrReviewThread(thread) {
3862
+ const threadRecord = asRecord(thread);
3863
+ if (!threadRecord || typeof threadRecord.id !== "string") {
3864
+ return null;
3865
+ }
3866
+ const comments = asRecord(threadRecord.comments);
3867
+ const commentNodes = Array.isArray(comments?.nodes) ? comments.nodes : [];
3868
+ const resolvedBy = asRecord(threadRecord.resolvedBy);
3869
+ return {
3870
+ id: threadRecord.id,
3871
+ path: typeof threadRecord.path === "string" ? threadRecord.path : null,
3872
+ line: typeof threadRecord.line === "number" ? threadRecord.line : null,
3873
+ startLine: typeof threadRecord.startLine === "number" ? threadRecord.startLine : null,
3874
+ diffSide: typeof threadRecord.diffSide === "string" ? threadRecord.diffSide : null,
3875
+ subjectType: typeof threadRecord.subjectType === "string" ? threadRecord.subjectType : null,
3876
+ isResolved: Boolean(threadRecord.isResolved),
3877
+ isOutdated: Boolean(threadRecord.isOutdated),
3878
+ viewerCanReply: Boolean(threadRecord.viewerCanReply),
3879
+ viewerCanResolve: Boolean(threadRecord.viewerCanResolve),
3880
+ viewerCanUnresolve: Boolean(threadRecord.viewerCanUnresolve),
3881
+ resolvedByLogin: typeof resolvedBy?.login === "string" ? resolvedBy.login : null,
3882
+ comments: commentNodes.map((comment) => normalizePrReviewThreadComment(comment)).flatMap((comment) => comment ? [comment] : [])
3883
+ };
3884
+ }
3885
+ async function runPrCommentsList(graphqlClient, input) {
3886
+ assertPrCommentsListInput(input);
3887
+ const unresolvedOnly = input.unresolvedOnly ?? false;
3888
+ const includeOutdated = input.includeOutdated ?? true;
3889
+ const filteredThreads = [];
3890
+ let sourceEndCursor = input.after ?? null;
3891
+ let sourceHasNextPage = false;
3892
+ let pagesScanned = 0;
3893
+ let sourceItemsScanned = 0;
3894
+ while (pagesScanned < MAX_PR_REVIEW_THREAD_SCAN_PAGES && filteredThreads.length < input.first) {
3895
+ const result = await graphqlClient.query(PR_COMMENTS_LIST_QUERY, {
3896
+ owner: input.owner,
3897
+ name: input.name,
3898
+ prNumber: input.prNumber,
3899
+ first: input.first,
3900
+ after: sourceEndCursor
3901
+ });
3902
+ const repository = asRecord(asRecord(result)?.repository);
3903
+ const pullRequest = asRecord(repository?.pullRequest);
3904
+ const reviewThreads = asRecord(pullRequest?.reviewThreads);
3905
+ if (!reviewThreads) {
3906
+ throw new Error("Pull request review threads not found");
3907
+ }
3908
+ const pageInfo = asRecord(reviewThreads.pageInfo);
3909
+ const threadEdges = Array.isArray(reviewThreads.edges) ? reviewThreads.edges.map((edge) => {
3910
+ const edgeRecord = asRecord(edge);
3911
+ if (!edgeRecord) {
3912
+ return null;
3913
+ }
3914
+ return {
3915
+ cursor: typeof edgeRecord.cursor === "string" ? edgeRecord.cursor : null,
3916
+ node: edgeRecord.node
3917
+ };
3918
+ }).flatMap((edge) => edge ? [edge] : []) : [];
3919
+ const threadNodes = threadEdges.length > 0 ? threadEdges : Array.isArray(reviewThreads.nodes) ? reviewThreads.nodes.map((node) => ({ cursor: null, node })) : [];
3920
+ pagesScanned += 1;
3921
+ sourceItemsScanned += threadNodes.length;
3922
+ for (const threadNode of threadNodes) {
3923
+ const normalized = normalizePrReviewThread(threadNode.node);
3924
+ if (!normalized) {
3925
+ continue;
3926
+ }
3927
+ if (unresolvedOnly && normalized.isResolved) {
3928
+ continue;
3929
+ }
3930
+ if (unresolvedOnly && !includeOutdated && normalized.isOutdated) {
3931
+ continue;
3932
+ }
3933
+ filteredThreads.push({ thread: normalized, cursor: threadNode.cursor });
3934
+ }
3935
+ sourceHasNextPage = Boolean(pageInfo?.hasNextPage);
3936
+ sourceEndCursor = typeof pageInfo?.endCursor === "string" ? pageInfo.endCursor : null;
3937
+ if (!sourceHasNextPage) {
3938
+ break;
3939
+ }
3940
+ }
3941
+ const hasBufferedFilteredItems = filteredThreads.length > input.first;
3942
+ const returnedThreads = filteredThreads.slice(0, input.first);
3943
+ const endCursor = returnedThreads.length > 0 ? returnedThreads[returnedThreads.length - 1]?.cursor ?? sourceEndCursor : sourceEndCursor;
3944
+ const scanTruncated = sourceHasNextPage && pagesScanned >= MAX_PR_REVIEW_THREAD_SCAN_PAGES;
3945
+ return {
3946
+ items: returnedThreads.map((entry) => entry.thread),
3947
+ pageInfo: {
3948
+ hasNextPage: hasBufferedFilteredItems || sourceHasNextPage,
3949
+ endCursor: hasBufferedFilteredItems || sourceHasNextPage ? endCursor : null
3950
+ },
3951
+ filterApplied: {
3952
+ unresolvedOnly,
3953
+ includeOutdated
3954
+ },
3955
+ scan: {
3956
+ pagesScanned,
3957
+ sourceItemsScanned,
3958
+ scanTruncated
3959
+ }
3960
+ };
3961
+ }
3962
+ function assertReviewThreadInput(input) {
3963
+ if (typeof input.threadId !== "string" || input.threadId.trim().length === 0) {
3964
+ throw new Error("Review thread id is required");
3965
+ }
3966
+ }
3967
+ function assertReplyToReviewThreadInput(input) {
3968
+ assertReviewThreadInput(input);
3969
+ if (typeof input.body !== "string" || input.body.trim().length === 0) {
3970
+ throw new Error("Reply body is required");
3971
+ }
3972
+ }
3973
+ function parseReviewThreadMutationResult(result, mutationKey) {
3974
+ const root = asRecord(result);
3975
+ const mutation = asRecord(root?.[mutationKey]);
3976
+ const thread = asRecord(mutation?.thread);
3977
+ if (!thread || typeof thread.id !== "string") {
3978
+ throw new Error("Review thread mutation failed");
3979
+ }
3980
+ return {
3981
+ id: thread.id,
3982
+ isResolved: Boolean(thread.isResolved)
3983
+ };
3984
+ }
3985
+ async function runReplyToReviewThread(graphqlClient, input) {
3986
+ assertReplyToReviewThreadInput(input);
3987
+ const result = await graphqlClient.query(PR_COMMENT_REPLY_MUTATION, {
3988
+ threadId: input.threadId,
3989
+ body: input.body
3990
+ });
3991
+ const root = asRecord(result);
3992
+ const mutation = asRecord(root?.addPullRequestReviewThreadReply);
3993
+ const comment = asRecord(mutation?.comment);
3994
+ if (!comment || typeof comment.id !== "string") {
3995
+ throw new Error("Review thread mutation failed");
3996
+ }
3997
+ const threadStateResult = await graphqlClient.query(
3998
+ REVIEW_THREAD_STATE_QUERY,
3999
+ {
4000
+ threadId: input.threadId
4001
+ }
4002
+ );
4003
+ const threadNode = asRecord(asRecord(threadStateResult)?.node);
4004
+ if (!threadNode || typeof threadNode.id !== "string") {
4005
+ throw new Error("Review thread state lookup failed");
4006
+ }
4007
+ return {
4008
+ id: input.threadId,
4009
+ isResolved: Boolean(threadNode.isResolved)
4010
+ };
4011
+ }
4012
+ async function runResolveReviewThread(graphqlClient, input) {
4013
+ assertReviewThreadInput(input);
4014
+ const result = await graphqlClient.query(PR_COMMENT_RESOLVE_MUTATION, {
4015
+ threadId: input.threadId
4016
+ });
4017
+ return parseReviewThreadMutationResult(result, "resolveReviewThread");
4018
+ }
4019
+ async function runUnresolveReviewThread(graphqlClient, input) {
4020
+ assertReviewThreadInput(input);
4021
+ const result = await graphqlClient.query(
4022
+ PR_COMMENT_UNRESOLVE_MUTATION,
4023
+ {
4024
+ threadId: input.threadId
4025
+ }
4026
+ );
4027
+ return parseReviewThreadMutationResult(result, "unresolveReviewThread");
4028
+ }
4029
+ function queryToString(query) {
4030
+ if (typeof query === "string") {
4031
+ return query;
4032
+ }
4033
+ if (typeof query === "object" && query !== null && "kind" in query) {
4034
+ return print(query);
4035
+ }
4036
+ return String(query);
4037
+ }
4038
+ function assertQuery(query) {
4039
+ if (query.trim().length === 0) {
4040
+ throw new Error("GraphQL query must be non-empty");
4041
+ }
4042
+ }
4043
+ function createGraphqlClient(transport) {
4044
+ return {
4045
+ async query(query, variables) {
4046
+ const queryText = queryToString(query);
4047
+ assertQuery(queryText);
4048
+ return transport.execute(queryText, variables);
4049
+ }
4050
+ };
4051
+ }
4052
+ var DEFAULT_GRAPHQL_URL = "https://api.github.com/graphql";
4053
+ function resolveGraphqlUrl() {
4054
+ if (process.env.GITHUB_GRAPHQL_URL) {
4055
+ return process.env.GITHUB_GRAPHQL_URL;
4056
+ }
4057
+ if (process.env.GH_HOST) {
4058
+ return `https://${process.env.GH_HOST}/api/graphql`;
4059
+ }
4060
+ return DEFAULT_GRAPHQL_URL;
4061
+ }
4062
+ function createTokenTransport(token, graphqlUrl) {
4063
+ const url = graphqlUrl ?? resolveGraphqlUrl();
4064
+ return {
4065
+ async execute(query, variables) {
4066
+ const response = await fetch(url, {
4067
+ method: "POST",
4068
+ headers: {
4069
+ "content-type": "application/json",
4070
+ authorization: `Bearer ${token}`
4071
+ },
4072
+ body: JSON.stringify({ query, variables: variables ?? {} })
4073
+ });
4074
+ const payload = await response.json();
4075
+ if (!response.ok) {
4076
+ throw new Error(payload.message ?? `GraphQL request failed (${response.status})`);
4077
+ }
4078
+ if (payload.errors?.length) {
4079
+ throw new Error(payload.errors[0]?.message ?? "GraphQL returned errors");
4080
+ }
4081
+ if (payload.data === void 0) {
4082
+ throw new Error("GraphQL response missing data");
4083
+ }
4084
+ return payload.data;
4085
+ }
4086
+ };
4087
+ }
4088
+ function createGithubClientFromToken(tokenOrOptions) {
4089
+ const token = typeof tokenOrOptions === "string" ? tokenOrOptions : tokenOrOptions.token;
4090
+ const graphqlUrl = typeof tokenOrOptions === "string" ? void 0 : tokenOrOptions.graphqlUrl;
4091
+ if (!token || token.trim().length === 0) {
4092
+ throw new Error("GitHub token is required");
4093
+ }
4094
+ return createGithubClient(createTokenTransport(token, graphqlUrl));
4095
+ }
4096
+ function createGithubClient(transport) {
4097
+ const graphqlClient = createGraphqlClient(transport);
4098
+ const sdk = createSdkClients(transport);
4099
+ return {
4100
+ query: (query, variables) => graphqlClient.query(query, variables),
4101
+ fetchRepoView: (input) => runRepoView(sdk.repo, input),
4102
+ fetchIssueCommentsList: (input) => runIssueCommentsList(sdk.issueCommentsList, input),
4103
+ createIssue: (input) => runIssueCreate(graphqlClient, input),
4104
+ updateIssue: (input) => runIssueUpdate(graphqlClient, input),
4105
+ closeIssue: (input) => runIssueClose(graphqlClient, input),
4106
+ reopenIssue: (input) => runIssueReopen(graphqlClient, input),
4107
+ deleteIssue: (input) => runIssueDelete(graphqlClient, input),
4108
+ updateIssueLabels: (input) => runIssueLabelsUpdate(graphqlClient, input),
4109
+ updateIssueAssignees: (input) => runIssueAssigneesUpdate(graphqlClient, input),
4110
+ setIssueMilestone: (input) => runIssueMilestoneSet(graphqlClient, input),
4111
+ createIssueComment: (input) => runIssueCommentCreate(graphqlClient, input),
4112
+ fetchIssueLinkedPrs: (input) => runIssueLinkedPrsList(graphqlClient, input),
4113
+ fetchIssueRelations: (input) => runIssueRelationsGet(graphqlClient, input),
4114
+ setIssueParent: (input) => runIssueParentSet(graphqlClient, input),
4115
+ removeIssueParent: (input) => runIssueParentRemove(graphqlClient, input),
4116
+ addIssueBlockedBy: (input) => runIssueBlockedByAdd(graphqlClient, input),
4117
+ removeIssueBlockedBy: (input) => runIssueBlockedByRemove(graphqlClient, input),
4118
+ fetchIssueList: (input) => runIssueList(sdk.issueList, input),
4119
+ fetchIssueView: (input) => runIssueView(sdk.issue, input),
4120
+ fetchPrList: (input) => runPrList(sdk.prList, input),
4121
+ fetchPrView: (input) => runPrView(sdk.pr, input),
4122
+ fetchPrCommentsList: (input) => runPrCommentsList(graphqlClient, input),
4123
+ fetchPrReviewsList: (input) => runPrReviewsList(sdk.prReviewsList, input),
4124
+ fetchPrDiffListFiles: (input) => runPrDiffListFiles(sdk.prDiffListFiles, input),
4125
+ replyToReviewThread: (input) => runReplyToReviewThread(graphqlClient, input),
4126
+ resolveReviewThread: (input) => runResolveReviewThread(graphqlClient, input),
4127
+ unresolveReviewThread: (input) => runUnresolveReviewThread(graphqlClient, input)
4128
+ };
4129
+ }
4130
+
4131
+ export {
4132
+ createSafeCliCommandRunner,
4133
+ errorCodes,
4134
+ executeTask,
4135
+ createGraphqlClient,
4136
+ createGithubClientFromToken,
4137
+ createGithubClient
4138
+ };
4139
+ //# sourceMappingURL=chunk-RDUPMVHG.js.map