somora 2026.930.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 (404) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +364 -0
  3. package/bin/node-version.d.mts +3 -0
  4. package/bin/node-version.mjs +45 -0
  5. package/bin/somora.mjs +77 -0
  6. package/config.example.yaml +896 -0
  7. package/docs/agents.md +677 -0
  8. package/docs/api.md +3194 -0
  9. package/docs/browser.md +317 -0
  10. package/docs/builder.md +331 -0
  11. package/docs/cache-strategy.md +373 -0
  12. package/docs/compaction.md +253 -0
  13. package/docs/display.md +154 -0
  14. package/docs/dream-phases.md +891 -0
  15. package/docs/files.md +387 -0
  16. package/docs/imagegen.md +366 -0
  17. package/docs/images/somora-hero.png +0 -0
  18. package/docs/images/somora-mobile-2026-05-23.png +0 -0
  19. package/docs/images/somora-tui-2026-05-23.png +0 -0
  20. package/docs/images/somora-web-2026-05-23.png +0 -0
  21. package/docs/index.md +178 -0
  22. package/docs/lsp.md +93 -0
  23. package/docs/mcp.md +332 -0
  24. package/docs/memory.md +407 -0
  25. package/docs/mobile.md +310 -0
  26. package/docs/models.md +379 -0
  27. package/docs/projects.md +425 -0
  28. package/docs/realtime-voice.md +293 -0
  29. package/docs/resources.md +230 -0
  30. package/docs/sampling.md +128 -0
  31. package/docs/security.md +189 -0
  32. package/docs/sentinel.md +295 -0
  33. package/docs/setup.md +1217 -0
  34. package/docs/skills.md +501 -0
  35. package/docs/team.md +189 -0
  36. package/docs/thinking.md +463 -0
  37. package/docs/tmux.md +399 -0
  38. package/docs/tools.md +117 -0
  39. package/docs/videogen.md +191 -0
  40. package/docs/voice.md +288 -0
  41. package/docs/web.md +893 -0
  42. package/docs/wiki.md +583 -0
  43. package/npm-shrinkwrap.json +5670 -0
  44. package/package.json +116 -0
  45. package/src/attachments/store.ts +196 -0
  46. package/src/browser/change-stream.ts +31 -0
  47. package/src/browser/display.ts +108 -0
  48. package/src/browser/policy.ts +121 -0
  49. package/src/browser/screencast.ts +374 -0
  50. package/src/browser/service.ts +1337 -0
  51. package/src/browser/session.ts +15 -0
  52. package/src/browser/snapshot.ts +40 -0
  53. package/src/cli/auth.ts +117 -0
  54. package/src/cli/codex.ts +41 -0
  55. package/src/cli/lsp.ts +71 -0
  56. package/src/cli/resolvers/clawhub.ts +400 -0
  57. package/src/cli/setup.ts +835 -0
  58. package/src/cli/skill.ts +619 -0
  59. package/src/cli/somora.ts +548 -0
  60. package/src/cli/systemd-unit.ts +72 -0
  61. package/src/cli/team.ts +148 -0
  62. package/src/cli/tui/activity-stream.ts +121 -0
  63. package/src/cli/tui/api.ts +479 -0
  64. package/src/cli/tui/app.tsx +1169 -0
  65. package/src/cli/tui/autocomplete.tsx +55 -0
  66. package/src/cli/tui/commands.ts +913 -0
  67. package/src/cli/tui/dream-glyphs.ts +22 -0
  68. package/src/cli/tui/footer.tsx +15 -0
  69. package/src/cli/tui/format.ts +28 -0
  70. package/src/cli/tui/header.tsx +279 -0
  71. package/src/cli/tui/index.tsx +120 -0
  72. package/src/cli/tui/markdown.tsx +63 -0
  73. package/src/cli/tui/sampling.ts +162 -0
  74. package/src/cli/tui/separator.tsx +13 -0
  75. package/src/cli/tui/state.ts +42 -0
  76. package/src/cli/tui/stream.ts +330 -0
  77. package/src/cli/tui/thinking-text.ts +54 -0
  78. package/src/cli/tui/turn-views.tsx +499 -0
  79. package/src/cli/tui/types.ts +410 -0
  80. package/src/cli/tui/work-queue.ts +161 -0
  81. package/src/cli/update-args.ts +55 -0
  82. package/src/cli/wiki.ts +406 -0
  83. package/src/compaction/index.ts +28 -0
  84. package/src/compaction/midturn.ts +210 -0
  85. package/src/compaction/policy.ts +154 -0
  86. package/src/compaction/summarize.ts +691 -0
  87. package/src/compaction/template.ts +90 -0
  88. package/src/compaction/types.ts +148 -0
  89. package/src/config/loader.ts +276 -0
  90. package/src/config/reload.ts +43 -0
  91. package/src/config/types.ts +2292 -0
  92. package/src/dream/deep-actions.ts +324 -0
  93. package/src/dream/deep-dispatcher.ts +237 -0
  94. package/src/dream/deep-llm.ts +388 -0
  95. package/src/dream/deep-prompts.ts +106 -0
  96. package/src/dream/deep-runner.ts +757 -0
  97. package/src/dream/deep-skip-cache.ts +199 -0
  98. package/src/dream/deep-worker.ts +229 -0
  99. package/src/dream/json-salvage.ts +34 -0
  100. package/src/dream/judge.ts +188 -0
  101. package/src/dream/loop-state.ts +286 -0
  102. package/src/dream/lucid-actions.ts +303 -0
  103. package/src/dream/lucid-batches.ts +94 -0
  104. package/src/dream/lucid-prompt.ts +82 -0
  105. package/src/dream/lucid-runner.ts +744 -0
  106. package/src/dream/lucid-storage.ts +277 -0
  107. package/src/dream/lucid-structure.ts +102 -0
  108. package/src/dream/lucid-types.ts +137 -0
  109. package/src/dream/lucid-worker.ts +224 -0
  110. package/src/dream/rem-dedup.ts +502 -0
  111. package/src/dream/rem-extract.ts +782 -0
  112. package/src/dream/rem-reset-run.ts +67 -0
  113. package/src/dream/rem-runner.ts +696 -0
  114. package/src/dream/rem-worker.ts +527 -0
  115. package/src/dream/review-window.ts +71 -0
  116. package/src/dream/scheduler-state.ts +129 -0
  117. package/src/dream/storage.ts +497 -0
  118. package/src/dream/types.ts +133 -0
  119. package/src/dream/wiki-context.ts +133 -0
  120. package/src/engine/a2a.ts +33 -0
  121. package/src/engine/availability.ts +63 -0
  122. package/src/engine/claude-cli.ts +969 -0
  123. package/src/engine/codex-app-server-client.ts +294 -0
  124. package/src/engine/codex-bin.ts +49 -0
  125. package/src/engine/codex-cli.ts +1014 -0
  126. package/src/engine/codex-dynamic-tools.ts +239 -0
  127. package/src/engine/codex-home.ts +63 -0
  128. package/src/engine/codex-thread-config.ts +74 -0
  129. package/src/engine/context-budget.ts +257 -0
  130. package/src/engine/engine-meta-labels.ts +211 -0
  131. package/src/engine/grok-cli.ts +941 -0
  132. package/src/engine/inline-think.ts +59 -0
  133. package/src/engine/model-availability.ts +105 -0
  134. package/src/engine/openai-compatible.ts +2464 -0
  135. package/src/engine/reasoning-retry.ts +83 -0
  136. package/src/engine/registry.ts +13 -0
  137. package/src/engine/replay.ts +195 -0
  138. package/src/engine/sampling.ts +90 -0
  139. package/src/engine/thinking-params.ts +264 -0
  140. package/src/engine/types.ts +269 -0
  141. package/src/engine/user-tag.ts +24 -0
  142. package/src/imagegen/aspect.ts +128 -0
  143. package/src/imagegen/generate.ts +642 -0
  144. package/src/imagegen/references.ts +75 -0
  145. package/src/imagegen/types.ts +154 -0
  146. package/src/lsp/client.ts +183 -0
  147. package/src/lsp/fake-server.helper.mjs +42 -0
  148. package/src/lsp/format.ts +29 -0
  149. package/src/lsp/index.ts +21 -0
  150. package/src/lsp/manager.ts +238 -0
  151. package/src/lsp/registry.ts +151 -0
  152. package/src/mcp/config.ts +117 -0
  153. package/src/mcp/hub/audit.ts +55 -0
  154. package/src/mcp/hub/bridge.ts +115 -0
  155. package/src/mcp/hub/catalog.ts +69 -0
  156. package/src/mcp/hub/credentials.ts +406 -0
  157. package/src/mcp/hub/env-expand.ts +14 -0
  158. package/src/mcp/hub/manager.ts +770 -0
  159. package/src/mcp/hub/normalize.ts +213 -0
  160. package/src/mcp/server.ts +368 -0
  161. package/src/mcp/tool-schema.ts +20 -0
  162. package/src/media/capabilities.ts +392 -0
  163. package/src/media/records.ts +175 -0
  164. package/src/media/store.ts +217 -0
  165. package/src/media/types.ts +69 -0
  166. package/src/memory/chunking.ts +168 -0
  167. package/src/memory/embeddings.ts +262 -0
  168. package/src/memory/index.ts +15 -0
  169. package/src/memory/inject.ts +197 -0
  170. package/src/memory/manager.ts +996 -0
  171. package/src/memory/registry.ts +176 -0
  172. package/src/memory/rescan.ts +101 -0
  173. package/src/memory/retrieval.ts +586 -0
  174. package/src/memory/shared-index.ts +372 -0
  175. package/src/memory/slug.ts +39 -0
  176. package/src/memory/storage.ts +385 -0
  177. package/src/memory/watcher.ts +134 -0
  178. package/src/multimodal/blocks.ts +101 -0
  179. package/src/multimodal/dimensions.ts +214 -0
  180. package/src/multimodal/load.ts +86 -0
  181. package/src/multimodal/mime.ts +135 -0
  182. package/src/multimodal/pdf-render.ts +80 -0
  183. package/src/multimodal/user-content.ts +266 -0
  184. package/src/persona/files.ts +144 -0
  185. package/src/persona/loader.ts +598 -0
  186. package/src/persona/skill-gating-store.ts +59 -0
  187. package/src/persona/tool-gating-store.ts +113 -0
  188. package/src/projects/focus.ts +186 -0
  189. package/src/projects/prompt-block.ts +106 -0
  190. package/src/projects/scheme.ts +107 -0
  191. package/src/projects/store.ts +144 -0
  192. package/src/projects/types.ts +73 -0
  193. package/src/sentinel/dispatcher.ts +97 -0
  194. package/src/sentinel/schedule.ts +271 -0
  195. package/src/sentinel/scheduler.ts +840 -0
  196. package/src/sentinel/store.ts +259 -0
  197. package/src/sentinel/types.ts +221 -0
  198. package/src/server/activity-stream.ts +160 -0
  199. package/src/server/ask-calls.ts +137 -0
  200. package/src/server/ask-wait-graph.ts +171 -0
  201. package/src/server/async-tasks.ts +199 -0
  202. package/src/server/builder-busy.ts +86 -0
  203. package/src/server/builder-prompt.ts +204 -0
  204. package/src/server/builder-questions.ts +117 -0
  205. package/src/server/builder-session.ts +249 -0
  206. package/src/server/chat-aborts.ts +83 -0
  207. package/src/server/claude-config-dir.ts +71 -0
  208. package/src/server/claude-credential-sync.ts +454 -0
  209. package/src/server/env-file.ts +100 -0
  210. package/src/server/env.ts +115 -0
  211. package/src/server/heal-session.ts +151 -0
  212. package/src/server/history-page.ts +46 -0
  213. package/src/server/index.ts +7244 -0
  214. package/src/server/lockfile.ts +89 -0
  215. package/src/server/logger.ts +67 -0
  216. package/src/server/logs.ts +187 -0
  217. package/src/server/loopback-fetch.ts +130 -0
  218. package/src/server/openai-client.ts +89 -0
  219. package/src/server/prompt-assembly.ts +334 -0
  220. package/src/server/restart-reconcile.ts +139 -0
  221. package/src/server/run-turn-fallback.ts +275 -0
  222. package/src/server/run-turn-types.ts +91 -0
  223. package/src/server/run-turn.ts +1474 -0
  224. package/src/server/sanitize-assistant-text.ts +112 -0
  225. package/src/server/session-export.ts +220 -0
  226. package/src/server/session-queue.ts +376 -0
  227. package/src/server/session-workdir.ts +49 -0
  228. package/src/server/sse-h2-safe.ts +61 -0
  229. package/src/server/sse-liveness.ts +162 -0
  230. package/src/server/sse-serializer.ts +161 -0
  231. package/src/server/start-turn.ts +249 -0
  232. package/src/server/steer-inbox.ts +107 -0
  233. package/src/server/tls-keeper.ts +153 -0
  234. package/src/server/tool-format.ts +167 -0
  235. package/src/server/turn-framing.ts +52 -0
  236. package/src/server/turn-origin-kind.ts +74 -0
  237. package/src/server/turn-origin.ts +40 -0
  238. package/src/server/work-ledger.ts +975 -0
  239. package/src/server/workspace.ts +114 -0
  240. package/src/setup/config-edit.ts +201 -0
  241. package/src/setup/presets.ts +71 -0
  242. package/src/setup/prompt.ts +163 -0
  243. package/src/setup/tailscale.ts +44 -0
  244. package/src/skills/bin-checks.ts +227 -0
  245. package/src/skills/bootstrap.ts +347 -0
  246. package/src/skills/env-scope.ts +175 -0
  247. package/src/skills/gating.ts +71 -0
  248. package/src/skills/lint.ts +202 -0
  249. package/src/skills/load.ts +368 -0
  250. package/src/skills/path-helpers.ts +102 -0
  251. package/src/skills/registry.ts +178 -0
  252. package/src/ssh/exec.ts +142 -0
  253. package/src/ssh/index.ts +12 -0
  254. package/src/ssh/known-hosts.ts +109 -0
  255. package/src/ssh/pool.ts +307 -0
  256. package/src/storage/sessions.ts +602 -0
  257. package/src/team/render.ts +149 -0
  258. package/src/team/resolve.ts +122 -0
  259. package/src/team/store.ts +124 -0
  260. package/src/team/types.ts +111 -0
  261. package/src/team/write.ts +95 -0
  262. package/src/testing/isolated-home.mts +46 -0
  263. package/src/tmux/attention-watcher.ts +272 -0
  264. package/src/tmux/attention.ts +336 -0
  265. package/src/tmux/list.ts +91 -0
  266. package/src/tmux/origin-store.ts +102 -0
  267. package/src/tmux/tui-markers.ts +267 -0
  268. package/src/tools/agents/ask-cancel.ts +94 -0
  269. package/src/tools/agents/ask-result.ts +235 -0
  270. package/src/tools/agents/ask.ts +704 -0
  271. package/src/tools/agents/builder-dispatch.ts +217 -0
  272. package/src/tools/agents/images.ts +104 -0
  273. package/src/tools/agents/index.ts +42 -0
  274. package/src/tools/agents/long-task-timeouts.ts +39 -0
  275. package/src/tools/agents/session-list.ts +136 -0
  276. package/src/tools/agents/session-model.ts +106 -0
  277. package/src/tools/agents/spawn.ts +845 -0
  278. package/src/tools/agents/status.ts +589 -0
  279. package/src/tools/browser/index.ts +6 -0
  280. package/src/tools/browser/ops.ts +145 -0
  281. package/src/tools/browser/tools.ts +184 -0
  282. package/src/tools/builder/short-descriptions.ts +80 -0
  283. package/src/tools/builder/tools.ts +222 -0
  284. package/src/tools/docs/index.ts +1 -0
  285. package/src/tools/docs/tools.ts +228 -0
  286. package/src/tools/dream/index.ts +11 -0
  287. package/src/tools/dream/tools.ts +1002 -0
  288. package/src/tools/exec/allowlist.ts +233 -0
  289. package/src/tools/exec/background-detach.helper.mts +27 -0
  290. package/src/tools/exec/blacklist.ts +336 -0
  291. package/src/tools/exec/concurrency.ts +150 -0
  292. package/src/tools/exec/fit-output.ts +82 -0
  293. package/src/tools/exec/index.ts +7 -0
  294. package/src/tools/exec/internal-env.ts +89 -0
  295. package/src/tools/exec/job-store.ts +403 -0
  296. package/src/tools/exec/local.ts +649 -0
  297. package/src/tools/exec/remote.ts +399 -0
  298. package/src/tools/exec/tools.ts +934 -0
  299. package/src/tools/file/analyze.ts +378 -0
  300. package/src/tools/file/index.ts +2 -0
  301. package/src/tools/file/local.ts +707 -0
  302. package/src/tools/file/lsp-hook.ts +72 -0
  303. package/src/tools/file/persona-guard.ts +61 -0
  304. package/src/tools/file/policy.ts +292 -0
  305. package/src/tools/file/read-format.ts +129 -0
  306. package/src/tools/file/remote.ts +680 -0
  307. package/src/tools/file/replace.ts +507 -0
  308. package/src/tools/file/search-window.ts +224 -0
  309. package/src/tools/file/tools.ts +658 -0
  310. package/src/tools/file/write-scope.ts +182 -0
  311. package/src/tools/gating.ts +106 -0
  312. package/src/tools/image/budget.ts +82 -0
  313. package/src/tools/image/index.ts +7 -0
  314. package/src/tools/image/tools.ts +601 -0
  315. package/src/tools/index.ts +99 -0
  316. package/src/tools/memory/index.ts +12 -0
  317. package/src/tools/memory/tools.ts +399 -0
  318. package/src/tools/projects/index.ts +1 -0
  319. package/src/tools/projects/tools.ts +643 -0
  320. package/src/tools/registry.ts +427 -0
  321. package/src/tools/resources/index.ts +8 -0
  322. package/src/tools/resources/tools.ts +176 -0
  323. package/src/tools/resources/visibility.ts +60 -0
  324. package/src/tools/sentinel/index.ts +1 -0
  325. package/src/tools/sentinel/tools.ts +592 -0
  326. package/src/tools/skill/index.ts +4 -0
  327. package/src/tools/skill/tools.ts +285 -0
  328. package/src/tools/time/index.ts +5 -0
  329. package/src/tools/time/tools.ts +123 -0
  330. package/src/tools/tmux/index.ts +1 -0
  331. package/src/tools/tmux/local.ts +277 -0
  332. package/src/tools/tmux/remote.ts +168 -0
  333. package/src/tools/tmux/tools.ts +1064 -0
  334. package/src/tools/tool-output.ts +97 -0
  335. package/src/tools/types.ts +227 -0
  336. package/src/tools/video/index.ts +1 -0
  337. package/src/tools/video/tools.ts +425 -0
  338. package/src/tools/web/fetch.ts +337 -0
  339. package/src/tools/web/index.ts +4 -0
  340. package/src/tools/web/tools.ts +186 -0
  341. package/src/tools/wiki/index.ts +1 -0
  342. package/src/tools/wiki/tools.ts +445 -0
  343. package/src/tts/cache-gc.ts +128 -0
  344. package/src/tts/prepare-for-tts.ts +114 -0
  345. package/src/tts/service.ts +332 -0
  346. package/src/types/events.ts +695 -0
  347. package/src/types/turn-origin.ts +53 -0
  348. package/src/version.ts +21 -0
  349. package/src/videogen/dialects.ts +222 -0
  350. package/src/videogen/generate.ts +484 -0
  351. package/src/videogen/jobs.ts +178 -0
  352. package/src/videogen/runner.ts +125 -0
  353. package/src/videogen/wake.ts +119 -0
  354. package/src/voice/realtime/call.ts +948 -0
  355. package/src/voice/realtime/consult.ts +293 -0
  356. package/src/voice/realtime/fake-provider.ts +134 -0
  357. package/src/voice/realtime/manager.ts +384 -0
  358. package/src/voice/realtime/openai-provider.ts +471 -0
  359. package/src/voice/realtime/persona.ts +227 -0
  360. package/src/voice/realtime/session-match.ts +116 -0
  361. package/src/voice/realtime/types.ts +182 -0
  362. package/src/wiki/conflict.ts +113 -0
  363. package/src/wiki/explorer.ts +578 -0
  364. package/src/wiki/index-builder.ts +172 -0
  365. package/src/wiki/language.ts +134 -0
  366. package/src/wiki/log-builder.ts +150 -0
  367. package/src/wiki/map.ts +258 -0
  368. package/src/wiki/migration/analyze.ts +304 -0
  369. package/src/wiki/migration/execute.ts +689 -0
  370. package/src/wiki/migration/refine.ts +402 -0
  371. package/src/wiki/migration/store.ts +100 -0
  372. package/src/wiki/move-page.ts +57 -0
  373. package/src/wiki/structure-file.ts +192 -0
  374. package/src/wiki/taxonomy.ts +140 -0
  375. package/src/wiki/templates.ts +163 -0
  376. package/src/wiki/types.ts +133 -0
  377. package/templates/skills/README.md +24 -0
  378. package/templates/skills/_templates/api-wrapper/SKILL.md +26 -0
  379. package/templates/skills/_templates/cli-wrapper/BOOTSTRAP.md +32 -0
  380. package/templates/skills/_templates/cli-wrapper/SKILL.md +24 -0
  381. package/templates/skills/_templates/default/SKILL.md +25 -0
  382. package/templates/skills/builder-handover/SKILL.md +96 -0
  383. package/templates/skills/builder-handover/assets/ORDER.md +12 -0
  384. package/templates/skills/skill-author/SKILL.md +110 -0
  385. package/tsconfig.json +22 -0
  386. package/web/dist/assets/index-BaVv6pB2.js +631 -0
  387. package/web/dist/assets/index-BaVv6pB2.js.map +1 -0
  388. package/web/dist/assets/index-V3FV3Z25.css +32 -0
  389. package/web/dist/favicon.svg +8 -0
  390. package/web/dist/index.html +20 -0
  391. package/web/package.json +36 -0
  392. package/web/tsconfig.json +25 -0
  393. package/web-mobile/dist/apple-touch-icon.png +0 -0
  394. package/web-mobile/dist/assets/index-BqKt7IMx.css +1 -0
  395. package/web-mobile/dist/assets/index-X_vRr6cd.js +88 -0
  396. package/web-mobile/dist/assets/index-X_vRr6cd.js.map +1 -0
  397. package/web-mobile/dist/favicon.svg +8 -0
  398. package/web-mobile/dist/icon-192.png +0 -0
  399. package/web-mobile/dist/icon-512.png +0 -0
  400. package/web-mobile/dist/index.html +27 -0
  401. package/web-mobile/dist/manifest.webmanifest +32 -0
  402. package/web-mobile/dist/service-worker.js +90 -0
  403. package/web-mobile/package.json +28 -0
  404. package/web-mobile/tsconfig.json +25 -0
