pi-kot 0.1.21 → 0.1.22

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/bin/pi-kot.mjs +148 -0
  2. package/client/assets/KaTeX_AMS-Regular-BQhdFMY1.woff2 +0 -0
  3. package/client/assets/KaTeX_AMS-Regular-DMm9YOAa.woff +0 -0
  4. package/client/assets/KaTeX_AMS-Regular-DRggAlZN.ttf +0 -0
  5. package/client/assets/KaTeX_Caligraphic-Bold-ATXxdsX0.ttf +0 -0
  6. package/client/assets/KaTeX_Caligraphic-Bold-BEiXGLvX.woff +0 -0
  7. package/client/assets/KaTeX_Caligraphic-Bold-Dq_IR9rO.woff2 +0 -0
  8. package/client/assets/KaTeX_Caligraphic-Regular-CTRA-rTL.woff +0 -0
  9. package/client/assets/KaTeX_Caligraphic-Regular-Di6jR-x-.woff2 +0 -0
  10. package/client/assets/KaTeX_Caligraphic-Regular-wX97UBjC.ttf +0 -0
  11. package/client/assets/KaTeX_Fraktur-Bold-BdnERNNW.ttf +0 -0
  12. package/client/assets/KaTeX_Fraktur-Bold-BsDP51OF.woff +0 -0
  13. package/client/assets/KaTeX_Fraktur-Bold-CL6g_b3V.woff2 +0 -0
  14. package/client/assets/KaTeX_Fraktur-Regular-CB_wures.ttf +0 -0
  15. package/client/assets/KaTeX_Fraktur-Regular-CTYiF6lA.woff2 +0 -0
  16. package/client/assets/KaTeX_Fraktur-Regular-Dxdc4cR9.woff +0 -0
  17. package/client/assets/KaTeX_Main-Bold-Cx986IdX.woff2 +0 -0
  18. package/client/assets/KaTeX_Main-Bold-Jm3AIy58.woff +0 -0
  19. package/client/assets/KaTeX_Main-Bold-waoOVXN0.ttf +0 -0
  20. package/client/assets/KaTeX_Main-BoldItalic-DxDJ3AOS.woff2 +0 -0
  21. package/client/assets/KaTeX_Main-BoldItalic-DzxPMmG6.ttf +0 -0
  22. package/client/assets/KaTeX_Main-BoldItalic-SpSLRI95.woff +0 -0
  23. package/client/assets/KaTeX_Main-Italic-3WenGoN9.ttf +0 -0
  24. package/client/assets/KaTeX_Main-Italic-BMLOBm91.woff +0 -0
  25. package/client/assets/KaTeX_Main-Italic-NWA7e6Wa.woff2 +0 -0
  26. package/client/assets/KaTeX_Main-Regular-B22Nviop.woff2 +0 -0
  27. package/client/assets/KaTeX_Main-Regular-Dr94JaBh.woff +0 -0
  28. package/client/assets/KaTeX_Main-Regular-ypZvNtVU.ttf +0 -0
  29. package/client/assets/KaTeX_Math-BoldItalic-B3XSjfu4.ttf +0 -0
  30. package/client/assets/KaTeX_Math-BoldItalic-CZnvNsCZ.woff2 +0 -0
  31. package/client/assets/KaTeX_Math-BoldItalic-iY-2wyZ7.woff +0 -0
  32. package/client/assets/KaTeX_Math-Italic-DA0__PXp.woff +0 -0
  33. package/client/assets/KaTeX_Math-Italic-flOr_0UB.ttf +0 -0
  34. package/client/assets/KaTeX_Math-Italic-t53AETM-.woff2 +0 -0
  35. package/client/assets/KaTeX_SansSerif-Bold-CFMepnvq.ttf +0 -0
  36. package/client/assets/KaTeX_SansSerif-Bold-D1sUS0GD.woff2 +0 -0
  37. package/client/assets/KaTeX_SansSerif-Bold-DbIhKOiC.woff +0 -0
  38. package/client/assets/KaTeX_SansSerif-Italic-C3H0VqGB.woff2 +0 -0
  39. package/client/assets/KaTeX_SansSerif-Italic-DN2j7dab.woff +0 -0
  40. package/client/assets/KaTeX_SansSerif-Italic-YYjJ1zSn.ttf +0 -0
  41. package/client/assets/KaTeX_SansSerif-Regular-BNo7hRIc.ttf +0 -0
  42. package/client/assets/KaTeX_SansSerif-Regular-CS6fqUqJ.woff +0 -0
  43. package/client/assets/KaTeX_SansSerif-Regular-DDBCnlJ7.woff2 +0 -0
  44. package/client/assets/KaTeX_Script-Regular-C5JkGWo-.ttf +0 -0
  45. package/client/assets/KaTeX_Script-Regular-D3wIWfF6.woff2 +0 -0
  46. package/client/assets/KaTeX_Script-Regular-D5yQViql.woff +0 -0
  47. package/client/assets/KaTeX_Size1-Regular-C195tn64.woff +0 -0
  48. package/client/assets/KaTeX_Size1-Regular-Dbsnue_I.ttf +0 -0
  49. package/client/assets/KaTeX_Size1-Regular-mCD8mA8B.woff2 +0 -0
  50. package/client/assets/KaTeX_Size2-Regular-B7gKUWhC.ttf +0 -0
  51. package/client/assets/KaTeX_Size2-Regular-Dy4dx90m.woff2 +0 -0
  52. package/client/assets/KaTeX_Size2-Regular-oD1tc_U0.woff +0 -0
  53. package/client/assets/KaTeX_Size3-Regular-CTq5MqoE.woff +0 -0
  54. package/client/assets/KaTeX_Size3-Regular-DgpXs0kz.ttf +0 -0
  55. package/client/assets/KaTeX_Size4-Regular-BF-4gkZK.woff +0 -0
  56. package/client/assets/KaTeX_Size4-Regular-DWFBv043.ttf +0 -0
  57. package/client/assets/KaTeX_Size4-Regular-Dl5lxZxV.woff2 +0 -0
  58. package/client/assets/KaTeX_Typewriter-Regular-C0xS9mPB.woff +0 -0
  59. package/client/assets/KaTeX_Typewriter-Regular-CO6r4hn1.woff2 +0 -0
  60. package/client/assets/KaTeX_Typewriter-Regular-D3Ib7_Hf.ttf +0 -0
  61. package/client/assets/index-CE_Na97I.js +75 -0
  62. package/client/assets/index-CE_Na97I.js.map +1 -0
  63. package/client/assets/index-QP95zkpd.css +1 -0
  64. package/client/assets/rolldown-runtime-QTnfLwEv.js +1 -0
  65. package/client/assets/vendor-codemirror-CD3uCqRj.js +48 -0
  66. package/client/assets/vendor-codemirror-CD3uCqRj.js.map +1 -0
  67. package/client/assets/vendor-icons-W8thHNMl.js +2 -0
  68. package/client/assets/vendor-icons-W8thHNMl.js.map +1 -0
  69. package/client/assets/vendor-katex-4z5K3dyr.js +260 -0
  70. package/client/assets/vendor-katex-4z5K3dyr.js.map +1 -0
  71. package/client/assets/vendor-katex-CYlHEDRF.css +1 -0
  72. package/client/assets/vendor-markdown-BSzxNR_7.js +35 -0
  73. package/client/assets/vendor-markdown-BSzxNR_7.js.map +1 -0
  74. package/client/assets/vendor-prism-CQGp13s2.js +4 -0
  75. package/client/assets/vendor-prism-CQGp13s2.js.map +1 -0
  76. package/client/assets/vendor-xterm-BrP-ENHg.css +1 -0
  77. package/client/assets/vendor-xterm-DXwh06H3.js +36 -0
  78. package/client/assets/vendor-xterm-DXwh06H3.js.map +1 -0
  79. package/client/index.html +23 -0
  80. package/package.json +5 -3
  81. package/server/ask-user-question/envelope.d.ts +11 -0
  82. package/server/ask-user-question/envelope.d.ts.map +1 -0
  83. package/server/ask-user-question/envelope.js +41 -0
  84. package/server/ask-user-question/envelope.js.map +1 -0
  85. package/server/ask-user-question/plan-mode-question-tool.d.ts +26 -0
  86. package/server/ask-user-question/plan-mode-question-tool.d.ts.map +1 -0
  87. package/server/ask-user-question/plan-mode-question-tool.js +273 -0
  88. package/server/ask-user-question/plan-mode-question-tool.js.map +1 -0
  89. package/server/ask-user-question/prompt-strings.d.ts +4 -0
  90. package/server/ask-user-question/prompt-strings.d.ts.map +1 -0
  91. package/server/ask-user-question/prompt-strings.js +18 -0
  92. package/server/ask-user-question/prompt-strings.js.map +1 -0
  93. package/server/ask-user-question/registry.d.ts +39 -0
  94. package/server/ask-user-question/registry.d.ts.map +1 -0
  95. package/server/ask-user-question/registry.js +124 -0
  96. package/server/ask-user-question/registry.js.map +1 -0
  97. package/server/ask-user-question/tool.d.ts +4 -0
  98. package/server/ask-user-question/tool.d.ts.map +1 -0
  99. package/server/ask-user-question/tool.js +68 -0
  100. package/server/ask-user-question/tool.js.map +1 -0
  101. package/server/ask-user-question/types.d.ts +50 -0
  102. package/server/ask-user-question/types.d.ts.map +1 -0
  103. package/server/ask-user-question/types.js +7 -0
  104. package/server/ask-user-question/types.js.map +1 -0
  105. package/server/ask-user-question/validate.d.ts +3 -0
  106. package/server/ask-user-question/validate.d.ts.map +1 -0
  107. package/server/ask-user-question/validate.js +67 -0
  108. package/server/ask-user-question/validate.js.map +1 -0
  109. package/server/clone-provider.d.ts +55 -0
  110. package/server/clone-provider.d.ts.map +1 -0
  111. package/server/clone-provider.js +172 -0
  112. package/server/clone-provider.js.map +1 -0
  113. package/server/compaction-cards.d.ts +62 -0
  114. package/server/compaction-cards.d.ts.map +1 -0
  115. package/server/compaction-cards.js +180 -0
  116. package/server/compaction-cards.js.map +1 -0
  117. package/server/compaction-continuation.d.ts +112 -0
  118. package/server/compaction-continuation.d.ts.map +1 -0
  119. package/server/compaction-continuation.js +65 -0
  120. package/server/compaction-continuation.js.map +1 -0
  121. package/server/config-store.d.ts +97 -0
  122. package/server/config-store.d.ts.map +1 -0
  123. package/server/config-store.js +351 -0
  124. package/server/config-store.js.map +1 -0
  125. package/server/config.d.ts +24 -0
  126. package/server/config.d.ts.map +1 -0
  127. package/server/config.js +67 -0
  128. package/server/config.js.map +1 -0
  129. package/server/event-stream.d.ts +28 -0
  130. package/server/event-stream.d.ts.map +1 -0
  131. package/server/event-stream.js +153 -0
  132. package/server/event-stream.js.map +1 -0
  133. package/server/extension-manager.d.ts +116 -0
  134. package/server/extension-manager.d.ts.map +1 -0
  135. package/server/extension-manager.js +586 -0
  136. package/server/extension-manager.js.map +1 -0
  137. package/server/extension-scanner.d.ts +26 -0
  138. package/server/extension-scanner.d.ts.map +1 -0
  139. package/server/extension-scanner.js +107 -0
  140. package/server/extension-scanner.js.map +1 -0
  141. package/server/extension-ui-bridge.d.ts +35 -0
  142. package/server/extension-ui-bridge.d.ts.map +1 -0
  143. package/server/extension-ui-bridge.js +228 -0
  144. package/server/extension-ui-bridge.js.map +1 -0
  145. package/server/file-manager.d.ts +79 -0
  146. package/server/file-manager.d.ts.map +1 -0
  147. package/server/file-manager.js +535 -0
  148. package/server/file-manager.js.map +1 -0
  149. package/server/file-searcher.d.ts +29 -0
  150. package/server/file-searcher.d.ts.map +1 -0
  151. package/server/file-searcher.js +318 -0
  152. package/server/file-searcher.js.map +1 -0
  153. package/server/git-operations.d.ts +346 -0
  154. package/server/git-operations.d.ts.map +1 -0
  155. package/server/git-operations.js +884 -0
  156. package/server/git-operations.js.map +1 -0
  157. package/server/hunk-stager.d.ts +56 -0
  158. package/server/hunk-stager.d.ts.map +1 -0
  159. package/server/hunk-stager.js +137 -0
  160. package/server/hunk-stager.js.map +1 -0
  161. package/server/index.d.ts +21 -0
  162. package/server/index.d.ts.map +1 -0
  163. package/server/index.js +262 -0
  164. package/server/index.js.map +1 -0
  165. package/server/mcp/config.d.ts +23 -0
  166. package/server/mcp/config.d.ts.map +1 -0
  167. package/server/mcp/config.js +139 -0
  168. package/server/mcp/config.js.map +1 -0
  169. package/server/mcp/manager.d.ts +40 -0
  170. package/server/mcp/manager.d.ts.map +1 -0
  171. package/server/mcp/manager.js +435 -0
  172. package/server/mcp/manager.js.map +1 -0
  173. package/server/mcp/stdio-trust.d.ts +5 -0
  174. package/server/mcp/stdio-trust.d.ts.map +1 -0
  175. package/server/mcp/stdio-trust.js +78 -0
  176. package/server/mcp/stdio-trust.js.map +1 -0
  177. package/server/mcp/tool-bridge.d.ts +33 -0
  178. package/server/mcp/tool-bridge.d.ts.map +1 -0
  179. package/server/mcp/tool-bridge.js +138 -0
  180. package/server/mcp/tool-bridge.js.map +1 -0
  181. package/server/orchestration/config.d.ts +5 -0
  182. package/server/orchestration/config.d.ts.map +1 -0
  183. package/server/orchestration/config.js +35 -0
  184. package/server/orchestration/config.js.map +1 -0
  185. package/server/orchestration/event-bridge.d.ts +32 -0
  186. package/server/orchestration/event-bridge.d.ts.map +1 -0
  187. package/server/orchestration/event-bridge.js +110 -0
  188. package/server/orchestration/event-bridge.js.map +1 -0
  189. package/server/orchestration/inbox.d.ts +9 -0
  190. package/server/orchestration/inbox.d.ts.map +1 -0
  191. package/server/orchestration/inbox.js +186 -0
  192. package/server/orchestration/inbox.js.map +1 -0
  193. package/server/orchestration/init.d.ts +2 -0
  194. package/server/orchestration/init.d.ts.map +1 -0
  195. package/server/orchestration/init.js +22 -0
  196. package/server/orchestration/init.js.map +1 -0
  197. package/server/orchestration/store.d.ts +33 -0
  198. package/server/orchestration/store.d.ts.map +1 -0
  199. package/server/orchestration/store.js +331 -0
  200. package/server/orchestration/store.js.map +1 -0
  201. package/server/orchestration/tools.d.ts +15 -0
  202. package/server/orchestration/tools.d.ts.map +1 -0
  203. package/server/orchestration/tools.js +621 -0
  204. package/server/orchestration/tools.js.map +1 -0
  205. package/server/orchestration/types.d.ts +68 -0
  206. package/server/orchestration/types.d.ts.map +1 -0
  207. package/server/orchestration/types.js +43 -0
  208. package/server/orchestration/types.js.map +1 -0
  209. package/server/orchestration/worker-lifecycle.d.ts +15 -0
  210. package/server/orchestration/worker-lifecycle.d.ts.map +1 -0
  211. package/server/orchestration/worker-lifecycle.js +45 -0
  212. package/server/orchestration/worker-lifecycle.js.map +1 -0
  213. package/server/path-refs.d.ts +5 -0
  214. package/server/path-refs.d.ts.map +1 -0
  215. package/server/path-refs.js +249 -0
  216. package/server/path-refs.js.map +1 -0
  217. package/server/routes/_schemas.d.ts +16 -0
  218. package/server/routes/_schemas.d.ts.map +1 -0
  219. package/server/routes/_schemas.js +12 -0
  220. package/server/routes/_schemas.js.map +1 -0
  221. package/server/routes/ask-user-question.d.ts +3 -0
  222. package/server/routes/ask-user-question.d.ts.map +1 -0
  223. package/server/routes/ask-user-question.js +105 -0
  224. package/server/routes/ask-user-question.js.map +1 -0
  225. package/server/routes/auth.d.ts +8 -0
  226. package/server/routes/auth.d.ts.map +1 -0
  227. package/server/routes/auth.js +225 -0
  228. package/server/routes/auth.js.map +1 -0
  229. package/server/routes/config.d.ts +3 -0
  230. package/server/routes/config.d.ts.map +1 -0
  231. package/server/routes/config.js +602 -0
  232. package/server/routes/config.js.map +1 -0
  233. package/server/routes/control.d.ts +3 -0
  234. package/server/routes/control.d.ts.map +1 -0
  235. package/server/routes/control.js +365 -0
  236. package/server/routes/control.js.map +1 -0
  237. package/server/routes/exec.d.ts +3 -0
  238. package/server/routes/exec.d.ts.map +1 -0
  239. package/server/routes/exec.js +426 -0
  240. package/server/routes/exec.js.map +1 -0
  241. package/server/routes/extension-commands.d.ts +22 -0
  242. package/server/routes/extension-commands.d.ts.map +1 -0
  243. package/server/routes/extension-commands.js +178 -0
  244. package/server/routes/extension-commands.js.map +1 -0
  245. package/server/routes/extensions.d.ts +8 -0
  246. package/server/routes/extensions.d.ts.map +1 -0
  247. package/server/routes/extensions.js +414 -0
  248. package/server/routes/extensions.js.map +1 -0
  249. package/server/routes/files.d.ts +3 -0
  250. package/server/routes/files.d.ts.map +1 -0
  251. package/server/routes/files.js +835 -0
  252. package/server/routes/files.js.map +1 -0
  253. package/server/routes/git.d.ts +3 -0
  254. package/server/routes/git.d.ts.map +1 -0
  255. package/server/routes/git.js +1058 -0
  256. package/server/routes/git.js.map +1 -0
  257. package/server/routes/mcp.d.ts +3 -0
  258. package/server/routes/mcp.d.ts.map +1 -0
  259. package/server/routes/mcp.js +403 -0
  260. package/server/routes/mcp.js.map +1 -0
  261. package/server/routes/orchestration.d.ts +3 -0
  262. package/server/routes/orchestration.d.ts.map +1 -0
  263. package/server/routes/orchestration.js +251 -0
  264. package/server/routes/orchestration.js.map +1 -0
  265. package/server/routes/projects.d.ts +3 -0
  266. package/server/routes/projects.d.ts.map +1 -0
  267. package/server/routes/projects.js +421 -0
  268. package/server/routes/projects.js.map +1 -0
  269. package/server/routes/prompt.d.ts +3 -0
  270. package/server/routes/prompt.d.ts.map +1 -0
  271. package/server/routes/prompt.js +311 -0
  272. package/server/routes/prompt.js.map +1 -0
  273. package/server/routes/session-extensions.d.ts +11 -0
  274. package/server/routes/session-extensions.d.ts.map +1 -0
  275. package/server/routes/session-extensions.js +171 -0
  276. package/server/routes/session-extensions.js.map +1 -0
  277. package/server/routes/sessions.d.ts +3 -0
  278. package/server/routes/sessions.d.ts.map +1 -0
  279. package/server/routes/sessions.js +706 -0
  280. package/server/routes/sessions.js.map +1 -0
  281. package/server/routes/skills.d.ts +14 -0
  282. package/server/routes/skills.d.ts.map +1 -0
  283. package/server/routes/skills.js +448 -0
  284. package/server/routes/skills.js.map +1 -0
  285. package/server/routes/stream.d.ts +3 -0
  286. package/server/routes/stream.d.ts.map +1 -0
  287. package/server/routes/stream.js +112 -0
  288. package/server/routes/stream.js.map +1 -0
  289. package/server/routes/terminal.d.ts +28 -0
  290. package/server/routes/terminal.d.ts.map +1 -0
  291. package/server/routes/terminal.js +211 -0
  292. package/server/routes/terminal.js.map +1 -0
  293. package/server/routes/tunnel.d.ts +13 -0
  294. package/server/routes/tunnel.d.ts.map +1 -0
  295. package/server/routes/tunnel.js +231 -0
  296. package/server/routes/tunnel.js.map +1 -0
  297. package/server/session-alerts.d.ts +28 -0
  298. package/server/session-alerts.d.ts.map +1 -0
  299. package/server/session-alerts.js +38 -0
  300. package/server/session-alerts.js.map +1 -0
  301. package/server/session-store.d.ts +164 -0
  302. package/server/session-store.d.ts.map +1 -0
  303. package/server/session-store.js +754 -0
  304. package/server/session-store.js.map +1 -0
  305. package/server/skill-policy.d.ts +47 -0
  306. package/server/skill-policy.d.ts.map +1 -0
  307. package/server/skill-policy.js +178 -0
  308. package/server/skill-policy.js.map +1 -0
  309. package/server/terminal-provider.d.ts +54 -0
  310. package/server/terminal-provider.d.ts.map +1 -0
  311. package/server/terminal-provider.js +220 -0
  312. package/server/terminal-provider.js.map +1 -0
  313. package/server/tool-policy.d.ts +39 -0
  314. package/server/tool-policy.d.ts.map +1 -0
  315. package/server/tool-policy.js +121 -0
  316. package/server/tool-policy.js.map +1 -0
  317. package/server/tunnel/executable-search.d.ts +43 -0
  318. package/server/tunnel/executable-search.d.ts.map +1 -0
  319. package/server/tunnel/executable-search.js +148 -0
  320. package/server/tunnel/executable-search.js.map +1 -0
  321. package/server/tunnel/install-help.d.ts +19 -0
  322. package/server/tunnel/install-help.d.ts.map +1 -0
  323. package/server/tunnel/install-help.js +47 -0
  324. package/server/tunnel/install-help.js.map +1 -0
  325. package/server/tunnel/providers/ngrok.d.ts +31 -0
  326. package/server/tunnel/providers/ngrok.d.ts.map +1 -0
  327. package/server/tunnel/providers/ngrok.js +461 -0
  328. package/server/tunnel/providers/ngrok.js.map +1 -0
  329. package/server/tunnel/registry.d.ts +13 -0
  330. package/server/tunnel/registry.d.ts.map +1 -0
  331. package/server/tunnel/registry.js +56 -0
  332. package/server/tunnel/registry.js.map +1 -0
  333. package/server/tunnel/service.d.ts +13 -0
  334. package/server/tunnel/service.d.ts.map +1 -0
  335. package/server/tunnel/service.js +156 -0
  336. package/server/tunnel/service.js.map +1 -0
  337. package/server/tunnel/types.d.ts +163 -0
  338. package/server/tunnel/types.d.ts.map +1 -0
  339. package/server/tunnel/types.js +214 -0
  340. package/server/tunnel/types.js.map +1 -0
  341. package/server/ui-settings-store.d.ts +25 -0
  342. package/server/ui-settings-store.d.ts.map +1 -0
  343. package/server/ui-settings-store.js +91 -0
  344. package/server/ui-settings-store.js.map +1 -0
  345. package/server/workspace-store.d.ts +25 -0
  346. package/server/workspace-store.d.ts.map +1 -0
  347. package/server/workspace-store.js +157 -0
  348. package/server/workspace-store.js.map +1 -0
