moi-computer 0.11.0 → 0.11.1-dev.be1ed10

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 (362) hide show
  1. package/README.md +2 -2
  2. package/client/AGENTS.md +2 -2
  3. package/client/app/AppRouter.tsx +2 -2
  4. package/client/app/routes/WorkspaceRoute.tsx +7 -9
  5. package/client/app/shell/SidebarLayout.tsx +18 -15
  6. package/client/components/shared/BottomPanel.tsx +26 -14
  7. package/client/components/shared/PanelHeader.tsx +1 -1
  8. package/client/components/shared/ReorderableList.tsx +7 -2
  9. package/client/components/shared/WorkspaceIcon.tsx +92 -0
  10. package/client/components/ui/alert-dialog.tsx +1 -0
  11. package/client/components/ui/button.tsx +1 -53
  12. package/client/components/ui/checkbox.tsx +1 -0
  13. package/client/components/ui/collapsible.tsx +1 -15
  14. package/client/components/ui/dialog.tsx +1 -58
  15. package/client/components/ui/dropdown-menu.tsx +1 -254
  16. package/client/components/ui/hover-card.tsx +1 -44
  17. package/client/components/ui/inline-input.tsx +84 -0
  18. package/client/components/ui/input.tsx +1 -21
  19. package/client/components/ui/popover.tsx +1 -88
  20. package/client/components/ui/resizable.tsx +1 -40
  21. package/client/components/ui/skeleton.tsx +1 -13
  22. package/client/components/ui/slider.tsx +1 -70
  23. package/client/components/ui/spinner.tsx +1 -18
  24. package/client/components/ui/switch.tsx +1 -23
  25. package/client/components/ui/tabs.tsx +1 -0
  26. package/client/components/ui/textarea.tsx +1 -18
  27. package/client/components/ui/toast.tsx +2 -2
  28. package/client/components/ui/tooltip.tsx +1 -51
  29. package/client/features/applets/AppletMount.tsx +1 -1
  30. package/client/features/applets/applet-cache.ts +3 -3
  31. package/client/features/applets/applet-runtime.ts +147 -108
  32. package/client/features/applets/applet-styles.ts +2 -2
  33. package/client/features/applets/applet-thumbnail.ts +6 -8
  34. package/client/features/applets/useApplet.ts +10 -9
  35. package/client/features/chat/ChatPanel.tsx +24 -15
  36. package/client/features/chat/ChatPopup.tsx +9 -5
  37. package/client/features/chat/applet-chat-intents.ts +170 -0
  38. package/client/features/chat/chat-send.ts +116 -64
  39. package/client/features/chat/chat-store.ts +51 -62
  40. package/client/features/chat/composer/ChatComposer.tsx +43 -128
  41. package/client/features/chat/composer/ModelPicker.tsx +47 -60
  42. package/client/features/chat/composer/attachments/AttachmentChip.tsx +99 -0
  43. package/client/features/chat/composer/attachments/DrawingAttachmentChip.tsx +37 -0
  44. package/client/features/chat/composer/attachments/FileAttachmentChip.tsx +22 -0
  45. package/client/features/chat/composer/attachments/TextAttachmentChip.tsx +11 -0
  46. package/client/features/chat/composer/attachments/draft-attachments.ts +168 -0
  47. package/client/features/chat/composer/attachments/types.ts +25 -0
  48. package/client/features/chat/composer/attachments/uploads.ts +26 -0
  49. package/client/features/chat/composer/banners/ErrorBanner.tsx +20 -12
  50. package/client/features/chat/composer/model-order.ts +15 -0
  51. package/client/features/chat/composer/useWorkspaceComposerState.tsx +15 -7
  52. package/client/features/chat/{chat-connection.ts → connection/chat-connection.ts} +1 -1
  53. package/client/features/chat/{chat-frames.ts → connection/chat-frames.ts} +10 -8
  54. package/client/features/chat/{ChatEmptyState.tsx → messages/ChatEmptyState.tsx} +16 -11
  55. package/client/features/chat/{MarkdownContent.tsx → messages/MarkdownContent.tsx} +16 -1
  56. package/client/features/chat/{TurnView.tsx → messages/TurnView.tsx} +27 -19
  57. package/client/features/chat/{group-turns.ts → messages/group-turns.ts} +12 -0
  58. package/client/features/chat/{interleave-notices.ts → messages/interleave-notices.ts} +7 -11
  59. package/client/features/chat/{tool-group → messages/tool-group}/SubagentCard.tsx +1 -1
  60. package/client/features/chat/{tool-group → messages/tool-group}/TimelineRow.tsx +2 -2
  61. package/client/features/chat/{tool-group → messages/tool-group}/ToolCallGroup.tsx +2 -5
  62. package/client/features/chat/{tool-group → messages/tool-group}/format/codex.ts +4 -1
  63. package/client/features/chat/{ChatSelector.tsx → sessions/ChatSelector.tsx} +3 -3
  64. package/client/features/chat/{api.ts → sessions/api.ts} +5 -14
  65. package/client/features/chat/sessions/session-view.ts +53 -0
  66. package/client/features/chat/useChat.ts +42 -24
  67. package/client/features/dev/ChatStatesPage.tsx +8 -7
  68. package/client/features/dev/DevIndexPage.tsx +5 -0
  69. package/client/features/dev/DevRoutes.tsx +2 -0
  70. package/client/features/dev/HarnessDebugPage.tsx +11 -8
  71. package/client/features/dev/ToolCallsPage.tsx +1 -1
  72. package/client/features/dev/UiComponentPreviews.tsx +855 -0
  73. package/client/features/dev/UiComponentsPage.tsx +60 -0
  74. package/client/features/dev/chat-states-fixtures.ts +13 -2
  75. package/client/features/drawings/useChatAnnotation.ts +17 -17
  76. package/client/features/drawings/useDrawingLayer.ts +7 -9
  77. package/client/features/drawings/useViewBuilderSketch.ts +18 -15
  78. package/client/features/home/HomePage.tsx +8 -7
  79. package/client/features/home/WorkspacePreview.tsx +2 -2
  80. package/client/features/home/workspace-presentation.tsx +1 -11
  81. package/client/features/home/workspace-setup/DemoDialog.tsx +3 -2
  82. package/client/features/home/workspace-setup/ImportWorkspaceDialog.tsx +5 -8
  83. package/client/features/home/workspace-setup/WorkspaceAgentStep.tsx +2 -4
  84. package/client/features/home/workspace-setup/WorkspaceDialogContent.tsx +7 -20
  85. package/client/features/overview/HiddenPanel.tsx +109 -0
  86. package/client/features/overview/Overview.tsx +302 -0
  87. package/client/features/overview/WidgetCanvas.tsx +164 -0
  88. package/client/features/{widgets → overview}/WidgetFrame.tsx +25 -17
  89. package/client/features/overview/WorkspaceName.tsx +60 -0
  90. package/client/features/overview/api.ts +30 -0
  91. package/client/features/overview/default/ViewsWidget.tsx +252 -0
  92. package/client/features/overview/default/registry.tsx +36 -0
  93. package/client/features/{widgets → overview}/grid.ts +36 -0
  94. package/client/features/overview/useGridReconcile.ts +94 -0
  95. package/client/features/scratchpad/Scratchpad.tsx +7 -8
  96. package/client/features/scratchpad/ScratchpadControls.tsx +0 -1
  97. package/client/features/scratchpad/useScratchpadSnapshot.tsx +23 -13
  98. package/client/features/settings/GeneralSettings.tsx +55 -58
  99. package/client/features/settings/SettingsLayout.tsx +2 -2
  100. package/client/features/settings/WorkspaceIconPicker.tsx +318 -0
  101. package/client/features/settings/WorkspaceSettingsDialog.tsx +65 -0
  102. package/client/features/settings/api.ts +48 -24
  103. package/client/features/views/ViewBuilder.tsx +5 -4
  104. package/client/features/views/ViewManager.tsx +25 -22
  105. package/client/features/views/api.ts +36 -2
  106. package/client/features/views/useViewBuilderActions.ts +8 -5
  107. package/client/features/views/useViewBuilderDrafts.ts +23 -21
  108. package/client/features/views/view-presentation.ts +13 -0
  109. package/client/features/workspace/{CustomizePanel.tsx → ThemePanel.tsx} +26 -31
  110. package/client/features/workspace/UnavailablePage.tsx +21 -0
  111. package/client/features/workspace/WorkspaceLayoutContext.tsx +4 -7
  112. package/client/features/workspace/WorkspaceScreen.tsx +210 -162
  113. package/client/features/workspace/WorkspaceSplitLayout.tsx +7 -2
  114. package/client/features/workspace/WorkspaceTabs.tsx +2 -0
  115. package/client/features/workspace/api.ts +2 -30
  116. package/client/features/workspace/moi-context.ts +8 -9
  117. package/client/features/workspace/tab-resolution.ts +10 -33
  118. package/client/features/workspace/useWorkspaceNavigation.ts +164 -101
  119. package/client/index.css +23 -30
  120. package/client/lib/app-icon-registry.ts +2 -0
  121. package/client/lib/use-latest-ref.ts +11 -0
  122. package/client/main.tsx +1 -1
  123. package/client/runtime/useWorkspaceEvents.ts +59 -14
  124. package/client/theme.css +5 -5
  125. package/dist/{chunk-tqd3pkg8.css → chunk-60q353jq.css} +1 -1
  126. package/dist/chunk-691pqsj6.js +2 -0
  127. package/dist/chunk-7a5nm4k9.css +1 -0
  128. package/dist/chunk-amb8y04y.js +1 -0
  129. package/dist/chunk-cf3pgy7j.js +546 -0
  130. package/dist/{chunk-11cab5dq.css → chunk-cq2r11fg.css} +1 -1
  131. package/dist/chunk-mzrgr577.js +5 -0
  132. package/dist/chunk-nf2wkvf9.js +14 -0
  133. package/dist/chunk-q6a0g26x.js +1 -0
  134. package/dist/chunk-twgdemkc.js +74 -0
  135. package/dist/chunk-x90k0f5c.js +2 -0
  136. package/dist/chunk-yq00csvd.js +2 -0
  137. package/dist/index.html +1 -1
  138. package/lib/app-icons.ts +1 -0
  139. package/lib/applet-selector.ts +24 -0
  140. package/lib/chat-title.ts +6 -1
  141. package/lib/default-widgets.ts +32 -0
  142. package/lib/format.ts +67 -7
  143. package/lib/message-attachments.ts +40 -0
  144. package/lib/moi-attachments.ts +204 -0
  145. package/lib/moi-context.ts +20 -35
  146. package/lib/navigation.ts +84 -0
  147. package/lib/themes.ts +6 -6
  148. package/lib/types.ts +91 -34
  149. package/lib/workspace-icon.ts +20 -0
  150. package/lib/workspace-layout.ts +22 -2
  151. package/lib/workspace-tabs.ts +9 -33
  152. package/package.json +42 -32
  153. package/registry.json +656 -0
  154. package/server/AGENTS.md +2 -0
  155. package/server/agent.ts +1 -1
  156. package/server/api.ts +139 -66
  157. package/server/applet-typecheck.ts +95 -0
  158. package/server/applets/applet-css.ts +55 -0
  159. package/server/{bundler → applets}/build-applet.ts +13 -242
  160. package/server/applets/build-worker.ts +178 -0
  161. package/server/applets/config.ts +226 -0
  162. package/server/applets/dependencies.ts +206 -0
  163. package/server/{applets.ts → applets/index.ts} +44 -189
  164. package/server/applets/runtime/base.ts +4 -0
  165. package/server/applets/runtime/moi.ts +42 -0
  166. package/server/applets/runtime/rpc.ts +17 -0
  167. package/server/applets/view-source.ts +67 -0
  168. package/server/attachment-message.ts +95 -0
  169. package/server/cli-ui-components.ts +28 -33
  170. package/server/cli.ts +169 -108
  171. package/server/control.ts +63 -42
  172. package/server/data-dir.ts +1 -1
  173. package/server/harness/README.md +45 -50
  174. package/server/harness/acp/NOTES.md +426 -0
  175. package/server/harness/acp/adapter.ts +7 -21
  176. package/server/harness/acp/discovery.ts +27 -30
  177. package/server/harness/acp/model-state.ts +57 -0
  178. package/server/harness/acp/session.ts +49 -56
  179. package/server/harness/claude-code/NOTES.md +54 -13
  180. package/server/harness/claude-code/adapter.ts +8 -25
  181. package/server/harness/claude-code/cli.ts +40 -0
  182. package/server/harness/claude-code/index.ts +13 -5
  183. package/server/harness/claude-code/models.ts +72 -19
  184. package/server/harness/claude-code/session.ts +447 -343
  185. package/server/harness/claude-code/sessions.ts +9 -4
  186. package/server/harness/codex/NOTES.md +222 -350
  187. package/server/harness/codex/adapter.ts +102 -52
  188. package/server/harness/codex/auth.ts +1 -3
  189. package/server/harness/codex/client.ts +169 -249
  190. package/server/harness/codex/discovery.ts +9 -17
  191. package/server/harness/codex/index.ts +3 -1
  192. package/server/harness/codex/pagination.ts +24 -0
  193. package/server/harness/codex/permissions.ts +32 -8
  194. package/server/harness/codex/probe.ts +10 -13
  195. package/server/harness/codex/session.ts +567 -181
  196. package/server/harness/codex/transport.ts +184 -0
  197. package/server/harness/debug.ts +1 -1
  198. package/server/harness/hermes/NOTES.md +19 -1
  199. package/server/harness/hermes/discovery.ts +20 -0
  200. package/server/harness/hermes/index.ts +13 -0
  201. package/server/harness/hermes/models.ts +28 -8
  202. package/server/harness/openclaw/NOTES.md +1 -1
  203. package/server/harness/openclaw/adapter.ts +22 -4
  204. package/server/harness/openclaw/gateway.ts +5 -3
  205. package/server/harness/openclaw/session.ts +27 -27
  206. package/server/harness/types.ts +9 -5
  207. package/server/layout.ts +9 -14
  208. package/server/moi-scaffold.ts +22 -14
  209. package/server/navigation-relay.ts +110 -0
  210. package/server/preview.ts +3 -1
  211. package/server/registry.ts +71 -41
  212. package/server/scratchpad-executor.ts +79 -56
  213. package/server/scratchpad-shape-defaults.ts +82 -0
  214. package/server/selected-session.ts +24 -4
  215. package/server/skill-update.ts +5 -3
  216. package/server/skill-version.ts +4 -7
  217. package/server/skills-template.ts +48 -9
  218. package/server/tabs.ts +19 -33
  219. package/server/tldraw-package.d.ts +4 -0
  220. package/server/ui-components.ts +101 -434
  221. package/server/uploads.ts +0 -0
  222. package/server/view-builders.ts +20 -2
  223. package/server/views.ts +126 -6
  224. package/server/web.ts +46 -13
  225. package/server/widgets.ts +12 -5
  226. package/server/workspace-config.ts +13 -9
  227. package/server/workspace-env.ts +3 -2
  228. package/tsconfig.json +0 -1
  229. package/ui-components/accordion.tsx +71 -0
  230. package/ui-components/alert-dialog.tsx +165 -0
  231. package/ui-components/alert.tsx +68 -0
  232. package/ui-components/attachment.tsx +195 -0
  233. package/ui-components/avatar.tsx +90 -0
  234. package/ui-components/badge.tsx +49 -0
  235. package/ui-components/button-group.tsx +78 -0
  236. package/ui-components/button.tsx +55 -0
  237. package/ui-components/calendar.tsx +180 -0
  238. package/ui-components/card.tsx +84 -0
  239. package/ui-components/carousel.tsx +235 -0
  240. package/ui-components/chart.tsx +338 -0
  241. package/ui-components/checkbox.tsx +28 -0
  242. package/ui-components/collapsible.tsx +15 -0
  243. package/ui-components/combobox.tsx +267 -0
  244. package/ui-components/context-menu.tsx +244 -0
  245. package/ui-components/dialog.tsx +138 -0
  246. package/ui-components/docs/accordion.md +463 -0
  247. package/ui-components/docs/alert-dialog.md +481 -0
  248. package/ui-components/docs/alert.md +301 -0
  249. package/ui-components/docs/attachment.md +689 -0
  250. package/ui-components/docs/avatar.md +495 -0
  251. package/ui-components/docs/badge.md +258 -0
  252. package/ui-components/docs/button-group.md +879 -0
  253. package/ui-components/docs/button.md +26 -0
  254. package/ui-components/docs/calendar.md +862 -0
  255. package/ui-components/docs/card.md +265 -0
  256. package/ui-components/docs/carousel.md +627 -0
  257. package/ui-components/docs/chart.md +1256 -0
  258. package/ui-components/docs/checkbox.md +477 -0
  259. package/ui-components/docs/collapsible.md +446 -0
  260. package/ui-components/docs/combobox.md +1003 -0
  261. package/ui-components/docs/context-menu.md +860 -0
  262. package/ui-components/docs/data-table.md +1580 -0
  263. package/ui-components/docs/date-picker.md +614 -0
  264. package/ui-components/docs/dialog.md +414 -0
  265. package/ui-components/docs/drawer.md +51 -0
  266. package/ui-components/docs/dropdown-menu.md +1000 -0
  267. package/ui-components/docs/field.md +1192 -0
  268. package/ui-components/docs/hover-card.md +275 -0
  269. package/ui-components/docs/input-group.md +866 -0
  270. package/ui-components/docs/input.md +456 -0
  271. package/ui-components/docs/kbd.md +191 -0
  272. package/ui-components/docs/label.md +295 -0
  273. package/ui-components/docs/pagination.md +416 -0
  274. package/ui-components/docs/popover.md +348 -0
  275. package/ui-components/docs/progress.md +214 -0
  276. package/ui-components/docs/radio-group.md +389 -0
  277. package/ui-components/docs/resizable.md +265 -0
  278. package/ui-components/docs/select.md +616 -0
  279. package/ui-components/docs/separator.md +216 -0
  280. package/ui-components/docs/skeleton.md +205 -0
  281. package/ui-components/docs/slider.md +226 -0
  282. package/ui-components/docs/spinner.md +332 -0
  283. package/ui-components/docs/switch.md +236 -0
  284. package/ui-components/docs/table.md +551 -0
  285. package/ui-components/docs/tabs.md +379 -0
  286. package/ui-components/docs/textarea.md +187 -0
  287. package/ui-components/docs/toggle-group.md +370 -0
  288. package/ui-components/docs/toggle.md +91 -0
  289. package/ui-components/docs/tooltip.md +290 -0
  290. package/ui-components/drawer.tsx +213 -0
  291. package/ui-components/dropdown-menu.tsx +263 -0
  292. package/ui-components/field.tsx +224 -0
  293. package/ui-components/hover-card.tsx +46 -0
  294. package/ui-components/input-group.tsx +146 -0
  295. package/ui-components/input.tsx +20 -0
  296. package/ui-components/kbd.tsx +32 -0
  297. package/ui-components/label.tsx +17 -0
  298. package/ui-components/pagination.tsx +124 -0
  299. package/ui-components/popover.tsx +81 -0
  300. package/ui-components/progress.tsx +63 -0
  301. package/ui-components/radio-group.tsx +38 -0
  302. package/ui-components/resizable.tsx +40 -0
  303. package/ui-components/scoped-portal.tsx +31 -0
  304. package/ui-components/select.tsx +195 -0
  305. package/ui-components/separator.tsx +18 -0
  306. package/ui-components/skeleton.tsx +15 -0
  307. package/ui-components/slider.tsx +75 -0
  308. package/ui-components/spinner.tsx +20 -0
  309. package/ui-components/switch.tsx +27 -0
  310. package/ui-components/table.tsx +86 -0
  311. package/ui-components/tabs.tsx +75 -0
  312. package/ui-components/textarea.tsx +17 -0
  313. package/ui-components/toggle-group.tsx +85 -0
  314. package/ui-components/toggle.tsx +42 -0
  315. package/ui-components/tooltip.tsx +61 -0
  316. package/ui-components/utils.ts +8 -0
  317. package/workspace/.claude/skills/moi-workspace/SKILL.md +295 -248
  318. package/workspace/.claude/skills/moi-workspace/references/DESIGN.md +100 -152
  319. package/workspace/.claude/skills/moi-workspace/references/INTENTS.md +156 -0
  320. package/workspace/.claude/skills/moi-workspace/references/UI-COMPONENTS.md +67 -203
  321. package/client/features/chat/attachment-staging.ts +0 -153
  322. package/client/features/chat/uploads.ts +0 -18
  323. package/client/features/chat/useAppletChatMessage.ts +0 -68
  324. package/client/features/settings/IconPicker.tsx +0 -442
  325. package/client/features/settings/WorkspaceSettings.tsx +0 -92
  326. package/client/features/settings/render-icon.ts +0 -173
  327. package/client/features/widgets/HiddenPanel.tsx +0 -80
  328. package/client/features/widgets/WidgetGrid.tsx +0 -123
  329. package/client/features/widgets/Widgets.tsx +0 -264
  330. package/client/features/widgets/useGridReconcile.ts +0 -73
  331. package/dist/chunk-104m57qw.js +0 -2
  332. package/dist/chunk-59zf0m6n.js +0 -1
  333. package/dist/chunk-bj3akjs2.js +0 -1
  334. package/dist/chunk-c9pjqx9m.js +0 -14
  335. package/dist/chunk-j2w2vak4.js +0 -546
  336. package/dist/chunk-k2r9c95m.js +0 -10
  337. package/dist/chunk-kmbxhgwv.js +0 -1
  338. package/dist/chunk-p1yqa71k.js +0 -83
  339. package/dist/chunk-pcnahct1.js +0 -5
  340. package/dist/chunk-r5xrenjy.css +0 -1
  341. package/dist/chunk-tny85yt2.js +0 -2
  342. package/dist/chunk-v7wr1df4.js +0 -2
  343. package/server/bundler/applet-css.ts +0 -155
  344. /package/client/features/chat/{ChatPromptBubbles.tsx → messages/ChatPromptBubbles.tsx} +0 -0
  345. /package/client/features/chat/{ShimmerText.tsx → messages/ShimmerText.tsx} +0 -0
  346. /package/client/features/chat/{preview-turn.ts → messages/preview-turn.ts} +0 -0
  347. /package/client/features/chat/{tool-group → messages/tool-group}/CodeBlock.tsx +0 -0
  348. /package/client/features/chat/{tool-group → messages/tool-group}/Collapse.tsx +0 -0
  349. /package/client/features/chat/{tool-group → messages/tool-group}/ReadImagePreview.tsx +0 -0
  350. /package/client/features/chat/{tool-group → messages/tool-group}/ToolOutput.tsx +0 -0
  351. /package/client/features/chat/{tool-group → messages/tool-group}/detect.ts +0 -0
  352. /package/client/features/chat/{tool-group → messages/tool-group}/fixtures.ts +0 -0
  353. /package/client/features/chat/{tool-group → messages/tool-group}/format/claude.ts +0 -0
  354. /package/client/features/chat/{tool-group → messages/tool-group}/format/hermes.ts +0 -0
  355. /package/client/features/chat/{tool-group → messages/tool-group}/format/index.ts +0 -0
  356. /package/client/features/chat/{tool-group → messages/tool-group}/format/mcp.ts +0 -0
  357. /package/client/features/chat/{tool-group → messages/tool-group}/format/openclaw.ts +0 -0
  358. /package/client/features/chat/{tool-group → messages/tool-group}/format/shared.ts +0 -0
  359. /package/client/features/chat/{tool-group → messages/tool-group}/format/shell.ts +0 -0
  360. /package/client/features/chat/{tool-group → messages/tool-group}/index.ts +0 -0
  361. /package/client/features/chat/{useStickToBottom.ts → messages/useStickToBottom.ts} +0 -0
  362. /package/client/features/chat/{useSelectedSession.ts → sessions/useSelectedSession.ts} +0 -0
