@nanonets/graft 0.21.1 → 0.22.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 (348) hide show
  1. package/README.md +549 -315
  2. package/dist/app/review-process.d.ts.map +1 -1
  3. package/dist/app/review-process.js +6 -5
  4. package/dist/app/review-process.js.map +1 -1
  5. package/dist/app/sources.js +2 -2
  6. package/dist/app/sources.js.map +1 -1
  7. package/dist/ask/ask.d.ts +12 -6
  8. package/dist/ask/ask.d.ts.map +1 -1
  9. package/dist/ask/ask.js +28 -38
  10. package/dist/ask/ask.js.map +1 -1
  11. package/dist/bin/graft.d.ts +3 -0
  12. package/dist/bin/graft.d.ts.map +1 -0
  13. package/dist/bin/graft.js +8 -0
  14. package/dist/bin/graft.js.map +1 -0
  15. package/dist/bin/trail.d.ts +3 -0
  16. package/dist/bin/trail.d.ts.map +1 -0
  17. package/dist/bin/trail.js +6 -0
  18. package/dist/bin/trail.js.map +1 -0
  19. package/dist/blast/blast-cli.d.ts.map +1 -1
  20. package/dist/blast/blast-cli.js +2 -1
  21. package/dist/blast/blast-cli.js.map +1 -1
  22. package/dist/blast/render.d.ts.map +1 -1
  23. package/dist/blast/render.js +3 -2
  24. package/dist/blast/render.js.map +1 -1
  25. package/dist/brand.d.ts +97 -0
  26. package/dist/brand.d.ts.map +1 -0
  27. package/dist/brand.js +254 -0
  28. package/dist/brand.js.map +1 -0
  29. package/dist/check/local-check.d.ts +104 -0
  30. package/dist/check/local-check.d.ts.map +1 -0
  31. package/dist/check/local-check.js +830 -0
  32. package/dist/check/local-check.js.map +1 -0
  33. package/dist/check/types.d.ts +31 -0
  34. package/dist/check/types.d.ts.map +1 -0
  35. package/dist/check/types.js +2 -0
  36. package/dist/check/types.js.map +1 -0
  37. package/dist/claude/format.d.ts +44 -1
  38. package/dist/claude/format.d.ts.map +1 -1
  39. package/dist/claude/format.js +113 -19
  40. package/dist/claude/format.js.map +1 -1
  41. package/dist/claude/hook-layers.d.ts +8 -0
  42. package/dist/claude/hook-layers.d.ts.map +1 -0
  43. package/dist/claude/hook-layers.js +72 -0
  44. package/dist/claude/hook-layers.js.map +1 -0
  45. package/dist/claude/hooks.d.ts +34 -0
  46. package/dist/claude/hooks.d.ts.map +1 -1
  47. package/dist/claude/hooks.js +220 -12
  48. package/dist/claude/hooks.js.map +1 -1
  49. package/dist/claude/init.d.ts +12 -1
  50. package/dist/claude/init.d.ts.map +1 -1
  51. package/dist/claude/init.js +48 -19
  52. package/dist/claude/init.js.map +1 -1
  53. package/dist/claude/session-metrics.d.ts +1 -1
  54. package/dist/claude/session-metrics.d.ts.map +1 -1
  55. package/dist/claude/session-metrics.js +11 -8
  56. package/dist/claude/session-metrics.js.map +1 -1
  57. package/dist/claude/settings-merge.d.ts +1 -0
  58. package/dist/claude/settings-merge.d.ts.map +1 -1
  59. package/dist/claude/settings-merge.js +21 -18
  60. package/dist/claude/settings-merge.js.map +1 -1
  61. package/dist/claude/shim-template.d.ts +17 -2
  62. package/dist/claude/shim-template.d.ts.map +1 -1
  63. package/dist/claude/shim-template.js +116 -22
  64. package/dist/claude/shim-template.js.map +1 -1
  65. package/dist/claude/skill-template.d.ts +10 -1
  66. package/dist/claude/skill-template.d.ts.map +1 -1
  67. package/dist/claude/skill-template.js +132 -1
  68. package/dist/claude/skill-template.js.map +1 -1
  69. package/dist/claude/state.d.ts +8 -0
  70. package/dist/claude/state.d.ts.map +1 -1
  71. package/dist/claude/state.js.map +1 -1
  72. package/dist/claude/statusline.d.ts.map +1 -1
  73. package/dist/claude/statusline.js +4 -1
  74. package/dist/claude/statusline.js.map +1 -1
  75. package/dist/claude/tally.js +1 -1
  76. package/dist/claude/tally.js.map +1 -1
  77. package/dist/cli-epilogue.d.ts +0 -6
  78. package/dist/cli-epilogue.d.ts.map +1 -1
  79. package/dist/cli-epilogue.js +5 -4
  80. package/dist/cli-epilogue.js.map +1 -1
  81. package/dist/cli-meta.d.ts +8 -0
  82. package/dist/cli-meta.d.ts.map +1 -1
  83. package/dist/cli-meta.js +28 -8
  84. package/dist/cli-meta.js.map +1 -1
  85. package/dist/cli-picker.d.ts.map +1 -1
  86. package/dist/cli-picker.js +11 -7
  87. package/dist/cli-picker.js.map +1 -1
  88. package/dist/cli.d.ts +0 -5
  89. package/dist/cli.d.ts.map +1 -1
  90. package/dist/cli.js +1039 -559
  91. package/dist/cli.js.map +1 -1
  92. package/dist/cloud/diff.d.ts +18 -0
  93. package/dist/cloud/diff.d.ts.map +1 -0
  94. package/dist/cloud/diff.js +58 -0
  95. package/dist/cloud/diff.js.map +1 -0
  96. package/dist/cloud/nudge.d.ts +66 -0
  97. package/dist/cloud/nudge.d.ts.map +1 -0
  98. package/dist/cloud/nudge.js +269 -0
  99. package/dist/cloud/nudge.js.map +1 -0
  100. package/dist/cloud/workspace-sync.d.ts +58 -0
  101. package/dist/cloud/workspace-sync.d.ts.map +1 -0
  102. package/dist/cloud/workspace-sync.js +268 -0
  103. package/dist/cloud/workspace-sync.js.map +1 -0
  104. package/dist/cloud/workspace.d.ts +159 -0
  105. package/dist/cloud/workspace.d.ts.map +1 -0
  106. package/dist/cloud/workspace.js +134 -0
  107. package/dist/cloud/workspace.js.map +1 -0
  108. package/dist/context/check.d.ts +1 -1
  109. package/dist/context/check.d.ts.map +1 -1
  110. package/dist/context/check.js +9 -8
  111. package/dist/context/check.js.map +1 -1
  112. package/dist/context/node-file.js +1 -1
  113. package/dist/context/node-file.js.map +1 -1
  114. package/dist/context/savings.d.ts.map +1 -1
  115. package/dist/context/savings.js +10 -7
  116. package/dist/context/savings.js.map +1 -1
  117. package/dist/engine.d.ts.map +1 -1
  118. package/dist/engine.js +3 -1
  119. package/dist/engine.js.map +1 -1
  120. package/dist/graph/build.d.ts +30 -0
  121. package/dist/graph/build.d.ts.map +1 -1
  122. package/dist/graph/build.js +65 -19
  123. package/dist/graph/build.js.map +1 -1
  124. package/dist/graph/cards.d.ts.map +1 -1
  125. package/dist/graph/cards.js +4 -2
  126. package/dist/graph/cards.js.map +1 -1
  127. package/dist/graph/check.d.ts.map +1 -1
  128. package/dist/graph/check.js +17 -18
  129. package/dist/graph/check.js.map +1 -1
  130. package/dist/graph/container.d.ts.map +1 -1
  131. package/dist/graph/container.js +7 -2
  132. package/dist/graph/container.js.map +1 -1
  133. package/dist/graph/extract-cache.d.ts +4 -0
  134. package/dist/graph/extract-cache.d.ts.map +1 -1
  135. package/dist/graph/extract-cache.js.map +1 -1
  136. package/dist/graph/extract.d.ts +2 -0
  137. package/dist/graph/extract.d.ts.map +1 -1
  138. package/dist/graph/extract.js +5 -32
  139. package/dist/graph/extract.js.map +1 -1
  140. package/dist/graph/generic.d.ts +7 -1
  141. package/dist/graph/generic.d.ts.map +1 -1
  142. package/dist/graph/generic.js +48 -8
  143. package/dist/graph/generic.js.map +1 -1
  144. package/dist/graph/native.d.ts +38 -0
  145. package/dist/graph/native.d.ts.map +1 -0
  146. package/dist/graph/native.js +169 -0
  147. package/dist/graph/native.js.map +1 -0
  148. package/dist/graph/refresh.d.ts.map +1 -1
  149. package/dist/graph/refresh.js +3 -2
  150. package/dist/graph/refresh.js.map +1 -1
  151. package/dist/graph/traverse-cli.d.ts.map +1 -1
  152. package/dist/graph/traverse-cli.js +4 -3
  153. package/dist/graph/traverse-cli.js.map +1 -1
  154. package/dist/graph/workspace-cli.d.ts +2 -0
  155. package/dist/graph/workspace-cli.d.ts.map +1 -1
  156. package/dist/graph/workspace-cli.js +13 -1
  157. package/dist/graph/workspace-cli.js.map +1 -1
  158. package/dist/graph/workspace.d.ts.map +1 -1
  159. package/dist/graph/workspace.js +6 -5
  160. package/dist/graph/workspace.js.map +1 -1
  161. package/dist/hosts/antigravity.d.ts +10 -3
  162. package/dist/hosts/antigravity.d.ts.map +1 -1
  163. package/dist/hosts/antigravity.js +27 -10
  164. package/dist/hosts/antigravity.js.map +1 -1
  165. package/dist/hosts/claude-global.d.ts +27 -4
  166. package/dist/hosts/claude-global.d.ts.map +1 -1
  167. package/dist/hosts/claude-global.js +90 -9
  168. package/dist/hosts/claude-global.js.map +1 -1
  169. package/dist/hosts/codex-hooks.d.ts.map +1 -1
  170. package/dist/hosts/codex-hooks.js +1 -2
  171. package/dist/hosts/codex-hooks.js.map +1 -1
  172. package/dist/hosts/config-write.d.ts.map +1 -1
  173. package/dist/hosts/config-write.js +2 -1
  174. package/dist/hosts/config-write.js.map +1 -1
  175. package/dist/hosts/cursor-hooks.d.ts +5 -2
  176. package/dist/hosts/cursor-hooks.d.ts.map +1 -1
  177. package/dist/hosts/cursor-hooks.js +14 -9
  178. package/dist/hosts/cursor-hooks.js.map +1 -1
  179. package/dist/hosts/init.d.ts +3 -0
  180. package/dist/hosts/init.d.ts.map +1 -1
  181. package/dist/hosts/init.js +32 -10
  182. package/dist/hosts/init.js.map +1 -1
  183. package/dist/hosts/instructions.d.ts +9 -4
  184. package/dist/hosts/instructions.d.ts.map +1 -1
  185. package/dist/hosts/instructions.js +19 -16
  186. package/dist/hosts/instructions.js.map +1 -1
  187. package/dist/hosts/mcp-config.d.ts +19 -4
  188. package/dist/hosts/mcp-config.d.ts.map +1 -1
  189. package/dist/hosts/mcp-config.js +81 -30
  190. package/dist/hosts/mcp-config.js.map +1 -1
  191. package/dist/hosts/plan.d.ts.map +1 -1
  192. package/dist/hosts/plan.js +11 -9
  193. package/dist/hosts/plan.js.map +1 -1
  194. package/dist/hosts/registry.d.ts +25 -2
  195. package/dist/hosts/registry.d.ts.map +1 -1
  196. package/dist/hosts/registry.js +53 -0
  197. package/dist/hosts/registry.js.map +1 -1
  198. package/dist/hosts/retract.d.ts.map +1 -1
  199. package/dist/hosts/retract.js +73 -33
  200. package/dist/hosts/retract.js.map +1 -1
  201. package/dist/hosts/sections.d.ts +17 -1
  202. package/dist/hosts/sections.d.ts.map +1 -1
  203. package/dist/hosts/sections.js +52 -2
  204. package/dist/hosts/sections.js.map +1 -1
  205. package/dist/mcp/instructions.d.ts +1 -25
  206. package/dist/mcp/instructions.d.ts.map +1 -1
  207. package/dist/mcp/instructions.js +6 -4
  208. package/dist/mcp/instructions.js.map +1 -1
  209. package/dist/mcp/server.d.ts.map +1 -1
  210. package/dist/mcp/server.js +7 -3
  211. package/dist/mcp/server.js.map +1 -1
  212. package/dist/mcp/tool-names.d.ts +10 -3
  213. package/dist/mcp/tool-names.d.ts.map +1 -1
  214. package/dist/mcp/tool-names.js +13 -5
  215. package/dist/mcp/tool-names.js.map +1 -1
  216. package/dist/mcp/tools.d.ts.map +1 -1
  217. package/dist/mcp/tools.js +6 -5
  218. package/dist/mcp/tools.js.map +1 -1
  219. package/dist/notes/ask-notes.d.ts +8 -0
  220. package/dist/notes/ask-notes.d.ts.map +1 -0
  221. package/dist/notes/ask-notes.js +18 -0
  222. package/dist/notes/ask-notes.js.map +1 -0
  223. package/dist/notes/branches.d.ts +85 -0
  224. package/dist/notes/branches.d.ts.map +1 -0
  225. package/dist/notes/branches.js +238 -0
  226. package/dist/notes/branches.js.map +1 -0
  227. package/dist/notes/cold-start.d.ts +127 -0
  228. package/dist/notes/cold-start.d.ts.map +1 -0
  229. package/dist/notes/cold-start.js +476 -0
  230. package/dist/notes/cold-start.js.map +1 -0
  231. package/dist/notes/git-facts.d.ts +17 -0
  232. package/dist/notes/git-facts.d.ts.map +1 -0
  233. package/dist/notes/git-facts.js +117 -0
  234. package/dist/notes/git-facts.js.map +1 -0
  235. package/dist/notes/home.d.ts +87 -0
  236. package/dist/notes/home.d.ts.map +1 -0
  237. package/dist/notes/home.js +423 -0
  238. package/dist/notes/home.js.map +1 -0
  239. package/dist/notes/notes.d.ts +178 -0
  240. package/dist/notes/notes.d.ts.map +1 -0
  241. package/dist/notes/notes.js +498 -0
  242. package/dist/notes/notes.js.map +1 -0
  243. package/dist/notes/repo-trail.d.ts +16 -0
  244. package/dist/notes/repo-trail.d.ts.map +1 -0
  245. package/dist/notes/repo-trail.js +74 -0
  246. package/dist/notes/repo-trail.js.map +1 -0
  247. package/dist/notes/session-cost.d.ts +21 -0
  248. package/dist/notes/session-cost.d.ts.map +1 -0
  249. package/dist/notes/session-cost.js +162 -0
  250. package/dist/notes/session-cost.js.map +1 -0
  251. package/dist/search/grep-cli.d.ts.map +1 -1
  252. package/dist/search/grep-cli.js +4 -3
  253. package/dist/search/grep-cli.js.map +1 -1
  254. package/dist/skills/skills.d.ts +118 -0
  255. package/dist/skills/skills.d.ts.map +1 -0
  256. package/dist/skills/skills.js +370 -0
  257. package/dist/skills/skills.js.map +1 -0
  258. package/dist/telemetry/contract.d.ts +2 -14
  259. package/dist/telemetry/contract.d.ts.map +1 -1
  260. package/dist/telemetry/contract.js +39 -24
  261. package/dist/telemetry/contract.js.map +1 -1
  262. package/dist/telemetry/gate.d.ts.map +1 -1
  263. package/dist/telemetry/gate.js +2 -1
  264. package/dist/telemetry/gate.js.map +1 -1
  265. package/dist/telemetry/notice.d.ts +1 -1
  266. package/dist/telemetry/notice.d.ts.map +1 -1
  267. package/dist/telemetry/notice.js +6 -5
  268. package/dist/telemetry/notice.js.map +1 -1
  269. package/dist/telemetry/track.d.ts.map +1 -1
  270. package/dist/telemetry/track.js +5 -0
  271. package/dist/telemetry/track.js.map +1 -1
  272. package/dist/upkeep-run.d.ts +7 -0
  273. package/dist/upkeep-run.d.ts.map +1 -1
  274. package/dist/upkeep-run.js +52 -12
  275. package/dist/upkeep-run.js.map +1 -1
  276. package/dist/upkeep.d.ts +9 -19
  277. package/dist/upkeep.d.ts.map +1 -1
  278. package/dist/upkeep.js +38 -59
  279. package/dist/upkeep.js.map +1 -1
  280. package/dist/util/browser.d.ts +3 -0
  281. package/dist/util/browser.d.ts.map +1 -0
  282. package/dist/util/browser.js +14 -0
  283. package/dist/util/browser.js.map +1 -0
  284. package/dist/util/front-matter.d.ts +19 -0
  285. package/dist/util/front-matter.d.ts.map +1 -0
  286. package/dist/util/front-matter.js +21 -0
  287. package/dist/util/front-matter.js.map +1 -0
  288. package/dist/util/state.d.ts +1 -18
  289. package/dist/util/state.d.ts.map +1 -1
  290. package/dist/util/state.js +4 -2
  291. package/dist/util/state.js.map +1 -1
  292. package/dist/viz/assemble.js +1 -1
  293. package/dist/viz/assemble.js.map +1 -1
  294. package/dist/viz/serve.d.ts.map +1 -1
  295. package/dist/viz/serve.js +4 -3
  296. package/dist/viz/serve.js.map +1 -1
  297. package/package.json +7 -7
  298. package/scripts/pack-trail.mjs +53 -0
  299. package/scripts/postinstall.mjs +17 -2
  300. package/scripts/run-tests.mjs +4 -1
  301. package/dist/brain/attach.d.ts +0 -44
  302. package/dist/brain/attach.d.ts.map +0 -1
  303. package/dist/brain/attach.js +0 -63
  304. package/dist/brain/attach.js.map +0 -1
  305. package/dist/brain/claude-md.d.ts +0 -61
  306. package/dist/brain/claude-md.d.ts.map +0 -1
  307. package/dist/brain/claude-md.js +0 -171
  308. package/dist/brain/claude-md.js.map +0 -1
  309. package/dist/brain/connect.d.ts +0 -59
  310. package/dist/brain/connect.d.ts.map +0 -1
  311. package/dist/brain/connect.js +0 -80
  312. package/dist/brain/connect.js.map +0 -1
  313. package/dist/brain/context-files.d.ts +0 -79
  314. package/dist/brain/context-files.d.ts.map +0 -1
  315. package/dist/brain/context-files.js +0 -245
  316. package/dist/brain/context-files.js.map +0 -1
  317. package/dist/brain/link.d.ts +0 -106
  318. package/dist/brain/link.d.ts.map +0 -1
  319. package/dist/brain/link.js +0 -167
  320. package/dist/brain/link.js.map +0 -1
  321. package/dist/brain/pull.d.ts +0 -48
  322. package/dist/brain/pull.d.ts.map +0 -1
  323. package/dist/brain/pull.js +0 -257
  324. package/dist/brain/pull.js.map +0 -1
  325. package/dist/brain/push.d.ts +0 -155
  326. package/dist/brain/push.d.ts.map +0 -1
  327. package/dist/brain/push.js +0 -304
  328. package/dist/brain/push.js.map +0 -1
  329. package/dist/brain/signup.d.ts +0 -117
  330. package/dist/brain/signup.d.ts.map +0 -1
  331. package/dist/brain/signup.js +0 -276
  332. package/dist/brain/signup.js.map +0 -1
  333. package/dist/brain/upload.d.ts +0 -61
  334. package/dist/brain/upload.d.ts.map +0 -1
  335. package/dist/brain/upload.js +0 -210
  336. package/dist/brain/upload.js.map +0 -1
  337. package/dist/brain/watch.d.ts +0 -209
  338. package/dist/brain/watch.d.ts.map +0 -1
  339. package/dist/brain/watch.js +0 -397
  340. package/dist/brain/watch.js.map +0 -1
  341. package/dist/brain/wire.d.ts +0 -38
  342. package/dist/brain/wire.d.ts.map +0 -1
  343. package/dist/brain/wire.js +0 -133
  344. package/dist/brain/wire.js.map +0 -1
  345. package/dist/legacy-args.d.ts +0 -12
  346. package/dist/legacy-args.d.ts.map +0 -1
  347. package/dist/legacy-args.js +0 -31
  348. package/dist/legacy-args.js.map +0 -1
