@moberg_hr/work-tree 2.0.6 → 2.0.8

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 (180) hide show
  1. package/dist/{answer-AX2VHEXS.js → answer-QQAEJ5N3.js} +4 -4
  2. package/dist/{attach-WLJVKXOJ.js → attach-XG3Y7QA7.js} +6 -6
  3. package/dist/bin.js +2 -2
  4. package/dist/{block-NZJC7GVM.js → block-WW4BWDN7.js} +5 -5
  5. package/dist/{broadcast-JPVHPQ6Y.js → broadcast-LEOMDVSA.js} +2 -2
  6. package/dist/{catchup-RUNKM6ZH.js → catchup-UBHGEMED.js} +7 -7
  7. package/dist/chunk-34QBYOHC.js +9 -0
  8. package/dist/{chunk-BSCAA322.js → chunk-4V7C3O6V.js} +22 -8
  9. package/dist/chunk-4V7C3O6V.js.map +1 -0
  10. package/dist/{chunk-46UD4QBL.js → chunk-5RRKVAIZ.js} +3 -2
  11. package/dist/chunk-5RRKVAIZ.js.map +1 -0
  12. package/dist/{chunk-EK3WRCQX.js → chunk-6AULWNAN.js} +3 -3
  13. package/dist/{chunk-UI5MPBIH.js → chunk-73J2ZJA6.js} +3 -3
  14. package/dist/{chunk-ES3KY6YT.js → chunk-7IZW6GLY.js} +2 -2
  15. package/dist/chunk-BLCAZAU5.js +334 -0
  16. package/dist/chunk-BLCAZAU5.js.map +1 -0
  17. package/dist/{chunk-G2O7EIKX.js → chunk-E72ETFAB.js} +2 -2
  18. package/dist/{chunk-7OUBCJVJ.js → chunk-E74YIDHX.js} +6 -6
  19. package/dist/{chunk-X5EMINGT.js → chunk-EN24GJCO.js} +4 -4
  20. package/dist/{chunk-5S3ORHTD.js → chunk-F3SPCHLH.js} +6 -6
  21. package/dist/{chunk-DUUH6FPH.js → chunk-G5PN5NIS.js} +28 -4
  22. package/dist/chunk-G5PN5NIS.js.map +1 -0
  23. package/dist/{chunk-65DPISNE.js → chunk-HLXEMPEI.js} +2 -2
  24. package/dist/{chunk-52IEEAYJ.js → chunk-I5HHTEAA.js} +4 -4
  25. package/dist/{chunk-CK2QC2UF.js → chunk-IC5PFQCV.js} +2 -2
  26. package/dist/{chunk-ED7E2WKK.js → chunk-JYWCNLZN.js} +2 -2
  27. package/dist/{chunk-LZHCTPBF.js → chunk-KLK6O54M.js} +3 -3
  28. package/dist/{chunk-FOG4WG3Y.js → chunk-LNMIG35F.js} +6 -2
  29. package/dist/chunk-LNMIG35F.js.map +1 -0
  30. package/dist/{chunk-67IZNVDI.js → chunk-LXM7QFBK.js} +2 -2
  31. package/dist/chunk-MFSKRN2J.js +78 -0
  32. package/dist/chunk-MFSKRN2J.js.map +1 -0
  33. package/dist/{chunk-HIXC67MU.js → chunk-MXZRFWC3.js} +3 -3
  34. package/dist/{chunk-KZQDONTU.js → chunk-NIRVJMJL.js} +12 -5
  35. package/dist/chunk-NIRVJMJL.js.map +1 -0
  36. package/dist/{chunk-HZEYGMYK.js → chunk-P2U6R35K.js} +3 -3
  37. package/dist/{chunk-ESPZRTUB.js → chunk-PG2MPTZD.js} +4 -4
  38. package/dist/{chunk-XHOQ7BWT.js → chunk-QQNI3K3V.js} +3 -3
  39. package/dist/{chunk-YCDULFF5.js → chunk-SIHAOB4F.js} +3 -3
  40. package/dist/{chunk-MODMK7WQ.js → chunk-ULQQ6SXT.js} +3 -3
  41. package/dist/{chunk-R7BXN427.js → chunk-UNLBHYA5.js} +2 -2
  42. package/dist/{chunk-XBNLSKTX.js → chunk-UZROMRQM.js} +3 -3
  43. package/dist/{chunk-UNPEZODB.js → chunk-V4RQ72HY.js} +28 -20
  44. package/dist/chunk-V4RQ72HY.js.map +1 -0
  45. package/dist/{chunk-QQJF4R6J.js → chunk-WB2BP2G5.js} +2 -2
  46. package/dist/{chunk-5653XPLJ.js → chunk-WOCS6MLE.js} +42 -42
  47. package/dist/{chunk-6GCF2XWP.js → chunk-WTR5BUGS.js} +20 -1
  48. package/dist/chunk-WTR5BUGS.js.map +1 -0
  49. package/dist/{chunk-WQMY4AJR.js → chunk-WUWED3LV.js} +2 -2
  50. package/dist/{chunk-N23HFT4X.js → chunk-YZSSYD2G.js} +244 -54
  51. package/dist/chunk-YZSSYD2G.js.map +1 -0
  52. package/dist/{cleanup-QLN3C3H5.js → cleanup-6LIZ3BQF.js} +16 -15
  53. package/dist/{cleanup-QLN3C3H5.js.map → cleanup-6LIZ3BQF.js.map} +1 -1
  54. package/dist/{cli-MIBNJRX6.js → cli-R3FITDNB.js} +3 -3
  55. package/dist/{config-TPYNBTVM.js → config-DULJPECI.js} +6 -6
  56. package/dist/{diff-IDF3K74H.js → diff-2PPFXZD6.js} +4 -4
  57. package/dist/{digest-AXSMYBYS.js → digest-5CRGAAK5.js} +4 -4
  58. package/dist/{fork-Y4PJNRUB.js → fork-FYEV4TU2.js} +15 -13
  59. package/dist/{fork-Y4PJNRUB.js.map → fork-FYEV4TU2.js.map} +1 -1
  60. package/dist/{hook-QMW5HHNP.js → hook-U37AFPKY.js} +4 -4
  61. package/dist/{hydrate-XMHHC5EG.js → hydrate-MAFHTY2W.js} +2 -2
  62. package/dist/{init-NGL64E3F.js → init-276XRZS2.js} +6 -6
  63. package/dist/{move-FFQR5TEI.js → move-QHCDO2R5.js} +14 -15
  64. package/dist/move-QHCDO2R5.js.map +1 -0
  65. package/dist/{note-C4RNIDRJ.js → note-TNC633NG.js} +4 -4
  66. package/dist/{overlaps-3LZXSDYZ.js → overlaps-SEK7H2YB.js} +5 -5
  67. package/dist/{pin-TJBCJGPQ.js → pin-E53PGMGD.js} +4 -4
  68. package/dist/{pr-JM4DRRIV.js → pr-JMMUGCKS.js} +5 -5
  69. package/dist/{prune-63N3QNDR.js → prune-MR37KLIW.js} +15 -14
  70. package/dist/{prune-63N3QNDR.js.map → prune-MR37KLIW.js.map} +1 -1
  71. package/dist/{pty-host-MQSUN6EI.js → pty-host-36Y4XSPP.js} +14 -7
  72. package/dist/pty-host-36Y4XSPP.js.map +1 -0
  73. package/dist/{read-NU4WZ3J5.js → read-ESOOJSBO.js} +4 -4
  74. package/dist/{recent-ZW4WDGCK.js → recent-3WYFF36X.js} +2 -2
  75. package/dist/{remove-ADWLTOFS.js → remove-5IZVMK4V.js} +14 -13
  76. package/dist/{remove-ADWLTOFS.js.map → remove-5IZVMK4V.js.map} +1 -1
  77. package/dist/{resume-SLNE75JO.js → resume-NDE6NKKT.js} +2 -2
  78. package/dist/{run-MD77Z2BV.js → run-UW4BJCSC.js} +2 -2
  79. package/dist/{screen-RCUGD52V.js → screen-5BLTXIKS.js} +4 -4
  80. package/dist/{search-5GK5HL4Y.js → search-MK6R5VR6.js} +2 -2
  81. package/dist/{section-OAMRNSO7.js → section-B4BWRY7K.js} +4 -4
  82. package/dist/{send-TT6U64HQ.js → send-OT3OXHHW.js} +5 -5
  83. package/dist/{sessions-CAOAXKKG.js → sessions-LHMTS6KT.js} +12 -10
  84. package/dist/{sessions-CAOAXKKG.js.map → sessions-LHMTS6KT.js.map} +1 -1
  85. package/dist/{snooze-DBJJD6ZM.js → snooze-A2BVEYWD.js} +4 -4
  86. package/dist/{start-2KUDSMBM.js → start-LEYVJWZG.js} +4 -4
  87. package/dist/{status-S3NZTRG3.js → status-AO653RKW.js} +2 -2
  88. package/dist/{stop-KJHXWYZ2.js → stop-QYIRUR5Y.js} +4 -4
  89. package/dist/{sync-EVPQVVWT.js → sync-SAZVBQIH.js} +15 -14
  90. package/dist/{sync-EVPQVVWT.js.map → sync-SAZVBQIH.js.map} +1 -1
  91. package/dist/{time-MWABXPA6.js → time-4V56YERF.js} +5 -5
  92. package/dist/{tree-O4VADOFG.js → tree-WFOG72Z3.js} +37 -6
  93. package/dist/tree-WFOG72Z3.js.map +1 -0
  94. package/dist/{update-K73WHYY3.js → update-NU5EMISM.js} +7 -7
  95. package/dist/{wait-JZIJB6P6.js → wait-FW7RARBV.js} +5 -5
  96. package/dist/wd-bin.js +2 -2
  97. package/dist/web/assets/PtyView-DQw8g-PN.js +90 -0
  98. package/dist/web/assets/PtyView-DQw8g-PN.js.map +1 -0
  99. package/dist/web/assets/index-CO_OtClq.js +118 -0
  100. package/dist/web/assets/index-CO_OtClq.js.map +1 -0
  101. package/dist/web/assets/index-D-_oxT3O.css +1 -0
  102. package/dist/web/index.html +2 -2
  103. package/dist/{web-GN2ATEXW.js → web-DTVGZZDZ.js} +199 -335
  104. package/dist/web-DTVGZZDZ.js.map +1 -0
  105. package/npm-shrinkwrap.json +2 -2
  106. package/package.json +1 -1
  107. package/dist/chunk-46UD4QBL.js.map +0 -1
  108. package/dist/chunk-6GCF2XWP.js.map +0 -1
  109. package/dist/chunk-BSCAA322.js.map +0 -1
  110. package/dist/chunk-DUUH6FPH.js.map +0 -1
  111. package/dist/chunk-FOG4WG3Y.js.map +0 -1
  112. package/dist/chunk-KZQDONTU.js.map +0 -1
  113. package/dist/chunk-MNZOOANK.js +0 -9
  114. package/dist/chunk-N23HFT4X.js.map +0 -1
  115. package/dist/chunk-UNPEZODB.js.map +0 -1
  116. package/dist/move-FFQR5TEI.js.map +0 -1
  117. package/dist/pty-host-MQSUN6EI.js.map +0 -1
  118. package/dist/tree-O4VADOFG.js.map +0 -1
  119. package/dist/web/assets/PtyView-DBMOq3Ro.js +0 -90
  120. package/dist/web/assets/PtyView-DBMOq3Ro.js.map +0 -1
  121. package/dist/web/assets/index-CV8NpZB8.css +0 -1
  122. package/dist/web/assets/index-DvFWtkAs.js +0 -117
  123. package/dist/web/assets/index-DvFWtkAs.js.map +0 -1
  124. package/dist/web-GN2ATEXW.js.map +0 -1
  125. /package/dist/{answer-AX2VHEXS.js.map → answer-QQAEJ5N3.js.map} +0 -0
  126. /package/dist/{attach-WLJVKXOJ.js.map → attach-XG3Y7QA7.js.map} +0 -0
  127. /package/dist/{block-NZJC7GVM.js.map → block-WW4BWDN7.js.map} +0 -0
  128. /package/dist/{broadcast-JPVHPQ6Y.js.map → broadcast-LEOMDVSA.js.map} +0 -0
  129. /package/dist/{catchup-RUNKM6ZH.js.map → catchup-UBHGEMED.js.map} +0 -0
  130. /package/dist/{chunk-MNZOOANK.js.map → chunk-34QBYOHC.js.map} +0 -0
  131. /package/dist/{chunk-EK3WRCQX.js.map → chunk-6AULWNAN.js.map} +0 -0
  132. /package/dist/{chunk-UI5MPBIH.js.map → chunk-73J2ZJA6.js.map} +0 -0
  133. /package/dist/{chunk-ES3KY6YT.js.map → chunk-7IZW6GLY.js.map} +0 -0
  134. /package/dist/{chunk-G2O7EIKX.js.map → chunk-E72ETFAB.js.map} +0 -0
  135. /package/dist/{chunk-7OUBCJVJ.js.map → chunk-E74YIDHX.js.map} +0 -0
  136. /package/dist/{chunk-X5EMINGT.js.map → chunk-EN24GJCO.js.map} +0 -0
  137. /package/dist/{chunk-5S3ORHTD.js.map → chunk-F3SPCHLH.js.map} +0 -0
  138. /package/dist/{chunk-65DPISNE.js.map → chunk-HLXEMPEI.js.map} +0 -0
  139. /package/dist/{chunk-52IEEAYJ.js.map → chunk-I5HHTEAA.js.map} +0 -0
  140. /package/dist/{chunk-CK2QC2UF.js.map → chunk-IC5PFQCV.js.map} +0 -0
  141. /package/dist/{chunk-ED7E2WKK.js.map → chunk-JYWCNLZN.js.map} +0 -0
  142. /package/dist/{chunk-LZHCTPBF.js.map → chunk-KLK6O54M.js.map} +0 -0
  143. /package/dist/{chunk-67IZNVDI.js.map → chunk-LXM7QFBK.js.map} +0 -0
  144. /package/dist/{chunk-HIXC67MU.js.map → chunk-MXZRFWC3.js.map} +0 -0
  145. /package/dist/{chunk-HZEYGMYK.js.map → chunk-P2U6R35K.js.map} +0 -0
  146. /package/dist/{chunk-ESPZRTUB.js.map → chunk-PG2MPTZD.js.map} +0 -0
  147. /package/dist/{chunk-XHOQ7BWT.js.map → chunk-QQNI3K3V.js.map} +0 -0
  148. /package/dist/{chunk-YCDULFF5.js.map → chunk-SIHAOB4F.js.map} +0 -0
  149. /package/dist/{chunk-MODMK7WQ.js.map → chunk-ULQQ6SXT.js.map} +0 -0
  150. /package/dist/{chunk-R7BXN427.js.map → chunk-UNLBHYA5.js.map} +0 -0
  151. /package/dist/{chunk-XBNLSKTX.js.map → chunk-UZROMRQM.js.map} +0 -0
  152. /package/dist/{chunk-QQJF4R6J.js.map → chunk-WB2BP2G5.js.map} +0 -0
  153. /package/dist/{chunk-5653XPLJ.js.map → chunk-WOCS6MLE.js.map} +0 -0
  154. /package/dist/{chunk-WQMY4AJR.js.map → chunk-WUWED3LV.js.map} +0 -0
  155. /package/dist/{cli-MIBNJRX6.js.map → cli-R3FITDNB.js.map} +0 -0
  156. /package/dist/{config-TPYNBTVM.js.map → config-DULJPECI.js.map} +0 -0
  157. /package/dist/{diff-IDF3K74H.js.map → diff-2PPFXZD6.js.map} +0 -0
  158. /package/dist/{digest-AXSMYBYS.js.map → digest-5CRGAAK5.js.map} +0 -0
  159. /package/dist/{hook-QMW5HHNP.js.map → hook-U37AFPKY.js.map} +0 -0
  160. /package/dist/{hydrate-XMHHC5EG.js.map → hydrate-MAFHTY2W.js.map} +0 -0
  161. /package/dist/{init-NGL64E3F.js.map → init-276XRZS2.js.map} +0 -0
  162. /package/dist/{note-C4RNIDRJ.js.map → note-TNC633NG.js.map} +0 -0
  163. /package/dist/{overlaps-3LZXSDYZ.js.map → overlaps-SEK7H2YB.js.map} +0 -0
  164. /package/dist/{pin-TJBCJGPQ.js.map → pin-E53PGMGD.js.map} +0 -0
  165. /package/dist/{pr-JM4DRRIV.js.map → pr-JMMUGCKS.js.map} +0 -0
  166. /package/dist/{read-NU4WZ3J5.js.map → read-ESOOJSBO.js.map} +0 -0
  167. /package/dist/{recent-ZW4WDGCK.js.map → recent-3WYFF36X.js.map} +0 -0
  168. /package/dist/{resume-SLNE75JO.js.map → resume-NDE6NKKT.js.map} +0 -0
  169. /package/dist/{run-MD77Z2BV.js.map → run-UW4BJCSC.js.map} +0 -0
  170. /package/dist/{screen-RCUGD52V.js.map → screen-5BLTXIKS.js.map} +0 -0
  171. /package/dist/{search-5GK5HL4Y.js.map → search-MK6R5VR6.js.map} +0 -0
  172. /package/dist/{section-OAMRNSO7.js.map → section-B4BWRY7K.js.map} +0 -0
  173. /package/dist/{send-TT6U64HQ.js.map → send-OT3OXHHW.js.map} +0 -0
  174. /package/dist/{snooze-DBJJD6ZM.js.map → snooze-A2BVEYWD.js.map} +0 -0
  175. /package/dist/{start-2KUDSMBM.js.map → start-LEYVJWZG.js.map} +0 -0
  176. /package/dist/{status-S3NZTRG3.js.map → status-AO653RKW.js.map} +0 -0
  177. /package/dist/{stop-KJHXWYZ2.js.map → stop-QYIRUR5Y.js.map} +0 -0
  178. /package/dist/{time-MWABXPA6.js.map → time-4V56YERF.js.map} +0 -0
  179. /package/dist/{update-K73WHYY3.js.map → update-NU5EMISM.js.map} +0 -0
  180. /package/dist/{wait-JZIJB6P6.js.map → wait-FW7RARBV.js.map} +0 -0
