openvibe 0.57.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (636) hide show
  1. package/CHANGELOG.md +3041 -0
  2. package/README.md +569 -0
  3. package/dist/cli/args.d.ts +44 -0
  4. package/dist/cli/args.d.ts.map +1 -0
  5. package/dist/cli/args.js +272 -0
  6. package/dist/cli/args.js.map +1 -0
  7. package/dist/cli/config-selector.d.ts +10 -0
  8. package/dist/cli/config-selector.d.ts.map +1 -0
  9. package/dist/cli/config-selector.js +26 -0
  10. package/dist/cli/config-selector.js.map +1 -0
  11. package/dist/cli/file-processor.d.ts +10 -0
  12. package/dist/cli/file-processor.d.ts.map +1 -0
  13. package/dist/cli/file-processor.js +68 -0
  14. package/dist/cli/file-processor.js.map +1 -0
  15. package/dist/cli/list-models.d.ts +3 -0
  16. package/dist/cli/list-models.d.ts.map +1 -0
  17. package/dist/cli/list-models.js +30 -0
  18. package/dist/cli/list-models.js.map +1 -0
  19. package/dist/cli/session-picker.d.ts +5 -0
  20. package/dist/cli/session-picker.d.ts.map +1 -0
  21. package/dist/cli/session-picker.js +30 -0
  22. package/dist/cli/session-picker.js.map +1 -0
  23. package/dist/cli.d.ts +3 -0
  24. package/dist/cli.d.ts.map +1 -0
  25. package/dist/cli.js +31 -0
  26. package/dist/cli.js.map +1 -0
  27. package/dist/config.d.ts +29 -0
  28. package/dist/config.d.ts.map +1 -0
  29. package/dist/config.js +145 -0
  30. package/dist/config.js.map +1 -0
  31. package/dist/core/accelerated-client.d.ts +42 -0
  32. package/dist/core/accelerated-client.d.ts.map +1 -0
  33. package/dist/core/accelerated-client.js +97 -0
  34. package/dist/core/accelerated-client.js.map +1 -0
  35. package/dist/core/accelerated-stream.d.ts +41 -0
  36. package/dist/core/accelerated-stream.d.ts.map +1 -0
  37. package/dist/core/accelerated-stream.js +133 -0
  38. package/dist/core/accelerated-stream.js.map +1 -0
  39. package/dist/core/agent-session.d.ts +566 -0
  40. package/dist/core/agent-session.d.ts.map +1 -0
  41. package/dist/core/agent-session.js +2361 -0
  42. package/dist/core/agent-session.js.map +1 -0
  43. package/dist/core/api-concurrency.d.ts +37 -0
  44. package/dist/core/api-concurrency.d.ts.map +1 -0
  45. package/dist/core/api-concurrency.js +179 -0
  46. package/dist/core/api-concurrency.js.map +1 -0
  47. package/dist/core/auth-storage.d.ts +66 -0
  48. package/dist/core/auth-storage.d.ts.map +1 -0
  49. package/dist/core/auth-storage.js +336 -0
  50. package/dist/core/auth-storage.js.map +1 -0
  51. package/dist/core/bash-executor.d.ts +15 -0
  52. package/dist/core/bash-executor.d.ts.map +1 -0
  53. package/dist/core/bash-executor.js +166 -0
  54. package/dist/core/bash-executor.js.map +1 -0
  55. package/dist/core/branded-ai.d.ts +17 -0
  56. package/dist/core/branded-ai.d.ts.map +1 -0
  57. package/dist/core/branded-ai.js +123 -0
  58. package/dist/core/branded-ai.js.map +1 -0
  59. package/dist/core/compaction/branch-summarization.d.ts +37 -0
  60. package/dist/core/compaction/branch-summarization.d.ts.map +1 -0
  61. package/dist/core/compaction/branch-summarization.js +158 -0
  62. package/dist/core/compaction/branch-summarization.js.map +1 -0
  63. package/dist/core/compaction/compaction.d.ts +56 -0
  64. package/dist/core/compaction/compaction.d.ts.map +1 -0
  65. package/dist/core/compaction/compaction.js +501 -0
  66. package/dist/core/compaction/compaction.js.map +1 -0
  67. package/dist/core/compaction/index.d.ts +4 -0
  68. package/dist/core/compaction/index.d.ts.map +1 -0
  69. package/dist/core/compaction/index.js +4 -0
  70. package/dist/core/compaction/index.js.map +1 -0
  71. package/dist/core/compaction/utils.d.ts +17 -0
  72. package/dist/core/compaction/utils.d.ts.map +1 -0
  73. package/dist/core/compaction/utils.js +120 -0
  74. package/dist/core/compaction/utils.js.map +1 -0
  75. package/dist/core/defaults.d.ts +3 -0
  76. package/dist/core/defaults.d.ts.map +1 -0
  77. package/dist/core/defaults.js +2 -0
  78. package/dist/core/defaults.js.map +1 -0
  79. package/dist/core/diagnostics.d.ts +15 -0
  80. package/dist/core/diagnostics.d.ts.map +1 -0
  81. package/dist/core/diagnostics.js +2 -0
  82. package/dist/core/diagnostics.js.map +1 -0
  83. package/dist/core/event-bus.d.ts +9 -0
  84. package/dist/core/event-bus.d.ts.map +1 -0
  85. package/dist/core/event-bus.js +25 -0
  86. package/dist/core/event-bus.js.map +1 -0
  87. package/dist/core/exec.d.ts +13 -0
  88. package/dist/core/exec.d.ts.map +1 -0
  89. package/dist/core/exec.js +61 -0
  90. package/dist/core/exec.js.map +1 -0
  91. package/dist/core/export-html/ansi-to-html.d.ts +3 -0
  92. package/dist/core/export-html/ansi-to-html.d.ts.map +1 -0
  93. package/dist/core/export-html/ansi-to-html.js +193 -0
  94. package/dist/core/export-html/ansi-to-html.js.map +1 -0
  95. package/dist/core/export-html/index.d.ts +22 -0
  96. package/dist/core/export-html/index.d.ts.map +1 -0
  97. package/dist/core/export-html/index.js +193 -0
  98. package/dist/core/export-html/index.js.map +1 -0
  99. package/dist/core/export-html/template.css +971 -0
  100. package/dist/core/export-html/template.html +54 -0
  101. package/dist/core/export-html/template.js +1583 -0
  102. package/dist/core/export-html/tool-renderer.d.ts +21 -0
  103. package/dist/core/export-html/tool-renderer.d.ts.map +1 -0
  104. package/dist/core/export-html/tool-renderer.js +51 -0
  105. package/dist/core/export-html/tool-renderer.js.map +1 -0
  106. package/dist/core/export-html/vendor/highlight.min.js +1213 -0
  107. package/dist/core/export-html/vendor/marked.min.js +6 -0
  108. package/dist/core/extensions/index.d.ts +8 -0
  109. package/dist/core/extensions/index.d.ts.map +1 -0
  110. package/dist/core/extensions/index.js +5 -0
  111. package/dist/core/extensions/index.js.map +1 -0
  112. package/dist/core/extensions/loader.d.ts +7 -0
  113. package/dist/core/extensions/loader.d.ts.map +1 -0
  114. package/dist/core/extensions/loader.js +349 -0
  115. package/dist/core/extensions/loader.js.map +1 -0
  116. package/dist/core/extensions/runner.d.ts +124 -0
  117. package/dist/core/extensions/runner.d.ts.map +1 -0
  118. package/dist/core/extensions/runner.js +657 -0
  119. package/dist/core/extensions/runner.js.map +1 -0
  120. package/dist/core/extensions/types.d.ts +1032 -0
  121. package/dist/core/extensions/types.d.ts.map +1 -0
  122. package/dist/core/extensions/types.js +35 -0
  123. package/dist/core/extensions/types.js.map +1 -0
  124. package/dist/core/extensions/wrapper.d.ts +8 -0
  125. package/dist/core/extensions/wrapper.d.ts.map +1 -0
  126. package/dist/core/extensions/wrapper.js +79 -0
  127. package/dist/core/extensions/wrapper.js.map +1 -0
  128. package/dist/core/footer-data-provider.d.ts +19 -0
  129. package/dist/core/footer-data-provider.d.ts.map +1 -0
  130. package/dist/core/footer-data-provider.js +113 -0
  131. package/dist/core/footer-data-provider.js.map +1 -0
  132. package/dist/core/index.d.ts +13 -0
  133. package/dist/core/index.d.ts.map +1 -0
  134. package/dist/core/index.js +11 -0
  135. package/dist/core/index.js.map +1 -0
  136. package/dist/core/keybindings.d.ts +22 -0
  137. package/dist/core/keybindings.d.ts.map +1 -0
  138. package/dist/core/keybindings.js +124 -0
  139. package/dist/core/keybindings.js.map +1 -0
  140. package/dist/core/messages.d.ts +51 -0
  141. package/dist/core/messages.d.ts.map +1 -0
  142. package/dist/core/messages.js +102 -0
  143. package/dist/core/messages.js.map +1 -0
  144. package/dist/core/model-registry.d.ts +26 -0
  145. package/dist/core/model-registry.d.ts.map +1 -0
  146. package/dist/core/model-registry.js +61 -0
  147. package/dist/core/model-registry.js.map +1 -0
  148. package/dist/core/model-resolver.d.ts +20 -0
  149. package/dist/core/model-resolver.d.ts.map +1 -0
  150. package/dist/core/model-resolver.js +47 -0
  151. package/dist/core/model-resolver.js.map +1 -0
  152. package/dist/core/multi-gpu-executor.d.ts +50 -0
  153. package/dist/core/multi-gpu-executor.d.ts.map +1 -0
  154. package/dist/core/multi-gpu-executor.js +201 -0
  155. package/dist/core/multi-gpu-executor.js.map +1 -0
  156. package/dist/core/onboarding.d.ts +3 -0
  157. package/dist/core/onboarding.d.ts.map +1 -0
  158. package/dist/core/onboarding.js +109 -0
  159. package/dist/core/onboarding.js.map +1 -0
  160. package/dist/core/package-manager.d.ts +136 -0
  161. package/dist/core/package-manager.d.ts.map +1 -0
  162. package/dist/core/package-manager.js +1375 -0
  163. package/dist/core/package-manager.js.map +1 -0
  164. package/dist/core/prompt-templates.d.ts +18 -0
  165. package/dist/core/prompt-templates.d.ts.map +1 -0
  166. package/dist/core/prompt-templates.js +204 -0
  167. package/dist/core/prompt-templates.js.map +1 -0
  168. package/dist/core/resolve-config-value.d.ts +4 -0
  169. package/dist/core/resolve-config-value.d.ts.map +1 -0
  170. package/dist/core/resolve-config-value.js +45 -0
  171. package/dist/core/resolve-config-value.js.map +1 -0
  172. package/dist/core/resource-loader.d.ts +184 -0
  173. package/dist/core/resource-loader.d.ts.map +1 -0
  174. package/dist/core/resource-loader.js +661 -0
  175. package/dist/core/resource-loader.js.map +1 -0
  176. package/dist/core/response-accelerator.d.ts +51 -0
  177. package/dist/core/response-accelerator.d.ts.map +1 -0
  178. package/dist/core/response-accelerator.js +149 -0
  179. package/dist/core/response-accelerator.js.map +1 -0
  180. package/dist/core/sdk.d.ts +39 -0
  181. package/dist/core/sdk.d.ts.map +1 -0
  182. package/dist/core/sdk.js +151 -0
  183. package/dist/core/sdk.js.map +1 -0
  184. package/dist/core/session-manager.d.ts +160 -0
  185. package/dist/core/session-manager.d.ts.map +1 -0
  186. package/dist/core/session-manager.js +899 -0
  187. package/dist/core/session-manager.js.map +1 -0
  188. package/dist/core/settings-manager.d.ts +220 -0
  189. package/dist/core/settings-manager.d.ts.map +1 -0
  190. package/dist/core/settings-manager.js +673 -0
  191. package/dist/core/settings-manager.js.map +1 -0
  192. package/dist/core/skills.d.ts +33 -0
  193. package/dist/core/skills.d.ts.map +1 -0
  194. package/dist/core/skills.js +326 -0
  195. package/dist/core/skills.js.map +1 -0
  196. package/dist/core/slash-commands.d.ts +15 -0
  197. package/dist/core/slash-commands.d.ts.map +1 -0
  198. package/dist/core/slash-commands.js +19 -0
  199. package/dist/core/slash-commands.js.map +1 -0
  200. package/dist/core/system-prompt.d.ts +23 -0
  201. package/dist/core/system-prompt.d.ts.map +1 -0
  202. package/dist/core/system-prompt.js +154 -0
  203. package/dist/core/system-prompt.js.map +1 -0
  204. package/dist/core/timings.d.ts +3 -0
  205. package/dist/core/timings.d.ts.map +1 -0
  206. package/dist/core/timings.js +21 -0
  207. package/dist/core/timings.js.map +1 -0
  208. package/dist/core/tools/bash.d.ts +40 -0
  209. package/dist/core/tools/bash.d.ts.map +1 -0
  210. package/dist/core/tools/bash.js +212 -0
  211. package/dist/core/tools/bash.js.map +1 -0
  212. package/dist/core/tools/edit-diff.d.ts +29 -0
  213. package/dist/core/tools/edit-diff.d.ts.map +1 -0
  214. package/dist/core/tools/edit-diff.js +182 -0
  215. package/dist/core/tools/edit-diff.js.map +1 -0
  216. package/dist/core/tools/edit.d.ts +28 -0
  217. package/dist/core/tools/edit.d.ts.map +1 -0
  218. package/dist/core/tools/edit.js +129 -0
  219. package/dist/core/tools/edit.js.map +1 -0
  220. package/dist/core/tools/fast-executor.d.ts +33 -0
  221. package/dist/core/tools/fast-executor.d.ts.map +1 -0
  222. package/dist/core/tools/fast-executor.js +83 -0
  223. package/dist/core/tools/fast-executor.js.map +1 -0
  224. package/dist/core/tools/find.d.ts +28 -0
  225. package/dist/core/tools/find.d.ts.map +1 -0
  226. package/dist/core/tools/find.js +50 -0
  227. package/dist/core/tools/find.js.map +1 -0
  228. package/dist/core/tools/grep.d.ts +37 -0
  229. package/dist/core/tools/grep.d.ts.map +1 -0
  230. package/dist/core/tools/grep.js +233 -0
  231. package/dist/core/tools/grep.js.map +1 -0
  232. package/dist/core/tools/index.d.ts +63 -0
  233. package/dist/core/tools/index.d.ts.map +1 -0
  234. package/dist/core/tools/index.js +52 -0
  235. package/dist/core/tools/index.js.map +1 -0
  236. package/dist/core/tools/local-accelerator.d.ts +65 -0
  237. package/dist/core/tools/local-accelerator.d.ts.map +1 -0
  238. package/dist/core/tools/local-accelerator.js +198 -0
  239. package/dist/core/tools/local-accelerator.js.map +1 -0
  240. package/dist/core/tools/ls.d.ts +31 -0
  241. package/dist/core/tools/ls.d.ts.map +1 -0
  242. package/dist/core/tools/ls.js +109 -0
  243. package/dist/core/tools/ls.js.map +1 -0
  244. package/dist/core/tools/parallel-executor.d.ts +60 -0
  245. package/dist/core/tools/parallel-executor.d.ts.map +1 -0
  246. package/dist/core/tools/parallel-executor.js +257 -0
  247. package/dist/core/tools/parallel-executor.js.map +1 -0
  248. package/dist/core/tools/path-utils.d.ts +4 -0
  249. package/dist/core/tools/path-utils.d.ts.map +1 -0
  250. package/dist/core/tools/path-utils.js +70 -0
  251. package/dist/core/tools/path-utils.js.map +1 -0
  252. package/dist/core/tools/read.d.ts +29 -0
  253. package/dist/core/tools/read.d.ts.map +1 -0
  254. package/dist/core/tools/read.js +146 -0
  255. package/dist/core/tools/read.js.map +1 -0
  256. package/dist/core/tools/truncate.d.ts +28 -0
  257. package/dist/core/tools/truncate.d.ts.map +1 -0
  258. package/dist/core/tools/truncate.js +161 -0
  259. package/dist/core/tools/truncate.js.map +1 -0
  260. package/dist/core/tools/write.d.ts +21 -0
  261. package/dist/core/tools/write.d.ts.map +1 -0
  262. package/dist/core/tools/write.js +69 -0
  263. package/dist/core/tools/write.js.map +1 -0
  264. package/dist/core/user-config.d.ts +26 -0
  265. package/dist/core/user-config.d.ts.map +1 -0
  266. package/dist/core/user-config.js +75 -0
  267. package/dist/core/user-config.js.map +1 -0
  268. package/dist/index.d.ts +27 -0
  269. package/dist/index.d.ts.map +1 -0
  270. package/dist/index.js +42 -0
  271. package/dist/index.js.map +1 -0
  272. package/dist/main.d.ts +2 -0
  273. package/dist/main.d.ts.map +1 -0
  274. package/dist/main.js +609 -0
  275. package/dist/main.js.map +1 -0
  276. package/dist/migrations.d.ts +8 -0
  277. package/dist/migrations.d.ts.map +1 -0
  278. package/dist/migrations.js +197 -0
  279. package/dist/migrations.js.map +1 -0
  280. package/dist/modes/index.d.ts +6 -0
  281. package/dist/modes/index.d.ts.map +1 -0
  282. package/dist/modes/index.js +5 -0
  283. package/dist/modes/index.js.map +1 -0
  284. package/dist/modes/interactive/components/armin.d.ts +31 -0
  285. package/dist/modes/interactive/components/armin.d.ts.map +1 -0
  286. package/dist/modes/interactive/components/armin.js +306 -0
  287. package/dist/modes/interactive/components/armin.js.map +1 -0
  288. package/dist/modes/interactive/components/assistant-message.d.ts +13 -0
  289. package/dist/modes/interactive/components/assistant-message.d.ts.map +1 -0
  290. package/dist/modes/interactive/components/assistant-message.js +82 -0
  291. package/dist/modes/interactive/components/assistant-message.js.map +1 -0
  292. package/dist/modes/interactive/components/bash-execution.d.ts +23 -0
  293. package/dist/modes/interactive/components/bash-execution.d.ts.map +1 -0
  294. package/dist/modes/interactive/components/bash-execution.js +126 -0
  295. package/dist/modes/interactive/components/bash-execution.js.map +1 -0
  296. package/dist/modes/interactive/components/bordered-loader.d.ts +15 -0
  297. package/dist/modes/interactive/components/bordered-loader.d.ts.map +1 -0
  298. package/dist/modes/interactive/components/bordered-loader.js +50 -0
  299. package/dist/modes/interactive/components/bordered-loader.js.map +1 -0
  300. package/dist/modes/interactive/components/branch-summary-message.d.ts +12 -0
  301. package/dist/modes/interactive/components/branch-summary-message.d.ts.map +1 -0
  302. package/dist/modes/interactive/components/branch-summary-message.js +40 -0
  303. package/dist/modes/interactive/components/branch-summary-message.js.map +1 -0
  304. package/dist/modes/interactive/components/compaction-summary-message.d.ts +12 -0
  305. package/dist/modes/interactive/components/compaction-summary-message.d.ts.map +1 -0
  306. package/dist/modes/interactive/components/compaction-summary-message.js +41 -0
  307. package/dist/modes/interactive/components/compaction-summary-message.js.map +1 -0
  308. package/dist/modes/interactive/components/config-selector.d.ts +68 -0
  309. package/dist/modes/interactive/components/config-selector.d.ts.map +1 -0
  310. package/dist/modes/interactive/components/config-selector.js +451 -0
  311. package/dist/modes/interactive/components/config-selector.js.map +1 -0
  312. package/dist/modes/interactive/components/countdown-timer.d.ts +11 -0
  313. package/dist/modes/interactive/components/countdown-timer.d.ts.map +1 -0
  314. package/dist/modes/interactive/components/countdown-timer.js +30 -0
  315. package/dist/modes/interactive/components/countdown-timer.js.map +1 -0
  316. package/dist/modes/interactive/components/custom-editor.d.ts +14 -0
  317. package/dist/modes/interactive/components/custom-editor.d.ts.map +1 -0
  318. package/dist/modes/interactive/components/custom-editor.js +52 -0
  319. package/dist/modes/interactive/components/custom-editor.js.map +1 -0
  320. package/dist/modes/interactive/components/custom-message.d.ts +16 -0
  321. package/dist/modes/interactive/components/custom-message.d.ts.map +1 -0
  322. package/dist/modes/interactive/components/custom-message.js +66 -0
  323. package/dist/modes/interactive/components/custom-message.js.map +1 -0
  324. package/dist/modes/interactive/components/daxnuts.d.ts +18 -0
  325. package/dist/modes/interactive/components/daxnuts.d.ts.map +1 -0
  326. package/dist/modes/interactive/components/daxnuts.js +130 -0
  327. package/dist/modes/interactive/components/daxnuts.js.map +1 -0
  328. package/dist/modes/interactive/components/diff.d.ts +5 -0
  329. package/dist/modes/interactive/components/diff.d.ts.map +1 -0
  330. package/dist/modes/interactive/components/diff.js +106 -0
  331. package/dist/modes/interactive/components/diff.js.map +1 -0
  332. package/dist/modes/interactive/components/dynamic-border.d.ts +8 -0
  333. package/dist/modes/interactive/components/dynamic-border.d.ts.map +1 -0
  334. package/dist/modes/interactive/components/dynamic-border.js +12 -0
  335. package/dist/modes/interactive/components/dynamic-border.js.map +1 -0
  336. package/dist/modes/interactive/components/extension-editor.d.ts +16 -0
  337. package/dist/modes/interactive/components/extension-editor.d.ts.map +1 -0
  338. package/dist/modes/interactive/components/extension-editor.js +95 -0
  339. package/dist/modes/interactive/components/extension-editor.js.map +1 -0
  340. package/dist/modes/interactive/components/extension-input.d.ts +20 -0
  341. package/dist/modes/interactive/components/extension-input.d.ts.map +1 -0
  342. package/dist/modes/interactive/components/extension-input.js +57 -0
  343. package/dist/modes/interactive/components/extension-input.js.map +1 -0
  344. package/dist/modes/interactive/components/extension-selector.d.ts +20 -0
  345. package/dist/modes/interactive/components/extension-selector.d.ts.map +1 -0
  346. package/dist/modes/interactive/components/extension-selector.js +74 -0
  347. package/dist/modes/interactive/components/extension-selector.js.map +1 -0
  348. package/dist/modes/interactive/components/footer.d.ts +14 -0
  349. package/dist/modes/interactive/components/footer.d.ts.map +1 -0
  350. package/dist/modes/interactive/components/footer.js +78 -0
  351. package/dist/modes/interactive/components/footer.js.map +1 -0
  352. package/dist/modes/interactive/components/index.d.ts +28 -0
  353. package/dist/modes/interactive/components/index.d.ts.map +1 -0
  354. package/dist/modes/interactive/components/index.js +28 -0
  355. package/dist/modes/interactive/components/index.js.map +1 -0
  356. package/dist/modes/interactive/components/keybinding-hints.d.ts +8 -0
  357. package/dist/modes/interactive/components/keybinding-hints.d.ts.map +1 -0
  358. package/dist/modes/interactive/components/keybinding-hints.js +25 -0
  359. package/dist/modes/interactive/components/keybinding-hints.js.map +1 -0
  360. package/dist/modes/interactive/components/onboarding-wizard.d.ts +23 -0
  361. package/dist/modes/interactive/components/onboarding-wizard.d.ts.map +1 -0
  362. package/dist/modes/interactive/components/onboarding-wizard.js +250 -0
  363. package/dist/modes/interactive/components/onboarding-wizard.js.map +1 -0
  364. package/dist/modes/interactive/components/session-selector-search.d.ts +21 -0
  365. package/dist/modes/interactive/components/session-selector-search.d.ts.map +1 -0
  366. package/dist/modes/interactive/components/session-selector-search.js +149 -0
  367. package/dist/modes/interactive/components/session-selector-search.js.map +1 -0
  368. package/dist/modes/interactive/components/session-selector.d.ts +89 -0
  369. package/dist/modes/interactive/components/session-selector.d.ts.map +1 -0
  370. package/dist/modes/interactive/components/session-selector.js +786 -0
  371. package/dist/modes/interactive/components/session-selector.js.map +1 -0
  372. package/dist/modes/interactive/components/settings-selector.d.ts +55 -0
  373. package/dist/modes/interactive/components/settings-selector.d.ts.map +1 -0
  374. package/dist/modes/interactive/components/settings-selector.js +273 -0
  375. package/dist/modes/interactive/components/settings-selector.js.map +1 -0
  376. package/dist/modes/interactive/components/show-images-selector.d.ts +7 -0
  377. package/dist/modes/interactive/components/show-images-selector.d.ts.map +1 -0
  378. package/dist/modes/interactive/components/show-images-selector.js +28 -0
  379. package/dist/modes/interactive/components/show-images-selector.js.map +1 -0
  380. package/dist/modes/interactive/components/skill-invocation-message.d.ts +12 -0
  381. package/dist/modes/interactive/components/skill-invocation-message.d.ts.map +1 -0
  382. package/dist/modes/interactive/components/skill-invocation-message.js +40 -0
  383. package/dist/modes/interactive/components/skill-invocation-message.js.map +1 -0
  384. package/dist/modes/interactive/components/theme-selector.d.ts +8 -0
  385. package/dist/modes/interactive/components/theme-selector.d.ts.map +1 -0
  386. package/dist/modes/interactive/components/theme-selector.js +38 -0
  387. package/dist/modes/interactive/components/theme-selector.js.map +1 -0
  388. package/dist/modes/interactive/components/thinking-selector.d.ts +8 -0
  389. package/dist/modes/interactive/components/thinking-selector.d.ts.map +1 -0
  390. package/dist/modes/interactive/components/thinking-selector.js +40 -0
  391. package/dist/modes/interactive/components/thinking-selector.js.map +1 -0
  392. package/dist/modes/interactive/components/tool-execution.d.ts +54 -0
  393. package/dist/modes/interactive/components/tool-execution.d.ts.map +1 -0
  394. package/dist/modes/interactive/components/tool-execution.js +704 -0
  395. package/dist/modes/interactive/components/tool-execution.js.map +1 -0
  396. package/dist/modes/interactive/components/tree-selector.d.ts +59 -0
  397. package/dist/modes/interactive/components/tree-selector.d.ts.map +1 -0
  398. package/dist/modes/interactive/components/tree-selector.js +929 -0
  399. package/dist/modes/interactive/components/tree-selector.js.map +1 -0
  400. package/dist/modes/interactive/components/user-message-selector.d.ts +24 -0
  401. package/dist/modes/interactive/components/user-message-selector.d.ts.map +1 -0
  402. package/dist/modes/interactive/components/user-message-selector.js +89 -0
  403. package/dist/modes/interactive/components/user-message-selector.js.map +1 -0
  404. package/dist/modes/interactive/components/user-message.d.ts +6 -0
  405. package/dist/modes/interactive/components/user-message.d.ts.map +1 -0
  406. package/dist/modes/interactive/components/user-message.js +24 -0
  407. package/dist/modes/interactive/components/user-message.js.map +1 -0
  408. package/dist/modes/interactive/components/visual-truncate.d.ts +6 -0
  409. package/dist/modes/interactive/components/visual-truncate.d.ts.map +1 -0
  410. package/dist/modes/interactive/components/visual-truncate.js +15 -0
  411. package/dist/modes/interactive/components/visual-truncate.js.map +1 -0
  412. package/dist/modes/interactive/interactive-mode.d.ts +177 -0
  413. package/dist/modes/interactive/interactive-mode.d.ts.map +1 -0
  414. package/dist/modes/interactive/interactive-mode.js +3037 -0
  415. package/dist/modes/interactive/interactive-mode.js.map +1 -0
  416. package/dist/modes/interactive/theme/dark.json +85 -0
  417. package/dist/modes/interactive/theme/light.json +84 -0
  418. package/dist/modes/interactive/theme/theme-schema.json +335 -0
  419. package/dist/modes/interactive/theme/theme.d.ts +60 -0
  420. package/dist/modes/interactive/theme/theme.d.ts.map +1 -0
  421. package/dist/modes/interactive/theme/theme.js +852 -0
  422. package/dist/modes/interactive/theme/theme.js.map +1 -0
  423. package/dist/modes/print-mode.d.ts +10 -0
  424. package/dist/modes/print-mode.d.ts.map +1 -0
  425. package/dist/modes/print-mode.js +80 -0
  426. package/dist/modes/print-mode.js.map +1 -0
  427. package/dist/modes/rpc/jsonl.d.ts +4 -0
  428. package/dist/modes/rpc/jsonl.d.ts.map +1 -0
  429. package/dist/modes/rpc/jsonl.js +36 -0
  430. package/dist/modes/rpc/jsonl.js.map +1 -0
  431. package/dist/modes/rpc/rpc-client.d.ts +94 -0
  432. package/dist/modes/rpc/rpc-client.d.ts.map +1 -0
  433. package/dist/modes/rpc/rpc-client.js +262 -0
  434. package/dist/modes/rpc/rpc-client.js.map +1 -0
  435. package/dist/modes/rpc/rpc-mode.d.ts +3 -0
  436. package/dist/modes/rpc/rpc-mode.d.ts.map +1 -0
  437. package/dist/modes/rpc/rpc-mode.js +227 -0
  438. package/dist/modes/rpc/rpc-mode.js.map +1 -0
  439. package/dist/modes/rpc/rpc-types.d.ts +395 -0
  440. package/dist/modes/rpc/rpc-types.d.ts.map +1 -0
  441. package/dist/modes/rpc/rpc-types.js +2 -0
  442. package/dist/modes/rpc/rpc-types.js.map +1 -0
  443. package/dist/utils/changelog.d.ts +11 -0
  444. package/dist/utils/changelog.d.ts.map +1 -0
  445. package/dist/utils/changelog.js +69 -0
  446. package/dist/utils/changelog.js.map +1 -0
  447. package/dist/utils/clipboard-image.d.ts +11 -0
  448. package/dist/utils/clipboard-image.d.ts.map +1 -0
  449. package/dist/utils/clipboard-image.js +157 -0
  450. package/dist/utils/clipboard-image.js.map +1 -0
  451. package/dist/utils/clipboard-native.d.ts +7 -0
  452. package/dist/utils/clipboard-native.d.ts.map +1 -0
  453. package/dist/utils/clipboard-native.js +14 -0
  454. package/dist/utils/clipboard-native.js.map +1 -0
  455. package/dist/utils/clipboard.d.ts +2 -0
  456. package/dist/utils/clipboard.d.ts.map +1 -0
  457. package/dist/utils/clipboard.js +55 -0
  458. package/dist/utils/clipboard.js.map +1 -0
  459. package/dist/utils/frontmatter.d.ts +8 -0
  460. package/dist/utils/frontmatter.d.ts.map +1 -0
  461. package/dist/utils/frontmatter.js +26 -0
  462. package/dist/utils/frontmatter.js.map +1 -0
  463. package/dist/utils/git.d.ts +10 -0
  464. package/dist/utils/git.d.ts.map +1 -0
  465. package/dist/utils/git.js +156 -0
  466. package/dist/utils/git.js.map +1 -0
  467. package/dist/utils/image-convert.d.ts +5 -0
  468. package/dist/utils/image-convert.d.ts.map +1 -0
  469. package/dist/utils/image-convert.js +28 -0
  470. package/dist/utils/image-convert.js.map +1 -0
  471. package/dist/utils/image-resize.d.ts +19 -0
  472. package/dist/utils/image-resize.d.ts.map +1 -0
  473. package/dist/utils/image-resize.js +152 -0
  474. package/dist/utils/image-resize.js.map +1 -0
  475. package/dist/utils/mime.d.ts +2 -0
  476. package/dist/utils/mime.d.ts.map +1 -0
  477. package/dist/utils/mime.js +26 -0
  478. package/dist/utils/mime.js.map +1 -0
  479. package/dist/utils/photon.d.ts +3 -0
  480. package/dist/utils/photon.d.ts.map +1 -0
  481. package/dist/utils/photon.js +102 -0
  482. package/dist/utils/photon.js.map +1 -0
  483. package/dist/utils/shell.d.ts +8 -0
  484. package/dist/utils/shell.d.ts.map +1 -0
  485. package/dist/utils/shell.js +135 -0
  486. package/dist/utils/shell.js.map +1 -0
  487. package/dist/utils/sleep.d.ts +2 -0
  488. package/dist/utils/sleep.d.ts.map +1 -0
  489. package/dist/utils/sleep.js +14 -0
  490. package/dist/utils/sleep.js.map +1 -0
  491. package/dist/utils/tools-manager.d.ts +3 -0
  492. package/dist/utils/tools-manager.d.ts.map +1 -0
  493. package/dist/utils/tools-manager.js +227 -0
  494. package/dist/utils/tools-manager.js.map +1 -0
  495. package/docs/compaction.md +392 -0
  496. package/docs/custom-provider.md +592 -0
  497. package/docs/development.md +69 -0
  498. package/docs/extensions.md +2023 -0
  499. package/docs/images/doom-extension.png +0 -0
  500. package/docs/images/exy.png +0 -0
  501. package/docs/images/interactive-mode.png +0 -0
  502. package/docs/images/tree-view.png +0 -0
  503. package/docs/json.md +79 -0
  504. package/docs/keybindings.md +182 -0
  505. package/docs/models.md +297 -0
  506. package/docs/packages.md +209 -0
  507. package/docs/prompt-templates.md +67 -0
  508. package/docs/providers.md +188 -0
  509. package/docs/rpc.md +1354 -0
  510. package/docs/sdk.md +968 -0
  511. package/docs/session.md +412 -0
  512. package/docs/settings.md +225 -0
  513. package/docs/shell-aliases.md +13 -0
  514. package/docs/skills.md +231 -0
  515. package/docs/terminal-setup.md +87 -0
  516. package/docs/termux.md +127 -0
  517. package/docs/themes.md +295 -0
  518. package/docs/tmux.md +61 -0
  519. package/docs/tree.md +228 -0
  520. package/docs/tui.md +887 -0
  521. package/docs/windows.md +17 -0
  522. package/examples/README.md +25 -0
  523. package/examples/extensions/README.md +205 -0
  524. package/examples/extensions/antigravity-image-gen.ts +415 -0
  525. package/examples/extensions/auto-commit-on-exit.ts +49 -0
  526. package/examples/extensions/bash-spawn-hook.ts +30 -0
  527. package/examples/extensions/bookmark.ts +50 -0
  528. package/examples/extensions/built-in-tool-renderer.ts +246 -0
  529. package/examples/extensions/claude-rules.ts +86 -0
  530. package/examples/extensions/commands.ts +72 -0
  531. package/examples/extensions/confirm-destructive.ts +59 -0
  532. package/examples/extensions/custom-compaction.ts +114 -0
  533. package/examples/extensions/custom-footer.ts +64 -0
  534. package/examples/extensions/custom-header.ts +73 -0
  535. package/examples/extensions/custom-provider-anthropic/index.ts +604 -0
  536. package/examples/extensions/custom-provider-anthropic/package-lock.json +24 -0
  537. package/examples/extensions/custom-provider-anthropic/package.json +19 -0
  538. package/examples/extensions/custom-provider-gitlab-duo/index.ts +349 -0
  539. package/examples/extensions/custom-provider-gitlab-duo/package.json +16 -0
  540. package/examples/extensions/custom-provider-gitlab-duo/test.ts +82 -0
  541. package/examples/extensions/custom-provider-qwen-cli/index.ts +345 -0
  542. package/examples/extensions/custom-provider-qwen-cli/package.json +16 -0
  543. package/examples/extensions/dirty-repo-guard.ts +56 -0
  544. package/examples/extensions/doom-overlay/README.md +46 -0
  545. package/examples/extensions/doom-overlay/doom/build/doom.js +21 -0
  546. package/examples/extensions/doom-overlay/doom/build/doom.wasm +0 -0
  547. package/examples/extensions/doom-overlay/doom/build.sh +152 -0
  548. package/examples/extensions/doom-overlay/doom/doomgeneric_pi.c +72 -0
  549. package/examples/extensions/doom-overlay/doom-component.ts +132 -0
  550. package/examples/extensions/doom-overlay/doom-engine.ts +173 -0
  551. package/examples/extensions/doom-overlay/doom-keys.ts +104 -0
  552. package/examples/extensions/doom-overlay/index.ts +74 -0
  553. package/examples/extensions/doom-overlay/wad-finder.ts +51 -0
  554. package/examples/extensions/dynamic-resources/SKILL.md +8 -0
  555. package/examples/extensions/dynamic-resources/dynamic.json +79 -0
  556. package/examples/extensions/dynamic-resources/dynamic.md +5 -0
  557. package/examples/extensions/dynamic-resources/index.ts +15 -0
  558. package/examples/extensions/dynamic-tools.ts +74 -0
  559. package/examples/extensions/event-bus.ts +43 -0
  560. package/examples/extensions/file-trigger.ts +41 -0
  561. package/examples/extensions/git-checkpoint.ts +53 -0
  562. package/examples/extensions/handoff.ts +150 -0
  563. package/examples/extensions/hello.ts +25 -0
  564. package/examples/extensions/inline-bash.ts +94 -0
  565. package/examples/extensions/input-transform.ts +43 -0
  566. package/examples/extensions/interactive-shell.ts +196 -0
  567. package/examples/extensions/mac-system-theme.ts +47 -0
  568. package/examples/extensions/message-renderer.ts +59 -0
  569. package/examples/extensions/minimal-mode.ts +426 -0
  570. package/examples/extensions/modal-editor.ts +85 -0
  571. package/examples/extensions/model-status.ts +31 -0
  572. package/examples/extensions/notify.ts +55 -0
  573. package/examples/extensions/overlay-qa-tests.ts +1348 -0
  574. package/examples/extensions/overlay-test.ts +150 -0
  575. package/examples/extensions/permission-gate.ts +34 -0
  576. package/examples/extensions/pirate.ts +47 -0
  577. package/examples/extensions/plan-mode/README.md +65 -0
  578. package/examples/extensions/plan-mode/index.ts +340 -0
  579. package/examples/extensions/plan-mode/utils.ts +168 -0
  580. package/examples/extensions/preset.ts +398 -0
  581. package/examples/extensions/protected-paths.ts +30 -0
  582. package/examples/extensions/provider-payload.ts +14 -0
  583. package/examples/extensions/qna.ts +119 -0
  584. package/examples/extensions/question.ts +264 -0
  585. package/examples/extensions/questionnaire.ts +427 -0
  586. package/examples/extensions/rainbow-editor.ts +88 -0
  587. package/examples/extensions/reload-runtime.ts +37 -0
  588. package/examples/extensions/rpc-demo.ts +124 -0
  589. package/examples/extensions/sandbox/index.ts +318 -0
  590. package/examples/extensions/sandbox/package-lock.json +92 -0
  591. package/examples/extensions/sandbox/package.json +19 -0
  592. package/examples/extensions/send-user-message.ts +97 -0
  593. package/examples/extensions/session-name.ts +27 -0
  594. package/examples/extensions/shutdown-command.ts +63 -0
  595. package/examples/extensions/snake.ts +343 -0
  596. package/examples/extensions/space-invaders.ts +560 -0
  597. package/examples/extensions/ssh.ts +220 -0
  598. package/examples/extensions/status-line.ts +40 -0
  599. package/examples/extensions/subagent/README.md +172 -0
  600. package/examples/extensions/subagent/agents/planner.md +37 -0
  601. package/examples/extensions/subagent/agents/reviewer.md +35 -0
  602. package/examples/extensions/subagent/agents/scout.md +50 -0
  603. package/examples/extensions/subagent/agents/worker.md +24 -0
  604. package/examples/extensions/subagent/agents.ts +126 -0
  605. package/examples/extensions/subagent/index.ts +964 -0
  606. package/examples/extensions/subagent/prompts/implement-and-review.md +10 -0
  607. package/examples/extensions/subagent/prompts/implement.md +10 -0
  608. package/examples/extensions/subagent/prompts/scout-and-plan.md +9 -0
  609. package/examples/extensions/summarize.ts +195 -0
  610. package/examples/extensions/system-prompt-header.ts +17 -0
  611. package/examples/extensions/timed-confirm.ts +70 -0
  612. package/examples/extensions/titlebar-spinner.ts +58 -0
  613. package/examples/extensions/todo.ts +299 -0
  614. package/examples/extensions/tool-override.ts +143 -0
  615. package/examples/extensions/tools.ts +146 -0
  616. package/examples/extensions/trigger-compact.ts +40 -0
  617. package/examples/extensions/truncated-tool.ts +192 -0
  618. package/examples/extensions/widget-placement.ts +17 -0
  619. package/examples/extensions/with-deps/index.ts +32 -0
  620. package/examples/extensions/with-deps/package-lock.json +31 -0
  621. package/examples/extensions/with-deps/package.json +22 -0
  622. package/examples/rpc-extension-ui.ts +632 -0
  623. package/examples/sdk/01-minimal.ts +22 -0
  624. package/examples/sdk/02-custom-model.ts +49 -0
  625. package/examples/sdk/03-custom-prompt.ts +55 -0
  626. package/examples/sdk/04-skills.ts +46 -0
  627. package/examples/sdk/05-tools.ts +56 -0
  628. package/examples/sdk/06-extensions.ts +88 -0
  629. package/examples/sdk/07-context-files.ts +40 -0
  630. package/examples/sdk/08-prompt-templates.ts +47 -0
  631. package/examples/sdk/09-api-keys-and-oauth.ts +48 -0
  632. package/examples/sdk/10-settings.ts +51 -0
  633. package/examples/sdk/11-sessions.ts +48 -0
  634. package/examples/sdk/12-full-control.ts +82 -0
  635. package/examples/sdk/README.md +144 -0
  636. package/package.json +100 -0