@@ -0,0 +1,180 @@
1
+ function isCompactionEntry(e) {
2
+ return e.type === "compaction";
3
+ }
4
+ function isMessageEntry(e) {
5
+ return e.type === "message";
6
+ }
7
+ /**
8
+ * Walk `session.sessionManager.getEntries()` once and produce one
9
+ * CompactionEvent per CompactionEntry. The mapping back to a position
10
+ * in `session.messages` is the tricky part: the post-compaction
11
+ * messages array is rebuilt from the entries that come AT or AFTER
12
+ * the latest compaction's `firstKeptEntryId`, with the compaction
13
+ * summary itself synthesised in. We compute `insertBeforeIndex` by
14
+ * counting how many "kept" message entries appear in `messages`
15
+ * before the position where this compaction's first-kept entry lands.
16
+ */
17
+ export function buildCompactionHistory(session) {
18
+ const entries = session.sessionManager.getEntries();
19
+ const compactions = [];
20
+ for (const e of entries)
21
+ if (isCompactionEntry(e))
22
+ compactions.push(e);
23
+ if (compactions.length === 0)
24
+ return [];
25
+ // Walk entries in order; for each compaction event, capture the
26
+ // message entries between the previous compaction (or session start)
27
+ // and this one. Those are the "archived" messages — the ones that
28
+ // were summarised and dropped.
29
+ const events = [];
30
+ let archiveBuffer = [];
31
+ for (const entry of entries) {
32
+ if (isMessageEntry(entry)) {
33
+ archiveBuffer.push(entry.message);
34
+ continue;
35
+ }
36
+ if (isCompactionEntry(entry)) {
37
+ // Estimate what the kept context size was AFTER this compaction
38
+ // by counting tokens for all message entries from firstKeptEntryId
39
+ // to the end of the entries array.
40
+ const estimatedTokensAfter = estimateKeptTokens(entries, entry.firstKeptEntryId);
41
+ events.push({
42
+ id: entry.id,
43
+ timestamp: entry.timestamp,
44
+ summary: entry.summary,
45
+ tokensBefore: entry.tokensBefore,
46
+ estimatedTokensAfter: estimatedTokensAfter > 0 ? estimatedTokensAfter : undefined,
47
+ // Filled in below — depends on the index of `firstKeptEntryId`
48
+ // within the *kept* portion of the messages stream.
49
+ insertBeforeIndex: 0,
50
+ archivedMessages: archiveBuffer,
51
+ });
52
+ // Reset for the next archive window. Anything between this
53
+ // compaction and the next one (or end of session) belongs to
54
+ // the next event's archive — but only if there IS a next
55
+ // compaction. If not, those messages live in `session.messages`
56
+ // and don't need archiving.
57
+ archiveBuffer = [];
58
+ }
59
+ }
60
+ // Compute insertBeforeIndex for each event. Given a compaction whose
61
+ // firstKeptEntryId points at message-entry M, the number of message
62
+ // entries BEFORE M (within the post-this-compaction kept portion of
63
+ // the entries array) tells us where to splice the card.
64
+ //
65
+ // For the LAST compaction, the kept portion lines up with what
66
+ // session.messages actually contains, so we can count message
67
+ // entries from `firstKeptEntryId` forward up to the compaction's
68
+ // own position. Earlier compactions' kept portions were re-archived
69
+ // by later compactions — those events sit at the TOP of the
70
+ // (current) display, so insertBeforeIndex = 0 for all but the last.
71
+ // (Once a compaction's kept window has itself been archived, no
72
+ // post-compaction message in `session.messages` corresponds to it,
73
+ // so the only sensible position is "before everything else".)
74
+ for (let i = 0; i < events.length - 1; i++) {
75
+ const ev = events[i];
76
+ if (ev !== undefined)
77
+ ev.insertBeforeIndex = 0;
78
+ }
79
+ const last = events[events.length - 1];
80
+ if (last !== undefined) {
81
+ const lastCompaction = compactions[compactions.length - 1];
82
+ if (lastCompaction !== undefined) {
83
+ last.insertBeforeIndex = countMessagesBetween(entries, lastCompaction.firstKeptEntryId, lastCompaction.id);
84
+ }
85
+ }
86
+ return events;
87
+ }
88
+ /**
89
+ * Estimate token count for a single message using char/4 heuristic.
90
+ * Mirrors the SDK's `estimateTokens()` in `core/compaction/compaction.ts`.
91
+ */
92
+ function estimateMessageTokens(msg) {
93
+ const m = msg;
94
+ let chars = 0;
95
+ // Roles with a `content` field: user, assistant, toolResult, custom
96
+ const content = m.content;
97
+ if (typeof content === "string") {
98
+ chars += content.length;
99
+ }
100
+ else if (Array.isArray(content)) {
101
+ for (const block of content) {
102
+ const b = block;
103
+ if (b.type === "text" && typeof b.text === "string") {
104
+ chars += b.text.length;
105
+ }
106
+ else if (b.type === "thinking" && typeof b.thinking === "string") {
107
+ chars += b.thinking.length;
108
+ }
109
+ else if (b.type === "toolCall") {
110
+ chars += typeof b.name === "string" ? b.name.length : 0;
111
+ try {
112
+ chars += typeof b.arguments === "string"
113
+ ? b.arguments.length
114
+ : JSON.stringify(b.arguments).length;
115
+ }
116
+ catch { /* skip unstringifiable */ }
117
+ }
118
+ else if (b.type === "image") {
119
+ chars += 4800; // ESTIMATED_IMAGE_CHARS — same value as the SDK
120
+ }
121
+ }
122
+ }
123
+ // compactionSummary / branchSummary roles: carry `summary` instead of `content`
124
+ if (typeof m.summary === "string") {
125
+ chars = m.summary.length;
126
+ }
127
+ // bashExecution: carries `command` + `output`
128
+ if (typeof m.command === "string") {
129
+ chars += m.command.length;
130
+ }
131
+ if (typeof m.output === "string") {
132
+ chars += m.output.length;
133
+ }
134
+ return Math.ceil(chars / 4);
135
+ }
136
+ /**
137
+ * Walk message entries from `firstKeptEntryId` to the end of the entries
138
+ * array and estimate their total tokens. This gives us the
139
+ * `estimatedTokensAfter` — the approximate size of the kept context
140
+ * right after compaction.
141
+ */
142
+ function estimateKeptTokens(entries, firstKeptEntryId) {
143
+ const startIdx = entries.findIndex((e) => e.id === firstKeptEntryId);
144
+ if (startIdx === -1)
145
+ return 0;
146
+ let total = 0;
147
+ for (let i = startIdx; i < entries.length; i++) {
148
+ const e = entries[i];
149
+ if (e === undefined)
150
+ break;
151
+ if (isMessageEntry(e)) {
152
+ total += estimateMessageTokens(e.message);
153
+ }
154
+ }
155
+ return total;
156
+ }
157
+ /**
158
+ * Count message-typed entries between two entry ids (exclusive of the
159
+ * end id). Returns the position where the compaction card should
160
+ * splice into `session.messages`. When `firstKeptEntryId` doesn't
161
+ * resolve (legacy session, manual JSONL edit), returns 0 — the card
162
+ * lands at the top of the chat, which is the safe fallback.
163
+ */
164
+ function countMessagesBetween(entries, firstKeptEntryId, endEntryId) {
165
+ const startIdx = entries.findIndex((e) => e.id === firstKeptEntryId);
166
+ if (startIdx === -1)
167
+ return 0;
168
+ let count = 0;
169
+ for (let i = startIdx; i < entries.length; i++) {
170
+ const e = entries[i];
171
+ if (e === undefined)
172
+ break;
173
+ if (e.id === endEntryId)
174
+ break;
175
+ if (isMessageEntry(e))
176
+ count++;
177
+ }
178
+ return count;
179
+ }
180
+ //# sourceMappingURL=compaction-cards.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"compaction-cards.js","sourceRoot":"","sources":["../src/compaction-cards.ts"],"names":[],"mappings":"AAoEA,SAAS,iBAAiB,CAAC,CAAe;IACxC,OAAO,CAAC,CAAC,IAAI,KAAK,YAAY,CAAC;AACjC,CAAC;AAED,SAAS,cAAc,CAAC,CAAe;IACrC,OAAO,CAAC,CAAC,IAAI,KAAK,SAAS,CAAC;AAC9B,CAAC;AAED;;;;;;;;;GASG;AACH,MAAM,UAAU,sBAAsB,CAAC,OAAqB;IAC1D,MAAM,OAAO,GAAG,OAAO,CAAC,cAAc,CAAC,UAAU,EAAE,CAAC;IACpD,MAAM,WAAW,GAA4C,EAAE,CAAC;IAChE,KAAK,MAAM,CAAC,IAAI,OAAO;QAAE,IAAI,iBAAiB,CAAC,CAAC,CAAC;Y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CAAC,GAAG,OAAO,CAAC,CAAC,CAAC,CAAC;QACrB,IAAI,CAAC,KAAK,SAAS;YAAE,MAAM;QAC3B,IAAI,CAAC,CAAC,EAAE,KAAK,UAAU;YAAE,MAAM;QAC/B,IAAI,cAAc,CAAC,CAAC,CAAC;YAAE,KAAK,EAAE,CAAC;IACjC,CAAC;IACD,OAAO,KAAK,CAAC;AACf,CAAC"}
@@ -0,0 +1,112 @@
1
+ /**
2
+ * In-process pi extension that nudges the model to KEEP WORKING on
3
+ * the in-progress task after an overflow-driven auto-compaction,
4
+ * instead of producing a prose status report that paraphrases the
5
+ * compaction summary's "Next Steps" section.
6
+ *
7
+ * ## The problem this solves
8
+ *
9
+ * When the LLM rejects a request with a context-overflow error, the
10
+ * pi SDK auto-compacts and calls `agent.continue()` to resume the
11
+ * loop. The model then sees:
12
+ *
13
+ * - system prompt + tool defs
14
+ * - <kept-recent messages — whatever fit under keepRecentTokens>
15
+ * - <compactionSummary> — a structured doc with sections "## Goal",
16
+ * "## Progress (Done / In Progress / Blocked)", "## Next Steps",
17
+ * "## Critical Context"
18
+ *
19
+ * The failed assistant message was stripped by the SDK (per the
20
+ * overflow path in `agent-session.js:_checkCompaction`), so the
21
+ * `compactionSummary` is the LAST message and the next model output
22
+ * starts a fresh turn. Strong models (Claude, GPT-4) usually infer
23
+ * "I'm mid-task — pick up where I left off." Weaker / smaller local
24
+ * models (Gemma-class on vLLM in particular) read the structured
25
+ * summary as a status report addressed TO them and respond with
26
+ * prose paraphrasing the "Next Steps" section instead of actually
27
+ * doing the work. End-effect: the agent stops making progress right
28
+ * when the user needs it to keep going.
29
+ *
30
+ * The next action might be a tool call, a final answer, a follow-up
31
+ * question, or anything else the task requires — we don't prescribe
32
+ * the shape, we just say "keep going."
33
+ *
34
+ * ## How this extension fixes it
35
+ *
36
+ * Registers a `context` event handler. The `context` event fires
37
+ * BEFORE every LLM request, with the messages array that's about to
38
+ * be sent. We never mutate the session itself — we append a
39
+ * synthetic user message to the OUTBOUND copy only. The handler:
40
+ *
41
+ * 1. Looks at the messages array.
42
+ * 2. If the LAST message is a `compactionSummary`, the model is
43
+ * about to receive a fresh post-compaction context with no
44
+ * forward prompt. Append `NUDGE_MESSAGE` — a one-line
45
+ * imperative telling the model to resume by calling tools.
46
+ * 3. Otherwise (last message is a user prompt, assistant turn, or
47
+ * tool result), do nothing. Threshold compactions don't auto-
48
+ * continue so the user types the next prompt themselves — which
49
+ * becomes the last message — and provides the imperative
50
+ * naturally.
51
+ *
52
+ * The nudge is sent to the LLM but NOT persisted to the session
53
+ * JSONL, so it doesn't leak into compaction summaries, tree views,
54
+ * or session exports.
55
+ *
56
+ * ## Why the `context` hook and not `session_before_compact`
57
+ *
58
+ * `session_before_compact` would let us replace the entire
59
+ * compaction (cancel it, or provide our own). To append text to the
60
+ * SDK-generated summary we'd have to re-implement summarization
61
+ * (call the SDK's exported `compact()` helper, mutate the result,
62
+ * return it). That works but is heavier and couples us to internal
63
+ * SDK shapes. The `context` hook is lighter: SDK does its own
64
+ * summarization, we just inject the imperative at LLM-call time.
65
+ *
66
+ * ## Why a user message and not a system / custom message
67
+ *
68
+ * The `context` hook returns an `AgentMessage[]` that the SDK passes
69
+ * to the provider. Providers expect a system prompt + a user/assistant
70
+ * dialogue; injecting a synthetic `system` mid-stream is non-standard
71
+ * and reorders cache. A trailing user message is the cheapest signal
72
+ * the model interprets as "respond to this now."
73
+ *
74
+ * Useful for nudging the model to continue after an auto-compaction.
75
+ */
76
+ import type { ExtensionFactory } from "@earendil-works/pi-coding-agent";
77
+ import type { AgentMessage } from "@earendil-works/pi-agent-core";
78
+ /**
79
+ * The text the LLM sees as a synthetic user message after an
80
+ * overflow-driven auto-compaction. Tuned to be imperative and brief:
81
+ *
82
+ * - "Continue the task in progress" — open-ended about what the
83
+ * next step is. The agent may need to call a tool, write a
84
+ * final answer, ask a follow-up question, or anything else the
85
+ * task requires. We don't prescribe the shape; we just say
86
+ * keep going.
87
+ * - "Do not write a summary of what you were doing" — names the
88
+ * observed failure mode (model paraphrases the summary's
89
+ * "Next Steps" instead of acting).
90
+ * - "Pick up from where you left off" — frames the summary as
91
+ * reference material, not as a fresh prompt addressed to the
92
+ * model.
93
+ *
94
+ * Kept under 250 characters so the addition to LLM input is
95
+ * negligible (~50 tokens).
96
+ */
97
+ export declare const NUDGE_MESSAGE: string;
98
+ /**
99
+ * Inspect a messages array and decide whether the post-compaction
100
+ * nudge should be appended. Exported separately so the unit test can
101
+ * exercise the boundary cases (empty, only summary, summary then user
102
+ * prompt, summary then assistant turn) without booting a full SDK
103
+ * session.
104
+ */
105
+ export declare function shouldNudgeAfterCompaction(messages: readonly AgentMessage[]): boolean;
106
+ /**
107
+ * Pi extension factory. Registered via `DefaultResourceLoader`'s
108
+ * `extensionFactories` option in `session-store.ts`. No I/O,
109
+ * no async setup — just registers the handler and returns.
110
+ */
111
+ export declare const compactionContinuationExtension: ExtensionFactory;
112
+ //# sourceMappingURL=compaction-continuation.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"compaction-continuation.d.ts","sourceRoot":"","sources":["../src/compaction-continuation.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA0EG;AACH,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,iCAAiC,CAAC;AACxE,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,+BAA+B,CAAC;AAElE;;;;;;;;;;;;;;;;;;GAkBG;AACH,eAAO,MAAM,aAAa,QAG0C,CAAC;AAErE;;;;;;GAMG;AACH,wBAAgB,0BAA0B,CAAC,QAAQ,EAAE,SAAS,YAAY,EAAE,GAAG,OAAO,CAIrF;AAiBD;;;;GAIG;AACH,eAAO,MAAM,+BAA+B,EAAE,gBAS7C,CAAC"}
@@ -0,0 +1,65 @@
1
+ /**
2
+ * The text the LLM sees as a synthetic user message after an
3
+ * overflow-driven auto-compaction. Tuned to be imperative and brief:
4
+ *
5
+ * - "Continue the task in progress" — open-ended about what the
6
+ * next step is. The agent may need to call a tool, write a
7
+ * final answer, ask a follow-up question, or anything else the
8
+ * task requires. We don't prescribe the shape; we just say
9
+ * keep going.
10
+ * - "Do not write a summary of what you were doing" — names the
11
+ * observed failure mode (model paraphrases the summary's
12
+ * "Next Steps" instead of acting).
13
+ * - "Pick up from where you left off" — frames the summary as
14
+ * reference material, not as a fresh prompt addressed to the
15
+ * model.
16
+ *
17
+ * Kept under 250 characters so the addition to LLM input is
18
+ * negligible (~50 tokens).
19
+ */
20
+ export const NUDGE_MESSAGE = "[continuation] Continue the task in progress — pick up from where you left off " +
21
+ "based on the summary above. Do not write a status update or summary of what you " +
22
+ "were doing; just proceed with the next action the task requires.";
23
+ /**
24
+ * Inspect a messages array and decide whether the post-compaction
25
+ * nudge should be appended. Exported separately so the unit test can
26
+ * exercise the boundary cases (empty, only summary, summary then user
27
+ * prompt, summary then assistant turn) without booting a full SDK
28
+ * session.
29
+ */
30
+ export function shouldNudgeAfterCompaction(messages) {
31
+ const last = messages[messages.length - 1];
32
+ if (last === undefined)
33
+ return false;
34
+ return last.role === "compactionSummary";
35
+ }
36
+ /**
37
+ * Build the synthetic user message used as the nudge. Timestamp is
38
+ * `Date.now()` so the message sorts after any prior content if a
39
+ * downstream consumer ever inspects timestamps; in practice the SDK
40
+ * doesn't reorder by timestamp at LLM-call time, but it costs nothing
41
+ * to keep monotonic ordering.
42
+ */
43
+ function buildNudgeMessage() {
44
+ return {
45
+ role: "user",
46
+ content: [{ type: "text", text: NUDGE_MESSAGE }],
47
+ timestamp: Date.now(),
48
+ };
49
+ }
50
+ /**
51
+ * Pi extension factory. Registered via `DefaultResourceLoader`'s
52
+ * `extensionFactories` option in `session-store.ts`. No I/O,
53
+ * no async setup — just registers the handler and returns.
54
+ */
55
+ export const compactionContinuationExtension = (pi) => {
56
+ pi.on("context", (event) => {
57
+ if (!shouldNudgeAfterCompaction(event.messages)) {
58
+ return undefined;
59
+ }
60
+ return {
61
+ messages: [...event.messages, buildNudgeMessage()],
62
+ };
63
+ });
64
+ };
65
+ //# sourceMappingURL=compaction-continuation.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"compaction-continuation.js","sourceRoot":"","sources":["../src/compaction-continuation.ts"],"names":[],"mappings":"AA8EA;;;;;;;;;;;;;;;;;;GAkBG;AACH,MAAM,CAAC,MAAM,aAAa,GACxB,iFAAiF;IACjF,kFAAkF;IAClF,kEAAkE,CAAC;AAErE;;;;;;GAMG;AACH,MAAM,UAAU,0BAA0B,CAAC,QAAiC;IAC1E,MAAM,IAAI,GAAG,QAAQ,CAAC,QAAQ,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC;IAC3C,IAAI,IAAI,KAAK,SAAS;QAAE,OAAO,KAAK,CAAC;IACrC,OAAO,IAAI,CAAC,IAAI,KAAK,mBAAmB,CAAC;AAC3C,CAAC;AAED;;;;;;GAMG;AACH,SAAS,iBAAiB;IACxB,OAAO;QACL,IAAI,EAAE,MAAM;QACZ,OAAO,EAAE,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,aAAa,EAAE,CAAC;QAChD,SAAS,EAAE,IAAI,CAAC,GAAG,EAAE;KACtB,CAAC;AACJ,CAAC;AAED;;;;GAIG;AACH,MAAM,CAAC,MAAM,+BAA+B,GAAqB,CAAC,EAAE,EAAE,EAAE;IACtE,EAAE,CAAC,EAAE,CAAC,SAAS,EAAE,CAAC,KAAK,EAAE,EAAE;QACzB,IAAI,CAAC,0BAA0B,CAAC,KAAK,CAAC,QAAQ,CAAC,EAAE,CAAC;YAChD,OAAO,SAAS,CAAC;QACnB,CAAC;QACD,OAAO;YACL,QAAQ,EAAE,CAAC,GAAG,KAAK,CAAC,QAAQ,EAAE,iBAAiB,EAAE,CAAC;SACnD,CAAC;IACJ,CAAC,CAAC,CAAC;AACL,CAAC,CAAC"}
@@ -0,0 +1,97 @@
1
+ interface ProbeRequest {
2
+ baseUrl: string;
3
+ apiKey?: string;
4
+ apiType?: string;
5
+ headers?: Record<string, string>;
6
+ }
7
+ interface ProbeResult {
8
+ reachable: boolean;
9
+ error?: string;
10
+ detectedApiType?: string;
11
+ models?: Array<{
12
+ id: string;
13
+ name?: string;
14
+ }>;
15
+ suggestedName?: string;
16
+ /** Full response from the models endpoint for debugging */
17
+ rawResponse?: unknown;
18
+ }
19
+ /**
20
+ * Probe a provider endpoint to test connectivity, detect API type,
21
+ * and fetch available models.
22
+ */
23
+ export declare function probeProvider(req: ProbeRequest): Promise<ProbeResult>;
24
+ /**
25
+ * Add or update a custom provider in models.json.
26
+ */
27
+ export declare function addCustomProvider(providerName: string, config: Record<string, unknown>): Promise<{
28
+ providers: Record<string, unknown>;
29
+ }>;
30
+ /**
31
+ * Remove a custom provider from models.json.
32
+ */
33
+ export declare function removeCustomProvider(providerName: string): Promise<{
34
+ providers: Record<string, unknown>;
35
+ }>;
36
+ export declare class AuthProviderNotFoundError extends Error {
37
+ constructor(provider: string);
38
+ }
39
+ export interface AuthPresence {
40
+ configured: boolean;
41
+ source?: string;
42
+ label?: string;
43
+ }
44
+ export interface AuthSummary {
45
+ providers: Record<string, AuthPresence>;
46
+ }
47
+ export declare function readAuthSummary(): AuthSummary;
48
+ export declare function writeApiKey(provider: string, apiKey: string): void;
49
+ export declare function removeApiKey(provider: string): void;
50
+ export declare function readSettings(): Record<string, unknown>;
51
+ export declare function updateSettings(patch: Record<string, unknown>): Record<string, unknown>;
52
+ export interface ModelsJson {
53
+ providers: Record<string, unknown>;
54
+ }
55
+ /**
56
+ * Read models.json, redacting secret fields (apiKey, apiKeyCommand).
57
+ */
58
+ export declare function readModelsJsonRedacted(): Promise<ModelsJson>;
59
+ export declare function writeModelsJson(data: ModelsJson): Promise<void>;
60
+ /**
61
+ * Write settings.json atomically. Used by the per-session setModel route
62
+ * to restore the global default after the SDK mutates it as a side effect
63
+ * of session.setModel().
64
+ * Uses a temp-file + rename pattern for atomic writes.
65
+ */
66
+ export declare function writeSettings(settings: Record<string, unknown>): Promise<void>;
67
+ /**
68
+ * Read the enabledModels array from settings via the SDK SettingsManager.
69
+ * Returns undefined when no scoping is active (all models visible).
70
+ */
71
+ export declare function readEnabledModels(): string[] | undefined;
72
+ /**
73
+ * Persist the enabledModels array to settings. Pass undefined or null
74
+ * to disable scoping (all models visible).
75
+ */
76
+ export declare function writeEnabledModels(patterns: string[] | null | undefined): void;
77
+ export interface ProvidersListingOptions {
78
+ /** When true, only return models listed in enabledModels. */
79
+ scoped?: boolean;
80
+ }
81
+ export declare function liveProvidersListing(opts?: ProvidersListingOptions): {
82
+ providers: Array<{
83
+ provider: string;
84
+ models: Array<{
85
+ id: string;
86
+ name: string;
87
+ contextWindow: number;
88
+ maxTokens: number;
89
+ reasoning: boolean;
90
+ input: string[];
91
+ hasAuth: boolean;
92
+ supportedThinkingLevels: string[];
93
+ }>;
94
+ }>;
95
+ };
96
+ export {};
97
+ //# sourceMappingURL=config-store.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"config-store.d.ts","sourceRoot":"","sources":["../src/config-store.ts"],"names":[],"mappings":"AAkBA,UAAU,YAAY;IACpB,OAAO,EAAE,MAAM,CAAC;IAChB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;CAClC;AAED,UAAU,WAAW;IACnB,SAAS,EAAE,OAAO,CAAC;IACnB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,MAAM,CAAC,EAAE,KAAK,CAAC;QAAE,EAAE,EAAE,MAAM,CAAC;QAAC,IAAI,CAAC,EAAE,MAAM,CAAA;KAAE,CAAC,CAAC;IAC9C,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,2DAA2D;IAC3D,WAAW,CAAC,EAAE,OAAO,CAAC;CACvB;AAED;;;GAGG;AACH,w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