@nanonets/graft 0.24.0 → 0.25.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (791) hide show
  1. package/README.md +26 -21
  2. package/dist/ask/ask.d.ts +8 -0
  3. package/dist/ask/ask.d.ts.map +1 -1
  4. package/dist/ask/ask.js +33 -12
  5. package/dist/ask/ask.js.map +1 -1
  6. package/dist/blast/render.js +1 -1
  7. package/dist/blast/render.js.map +1 -1
  8. package/dist/brand.js +1 -1
  9. package/dist/brand.js.map +1 -1
  10. package/dist/check/learning-edits.d.ts +18 -3
  11. package/dist/check/learning-edits.d.ts.map +1 -1
  12. package/dist/check/learning-edits.js +54 -10
  13. package/dist/check/learning-edits.js.map +1 -1
  14. package/dist/check/local-check.d.ts +7 -3
  15. package/dist/check/local-check.d.ts.map +1 -1
  16. package/dist/check/local-check.js +55 -11
  17. package/dist/check/local-check.js.map +1 -1
  18. package/dist/check/types.d.ts +11 -2
  19. package/dist/check/types.d.ts.map +1 -1
  20. package/dist/claude/format.d.ts +11 -7
  21. package/dist/claude/format.d.ts.map +1 -1
  22. package/dist/claude/format.js +50 -28
  23. package/dist/claude/format.js.map +1 -1
  24. package/dist/claude/hook-io.d.ts +44 -0
  25. package/dist/claude/hook-io.d.ts.map +1 -0
  26. package/dist/claude/hook-io.js +144 -0
  27. package/dist/claude/hook-io.js.map +1 -0
  28. package/dist/claude/hook-layers.d.ts +4 -2
  29. package/dist/claude/hook-layers.d.ts.map +1 -1
  30. package/dist/claude/hook-layers.js +21 -4
  31. package/dist/claude/hook-layers.js.map +1 -1
  32. package/dist/claude/hooks.d.ts +9 -32
  33. package/dist/claude/hooks.d.ts.map +1 -1
  34. package/dist/claude/hooks.js +154 -350
  35. package/dist/claude/hooks.js.map +1 -1
  36. package/dist/claude/init.d.ts.map +1 -1
  37. package/dist/claude/init.js +56 -18
  38. package/dist/claude/init.js.map +1 -1
  39. package/dist/claude/note-signals.d.ts +6 -0
  40. package/dist/claude/note-signals.d.ts.map +1 -1
  41. package/dist/claude/note-signals.js +14 -3
  42. package/dist/claude/note-signals.js.map +1 -1
  43. package/dist/claude/post-bash.d.ts +26 -0
  44. package/dist/claude/post-bash.d.ts.map +1 -0
  45. package/dist/claude/post-bash.js +191 -0
  46. package/dist/claude/post-bash.js.map +1 -0
  47. package/dist/claude/pre-bash-skills.d.ts +21 -0
  48. package/dist/claude/pre-bash-skills.d.ts.map +1 -0
  49. package/dist/claude/pre-bash-skills.js +253 -0
  50. package/dist/claude/pre-bash-skills.js.map +1 -0
  51. package/dist/claude/pre-bash.d.ts +50 -0
  52. package/dist/claude/pre-bash.d.ts.map +1 -0
  53. package/dist/claude/pre-bash.js +245 -0
  54. package/dist/claude/pre-bash.js.map +1 -0
  55. package/dist/claude/prompt-consent.d.ts +19 -0
  56. package/dist/claude/prompt-consent.d.ts.map +1 -0
  57. package/dist/claude/prompt-consent.js +14 -0
  58. package/dist/claude/prompt-consent.js.map +1 -0
  59. package/dist/claude/prompt-hook.d.ts +76 -0
  60. package/dist/claude/prompt-hook.d.ts.map +1 -0
  61. package/dist/claude/prompt-hook.js +303 -0
  62. package/dist/claude/prompt-hook.js.map +1 -0
  63. package/dist/claude/prompt-skills.d.ts +19 -0
  64. package/dist/claude/prompt-skills.d.ts.map +1 -0
  65. package/dist/claude/prompt-skills.js +305 -0
  66. package/dist/claude/prompt-skills.js.map +1 -0
  67. package/dist/claude/session-metrics.js +4 -4
  68. package/dist/claude/session-metrics.js.map +1 -1
  69. package/dist/claude/settings-merge.d.ts +10 -0
  70. package/dist/claude/settings-merge.d.ts.map +1 -1
  71. package/dist/claude/settings-merge.js +46 -17
  72. package/dist/claude/settings-merge.js.map +1 -1
  73. package/dist/claude/shim-template.d.ts.map +1 -1
  74. package/dist/claude/shim-template.js +86 -28
  75. package/dist/claude/shim-template.js.map +1 -1
  76. package/dist/claude/skill-template.d.ts +2 -0
  77. package/dist/claude/skill-template.d.ts.map +1 -1
  78. package/dist/claude/skill-template.js +53 -34
  79. package/dist/claude/skill-template.js.map +1 -1
  80. package/dist/claude/skill-use.d.ts +16 -0
  81. package/dist/claude/skill-use.d.ts.map +1 -0
  82. package/dist/claude/skill-use.js +78 -0
  83. package/dist/claude/skill-use.js.map +1 -0
  84. package/dist/claude/skills-hook-util.d.ts +25 -0
  85. package/dist/claude/skills-hook-util.d.ts.map +1 -0
  86. package/dist/claude/skills-hook-util.js +71 -0
  87. package/dist/claude/skills-hook-util.js.map +1 -0
  88. package/dist/claude/skills-wiring.d.ts +26 -0
  89. package/dist/claude/skills-wiring.d.ts.map +1 -0
  90. package/dist/claude/skills-wiring.js +110 -0
  91. package/dist/claude/skills-wiring.js.map +1 -0
  92. package/dist/claude/start-init.d.ts +13 -0
  93. package/dist/claude/start-init.d.ts.map +1 -0
  94. package/dist/claude/start-init.js +75 -0
  95. package/dist/claude/start-init.js.map +1 -0
  96. package/dist/claude/start-skills.d.ts +31 -0
  97. package/dist/claude/start-skills.d.ts.map +1 -0
  98. package/dist/claude/start-skills.js +274 -0
  99. package/dist/claude/start-skills.js.map +1 -0
  100. package/dist/claude/state.d.ts +19 -7
  101. package/dist/claude/state.d.ts.map +1 -1
  102. package/dist/claude/state.js +59 -4
  103. package/dist/claude/state.js.map +1 -1
  104. package/dist/claude/stop-skills.d.ts +23 -0
  105. package/dist/claude/stop-skills.d.ts.map +1 -0
  106. package/dist/claude/stop-skills.js +233 -0
  107. package/dist/claude/stop-skills.js.map +1 -0
  108. package/dist/claude/stop.d.ts +23 -0
  109. package/dist/claude/stop.d.ts.map +1 -0
  110. package/dist/claude/stop.js +219 -0
  111. package/dist/claude/stop.js.map +1 -0
  112. package/dist/claude/tally.d.ts +29 -41
  113. package/dist/claude/tally.d.ts.map +1 -1
  114. package/dist/claude/tally.js +111 -165
  115. package/dist/claude/tally.js.map +1 -1
  116. package/dist/claude/walls-hook.d.ts +52 -0
  117. package/dist/claude/walls-hook.d.ts.map +1 -0
  118. package/dist/claude/walls-hook.js +279 -0
  119. package/dist/claude/walls-hook.js.map +1 -0
  120. package/dist/cli-epilogue.d.ts.map +1 -1
  121. package/dist/cli-epilogue.js +24 -14
  122. package/dist/cli-epilogue.js.map +1 -1
  123. package/dist/cli-meta.js +3 -3
  124. package/dist/cli-meta.js.map +1 -1
  125. package/dist/cli-picker.d.ts +24 -0
  126. package/dist/cli-picker.d.ts.map +1 -1
  127. package/dist/cli-picker.js +44 -11
  128. package/dist/cli-picker.js.map +1 -1
  129. package/dist/cli.d.ts.map +1 -1
  130. package/dist/cli.js +475 -390
  131. package/dist/cli.js.map +1 -1
  132. package/dist/cloud/head-learnings.d.ts +13 -0
  133. package/dist/cloud/head-learnings.d.ts.map +1 -0
  134. package/dist/cloud/head-learnings.js +84 -0
  135. package/dist/cloud/head-learnings.js.map +1 -0
  136. package/dist/cloud/lookup-activity.d.ts +18 -0
  137. package/dist/cloud/lookup-activity.d.ts.map +1 -0
  138. package/dist/cloud/lookup-activity.js +56 -0
  139. package/dist/cloud/lookup-activity.js.map +1 -0
  140. package/dist/cloud/nudge.d.ts +15 -7
  141. package/dist/cloud/nudge.d.ts.map +1 -1
  142. package/dist/cloud/nudge.js +45 -33
  143. package/dist/cloud/nudge.js.map +1 -1
  144. package/dist/cloud/onboarding.d.ts +273 -0
  145. package/dist/cloud/onboarding.d.ts.map +1 -0
  146. package/dist/cloud/onboarding.js +612 -0
  147. package/dist/cloud/onboarding.js.map +1 -0
  148. package/dist/cloud/other-repos.d.ts +39 -0
  149. package/dist/cloud/other-repos.d.ts.map +1 -0
  150. package/dist/cloud/other-repos.js +137 -0
  151. package/dist/cloud/other-repos.js.map +1 -0
  152. package/dist/cloud/pair.d.ts +86 -0
  153. package/dist/cloud/pair.d.ts.map +1 -0
  154. package/dist/cloud/pair.js +270 -0
  155. package/dist/cloud/pair.js.map +1 -0
  156. package/dist/cloud/workspace-sync.d.ts +75 -11
  157. package/dist/cloud/workspace-sync.d.ts.map +1 -1
  158. package/dist/cloud/workspace-sync.js +409 -53
  159. package/dist/cloud/workspace-sync.js.map +1 -1
  160. package/dist/cloud/workspace.d.ts +95 -10
  161. package/dist/cloud/workspace.d.ts.map +1 -1
  162. package/dist/cloud/workspace.js +112 -9
  163. package/dist/cloud/workspace.js.map +1 -1
  164. package/dist/graph/native.d.ts +2 -0
  165. package/dist/graph/native.d.ts.map +1 -1
  166. package/dist/graph/native.js +29 -4
  167. package/dist/graph/native.js.map +1 -1
  168. package/dist/hosts/claude-global.d.ts +14 -0
  169. package/dist/hosts/claude-global.d.ts.map +1 -1
  170. package/dist/hosts/claude-global.js +39 -4
  171. package/dist/hosts/claude-global.js.map +1 -1
  172. package/dist/hosts/codex-hooks.d.ts +6 -0
  173. package/dist/hosts/codex-hooks.d.ts.map +1 -1
  174. package/dist/hosts/codex-hooks.js +89 -16
  175. package/dist/hosts/codex-hooks.js.map +1 -1
  176. package/dist/hosts/codex-trust.d.ts +28 -0
  177. package/dist/hosts/codex-trust.d.ts.map +1 -0
  178. package/dist/hosts/codex-trust.js +280 -0
  179. package/dist/hosts/codex-trust.js.map +1 -0
  180. package/dist/hosts/cursor-hooks.d.ts.map +1 -1
  181. package/dist/hosts/cursor-hooks.js +3 -1
  182. package/dist/hosts/cursor-hooks.js.map +1 -1
  183. package/dist/init/candidates.d.ts +60 -0
  184. package/dist/init/candidates.d.ts.map +1 -0
  185. package/dist/init/candidates.js +202 -0
  186. package/dist/init/candidates.js.map +1 -0
  187. package/dist/init/claude-call.d.ts +51 -0
  188. package/dist/init/claude-call.d.ts.map +1 -0
  189. package/dist/init/claude-call.js +199 -0
  190. package/dist/init/claude-call.js.map +1 -0
  191. package/dist/init/discover-worker.d.ts +18 -0
  192. package/dist/init/discover-worker.d.ts.map +1 -0
  193. package/dist/init/discover-worker.js +111 -0
  194. package/dist/init/discover-worker.js.map +1 -0
  195. package/dist/init/handover.d.ts +16 -0
  196. package/dist/init/handover.d.ts.map +1 -0
  197. package/dist/init/handover.js +92 -0
  198. package/dist/init/handover.js.map +1 -0
  199. package/dist/init/howtos.d.ts +20 -0
  200. package/dist/init/howtos.d.ts.map +1 -0
  201. package/dist/init/howtos.js +90 -0
  202. package/dist/init/howtos.js.map +1 -0
  203. package/dist/init/init-record.d.ts +134 -0
  204. package/dist/init/init-record.d.ts.map +1 -0
  205. package/dist/init/init-record.js +339 -0
  206. package/dist/init/init-record.js.map +1 -0
  207. package/dist/init/install-paths.d.ts +6 -0
  208. package/dist/init/install-paths.d.ts.map +1 -0
  209. package/dist/init/install-paths.js +87 -0
  210. package/dist/init/install-paths.js.map +1 -0
  211. package/dist/init/install-record.d.ts +21 -0
  212. package/dist/init/install-record.d.ts.map +1 -0
  213. package/dist/init/install-record.js +144 -0
  214. package/dist/init/install-record.js.map +1 -0
  215. package/dist/init/keep-answer.d.ts +43 -0
  216. package/dist/init/keep-answer.d.ts.map +1 -0
  217. package/dist/init/keep-answer.js +118 -0
  218. package/dist/init/keep-answer.js.map +1 -0
  219. package/dist/init/keep-gate.d.ts +30 -0
  220. package/dist/init/keep-gate.d.ts.map +1 -0
  221. package/dist/init/keep-gate.js +178 -0
  222. package/dist/init/keep-gate.js.map +1 -0
  223. package/dist/init/keep-list.d.ts +67 -0
  224. package/dist/init/keep-list.d.ts.map +1 -0
  225. package/dist/init/keep-list.js +232 -0
  226. package/dist/init/keep-list.js.map +1 -0
  227. package/dist/init/keep.d.ts +52 -0
  228. package/dist/init/keep.d.ts.map +1 -0
  229. package/dist/init/keep.js +393 -0
  230. package/dist/init/keep.js.map +1 -0
  231. package/dist/init/look-back-mine.d.ts +37 -0
  232. package/dist/init/look-back-mine.d.ts.map +1 -0
  233. package/dist/init/look-back-mine.js +215 -0
  234. package/dist/init/look-back-mine.js.map +1 -0
  235. package/dist/init/look-back.d.ts +81 -0
  236. package/dist/init/look-back.d.ts.map +1 -0
  237. package/dist/init/look-back.js +170 -0
  238. package/dist/init/look-back.js.map +1 -0
  239. package/dist/init/miners.d.ts +46 -0
  240. package/dist/init/miners.d.ts.map +1 -0
  241. package/dist/init/miners.js +141 -0
  242. package/dist/init/miners.js.map +1 -0
  243. package/dist/init/name-call.d.ts +37 -0
  244. package/dist/init/name-call.d.ts.map +1 -0
  245. package/dist/init/name-call.js +151 -0
  246. package/dist/init/name-call.js.map +1 -0
  247. package/dist/init/plain-file.d.ts +11 -0
  248. package/dist/init/plain-file.d.ts.map +1 -0
  249. package/dist/init/plain-file.js +83 -0
  250. package/dist/init/plain-file.js.map +1 -0
  251. package/dist/init/prefs.d.ts +70 -0
  252. package/dist/init/prefs.d.ts.map +1 -0
  253. package/dist/init/prefs.js +282 -0
  254. package/dist/init/prefs.js.map +1 -0
  255. package/dist/init/relay.d.ts +15 -0
  256. package/dist/init/relay.d.ts.map +1 -0
  257. package/dist/init/relay.js +15 -0
  258. package/dist/init/relay.js.map +1 -0
  259. package/dist/init/replay-runs.d.ts +121 -0
  260. package/dist/init/replay-runs.d.ts.map +1 -0
  261. package/dist/init/replay-runs.js +457 -0
  262. package/dist/init/replay-runs.js.map +1 -0
  263. package/dist/init/replay-tamper.d.ts +18 -0
  264. package/dist/init/replay-tamper.d.ts.map +1 -0
  265. package/dist/init/replay-tamper.js +87 -0
  266. package/dist/init/replay-tamper.js.map +1 -0
  267. package/dist/init/review-screen.d.ts +74 -0
  268. package/dist/init/review-screen.d.ts.map +1 -0
  269. package/dist/init/review-screen.js +258 -0
  270. package/dist/init/review-screen.js.map +1 -0
  271. package/dist/init/review-tty.d.ts +29 -0
  272. package/dist/init/review-tty.d.ts.map +1 -0
  273. package/dist/init/review-tty.js +218 -0
  274. package/dist/init/review-tty.js.map +1 -0
  275. package/dist/init/review.d.ts +12 -0
  276. package/dist/init/review.d.ts.map +1 -0
  277. package/dist/init/review.js +12 -0
  278. package/dist/init/review.js.map +1 -0
  279. package/dist/init/run.d.ts +87 -0
  280. package/dist/init/run.d.ts.map +1 -0
  281. package/dist/init/run.js +347 -0
  282. package/dist/init/run.js.map +1 -0
  283. package/dist/init/sessions.d.ts +63 -0
  284. package/dist/init/sessions.d.ts.map +1 -0
  285. package/dist/init/sessions.js +377 -0
  286. package/dist/init/sessions.js.map +1 -0
  287. package/dist/init/transcript.d.ts +81 -0
  288. package/dist/init/transcript.d.ts.map +1 -0
  289. package/dist/init/transcript.js +216 -0
  290. package/dist/init/transcript.js.map +1 -0
  291. package/dist/init/types.d.ts +139 -0
  292. package/dist/init/types.d.ts.map +1 -0
  293. package/dist/init/types.js +2 -0
  294. package/dist/init/types.js.map +1 -0
  295. package/dist/mcp/brains.d.ts +72 -0
  296. package/dist/mcp/brains.d.ts.map +1 -0
  297. package/dist/mcp/brains.js +220 -0
  298. package/dist/mcp/brains.js.map +1 -0
  299. package/dist/mcp/server.d.ts +3 -1
  300. package/dist/mcp/server.d.ts.map +1 -1
  301. package/dist/mcp/server.js +40 -5
  302. package/dist/mcp/server.js.map +1 -1
  303. package/dist/mcp/tools.d.ts.map +1 -1
  304. package/dist/mcp/tools.js +7 -2
  305. package/dist/mcp/tools.js.map +1 -1
  306. package/dist/notes/cold-start.d.ts +5 -184
  307. package/dist/notes/cold-start.d.ts.map +1 -1
  308. package/dist/notes/cold-start.js +5 -575
  309. package/dist/notes/cold-start.js.map +1 -1
  310. package/dist/notes/edit-overlap.d.ts.map +1 -1
  311. package/dist/notes/edit-overlap.js +4 -1
  312. package/dist/notes/edit-overlap.js.map +1 -1
  313. package/dist/notes/every-repo.d.ts +18 -0
  314. package/dist/notes/every-repo.d.ts.map +1 -0
  315. package/dist/notes/every-repo.js +86 -0
  316. package/dist/notes/every-repo.js.map +1 -0
  317. package/dist/notes/guardrails.d.ts +8 -0
  318. package/dist/notes/guardrails.d.ts.map +1 -0
  319. package/dist/notes/guardrails.js +38 -0
  320. package/dist/notes/guardrails.js.map +1 -0
  321. package/dist/notes/lesson-index.d.ts +13 -0
  322. package/dist/notes/lesson-index.d.ts.map +1 -0
  323. package/dist/notes/lesson-index.js +135 -0
  324. package/dist/notes/lesson-index.js.map +1 -0
  325. package/dist/notes/linked-learnings.d.ts +8 -0
  326. package/dist/notes/linked-learnings.d.ts.map +1 -0
  327. package/dist/notes/linked-learnings.js +113 -0
  328. package/dist/notes/linked-learnings.js.map +1 -0
  329. package/dist/notes/notes.d.ts +8 -4
  330. package/dist/notes/notes.d.ts.map +1 -1
  331. package/dist/notes/notes.js +9 -7
  332. package/dist/notes/notes.js.map +1 -1
  333. package/dist/notes/pr-reviews.d.ts +4 -0
  334. package/dist/notes/pr-reviews.d.ts.map +1 -1
  335. package/dist/notes/pr-reviews.js +6 -5
  336. package/dist/notes/pr-reviews.js.map +1 -1
  337. package/dist/notes/replace.d.ts +14 -0
  338. package/dist/notes/replace.d.ts.map +1 -0
  339. package/dist/notes/replace.js +38 -0
  340. package/dist/notes/replace.js.map +1 -0
  341. package/dist/notes/repo-notes-dir.d.ts +2 -0
  342. package/dist/notes/repo-notes-dir.d.ts.map +1 -0
  343. package/dist/notes/repo-notes-dir.js +16 -0
  344. package/dist/notes/repo-notes-dir.js.map +1 -0
  345. package/dist/notes/repo-trail.d.ts +1 -1
  346. package/dist/notes/repo-trail.d.ts.map +1 -1
  347. package/dist/notes/repo-trail.js +24 -4
  348. package/dist/notes/repo-trail.js.map +1 -1
  349. package/dist/search/grep.d.ts.map +1 -1
  350. package/dist/search/grep.js +4 -2
  351. package/dist/search/grep.js.map +1 -1
  352. package/dist/search/user-regexp.d.ts +26 -0
  353. package/dist/search/user-regexp.d.ts.map +1 -0
  354. package/dist/search/user-regexp.js +150 -0
  355. package/dist/search/user-regexp.js.map +1 -0
  356. package/dist/skills/anchors-cli.d.ts +38 -0
  357. package/dist/skills/anchors-cli.d.ts.map +1 -0
  358. package/dist/skills/anchors-cli.js +279 -0
  359. package/dist/skills/anchors-cli.js.map +1 -0
  360. package/dist/skills/anchors-git.d.ts +29 -0
  361. package/dist/skills/anchors-git.d.ts.map +1 -0
  362. package/dist/skills/anchors-git.js +241 -0
  363. package/dist/skills/anchors-git.js.map +1 -0
  364. package/dist/skills/anchors-wide.d.ts +25 -0
  365. package/dist/skills/anchors-wide.d.ts.map +1 -0
  366. package/dist/skills/anchors-wide.js +481 -0
  367. package/dist/skills/anchors-wide.js.map +1 -0
  368. package/dist/skills/anchors.d.ts +32 -0
  369. package/dist/skills/anchors.d.ts.map +1 -0
  370. package/dist/skills/anchors.js +485 -0
  371. package/dist/skills/anchors.js.map +1 -0
  372. package/dist/skills/check-result.d.ts +26 -0
  373. package/dist/skills/check-result.d.ts.map +1 -0
  374. package/dist/skills/check-result.js +46 -0
  375. package/dist/skills/check-result.js.map +1 -0
  376. package/dist/skills/cli-skills-1b.d.ts +17 -0
  377. package/dist/skills/cli-skills-1b.d.ts.map +1 -0
  378. package/dist/skills/cli-skills-1b.js +166 -0
  379. package/dist/skills/cli-skills-1b.js.map +1 -0
  380. package/dist/skills/cli-skills-2.d.ts +35 -0
  381. package/dist/skills/cli-skills-2.d.ts.map +1 -0
  382. package/dist/skills/cli-skills-2.js +129 -0
  383. package/dist/skills/cli-skills-2.js.map +1 -0
  384. package/dist/skills/cli-skills-report-1b.d.ts +49 -0
  385. package/dist/skills/cli-skills-report-1b.d.ts.map +1 -0
  386. package/dist/skills/cli-skills-report-1b.js +191 -0
  387. package/dist/skills/cli-skills-report-1b.js.map +1 -0
  388. package/dist/skills/cli-skills-report.d.ts +86 -0
  389. package/dist/skills/cli-skills-report.d.ts.map +1 -0
  390. package/dist/skills/cli-skills-report.js +121 -0
  391. package/dist/skills/cli-skills-report.js.map +1 -0
  392. package/dist/skills/cli-skills.d.ts +30 -0
  393. package/dist/skills/cli-skills.d.ts.map +1 -0
  394. package/dist/skills/cli-skills.js +379 -0
  395. package/dist/skills/cli-skills.js.map +1 -0
  396. package/dist/skills/codex-sandbox.d.ts +6 -0
  397. package/dist/skills/codex-sandbox.d.ts.map +1 -0
  398. package/dist/skills/codex-sandbox.js +55 -0
  399. package/dist/skills/codex-sandbox.js.map +1 -0
  400. package/dist/skills/compile-split.d.ts +57 -0
  401. package/dist/skills/compile-split.d.ts.map +1 -0
  402. package/dist/skills/compile-split.js +550 -0
  403. package/dist/skills/compile-split.js.map +1 -0
  404. package/dist/skills/compile-version.d.ts +37 -0
  405. package/dist/skills/compile-version.d.ts.map +1 -0
  406. package/dist/skills/compile-version.js +56 -0
  407. package/dist/skills/compile-version.js.map +1 -0
  408. package/dist/skills/compile-waits.d.ts +12 -0
  409. package/dist/skills/compile-waits.d.ts.map +1 -0
  410. package/dist/skills/compile-waits.js +52 -0
  411. package/dist/skills/compile-waits.js.map +1 -0
  412. package/dist/skills/compile-words.d.ts +85 -0
  413. package/dist/skills/compile-words.d.ts.map +1 -0
  414. package/dist/skills/compile-words.js +445 -0
  415. package/dist/skills/compile-words.js.map +1 -0
  416. package/dist/skills/compile.d.ts +42 -0
  417. package/dist/skills/compile.d.ts.map +1 -0
  418. package/dist/skills/compile.js +505 -0
  419. package/dist/skills/compile.js.map +1 -0
  420. package/dist/skills/credit-facts.d.ts +8 -0
  421. package/dist/skills/credit-facts.d.ts.map +1 -0
  422. package/dist/skills/credit-facts.js +32 -0
  423. package/dist/skills/credit-facts.js.map +1 -0
  424. package/dist/skills/credit.d.ts +86 -0
  425. package/dist/skills/credit.d.ts.map +1 -0
  426. package/dist/skills/credit.js +259 -0
  427. package/dist/skills/credit.js.map +1 -0
  428. package/dist/skills/directive-words.d.ts +11 -0
  429. package/dist/skills/directive-words.d.ts.map +1 -0
  430. package/dist/skills/directive-words.js +33 -0
  431. package/dist/skills/directive-words.js.map +1 -0
  432. package/dist/skills/fidelity.d.ts +42 -0
  433. package/dist/skills/fidelity.d.ts.map +1 -0
  434. package/dist/skills/fidelity.js +138 -0
  435. package/dist/skills/fidelity.js.map +1 -0
  436. package/dist/skills/fold-gated.d.ts +3 -0
  437. package/dist/skills/fold-gated.d.ts.map +1 -0
  438. package/dist/skills/fold-gated.js +78 -0
  439. package/dist/skills/fold-gated.js.map +1 -0
  440. package/dist/skills/fold.d.ts +87 -0
  441. package/dist/skills/fold.d.ts.map +1 -0
  442. package/dist/skills/fold.js +348 -0
  443. package/dist/skills/fold.js.map +1 -0
  444. package/dist/skills/follow-learnings.d.ts +128 -0
  445. package/dist/skills/follow-learnings.d.ts.map +1 -0
  446. package/dist/skills/follow-learnings.js +278 -0
  447. package/dist/skills/follow-learnings.js.map +1 -0
  448. package/dist/skills/forget-notice.d.ts +44 -0
  449. package/dist/skills/forget-notice.d.ts.map +1 -0
  450. package/dist/skills/forget-notice.js +131 -0
  451. package/dist/skills/forget-notice.js.map +1 -0
  452. package/dist/skills/front-version.d.ts +12 -0
  453. package/dist/skills/front-version.d.ts.map +1 -0
  454. package/dist/skills/front-version.js +87 -0
  455. package/dist/skills/front-version.js.map +1 -0
  456. package/dist/skills/host-facts.d.ts +51 -0
  457. package/dist/skills/host-facts.d.ts.map +1 -0
  458. package/dist/skills/host-facts.js +134 -0
  459. package/dist/skills/host-facts.js.map +1 -0
  460. package/dist/skills/learning-steps.d.ts +43 -0
  461. package/dist/skills/learning-steps.d.ts.map +1 -0
  462. package/dist/skills/learning-steps.js +294 -0
  463. package/dist/skills/learning-steps.js.map +1 -0
  464. package/dist/skills/ledger.d.ts +43 -0
  465. package/dist/skills/ledger.d.ts.map +1 -0
  466. package/dist/skills/ledger.js +336 -0
  467. package/dist/skills/ledger.js.map +1 -0
  468. package/dist/skills/lesson-gate.d.ts +25 -0
  469. package/dist/skills/lesson-gate.d.ts.map +1 -0
  470. package/dist/skills/lesson-gate.js +316 -0
  471. package/dist/skills/lesson-gate.js.map +1 -0
  472. package/dist/skills/lessons.d.ts +60 -0
  473. package/dist/skills/lessons.d.ts.map +1 -0
  474. package/dist/skills/lessons.js +396 -0
  475. package/dist/skills/lessons.js.map +1 -0
  476. package/dist/skills/offer-answers.d.ts +20 -0
  477. package/dist/skills/offer-answers.d.ts.map +1 -0
  478. package/dist/skills/offer-answers.js +51 -0
  479. package/dist/skills/offer-answers.js.map +1 -0
  480. package/dist/skills/offer-drift.d.ts +35 -0
  481. package/dist/skills/offer-drift.d.ts.map +1 -0
  482. package/dist/skills/offer-drift.js +98 -0
  483. package/dist/skills/offer-drift.js.map +1 -0
  484. package/dist/skills/offer-lesson.d.ts +31 -0
  485. package/dist/skills/offer-lesson.d.ts.map +1 -0
  486. package/dist/skills/offer-lesson.js +123 -0
  487. package/dist/skills/offer-lesson.js.map +1 -0
  488. package/dist/skills/offer-lines.d.ts +40 -0
  489. package/dist/skills/offer-lines.d.ts.map +1 -0
  490. package/dist/skills/offer-lines.js +80 -0
  491. package/dist/skills/offer-lines.js.map +1 -0
  492. package/dist/skills/offer-moment.d.ts +102 -0
  493. package/dist/skills/offer-moment.d.ts.map +1 -0
  494. package/dist/skills/offer-moment.js +260 -0
  495. package/dist/skills/offer-moment.js.map +1 -0
  496. package/dist/skills/offer-repair.d.ts +36 -0
  497. package/dist/skills/offer-repair.d.ts.map +1 -0
  498. package/dist/skills/offer-repair.js +212 -0
  499. package/dist/skills/offer-repair.js.map +1 -0
  500. package/dist/skills/offer-retire.d.ts +53 -0
  501. package/dist/skills/offer-retire.d.ts.map +1 -0
  502. package/dist/skills/offer-retire.js +149 -0
  503. package/dist/skills/offer-retire.js.map +1 -0
  504. package/dist/skills/offer-update.d.ts +54 -0
  505. package/dist/skills/offer-update.d.ts.map +1 -0
  506. package/dist/skills/offer-update.js +115 -0
  507. package/dist/skills/offer-update.js.map +1 -0
  508. package/dist/skills/offer-words-1b.d.ts +32 -0
  509. package/dist/skills/offer-words-1b.d.ts.map +1 -0
  510. package/dist/skills/offer-words-1b.js +80 -0
  511. package/dist/skills/offer-words-1b.js.map +1 -0
  512. package/dist/skills/offer-words-2.d.ts +123 -0
  513. package/dist/skills/offer-words-2.d.ts.map +1 -0
  514. package/dist/skills/offer-words-2.js +194 -0
  515. package/dist/skills/offer-words-2.js.map +1 -0
  516. package/dist/skills/offer-words.d.ts +65 -0
  517. package/dist/skills/offer-words.d.ts.map +1 -0
  518. package/dist/skills/offer-words.js +205 -0
  519. package/dist/skills/offer-words.js.map +1 -0
  520. package/dist/skills/offers.d.ts +66 -0
  521. package/dist/skills/offers.d.ts.map +1 -0
  522. package/dist/skills/offers.js +284 -0
  523. package/dist/skills/offers.js.map +1 -0
  524. package/dist/skills/own-folder.d.ts +9 -0
  525. package/dist/skills/own-folder.d.ts.map +1 -0
  526. package/dist/skills/own-folder.js +36 -0
  527. package/dist/skills/own-folder.js.map +1 -0
  528. package/dist/skills/person.d.ts +34 -0
  529. package/dist/skills/person.d.ts.map +1 -0
  530. package/dist/skills/person.js +102 -0
  531. package/dist/skills/person.js.map +1 -0
  532. package/dist/skills/probe-clean.d.ts +9 -0
  533. package/dist/skills/probe-clean.d.ts.map +1 -0
  534. package/dist/skills/probe-clean.js +48 -0
  535. package/dist/skills/probe-clean.js.map +1 -0
  536. package/dist/skills/probes.d.ts +26 -0
  537. package/dist/skills/probes.d.ts.map +1 -0
  538. package/dist/skills/probes.js +225 -0
  539. package/dist/skills/probes.js.map +1 -0
  540. package/dist/skills/recall.d.ts +119 -0
  541. package/dist/skills/recall.d.ts.map +1 -0
  542. package/dist/skills/recall.js +370 -0
  543. package/dist/skills/recall.js.map +1 -0
  544. package/dist/skills/receipts.d.ts +44 -0
  545. package/dist/skills/receipts.d.ts.map +1 -0
  546. package/dist/skills/receipts.js +223 -0
  547. package/dist/skills/receipts.js.map +1 -0
  548. package/dist/skills/run-checkout.d.ts +4 -0
  549. package/dist/skills/run-checkout.d.ts.map +1 -0
  550. package/dist/skills/run-checkout.js +37 -0
  551. package/dist/skills/run-checkout.js.map +1 -0
  552. package/dist/skills/runblock.d.ts +47 -0
  553. package/dist/skills/runblock.d.ts.map +1 -0
  554. package/dist/skills/runblock.js +227 -0
  555. package/dist/skills/runblock.js.map +1 -0
  556. package/dist/skills/save-gate.d.ts +64 -0
  557. package/dist/skills/save-gate.d.ts.map +1 -0
  558. package/dist/skills/save-gate.js +354 -0
  559. package/dist/skills/save-gate.js.map +1 -0
  560. package/dist/skills/save-parse.d.ts +42 -0
  561. package/dist/skills/save-parse.d.ts.map +1 -0
  562. package/dist/skills/save-parse.js +172 -0
  563. package/dist/skills/save-parse.js.map +1 -0
  564. package/dist/skills/save-store.d.ts +12 -0
  565. package/dist/skills/save-store.d.ts.map +1 -0
  566. package/dist/skills/save-store.js +22 -0
  567. package/dist/skills/save-store.js.map +1 -0
  568. package/dist/skills/save-verify.d.ts +59 -0
  569. package/dist/skills/save-verify.d.ts.map +1 -0
  570. package/dist/skills/save-verify.js +390 -0
  571. package/dist/skills/save-verify.js.map +1 -0
  572. package/dist/skills/settings.d.ts +48 -0
  573. package/dist/skills/settings.d.ts.map +1 -0
  574. package/dist/skills/settings.js +155 -0
  575. package/dist/skills/settings.js.map +1 -0
  576. package/dist/skills/skill-diff.d.ts +40 -0
  577. package/dist/skills/skill-diff.d.ts.map +1 -0
  578. package/dist/skills/skill-diff.js +191 -0
  579. package/dist/skills/skill-diff.js.map +1 -0
  580. package/dist/skills/skill-file.d.ts +24 -0
  581. package/dist/skills/skill-file.d.ts.map +1 -0
  582. package/dist/skills/skill-file.js +97 -0
  583. package/dist/skills/skill-file.js.map +1 -0
  584. package/dist/skills/skill-rebuild.d.ts +27 -0
  585. package/dist/skills/skill-rebuild.d.ts.map +1 -0
  586. package/dist/skills/skill-rebuild.js +85 -0
  587. package/dist/skills/skill-rebuild.js.map +1 -0
  588. package/dist/skills/skillmd.d.ts +17 -0
  589. package/dist/skills/skillmd.d.ts.map +1 -0
  590. package/dist/skills/skillmd.js +219 -0
  591. package/dist/skills/skillmd.js.map +1 -0
  592. package/dist/skills/skills.d.ts +28 -8
  593. package/dist/skills/skills.d.ts.map +1 -1
  594. package/dist/skills/skills.js +106 -53
  595. package/dist/skills/skills.js.map +1 -1
  596. package/dist/skills/staleness.d.ts +27 -0
  597. package/dist/skills/staleness.d.ts.map +1 -0
  598. package/dist/skills/staleness.js +178 -0
  599. package/dist/skills/staleness.js.map +1 -0
  600. package/dist/skills/state.d.ts +36 -0
  601. package/dist/skills/state.d.ts.map +1 -0
  602. package/dist/skills/state.js +259 -0
  603. package/dist/skills/state.js.map +1 -0
  604. package/dist/skills/store-fs.d.ts +77 -0
  605. package/dist/skills/store-fs.d.ts.map +1 -0
  606. package/dist/skills/store-fs.js +194 -0
  607. package/dist/skills/store-fs.js.map +1 -0
  608. package/dist/skills/store-held.d.ts +44 -0
  609. package/dist/skills/store-held.d.ts.map +1 -0
  610. package/dist/skills/store-held.js +147 -0
  611. package/dist/skills/store-held.js.map +1 -0
  612. package/dist/skills/store.d.ts +73 -0
  613. package/dist/skills/store.d.ts.map +1 -0
  614. package/dist/skills/store.js +279 -0
  615. package/dist/skills/store.js.map +1 -0
  616. package/dist/skills/types.d.ts +8 -0
  617. package/dist/skills/types.d.ts.map +1 -1
  618. package/dist/skills/update-gate.d.ts +36 -0
  619. package/dist/skills/update-gate.d.ts.map +1 -0
  620. package/dist/skills/update-gate.js +357 -0
  621. package/dist/skills/update-gate.js.map +1 -0
  622. package/dist/skills/update-plan.d.ts +40 -0
  623. package/dist/skills/update-plan.d.ts.map +1 -0
  624. package/dist/skills/update-plan.js +196 -0
  625. package/dist/skills/update-plan.js.map +1 -0
  626. package/dist/skills/validate.d.ts +11 -0
  627. package/dist/skills/validate.d.ts.map +1 -0
  628. package/dist/skills/validate.js +112 -0
  629. package/dist/skills/validate.js.map +1 -0
  630. package/dist/skills/value-line.d.ts +94 -0
  631. package/dist/skills/value-line.d.ts.map +1 -0
  632. package/dist/skills/value-line.js +355 -0
  633. package/dist/skills/value-line.js.map +1 -0
  634. package/dist/skills/versions-fs.d.ts +45 -0
  635. package/dist/skills/versions-fs.d.ts.map +1 -0
  636. package/dist/skills/versions-fs.js +234 -0
  637. package/dist/skills/versions-fs.js.map +1 -0
  638. package/dist/skills/versions.d.ts +56 -0
  639. package/dist/skills/versions.d.ts.map +1 -0
  640. package/dist/skills/versions.js +351 -0
  641. package/dist/skills/versions.js.map +1 -0
  642. package/dist/telemetry/contract.d.ts +15 -1
  643. package/dist/telemetry/contract.d.ts.map +1 -1
  644. package/dist/telemetry/contract.js +80 -11
  645. package/dist/telemetry/contract.js.map +1 -1
  646. package/dist/telemetry/gate.js +4 -4
  647. package/dist/telemetry/gate.js.map +1 -1
  648. package/dist/telemetry/index.d.ts +1 -1
  649. package/dist/telemetry/index.d.ts.map +1 -1
  650. package/dist/telemetry/index.js +1 -1
  651. package/dist/telemetry/index.js.map +1 -1
  652. package/dist/telemetry/notice.js +5 -5
  653. package/dist/telemetry/notice.js.map +1 -1
  654. package/dist/telemetry/queue.d.ts.map +1 -1
  655. package/dist/telemetry/queue.js +7 -7
  656. package/dist/telemetry/queue.js.map +1 -1
  657. package/dist/telemetry/track.d.ts.map +1 -1
  658. package/dist/telemetry/track.js +4 -3
  659. package/dist/telemetry/track.js.map +1 -1
  660. package/dist/trace/checks.d.ts +63 -0
  661. package/dist/trace/checks.d.ts.map +1 -0
  662. package/dist/trace/checks.js +495 -0
  663. package/dist/trace/checks.js.map +1 -0
  664. package/dist/trace/claude.d.ts +124 -0
  665. package/dist/trace/claude.d.ts.map +1 -0
  666. package/dist/trace/claude.js +303 -0
  667. package/dist/trace/claude.js.map +1 -0
  668. package/dist/trace/codex-exec.d.ts +22 -0
  669. package/dist/trace/codex-exec.d.ts.map +1 -0
  670. package/dist/trace/codex-exec.js +129 -0
  671. package/dist/trace/codex-exec.js.map +1 -0
  672. package/dist/trace/codex-meta.d.ts +23 -0
  673. package/dist/trace/codex-meta.d.ts.map +1 -0
  674. package/dist/trace/codex-meta.js +112 -0
  675. package/dist/trace/codex-meta.js.map +1 -0
  676. package/dist/trace/codex.d.ts +33 -0
  677. package/dist/trace/codex.d.ts.map +1 -0
  678. package/dist/trace/codex.js +485 -0
  679. package/dist/trace/codex.js.map +1 -0
  680. package/dist/trace/cursor.d.ts +16 -0
  681. package/dist/trace/cursor.d.ts.map +1 -0
  682. package/dist/trace/cursor.js +133 -0
  683. package/dist/trace/cursor.js.map +1 -0
  684. package/dist/trace/dialect.d.ts +43 -0
  685. package/dist/trace/dialect.d.ts.map +1 -0
  686. package/dist/trace/dialect.js +95 -0
  687. package/dist/trace/dialect.js.map +1 -0
  688. package/dist/trace/epochs.d.ts +10 -0
  689. package/dist/trace/epochs.d.ts.map +1 -0
  690. package/dist/trace/epochs.js +16 -0
  691. package/dist/trace/epochs.js.map +1 -0
  692. package/dist/trace/failure.d.ts +15 -0
  693. package/dist/trace/failure.d.ts.map +1 -0
  694. package/dist/trace/failure.js +69 -0
  695. package/dist/trace/failure.js.map +1 -0
  696. package/dist/trace/gate-file.d.ts +71 -0
  697. package/dist/trace/gate-file.d.ts.map +1 -0
  698. package/dist/trace/gate-file.js +329 -0
  699. package/dist/trace/gate-file.js.map +1 -0
  700. package/dist/trace/guard-fast.d.ts +22 -0
  701. package/dist/trace/guard-fast.d.ts.map +1 -0
  702. package/dist/trace/guard-fast.js +213 -0
  703. package/dist/trace/guard-fast.js.map +1 -0
  704. package/dist/trace/housekeeping.d.ts +5 -0
  705. package/dist/trace/housekeeping.d.ts.map +1 -0
  706. package/dist/trace/housekeeping.js +93 -0
  707. package/dist/trace/housekeeping.js.map +1 -0
  708. package/dist/trace/jobs.d.ts +52 -0
  709. package/dist/trace/jobs.d.ts.map +1 -0
  710. package/dist/trace/jobs.js +182 -0
  711. package/dist/trace/jobs.js.map +1 -0
  712. package/dist/trace/known-repo.d.ts +3 -0
  713. package/dist/trace/known-repo.d.ts.map +1 -0
  714. package/dist/trace/known-repo.js +55 -0
  715. package/dist/trace/known-repo.js.map +1 -0
  716. package/dist/trace/pool.d.ts +40 -0
  717. package/dist/trace/pool.d.ts.map +1 -0
  718. package/dist/trace/pool.js +154 -0
  719. package/dist/trace/pool.js.map +1 -0
  720. package/dist/trace/repairs.d.ts +27 -0
  721. package/dist/trace/repairs.d.ts.map +1 -0
  722. package/dist/trace/repairs.js +303 -0
  723. package/dist/trace/repairs.js.map +1 -0
  724. package/dist/trace/run-calls.d.ts +82 -0
  725. package/dist/trace/run-calls.d.ts.map +1 -0
  726. package/dist/trace/run-calls.js +331 -0
  727. package/dist/trace/run-calls.js.map +1 -0
  728. package/dist/trace/run-join.d.ts +20 -0
  729. package/dist/trace/run-join.d.ts.map +1 -0
  730. package/dist/trace/run-join.js +99 -0
  731. package/dist/trace/run-join.js.map +1 -0
  732. package/dist/trace/run-sheets.d.ts +26 -0
  733. package/dist/trace/run-sheets.d.ts.map +1 -0
  734. package/dist/trace/run-sheets.js +145 -0
  735. package/dist/trace/run-sheets.js.map +1 -0
  736. package/dist/trace/run-turns.d.ts +24 -0
  737. package/dist/trace/run-turns.d.ts.map +1 -0
  738. package/dist/trace/run-turns.js +67 -0
  739. package/dist/trace/run-turns.js.map +1 -0
  740. package/dist/trace/run-verdict.d.ts +24 -0
  741. package/dist/trace/run-verdict.d.ts.map +1 -0
  742. package/dist/trace/run-verdict.js +176 -0
  743. package/dist/trace/run-verdict.js.map +1 -0
  744. package/dist/trace/runs.d.ts +54 -0
  745. package/dist/trace/runs.d.ts.map +1 -0
  746. package/dist/trace/runs.js +501 -0
  747. package/dist/trace/runs.js.map +1 -0
  748. package/dist/trace/skill-session.d.ts +64 -0
  749. package/dist/trace/skill-session.d.ts.map +1 -0
  750. package/dist/trace/skill-session.js +232 -0
  751. package/dist/trace/skill-session.js.map +1 -0
  752. package/dist/trace/tamper.d.ts +12 -0
  753. package/dist/trace/tamper.d.ts.map +1 -0
  754. package/dist/trace/tamper.js +405 -0
  755. package/dist/trace/tamper.js.map +1 -0
  756. package/dist/trace/typed.d.ts +30 -0
  757. package/dist/trace/typed.d.ts.map +1 -0
  758. package/dist/trace/typed.js +132 -0
  759. package/dist/trace/typed.js.map +1 -0
  760. package/dist/trace/wall-state.d.ts +86 -0
  761. package/dist/trace/wall-state.d.ts.map +1 -0
  762. package/dist/trace/wall-state.js +279 -0
  763. package/dist/trace/wall-state.js.map +1 -0
  764. package/dist/trace/walls.d.ts +40 -0
  765. package/dist/trace/walls.d.ts.map +1 -0
  766. package/dist/trace/walls.js +318 -0
  767. package/dist/trace/walls.js.map +1 -0
  768. package/dist/upkeep-run.d.ts.map +1 -1
  769. package/dist/upkeep-run.js +2 -23
  770. package/dist/upkeep-run.js.map +1 -1
  771. package/dist/upkeep.d.ts.map +1 -1
  772. package/dist/upkeep.js +2 -3
  773. package/dist/upkeep.js.map +1 -1
  774. package/dist/util/private-fs.d.ts +6 -0
  775. package/dist/util/private-fs.d.ts.map +1 -1
  776. package/dist/util/private-fs.js +9 -1
  777. package/dist/util/private-fs.js.map +1 -1
  778. package/dist/util/state.d.ts.map +1 -1
  779. package/dist/util/state.js +17 -3
  780. package/dist/util/state.js.map +1 -1
  781. package/dist/vendor/tree-sitter-swift/LICENSE +21 -0
  782. package/dist/vendor/tree-sitter-swift/node-types.json +30694 -0
  783. package/dist/vendor/tree-sitter-swift/prebuilds/darwin-arm64/tree-sitter-swift.node +0 -0
  784. package/dist/vendor/tree-sitter-swift/prebuilds/darwin-x64/tree-sitter-swift.node +0 -0
  785. package/dist/vendor/tree-sitter-swift/prebuilds/linux-arm64/tree-sitter-swift.node +0 -0
  786. package/dist/vendor/tree-sitter-swift/prebuilds/linux-x64/tree-sitter-swift.node +0 -0
  787. package/dist/vendor/tree-sitter-swift/prebuilds/win32-arm64/tree-sitter-swift.node +0 -0
  788. package/dist/vendor/tree-sitter-swift/prebuilds/win32-x64/tree-sitter-swift.node +0 -0
  789. package/package.json +6 -3
  790. package/scripts/stamp-telemetry-key.mjs +8 -5
  791. package/scripts/vendor-grammars.mjs +35 -0
