@ruverd/julius 0.0.0-stage → 0.24.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 (704) hide show
  1. package/CHANGELOG.md +47 -0
  2. package/CREDITS.md +25 -0
  3. package/LICENSE +21 -0
  4. package/PROVENANCE.md +9 -0
  5. package/README.md +229 -2
  6. package/dist/ai/crux.d.ts +60 -0
  7. package/dist/ai/crux.d.ts.map +1 -0
  8. package/dist/ai/crux.js +141 -0
  9. package/dist/ai/crux.js.map +1 -0
  10. package/dist/ai/failure.d.ts +60 -0
  11. package/dist/ai/failure.d.ts.map +1 -0
  12. package/dist/ai/failure.js +86 -0
  13. package/dist/ai/failure.js.map +1 -0
  14. package/dist/ai/llm/anthropic.d.ts +37 -0
  15. package/dist/ai/llm/anthropic.d.ts.map +1 -0
  16. package/dist/ai/llm/anthropic.js +144 -0
  17. package/dist/ai/llm/anthropic.js.map +1 -0
  18. package/dist/ai/llm/factory.d.ts +28 -0
  19. package/dist/ai/llm/factory.d.ts.map +1 -0
  20. package/dist/ai/llm/factory.js +36 -0
  21. package/dist/ai/llm/factory.js.map +1 -0
  22. package/dist/ai/llm/litellm.d.ts +34 -0
  23. package/dist/ai/llm/litellm.d.ts.map +1 -0
  24. package/dist/ai/llm/litellm.js +45 -0
  25. package/dist/ai/llm/litellm.js.map +1 -0
  26. package/dist/ai/llm/openai.d.ts +44 -0
  27. package/dist/ai/llm/openai.d.ts.map +1 -0
  28. package/dist/ai/llm/openai.js +239 -0
  29. package/dist/ai/llm/openai.js.map +1 -0
  30. package/dist/ai/llm/orcarouter.d.ts +34 -0
  31. package/dist/ai/llm/orcarouter.d.ts.map +1 -0
  32. package/dist/ai/llm/orcarouter.js +45 -0
  33. package/dist/ai/llm/orcarouter.js.map +1 -0
  34. package/dist/ai/llm/recover-tool.d.ts +19 -0
  35. package/dist/ai/llm/recover-tool.d.ts.map +1 -0
  36. package/dist/ai/llm/recover-tool.js +109 -0
  37. package/dist/ai/llm/recover-tool.js.map +1 -0
  38. package/dist/ai/llm/types.d.ts +122 -0
  39. package/dist/ai/llm/types.d.ts.map +1 -0
  40. package/dist/ai/llm/types.js +33 -0
  41. package/dist/ai/llm/types.js.map +1 -0
  42. package/dist/ai/providers.d.ts +59 -0
  43. package/dist/ai/providers.d.ts.map +1 -0
  44. package/dist/ai/providers.js +54 -0
  45. package/dist/ai/providers.js.map +1 -0
  46. package/dist/ai/summarize.d.ts +25 -0
  47. package/dist/ai/summarize.d.ts.map +1 -0
  48. package/dist/ai/summarize.js +34 -0
  49. package/dist/ai/summarize.js.map +1 -0
  50. package/dist/ai/synthesize.d.ts +40 -0
  51. package/dist/ai/synthesize.d.ts.map +1 -0
  52. package/dist/ai/synthesize.js +131 -0
  53. package/dist/ai/synthesize.js.map +1 -0
  54. package/dist/app/checkout.d.ts +46 -0
  55. package/dist/app/checkout.d.ts.map +1 -0
  56. package/dist/app/checkout.js +223 -0
  57. package/dist/app/checkout.js.map +1 -0
  58. package/dist/app/events.d.ts +44 -0
  59. package/dist/app/events.d.ts.map +1 -0
  60. package/dist/app/events.js +64 -0
  61. package/dist/app/events.js.map +1 -0
  62. package/dist/app/identity.d.ts +54 -0
  63. package/dist/app/identity.d.ts.map +1 -0
  64. package/dist/app/identity.js +96 -0
  65. package/dist/app/identity.js.map +1 -0
  66. package/dist/app/main.d.ts +2 -0
  67. package/dist/app/main.d.ts.map +1 -0
  68. package/dist/app/main.js +62 -0
  69. package/dist/app/main.js.map +1 -0
  70. package/dist/app/pages.d.ts +56 -0
  71. package/dist/app/pages.d.ts.map +1 -0
  72. package/dist/app/pages.js +193 -0
  73. package/dist/app/pages.js.map +1 -0
  74. package/dist/app/queue.d.ts +40 -0
  75. package/dist/app/queue.d.ts.map +1 -0
  76. package/dist/app/queue.js +68 -0
  77. package/dist/app/queue.js.map +1 -0
  78. package/dist/app/review-process.d.ts +66 -0
  79. package/dist/app/review-process.d.ts.map +1 -0
  80. package/dist/app/review-process.js +200 -0
  81. package/dist/app/review-process.js.map +1 -0
  82. package/dist/app/review-worker.d.ts +2 -0
  83. package/dist/app/review-worker.d.ts.map +1 -0
  84. package/dist/app/review-worker.js +108 -0
  85. package/dist/app/review-worker.js.map +1 -0
  86. package/dist/app/review.d.ts +23 -0
  87. package/dist/app/review.d.ts.map +1 -0
  88. package/dist/app/review.js +142 -0
  89. package/dist/app/review.js.map +1 -0
  90. package/dist/app/server.d.ts +49 -0
  91. package/dist/app/server.d.ts.map +1 -0
  92. package/dist/app/server.js +123 -0
  93. package/dist/app/server.js.map +1 -0
  94. package/dist/ask/ask.d.ts +195 -0
  95. package/dist/ask/ask.d.ts.map +1 -0
  96. package/dist/ask/ask.js +1252 -0
  97. package/dist/ask/ask.js.map +1 -0
  98. package/dist/ask/file-rank.d.ts +72 -0
  99. package/dist/ask/file-rank.d.ts.map +1 -0
  100. package/dist/ask/file-rank.js +160 -0
  101. package/dist/ask/file-rank.js.map +1 -0
  102. package/dist/ask/file-selection.d.ts +22 -0
  103. package/dist/ask/file-selection.d.ts.map +1 -0
  104. package/dist/ask/file-selection.js +66 -0
  105. package/dist/ask/file-selection.js.map +1 -0
  106. package/dist/ask/fuse.d.ts +195 -0
  107. package/dist/ask/fuse.d.ts.map +1 -0
  108. package/dist/ask/fuse.js +344 -0
  109. package/dist/ask/fuse.js.map +1 -0
  110. package/dist/ask/graphrank.d.ts +61 -0
  111. package/dist/ask/graphrank.d.ts.map +1 -0
  112. package/dist/ask/graphrank.js +130 -0
  113. package/dist/ask/graphrank.js.map +1 -0
  114. package/dist/ask/index-file.d.ts +44 -0
  115. package/dist/ask/index-file.d.ts.map +1 -0
  116. package/dist/ask/index-file.js +128 -0
  117. package/dist/ask/index-file.js.map +1 -0
  118. package/dist/bin/julius.d.ts +3 -0
  119. package/dist/bin/julius.d.ts.map +1 -0
  120. package/dist/bin/julius.js +4 -0
  121. package/dist/bin/julius.js.map +1 -0
  122. package/dist/blast/blast-cli.d.ts +35 -0
  123. package/dist/blast/blast-cli.d.ts.map +1 -0
  124. package/dist/blast/blast-cli.js +155 -0
  125. package/dist/blast/blast-cli.js.map +1 -0
  126. package/dist/blast/blast.d.ts +128 -0
  127. package/dist/blast/blast.d.ts.map +1 -0
  128. package/dist/blast/blast.js +383 -0
  129. package/dist/blast/blast.js.map +1 -0
  130. package/dist/blast/diff.d.ts +53 -0
  131. package/dist/blast/diff.d.ts.map +1 -0
  132. package/dist/blast/diff.js +193 -0
  133. package/dist/blast/diff.js.map +1 -0
  134. package/dist/blast/evidence.d.ts +51 -0
  135. package/dist/blast/evidence.d.ts.map +1 -0
  136. package/dist/blast/evidence.js +162 -0
  137. package/dist/blast/evidence.js.map +1 -0
  138. package/dist/blast/modules.d.ts +33 -0
  139. package/dist/blast/modules.d.ts.map +1 -0
  140. package/dist/blast/modules.js +83 -0
  141. package/dist/blast/modules.js.map +1 -0
  142. package/dist/blast/name.d.ts +74 -0
  143. package/dist/blast/name.d.ts.map +1 -0
  144. package/dist/blast/name.js +269 -0
  145. package/dist/blast/name.js.map +1 -0
  146. package/dist/blast/owners.d.ts +85 -0
  147. package/dist/blast/owners.d.ts.map +1 -0
  148. package/dist/blast/owners.js +272 -0
  149. package/dist/blast/owners.js.map +1 -0
  150. package/dist/blast/render.d.ts +46 -0
  151. package/dist/blast/render.d.ts.map +1 -0
  152. package/dist/blast/render.js +422 -0
  153. package/dist/blast/render.js.map +1 -0
  154. package/dist/blast/viz.d.ts +37 -0
  155. package/dist/blast/viz.d.ts.map +1 -0
  156. package/dist/blast/viz.js +180 -0
  157. package/dist/blast/viz.js.map +1 -0
  158. package/dist/brand.d.ts +13 -0
  159. package/dist/brand.d.ts.map +1 -0
  160. package/dist/brand.js +43 -0
  161. package/dist/brand.js.map +1 -0
  162. package/dist/check/learning-edits.d.ts +9 -0
  163. package/dist/check/learning-edits.d.ts.map +1 -0
  164. package/dist/check/learning-edits.js +62 -0
  165. package/dist/check/learning-edits.js.map +1 -0
  166. package/dist/check/local-check.d.ts +104 -0
  167. package/dist/check/local-check.d.ts.map +1 -0
  168. package/dist/check/local-check.js +830 -0
  169. package/dist/check/local-check.js.map +1 -0
  170. package/dist/check/types.d.ts +31 -0
  171. package/dist/check/types.d.ts.map +1 -0
  172. package/dist/check/types.js +2 -0
  173. package/dist/check/types.js.map +1 -0
  174. package/dist/claude/build-progress.d.ts +29 -0
  175. package/dist/claude/build-progress.d.ts.map +1 -0
  176. package/dist/claude/build-progress.js +76 -0
  177. package/dist/claude/build-progress.js.map +1 -0
  178. package/dist/claude/format.d.ts +131 -0
  179. package/dist/claude/format.d.ts.map +1 -0
  180. package/dist/claude/format.js +328 -0
  181. package/dist/claude/format.js.map +1 -0
  182. package/dist/claude/hook-layers.d.ts +8 -0
  183. package/dist/claude/hook-layers.d.ts.map +1 -0
  184. package/dist/claude/hook-layers.js +74 -0
  185. package/dist/claude/hook-layers.js.map +1 -0
  186. package/dist/claude/hooks.d.ts +101 -0
  187. package/dist/claude/hooks.d.ts.map +1 -0
  188. package/dist/claude/hooks.js +849 -0
  189. package/dist/claude/hooks.js.map +1 -0
  190. package/dist/claude/init.d.ts +70 -0
  191. package/dist/claude/init.d.ts.map +1 -0
  192. package/dist/claude/init.js +207 -0
  193. package/dist/claude/init.js.map +1 -0
  194. package/dist/claude/note-signals.d.ts +28 -0
  195. package/dist/claude/note-signals.d.ts.map +1 -0
  196. package/dist/claude/note-signals.js +325 -0
  197. package/dist/claude/note-signals.js.map +1 -0
  198. package/dist/claude/paths.d.ts +9 -0
  199. package/dist/claude/paths.d.ts.map +1 -0
  200. package/dist/claude/paths.js +22 -0
  201. package/dist/claude/paths.js.map +1 -0
  202. package/dist/claude/session-metrics.d.ts +73 -0
  203. package/dist/claude/session-metrics.d.ts.map +1 -0
  204. package/dist/claude/session-metrics.js +209 -0
  205. package/dist/claude/session-metrics.js.map +1 -0
  206. package/dist/claude/settings-merge.d.ts +66 -0
  207. package/dist/claude/settings-merge.d.ts.map +1 -0
  208. package/dist/claude/settings-merge.js +249 -0
  209. package/dist/claude/settings-merge.js.map +1 -0
  210. package/dist/claude/shim-template.d.ts +18 -0
  211. package/dist/claude/shim-template.d.ts.map +1 -0
  212. package/dist/claude/shim-template.js +226 -0
  213. package/dist/claude/shim-template.js.map +1 -0
  214. package/dist/claude/skill-template.d.ts +12 -0
  215. package/dist/claude/skill-template.d.ts.map +1 -0
  216. package/dist/claude/skill-template.js +294 -0
  217. package/dist/claude/skill-template.js.map +1 -0
  218. package/dist/claude/state.d.ts +73 -0
  219. package/dist/claude/state.d.ts.map +1 -0
  220. package/dist/claude/state.js +33 -0
  221. package/dist/claude/state.js.map +1 -0
  222. package/dist/claude/stats.d.ts +5 -0
  223. package/dist/claude/stats.d.ts.map +1 -0
  224. package/dist/claude/stats.js +24 -0
  225. package/dist/claude/stats.js.map +1 -0
  226. package/dist/claude/statusline.d.ts +14 -0
  227. package/dist/claude/statusline.d.ts.map +1 -0
  228. package/dist/claude/statusline.js +45 -0
  229. package/dist/claude/statusline.js.map +1 -0
  230. package/dist/claude/sync-run.d.ts +3 -0
  231. package/dist/claude/sync-run.d.ts.map +1 -0
  232. package/dist/claude/sync-run.js +46 -0
  233. package/dist/claude/sync-run.js.map +1 -0
  234. package/dist/claude/tally.d.ts +50 -0
  235. package/dist/claude/tally.d.ts.map +1 -0
  236. package/dist/claude/tally.js +211 -0
  237. package/dist/claude/tally.js.map +1 -0
  238. package/dist/cli-epilogue.d.ts +12 -0
  239. package/dist/cli-epilogue.d.ts.map +1 -0
  240. package/dist/cli-epilogue.js +55 -0
  241. package/dist/cli-epilogue.js.map +1 -0
  242. package/dist/cli-meta.d.ts +45 -0
  243. package/dist/cli-meta.d.ts.map +1 -0
  244. package/dist/cli-meta.js +145 -0
  245. package/dist/cli-meta.js.map +1 -0
  246. package/dist/cli-picker.d.ts +129 -0
  247. package/dist/cli-picker.d.ts.map +1 -0
  248. package/dist/cli-picker.js +432 -0
  249. package/dist/cli-picker.js.map +1 -0
  250. package/dist/cli.d.ts +3 -0
  251. package/dist/cli.d.ts.map +1 -0
  252. package/dist/cli.js +2213 -0
  253. package/dist/cli.js.map +1 -0
  254. package/dist/cloud/diff.d.ts +20 -0
  255. package/dist/cloud/diff.d.ts.map +1 -0
  256. package/dist/cloud/diff.js +59 -0
  257. package/dist/cloud/diff.js.map +1 -0
  258. package/dist/cloud/nudge.d.ts +66 -0
  259. package/dist/cloud/nudge.d.ts.map +1 -0
  260. package/dist/cloud/nudge.js +268 -0
  261. package/dist/cloud/nudge.js.map +1 -0
  262. package/dist/cloud/workspace-sync.d.ts +58 -0
  263. package/dist/cloud/workspace-sync.d.ts.map +1 -0
  264. package/dist/cloud/workspace-sync.js +268 -0
  265. package/dist/cloud/workspace-sync.js.map +1 -0
  266. package/dist/cloud/workspace.d.ts +159 -0
  267. package/dist/cloud/workspace.d.ts.map +1 -0
  268. package/dist/cloud/workspace.js +134 -0
  269. package/dist/cloud/workspace.js.map +1 -0
  270. package/dist/context/build.d.ts +52 -0
  271. package/dist/context/build.d.ts.map +1 -0
  272. package/dist/context/build.js +362 -0
  273. package/dist/context/build.js.map +1 -0
  274. package/dist/context/check.d.ts +42 -0
  275. package/dist/context/check.d.ts.map +1 -0
  276. package/dist/context/check.js +162 -0
  277. package/dist/context/check.js.map +1 -0
  278. package/dist/context/map-dir.d.ts +4 -0
  279. package/dist/context/map-dir.d.ts.map +1 -0
  280. package/dist/context/map-dir.js +6 -0
  281. package/dist/context/map-dir.js.map +1 -0
  282. package/dist/context/node-file.d.ts +109 -0
  283. package/dist/context/node-file.d.ts.map +1 -0
  284. package/dist/context/node-file.js +362 -0
  285. package/dist/context/node-file.js.map +1 -0
  286. package/dist/context/price.d.ts +49 -0
  287. package/dist/context/price.d.ts.map +1 -0
  288. package/dist/context/price.js +83 -0
  289. package/dist/context/price.js.map +1 -0
  290. package/dist/context/savings.d.ts +26 -0
  291. package/dist/context/savings.d.ts.map +1 -0
  292. package/dist/context/savings.js +59 -0
  293. package/dist/context/savings.js.map +1 -0
  294. package/dist/economy/cli.d.ts +3 -0
  295. package/dist/economy/cli.d.ts.map +1 -0
  296. package/dist/economy/cli.js +52 -0
  297. package/dist/economy/cli.js.map +1 -0
  298. package/dist/economy/delivery.d.ts +49 -0
  299. package/dist/economy/delivery.d.ts.map +1 -0
  300. package/dist/economy/delivery.js +176 -0
  301. package/dist/economy/delivery.js.map +1 -0
  302. package/dist/economy/index.d.ts +68 -0
  303. package/dist/economy/index.d.ts.map +1 -0
  304. package/dist/economy/index.js +524 -0
  305. package/dist/economy/index.js.map +1 -0
  306. package/dist/engine.d.ts +83 -0
  307. package/dist/engine.d.ts.map +1 -0
  308. package/dist/engine.js +122 -0
  309. package/dist/engine.js.map +1 -0
  310. package/dist/evaluation/index.d.ts +41 -0
  311. package/dist/evaluation/index.d.ts.map +1 -0
  312. package/dist/evaluation/index.js +61 -0
  313. package/dist/evaluation/index.js.map +1 -0
  314. package/dist/graph/bindings.d.ts +64 -0
  315. package/dist/graph/bindings.d.ts.map +1 -0
  316. package/dist/graph/bindings.js +713 -0
  317. package/dist/graph/bindings.js.map +1 -0
  318. package/dist/graph/build.d.ts +88 -0
  319. package/dist/graph/build.d.ts.map +1 -0
  320. package/dist/graph/build.js +375 -0
  321. package/dist/graph/build.js.map +1 -0
  322. package/dist/graph/cards.d.ts +46 -0
  323. package/dist/graph/cards.d.ts.map +1 -0
  324. package/dist/graph/cards.js +280 -0
  325. package/dist/graph/cards.js.map +1 -0
  326. package/dist/graph/check.d.ts +25 -0
  327. package/dist/graph/check.d.ts.map +1 -0
  328. package/dist/graph/check.js +192 -0
  329. package/dist/graph/check.js.map +1 -0
  330. package/dist/graph/container.d.ts +63 -0
  331. package/dist/graph/container.d.ts.map +1 -0
  332. package/dist/graph/container.js +190 -0
  333. package/dist/graph/container.js.map +1 -0
  334. package/dist/graph/enrich.d.ts +62 -0
  335. package/dist/graph/enrich.d.ts.map +1 -0
  336. package/dist/graph/enrich.js +253 -0
  337. package/dist/graph/enrich.js.map +1 -0
  338. package/dist/graph/extract-cache.d.ts +101 -0
  339. package/dist/graph/extract-cache.d.ts.map +1 -0
  340. package/dist/graph/extract-cache.js +199 -0
  341. package/dist/graph/extract-cache.js.map +1 -0
  342. package/dist/graph/extract.d.ts +85 -0
  343. package/dist/graph/extract.d.ts.map +1 -0
  344. package/dist/graph/extract.js +2376 -0
  345. package/dist/graph/extract.js.map +1 -0
  346. package/dist/graph/fingerprint.d.ts +76 -0
  347. package/dist/graph/fingerprint.d.ts.map +1 -0
  348. package/dist/graph/fingerprint.js +160 -0
  349. package/dist/graph/fingerprint.js.map +1 -0
  350. package/dist/graph/generic.d.ts +74 -0
  351. package/dist/graph/generic.d.ts.map +1 -0
  352. package/dist/graph/generic.js +580 -0
  353. package/dist/graph/generic.js.map +1 -0
  354. package/dist/graph/invariants.d.ts +33 -0
  355. package/dist/graph/invariants.d.ts.map +1 -0
  356. package/dist/graph/invariants.js +52 -0
  357. package/dist/graph/invariants.js.map +1 -0
  358. package/dist/graph/load.d.ts +29 -0
  359. package/dist/graph/load.d.ts.map +1 -0
  360. package/dist/graph/load.js +97 -0
  361. package/dist/graph/load.js.map +1 -0
  362. package/dist/graph/lsp/client.d.ts +43 -0
  363. package/dist/graph/lsp/client.d.ts.map +1 -0
  364. package/dist/graph/lsp/client.js +179 -0
  365. package/dist/graph/lsp/client.js.map +1 -0
  366. package/dist/graph/lsp/enrich.d.ts +11 -0
  367. package/dist/graph/lsp/enrich.d.ts.map +1 -0
  368. package/dist/graph/lsp/enrich.js +155 -0
  369. package/dist/graph/lsp/enrich.js.map +1 -0
  370. package/dist/graph/lsp/registry.d.ts +15 -0
  371. package/dist/graph/lsp/registry.d.ts.map +1 -0
  372. package/dist/graph/lsp/registry.js +46 -0
  373. package/dist/graph/lsp/registry.js.map +1 -0
  374. package/dist/graph/map.d.ts +107 -0
  375. package/dist/graph/map.d.ts.map +1 -0
  376. package/dist/graph/map.js +239 -0
  377. package/dist/graph/map.js.map +1 -0
  378. package/dist/graph/native.d.ts +38 -0
  379. package/dist/graph/native.d.ts.map +1 -0
  380. package/dist/graph/native.js +169 -0
  381. package/dist/graph/native.js.map +1 -0
  382. package/dist/graph/queries/c.scm +13 -0
  383. package/dist/graph/queries/c_sharp.scm +19 -0
  384. package/dist/graph/queries/clojure.scm +58 -0
  385. package/dist/graph/queries/cpp.scm +23 -0
  386. package/dist/graph/queries/dart.scm +42 -0
  387. package/dist/graph/queries/elixir.scm +54 -0
  388. package/dist/graph/queries/java.scm +20 -0
  389. package/dist/graph/queries/kotlin.scm +43 -0
  390. package/dist/graph/queries/lua.scm +36 -0
  391. package/dist/graph/queries/nix.scm +32 -0
  392. package/dist/graph/queries/php.scm +40 -0
  393. package/dist/graph/queries/ruby.scm +65 -0
  394. package/dist/graph/queries/rust.scm +41 -0
  395. package/dist/graph/queries/scala.scm +66 -0
  396. package/dist/graph/queries/solidity.scm +43 -0
  397. package/dist/graph/queries/swift.scm +51 -0
  398. package/dist/graph/refresh.d.ts +49 -0
  399. package/dist/graph/refresh.d.ts.map +1 -0
  400. package/dist/graph/refresh.js +255 -0
  401. package/dist/graph/refresh.js.map +1 -0
  402. package/dist/graph/relations.d.ts +14 -0
  403. package/dist/graph/relations.d.ts.map +1 -0
  404. package/dist/graph/relations.js +8 -0
  405. package/dist/graph/relations.js.map +1 -0
  406. package/dist/graph/resolve.d.ts +17 -0
  407. package/dist/graph/resolve.d.ts.map +1 -0
  408. package/dist/graph/resolve.js +654 -0
  409. package/dist/graph/resolve.js.map +1 -0
  410. package/dist/graph/root.d.ts +11 -0
  411. package/dist/graph/root.d.ts.map +1 -0
  412. package/dist/graph/root.js +40 -0
  413. package/dist/graph/root.js.map +1 -0
  414. package/dist/graph/scopes.d.ts +42 -0
  415. package/dist/graph/scopes.d.ts.map +1 -0
  416. package/dist/graph/scopes.js +342 -0
  417. package/dist/graph/scopes.js.map +1 -0
  418. package/dist/graph/seed.d.ts +38 -0
  419. package/dist/graph/seed.d.ts.map +1 -0
  420. package/dist/graph/seed.js +226 -0
  421. package/dist/graph/seed.js.map +1 -0
  422. package/dist/graph/source-files.d.ts +40 -0
  423. package/dist/graph/source-files.d.ts.map +1 -0
  424. package/dist/graph/source-files.js +85 -0
  425. package/dist/graph/source-files.js.map +1 -0
  426. package/dist/graph/traverse-cli.d.ts +55 -0
  427. package/dist/graph/traverse-cli.d.ts.map +1 -0
  428. package/dist/graph/traverse-cli.js +189 -0
  429. package/dist/graph/traverse-cli.js.map +1 -0
  430. package/dist/graph/traverse.d.ts +112 -0
  431. package/dist/graph/traverse.d.ts.map +1 -0
  432. package/dist/graph/traverse.js +192 -0
  433. package/dist/graph/traverse.js.map +1 -0
  434. package/dist/graph/types.d.ts +78 -0
  435. package/dist/graph/types.d.ts.map +1 -0
  436. package/dist/graph/types.js +14 -0
  437. package/dist/graph/types.js.map +1 -0
  438. package/dist/graph/workspace-cli.d.ts +48 -0
  439. package/dist/graph/workspace-cli.d.ts.map +1 -0
  440. package/dist/graph/workspace-cli.js +102 -0
  441. package/dist/graph/workspace-cli.js.map +1 -0
  442. package/dist/graph/workspace.d.ts +135 -0
  443. package/dist/graph/workspace.d.ts.map +1 -0
  444. package/dist/graph/workspace.js +598 -0
  445. package/dist/graph/workspace.js.map +1 -0
  446. package/dist/graph/write.d.ts +13 -0
  447. package/dist/graph/write.d.ts.map +1 -0
  448. package/dist/graph/write.js +86 -0
  449. package/dist/graph/write.js.map +1 -0
  450. package/dist/hosts/antigravity.d.ts +8 -0
  451. package/dist/hosts/antigravity.d.ts.map +1 -0
  452. package/dist/hosts/antigravity.js +42 -0
  453. package/dist/hosts/antigravity.js.map +1 -0
  454. package/dist/hosts/claude-global.d.ts +36 -0
  455. package/dist/hosts/claude-global.d.ts.map +1 -0
  456. package/dist/hosts/claude-global.js +153 -0
  457. package/dist/hosts/claude-global.js.map +1 -0
  458. package/dist/hosts/codex-hooks.d.ts +11 -0
  459. package/dist/hosts/codex-hooks.d.ts.map +1 -0
  460. package/dist/hosts/codex-hooks.js +80 -0
  461. package/dist/hosts/codex-hooks.js.map +1 -0
  462. package/dist/hosts/config-write.d.ts +36 -0
  463. package/dist/hosts/config-write.d.ts.map +1 -0
  464. package/dist/hosts/config-write.js +64 -0
  465. package/dist/hosts/config-write.js.map +1 -0
  466. package/dist/hosts/cursor-hooks.d.ts +21 -0
  467. package/dist/hosts/cursor-hooks.d.ts.map +1 -0
  468. package/dist/hosts/cursor-hooks.js +103 -0
  469. package/dist/hosts/cursor-hooks.js.map +1 -0
  470. package/dist/hosts/init.d.ts +26 -0
  471. package/dist/hosts/init.d.ts.map +1 -0
  472. package/dist/hosts/init.js +82 -0
  473. package/dist/hosts/init.js.map +1 -0
  474. package/dist/hosts/install.d.ts +12 -0
  475. package/dist/hosts/install.d.ts.map +1 -0
  476. package/dist/hosts/install.js +347 -0
  477. package/dist/hosts/install.js.map +1 -0
  478. package/dist/hosts/instructions.d.ts +7 -0
  479. package/dist/hosts/instructions.d.ts.map +1 -0
  480. package/dist/hosts/instructions.js +71 -0
  481. package/dist/hosts/instructions.js.map +1 -0
  482. package/dist/hosts/investigation-instructions.d.ts +2 -0
  483. package/dist/hosts/investigation-instructions.d.ts.map +1 -0
  484. package/dist/hosts/investigation-instructions.js +2 -0
  485. package/dist/hosts/investigation-instructions.js.map +1 -0
  486. package/dist/hosts/mcp-config.d.ts +59 -0
  487. package/dist/hosts/mcp-config.d.ts.map +1 -0
  488. package/dist/hosts/mcp-config.js +229 -0
  489. package/dist/hosts/mcp-config.js.map +1 -0
  490. package/dist/hosts/plan.d.ts +32 -0
  491. package/dist/hosts/plan.d.ts.map +1 -0
  492. package/dist/hosts/plan.js +77 -0
  493. package/dist/hosts/plan.js.map +1 -0
  494. package/dist/hosts/registry.d.ts +35 -0
  495. package/dist/hosts/registry.d.ts.map +1 -0
  496. package/dist/hosts/registry.js +157 -0
  497. package/dist/hosts/registry.js.map +1 -0
  498. package/dist/hosts/retract.d.ts +47 -0
  499. package/dist/hosts/retract.d.ts.map +1 -0
  500. package/dist/hosts/retract.js +541 -0
  501. package/dist/hosts/retract.js.map +1 -0
  502. package/dist/hosts/sections.d.ts +46 -0
  503. package/dist/hosts/sections.d.ts.map +1 -0
  504. package/dist/hosts/sections.js +126 -0
  505. package/dist/hosts/sections.js.map +1 -0
  506. package/dist/index.d.ts +43 -0
  507. package/dist/index.d.ts.map +1 -0
  508. package/dist/index.js +33 -0
  509. package/dist/index.js.map +1 -0
  510. package/dist/ingest/fs.d.ts +79 -0
  511. package/dist/ingest/fs.d.ts.map +1 -0
  512. package/dist/ingest/fs.js +307 -0
  513. package/dist/ingest/fs.js.map +1 -0
  514. package/dist/init-guard.d.ts +11 -0
  515. package/dist/init-guard.d.ts.map +1 -0
  516. package/dist/init-guard.js +21 -0
  517. package/dist/init-guard.js.map +1 -0
  518. package/dist/investigation/index.d.ts +57 -0
  519. package/dist/investigation/index.d.ts.map +1 -0
  520. package/dist/investigation/index.js +346 -0
  521. package/dist/investigation/index.js.map +1 -0
  522. package/dist/mcp/compact.d.ts +9 -0
  523. package/dist/mcp/compact.d.ts.map +1 -0
  524. package/dist/mcp/compact.js +133 -0
  525. package/dist/mcp/compact.js.map +1 -0
  526. package/dist/mcp/instructions.d.ts +5 -0
  527. package/dist/mcp/instructions.d.ts.map +1 -0
  528. package/dist/mcp/instructions.js +57 -0
  529. package/dist/mcp/instructions.js.map +1 -0
  530. package/dist/mcp/server.d.ts +7 -0
  531. package/dist/mcp/server.d.ts.map +1 -0
  532. package/dist/mcp/server.js +128 -0
  533. package/dist/mcp/server.js.map +1 -0
  534. package/dist/mcp/tool-names.d.ts +20 -0
  535. package/dist/mcp/tool-names.d.ts.map +1 -0
  536. package/dist/mcp/tool-names.js +36 -0
  537. package/dist/mcp/tool-names.js.map +1 -0
  538. package/dist/mcp/tools.d.ts +22 -0
  539. package/dist/mcp/tools.d.ts.map +1 -0
  540. package/dist/mcp/tools.js +300 -0
  541. package/dist/mcp/tools.js.map +1 -0
  542. package/dist/notes/ask-notes.d.ts +8 -0
  543. package/dist/notes/ask-notes.d.ts.map +1 -0
  544. package/dist/notes/ask-notes.js +19 -0
  545. package/dist/notes/ask-notes.js.map +1 -0
  546. package/dist/notes/branches.d.ts +102 -0
  547. package/dist/notes/branches.d.ts.map +1 -0
  548. package/dist/notes/branches.js +304 -0
  549. package/dist/notes/branches.js.map +1 -0
  550. package/dist/notes/cold-start.d.ts +177 -0
  551. package/dist/notes/cold-start.d.ts.map +1 -0
  552. package/dist/notes/cold-start.js +537 -0
  553. package/dist/notes/cold-start.js.map +1 -0
  554. package/dist/notes/edit-overlap.d.ts +62 -0
  555. package/dist/notes/edit-overlap.d.ts.map +1 -0
  556. package/dist/notes/edit-overlap.js +202 -0
  557. package/dist/notes/edit-overlap.js.map +1 -0
  558. package/dist/notes/git-facts.d.ts +21 -0
  559. package/dist/notes/git-facts.d.ts.map +1 -0
  560. package/dist/notes/git-facts.js +121 -0
  561. package/dist/notes/git-facts.js.map +1 -0
  562. package/dist/notes/home.d.ts +87 -0
  563. package/dist/notes/home.d.ts.map +1 -0
  564. package/dist/notes/home.js +430 -0
  565. package/dist/notes/home.js.map +1 -0
  566. package/dist/notes/learning-fields.d.ts +102 -0
  567. package/dist/notes/learning-fields.d.ts.map +1 -0
  568. package/dist/notes/learning-fields.js +217 -0
  569. package/dist/notes/learning-fields.js.map +1 -0
  570. package/dist/notes/note-gate.d.ts +42 -0
  571. package/dist/notes/note-gate.d.ts.map +1 -0
  572. package/dist/notes/note-gate.js +181 -0
  573. package/dist/notes/note-gate.js.map +1 -0
  574. package/dist/notes/notes.d.ts +214 -0
  575. package/dist/notes/notes.d.ts.map +1 -0
  576. package/dist/notes/notes.js +591 -0
  577. package/dist/notes/notes.js.map +1 -0
  578. package/dist/notes/pr-reviews.d.ts +108 -0
  579. package/dist/notes/pr-reviews.d.ts.map +1 -0
  580. package/dist/notes/pr-reviews.js +325 -0
  581. package/dist/notes/pr-reviews.js.map +1 -0
  582. package/dist/notes/repo-julius.d.ts +18 -0
  583. package/dist/notes/repo-julius.d.ts.map +1 -0
  584. package/dist/notes/repo-julius.js +111 -0
  585. package/dist/notes/repo-julius.js.map +1 -0
  586. package/dist/notes/session-cost.d.ts +35 -0
  587. package/dist/notes/session-cost.d.ts.map +1 -0
  588. package/dist/notes/session-cost.js +276 -0
  589. package/dist/notes/session-cost.js.map +1 -0
  590. package/dist/search/grep-cli.d.ts +37 -0
  591. package/dist/search/grep-cli.d.ts.map +1 -0
  592. package/dist/search/grep-cli.js +119 -0
  593. package/dist/search/grep-cli.js.map +1 -0
  594. package/dist/search/grep.d.ts +60 -0
  595. package/dist/search/grep.d.ts.map +1 -0
  596. package/dist/search/grep.js +176 -0
  597. package/dist/search/grep.js.map +1 -0
  598. package/dist/search/ignored-code.d.ts +9 -0
  599. package/dist/search/ignored-code.d.ts.map +1 -0
  600. package/dist/search/ignored-code.js +73 -0
  601. package/dist/search/ignored-code.js.map +1 -0
  602. package/dist/skills/skills.d.ts +118 -0
  603. package/dist/skills/skills.d.ts.map +1 -0
  604. package/dist/skills/skills.js +370 -0
  605. package/dist/skills/skills.js.map +1 -0
  606. package/dist/telemetry/contract.d.ts +103 -0
  607. package/dist/telemetry/contract.d.ts.map +1 -0
  608. package/dist/telemetry/contract.js +270 -0
  609. package/dist/telemetry/contract.js.map +1 -0
  610. package/dist/telemetry/flush.d.ts +21 -0
  611. package/dist/telemetry/flush.d.ts.map +1 -0
  612. package/dist/telemetry/flush.js +85 -0
  613. package/dist/telemetry/flush.js.map +1 -0
  614. package/dist/telemetry/gate.d.ts +30 -0
  615. package/dist/telemetry/gate.d.ts.map +1 -0
  616. package/dist/telemetry/gate.js +81 -0
  617. package/dist/telemetry/gate.js.map +1 -0
  618. package/dist/telemetry/identity.d.ts +40 -0
  619. package/dist/telemetry/identity.d.ts.map +1 -0
  620. package/dist/telemetry/identity.js +80 -0
  621. package/dist/telemetry/identity.js.map +1 -0
  622. package/dist/telemetry/index.d.ts +18 -0
  623. package/dist/telemetry/index.d.ts.map +1 -0
  624. package/dist/telemetry/index.js +16 -0
  625. package/dist/telemetry/index.js.map +1 -0
  626. package/dist/telemetry/key.d.ts +4 -0
  627. package/dist/telemetry/key.d.ts.map +1 -0
  628. package/dist/telemetry/key.js +4 -0
  629. package/dist/telemetry/key.js.map +1 -0
  630. package/dist/telemetry/notice.d.ts +19 -0
  631. package/dist/telemetry/notice.d.ts.map +1 -0
  632. package/dist/telemetry/notice.js +93 -0
  633. package/dist/telemetry/notice.js.map +1 -0
  634. package/dist/telemetry/queue.d.ts +35 -0
  635. package/dist/telemetry/queue.d.ts.map +1 -0
  636. package/dist/telemetry/queue.js +162 -0
  637. package/dist/telemetry/queue.js.map +1 -0
  638. package/dist/telemetry/send.d.ts +19 -0
  639. package/dist/telemetry/send.d.ts.map +1 -0
  640. package/dist/telemetry/send.js +84 -0
  641. package/dist/telemetry/send.js.map +1 -0
  642. package/dist/telemetry/sessions.d.ts +25 -0
  643. package/dist/telemetry/sessions.d.ts.map +1 -0
  644. package/dist/telemetry/sessions.js +104 -0
  645. package/dist/telemetry/sessions.js.map +1 -0
  646. package/dist/telemetry/track.d.ts +62 -0
  647. package/dist/telemetry/track.d.ts.map +1 -0
  648. package/dist/telemetry/track.js +142 -0
  649. package/dist/telemetry/track.js.map +1 -0
  650. package/dist/upkeep-run.d.ts +15 -0
  651. package/dist/upkeep-run.d.ts.map +1 -0
  652. package/dist/upkeep-run.js +71 -0
  653. package/dist/upkeep-run.js.map +1 -0
  654. package/dist/upkeep.d.ts +125 -0
  655. package/dist/upkeep.d.ts.map +1 -0
  656. package/dist/upkeep.js +255 -0
  657. package/dist/upkeep.js.map +1 -0
  658. package/dist/util/browser.d.ts +3 -0
  659. package/dist/util/browser.d.ts.map +1 -0
  660. package/dist/util/browser.js +14 -0
  661. package/dist/util/browser.js.map +1 -0
  662. package/dist/util/front-matter.d.ts +19 -0
  663. package/dist/util/front-matter.d.ts.map +1 -0
  664. package/dist/util/front-matter.js +21 -0
  665. package/dist/util/front-matter.js.map +1 -0
  666. package/dist/util/id.d.ts +7 -0
  667. package/dist/util/id.d.ts.map +1 -0
  668. package/dist/util/id.js +14 -0
  669. package/dist/util/id.js.map +1 -0
  670. package/dist/util/paths.d.ts +29 -0
  671. package/dist/util/paths.d.ts.map +1 -0
  672. package/dist/util/paths.js +71 -0
  673. package/dist/util/paths.js.map +1 -0
  674. package/dist/util/source.d.ts +4 -0
  675. package/dist/util/source.d.ts.map +1 -0
  676. package/dist/util/source.js +12 -0
  677. package/dist/util/source.js.map +1 -0
  678. package/dist/util/spinner.d.ts +15 -0
  679. package/dist/util/spinner.d.ts.map +1 -0
  680. package/dist/util/spinner.js +52 -0
  681. package/dist/util/spinner.js.map +1 -0
  682. package/dist/util/state.d.ts +100 -0
  683. package/dist/util/state.d.ts.map +1 -0
  684. package/dist/util/state.js +186 -0
  685. package/dist/util/state.js.map +1 -0
  686. package/dist/viewer/app.js +2 -0
  687. package/dist/viewer/index.html +49 -0
  688. package/dist/viewer/style.css +154 -0
  689. package/dist/viz/assemble.d.ts +83 -0
  690. package/dist/viz/assemble.d.ts.map +1 -0
  691. package/dist/viz/assemble.js +101 -0
  692. package/dist/viz/assemble.js.map +1 -0
  693. package/dist/viz/export.d.ts +39 -0
  694. package/dist/viz/export.d.ts.map +1 -0
  695. package/dist/viz/export.js +98 -0
  696. package/dist/viz/export.js.map +1 -0
  697. package/dist/viz/serve.d.ts +12 -0
  698. package/dist/viz/serve.d.ts.map +1 -0
  699. package/dist/viz/serve.js +129 -0
  700. package/dist/viz/serve.js.map +1 -0
  701. package/docs/assets/context-benchmark.svg +31 -0
  702. package/docs/assets/julius-hero.png +0 -0
  703. package/docs/upstream-changelog.md +785 -0
  704. package/package.json +138 -4
