@greppleai/grip 0.1.5 → 0.1.7

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 (587) hide show
  1. package/CHANGELOG.md +35 -0
  2. package/README.md +1 -1
  3. package/dist/bun/cli.d.ts.map +1 -1
  4. package/dist/bun/cli.js.map +1 -1
  5. package/dist/bun/embedded-assets.d.ts.map +1 -1
  6. package/dist/bun/embedded-assets.js.map +1 -1
  7. package/dist/bun/register-bedrock.d.ts.map +1 -1
  8. package/dist/bun/restore-sandbox-env.d.ts.map +1 -1
  9. package/dist/bun/restore-sandbox-env.js.map +1 -1
  10. package/dist/cli/args.d.ts.map +1 -1
  11. package/dist/cli/args.js.map +1 -1
  12. package/dist/cli/config-selector.d.ts.map +1 -1
  13. package/dist/cli/config-selector.js.map +1 -1
  14. package/dist/cli/file-processor.d.ts.map +1 -1
  15. package/dist/cli/file-processor.js.map +1 -1
  16. package/dist/cli/initial-message.d.ts +1 -1
  17. package/dist/cli/initial-message.d.ts.map +1 -1
  18. package/dist/cli/initial-message.js.map +1 -1
  19. package/dist/cli/list-models.d.ts.map +1 -1
  20. package/dist/cli/list-models.js.map +1 -1
  21. package/dist/cli/session-picker.d.ts.map +1 -1
  22. package/dist/cli/session-picker.js.map +1 -1
  23. package/dist/cli.d.ts.map +1 -1
  24. package/dist/cli.js.map +1 -1
  25. package/dist/config.d.ts.map +1 -1
  26. package/dist/config.js +2 -0
  27. package/dist/config.js.map +1 -1
  28. package/dist/core/agent-session.d.ts +38 -1
  29. package/dist/core/agent-session.d.ts.map +1 -1
  30. package/dist/core/agent-session.js +289 -154
  31. package/dist/core/agent-session.js.map +1 -1
  32. package/dist/core/auth-guidance.d.ts.map +1 -1
  33. package/dist/core/auth-guidance.js.map +1 -1
  34. package/dist/core/auth-storage.d.ts +4 -0
  35. package/dist/core/auth-storage.d.ts.map +1 -1
  36. package/dist/core/auth-storage.js +3 -10
  37. package/dist/core/auth-storage.js.map +1 -1
  38. package/dist/core/bash-executor.d.ts.map +1 -1
  39. package/dist/core/bash-executor.js +19 -23
  40. package/dist/core/bash-executor.js.map +1 -1
  41. package/dist/core/compaction/branch-summarization.d.ts.map +1 -1
  42. package/dist/core/compaction/branch-summarization.js.map +1 -1
  43. package/dist/core/compaction/compaction.d.ts.map +1 -1
  44. package/dist/core/compaction/compaction.js +9 -2
  45. package/dist/core/compaction/compaction.js.map +1 -1
  46. package/dist/core/compaction/compression-detection-ledger.d.ts.map +1 -1
  47. package/dist/core/compaction/compression-detection-ledger.js.map +1 -1
  48. package/dist/core/compaction/compression-detector.d.ts +1 -0
  49. package/dist/core/compaction/compression-detector.d.ts.map +1 -1
  50. package/dist/core/compaction/compression-detector.js +10 -21
  51. package/dist/core/compaction/compression-detector.js.map +1 -1
  52. package/dist/core/compaction/compression-economics.d.ts.map +1 -1
  53. package/dist/core/compaction/compression-economics.js.map +1 -1
  54. package/dist/core/compaction/utils.d.ts.map +1 -1
  55. package/dist/core/compaction/utils.js.map +1 -1
  56. package/dist/core/defaults.d.ts.map +1 -1
  57. package/dist/core/diagnostics.d.ts.map +1 -1
  58. package/dist/core/event-bus.d.ts.map +1 -1
  59. package/dist/core/event-bus.js.map +1 -1
  60. package/dist/core/exec.d.ts.map +1 -1
  61. package/dist/core/exec.js.map +1 -1
  62. package/dist/core/export-html/ansi-to-html.d.ts.map +1 -1
  63. package/dist/core/export-html/ansi-to-html.js.map +1 -1
  64. package/dist/core/export-html/index.d.ts.map +1 -1
  65. package/dist/core/export-html/index.js.map +1 -1
  66. package/dist/core/export-html/tool-renderer.d.ts.map +1 -1
  67. package/dist/core/export-html/tool-renderer.js.map +1 -1
  68. package/dist/core/extensions/loader.d.ts.map +1 -1
  69. package/dist/core/extensions/loader.js.map +1 -1
  70. package/dist/core/extensions/runner.d.ts +3 -0
  71. package/dist/core/extensions/runner.d.ts.map +1 -1
  72. package/dist/core/extensions/runner.js +40 -30
  73. package/dist/core/extensions/runner.js.map +1 -1
  74. package/dist/core/extensions/types.d.ts +21 -1
  75. package/dist/core/extensions/types.d.ts.map +1 -1
  76. package/dist/core/extensions/types.js.map +1 -1
  77. package/dist/core/extensions/wrapper.d.ts.map +1 -1
  78. package/dist/core/extensions/wrapper.js.map +1 -1
  79. package/dist/core/footer-data-provider.d.ts.map +1 -1
  80. package/dist/core/footer-data-provider.js +15 -16
  81. package/dist/core/footer-data-provider.js.map +1 -1
  82. package/dist/core/grip-agent.d.ts.map +1 -1
  83. package/dist/core/grip-agent.js +7 -21
  84. package/dist/core/grip-agent.js.map +1 -1
  85. package/dist/core/grip-manifest.d.ts.map +1 -1
  86. package/dist/core/grip-manifest.js.map +1 -1
  87. package/dist/core/hooks/aggregate.d.ts.map +1 -1
  88. package/dist/core/hooks/aggregate.js.map +1 -1
  89. package/dist/core/hooks/config.d.ts.map +1 -1
  90. package/dist/core/hooks/config.js.map +1 -1
  91. package/dist/core/hooks/executor.d.ts.map +1 -1
  92. package/dist/core/hooks/executor.js.map +1 -1
  93. package/dist/core/hooks/index.d.ts.map +1 -1
  94. package/dist/core/hooks/index.js.map +1 -1
  95. package/dist/core/hooks/matcher.d.ts.map +1 -1
  96. package/dist/core/hooks/matcher.js.map +1 -1
  97. package/dist/core/hooks/trust-store.d.ts.map +1 -1
  98. package/dist/core/hooks/trust-store.js +0 -3
  99. package/dist/core/hooks/trust-store.js.map +1 -1
  100. package/dist/core/hooks/types.d.ts.map +1 -1
  101. package/dist/core/hooks/types.js.map +1 -1
  102. package/dist/core/http-dispatcher.d.ts.map +1 -1
  103. package/dist/core/http-dispatcher.js.map +1 -1
  104. package/dist/core/instruction-resource-loader.d.ts +1 -0
  105. package/dist/core/instruction-resource-loader.d.ts.map +1 -1
  106. package/dist/core/instruction-resource-loader.js +2 -4
  107. package/dist/core/instruction-resource-loader.js.map +1 -1
  108. package/dist/core/keybindings.d.ts.map +1 -1
  109. package/dist/core/keybindings.js +0 -1
  110. package/dist/core/keybindings.js.map +1 -1
  111. package/dist/core/lsp/abort.d.ts.map +1 -1
  112. package/dist/core/lsp/abort.js.map +1 -1
  113. package/dist/core/lsp/client.d.ts.map +1 -1
  114. package/dist/core/lsp/client.js +8 -22
  115. package/dist/core/lsp/client.js.map +1 -1
  116. package/dist/core/lsp/config-loader.d.ts.map +1 -1
  117. package/dist/core/lsp/config-loader.js.map +1 -1
  118. package/dist/core/lsp/config.d.ts.map +1 -1
  119. package/dist/core/lsp/config.js.map +1 -1
  120. package/dist/core/lsp/diagnostics.d.ts.map +1 -1
  121. package/dist/core/lsp/diagnostics.js.map +1 -1
  122. package/dist/core/lsp/file-sync.d.ts.map +1 -1
  123. package/dist/core/lsp/file-sync.js +7 -9
  124. package/dist/core/lsp/file-sync.js.map +1 -1
  125. package/dist/core/lsp/integration.d.ts.map +1 -1
  126. package/dist/core/lsp/integration.js.map +1 -1
  127. package/dist/core/lsp/language-map.d.ts.map +1 -1
  128. package/dist/core/lsp/language-map.js +2 -7
  129. package/dist/core/lsp/language-map.js.map +1 -1
  130. package/dist/core/lsp/manager.d.ts.map +1 -1
  131. package/dist/core/lsp/manager.js +18 -29
  132. package/dist/core/lsp/manager.js.map +1 -1
  133. package/dist/core/lsp/navigation.d.ts.map +1 -1
  134. package/dist/core/lsp/navigation.js.map +1 -1
  135. package/dist/core/lsp/portable-path.d.ts.map +1 -1
  136. package/dist/core/lsp/portable-path.js.map +1 -1
  137. package/dist/core/lsp/refactor.d.ts.map +1 -1
  138. package/dist/core/lsp/refactor.js.map +1 -1
  139. package/dist/core/lsp/transport.d.ts.map +1 -1
  140. package/dist/core/lsp/transport.js.map +1 -1
  141. package/dist/core/messages.d.ts.map +1 -1
  142. package/dist/core/messages.js +30 -1
  143. package/dist/core/messages.js.map +1 -1
  144. package/dist/core/model-registry.d.ts.map +1 -1
  145. package/dist/core/model-registry.js +5 -7
  146. package/dist/core/model-registry.js.map +1 -1
  147. package/dist/core/model-resolver.d.ts.map +1 -1
  148. package/dist/core/model-resolver.js.map +1 -1
  149. package/dist/core/output-guard.d.ts.map +1 -1
  150. package/dist/core/output-guard.js.map +1 -1
  151. package/dist/core/package-manager.d.ts.map +1 -1
  152. package/dist/core/package-manager.js +0 -6
  153. package/dist/core/package-manager.js.map +1 -1
  154. package/dist/core/prompt-templates.d.ts.map +1 -1
  155. package/dist/core/prompt-templates.js.map +1 -1
  156. package/dist/core/provider-display-names.d.ts.map +1 -1
  157. package/dist/core/remote-workspace-protocol/contract.d.ts.map +1 -1
  158. package/dist/core/remote-workspace-protocol/contract.js +4 -2
  159. package/dist/core/remote-workspace-protocol/contract.js.map +1 -1
  160. package/dist/core/remote-workspace-protocol/guest-shared-client.d.ts.map +1 -1
  161. package/dist/core/remote-workspace-protocol/guest-shared-client.js +1 -5
  162. package/dist/core/remote-workspace-protocol/guest-shared-client.js.map +1 -1
  163. package/dist/core/remote-workspace-protocol/guest-shared-outbound-scheduler.d.ts.map +1 -1
  164. package/dist/core/remote-workspace-protocol/guest-shared-outbound-scheduler.js +5 -10
  165. package/dist/core/remote-workspace-protocol/guest-shared-outbound-scheduler.js.map +1 -1
  166. package/dist/core/remote-workspace-protocol/guest-shared-uplink.d.ts.map +1 -1
  167. package/dist/core/remote-workspace-protocol/guest-shared-uplink.js +2 -9
  168. package/dist/core/remote-workspace-protocol/guest-shared-uplink.js.map +1 -1
  169. package/dist/core/remote-workspace-protocol/lima-owner-directory.d.ts.map +1 -1
  170. package/dist/core/remote-workspace-protocol/lima-owner-directory.js.map +1 -1
  171. package/dist/core/remote-workspace-protocol/lima-owner-lock.d.ts.map +1 -1
  172. package/dist/core/remote-workspace-protocol/lima-owner-lock.js.map +1 -1
  173. package/dist/core/remote-workspace-protocol/session.d.ts.map +1 -1
  174. package/dist/core/remote-workspace-protocol/session.js +27 -65
  175. package/dist/core/remote-workspace-protocol/session.js.map +1 -1
  176. package/dist/core/remote-workspace-protocol/shared-transport.d.ts.map +1 -1
  177. package/dist/core/remote-workspace-protocol/shared-transport.js.map +1 -1
  178. package/dist/core/resolve-config-value.d.ts.map +1 -1
  179. package/dist/core/resolve-config-value.js.map +1 -1
  180. package/dist/core/resource-loader.d.ts.map +1 -1
  181. package/dist/core/resource-loader.js +0 -48
  182. package/dist/core/resource-loader.js.map +1 -1
  183. package/dist/core/rules.d.ts.map +1 -1
  184. package/dist/core/rules.js.map +1 -1
  185. package/dist/core/sandbox/command.d.ts.map +1 -1
  186. package/dist/core/sandbox/command.js.map +1 -1
  187. package/dist/core/sandbox/config.d.ts.map +1 -1
  188. package/dist/core/sandbox/config.js.map +1 -1
  189. package/dist/core/sandbox/lima-guest-binary.d.ts.map +1 -1
  190. package/dist/core/sandbox/lima-guest-binary.js.map +1 -1
  191. package/dist/core/sandbox/lima.d.ts +2 -0
  192. package/dist/core/sandbox/lima.d.ts.map +1 -1
  193. package/dist/core/sandbox/lima.js +3 -9
  194. package/dist/core/sandbox/lima.js.map +1 -1
  195. package/dist/core/sandbox/shared-lima-roots.d.ts.map +1 -1
  196. package/dist/core/sandbox/shared-lima-roots.js.map +1 -1
  197. package/dist/core/sandbox/update-shared-guest-binary.d.ts.map +1 -1
  198. package/dist/core/sandbox/update-shared-guest-binary.js.map +1 -1
  199. package/dist/core/session/constants.d.ts.map +1 -1
  200. package/dist/core/session/context-metadata.d.ts.map +1 -1
  201. package/dist/core/session/context-metadata.js.map +1 -1
  202. package/dist/core/session/context.d.ts.map +1 -1
  203. package/dist/core/session/context.js.map +1 -1
  204. package/dist/core/session/ids.d.ts.map +1 -1
  205. package/dist/core/session/ids.js.map +1 -1
  206. package/dist/core/session/in-memory-session-manager.d.ts.map +1 -1
  207. package/dist/core/session/in-memory-session-manager.js +0 -1
  208. package/dist/core/session/in-memory-session-manager.js.map +1 -1
  209. package/dist/core/session/in-memory-session.d.ts.map +1 -1
  210. package/dist/core/session/in-memory-session.js.map +1 -1
  211. package/dist/core/session/jsonl-errors.d.ts.map +1 -1
  212. package/dist/core/session/jsonl-errors.js +0 -11
  213. package/dist/core/session/jsonl-errors.js.map +1 -1
  214. package/dist/core/session/jsonl-helpers.d.ts.map +1 -1
  215. package/dist/core/session/jsonl-helpers.js.map +1 -1
  216. package/dist/core/session/local-session-manager.d.ts.map +1 -1
  217. package/dist/core/session/local-session-manager.js +4 -6
  218. package/dist/core/session/local-session-manager.js.map +1 -1
  219. package/dist/core/session/local-session.d.ts.map +1 -1
  220. package/dist/core/session/local-session.js.map +1 -1
  221. package/dist/core/session/migrations.d.ts.map +1 -1
  222. package/dist/core/session/migrations.js.map +1 -1
  223. package/dist/core/session/remote-session-client.d.ts.map +1 -1
  224. package/dist/core/session/remote-session-client.js +0 -6
  225. package/dist/core/session/remote-session-client.js.map +1 -1
  226. package/dist/core/session/remote-session-manager.d.ts.map +1 -1
  227. package/dist/core/session/remote-session-manager.js +0 -3
  228. package/dist/core/session/remote-session-manager.js.map +1 -1
  229. package/dist/core/session/remote-session.d.ts.map +1 -1
  230. package/dist/core/session/remote-session.js +0 -1
  231. package/dist/core/session/remote-session.js.map +1 -1
  232. package/dist/core/session/session-manager.d.ts.map +1 -1
  233. package/dist/core/session/session.d.ts.map +1 -1
  234. package/dist/core/session/session.js +1 -5
  235. package/dist/core/session/session.js.map +1 -1
  236. package/dist/core/session/stores/in-memory-session-store.d.ts.map +1 -1
  237. package/dist/core/session/stores/in-memory-session-store.js +7 -6
  238. package/dist/core/session/stores/in-memory-session-store.js.map +1 -1
  239. package/dist/core/session/stores/jsonl-session-store.d.ts.map +1 -1
  240. package/dist/core/session/stores/jsonl-session-store.js +6 -14
  241. package/dist/core/session/stores/jsonl-session-store.js.map +1 -1
  242. package/dist/core/session/stores/remote-session-store.d.ts.map +1 -1
  243. package/dist/core/session/stores/remote-session-store.js +3 -8
  244. package/dist/core/session/stores/remote-session-store.js.map +1 -1
  245. package/dist/core/session/stores/session-store.d.ts.map +1 -1
  246. package/dist/core/session/types.d.ts.map +1 -1
  247. package/dist/core/session/usage-ledger.d.ts.map +1 -1
  248. package/dist/core/session/usage-ledger.js.map +1 -1
  249. package/dist/core/session-cwd.d.ts.map +1 -1
  250. package/dist/core/session-cwd.js +0 -1
  251. package/dist/core/session-cwd.js.map +1 -1
  252. package/dist/core/settings-manager.d.ts.map +1 -1
  253. package/dist/core/settings-manager.js +9 -17
  254. package/dist/core/settings-manager.js.map +1 -1
  255. package/dist/core/skills.d.ts.map +1 -1
  256. package/dist/core/skills.js +3 -2
  257. package/dist/core/skills.js.map +1 -1
  258. package/dist/core/slash-commands.d.ts.map +1 -1
  259. package/dist/core/source-info.d.ts.map +1 -1
  260. package/dist/core/source-info.js.map +1 -1
  261. package/dist/core/system-prompt.d.ts +1 -1
  262. package/dist/core/system-prompt.d.ts.map +1 -1
  263. package/dist/core/system-prompt.js +3 -2
  264. package/dist/core/system-prompt.js.map +1 -1
  265. package/dist/core/telemetry.d.ts.map +1 -1
  266. package/dist/core/telemetry.js.map +1 -1
  267. package/dist/core/timings.d.ts.map +1 -1
  268. package/dist/core/timings.js.map +1 -1
  269. package/dist/core/tools/bash.d.ts +1 -0
  270. package/dist/core/tools/bash.d.ts.map +1 -1
  271. package/dist/core/tools/bash.js +34 -28
  272. package/dist/core/tools/bash.js.map +1 -1
  273. package/dist/core/tools/compress-context.d.ts.map +1 -1
  274. package/dist/core/tools/compress-context.js.map +1 -1
  275. package/dist/core/tools/edit-diff.d.ts.map +1 -1
  276. package/dist/core/tools/edit-diff.js.map +1 -1
  277. package/dist/core/tools/edit.d.ts.map +1 -1
  278. package/dist/core/tools/edit.js.map +1 -1
  279. package/dist/core/tools/file-mutation-queue.d.ts.map +1 -1
  280. package/dist/core/tools/file-mutation-queue.js.map +1 -1
  281. package/dist/core/tools/find.d.ts.map +1 -1
  282. package/dist/core/tools/find.js.map +1 -1
  283. package/dist/core/tools/grep.d.ts.map +1 -1
  284. package/dist/core/tools/grep.js.map +1 -1
  285. package/dist/core/tools/hash-store.d.ts.map +1 -1
  286. package/dist/core/tools/hash-store.js.map +1 -1
  287. package/dist/core/tools/hashline/apply.d.ts.map +1 -1
  288. package/dist/core/tools/hashline/apply.js.map +1 -1
  289. package/dist/core/tools/hashline/hash.d.ts.map +1 -1
  290. package/dist/core/tools/hashline/hash.js.map +1 -1
  291. package/dist/core/tools/hashline/parse.d.ts.map +1 -1
  292. package/dist/core/tools/hashline/parse.js.map +1 -1
  293. package/dist/core/tools/hashline/resolve.d.ts.map +1 -1
  294. package/dist/core/tools/hashline/resolve.js.map +1 -1
  295. package/dist/core/tools/hashline-utils.d.ts.map +1 -1
  296. package/dist/core/tools/hashline-utils.js.map +1 -1
  297. package/dist/core/tools/index.d.ts.map +1 -1
  298. package/dist/core/tools/index.js.map +1 -1
  299. package/dist/core/tools/ls.d.ts.map +1 -1
  300. package/dist/core/tools/ls.js.map +1 -1
  301. package/dist/core/tools/operations.d.ts +11 -0
  302. package/dist/core/tools/operations.d.ts.map +1 -1
  303. package/dist/core/tools/operations.js +54 -28
  304. package/dist/core/tools/operations.js.map +1 -1
  305. package/dist/core/tools/output-accumulator.d.ts.map +1 -1
  306. package/dist/core/tools/output-accumulator.js +12 -18
  307. package/dist/core/tools/output-accumulator.js.map +1 -1
  308. package/dist/core/tools/path-utils.d.ts.map +1 -1
  309. package/dist/core/tools/path-utils.js.map +1 -1
  310. package/dist/core/tools/read.d.ts.map +1 -1
  311. package/dist/core/tools/read.js.map +1 -1
  312. package/dist/core/tools/render-utils.d.ts.map +1 -1
  313. package/dist/core/tools/render-utils.js.map +1 -1
  314. package/dist/core/tools/replace-diff.d.ts.map +1 -1
  315. package/dist/core/tools/replace-diff.js.map +1 -1
  316. package/dist/core/tools/replace-normalize.d.ts.map +1 -1
  317. package/dist/core/tools/replace-normalize.js.map +1 -1
  318. package/dist/core/tools/replace-render.d.ts +1 -1
  319. package/dist/core/tools/replace-render.d.ts.map +1 -1
  320. package/dist/core/tools/replace-render.js.map +1 -1
  321. package/dist/core/tools/runtime.d.ts.map +1 -1
  322. package/dist/core/tools/runtime.js.map +1 -1
  323. package/dist/core/tools/session-history.d.ts.map +1 -1
  324. package/dist/core/tools/session-history.js.map +1 -1
  325. package/dist/core/tools/subagent-agents.d.ts.map +1 -1
  326. package/dist/core/tools/subagent-agents.js.map +1 -1
  327. package/dist/core/tools/subagent.d.ts.map +1 -1
  328. package/dist/core/tools/subagent.js.map +1 -1
  329. package/dist/core/tools/tool-definition-wrapper.d.ts.map +1 -1
  330. package/dist/core/tools/tool-definition-wrapper.js.map +1 -1
  331. package/dist/core/tools/truncate.d.ts.map +1 -1
  332. package/dist/core/tools/truncate.js.map +1 -1
  333. package/dist/core/tools/websearch.d.ts.map +1 -1
  334. package/dist/core/tools/websearch.js.map +1 -1
  335. package/dist/core/tools/workspace-tool-host.d.ts +1 -0
  336. package/dist/core/tools/workspace-tool-host.d.ts.map +1 -1
  337. package/dist/core/tools/workspace-tool-host.js +36 -22
  338. package/dist/core/tools/workspace-tool-host.js.map +1 -1
  339. package/dist/core/tools/write.d.ts.map +1 -1
  340. package/dist/core/tools/write.js +0 -1
  341. package/dist/core/tools/write.js.map +1 -1
  342. package/dist/core/workspace-identity.d.ts.map +1 -1
  343. package/dist/daemon/activity-budget.d.ts.map +1 -1
  344. package/dist/daemon/activity-budget.js +2 -3
  345. package/dist/daemon/activity-budget.js.map +1 -1
  346. package/dist/daemon/command.d.ts.map +1 -1
  347. package/dist/daemon/command.js.map +1 -1
  348. package/dist/daemon/config.d.ts +2 -0
  349. package/dist/daemon/config.d.ts.map +1 -1
  350. package/dist/daemon/config.js +4 -0
  351. package/dist/daemon/config.js.map +1 -1
  352. package/dist/daemon/help.d.ts.map +1 -1
  353. package/dist/daemon/help.js +4 -3
  354. package/dist/daemon/help.js.map +1 -1
  355. package/dist/daemon/lsp-config.d.ts.map +1 -1
  356. package/dist/daemon/lsp-config.js.map +1 -1
  357. package/dist/daemon/outbound-budget.d.ts.map +1 -1
  358. package/dist/daemon/outbound-budget.js +2 -4
  359. package/dist/daemon/outbound-budget.js.map +1 -1
  360. package/dist/daemon/security.d.ts.map +1 -1
  361. package/dist/daemon/security.js.map +1 -1
  362. package/dist/daemon/server.d.ts.map +1 -1
  363. package/dist/daemon/server.js.map +1 -1
  364. package/dist/daemon/shared-connection.d.ts.map +1 -1
  365. package/dist/daemon/shared-connection.js +10 -15
  366. package/dist/daemon/shared-connection.js.map +1 -1
  367. package/dist/daemon/shared-revision.d.ts.map +1 -1
  368. package/dist/daemon/shared-revision.js +2 -1
  369. package/dist/daemon/shared-revision.js.map +1 -1
  370. package/dist/daemon/shared-roots.d.ts.map +1 -1
  371. package/dist/daemon/shared-roots.js +0 -1
  372. package/dist/daemon/shared-roots.js.map +1 -1
  373. package/dist/daemon/workspace-runtime.d.ts +2 -0
  374. package/dist/daemon/workspace-runtime.d.ts.map +1 -1
  375. package/dist/daemon/workspace-runtime.js +43 -15
  376. package/dist/daemon/workspace-runtime.js.map +1 -1
  377. package/dist/index.d.ts +1 -1
  378. package/dist/index.d.ts.map +1 -1
  379. package/dist/index.js.map +1 -1
  380. package/dist/main.d.ts.map +1 -1
  381. package/dist/main.js +8 -3
  382. package/dist/main.js.map +1 -1
  383. package/dist/migrations.d.ts.map +1 -1
  384. package/dist/migrations.js.map +1 -1
  385. package/dist/modes/interactive/components/assistant-message.d.ts.map +1 -1
  386. package/dist/modes/interactive/components/assistant-message.js +3 -10
  387. package/dist/modes/interactive/components/assistant-message.js.map +1 -1
  388. package/dist/modes/interactive/components/bash-execution.d.ts.map +1 -1
  389. package/dist/modes/interactive/components/bash-execution.js +4 -9
  390. package/dist/modes/interactive/components/bash-execution.js.map +1 -1
  391. package/dist/modes/interactive/components/bordered-loader.d.ts.map +1 -1
  392. package/dist/modes/interactive/components/bordered-loader.js +0 -3
  393. package/dist/modes/interactive/components/bordered-loader.js.map +1 -1
  394. package/dist/modes/interactive/components/branch-summary-message.d.ts.map +1 -1
  395. package/dist/modes/interactive/components/branch-summary-message.js +1 -3
  396. package/dist/modes/interactive/components/branch-summary-message.js.map +1 -1
  397. package/dist/modes/interactive/components/compaction-summary-message.d.ts.map +1 -1
  398. package/dist/modes/interactive/components/compaction-summary-message.js +1 -3
  399. package/dist/modes/interactive/components/compaction-summary-message.js.map +1 -1
  400. package/dist/modes/interactive/components/config-selector.d.ts.map +1 -1
  401. package/dist/modes/interactive/components/config-selector.js +6 -16
  402. package/dist/modes/interactive/components/config-selector.js.map +1 -1
  403. package/dist/modes/interactive/components/countdown-timer.d.ts.map +1 -1
  404. package/dist/modes/interactive/components/countdown-timer.js +0 -5
  405. package/dist/modes/interactive/components/countdown-timer.js.map +1 -1
  406. package/dist/modes/interactive/components/custom-editor.d.ts.map +1 -1
  407. package/dist/modes/interactive/components/custom-editor.js +1 -8
  408. package/dist/modes/interactive/components/custom-editor.js.map +1 -1
  409. package/dist/modes/interactive/components/custom-message.d.ts.map +1 -1
  410. package/dist/modes/interactive/components/custom-message.js +1 -6
  411. package/dist/modes/interactive/components/custom-message.js.map +1 -1
  412. package/dist/modes/interactive/components/diff.d.ts.map +1 -1
  413. package/dist/modes/interactive/components/diff.js.map +1 -1
  414. package/dist/modes/interactive/components/dynamic-border.d.ts.map +1 -1
  415. package/dist/modes/interactive/components/dynamic-border.js +0 -1
  416. package/dist/modes/interactive/components/dynamic-border.js.map +1 -1
  417. package/dist/modes/interactive/components/extension-editor.d.ts.map +1 -1
  418. package/dist/modes/interactive/components/extension-editor.js +1 -7
  419. package/dist/modes/interactive/components/extension-editor.js.map +1 -1
  420. package/dist/modes/interactive/components/extension-input.d.ts.map +1 -1
  421. package/dist/modes/interactive/components/extension-input.js +2 -8
  422. package/dist/modes/interactive/components/extension-input.js.map +1 -1
  423. package/dist/modes/interactive/components/extension-selector.d.ts.map +1 -1
  424. package/dist/modes/interactive/components/extension-selector.js +1 -9
  425. package/dist/modes/interactive/components/extension-selector.js.map +1 -1
  426. package/dist/modes/interactive/components/footer.d.ts.map +1 -1
  427. package/dist/modes/interactive/components/footer.js +8 -4
  428. package/dist/modes/interactive/components/footer.js.map +1 -1
  429. package/dist/modes/interactive/components/hook-execution.d.ts.map +1 -1
  430. package/dist/modes/interactive/components/hook-execution.js +2 -5
  431. package/dist/modes/interactive/components/hook-execution.js.map +1 -1
  432. package/dist/modes/interactive/components/keybinding-hints.d.ts.map +1 -1
  433. package/dist/modes/interactive/components/keybinding-hints.js.map +1 -1
  434. package/dist/modes/interactive/components/login-dialog.d.ts.map +1 -1
  435. package/dist/modes/interactive/components/login-dialog.js +3 -9
  436. package/dist/modes/interactive/components/login-dialog.js.map +1 -1
  437. package/dist/modes/interactive/components/markdown-transform.d.ts.map +1 -1
  438. package/dist/modes/interactive/components/markdown-transform.js.map +1 -1
  439. package/dist/modes/interactive/components/mermaid.d.ts.map +1 -1
  440. package/dist/modes/interactive/components/mermaid.js.map +1 -1
  441. package/dist/modes/interactive/components/message-card.d.ts.map +1 -1
  442. package/dist/modes/interactive/components/message-card.js +0 -1
  443. package/dist/modes/interactive/components/message-card.js.map +1 -1
  444. package/dist/modes/interactive/components/model-selector.d.ts.map +1 -1
  445. package/dist/modes/interactive/components/model-selector.js +13 -28
  446. package/dist/modes/interactive/components/model-selector.js.map +1 -1
  447. package/dist/modes/interactive/components/oauth-selector.d.ts.map +1 -1
  448. package/dist/modes/interactive/components/oauth-selector.js +3 -12
  449. package/dist/modes/interactive/components/oauth-selector.js.map +1 -1
  450. package/dist/modes/interactive/components/scoped-models-selector.d.ts.map +1 -1
  451. package/dist/modes/interactive/components/scoped-models-selector.js +9 -13
  452. package/dist/modes/interactive/components/scoped-models-selector.js.map +1 -1
  453. package/dist/modes/interactive/components/session-selector-search.d.ts.map +1 -1
  454. package/dist/modes/interactive/components/session-selector-search.js.map +1 -1
  455. package/dist/modes/interactive/components/session-selector.d.ts.map +1 -1
  456. package/dist/modes/interactive/components/session-selector.js +33 -58
  457. package/dist/modes/interactive/components/session-selector.js.map +1 -1
  458. package/dist/modes/interactive/components/settings-selector.d.ts.map +1 -1
  459. package/dist/modes/interactive/components/settings-selector.js +0 -4
  460. package/dist/modes/interactive/components/settings-selector.js.map +1 -1
  461. package/dist/modes/interactive/components/show-images-selector.d.ts.map +1 -1
  462. package/dist/modes/interactive/components/show-images-selector.js +0 -1
  463. package/dist/modes/interactive/components/show-images-selector.js.map +1 -1
  464. package/dist/modes/interactive/components/skill-invocation-message.d.ts.map +1 -1
  465. package/dist/modes/interactive/components/skill-invocation-message.js +1 -3
  466. package/dist/modes/interactive/components/skill-invocation-message.js.map +1 -1
  467. package/dist/modes/interactive/components/theme-selector.d.ts.map +1 -1
  468. package/dist/modes/interactive/components/theme-selector.js +0 -2
  469. package/dist/modes/interactive/components/theme-selector.js.map +1 -1
  470. package/dist/modes/interactive/components/thinking-selector.d.ts.map +1 -1
  471. package/dist/modes/interactive/components/thinking-selector.js +0 -1
  472. package/dist/modes/interactive/components/thinking-selector.js.map +1 -1
  473. package/dist/modes/interactive/components/tool-execution.d.ts.map +1 -1
  474. package/dist/modes/interactive/components/tool-execution.js +9 -24
  475. package/dist/modes/interactive/components/tool-execution.js.map +1 -1
  476. package/dist/modes/interactive/components/tree-selector.d.ts.map +1 -1
  477. package/dist/modes/interactive/components/tree-selector.js +18 -34
  478. package/dist/modes/interactive/components/tree-selector.js.map +1 -1
  479. package/dist/modes/interactive/components/user-message-selector.d.ts.map +1 -1
  480. package/dist/modes/interactive/components/user-message-selector.js +3 -6
  481. package/dist/modes/interactive/components/user-message-selector.js.map +1 -1
  482. package/dist/modes/interactive/components/user-message.d.ts.map +1 -1
  483. package/dist/modes/interactive/components/user-message.js +0 -4
  484. package/dist/modes/interactive/components/user-message.js.map +1 -1
  485. package/dist/modes/interactive/components/visual-truncate.d.ts.map +1 -1
  486. package/dist/modes/interactive/components/visual-truncate.js.map +1 -1
  487. package/dist/modes/interactive/interactive-mode.d.ts +13 -0
  488. package/dist/modes/interactive/interactive-mode.d.ts.map +1 -1
  489. package/dist/modes/interactive/interactive-mode.js +162 -136
  490. package/dist/modes/interactive/interactive-mode.js.map +1 -1
  491. package/dist/modes/interactive/theme/theme.d.ts.map +1 -1
  492. package/dist/modes/interactive/theme/theme.js +0 -7
  493. package/dist/modes/interactive/theme/theme.js.map +1 -1
  494. package/dist/modes/json-event.d.ts.map +1 -1
  495. package/dist/modes/json-event.js.map +1 -1
  496. package/dist/modes/print-mode.d.ts.map +1 -1
  497. package/dist/modes/print-mode.js.map +1 -1
  498. package/dist/modes/rpc/jsonl.d.ts.map +1 -1
  499. package/dist/modes/rpc/jsonl.js.map +1 -1
  500. package/dist/modes/rpc/rpc-client.d.ts.map +1 -1
  501. package/dist/modes/rpc/rpc-client.js +10 -11
  502. package/dist/modes/rpc/rpc-client.js.map +1 -1
  503. package/dist/modes/rpc/rpc-mode.d.ts.map +1 -1
  504. package/dist/modes/rpc/rpc-mode.js.map +1 -1
  505. package/dist/modes/rpc/rpc-types.d.ts.map +1 -1
  506. package/dist/package-manager-cli.d.ts.map +1 -1
  507. package/dist/package-manager-cli.js +33 -2
  508. package/dist/package-manager-cli.js.map +1 -1
  509. package/dist/utils/ansi.d.ts.map +1 -1
  510. package/dist/utils/ansi.js.map +1 -1
  511. package/dist/utils/binary-self-update.d.ts +25 -0
  512. package/dist/utils/binary-self-update.d.ts.map +1 -0
  513. package/dist/utils/binary-self-update.js +159 -0
  514. package/dist/utils/binary-self-update.js.map +1 -0
  515. package/dist/utils/changelog.d.ts.map +1 -1
  516. package/dist/utils/changelog.js.map +1 -1
  517. package/dist/utils/child-process.d.ts.map +1 -1
  518. package/dist/utils/child-process.js.map +1 -1
  519. package/dist/utils/clipboard-image.d.ts.map +1 -1
  520. package/dist/utils/clipboard-image.js.map +1 -1
  521. package/dist/utils/clipboard-native.d.ts.map +1 -1
  522. package/dist/utils/clipboard-native.js.map +1 -1
  523. package/dist/utils/clipboard.d.ts.map +1 -1
  524. package/dist/utils/clipboard.js.map +1 -1
  525. package/dist/utils/deprecation.d.ts.map +1 -1
  526. package/dist/utils/deprecation.js.map +1 -1
  527. package/dist/utils/directory-completions.d.ts +8 -0
  528. package/dist/utils/directory-completions.d.ts.map +1 -1
  529. package/dist/utils/directory-completions.js +42 -1
  530. package/dist/utils/directory-completions.js.map +1 -1
  531. package/dist/utils/exif-orientation.d.ts.map +1 -1
  532. package/dist/utils/exif-orientation.js.map +1 -1
  533. package/dist/utils/frontmatter.d.ts.map +1 -1
  534. package/dist/utils/frontmatter.js.map +1 -1
  535. package/dist/utils/fs-watch.d.ts.map +1 -1
  536. package/dist/utils/fs-watch.js.map +1 -1
  537. package/dist/utils/git.d.ts.map +1 -1
  538. package/dist/utils/git.js.map +1 -1
  539. package/dist/utils/grip-user-agent.d.ts.map +1 -1
  540. package/dist/utils/grip-user-agent.js.map +1 -1
  541. package/dist/utils/html.d.ts.map +1 -1
  542. package/dist/utils/html.js.map +1 -1
  543. package/dist/utils/image-convert.d.ts.map +1 -1
  544. package/dist/utils/image-convert.js.map +1 -1
  545. package/dist/utils/image-process.d.ts.map +1 -1
  546. package/dist/utils/image-process.js.map +1 -1
  547. package/dist/utils/image-resize-core.d.ts.map +1 -1
  548. package/dist/utils/image-resize-core.js.map +1 -1
  549. package/dist/utils/image-resize-worker.d.ts.map +1 -1
  550. package/dist/utils/image-resize-worker.js.map +1 -1
  551. package/dist/utils/image-resize.d.ts.map +1 -1
  552. package/dist/utils/image-resize.js.map +1 -1
  553. package/dist/utils/json.d.ts.map +1 -1
  554. package/dist/utils/json.js.map +1 -1
  555. package/dist/utils/mime.d.ts.map +1 -1
  556. package/dist/utils/mime.js.map +1 -1
  557. package/dist/utils/open-browser.d.ts.map +1 -1
  558. package/dist/utils/open-browser.js.map +1 -1
  559. package/dist/utils/paths.d.ts.map +1 -1
  560. package/dist/utils/paths.js.map +1 -1
  561. package/dist/utils/photon.d.ts.map +1 -1
  562. package/dist/utils/photon.js +10 -5
  563. package/dist/utils/photon.js.map +1 -1
  564. package/dist/utils/shell.d.ts.map +1 -1
  565. package/dist/utils/shell.js.map +1 -1
  566. package/dist/utils/sleep.d.ts.map +1 -1
  567. package/dist/utils/sleep.js.map +1 -1
  568. package/dist/utils/syntax-highlight.d.ts.map +1 -1
  569. package/dist/utils/syntax-highlight.js +1 -1
  570. package/dist/utils/syntax-highlight.js.map +1 -1
  571. package/dist/utils/tools-manager.d.ts.map +1 -1
  572. package/dist/utils/tools-manager.js.map +1 -1
  573. package/dist/utils/version-check.d.ts.map +1 -1
  574. package/dist/utils/version-check.js.map +1 -1
  575. package/dist/utils/windows-self-update.d.ts.map +1 -1
  576. package/dist/utils/windows-self-update.js.map +1 -1
  577. package/docs/extensions.md +31 -1
  578. package/docs/sandbox.md +6 -0
  579. package/docs/sessions.md +1 -1
  580. package/docs/skills.md +4 -4
  581. package/docs/usage.md +2 -1
  582. package/examples/extensions/custom-provider-anthropic/package.json +2 -2
  583. package/examples/extensions/custom-provider-gitlab-duo/package.json +1 -1
  584. package/examples/extensions/sandbox/package.json +2 -2
  585. package/examples/extensions/with-deps/package.json +1 -1
  586. package/npm-shrinkwrap.json +602 -834
  587. package/package.json +20 -21
