saeeol 1.1.1 → 1.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (379) hide show
  1. package/package.json +14 -14
  2. package/script/build.ts +1 -1
  3. package/src/addons/addon-analytics.ts +1 -1
  4. package/src/cli/cmd/tui/routes/session/suggest.tsx +1 -1
  5. package/src/cli/logo.ts +1 -1
  6. package/src/cli/ui.ts +1 -1
  7. package/src/config/config-loader.ts +1 -1
  8. package/src/config/config-schema.ts +1 -1
  9. package/src/config/config.ts +1 -1
  10. package/src/config/markdown.ts +1 -1
  11. package/src/index.ts +2 -2
  12. package/src/lsp/lsp.ts +1 -1
  13. package/src/lsp/server-web.ts +1 -1
  14. package/src/mcp/oauth-callback.ts +1 -1
  15. package/src/{saeeol → overlay}/encoding.ts +1 -1
  16. package/src/{saeeol → overlay}/text-stream.ts +1 -1
  17. package/src/{saeeol → overlay}/tool/encoded-io.ts +1 -1
  18. package/src/patch/patch-apply.ts +1 -1
  19. package/src/patch/patch-parse.ts +1 -1
  20. package/src/session/compaction-helpers.ts +1 -169
  21. package/src/session/compaction.ts +1 -712
  22. package/src/session/core/compaction/compaction-helpers.ts +169 -0
  23. package/src/session/core/compaction/compaction.ts +712 -0
  24. package/src/session/core/compaction/overflow.ts +28 -0
  25. package/src/session/core/instruction.ts +234 -0
  26. package/src/session/core/llm.ts +504 -0
  27. package/src/session/core/network.ts +392 -0
  28. package/src/session/core/processor.ts +731 -0
  29. package/src/session/core/projectors.ts +139 -0
  30. package/src/session/core/resolve-tools.ts +241 -0
  31. package/src/session/core/retry.ts +149 -0
  32. package/src/session/core/revert.ts +173 -0
  33. package/src/session/core/run-state.ts +110 -0
  34. package/src/session/core/schema.ts +35 -0
  35. package/src/session/core/session-types.ts +160 -0
  36. package/src/session/core/session.sql.ts +124 -0
  37. package/src/session/core/session.ts +948 -0
  38. package/src/session/core/shell-exec.ts +205 -0
  39. package/src/session/core/status.ts +100 -0
  40. package/src/session/core/subtask.ts +268 -0
  41. package/src/session/core/summary.ts +173 -0
  42. package/src/session/core/system.ts +114 -0
  43. package/src/session/core/todo.ts +86 -0
  44. package/src/session/core/user-part.ts +293 -0
  45. package/src/session/instruction.ts +1 -234
  46. package/src/session/llm.ts +1 -504
  47. package/src/session/message/message-errors.ts +83 -0
  48. package/src/session/message/message-parts.ts +89 -0
  49. package/src/session/message/message-query.ts +107 -0
  50. package/src/session/message/message-transform.ts +156 -0
  51. package/src/session/message/message-types.ts +68 -0
  52. package/src/session/message/message-v2.ts +73 -0
  53. package/src/session/message/message.ts +192 -0
  54. package/src/session/message-errors.ts +1 -83
  55. package/src/session/message-parts.ts +1 -89
  56. package/src/session/message-query.ts +1 -107
  57. package/src/session/message-transform.ts +1 -156
  58. package/src/session/message-types.ts +1 -68
  59. package/src/session/message-v2.ts +1 -73
  60. package/src/session/message.ts +1 -192
  61. package/src/session/network.ts +1 -392
  62. package/src/session/overflow.ts +1 -28
  63. package/src/session/processor.ts +1 -731
  64. package/src/session/projectors.ts +2 -139
  65. package/src/session/prompt/prompt-command.ts +93 -0
  66. package/src/session/prompt/prompt-loop.ts +299 -0
  67. package/src/session/prompt/prompt-model.ts +44 -0
  68. package/src/session/prompt/prompt-reminders.ts +120 -0
  69. package/src/session/prompt/prompt-resolve.ts +42 -0
  70. package/src/session/prompt/prompt-schemas.ts +128 -0
  71. package/src/session/prompt/prompt-title.ts +55 -0
  72. package/src/session/prompt/prompt-types.ts +47 -0
  73. package/src/session/prompt/prompt-user-msg.ts +80 -0
  74. package/src/session/prompt/prompt.ts +211 -0
  75. package/src/session/prompt-command.ts +1 -93
  76. package/src/session/prompt-loop.ts +1 -299
  77. package/src/session/prompt-model.ts +1 -44
  78. package/src/session/prompt-reminders.ts +1 -120
  79. package/src/session/prompt-resolve.ts +1 -42
  80. package/src/session/prompt-schemas.ts +1 -128
  81. package/src/session/prompt-title.ts +1 -55
  82. package/src/session/prompt-types.ts +1 -47
  83. package/src/session/prompt-user-msg.ts +1 -80
  84. package/src/session/prompt.ts +1 -211
  85. package/src/session/resolve-tools.ts +1 -241
  86. package/src/session/retry.ts +1 -149
  87. package/src/session/revert.ts +1 -173
  88. package/src/session/run-state.ts +1 -110
  89. package/src/session/schema.ts +1 -35
  90. package/src/session/session-types.ts +1 -160
  91. package/src/session/session.sql.ts +1 -124
  92. package/src/session/session.ts +1 -948
  93. package/src/session/shell-exec.ts +1 -205
  94. package/src/session/status.ts +1 -100
  95. package/src/session/subtask.ts +1 -268
  96. package/src/session/summary.ts +1 -173
  97. package/src/session/system.ts +1 -114
  98. package/src/session/todo.ts +1 -86
  99. package/src/session/user-part.ts +1 -293
  100. package/src/skill/index.ts +1 -1
  101. package/src/suggestion/index.ts +1 -1
  102. package/src/tool/apply_patch.ts +2 -2
  103. package/src/tool/edit.ts +2 -2
  104. package/src/tool/read.ts +2 -2
  105. package/src/tool/recall.ts +1 -1
  106. package/src/tool/registry.ts +2 -2
  107. package/src/tool/suggest.ts +1 -1
  108. package/src/tool/task.ts +3 -3
  109. package/src/tool/todo.ts +1 -1
  110. package/src/tool/write.ts +2 -2
  111. package/test/lsp/index.test.ts +1 -1
  112. package/test/saeeol/agent-manager-tool.test.ts +1 -1
  113. package/test/saeeol/ask-agent-permissions.test.ts +1 -1
  114. package/test/saeeol/bash-hierarchy.test.ts +1 -1
  115. package/test/saeeol/builtin-skills.test.ts +1 -1
  116. package/test/saeeol/cli/dev-setup.test.ts +1 -1
  117. package/test/saeeol/cli/roll-call.test.ts +1 -1
  118. package/test/saeeol/cli-run-auto-helper.test.ts +1 -1
  119. package/test/saeeol/codex-auth-refresh.test.ts +1 -1
  120. package/test/saeeol/commit-message/generate.test.ts +1 -1
  121. package/test/saeeol/commit-message/git-context.test.ts +1 -1
  122. package/test/saeeol/commit-message-windows.test.ts +1 -1
  123. package/test/saeeol/compaction-payload-recovery.test.ts +1 -1
  124. package/test/saeeol/config/config.test.ts +1 -1
  125. package/test/saeeol/config-injector.test.ts +1 -1
  126. package/test/saeeol/config-validation.test.ts +1 -1
  127. package/test/saeeol/cost-propagation.test.ts +1 -1
  128. package/test/saeeol/custom-provider-delete.test.ts +1 -1
  129. package/test/saeeol/diff-full.test.ts +1 -1
  130. package/test/saeeol/encoding.test.ts +1 -1
  131. package/test/saeeol/enhance-prompt.test.ts +1 -1
  132. package/test/saeeol/ensure-plan-dir.test.ts +1 -1
  133. package/test/saeeol/errors.test.ts +1 -1
  134. package/test/saeeol/help.test.ts +3 -3
  135. package/test/saeeol/ignore-migrator.test.ts +1 -1
  136. package/test/saeeol/indexing-auth.test.ts +1 -1
  137. package/test/saeeol/indexing-feature.test.ts +1 -1
  138. package/test/saeeol/indexing-label.test.ts +1 -1
  139. package/test/saeeol/indexing-startup.test.ts +1 -1
  140. package/test/saeeol/indexing-worktree.test.ts +1 -1
  141. package/test/saeeol/lancedb-runtime.test.ts +9 -9
  142. package/test/saeeol/logo.test.ts +1 -1
  143. package/test/saeeol/lsp-typescript-lightweight.test.ts +2 -2
  144. package/test/saeeol/mcp-migrator.test.ts +1 -1
  145. package/test/saeeol/model-info-panel-utils.test.ts +1 -1
  146. package/test/saeeol/modes-migrator.test.ts +1 -1
  147. package/test/saeeol/paths.test.ts +1 -1
  148. package/test/saeeol/permission/config-paths.test.ts +2 -2
  149. package/test/saeeol/permission/external-directory-allow.test.ts +1 -1
  150. package/test/saeeol/plan-exit-detection.test.ts +1 -1
  151. package/test/saeeol/plan-followup.test.ts +2 -2
  152. package/test/saeeol/project-id.test.ts +1 -1
  153. package/test/saeeol/question-dismiss-all.test.ts +1 -1
  154. package/test/saeeol/rules-migrator.test.ts +1 -1
  155. package/test/saeeol/semantic-search.test.ts +2 -2
  156. package/test/saeeol/session/platform-attribution.test.ts +1 -1
  157. package/test/saeeol/session-compaction-cap.test.ts +2 -2
  158. package/test/saeeol/session-compaction-chunks.test.ts +1 -1
  159. package/test/saeeol/session-compaction-safety.test.ts +1 -1
  160. package/test/saeeol/session-import-service.test.ts +1 -1
  161. package/test/saeeol/session-processor-empty-tool-calls.test.ts +1 -1
  162. package/test/saeeol/session-processor-review-telemetry.test.ts +1 -1
  163. package/test/saeeol/session-prompt-queue.test.ts +1 -1
  164. package/test/saeeol/sessions/remote-sender.test.ts +1 -1
  165. package/test/saeeol/snapshot-track-timeout.test.ts +1 -1
  166. package/test/saeeol/suggestion/auto-dismiss.test.ts +2 -2
  167. package/test/saeeol/suggestion/suggestion.test.ts +1 -1
  168. package/test/saeeol/suggestion/tool.test.ts +2 -2
  169. package/test/saeeol/system-prompt.test.ts +1 -1
  170. package/test/saeeol/todo-view.test.ts +1 -1
  171. package/test/saeeol/tool-registry-indexing.test.ts +3 -3
  172. package/test/saeeol/tui-diff.test.ts +1 -1
  173. package/test/saeeol/tui-sync.test.ts +1 -1
  174. package/test/saeeol/util/url.test.ts +1 -1
  175. package/test/saeeol/workflows-migrator.test.ts +1 -1
  176. package/test/saeeol/worktree-diff-summary.test.ts +1 -1
  177. package/tsconfig.json +1 -1
  178. /package/src/{saeeol → overlay}/agent/agent-remove.ts +0 -0
  179. /package/src/{saeeol → overlay}/agent/index.ts +0 -0
  180. /package/src/{saeeol → overlay}/agent/patch-agents.ts +0 -0
  181. /package/src/{saeeol → overlay}/agent/permissions.ts +0 -0
  182. /package/src/{saeeol → overlay}/agent-manager/event.ts +0 -0
  183. /package/src/{saeeol → overlay}/bash-hierarchy.ts +0 -0
  184. /package/src/{saeeol → overlay}/bell.ts +0 -0
  185. /package/src/{saeeol → overlay}/bootstrap.ts +0 -0
  186. /package/src/{saeeol → overlay}/claw/autocomplete-popup.tsx +0 -0
  187. /package/src/{saeeol → overlay}/claw/autocomplete-ref.ts +0 -0
  188. /package/src/{saeeol → overlay}/claw/autocomplete-types.ts +0 -0
  189. /package/src/{saeeol → overlay}/claw/autocomplete.tsx +0 -0
  190. /package/src/{saeeol → overlay}/claw/chat-client.ts +0 -0
  191. /package/src/{saeeol → overlay}/claw/chat.tsx +0 -0
  192. /package/src/{saeeol → overlay}/claw/client-events.ts +0 -0
  193. /package/src/{saeeol → overlay}/claw/client-helpers.ts +0 -0
  194. /package/src/{saeeol → overlay}/claw/client.ts +0 -0
  195. /package/src/{saeeol → overlay}/claw/dialog-conversation-list.tsx +0 -0
  196. /package/src/{saeeol → overlay}/claw/event-service-client-core.ts +0 -0
  197. /package/src/{saeeol → overlay}/claw/event-service-client-impl.ts +0 -0
  198. /package/src/{saeeol → overlay}/claw/event-service-client.ts +0 -0
  199. /package/src/{saeeol → overlay}/claw/hooks.ts +0 -0
  200. /package/src/{saeeol → overlay}/claw/sidebar.tsx +0 -0
  201. /package/src/{saeeol → overlay}/claw/types.ts +0 -0
  202. /package/src/{saeeol → overlay}/claw/view.tsx +0 -0
  203. /package/src/{saeeol → overlay}/cli/cmd/roll-call-call.ts +0 -0
  204. /package/src/{saeeol → overlay}/cli/cmd/roll-call-format.ts +0 -0
  205. /package/src/{saeeol → overlay}/cli/cmd/roll-call.ts +0 -0
  206. /package/src/{saeeol → overlay}/cli/cmd/tui/app.tsx +0 -0
  207. /package/src/{saeeol → overlay}/cli/cmd/tui/component/dialog-provider.tsx +0 -0
  208. /package/src/{saeeol → overlay}/cli/cmd/tui/feedback.ts +0 -0
  209. /package/src/{saeeol → overlay}/cli/cmd/tui/util/terminal.ts +0 -0
  210. /package/src/{saeeol → overlay}/cli/dev-setup-utils.ts +0 -0
  211. /package/src/{saeeol → overlay}/cli/dev-setup.ts +0 -0
  212. /package/src/{saeeol → overlay}/cli/heap-snapshot.ts +0 -0
  213. /package/src/{saeeol → overlay}/cli/logo.ts +0 -0
  214. /package/src/{saeeol → overlay}/cli/run-auto.ts +0 -0
  215. /package/src/{saeeol → overlay}/cli/saeeol-logo.ts +0 -0
  216. /package/src/{saeeol → overlay}/cloud-session.ts +0 -0
  217. /package/src/{saeeol → overlay}/commands-index.ts +0 -0
  218. /package/src/{saeeol → overlay}/commands.ts +0 -0
  219. /package/src/{saeeol → overlay}/commands.tsx +0 -0
  220. /package/src/{saeeol → overlay}/commit-message/generate.ts +0 -0
  221. /package/src/{saeeol → overlay}/commit-message/git-context.ts +0 -0
  222. /package/src/{saeeol → overlay}/commit-message/index.ts +0 -0
  223. /package/src/{saeeol → overlay}/commit-message/types.ts +0 -0
  224. /package/src/{saeeol → overlay}/components/dialog-auto-method.tsx +0 -0
  225. /package/src/{saeeol → overlay}/components/dialog-claw-setup.tsx +0 -0
  226. /package/src/{saeeol → overlay}/components/dialog-claw-upgrade.tsx +0 -0
  227. /package/src/{saeeol → overlay}/components/dialog-indexing-helpers.ts +0 -0
  228. /package/src/{saeeol → overlay}/components/dialog-indexing.tsx +0 -0
  229. /package/src/{saeeol → overlay}/components/dialog-notifications.tsx +0 -0
  230. /package/src/{saeeol → overlay}/components/dialog-organization.tsx +0 -0
  231. /package/src/{saeeol → overlay}/components/dialog-profile.tsx +0 -0
  232. /package/src/{saeeol → overlay}/components/dialog-provider-settings.tsx +0 -0
  233. /package/src/{saeeol → overlay}/components/dialog-team-select.tsx +0 -0
  234. /package/src/{saeeol → overlay}/components/dialog-tuning.tsx +0 -0
  235. /package/src/{saeeol → overlay}/components/dialog-vector-store.tsx +0 -0
  236. /package/src/{saeeol → overlay}/components/error-display.tsx +0 -0
  237. /package/src/{saeeol → overlay}/components/model-info-panel-utils.ts +0 -0
  238. /package/src/{saeeol → overlay}/components/model-info-panel.tsx +0 -0
  239. /package/src/{saeeol → overlay}/components/news.tsx +0 -0
  240. /package/src/{saeeol → overlay}/components/notification-banner.tsx +0 -0
  241. /package/src/{saeeol → overlay}/components/session-indexing.tsx +0 -0
  242. /package/src/{saeeol → overlay}/components/tips.tsx +0 -0
  243. /package/src/{saeeol → overlay}/config/config-core.ts +0 -0
  244. /package/src/{saeeol → overlay}/config/config-helpers.ts +0 -0
  245. /package/src/{saeeol → overlay}/config/config-legacy.ts +0 -0
  246. /package/src/{saeeol → overlay}/config/config.ts +0 -0
  247. /package/src/{saeeol → overlay}/config/default-plugins.ts +0 -0
  248. /package/src/{saeeol → overlay}/config/markdown.ts +0 -0
  249. /package/src/{saeeol → overlay}/config-injector.ts +0 -0
  250. /package/src/{saeeol → overlay}/config-validation.ts +0 -0
  251. /package/src/{saeeol → overlay}/const.ts +0 -0
  252. /package/src/{saeeol → overlay}/cost-tracker/format.ts +0 -0
  253. /package/src/{saeeol → overlay}/cost-tracker/index.ts +0 -0
  254. /package/src/{saeeol → overlay}/cost-tracker/state.ts +0 -0
  255. /package/src/{saeeol → overlay}/cost-tracker/types.ts +0 -0
  256. /package/src/{saeeol → overlay}/docs/migration.md +0 -0
  257. /package/src/{saeeol → overlay}/docs/rules-migration.md +0 -0
  258. /package/src/{saeeol → overlay}/editor-context.ts +0 -0
  259. /package/src/{saeeol → overlay}/enhance-prompt.ts +0 -0
  260. /package/src/{saeeol → overlay}/errors.ts +0 -0
  261. /package/src/{saeeol → overlay}/generate-cli-docs.ts +0 -0
  262. /package/src/{saeeol → overlay}/help-command.ts +0 -0
  263. /package/src/{saeeol → overlay}/help.ts +0 -0
  264. /package/src/{saeeol → overlay}/i18n/index.ts +0 -0
  265. /package/src/{saeeol → overlay}/ignore-migrator.ts +0 -0
  266. /package/src/{saeeol → overlay}/index.ts +0 -0
  267. /package/src/{saeeol → overlay}/indexing-auth.ts +0 -0
  268. /package/src/{saeeol → overlay}/indexing-feature.ts +0 -0
  269. /package/src/{saeeol → overlay}/indexing-helpers.ts +0 -0
  270. /package/src/{saeeol → overlay}/indexing-label.ts +0 -0
  271. /package/src/{saeeol → overlay}/indexing-state.ts +0 -0
  272. /package/src/{saeeol → overlay}/indexing-types.ts +0 -0
  273. /package/src/{saeeol → overlay}/indexing.ts +0 -0
  274. /package/src/{saeeol → overlay}/lancedb.ts +0 -0
  275. /package/src/{saeeol → overlay}/mcp-migrator.ts +0 -0
  276. /package/src/{saeeol → overlay}/mcp-oauth-callback.ts +0 -0
  277. /package/src/{saeeol → overlay}/memory/age.ts +0 -0
  278. /package/src/{saeeol → overlay}/memory/index.ts +0 -0
  279. /package/src/{saeeol → overlay}/memory/paths.ts +0 -0
  280. /package/src/{saeeol → overlay}/memory/scan.ts +0 -0
  281. /package/src/{saeeol → overlay}/memory/types.ts +0 -0
  282. /package/src/{saeeol → overlay}/model-match.ts +0 -0
  283. /package/src/{saeeol → overlay}/modes-migrator.ts +0 -0
  284. /package/src/{saeeol → overlay}/paths.ts +0 -0
  285. /package/src/{saeeol → overlay}/permission/config-paths.ts +0 -0
  286. /package/src/{saeeol → overlay}/permission/drain.ts +0 -0
  287. /package/src/{saeeol → overlay}/permission/external-directory.ts +0 -0
  288. /package/src/{saeeol → overlay}/permission/read.ts +0 -0
  289. /package/src/{saeeol → overlay}/permission/routes.ts +0 -0
  290. /package/src/{saeeol → overlay}/permission/rule.ts +0 -0
  291. /package/src/{saeeol → overlay}/plan-followup-handover.ts +0 -0
  292. /package/src/{saeeol → overlay}/plan-followup-runtime.ts +0 -0
  293. /package/src/{saeeol → overlay}/plan-followup-session.ts +0 -0
  294. /package/src/{saeeol → overlay}/plan-followup.ts +0 -0
  295. /package/src/{saeeol → overlay}/plugins/home-footer.tsx +0 -0
  296. /package/src/{saeeol → overlay}/plugins/home-news.tsx +0 -0
  297. /package/src/{saeeol → overlay}/plugins/home-onboarding.tsx +0 -0
  298. /package/src/{saeeol → overlay}/plugins/sidebar-footer.tsx +0 -0
  299. /package/src/{saeeol → overlay}/plugins/sidebar-pr.tsx +0 -0
  300. /package/src/{saeeol → overlay}/plugins/sidebar-usage.tsx +0 -0
  301. /package/src/{saeeol → overlay}/project-id.ts +0 -0
  302. /package/src/{saeeol → overlay}/provider/codex-refresh.ts +0 -0
  303. /package/src/{saeeol → overlay}/provider/provider.ts +0 -0
  304. /package/src/{saeeol → overlay}/provider-options.ts +0 -0
  305. /package/src/{saeeol → overlay}/question/index.ts +0 -0
  306. /package/src/{saeeol → overlay}/remote-tui.tsx +0 -0
  307. /package/src/{saeeol → overlay}/review/command.ts +0 -0
  308. /package/src/{saeeol → overlay}/review/diff.ts +0 -0
  309. /package/src/{saeeol → overlay}/review/prompt.ts +0 -0
  310. /package/src/{saeeol → overlay}/review/review.ts +0 -0
  311. /package/src/{saeeol → overlay}/review/types.ts +0 -0
  312. /package/src/{saeeol → overlay}/review/worktree-diff.ts +0 -0
  313. /package/src/{saeeol → overlay}/rules-migrator.ts +0 -0
  314. /package/src/{saeeol → overlay}/server/instance.ts +0 -0
  315. /package/src/{saeeol → overlay}/server/router.ts +0 -0
  316. /package/src/{saeeol → overlay}/server/routes/commit-message.ts +0 -0
  317. /package/src/{saeeol → overlay}/server/routes/indexing.ts +0 -0
  318. /package/src/{saeeol → overlay}/server/server.ts +0 -0
  319. /package/src/{saeeol → overlay}/session/compaction-chunks-core.ts +0 -0
  320. /package/src/{saeeol → overlay}/session/compaction-chunks-utils.ts +0 -0
  321. /package/src/{saeeol → overlay}/session/compaction-chunks.ts +0 -0
  322. /package/src/{saeeol → overlay}/session/compaction-payload-recovery.ts +0 -0
  323. /package/src/{saeeol → overlay}/session/cost-propagation.ts +0 -0
  324. /package/src/{saeeol → overlay}/session/digest-storage.ts +0 -0
  325. /package/src/{saeeol → overlay}/session/fork.ts +0 -0
  326. /package/src/{saeeol → overlay}/session/index.ts +0 -0
  327. /package/src/{saeeol → overlay}/session/instruction.ts +0 -0
  328. /package/src/{saeeol → overlay}/session/kg-compaction.ts +0 -0
  329. /package/src/{saeeol → overlay}/session/llm.ts +0 -0
  330. /package/src/{saeeol → overlay}/session/overflow.ts +0 -0
  331. /package/src/{saeeol → overlay}/session/platform.ts +0 -0
  332. /package/src/{saeeol → overlay}/session/processor.ts +0 -0
  333. /package/src/{saeeol → overlay}/session/prompt-context.ts +0 -0
  334. /package/src/{saeeol → overlay}/session/prompt-plan.ts +0 -0
  335. /package/src/{saeeol → overlay}/session/prompt-queue.ts +0 -0
  336. /package/src/{saeeol → overlay}/session/prompt.ts +0 -0
  337. /package/src/{saeeol → overlay}/session/queries.ts +0 -0
  338. /package/src/{saeeol → overlay}/session/tui-sync.ts +0 -0
  339. /package/src/{saeeol → overlay}/session-import/routes.ts +0 -0
  340. /package/src/{saeeol → overlay}/session-import/service.ts +0 -0
  341. /package/src/{saeeol → overlay}/session-import/types.ts +0 -0
  342. /package/src/{saeeol → overlay}/skills/builtin.ts +0 -0
  343. /package/src/{saeeol → overlay}/skills/config.md +0 -0
  344. /package/src/{saeeol → overlay}/snapshot/diff-full.ts +0 -0
  345. /package/src/{saeeol → overlay}/snapshot/index.ts +0 -0
  346. /package/src/{saeeol → overlay}/snapshot/track-hooks.ts +0 -0
  347. /package/src/{saeeol → overlay}/snapshot/track-types.ts +0 -0
  348. /package/src/{saeeol → overlay}/snapshot/track.ts +0 -0
  349. /package/src/{saeeol → overlay}/soul.txt +0 -0
  350. /package/src/{saeeol → overlay}/suggestion/index.ts +0 -0
  351. /package/src/{saeeol → overlay}/suggestion/routes.ts +0 -0
  352. /package/src/{saeeol → overlay}/suggestion/tool.ts +0 -0
  353. /package/src/{saeeol → overlay}/suggestion/tool.txt +0 -0
  354. /package/src/{saeeol → overlay}/suggestion/tui/bar.tsx +0 -0
  355. /package/src/{saeeol → overlay}/suggestion/tui/prompt.tsx +0 -0
  356. /package/src/{saeeol → overlay}/suggestion/tui/render.tsx +0 -0
  357. /package/src/{saeeol → overlay}/suggestion/tui/sync.ts +0 -0
  358. /package/src/{saeeol → overlay}/system-prompt.ts +0 -0
  359. /package/src/{saeeol → overlay}/todo-view.ts +0 -0
  360. /package/src/{saeeol → overlay}/tool/agent-manager.ts +0 -0
  361. /package/src/{saeeol → overlay}/tool/agent-manager.txt +0 -0
  362. /package/src/{saeeol → overlay}/tool/bash-security-patterns.ts +0 -0
  363. /package/src/{saeeol → overlay}/tool/bash-security.ts +0 -0
  364. /package/src/{saeeol → overlay}/tool/question.ts +0 -0
  365. /package/src/{saeeol → overlay}/tool/registry.ts +0 -0
  366. /package/src/{saeeol → overlay}/tool/semantic-search.ts +0 -0
  367. /package/src/{saeeol → overlay}/tool/semantic-search.txt +0 -0
  368. /package/src/{saeeol → overlay}/tool/task.ts +0 -0
  369. /package/src/{saeeol → overlay}/ts-check.ts +0 -0
  370. /package/src/{saeeol → overlay}/ts-client.ts +0 -0
  371. /package/src/{saeeol → overlay}/tui/diff.ts +0 -0
  372. /package/src/{saeeol → overlay}/util/url.ts +0 -0
  373. /package/src/{saeeol → overlay}/worker/index.ts +0 -0
  374. /package/src/{saeeol → overlay}/worker/pool.ts +0 -0
  375. /package/src/{saeeol → overlay}/worker/store.ts +0 -0
  376. /package/src/{saeeol → overlay}/worker/types.ts +0 -0
  377. /package/src/{saeeol → overlay}/workflows-migrator.ts +0 -0
  378. /package/src/{saeeol → overlay}/worktree-cleanup.ts +0 -0
  379. /package/src/{saeeol → overlay}/worktree-family.ts +0 -0