@@ -0,0 +1,849 @@
1
+ import { readFileSync, existsSync } from 'node:fs';
2
+ import { execFileSync, spawn } from 'node:child_process';
3
+ import { join, basename, isAbsolute, relative, resolve } from 'node:path';
4
+ import { homedir } from 'node:os';
5
+ import { readWiring } from './stats.js';
6
+ import { formatBlastRadius, relevantRetrieval, formatOrientation, notesForPrompt, notesOnTouch, standingDirective } from './format.js';
7
+ import { commitLines, listNotes, setupCommitLine, standingLearnings } from '../notes/notes.js';
8
+ import { liveLearnings } from '../notes/learning-fields.js';
9
+ import { noteAsk, noteSignals, NOTE_ASKS_PER_SESSION } from './note-signals.js';
10
+ import { noteAuthor, teammatesOn } from '../notes/git-facts.js';
11
+ import { indexFreshness, staleBanner } from '../context/check.js';
12
+ import { patchStats, readStats, acquireLock, readSession, writeSession, resolveContextDir } from './state.js';
13
+ import { juliusCliPath, claudeScriptPath } from './paths.js';
14
+ import { runUpkeep } from '../upkeep-run.js';
15
+ import { runningVersion } from '../upkeep.js';
16
+ import { hostsWiredForJulius } from '../hosts/registry.js';
17
+ import { flushClosedSessions, summarizeSession } from '../telemetry/sessions.js';
18
+ import { maybeFlushInBackground } from '../telemetry/flush.js';
19
+ import { hasSavingsTally, lastAssistantTurn, lastTurnBilling } from './tally.js';
20
+ import { scopeOf, scopesOfGraph } from '../graph/scopes.js';
21
+ import { classifyToolUse, commandInvokesJulius, isMcpToolName, isJuliusMcpTool, parseSavings, recordToolUse } from './session-metrics.js';
22
+ import { adoptRepoBrand, cmd, tag } from '../brand.js';
23
+ import { globalCopyCovers } from './hook-layers.js';
24
+ import { NOTE_CALL } from '../notes/session-cost.js';
25
+ import { keepsNotes, noteCount, repoPlace } from '../notes/home.js';
26
+ import { branchesStale, overlapMark, readBranchCache, refreshBranches, SESSION_REFRESH_MS } from '../notes/branches.js';
27
+ import { learningFiles } from '../notes/repo-julius.js';
28
+ import { inWorkspace, maybeSyncInBackground } from '../cloud/workspace-sync.js';
29
+ import { cacheDir, readJson, writeJsonAtomic } from '../util/state.js';
30
+ import { countBucket } from '../telemetry/contract.js';
31
+ import { track } from '../telemetry/track.js';
32
+ import { skillsDirective } from '../skills/skills.js';
33
+ /** Prompts shorter than this never trigger retrieval — they are almost always
34
+ * conversational ("yes go ahead", "thanks") and the coverage gate can't judge
35
+ * them reliably with so few terms. */
36
+ const MIN_PROMPT_CHARS = 12;
37
+ function readStdin() {
38
+ const seam = process.env.JULIUS_TEST_STDIN;
39
+ const raw = seam !== undefined ? seam : safeReadFd0();
40
+ try {
41
+ return JSON.parse(raw);
42
+ }
43
+ catch {
44
+ return {};
45
+ }
46
+ }
47
+ function safeReadFd0() { try {
48
+ return readFileSync(0, 'utf8');
49
+ }
50
+ catch {
51
+ return '';
52
+ } }
53
+ function projectDir(input) {
54
+ return process.env.CLAUDE_PROJECT_DIR || input.cwd || process.cwd();
55
+ }
56
+ export function underJulius(dir, file) {
57
+ const rel = file.startsWith(dir) ? file.slice(dir.length) : file;
58
+ const posix = rel.replace(/^[/\\]+/, '').replace(/\\/g, '/');
59
+ return posix.startsWith('julius/') || posix.startsWith('.julius/cache/');
60
+ }
61
+ /** Default budget for a julius child process invoked from a hook, matching the 8s
62
+ * the installed hook entries carry. */
63
+ const CHILD_TIMEOUT_MS = 8000;
64
+ /** Headroom left for the hook's own work (read stdin, score, write session, emit)
65
+ * after its `julius ask` child returns. */
66
+ const HOOK_OVERHEAD_MS = 2000;
67
+ /** Floor, so a hand-edited tiny timeout can't leave the child no time at all. */
68
+ const MIN_CHILD_TIMEOUT_MS = 4000;
69
+ /**
70
+ * How long the prompt hook may let `julius ask` run — derived from the budget that is
71
+ * *actually installed* in this repo's `.claude/settings.json`, not from what the
72
+ * current version of `settings-merge.ts` would install.
73
+ *
74
+ * A query now brings the graph up to date first, so `julius init` raises the
75
+ * UserPromptSubmit budget to 15s to cover the one cold rebuild after an upgrade. But
76
+ * `mergeJuliusSettings` only runs during `julius init` — upgrading the npm package does
77
+ * not re-run it. So every repo wired before that change keeps `"timeout": 8000`, and
78
+ * hard-coding a 13s child there means Claude Code kills the hook first: `emit()` and
79
+ * `writeSession()` never run, the turn gets no retrieval pack at all, and the SIGKILLed
80
+ * child can't even release the build lock. Reading the installed number keeps the child
81
+ * strictly inside whatever budget this repo really has.
82
+ */
83
+ export function promptAskTimeout(dir) {
84
+ const installed = installedHookTimeout(dir, 'UserPromptSubmit');
85
+ if (installed === null)
86
+ return CHILD_TIMEOUT_MS - HOOK_OVERHEAD_MS;
87
+ return Math.max(MIN_CHILD_TIMEOUT_MS, installed - HOOK_OVERHEAD_MS);
88
+ }
89
+ /**
90
+ * Every settings file Claude Code merges hook definitions from, for a session
91
+ * rooted at `dir`. The per-repo file is not the only place julius's hooks can be
92
+ * installed: declaring them once at the user level wires every repo on the
93
+ * machine at once, and such a repo has no `.claude/settings.json` at all.
94
+ */
95
+ function hookSettingsFiles(dir) {
96
+ const user = process.env.CLAUDE_CONFIG_DIR ?? join(homedir(), '.claude');
97
+ return [
98
+ join(dir, '.claude', 'settings.json'),
99
+ join(dir, '.claude', 'settings.local.json'),
100
+ join(user, 'settings.json'),
101
+ ];
102
+ }
103
+ /** The timeout on one settings file's julius hook entry for `event`, or null if it
104
+ * can't be read (no settings file, hand-edited shape, unparseable JSON). */
105
+ function hookTimeoutIn(file, event) {
106
+ try {
107
+ const settings = JSON.parse(readFileSync(file, 'utf8'));
108
+ const blocks = settings?.hooks?.[event];
109
+ if (!Array.isArray(blocks))
110
+ return null;
111
+ for (const block of blocks) {
112
+ for (const h of block?.hooks ?? []) {
113
+ if (typeof h?.command === 'string' && /(julius)-hooks\.cjs/.test(h.command) && typeof h.timeout === 'number') {
114
+ return h.timeout;
115
+ }
116
+ }
117
+ }
118
+ return null;
119
+ }
120
+ catch {
121
+ return null;
122
+ }
123
+ }
124
+ /**
125
+ * The budget this hook is actually running under, or null when no settings file
126
+ * declares one.
127
+ *
128
+ * The smallest declared timeout wins rather than the nearest, because when more
129
+ * than one file declares the hook Claude Code runs every matching entry and this
130
+ * process cannot tell which one launched it. Guessing high is the expensive
131
+ * mistake: an overrunning child gets the whole hook SIGKILLed, so `emit()` and
132
+ * `writeSession()` never run and the turn silently gets no retrieval at all.
133
+ * Guessing low only shortens one query.
134
+ */
135
+ function installedHookTimeout(dir, event) {
136
+ let smallest = null;
137
+ for (const file of hookSettingsFiles(dir)) {
138
+ const timeout = hookTimeoutIn(file, event);
139
+ if (timeout === null)
140
+ continue;
141
+ if (smallest === null || timeout < smallest)
142
+ smallest = timeout;
143
+ }
144
+ return smallest;
145
+ }
146
+ /**
147
+ * Append `--dir <contextDir>` for the hooks' own `julius ask`/`julius check`
148
+ * children — the one place in this file that spawns the CLI itself rather
149
+ * than reading `julius/` off disk (which already resolves through
150
+ * `resolveContextDir` inside `util/state.ts` and `claude/stats.ts`). A no-op
151
+ * when `JULIUS_DIR` isn't set, so an unconfigured repo's spawned CLI sees
152
+ * byte-identical argv to before this existed.
153
+ */
154
+ function withContextDirArg(dir, args) {
155
+ return process.env.JULIUS_DIR ? [...args, '--dir', resolveContextDir(dir)] : args;
156
+ }
157
+ function juliusJson(dir, args, timeout = CHILD_TIMEOUT_MS) {
158
+ try {
159
+ // JULIUS_TEST_CLI is a test seam (mirrors JULIUS_TEST_STDIN/JULIUS_TEST_SYNC_RUN) so
160
+ // tests can point the prompt hook's `julius ask`/`julius check` calls at a stub
161
+ // script and observe the exact args it was invoked with, instead of shelling
162
+ // out to the real CLI (which isn't built relative to the TS source under test).
163
+ const cliPath = process.env.JULIUS_TEST_CLI ?? juliusCliPath();
164
+ const out = execFileSync(process.execPath, [cliPath, ...args], { cwd: dir, encoding: 'utf8', timeout, stdio: ['ignore', 'pipe', 'ignore'] });
165
+ return JSON.parse(out);
166
+ }
167
+ catch (e) {
168
+ // `julius check` exits non-zero when the graph is stale (by design) but still
169
+ // prints valid JSON to stdout; recover it from the thrown error before giving up.
170
+ if (e && typeof e.stdout === 'string' && e.stdout.trim()) {
171
+ try {
172
+ return JSON.parse(e.stdout);
173
+ }
174
+ catch { /* not JSON — fall through */ }
175
+ }
176
+ return null;
177
+ }
178
+ }
179
+ function checkStaleCount(dir) {
180
+ const r = juliusJson(dir, withContextDirArg(dir, ['check', '.', '--json']));
181
+ const g = r?.graph ?? {};
182
+ return (g.changed?.length ?? 0) + (g.added?.length ?? 0) + (g.removed?.length ?? 0);
183
+ }
184
+ function emit(eventName, additionalContext) {
185
+ process.stdout.write(JSON.stringify({ hookSpecificOutput: { hookEventName: eventName, additionalContext } }));
186
+ }
187
+ /**
188
+ * The absolute path of the file a PostToolUse edit touched, across host edit-tool
189
+ * shapes:
190
+ * - Claude Code (`Write`/`Edit`/`MultiEdit`) states it directly as
191
+ * `tool_input.file_path` (already absolute).
192
+ * - Codex (`apply_patch`) carries the whole patch in `tool_input.command` and
193
+ * names the file in the patch header (`*** Add File:` / `*** Update File:`),
194
+ * as a repo-relative path — resolved against `dir` here. Take the first
195
+ * Add/Update target; that one file is enough to mark the graph dirty and
196
+ * draw a blast radius (the sync re-checks the whole tree anyway).
197
+ * Returns null when neither shape yields a path, so the hook stays a clean no-op.
198
+ */
199
+ export function editedFilePath(input, dir) {
200
+ const direct = input?.tool_input?.file_path;
201
+ if (typeof direct === 'string' && direct.trim())
202
+ return direct;
203
+ const cmd = input?.tool_input?.command;
204
+ if (typeof cmd === 'string' && cmd) {
205
+ const m = /^\*\*\*\s+(?:Add|Update)\s+File:\s+(.+?)\s*$/m.exec(cmd);
206
+ if (m)
207
+ return isAbsolute(m[1]) ? m[1] : join(dir, m[1]);
208
+ }
209
+ return null;
210
+ }
211
+ async function handlePostEdit(input, dir) {
212
+ const file = editedFilePath(input, dir);
213
+ if (!file || underJulius(dir, file))
214
+ return;
215
+ patchStats(dir, { dirty: true, staleCount: checkStaleCount(dir), lastFile: basename(file) });
216
+ const out = [];
217
+ const w = readWiring(dir);
218
+ if (w) {
219
+ const br = formatBlastRadius(w, file);
220
+ if (br)
221
+ out.push(br);
222
+ }
223
+ const overlap = await editOverlap(input, dir, file);
224
+ if (overlap)
225
+ out.push(overlap);
226
+ const learned = learningsOnTouch(input, dir);
227
+ if (learned)
228
+ out.push(learned);
229
+ // One hook, one answer: two JSON objects on stdout would be read as neither.
230
+ if (out.length)
231
+ emit('PostToolUse', out.join('\n\n'));
232
+ }
233
+ /** Branch-and-function pairs remembered per session, so each is said once. */
234
+ const INJECTED_OVERLAPS_CAP = 40;
235
+ /**
236
+ * Under julius, a teammate's open branch that changes the function this edit
237
+ * just changed, for the agent to read and tell the person about, each branch
238
+ * and function once a session. Parsing loads grammars, so it's imported only
239
+ * when the edited file is one some branch changes. Never throws.
240
+ */
241
+ async function editOverlap(input, dir, file) {
242
+ if (!keepsNotes(dir))
243
+ return null;
244
+ try {
245
+ const top = repoPlace(dir);
246
+ if (!top.git)
247
+ return null;
248
+ const { functionOverlaps, editOverlapDirective } = await import('../notes/edit-overlap.js');
249
+ const found = await functionOverlaps(top.checkout, resolve(dir, file), input?.tool_input, noteAuthor(top.checkout));
250
+ if (!found.length)
251
+ return null;
252
+ const id = input?.session_id || 'default';
253
+ const s = readSession(dir, id);
254
+ const seen = new Set(s.injectedOverlaps ?? []);
255
+ const fresh = found.filter((o) => o.symbols.some((x) => !seen.has(`${o.ref} ${x.id}`)));
256
+ if (!fresh.length)
257
+ return null;
258
+ s.injectedOverlaps = [...seen, ...fresh.flatMap((o) => o.symbols.map((x) => `${o.ref} ${x.id}`))].slice(-INJECTED_OVERLAPS_CAP);
259
+ writeSession(dir, id, s);
260
+ const base = readBranchCache(top.checkout)?.base ?? 'origin/main';
261
+ return fresh.slice(0, 2).map((o) => editOverlapDirective(o, base, tag(), overlapMark())).join('\n\n');
262
+ }
263
+ catch {
264
+ return null;
265
+ }
266
+ }
267
+ /**
268
+ * The "you're working in backend/, weight it" hint: on a multi-scope repo,
269
+ * narrow the prompt hook's `ask` call to whatever scope the last-edited file
270
+ * (`stats.lastFile`, captured at {@link handlePostEdit}) sits in.
271
+ *
272
+ * `lastFile` is only a basename (not a repo-relative path — see
273
+ * `handlePostEdit`), so this is a best-effort lookup against the CURRENT
274
+ * graph: any file node whose path ends in `/<lastFile>` (or equals it, for a
275
+ * repo-root file). Fails soft in every direction a hook must never crash on —
276
+ * no graph, a single-scope graph, a lastFile no longer in the graph (moved,
277
+ * deleted, or edited before the first build), or a basename that lands in
278
+ * more than one scope (ambiguous: could be either sub-project) all skip the
279
+ * hint silently, logging one line to stderr so the miss is visible without
280
+ * ever failing the hook.
281
+ */
282
+ export function lastFileScopeHint(dir, lastFile) {
283
+ if (!lastFile)
284
+ return null;
285
+ try {
286
+ const w = readWiring(dir);
287
+ if (!w)
288
+ return null;
289
+ const scopes = scopesOfGraph(w);
290
+ if (scopes.length <= 1)
291
+ return null; // single-scope: no hint, no --in
292
+ const matches = (w.nodes ?? []).filter((n) => n.kind === 'file' && (n.path === lastFile || n.path.endsWith(`/${lastFile}`)));
293
+ if (matches.length === 0) {
294
+ console.error(`${tag()} prompt hook: lastFile "${lastFile}" not found in the graph — skipping scope hint`);
295
+ return null;
296
+ }
297
+ const prefixes = new Set(matches.map((n) => scopeOf(n.path, scopes).prefix));
298
+ if (prefixes.size > 1) {
299
+ console.error(`${tag()} prompt hook: lastFile "${lastFile}" matches more than one scope — skipping scope hint`);
300
+ return null;
301
+ }
302
+ const [prefix] = prefixes;
303
+ return prefix === '' ? null : prefix; // root scope: nothing to narrow
304
+ }
305
+ catch (e) {
306
+ console.error(`${tag()} prompt hook: scope hint lookup failed (${e?.message ?? e}) — skipping`);
307
+ return null;
308
+ }
309
+ }
310
+ /**
311
+ * PostToolUse on a retrieval tool. Two jobs, both a pure parse of the payload the
312
+ * hook already received (no re-run):
313
+ *
314
+ * 1. Score the usage mix: classify the tool as a julius retrieval or a source
315
+ * read (Read/Grep/Glob) and bump the session's `juliusReads`/`sourceReads`.
316
+ * Until this ran, those counters were never incremented, so
317
+ * `session_summary` telemetry shipped 0/0 for every session.
318
+ * 2. Sum any `[julius] tokens saved ≈ N` footers in the output into the running
319
+ * `savedTokens` total, so the statusline's `~N tok saved` reflects the
320
+ * session across CLI and MCP.
321
+ *
322
+ * A `[julius]` footer is itself proof julius ran, so it also counts as a julius
323
+ * read even when the tool name alone (a bare `Bash`) couldn't say so. A julius use
324
+ * also flags the turn (`turnUsedJulius`) so the Stop hook's tally can resolve
325
+ * whether the reply told the user what it saved. Stays a no-op on the
326
+ * Write/Edit/unrelated-Bash majority: nothing to classify and no footer means
327
+ * nothing is written.
328
+ */
329
+ function handleToolUse(input, dir) {
330
+ recordToolUse(dir, input?.session_id || 'default', { ...classifyAndScore(input?.tool_name, input?.tool_input?.command, () => input?.tool_response ?? input), host: 'claude-code' });
331
+ const learned = learningsOnTouch(input, dir);
332
+ if (learned)
333
+ emit('PostToolUse', learned);
334
+ }
335
+ /**
336
+ * Under julius, the learnings about the file a Read, Edit or Write just touched,
337
+ * or that a shell command (`sed -n 1,40p src/a.ts`, `cat`, a test run) names,
338
+ * each once a session. A julius command is skipped: its own output already
339
+ * carries the learnings that bear on it. Never throws.
340
+ */
341
+ export function learningsOnTouch(input, dir) {
342
+ try {
343
+ if (!keepsNotes(dir))
344
+ return null;
345
+ const ti = input?.tool_input ?? {};
346
+ const path = typeof ti.file_path === 'string' ? ti.file_path : typeof ti.notebook_path === 'string' ? ti.notebook_path : null;
347
+ let touch;
348
+ if (path) {
349
+ const rel = relative(dir, isAbsolute(path) ? path : join(dir, path)).replace(/\\/g, '/');
350
+ if (!rel || rel.startsWith('..') || underJulius(dir, path))
351
+ return null;
352
+ touch = { file: rel, verb: input?.tool_name === 'Read' ? 'opened' : 'changed' };
353
+ }
354
+ else if (typeof ti.command === 'string' && ti.command && !commandInvokesJulius(ti.command)) {
355
+ touch = { command: ti.command };
356
+ }
357
+ else
358
+ return null;
359
+ const notes = liveLearnings(listNotes(dir, { branches: false }));
360
+ if (!notes.length)
361
+ return null;
362
+ const id = input?.session_id || 'default';
363
+ const s = readSession(dir, id);
364
+ const text = notesOnTouch(notes, touch, s);
365
+ if (text)
366
+ writeSession(dir, id, s);
367
+ return text;
368
+ }
369
+ catch {
370
+ // A learning that doesn't arrive costs one reminder; a broken hook costs the turn.
371
+ return null;
372
+ }
373
+ }
374
+ /**
375
+ * Classify a tool use and, only when it could carry a julius footer, parse the
376
+ * savings out of its (lazily-serialised) output.
377
+ *
378
+ * Source reads (Read/Grep/Glob) never print a `[julius]` footer, and their output
379
+ * is a whole file or every match — serialising and regexing that on every read
380
+ * is the expensive, pointless case the widened PostToolUse matcher would
381
+ * otherwise hit. So skip `payload()` entirely for them. For anything else, a
382
+ * footer is itself proof julius ran (a bare `Bash julius …` the name couldn't
383
+ * classify), so its presence upgrades the kind to 'julius'.
384
+ */
385
+ function classifyAndScore(toolName, command, payload) {
386
+ let kind = classifyToolUse(toolName, command);
387
+ if (kind === 'source')
388
+ return { kind, savedTokens: 0 };
389
+ const savedTokens = parseSavings(JSON.stringify(payload() ?? ''));
390
+ if (savedTokens > 0)
391
+ kind = 'julius';
392
+ return { kind, savedTokens };
393
+ }
394
+ /**
395
+ * Cursor `postToolUse` (https://cursor.com/docs/hooks). Same job as
396
+ * {@link handleToolUse} but over Cursor's payload shape: `tool_output` holds the
397
+ * JSON-stringified result (a Shell `julius …` call's footer lives in its stdout),
398
+ * and the session key is `conversation_id`. MCP julius calls are skipped here —
399
+ * `afterMCPExecution` owns them, and counting both would double the julius tally.
400
+ * The skip covers both the prefixed (`MCP:julius_find_code`) and bare
401
+ * (`julius_find_code`) tool-name shapes, so the guard — not just the installed
402
+ * matcher — is what prevents the double count.
403
+ */
404
+ function handleCursorPostTool(input, dir) {
405
+ const toolName = String(input?.tool_name ?? '');
406
+ if (isMcpToolName(toolName) || isJuliusMcpTool(toolName))
407
+ return; // handled by handleCursorMcp
408
+ const command = input?.tool_input?.command ?? input?.tool_input?.cmd;
409
+ recordToolUse(dir, cursorSessionId(input), { ...classifyAndScore(toolName, command, () => input?.tool_output ?? input?.tool_response ?? input), host: 'cursor' });
410
+ }
411
+ /**
412
+ * Cursor `afterMCPExecution`: fires only for MCP tools, so a julius tool is
413
+ * recognised by its name and its savings read out of `result_json`. This is the
414
+ * one place julius MCP calls are counted for Cursor.
415
+ */
416
+ function handleCursorMcp(input, dir) {
417
+ const toolName = String(input?.tool_name ?? '');
418
+ if (!isJuliusMcpTool(toolName))
419
+ return;
420
+ const savedTokens = parseSavings(JSON.stringify(input?.result_json ?? input?.result ?? input ?? ''));
421
+ recordToolUse(dir, cursorSessionId(input), { kind: 'julius', savedTokens, host: 'cursor' });
422
+ }
423
+ /** Cursor keys a chat by `conversation_id` (its `session_id` equivalent). */
424
+ function cursorSessionId(input) {
425
+ return input?.conversation_id || input?.session_id || 'default';
426
+ }
427
+ /**
428
+ * At turn end: what did this turn's input tokens actually cost?
429
+ *
430
+ * Deliberately ungated, unlike {@link countTallyTurn}: the blended rate has to
431
+ * describe the session, and julius turns are not a fair sample of it — they are
432
+ * the long, tool-heavy, cache-warm ones. Sampling only those would report a
433
+ * cheaper token than the session really pays.
434
+ *
435
+ * Accumulates the pair, never the ratio, so the rate re-blends every turn. A
436
+ * turn already billed (a duplicate Stop, or a Stop racing the transcript write)
437
+ * is skipped on its uuid.
438
+ */
439
+ function sampleTurnCost(input, dir) {
440
+ try {
441
+ const id = input?.session_id || 'default';
442
+ const billing = lastTurnBilling(input?.transcript_path);
443
+ if (!billing)
444
+ return;
445
+ const s = readSession(dir, id);
446
+ if (billing.uuid === s.lastBillingUuid)
447
+ return;
448
+ s.inputCostMicros = (s.inputCostMicros ?? 0) + billing.costMicros;
449
+ s.inputTokensBilled = (s.inputTokensBilled ?? 0) + billing.tokens;
450
+ s.lastBillingUuid = billing.uuid;
451
+ writeSession(dir, id, s);
452
+ }
453
+ catch {
454
+ // A billing estimate is never worth failing the graph sync over.
455
+ }
456
+ }
457
+ /**
458
+ * At turn end: did the reply the user just read say what julius saved?
459
+ *
460
+ * Runs only on turns the tool-savings hook flagged, so a conversational turn
461
+ * costs nothing. A turn we cannot observe — a host whose Stop hook names no
462
+ * transcript, an unreadable file, or a Stop that fires before the final prose
463
+ * is on disk — is counted in NEITHER total: the ratio these two numbers form
464
+ * has to mean "of the turns we could check", not "of the turns we tried to".
465
+ */
466
+ function countTallyTurn(input, dir) {
467
+ try {
468
+ const id = input?.session_id || 'default';
469
+ const s = readSession(dir, id);
470
+ if (!s.turnUsedJulius)
471
+ return;
472
+ const turn = lastAssistantTurn(input?.transcript_path);
473
+ // Same reply as last time we looked: no new prose has landed, so this Stop
474
+ // is a duplicate or a race with the transcript write. Drop the turn rather
475
+ // than judge it on a stale message.
476
+ if (!turn || turn.uuid === s.lastTallyUuid) {
477
+ writeSession(dir, id, { ...s, turnUsedJulius: false });
478
+ return;
479
+ }
480
+ s.juliusTurns = (s.juliusTurns ?? 0) + 1;
481
+ if (hasSavingsTally(turn.text))
482
+ s.reportedTurns = (s.reportedTurns ?? 0) + 1;
483
+ s.turnUsedJulius = false;
484
+ s.lastTallyUuid = turn.uuid;
485
+ writeSession(dir, id, s);
486
+ }
487
+ catch {
488
+ // A turn-end metric is never worth failing the graph sync over.
489
+ }
490
+ }
491
+ /** Tool calls in one turn before it counts as digging worth a note. */
492
+ export const NOTE_WORTHY_CALLS = 3;
493
+ /**
494
+ * Reading that julius's answers stood in for, in one turn, before it counts as
495
+ * digging too. julius answers most questions in one or two calls, so on calls
496
+ * alone an exploratory turn never qualified and its findings were never saved.
497
+ */
498
+ export const NOTE_WORTHY_TOKENS = 30_000;
499
+ /** The reading a query stood in for, from its `[julius] tokens saved ≈ N` line. A
500
+ * reused learning's own line doesn't count: that digging was done before. */
501
+ function codeReadIn(content) {
502
+ const text = typeof content === 'string' ? content : Array.isArray(content) ? content.map((c) => (typeof c?.text === 'string' ? c.text : '')).join('\n') : '';
503
+ let total = 0;
504
+ for (const m of text.matchAll(/\[(?:julius)\] tokens saved ≈ ([\d,]+)/g))
505
+ total += Number(m[1].replace(/,/g, '')) || 0;
506
+ return total;
507
+ }
508
+ /** What the agent is told when a turn took real digging and left no note. */
509
+ export const NOTE_ASK = '[julius] This took real digging and the session has saved no learning. Before you finish, save one for the next session: ' +
510
+ '`julius note --title "<what it was about>"` with the text on stdin, under ## Decided, ## Tried and ruled out and ## Watch out. ' +
511
+ "A summary, never a transcript, and nothing secret. If you've committed this work, commit the learning too. Then finish as julius's output asks, if it asks anything.";
512
+ /**
513
+ * Whether the turn that just ended deserves a note: since the person's last
514
+ * message it made at least NOTE_WORTHY_CALLS tool calls, or julius's answers in
515
+ * it stood in for at least NOTE_WORTHY_TOKENS of reading; and nothing in the
516
+ * session has run `julius note` yet. Pure, for tests: `text` is the
517
+ * transcript's JSONL.
518
+ */
519
+ export function turnWantsNote(text) {
520
+ let calls = 0;
521
+ let codeRead = 0;
522
+ for (const line of text.split('\n')) {
523
+ if (!line.trim())
524
+ continue;
525
+ let e;
526
+ try {
527
+ e = JSON.parse(line);
528
+ }
529
+ catch {
530
+ continue;
531
+ }
532
+ const content = e?.message?.content;
533
+ const blocks = Array.isArray(content) ? content : [];
534
+ // A message the person typed starts a new turn; a tool result does not.
535
+ if (e?.type === 'user' && (typeof content === 'string' || blocks.some((b) => b?.type === 'text'))) {
536
+ calls = 0;
537
+ codeRead = 0;
538
+ }
539
+ for (const b of blocks) {
540
+ if (b?.type === 'tool_result')
541
+ codeRead += codeReadIn(b.content);
542
+ if (b?.type !== 'tool_use')
543
+ continue;
544
+ if (typeof b.input?.command === 'string' && NOTE_CALL.test(b.input.command))
545
+ return false;
546
+ calls++;
547
+ }
548
+ }
549
+ return calls >= NOTE_WORTHY_CALLS || codeRead >= NOTE_WORTHY_TOKENS;
550
+ }
551
+ /**
552
+ * Under julius, a turn that took real digging and left no note is asked once
553
+ * per session to leave one, by blocking the stop with the reason. The agent
554
+ * then saves the note, and julius's output carries on from there (the sign-in
555
+ * link, when one is due). Never blocks twice in a row: Claude Code sets
556
+ * `stop_hook_active` on the stop that follows a block.
557
+ */
558
+ function askForNote(input, dir) {
559
+ try {
560
+ if (input?.stop_hook_active || !input?.transcript_path || !keepsNotes(dir))
561
+ return;
562
+ const id = input?.session_id || 'default';
563
+ const s = readSession(dir, id);
564
+ const asked = s.noteSignalKeys ?? [];
565
+ if (asked.length >= NOTE_ASKS_PER_SESSION)
566
+ return;
567
+ const next = noteSignals(readFileSync(input.transcript_path, 'utf8'), dir).find((signal) => !asked.includes(signal.key));
568
+ if (!next)
569
+ return;
570
+ writeSession(dir, id, { ...s, noteAsked: true, noteSignalKeys: [...asked, next.key] });
571
+ process.stdout.write(JSON.stringify({ decision: 'block', reason: noteAsk(next) }));
572
+ }
573
+ catch {
574
+ // A missed reminder costs one note; a broken Stop hook costs the session.
575
+ }
576
+ }
577
+ function handleStop(input, dir) {
578
+ sampleTurnCost(input, dir);
579
+ countTallyTurn(input, dir);
580
+ // sync-run.js ships next to this module inside the package, so it resolves in
581
+ // any repo that installs julius (not just julius's own). Defensive existsSync:
582
+ // if the package is somehow incomplete, skip rather than wedge on syncing:true.
583
+ // JULIUS_TEST_SYNC_RUN is a test seam (mirrors JULIUS_TEST_STDIN) so tests can point
584
+ // this at a stub file inside their own sandbox instead of writing into src/claude/.
585
+ const syncRun = process.env.JULIUS_TEST_SYNC_RUN ?? claudeScriptPath('sync-run.js');
586
+ if (!existsSync(syncRun))
587
+ return;
588
+ const stats = readStats(dir);
589
+ if (stats?.dirty && acquireLock(dir)) {
590
+ patchStats(dir, { syncing: true });
591
+ const child = spawn(process.execPath, [syncRun, dir], { detached: true, stdio: 'ignore', windowsHide: true });
592
+ child.unref();
593
+ }
594
+ }
595
+ const DAY_MS = 24 * 60 * 60 * 1000;
596
+ /**
597
+ * Once a day per repo, the `repo_seen` event: whether `.julius/` is committed
598
+ * here, how many learnings it holds, and whether this machine shares the repo
599
+ * with a workspace. Queued only, like every hook's telemetry.
600
+ */
601
+ export function trackRepoSeen(dir, now = Date.now()) {
602
+ try {
603
+ const place = repoPlace(dir);
604
+ if (!place.git)
605
+ return;
606
+ const mark = join(cacheDir(place.checkout), 'julius-repo-seen.json');
607
+ if (now - (readJson(mark)?.at ?? 0) < DAY_MS)
608
+ return;
609
+ writeJsonAtomic(mark, { at: now }, true);
610
+ const tracked = execFileSync('git', ['ls-files', '--', '.julius'], { cwd: place.checkout, encoding: 'utf8', stdio: ['ignore', 'pipe', 'ignore'], timeout: 3000 });
611
+ track('repo_seen', { julius_committed: String(tracked.trim().length > 0), learnings_bucket: countBucket(learningFiles(place.checkout).length), workspace: String(inWorkspace(place.checkout)) }, { repo: place.checkout });
612
+ }
613
+ catch {
614
+ // A missed sighting undercounts one repo for one day.
615
+ }
616
+ }
617
+ /**
618
+ * When the learnings committed on this checkout's HEAD went up since the last
619
+ * session here: how many came in and how many there are, as buckets. A repo
620
+ * with committed learnings is where julius starts paying off, so this is the
621
+ * activation count. `first_look` marks the first time this clone is seen, so
622
+ * a clone of a repo that already had them isn't counted as new ones.
623
+ */
624
+ export function trackLearningsCommitted(dir) {
625
+ try {
626
+ const place = repoPlace(dir);
627
+ if (!place.git)
628
+ return;
629
+ const listed = execFileSync('git', ['ls-tree', '-r', '--name-only', 'HEAD', '--', '.julius/learnings'], {
630
+ cwd: place.checkout, encoding: 'utf8', stdio: ['ignore', 'pipe', 'ignore'], timeout: 3000,
631
+ });
632
+ const count = listed.split('\n').filter((f) => f.endsWith('.md')).length;
633
+ const mark = join(cacheDir(place.checkout), 'julius-learnings-committed.json');
634
+ const before = readJson(mark)?.count;
635
+ if (before === count)
636
+ return;
637
+ writeJsonAtomic(mark, { count }, true);
638
+ if (count <= (before ?? 0))
639
+ return;
640
+ track('learnings_committed', { added_bucket: countBucket(count - (before ?? 0)), total_bucket: countBucket(count), first_look: String(before === undefined) }, { repo: place.checkout });
641
+ }
642
+ catch {
643
+ // Not a repo with a HEAD yet, or git is slow: counted next session.
644
+ }
645
+ }
646
+ /**
647
+ * Team learnings sitting uncommitted in `.julius/learnings/` (from julius init's
648
+ * read of past sessions, or a session that ended before committing) reach no
649
+ * teammate. Once a day per repo, the first reply says so, with the line that
650
+ * makes the case for committing them. Empty when everything is committed.
651
+ */
652
+ export function uncommittedDirective(dir, now = Date.now()) {
653
+ try {
654
+ const place = repoPlace(dir);
655
+ if (!place.git)
656
+ return '';
657
+ const status = execFileSync('git', ['status', '--porcelain', '--untracked-files=all', '--', '.julius/learnings'], {
658
+ cwd: place.checkout, encoding: 'utf8', stdio: ['ignore', 'pipe', 'ignore'], timeout: 3000,
659
+ });
660
+ const n = status.split('\n').filter((l) => l.trimEnd().endsWith('.md')).length;
661
+ const setup = setupUncommitted(place.checkout);
662
+ if (!n && !setup)
663
+ return '';
664
+ const mark = join(cacheDir(place.checkout), 'julius-uncommitted-said.json');
665
+ if (now - (readJson(mark)?.at ?? 0) < DAY_MS)
666
+ return '';
667
+ writeJsonAtomic(mark, { at: now }, true);
668
+ if (setup) {
669
+ const line = setupCommitLine(teammatesOn(place.checkout));
670
+ return `${tag()} julius's shared setup here (.julius/ and .claude/settings.json) isn't committed yet, so teammates' Claude can't read the learnings. Say so once, at the end of your first reply, with this line, word for word: ${line}\n`;
671
+ }
672
+ const line = commitLines({}, teammatesOn(place.checkout), 'repo').uncommitted;
673
+ const them = n === 1 ? "learning in .julius/learnings/ isn't committed yet, so no teammate's agent has it" : `learnings in .julius/learnings/ aren't committed yet, so no teammate's agent has them`;
674
+ return `${tag()} ${n} team ${them}. Say so once, at the end of your first reply, with this line, word for word: ${line}\n`;
675
+ }
676
+ catch {
677
+ return '';
678
+ }
679
+ }
680
+ /**
681
+ * julius's shared setup isn't in the last commit: `.julius/hook.cjs` isn't
682
+ * tracked, or HEAD's `.claude/settings.json` doesn't run it. Only checked
683
+ * where the hook is on disk, so a repo still set up the old way says nothing.
684
+ */
685
+ export function setupUncommitted(checkout) {
686
+ if (!existsSync(join(checkout, '.julius', 'hook.cjs')))
687
+ return false;
688
+ const git = (args) => execFileSync('git', args, { cwd: checkout, encoding: 'utf8', stdio: ['ignore', 'pipe', 'ignore'], timeout: 3000 });
689
+ try {
690
+ git(['ls-files', '--error-unmatch', '--', '.julius/hook.cjs']);
691
+ }
692
+ catch {
693
+ return true;
694
+ }
695
+ try {
696
+ return !git(['show', 'HEAD:.claude/settings.json']).includes('/.julius/hook.cjs');
697
+ }
698
+ catch {
699
+ return true;
700
+ }
701
+ }
702
+ /** The most the session-start hook waits on `git fetch` for teammates' branches. */
703
+ export const BRANCH_FETCH_CAP_MS = 3000;
704
+ /**
705
+ * At session start, under julius: read what teammates have pushed, so the
706
+ * session's first prompt already knows their learnings and where their work
707
+ * overlaps; send any learnings and uses the workspace hasn't seen; and count
708
+ * the repo once a day. The fetch is the one wait, capped at
709
+ * BRANCH_FETCH_CAP_MS and skipped when the branches were read in the last
710
+ * minute; a fetch that runs out of time still reads the branches already here.
711
+ * The sync only spawns a detached child.
712
+ */
713
+ function juliusAtStart(dir) {
714
+ if (!keepsNotes(dir))
715
+ return;
716
+ try {
717
+ const top = repoPlace(dir);
718
+ if (top.git && branchesStale(top.checkout, Date.now(), SESSION_REFRESH_MS))
719
+ refreshBranches(top.checkout, { fetchTimeoutMs: BRANCH_FETCH_CAP_MS });
720
+ }
721
+ catch {
722
+ // Without it, the first prompt sees what the last refresh saw.
723
+ }
724
+ maybeSyncInBackground(dir);
725
+ trackRepoSeen(dir);
726
+ trackLearningsCommitted(dir);
727
+ }
728
+ /** The repo's committed `.mcp.json` still registers julius's server (set up before 0.23). */
729
+ function repoNamesJuliusServer(dir) {
730
+ try {
731
+ return Boolean(JSON.parse(readFileSync(join(dir, '.mcp.json'), 'utf8'))?.mcpServers?.julius);
732
+ }
733
+ catch {
734
+ return false;
735
+ }
736
+ }
737
+ export async function main(event) {
738
+ // julius's own headless Claude calls (the first-run read of past sessions) run with this set.
739
+ if (process.env.JULIUS_NO_HOOKS === '1')
740
+ return;
741
+ // Registered in the repo and in ~/.claude, Claude Code runs both: one answers.
742
+ if (globalCopyCovers(event, process.argv[1]))
743
+ return;
744
+ const input = readStdin();
745
+ const dir = projectDir(input);
746
+ adoptRepoBrand(dir, process.env, hostsWiredForJulius);
747
+ if (event === 'session-start') {
748
+ // Before anything is emitted: refresh this repo's wiring if it was written by
749
+ // an older julius, and pick up any cached "newer version on npm" answer.
750
+ // background:false — the registry check stays off the network here; the CLI
751
+ // and the MCP server fill that cache, this only reads it.
752
+ const upkeep = runUpkeep(dir, runningVersion(), { background: false }).lines;
753
+ // Roll up any session that ended since we were last here, then send the
754
+ // queue from a detached child: what session end didn't get to (a killed
755
+ // terminal never fires it) goes now. Once a day at most, never waited on.
756
+ flushClosedSessions(dir);
757
+ maybeFlushInBackground();
758
+ juliusAtStart(dir);
759
+ try {
760
+ const idx = readFileSync(join(resolveContextDir(dir), 'INDEX.md'), 'utf8');
761
+ const banner = staleBanner(indexFreshness(dir)) ?? undefined;
762
+ const kept = keepsNotes(dir);
763
+ const skills = kept ? skillsDirective(dir, cmd('julius skills show')) : '';
764
+ const underJulius = kept && true;
765
+ const standing = underJulius ? standingDirective(standingLearnings(dir)) + uncommittedDirective(dir) : '';
766
+ const mapDir = relative(dir, resolveContextDir(dir)).split('\\').join('/') || 'julius';
767
+ const orientation = formatOrientation(idx, undefined, banner, noteCount(dir), kept, skills + standing, mapDir);
768
+ emit('SessionStart', upkeep.length ? `${upkeep.join('\n')}\n\n${orientation}` : orientation);
769
+ }
770
+ catch {
771
+ // No INDEX.md (never built here). An upgrade nudge is still worth saying.
772
+ if (upkeep.length)
773
+ emit('SessionStart', upkeep.join('\n'));
774
+ }
775
+ return;
776
+ }
777
+ // Claude closing: send the queue from a detached child, so quitting isn't slowed.
778
+ if (event === 'session-end') {
779
+ maybeFlushInBackground();
780
+ return;
781
+ }
782
+ if (event === 'post-edit') {
783
+ await handlePostEdit(input, dir);
784
+ return;
785
+ }
786
+ if (event === 'tool-savings') {
787
+ handleToolUse(input, dir);
788
+ return;
789
+ }
790
+ if (event === 'cursor-post-tool') {
791
+ handleCursorPostTool(input, dir);
792
+ return;
793
+ }
794
+ if (event === 'cursor-mcp') {
795
+ handleCursorMcp(input, dir);
796
+ return;
797
+ }
798
+ // Cursor closes a chat: force-close THIS conversation into a bucketed
799
+ // `session_summary` now (its file's mtime is fresh, so the idle sweep would
800
+ // skip it). Attributed to Cursor. The idle sweep stays on Claude's
801
+ // session-start, whose Stop fires per turn and so has no real end signal.
802
+ if (event === 'cursor-session-end') {
803
+ summarizeSession(dir, cursorSessionId(input), { host: 'cursor' });
804
+ return;
805
+ }
806
+ if (event === 'stop') {
807
+ handleStop(input, dir);
808
+ askForNote(input, dir);
809
+ return;
810
+ }
811
+ if (event === 'post-edit-sync') {
812
+ await handlePostEdit(input, dir);
813
+ handleStop(input, dir);
814
+ return;
815
+ }
816
+ if (event === 'prompt') {
817
+ const prompt = String(input?.prompt ?? '').trim();
818
+ if (prompt.length < MIN_PROMPT_CHARS || prompt.startsWith('<task-notification>'))
819
+ return;
820
+ // Pointers-only, small, gated. No --source: per-prompt injected tokens are
821
+ // fresh full-price input on every turn (unlike the cached SessionStart
822
+ // orientation), so the pack carries locators, never inlined code — the agent
823
+ // pulls spans itself via `julius ask --source` when a pointer looks right.
824
+ // relevantRetrieval then drops the pack entirely when the prompt barely
825
+ // overlaps the top hit or when every hit was already injected this session.
826
+ const askArgs = withContextDirArg(dir, ['ask', prompt, '.', '--json', '-n', '3']);
827
+ // "You're working in backend/, weight it": only fires on a multi-scope
828
+ // repo whose lastFile resolves cleanly to one scope — see lastFileScopeHint.
829
+ const scopeHint = lastFileScopeHint(dir, readStats(dir)?.lastFile);
830
+ if (scopeHint)
831
+ askArgs.push('--in', scopeHint);
832
+ const ask = juliusJson(dir, askArgs, promptAskTimeout(dir));
833
+ if (!ask)
834
+ return;
835
+ const id = input.session_id || 'default';
836
+ const s = readSession(dir, id);
837
+ s.lastQuery = prompt;
838
+ const agent = input?.agent?.name;
839
+ if (agent)
840
+ s.perAgentQuery[agent] = prompt;
841
+ // Learnings first: what an earlier session worked out matters more than where code is.
842
+ const notes = notesForPrompt(ask, s);
843
+ const txt = [notes, relevantRetrieval(ask, s)].filter(Boolean).join('\n\n');
844
+ if (txt)
845
+ emit('UserPromptSubmit', txt);
846
+ writeSession(dir, id, s);
847
+ }
848
+ }
849
+ //# sourceMappingURL=hooks.js.map