@moberg_hr/work-tree 1.16.0 → 2.0.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 (249) hide show
  1. package/README.md +56 -142
  2. package/dist/answer-2J4XLIP7.js +63 -0
  3. package/dist/answer-2J4XLIP7.js.map +1 -0
  4. package/dist/attach-CZKRNPAJ.js +59 -0
  5. package/dist/attach-CZKRNPAJ.js.map +1 -0
  6. package/dist/bin.js +26 -11924
  7. package/dist/bin.js.map +1 -1
  8. package/dist/block-RAIDCJ4F.js +84 -0
  9. package/dist/block-RAIDCJ4F.js.map +1 -0
  10. package/dist/broadcast-BSI5NDDB.js +104 -0
  11. package/dist/broadcast-BSI5NDDB.js.map +1 -0
  12. package/dist/catchup-VVOPL2S5.js +51 -0
  13. package/dist/catchup-VVOPL2S5.js.map +1 -0
  14. package/dist/chunk-3JWTO5VZ.js +135 -0
  15. package/dist/chunk-3JWTO5VZ.js.map +1 -0
  16. package/dist/chunk-4BOK2GXL.js +210 -0
  17. package/dist/chunk-4BOK2GXL.js.map +1 -0
  18. package/dist/chunk-5QK7GB5K.js +112 -0
  19. package/dist/chunk-5QK7GB5K.js.map +1 -0
  20. package/dist/chunk-6AQRYLOB.js +16 -0
  21. package/dist/chunk-6AQRYLOB.js.map +1 -0
  22. package/dist/chunk-6FTIY5M6.js +120 -0
  23. package/dist/chunk-6FTIY5M6.js.map +1 -0
  24. package/dist/chunk-6H3MLDGG.js +48 -0
  25. package/dist/chunk-6H3MLDGG.js.map +1 -0
  26. package/dist/chunk-77XFJQGC.js +103 -0
  27. package/dist/chunk-77XFJQGC.js.map +1 -0
  28. package/dist/chunk-7H4BJ2YA.js +308 -0
  29. package/dist/chunk-7H4BJ2YA.js.map +1 -0
  30. package/dist/chunk-7HEB6SQS.js +257 -0
  31. package/dist/chunk-7HEB6SQS.js.map +1 -0
  32. package/dist/chunk-7NAXFBFI.js +206 -0
  33. package/dist/chunk-7NAXFBFI.js.map +1 -0
  34. package/dist/chunk-7NCW3LUT.js +358 -0
  35. package/dist/chunk-7NCW3LUT.js.map +1 -0
  36. package/dist/chunk-7OLPI334.js +537 -0
  37. package/dist/chunk-7OLPI334.js.map +1 -0
  38. package/dist/chunk-ABQYKTG4.js +38 -0
  39. package/dist/chunk-ABQYKTG4.js.map +1 -0
  40. package/dist/chunk-AH5TM3NB.js +21 -0
  41. package/dist/chunk-AH5TM3NB.js.map +1 -0
  42. package/dist/chunk-AKMPF72Y.js +274 -0
  43. package/dist/chunk-AKMPF72Y.js.map +1 -0
  44. package/dist/chunk-C2BK6EBN.js +162 -0
  45. package/dist/chunk-C2BK6EBN.js.map +1 -0
  46. package/dist/chunk-C2THFSXA.js +37 -0
  47. package/dist/chunk-C2THFSXA.js.map +1 -0
  48. package/dist/chunk-CLGVSX36.js +668 -0
  49. package/dist/chunk-CLGVSX36.js.map +1 -0
  50. package/dist/chunk-CXEC5W5V.js +267 -0
  51. package/dist/chunk-CXEC5W5V.js.map +1 -0
  52. package/dist/chunk-DW4JPVXB.js +41 -0
  53. package/dist/chunk-DW4JPVXB.js.map +1 -0
  54. package/dist/chunk-FR3EWVXI.js +188 -0
  55. package/dist/chunk-FR3EWVXI.js.map +1 -0
  56. package/dist/chunk-H5LKMR45.js +117 -0
  57. package/dist/chunk-H5LKMR45.js.map +1 -0
  58. package/dist/chunk-HSICXDMZ.js +41 -0
  59. package/dist/chunk-HSICXDMZ.js.map +1 -0
  60. package/dist/chunk-HUXS3VAI.js +90 -0
  61. package/dist/chunk-HUXS3VAI.js.map +1 -0
  62. package/dist/chunk-HWUINPIL.js +151 -0
  63. package/dist/chunk-HWUINPIL.js.map +1 -0
  64. package/dist/chunk-IXKVCR4Y.js +487 -0
  65. package/dist/chunk-IXKVCR4Y.js.map +1 -0
  66. package/dist/chunk-JNBYNRFS.js +54 -0
  67. package/dist/chunk-JNBYNRFS.js.map +1 -0
  68. package/dist/chunk-JYTMT5DF.js +421 -0
  69. package/dist/chunk-JYTMT5DF.js.map +1 -0
  70. package/dist/chunk-KA4JVX5U.js +295 -0
  71. package/dist/chunk-KA4JVX5U.js.map +1 -0
  72. package/dist/chunk-KGZ6OZ2T.js +102 -0
  73. package/dist/chunk-KGZ6OZ2T.js.map +1 -0
  74. package/dist/chunk-LNHSBM4L.js +26 -0
  75. package/dist/chunk-LNHSBM4L.js.map +1 -0
  76. package/dist/chunk-M4FVCAT6.js +2406 -0
  77. package/dist/chunk-M4FVCAT6.js.map +1 -0
  78. package/dist/chunk-MAGGGRSB.js +9 -0
  79. package/dist/chunk-MAGGGRSB.js.map +1 -0
  80. package/dist/chunk-N4EYQKSM.js +104 -0
  81. package/dist/chunk-N4EYQKSM.js.map +1 -0
  82. package/dist/chunk-NDWSLQPB.js +112 -0
  83. package/dist/chunk-NDWSLQPB.js.map +1 -0
  84. package/dist/chunk-O3QTWVSK.js +323 -0
  85. package/dist/chunk-O3QTWVSK.js.map +1 -0
  86. package/dist/chunk-P3BL4EOP.js +37 -0
  87. package/dist/chunk-P3BL4EOP.js.map +1 -0
  88. package/dist/chunk-PN44M5EE.js +887 -0
  89. package/dist/chunk-PN44M5EE.js.map +1 -0
  90. package/dist/chunk-PZ4RG6EW.js +132 -0
  91. package/dist/chunk-PZ4RG6EW.js.map +1 -0
  92. package/dist/chunk-Q6WZCO45.js +47 -0
  93. package/dist/chunk-Q6WZCO45.js.map +1 -0
  94. package/dist/chunk-QBAZG4CY.js +230 -0
  95. package/dist/chunk-QBAZG4CY.js.map +1 -0
  96. package/dist/chunk-R2LN3JJJ.js +132 -0
  97. package/dist/chunk-R2LN3JJJ.js.map +1 -0
  98. package/dist/chunk-RCYI7SRA.js +15 -0
  99. package/dist/chunk-RCYI7SRA.js.map +1 -0
  100. package/dist/chunk-RYNBBSLY.js +67 -0
  101. package/dist/chunk-RYNBBSLY.js.map +1 -0
  102. package/dist/chunk-S5HJT7CM.js +30 -0
  103. package/dist/chunk-S5HJT7CM.js.map +1 -0
  104. package/dist/chunk-SNAQOHNL.js +285 -0
  105. package/dist/chunk-SNAQOHNL.js.map +1 -0
  106. package/dist/chunk-SOCPIHCS.js +181 -0
  107. package/dist/chunk-SOCPIHCS.js.map +1 -0
  108. package/dist/chunk-TUC4QY4O.js +147 -0
  109. package/dist/chunk-TUC4QY4O.js.map +1 -0
  110. package/dist/chunk-TUFQJXXO.js +19 -0
  111. package/dist/chunk-TUFQJXXO.js.map +1 -0
  112. package/dist/chunk-UFY7C5PP.js +90 -0
  113. package/dist/chunk-UFY7C5PP.js.map +1 -0
  114. package/dist/chunk-UQ35KLHH.js +34 -0
  115. package/dist/chunk-UQ35KLHH.js.map +1 -0
  116. package/dist/chunk-VJ7SVDED.js +177 -0
  117. package/dist/chunk-VJ7SVDED.js.map +1 -0
  118. package/dist/chunk-VJNSIDOA.js +23 -0
  119. package/dist/chunk-VJNSIDOA.js.map +1 -0
  120. package/dist/chunk-WF5SBVPZ.js +190 -0
  121. package/dist/chunk-WF5SBVPZ.js.map +1 -0
  122. package/dist/chunk-WMJIU3YW.js +29 -0
  123. package/dist/chunk-WMJIU3YW.js.map +1 -0
  124. package/dist/chunk-XJDEROHY.js +19 -0
  125. package/dist/chunk-XJDEROHY.js.map +1 -0
  126. package/dist/chunk-YKODIG22.js +221 -0
  127. package/dist/chunk-YKODIG22.js.map +1 -0
  128. package/dist/chunk-YLG6DO5Y.js +162 -0
  129. package/dist/chunk-YLG6DO5Y.js.map +1 -0
  130. package/dist/chunk-YNKWLC45.js +122 -0
  131. package/dist/chunk-YNKWLC45.js.map +1 -0
  132. package/dist/chunk-YZDD5YGE.js +165 -0
  133. package/dist/chunk-YZDD5YGE.js.map +1 -0
  134. package/dist/chunk-YZWADOEW.js +151 -0
  135. package/dist/chunk-YZWADOEW.js.map +1 -0
  136. package/dist/chunk-ZJN5RWZD.js +76 -0
  137. package/dist/chunk-ZJN5RWZD.js.map +1 -0
  138. package/dist/chunk-ZSHWP2VS.js +22 -0
  139. package/dist/chunk-ZSHWP2VS.js.map +1 -0
  140. package/dist/chunk-ZXPYWZL5.js +307 -0
  141. package/dist/chunk-ZXPYWZL5.js.map +1 -0
  142. package/dist/cleanup-X45MA74G.js +192 -0
  143. package/dist/cleanup-X45MA74G.js.map +1 -0
  144. package/dist/cli-52VWEHIQ.js +18 -0
  145. package/dist/cli-52VWEHIQ.js.map +1 -0
  146. package/dist/command-hook-installer-SGEJTZ2Y.js +204 -0
  147. package/dist/command-hook-installer-SGEJTZ2Y.js.map +1 -0
  148. package/dist/completion-MXX5TRIV.js +118 -0
  149. package/dist/completion-MXX5TRIV.js.map +1 -0
  150. package/dist/config-IEIU7A66.js +410 -0
  151. package/dist/config-IEIU7A66.js.map +1 -0
  152. package/dist/console-reporter-XU6VFUZE.js +10 -0
  153. package/dist/console-reporter-XU6VFUZE.js.map +1 -0
  154. package/dist/diff-K47HB6SA.js +582 -0
  155. package/dist/diff-K47HB6SA.js.map +1 -0
  156. package/dist/digest-FBZTBXQO.js +100 -0
  157. package/dist/digest-FBZTBXQO.js.map +1 -0
  158. package/dist/fork-BKI5UNNS.js +120 -0
  159. package/dist/fork-BKI5UNNS.js.map +1 -0
  160. package/dist/hook-SLMZT5OV.js +220 -0
  161. package/dist/hook-SLMZT5OV.js.map +1 -0
  162. package/dist/hydrate-Y2AAMZTA.js +121 -0
  163. package/dist/hydrate-Y2AAMZTA.js.map +1 -0
  164. package/dist/init-7ESFTYZC.js +187 -0
  165. package/dist/init-7ESFTYZC.js.map +1 -0
  166. package/dist/install-skills-O34BHFHD.js +14 -0
  167. package/dist/install-skills-O34BHFHD.js.map +1 -0
  168. package/dist/install-skills-bin.js +12 -0
  169. package/dist/install-skills-bin.js.map +1 -0
  170. package/dist/list-KEF73NLQ.js +126 -0
  171. package/dist/list-KEF73NLQ.js.map +1 -0
  172. package/dist/move-FKT2P5LY.js +313 -0
  173. package/dist/move-FKT2P5LY.js.map +1 -0
  174. package/dist/note-WGM6LCP2.js +78 -0
  175. package/dist/note-WGM6LCP2.js.map +1 -0
  176. package/dist/overlaps-FRLMMIGC.js +56 -0
  177. package/dist/overlaps-FRLMMIGC.js.map +1 -0
  178. package/dist/pin-MQ5ZE37R.js +45 -0
  179. package/dist/pin-MQ5ZE37R.js.map +1 -0
  180. package/dist/pr-YU3NOW6G.js +118 -0
  181. package/dist/pr-YU3NOW6G.js.map +1 -0
  182. package/dist/prune-26FYYFTO.js +92 -0
  183. package/dist/prune-26FYYFTO.js.map +1 -0
  184. package/dist/pty-host-RWIS55N4.js +826 -0
  185. package/dist/pty-host-RWIS55N4.js.map +1 -0
  186. package/dist/read-AP6T3ZGN.js +57 -0
  187. package/dist/read-AP6T3ZGN.js.map +1 -0
  188. package/dist/recent-IE3LYQ65.js +111 -0
  189. package/dist/recent-IE3LYQ65.js.map +1 -0
  190. package/dist/remove-2UHJQ4DY.js +108 -0
  191. package/dist/remove-2UHJQ4DY.js.map +1 -0
  192. package/dist/report-KM4OZCZB.js +16 -0
  193. package/dist/report-KM4OZCZB.js.map +1 -0
  194. package/dist/resume-UUP6R2IE.js +81 -0
  195. package/dist/resume-UUP6R2IE.js.map +1 -0
  196. package/dist/run-V4755W7C.js +263 -0
  197. package/dist/run-V4755W7C.js.map +1 -0
  198. package/dist/screen-DNX4K23V.js +58 -0
  199. package/dist/screen-DNX4K23V.js.map +1 -0
  200. package/dist/search-3JZXLCR2.js +46 -0
  201. package/dist/search-3JZXLCR2.js.map +1 -0
  202. package/dist/section-TXLC5XO3.js +79 -0
  203. package/dist/section-TXLC5XO3.js.map +1 -0
  204. package/dist/send-6X46WZLC.js +87 -0
  205. package/dist/send-6X46WZLC.js.map +1 -0
  206. package/dist/sessions-T3QDTNP7.js +135 -0
  207. package/dist/sessions-T3QDTNP7.js.map +1 -0
  208. package/dist/snooze-KYSFXLPY.js +65 -0
  209. package/dist/snooze-KYSFXLPY.js.map +1 -0
  210. package/dist/start-SQSDQK4F.js +56 -0
  211. package/dist/start-SQSDQK4F.js.map +1 -0
  212. package/dist/state-4DFV6SHG.js +147 -0
  213. package/dist/state-4DFV6SHG.js.map +1 -0
  214. package/dist/status-H5OW4LYE.js +118 -0
  215. package/dist/status-H5OW4LYE.js.map +1 -0
  216. package/dist/stop-HC7XPSSP.js +45 -0
  217. package/dist/stop-HC7XPSSP.js.map +1 -0
  218. package/dist/sync-3CTAXM6J.js +96 -0
  219. package/dist/sync-3CTAXM6J.js.map +1 -0
  220. package/dist/time-GN6B4QD6.js +111 -0
  221. package/dist/time-GN6B4QD6.js.map +1 -0
  222. package/dist/todo-LWMQY6XW.js +152 -0
  223. package/dist/todo-LWMQY6XW.js.map +1 -0
  224. package/dist/tree-7BMORJ6J.js +235 -0
  225. package/dist/tree-7BMORJ6J.js.map +1 -0
  226. package/dist/update-6LQNLRA4.js +57 -0
  227. package/dist/update-6LQNLRA4.js.map +1 -0
  228. package/dist/wait-MZOZQ3CI.js +57 -0
  229. package/dist/wait-MZOZQ3CI.js.map +1 -0
  230. package/dist/wd-bin.js +21 -11912
  231. package/dist/wd-bin.js.map +1 -1
  232. package/dist/web/assets/PtyView-BrP-ENHg.css +1 -0
  233. package/dist/web/assets/PtyView-M4b0GFVs.js +90 -0
  234. package/dist/web/assets/PtyView-M4b0GFVs.js.map +1 -0
  235. package/dist/web/assets/index-5hi1kMKy.js +116 -0
  236. package/dist/web/assets/index-5hi1kMKy.js.map +1 -0
  237. package/dist/web/assets/index-L8mjakHP.css +1 -0
  238. package/dist/web/index.html +3 -5
  239. package/dist/web-BI3MRQEM.js +7662 -0
  240. package/dist/web-BI3MRQEM.js.map +1 -0
  241. package/npm-shrinkwrap.json +6947 -0
  242. package/package.json +52 -34
  243. package/plugins/work-tree/.claude-plugin/plugin.json +1 -1
  244. package/plugins/work-tree/skills/wd-review/SKILL.md +4 -4
  245. package/plugins/work-tree/skills/work-sessions/SKILL.md +62 -0
  246. package/scripts/postinstall.mjs +15 -45
  247. package/dist/web/assets/index-B9H3vCtL.js +0 -107
  248. package/dist/web/assets/index-B9H3vCtL.js.map +0 -1
  249. package/dist/web/assets/index-BseMpW5i.css +0 -1
