farming-code 2.2.6

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 (453) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +287 -0
  3. package/README.zh_cn.md +329 -0
  4. package/SECURITY.md +29 -0
  5. package/THIRD_PARTY_NOTICES.md +106 -0
  6. package/backend/acp/client-services.js +312 -0
  7. package/backend/acp/patch-decisions.js +137 -0
  8. package/backend/acp/permission-security.js +108 -0
  9. package/backend/acp-runtime.js +1144 -0
  10. package/backend/acp-session-state.js +448 -0
  11. package/backend/acp-transcript.js +169 -0
  12. package/backend/agent-activity.js +186 -0
  13. package/backend/agent-env.js +250 -0
  14. package/backend/agent-json-stream.js +268 -0
  15. package/backend/agent-manager.js +4259 -0
  16. package/backend/agent-memory-report.js +583 -0
  17. package/backend/agent-order.js +162 -0
  18. package/backend/agent-provider-session.js +287 -0
  19. package/backend/agent-session-history.js +888 -0
  20. package/backend/app-server-api.js +917 -0
  21. package/backend/async-cache.js +94 -0
  22. package/backend/auth.js +178 -0
  23. package/backend/claude-settings.js +121 -0
  24. package/backend/cli-agents.js +484 -0
  25. package/backend/codex-app-server-home.js +39 -0
  26. package/backend/codex-app-server-runtime.js +901 -0
  27. package/backend/codex-context-window.js +189 -0
  28. package/backend/codex-models.js +229 -0
  29. package/backend/codex-rollout-follower.js +243 -0
  30. package/backend/codex-session-history.js +553 -0
  31. package/backend/codex-transcript-sanitizer.js +103 -0
  32. package/backend/codex-transcript.js +2341 -0
  33. package/backend/command-runner-child.js +67 -0
  34. package/backend/config-manager.js +815 -0
  35. package/backend/control-api.js +151 -0
  36. package/backend/data/chinese-poetic-words.json +8223 -0
  37. package/backend/data/poetic-word-sources/china.json +49209 -0
  38. package/backend/data/poetic-word-sources/india.json +9763 -0
  39. package/backend/data/poetic-word-sources/japan.json +8455 -0
  40. package/backend/executable-discovery.js +207 -0
  41. package/backend/farming-app-cli.js +790 -0
  42. package/backend/farming-cli.js +400 -0
  43. package/backend/farming-session-store.js +373 -0
  44. package/backend/haiku-token.js +772 -0
  45. package/backend/index-html.js +49 -0
  46. package/backend/input-parts.js +54 -0
  47. package/backend/input-routing.js +24 -0
  48. package/backend/json-cli-runtime.js +161 -0
  49. package/backend/local-session-engine.js +620 -0
  50. package/backend/main-agent-skills.js +292 -0
  51. package/backend/main-page-session.js +119 -0
  52. package/backend/native-pty-host-client.js +516 -0
  53. package/backend/native-pty-host-path.js +22 -0
  54. package/backend/native-pty-host.js +816 -0
  55. package/backend/native-session-engine.js +196 -0
  56. package/backend/network.js +23 -0
  57. package/backend/npm-update-helper.js +196 -0
  58. package/backend/packaged-node-pty.js +79 -0
  59. package/backend/provider-session-id.js +47 -0
  60. package/backend/qr-share-tickets.js +100 -0
  61. package/backend/review-diff-router.js +180 -0
  62. package/backend/review-diff-service.js +1270 -0
  63. package/backend/review-session-router.js +74 -0
  64. package/backend/review-session-service.js +432 -0
  65. package/backend/review-session-store.js +144 -0
  66. package/backend/review-state-router.js +116 -0
  67. package/backend/review-state-store.js +287 -0
  68. package/backend/run-history-store.js +70 -0
  69. package/backend/server.js +2446 -0
  70. package/backend/session-engine-bridge.js +110 -0
  71. package/backend/session-engine-router.js +66 -0
  72. package/backend/session-engine.js +39 -0
  73. package/backend/shell-busy-integration.js +472 -0
  74. package/backend/slash-command-discovery.js +296 -0
  75. package/backend/storage-layout.js +101 -0
  76. package/backend/system-monitor.js +77 -0
  77. package/backend/terminal-runtime-cleanup.js +80 -0
  78. package/backend/terminal-screen-state.js +240 -0
  79. package/backend/terminal-screen-worker-pool.js +165 -0
  80. package/backend/terminal-screen-worker-thread.js +161 -0
  81. package/backend/terminal-screen-worker.js +255 -0
  82. package/backend/terminal-status.js +356 -0
  83. package/backend/theme-manager.js +145 -0
  84. package/backend/update-service.js +1183 -0
  85. package/backend/usage-forecast.js +86 -0
  86. package/backend/usage-monitor.js +1357 -0
  87. package/backend/workspace-discovery.js +311 -0
  88. package/backend/workspace-file-router.js +431 -0
  89. package/backend/workspace-file-service.js +2765 -0
  90. package/bin/farming +5 -0
  91. package/config/farming.deploy.env.example +13 -0
  92. package/config/farming.install.env.example +17 -0
  93. package/dist/assets/App-BrP-ENHg.css +1 -0
  94. package/dist/assets/App-Dza5yEDe.js +124 -0
  95. package/dist/assets/FileEditorMarkdownPreview-DRDNQ8mX.css +1 -0
  96. package/dist/assets/FileEditorMarkdownPreview-elKWc8Im.js +404 -0
  97. package/dist/assets/FileEditorPane-BQLocXOp.js +5 -0
  98. package/dist/assets/IconGlyphs-RkMAdBXF.js +1 -0
  99. package/dist/assets/KaTeX_AMS-Regular-BQhdFMY1.woff2 +0 -0
  100. package/dist/assets/KaTeX_AMS-Regular-DMm9YOAa.woff +0 -0
  101. package/dist/assets/KaTeX_AMS-Regular-DRggAlZN.ttf +0 -0
  102. package/dist/assets/KaTeX_Caligraphic-Bold-ATXxdsX0.ttf +0 -0
  103. package/dist/assets/KaTeX_Caligraphic-Bold-BEiXGLvX.woff +0 -0
  104. package/dist/assets/KaTeX_Caligraphic-Bold-Dq_IR9rO.woff2 +0 -0
  105. package/dist/assets/KaTeX_Caligraphic-Regular-CTRA-rTL.woff +0 -0
  106. package/dist/assets/KaTeX_Caligraphic-Regular-Di6jR-x-.woff2 +0 -0
  107. package/dist/assets/KaTeX_Caligraphic-Regular-wX97UBjC.ttf +0 -0
  108. package/dist/assets/KaTeX_Fraktur-Bold-BdnERNNW.ttf +0 -0
  109. package/dist/assets/KaTeX_Fraktur-Bold-BsDP51OF.woff +0 -0
  110. package/dist/assets/KaTeX_Fraktur-Bold-CL6g_b3V.woff2 +0 -0
  111. package/dist/assets/KaTeX_Fraktur-Regular-CB_wures.ttf +0 -0
  112. package/dist/assets/KaTeX_Fraktur-Regular-CTYiF6lA.woff2 +0 -0
  113. package/dist/assets/KaTeX_Fraktur-Regular-Dxdc4cR9.woff +0 -0
  114. package/dist/assets/KaTeX_Main-Bold-Cx986IdX.woff2 +0 -0
  115. package/dist/assets/KaTeX_Main-Bold-Jm3AIy58.woff +0 -0
  116. package/dist/assets/KaTeX_Main-Bold-waoOVXN0.ttf +0 -0
  117. package/dist/assets/KaTeX_Main-BoldItalic-DxDJ3AOS.woff2 +0 -0
  118. package/dist/assets/KaTeX_Main-BoldItalic-DzxPMmG6.ttf +0 -0
  119. package/dist/assets/KaTeX_Main-BoldItalic-SpSLRI95.woff +0 -0
  120. package/dist/assets/KaTeX_Main-Italic-3WenGoN9.ttf +0 -0
  121. package/dist/assets/KaTeX_Main-Italic-BMLOBm91.woff +0 -0
  122. package/dist/assets/KaTeX_Main-Italic-NWA7e6Wa.woff2 +0 -0
  123. package/dist/assets/KaTeX_Main-Regular-B22Nviop.woff2 +0 -0
  124. package/dist/assets/KaTeX_Main-Regular-Dr94JaBh.woff +0 -0
  125. package/dist/assets/KaTeX_Main-Regular-ypZvNtVU.ttf +0 -0
  126. package/dist/assets/KaTeX_Math-BoldItalic-B3XSjfu4.ttf +0 -0
  127. package/dist/assets/KaTeX_Math-BoldItalic-CZnvNsCZ.woff2 +0 -0
  128. package/dist/assets/KaTeX_Math-BoldItalic-iY-2wyZ7.woff +0 -0
  129. package/dist/assets/KaTeX_Math-Italic-DA0__PXp.woff +0 -0
  130. package/dist/assets/KaTeX_Math-Italic-flOr_0UB.ttf +0 -0
  131. package/dist/assets/KaTeX_Math-Italic-t53AETM-.woff2 +0 -0
  132. package/dist/assets/KaTeX_SansSerif-Bold-CFMepnvq.ttf +0 -0
  133. package/dist/assets/KaTeX_SansSerif-Bold-D1sUS0GD.woff2 +0 -0
  134. package/dist/assets/KaTeX_SansSerif-Bold-DbIhKOiC.woff +0 -0
  135. package/dist/assets/KaTeX_SansSerif-Italic-C3H0VqGB.woff2 +0 -0
  136. package/dist/assets/KaTeX_SansSerif-Italic-DN2j7dab.woff +0 -0
  137. package/dist/assets/KaTeX_SansSerif-Italic-YYjJ1zSn.ttf +0 -0
  138. package/dist/assets/KaTeX_SansSerif-Regular-BNo7hRIc.ttf +0 -0
  139. package/dist/assets/KaTeX_SansSerif-Regular-CS6fqUqJ.woff +0 -0
  140. package/dist/assets/KaTeX_SansSerif-Regular-DDBCnlJ7.woff2 +0 -0
  141. package/dist/assets/KaTeX_Script-Regular-C5JkGWo-.ttf +0 -0
  142. package/dist/assets/KaTeX_Script-Regular-D3wIWfF6.woff2 +0 -0
  143. package/dist/assets/KaTeX_Script-Regular-D5yQViql.woff +0 -0
  144. package/dist/assets/KaTeX_Size1-Regular-C195tn64.woff +0 -0
  145. package/dist/assets/KaTeX_Size1-Regular-Dbsnue_I.ttf +0 -0
  146. package/dist/assets/KaTeX_Size1-Regular-mCD8mA8B.woff2 +0 -0
  147. package/dist/assets/KaTeX_Size2-Regular-B7gKUWhC.ttf +0 -0
  148. package/dist/assets/KaTeX_Size2-Regular-Dy4dx90m.woff2 +0 -0
  149. package/dist/assets/KaTeX_Size2-Regular-oD1tc_U0.woff +0 -0
  150. package/dist/assets/KaTeX_Size3-Regular-CTq5MqoE.woff +0 -0
  151. package/dist/assets/KaTeX_Size3-Regular-DgpXs0kz.ttf +0 -0
  152. package/dist/assets/KaTeX_Size4-Regular-BF-4gkZK.woff +0 -0
  153. package/dist/assets/KaTeX_Size4-Regular-DWFBv043.ttf +0 -0
  154. package/dist/assets/KaTeX_Size4-Regular-Dl5lxZxV.woff2 +0 -0
  155. package/dist/assets/KaTeX_Typewriter-Regular-C0xS9mPB.woff +0 -0
  156. package/dist/assets/KaTeX_Typewriter-Regular-CO6r4hn1.woff2 +0 -0
  157. package/dist/assets/KaTeX_Typewriter-Regular-D3Ib7_Hf.ttf +0 -0
  158. package/dist/assets/ProjectFilesSection-lS1azbgj.js +12 -0
  159. package/dist/assets/ReviewPage-DgnmgU2T.js +3 -0
  160. package/dist/assets/abap-Cc5D5h5i.js +1 -0
  161. package/dist/assets/abnfDiagram-VRR7QNED-BgawzDQT.js +1 -0
  162. package/dist/assets/apex-BKopwLmx.js +1 -0
  163. package/dist/assets/api-D1lyBYIQ.js +1 -0
  164. package/dist/assets/arc-CWoVlxJw.js +1 -0
  165. package/dist/assets/architecture-TIHT7OUA-CbJBFh3w.js +1 -0
  166. package/dist/assets/architectureDiagram-ZJ3FMSHR-DUShwPg0.js +36 -0
  167. package/dist/assets/array-HeX70jSN.js +1 -0
  168. package/dist/assets/azcli-DI-C34WA.js +1 -0
  169. package/dist/assets/bat-Cbp6u42z.js +1 -0
  170. package/dist/assets/bicep-4QA1jTCM.js +2 -0
  171. package/dist/assets/blockDiagram-677ZJIJ3-CeGZviXR.js +132 -0
  172. package/dist/assets/c4Diagram-LMCZKHZV-CLhYht6S.js +10 -0
  173. package/dist/assets/cameligo-Dda_adPs.js +1 -0
  174. package/dist/assets/channel-Uw90AO0b.js +1 -0
  175. package/dist/assets/chunk-2Q5K7J3B-d5WWh8jo.js +1 -0
  176. package/dist/assets/chunk-32BRIVSS-LFYpT-Cu.js +1 -0
  177. package/dist/assets/chunk-52WLFC77-BH6jDw9J.js +10 -0
  178. package/dist/assets/chunk-5FCAYU7R-C7AmIhYv.js +1 -0
  179. package/dist/assets/chunk-5HE753X5-C8cXaouP.js +1 -0
  180. package/dist/assets/chunk-5JV3BV7I-C1PtimcA.js +1 -0
  181. package/dist/assets/chunk-5TONJI2A-_81zUME8.js +2 -0
  182. package/dist/assets/chunk-5VM5RSS4-Dlw7AXWp.js +15 -0
  183. package/dist/assets/chunk-7BUUIJ7U-ZBRhjLOh.js +1 -0
  184. package/dist/assets/chunk-BIQX33UG-CWmzxeAw.js +1 -0
  185. package/dist/assets/chunk-C7G6YPKG-B_mIUlb7.js +1 -0
  186. package/dist/assets/chunk-CQNSW5MT-CMayolwI.js +1 -0
  187. package/dist/assets/chunk-CYSBUYHQ-lSPbrL3Z.js +1 -0
  188. package/dist/assets/chunk-DECur_0Z.js +1 -0
  189. package/dist/assets/chunk-EMLP6XTP-D9-jtCnM.js +1 -0
  190. package/dist/assets/chunk-EX3LRPZG-C63hVuAJ.js +231 -0
  191. package/dist/assets/chunk-FWX5IMBZ-CboX-WF_.js +2 -0
  192. package/dist/assets/chunk-HOUHSVGY-BOgSd6Un.js +1 -0
  193. package/dist/assets/chunk-ICXQ74PX-C0K-pgZt.js +2 -0
  194. package/dist/assets/chunk-JG7HCLWE-Cib606u_.js +2 -0
  195. package/dist/assets/chunk-JWPE2WC7-DSyBRaRG.js +1 -0
  196. package/dist/assets/chunk-KEIR6QF5-CNOHik0T.js +161 -0
  197. package/dist/assets/chunk-MOJQB5TN-CVMfwN_7.js +88 -0
  198. package/dist/assets/chunk-MOZMSUNE-D6JeZqmE.js +1 -0
  199. package/dist/assets/chunk-OGEWGWER-DLT3pxyw.js +1 -0
  200. package/dist/assets/chunk-OSBZ3O6U-C0W8KSeg.js +1 -0
  201. package/dist/assets/chunk-PUDLZKDR-Cd079yIQ.js +156 -0
  202. package/dist/assets/chunk-Q4XR5HBZ-D0jHa6SO.js +70 -0
  203. package/dist/assets/chunk-QBLGF6JB-p4omp7uO.js +1 -0
  204. package/dist/assets/chunk-R7FJI6CG-CZ_p9hSr.js +1 -0
  205. package/dist/assets/chunk-RYQCIY6F-CZA9pvFX.js +1 -0
  206. package/dist/assets/chunk-U6XO7XAA-CcXKsWxp.js +2 -0
  207. package/dist/assets/chunk-V7JOEXUC-CVDtR75H.js +206 -0
  208. package/dist/assets/chunk-VAUOI2AC-B-W2_9Ot.js +1 -0
  209. package/dist/assets/chunk-VR4S4FIN-FD3kWh32.js +1 -0
  210. package/dist/assets/chunk-WYO6CB5R-C2bGaS5r.js +127 -0
  211. package/dist/assets/chunk-XXDRQBXY-BBXwjhUx.js +1 -0
  212. package/dist/assets/chunk-Y2CYZVJY-Di0sYzi1.js +1 -0
  213. package/dist/assets/chunk-YOTPTUD7-BXHmEk89.js +1 -0
  214. package/dist/assets/chunk-ZGVPDNZ5-ymgts0zo.js +62 -0
  215. package/dist/assets/chunk-ZIRB5QZD-DncwlQQc.js +32 -0
  216. package/dist/assets/classDiagram-OUVF2IWQ-DKW_dtku.js +1 -0
  217. package/dist/assets/classDiagram-v2-EOCWNBFH-C8Fi7-yv.js +1 -0
  218. package/dist/assets/clojure-CvY8A83L.js +1 -0
  219. package/dist/assets/code-dark-Cjb1QGhu.css +1 -0
  220. package/dist/assets/code-mobile-3C2Rr-CN.css +1 -0
  221. package/dist/assets/codicon-ngg6Pgfi.ttf +0 -0
  222. package/dist/assets/coffee-4LX2Sv8A.js +1 -0
  223. package/dist/assets/core-ZlAPicox.js +3 -0
  224. package/dist/assets/cose-bilkent-JH36ORCC-BNIAz0nN.js +1 -0
  225. package/dist/assets/cpp-D4AzSV28.js +1 -0
  226. package/dist/assets/csharp-C4nWN4Yd.js +1 -0
  227. package/dist/assets/csp-CiEaaS5Z.js +1 -0
  228. package/dist/assets/css-DXxBRsbk.js +3 -0
  229. package/dist/assets/css.worker-DyDu5ynT.js +89 -0
  230. package/dist/assets/cssMode-DDWxTPm_.js +1 -0
  231. package/dist/assets/cynefin-VYW2F7L2-DgXGHlRt.js +1 -0
  232. package/dist/assets/cynefinDiagram-TSTJHNR4-CwpobXIl.js +62 -0
  233. package/dist/assets/cypher-DOMzqyFA.js +1 -0
  234. package/dist/assets/cytoscape.esm-Cl8iC3D7.js +321 -0
  235. package/dist/assets/dagre-DXlcHgr3.js +1 -0
  236. package/dist/assets/dagre-VKFMJZFB-Dkhlfjna.js +4 -0
  237. package/dist/assets/dart-BWS7MXt_.js +1 -0
  238. package/dist/assets/defaultLocale-GJwWH1Jr.js +1 -0
  239. package/dist/assets/diagram-FQU43EPY-hA8dicp6.js +3 -0
  240. package/dist/assets/diagram-G47NLZAW-BTY6JTzO.js +24 -0
  241. package/dist/assets/diagram-NH7WQ7WH-xkaHHX9M.js +24 -0
  242. package/dist/assets/diagram-OA4YK3LP-gk_fg9UU.js +30 -0
  243. package/dist/assets/diagram-WEI45ONY-BvC8xd6T.js +41 -0
  244. package/dist/assets/dist-ClAL-Tv5.js +1 -0
  245. package/dist/assets/dockerfile-Baf4U3xT.js +1 -0
  246. package/dist/assets/ebnfDiagram-CCIWWBDH-CR7RaNat.js +1 -0
  247. package/dist/assets/ecl-CT7udlkQ.js +1 -0
  248. package/dist/assets/editor-CtbFZlk0.css +1 -0
  249. package/dist/assets/editor.api2-B9h6iFPK.js +872 -0
  250. package/dist/assets/editor.worker-Dpt_xPrs.js +26 -0
  251. package/dist/assets/elixir-CIbAZw5l.js +1 -0
  252. package/dist/assets/erDiagram-Q63AITRT-_M-JFPbj.js +85 -0
  253. package/dist/assets/eventmodeling-45OFAUF4-DXYTQ2nt.js +1 -0
  254. package/dist/assets/file-icons-EFUGSSwf.js +1 -0
  255. package/dist/assets/flow9-Dqiw45WV.js +1 -0
  256. package/dist/assets/flowDiagram-23GEKE2U-DAiS5Y7G.js +1 -0
  257. package/dist/assets/freemarker2-QBsTERH-.js +3 -0
  258. package/dist/assets/fsharp-E8E2L9jU.js +1 -0
  259. package/dist/assets/ganttDiagram-NO4QXBWP-Bl8P1yf_.js +292 -0
  260. package/dist/assets/gitGraph-TEB2WS4Q-CzTBjEvV.js +1 -0
  261. package/dist/assets/gitGraphDiagram-IHSO6WYX-DoHa5ysz.js +106 -0
  262. package/dist/assets/go-CouVSN4D.js +1 -0
  263. package/dist/assets/graphlib-CbSvZcZU.js +1 -0
  264. package/dist/assets/graphql-a6h6h5-t.js +1 -0
  265. package/dist/assets/handlebars-CuoxPo5A.js +1 -0
  266. package/dist/assets/hcl-vso3e6N-.js +1 -0
  267. package/dist/assets/html-gX5PEu0Q.js +1 -0
  268. package/dist/assets/html.worker-IWNXhnIC.js +502 -0
  269. package/dist/assets/htmlMode-DIWUbUxd.js +1 -0
  270. package/dist/assets/index-BpHPeJf0.js +10 -0
  271. package/dist/assets/info-DKCQHKI2-DznP7j3s.js +1 -0
  272. package/dist/assets/infoDiagram-FWYZ7A6U-DSFcSuUs.js +2 -0
  273. package/dist/assets/ini-SwZZkotR.js +1 -0
  274. package/dist/assets/init-BPLPMQ3Y.js +1 -0
  275. package/dist/assets/ishikawaDiagram-FXEZZL3T-DdkqullI.js +70 -0
  276. package/dist/assets/java-CtRLC4_3.js +1 -0
  277. package/dist/assets/javascript-BYKGIUGs.js +1 -0
  278. package/dist/assets/journeyDiagram-5HDEW3XC-B4hRnQJr.js +139 -0
  279. package/dist/assets/json.worker-c4h5s80L.js +58 -0
  280. package/dist/assets/jsonMode-AFmQQP6u.js +7 -0
  281. package/dist/assets/jsx-runtime-BthL93pI.js +1 -0
  282. package/dist/assets/julia-CuJWFKQH.js +1 -0
  283. package/dist/assets/kanban-definition-HUTT4EX6-tm2FZB2E.js +89 -0
  284. package/dist/assets/katex-C8DPyI6s.js +257 -0
  285. package/dist/assets/kotlin-B_kBhsre.js +1 -0
  286. package/dist/assets/less-CtrHIfz3.js +2 -0
  287. package/dist/assets/lexon-yVt1pJLu.js +1 -0
  288. package/dist/assets/line-CmsjK4kn.js +1 -0
  289. package/dist/assets/linear-Dld3_ERu.js +1 -0
  290. package/dist/assets/liquid-DBIl-f0z.js +1 -0
  291. package/dist/assets/lspLanguageFeatures-DK6tqicV.js +4 -0
  292. package/dist/assets/lua-prOwgJ4U.js +1 -0
  293. package/dist/assets/m3-DhrdTQ84.js +1 -0
  294. package/dist/assets/main-DTJwH51M.css +1 -0
  295. package/dist/assets/map-LZWWoeWa.js +1 -0
  296. package/dist/assets/markdown-DoI5HwSM.js +1 -0
  297. package/dist/assets/mdx-DS-bVtZN.js +1 -0
  298. package/dist/assets/mermaid-parser.core-BQtepoLd.js +4 -0
  299. package/dist/assets/mermaid.core-C7UT_EEL.js +11 -0
  300. package/dist/assets/mindmap-definition-LN4V7U3C-DplfjGms.js +96 -0
  301. package/dist/assets/mips-Dye5jsBU.js +1 -0
  302. package/dist/assets/monaco.contribution-CyLosfZI.js +2 -0
  303. package/dist/assets/msdax-TkNOyIL8.js +1 -0
  304. package/dist/assets/mysql-CEc-RKZF.js +1 -0
  305. package/dist/assets/objective-c-CqqCsQz0.js +1 -0
  306. package/dist/assets/ordinal-BLrOss5K.js +1 -0
  307. package/dist/assets/packet-7NZHBO7P-BDEPOPha.js +1 -0
  308. package/dist/assets/pascal-DO_pj8yg.js +1 -0
  309. package/dist/assets/pascaligo-1cbdZdF3.js +1 -0
  310. package/dist/assets/path-YdFzr2W6.js +1 -0
  311. package/dist/assets/pegDiagram-2B236MQR-lu3SdkQs.js +1 -0
  312. package/dist/assets/perl-B_N3PYfC.js +1 -0
  313. package/dist/assets/pgsql-9iYk1FQ7.js +1 -0
  314. package/dist/assets/php-rO2sgoUM.js +1 -0
  315. package/dist/assets/pie-RZYD4A2V-DWIrwPJQ.js +1 -0
  316. package/dist/assets/pieDiagram-ENE6RG2P-3fHbmDf9.js +39 -0
  317. package/dist/assets/pla-Cbgv60kq.js +1 -0
  318. package/dist/assets/postiats-y6xrhy_M.js +1 -0
  319. package/dist/assets/powerquery-BaD8gWNE.js +1 -0
  320. package/dist/assets/powershell-BMhG4JVe.js +1 -0
  321. package/dist/assets/preload-helper-mJowh_hw.js +1 -0
  322. package/dist/assets/protobuf-CdOP5kN3.js +2 -0
  323. package/dist/assets/pug-Ck60hNF9.js +1 -0
  324. package/dist/assets/python-C93q3xXz.js +1 -0
  325. package/dist/assets/qoder-C9LmmOSf.svg +1 -0
  326. package/dist/assets/qoder-Cf9gl0Y5.svg +1 -0
  327. package/dist/assets/qoder-gHCinseV.svg +1 -0
  328. package/dist/assets/qrcode-DV-_rjU8.js +3 -0
  329. package/dist/assets/qsharp-BcaKFfP-.js +1 -0
  330. package/dist/assets/quadrantDiagram-ABIIQ3AL-a5qoWz-X.js +7 -0
  331. package/dist/assets/r-rFNes0iK.js +1 -0
  332. package/dist/assets/radar-I7S5WNFK-B7OaD8vp.js +1 -0
  333. package/dist/assets/railroad-3IZDKUUU-BXW2nuCA.js +1 -0
  334. package/dist/assets/railroad-abnf-AHOZXSZD-Buw9QG2r.js +1 -0
  335. package/dist/assets/railroad-ebnf-EBAXGLYW-BjSi4sWJ.js +1 -0
  336. package/dist/assets/railroad-peg-LSFZ7HO6-DN1wIVhS.js +1 -0
  337. package/dist/assets/railroadDiagram-RFXS5EU6-D2TOuXW9.js +1 -0
  338. package/dist/assets/razor-CBifNGXO.js +1 -0
  339. package/dist/assets/react-dom-gtU6X-Hj.js +1 -0
  340. package/dist/assets/redis-DkpQ3K6G.js +1 -0
  341. package/dist/assets/redshift-Di9N5TI3.js +1 -0
  342. package/dist/assets/requirementDiagram-TGXJPOKE-LQBWpUvd.js +84 -0
  343. package/dist/assets/restructuredtext-By5ZzLt6.js +1 -0
  344. package/dist/assets/review-BcnwQtJv.css +1 -0
  345. package/dist/assets/rough.esm-c4PR5shF.js +1 -0
  346. package/dist/assets/ruby-fF5zGiLp.js +1 -0
  347. package/dist/assets/rust-C5b3AYY6.js +1 -0
  348. package/dist/assets/sankeyDiagram-HTMAVEWB-B1ohYoyK.js +40 -0
  349. package/dist/assets/sb-CD07UNRs.js +1 -0
  350. package/dist/assets/scala-jtn1ip9G.js +1 -0
  351. package/dist/assets/scheme-C4vqMkn_.js +1 -0
  352. package/dist/assets/scss-I4Glxjbz.js +3 -0
  353. package/dist/assets/sequenceDiagram-DBY2YBRQ-C3vM-hMq.js +162 -0
  354. package/dist/assets/shell-DubUcuns.js +1 -0
  355. package/dist/assets/sizeCapture-X5ZJPWSS-daTB6OcF.js +1 -0
  356. package/dist/assets/solidity-CNy2KSl2.js +1 -0
  357. package/dist/assets/sophia-D9_URt84.js +1 -0
  358. package/dist/assets/sparql-DviXpm4C.js +1 -0
  359. package/dist/assets/sql-vDRbAZgK.js +1 -0
  360. package/dist/assets/src-WBW1QxJt.js +1 -0
  361. package/dist/assets/st-CnpnRqA7.js +1 -0
  362. package/dist/assets/stateDiagram-2N3HPSRC-BvFhOryI.js +1 -0
  363. package/dist/assets/stateDiagram-v2-6OUMAXLB-WMrz4PNo.js +1 -0
  364. package/dist/assets/swift-D_g8Ganz.js +1 -0
  365. package/dist/assets/swimlanes-5IMT3BWC-DKF_b-2s.js +2 -0
  366. package/dist/assets/swimlanesDiagram-G3AALYLV-BGswC9oC.js +8 -0
  367. package/dist/assets/systemverilog-OuZa5h1M.js +1 -0
  368. package/dist/assets/tcl-DBm9ucsV.js +1 -0
  369. package/dist/assets/timeline-definition-FHXFAJF6-vAs11ux_.js +120 -0
  370. package/dist/assets/tokens-BwenNn5Q.css +1 -0
  371. package/dist/assets/treeView-QDETBFTQ-BVfICaZQ.js +1 -0
  372. package/dist/assets/treemap-6X3UGDF4-oWHPqo17.js +1 -0
  373. package/dist/assets/ts.worker-BwM5Ha3L.js +67719 -0
  374. package/dist/assets/tsMode-DGZTlTj8.js +11 -0
  375. package/dist/assets/twig-BRzEqX5Y.js +1 -0
  376. package/dist/assets/typescript-KJKfYO7K.js +1 -0
  377. package/dist/assets/typespec-D4ZgGeX8.js +1 -0
  378. package/dist/assets/useWorkspaceMenuKeyboard-CneKAZUJ.js +1 -0
  379. package/dist/assets/vb-DcP4s6WS.js +1 -0
  380. package/dist/assets/vennDiagram-L72KCM5P-BybTX_9B.js +34 -0
  381. package/dist/assets/wardley-OPB4EBWU-Dg8t5y3s.js +1 -0
  382. package/dist/assets/wardleyDiagram-EHGQE667-CicUmMBR.js +78 -0
  383. package/dist/assets/wgsl-CnRJ_QUf.js +298 -0
  384. package/dist/assets/workers-BSQRIkqa.js +1 -0
  385. package/dist/assets/workspace-view-state-CTyDzk2D.js +1 -0
  386. package/dist/assets/xml-C8FAcN6j.js +1 -0
  387. package/dist/assets/xychartDiagram-FW5EYKEG-BhWDyCX-.js +7 -0
  388. package/dist/assets/yaml-BQ4NrRhG.js +1 -0
  389. package/dist/assets/zsh-CLpveKlF.svg +1 -0
  390. package/dist/assets/zsh-FxSpMPbz.svg +1 -0
  391. package/dist/farming-2/app-icon-v2-180.png +0 -0
  392. package/dist/farming-2/app-icon-v2-192.png +0 -0
  393. package/dist/farming-2/app-icon-v2-512.png +0 -0
  394. package/dist/farming-2/app-icon-v2-maskable-512.png +0 -0
  395. package/dist/farming-2/app-icon-v2-master.png +0 -0
  396. package/dist/farming-2/favicon-v2-16.png +0 -0
  397. package/dist/farming-2/favicon-v2-32.png +0 -0
  398. package/dist/farming-2/favicon-v2-48.png +0 -0
  399. package/dist/farming-2/favicon-v2-64.png +0 -0
  400. package/dist/farming-2/favicon-v2.ico +0 -0
  401. package/dist/farming-2/favicon.ico +0 -0
  402. package/dist/farming-2/github-social-preview.png +0 -0
  403. package/dist/farming-2/images/avatar-watercolor-v1-bee-garden.png +0 -0
  404. package/dist/farming-2/images/avatar-watercolor-v2.png +0 -0
  405. package/dist/farming-2/images/avatar-watercolor-v3.png +0 -0
  406. package/dist/farming-2/legacy-icons-v1/favicon.ico +1 -0
  407. package/dist/farming-2/legacy-icons-v1/logo-16.png +0 -0
  408. package/dist/farming-2/legacy-icons-v1/logo-180.png +0 -0
  409. package/dist/farming-2/legacy-icons-v1/logo-192.png +0 -0
  410. package/dist/farming-2/legacy-icons-v1/logo-32.png +0 -0
  411. package/dist/farming-2/legacy-icons-v1/logo-48.png +0 -0
  412. package/dist/farming-2/legacy-icons-v1/logo-512.png +0 -0
  413. package/dist/farming-2/legacy-icons-v1/logo-64.png +0 -0
  414. package/dist/farming-2/logo-16.png +0 -0
  415. package/dist/farming-2/logo-180.png +0 -0
  416. package/dist/farming-2/logo-192.png +0 -0
  417. package/dist/farming-2/logo-32.png +0 -0
  418. package/dist/farming-2/logo-48.png +0 -0
  419. package/dist/farming-2/logo-512.png +0 -0
  420. package/dist/farming-2/logo-64.png +0 -0
  421. package/dist/farming-2/site.webmanifest +27 -0
  422. package/dist/farming-2/style_capsules/watercolor-pastoral.json +94 -0
  423. package/dist/index.html +27 -0
  424. package/frontend/ghostty-loader.js +24 -0
  425. package/frontend/runtime-paths.js +28 -0
  426. package/frontend/session-bridge.js +82 -0
  427. package/frontend/session-modal-bridge.js +331 -0
  428. package/frontend/skin-bridge.js +25 -0
  429. package/frontend/skins/crt/app.js +6940 -0
  430. package/frontend/skins/crt/assets/branding/farming-crt-icon.svg +11 -0
  431. package/frontend/skins/crt/assets/branding/farming-crt-logo-v1.png +0 -0
  432. package/frontend/skins/crt/assets/effects/phosphor-noise.svg +11 -0
  433. package/frontend/skins/crt/assets/fonts/departure-mono/DepartureMonoNerdFontMono-Regular.otf +0 -0
  434. package/frontend/skins/crt/assets/fonts/departure-mono/LICENSE +93 -0
  435. package/frontend/skins/crt/effects.js +8 -0
  436. package/frontend/skins/crt/index.html +1712 -0
  437. package/frontend/skins/crt/styles/billing.css +1003 -0
  438. package/frontend/skins/crt/styles/effects.css +171 -0
  439. package/frontend/skins/crt/styles/history.css +215 -0
  440. package/frontend/skins/crt/styles/monochrome-green.css +509 -0
  441. package/frontend/skins/crt/styles/search.css +271 -0
  442. package/frontend/terminal-bridge.js +192 -0
  443. package/frontend/theme-loader.js +84 -0
  444. package/frontend/themes/terminal/theme.json +24 -0
  445. package/frontend/vendor/ghostty-web/LICENSE +21 -0
  446. package/frontend/vendor/ghostty-web/__vite-browser-external-2447137e.js +4 -0
  447. package/frontend/vendor/ghostty-web/ghostty-vt.wasm +0 -0
  448. package/frontend/vendor/ghostty-web/ghostty-web.js +2963 -0
  449. package/frontend/vendor/ghostty-web/ghostty-web.umd.cjs +13 -0
  450. package/frontend/vendor/ghostty-web/index.d.ts +1842 -0
  451. package/index.html +23 -0
  452. package/package.json +144 -0
  453. package/scripts/sync-ghostty-vendor.js +66 -0