@@ -0,0 +1,695 @@
1
+ // Internal canonical event format. Persisted as JSONL (later in step 1b+).
2
+ // Engine-agnostic — every adapter (anthropic, openai, ...) maps SDK events to this shape.
3
+ import type { TurnOrigin } from './turn-origin.ts';
4
+
5
+ export type NormalizedEvent =
6
+ | {
7
+ kind: 'user_message';
8
+ ts: number;
9
+ engine: string;
10
+ text: string;
11
+ /**
12
+ * Agent-to-agent (A2A) attribution. When set, this user_message
13
+ * was written into THIS session by another somora agent (via
14
+ * `agent_ask` or as a sub-task seed) — NOT by the human user.
15
+ *
16
+ * Semantics:
17
+ * - undefined → human user (default, unchanged behavior)
18
+ * - '<agent>' → another agent wrote this turn into the current
19
+ * agent's session as part of an A2A flow.
20
+ *
21
+ * Storage: persists in JSONL alongside `text`; replays into
22
+ * cross-engine context with a "[Message from agent <name>]"
23
+ * header so other engines learn provenance during catch-up.
24
+ *
25
+ * TUI: rendered with the sender's icon instead of the user icon.
26
+ */
27
+ from_agent?: string;
28
+ /**
29
+ * A2A: the session the asking agent wrote from (its session id,
30
+ * or 'main'). Set together with from_agent by agent_ask. Lets
31
+ * the receiver address a follow-up to the right session and
32
+ * lets `agent_ask` without an explicit `session` route a reply
33
+ * back there (see src/server/turn-origin.ts).
34
+ */
35
+ from_session?: string;
36
+ /**
37
+ * Marks a user_message that was synthesized by an internal
38
+ * subsystem rather than typed by a human or sent by a peer
39
+ * agent: a sentinel fire, a tmux or browser wake, a voice
40
+ * consult, or a wake-up about a finished agent_ask (`a2a`),
41
+ * sub-agent (`subagent`) or background job (`job`). Clients
42
+ * render the inbound as a centered system divider instead of a
43
+ * regular user-bubble; `origin` below says the same with detail.
44
+ *
45
+ * Note: from_agent and from_system are mutually exclusive — an
46
+ * inbound is either A2A (from another agent) OR system
47
+ * (synthesized by an internal subsystem) OR neither (human
48
+ * user). The renderer picks the bubble class in that order.
49
+ */
50
+ /**
51
+ * `job` means a background job the agent started has finished and
52
+ * brought it back — video renders today. Deliberately not named
53
+ * after the medium: the distinguishing fact is "something you
54
+ * kicked off is done", and video is only the first of those.
55
+ */
56
+ from_system?: 'sentinel' | 'tmux' | 'subagent' | 'job' | 'browser' | 'voice' | 'a2a';
57
+ /**
58
+ * Where the turn came from, as one value (src/types/turn-origin.ts).
59
+ * Additive since 2026-09-13: from_agent / from_system above stay
60
+ * the fields every older reader uses; a client that knows this
61
+ * one renders glyph, label and subtitle from it instead of
62
+ * parsing the message text. Absent on turns recorded before.
63
+ */
64
+ origin?: TurnOrigin;
65
+ /**
66
+ * Steering (since 2026-09-23): this message was sent while a turn
67
+ * was running and handed to the model inside that turn, before
68
+ * its next step — it did not start a turn of its own. `steer_id`
69
+ * is the id the client got back from `POST /chat/send` with
70
+ * `steer: true`, so it can pair the record with its bubble.
71
+ */
72
+ steer?: true;
73
+ steer_id?: string;
74
+ /**
75
+ * Correlation UUID for an `agent_ask` round-trip. Persisted on
76
+ * BOTH sides: on the caller's side as a tool_call → tool_result
77
+ * pair (the call_id is in the tool_call payload), and on the
78
+ * target's side as user_message.agent_ask_call_id alongside
79
+ * from_agent.
80
+ *
81
+ * Powers `agent_ask_result(call_id)`: the live registry
82
+ * (src/server/ask-calls.ts) answers first; after a restart the
83
+ * route re-reads this field from the target's JSONL.
84
+ */
85
+ agent_ask_call_id?: string;
86
+ /**
87
+ * Memory-recall block (`<memory-context>...</memory-context>`)
88
+ * that was injected at the time THIS turn was sent. Persisted
89
+ * here so history reconstruction at later turns recreates the
90
+ * exact byte sequence we originally sent — required for
91
+ * prefix-cache to match across turns on stateless backends.
92
+ *
93
+ * Without this field, openai-compatible engines have no way to
94
+ * rebuild past user_messages identically (every turn re-queries
95
+ * memory and gets potentially different hits), so any cache
96
+ * breakpoint sitting between the system block and the latest
97
+ * user message gets invalidated turn-after-turn.
98
+ *
99
+ * Engines that don't reconstruct full history (claude-cli /
100
+ * codex-cli with resumed sessions) ignore this field — they
101
+ * inline the memory block into the outgoing user_message text
102
+ * directly, and the underlying provider remembers the prior
103
+ * turns it already saw.
104
+ *
105
+ * TUI rendering should display only `text`, not `ephemeral` —
106
+ * the recall block is internal scaffolding, not user-typed.
107
+ */
108
+ ephemeral?: string;
109
+ /**
110
+ * User-attached files (Phase Y.B, web upload). Refs only — bytes
111
+ * live at `~/.somora/attachments/<hash>.<ext>` content-
112
+ * addressed. JSONL persists name/mime/size for display +
113
+ * sanity-checks at replay time; the path is derived from the
114
+ * hash on demand.
115
+ */
116
+ attachments?: Array<{
117
+ hash: string;
118
+ name: string;
119
+ mime: string;
120
+ size: number;
121
+ }>;
122
+ /**
123
+ * Input-channel metadata. Populated when the user message
124
+ * arrived through a non-text channel (currently: STT
125
+ * transcription from the mic button on web/mobile, or the
126
+ * `/voice/turn` audio-in endpoint). Drives the auto-TTS
127
+ * policy in run-turn: only voice-input turns are eligible
128
+ * for assistant_audio generation. Absent ⇒ treat as text
129
+ * (backwards-compatible with pre-voice JSONL).
130
+ */
131
+ input?: {
132
+ modality?: 'text' | 'voice';
133
+ /** True if the text was produced by an STT pass (not typed). */
134
+ transcribed?: boolean;
135
+ /** Free-form tag for the STT path used, e.g. provider name. */
136
+ sttProvider?: string;
137
+ /**
138
+ * WHICH spoken path this came from. Two different features
139
+ * write `modality: 'voice'` and they must not be read as one
140
+ * (Rene, 2026-09-12): `stt` is the microphone button — one
141
+ * recording becomes one message you can still edit before
142
+ * sending. `realtime` is a live call, where the sentence was
143
+ * spoken into a standing connection and is recorded after the
144
+ * fact.
145
+ */
146
+ source?: 'stt' | 'realtime';
147
+ };
148
+ /**
149
+ * Per-turn client request: did the client (web / mobile / voice
150
+ * endpoint) ask somora to also generate spoken audio for the
151
+ * assistant reply? The auto-TTS hook in run-turn only fires
152
+ * when this is true AND `input.modality === 'voice'`. Absent ⇒
153
+ * no audio generated (default-safe).
154
+ */
155
+ autoPlayRequested?: boolean;
156
+ }
157
+ | { kind: 'assistant_delta'; ts: number; engine: string; text: string }
158
+ | { kind: 'assistant_message'; ts: number; engine: string; text: string }
159
+ /**
160
+ * The model's reasoning text, separate from the reply. `thinking_delta`
161
+ * is CUMULATIVE for the turn (like assistant_delta) and never persisted;
162
+ * `thinking_message` is the final text, persisted to JSONL before the
163
+ * turn's assistant_message. Engines that surface no thinking emit
164
+ * neither. Never replayed to a model and never fed to REM.
165
+ */
166
+ | { kind: 'thinking_delta'; ts: number; engine: string; text: string }
167
+ | {
168
+ kind: 'thinking_message';
169
+ ts: number;
170
+ engine: string;
171
+ text: string;
172
+ /** Set by the server when the text was cut at thinkingContent.maxChars. */
173
+ truncated?: true;
174
+ }
175
+ | {
176
+ /**
177
+ * Audio artifact attached to an assistant_message. Emitted by
178
+ * the auto-TTS hook in run-turn after the assistant text
179
+ * finalizes and the speech-sanitizer accepts it, or by the
180
+ * `/voice/turn` endpoint as part of its synchronous response.
181
+ *
182
+ * Append-only — never mutates the original assistant_message
183
+ * event. Clients pair by `turnId`: when an assistant_audio
184
+ * with matching turnId arrives, render a Play-button on the
185
+ * corresponding assistant bubble.
186
+ */
187
+ kind: 'assistant_audio';
188
+ ts: number;
189
+ engine: string;
190
+ turnId: string;
191
+ audio: {
192
+ /** Absolute URL path served by GET /tts/cache/:hash.:ext. */
193
+ url: string;
194
+ /** Concrete MIME (`audio/wav`, `audio/opus`, `audio/mp4`). */
195
+ mime: string;
196
+ /** Approximate duration of the generated audio in ms. */
197
+ durationMs?: number;
198
+ /** sha256(text+voice+model+format) — debug/forensic only. */
199
+ cacheKey: string;
200
+ };
201
+ }
202
+ | {
203
+ /**
204
+ * Media produced during an assistant turn. Emitted after the turn
205
+ * finalizes, once, listing everything the turn's generation tools
206
+ * made while it ran.
207
+ *
208
+ * Deliberately NOT called `assistant_images`: this string is
209
+ * written into session JSONL and stays there for the life of the
210
+ * session. A video endpoint would otherwise need a second,
211
+ * near-identical event kind, and every reader would have to
212
+ * understand both forever. Instead each entry carries its own
213
+ * `type`, and a reader that meets a type it doesn't know skips
214
+ * that entry.
215
+ *
216
+ * Append-only and paired by `turnId`, exactly like
217
+ * assistant_audio — the original assistant_message is never
218
+ * mutated. Clients render the media on the matching bubble.
219
+ *
220
+ * Why the server volunteers these instead of the agent sending
221
+ * them: a person who asked for a picture should get the picture.
222
+ * Leaving it to the agent to remember means the failure mode is
223
+ * "Done!" with nothing to look at.
224
+ *
225
+ * Refs only — bytes stay in the images directory and are served
226
+ * by GET /images/:id/file. JSONL keeps enough to render a
227
+ * placeholder if the file later disappears. Note that `url` is
228
+ * itself part of the persisted payload: that route has to keep
229
+ * resolving even if a later generalisation adds a /media/ path.
230
+ */
231
+ kind: 'assistant_media';
232
+ ts: number;
233
+ engine: string;
234
+ turnId: string;
235
+ media: Array<{
236
+ /** What this entry is. Adding `video` here — rather than a
237
+ * second event kind — is exactly what this field was for. */
238
+ type: 'image' | 'video';
239
+ id: string;
240
+ prompt: string;
241
+ mime: string;
242
+ filename: string;
243
+ /**
244
+ * Absolute URL path: `/media/<id>/file`.
245
+ *
246
+ * Rows written on 2026-08-27 carry `/images/<id>/file`. That
247
+ * route stays mounted for good — the string is in session files
248
+ * and cannot be rewritten.
249
+ */
250
+ url: string;
251
+ /** Video: a still, where the provider serves one. */
252
+ thumbUrl?: string;
253
+ /** Video: playing time in seconds. */
254
+ durationSec?: number;
255
+ }>;
256
+ }
257
+ | { kind: 'tool_call'; ts: number; engine: string; callId: string; tool: string; input: unknown }
258
+ | { kind: 'tool_result'; ts: number; engine: string; callId: string; output: unknown; error?: string }
259
+ // Engine-internal metadata that the agent emits as a side-channel to
260
+ // the conversation. The canonical case is codex-cli's `todo_list`
261
+ // item — codex tracks an internal plan/checklist that the model
262
+ // updates mid-turn. We don't drive it ourselves; we observe + persist
263
+ // it so REM-dream/memory can read history later, and so the user can
264
+ // optionally see it when their `show.tools` toggle is on. Opaque
265
+ // payload — different engines / future codex versions can ship
266
+ // arbitrary itemType strings without parser churn.
267
+ | {
268
+ kind: 'engine_meta';
269
+ ts: number;
270
+ engine: string;
271
+ /** Raw item-type label as the engine produced it (e.g. 'todo_list',
272
+ * 'hookPrompt'). Clients map known ones to friendly labels (see
273
+ * src/engine/codex-cli.ts CODEX_META_LABELS) and fall back to the
274
+ * raw string for unknowns. */
275
+ itemType: string;
276
+ /** The original event payload, untouched. Schema depends on
277
+ * engine + itemType — treat as opaque. */
278
+ payload: unknown;
279
+ }
280
+ | { kind: 'turn_start'; ts: number; engine: string; turnId: string }
281
+ /**
282
+ * Engine-internal: steer messages (src/server/steer-inbox.ts) were
283
+ * handed to the model at a step boundary, in this order. run-turn
284
+ * turns each into a persisted `user_message` with `steer: true`; the
285
+ * event itself is never written to the session file.
286
+ */
287
+ | {
288
+ kind: 'steer_applied';
289
+ ts: number;
290
+ engine: string;
291
+ messages: Array<{
292
+ id: string;
293
+ text: string;
294
+ ts: number;
295
+ origin: TurnOrigin;
296
+ from_agent?: string;
297
+ from_session?: string;
298
+ }>;
299
+ }
300
+ | {
301
+ kind: 'turn_end';
302
+ ts: number;
303
+ engine: string;
304
+ turnId: string;
305
+ /** `<provider>/<modelId>` that actually produced this turn — the
306
+ * fallback's when one took over. Stamped by run-turn when the
307
+ * event is persisted (since 2026-09-21); absent on older turns.
308
+ * Without it a session file could not answer "which model wrote
309
+ * this?" once the session's model had been switched. */
310
+ model?: string;
311
+ usage?: {
312
+ tokens_in: number;
313
+ tokens_out: number;
314
+ /** Tokens served from the provider's prefix-cache (subset of tokens_in). Optional — not all engines surface it. */
315
+ tokens_in_cached?: number;
316
+ /** Reasoning/thinking tokens (subset of tokens_out). Optional — only reasoning-capable models surface it. */
317
+ tokens_out_reasoning?: number;
318
+ /** True when tokens_out_reasoning was estimated from streamed reasoning text (backend reported none). */
319
+ tokens_out_reasoning_estimated?: boolean;
320
+ /**
321
+ * Prompt size of the LAST request of this turn — how full the
322
+ * context actually was, not how much was spent getting there.
323
+ *
324
+ * `tokens_in` is a sum across every request a turn makes, which
325
+ * for a tool-using turn is a multiple of the window and cannot
326
+ * be compared against it. Displaying that sum as occupancy is
327
+ * what let a turn read as 58k while the backend was refusing
328
+ * 507k (2026-09-10 report). Engines that can report it do.
329
+ */
330
+ context_tokens?: number;
331
+ /**
332
+ * The window the ENGINE says this model has, when it says so.
333
+ *
334
+ * For a CLI engine the configured `contextWindow` is somora's
335
+ * own guess at a session cap it does not control: codex reports
336
+ * `modelContextWindow` per thread (258,400 for gpt-6-astra on
337
+ * 2026-09-11, against 272,000 configured by hand), and that
338
+ * number is the one the CLI compacts against. Shown instead of
339
+ * the configured value when present.
340
+ */
341
+ context_window?: number;
342
+ };
343
+ /** Tool-call rounds the engine ran this turn (engines that count). */
344
+ rounds?: number;
345
+ /** The engine had to force a no-tools finish (round cap, tool
346
+ * budget, scaffold leak) and the model then produced a real
347
+ * answer — a partial result, not a clean one. */
348
+ forced_final?: string;
349
+ /** The final text is a harness marker, not a model answer:
350
+ * the model looped, leaked scaffold, or never answered. Runtime
351
+ * signal — never inferred from model text by consumers. */
352
+ degraded?: { reason: string };
353
+ }
354
+ | {
355
+ kind: 'error';
356
+ ts: number;
357
+ engine: string;
358
+ message: string;
359
+ /**
360
+ * The PROVIDER refused or could not serve this request: quota
361
+ * exhausted, auth rejected, host unreachable, backend 5xx. Set by
362
+ * the engine adapter, which is the only place that knows how its
363
+ * provider dresses a failure — never inferred from model text.
364
+ *
365
+ * Two consumers depend on it. The fallback chain may switch models
366
+ * even when text already arrived, because a quota notice that the
367
+ * provider streamed as an assistant message is not an answer
368
+ * (2026-09-09 report: Claude's monthly-limit text set the
369
+ * first-output guard and the configured backups never ran). And
370
+ * the turn result counts as failed rather than completed.
371
+ */
372
+ providerError?: boolean;
373
+ }
374
+ // Server-side marker for project focus changes within a session. Fired
375
+ // whenever the user pins a project via slash-command OR an agent
376
+ // autonomously calls project_focus via the Tool surface. Persists in
377
+ // JSONL purely for forensics: lets you reconstruct "from which turn
378
+ // onwards did this session see project context X?" months later
379
+ // without needing to replay session.meta history. The `engine` field
380
+ // is the sentinel `'somora'` here — these aren't engine-emitted.
381
+ | {
382
+ kind: 'project_switched';
383
+ ts: number;
384
+ engine: string;
385
+ from: string | null;
386
+ to: string | null;
387
+ via: 'tool' | 'slash_command';
388
+ }
389
+ // Server-side marker: the persona's primary model failed before
390
+ // producing any content and run-turn-fallback re-ran the turn on the
391
+ // configured `fallback:` model. Persisted right before the fallback
392
+ // engine's events so history can mark the turn that follows; clients
393
+ // show a chip on that assistant bubble + a one-time notice. `engine`
394
+ // is the sentinel 'somora'. Refs are `provider/modelId`.
395
+ | {
396
+ kind: 'model_fallback';
397
+ ts: number;
398
+ engine: string;
399
+ requested: string;
400
+ actual: string;
401
+ /** Primary's failure message, trimmed — what the user sees on hover. */
402
+ reason: string;
403
+ /** Every model that died before producing anything on this turn,
404
+ * in order (the primary first). Present since fallback chains
405
+ * (2026-09-08); one entry when a single `fallback:` took over. */
406
+ hops?: Array<{ model: string; reason: string }>;
407
+ };
408
+
409
+ export interface ModelFallbackInfo {
410
+ requested: string;
411
+ actual: string;
412
+ reason: string;
413
+ /** Failed attempts in order, primary first. See NormalizedEvent. */
414
+ hops?: Array<{ model: string; reason: string }>;
415
+ }
416
+
417
+ // Wire format over SSE — orbit-compatible. Deltas are cumulative.
418
+ export type SseEvent =
419
+ | { event: 'chat'; data: { state: 'delta' | 'final'; text: string } }
420
+ /** Reasoning text; deltas cumulative like `chat`. `final` precedes the chat final of the same turn. */
421
+ | { event: 'thinking'; data: { state: 'delta' | 'final'; text: string; truncated?: true } }
422
+ | {
423
+ event: 'agent';
424
+ data: {
425
+ phase: 'start' | 'end';
426
+ usage?: {
427
+ tokens_in: number;
428
+ tokens_out: number;
429
+ tokens_in_cached?: number;
430
+ tokens_out_reasoning?: number;
431
+ tokens_out_reasoning_estimated?: boolean;
432
+ /** Prompt size of the turn's last request — occupancy, not spend. */
433
+ context_tokens?: number;
434
+ };
435
+ contextWindow?: number;
436
+ /** The model that ACTUALLY answered (the fallback when one ran). */
437
+ provider?: string;
438
+ model?: string;
439
+ /**
440
+ * Effective thinking depth for this turn. Surfaces what the
441
+ * engine actually applied so clients can show it in the header.
442
+ * 'dormant' = setting present but model lacks 'reasoning' capability.
443
+ */
444
+ thinking?: { level: 'off' | 'low' | 'medium' | 'high'; active: boolean };
445
+ /** Set on phase:'end' when the turn was answered by the fallback model. */
446
+ fallback?: ModelFallbackInfo;
447
+ };
448
+ }
449
+ | { event: 'model_fallback'; data: ModelFallbackInfo }
450
+ | {
451
+ // Per-turn auto-inject summary — what the runtime pulled from memory
452
+ // before the engine ran. Lets the CLI / orbit show users which notes
453
+ // were surfaced without them having to grep server logs.
454
+ event: 'memory';
455
+ data: {
456
+ count: number;
457
+ topScore?: number;
458
+ // `<source>/<slug>` references in score order, top first.
459
+ refs: string[];
460
+ // Full inject block text — exactly what was concatenated into
461
+ // the engine's systemPrompt/ephemeralContext for this turn.
462
+ // Always present; clients render only when /verbose memory is on.
463
+ fullText: string;
464
+ };
465
+ }
466
+ | {
467
+ // Tool lifecycle event. Server pre-formats the renderable bits:
468
+ // call → tool name (stripped of mcp__ prefix) + args summary
469
+ // result → tool name + result summary (omitted entirely if trivial,
470
+ // so clients never see "boring" rows like {ok:true})
471
+ // error → tool name + error string
472
+ // Clients render summary/error directly without inspecting raw payloads.
473
+ event: 'tool';
474
+ data:
475
+ | { phase: 'call'; tool: string; summary: string; details: string }
476
+ | { phase: 'result'; tool: string; summary: string; details: string }
477
+ | { phase: 'error'; tool: string; error: string; details?: string };
478
+ }
479
+ | { event: 'status'; data: { msg: string } }
480
+ | {
481
+ // A2A user-message broadcast. Fired ONLY when an `agent_ask` (or
482
+ // similar A2A tool) writes a user_message with `from_agent` set
483
+ // into a session. Used by the TUI of a human watching that
484
+ // session live so they see the inbound A2A turn appear in real
485
+ // time, rendered with the sender's icon instead of their own.
486
+ //
487
+ // Now ALSO fired for self-typed turns so multi-client setups
488
+ // (TUI tail + web window open at once) see each other's
489
+ // inputs live. Senders dedupe their own optimistic copy by
490
+ // recent-text — TUI does this implicitly via the local echo,
491
+ // web's ChatProvider tracks pending texts in a ref.
492
+ event: 'user_message';
493
+ data: {
494
+ text: string;
495
+ ts?: number;
496
+ /** Server-generated turn id. Echoed back so clients can match
497
+ * this event to an optimistic bubble created from POST
498
+ * /chat/send (whose response carries the same turnId), and to
499
+ * clear any pending `turn_queued` indicator on that bubble. */
500
+ turnId?: string;
501
+ /** Set only when the message came from another agent
502
+ * (A2A). Self-typed user turns omit it. */
503
+ from_agent?: string;
504
+ /** Set only when the inbound was synthesized by an internal
505
+ * subsystem (today: 'sentinel'). Clients render the message
506
+ * as a centered system divider. */
507
+ from_system?: 'sentinel' | 'tmux' | 'subagent' | 'job' | 'browser' | 'voice' | 'a2a';
508
+ /** Same value as on the stored event — see NormalizedEvent. */
509
+ origin?: TurnOrigin;
510
+ agent_ask_call_id?: string;
511
+ /** Steering: this message was handed to the running turn (the
512
+ * `turnId` here) before its next step; `steer_id` pairs it with
513
+ * the `steer_queued` event / the POST /chat/send response. */
514
+ steer?: true;
515
+ steer_id?: string;
516
+ /** How the turn was said, when it was not typed. Mirrors the
517
+ * `input` field on the stored event so the live bubble and the
518
+ * one rebuilt from history render the same way — dictation and
519
+ * a standing call look different, and both differ from text. */
520
+ input?: { modality?: 'text' | 'voice'; source?: 'stt' | 'realtime' };
521
+ };
522
+ }
523
+ | {
524
+ // User-turn was enqueued behind a still-running turn on the same
525
+ // (agent, session). Fired by POST /chat/send right after pushing
526
+ // the waiter into the session lock's queue. Clients tag their
527
+ // optimistic user-bubble (matched by turnId from the HTTP
528
+ // response) with a "queued" indicator until the matching
529
+ // `user_message` event arrives — at which point the lock has
530
+ // been acquired and the turn is actually running.
531
+ //
532
+ // `ahead` = number of turns this one must wait for, INCLUDING
533
+ // the currently-running one (so ahead=1 means "next in line").
534
+ // Static snapshot at enqueue time: not updated as the queue
535
+ // drains. Clients show "queued" for ahead=1, "queued · N ahead"
536
+ // for ahead>1.
537
+ event: 'turn_queued';
538
+ data: {
539
+ turnId: string;
540
+ ahead: number;
541
+ /** Phase 2: the ledger id and origin kind of the waiter. */
542
+ workId?: string;
543
+ kind?: string;
544
+ };
545
+ }
546
+ /**
547
+ * A message was accepted for steering into the running turn `turnId`
548
+ * (POST /chat/send with `steer: true`). It is not in the session file
549
+ * yet: the matching `user_message` with the same `steer_id` follows
550
+ * when the engine hands it to the model. Other windows on the session
551
+ * render a pending bubble from this.
552
+ */
553
+ | {
554
+ event: 'steer_queued';
555
+ data: { steerId: string; text: string; ts: number; turnId: string; origin: TurnOrigin };
556
+ }
557
+ /** Builder sessions (docs/builder.md): the task list changed. */
558
+ | { event: 'todo_updated'; data: { todos: Array<{ content: string; status: string; priority?: string }>; by?: string } }
559
+ /** Builder: the agent asked the person a question (ask_user); answer via POST …/answer. */
560
+ | {
561
+ event: 'question_asked';
562
+ data: {
563
+ questionId: string;
564
+ question: string;
565
+ header?: string;
566
+ options: Array<{ label: string; description?: string }>;
567
+ multiple: boolean;
568
+ expiresAt: number;
569
+ };
570
+ }
571
+ /** Builder: the open question was answered or withdrawn. */
572
+ | { event: 'question_answered'; data: { questionId: string; answered: boolean } }
573
+ /** Builder: mode / phase / plan path changed. */
574
+ | { event: 'builder_state'; data: { mode: 'attended' | 'unattended'; phase: 'plan' | 'build'; planPath: string | null } }
575
+ | {
576
+ // A queued user turn was taken back before it started
577
+ // (DELETE /chat/queue/:turnId). `turnId` is the same server-
578
+ // issued id the client got from POST /chat/send. Clients drop
579
+ // the optimistic bubble; the initiating client already has the
580
+ // text back in its composer. Followed by fresh `turn_queued`
581
+ // events for the waiters that moved up.
582
+ event: 'turn_dequeued';
583
+ /** `workId` (Phase 2): the work-ledger id — equals `turnId` for a
584
+ * human turn, a call_id or task_id for anything else. */
585
+ data: { turnId: string; workId?: string };
586
+ }
587
+ | {
588
+ // The engine opened a turn: its own turn id (`t-…`, the one
589
+ // that `assistant_media` / `turn_end` carry in the session
590
+ // file). Clients stamp the assistant bubble they are about to
591
+ // build with it, so late-arriving media and errors can be
592
+ // paired to THIS turn instead of "the most recent bubble" —
593
+ // which, when a turn errors without an assistant message, is
594
+ // the previous turn's (2026-08-28 report: pictures landed a
595
+ // few lines up).
596
+ event: 'turn_started';
597
+ data: { turnId: string };
598
+ }
599
+ | {
600
+ // The turn ended with an error instead of (or after) an
601
+ // assistant message. `status` still carries the same text for
602
+ // older clients; this event adds the engine turn id so the
603
+ // failure renders as a block inside the right turn.
604
+ event: 'turn_error';
605
+ data: { turnId?: string; message: string; engine: string };
606
+ }
607
+ | {
608
+ // Audio artifact ready for an assistant message. Sibling to
609
+ // `chat: final` — that event delivers the text, this one
610
+ // delivers a play-able URL for the same turn. Clients pair
611
+ // by `turnId` and render a Play-button on the corresponding
612
+ // assistant bubble.
613
+ event: 'assistant_audio';
614
+ data: {
615
+ turnId: string;
616
+ url: string;
617
+ mime: string;
618
+ durationMs?: number;
619
+ cacheKey: string;
620
+ };
621
+ }
622
+ | {
623
+ // Media produced during the turn. Same pairing mechanism as
624
+ // assistant_audio: arrives after the reply, clients attach it to
625
+ // the bubble with the matching turnId. Mirrors the persisted
626
+ // `assistant_media` event — see the note there on why entries
627
+ // carry a `type` instead of the kind naming one medium.
628
+ event: 'assistant_media';
629
+ data: {
630
+ turnId: string;
631
+ media: Array<{
632
+ type: 'image' | 'video';
633
+ id: string;
634
+ prompt: string;
635
+ mime: string;
636
+ filename: string;
637
+ url: string;
638
+ thumbUrl?: string;
639
+ durationSec?: number;
640
+ }>;
641
+ };
642
+ }
643
+ | {
644
+ // Engine-internal metadata (codex todo_list / future side-channel
645
+ // items). Persisted in JSONL by run-turn; clients only render when
646
+ // the `show.tools` toggle is on. Label mapping (raw itemType →
647
+ // friendly word) is shared via src/engine/engine-meta-labels.ts so
648
+ // server + clients stay in sync.
649
+ event: 'engine_meta';
650
+ data: {
651
+ engine: string;
652
+ itemType: string;
653
+ /** Pretty label resolved server-side (e.g. todo_list → "plan").
654
+ * Falls back to itemType verbatim for unknown types. */
655
+ label: string;
656
+ /** Optional one-liner summary (e.g. "3 items, 2 completed"). */
657
+ summary?: string;
658
+ /** Opaque structured payload — clients render via known itemType
659
+ * shapes or fall back to compact JSON dump for unknowns. */
660
+ payload: unknown;
661
+ };
662
+ }
663
+ | {
664
+ // Project focus change. Fired when the user (via /projekt slash-
665
+ // command or web button) pins or clears a project for this
666
+ // session. Clients use this to live-update the project-chip in
667
+ // the chat header without polling.
668
+ //
669
+ // `to: null` means the focus was cleared. Agent-initiated focus
670
+ // changes from MCP-routed tool calls (claude-cli / codex-cli)
671
+ // don't have SSE access from the child process — the client
672
+ // catches up on the next chat:final or by refetching
673
+ // /agents/:agent/sessions/:session/project explicitly.
674
+ event: 'project';
675
+ data: {
676
+ from: string | null;
677
+ to: string | null;
678
+ via: 'tool' | 'slash_command';
679
+ };
680
+ }
681
+ | {
682
+ // The session's model override was set or cleared (PUT/DELETE
683
+ // …/model). Often done from outside the window that shows the
684
+ // session — an orchestrator agent, another client — so clients
685
+ // re-read the session's model on this instead of showing the old
686
+ // one until reopened. `model: null` = override cleared, the
687
+ // persona default applies again. The running turn keeps the model
688
+ // it started with; the next turn uses the new one.
689
+ event: 'session_model';
690
+ data: {
691
+ model: string | null;
692
+ resolved?: string;
693
+ source: 'session-override' | 'persona-default';
694
+ };
695
+ };