@openeryc/pi-coding-agent 0.75.12 → 0.75.14

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 (591) hide show
  1. package/CHANGELOG.md +4 -0
  2. package/examples/extensions/custom-provider-anthropic/package-lock.json +2 -2
  3. package/examples/extensions/custom-provider-anthropic/package.json +1 -1
  4. package/examples/extensions/custom-provider-gitlab-duo/package.json +1 -1
  5. package/examples/extensions/sandbox/package-lock.json +2 -2
  6. package/examples/extensions/sandbox/package.json +1 -1
  7. package/examples/extensions/with-deps/package-lock.json +2 -2
  8. package/examples/extensions/with-deps/package.json +1 -1
  9. package/npm-shrinkwrap.json +12 -12
  10. package/package.json +4 -4
  11. package/dist/bun/cli.d.ts +0 -3
  12. package/dist/bun/cli.d.ts.map +0 -1
  13. package/dist/bun/cli.js +0 -9
  14. package/dist/bun/cli.js.map +0 -1
  15. package/dist/bun/register-bedrock.d.ts +0 -2
  16. package/dist/bun/register-bedrock.d.ts.map +0 -1
  17. package/dist/bun/register-bedrock.js +0 -4
  18. package/dist/bun/register-bedrock.js.map +0 -1
  19. package/dist/bun/restore-sandbox-env.d.ts +0 -13
  20. package/dist/bun/restore-sandbox-env.d.ts.map +0 -1
  21. package/dist/bun/restore-sandbox-env.js +0 -32
  22. package/dist/bun/restore-sandbox-env.js.map +0 -1
  23. package/dist/cli/args.d.ts +0 -53
  24. package/dist/cli/args.d.ts.map +0 -1
  25. package/dist/cli/args.js +0 -341
  26. package/dist/cli/args.js.map +0 -1
  27. package/dist/cli/config-selector.d.ts +0 -14
  28. package/dist/cli/config-selector.d.ts.map +0 -1
  29. package/dist/cli/config-selector.js +0 -31
  30. package/dist/cli/config-selector.js.map +0 -1
  31. package/dist/cli/file-processor.d.ts +0 -15
  32. package/dist/cli/file-processor.d.ts.map +0 -1
  33. package/dist/cli/file-processor.js +0 -83
  34. package/dist/cli/file-processor.js.map +0 -1
  35. package/dist/cli/initial-message.d.ts +0 -18
  36. package/dist/cli/initial-message.d.ts.map +0 -1
  37. package/dist/cli/initial-message.js +0 -22
  38. package/dist/cli/initial-message.js.map +0 -1
  39. package/dist/cli/list-models.d.ts +0 -9
  40. package/dist/cli/list-models.d.ts.map +0 -1
  41. package/dist/cli/list-models.js +0 -98
  42. package/dist/cli/list-models.js.map +0 -1
  43. package/dist/cli/session-picker.d.ts +0 -9
  44. package/dist/cli/session-picker.d.ts.map +0 -1
  45. package/dist/cli/session-picker.js +0 -35
  46. package/dist/cli/session-picker.js.map +0 -1
  47. package/dist/cli.d.ts +0 -3
  48. package/dist/cli.d.ts.map +0 -1
  49. package/dist/cli.js +0 -18
  50. package/dist/cli.js.map +0 -1
  51. package/dist/config.d.ts +0 -92
  52. package/dist/config.d.ts.map +0 -1
  53. package/dist/config.js +0 -422
  54. package/dist/config.js.map +0 -1
  55. package/dist/core/agent-session-runtime.d.ts +0 -117
  56. package/dist/core/agent-session-runtime.d.ts.map +0 -1
  57. package/dist/core/agent-session-runtime.js +0 -299
  58. package/dist/core/agent-session-runtime.js.map +0 -1
  59. package/dist/core/agent-session-services.d.ts +0 -86
  60. package/dist/core/agent-session-services.d.ts.map +0 -1
  61. package/dist/core/agent-session-services.js +0 -117
  62. package/dist/core/agent-session-services.js.map +0 -1
  63. package/dist/core/agent-session.d.ts +0 -605
  64. package/dist/core/agent-session.d.ts.map +0 -1
  65. package/dist/core/agent-session.js +0 -2519
  66. package/dist/core/agent-session.js.map +0 -1
  67. package/dist/core/auth-guidance.d.ts +0 -5
  68. package/dist/core/auth-guidance.d.ts.map +0 -1
  69. package/dist/core/auth-guidance.js +0 -21
  70. package/dist/core/auth-guidance.js.map +0 -1
  71. package/dist/core/auth-storage.d.ts +0 -141
  72. package/dist/core/auth-storage.d.ts.map +0 -1
  73. package/dist/core/auth-storage.js +0 -441
  74. package/dist/core/auth-storage.js.map +0 -1
  75. package/dist/core/bash-executor.d.ts +0 -32
  76. package/dist/core/bash-executor.d.ts.map +0 -1
  77. package/dist/core/bash-executor.js +0 -111
  78. package/dist/core/bash-executor.js.map +0 -1
  79. package/dist/core/compaction/branch-summarization.d.ts +0 -88
  80. package/dist/core/compaction/branch-summarization.d.ts.map +0 -1
  81. package/dist/core/compaction/branch-summarization.js +0 -243
  82. package/dist/core/compaction/branch-summarization.js.map +0 -1
  83. package/dist/core/compaction/compaction.d.ts +0 -121
  84. package/dist/core/compaction/compaction.d.ts.map +0 -1
  85. package/dist/core/compaction/compaction.js +0 -638
  86. package/dist/core/compaction/compaction.js.map +0 -1
  87. package/dist/core/compaction/index.d.ts +0 -7
  88. package/dist/core/compaction/index.d.ts.map +0 -1
  89. package/dist/core/compaction/index.js +0 -7
  90. package/dist/core/compaction/index.js.map +0 -1
  91. package/dist/core/compaction/utils.d.ts +0 -38
  92. package/dist/core/compaction/utils.d.ts.map +0 -1
  93. package/dist/core/compaction/utils.js +0 -153
  94. package/dist/core/compaction/utils.js.map +0 -1
  95. package/dist/core/defaults.d.ts +0 -3
  96. package/dist/core/defaults.d.ts.map +0 -1
  97. package/dist/core/defaults.js +0 -2
  98. package/dist/core/defaults.js.map +0 -1
  99. package/dist/core/diagnostics.d.ts +0 -15
  100. package/dist/core/diagnostics.d.ts.map +0 -1
  101. package/dist/core/diagnostics.js +0 -2
  102. package/dist/core/diagnostics.js.map +0 -1
  103. package/dist/core/event-bus.d.ts +0 -9
  104. package/dist/core/event-bus.d.ts.map +0 -1
  105. package/dist/core/event-bus.js +0 -25
  106. package/dist/core/event-bus.js.map +0 -1
  107. package/dist/core/exec.d.ts +0 -29
  108. package/dist/core/exec.d.ts.map +0 -1
  109. package/dist/core/exec.js +0 -75
  110. package/dist/core/exec.js.map +0 -1
  111. package/dist/core/export-html/ansi-to-html.d.ts +0 -22
  112. package/dist/core/export-html/ansi-to-html.d.ts.map +0 -1
  113. package/dist/core/export-html/ansi-to-html.js +0 -249
  114. package/dist/core/export-html/ansi-to-html.js.map +0 -1
  115. package/dist/core/export-html/index.d.ts +0 -37
  116. package/dist/core/export-html/index.d.ts.map +0 -1
  117. package/dist/core/export-html/index.js +0 -224
  118. package/dist/core/export-html/index.js.map +0 -1
  119. package/dist/core/export-html/template.css +0 -1066
  120. package/dist/core/export-html/template.html +0 -55
  121. package/dist/core/export-html/template.js +0 -1848
  122. package/dist/core/export-html/tool-renderer.d.ts +0 -34
  123. package/dist/core/export-html/tool-renderer.d.ts.map +0 -1
  124. package/dist/core/export-html/tool-renderer.js +0 -108
  125. package/dist/core/export-html/tool-renderer.js.map +0 -1
  126. package/dist/core/export-html/vendor/highlight.min.js +0 -1213
  127. package/dist/core/export-html/vendor/marked.min.js +0 -6
  128. package/dist/core/extensions/index.d.ts +0 -12
  129. package/dist/core/extensions/index.d.ts.map +0 -1
  130. package/dist/core/extensions/index.js +0 -9
  131. package/dist/core/extensions/index.js.map +0 -1
  132. package/dist/core/extensions/loader.d.ts +0 -24
  133. package/dist/core/extensions/loader.d.ts.map +0 -1
  134. package/dist/core/extensions/loader.js +0 -508
  135. package/dist/core/extensions/loader.js.map +0 -1
  136. package/dist/core/extensions/runner.d.ts +0 -159
  137. package/dist/core/extensions/runner.d.ts.map +0 -1
  138. package/dist/core/extensions/runner.js +0 -826
  139. package/dist/core/extensions/runner.js.map +0 -1
  140. package/dist/core/extensions/types.d.ts +0 -1181
  141. package/dist/core/extensions/types.d.ts.map +0 -1
  142. package/dist/core/extensions/types.js +0 -45
  143. package/dist/core/extensions/types.js.map +0 -1
  144. package/dist/core/extensions/wrapper.d.ts +0 -20
  145. package/dist/core/extensions/wrapper.d.ts.map +0 -1
  146. package/dist/core/extensions/wrapper.js +0 -22
  147. package/dist/core/extensions/wrapper.js.map +0 -1
  148. package/dist/core/footer-data-provider.d.ts +0 -52
  149. package/dist/core/footer-data-provider.d.ts.map +0 -1
  150. package/dist/core/footer-data-provider.js +0 -310
  151. package/dist/core/footer-data-provider.js.map +0 -1
  152. package/dist/core/http-dispatcher.d.ts +0 -21
  153. package/dist/core/http-dispatcher.d.ts.map +0 -1
  154. package/dist/core/http-dispatcher.js +0 -48
  155. package/dist/core/http-dispatcher.js.map +0 -1
  156. package/dist/core/index.d.ts +0 -12
  157. package/dist/core/index.d.ts.map +0 -1
  158. package/dist/core/index.js +0 -12
  159. package/dist/core/index.js.map +0 -1
  160. package/dist/core/keybindings.d.ts +0 -353
  161. package/dist/core/keybindings.d.ts.map +0 -1
  162. package/dist/core/keybindings.js +0 -295
  163. package/dist/core/keybindings.js.map +0 -1
  164. package/dist/core/messages.d.ts +0 -77
  165. package/dist/core/messages.d.ts.map +0 -1
  166. package/dist/core/messages.js +0 -123
  167. package/dist/core/messages.js.map +0 -1
  168. package/dist/core/model-registry.d.ts +0 -150
  169. package/dist/core/model-registry.d.ts.map +0 -1
  170. package/dist/core/model-registry.js +0 -728
  171. package/dist/core/model-registry.js.map +0 -1
  172. package/dist/core/model-resolver.d.ts +0 -110
  173. package/dist/core/model-resolver.d.ts.map +0 -1
  174. package/dist/core/model-resolver.js +0 -495
  175. package/dist/core/model-resolver.js.map +0 -1
  176. package/dist/core/output-guard.d.ts +0 -6
  177. package/dist/core/output-guard.d.ts.map +0 -1
  178. package/dist/core/output-guard.js +0 -59
  179. package/dist/core/output-guard.js.map +0 -1
  180. package/dist/core/package-manager.d.ts +0 -203
  181. package/dist/core/package-manager.d.ts.map +0 -1
  182. package/dist/core/package-manager.js +0 -2013
  183. package/dist/core/package-manager.js.map +0 -1
  184. package/dist/core/prompt-templates.d.ts +0 -52
  185. package/dist/core/prompt-templates.d.ts.map +0 -1
  186. package/dist/core/prompt-templates.js +0 -252
  187. package/dist/core/prompt-templates.js.map +0 -1
  188. package/dist/core/provider-display-names.d.ts +0 -2
  189. package/dist/core/provider-display-names.d.ts.map +0 -1
  190. package/dist/core/provider-display-names.js +0 -33
  191. package/dist/core/provider-display-names.js.map +0 -1
  192. package/dist/core/resolve-config-value.d.ts +0 -23
  193. package/dist/core/resolve-config-value.d.ts.map +0 -1
  194. package/dist/core/resolve-config-value.js +0 -126
  195. package/dist/core/resolve-config-value.js.map +0 -1
  196. package/dist/core/resource-loader.d.ts +0 -197
  197. package/dist/core/resource-loader.d.ts.map +0 -1
  198. package/dist/core/resource-loader.js +0 -757
  199. package/dist/core/resource-loader.js.map +0 -1
  200. package/dist/core/sdk.d.ts +0 -107
  201. package/dist/core/sdk.d.ts.map +0 -1
  202. package/dist/core/sdk.js +0 -282
  203. package/dist/core/sdk.js.map +0 -1
  204. package/dist/core/session-cwd.d.ts +0 -19
  205. package/dist/core/session-cwd.d.ts.map +0 -1
  206. package/dist/core/session-cwd.js +0 -38
  207. package/dist/core/session-cwd.js.map +0 -1
  208. package/dist/core/session-manager.d.ts +0 -363
  209. package/dist/core/session-manager.d.ts.map +0 -1
  210. package/dist/core/session-manager.js +0 -1318
  211. package/dist/core/session-manager.js.map +0 -1
  212. package/dist/core/settings-manager.d.ts +0 -264
  213. package/dist/core/settings-manager.d.ts.map +0 -1
  214. package/dist/core/settings-manager.js +0 -802
  215. package/dist/core/settings-manager.js.map +0 -1
  216. package/dist/core/skills.d.ts +0 -60
  217. package/dist/core/skills.d.ts.map +0 -1
  218. package/dist/core/skills.js +0 -401
  219. package/dist/core/skills.js.map +0 -1
  220. package/dist/core/slash-commands.d.ts +0 -14
  221. package/dist/core/slash-commands.d.ts.map +0 -1
  222. package/dist/core/slash-commands.js +0 -28
  223. package/dist/core/slash-commands.js.map +0 -1
  224. package/dist/core/source-info.d.ts +0 -18
  225. package/dist/core/source-info.d.ts.map +0 -1
  226. package/dist/core/source-info.js +0 -19
  227. package/dist/core/source-info.js.map +0 -1
  228. package/dist/core/system-prompt.d.ts +0 -30
  229. package/dist/core/system-prompt.d.ts.map +0 -1
  230. package/dist/core/system-prompt.js +0 -132
  231. package/dist/core/system-prompt.js.map +0 -1
  232. package/dist/core/telemetry.d.ts +0 -3
  233. package/dist/core/telemetry.d.ts.map +0 -1
  234. package/dist/core/telemetry.js +0 -9
  235. package/dist/core/telemetry.js.map +0 -1
  236. package/dist/core/timings.d.ts +0 -8
  237. package/dist/core/timings.d.ts.map +0 -1
  238. package/dist/core/timings.js +0 -31
  239. package/dist/core/timings.js.map +0 -1
  240. package/dist/core/tools/bash.d.ts +0 -68
  241. package/dist/core/tools/bash.d.ts.map +0 -1
  242. package/dist/core/tools/bash.js +0 -336
  243. package/dist/core/tools/bash.js.map +0 -1
  244. package/dist/core/tools/edit-diff.d.ts +0 -85
  245. package/dist/core/tools/edit-diff.d.ts.map +0 -1
  246. package/dist/core/tools/edit-diff.js +0 -338
  247. package/dist/core/tools/edit-diff.js.map +0 -1
  248. package/dist/core/tools/edit.d.ts +0 -49
  249. package/dist/core/tools/edit.d.ts.map +0 -1
  250. package/dist/core/tools/edit.js +0 -324
  251. package/dist/core/tools/edit.js.map +0 -1
  252. package/dist/core/tools/file-mutation-queue.d.ts +0 -6
  253. package/dist/core/tools/file-mutation-queue.d.ts.map +0 -1
  254. package/dist/core/tools/file-mutation-queue.js +0 -37
  255. package/dist/core/tools/file-mutation-queue.js.map +0 -1
  256. package/dist/core/tools/find.d.ts +0 -35
  257. package/dist/core/tools/find.d.ts.map +0 -1
  258. package/dist/core/tools/find.js +0 -298
  259. package/dist/core/tools/find.js.map +0 -1
  260. package/dist/core/tools/grep.d.ts +0 -37
  261. package/dist/core/tools/grep.d.ts.map +0 -1
  262. package/dist/core/tools/grep.js +0 -304
  263. package/dist/core/tools/grep.js.map +0 -1
  264. package/dist/core/tools/index.d.ts +0 -40
  265. package/dist/core/tools/index.d.ts.map +0 -1
  266. package/dist/core/tools/index.js +0 -112
  267. package/dist/core/tools/index.js.map +0 -1
  268. package/dist/core/tools/ls.d.ts +0 -37
  269. package/dist/core/tools/ls.d.ts.map +0 -1
  270. package/dist/core/tools/ls.js +0 -169
  271. package/dist/core/tools/ls.js.map +0 -1
  272. package/dist/core/tools/output-accumulator.d.ts +0 -50
  273. package/dist/core/tools/output-accumulator.d.ts.map +0 -1
  274. package/dist/core/tools/output-accumulator.js +0 -178
  275. package/dist/core/tools/output-accumulator.js.map +0 -1
  276. package/dist/core/tools/path-utils.d.ts +0 -8
  277. package/dist/core/tools/path-utils.d.ts.map +0 -1
  278. package/dist/core/tools/path-utils.js +0 -81
  279. package/dist/core/tools/path-utils.js.map +0 -1
  280. package/dist/core/tools/read.d.ts +0 -35
  281. package/dist/core/tools/read.d.ts.map +0 -1
  282. package/dist/core/tools/read.js +0 -291
  283. package/dist/core/tools/read.js.map +0 -1
  284. package/dist/core/tools/render-utils.d.ts +0 -21
  285. package/dist/core/tools/render-utils.d.ts.map +0 -1
  286. package/dist/core/tools/render-utils.js +0 -49
  287. package/dist/core/tools/render-utils.js.map +0 -1
  288. package/dist/core/tools/tool-definition-wrapper.d.ts +0 -14
  289. package/dist/core/tools/tool-definition-wrapper.d.ts.map +0 -1
  290. package/dist/core/tools/tool-definition-wrapper.js +0 -34
  291. package/dist/core/tools/tool-definition-wrapper.js.map +0 -1
  292. package/dist/core/tools/truncate.d.ts +0 -70
  293. package/dist/core/tools/truncate.d.ts.map +0 -1
  294. package/dist/core/tools/truncate.js +0 -205
  295. package/dist/core/tools/truncate.js.map +0 -1
  296. package/dist/core/tools/write.d.ts +0 -26
  297. package/dist/core/tools/write.d.ts.map +0 -1
  298. package/dist/core/tools/write.js +0 -213
  299. package/dist/core/tools/write.js.map +0 -1
  300. package/dist/index.d.ts +0 -29
  301. package/dist/index.d.ts.map +0 -1
  302. package/dist/index.js +0 -42
  303. package/dist/index.js.map +0 -1
  304. package/dist/main.d.ts +0 -12
  305. package/dist/main.d.ts.map +0 -1
  306. package/dist/main.js +0 -587
  307. package/dist/main.js.map +0 -1
  308. package/dist/migrations.d.ts +0 -33
  309. package/dist/migrations.d.ts.map +0 -1
  310. package/dist/migrations.js +0 -281
  311. package/dist/migrations.js.map +0 -1
  312. package/dist/modes/index.d.ts +0 -10
  313. package/dist/modes/index.d.ts.map +0 -1
  314. package/dist/modes/index.js +0 -9
  315. package/dist/modes/index.js.map +0 -1
  316. package/dist/modes/interactive/assets/clankolas.png +0 -0
  317. package/dist/modes/interactive/components/armin.d.ts +0 -34
  318. package/dist/modes/interactive/components/armin.d.ts.map +0 -1
  319. package/dist/modes/interactive/components/armin.js +0 -333
  320. package/dist/modes/interactive/components/armin.js.map +0 -1
  321. package/dist/modes/interactive/components/assistant-message.d.ts +0 -20
  322. package/dist/modes/interactive/components/assistant-message.d.ts.map +0 -1
  323. package/dist/modes/interactive/components/assistant-message.js +0 -121
  324. package/dist/modes/interactive/components/assistant-message.js.map +0 -1
  325. package/dist/modes/interactive/components/bash-execution.d.ts +0 -34
  326. package/dist/modes/interactive/components/bash-execution.d.ts.map +0 -1
  327. package/dist/modes/interactive/components/bash-execution.js +0 -175
  328. package/dist/modes/interactive/components/bash-execution.js.map +0 -1
  329. package/dist/modes/interactive/components/bordered-loader.d.ts +0 -16
  330. package/dist/modes/interactive/components/bordered-loader.d.ts.map +0 -1
  331. package/dist/modes/interactive/components/bordered-loader.js +0 -54
  332. package/dist/modes/interactive/components/bordered-loader.js.map +0 -1
  333. package/dist/modes/interactive/components/branch-summary-message.d.ts +0 -16
  334. package/dist/modes/interactive/components/branch-summary-message.d.ts.map +0 -1
  335. package/dist/modes/interactive/components/branch-summary-message.js +0 -44
  336. package/dist/modes/interactive/components/branch-summary-message.js.map +0 -1
  337. package/dist/modes/interactive/components/compaction-summary-message.d.ts +0 -16
  338. package/dist/modes/interactive/components/compaction-summary-message.d.ts.map +0 -1
  339. package/dist/modes/interactive/components/compaction-summary-message.js +0 -45
  340. package/dist/modes/interactive/components/compaction-summary-message.js.map +0 -1
  341. package/dist/modes/interactive/components/config-selector.d.ts +0 -71
  342. package/dist/modes/interactive/components/config-selector.d.ts.map +0 -1
  343. package/dist/modes/interactive/components/config-selector.js +0 -506
  344. package/dist/modes/interactive/components/config-selector.js.map +0 -1
  345. package/dist/modes/interactive/components/countdown-timer.d.ts +0 -14
  346. package/dist/modes/interactive/components/countdown-timer.d.ts.map +0 -1
  347. package/dist/modes/interactive/components/countdown-timer.js +0 -33
  348. package/dist/modes/interactive/components/countdown-timer.js.map +0 -1
  349. package/dist/modes/interactive/components/custom-editor.d.ts +0 -21
  350. package/dist/modes/interactive/components/custom-editor.d.ts.map +0 -1
  351. package/dist/modes/interactive/components/custom-editor.js +0 -70
  352. package/dist/modes/interactive/components/custom-editor.js.map +0 -1
  353. package/dist/modes/interactive/components/custom-message.d.ts +0 -20
  354. package/dist/modes/interactive/components/custom-message.d.ts.map +0 -1
  355. package/dist/modes/interactive/components/custom-message.js +0 -79
  356. package/dist/modes/interactive/components/custom-message.js.map +0 -1
  357. package/dist/modes/interactive/components/daxnuts.d.ts +0 -23
  358. package/dist/modes/interactive/components/daxnuts.d.ts.map +0 -1
  359. package/dist/modes/interactive/components/daxnuts.js +0 -140
  360. package/dist/modes/interactive/components/daxnuts.js.map +0 -1
  361. package/dist/modes/interactive/components/diff.d.ts +0 -12
  362. package/dist/modes/interactive/components/diff.d.ts.map +0 -1
  363. package/dist/modes/interactive/components/diff.js +0 -133
  364. package/dist/modes/interactive/components/diff.js.map +0 -1
  365. package/dist/modes/interactive/components/dynamic-border.d.ts +0 -15
  366. package/dist/modes/interactive/components/dynamic-border.d.ts.map +0 -1
  367. package/dist/modes/interactive/components/dynamic-border.js +0 -21
  368. package/dist/modes/interactive/components/dynamic-border.js.map +0 -1
  369. package/dist/modes/interactive/components/earendil-announcement.d.ts +0 -5
  370. package/dist/modes/interactive/components/earendil-announcement.d.ts.map +0 -1
  371. package/dist/modes/interactive/components/earendil-announcement.js +0 -40
  372. package/dist/modes/interactive/components/earendil-announcement.js.map +0 -1
  373. package/dist/modes/interactive/components/extension-editor.d.ts +0 -20
  374. package/dist/modes/interactive/components/extension-editor.d.ts.map +0 -1
  375. package/dist/modes/interactive/components/extension-editor.js +0 -119
  376. package/dist/modes/interactive/components/extension-editor.js.map +0 -1
  377. package/dist/modes/interactive/components/extension-input.d.ts +0 -23
  378. package/dist/modes/interactive/components/extension-input.d.ts.map +0 -1
  379. package/dist/modes/interactive/components/extension-input.js +0 -61
  380. package/dist/modes/interactive/components/extension-input.js.map +0 -1
  381. package/dist/modes/interactive/components/extension-selector.d.ts +0 -26
  382. package/dist/modes/interactive/components/extension-selector.d.ts.map +0 -1
  383. package/dist/modes/interactive/components/extension-selector.js +0 -83
  384. package/dist/modes/interactive/components/extension-selector.js.map +0 -1
  385. package/dist/modes/interactive/components/footer.d.ts +0 -27
  386. package/dist/modes/interactive/components/footer.d.ts.map +0 -1
  387. package/dist/modes/interactive/components/footer.js +0 -201
  388. package/dist/modes/interactive/components/footer.js.map +0 -1
  389. package/dist/modes/interactive/components/index.d.ts +0 -32
  390. package/dist/modes/interactive/components/index.d.ts.map +0 -1
  391. package/dist/modes/interactive/components/index.js +0 -33
  392. package/dist/modes/interactive/components/index.js.map +0 -1
  393. package/dist/modes/interactive/components/keybinding-hints.d.ts +0 -13
  394. package/dist/modes/interactive/components/keybinding-hints.d.ts.map +0 -1
  395. package/dist/modes/interactive/components/keybinding-hints.js +0 -36
  396. package/dist/modes/interactive/components/keybinding-hints.js.map +0 -1
  397. package/dist/modes/interactive/components/login-dialog.d.ts +0 -46
  398. package/dist/modes/interactive/components/login-dialog.d.ts.map +0 -1
  399. package/dist/modes/interactive/components/login-dialog.js +0 -160
  400. package/dist/modes/interactive/components/login-dialog.js.map +0 -1
  401. package/dist/modes/interactive/components/model-selector.d.ts +0 -47
  402. package/dist/modes/interactive/components/model-selector.d.ts.map +0 -1
  403. package/dist/modes/interactive/components/model-selector.js +0 -278
  404. package/dist/modes/interactive/components/model-selector.js.map +0 -1
  405. package/dist/modes/interactive/components/oauth-selector.d.ts +0 -31
  406. package/dist/modes/interactive/components/oauth-selector.d.ts.map +0 -1
  407. package/dist/modes/interactive/components/oauth-selector.js +0 -165
  408. package/dist/modes/interactive/components/oauth-selector.js.map +0 -1
  409. package/dist/modes/interactive/components/scoped-models-selector.d.ts +0 -42
  410. package/dist/modes/interactive/components/scoped-models-selector.d.ts.map +0 -1
  411. package/dist/modes/interactive/components/scoped-models-selector.js +0 -290
  412. package/dist/modes/interactive/components/scoped-models-selector.js.map +0 -1
  413. package/dist/modes/interactive/components/session-selector-search.d.ts +0 -23
  414. package/dist/modes/interactive/components/session-selector-search.d.ts.map +0 -1
  415. package/dist/modes/interactive/components/session-selector-search.js +0 -155
  416. package/dist/modes/interactive/components/session-selector-search.js.map +0 -1
  417. package/dist/modes/interactive/components/session-selector.d.ts +0 -96
  418. package/dist/modes/interactive/components/session-selector.d.ts.map +0 -1
  419. package/dist/modes/interactive/components/session-selector.js +0 -861
  420. package/dist/modes/interactive/components/session-selector.js.map +0 -1
  421. package/dist/modes/interactive/components/settings-selector.d.ts +0 -69
  422. package/dist/modes/interactive/components/settings-selector.d.ts.map +0 -1
  423. package/dist/modes/interactive/components/settings-selector.js +0 -390
  424. package/dist/modes/interactive/components/settings-selector.js.map +0 -1
  425. package/dist/modes/interactive/components/show-images-selector.d.ts +0 -10
  426. package/dist/modes/interactive/components/show-images-selector.d.ts.map +0 -1
  427. package/dist/modes/interactive/components/show-images-selector.js +0 -39
  428. package/dist/modes/interactive/components/show-images-selector.js.map +0 -1
  429. package/dist/modes/interactive/components/skill-invocation-message.d.ts +0 -17
  430. package/dist/modes/interactive/components/skill-invocation-message.d.ts.map +0 -1
  431. package/dist/modes/interactive/components/skill-invocation-message.js +0 -47
  432. package/dist/modes/interactive/components/skill-invocation-message.js.map +0 -1
  433. package/dist/modes/interactive/components/theme-selector.d.ts +0 -11
  434. package/dist/modes/interactive/components/theme-selector.d.ts.map +0 -1
  435. package/dist/modes/interactive/components/theme-selector.js +0 -50
  436. package/dist/modes/interactive/components/theme-selector.js.map +0 -1
  437. package/dist/modes/interactive/components/thinking-selector.d.ts +0 -11
  438. package/dist/modes/interactive/components/thinking-selector.d.ts.map +0 -1
  439. package/dist/modes/interactive/components/thinking-selector.js +0 -51
  440. package/dist/modes/interactive/components/thinking-selector.js.map +0 -1
  441. package/dist/modes/interactive/components/tool-execution.d.ts +0 -63
  442. package/dist/modes/interactive/components/tool-execution.d.ts.map +0 -1
  443. package/dist/modes/interactive/components/tool-execution.js +0 -295
  444. package/dist/modes/interactive/components/tool-execution.js.map +0 -1
  445. package/dist/modes/interactive/components/tree-selector.d.ts +0 -89
  446. package/dist/modes/interactive/components/tree-selector.d.ts.map +0 -1
  447. package/dist/modes/interactive/components/tree-selector.js +0 -1093
  448. package/dist/modes/interactive/components/tree-selector.js.map +0 -1
  449. package/dist/modes/interactive/components/user-message-selector.d.ts +0 -30
  450. package/dist/modes/interactive/components/user-message-selector.d.ts.map +0 -1
  451. package/dist/modes/interactive/components/user-message-selector.js +0 -114
  452. package/dist/modes/interactive/components/user-message-selector.js.map +0 -1
  453. package/dist/modes/interactive/components/user-message.d.ts +0 -10
  454. package/dist/modes/interactive/components/user-message.d.ts.map +0 -1
  455. package/dist/modes/interactive/components/user-message.js +0 -29
  456. package/dist/modes/interactive/components/user-message.js.map +0 -1
  457. package/dist/modes/interactive/components/visual-truncate.d.ts +0 -24
  458. package/dist/modes/interactive/components/visual-truncate.d.ts.map +0 -1
  459. package/dist/modes/interactive/components/visual-truncate.js +0 -33
  460. package/dist/modes/interactive/components/visual-truncate.js.map +0 -1
  461. package/dist/modes/interactive/interactive-mode.d.ts +0 -373
  462. package/dist/modes/interactive/interactive-mode.d.ts.map +0 -1
  463. package/dist/modes/interactive/interactive-mode.js +0 -4750
  464. package/dist/modes/interactive/interactive-mode.js.map +0 -1
  465. package/dist/modes/interactive/theme/dark.json +0 -86
  466. package/dist/modes/interactive/theme/light.json +0 -85
  467. package/dist/modes/interactive/theme/theme-schema.json +0 -335
  468. package/dist/modes/interactive/theme/theme.d.ts +0 -100
  469. package/dist/modes/interactive/theme/theme.d.ts.map +0 -1
  470. package/dist/modes/interactive/theme/theme.js +0 -1015
  471. package/dist/modes/interactive/theme/theme.js.map +0 -1
  472. package/dist/modes/print-mode.d.ts +0 -28
  473. package/dist/modes/print-mode.d.ts.map +0 -1
  474. package/dist/modes/print-mode.js +0 -131
  475. package/dist/modes/print-mode.js.map +0 -1
  476. package/dist/modes/rpc/jsonl.d.ts +0 -17
  477. package/dist/modes/rpc/jsonl.d.ts.map +0 -1
  478. package/dist/modes/rpc/jsonl.js +0 -49
  479. package/dist/modes/rpc/jsonl.js.map +0 -1
  480. package/dist/modes/rpc/rpc-client.d.ts +0 -228
  481. package/dist/modes/rpc/rpc-client.d.ts.map +0 -1
  482. package/dist/modes/rpc/rpc-client.js +0 -416
  483. package/dist/modes/rpc/rpc-client.js.map +0 -1
  484. package/dist/modes/rpc/rpc-mode.d.ts +0 -20
  485. package/dist/modes/rpc/rpc-mode.d.ts.map +0 -1
  486. package/dist/modes/rpc/rpc-mode.js +0 -609
  487. package/dist/modes/rpc/rpc-mode.js.map +0 -1
  488. package/dist/modes/rpc/rpc-types.d.ts +0 -428
  489. package/dist/modes/rpc/rpc-types.d.ts.map +0 -1
  490. package/dist/modes/rpc/rpc-types.js +0 -8
  491. package/dist/modes/rpc/rpc-types.js.map +0 -1
  492. package/dist/modes/web/web-mode.d.ts +0 -3
  493. package/dist/modes/web/web-mode.d.ts.map +0 -1
  494. package/dist/modes/web/web-mode.js +0 -244
  495. package/dist/modes/web/web-mode.js.map +0 -1
  496. package/dist/package-manager-cli.d.ts +0 -4
  497. package/dist/package-manager-cli.d.ts.map +0 -1
  498. package/dist/package-manager-cli.js +0 -515
  499. package/dist/package-manager-cli.js.map +0 -1
  500. package/dist/utils/ansi.d.ts +0 -2
  501. package/dist/utils/ansi.d.ts.map +0 -1
  502. package/dist/utils/ansi.js +0 -52
  503. package/dist/utils/ansi.js.map +0 -1
  504. package/dist/utils/changelog.d.ts +0 -21
  505. package/dist/utils/changelog.d.ts.map +0 -1
  506. package/dist/utils/changelog.js +0 -87
  507. package/dist/utils/changelog.js.map +0 -1
  508. package/dist/utils/child-process.d.ts +0 -15
  509. package/dist/utils/child-process.d.ts.map +0 -1
  510. package/dist/utils/child-process.js +0 -88
  511. package/dist/utils/child-process.js.map +0 -1
  512. package/dist/utils/clipboard-image.d.ts +0 -11
  513. package/dist/utils/clipboard-image.d.ts.map +0 -1
  514. package/dist/utils/clipboard-image.js +0 -245
  515. package/dist/utils/clipboard-image.js.map +0 -1
  516. package/dist/utils/clipboard-native.d.ts +0 -8
  517. package/dist/utils/clipboard-native.d.ts.map +0 -1
  518. package/dist/utils/clipboard-native.js +0 -14
  519. package/dist/utils/clipboard-native.js.map +0 -1
  520. package/dist/utils/clipboard.d.ts +0 -2
  521. package/dist/utils/clipboard.d.ts.map +0 -1
  522. package/dist/utils/clipboard.js +0 -117
  523. package/dist/utils/clipboard.js.map +0 -1
  524. package/dist/utils/exif-orientation.d.ts +0 -5
  525. package/dist/utils/exif-orientation.d.ts.map +0 -1
  526. package/dist/utils/exif-orientation.js +0 -158
  527. package/dist/utils/exif-orientation.js.map +0 -1
  528. package/dist/utils/frontmatter.d.ts +0 -8
  529. package/dist/utils/frontmatter.d.ts.map +0 -1
  530. package/dist/utils/frontmatter.js +0 -26
  531. package/dist/utils/frontmatter.js.map +0 -1
  532. package/dist/utils/fs-watch.d.ts +0 -5
  533. package/dist/utils/fs-watch.d.ts.map +0 -1
  534. package/dist/utils/fs-watch.js +0 -25
  535. package/dist/utils/fs-watch.js.map +0 -1
  536. package/dist/utils/git.d.ts +0 -26
  537. package/dist/utils/git.d.ts.map +0 -1
  538. package/dist/utils/git.js +0 -163
  539. package/dist/utils/git.js.map +0 -1
  540. package/dist/utils/html.d.ts +0 -7
  541. package/dist/utils/html.d.ts.map +0 -1
  542. package/dist/utils/html.js +0 -40
  543. package/dist/utils/html.js.map +0 -1
  544. package/dist/utils/image-convert.d.ts +0 -9
  545. package/dist/utils/image-convert.d.ts.map +0 -1
  546. package/dist/utils/image-convert.js +0 -39
  547. package/dist/utils/image-convert.js.map +0 -1
  548. package/dist/utils/image-resize.d.ts +0 -36
  549. package/dist/utils/image-resize.d.ts.map +0 -1
  550. package/dist/utils/image-resize.js +0 -137
  551. package/dist/utils/image-resize.js.map +0 -1
  552. package/dist/utils/mime.d.ts +0 -3
  553. package/dist/utils/mime.d.ts.map +0 -1
  554. package/dist/utils/mime.js +0 -69
  555. package/dist/utils/mime.js.map +0 -1
  556. package/dist/utils/paths.d.ts +0 -17
  557. package/dist/utils/paths.d.ts.map +0 -1
  558. package/dist/utils/paths.js +0 -66
  559. package/dist/utils/paths.js.map +0 -1
  560. package/dist/utils/photon.d.ts +0 -21
  561. package/dist/utils/photon.d.ts.map +0 -1
  562. package/dist/utils/photon.js +0 -121
  563. package/dist/utils/photon.js.map +0 -1
  564. package/dist/utils/pi-user-agent.d.ts +0 -2
  565. package/dist/utils/pi-user-agent.d.ts.map +0 -1
  566. package/dist/utils/pi-user-agent.js +0 -5
  567. package/dist/utils/pi-user-agent.js.map +0 -1
  568. package/dist/utils/shell.d.ts +0 -30
  569. package/dist/utils/shell.d.ts.map +0 -1
  570. package/dist/utils/shell.js +0 -195
  571. package/dist/utils/shell.js.map +0 -1
  572. package/dist/utils/sleep.d.ts +0 -5
  573. package/dist/utils/sleep.d.ts.map +0 -1
  574. package/dist/utils/sleep.js +0 -17
  575. package/dist/utils/sleep.js.map +0 -1
  576. package/dist/utils/syntax-highlight.d.ts +0 -12
  577. package/dist/utils/syntax-highlight.d.ts.map +0 -1
  578. package/dist/utils/syntax-highlight.js +0 -118
  579. package/dist/utils/syntax-highlight.js.map +0 -1
  580. package/dist/utils/tools-manager.d.ts +0 -3
  581. package/dist/utils/tools-manager.d.ts.map +0 -1
  582. package/dist/utils/tools-manager.js +0 -328
  583. package/dist/utils/tools-manager.js.map +0 -1
  584. package/dist/utils/version-check.d.ts +0 -15
  585. package/dist/utils/version-check.d.ts.map +0 -1
  586. package/dist/utils/version-check.js +0 -82
  587. package/dist/utils/version-check.js.map +0 -1
  588. package/dist/utils/windows-self-update.d.ts +0 -3
  589. package/dist/utils/windows-self-update.d.ts.map +0 -1
  590. package/dist/utils/windows-self-update.js +0 -77
  591. package/dist/utils/windows-self-update.js.map +0 -1
