@joshuafolkken/kit 1.1471.0 → 1.1784.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (895) hide show
  1. package/.claude/agents/investigator.md +1 -1
  2. package/.claude/settings.json +6 -6
  3. package/.claude/skills/epic-commands/SKILL.md +26 -77
  4. package/.claude/skills/epic-commands/epic-bundle.md +12 -6
  5. package/.claude/skills/epic-commands/execution-waves.md +1 -2
  6. package/.claude/skills/verify-ui/SKILL.md +1 -2
  7. package/.claude/skills/workflow-commands/SKILL.md +12 -14
  8. package/.claude/skills/workflow-commands/background-commands.md +8 -12
  9. package/.claude/skills/workflow-commands/backlogrun-child.md +13 -18
  10. package/.claude/skills/workflow-commands/backlogrun-handoff-report.md +7 -25
  11. package/.claude/skills/workflow-commands/backlogrun-lanes.md +23 -28
  12. package/.claude/skills/workflow-commands/backlogrun-park.md +16 -31
  13. package/.claude/skills/workflow-commands/backlogrun-progress.md +12 -21
  14. package/.claude/skills/workflow-commands/backlogrun-recovery.md +12 -12
  15. package/.claude/skills/workflow-commands/backlogrun-steps.md +12 -20
  16. package/.claude/skills/workflow-commands/backlogrun.md +32 -51
  17. package/.claude/skills/workflow-commands/chain-rule.md +18 -11
  18. package/.claude/skills/workflow-commands/delegation.md +13 -8
  19. package/.claude/skills/workflow-commands/entry-sequence.md +10 -12
  20. package/.claude/skills/workflow-commands/followup.md +10 -35
  21. package/.claude/skills/workflow-commands/fullrun-steps.md +38 -49
  22. package/.claude/skills/workflow-commands/fullrun.md +6 -8
  23. package/.claude/skills/workflow-commands/halfrun.md +20 -32
  24. package/.claude/skills/workflow-commands/into-target.md +1 -2
  25. package/.claude/skills/workflow-commands/issue-comments.md +19 -15
  26. package/.claude/skills/workflow-commands/issue-scout.md +5 -4
  27. package/.claude/skills/workflow-commands/kickoff.md +24 -23
  28. package/.claude/skills/workflow-commands/latest-gate.md +9 -18
  29. package/.claude/skills/workflow-commands/needs-human-review.md +11 -19
  30. package/.claude/skills/workflow-commands/observation-filing.md +4 -50
  31. package/.claude/skills/workflow-commands/observation-ledger.md +5 -10
  32. package/.claude/skills/workflow-commands/pre-gate-cut.md +22 -44
  33. package/.claude/skills/workflow-commands/prerequisite.md +11 -18
  34. package/.claude/skills/workflow-commands/progress-watcher.md +3 -8
  35. package/.claude/skills/workflow-commands/prrun.md +6 -12
  36. package/.claude/skills/workflow-commands/retrospective.md +5 -5
  37. package/.claude/skills/workflow-commands/split-assessment.md +14 -4
  38. package/.claude/skills/workflow-commands/target-repository.md +1 -2
  39. package/.claude/skills/workflow-commands/working-tree-hold.md +11 -13
  40. package/.codex/hooks.json +6 -6
  41. package/.github/actions/setup-node/action.yml +10 -1
  42. package/.github/actions/setup-pnpm/action.yml +1 -1
  43. package/.github/dependabot.yml +16 -0
  44. package/.github/release.yml +0 -2
  45. package/.github/workflows/ci.yml +121 -11
  46. package/.github/workflows/publish.yml +10 -3
  47. package/.github/workflows/sonar-qube.yml +1 -0
  48. package/.prettierignore +2 -0
  49. package/.vscode/tasks.json +1 -2
  50. package/CLAUDE.md +4 -8
  51. package/README.md +4 -2
  52. package/SECURITY.md +1 -1
  53. package/cspell/index.yaml +7 -0
  54. package/dist/CLAUDE.md +4 -8
  55. package/dist/commands/document-read-cli.js +882 -0
  56. package/dist/commands/{document-section-cli.js → document-section-main.js} +137 -62
  57. package/dist/commands/read-set-cli.js +1867 -0
  58. package/dist/commands/run-prep-main.js +21653 -0
  59. package/dist/commands/run-step-cli.js +23880 -0
  60. package/dist/config-merge/index.js +5 -1
  61. package/dist/hooks/audit-provision.js +20 -35
  62. package/dist/hooks/{chunk-DGT54IH5.js → chunk-AZX4FGQ3.js} +63 -17
  63. package/dist/hooks/chunk-CWMBGKYW.js +6483 -0
  64. package/dist/hooks/chunk-O2YBIDSI.js +4306 -0
  65. package/dist/hooks/{chunk-AS74OU3D.js → chunk-PT5R6UJD.js} +4582 -2118
  66. package/dist/hooks/chunk-TUIFS5E7.js +72 -0
  67. package/dist/hooks/{chunk-723HKZO5.js → chunk-VWWCFGWK.js} +1 -1
  68. package/dist/hooks/{chunk-E7OIKX5Z.js → chunk-WR2KQAYZ.js} +1863 -382
  69. package/dist/hooks/{chunk-KC5AK2GF.js → chunk-XGBNSWEI.js} +248 -46
  70. package/dist/hooks/chunk-YCDOIR3I.js +3456 -0
  71. package/dist/hooks/codex-hook-adapter.js +10 -19
  72. package/dist/hooks/format-edited.js +5 -5
  73. package/dist/hooks/inputs.json +436 -257
  74. package/dist/hooks/pretool-guard.js +7 -22
  75. package/dist/hooks/session-lang.js +380 -42
  76. package/dist/hooks/stop-guard.js +8711 -782
  77. package/dist/josh.js +5263 -997
  78. package/dist/self-sync-guard/index.js +74 -10
  79. package/dist/version/index.js +115 -406
  80. package/eslint/base.js +1 -1
  81. package/lefthook/base.yml +8 -4
  82. package/package.json +17 -53
  83. package/pnpm-workspace.yaml +4 -2
  84. package/prompts/coding-standards.md +1 -1
  85. package/prompts/collaboration-workflow/file-edits.md +1 -9
  86. package/prompts/collaboration-workflow/gh-rest.md +1 -2
  87. package/prompts/collaboration-workflow/issue-citation.md +2 -4
  88. package/prompts/collaboration-workflow/issue-template.md +42 -17
  89. package/prompts/collaboration-workflow/lane-instructions.md +34 -0
  90. package/prompts/collaboration-workflow/measurement.md +37 -0
  91. package/prompts/collaboration-workflow/operating-rules.md +6 -12
  92. package/prompts/collaboration-workflow/output-bounds.md +4 -9
  93. package/prompts/collaboration-workflow/overview.md +1 -1
  94. package/prompts/collaboration-workflow/plan-comment.md +3 -42
  95. package/prompts/collaboration-workflow/principles.md +19 -8
  96. package/prompts/collaboration-workflow/report-format.md +37 -57
  97. package/prompts/collaboration-workflow/residency.md +12 -8
  98. package/prompts/collaboration-workflow/rule-delivery.md +3 -11
  99. package/prompts/collaboration-workflow/shell-body.md +8 -18
  100. package/prompts/collaboration-workflow/turn-batching.md +4 -6
  101. package/prompts/collaboration-workflow/upstream-interrupt.md +16 -6
  102. package/prompts/collaboration-workflow/wip-cap.md +7 -7
  103. package/prompts/collaboration-workflow.md +4 -7
  104. package/prompts/refactoring.md +1 -1
  105. package/prompts/review-rubric.md +1 -2
  106. package/prompts/review.md +45 -26
  107. package/prompts/testing-guide.md +10 -45
  108. package/scripts/agent/agent-argv.ts +20 -4
  109. package/scripts/agent/agent-event.ts +15 -15
  110. package/scripts/agent/agent-exit-record.ts +13 -1
  111. package/scripts/agent/agent-role-profile.ts +101 -45
  112. package/scripts/agent/agent-safe-text.ts +60 -0
  113. package/scripts/agent/api-auth.ts +41 -0
  114. package/scripts/agent/api-outage.ts +1 -1
  115. package/scripts/agent/claude-agent-argv.ts +14 -0
  116. package/scripts/agent/codex-agent-argv.ts +2 -0
  117. package/scripts/agent/lane-instructions.ts +144 -0
  118. package/scripts/auto-ok/auto-ok-cli.ts +14 -16
  119. package/scripts/auto-ok/auto-ok-judge-read.ts +12 -3
  120. package/scripts/auto-ok/auto-ok-judge-write.ts +46 -19
  121. package/scripts/auto-ok/auto-ok-judge.ts +13 -2
  122. package/scripts/auto-ok/auto-ok-main.ts +17 -0
  123. package/scripts/backlog/backlog-arrival.ts +14 -3
  124. package/scripts/backlog/backlog-budget-cli.ts +7 -33
  125. package/scripts/backlog/backlog-budget-main.ts +16 -0
  126. package/scripts/backlog/backlog-budget.ts +6 -7
  127. package/scripts/backlog/backlog-defect-priority.ts +4 -3
  128. package/scripts/backlog/backlog-drive-adopt.ts +67 -0
  129. package/scripts/backlog/backlog-drive-args.ts +4 -5
  130. package/scripts/backlog/backlog-drive-cli.ts +113 -28
  131. package/scripts/backlog/backlog-drive-hold.ts +162 -0
  132. package/scripts/backlog/backlog-drive-idle.ts +151 -0
  133. package/scripts/backlog/backlog-drive-judge.ts +25 -0
  134. package/scripts/backlog/backlog-drive-memory.ts +126 -0
  135. package/scripts/backlog/backlog-drive-named-offer.ts +5 -10
  136. package/scripts/backlog/backlog-drive-named.ts +54 -7
  137. package/scripts/backlog/backlog-drive-offer-argv.ts +3 -8
  138. package/scripts/backlog/backlog-drive-paused.ts +169 -0
  139. package/scripts/backlog/backlog-drive-restore.ts +39 -8
  140. package/scripts/backlog/backlog-drive-seats.ts +18 -8
  141. package/scripts/backlog/backlog-drive-token-handling.ts +38 -0
  142. package/scripts/backlog/backlog-drive.ts +79 -75
  143. package/scripts/backlog/backlog-next-main.ts +16 -0
  144. package/scripts/backlog/backlog-next-shared.ts +73 -0
  145. package/scripts/backlog/backlog-next.ts +48 -16
  146. package/scripts/backlog/backlog-occupied.ts +69 -0
  147. package/scripts/backlog/backlog-offer-cli.ts +6 -21
  148. package/scripts/backlog/backlog-offer-exclude.ts +15 -0
  149. package/scripts/backlog/backlog-offer-main.ts +12 -0
  150. package/scripts/backlog/backlog-offer.ts +36 -3
  151. package/scripts/backlog/backlog-overlap.ts +22 -4
  152. package/scripts/backlog/backlog-plan-read.ts +6 -2
  153. package/scripts/backlog/backlog-plan.ts +18 -4
  154. package/scripts/backlog/backlog-pool.ts +10 -10
  155. package/scripts/backlog/backlog-rank.ts +10 -2
  156. package/scripts/backlog/backlog-ready.ts +137 -18
  157. package/scripts/backlog/backlog-stalled-detect.ts +109 -36
  158. package/scripts/backlog/backlog-stalled.ts +52 -16
  159. package/scripts/backlog/backlog-wait-cause.ts +86 -0
  160. package/scripts/backlog/backlog-waves.ts +39 -13
  161. package/scripts/backlog/backlogrun-args.ts +19 -7
  162. package/scripts/backlog/backlogrun-cli.ts +19 -5
  163. package/scripts/backlog/backlogrun-launch.ts +6 -0
  164. package/scripts/backlog/backlogrun-restart.ts +97 -0
  165. package/scripts/backlog/backlogrun-stop.ts +79 -7
  166. package/scripts/behavior/behavior-cli.ts +2 -2
  167. package/scripts/behavior/behavior-rules.ts +47 -24
  168. package/scripts/build/build-bin.ts +2 -16
  169. package/scripts/build/build-claude-md.ts +0 -7
  170. package/scripts/build/build-commands.ts +0 -13
  171. package/scripts/build/build-hooks.ts +49 -48
  172. package/scripts/build/hook-bundle-stamp.ts +29 -11
  173. package/scripts/build/local-bin.ts +1 -1
  174. package/scripts/cases/cases-cli.ts +25 -13
  175. package/scripts/cases/cases-interaction-scan.ts +134 -0
  176. package/scripts/cases/cases-interaction.ts +183 -0
  177. package/scripts/cases/cases-logic.ts +39 -6
  178. package/scripts/ci/pr-classification-main.ts +18 -0
  179. package/scripts/ci/pr-classification.ts +10 -17
  180. package/scripts/clone/clone-scan.ts +1 -1
  181. package/scripts/cost-runtime/cost-blocks.ts +22 -37
  182. package/scripts/cost-runtime/cost-cli.ts +31 -14
  183. package/scripts/cost-runtime/cost-main.ts +12 -0
  184. package/scripts/cost-runtime/cost-transcript.ts +1 -0
  185. package/scripts/delegation/delegation-policy.ts +17 -4
  186. package/scripts/delegation/duplicate-read-guard.ts +2 -10
  187. package/scripts/delegation/investigation-guard.ts +15 -73
  188. package/scripts/delegation/investigation-reads.ts +3 -5
  189. package/scripts/dependabot/dependabot-cooldown.ts +194 -0
  190. package/scripts/discovery/repo-discovery.ts +24 -6
  191. package/scripts/doctor/doctor-consumer.ts +2 -5
  192. package/scripts/document/document-byte-budget.ts +9 -6
  193. package/scripts/document/document-scan.ts +1 -1
  194. package/scripts/document/document-section-cli.ts +17 -13
  195. package/scripts/document/document-section-main.ts +12 -0
  196. package/scripts/document/entry-read-budget.ts +2 -2
  197. package/scripts/document/read-set-cli.ts +4 -1
  198. package/scripts/epic/epic-audit-cli.ts +12 -6
  199. package/scripts/epic/epic-audit-orphans.ts +5 -8
  200. package/scripts/epic/epic-audit.ts +52 -1
  201. package/scripts/epic/epic-bundle-apply.ts +137 -0
  202. package/scripts/epic/epic-bundle-cli.ts +32 -121
  203. package/scripts/epic/epic-bundle-evidence.ts +49 -26
  204. package/scripts/epic/epic-bundle-format.ts +116 -0
  205. package/scripts/epic/epic-bundle-main.ts +17 -0
  206. package/scripts/epic/epic-bundle-referenced.ts +14 -3
  207. package/scripts/epic/epic-bundle.ts +17 -9
  208. package/scripts/epic/epic-busy.ts +5 -12
  209. package/scripts/epic/epic-classify.ts +24 -15
  210. package/scripts/epic/epic-cli-argv.ts +31 -0
  211. package/scripts/epic/epic-cli-decide.ts +42 -0
  212. package/scripts/epic/epic-cli.ts +6 -38
  213. package/scripts/epic/epic-close.ts +112 -55
  214. package/scripts/epic/epic-cross-repo.ts +4 -7
  215. package/scripts/epic/epic-decide.ts +119 -0
  216. package/scripts/epic/epic-decision.ts +9 -0
  217. package/scripts/epic/epic-fetch.ts +4 -0
  218. package/scripts/epic/epic-graph.ts +2 -0
  219. package/scripts/epic/epic-issue.ts +5 -1
  220. package/scripts/epic/epic-label-age.ts +1 -1
  221. package/scripts/epic/epic-lane-offer.ts +39 -4
  222. package/scripts/epic/epic-next-main.ts +24 -0
  223. package/scripts/epic/epic-next.ts +6 -24
  224. package/scripts/epic/epic-outside-blocker.ts +6 -2
  225. package/scripts/epic/epic-parse.ts +9 -3
  226. package/scripts/epic/epic-read.ts +1 -0
  227. package/scripts/epic/epic-reconcile.ts +39 -0
  228. package/scripts/epic/epic-run.ts +10 -1
  229. package/scripts/epic/epic-solo.ts +50 -14
  230. package/scripts/epic/epic.ts +41 -7
  231. package/scripts/exports/unused-members-cli.ts +2 -2
  232. package/scripts/followup/followup-checks-event.ts +8 -3
  233. package/scripts/followup/followup-coderabbit-wait.ts +82 -0
  234. package/scripts/followup/followup-review-gates.ts +81 -0
  235. package/scripts/followup/git-followup-stages.ts +13 -3
  236. package/scripts/followup/git-followup-workflow.ts +31 -60
  237. package/scripts/followup/git-pr-followup-wrapup.ts +9 -14
  238. package/scripts/followup/git-pr-followup.ts +36 -8
  239. package/scripts/fresh-machine/fresh-machine-cli.ts +1 -1
  240. package/scripts/fresh-machine/fresh-machine-run.ts +8 -8
  241. package/scripts/fresh-machine/specs/kit-test-backlogrun.json +1 -1
  242. package/scripts/gate/busy-average.ts +58 -0
  243. package/scripts/gate/check-cpu.ts +60 -0
  244. package/scripts/gate/check-inputs.ts +73 -0
  245. package/scripts/gate/check-reuse.ts +141 -0
  246. package/scripts/gate/command-memory.ts +192 -0
  247. package/scripts/gate/core-admission.ts +218 -28
  248. package/scripts/gate/core-budget-timing.ts +37 -0
  249. package/scripts/gate/core-budget.ts +150 -119
  250. package/scripts/gate/core-wait-record.ts +48 -0
  251. package/scripts/gate/core-wait.ts +162 -0
  252. package/scripts/gate/core-weights.ts +86 -0
  253. package/scripts/gate/free-cores.ts +72 -0
  254. package/scripts/gate/gate-ledger.ts +49 -7
  255. package/scripts/gate/gate-plan.ts +44 -15
  256. package/scripts/gate/gate-report.ts +29 -4
  257. package/scripts/gate/gate-run-steps.ts +195 -0
  258. package/scripts/gate/gate-skip.ts +12 -2
  259. package/scripts/gate/gate-steps.ts +12 -1
  260. package/scripts/gate/held-mark.ts +55 -0
  261. package/scripts/gate/input-fingerprint.ts +42 -0
  262. package/scripts/gate/machine-capacity.ts +124 -31
  263. package/scripts/gate/moved-paths.ts +67 -0
  264. package/scripts/gate/pre-commit-type-check.ts +14 -1
  265. package/scripts/gate/project-checks.ts +5 -12
  266. package/scripts/gate/scoped-green.ts +12 -8
  267. package/scripts/gate/since-green.ts +62 -0
  268. package/scripts/gate/toolchain-inputs.ts +115 -0
  269. package/scripts/gate/verification-gate.ts +65 -129
  270. package/scripts/gate/verification-inputs.ts +250 -0
  271. package/scripts/gh/gh-author-association.ts +96 -9
  272. package/scripts/gh/git-ai-review-scan.ts +4 -2
  273. package/scripts/gh/git-gh-api-path.ts +15 -0
  274. package/scripts/gh/git-gh-branch-rules.ts +73 -0
  275. package/scripts/gh/git-gh-conditional.ts +5 -2
  276. package/scripts/gh/git-gh-issue-read.ts +5 -1
  277. package/scripts/gh/git-gh-issue-rest.ts +1 -0
  278. package/scripts/gh/git-gh-issue-write.ts +77 -17
  279. package/scripts/gh/git-gh-issue.ts +7 -3
  280. package/scripts/gh/git-gh-poll-read.ts +89 -0
  281. package/scripts/gh/git-gh-pr-auto-merge.ts +8 -3
  282. package/scripts/gh/git-gh-pr-rest.ts +1 -1
  283. package/scripts/gh/git-gh-pr-snapshot.ts +33 -20
  284. package/scripts/gh/git-gh-pr.ts +27 -15
  285. package/scripts/gh/git-pr-checks-eval.ts +39 -7
  286. package/scripts/gh/git-pr-checks-parse.ts +39 -9
  287. package/scripts/gh/git-pr-merge-checked.ts +80 -0
  288. package/scripts/gh/git-pr.ts +13 -1
  289. package/scripts/git/base-tree.ts +19 -2
  290. package/scripts/git/changed-file-scope.ts +6 -4
  291. package/scripts/git/changed-paths.ts +18 -1
  292. package/scripts/git/git-diff-reads.ts +27 -2
  293. package/scripts/git/git-grep-hits.ts +85 -0
  294. package/scripts/git/git-location-environment.ts +1 -1
  295. package/scripts/git/git-merge-conflicts.ts +83 -0
  296. package/scripts/git/git-preflight.ts +37 -12
  297. package/scripts/git/git-push-transport.ts +1 -2
  298. package/scripts/git/git-schemas.ts +17 -7
  299. package/scripts/git/git-spawn.ts +1 -2
  300. package/scripts/git/git-status.ts +4 -4
  301. package/scripts/git/main-merge-main.ts +12 -0
  302. package/scripts/git/main-merge-regenerate.ts +78 -0
  303. package/scripts/git/main-merge.ts +39 -14
  304. package/scripts/git/main-sync-main.ts +12 -0
  305. package/scripts/git/main-sync.ts +0 -9
  306. package/scripts/git/stash/git-stash.ts +27 -4
  307. package/scripts/git/stash/{stash-pop-args.ts → stash-args.ts} +13 -10
  308. package/scripts/git/stash/stash-pop-cli.ts +6 -12
  309. package/scripts/git/stash/stash-pop-main.ts +12 -0
  310. package/scripts/git/stash/stash-push-cli.ts +76 -0
  311. package/scripts/git/stash/stash-push-main.ts +12 -0
  312. package/scripts/hooks/batch-guard.ts +5 -16
  313. package/scripts/hooks/check-commit-message-main.ts +8 -0
  314. package/scripts/hooks/check-commit-message.ts +4 -7
  315. package/scripts/hooks/format-edited-file.ts +8 -24
  316. package/scripts/hooks/pre-commit-lint.ts +118 -0
  317. package/scripts/hooks/pre-push-unit.ts +4 -2
  318. package/scripts/hooks/pretool-guard-cli.ts +1 -8
  319. package/scripts/hooks/pretool-guard.ts +57 -69
  320. package/scripts/hooks/reserved-run.ts +67 -8
  321. package/scripts/hooks/run-hook.sh +18 -11
  322. package/scripts/hooks/shell-rules-notice.ts +37 -0
  323. package/scripts/hooks/stop-actions.ts +185 -0
  324. package/scripts/hooks/stop-guard.ts +72 -27
  325. package/scripts/init/hook-command-rewrite.ts +19 -5
  326. package/scripts/init/hook-launch.ts +15 -12
  327. package/scripts/init/init-actions.ts +0 -6
  328. package/scripts/init/init-ai-copy.ts +10 -36
  329. package/scripts/init/init-bootstrap.ts +9 -8
  330. package/scripts/init/init-dry-run-report.ts +1 -1
  331. package/scripts/init/init-dry-run.ts +1 -1
  332. package/scripts/init/init-file-action.ts +7 -9
  333. package/scripts/init/init-logic-json-merge.ts +2 -2
  334. package/scripts/init/init-logic-migrate.ts +9 -82
  335. package/scripts/init/init-logic.ts +3 -2
  336. package/scripts/init/init-main.ts +12 -0
  337. package/scripts/init/init.ts +5 -12
  338. package/scripts/init/kit-development-versions.ts +3 -7
  339. package/scripts/init/kit-written-paths.ts +2 -2
  340. package/scripts/init/project-profile.ts +5 -4
  341. package/scripts/init/tsconfig-preset-migration.ts +2 -1
  342. package/scripts/init/vscode-tasks.ts +1 -1
  343. package/scripts/issue/defect-origin-cli.ts +106 -0
  344. package/scripts/issue/defect-origin-line.ts +60 -0
  345. package/scripts/issue/defect-origin-main.ts +11 -0
  346. package/scripts/issue/defect-origin.ts +114 -0
  347. package/scripts/issue/defect-rate-cli.ts +34 -78
  348. package/scripts/issue/defect-rate.ts +0 -16
  349. package/scripts/issue/defect-report-cli.ts +128 -0
  350. package/scripts/issue/defect-report-format.ts +56 -0
  351. package/scripts/issue/defect-report-main.ts +11 -0
  352. package/scripts/issue/defect-report.ts +160 -0
  353. package/scripts/issue/expected-effect-lint.ts +60 -0
  354. package/scripts/issue/issue-already-done-cli.ts +62 -0
  355. package/scripts/issue/issue-body-or-comment.ts +40 -0
  356. package/scripts/issue/issue-cite-cli.ts +33 -22
  357. package/scripts/issue/issue-cite-main.ts +12 -0
  358. package/scripts/issue/issue-classification.ts +13 -8
  359. package/scripts/issue/issue-comment-cli.ts +10 -24
  360. package/scripts/issue/issue-comment-main.ts +12 -0
  361. package/scripts/issue/issue-evidence-exit.ts +100 -0
  362. package/scripts/issue/issue-file-cli.ts +29 -7
  363. package/scripts/issue/issue-file.ts +19 -19
  364. package/scripts/issue/issue-fold-cli.ts +2 -11
  365. package/scripts/issue/issue-fold-main.ts +12 -0
  366. package/scripts/issue/issue-labels.ts +81 -90
  367. package/scripts/issue/issue-lint-cli.ts +7 -13
  368. package/scripts/issue/issue-lint-main.ts +12 -0
  369. package/scripts/issue/issue-measured-cli.ts +56 -0
  370. package/scripts/issue/issue-merged.ts +19 -2
  371. package/scripts/issue/issue-not-before-label.ts +135 -0
  372. package/scripts/issue/issue-not-before.ts +111 -0
  373. package/scripts/issue/issue-number-shape.ts +15 -1
  374. package/scripts/issue/issue-park.ts +28 -0
  375. package/scripts/issue/issue-plan-cli.ts +151 -0
  376. package/scripts/issue/issue-priority.ts +151 -0
  377. package/scripts/issue/issue-rank.ts +7 -1
  378. package/scripts/issue/issue-read-cli.ts +3 -10
  379. package/scripts/issue/issue-read-main.ts +12 -0
  380. package/scripts/issue/issue-read.ts +29 -5
  381. package/scripts/issue/issue-release-cli.ts +0 -10
  382. package/scripts/issue/issue-release-main.ts +13 -0
  383. package/scripts/issue/issue-release.ts +7 -12
  384. package/scripts/issue/issue-sample-gate.ts +192 -0
  385. package/scripts/issue/issue-sample-source.ts +76 -0
  386. package/scripts/issue/issue-scout-cli.ts +19 -25
  387. package/scripts/issue/issue-scout-main.ts +14 -0
  388. package/scripts/issue/issue-state-cli.ts +0 -10
  389. package/scripts/issue/issue-state-main.ts +12 -0
  390. package/scripts/issue/issue-watch-diff.ts +56 -15
  391. package/scripts/issue/issue-watch.ts +2 -1
  392. package/scripts/issue/issue-wip.ts +2 -7
  393. package/scripts/issue/markdown-section.ts +19 -5
  394. package/scripts/issue/measure-rerun-cli.ts +13 -8
  395. package/scripts/issue/plan-consumers-cli.ts +39 -0
  396. package/scripts/issue/plan-consumers-main.ts +11 -0
  397. package/scripts/issue/plan-consumers-section.ts +55 -0
  398. package/scripts/issue/plan-consumers.ts +127 -0
  399. package/scripts/josh/agent-session-environment.ts +1 -1
  400. package/scripts/josh/command-usage.ts +82 -0
  401. package/scripts/josh/file-map-stamp.ts +49 -16
  402. package/scripts/josh/hook-decision.ts +32 -20
  403. package/scripts/josh/josh-command-map.ts +6 -1
  404. package/scripts/josh/josh-command-types.ts +65 -13
  405. package/scripts/josh/josh-commands-agent-hooks.ts +83 -0
  406. package/scripts/josh/josh-commands-ai.ts +169 -157
  407. package/scripts/josh/josh-commands-backlog.ts +82 -16
  408. package/scripts/josh/josh-commands-clone.ts +1 -0
  409. package/scripts/josh/josh-commands-development.ts +111 -71
  410. package/scripts/josh/josh-commands-document.ts +43 -1
  411. package/scripts/josh/josh-commands-epic.ts +171 -0
  412. package/scripts/josh/josh-commands-hooks.ts +31 -2
  413. package/scripts/josh/josh-commands-issue-write.ts +181 -0
  414. package/scripts/josh/josh-commands-issue.ts +124 -24
  415. package/scripts/josh/josh-commands-lane.ts +112 -2
  416. package/scripts/josh/josh-commands-lint.ts +19 -8
  417. package/scripts/josh/josh-commands-maintenance.ts +112 -4
  418. package/scripts/josh/josh-commands-pause.ts +29 -0
  419. package/scripts/josh/josh-commands-progress.ts +87 -0
  420. package/scripts/josh/josh-commands-project.ts +138 -9
  421. package/scripts/josh/josh-commands-review.ts +124 -0
  422. package/scripts/josh/josh-commands-run.ts +211 -23
  423. package/scripts/josh/josh-commands-ship.ts +169 -0
  424. package/scripts/josh/josh-commands-split.ts +9 -0
  425. package/scripts/josh/josh-commands-versioning.ts +49 -2
  426. package/scripts/josh/josh-commands-workflow.ts +149 -6
  427. package/scripts/josh/josh-logic.ts +11 -27
  428. package/scripts/josh/josh.ts +14 -5
  429. package/scripts/josh/package-directory.ts +18 -0
  430. package/scripts/josh/process-identity.ts +13 -4
  431. package/scripts/josh/session-language-cli.ts +4 -8
  432. package/scripts/josh/session-language-main.ts +13 -0
  433. package/scripts/josh/session-language.ts +6 -1
  434. package/scripts/josh/shared-cache.ts +90 -0
  435. package/scripts/josh/stamp-file.ts +9 -15
  436. package/scripts/lane/lane-await.ts +51 -12
  437. package/scripts/lane/lane-cache.ts +5 -30
  438. package/scripts/lane/lane-capacity.ts +19 -22
  439. package/scripts/lane/lane-check-stats.ts +97 -0
  440. package/scripts/lane/lane-child-invocation.ts +43 -4
  441. package/scripts/lane/lane-cli.ts +15 -5
  442. package/scripts/lane/lane-close.ts +86 -18
  443. package/scripts/lane/lane-core-wait-stats.ts +66 -0
  444. package/scripts/lane/lane-dispatch.ts +27 -6
  445. package/scripts/lane/lane-gap-stats.ts +156 -0
  446. package/scripts/lane/lane-guard-policy.ts +2 -2
  447. package/scripts/lane/lane-handoff.ts +76 -1
  448. package/scripts/lane/lane-held-stats.ts +129 -0
  449. package/scripts/lane/lane-install.ts +16 -15
  450. package/scripts/lane/lane-launch-cli.ts +0 -9
  451. package/scripts/lane/lane-launch-main.ts +12 -0
  452. package/scripts/lane/lane-ledger-schema.ts +266 -0
  453. package/scripts/lane/lane-ledger.ts +108 -97
  454. package/scripts/lane/lane-limit-cli.ts +19 -9
  455. package/scripts/lane/lane-measure-cli.ts +58 -10
  456. package/scripts/lane/lane-open.ts +9 -1
  457. package/scripts/lane/lane-parked.ts +3 -3
  458. package/scripts/lane/lane-pause-cli.ts +130 -0
  459. package/scripts/lane/lane-pause.ts +158 -0
  460. package/scripts/lane/lane-preserve.ts +29 -1
  461. package/scripts/lane/lane-process-table.ts +166 -0
  462. package/scripts/lane/lane-reap-settle.ts +124 -0
  463. package/scripts/lane/lane-reap.ts +50 -15
  464. package/scripts/lane/lane-registry.ts +33 -10
  465. package/scripts/lane/lane-residents.ts +162 -0
  466. package/scripts/lane/lane-restart.ts +26 -27
  467. package/scripts/lane/lane-round-two-stats.ts +49 -0
  468. package/scripts/lane/lane-sampler.ts +4 -0
  469. package/scripts/lane/lane-session-action.ts +160 -0
  470. package/scripts/lane/lane-session-broker.ts +134 -134
  471. package/scripts/lane/lane-snapshot-trace.ts +84 -0
  472. package/scripts/lane/lane-spans.ts +51 -0
  473. package/scripts/lane/lane-spent.ts +6 -3
  474. package/scripts/lane/lane-stage-stats.ts +7 -2
  475. package/scripts/lane/lane-state.ts +302 -0
  476. package/scripts/lane/lane-stats.ts +58 -4
  477. package/scripts/lane/lane-stop-stats.ts +113 -37
  478. package/scripts/lane/lane-test-related-stats.ts +127 -0
  479. package/scripts/lane/lane-transcript-calls.ts +145 -0
  480. package/scripts/lane/lane-transcript-stats.ts +168 -0
  481. package/scripts/lane/lane-vacant.ts +13 -3
  482. package/scripts/lane/lane-withdraw-cli.ts +72 -0
  483. package/scripts/lane/lane-withdraw.ts +183 -0
  484. package/scripts/lane/process-directories.ts +70 -0
  485. package/scripts/lane/process-lane-marks.ts +94 -0
  486. package/scripts/lib/atomic-write.ts +62 -0
  487. package/scripts/lib/buffered-process.ts +12 -5
  488. package/scripts/lib/cli-flags.ts +53 -0
  489. package/scripts/lib/figure-format.ts +63 -0
  490. package/scripts/lib/json-value.ts +9 -1
  491. package/scripts/lib/package-manifest.ts +35 -0
  492. package/scripts/lib/read-file.ts +3 -1
  493. package/scripts/lib/stamped-memo.ts +63 -0
  494. package/scripts/lib/stdout-on-stderr.ts +24 -0
  495. package/scripts/lib/timeouts.ts +9 -0
  496. package/scripts/lib/transcript-record.ts +91 -0
  497. package/scripts/lines/effective-limit.ts +1 -1
  498. package/scripts/lint/eslint-cache-dependencies.ts +145 -0
  499. package/scripts/lint/eslint-daemon.ts +265 -0
  500. package/scripts/lint/format.ts +14 -5
  501. package/scripts/lint/import-graph.ts +279 -0
  502. package/scripts/lint/lint-gate-scope.ts +102 -0
  503. package/scripts/lint/lint-parallel-main.ts +19 -0
  504. package/scripts/lint/lint-parallel.ts +72 -33
  505. package/scripts/lint/lint-related-scope.ts +33 -24
  506. package/scripts/lint/lint-related.ts +38 -6
  507. package/scripts/notify/confirmation-options.ts +1 -2
  508. package/scripts/notify/telegram-notify.ts +20 -20
  509. package/scripts/notify/telegram-test-logic.ts +0 -1
  510. package/scripts/notify/telegram-test-main.ts +8 -0
  511. package/scripts/notify/telegram-test.ts +12 -11
  512. package/scripts/observations/observation-ledger.ts +13 -0
  513. package/scripts/observations/observations-flush-landing.ts +5 -3
  514. package/scripts/observations/observations-flush.ts +6 -1
  515. package/scripts/overrides/overrides-check.ts +2 -5
  516. package/scripts/overrides/overrides-files.ts +2 -1
  517. package/scripts/overrides/overrides-logic.ts +3 -6
  518. package/scripts/package/verify-optional-eslint-install.ts +8 -6
  519. package/scripts/propagate/propagate-publish.ts +2 -7
  520. package/scripts/propagate/propagate-targets.ts +4 -12
  521. package/scripts/refactor/import-graph.ts +9 -7
  522. package/scripts/release/github-release-runs.ts +17 -6
  523. package/scripts/release/release-approval-prune.ts +18 -0
  524. package/scripts/release/release-history.ts +1 -3
  525. package/scripts/release/release-progress.ts +42 -22
  526. package/scripts/release/release-publish-run.ts +39 -0
  527. package/scripts/release/release-publish.ts +6 -6
  528. package/scripts/release/release-scope-cli.ts +0 -10
  529. package/scripts/release/release-scope-main.ts +12 -0
  530. package/scripts/repo/repo-setting.ts +3 -6
  531. package/scripts/repo/required-checks-logic.ts +6 -15
  532. package/scripts/report/report-format-reference.ts +4 -0
  533. package/scripts/report/report-labels.ts +155 -0
  534. package/scripts/report/report-lint-cli.ts +3 -0
  535. package/scripts/report/report-lint.ts +85 -110
  536. package/scripts/report/report-template-cli.ts +59 -0
  537. package/scripts/report/report-template.ts +112 -0
  538. package/scripts/review/acceptance-map-check.ts +61 -0
  539. package/scripts/review/acceptance-map.ts +206 -0
  540. package/scripts/review/removed-tests-check.ts +86 -0
  541. package/scripts/review/removed-tests.ts +149 -0
  542. package/scripts/review/review-brief-cli.ts +82 -16
  543. package/scripts/review/review-brief-main.ts +12 -0
  544. package/scripts/review/review-brief.ts +31 -3
  545. package/scripts/review/review-code-tree.ts +10 -6
  546. package/scripts/review/review-comment-round.ts +26 -8
  547. package/scripts/review/review-finding-ledger.ts +30 -15
  548. package/scripts/review/review-interaction.ts +94 -0
  549. package/scripts/review/review-readers-scan.ts +163 -0
  550. package/scripts/review/review-record-cli.ts +69 -30
  551. package/scripts/review/review-record-main.ts +12 -0
  552. package/scripts/review/review-round-one-blobs.ts +221 -0
  553. package/scripts/review/review-round2-cli.ts +49 -12
  554. package/scripts/review/review-round2.ts +80 -12
  555. package/scripts/review/review-stamps.ts +19 -1
  556. package/scripts/review/review-stop-log.ts +96 -0
  557. package/scripts/review/review-stops-cli.ts +85 -0
  558. package/scripts/review/review-tree.ts +6 -17
  559. package/scripts/review/review-untouched-readers.ts +146 -0
  560. package/scripts/review/test-titles.ts +118 -0
  561. package/scripts/rules/agent-model.ts +67 -0
  562. package/scripts/rules/bash-triggers.ts +46 -3
  563. package/scripts/rules/decision-oracle-batch.ts +9 -1
  564. package/scripts/rules/decision-oracle.ts +2 -2
  565. package/scripts/rules/delivered-rules.ts +90 -3
  566. package/scripts/rules/destructive-command.ts +8 -1
  567. package/scripts/rules/direct-filing.ts +10 -2
  568. package/scripts/rules/direct-issue-comment.ts +117 -0
  569. package/scripts/rules/direct-pr-create.ts +69 -3
  570. package/scripts/rules/early-heartbeat.ts +2 -1
  571. package/scripts/rules/file-body.ts +7 -0
  572. package/scripts/rules/filing-cap.ts +8 -0
  573. package/scripts/rules/firing-point.ts +6 -5
  574. package/scripts/rules/git-argv.ts +72 -14
  575. package/scripts/rules/git-force.ts +12 -2
  576. package/scripts/rules/guard-remedy.ts +121 -0
  577. package/scripts/rules/implementation-cut-verdict.ts +1 -1
  578. package/scripts/rules/implementation-cut.ts +11 -3
  579. package/scripts/rules/index-guard.ts +8 -1
  580. package/scripts/rules/issue-comments.ts +76 -7
  581. package/scripts/rules/josh-git-bare.ts +7 -0
  582. package/scripts/rules/lane-background.ts +67 -25
  583. package/scripts/rules/lane-carry-conflict.ts +6 -0
  584. package/scripts/rules/lane-direct-tool.ts +74 -0
  585. package/scripts/rules/lane-interactive-ask.ts +9 -2
  586. package/scripts/rules/lane-park.ts +45 -23
  587. package/scripts/rules/lane-split-park.ts +10 -2
  588. package/scripts/rules/lane-switch-main.ts +7 -0
  589. package/scripts/rules/last-prompt.ts +50 -5
  590. package/scripts/rules/oracle-consulted.ts +10 -0
  591. package/scripts/rules/oracle-firing.ts +1 -0
  592. package/scripts/rules/oracle-list-cli.ts +7 -0
  593. package/scripts/rules/permission-guards.ts +3 -0
  594. package/scripts/rules/piped-verification.ts +4 -2
  595. package/scripts/rules/poll-loop.ts +7 -0
  596. package/scripts/rules/pr-merge.ts +123 -0
  597. package/scripts/rules/protected-files.ts +32 -5
  598. package/scripts/rules/raw-field-body.ts +6 -0
  599. package/scripts/rules/rule-body-guard.ts +8 -0
  600. package/scripts/rules/rule-list.ts +12 -28
  601. package/scripts/rules/rule-rewrite.ts +114 -0
  602. package/scripts/rules/rule-value-cache.ts +4 -9
  603. package/scripts/rules/rule-value-cli.ts +51 -32
  604. package/scripts/rules/rule-value.ts +8 -2
  605. package/scripts/rules/shell-segments.ts +50 -0
  606. package/scripts/rules/stop-decision.ts +77 -0
  607. package/scripts/rules/stop-rule-rows.ts +64 -0
  608. package/scripts/rules/stop-rules.ts +150 -51
  609. package/scripts/rules/tail-commands.ts +15 -1
  610. package/scripts/rules/test-declared-commit.ts +11 -1
  611. package/scripts/rules/third-party-write.ts +7 -0
  612. package/scripts/rules/timed-rerun.ts +69 -0
  613. package/scripts/rules/worktree-guard.ts +13 -3
  614. package/scripts/run/board/run-board-app-name.ts +23 -0
  615. package/scripts/run/board/run-board-cli.ts +65 -30
  616. package/scripts/run/board/run-board-closed.ts +8 -2
  617. package/scripts/run/board/run-board-earlier.ts +94 -0
  618. package/scripts/run/board/run-board-ending-reason.ts +67 -0
  619. package/scripts/run/board/run-board-estimate-schedule.ts +103 -0
  620. package/scripts/run/board/run-board-estimate.ts +98 -0
  621. package/scripts/run/board/run-board-fit.ts +153 -36
  622. package/scripts/run/board/run-board-fold.ts +123 -0
  623. package/scripts/run/board/run-board-fresh.ts +2 -2
  624. package/scripts/run/board/run-board-gather-live.ts +29 -0
  625. package/scripts/run/board/run-board-gather-thread.ts +189 -0
  626. package/scripts/run/board/run-board-gather-worker.ts +29 -0
  627. package/scripts/run/board/run-board-gather.ts +187 -0
  628. package/scripts/run/board/run-board-github.ts +119 -31
  629. package/scripts/run/board/run-board-header.ts +86 -21
  630. package/scripts/run/board/run-board-keys.ts +58 -0
  631. package/scripts/run/board/run-board-kind.ts +20 -6
  632. package/scripts/run/board/run-board-labels.ts +118 -71
  633. package/scripts/run/board/run-board-lane-state.ts +109 -0
  634. package/scripts/run/board/run-board-lane-time.ts +122 -0
  635. package/scripts/run/board/run-board-layout.ts +240 -61
  636. package/scripts/run/board/run-board-length.ts +52 -0
  637. package/scripts/run/board/run-board-machine.ts +8 -4
  638. package/scripts/run/board/run-board-main.ts +12 -0
  639. package/scripts/run/board/run-board-notes.ts +52 -31
  640. package/scripts/run/board/run-board-now.ts +1 -1
  641. package/scripts/run/board/run-board-operation.ts +15 -33
  642. package/scripts/run/board/run-board-phase.ts +1 -1
  643. package/scripts/run/board/run-board-plan-shared.ts +115 -0
  644. package/scripts/run/board/run-board-plan.ts +55 -3
  645. package/scripts/run/board/run-board-planning.ts +45 -0
  646. package/scripts/run/board/run-board-priority.ts +44 -0
  647. package/scripts/run/board/run-board-process-groups.ts +195 -0
  648. package/scripts/run/board/run-board-read.ts +153 -13
  649. package/scripts/run/board/run-board-reason.ts +238 -45
  650. package/scripts/run/board/run-board-released.ts +35 -0
  651. package/scripts/run/board/run-board-render-checks.ts +39 -5
  652. package/scripts/run/board/run-board-render-condition.ts +96 -0
  653. package/scripts/run/board/run-board-render-drawn.ts +67 -0
  654. package/scripts/run/board/run-board-render-foot.ts +59 -0
  655. package/scripts/run/board/run-board-render-icon.ts +35 -0
  656. package/scripts/run/board/run-board-render-lanes.ts +145 -0
  657. package/scripts/run/board/run-board-render-lead.ts +80 -0
  658. package/scripts/run/board/run-board-render-legend.ts +117 -47
  659. package/scripts/run/board/run-board-render-notes.ts +156 -29
  660. package/scripts/run/board/run-board-render-processes.ts +196 -0
  661. package/scripts/run/board/run-board-render-section.ts +119 -0
  662. package/scripts/run/board/run-board-render-slot.ts +3 -36
  663. package/scripts/run/board/run-board-render-tail.ts +115 -48
  664. package/scripts/run/board/run-board-render-time.ts +56 -0
  665. package/scripts/run/board/run-board-render-title.ts +117 -24
  666. package/scripts/run/board/run-board-render-waits.ts +125 -0
  667. package/scripts/run/board/run-board-render.ts +206 -259
  668. package/scripts/run/board/run-board-roots.ts +54 -0
  669. package/scripts/run/board/run-board-row-yield.ts +10 -4
  670. package/scripts/run/board/run-board-setup.ts +1 -12
  671. package/scripts/run/board/run-board-snapshot.ts +111 -0
  672. package/scripts/run/board/run-board-spin.ts +2 -2
  673. package/scripts/run/board/run-board-state.ts +23 -29
  674. package/scripts/run/board/run-board-status.ts +206 -79
  675. package/scripts/run/board/run-board-thanks-read.ts +2 -2
  676. package/scripts/run/board/run-board-tick.ts +123 -104
  677. package/scripts/run/board/run-board-usage-board.ts +78 -0
  678. package/scripts/run/board/run-board-usage-lanes.ts +113 -0
  679. package/scripts/run/board/run-board-usage-listing.ts +93 -0
  680. package/scripts/run/board/run-board-usage-read.ts +120 -150
  681. package/scripts/run/board/run-board-usage-rusage.ts +19 -7
  682. package/scripts/run/board/run-board-usage-text.ts +139 -51
  683. package/scripts/run/board/run-board-usage-top.ts +102 -0
  684. package/scripts/run/board/run-board-usage.ts +89 -72
  685. package/scripts/run/board/run-board-usual.ts +20 -9
  686. package/scripts/run/carry/run-carry-args.ts +4 -7
  687. package/scripts/run/carry/run-carry-conversation.ts +1 -1
  688. package/scripts/run/carry/run-carry.ts +9 -4
  689. package/scripts/run/cut/run-cut-cli.ts +3 -2
  690. package/scripts/run/cut/run-cut-handoff.ts +2 -2
  691. package/scripts/run/cut/run-cut-report.ts +16 -0
  692. package/scripts/run/detached-launch.ts +23 -4
  693. package/scripts/run/entry/run-entry-cli.ts +8 -1
  694. package/scripts/run/event/run-event-cli.ts +1 -5
  695. package/scripts/run/event/run-event-filed.ts +12 -6
  696. package/scripts/run/event/run-event-follow.ts +2 -3
  697. package/scripts/run/event/run-event-render.ts +7 -10
  698. package/scripts/run/event/run-event-scope.ts +20 -2
  699. package/scripts/run/event/run-event-stream-emit.ts +78 -11
  700. package/scripts/run/event/run-event-stream.ts +37 -7
  701. package/scripts/run/hold/run-hold-adopt.ts +65 -0
  702. package/scripts/run/hold/run-hold-cli.ts +93 -22
  703. package/scripts/run/hold/run-hold-main.ts +12 -0
  704. package/scripts/run/hold/run-hold-member.ts +37 -0
  705. package/scripts/run/hold/run-hold-session.ts +46 -0
  706. package/scripts/run/hold/run-hold.ts +7 -1
  707. package/scripts/run/hold/run-stop-notify.ts +183 -0
  708. package/scripts/run/launch-priority.ts +32 -0
  709. package/scripts/run/merge/run-merge-auth.ts +31 -0
  710. package/scripts/run/merge/run-merge-cli.ts +72 -107
  711. package/scripts/run/merge/run-merge-close.ts +74 -0
  712. package/scripts/run/merge/run-merge-collect.ts +6 -13
  713. package/scripts/run/merge/run-merge-driver.ts +71 -0
  714. package/scripts/run/merge/run-merge-main.ts +12 -0
  715. package/scripts/run/merge/run-merge-outcome.ts +23 -0
  716. package/scripts/run/merge/run-merge-restart.ts +39 -0
  717. package/scripts/run/merge/run-merge-ship.ts +20 -4
  718. package/scripts/run/merge/run-merge-signals.ts +123 -0
  719. package/scripts/run/merge/run-merge-steps.ts +128 -83
  720. package/scripts/run/merge/run-merge.ts +53 -40
  721. package/scripts/run/park/run-park-cli.ts +91 -0
  722. package/scripts/run/park/run-park.ts +88 -0
  723. package/scripts/run/park/run-stalled.ts +68 -0
  724. package/scripts/run/pause/run-pause-cli.ts +73 -0
  725. package/scripts/run/pause/run-pause.ts +251 -0
  726. package/scripts/run/progress/run-progress-cli.ts +4 -12
  727. package/scripts/run/progress/run-progress-clock.ts +1 -1
  728. package/scripts/run/progress/run-progress-config.ts +6 -14
  729. package/scripts/run/progress/run-progress-main.ts +12 -0
  730. package/scripts/run/progress/run-progress.ts +1 -4
  731. package/scripts/run/review/run-review.ts +2 -1
  732. package/scripts/run/run-ending.ts +1 -0
  733. package/scripts/run/run-invocation.ts +5 -6
  734. package/scripts/run/run-liveness-cli.ts +6 -8
  735. package/scripts/run/run-liveness.ts +61 -30
  736. package/scripts/run/run-next.ts +1 -1
  737. package/scripts/run/run-parent-cut-hook.ts +2 -2
  738. package/scripts/run/run-poll-hook.ts +157 -0
  739. package/scripts/run/run-preflight.ts +18 -3
  740. package/scripts/run/run-prep-cli.ts +1 -10
  741. package/scripts/run/run-prep-locate.ts +7 -50
  742. package/scripts/run/run-prep-main.ts +12 -0
  743. package/scripts/run/run-prep.ts +6 -0
  744. package/scripts/run/run-report-cli.ts +101 -13
  745. package/scripts/run/run-report-handoff.ts +114 -0
  746. package/scripts/run/run-step-cli.ts +22 -15
  747. package/scripts/run/run-step-section.ts +85 -0
  748. package/scripts/run/run-step.ts +1 -1
  749. package/scripts/run/run-stranded-detect.ts +13 -0
  750. package/scripts/run/run-watcher-guard-cli.ts +1 -1
  751. package/scripts/run/run-watcher-guard.ts +1 -1
  752. package/scripts/run/ship/run-ship-args.ts +121 -0
  753. package/scripts/run/ship/run-ship-body-draft.ts +110 -0
  754. package/scripts/run/ship/run-ship-cli.ts +67 -151
  755. package/scripts/run/ship/run-ship-detach.ts +27 -7
  756. package/scripts/run/ship/run-ship-infra-retry.ts +59 -0
  757. package/scripts/run/ship/run-ship-next.ts +27 -3
  758. package/scripts/run/ship/run-ship-overlap.ts +232 -0
  759. package/scripts/run/ship/run-ship-place.ts +96 -0
  760. package/scripts/run/ship/run-ship-pre-detach-timed.ts +43 -0
  761. package/scripts/run/ship/run-ship-pre-detach.ts +102 -27
  762. package/scripts/run/ship/run-ship-preflight.ts +161 -30
  763. package/scripts/run/ship/run-ship-probe.ts +11 -3
  764. package/scripts/run/ship/run-ship-relaunch-cap.ts +70 -0
  765. package/scripts/run/ship/run-ship-removed-rows.ts +61 -0
  766. package/scripts/run/ship/run-ship-return.ts +123 -15
  767. package/scripts/run/ship/run-ship-review-steps.ts +105 -149
  768. package/scripts/run/ship/run-ship-review.ts +73 -6
  769. package/scripts/run/ship/run-ship-reviewer.ts +207 -0
  770. package/scripts/run/ship/run-ship-stage.ts +55 -6
  771. package/scripts/run/ship/run-ship-steps.ts +46 -15
  772. package/scripts/run/ship/run-ship-stop-cause.ts +135 -0
  773. package/scripts/run/ship/run-ship-stop-context.ts +206 -0
  774. package/scripts/run/ship/run-ship-stop-text.ts +11 -6
  775. package/scripts/run/ship/run-ship-sync.ts +57 -12
  776. package/scripts/run/ship/run-ship.ts +30 -2
  777. package/scripts/run/tidy/run-tidy-cli.ts +0 -4
  778. package/scripts/run/tidy/run-tidy-lanes.ts +3 -0
  779. package/scripts/run/tidy/run-tidy-main.ts +8 -0
  780. package/scripts/run/wake/run-wake-cli.ts +119 -100
  781. package/scripts/run/wake/run-wake-code.ts +83 -0
  782. package/scripts/run/wake/run-wake-driver.ts +19 -8
  783. package/scripts/run/wake/run-wake-loop.ts +34 -3
  784. package/scripts/run/wake/run-wake-main.ts +13 -0
  785. package/scripts/run/wake/run-wake-ports.ts +90 -0
  786. package/scripts/run/wake/run-wake-takeover.ts +66 -0
  787. package/scripts/run/wake/run-wake.ts +2 -1
  788. package/scripts/safe-chain/pack-hook.ts +2 -2
  789. package/scripts/safe-chain/preinstall-command.ts +2 -1
  790. package/scripts/safe-chain/project-config.ts +3 -9
  791. package/scripts/security/security-audit-main.ts +8 -0
  792. package/scripts/security/security-audit-provision-logic.ts +0 -11
  793. package/scripts/security/security-audit-provision-main.ts +12 -0
  794. package/scripts/security/security-audit-provision.ts +11 -26
  795. package/scripts/security/security-audit.ts +6 -7
  796. package/scripts/self-sync-guard/self-sync-guard-logic.ts +6 -13
  797. package/scripts/split/split-assess-cli.ts +2 -2
  798. package/scripts/split/split-assess.ts +15 -0
  799. package/scripts/split/split-measure.ts +65 -0
  800. package/scripts/sync/claude-settings-merge.ts +8 -15
  801. package/scripts/sync/directory-copy-guard.ts +4 -9
  802. package/scripts/sync/file-content.ts +78 -8
  803. package/scripts/sync/sync-ai-files.ts +3 -5
  804. package/scripts/sync/sync-configs.ts +11 -23
  805. package/scripts/sync/sync-hook-safety.ts +4 -10
  806. package/scripts/sync/sync-main.ts +11 -0
  807. package/scripts/sync/sync.ts +25 -37
  808. package/scripts/test/test-declared-changed.ts +2 -2
  809. package/scripts/test/test-declared.ts +1 -1
  810. package/scripts/test/test-e2e-guard.ts +55 -6
  811. package/scripts/test/test-e2e-stamp.ts +38 -0
  812. package/scripts/test/test-pinned-logic.ts +145 -0
  813. package/scripts/test/test-pinned-main.ts +78 -0
  814. package/scripts/test/test-pinned.ts +100 -0
  815. package/scripts/test/test-read-map.ts +264 -0
  816. package/scripts/test/test-read-recording.ts +91 -0
  817. package/scripts/test/test-read-trace.ts +148 -0
  818. package/scripts/test/test-red-main.ts +12 -0
  819. package/scripts/test/test-red.ts +12 -30
  820. package/scripts/test/test-related-main.ts +18 -0
  821. package/scripts/test/test-related-record.ts +119 -0
  822. package/scripts/test/test-related-scope.ts +229 -43
  823. package/scripts/test/test-related.ts +300 -22
  824. package/scripts/test/test-unit-guard-main.ts +15 -0
  825. package/scripts/test/test-unit-guard.ts +54 -21
  826. package/scripts/test/unit-count-file.ts +37 -0
  827. package/scripts/test/unit-run-marker.ts +162 -0
  828. package/scripts/test/unit-setup-files.ts +51 -0
  829. package/scripts/test/unit-worker-share.ts +71 -137
  830. package/scripts/test/whole-suite-files.ts +63 -0
  831. package/scripts/time-runtime/time-background.ts +20 -2
  832. package/scripts/time-runtime/time-bundles.ts +4 -3
  833. package/scripts/time-runtime/time-density-hook.ts +8 -6
  834. package/scripts/time-runtime/time-followup-stage.ts +1 -3
  835. package/scripts/time-runtime/time-format.ts +5 -28
  836. package/scripts/time-runtime/time-markers.ts +10 -1
  837. package/scripts/time-runtime/time-shell.ts +126 -14
  838. package/scripts/time-runtime/time-spans.ts +1 -0
  839. package/scripts/time-runtime/time-tool-call.ts +7 -0
  840. package/scripts/time-runtime/time-transcript-line.ts +49 -62
  841. package/scripts/uninstall/uninstall.ts +1 -1
  842. package/scripts/version/bump-version-main.ts +12 -0
  843. package/scripts/version/bump-version.ts +25 -25
  844. package/scripts/version/effective-upstream.ts +6 -12
  845. package/scripts/version/latest-corepack.ts +17 -32
  846. package/scripts/version/latest-if-required-cli.ts +93 -0
  847. package/scripts/version/latest-lane-guard-main.ts +8 -0
  848. package/scripts/version/latest-lane-guard.ts +0 -4
  849. package/scripts/version/latest-scope-cli.ts +0 -9
  850. package/scripts/version/latest-scope-main.ts +12 -0
  851. package/scripts/version/latest-update.ts +5 -5
  852. package/scripts/version/npm-registry.ts +44 -6
  853. package/scripts/version/publishable-range-check.ts +5 -16
  854. package/scripts/version/release-age.ts +1 -1
  855. package/scripts/version/release-hold.ts +1 -1
  856. package/scripts/version/release-window.ts +38 -0
  857. package/scripts/version/running-binary.ts +1 -1
  858. package/scripts/version/safe-chain-version-update.ts +3 -8
  859. package/scripts/version/version-targets.ts +6 -28
  860. package/templates/dependabot.yml +29 -0
  861. package/templates/gitignore +10 -3
  862. package/templates/pnpm-workspace.basic.yaml +1 -1
  863. package/templates/sonar-project.properties +3 -2
  864. package/templates/workflows/ci.yml +12 -4
  865. package/templates/workflows/github-release.yml +4 -0
  866. package/tsconfig.sonar.json +1 -1
  867. package/.ncurc.json +0 -3
  868. package/dist/hooks/batch-guard.js +0 -29
  869. package/dist/hooks/chunk-43ZHT22P.js +0 -3495
  870. package/dist/hooks/chunk-CDY4NFQG.js +0 -15
  871. package/dist/hooks/chunk-EUMACUK2.js +0 -2038
  872. package/dist/hooks/chunk-H5HVWYXK.js +0 -359
  873. package/dist/hooks/chunk-IIGFYXKC.js +0 -7104
  874. package/dist/hooks/chunk-IX6TTTI6.js +0 -95
  875. package/dist/hooks/chunk-J47HU5H5.js +0 -237
  876. package/dist/hooks/chunk-K4EOONYM.js +0 -45
  877. package/dist/hooks/chunk-K4LMBQC2.js +0 -68
  878. package/dist/hooks/chunk-SHGPANFB.js +0 -56
  879. package/dist/hooks/chunk-YHBZAJSV.js +0 -79
  880. package/dist/hooks/chunk-YYPI7SJZ.js +0 -131
  881. package/dist/hooks/duplicate-read-guard.js +0 -30
  882. package/dist/hooks/investigation-guard.js +0 -32
  883. package/scripts/backlog/backlog-stalled-cli.ts +0 -30
  884. package/scripts/cost-runtime/cost-format.ts +0 -29
  885. package/scripts/init/basic-path-migration.ts +0 -24
  886. package/scripts/issue/issue-backlinks-cli.ts +0 -93
  887. package/scripts/josh/josh-commands-guard.ts +0 -38
  888. package/scripts/lint/cross-file-recheck.ts +0 -155
  889. package/scripts/registry-migration/migrate-logic.ts +0 -237
  890. package/scripts/registry-migration/migrate.ts +0 -292
  891. package/scripts/registry-migration/user-npmrc.ts +0 -15
  892. package/scripts/rules/rule-guard.ts +0 -23
  893. package/scripts/rules/rule-registry-rows.ts +0 -282
  894. package/scripts/rules/rule-registry.ts +0 -109
  895. package/scripts/run/run-stranded-cli.ts +0 -27