@@ -0,0 +1,303 @@
1
+ /**
2
+ * The prompt hook: what the agent reads alongside what the person just typed.
3
+ *
4
+ * Two lookups, independent of each other. The learnings that bear on the
5
+ * prompt are matched here, by their words, from a 3-character prompt up: "ff
6
+ * to prod" is too short to ask the graph about, and an ask that fails or runs
7
+ * out of time must not take the learnings down with it. The graph ask (`graft
8
+ * ask`, pointers only) runs for prompts of MIN_PROMPT_CHARS and up, and when it
9
+ * answers it also brings the learnings that touch the files its hits point into,
10
+ * the teammates' branches on the same code, and the retrieval pack.
11
+ */
12
+ import { readFileSync } from 'node:fs';
13
+ import { join } from 'node:path';
14
+ import { homedir } from 'node:os';
15
+ import { brand, tag } from '../brand.js';
16
+ import { scopeOf, scopesOfGraph } from '../graph/scopes.js';
17
+ import { keepsNotes } from '../notes/home.js';
18
+ import { findNotes, listNotes } from '../notes/notes.js';
19
+ import { INJECTED_POINTERS_CAP, notesForPrompt, relevantRetrieval } from './format.js';
20
+ import { CHILD_TIMEOUT_MS, emitHook, graftJsonWithin, payloadSessionId, withContextDirArg } from './hook-io.js';
21
+ import { promptPart } from './skills-wiring.js';
22
+ import { recordSkillUse, skillOfPrompt } from './skill-use.js';
23
+ import { readSession, readStats, writeSession } from './state.js';
24
+ import { readWiring } from './stats.js';
25
+ import { ownText, PASTE_MARK } from '../trace/claude.js';
26
+ /** Prompts shorter than this never trigger the graph ask — they are almost always
27
+ * conversational ("yes go ahead", "thanks") and the coverage gate can't judge
28
+ * them reliably with so few terms. */
29
+ export const MIN_PROMPT_CHARS = 12;
30
+ /** Prompts shorter than this match nothing at all, learnings included: no
31
+ * word in them is long enough to look up. "ff to prod" (10) and "ship it" (7)
32
+ * clear it. */
33
+ export const MIN_CUE_CHARS = 3;
34
+ /**
35
+ * The most the prompt hook takes in all, graph ask included: the person's
36
+ * prompt waits on it before the agent starts. The learnings are matched first
37
+ * and never wait on the ask; the ask gets only what is left. A large repo's
38
+ * ask took 13 s at p95 before this (the lab, on main).
39
+ */
40
+ export const PROMPT_BUDGET_MS = 4000;
41
+ /** Kept back after the ask for the hook's own work: format, write the session, emit. */
42
+ const AFTER_ASK_MS = 250;
43
+ /** An ask with less time than this left isn't started: it would only be cut off. */
44
+ const MIN_ASK_MS = 500;
45
+ /** Headroom left for the hook's own work (read stdin, score, write session, emit)
46
+ * after its `graft ask` child returns, inside the installed timeout. */
47
+ const HOOK_OVERHEAD_MS = 2000;
48
+ /** Floor for an install from before 0.23 (a timeout meant as ms), so a hand-edited tiny one can't leave the child no time at all. */
49
+ const MIN_CHILD_TIMEOUT_MS = 4000;
50
+ /** An installed timeout at or over this was written as milliseconds (before 0.23); under it, seconds. */
51
+ const LEGACY_MS_FROM = 1000;
52
+ /**
53
+ * How long the prompt hook may let `graft ask` run, from the timeout that is
54
+ * *actually installed* (repo and user settings), not from what the current
55
+ * `settings-merge.ts` would install: an upgrade doesn't rewrite settings until
56
+ * the next init or upkeep, and a child that outlives the installed timeout
57
+ * gets the whole hook killed (no learnings, no session write).
58
+ *
59
+ * Claude Code reads `timeout` in seconds, which Trail writes from 0.23 on. A
60
+ * number of 1000 or more is an install from before, meant as milliseconds,
61
+ * and read that way. 0 means no room for an ask at all. The hook's own total
62
+ * budget (PROMPT_BUDGET_MS) cuts this further.
63
+ */
64
+ export function promptAskTimeout(dir) {
65
+ const installed = installedHookTimeout(dir, 'UserPromptSubmit');
66
+ if (installed === null)
67
+ return CHILD_TIMEOUT_MS - HOOK_OVERHEAD_MS;
68
+ if (installed.legacy)
69
+ return Math.max(MIN_CHILD_TIMEOUT_MS, installed.ms - HOOK_OVERHEAD_MS);
70
+ const room = installed.ms - HOOK_OVERHEAD_MS;
71
+ return room >= MIN_ASK_MS ? room : 0;
72
+ }
73
+ /**
74
+ * Every settings file Claude Code merges hook definitions from, for a session
75
+ * rooted at `dir`. The per-repo file is not the only place graft's hooks can be
76
+ * installed: declaring them once at the user level wires every repo on the
77
+ * machine at once, and such a repo has no `.claude/settings.json` at all.
78
+ */
79
+ function hookSettingsFiles(dir) {
80
+ const user = process.env.CLAUDE_CONFIG_DIR ?? join(homedir(), '.claude');
81
+ return [
82
+ join(dir, '.claude', 'settings.json'),
83
+ join(dir, '.claude', 'settings.local.json'),
84
+ join(user, 'settings.json'),
85
+ ];
86
+ }
87
+ /** The timeout on one settings file's graft hook entry for `event`, or null if it
88
+ * can't be read (no settings file, hand-edited shape, unparseable JSON). */
89
+ function hookTimeoutIn(file, event) {
90
+ try {
91
+ const settings = JSON.parse(readFileSync(file, 'utf8'));
92
+ const blocks = settings?.hooks?.[event];
93
+ if (!Array.isArray(blocks))
94
+ return null;
95
+ for (const block of blocks) {
96
+ for (const h of block?.hooks ?? []) {
97
+ if (typeof h?.command === 'string' && /(graft|trail)-hooks\.cjs|\/\.trail\/hook\.cjs/.test(h.command) && typeof h.timeout === 'number' && h.timeout > 0) {
98
+ const legacy = h.timeout >= LEGACY_MS_FROM;
99
+ return { ms: legacy ? h.timeout : h.timeout * 1000, legacy };
100
+ }
101
+ }
102
+ }
103
+ return null;
104
+ }
105
+ catch {
106
+ return null;
107
+ }
108
+ }
109
+ /**
110
+ * The budget this hook is actually running under, or null when no settings file
111
+ * declares one.
112
+ *
113
+ * The smallest declared timeout wins rather than the nearest, because when more
114
+ * than one file declares the hook Claude Code runs every matching entry and this
115
+ * process cannot tell which one launched it. Guessing high is the expensive
116
+ * mistake: an overrunning child gets the whole hook SIGKILLed, so `emit()` and
117
+ * `writeSession()` never run and the turn silently gets no retrieval at all.
118
+ * Guessing low only shortens one query.
119
+ */
120
+ function installedHookTimeout(dir, event) {
121
+ let smallest = null;
122
+ for (const file of hookSettingsFiles(dir)) {
123
+ const timeout = hookTimeoutIn(file, event);
124
+ if (timeout === null)
125
+ continue;
126
+ if (smallest === null || timeout.ms < smallest.ms)
127
+ smallest = timeout;
128
+ }
129
+ return smallest;
130
+ }
131
+ /**
132
+ * The "you're working in backend/, weight it" hint: on a multi-scope repo,
133
+ * narrow the prompt hook's `ask` call to whatever scope the last-edited file
134
+ * (`stats.lastFile`, captured at {@link handlePostEdit}) sits in.
135
+ *
136
+ * `lastFile` is only a basename (not a repo-relative path — see
137
+ * `handlePostEdit`), so this is a best-effort lookup against the CURRENT
138
+ * graph: any file node whose path ends in `/<lastFile>` (or equals it, for a
139
+ * repo-root file). Fails soft in every direction a hook must never crash on —
140
+ * no graph, a single-scope graph, a lastFile no longer in the graph (moved,
141
+ * deleted, or edited before the first build), or a basename that lands in
142
+ * more than one scope (ambiguous: could be either sub-project) all skip the
143
+ * hint silently, logging one line to stderr so the miss is visible without
144
+ * ever failing the hook.
145
+ */
146
+ export function lastFileScopeHint(dir, lastFile) {
147
+ if (!lastFile)
148
+ return null;
149
+ try {
150
+ const w = readWiring(dir);
151
+ if (!w)
152
+ return null;
153
+ const scopes = scopesOfGraph(w);
154
+ if (scopes.length <= 1)
155
+ return null; // single-scope: no hint, no --in
156
+ const matches = (w.nodes ?? []).filter((n) => n.kind === 'file' && (n.path === lastFile || n.path.endsWith(`/${lastFile}`)));
157
+ if (matches.length === 0) {
158
+ console.error(`${tag()} prompt hook: lastFile "${lastFile}" not found in the graph, so no scope hint`);
159
+ return null;
160
+ }
161
+ const prefixes = new Set(matches.map((n) => scopeOf(n.path, scopes).prefix));
162
+ if (prefixes.size > 1) {
163
+ console.error(`${tag()} prompt hook: lastFile "${lastFile}" matches more than one scope, so no scope hint`);
164
+ return null;
165
+ }
166
+ const [prefix] = prefixes;
167
+ return prefix === '' ? null : prefix; // root scope: nothing to narrow
168
+ }
169
+ catch (e) {
170
+ console.error(`${tag()} prompt hook: scope hint lookup failed (${e?.message ?? e}), so no scope hint`);
171
+ return null;
172
+ }
173
+ }
174
+ /**
175
+ * The learnings that bear on `prompt`, best first: the ones whose title or
176
+ * text share its words, matched here with no graph ask needed, joined by the
177
+ * ones the ask matched on the files its hits point into when it answered. One
178
+ * learning is one entry, at its better score. Empty for a repo that keeps no
179
+ * learnings on this machine, and on any read failure: a missing learning costs
180
+ * one prompt, a broken hook costs the turn.
181
+ */
182
+ export function promptLearnings(dir, prompt, ask, byWords = learningsByWords(dir, prompt)) {
183
+ const best = new Map();
184
+ const add = (h) => {
185
+ const key = h?.note && (h.note.path || h.note.title);
186
+ if (!key)
187
+ return;
188
+ const had = best.get(key);
189
+ if (!had || h.score > had.score)
190
+ best.set(key, h);
191
+ };
192
+ for (const h of byWords)
193
+ add(h);
194
+ for (const h of ask?.notes ?? [])
195
+ add(h);
196
+ return [...best.values()].sort((a, b) => b.score - a.score || String(b.note.date).localeCompare(String(a.note.date)));
197
+ }
198
+ /** The learnings whose title or text share the prompt's words: no graph needed. Empty on any read failure. */
199
+ function learningsByWords(dir, prompt) {
200
+ try {
201
+ return keepsNotes(dir) ? findNotes(listNotes(dir), prompt) : [];
202
+ }
203
+ catch {
204
+ // Nothing matched by words this time; the ask's own matches still count.
205
+ return [];
206
+ }
207
+ }
208
+ /**
209
+ * The graph ask for `prompt`: pointers only, narrowed to the last-edited
210
+ * file's scope. Null when it fails, runs out of time, or there is no time
211
+ * left before `deadline` to start one.
212
+ */
213
+ async function askGraph(dir, prompt, deadline) {
214
+ // Pointers-only, small, gated. No --source: per-prompt injected tokens are
215
+ // fresh full-price input on every turn (unlike the cached SessionStart
216
+ // orientation), so the pack carries locators, never inlined code — the agent
217
+ // pulls spans itself via `graft ask --source` when a pointer looks right.
218
+ // relevantRetrieval then drops the pack entirely when the prompt barely
219
+ // overlaps the top hit or when every hit was already injected this session.
220
+ // The prompt goes on stdin (`-`), never in argv, where any process on the
221
+ // machine can read it with `ps`.
222
+ const askArgs = withContextDirArg(dir, ['ask', '-', '.', '--json', '-n', '3']);
223
+ // "You're working in backend/, weight it": only fires on a multi-scope
224
+ // repo whose lastFile resolves cleanly to one scope — see lastFileScopeHint.
225
+ const scopeHint = lastFileScopeHint(dir, readStats(dir)?.lastFile);
226
+ if (scopeHint)
227
+ askArgs.push('--in', scopeHint);
228
+ const timeout = Math.min(promptAskTimeout(dir), deadline - Date.now() - AFTER_ASK_MS);
229
+ if (timeout < MIN_ASK_MS)
230
+ return null;
231
+ const ask = await graftJsonWithin(dir, askArgs, timeout, prompt);
232
+ return ask && typeof ask === 'object' ? ask : null;
233
+ }
234
+ /**
235
+ * The person's own words in the prompt slot, the shared filter's way: IDE
236
+ * context and reminders stripped, a pasted block left out, and '' when what
237
+ * arrived is harness text (a task notice, a command wrapper, a hand-back).
238
+ */
239
+ export function promptWords(raw) {
240
+ return ownText(String(raw ?? '')).split(PASTE_MARK).join(' ').trim();
241
+ }
242
+ /**
243
+ * UserPromptSubmit. Ends inside `budgetMs` (PROMPT_BUDGET_MS by default): the
244
+ * learned-skills part first (its own 400 ms deadline), then the learnings
245
+ * matched by their words, then the graph ask in what is left; whatever was
246
+ * found goes out in one object even when the ask is cut. A skills block (a
247
+ * bare "no" where the host shows it) is the whole answer, with no ask.
248
+ *
249
+ * The skills part comes before the 3-character floor: an answer to an offer
250
+ * can be shorter than that ("no", "y", "ok"), and it only matches what the
251
+ * person typed.
252
+ */
253
+ export async function handlePrompt(input, dir, opts = {}) {
254
+ // Background completion notices are machine events, not user queries: no skills answer, no ask (#551).
255
+ if (String(input?.prompt ?? '').trimStart().startsWith('<task-notification>'))
256
+ return;
257
+ const deadline = Date.now() + (opts.budgetMs ?? PROMPT_BUDGET_MS);
258
+ // `/name` for one of the repo's skills is a run of it; the name only goes.
259
+ recordSkillUse(skillOfPrompt(input?.prompt), input, dir);
260
+ const skills = await promptPart(input, dir);
261
+ if (skills.block)
262
+ return void emitHook('UserPromptSubmit', { block: skills.block });
263
+ const say = (txt) => emitHook('UserPromptSubmit', { context: [skills.context, txt].filter(Boolean).join('\n\n'), notice: skills.notice });
264
+ const prompt = promptWords(input?.prompt);
265
+ if (prompt.length < MIN_CUE_CHARS)
266
+ return say('');
267
+ const underTrail = brand() === 'trail';
268
+ // Learnings first: matched by their words, before and whatever the ask does.
269
+ const byWords = underTrail ? learningsByWords(dir, prompt) : [];
270
+ const ask = prompt.length >= MIN_PROMPT_CHARS ? await askGraph(dir, prompt, deadline) : null;
271
+ // Under graft, learnings come only with the ask; nothing else to say without it.
272
+ if (!ask && !underTrail)
273
+ return say('');
274
+ const id = payloadSessionId(input);
275
+ const s = readSession(dir, id);
276
+ // What an earlier session worked out matters more than where code is.
277
+ // Part 7: a learning the run block already says (its step repeats it, or it wins over a step) is said once, there.
278
+ const said = new Set(skills.said ?? []);
279
+ const all = underTrail ? promptLearnings(dir, prompt, ask, byWords) : [];
280
+ const learnings = all.filter((h) => !said.has(h.note.id));
281
+ // The session's one shown list, which on-touch reads too: a learning the block said is not shown again on a file open.
282
+ if (said.size)
283
+ s.injectedNotes = [...(s.injectedNotes ?? []), ...saidPaths(dir, said)].slice(-INJECTED_POINTERS_CAP);
284
+ const notes = learnings.length ? notesForPrompt({ query: prompt, mode: 'learnings', hits: [], notes: learnings }, s) : null;
285
+ const retrieval = ask ? relevantRetrieval(ask, s) : null;
286
+ // A count, never the prompt: nothing the person typed is kept (spec section 6).
287
+ if (ask)
288
+ s.promptAsks = (s.promptAsks ?? 0) + 1;
289
+ // Teammates' branches on the same code come after an edit instead (hooks.ts editOverlap).
290
+ say([notes, retrieval].filter(Boolean).join('\n\n'));
291
+ if (ask || notes || said.size)
292
+ writeSession(dir, id, s);
293
+ }
294
+ /** The paths the session's shown list knows the learnings `ids` by (as `listNotes` gives them). [] on a read failure. */
295
+ function saidPaths(dir, ids) {
296
+ try {
297
+ return listNotes(dir, { branches: false }).filter((n) => ids.has(n.id)).map((n) => n.path || n.title);
298
+ }
299
+ catch {
300
+ return [];
301
+ }
302
+ }
303
+ //# sourceMappingURL=prompt-hook.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"prompt-hook.js","sourceRoot":"","sources":["../../src/claude/prompt-hook.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AACH,OAAO,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AACvC,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AACjC,OAAO,EAAE,OAAO,EAAE,MAAM,SAAS,CAAC;AAClC,OAAO,EAAE,KAAK,EAAE,GAAG,EAAE,MAAM,aAAa,CAAC;AACzC,OAAO,EAAE,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AAC5D,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAC9C,OAAO,EAAE,SAAS,EAAE,SAAS,EAAgB,MAAM,mBAAmB,CAAC;AACvE,OAAO,EAAE,qBAAqB,EAAE,cAAc,EAAE,iBAAiB,EAAgB,MAAM,aAAa,CAAC;AACrG,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E,CAAC,CAAC,UAAU,GAAG,CAAC,CAAC,CAAC,UAAU,IAAI,CAAC,CAAC,GAAG,CAAC,CAAC;IAChD,0FAA0F;IAC1F,GAAG,CAAC,CAAC,KAAK,EAAE,SAAS,CAAC,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC;IACrD,IAAI,GAAG,IAAI,KAAK,IAAI,IAAI,CAAC,IAAI;QAAE,YAAY,CAAC,GAAG,EAAE,EAAE,EAAE,CAAC,CAAC,CAAC;AAC1D,CAAC;AAED,yHAAyH;AACzH,SAAS,SAAS,CAAC,GAAW,EAAE,GAAwB;IACtD,IAAI,CAAC;QACH,OAAO,SAAS,CAAC,GAAG,EAAE,EAAE,QAAQ,EAAE,KAAK,EAAE,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,IAAI,CAAC,CAAC,KAAK,CAAC,CAAC;IACxG,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,EAAE,CAAC;IACZ,CAAC;AACH,CAAC"}
@@ -0,0 +1,19 @@
1
+ import type { HookOut } from '../skills/types.js';
2
+ import { skillsGate } from '../trace/skill-session.js';
3
+ import { type ProbeOpts } from '../skills/runblock.js';
4
+ import { type Consent } from './prompt-consent.js';
5
+ export { sessionStartSkills } from './start-skills.js';
6
+ export declare const PROMPT_DEADLINE_MS = 400;
7
+ /** What tests swap: g5's two calls, telemetry, the gate (a temp folder reads as scratch), the probes' git, the deadline's clock. */
8
+ export interface PromptDeps {
9
+ consent: Consent;
10
+ track: (event: string, props: Record<string, string>) => void;
11
+ gate: (input: unknown, dir: string, env?: NodeJS.ProcessEnv) => ReturnType<typeof skillsGate>;
12
+ probes: ProbeOpts;
13
+ clock: () => number;
14
+ /** Part 7: the file names of the learnings this session showed already (the prompt hook's and on-touch's one list). */
15
+ shown: () => ReadonlySet<string>;
16
+ }
17
+ /** 3.2. */
18
+ export declare function promptSkills(input: any, dir: string, env?: NodeJS.ProcessEnv, deps?: Partial<PromptDeps>): HookOut;
19
+ //# sourceMappingURL=prompt-skills.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"prompt-skills.d.ts","sourceRoot":"","sources":["../../src/claude/prompt-skills.ts"],"names":[],"mappings":"AAoBA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,oBAAoB,CAAC;AAIlD,OAAO,EAAiC,UAAU,EAAkC,MAAM,2BAA2B,CAAC;AAYtH,OAAO,EAA4G,KAAK,SAAS,EAAE,MAAM,uBAAuB,CAAC;AAGjK,OAAO,EAAwB,KAAK,OAAO,EAAE,MAAM,qBAAqB,CAAC;AAWzE,OAAO,EAAE,kBAAkB,EAAE,MAAM,mBAAmB,CAAC;AAEvD,eAAO,MAAM,kBAAkB,MAAM,CAAC;AAKtC,oIAAoI;AACpI,MAAM,WAAW,UAAU;IACzB,OAAO,EAAE,OAAO,CAAC;IACjB,KAAK,EAAE,CAAC,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,KAAK,IAAI,CAAC;IAC9D,IAAI,EAAE,CAAC,KAAK,EAAE,OAAO,EAAE,GAAG,EAAE,MAAM,EAAE,GAAG,CAAC,EAAE,MAAM,CAAC,UAAU,KAAK,UAAU,CAAC,OAAO,UAAU,CAAC,CAAC;IAC9F,MAAM,EAAE,SAAS,CAAC;IAClB,KAAK,EAAE,MAAM,MAAM,CAAC;IACpB,uHAAuH;IACvH,KAAK,EAAE,MAAM,WAAW,CAAC,MAAM,CAAC,CAAC;CAClC;AAKD,WAAW;AACX,wBAAgB,YAAY,CAAC,KAAK,EAAE,GAAG,EAAE,GAAG,EAAE,MAAM,EAAE,GAAG,GAAE,MAAM,CAAC,UAAwB,EAAE,IAAI,GAAE,OAAO,CAAC,UAAU,CAAM,GAAG,OAAO,CAoCnI"}
@@ -0,0 +1,305 @@
1
+ import { homedir } from 'node:os';
2
+ import { askText, matchJob } from '../trace/jobs.js';
3
+ import { isCorrection, isSaveRequest, scopeWords, typedPrompt, typedSha } from '../trace/typed.js';
4
+ import { currentRun, injectedThisEpoch, skillsGate, withSkillSession } from '../trace/skill-session.js';
5
+ import { lastGoodRun } from '../trace/run-verdict.js';
6
+ import { findPriorSheet, readRunSheet } from '../trace/runs.js';
7
+ import { track } from '../telemetry/track.js';
8
+ import { creditWindow, noteCorrectionLine, settleCredit } from '../skills/credit.js';
9
+ import { compileRun } from '../skills/compile.js';
10
+ import { refusalWords } from '../skills/compile-words.js';
11
+ import { hostFacts } from '../skills/host-facts.js';
12
+ import { resolveParams } from '../skills/params.js';
13
+ import { lastUsedIn } from '../skills/state.js';
14
+ import { nameTaken } from '../skills/store.js';
15
+ import { candidatesHere, matchCue, nameOf, normalizePrompt, refusedAtRecall, withRunParams } from '../skills/recall.js';
16
+ import { checkLine, injectionFor, readOnlyCheck, runBlock, runProbes, useNotice, withReadyFailed, PROBE_BUDGET_MS } from '../skills/runblock.js';
17
+ import { flatLine } from '../notes/flatten.js';
18
+ import { directive } from '../skills/directive-words.js';
19
+ import { consent as g5consent } from './prompt-consent.js';
20
+ import { canAsk, hookError, scopeKeys, sendAll, syncGate, trimInjected } from './skills-hook-util.js';
21
+ import { runCheckout } from '../skills/run-checkout.js';
22
+ import { lastResult, lastResultLine } from '../skills/check-result.js';
23
+ import { noteCodexPrompt } from '../trace/codex.js';
24
+ import { useFor } from '../trace/dialect.js';
25
+ import { stopBlockReason } from '../skills/offer-words.js';
26
+ import { recallMarks, saidIn, shownFiles, stepLearnings, withFixes } from '../skills/follow-learnings.js';
27
+ import { readSession } from './state.js';
28
+ import { payloadSessionId } from './hook-io.js';
29
+ export { sessionStartSkills } from './start-skills.js';
30
+ export const PROMPT_DEADLINE_MS = 400;
31
+ const LOCK_WAIT_MS = 150;
32
+ const LIVE_MS = 2 * 60 * 60 * 1000;
33
+ const MAX_ASK_WORDS = 25;
34
+ /** The telemetry answer for each class g5 reports (stale and not-shown were never answered: nothing is sent). */
35
+ const ANSWERED = { yes: 'yes', show: 'show', no: 'no', other: 'none', retire: 'retire' };
36
+ /** 3.2. */
37
+ export function promptSkills(input, dir, env = process.env, deps = {}) {
38
+ const clock = deps.clock ?? Date.now;
39
+ const deadline = clock() + PROMPT_DEADLINE_MS;
40
+ const sent = [];
41
+ try {
42
+ const g = (deps.gate ?? skillsGate)(input, dir, env);
43
+ if (!g.ok)
44
+ return {};
45
+ const ctx = g.ctx;
46
+ const typed = typedPrompt(String(input?.prompt ?? ''));
47
+ if (!typed)
48
+ return {};
49
+ const d = {
50
+ consent: deps.consent ?? g5consent,
51
+ track: deps.track ?? ((e, p) => track(e, p, { env: ctx.env, ...(ctx.checkout ? { repo: ctx.checkout } : {}) })),
52
+ gate: deps.gate ?? skillsGate,
53
+ probes: deps.probes ?? {},
54
+ clock,
55
+ shown: deps.shown ?? (() => {
56
+ try {
57
+ return shownFiles(readSession(dir, payloadSessionId(input)).injectedNotes);
58
+ }
59
+ catch {
60
+ return new Set();
61
+ }
62
+ }),
63
+ };
64
+ // Phase 2 (3.2 step 1, P30, R7): on Codex the prompt's keyed hash goes into the session first, before the catch-up
65
+ // reads the rollout, so the typed line already there counts as the person's. A prompt that is Trail's own Stop
66
+ // reason (a continuation, should Codex send one through UserPromptSubmit, HC3) is never the person's: nothing runs.
67
+ let own = false;
68
+ const prepare = ctx.host === 'codex' ? (st) => {
69
+ own = isOwnBlockReason(st, String(input?.prompt ?? ''), ctx.transcriptPath);
70
+ if (!own)
71
+ noteCodexPrompt(st, String(input?.prompt ?? ''), env);
72
+ } : undefined;
73
+ const out = withSkillSession(ctx, { catchUp: ctx.fold, waitMs: LOCK_WAIT_MS, ...(prepare ? { prepare } : {}) }, (st, fold) => (own ? {} : inside(ctx, st, fold, typed, d, deadline, sent)));
74
+ sendAll(sent, d.track);
75
+ return out ?? {};
76
+ }
77
+ catch (e) {
78
+ hookError('prompt', e, env);
79
+ return {};
80
+ }
81
+ }
82
+ function inside(ctx, st, fold, typed, d, deadline, sent) {
83
+ const { env, now } = ctx;
84
+ const context = [];
85
+ // 4. An answer to a pending offer: g5 records it; yes, show me and no end the prompt here. Phase 2 (4.9, D72, R1): a
86
+ // retire is checked against the reply before it in the transcript, so the hook passes where it is.
87
+ const cap = d.consent.captureAnswer(st, typed, env, now, { transcriptPath: ctx.transcriptPath });
88
+ if (cap.answer && ANSWERED[cap.answer])
89
+ sent.push(['skill_answer', { answer: ANSWERED[cap.answer] }]);
90
+ if (cap.changed === 'retire')
91
+ sent.push(['skill_changed', { op: 'retire' }]);
92
+ if (cap.out)
93
+ return cap.out;
94
+ if (cap.extra)
95
+ context.push(cap.extra);
96
+ // 5. Credit (D57): the run a block came in for may have closed with this catch-up; then the correction window.
97
+ if (ctx.learn) {
98
+ // 1b (4.19): a cue phrase dropped at the flush says so once.
99
+ const cueDropped = () => sent.push(['skill_stale', { reason: 'unfollowed' }]);
100
+ // c8 (4.9): a firing this settle writes is considered by the next Stop's retire proposal.
101
+ const fired = (f) => { if (!f.followed)
102
+ st.firedLater = [...(st.firedLater ?? []), f].slice(-4); };
103
+ for (const s of settleCredit(st, { host: ctx.host, env, now, sessionId: ctx.sessionId, cueDropped, fired }))
104
+ sent.push(['skill_used', { outcome: s.outcome }]);
105
+ creditWindow(st, isCorrection(typed) ? { sha: typedSha(typed) } : null, { env, now });
106
+ noteCorrectionLine(st, fold?.typed ?? []);
107
+ }
108
+ // 6. "Save this as a skill" (moment 1).
109
+ if (ctx.fold && isSaveRequest(typed)) {
110
+ context.push(saveAsk(ctx, st, fold, typed, d));
111
+ syncGate(ctx, st);
112
+ return { context: context.join('\n') };
113
+ }
114
+ const np = normalizePrompt(typed);
115
+ let cached = null;
116
+ const cands = () => (cached ??= (() => {
117
+ const r = candidatesHere({ repoKeys: scopeKeys(ctx, st), checkout: ctx.checkout, env });
118
+ // Phase 2 (4.6): a proposal the person copied over their file is Trail's own again.
119
+ for (const _ of r.adopted)
120
+ sent.push(['skill_changed', { op: 'adopted' }]);
121
+ return r.cands;
122
+ })());
123
+ // 7. Liveness, before the cue.
124
+ endBlocks(st, typed, np, now, cands, askRun(st, fold, typed));
125
+ // 8. The cue, while there is time for it.
126
+ let notice;
127
+ let said;
128
+ if (d.clock() < deadline) {
129
+ const mine = [...st.injected].reverse().find((i) => i.cue !== 'check');
130
+ // A block this session counts as used just now; otherwise the newest use here, within 24 hours.
131
+ const lastUsed = mine ? { id: mine.skillId, at: now.toISOString() } : lastUsedIn(scopeKeys(ctx, st), env);
132
+ const cue = matchCue(np, cands(), lastUsed, now);
133
+ // Reading a large store can use up the time: past the deadline, no block this prompt (never half of one).
134
+ if (!cue || d.clock() >= deadline) { /* nothing */ }
135
+ else if (cue.kind === 'check') {
136
+ const values = checkValues(cue, np, mine && mine.skillId === cue.cand.ref.id ? mine : null);
137
+ // D116 item 1: a check that changes things (the push that moved prod) is never one to run for a status
138
+ // question; the last run's recorded result answers instead.
139
+ const line = refusedAtRecall(cue.cand.skill, values) ? ''
140
+ : readOnlyCheck(cue.cand.skill) ? checkLine(cue.cand, values)
141
+ : lastResultLine(cue.cand, typed, lastResult(cue.cand, mine ?? null, st.runs, env));
142
+ if (line) {
143
+ context.push(line);
144
+ st.injected.push(injectionFor(cue.cand, values, 'check', st.epoch, now));
145
+ }
146
+ }
147
+ else {
148
+ const run = askRun(st, fold, typed);
149
+ // D118 b: what an earlier ask of this run named (the version) holds across its turns and re-sent blocks.
150
+ const r = bring(ctx, st, run ? withRunParams(cue, run.promptParams, np) : cue, d, deadline, run);
151
+ if (r) {
152
+ context.push(r.context);
153
+ notice = r.notice;
154
+ if (r.said?.length)
155
+ said = r.said;
156
+ }
157
+ }
158
+ }
159
+ trimInjected(st);
160
+ syncGate(ctx, st);
161
+ const out = {};
162
+ if (context.length)
163
+ out.context = context.join('\n');
164
+ if (notice)
165
+ out.notice = notice;
166
+ if (said)
167
+ out.said = said;
168
+ return out;
169
+ }
170
+ /** 4.16: the prompt is the Stop block reason Trail gave for the offer it holds (whitespace aside). */
171
+ function isOwnBlockReason(st, prompt, transcriptPath) {
172
+ const po = st.pendingOffer;
173
+ if (!po || po.channel !== 'stop' || !po.shownAt)
174
+ return false;
175
+ const flat = (t) => t.replace(/\s+/g, ' ').trim();
176
+ const reason = flat(stopBlockReason(po, transcriptPath, useFor('codex', st)));
177
+ return reason !== '' && flat(prompt) === reason;
178
+ }
179
+ /** 3.2 step 6. */
180
+ function saveAsk(ctx, st, fold, typed, d) {
181
+ const env = ctx.env;
182
+ const last = lastGoodRun(st, env);
183
+ if ('none' in last)
184
+ return directive(typed, nothingToKeep(last));
185
+ const { run, sheet } = last;
186
+ const scope = scopeWords(typed);
187
+ const keys = st.scopeKeys.includes(run.repoKey) ? st.scopeKeys : [run.repoKey];
188
+ // D93: the run's own checkout, as both halves of the save gate compile it.
189
+ const root = runCheckout(sheet, env, ctx.repoKey === sheet.repoKey ? ctx.checkout : '');
190
+ const compiled = compileRun(sheet, {
191
+ repoRoot: root, home: env.HOME || homedir(), platform: process.platform,
192
+ prior: findPriorSheet(sheet, env), moment: 'asked', applies: scope === 'every repo' ? 'every repo' : run.repoKey, now: ctx.now, askedWith: typed,
193
+ readSheet: (id) => readRunSheet(id, env), taken: (n) => nameTaken(n, { repoKeys: keys, checkout: root || ctx.checkout, env }) !== null,
194
+ learnings: stepLearnings({ repoKeys: [sheet.repoKey], checkout: root, env }),
195
+ });
196
+ if (!compiled.ok) {
197
+ const words = refusalWords(compiled.reason, compiled.detail);
198
+ return directive(typed, `Trail can't keep that job as a skill: ${words}. Let them know: "I can't keep that as a skill: ${words}."`);
199
+ }
200
+ d.consent.noteSaveRequest(st, fold, { runId: run.id, typed, scope, skill: compiled.skill }, env, ctx.now);
201
+ return directive(typed, `The last job here worked, so to keep it as they asked, run: trail skills add ${compiled.skill.name} --run ${run.id}. `
202
+ + 'Trail checks their words in this session before it keeps anything. Then tell them the line it prints.');
203
+ }
204
+ /** 3.2 step 6, no run to keep: Trail's reason, then the words for the person (D101). */
205
+ function nothingToKeep(last) {
206
+ if (last.none === 'skill') {
207
+ const name = flatLine(last.skillName ?? 'a skill', 60);
208
+ return `That job already ran from the skill ${name}, so Trail has nothing new to keep. Let them know: "That job already ran from the skill ${name}, so there's nothing new to keep."`;
209
+ }
210
+ if (last.none === 'failed') {
211
+ return `${ONLY_WORKED} and the last one didn't finish cleanly. Let them know: "There's nothing to keep yet: the last job didn't finish cleanly. Ask me again once it works."`;
212
+ }
213
+ if (last.none === 'unproven') {
214
+ return `${ONLY_WORKED} and the last command passed only through its fallback (|| echo, || true or || :), so Trail can't tell it worked. `
215
+ + 'Let them know: "There\'s nothing to keep yet: the last command only passed through its fallback, so I can\'t tell it worked. Ask me again once it works."';
216
+ }
217
+ return `${ONLY_WORKED} and no job has finished here since the conversation started or was last compacted. Let them know: "There's nothing to keep yet: no job has finished here since the conversation was last compacted. Ask me again once one works."`;
218
+ }
219
+ const ONLY_WORKED = 'Trail keeps only a job that worked,';
220
+ /**
221
+ * 3.2 step 7: another job, over 25 words or 2 hours end a block; a status question or a short follow-up keeps it.
222
+ * D116 item 3: a line the fold folded into the block's own run (a go-ahead, an answer to the agent's question) keeps
223
+ * it at any length: the block lives as long as its run.
224
+ */
225
+ function endBlocks(st, typed, np, now, cands, run) {
226
+ const live = st.injected.filter((i) => i.live);
227
+ if (!live.length)
228
+ return;
229
+ const job = np.status ? null : matchJob(askText(typed))?.job ?? null;
230
+ for (const inj of live) {
231
+ const age = now.getTime() - Date.parse(inj.at);
232
+ const skillJob = job === null ? null : cands().find((c) => c.ref.id === inj.skillId)?.skill.meta.job ?? null;
233
+ const ownRun = run !== null && inj.runId === run.id;
234
+ if (!(age < LIVE_MS) || (np.wordCount > MAX_ASK_WORDS && !ownRun) || (job !== null && job !== skillJob))
235
+ inj.live = false;
236
+ }
237
+ }
238
+ /** 3.2 step 8, job or name cue: a block, or a re-arm of the one this epoch already has. Null: its filled steps are refused. */
239
+ /**
240
+ * The run of this very prompt, when this hook's catch-up folded its typed line (Claude Code writes the line before
241
+ * the hook runs): the block it brings belongs to that run, and no other ask typed a moment before or after it.
242
+ * Null when the line isn't on disk yet (the next fold links the block) or it started no run.
243
+ */
244
+ function askRun(st, fold, typed) {
245
+ const last = fold?.typed[fold.typed.length - 1];
246
+ if (!last || last.sha !== typedSha(typed))
247
+ return null;
248
+ const run = currentRun(st);
249
+ return run && Date.parse(run.lastAt) >= Date.parse(last.at) ? run : null;
250
+ }
251
+ function bring(ctx, st, cue, d, deadline, run) {
252
+ const { env, now } = ctx;
253
+ const c = cue.cand;
254
+ // The risk rules on the steps as the block would show them, values filled in (a default can be edited by hand).
255
+ if (refusedAtRecall(c.skill, cue.values))
256
+ return null;
257
+ const prior = [...injectedThisEpoch(st)].reverse().find((i) => i.skillId === c.ref.id && i.cue !== 'check');
258
+ if (prior && sameValues(prior.params, cue.values)) {
259
+ // D65: a re-armed block is for the next ask's run. D137: after a hand-off it continues that block's run and window,
260
+ // but only while the fold continued that run (the 2-hour wait); a new run starts a new window with nothing handed.
261
+ if (prior.handed?.length && (run === null || run.id === prior.runId))
262
+ Object.assign(prior, { live: true, runId: run?.id ?? prior.runId });
263
+ else {
264
+ delete prior.handed;
265
+ Object.assign(prior, { live: true, at: now.toISOString(), runId: run?.id ?? null });
266
+ }
267
+ if (run)
268
+ run.skillId = c.ref.id;
269
+ return { context: `[trail] Same job as before: start from the steps of skill ${nameOf(c)} above.` };
270
+ }
271
+ // Part 7: what the person's live learnings say of these steps; the block says each once, and its steps are what credit reads.
272
+ // Read before the probes, so their budget is what is left. Past the deadline the block goes without them, and the prompt's learnings lines still say them.
273
+ const marks = d.clock() < deadline ? recallMarks(c.skill.steps, stepLearnings({ repoKeys: scopeKeys(ctx, st), checkout: ctx.checkout, env }), d.shown()) : [];
274
+ const budgetMs = Math.max(0, Math.min(PROBE_BUDGET_MS, deadline - d.clock()));
275
+ const probes = runProbes(c.skill, ctx.checkout, now, env, { ...d.probes, budgetMs });
276
+ const lastFail = c.state?.lastFails?.length ? c.state.lastFails[c.state.lastFails.length - 1] : null;
277
+ // Phase 2 (3.2 step 5): the anchors' CLI scan gets only what the 400 ms leave after the probes (the hook's clock may be a test's).
278
+ const anchorDeadline = Date.now() + Math.max(0, deadline - d.clock());
279
+ const block = runBlock(c, { values: cue.values, notes: cue.notes, probes, canAsk: canAsk(ctx), header: 'job', lastFail, anchorDeadline, marks });
280
+ const inj = withReadyFailed(injectionFor({ ...c, skill: withFixes(c.skill, marks) }, cue.values, cue.kind, st.epoch, now), probes);
281
+ if (run) {
282
+ inj.runId = run.id;
283
+ run.skillId = c.ref.id;
284
+ }
285
+ // New values: the full block replaces that injection's values and steps (same injId, a fresh run).
286
+ if (prior)
287
+ st.injected[st.injected.indexOf(prior)] = { ...inj, injId: prior.injId };
288
+ else
289
+ st.injected.push(inj);
290
+ const said = saidIn(block, marks);
291
+ return { context: block, ...(hostFacts(env, ctx.host).promptNotice ? { notice: useNotice(c) } : {}), ...(said.length ? { said } : {}) };
292
+ }
293
+ /** The check uses the values of the block it checks, and any the question itself names. */
294
+ function checkValues(cue, np, block) {
295
+ const defs = cue.cand.skill.params;
296
+ const plain = resolveParams(defs, {}).values;
297
+ const asked = Object.fromEntries(Object.entries(cue.values).filter(([k, v]) => plain[k] !== v));
298
+ return { ...cue.values, ...(block?.params ?? {}), ...asked };
299
+ }
300
+ const sameValues = (a, b) => {
301
+ const ka = Object.keys(a).sort();
302
+ const kb = Object.keys(b).sort();
303
+ return ka.length === kb.length && ka.every((k, i) => k === kb[i] && a[k] === b[k]);
304
+ };
305
+ //# sourceMappingURL=prompt-skills.js.map