@@ -0,0 +1,334 @@
1
+ #!/usr/bin/env node
2
+ import {
3
+ originUrl,
4
+ ownerRepo,
5
+ readGitConfig
6
+ } from "./chunk-4V7C3O6V.js";
7
+ import {
8
+ defaultRunner
9
+ } from "./chunk-5RRKVAIZ.js";
10
+
11
+ // src/core/pr/pr-ref.ts
12
+ function parsePrRef(input) {
13
+ const s = input.trim();
14
+ const url = /^(?:https?:\/\/)?(?:www\.)?github\.com\/([^/\s]+)\/([^/\s]+)\/pull\/(\d+)(?:[/?#].*)?$/i.exec(s);
15
+ if (url) return { repo: `${url[1]}/${url[2]}`.toLowerCase(), number: Number(url[3]) };
16
+ const n = /^#?(\d+)$/.exec(s);
17
+ return n && Number(n[1]) > 0 ? { number: Number(n[1]) } : null;
18
+ }
19
+ function workOnPrPrompt(pr, instruction) {
20
+ const who = pr.author ? `@${pr.author}` : "its author";
21
+ const todo = instruction?.trim();
22
+ const upToSpeed = `Get up to speed first (gh pr view ${pr.number}, gh pr diff ${pr.number})`;
23
+ return [
24
+ `Work on PR #${pr.number} by ${who}: ${pr.title}`,
25
+ pr.url,
26
+ "",
27
+ `This worktree is on ${who}'s branch: what you commit and push lands in their PR.`,
28
+ ...todo ? [`${upToSpeed}, then:`, "", todo, ""] : [`${upToSpeed}, tell me where it stands, and wait for what I want done.`],
29
+ "Don't post on GitHub (no comments, reviews or replies)."
30
+ ].join("\n");
31
+ }
32
+
33
+ // src/core/pr/pr.ts
34
+ import { execFile } from "child_process";
35
+ function execAsync(cmd, args, cwd, timeout) {
36
+ return new Promise((resolve, reject) => {
37
+ execFile(cmd, args, { cwd, encoding: "utf-8", timeout, windowsHide: true }, (err, stdout) => {
38
+ if (err) reject(err);
39
+ else resolve(stdout ?? "");
40
+ });
41
+ });
42
+ }
43
+ function parsePrJson(stdout, repoAlias, currentUser) {
44
+ const parsed = JSON.parse(stdout);
45
+ const prs = Array.isArray(parsed) ? parsed : [];
46
+ return prs.map((pr) => toPrInfo(pr, repoAlias, currentUser));
47
+ }
48
+ function toPrInfo(pr, repoAlias, currentUser) {
49
+ {
50
+ let checksStatus = "NONE";
51
+ const checks = pr.statusCheckRollup ?? [];
52
+ if (checks.length > 0) {
53
+ const hasFailure = checks.some((c) => c.conclusion === "FAILURE" || c.conclusion === "TIMED_OUT" || c.conclusion === "CANCELLED");
54
+ const hasPending = checks.some((c) => c.status === "IN_PROGRESS" || c.status === "QUEUED" || c.status === "PENDING");
55
+ if (hasFailure) checksStatus = "FAILURE";
56
+ else if (hasPending) checksStatus = "PENDING";
57
+ else checksStatus = "SUCCESS";
58
+ }
59
+ let reviewDecision = "NONE";
60
+ if (pr.reviewDecision === "APPROVED") reviewDecision = "APPROVED";
61
+ else if (pr.reviewDecision === "CHANGES_REQUESTED") reviewDecision = "CHANGES_REQUESTED";
62
+ else if (pr.reviewDecision === "REVIEW_REQUIRED") reviewDecision = "REVIEW_REQUIRED";
63
+ let myReview = "NONE";
64
+ if (currentUser) {
65
+ const reviews = pr.reviews ?? [];
66
+ for (let i = reviews.length - 1; i >= 0; i--) {
67
+ if (reviews[i].author?.login?.toLowerCase() === currentUser.toLowerCase()) {
68
+ const state = reviews[i].state;
69
+ if (state === "APPROVED") myReview = "APPROVED";
70
+ else if (state === "CHANGES_REQUESTED") myReview = "CHANGES_REQUESTED";
71
+ else if (state === "COMMENTED") myReview = "COMMENTED";
72
+ break;
73
+ }
74
+ }
75
+ }
76
+ return {
77
+ number: pr.number ?? 0,
78
+ title: pr.title ?? "",
79
+ branch: pr.headRefName ?? "",
80
+ url: pr.url ?? "",
81
+ isDraft: pr.isDraft ?? false,
82
+ checksStatus,
83
+ reviewDecision,
84
+ myReview,
85
+ isMine: currentUser ? pr.author?.login?.toLowerCase() === currentUser.toLowerCase() : false,
86
+ conflicting: pr.mergeable === "CONFLICTING",
87
+ reviewRequested: !!currentUser && (pr.reviewRequests ?? []).some((r) => r?.login?.toLowerCase() === currentUser.toLowerCase()),
88
+ repoAlias,
89
+ author: pr.author?.login ?? "",
90
+ fork: pr.isCrossRepository === true
91
+ };
92
+ }
93
+ }
94
+ var PR_SEARCH_QUERY = `query($mine: String!, $asked: String!) {
95
+ viewer { login }
96
+ mine: search(query: $mine, type: ISSUE, first: 100) { issueCount nodes { ...pr } }
97
+ asked: search(query: $asked, type: ISSUE, first: 100) { issueCount nodes { ...pr } }
98
+ }
99
+ fragment pr on PullRequest {
100
+ number title url isDraft headRefName mergeable reviewDecision isCrossRepository
101
+ author { login }
102
+ repository { nameWithOwner }
103
+ commits(last: 1) { nodes { commit { statusCheckRollup { state } } } }
104
+ reviewRequests(first: 20) { nodes { requestedReviewer { ... on User { login } } } }
105
+ latestReviews(first: 20) { nodes { author { login } state } }
106
+ }`;
107
+ var PR_SEARCH_VARS = {
108
+ mine: "is:pr is:open archived:false author:@me",
109
+ asked: "is:pr is:open archived:false review-requested:@me"
110
+ };
111
+ function rollupAsChecks(state) {
112
+ if (state === "FAILURE" || state === "ERROR") return [{ conclusion: "FAILURE", status: "COMPLETED" }];
113
+ if (state === "PENDING" || state === "EXPECTED") return [{ conclusion: null, status: "PENDING" }];
114
+ if (state === "SUCCESS") return [{ conclusion: "SUCCESS", status: "COMPLETED" }];
115
+ return [];
116
+ }
117
+ function parsePrSearch(stdout, aliasesOf) {
118
+ const data = JSON.parse(stdout)?.data ?? {};
119
+ const user = (data.viewer?.login ?? "").trim();
120
+ const seen = /* @__PURE__ */ new Set();
121
+ const prs = [];
122
+ let incomplete = false;
123
+ for (const key of ["mine", "asked"]) {
124
+ const result = data[key];
125
+ const nodes = (result?.nodes ?? []).filter((n) => !!n && typeof n.number === "number");
126
+ if ((result?.issueCount ?? 0) > nodes.length) incomplete = true;
127
+ for (const n of nodes) {
128
+ const pr = {
129
+ ...n,
130
+ statusCheckRollup: rollupAsChecks(n.commits?.nodes?.[0]?.commit?.statusCheckRollup?.state),
131
+ reviews: (n.latestReviews?.nodes ?? []).filter((r) => !!r),
132
+ reviewRequests: (n.reviewRequests?.nodes ?? []).map((r) => r?.requestedReviewer ?? null)
133
+ };
134
+ for (const alias of aliasesOf(n.repository?.nameWithOwner ?? "")) {
135
+ const id = `${alias}#${n.number}`;
136
+ if (seen.has(id)) continue;
137
+ seen.add(id);
138
+ prs.push(toPrInfo(pr, alias, user));
139
+ }
140
+ }
141
+ }
142
+ return { prs, incomplete };
143
+ }
144
+ function readSearch(stdout, aliasesOf) {
145
+ try {
146
+ return parsePrSearch(stdout, aliasesOf);
147
+ } catch {
148
+ return null;
149
+ }
150
+ }
151
+ function githubRepoOf(configText) {
152
+ const url = originUrl(configText);
153
+ if (!url || !/(^|[@/.])github\.com[:/]/i.test(url)) return null;
154
+ return ownerRepo(url)?.toLowerCase() ?? null;
155
+ }
156
+ var PR_LIST_LIMIT = 100;
157
+ async function fetchPullRequests(repoPath, repoAlias, currentUser) {
158
+ try {
159
+ const stdout = await execAsync(
160
+ "gh",
161
+ [
162
+ "pr",
163
+ "list",
164
+ "--state",
165
+ "open",
166
+ "--json",
167
+ "number,title,headRefName,url,isDraft,statusCheckRollup,reviewDecision,reviews,reviewRequests,mergeable,author,isCrossRepository",
168
+ "--limit",
169
+ String(PR_LIST_LIMIT)
170
+ ],
171
+ repoPath,
172
+ 15e3
173
+ );
174
+ if (!stdout) return [];
175
+ return parsePrJson(stdout, repoAlias, currentUser);
176
+ } catch {
177
+ return null;
178
+ }
179
+ }
180
+ async function getCurrentUser() {
181
+ try {
182
+ const stdout = await execAsync("gh", ["api", "user", "--jq", ".login"], process.cwd(), 5e3);
183
+ return stdout.trim();
184
+ } catch {
185
+ return "";
186
+ }
187
+ }
188
+ function defaultPrListDeps() {
189
+ let user = null;
190
+ return {
191
+ search: async () => {
192
+ try {
193
+ return await execAsync(
194
+ "gh",
195
+ ["api", "graphql", "-f", `query=${PR_SEARCH_QUERY}`, "-f", `mine=${PR_SEARCH_VARS.mine}`, "-f", `asked=${PR_SEARCH_VARS.asked}`],
196
+ process.cwd(),
197
+ 2e4
198
+ );
199
+ } catch {
200
+ return null;
201
+ }
202
+ },
203
+ listRepo: async (repoPath, alias) => fetchPullRequests(repoPath, alias, await (user ??= getCurrentUser())),
204
+ gitConfig: readGitConfig
205
+ };
206
+ }
207
+ async function fetchAllPullRequests(repos, deps = defaultPrListDeps()) {
208
+ const entries = Object.entries(repos);
209
+ const onGithub = /* @__PURE__ */ new Map();
210
+ const elsewhere = [];
211
+ for (const [alias, repoPath] of entries) {
212
+ const text = deps.gitConfig(repoPath);
213
+ const gh = text ? githubRepoOf(text) : null;
214
+ if (gh) onGithub.set(gh, [...onGithub.get(gh) ?? [], alias]);
215
+ else elsewhere.push([alias, repoPath]);
216
+ }
217
+ const results = [];
218
+ const incomplete = [];
219
+ if (onGithub.size) {
220
+ const out = await deps.search();
221
+ const parsed = out ? readSearch(out, (repo) => onGithub.get(repo.toLowerCase()) ?? []) : null;
222
+ if (parsed) {
223
+ results.push(parsed.prs);
224
+ if (parsed.incomplete) incomplete.push(...[...onGithub.values()].flat());
225
+ } else {
226
+ const asked = new Set(elsewhere.map(([a]) => a));
227
+ for (const [alias, repoPath] of entries) if (!asked.has(alias)) elsewhere.push([alias, repoPath]);
228
+ }
229
+ }
230
+ const listed = await Promise.all(elsewhere.map(([alias, repoPath]) => deps.listRepo(repoPath, alias)));
231
+ results.push(...listed);
232
+ incomplete.push(...elsewhere.filter((_, i) => listed[i] === null || listed[i].length >= PR_LIST_LIMIT).map(([alias]) => alias));
233
+ const map = /* @__PURE__ */ new Map();
234
+ for (const prList of results) {
235
+ for (const pr of prList ?? []) {
236
+ const existing = map.get(pr.branch);
237
+ if (existing) {
238
+ existing.push(pr);
239
+ } else {
240
+ map.set(pr.branch, [pr]);
241
+ }
242
+ }
243
+ }
244
+ return { map, incomplete };
245
+ }
246
+
247
+ // src/core/pr/pr-start.ts
248
+ async function resolvePrToStart(input, config, target, deps = {}) {
249
+ const run = deps.run ?? defaultRunner;
250
+ const gitConfig = deps.gitConfig ?? readGitConfig;
251
+ const ref = parsePrRef(input);
252
+ if (!ref) return { ok: false, error: "Give a pull request link (https://github.com/owner/repo/pull/123), or its number with a repo." };
253
+ const repoOf = (alias2) => githubRepoOf(gitConfig(config.repos[alias2]) ?? "");
254
+ let alias;
255
+ if (ref.repo) {
256
+ const matches = Object.keys(config.repos).filter((a) => repoOf(a) === ref.repo);
257
+ if (!matches.length) return { ok: false, error: `${ref.repo} isn't one of your repos: add it first (work config add <alias> <path>).` };
258
+ const within = target ? config.groups?.[target] ?? [target] : matches;
259
+ alias = matches.find((a) => within.includes(a));
260
+ if (!alias) return { ok: false, error: `PR #${ref.number} is in ${matches.join(" / ")} (${ref.repo}), not ${target}.` };
261
+ } else {
262
+ if (!target) return { ok: false, error: `PR #${ref.number}: which repo? Give its link, or pick the repo.` };
263
+ if (config.groups?.[target])
264
+ return { ok: false, error: `${target} is a group: a PR is one repo's. Give its link, or one of the group's repos.` };
265
+ if (!config.repos[target]) return { ok: false, error: `${target} isn't one of your repos.` };
266
+ alias = target;
267
+ }
268
+ const github = repoOf(alias);
269
+ if (!github) return { ok: false, error: `${alias} isn't on github.com: work can only look up GitHub PRs.` };
270
+ const view = await run(
271
+ "gh",
272
+ [
273
+ "pr",
274
+ "view",
275
+ String(ref.number),
276
+ "--repo",
277
+ github,
278
+ "--json",
279
+ "number,title,url,headRefName,headRefOid,baseRefName,state,isCrossRepository,author,headRepositoryOwner"
280
+ ],
281
+ config.repos[alias]
282
+ );
283
+ if (view.code === 127) return { ok: false, error: "GitHub CLI (gh) not found: install it to start from a PR." };
284
+ if (view.code !== 0)
285
+ return { ok: false, error: `PR #${ref.number} in ${github}: ${view.stderr.trim().split("\n")[0] || "gh pr view failed"}` };
286
+ let pr;
287
+ try {
288
+ pr = JSON.parse(view.stdout);
289
+ } catch {
290
+ return { ok: false, error: "Couldn't read what gh said about the PR." };
291
+ }
292
+ if (pr.state && pr.state !== "OPEN") return { ok: false, error: `PR #${ref.number} is ${pr.state.toLowerCase()}.` };
293
+ if (pr.isCrossRepository) {
294
+ const owner = pr.headRepositoryOwner?.login ?? "a fork";
295
+ return {
296
+ ok: false,
297
+ error: `PR #${ref.number} comes from a fork (${owner}): its branch isn't on origin, so a session couldn't push to it.`
298
+ };
299
+ }
300
+ if (!pr.headRefName) return { ok: false, error: `PR #${ref.number}: gh didn't say its branch.` };
301
+ const stale = await localGoneOtherWay(run, config.repos[alias], pr.headRefName, pr.headRefOid);
302
+ if (stale) return { ok: false, error: stale };
303
+ return {
304
+ ok: true,
305
+ pr: {
306
+ alias,
307
+ number: pr.number ?? ref.number,
308
+ title: pr.title ?? "",
309
+ url: pr.url ?? "",
310
+ branch: pr.headRefName,
311
+ base: pr.baseRefName ?? "",
312
+ author: pr.author?.login ?? ""
313
+ }
314
+ };
315
+ }
316
+ async function localGoneOtherWay(run, repoPath, branch, headOid) {
317
+ if (!headOid) return null;
318
+ const local = await run("git", ["rev-parse", "--verify", "--quiet", `refs/heads/${branch}`], repoPath);
319
+ if (local.code !== 0) return null;
320
+ await run("git", ["fetch", "--quiet", "origin", branch], repoPath);
321
+ const contains = await run("git", ["merge-base", "--is-ancestor", headOid, `refs/heads/${branch}`], repoPath);
322
+ if (contains.code === 0) return null;
323
+ const behind = await run("git", ["merge-base", "--is-ancestor", `refs/heads/${branch}`, headOid], repoPath);
324
+ if (behind.code !== 1 || contains.code !== 1) return null;
325
+ return `Your local branch ${branch} and the PR's have gone separate ways (a force-push, or another branch of that name): rename yours (git branch -m ${branch} ${branch}-old) and try again, or go into its session as it is (work tree <repo> ${branch}).`;
326
+ }
327
+
328
+ export {
329
+ fetchAllPullRequests,
330
+ parsePrRef,
331
+ workOnPrPrompt,
332
+ resolvePrToStart
333
+ };
334
+ //# sourceMappingURL=chunk-BLCAZAU5.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/core/pr/pr-ref.ts","../src/core/pr/pr.ts","../src/core/pr/pr-start.ts"],"sourcesContent":["/**\n * Starting a session on someone else's pull request — on their branch, so\n * what you push lands in their PR. Pure (the SPA and the demo use it): how a\n * PR is named, and what its session's Claude is told first. The lookup\n * (`gh pr view`) is `pr-start.ts`.\n */\n\nimport type { PrToStart } from '../api-types.js';\n\nexport type { PrToStart };\n\n/** A PR as you'd name it: its link (repo known), or its number (in a repo you pick). */\nexport interface PrRef {\n /** `owner/name`, lowercase, from a link. */\n repo?: string;\n number: number;\n}\n\n/** A PR link (`https://github.com/owner/repo/pull/123`, any tail), `#123` or `123`; null for anything else. */\nexport function parsePrRef(input: string): PrRef | null {\n const s = input.trim();\n const url = /^(?:https?:\\/\\/)?(?:www\\.)?github\\.com\\/([^/\\s]+)\\/([^/\\s]+)\\/pull\\/(\\d+)(?:[/?#].*)?$/i.exec(s);\n if (url) return { repo: `${url[1]}/${url[2]}`.toLowerCase(), number: Number(url[3]) };\n const n = /^#?(\\d+)$/.exec(s);\n return n && Number(n[1]) > 0 ? { number: Number(n[1]) } : null;\n}\n\n/**\n * The first message to the session's Claude: whose PR this is, that what it\n * pushes lands there, and to get up to speed — then do `instruction`, or\n * with none, say where it stands and wait for what the user wants. Nothing\n * on GitHub (no comments, reviews or replies): that's the author's\n * conversation.\n */\nexport function workOnPrPrompt(pr: Pick<PrToStart, 'number' | 'title' | 'url'> & { author?: string }, instruction?: string): string {\n const who = pr.author ? `@${pr.author}` : 'its author';\n const todo = instruction?.trim();\n const upToSpeed = `Get up to speed first (gh pr view ${pr.number}, gh pr diff ${pr.number})`;\n return [\n `Work on PR #${pr.number} by ${who}: ${pr.title}`,\n pr.url,\n '',\n `This worktree is on ${who}'s branch: what you commit and push lands in their PR.`,\n ...(todo ? [`${upToSpeed}, then:`, '', todo, ''] : [`${upToSpeed}, tell me where it stands, and wait for what I want done.`]),\n \"Don't post on GitHub (no comments, reviews or replies).\",\n ].join('\\n');\n}\n","import { execFile } from 'node:child_process';\nimport { originUrl, ownerRepo, readGitConfig } from '../worktree/repo-scan.js';\n\nexport interface PullRequestInfo {\n number: number;\n title: string;\n branch: string;\n url: string;\n isDraft: boolean;\n checksStatus: 'SUCCESS' | 'FAILURE' | 'PENDING' | 'NONE';\n reviewDecision: 'APPROVED' | 'CHANGES_REQUESTED' | 'REVIEW_REQUIRED' | 'NONE';\n /** Current user's latest review state on this PR. */\n myReview: 'APPROVED' | 'CHANGES_REQUESTED' | 'COMMENTED' | 'NONE';\n /** Whether the current user is the PR author. */\n isMine: boolean;\n /** It can't merge as it is: a conflict with its base (checks say nothing about that). */\n conflicting: boolean;\n /** Your review was asked for, by name (a team's request isn't known here). */\n reviewRequested: boolean;\n /** Repo alias this PR belongs to (for distinguishing group PRs). */\n repoAlias: string;\n /** Its author's login (absent from a server before this). */\n author?: string;\n /** It comes from a fork: its branch isn't on origin (absent from a server before this). */\n fork?: boolean;\n}\n\n/**\n * Map from branch name to array of PRs (one per repo that has a PR for that branch).\n * Single-repo sessions will have at most 1 entry; groups can have multiple.\n */\nexport type BranchPrMap = Map<string, PullRequestInfo[]>;\n\nfunction execAsync(cmd: string, args: string[], cwd: string, timeout: number): Promise<string> {\n return new Promise((resolve, reject) => {\n // `windowsHide: true` prevents a console window from flashing on\n // Windows whenever the PRs pane refreshes. Without it, opening\n // the PRs pane in `work web` triggers a visible terminal popup\n // for every configured repo's `gh pr list` invocation.\n execFile(cmd, args, { cwd, encoding: 'utf-8', timeout, windowsHide: true }, (err, stdout) => {\n if (err) reject(err);\n else resolve(stdout ?? '');\n });\n });\n}\n\n/** The fields of `gh pr list --json …` this reads; all optional — it is someone else's output. */\ninterface GhPr {\n number?: number;\n title?: string;\n headRefName?: string;\n url?: string;\n isDraft?: boolean;\n mergeable?: string;\n reviewDecision?: string;\n author?: { login?: string } | null;\n isCrossRepository?: boolean;\n statusCheckRollup?: Array<{ conclusion?: string | null; status?: string | null }> | null;\n reviews?: Array<{ author?: { login?: string } | null; state?: string }> | null;\n reviewRequests?: Array<{ login?: string } | null> | null;\n}\n\n/** `gh pr list --json …` output as work's PR rows: checks, review, yours or not, conflicts, review asked of you. Pure. */\nexport function parsePrJson(stdout: string, repoAlias: string, currentUser: string): PullRequestInfo[] {\n const parsed = JSON.parse(stdout) as unknown;\n const prs: GhPr[] = Array.isArray(parsed) ? (parsed as GhPr[]) : [];\n return prs.map((pr) => toPrInfo(pr, repoAlias, currentUser));\n}\n\n/** One PR as work's row. */\nfunction toPrInfo(pr: GhPr, repoAlias: string, currentUser: string): PullRequestInfo {\n {\n let checksStatus: PullRequestInfo['checksStatus'] = 'NONE';\n const checks = pr.statusCheckRollup ?? [];\n if (checks.length > 0) {\n const hasFailure = checks.some((c) => c.conclusion === 'FAILURE' || c.conclusion === 'TIMED_OUT' || c.conclusion === 'CANCELLED');\n const hasPending = checks.some((c) => c.status === 'IN_PROGRESS' || c.status === 'QUEUED' || c.status === 'PENDING');\n if (hasFailure) checksStatus = 'FAILURE';\n else if (hasPending) checksStatus = 'PENDING';\n else checksStatus = 'SUCCESS';\n }\n\n let reviewDecision: PullRequestInfo['reviewDecision'] = 'NONE';\n if (pr.reviewDecision === 'APPROVED') reviewDecision = 'APPROVED';\n else if (pr.reviewDecision === 'CHANGES_REQUESTED') reviewDecision = 'CHANGES_REQUESTED';\n else if (pr.reviewDecision === 'REVIEW_REQUIRED') reviewDecision = 'REVIEW_REQUIRED';\n\n // Check current user's latest review state\n let myReview: PullRequestInfo['myReview'] = 'NONE';\n if (currentUser) {\n const reviews = pr.reviews ?? [];\n for (let i = reviews.length - 1; i >= 0; i--) {\n if (reviews[i].author?.login?.toLowerCase() === currentUser.toLowerCase()) {\n const state = reviews[i].state;\n if (state === 'APPROVED') myReview = 'APPROVED';\n else if (state === 'CHANGES_REQUESTED') myReview = 'CHANGES_REQUESTED';\n else if (state === 'COMMENTED') myReview = 'COMMENTED';\n break;\n }\n }\n }\n\n return {\n number: pr.number ?? 0,\n title: pr.title ?? '',\n branch: pr.headRefName ?? '',\n url: pr.url ?? '',\n isDraft: pr.isDraft ?? false,\n checksStatus,\n reviewDecision,\n myReview,\n isMine: currentUser ? pr.author?.login?.toLowerCase() === currentUser.toLowerCase() : false,\n conflicting: pr.mergeable === 'CONFLICTING',\n reviewRequested: !!currentUser && (pr.reviewRequests ?? []).some((r) => r?.login?.toLowerCase() === currentUser.toLowerCase()),\n repoAlias,\n author: pr.author?.login ?? '',\n fork: pr.isCrossRepository === true,\n };\n }\n}\n\n/**\n * Your open PRs and the ones asking for your review, across every GitHub\n * repo, in ONE GraphQL call (about one API point). The list used to be a\n * `gh pr list` per enrolled repo every two minutes: 27 calls for 27 repos.\n * Start shows only these two kinds anyway.\n */\nexport const PR_SEARCH_QUERY = `query($mine: String!, $asked: String!) {\n viewer { login }\n mine: search(query: $mine, type: ISSUE, first: 100) { issueCount nodes { ...pr } }\n asked: search(query: $asked, type: ISSUE, first: 100) { issueCount nodes { ...pr } }\n}\nfragment pr on PullRequest {\n number title url isDraft headRefName mergeable reviewDecision isCrossRepository\n author { login }\n repository { nameWithOwner }\n commits(last: 1) { nodes { commit { statusCheckRollup { state } } } }\n reviewRequests(first: 20) { nodes { requestedReviewer { ... on User { login } } } }\n latestReviews(first: 20) { nodes { author { login } state } }\n}`;\n\n/** The search's two queries: open PRs by you, and open PRs asking you by name. */\nexport const PR_SEARCH_VARS = {\n mine: 'is:pr is:open archived:false author:@me',\n asked: 'is:pr is:open archived:false review-requested:@me',\n};\n\ninterface SearchNode extends Omit<GhPr, 'statusCheckRollup' | 'reviews' | 'reviewRequests'> {\n repository?: { nameWithOwner?: string } | null;\n commits?: { nodes?: Array<{ commit?: { statusCheckRollup?: { state?: string } | null } | null } | null> | null } | null;\n reviewRequests?: { nodes?: Array<{ requestedReviewer?: { login?: string } | null } | null> | null } | null;\n latestReviews?: { nodes?: Array<{ author?: { login?: string } | null; state?: string } | null> | null } | null;\n}\n\n/** A check rollup's one word, in the shape `gh pr list` gives (so one conversion reads both). */\nfunction rollupAsChecks(state: string | undefined): GhPr['statusCheckRollup'] {\n if (state === 'FAILURE' || state === 'ERROR') return [{ conclusion: 'FAILURE', status: 'COMPLETED' }];\n if (state === 'PENDING' || state === 'EXPECTED') return [{ conclusion: null, status: 'PENDING' }];\n if (state === 'SUCCESS') return [{ conclusion: 'SUCCESS', status: 'COMPLETED' }];\n return [];\n}\n\n/**\n * The search's answer as work's PR rows, each under the alias (or aliases)\n * enrolled for its repository; PRs of repos you haven't enrolled are left\n * out, as before. `incomplete` when a search found more than it returned. Pure.\n */\nexport function parsePrSearch(\n stdout: string,\n aliasesOf: (nameWithOwner: string) => string[],\n): { prs: PullRequestInfo[]; incomplete: boolean } {\n const data = (JSON.parse(stdout) as { data?: Record<string, unknown> } | null)?.data ?? {};\n const user = ((data.viewer as { login?: string } | undefined)?.login ?? '').trim();\n const seen = new Set<string>();\n const prs: PullRequestInfo[] = [];\n let incomplete = false;\n for (const key of ['mine', 'asked']) {\n const result = data[key] as { issueCount?: number; nodes?: Array<SearchNode | null> } | undefined;\n const nodes = (result?.nodes ?? []).filter((n): n is SearchNode => !!n && typeof n.number === 'number');\n if ((result?.issueCount ?? 0) > nodes.length) incomplete = true;\n for (const n of nodes) {\n const pr: GhPr = {\n ...n,\n statusCheckRollup: rollupAsChecks(n.commits?.nodes?.[0]?.commit?.statusCheckRollup?.state),\n reviews: (n.latestReviews?.nodes ?? []).filter((r) => !!r),\n reviewRequests: (n.reviewRequests?.nodes ?? []).map((r) => r?.requestedReviewer ?? null),\n };\n for (const alias of aliasesOf(n.repository?.nameWithOwner ?? '')) {\n const id = `${alias}#${n.number}`;\n if (seen.has(id)) continue;\n seen.add(id);\n prs.push(toPrInfo(pr, alias, user));\n }\n }\n }\n return { prs, incomplete };\n}\n\n/** parsePrSearch, or null for an answer that isn't JSON. */\nfunction readSearch(stdout: string, aliasesOf: (nameWithOwner: string) => string[]): ReturnType<typeof parsePrSearch> | null {\n try {\n return parsePrSearch(stdout, aliasesOf);\n } catch {\n return null;\n }\n}\n\n/** `owner/name` (lowercase) of a repo's origin on github.com, from its `.git/config` text; null for another host or no origin. Pure. */\nexport function githubRepoOf(configText: string): string | null {\n const url = originUrl(configText);\n if (!url || !/(^|[@/.])github\\.com[:/]/i.test(url)) return null;\n return ownerRepo(url)?.toLowerCase() ?? null;\n}\n\n/**\n * Fetch open PRs for a repo using `gh` CLI (async, non-blocking).\n */\nconst PR_LIST_LIMIT = 100;\n\n/** Open PRs for a repo; null when gh couldn't say (missing, offline, not a GitHub repo). */\nasync function fetchPullRequests(repoPath: string, repoAlias: string, currentUser: string): Promise<PullRequestInfo[] | null> {\n try {\n const stdout = await execAsync(\n 'gh',\n [\n 'pr',\n 'list',\n '--state',\n 'open',\n '--json',\n 'number,title,headRefName,url,isDraft,statusCheckRollup,reviewDecision,reviews,reviewRequests,mergeable,author,isCrossRepository',\n '--limit',\n String(PR_LIST_LIMIT),\n ],\n repoPath,\n 15000,\n );\n if (!stdout) return [];\n return parsePrJson(stdout, repoAlias, currentUser);\n } catch {\n return null;\n }\n}\n\n/**\n * Fetch PRs for all configured repos (async, non-blocking).\n * Runs all repo fetches in parallel.\n * Returns a map from branch name → array of PRs across repos.\n */\nasync function getCurrentUser(): Promise<string> {\n try {\n const stdout = await execAsync('gh', ['api', 'user', '--jq', '.login'], process.cwd(), 5000);\n return stdout.trim();\n } catch {\n return '';\n }\n}\n\n/** What fetchAllPullRequests reaches outside (tests pass fakes). */\nexport interface PrListDeps {\n /** `gh api graphql` with the search: its stdout, or null when gh couldn't. */\n search: () => Promise<string | null>;\n /** One repo the old way (`gh pr list` there): not on github.com, or the search failed. */\n listRepo: (repoPath: string, alias: string) => Promise<PullRequestInfo[] | null>;\n /** A repo's `.git/config` text, or null. */\n gitConfig: (repoPath: string) => string | null;\n}\n\nfunction defaultPrListDeps(): PrListDeps {\n let user: Promise<string> | null = null;\n return {\n search: async () => {\n try {\n return await execAsync(\n 'gh',\n ['api', 'graphql', '-f', `query=${PR_SEARCH_QUERY}`, '-f', `mine=${PR_SEARCH_VARS.mine}`, '-f', `asked=${PR_SEARCH_VARS.asked}`],\n process.cwd(),\n 20000,\n );\n } catch {\n return null;\n }\n },\n listRepo: async (repoPath, alias) => fetchPullRequests(repoPath, alias, await (user ??= getCurrentUser())),\n gitConfig: readGitConfig,\n };\n}\n\n/**\n * The PRs for the dashboard: one search for every repo on github.com (yours,\n * and those asking your review), and the old per-repo list only for repos\n * elsewhere (GitHub Enterprise, no origin) — or for all of them when the\n * search fails. Returns a map from branch name → PRs across repos.\n */\nexport async function fetchAllPullRequests(\n repos: Record<string, string>,\n deps: PrListDeps = defaultPrListDeps(),\n): Promise<{ map: BranchPrMap; incomplete: string[] }> {\n const entries = Object.entries(repos);\n const onGithub = new Map<string, string[]>(); // owner/name → its aliases\n const elsewhere: Array<[string, string]> = [];\n for (const [alias, repoPath] of entries) {\n const text = deps.gitConfig(repoPath);\n const gh = text ? githubRepoOf(text) : null;\n if (gh) onGithub.set(gh, [...(onGithub.get(gh) ?? []), alias]);\n else elsewhere.push([alias, repoPath]);\n }\n\n const results: Array<PullRequestInfo[] | null> = [];\n const incomplete: string[] = [];\n if (onGithub.size) {\n const out = await deps.search();\n const parsed = out ? readSearch(out, (repo) => onGithub.get(repo.toLowerCase()) ?? []) : null;\n if (parsed) {\n results.push(parsed.prs);\n if (parsed.incomplete) incomplete.push(...[...onGithub.values()].flat());\n } else {\n // gh can't search (an old gh, no network): the old way, repo by repo.\n const asked = new Set(elsewhere.map(([a]) => a));\n for (const [alias, repoPath] of entries) if (!asked.has(alias)) elsewhere.push([alias, repoPath]);\n }\n }\n const listed = await Promise.all(elsewhere.map(([alias, repoPath]) => deps.listRepo(repoPath, alias)));\n results.push(...listed);\n // Repos whose list may be missing PRs: gh failed, or it hit the limit.\n incomplete.push(...elsewhere.filter((_, i) => listed[i] === null || listed[i]!.length >= PR_LIST_LIMIT).map(([alias]) => alias));\n\n const map: BranchPrMap = new Map();\n for (const prList of results) {\n for (const pr of prList ?? []) {\n const existing = map.get(pr.branch);\n if (existing) {\n existing.push(pr);\n } else {\n map.set(pr.branch, [pr]);\n }\n }\n }\n\n return { map, incomplete };\n}\n","import type { WorkConfig } from '../platform/config.js';\nimport { githubRepoOf } from './pr.js';\nimport { readGitConfig } from '../worktree/repo-scan.js';\nimport { parsePrRef, type PrToStart } from './pr-ref.js';\nimport { defaultRunner, type CommandRunner } from './ship.js';\n\nexport type PrStartResult = { ok: true; pr: PrToStart } | { ok: false; error: string };\n\nexport interface PrStartDeps {\n run?: CommandRunner;\n /** A repo's `.git/config` text (tests pass their own). */\n gitConfig?: (repoPath: string) => string | null;\n}\n\n/** The fields of `gh pr view --json …` this reads; all optional — it is someone else's output. */\ninterface GhPrView {\n number?: number;\n title?: string;\n url?: string;\n headRefName?: string;\n headRefOid?: string;\n baseRefName?: string;\n state?: string;\n isCrossRepository?: boolean;\n author?: { login?: string } | null;\n headRepositoryOwner?: { login?: string } | null;\n}\n\n/**\n * Which of your repos a PR is in, and its branch: from its link (the repo\n * matched by its origin) or its number (in `target`, a repo). Refused: a\n * repo you haven't enrolled, a group as the repo of a bare number, a PR\n * that isn't open, and one from a fork — its branch isn't on origin, so the\n * session couldn't push to it (and `work tree` would make a new, empty\n * branch of that name instead).\n */\nexport async function resolvePrToStart(\n input: string,\n config: Pick<WorkConfig, 'repos' | 'groups'>,\n target?: string,\n deps: PrStartDeps = {},\n): Promise<PrStartResult> {\n const run = deps.run ?? defaultRunner;\n const gitConfig = deps.gitConfig ?? readGitConfig;\n const ref = parsePrRef(input);\n if (!ref) return { ok: false, error: 'Give a pull request link (https://github.com/owner/repo/pull/123), or its number with a repo.' };\n\n const repoOf = (alias: string) => githubRepoOf(gitConfig(config.repos[alias]) ?? '');\n let alias: string | undefined;\n if (ref.repo) {\n const matches = Object.keys(config.repos).filter((a) => repoOf(a) === ref.repo);\n if (!matches.length) return { ok: false, error: `${ref.repo} isn't one of your repos: add it first (work config add <alias> <path>).` };\n // A target named beside a link must hold it: the repo itself, or a group with it among its repos.\n const within = target ? (config.groups?.[target] ?? [target]) : matches;\n alias = matches.find((a) => within.includes(a));\n if (!alias) return { ok: false, error: `PR #${ref.number} is in ${matches.join(' / ')} (${ref.repo}), not ${target}.` };\n } else {\n if (!target) return { ok: false, error: `PR #${ref.number}: which repo? Give its link, or pick the repo.` };\n if (config.groups?.[target])\n return { ok: false, error: `${target} is a group: a PR is one repo's. Give its link, or one of the group's repos.` };\n if (!config.repos[target]) return { ok: false, error: `${target} isn't one of your repos.` };\n alias = target;\n }\n const github = repoOf(alias);\n if (!github) return { ok: false, error: `${alias} isn't on github.com: work can only look up GitHub PRs.` };\n\n const view = await run(\n 'gh',\n [\n 'pr',\n 'view',\n String(ref.number),\n '--repo',\n github,\n '--json',\n 'number,title,url,headRefName,headRefOid,baseRefName,state,isCrossRepository,author,headRepositoryOwner',\n ],\n config.repos[alias],\n );\n if (view.code === 127) return { ok: false, error: 'GitHub CLI (gh) not found: install it to start from a PR.' };\n if (view.code !== 0)\n return { ok: false, error: `PR #${ref.number} in ${github}: ${view.stderr.trim().split('\\n')[0] || 'gh pr view failed'}` };\n let pr: GhPrView;\n try {\n pr = JSON.parse(view.stdout) as GhPrView;\n } catch {\n return { ok: false, error: \"Couldn't read what gh said about the PR.\" };\n }\n if (pr.state && pr.state !== 'OPEN') return { ok: false, error: `PR #${ref.number} is ${pr.state.toLowerCase()}.` };\n if (pr.isCrossRepository) {\n const owner = pr.headRepositoryOwner?.login ?? 'a fork';\n return {\n ok: false,\n error: `PR #${ref.number} comes from a fork (${owner}): its branch isn't on origin, so a session couldn't push to it.`,\n };\n }\n if (!pr.headRefName) return { ok: false, error: `PR #${ref.number}: gh didn't say its branch.` };\n const stale = await localGoneOtherWay(run, config.repos[alias], pr.headRefName, pr.headRefOid);\n if (stale) return { ok: false, error: stale };\n return {\n ok: true,\n pr: {\n alias,\n number: pr.number ?? ref.number,\n title: pr.title ?? '',\n url: pr.url ?? '',\n branch: pr.headRefName,\n base: pr.baseRefName ?? '',\n author: pr.author?.login ?? '',\n },\n };\n}\n\n/**\n * `work tree` takes a local branch of that name over origin's, moving it\n * forward when it can. One that has gone another way than the PR (the author\n * force-pushed, or an unrelated branch of the same name) would open on the\n * wrong commits, and what's pushed from it wouldn't go. Ahead (your commits\n * on top) or behind (it fast-forwards) is fine; when git can't tell (no\n * fetch), the usual warning on entering is left to say it.\n */\nasync function localGoneOtherWay(run: CommandRunner, repoPath: string, branch: string, headOid?: string): Promise<string | null> {\n if (!headOid) return null;\n const local = await run('git', ['rev-parse', '--verify', '--quiet', `refs/heads/${branch}`], repoPath);\n if (local.code !== 0) return null;\n await run('git', ['fetch', '--quiet', 'origin', branch], repoPath);\n const contains = await run('git', ['merge-base', '--is-ancestor', headOid, `refs/heads/${branch}`], repoPath);\n if (contains.code === 0) return null;\n const behind = await run('git', ['merge-base', '--is-ancestor', `refs/heads/${branch}`, headOid], repoPath);\n if (behind.code !== 1 || contains.code !== 1) return null; // 1 = not an ancestor; anything else: git couldn't say\n return `Your local branch ${branch} and the PR's have gone separate ways (a force-push, or another branch of that name): rename yours (git branch -m ${branch} ${branch}-old) and try again, or go into its session as it is (work tree <repo> ${branch}).`;\n}\n"],"mappings":";;;;;;;;;;;AAmBO,SAAS,WAAW,OAA6B;AACtD,QAAM,IAAI,MAAM,KAAK;AACrB,QAAM,MAAM,0FAA0F,KAAK,CAAC;AAC5G,MAAI,IAAK,QAAO,EAAE,MAAM,GAAG,IAAI,CAAC,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MAAM,EAAE,GAAG,QAAQ;AACrG,MAAI,MAAM,SAAS,EAAG,QAAO;AAC7B,QAAM,IAAI,OAAO,CAAC,SAAS,WAAW,UAAU,MAAM,GAAG,QAAQ;AACjE,QAAM,WAAW,MAAM,IAAI,OAAO,CAAC,cAAc,iBAAiB,SAAS,cAAc,MAAM,EAAE,GAAG,QAAQ;AAC5G,MAAI,SAAS,SAAS,EAAG,QAAO;AAChC,QAAM,SAAS,MAAM,IAAI,OAAO,CAAC,cAAc,iBAAiB,cAAc,MAAM,IAAI,OAAO,GAAG,QAAQ;AAC1G,MAAI,OAAO,SAAS,KAAK,SAAS,SAAS,EAAG,QAAO;AACrD,SAAO,qBAAqB,MAAM,qHAAqH,MAAM,IAAI,MAAM,0EAA0E,MAAM;AACzP;","names":["alias"]}
@@ -5,7 +5,7 @@ import {
5
5
  samePathKey,
6
6
  scanForRepos,
7
7
  suggestAlias
8
- } from "./chunk-BSCAA322.js";
8
+ } from "./chunk-4V7C3O6V.js";
9
9
  import {
10
10
  atomicWriteFile,
11
11
  getConfigDir,
@@ -162,4 +162,4 @@ export {
162
162
  saveGroup,
163
163
  deleteGroup
164
164
  };
165
- //# sourceMappingURL=chunk-G2O7EIKX.js.map
165
+ //# sourceMappingURL=chunk-E72ETFAB.js.map
@@ -1,29 +1,29 @@
1
1
  #!/usr/bin/env node
2
2
  import {
3
3
  defaultArchiveDeps
4
- } from "./chunk-UNPEZODB.js";
4
+ } from "./chunk-V4RQ72HY.js";
5
5
  import {
6
6
  normPath
7
7
  } from "./chunk-AKMPF72Y.js";
8
8
  import {
9
9
  teardownWorktree
10
- } from "./chunk-N23HFT4X.js";
10
+ } from "./chunk-YZSSYD2G.js";
11
11
  import {
12
12
  disposePty
13
- } from "./chunk-LZHCTPBF.js";
13
+ } from "./chunk-KLK6O54M.js";
14
14
  import {
15
15
  fetchRemoteAsync
16
16
  } from "./chunk-7NAXFBFI.js";