@@ -1 +1 @@
1
- {"version":3,"file":"remote-session-client.js","sourceRoot":"","sources":["../../../src/core/session/remote-session-client.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,UAAU,CAAC;AAuE7C,MAAM,OAAO,wBAAyB,SAAQ,KAAK;IACzC,MAAM,CAAS;IACf,YAAY,CAAS;IAE9B,YAAY,MAAc,EAAE,YAAoB,EAAE;QACjD,KAAK,CAAC,6CAA6C,MAAM,KAAK,YAAY,EAAE,CAAC,CAAC;QAC9E,IAAI,CAAC,IAAI,GAAG,0BAA0B,CAAC;QACvC,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;QACrB,IAAI,CAAC,YAAY,GAAG,YAAY,CAAC;IAAA,CACjC;CACD;AAED,MAAM,OAAO,0BAA2B,SAAQ,KAAK;IAC3C,SAAS,CAAyB;IAE3C,YAAY,SAAiC,EAAE,OAAe,EAAE,KAAe,EAAE;QAChF,KAAK,CAAC,0BAA0B,SAAS,cAAc,OAAO,EAAE,EAAE,EAAE,KAAK,EAAE,CAAC,CAAC;QAC7E,IAAI,CAAC,I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G,EAAE,CAAC;YAC7B,MAAM,IAAI,0BAA0B,CAAC,SAAS,EAAE,2BAA2B,CAAC,CAAC;QAC9E,CAAC;QAED,IAAI,KAAc,CAAC;QACnB,IAAI,CAAC;YACJ,KAAK,GAAG,MAAM,QAAQ,CAAC,IAAI,EAAE,CAAC;QAC/B,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YAChB,MAAM,IAAI,0BAA0B,CAAC,SAAS,EAAE,wBAAwB,EAAE,KAAK,CAAC,CAAC;QAClF,CAAC;QACD,OAAO,MAAM,CAAC,KAAK,CAAC,CAAC;IAAA,CACrB;CACD;AAED,MAAM,UAAU,oBAAoB,CAAC,SAAiB,EAAU;IAC/D,OAAO,SAAS,CAAC,UAAU,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC,KAAK,CAAC,SAAS,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC;AAAA,CACvF;AAED,MAAM,UAAU,4BAA4B,CAAC,SAAiB,EAAU;IACvE,OAAO,SAAS,CAAC,UAAU,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,UAAU,SAAS,EAAE,CAAC;AAAA,CAC3E","sourcesContent":["import { validateSessionId } from \"./ids.ts\";\nimport type { FileEntry, SessionInfo } from \"./types.ts\";\n\nexport type RemoteSessionInfo = Omit<SessionInfo, \"path\" | \"created\" | \"modified\"> & {\n\tpath?: string;\n\tcreated: Date | string;\n\tmodified: Date | string;\n};\n\nexport interface RemoteSessionClientOptions {\n\tbaseUrl: string;\n\ttoken: string;\n\tfetch?: typeof fetch;\n}\n\nexport interface RemoteSessionSnapshot {\n\treference: string;\n\tid: string;\n\tversion?: number;\n\tentries: FileEntry[];\n\tetag?: string;\n}\n\nexport interface CreateRemoteSessionRequest {\n\tid?: string;\n\tcwd: string;\n\tprojectId?: string;\n\tparentSession?: string;\n\tmetadata?: Record<string, unknown>;\n}\n\nexport interface AppendRemoteSessionEntriesRequest {\n\tbaseEtag?: string;\n\tentries: FileEntry[];\n}\n\nexport interface AppendRemoteSessionEntriesResponse {\n\tetag?: string;\n\taccepted: number;\n}\n\n// grip-ignore noNearIdenticalDataStructures: Snapshot replacement atomically rewrites complete state, while append applies incremental entries; their endpoint validation and concurrency contracts evolve independently.\nexport interface ReplaceRemoteSessionSnapshotRequest {\n\tbaseEtag?: string;\n\tentries: FileEntry[];\n}\n\nexport interface ReplaceRemoteSessionSnapshotResponse {\n\tetag?: string;\n}\n\nexport interface ForkRemoteSessionRequest {\n\tcwd: string;\n\tprojectId?: string;\n\tleafId?: string;\n}\n\nexport interface ImportRemoteSessionJsonlRequest {\n\tcwd: string;\n\tprojectId?: string;\n\tsourceName?: string;\n\tentries: FileEntry[];\n\tmetadata?: Record<string, unknown>;\n}\n\nexport interface ListRemoteSessionsResponse {\n\tsessions: RemoteSessionInfo[];\n}\n\nexport type RemoteSessionOperation = \"create\" | \"open\" | \"recent\" | \"fork\" | \"import\" | \"list\" | \"append\" | \"replace\";\n\nexport class RemoteSessionClientError extends Error {\n\treadonly status: number;\n\treadonly responseText: string;\n\n\tconstructor(status: number, responseText: string) {\n\t\tsuper(`Remote session request failed with status ${status}: ${responseText}`);\n\t\tthis.name = \"RemoteSessionClientError\";\n\t\tthis.status = status;\n\t\tthis.responseText = responseText;\n\t}\n}\n\nexport class RemoteSessionProtocolError extends Error {\n\treadonly operation: RemoteSessionOperation;\n\n\tconstructor(operation: RemoteSessionOperation, message: string, cause?: unknown) {\n\t\tsuper(`Invalid remote session ${operation} response: ${message}`, { cause });\n\t\tthis.name = \"RemoteSessionProtocolError\";\n\t\tthis.operation = operation;\n\t}\n}\n\nfunction isRecord(value: unknown): value is Record<string, unknown> {\n\treturn typeof value === \"object\" && value !== null && !Array.isArray(value);\n}\n\nfunction requiredString(record: Record<string, unknown>, key: string, operation: RemoteSessionOperation): string {\n\tconst value = record[key];\n\tif (typeof value !== \"string\" || value.length === 0) {\n\t\tthrow new RemoteSessionProtocolError(operation, `${key} must be a non-empty string`);\n\t}\n\treturn value;\n}\n\nfunction stringValue(record: Record<string, unknown>, key: string, operation: RemoteSessionOperation): string {\n\tconst value = record[key];\n\tif (typeof value !== \"string\") {\n\t\tthrow new RemoteSessionProtocolError(operation, `${key} must be a string`);\n\t}\n\treturn value;\n}\n\nfunction requiredSessionId(record: Record<string, unknown>, operation: RemoteSessionOperation): string {\n\tconst id = requiredString(record, \"id\", operation);\n\ttry {\n\t\tvalidateSessionId(id);\n\t} catch (error) {\n\t\tthrow new RemoteSessionProtocolError(operation, \"id is not a valid session id\", error);\n\t}\n\treturn id;\n}\n\nfunction optionalString(\n\trecord: Record<string, unknown>,\n\tkey: string,\n\toperation: RemoteSessionOperation,\n): string | undefined {\n\tconst value = record[key];\n\tif (value === undefined) return undefined;\n\tif (typeof value !== \"string\" || value.length === 0) {\n\t\tthrow new RemoteSessionProtocolError(operation, `${key} must be a non-empty string when present`);\n\t}\n\treturn value;\n}\n\nfunction decodeSnapshot(value: unknown, operation: RemoteSessionOperation, expectedId?: string): RemoteSessionSnapshot {\n\tif (!isRecord(value)) throw new RemoteSessionProtocolError(operation, \"snapshot must be an object\");\n\tconst id = requiredSessionId(value, operation);\n\tconst reference = requiredString(value, \"reference\", operation);\n\tif (parseRemoteSessionId(reference) !== id) {\n\t\tthrow new RemoteSessionProtocolError(operation, `reference ${reference} does not identify snapshot id ${id}`);\n\t}\n\tif (expectedId !== undefined && id !== expectedId) {\n\t\tthrow new RemoteSessionProtocolError(operation, `snapshot id ${id} does not match requested id ${expectedId}`);\n\t}\n\tif (!Array.isArray(value.entries) || value.entries.length === 0 || value.entries.some((entry) => !isRecord(entry))) {\n\t\tthrow new RemoteSessionProtocolError(operation, \"entries must be a non-empty array of objects\");\n\t}\n\tconst header = value.entries[0];\n\tif (\n\t\t!isRecord(header) ||\n\t\theader.type !== \"session\" ||\n\t\theader.id !== id ||\n\t\ttypeof header.cwd !== \"string\" ||\n\t\ttypeof header.timestamp !== \"string\"\n\t) {\n\t\tthrow new RemoteSessionProtocolError(operation, \"entries must begin with a matching session header\");\n\t}\n\tconst version = value.version;\n\tif (\n\t\tversion !== undefined &&\n\t\t(typeof version !== \"number\" || !Number.isInteger(version) || version < 1 || version !== header.version)\n\t) {\n\t\tthrow new RemoteSessionProtocolError(operation, \"version must be a positive integer matching the session header\");\n\t}\n\treturn {\n\t\treference,\n\t\tid,\n\t\tversion: version as number | undefined,\n\t\tentries: value.entries as FileEntry[],\n\t\tetag: optionalString(value, \"etag\", operation),\n\t};\n}\n\nfunction decodeForkSnapshot(value: unknown, sourceId: string): RemoteSessionSnapshot {\n\tconst snapshot = decodeSnapshot(value, \"fork\");\n\tif (snapshot.id === sourceId) {\n\t\tthrow new RemoteSessionProtocolError(\"fork\", \"fork snapshot must have a new session id\");\n\t}\n\tconst header = snapshot.entries[0];\n\tif (header?.type !== \"session\" || !header.parentSession || parseRemoteSessionId(header.parentSession) !== sourceId) {\n\t\tthrow new RemoteSessionProtocolError(\"fork\", `fork header must reference source session ${sourceId}`);\n\t}\n\treturn snapshot;\n}\n\nfunction decodeAppendResponse(value: unknown): AppendRemoteSessionEntriesResponse {\n\tconst operation = \"append\";\n\tif (!isRecord(value)) throw new RemoteSessionProtocolError(operation, \"response must be an object\");\n\tif (!Number.isInteger(value.accepted)) {\n\t\tthrow new RemoteSessionProtocolError(operation, \"accepted must be an integer\");\n\t}\n\treturn { accepted: value.accepted as number, etag: optionalString(value, \"etag\", operation) };\n}\n\nfunction decodeReplaceResponse(value: unknown): ReplaceRemoteSessionSnapshotResponse {\n\tconst operation = \"replace\";\n\tif (!isRecord(value)) throw new RemoteSessionProtocolError(operation, \"response must be an object\");\n\treturn { etag: optionalString(value, \"etag\", operation) };\n}\n\nfunction decodeSessionInfo(value: unknown): RemoteSessionInfo {\n\tconst operation = \"list\";\n\tif (!isRecord(value)) throw new RemoteSessionProtocolError(operation, \"each session must be an object\");\n\tconst id = requiredSessionId(value, operation);\n\tconst reference = optionalString(value, \"reference\", operation);\n\tconst path = optionalString(value, \"path\", operation);\n\tfor (const candidate of [reference, path]) {\n\t\tif (candidate !== undefined && parseRemoteSessionId(candidate) !== id) {\n\t\t\tthrow new RemoteSessionProtocolError(operation, `reference ${candidate} does not identify session id ${id}`);\n\t\t}\n\t}\n\tconst created = requiredString(value, \"created\", operation);\n\tconst modified = requiredString(value, \"modified\", operation);\n\tif (!Number.isFinite(Date.parse(created)) || !Number.isFinite(Date.parse(modified))) {\n\t\tthrow new RemoteSessionProtocolError(operation, \"created and modified must be valid date strings\");\n\t}\n\tif (!Number.isInteger(value.messageCount) || (value.messageCount as number) < 0) {\n\t\tthrow new RemoteSessionProtocolError(operation, \"messageCount must be a non-negative integer\");\n\t}\n\treturn {\n\t\treference,\n\t\tpath,\n\t\tid,\n\t\tcwd: stringValue(value, \"cwd\", operation),\n\t\tname: optionalString(value, \"name\", operation),\n\t\tparentSessionPath: optionalString(value, \"parentSessionPath\", operation),\n\t\tcreated,\n\t\tmodified,\n\t\tmessageCount: value.messageCount as number,\n\t\tfirstMessage: stringValue(value, \"firstMessage\", operation),\n\t\tallMessagesText: stringValue(value, \"allMessagesText\", operation),\n\t};\n}\n\nfunction decodeListResponse(value: unknown): ListRemoteSessionsResponse {\n\tif (!isRecord(value) || !Array.isArray(value.sessions)) {\n\t\tthrow new RemoteSessionProtocolError(\"list\", \"sessions must be an array\");\n\t}\n\treturn { sessions: value.sessions.map((session) => decodeSessionInfo(session)) };\n}\n\nexport class RemoteSessionClient {\n\tprivate readonly baseUrl: string;\n\tprivate readonly token: string;\n\tprivate readonly fetchImpl: typeof fetch;\n\n\tconstructor(options: RemoteSessionClientOptions) {\n\t\tthis.baseUrl = options.baseUrl.replace(/\\/+$/, \"\");\n\t\tthis.token = options.token;\n\t\tthis.fetchImpl = options.fetch ?? fetch;\n\t}\n\n\tcreateSession(request: CreateRemoteSessionRequest): Promise<RemoteSessionSnapshot> {\n\t\treturn this.request(\"POST\", \"/v1/sessions\", request, \"create\", (value) =>\n\t\t\tdecodeSnapshot(value, \"create\", request.id),\n\t\t);\n\t}\n\n\topenSession(sessionIdOrReference: string): Promise<RemoteSessionSnapshot> {\n\t\tconst id = parseRemoteSessionId(sessionIdOrReference);\n\t\treturn this.request(\"GET\", `/v1/sessions/${encodeURIComponent(id)}`, undefined, \"open\", (value) =>\n\t\t\tdecodeSnapshot(value, \"open\", id),\n\t\t);\n\t}\n\n\tappendEntries(\n\t\tsessionIdOrReference: string,\n\t\trequest: AppendRemoteSessionEntriesRequest,\n\t): Promise<AppendRemoteSessionEntriesResponse> {\n\t\treturn this.request(\n\t\t\t\"POST\",\n\t\t\t`/v1/sessions/${encodeURIComponent(parseRemoteSessionId(sessionIdOrReference))}/entries`,\n\t\t\trequest,\n\t\t\t\"append\",\n\t\t\tdecodeAppendResponse,\n\t\t);\n\t}\n\n\treplaceSnapshot(\n\t\tsessionIdOrReference: string,\n\t\trequest: ReplaceRemoteSessionSnapshotRequest,\n\t): Promise<ReplaceRemoteSessionSnapshotResponse> {\n\t\treturn this.request(\n\t\t\t\"PUT\",\n\t\t\t`/v1/sessions/${encodeURIComponent(parseRemoteSessionId(sessionIdOrReference))}/snapshot`,\n\t\t\trequest,\n\t\t\t\"replace\",\n\t\t\tdecodeReplaceResponse,\n\t\t);\n\t}\n\n\tlistSessions(): Promise<ListRemoteSessionsResponse> {\n\t\treturn this.request(\"GET\", \"/v1/sessions\", undefined, \"list\", decodeListResponse);\n\t}\n\n\tgetRecentSession(): Promise<RemoteSessionSnapshot> {\n\t\treturn this.request(\"GET\", \"/v1/sessions/recent\", undefined, \"recent\", (value) =>\n\t\t\tdecodeSnapshot(value, \"recent\"),\n\t\t);\n\t}\n\n\tforkSession(sessionIdOrReference: string, request: ForkRemoteSessionRequest): Promise<RemoteSessionSnapshot> {\n\t\tconst sourceId = parseRemoteSessionId(sessionIdOrReference);\n\t\treturn this.request(\"POST\", `/v1/sessions/${encodeURIComponent(sourceId)}/fork`, request, \"fork\", (value) =>\n\t\t\tdecodeForkSnapshot(value, sourceId),\n\t\t);\n\t}\n\n\timportJsonl(request: ImportRemoteSessionJsonlRequest): Promise<RemoteSessionSnapshot> {\n\t\treturn this.request(\"POST\", \"/v1/sessions/import-jsonl\", request, \"import\", (value) =>\n\t\t\tdecodeSnapshot(value, \"import\"),\n\t\t);\n\t}\n\n\tprivate async request<T>(\n\t\tmethod: string,\n\t\tpath: string,\n\t\tbody: unknown,\n\t\toperation: RemoteSessionOperation,\n\t\tdecode: (value: unknown) => T,\n\t): Promise<T> {\n\t\tconst response = await this.fetchImpl(`${this.baseUrl}${path}`, {\n\t\t\tmethod,\n\t\t\theaders: {\n\t\t\t\tAuthorization: `Bearer ${this.token}`,\n\t\t\t\tAccept: \"application/json\",\n\t\t\t\t...(body === undefined ? {} : { \"Content-Type\": \"application/json\" }),\n\t\t\t},\n\t\t\tbody: body === undefined ? undefined : JSON.stringify(body),\n\t\t});\n\n\t\tif (!response.ok) {\n\t\t\tthrow new RemoteSessionClientError(response.status, await response.text());\n\t\t}\n\t\tif (response.status === 204) {\n\t\t\tthrow new RemoteSessionProtocolError(operation, \"response body is required\");\n\t\t}\n\n\t\tlet value: unknown;\n\t\ttry {\n\t\t\tvalue = await response.json();\n\t\t} catch (error) {\n\t\t\tthrow new RemoteSessionProtocolError(operation, \"body is not valid JSON\", error);\n\t\t}\n\t\treturn decode(value);\n\t}\n}\n\nexport function parseRemoteSessionId(reference: string): string {\n\treturn reference.startsWith(\"remote:\") ? reference.slice(\"remote:\".length) : reference;\n}\n\nexport function formatRemoteSessionReference(sessionId: string): string {\n\treturn sessionId.startsWith(\"remote:\") ? sessionId : `remote:${sessionId}`;\n}\n"]}
1
+ {"version":3,"file":"remote-session-client.js","sourceRoot":"","sources":["../../../src/core/session/remote-session-client.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,UAAU,CAAC;AAuE7C,MAAM,OAAO,wBAAyB,SAAQ,KAAK;IAIlD,YAAY,MAAc,EAAE,YAA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SAC3D,CAAC,CAAC;QAEH,IAAI,CAAC,QAAQ,CAAC,EAAE,EAAE,CAAC;YAClB,MAAM,IAAI,wBAAwB,CAAC,QAAQ,CAAC,MAAM,EAAE,MAAM,QAAQ,CAAC,IAAI,EAAE,CAAC,CAAC;QAC5E,CAAC;QACD,IAAI,QAAQ,CAAC,MAAM,KAAK,GAAG,EAAE,CAAC;YAC7B,MAAM,IAAI,0BAA0B,CAAC,SAAS,EAAE,2BAA2B,CAAC,CAAC;QAC9E,CAAC;QAED,IAAI,KAAc,CAAC;QACnB,IAAI,CAAC;YACJ,KAAK,GAAG,MAAM,QAAQ,CAAC,IAAI,EAAE,CAAC;QAC/B,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YAChB,MAAM,IAAI,0BAA0B,CAAC,SAAS,EAAE,wBAAwB,EAAE,KAAK,CAAC,CAAC;QAClF,CAAC;QACD,OAAO,MAAM,CAAC,KAAK,CAAC,CAAC;IACtB,CAAC;CACD;AAED,MAAM,UAAU,oBAAoB,CAAC,SAAiB;IACrD,OAAO,SAAS,CAAC,UAAU,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC,KAAK,CAAC,SAAS,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC;AACxF,CAAC;AAED,MAAM,UAAU,4BAA4B,CAAC,SAAiB;IAC7D,OAAO,SAAS,CAAC,UAAU,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,UAAU,SAAS,EAAE,CAAC;AAC5E,CAAC","sourcesContent":["import { validateSessionId } from \"./ids.ts\";\nimport type { FileEntry, SessionInfo } from \"./types.ts\";\n\nexport type RemoteSessionInfo = Omit<SessionInfo, \"path\" | \"created\" | \"modified\"> & {\n\tpath?: string;\n\tcreated: Date | string;\n\tmodified: Date | string;\n};\n\nexport interface RemoteSessionClientOptions {\n\tbaseUrl: string;\n\ttoken: string;\n\tfetch?: typeof fetch;\n}\n\nexport interface RemoteSessionSnapshot {\n\treference: string;\n\tid: string;\n\tversion?: number;\n\tentries: FileEntry[];\n\tetag?: string;\n}\n\nexport interface CreateRemoteSessionRequest {\n\tid?: string;\n\tcwd: string;\n\tprojectId?: string;\n\tparentSession?: string;\n\tmetadata?: Record<string, unknown>;\n}\n\nexport interface AppendRemoteSessionEntriesRequest {\n\tbaseEtag?: string;\n\tentries: FileEntry[];\n}\n\nexport interface AppendRemoteSessionEntriesResponse {\n\tetag?: string;\n\taccepted: number;\n}\n\n// grip-ignore noNearIdenticalDataStructures: Snapshot replacement atomically rewrites complete state, while append applies incremental entries; their endpoint validation and concurrency contracts evolve independently.\nexport interface ReplaceRemoteSessionSnapshotRequest {\n\tbaseEtag?: string;\n\tentries: FileEntry[];\n}\n\nexport interface ReplaceRemoteSessionSnapshotResponse {\n\tetag?: string;\n}\n\nexport interface ForkRemoteSessionRequest {\n\tcwd: string;\n\tprojectId?: string;\n\tleafId?: string;\n}\n\nexport interface ImportRemoteSessionJsonlRequest {\n\tcwd: string;\n\tprojectId?: string;\n\tsourceName?: string;\n\tentries: FileEntry[];\n\tmetadata?: Record<string, unknown>;\n}\n\nexport interface ListRemoteSessionsResponse {\n\tsessions: RemoteSessionInfo[];\n}\n\nexport type RemoteSessionOperation = \"create\" | \"open\" | \"recent\" | \"fork\" | \"import\" | \"list\" | \"append\" | \"replace\";\n\nexport class RemoteSessionClientError extends Error {\n\treadonly status: number;\n\treadonly responseText: string;\n\n\tconstructor(status: number, responseText: string) {\n\t\tsuper(`Remote session request failed with status ${status}: ${responseText}`);\n\t\tthis.name = \"RemoteSessionClientError\";\n\t\tthis.status = status;\n\t\tthis.responseText = responseText;\n\t}\n}\n\nexport class RemoteSessionProtocolError extends Error {\n\treadonly operation: RemoteSessionOperation;\n\n\tconstructor(operation: RemoteSessionOperation, message: string, cause?: unknown) {\n\t\tsuper(`Invalid remote session ${operation} response: ${message}`, { cause });\n\t\tthis.name = \"RemoteSessionProtocolError\";\n\t\tthis.operation = operation;\n\t}\n}\n\nfunction isRecord(value: unknown): value is Record<string, unknown> {\n\treturn typeof value === \"object\" && value !== null && !Array.isArray(value);\n}\n\nfunction requiredString(record: Record<string, unknown>, key: string, operation: RemoteSessionOperation): string {\n\tconst value = record[key];\n\tif (typeof value !== \"string\" || value.length === 0) {\n\t\tthrow new RemoteSessionProtocolError(operation, `${key} must be a non-empty string`);\n\t}\n\treturn value;\n}\n\nfunction stringValue(record: Record<string, unknown>, key: string, operation: RemoteSessionOperation): string {\n\tconst value = record[key];\n\tif (typeof value !== \"string\") {\n\t\tthrow new RemoteSessionProtocolError(operation, `${key} must be a string`);\n\t}\n\treturn value;\n}\n\nfunction requiredSessionId(record: Record<string, unknown>, operation: RemoteSessionOperation): string {\n\tconst id = requiredString(record, \"id\", operation);\n\ttry {\n\t\tvalidateSessionId(id);\n\t} catch (error) {\n\t\tthrow new RemoteSessionProtocolError(operation, \"id is not a valid session id\", error);\n\t}\n\treturn id;\n}\n\nfunction optionalString(\n\trecord: Record<string, unknown>,\n\tkey: string,\n\toperation: RemoteSessionOperation,\n): string | undefined {\n\tconst value = record[key];\n\tif (value === undefined) return undefined;\n\tif (typeof value !== \"string\" || value.length === 0) {\n\t\tthrow new RemoteSessionProtocolError(operation, `${key} must be a non-empty string when present`);\n\t}\n\treturn value;\n}\n\nfunction decodeSnapshot(value: unknown, operation: RemoteSessionOperation, expectedId?: string): RemoteSessionSnapshot {\n\tif (!isRecord(value)) throw new RemoteSessionProtocolError(operation, \"snapshot must be an object\");\n\tconst id = requiredSessionId(value, operation);\n\tconst reference = requiredString(value, \"reference\", operation);\n\tif (parseRemoteSessionId(reference) !== id) {\n\t\tthrow new RemoteSessionProtocolError(operation, `reference ${reference} does not identify snapshot id ${id}`);\n\t}\n\tif (expectedId !== undefined && id !== expectedId) {\n\t\tthrow new RemoteSessionProtocolError(operation, `snapshot id ${id} does not match requested id ${expectedId}`);\n\t}\n\tif (!Array.isArray(value.entries) || value.entries.length === 0 || value.entries.some((entry) => !isRecord(entry))) {\n\t\tthrow new RemoteSessionProtocolError(operation, \"entries must be a non-empty array of objects\");\n\t}\n\tconst header = value.entries[0];\n\tif (\n\t\t!isRecord(header) ||\n\t\theader.type !== \"session\" ||\n\t\theader.id !== id ||\n\t\ttypeof header.cwd !== \"string\" ||\n\t\ttypeof header.timestamp !== \"string\"\n\t) {\n\t\tthrow new RemoteSessionProtocolError(operation, \"entries must begin with a matching session header\");\n\t}\n\tconst version = value.version;\n\tif (\n\t\tversion !== undefined &&\n\t\t(typeof version !== \"number\" || !Number.isInteger(version) || version < 1 || version !== header.version)\n\t) {\n\t\tthrow new RemoteSessionProtocolError(operation, \"version must be a positive integer matching the session header\");\n\t}\n\treturn {\n\t\treference,\n\t\tid,\n\t\tversion: version as number | undefined,\n\t\tentries: value.entries as FileEntry[],\n\t\tetag: optionalString(value, \"etag\", operation),\n\t};\n}\n\nfunction decodeForkSnapshot(value: unknown, sourceId: string): RemoteSessionSnapshot {\n\tconst snapshot = decodeSnapshot(value, \"fork\");\n\tif (snapshot.id === sourceId) {\n\t\tthrow new RemoteSessionProtocolError(\"fork\", \"fork snapshot must have a new session id\");\n\t}\n\tconst header = snapshot.entries[0];\n\tif (header?.type !== \"session\" || !header.parentSession || parseRemoteSessionId(header.parentSession) !== sourceId) {\n\t\tthrow new RemoteSessionProtocolError(\"fork\", `fork header must reference source session ${sourceId}`);\n\t}\n\treturn snapshot;\n}\n\nfunction decodeAppendResponse(value: unknown): AppendRemoteSessionEntriesResponse {\n\tconst operation = \"append\";\n\tif (!isRecord(value)) throw new RemoteSessionProtocolError(operation, \"response must be an object\");\n\tif (!Number.isInteger(value.accepted)) {\n\t\tthrow new RemoteSessionProtocolError(operation, \"accepted must be an integer\");\n\t}\n\treturn { accepted: value.accepted as number, etag: optionalString(value, \"etag\", operation) };\n}\n\nfunction decodeReplaceResponse(value: unknown): ReplaceRemoteSessionSnapshotResponse {\n\tconst operation = \"replace\";\n\tif (!isRecord(value)) throw new RemoteSessionProtocolError(operation, \"response must be an object\");\n\treturn { etag: optionalString(value, \"etag\", operation) };\n}\n\nfunction decodeSessionInfo(value: unknown): RemoteSessionInfo {\n\tconst operation = \"list\";\n\tif (!isRecord(value)) throw new RemoteSessionProtocolError(operation, \"each session must be an object\");\n\tconst id = requiredSessionId(value, operation);\n\tconst reference = optionalString(value, \"reference\", operation);\n\tconst path = optionalString(value, \"path\", operation);\n\tfor (const candidate of [reference, path]) {\n\t\tif (candidate !== undefined && parseRemoteSessionId(candidate) !== id) {\n\t\t\tthrow new RemoteSessionProtocolError(operation, `reference ${candidate} does not identify session id ${id}`);\n\t\t}\n\t}\n\tconst created = requiredString(value, \"created\", operation);\n\tconst modified = requiredString(value, \"modified\", operation);\n\tif (!Number.isFinite(Date.parse(created)) || !Number.isFinite(Date.parse(modified))) {\n\t\tthrow new RemoteSessionProtocolError(operation, \"created and modified must be valid date strings\");\n\t}\n\tif (!Number.isInteger(value.messageCount) || (value.messageCount as number) < 0) {\n\t\tthrow new RemoteSessionProtocolError(operation, \"messageCount must be a non-negative integer\");\n\t}\n\treturn {\n\t\treference,\n\t\tpath,\n\t\tid,\n\t\tcwd: stringValue(value, \"cwd\", operation),\n\t\tname: optionalString(value, \"name\", operation),\n\t\tparentSessionPath: optionalString(value, \"parentSessionPath\", operation),\n\t\tcreated,\n\t\tmodified,\n\t\tmessageCount: value.messageCount as number,\n\t\tfirstMessage: stringValue(value, \"firstMessage\", operation),\n\t\tallMessagesText: stringValue(value, \"allMessagesText\", operation),\n\t};\n}\n\nfunction decodeListResponse(value: unknown): ListRemoteSessionsResponse {\n\tif (!isRecord(value) || !Array.isArray(value.sessions)) {\n\t\tthrow new RemoteSessionProtocolError(\"list\", \"sessions must be an array\");\n\t}\n\treturn { sessions: value.sessions.map((session) => decodeSessionInfo(session)) };\n}\n\nexport class RemoteSessionClient {\n\tprivate readonly baseUrl: string;\n\tprivate readonly token: string;\n\tprivate readonly fetchImpl: typeof fetch;\n\n\tconstructor(options: RemoteSessionClientOptions) {\n\t\tthis.baseUrl = options.baseUrl.replace(/\\/+$/, \"\");\n\t\tthis.token = options.token;\n\t\tthis.fetchImpl = options.fetch ?? fetch;\n\t}\n\n\tcreateSession(request: CreateRemoteSessionRequest): Promise<RemoteSessionSnapshot> {\n\t\treturn this.request(\"POST\", \"/v1/sessions\", request, \"create\", (value) =>\n\t\t\tdecodeSnapshot(value, \"create\", request.id),\n\t\t);\n\t}\n\n\topenSession(sessionIdOrReference: string): Promise<RemoteSessionSnapshot> {\n\t\tconst id = parseRemoteSessionId(sessionIdOrReference);\n\t\treturn this.request(\"GET\", `/v1/sessions/${encodeURIComponent(id)}`, undefined, \"open\", (value) =>\n\t\t\tdecodeSnapshot(value, \"open\", id),\n\t\t);\n\t}\n\n\tappendEntries(\n\t\tsessionIdOrReference: string,\n\t\trequest: AppendRemoteSessionEntriesRequest,\n\t): Promise<AppendRemoteSessionEntriesResponse> {\n\t\treturn this.request(\n\t\t\t\"POST\",\n\t\t\t`/v1/sessions/${encodeURIComponent(parseRemoteSessionId(sessionIdOrReference))}/entries`,\n\t\t\trequest,\n\t\t\t\"append\",\n\t\t\tdecodeAppendResponse,\n\t\t);\n\t}\n\n\treplaceSnapshot(\n\t\tsessionIdOrReference: string,\n\t\trequest: ReplaceRemoteSessionSnapshotRequest,\n\t): Promise<ReplaceRemoteSessionSnapshotResponse> {\n\t\treturn this.request(\n\t\t\t\"PUT\",\n\t\t\t`/v1/sessions/${encodeURIComponent(parseRemoteSessionId(sessionIdOrReference))}/snapshot`,\n\t\t\trequest,\n\t\t\t\"replace\",\n\t\t\tdecodeReplaceResponse,\n\t\t);\n\t}\n\n\tlistSessions(): Promise<ListRemoteSessionsResponse> {\n\t\treturn this.request(\"GET\", \"/v1/sessions\", undefined, \"list\", decodeListResponse);\n\t}\n\n\tgetRecentSession(): Promise<RemoteSessionSnapshot> {\n\t\treturn this.request(\"GET\", \"/v1/sessions/recent\", undefined, \"recent\", (value) =>\n\t\t\tdecodeSnapshot(value, \"recent\"),\n\t\t);\n\t}\n\n\tforkSession(sessionIdOrReference: string, request: ForkRemoteSessionRequest): Promise<RemoteSessionSnapshot> {\n\t\tconst sourceId = parseRemoteSessionId(sessionIdOrReference);\n\t\treturn this.request(\"POST\", `/v1/sessions/${encodeURIComponent(sourceId)}/fork`, request, \"fork\", (value) =>\n\t\t\tdecodeForkSnapshot(value, sourceId),\n\t\t);\n\t}\n\n\timportJsonl(request: ImportRemoteSessionJsonlRequest): Promise<RemoteSessionSnapshot> {\n\t\treturn this.request(\"POST\", \"/v1/sessions/import-jsonl\", request, \"import\", (value) =>\n\t\t\tdecodeSnapshot(value, \"import\"),\n\t\t);\n\t}\n\n\tprivate async request<T>(\n\t\tmethod: string,\n\t\tpath: string,\n\t\tbody: unknown,\n\t\toperation: RemoteSessionOperation,\n\t\tdecode: (value: unknown) => T,\n\t): Promise<T> {\n\t\tconst response = await this.fetchImpl(`${this.baseUrl}${path}`, {\n\t\t\tmethod,\n\t\t\theaders: {\n\t\t\t\tAuthorization: `Bearer ${this.token}`,\n\t\t\t\tAccept: \"application/json\",\n\t\t\t\t...(body === undefined ? {} : { \"Content-Type\": \"application/json\" }),\n\t\t\t},\n\t\t\tbody: body === undefined ? undefined : JSON.stringify(body),\n\t\t});\n\n\t\tif (!response.ok) {\n\t\t\tthrow new RemoteSessionClientError(response.status, await response.text());\n\t\t}\n\t\tif (response.status === 204) {\n\t\t\tthrow new RemoteSessionProtocolError(operation, \"response body is required\");\n\t\t}\n\n\t\tlet value: unknown;\n\t\ttry {\n\t\t\tvalue = await response.json();\n\t\t} catch (error) {\n\t\t\tthrow new RemoteSessionProtocolError(operation, \"body is not valid JSON\", error);\n\t\t}\n\t\treturn decode(value);\n\t}\n}\n\nexport function parseRemoteSessionId(reference: string): string {\n\treturn reference.startsWith(\"remote:\") ? reference.slice(\"remote:\".length) : reference;\n}\n\nexport function formatRemoteSessionReference(sessionId: string): string {\n\treturn sessionId.startsWith(\"remote:\") ? sessionId : `remote:${sessionId}`;\n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W,CAAC,SAAS,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,kBAAkB,GAAG,OAAO,CAAC,aAAa,CAAC,CAqCzF;IAEK,IAAI,CAAC,WAAW,CAAC,EAAE,mBAAmB,GAAG,OAAO,CAAC,WAAW,EAAE,CAAC,CAGpE;IAEK,OAAO,CAAC,WAAW,CAAC,EAAE,mBAAmB,GAAG,OAAO,CAAC,WAAW,EAAE,CAAC,CAGvE;CACD","sourcesContent":["import { existsSync } from \"node:fs\";\nimport { basename, resolve } from \"node:path\";\nimport type { JsonlErrorPhase } from \"./jsonl-errors.ts\";\nimport { createJsonlSessionDecodeError } from \"./jsonl-errors.ts\";\nimport { loadEntriesFromFile } from \"./jsonl-helpers.ts\";\nimport { migrateToCurrentVersion } from \"./migrations.ts\";\nimport { RemoteSession } from \"./remote-session.ts\";\nimport type { RemoteSessionInfo, RemoteSessionSnapshot } from \"./remote-session-client.ts\";\nimport { RemoteSessionClient } from \"./remote-session-client.ts\";\nimport type { Session } from \"./session.ts\";\nimport type { OpenSessionOptions, SessionManager } from \"./session-manager.ts\";\nimport { getJsonlEntryLocations, validateCurrentSessionEntries } from \"./stores/jsonl-session-store.ts\";\nimport type { NewSessionOptions, SessionHeader, SessionInfo, SessionListProgress } from \"./types.ts\";\n\nexport interface RemoteSessionManagerOptions {\n\tbaseUrl: string;\n\ttoken: string;\n\tcwd: string;\n\tprojectId?: string;\n\tfetch?: typeof fetch;\n}\n\nfunction getSnapshotCwd(snapshot: RemoteSessionSnapshot, fallback: string): string {\n\tconst header = snapshot.entries.find((entry) => entry.type === \"session\") as SessionHeader | undefined;\n\treturn typeof header?.cwd === \"string\" ? header.cwd : fallback;\n}\n\nfunction validateRemoteSnapshot(snapshot: RemoteSessionSnapshot, phase: JsonlErrorPhase): RemoteSessionSnapshot {\n\tvalidateCurrentSessionEntries(snapshot.entries, snapshot.reference, { phase });\n\treturn snapshot;\n}\n\nfunction normalizeRemoteSessionInfo(session: RemoteSessionInfo): SessionInfo {\n\tconst reference = session.reference ?? session.path;\n\treturn {\n\t\t...session,\n\t\treference,\n\t\tpath: session.path ?? reference ?? session.id,\n\t\tcreated: session.created instanceof Date ? session.created : new Date(session.created),\n\t\tmodified: session.modified instanceof Date ? session.modified : new Date(session.modified),\n\t};\n}\n\n/**\n * Remote session manager skeleton.\n *\n * Lifecycle methods are async-compatible through SessionManager so this backend\n * can fetch/create snapshots before returning an active Session.\n */\nexport class RemoteSessionManager implements SessionManager {\n\tprivate readonly client: RemoteSessionClient;\n\tprivate readonly cwd: string;\n\tprivate readonly projectId: string | undefined;\n\n\tconstructor(options: RemoteSessionManagerOptions) {\n\t\tthis.client = new RemoteSessionClient({ baseUrl: options.baseUrl, token: options.token, fetch: options.fetch });\n\t\tthis.cwd = options.cwd;\n\t\tthis.projectId = options.projectId;\n\t}\n\n\tasync create(options?: NewSessionOptions): Promise<RemoteSession> {\n\t\tconst snapshot = validateRemoteSnapshot(\n\t\t\tawait this.client.createSession({\n\t\t\t\tid: options?.id,\n\t\t\t\tcwd: this.cwd,\n\t\t\t\tprojectId: this.projectId,\n\t\t\t\tparentSession: options?.parentSession,\n\t\t\t}),\n\t\t\t\"create\",\n\t\t);\n\t\treturn new RemoteSession({ client: this.client, cwd: this.cwd, snapshot, sessionManager: this });\n\t}\n\n\tasync openReference(reference: string, options?: OpenSessionOptions): Promise<RemoteSession> {\n\t\tconst snapshot = validateRemoteSnapshot(await this.client.openSession(reference), \"open\");\n\t\treturn new RemoteSession({\n\t\t\tclient: this.client,\n\t\t\tcwd: options?.cwdOverride ?? getSnapshotCwd(snapshot, this.cwd),\n\t\t\tsnapshot,\n\t\t\tsessionManager: this,\n\t\t});\n\t}\n\n\tasync continueRecent(): Promise<RemoteSession> {\n\t\tconst snapshot = validateRemoteSnapshot(await this.client.getRecentSession(), \"open\");\n\t\treturn new RemoteSession({\n\t\t\tclient: this.client,\n\t\t\tcwd: getSnapshotCwd(snapshot, this.cwd),\n\t\t\tsnapshot,\n\t\t\tsessionManager: this,\n\t\t});\n\t}\n\n\tasync forkFrom(reference: string): Promise<RemoteSession> {\n\t\tconst snapshot = validateRemoteSnapshot(\n\t\t\tawait this.client.forkSession(reference, { cwd: this.cwd, projectId: this.projectId }),\n\t\t\t\"fork\",\n\t\t);\n\t\treturn new RemoteSession({ client: this.client, cwd: this.cwd, snapshot, sessionManager: this });\n\t}\n\n\tasync forkSession(source: Session, targetLeafId: string | null): Promise<RemoteSession> {\n\t\tif (source instanceof RemoteSession) await source.flushPendingSync();\n\t\tconst reference = source.getSessionReference();\n\t\tif (!reference) {\n\t\t\tthrow new Error(\"Cannot fork a remote session without a session reference\");\n\t\t}\n\t\tconst snapshot = validateRemoteSnapshot(\n\t\t\tawait this.client.forkSession(reference, {\n\t\t\t\tcwd: this.cwd,\n\t\t\t\tprojectId: this.projectId,\n\t\t\t\tleafId: targetLeafId ?? undefined,\n\t\t\t}),\n\t\t\t\"fork\",\n\t\t);\n\t\treturn new RemoteSession({ client: this.client, cwd: this.cwd, snapshot, sessionManager: this });\n\t}\n\n\tasync importJsonl(inputPath: string, options?: OpenSessionOptions): Promise<RemoteSession> {\n\t\tconst resolvedPath = resolve(inputPath);\n\t\tif (!existsSync(resolvedPath)) {\n\t\t\tthrow new Error(`File not found: ${resolvedPath}`);\n\t\t}\n\n\t\tconst entries = loadEntriesFromFile(resolvedPath, { repair: false, phase: \"import\" });\n\t\tif (entries.length === 0) {\n\t\t\tthrow createJsonlSessionDecodeError(\n\t\t\t\tresolvedPath,\n\t\t\t\t\"import\",\n\t\t\t\t\"schema\",\n\t\t\t\t`Cannot import empty or invalid session JSONL: ${resolvedPath}`,\n\t\t\t);\n\t\t}\n\t\tmigrateToCurrentVersion(entries);\n\t\tvalidateCurrentSessionEntries(entries, resolvedPath, {\n\t\t\tphase: \"import\",\n\t\t\tlocations: getJsonlEntryLocations(entries),\n\t\t});\n\n\t\tconst cwd = options?.cwdOverride ?? getSnapshotCwd({ id: \"\", reference: \"\", entries }, this.cwd);\n\t\tconst snapshot = validateRemoteSnapshot(\n\t\t\tawait this.client.importJsonl({\n\t\t\t\tcwd,\n\t\t\t\tprojectId: this.projectId,\n\t\t\t\tsourceName: basename(resolvedPath),\n\t\t\t\tentries,\n\t\t\t}),\n\t\t\t\"import\",\n\t\t);\n\t\treturn new RemoteSession({\n\t\t\tclient: this.client,\n\t\t\tcwd: getSnapshotCwd(snapshot, cwd),\n\t\t\tsnapshot,\n\t\t\tsessionManager: this,\n\t\t});\n\t}\n\n\tasync list(_onProgress?: SessionListProgress): Promise<SessionInfo[]> {\n\t\tconst response = await this.client.listSessions();\n\t\treturn response.sessions.map((session) => normalizeRemoteSessionInfo(session));\n\t}\n\n\tasync listAll(_onProgress?: SessionListProgress): Promise<SessionInfo[]> {\n\t\tconst response = await this.client.listSessions();\n\t\treturn response.sessions.map((session) => normalizeRemoteSessionInfo(session));\n\t}\n}\n"]}
1
+ {"version":3,"file":"remote-session-manager.d.ts","sourceRoot":"","sources":["../../../src/core/session/remote-session-manager.ts"],"names":[],"mappings":"AAMA,OAAO,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AAGpD,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AAC5C,OAAO,KAAK,EAAE,kBAAkB,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC;AAE/E,OAAO,KAAK,EAAE,iBAAiB,EAAiB,WAAW,EAAE,mBAAmB,EAAE,MAAM,YAAY,CAAC;AAErG,MAAM,WAAW,2BAA2B;IAC3C,OAAO,EAAE,MAAM,CAAC;IAChB,KAAK,EAAE,MAAM,CAAC;IACd,GAAG,EAAE,MAAM,CAAC;IACZ,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,KAAK,CAAC,EAAE,OAAO,KAAK,CAAC;CACrB;AAuBD;;;;;GAKG;AACH,qBAAa,oBAAqB,YAAW,cAAc;IAC1D,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAsB;IAC7C,OAAO,CAAC,QAAQ,CAAC,GAAG,CAAS;IAC7B,OAAO,CAAC,QAAQ,CAAC,SAAS,CAAqB;IAE/C,YAAY,OAAO,EAAE,2BAA2B,EAI/C;IAEK,MAAM,CAAC,OAAO,CAAC,EAAE,iBAAiB,GAAG,OAAO,CAAC,aAAa,CAAC,CAWhE;IAEK,aAAa,CAAC,SAAS,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,kBAAkB,GAAG,OAAO,CAAC,aAAa,CAAC,CAQ3F;IAEK,cAAc,IAAI,OAAO,CAAC,aAAa,CAAC,CAQ7C;IAEK,QAAQ,CAAC,SAAS,EAAE,MAAM,GAAG,OAAO,CAAC,aAAa,CAAC,CAMxD;IAEK,WAAW,CAAC,MAAM,EAAE,OAAO,EAAE,YAAY,EAAE,MAAM,GAAG,IAAI,GAAG,OAAO,CAAC,aAAa,CAAC,CAetF;IAEK,WAAW,CAAC,SAAS,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,kBAAkB,GAAG,OAAO,CAAC,aAAa,CAAC,CAqCzF;IAEK,IAAI,CAAC,WAAW,CAAC,EAAE,mBAAmB,GAAG,OAAO,CAAC,WAAW,EAAE,CAAC,CAGpE;IAEK,OAAO,CAAC,WAAW,CAAC,EAAE,mBAAmB,GAAG,OAAO,CAAC,WAAW,EAAE,CAAC,CAGvE;CACD"}
@@ -31,9 +31,6 @@ function normalizeRemoteSessionInfo(session) {
31
31
  * can fetch/create snapshots before returning an active Session.
32
32
  */
33
33
  export class RemoteSessionManager {
34
- client;
35
- cwd;
36
- projectId;
37
34
  constructor(options) {
38
35
  this.client = new RemoteSessionClient({ baseUrl: options.baseUrl, token: options.token, fetch: options.fetch });
39
36
  this.cwd = options.cwd;
@@ -1 +1 @@
1
- {"version":3,"file":"remote-session-manager.js","sourceRoot":"","sources":["../../../src/core/session/remote-session-manager.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AACrC,OAAO,EAAE,QAAQ,EAAE,OAAO,EAAE,MAAM,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AE,EAAE,OAAO,EAAE,EAAE,IAAI,CAAC,GAAG,CAAC,CAAC;QACjG,MAAM,QAAQ,GAAG,sBAAsB,CACtC,MAAM,IAAI,CAAC,MAAM,CAAC,WAAW,CAAC;YAC7B,GAAG;YACH,SAAS,EAAE,IAAI,CAAC,SAAS;YACzB,UAAU,EAAE,QAAQ,CAAC,YAAY,CAAC;YAClC,OAAO;SACP,CAAC,EACF,QAAQ,CACR,CAAC;QACF,OAAO,IAAI,aAAa,CAAC;YACxB,MAAM,EAAE,IAAI,CAAC,MAAM;YACnB,GAAG,EAAE,cAAc,CAAC,QAAQ,EAAE,GAAG,CAAC;YAClC,QAAQ;YACR,cAAc,EAAE,IAAI;SACpB,CAAC,CAAC;IAAA,CACH;IAED,KAAK,CAAC,IAAI,CAAC,WAAiC,EAA0B;QACrE,MAAM,QAAQ,GAAG,MAAM,IAAI,CAAC,MAAM,CAAC,YAAY,EAAE,CAAC;QAClD,OAAO,QAAQ,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,0BAA0B,CAAC,OAAO,CAAC,CAAC,CAAC;IAAA,CAC/E;IAED,KAAK,CAAC,OAAO,CAAC,WAAiC,EAA0B;QACxE,MAAM,QAAQ,GAAG,MAAM,IAAI,CAAC,MAAM,CAAC,YAAY,EAAE,CAAC;QAClD,OAAO,QAAQ,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,0BAA0B,CAAC,OAAO,CAAC,CAAC,CAAC;IAAA,CAC/E;CACD","sourcesContent":["import { existsSync } from \"node:fs\";\nimport { basename, resolve } from \"node:path\";\nimport type { JsonlErrorPhase } from \"./jsonl-errors.ts\";\nimport { createJsonlSessionDecodeError } from \"./jsonl-errors.ts\";\nimport { loadEntriesFromFile } from \"./jsonl-helpers.ts\";\nimport { migrateToCurrentVersion } from \"./migrations.ts\";\nimport { RemoteSession } from \"./remote-session.ts\";\nimport type { RemoteSessionInfo, RemoteSessionSnapshot } from \"./remote-session-client.ts\";\nimport { RemoteSessionClient } from \"./remote-session-client.ts\";\nimport type { Session } from \"./session.ts\";\nimport type { OpenSessionOptions, SessionManager } from \"./session-manager.ts\";\nimport { getJsonlEntryLocations, validateCurrentSessionEntries } from \"./stores/jsonl-session-store.ts\";\nimport type { NewSessionOptions, SessionHeader, SessionInfo, SessionListProgress } from \"./types.ts\";\n\nexport interface RemoteSessionManagerOptions {\n\tbaseUrl: string;\n\ttoken: string;\n\tcwd: string;\n\tprojectId?: string;\n\tfetch?: typeof fetch;\n}\n\nfunction getSnapshotCwd(snapshot: RemoteSessionSnapshot, fallback: string): string {\n\tconst header = snapshot.entries.find((entry) => entry.type === \"session\") as SessionHeader | undefined;\n\treturn typeof header?.cwd === \"string\" ? header.cwd : fallback;\n}\n\nfunction validateRemoteSnapshot(snapshot: RemoteSessionSnapshot, phase: JsonlErrorPhase): RemoteSessionSnapshot {\n\tvalidateCurrentSessionEntries(snapshot.entries, snapshot.reference, { phase });\n\treturn snapshot;\n}\n\nfunction normalizeRemoteSessionInfo(session: RemoteSessionInfo): SessionInfo {\n\tconst reference = session.reference ?? session.path;\n\treturn {\n\t\t...session,\n\t\treference,\n\t\tpath: session.path ?? reference ?? session.id,\n\t\tcreated: session.created instanceof Date ? session.created : new Date(session.created),\n\t\tmodified: session.modified instanceof Date ? session.modified : new Date(session.modified),\n\t};\n}\n\n/**\n * Remote session manager skeleton.\n *\n * Lifecycle methods are async-compatible through SessionManager so this backend\n * can fetch/create snapshots before returning an active Session.\n */\nexport class RemoteSessionManager implements SessionManager {\n\tprivate readonly client: RemoteSessionClient;\n\tprivate readonly cwd: string;\n\tprivate readonly projectId: string | undefined;\n\n\tconstructor(options: RemoteSessionManagerOptions) {\n\t\tthis.client = new RemoteSessionClient({ baseUrl: options.baseUrl, token: options.token, fetch: options.fetch });\n\t\tthis.cwd = options.cwd;\n\t\tthis.projectId = options.projectId;\n\t}\n\n\tasync create(options?: NewSessionOptions): Promise<RemoteSession> {\n\t\tconst snapshot = validateRemoteSnapshot(\n\t\t\tawait this.client.createSession({\n\t\t\t\tid: options?.id,\n\t\t\t\tcwd: this.cwd,\n\t\t\t\tprojectId: this.projectId,\n\t\t\t\tparentSession: options?.parentSession,\n\t\t\t}),\n\t\t\t\"create\",\n\t\t);\n\t\treturn new RemoteSession({ client: this.client, cwd: this.cwd, snapshot, sessionManager: this });\n\t}\n\n\tasync openReference(reference: string, options?: OpenSessionOptions): Promise<RemoteSession> {\n\t\tconst snapshot = validateRemoteSnapshot(await this.client.openSession(reference), \"open\");\n\t\treturn new RemoteSession({\n\t\t\tclient: this.client,\n\t\t\tcwd: options?.cwdOverride ?? getSnapshotCwd(snapshot, this.cwd),\n\t\t\tsnapshot,\n\t\t\tsessionManager: this,\n\t\t});\n\t}\n\n\tasync continueRecent(): Promise<RemoteSession> {\n\t\tconst snapshot = validateRemoteSnapshot(await this.client.getRecentSession(), \"open\");\n\t\treturn new RemoteSession({\n\t\t\tclient: this.client,\n\t\t\tcwd: getSnapshotCwd(snapshot, this.cwd),\n\t\t\tsnapshot,\n\t\t\tsessionManager: this,\n\t\t});\n\t}\n\n\tasync forkFrom(reference: string): Promise<RemoteSession> {\n\t\tconst snapshot = validateRemoteSnapshot(\n\t\t\tawait this.client.forkSession(reference, { cwd: this.cwd, projectId: this.projectId }),\n\t\t\t\"fork\",\n\t\t);\n\t\treturn new RemoteSession({ client: this.client, cwd: this.cwd, snapshot, sessionManager: this });\n\t}\n\n\tasync forkSession(source: Session, targetLeafId: string | null): Promise<RemoteSession> {\n\t\tif (source instanceof RemoteSession) await source.flushPendingSync();\n\t\tconst reference = source.getSessionReference();\n\t\tif (!reference) {\n\t\t\tthrow new Error(\"Cannot fork a remote session without a session reference\");\n\t\t}\n\t\tconst snapshot = validateRemoteSnapshot(\n\t\t\tawait this.client.forkSession(reference, {\n\t\t\t\tcwd: this.cwd,\n\t\t\t\tprojectId: this.projectId,\n\t\t\t\tleafId: targetLeafId ?? undefined,\n\t\t\t}),\n\t\t\t\"fork\",\n\t\t);\n\t\treturn new RemoteSession({ client: this.client, cwd: this.cwd, snapshot, sessionManager: this });\n\t}\n\n\tasync importJsonl(inputPath: string, options?: OpenSessionOptions): Promise<RemoteSession> {\n\t\tconst resolvedPath = resolve(inputPath);\n\t\tif (!existsSync(resolvedPath)) {\n\t\t\tthrow new Error(`File not found: ${resolvedPath}`);\n\t\t}\n\n\t\tconst entries = loadEntriesFromFile(resolvedPath, { repair: false, phase: \"import\" });\n\t\tif (entries.length === 0) {\n\t\t\tthrow createJsonlSessionDecodeError(\n\t\t\t\tresolvedPath,\n\t\t\t\t\"import\",\n\t\t\t\t\"schema\",\n\t\t\t\t`Cannot import empty or invalid session JSONL: ${resolvedPath}`,\n\t\t\t);\n\t\t}\n\t\tmigrateToCurrentVersion(entries);\n\t\tvalidateCurrentSessionEntries(entries, resolvedPath, {\n\t\t\tphase: \"import\",\n\t\t\tlocations: getJsonlEntryLocations(entries),\n\t\t});\n\n\t\tconst cwd = options?.cwdOverride ?? getSnapshotCwd({ id: \"\", reference: \"\", entries }, this.cwd);\n\t\tconst snapshot = validateRemoteSnapshot(\n\t\t\tawait this.client.importJsonl({\n\t\t\t\tcwd,\n\t\t\t\tprojectId: this.projectId,\n\t\t\t\tsourceName: basename(resolvedPath),\n\t\t\t\tentries,\n\t\t\t}),\n\t\t\t\"import\",\n\t\t);\n\t\treturn new RemoteSession({\n\t\t\tclient: this.client,\n\t\t\tcwd: getSnapshotCwd(snapshot, cwd),\n\t\t\tsnapshot,\n\t\t\tsessionManager: this,\n\t\t});\n\t}\n\n\tasync list(_onProgress?: SessionListProgress): Promise<SessionInfo[]> {\n\t\tconst response = await this.client.listSessions();\n\t\treturn response.sessions.map((session) => normalizeRemoteSessionInfo(session));\n\t}\n\n\tasync listAll(_onProgress?: SessionListProgress): Promise<SessionInfo[]> {\n\t\tconst response = await this.client.listSessions();\n\t\treturn response.sessions.map((session) => normalizeRemoteSessionInfo(session));\n\t}\n}\n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AI,cAAc,CAAC,EAAE,EAAE,EAAE,EAAE,EAAE,SAAS,EAAE,EAAE,EAAE,OAAO,EAAE,EAAE,IAAI,CAAC,GAAG,CAAC,CAAC;QACjG,MAAM,QAAQ,GAAG,sBAAsB,CACtC,MAAM,IAAI,CAAC,MAAM,CAAC,WAAW,CAAC;YAC7B,GAAG;YACH,SAAS,EAAE,IAAI,CAAC,SAAS;YACzB,UAAU,EAAE,QAAQ,CAAC,YAAY,CAAC;YAClC,OAAO;SACP,CAAC,EACF,QAAQ,CACR,CAAC;QACF,OAAO,IAAI,aAAa,CAAC;YACxB,MAAM,EAAE,IAAI,CAAC,MAAM;YACnB,GAAG,EAAE,cAAc,CAAC,QAAQ,EAAE,GAAG,CAAC;YAClC,QAAQ;YACR,cAAc,EAAE,IAAI;SACpB,CAAC,CAAC;IACJ,CAAC;IAED,KAAK,CAAC,IAAI,CAAC,WAAiC;QAC3C,MAAM,QAAQ,GAAG,MAAM,IAAI,CAAC,MAAM,CAAC,YAAY,EAAE,CAAC;QAClD,OAAO,QAAQ,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,0BAA0B,CAAC,OAAO,CAAC,CAAC,CAAC;IAChF,CAAC;IAED,KAAK,CAAC,OAAO,CAAC,WAAiC;QAC9C,MAAM,QAAQ,GAAG,MAAM,IAAI,CAAC,MAAM,CAAC,YAAY,EAAE,CAAC;QAClD,OAAO,QAAQ,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,0BAA0B,CAAC,OAAO,CAAC,CAAC,CAAC;IAChF,CAAC;CACD","sourcesContent":["import { existsSync } from \"node:fs\";\nimport { basename, resolve } from \"node:path\";\nimport type { JsonlErrorPhase } from \"./jsonl-errors.ts\";\nimport { createJsonlSessionDecodeError } from \"./jsonl-errors.ts\";\nimport { loadEntriesFromFile } from \"./jsonl-helpers.ts\";\nimport { migrateToCurrentVersion } from \"./migrations.ts\";\nimport { RemoteSession } from \"./remote-session.ts\";\nimport type { RemoteSessionInfo, RemoteSessionSnapshot } from \"./remote-session-client.ts\";\nimport { RemoteSessionClient } from \"./remote-session-client.ts\";\nimport type { Session } from \"./session.ts\";\nimport type { OpenSessionOptions, SessionManager } from \"./session-manager.ts\";\nimport { getJsonlEntryLocations, validateCurrentSessionEntries } from \"./stores/jsonl-session-store.ts\";\nimport type { NewSessionOptions, SessionHeader, SessionInfo, SessionListProgress } from \"./types.ts\";\n\nexport interface RemoteSessionManagerOptions {\n\tbaseUrl: string;\n\ttoken: string;\n\tcwd: string;\n\tprojectId?: string;\n\tfetch?: typeof fetch;\n}\n\nfunction getSnapshotCwd(snapshot: RemoteSessionSnapshot, fallback: string): string {\n\tconst header = snapshot.entries.find((entry) => entry.type === \"session\") as SessionHeader | undefined;\n\treturn typeof header?.cwd === \"string\" ? header.cwd : fallback;\n}\n\nfunction validateRemoteSnapshot(snapshot: RemoteSessionSnapshot, phase: JsonlErrorPhase): RemoteSessionSnapshot {\n\tvalidateCurrentSessionEntries(snapshot.entries, snapshot.reference, { phase });\n\treturn snapshot;\n}\n\nfunction normalizeRemoteSessionInfo(session: RemoteSessionInfo): SessionInfo {\n\tconst reference = session.reference ?? session.path;\n\treturn {\n\t\t...session,\n\t\treference,\n\t\tpath: session.path ?? reference ?? session.id,\n\t\tcreated: session.created instanceof Date ? session.created : new Date(session.created),\n\t\tmodified: session.modified instanceof Date ? session.modified : new Date(session.modified),\n\t};\n}\n\n/**\n * Remote session manager skeleton.\n *\n * Lifecycle methods are async-compatible through SessionManager so this backend\n * can fetch/create snapshots before returning an active Session.\n */\nexport class RemoteSessionManager implements SessionManager {\n\tprivate readonly client: RemoteSessionClient;\n\tprivate readonly cwd: string;\n\tprivate readonly projectId: string | undefined;\n\n\tconstructor(options: RemoteSessionManagerOptions) {\n\t\tthis.client = new RemoteSessionClient({ baseUrl: options.baseUrl, token: options.token, fetch: options.fetch });\n\t\tthis.cwd = options.cwd;\n\t\tthis.projectId = options.projectId;\n\t}\n\n\tasync create(options?: NewSessionOptions): Promise<RemoteSession> {\n\t\tconst snapshot = validateRemoteSnapshot(\n\t\t\tawait this.client.createSession({\n\t\t\t\tid: options?.id,\n\t\t\t\tcwd: this.cwd,\n\t\t\t\tprojectId: this.projectId,\n\t\t\t\tparentSession: options?.parentSession,\n\t\t\t}),\n\t\t\t\"create\",\n\t\t);\n\t\treturn new RemoteSession({ client: this.client, cwd: this.cwd, snapshot, sessionManager: this });\n\t}\n\n\tasync openReference(reference: string, options?: OpenSessionOptions): Promise<RemoteSession> {\n\t\tconst snapshot = validateRemoteSnapshot(await this.client.openSession(reference), \"open\");\n\t\treturn new RemoteSession({\n\t\t\tclient: this.client,\n\t\t\tcwd: options?.cwdOverride ?? getSnapshotCwd(snapshot, this.cwd),\n\t\t\tsnapshot,\n\t\t\tsessionManager: this,\n\t\t});\n\t}\n\n\tasync continueRecent(): Promise<RemoteSession> {\n\t\tconst snapshot = validateRemoteSnapshot(await this.client.getRecentSession(), \"open\");\n\t\treturn new RemoteSession({\n\t\t\tclient: this.client,\n\t\t\tcwd: getSnapshotCwd(snapshot, this.cwd),\n\t\t\tsnapshot,\n\t\t\tsessionManager: this,\n\t\t});\n\t}\n\n\tasync forkFrom(reference: string): Promise<RemoteSession> {\n\t\tconst snapshot = validateRemoteSnapshot(\n\t\t\tawait this.client.forkSession(reference, { cwd: this.cwd, projectId: this.projectId }),\n\t\t\t\"fork\",\n\t\t);\n\t\treturn new RemoteSession({ client: this.client, cwd: this.cwd, snapshot, sessionManager: this });\n\t}\n\n\tasync forkSession(source: Session, targetLeafId: string | null): Promise<RemoteSession> {\n\t\tif (source instanceof RemoteSession) await source.flushPendingSync();\n\t\tconst reference = source.getSessionReference();\n\t\tif (!reference) {\n\t\t\tthrow new Error(\"Cannot fork a remote session without a session reference\");\n\t\t}\n\t\tconst snapshot = validateRemoteSnapshot(\n\t\t\tawait this.client.forkSession(reference, {\n\t\t\t\tcwd: this.cwd,\n\t\t\t\tprojectId: this.projectId,\n\t\t\t\tleafId: targetLeafId ?? undefined,\n\t\t\t}),\n\t\t\t\"fork\",\n\t\t);\n\t\treturn new RemoteSession({ client: this.client, cwd: this.cwd, snapshot, sessionManager: this });\n\t}\n\n\tasync importJsonl(inputPath: string, options?: OpenSessionOptions): Promise<RemoteSession> {\n\t\tconst resolvedPath = resolve(inputPath);\n\t\tif (!existsSync(resolvedPath)) {\n\t\t\tthrow new Error(`File not found: ${resolvedPath}`);\n\t\t}\n\n\t\tconst entries = loadEntriesFromFile(resolvedPath, { repair: false, phase: \"import\" });\n\t\tif (entries.length === 0) {\n\t\t\tthrow createJsonlSessionDecodeError(\n\t\t\t\tresolvedPath,\n\t\t\t\t\"import\",\n\t\t\t\t\"schema\",\n\t\t\t\t`Cannot import empty or invalid session JSONL: ${resolvedPath}`,\n\t\t\t);\n\t\t}\n\t\tmigrateToCurrentVersion(entries);\n\t\tvalidateCurrentSessionEntries(entries, resolvedPath, {\n\t\t\tphase: \"import\",\n\t\t\tlocations: getJsonlEntryLocations(entries),\n\t\t});\n\n\t\tconst cwd = options?.cwdOverride ?? getSnapshotCwd({ id: \"\", reference: \"\", entries }, this.cwd);\n\t\tconst snapshot = validateRemoteSnapshot(\n\t\t\tawait this.client.importJsonl({\n\t\t\t\tcwd,\n\t\t\t\tprojectId: this.projectId,\n\t\t\t\tsourceName: basename(resolvedPath),\n\t\t\t\tentries,\n\t\t\t}),\n\t\t\t\"import\",\n\t\t);\n\t\treturn new RemoteSession({\n\t\t\tclient: this.client,\n\t\t\tcwd: getSnapshotCwd(snapshot, cwd),\n\t\t\tsnapshot,\n\t\t\tsessionManager: this,\n\t\t});\n\t}\n\n\tasync list(_onProgress?: SessionListProgress): Promise<SessionInfo[]> {\n\t\tconst response = await this.client.listSessions();\n\t\treturn response.sessions.map((session) => normalizeRemoteSessionInfo(session));\n\t}\n\n\tasync listAll(_onProgress?: SessionListProgress): Promise<SessionInfo[]> {\n\t\tconst response = await this.client.listSessions();\n\t\treturn response.sessions.map((session) => normalizeRemoteSessionInfo(session));\n\t}\n}\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"remote-session.d.ts","sourceRoot":"","sources":["../../../src/core/session/remote-session.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,mBAAmB,EAAE,qBAAqB,EAAE,MAAM,4BAA4B,CAAC;AAE7F,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AACvC,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC;AAE3D,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,YAAY,CAAC;AAEpD,MAAM,WAAW,oBAAoB;IACpC,MAAM,EAAE,mBAAmB,CAAC;IAC5B,GAAG,EAAE,MAAM,CAAC;IACZ,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,QAAQ,CAAC,EAAE,qBAAqB,CAAC;IACjC,cAAc,CAAC,EAAE,cAAc,CAAC;CAChC;AAED,qBAAa,aAAc,SAAQ,OAAO;IACzC,OAAO,CAAC,WAAW,CAAiC;IAEpD,YAAY,OAAO,EAAE,oBAAoB,EAYxC;IAED,SAAS,CAAC,0BAA0B,CACnC,WAAW,EAAE,MAAM,EACnB,SAAS,EAAE,MAAM,EACjB,UAAU,EAAE,MAAM,GAChB,MAAM,GAAG,SAAS,CAEpB;IAEQ,UAAU,CAAC,OAAO,CAAC,EAAE,iBAAiB,GAAG,MAAM,GAAG,SAAS,CAInE;IAED,gBAAgB,IAAI,OAAO,CAAC,IAAI,CAAC,CAEhC;IAED,gBAAgB,IAAI,OAAO,CAE1B;CACD","sourcesContent":["import type { RemoteSessionClient, RemoteSessionSnapshot } from \"./remote-session-client.ts\";\nimport { formatRemoteSessionReference } from \"./remote-session-client.ts\";\nimport { Session } from \"./session.ts\";\nimport type { SessionManager } from \"./session-manager.ts\";\nimport { RemoteSessionStore } from \"./stores/remote-session-store.ts\";\nimport type { NewSessionOptions } from \"./types.ts\";\n\nexport interface RemoteSessionOptions {\n\tclient: RemoteSessionClient;\n\tcwd: string;\n\treference?: string;\n\tsnapshot?: RemoteSessionSnapshot;\n\tsessionManager?: SessionManager;\n}\n\nexport class RemoteSession extends Session {\n\tprivate remoteStore: RemoteSessionStore | undefined;\n\n\tconstructor(options: RemoteSessionOptions) {\n\t\tconst reference =\n\t\t\toptions.reference ??\n\t\t\toptions.snapshot?.reference ??\n\t\t\t(options.snapshot ? formatRemoteSessionReference(options.snapshot.id) : undefined);\n\t\tconst store = new RemoteSessionStore({\n\t\t\tclient: options.client,\n\t\t\treference,\n\t\t\tsnapshot: options.snapshot,\n\t\t});\n\t\tsuper(options.cwd, \"\", reference, store, options.sessionManager);\n\t\tthis.remoteStore = store;\n\t}\n\n\tprotected prepareNewSessionReference(\n\t\t_sessionDir: string,\n\t\tsessionId: string,\n\t\t_timestamp: string,\n\t): string | undefined {\n\t\treturn this.getSessionReference() ?? formatRemoteSessionReference(sessionId);\n\t}\n\n\toverride newSession(options?: NewSessionOptions): string | undefined {\n\t\tconst reference = super.newSession(options);\n\t\tthis.remoteStore?.saveSnapshot();\n\t\treturn reference;\n\t}\n\n\tflushPendingSync(): Promise<void> {\n\t\treturn this.remoteStore?.flushPendingSync() ?? Promise.resolve();\n\t}\n\n\tgetLastSyncError(): unknown {\n\t\treturn this.remoteStore?.getLastSyncError();\n\t}\n}\n"]}
1
+ {"version":3,"file":"remote-session.d.ts","sourceRoot":"","sources":["../../../src/core/session/remote-session.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,mBAAmB,EAAE,qBAAqB,EAAE,MAAM,4BAA4B,CAAC;AAE7F,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AACvC,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC;AAE3D,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,YAAY,CAAC;AAEpD,MAAM,WAAW,oBAAoB;IACpC,MAAM,EAAE,mBAAmB,CAAC;IAC5B,GAAG,EAAE,MAAM,CAAC;IACZ,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,QAAQ,CAAC,EAAE,qBAAqB,CAAC;IACjC,cAAc,CAAC,EAAE,cAAc,CAAC;CAChC;AAED,qBAAa,aAAc,SAAQ,OAAO;IACzC,OAAO,CAAC,WAAW,CAAiC;IAEpD,YAAY,OAAO,EAAE,oBAAoB,EAYxC;IAED,SAAS,CAAC,0BAA0B,CACnC,WAAW,EAAE,MAAM,EACnB,SAAS,EAAE,MAAM,EACjB,UAAU,EAAE,MAAM,GAChB,MAAM,GAAG,SAAS,CAEpB;IAEQ,UAAU,CAAC,OAAO,CAAC,EAAE,iBAAiB,GAAG,MAAM,GAAG,SAAS,CAInE;IAED,gBAAgB,IAAI,OAAO,CAAC,IAAI,CAAC,CAEhC;IAED,gBAAgB,IAAI,OAAO,CAE1B;CACD"}
@@ -2,7 +2,6 @@ import { formatRemoteSessionReference } from "./remote-session-client.js";
2
2
  import { Session } from "./session.js";
3
3
  import { RemoteSessionStore } from "./stores/remote-session-store.js";
4
4
  export class RemoteSession extends Session {
5
- remoteStore;
6
5
  constructor(options) {
7
6
  const reference = options.reference ??
8
7
  options.snapshot?.reference ??
@@ -1 +1 @@
1
- {"version":3,"file":"remote-session.js","sourceRoot":"","sources":["../../../src/core/session/remote-session.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,4BAA4B,EAAE,MAAM,4BAA4B,CAAC;AAC1E,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AAEvC,OAAO,EAAE,kBAAkB,EAAE,MAAM,kCAAkC,CAAC;AAWtE,MAAM,OAAO,aAAc,SAAQ,OAAO;IACjC,WAAW,CAAiC;IAEpD,YAAY,OAA6B,EAAE;QAC1C,MAAM,SAAS,GACd,OAAO,CAAC,SAAS;YACjB,OAAO,CAAC,QAAQ,EAAE,SAAS;YAC3B,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC,CAAC,4BAA4B,CAAC,OAAO,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC;QACpF,MAAM,KAAK,GAAG,IAAI,kBAAkB,CAAC;YACpC,MAAM,EAAE,OAAO,CAAC,MAAM;YACtB,SAAS;YACT,QAAQ,EAAE,OAAO,CAAC,QAAQ;SAC1B,CAAC,CAAC;QACH,KAAK,CAAC,OAAO,CAAC,GAAG,EAAE,EAAE,EAAE,SAAS,EAAE,KAAK,EAAE,OAAO,CAAC,cAAc,CAAC,CAAC;QACjE,IAAI,CAAC,WAAW,GAAG,KAAK,CAAC;IAAA,CACzB;IAES,0BAA0B,CACnC,WAAmB,EACnB,SAAiB,EACjB,UAAkB,EACG;QACrB,OAAO,IAAI,CAAC,mBAAmB,EAAE,IAAI,4BAA4B,CAAC,SAAS,CAAC,CAAC;IAAA,CAC7E;IAEQ,UAAU,CAAC,OAA2B,EAAsB;QACpE,MAAM,SAAS,GAAG,KAAK,CAAC,UAAU,CAAC,OAAO,CAAC,CAAC;QAC5C,IAAI,CAAC,WAAW,EAAE,YAAY,EAAE,CAAC;QACjC,OAAO,SAAS,CAAC;IAAA,CACjB;IAED,gBAAgB,GAAkB;QACjC,OAAO,IAAI,CAAC,WAAW,EAAE,gBAAgB,EAAE,IAAI,OAAO,CAAC,OAAO,EAAE,CAAC;IAAA,CACjE;IAED,gBAAgB,GAAY;QAC3B,OAAO,IAAI,CAAC,WAAW,EAAE,gBAAgB,EAAE,CAAC;IAAA,CAC5C;CACD","sourcesContent":["import type { RemoteSessionClient, RemoteSessionSnapshot } from \"./remote-session-client.ts\";\nimport { formatRemoteSessionReference } from \"./remote-session-client.ts\";\nimport { Session } from \"./session.ts\";\nimport type { SessionManager } from \"./session-manager.ts\";\nimport { RemoteSessionStore } from \"./stores/remote-session-store.ts\";\nimport type { NewSessionOptions } from \"./types.ts\";\n\nexport interface RemoteSessionOptions {\n\tclient: RemoteSessionClient;\n\tcwd: string;\n\treference?: string;\n\tsnapshot?: RemoteSessionSnapshot;\n\tsessionManager?: SessionManager;\n}\n\nexport class RemoteSession extends Session {\n\tprivate remoteStore: RemoteSessionStore | undefined;\n\n\tconstructor(options: RemoteSessionOptions) {\n\t\tconst reference =\n\t\t\toptions.reference ??\n\t\t\toptions.snapshot?.reference ??\n\t\t\t(options.snapshot ? formatRemoteSessionReference(options.snapshot.id) : undefined);\n\t\tconst store = new RemoteSessionStore({\n\t\t\tclient: options.client,\n\t\t\treference,\n\t\t\tsnapshot: options.snapshot,\n\t\t});\n\t\tsuper(options.cwd, \"\", reference, store, options.sessionManager);\n\t\tthis.remoteStore = store;\n\t}\n\n\tprotected prepareNewSessionReference(\n\t\t_sessionDir: string,\n\t\tsessionId: string,\n\t\t_timestamp: string,\n\t): string | undefined {\n\t\treturn this.getSessionReference() ?? formatRemoteSessionReference(sessionId);\n\t}\n\n\toverride newSession(options?: NewSessionOptions): string | undefined {\n\t\tconst reference = super.newSession(options);\n\t\tthis.remoteStore?.saveSnapshot();\n\t\treturn reference;\n\t}\n\n\tflushPendingSync(): Promise<void> {\n\t\treturn this.remoteStore?.flushPendingSync() ?? Promise.resolve();\n\t}\n\n\tgetLastSyncError(): unknown {\n\t\treturn this.remoteStore?.getLastSyncError();\n\t}\n}\n"]}
1
+ {"version":3,"file":"remote-session.js","sourceRoot":"","sources":["../../../src/core/session/remote-session.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,4BAA4B,EAAE,MAAM,4BAA4B,CAAC;AAC1E,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AAEvC,OAAO,EAAE,kBAAkB,EAAE,MAAM,kCAAkC,CAAC;AAWtE,MAAM,OAAO,aAAc,SAAQ,OAAO;IAGzC,YAAY,OAA6B;QACxC,MAAM,SAAS,GACd,OAAO,CAAC,SAAS;YACjB,OAAO,CAAC,QAAQ,EAAE,SAAS;YAC3B,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC,CAAC,4BAA4B,CAAC,OAAO,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC;QACpF,MAAM,KAAK,GAAG,IAAI,kBAAkB,CAAC;YACpC,MAAM,EAAE,OAAO,CAAC,MAAM;YACtB,SAAS;YACT,QAAQ,EAAE,OAAO,CAAC,QAAQ;SAC1B,CAAC,CAAC;QACH,KAAK,CAAC,OAAO,CAAC,GAAG,EAAE,EAAE,EAAE,SAAS,EAAE,KAAK,EAAE,OAAO,CAAC,cAAc,CAAC,CAAC;QACjE,IAAI,CAAC,WAAW,GAAG,KAAK,CAAC;IAC1B,CAAC;IAES,0BAA0B,CACnC,WAAmB,EACnB,SAAiB,EACjB,UAAkB;QAElB,OAAO,IAAI,CAAC,mBAAmB,EAAE,IAAI,4BAA4B,CAAC,SAAS,CAAC,CAAC;IAC9E,CAAC;IAEQ,UAAU,CAAC,OAA2B;QAC9C,MAAM,SAAS,GAAG,KAAK,CAAC,UAAU,CAAC,OAAO,CAAC,CAAC;QAC5C,IAAI,CAAC,WAAW,EAAE,YAAY,EAAE,CAAC;QACjC,OAAO,SAAS,CAAC;IAClB,CAAC;IAED,gBAAgB;QACf,OAAO,IAAI,CAAC,WAAW,EAAE,gBAAgB,EAAE,IAAI,OAAO,CAAC,OAAO,EAAE,CAAC;IAClE,CAAC;IAED,gBAAgB;QACf,OAAO,IAAI,CAAC,WAAW,EAAE,gBAAgB,EAAE,CAAC;IAC7C,CAAC;CACD","sourcesContent":["import type { RemoteSessionClient, RemoteSessionSnapshot } from \"./remote-session-client.ts\";\nimport { formatRemoteSessionReference } from \"./remote-session-client.ts\";\nimport { Session } from \"./session.ts\";\nimport type { SessionManager } from \"./session-manager.ts\";\nimport { RemoteSessionStore } from \"./stores/remote-session-store.ts\";\nimport type { NewSessionOptions } from \"./types.ts\";\n\nexport interface RemoteSessionOptions {\n\tclient: RemoteSessionClient;\n\tcwd: string;\n\treference?: string;\n\tsnapshot?: RemoteSessionSnapshot;\n\tsessionManager?: SessionManager;\n}\n\nexport class RemoteSession extends Session {\n\tprivate remoteStore: RemoteSessionStore | undefined;\n\n\tconstructor(options: RemoteSessionOptions) {\n\t\tconst reference =\n\t\t\toptions.reference ??\n\t\t\toptions.snapshot?.reference ??\n\t\t\t(options.snapshot ? formatRemoteSessionReference(options.snapshot.id) : undefined);\n\t\tconst store = new RemoteSessionStore({\n\t\t\tclient: options.client,\n\t\t\treference,\n\t\t\tsnapshot: options.snapshot,\n\t\t});\n\t\tsuper(options.cwd, \"\", reference, store, options.sessionManager);\n\t\tthis.remoteStore = store;\n\t}\n\n\tprotected prepareNewSessionReference(\n\t\t_sessionDir: string,\n\t\tsessionId: string,\n\t\t_timestamp: string,\n\t): string | undefined {\n\t\treturn this.getSessionReference() ?? formatRemoteSessionReference(sessionId);\n\t}\n\n\toverride newSession(options?: NewSessionOptions): string | undefined {\n\t\tconst reference = super.newSession(options);\n\t\tthis.remoteStore?.saveSnapshot();\n\t\treturn reference;\n\t}\n\n\tflushPendingSync(): Promise<void> {\n\t\treturn this.remoteStore?.flushPendingSync() ?? Promise.resolve();\n\t}\n\n\tgetLastSyncError(): unknown {\n\t\treturn this.remoteStore?.getLastSyncError();\n\t}\n}\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"session-manager.d.ts","sourceRoot":"","sources":["../../../src/core/session/session-manager.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AAC5C,OAAO,KAAK,EAAE,iBAAiB,EAAE,WAAW,EAAE,mBAAmB,EAAE,MAAM,YAAY,CAAC;AAEtF,MAAM,MAAM,aAAa,GAAG,OAAO,GAAG,OAAO,CAAC,OAAO,CAAC,CAAC;AAEvD,MAAM,WAAW,kBAAkB;IAClC,WAAW,CAAC,EAAE,MAAM,CAAC;CACrB;AAED,MAAM,WAAW,cAAc;IAC9B,MAAM,CAAC,OAAO,CAAC,EAAE,iBAAiB,GAAG,aAAa,CAAC;IACnD,aAAa,CAAC,SAAS,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,kBAAkB,GAAG,aAAa,CAAC;IAC9E,cAAc,IAAI,aAAa,CAAC;IAChC,QAAQ,CAAC,SAAS,EAAE,MAAM,GAAG,aAAa,CAAC;IAC3C,WAAW,CAAC,MAAM,EAAE,OAAO,EAAE,YAAY,EAAE,MAAM,GAAG,IAAI,GAAG,aAAa,CAAC;IACzE,WAAW,CAAC,SAAS,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,kBAAkB,GAAG,aAAa,CAAC;IAC5E,IAAI,CAAC,UAAU,CAAC,EAAE,mBAAmB,GAAG,OAAO,CAAC,WAAW,EAAE,CAAC,CAAC;IAC/D,OAAO,CAAC,UAAU,CAAC,EAAE,mBAAmB,GAAG,OAAO,CAAC,WAAW,EAAE,CAAC,CAAC;IAClE,qBAAqB,CAAC,IAAI,OAAO,CAAC;CAClC","sourcesContent":["import type { Session } from \"./session.ts\";\nimport type { NewSessionOptions, SessionInfo, SessionListProgress } from \"./types.ts\";\n\nexport type SessionResult = Session | Promise<Session>;\n\nexport interface OpenSessionOptions {\n\tcwdOverride?: string;\n}\n\nexport interface SessionManager {\n\tcreate(options?: NewSessionOptions): SessionResult;\n\topenReference(reference: string, options?: OpenSessionOptions): SessionResult;\n\tcontinueRecent(): SessionResult;\n\tforkFrom(reference: string): SessionResult;\n\tforkSession(source: Session, targetLeafId: string | null): SessionResult;\n\timportJsonl(inputPath: string, options?: OpenSessionOptions): SessionResult;\n\tlist(onProgress?: SessionListProgress): Promise<SessionInfo[]>;\n\tlistAll(onProgress?: SessionListProgress): Promise<SessionInfo[]>;\n\tusesDefaultSessionDir?(): boolean;\n}\n"]}
1
+ {"version":3,"file":"session-manager.d.ts","sourceRoot":"","sources":["../../../src/core/session/session-manager.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AAC5C,OAAO,KAAK,EAAE,iBAAiB,EAAE,WAAW,EAAE,mBAAmB,EAAE,MAAM,YAAY,CAAC;AAEtF,MAAM,MAAM,aAAa,GA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AAS,CAEvC;IAED;;;;OAIG;IACH,iBAAiB,CAAC,QAAQ,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,SAAS,GAAG,MAAM,CAcrE;IAED;;;;OAIG;IACH,SAAS,CAAC,MAAM,CAAC,EAAE,MAAM,GAAG,YAAY,EAAE,CAEzC;IAED;;;OAGG;IACH,mBAAmB,IAAI,cAAc,CAEpC;IAED;;OAEG;IACH,SAAS,IAAI,aAAa,GAAG,IAAI,CAEhC;IAED;;;;OAIG;IACH,UAAU,IAAI,YAAY,EAAE,CAE3B;IAED;;;;OAIG;IACH,OAAO,IAAI,eAAe,EAAE,CAE3B;IAMD;;;;;OAKG;IACH,MAAM,CAAC,YAAY,EAAE,MAAM,GAAG,IAAI,CAKjC;IAED;;;;OAIG;IACH,SAAS,IAAI,IAAI,CAEhB;IAED;;;;OAIG;IACH,iBAAiB,CAAC,YAAY,EAAE,MAAM,GAAG,IAAI,EAAE,OAAO,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,OAAO,EAAE,QAAQ,CAAC,EAAE,OAAO,GAAG,MAAM,CAiB7G;IAED;;;;OAIG;IACH,qBAAqB,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,CAiDxD;IAED,cAAc,CAAC,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,aAAa,CAAC,EAAE,MAAM,GAAG,IAAI,CAgC5E;IAED,gBAAgB,CAAC,OAAO,CAAC,EAAE,iBAAiB,GAAG,aAAa,CAQ3D;IAED,cAAc,CAAC,YAAY,EAAE,MAAM,GAAG,IAAI,GAAG,aAAa,CAKzD;CACD","sourcesContent":["import { statSync } from \"node:fs\";\nimport type { ImageContent, Message, TextContent } from \"@greppleai/grip-ai\";\nimport type { BashExecutionMessage, CustomMessage } from \"../messages.ts\";\nimport { CURRENT_SESSION_VERSION } from \"./constants.ts\";\nimport { buildSessionContext } from \"./context.ts\";\nimport { createSessionId, generateId, validateSessionId } from \"./ids.ts\";\nimport { migrateToCurrentVersion } from \"./migrations.ts\";\nimport type { SessionManager, SessionResult } from \"./session-manager.ts\";\nimport { getJsonlEntryLocations, validateCurrentSessionEntries } from \"./stores/jsonl-session-store.ts\";\nimport type { SessionStore } from \"./stores/session-store.ts\";\nimport type {\n\tBranchSummaryEntry,\n\tCompactionEntry,\n\tCustomEntry,\n\tCustomMessageEntry,\n\tLabelEntry,\n\tModelChangeEntry,\n\tNewSessionOptions,\n\tSessionContext,\n\tSessionEntry,\n\tSessionHeader,\n\tSessionInfoEntry,\n\tSessionMessageEntry,\n\tSessionTreeNode,\n\tThinkingLevelChangeEntry,\n} from \"./types.ts\";\n\nexport type ReadonlySession = Pick<\n\tSession,\n\t| \"getCwd\"\n\t| \"getSessionDir\"\n\t| \"getSessionId\"\n\t| \"getSessionReference\"\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>;\n\n/**\n * Represents one active conversation session as an append-only tree.\n *\n * Each session entry has an id and parentId forming a tree structure. The \"leaf\"\n * pointer tracks the current position. Appending creates a child of the current leaf.\n * Branching moves the leaf to an earlier entry, allowing new branches without\n * modifying history.\n *\n * Use buildSessionContext() to get the resolved message list for the LLM, which\n * handles compaction summaries and follows the path from root to current leaf.\n */\nexport abstract class Session {\n\tprivate sessionId: string = \"\";\n\tprivate sessionDir: string;\n\tprivate cwd: string;\n\tprivate store: SessionStore;\n\tprivate sessionManager: SessionManager | undefined;\n\n\tprotected constructor(\n\t\tcwd: string,\n\t\tsessionDir: string,\n\t\tsessionReference: string | undefined,\n\t\tstore: SessionStore,\n\t\tsessionManager?: SessionManager,\n\t) {\n\t\tthis.cwd = cwd;\n\t\tthis.sessionDir = sessionDir;\n\t\tthis.store = store;\n\t\tthis.sessionManager = sessionManager;\n\t\tif (sessionDir) {\n\t\t\tthis.store.ensureDir(sessionDir);\n\t\t}\n\n\t\tif (sessionReference) {\n\t\t\tthis.setSessionReference(sessionReference);\n\t\t} else {\n\t\t\tthis.newSession();\n\t\t}\n\t}\n\n\tprotected abstract prepareNewSessionReference(\n\t\tsessionDir: string,\n\t\tsessionId: string,\n\t\ttimestamp: string,\n\t): string | undefined;\n\n\t/** Switch to a different session reference (used for resume and branching). */\n\tsetSessionReference(sessionReference: string): void {\n\t\tthis.store.setSessionReference(sessionReference);\n\t\tif (this.store.exists(sessionReference)) {\n\t\t\tthis.store.setEntries(this.store.load(sessionReference));\n\n\t\t\t// If the file is empty, initialize it with a valid session header. If it was\n\t\t\t// non-empty but did not parse as a grip session, fail without modifying it.\n\t\t\tif (this.store.getFileEntries().length === 0) {\n\t\t\t\tif (statSync(sessionReference).size > 0) {\n\t\t\t\t\tthrow new Error(`Session file is not a valid grip session: ${sessionReference}`);\n\t\t\t\t}\n\t\t\t\tthis.newSession();\n\t\t\t\tthis.store.setSessionReference(sessionReference, { allowExistingEmptyFile: true });\n\t\t\t\tthis.store.saveSnapshot();\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tconst header = this.store.getHeader();\n\t\t\tthis.sessionId = header?.id ?? createSessionId();\n\n\t\t\tconst entries = this.store.getFileEntries();\n\t\t\tif (migrateToCurrentVersion(entries)) {\n\t\t\t\tvalidateCurrentSessionEntries(entries, sessionReference, {\n\t\t\t\t\tphase: \"migrate\",\n\t\t\t\t\tlocations: getJsonlEntryLocations(entries),\n\t\t\t\t});\n\t\t\t\tthis.store.setEntries(entries);\n\t\t\t\tthis.store.saveSnapshot({ phase: \"migrate\" });\n\t\t\t}\n\t\t} else {\n\t\t\tthis.newSession();\n\t\t\tthis.store.setSessionReference(sessionReference); // preserve explicit reference from --session flag\n\t\t}\n\t}\n\n\tnewSession(options?: NewSessionOptions): string | undefined {\n\t\tthis.sessionId = options?.id ?? createSessionId();\n\t\tvalidateSessionId(this.sessionId);\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\tconst sessionReference = this.prepareNewSessionReference(this.getSessionDir(), this.sessionId, timestamp);\n\t\tif (sessionReference) {\n\t\t\tthis.store.setSessionReference(sessionReference);\n\t\t}\n\t\tthis.store.setEntries([header]);\n\t\treturn sessionReference;\n\t}\n\n\tisPersisted(): boolean {\n\t\treturn this.store.isPersisted();\n\t}\n\n\tgetCwd(): string {\n\t\treturn this.cwd;\n\t}\n\n\t/** Update the active runtime cwd without rewriting the session's original header. */\n\tsetCwd(cwd: string): void {\n\t\tthis.cwd = cwd;\n\t}\n\n\tgetSessionDir(): string {\n\t\treturn this.sessionDir;\n\t}\n\n\tgetSessionId(): string {\n\t\treturn this.sessionId;\n\t}\n\n\tgetSessionReference(): string | undefined {\n\t\treturn this.store.getSessionReference();\n\t}\n\n\tprivate _appendEntry(entry: SessionEntry): void {\n\t\tthis.store.appendEntry(entry);\n\t}\n\n\t/** Copy a preserved suffix onto a new branch without mutating the archived entries. */\n\tappendReplayedEntry(entry: SessionEntry, ids: ReadonlyMap<string, string>): string {\n\t\tif (entry.type === \"compaction\") throw new Error(\"Cannot replay a compaction boundary\");\n\t\tconst id = generateId(this.store);\n\t\tconst base = { id, parentId: this.store.getLeafId(), timestamp: new Date().toISOString() };\n\t\tconst replayed: SessionEntry =\n\t\t\tentry.type === \"label\"\n\t\t\t\t? { ...entry, ...base, targetId: ids.get(entry.targetId) ?? entry.targetId }\n\t\t\t\t: entry.type === \"branch_summary\"\n\t\t\t\t\t? { ...entry, ...base, fromId: ids.get(entry.fromId) ?? entry.fromId }\n\t\t\t\t\t: entry.type === \"message\"\n\t\t\t\t\t\t? { ...entry, ...base, replayedFromId: entry.replayedFromId ?? entry.id }\n\t\t\t\t\t\t: { ...entry, ...base };\n\t\tthis._appendEntry(replayed);\n\t\treturn id;\n\t}\n\n\t/** Append a message as child of current leaf, then advance leaf. Returns entry id.\n\t * Does not allow writing CompactionSummaryMessage and BranchSummaryMessage directly.\n\t * Reason: we want these to be top-level entries in the session, not message session entries,\n\t * so it is easier to find them.\n\t * These need to be appended via appendCompaction() and appendBranchSummary() methods.\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.store),\n\t\t\tparentId: this.store.getLeafId(),\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\n\t/** Append a thinking level change as child of current leaf, then advance leaf. Returns entry id. */\n\tappendThinkingLevelChange(thinkingLevel: string): string {\n\t\tconst entry: ThinkingLevelChangeEntry = {\n\t\t\ttype: \"thinking_level_change\",\n\t\t\tid: generateId(this.store),\n\t\t\tparentId: this.store.getLeafId(),\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\n\t/** Append a model change as child of current leaf, then advance leaf. Returns entry id. */\n\tappendModelChange(provider: string, modelId: string): string {\n\t\tconst entry: ModelChangeEntry = {\n\t\t\ttype: \"model_change\",\n\t\t\tid: generateId(this.store),\n\t\t\tparentId: this.store.getLeafId(),\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\n\t/** Append a compaction summary as child of current leaf, then advance leaf. Returns entry id. */\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.store),\n\t\t\tparentId: this.store.getLeafId(),\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\n\t/** Append a custom entry (for extensions) as child of current leaf, then advance leaf. Returns entry id. */\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.store),\n\t\t\tparentId: this.store.getLeafId(),\n\t\t\ttimestamp: new Date().toISOString(),\n\t\t};\n\t\tthis._appendEntry(entry);\n\t\treturn entry.id;\n\t}\n\n\t/** Append a session info entry (e.g., display name). Returns entry id. */\n\tappendSessionInfo(name: string): string {\n\t\tconst entry: SessionInfoEntry = {\n\t\t\ttype: \"session_info\",\n\t\t\tid: generateId(this.store),\n\t\t\tparentId: this.store.getLeafId(),\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\n\t/** Get the current session name from the latest session_info entry, if any. */\n\tgetSessionName(): string | undefined {\n\t\treturn this.store.getSessionName();\n\t}\n\n\t/**\n\t * Append a custom message entry (for extensions) that participates in LLM context.\n\t * @param customType Extension identifier for filtering on reload\n\t * @param content Message content (string or TextContent/ImageContent array)\n\t * @param display Whether to show in TUI (true = styled display, false = hidden)\n\t * @param details Optional extension-specific metadata (not sent to LLM)\n\t * @returns Entry id\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.store),\n\t\t\tparentId: this.store.getLeafId(),\n\t\t\ttimestamp: new Date().toISOString(),\n\t\t};\n\t\tthis._appendEntry(entry);\n\t\treturn entry.id;\n\t}\n\n\t// =========================================================================\n\t// Tree Traversal\n\t// =========================================================================\n\n\tgetLeafId(): string | null {\n\t\treturn this.store.getLeafId();\n\t}\n\n\tgetLeafEntry(): SessionEntry | undefined {\n\t\treturn this.store.getLeafEntry();\n\t}\n\n\tgetEntry(id: string): SessionEntry | undefined {\n\t\treturn this.store.getEntry(id);\n\t}\n\n\t/**\n\t * Get all direct children of an entry.\n\t */\n\tgetChildren(parentId: string): SessionEntry[] {\n\t\treturn this.store.getChildren(parentId);\n\t}\n\n\t/**\n\t * Get the label for an entry, if any.\n\t */\n\tgetLabel(id: string): string | undefined {\n\t\treturn this.store.getLabel(id);\n\t}\n\n\t/**\n\t * Set or clear a label on an entry.\n\t * Labels are user-defined markers for bookmarking/navigation.\n\t * Pass undefined or empty string to clear the label.\n\t */\n\tappendLabelChange(targetId: string, label: string | undefined): string {\n\t\tif (!this.store.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.store),\n\t\t\tparentId: this.store.getLeafId(),\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\treturn entry.id;\n\t}\n\n\t/**\n\t * Walk from entry to root, returning all entries in path order.\n\t * Includes all entry types (messages, compaction, model changes, etc.).\n\t * Use buildSessionContext() to get the resolved messages for the LLM.\n\t */\n\tgetBranch(fromId?: string): SessionEntry[] {\n\t\treturn this.store.getBranch(fromId);\n\t}\n\n\t/**\n\t * Build the session context (what gets sent to the LLM).\n\t * Uses tree traversal from current leaf.\n\t */\n\tbuildSessionContext(): SessionContext {\n\t\treturn buildSessionContext(this.getEntries(), this.store.getLeafId(), this.store.getEntryIndex());\n\t}\n\n\t/**\n\t * Get session header.\n\t */\n\tgetHeader(): SessionHeader | null {\n\t\treturn this.store.getHeader();\n\t}\n\n\t/**\n\t * Get all session entries (excludes header). Returns a shallow copy.\n\t * The session is append-only: use appendXXX() to add entries, branch() to\n\t * change the leaf pointer. Entries cannot be modified or deleted.\n\t */\n\tgetEntries(): SessionEntry[] {\n\t\treturn this.store.getEntries();\n\t}\n\n\t/**\n\t * Get the session as a tree structure. Returns a shallow defensive copy of all entries.\n\t * A well-formed session has exactly one root (first entry with parentId === null).\n\t * Orphaned entries (broken parent chain) are also returned as roots.\n\t */\n\tgetTree(): SessionTreeNode[] {\n\t\treturn this.store.getTree();\n\t}\n\n\t// =========================================================================\n\t// Branching\n\t// =========================================================================\n\n\t/**\n\t * Start a new branch from an earlier entry.\n\t * Moves the leaf pointer to the specified entry. The next appendXXX() call\n\t * will create a child of that entry, forming a new branch. Existing entries\n\t * are not modified or deleted.\n\t */\n\tbranch(branchFromId: string): void {\n\t\tif (!this.store.has(branchFromId)) {\n\t\t\tthrow new Error(`Entry ${branchFromId} not found`);\n\t\t}\n\t\tthis.store.setLeafId(branchFromId);\n\t}\n\n\t/**\n\t * Reset the leaf pointer to null (before any entries).\n\t * The next appendXXX() call will create a new root entry (parentId = null).\n\t * Use this when navigating to re-edit the first user message.\n\t */\n\tresetLeaf(): void {\n\t\tthis.store.setLeafId(null);\n\t}\n\n\t/**\n\t * Start a new branch with a summary of the abandoned path.\n\t * Same as branch(), but also appends a branch_summary entry that captures\n\t * context from the abandoned conversation path.\n\t */\n\tbranchWithSummary(branchFromId: string | null, summary: string, details?: unknown, fromHook?: boolean): string {\n\t\tif (branchFromId !== null && !this.store.has(branchFromId)) {\n\t\t\tthrow new Error(`Entry ${branchFromId} not found`);\n\t\t}\n\t\tthis.store.setLeafId(branchFromId);\n\t\tconst entry: BranchSummaryEntry = {\n\t\t\ttype: \"branch_summary\",\n\t\t\tid: generateId(this.store),\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\n\t/**\n\t * Create a new session reference containing only the path from root to the specified leaf.\n\t * Useful for extracting a single conversation path from a branched session.\n\t * Returns the new session reference, or undefined if the store does not expose one.\n\t */\n\tcreateBranchedSession(leafId: string): string | undefined {\n\t\tconst parentSession = this.getSessionReference();\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\n\t\t// Filter out LabelEntry from path - we'll recreate them from the resolved map\n\t\tconst pathWithoutLabels = path.filter((e) => e.type !== \"label\");\n\n\t\tconst newSessionId = createSessionId();\n\t\tconst timestamp = new Date().toISOString();\n\t\tconst newSessionReference = this.prepareNewSessionReference(this.getSessionDir(), newSessionId, timestamp);\n\t\tif (newSessionReference) {\n\t\t\tthis.store.setSessionReference(newSessionReference);\n\t\t}\n\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,\n\t\t};\n\n\t\t// Collect labels for entries in the path\n\t\tconst pathEntryIds = new Set(pathWithoutLabels.map((e) => e.id));\n\t\tconst labelsToWrite = this.store.getLabelsForEntryIds(pathEntryIds);\n\n\t\tconst labelEntries: LabelEntry[] = [];\n\t\tlet parentId = pathWithoutLabels[pathWithoutLabels.length - 1]?.id || null;\n\t\tfor (const { targetId, label, timestamp: labelTimestamp } of labelsToWrite) {\n\t\t\tconst labelEntry: LabelEntry = {\n\t\t\t\ttype: \"label\",\n\t\t\t\tid: generateId(pathEntryIds),\n\t\t\t\tparentId,\n\t\t\t\ttimestamp: labelTimestamp,\n\t\t\t\ttargetId,\n\t\t\t\tlabel,\n\t\t\t};\n\t\t\tpathEntryIds.add(labelEntry.id);\n\t\t\tlabelEntries.push(labelEntry);\n\t\t\tparentId = labelEntry.id;\n\t\t}\n\t\tthis.store.setEntries([header, ...pathWithoutLabels, ...labelEntries]);\n\t\tthis.sessionId = newSessionId;\n\t\tthis.store.commitSnapshot();\n\t\treturn newSessionReference;\n\t}\n\n\tcopyBranchFrom(source: Session, leafId: string, parentSession?: string): void {\n\t\tconst path = source.getBranch(leafId);\n\t\tif (path.length === 0) {\n\t\t\tthrow new Error(`Entry ${leafId} not found`);\n\t\t}\n\n\t\tconst header = this.getHeader();\n\t\tif (!header) {\n\t\t\tthrow new Error(\"Target session has no header\");\n\t\t}\n\n\t\tconst pathWithoutLabels = structuredClone(path.filter((entry) => entry.type !== \"label\"));\n\t\tconst pathEntryIds = new Set(pathWithoutLabels.map((entry) => entry.id));\n\t\tconst labelsToWrite = source.store.getLabelsForEntryIds(pathEntryIds);\n\t\tconst labelEntries: LabelEntry[] = [];\n\t\tlet nextParentId = pathWithoutLabels[pathWithoutLabels.length - 1]?.id ?? null;\n\t\tfor (const { targetId, label, timestamp } of labelsToWrite) {\n\t\t\tconst labelEntry: LabelEntry = {\n\t\t\t\ttype: \"label\",\n\t\t\t\tid: generateId(pathEntryIds),\n\t\t\t\tparentId: nextParentId,\n\t\t\t\ttimestamp,\n\t\t\t\ttargetId,\n\t\t\t\tlabel,\n\t\t\t};\n\t\t\tpathEntryIds.add(labelEntry.id);\n\t\t\tlabelEntries.push(labelEntry);\n\t\t\tnextParentId = labelEntry.id;\n\t\t}\n\n\t\tthis.store.setEntries([{ ...header, parentSession }, ...pathWithoutLabels, ...labelEntries]);\n\t\tthis.store.commitSnapshot();\n\t}\n\n\tcreateSubSession(options?: NewSessionOptions): SessionResult {\n\t\tif (!this.sessionManager) {\n\t\t\tthrow new Error(\"Session manager unavailable\");\n\t\t}\n\t\treturn this.sessionManager.create({\n\t\t\t...options,\n\t\t\tparentSession: options?.parentSession ?? this.getSessionReference(),\n\t\t});\n\t}\n\n\tforkSubSession(targetLeafId: string | null): SessionResult {\n\t\tif (!this.sessionManager) {\n\t\t\tthrow new Error(\"Session manager unavailable\");\n\t\t}\n\t\treturn this.sessionManager.forkSession(this, targetLeafId);\n\t}\n}\n"]}
1
+ {"version":3,"file":"session.d.ts","sourceRoot":"","sources":["../../../src/core/session/session.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,YAAY,EAAE,OAAO,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;AAC7E,OAAO,KAAK,EAAE,oBAAoB,EAAE,aAAa,EAAE,MAAM,gBAAgB,CAAC;AAK1E,OAAO,KAAK,EAAE,cAAc,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC;AAE1E,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,2BAA2B,CAAC;AAC9D,OAAO,KAAK,EAOX,iBAAiB,EACjB,cAAc,EACd,YAAY,EACZ,aAAa,EAGb,eAAe,EAEf,MAAM,YAAY,CAAC;AAEpB,MAAM,MAAM,eAAe,GAAG,IAAI,CACjC,OAAO,EACL,QAAQ,GACR,eAAe,GACf,cAAc,GACd,qBAAqB,GACrB,WAAW,GACX,cAAc,GACd,UAAU,GACV,UAAU,GACV,WAAW,GACX,WAAW,GACX,YAAY,GACZ,SAAS,GACT,gBAAgB,CAClB,CAAC;AAEF;;;;;;;;;;GAUG;AACH,8BAAsB,OAAO;IAC5B,OAAO,CAAC,SAAS,CAAc;IAC/B,OAAO,CAAC,UAAU,CAAS;IAC3B,OAAO,CAAC,GAAG,CAAS;IACpB,OAAO,CAAC,KAAK,CAAe;IAC5B,OAAO,CAAC,cAAc,CAA6B;IAEnD,SAAS,aACR,GAAG,EAAE,MAAM,EACX,UAAU,EAAE,MAAM,EAClB,gBAAgB,EAAE,MAAM,GAAG,SAAS,EACpC,KAAK,EAAE,YAAY,EACnB,cAAc,CAAC,EAAE,cAAc,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,IAAI,EAAE,OAAO,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,OAAO,EAAE,QAAQ,CAAC,EAAE,OAAO,GAAG,MAAM,CAiB7G;IAED;;;;OAIG;IACH,qBAAqB,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,CAiDxD;IAED,cAAc,CAAC,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,aAAa,CAAC,EAAE,MAAM,GAAG,IAAI,CAgC5E;IAED,gBAAgB,CAAC,OAAO,CAAC,EAAE,iBAAiB,GAAG,aAAa,CAQ3D;IAED,cAAc,CAAC,YAAY,EAAE,MAAM,GAAG,IAAI,GAAG,aAAa,CAKzD;CACD"}
@@ -16,12 +16,8 @@ import { getJsonlEntryLocations, validateCurrentSessionEntries } from "./stores/
16
16
  * handles compaction summaries and follows the path from root to current leaf.
17
17
  */
18
18
  export class Session {
19
- sessionId = "";
20
- sessionDir;
21
- cwd;
22
- store;
23
- sessionManager;
24
19
  constructor(cwd, sessionDir, sessionReference, store, sessionManager) {
20
+ this.sessionId = "";
25
21
  this.cwd = cwd;
26
22
  this.sessionDir = sessionDir;
27
23
  this.store = store;
@@ -1 +1 @@
1
- {"version":3,"file":"session.js","sourceRoot":"","sources":["../../../src/core/session/session.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AAGnC,OAAO,EAAE,uBAAuB,EAAE,MAAM,gBAAgB,CAAC;AACzD,OAAO,EAAE,mBAAmB,EAAE,MAAM,cAAc,CAAC;AACnD,OAAO,EAAE,eAAe,EAAE,UAAU,EAAE,iBAAiB,EAAE,MAAM,UAAU,CAAC;AAC1E,OAAO,EAAE,uBAAuB,EAAE,MAAM,iBAAiB,CAAC;AAE1D,OAAO,EAAE,sBAAsB,EAAE,6BAA6B,EAAE,MAAM,iCAAiC,CAAC;AAoCxG;;;;;;;;;;GAUG;AACH,MAAM,OAAgB,OAAO;IACpB,SAAS,GAAW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R,KAAK;aACL,CAAC;YACF,YAAY,CAAC,GAAG,CAAC,UAAU,CAAC,EAAE,CAAC,CAAC;YAChC,YAAY,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC;YAC9B,YAAY,GAAG,UAAU,CAAC,EAAE,CAAC;QAC9B,CAAC;QAED,IAAI,CAAC,KAAK,CAAC,UAAU,CAAC,CAAC,EAAE,GAAG,MAAM,EAAE,aAAa,EAAE,EAAE,GAAG,iBAAiB,EAAE,GAAG,YAAY,CAAC,CAAC,CAAC;QAC7F,IAAI,CAAC,KAAK,CAAC,cAAc,EAAE,CAAC;IAAA,CAC5B;IAED,gBAAgB,CAAC,OAA2B,EAAiB;QAC5D,IAAI,CAAC,IAAI,CAAC,cAAc,EAAE,CAAC;YAC1B,MAAM,IAAI,KAAK,CAAC,6BAA6B,CAAC,CAAC;QAChD,CAAC;QACD,OAAO,IAAI,CAAC,cAAc,CAAC,MAAM,CAAC;YACjC,GAAG,OAAO;YACV,aAAa,EAAE,OAAO,EAAE,aAAa,IAAI,IAAI,CAAC,mBAAmB,EAAE;SACnE,CAAC,CAAC;IAAA,CACH;IAED,cAAc,CAAC,YAA2B,EAAiB;QAC1D,IAAI,CAAC,IAAI,CAAC,cAAc,EAAE,CAAC;YAC1B,MAAM,IAAI,KAAK,CAAC,6BAA6B,CAAC,CAAC;QAChD,CAAC;QACD,OAAO,IAAI,CAAC,cAAc,CAAC,WAAW,CAAC,IAAI,EAAE,YAAY,CAAC,CAAC;IAAA,CAC3D;CACD","sourcesContent":["import { statSync } from \"node:fs\";\nimport type { ImageContent, Message, TextContent } from \"@greppleai/grip-ai\";\nimport type { BashExecutionMessage, CustomMessage } from \"../messages.ts\";\nimport { CURRENT_SESSION_VERSION } from \"./constants.ts\";\nimport { buildSessionContext } from \"./context.ts\";\nimport { createSessionId, generateId, validateSessionId } from \"./ids.ts\";\nimport { migrateToCurrentVersion } from \"./migrations.ts\";\nimport type { SessionManager, SessionResult } from \"./session-manager.ts\";\nimport { getJsonlEntryLocations, validateCurrentSessionEntries } from \"./stores/jsonl-session-store.ts\";\nimport type { SessionStore } from \"./stores/session-store.ts\";\nimport type {\n\tBranchSummaryEntry,\n\tCompactionEntry,\n\tCustomEntry,\n\tCustomMessageEntry,\n\tLabelEntry,\n\tModelChangeEntry,\n\tNewSessionOptions,\n\tSessionContext,\n\tSessionEntry,\n\tSessionHeader,\n\tSessionInfoEntry,\n\tSessionMessageEntry,\n\tSessionTreeNode,\n\tThinkingLevelChangeEntry,\n} from \"./types.ts\";\n\nexport type ReadonlySession = Pick<\n\tSession,\n\t| \"getCwd\"\n\t| \"getSessionDir\"\n\t| \"getSessionId\"\n\t| \"getSessionReference\"\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>;\n\n/**\n * Represents one active conversation session as an append-only tree.\n *\n * Each session entry has an id and parentId forming a tree structure. The \"leaf\"\n * pointer tracks the current position. Appending creates a child of the current leaf.\n * Branching moves the leaf to an earlier entry, allowing new branches without\n * modifying history.\n *\n * Use buildSessionContext() to get the resolved message list for the LLM, which\n * handles compaction summaries and follows the path from root to current leaf.\n */\nexport abstract class Session {\n\tprivate sessionId: string = \"\";\n\tprivate sessionDir: string;\n\tprivate cwd: string;\n\tprivate store: SessionStore;\n\tprivate sessionManager: SessionManager | undefined;\n\n\tprotected constructor(\n\t\tcwd: string,\n\t\tsessionDir: string,\n\t\tsessionReference: string | undefined,\n\t\tstore: SessionStore,\n\t\tsessionManager?: SessionManager,\n\t) {\n\t\tthis.cwd = cwd;\n\t\tthis.sessionDir = sessionDir;\n\t\tthis.store = store;\n\t\tthis.sessionManager = sessionManager;\n\t\tif (sessionDir) {\n\t\t\tthis.store.ensureDir(sessionDir);\n\t\t}\n\n\t\tif (sessionReference) {\n\t\t\tthis.setSessionReference(sessionReference);\n\t\t} else {\n\t\t\tthis.newSession();\n\t\t}\n\t}\n\n\tprotected abstract prepareNewSessionReference(\n\t\tsessionDir: string,\n\t\tsessionId: string,\n\t\ttimestamp: string,\n\t): string | undefined;\n\n\t/** Switch to a different session reference (used for resume and branching). */\n\tsetSessionReference(sessionReference: string): void {\n\t\tthis.store.setSessionReference(sessionReference);\n\t\tif (this.store.exists(sessionReference)) {\n\t\t\tthis.store.setEntries(this.store.load(sessionReference));\n\n\t\t\t// If the file is empty, initialize it with a valid session header. If it was\n\t\t\t// non-empty but did not parse as a grip session, fail without modifying it.\n\t\t\tif (this.store.getFileEntries().length === 0) {\n\t\t\t\tif (statSync(sessionReference).size > 0) {\n\t\t\t\t\tthrow new Error(`Session file is not a valid grip session: ${sessionReference}`);\n\t\t\t\t}\n\t\t\t\tthis.newSession();\n\t\t\t\tthis.store.setSessionReference(sessionReference, { allowExistingEmptyFile: true });\n\t\t\t\tthis.store.saveSnapshot();\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tconst header = this.store.getHeader();\n\t\t\tthis.sessionId = header?.id ?? createSessionId();\n\n\t\t\tconst entries = this.store.getFileEntries();\n\t\t\tif (migrateToCurrentVersion(entries)) {\n\t\t\t\tvalidateCurrentSessionEntries(entries, sessionReference, {\n\t\t\t\t\tphase: \"migrate\",\n\t\t\t\t\tlocations: getJsonlEntryLocations(entries),\n\t\t\t\t});\n\t\t\t\tthis.store.setEntries(entries);\n\t\t\t\tthis.store.saveSnapshot({ phase: \"migrate\" });\n\t\t\t}\n\t\t} else {\n\t\t\tthis.newSession();\n\t\t\tthis.store.setSessionReference(sessionReference); // preserve explicit reference from --session flag\n\t\t}\n\t}\n\n\tnewSession(options?: NewSessionOptions): string | undefined {\n\t\tthis.sessionId = options?.id ?? createSessionId();\n\t\tvalidateSessionId(this.sessionId);\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\tconst sessionReference = this.prepareNewSessionReference(this.getSessionDir(), this.sessionId, timestamp);\n\t\tif (sessionReference) {\n\t\t\tthis.store.setSessionReference(sessionReference);\n\t\t}\n\t\tthis.store.setEntries([header]);\n\t\treturn sessionReference;\n\t}\n\n\tisPersisted(): boolean {\n\t\treturn this.store.isPersisted();\n\t}\n\n\tgetCwd(): string {\n\t\treturn this.cwd;\n\t}\n\n\t/** Update the active runtime cwd without rewriting the session's original header. */\n\tsetCwd(cwd: string): void {\n\t\tthis.cwd = cwd;\n\t}\n\n\tgetSessionDir(): string {\n\t\treturn this.sessionDir;\n\t}\n\n\tgetSessionId(): string {\n\t\treturn this.sessionId;\n\t}\n\n\tgetSessionReference(): string | undefined {\n\t\treturn this.store.getSessionReference();\n\t}\n\n\tprivate _appendEntry(entry: SessionEntry): void {\n\t\tthis.store.appendEntry(entry);\n\t}\n\n\t/** Copy a preserved suffix onto a new branch without mutating the archived entries. */\n\tappendReplayedEntry(entry: SessionEntry, ids: ReadonlyMap<string, string>): string {\n\t\tif (entry.type === \"compaction\") throw new Error(\"Cannot replay a compaction boundary\");\n\t\tconst id = generateId(this.store);\n\t\tconst base = { id, parentId: this.store.getLeafId(), timestamp: new Date().toISOString() };\n\t\tconst replayed: SessionEntry =\n\t\t\tentry.type === \"label\"\n\t\t\t\t? { ...entry, ...base, targetId: ids.get(entry.targetId) ?? entry.targetId }\n\t\t\t\t: entry.type === \"branch_summary\"\n\t\t\t\t\t? { ...entry, ...base, fromId: ids.get(entry.fromId) ?? entry.fromId }\n\t\t\t\t\t: entry.type === \"message\"\n\t\t\t\t\t\t? { ...entry, ...base, replayedFromId: entry.replayedFromId ?? entry.id }\n\t\t\t\t\t\t: { ...entry, ...base };\n\t\tthis._appendEntry(replayed);\n\t\treturn id;\n\t}\n\n\t/** Append a message as child of current leaf, then advance leaf. Returns entry id.\n\t * Does not allow writing CompactionSummaryMessage and BranchSummaryMessage directly.\n\t * Reason: we want these to be top-level entries in the session, not message session entries,\n\t * so it is easier to find them.\n\t * These need to be appended via appendCompaction() and appendBranchSummary() methods.\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.store),\n\t\t\tparentId: this.store.getLeafId(),\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\n\t/** Append a thinking level change as child of current leaf, then advance leaf. Returns entry id. */\n\tappendThinkingLevelChange(thinkingLevel: string): string {\n\t\tconst entry: ThinkingLevelChangeEntry = {\n\t\t\ttype: \"thinking_level_change\",\n\t\t\tid: generateId(this.store),\n\t\t\tparentId: this.store.getLeafId(),\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\n\t/** Append a model change as child of current leaf, then advance leaf. Returns entry id. */\n\tappendModelChange(provider: string, modelId: string): string {\n\t\tconst entry: ModelChangeEntry = {\n\t\t\ttype: \"model_change\",\n\t\t\tid: generateId(this.store),\n\t\t\tparentId: this.store.getLeafId(),\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\n\t/** Append a compaction summary as child of current leaf, then advance leaf. Returns entry id. */\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.store),\n\t\t\tparentId: this.store.getLeafId(),\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\n\t/** Append a custom entry (for extensions) as child of current leaf, then advance leaf. Returns entry id. */\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.store),\n\t\t\tparentId: this.store.getLeafId(),\n\t\t\ttimestamp: new Date().toISOString(),\n\t\t};\n\t\tthis._appendEntry(entry);\n\t\treturn entry.id;\n\t}\n\n\t/** Append a session info entry (e.g., display name). Returns entry id. */\n\tappendSessionInfo(name: string): string {\n\t\tconst entry: SessionInfoEntry = {\n\t\t\ttype: \"session_info\",\n\t\t\tid: generateId(this.store),\n\t\t\tparentId: this.store.getLeafId(),\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\n\t/** Get the current session name from the latest session_info entry, if any. */\n\tgetSessionName(): string | undefined {\n\t\treturn this.store.getSessionName();\n\t}\n\n\t/**\n\t * Append a custom message entry (for extensions) that participates in LLM context.\n\t * @param customType Extension identifier for filtering on reload\n\t * @param content Message content (string or TextContent/ImageContent array)\n\t * @param display Whether to show in TUI (true = styled display, false = hidden)\n\t * @param details Optional extension-specific metadata (not sent to LLM)\n\t * @returns Entry id\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.store),\n\t\t\tparentId: this.store.getLeafId(),\n\t\t\ttimestamp: new Date().toISOString(),\n\t\t};\n\t\tthis._appendEntry(entry);\n\t\treturn entry.id;\n\t}\n\n\t// =========================================================================\n\t// Tree Traversal\n\t// =========================================================================\n\n\tgetLeafId(): string | null {\n\t\treturn this.store.getLeafId();\n\t}\n\n\tgetLeafEntry(): SessionEntry | undefined {\n\t\treturn this.store.getLeafEntry();\n\t}\n\n\tgetEntry(id: string): SessionEntry | undefined {\n\t\treturn this.store.getEntry(id);\n\t}\n\n\t/**\n\t * Get all direct children of an entry.\n\t */\n\tgetChildren(parentId: string): SessionEntry[] {\n\t\treturn this.store.getChildren(parentId);\n\t}\n\n\t/**\n\t * Get the label for an entry, if any.\n\t */\n\tgetLabel(id: string): string | undefined {\n\t\treturn this.store.getLabel(id);\n\t}\n\n\t/**\n\t * Set or clear a label on an entry.\n\t * Labels are user-defined markers for bookmarking/navigation.\n\t * Pass undefined or empty string to clear the label.\n\t */\n\tappendLabelChange(targetId: string, label: string | undefined): string {\n\t\tif (!this.store.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.store),\n\t\t\tparentId: this.store.getLeafId(),\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\treturn entry.id;\n\t}\n\n\t/**\n\t * Walk from entry to root, returning all entries in path order.\n\t * Includes all entry types (messages, compaction, model changes, etc.).\n\t * Use buildSessionContext() to get the resolved messages for the LLM.\n\t */\n\tgetBranch(fromId?: string): SessionEntry[] {\n\t\treturn this.store.getBranch(fromId);\n\t}\n\n\t/**\n\t * Build the session context (what gets sent to the LLM).\n\t * Uses tree traversal from current leaf.\n\t */\n\tbuildSessionContext(): SessionContext {\n\t\treturn buildSessionContext(this.getEntries(), this.store.getLeafId(), this.store.getEntryIndex());\n\t}\n\n\t/**\n\t * Get session header.\n\t */\n\tgetHeader(): SessionHeader | null {\n\t\treturn this.store.getHeader();\n\t}\n\n\t/**\n\t * Get all session entries (excludes header). Returns a shallow copy.\n\t * The session is append-only: use appendXXX() to add entries, branch() to\n\t * change the leaf pointer. Entries cannot be modified or deleted.\n\t */\n\tgetEntries(): SessionEntry[] {\n\t\treturn this.store.getEntries();\n\t}\n\n\t/**\n\t * Get the session as a tree structure. Returns a shallow defensive copy of all entries.\n\t * A well-formed session has exactly one root (first entry with parentId === null).\n\t * Orphaned entries (broken parent chain) are also returned as roots.\n\t */\n\tgetTree(): SessionTreeNode[] {\n\t\treturn this.store.getTree();\n\t}\n\n\t// =========================================================================\n\t// Branching\n\t// =========================================================================\n\n\t/**\n\t * Start a new branch from an earlier entry.\n\t * Moves the leaf pointer to the specified entry. The next appendXXX() call\n\t * will create a child of that entry, forming a new branch. Existing entries\n\t * are not modified or deleted.\n\t */\n\tbranch(branchFromId: string): void {\n\t\tif (!this.store.has(branchFromId)) {\n\t\t\tthrow new Error(`Entry ${branchFromId} not found`);\n\t\t}\n\t\tthis.store.setLeafId(branchFromId);\n\t}\n\n\t/**\n\t * Reset the leaf pointer to null (before any entries).\n\t * The next appendXXX() call will create a new root entry (parentId = null).\n\t * Use this when navigating to re-edit the first user message.\n\t */\n\tresetLeaf(): void {\n\t\tthis.store.setLeafId(null);\n\t}\n\n\t/**\n\t * Start a new branch with a summary of the abandoned path.\n\t * Same as branch(), but also appends a branch_summary entry that captures\n\t * context from the abandoned conversation path.\n\t */\n\tbranchWithSummary(branchFromId: string | null, summary: string, details?: unknown, fromHook?: boolean): string {\n\t\tif (branchFromId !== null && !this.store.has(branchFromId)) {\n\t\t\tthrow new Error(`Entry ${branchFromId} not found`);\n\t\t}\n\t\tthis.store.setLeafId(branchFromId);\n\t\tconst entry: BranchSummaryEntry = {\n\t\t\ttype: \"branch_summary\",\n\t\t\tid: generateId(this.store),\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\n\t/**\n\t * Create a new session reference containing only the path from root to the specified leaf.\n\t * Useful for extracting a single conversation path from a branched session.\n\t * Returns the new session reference, or undefined if the store does not expose one.\n\t */\n\tcreateBranchedSession(leafId: string): string | undefined {\n\t\tconst parentSession = this.getSessionReference();\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\n\t\t// Filter out LabelEntry from path - we'll recreate them from the resolved map\n\t\tconst pathWithoutLabels = path.filter((e) => e.type !== \"label\");\n\n\t\tconst newSessionId = createSessionId();\n\t\tconst timestamp = new Date().toISOString();\n\t\tconst newSessionReference = this.prepareNewSessionReference(this.getSessionDir(), newSessionId, timestamp);\n\t\tif (newSessionReference) {\n\t\t\tthis.store.setSessionReference(newSessionReference);\n\t\t}\n\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,\n\t\t};\n\n\t\t// Collect labels for entries in the path\n\t\tconst pathEntryIds = new Set(pathWithoutLabels.map((e) => e.id));\n\t\tconst labelsToWrite = this.store.getLabelsForEntryIds(pathEntryIds);\n\n\t\tconst labelEntries: LabelEntry[] = [];\n\t\tlet parentId = pathWithoutLabels[pathWithoutLabels.length - 1]?.id || null;\n\t\tfor (const { targetId, label, timestamp: labelTimestamp } of labelsToWrite) {\n\t\t\tconst labelEntry: LabelEntry = {\n\t\t\t\ttype: \"label\",\n\t\t\t\tid: generateId(pathEntryIds),\n\t\t\t\tparentId,\n\t\t\t\ttimestamp: labelTimestamp,\n\t\t\t\ttargetId,\n\t\t\t\tlabel,\n\t\t\t};\n\t\t\tpathEntryIds.add(labelEntry.id);\n\t\t\tlabelEntries.push(labelEntry);\n\t\t\tparentId = labelEntry.id;\n\t\t}\n\t\tthis.store.setEntries([header, ...pathWithoutLabels, ...labelEntries]);\n\t\tthis.sessionId = newSessionId;\n\t\tthis.store.commitSnapshot();\n\t\treturn newSessionReference;\n\t}\n\n\tcopyBranchFrom(source: Session, leafId: string, parentSession?: string): void {\n\t\tconst path = source.getBranch(leafId);\n\t\tif (path.length === 0) {\n\t\t\tthrow new Error(`Entry ${leafId} not found`);\n\t\t}\n\n\t\tconst header = this.getHeader();\n\t\tif (!header) {\n\t\t\tthrow new Error(\"Target session has no header\");\n\t\t}\n\n\t\tconst pathWithoutLabels = structuredClone(path.filter((entry) => entry.type !== \"label\"));\n\t\tconst pathEntryIds = new Set(pathWithoutLabels.map((entry) => entry.id));\n\t\tconst labelsToWrite = source.store.getLabelsForEntryIds(pathEntryIds);\n\t\tconst labelEntries: LabelEntry[] = [];\n\t\tlet nextParentId = pathWithoutLabels[pathWithoutLabels.length - 1]?.id ?? null;\n\t\tfor (const { targetId, label, timestamp } of labelsToWrite) {\n\t\t\tconst labelEntry: LabelEntry = {\n\t\t\t\ttype: \"label\",\n\t\t\t\tid: generateId(pathEntryIds),\n\t\t\t\tparentId: nextParentId,\n\t\t\t\ttimestamp,\n\t\t\t\ttargetId,\n\t\t\t\tlabel,\n\t\t\t};\n\t\t\tpathEntryIds.add(labelEntry.id);\n\t\t\tlabelEntries.push(labelEntry);\n\t\t\tnextParentId = labelEntry.id;\n\t\t}\n\n\t\tthis.store.setEntries([{ ...header, parentSession }, ...pathWithoutLabels, ...labelEntries]);\n\t\tthis.store.commitSnapshot();\n\t}\n\n\tcreateSubSession(options?: NewSessionOptions): SessionResult {\n\t\tif (!this.sessionManager) {\n\t\t\tthrow new Error(\"Session manager unavailable\");\n\t\t}\n\t\treturn this.sessionManager.create({\n\t\t\t...options,\n\t\t\tparentSession: options?.parentSession ?? this.getSessionReference(),\n\t\t});\n\t}\n\n\tforkSubSession(targetLeafId: string | null): SessionResult {\n\t\tif (!this.sessionManager) {\n\t\t\tthrow new Error(\"Session manager unavailable\");\n\t\t}\n\t\treturn this.sessionManager.forkSession(this, targetLeafId);\n\t}\n}\n"]}
1
+ {"version":3,"file":"session.js","sourceRoot":"","sources":["../../../src/core/session/session.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AAGnC,OAAO,EAAE,uBAAuB,EAAE,MAAM,gBAAgB,CAAC;AACzD,OAAO,EAAE,mBAAmB,EAAE,MAAM,cAAc,CAAC;AACnD,OAAO,EAAE,eAAe,EAAE,UAAU,EAAE,iBAAiB,EAAE,MAAM,UAAU,CAAC;AAC1E,OAAO,EAAE,uBAAuB,EAAE,MAAM,iBAAiB,CAAC;AAE1D,OAAO,EAAE,sBAAsB,EAAE,6BAA6B,EAAE,MAAM,iCAAiC,CAAC;AAoCxG;;;;;;;;;;GAUG;AACH,MAAM,OAAgB,OAAO;IAO5B,YACC,GAAW,EACX,UAAkB,EAClB,gBAAoC,EACpC,KAAmB,EACnB,cAA+B;QAXxB,cAAS,GAAW,EAAE,CAAC;QAa9B,IAAI,CAAC,GAAG,GAAG,GAAG,CAAC;QACf,IAAI,CAAC,UAAU,GAAG,UAAU,CAAC;QAC7B,IAAI,CAAC,KAAK,GAAG,KAAK,CAAC;QACnB,IAAI,CAAC,cAAc,GAAG,cAAc,CAAC;QACrC,IAAI,UAAU,EAAE,CAAC;YAChB,IAAI,CAAC,KAAK,CAAC,SAAS,CAAC,UAAU,CAAC,CAAC;QAClC,CAAC;QAED,IAAI,gBAAgB,EAAE,CAAC;YACtB,IAAI,CAAC,mBAAmB,CAAC,gBAAgB,CAAC,CAAC;QAC5C,CAAC;aAAM,CAAC;YACP,IAAI,CAAC,UAAU,EAAE,CAAC;QACnB,CAAC;IACF,CAAC;IAQD,+EAA+E;IAC/E,mBAAmB,CAAC,gBAAwB;QAC3C,IAAI,CAAC,KAAK,CAAC,mBAAmB,CAAC,g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node:fs\";\nimport type { ImageContent, Message, TextContent } from \"@greppleai/grip-ai\";\nimport type { BashExecutionMessage, CustomMessage } from \"../messages.ts\";\nimport { CURRENT_SESSION_VERSION } from \"./constants.ts\";\nimport { buildSessionContext } from \"./context.ts\";\nimport { createSessionId, generateId, validateSessionId } from \"./ids.ts\";\nimport { migrateToCurrentVersion } from \"./migrations.ts\";\nimport type { SessionManager, SessionResult } from \"./session-manager.ts\";\nimport { getJsonlEntryLocations, validateCurrentSessionEntries } from \"./stores/jsonl-session-store.ts\";\nimport type { SessionStore } from \"./stores/session-store.ts\";\nimport type {\n\tBranchSummaryEntry,\n\tCompactionEntry,\n\tCustomEntry,\n\tCustomMessageEntry,\n\tLabelEntry,\n\tModelChangeEntry,\n\tNewSessionOptions,\n\tSessionContext,\n\tSessionEntry,\n\tSessionHeader,\n\tSessionInfoEntry,\n\tSessionMessageEntry,\n\tSessionTreeNode,\n\tThinkingLevelChangeEntry,\n} from \"./types.ts\";\n\nexport type ReadonlySession = Pick<\n\tSession,\n\t| \"getCwd\"\n\t| \"getSessionDir\"\n\t| \"getSessionId\"\n\t| \"getSessionReference\"\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>;\n\n/**\n * Represents one active conversation session as an append-only tree.\n *\n * Each session entry has an id and parentId forming a tree structure. The \"leaf\"\n * pointer tracks the current position. Appending creates a child of the current leaf.\n * Branching moves the leaf to an earlier entry, allowing new branches without\n * modifying history.\n *\n * Use buildSessionContext() to get the resolved message list for the LLM, which\n * handles compaction summaries and follows the path from root to current leaf.\n */\nexport abstract class Session {\n\tprivate sessionId: string = \"\";\n\tprivate sessionDir: string;\n\tprivate cwd: string;\n\tprivate store: SessionStore;\n\tprivate sessionManager: SessionManager | undefined;\n\n\tprotected constructor(\n\t\tcwd: string,\n\t\tsessionDir: string,\n\t\tsessionReference: string | undefined,\n\t\tstore: SessionStore,\n\t\tsessionManager?: SessionManager,\n\t) {\n\t\tthis.cwd = cwd;\n\t\tthis.sessionDir = sessionDir;\n\t\tthis.store = store;\n\t\tthis.sessionManager = sessionManager;\n\t\tif (sessionDir) {\n\t\t\tthis.store.ensureDir(sessionDir);\n\t\t}\n\n\t\tif (sessionReference) {\n\t\t\tthis.setSessionReference(sessionReference);\n\t\t} else {\n\t\t\tthis.newSession();\n\t\t}\n\t}\n\n\tprotected abstract prepareNewSessionReference(\n\t\tsessionDir: string,\n\t\tsessionId: string,\n\t\ttimestamp: string,\n\t): string | undefined;\n\n\t/** Switch to a different session reference (used for resume and branching). */\n\tsetSessionReference(sessionReference: string): void {\n\t\tthis.store.setSessionReference(sessionReference);\n\t\tif (this.store.exists(sessionReference)) {\n\t\t\tthis.store.setEntries(this.store.load(sessionReference));\n\n\t\t\t// If the file is empty, initialize it with a valid session header. If it was\n\t\t\t// non-empty but did not parse as a grip session, fail without modifying it.\n\t\t\tif (this.store.getFileEntries().length === 0) {\n\t\t\t\tif (statSync(sessionReference).size > 0) {\n\t\t\t\t\tthrow new Error(`Session file is not a valid grip session: ${sessionReference}`);\n\t\t\t\t}\n\t\t\t\tthis.newSession();\n\t\t\t\tthis.store.setSessionReference(sessionReference, { allowExistingEmptyFile: true });\n\t\t\t\tthis.store.saveSnapshot();\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tconst header = this.store.getHeader();\n\t\t\tthis.sessionId = header?.id ?? createSessionId();\n\n\t\t\tconst entries = this.store.getFileEntries();\n\t\t\tif (migrateToCurrentVersion(entries)) {\n\t\t\t\tvalidateCurrentSessionEntries(entries, sessionReference, {\n\t\t\t\t\tphase: \"migrate\",\n\t\t\t\t\tlocations: getJsonlEntryLocations(entries),\n\t\t\t\t});\n\t\t\t\tthis.store.setEntries(entries);\n\t\t\t\tthis.store.saveSnapshot({ phase: \"migrate\" });\n\t\t\t}\n\t\t} else {\n\t\t\tthis.newSession();\n\t\t\tthis.store.setSessionReference(sessionReference); // preserve explicit reference from --session flag\n\t\t}\n\t}\n\n\tnewSession(options?: NewSessionOptions): string | undefined {\n\t\tthis.sessionId = options?.id ?? createSessionId();\n\t\tvalidateSessionId(this.sessionId);\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\tconst sessionReference = this.prepareNewSessionReference(this.getSessionDir(), this.sessionId, timestamp);\n\t\tif (sessionReference) {\n\t\t\tthis.store.setSessionReference(sessionReference);\n\t\t}\n\t\tthis.store.setEntries([header]);\n\t\treturn sessionReference;\n\t}\n\n\tisPersisted(): boolean {\n\t\treturn this.store.isPersisted();\n\t}\n\n\tgetCwd(): string {\n\t\treturn this.cwd;\n\t}\n\n\t/** Update the active runtime cwd without rewriting the session's original header. */\n\tsetCwd(cwd: string): void {\n\t\tthis.cwd = cwd;\n\t}\n\n\tgetSessionDir(): string {\n\t\treturn this.sessionDir;\n\t}\n\n\tgetSessionId(): string {\n\t\treturn this.sessionId;\n\t}\n\n\tgetSessionReference(): string | undefined {\n\t\treturn this.store.getSessionReference();\n\t}\n\n\tprivate _appendEntry(entry: SessionEntry): void {\n\t\tthis.store.appendEntry(entry);\n\t}\n\n\t/** Copy a preserved suffix onto a new branch without mutating the archived entries. */\n\tappendReplayedEntry(entry: SessionEntry, ids: ReadonlyMap<string, string>): string {\n\t\tif (entry.type === \"compaction\") throw new Error(\"Cannot replay a compaction boundary\");\n\t\tconst id = generateId(this.store);\n\t\tconst base = { id, parentId: this.store.getLeafId(), timestamp: new Date().toISOString() };\n\t\tconst replayed: SessionEntry =\n\t\t\tentry.type === \"label\"\n\t\t\t\t? { ...entry, ...base, targetId: ids.get(entry.targetId) ?? entry.targetId }\n\t\t\t\t: entry.type === \"branch_summary\"\n\t\t\t\t\t? { ...entry, ...base, fromId: ids.get(entry.fromId) ?? entry.fromId }\n\t\t\t\t\t: entry.type === \"message\"\n\t\t\t\t\t\t? { ...entry, ...base, replayedFromId: entry.replayedFromId ?? entry.id }\n\t\t\t\t\t\t: { ...entry, ...base };\n\t\tthis._appendEntry(replayed);\n\t\treturn id;\n\t}\n\n\t/** Append a message as child of current leaf, then advance leaf. Returns entry id.\n\t * Does not allow writing CompactionSummaryMessage and BranchSummaryMessage directly.\n\t * Reason: we want these to be top-level entries in the session, not message session entries,\n\t * so it is easier to find them.\n\t * These need to be appended via appendCompaction() and appendBranchSummary() methods.\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.store),\n\t\t\tparentId: this.store.getLeafId(),\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\n\t/** Append a thinking level change as child of current leaf, then advance leaf. Returns entry id. */\n\tappendThinkingLevelChange(thinkingLevel: string): string {\n\t\tconst entry: ThinkingLevelChangeEntry = {\n\t\t\ttype: \"thinking_level_change\",\n\t\t\tid: generateId(this.store),\n\t\t\tparentId: this.store.getLeafId(),\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\n\t/** Append a model change as child of current leaf, then advance leaf. Returns entry id. */\n\tappendModelChange(provider: string, modelId: string): string {\n\t\tconst entry: ModelChangeEntry = {\n\t\t\ttype: \"model_change\",\n\t\t\tid: generateId(this.store),\n\t\t\tparentId: this.store.getLeafId(),\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\n\t/** Append a compaction summary as child of current leaf, then advance leaf. Returns entry id. */\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.store),\n\t\t\tparentId: this.store.getLeafId(),\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\n\t/** Append a custom entry (for extensions) as child of current leaf, then advance leaf. Returns entry id. */\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.store),\n\t\t\tparentId: this.store.getLeafId(),\n\t\t\ttimestamp: new Date().toISOString(),\n\t\t};\n\t\tthis._appendEntry(entry);\n\t\treturn entry.id;\n\t}\n\n\t/** Append a session info entry (e.g., display name). Returns entry id. */\n\tappendSessionInfo(name: string): string {\n\t\tconst entry: SessionInfoEntry = {\n\t\t\ttype: \"session_info\",\n\t\t\tid: generateId(this.store),\n\t\t\tparentId: this.store.getLeafId(),\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\n\t/** Get the current session name from the latest session_info entry, if any. */\n\tgetSessionName(): string | undefined {\n\t\treturn this.store.getSessionName();\n\t}\n\n\t/**\n\t * Append a custom message entry (for extensions) that participates in LLM context.\n\t * @param customType Extension identifier for filtering on reload\n\t * @param content Message content (string or TextContent/ImageContent array)\n\t * @param display Whether to show in TUI (true = styled display, false = hidden)\n\t * @param details Optional extension-specific metadata (not sent to LLM)\n\t * @returns Entry id\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.store),\n\t\t\tparentId: this.store.getLeafId(),\n\t\t\ttimestamp: new Date().toISOString(),\n\t\t};\n\t\tthis._appendEntry(entry);\n\t\treturn entry.id;\n\t}\n\n\t// =========================================================================\n\t// Tree Traversal\n\t// =========================================================================\n\n\tgetLeafId(): string | null {\n\t\treturn this.store.getLeafId();\n\t}\n\n\tgetLeafEntry(): SessionEntry | undefined {\n\t\treturn this.store.getLeafEntry();\n\t}\n\n\tgetEntry(id: string): SessionEntry | undefined {\n\t\treturn this.store.getEntry(id);\n\t}\n\n\t/**\n\t * Get all direct children of an entry.\n\t */\n\tgetChildren(parentId: string): SessionEntry[] {\n\t\treturn this.store.getChildren(parentId);\n\t}\n\n\t/**\n\t * Get the label for an entry, if any.\n\t */\n\tgetLabel(id: string): string | undefined {\n\t\treturn this.store.getLabel(id);\n\t}\n\n\t/**\n\t * Set or clear a label on an entry.\n\t * Labels are user-defined markers for bookmarking/navigation.\n\t * Pass undefined or empty string to clear the label.\n\t */\n\tappendLabelChange(targetId: string, label: string | undefined): string {\n\t\tif (!this.store.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.store),\n\t\t\tparentId: this.store.getLeafId(),\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\treturn entry.id;\n\t}\n\n\t/**\n\t * Walk from entry to root, returning all entries in path order.\n\t * Includes all entry types (messages, compaction, model changes, etc.).\n\t * Use buildSessionContext() to get the resolved messages for the LLM.\n\t */\n\tgetBranch(fromId?: string): SessionEntry[] {\n\t\treturn this.store.getBranch(fromId);\n\t}\n\n\t/**\n\t * Build the session context (what gets sent to the LLM).\n\t * Uses tree traversal from current leaf.\n\t */\n\tbuildSessionContext(): SessionContext {\n\t\treturn buildSessionContext(this.getEntries(), this.store.getLeafId(), this.store.getEntryIndex());\n\t}\n\n\t/**\n\t * Get session header.\n\t */\n\tgetHeader(): SessionHeader | null {\n\t\treturn this.store.getHeader();\n\t}\n\n\t/**\n\t * Get all session entries (excludes header). Returns a shallow copy.\n\t * The session is append-only: use appendXXX() to add entries, branch() to\n\t * change the leaf pointer. Entries cannot be modified or deleted.\n\t */\n\tgetEntries(): SessionEntry[] {\n\t\treturn this.store.getEntries();\n\t}\n\n\t/**\n\t * Get the session as a tree structure. Returns a shallow defensive copy of all entries.\n\t * A well-formed session has exactly one root (first entry with parentId === null).\n\t * Orphaned entries (broken parent chain) are also returned as roots.\n\t */\n\tgetTree(): SessionTreeNode[] {\n\t\treturn this.store.getTree();\n\t}\n\n\t// =========================================================================\n\t// Branching\n\t// =========================================================================\n\n\t/**\n\t * Start a new branch from an earlier entry.\n\t * Moves the leaf pointer to the specified entry. The next appendXXX() call\n\t * will create a child of that entry, forming a new branch. Existing entries\n\t * are not modified or deleted.\n\t */\n\tbranch(branchFromId: string): void {\n\t\tif (!this.store.has(branchFromId)) {\n\t\t\tthrow new Error(`Entry ${branchFromId} not found`);\n\t\t}\n\t\tthis.store.setLeafId(branchFromId);\n\t}\n\n\t/**\n\t * Reset the leaf pointer to null (before any entries).\n\t * The next appendXXX() call will create a new root entry (parentId = null).\n\t * Use this when navigating to re-edit the first user message.\n\t */\n\tresetLeaf(): void {\n\t\tthis.store.setLeafId(null);\n\t}\n\n\t/**\n\t * Start a new branch with a summary of the abandoned path.\n\t * Same as branch(), but also appends a branch_summary entry that captures\n\t * context from the abandoned conversation path.\n\t */\n\tbranchWithSummary(branchFromId: string | null, summary: string, details?: unknown, fromHook?: boolean): string {\n\t\tif (branchFromId !== null && !this.store.has(branchFromId)) {\n\t\t\tthrow new Error(`Entry ${branchFromId} not found`);\n\t\t}\n\t\tthis.store.setLeafId(branchFromId);\n\t\tconst entry: BranchSummaryEntry = {\n\t\t\ttype: \"branch_summary\",\n\t\t\tid: generateId(this.store),\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\n\t/**\n\t * Create a new session reference containing only the path from root to the specified leaf.\n\t * Useful for extracting a single conversation path from a branched session.\n\t * Returns the new session reference, or undefined if the store does not expose one.\n\t */\n\tcreateBranchedSession(leafId: string): string | undefined {\n\t\tconst parentSession = this.getSessionReference();\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\n\t\t// Filter out LabelEntry from path - we'll recreate them from the resolved map\n\t\tconst pathWithoutLabels = path.filter((e) => e.type !== \"label\");\n\n\t\tconst newSessionId = createSessionId();\n\t\tconst timestamp = new Date().toISOString();\n\t\tconst newSessionReference = this.prepareNewSessionReference(this.getSessionDir(), newSessionId, timestamp);\n\t\tif (newSessionReference) {\n\t\t\tthis.store.setSessionReference(newSessionReference);\n\t\t}\n\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,\n\t\t};\n\n\t\t// Collect labels for entries in the path\n\t\tconst pathEntryIds = new Set(pathWithoutLabels.map((e) => e.id));\n\t\tconst labelsToWrite = this.store.getLabelsForEntryIds(pathEntryIds);\n\n\t\tconst labelEntries: LabelEntry[] = [];\n\t\tlet parentId = pathWithoutLabels[pathWithoutLabels.length - 1]?.id || null;\n\t\tfor (const { targetId, label, timestamp: labelTimestamp } of labelsToWrite) {\n\t\t\tconst labelEntry: LabelEntry = {\n\t\t\t\ttype: \"label\",\n\t\t\t\tid: generateId(pathEntryIds),\n\t\t\t\tparentId,\n\t\t\t\ttimestamp: labelTimestamp,\n\t\t\t\ttargetId,\n\t\t\t\tlabel,\n\t\t\t};\n\t\t\tpathEntryIds.add(labelEntry.id);\n\t\t\tlabelEntries.push(labelEntry);\n\t\t\tparentId = labelEntry.id;\n\t\t}\n\t\tthis.store.setEntries([header, ...pathWithoutLabels, ...labelEntries]);\n\t\tthis.sessionId = newSessionId;\n\t\tthis.store.commitSnapshot();\n\t\treturn newSessionReference;\n\t}\n\n\tcopyBranchFrom(source: Session, leafId: string, parentSession?: string): void {\n\t\tconst path = source.getBranch(leafId);\n\t\tif (path.length === 0) {\n\t\t\tthrow new Error(`Entry ${leafId} not found`);\n\t\t}\n\n\t\tconst header = this.getHeader();\n\t\tif (!header) {\n\t\t\tthrow new Error(\"Target session has no header\");\n\t\t}\n\n\t\tconst pathWithoutLabels = structuredClone(path.filter((entry) => entry.type !== \"label\"));\n\t\tconst pathEntryIds = new Set(pathWithoutLabels.map((entry) => entry.id));\n\t\tconst labelsToWrite = source.store.getLabelsForEntryIds(pathEntryIds);\n\t\tconst labelEntries: LabelEntry[] = [];\n\t\tlet nextParentId = pathWithoutLabels[pathWithoutLabels.length - 1]?.id ?? null;\n\t\tfor (const { targetId, label, timestamp } of labelsToWrite) {\n\t\t\tconst labelEntry: LabelEntry = {\n\t\t\t\ttype: \"label\",\n\t\t\t\tid: generateId(pathEntryIds),\n\t\t\t\tparentId: nextParentId,\n\t\t\t\ttimestamp,\n\t\t\t\ttargetId,\n\t\t\t\tlabel,\n\t\t\t};\n\t\t\tpathEntryIds.add(labelEntry.id);\n\t\t\tlabelEntries.push(labelEntry);\n\t\t\tnextParentId = labelEntry.id;\n\t\t}\n\n\t\tthis.store.setEntries([{ ...header, parentSession }, ...pathWithoutLabels, ...labelEntries]);\n\t\tthis.store.commitSnapshot();\n\t}\n\n\tcreateSubSession(options?: NewSessionOptions): SessionResult {\n\t\tif (!this.sessionManager) {\n\t\t\tthrow new Error(\"Session manager unavailable\");\n\t\t}\n\t\treturn this.sessionManager.create({\n\t\t\t...options,\n\t\t\tparentSession: options?.parentSession ?? this.getSessionReference(),\n\t\t});\n\t}\n\n\tforkSubSession(targetLeafId: string | null): SessionResult {\n\t\tif (!this.sessionManager) {\n\t\t\tthrow new Error(\"Session manager unavailable\");\n\t\t}\n\t\treturn this.sessionManager.forkSession(this, targetLeafId);\n\t}\n}\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"in-memory-session-store.d.ts","sourceRoot":"","sources":["../../../../src/core/session/stores/in-memory-session-store.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAc,YAAY,EAAE,aAAa,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AACvG,OAAO,KAAK,EAAE,oBAAoB,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAE7E,qBAAa,oBAAqB,YAAW,YAAY;IACxD,SAAS,CAAC,WAAW,EAAE,SAAS,EAAE,CAAM;IACxC,SAAS,CAAC,IAAI,EAAE,GAAG,CAAC,MAAM,EAAE,YAAY,CAAC,CAAa;IACtD,SAAS,CAAC,UAAU,EAAE,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,CAAa;IACtD,SAAS,CAAC,mBAAmB,EAAE,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,CAAa;IAC/D,SAAS,CAAC,MAAM,EAAE,MAAM,GAAG,IAAI,CAAQ;IACvC,OAAO,CAAC,gBAAgB,CAAqB;IAE7C,WAAW,IAAI,OAAO,CAErB;IAED,mBAAmB,IAAI,MAAM,GAAG,SAAS,CAExC;IAED,mBAAmB,CAAC,SAAS,EAAE,MAAM,GAAG,IAAI,CAE3C;IAED,MAAM,CAAC,SAAS,EAAE,MA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Entry, SessionHeader, SessionTreeNode } from \"../types.ts\";\nimport type { SessionLabelSnapshot, SessionStore } from \"./session-store.ts\";\n\nexport class InMemorySessionStore implements SessionStore {\n\tprotected fileEntries: FileEntry[] = [];\n\tprotected byId: Map<string, SessionEntry> = new Map();\n\tprotected labelsById: Map<string, string> = new Map();\n\tprotected labelTimestampsById: Map<string, string> = new Map();\n\tprotected leafId: string | null = null;\n\tprivate sessionReference: string | undefined;\n\n\tisPersisted(): boolean {\n\t\treturn false;\n\t}\n\n\tgetSessionReference(): string | undefined {\n\t\treturn this.sessionReference;\n\t}\n\n\tsetSessionReference(reference: string): void {\n\t\tthis.sessionReference = reference;\n\t}\n\n\texists(reference: string): boolean {\n\t\treturn reference === this.sessionReference && this.fileEntries.length > 0;\n\t}\n\n\tensureDir(_path: string): void {\n\t\t// No-op for in-memory sessions.\n\t}\n\n\tload(reference: string): FileEntry[] {\n\t\treturn reference === this.sessionReference ? [...this.fileEntries] : [];\n\t}\n\n\tsetEntries(entries: FileEntry[]): void {\n\t\tthis.fileEntries = entries;\n\t\tthis.rebuildIndex();\n\t}\n\n\tgetFileEntries(): FileEntry[] {\n\t\treturn this.fileEntries;\n\t}\n\n\tgetHeader(): SessionHeader | null {\n\t\tconst header = this.fileEntries.find((entry) => entry.type === \"session\");\n\t\treturn header ? (header as SessionHeader) : null;\n\t}\n\n\tgetEntries(): SessionEntry[] {\n\t\treturn this.fileEntries.filter((entry): entry is SessionEntry => entry.type !== \"session\");\n\t}\n\n\tgetEntryIndex(): Map<string, SessionEntry> {\n\t\treturn this.byId;\n\t}\n\n\thas(id: string): boolean {\n\t\treturn this.byId.has(id);\n\t}\n\n\tappendEntry(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.applyLabelEntry(entry);\n\t}\n\n\tsaveSnapshot(): void {\n\t\t// No-op for in-memory sessions.\n\t}\n\n\tcommitSnapshot(): void {\n\t\t// No-op for in-memory sessions.\n\t}\n\n\tgetLeafId(): string | null {\n\t\treturn this.leafId;\n\t}\n\n\tsetLeafId(leafId: string | null): void {\n\t\tthis.leafId = leafId;\n\t}\n\n\tgetLeafEntry(): SessionEntry | undefined {\n\t\treturn this.leafId ? this.byId.get(this.leafId) : undefined;\n\t}\n\n\tgetEntry(id: string): SessionEntry | undefined {\n\t\treturn this.byId.get(id);\n\t}\n\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\n\tgetLabel(id: string): string | undefined {\n\t\treturn this.labelsById.get(id);\n\t}\n\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\n\tgetTree(): SessionTreeNode[] {\n\t\tconst entries = this.getEntries();\n\t\tconst nodeMap = new Map<string, SessionTreeNode>();\n\t\tconst roots: SessionTreeNode[] = [];\n\n\t\tfor (const entry of entries) {\n\t\t\tconst label = this.labelsById.get(entry.id);\n\t\t\tconst labelTimestamp = this.labelTimestampsById.get(entry.id);\n\t\t\tnodeMap.set(entry.id, { entry, children: [], label, labelTimestamp });\n\t\t}\n\n\t\tconst childNodes: Array<[parent: SessionTreeNode, child: SessionTreeNode]> = [];\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\tcontinue;\n\t\t\t}\n\t\t\tconst parent = nodeMap.get(entry.parentId);\n\t\t\tif (parent) childNodes.push([parent, node]);\n\t\t\telse roots.push(node);\n\t\t}\n\t\tchildNodes.sort(\n\t\t\t([, left], [, right]) => new Date(left.entry.timestamp).getTime() - new Date(right.entry.timestamp).getTime(),\n\t\t);\n\t\tfor (const [parent, child] of childNodes) parent.children.push(child);\n\n\t\treturn roots;\n\t}\n\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\") {\n\t\t\t\treturn entry.name?.trim() || undefined;\n\t\t\t}\n\t\t}\n\t\treturn undefined;\n\t}\n\n\tgetLabelsForEntryIds(entryIds: Set<string>): SessionLabelSnapshot[] {\n\t\tconst labels: SessionLabelSnapshot[] = [];\n\t\tfor (const [targetId, label] of this.labelsById) {\n\t\t\tif (entryIds.has(targetId)) {\n\t\t\t\tlabels.push({ targetId, label, timestamp: this.labelTimestampsById.get(targetId)! });\n\t\t\t}\n\t\t}\n\t\treturn labels;\n\t}\n\n\thasAssistantMessage(): boolean {\n\t\treturn this.fileEntries.some((entry) => entry.type === \"message\" && entry.message.role === \"assistant\");\n\t}\n\n\tprivate rebuildIndex(): void {\n\t\tthis.byId.clear();\n\t\tthis.labelsById.clear();\n\t\tthis.labelTimestampsById.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\tthis.applyLabelEntry(entry);\n\t\t}\n\t}\n\n\tprivate applyLabelEntry(entry: SessionEntry): void {\n\t\tif (entry.type !== \"label\") return;\n\t\tconst labelEntry = entry as LabelEntry;\n\t\tif (labelEntry.label) {\n\t\t\tthis.labelsById.set(labelEntry.targetId, labelEntry.label);\n\t\t\tthis.labelTimestampsById.set(labelEntry.targetId, labelEntry.timestamp);\n\t\t} else {\n\t\t\tthis.labelsById.delete(labelEntry.targetId);\n\t\t\tthis.labelTimestampsById.delete(labelEntry.targetId);\n\t\t}\n\t}\n}\n"]}
1
+ {"version":3,"file":"in-memory-session-store.d.ts","sourceRoot":"","sources":["../../../../src/core/session/stores/in-memory-session-store.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAc,YAAY,EAAE,aAAa,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AACvG,OAAO,KAAK,EAAE,oBAAoB,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAE7E,qBAAa,oBAAqB,YAAW,YAAY;IACxD,SAAS,CAAC,WAAW,EAAE,SAAS,EAAE,CAAM;IACxC,SAAS,CAAC,IAAI,EAAE,GAAG,CAAC,MAAM,EAAE,YAAY,CAAC,CAAa;IACtD,SAAS,CAAC,UAAU,EAAE,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,CAAa;IACtD,SAAS,CAAC,mBAAmB,EAAE,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,CAAa;IAC/D,SAAS,CAAC,MAAM,EAAE,MAAM,GAAG,IAAI,CAAQ;IACvC,OAAO,CAAC,gBAAgB,CAAqB;IAE7C,WAAW,IAAI,OAAO,CAErB;IAED,mBAAmB,IAAI,MAAM,GAAG,SAAS,CAExC;IAED,mBAAmB,CAAC,SAAS,EAAE,MAAM,GAAG,IAAI,CAE3C;IAED,MAAM,CAAC,SAAS,EAAE,MAAM,GAAG,OAAO,CAEjC;IAED,SAAS,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI,CAE7B;IAED,IAAI,CAAC,SAAS,EAAE,MAAM,GAAG,SAAS,EAAE,CAEnC;IAED,UAAU,CAAC,OAAO,EAAE,SAAS,EAAE,GAAG,IAAI,CAGrC;IAED,cAAc,IAAI,SAAS,EAAE,CAE5B;IAED,SAAS,IAAI,aAAa,GAAG,IAAI,CAGhC;IAED,UAAU,IAAI,YAAY,EAAE,CAE3B;IAED,aAAa,IAAI,GAAG,CAAC,MAAM,EAAE,YAAY,CAAC,CAEzC;IAED,GAAG,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO,CAEvB;IAED,WAAW,CAAC,KAAK,EAAE,YAAY,GAAG,IAAI,CAKrC;IAED,YAAY,IAAI,IAAI,CAEnB;IAED,cAAc,IAAI,IAAI,CAErB;IAED,SAAS,IAAI,MAAM,GAAG,IAAI,CAEzB;IAED,SAAS,CAAC,MAAM,EAAE,MAAM,GAAG,IAAI,GAAG,IAAI,CAErC;IAED,YAAY,IAAI,YAAY,GAAG,SAAS,CAEvC;IAED,QAAQ,CAAC,EAAE,EAAE,MAAM,GAAG,YAAY,GAAG,SAAS,CAE7C;IAED,WAAW,CAAC,QAAQ,EAAE,MAAM,GAAG,YAAY,EAAE,CAQ5C;IAED,QAAQ,CAAC,EAAE,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,CAEvC;IAED,SAAS,CAAC,MAAM,CAAC,EAAE,MAAM,GAAG,YAAY,EAAE,CASzC;IAED,OAAO,IAAI,eAAe,EAAE,CA4B3B;IAED,cAAc,IAAI,MAAM,GAAG,SAAS,CASnC;IAED,oBAAoB,CAAC,QAAQ,EAAE,GAAG,CAAC,MAAM,CAAC,GAAG,oBAAoB,EAAE,CAQlE;IAED,mBAAmB,IAAI,OAAO,CAE7B;IAED,OAAO,CAAC,YAAY;IAapB,OAAO,CAAC,eAAe;CAWvB"}
@@ -1,10 +1,11 @@
1
1
  export class InMemorySessionStore {
2
- fileEntries = [];
3
- byId = new Map();
4
- labelsById = new Map();
5
- labelTimestampsById = new Map();
6
- leafId = null;
7
- sessionReference;
2
+ constructor() {
3
+ this.fileEntries = [];
4
+ this.byId = new Map();
5
+ this.labelsById = new Map();
6
+ this.labelTimestampsById = new Map();
7
+ this.leafId = null;
8
+ }
8
9
  isPersisted() {
9
10
  return false;
10
11
  }