@@ -1,5 +1,6 @@
1
1
  // Session discovery + history replay for Claude Code workspaces, backed by
2
2
  // the Agent SDK's persisted `.jsonl` session files.
3
+ import { attachmentLabel, splitAttachments, stripAttachmentsLoose } from '@/lib/moi-attachments'
3
4
  import {
4
5
  getSessionInfo,
5
6
  getSessionMessages,
@@ -35,12 +36,16 @@ export function claudeSessionSummary(
35
36
  session: Pick<SDKSessionInfo, 'customTitle' | 'firstPrompt' | 'summary'>
36
37
  ): string {
37
38
  if (session.customTitle || !session.firstPrompt || session.summary !== session.firstPrompt) {
38
- return session.summary
39
+ return stripAttachmentsLoose(session.summary)
39
40
  }
40
- const split = splitAttachmentNote(session.firstPrompt)
41
+ const attached = splitAttachments(session.firstPrompt)
42
+ const split = splitAttachmentNote(attached.text)
41
43
  return isAttachmentOnlyPlaceholder(split.text)
42
44
  ? attachmentOnlyFilenames(split.text).join(', ')
43
- : session.summary
45
+ : stripAttachmentsLoose(split.text) ||
46
+ [...attached.attachments.map(attachmentLabel), ...split.files.map(f => f.filename)].join(
47
+ ', '
48
+ )
44
49
  }
45
50
 
46
51
  export function visibleClaudeSessions<T extends Pick<SDKSessionInfo, 'tag'>>(sessions: T[]): T[] {
@@ -67,7 +72,7 @@ export function selectOldestSessionFirstUserMessage(
67
72
  (a.createdAt ?? a.lastModified) - (b.createdAt ?? b.lastModified) ||
68
73
  a.sessionId.localeCompare(b.sessionId)
69
74
  )[0]
70
- return oldest?.firstPrompt
75
+ return oldest?.firstPrompt ? stripAttachmentsLoose(oldest.firstPrompt) : undefined
71
76
  }
72
77
 
73
78
  export function selectLatestSessionUpdatedAt(
@@ -1,356 +1,228 @@
1
- # Codex — integration research
2
-
3
- Research notes on driving OpenAI Codex as a moi harness (July 2026). The
4
- adapter shipped on the app-server path recommended below — see §5 for what
5
- implementation against CLI 0.144.5 confirmed/corrected. Codex exposes **two**
6
- programmable surfaces, and they differ enough that the choice shapes the
7
- whole adapter:
8
-
9
- 1. **`@openai/codex-sdk`** (npm, TypeScript) — a thin wrapper that spawns
10
- `codex exec` as a fresh subprocess per turn.
11
- 2. **`codex app-server`** — a long-lived JSON-RPC 2.0 server bundled with the
12
- CLI; the protocol behind the official VS Code extension.
13
-
14
- **Recommendation: target the app-server.** The exec SDK is missing too much
15
- (no interrupt method, no model list, no token deltas, no steering); the
16
- app-server covers essentially the whole adapter checklist in
17
- [../README.md](../README.md) and even exceeds the Claude Agent SDK in places.
18
-
19
- Sources: [SDK TypeScript source](https://github.com/openai/codex/tree/main/sdk/typescript/src),
20
- [app-server README](https://github.com/openai/codex/blob/main/codex-rs/app-server/README.md),
21
- [Codex SDK docs](https://developers.openai.com/codex/sdk).
22
-
23
- ## 1. The exec SDK (`@openai/codex-sdk`)
24
-
25
- ```ts
26
- const codex = new Codex({ env, config }) // env REPLACES process.env, not merged
27
- const thread = codex.startThread({
28
- model,
29
- sandboxMode,
30
- workingDirectory,
31
- modelReasoningEffort,
32
- approvalPolicy
33
- })
34
- const { events } = await thread.runStreamed(input, { outputSchema, signal })
1
+ # Codex harness
2
+
3
+ moi drives chats through `codex app-server`, a persistent process speaking
4
+ newline-delimited JSON-RPC over stdio. It provides native model and session
5
+ lists, token deltas, steering, and interruption. Codex owns durable history;
6
+ moi holds a display copy and translates native items into shared chat events.
7
+
8
+ The upstream [app-server specification](https://learn.chatgpt.com/docs/app-server)
9
+ defines the protocol; generated types from the installed CLI define its exact wire shapes.
10
+
11
+ ## Module ownership
12
+
13
+ | Module | Responsibility |
14
+ | -------------------------------------- | ---------------------------------------------------------------------------------------------------------------------- |
15
+ | `index.ts` | Implements the shared `Harness` contract. |
16
+ | `transport.ts` | Frames stdio, routes RPC replies and server requests, times out requests, and closes waiters on disconnect. |
17
+ | `client.ts` | Owns one app-server per workspace, initialization, catalogs, session/history queries, and bounded child-history reads. |
18
+ | `session.ts` | Owns live session state, sends, steering, stop, replay hydration, previews, and notices. |
19
+ | `adapter.ts` | Defines the consumed wire types and maps models, items, and history to display types. |
20
+ | `permissions.ts` | Defines sandbox access and the default approval policy; rejects unsupported requests. |
21
+ | `auth.ts`, `discovery.ts`, `status.ts` | Check login readiness, discover workspace paths from rollout heads, and report running processes. |
22
+ | `session-title.ts` | Generates a title with a separate ephemeral `codex exec` call and applies it if the session is still unnamed. |
23
+ | `probe.ts` | Runs standalone protocol diagnostics without moi's session or workspace policy. |
24
+
25
+ The shared contract and event layers are in [../README.md](../README.md).
26
+
27
+ ## Runtime and configuration
28
+
29
+ `../executable.ts` searches the login-shell PATH followed by the server PATH.
30
+ If neither resolves `codex`, it checks the macOS `ChatGPT.app` and `Codex.app`
31
+ bundles. A CLI on PATH wins even when the desktop app bundles a newer version.
32
+
33
+ Each process inherits the server environment plus `resolveWorkspaceEnv()` and
34
+ `MOI_AGENT=1`. Workspace environment variables are fixed at spawn, which is
35
+ why workspaces have separate app-servers. Environment changes close the affected
36
+ process; the next request starts a replacement. Closing a process interrupts
37
+ its active runs. Idle display eviction does not stop the workspace process.
38
+
39
+ Codex resolves its own configuration and credentials, including `CODEX_HOME`
40
+ (default `~/.codex`). Installations can share that home while running different
41
+ binary versions. `config/read` with the workspace cwd supplies effective model,
42
+ effort, and tier defaults; moi does not rewrite the user's Codex config.
43
+
44
+ Initialization enables `experimentalApi`, reads the version from `userAgent`,
45
+ and then sends `initialized`. The availability check rejects parsed versions
46
+ below 0.89.0, the harness's basic protocol floor; unknown and development
47
+ versions are allowed. This floor does **not** establish support for every
48
+ feature or model. Use the running process's catalog and version when diagnosing
49
+ model errors.
50
+
51
+ The HTTP server allows 60 seconds of inactivity so discovery can finish or
52
+ reach the harness's 30-second RPC timeout before Bun closes the connection.
53
+
54
+ ## Session lifecycle
55
+
56
+ - A new chat starts under a temporary moi id. `thread/start` supplies the real
57
+ id; `session_renamed` rekeys the chat, saved settings, and builder references.
58
+ - Concurrent resumes share one promise. Subscribe before `thread/resume`,
59
+ buffer notifications while loading history, then apply them after the
60
+ snapshot. Otherwise a live update can be overwritten by replay.
61
+ - Serialize sends through RPC acknowledgement, not through model completion.
62
+ Follow-ups use `turn/steer` with `expectedTurnId` while a turn is active.
63
+ Only an explicit no-active-turn RPC error permits fallback to `turn/start`.
64
+ A timeout or ambiguous failure must not resubmit potentially accepted input.
65
+ - Native lifecycle notifications determine activity. Completion can arrive
66
+ before the start acknowledgement; completed ids prevent late responses from
67
+ reviving a run. Ignore stale usage and completion from older turns.
68
+ Active waiting flags map to `requires-action`. Closed, archived, deleted, or
69
+ unloaded threads release the live record; later access resumes it again.
70
+ - `error.willRetry` keeps the turn active and emits a retry notice. Failed
71
+ steer/interrupt RPCs keep a known active turn stoppable. A terminal error or
72
+ disconnect clears previews and settles unfinished tool cards.
73
+ - Stop invalidates queued sends and interrupts a start acknowledged after Stop.
74
+ For a running turn, wait for native completion before reporting it stopped.
75
+ - Idle display records expire after 30 minutes, except during active turns,
76
+ hydration, or title generation. Cold access resumes and subscribes again;
77
+ `thread/read` provides a static fallback when live resume fails.
78
+
79
+ `thread/list` uses cwd filtering, `updated_at` ordering, and every cursor page.
80
+ Repeated cursors fail instead of looping. Child-history loading is limited to
81
+ four concurrent reads. Home-card previews reuse an existing app-server and read
82
+ up to 50 recent sessions; rendering the home page does not spawn one per card.
83
+ Workspace import discovery separately reads up to 400 recent rollout heads
84
+ under the server's `$CODEX_HOME/sessions`, without requiring a CLI executable.
85
+
86
+ ## Models, effort, and fast mode
87
+
88
+ `model/list` is the source of picker capabilities. The catalog is paginated,
89
+ filters hidden rows, and is cached per client for one minute. Login/account
90
+ notifications invalidate it; replacing the process also replaces its cache.
91
+ Effective config is read separately. Never share catalogs across workspace
92
+ processes, whose environment can select different accounts or providers.
93
+
94
+ The synthetic `default` row resolves to the configured model when listed,
95
+ otherwise the catalog default, otherwise the first available model. The picker
96
+ and send path share `resolveSelectedModel`; when the catalog is available, a
97
+ Codex UI send includes that concrete native model. Omitting it can inherit an
98
+ unavailable config or resumed-thread model while the picker shows a fallback.
99
+ Changing a selection does not retry an earlier failed message.
100
+
101
+ Configured reasoning effort applies when supported by the selected model;
102
+ otherwise the adapter uses its advertised default. Fast mode is available when
103
+ `serviceTiers` includes `priority`. Only catalogs missing that field fall back
104
+ to `additionalSpeedTiers: ["fast"]`. A non-null configured tier takes precedence
105
+ over the catalog default.
106
+
107
+ | moi fast-mode setting | Native `serviceTier` |
108
+ | --------------------- | ---------------------------------------- |
109
+ | On | `"priority"` |
110
+ | Off | `null` |
111
+ | Unset | Omitted; inherits the config/thread tier |
112
+
113
+ Model, effort, and tier changes apply on the next **new turn**. `turn/steer`
114
+ has no fields for changing them during an active turn. moi uses the persistent
115
+ `serviceTier` override for chat settings; it does not use the newer
116
+ `serviceTierForTurn` override, which affects only one turn.
117
+
118
+ ## Context and permissions
119
+
120
+ `additionalContext` carries the application context under `moi-context`, and
121
+ localhost access guidance under `moi-control-access`. Values use the unwrapped
122
+ body because Codex supplies the tags; native context is not echoed as a user
123
+ item. `client.ts` gates this channel at 0.135.0. Older or unrecognized versions
124
+ receive a text envelope, which the adapter strips from echoes and previews.
125
+ The version gate matters because older servers can silently ignore the field.
126
+
127
+ `permissions.ts` selects workspace-write access and `approvalPolicy: 'on-request'`
128
+ on start/resume. New turns explicitly set the workspace-write sandbox with
129
+ network access disabled. moi automatically accepts supported permission
130
+ requests; there is no command-approval UI.
131
+ Command/file requests use `decision: 'accept'`, legacy requests use `approved`,
132
+ and permission extensions grant the requested network/file-system fields for
133
+ `scope: 'turn'`. Unknown request methods receive an unsupported-method error.
134
+
135
+ Native question forms (`item/tool/requestUserInput`) are not supported and
136
+ receive the same unsupported-method error. moi does not opt into
137
+ `features.default_mode_request_user_input`. MCP schema/URL elicitation is
138
+ declined with `action: 'decline'`.
139
+
140
+ ### TODO: restore native question forms
141
+
142
+ This feature is deferred, not ruled out. It was removed in `1cfce26` because
143
+ the question form exposed an undefined `Field` namespace in Base UI's `Input`
144
+ wrapper in Bun's dev bundle. The earlier workaround changed every shared
145
+ Input to `Field.Control`; the underlying bundler cause was not established.
146
+ The removed implementation is available in that commit's parent for reference.
147
+
148
+ Before restoring support:
149
+
150
+ - Resolve the Input failure at its source and verify the form in both dev and
151
+ production builds before opting into native questions again.
152
+ - Re-read the current app-server spec and generated types. Preserve fixed
153
+ choices, free-text answers, secret fields, and blocking/nonblocking semantics.
154
+ - Restore session-scoped request handling, the answer endpoint, and chat UI.
155
+ Handle reload, skip, stop, disconnect, and `serverRequest/resolved` without
156
+ duplicate replies or stale forms answering reused request ids. Keep answers
157
+ out of debug logs and notice payloads.
158
+ - Verify the full flow with browser interactions and a real Codex session,
159
+ including cancellation and recovery; add tests for those boundaries.
160
+
161
+ ## Display and MCP boundaries
162
+
163
+ - Native items become display turns or notices. `clientUserMessageId` is echoed
164
+ as `clientId` on live user items, so the optimistic bubble is updated in place.
165
+ Replay can change item ids and omit `clientId`; they are not durable moi ids.
166
+ - Agent text and reasoning-summary deltas become cumulative previews, batched
167
+ every 40ms. Item completion removes its pending preview. Command output
168
+ deltas are also batched; the live tail is bounded to 64K characters until the
169
+ completed item replaces it with authoritative output. Native plan updates
170
+ upsert a plan card within their turn.
171
+ - New turns request `summary: 'detailed'`. Reasoning can still be absent for a
172
+ trivial prompt. Replay uses native timestamps and duration when supplied,
173
+ rather than deriving duration from items sharing a turn timestamp.
174
+ - Child transcripts nest under `subAgentActivity` cards. Replay excludes
175
+ inherited parent turns and child send-back activity; missing children leave
176
+ their cards visible. Generated images are represented by tool cards without
177
+ embedding the potentially large base64 result in every display event.
178
+ - Uploads send images inline as data URLs and other files as materialized path
179
+ notes. Text-only models reject image sends with an actionable error; absent
180
+ `inputModalities` retains the protocol's image-compatible default. Steering
181
+ checks the running model. Replayed `localImage` items currently show a path label.
182
+ - Warnings, failed MCP startups, and model reroutes appear in the chat timeline.
183
+ Hook notices are retained but have no chat rendering. The connector list uses
184
+ native runtime status; older servers without it remain pending unless auth
185
+ is required. The status request omits resource catalogs with `toolsAndAuthOnly`.
186
+ It targets the workspace's most recently observed loaded chat, since an
187
+ app-scoped request can return null runtime states.
188
+ Full tool definitions are not carried into connector display rows. `codex_apps` branding
189
+ uses the dotted tool-name prefix; connector `_meta` is not forwarded.
190
+
191
+ ## Diagnostics and maintenance
192
+
193
+ 1. Inspect `/status` for the selected executable, process ids, and active turns.
194
+ Use `/dev/harness` or `GET /api/workspaces/:id/harness/debug` for the native
195
+ wire and display frames. `initialize.userAgent` identifies the running
196
+ version; `codex --version` only identifies what a new terminal process runs.
197
+ 2. For a picker mismatch, compare `model/list`, `config/read`, and the outgoing
198
+ `turn/start` model/effort/tier. For a run that stays busy, inspect lifecycle
199
+ frames and pending native input before assuming it is still generating.
200
+ 3. Update the selected standalone CLI with `codex update` when it supports that
201
+ command. Already-running app-servers keep the old executable until restarted;
202
+ let active chats finish before restarting them or the moi dev server.
203
+
204
+ Read-only standalone probes (run from the repo root):
205
+
206
+ ```sh
207
+ bun server/harness/codex/probe.ts models
208
+ bun server/harness/codex/probe.ts threads "$PWD"
209
+ bun server/harness/codex/probe.ts rpc "$PWD" config/read '{}'
35
210
  ```
36
211
 
37
- - Every `run()`/`runStreamed()` spawns `codex exec` (`resume <threadId>` after
38
- the first turn) and exits when the turn ends. Thread state persists in
39
- `~/.codex/sessions`; the in-memory `Thread` is just an id + options.
40
- - Because each turn is a new process, _every_ setting is effectively per-turn
41
- (`resumeThread(id, newOptions)`) — but there's also no live process to
42
- interrupt (`AbortSignal` kills it) or steer.
43
- - Events are **item-level**, not token-level: `thread.started`, `turn.started`,
44
- `item.started/updated/completed`, `turn.completed { usage }`, `turn.failed`.
45
- Item union: `agent_message`, `reasoning`, `command_execution` (aggregated
46
- output + exit code), `file_change` (patch summary), `mcp_tool_call`,
47
- `web_search`, `todo_list`, `error`.
48
- - Input: plain string or `{type:"text"}` / `{type:"local_image", path}` — no
49
- base64 image blocks; uploads must be materialized to disk (we already do
50
- this for OpenClaw).
51
- - No model list, no session list API, no MCP status probe, no approval
52
- callbacks. Structured output via `outputSchema` (JSON Schema/Zod) is the one
53
- feature CC lacks.
54
-
55
- Fine for CI-style one-shot runs; too thin for a moi chat harness.
56
-
57
- ## 2. The app-server (`codex app-server`)
58
-
59
- JSON-RPC 2.0 over **stdio** (newline-delimited JSON, `"jsonrpc"` header
60
- omitted — same transport style as a stdio MCP server). Other transports
61
- (unix socket, websocket) exist but stdio is the only production-supported one.
62
-
63
- ### Topology
64
-
65
- - **One process serves N threads in N different cwds.** `cwd` is per-thread
66
- (`thread/start`) and overridable per-turn. `thread/loaded/list` shows what's
67
- in memory; a thread with no subscribers and no activity for 30 min is
68
- unloaded (`thread/closed`). This replaces most of `claude-code/session.ts`'s
69
- eviction/idle-TTL machinery.
70
- - **Env vars are process-level.** There is no per-thread env injection, so
71
- moi's per-workspace `workspaceEnv` doesn't map onto a single shared process.
72
- Options: one app-server per workspace (env frozen at spawn, restart on env
73
- change — same semantics as `restartWorkspaceSessions`), or accept
74
- process-level env.
75
- - Handshake: one `initialize` request per connection (with `clientInfo`), then
76
- an `initialized` notification. Everything before that is rejected.
77
- - The wire carries three shapes the client must route: responses (matched by
78
- `id`), notifications, and **server-initiated requests** the client must
79
- answer (approvals, dynamic tool calls).
80
- - Backpressure: overload → error `-32001`, retry with backoff.
81
- - Crash recovery: respawn + `thread/resume` (threads persist in
82
- `~/.codex/sessions`).
83
-
84
- ### Core flow
212
+ The probe uses the invoking shell's PATH/environment, disables experimental
213
+ fields, and logs raw frames. Use the running moi wire tap to verify workspace
214
+ policy or actual UI behavior.
85
215
 
86
- ```
87
- thread/start | thread/resume | thread/fork → thread id, auto-subscribes
88
- turn/start { threadId, input, model?, effort?, outputSchema?, ... }
89
- ← turn/started
90
- ← item/started / item/*/delta / item/completed (per item)
91
- ← turn/completed { status: completed|interrupted|failed }
92
- turn/steer { expectedTurnId, input } — append input to the RUNNING turn
93
- turn/interrupt { threadId, turnId }
94
- ```
216
+ Wire types are a hand-written subset, read defensively. Generate reference
217
+ bindings into a temporary directory when changing the integration:
95
218
 
96
- Per-turn overrides (`model`, `effort`, `summary`, sandbox/approval policy)
97
- become the thread's defaults for later turns — no drain-then-rebuild dance at
98
- all. `thread/settings/update` queues setting changes without starting a turn.
99
-
100
- ### additionalContext (native per-turn ambient context)
101
-
102
- `turn/start` and `turn/steer` take an experimental
103
- `additionalContext: { <key>: { value, kind: 'untrusted' | 'application' } }`
104
- map (openai/codex#24154, shipped in 0.135.0, May 2026) — moi uses it for the
105
- `<moi-context>` envelope (key `moi-context`, kind `application`, so the wire
106
- tag matches the tag the moi-workspace skill triggers on):
107
-
108
- - `application` injects a developer-role message `<key>value</key>`;
109
- `untrusted` a user-role `<external_key>value</external_key>`. Values are
110
- middle-truncated to a ~1,000-token budget.
111
- - Send the map every turn; the server diffs per key and injects only when a
112
- value CHANGED since the last turn — unchanged keys cost nothing.
113
- - Injected fragments never appear as `userMessage` items (live or on
114
- `thread/read` replay), so nothing to strip.
115
- - Gated: requires `initialize.capabilities.experimentalApi: true`, else a
116
- new-enough server rejects the request when the field is present.
117
- - Servers < 0.135 have no `deny_unknown_fields` on TurnStartParams and
118
- silently DROP the field — no error to detect. The only reliable support
119
- signal is the version in the initialize response's `userAgent`
120
- (`codex_cli_rs/<semver> …`) — see `codexSupportsAdditionalContext`
121
- (client.ts). Below the cutoff the session path appends the envelope to the
122
- text item instead (adapter strips it from echoes).
123
-
124
- ### Feature map vs the adapter checklist
125
-
126
- - **Models**: `model/list` — models with ordered `supportedReasoningEfforts`,
127
- exactly what the picker needs.
128
- - **Streaming**: `item/agentMessage/delta`, `item/reasoning/summaryTextDelta`
129
- (+ raw `textDelta`), `item/commandExecution/outputDelta` (live command
130
- output — CC has no equivalent). Per-connection opt-out via
131
- `initialize.capabilities.optOutNotificationMethods`, so non-streaming mode
132
- is a handshake flag, not a session rebuild.
133
- - **Items**: `userMessage` (echoes our `clientUserMessageId` as `clientId` —
134
- native optimistic-id rendezvous), `agentMessage`, `reasoning`
135
- (summary vs raw content), `commandExecution` (cwd, exit code, duration),
136
- `fileChange` (structured per-file diffs), `mcpToolCall`, `collabToolCall`
137
- (subagents: spawn/send/wait/close), `webSearch`, `todoList`/`plan`
138
- (`turn/plan/updated`), `imageView`, `contextCompaction`, review items.
139
- Plus `turn/diff/updated` — an aggregated unified diff for the whole turn.
140
- - **Approvals**: interactive server→client JSON-RPC requests
141
- (`item/commandExecution/requestApproval`, `item/fileChange/requestApproval`,
142
- `item/permissions/requestApproval`) answered with
143
- `accept | acceptForSession | decline | cancel`. Or delegate with
144
- `approvalsReviewer: "auto_review"`. Sandbox modes / named permission
145
- profiles (`:read-only`, `:workspace`).
146
- - **Input**: `{type:"text"}`, `{type:"image", url:"data:..."}` (inline data
147
- URL — our base64 upload path works), `{type:"localImage", path}`, plus
148
- skill invocation items (`{type:"skill", name, path}`).
149
- - **History**: `thread/list` (cursor pagination, cwd filter, search),
150
- `thread/read` (without resuming), `thread/turns/list`, archive/unarchive/
151
- delete, `thread/name/set`. Replaces jsonl-scraping entirely.
152
- - **MCP**: `mcpServerStatus/list` (tools + auth status — our whole `mcp.ts`
153
- probe becomes one call), `mcpServer/oauth/login`, `config/mcpServer/reload`.
154
- - **Usage**: `thread/tokenUsage/updated` streamed live (restored on resume);
155
- `account/rateLimits/read` + `/updated`, `account/usage/read`.
156
- - **Errors**: typed `codexErrorInfo` enum (`ContextWindowExceeded`,
157
- `UsageLimitExceeded`, `HttpConnectionFailed{status}`, …).
158
- - **Auth**: `account/read`, `account/login/start` (API key / ChatGPT OAuth /
159
- device code), `account/updated` notifications.
160
- - **Extras with no CC equivalent**: `review/start` (built-in reviewer),
161
- `thread/shellCommand` (user `!` commands injected into the turn),
162
- `command/exec` / `process/spawn` (sandboxed/unsandboxed exec with PTY),
163
- `fs/*` + `fs/watch`, **dynamic client-provided tools** (`item/tool/call` —
164
- the agent calls back into moi), `thread/compact/start`, structured
165
- `outputSchema` per turn.
166
-
167
- ### Caveats
168
-
169
- - Much of the surface is gated behind `capabilities.experimentalApi` or marked
170
- under development (plugins, environments, realtime). The core
171
- thread/turn/item/approval/model surface is stable — it's what the VS Code
172
- extension runs on.
173
- - Typed bindings are generated, version-matched to the installed binary:
174
- `codex app-server generate-ts --out DIR` (or `generate-json-schema`).
175
-
176
- ### Binary availability
177
-
178
- The adapter resolves `codex` through `../executable.ts`: first a PATH lookup
179
- over the server's PATH merged with the user's login-shell PATH
180
- (`../shell-path.ts`), then the known macOS app-bundle locations —
181
- `/Applications/ChatGPT.app/Contents/Resources/codex` and the legacy
182
- `/Applications/Codex.app/Contents/Resources/codex` — since Codex Desktop
183
- manages an app-internal binary that is not shell-visible. PATH wins over the
184
- bundle probe, so a deliberately installed CLI is never shadowed. If nothing
185
- resolves, install the CLI with
186
- `curl -fsSL https://chatgpt.com/codex/install.sh | sh`.
187
-
188
- ## 3. Client libraries
189
-
190
- - **TypeScript: nothing official.** `@openai/codex-sdk` wraps exec only.
191
- - **Python: official** — `openai-codex` on PyPI (`sdk/python` in openai/codex)
192
- is a real app-server client: subprocess + stdio JSON-RPC, message router,
193
- generated pydantic models, approval handler callbacks. Good design
194
- reference.
195
- - Community TS/JS bridges exist (see the
196
- [`codex-app-server` GitHub topic](https://github.com/topics/codex-app-server))
197
- but are small/young.
198
- - **Plan for moi**: write the thin client ourselves (~200 lines in Bun — spawn,
199
- line-split stdio, id→promise map, notification + server-request routing;
200
- same pattern as `../openclaw/gateway.ts`) and use `generate-ts` for
201
- types.
202
-
203
- ## 4. Adapter shape
204
-
205
- A Codex harness would look much closer to `openclaw/session.ts` than
206
- `claude-code/session.ts`: one long-lived connection to a server that owns session
207
- lifecycle, subscribe per thread, map `item/*` notifications onto
208
- `StreamEvent`s. Capability flags: `liveSettingsPerTurn`, `steering`,
209
- `interactiveApprovals`, `nativeThreadList`, `imagesInline: 'data-url'`.
210
-
211
- ## 5. Implementation notes (shipped, CLI 0.144.5)
212
-
213
- The adapter landed as `client.ts` (process + stdio JSON-RPC client, one
214
- app-server per workspace for env injection), `adapter.ts` (item →
215
- `Turn` mapping, hand-written types), and `session.ts` (per-thread
216
- state, steer/interrupt, previews, usage). Empirical findings beyond §2:
217
-
218
- - **Always pass absolute `cwd`.** A relative `thread/start.cwd` is resolved
219
- against the app-server process cwd, silently nesting paths.
220
- - **Deltas stream by default** — no opt-in needed; moi's `stream` flag only
221
- gates forwarding them as preview frames.
222
- - **Reasoning summaries need `summary: "auto"` on `turn/start`.** Without it
223
- the model still reasons (nonzero `reasoningOutputTokens`) but the
224
- `reasoning` item arrives with EMPTY `summary`/`content` — thinking is
225
- invisible. With it, summaries stream via `item/reasoning/summaryTextDelta`
226
- and land populated. Also note reasoning is adaptive: trivial prompts at low
227
- effort legitimately produce no reasoning item at all.
228
- - **Subagents (collab tools) work unflagged**: the parent emits
229
- `collabAgentToolCall` (spawn/send/wait/close) and `subAgentActivity` items;
230
- the child agent runs as its own thread whose full item stream arrives on
231
- the same connection under `agentThreadId`.
232
- - **`clientUserMessageId` echo confirmed**: the `userMessage` item carries it
233
- as `clientId`, on live frames only. `thread/read` replay _renumbers_ item
234
- ids (`item-1`, `item-2`, …) and drops `clientId`, so replayed turn ids never
235
- match live ones — harmless under upsert-by-id, but don't key anything
236
- durable on them.
237
- - **`turn/completed` carries no items** (`itemsView: "notLoaded"`); items
238
- arrive only via `item/started`/`item/completed`.
239
- - **The npm `codex` bin is a Node shim** that spawns the platform binary;
240
- killing the shim tears down the server via stdin EOF, so no orphans. The
241
- absolute shim path returned by the PATH lookup is safe to spawn.
242
- - **Rollout files double as a discovery index.** Each thread persists to
243
- `~/.codex/sessions/YYYY/MM/DD/rollout-<timestamp>-<uuid>.jsonl` whose first
244
- line is a `session_meta` record with the thread's `cwd` (older formats put
245
- the meta fields at the top level). `discovery.ts` reads those heads directly
246
- — workspace discovery works without the binary installed.
247
- - **User-level config bleeds in**: threads start MCP servers and hooks from
248
- `~/.codex/config.toml` / `hooks.json` per thread; their failures arrive as
249
- notifications (`mcpServer/startupStatus/updated`, `hook/completed`) we
250
- currently ignore.
251
- - `thread/start` responses label threads `source: "vscode"` — app-server
252
- clients are indistinguishable from the VS Code extension in `thread/list`.
253
-
254
- ## 6. MCP servers & connectors (probed at CLI 0.144.5)
255
-
256
- One-off probe: `bun server/harness/codex/probe.ts rpc . mcpServerStatus/list '{}'`.
257
-
258
- ### `mcpServerStatus/list` payload
259
-
260
- `{ data: McpServerStatus[] }`, one entry per server Codex loaded:
261
-
262
- - `name` — the registry key (config.toml table name, or injected name).
263
- - `serverInfo` — the server's MCP `initialize` result (`name`, `title`,
264
- `version`, `description`, `icons`, `websiteUrl`), `null` if it never
265
- answered. A server can list with `serverInfo: null` and an empty `tools`
266
- map and still be "configured" — that's what a dead/misbehaving remote
267
- looks like (no error field).
268
- - `tools` — a **map keyed by tool name**, each value a full MCP tool def:
269
- `name`, `title`, `description`, `inputSchema`, `outputSchema`,
270
- `annotations` (`readOnlyHint`/`destructiveHint`/`openWorldHint`), `_meta`.
271
- This payload is BIG (~0.5 MB with ChatGPT connectors installed) — don't
272
- fold it into anything broadcast.
273
- - `resources`, `resourceTemplates` — arrays.
274
- - `authStatus` — `bearerToken` (authed HTTP/OAuth), `notLoggedIn` (OAuth
275
- awaiting `mcpServer/oauth/login`; the one `getCodexMcpStatus` maps to
276
- `needs-auth`), `unsupported` (stdio server, no auth concept).
277
-
278
- ### `codex_apps` — the ChatGPT connector aggregator
279
-
280
- Injected automatically when signed in with a ChatGPT account; **absent from
281
- config.toml**. `serverInfo.name` is `plugin-runtime`. It flattens every
282
- connector installed on the user's ChatGPT account (GitHub, Figma, Granola, …)
283
- into ONE server whose tool names are dotted `<connector>.<tool>`
284
- (`figma.generate_deck`). The true brand lives in each tool's `_meta`:
285
- `connector_id`, `connector_name` ("Figma"), `connector_description`,
286
- `link_id` (the user's authorization to that connector), plus Apps SDK widget
287
- hints (`openai/outputTemplate: "ui://widget/….html"`). This is why the
288
- client's `parseCodexMcp` brands dotted `codex_apps` calls by the prefix
289
- before the dot, not the server name. The adapter does not currently carry
290
- `_meta.connector_name` through to the `ToolCall` — icon/brand matching is
291
- name-based.
292
-
293
- ### Where MCP servers can be defined (config layers)
294
-
295
- From the 0.144.5 binary's config-layer enum, lowest to highest:
296
-
297
- 1. **User** — `$CODEX_HOME/config.toml` (`[mcp_servers.<name>]`). Shared by
298
- three writers: hand edits, `codex mcp add/remove`, and other apps (the
299
- ChatGPT desktop app writes `node_repl` / `computer-use` entries here).
300
- 2. **Profile v2** — `$CODEX_HOME/<name>.config.toml`, layered via `-p <name>`
301
- (legacy `[profiles.<name>]` tables in config.toml also exist).
302
- 3. **Project** — `.codex/config.toml` in a trusted repo ("sandbox, MCP,
303
- hooks, model, or reasoning defaults").
304
- 4. **Session flags** — `-c 'mcp_servers.foo.command="…"'` per invocation.
305
- 5. **Plugins** — an enabled plugin can provide MCP servers ("not configured
306
- in config.toml or an enabled plugin").
307
- 6. **Account-injected** — `codex_apps` (above); server-side, no local file.
308
- 7. **Admin layers** — system config.toml, MDM managed preferences, legacy
309
- `managed_config.toml`, and an enterprise-managed cloud layer;
310
- `requirements.toml` restricts (never defines) what the others may set.
311
-
312
- The app-server can also edit the user layer programmatically
313
- (`config/value/write`, `config/batchWrite`) — unused by moi.
314
-
315
- ### The full MCP RPC surface (from the 0.144.5 binary's method enums)
316
-
317
- Requests:
318
-
319
- - `mcpServerStatus/list` — the registry dump above.
320
- - `mcpServer/tool/call` — **direct one-off tool invocation, no model turn**:
321
- `{ threadId, server, tool, arguments }` → a raw MCP `CallToolResult`
322
- (`{ content: [...], isError }`). Requires a live `threadId` (MCP servers
323
- are started per thread), but `thread/start` + call works without ever
324
- running a turn — verified against `mastra_docs`. Argument validation
325
- errors come back as `isError: true` content, not JSON-RPC errors.
326
- - `mcpServer/resource/read` — read an MCP resource by uri.
327
- - `mcpServer/oauth/login` — start OAuth for a `notLoggedIn` server;
328
- completion arrives as the `mcpServer/oauthLogin/completed` notification.
329
- - `config/mcpServer/reload` — re-read server definitions without a restart.
330
- - `config/read`, `config/value/write`, `config/batchWrite`,
331
- `configRequirements/read` — inspect/edit the config layers that define
332
- servers.
333
-
334
- Notifications: `mcpServer/startupStatus/updated` (per-thread startup
335
- progress/failures — we currently ignore it), `mcpServer/oauthLogin/completed`,
336
- `item/mcpToolCall/progress` (progress of an in-turn MCP call).
337
-
338
- Server→client request: `mcpServer/elicitation/request` — an MCP server
339
- asking the user for input mid-call, forwarded for the client to answer.
340
-
341
- ## 7. Type maintenance (`generate-ts`)
342
-
343
- The wire types in `adapter.ts`/`client.ts` are a hand-written defensive
344
- subset of the protocol, produced against the bindings from:
345
-
346
- ```
347
- codex app-server generate-ts --out /tmp/codex-types # CLI 0.144.5
219
+ ```sh
220
+ codex app-server generate-ts --experimental --out /tmp/moi-codex-protocol
348
221
  ```
349
222
 
350
- They are deliberately NOT generated at build time: users run arbitrary codex
351
- CLI versions, so the runtime reads frames defensively regardless, and
352
- vendoring ~600 generated files (or generating in CI) would couple typecheck
353
- to an installed codex binary. When bumping the supported CLI version, re-run
354
- `generate-ts` into a scratch dir and diff the relevant definitions
355
- (`v2/ThreadItem`, `v2/TurnStartParams`, `ServerNotification`, `ServerRequest`)
356
- against the subset here.
223
+ Compare the relevant `ServerRequest`, `ServerNotification`, and `v2` types;
224
+ do not generate bindings during builds or require an installed CLI in CI.
225
+ Tests are colocated; run `bun test server/harness/codex` for the harness suite.
226
+ Protocol presence alone is not UI support: review/fork controls, account usage
227
+ limits, direct MCP operations, and general structured chat output are not
228
+ exposed by this harness.