17
17
  import {
18
18
  defaultRunner
19
- } from "./chunk-46UD4QBL.js";
19
+ } from "./chunk-5RRKVAIZ.js";
20
20
  import {
21
21
  archiveSession,
22
22
  loadHistory,
23
23
  readSessionActivity,
24
24
  readStatus,
25
25
  removeSession
26
- } from "./chunk-DUUH6FPH.js";
26
+ } from "./chunk-G5PN5NIS.js";
27
27
  import {
28
28
  sessionIdFor
29
29
  } from "./chunk-WF57CF7A.js";
@@ -159,4 +159,4 @@ function defaultCleanupDeps(opts = {}) {
159
159
  export {
160
160
  defaultCleanupDeps
161
161
  };
162
- //# sourceMappingURL=chunk-7OUBCJVJ.js.map
162
+ //# sourceMappingURL=chunk-E74YIDHX.js.map
@@ -2,17 +2,17 @@
2
2
  import {
3
3
  openBaseCheckout,
4
4
  setupWorktree
5
- } from "./chunk-N23HFT4X.js";
5
+ } from "./chunk-YZSSYD2G.js";
6
6
  import {
7
7
  resolveProjectTarget
8
8
  } from "./chunk-H5LKMR45.js";
9
9
  import {
10
10
  defaultRunner
11
- } from "./chunk-46UD4QBL.js";
11
+ } from "./chunk-5RRKVAIZ.js";
12
12
  import {
13
13
  findSession,
14
14
  loadHistory
15
- } from "./chunk-DUUH6FPH.js";
15
+ } from "./chunk-G5PN5NIS.js";
16
16
  import {
17
17
  spawn_default
18
18
  } from "./chunk-RCYI7SRA.js";