@@ -0,0 +1,917 @@
1
+ const express = require('express');
2
+ const crypto = require('crypto');
3
+ const path = require('path');
4
+ const WebSocket = require('ws');
5
+ const packageJson = require('../package.json');
6
+
7
+ const DEFAULT_PROVIDER = 'codex';
8
+ const DEFAULT_REQUEST_TIMEOUT_MS = 30_000;
9
+ const MAX_REQUEST_TIMEOUT_MS = 5 * 60_000;
10
+ const DEFAULT_INITIALIZE_TIMEOUT_MS = 10_000;
11
+ const EVENT_BUFFER_LIMIT = 500;
12
+
13
+ const CODEX_APP_SERVER_CLIENT_METHODS = Object.freeze([
14
+ 'thread/start',
15
+ 'thread/resume',
16
+ 'thread/fork',
17
+ 'thread/archive',
18
+ 'thread/delete',
19
+ 'thread/unsubscribe',
20
+ 'thread/increment_elicitation',
21
+ 'thread/decrement_elicitation',
22
+ 'thread/name/set',
23
+ 'thread/goal/set',
24
+ 'thread/goal/get',
25
+ 'thread/goal/clear',
26
+ 'thread/metadata/update',
27
+ 'thread/settings/update',
28
+ 'thread/memoryMode/set',
29
+ 'memory/reset',
30
+ 'thread/unarchive',
31
+ 'thread/compact/start',
32
+ 'thread/shellCommand',
33
+ 'thread/approveGuardianDeniedAction',
34
+ 'thread/backgroundTerminals/clean',
35
+ 'thread/backgroundTerminals/list',
36
+ 'thread/backgroundTerminals/terminate',
37
+ 'thread/rollback',
38
+ 'thread/list',
39
+ 'thread/search',
40
+ 'thread/loaded/list',
41
+ 'thread/read',
42
+ 'thread/turns/list',
43
+ 'thread/items/list',
44
+ 'thread/inject_items',
45
+ 'skills/list',
46
+ 'skills/extraRoots/set',
47
+ 'hooks/list',
48
+ 'marketplace/add',
49
+ 'marketplace/remove',
50
+ 'marketplace/upgrade',
51
+ 'plugin/list',
52
+ 'plugin/installed',
53
+ 'plugin/read',
54
+ 'plugin/skill/read',
55
+ 'plugin/share/save',
56
+ 'plugin/share/updateTargets',
57
+ 'plugin/share/list',
58
+ 'plugin/share/checkout',
59
+ 'plugin/share/delete',
60
+ 'app/list',
61
+ 'fs/readFile',
62
+ 'fs/writeFile',
63
+ 'fs/createDirectory',
64
+ 'fs/getMetadata',
65
+ 'fs/readDirectory',
66
+ 'fs/remove',
67
+ 'fs/copy',
68
+ 'fs/watch',
69
+ 'fs/unwatch',
70
+ 'skills/config/write',
71
+ 'plugin/install',
72
+ 'plugin/uninstall',
73
+ 'turn/start',
74
+ 'turn/steer',
75
+ 'turn/interrupt',
76
+ 'thread/realtime/start',
77
+ 'thread/realtime/appendAudio',
78
+ 'thread/realtime/appendText',
79
+ 'thread/realtime/appendSpeech',
80
+ 'thread/realtime/stop',
81
+ 'thread/realtime/listVoices',
82
+ 'review/start',
83
+ 'model/list',
84
+ 'modelProvider/capabilities/read',
85
+ 'experimentalFeature/list',
86
+ 'permissionProfile/list',
87
+ 'experimentalFeature/enablement/set',
88
+ 'remoteControl/enable',
89
+ 'remoteControl/disable',
90
+ 'remoteControl/status/read',
91
+ 'remoteControl/pairing/start',
92
+ 'remoteControl/pairing/status',
93
+ 'remoteControl/client/list',
94
+ 'remoteControl/client/revoke',
95
+ 'collaborationMode/list',
96
+ 'environment/add',
97
+ 'environment/info',
98
+ 'mcpServer/oauth/login',
99
+ 'config/mcpServer/reload',
100
+ 'mcpServerStatus/list',
101
+ 'mcpServer/resource/read',
102
+ 'mcpServer/tool/call',
103
+ 'windowsSandbox/setupStart',
104
+ 'windowsSandbox/readiness',
105
+ 'account/login/start',
106
+ 'account/login/cancel',
107
+ 'account/logout',
108
+ 'account/rateLimits/read',
109
+ 'account/rateLimitResetCredit/consume',
110
+ 'account/usage/read',
111
+ 'account/workspaceMessages/read',
112
+ 'account/sendAddCreditsNudgeEmail',
113
+ 'feedback/upload',
114
+ 'command/exec',
115
+ 'command/exec/write',
116
+ 'command/exec/terminate',
117
+ 'command/exec/resize',
118
+ 'process/spawn',
119
+ 'process/writeStdin',
120
+ 'process/kill',
121
+ 'process/resizePty',
122
+ 'config/read',
123
+ 'externalAgentConfig/detect',
124
+ 'externalAgentConfig/import',
125
+ 'externalAgentConfig/import/readHistories',
126
+ 'config/value/write',
127
+ 'config/batchWrite',
128
+ 'configRequirements/read',
129
+ 'account/read',
130
+ 'getConversationSummary',
131
+ 'gitDiffToRemote',
132
+ 'getAuthStatus',
133
+ 'fuzzyFileSearch',
134
+ 'fuzzyFileSearch/sessionStart',
135
+ 'fuzzyFileSearch/sessionUpdate',
136
+ 'fuzzyFileSearch/sessionStop',
137
+ ]);
138
+
139
+ const CODEX_APP_SERVER_SERVER_REQUEST_METHODS = Object.freeze([
140
+ 'item/commandExecution/requestApproval',
141
+ 'item/fileChange/requestApproval',
142
+ 'item/tool/requestUserInput',
143
+ 'mcpServer/elicitation/request',
144
+ 'item/permissions/requestApproval',
145
+ 'item/tool/call',
146
+ 'account/chatgptAuthTokens/refresh',
147
+ 'attestation/generate',
148
+ 'currentTime/read',
149
+ 'applyPatchApproval',
150
+ 'execCommandApproval',
151
+ ]);
152
+
153
+ const CODEX_APP_SERVER_NOTIFICATION_METHODS = Object.freeze([
154
+ 'error',
155
+ 'thread/started',
156
+ 'thread/status/changed',
157
+ 'thread/archived',
158
+ 'thread/deleted',
159
+ 'thread/unarchived',
160
+ 'thread/closed',
161
+ 'skills/changed',
162
+ 'thread/name/updated',
163
+ 'thread/goal/updated',
164
+ 'thread/goal/cleared',
165
+ 'thread/settings/updated',
166
+ 'thread/tokenUsage/updated',
167
+ 'turn/started',
168
+ 'hook/started',
169
+ 'turn/completed',
170
+ 'hook/completed',
171
+ 'turn/diff/updated',
172
+ 'turn/plan/updated',
173
+ 'item/started',
174
+ 'item/autoApprovalReview/started',
175
+ 'item/autoApprovalReview/completed',
176
+ 'item/completed',
177
+ 'rawResponseItem/completed',
178
+ 'item/agentMessage/delta',
179
+ 'item/plan/delta',
180
+ 'command/exec/outputDelta',
181
+ 'process/outputDelta',
182
+ 'process/exited',
183
+ 'item/commandExecution/outputDelta',
184
+ 'item/commandExecution/terminalInteraction',
185
+ 'item/fileChange/outputDelta',
186
+ 'item/fileChange/patchUpdated',
187
+ 'serverRequest/resolved',
188
+ 'item/mcpToolCall/progress',
189
+ 'mcpServer/oauthLogin/completed',
190
+ 'mcpServer/startupStatus/updated',
191
+ 'account/updated',
192
+ 'account/rateLimits/updated',
193
+ 'app/list/updated',
194
+ 'remoteControl/status/changed',
195
+ 'externalAgentConfig/import/progress',
196
+ 'externalAgentConfig/import/completed',
197
+ 'fs/changed',
198
+ 'item/reasoning/summaryTextDelta',
199
+ 'item/reasoning/summaryPartAdded',
200
+ 'item/reasoning/textDelta',
201
+ 'thread/compacted',
202
+ 'model/rerouted',
203
+ 'model/verification',
204
+ 'turn/moderationMetadata',
205
+ 'model/safetyBuffering/updated',
206
+ 'warning',
207
+ 'guardianWarning',
208
+ 'deprecationNotice',
209
+ 'configWarning',
210
+ 'fuzzyFileSearch/sessionUpdated',
211
+ 'fuzzyFileSearch/sessionCompleted',
212
+ 'thread/realtime/started',
213
+ 'thread/realtime/itemAdded',
214
+ 'thread/realtime/transcript/delta',
215
+ 'thread/realtime/transcript/done',
216
+ 'thread/realtime/outputAudio/delta',
217
+ 'thread/realtime/sdp',
218
+ 'thread/realtime/error',
219
+ 'thread/realtime/closed',
220
+ 'windows/worldWritableWarning',
221
+ 'windowsSandbox/setupCompleted',
222
+ 'account/login/completed',
223
+ ]);
224
+
225
+ const CODEX_APP_SERVER_METHOD_SET = new Set(CODEX_APP_SERVER_CLIENT_METHODS);
226
+
227
+ class AppServerApiError extends Error {
228
+ constructor(status, message, details = undefined) {
229
+ super(message);
230
+ this.status = status;
231
+ this.details = details;
232
+ }
233
+ }
234
+
235
+ function nowIso() {
236
+ return new Date().toISOString();
237
+ }
238
+
239
+ function clampTimeoutMs(value, fallback = DEFAULT_REQUEST_TIMEOUT_MS) {
240
+ const timeoutMs = Math.floor(Number(value));
241
+ if (!Number.isFinite(timeoutMs) || timeoutMs <= 0) return fallback;
242
+ return Math.min(timeoutMs, MAX_REQUEST_TIMEOUT_MS);
243
+ }
244
+
245
+ function normalizeProvider(provider) {
246
+ return String(provider || '').trim().toLowerCase() === DEFAULT_PROVIDER ? DEFAULT_PROVIDER : '';
247
+ }
248
+
249
+ function normalizeEndpoint(endpoint, fallbackEndpoint = '') {
250
+ const value = String(endpoint || fallbackEndpoint || '').trim();
251
+ if (!value) {
252
+ throw new AppServerApiError(
253
+ 400,
254
+ 'Codex app-server endpoint is required. Start Codex with `codex app-server --listen ws://127.0.0.1:4500` or set FARMING_CODEX_APP_SERVER_ENDPOINT.'
255
+ );
256
+ }
257
+ if (/^wss?:\/\//i.test(value)) return value;
258
+ if (/^unix:\/\//i.test(value)) {
259
+ const socketPath = value.slice('unix://'.length);
260
+ if (!socketPath || !path.isAbsolute(socketPath)) {
261
+ throw new AppServerApiError(400, 'Explicit Unix socket endpoints must look like unix:///absolute/path.sock');
262
+ }
263
+ return value;
264
+ }
265
+ throw new AppServerApiError(400, 'Codex app-server endpoint must be ws://, wss://, or unix:///absolute/path.sock');
266
+ }
267
+
268
+ function bearerTokenFromRequest(req, body = {}) {
269
+ if (body && typeof body.authToken === 'string' && body.authToken.trim()) {
270
+ return body.authToken.trim();
271
+ }
272
+
273
+ const appServerToken = req.get('x-app-server-auth-token');
274
+ if (appServerToken && appServerToken.trim()) return appServerToken.trim();
275
+
276
+ const authorization = req.get('authorization') || '';
277
+ const match = authorization.match(/^Bearer\s+(.+)$/i);
278
+ return match ? match[1].trim() : '';
279
+ }
280
+
281
+ function tokenFingerprint(token) {
282
+ if (!token) return 'none';
283
+ return crypto.createHash('sha256').update(token).digest('hex').slice(0, 16);
284
+ }
285
+
286
+ function requestIdKey(id) {
287
+ return typeof id === 'string' ? id : JSON.stringify(id);
288
+ }
289
+
290
+ function safeJsonForSse(value) {
291
+ return JSON.stringify(value).replace(/\u2028|\u2029/g, '');
292
+ }
293
+
294
+ function sendSseEvent(res, eventName, payload) {
295
+ res.write(`event: ${eventName}\n`);
296
+ res.write(`data: ${safeJsonForSse(payload)}\n\n`);
297
+ }
298
+
299
+ function isJsonRpcResponse(message) {
300
+ return message && Object.prototype.hasOwnProperty.call(message, 'id') &&
301
+ (Object.prototype.hasOwnProperty.call(message, 'result') || Object.prototype.hasOwnProperty.call(message, 'error'));
302
+ }
303
+
304
+ function isJsonRpcServerRequest(message) {
305
+ return message && Object.prototype.hasOwnProperty.call(message, 'id') &&
306
+ typeof message.method === 'string' &&
307
+ !Object.prototype.hasOwnProperty.call(message, 'result') &&
308
+ !Object.prototype.hasOwnProperty.call(message, 'error');
309
+ }
310
+
311
+ function isJsonRpcNotification(message) {
312
+ return message && !Object.prototype.hasOwnProperty.call(message, 'id') &&
313
+ typeof message.method === 'string';
314
+ }
315
+
316
+ class AppServerConnection {
317
+ constructor(options) {
318
+ this.provider = options.provider;
319
+ this.endpoint = options.endpoint;
320
+ this.authToken = options.authToken || '';
321
+ this.experimentalApi = options.experimentalApi !== false;
322
+ this.clientInfo = options.clientInfo;
323
+ this.initializeTimeoutMs = options.initializeTimeoutMs || DEFAULT_INITIALIZE_TIMEOUT_MS;
324
+ this.requestCounter = 1;
325
+ this.eventCounter = 1;
326
+ this.pendingRequests = new Map();
327
+ this.pendingServerRequests = new Map();
328
+ this.eventSubscribers = new Set();
329
+ this.recentEvents = [];
330
+ this.ws = null;
331
+ this.connectPromise = null;
332
+ this.connectedAt = null;
333
+ this.closedAt = null;
334
+ this.lastError = null;
335
+ this.serverInfo = null;
336
+ }
337
+
338
+ status() {
339
+ return {
340
+ provider: this.provider,
341
+ endpoint: this.endpoint,
342
+ connected: this.ws && this.ws.readyState === WebSocket.OPEN,
343
+ connecting: !!this.connectPromise && !(this.ws && this.ws.readyState === WebSocket.OPEN),
344
+ connectedAt: this.connectedAt,
345
+ closedAt: this.closedAt,
346
+ lastError: this.lastError,
347
+ serverInfo: this.serverInfo,
348
+ pendingRequestCount: this.pendingRequests.size,
349
+ pendingServerRequestIds: Array.from(this.pendingServerRequests.keys()),
350
+ recentEventCount: this.recentEvents.length,
351
+ };
352
+ }
353
+
354
+ async connect() {
355
+ if (this.ws && this.ws.readyState === WebSocket.OPEN) return this;
356
+ if (this.connectPromise) return this.connectPromise;
357
+
358
+ this.connectPromise = this.open().finally(() => {
359
+ this.connectPromise = null;
360
+ });
361
+ return this.connectPromise;
362
+ }
363
+
364
+ async open() {
365
+ const ws = await this.openWebSocket();
366
+ this.ws = ws;
367
+ this.closedAt = null;
368
+ this.lastError = null;
369
+ this.attachWebSocketHandlers(ws);
370
+
371
+ const initializeResult = await this.sendRequest('initialize', {
372
+ clientInfo: this.clientInfo,
373
+ capabilities: {
374
+ experimentalApi: this.experimentalApi,
375
+ requestAttestation: false,
376
+ mcpServerOpenaiFormElicitation: true,
377
+ },
378
+ }, {
379
+ id: 'initialize',
380
+ timeoutMs: this.initializeTimeoutMs,
381
+ allowInitialize: true,
382
+ });
383
+ if (initializeResult.error) {
384
+ throw new AppServerApiError(502, `Codex app-server initialize failed: ${initializeResult.error.message || 'unknown error'}`, initializeResult.error);
385
+ }
386
+
387
+ this.serverInfo = initializeResult.result || null;
388
+ this.connectedAt = nowIso();
389
+ this.sendRaw({ method: 'initialized' });
390
+ this.emitEvent('transport', {
391
+ state: 'connected',
392
+ serverInfo: this.serverInfo,
393
+ });
394
+ return this;
395
+ }
396
+
397
+ openWebSocket() {
398
+ const headers = this.authToken ? { Authorization: `Bearer ${this.authToken}` } : {};
399
+ const endpoint = this.endpoint;
400
+
401
+ return new Promise((resolve, reject) => {
402
+ const timeout = setTimeout(() => {
403
+ reject(new AppServerApiError(504, `Timed out connecting to Codex app-server at ${endpoint}`));
404
+ }, this.initializeTimeoutMs);
405
+ if (typeof timeout.unref === 'function') timeout.unref();
406
+
407
+ const handleOpen = (ws) => {
408
+ clearTimeout(timeout);
409
+ resolve(ws);
410
+ };
411
+ const handleError = (error) => {
412
+ clearTimeout(timeout);
413
+ reject(new AppServerApiError(502, `Failed to connect to Codex app-server: ${error.message || error}`));
414
+ };
415
+
416
+ let ws;
417
+ if (endpoint.startsWith('unix://')) {
418
+ const socketPath = endpoint.slice('unix://'.length);
419
+ // `ws` deliberately ignores a `socketPath` option for ws:// URLs.
420
+ // Its documented IPC transport is ws+unix://<socket-path>:/<request-path>.
421
+ // Codex uses `/` for its control-socket WebSocket upgrade.
422
+ ws = new WebSocket(`ws+unix://${socketPath}:/`, {
423
+ headers,
424
+ // Codex's Unix control socket uses tokio-tungstenite without
425
+ // permessage-deflate negotiation. `ws` enables it by default,
426
+ // which makes the server reject the upgrade before initialize.
427
+ perMessageDeflate: false,
428
+ });
429
+ } else {
430
+ ws = new WebSocket(endpoint, { headers, perMessageDeflate: false });
431
+ }
432
+ ws.once('open', () => handleOpen(ws));
433
+ ws.once('error', handleError);
434
+ });
435
+ }
436
+
437
+ attachWebSocketHandlers(ws) {
438
+ ws.on('message', (data) => {
439
+ this.handleMessage(data);
440
+ });
441
+ ws.on('error', (error) => {
442
+ this.lastError = error.message || String(error);
443
+ this.emitEvent('transport', {
444
+ state: 'error',
445
+ error: this.lastError,
446
+ });
447
+ });
448
+ ws.on('close', (code, reasonBuffer) => {
449
+ const reason = reasonBuffer ? reasonBuffer.toString() : '';
450
+ this.closedAt = nowIso();
451
+ this.emitEvent('transport', {
452
+ state: 'closed',
453
+ code,
454
+ reason,
455
+ });
456
+ this.rejectPendingRequests({
457
+ code: -32000,
458
+ message: reason || 'Codex app-server connection closed',
459
+ });
460
+ });
461
+ }
462
+
463
+ handleMessage(data) {
464
+ let message;
465
+ try {
466
+ message = JSON.parse(data.toString());
467
+ } catch (error) {
468
+ this.emitEvent('parse-error', {
469
+ error: error.message || 'Failed to parse Codex app-server message',
470
+ });
471
+ return;
472
+ }
473
+
474
+ if (isJsonRpcResponse(message)) {
475
+ this.handleResponse(message);
476
+ return;
477
+ }
478
+
479
+ if (isJsonRpcServerRequest(message)) {
480
+ const key = requestIdKey(message.id);
481
+ this.pendingServerRequests.set(key, {
482
+ id: message.id,
483
+ method: message.method,
484
+ params: message.params,
485
+ receivedAt: nowIso(),
486
+ });
487
+ this.emitEvent('server-request', message);
488
+ return;
489
+ }
490
+
491
+ if (isJsonRpcNotification(message)) {
492
+ this.emitEvent('notification', message);
493
+ return;
494
+ }
495
+
496
+ this.emitEvent('unknown-message', { message });
497
+ }
498
+
499
+ handleResponse(message) {
500
+ const key = requestIdKey(message.id);
501
+ const pending = this.pendingRequests.get(key);
502
+ if (!pending) {
503
+ this.emitEvent('response', message);
504
+ return;
505
+ }
506
+
507
+ clearTimeout(pending.timeout);
508
+ this.pendingRequests.delete(key);
509
+ pending.resolve(message);
510
+ }
511
+
512
+ rejectPendingRequests(error) {
513
+ this.pendingRequests.forEach((pending, key) => {
514
+ clearTimeout(pending.timeout);
515
+ pending.resolve({
516
+ id: pending.id,
517
+ error,
518
+ });
519
+ this.pendingRequests.delete(key);
520
+ });
521
+ }
522
+
523
+ sendRaw(message) {
524
+ if (!this.ws || this.ws.readyState !== WebSocket.OPEN) {
525
+ throw new AppServerApiError(502, 'Codex app-server connection is not open');
526
+ }
527
+ this.ws.send(JSON.stringify(message));
528
+ }
529
+
530
+ sendRequest(method, params, options = {}) {
531
+ if (!options.allowInitialize && !CODEX_APP_SERVER_METHOD_SET.has(method)) {
532
+ throw new AppServerApiError(400, `Unsupported Codex app-server method: ${method}`);
533
+ }
534
+
535
+ const id = options.id || `farming-${this.requestCounter++}`;
536
+ const message = { id, method };
537
+ if (params !== undefined) message.params = params;
538
+ const timeoutMs = clampTimeoutMs(options.timeoutMs);
539
+
540
+ return new Promise((resolve, reject) => {
541
+ let timeout = null;
542
+ try {
543
+ timeout = setTimeout(() => {
544
+ this.pendingRequests.delete(requestIdKey(id));
545
+ resolve({
546
+ id,
547
+ error: {
548
+ code: -32002,
549
+ message: `Timed out waiting for ${method} response`,
550
+ },
551
+ });
552
+ }, timeoutMs);
553
+ if (typeof timeout.unref === 'function') timeout.unref();
554
+ this.pendingRequests.set(requestIdKey(id), { id, method, resolve, timeout });
555
+ this.sendRaw(message);
556
+ } catch (error) {
557
+ if (timeout) clearTimeout(timeout);
558
+ this.pendingRequests.delete(requestIdKey(id));
559
+ reject(error);
560
+ }
561
+ });
562
+ }
563
+
564
+ async request(method, params, options = {}) {
565
+ await this.connect();
566
+ return this.sendRequest(method, params, options);
567
+ }
568
+
569
+ resolveServerRequest(rawRequestId, result) {
570
+ const key = String(rawRequestId || '');
571
+ const request = this.pendingServerRequests.get(key);
572
+ if (!request) {
573
+ throw new AppServerApiError(404, 'Codex app-server server request not found');
574
+ }
575
+ this.sendRaw({ id: request.id, result: result === undefined ? null : result });
576
+ this.pendingServerRequests.delete(key);
577
+ return { id: request.id, resolved: true };
578
+ }
579
+
580
+ rejectServerRequest(rawRequestId, error) {
581
+ const key = String(rawRequestId || '');
582
+ const request = this.pendingServerRequests.get(key);
583
+ if (!request) {
584
+ throw new AppServerApiError(404, 'Codex app-server server request not found');
585
+ }
586
+ this.sendRaw({
587
+ id: request.id,
588
+ error: {
589
+ code: Number.isFinite(Number(error && error.code)) ? Number(error.code) : -32000,
590
+ message: String(error && error.message ? error.message : 'Rejected by Farming app-server API'),
591
+ ...(error && error.data !== undefined ? { data: error.data } : {}),
592
+ },
593
+ });
594
+ this.pendingServerRequests.delete(key);
595
+ return { id: request.id, rejected: true };
596
+ }
597
+
598
+ subscribe(handler, options = {}) {
599
+ if (options.replay !== false) {
600
+ this.recentEvents.forEach(handler);
601
+ }
602
+ this.eventSubscribers.add(handler);
603
+ return () => {
604
+ this.eventSubscribers.delete(handler);
605
+ };
606
+ }
607
+
608
+ emitEvent(kind, payload) {
609
+ const event = {
610
+ id: this.eventCounter++,
611
+ at: nowIso(),
612
+ provider: this.provider,
613
+ endpoint: this.endpoint,
614
+ kind,
615
+ payload,
616
+ };
617
+ this.recentEvents.push(event);
618
+ if (this.recentEvents.length > EVENT_BUFFER_LIMIT) {
619
+ this.recentEvents.splice(0, this.recentEvents.length - EVENT_BUFFER_LIMIT);
620
+ }
621
+ this.eventSubscribers.forEach((handler) => {
622
+ try {
623
+ handler(event);
624
+ } catch {
625
+ // Event subscribers are HTTP response writers; a failed subscriber should
626
+ // not break the app-server transport connection.
627
+ }
628
+ });
629
+ }
630
+
631
+ close() {
632
+ if (this.ws) {
633
+ this.ws.close();
634
+ this.ws = null;
635
+ }
636
+ this.rejectPendingRequests({
637
+ code: -32000,
638
+ message: 'Codex app-server connection closed by Farming',
639
+ });
640
+ }
641
+ }
642
+
643
+ class AppServerApiBridge {
644
+ constructor(options = {}) {
645
+ this.defaultCodexEndpoint = options.defaultCodexEndpoint || process.env.FARMING_CODEX_APP_SERVER_ENDPOINT || '';
646
+ this.clientInfo = {
647
+ name: 'farming',
648
+ title: 'Farming app-server API',
649
+ version: packageJson.version || '0.0.0',
650
+ };
651
+ this.connections = new Map();
652
+ }
653
+
654
+ metadata() {
655
+ return {
656
+ providers: [DEFAULT_PROVIDER],
657
+ codex: {
658
+ transportManagedMethods: ['initialize', 'initialized'],
659
+ clientMethods: CODEX_APP_SERVER_CLIENT_METHODS,
660
+ serverRequestMethods: CODEX_APP_SERVER_SERVER_REQUEST_METHODS,
661
+ notificationMethods: CODEX_APP_SERVER_NOTIFICATION_METHODS,
662
+ defaultEndpointConfigured: !!this.defaultCodexEndpoint,
663
+ },
664
+ };
665
+ }
666
+
667
+ connectionKey(provider, endpoint, authToken) {
668
+ return `${provider}\0${endpoint}\0${tokenFingerprint(authToken)}`;
669
+ }
670
+
671
+ getConnection(provider, options = {}) {
672
+ const normalizedProvider = normalizeProvider(provider);
673
+ if (!normalizedProvider) {
674
+ throw new AppServerApiError(404, 'Only the codex app-server provider is supported');
675
+ }
676
+ const endpoint = normalizeEndpoint(options.endpoint, this.defaultCodexEndpoint);
677
+ const authToken = options.authToken || '';
678
+ const key = this.connectionKey(normalizedProvider, endpoint, authToken);
679
+ let connection = this.connections.get(key);
680
+ if (!connection) {
681
+ connection = new AppServerConnection({
682
+ provider: normalizedProvider,
683
+ endpoint,
684
+ authToken,
685
+ experimentalApi: options.experimentalApi,
686
+ clientInfo: this.clientInfo,
687
+ });
688
+ this.connections.set(key, connection);
689
+ }
690
+ return connection;
691
+ }
692
+
693
+ getStatus(provider, options = {}) {
694
+ const normalizedProvider = normalizeProvider(provider);
695
+ if (!normalizedProvider) {
696
+ throw new AppServerApiError(404, 'Only the codex app-server provider is supported');
697
+ }
698
+ const endpoint = normalizeEndpoint(options.endpoint, this.defaultCodexEndpoint);
699
+ const authToken = options.authToken || '';
700
+ const connection = this.connections.get(this.connectionKey(normalizedProvider, endpoint, authToken));
701
+ return connection
702
+ ? connection.status()
703
+ : {
704
+ provider: normalizedProvider,
705
+ endpoint,
706
+ connected: false,
707
+ connecting: false,
708
+ connectedAt: null,
709
+ closedAt: null,
710
+ lastError: null,
711
+ serverInfo: null,
712
+ pendingRequestCount: 0,
713
+ pendingServerRequestIds: [],
714
+ recentEventCount: 0,
715
+ };
716
+ }
717
+
718
+ async connect(provider, options = {}) {
719
+ const connection = this.getConnection(provider, options);
720
+ await connection.connect();
721
+ return connection.status();
722
+ }
723
+
724
+ async request(provider, method, params, options = {}) {
725
+ const connection = this.getConnection(provider, options);
726
+ return connection.request(method, params, {
727
+ timeoutMs: options.timeoutMs,
728
+ });
729
+ }
730
+
731
+ resolveServerRequest(provider, requestId, result, options = {}) {
732
+ const connection = this.getConnection(provider, options);
733
+ return connection.resolveServerRequest(requestId, result);
734
+ }
735
+
736
+ rejectServerRequest(provider, requestId, error, options = {}) {
737
+ const connection = this.getConnection(provider, options);
738
+ return connection.rejectServerRequest(requestId, error);
739
+ }
740
+
741
+ disconnect(provider, options = {}) {
742
+ const connection = this.getConnection(provider, options);
743
+ connection.close();
744
+ return connection.status();
745
+ }
746
+ }
747
+
748
+ function sendError(res, error) {
749
+ if (error instanceof AppServerApiError) {
750
+ res.status(error.status).json({
751
+ error: error.message,
752
+ ...(error.details !== undefined ? { details: error.details } : {}),
753
+ });
754
+ return;
755
+ }
756
+ res.status(500).json({ error: error.message || 'Farming app-server API failed' });
757
+ }
758
+
759
+ function requestOptions(req, body = {}) {
760
+ return {
761
+ endpoint: body.endpoint || req.query.endpoint,
762
+ authToken: bearerTokenFromRequest(req, body),
763
+ experimentalApi: body.experimentalApi !== false,
764
+ timeoutMs: body.timeoutMs,
765
+ };
766
+ }
767
+
768
+ function createAppServerApiRouter(options = {}) {
769
+ const bridge = options.bridge || new AppServerApiBridge(options);
770
+ const router = express.Router();
771
+
772
+ router.use(express.json({ limit: '2mb' }));
773
+
774
+ router.get('/', (_req, res) => {
775
+ res.json(bridge.metadata());
776
+ });
777
+
778
+ router.get('/:provider', (req, res) => {
779
+ try {
780
+ const provider = normalizeProvider(req.params.provider);
781
+ if (!provider) throw new AppServerApiError(404, 'Only the codex app-server provider is supported');
782
+ const options = requestOptions(req);
783
+ const hasEndpoint = !!(options.endpoint || bridge.defaultCodexEndpoint);
784
+ res.json({
785
+ ...bridge.metadata()[provider],
786
+ status: hasEndpoint
787
+ ? bridge.getStatus(provider, options)
788
+ : {
789
+ provider,
790
+ endpoint: null,
791
+ connected: false,
792
+ connecting: false,
793
+ endpointRequired: true,
794
+ },
795
+ });
796
+ } catch (error) {
797
+ sendError(res, error);
798
+ }
799
+ });
800
+
801
+ router.post('/:provider/connect', async (req, res) => {
802
+ try {
803
+ const status = await bridge.connect(req.params.provider, requestOptions(req, req.body || {}));
804
+ res.json({ status });
805
+ } catch (error) {
806
+ sendError(res, error);
807
+ }
808
+ });
809
+
810
+ router.post('/:provider/disconnect', (req, res) => {
811
+ try {
812
+ const status = bridge.disconnect(req.params.provider, requestOptions(req, req.body || {}));
813
+ res.json({ status });
814
+ } catch (error) {
815
+ sendError(res, error);
816
+ }
817
+ });
818
+
819
+ router.post('/:provider/rpc', async (req, res) => {
820
+ const body = req.body || {};
821
+ try {
822
+ const method = String(body.method || '').trim();
823
+ if (!method) throw new AppServerApiError(400, 'method is required');
824
+ const response = await bridge.request(req.params.provider, method, body.params, requestOptions(req, body));
825
+ res.json(response);
826
+ } catch (error) {
827
+ sendError(res, error);
828
+ }
829
+ });
830
+
831
+ router.post('/:provider/server-requests/:requestId/resolve', (req, res) => {
832
+ try {
833
+ const body = req.body || {};
834
+ const response = bridge.resolveServerRequest(
835
+ req.params.provider,
836
+ req.params.requestId,
837
+ Object.prototype.hasOwnProperty.call(body, 'result') ? body.result : null,
838
+ requestOptions(req, body)
839
+ );
840
+ res.json(response);
841
+ } catch (error) {
842
+ sendError(res, error);
843
+ }
844
+ });
845
+
846
+ router.post('/:provider/server-requests/:requestId/reject', (req, res) => {
847
+ try {
848
+ const body = req.body || {};
849
+ const response = bridge.rejectServerRequest(
850
+ req.params.provider,
851
+ req.params.requestId,
852
+ body.error || {},
853
+ requestOptions(req, body)
854
+ );
855
+ res.json(response);
856
+ } catch (error) {
857
+ sendError(res, error);
858
+ }
859
+ });
860
+
861
+ router.get('/:provider/events', async (req, res) => {
862
+ let heartbeat = null;
863
+ let unsubscribe = null;
864
+
865
+ try {
866
+ res.writeHead(200, {
867
+ 'Content-Type': 'text/event-stream',
868
+ 'Cache-Control': 'no-cache, no-transform',
869
+ Connection: 'keep-alive',
870
+ 'X-Accel-Buffering': 'no',
871
+ });
872
+ sendSseEvent(res, 'ready', {
873
+ provider: req.params.provider,
874
+ at: nowIso(),
875
+ });
876
+
877
+ const connection = bridge.getConnection(req.params.provider, requestOptions(req));
878
+ unsubscribe = connection.subscribe((event) => {
879
+ sendSseEvent(res, event.kind, event);
880
+ }, {
881
+ replay: req.query.replay !== '0',
882
+ });
883
+ await connection.connect();
884
+ heartbeat = setInterval(() => {
885
+ sendSseEvent(res, 'heartbeat', { at: nowIso() });
886
+ }, 25_000);
887
+ if (typeof heartbeat.unref === 'function') heartbeat.unref();
888
+ } catch (error) {
889
+ sendSseEvent(res, 'error', {
890
+ at: nowIso(),
891
+ error: error.message || 'Farming app-server API event stream failed',
892
+ });
893
+ res.end();
894
+ if (unsubscribe) unsubscribe();
895
+ if (heartbeat) clearInterval(heartbeat);
896
+ return;
897
+ }
898
+
899
+ req.on('close', () => {
900
+ if (unsubscribe) unsubscribe();
901
+ if (heartbeat) clearInterval(heartbeat);
902
+ });
903
+ });
904
+
905
+ return router;
906
+ }
907
+
908
+ module.exports = {
909
+ AppServerConnection,
910
+ AppServerApiBridge,
911
+ AppServerApiError,
912
+ CODEX_APP_SERVER_CLIENT_METHODS,
913
+ CODEX_APP_SERVER_NOTIFICATION_METHODS,
914
+ CODEX_APP_SERVER_SERVER_REQUEST_METHODS,
915
+ createAppServerApiRouter,
916
+ normalizeEndpoint,
917
+ };