@moberg_hr/work-tree 1.16.0 → 2.0.1

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-7HEB6SQS.js +257 -0
  29. package/dist/chunk-7HEB6SQS.js.map +1 -0
  30. package/dist/chunk-7NAXFBFI.js +206 -0
  31. package/dist/chunk-7NAXFBFI.js.map +1 -0
  32. package/dist/chunk-7NCW3LUT.js +358 -0
  33. package/dist/chunk-7NCW3LUT.js.map +1 -0
  34. package/dist/chunk-7OLPI334.js +537 -0
  35. package/dist/chunk-7OLPI334.js.map +1 -0
  36. package/dist/chunk-ABQYKTG4.js +38 -0
  37. package/dist/chunk-ABQYKTG4.js.map +1 -0
  38. package/dist/chunk-AH5TM3NB.js +21 -0
  39. package/dist/chunk-AH5TM3NB.js.map +1 -0
  40. package/dist/chunk-AKMPF72Y.js +274 -0
  41. package/dist/chunk-AKMPF72Y.js.map +1 -0
  42. package/dist/chunk-BR6OPEE4.js +162 -0
  43. package/dist/chunk-BR6OPEE4.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-C7W5TMFB.js +308 -0
  49. package/dist/chunk-C7W5TMFB.js.map +1 -0
  50. package/dist/chunk-CLGVSX36.js +668 -0
  51. package/dist/chunk-CLGVSX36.js.map +1 -0
  52. package/dist/chunk-CVAVYDXO.js +295 -0
  53. package/dist/chunk-CVAVYDXO.js.map +1 -0
  54. package/dist/chunk-DW4JPVXB.js +41 -0
  55. package/dist/chunk-DW4JPVXB.js.map +1 -0
  56. package/dist/chunk-FPKERDK7.js +142 -0
  57. package/dist/chunk-FPKERDK7.js.map +1 -0
  58. package/dist/chunk-FR3EWVXI.js +188 -0
  59. package/dist/chunk-FR3EWVXI.js.map +1 -0
  60. package/dist/chunk-H5LKMR45.js +117 -0
  61. package/dist/chunk-H5LKMR45.js.map +1 -0
  62. package/dist/chunk-HIZBWYPL.js +267 -0
  63. package/dist/chunk-HIZBWYPL.js.map +1 -0
  64. package/dist/chunk-HSICXDMZ.js +41 -0
  65. package/dist/chunk-HSICXDMZ.js.map +1 -0
  66. package/dist/chunk-HUXS3VAI.js +90 -0
  67. package/dist/chunk-HUXS3VAI.js.map +1 -0
  68. package/dist/chunk-HWUINPIL.js +151 -0
  69. package/dist/chunk-HWUINPIL.js.map +1 -0
  70. package/dist/chunk-IXKVCR4Y.js +487 -0
  71. package/dist/chunk-IXKVCR4Y.js.map +1 -0
  72. package/dist/chunk-JNBYNRFS.js +54 -0
  73. package/dist/chunk-JNBYNRFS.js.map +1 -0
  74. package/dist/chunk-JYTMT5DF.js +421 -0
  75. package/dist/chunk-JYTMT5DF.js.map +1 -0
  76. package/dist/chunk-KGZ6OZ2T.js +102 -0
  77. package/dist/chunk-KGZ6OZ2T.js.map +1 -0
  78. package/dist/chunk-LMIEEDDC.js +9 -0
  79. package/dist/chunk-LMIEEDDC.js.map +1 -0
  80. package/dist/chunk-LNHSBM4L.js +26 -0
  81. package/dist/chunk-LNHSBM4L.js.map +1 -0
  82. package/dist/chunk-M4FVCAT6.js +2406 -0
  83. package/dist/chunk-M4FVCAT6.js.map +1 -0
  84. package/dist/chunk-N4EYQKSM.js +104 -0
  85. package/dist/chunk-N4EYQKSM.js.map +1 -0
  86. package/dist/chunk-NDWSLQPB.js +112 -0
  87. package/dist/chunk-NDWSLQPB.js.map +1 -0
  88. package/dist/chunk-O3QTWVSK.js +323 -0
  89. package/dist/chunk-O3QTWVSK.js.map +1 -0
  90. package/dist/chunk-P3BL4EOP.js +37 -0
  91. package/dist/chunk-P3BL4EOP.js.map +1 -0
  92. package/dist/chunk-PN44M5EE.js +887 -0
  93. package/dist/chunk-PN44M5EE.js.map +1 -0
  94. package/dist/chunk-Q6WZCO45.js +47 -0
  95. package/dist/chunk-Q6WZCO45.js.map +1 -0
  96. package/dist/chunk-QBAZG4CY.js +230 -0
  97. package/dist/chunk-QBAZG4CY.js.map +1 -0
  98. package/dist/chunk-R2LN3JJJ.js +132 -0
  99. package/dist/chunk-R2LN3JJJ.js.map +1 -0
  100. package/dist/chunk-RCYI7SRA.js +15 -0
  101. package/dist/chunk-RCYI7SRA.js.map +1 -0
  102. package/dist/chunk-RYNBBSLY.js +67 -0
  103. package/dist/chunk-RYNBBSLY.js.map +1 -0
  104. package/dist/chunk-S5HJT7CM.js +30 -0
  105. package/dist/chunk-S5HJT7CM.js.map +1 -0
  106. package/dist/chunk-SNAQOHNL.js +285 -0
  107. package/dist/chunk-SNAQOHNL.js.map +1 -0
  108. package/dist/chunk-SOCPIHCS.js +181 -0
  109. package/dist/chunk-SOCPIHCS.js.map +1 -0
  110. package/dist/chunk-TUC4QY4O.js +147 -0
  111. package/dist/chunk-TUC4QY4O.js.map +1 -0
  112. package/dist/chunk-TUFQJXXO.js +19 -0
  113. package/dist/chunk-TUFQJXXO.js.map +1 -0
  114. package/dist/chunk-UFY7C5PP.js +90 -0
  115. package/dist/chunk-UFY7C5PP.js.map +1 -0
  116. package/dist/chunk-UQ35KLHH.js +34 -0
  117. package/dist/chunk-UQ35KLHH.js.map +1 -0
  118. package/dist/chunk-VJ7SVDED.js +177 -0
  119. package/dist/chunk-VJ7SVDED.js.map +1 -0
  120. package/dist/chunk-VJNSIDOA.js +23 -0
  121. package/dist/chunk-VJNSIDOA.js.map +1 -0
  122. package/dist/chunk-WF5SBVPZ.js +190 -0
  123. package/dist/chunk-WF5SBVPZ.js.map +1 -0
  124. package/dist/chunk-WMJIU3YW.js +29 -0
  125. package/dist/chunk-WMJIU3YW.js.map +1 -0
  126. package/dist/chunk-XJDEROHY.js +19 -0
  127. package/dist/chunk-XJDEROHY.js.map +1 -0
  128. package/dist/chunk-YKODIG22.js +221 -0
  129. package/dist/chunk-YKODIG22.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-LDBGWEKZ.js +192 -0
  143. package/dist/cleanup-LDBGWEKZ.js.map +1 -0
  144. package/dist/cli-UATB4RM2.js +18 -0
  145. package/dist/cli-UATB4RM2.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-527S5HXB.js +122 -0
  181. package/dist/pr-527S5HXB.js.map +1 -0
  182. package/dist/prune-AIS5YEXP.js +92 -0
  183. package/dist/prune-AIS5YEXP.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-YGUTSKZP.js +108 -0
  191. package/dist/remove-YGUTSKZP.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-ITK5UYGM.js +96 -0
  219. package/dist/sync-ITK5UYGM.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-DYvawzWb.js +90 -0
  234. package/dist/web/assets/PtyView-DYvawzWb.js.map +1 -0
  235. package/dist/web/assets/index-C5lJhIwK.js +116 -0
  236. package/dist/web/assets/index-C5lJhIwK.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-IC3P7EHZ.js +7689 -0
  240. package/dist/web-IC3P7EHZ.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,84 @@