@@ -1,209 +0,0 @@
1
- /**
2
- * Watching a brain being built, from the terminal.
3
- *
4
- * `graft trail push` used to end at "it is being mined into rules now — a few
5
- * minutes. Watch it finish in your browser." and hand the prompt straight back.
6
- * That sentence is the last thing this process ever says about the work, and it
7
- * is said BEFORE the part that actually fails: of the repo brains attempted in
8
- * production, roughly a third die inside the miner, after the push succeeded.
9
- * The terminal has already returned by then, so on this side the failure does
10
- * not exist at all — and on a CI runner or over SSH, where nobody is going to
11
- * open a browser, it exists nowhere.
12
- *
13
- * So the push now holds the line and reports the same four stages the browser
14
- * shows, off the same row. Ctrl-C detaches without cancelling anything, because
15
- * the work is server-side and killing a watcher must never look like killing
16
- * the build.
17
- *
18
- * What it holds the line UNTIL changed with slicing. The history is now mined in
19
- * several calls rather than one, and the first of them returns in about ten
20
- * seconds; filing all of the rules into the graph takes minutes more. Mining is
21
- * where the failures are — the thing this watcher exists to report — and filing
22
- * is long, dull and reliable, so the line is held through the first and handed
23
- * back before the second. Holding a terminal through five minutes of successful
24
- * filing buys nobody anything, and on a CI runner it is five minutes of a job
25
- * sitting idle.
26
- */
27
- import type { BrainLink } from "./link.js";
28
- /** The stages, in the order they happen. The wording matches Trail's build
29
- * screen deliberately: two products describing one process differently is how
30
- * a person ends up unsure whether they are looking at the same thing. */
31
- export declare const STAGES: readonly [{
32
- readonly id: "reach";
33
- readonly label: "reaching the repository";
34
- }, {
35
- readonly id: "read";
36
- readonly label: "reading its history";
37
- }, {
38
- readonly id: "mine";
39
- readonly label: "mining the rules";
40
- }, {
41
- readonly id: "file";
42
- readonly label: "filing them into the brain";
43
- }];
44
- export type StageId = (typeof STAGES)[number]["id"];
45
- export type StageState = "waiting" | "doing" | "done" | "failed";
46
- export interface Stage {
47
- id: StageId;
48
- label: string;
49
- state: StageState;
50
- /** A count worth printing beside a stage that has produced one. */
51
- detail?: string;
52
- }
53
- /** The repo row, as the public endpoint returns it. Only the fields the stages
54
- * read, so a field added server-side cannot quietly change what is printed. */
55
- export interface RepoState {
56
- status: string;
57
- errorMessage?: string;
58
- ruleCount: number;
59
- commitCount: number;
60
- threadCount: number;
61
- /** Rules in the graph right now, from the job still running. The row's own
62
- * `ruleCount` is only written when that job finishes, so mid-build it is
63
- * zero however many rules are already there.
64
- *
65
- * Optional because an older Trail does not send it, and a graft pointed at
66
- * one must fall back to waiting for the finished row rather than reading a
67
- * missing field as "no rules". */
68
- filedSoFar?: number;
69
- /** Rules the miner has handed over so far. Grows with every slice of the
70
- * history that comes back, so it is a floor and never a total. */
71
- foundSoFar?: number;
72
- /** Suggested changes to the repo's context files, when Trail sends them. */
73
- suggestions?: Suggestions;
74
- }
75
- /**
76
- * The suggestions Trail has for this repository's context files so far.
77
- *
78
- * Counts, because that is all the terminal prints; the changes themselves are
79
- * reviewed in Trail and written by `graft trail pull`.
80
- */
81
- export interface Suggestions {
82
- /** Changes suggested for the root CLAUDE.md. */
83
- claudeMd: number;
84
- /** Changes suggested for every other context file, all kinds together. */
85
- contextFiles: number;
86
- /** Per file, when Trail lists them — which is what lets the count be cut to
87
- * the files the wired agents actually read. */
88
- files?: Array<{
89
- kind: string;
90
- path: string;
91
- changes: number;
92
- }>;
93
- }
94
- export interface BuildView {
95
- stages: Stage[];
96
- /**
97
- * True once rules are in the graph — which is when this watcher has nothing
98
- * left to report, not when the job ends. The rest of the slices keep mining
99
- * and filing after the prompt comes back.
100
- */
101
- ready: boolean;
102
- done: boolean;
103
- /** The server's own words, when it failed. */
104
- error: string | null;
105
- }
106
- /**
107
- * Which stage the work is in.
108
- *
109
- * The rule that matters is where a failure lands. A row that never left
110
- * `pending` failed at the access check; one that read 412 commits and then died
111
- * failed in the miner. Reporting both as "could not reach it" would send someone
112
- * to fix repository access for a problem that has nothing to do with it.
113
- */
114
- export declare function stagesFrom(repo: RepoState | null): BuildView;
115
- /**
116
- * The repo state out of an expected-repo body — the polled GET and every SSE
117
- * `progress` event carry the same shape. Null when there is no repo row.
118
- */
119
- export declare function parseRepoBody(body: unknown): RepoState | null;
120
- /**
121
- * Read the repo row this brain is building.
122
- *
123
- * The same endpoint `fetchExpectedRepo` uses, read for its counts rather than
124
- * its slug. Null on any failure, so a watcher that cannot reach the API prints
125
- * nothing new rather than inventing a failure the build did not have.
126
- */
127
- export declare function fetchRepoState(link: BrainLink, fetchImpl?: typeof fetch): Promise<RepoState | null>;
128
- /** What the spinner says while a stage is running. */
129
- export declare const DOING_LABEL: Record<StageId, string>;
130
- /** The first rules there are, from whichever count the row has. */
131
- export declare function rulesSoFar(repo: RepoState | null): number;
132
- /**
133
- * One printable line per stage that has finished since it was last printed.
134
- *
135
- * Only for a log with no terminal to redraw — on a TTY the spinner says which
136
- * stage is running and these lines are never printed. Filing is left out: the
137
- * watcher hands the prompt back on the first rules, before filing finishes, and
138
- * the closing line says how many there are.
139
- */
140
- export declare function linesFor(view: BuildView, already: Set<string>, repo?: RepoState | null): string[];
141
- /** The stage the build is in now, for the spinner. */
142
- export declare function currentStage(view: BuildView): StageId;
143
- /** The failure line: where it stopped, and that nothing was lost. The server's
144
- * own words follow on the next line, in full. */
145
- export declare function failureLines(view: BuildView): string[];
146
- export interface WatchOptions {
147
- /** How long to hold before giving up on a build that is still running. */
148
- timeoutMs?: number;
149
- pollMs?: number;
150
- fetchImpl?: typeof fetch;
151
- /** Where the lines go. Injected so the tests do not need a console. */
152
- write?: (line: string) => void;
153
- sleep?: (ms: number) => Promise<void>;
154
- /** Print a line per finished stage. Off on a TTY, where a spinner says it. */
155
- stageLines?: boolean;
156
- /** Every state read, with its view — the spinner's feed. */
157
- onState?: (view: BuildView, repo: RepoState) => void;
158
- /** Follow `GET /events` instead of polling (the server advertised `events`). */
159
- events?: boolean;
160
- /** Silence on the stream for this long counts as a drop. Keep-alives come every 15 s. */
161
- idleMs?: number;
162
- /** Stream reconnects before falling back to polling. */
163
- maxReconnects?: number;
164
- }
165
- /**
166
- * How the watch ended.
167
- *
168
- * `building` is the ordinary success: rules are in the brain and the rest of the
169
- * history is still being read behind the prompt. `completed` is the same thing
170
- * after the whole job has finished, which only happens for a repository small
171
- * enough to be mined in one slice.
172
- */
173
- export type WatchOutcome = "completed" | "building" | "failed" | "timed_out" | "unreachable";
174
- /**
175
- * Hold until the brain has rules, reporting each stage as it settles.
176
- *
177
- * Returns on the first rules rather than on the finished job: mining is what
178
- * fails and it is done by then, and filing the rest is minutes of work nobody
179
- * needs to watch. The caller prints where to see the rest.
180
- *
181
- * Live when the server streams events: each change arrives as it happens
182
- * instead of up to four seconds late. A stream that drops is reopened up to
183
- * three times, and after that the watcher polls as it always did — so the
184
- * worst a broken stream costs is the old behaviour.
185
- *
186
- * Fifteen minutes by default. That is far more than the mining now takes, and it
187
- * stays generous on purpose: a watcher that gives up before the build does would
188
- * report a healthy build as a timeout, which is the exact confusion this is
189
- * meant to remove. Giving up says so and says the work continues, because it
190
- * does.
191
- */
192
- export declare function watchBuild(link: BrainLink, opts?: WatchOptions): Promise<WatchOutcome>;
193
- /** One server-sent event. */
194
- export interface SseEvent {
195
- event: string;
196
- data: string;
197
- }
198
- /**
199
- * An incremental text/event-stream parser: feed it chunks as they arrive,
200
- * get back the events they completed. Comments (`: ping`) are dropped; a
201
- * missing `event:` field means `message`, per the spec.
202
- */
203
- export declare class SseParser {
204
- private buf;
205
- private event;
206
- private data;
207
- push(chunk: string): SseEvent[];
208
- }
209
- //# sourceMappingURL=watch.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AAE,CAAC,IAAI,EAAE,MAAM,KAAK,IAAI,CAAC;IAC/B,KAAK,CAAC,EAAE,CAAC,EAAE,EAAE,MAAM,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;IACtC,8EAA8E;IAC9E,UAAU,CAAC,EAAE,OAAO,CAAC;IACrB,4DAA4D;IAC5D,OAAO,CAAC,EAAE,CAAC,IAAI,EAAE,SAAS,EAAE,IAAI,EAAE,SAAS,KAAK,IAAI,CAAC;IACrD,gFAAgF;IAChF,MAAM,CAAC,EAAE,OAAO,CAAC;IACjB,yFAAyF;IACzF,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,wDAAwD;IACxD,aAAa,CAAC,EAAE,MAAM,CAAC;CACxB;AAED;;;;;;;GAOG;AACH,MAAM,MAAM,YAAY,GAAG,WAAW,GAAG,UAAU,GAAG,QAAQ,GAAG,WAAW,GAAG,aAAa,CAAC;AAE7F;;;;;;;;;;;;;;;;;GAiBG;AACH,wBAAsB,UAAU,CAAC,IAAI,EAAE,SAAS,EAAE,IAAI,GAAE,YAAiB,GAAG,OAAO,CAAC,YAAY,CAAC,CA6DhG;AAED,6BAA6B;AAC7B,MAAM,WAAW,QAAQ;IACvB,KAAK,EAAE,MAAM,CAAC;IACd,IAAI,EAAE,MAAM,CAAC;CACd;AAED;;;;GAIG;AACH,qBAAa,SAAS;IACpB,OAAO,CAAC,GAAG,CAAM;IACjB,OAAO,CAAC,KAAK,CAAM;IACnB,OAAO,CAAC,IAAI,CAAgB;IAE5B,IAAI,CAAC,KAAK,EAAE,MAAM,GAAG,QAAQ,EAAE;CA4BhC"}
@@ -1,397 +0,0 @@
1
- import { baseUrlFor } from "./link.js";
2
- /** The stages, in the order they happen. The wording matches Trail's build
3
- * screen deliberately: two products describing one process differently is how
4
- * a person ends up unsure whether they are looking at the same thing. */
5
- export const STAGES = [
6
- { id: "reach", label: "reaching the repository" },
7
- { id: "read", label: "reading its history" },
8
- { id: "mine", label: "mining the rules" },
9
- { id: "file", label: "filing them into the brain" },
10
- ];
11
- const num = (v) => (typeof v === "number" && v > 0 ? v : 0);
12
- /**
13
- * Which stage the work is in.
14
- *
15
- * The rule that matters is where a failure lands. A row that never left
16
- * `pending` failed at the access check; one that read 412 commits and then died
17
- * failed in the miner. Reporting both as "could not reach it" would send someone
18
- * to fix repository access for a problem that has nothing to do with it.
19
- */
20
- export function stagesFrom(repo) {
21
- const commits = num(repo?.commitCount);
22
- const threads = num(repo?.threadCount);
23
- const rules = num(repo?.ruleCount);
24
- const filedSoFar = num(repo?.filedSoFar);
25
- const foundSoFar = num(repo?.foundSoFar);
26
- const reached = !!repo && repo.status !== "pending";
27
- const readIt = commits > 0 || threads > 0;
28
- // Rules that exist, whether the job has finished writing its count or not.
29
- const hasRules = filedSoFar > 0 || rules > 0;
30
- const filed = rules > 0;
31
- const failed = repo?.status === "failed";
32
- const failedAt = !failed ? null : !reached || !readIt ? "reach" : !hasRules ? "mine" : "file";
33
- const order = STAGES.map((s) => s.id);
34
- const state = (id) => {
35
- if (failedAt === id)
36
- return "failed";
37
- if (failedAt && order.indexOf(id) > order.indexOf(failedAt))
38
- return "waiting";
39
- switch (id) {
40
- case "reach":
41
- return reached ? "done" : "doing";
42
- case "read":
43
- return readIt ? "done" : reached ? "doing" : "waiting";
44
- case "mine":
45
- // Done on the first slice's rules. The remaining slices are still being
46
- // mined at this point, behind the prompt this watcher is about to
47
- // return — which is the whole change.
48
- return hasRules ? "done" : readIt ? "doing" : "waiting";
49
- case "file":
50
- return filed ? "done" : hasRules ? "doing" : readIt ? "waiting" : "waiting";
51
- }
52
- };
53
- const detail = (id) => {
54
- if (id === "read" && (commits || threads)) {
55
- return [commits ? `${commits} commits` : null, threads ? `${threads} discussions` : null].filter(Boolean).join(", ");
56
- }
57
- // "so far" because the count grows with each slice that lands. Printing it
58
- // as a total would promise history that has not been read yet.
59
- if (id === "mine" && foundSoFar)
60
- return `${foundSoFar} rules so far`;
61
- if (id === "file" && rules)
62
- return `${rules} rules`;
63
- if (id === "file" && filedSoFar)
64
- return `${filedSoFar} rules so far`;
65
- return undefined;
66
- };
67
- return {
68
- stages: STAGES.map((s) => ({ id: s.id, label: s.label, state: state(s.id), detail: detail(s.id) })),
69
- ready: hasRules && !failed,
70
- done: repo?.status === "completed" && filed,
71
- error: failed ? (repo?.errorMessage?.trim() || "the read stopped before it finished") : null,
72
- };
73
- }
74
- /** A count from a field Trail may send as a number or as the list itself. */
75
- const countOf = (v) => (Array.isArray(v) ? v.length : num(v));
76
- /**
77
- * The repo state out of an expected-repo body — the polled GET and every SSE
78
- * `progress` event carry the same shape. Null when there is no repo row.
79
- */
80
- export function parseRepoBody(body) {
81
- const b = (body ?? {});
82
- if (!b.repo || typeof b.repo !== "object")
83
- return null;
84
- const state = {
85
- status: String(b.repo.status ?? ""),
86
- errorMessage: b.repo.error_message,
87
- ruleCount: num(b.repo.rule_count),
88
- commitCount: num(b.repo.commit_count),
89
- threadCount: num(b.repo.thread_count),
90
- filedSoFar: num(b.build?.filed_so_far),
91
- foundSoFar: num(b.build?.found_so_far),
92
- };
93
- const cf = b.context_files && typeof b.context_files === "object" ? b.context_files : b.context_files_progress;
94
- if (b.claude_md || cf) {
95
- const files = Array.isArray(cf?.files)
96
- ? cf.files
97
- .filter((f) => f && typeof f === "object")
98
- .map((f) => ({ kind: String(f.kind ?? ""), path: String(f.path ?? ""), changes: countOf(f.changes) }))
99
- : undefined;
100
- state.suggestions = {
101
- claudeMd: countOf(b.claude_md?.changes),
102
- contextFiles: cf?.changes !== undefined ? countOf(cf.changes) : (files ?? []).reduce((n, f) => n + f.changes, 0),
103
- ...(files ? { files } : {}),
104
- };
105
- }
106
- return state;
107
- }
108
- /**
109
- * Read the repo row this brain is building.
110
- *
111
- * The same endpoint `fetchExpectedRepo` uses, read for its counts rather than
112
- * its slug. Null on any failure, so a watcher that cannot reach the API prints
113
- * nothing new rather than inventing a failure the build did not have.
114
- */
115
- export async function fetchRepoState(link, fetchImpl = fetch) {
116
- try {
117
- const res = await fetchImpl(`${baseUrlFor(link)}/api/public/brains/${encodeURIComponent(link.brainId)}/repo`, {
118
- headers: { authorization: `Bearer ${link.token}`, accept: "application/json" },
119
- signal: AbortSignal.timeout(5000),
120
- });
121
- if (!res.ok)
122
- return null;
123
- return parseRepoBody(await res.json());
124
- }
125
- catch {
126
- return null;
127
- }
128
- }
129
- /** Past tense, for the no-TTY log: each line reports a stage that finished. */
130
- const DONE_LABEL = {
131
- reach: "reached the repository",
132
- read: "read its history",
133
- mine: "mined the rules",
134
- file: "filed them into the trail",
135
- };
136
- /** What the spinner says while a stage is running. */
137
- export const DOING_LABEL = {
138
- reach: "reaching the repository",
139
- read: "reading its history",
140
- mine: "mining rules",
141
- file: "filing the rules",
142
- };
143
- /** The first rules there are, from whichever count the row has. */
144
- export function rulesSoFar(repo) {
145
- return Math.max(num(repo?.ruleCount), num(repo?.filedSoFar), num(repo?.foundSoFar));
146
- }
147
- /**
148
- * One printable line per stage that has finished since it was last printed.
149
- *
150
- * Only for a log with no terminal to redraw — on a TTY the spinner says which
151
- * stage is running and these lines are never printed. Filing is left out: the
152
- * watcher hands the prompt back on the first rules, before filing finishes, and
153
- * the closing line says how many there are.
154
- */
155
- export function linesFor(view, already, repo = null) {
156
- const out = [];
157
- for (const s of view.stages) {
158
- if (s.state !== "done" || s.id === "file")
159
- continue;
160
- const key = `${s.id}:${s.state}`;
161
- if (already.has(key))
162
- continue;
163
- already.add(key);
164
- const rules = rulesSoFar(repo);
165
- const label = s.id === "mine" && rules > 0
166
- ? `mined the first ${rules.toLocaleString("en-US")} rule${rules === 1 ? "" : "s"}`
167
- : DONE_LABEL[s.id];
168
- out.push(` ✓ ${label}`);
169
- }
170
- return out;
171
- }
172
- /** The stage the build is in now, for the spinner. */
173
- export function currentStage(view) {
174
- return (view.stages.find((s) => s.state === "doing" || s.state === "failed") ?? view.stages[view.stages.length - 1]).id;
175
- }
176
- /** The failure line: where it stopped, and that nothing was lost. The server's
177
- * own words follow on the next line, in full. */
178
- export function failureLines(view) {
179
- const at = view.stages.find((s) => s.state === "failed")?.id ?? "mine";
180
- const lines = [`✗ the build stopped while ${DOING_LABEL[at]} · nothing was lost — run graft trail push again`];
181
- if (view.error)
182
- lines.push(` ${view.error}`);
183
- return lines;
184
- }
185
- /**
186
- * Hold until the brain has rules, reporting each stage as it settles.
187
- *
188
- * Returns on the first rules rather than on the finished job: mining is what
189
- * fails and it is done by then, and filing the rest is minutes of work nobody
190
- * needs to watch. The caller prints where to see the rest.
191
- *
192
- * Live when the server streams events: each change arrives as it happens
193
- * instead of up to four seconds late. A stream that drops is reopened up to
194
- * three times, and after that the watcher polls as it always did — so the
195
- * worst a broken stream costs is the old behaviour.
196
- *
197
- * Fifteen minutes by default. That is far more than the mining now takes, and it
198
- * stays generous on purpose: a watcher that gives up before the build does would
199
- * report a healthy build as a timeout, which is the exact confusion this is
200
- * meant to remove. Giving up says so and says the work continues, because it
201
- * does.
202
- */
203
- export async function watchBuild(link, opts = {}) {
204
- const timeoutMs = opts.timeoutMs ?? 15 * 60 * 1000;
205
- const pollMs = opts.pollMs ?? 4000;
206
- const write = opts.write ?? ((l) => console.error(l));
207
- // Not unref'd: between polls this timer is the only thing the process is
208
- // waiting on, and an unref'd one let it exit mid-watch with nothing printed.
209
- const sleep = opts.sleep ?? ((ms) => new Promise((r) => setTimeout(r, ms)));
210
- const fetchImpl = opts.fetchImpl ?? fetch;
211
- const stageLines = opts.stageLines !== false;
212
- const printed = new Set();
213
- const startedAt = Date.now();
214
- const deadline = startedAt + timeoutMs;
215
- // A row we could never read at all, as opposed to one that answered once and
216
- // then stopped answering: the first is a broken link or a host that is down
217
- // and is worth saying, the second is a blip the next poll usually covers.
218
- let everRead = false;
219
- /** One state read → the outcome it settles, or null to keep watching. */
220
- const settle = (repo) => {
221
- if (!repo)
222
- return null;
223
- everRead = true;
224
- const view = stagesFrom(repo);
225
- opts.onState?.(view, repo);
226
- if (stageLines)
227
- for (const line of linesFor(view, printed, repo))
228
- write(line);
229
- if (view.error) {
230
- for (const line of failureLines(view))
231
- write(line);
232
- return "failed";
233
- }
234
- if (view.done)
235
- return "completed";
236
- // The ordinary ending now. The job is still filing the rules the miner
237
- // has handed over, and still mining the older slices of the history, and
238
- // neither is worth a terminal sitting on it.
239
- if (view.ready)
240
- return "building";
241
- return null;
242
- };
243
- if (opts.events) {
244
- let drops = 0;
245
- const maxReconnects = opts.maxReconnects ?? 3;
246
- while (drops <= maxReconnects && Date.now() < deadline) {
247
- const r = await streamOnce(link, fetchImpl, settle, deadline, opts.idleMs ?? 45_000);
248
- if (r.outcome)
249
- return r.outcome;
250
- if (r.end === "unsupported" || r.end === "deadline")
251
- break;
252
- if (r.end === "done") {
253
- // The build ended without the event saying how: read the row once.
254
- const final = settle(await fetchRepoState(link, fetchImpl));
255
- if (final)
256
- return final;
257
- break;
258
- }
259
- drops++;
260
- if (drops <= maxReconnects)
261
- await sleep(Math.min(1000 * drops, 4000));
262
- }
263
- }
264
- for (;;) {
265
- const outcome = settle(await fetchRepoState(link, fetchImpl));
266
- if (outcome)
267
- return outcome;
268
- if (Date.now() >= deadline)
269
- return everRead ? "timed_out" : "unreachable";
270
- await sleep(pollMs);
271
- }
272
- }
273
- /**
274
- * An incremental text/event-stream parser: feed it chunks as they arrive,
275
- * get back the events they completed. Comments (`: ping`) are dropped; a
276
- * missing `event:` field means `message`, per the spec.
277
- */
278
- export class SseParser {
279
- buf = "";
280
- event = "";
281
- data = [];
282
- push(chunk) {
283
- this.buf += chunk;
284
- const out = [];
285
- for (;;) {
286
- const nl = this.buf.search(/\r\n|\r|\n/);
287
- if (nl < 0)
288
- break;
289
- const sep = this.buf.startsWith("\r\n", nl) ? 2 : 1;
290
- // A lone \r at the very end may be the first half of \r\n: wait for more.
291
- if (this.buf[nl] === "\r" && sep === 1 && nl === this.buf.length - 1)
292
- break;
293
- const line = this.buf.slice(0, nl);
294
- this.buf = this.buf.slice(nl + sep);
295
- if (line === "") {
296
- if (this.data.length > 0)
297
- out.push({ event: this.event || "message", data: this.data.join("\n") });
298
- this.event = "";
299
- this.data = [];
300
- continue;
301
- }
302
- if (line.startsWith(":"))
303
- continue;
304
- const colon = line.indexOf(":");
305
- const field = colon < 0 ? line : line.slice(0, colon);
306
- let value = colon < 0 ? "" : line.slice(colon + 1);
307
- if (value.startsWith(" "))
308
- value = value.slice(1);
309
- if (field === "event")
310
- this.event = value;
311
- else if (field === "data")
312
- this.data.push(value);
313
- // id and retry are not used: a reconnect starts from a fresh `progress`.
314
- }
315
- return out;
316
- }
317
- }
318
- /**
319
- * One connection to `GET /events`. Resolves with the outcome when an event
320
- * settled the watch, or with how the stream ended when none did.
321
- */
322
- async function streamOnce(link, fetchImpl, settle, deadline, idleMs) {
323
- const ctl = new AbortController();
324
- let res;
325
- try {
326
- res = await fetchImpl(`${baseUrlFor(link)}/api/public/brains/${encodeURIComponent(link.brainId)}/events`, {
327
- headers: { authorization: `Bearer ${link.token}`, accept: "text/event-stream", "cache-control": "no-cache" },
328
- signal: ctl.signal,
329
- });
330
- }
331
- catch {
332
- return { end: "dropped" };
333
- }
334
- // A server without the route, or one that answered with something other
335
- // than a stream: polling is the answer, not three more tries.
336
- if (res.status === 404 || res.status === 405 || res.status === 501)
337
- return { end: "unsupported" };
338
- if (!res.ok)
339
- return { end: "dropped" };
340
- const type = res.headers?.get?.("content-type") ?? "text/event-stream";
341
- if (!res.body || !/event-stream/i.test(type))
342
- return { end: "unsupported" };
343
- const reader = res.body.getReader();
344
- const decoder = new TextDecoder();
345
- const parser = new SseParser();
346
- try {
347
- for (;;) {
348
- const left = deadline - Date.now();
349
- if (left <= 0)
350
- return { end: "deadline" };
351
- let timer;
352
- const idle = new Promise((r) => {
353
- // Not unref'd: while the stream is quiet this timer is what the
354
- // process is waiting on, and it is cleared the moment a chunk lands.
355
- timer = setTimeout(() => r("idle"), Math.min(idleMs, left));
356
- });
357
- const got = await Promise.race([reader.read(), idle]).finally(() => clearTimeout(timer));
358
- if (got === "idle")
359
- return { end: Date.now() >= deadline ? "deadline" : "dropped" };
360
- if (got.done)
361
- return { end: "dropped" };
362
- for (const ev of parser.push(decoder.decode(got.value, { stream: true }))) {
363
- let payload = null;
364
- try {
365
- payload = ev.data ? JSON.parse(ev.data) : null;
366
- }
367
- catch {
368
- payload = null;
369
- }
370
- if (ev.event === "progress" || ev.event === "message") {
371
- const outcome = settle(parseRepoBody(payload));
372
- if (outcome)
373
- return { outcome };
374
- }
375
- else if (ev.event === "done") {
376
- const outcome = settle(parseRepoBody(payload));
377
- if (outcome)
378
- return { outcome };
379
- return { end: "done" };
380
- }
381
- }
382
- }
383
- }
384
- catch {
385
- return { end: "dropped" };
386
- }
387
- finally {
388
- ctl.abort();
389
- try {
390
- reader.releaseLock();
391
- }
392
- catch {
393
- /* already released by the abort */
394
- }
395
- }
396
- }
397
- //# sourceMappingURL=watch.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"watch.js","sourceRoot":"","sources":["../../src/brain/watch.ts"],"names":[],"mappings":"AA2BA,OAAO,EAAE,UAAU,EAAE,MAAM,WAAW,CAAC;AAEvC;;0EAE0E;AAC1E,MAAM,CAAC,MAAM,MAAM,GAAG;IACpB,EAAE,EAAE,EAAE,OAAO,EAAE,KAAK,EAAE,yBAAyB,EAAE;IACjD,EAAE,EAAE,EAAE,MAAM,EAAE,KAAK,EAAE,qBAAqB,EAAE;IAC5C,EAAE,EAAE,EAAE,MAAM,EAAE,KAAK,EAAE,kBAAkB,EAAE;IACzC,EAAE,EAAE,EAAE,MAAM,EAAE,KAAK,EAAE,4BAA4B,EAAE;CAC3C,CAAC;AAiEX,MAAM,GAAG,GAAG,CAAC,CAAU,EAAU,EAAE,CAAC,CAAC,OAAO,CAAC,KAAK,QAAQ,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;AAE7E;;;;;;;GAOG;AACH,MAAM,UAAU,UAAU,CAAC,IAAsB;IAC/C,MAAM,OAAO,GAAG,GAAG,CAAC,IA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