@@ -1 +0,0 @@
1
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O,EAAE,MAAM,EACf,OAAO,CAAC,EAAE;QAAE,QAAQ,CAAC,EAAE,QAAQ,GAAG,IAAI,CAAC;QAAC,WAAW,CAAC,EAAE,CAAC,GAAG,EAAE,sBAAsB,KAAK,OAAO,CAAC,IAAI,CAAC,CAAA;KAAE,GACpG,OAAO,CAAC;QAAE,SAAS,EAAE,OAAO,CAAC;QAAC,YAAY,CAAC,EAAE,MAAM,CAAA;KAAE,CAAC,CAkFxD;IAED;;;;;;OAMG;IACG,eAAe,CAAC,SAAS,EAAE,MAAM,EAAE,WAAW,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC;QAAE,SAAS,EAAE,OAAO,CAAA;KAAE,CAAC,CAmC9F;IAEK,OAAO,IAAI,OAAO,CAAC,IAAI,CAAC,CAO7B;CACD;AAED;;;;;GAKG;AACH,wBAAsB,yBAAyB,CAC9C,aAAa,EAAE,gCAAgC,EAC/C,OAAO,EAAE;IACR,GAAG,EAAE,MAAM,CAAC;IACZ,QAAQ,EAAE,MAAM,CAAC;IACjB,cAAc,EAAE,cAAc,CAAC;IAC/B,iBAAiB,CAAC,EAAE,iBAAiB,CAAC;CACtC,GACC,OAAO,CAAC,mBAAmB,CAAC,CAU9B;AAED,OAAO,EACN,KAAK,6BAA6B,EAClC,KAAK,oBAAoB,EACzB,KAAK,qCAAqC,EAC1C,KAAK,iCAAiC,EACtC,8BAA8B,EAC9B,0BAA0B,GAC1B,MAAM,6BAA6B,CAAC","sourcesContent":["import { copyFileSync, existsSync, mkdirSync } from \"node:fs\";\nimport { basename, join, resolve } from \"node:path\";\nimport type { AgentSession } from \"./agent-session.ts\";\nimport type { AgentSessionRuntimeDiagnostic, AgentSessionServices } from \"./agent-session-services.ts\";\nimport type { ReplacedSessionContext, SessionShutdownEvent, SessionStartEvent } from \"./extensions/index.ts\";\nimport { emitSessionShutdownEvent } from \"./extensions/runner.ts\";\nimport type { CreateAgentSessionResult } from \"./sdk.ts\";\nimport { assertSessionCwdExists } from \"./session-cwd.ts\";\nimport { SessionManager } from \"./session-manager.ts\";\n\n/**\n * Result returned by runtime creation.\n *\n * The caller gets the created session, its cwd-bound services, and all\n * diagnostics collected during setup.\n */\nexport interface CreateAgentSessionRuntimeResult extends CreateAgentSessionResult {\n\tservices: AgentSessionServices;\n\tdiagnostics: AgentSessionRuntimeDiagnostic[];\n}\n\n/**\n * Creates a full runtime for a target cwd and session manager.\n *\n * The factory closes over process-global fixed inputs, recreates cwd-bound\n * services for the effective cwd, resolves session options against those\n * services, and finally creates the AgentSession.\n */\nexport type CreateAgentSessionRuntimeFactory = (options: {\n\tcwd: string;\n\tagentDir: string;\n\tsessionManager: SessionManager;\n\tsessionStartEvent?: SessionStartEvent;\n}) => Promise<CreateAgentSessionRuntimeResult>;\n\n/**\n * Thrown when /import references a JSONL file path that does not exist.\n */\nexport class SessionImportFileNotFoundError extends Error {\n\treadonly filePath: string;\n\n\tconstructor(filePath: string) {\n\t\tsuper(`File not found: ${filePath}`);\n\t\tthis.name = \"SessionImportFileNotFoundError\";\n\t\tthis.filePath = filePath;\n\t}\n}\n\nfunction extractUserMessageText(content: string | Array<{ type: string; text?: string }>): string {\n\tif (typeof content === \"string\") {\n\t\treturn content;\n\t}\n\n\treturn content\n\t\t.filter((part): part is { type: \"text\"; text: string } => part.type === \"text\" && typeof part.text === \"string\")\n\t\t.map((part) => part.text)\n\t\t.join(\"\");\n}\n\n/**\n * Owns the current AgentSession plus its cwd-bound services.\n *\n * Session replacement methods tear down the current runtime first, then create\n * and apply the next runtime. If creation fails, the error is propagated to the\n * caller. The caller is responsible for user-facing error handling.\n */\nexport class AgentSessionRuntime {\n\tprivate rebindSession?: (session: AgentSession) => Promise<void>;\n\tprivate beforeSessionInvalidate?: () => void;\n\tprivate _session: AgentSession;\n\tprivate _services: AgentSessionServices;\n\tprivate readonly createRuntime: CreateAgentSessionRuntimeFactory;\n\tprivate _diagnostics: AgentSessionRuntimeDiagnostic[];\n\tprivate _modelFallbackMessage?: string;\n\n\tconstructor(\n\t\t_session: AgentSession,\n\t\t_services: AgentSessionServices,\n\t\tcreateRuntime: CreateAgentSessionRuntimeFactory,\n\t\t_diagnostics: AgentSessionRuntimeDiagnostic[] = [],\n\t\t_modelFallbackMessage?: string,\n\t) {\n\t\tthis._session = _session;\n\t\tthis._services = _services;\n\t\tthis.createRuntime = createRuntime;\n\t\tthis._diagnostics = _diagnostics;\n\t\tthis._modelFallbackMessage = _modelFallbackMessage;\n\t}\n\n\tget services(): AgentSessionServices {\n\t\treturn this._services;\n\t}\n\n\tget session(): AgentSession {\n\t\treturn this._session;\n\t}\n\n\tget cwd(): string {\n\t\treturn this._services.cwd;\n\t}\n\n\tget diagnostics(): readonly AgentSessionRuntimeDiagnostic[] {\n\t\treturn this._diagnostics;\n\t}\n\n\tget modelFallbackMessage(): string | undefined {\n\t\treturn this._modelFallbackMessage;\n\t}\n\n\tsetRebindSession(rebindSession?: (session: AgentSession) => Promise<void>): void {\n\t\tthis.rebindSession = rebindSession;\n\t}\n\n\t/**\n\t * Set a synchronous callback that runs after `session_shutdown` handlers finish\n\t * but before the current session is invalidated.\n\t *\n\t * This is for host-owned UI teardown that must not yield to the event loop,\n\t * such as detaching extension-provided TUI components before the old extension\n\t * context becomes stale.\n\t */\n\tsetBeforeSessionInvalidate(beforeSessionInvalidate?: () => void): void {\n\t\tthis.beforeSessionInvalidate = beforeSessionInvalidate;\n\t}\n\n\tprivate async emitBeforeSwitch(\n\t\treason: \"new\" | \"resume\",\n\t\ttargetSessionFile?: string,\n\t): Promise<{ cancelled: boolean }> {\n\t\tconst runner = this.session.extensionRunner;\n\t\tif (!runner.hasHandlers(\"session_before_switch\")) {\n\t\t\treturn { cancelled: false };\n\t\t}\n\n\t\tconst result = await runner.emit({\n\t\t\ttype: \"session_before_switch\",\n\t\t\treason,\n\t\t\ttargetSessionFile,\n\t\t});\n\t\treturn { cancelled: result?.cancel === true };\n\t}\n\n\tprivate async emitBeforeFork(\n\t\tentryId: string,\n\t\toptions: { position: \"before\" | \"at\" },\n\t): Promise<{ cancelled: boolean }> {\n\t\tconst runner = this.session.extensionRunner;\n\t\tif (!runner.hasHandlers(\"session_before_fork\")) {\n\t\t\treturn { cancelled: false };\n\t\t}\n\n\t\tconst result = await runner.emit({\n\t\t\ttype: \"session_before_fork\",\n\t\t\tentryId,\n\t\t\t...options,\n\t\t});\n\t\treturn { cancelled: result?.cancel === true };\n\t}\n\n\tprivate async teardownCurrent(reason: SessionShutdownEvent[\"reason\"], targetSessionFile?: string): Promise<void> {\n\t\tawait emitSessionShutdownEvent(this.session.extensionRunner, {\n\t\t\ttype: \"session_shutdown\",\n\t\t\treason,\n\t\t\ttargetSessionFile,\n\t\t});\n\t\tthis.beforeSessionInvalidate?.();\n\t\tthis.session.dispose();\n\t}\n\n\tprivate apply(result: CreateAgentSessionRuntimeResult): void {\n\t\tthis._session = result.session;\n\t\tthis._services = result.services;\n\t\tthis._diagnostics = result.diagnostics;\n\t\tthis._modelFallbackMessage = result.modelFallbackMessage;\n\t}\n\n\tprivate async finishSessionReplacement(withSession?: (ctx: ReplacedSessionContext) => Promise<void>): Promise<void> {\n\t\tif (this.rebindSession) {\n\t\t\tawait this.rebindSession(this.session);\n\t\t}\n\t\tif (withSession) {\n\t\t\tawait withSession(this.session.createReplacedSessionContext());\n\t\t}\n\t}\n\n\tasync switchSession(\n\t\tsessionPath: string,\n\t\toptions?: { cwdOverride?: string; withSession?: (ctx: ReplacedSessionContext) => Promise<void> },\n\t): Promise<{ cancelled: boolean }> {\n\t\tconst beforeResult = await this.emitBeforeSwitch(\"resume\", sessionPath);\n\t\tif (beforeResult.cancelled) {\n\t\t\treturn beforeResult;\n\t\t}\n\n\t\tconst previousSessionFile = this.session.sessionFile;\n\t\tconst sessionManager = SessionManager.open(sessionPath, undefined, options?.cwdOverride);\n\t\tassertSessionCwdExists(sessionManager, this.cwd);\n\t\tawait this.teardownCurrent(\"resume\", sessionManager.getSessionFile());\n\t\tthis.apply(\n\t\t\tawait this.createRuntime({\n\t\t\t\tcwd: sessionManager.getCwd(),\n\t\t\t\tagentDir: this.services.agentDir,\n\t\t\t\tsessionManager,\n\t\t\t\tsessionStartEvent: { type: \"session_start\", reason: \"resume\", previousSessionFile },\n\t\t\t}),\n\t\t);\n\t\tawait this.finishSessionReplacement(options?.withSession);\n\t\treturn { cancelled: false };\n\t}\n\n\tasync newSession(options?: {\n\t\tparentSession?: string;\n\t\tsetup?: (sessionManager: SessionManager) => Promise<void>;\n\t\twithSession?: (ctx: ReplacedSessionContext) => Promise<void>;\n\t}): Promise<{ cancelled: boolean }> {\n\t\tconst beforeResult = await this.emitBeforeSwitch(\"new\");\n\t\tif (beforeResult.cancelled) {\n\t\t\treturn beforeResult;\n\t\t}\n\n\t\tconst previousSessionFile = this.session.sessionFile;\n\t\tconst sessionDir = this.session.sessionManager.getSessionDir();\n\t\tconst sessionManager = SessionManager.create(this.cwd, sessionDir);\n\t\tif (options?.parentSession) {\n\t\t\tsessionManager.newSession({ parentSession: options.parentSession });\n\t\t}\n\n\t\tawait this.teardownCurrent(\"new\", sessionManager.getSessionFile());\n\t\tthis.apply(\n\t\t\tawait this.createRuntime({\n\t\t\t\tcwd: this.cwd,\n\t\t\t\tagentDir: this.services.agentDir,\n\t\t\t\tsessionManager,\n\t\t\t\tsessionStartEvent: { type: \"session_start\", reason: \"new\", previousSessionFile },\n\t\t\t}),\n\t\t);\n\t\tif (options?.setup) {\n\t\t\tawait options.setup(this.session.sessionManager);\n\t\t\tthis.session.agent.state.messages = this.session.sessionManager.buildSessionContext().messages;\n\t\t}\n\t\tawait this.finishSessionReplacement(options?.withSession);\n\t\treturn { cancelled: false };\n\t}\n\n\tasync fork(\n\t\tentryId: string,\n\t\toptions?: { position?: \"before\" | \"at\"; withSession?: (ctx: ReplacedSessionContext) => Promise<void> },\n\t): Promise<{ cancelled: boolean; selectedText?: string }> {\n\t\tconst position = options?.position ?? \"before\";\n\t\tconst beforeResult = await this.emitBeforeFork(entryId, { position });\n\t\tif (beforeResult.cancelled) {\n\t\t\treturn { cancelled: true };\n\t\t}\n\t\tlet targetLeafId: string | null;\n\t\tlet selectedText: string | undefined;\n\n\t\tconst selectedEntry = this.session.sessionManager.getEntry(entryId);\n\t\tif (!selectedEntry) {\n\t\t\tthrow new Error(\"Invalid entry ID for forking\");\n\t\t}\n\n\t\tif (position === \"at\") {\n\t\t\ttargetLeafId = selectedEntry.id;\n\t\t} else {\n\t\t\tif (selectedEntry.type !== \"message\" || selectedEntry.message.role !== \"user\") {\n\t\t\t\tthrow new Error(\"Invalid entry ID for forking\");\n\t\t\t}\n\t\t\ttargetLeafId = selectedEntry.parentId;\n\t\t\tselectedText = extractUserMessageText(selectedEntry.message.content);\n\t\t}\n\n\t\tconst previousSessionFile = this.session.sessionFile;\n\t\tif (this.session.sessionManager.isPersisted()) {\n\t\t\tconst currentSessionFile = this.session.sessionFile;\n\t\t\tif (!currentSessionFile) {\n\t\t\t\tthrow new Error(\"Persisted session is missing a session file\");\n\t\t\t}\n\t\t\tconst sessionDir = this.session.sessionManager.getSessionDir();\n\t\t\tif (!targetLeafId) {\n\t\t\t\tconst sessionManager = SessionManager.create(this.cwd, sessionDir);\n\t\t\t\tsessionManager.newSession({ parentSession: currentSessionFile });\n\t\t\t\tawait this.teardownCurrent(\"fork\", sessionManager.getSessionFile());\n\t\t\t\tthis.apply(\n\t\t\t\t\tawait this.createRuntime({\n\t\t\t\t\t\tcwd: this.cwd,\n\t\t\t\t\t\tagentDir: this.services.agentDir,\n\t\t\t\t\t\tsessionManager,\n\t\t\t\t\t\tsessionStartEvent: { type: \"session_start\", reason: \"fork\", previousSessionFile },\n\t\t\t\t\t}),\n\t\t\t\t);\n\t\t\t\tawait this.finishSessionReplacement(options?.withSession);\n\t\t\t\treturn { cancelled: false, selectedText };\n\t\t\t}\n\n\t\t\tconst sessionManager = SessionManager.open(currentSessionFile, sessionDir);\n\t\t\tconst forkedSessionPath = sessionManager.createBranchedSession(targetLeafId);\n\t\t\tif (!forkedSessionPath) {\n\t\t\t\tthrow new Error(\"Failed to create forked session\");\n\t\t\t}\n\t\t\tawait this.teardownCurrent(\"fork\", sessionManager.getSessionFile());\n\t\t\tthis.apply(\n\t\t\t\tawait this.createRuntime({\n\t\t\t\t\tcwd: sessionManager.getCwd(),\n\t\t\t\t\tagentDir: this.services.agentDir,\n\t\t\t\t\tsessionManager,\n\t\t\t\t\tsessionStartEvent: { type: \"session_start\", reason: \"fork\", previousSessionFile },\n\t\t\t\t}),\n\t\t\t);\n\t\t\tawait this.finishSessionReplacement(options?.withSession);\n\t\t\treturn { cancelled: false, selectedText };\n\t\t}\n\n\t\tconst sessionManager = this.session.sessionManager;\n\t\tif (!targetLeafId) {\n\t\t\tsessionManager.newSession({ parentSession: this.session.sessionFile });\n\t\t} else {\n\t\t\tsessionManager.createBranchedSession(targetLeafId);\n\t\t}\n\t\tawait this.teardownCurrent(\"fork\", sessionManager.getSessionFile());\n\t\tthis.apply(\n\t\t\tawait this.createRuntime({\n\t\t\t\tcwd: this.cwd,\n\t\t\t\tagentDir: this.services.agentDir,\n\t\t\t\tsessionManager,\n\t\t\t\tsessionStartEvent: { type: \"session_start\", reason: \"fork\", previousSessionFile },\n\t\t\t}),\n\t\t);\n\t\tawait this.finishSessionReplacement(options?.withSession);\n\t\treturn { cancelled: false, selectedText };\n\t}\n\n\t/**\n\t * Import a session JSONL file and switch runtime state to the imported session.\n\t *\n\t * @returns `{ cancelled: true }` when cancelled by `session_before_switch`, otherwise `{ cancelled: false }`.\n\t * @throws {SessionImportFileNotFoundError} When the input path does not exist.\n\t * @throws {MissingSessionCwdError} When the imported session cwd cannot be resolved and no override is provided.\n\t */\n\tasync importFromJsonl(inputPath: string, cwdOverride?: string): Promise<{ cancelled: boolean }> {\n\t\tconst resolvedPath = resolve(inputPath);\n\t\tif (!existsSync(resolvedPath)) {\n\t\t\tthrow new SessionImportFileNotFoundError(resolvedPath);\n\t\t}\n\n\t\tconst sessionDir = this.session.sessionManager.getSessionDir();\n\t\tif (!existsSync(sessionDir)) {\n\t\t\tmkdirSync(sessionDir, { recursive: true });\n\t\t}\n\n\t\tconst destinationPath = join(sessionDir, basename(resolvedPath));\n\t\tconst beforeResult = await this.emitBeforeSwitch(\"resume\", destinationPath);\n\t\tif (beforeResult.cancelled) {\n\t\t\treturn beforeResult;\n\t\t}\n\n\t\tconst previousSessionFile = this.session.sessionFile;\n\t\tif (resolve(destinationPath) !== resolvedPath) {\n\t\t\tcopyFileSync(resolvedPath, destinationPath);\n\t\t}\n\n\t\tconst sessionManager = SessionManager.open(destinationPath, sessionDir, cwdOverride);\n\t\tassertSessionCwdExists(sessionManager, this.cwd);\n\t\tawait this.teardownCurrent(\"resume\", sessionManager.getSessionFile());\n\t\tthis.apply(\n\t\t\tawait this.createRuntime({\n\t\t\t\tcwd: sessionManager.getCwd(),\n\t\t\t\tagentDir: this.services.agentDir,\n\t\t\t\tsessionManager,\n\t\t\t\tsessionStartEvent: { type: \"session_start\", reason: \"resume\", previousSessionFile },\n\t\t\t}),\n\t\t);\n\t\tawait this.finishSessionReplacement();\n\t\treturn { cancelled: false };\n\t}\n\n\tasync dispose(): Promise<void> {\n\t\tawait emitSessionShutdownEvent(this.session.extensionRunner, {\n\t\t\ttype: \"session_shutdown\",\n\t\t\treason: \"quit\",\n\t\t});\n\t\tthis.beforeSessionInvalidate?.();\n\t\tthis.session.dispose();\n\t}\n}\n\n/**\n * Create the initial runtime from a runtime factory and initial session target.\n *\n * The same factory is stored on the returned AgentSessionRuntime and reused for\n * later /new, /resume, /fork, and import flows.\n */\nexport async function createAgentSessionRuntime(\n\tcreateRuntime: CreateAgentSessionRuntimeFactory,\n\toptions: {\n\t\tcwd: string;\n\t\tagentDir: string;\n\t\tsessionManager: SessionManager;\n\t\tsessionStartEvent?: SessionStartEvent;\n\t},\n): Promise<AgentSessionRuntime> {\n\tassertSessionCwdExists(options.sessionManager, options.cwd);\n\tconst result = await createRuntime(options);\n\treturn new AgentSessionRuntime(\n\t\tresult.session,\n\t\tresult.services,\n\t\tcreateRuntime,\n\t\tresult.diagnostics,\n\t\tresult.modelFallbackMessage,\n\t);\n}\n\nexport {\n\ttype AgentSessionRuntimeDiagnostic,\n\ttype AgentSessionServices,\n\ttype CreateAgentSessionFromServicesOptions,\n\ttype CreateAgentSessionServicesOptions,\n\tcreateAgentSessionFromServices,\n\tcreateAgentSessionServices,\n} from \"./agent-session-services.ts\";\n"]}
@@ -1,299 +0,0 @@
1
- import { copyFileSync, existsSync, mkdirSync } from "node:fs";
2
- import { basename, join, resolve } from "node:path";
3
- import { emitSessionShutdownEvent } from "./extensions/runner.js";
4
- import { assertSessionCwdExists } from "./session-cwd.js";
5
- import { SessionManager } from "./session-manager.js";
6
- /**
7
- * Thrown when /import references a JSONL file path that does not exist.
8
- */
9
- export class SessionImportFileNotFoundError extends Error {
10
- filePath;
11
- constructor(filePath) {
12
- super(`File not found: ${filePath}`);
13
- this.name = "SessionImportFileNotFoundError";
14
- this.filePath = filePath;
15
- }
16
- }
17
- function extractUserMessageText(content) {
18
- if (typeof content === "string") {
19
- return content;
20
- }
21
- return content
22
- .filter((part) => part.type === "text" && typeof part.text === "string")
23
- .map((part) => part.text)
24
- .join("");
25
- }
26
- /**
27
- * Owns the current AgentSession plus its cwd-bound services.
28
- *
29
- * Session replacement methods tear down the current runtime first, then create
30
- * and apply the next runtime. If creation fails, the error is propagated to the
31
- * caller. The caller is responsible for user-facing error handling.
32
- */
33
- export class AgentSessionRuntime {
34
- rebindSession;
35
- beforeSessionInvalidate;
36
- _session;
37
- _services;
38
- createRuntime;
39
- _diagnostics;
40
- _modelFallbackMessage;
41
- constructor(_session, _services, createRuntime, _diagnostics = [], _modelFallbackMessage) {
42
- this._session = _session;
43
- this._services = _services;
44
- this.createRuntime = createRuntime;
45
- this._diagnostics = _diagnostics;
46
- this._modelFallbackMessage = _modelFallbackMessage;
47
- }
48
- get services() {
49
- return this._services;
50
- }
51
- get session() {
52
- return this._session;
53
- }
54
- get cwd() {
55
- return this._services.cwd;
56
- }
57
- get diagnostics() {
58
- return this._diagnostics;
59
- }
60
- get modelFallbackMessage() {
61
- return this._modelFallbackMessage;
62
- }
63
- setRebindSession(rebindSession) {
64
- this.rebindSession = rebindSession;
65
- }
66
- /**
67
- * Set a synchronous callback that runs after `session_shutdown` handlers finish
68
- * but before the current session is invalidated.
69
- *
70
- * This is for host-owned UI teardown that must not yield to the event loop,
71
- * such as detaching extension-provided TUI components before the old extension
72
- * context becomes stale.
73
- */
74
- setBeforeSessionInvalidate(beforeSessionInvalidate) {
75
- this.beforeSessionInvalidate = beforeSessionInvalidate;
76
- }
77
- async emitBeforeSwitch(reason, targetSessionFile) {
78
- const runner = this.session.extensionRunner;
79
- if (!runner.hasHandlers("session_before_switch")) {
80
- return { cancelled: false };
81
- }
82
- const result = await runner.emit({
83
- type: "session_before_switch",
84
- reason,
85
- targetSessionFile,
86
- });
87
- return { cancelled: result?.cancel === true };
88
- }
89
- async emitBeforeFork(entryId, options) {
90
- const runner = this.session.extensionRunner;
91
- if (!runner.hasHandlers("session_before_fork")) {
92
- return { cancelled: false };
93
- }
94
- const result = await runner.emit({
95
- type: "session_before_fork",
96
- entryId,
97
- ...options,
98
- });
99
- return { cancelled: result?.cancel === true };
100
- }
101
- async teardownCurrent(reason, targetSessionFile) {
102
- await emitSessionShutdownEvent(this.session.extensionRunner, {
103
- type: "session_shutdown",
104
- reason,
105
- targetSessionFile,
106
- });
107
- this.beforeSessionInvalidate?.();
108
- this.session.dispose();
109
- }
110
- apply(result) {
111
- this._session = result.session;
112
- this._services = result.services;
113
- this._diagnostics = result.diagnostics;
114
- this._modelFallbackMessage = result.modelFallbackMessage;
115
- }
116
- async finishSessionReplacement(withSession) {
117
- if (this.rebindSession) {
118
- await this.rebindSession(this.session);
119
- }
120
- if (withSession) {
121
- await withSession(this.session.createReplacedSessionContext());
122
- }
123
- }
124
- async switchSession(sessionPath, options) {
125
- const beforeResult = await this.emitBeforeSwitch("resume", sessionPath);
126
- if (beforeResult.cancelled) {
127
- return beforeResult;
128
- }
129
- const previousSessionFile = this.session.sessionFile;
130
- const sessionManager = SessionManager.open(sessionPath, undefined, options?.cwdOverride);
131
- assertSessionCwdExists(sessionManager, this.cwd);
132
- await this.teardownCurrent("resume", sessionManager.getSessionFile());
133
- this.apply(await this.createRuntime({
134
- cwd: sessionManager.getCwd(),
135
- agentDir: this.services.agentDir,
136
- sessionManager,
137
- sessionStartEvent: { type: "session_start", reason: "resume", previousSessionFile },
138
- }));
139
- await this.finishSessionReplacement(options?.withSession);
140
- return { cancelled: false };
141
- }
142
- async newSession(options) {
143
- const beforeResult = await this.emitBeforeSwitch("new");
144
- if (beforeResult.cancelled) {
145
- return beforeResult;
146
- }
147
- const previousSessionFile = this.session.sessionFile;
148
- const sessionDir = this.session.sessionManager.getSessionDir();
149
- const sessionManager = SessionManager.create(this.cwd, sessionDir);
150
- if (options?.parentSession) {
151
- sessionManager.newSession({ parentSession: options.parentSession });
152
- }
153
- await this.teardownCurrent("new", sessionManager.getSessionFile());
154
- this.apply(await this.createRuntime({
155
- cwd: this.cwd,
156
- agentDir: this.services.agentDir,
157
- sessionManager,
158
- sessionStartEvent: { type: "session_start", reason: "new", previousSessionFile },
159
- }));
160
- if (options?.setup) {
161
- await options.setup(this.session.sessionManager);
162
- this.session.agent.state.messages = this.session.sessionManager.buildSessionContext().messages;
163
- }
164
- await this.finishSessionReplacement(options?.withSession);
165
- return { cancelled: false };
166
- }
167
- async fork(entryId, options) {
168
- const position = options?.position ?? "before";
169
- const beforeResult = await this.emitBeforeFork(entryId, { position });
170
- if (beforeResult.cancelled) {
171
- return { cancelled: true };
172
- }
173
- let targetLeafId;
174
- let selectedText;
175
- const selectedEntry = this.session.sessionManager.getEntry(entryId);
176
- if (!selectedEntry) {
177
- throw new Error("Invalid entry ID for forking");
178
- }
179
- if (position === "at") {
180
- targetLeafId = selectedEntry.id;
181
- }
182
- else {
183
- if (selectedEntry.type !== "message" || selectedEntry.message.role !== "user") {
184
- throw new Error("Invalid entry ID for forking");
185
- }
186
- targetLeafId = selectedEntry.parentId;
187
- selectedText = extractUserMessageText(selectedEntry.message.content);
188
- }
189
- const previousSessionFile = this.session.sessionFile;
190
- if (this.session.sessionManager.isPersisted()) {
191
- const currentSessionFile = this.session.sessionFile;
192
- if (!currentSessionFile) {
193
- throw new Error("Persisted session is missing a session file");
194
- }
195
- const sessionDir = this.session.sessionManager.getSessionDir();
196
- if (!targetLeafId) {
197
- const sessionManager = SessionManager.create(this.cwd, sessionDir);
198
- sessionManager.newSession({ parentSession: currentSessionFile });
199
- await this.teardownCurrent("fork", sessionManager.getSessionFile());
200
- this.apply(await this.createRuntime({
201
- cwd: this.cwd,
202
- agentDir: this.services.agentDir,
203
- sessionManager,
204
- sessionStartEvent: { type: "session_start", reason: "fork", previousSessionFile },
205
- }));
206
- await this.finishSessionReplacement(options?.withSession);
207
- return { cancelled: false, selectedText };
208
- }
209
- const sessionManager = SessionManager.open(currentSessionFile, sessionDir);
210
- const forkedSessionPath = sessionManager.createBranchedSession(targetLeafId);
211
- if (!forkedSessionPath) {
212
- throw new Error("Failed to create forked session");
213
- }
214
- await this.teardownCurrent("fork", sessionManager.getSessionFile());
215
- this.apply(await this.createRuntime({
216
- cwd: sessionManager.getCwd(),
217
- agentDir: this.services.agentDir,
218
- sessionManager,
219
- sessionStartEvent: { type: "session_start", reason: "fork", previousSessionFile },
220
- }));
221
- await this.finishSessionReplacement(options?.withSession);
222
- return { cancelled: false, selectedText };
223
- }
224
- const sessionManager = this.session.sessionManager;
225
- if (!targetLeafId) {
226
- sessionManager.newSession({ parentSession: this.session.sessionFile });
227
- }
228
- else {
229
- sessionManager.createBranchedSession(targetLeafId);
230
- }
231
- await this.teardownCurrent("fork", sessionManager.getSessionFile());
232
- this.apply(await this.createRuntime({
233
- cwd: this.cwd,
234
- agentDir: this.services.agentDir,
235
- sessionManager,
236
- sessionStartEvent: { type: "session_start", reason: "fork", previousSessionFile },
237
- }));
238
- await this.finishSessionReplacement(options?.withSession);
239
- return { cancelled: false, selectedText };
240
- }
241
- /**
242
- * Import a session JSONL file and switch runtime state to the imported session.
243
- *
244
- * @returns `{ cancelled: true }` when cancelled by `session_before_switch`, otherwise `{ cancelled: false }`.
245
- * @throws {SessionImportFileNotFoundError} When the input path does not exist.
246
- * @throws {MissingSessionCwdError} When the imported session cwd cannot be resolved and no override is provided.
247
- */
248
- async importFromJsonl(inputPath, cwdOverride) {
249
- const resolvedPath = resolve(inputPath);
250
- if (!existsSync(resolvedPath)) {
251
- throw new SessionImportFileNotFoundError(resolvedPath);
252
- }
253
- const sessionDir = this.session.sessionManager.getSessionDir();
254
- if (!existsSync(sessionDir)) {
255
- mkdirSync(sessionDir, { recursive: true });
256
- }
257
- const destinationPath = join(sessionDir, basename(resolvedPath));
258
- const beforeResult = await this.emitBeforeSwitch("resume", destinationPath);
259
- if (beforeResult.cancelled) {
260
- return beforeResult;
261
- }
262
- const previousSessionFile = this.session.sessionFile;
263
- if (resolve(destinationPath) !== resolvedPath) {
264
- copyFileSync(resolvedPath, destinationPath);
265
- }
266
- const sessionManager = SessionManager.open(destinationPath, sessionDir, cwdOverride);
267
- assertSessionCwdExists(sessionManager, this.cwd);
268
- await this.teardownCurrent("resume", sessionManager.getSessionFile());
269
- this.apply(await this.createRuntime({
270
- cwd: sessionManager.getCwd(),
271
- agentDir: this.services.agentDir,
272
- sessionManager,
273
- sessionStartEvent: { type: "session_start", reason: "resume", previousSessionFile },
274
- }));
275
- await this.finishSessionReplacement();
276
- return { cancelled: false };
277
- }
278
- async dispose() {
279
- await emitSessionShutdownEvent(this.session.extensionRunner, {
280
- type: "session_shutdown",
281
- reason: "quit",
282
- });
283
- this.beforeSessionInvalidate?.();
284
- this.session.dispose();
285
- }
286
- }
287
- /**
288
- * Create the initial runtime from a runtime factory and initial session target.
289
- *
290
- * The same factory is stored on the returned AgentSessionRuntime and reused for
291
- * later /new, /resume, /fork, and import flows.
292
- */
293
- export async function createAgentSessionRuntime(createRuntime, options) {
294
- assertSessionCwdExists(options.sessionManager, options.cwd);
295
- const result = await createRuntime(options);
296
- return new AgentSessionRuntime(result.session, result.services, createRuntime, result.diagnostics, result.modelFallbackMessage);
297
- }
298
- export { createAgentSessionFromServices, createAgentSessionServices, } from "./agent-session-services.js";
299
- //# sourceMappingURL=agent-session-runtime.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"agent-session-runtime.js","sourceRoot":"","sources":["../../src/core/agent-session-runtime.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,UAAU,EAAE,SAAS,EAAE,MAAM,SAAS,CAAC;AAC9D,OAAO,EAAE,QAAQ,EAAE,IAAI,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAIpD,OAAO,EAAE,wBAAwB,EAAE,MAAM,wBAAwB,CAAC;AAElE,OAAO,EAAE,sBAAsB,EAAE,MAAM,kBAAkB,CAAC;AAC1D,OAAO,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC;AA2BtD;;GAEG;AACH,MAAM,OAAO,8BAA+B,SAAQ,KAAK;IAC/C,QAAQ,CAAS;IAE1B,YAAY,QAAgB,EAAE;QAC7B,KAAK,CAAC,mBAAmB,QAAQ,EAAE,CAAC,CAAC;QACrC,IAAI,CAAC,IAAI,GAAG,gCAAgC,CAAC;QAC7C,IAAI,CAAC,QAAQ,GAAG,QAAQ,CAAC;IAAA,CACzB;CACD;AAED,SAAS,sBAAsB,CAAC,OAAwD,EAAU;IACjG,IAAI,OAAO,OAAO,KAAK,QAAQ,EAAE,CAAC;QACjC,OAAO,OAAO,CAAC;IAChB,CAAC;IAED,OAAO,OAAO;SACZ,MAAM,CAAC,CAAC,IAAI,EAA0C,EAAE,CAAC,IAAI,CAAC,IAAI,KAAK,MAAM,IAAI,OAAO,IAAI,CAAC,IAAI,KAAK,QAAQ,CAAC;SAC/G,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,IAAI,CAAC;SACxB,IAAI,CAAC,EAAE,CAAC,CAAC;AAAA,CACX;AAED;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AAC,KAAK,CACT,MAAM,IAAI,CAAC,aAAa,CAAC;YACxB,GAAG,EAAE,cAAc,CAAC,MAAM,EAAE;YAC5B,QAAQ,EAAE,IAAI,CAAC,QAAQ,CAAC,QAAQ;YAChC,cAAc;YACd,iBAAiB,EAAE,EAAE,IAAI,EAAE,eAAe,EAAE,MAAM,EAAE,QAAQ,EAAE,mBAAmB,EAAE;SACnF,CAAC,CACF,CAAC;QACF,MAAM,IAAI,CAAC,wBAAwB,EAAE,CAAC;QACtC,OAAO,EAAE,SAAS,EAAE,KAAK,EAAE,CAAC;IAAA,CAC5B;IAED,KAAK,CAAC,OAAO,GAAkB;QAC9B,MAAM,wBAAwB,CAAC,IAAI,CAAC,OAAO,CAAC,eAAe,EAAE;YAC5D,IAAI,EAAE,kBAAkB;YACxB,MAAM,EAAE,MAAM;SACd,CAAC,CAAC;QACH,IAAI,CAAC,uBAAuB,EAAE,EAAE,CAAC;QACjC,IAAI,CAAC,OAAO,CAAC,OAAO,EAAE,CAAC;IAAA,CACvB;CACD;AAED;;;;;GAKG;AACH,MAAM,CAAC,KAAK,UAAU,yBAAyB,CAC9C,aAA+C,EAC/C,OAKC,EAC8B;IAC/B,sBAAsB,CAAC,OAAO,CAAC,cAAc,EAAE,OAAO,CAAC,GAAG,CAAC,CAAC;IAC5D,MAAM,MAAM,GAAG,MAAM,aAAa,CAAC,OAAO,CAAC,CAAC;IAC5C,OAAO,IAAI,mBAAmB,CAC7B,MAAM,CAAC,OAAO,EACd,MAAM,CAAC,QAAQ,EACf,aAAa,EACb,MAAM,CAAC,WAAW,EAClB,MAAM,CAAC,oBAAoB,CAC3B,CAAC;AAAA,CACF;AAED,OAAO,EAKN,8BAA8B,EAC9B,0BAA0B,GAC1B,MAAM,6BAA6B,CAAC","sourcesContent":["import { copyFileSync, existsSync, mkdirSync } from \"node:fs\";\nimport { basename, join, resolve } from \"node:path\";\nimport type { AgentSession } from \"./agent-session.ts\";\nimport type { AgentSessionRuntimeDiagnostic, AgentSessionServices } from \"./agent-session-services.ts\";\nimport type { ReplacedSessionContext, SessionShutdownEvent, SessionStartEvent } from \"./extensions/index.ts\";\nimport { emitSessionShutdownEvent } from \"./extensions/runner.ts\";\nimport type { CreateAgentSessionResult } from \"./sdk.ts\";\nimport { assertSessionCwdExists } from \"./session-cwd.ts\";\nimport { SessionManager } from \"./session-manager.ts\";\n\n/**\n * Result returned by runtime creation.\n *\n * The caller gets the created session, its cwd-bound services, and all\n * diagnostics collected during setup.\n */\nexport interface CreateAgentSessionRuntimeResult extends CreateAgentSessionResult {\n\tservices: AgentSessionServices;\n\tdiagnostics: AgentSessionRuntimeDiagnostic[];\n}\n\n/**\n * Creates a full runtime for a target cwd and session manager.\n *\n * The factory closes over process-global fixed inputs, recreates cwd-bound\n * services for the effective cwd, resolves session options against those\n * services, and finally creates the AgentSession.\n */\nexport type CreateAgentSessionRuntimeFactory = (options: {\n\tcwd: string;\n\tagentDir: string;\n\tsessionManager: SessionManager;\n\tsessionStartEvent?: SessionStartEvent;\n}) => Promise<CreateAgentSessionRuntimeResult>;\n\n/**\n * Thrown when /import references a JSONL file path that does not exist.\n */\nexport class SessionImportFileNotFoundError extends Error {\n\treadonly filePath: string;\n\n\tconstructor(filePath: string) {\n\t\tsuper(`File not found: ${filePath}`);\n\t\tthis.name = \"SessionImportFileNotFoundError\";\n\t\tthis.filePath = filePath;\n\t}\n}\n\nfunction extractUserMessageText(content: string | Array<{ type: string; text?: string }>): string {\n\tif (typeof content === \"string\") {\n\t\treturn content;\n\t}\n\n\treturn content\n\t\t.filter((part): part is { type: \"text\"; text: string } => part.type === \"text\" && typeof part.text === \"string\")\n\t\t.map((part) => part.text)\n\t\t.join(\"\");\n}\n\n/**\n * Owns the current AgentSession plus its cwd-bound services.\n *\n * Session replacement methods tear down the current runtime first, then create\n * and apply the next runtime. If creation fails, the error is propagated to the\n * caller. The caller is responsible for user-facing error handling.\n */\nexport class AgentSessionRuntime {\n\tprivate rebindSession?: (session: AgentSession) => Promise<void>;\n\tprivate beforeSessionInvalidate?: () => void;\n\tprivate _session: AgentSession;\n\tprivate _services: AgentSessionServices;\n\tprivate readonly createRuntime: CreateAgentSessionRuntimeFactory;\n\tprivate _diagnostics: AgentSessionRuntimeDiagnostic[];\n\tprivate _modelFallbackMessage?: string;\n\n\tconstructor(\n\t\t_session: AgentSession,\n\t\t_services: AgentSessionServices,\n\t\tcreateRuntime: CreateAgentSessionRuntimeFactory,\n\t\t_diagnostics: AgentSessionRuntimeDiagnostic[] = [],\n\t\t_modelFallbackMessage?: string,\n\t) {\n\t\tthis._session = _session;\n\t\tthis._services = _services;\n\t\tthis.createRuntime = createRuntime;\n\t\tthis._diagnostics = _diagnostics;\n\t\tthis._modelFallbackMessage = _modelFallbackMessage;\n\t}\n\n\tget services(): AgentSessionServices {\n\t\treturn this._services;\n\t}\n\n\tget session(): AgentSession {\n\t\treturn this._session;\n\t}\n\n\tget cwd(): string {\n\t\treturn this._services.cwd;\n\t}\n\n\tget diagnostics(): readonly AgentSessionRuntimeDiagnostic[] {\n\t\treturn this._diagnostics;\n\t}\n\n\tget modelFallbackMessage(): string | undefined {\n\t\treturn this._modelFallbackMessage;\n\t}\n\n\tsetRebindSession(rebindSession?: (session: AgentSession) => Promise<void>): void {\n\t\tthis.rebindSession = rebindSession;\n\t}\n\n\t/**\n\t * Set a synchronous callback that runs after `session_shutdown` handlers finish\n\t * but before the current session is invalidated.\n\t *\n\t * This is for host-owned UI teardown that must not yield to the event loop,\n\t * such as detaching extension-provided TUI components before the old extension\n\t * context becomes stale.\n\t */\n\tsetBeforeSessionInvalidate(beforeSessionInvalidate?: () => void): void {\n\t\tthis.beforeSessionInvalidate = beforeSessionInvalidate;\n\t}\n\n\tprivate async emitBeforeSwitch(\n\t\treason: \"new\" | \"resume\",\n\t\ttargetSessionFile?: string,\n\t): Promise<{ cancelled: boolean }> {\n\t\tconst runner = this.session.extensionRunner;\n\t\tif (!runner.hasHandlers(\"session_before_switch\")) {\n\t\t\treturn { cancelled: false };\n\t\t}\n\n\t\tconst result = await runner.emit({\n\t\t\ttype: \"session_before_switch\",\n\t\t\treason,\n\t\t\ttargetSessionFile,\n\t\t});\n\t\treturn { cancelled: result?.cancel === true };\n\t}\n\n\tprivate async emitBeforeFork(\n\t\tentryId: string,\n\t\toptions: { position: \"before\" | \"at\" },\n\t): Promise<{ cancelled: boolean }> {\n\t\tconst runner = this.session.extensionRunner;\n\t\tif (!runner.hasHandlers(\"session_before_fork\")) {\n\t\t\treturn { cancelled: false };\n\t\t}\n\n\t\tconst result = await runner.emit({\n\t\t\ttype: \"session_before_fork\",\n\t\t\tentryId,\n\t\t\t...options,\n\t\t});\n\t\treturn { cancelled: result?.cancel === true };\n\t}\n\n\tprivate async teardownCurrent(reason: SessionShutdownEvent[\"reason\"], targetSessionFile?: string): Promise<void> {\n\t\tawait emitSessionShutdownEvent(this.session.extensionRunner, {\n\t\t\ttype: \"session_shutdown\",\n\t\t\treason,\n\t\t\ttargetSessionFile,\n\t\t});\n\t\tthis.beforeSessionInvalidate?.();\n\t\tthis.session.dispose();\n\t}\n\n\tprivate apply(result: CreateAgentSessionRuntimeResult): void {\n\t\tthis._session = result.session;\n\t\tthis._services = result.services;\n\t\tthis._diagnostics = result.diagnostics;\n\t\tthis._modelFallbackMessage = result.modelFallbackMessage;\n\t}\n\n\tprivate async finishSessionReplacement(withSession?: (ctx: ReplacedSessionContext) => Promise<void>): Promise<void> {\n\t\tif (this.rebindSession) {\n\t\t\tawait this.rebindSession(this.session);\n\t\t}\n\t\tif (withSession) {\n\t\t\tawait withSession(this.session.createReplacedSessionContext());\n\t\t}\n\t}\n\n\tasync switchSession(\n\t\tsessionPath: string,\n\t\toptions?: { cwdOverride?: string; withSession?: (ctx: ReplacedSessionContext) => Promise<void> },\n\t): Promise<{ cancelled: boolean }> {\n\t\tconst beforeResult = await this.emitBeforeSwitch(\"resume\", sessionPath);\n\t\tif (beforeResult.cancelled) {\n\t\t\treturn beforeResult;\n\t\t}\n\n\t\tconst previousSessionFile = this.session.sessionFile;\n\t\tconst sessionManager = SessionManager.open(sessionPath, undefined, options?.cwdOverride);\n\t\tassertSessionCwdExists(sessionManager, this.cwd);\n\t\tawait this.teardownCurrent(\"resume\", sessionManager.getSessionFile());\n\t\tthis.apply(\n\t\t\tawait this.createRuntime({\n\t\t\t\tcwd: sessionManager.getCwd(),\n\t\t\t\tagentDir: this.services.agentDir,\n\t\t\t\tsessionManager,\n\t\t\t\tsessionStartEvent: { type: \"session_start\", reason: \"resume\", previousSessionFile },\n\t\t\t}),\n\t\t);\n\t\tawait this.finishSessionReplacement(options?.withSession);\n\t\treturn { cancelled: false };\n\t}\n\n\tasync newSession(options?: {\n\t\tparentSession?: string;\n\t\tsetup?: (sessionManager: SessionManager) => Promise<void>;\n\t\twithSession?: (ctx: ReplacedSessionContext) => Promise<void>;\n\t}): Promise<{ cancelled: boolean }> {\n\t\tconst beforeResult = await this.emitBeforeSwitch(\"new\");\n\t\tif (beforeResult.cancelled) {\n\t\t\treturn beforeResult;\n\t\t}\n\n\t\tconst previousSessionFile = this.session.sessionFile;\n\t\tconst sessionDir = this.session.sessionManager.getSessionDir();\n\t\tconst sessionManager = SessionManager.create(this.cwd, sessionDir);\n\t\tif (options?.parentSession) {\n\t\t\tsessionManager.newSession({ parentSession: options.parentSession });\n\t\t}\n\n\t\tawait this.teardownCurrent(\"new\", sessionManager.getSessionFile());\n\t\tthis.apply(\n\t\t\tawait this.createRuntime({\n\t\t\t\tcwd: this.cwd,\n\t\t\t\tagentDir: this.services.agentDir,\n\t\t\t\tsessionManager,\n\t\t\t\tsessionStartEvent: { type: \"session_start\", reason: \"new\", previousSessionFile },\n\t\t\t}),\n\t\t);\n\t\tif (options?.setup) {\n\t\t\tawait options.setup(this.session.sessionManager);\n\t\t\tthis.session.agent.state.messages = this.session.sessionManager.buildSessionContext().messages;\n\t\t}\n\t\tawait this.finishSessionReplacement(options?.withSession);\n\t\treturn { cancelled: false };\n\t}\n\n\tasync fork(\n\t\tentryId: string,\n\t\toptions?: { position?: \"before\" | \"at\"; withSession?: (ctx: ReplacedSessionContext) => Promise<void> },\n\t): Promise<{ cancelled: boolean; selectedText?: string }> {\n\t\tconst position = options?.position ?? \"before\";\n\t\tconst beforeResult = await this.emitBeforeFork(entryId, { position });\n\t\tif (beforeResult.cancelled) {\n\t\t\treturn { cancelled: true };\n\t\t}\n\t\tlet targetLeafId: string | null;\n\t\tlet selectedText: string | undefined;\n\n\t\tconst selectedEntry = this.session.sessionManager.getEntry(entryId);\n\t\tif (!selectedEntry) {\n\t\t\tthrow new Error(\"Invalid entry ID for forking\");\n\t\t}\n\n\t\tif (position === \"at\") {\n\t\t\ttargetLeafId = selectedEntry.id;\n\t\t} else {\n\t\t\tif (selectedEntry.type !== \"message\" || selectedEntry.message.role !== \"user\") {\n\t\t\t\tthrow new Error(\"Invalid entry ID for forking\");\n\t\t\t}\n\t\t\ttargetLeafId = selectedEntry.parentId;\n\t\t\tselectedText = extractUserMessageText(selectedEntry.message.content);\n\t\t}\n\n\t\tconst previousSessionFile = this.session.sessionFile;\n\t\tif (this.session.sessionManager.isPersisted()) {\n\t\t\tconst currentSessionFile = this.session.sessionFile;\n\t\t\tif (!currentSessionFile) {\n\t\t\t\tthrow new Error(\"Persisted session is missing a session file\");\n\t\t\t}\n\t\t\tconst sessionDir = this.session.sessionManager.getSessionDir();\n\t\t\tif (!targetLeafId) {\n\t\t\t\tconst sessionManager = SessionManager.create(this.cwd, sessionDir);\n\t\t\t\tsessionManager.newSession({ parentSession: currentSessionFile });\n\t\t\t\tawait this.teardownCurrent(\"fork\", sessionManager.getSessionFile());\n\t\t\t\tthis.apply(\n\t\t\t\t\tawait this.createRuntime({\n\t\t\t\t\t\tcwd: this.cwd,\n\t\t\t\t\t\tagentDir: this.services.agentDir,\n\t\t\t\t\t\tsessionManager,\n\t\t\t\t\t\tsessionStartEvent: { type: \"session_start\", reason: \"fork\", previousSessionFile },\n\t\t\t\t\t}),\n\t\t\t\t);\n\t\t\t\tawait this.finishSessionReplacement(options?.withSession);\n\t\t\t\treturn { cancelled: false, selectedText };\n\t\t\t}\n\n\t\t\tconst sessionManager = SessionManager.open(currentSessionFile, sessionDir);\n\t\t\tconst forkedSessionPath = sessionManager.createBranchedSession(targetLeafId);\n\t\t\tif (!forkedSessionPath) {\n\t\t\t\tthrow new Error(\"Failed to create forked session\");\n\t\t\t}\n\t\t\tawait this.teardownCurrent(\"fork\", sessionManager.getSessionFile());\n\t\t\tthis.apply(\n\t\t\t\tawait this.createRuntime({\n\t\t\t\t\tcwd: sessionManager.getCwd(),\n\t\t\t\t\tagentDir: this.services.agentDir,\n\t\t\t\t\tsessionManager,\n\t\t\t\t\tsessionStartEvent: { type: \"session_start\", reason: \"fork\", previousSessionFile },\n\t\t\t\t}),\n\t\t\t);\n\t\t\tawait this.finishSessionReplacement(options?.withSession);\n\t\t\treturn { cancelled: false, selectedText };\n\t\t}\n\n\t\tconst sessionManager = this.session.sessionManager;\n\t\tif (!targetLeafId) {\n\t\t\tsessionManager.newSession({ parentSession: this.session.sessionFile });\n\t\t} else {\n\t\t\tsessionManager.createBranchedSession(targetLeafId);\n\t\t}\n\t\tawait this.teardownCurrent(\"fork\", sessionManager.getSessionFile());\n\t\tthis.apply(\n\t\t\tawait this.createRuntime({\n\t\t\t\tcwd: this.cwd,\n\t\t\t\tagentDir: this.services.agentDir,\n\t\t\t\tsessionManager,\n\t\t\t\tsessionStartEvent: { type: \"session_start\", reason: \"fork\", previousSessionFile },\n\t\t\t}),\n\t\t);\n\t\tawait this.finishSessionReplacement(options?.withSession);\n\t\treturn { cancelled: false, selectedText };\n\t}\n\n\t/**\n\t * Import a session JSONL file and switch runtime state to the imported session.\n\t *\n\t * @returns `{ cancelled: true }` when cancelled by `session_before_switch`, otherwise `{ cancelled: false }`.\n\t * @throws {SessionImportFileNotFoundError} When the input path does not exist.\n\t * @throws {MissingSessionCwdError} When the imported session cwd cannot be resolved and no override is provided.\n\t */\n\tasync importFromJsonl(inputPath: string, cwdOverride?: string): Promise<{ cancelled: boolean }> {\n\t\tconst resolvedPath = resolve(inputPath);\n\t\tif (!existsSync(resolvedPath)) {\n\t\t\tthrow new SessionImportFileNotFoundError(resolvedPath);\n\t\t}\n\n\t\tconst sessionDir = this.session.sessionManager.getSessionDir();\n\t\tif (!existsSync(sessionDir)) {\n\t\t\tmkdirSync(sessionDir, { recursive: true });\n\t\t}\n\n\t\tconst destinationPath = join(sessionDir, basename(resolvedPath));\n\t\tconst beforeResult = await this.emitBeforeSwitch(\"resume\", destinationPath);\n\t\tif (beforeResult.cancelled) {\n\t\t\treturn beforeResult;\n\t\t}\n\n\t\tconst previousSessionFile = this.session.sessionFile;\n\t\tif (resolve(destinationPath) !== resolvedPath) {\n\t\t\tcopyFileSync(resolvedPath, destinationPath);\n\t\t}\n\n\t\tconst sessionManager = SessionManager.open(destinationPath, sessionDir, cwdOverride);\n\t\tassertSessionCwdExists(sessionManager, this.cwd);\n\t\tawait this.teardownCurrent(\"resume\", sessionManager.getSessionFile());\n\t\tthis.apply(\n\t\t\tawait this.createRuntime({\n\t\t\t\tcwd: sessionManager.getCwd(),\n\t\t\t\tagentDir: this.services.agentDir,\n\t\t\t\tsessionManager,\n\t\t\t\tsessionStartEvent: { type: \"session_start\", reason: \"resume\", previousSessionFile },\n\t\t\t}),\n\t\t);\n\t\tawait this.finishSessionReplacement();\n\t\treturn { cancelled: false };\n\t}\n\n\tasync dispose(): Promise<void> {\n\t\tawait emitSessionShutdownEvent(this.session.extensionRunner, {\n\t\t\ttype: \"session_shutdown\",\n\t\t\treason: \"quit\",\n\t\t});\n\t\tthis.beforeSessionInvalidate?.();\n\t\tthis.session.dispose();\n\t}\n}\n\n/**\n * Create the initial runtime from a runtime factory and initial session target.\n *\n * The same factory is stored on the returned AgentSessionRuntime and reused for\n * later /new, /resume, /fork, and import flows.\n */\nexport async function createAgentSessionRuntime(\n\tcreateRuntime: CreateAgentSessionRuntimeFactory,\n\toptions: {\n\t\tcwd: string;\n\t\tagentDir: string;\n\t\tsessionManager: SessionManager;\n\t\tsessionStartEvent?: SessionStartEvent;\n\t},\n): Promise<AgentSessionRuntime> {\n\tassertSessionCwdExists(options.sessionManager, options.cwd);\n\tconst result = await createRuntime(options);\n\treturn new AgentSessionRuntime(\n\t\tresult.session,\n\t\tresult.services,\n\t\tcreateRuntime,\n\t\tresult.diagnostics,\n\t\tresult.modelFallbackMessage,\n\t);\n}\n\nexport {\n\ttype AgentSessionRuntimeDiagnostic,\n\ttype AgentSessionServices,\n\ttype CreateAgentSessionFromServicesOptions,\n\ttype CreateAgentSessionServicesOptions,\n\tcreateAgentSessionFromServices,\n\tcreateAgentSessionServices,\n} from \"./agent-session-services.ts\";\n"]}
@@ -1,86 +0,0 @@
1
- import type { ThinkingLevel } from "@openeryc/pi-agent-core";
2
- import type { Model } from "@openeryc/pi-ai";
3
- import { AuthStorage } from "./auth-storage.ts";
4
- import type { SessionStartEvent, ToolDefinition } from "./extensions/index.ts";
5
- import { ModelRegistry } from "./model-registry.ts";
6
- import { type DefaultResourceLoaderOptions, type ResourceLoader } from "./resource-loader.ts";
7
- import { type CreateAgentSessionOptions, type CreateAgentSessionResult } from "./sdk.ts";
8
- import type { SessionManager } from "./session-manager.ts";
9
- import { SettingsManager } from "./settings-manager.ts";
10
- /**
11
- * Non-fatal issues collected while creating services or sessions.
12
- *
13
- * Runtime creation returns diagnostics to the caller instead of printing or
14
- * exiting. The app layer decides whether warnings should be shown and whether
15
- * errors should abort startup.
16
- */
17
- export interface AgentSessionRuntimeDiagnostic {
18
- type: "info" | "warning" | "error";
19
- message: string;
20
- }
21
- /**
22
- * Inputs for creating cwd-bound runtime services.
23
- *
24
- * These services are recreated whenever the effective session cwd changes.
25
- * CLI-provided resource paths should be resolved to absolute paths before they
26
- * reach this function, so later cwd switches do not reinterpret them.
27
- */
28
- export interface CreateAgentSessionServicesOptions {
29
- cwd: string;
30
- agentDir?: string;
31
- authStorage?: AuthStorage;
32
- settingsManager?: SettingsManager;
33
- modelRegistry?: ModelRegistry;
34
- extensionFlagValues?: Map<string, boolean | string>;
35
- resourceLoaderOptions?: Omit<DefaultResourceLoaderOptions, "cwd" | "agentDir" | "settingsManager">;
36
- }
37
- /**
38
- * Inputs for creating an AgentSession from already-created services.
39
- *
40
- * Use this after services exist and any cwd-bound model/tool/session options
41
- * have been resolved against those services.
42
- */
43
- export interface CreateAgentSessionFromServicesOptions {
44
- services: AgentSessionServices;
45
- sessionManager: SessionManager;
46
- sessionStartEvent?: SessionStartEvent;
47
- model?: Model<any>;
48
- thinkingLevel?: ThinkingLevel;
49
- scopedModels?: Array<{
50
- model: Model<any>;
51
- thinkingLevel?: ThinkingLevel;
52
- }>;
53
- tools?: string[];
54
- noTools?: CreateAgentSessionOptions["noTools"];
55
- customTools?: ToolDefinition[];
56
- }
57
- /**
58
- * Coherent cwd-bound runtime services for one effective session cwd.
59
- *
60
- * This is infrastructure only. The AgentSession itself is created separately so
61
- * session options can be resolved against these services first.
62
- */
63
- export interface AgentSessionServices {
64
- cwd: string;
65
- agentDir: string;
66
- authStorage: AuthStorage;
67
- settingsManager: SettingsManager;
68
- modelRegistry: ModelRegistry;
69
- resourceLoader: ResourceLoader;
70
- diagnostics: AgentSessionRuntimeDiagnostic[];
71
- }
72
- /**
73
- * Create cwd-bound runtime services.
74
- *
75
- * Returns services plus diagnostics. It does not create an AgentSession.
76
- */
77
- export declare function createAgentSessionServices(options: CreateAgentSessionServicesOptions): Promise<AgentSessionServices>;
78
- /**
79
- * Create an AgentSession from previously created services.
80
- *
81
- * This keeps session creation separate from service creation so callers can
82
- * resolve model, thinking, tools, and other session inputs against the target
83
- * cwd before constructing the session.
84
- */
85
- export declare function createAgentSessionFromServices(options: CreateAgentSessionFromServicesOptions): Promise<CreateAgentSessionResult>;
86
- //# sourceMappingURL=agent-session-services.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"agent-session-services.d.ts","sourceRoot":"","sources":["../../src/core/agent-session-services.ts"],"names":[],"mappings":"AACA,OAAO,KAA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KAAK,CAAC,EAAE,KAAK,CAAC,GAAG,CAAC,CAAC;IACnB,aAAa,CAAC,EAAE,aAAa,CAAC;IAC9B,YAAY,CAAC,EAAE,KAAK,CAAC;QAAE,KAAK,EAAE,KAAK,CAAC,GAAG,CAAC,CAAC;QAAC,aAAa,CAAC,EAAE,aAAa,CAAA;KAAE,CAAC,CAAC;IAC3E,KAAK,CAAC,EAAE,MAAM,EAAE,CAAC;IACjB,OAAO,CAAC,EAAE,yBAAyB,CAAC,SAAS,CAAC,CAAC;IAC/C,WAAW,CAAC,EAAE,cAAc,EAAE,CAAC;CAC/B;AAED;;;;;GAKG;AACH,MAAM,WAAW,oBAAoB;IACpC,GAAG,EAAE,MAAM,CAAC;IACZ,QAAQ,EAAE,MAAM,CAAC;IACjB,WAAW,EAAE,WAAW,CAAC;IACzB,eAAe,EAAE,eAAe,CAAC;IACjC,aAAa,EAAE,aAAa,CAAC;IAC7B,cAAc,EAAE,cAAc,CAAC;IAC/B,WAAW,EAAE,6BAA6B,EAAE,CAAC;CAC7C;AAkDD;;;;GAIG;AACH,wBAAsB,0BAA0B,CAC/C,OAAO,EAAE,iCAAiC,GACxC,OAAO,CAAC,oBAAoB,CAAC,CAuC/B;AAED;;;;;;GAMG;AACH,wBAAsB,8BAA8B,CACnD,OAAO,EAAE,qCAAqC,GAC5C,OAAO,CAAC,wBAAwB,CAAC,CAiBnC","sourcesContent":["import { join } from \"node:path\";\nimport type { ThinkingLevel } from \"@openeryc/pi-agent-core\";\nimport type { Model } from \"@openeryc/pi-ai\";\nimport { getAgentDir } from \"../config.ts\";\nimport { AuthStorage } from \"./auth-storage.ts\";\nimport type { SessionStartEvent, ToolDefinition } from \"./extensions/index.ts\";\nimport { ModelRegistry } from \"./model-registry.ts\";\nimport { DefaultResourceLoader, type DefaultResourceLoaderOptions, type ResourceLoader } from \"./resource-loader.ts\";\nimport { type CreateAgentSessionOptions, type CreateAgentSessionResult, createAgentSession } from \"./sdk.ts\";\nimport type { SessionManager } from \"./session-manager.ts\";\nimport { SettingsManager } from \"./settings-manager.ts\";\n\n/**\n * Non-fatal issues collected while creating services or sessions.\n *\n * Runtime creation returns diagnostics to the caller instead of printing or\n * exiting. The app layer decides whether warnings should be shown and whether\n * errors should abort startup.\n */\nexport interface AgentSessionRuntimeDiagnostic {\n\ttype: \"info\" | \"warning\" | \"error\";\n\tmessage: string;\n}\n\n/**\n * Inputs for creating cwd-bound runtime services.\n *\n * These services are recreated whenever the effective session cwd changes.\n * CLI-provided resource paths should be resolved to absolute paths before they\n * reach this function, so later cwd switches do not reinterpret them.\n */\nexport interface CreateAgentSessionServicesOptions {\n\tcwd: string;\n\tagentDir?: string;\n\tauthStorage?: AuthStorage;\n\tsettingsManager?: SettingsManager;\n\tmodelRegistry?: ModelRegistry;\n\textensionFlagValues?: Map<string, boolean | string>;\n\tresourceLoaderOptions?: Omit<DefaultResourceLoaderOptions, \"cwd\" | \"agentDir\" | \"settingsManager\">;\n}\n\n/**\n * Inputs for creating an AgentSession from already-created services.\n *\n * Use this after services exist and any cwd-bound model/tool/session options\n * have been resolved against those services.\n */\nexport interface CreateAgentSessionFromServicesOptions {\n\tservices: AgentSessionServices;\n\tsessionManager: SessionManager;\n\tsessionStartEvent?: SessionStartEvent;\n\tmodel?: Model<any>;\n\tthinkingLevel?: ThinkingLevel;\n\tscopedModels?: Array<{ model: Model<any>; thinkingLevel?: ThinkingLevel }>;\n\ttools?: string[];\n\tnoTools?: CreateAgentSessionOptions[\"noTools\"];\n\tcustomTools?: ToolDefinition[];\n}\n\n/**\n * Coherent cwd-bound runtime services for one effective session cwd.\n *\n * This is infrastructure only. The AgentSession itself is created separately so\n * session options can be resolved against these services first.\n */\nexport interface AgentSessionServices {\n\tcwd: string;\n\tagentDir: string;\n\tauthStorage: AuthStorage;\n\tsettingsManager: SettingsManager;\n\tmodelRegistry: ModelRegistry;\n\tresourceLoader: ResourceLoader;\n\tdiagnostics: AgentSessionRuntimeDiagnostic[];\n}\n\nfunction applyExtensionFlagValues(\n\tresourceLoader: ResourceLoader,\n\textensionFlagValues: Map<string, boolean | string> | undefined,\n): AgentSessionRuntimeDiagnostic[] {\n\tif (!extensionFlagValues) {\n\t\treturn [];\n\t}\n\n\tconst diagnostics: AgentSessionRuntimeDiagnostic[] = [];\n\tconst extensionsResult = resourceLoader.getExtensions();\n\tconst registeredFlags = new Map<string, { type: \"boolean\" | \"string\" }>();\n\tfor (const extension of extensionsResult.extensions) {\n\t\tfor (const [name, flag] of extension.flags) {\n\t\t\tregisteredFlags.set(name, { type: flag.type });\n\t\t}\n\t}\n\n\tconst unknownFlags: string[] = [];\n\tfor (const [name, value] of extensionFlagValues) {\n\t\tconst flag = registeredFlags.get(name);\n\t\tif (!flag) {\n\t\t\tunknownFlags.push(name);\n\t\t\tcontinue;\n\t\t}\n\t\tif (flag.type === \"boolean\") {\n\t\t\textensionsResult.runtime.flagValues.set(name, true);\n\t\t\tcontinue;\n\t\t}\n\t\tif (typeof value === \"string\") {\n\t\t\textensionsResult.runtime.flagValues.set(name, value);\n\t\t\tcontinue;\n\t\t}\n\t\tdiagnostics.push({\n\t\t\ttype: \"error\",\n\t\t\tmessage: `Extension flag \"--${name}\" requires a value`,\n\t\t});\n\t}\n\n\tif (unknownFlags.length > 0) {\n\t\tdiagnostics.push({\n\t\t\ttype: \"error\",\n\t\t\tmessage: `Unknown option${unknownFlags.length === 1 ? \"\" : \"s\"}: ${unknownFlags.map((name) => `--${name}`).join(\", \")}`,\n\t\t});\n\t}\n\n\treturn diagnostics;\n}\n\n/**\n * Create cwd-bound runtime services.\n *\n * Returns services plus diagnostics. It does not create an AgentSession.\n */\nexport async function createAgentSessionServices(\n\toptions: CreateAgentSessionServicesOptions,\n): Promise<AgentSessionServices> {\n\tconst cwd = options.cwd;\n\tconst agentDir = options.agentDir ?? getAgentDir();\n\tconst authStorage = options.authStorage ?? AuthStorage.create(join(agentDir, \"auth.json\"));\n\tconst settingsManager = options.settingsManager ?? SettingsManager.create(cwd, agentDir);\n\tconst modelRegistry = options.modelRegistry ?? ModelRegistry.create(authStorage, join(agentDir, \"models.json\"));\n\tconst resourceLoader = new DefaultResourceLoader({\n\t\t...(options.resourceLoaderOptions ?? {}),\n\t\tcwd,\n\t\tagentDir,\n\t\tsettingsManager,\n\t});\n\tawait resourceLoader.reload();\n\n\tconst diagnostics: AgentSessionRuntimeDiagnostic[] = [];\n\tconst extensionsResult = resourceLoader.getExtensions();\n\tfor (const { name, config, extensionPath } of extensionsResult.runtime.pendingProviderRegistrations) {\n\t\ttry {\n\t\t\tmodelRegistry.registerProvider(name, config);\n\t\t} catch (error) {\n\t\t\tconst message = error instanceof Error ? error.message : String(error);\n\t\t\tdiagnostics.push({\n\t\t\t\ttype: \"error\",\n\t\t\t\tmessage: `Extension \"${extensionPath}\" error: ${message}`,\n\t\t\t});\n\t\t}\n\t}\n\textensionsResult.runtime.pendingProviderRegistrations = [];\n\tdiagnostics.push(...applyExtensionFlagValues(resourceLoader, options.extensionFlagValues));\n\n\treturn {\n\t\tcwd,\n\t\tagentDir,\n\t\tauthStorage,\n\t\tsettingsManager,\n\t\tmodelRegistry,\n\t\tresourceLoader,\n\t\tdiagnostics,\n\t};\n}\n\n/**\n * Create an AgentSession from previously created services.\n *\n * This keeps session creation separate from service creation so callers can\n * resolve model, thinking, tools, and other session inputs against the target\n * cwd before constructing the session.\n */\nexport async function createAgentSessionFromServices(\n\toptions: CreateAgentSessionFromServicesOptions,\n): Promise<CreateAgentSessionResult> {\n\treturn createAgentSession({\n\t\tcwd: options.services.cwd,\n\t\tagentDir: options.services.agentDir,\n\t\tauthStorage: options.services.authStorage,\n\t\tsettingsManager: options.services.settingsManager,\n\t\tmodelRegistry: options.services.modelRegistry,\n\t\tresourceLoader: options.services.resourceLoader,\n\t\tsessionManager: options.sessionManager,\n\t\tmodel: options.model,\n\t\tthinkingLevel: options.thinkingLevel,\n\t\tscopedModels: options.scopedModels,\n\t\ttools: options.tools,\n\t\tnoTools: options.noTools,\n\t\tcustomTools: options.customTools,\n\t\tsessionStartEvent: options.sessionStartEvent,\n\t});\n}\n"]}
@@ -1,117 +0,0 @@
1
- import { join } from "node:path";
2
- import { getAgentDir } from "../config.js";
3
- import { AuthStorage } from "./auth-storage.js";
4
- import { ModelRegistry } from "./model-registry.js";
5
- import { DefaultResourceLoader } from "./resource-loader.js";
6
- import { createAgentSession } from "./sdk.js";
7
- import { SettingsManager } from "./settings-manager.js";
8
- function applyExtensionFlagValues(resourceLoader, extensionFlagValues) {
9
- if (!extensionFlagValues) {
10
- return [];
11
- }
12
- const diagnostics = [];
13
- const extensionsResult = resourceLoader.getExtensions();
14
- const registeredFlags = new Map();
15
- for (const extension of extensionsResult.extensions) {
16
- for (const [name, flag] of extension.flags) {
17
- registeredFlags.set(name, { type: flag.type });
18
- }
19
- }
20
- const unknownFlags = [];
21
- for (const [name, value] of extensionFlagValues) {
22
- const flag = registeredFlags.get(name);
23
- if (!flag) {
24
- unknownFlags.push(name);
25
- continue;
26
- }
27
- if (flag.type === "boolean") {
28
- extensionsResult.runtime.flagValues.set(name, true);
29
- continue;
30
- }
31
- if (typeof value === "string") {
32
- extensionsResult.runtime.flagValues.set(name, value);
33
- continue;
34
- }
35
- diagnostics.push({
36
- type: "error",
37
- message: `Extension flag "--${name}" requires a value`,
38
- });
39
- }
40
- if (unknownFlags.length > 0) {
41
- diagnostics.push({
42
- type: "error",
43
- message: `Unknown option${unknownFlags.length === 1 ? "" : "s"}: ${unknownFlags.map((name) => `--${name}`).join(", ")}`,
44
- });
45
- }
46
- return diagnostics;
47
- }
48
- /**
49
- * Create cwd-bound runtime services.
50
- *
51
- * Returns services plus diagnostics. It does not create an AgentSession.
52
- */
53
- export async function createAgentSessionServices(options) {
54
- const cwd = options.cwd;
55
- const agentDir = options.agentDir ?? getAgentDir();
56
- const authStorage = options.authStorage ?? AuthStorage.create(join(agentDir, "auth.json"));
57
- const settingsManager = options.settingsManager ?? SettingsManager.create(cwd, agentDir);
58
- const modelRegistry = options.modelRegistry ?? ModelRegistry.create(authStorage, join(agentDir, "models.json"));
59
- const resourceLoader = new DefaultResourceLoader({
60
- ...(options.resourceLoaderOptions ?? {}),
61
- cwd,
62
- agentDir,
63
- settingsManager,
64
- });
65
- await resourceLoader.reload();
66
- const diagnostics = [];
67
- const extensionsResult = resourceLoader.getExtensions();
68
- for (const { name, config, extensionPath } of extensionsResult.runtime.pendingProviderRegistrations) {
69
- try {
70
- modelRegistry.registerProvider(name, config);
71
- }
72
- catch (error) {
73
- const message = error instanceof Error ? error.message : String(error);
74
- diagnostics.push({
75
- type: "error",
76
- message: `Extension "${extensionPath}" error: ${message}`,
77
- });
78
- }
79
- }
80
- extensionsResult.runtime.pendingProviderRegistrations = [];
81
- diagnostics.push(...applyExtensionFlagValues(resourceLoader, options.extensionFlagValues));
82
- return {
83
- cwd,
84
- agentDir,
85
- authStorage,
86
- settingsManager,
87
- modelRegistry,
88
- resourceLoader,
89
- diagnostics,
90
- };
91
- }
92
- /**
93
- * Create an AgentSession from previously created services.
94
- *
95
- * This keeps session creation separate from service creation so callers can
96
- * resolve model, thinking, tools, and other session inputs against the target
97
- * cwd before constructing the session.
98
- */
99
- export async function createAgentSessionFromServices(options) {
100
- return createAgentSession({
101
- cwd: options.services.cwd,
102
- agentDir: options.services.agentDir,
103
- authStorage: options.services.authStorage,
104
- settingsManager: options.services.settingsManager,
105
- modelRegistry: options.services.modelRegistry,
106
- resourceLoader: options.services.resourceLoader,
107
- sessionManager: options.sessionManager,
108
- model: options.model,
109
- thinkingLevel: options.thinkingLevel,
110
- scopedModels: options.scopedModels,
111
- tools: options.tools,
112
- noTools: options.noTools,
113
- customTools: options.customTools,
114
- sessionStartEvent: options.sessionStartEvent,
115
- });
116
- }
117
- //# sourceMappingURL=agent-session-services.js.map