@@ -0,0 +1,192 @@
1
+ import { Schema } from "effect"
2
+ import { SessionID } from "../core/schema"
3
+ import { ModelID, ProviderID } from "../../provider/schema"
4
+ import { zod } from "@/util/effect-zod"
5
+ import { NonNegativeInt, withStatics } from "@/util/schema"
6
+ import { namedSchemaError } from "@/util/named-schema-error"
7
+
8
+ export const OutputLengthError = namedSchemaError("MessageOutputLengthError", {})
9
+ export const AuthError = namedSchemaError("ProviderAuthError", {
10
+ providerID: Schema.String,
11
+ message: Schema.String,
12
+ })
13
+
14
+ const AuthErrorEffect = Schema.Struct({
15
+ name: Schema.Literal("ProviderAuthError"),
16
+ data: Schema.Struct({
17
+ providerID: Schema.String,
18
+ message: Schema.String,
19
+ }),
20
+ })
21
+
22
+ const OutputLengthErrorEffect = Schema.Struct({
23
+ name: Schema.Literal("MessageOutputLengthError"),
24
+ data: Schema.Struct({}),
25
+ })
26
+
27
+ const UnknownErrorEffect = Schema.Struct({
28
+ name: Schema.Literal("UnknownError"),
29
+ data: Schema.Struct({
30
+ message: Schema.String,
31
+ }),
32
+ })
33
+
34
+ export const ToolCall = Schema.Struct({
35
+ state: Schema.Literal("call"),
36
+ step: Schema.optional(NonNegativeInt),
37
+ toolCallId: Schema.String,
38
+ toolName: Schema.String,
39
+ args: Schema.Unknown,
40
+ })
41
+ .annotate({ identifier: "ToolCall" })
42
+ .pipe(withStatics((s) => ({ zod: zod(s) })))
43
+ export type ToolCall = Schema.Schema.Type<typeof ToolCall>
44
+
45
+ export const ToolPartialCall = Schema.Struct({
46
+ state: Schema.Literal("partial-call"),
47
+ step: Schema.optional(NonNegativeInt),
48
+ toolCallId: Schema.String,
49
+ toolName: Schema.String,
50
+ args: Schema.Unknown,
51
+ })
52
+ .annotate({ identifier: "ToolPartialCall" })
53
+ .pipe(withStatics((s) => ({ zod: zod(s) })))
54
+ export type ToolPartialCall = Schema.Schema.Type<typeof ToolPartialCall>
55
+
56
+ export const ToolResult = Schema.Struct({
57
+ state: Schema.Literal("result"),
58
+ step: Schema.optional(NonNegativeInt),
59
+ toolCallId: Schema.String,
60
+ toolName: Schema.String,
61
+ args: Schema.Unknown,
62
+ result: Schema.String,
63
+ })
64
+ .annotate({ identifier: "ToolResult" })
65
+ .pipe(withStatics((s) => ({ zod: zod(s) })))
66
+ export type ToolResult = Schema.Schema.Type<typeof ToolResult>
67
+
68
+ export const ToolInvocation = Schema.Union([ToolCall, ToolPartialCall, ToolResult])
69
+ .annotate({ identifier: "ToolInvocation", discriminator: "state" })
70
+ .pipe(withStatics((s) => ({ zod: zod(s) })))
71
+ export type ToolInvocation = Schema.Schema.Type<typeof ToolInvocation>
72
+
73
+ export const TextPart = Schema.Struct({
74
+ type: Schema.Literal("text"),
75
+ text: Schema.String,
76
+ })
77
+ .annotate({ identifier: "TextPart" })
78
+ .pipe(withStatics((s) => ({ zod: zod(s) })))
79
+ export type TextPart = Schema.Schema.Type<typeof TextPart>
80
+
81
+ export const ReasoningPart = Schema.Struct({
82
+ type: Schema.Literal("reasoning"),
83
+ text: Schema.String,
84
+ providerMetadata: Schema.optional(Schema.Record(Schema.String, Schema.Unknown)),
85
+ })
86
+ .annotate({ identifier: "ReasoningPart" })
87
+ .pipe(withStatics((s) => ({ zod: zod(s) })))
88
+ export type ReasoningPart = Schema.Schema.Type<typeof ReasoningPart>
89
+
90
+ export const ToolInvocationPart = Schema.Struct({
91
+ type: Schema.Literal("tool-invocation"),
92
+ toolInvocation: ToolInvocation,
93
+ })
94
+ .annotate({ identifier: "ToolInvocationPart" })
95
+ .pipe(withStatics((s) => ({ zod: zod(s) })))
96
+ export type ToolInvocationPart = Schema.Schema.Type<typeof ToolInvocationPart>
97
+
98
+ export const SourceUrlPart = Schema.Struct({
99
+ type: Schema.Literal("source-url"),
100
+ sourceId: Schema.String,
101
+ url: Schema.String,
102
+ title: Schema.optional(Schema.String),
103
+ providerMetadata: Schema.optional(Schema.Record(Schema.String, Schema.Unknown)),
104
+ })
105
+ .annotate({ identifier: "SourceUrlPart" })
106
+ .pipe(withStatics((s) => ({ zod: zod(s) })))
107
+ export type SourceUrlPart = Schema.Schema.Type<typeof SourceUrlPart>
108
+
109
+ export const FilePart = Schema.Struct({
110
+ type: Schema.Literal("file"),
111
+ mediaType: Schema.String,
112
+ filename: Schema.optional(Schema.String),
113
+ url: Schema.String,
114
+ })
115
+ .annotate({ identifier: "FilePart" })
116
+ .pipe(withStatics((s) => ({ zod: zod(s) })))
117
+ export type FilePart = Schema.Schema.Type<typeof FilePart>
118
+
119
+ export const StepStartPart = Schema.Struct({
120
+ type: Schema.Literal("step-start"),
121
+ })
122
+ .annotate({ identifier: "StepStartPart" })
123
+ .pipe(withStatics((s) => ({ zod: zod(s) })))
124
+ export type StepStartPart = Schema.Schema.Type<typeof StepStartPart>
125
+
126
+ export const MessagePart = Schema.Union([
127
+ TextPart,
128
+ ReasoningPart,
129
+ ToolInvocationPart,
130
+ SourceUrlPart,
131
+ FilePart,
132
+ StepStartPart,
133
+ ])
134
+ .annotate({ identifier: "MessagePart", discriminator: "type" })
135
+ .pipe(withStatics((s) => ({ zod: zod(s) })))
136
+ export type MessagePart = Schema.Schema.Type<typeof MessagePart>
137
+
138
+ export const Info = Schema.Struct({
139
+ id: Schema.String,
140
+ role: Schema.Literals(["user", "assistant"]),
141
+ parts: Schema.Array(MessagePart),
142
+ metadata: Schema.Struct({
143
+ time: Schema.Struct({
144
+ created: NonNegativeInt,
145
+ completed: Schema.optional(NonNegativeInt),
146
+ }),
147
+ error: Schema.optional(Schema.Union([AuthErrorEffect, UnknownErrorEffect, OutputLengthErrorEffect])),
148
+ sessionID: SessionID,
149
+ tool: Schema.Record(
150
+ Schema.String,
151
+ Schema.StructWithRest(
152
+ Schema.Struct({
153
+ title: Schema.String,
154
+ snapshot: Schema.optional(Schema.String),
155
+ time: Schema.Struct({
156
+ start: NonNegativeInt,
157
+ end: NonNegativeInt,
158
+ }),
159
+ }),
160
+ [Schema.Record(Schema.String, Schema.Unknown)],
161
+ ),
162
+ ),
163
+ assistant: Schema.optional(
164
+ Schema.Struct({
165
+ system: Schema.Array(Schema.String),
166
+ modelID: ModelID,
167
+ providerID: ProviderID,
168
+ path: Schema.Struct({
169
+ cwd: Schema.String,
170
+ root: Schema.String,
171
+ }),
172
+ cost: Schema.Finite,
173
+ summary: Schema.optional(Schema.Boolean),
174
+ tokens: Schema.Struct({
175
+ input: NonNegativeInt,
176
+ output: NonNegativeInt,
177
+ reasoning: NonNegativeInt,
178
+ cache: Schema.Struct({
179
+ read: NonNegativeInt,
180
+ write: NonNegativeInt,
181
+ }),
182
+ }),
183
+ }),
184
+ ),
185
+ snapshot: Schema.optional(Schema.String),
186
+ }).annotate({ identifier: "MessageMetadata" }),
187
+ })
188
+ .annotate({ identifier: "Message" })
189
+ .pipe(withStatics((s) => ({ zod: zod(s) })))
190
+ export type Info = Schema.Schema.Type<typeof Info>
191
+
192
+ export * as Message from "./message"
@@ -1,83 +1 @@
1
- /** 에러 타입 + fromError + OutputFormat — message-v2.ts에서 분리 */
2
-
3
- import { APICallError, LoadAPIKeyError } from "ai"
4
- import { NamedError } from "@saeeol/core/util/error"
5
- import * as ProviderError from "@/provider/error"
6
- import { SessionNetwork } from "./network"
7
- import { CodexAuthExpiredError } from "@/saeeol/provider/codex-refresh"
8
- import { Effect, Schema } from "effect"
9
- import { zod } from "@/util/effect-zod"
10
- import { NonNegativeInt } from "@/util/schema"
11
- import { namedSchemaError } from "@/util/named-schema-error"
12
- import { errorMessage } from "@/util/error"
13
- import { ProviderID } from "@/provider/schema"
14
- import type { Assistant } from "./message-types"
15
-
16
- interface FetchDecompressionError extends Error { code: "ZlibError"; errno: number; path: string }
17
-
18
- export const OutputLengthError = namedSchemaError("MessageOutputLengthError", {})
19
- export const AbortedError = namedSchemaError("MessageAbortedError", { message: Schema.String })
20
- export const StructuredOutputError = namedSchemaError("StructuredOutputError", { message: Schema.String, retries: NonNegativeInt })
21
- export const AuthError = namedSchemaError("ProviderAuthError", { providerID: Schema.String, message: Schema.String })
22
- export const APIError = namedSchemaError("APIError", {
23
- message: Schema.String, statusCode: Schema.optional(NonNegativeInt), isRetryable: Schema.Boolean,
24
- responseHeaders: Schema.optional(Schema.Record(Schema.String, Schema.String)), responseBody: Schema.optional(Schema.String),
25
- metadata: Schema.optional(Schema.Record(Schema.String, Schema.String)),
26
- })
27
- export type APIError = import("zod").infer<typeof APIError.Schema>
28
- export const ContextOverflowError = namedSchemaError("ContextOverflowError", { message: Schema.String, responseBody: Schema.optional(Schema.String) })
29
-
30
- export class OutputFormatText extends Schema.Class<OutputFormatText>("OutputFormatText")({ type: Schema.Literal("text") }) { static readonly zod = zod(this) }
31
- export class OutputFormatJsonSchema extends Schema.Class<OutputFormatJsonSchema>("OutputFormatJsonSchema")({
32
- type: Schema.Literal("json_schema"), schema: Schema.Record(Schema.String, Schema.Any).annotate({ identifier: "JSONSchema" }),
33
- retryCount: NonNegativeInt.pipe(Schema.optional, Schema.withDecodingDefault(Effect.succeed(2))),
34
- }) { static readonly zod = zod(this) }
35
-
36
- const _Format = Schema.Union([OutputFormatText, OutputFormatJsonSchema]).annotate({ discriminator: "type", identifier: "OutputFormat" })
37
- export { _Format }
38
- export const Format = Object.assign(_Format, { zod: zod(_Format) })
39
- export type OutputFormat = Schema.Schema.Type<typeof _Format>
40
-
41
- // Assistant error union (Zod)
42
- import z from "zod"
43
- const AssistantErrorZod = z.discriminatedUnion("name", [
44
- AuthError.Schema, NamedError.Unknown.Schema, OutputLengthError.Schema, AbortedError.Schema,
45
- StructuredOutputError.Schema, ContextOverflowError.Schema, APIError.Schema,
46
- ])
47
- export type AssistantError = z.infer<typeof AssistantErrorZod>
48
- export { AssistantErrorZod }
49
-
50
- // Assistant error union (Effect Schema)
51
- export const AssistantErrorSchema = Schema.Union([
52
- AuthError.EffectSchema,
53
- Schema.Struct({ name: Schema.Literal("UnknownError"), data: Schema.Struct({ message: Schema.String }) }).annotate({ identifier: "UnknownError" }),
54
- OutputLengthError.EffectSchema, AbortedError.EffectSchema, StructuredOutputError.EffectSchema, ContextOverflowError.EffectSchema, APIError.EffectSchema,
55
- ]).annotate({ discriminator: "name" })
56
-
57
- export function fromError(e: unknown, ctx: { providerID: ProviderID; aborted?: boolean }): NonNullable<Assistant["error"]> {
58
- switch (true) {
59
- case e instanceof DOMException && e.name === "AbortError": return new AbortedError({ message: e.message }, { cause: e }).toObject()
60
- case OutputLengthError.isInstance(e): return e
61
- case LoadAPIKeyError.isInstance(e): return new AuthError({ providerID: ctx.providerID, message: e.message }, { cause: e }).toObject()
62
- case e instanceof CodexAuthExpiredError: return new AuthError({ providerID: "openai", message: e.message }, { cause: e }).toObject()
63
- case SessionNetwork.disconnected(e):
64
- return new APIError({ message: SessionNetwork.message(e), isRetryable: true, metadata: { code: (e as import("bun").SystemError).code ?? "", syscall: (e as import("bun").SystemError).syscall ?? "", message: (e as import("bun").SystemError).message ?? "" } }, { cause: e }).toObject()
65
- case e instanceof Error && (e as FetchDecompressionError).code === "ZlibError":
66
- if (ctx.aborted) return new AbortedError({ message: e.message }, { cause: e }).toObject()
67
- return new APIError({ message: "Response decompression failed", isRetryable: true, metadata: { code: (e as FetchDecompressionError).code, message: e.message } }, { cause: e }).toObject()
68
- case APICallError.isInstance(e):
69
- const parsed = ProviderError.parseAPICallError({ providerID: ctx.providerID, error: e })
70
- if (parsed.type === "context_overflow") return new ContextOverflowError({ message: parsed.message, responseBody: parsed.responseBody }, { cause: e }).toObject()
71
- return new APIError({ message: parsed.message, statusCode: parsed.statusCode, isRetryable: parsed.isRetryable, responseHeaders: parsed.responseHeaders, responseBody: parsed.responseBody, metadata: parsed.metadata }, { cause: e }).toObject()
72
- case e instanceof Error: return new NamedError.Unknown({ message: errorMessage(e) }, { cause: e }).toObject()
73
- default:
74
- try {
75
- const parsed = ProviderError.parseStreamError(e)
76
- if (parsed) {
77
- if (parsed.type === "context_overflow") return new ContextOverflowError({ message: parsed.message, responseBody: parsed.responseBody }, { cause: e }).toObject()
78
- return new APIError({ message: parsed.message, isRetryable: parsed.isRetryable, responseBody: parsed.responseBody }, { cause: e }).toObject()
79
- }
80
- } catch {}
81
- return new NamedError.Unknown({ message: JSON.stringify(e) }, { cause: e }).toObject()
82
- }
83
- }
1
+ export * from "./message/message-errors"
@@ -1,89 +1 @@
1
- /** Part 스키마 + ToolState + Input 스키마 — message-v2.ts에서 분리 */
2
-
3
- import { SessionID, MessageID, PartID } from "./schema"
4
- import { LSP } from "@/lsp/lsp"
5
- import { Snapshot } from "@/snapshot"
6
- import { Effect, Schema, Types } from "effect"
7
- import { zod } from "@/util/effect-zod"
8
- import { NonNegativeInt, withStatics } from "@/util/schema"
9
- import { APIError } from "./message-errors"
10
- import { ModelID, ProviderID } from "@/provider/schema"
11
- import z from "zod"
12
-
13
- const partBase = { id: PartID, sessionID: SessionID, messageID: MessageID }
14
-
15
- export const SnapshotPart = Schema.Struct({ ...partBase, type: Schema.Literal("snapshot"), snapshot: Schema.String }).annotate({ identifier: "SnapshotPart" }).pipe(withStatics((s) => ({ zod: zod(s) })))
16
- export type SnapshotPart = Types.DeepMutable<Schema.Schema.Type<typeof SnapshotPart>>
17
- export const PatchPart = Schema.Struct({ ...partBase, type: Schema.Literal("patch"), hash: Schema.String, files: Schema.Array(Schema.String) }).annotate({ identifier: "PatchPart" }).pipe(withStatics((s) => ({ zod: zod(s) })))
18
- export type PatchPart = Types.DeepMutable<Schema.Schema.Type<typeof PatchPart>>
19
- export const TextPart = Schema.Struct({
20
- ...partBase, type: Schema.Literal("text"), text: Schema.String, synthetic: Schema.optional(Schema.Boolean), ignored: Schema.optional(Schema.Boolean),
21
- time: Schema.optional(Schema.Struct({ start: NonNegativeInt, end: Schema.optional(NonNegativeInt) })), metadata: Schema.optional(Schema.Record(Schema.String, Schema.Any)),
22
- }).annotate({ identifier: "TextPart" }).pipe(withStatics((s) => ({ zod: zod(s) })))
23
- export type TextPart = Types.DeepMutable<Schema.Schema.Type<typeof TextPart>>
24
- export const ReasoningPart = Schema.Struct({
25
- ...partBase, type: Schema.Literal("reasoning"), text: Schema.String, metadata: Schema.optional(Schema.Record(Schema.String, Schema.Any)),
26
- time: Schema.Struct({ start: NonNegativeInt, end: Schema.optional(NonNegativeInt) }),
27
- }).annotate({ identifier: "ReasoningPart" }).pipe(withStatics((s) => ({ zod: zod(s) })))
28
- export type ReasoningPart = Types.DeepMutable<Schema.Schema.Type<typeof ReasoningPart>>
29
-
30
- const filePartSourceBase = { text: Schema.Struct({ value: Schema.String, start: NonNegativeInt, end: NonNegativeInt }).annotate({ identifier: "FilePartSourceText" }) }
31
- export const FileSource = Schema.Struct({ ...filePartSourceBase, type: Schema.Literal("file"), path: Schema.String }).annotate({ identifier: "FileSource" }).pipe(withStatics((s) => ({ zod: zod(s) })))
32
- export const SymbolSource = Schema.Struct({ ...filePartSourceBase, type: Schema.Literal("symbol"), path: Schema.String, range: LSP.Range, name: Schema.String, kind: NonNegativeInt }).annotate({ identifier: "SymbolSource" }).pipe(withStatics((s) => ({ zod: zod(s) })))
33
- export const ResourceSource = Schema.Struct({ ...filePartSourceBase, type: Schema.Literal("resource"), clientName: Schema.String, uri: Schema.String }).annotate({ identifier: "ResourceSource" }).pipe(withStatics((s) => ({ zod: zod(s) })))
34
-
35
- const _FilePartSource = Schema.Union([FileSource, SymbolSource, ResourceSource]).annotate({ discriminator: "type", identifier: "FilePartSource" })
36
- export const FilePartSource = Object.assign(_FilePartSource, { zod: zod(_FilePartSource) })
37
-
38
- export const FilePart = Schema.Struct({ ...partBase, type: Schema.Literal("file"), mime: Schema.String, filename: Schema.optional(Schema.String), url: Schema.String, source: Schema.optional(_FilePartSource) }).annotate({ identifier: "FilePart" }).pipe(withStatics((s) => ({ zod: zod(s) })))
39
- export type FilePart = Types.DeepMutable<Schema.Schema.Type<typeof FilePart>>
40
- export const AgentPart = Schema.Struct({ ...partBase, type: Schema.Literal("agent"), name: Schema.String, source: Schema.optional(Schema.Struct({ value: Schema.String, start: NonNegativeInt, end: NonNegativeInt })) }).annotate({ identifier: "AgentPart" }).pipe(withStatics((s) => ({ zod: zod(s) })))
41
- export type AgentPart = Types.DeepMutable<Schema.Schema.Type<typeof AgentPart>>
42
- export const CompactionPart = Schema.Struct({ ...partBase, type: Schema.Literal("compaction"), auto: Schema.Boolean, overflow: Schema.optional(Schema.Boolean), tail_start_id: Schema.optional(MessageID) }).annotate({ identifier: "CompactionPart" }).pipe(withStatics((s) => ({ zod: zod(s) })))
43
- export type CompactionPart = Types.DeepMutable<Schema.Schema.Type<typeof CompactionPart>>
44
- export const SubtaskPart = Schema.Struct({ ...partBase, type: Schema.Literal("subtask"), prompt: Schema.String, description: Schema.String, agent: Schema.String, model: Schema.optional(Schema.Struct({ providerID: ProviderID, modelID: ModelID })), command: Schema.optional(Schema.String) }).annotate({ identifier: "SubtaskPart" }).pipe(withStatics((s) => ({ zod: zod(s) })))
45
- export type SubtaskPart = Types.DeepMutable<Schema.Schema.Type<typeof SubtaskPart>>
46
- export const RetryPart = Schema.Struct({ ...partBase, type: Schema.Literal("retry"), attempt: NonNegativeInt, error: APIError.EffectSchema, time: Schema.Struct({ created: NonNegativeInt }) }).annotate({ identifier: "RetryPart" }).pipe(withStatics((s) => ({ zod: zod(s) })))
47
- export type RetryPart = Omit<Types.DeepMutable<Schema.Schema.Type<typeof RetryPart>>, "error"> & { error: APIError }
48
- export const StepStartPart = Schema.Struct({ ...partBase, type: Schema.Literal("step-start"), snapshot: Schema.optional(Schema.String) }).annotate({ identifier: "StepStartPart" }).pipe(withStatics((s) => ({ zod: zod(s) })))
49
- export type StepStartPart = Types.DeepMutable<Schema.Schema.Type<typeof StepStartPart>>
50
- export const StepFinishPart = Schema.Struct({
51
- ...partBase, type: Schema.Literal("step-finish"), reason: Schema.String, snapshot: Schema.optional(Schema.String), cost: Schema.Finite,
52
- tokens: Schema.Struct({ total: Schema.optional(NonNegativeInt), input: NonNegativeInt, output: NonNegativeInt, reasoning: NonNegativeInt, cache: Schema.Struct({ read: NonNegativeInt, write: NonNegativeInt }) }),
53
- }).annotate({ identifier: "StepFinishPart" }).pipe(withStatics((s) => ({ zod: zod(s) })))
54
- export type StepFinishPart = Types.DeepMutable<Schema.Schema.Type<typeof StepFinishPart>>
55
-
56
- export const ToolStatePending = Schema.Struct({ status: Schema.Literal("pending"), input: Schema.Record(Schema.String, Schema.Any), raw: Schema.String }).annotate({ identifier: "ToolStatePending" }).pipe(withStatics((s) => ({ zod: zod(s) })))
57
- export type ToolStatePending = Types.DeepMutable<Schema.Schema.Type<typeof ToolStatePending>>
58
- export const ToolStateRunning = Schema.Struct({ status: Schema.Literal("running"), input: Schema.Record(Schema.String, Schema.Any), title: Schema.optional(Schema.String), metadata: Schema.optional(Schema.Record(Schema.String, Schema.Any)), time: Schema.Struct({ start: NonNegativeInt }) }).annotate({ identifier: "ToolStateRunning" }).pipe(withStatics((s) => ({ zod: zod(s) })))
59
- export type ToolStateRunning = Types.DeepMutable<Schema.Schema.Type<typeof ToolStateRunning>>
60
- export const ToolStateCompleted = Schema.Struct({
61
- status: Schema.Literal("completed"), input: Schema.Record(Schema.String, Schema.Any), output: Schema.String, title: Schema.String, metadata: Schema.Record(Schema.String, Schema.Any),
62
- time: Schema.Struct({ start: NonNegativeInt, end: NonNegativeInt, compacted: Schema.optional(NonNegativeInt) }), attachments: Schema.optional(Schema.Array(FilePart)),
63
- }).annotate({ identifier: "ToolStateCompleted" }).pipe(withStatics((s) => ({ zod: zod(s) })))
64
- export type ToolStateCompleted = Types.DeepMutable<Schema.Schema.Type<typeof ToolStateCompleted>>
65
- export function truncateToolOutput(text: string, maxChars?: number) { if (!maxChars || text.length <= maxChars) return text; return `${text.slice(0, maxChars)}\n[Tool output truncated for compaction: omitted ${text.length - maxChars} chars]` }
66
- export const ToolStateError = Schema.Struct({ status: Schema.Literal("error"), input: Schema.Record(Schema.String, Schema.Any), error: Schema.String, metadata: Schema.optional(Schema.Record(Schema.String, Schema.Any)), time: Schema.Struct({ start: NonNegativeInt, end: NonNegativeInt }) }).annotate({ identifier: "ToolStateError" }).pipe(withStatics((s) => ({ zod: zod(s) })))
67
- export type ToolStateError = Types.DeepMutable<Schema.Schema.Type<typeof ToolStateError>>
68
-
69
- const _ToolState = Schema.Union([ToolStatePending, ToolStateRunning, ToolStateCompleted, ToolStateError]).annotate({ discriminator: "status", identifier: "ToolState" })
70
- export const ToolState = Object.assign(_ToolState, { zod: zod(_ToolState) as unknown as z.ZodType<ToolStatePending | ToolStateRunning | ToolStateCompleted | ToolStateError> })
71
- export type ToolState = ToolStatePending | ToolStateRunning | ToolStateCompleted | ToolStateError
72
- export const ToolPart = Schema.Struct({ ...partBase, type: Schema.Literal("tool"), callID: Schema.String, tool: Schema.String, state: _ToolState, metadata: Schema.optional(Schema.Record(Schema.String, Schema.Any)) }).annotate({ identifier: "ToolPart" }).pipe(withStatics((s) => ({ zod: zod(s) })))
73
- export type ToolPart = Omit<Types.DeepMutable<Schema.Schema.Type<typeof ToolPart>>, "state"> & { state: ToolState }
74
-
75
- // Input variants (without ambient IDs)
76
- export const TextPartInput = Schema.Struct({ id: Schema.optional(PartID), type: Schema.Literal("text"), text: Schema.String, synthetic: Schema.optional(Schema.Boolean), ignored: Schema.optional(Schema.Boolean), time: Schema.optional(Schema.Struct({ start: NonNegativeInt, end: Schema.optional(NonNegativeInt) })), metadata: Schema.optional(Schema.Record(Schema.String, Schema.Any)) }).annotate({ identifier: "TextPartInput" }).pipe(withStatics((s) => ({ zod: zod(s) })))
77
- export type TextPartInput = Types.DeepMutable<Schema.Schema.Type<typeof TextPartInput>>
78
- export const FilePartInput = Schema.Struct({ id: Schema.optional(PartID), type: Schema.Literal("file"), mime: Schema.String, filename: Schema.optional(Schema.String), url: Schema.String, source: Schema.optional(_FilePartSource) }).annotate({ identifier: "FilePartInput" }).pipe(withStatics((s) => ({ zod: zod(s) })))
79
- export type FilePartInput = Types.DeepMutable<Schema.Schema.Type<typeof FilePartInput>>
80
- export const AgentPartInput = Schema.Struct({ id: Schema.optional(PartID), type: Schema.Literal("agent"), name: Schema.String, source: Schema.optional(Schema.Struct({ value: Schema.String, start: NonNegativeInt, end: NonNegativeInt })) }).annotate({ identifier: "AgentPartInput" }).pipe(withStatics((s) => ({ zod: zod(s) })))
81
- export type AgentPartInput = Types.DeepMutable<Schema.Schema.Type<typeof AgentPartInput>>
82
- export const SubtaskPartInput = Schema.Struct({ id: Schema.optional(PartID), type: Schema.Literal("subtask"), prompt: Schema.String, description: Schema.String, agent: Schema.String, model: Schema.optional(Schema.Struct({ providerID: ProviderID, modelID: ModelID })), command: Schema.optional(Schema.String) }).annotate({ identifier: "SubtaskPartInput" }).pipe(withStatics((s) => ({ zod: zod(s) })))
83
- export type SubtaskPartInput = Types.DeepMutable<Schema.Schema.Type<typeof SubtaskPartInput>>
84
-
85
- // Part union
86
- const _Part = Schema.Union([TextPart, SubtaskPart, ReasoningPart, FilePart, ToolPart, StepStartPart, StepFinishPart, SnapshotPart, PatchPart, AgentPart, RetryPart, CompactionPart]).annotate({ discriminator: "type", identifier: "Part" })
87
- export const Part = Object.assign(_Part, { zod: zod(_Part) as unknown as z.ZodType<TextPart | SubtaskPart | ReasoningPart | FilePart | ToolPart | StepStartPart | StepFinishPart | SnapshotPart | PatchPart | AgentPart | RetryPart | CompactionPart> })
88
- export type Part = TextPart | SubtaskPart | ReasoningPart | FilePart | ToolPart | StepStartPart | StepFinishPart | SnapshotPart | PatchPart | AgentPart | RetryPart | CompactionPart
89
- export { _Part }
1
+ export * from "./message/message-parts"
@@ -1,107 +1 @@
1
- import { Effect } from "effect"
2
- import { and, desc, eq } from "drizzle-orm"
3
- import { Database } from "@/storage/db"
4
- import { NotFoundError } from "@/storage/storage"
5
- import { MessageTable, PartTable, SessionTable } from "./session.sql"
6
- import { SessionID, MessageID } from "./schema"
7
- import type { WithParts } from "./message-types"
8
- import { cursor } from "./message-types"
9
- import type { Part, CompactionPart } from "./message-parts"
10
- import { stripPartMetadata, hydrate, older, toInfo } from "./message-transform"
11
-
12
- export function page(input: { sessionID: SessionID; limit: number; before?: string }) {
13
- const before = input.before ? cursor.decode(input.before) : undefined
14
- const where = before
15
- ? and(eq(MessageTable.session_id, input.sessionID), older(before))
16
- : eq(MessageTable.session_id, input.sessionID)
17
- const rows = Database.use((db) =>
18
- db
19
- .select()
20
- .from(MessageTable)
21
- .where(where)
22
- .orderBy(desc(MessageTable.time_created), desc(MessageTable.id))
23
- .limit(input.limit + 1)
24
- .all(),
25
- )
26
- if (rows.length === 0) {
27
- const row = Database.use((db) =>
28
- db.select({ id: SessionTable.id }).from(SessionTable).where(eq(SessionTable.id, input.sessionID)).get(),
29
- )
30
- if (!row) throw new NotFoundError({ message: `Session not found: ${input.sessionID}` })
31
- return { items: [] as WithParts[], more: false }
32
- }
33
- const more = rows.length > input.limit
34
- const slice = more ? rows.slice(0, input.limit) : rows
35
- const items = hydrate(slice)
36
- items.reverse()
37
- const tail = slice.at(-1)
38
- return {
39
- items,
40
- more,
41
- cursor: more && tail ? cursor.encode({ id: tail.id, time: tail.time_created }) : undefined,
42
- }
43
- }
44
-
45
- export function* stream(sessionID: SessionID) {
46
- const size = 50
47
- let before: string | undefined
48
- while (true) {
49
- const next = page({ sessionID, limit: size, before })
50
- if (next.items.length === 0) break
51
- for (let i = next.items.length - 1; i >= 0; i--) yield next.items[i]
52
- if (!next.more || !next.cursor) break
53
- before = next.cursor
54
- }
55
- }
56
-
57
- export function parts(message_id: MessageID) {
58
- const rows = Database.use((db) =>
59
- db.select().from(PartTable).where(eq(PartTable.message_id, message_id)).orderBy(PartTable.id).all(),
60
- )
61
- return rows.map((row) =>
62
- stripPartMetadata({ ...row.data, id: row.id, sessionID: row.session_id, messageID: row.message_id } as Part),
63
- )
64
- }
65
-
66
- export function get(input: { sessionID: SessionID; messageID: MessageID }): WithParts {
67
- const row = Database.use((db) =>
68
- db
69
- .select()
70
- .from(MessageTable)
71
- .where(and(eq(MessageTable.id, input.messageID), eq(MessageTable.session_id, input.sessionID)))
72
- .get(),
73
- )
74
- if (!row) throw new NotFoundError({ message: `Message not found: ${input.messageID}` })
75
- return { info: toInfo(row), parts: parts(input.messageID) }
76
- }
77
-
78
- export function filterCompacted(msgs: Iterable<WithParts>) {
79
- const result = [] as WithParts[]
80
- const completed = new Set<string>()
81
- let retain: MessageID | undefined
82
- for (const msg of msgs) {
83
- result.push(msg)
84
- if (retain) {
85
- if (msg.info.id === retain) break
86
- continue
87
- }
88
- if (msg.info.role === "user" && completed.has(msg.info.id)) {
89
- const part = msg.parts.find((item): item is CompactionPart => item.type === "compaction")
90
- if (!part) continue
91
- if (!part.tail_start_id) break
92
- retain = part.tail_start_id
93
- if (msg.info.id === retain) break
94
- continue
95
- }
96
- if (msg.info.role === "user" && completed.has(msg.info.id) && msg.parts.some((part) => part.type === "compaction"))
97
- break
98
- if (msg.info.role === "assistant" && msg.info.summary && msg.info.finish && !msg.info.error)
99
- completed.add(msg.info.parentID)
100
- }
101
- result.reverse()
102
- return result
103
- }
104
-
105
- export const filterCompactedEffect = Effect.fnUntraced(function* (sessionID: SessionID) {
106
- return filterCompacted(stream(sessionID))
107
- })
1
+ export * from "./message/message-query"
@@ -1,156 +1 @@
1
- /** toModelMessages + 메타데이터 스트리핑 + DB 하이드레이션 — message-v2.ts에서 분리 */
2
-
3
- import { convertToModelMessages, type UIMessage } from "ai"
4
- import { Effect } from "effect"
5
- import { and, desc, eq, inArray, lt, or } from "drizzle-orm"
6
- import { Database } from "@/storage/db"
7
- import { MessageTable, PartTable } from "./session.sql"
8
- import { Snapshot } from "@/snapshot"
9
- import { iife } from "@/util/iife"
10
- import { isMedia } from "@/util/media"
11
- import { MessageID, SessionID } from "./schema"
12
- import * as EffectLogger from "@saeeol/core/effect/logger"
13
- import type { Provider } from "@/provider/provider"
14
- export const SYNTHETIC_ATTACHMENT_PROMPT = "Attached image(s) from tool result:"
15
- import type { Info, User, WithParts } from "./message-types"
16
- import type { Part, CompactionPart, ToolState, ToolStateCompleted } from "./message-parts"
17
- import { truncateToolOutput } from "./message-parts"
18
- import { AbortedError } from "./message-errors"
19
-
20
- export { isMedia }
21
-
22
- function stripPatch(value: unknown) {
23
- if (typeof value !== "string") return undefined
24
- if (Buffer.byteLength(value) > Snapshot.MAX_DIFF_SIZE) return undefined
25
- return value
26
- }
27
- function withPatch(value: unknown) { const kept = stripPatch(value); return kept ? { patch: kept } : {} }
28
-
29
- export function stripPartMetadata(part: Part): Part {
30
- if (part.type !== "tool") return part
31
- const { state } = part
32
- if (state.status !== "completed" && state.status !== "running") return part
33
- const meta = state.metadata
34
- if (!meta) return part
35
- let changed = false
36
- let next = meta
37
- if (meta.diff !== undefined) { const { diff, ...rest } = next; next = rest; changed = true }
38
- if (meta.filediff) { const { before, after, patch, ...rest } = meta.filediff; next = { ...next, filediff: { ...rest, ...withPatch(patch) } }; changed = true }
39
- if (Array.isArray(meta.files) && meta.files.length > 0) { next = { ...next, files: meta.files.map((f: Record<string, unknown>) => { const { before, after, patch, diff, ...rest } = f; const kept = stripPatch(patch) ?? stripPatch(diff); return { ...rest, ...(kept ? { patch: kept } : {}) } }) }; changed = true }
40
- if (Array.isArray(meta.results) && meta.results.length > 0) { next = { ...next, results: meta.results.map((r: Record<string, unknown>) => { const { diff, ...rest } = r; if (!r.filediff || typeof r.filediff !== "object") return rest; const fd = r.filediff as Record<string, unknown>; const { before, after, patch, ...file } = fd; return { ...rest, filediff: { ...file, ...withPatch(patch) } } }) }; changed = true }
41
- if (!changed) return part
42
- return { ...part, state: { ...state, metadata: next } } as Part
43
- }
44
-
45
- export function stripMessageMetadata(info: Info): Info {
46
- if (info.role !== "user") return info
47
- const user = info as User
48
- if (!user.summary?.diffs?.length) return info
49
- const oversized = (d: Snapshot.FileDiff) => d.patch && Buffer.byteLength(d.patch) > Snapshot.MAX_DIFF_SIZE
50
- if (!user.summary.diffs.some(oversized)) return info
51
- return { ...user, summary: { ...user.summary, diffs: user.summary.diffs.map((d: Snapshot.FileDiff) => (oversized(d) ? { ...d, patch: "" } : d)) } } as Info
52
- }
53
-
54
- export const toInfo = (row: typeof MessageTable.$inferSelect) => stripMessageMetadata({ ...row.data, id: row.id, sessionID: row.session_id } as Info)
55
- const toPart = (row: typeof PartTable.$inferSelect) => stripPartMetadata({ ...row.data, id: row.id, sessionID: row.session_id, messageID: row.message_id } as Part)
56
-
57
- export const older = (row: { id: MessageID; time: number }) =>
58
- or(lt(MessageTable.time_created, row.time), and(eq(MessageTable.time_created, row.time), lt(MessageTable.id, row.id)))
59
-
60
- export function hydrate(rows: (typeof MessageTable.$inferSelect)[]) {
61
- const ids = rows.map((row) => row.id)
62
- const partByMessage = new Map<string, Part[]>()
63
- if (ids.length > 0) {
64
- const partRows = Database.use((db) => db.select().from(PartTable).where(inArray(PartTable.message_id, ids)).orderBy(PartTable.message_id, PartTable.id).all())
65
- for (const row of partRows) { const next = toPart(row); const list = partByMessage.get(row.message_id); if (list) list.push(next); else partByMessage.set(row.message_id, [next]) }
66
- }
67
- return rows.map((row) => ({ info: toInfo(row), parts: partByMessage.get(row.id) ?? [] }))
68
- }
69
-
70
- function providerMeta(metadata: Record<string, any> | undefined) {
71
- if (!metadata) return undefined
72
- const { providerExecuted: _, ...rest } = metadata
73
- return Object.keys(rest).length > 0 ? rest : undefined
74
- }
75
-
76
- export const toModelMessagesEffect = Effect.fnUntraced(function* (input: WithParts[], model: Provider.Model, options?: { stripMedia?: boolean; toolOutputMaxChars?: number }) {
77
- const result: UIMessage[] = []
78
- const toolNames = new Set<string>()
79
- const supportsMediaInToolResults = (() => {
80
- if (model.api.npm === "@ai-sdk/anthropic") return true
81
- if (model.api.npm === "@ai-sdk/openai") return true
82
- if (model.api.npm === "@ai-sdk/amazon-bedrock") return true
83
- if (model.api.npm === "@ai-sdk/google-vertex/anthropic") return true
84
- if (model.api.npm === "@ai-sdk/google") { const id = model.api.id.toLowerCase(); return id.includes("gemini-3") && !id.includes("gemini-2") }
85
- return false
86
- })()
87
- const toModelOutput = (opts: { toolCallId: string; input: unknown; output: unknown }) => {
88
- const output = opts.output
89
- if (typeof output === "string") return { type: "text", value: output }
90
- if (typeof output === "object") {
91
- const o = output as { text: string; attachments?: Array<{ mime: string; url: string }> }
92
- const attachments = (o.attachments ?? []).filter((a) => a.url.startsWith("data:") && a.url.includes(","))
93
- return { type: "content", value: [...(o.text ? [{ type: "text", text: o.text }] : []), ...attachments.map((a) => ({ type: "media", mediaType: a.mime, data: iife(() => { const ci = a.url.indexOf(","); return ci === -1 ? a.url : a.url.slice(ci + 1) }) }))] }
94
- }
95
- return { type: "json", value: output as never }
96
- }
97
- for (const msg of input) {
98
- if (msg.parts.length === 0) continue
99
- if (msg.info.role === "user") {
100
- const userMessage: UIMessage = { id: msg.info.id, role: "user", parts: [] }
101
- result.push(userMessage)
102
- for (const part of msg.parts) {
103
- if (part.type === "text" && !part.ignored) userMessage.parts.push({ type: "text", text: part.text })
104
- if (part.type === "file" && part.mime !== "text/plain" && part.mime !== "application/x-directory") {
105
- if (options?.stripMedia && isMedia(part.mime)) userMessage.parts.push({ type: "text", text: `[Attached ${part.mime}: ${part.filename ?? "file"}]` })
106
- else userMessage.parts.push({ type: "file", url: part.url, mediaType: part.mime, filename: part.filename })
107
- }
108
- if (part.type === "compaction") userMessage.parts.push({ type: "text", text: "What did we do so far?" })
109
- if (part.type === "subtask") userMessage.parts.push({ type: "text", text: "The following tool was executed by the user" })
110
- }
111
- }
112
- if (msg.info.role === "assistant") {
113
- const differentModel = `${model.providerID}/${model.id}` !== `${msg.info.providerID}/${msg.info.modelID}`
114
- const media: Array<{ mime: string; url: string }> = []
115
- if (msg.info.error && !(AbortedError.isInstance(msg.info.error) && msg.parts.some((p) => p.type !== "step-start" && p.type !== "reasoning"))) continue
116
- const assistantMessage: UIMessage = { id: msg.info.id, role: "assistant", parts: [] }
117
- for (const part of msg.parts) {
118
- if (part.type === "text" && !part.ignored) assistantMessage.parts.push({ type: "text", text: part.text, ...(differentModel ? {} : { providerMetadata: part.metadata }) })
119
- if (part.type === "step-start") assistantMessage.parts.push({ type: "step-start" })
120
- if (part.type === "tool") {
121
- toolNames.add(part.tool)
122
- if (part.state.status === "completed") {
123
- const outputText = part.state.time.compacted ? "[Old tool result content cleared]" : truncateToolOutput(part.state.output, options?.toolOutputMaxChars)
124
- const attachments = part.state.time.compacted || options?.stripMedia ? [] : (part.state.attachments ?? [])
125
- const mediaAttachments = attachments.filter((a) => isMedia(a.mime))
126
- const nonMediaAttachments = attachments.filter((a) => !isMedia(a.mime))
127
- if (!supportsMediaInToolResults && mediaAttachments.length > 0) media.push(...mediaAttachments)
128
- const finalAttachments = supportsMediaInToolResults ? attachments : nonMediaAttachments
129
- const output = finalAttachments.length > 0 ? { text: outputText, attachments: finalAttachments } : outputText
130
- assistantMessage.parts.push({ type: ("tool-" + part.tool) as `tool-${string}`, state: "output-available", toolCallId: part.callID, input: part.state.input, output, ...(part.metadata?.providerExecuted ? { providerExecuted: true } : {}), ...(differentModel ? {} : { callProviderMetadata: providerMeta(part.metadata) }) })
131
- }
132
- if (part.state.status === "error") {
133
- const output = part.state.metadata?.interrupted === true ? part.state.metadata.output : undefined
134
- if (typeof output === "string") assistantMessage.parts.push({ type: ("tool-" + part.tool) as `tool-${string}`, state: "output-available", toolCallId: part.callID, input: part.state.input, output, ...(part.metadata?.providerExecuted ? { providerExecuted: true } : {}), ...(differentModel ? {} : { callProviderMetadata: providerMeta(part.metadata) }) })
135
- else assistantMessage.parts.push({ type: ("tool-" + part.tool) as `tool-${string}`, state: "output-error", toolCallId: part.callID, input: part.state.input, errorText: part.state.error, ...(part.metadata?.providerExecuted ? { providerExecuted: true } : {}), ...(differentModel ? {} : { callProviderMetadata: providerMeta(part.metadata) }) })
136
- }
137
- if (part.state.status === "pending" || part.state.status === "running") assistantMessage.parts.push({ type: ("tool-" + part.tool) as `tool-${string}`, state: "output-error", toolCallId: part.callID, input: part.state.input, errorText: "[Tool execution was interrupted]", ...(part.metadata?.providerExecuted ? { providerExecuted: true } : {}), ...(differentModel ? {} : { callProviderMetadata: providerMeta(part.metadata) }) })
138
- }
139
- if (part.type === "reasoning") {
140
- if (differentModel) { if (part.text.trim().length > 0) assistantMessage.parts.push({ type: "text", text: part.text }); continue }
141
- assistantMessage.parts.push({ type: "reasoning", text: part.text, providerMetadata: part.metadata })
142
- }
143
- }
144
- if (assistantMessage.parts.length > 0) {
145
- result.push(assistantMessage)
146
- if (media.length > 0) result.push({ id: MessageID.ascending(), role: "user", parts: [{ type: "text" as const, text: SYNTHETIC_ATTACHMENT_PROMPT }, ...media.map((a) => ({ type: "file" as const, url: a.url, mediaType: a.mime }))] })
147
- }
148
- }
149
- }
150
- const tools = Object.fromEntries(Array.from(toolNames).map((n) => [n, { toModelOutput }]))
151
- return yield* Effect.promise(() => convertToModelMessages(result.filter((m) => m.parts.some((p) => p.type !== "step-start")), { tools } as any))
152
- })
153
-
154
- export function toModelMessages(input: WithParts[], model: Provider.Model, options?: { stripMedia?: boolean; toolOutputMaxChars?: number }): Promise<import("ai").ModelMessage[]> {
155
- return Effect.runPromise(toModelMessagesEffect(input, model, options).pipe(Effect.provide(EffectLogger.layer)))
156
- }
1
+ export * from "./message/message-transform"