@@ -159,4 +159,4 @@ export {
159
159
  createInChild,
160
160
  createInProcess
161
161
  };
162
- //# sourceMappingURL=chunk-X5EMINGT.js.map
162
+ //# sourceMappingURL=chunk-EN24GJCO.js.map
@@ -1,23 +1,23 @@
1
1
  #!/usr/bin/env node
2
2
  import {
3
3
  defaultCleanupDeps
4
- } from "./chunk-7OUBCJVJ.js";
4
+ } from "./chunk-E74YIDHX.js";
5
5
  import {
6
6
  normPath
7
7
  } from "./chunk-AKMPF72Y.js";
8
8
  import {
9
9
  findSessionForCwd
10
- } from "./chunk-ED7E2WKK.js";
10
+ } from "./chunk-JYWCNLZN.js";
11
11
  import {
12
12
  buildFoldersOf,
13
13
  clearBuildFolders
14
- } from "./chunk-FOG4WG3Y.js";
14
+ } from "./chunk-LNMIG35F.js";
15
15
  import {
16
16
  defaultRunner
17
- } from "./chunk-46UD4QBL.js";
17
+ } from "./chunk-5RRKVAIZ.js";
18
18
  import {
19
19
  loadHistory
20
- } from "./chunk-DUUH6FPH.js";
20
+ } from "./chunk-G5PN5NIS.js";
21
21
  import {
22
22
  sessionIdFor
23
23
  } from "./chunk-WF57CF7A.js";