@@ -0,0 +1,160 @@
1
+ import type { AgentMessage } from "@mariozechner/pi-agent-core";
2
+ import type { ImageContent, Message, TextContent } from "@mariozechner/pi-ai";
3
+ import { type BashExecutionMessage, type CustomMessage } from "./messages.js";
4
+ export declare const CURRENT_SESSION_VERSION = 3;
5
+ export interface SessionHeader {
6
+ type: "session";
7
+ version?: number;
8
+ id: string;
9
+ timestamp: string;
10
+ cwd: string;
11
+ parentSession?: string;
12
+ }
13
+ export interface NewSessionOptions {
14
+ parentSession?: string;
15
+ }
16
+ export interface SessionEntryBase {
17
+ type: string;
18
+ id: string;
19
+ parentId: string | null;
20
+ timestamp: string;
21
+ }
22
+ export interface SessionMessageEntry extends SessionEntryBase {
23
+ type: "message";
24
+ message: AgentMessage;
25
+ }
26
+ export interface ThinkingLevelChangeEntry extends SessionEntryBase {
27
+ type: "thinking_level_change";
28
+ thinkingLevel: string;
29
+ }
30
+ export interface ModelChangeEntry extends SessionEntryBase {
31
+ type: "model_change";
32
+ provider: string;
33
+ modelId: string;
34
+ }
35
+ export interface CompactionEntry<T = unknown> extends SessionEntryBase {
36
+ type: "compaction";
37
+ summary: string;
38
+ firstKeptEntryId: string;
39
+ tokensBefore: number;
40
+ details?: T;
41
+ fromHook?: boolean;
42
+ }
43
+ export interface BranchSummaryEntry<T = unknown> extends SessionEntryBase {
44
+ type: "branch_summary";
45
+ fromId: string;
46
+ summary: string;
47
+ details?: T;
48
+ fromHook?: boolean;
49
+ }
50
+ export interface CustomEntry<T = unknown> extends SessionEntryBase {
51
+ type: "custom";
52
+ customType: string;
53
+ data?: T;
54
+ }
55
+ export interface LabelEntry extends SessionEntryBase {
56
+ type: "label";
57
+ targetId: string;
58
+ label: string | undefined;
59
+ }
60
+ export interface SessionInfoEntry extends SessionEntryBase {
61
+ type: "session_info";
62
+ name?: string;
63
+ }
64
+ export interface CustomMessageEntry<T = unknown> extends SessionEntryBase {
65
+ type: "custom_message";
66
+ customType: string;
67
+ content: string | (TextContent | ImageContent)[];
68
+ details?: T;
69
+ display: boolean;
70
+ }
71
+ export type SessionEntry = SessionMessageEntry | ThinkingLevelChangeEntry | ModelChangeEntry | CompactionEntry | BranchSummaryEntry | CustomEntry | CustomMessageEntry | LabelEntry | SessionInfoEntry;
72
+ export type FileEntry = SessionHeader | SessionEntry;
73
+ export interface SessionTreeNode {
74
+ entry: SessionEntry;
75
+ children: SessionTreeNode[];
76
+ label?: string;
77
+ }
78
+ export interface SessionContext {
79
+ messages: AgentMessage[];
80
+ thinkingLevel: string;
81
+ model: {
82
+ provider: string;
83
+ modelId: string;
84
+ } | null;
85
+ }
86
+ export interface SessionInfo {
87
+ path: string;
88
+ id: string;
89
+ cwd: string;
90
+ name?: string;
91
+ parentSessionPath?: string;
92
+ created: Date;
93
+ modified: Date;
94
+ messageCount: number;
95
+ firstMessage: string;
96
+ allMessagesText: string;
97
+ }
98
+ export type ReadonlySessionManager = Pick<SessionManager, "getCwd" | "getSessionDir" | "getSessionId" | "getSessionFile" | "getLeafId" | "getLeafEntry" | "getEntry" | "getLabel" | "getBranch" | "getHeader" | "getEntries" | "getTree" | "getSessionName">;
99
+ export declare function migrateSessionEntries(entries: FileEntry[]): void;
100
+ export declare function parseSessionEntries(content: string): FileEntry[];
101
+ export declare function getLatestCompactionEntry(entries: SessionEntry[]): CompactionEntry | null;
102
+ export declare function buildSessionContext(entries: SessionEntry[], leafId?: string | null, byId?: Map<string, SessionEntry>): SessionContext;
103
+ export declare function loadEntriesFromFile(filePath: string): FileEntry[];
104
+ export declare function findMostRecentSession(sessionDir: string): string | null;
105
+ export type SessionListProgress = (loaded: number, total: number) => void;
106
+ export declare class SessionManager {
107
+ private sessionId;
108
+ private sessionFile;
109
+ private sessionDir;
110
+ private cwd;
111
+ private persist;
112
+ private flushed;
113
+ private fileEntries;
114
+ private byId;
115
+ private labelsById;
116
+ private leafId;
117
+ private constructor();
118
+ setSessionFile(sessionFile: string): void;
119
+ newSession(options?: NewSessionOptions): string | undefined;
120
+ private _buildIndex;
121
+ private _rewriteFile;
122
+ isPersisted(): boolean;
123
+ getCwd(): string;
124
+ getSessionDir(): string;
125
+ getSessionId(): string;
126
+ getSessionFile(): string | undefined;
127
+ _persist(entry: SessionEntry): void;
128
+ private _appendEntry;
129
+ appendMessage(message: Message | CustomMessage | BashExecutionMessage): string;
130
+ appendThinkingLevelChange(thinkingLevel: string): string;
131
+ appendModelChange(provider: string, modelId: string): string;
132
+ appendCompaction<T = unknown>(summary: string, firstKeptEntryId: string, tokensBefore: number, details?: T, fromHook?: boolean): string;
133
+ appendCustomEntry(customType: string, data?: unknown): string;
134
+ appendSessionInfo(name: string): string;
135
+ getSessionName(): string | undefined;
136
+ appendCustomMessageEntry<T = unknown>(customType: string, content: string | (TextContent | ImageContent)[], display: boolean, details?: T): string;
137
+ getLeafId(): string | null;
138
+ getLeafEntry(): SessionEntry | undefined;
139
+ getEntry(id: string): SessionEntry | undefined;
140
+ getChildren(parentId: string): SessionEntry[];
141
+ getLabel(id: string): string | undefined;
142
+ appendLabelChange(targetId: string, label: string | undefined): string;
143
+ getBranch(fromId?: string): SessionEntry[];
144
+ buildSessionContext(): SessionContext;
145
+ getHeader(): SessionHeader | null;
146
+ getEntries(): SessionEntry[];
147
+ getTree(): SessionTreeNode[];
148
+ branch(branchFromId: string): void;
149
+ resetLeaf(): void;
150
+ branchWithSummary(branchFromId: string | null, summary: string, details?: unknown, fromHook?: boolean): string;
151
+ createBranchedSession(leafId: string): string | undefined;
152
+ static create(cwd: string, sessionDir?: string): SessionManager;
153
+ static open(path: string, sessionDir?: string): SessionManager;
154
+ static continueRecent(cwd: string, sessionDir?: string): SessionManager;
155
+ static inMemory(cwd?: string): SessionManager;
156
+ static forkFrom(sourcePath: string, targetCwd: string, sessionDir?: string): SessionManager;
157
+ static list(cwd: string, sessionDir?: string, onProgress?: SessionListProgress): Promise<SessionInfo[]>;
158
+ static listAll(onProgress?: SessionListProgress): Promise<SessionInfo[]>;
159
+ }
160
+ //# sourceMappingURL=session-manager.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"session-manager.d.ts","sourceRoot":"","sources":["../../src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AAE,CAE3B;IACD,OAAO,IAAI,eAAe,EAAE,CA4B3B;IACD,MAAM,CAAC,YAAY,EAAE,MAAM,GAAG,IAAI,CAKjC;IACD,SAAS,IAAI,IAAI,CAEhB;IACD,iBAAiB,CAAC,YAAY,EAAE,MAAM,GAAG,IAAI,EAAE,OAAO,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,OAAO,EAAE,QAAQ,CAAC,EAAE,OAAO,GAAG,MAAM,CAiB7G;IACD,qBAAqB,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,CA0ExD;IACD,MAAM,CAAC,MAAM,CAAC,GAAG,EAAE,MAAM,EAAE,UAAU,CAAC,EAAE,MAAM,GAAG,cAAc,CAG9D;IACD,MAAM,CAAC,IAAI,CAAC,IAAI,EAAE,MAAM,EAAE,UAAU,CAAC,EAAE,MAAM,GAAG,cAAc,CAM7D;IACD,MAAM,CAAC,cAAc,CAAC,GAAG,EAAE,MAAM,EAAE,UAAU,CAAC,EAAE,MAAM,GAAG,cAAc,CAOtE;IACD,MAAM,CAAC,QAAQ,CAAC,GAAG,GAAE,MAAsB,GAAG,cAAc,CAE3D;IACD,MAAM,CAAC,QAAQ,CAAC,UAAU,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,EAAE,UAAU,CAAC,EAAE,MAAM,GAAG,cAAc,CAgC1F;IACD,OAAa,IAAI,CAAC,GAAG,EAAE,MAAM,EAAE,UAAU,CAAC,EAAE,MAAM,EAAE,UAAU,CAAC,EAAE,mBAAmB,GAAG,OAAO,CAAC,WAAW,EAAE,CAAC,CAK5G;IACD,OAAa,OAAO,CAAC,UAAU,CAAC,EAAE,mBAAmB,GAAG,OAAO,CAAC,WAAW,EAAE,CAAC,CAwC7E;CACD","sourcesContent":["import type { AgentMessage } from \"@mariozechner/pi-agent-core\";\nimport type { ImageContent, Message, TextContent } from \"@mariozechner/pi-ai\";\nimport { randomUUID } from \"crypto\";\nimport {\n\tappendFileSync,\n\tcloseSync,\n\texistsSync,\n\tmkdirSync,\n\topenSync,\n\treaddirSync,\n\treadFileSync,\n\treadSync,\n\tstatSync,\n\twriteFileSync,\n} from \"fs\";\nimport { readdir, readFile, stat } from \"fs/promises\";\nimport { join, resolve } from \"path\";\nimport { getAgentDir as getDefaultAgentDir, getSessionsDir } from \"../config.js\";\nimport {\n\ttype BashExecutionMessage,\n\ttype CustomMessage,\n\tcreateBranchSummaryMessage,\n\tcreateCompactionSummaryMessage,\n\tcreateCustomMessage,\n} from \"./messages.js\";\nexport const CURRENT_SESSION_VERSION = 3;\nexport interface SessionHeader {\n\ttype: \"session\";\n\tversion?: number;\n\tid: string;\n\ttimestamp: string;\n\tcwd: string;\n\tparentSession?: string;\n}\nexport interface NewSessionOptions {\n\tparentSession?: string;\n}\nexport interface SessionEntryBase {\n\ttype: string;\n\tid: string;\n\tparentId: string | null;\n\ttimestamp: string;\n}\nexport interface SessionMessageEntry extends SessionEntryBase {\n\ttype: \"message\";\n\tmessage: AgentMessage;\n}\nexport interface ThinkingLevelChangeEntry extends SessionEntryBase {\n\ttype: \"thinking_level_change\";\n\tthinkingLevel: string;\n}\nexport interface ModelChangeEntry extends SessionEntryBase {\n\ttype: \"model_change\";\n\tprovider: string;\n\tmodelId: string;\n}\nexport interface CompactionEntry<T = unknown> extends SessionEntryBase {\n\ttype: \"compaction\";\n\tsummary: string;\n\tfirstKeptEntryId: string;\n\ttokensBefore: number;\n\tdetails?: T;\n\tfromHook?: boolean;\n}\nexport interface BranchSummaryEntry<T = unknown> extends SessionEntryBase {\n\ttype: \"branch_summary\";\n\tfromId: string;\n\tsummary: string;\n\tdetails?: T;\n\tfromHook?: boolean;\n}\nexport interface CustomEntry<T = unknown> extends SessionEntryBase {\n\ttype: \"custom\";\n\tcustomType: string;\n\tdata?: T;\n}\nexport interface LabelEntry extends SessionEntryBase {\n\ttype: \"label\";\n\ttargetId: string;\n\tlabel: string | undefined;\n}\nexport interface SessionInfoEntry extends SessionEntryBase {\n\ttype: \"session_info\";\n\tname?: string;\n}\nexport interface CustomMessageEntry<T = unknown> extends SessionEntryBase {\n\ttype: \"custom_message\";\n\tcustomType: string;\n\tcontent: string | (TextContent | ImageContent)[];\n\tdetails?: T;\n\tdisplay: boolean;\n}\nexport type SessionEntry =\n\t| SessionMessageEntry\n\t| ThinkingLevelChangeEntry\n\t| ModelChangeEntry\n\t| CompactionEntry\n\t| BranchSummaryEntry\n\t| CustomEntry\n\t| CustomMessageEntry\n\t| LabelEntry\n\t| SessionInfoEntry;\nexport type FileEntry = SessionHeader | SessionEntry;\nexport interface SessionTreeNode {\n\tentry: SessionEntry;\n\tchildren: SessionTreeNode[];\n\tlabel?: string;\n}\nexport interface SessionContext {\n\tmessages: AgentMessage[];\n\tthinkingLevel: string;\n\tmodel: { provider: string; modelId: string } | null;\n}\nexport interface SessionInfo {\n\tpath: string;\n\tid: string;\n\tcwd: string;\n\tname?: string;\n\tparentSessionPath?: string;\n\tcreated: Date;\n\tmodified: Date;\n\tmessageCount: number;\n\tfirstMessage: string;\n\tallMessagesText: string;\n}\nexport type ReadonlySessionManager = Pick<\n\tSessionManager,\n\t| \"getCwd\"\n\t| \"getSessionDir\"\n\t| \"getSessionId\"\n\t| \"getSessionFile\"\n\t| \"getLeafId\"\n\t| \"getLeafEntry\"\n\t| \"getEntry\"\n\t| \"getLabel\"\n\t| \"getBranch\"\n\t| \"getHeader\"\n\t| \"getEntries\"\n\t| \"getTree\"\n\t| \"getSessionName\"\n>;\nfunction generateId(byId: { has(id: string): boolean }): string {\n\tfor (let i = 0; i < 100; i++) {\n\t\tconst id = randomUUID().slice(0, 8);\n\t\tif (!byId.has(id)) return id;\n\t}\n\treturn randomUUID();\n}\nfunction migrateV1ToV2(entries: FileEntry[]): void {\n\tconst ids = new Set<string>();\n\tlet prevId: string | null = null;\n\tfor (const entry of entries) {\n\t\tif (entry.type === \"session\") {\n\t\t\tentry.version = 2;\n\t\t\tcontinue;\n\t\t}\n\t\tentry.id = generateId(ids);\n\t\tentry.parentId = prevId;\n\t\tprevId = entry.id;\n\t\tif (entry.type === \"compaction\") {\n\t\t\tconst comp = entry as CompactionEntry & { firstKeptEntryIndex?: number };\n\t\t\tif (typeof comp.firstKeptEntryIndex === \"number\") {\n\t\t\t\tconst targetEntry = entries[comp.firstKeptEntryIndex];\n\t\t\t\tif (targetEntry && targetEntry.type !== \"session\") {\n\t\t\t\t\tcomp.firstKeptEntryId = targetEntry.id;\n\t\t\t\t}\n\t\t\t\tdelete comp.firstKeptEntryIndex;\n\t\t\t}\n\t\t}\n\t}\n}\nfunction migrateV2ToV3(entries: FileEntry[]): void {\n\tfor (const entry of entries) {\n\t\tif (entry.type === \"session\") {\n\t\t\tentry.version = 3;\n\t\t\tcontinue;\n\t\t}\n\t\tif (entry.type === \"message\") {\n\t\t\tconst msgEntry = entry as SessionMessageEntry;\n\t\t\tif (msgEntry.message && (msgEntry.message as { role: string }).role === \"hookMessage\") {\n\t\t\t\t(msgEntry.message as { role: string }).role = \"custom\";\n\t\t\t}\n\t\t}\n\t}\n}\nfunction migrateToCurrentVersion(entries: FileEntry[]): boolean {\n\tconst header = entries.find((e) => e.type === \"session\") as SessionHeader | undefined;\n\tconst version = header?.version ?? 1;\n\tif (version >= CURRENT_SESSION_VERSION) return false;\n\tif (version < 2) migrateV1ToV2(entries);\n\tif (version < 3) migrateV2ToV3(entries);\n\treturn true;\n}\nexport function migrateSessionEntries(entries: FileEntry[]): void {\n\tmigrateToCurrentVersion(entries);\n}\nexport function parseSessionEntries(content: string): FileEntry[] {\n\tconst entries: FileEntry[] = [];\n\tconst lines = content.trim().split(\"\\n\");\n\tfor (const line of lines) {\n\t\tif (!line.trim()) continue;\n\t\ttry {\n\t\t\tconst entry = JSON.parse(line) as FileEntry;\n\t\t\tentries.push(entry);\n\t\t} catch {}\n\t}\n\treturn entries;\n}\nexport function getLatestCompactionEntry(entries: SessionEntry[]): CompactionEntry | null {\n\tfor (let i = entries.length - 1; i >= 0; i--) {\n\t\tif (entries[i].type === \"compaction\") {\n\t\t\treturn entries[i] as CompactionEntry;\n\t\t}\n\t}\n\treturn null;\n}\nexport function buildSessionContext(\n\tentries: SessionEntry[],\n\tleafId?: string | null,\n\tbyId?: Map<string, SessionEntry>,\n): SessionContext {\n\tif (!byId) {\n\t\tbyId = new Map<string, SessionEntry>();\n\t\tfor (const entry of entries) {\n\t\t\tbyId.set(entry.id, entry);\n\t\t}\n\t}\n\tlet leaf: SessionEntry | undefined;\n\tif (leafId === null) {\n\t\treturn { messages: [], thinkingLevel: \"off\", model: null };\n\t}\n\tif (leafId) {\n\t\tleaf = byId.get(leafId);\n\t}\n\tif (!leaf) {\n\t\tleaf = entries[entries.length - 1];\n\t}\n\tif (!leaf) {\n\t\treturn { messages: [], thinkingLevel: \"off\", model: null };\n\t}\n\tconst path: SessionEntry[] = [];\n\tlet current: SessionEntry | undefined = leaf;\n\twhile (current) {\n\t\tpath.unshift(current);\n\t\tcurrent = current.parentId ? byId.get(current.parentId) : undefined;\n\t}\n\tlet thinkingLevel = \"off\";\n\tlet model: { provider: string; modelId: string } | null = null;\n\tlet compaction: CompactionEntry | null = null;\n\tfor (const entry of path) {\n\t\tif (entry.type === \"thinking_level_change\") {\n\t\t\tthinkingLevel = entry.thinkingLevel;\n\t\t} else if (entry.type === \"model_change\") {\n\t\t\tmodel = { provider: entry.provider, modelId: entry.modelId };\n\t\t} else if (entry.type === \"message\" && entry.message.role === \"assistant\") {\n\t\t\tmodel = { provider: entry.message.provider, modelId: entry.message.model };\n\t\t} else if (entry.type === \"compaction\") {\n\t\t\tcompaction = entry;\n\t\t}\n\t}\n\tconst messages: AgentMessage[] = [];\n\tconst appendMessage = (entry: SessionEntry) => {\n\t\tif (entry.type === \"message\") {\n\t\t\tmessages.push(entry.message);\n\t\t} else if (entry.type === \"custom_message\") {\n\t\t\tmessages.push(\n\t\t\t\tcreateCustomMessage(entry.customType, entry.content, entry.display, entry.details, entry.timestamp),\n\t\t\t);\n\t\t} else if (entry.type === \"branch_summary\" && entry.summary) {\n\t\t\tmessages.push(createBranchSummaryMessage(entry.summary, entry.fromId, entry.timestamp));\n\t\t}\n\t};\n\tif (compaction) {\n\t\tmessages.push(createCompactionSummaryMessage(compaction.summary, compaction.tokensBefore, compaction.timestamp));\n\t\tconst compactionIdx = path.findIndex((e) => e.type === \"compaction\" && e.id === compaction.id);\n\t\tlet foundFirstKept = false;\n\t\tfor (let i = 0; i < compactionIdx; i++) {\n\t\t\tconst entry = path[i];\n\t\t\tif (entry.id === compaction.firstKeptEntryId) {\n\t\t\t\tfoundFirstKept = true;\n\t\t\t}\n\t\t\tif (foundFirstKept) {\n\t\t\t\tappendMessage(entry);\n\t\t\t}\n\t\t}\n\t\tfor (let i = compactionIdx + 1; i < path.length; i++) {\n\t\t\tconst entry = path[i];\n\t\t\tappendMessage(entry);\n\t\t}\n\t} else {\n\t\tfor (const entry of path) {\n\t\t\tappendMessage(entry);\n\t\t}\n\t}\n\treturn { messages, thinkingLevel, model };\n}\nfunction getDefaultSessionDir(cwd: string): string {\n\tconst safePath = `--${cwd.replace(/^[/\\\\]/, \"\").replace(/[/\\\\:]/g, \"-\")}--`;\n\tconst sessionDir = join(getDefaultAgentDir(), \"sessions\", safePath);\n\tif (!existsSync(sessionDir)) {\n\t\tmkdirSync(sessionDir, { recursive: true });\n\t}\n\treturn sessionDir;\n}\nexport function loadEntriesFromFile(filePath: string): FileEntry[] {\n\tif (!existsSync(filePath)) return [];\n\tconst content = readFileSync(filePath, \"utf8\");\n\tconst entries: FileEntry[] = [];\n\tconst lines = content.trim().split(\"\\n\");\n\tfor (const line of lines) {\n\t\tif (!line.trim()) continue;\n\t\ttry {\n\t\t\tconst entry = JSON.parse(line) as FileEntry;\n\t\t\tentries.push(entry);\n\t\t} catch {}\n\t}\n\tif (entries.length === 0) return entries;\n\tconst header = entries[0];\n\tif (header.type !== \"session\" || typeof (header as any).id !== \"string\") {\n\t\treturn [];\n\t}\n\treturn entries;\n}\nfunction isValidSessionFile(filePath: string): boolean {\n\ttry {\n\t\tconst fd = openSync(filePath, \"r\");\n\t\tconst buffer = Buffer.alloc(512);\n\t\tconst bytesRead = readSync(fd, buffer, 0, 512, 0);\n\t\tcloseSync(fd);\n\t\tconst firstLine = buffer.toString(\"utf8\", 0, bytesRead).split(\"\\n\")[0];\n\t\tif (!firstLine) return false;\n\t\tconst header = JSON.parse(firstLine);\n\t\treturn header.type === \"session\" && typeof header.id === \"string\";\n\t} catch {\n\t\treturn false;\n\t}\n}\nexport function findMostRecentSession(sessionDir: string): string | null {\n\ttry {\n\t\tconst files = readdirSync(sessionDir)\n\t\t\t.filter((f) => f.endsWith(\".jsonl\"))\n\t\t\t.map((f) => join(sessionDir, f))\n\t\t\t.filter(isValidSessionFile)\n\t\t\t.map((path) => ({ path, mtime: statSync(path).mtime }))\n\t\t\t.sort((a, b) => b.mtime.getTime() - a.mtime.getTime());\n\t\treturn files[0]?.path || null;\n\t} catch {\n\t\treturn null;\n\t}\n}\nfunction isMessageWithContent(message: AgentMessage): message is Message {\n\treturn typeof (message as Message).role === \"string\" && \"content\" in message;\n}\nfunction extractTextContent(message: Message): string {\n\tconst content = message.content;\n\tif (typeof content === \"string\") {\n\t\treturn content;\n\t}\n\treturn content\n\t\t.filter((block): block is TextContent => block.type === \"text\")\n\t\t.map((block) => block.text)\n\t\t.join(\" \");\n}\nfunction getLastActivityTime(entries: FileEntry[]): number | undefined {\n\tlet lastActivityTime: number | undefined;\n\tfor (const entry of entries) {\n\t\tif (entry.type !== \"message\") continue;\n\t\tconst message = (entry as SessionMessageEntry).message;\n\t\tif (!isMessageWithContent(message)) continue;\n\t\tif (message.role !== \"user\" && message.role !== \"assistant\") continue;\n\t\tconst msgTimestamp = (message as { timestamp?: number }).timestamp;\n\t\tif (typeof msgTimestamp === \"number\") {\n\t\t\tlastActivityTime = Math.max(lastActivityTime ?? 0, msgTimestamp);\n\t\t\tcontinue;\n\t\t}\n\t\tconst entryTimestamp = (entry as SessionEntryBase).timestamp;\n\t\tif (typeof entryTimestamp === \"string\") {\n\t\t\tconst t = new Date(entryTimestamp).getTime();\n\t\t\tif (!Number.isNaN(t)) {\n\t\t\t\tlastActivityTime = Math.max(lastActivityTime ?? 0, t);\n\t\t\t}\n\t\t}\n\t}\n\treturn lastActivityTime;\n}\nfunction getSessionModifiedDate(entries: FileEntry[], header: SessionHeader, statsMtime: Date): Date {\n\tconst lastActivityTime = getLastActivityTime(entries);\n\tif (typeof lastActivityTime === \"number\" && lastActivityTime > 0) {\n\t\treturn new Date(lastActivityTime);\n\t}\n\tconst headerTime = typeof header.timestamp === \"string\" ? new Date(header.timestamp).getTime() : NaN;\n\treturn !Number.isNaN(headerTime) ? new Date(headerTime) : statsMtime;\n}\nasync function buildSessionInfo(filePath: string): Promise<SessionInfo | null> {\n\ttry {\n\t\tconst content = await readFile(filePath, \"utf8\");\n\t\tconst entries: FileEntry[] = [];\n\t\tconst lines = content.trim().split(\"\\n\");\n\t\tfor (const line of lines) {\n\t\t\tif (!line.trim()) continue;\n\t\t\ttry {\n\t\t\t\tentries.push(JSON.parse(line) as FileEntry);\n\t\t\t} catch {}\n\t\t}\n\t\tif (entries.length === 0) return null;\n\t\tconst header = entries[0];\n\t\tif (header.type !== \"session\") return null;\n\t\tconst stats = await stat(filePath);\n\t\tlet messageCount = 0;\n\t\tlet firstMessage = \"\";\n\t\tconst allMessages: string[] = [];\n\t\tlet name: string | undefined;\n\t\tfor (const entry of entries) {\n\t\t\tif (entry.type === \"session_info\") {\n\t\t\t\tconst infoEntry = entry as SessionInfoEntry;\n\t\t\t\tif (infoEntry.name) {\n\t\t\t\t\tname = infoEntry.name.trim();\n\t\t\t\t}\n\t\t\t}\n\t\t\tif (entry.type !== \"message\") continue;\n\t\t\tmessageCount++;\n\t\t\tconst message = (entry as SessionMessageEntry).message;\n\t\t\tif (!isMessageWithContent(message)) continue;\n\t\t\tif (message.role !== \"user\" && message.role !== \"assistant\") continue;\n\t\t\tconst textContent = extractTextContent(message);\n\t\t\tif (!textContent) continue;\n\t\t\tallMessages.push(textContent);\n\t\t\tif (!firstMessage && message.role === \"user\") {\n\t\t\t\tfirstMessage = textContent;\n\t\t\t}\n\t\t}\n\t\tconst cwd = typeof (header as SessionHeader).cwd === \"string\" ? (header as SessionHeader).cwd : \"\";\n\t\tconst parentSessionPath = (header as SessionHeader).parentSession;\n\t\tconst modified = getSessionModifiedDate(entries, header as SessionHeader, stats.mtime);\n\t\treturn {\n\t\t\tpath: filePath,\n\t\t\tid: (header as SessionHeader).id,\n\t\t\tcwd,\n\t\t\tname,\n\t\t\tparentSessionPath,\n\t\t\tcreated: new Date((header as SessionHeader).timestamp),\n\t\t\tmodified,\n\t\t\tmessageCount,\n\t\t\tfirstMessage: firstMessage || \"(no messages)\",\n\t\t\tallMessagesText: allMessages.join(\" \"),\n\t\t};\n\t} catch {\n\t\treturn null;\n\t}\n}\nexport type SessionListProgress = (loaded: number, total: number) => void;\nasync function listSessionsFromDir(\n\tdir: string,\n\tonProgress?: SessionListProgress,\n\tprogressOffset = 0,\n\tprogressTotal?: number,\n): Promise<SessionInfo[]> {\n\tconst sessions: SessionInfo[] = [];\n\tif (!existsSync(dir)) {\n\t\treturn sessions;\n\t}\n\ttry {\n\t\tconst dirEntries = await readdir(dir);\n\t\tconst files = dirEntries.filter((f) => f.endsWith(\".jsonl\")).map((f) => join(dir, f));\n\t\tconst total = progressTotal ?? files.length;\n\t\tlet loaded = 0;\n\t\tconst results = await Promise.all(\n\t\t\tfiles.map(async (file) => {\n\t\t\t\tconst info = await buildSessionInfo(file);\n\t\t\t\tloaded++;\n\t\t\t\tonProgress?.(progressOffset + loaded, total);\n\t\t\t\treturn info;\n\t\t\t}),\n\t\t);\n\t\tfor (const info of results) {\n\t\t\tif (info) {\n\t\t\t\tsessions.push(info);\n\t\t\t}\n\t\t}\n\t} catch {}\n\treturn sessions;\n}\nexport class SessionManager {\n\tprivate sessionId: string = \"\";\n\tprivate sessionFile: string | undefined;\n\tprivate sessionDir: string;\n\tprivate cwd: string;\n\tprivate persist: boolean;\n\tprivate flushed: boolean = false;\n\tprivate fileEntries: FileEntry[] = [];\n\tprivate byId: Map<string, SessionEntry> = new Map();\n\tprivate labelsById: Map<string, string> = new Map();\n\tprivate leafId: string | null = null;\n\tprivate constructor(cwd: string, sessionDir: string, sessionFile: string | undefined, persist: boolean) {\n\t\tthis.cwd = cwd;\n\t\tthis.sessionDir = sessionDir;\n\t\tthis.persist = persist;\n\t\tif (persist && sessionDir && !existsSync(sessionDir)) {\n\t\t\tmkdirSync(sessionDir, { recursive: true });\n\t\t}\n\t\tif (sessionFile) {\n\t\t\tthis.setSessionFile(sessionFile);\n\t\t} else {\n\t\t\tthis.newSession();\n\t\t}\n\t}\n\tsetSessionFile(sessionFile: string): void {\n\t\tthis.sessionFile = resolve(sessionFile);\n\t\tif (existsSync(this.sessionFile)) {\n\t\t\tthis.fileEntries = loadEntriesFromFile(this.sessionFile);\n\t\t\tif (this.fileEntries.length === 0) {\n\t\t\t\tconst explicitPath = this.sessionFile;\n\t\t\t\tthis.newSession();\n\t\t\t\tthis.sessionFile = explicitPath;\n\t\t\t\tthis._rewriteFile();\n\t\t\t\tthis.flushed = true;\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tconst header = this.fileEntries.find((e) => e.type === \"session\") as SessionHeader | undefined;\n\t\t\tthis.sessionId = header?.id ?? randomUUID();\n\t\t\tif (migrateToCurrentVersion(this.fileEntries)) {\n\t\t\t\tthis._rewriteFile();\n\t\t\t}\n\t\t\tthis._buildIndex();\n\t\t\tthis.flushed = true;\n\t\t} else {\n\t\t\tconst explicitPath = this.sessionFile;\n\t\t\tthis.newSession();\n\t\t\tthis.sessionFile = explicitPath;\n\t\t}\n\t}\n\tnewSession(options?: NewSessionOptions): string | undefined {\n\t\tthis.sessionId = randomUUID();\n\t\tconst timestamp = new Date().toISOString();\n\t\tconst header: SessionHeader = {\n\t\t\ttype: \"session\",\n\t\t\tversion: CURRENT_SESSION_VERSION,\n\t\t\tid: this.sessionId,\n\t\t\ttimestamp,\n\t\t\tcwd: this.cwd,\n\t\t\tparentSession: options?.parentSession,\n\t\t};\n\t\tthis.fileEntries = [header];\n\t\tthis.byId.clear();\n\t\tthis.labelsById.clear();\n\t\tthis.leafId = null;\n\t\tthis.flushed = false;\n\t\tif (this.persist) {\n\t\t\tconst fileTimestamp = timestamp.replace(/[:.]/g, \"-\");\n\t\t\tthis.sessionFile = join(this.getSessionDir(), `${fileTimestamp}_${this.sessionId}.jsonl`);\n\t\t}\n\t\treturn this.sessionFile;\n\t}\n\tprivate _buildIndex(): void {\n\t\tthis.byId.clear();\n\t\tthis.labelsById.clear();\n\t\tthis.leafId = null;\n\t\tfor (const entry of this.fileEntries) {\n\t\t\tif (entry.type === \"session\") continue;\n\t\t\tthis.byId.set(entry.id, entry);\n\t\t\tthis.leafId = entry.id;\n\t\t\tif (entry.type === \"label\") {\n\t\t\t\tif (entry.label) {\n\t\t\t\t\tthis.labelsById.set(entry.targetId, entry.label);\n\t\t\t\t} else {\n\t\t\t\t\tthis.labelsById.delete(entry.targetId);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\tprivate _rewriteFile(): void {\n\t\tif (!this.persist || !this.sessionFile) return;\n\t\tconst content = `${this.fileEntries.map((e) => JSON.stringify(e)).join(\"\\n\")}\\n`;\n\t\twriteFileSync(this.sessionFile, content);\n\t}\n\tisPersisted(): boolean {\n\t\treturn this.persist;\n\t}\n\tgetCwd(): string {\n\t\treturn this.cwd;\n\t}\n\tgetSessionDir(): string {\n\t\treturn this.sessionDir;\n\t}\n\tgetSessionId(): string {\n\t\treturn this.sessionId;\n\t}\n\tgetSessionFile(): string | undefined {\n\t\treturn this.sessionFile;\n\t}\n\t_persist(entry: SessionEntry): void {\n\t\tif (!this.persist || !this.sessionFile) return;\n\t\tconst hasAssistant = this.fileEntries.some((e) => e.type === \"message\" && e.message.role === \"assistant\");\n\t\tif (!hasAssistant) {\n\t\t\tthis.flushed = false;\n\t\t\treturn;\n\t\t}\n\t\tif (!this.flushed) {\n\t\t\tfor (const e of this.fileEntries) {\n\t\t\t\tappendFileSync(this.sessionFile, `${JSON.stringify(e)}\\n`);\n\t\t\t}\n\t\t\tthis.flushed = true;\n\t\t} else {\n\t\t\tappendFileSync(this.sessionFile, `${JSON.stringify(entry)}\\n`);\n\t\t}\n\t}\n\tprivate _appendEntry(entry: SessionEntry): void {\n\t\tthis.fileEntries.push(entry);\n\t\tthis.byId.set(entry.id, entry);\n\t\tthis.leafId = entry.id;\n\t\tthis._persist(entry);\n\t}\n\tappendMessage(message: Message | CustomMessage | BashExecutionMessage): string {\n\t\tconst entry: SessionMessageEntry = {\n\t\t\ttype: \"message\",\n\t\t\tid: generateId(this.byId),\n\t\t\tparentId: this.leafId,\n\t\t\ttimestamp: new Date().toISOString(),\n\t\t\tmessage,\n\t\t};\n\t\tthis._appendEntry(entry);\n\t\treturn entry.id;\n\t}\n\tappendThinkingLevelChange(thinkingLevel: string): string {\n\t\tconst entry: ThinkingLevelChangeEntry = {\n\t\t\ttype: \"thinking_level_change\",\n\t\t\tid: generateId(this.byId),\n\t\t\tparentId: this.leafId,\n\t\t\ttimestamp: new Date().toISOString(),\n\t\t\tthinkingLevel,\n\t\t};\n\t\tthis._appendEntry(entry);\n\t\treturn entry.id;\n\t}\n\tappendModelChange(provider: string, modelId: string): string {\n\t\tconst entry: ModelChangeEntry = {\n\t\t\ttype: \"model_change\",\n\t\t\tid: generateId(this.byId),\n\t\t\tparentId: this.leafId,\n\t\t\ttimestamp: new Date().toISOString(),\n\t\t\tprovider,\n\t\t\tmodelId,\n\t\t};\n\t\tthis._appendEntry(entry);\n\t\treturn entry.id;\n\t}\n\tappendCompaction<T = unknown>(\n\t\tsummary: string,\n\t\tfirstKeptEntryId: string,\n\t\ttokensBefore: number,\n\t\tdetails?: T,\n\t\tfromHook?: boolean,\n\t): string {\n\t\tconst entry: CompactionEntry<T> = {\n\t\t\ttype: \"compaction\",\n\t\t\tid: generateId(this.byId),\n\t\t\tparentId: this.leafId,\n\t\t\ttimestamp: new Date().toISOString(),\n\t\t\tsummary,\n\t\t\tfirstKeptEntryId,\n\t\t\ttokensBefore,\n\t\t\tdetails,\n\t\t\tfromHook,\n\t\t};\n\t\tthis._appendEntry(entry);\n\t\treturn entry.id;\n\t}\n\tappendCustomEntry(customType: string, data?: unknown): string {\n\t\tconst entry: CustomEntry = {\n\t\t\ttype: \"custom\",\n\t\t\tcustomType,\n\t\t\tdata,\n\t\t\tid: generateId(this.byId),\n\t\t\tparentId: this.leafId,\n\t\t\ttimestamp: new Date().toISOString(),\n\t\t};\n\t\tthis._appendEntry(entry);\n\t\treturn entry.id;\n\t}\n\tappendSessionInfo(name: string): string {\n\t\tconst entry: SessionInfoEntry = {\n\t\t\ttype: \"session_info\",\n\t\t\tid: generateId(this.byId),\n\t\t\tparentId: this.leafId,\n\t\t\ttimestamp: new Date().toISOString(),\n\t\t\tname: name.trim(),\n\t\t};\n\t\tthis._appendEntry(entry);\n\t\treturn entry.id;\n\t}\n\tgetSessionName(): string | undefined {\n\t\tconst entries = this.getEntries();\n\t\tfor (let i = entries.length - 1; i >= 0; i--) {\n\t\t\tconst entry = entries[i];\n\t\t\tif (entry.type === \"session_info\" && entry.name) {\n\t\t\t\treturn entry.name;\n\t\t\t}\n\t\t}\n\t\treturn undefined;\n\t}\n\tappendCustomMessageEntry<T = unknown>(\n\t\tcustomType: string,\n\t\tcontent: string | (TextContent | ImageContent)[],\n\t\tdisplay: boolean,\n\t\tdetails?: T,\n\t): string {\n\t\tconst entry: CustomMessageEntry<T> = {\n\t\t\ttype: \"custom_message\",\n\t\t\tcustomType,\n\t\t\tcontent,\n\t\t\tdisplay,\n\t\t\tdetails,\n\t\t\tid: generateId(this.byId),\n\t\t\tparentId: this.leafId,\n\t\t\ttimestamp: new Date().toISOString(),\n\t\t};\n\t\tthis._appendEntry(entry);\n\t\treturn entry.id;\n\t}\n\tgetLeafId(): string | null {\n\t\treturn this.leafId;\n\t}\n\tgetLeafEntry(): SessionEntry | undefined {\n\t\treturn this.leafId ? this.byId.get(this.leafId) : undefined;\n\t}\n\tgetEntry(id: string): SessionEntry | undefined {\n\t\treturn this.byId.get(id);\n\t}\n\tgetChildren(parentId: string): SessionEntry[] {\n\t\tconst children: SessionEntry[] = [];\n\t\tfor (const entry of this.byId.values()) {\n\t\t\tif (entry.parentId === parentId) {\n\t\t\t\tchildren.push(entry);\n\t\t\t}\n\t\t}\n\t\treturn children;\n\t}\n\tgetLabel(id: string): string | undefined {\n\t\treturn this.labelsById.get(id);\n\t}\n\tappendLabelChange(targetId: string, label: string | undefined): string {\n\t\tif (!this.byId.has(targetId)) {\n\t\t\tthrow new Error(`Entry ${targetId} not found`);\n\t\t}\n\t\tconst entry: LabelEntry = {\n\t\t\ttype: \"label\",\n\t\t\tid: generateId(this.byId),\n\t\t\tparentId: this.leafId,\n\t\t\ttimestamp: new Date().toISOString(),\n\t\t\ttargetId,\n\t\t\tlabel,\n\t\t};\n\t\tthis._appendEntry(entry);\n\t\tif (label) {\n\t\t\tthis.labelsById.set(targetId, label);\n\t\t} else {\n\t\t\tthis.labelsById.delete(targetId);\n\t\t}\n\t\treturn entry.id;\n\t}\n\tgetBranch(fromId?: string): SessionEntry[] {\n\t\tconst path: SessionEntry[] = [];\n\t\tconst startId = fromId ?? this.leafId;\n\t\tlet current = startId ? this.byId.get(startId) : undefined;\n\t\twhile (current) {\n\t\t\tpath.unshift(current);\n\t\t\tcurrent = current.parentId ? this.byId.get(current.parentId) : undefined;\n\t\t}\n\t\treturn path;\n\t}\n\tbuildSessionContext(): SessionContext {\n\t\treturn buildSessionContext(this.getEntries(), this.leafId, this.byId);\n\t}\n\tgetHeader(): SessionHeader | null {\n\t\tconst h = this.fileEntries.find((e) => e.type === \"session\");\n\t\treturn h ? (h as SessionHeader) : null;\n\t}\n\tgetEntries(): SessionEntry[] {\n\t\treturn this.fileEntries.filter((e): e is SessionEntry => e.type !== \"session\");\n\t}\n\tgetTree(): SessionTreeNode[] {\n\t\tconst entries = this.getEntries();\n\t\tconst nodeMap = new Map<string, SessionTreeNode>();\n\t\tconst roots: SessionTreeNode[] = [];\n\t\tfor (const entry of entries) {\n\t\t\tconst label = this.labelsById.get(entry.id);\n\t\t\tnodeMap.set(entry.id, { entry, children: [], label });\n\t\t}\n\t\tfor (const entry of entries) {\n\t\t\tconst node = nodeMap.get(entry.id)!;\n\t\t\tif (entry.parentId === null || entry.parentId === entry.id) {\n\t\t\t\troots.push(node);\n\t\t\t} else {\n\t\t\t\tconst parent = nodeMap.get(entry.parentId);\n\t\t\t\tif (parent) {\n\t\t\t\t\tparent.children.push(node);\n\t\t\t\t} else {\n\t\t\t\t\troots.push(node);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tconst stack: SessionTreeNode[] = [...roots];\n\t\twhile (stack.length > 0) {\n\t\t\tconst node = stack.pop()!;\n\t\t\tnode.children.sort((a, b) => new Date(a.entry.timestamp).getTime() - new Date(b.entry.timestamp).getTime());\n\t\t\tstack.push(...node.children);\n\t\t}\n\t\treturn roots;\n\t}\n\tbranch(branchFromId: string): void {\n\t\tif (!this.byId.has(branchFromId)) {\n\t\t\tthrow new Error(`Entry ${branchFromId} not found`);\n\t\t}\n\t\tthis.leafId = branchFromId;\n\t}\n\tresetLeaf(): void {\n\t\tthis.leafId = null;\n\t}\n\tbranchWithSummary(branchFromId: string | null, summary: string, details?: unknown, fromHook?: boolean): string {\n\t\tif (branchFromId !== null && !this.byId.has(branchFromId)) {\n\t\t\tthrow new Error(`Entry ${branchFromId} not found`);\n\t\t}\n\t\tthis.leafId = branchFromId;\n\t\tconst entry: BranchSummaryEntry = {\n\t\t\ttype: \"branch_summary\",\n\t\t\tid: generateId(this.byId),\n\t\t\tparentId: branchFromId,\n\t\t\ttimestamp: new Date().toISOString(),\n\t\t\tfromId: branchFromId ?? \"root\",\n\t\t\tsummary,\n\t\t\tdetails,\n\t\t\tfromHook,\n\t\t};\n\t\tthis._appendEntry(entry);\n\t\treturn entry.id;\n\t}\n\tcreateBranchedSession(leafId: string): string | undefined {\n\t\tconst previousSessionFile = this.sessionFile;\n\t\tconst path = this.getBranch(leafId);\n\t\tif (path.length === 0) {\n\t\t\tthrow new Error(`Entry ${leafId} not found`);\n\t\t}\n\t\tconst pathWithoutLabels = path.filter((e) => e.type !== \"label\");\n\t\tconst newSessionId = randomUUID();\n\t\tconst timestamp = new Date().toISOString();\n\t\tconst fileTimestamp = timestamp.replace(/[:.]/g, \"-\");\n\t\tconst newSessionFile = join(this.getSessionDir(), `${fileTimestamp}_${newSessionId}.jsonl`);\n\t\tconst header: SessionHeader = {\n\t\t\ttype: \"session\",\n\t\t\tversion: CURRENT_SESSION_VERSION,\n\t\t\tid: newSessionId,\n\t\t\ttimestamp,\n\t\t\tcwd: this.cwd,\n\t\t\tparentSession: this.persist ? previousSessionFile : undefined,\n\t\t};\n\t\tconst pathEntryIds = new Set(pathWithoutLabels.map((e) => e.id));\n\t\tconst labelsToWrite: Array<{ targetId: string; label: string }> = [];\n\t\tfor (const [targetId, label] of this.labelsById) {\n\t\t\tif (pathEntryIds.has(targetId)) {\n\t\t\t\tlabelsToWrite.push({ targetId, label });\n\t\t\t}\n\t\t}\n\t\tif (this.persist) {\n\t\t\tconst lastEntryId = pathWithoutLabels[pathWithoutLabels.length - 1]?.id || null;\n\t\t\tlet parentId = lastEntryId;\n\t\t\tconst labelEntries: LabelEntry[] = [];\n\t\t\tfor (const { targetId, label } of labelsToWrite) {\n\t\t\t\tconst labelEntry: LabelEntry = {\n\t\t\t\t\ttype: \"label\",\n\t\t\t\t\tid: generateId(new Set(pathEntryIds)),\n\t\t\t\t\tparentId,\n\t\t\t\t\ttimestamp: new Date().toISOString(),\n\t\t\t\t\ttargetId,\n\t\t\t\t\tlabel,\n\t\t\t\t};\n\t\t\t\tpathEntryIds.add(labelEntry.id);\n\t\t\t\tlabelEntries.push(labelEntry);\n\t\t\t\tparentId = labelEntry.id;\n\t\t\t}\n\t\t\tthis.fileEntries = [header, ...pathWithoutLabels, ...labelEntries];\n\t\t\tthis.sessionId = newSessionId;\n\t\t\tthis.sessionFile = newSessionFile;\n\t\t\tthis._buildIndex();\n\t\t\tconst hasAssistant = this.fileEntries.some((e) => e.type === \"message\" && e.message.role === \"assistant\");\n\t\t\tif (hasAssistant) {\n\t\t\t\tthis._rewriteFile();\n\t\t\t\tthis.flushed = true;\n\t\t\t} else {\n\t\t\t\tthis.flushed = false;\n\t\t\t}\n\t\t\treturn newSessionFile;\n\t\t}\n\t\tconst labelEntries: LabelEntry[] = [];\n\t\tlet parentId = pathWithoutLabels[pathWithoutLabels.length - 1]?.id || null;\n\t\tfor (const { targetId, label } of labelsToWrite) {\n\t\t\tconst labelEntry: LabelEntry = {\n\t\t\t\ttype: \"label\",\n\t\t\t\tid: generateId(new Set([...pathEntryIds, ...labelEntries.map((e) => e.id)])),\n\t\t\t\tparentId,\n\t\t\t\ttimestamp: new Date().toISOString(),\n\t\t\t\ttargetId,\n\t\t\t\tlabel,\n\t\t\t};\n\t\t\tlabelEntries.push(labelEntry);\n\t\t\tparentId = labelEntry.id;\n\t\t}\n\t\tthis.fileEntries = [header, ...pathWithoutLabels, ...labelEntries];\n\t\tthis.sessionId = newSessionId;\n\t\tthis._buildIndex();\n\t\treturn undefined;\n\t}\n\tstatic create(cwd: string, sessionDir?: string): SessionManager {\n\t\tconst dir = sessionDir ?? getDefaultSessionDir(cwd);\n\t\treturn new SessionManager(cwd, dir, undefined, true);\n\t}\n\tstatic open(path: string, sessionDir?: string): SessionManager {\n\t\tconst entries = loadEntriesFromFile(path);\n\t\tconst header = entries.find((e) => e.type === \"session\") as SessionHeader | undefined;\n\t\tconst cwd = header?.cwd ?? process.cwd();\n\t\tconst dir = sessionDir ?? resolve(path, \"..\");\n\t\treturn new SessionManager(cwd, dir, path, true);\n\t}\n\tstatic continueRecent(cwd: string, sessionDir?: string): SessionManager {\n\t\tconst dir = sessionDir ?? getDefaultSessionDir(cwd);\n\t\tconst mostRecent = findMostRecentSession(dir);\n\t\tif (mostRecent) {\n\t\t\treturn new SessionManager(cwd, dir, mostRecent, true);\n\t\t}\n\t\treturn new SessionManager(cwd, dir, undefined, true);\n\t}\n\tstatic inMemory(cwd: string = process.cwd()): SessionManager {\n\t\treturn new SessionManager(cwd, \"\", undefined, false);\n\t}\n\tstatic forkFrom(sourcePath: string, targetCwd: string, sessionDir?: string): SessionManager {\n\t\tconst sourceEntries = loadEntriesFromFile(sourcePath);\n\t\tif (sourceEntries.length === 0) {\n\t\t\tthrow new Error(`Cannot fork: source session file is empty or invalid: ${sourcePath}`);\n\t\t}\n\t\tconst sourceHeader = sourceEntries.find((e) => e.type === \"session\") as SessionHeader | undefined;\n\t\tif (!sourceHeader) {\n\t\t\tthrow new Error(`Cannot fork: source session has no header: ${sourcePath}`);\n\t\t}\n\t\tconst dir = sessionDir ?? getDefaultSessionDir(targetCwd);\n\t\tif (!existsSync(dir)) {\n\t\t\tmkdirSync(dir, { recursive: true });\n\t\t}\n\t\tconst newSessionId = randomUUID();\n\t\tconst timestamp = new Date().toISOString();\n\t\tconst fileTimestamp = timestamp.replace(/[:.]/g, \"-\");\n\t\tconst newSessionFile = join(dir, `${fileTimestamp}_${newSessionId}.jsonl`);\n\t\tconst newHeader: SessionHeader = {\n\t\t\ttype: \"session\",\n\t\t\tversion: CURRENT_SESSION_VERSION,\n\t\t\tid: newSessionId,\n\t\t\ttimestamp,\n\t\t\tcwd: targetCwd,\n\t\t\tparentSession: sourcePath,\n\t\t};\n\t\tappendFileSync(newSessionFile, `${JSON.stringify(newHeader)}\\n`);\n\t\tfor (const entry of sourceEntries) {\n\t\t\tif (entry.type !== \"session\") {\n\t\t\t\tappendFileSync(newSessionFile, `${JSON.stringify(entry)}\\n`);\n\t\t\t}\n\t\t}\n\t\treturn new SessionManager(targetCwd, dir, newSessionFile, true);\n\t}\n\tstatic async list(cwd: string, sessionDir?: string, onProgress?: SessionListProgress): Promise<SessionInfo[]> {\n\t\tconst dir = sessionDir ?? getDefaultSessionDir(cwd);\n\t\tconst sessions = await listSessionsFromDir(dir, onProgress);\n\t\tsessions.sort((a, b) => b.modified.getTime() - a.modified.getTime());\n\t\treturn sessions;\n\t}\n\tstatic async listAll(onProgress?: SessionListProgress): Promise<SessionInfo[]> {\n\t\tconst sessionsDir = getSessionsDir();\n\t\ttry {\n\t\t\tif (!existsSync(sessionsDir)) {\n\t\t\t\treturn [];\n\t\t\t}\n\t\t\tconst entries = await readdir(sessionsDir, { withFileTypes: true });\n\t\t\tconst dirs = entries.filter((e) => e.isDirectory()).map((e) => join(sessionsDir, e.name));\n\t\t\tlet totalFiles = 0;\n\t\t\tconst dirFiles: string[][] = [];\n\t\t\tfor (const dir of dirs) {\n\t\t\t\ttry {\n\t\t\t\t\tconst files = (await readdir(dir)).filter((f) => f.endsWith(\".jsonl\"));\n\t\t\t\t\tdirFiles.push(files.map((f) => join(dir, f)));\n\t\t\t\t\ttotalFiles += files.length;\n\t\t\t\t} catch {\n\t\t\t\t\tdirFiles.push([]);\n\t\t\t\t}\n\t\t\t}\n\t\t\tlet loaded = 0;\n\t\t\tconst sessions: SessionInfo[] = [];\n\t\t\tconst allFiles = dirFiles.flat();\n\t\t\tconst results = await Promise.all(\n\t\t\t\tallFiles.map(async (file) => {\n\t\t\t\t\tconst info = await buildSessionInfo(file);\n\t\t\t\t\tloaded++;\n\t\t\t\t\tonProgress?.(loaded, totalFiles);\n\t\t\t\t\treturn info;\n\t\t\t\t}),\n\t\t\t);\n\t\t\tfor (const info of results) {\n\t\t\t\tif (info) {\n\t\t\t\t\tsessions.push(info);\n\t\t\t\t}\n\t\t\t}\n\t\t\tsessions.sort((a, b) => b.modified.getTime() - a.modified.getTime());\n\t\t\treturn sessions;\n\t\t} catch {\n\t\t\treturn [];\n\t\t}\n\t}\n}\n"]}