@@ -1,3495 +0,0 @@
1
- import {
2
- agent_role_profile,
3
- detached_launch,
4
- git_common_directory,
5
- issue_cite,
6
- lane_child_invocation,
7
- repo_discovery,
8
- repo_origin,
9
- run_event_stream,
10
- run_event_stream_emit
11
- } from "./chunk-EUMACUK2.js";
12
- import {
13
- error_text
14
- } from "./chunk-CDY4NFQG.js";
15
- import {
16
- CHECK_STATUS_FAIL,
17
- CHECK_STATUS_PENDING,
18
- PrConflictError,
19
- blocking_issue_schema,
20
- cost_blocks,
21
- describe_pr_failure,
22
- evaluate_pr_state,
23
- is_coderabbit_check,
24
- is_merge_conflict,
25
- is_required_check,
26
- is_review_decision_decisive,
27
- parse_pr_state_snapshot,
28
- read_string,
29
- rest_comment_schema,
30
- time_density_hook,
31
- time_shell,
32
- time_transcript_line
33
- } from "./chunk-AS74OU3D.js";
34
- import {
35
- lane_child_marker
36
- } from "./chunk-K4EOONYM.js";
37
- import {
38
- agent_session_environment,
39
- backlog_budget,
40
- cost_usage,
41
- git_command,
42
- has_timed_out,
43
- json_value,
44
- process_identity
45
- } from "./chunk-E7OIKX5Z.js";
46
- import {
47
- COMMAND_TIMEOUT_MS,
48
- PROJECT_ROOT,
49
- stamp_file
50
- } from "./chunk-DGT54IH5.js";
51
-
52
- // scripts/lib/bounded-pool.ts
53
- function pool_width(limit, total) {
54
- if (!Number.isFinite(limit)) return 1;
55
- return Math.max(1, Math.min(Math.floor(limit), total));
56
- }
57
- function throw_first_failure(failures) {
58
- if (failures.length === 0) return;
59
- const [first] = failures;
60
- throw first;
61
- }
62
- async function drain(pool, worker) {
63
- for (let entry = pool.queue.shift(); entry !== void 0 && pool.failures.length === 0; entry = pool.queue.shift()) {
64
- const [index, item] = entry;
65
- try {
66
- pool.results.push({ index, value: await worker(item, index) });
67
- } catch (error) {
68
- pool.failures.push(error);
69
- }
70
- }
71
- }
72
- async function bounded_map(items, limit, worker) {
73
- const pool = {
74
- failures: [],
75
- queue: items.map((item, index) => [index, item]),
76
- results: []
77
- };
78
- const consumers = Array.from({ length: pool_width(limit, items.length) }, async () => {
79
- await drain(pool, worker);
80
- });
81
- await Promise.all(consumers);
82
- throw_first_failure(pool.failures);
83
- return pool.results.toSorted((left, right) => left.index - right.index).map((result) => result.value);
84
- }
85
- var bounded_pool = { bounded_map, pool_width };
86
-
87
- // scripts/rules/shell-segments.ts
88
- var SEGMENT_SEPARATOR = /&&|\|\||;|\n/u;
89
- var SEGMENT_PARTS = new RegExp(`(${SEGMENT_SEPARATOR.source})`, "u");
90
- function segments_of(command) {
91
- return command.split(SEGMENT_SEPARATOR).map((segment) => segment.trim());
92
- }
93
- function parts_of(command) {
94
- return command.split(SEGMENT_PARTS);
95
- }
96
- function is_josh_command(segment, names) {
97
- const named = time_shell.josh_command_of(segment);
98
- if (!named.startsWith(time_shell.JOSH_PREFIX)) return false;
99
- return names.has(named.slice(time_shell.JOSH_PREFIX.length));
100
- }
101
- var shell_segments = {
102
- is_josh_command,
103
- parts_of,
104
- segments_of
105
- };
106
-
107
- // scripts/rules/bash-triggers.ts
108
- function on_bash_command(is_match) {
109
- return function is_trigger(call) {
110
- if (call.name !== cost_blocks.BASH_TOOL) return false;
111
- return is_match(time_shell.bash_command(call.input));
112
- };
113
- }
114
- var ISSUE_CREATE_COMMAND = /\bgh\s+(?:\S+\s+)*?issue\s+create\b/u;
115
- var ISSUES_ENDPOINT = /repos\/[^\s'"]*\/issues(?=$|["'\s])/u;
116
- var TITLE_FIELD = /(?:-f|-F|--field|--raw-field)\s*'?title=/u;
117
- function is_direct_filing(command) {
118
- if (ISSUE_CREATE_COMMAND.test(command)) return true;
119
- return ISSUES_ENDPOINT.test(command) && TITLE_FIELD.test(command);
120
- }
121
- var FILING_NAMES = /* @__PURE__ */ new Set(["issue:file"]);
122
- function is_issue_filing(command) {
123
- return shell_segments.segments_of(command).some((segment) => shell_segments.is_josh_command(segment, FILING_NAMES));
124
- }
125
- var bash_triggers = { is_direct_filing, is_issue_filing, on_bash_command };
126
-
127
- // scripts/rules/tail-commands.ts
128
- function is_bash_use(block) {
129
- return block.type === cost_blocks.TOOL_USE_TYPE && block.name === cost_blocks.BASH_TOOL;
130
- }
131
- function bash_commands_of(line) {
132
- const parsed = time_transcript_line.parse_line(line);
133
- if (parsed === void 0) return [];
134
- return parsed.blocks.filter((block) => is_bash_use(block)).map((block) => time_shell.bash_command(block.input));
135
- }
136
- function prior_bash_commands(tail) {
137
- return tail.split("\n").flatMap((line) => bash_commands_of(line));
138
- }
139
- var tail_commands = { is_bash_use, prior_bash_commands };
140
-
141
- // scripts/rules/filing-cap.ts
142
- var FILING_CAP = 10;
143
- var CAP_REACHED = FILING_CAP;
144
- function is_filing_use(block) {
145
- if (!tail_commands.is_bash_use(block)) return false;
146
- return bash_triggers.is_issue_filing(time_shell.bash_command(block.input));
147
- }
148
- function collect_block(block, found) {
149
- if (block.result_id !== "" && block.is_error === true) found.failures.add(block.result_id);
150
- if (is_filing_use(block)) found.filing_ids.push(block.id);
151
- }
152
- function collect_line(line, found) {
153
- const parsed = time_transcript_line.parse_line(line);
154
- if (parsed === void 0) return;
155
- for (const block of parsed.blocks) collect_block(block, found);
156
- }
157
- function scan_tail(tail) {
158
- const found = { filing_ids: [], failures: /* @__PURE__ */ new Set() };
159
- for (const line of tail.split("\n")) collect_line(line, found);
160
- return found;
161
- }
162
- function prior_filing_count(tail) {
163
- const { filing_ids, failures } = scan_tail(tail);
164
- return filing_ids.filter((id) => !failures.has(id)).length;
165
- }
166
- function is_prompt_line(line) {
167
- const parsed = time_transcript_line.parse_line(line);
168
- if (parsed?.type !== "user") return false;
169
- return parsed.blocks.every((block) => block.result_id === "");
170
- }
171
- function current_turn(tail) {
172
- const lines = tail.split("\n");
173
- const start = lines.findLastIndex((line) => is_prompt_line(line));
174
- return lines.slice(Math.max(start, 0)).join("\n");
175
- }
176
- function turn_filing_count(tail) {
177
- return prior_filing_count(current_turn(tail));
178
- }
179
- function decide(_call, run) {
180
- return prior_filing_count(time_density_hook.read_tail(run.transcript)) >= CAP_REACHED;
181
- }
182
- var FILING_CAP_REASON = `\u26D4 filing cap: this run has already filed ${String(FILING_CAP)} Issues, the per-run ceiling. Stop filing and report; a further Issue is a person's call. It fires on every occurrence (\`.claude/skills/workflow-commands/observation-filing.md\`).`;
183
- var ROW = {
184
- id: "filing-cap",
185
- is_trigger: bash_triggers.on_bash_command(bash_triggers.is_issue_filing),
186
- reason: FILING_CAP_REASON,
187
- decide
188
- };
189
- var filing_cap = {
190
- FILING_CAP,
191
- FILING_CAP_REASON,
192
- ROW,
193
- is_prompt_line,
194
- prior_filing_count,
195
- turn_filing_count
196
- };
197
-
198
- // scripts/rules/issue-citation.ts
199
- var ISSUE_NUMBER = /#\d+/gu;
200
- var REFERENCE_BOUNDARY = /[\s#()[\]<>|]/u;
201
- var OWNER_REPO = /^[^\s/#]+\/[^\s/#]+$/u;
202
- var MARKDOWN_LINK = /\[[^[\]]*\]\([^()]*\)/gu;
203
- var NUMBER_CONTINUATION = /^(?:\w|-[a-z])/iu;
204
- var CONTINUATION_WIDTH = 2;
205
- var GLUED_LEAD = /[&./]/u;
206
- var FENCE_MARKER = /^\s*(?:`{3,}|~{3,})/u;
207
- var QUOTE_LINE = /^\s*>/u;
208
- var PR_PREFIX = /\b(?:pr|pull request)\s*$/iu;
209
- var BACKTICK_PAIR = 2;
210
- function link_covers(link, index) {
211
- const start = link.index ?? 0;
212
- return index >= start && index < start + link[0].length;
213
- }
214
- function is_linked_at(line, index) {
215
- for (const link of line.matchAll(MARKDOWN_LINK)) {
216
- if (link_covers(link, index)) return true;
217
- }
218
- return false;
219
- }
220
- function lead_token(message, hash_index) {
221
- let start = hash_index;
222
- while (start > 0 && !REFERENCE_BOUNDARY.test(message.charAt(start - 1))) start -= 1;
223
- return message.slice(start, hash_index);
224
- }
225
- function repo_prefix(message, hash_index) {
226
- const token = lead_token(message, hash_index);
227
- return OWNER_REPO.test(token) ? token : "";
228
- }
229
- function is_inline_code_at(line, index) {
230
- const backticks = line.slice(0, index).split("`").length - 1;
231
- return backticks % BACKTICK_PAIR === 1;
232
- }
233
- function is_bare_at(line, index) {
234
- if (is_linked_at(line, index) || is_inline_code_at(line, index)) return false;
235
- return !PR_PREFIX.test(line.slice(0, index));
236
- }
237
- function is_glued(line, reference) {
238
- const end = reference.index + reference.text.length;
239
- if (NUMBER_CONTINUATION.test(line.slice(end, end + CONTINUATION_WIDTH))) return true;
240
- return reference.prefix === "" && GLUED_LEAD.test(lead_token(line, reference.index));
241
- }
242
- function line_references(line) {
243
- const references = [];
244
- for (const match of line.matchAll(ISSUE_NUMBER)) {
245
- const reference = { index: match.index, prefix: repo_prefix(line, match.index), text: match[0] };
246
- if (!is_glued(line, reference) && is_bare_at(line, match.index)) references.push(reference);
247
- }
248
- return references;
249
- }
250
- function collect_line_references(line, found) {
251
- for (const reference of line_references(line)) found.push(`${reference.prefix}${reference.text}`);
252
- }
253
- function lines_outside_fences(message) {
254
- const lines = [];
255
- let is_in_fence = false;
256
- for (const line of message.split("\n")) {
257
- if (FENCE_MARKER.test(line)) is_in_fence = !is_in_fence;
258
- else if (!is_in_fence) lines.push(line);
259
- }
260
- return lines;
261
- }
262
- function prose_lines(message) {
263
- return lines_outside_fences(message).filter((line) => !QUOTE_LINE.test(line));
264
- }
265
- function bare_references(message) {
266
- const found = [];
267
- for (const line of prose_lines(message)) collect_line_references(line, found);
268
- return [...new Set(found)];
269
- }
270
- function prompt_references(prompt) {
271
- const found = /* @__PURE__ */ new Set();
272
- for (const match of prompt.matchAll(ISSUE_NUMBER)) {
273
- found.add(repo_prefix(prompt, match.index) + match[0]);
274
- }
275
- return found;
276
- }
277
- function unquoted_references(message, prompt) {
278
- const quoted = prompt_references(prompt);
279
- return bare_references(message).filter((reference) => !quoted.has(reference));
280
- }
281
- function has_bare_reference(message) {
282
- return bare_references(message).length > 0;
283
- }
284
- function cite_argument(reference) {
285
- return reference.startsWith("#") ? reference.slice(1) : reference;
286
- }
287
- function cite_arguments(references) {
288
- return references.map((reference) => cite_argument(reference));
289
- }
290
- function reference_link(reference, default_slug) {
291
- const slug = reference.prefix === "" ? default_slug : reference.prefix;
292
- const number = reference.text.slice(1);
293
- return `[${reference.prefix}${reference.text}](${issue_cite.issue_url(slug, number)})`;
294
- }
295
- function linkify_line(line, slug) {
296
- let result = "";
297
- let cursor = 0;
298
- for (const reference of line_references(line)) {
299
- const start = reference.index - reference.prefix.length;
300
- result += line.slice(cursor, start) + reference_link(reference, slug);
301
- cursor = reference.index + reference.text.length;
302
- }
303
- return result + line.slice(cursor);
304
- }
305
- function rewrite_line(line, slug, is_in_fence) {
306
- if (is_in_fence || FENCE_MARKER.test(line) || QUOTE_LINE.test(line)) return line;
307
- return linkify_line(line, slug);
308
- }
309
- function linkify(message, slug) {
310
- const out = [];
311
- let is_in_fence = false;
312
- for (const line of message.split("\n")) {
313
- if (FENCE_MARKER.test(line)) is_in_fence = !is_in_fence;
314
- out.push(rewrite_line(line, slug, is_in_fence));
315
- }
316
- return out.join("\n");
317
- }
318
- var issue_citation = {
319
- bare_references,
320
- cite_arguments,
321
- has_bare_reference,
322
- linkify,
323
- prose_lines,
324
- unquoted_references
325
- };
326
-
327
- // scripts/issue/session-cite.ts
328
- function session_repo() {
329
- const url = repo_discovery.read_origin_url(process.cwd());
330
- const identity = url === void 0 ? void 0 : repo_origin.parse_origin_url(url);
331
- return identity === void 0 ? void 0 : `${identity.owner}/${identity.repo}`;
332
- }
333
- function issue(number, title, repo = session_repo()) {
334
- return issue_cite.reference(repo, String(number), title);
335
- }
336
- function text(message) {
337
- const repo = session_repo();
338
- return repo === void 0 ? message : issue_citation.linkify(message, repo);
339
- }
340
- var session_cite = {
341
- issue,
342
- session_repo,
343
- text
344
- };
345
-
346
- // scripts/josh/stamp-record.ts
347
- var NONE_READ = { kind: "none" };
348
- var UNREADABLE_READ = { kind: "unreadable" };
349
- function is_older_than(iso, max_age_ms, now) {
350
- const at = Date.parse(iso);
351
- if (Number.isNaN(at)) return true;
352
- return now.getTime() - at > max_age_ms;
353
- }
354
- function classify(raw, spec, now) {
355
- if (raw === void 0) return NONE_READ;
356
- const record = spec.parse(raw);
357
- if (record === void 0) return UNREADABLE_READ;
358
- const is_expired3 = is_older_than(spec.timestamp_of(record), spec.max_age_ms, now);
359
- return { kind: is_expired3 ? "expired" : "carried", record };
360
- }
361
- var stamp_record = { classify, is_older_than };
362
-
363
- // scripts/run/hold/run-hold.ts
364
- import { z } from "zod";
365
- var HOLD_PREFIX = "josh-run-hold-";
366
- var UNNUMBERED_ISSUE = "new";
367
- var HOLD_MAX_AGE_HOURS = 8;
368
- var MILLISECONDS_PER_HOUR = 36e5;
369
- var HOLD_MAX_AGE_MS = HOLD_MAX_AGE_HOURS * MILLISECONDS_PER_HOUR;
370
- var RELEASE_COMMAND = "pnpm josh run:release";
371
- var FORCE_RELEASE_COMMAND = `${RELEASE_COMMAND} --force`;
372
- var NOT_IDLE = 'that is not "nothing is running here"';
373
- var FREE_READ = { kind: "free" };
374
- var UNREADABLE_READ2 = { kind: "unreadable" };
375
- function hold_path(git_directory) {
376
- return stamp_file.stamp_path(HOLD_PREFIX, git_directory);
377
- }
378
- async function worktree_directory() {
379
- const directories = await git_command.git_directories();
380
- return directories[0];
381
- }
382
- async function is_linked_worktree() {
383
- const directories = await git_command.git_directories();
384
- return directories[0] !== void 0 && directories[0] !== directories[1];
385
- }
386
- var run_hold_schema = z.object({
387
- issue: z.string(),
388
- taken_at: z.string(),
389
- pid: z.number(),
390
- is_fullrun: z.boolean().optional(),
391
- is_halfrun_stop: z.boolean().optional(),
392
- prrun_stop_head: z.string().optional(),
393
- owner_pid: z.number().optional(),
394
- owner_start: z.string().optional()
395
- });
396
- function parse_hold(raw) {
397
- return json_value.parse_with(raw, run_hold_schema);
398
- }
399
- function is_expired(hold, now) {
400
- return stamp_record.is_older_than(hold.taken_at, HOLD_MAX_AGE_MS, now);
401
- }
402
- function is_stop_marked(hold) {
403
- return hold.is_halfrun_stop === true || hold.prrun_stop_head !== void 0;
404
- }
405
- function is_owner_gone(hold) {
406
- if (is_stop_marked(hold) || hold.owner_pid === void 0) return false;
407
- return process_identity.is_same_process(hold.owner_pid, hold.owner_start) === false;
408
- }
409
- function is_stale(hold, now) {
410
- return is_expired(hold, now) || is_owner_gone(hold);
411
- }
412
- function classify2(raw, now) {
413
- if (raw === void 0) return FREE_READ;
414
- const hold = parse_hold(raw);
415
- if (hold === void 0) return UNREADABLE_READ2;
416
- return { kind: is_stale(hold, now) ? "stale" : "held", hold };
417
- }
418
- function read_hold(target, now = /* @__PURE__ */ new Date()) {
419
- return classify2(stamp_file.read_stamp_text(target), now);
420
- }
421
- function session_owner(environment = process.env) {
422
- const pid = Number(environment[agent_session_environment.AGENT_PID_KEY]);
423
- if (!Number.isSafeInteger(pid) || pid <= 0) return {};
424
- return { owner_pid: pid, owner_start: process_identity.read_start(pid) };
425
- }
426
- function build_hold(issue2, now, is_fullrun) {
427
- return { issue: issue2, taken_at: now.toISOString(), pid: process.pid, is_fullrun, ...session_owner() };
428
- }
429
- function write_hold(target, issue2, now = /* @__PURE__ */ new Date()) {
430
- const hold = build_hold(issue2, now);
431
- stamp_file.write_stamp(target, hold);
432
- return hold;
433
- }
434
- function create_hold(target, issue2, now = /* @__PURE__ */ new Date(), is_fullrun) {
435
- return stamp_file.create_stamp(target, build_hold(issue2, now, is_fullrun));
436
- }
437
- var HALFRUN_STOP_FIELDS = { is_halfrun_stop: true };
438
- function create_stop_hold(target, issue2, mark, now = /* @__PURE__ */ new Date()) {
439
- return stamp_file.create_stamp(target, { ...build_hold(issue2, now), ...mark });
440
- }
441
- function create_halfrun_stop_hold(target, issue2, now = /* @__PURE__ */ new Date()) {
442
- return create_stop_hold(target, issue2, HALFRUN_STOP_FIELDS, now);
443
- }
444
- async function is_tree_dirty(directory) {
445
- try {
446
- const status = await git_command.status(directory);
447
- return status.trim() !== "";
448
- } catch (error) {
449
- error_text.trace_swallowed("run_hold.is_tree_dirty", error);
450
- return true;
451
- }
452
- }
453
- function release_hold(target) {
454
- stamp_file.remove_stamp(target);
455
- }
456
- function describe_holder(hold) {
457
- const holder = hold.issue === UNNUMBERED_ISSUE ? "an unnumbered run" : session_cite.issue(hold.issue);
458
- return `${holder}, recorded ${hold.taken_at} (pid ${String(hold.owner_pid ?? hold.pid)})`;
459
- }
460
- function own_release_command(issue2) {
461
- return issue2 === UNNUMBERED_ISSUE ? RELEASE_COMMAND : `${RELEASE_COMMAND} ${issue2}`;
462
- }
463
- function is_own_hold(hold, claimant) {
464
- return hold.issue === claimant;
465
- }
466
- function is_reentry(hold, claimant) {
467
- return claimant !== UNNUMBERED_ISSUE && is_own_hold(hold, claimant);
468
- }
469
- function held_message(hold) {
470
- return `This working tree is already held by ${describe_holder(hold)}. One run at a time per working tree: a second run here commits its files onto the other run's branch. If that record is stale, run \`${FORCE_RELEASE_COMMAND}\` in this working tree \u2014 it removes a record this run did not write, so be sure the run that did has ended \u2014 and ask again.`;
471
- }
472
- function foreign_release_message(hold) {
473
- return `This working tree is held by ${describe_holder(hold)}, and this release did not claim it \u2014 nothing was removed. Release it as that run with \`${own_release_command(hold.issue)}\`, or, once you are sure it has ended, remove the record with \`${FORCE_RELEASE_COMMAND}\`.`;
474
- }
475
- function forced_release_message(hold) {
476
- return `Forced: removed the run record held by ${describe_holder(hold)}.`;
477
- }
478
- function unreadable_message() {
479
- return `This working tree's run record could not be read \u2014 ${NOT_IDLE}. Run \`${FORCE_RELEASE_COMMAND}\` in this working tree to clear it, then ask again.`;
480
- }
481
- function stale_message(hold) {
482
- const why = is_owner_gone(hold) ? "the session that wrote it has ended" : `older than ${String(HOLD_MAX_AGE_HOURS)} hours`;
483
- return `Replaced a stale run record held by ${describe_holder(hold)}: ${why}, so the run that wrote it has ended without releasing it.`;
484
- }
485
- function uncommitted_message(hold) {
486
- return `This working tree still has uncommitted changes, and its run record \u2014 held by ${describe_holder(hold)} \u2014 has expired or outlived its session. That is a run which stopped for a person rather than one that finished, so the tree is not free: commit or stash the work, or run \`${own_release_command(hold.issue)}\` once you are done with it, then ask again.`;
487
- }
488
- function race_message(read, target) {
489
- if (read.kind === "held") return held_message(read.hold);
490
- return `A record already exists at ${target} and this run did not write it \u2014 ${NOT_IDLE}. Either another run claimed the tree at the same moment, or the record belongs to another account. Run \`${FORCE_RELEASE_COMMAND}\`, and remove that file by hand if it is still there.`;
491
- }
492
- function unknown_message() {
493
- return `Could not read this working tree's git directory \u2014 ${NOT_IDLE}. Run this from inside the checkout the run will edit.`;
494
- }
495
- var run_hold = {
496
- is_stop_marked,
497
- FORCE_RELEASE_COMMAND,
498
- HOLD_MAX_AGE_HOURS,
499
- HOLD_MAX_AGE_MS,
500
- RELEASE_COMMAND,
501
- UNNUMBERED_ISSUE,
502
- classify: classify2,
503
- create_halfrun_stop_hold,
504
- create_stop_hold,
505
- HALFRUN_STOP_FIELDS,
506
- create_hold,
507
- foreign_release_message,
508
- forced_release_message,
509
- held_message,
510
- hold_path,
511
- is_linked_worktree,
512
- is_own_hold,
513
- is_reentry,
514
- is_tree_dirty,
515
- own_release_command,
516
- race_message,
517
- read_hold,
518
- release_hold,
519
- stale_message,
520
- uncommitted_message,
521
- unknown_message,
522
- unreadable_message,
523
- worktree_directory,
524
- write_hold
525
- };
526
-
527
- // scripts/cost-runtime/cost-pricing.ts
528
- var CACHE_WRITE_5M_MULTIPLIER = 1.25;
529
- var CACHE_WRITE_1H_MULTIPLIER = 2;
530
- var DEFAULT_CACHE_READ_MULTIPLIER = 0.1;
531
- var HALVED_CACHE_READ_MULTIPLIER = 0.05;
532
- var QUARTERED_CACHE_READ_MULTIPLIER = 0.025;
533
- var TOKENS_PER_MILLION = 1e6;
534
- var LONG_PROMPT_SUFFIX = ":long-prompt";
535
- var LONG_PROMPT_THRESHOLD = 1e5;
536
- var MODEL_PRICES = {
537
- "claude-fable-5-1": {
538
- input: 10,
539
- output: 50,
540
- cache_read_multiplier: QUARTERED_CACHE_READ_MULTIPLIER
541
- },
542
- "claude-mythos-5-1": {
543
- input: 10,
544
- output: 50,
545
- cache_read_multiplier: QUARTERED_CACHE_READ_MULTIPLIER
546
- },
547
- "claude-fable-5": { input: 10, output: 50 },
548
- "claude-mythos-5": { input: 10, output: 50 },
549
- "claude-opus-5-5": { input: 4, output: 20, cache_read_multiplier: HALVED_CACHE_READ_MULTIPLIER },
550
- "claude-opus-5": { input: 5, output: 25 },
551
- "claude-opus-4-8": { input: 5, output: 25 },
552
- "claude-opus-4-7": { input: 5, output: 25 },
553
- "claude-opus-4-6": { input: 5, output: 25 },
554
- "claude-sonnet-5-5": {
555
- input: 2,
556
- output: 10,
557
- cache_read_multiplier: HALVED_CACHE_READ_MULTIPLIER
558
- },
559
- "claude-sonnet-5": { input: 2, output: 10 },
560
- "claude-sonnet-4-6": { input: 3, output: 15 },
561
- "claude-haiku-5-5": { input: 0.1, output: 0.5 },
562
- [`claude-haiku-5-5${LONG_PROMPT_SUFFIX}`]: { input: 0.5, output: 2.5 },
563
- "claude-haiku-4-5": { input: 1, output: 5 }
564
- };
565
- var CONTEXT_MARKER = "[";
566
- var DATE_SUFFIX = /-\d{8}$/u;
567
- function known_id(model) {
568
- const base = model.split(CONTEXT_MARKER)[0] ?? model;
569
- return [base, base.replace(DATE_SUFFIX, "")].find((id) => Object.hasOwn(MODEL_PRICES, id));
570
- }
571
- function resolve_price(model) {
572
- const id = known_id(model);
573
- return id === void 0 ? void 0 : MODEL_PRICES[id];
574
- }
575
- function cache_read_multiplier(price) {
576
- return price.cache_read_multiplier ?? DEFAULT_CACHE_READ_MULTIPLIER;
577
- }
578
- function estimate_cost(totals, price) {
579
- const weighted_input = totals.input_tokens + totals.cache_write_5m_tokens * CACHE_WRITE_5M_MULTIPLIER + totals.cache_write_1h_tokens * CACHE_WRITE_1H_MULTIPLIER + totals.cache_read_tokens * cache_read_multiplier(price);
580
- return (weighted_input * price.input + totals.output_tokens * price.output) / TOKENS_PER_MILLION;
581
- }
582
- function priced(tokens, rate) {
583
- return tokens * rate / TOKENS_PER_MILLION;
584
- }
585
- function estimate_composition(totals, price) {
586
- return {
587
- input_usd: priced(totals.input_tokens, price.input),
588
- cache_write_5m_usd: priced(
589
- totals.cache_write_5m_tokens * CACHE_WRITE_5M_MULTIPLIER,
590
- price.input
591
- ),
592
- cache_write_1h_usd: priced(
593
- totals.cache_write_1h_tokens * CACHE_WRITE_1H_MULTIPLIER,
594
- price.input
595
- ),
596
- cache_read_usd: priced(totals.cache_read_tokens * cache_read_multiplier(price), price.input),
597
- output_usd: priced(totals.output_tokens, price.output)
598
- };
599
- }
600
- function to_model_cost(model, totals) {
601
- const price = resolve_price(model);
602
- if (price === void 0) return { model, totals };
603
- return { model, totals, cost_usd: estimate_cost(totals, price) };
604
- }
605
- function billed_model(usage) {
606
- const long_id = `${known_id(usage.model) ?? usage.model}${LONG_PROMPT_SUFFIX}`;
607
- const is_long = cost_usage.billed_input(usage.totals) > LONG_PROMPT_THRESHOLD;
608
- return is_long && Object.hasOwn(MODEL_PRICES, long_id) ? long_id : usage.model;
609
- }
610
- function cost_by_model(records) {
611
- const grouped = /* @__PURE__ */ new Map();
612
- for (const record of records) {
613
- const model = billed_model(record);
614
- const running = grouped.get(model) ?? cost_usage.EMPTY_TOTALS;
615
- grouped.set(model, cost_usage.add_totals(running, record.totals));
616
- }
617
- return [...grouped].map(([model, totals]) => to_model_cost(model, totals));
618
- }
619
- function total_cost(costs) {
620
- return {
621
- usd: costs.reduce((sum, entry) => sum + (entry.cost_usd ?? 0), 0),
622
- unpriced: costs.filter((entry) => entry.cost_usd === void 0).map((entry) => entry.model)
623
- };
624
- }
625
- function cost_of(records) {
626
- return total_cost(cost_by_model(records)).usd;
627
- }
628
- var cost_pricing = {
629
- CACHE_WRITE_5M_MULTIPLIER,
630
- CACHE_WRITE_1H_MULTIPLIER,
631
- DEFAULT_CACHE_READ_MULTIPLIER,
632
- LONG_PROMPT_THRESHOLD,
633
- resolve_price,
634
- estimate_cost,
635
- estimate_composition,
636
- cost_by_model,
637
- total_cost,
638
- cost_of
639
- };
640
-
641
- // scripts/cost-runtime/context-cut-payback.ts
642
- var POST_CUT_CONTEXT = 6e4;
643
- var EXPECTED_REMAINING_REQUESTS = 10;
644
- function write_over_read() {
645
- return cost_pricing.CACHE_WRITE_5M_MULTIPLIER / cost_pricing.DEFAULT_CACHE_READ_MULTIPLIER;
646
- }
647
- function break_even_context(remaining = EXPECTED_REMAINING_REQUESTS) {
648
- if (remaining <= 0) return Infinity;
649
- return Math.round(POST_CUT_CONTEXT * (1 + write_over_read() / remaining));
650
- }
651
- function break_even_requests(current_context) {
652
- const saved_per_request = current_context - POST_CUT_CONTEXT;
653
- if (saved_per_request <= 0) return Infinity;
654
- return POST_CUT_CONTEXT * write_over_read() / saved_per_request;
655
- }
656
- function pays_back(current_context, remaining = EXPECTED_REMAINING_REQUESTS) {
657
- return current_context > break_even_context(remaining);
658
- }
659
- var context_cut_payback = {
660
- POST_CUT_CONTEXT,
661
- EXPECTED_REMAINING_REQUESTS,
662
- break_even_context,
663
- break_even_requests,
664
- pays_back
665
- };
666
-
667
- // scripts/cost-runtime/context-cut-threshold.ts
668
- var CONTEXT_CUT_THRESHOLD = context_cut_payback.break_even_context();
669
-
670
- // scripts/run/cut/run-cut.ts
671
- import { z as z3 } from "zod";
672
-
673
- // scripts/run/cut/run-cut-handoff.ts
674
- import { readFileSync } from "node:fs";
675
- import { z as z2 } from "zod";
676
- var handoff_schema = z2.object({
677
- instruction: z2.string(),
678
- completed: z2.array(z2.string()),
679
- remaining: z2.array(z2.string()),
680
- untouched: z2.array(z2.string())
681
- });
682
- var COMPLETED_LABEL = "Completed";
683
- var REMAINING_LABEL = "Remaining";
684
- var UNTOUCHED_LABEL = "Deliberately untouched";
685
- var INSTRUCTION_LABEL = "Instruction (verbatim)";
686
- var EMPTY_LIST_NOTE = "(none)";
687
- function describe_key(key2) {
688
- const value = handoff_schema.shape[key2] instanceof z2.ZodArray ? '["\u2026"]' : '"\u2026"';
689
- return `"${key2}": ${value}`;
690
- }
691
- var HANDOFF_FORMAT = `a JSON object {${handoff_schema.keyof().options.map((key2) => describe_key(key2)).join(", ")}}`;
692
- function parse_handoff(raw) {
693
- return json_value.parse_with(raw, handoff_schema);
694
- }
695
- function read_handoff_file(handoff_path) {
696
- try {
697
- return parse_handoff(readFileSync(handoff_path, "utf8"));
698
- } catch {
699
- return void 0;
700
- }
701
- }
702
- function is_complete_handoff(handoff) {
703
- return handoff !== void 0 && handoff.instruction.trim() !== "";
704
- }
705
- function is_within_bound(handoff, max_bytes) {
706
- return Buffer.byteLength(JSON.stringify(handoff), "utf8") <= max_bytes;
707
- }
708
- function load_handoff(handoff_path, max_bytes) {
709
- if (handoff_path === void 0) return { kind: "ok", handoff: void 0 };
710
- const handoff = read_handoff_file(handoff_path);
711
- if (handoff === void 0) {
712
- return {
713
- kind: "bad",
714
- note: `--handoff ${handoff_path} is not a readable handoff file \u2014 write ${HANDOFF_FORMAT}`
715
- };
716
- }
717
- if (!is_within_bound(handoff, max_bytes)) {
718
- return { kind: "bad", note: `--handoff ${handoff_path} is too large to carry across the cut` };
719
- }
720
- return { kind: "ok", handoff };
721
- }
722
- function describe_list(label, items) {
723
- if (items.length === 0) return `${label}: ${EMPTY_LIST_NOTE}`;
724
- const bullets = items.map((item) => ` - ${item}`).join("\n");
725
- return `${label}:
726
- ${bullets}`;
727
- }
728
- function describe_handoff(handoff) {
729
- return [
730
- `${INSTRUCTION_LABEL}:
731
- ${handoff.instruction}`,
732
- describe_list(COMPLETED_LABEL, handoff.completed),
733
- describe_list(REMAINING_LABEL, handoff.remaining),
734
- describe_list(UNTOUCHED_LABEL, handoff.untouched)
735
- ].join("\n\n");
736
- }
737
- var HANDOFF_PATH = ".claude/tmp/handoff-<N>.json";
738
- var run_cut_handoff = {
739
- HANDOFF_FORMAT,
740
- HANDOFF_PATH,
741
- describe_handoff,
742
- handoff_schema,
743
- is_complete_handoff,
744
- load_handoff,
745
- parse_handoff,
746
- read_handoff_file
747
- };
748
-
749
- // scripts/run/cut/run-cut.ts
750
- var CUT_PREFIX = "josh-run-cut-";
751
- var { PRE_GATE_PHASE, IMPLEMENTATION_PHASE } = agent_role_profile;
752
- var IMPLEMENTATION_CONTEXT_THRESHOLD = CONTEXT_CUT_THRESHOLD;
753
- var CUT_MAX_AGE_MS = backlog_budget.DEFAULT_IDLE_MS;
754
- var CUT_MAX_AGE_HOURS = backlog_budget.IDLE_WAIT_HOURS;
755
- var END_COMMAND = "pnpm josh run:cut --end";
756
- var READ_COMMAND = "pnpm josh run:cut --json";
757
- var MAX_HANDOFF_BYTES = 8192;
758
- var run_cut_schema = z3.object({
759
- invocation: z3.string(),
760
- issue: z3.string(),
761
- branch: z3.string(),
762
- phase: z3.string(),
763
- cut_at: z3.string(),
764
- is_handed_off: z3.boolean().optional(),
765
- handoff: run_cut_handoff.handoff_schema.optional(),
766
- is_merge_relaunched: z3.boolean().optional()
767
- });
768
- function cut_path(git_directory) {
769
- return stamp_file.stamp_path(CUT_PREFIX, git_directory);
770
- }
771
- var { worktree_directory: worktree_directory2 } = run_hold;
772
- function invocation_for(issue2) {
773
- return lane_child_invocation.child_invocation(issue2);
774
- }
775
- function parse_cut(raw) {
776
- return json_value.parse_with(raw, run_cut_schema);
777
- }
778
- function cut_at_of(cut) {
779
- return cut.cut_at;
780
- }
781
- var CUT_SPEC = {
782
- parse: parse_cut,
783
- timestamp_of: cut_at_of,
784
- max_age_ms: CUT_MAX_AGE_MS
785
- };
786
- function is_expired2(cut, now) {
787
- return stamp_record.is_older_than(cut_at_of(cut), CUT_MAX_AGE_MS, now);
788
- }
789
- function classify3(raw, now) {
790
- const read = stamp_record.classify(raw, CUT_SPEC, now);
791
- if (!("record" in read)) return read;
792
- return { kind: read.kind, cut: read.record };
793
- }
794
- function read_cut(target, now = /* @__PURE__ */ new Date()) {
795
- return classify3(stamp_file.read_stamp_text(target), now);
796
- }
797
- function worktree_git_directory_sync() {
798
- return git_common_directory.own();
799
- }
800
- function carried_cut_sync(now = /* @__PURE__ */ new Date(), directory = worktree_git_directory_sync()) {
801
- if (directory === void 0) return void 0;
802
- const read = read_cut(cut_path(directory), now);
803
- return read.kind === "carried" ? read.cut : void 0;
804
- }
805
- function lane_cut_sync(lane_directory) {
806
- const directory = git_common_directory.own(lane_directory);
807
- if (directory === void 0) return void 0;
808
- const cut = carried_cut_sync(/* @__PURE__ */ new Date(), directory);
809
- return cut === void 0 ? void 0 : { target: cut_path(directory), cut };
810
- }
811
- function fresh_cut(spec, now) {
812
- return {
813
- invocation: invocation_for(spec.issue),
814
- issue: spec.issue,
815
- branch: spec.branch,
816
- phase: spec.phase,
817
- cut_at: now.toISOString(),
818
- is_handed_off: true,
819
- handoff: spec.handoff
820
- };
821
- }
822
- function resumes_into_implementation(phase) {
823
- return phase === IMPLEMENTATION_PHASE;
824
- }
825
- function within_handoff_bound(cut) {
826
- return Buffer.byteLength(JSON.stringify(cut), "utf8") <= MAX_HANDOFF_BYTES;
827
- }
828
- function record_within_bound(spec, now = /* @__PURE__ */ new Date()) {
829
- return within_handoff_bound(fresh_cut(spec, now));
830
- }
831
- function begin_cut(target, spec, now = /* @__PURE__ */ new Date()) {
832
- const cut = fresh_cut(spec, now);
833
- if (!within_handoff_bound(cut)) return void 0;
834
- return stamp_file.create_stamp(target, cut) ? cut : void 0;
835
- }
836
- function is_declared_cut(cut, issue2) {
837
- return cut.is_handed_off === true && cut.invocation === invocation_for(issue2);
838
- }
839
- function matches_state(cut, request) {
840
- return cut.branch === request.current_branch && cut.issue === request.issue && request.is_dirty && request.is_held;
841
- }
842
- function is_adopted_cut(cut, issue2) {
843
- return cut.is_handed_off === false && cut.invocation === invocation_for(issue2);
844
- }
845
- function has_required_handoff(cut) {
846
- return !resumes_into_implementation(cut.phase) || run_cut_handoff.is_complete_handoff(cut.handoff);
847
- }
848
- function is_relaunchable(cut, issue2) {
849
- return is_declared_cut(cut, issue2) && has_required_handoff(cut) && cut.is_merge_relaunched !== true;
850
- }
851
- function mark_merge_relaunched(target, cut) {
852
- stamp_file.remove_stamp(target);
853
- return stamp_file.create_stamp(target, { ...cut, is_merge_relaunched: true });
854
- }
855
- function classify_resume(cut, request) {
856
- if (is_adopted_cut(cut, request.issue)) return "handed-off";
857
- if (!is_declared_cut(cut, request.issue) || !matches_state(cut, request)) return "stale";
858
- return has_required_handoff(cut) ? "resume" : "incomplete";
859
- }
860
- function adopt_cut(target, cut) {
861
- const next = { ...cut, is_handed_off: false };
862
- stamp_file.remove_stamp(target);
863
- return stamp_file.create_stamp(target, next) ? next : void 0;
864
- }
865
- function end_cut(target) {
866
- stamp_file.remove_stamp(target);
867
- }
868
- function hold_of(directory) {
869
- if (directory === void 0) return void 0;
870
- const read = run_hold.read_hold(run_hold.hold_path(directory));
871
- return read.kind === "held" || read.kind === "stale" ? read.hold : void 0;
872
- }
873
- function fullrun_issue(hold) {
874
- return hold?.is_fullrun === true ? hold.issue : void 0;
875
- }
876
- function held_issue_sync() {
877
- return fullrun_issue(hold_of(worktree_git_directory_sync()));
878
- }
879
- async function current_state() {
880
- const branch = await git_command.branch();
881
- const is_dirty = await run_hold.is_tree_dirty();
882
- const hold = hold_of(await worktree_directory2());
883
- return {
884
- branch,
885
- is_dirty,
886
- is_held: hold !== void 0,
887
- held_issue: fullrun_issue(hold),
888
- hold_taken_at: hold?.taken_at
889
- };
890
- }
891
- function describe_cut(cut) {
892
- return `${cut.invocation} cut at ${cut.cut_at} on ${cut.branch} (${cut.phase})`;
893
- }
894
- function busy_message(cut) {
895
- return `Another process already resumed this cut \u2014 ${describe_cut(cut)}. Nothing was resumed here; a double launch was detected.`;
896
- }
897
- function handed_off_message(cut) {
898
- return `This cut was already handed off to a successor \u2014 ${describe_cut(cut)}. Nothing was resumed here; the run is being carried on by the process that adopted it, so this one has nothing to do.`;
899
- }
900
- function stale_message2(cut) {
901
- return `This cut does not match the current tree \u2014 ${describe_cut(cut)}. Resume failed; verify the branch and the uncommitted work, then clear it with \`${END_COMMAND}\` if the run is over.`;
902
- }
903
- function incomplete_message(cut) {
904
- return `This cut carries no instruction to resume on \u2014 ${describe_cut(cut)}. Resume was refused rather than continuing without it; recover the run's instruction and work state before implementing, and clear the record with \`${END_COMMAND}\` if the run is over.`;
905
- }
906
- function unreadable_message2() {
907
- return `A cut record is here but could not be read; clear it with \`${END_COMMAND}\` once you know no run is using it. Read it with \`${READ_COMMAND}\`.`;
908
- }
909
- function unknown_message2() {
910
- return "This working tree\u2019s git directory could not be read, so no cut record was acted on.";
911
- }
912
- var run_cut = {
913
- CUT_MAX_AGE_HOURS,
914
- CUT_MAX_AGE_MS,
915
- END_COMMAND,
916
- IMPLEMENTATION_CONTEXT_THRESHOLD,
917
- IMPLEMENTATION_PHASE,
918
- MAX_HANDOFF_BYTES,
919
- PRE_GATE_PHASE,
920
- adopt_cut,
921
- begin_cut,
922
- busy_message,
923
- carried_cut_sync,
924
- classify: classify3,
925
- classify_resume,
926
- current_state,
927
- cut_path,
928
- describe_cut,
929
- end_cut,
930
- fresh_cut,
931
- fullrun_issue,
932
- handed_off_message,
933
- has_required_handoff,
934
- held_issue_sync,
935
- hold_of,
936
- incomplete_message,
937
- invocation_for,
938
- is_expired: is_expired2,
939
- is_relaunchable,
940
- lane_cut_sync,
941
- mark_merge_relaunched,
942
- read_cut,
943
- record_within_bound,
944
- resumes_into_implementation,
945
- stale_message: stale_message2,
946
- unknown_message: unknown_message2,
947
- unreadable_message: unreadable_message2,
948
- within_handoff_bound,
949
- worktree_directory: worktree_directory2,
950
- worktree_git_directory_sync
951
- };
952
-
953
- // scripts/rules/run-tail-rule.ts
954
- var SEGMENT_PREFIX = String.raw`(?:\(\s*)?(?:[A-Za-z_][A-Za-z0-9_]*=\S*\s+)*(?:npx\s+|pnpm\s+(?:exec\s+|run\s+)?)?`;
955
- var WORD_END = String.raw`(?=\s|$|\))`;
956
- var PUSH_STEP_SEGMENT = new RegExp(String.raw`^${SEGMENT_PREFIX}josh\s+(?:git|g)${WORD_END}`, "u");
957
- var CONFIRMED_FLAG = new RegExp(String.raw`(?:^|\s)(?:-y|--yes)${WORD_END}`, "u");
958
- var SKIPS_THE_PUSH = new RegExp(String.raw`(?:^|\s)--skip-push${WORD_END}`, "u");
959
- var BACKGROUND_KEY = "run_in_background";
960
- var QUOTED_SPAN = /"[^"]*"|'[^']*'/gu;
961
- function flags_of(segment) {
962
- return segment.replaceAll(QUOTED_SPAN, " ");
963
- }
964
- function is_push_step_segment(segment) {
965
- if (!PUSH_STEP_SEGMENT.test(segment)) return false;
966
- const flags = flags_of(segment);
967
- if (SKIPS_THE_PUSH.test(flags)) return false;
968
- return CONFIRMED_FLAG.test(flags);
969
- }
970
- function is_push_step(command) {
971
- return shell_segments.segments_of(command).some((segment) => is_push_step_segment(segment));
972
- }
973
- function is_backgrounded(input) {
974
- if (!json_value.is_record(input)) return false;
975
- return input[BACKGROUND_KEY] === true;
976
- }
977
- function is_push_step_call(call) {
978
- if (call.name !== cost_blocks.BASH_TOOL) return false;
979
- return is_push_step(time_shell.bash_command(call.input));
980
- }
981
- function is_backgrounded_push_step(call) {
982
- if (!is_backgrounded(call.input)) return false;
983
- return is_push_step_call(call);
984
- }
985
- function is_foreground_push_step(call) {
986
- if (is_backgrounded(call.input)) return false;
987
- return is_push_step_call(call);
988
- }
989
- function decide2() {
990
- return true;
991
- }
992
- var RUN_TAIL_REASON = "\u26D4 run tail: this issues the commit-push-PR step in the foreground, where the harness decides when to stop waiting. Reissue it with `run_in_background` set; when it exits, go straight on to `pnpm josh followup` in the foreground \u2014 the turn never ends at the push (`.claude/skills/workflow-commands/background-commands.md`). It fires on every foreground push, not once per run.";
993
- var run_tail_rule = {
994
- RUN_TAIL_REASON,
995
- decide: decide2,
996
- is_backgrounded_push_step,
997
- is_foreground_push_step,
998
- is_push_step,
999
- is_push_step_call
1000
- };
1001
-
1002
- // scripts/rules/lane-background.ts
1003
- var SHIP_COMMAND = `${time_shell.JOSH_PREFIX}ship`;
1004
- var LONG_RUNNING_COMMANDS = /* @__PURE__ */ new Set([
1005
- ...["gate", "git", "followup"].map((name) => `${time_shell.JOSH_PREFIX}${name}`),
1006
- SHIP_COMMAND
1007
- ]);
1008
- var BACKGROUND_KEY2 = "run_in_background";
1009
- var TIMEOUT_KEY = "timeout";
1010
- var FOREGROUND_TIMEOUT_MS = 6e5;
1011
- function is_backgrounded2(input) {
1012
- return json_value.is_record(input) && input[BACKGROUND_KEY2] === true;
1013
- }
1014
- function long_commands_of(command) {
1015
- return time_shell.josh_commands_of(command).filter((name) => LONG_RUNNING_COMMANDS.has(name));
1016
- }
1017
- function ships_alone(command) {
1018
- const names = long_commands_of(command);
1019
- return names.length > 0 && names.every((name) => name === SHIP_COMMAND);
1020
- }
1021
- function backgrounded_bash_command(call) {
1022
- if (call.name !== cost_blocks.BASH_TOOL || !is_backgrounded2(call.input)) return void 0;
1023
- return time_shell.bash_command(call.input);
1024
- }
1025
- function is_backgrounded_ship(call) {
1026
- const command = backgrounded_bash_command(call);
1027
- return command !== void 0 && ships_alone(command);
1028
- }
1029
- function is_candidate(call) {
1030
- if (run_tail_rule.is_push_step_call(call)) return true;
1031
- const command = backgrounded_bash_command(call);
1032
- if (command === void 0 || is_backgrounded_ship(call)) return false;
1033
- return long_commands_of(command).length > 0;
1034
- }
1035
- function is_background_long_run(call, is_lane_child = () => lane_child_marker.is_child_of(process.cwd())) {
1036
- return is_candidate(call) && is_lane_child();
1037
- }
1038
- function foreground_input(call, is_lane_child = () => lane_child_marker.is_child_of(process.cwd())) {
1039
- if (!is_backgrounded_ship(call) || !json_value.is_record(call.input) || !is_lane_child()) {
1040
- return void 0;
1041
- }
1042
- return { ...call.input, [BACKGROUND_KEY2]: false, [TIMEOUT_KEY]: FOREGROUND_TIMEOUT_MS };
1043
- }
1044
- var FOREGROUND_NOTE = "lane background: this lane child backgrounded `josh ship`, which would die with the headless turn before its supervisor exists \u2014 so it was run in the foreground instead, where it detaches itself after the preflight. End the turn on `launched` / `busy`.";
1045
- function unfinished_ids(tail, launched_ids) {
1046
- const lines = tail.split("\n").map((line) => time_transcript_line.parse_line(line));
1047
- const finished = new Set(lines.map((line) => line?.finished_background ?? ""));
1048
- const blocks = lines.flatMap((line) => line?.blocks ?? []);
1049
- const launched = blocks.flatMap((block) => launched_ids(block));
1050
- return launched.filter((id) => id !== "" && !finished.has(id));
1051
- }
1052
- function pending_background_ids(tail) {
1053
- return unfinished_ids(tail, (block) => [block.background_id, block.agent_id]);
1054
- }
1055
- function pending_agent_ids(tail) {
1056
- return unfinished_ids(tail, (block) => [block.agent_id]);
1057
- }
1058
- var LANE_BACKGROUND_REASON = '\u26D4 lane background: this session is a dispatched lane child (`JOSH_LANE_CHILD`), a headless process whose background tasks die when the turn ends. Hand over to `pnpm josh ship --detach --review "<title> #<N>"`, issued in the foreground, then end the turn on `launched` / `busy`. It fires on every occurrence (`.claude/skills/workflow-commands/chain-rule.md` step 0).';
1059
- var LANE_BACKGROUND_STOP_REASON = "\u26D4 lane background stop: this is a dispatched lane child (`JOSH_LANE_CHILD`) and a background task it launched has not finished, and ending this turn kills it. Wait for it in the foreground, or re-issue the work through `pnpm josh ship --detach` \u2014 do not notify, stop or repeat your reply.";
1060
- var ROW2 = {
1061
- id: "lane-background",
1062
- is_trigger: (call) => is_background_long_run(call),
1063
- reason: LANE_BACKGROUND_REASON,
1064
- decide: () => true
1065
- };
1066
- var lane_background = {
1067
- FOREGROUND_NOTE,
1068
- LANE_BACKGROUND_REASON,
1069
- LANE_BACKGROUND_STOP_REASON,
1070
- ROW: ROW2,
1071
- foreground_input,
1072
- is_background_long_run,
1073
- pending_agent_ids,
1074
- pending_background_ids
1075
- };
1076
-
1077
- // scripts/run/ship/run-ship-detach.ts
1078
- import { randomUUID } from "node:crypto";
1079
- import { setTimeout as sleep } from "node:timers/promises";
1080
- import { z as z4 } from "zod";
1081
- var LOG_PREFIX = "josh-ship-log-";
1082
- var PID_PREFIX = "josh-ship-pid-";
1083
- var BODY_PREFIX = "josh-ship-notify-";
1084
- var KEY_SEPARATOR = "-";
1085
- var LOG_SUFFIX = ".log";
1086
- var BODY_SUFFIX = ".txt";
1087
- var PNPM = "pnpm";
1088
- var INLINE_NOTIFY = "--notify-message";
1089
- var FILE_NOTIFY = "--notify-message-file";
1090
- var NOTIFY_VALUE_INDEX = 1;
1091
- var SUPERVISED_KEY = "JOSH_SHIP_SUPERVISED";
1092
- var LAUNCH_ID_KEY = "JOSH_SHIP_LAUNCH_ID";
1093
- var SUPERVISED_VALUE = "1";
1094
- var LAUNCHED = "launched";
1095
- var BUSY = "busy";
1096
- var FAILED = "failed";
1097
- var RESULT_PREFIX = "josh-ship-result-";
1098
- var RECORD_POLL_MS = 25;
1099
- var RECORD_WAIT_ATTEMPTS = 200;
1100
- var CLAIM_WINDOW_MS = 12e4;
1101
- var ship_record_schema = z4.object({
1102
- pid: z4.number().int().positive().optional(),
1103
- process_start: z4.string().optional(),
1104
- launched_at: z4.number().optional(),
1105
- launcher_pid: z4.number().int().positive().optional(),
1106
- launcher_start: z4.string().optional(),
1107
- launch_id: z4.string(),
1108
- result: z4.enum(["success", "failed"]).optional()
1109
- });
1110
- var LAUNCH_MARK = " \xB7 started by process ";
1111
- var HEADER_START = "\n";
1112
- function key(prefix, request) {
1113
- return stamp_file.stamp_path(`${prefix}${request.number}${KEY_SEPARATOR}`, request.repository);
1114
- }
1115
- function log_path(repository, number) {
1116
- return stamp_file.stamp_path(`${LOG_PREFIX}${number}${KEY_SEPARATOR}`, repository, LOG_SUFFIX);
1117
- }
1118
- function result_path(repository, number) {
1119
- return stamp_file.stamp_path(`${RESULT_PREFIX}${number}${KEY_SEPARATOR}`, repository);
1120
- }
1121
- function read_record(repository, number) {
1122
- try {
1123
- const raw = stamp_file.read_stamp_text(result_path(repository, number));
1124
- return raw === void 0 ? void 0 : json_value.parse_with(raw, ship_record_schema);
1125
- } catch {
1126
- return void 0;
1127
- }
1128
- }
1129
- function record_launch(request, pid, launch_id) {
1130
- stamp_file.write_text_stamp(key(PID_PREFIX, request), String(pid));
1131
- const process_start = process_identity.read_start(pid);
1132
- stamp_file.replace_stamp(result_path(request.repository, request.number), {
1133
- pid,
1134
- launch_id,
1135
- launched_at: Date.now(),
1136
- ...process_start !== void 0 && { process_start }
1137
- });
1138
- }
1139
- function supervisor_environment(launch_id) {
1140
- return {
1141
- ...agent_role_profile.handoff_environment(),
1142
- [SUPERVISED_KEY]: SUPERVISED_VALUE,
1143
- [LAUNCH_ID_KEY]: launch_id
1144
- };
1145
- }
1146
- function is_within_claim_window(record) {
1147
- return record.launched_at !== void 0 && Date.now() - record.launched_at < CLAIM_WINDOW_MS;
1148
- }
1149
- function has_live_identity(pid, record) {
1150
- if (record.process_start === void 0) {
1151
- return is_within_claim_window(record) && process_identity.is_live_pid(pid);
1152
- }
1153
- return process_identity.is_same_process(pid, record.process_start) !== false;
1154
- }
1155
- function result_of(record) {
1156
- if (record.pid === void 0) {
1157
- const is_launcher = process_identity.is_same_process(record.launcher_pid, record.launcher_start);
1158
- return is_launcher === false ? "abnormal" : "running";
1159
- }
1160
- if (has_live_identity(record.pid, record)) return "running";
1161
- return record.result ?? "abnormal";
1162
- }
1163
- function read_result(repository, number) {
1164
- const record = read_record(repository, number);
1165
- return record === void 0 ? void 0 : { launch_id: record.launch_id, result: result_of(record) };
1166
- }
1167
- function current_record(repository, number) {
1168
- const record = read_record(repository, number);
1169
- return record?.launch_id === process.env[LAUNCH_ID_KEY] ? record : void 0;
1170
- }
1171
- function is_pending(record) {
1172
- return record !== void 0 && record.pid === void 0;
1173
- }
1174
- async function ready_record(repository, number) {
1175
- let record = current_record(repository, number);
1176
- for (let attempt = 0; attempt < RECORD_WAIT_ATTEMPTS; attempt += 1) {
1177
- if (!is_pending(record)) return record;
1178
- await sleep(RECORD_POLL_MS);
1179
- record = current_record(repository, number);
1180
- }
1181
- return void 0;
1182
- }
1183
- async function update_record(repository, number, fields) {
1184
- const record = await ready_record(repository, number);
1185
- if (record === void 0) return;
1186
- stamp_file.replace_stamp(result_path(repository, number), { ...record, ...fields });
1187
- }
1188
- async function mark_result(repository, number, code) {
1189
- await update_record(repository, number, { result: code === 0 ? "success" : "failed" });
1190
- }
1191
- async function claim_identity(repository, number) {
1192
- const own = process_identity.own_fields();
1193
- if (own.process_start === void 0) return;
1194
- await update_record(repository, number, own);
1195
- }
1196
- function failed_launch(request, note) {
1197
- stamp_file.remove_stamp(result_path(request.repository, request.number));
1198
- return { verdict: FAILED, note };
1199
- }
1200
- function notify_arguments(request) {
1201
- const [flag, value] = [request.notify[0], request.notify[NOTIFY_VALUE_INDEX]];
1202
- if (flag !== INLINE_NOTIFY || value === void 0) return request.notify;
1203
- const body_path = stamp_file.stamp_path(
1204
- `${BODY_PREFIX}${request.number}${KEY_SEPARATOR}`,
1205
- request.repository,
1206
- BODY_SUFFIX
1207
- );
1208
- stamp_file.write_text_stamp(body_path, value);
1209
- return [FILE_NOTIFY, body_path];
1210
- }
1211
- function supervisor_argv(request) {
1212
- const review = request.is_review ? ["--review"] : [];
1213
- const cites = request.cites.flatMap((cite) => ["--cite", cite]);
1214
- return {
1215
- command: PNPM,
1216
- args: [
1217
- "josh",
1218
- "ship",
1219
- ...review,
1220
- ...notify_arguments(request),
1221
- ...request.body,
1222
- ...cites,
1223
- request.title
1224
- ]
1225
- };
1226
- }
1227
- function prepare_launch(request) {
1228
- const launch_id = randomUUID();
1229
- const launcher = process_identity.own_fields();
1230
- stamp_file.replace_stamp(result_path(request.repository, request.number), {
1231
- launch_id,
1232
- launcher_pid: launcher.pid,
1233
- ...launcher.process_start !== void 0 && { launcher_start: launcher.process_start }
1234
- });
1235
- return launch_id;
1236
- }
1237
- function launch(request) {
1238
- const notes = [];
1239
- const log = log_path(request.repository, request.number);
1240
- const launch_id = prepare_launch(request);
1241
- const result = detached_launch.launch(
1242
- {
1243
- argv: supervisor_argv(request),
1244
- cwd: request.cwd,
1245
- log_path: log,
1246
- // The provider travels as a mark because the launch strips the session keys that name it, and
1247
- // `ship --review` resolves its reviewer from it.
1248
- env: supervisor_environment(launch_id)
1249
- },
1250
- (note) => {
1251
- notes.push(note);
1252
- }
1253
- );
1254
- agent_role_profile.warn_of_default();
1255
- if (result.kind === "failed") return failed_launch(request, result.note);
1256
- record_launch(request, result.pid, launch_id);
1257
- return {
1258
- verdict: LAUNCHED,
1259
- note: [`supervisor ${String(result.pid)} \u2014 log: ${log}`, ...notes].join("\n")
1260
- };
1261
- }
1262
- async function detach(request) {
1263
- if (read_result(request.repository, request.number)?.result === "running") {
1264
- return {
1265
- verdict: BUSY,
1266
- note: `a ship supervisor for ${session_cite.issue(request.number)} is already running`
1267
- };
1268
- }
1269
- const result = launch(request);
1270
- if (result.verdict === LAUNCHED) {
1271
- await run_event_stream_emit.emit(
1272
- run_event_stream.EVENT_KIND.SHIP_LAUNCH,
1273
- `${issue_cite.plain(request.number)} ship supervisor launched`
1274
- );
1275
- }
1276
- return result;
1277
- }
1278
- function last_launch(text2) {
1279
- const mark = text2.lastIndexOf(LAUNCH_MARK);
1280
- if (mark === -1) return text2;
1281
- return text2.slice(text2.lastIndexOf(HEADER_START, mark) + HEADER_START.length);
1282
- }
1283
- function read_log(repository, number) {
1284
- const text2 = stamp_file.read_stamp_text(log_path(repository, number));
1285
- return text2 === void 0 ? void 0 : last_launch(text2);
1286
- }
1287
- function is_supervised(source = process.env) {
1288
- return source[SUPERVISED_KEY] === SUPERVISED_VALUE;
1289
- }
1290
- var run_ship_detach = {
1291
- BUSY,
1292
- FAILED,
1293
- LAUNCHED,
1294
- LAUNCH_ID_KEY,
1295
- claim_identity,
1296
- mark_result,
1297
- read_result,
1298
- SUPERVISED_KEY,
1299
- detach,
1300
- is_supervised,
1301
- last_launch,
1302
- log_path,
1303
- read_log,
1304
- supervisor_argv
1305
- };
1306
-
1307
- // scripts/lane/lane-handoff.ts
1308
- function is_ship_running(issue2, directory) {
1309
- const repository = git_common_directory.repository(directory);
1310
- return repository !== void 0 && run_ship_detach.read_result(repository, issue2)?.result === "running";
1311
- }
1312
- function is_handed_off(directory, source = process.env) {
1313
- const issue2 = lane_child_marker.marked_issue(source);
1314
- if (issue2 === void 0 || !lane_child_marker.is_child_of(directory, source)) return false;
1315
- return is_ship_running(issue2, directory);
1316
- }
1317
- var lane_handoff = { is_handed_off, is_ship_running };
1318
-
1319
- // scripts/issue/issue-labels.ts
1320
- var EPIC_LABEL = "epic";
1321
- var BUG_LABEL = "bug";
1322
- var ENHANCEMENT_LABEL = "enhancement";
1323
- var BREAKING_CHANGE_LABEL = "breaking-change";
1324
- var IN_PROGRESS_LABEL = "in-progress";
1325
- var PLANNED_LABEL = "run:planned";
1326
- var NEEDS_DECISION_LABEL = "needs-decision";
1327
- var RUN_SOLO_LABEL = "run:solo";
1328
- var RUN_LANE_LABEL = "run:lane";
1329
- var PRIORITY_HIGH_LABEL = "priority:high";
1330
- var AUTO_OK_LABEL = "auto-ok";
1331
- var NEEDS_HUMAN_REVIEW_LABEL = "needs-human-review";
1332
- var ALREADY_DONE_LABEL = "already-done";
1333
- var RELEASE_LABEL = "release";
1334
- var REVIEW_ROUND2_SKIPPED_LABEL = "review-round2-skipped";
1335
- var INTERRUPT_ROUTE_LABEL = "route:interrupt";
1336
- var REVIEW_CAP_ROUTE_LABEL = "route:review-cap";
1337
- var SPLIT_ROUTE_LABEL = "route:split";
1338
- var TIER_A_ROUTE_LABEL = "route:tier-a";
1339
- var FILING_ROUTE_LABELS = [
1340
- {
1341
- name: INTERRUPT_ROUTE_LABEL,
1342
- // Not `5319e7`, which is the `epic` label's purple: in a listing an interrupt would render as
1343
- // an epic, and the two are read at a glance rather than by name.
1344
- color: "1d76db",
1345
- // Keyed to the tests rather than to severity. "A serious defect" is the self-assessment
1346
- // `wip-cap.md` bans as a criterion, and this string is what a person reads in `gh label list`.
1347
- description: "Filed past the WIP cap \u2014 meets one of the three interrupt tests (wip-cap.md)"
1348
- },
1349
- {
1350
- name: REVIEW_CAP_ROUTE_LABEL,
1351
- color: "eab308",
1352
- description: "Filed by the review round cap's carry-forward (prompts/review.md \u2192 Review round cap)"
1353
- },
1354
- {
1355
- name: SPLIT_ROUTE_LABEL,
1356
- color: "0e8a16",
1357
- description: "A child issue created by a split (split-assessment.md)"
1358
- },
1359
- {
1360
- name: TIER_A_ROUTE_LABEL,
1361
- color: "d93f0b",
1362
- description: "Filed Tier A during implementation \u2014 an upstream defect or a prerequisite"
1363
- }
1364
- ];
1365
- var DEPTH_0_LABEL = "depth:0";
1366
- var DEPTH_1_LABEL = "depth:1";
1367
- var DEPTH_2_LABEL = "depth:2";
1368
- var DEPTH_LABELS = [
1369
- {
1370
- name: DEPTH_0_LABEL,
1371
- color: "0e8a16",
1372
- description: "Depth 0 \u2014 what a consumer of this package touches (observation-filing.md)"
1373
- },
1374
- {
1375
- name: DEPTH_1_LABEL,
1376
- color: "fbc02d",
1377
- description: "Depth 1 \u2014 the run orchestration that executes an Issue (observation-filing.md)"
1378
- },
1379
- {
1380
- name: DEPTH_2_LABEL,
1381
- color: "c5def5",
1382
- description: "Depth 2 \u2014 what measures a run (observation-filing.md)"
1383
- }
1384
- ];
1385
- var WORKFLOW_LABELS = [
1386
- {
1387
- name: EPIC_LABEL,
1388
- color: "5319e7",
1389
- description: "Tracks a batch of child issues from one split"
1390
- },
1391
- { name: IN_PROGRESS_LABEL, color: "0075ca", description: "Work is actively in progress" },
1392
- { name: PLANNED_LABEL, color: "c2e0c6", description: "kickoff posted the plan" },
1393
- {
1394
- name: RUN_SOLO_LABEL,
1395
- color: "b60205",
1396
- description: "Runs alone in a backlogrun: nothing starts beside it"
1397
- },
1398
- {
1399
- name: RUN_LANE_LABEL,
1400
- color: "0e8a16",
1401
- description: "Judged safe to run beside others in a backlogrun"
1402
- },
1403
- {
1404
- name: PRIORITY_HIGH_LABEL,
1405
- color: "e99695",
1406
- description: "Offered first in a backlogrun; only a person removes it"
1407
- },
1408
- {
1409
- name: RELEASE_LABEL,
1410
- color: "fef2c0",
1411
- description: "Tracks the next release; its blockers are the merged work it publishes"
1412
- },
1413
- {
1414
- name: AUTO_OK_LABEL,
1415
- color: "0e8a16",
1416
- description: "Opted in to unattended execution outside an epic"
1417
- },
1418
- {
1419
- name: NEEDS_DECISION_LABEL,
1420
- color: "d93f0b",
1421
- description: "Parked: needs a decision before it can run"
1422
- },
1423
- {
1424
- name: NEEDS_HUMAN_REVIEW_LABEL,
1425
- color: "d93f0b",
1426
- description: "Implement and verify, but stop before committing so a person can look"
1427
- },
1428
- {
1429
- name: ALREADY_DONE_LABEL,
1430
- color: "6f42c1",
1431
- description: "Verified already merged \u2014 a person closes it"
1432
- },
1433
- {
1434
- name: REVIEW_ROUND2_SKIPPED_LABEL,
1435
- color: "c5def5",
1436
- description: "Review round 2 was skipped under the condition in prompts/review.md"
1437
- },
1438
- { name: BUG_LABEL, color: "d73a4a", description: "Something isn't working" },
1439
- ...FILING_ROUTE_LABELS,
1440
- ...DEPTH_LABELS
1441
- ];
1442
- var BUGFIX_LABEL = "bugfix";
1443
- var OTHER_CHANGE_LABEL = "other-change";
1444
- var IGNORE_FOR_RELEASE_LABEL = "ignore-for-release";
1445
- var RELEASE_CLASSIFICATION_NAMES = [
1446
- BREAKING_CHANGE_LABEL,
1447
- ENHANCEMENT_LABEL,
1448
- BUGFIX_LABEL,
1449
- OTHER_CHANGE_LABEL,
1450
- IGNORE_FOR_RELEASE_LABEL
1451
- ];
1452
- var RELEASE_CLASSIFICATION_METADATA = {
1453
- [BREAKING_CHANGE_LABEL]: { color: "d93f0b", description: "Release: a breaking change (major)" },
1454
- [ENHANCEMENT_LABEL]: { color: "84b6eb", description: "Release: a new feature (minor)" },
1455
- [BUGFIX_LABEL]: { color: "d73a4a", description: "Release: a bug fix (patch)" },
1456
- [OTHER_CHANGE_LABEL]: { color: "c2e0c6", description: "Release: any other change (patch)" },
1457
- [IGNORE_FOR_RELEASE_LABEL]: { color: "cfd3d7", description: "Release: left out of the notes" }
1458
- };
1459
- var RELEASE_CLASSIFICATION_LABELS = RELEASE_CLASSIFICATION_NAMES.map((name) => ({ name, ...RELEASE_CLASSIFICATION_METADATA[name] }));
1460
- var REPOSITORY_LABELS = [
1461
- ...WORKFLOW_LABELS,
1462
- ...RELEASE_CLASSIFICATION_LABELS
1463
- ];
1464
- function has_any_label(labels, wanted) {
1465
- return (labels ?? []).some((label) => wanted.has(label.name.toLowerCase()));
1466
- }
1467
- function label_name_of(labels, wanted) {
1468
- const target = wanted.toLowerCase();
1469
- return labels.find((label) => label.toLowerCase() === target);
1470
- }
1471
- function has_label_name(labels, wanted) {
1472
- return label_name_of(labels, wanted) !== void 0;
1473
- }
1474
-
1475
- // scripts/rules/lane-park.ts
1476
- var NOTIFY_COMMANDS = /* @__PURE__ */ new Set(["notify"]);
1477
- var CONFIRMATION_TASK_TYPE = /(?:^|\s)--task-type[=\s]+["']?confirmation\b/u;
1478
- function is_confirmation_notify(command) {
1479
- return shell_segments.segments_of(command).some(
1480
- (segment) => shell_segments.is_josh_command(segment, NOTIFY_COMMANDS) && CONFIRMATION_TASK_TYPE.test(segment)
1481
- );
1482
- }
1483
- var NOTIFY_INVOCATION = /josh\s+(?:notify|nf)\b/u;
1484
- var COMMAND_NOTIFY_MARKER = "stop notified: a confirmation Telegram was sent by this command";
1485
- function mentions_confirmation_notify(text2) {
1486
- if (text2.includes(COMMAND_NOTIFY_MARKER)) return true;
1487
- return NOTIFY_INVOCATION.test(text2) && CONFIRMATION_TASK_TYPE.test(text2);
1488
- }
1489
- function is_parking_child(directory = process.cwd()) {
1490
- return lane_child_marker.is_child_of(directory) && !lane_handoff.is_handed_off(directory);
1491
- }
1492
- function is_unparked_stop(command, is_child = is_parking_child) {
1493
- if (!is_confirmation_notify(command)) return false;
1494
- return is_child();
1495
- }
1496
- var APPLIES_NEEDS_DECISION = new RegExp(
1497
- String.raw`(?:labels\[\]=|--add-label[= ]'?)${NEEDS_DECISION_LABEL}\b`,
1498
- "u"
1499
- );
1500
- function records_the_park(command) {
1501
- return APPLIES_NEEDS_DECISION.test(command);
1502
- }
1503
- var LANE_PARK_REASON = "\u26D4 lane child park: this session is a dispatched lane child, so a stop for a person parks first: `gh api repos/{owner}/{repo}/issues/<N>/labels -f 'labels[]=needs-decision'`; `pnpm josh issue:comment <N> --body-file <path>` (question, options, stash); a `needs-human-review` / `already-done` stop already is. Reissue this notify, once per run (`.claude/skills/workflow-commands/pre-gate-cut.md`).";
1504
- var ROW3 = {
1505
- id: "lane-park",
1506
- is_trigger: bash_triggers.on_bash_command(is_unparked_stop),
1507
- reason: LANE_PARK_REASON,
1508
- keeps: bash_triggers.on_bash_command(records_the_park)
1509
- };
1510
- var lane_park = {
1511
- COMMAND_NOTIFY_MARKER,
1512
- LANE_PARK_REASON,
1513
- ROW: ROW3,
1514
- is_confirmation_notify,
1515
- is_parking_child,
1516
- is_unparked_stop,
1517
- mentions_confirmation_notify,
1518
- records_the_park
1519
- };
1520
-
1521
- // scripts/discovery/repo-party.ts
1522
- var FIRST_PARTY = "first-party";
1523
- var THIRD_PARTY = "third-party";
1524
- var UNKNOWN = "unknown";
1525
- var GH_REPO_ENV_KEY = "GH_REPO";
1526
- var GH_REPO_PATH_SEGMENTS = 2;
1527
- function classify4(session_owner2, target) {
1528
- if (session_owner2 === void 0 || target === void 0) return UNKNOWN;
1529
- return session_owner2.toLowerCase() === target.toLowerCase() ? FIRST_PARTY : THIRD_PARTY;
1530
- }
1531
- function target_owner(owner_repo) {
1532
- return repo_origin.parse_origin_url(`https://${repo_origin.GITHUB_HOST}/${owner_repo}`)?.owner;
1533
- }
1534
- function current_owner(repository_path = process.cwd()) {
1535
- return repo_discovery.resolve_current_owner(repository_path);
1536
- }
1537
- function gh_repo_owners(gh_repo) {
1538
- return [target_owner(gh_repo.split("/").slice(-GH_REPO_PATH_SEGMENTS).join("/"))];
1539
- }
1540
- function remote_owners(repository_path) {
1541
- return repo_discovery.read_remote_urls(repository_path).map((url) => repo_origin.parse_origin_url(url)?.owner);
1542
- }
1543
- function placeholder_owners(repository_path = process.cwd(), environment = process.env) {
1544
- const gh_repo = environment[GH_REPO_ENV_KEY];
1545
- return gh_repo === void 0 || gh_repo === "" ? remote_owners(repository_path) : gh_repo_owners(gh_repo);
1546
- }
1547
- var repo_party = {
1548
- FIRST_PARTY,
1549
- THIRD_PARTY,
1550
- UNKNOWN,
1551
- classify: classify4,
1552
- current_owner,
1553
- placeholder_owners,
1554
- target_owner
1555
- };
1556
-
1557
- // scripts/gh/git-gh-api-path.ts
1558
- var FULL_PAGE_QUERY = "?per_page=100";
1559
- function repo_api_path(repo = "{owner}/{repo}") {
1560
- return `repos/${repo}`;
1561
- }
1562
- function issues_api_path(repo) {
1563
- return `${repo_api_path(repo)}/issues`;
1564
- }
1565
- function issue_api_path(issue_number, repo) {
1566
- return `${issues_api_path(repo)}/${issue_number}`;
1567
- }
1568
- function blocked_by_api_path(issue_number, repo) {
1569
- return `${issue_api_path(issue_number, repo)}/dependencies/blocked_by`;
1570
- }
1571
- function issue_comments_api_path(issue_number, repo) {
1572
- return `${issue_api_path(issue_number, repo)}/comments`;
1573
- }
1574
- function pulls_api_path(repo) {
1575
- return `${repo_api_path(repo)}/pulls`;
1576
- }
1577
- function pull_api_path(pr_number, repo) {
1578
- return `${pulls_api_path(repo)}/${pr_number}`;
1579
- }
1580
- function pull_merge_api_path(pr_number, repo) {
1581
- return `${pull_api_path(pr_number, repo)}/merge`;
1582
- }
1583
- function pull_comments_api_path(pr_number, repo) {
1584
- return `${pull_api_path(pr_number, repo)}/comments`;
1585
- }
1586
- function pull_reviews_api_path(pr_number, repo) {
1587
- return `${pull_api_path(pr_number, repo)}/reviews`;
1588
- }
1589
- function commit_api_path(commit_sha, repo) {
1590
- return `${repo_api_path(repo)}/commits/${commit_sha}`;
1591
- }
1592
- function commit_check_runs_api_path(commit_sha, repo) {
1593
- return `${commit_api_path(commit_sha, repo)}/check-runs`;
1594
- }
1595
- function commit_status_api_path(commit_sha, repo) {
1596
- return `${commit_api_path(commit_sha, repo)}/status`;
1597
- }
1598
- function tag_reference_api_path(tag, repo) {
1599
- return `${repo_api_path(repo)}/git/ref/tags/${tag}`;
1600
- }
1601
- function release_by_tag_api_path(tag, repo) {
1602
- return `${repo_api_path(repo)}/releases/tags/${tag}`;
1603
- }
1604
- var git_gh_api_path = {
1605
- FULL_PAGE_QUERY,
1606
- repo_api_path,
1607
- tag_ref_api_path: tag_reference_api_path,
1608
- release_by_tag_api_path,
1609
- issues_api_path,
1610
- issue_api_path,
1611
- blocked_by_api_path,
1612
- issue_comments_api_path,
1613
- pulls_api_path,
1614
- pull_api_path,
1615
- pull_merge_api_path,
1616
- pull_comments_api_path,
1617
- pull_reviews_api_path,
1618
- commit_api_path,
1619
- commit_check_runs_api_path,
1620
- commit_status_api_path
1621
- };
1622
-
1623
- // scripts/gh/git-gh-exec.ts
1624
- import { execa as execa2, execaSync } from "execa";
1625
-
1626
- // scripts/gh/git-gh-check.ts
1627
- import { execa } from "execa";
1628
- var GH_NOT_INSTALLED_MSG = "gh CLI is not installed. Install it from https://cli.github.com/";
1629
- var gh_check = {};
1630
- async function run_gh_check() {
1631
- try {
1632
- await execa("gh", ["--version"], { timeout: COMMAND_TIMEOUT_MS });
1633
- } catch {
1634
- delete gh_check.promise;
1635
- throw new Error(GH_NOT_INSTALLED_MSG);
1636
- }
1637
- }
1638
- async function check_gh_installed() {
1639
- gh_check.promise ??= run_gh_check();
1640
- await gh_check.promise;
1641
- }
1642
-
1643
- // scripts/git/parse-json-array.ts
1644
- function parse_json_loose(raw_json) {
1645
- return json_value.parse_or_undefined(raw_json);
1646
- }
1647
- function parse_json_array_or_undefined(raw_json, element_schema) {
1648
- const value = parse_json_loose(raw_json);
1649
- if (!Array.isArray(value)) return void 0;
1650
- return element_schema.array().parse(value);
1651
- }
1652
- function read_json_listing(raw_json, element_schema) {
1653
- try {
1654
- const rows = parse_json_array_or_undefined(raw_json, element_schema);
1655
- return rows === void 0 ? { kind: "unreadable" } : { kind: "read", rows };
1656
- } catch {
1657
- return { kind: "unexpected_shape" };
1658
- }
1659
- }
1660
- function parse_json_object_or_undefined(raw_json, schema) {
1661
- const value = parse_json_loose(raw_json);
1662
- if (value === void 0) return void 0;
1663
- return schema.parse(value);
1664
- }
1665
- var parse_json = {
1666
- parse_json_object_or_undefined
1667
- };
1668
-
1669
- // scripts/gh/git-gh-failure.ts
1670
- import { z as z5 } from "zod";
1671
- var error_document_schema = z5.object({ status: z5.union([z5.string(), z5.number()]).optional() }).catch({});
1672
- var GH_FAILURE_FIELD = "gh_failure";
1673
- function has_gh_failure(error) {
1674
- return error instanceof Error && Object.hasOwn(error, GH_FAILURE_FIELD);
1675
- }
1676
- function parse_response_status(stdout) {
1677
- const document = parse_json.parse_json_object_or_undefined(stdout, error_document_schema);
1678
- if (document?.status === void 0) return void 0;
1679
- const status = Number(document.status);
1680
- return Number.isSafeInteger(status) ? status : void 0;
1681
- }
1682
- function classify_stdout(stdout) {
1683
- return { status: parse_response_status(stdout) };
1684
- }
1685
- function attach(error, failure) {
1686
- Object.defineProperty(error, GH_FAILURE_FIELD, {
1687
- value: failure,
1688
- enumerable: false,
1689
- configurable: true
1690
- });
1691
- return error;
1692
- }
1693
- function failure_of(error) {
1694
- return has_gh_failure(error) ? error.gh_failure : void 0;
1695
- }
1696
- var gh_failure = { attach, classify_stdout, failure_of, parse_response_status };
1697
-
1698
- // scripts/gh/git-gh-exec.ts
1699
- var BODY_FROM_STDIN = "-";
1700
- var GH_REQUEST_TIMEOUT_MS = 6e4;
1701
- function to_timeout_option(timeout_ms) {
1702
- return { timeout: timeout_ms ?? GH_REQUEST_TIMEOUT_MS };
1703
- }
1704
- function direct_environment() {
1705
- const removed = agent_session_environment.removed_proxy_environment();
1706
- return Object.keys(removed).length > 0 ? { env: removed } : {};
1707
- }
1708
- function to_spawn_options(timeout_ms, cwd) {
1709
- return {
1710
- ...to_timeout_option(timeout_ms),
1711
- ...direct_environment(),
1712
- ...cwd !== void 0 && { cwd }
1713
- };
1714
- }
1715
- var GH_REQUEST_TIMEOUT_MESSAGE = "gh request timed out";
1716
- function has_stderr_field(error) {
1717
- return error instanceof Error && "stderr" in error && typeof error.stderr === "string";
1718
- }
1719
- function has_stdout_field(error) {
1720
- return error instanceof Error && "stdout" in error && typeof error.stdout === "string";
1721
- }
1722
- function to_timeout_prefix(error) {
1723
- return has_timed_out(error) ? `${GH_REQUEST_TIMEOUT_MESSAGE}: ` : "";
1724
- }
1725
- function to_gh_error(error) {
1726
- const stderr = has_stderr_field(error) ? error.stderr.trim() : "";
1727
- const stdout = has_stdout_field(error) ? error.stdout.trim() : "";
1728
- const summary = stderr.length > 0 ? stderr : error_text.message_of(error);
1729
- const detail = stdout.length > 0 ? `${summary}
1730
- ${stdout}` : summary;
1731
- return gh_failure.attach(
1732
- new Error(`${to_timeout_prefix(error)}${detail}`, { cause: error }),
1733
- gh_failure.classify_stdout(stdout)
1734
- );
1735
- }
1736
- async function exec_gh_command(arguments_, timeout_ms, cwd) {
1737
- await check_gh_installed();
1738
- const options = to_spawn_options(timeout_ms, cwd);
1739
- try {
1740
- const { stdout } = await execa2("gh", arguments_, options);
1741
- return stdout.trimEnd();
1742
- } catch (error) {
1743
- throw to_gh_error(error);
1744
- }
1745
- }
1746
- async function exec_gh_command_with_stdin(input) {
1747
- await check_gh_installed();
1748
- const options = { input: input.stdin_body, ...to_spawn_options(input.timeout_ms, input.cwd) };
1749
- try {
1750
- const { stdout } = await execa2("gh", input.args, options);
1751
- return stdout.trimEnd();
1752
- } catch (error) {
1753
- throw to_gh_error(error);
1754
- }
1755
- }
1756
- var STATUS_LINE_PATTERN = /^HTTP\/[\d.]+ (?<status>\d{3})\b/u;
1757
- function parse_status_line(output) {
1758
- const { status } = STATUS_LINE_PATTERN.exec(output)?.groups ?? {};
1759
- return status === void 0 ? void 0 : Number(status);
1760
- }
1761
- function status_of_failure(error) {
1762
- return has_stdout_field(error) ? parse_status_line(error.stdout) : void 0;
1763
- }
1764
- async function exec_gh_api_status(path, timeout_ms) {
1765
- const options = to_spawn_options(timeout_ms);
1766
- try {
1767
- await check_gh_installed();
1768
- const { stdout } = await execa2("gh", ["api", "--include", "--silent", path], options);
1769
- return parse_status_line(stdout);
1770
- } catch (error) {
1771
- return status_of_failure(error);
1772
- }
1773
- }
1774
- function exec_gh_api_status_sync(path, timeout_ms) {
1775
- const options = to_spawn_options(timeout_ms);
1776
- try {
1777
- const { stdout } = execaSync("gh", ["api", "--include", "--silent", path], options);
1778
- return parse_status_line(stdout);
1779
- } catch (error) {
1780
- return status_of_failure(error);
1781
- }
1782
- }
1783
- var METHOD_FLAG = "--method";
1784
- var INPUT_FLAG = "--input";
1785
- var PAGINATE_FLAG = "--paginate";
1786
- var SLURP_FLAG = "--slurp";
1787
- var JQ_FLAG = "--jq";
1788
- function optional_flag(flag, value) {
1789
- return value === void 0 ? [] : [flag, value];
1790
- }
1791
- function to_gh_api_args(request) {
1792
- const body_args = request.body === void 0 ? [] : [INPUT_FLAG, BODY_FROM_STDIN];
1793
- const paginate_args = request.should_paginate === true ? [PAGINATE_FLAG] : [];
1794
- const slurp_args = request.should_slurp === true ? [SLURP_FLAG] : [];
1795
- return [
1796
- "api",
1797
- request.path,
1798
- ...optional_flag(METHOD_FLAG, request.method),
1799
- ...body_args,
1800
- ...paginate_args,
1801
- ...slurp_args,
1802
- ...optional_flag(JQ_FLAG, request.jq_filter)
1803
- ];
1804
- }
1805
- async function exec_gh_api(request) {
1806
- const args = to_gh_api_args(request);
1807
- if (request.body === void 0) {
1808
- return await exec_gh_command(args, request.timeout_ms, request.cwd);
1809
- }
1810
- return await exec_gh_command_with_stdin({
1811
- args,
1812
- stdin_body: request.body,
1813
- timeout_ms: request.timeout_ms,
1814
- cwd: request.cwd
1815
- });
1816
- }
1817
- function exec_gh_api_sync(request) {
1818
- const body_option = request.body === void 0 ? {} : { input: request.body };
1819
- const options = { ...body_option, ...to_spawn_options(request.timeout_ms, request.cwd) };
1820
- try {
1821
- const { stdout } = execaSync("gh", to_gh_api_args(request), options);
1822
- return stdout.trimEnd();
1823
- } catch (error) {
1824
- throw to_gh_error(error);
1825
- }
1826
- }
1827
- function read_gh_api_sync(request) {
1828
- try {
1829
- return exec_gh_api_sync(request);
1830
- } catch {
1831
- return void 0;
1832
- }
1833
- }
1834
- var git_gh_exec = {
1835
- direct_environment,
1836
- exec_gh_command,
1837
- exec_gh_command_with_stdin,
1838
- exec_gh_api,
1839
- exec_gh_api_sync,
1840
- read_gh_api_sync,
1841
- exec_gh_api_status,
1842
- exec_gh_api_status_sync,
1843
- parse_status_line
1844
- };
1845
-
1846
- // scripts/gh/git-gh-helpers.ts
1847
- function parse_pr_state_string(result) {
1848
- const trimmed = result.trim();
1849
- return trimmed.length > 0 ? trimmed : void 0;
1850
- }
1851
- function is_pr_already_exists_message(error_message) {
1852
- return error_message.toLowerCase().includes("already exists");
1853
- }
1854
- function get_error_message_with_stderr(error) {
1855
- if (!(error instanceof Error)) return String(error);
1856
- if (has_stderr_field(error) && error.stderr.length > 0) return `${error.message}
1857
- ${error.stderr}`;
1858
- return error.message;
1859
- }
1860
- function handle_pr_create_error(error) {
1861
- const error_message = get_error_message_with_stderr(error);
1862
- if (is_pr_already_exists_message(error_message)) {
1863
- throw new Error("PR_ALREADY_EXISTS");
1864
- }
1865
- throw error;
1866
- }
1867
- var git_gh_helpers = {
1868
- parse_pr_state_string,
1869
- get_error_message_with_stderr,
1870
- handle_pr_create_error
1871
- };
1872
-
1873
- // scripts/gh/git-gh-issue-rest.ts
1874
- import { z as z6 } from "zod";
1875
-
1876
- // scripts/gh/git-gh-rest-state.ts
1877
- var MERGED_STATE = "MERGED";
1878
- function to_gh_state(state) {
1879
- return state?.toUpperCase();
1880
- }
1881
-
1882
- // scripts/gh/git-gh-issue-rest.ts
1883
- var rest_issue_schema = z6.looseObject({
1884
- number: z6.number(),
1885
- issue_dependencies_summary: z6.looseObject({ total_blocked_by: z6.number().optional() }).nullish(),
1886
- // Present only on a pull request, which this endpoint serves as readily as an issue.
1887
- pull_request: z6.looseObject({ merged_at: z6.string().nullish() }).nullish()
1888
- });
1889
- var REPOSITORY_URL = /\/repos\/([\w.-]+\/[\w.-]+)$/u;
1890
- var REPOSITORY_URL_GROUP = 1;
1891
- var BLOCKED_BY_FIELD = "blockedBy";
1892
- var BLOCKED_BY_COUNT_FIELD = "blocked_by_count";
1893
- var STATE_FIELD = "state";
1894
- var BODY_FIELD = "body";
1895
- var FIELD_SEPARATOR = ",";
1896
- var EMPTY_BODY = "";
1897
- var REST_FIELD_NAMES = /* @__PURE__ */ new Map([
1898
- ["url", "html_url"],
1899
- ["createdAt", "created_at"],
1900
- ["closedAt", "closed_at"],
1901
- ["updatedAt", "updated_at"]
1902
- ]);
1903
- var NOT_AN_ISSUE_MESSAGE = "gh api answered something other than an issue object";
1904
- var NOT_AN_ISSUE_LISTING_MESSAGE = "gh api answered something other than an issue listing";
1905
- var NOT_A_BLOCKER_LISTING_MESSAGE = "gh api answered something other than a blocked-by listing";
1906
- function rest_field_name(field) {
1907
- return REST_FIELD_NAMES.get(field) ?? field;
1908
- }
1909
- function split_fields(fields) {
1910
- return fields.split(FIELD_SEPARATOR).map((field) => field.trim()).filter((field) => field.length > 0);
1911
- }
1912
- function to_issue_state(rest, value) {
1913
- if (typeof rest.pull_request?.merged_at === "string") return MERGED_STATE;
1914
- return typeof value === "string" ? to_gh_state(value) : value;
1915
- }
1916
- function total_blocked_by(rest) {
1917
- return rest.issue_dependencies_summary?.total_blocked_by;
1918
- }
1919
- function to_gh_field_value(field, rest) {
1920
- if (field === BLOCKED_BY_COUNT_FIELD) return total_blocked_by(rest);
1921
- const value = rest[rest_field_name(field)];
1922
- if (field === STATE_FIELD) return to_issue_state(rest, value);
1923
- return field === BODY_FIELD ? value ?? EMPTY_BODY : value;
1924
- }
1925
- function parse_rest_issue(rest_json) {
1926
- const parsed = parse_json_object_or_undefined(rest_json, rest_issue_schema);
1927
- if (parsed === void 0) throw new Error(NOT_AN_ISSUE_MESSAGE);
1928
- return parsed;
1929
- }
1930
- function is_pull_request(rest) {
1931
- return rest.pull_request !== void 0 && rest.pull_request !== null;
1932
- }
1933
- function parse_rest_issues(rest_json) {
1934
- const parsed = parse_json_array_or_undefined(rest_json, rest_issue_schema);
1935
- if (parsed === void 0) throw new Error(NOT_AN_ISSUE_LISTING_MESSAGE);
1936
- return parsed;
1937
- }
1938
- function empty_blocked_by() {
1939
- return { nodes: [], totalCount: 0 };
1940
- }
1941
- function repo_of_url(repository_url = "") {
1942
- const match = REPOSITORY_URL.exec(repository_url);
1943
- return match?.[REPOSITORY_URL_GROUP];
1944
- }
1945
- function to_blocked_by(blockers_json, exact_total) {
1946
- const parsed = parse_json_array_or_undefined(blockers_json, blocking_issue_schema);
1947
- if (parsed === void 0) throw new Error(NOT_A_BLOCKER_LISTING_MESSAGE);
1948
- const nodes = parsed.map((blocker) => ({ ...blocker, state: to_gh_state(blocker.state) }));
1949
- return { nodes, totalCount: exact_total ?? nodes.length };
1950
- }
1951
- function to_gh_issue(rest, fields, blocked_by) {
1952
- return Object.fromEntries(
1953
- fields.map((field) => [
1954
- field,
1955
- field === BLOCKED_BY_FIELD ? blocked_by : to_gh_field_value(field, rest)
1956
- ])
1957
- );
1958
- }
1959
- function to_field_text(value) {
1960
- if (typeof value === "string") return value;
1961
- return value === void 0 || value === null ? EMPTY_BODY : JSON.stringify(value);
1962
- }
1963
- var CLOSED = "CLOSED";
1964
- function reference_of_blocker(node, fallback_repo) {
1965
- const repo = repo_of_url(node.repository_url) ?? fallback_repo;
1966
- if (node.state === void 0) return { repo, number: node.number };
1967
- return { repo, number: node.number, state: node.state.toUpperCase() === CLOSED ? CLOSED : "OPEN" };
1968
- }
1969
- var git_gh_issue_rest = {
1970
- empty_blocked_by,
1971
- repo_of_url,
1972
- reference_of_blocker,
1973
- split_fields,
1974
- is_pull_request,
1975
- parse_rest_issue,
1976
- parse_rest_issues,
1977
- total_blocked_by,
1978
- to_blocked_by,
1979
- to_gh_issue,
1980
- to_field_text
1981
- };
1982
-
1983
- // scripts/gh/git-gh-reachability.ts
1984
- var RATE_LIMITED_STATUS = 429;
1985
- var SERVER_ERROR_FLOOR = 500;
1986
- function is_retryable_status(status) {
1987
- if (status >= SERVER_ERROR_FLOOR) return true;
1988
- return status === RATE_LIMITED_STATUS;
1989
- }
1990
- function classify_status(status) {
1991
- if (status === void 0) return "unreachable";
1992
- return is_retryable_status(status) ? "unreachable" : "reachable";
1993
- }
1994
- var gh_reachability = { classify_status };
1995
-
1996
- // scripts/gh/git-gh-issue-read.ts
1997
- async function read_blocked_by_listing(issue_number, repo, exact_total) {
1998
- const json = await git_gh_exec.exec_gh_api({
1999
- path: `${git_gh_api_path.blocked_by_api_path(issue_number, repo)}${git_gh_api_path.FULL_PAGE_QUERY}`
2000
- });
2001
- return git_gh_issue_rest.to_blocked_by(json, exact_total);
2002
- }
2003
- async function read_blocked_by(issue_number, rest, repo) {
2004
- if (git_gh_issue_rest.is_pull_request(rest)) return git_gh_issue_rest.empty_blocked_by();
2005
- const exact_total = git_gh_issue_rest.total_blocked_by(rest);
2006
- if (exact_total === 0) return git_gh_issue_rest.empty_blocked_by();
2007
- return await read_blocked_by_listing(issue_number, repo, exact_total);
2008
- }
2009
- function mark_followup(error) {
2010
- if (!(error instanceof Error)) return error;
2011
- const failure = gh_failure.failure_of(error);
2012
- if (failure === void 0) return error;
2013
- return gh_failure.attach(error, { ...failure, is_followup: true });
2014
- }
2015
- async function read_relations(issue_number, rest, repo) {
2016
- try {
2017
- return await read_blocked_by(issue_number, rest, repo);
2018
- } catch (error) {
2019
- throw mark_followup(error);
2020
- }
2021
- }
2022
- async function read_issue_fields(issue_number, fields, repo) {
2023
- const rest = git_gh_issue_rest.parse_rest_issue(
2024
- await git_gh_exec.exec_gh_api({ path: git_gh_api_path.issue_api_path(issue_number, repo) })
2025
- );
2026
- const requested = git_gh_issue_rest.split_fields(fields);
2027
- const blocked_by = requested.includes(BLOCKED_BY_FIELD) ? await read_relations(issue_number, rest, repo) : void 0;
2028
- return git_gh_issue_rest.to_gh_issue(rest, requested, blocked_by);
2029
- }
2030
- var NOT_FOUND_STATUS = 404;
2031
- function is_number_unresolved(failure) {
2032
- return failure.status === NOT_FOUND_STATUS && failure.is_followup !== true;
2033
- }
2034
- function to_unreadable_reason(status) {
2035
- return gh_reachability.classify_status(status) === "unreachable" ? "unreachable" : "rejected";
2036
- }
2037
- function to_read_failure(error) {
2038
- const failure = gh_failure.failure_of(error);
2039
- if (failure === void 0) return { kind: "unreadable", reason: "malformed", status: void 0 };
2040
- if (is_number_unresolved(failure)) return { kind: "missing" };
2041
- return {
2042
- kind: "unreadable",
2043
- reason: to_unreadable_reason(failure.status),
2044
- status: failure.status
2045
- };
2046
- }
2047
- async function issue_view_json_classified(issue_number, fields, repo) {
2048
- try {
2049
- const issue2 = await read_issue_fields(issue_number, fields, repo);
2050
- return { kind: "read", json: JSON.stringify(issue2) };
2051
- } catch (error) {
2052
- return to_read_failure(error);
2053
- }
2054
- }
2055
- async function issue_view_field_classified(issue_number, field, repo) {
2056
- try {
2057
- const issue2 = await read_issue_fields(issue_number, field, repo);
2058
- return { kind: "read", text: git_gh_issue_rest.to_field_text(issue2[field]) };
2059
- } catch (error) {
2060
- return to_read_failure(error);
2061
- }
2062
- }
2063
- async function issue_view_field(issue_number, field, repo) {
2064
- const read = await issue_view_field_classified(issue_number, field, repo);
2065
- return read.kind === "read" ? read.text : void 0;
2066
- }
2067
- async function issue_get_title(issue_number, repo) {
2068
- const result = await issue_view_field(issue_number, "title", repo);
2069
- return result === void 0 ? void 0 : git_gh_helpers.parse_pr_state_string(result);
2070
- }
2071
- async function issue_get_body(issue_number, repo) {
2072
- return await issue_view_field(issue_number, "body", repo);
2073
- }
2074
- async function issue_get_body_classified(issue_number, repo) {
2075
- return await issue_view_field_classified(issue_number, "body", repo);
2076
- }
2077
- async function issue_view_json(issue_number, fields, repo) {
2078
- const read = await issue_view_json_classified(issue_number, fields, repo);
2079
- return read.kind === "read" ? read.json : void 0;
2080
- }
2081
- var STATE_AND_RELATIONS_FIELDS = "number,state,labels,blockedBy";
2082
- async function issue_get_state_and_relations(issue_number, repo) {
2083
- return await issue_view_json(issue_number, STATE_AND_RELATIONS_FIELDS, repo);
2084
- }
2085
- async function issue_get_state_and_relations_classified(issue_number, repo) {
2086
- return await issue_view_json_classified(issue_number, STATE_AND_RELATIONS_FIELDS, repo);
2087
- }
2088
- function is_unreachable_read(failure) {
2089
- return failure.kind === "unreadable" && failure.reason === "unreachable";
2090
- }
2091
- var PLAN_FIELDS = "number,title,body,state,url,labels,blockedBy";
2092
- async function issue_get_plan_fields(issue_number) {
2093
- return await issue_view_json(issue_number, PLAN_FIELDS);
2094
- }
2095
- async function issue_get_plan_fields_classified(issue_number) {
2096
- return await issue_view_json_classified(issue_number, PLAN_FIELDS);
2097
- }
2098
- async function issue_get_labels_and_body(issue_number) {
2099
- return await issue_view_json(issue_number, "number,state,labels,body");
2100
- }
2101
- async function issue_list_comments(issue_number, timeout_ms) {
2102
- const path = `${git_gh_api_path.issue_comments_api_path(issue_number)}${git_gh_api_path.FULL_PAGE_QUERY}`;
2103
- try {
2104
- return await git_gh_exec.exec_gh_api({ path, should_paginate: true, timeout_ms });
2105
- } catch {
2106
- return void 0;
2107
- }
2108
- }
2109
- async function has_no_relations_endpoint(issue_number, repo) {
2110
- const status = await git_gh_exec.exec_gh_api_status(
2111
- git_gh_api_path.blocked_by_api_path(issue_number, repo)
2112
- );
2113
- return status === NOT_FOUND_STATUS;
2114
- }
2115
- async function issue_blocked_by_references(issue_number, own_repo, repo) {
2116
- try {
2117
- const listing = await read_blocked_by_listing(issue_number, repo);
2118
- return listing.nodes.map((blocker) => git_gh_issue_rest.reference_of_blocker(blocker, own_repo));
2119
- } catch (error) {
2120
- if (await has_no_relations_endpoint(issue_number, repo)) return [];
2121
- throw error;
2122
- }
2123
- }
2124
- async function issue_blocked_by_numbers(issue_number, repo) {
2125
- const references = await issue_blocked_by_references(issue_number, "", repo);
2126
- return references.map((blocker) => blocker.number);
2127
- }
2128
- var git_gh_issue_read = {
2129
- issue_blocked_by_numbers,
2130
- issue_blocked_by_references,
2131
- issue_get_title,
2132
- issue_get_body,
2133
- issue_get_body_classified,
2134
- issue_view_json,
2135
- issue_view_json_classified,
2136
- issue_get_state_and_relations,
2137
- issue_get_state_and_relations_classified,
2138
- is_unreachable_read,
2139
- issue_get_plan_fields,
2140
- issue_get_plan_fields_classified,
2141
- issue_get_labels_and_body,
2142
- issue_list_comments
2143
- };
2144
-
2145
- // scripts/gh/git-gh-issue-list.ts
2146
- var PER_PAGE = 100;
2147
- var FIRST_PAGE = 1;
2148
- var DEFAULT_STATE = "open";
2149
- var DEFAULT_SORT = "created";
2150
- var LISTING_DIRECTION = "direction=desc";
2151
- function listing_query(request) {
2152
- const state = request.state ?? DEFAULT_STATE;
2153
- const sort = request.sort ?? DEFAULT_SORT;
2154
- return `state=${state}&sort=${sort}&${LISTING_DIRECTION}`;
2155
- }
2156
- function listing_path(request, page) {
2157
- const label = request.label === void 0 ? "" : `&labels=${encodeURIComponent(request.label)}`;
2158
- const paging = `&per_page=${String(PER_PAGE)}&page=${String(page)}`;
2159
- return `${git_gh_api_path.issues_api_path(request.repo)}?${listing_query(request)}${label}${paging}`;
2160
- }
2161
- var DIGIT_PATTERN = /\d/u;
2162
- function has_token_occurrence(body, term) {
2163
- let index = body.indexOf(term);
2164
- while (index !== -1) {
2165
- if (!DIGIT_PATTERN.test(body.charAt(index + term.length))) return true;
2166
- index = body.indexOf(term, index + 1);
2167
- }
2168
- return false;
2169
- }
2170
- function matches_body(rest, term) {
2171
- if (term === void 0) return true;
2172
- const { body } = rest;
2173
- return typeof body === "string" && has_token_occurrence(body, term);
2174
- }
2175
- function is_selected(rest, request) {
2176
- return !git_gh_issue_rest.is_pull_request(rest) && matches_body(rest, request.body_term);
2177
- }
2178
- async function fetch_page(request, page) {
2179
- const path = listing_path(request, page);
2180
- const rows = git_gh_issue_rest.parse_rest_issues(await git_gh_exec.exec_gh_api({ path }));
2181
- return {
2182
- selected: rows.filter((row) => is_selected(row, request)),
2183
- is_full: rows.length >= PER_PAGE
2184
- };
2185
- }
2186
- var MAX_PAGES = 5;
2187
- var MAX_SCANNED = MAX_PAGES * PER_PAGE;
2188
- function wants_more(has_more, selected_count, limit) {
2189
- return has_more && selected_count < limit;
2190
- }
2191
- async function fetch_selected(request) {
2192
- const selected = [];
2193
- let page = FIRST_PAGE;
2194
- let has_more = true;
2195
- while (page <= MAX_PAGES && wants_more(has_more, selected.length, request.limit)) {
2196
- const result = await fetch_page(request, page);
2197
- selected.push(...result.selected);
2198
- has_more = result.is_full;
2199
- page += 1;
2200
- }
2201
- return {
2202
- rows: selected.slice(0, request.limit),
2203
- is_capped: wants_more(has_more, selected.length, request.limit)
2204
- };
2205
- }
2206
- var RELATION_CONCURRENCY = 8;
2207
- async function read_relations2(rows, repo) {
2208
- return await bounded_pool.bounded_map(
2209
- rows,
2210
- RELATION_CONCURRENCY,
2211
- async (row) => await read_blocked_by(String(row.number), row, repo)
2212
- );
2213
- }
2214
- async function issue_list(request) {
2215
- try {
2216
- const { rows, is_capped } = await fetch_selected(request);
2217
- const fields = git_gh_issue_rest.split_fields(request.json_fields);
2218
- const relations = fields.includes(BLOCKED_BY_FIELD) ? await read_relations2(rows, request.repo) : void 0;
2219
- const mapped = rows.map(
2220
- (row, index) => git_gh_issue_rest.to_gh_issue(row, fields, relations?.[index])
2221
- );
2222
- return { json: JSON.stringify(mapped), is_capped };
2223
- } catch {
2224
- return { json: void 0, is_capped: false };
2225
- }
2226
- }
2227
- var git_gh_issue_list = {
2228
- issue_list
2229
- };
2230
-
2231
- // scripts/issue/issue-watch-diff.ts
2232
- import { z as z7 } from "zod";
2233
- var RUN_MARKER = "<!-- josh:run -->";
2234
- var BOT_TYPE = "Bot";
2235
- var BOT_SUFFIX = "[bot]";
2236
- var NO_COMMENT_ID = 0;
2237
- var UNKNOWN_AUTHOR = "(unknown)";
2238
- var UNKNOWN_TIME = "(undated)";
2239
- var BODY_HEADING = "Body edited:";
2240
- var REMOVED_PREFIX = "- ";
2241
- var ADDED_PREFIX = "+ ";
2242
- var COMMENT_HEADING = "New comment by ";
2243
- var AT = " at ";
2244
- var SECTION_SEPARATOR = "\n\n";
2245
- var LINE_SEPARATOR = "\n";
2246
- var CRLF = "\r\n";
2247
- var comment_schema = z7.looseObject({
2248
- id: z7.number(),
2249
- user: z7.looseObject({ login: z7.string(), type: z7.string().optional() }).nullish(),
2250
- created_at: z7.string().optional(),
2251
- body: z7.string().nullish()
2252
- });
2253
- function is_bot(user) {
2254
- return user?.type === BOT_TYPE || (user?.login.endsWith(BOT_SUFFIX) ?? false);
2255
- }
2256
- function is_automated(user, body) {
2257
- return is_bot(user) || body.includes(RUN_MARKER);
2258
- }
2259
- function to_comment(raw) {
2260
- const body = raw.body ?? "";
2261
- const author = raw.user?.login ?? UNKNOWN_AUTHOR;
2262
- const created_at = raw.created_at ?? UNKNOWN_TIME;
2263
- return { id: raw.id, author, is_automated: is_automated(raw.user, body), created_at, body };
2264
- }
2265
- function parse_comments(json) {
2266
- if (json === void 0) return void 0;
2267
- const listing = read_json_listing(json, comment_schema);
2268
- return listing.kind === "read" ? listing.rows.map((row) => to_comment(row)) : void 0;
2269
- }
2270
- function last_comment_id(comments) {
2271
- return Math.max(NO_COMMENT_ID, ...comments.map((comment) => comment.id));
2272
- }
2273
- function baseline_of(snapshot) {
2274
- return { body: snapshot.body, last_comment_id: last_comment_id(snapshot.comments) };
2275
- }
2276
- function lines_missing_from(source, other) {
2277
- const present = new Set(other.split(LINE_SEPARATOR));
2278
- return source.split(LINE_SEPARATOR).filter((line) => line.trim() !== "" && !present.has(line));
2279
- }
2280
- function to_lf(body) {
2281
- return body.split(CRLF).join(LINE_SEPARATOR);
2282
- }
2283
- function body_section(previous_raw, current_raw) {
2284
- const previous = to_lf(previous_raw);
2285
- const current = to_lf(current_raw);
2286
- if (previous === current) return void 0;
2287
- const removed = lines_missing_from(previous, current).map((line) => `${REMOVED_PREFIX}${line}`);
2288
- const added = lines_missing_from(current, previous).map((line) => `${ADDED_PREFIX}${line}`);
2289
- return [BODY_HEADING, ...removed, ...added].join(LINE_SEPARATOR);
2290
- }
2291
- function comment_section(comment) {
2292
- return `${COMMENT_HEADING}${comment.author}${AT}${comment.created_at}${LINE_SEPARATOR}${comment.body}`;
2293
- }
2294
- function new_person_comments(baseline, snapshot) {
2295
- return snapshot.comments.filter(
2296
- (comment) => comment.id > baseline.last_comment_id && !comment.is_automated
2297
- );
2298
- }
2299
- function unread_diff(baseline, snapshot) {
2300
- const body = body_section(baseline.body, snapshot.body);
2301
- const comments = new_person_comments(baseline, snapshot).map(
2302
- (comment) => comment_section(comment)
2303
- );
2304
- const sections = [...body === void 0 ? [] : [body], ...comments];
2305
- return sections.length === 0 ? void 0 : sections.join(SECTION_SEPARATOR);
2306
- }
2307
- var issue_watch_diff = {
2308
- RUN_MARKER,
2309
- baseline_of,
2310
- parse_comments,
2311
- unread_diff
2312
- };
2313
-
2314
- // scripts/gh/git-gh-issue-write.ts
2315
- var PATCH_METHOD = "PATCH";
2316
- var DELETE_METHOD = "DELETE";
2317
- var HTML_URL_FILTER = ".html_url";
2318
- var ID_FILTER = ".id";
2319
- var LABEL_NAMES_FILTER = ".[].name";
2320
- var LABELS_SEGMENT = "/labels";
2321
- var COMMENTS_SEGMENT = "/comments";
2322
- var CLOSED_STATE = "closed";
2323
- var COLOR_HASH = "#";
2324
- var UNPROCESSABLE_STATUS = 422;
2325
- var ALREADY_EXISTS_CODE = "already_exists";
2326
- async function did_write_succeed(write) {
2327
- try {
2328
- await write();
2329
- return true;
2330
- } catch (error) {
2331
- error_text.trace_swallowed("git_gh_issue_write.did_write_succeed", error);
2332
- return false;
2333
- }
2334
- }
2335
- async function issue_edit_body(issue_number, body) {
2336
- return await git_gh_exec.exec_gh_api({
2337
- path: git_gh_api_path.issue_api_path(issue_number),
2338
- method: PATCH_METHOD,
2339
- body: JSON.stringify({ body }),
2340
- jq_filter: HTML_URL_FILTER
2341
- });
2342
- }
2343
- async function issue_comment(issue_number, body) {
2344
- return await git_gh_exec.exec_gh_api({
2345
- path: `${git_gh_api_path.issue_api_path(issue_number)}${COMMENTS_SEGMENT}`,
2346
- body: JSON.stringify({ body: `${body}
2347
-
2348
- ${issue_watch_diff.RUN_MARKER}` }),
2349
- jq_filter: HTML_URL_FILTER
2350
- });
2351
- }
2352
- async function issue_try_comment(issue_number, body) {
2353
- return await did_write_succeed(async () => await issue_comment(issue_number, body));
2354
- }
2355
- async function issue_close(issue_number, comment) {
2356
- return await did_write_succeed(async () => {
2357
- if (comment !== void 0) await issue_comment(issue_number, comment);
2358
- await git_gh_exec.exec_gh_api({
2359
- path: git_gh_api_path.issue_api_path(issue_number),
2360
- method: PATCH_METHOD,
2361
- body: JSON.stringify({ state: CLOSED_STATE })
2362
- });
2363
- });
2364
- }
2365
- function to_label_color(color) {
2366
- return color.startsWith(COLOR_HASH) ? color.slice(COLOR_HASH.length) : color;
2367
- }
2368
- function is_label_already_exists(error) {
2369
- if (gh_failure.failure_of(error)?.status !== UNPROCESSABLE_STATUS) return false;
2370
- return error_text.message_of(error).includes(ALREADY_EXISTS_CODE);
2371
- }
2372
- async function label_ensure(input) {
2373
- try {
2374
- await git_gh_exec.exec_gh_api({
2375
- path: `${git_gh_api_path.repo_api_path()}${LABELS_SEGMENT}`,
2376
- body: JSON.stringify({
2377
- name: input.name,
2378
- color: to_label_color(input.color),
2379
- description: input.description
2380
- })
2381
- });
2382
- } catch (error) {
2383
- if (is_label_already_exists(error)) return;
2384
- const [gist = ""] = error_text.message_of(error).split("\n", 1);
2385
- console.warn(`\u26A0 could not create the \`${input.name}\` label \u2014 ${gist}`);
2386
- }
2387
- }
2388
- function issue_create_request(input) {
2389
- const { labels } = input;
2390
- return {
2391
- path: git_gh_api_path.issues_api_path(input.repo),
2392
- body: JSON.stringify({
2393
- title: input.title,
2394
- ...labels !== void 0 && { labels },
2395
- body: input.body
2396
- }),
2397
- jq_filter: HTML_URL_FILTER
2398
- };
2399
- }
2400
- async function issue_create_with_label(input) {
2401
- return await git_gh_exec.exec_gh_api(
2402
- issue_create_request({ title: input.title, body: input.body, labels: [input.label] })
2403
- );
2404
- }
2405
- async function read_label_names(issue_number) {
2406
- try {
2407
- const raw = await git_gh_exec.exec_gh_api({
2408
- path: `${git_gh_api_path.issue_api_path(issue_number)}${LABELS_SEGMENT}`,
2409
- should_paginate: true,
2410
- jq_filter: LABEL_NAMES_FILTER
2411
- });
2412
- return raw.split("\n").map((name) => name.trim());
2413
- } catch (error) {
2414
- error_text.trace_swallowed("git_gh_issue_write.read_label_names", error);
2415
- return void 0;
2416
- }
2417
- }
2418
- async function issue_apply_label(issue_number, label) {
2419
- const labels_path = `${git_gh_api_path.issue_api_path(issue_number)}${LABELS_SEGMENT}`;
2420
- try {
2421
- await git_gh_exec.exec_gh_api({ path: labels_path, body: JSON.stringify({ labels: [label] }) });
2422
- return { is_applied: true };
2423
- } catch (error) {
2424
- const names = await read_label_names(issue_number);
2425
- if (names?.includes(label) === true) return { is_applied: true };
2426
- error_text.trace_swallowed("git_gh_issue_write.issue_apply_label", error);
2427
- const [gist = ""] = error_text.message_of(error).split("\n", 1);
2428
- return { is_applied: false, reason: gist };
2429
- }
2430
- }
2431
- async function issue_add_label(issue_number, label) {
2432
- const write = await issue_apply_label(issue_number, label);
2433
- return write.is_applied;
2434
- }
2435
- async function issue_remove_label(issue_number, label) {
2436
- const labels_path = `${git_gh_api_path.issue_api_path(issue_number)}${LABELS_SEGMENT}`;
2437
- await git_gh_exec.exec_gh_api({
2438
- path: `${labels_path}/${encodeURIComponent(label)}`,
2439
- method: DELETE_METHOD
2440
- });
2441
- }
2442
- async function read_issue_id(issue_number) {
2443
- const raw = await git_gh_exec.exec_gh_api({
2444
- path: git_gh_api_path.issue_api_path(issue_number),
2445
- jq_filter: ID_FILTER
2446
- });
2447
- const issue_id = Number(raw.trim());
2448
- if (!Number.isSafeInteger(issue_id) || issue_id <= 0) {
2449
- throw new Error(`gh api answered no database id for issue ${session_cite.issue(issue_number)}`);
2450
- }
2451
- return issue_id;
2452
- }
2453
- async function issue_add_blocked_by(issue_number, blocker) {
2454
- return await did_write_succeed(async () => {
2455
- const issue_id = await read_issue_id(blocker);
2456
- await git_gh_exec.exec_gh_api({
2457
- path: git_gh_api_path.blocked_by_api_path(issue_number),
2458
- body: JSON.stringify({ issue_id })
2459
- });
2460
- });
2461
- }
2462
- async function issue_remove_blocked_by(issue_number, blocker) {
2463
- return await did_write_succeed(async () => {
2464
- const issue_id = await read_issue_id(blocker);
2465
- const relations_path = git_gh_api_path.blocked_by_api_path(issue_number);
2466
- await git_gh_exec.exec_gh_api({
2467
- path: `${relations_path}/${String(issue_id)}`,
2468
- method: DELETE_METHOD
2469
- });
2470
- });
2471
- }
2472
- var git_gh_issue_write = {
2473
- issue_edit_body,
2474
- issue_comment,
2475
- issue_try_comment,
2476
- issue_close,
2477
- label_ensure,
2478
- issue_create_request,
2479
- issue_create_with_label,
2480
- issue_apply_label,
2481
- issue_add_label,
2482
- issue_remove_label,
2483
- issue_add_blocked_by,
2484
- issue_remove_blocked_by
2485
- };
2486
-
2487
- // scripts/gh/git-gh-issue.ts
2488
- var NUMBER_AND_BODY_FIELDS = "number,body";
2489
- var BACKLOG_SCAN_FIELDS = `number,title,body,labels,${BLOCKED_BY_COUNT_FIELD}`;
2490
- var NUMBER_TITLE_AND_LABELS_FIELDS = "number,title,labels";
2491
- var SUMMARY_FIELDS = "number,title,labels,createdAt";
2492
- var PICKUP_FIELDS = `${SUMMARY_FIELDS},blockedBy,body`;
2493
- var { issue_list: issue_list2 } = git_gh_issue_list;
2494
- async function issue_list_recent(limit) {
2495
- return await issue_list2({ json_fields: SUMMARY_FIELDS, limit });
2496
- }
2497
- async function issue_list_open_bodies(limit) {
2498
- return await issue_list2({ json_fields: BACKLOG_SCAN_FIELDS, limit });
2499
- }
2500
- async function issue_list_recently_closed(limit) {
2501
- return await issue_list2({
2502
- json_fields: NUMBER_TITLE_AND_LABELS_FIELDS,
2503
- limit,
2504
- state: "closed",
2505
- sort: "updated"
2506
- });
2507
- }
2508
- async function issue_search_body(term, limit) {
2509
- return await issue_list2({
2510
- json_fields: NUMBER_AND_BODY_FIELDS,
2511
- limit,
2512
- body_term: term
2513
- });
2514
- }
2515
- async function issue_list_by_label(label, limit) {
2516
- return await issue_list2({ json_fields: NUMBER_AND_BODY_FIELDS, limit, label });
2517
- }
2518
- async function issue_list_by_label_summary(label, limit, options) {
2519
- return await issue_list2({
2520
- json_fields: options?.json_fields ?? PICKUP_FIELDS,
2521
- limit,
2522
- label
2523
- });
2524
- }
2525
- async function issue_list_by_label_in_repo(label, limit, repo) {
2526
- return await issue_list2({ json_fields: SUMMARY_FIELDS, limit, label, repo });
2527
- }
2528
- var JUDGEMENT_FIELDS = "number,title,body,labels,updatedAt";
2529
- async function issue_list_open_for_judgement(limit) {
2530
- return await issue_list2({ json_fields: JUDGEMENT_FIELDS, limit });
2531
- }
2532
- var git_gh_issue = {
2533
- ...git_gh_issue_read,
2534
- ...git_gh_issue_write,
2535
- issue_list_recent,
2536
- issue_list_by_label,
2537
- issue_list_by_label_in_repo,
2538
- issue_list_by_label_summary,
2539
- issue_search_body,
2540
- issue_list_open_bodies,
2541
- issue_list_open_for_judgement,
2542
- issue_list_recently_closed
2543
- };
2544
-
2545
- // scripts/ci/pr-classification.ts
2546
- import { readFileSync as readFileSync2 } from "node:fs";
2547
- import { fileURLToPath } from "node:url";
2548
- import { z as z8 } from "zod";
2549
- var CLASSIFICATION_SET = new Set(RELEASE_CLASSIFICATION_NAMES);
2550
- var ISSUE_BUG_LABEL = "bug";
2551
- var DECLARATION_PREFIX = "- \u30EA\u30EA\u30FC\u30B9\u5206\u985E: ";
2552
- var DECLARATION = new RegExp(`^${DECLARATION_PREFIX}(.+)$`, "gmu");
2553
- var LEGACY_LABELS = /* @__PURE__ */ new Set(["semver-major", "semver-minor"]);
2554
- var LABEL = z8.object({ name: z8.string() });
2555
- var USER = z8.object({ login: z8.string() });
2556
- var PULL_REQUEST = z8.object({ number: z8.number(), user: USER });
2557
- var EVENT = z8.object({
2558
- pull_request: PULL_REQUEST,
2559
- repository: z8.object({ full_name: z8.string() })
2560
- });
2561
- function classification_error(labels, author) {
2562
- const legacy = labels.filter((label) => LEGACY_LABELS.has(label.toLowerCase()));
2563
- if (legacy.length > 0) return `Remove legacy release labels: ${legacy.join(", ")}`;
2564
- const selected = labels.filter((label) => CLASSIFICATION_SET.has(label.toLowerCase()));
2565
- if (selected.length > 1) {
2566
- return `Choose exactly one release classification; found: ${selected.join(", ")}`;
2567
- }
2568
- if (selected.length === 1 || author.endsWith("[bot]")) return void 0;
2569
- return `Choose one release classification: ${RELEASE_CLASSIFICATION_NAMES.join(", ")}`;
2570
- }
2571
- function declaration(label) {
2572
- return `${DECLARATION_PREFIX}${label}`;
2573
- }
2574
- function is_classification(value) {
2575
- return CLASSIFICATION_SET.has(value);
2576
- }
2577
- function release_candidates(candidates) {
2578
- if (!candidates.includes(BREAKING_CHANGE_LABEL)) return candidates;
2579
- return candidates.filter((candidate) => candidate !== ENHANCEMENT_LABEL);
2580
- }
2581
- function issue_candidates(issue_json) {
2582
- const issue2 = z8.object({ labels: z8.array(LABEL), body: z8.string().nullable() }).parse(JSON.parse(issue_json));
2583
- const names = issue2.labels.map((label) => label.name.toLowerCase());
2584
- const declared = [...(issue2.body ?? "").matchAll(DECLARATION)].map((match) => match[1] ?? "");
2585
- const candidates = [...release_candidates([...names, ...declared].filter(is_classification))];
2586
- const unknown = declared.filter((value) => !is_classification(value));
2587
- if (unknown.length > 0) throw new Error(`Unknown release classification: ${unknown.join(", ")}`);
2588
- if (names.includes(ISSUE_BUG_LABEL) && !candidates.includes(BREAKING_CHANGE_LABEL)) {
2589
- candidates.push(BUGFIX_LABEL);
2590
- }
2591
- return candidates;
2592
- }
2593
- function select_issue_classification(issue_json) {
2594
- const candidates = issue_candidates(issue_json);
2595
- const selected = [...new Set(candidates)];
2596
- const [label] = selected;
2597
- if (label === void 0 || selected.length > 1) {
2598
- throw new Error(
2599
- `Choose one release classification before opening the PR: ${RELEASE_CLASSIFICATION_NAMES.join(", ")}; found: ${selected.join(", ") || "none"}. Add "${DECLARATION_PREFIX}<label>" to the Issue body.`
2600
- );
2601
- }
2602
- return label;
2603
- }
2604
- function fetch_current_labels(repository, pull_number) {
2605
- const path = `repos/${repository}/issues/${String(pull_number)}/labels`;
2606
- try {
2607
- const names = git_gh_exec.exec_gh_api_sync({ path, jq_filter: ".[].name" });
2608
- return names.split("\n").filter((name) => name !== "");
2609
- } catch (error) {
2610
- const detail = error_text.message_of(error);
2611
- throw new Error(`Could not read the pull request labels: ${detail}`, { cause: error });
2612
- }
2613
- }
2614
- function check_event(event_path, read_labels = fetch_current_labels) {
2615
- const event = EVENT.parse(JSON.parse(readFileSync2(event_path, "utf8")));
2616
- const labels = read_labels(event.repository.full_name, event.pull_request.number);
2617
- return classification_error(labels, event.pull_request.user.login);
2618
- }
2619
- if (process.argv[1] === fileURLToPath(import.meta.url)) {
2620
- const event_path = process.env["GITHUB_EVENT_PATH"];
2621
- if (!event_path) throw new Error("GITHUB_EVENT_PATH is required");
2622
- const error = check_event(event_path);
2623
- if (error) {
2624
- console.error(`::error::${error}`);
2625
- process.exitCode = 1;
2626
- }
2627
- }
2628
- var pr_classification = {
2629
- classification_error,
2630
- check_event,
2631
- fetch_current_labels,
2632
- declaration,
2633
- is_classification,
2634
- select_issue_classification
2635
- };
2636
-
2637
- // scripts/lib/poll.ts
2638
- async function sleep2(duration_ms) {
2639
- await new Promise((resolve) => {
2640
- setTimeout(resolve, duration_ms);
2641
- });
2642
- }
2643
- async function wait_between(wait, interval_ms, attempt, attempts) {
2644
- if (attempt < attempts - 1) await wait(interval_ms);
2645
- }
2646
- async function poll_until(is_done, options) {
2647
- const wait = options.sleeper ?? sleep2;
2648
- for (let attempt = 0; attempt < options.attempts; attempt += 1) {
2649
- if (await is_done()) return true;
2650
- await wait_between(wait, options.interval_ms, attempt, options.attempts);
2651
- }
2652
- return false;
2653
- }
2654
- var poll = { poll_until, sleep: sleep2 };
2655
-
2656
- // scripts/gh/git-gh-pr.ts
2657
- import { z as z12 } from "zod";
2658
-
2659
- // scripts/gh/git-gh-pr-rest.ts
2660
- import { z as z9 } from "zod";
2661
- var rest_repo_schema = z9.looseObject({ full_name: z9.string().optional() }).nullish();
2662
- var rest_pull_side_schema = z9.looseObject({ repo: rest_repo_schema });
2663
- var rest_pull_schema = z9.looseObject({
2664
- number: z9.number(),
2665
- html_url: z9.string().optional(),
2666
- body: z9.string().nullish(),
2667
- state: z9.string().optional(),
2668
- merged: z9.boolean().nullish(),
2669
- merged_at: z9.string().nullish(),
2670
- mergeable: z9.boolean().nullish(),
2671
- mergeable_state: z9.string().optional(),
2672
- // `sha` is the head commit, which is what both halves of the merge-gate rollup are keyed by —
2673
- // REST hangs the check runs and the status contexts off the commit rather than off the pull
2674
- // request.
2675
- head: z9.looseObject({ ref: z9.string().optional(), sha: z9.string().optional(), repo: rest_repo_schema }).nullish(),
2676
- base: rest_pull_side_schema.nullish(),
2677
- // `node_id` is what the GraphQL auto-merge mutation addresses a pull request by, and `auto_merge`
2678
- // is `null` until auto-merge is enabled — both read by `git-gh-pr-auto-merge.ts`.
2679
- node_id: z9.string().optional(),
2680
- auto_merge: z9.looseObject({}).nullish()
2681
- });
2682
- var NOT_A_PULL_MESSAGE = "gh api answered something other than a pull request object";
2683
- var NOT_A_PULL_LISTING_MESSAGE = "gh api answered something other than a pull request listing";
2684
- var NOT_A_COMMENT_LISTING_MESSAGE = "gh api answered something other than a comment listing";
2685
- var OPEN_STATE = "open";
2686
- var EMPTY_BODY2 = "";
2687
- function parse_rest_pull(rest_json) {
2688
- const parsed = parse_json_object_or_undefined(rest_json, rest_pull_schema);
2689
- if (parsed === void 0) throw new Error(NOT_A_PULL_MESSAGE);
2690
- return parsed;
2691
- }
2692
- function parse_rest_pulls(rest_json) {
2693
- const parsed = parse_json_array_or_undefined(rest_json, rest_pull_schema);
2694
- if (parsed === void 0) throw new Error(NOT_A_PULL_LISTING_MESSAGE);
2695
- return parsed;
2696
- }
2697
- function select_pull(pulls) {
2698
- return pulls.find((pull) => pull.state === OPEN_STATE) ?? pulls[0];
2699
- }
2700
- function is_merged(pull) {
2701
- return pull.merged === true || typeof pull.merged_at === "string";
2702
- }
2703
- function to_pr_state(pull) {
2704
- return is_merged(pull) ? MERGED_STATE : to_gh_state(pull.state);
2705
- }
2706
- function to_repo_name(side) {
2707
- return side?.repo?.full_name;
2708
- }
2709
- function is_same_repository_head(pull) {
2710
- const head_repo = to_repo_name(pull.head);
2711
- return head_repo !== void 0 && head_repo === to_repo_name(pull.base);
2712
- }
2713
- function to_pr_info(pull) {
2714
- return {
2715
- mergeable: pull.mergeable,
2716
- mergeStateStatus: to_gh_state(pull.mergeable_state),
2717
- state: to_pr_state(pull)
2718
- };
2719
- }
2720
- function to_pr_comments(rest_json) {
2721
- const parsed = parse_json_array_or_undefined(rest_json, rest_comment_schema);
2722
- if (parsed === void 0) throw new Error(NOT_A_COMMENT_LISTING_MESSAGE);
2723
- return parsed.map((comment) => ({
2724
- body: comment.body ?? EMPTY_BODY2,
2725
- url: comment.html_url,
2726
- author: { login: comment.user?.login }
2727
- }));
2728
- }
2729
- var git_gh_pr_rest = {
2730
- parse_rest_pull,
2731
- parse_rest_pulls,
2732
- select_pull,
2733
- is_same_repository_head,
2734
- is_merged,
2735
- to_pr_state,
2736
- to_pr_info,
2737
- to_pr_comments
2738
- };
2739
-
2740
- // scripts/gh/git-gh-pr-read.ts
2741
- var pr_number_by_branch = /* @__PURE__ */ new Map();
2742
- var LOOKUP_QUERY = "state=all&sort=created&direction=desc&per_page=100";
2743
- var COMMENTS_QUERY = FULL_PAGE_QUERY;
2744
- var OWNER_PLACEHOLDER = "{owner}";
2745
- var NO_PULL_REQUEST_MESSAGE = "gh api found no pull request for branch";
2746
- var UNREADABLE_PULL_REQUEST_MESSAGE = "gh api could not read the pull requests for branch";
2747
- function lookup_path(branch_name) {
2748
- const head = `${OWNER_PLACEHOLDER}:${encodeURIComponent(branch_name)}`;
2749
- return `${git_gh_api_path.pulls_api_path()}?head=${head}&${LOOKUP_QUERY}`;
2750
- }
2751
- async function fetch_pr_number(branch_name) {
2752
- const json = await git_gh_exec.exec_gh_api({ path: lookup_path(branch_name) });
2753
- return git_gh_pr_rest.select_pull(git_gh_pr_rest.parse_rest_pulls(json))?.number;
2754
- }
2755
- var pending_pr_number_by_branch = /* @__PURE__ */ new Map();
2756
- var pull_by_number = /* @__PURE__ */ new Map();
2757
- async function fetch_pr_number_read(branch_name) {
2758
- try {
2759
- const pr_number = await fetch_pr_number(branch_name);
2760
- if (pr_number === void 0) return { kind: "missing" };
2761
- pr_number_by_branch.set(branch_name, pr_number);
2762
- return { kind: "read", pr_number };
2763
- } catch (error) {
2764
- return { kind: "unreadable", cause: error };
2765
- }
2766
- }
2767
- async function start_pr_number_read(branch_name) {
2768
- const pending = pending_pr_number_by_branch.get(branch_name);
2769
- if (pending !== void 0) return await pending;
2770
- const lookup = fetch_pr_number_read(branch_name);
2771
- pending_pr_number_by_branch.set(branch_name, lookup);
2772
- try {
2773
- return await lookup;
2774
- } finally {
2775
- pending_pr_number_by_branch.delete(branch_name);
2776
- }
2777
- }
2778
- function forget_pr_numbers() {
2779
- pr_number_by_branch.clear();
2780
- pending_pr_number_by_branch.clear();
2781
- pull_by_number.clear();
2782
- }
2783
- async function read_pr_number(branch_name) {
2784
- const cached = pr_number_by_branch.get(branch_name);
2785
- if (cached !== void 0) return { kind: "read", pr_number: cached };
2786
- return await start_pr_number_read(branch_name);
2787
- }
2788
- async function resolve_pr_number(branch_name) {
2789
- const read = await read_pr_number(branch_name);
2790
- return read.kind === "read" ? read.pr_number : void 0;
2791
- }
2792
- function to_unreadable_error(branch_name, cause) {
2793
- return new Error(`${UNREADABLE_PULL_REQUEST_MESSAGE}: ${branch_name}`, { cause });
2794
- }
2795
- async function require_pr_number(branch_name) {
2796
- const read = await read_pr_number(branch_name);
2797
- if (read.kind === "read") return read.pr_number;
2798
- if (read.kind === "missing") throw new Error(`${NO_PULL_REQUEST_MESSAGE}: ${branch_name}`);
2799
- throw to_unreadable_error(branch_name, read.cause);
2800
- }
2801
- async function read_pull(pr_number) {
2802
- const json = await git_gh_exec.exec_gh_api({
2803
- path: git_gh_api_path.pull_api_path(String(pr_number))
2804
- });
2805
- return git_gh_pr_rest.parse_rest_pull(json);
2806
- }
2807
- async function read_remembered_pull(pr_number) {
2808
- const pending = pull_by_number.get(pr_number) ?? read_pull(pr_number);
2809
- pull_by_number.set(pr_number, pending);
2810
- try {
2811
- return await pending;
2812
- } catch (error) {
2813
- if (pull_by_number.get(pr_number) === pending) pull_by_number.delete(pr_number);
2814
- throw error;
2815
- }
2816
- }
2817
- async function read_pull_of_branch(branch_name, read = read_remembered_pull) {
2818
- const number_read = await read_pr_number(branch_name);
2819
- if (number_read.kind !== "read") return number_read;
2820
- try {
2821
- return { kind: "read", pull: await read(number_read.pr_number) };
2822
- } catch (error) {
2823
- return { kind: "unreadable", cause: error };
2824
- }
2825
- }
2826
- async function read_pull_or_undefined(branch_name) {
2827
- const read = await read_pull_of_branch(branch_name);
2828
- return read.kind === "read" ? read.pull : void 0;
2829
- }
2830
- async function pr_exists(branch_name) {
2831
- const read = await read_pr_number(branch_name);
2832
- if (read.kind === "unreadable") throw to_unreadable_error(branch_name, read.cause);
2833
- return read.kind === "read";
2834
- }
2835
- async function pr_get_number(branch_name) {
2836
- return await resolve_pr_number(branch_name);
2837
- }
2838
- async function pr_get_url(branch_name) {
2839
- const pull = await read_pull_or_undefined(branch_name);
2840
- if (pull?.html_url === void 0) return void 0;
2841
- return git_gh_helpers.parse_pr_state_string(pull.html_url);
2842
- }
2843
- async function pr_get_merge_state(branch_name) {
2844
- const read = await read_pull_of_branch(branch_name, read_pull);
2845
- if (read.kind !== "read") return void 0;
2846
- const { pull } = read;
2847
- return {
2848
- is_merged: git_gh_pr_rest.is_merged(pull),
2849
- merged_at: pull.merged_at ?? void 0,
2850
- head_sha: pull.head?.sha,
2851
- merge_state_status: to_gh_state(pull.mergeable_state)
2852
- };
2853
- }
2854
- async function pr_get_body(branch_name) {
2855
- const pull = await read_pull_or_undefined(branch_name);
2856
- const body = pull?.body;
2857
- return typeof body === "string" && body.length > 0 ? body : void 0;
2858
- }
2859
- async function pr_view(branch_name) {
2860
- const read = await read_pull_of_branch(branch_name, read_pull);
2861
- if (read.kind === "unreadable") throw to_unreadable_error(branch_name, read.cause);
2862
- if (read.kind === "missing") return "";
2863
- return JSON.stringify(git_gh_pr_rest.to_pr_info(read.pull));
2864
- }
2865
- async function read_comments(branch_name, to_path, to_json) {
2866
- const pr_number = await resolve_pr_number(branch_name);
2867
- if (pr_number === void 0) return void 0;
2868
- const path = `${to_path(String(pr_number))}${COMMENTS_QUERY}`;
2869
- try {
2870
- return to_json(await git_gh_exec.exec_gh_api({ path, should_paginate: true }));
2871
- } catch {
2872
- return void 0;
2873
- }
2874
- }
2875
- function to_comments_json(raw) {
2876
- return JSON.stringify(git_gh_pr_rest.to_pr_comments(raw));
2877
- }
2878
- function as_served(raw) {
2879
- return raw;
2880
- }
2881
- async function pr_get_comments(branch_name) {
2882
- return await read_comments(branch_name, git_gh_api_path.issue_comments_api_path, to_comments_json);
2883
- }
2884
- async function pr_get_review_comments(branch_name) {
2885
- return await read_comments(branch_name, git_gh_api_path.pull_comments_api_path, as_served);
2886
- }
2887
- var git_gh_pr_read = {
2888
- pr_exists,
2889
- pr_get_number,
2890
- pr_get_url,
2891
- pr_get_body,
2892
- pr_get_merge_state,
2893
- pr_view,
2894
- pr_get_comments,
2895
- pr_get_review_comments
2896
- };
2897
-
2898
- // scripts/gh/git-gh-pr-review.ts
2899
- import { z as z10 } from "zod";
2900
- var REVIEW_APPROVED = "APPROVED";
2901
- var REVIEW_CHANGES_REQUESTED = "CHANGES_REQUESTED";
2902
- var REVIEW_NONE = "";
2903
- var STATE_CHANGING_REVIEWS = /* @__PURE__ */ new Set([REVIEW_APPROVED, REVIEW_CHANGES_REQUESTED]);
2904
- var rest_review_schema = z10.looseObject({
2905
- state: z10.string().optional(),
2906
- user: z10.looseObject({ login: z10.string().optional() }).nullish()
2907
- });
2908
- var NOT_A_REVIEW_LISTING = "gh api answered something other than a review listing";
2909
- function parse_rest_reviews(reviews_json) {
2910
- const parsed = parse_json_array_or_undefined(reviews_json, rest_review_schema);
2911
- if (parsed === void 0) throw new Error(NOT_A_REVIEW_LISTING);
2912
- return parsed;
2913
- }
2914
- var UNATTRIBUTED_REVIEWER = "(no author)";
2915
- function read_reviewer(review) {
2916
- const login = review.user?.login;
2917
- return typeof login === "string" && login.length > 0 ? login : UNATTRIBUTED_REVIEWER;
2918
- }
2919
- function read_state_changing(review) {
2920
- const state = review.state?.toUpperCase();
2921
- return state !== void 0 && STATE_CHANGING_REVIEWS.has(state) ? state : void 0;
2922
- }
2923
- function fold_latest_states(reviews) {
2924
- const latest = /* @__PURE__ */ new Map();
2925
- for (const review of reviews) {
2926
- const state = read_state_changing(review);
2927
- if (state !== void 0) latest.set(read_reviewer(review), state);
2928
- }
2929
- return latest;
2930
- }
2931
- function to_review_decision(reviews_json) {
2932
- const latest = new Set(fold_latest_states(parse_rest_reviews(reviews_json)).values());
2933
- if (latest.has(REVIEW_CHANGES_REQUESTED)) return REVIEW_CHANGES_REQUESTED;
2934
- return latest.has(REVIEW_APPROVED) ? REVIEW_APPROVED : REVIEW_NONE;
2935
- }
2936
- var git_gh_pr_review = { to_review_decision };
2937
-
2938
- // scripts/gh/git-gh-pr-rollup.ts
2939
- import { z as z11 } from "zod";
2940
- var STATUS_CONTEXT_TYPE_NAME = "StatusContext";
2941
- var TYPE_NAME_KEY = "__typename";
2942
- var rollup_element_schema = z11.looseObject({});
2943
- var check_runs_page_schema = z11.looseObject({
2944
- // Required, not optional: GitHub always names the key, and accepting a page without one would
2945
- // answer an empty rollup — which `git-pr-followup.ts` reports as "this branch has no checks".
2946
- check_runs: z11.array(rollup_element_schema)
2947
- });
2948
- var id_holder_schema = z11.object({ id: z11.number() });
2949
- var status_page_schema = z11.looseObject({
2950
- statuses: z11.array(rollup_element_schema)
2951
- });
2952
- var NOT_A_CHECK_RUNS_LISTING = "gh api answered something other than a check run listing";
2953
- var NOT_A_STATUS_LISTING = "gh api answered something other than a commit status listing";
2954
- function read_pages(raw_json, schema, message) {
2955
- const pages = parse_json_array_or_undefined(raw_json, schema);
2956
- if (pages === void 0) throw new Error(message);
2957
- return pages;
2958
- }
2959
- var NO_SUITE = -1;
2960
- function read_id(value) {
2961
- const parsed = id_holder_schema.safeParse(value);
2962
- return parsed.success ? parsed.data.id : void 0;
2963
- }
2964
- function check_run_group_key(run) {
2965
- const { name, app } = run;
2966
- if (typeof name !== "string") return void 0;
2967
- return JSON.stringify([name, read_id(app)]);
2968
- }
2969
- function read_rank(run) {
2970
- const id = read_id(run);
2971
- if (id === void 0) return void 0;
2972
- return { suite: read_id(run["check_suite"]) ?? NO_SUITE, run: id };
2973
- }
2974
- function is_ranked_above(candidate, current) {
2975
- if (candidate.suite !== current.suite) return candidate.suite > current.suite;
2976
- return candidate.run > current.run;
2977
- }
2978
- function should_replace(previous, rank) {
2979
- const previous_rank = previous === void 0 ? void 0 : read_rank(previous);
2980
- return previous_rank === void 0 || is_ranked_above(rank, previous_rank);
2981
- }
2982
- function remember_newest_run(run, newest) {
2983
- const key2 = check_run_group_key(run);
2984
- const rank = read_rank(run);
2985
- if (key2 === void 0 || rank === void 0) return;
2986
- if (should_replace(newest.get(key2), rank)) newest.set(key2, run);
2987
- }
2988
- function is_newest_run(run, newest) {
2989
- const key2 = check_run_group_key(run);
2990
- if (key2 === void 0 || read_rank(run) === void 0) return true;
2991
- return newest.get(key2) === run;
2992
- }
2993
- function to_check_run_items(check_runs_json) {
2994
- const pages = read_pages(check_runs_json, check_runs_page_schema, NOT_A_CHECK_RUNS_LISTING);
2995
- const runs = pages.flatMap((page) => page.check_runs);
2996
- const newest = /* @__PURE__ */ new Map();
2997
- for (const run of runs) remember_newest_run(run, newest);
2998
- return runs.filter((run) => is_newest_run(run, newest));
2999
- }
3000
- function to_status_context_items(status_json) {
3001
- const pages = read_pages(status_json, status_page_schema, NOT_A_STATUS_LISTING);
3002
- return pages.flatMap((page) => page.statuses).map((status) => ({ ...status, [TYPE_NAME_KEY]: STATUS_CONTEXT_TYPE_NAME }));
3003
- }
3004
- function to_status_check_rollup(input) {
3005
- return [
3006
- ...to_check_run_items(input.check_runs_json),
3007
- ...to_status_context_items(input.status_json)
3008
- ];
3009
- }
3010
- var git_gh_pr_rollup = {
3011
- to_status_check_rollup
3012
- };
3013
-
3014
- // scripts/gh/git-gh-pr-snapshot.ts
3015
- var NO_HEAD_SHA_MESSAGE = "gh api answered a pull request with no head commit";
3016
- async function read_object_pages(path) {
3017
- return await git_gh_exec.exec_gh_api({
3018
- path: `${path}${FULL_PAGE_QUERY}`,
3019
- should_paginate: true,
3020
- should_slurp: true
3021
- });
3022
- }
3023
- async function read_array_pages(path) {
3024
- return await git_gh_exec.exec_gh_api({
3025
- path: `${path}${FULL_PAGE_QUERY}`,
3026
- should_paginate: true
3027
- });
3028
- }
3029
- function read_head_sha(pull) {
3030
- const sha = pull.head?.sha;
3031
- if (sha === void 0) throw new Error(NO_HEAD_SHA_MESSAGE);
3032
- return sha;
3033
- }
3034
- async function read_status_check_rollup(commit_sha) {
3035
- const [check_runs_json, status_json] = await Promise.all([
3036
- read_object_pages(git_gh_api_path.commit_check_runs_api_path(commit_sha)),
3037
- read_object_pages(git_gh_api_path.commit_status_api_path(commit_sha))
3038
- ]);
3039
- return git_gh_pr_rollup.to_status_check_rollup({ check_runs_json, status_json });
3040
- }
3041
- async function pr_get_review_decision(pr_number) {
3042
- const path = git_gh_api_path.pull_reviews_api_path(String(pr_number));
3043
- return git_gh_pr_review.to_review_decision(await read_array_pages(path));
3044
- }
3045
- async function build_checks_fields(pull) {
3046
- return {
3047
- statusCheckRollup: await read_status_check_rollup(read_head_sha(pull)),
3048
- mergeStateStatus: to_gh_state(pull.mergeable_state)
3049
- };
3050
- }
3051
- async function resolve_pull(branch_name) {
3052
- const pr_number = await require_pr_number(branch_name);
3053
- return { pr_number, pull: await read_pull(pr_number) };
3054
- }
3055
- async function pr_get_checks_snapshot(branch_name) {
3056
- const { pr_number, pull } = await resolve_pull(branch_name);
3057
- return { pr_number, snapshot_json: JSON.stringify(await build_checks_fields(pull)) };
3058
- }
3059
- async function pr_get_state_snapshot(branch_name) {
3060
- const { pr_number, pull } = await resolve_pull(branch_name);
3061
- const [fields, review_decision] = await Promise.all([
3062
- build_checks_fields(pull),
3063
- pr_get_review_decision(pr_number)
3064
- ]);
3065
- return JSON.stringify({ ...fields, reviewDecision: review_decision });
3066
- }
3067
- var git_gh_pr_snapshot = {
3068
- pr_get_state_snapshot,
3069
- pr_get_checks_snapshot,
3070
- pr_get_review_decision
3071
- };
3072
-
3073
- // scripts/gh/git-gh-pr.ts
3074
- var HTML_URL_FILTER2 = ".html_url";
3075
- var PUT_METHOD = "PUT";
3076
- var PATCH_METHOD2 = "PATCH";
3077
- var MERGE_COMMIT_METHOD = "merge";
3078
- var MERGE_REQUEST_TIMEOUT_MS = 18e4;
3079
- var MERGE_UNCONFIRMED_MESSAGE = "gh api could not read the pull request back after the merge request failed";
3080
- var MERGE_READ_BACK_ATTEMPTS = 3;
3081
- var MERGE_READ_BACK_INTERVAL_MS = 1e3;
3082
- var PR_NUMBER_PATTERN = /\/pull\/([1-9]\d*)$/u;
3083
- var LABELS_SEGMENT2 = "/labels";
3084
- var PR_LABELS = z12.array(z12.object({ name: z12.string() }));
3085
- async function add_pr_classification(number, label) {
3086
- await git_gh_exec.exec_gh_api({
3087
- path: `${git_gh_api_path.issue_api_path(number)}${LABELS_SEGMENT2}`,
3088
- body: JSON.stringify({ labels: [label] })
3089
- });
3090
- }
3091
- async function pr_get_classification(branch_name) {
3092
- const number = await require_pr_number(branch_name);
3093
- const response = await git_gh_exec.exec_gh_api({
3094
- path: `${git_gh_api_path.issue_api_path(String(number))}${LABELS_SEGMENT2}`
3095
- });
3096
- const names = PR_LABELS.parse(JSON.parse(response)).map((label) => label.name.toLowerCase());
3097
- const selected = names.filter((name) => pr_classification.is_classification(name));
3098
- if (selected.length === 0) return void 0;
3099
- const error = pr_classification.classification_error(names, "human");
3100
- if (error !== void 0) throw new Error(error);
3101
- return selected[0];
3102
- }
3103
- async function pr_ensure_classification(branch_name, label) {
3104
- if (await pr_get_classification(branch_name) !== void 0) return;
3105
- const number = await require_pr_number(branch_name);
3106
- await add_pr_classification(String(number), label);
3107
- }
3108
- async function post_pull_request(title, body) {
3109
- const base = await git_command.get_default_branch();
3110
- const head = await git_command.branch();
3111
- forget_pr_numbers();
3112
- try {
3113
- return await git_gh_exec.exec_gh_api({
3114
- path: git_gh_api_path.pulls_api_path(),
3115
- body: JSON.stringify({ title, body, head, base }),
3116
- jq_filter: HTML_URL_FILTER2
3117
- });
3118
- } catch (error) {
3119
- return git_gh_helpers.handle_pr_create_error(error);
3120
- }
3121
- }
3122
- async function pr_create(title, body, label) {
3123
- const classification_error2 = pr_classification.classification_error([label], "human");
3124
- if (classification_error2 !== void 0) throw new Error(classification_error2);
3125
- const url = await post_pull_request(title, body);
3126
- const number = PR_NUMBER_PATTERN.exec(url)?.[1];
3127
- if (number === void 0) throw new Error(`Could not identify the created pull request: ${url}`);
3128
- await add_pr_classification(number, label);
3129
- return url;
3130
- }
3131
- async function pr_comment(branch_name, body) {
3132
- const pr_number = await require_pr_number(branch_name);
3133
- return await git_gh_issue_write.issue_comment(String(pr_number), body);
3134
- }
3135
- async function pr_update_body(branch_name, body) {
3136
- const pr_number = await require_pr_number(branch_name);
3137
- forget_pr_numbers();
3138
- await git_gh_exec.exec_gh_api({
3139
- path: git_gh_api_path.pull_api_path(String(pr_number)),
3140
- method: PATCH_METHOD2,
3141
- body: JSON.stringify({ body })
3142
- });
3143
- }
3144
- async function put_merge(pr_number) {
3145
- forget_pr_numbers();
3146
- await git_gh_exec.exec_gh_api({
3147
- path: git_gh_api_path.pull_merge_api_path(String(pr_number)),
3148
- method: PUT_METHOD,
3149
- body: JSON.stringify({ merge_method: MERGE_COMMIT_METHOD }),
3150
- timeout_ms: MERGE_REQUEST_TIMEOUT_MS
3151
- });
3152
- }
3153
- async function read_merge_state(pr_number) {
3154
- try {
3155
- return git_gh_pr_rest.is_merged(await read_pull(pr_number));
3156
- } catch (error) {
3157
- console.warn(`Could not read the pull request back: ${String(error)}`);
3158
- return void 0;
3159
- }
3160
- }
3161
- async function sleep_between_read_backs(attempt) {
3162
- if (attempt < MERGE_READ_BACK_ATTEMPTS - 1) await poll.sleep(MERGE_READ_BACK_INTERVAL_MS);
3163
- }
3164
- async function has_merge_landed(pr_number, merge_error) {
3165
- for (let attempt = 0; attempt < MERGE_READ_BACK_ATTEMPTS; attempt += 1) {
3166
- const is_merged2 = await read_merge_state(pr_number);
3167
- if (is_merged2 !== void 0) return is_merged2;
3168
- await sleep_between_read_backs(attempt);
3169
- }
3170
- throw new Error(MERGE_UNCONFIRMED_MESSAGE, { cause: merge_error });
3171
- }
3172
- async function pr_merge(branch_name) {
3173
- const pr_number = await require_pr_number(branch_name);
3174
- try {
3175
- await put_merge(pr_number);
3176
- } catch (error) {
3177
- if (!await has_merge_landed(pr_number, error)) throw error;
3178
- }
3179
- }
3180
- var git_gh_pr = {
3181
- ...git_gh_pr_read,
3182
- ...git_gh_pr_snapshot,
3183
- pr_create,
3184
- pr_get_classification,
3185
- pr_ensure_classification,
3186
- pr_comment,
3187
- pr_merge,
3188
- pr_update_body
3189
- };
3190
-
3191
- // scripts/gh/git-gh-pr-auto-merge.ts
3192
- var GRAPHQL_PATH = "graphql";
3193
- var OPEN_PULLS_QUERY = `${git_gh_api_path.FULL_PAGE_QUERY}&state=open`;
3194
- var MISSING_NODE_ID_MESSAGE = "gh api answered a pull request without a node_id";
3195
- var ENABLE_AUTO_MERGE_MUTATION = "mutation($id: ID!) { enablePullRequestAutoMerge(input: { pullRequestId: $id, mergeMethod: MERGE }) { clientMutationId } }";
3196
- async function pr_enable_auto_merge(branch_name) {
3197
- const pull = await read_pull(await require_pr_number(branch_name));
3198
- if (pull.node_id === void 0) throw new Error(MISSING_NODE_ID_MESSAGE);
3199
- await git_gh_exec.exec_gh_api({
3200
- path: GRAPHQL_PATH,
3201
- body: JSON.stringify({ query: ENABLE_AUTO_MERGE_MUTATION, variables: { id: pull.node_id } })
3202
- });
3203
- }
3204
- async function pr_is_merged(branch_name) {
3205
- try {
3206
- return git_gh_pr_rest.is_merged(await read_pull(await require_pr_number(branch_name)));
3207
- } catch (error) {
3208
- error_text.trace_swallowed("git_gh_pr_auto_merge.pr_is_merged", error);
3209
- return false;
3210
- }
3211
- }
3212
- function head_reference_of(pull) {
3213
- return pull.head?.ref ?? "";
3214
- }
3215
- function has_head_prefix(pull, prefix) {
3216
- return git_gh_pr_rest.is_same_repository_head(pull) && head_reference_of(pull).startsWith(prefix);
3217
- }
3218
- function to_open_pull(pull) {
3219
- return {
3220
- number: pull.number,
3221
- head_ref: head_reference_of(pull),
3222
- has_auto_merge: pull.auto_merge !== null && pull.auto_merge !== void 0
3223
- };
3224
- }
3225
- async function pr_list_open_with_head_prefix(prefix) {
3226
- const json = await git_gh_exec.exec_gh_api({
3227
- path: `${git_gh_api_path.pulls_api_path()}${OPEN_PULLS_QUERY}`,
3228
- should_paginate: true
3229
- });
3230
- return git_gh_pr_rest.parse_rest_pulls(json).filter((pull) => has_head_prefix(pull, prefix)).map((pull) => to_open_pull(pull));
3231
- }
3232
- var git_gh_pr_auto_merge = {
3233
- pr_enable_auto_merge,
3234
- pr_is_merged,
3235
- pr_list_open_with_head_prefix
3236
- };
3237
-
3238
- // scripts/gh/git-gh-repo.ts
3239
- async function repo_get_name_with_owner() {
3240
- try {
3241
- const result = await git_gh_exec.exec_gh_api({
3242
- path: git_gh_api_path.repo_api_path(),
3243
- jq_filter: ".full_name"
3244
- });
3245
- return git_gh_helpers.parse_pr_state_string(result);
3246
- } catch {
3247
- return void 0;
3248
- }
3249
- }
3250
- var git_gh_repo = {
3251
- repo_get_name_with_owner
3252
- };
3253
-
3254
- // scripts/gh/git-pr-checks.ts
3255
- var SECONDS_TO_MS = 1e3;
3256
- var CHECK_WAIT_INTERVAL_MS = 1e4;
3257
- var DEFAULT_TIMEOUT_SECONDS = 1920;
3258
- function compute_max_attempts(timeout_seconds, interval_ms) {
3259
- return Math.ceil(timeout_seconds / (interval_ms / SECONDS_TO_MS)) + 1;
3260
- }
3261
- var DEFAULT_MAX_ATTEMPTS = compute_max_attempts(DEFAULT_TIMEOUT_SECONDS, CHECK_WAIT_INTERVAL_MS);
3262
- function get_configured_max_attempts() {
3263
- const environment_seconds = Number(process.env["JOSH_CI_TIMEOUT_SECONDS"]);
3264
- return Number.isFinite(environment_seconds) && environment_seconds > 0 ? compute_max_attempts(environment_seconds, CHECK_WAIT_INTERVAL_MS) : DEFAULT_MAX_ATTEMPTS;
3265
- }
3266
- var CHECK_MAX_ATTEMPTS = get_configured_max_attempts();
3267
- var DEFAULT_STABLE_READS = 2;
3268
- var MAX_CONSECUTIVE_READ_FAILURES = 3;
3269
- var PR_CHECKS_TIMEOUT_MESSAGE = "Timed out while waiting for PR checks to complete.";
3270
- function is_pr_checks_timeout(error) {
3271
- return error instanceof Error && error.message === PR_CHECKS_TIMEOUT_MESSAGE;
3272
- }
3273
- function should_always_read_review_decision() {
3274
- return true;
3275
- }
3276
- var MERGE_GATE_EVALUATOR = {
3277
- evaluate: evaluate_pr_state,
3278
- describe: describe_pr_failure,
3279
- should_read_review_decision: is_review_decision_decisive
3280
- };
3281
- function advance_stable_count(previous, state) {
3282
- return state === "success" ? previous + 1 : 0;
3283
- }
3284
- function failure_error(message, snapshot) {
3285
- return is_merge_conflict(snapshot.merge_state_status) ? new PrConflictError(message) : new Error(message);
3286
- }
3287
- function classify_poll_result(input) {
3288
- const state = input.evaluator.evaluate(input.snapshot);
3289
- if (state === "failure") {
3290
- throw failure_error(input.evaluator.describe(input.snapshot), input.snapshot);
3291
- }
3292
- const next_stable_count = advance_stable_count(input.stable_count, state);
3293
- return {
3294
- is_done: next_stable_count >= input.required_stable_reads,
3295
- next_stable_count
3296
- };
3297
- }
3298
- async function read_pr_state(input, evaluator) {
3299
- try {
3300
- const snapshot = await input.options.fetcher(
3301
- input.options.branch_name,
3302
- evaluator.should_read_review_decision ?? should_always_read_review_decision
3303
- );
3304
- return { kind: "read", snapshot };
3305
- } catch (error) {
3306
- return { kind: "unreadable", cause: error };
3307
- }
3308
- }
3309
- async function sleep_before_next_attempt(input) {
3310
- if (input.attempt < input.options.max_attempts - 1) {
3311
- await poll.sleep(input.options.interval_ms);
3312
- }
3313
- }
3314
- async function retry_after_unreadable(input, cause) {
3315
- const next_failure_count = input.failure_count + 1;
3316
- if (next_failure_count >= MAX_CONSECUTIVE_READ_FAILURES) throw cause;
3317
- console.warn(
3318
- `Could not read the PR state (${String(next_failure_count)}/${String(MAX_CONSECUTIVE_READ_FAILURES)}); asking again on the next poll: ${String(cause)}`
3319
- );
3320
- await sleep_before_next_attempt(input);
3321
- return { next_stable_count: 0, next_failure_count, read_failure: cause };
3322
- }
3323
- function to_exhaustion_error(last_read_failure) {
3324
- return last_read_failure ?? new Error(PR_CHECKS_TIMEOUT_MESSAGE);
3325
- }
3326
- async function attempt_pr_success_poll(input) {
3327
- const evaluator = input.options.evaluator ?? MERGE_GATE_EVALUATOR;
3328
- const read = await read_pr_state(input, evaluator);
3329
- if (read.kind === "unreadable") return await retry_after_unreadable(input, read.cause);
3330
- const classification = classify_poll_result({
3331
- snapshot: read.snapshot,
3332
- stable_count: input.stable_count,
3333
- required_stable_reads: input.options.required_stable_reads,
3334
- evaluator
3335
- });
3336
- if (classification.is_done) {
3337
- return { snapshot: read.snapshot, next_stable_count: 0, next_failure_count: 0 };
3338
- }
3339
- await sleep_before_next_attempt(input);
3340
- return { next_stable_count: classification.next_stable_count, next_failure_count: 0 };
3341
- }
3342
- async function wait_for_pr_success(options) {
3343
- let carried = { next_stable_count: 0, next_failure_count: 0 };
3344
- for (let attempt = 0; attempt < options.max_attempts; attempt += 1) {
3345
- console.info(`Checking PR status\u2026 (${String(attempt + 1)}/${String(options.max_attempts)})`);
3346
- await options.before_poll?.();
3347
- carried = await attempt_pr_success_poll({
3348
- options,
3349
- stable_count: carried.next_stable_count,
3350
- failure_count: carried.next_failure_count,
3351
- attempt
3352
- });
3353
- if (carried.snapshot !== void 0) return carried.snapshot;
3354
- }
3355
- throw to_exhaustion_error(carried.read_failure);
3356
- }
3357
- async function default_fetch_pr_state(branch_name, should_read_review_decision = should_always_read_review_decision) {
3358
- const checks = await git_gh_pr_snapshot.pr_get_checks_snapshot(branch_name);
3359
- const snapshot = parse_pr_state_snapshot(checks.snapshot_json);
3360
- if (!should_read_review_decision(snapshot)) return snapshot;
3361
- const decision = await git_gh_pr_snapshot.pr_get_review_decision(checks.pr_number);
3362
- return { ...snapshot, review_decision: read_string(decision) };
3363
- }
3364
- function observed_fetcher(observe) {
3365
- if (observe === void 0) return default_fetch_pr_state;
3366
- return async function fetch_observed(branch_name, should_read_review_decision) {
3367
- const snapshot = await default_fetch_pr_state(branch_name, should_read_review_decision);
3368
- await observe(snapshot);
3369
- return snapshot;
3370
- };
3371
- }
3372
-
3373
- // scripts/gh/git-pr-checks-watch.ts
3374
- var PR_CHECKS_WATCH_TIMEOUT_MS = 12e4;
3375
- var WATCH_TIMED_OUT_NOTE = "\u23F1\uFE0F pr checks --watch timed out.";
3376
- var NO_CHECKS_MESSAGE = "gh api reported no checks on the branch";
3377
- var CHECKS_FAILED_MESSAGE = "gh api reported a failing check on the branch";
3378
- function is_awaited_check(check) {
3379
- return !is_coderabbit_check(check.name) || is_required_check(check.name);
3380
- }
3381
- function evaluate_checks_settled(snapshot) {
3382
- const awaited = snapshot.rollup.filter((check) => is_awaited_check(check));
3383
- const considered = awaited.length === 0 ? snapshot.rollup : awaited;
3384
- if (considered.length === 0 || considered.some((check) => check.status === CHECK_STATUS_PENDING)) {
3385
- return "pending";
3386
- }
3387
- return snapshot.rollup.some((check) => check.status === CHECK_STATUS_FAIL) ? "failure" : "success";
3388
- }
3389
- function describe_checks_failure(snapshot) {
3390
- const failed = snapshot.rollup.filter((check) => check.status === CHECK_STATUS_FAIL);
3391
- return `${CHECKS_FAILED_MESSAGE}: ${failed.map((check) => check.name).join(", ")}`;
3392
- }
3393
- function should_never_read_review_decision() {
3394
- return false;
3395
- }
3396
- var CHECKS_SETTLED_EVALUATOR = {
3397
- evaluate: evaluate_checks_settled,
3398
- describe: describe_checks_failure,
3399
- should_read_review_decision: should_never_read_review_decision
3400
- };
3401
- async function watch_until_settled(branch_name, observe) {
3402
- await wait_for_pr_success({
3403
- branch_name,
3404
- fetcher: observed_fetcher(observe),
3405
- interval_ms: CHECK_WAIT_INTERVAL_MS,
3406
- max_attempts: compute_max_attempts(
3407
- PR_CHECKS_WATCH_TIMEOUT_MS / SECONDS_TO_MS,
3408
- CHECK_WAIT_INTERVAL_MS
3409
- ),
3410
- required_stable_reads: DEFAULT_STABLE_READS,
3411
- evaluator: CHECKS_SETTLED_EVALUATOR
3412
- });
3413
- }
3414
- async function fail_when_no_checks(branch_name) {
3415
- const snapshot = await default_fetch_pr_state(branch_name, should_never_read_review_decision);
3416
- if (snapshot.rollup.length === 0) throw new Error(NO_CHECKS_MESSAGE);
3417
- }
3418
- async function pr_checks_watch(branch_name, observe) {
3419
- try {
3420
- await watch_until_settled(branch_name, observe);
3421
- return { timed_out: false };
3422
- } catch (error) {
3423
- if (!is_pr_checks_timeout(error)) throw error;
3424
- await fail_when_no_checks(branch_name);
3425
- console.info(WATCH_TIMED_OUT_NOTE);
3426
- return { timed_out: true };
3427
- }
3428
- }
3429
- var git_pr_checks_watch = { pr_checks_watch };
3430
-
3431
- // scripts/gh/git-gh-command.ts
3432
- var git_gh_command = {
3433
- ...git_gh_pr,
3434
- ...git_gh_pr_auto_merge,
3435
- pr_checks_watch: git_pr_checks_watch.pr_checks_watch,
3436
- ...git_gh_issue,
3437
- ...git_gh_repo
3438
- };
3439
-
3440
- // scripts/gh/gh-spawn.ts
3441
- var NO_BUDGET = 0;
3442
- function fetch_repo_name(timeout_ms) {
3443
- const stdout = git_gh_exec.read_gh_api_sync({
3444
- path: git_gh_api_path.repo_api_path(),
3445
- jq_filter: ".full_name",
3446
- cwd: PROJECT_ROOT,
3447
- timeout_ms: timeout_ms ?? NO_BUDGET
3448
- });
3449
- const name = stdout?.trim();
3450
- return name === "" ? void 0 : name;
3451
- }
3452
- function get_repo_name_with_owner() {
3453
- return fetch_repo_name(void 0);
3454
- }
3455
- function get_repo_name_with_owner_within(timeout_ms) {
3456
- return fetch_repo_name(timeout_ms);
3457
- }
3458
- var gh_spawn = { get_repo_name_with_owner, get_repo_name_with_owner_within };
3459
-
3460
- export {
3461
- bounded_pool,
3462
- git_gh_api_path,
3463
- read_json_listing,
3464
- parse_json_object_or_undefined,
3465
- has_stdout_field,
3466
- git_gh_exec,
3467
- git_gh_issue_read,
3468
- issue_watch_diff,
3469
- issue_citation,
3470
- session_cite,
3471
- shell_segments,
3472
- bash_triggers,
3473
- tail_commands,
3474
- filing_cap,
3475
- CONTEXT_CUT_THRESHOLD,
3476
- run_hold,
3477
- run_cut_handoff,
3478
- run_cut,
3479
- run_tail_rule,
3480
- lane_background,
3481
- IN_PROGRESS_LABEL,
3482
- NEEDS_DECISION_LABEL,
3483
- RUN_SOLO_LABEL,
3484
- RUN_LANE_LABEL,
3485
- NEEDS_HUMAN_REVIEW_LABEL,
3486
- ALREADY_DONE_LABEL,
3487
- has_any_label,
3488
- has_label_name,
3489
- lane_handoff,
3490
- lane_park,
3491
- gh_spawn,
3492
- repo_party,
3493
- git_gh_pr_read,
3494
- git_gh_command
3495
- };