@@ -292,4 +292,4 @@ export {
292
292
  deleteMergedBranches,
293
293
  defaultBranchTidyDeps
294
294
  };
295
- //# sourceMappingURL=chunk-5S3ORHTD.js.map
295
+ //# sourceMappingURL=chunk-F3SPCHLH.js.map
@@ -887,17 +887,29 @@ async function archiveSteps(s, deps, opts) {
887
887
  const verdict = await deps.removable(s, { uncommittedSaved: !saving.error });
888
888
  let worktreeRemoved = false;
889
889
  let keptBecause = null;
890
+ let leftovers = [];
891
+ let ignored = {};
892
+ const ignoredDir = path3.join(dir, "ignored");
890
893
  if (verdict.ok) {
894
+ fs3.rmSync(ignoredDir, { recursive: true, force: true });
895
+ ignored = deps.saveIgnored ? await deps.saveIgnored(s, dir).catch(() => ({})) : {};
891
896
  worktreeRemoved = await deps.removeWorktree(s);
892
- if (!worktreeRemoved) keptBecause = "git refused to remove the worktree";
897
+ leftovers = worktreeRemoved ? [] : deps.halfRemoved?.(s) ?? [];
898
+ if (leftovers.length && s.paths.every((p) => leftovers.includes(p) || !fs3.existsSync(p))) worktreeRemoved = true;
899
+ else if (!worktreeRemoved)
900
+ keptBecause = leftovers.length ? `git removed ${leftovers.join(", ")} only in part (a file in use) and kept the rest` : "git refused to remove the worktree";
893
901
  } else {
894
902
  keptBecause = saving.error && !verdict.reason.includes(saving.error) ? `${verdict.reason} (${saving.error})` : verdict.reason;
895
903
  }
896
- if (!worktreeRemoved && Object.keys(saved).length) {
904
+ if (!worktreeRemoved && !leftovers.length && Object.keys(saved).length) {
897
905
  await deps.dropSaved?.(s, saved, dir).catch(() => {
898
906
  });
899
907
  saved = {};
900
908
  }
909
+ if (!worktreeRemoved && !leftovers.length && Object.keys(ignored).length) {
910
+ fs3.rmSync(ignoredDir, { recursive: true, force: true });
911
+ ignored = {};
912
+ }
901
913
  const kept = deps.kept?.(id);
902
914
  const earlier = readArchive(id, root);
903
915
  const unrestored = [...earlier?.unrestored ?? [], ...Object.values(earlier?.uncommitted ?? {}).filter((u) => !u.restoredAt)];
@@ -918,6 +930,7 @@ async function archiveSteps(s, deps, opts) {
918
930
  archivedAt: new Date(now()).toISOString(),
919
931
  worktreeRemoved,
920
932
  keptBecause,
933
+ ...leftovers.length ? { leftovers } : {},
921
934
  transcripts: copied,
922
935
  summary: {
923
936
  prompts,
@@ -931,6 +944,7 @@ async function archiveSteps(s, deps, opts) {
931
944
  ...branchesDeleted.length ? { branchesDeleted } : {},
932
945
  ...buildFolders && buildFolders.folders ? { buildFolders } : {},
933
946
  ...Object.keys(saved).length ? { uncommitted: saved } : {},
947
+ ...Object.keys(ignored).length ? { ignored } : {},
934
948
  ...unrestored.length ? { unrestored } : {},
935
949
  ...keptAny(kept) ? { kept } : {}
936
950
  };
@@ -947,7 +961,7 @@ async function archiveSteps(s, deps, opts) {
947
961
  worktreeRemoved,
948
962
  keptBecause,
949
963
  transcripts: copied.length,
950
- message: (worktreeRemoved ? `Archived; worktree removed, conversation kept${savedFiles(saved) ? `, ${savedFiles(saved)} uncommitted file${savedFiles(saved) === 1 ? "" : "s"} saved for Restore` : ""}` : `Archived; worktree kept (${keptBecause})`) + (keptList(kept) ? `; kept for Restore: ${keptList(kept)}` : ""),
964
+ message: (worktreeRemoved ? `Archived; worktree removed, conversation kept${savedFiles(saved) ? `, ${savedFiles(saved)} uncommitted file${savedFiles(saved) === 1 ? "" : "s"} saved for Restore` : ""}${leftovers.length ? `; git stopped at a file in use, so part of the folder is left (${leftovers.join(", ")}): close what holds it and delete it, or Restore puts it back` : ""}` : `Archived; worktree kept (${keptBecause})`) + (keptList(kept) ? `; kept for Restore: ${keptList(kept)}` : ""),
951
965
  ...keptList(kept) ? { kept: keptList(kept) } : {}
952
966
  };
953
967
  }
@@ -999,6 +1013,11 @@ function readArchive(id, root = archiveRoot()) {
999
1013
  return null;
1000
1014
  }
1001
1015
  }
1016
+ function isSavedIgnored(v) {
1017
+ if (!v || typeof v !== "object") return false;
1018
+ const o = v;
1019
+ return typeof o.files === "number" && typeof o.bytes === "number" && typeof o.skipped === "number";
1020
+ }
1002
1021
  function withValidSaves(r) {
1003
1022
  const out = { ...r };
1004
1023
  if (r.uncommitted !== void 0) {
@@ -1011,6 +1030,11 @@ function withValidSaves(r) {
1011
1030
  if (valid2.length) out.unrestored = valid2;
1012
1031
  else delete out.unrestored;
1013
1032
  }
1033
+ if (r.ignored !== void 0) {
1034
+ const valid2 = typeof r.ignored === "object" && r.ignored ? Object.entries(r.ignored).filter(([, v]) => isSavedIgnored(v)) : [];
1035
+ if (valid2.length) out.ignored = Object.fromEntries(valid2);
1036
+ else delete out.ignored;
1037
+ }
1014
1038
  return out;
1015
1039
  }
1016
1040
  function isArchiveRecord(x) {
@@ -2444,4 +2468,4 @@ export {
2444
2468
  mergeHydratedSessions,
2445
2469
  forgetOtherBaseCheckoutEntries
2446
2470
  };
2447
- //# sourceMappingURL=chunk-DUUH6FPH.js.map
2471
+ //# sourceMappingURL=chunk-G5PN5NIS.js.map