1
+ #!/usr/bin/env node
2
+ import {
3
+ addBlocker,
4
+ blockKey,
5
+ blockRefFrom,
6
+ readBlock,
7
+ removeBlocker
8
+ } from "./chunk-YZWADOEW.js";
9
+ import {
10
+ sessionFromArgs,
11
+ sessionPositionals
12
+ } from "./chunk-HSICXDMZ.js";
13
+ import "./chunk-6AQRYLOB.js";
14
+ import "./chunk-WF5SBVPZ.js";
15
+ import "./chunk-ZSHWP2VS.js";
16
+ import "./chunk-5QK7GB5K.js";
17
+ import "./chunk-HUXS3VAI.js";
18
+ import {
19
+ findSession,
20
+ loadHistory
21
+ } from "./chunk-M4FVCAT6.js";
22
+ import {
23
+ sessionIdFor
24
+ } from "./chunk-7NCW3LUT.js";
25
+ import "./chunk-PN44M5EE.js";
26
+ import "./chunk-RCYI7SRA.js";
27
+ import "./chunk-DW4JPVXB.js";
28
+ import "./chunk-N4EYQKSM.js";
29
+ import "./chunk-7HEB6SQS.js";
30
+
31
+ // src/commands/block.ts
32
+ import chalk from "chalk";
33
+ var blockCommand = {
34
+ command: "block [target] [branch]",
35
+ describe: "Mark a session as waiting on another session or a PR (out of the Inbox until that is done)",
36
+ builder: (yargs) => sessionPositionals(yargs).option("on", { type: "string", describe: "The repo or group of the session it waits on" }).option("on-branch", { type: "string", describe: "The branch of the session it waits on" }).option("pr", { type: "string", describe: "A pull request URL it waits on" }).option("off", { type: "boolean", describe: "Stop waiting (on everything, or with --on/--pr on that one)" }),
37
+ handler: (argv) => {
38
+ const s = sessionFromArgs(argv);
39
+ if (!s) return;
40
+ const id = sessionIdFor(s);
41
+ const name = `${s.target} \xB7 ${s.branch}`;
42
+ let ref = null;
43
+ if (typeof argv.on === "string") {
44
+ const other = typeof argv["on-branch"] === "string" ? findSession(loadHistory(), argv.on, argv["on-branch"]) : null;
45
+ if (!other) {
46
+ console.error(chalk.red(`No live session ${argv.on} ${argv["on-branch"] ?? "(give --on-branch)"}.`));
47
+ process.exitCode = 1;
48
+ return;
49
+ }
50
+ ref = blockRefFrom({ kind: "session", id: sessionIdFor(other) });
51
+ } else if (typeof argv.pr === "string") {
52
+ ref = blockRefFrom({ kind: "pr", url: argv.pr });
53
+ if (!ref) {
54
+ console.error(chalk.red(`Not a GitHub pull request URL: ${argv.pr}`));
55
+ process.exitCode = 1;
56
+ return;
57
+ }
58
+ }
59
+ if (argv.off) {
60
+ removeBlocker(id, ref ? blockKey(ref) : void 0);
61
+ console.log(chalk.green(ref ? `${name} no longer waits on ${ref.label}.` : `${name} no longer waits on anything.`));
62
+ return;
63
+ }
64
+ if (!ref) {
65
+ const b = readBlock(id);
66
+ if (!b) console.log(chalk.gray(`${name} waits on nothing.`));
67
+ else
68
+ for (const x of b.by)
69
+ console.log(`${x.label}${x.kind === "pr" ? ` ${chalk.gray(x.url)}${x.state ? ` (${x.state.toLowerCase()})` : ""}` : ""}`);
70
+ return;
71
+ }
72
+ const r = addBlocker(id, ref);
73
+ if (!r.ok) {
74
+ console.error(chalk.red(r.error));
75
+ process.exitCode = 1;
76
+ return;
77
+ }
78
+ console.log(chalk.green(`${name} waits on ${ref.label}: out of the Inbox until it is done.`));
79
+ }
80
+ };
81
+ export {
82
+ blockCommand
83
+ };
84
+ //# sourceMappingURL=block-RAIDCJ4F.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/commands/block.ts"],"sourcesContent":["import chalk from 'chalk';\nimport type { CommandModule } from 'yargs';\nimport { blockRefFrom } from '../core/rail/session-blocks.js';\nimport { addBlocker, blockKey, readBlock, removeBlocker } from '../core/rail/session-blocks.js';\nimport { findSession, loadHistory } from '../core/sessions/history.js';\nimport { sessionIdFor } from '../core/sessions/session-id.js';\nimport { sessionFromArgs, sessionPositionals } from './shared/session-arg.js';\n\n/**\n * `work block` — \"Blocked by\" (session-blocks.ts) from a terminal: the\n * session waits on another session (`--on <alias> --on-branch <branch>`) or\n * a pull request (`--pr <url>`); `--off` stops waiting; no option lists it.\n */\nexport const blockCommand: CommandModule = {\n command: 'block [target] [branch]',\n describe: 'Mark a session as waiting on another session or a PR (out of the Inbox until that is done)',\n builder: (yargs) =>\n sessionPositionals(yargs)\n .option('on', { type: 'string', describe: 'The repo or group of the session it waits on' })\n .option('on-branch', { type: 'string', describe: 'The branch of the session it waits on' })\n .option('pr', { type: 'string', describe: 'A pull request URL it waits on' })\n .option('off', { type: 'boolean', describe: 'Stop waiting (on everything, or with --on/--pr on that one)' }),\n handler: (argv) => {\n const s = sessionFromArgs(argv);\n if (!s) return;\n const id = sessionIdFor(s);\n const name = `${s.target} · ${s.branch}`;\n let ref = null;\n if (typeof argv.on === 'string') {\n const other = typeof argv['on-branch'] === 'string' ? findSession(loadHistory(), argv.on, argv['on-branch']) : null;\n if (!other) {\n console.error(chalk.red(`No live session ${argv.on} ${argv['on-branch'] ?? '(give --on-branch)'}.`));\n process.exitCode = 1;\n return;\n }\n ref = blockRefFrom({ kind: 'session', id: sessionIdFor(other) });\n } else if (typeof argv.pr === 'string') {\n ref = blockRefFrom({ kind: 'pr', url: argv.pr });\n if (!ref) {\n console.error(chalk.red(`Not a GitHub pull request URL: ${argv.pr}`));\n process.exitCode = 1;\n return;\n }\n }\n if (argv.off) {\n removeBlocker(id, ref ? blockKey(ref) : undefined);\n console.log(chalk.green(ref ? `${name} no longer waits on ${ref.label}.` : `${name} no longer waits on anything.`));\n return;\n }\n if (!ref) {\n const b = readBlock(id);\n if (!b) console.log(chalk.gray(`${name} waits on nothing.`));\n else\n for (const x of b.by)\n console.log(`${x.label}${x.kind === 'pr' ? ` ${chalk.gray(x.url)}${x.state ? ` (${x.state.toLowerCase()})` : ''}` : ''}`);\n return;\n }\n const r = addBlocker(id, ref);\n if (!r.ok) {\n console.error(chalk.red(r.error));\n process.exitCode = 1;\n return;\n }\n console.log(chalk.green(`${name} waits on ${ref.label}: out of the Inbox until it is done.`));\n },\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,OAAO,WAAW;AAaX,IAAM,eAA8B;AAAA,EACzC,SAAS;AAAA,EACT,UAAU;AAAA,EACV,SAAS,CAAC,UACR,mBAAmB,KAAK,EACrB,OAAO,MAAM,EAAE,MAAM,UAAU,UAAU,+CAA+C,CAAC,EACzF,OAAO,aAAa,EAAE,MAAM,UAAU,UAAU,wCAAwC,CAAC,EACzF,OAAO,MAAM,EAAE,MAAM,UAAU,UAAU,iCAAiC,CAAC,EAC3E,OAAO,OAAO,EAAE,MAAM,WAAW,UAAU,8DAA8D,CAAC;AAAA,EAC/G,SAAS,CAAC,SAAS;AACjB,UAAM,IAAI,gBAAgB,IAAI;AAC9B,QAAI,CAAC,EAAG;AACR,UAAM,KAAK,aAAa,CAAC;AACzB,UAAM,OAAO,GAAG,EAAE,MAAM,SAAM,EAAE,MAAM;AACtC,QAAI,MAAM;AACV,QAAI,OAAO,KAAK,OAAO,UAAU;AAC/B,YAAM,QAAQ,OAAO,KAAK,WAAW,MAAM,WAAW,YAAY,YAAY,GAAG,KAAK,IAAI,KAAK,WAAW,CAAC,IAAI;AAC/G,UAAI,CAAC,OAAO;AACV,gBAAQ,MAAM,MAAM,IAAI,mBAAmB,KAAK,EAAE,IAAI,KAAK,WAAW,KAAK,oBAAoB,GAAG,CAAC;AACnG,gBAAQ,WAAW;AACnB;AAAA,MACF;AACA,YAAM,aAAa,EAAE,MAAM,WAAW,IAAI,aAAa,KAAK,EAAE,CAAC;AAAA,IACjE,WAAW,OAAO,KAAK,OAAO,UAAU;AACtC,YAAM,aAAa,EAAE,MAAM,MAAM,KAAK,KAAK,GAAG,CAAC;AAC/C,UAAI,CAAC,KAAK;AACR,gBAAQ,MAAM,MAAM,IAAI,kCAAkC,KAAK,EAAE,EAAE,CAAC;AACpE,gBAAQ,WAAW;AACnB;AAAA,MACF;AAAA,IACF;AACA,QAAI,KAAK,KAAK;AACZ,oBAAc,IAAI,MAAM,SAAS,GAAG,IAAI,MAAS;AACjD,cAAQ,IAAI,MAAM,MAAM,MAAM,GAAG,IAAI,uBAAuB,IAAI,KAAK,MAAM,GAAG,IAAI,+BAA+B,CAAC;AAClH;AAAA,IACF;AACA,QAAI,CAAC,KAAK;AACR,YAAM,IAAI,UAAU,EAAE;AACtB,UAAI,CAAC,EAAG,SAAQ,IAAI,MAAM,KAAK,GAAG,IAAI,oBAAoB,CAAC;AAAA;AAEzD,mBAAW,KAAK,EAAE;AAChB,kBAAQ,IAAI,GAAG,EAAE,KAAK,GAAG,EAAE,SAAS,OAAO,KAAK,MAAM,KAAK,EAAE,GAAG,CAAC,GAAG,EAAE,QAAQ,KAAK,EAAE,MAAM,YAAY,CAAC,MAAM,EAAE,KAAK,EAAE,EAAE;AAC7H;AAAA,IACF;AACA,UAAM,IAAI,WAAW,IAAI,GAAG;AAC5B,QAAI,CAAC,EAAE,IAAI;AACT,cAAQ,MAAM,MAAM,IAAI,EAAE,KAAK,CAAC;AAChC,cAAQ,WAAW;AACnB;AAAA,IACF;AACA,YAAQ,IAAI,MAAM,MAAM,GAAG,IAAI,aAAa,IAAI,KAAK,sCAAsC,CAAC;AAAA,EAC9F;AACF;","names":[]}
@@ -0,0 +1,104 @@
1
+ #!/usr/bin/env node
2
+ import {
3
+ selectSessions
4
+ } from "./chunk-WMJIU3YW.js";
5
+ import {
6
+ getCommentFileStore
7
+ } from "./chunk-5QK7GB5K.js";
8
+ import "./chunk-HUXS3VAI.js";
9
+ import {
10
+ loadHistory
11
+ } from "./chunk-M4FVCAT6.js";
12
+ import {
13
+ sessionIdFor
14
+ } from "./chunk-7NCW3LUT.js";
15
+ import "./chunk-PN44M5EE.js";
16
+ import "./chunk-RCYI7SRA.js";
17
+ import "./chunk-DW4JPVXB.js";
18
+ import "./chunk-N4EYQKSM.js";
19
+ import "./chunk-7HEB6SQS.js";
20
+
21
+ // src/commands/broadcast.ts
22
+ import fs from "fs";
23
+ import chalk from "chalk";
24
+
25
+ // src/core/comments/broadcast.ts
26
+ async function broadcastPrompt(sessions, filter, prompt) {
27
+ const body = prompt.trim();
28
+ if (!body) throw new Error("broadcast prompt is empty");
29
+ const selected = selectSessions(sessions, filter);
30
+ const out = [];
31
+ for (const session of selected) {
32
+ const sessionId = sessionIdFor(session);
33
+ const c = getCommentFileStore(sessionId).post({ side: "general", status: "published", author: "user", body });
34
+ out.push({ session, sessionId, commentId: c.id });
35
+ }
36
+ return out;
37
+ }
38
+
39
+ // src/commands/broadcast.ts
40
+ function readStdin() {
41
+ try {
42
+ return fs.readFileSync(0, "utf-8");
43
+ } catch {
44
+ return "";
45
+ }
46
+ }
47
+ var broadcastCommand = {
48
+ command: "broadcast <prompt>",
49
+ describe: "Queue a prompt to every live session; delivered on each session's next turn",
50
+ builder: (yargs) => yargs.positional("prompt", {
51
+ describe: 'Prompt to send, or "-" to read from stdin',
52
+ type: "string"
53
+ }).option("target", {
54
+ describe: "Only sessions for this project/group alias",
55
+ type: "string"
56
+ }).option("branch", {
57
+ describe: "With --target, only this branch",
58
+ type: "string"
59
+ }).option("all", {
60
+ describe: "Required to broadcast to every session when no --target",
61
+ type: "boolean",
62
+ default: false
63
+ }),
64
+ handler: async (argv) => {
65
+ let prompt = argv.prompt ?? "";
66
+ if (prompt === "-") {
67
+ prompt = readStdin();
68
+ }
69
+ prompt = prompt.trim();
70
+ if (!prompt) {
71
+ console.error(chalk.red("Empty prompt. Usage: work broadcast <prompt>"));
72
+ process.exitCode = 1;
73
+ return;
74
+ }
75
+ const target = argv.target;
76
+ const branch = argv.branch;
77
+ const all = argv.all;
78
+ if (branch && !target) {
79
+ console.error(chalk.red("--branch requires --target."));
80
+ process.exitCode = 1;
81
+ return;
82
+ }
83
+ if (!target && !all) {
84
+ console.error(chalk.red("Refusing to broadcast to every session. Pass --all to confirm, or --target <alias> to narrow."));
85
+ process.exitCode = 1;
86
+ return;
87
+ }
88
+ const queued = await broadcastPrompt(loadHistory(), { target, branch }, prompt);
89
+ if (queued.length === 0) {
90
+ console.log(chalk.yellow("No matching sessions to broadcast to."));
91
+ return;
92
+ }
93
+ console.log(chalk.cyan(`Queued prompt to ${queued.length} session${queued.length === 1 ? "" : "s"}:`));
94
+ for (const t of queued) {
95
+ console.log(` ${chalk.cyan(`[${t.session.target}/${t.session.branch}]`)} ${chalk.gray(t.sessionId)}`);
96
+ }
97
+ console.log("");
98
+ console.log(chalk.gray("Delivery is lazy: each session picks this up on its next prompt (UserPromptSubmit hook)."));
99
+ }
100
+ };
101
+ export {
102
+ broadcastCommand
103
+ };
104
+ //# sourceMappingURL=broadcast-BSI5NDDB.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/commands/broadcast.ts","../src/core/comments/broadcast.ts"],"sourcesContent":["import fs from 'node:fs';\nimport chalk from 'chalk';\nimport type { CommandModule } from 'yargs';\nimport { loadHistory } from '../core/sessions/history.js';\nimport { broadcastPrompt } from '../core/comments/broadcast.js';\n\n/** Read the whole of stdin synchronously (for `broadcast -`). */\nfunction readStdin(): string {\n try {\n return fs.readFileSync(0, 'utf-8');\n } catch {\n return '';\n }\n}\n\nexport const broadcastCommand: CommandModule = {\n command: 'broadcast <prompt>',\n describe: \"Queue a prompt to every live session; delivered on each session's next turn\",\n builder: (yargs) =>\n yargs\n .positional('prompt', {\n describe: 'Prompt to send, or \"-\" to read from stdin',\n type: 'string',\n })\n .option('target', {\n describe: 'Only sessions for this project/group alias',\n type: 'string',\n })\n .option('branch', {\n describe: 'With --target, only this branch',\n type: 'string',\n })\n .option('all', {\n describe: 'Required to broadcast to every session when no --target',\n type: 'boolean',\n default: false,\n }),\n handler: async (argv) => {\n let prompt = (argv.prompt as string | undefined) ?? '';\n if (prompt === '-') {\n prompt = readStdin();\n }\n prompt = prompt.trim();\n if (!prompt) {\n console.error(chalk.red('Empty prompt. Usage: work broadcast <prompt>'));\n process.exitCode = 1;\n return;\n }\n\n const target = argv.target as string | undefined;\n const branch = argv.branch as string | undefined;\n const all = argv.all as boolean;\n if (branch && !target) {\n console.error(chalk.red('--branch requires --target.'));\n process.exitCode = 1;\n return;\n }\n // Guardrail: broadcasting to every session is a wide blast radius, so\n // require an explicit --all (or a narrowing --target) rather than letting\n // a bare `work broadcast \"...\"` fan out to the whole fleet by accident.\n if (!target && !all) {\n console.error(chalk.red('Refusing to broadcast to every session. Pass --all to confirm, or --target <alias> to narrow.'));\n process.exitCode = 1;\n return;\n }\n\n const queued = await broadcastPrompt(loadHistory(), { target, branch }, prompt);\n\n if (queued.length === 0) {\n console.log(chalk.yellow('No matching sessions to broadcast to.'));\n return;\n }\n\n console.log(chalk.cyan(`Queued prompt to ${queued.length} session${queued.length === 1 ? '' : 's'}:`));\n for (const t of queued) {\n console.log(` ${chalk.cyan(`[${t.session.target}/${t.session.branch}]`)} ${chalk.gray(t.sessionId)}`);\n }\n console.log('');\n console.log(chalk.gray('Delivery is lazy: each session picks this up on its next prompt (UserPromptSubmit hook).'));\n },\n};\n","/**\n * Core for `work broadcast`: queue a prompt to every (filtered) live session\n * via the existing pending-delivery mechanism. We do NOT touch PTYs — those\n * are per-process and unreachable from a separate CLI. Instead we post a\n * `published`, `author:'user'` comment to each session's comment file store;\n * `work hook prompt-submit` surfaces it on that session's next turn (see\n * pending-delivery.ts `readPendingForSession`, which selects exactly those).\n *\n * Broadcast writes from a SEPARATE process while `work web` may be writing\n * the same session's comments; the comment store's writes are database\n * transactions that reload first, so neither side's write is lost.\n */\n\nimport { getCommentFileStore } from './comment-file-store.js';\nimport { sessionIdFor } from '../sessions/session-id.js';\nimport { selectSessions, type FleetFilter } from '../sessions/fleet.js';\nimport type { WorktreeSession } from '../sessions/history.js';\n\nexport interface BroadcastTarget {\n session: WorktreeSession;\n sessionId: string;\n commentId: string;\n}\n\n/**\n * Post `prompt` as a published user comment (side 'general') to every session\n * matching `filter`. Returns one entry per session queued.\n */\nexport async function broadcastPrompt(sessions: WorktreeSession[], filter: FleetFilter, prompt: string): Promise<BroadcastTarget[]> {\n const body = prompt.trim();\n if (!body) throw new Error('broadcast prompt is empty');\n\n const selected = selectSessions(sessions, filter);\n const out: BroadcastTarget[] = [];\n for (const session of selected) {\n const sessionId = sessionIdFor(session);\n // The store's post is a transaction that reloads first, so a\n // concurrent work web write to the same session can't be lost.\n const c = getCommentFileStore(sessionId).post({ side: 'general', status: 'published', author: 'user', body });\n out.push({ session, sessionId, commentId: c.id });\n }\n return out;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;AAAA,OAAO,QAAQ;AACf,OAAO,WAAW;;;AC2BlB,eAAsB,gBAAgB,UAA6B,QAAqB,QAA4C;AAClI,QAAM,OAAO,OAAO,KAAK;AACzB,MAAI,CAAC,KAAM,OAAM,IAAI,MAAM,2BAA2B;AAEtD,QAAM,WAAW,eAAe,UAAU,MAAM;AAChD,QAAM,MAAyB,CAAC;AAChC,aAAW,WAAW,UAAU;AAC9B,UAAM,YAAY,aAAa,OAAO;AAGtC,UAAM,IAAI,oBAAoB,SAAS,EAAE,KAAK,EAAE,MAAM,WAAW,QAAQ,aAAa,QAAQ,QAAQ,KAAK,CAAC;AAC5G,QAAI,KAAK,EAAE,SAAS,WAAW,WAAW,EAAE,GAAG,CAAC;AAAA,EAClD;AACA,SAAO;AACT;;;ADnCA,SAAS,YAAoB;AAC3B,MAAI;AACF,WAAO,GAAG,aAAa,GAAG,OAAO;AAAA,EACnC,QAAQ;AACN,WAAO;AAAA,EACT;AACF;AAEO,IAAM,mBAAkC;AAAA,EAC7C,SAAS;AAAA,EACT,UAAU;AAAA,EACV,SAAS,CAAC,UACR,MACG,WAAW,UAAU;AAAA,IACpB,UAAU;AAAA,IACV,MAAM;AAAA,EACR,CAAC,EACA,OAAO,UAAU;AAAA,IAChB,UAAU;AAAA,IACV,MAAM;AAAA,EACR,CAAC,EACA,OAAO,UAAU;AAAA,IAChB,UAAU;AAAA,IACV,MAAM;AAAA,EACR,CAAC,EACA,OAAO,OAAO;AAAA,IACb,UAAU;AAAA,IACV,MAAM;AAAA,IACN,SAAS;AAAA,EACX,CAAC;AAAA,EACL,SAAS,OAAO,SAAS;AACvB,QAAI,SAAU,KAAK,UAAiC;AACpD,QAAI,WAAW,KAAK;AAClB,eAAS,UAAU;AAAA,IACrB;AACA,aAAS,OAAO,KAAK;AACrB,QAAI,CAAC,QAAQ;AACX,cAAQ,MAAM,MAAM,IAAI,8CAA8C,CAAC;AACvE,cAAQ,WAAW;AACnB;AAAA,IACF;AAEA,UAAM,SAAS,KAAK;AACpB,UAAM,SAAS,KAAK;AACpB,UAAM,MAAM,KAAK;AACjB,QAAI,UAAU,CAAC,QAAQ;AACrB,cAAQ,MAAM,MAAM,IAAI,6BAA6B,CAAC;AACtD,cAAQ,WAAW;AACnB;AAAA,IACF;AAIA,QAAI,CAAC,UAAU,CAAC,KAAK;AACnB,cAAQ,MAAM,MAAM,IAAI,+FAA+F,CAAC;AACxH,cAAQ,WAAW;AACnB;AAAA,IACF;AAEA,UAAM,SAAS,MAAM,gBAAgB,YAAY,GAAG,EAAE,QAAQ,OAAO,GAAG,MAAM;AAE9E,QAAI,OAAO,WAAW,GAAG;AACvB,cAAQ,IAAI,MAAM,OAAO,uCAAuC,CAAC;AACjE;AAAA,IACF;AAEA,YAAQ,IAAI,MAAM,KAAK,oBAAoB,OAAO,MAAM,WAAW,OAAO,WAAW,IAAI,KAAK,GAAG,GAAG,CAAC;AACrG,eAAW,KAAK,QAAQ;AACtB,cAAQ,IAAI,KAAK,MAAM,KAAK,IAAI,EAAE,QAAQ,MAAM,IAAI,EAAE,QAAQ,MAAM,GAAG,CAAC,IAAI,MAAM,KAAK,EAAE,SAAS,CAAC,EAAE;AAAA,IACvG;AACA,YAAQ,IAAI,EAAE;AACd,YAAQ,IAAI,MAAM,KAAK,0FAA0F,CAAC;AAAA,EACpH;AACF;","names":[]}
@@ -0,0 +1,51 @@
1
+ #!/usr/bin/env node
2
+ import {
3
+ askCatchUp,
4
+ catchUp,
5
+ catchUpFacts
6
+ } from "./chunk-77XFJQGC.js";
7
+ import "./chunk-FR3EWVXI.js";
8
+ import "./chunk-7OLPI334.js";
9
+ import {
10
+ sessionFromArgs,
11
+ sessionPositionals
12
+ } from "./chunk-HSICXDMZ.js";
13
+ import "./chunk-6AQRYLOB.js";
14
+ import "./chunk-WF5SBVPZ.js";
15
+ import "./chunk-ZSHWP2VS.js";
16
+ import "./chunk-5QK7GB5K.js";
17
+ import "./chunk-HUXS3VAI.js";
18
+ import "./chunk-7NAXFBFI.js";
19
+ import "./chunk-M4FVCAT6.js";
20
+ import {
21
+ sessionIdFor
22
+ } from "./chunk-7NCW3LUT.js";
23
+ import "./chunk-PN44M5EE.js";
24
+ import "./chunk-RCYI7SRA.js";
25
+ import "./chunk-DW4JPVXB.js";
26
+ import "./chunk-N4EYQKSM.js";
27
+ import "./chunk-7HEB6SQS.js";
28
+
29
+ // src/commands/catchup.ts
30
+ import chalk from "chalk";
31
+ var catchupCommand = {
32
+ command: "catchup [target] [branch]",
33
+ describe: "A few sentences on where a session stands: done, left, anything waiting on you (default: the session for this folder)",
34
+ builder: (yargs) => sessionPositionals(yargs),
35
+ handler: async (argv) => {
36
+ const s = sessionFromArgs(argv);
37
+ if (!s) return;
38
+ console.error(chalk.gray(`Reading the last week of ${s.target} \xB7 ${s.branch}\u2026`));
39
+ const r = await catchUp(s, askCatchUp, catchUpFacts(sessionIdFor(s)));
40
+ if (!r) {
41
+ console.error(chalk.yellow("Nothing to go on: no conversation in the last week, or no answer from Claude."));
42
+ process.exitCode = 1;
43
+ return;
44
+ }
45
+ console.log(r.text);
46
+ }
47
+ };
48
+ export {
49
+ catchupCommand
50
+ };
51
+ //# sourceMappingURL=catchup-VVOPL2S5.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/commands/catchup.ts"],"sourcesContent":["import chalk from 'chalk';\nimport type { CommandModule } from 'yargs';\nimport { askCatchUp, catchUpFacts } from '../core/conversations/catch-up-deps.js';\nimport { catchUp } from '../core/conversations/catch-up.js';\nimport { sessionIdFor } from '../core/sessions/session-id.js';\nimport { sessionFromArgs, sessionPositionals } from './shared/session-arg.js';\n\n/** `work catchup` — the dashboard's Catch me up (catch-up.ts): a few sentences on where a session stands. */\nexport const catchupCommand: CommandModule = {\n command: 'catchup [target] [branch]',\n describe: 'A few sentences on where a session stands: done, left, anything waiting on you (default: the session for this folder)',\n builder: (yargs) => sessionPositionals(yargs),\n handler: async (argv) => {\n const s = sessionFromArgs(argv);\n if (!s) return;\n console.error(chalk.gray(`Reading the last week of ${s.target} · ${s.branch}…`));\n const r = await catchUp(s, askCatchUp, catchUpFacts(sessionIdFor(s)));\n if (!r) {\n console.error(chalk.yellow('Nothing to go on: no conversation in the last week, or no answer from Claude.'));\n process.exitCode = 1;\n return;\n }\n console.log(r.text);\n },\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,OAAO,WAAW;AAQX,IAAM,iBAAgC;AAAA,EAC3C,SAAS;AAAA,EACT,UAAU;AAAA,EACV,SAAS,CAAC,UAAU,mBAAmB,KAAK;AAAA,EAC5C,SAAS,OAAO,SAAS;AACvB,UAAM,IAAI,gBAAgB,IAAI;AAC9B,QAAI,CAAC,EAAG;AACR,YAAQ,MAAM,MAAM,KAAK,4BAA4B,EAAE,MAAM,SAAM,EAAE,MAAM,QAAG,CAAC;AAC/E,UAAM,IAAI,MAAM,QAAQ,GAAG,YAAY,aAAa,aAAa,CAAC,CAAC,CAAC;AACpE,QAAI,CAAC,GAAG;AACN,cAAQ,MAAM,MAAM,OAAO,+EAA+E,CAAC;AAC3G,cAAQ,WAAW;AACnB;AAAA,IACF;AACA,YAAQ,IAAI,EAAE,IAAI;AAAA,EACpB;AACF;","names":[]}
@@ -0,0 +1,135 @@
1
+ #!/usr/bin/env node
2
+ import {
3
+ isPidAlive
4
+ } from "./chunk-PN44M5EE.js";
5
+
6
+ // src/core/platform/web-discovery.ts
7
+ import fs from "fs";
8
+ import os from "os";
9
+ import path from "path";
10
+ function webUrlPath() {
11
+ return path.join(os.homedir(), ".work", "web.url");
12
+ }
13
+ function webPidPath() {
14
+ return path.join(os.homedir(), ".work", "web.pid");
15
+ }
16
+ function readWebUrl() {
17
+ try {
18
+ return fs.readFileSync(webUrlPath(), "utf-8").trim() || null;
19
+ } catch {
20
+ return null;
21
+ }
22
+ }
23
+ function readWebPid() {
24
+ try {
25
+ const n = Number(fs.readFileSync(webPidPath(), "utf-8").trim());
26
+ return Number.isFinite(n) && n > 0 ? n : null;
27
+ } catch {
28
+ return null;
29
+ }
30
+ }
31
+ function writeWebDiscovery(url, pid) {
32
+ fs.mkdirSync(path.dirname(webUrlPath()), { recursive: true });
33
+ fs.writeFileSync(webUrlPath(), url);
34
+ fs.writeFileSync(webPidPath(), String(pid));
35
+ }
36
+ function clearWebDiscovery(ownerPid) {
37
+ if (ownerPid !== void 0) {
38
+ const current = readWebPid();
39
+ if (current !== null && current !== ownerPid) return;
40
+ }
41
+ try {
42
+ fs.unlinkSync(webPidPath());
43
+ } catch {
44
+ }
45
+ try {
46
+ fs.unlinkSync(webUrlPath());
47
+ } catch {
48
+ }
49
+ }
50
+ async function probeWeb(url, timeoutMs = 1500) {
51
+ try {
52
+ const res = await fetch(`${url}api/context`, { signal: AbortSignal.timeout(timeoutMs) });
53
+ if (!res.ok) return { kind: "gone" };
54
+ const body = await res.json().catch(() => ({}));
55
+ if (typeof body.mode !== "string") return { kind: "gone" };
56
+ return {
57
+ kind: "ours",
58
+ pid: typeof body.pid === "number" ? body.pid : null,
59
+ lean: body.lean === true,
60
+ build: typeof body.build === "string" ? body.build : null
61
+ };
62
+ } catch (err) {
63
+ const name = err.name;
64
+ return name === "TimeoutError" || name === "AbortError" ? { kind: "timeout" } : { kind: "gone" };
65
+ }
66
+ }
67
+ async function existingWebDecision(url, opts = {}) {
68
+ const probe = opts.probe ?? probeWeb;
69
+ const until = Date.now() + (opts.patienceMs ?? 6e3);
70
+ for (let first = true; ; first = false) {
71
+ const r = await probe(url, first ? 1500 : 3e3);
72
+ if (r.kind === "ours") return "reuse";
73
+ if (r.kind === "gone") return "start";
74
+ if (Date.now() >= until) return "reuse";
75
+ }
76
+ }
77
+ async function discoveryCheck(self, deps = {}) {
78
+ const pid = (deps.readPid ?? readWebPid)();
79
+ if (pid === self.pid) return "keep";
80
+ const alive = deps.alive ?? isPidAlive;
81
+ if (pid === null || !alive(pid)) return "reclaim";
82
+ const url = (deps.readUrl ?? readWebUrl)();
83
+ if (!url || url === self.url) return "keep";
84
+ const r = await (deps.probe ?? probeWeb)(url, 3e3);
85
+ return r.kind === "ours" && r.pid === pid ? "retire" : "keep";
86
+ }
87
+ async function webServerResponds(url, timeoutMs = 1500) {
88
+ try {
89
+ const res = await fetch(`${url}api/context`, { signal: AbortSignal.timeout(timeoutMs) });
90
+ return res.ok;
91
+ } catch {
92
+ return false;
93
+ }
94
+ }
95
+ async function askWorkWeb(route, timeoutMs = 3e3) {
96
+ const url = readWebUrl();
97
+ if (!url) return null;
98
+ try {
99
+ const res = await fetch(`${url}${route.replace(/^\//, "")}`, { signal: AbortSignal.timeout(timeoutMs) });
100
+ return res.ok ? await res.json() : null;
101
+ } catch {
102
+ return null;
103
+ }
104
+ }
105
+ async function callWorkWeb(method, route, body, timeoutMs = 15e3) {
106
+ const url = readWebUrl();
107
+ if (!url) return { ok: false, status: 0, error: "work web is not running (start it with `work web`, or open the desktop app)" };
108
+ try {
109
+ const res = await fetch(`${url}${route.replace(/^\//, "")}`, {
110
+ method,
111
+ signal: AbortSignal.timeout(timeoutMs),
112
+ ...body !== void 0 ? { headers: { "Content-Type": "application/json" }, body: JSON.stringify(body) } : {}
113
+ });
114
+ const json = await res.json().catch(() => null);
115
+ if (res.ok && json) return { ok: true, body: json };
116
+ return { ok: false, status: res.status, error: typeof json?.error === "string" ? json.error : `work web answered ${res.status}` };
117
+ } catch (err) {
118
+ return { ok: false, status: 0, error: `work web did not answer (${err.message})` };
119
+ }
120
+ }
121
+
122
+ export {
123
+ webUrlPath,
124
+ readWebUrl,
125
+ readWebPid,
126
+ writeWebDiscovery,
127
+ clearWebDiscovery,
128
+ probeWeb,
129
+ existingWebDecision,
130
+ discoveryCheck,
131
+ webServerResponds,
132
+ askWorkWeb,
133
+ callWorkWeb
134
+ };
135
+ //# sourceMappingURL=chunk-3JWTO5VZ.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/core/platform/web-discovery.ts"],"sourcesContent":["import fs from 'node:fs';\nimport os from 'node:os';\nimport path from 'node:path';\nimport { isPidAlive } from './process.js';\n\n/**\n * How everything finds the running `work web` (the singleton): the\n * `web.url` + `web.pid` files it writes in ~/.work. One module instead of\n * copies in the web command, `wd`, and the Claude hook bridge.\n *\n * The files outlive the process (crash, kill, reboot) and Windows reuses\n * PIDs, so neither file is proof of anything: `probeWeb` asks the server\n * itself, and it answers /api/context with its own pid.\n */\n\n// os.homedir() per call (not getConfigDir, which creates the dir): tests\n// mock homedir, and readers must not create ~/.work as a side effect.\nexport function webUrlPath(): string {\n return path.join(os.homedir(), '.work', 'web.url');\n}\nexport function webPidPath(): string {\n return path.join(os.homedir(), '.work', 'web.pid');\n}\n\nexport function readWebUrl(): string | null {\n try {\n return fs.readFileSync(webUrlPath(), 'utf-8').trim() || null;\n } catch {\n return null;\n }\n}\n\nexport function readWebPid(): number | null {\n try {\n const n = Number(fs.readFileSync(webPidPath(), 'utf-8').trim());\n return Number.isFinite(n) && n > 0 ? n : null;\n } catch {\n return null;\n }\n}\n\nexport function writeWebDiscovery(url: string, pid: number): void {\n fs.mkdirSync(path.dirname(webUrlPath()), { recursive: true });\n fs.writeFileSync(webUrlPath(), url);\n fs.writeFileSync(webPidPath(), String(pid));\n}\n\n/**\n * Remove the discovery files. With `ownerPid`, only if they still name that\n * server: a new one (the desktop app restarts it at once) may have written\n * its own in the meantime, and deleting those hides it from every client —\n * `wd`, the CLI, the Claude hooks.\n */\nexport function clearWebDiscovery(ownerPid?: number): void {\n if (ownerPid !== undefined) {\n const current = readWebPid();\n if (current !== null && current !== ownerPid) return;\n }\n try {\n fs.unlinkSync(webPidPath());\n } catch {\n /* already gone */\n }\n try {\n fs.unlinkSync(webUrlPath());\n } catch {\n /* already gone */\n }\n}\n\nexport type WebProbe =\n | { kind: 'ours'; pid: number | null; lean: boolean; /** null: a build before stamps. */ build: string | null }\n /** Nothing listens there (or something that isn't work web answered). */\n | { kind: 'gone' }\n /** No answer in time — possibly just busy; never proof it's gone. */\n | { kind: 'timeout' };\n\nexport async function probeWeb(url: string, timeoutMs = 1500): Promise<WebProbe> {\n try {\n const res = await fetch(`${url}api/context`, { signal: AbortSignal.timeout(timeoutMs) });\n if (!res.ok) return { kind: 'gone' };\n const body = (await res.json().catch(() => ({}))) as { mode?: unknown; pid?: unknown; lean?: unknown; build?: unknown };\n if (typeof body.mode !== 'string') return { kind: 'gone' };\n return {\n kind: 'ours',\n pid: typeof body.pid === 'number' ? body.pid : null,\n lean: body.lean === true,\n build: typeof body.build === 'string' ? body.build : null,\n };\n } catch (err) {\n const name = (err as { name?: string }).name;\n return name === 'TimeoutError' || name === 'AbortError' ? { kind: 'timeout' } : { kind: 'gone' };\n }\n}\n\n/**\n * What to do with the recorded work web before starting one:\n * - 'reuse' it answered as work web — or it is BUSY (timed out, possibly\n * more than once): a slow server is still the running one, and\n * replacing it orphans it (the new one sees the live pid and\n * exits; the old one keeps the port and hooks but can no longer\n * be found once web.url is gone).\n * - 'start' nothing is there any more (the url file is stale).\n * Busy servers get `patienceMs` of re-probing before being reused anyway.\n */\nexport async function existingWebDecision(\n url: string,\n opts: { patienceMs?: number; probe?: typeof probeWeb } = {},\n): Promise<'reuse' | 'start'> {\n const probe = opts.probe ?? probeWeb;\n const until = Date.now() + (opts.patienceMs ?? 6000);\n for (let first = true; ; first = false) {\n const r = await probe(url, first ? 1500 : 3000);\n if (r.kind === 'ours') return 'reuse';\n if (r.kind === 'gone') return 'start';\n if (Date.now() >= until) return 'reuse';\n }\n}\n\n/**\n * A running work web checks, now and then, that it is still THE one:\n * - 'keep' web.pid names us.\n * - 'retire' web.pid names another work web that answers as itself: two\n * were started at once (a restart racing the desktop app's\n * watchdog, which starts one when none answers) and the other\n * won the discovery files. Ours can no longer be found, but it\n * kept its PR watch and gh calls going — twice the GitHub API\n * use — and the desktop app stayed on it, an old build.\n * - 'reclaim' nothing recorded (or a dead pid): write ours back, so `wd`,\n * the app and `work web --stop` find the one that runs.\n * A busy or silent other is never reason to retire (see existingWebDecision).\n */\nexport async function discoveryCheck(\n self: { pid: number; url: string },\n deps: { readPid?: () => number | null; readUrl?: () => string | null; alive?: (pid: number) => boolean; probe?: typeof probeWeb } = {},\n): Promise<'keep' | 'retire' | 'reclaim'> {\n const pid = (deps.readPid ?? readWebPid)();\n if (pid === self.pid) return 'keep';\n const alive = deps.alive ?? isPidAlive;\n if (pid === null || !alive(pid)) return 'reclaim';\n const url = (deps.readUrl ?? readWebUrl)();\n if (!url || url === self.url) return 'keep';\n const r = await (deps.probe ?? probeWeb)(url, 3000);\n return r.kind === 'ours' && r.pid === pid ? 'retire' : 'keep';\n}\n\n/**\n * Liveness only: is a server serving the recorded URL (any 2xx at\n * api/context)? Enough for \"reuse it / autostart one\". Identity — is it\n * work web, with the recorded pid — is probeWeb's job, and only matters\n * before killing something.\n */\nexport async function webServerResponds(url: string, timeoutMs = 1500): Promise<boolean> {\n try {\n const res = await fetch(`${url}api/context`, { signal: AbortSignal.timeout(timeoutMs) });\n return res.ok;\n } catch {\n return false;\n }\n}\n\n/**\n * GET a JSON route from the running work web, for what only it holds (the\n * PR watch's cache, which PTYs are live). Null when none runs or it doesn't\n * answer in time: callers go without that part rather than fail.\n */\nexport async function askWorkWeb<T>(route: string, timeoutMs = 3000): Promise<T | null> {\n const url = readWebUrl();\n if (!url) return null;\n try {\n const res = await fetch(`${url}${route.replace(/^\\//, '')}`, { signal: AbortSignal.timeout(timeoutMs) });\n return res.ok ? ((await res.json()) as T) : null;\n } catch {\n return null;\n }\n}\n\nexport type WorkWebAnswer<T> =\n { ok: true; body: T } | { ok: false; status: number; error: string } | { ok: false; status: 0; error: string };\n\n/**\n * Call a route of the running work web (what only it can do: type into a\n * terminal it owns, start a Claude in the PTY host). Unlike askWorkWeb, a\n * refusal comes back with its reason, and \"no work web\" is its own answer\n * (status 0), so the caller can say how to start one.\n */\nexport async function callWorkWeb<T>(method: 'GET' | 'POST', route: string, body?: unknown, timeoutMs = 15_000): Promise<WorkWebAnswer<T>> {\n const url = readWebUrl();\n if (!url) return { ok: false, status: 0, error: 'work web is not running (start it with `work web`, or open the desktop app)' };\n try {\n const res = await fetch(`${url}${route.replace(/^\\//, '')}`, {\n method,\n signal: AbortSignal.timeout(timeoutMs),\n ...(body !== undefined ? { headers: { 'Content-Type': 'application/json' }, body: JSON.stringify(body) } : {}),\n });\n const json = (await res.json().catch(() => null)) as (T & { error?: unknown }) | null;\n if (res.ok && json) return { ok: true, body: json };\n return { ok: false, status: res.status, error: typeof json?.error === 'string' ? json.error : `work web answered ${res.status}` };\n } catch (err) {\n return { ok: false, status: 0, error: `work web did not answer (${(err as Error).message})` };\n }\n}\n"],"mappings":"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","names":[]}
@@ -0,0 +1,210 @@
1
+ #!/usr/bin/env node
2
+ import {
3
+ defaultRunner
4
+ } from "./chunk-ZXPYWZL5.js";
5
+ import {
6
+ logSwallowed
7
+ } from "./chunk-M4FVCAT6.js";
8
+
9
+ // src/core/diff/diff-stat.ts
10
+ import fs from "fs";
11
+ import path from "path";
12
+ function parseNumstat(out) {
13
+ let added = 0;
14
+ let deleted = 0;
15
+ let files = 0;
16
+ for (const line of out.split("\n")) {
17
+ const m = line.match(/^(\d+|-)\t(\d+|-)\t/);
18
+ if (!m) continue;
19
+ files++;
20
+ if (m[1] !== "-") added += Number(m[1]);
21
+ if (m[2] !== "-") deleted += Number(m[2]);
22
+ }
23
+ return { added, deleted, files };
24
+ }
25
+ var lines = (out) => out.split("\n").map((l) => l.trim()).filter(Boolean);
26
+ var MAIN_BRANCHES = ["origin/HEAD", "origin/main", "origin/master", "main", "master"];
27
+ var commonDirs = /* @__PURE__ */ new Map();
28
+ async function repoKeyFor(p, run) {
29
+ const known = commonDirs.get(p);
30
+ if (known) return known;
31
+ const r = await run("git", ["rev-parse", "--path-format=absolute", "--git-common-dir"], p);
32
+ if (r.code !== 0 || !r.stdout.trim()) return null;
33
+ let key = path.resolve(r.stdout.trim());
34
+ if (process.platform === "win32") key = key.toLowerCase();
35
+ commonDirs.set(p, key);
36
+ return key;
37
+ }
38
+ async function computeChanges(paths, names, run = defaultRunner) {
39
+ let total = { added: 0, deleted: 0, files: 0 };
40
+ let any = false;
41
+ const touched = [];
42
+ for (const [i, p] of paths.entries()) {
43
+ if (!fs.existsSync(p)) continue;
44
+ const numstat = await run("git", ["diff", "HEAD", "--numstat"], p);
45
+ if (numstat.code !== 0) continue;
46
+ any = true;
47
+ const t = parseNumstat(numstat.stdout);
48
+ const untracked = await run("git", ["ls-files", "--others", "--exclude-standard"], p);
49
+ const newFiles = untracked.code === 0 ? lines(untracked.stdout) : [];
50
+ total = { added: total.added + t.added, deleted: total.deleted + t.deleted, files: total.files + t.files + newFiles.length };
51
+ const repoKey = await repoKeyFor(p, run);
52
+ if (!repoKey) continue;
53
+ let since = "HEAD";
54
+ for (const base of MAIN_BRANCHES) {
55
+ const mb = await run("git", ["merge-base", "HEAD", base], p);
56
+ if (mb.code === 0 && /^[0-9a-f]{7,64}$/.test(mb.stdout.trim())) {
57
+ since = mb.stdout.trim();
58
+ break;
59
+ }
60
+ }
61
+ const changed = await run("git", ["diff", "--name-only", since], p);
62
+ const files = /* @__PURE__ */ new Set([...changed.code === 0 ? lines(changed.stdout) : [], ...newFiles]);
63
+ if (files.size) touched.push({ repoKey, name: names[i] ?? path.basename(p), files: [...files].sort() });
64
+ }
65
+ return { stat: any ? total : null, touched };
66
+ }
67
+ var DiffStatCache = class {
68
+ constructor(opts = {}) {
69
+ this.opts = opts;
70
+ this.ttlMs = opts.ttlMs ?? 2e4;
71
+ this.concurrency = opts.concurrency ?? 4;
72
+ this.run = opts.run ?? defaultRunner;
73
+ this.now = opts.now ?? Date.now;
74
+ }
75
+ entries = /* @__PURE__ */ new Map();
76
+ queue = [];
77
+ running = 0;
78
+ ttlMs;
79
+ concurrency;
80
+ run;
81
+ now;
82
+ /** Last known value (possibly stale or null); schedules a refresh when
83
+ * it's missing or older than the TTL. Never blocks. */
84
+ get(id, paths, names = []) {
85
+ const e = this.entries.get(id);
86
+ if (!e || !e.inFlight && this.now() - e.at > this.ttlMs) this.schedule(id, paths, names);
87
+ return e?.stat ?? null;
88
+ }
89
+ /** Last known value, without scheduling a refresh (reads that must not
90
+ * start work, like the digest). */
91
+ peek(id) {
92
+ return this.entries.get(id)?.stat ?? null;
93
+ }
94
+ /** Last known files per repo (for overlaps); [] until computed. Call
95
+ * after get(), which keeps it fresh. */
96
+ touched(id) {
97
+ return this.entries.get(id)?.touched ?? [];
98
+ }
99
+ /** Force a refresh soon (a file changed in that worktree). */
100
+ invalidate(id) {
101
+ const e = this.entries.get(id);
102
+ if (e) {
103
+ e.at = 0;
104
+ e.gen++;
105
+ }
106
+ }
107
+ /** Resolves when the queue is drained — for tests. */
108
+ async idle() {
109
+ while (this.running > 0 || this.queue.length > 0) {
110
+ await new Promise((r) => setTimeout(r, 5));
111
+ }
112
+ }
113
+ schedule(id, paths, names) {
114
+ const e = this.entries.get(id) ?? { stat: null, touched: [], at: 0, inFlight: false, gen: 0 };
115
+ if (e.inFlight) return;
116
+ e.inFlight = true;
117
+ this.entries.set(id, e);
118
+ this.queue.push({ id, paths, names, gen: e.gen });
119
+ this.pump();
120
+ }
121
+ pump() {
122
+ while (this.running < this.concurrency && this.queue.length > 0) {
123
+ const job = this.queue.shift();
124
+ this.running++;
125
+ void computeChanges(job.paths, job.names, this.run).catch((err) => {
126
+ logSwallowed(`diff stat for ${job.id}`, err);
127
+ return { stat: null, touched: [] };
128
+ }).then(({ stat, touched }) => {
129
+ const e = this.entries.get(job.id);
130
+ const changed = JSON.stringify(e.stat) !== JSON.stringify(stat) || JSON.stringify(e.touched) !== JSON.stringify(touched);
131
+ e.stat = stat;
132
+ e.touched = touched;
133
+ e.at = e.gen === job.gen ? this.now() : 0;
134
+ e.inFlight = false;
135
+ if (changed) this.opts.onChange?.();
136
+ }).finally(() => {
137
+ this.running--;
138
+ this.pump();
139
+ });
140
+ }
141
+ }
142
+ };
143
+ function wantsDiffStat(s, hasStatus, now = Date.now()) {
144
+ if (s.archivedAt) return false;
145
+ if (hasStatus) return true;
146
+ const last = Date.parse(s.lastAccessedAt) || 0;
147
+ return now - last < 14 * 24 * 60 * 6e4;
148
+ }
149
+
150
+ // src/core/diff/overlap.ts
151
+ var MAX_OVERLAP_FILES = 20;
152
+ function findOverlaps(sessions) {
153
+ const index = /* @__PURE__ */ new Map();
154
+ sessions.forEach((s, i) => {
155
+ for (const r of s.touched) {
156
+ let files = index.get(r.repoKey);
157
+ if (!files) index.set(r.repoKey, files = /* @__PURE__ */ new Map());
158
+ for (const f of r.files) {
159
+ let who = files.get(f);
160
+ if (!who) files.set(f, who = /* @__PURE__ */ new Set());
161
+ who.add(i);
162
+ }
163
+ }
164
+ });
165
+ const shared = /* @__PURE__ */ new Map();
166
+ for (const [repoKey, files] of index) {
167
+ for (const [file, who] of files) {
168
+ if (who.size < 2) continue;
169
+ const ids = [...who].sort((a, b) => a - b);
170
+ for (let a = 0; a < ids.length; a++) {
171
+ for (let b = a + 1; b < ids.length; b++) {
172
+ const key = `${ids[a]}:${ids[b]}`;
173
+ const name = sessions[ids[a]].touched.find((r) => r.repoKey === repoKey)?.name ?? "";
174
+ let list = shared.get(key);
175
+ if (!list) shared.set(key, list = []);
176
+ list.push({ repo: name, path: file });
177
+ }
178
+ }
179
+ }
180
+ }
181
+ const out = /* @__PURE__ */ new Map();
182
+ const add = (self, other, files) => {
183
+ const o = sessions[other];
184
+ const list = out.get(sessions[self].id) ?? [];
185
+ list.push({
186
+ sessionId: o.id,
187
+ target: o.target,
188
+ branch: o.branch,
189
+ count: files.length,
190
+ files: files.slice(0, MAX_OVERLAP_FILES)
191
+ });
192
+ out.set(sessions[self].id, list);
193
+ };
194
+ for (const [key, files] of shared) {
195
+ const [a, b] = key.split(":").map(Number);
196
+ files.sort((x, y) => x.repo.localeCompare(y.repo) || x.path.localeCompare(y.path));
197
+ add(a, b, files);
198
+ add(b, a, files);
199
+ }
200
+ for (const list of out.values()) list.sort((x, y) => y.count - x.count || x.branch.localeCompare(y.branch));
201
+ return out;
202
+ }
203
+
204
+ export {
205
+ computeChanges,
206
+ DiffStatCache,
207
+ wantsDiffStat,
208
+ findOverlaps
209
+ };
210
+ //# sourceMappingURL=chunk-4BOK2GXL.js.map