@@ -0,0 +1,582 @@
1
+ #!/usr/bin/env node
2
+ import {
3
+ buildRepoSpecs,
4
+ commentInputSchema,
5
+ findAnyParentBranch,
6
+ resolveBase,
7
+ resolveSchema,
8
+ resolveScope,
9
+ resolveWebRoot,
10
+ startDiffServer,
11
+ submitReviewSchema
12
+ } from "./chunk-IXKVCR4Y.js";
13
+ import {
14
+ resolveWorkBinPath
15
+ } from "./chunk-AH5TM3NB.js";
16
+ import {
17
+ computeDiff
18
+ } from "./chunk-7OLPI334.js";
19
+ import "./chunk-LNHSBM4L.js";
20
+ import {
21
+ existingWebDecision,
22
+ readWebUrl,
23
+ webServerResponds,
24
+ webUrlPath
25
+ } from "./chunk-3JWTO5VZ.js";
26
+ import {
27
+ stableDiffPath
28
+ } from "./chunk-ZSHWP2VS.js";
29
+ import {
30
+ createCommentStore
31
+ } from "./chunk-HUXS3VAI.js";
32
+ import "./chunk-7NAXFBFI.js";
33
+ import {
34
+ openUrl
35
+ } from "./chunk-P3BL4EOP.js";
36
+ import "./chunk-M4FVCAT6.js";
37
+ import "./chunk-7NCW3LUT.js";
38
+ import {
39
+ spawnDetachedWork
40
+ } from "./chunk-PN44M5EE.js";
41
+ import "./chunk-RCYI7SRA.js";
42
+ import "./chunk-DW4JPVXB.js";
43
+ import "./chunk-N4EYQKSM.js";
44
+ import "./chunk-7HEB6SQS.js";
45
+
46
+ // src/commands/diff.ts
47
+ import fs2 from "fs";
48
+ import os from "os";
49
+ import path2 from "path";
50
+ import chalk from "chalk";
51
+
52
+ // src/server/comment-server.ts
53
+ import { Hono } from "hono";
54
+ import { zValidator } from "@hono/zod-validator";
55
+ async function startCommentServer(opts) {
56
+ const store = createCommentStore();
57
+ let resolveDone = null;
58
+ const donePromise = new Promise((resolve) => {
59
+ resolveDone = resolve;
60
+ });
61
+ function attachRoutes(api) {
62
+ const routes = new Hono();
63
+ routes.get("/api/comments", (c) => c.json({ comments: store.snapshot() }));
64
+ routes.post("/api/comments", zValidator("json", commentInputSchema), (c) => {
65
+ try {
66
+ const input = c.req.valid("json");
67
+ const comment = store.post(input);
68
+ if (comment.status === "published" && comment.author === "user" && opts.onComment) {
69
+ opts.onComment(comment);
70
+ }
71
+ if (comment.author === "claude") {
72
+ api.broadcast("comments-changed", { id: comment.id });
73
+ }
74
+ return c.json({ comment, comments: store.snapshot() });
75
+ } catch (err) {
76
+ return c.json({ error: err.message }, 400);
77
+ }
78
+ });
79
+ routes.delete("/api/comments/:id", (c) => {
80
+ const id = c.req.param("id");
81
+ const removed = store.remove(id);
82
+ if (removed && opts.onCommentDeleted) opts.onCommentDeleted(id);
83
+ return c.json({ comments: store.snapshot() });
84
+ });
85
+ routes.post("/api/comments/:id/resolve", zValidator("json", resolveSchema), (c) => {
86
+ const updated = store.setResolved(c.req.param("id"), c.req.valid("json").resolved);
87
+ if (updated) api.broadcast("comments-changed", { id: updated.id });
88
+ return c.json({ comments: store.snapshot() });
89
+ });
90
+ routes.post("/api/submit-review", zValidator("json", submitReviewSchema), (c) => {
91
+ const body = c.req.valid("json");
92
+ const result = store.submit(body.summary);
93
+ if (opts.onSubmitReviewStart) {
94
+ opts.onSubmitReviewStart({
95
+ count: result.drafts.length,
96
+ summary: result.summary
97
+ });
98
+ }
99
+ if (result.summary && opts.onComment) opts.onComment(result.summary);
100
+ if (opts.onComment) {
101
+ for (const d of result.drafts) opts.onComment(d);
102
+ }
103
+ if (opts.onSubmitReviewEnd) opts.onSubmitReviewEnd();
104
+ return c.json({
105
+ count: result.drafts.length,
106
+ comments: store.snapshot()
107
+ });
108
+ });
109
+ routes.post("/api/discard-review", (c) => {
110
+ const discarded = store.discardDrafts();
111
+ return c.json({ discarded, comments: store.snapshot() });
112
+ });
113
+ routes.post("/api/done", (c) => {
114
+ const out = c.json({ ok: true, count: store.list().length });
115
+ if (resolveDone) {
116
+ resolveDone(store.snapshot());
117
+ resolveDone = null;
118
+ }
119
+ return out;
120
+ });
121
+ api.route("/", routes);
122
+ }
123
+ const server = await startDiffServer({
124
+ repos: opts.repos,
125
+ scopeLabel: opts.scopeLabel,
126
+ sessionBaseBranch: opts.sessionBaseBranch,
127
+ sessionBaseBranches: opts.sessionBaseBranches,
128
+ watchDebounceMs: opts.watchDebounceMs,
129
+ attachRoutes
130
+ });
131
+ return {
132
+ url: server.url,
133
+ waitForDone: () => donePromise,
134
+ snapshot: () => store.snapshot(),
135
+ stop: () => server.stop()
136
+ };
137
+ }
138
+ function formatSingleComment(c) {
139
+ const bodyLines = c.body.split("\n").map((l) => `> ${l}`).join("\n");
140
+ const header = c.side === "general" ? `**General review comment**` : c.side === "file" ? `**${c.repo}/${c.file}** : whole file` : `**${c.repo}/${c.file}** : line ${c.line} (${c.side})`;
141
+ const meta = [];
142
+ if (c.author === "claude") meta.push("author: claude");
143
+ if (c.parentId) meta.push(`reply-to: ${c.parentId}`);
144
+ meta.push(`id: ${c.id}`);
145
+ return [`--- comment ---`, header, meta.join(" \xB7 "), bodyLines, ``].join("\n");
146
+ }
147
+
148
+ // src/core/comments/review-poll.ts
149
+ function diffReviewSnapshot(snapshot, seen) {
150
+ const now = new Set(snapshot.map((c) => c.id));
151
+ const deleted = [];
152
+ for (const id of seen) {
153
+ if (!now.has(id)) deleted.push(id);
154
+ }
155
+ for (const id of deleted) seen.delete(id);
156
+ const newComments = [];
157
+ for (const c of snapshot) {
158
+ if (seen.has(c.id)) continue;
159
+ if (c.status === "draft") continue;
160
+ newComments.push(c);
161
+ }
162
+ for (const c of snapshot) {
163
+ if (c.status === "published") seen.add(c.id);
164
+ }
165
+ return { newComments, deleted };
166
+ }
167
+
168
+ // src/core/diff/static-renderer.ts
169
+ import fs from "fs";
170
+ import path from "path";
171
+ function buildDiff(specs, resolvedBase) {
172
+ return {
173
+ repos: specs.map((r) => ({
174
+ name: r.name,
175
+ root: r.root,
176
+ files: computeDiff({ root: r.root, diffArg: r.diffArg })
177
+ })),
178
+ resolvedBase
179
+ };
180
+ }
181
+ function renderStatic(opts) {
182
+ const webRoot = resolveWebRoot();
183
+ if (!webRoot) {
184
+ throw new Error("Could not find dist/web/. Run `npm run build` first.");
185
+ }
186
+ const shellPath = path.join(webRoot, "index.html");
187
+ let shell = fs.readFileSync(shellPath, "utf-8");
188
+ const uncommitted = buildDiff(opts.uncommitted, "HEAD");
189
+ const branch = opts.branch ? buildDiff(opts.branch.specs, opts.branch.resolvedBase) : void 0;
190
+ const initialBase = opts.initialBase ?? "uncommitted";
191
+ const initial = initialBase === "branch" && branch ? branch : uncommitted;
192
+ const boot = {
193
+ context: {
194
+ mode: "review",
195
+ scopeLabel: opts.scopeLabel,
196
+ repos: opts.uncommitted.map((r) => ({ name: r.name })),
197
+ readOnly: true,
198
+ staticMode: true,
199
+ initialBase: branch ? initialBase : "uncommitted"
200
+ },
201
+ diffs: { uncommitted, branch },
202
+ diff: initial
203
+ };
204
+ const bootJson = escapeForScriptTag(JSON.stringify(boot));
205
+ const bootScript = `<script>window.__WD_BOOT__=${bootJson};</script>`;
206
+ shell = shell.replace(/<\/head>/i, () => `${bootScript}</head>`);
207
+ shell = shell.replace(/<link rel="stylesheet"[^>]*href="([^"]+)"[^>]*>/g, (_match, href) => {
208
+ const css = readAsset(webRoot, href);
209
+ if (!css) return "";
210
+ const escaped = css.replace(/<\/style/gi, "<\\/style");
211
+ return `<style>${escaped}</style>`;
212
+ });
213
+ shell = shell.replace(/<script\b[^>]*\bsrc="([^"]+)"[^>]*><\/script>/g, (_match, src) => {
214
+ const js = readAsset(webRoot, src);
215
+ if (!js) return "";
216
+ const escaped = js.replace(/<\/script/gi, "<\\/script");
217
+ return `<script type="module">${escaped}</script>`;
218
+ });
219
+ return shell;
220
+ }
221
+ function escapeForScriptTag(json) {
222
+ const LS_RE = new RegExp("\\u2028", "g");
223
+ const PS_RE = new RegExp("\\u2029", "g");
224
+ return json.replace(/<(\/script|!--)/gi, "\\u003c$1").replace(LS_RE, "\\u2028").replace(PS_RE, "\\u2029").replace(/[\x00-\x08\x0b\x0c\x0e-\x1f]/g, (c) => {
225
+ return "\\u" + c.charCodeAt(0).toString(16).padStart(4, "0");
226
+ }).replace(/\n/g, "\\n").replace(/\r/g, "\\r");
227
+ }
228
+ function readAsset(webRoot, urlPath) {
229
+ const clean = urlPath.split("?")[0].replace(/^\//, "");
230
+ const full = path.join(webRoot, clean);
231
+ if (!path.normalize(full).startsWith(path.normalize(webRoot))) return null;
232
+ try {
233
+ return fs.readFileSync(full, "utf-8");
234
+ } catch {
235
+ return null;
236
+ }
237
+ }
238
+
239
+ // src/commands/diff.ts
240
+ function info(message) {
241
+ process.stderr.write(message + "\n");
242
+ }
243
+ function scopePathStem(repoSpecs) {
244
+ return stableDiffPath(repoSpecs.map((r) => r.root));
245
+ }
246
+ async function runStop(repoSpecs) {
247
+ const webUrl = readWebUrl();
248
+ if (!webUrl) {
249
+ info(chalk.gray("No work web running \u2014 nothing to stop."));
250
+ return;
251
+ }
252
+ const hash = stableDiffPath(repoSpecs.map((r) => r.root)).split(/[\\/]/).pop();
253
+ try {
254
+ const res = await fetch(`${webUrl}api/scopes/${hash}`, {
255
+ method: "DELETE"
256
+ });
257
+ if (res.ok) {
258
+ info(chalk.gray("De-registered this scope from work web."));
259
+ } else {
260
+ info(chalk.yellow(`work web responded ${res.status} \u2014 scope may not have been registered.`));
261
+ }
262
+ } catch (err) {
263
+ console.error(chalk.red("Could not reach work web:"), err.message);
264
+ }
265
+ }
266
+ async function ensureWorkWebRunning() {
267
+ const existing = readWebUrl();
268
+ if (existing) {
269
+ if (await existingWebDecision(existing) === "reuse") return existing;
270
+ try {
271
+ fs2.unlinkSync(webUrlPath());
272
+ } catch {
273
+ }
274
+ }
275
+ const workBin = resolveWorkBinPath(process.argv[1]);
276
+ spawnDetachedWork(workBin, ["web", "--lean", "--no-open"], path2.join(os.homedir(), ".work", "web-autostart.log"));
277
+ const url = await waitForUrlFile(webUrlPath(), 5e3);
278
+ return url;
279
+ }
280
+ async function tryRegisterWithWorkWeb(ctx, routeKind) {
281
+ const webUrl = await ensureWorkWebRunning();
282
+ if (!webUrl) return null;
283
+ try {
284
+ const res = await fetch(`${webUrl}api/scopes`, {
285
+ method: "POST",
286
+ headers: { "Content-Type": "application/json" },
287
+ body: JSON.stringify({
288
+ paths: ctx.repoSpecs.map((r) => r.root),
289
+ label: ctx.scopeLabel
290
+ })
291
+ });
292
+ if (!res.ok) return null;
293
+ const body = await res.json();
294
+ const route = routeKind === "diff" ? "diff" : "review";
295
+ return `${webUrl}${route}/${body.hash}`;
296
+ } catch {
297
+ return null;
298
+ }
299
+ }
300
+ async function runLauncher(ctx) {
301
+ const webRouteUrl = await tryRegisterWithWorkWeb(ctx, "diff");
302
+ if (webRouteUrl) {
303
+ info(chalk.gray(`Opening: ${webRouteUrl}`));
304
+ openUrl(webRouteUrl);
305
+ return;
306
+ }
307
+ console.error(chalk.red("Could not start or reach work web."));
308
+ console.error(
309
+ chalk.gray(`Tail ~/.work/web-autostart.log for diagnostics, or run \`work web\` in another shell to inspect startup directly.`)
310
+ );
311
+ process.exitCode = 1;
312
+ }
313
+ function runStatic(ctx, initialBranch) {
314
+ const uncommitted = buildRepoSpecs(ctx.scope, "HEAD");
315
+ const primaryRoot = ctx.scope.repos.find((r) => r.name === ctx.scope.activeRepoName)?.root ?? ctx.scope.repos[0].root;
316
+ const perRepoBase = ctx.scope.session?.baseBranches;
317
+ const parent = perRepoBase?.[primaryRoot] ?? ctx.scope.session?.baseBranch ?? findAnyParentBranch(primaryRoot);
318
+ const branch = parent === null ? void 0 : {
319
+ specs: buildRepoSpecs(ctx.scope, parent, perRepoBase),
320
+ resolvedBase: parent
321
+ };
322
+ const uncommittedTotal = uncommitted.reduce((s, r) => s + computeDiff({ root: r.root, diffArg: r.diffArg }).length, 0);
323
+ const branchTotal = branch ? branch.specs.reduce((s, r) => s + computeDiff({ root: r.root, diffArg: r.diffArg }).length, 0) : 0;
324
+ if (uncommittedTotal === 0 && branchTotal === 0) {
325
+ info(chalk.gray("No changes to show."));
326
+ return;
327
+ }
328
+ const html = renderStatic({
329
+ scopeLabel: ctx.scopeLabel,
330
+ uncommitted,
331
+ branch,
332
+ initialBase: initialBranch && branch ? "branch" : "uncommitted"
333
+ });
334
+ const filePath = `${ctx.scopeStem}.html`;
335
+ fs2.writeFileSync(filePath, html, "utf-8");
336
+ info(chalk.gray(`Wrote ${filePath}`));
337
+ openUrl(`file:///${filePath.replace(/\\/g, "/")}`);
338
+ }
339
+ function waitForUrlFile(filePath, timeoutMs) {
340
+ return new Promise((resolve) => {
341
+ const start = Date.now();
342
+ const tick = () => {
343
+ try {
344
+ const v = fs2.readFileSync(filePath, "utf-8").trim();
345
+ if (v) return resolve(v);
346
+ } catch {
347
+ }
348
+ if (Date.now() - start > timeoutMs) return resolve(null);
349
+ setTimeout(tick, 75);
350
+ };
351
+ tick();
352
+ });
353
+ }
354
+ async function tryReviewViaWorkWeb(ctx) {
355
+ const webUrl = await ensureWorkWebRunning();
356
+ if (!webUrl) return false;
357
+ let hash;
358
+ try {
359
+ const res = await fetch(`${webUrl}api/scopes`, {
360
+ method: "POST",
361
+ headers: { "Content-Type": "application/json" },
362
+ body: JSON.stringify({
363
+ paths: ctx.repoSpecs.map((r) => r.root),
364
+ label: ctx.scopeLabel
365
+ })
366
+ });
367
+ if (!res.ok) return false;
368
+ hash = (await res.json()).hash;
369
+ } catch {
370
+ return false;
371
+ }
372
+ const initialTotal = ctx.repoSpecs.reduce((s, r) => s + computeDiff({ root: r.root, diffArg: r.diffArg }).length, 0);
373
+ const reviewUrl = `${webUrl}review/${hash}`;
374
+ info(chalk.gray(`Opening review in work web: ${reviewUrl}`));
375
+ info(chalk.gray("Comments stream below. Ctrl+C to detach."));
376
+ process.stdout.write(
377
+ `--- review started ---
378
+ repos: ${ctx.repoSpecs.map((r) => r.name).join(", ")}
379
+ files: ${initialTotal}
380
+ url: ${reviewUrl}
381
+
382
+ `
383
+ );
384
+ openUrl(reviewUrl);
385
+ const seen = /* @__PURE__ */ new Set();
386
+ let exiting = false;
387
+ let interval = null;
388
+ let polling = false;
389
+ async function poll() {
390
+ if (exiting || polling) return;
391
+ polling = true;
392
+ try {
393
+ const res = await fetch(`${webUrl}api/scopes/${hash}/comments`);
394
+ if (res.status === 404) {
395
+ process.stdout.write(`--- review done ---
396
+ total: ${seen.size}
397
+ `);
398
+ cleanup();
399
+ process.exit(0);
400
+ }
401
+ if (!res.ok) return;
402
+ const { comments, ended } = await res.json();
403
+ const { newComments, deleted } = diffReviewSnapshot(comments, seen);
404
+ for (const id of deleted) {
405
+ process.stdout.write(`--- comment deleted ---
406
+ id: ${id}
407
+
408
+ `);
409
+ }
410
+ for (const c of newComments) {
411
+ process.stdout.write(formatSingleComment(c));
412
+ }
413
+ if (ended) {
414
+ process.stdout.write(`--- review done ---
415
+ total: ${seen.size}
416
+ `);
417
+ cleanup();
418
+ process.exit(0);
419
+ }
420
+ } catch {
421
+ } finally {
422
+ polling = false;
423
+ }
424
+ }
425
+ function cleanup() {
426
+ exiting = true;
427
+ if (interval) clearInterval(interval);
428
+ }
429
+ const onSignal = () => {
430
+ process.stdout.write(`--- review aborted (signal) ---
431
+ `);
432
+ cleanup();
433
+ process.exit(0);
434
+ };
435
+ process.on("SIGINT", onSignal);
436
+ process.on("SIGTERM", onSignal);
437
+ interval = setInterval(poll, 1e3);
438
+ await poll();
439
+ await new Promise(() => {
440
+ });
441
+ return true;
442
+ }
443
+ async function runReview(ctx) {
444
+ const initialTotal = ctx.repoSpecs.reduce((s, r) => s + computeDiff({ root: r.root, diffArg: r.diffArg }).length, 0);
445
+ if (initialTotal === 0) {
446
+ info(chalk.gray("No changes to review."));
447
+ return;
448
+ }
449
+ if (await tryReviewViaWorkWeb(ctx)) return;
450
+ const onComment = (c) => {
451
+ process.stdout.write(formatSingleComment(c));
452
+ };
453
+ const onCommentDeleted = (id) => {
454
+ process.stdout.write(`--- comment deleted ---
455
+ id: ${id}
456
+
457
+ `);
458
+ };
459
+ const onSubmitReviewStart = (info2) => {
460
+ const head = `--- review submitted ---
461
+ count: ${info2.count}${info2.summary ? `
462
+ summary-id: ${info2.summary.id}` : ""}
463
+
464
+ `;
465
+ process.stdout.write(head);
466
+ };
467
+ const onSubmitReviewEnd = () => {
468
+ process.stdout.write(`--- review batch end ---
469
+
470
+ `);
471
+ };
472
+ const handle = await startCommentServer({
473
+ repos: ctx.repoSpecs,
474
+ scopeLabel: ctx.scopeLabel,
475
+ sessionBaseBranch: ctx.scope.session?.baseBranch,
476
+ sessionBaseBranches: ctx.scope.session?.baseBranches,
477
+ onComment,
478
+ onCommentDeleted,
479
+ onSubmitReviewStart,
480
+ onSubmitReviewEnd
481
+ });
482
+ info(chalk.gray("Opening browser for review. Comments stream as you save them."));
483
+ info(chalk.gray('Page reloads automatically when you save a file. Click "End review" (or Ctrl+C) when finished.'));
484
+ process.stdout.write(
485
+ `--- review started ---
486
+ repos: ${ctx.repoSpecs.map((r) => r.name).join(", ")}
487
+ files: ${initialTotal}
488
+ url: ${handle.url}
489
+
490
+ `
491
+ );
492
+ openUrl(handle.url);
493
+ const cleanup = () => {
494
+ void handle.stop();
495
+ };
496
+ const onSignal = () => {
497
+ process.stdout.write(`--- review aborted (signal) ---
498
+ `);
499
+ cleanup();
500
+ process.exit(0);
501
+ };
502
+ process.on("SIGINT", onSignal);
503
+ process.on("SIGTERM", onSignal);
504
+ const comments = await handle.waitForDone();
505
+ await new Promise((r) => setTimeout(r, 100));
506
+ cleanup();
507
+ process.stdout.write(`--- review done ---
508
+ total: ${comments.length}
509
+ `);
510
+ }
511
+ var diffCommand = {
512
+ command: "diff [base]",
513
+ describe: "Open a GitHub-PR-style diff overview in your browser",
514
+ builder: (yargs) => yargs.positional("base", {
515
+ describe: "Base ref to compare against. Default: HEAD (uncommitted only). Use --branch for a full PR-style diff vs the parent branch.",
516
+ type: "string"
517
+ }).option("branch", {
518
+ type: "boolean",
519
+ default: false,
520
+ describe: 'Open the "Since branch" tab by default (still shows uncommitted as the other tab \u2014 toggle in the browser).'
521
+ }).option("static", {
522
+ type: "boolean",
523
+ default: false,
524
+ describe: "Write a self-contained HTML file with the current diff inlined (no server, no live reload). The default is a live server you can refresh."
525
+ }).option("server", {
526
+ type: "boolean",
527
+ default: false,
528
+ hidden: true,
529
+ describe: "Run a live server (now the default; flag kept for back-compat)."
530
+ }).option("watch", {
531
+ type: "boolean",
532
+ default: false,
533
+ hidden: true,
534
+ describe: "Alias for --server. Kept for back-compat."
535
+ }).option("stop", {
536
+ type: "boolean",
537
+ default: false,
538
+ describe: "De-register this scope from work web. The work web server itself keeps running; use `work web --stop` to terminate the server."
539
+ }).option("comments", {
540
+ type: "boolean",
541
+ alias: "c",
542
+ default: false,
543
+ describe: 'Review mode: open the diff in a browser with a comment UI; block until you click "Done & Send", then print all comments to stdout as markdown.'
544
+ }),
545
+ handler: async (argv) => {
546
+ const scope = resolveScope(process.cwd());
547
+ if (!scope) {
548
+ console.error(chalk.red("Not inside a git repository or known worktree."));
549
+ process.exit(1);
550
+ }
551
+ const { base, source: baseSource } = resolveBase(scope, {
552
+ base: argv.base,
553
+ branch: argv.branch
554
+ });
555
+ const repoSpecs = buildRepoSpecs(scope, base);
556
+ const scopeStem = scopePathStem(repoSpecs);
557
+ if (argv.stop) return runStop(repoSpecs);
558
+ if (base === "HEAD") {
559
+ info(chalk.gray("Showing uncommitted changes vs HEAD."));
560
+ } else {
561
+ info(chalk.gray(`Showing diff vs ${base} [${baseSource}]${scope.isGroup ? `, across ${scope.repos.length} repos` : ""}.`));
562
+ }
563
+ const scopeLabel = `${scope.repos.map((r) => r.name).join(", ")} \xB7 ${base}`;
564
+ const ctx = {
565
+ scope,
566
+ base,
567
+ baseSource,
568
+ repoSpecs,
569
+ scopeStem,
570
+ scopeLabel
571
+ };
572
+ if (argv.comments) return runReview(ctx);
573
+ if (argv.static) return runStatic(ctx, !!argv.branch);
574
+ return runLauncher(ctx);
575
+ }
576
+ };
577
+ export {
578
+ diffCommand,
579
+ resolveWorkBinPath,
580
+ webServerResponds
581
+ };
582
+ //# sourceMappingURL=diff-K47HB6SA.js.map