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.
- package/LICENSE +21 -0
- package/README.md +287 -0
- package/README.zh_cn.md +329 -0
- package/SECURITY.md +29 -0
- package/THIRD_PARTY_NOTICES.md +106 -0
- package/backend/acp/client-services.js +312 -0
- package/backend/acp/patch-decisions.js +137 -0
- package/backend/acp/permission-security.js +108 -0
- package/backend/acp-runtime.js +1144 -0
- package/backend/acp-session-state.js +448 -0
- package/backend/acp-transcript.js +169 -0
- package/backend/agent-activity.js +186 -0
- package/backend/agent-env.js +250 -0
- package/backend/agent-json-stream.js +268 -0
- package/backend/agent-manager.js +4259 -0
- package/backend/agent-memory-report.js +583 -0
- package/backend/agent-order.js +162 -0
- package/backend/agent-provider-session.js +287 -0
- package/backend/agent-session-history.js +888 -0
- package/backend/app-server-api.js +917 -0
- package/backend/async-cache.js +94 -0
- package/backend/auth.js +178 -0
- package/backend/claude-settings.js +121 -0
- package/backend/cli-agents.js +484 -0
- package/backend/codex-app-server-home.js +39 -0
- package/backend/codex-app-server-runtime.js +901 -0
- package/backend/codex-context-window.js +189 -0
- package/backend/codex-models.js +229 -0
- package/backend/codex-rollout-follower.js +243 -0
- package/backend/codex-session-history.js +553 -0
- package/backend/codex-transcript-sanitizer.js +103 -0
- package/backend/codex-transcript.js +2341 -0
- package/backend/command-runner-child.js +67 -0
- package/backend/config-manager.js +815 -0
- package/backend/control-api.js +151 -0
- package/backend/data/chinese-poetic-words.json +8223 -0
- package/backend/data/poetic-word-sources/china.json +49209 -0
- package/backend/data/poetic-word-sources/india.json +9763 -0
- package/backend/data/poetic-word-sources/japan.json +8455 -0
- package/backend/executable-discovery.js +207 -0
- package/backend/farming-app-cli.js +790 -0
- package/backend/farming-cli.js +400 -0
- package/backend/farming-session-store.js +373 -0
- package/backend/haiku-token.js +772 -0
- package/backend/index-html.js +49 -0
- package/backend/input-parts.js +54 -0
- package/backend/input-routing.js +24 -0
- package/backend/json-cli-runtime.js +161 -0
- package/backend/local-session-engine.js +620 -0
- package/backend/main-agent-skills.js +292 -0
- package/backend/main-page-session.js +119 -0
- package/backend/native-pty-host-client.js +516 -0
- package/backend/native-pty-host-path.js +22 -0
- package/backend/native-pty-host.js +816 -0
- package/backend/native-session-engine.js +196 -0
- package/backend/network.js +23 -0
- package/backend/npm-update-helper.js +196 -0
- package/backend/packaged-node-pty.js +79 -0
- package/backend/provider-session-id.js +47 -0
- package/backend/qr-share-tickets.js +100 -0
- package/backend/review-diff-router.js +180 -0
- package/backend/review-diff-service.js +1270 -0
- package/backend/review-session-router.js +74 -0
- package/backend/review-session-service.js +432 -0
- package/backend/review-session-store.js +144 -0
- package/backend/review-state-router.js +116 -0
- package/backend/review-state-store.js +287 -0
- package/backend/run-history-store.js +70 -0
- package/backend/server.js +2446 -0
- package/backend/session-engine-bridge.js +110 -0
- package/backend/session-engine-router.js +66 -0
- package/backend/session-engine.js +39 -0
- package/backend/shell-busy-integration.js +472 -0
- package/backend/slash-command-discovery.js +296 -0
- package/backend/storage-layout.js +101 -0
- package/backend/system-monitor.js +77 -0
- package/backend/terminal-runtime-cleanup.js +80 -0
- package/backend/terminal-screen-state.js +240 -0
- package/backend/terminal-screen-worker-pool.js +165 -0
- package/backend/terminal-screen-worker-thread.js +161 -0
- package/backend/terminal-screen-worker.js +255 -0
- package/backend/terminal-status.js +356 -0
- package/backend/theme-manager.js +145 -0
- package/backend/update-service.js +1183 -0
- package/backend/usage-forecast.js +86 -0
- package/backend/usage-monitor.js +1357 -0
- package/backend/workspace-discovery.js +311 -0
- package/backend/workspace-file-router.js +431 -0
- package/backend/workspace-file-service.js +2765 -0
- package/bin/farming +5 -0
- package/config/farming.deploy.env.example +13 -0
- package/config/farming.install.env.example +17 -0
- package/dist/assets/App-BrP-ENHg.css +1 -0
- package/dist/assets/App-Dza5yEDe.js +124 -0
- package/dist/assets/FileEditorMarkdownPreview-DRDNQ8mX.css +1 -0
- package/dist/assets/FileEditorMarkdownPreview-elKWc8Im.js +404 -0
- package/dist/assets/FileEditorPane-BQLocXOp.js +5 -0
- package/dist/assets/IconGlyphs-RkMAdBXF.js +1 -0
- package/dist/assets/KaTeX_AMS-Regular-BQhdFMY1.woff2 +0 -0
- package/dist/assets/KaTeX_AMS-Regular-DMm9YOAa.woff +0 -0
- package/dist/assets/KaTeX_AMS-Regular-DRggAlZN.ttf +0 -0
- package/dist/assets/KaTeX_Caligraphic-Bold-ATXxdsX0.ttf +0 -0
- package/dist/assets/KaTeX_Caligraphic-Bold-BEiXGLvX.woff +0 -0
- package/dist/assets/KaTeX_Caligraphic-Bold-Dq_IR9rO.woff2 +0 -0
- package/dist/assets/KaTeX_Caligraphic-Regular-CTRA-rTL.woff +0 -0
- package/dist/assets/KaTeX_Caligraphic-Regular-Di6jR-x-.woff2 +0 -0
- package/dist/assets/KaTeX_Caligraphic-Regular-wX97UBjC.ttf +0 -0
- package/dist/assets/KaTeX_Fraktur-Bold-BdnERNNW.ttf +0 -0
- package/dist/assets/KaTeX_Fraktur-Bold-BsDP51OF.woff +0 -0
- package/dist/assets/KaTeX_Fraktur-Bold-CL6g_b3V.woff2 +0 -0
- package/dist/assets/KaTeX_Fraktur-Regular-CB_wures.ttf +0 -0
- package/dist/assets/KaTeX_Fraktur-Regular-CTYiF6lA.woff2 +0 -0
- package/dist/assets/KaTeX_Fraktur-Regular-Dxdc4cR9.woff +0 -0
- package/dist/assets/KaTeX_Main-Bold-Cx986IdX.woff2 +0 -0
- package/dist/assets/KaTeX_Main-Bold-Jm3AIy58.woff +0 -0
- package/dist/assets/KaTeX_Main-Bold-waoOVXN0.ttf +0 -0
- package/dist/assets/KaTeX_Main-BoldItalic-DxDJ3AOS.woff2 +0 -0
- package/dist/assets/KaTeX_Main-BoldItalic-DzxPMmG6.ttf +0 -0
- package/dist/assets/KaTeX_Main-BoldItalic-SpSLRI95.woff +0 -0
- package/dist/assets/KaTeX_Main-Italic-3WenGoN9.ttf +0 -0
- package/dist/assets/KaTeX_Main-Italic-BMLOBm91.woff +0 -0
- package/dist/assets/KaTeX_Main-Italic-NWA7e6Wa.woff2 +0 -0
- package/dist/assets/KaTeX_Main-Regular-B22Nviop.woff2 +0 -0
- package/dist/assets/KaTeX_Main-Regular-Dr94JaBh.woff +0 -0
- package/dist/assets/KaTeX_Main-Regular-ypZvNtVU.ttf +0 -0
- package/dist/assets/KaTeX_Math-BoldItalic-B3XSjfu4.ttf +0 -0
- package/dist/assets/KaTeX_Math-BoldItalic-CZnvNsCZ.woff2 +0 -0
- package/dist/assets/KaTeX_Math-BoldItalic-iY-2wyZ7.woff +0 -0
- package/dist/assets/KaTeX_Math-Italic-DA0__PXp.woff +0 -0
- package/dist/assets/KaTeX_Math-Italic-flOr_0UB.ttf +0 -0
- package/dist/assets/KaTeX_Math-Italic-t53AETM-.woff2 +0 -0
- package/dist/assets/KaTeX_SansSerif-Bold-CFMepnvq.ttf +0 -0
- package/dist/assets/KaTeX_SansSerif-Bold-D1sUS0GD.woff2 +0 -0
- package/dist/assets/KaTeX_SansSerif-Bold-DbIhKOiC.woff +0 -0
- package/dist/assets/KaTeX_SansSerif-Italic-C3H0VqGB.woff2 +0 -0
- package/dist/assets/KaTeX_SansSerif-Italic-DN2j7dab.woff +0 -0
- package/dist/assets/KaTeX_SansSerif-Italic-YYjJ1zSn.ttf +0 -0
- package/dist/assets/KaTeX_SansSerif-Regular-BNo7hRIc.ttf +0 -0
- package/dist/assets/KaTeX_SansSerif-Regular-CS6fqUqJ.woff +0 -0
- package/dist/assets/KaTeX_SansSerif-Regular-DDBCnlJ7.woff2 +0 -0
- package/dist/assets/KaTeX_Script-Regular-C5JkGWo-.ttf +0 -0
- package/dist/assets/KaTeX_Script-Regular-D3wIWfF6.woff2 +0 -0
- package/dist/assets/KaTeX_Script-Regular-D5yQViql.woff +0 -0
- package/dist/assets/KaTeX_Size1-Regular-C195tn64.woff +0 -0
- package/dist/assets/KaTeX_Size1-Regular-Dbsnue_I.ttf +0 -0
- package/dist/assets/KaTeX_Size1-Regular-mCD8mA8B.woff2 +0 -0
- package/dist/assets/KaTeX_Size2-Regular-B7gKUWhC.ttf +0 -0
- package/dist/assets/KaTeX_Size2-Regular-Dy4dx90m.woff2 +0 -0
- package/dist/assets/KaTeX_Size2-Regular-oD1tc_U0.woff +0 -0
- package/dist/assets/KaTeX_Size3-Regular-CTq5MqoE.woff +0 -0
- package/dist/assets/KaTeX_Size3-Regular-DgpXs0kz.ttf +0 -0
- package/dist/assets/KaTeX_Size4-Regular-BF-4gkZK.woff +0 -0
- package/dist/assets/KaTeX_Size4-Regular-DWFBv043.ttf +0 -0
- package/dist/assets/KaTeX_Size4-Regular-Dl5lxZxV.woff2 +0 -0
- package/dist/assets/KaTeX_Typewriter-Regular-C0xS9mPB.woff +0 -0
- package/dist/assets/KaTeX_Typewriter-Regular-CO6r4hn1.woff2 +0 -0
- package/dist/assets/KaTeX_Typewriter-Regular-D3Ib7_Hf.ttf +0 -0
- package/dist/assets/ProjectFilesSection-lS1azbgj.js +12 -0
- package/dist/assets/ReviewPage-DgnmgU2T.js +3 -0
- package/dist/assets/abap-Cc5D5h5i.js +1 -0
- package/dist/assets/abnfDiagram-VRR7QNED-BgawzDQT.js +1 -0
- package/dist/assets/apex-BKopwLmx.js +1 -0
- package/dist/assets/api-D1lyBYIQ.js +1 -0
- package/dist/assets/arc-CWoVlxJw.js +1 -0
- package/dist/assets/architecture-TIHT7OUA-CbJBFh3w.js +1 -0
- package/dist/assets/architectureDiagram-ZJ3FMSHR-DUShwPg0.js +36 -0
- package/dist/assets/array-HeX70jSN.js +1 -0
- package/dist/assets/azcli-DI-C34WA.js +1 -0
- package/dist/assets/bat-Cbp6u42z.js +1 -0
- package/dist/assets/bicep-4QA1jTCM.js +2 -0
- package/dist/assets/blockDiagram-677ZJIJ3-CeGZviXR.js +132 -0
- package/dist/assets/c4Diagram-LMCZKHZV-CLhYht6S.js +10 -0
- package/dist/assets/cameligo-Dda_adPs.js +1 -0
- package/dist/assets/channel-Uw90AO0b.js +1 -0
- package/dist/assets/chunk-2Q5K7J3B-d5WWh8jo.js +1 -0
- package/dist/assets/chunk-32BRIVSS-LFYpT-Cu.js +1 -0
- package/dist/assets/chunk-52WLFC77-BH6jDw9J.js +10 -0
- package/dist/assets/chunk-5FCAYU7R-C7AmIhYv.js +1 -0
- package/dist/assets/chunk-5HE753X5-C8cXaouP.js +1 -0
- package/dist/assets/chunk-5JV3BV7I-C1PtimcA.js +1 -0
- package/dist/assets/chunk-5TONJI2A-_81zUME8.js +2 -0
- package/dist/assets/chunk-5VM5RSS4-Dlw7AXWp.js +15 -0
- package/dist/assets/chunk-7BUUIJ7U-ZBRhjLOh.js +1 -0
- package/dist/assets/chunk-BIQX33UG-CWmzxeAw.js +1 -0
- package/dist/assets/chunk-C7G6YPKG-B_mIUlb7.js +1 -0
- package/dist/assets/chunk-CQNSW5MT-CMayolwI.js +1 -0
- package/dist/assets/chunk-CYSBUYHQ-lSPbrL3Z.js +1 -0
- package/dist/assets/chunk-DECur_0Z.js +1 -0
- package/dist/assets/chunk-EMLP6XTP-D9-jtCnM.js +1 -0
- package/dist/assets/chunk-EX3LRPZG-C63hVuAJ.js +231 -0
- package/dist/assets/chunk-FWX5IMBZ-CboX-WF_.js +2 -0
- package/dist/assets/chunk-HOUHSVGY-BOgSd6Un.js +1 -0
- package/dist/assets/chunk-ICXQ74PX-C0K-pgZt.js +2 -0
- package/dist/assets/chunk-JG7HCLWE-Cib606u_.js +2 -0
- package/dist/assets/chunk-JWPE2WC7-DSyBRaRG.js +1 -0
- package/dist/assets/chunk-KEIR6QF5-CNOHik0T.js +161 -0
- package/dist/assets/chunk-MOJQB5TN-CVMfwN_7.js +88 -0
- package/dist/assets/chunk-MOZMSUNE-D6JeZqmE.js +1 -0
- package/dist/assets/chunk-OGEWGWER-DLT3pxyw.js +1 -0
- package/dist/assets/chunk-OSBZ3O6U-C0W8KSeg.js +1 -0
- package/dist/assets/chunk-PUDLZKDR-Cd079yIQ.js +156 -0
- package/dist/assets/chunk-Q4XR5HBZ-D0jHa6SO.js +70 -0
- package/dist/assets/chunk-QBLGF6JB-p4omp7uO.js +1 -0
- package/dist/assets/chunk-R7FJI6CG-CZ_p9hSr.js +1 -0
- package/dist/assets/chunk-RYQCIY6F-CZA9pvFX.js +1 -0
- package/dist/assets/chunk-U6XO7XAA-CcXKsWxp.js +2 -0
- package/dist/assets/chunk-V7JOEXUC-CVDtR75H.js +206 -0
- package/dist/assets/chunk-VAUOI2AC-B-W2_9Ot.js +1 -0
- package/dist/assets/chunk-VR4S4FIN-FD3kWh32.js +1 -0
- package/dist/assets/chunk-WYO6CB5R-C2bGaS5r.js +127 -0
- package/dist/assets/chunk-XXDRQBXY-BBXwjhUx.js +1 -0
- package/dist/assets/chunk-Y2CYZVJY-Di0sYzi1.js +1 -0
- package/dist/assets/chunk-YOTPTUD7-BXHmEk89.js +1 -0
- package/dist/assets/chunk-ZGVPDNZ5-ymgts0zo.js +62 -0
- package/dist/assets/chunk-ZIRB5QZD-DncwlQQc.js +32 -0
- package/dist/assets/classDiagram-OUVF2IWQ-DKW_dtku.js +1 -0
- package/dist/assets/classDiagram-v2-EOCWNBFH-C8Fi7-yv.js +1 -0
- package/dist/assets/clojure-CvY8A83L.js +1 -0
- package/dist/assets/code-dark-Cjb1QGhu.css +1 -0
- package/dist/assets/code-mobile-3C2Rr-CN.css +1 -0
- package/dist/assets/codicon-ngg6Pgfi.ttf +0 -0
- package/dist/assets/coffee-4LX2Sv8A.js +1 -0
- package/dist/assets/core-ZlAPicox.js +3 -0
- package/dist/assets/cose-bilkent-JH36ORCC-BNIAz0nN.js +1 -0
- package/dist/assets/cpp-D4AzSV28.js +1 -0
- package/dist/assets/csharp-C4nWN4Yd.js +1 -0
- package/dist/assets/csp-CiEaaS5Z.js +1 -0
- package/dist/assets/css-DXxBRsbk.js +3 -0
- package/dist/assets/css.worker-DyDu5ynT.js +89 -0
- package/dist/assets/cssMode-DDWxTPm_.js +1 -0
- package/dist/assets/cynefin-VYW2F7L2-DgXGHlRt.js +1 -0
- package/dist/assets/cynefinDiagram-TSTJHNR4-CwpobXIl.js +62 -0
- package/dist/assets/cypher-DOMzqyFA.js +1 -0
- package/dist/assets/cytoscape.esm-Cl8iC3D7.js +321 -0
- package/dist/assets/dagre-DXlcHgr3.js +1 -0
- package/dist/assets/dagre-VKFMJZFB-Dkhlfjna.js +4 -0
- package/dist/assets/dart-BWS7MXt_.js +1 -0
- package/dist/assets/defaultLocale-GJwWH1Jr.js +1 -0
- package/dist/assets/diagram-FQU43EPY-hA8dicp6.js +3 -0
- package/dist/assets/diagram-G47NLZAW-BTY6JTzO.js +24 -0
- package/dist/assets/diagram-NH7WQ7WH-xkaHHX9M.js +24 -0
- package/dist/assets/diagram-OA4YK3LP-gk_fg9UU.js +30 -0
- package/dist/assets/diagram-WEI45ONY-BvC8xd6T.js +41 -0
- package/dist/assets/dist-ClAL-Tv5.js +1 -0
- package/dist/assets/dockerfile-Baf4U3xT.js +1 -0
- package/dist/assets/ebnfDiagram-CCIWWBDH-CR7RaNat.js +1 -0
- package/dist/assets/ecl-CT7udlkQ.js +1 -0
- package/dist/assets/editor-CtbFZlk0.css +1 -0
- package/dist/assets/editor.api2-B9h6iFPK.js +872 -0
- package/dist/assets/editor.worker-Dpt_xPrs.js +26 -0
- package/dist/assets/elixir-CIbAZw5l.js +1 -0
- package/dist/assets/erDiagram-Q63AITRT-_M-JFPbj.js +85 -0
- package/dist/assets/eventmodeling-45OFAUF4-DXYTQ2nt.js +1 -0
- package/dist/assets/file-icons-EFUGSSwf.js +1 -0
- package/dist/assets/flow9-Dqiw45WV.js +1 -0
- package/dist/assets/flowDiagram-23GEKE2U-DAiS5Y7G.js +1 -0
- package/dist/assets/freemarker2-QBsTERH-.js +3 -0
- package/dist/assets/fsharp-E8E2L9jU.js +1 -0
- package/dist/assets/ganttDiagram-NO4QXBWP-Bl8P1yf_.js +292 -0
- package/dist/assets/gitGraph-TEB2WS4Q-CzTBjEvV.js +1 -0
- package/dist/assets/gitGraphDiagram-IHSO6WYX-DoHa5ysz.js +106 -0
- package/dist/assets/go-CouVSN4D.js +1 -0
- package/dist/assets/graphlib-CbSvZcZU.js +1 -0
- package/dist/assets/graphql-a6h6h5-t.js +1 -0
- package/dist/assets/handlebars-CuoxPo5A.js +1 -0
- package/dist/assets/hcl-vso3e6N-.js +1 -0
- package/dist/assets/html-gX5PEu0Q.js +1 -0
- package/dist/assets/html.worker-IWNXhnIC.js +502 -0
- package/dist/assets/htmlMode-DIWUbUxd.js +1 -0
- package/dist/assets/index-BpHPeJf0.js +10 -0
- package/dist/assets/info-DKCQHKI2-DznP7j3s.js +1 -0
- package/dist/assets/infoDiagram-FWYZ7A6U-DSFcSuUs.js +2 -0
- package/dist/assets/ini-SwZZkotR.js +1 -0
- package/dist/assets/init-BPLPMQ3Y.js +1 -0
- package/dist/assets/ishikawaDiagram-FXEZZL3T-DdkqullI.js +70 -0
- package/dist/assets/java-CtRLC4_3.js +1 -0
- package/dist/assets/javascript-BYKGIUGs.js +1 -0
- package/dist/assets/journeyDiagram-5HDEW3XC-B4hRnQJr.js +139 -0
- package/dist/assets/json.worker-c4h5s80L.js +58 -0
- package/dist/assets/jsonMode-AFmQQP6u.js +7 -0
- package/dist/assets/jsx-runtime-BthL93pI.js +1 -0
- package/dist/assets/julia-CuJWFKQH.js +1 -0
- package/dist/assets/kanban-definition-HUTT4EX6-tm2FZB2E.js +89 -0
- package/dist/assets/katex-C8DPyI6s.js +257 -0
- package/dist/assets/kotlin-B_kBhsre.js +1 -0
- package/dist/assets/less-CtrHIfz3.js +2 -0
- package/dist/assets/lexon-yVt1pJLu.js +1 -0
- package/dist/assets/line-CmsjK4kn.js +1 -0
- package/dist/assets/linear-Dld3_ERu.js +1 -0
- package/dist/assets/liquid-DBIl-f0z.js +1 -0
- package/dist/assets/lspLanguageFeatures-DK6tqicV.js +4 -0
- package/dist/assets/lua-prOwgJ4U.js +1 -0
- package/dist/assets/m3-DhrdTQ84.js +1 -0
- package/dist/assets/main-DTJwH51M.css +1 -0
- package/dist/assets/map-LZWWoeWa.js +1 -0
- package/dist/assets/markdown-DoI5HwSM.js +1 -0
- package/dist/assets/mdx-DS-bVtZN.js +1 -0
- package/dist/assets/mermaid-parser.core-BQtepoLd.js +4 -0
- package/dist/assets/mermaid.core-C7UT_EEL.js +11 -0
- package/dist/assets/mindmap-definition-LN4V7U3C-DplfjGms.js +96 -0
- package/dist/assets/mips-Dye5jsBU.js +1 -0
- package/dist/assets/monaco.contribution-CyLosfZI.js +2 -0
- package/dist/assets/msdax-TkNOyIL8.js +1 -0
- package/dist/assets/mysql-CEc-RKZF.js +1 -0
- package/dist/assets/objective-c-CqqCsQz0.js +1 -0
- package/dist/assets/ordinal-BLrOss5K.js +1 -0
- package/dist/assets/packet-7NZHBO7P-BDEPOPha.js +1 -0
- package/dist/assets/pascal-DO_pj8yg.js +1 -0
- package/dist/assets/pascaligo-1cbdZdF3.js +1 -0
- package/dist/assets/path-YdFzr2W6.js +1 -0
- package/dist/assets/pegDiagram-2B236MQR-lu3SdkQs.js +1 -0
- package/dist/assets/perl-B_N3PYfC.js +1 -0
- package/dist/assets/pgsql-9iYk1FQ7.js +1 -0
- package/dist/assets/php-rO2sgoUM.js +1 -0
- package/dist/assets/pie-RZYD4A2V-DWIrwPJQ.js +1 -0
- package/dist/assets/pieDiagram-ENE6RG2P-3fHbmDf9.js +39 -0
- package/dist/assets/pla-Cbgv60kq.js +1 -0
- package/dist/assets/postiats-y6xrhy_M.js +1 -0
- package/dist/assets/powerquery-BaD8gWNE.js +1 -0
- package/dist/assets/powershell-BMhG4JVe.js +1 -0
- package/dist/assets/preload-helper-mJowh_hw.js +1 -0
- package/dist/assets/protobuf-CdOP5kN3.js +2 -0
- package/dist/assets/pug-Ck60hNF9.js +1 -0
- package/dist/assets/python-C93q3xXz.js +1 -0
- package/dist/assets/qoder-C9LmmOSf.svg +1 -0
- package/dist/assets/qoder-Cf9gl0Y5.svg +1 -0
- package/dist/assets/qoder-gHCinseV.svg +1 -0
- package/dist/assets/qrcode-DV-_rjU8.js +3 -0
- package/dist/assets/qsharp-BcaKFfP-.js +1 -0
- package/dist/assets/quadrantDiagram-ABIIQ3AL-a5qoWz-X.js +7 -0
- package/dist/assets/r-rFNes0iK.js +1 -0
- package/dist/assets/radar-I7S5WNFK-B7OaD8vp.js +1 -0
- package/dist/assets/railroad-3IZDKUUU-BXW2nuCA.js +1 -0
- package/dist/assets/railroad-abnf-AHOZXSZD-Buw9QG2r.js +1 -0
- package/dist/assets/railroad-ebnf-EBAXGLYW-BjSi4sWJ.js +1 -0
- package/dist/assets/railroad-peg-LSFZ7HO6-DN1wIVhS.js +1 -0
- package/dist/assets/railroadDiagram-RFXS5EU6-D2TOuXW9.js +1 -0
- package/dist/assets/razor-CBifNGXO.js +1 -0
- package/dist/assets/react-dom-gtU6X-Hj.js +1 -0
- package/dist/assets/redis-DkpQ3K6G.js +1 -0
- package/dist/assets/redshift-Di9N5TI3.js +1 -0
- package/dist/assets/requirementDiagram-TGXJPOKE-LQBWpUvd.js +84 -0
- package/dist/assets/restructuredtext-By5ZzLt6.js +1 -0
- package/dist/assets/review-BcnwQtJv.css +1 -0
- package/dist/assets/rough.esm-c4PR5shF.js +1 -0
- package/dist/assets/ruby-fF5zGiLp.js +1 -0
- package/dist/assets/rust-C5b3AYY6.js +1 -0
- package/dist/assets/sankeyDiagram-HTMAVEWB-B1ohYoyK.js +40 -0
- package/dist/assets/sb-CD07UNRs.js +1 -0
- package/dist/assets/scala-jtn1ip9G.js +1 -0
- package/dist/assets/scheme-C4vqMkn_.js +1 -0
- package/dist/assets/scss-I4Glxjbz.js +3 -0
- package/dist/assets/sequenceDiagram-DBY2YBRQ-C3vM-hMq.js +162 -0
- package/dist/assets/shell-DubUcuns.js +1 -0
- package/dist/assets/sizeCapture-X5ZJPWSS-daTB6OcF.js +1 -0
- package/dist/assets/solidity-CNy2KSl2.js +1 -0
- package/dist/assets/sophia-D9_URt84.js +1 -0
- package/dist/assets/sparql-DviXpm4C.js +1 -0
- package/dist/assets/sql-vDRbAZgK.js +1 -0
- package/dist/assets/src-WBW1QxJt.js +1 -0
- package/dist/assets/st-CnpnRqA7.js +1 -0
- package/dist/assets/stateDiagram-2N3HPSRC-BvFhOryI.js +1 -0
- package/dist/assets/stateDiagram-v2-6OUMAXLB-WMrz4PNo.js +1 -0
- package/dist/assets/swift-D_g8Ganz.js +1 -0
- package/dist/assets/swimlanes-5IMT3BWC-DKF_b-2s.js +2 -0
- package/dist/assets/swimlanesDiagram-G3AALYLV-BGswC9oC.js +8 -0
- package/dist/assets/systemverilog-OuZa5h1M.js +1 -0
- package/dist/assets/tcl-DBm9ucsV.js +1 -0
- package/dist/assets/timeline-definition-FHXFAJF6-vAs11ux_.js +120 -0
- package/dist/assets/tokens-BwenNn5Q.css +1 -0
- package/dist/assets/treeView-QDETBFTQ-BVfICaZQ.js +1 -0
- package/dist/assets/treemap-6X3UGDF4-oWHPqo17.js +1 -0
- package/dist/assets/ts.worker-BwM5Ha3L.js +67719 -0
- package/dist/assets/tsMode-DGZTlTj8.js +11 -0
- package/dist/assets/twig-BRzEqX5Y.js +1 -0
- package/dist/assets/typescript-KJKfYO7K.js +1 -0
- package/dist/assets/typespec-D4ZgGeX8.js +1 -0
- package/dist/assets/useWorkspaceMenuKeyboard-CneKAZUJ.js +1 -0
- package/dist/assets/vb-DcP4s6WS.js +1 -0
- package/dist/assets/vennDiagram-L72KCM5P-BybTX_9B.js +34 -0
- package/dist/assets/wardley-OPB4EBWU-Dg8t5y3s.js +1 -0
- package/dist/assets/wardleyDiagram-EHGQE667-CicUmMBR.js +78 -0
- package/dist/assets/wgsl-CnRJ_QUf.js +298 -0
- package/dist/assets/workers-BSQRIkqa.js +1 -0
- package/dist/assets/workspace-view-state-CTyDzk2D.js +1 -0
- package/dist/assets/xml-C8FAcN6j.js +1 -0
- package/dist/assets/xychartDiagram-FW5EYKEG-BhWDyCX-.js +7 -0
- package/dist/assets/yaml-BQ4NrRhG.js +1 -0
- package/dist/assets/zsh-CLpveKlF.svg +1 -0
- package/dist/assets/zsh-FxSpMPbz.svg +1 -0
- package/dist/farming-2/app-icon-v2-180.png +0 -0
- package/dist/farming-2/app-icon-v2-192.png +0 -0
- package/dist/farming-2/app-icon-v2-512.png +0 -0
- package/dist/farming-2/app-icon-v2-maskable-512.png +0 -0
- package/dist/farming-2/app-icon-v2-master.png +0 -0
- package/dist/farming-2/favicon-v2-16.png +0 -0
- package/dist/farming-2/favicon-v2-32.png +0 -0
- package/dist/farming-2/favicon-v2-48.png +0 -0
- package/dist/farming-2/favicon-v2-64.png +0 -0
- package/dist/farming-2/favicon-v2.ico +0 -0
- package/dist/farming-2/favicon.ico +0 -0
- package/dist/farming-2/github-social-preview.png +0 -0
- package/dist/farming-2/images/avatar-watercolor-v1-bee-garden.png +0 -0
- package/dist/farming-2/images/avatar-watercolor-v2.png +0 -0
- package/dist/farming-2/images/avatar-watercolor-v3.png +0 -0
- package/dist/farming-2/legacy-icons-v1/favicon.ico +1 -0
- package/dist/farming-2/legacy-icons-v1/logo-16.png +0 -0
- package/dist/farming-2/legacy-icons-v1/logo-180.png +0 -0
- package/dist/farming-2/legacy-icons-v1/logo-192.png +0 -0
- package/dist/farming-2/legacy-icons-v1/logo-32.png +0 -0
- package/dist/farming-2/legacy-icons-v1/logo-48.png +0 -0
- package/dist/farming-2/legacy-icons-v1/logo-512.png +0 -0
- package/dist/farming-2/legacy-icons-v1/logo-64.png +0 -0
- package/dist/farming-2/logo-16.png +0 -0
- package/dist/farming-2/logo-180.png +0 -0
- package/dist/farming-2/logo-192.png +0 -0
- package/dist/farming-2/logo-32.png +0 -0
- package/dist/farming-2/logo-48.png +0 -0
- package/dist/farming-2/logo-512.png +0 -0
- package/dist/farming-2/logo-64.png +0 -0
- package/dist/farming-2/site.webmanifest +27 -0
- package/dist/farming-2/style_capsules/watercolor-pastoral.json +94 -0
- package/dist/index.html +27 -0
- package/frontend/ghostty-loader.js +24 -0
- package/frontend/runtime-paths.js +28 -0
- package/frontend/session-bridge.js +82 -0
- package/frontend/session-modal-bridge.js +331 -0
- package/frontend/skin-bridge.js +25 -0
- package/frontend/skins/crt/app.js +6940 -0
- package/frontend/skins/crt/assets/branding/farming-crt-icon.svg +11 -0
- package/frontend/skins/crt/assets/branding/farming-crt-logo-v1.png +0 -0
- package/frontend/skins/crt/assets/effects/phosphor-noise.svg +11 -0
- package/frontend/skins/crt/assets/fonts/departure-mono/DepartureMonoNerdFontMono-Regular.otf +0 -0
- package/frontend/skins/crt/assets/fonts/departure-mono/LICENSE +93 -0
- package/frontend/skins/crt/effects.js +8 -0
- package/frontend/skins/crt/index.html +1712 -0
- package/frontend/skins/crt/styles/billing.css +1003 -0
- package/frontend/skins/crt/styles/effects.css +171 -0
- package/frontend/skins/crt/styles/history.css +215 -0
- package/frontend/skins/crt/styles/monochrome-green.css +509 -0
- package/frontend/skins/crt/styles/search.css +271 -0
- package/frontend/terminal-bridge.js +192 -0
- package/frontend/theme-loader.js +84 -0
- package/frontend/themes/terminal/theme.json +24 -0
- package/frontend/vendor/ghostty-web/LICENSE +21 -0
- package/frontend/vendor/ghostty-web/__vite-browser-external-2447137e.js +4 -0
- package/frontend/vendor/ghostty-web/ghostty-vt.wasm +0 -0
- package/frontend/vendor/ghostty-web/ghostty-web.js +2963 -0
- package/frontend/vendor/ghostty-web/ghostty-web.umd.cjs +13 -0
- package/frontend/vendor/ghostty-web/index.d.ts +1842 -0
- package/index.html +23 -0
- package/package.json +144 -0
- package/scripts/sync-ghostty-vendor.js +66 -0
|
@@ -0,0 +1,901 @@
|
|
|
1
|
+
const EventEmitter = require('events');
|
|
2
|
+
const path = require('path');
|
|
3
|
+
const { spawn } = require('child_process');
|
|
4
|
+
const packageJson = require('../package.json');
|
|
5
|
+
const { AppServerConnection } = require('./app-server-api');
|
|
6
|
+
const { buildTranscriptFromEvents } = require('./codex-transcript');
|
|
7
|
+
|
|
8
|
+
const DEFAULT_CONNECT_TIMEOUT_MS = 8_000;
|
|
9
|
+
const DEFAULT_RETRY_DELAY_MS = 80;
|
|
10
|
+
const MAX_PENDING_REQUEST_DEPTH = 5;
|
|
11
|
+
const MAX_PENDING_REQUEST_ITEMS = 24;
|
|
12
|
+
const MAX_PENDING_REQUEST_STRING_LENGTH = 4_000;
|
|
13
|
+
const MAX_TRANSCRIPT_EVENTS = 12_000;
|
|
14
|
+
const CODEX_GOAL_STATUSES = new Set(['active', 'paused', 'blocked', 'usageLimited', 'budgetLimited', 'complete']);
|
|
15
|
+
const AUTO_REJECT_APPROVAL_REQUEST_METHODS = new Set([
|
|
16
|
+
'item/commandExecution/requestApproval',
|
|
17
|
+
'item/fileChange/requestApproval',
|
|
18
|
+
'item/permissions/requestApproval',
|
|
19
|
+
'applyPatchApproval',
|
|
20
|
+
'execCommandApproval',
|
|
21
|
+
]);
|
|
22
|
+
|
|
23
|
+
function normalizeCodexRuntimeMode(value) {
|
|
24
|
+
return value === 'cli' ? 'cli' : 'app-server';
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
function socketPathForCodexHome(codexHome) {
|
|
28
|
+
return path.join(
|
|
29
|
+
path.resolve(String(codexHome || '')),
|
|
30
|
+
'app-server-control',
|
|
31
|
+
'app-server-control.sock'
|
|
32
|
+
);
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
function endpointForCodexHome(codexHome) {
|
|
36
|
+
return `unix://${socketPathForCodexHome(codexHome)}`;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
function sleep(ms) {
|
|
40
|
+
return new Promise(resolve => setTimeout(resolve, ms));
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
function readThreadId(response, method) {
|
|
44
|
+
if (response && response.error) {
|
|
45
|
+
throw new Error(response.error.message || `${method} failed`);
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
const threadId = response && response.result && response.result.thread && response.result.thread.id;
|
|
49
|
+
if (typeof threadId !== 'string' || !threadId.trim()) {
|
|
50
|
+
throw new Error(`${method} did not return a Codex thread id`);
|
|
51
|
+
}
|
|
52
|
+
return threadId.trim();
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
function readTurnId(response, method) {
|
|
56
|
+
if (response && response.error) {
|
|
57
|
+
throw new Error(response.error.message || `${method} failed`);
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
const turnId = response && response.result && (
|
|
61
|
+
response.result.turnId
|
|
62
|
+
|| (response.result.turn && response.result.turn.id)
|
|
63
|
+
);
|
|
64
|
+
if (typeof turnId !== 'string' || !turnId.trim()) {
|
|
65
|
+
throw new Error(`${method} did not return a Codex turn id`);
|
|
66
|
+
}
|
|
67
|
+
return turnId.trim();
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
function readResult(response, method) {
|
|
71
|
+
if (response && response.error) {
|
|
72
|
+
throw new Error(response.error.message || `${method} failed`);
|
|
73
|
+
}
|
|
74
|
+
return response && response.result ? response.result : {};
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
function normalizeGoalStatus(status) {
|
|
78
|
+
const value = String(status || '').trim();
|
|
79
|
+
return CODEX_GOAL_STATUSES.has(value) ? value : '';
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
function normalizeGoal(goal, fallbackThreadId = '') {
|
|
83
|
+
if (!goal || typeof goal !== 'object') return null;
|
|
84
|
+
const objective = typeof goal.objective === 'string' ? goal.objective : '';
|
|
85
|
+
const status = normalizeGoalStatus(goal.status);
|
|
86
|
+
const threadId = typeof goal.threadId === 'string' && goal.threadId ? goal.threadId : String(fallbackThreadId || '');
|
|
87
|
+
if (!objective || !status || !threadId) return null;
|
|
88
|
+
return {
|
|
89
|
+
threadId,
|
|
90
|
+
objective,
|
|
91
|
+
status,
|
|
92
|
+
tokenBudget: Number.isFinite(Number(goal.tokenBudget)) ? Number(goal.tokenBudget) : null,
|
|
93
|
+
tokensUsed: Number.isFinite(Number(goal.tokensUsed)) ? Number(goal.tokensUsed) : 0,
|
|
94
|
+
timeUsedSeconds: Number.isFinite(Number(goal.timeUsedSeconds)) ? Number(goal.timeUsedSeconds) : 0,
|
|
95
|
+
createdAt: Number.isFinite(Number(goal.createdAt)) ? Number(goal.createdAt) : 0,
|
|
96
|
+
updatedAt: Number.isFinite(Number(goal.updatedAt)) ? Number(goal.updatedAt) : 0,
|
|
97
|
+
};
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
function runtimePermissions(mode) {
|
|
101
|
+
if (mode === 'ask') {
|
|
102
|
+
return {
|
|
103
|
+
approvalPolicy: 'untrusted',
|
|
104
|
+
sandbox: 'workspace-write',
|
|
105
|
+
};
|
|
106
|
+
}
|
|
107
|
+
if (mode === 'approve') {
|
|
108
|
+
return {
|
|
109
|
+
approvalPolicy: 'on-request',
|
|
110
|
+
sandbox: 'workspace-write',
|
|
111
|
+
};
|
|
112
|
+
}
|
|
113
|
+
if (mode === 'full') {
|
|
114
|
+
return {
|
|
115
|
+
approvalPolicy: 'never',
|
|
116
|
+
sandbox: 'danger-full-access',
|
|
117
|
+
};
|
|
118
|
+
}
|
|
119
|
+
return {};
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
function threadSettingsSandboxPolicy(sandbox) {
|
|
123
|
+
// `thread/settings/update` uses the App Server's structured SandboxPolicy
|
|
124
|
+
// object, whose installed protocol is camelCase (unlike the legacy string
|
|
125
|
+
// accepted by thread/start and thread/resume).
|
|
126
|
+
if (sandbox === 'danger-full-access') return { type: 'dangerFullAccess' };
|
|
127
|
+
if (sandbox === 'workspace-write') return { type: 'workspaceWrite', writableRoots: [] };
|
|
128
|
+
return null;
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
function requestThreadParams(options = {}) {
|
|
132
|
+
const permissions = runtimePermissions(options.approvalMode);
|
|
133
|
+
const config = {};
|
|
134
|
+
if (options.reasoningEffort && options.reasoningEffort !== 'config') {
|
|
135
|
+
config.model_reasoning_effort = options.reasoningEffort;
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
return {
|
|
139
|
+
...(options.model && options.model !== 'config' ? { model: options.model } : {}),
|
|
140
|
+
...(options.serviceTier && !['default', 'config'].includes(options.serviceTier)
|
|
141
|
+
? { serviceTier: options.serviceTier }
|
|
142
|
+
: {}),
|
|
143
|
+
...(options.cwd ? { cwd: options.cwd } : {}),
|
|
144
|
+
...(options.workspaceRoot ? { runtimeWorkspaceRoots: [options.workspaceRoot] } : {}),
|
|
145
|
+
...(permissions.approvalPolicy ? { approvalPolicy: permissions.approvalPolicy } : {}),
|
|
146
|
+
...(permissions.sandbox ? { sandbox: permissions.sandbox } : {}),
|
|
147
|
+
...(Object.keys(config).length > 0 ? { config } : {}),
|
|
148
|
+
...(options.developerInstructions ? { developerInstructions: options.developerInstructions } : {}),
|
|
149
|
+
};
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
function requestTurnParams(options = {}) {
|
|
153
|
+
return {
|
|
154
|
+
threadId: options.threadId,
|
|
155
|
+
input: [{
|
|
156
|
+
type: 'text',
|
|
157
|
+
text: options.message,
|
|
158
|
+
textElements: [],
|
|
159
|
+
}],
|
|
160
|
+
...(options.cwd ? { cwd: options.cwd } : {}),
|
|
161
|
+
...(options.workspaceRoot ? { runtimeWorkspaceRoots: [options.workspaceRoot] } : {}),
|
|
162
|
+
...(options.model && options.model !== 'config' ? { model: options.model } : {}),
|
|
163
|
+
...(options.serviceTier && !['default', 'config'].includes(options.serviceTier)
|
|
164
|
+
? { serviceTier: options.serviceTier }
|
|
165
|
+
: {}),
|
|
166
|
+
...(options.reasoningEffort && options.reasoningEffort !== 'config'
|
|
167
|
+
? { effort: options.reasoningEffort }
|
|
168
|
+
: {}),
|
|
169
|
+
};
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
function cliResumeArgs(threadId, cwd) {
|
|
173
|
+
return [
|
|
174
|
+
'resume',
|
|
175
|
+
...(cwd ? ['-C', cwd] : []),
|
|
176
|
+
threadId,
|
|
177
|
+
];
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
function serializePendingRequestValue(value, depth = 0) {
|
|
181
|
+
if (typeof value === 'string') return value.slice(0, MAX_PENDING_REQUEST_STRING_LENGTH);
|
|
182
|
+
if (value === null || typeof value === 'boolean' || typeof value === 'number') return value;
|
|
183
|
+
if (depth >= MAX_PENDING_REQUEST_DEPTH) return '[omitted]';
|
|
184
|
+
if (Array.isArray(value)) {
|
|
185
|
+
return value
|
|
186
|
+
.slice(0, MAX_PENDING_REQUEST_ITEMS)
|
|
187
|
+
.map(item => serializePendingRequestValue(item, depth + 1));
|
|
188
|
+
}
|
|
189
|
+
if (value && typeof value === 'object') {
|
|
190
|
+
return Object.fromEntries(
|
|
191
|
+
Object.entries(value)
|
|
192
|
+
.slice(0, MAX_PENDING_REQUEST_ITEMS)
|
|
193
|
+
.map(([key, item]) => [key, serializePendingRequestValue(item, depth + 1)])
|
|
194
|
+
);
|
|
195
|
+
}
|
|
196
|
+
return String(value);
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
function serializePendingServerRequest(event) {
|
|
200
|
+
const request = event && event.payload ? event.payload : {};
|
|
201
|
+
return {
|
|
202
|
+
id: String(request.id || ''),
|
|
203
|
+
method: String(request.method || ''),
|
|
204
|
+
params: serializePendingRequestValue(request.params || {}),
|
|
205
|
+
receivedAt: event && event.at ? event.at : new Date().toISOString(),
|
|
206
|
+
};
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
function approvalRejectedNotice(request) {
|
|
210
|
+
return {
|
|
211
|
+
id: `notice-${String(request.id || Date.now())}`,
|
|
212
|
+
kind: 'approval-rejected',
|
|
213
|
+
method: String(request.method || ''),
|
|
214
|
+
message: 'Permission request was declined in Chat. Increase this agent permission mode or use Terminal view to handle it.',
|
|
215
|
+
receivedAt: new Date().toISOString(),
|
|
216
|
+
};
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
class CodexAppServerRuntime extends EventEmitter {
|
|
220
|
+
constructor(options = {}) {
|
|
221
|
+
super();
|
|
222
|
+
this.connectTimeoutMs = options.connectTimeoutMs || DEFAULT_CONNECT_TIMEOUT_MS;
|
|
223
|
+
this.retryDelayMs = options.retryDelayMs || DEFAULT_RETRY_DELAY_MS;
|
|
224
|
+
this.spawnAppServer = options.spawnAppServer || spawn;
|
|
225
|
+
this.createConnection = options.createConnection || (connectionOptions => new AppServerConnection(connectionOptions));
|
|
226
|
+
this.maxTranscriptEvents = Number.isFinite(options.maxTranscriptEvents)
|
|
227
|
+
? Math.max(2, Math.floor(options.maxTranscriptEvents))
|
|
228
|
+
: MAX_TRANSCRIPT_EVENTS;
|
|
229
|
+
this.transcriptRefreshes = new Map();
|
|
230
|
+
this.clientInfo = {
|
|
231
|
+
name: 'farming',
|
|
232
|
+
title: 'Farming Codex runtime',
|
|
233
|
+
version: packageJson.version || '0.0.0',
|
|
234
|
+
};
|
|
235
|
+
this.homes = new Map();
|
|
236
|
+
this.bindings = new Map();
|
|
237
|
+
this.transcripts = new Map();
|
|
238
|
+
this.disposed = false;
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
homeEntry(codexHome) {
|
|
242
|
+
const rawHomePath = String(codexHome || '').trim();
|
|
243
|
+
if (!rawHomePath) throw new Error('Codex home path is required for App Server mode');
|
|
244
|
+
const homePath = path.resolve(rawHomePath);
|
|
245
|
+
|
|
246
|
+
let entry = this.homes.get(homePath);
|
|
247
|
+
if (entry) return entry;
|
|
248
|
+
|
|
249
|
+
entry = {
|
|
250
|
+
homePath,
|
|
251
|
+
endpoint: endpointForCodexHome(homePath),
|
|
252
|
+
socketPath: socketPathForCodexHome(homePath),
|
|
253
|
+
connection: null,
|
|
254
|
+
connectPromise: null,
|
|
255
|
+
spawnedByFarming: false,
|
|
256
|
+
child: null,
|
|
257
|
+
lastError: '',
|
|
258
|
+
lastConnectedAt: null,
|
|
259
|
+
agentIds: new Set(),
|
|
260
|
+
};
|
|
261
|
+
entry.connection = this.createRuntimeConnection(entry);
|
|
262
|
+
this.homes.set(homePath, entry);
|
|
263
|
+
return entry;
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
createRuntimeConnection(entry) {
|
|
267
|
+
const connection = this.createConnection({
|
|
268
|
+
provider: 'codex',
|
|
269
|
+
endpoint: entry.endpoint,
|
|
270
|
+
experimentalApi: true,
|
|
271
|
+
clientInfo: this.clientInfo,
|
|
272
|
+
});
|
|
273
|
+
connection.subscribe(event => this.handleConnectionEvent(entry, event), { replay: false });
|
|
274
|
+
return connection;
|
|
275
|
+
}
|
|
276
|
+
|
|
277
|
+
handleConnectionEvent(entry, event) {
|
|
278
|
+
if (event.kind === 'transport') {
|
|
279
|
+
if (event.payload && event.payload.state === 'connected') {
|
|
280
|
+
entry.lastConnectedAt = event.at;
|
|
281
|
+
entry.lastError = '';
|
|
282
|
+
}
|
|
283
|
+
if (event.payload && event.payload.state === 'error') {
|
|
284
|
+
entry.lastError = String(event.payload.error || 'Codex App Server transport failed');
|
|
285
|
+
}
|
|
286
|
+
if (event.payload && event.payload.state === 'closed') {
|
|
287
|
+
for (const agentId of entry.agentIds) {
|
|
288
|
+
this.emitAgentRuntime(agentId, {
|
|
289
|
+
state: 'disconnected',
|
|
290
|
+
error: entry.lastError || 'Codex App Server connection closed',
|
|
291
|
+
pendingRequestId: '',
|
|
292
|
+
pendingRequestMethod: '',
|
|
293
|
+
pendingRequest: null,
|
|
294
|
+
});
|
|
295
|
+
}
|
|
296
|
+
}
|
|
297
|
+
return;
|
|
298
|
+
}
|
|
299
|
+
|
|
300
|
+
if (event.kind === 'server-request') {
|
|
301
|
+
const request = event.payload || {};
|
|
302
|
+
const threadId = request.params && request.params.threadId;
|
|
303
|
+
const binding = this.bindingForThread(threadId, entry);
|
|
304
|
+
if (binding) {
|
|
305
|
+
if (AUTO_REJECT_APPROVAL_REQUEST_METHODS.has(String(request.method || ''))) {
|
|
306
|
+
try {
|
|
307
|
+
entry.connection.rejectServerRequest(request.id, {
|
|
308
|
+
code: -32000,
|
|
309
|
+
message: 'Permission request declined in Farming Chat. Increase permissions or use Terminal view.',
|
|
310
|
+
});
|
|
311
|
+
} catch (error) {
|
|
312
|
+
entry.lastError = error && error.message ? error.message : String(error);
|
|
313
|
+
}
|
|
314
|
+
this.emitAgentRuntime(binding.agentId, {
|
|
315
|
+
notice: approvalRejectedNotice(request),
|
|
316
|
+
state: binding.turnId ? 'working' : 'idle',
|
|
317
|
+
pendingRequestId: '',
|
|
318
|
+
pendingRequestMethod: '',
|
|
319
|
+
pendingRequest: null,
|
|
320
|
+
});
|
|
321
|
+
return;
|
|
322
|
+
}
|
|
323
|
+
const pendingRequest = serializePendingServerRequest(event);
|
|
324
|
+
this.emitAgentRuntime(binding.agentId, {
|
|
325
|
+
pendingRequestId: pendingRequest.id,
|
|
326
|
+
pendingRequestMethod: pendingRequest.method,
|
|
327
|
+
pendingRequest,
|
|
328
|
+
notice: null,
|
|
329
|
+
state: 'waiting-for-input',
|
|
330
|
+
});
|
|
331
|
+
}
|
|
332
|
+
return;
|
|
333
|
+
}
|
|
334
|
+
|
|
335
|
+
if (event.kind !== 'notification') return;
|
|
336
|
+
const message = event.payload || {};
|
|
337
|
+
const params = message.params || {};
|
|
338
|
+
const binding = this.bindingForThread(params.threadId, entry);
|
|
339
|
+
if (!binding) return;
|
|
340
|
+
|
|
341
|
+
this.appendTranscriptEvent(binding.agentId, message);
|
|
342
|
+
|
|
343
|
+
if (message.method === 'turn/started') {
|
|
344
|
+
const turnId = params.turn && params.turn.id;
|
|
345
|
+
if (turnId) binding.turnId = turnId;
|
|
346
|
+
this.emitAgentRuntime(binding.agentId, {
|
|
347
|
+
turnId: binding.turnId || '',
|
|
348
|
+
state: 'working',
|
|
349
|
+
notice: null,
|
|
350
|
+
pendingRequestId: '',
|
|
351
|
+
pendingRequestMethod: '',
|
|
352
|
+
});
|
|
353
|
+
return;
|
|
354
|
+
}
|
|
355
|
+
|
|
356
|
+
if (message.method === 'turn/completed') {
|
|
357
|
+
const turnId = params.turn && params.turn.id;
|
|
358
|
+
if (!turnId || turnId === binding.turnId) binding.turnId = '';
|
|
359
|
+
this.emitAgentRuntime(binding.agentId, {
|
|
360
|
+
turnId: binding.turnId,
|
|
361
|
+
state: 'idle',
|
|
362
|
+
cliResumable: true,
|
|
363
|
+
pendingRequestId: '',
|
|
364
|
+
pendingRequestMethod: '',
|
|
365
|
+
pendingRequest: null,
|
|
366
|
+
});
|
|
367
|
+
return;
|
|
368
|
+
}
|
|
369
|
+
|
|
370
|
+
if (message.method === 'thread/status/changed') {
|
|
371
|
+
const status = String(params.status || '');
|
|
372
|
+
const state = /in.?progress|working|running/i.test(status)
|
|
373
|
+
? 'working'
|
|
374
|
+
: /idle|completed/i.test(status)
|
|
375
|
+
? 'idle'
|
|
376
|
+
: status || 'connected';
|
|
377
|
+
this.emitAgentRuntime(binding.agentId, { state });
|
|
378
|
+
return;
|
|
379
|
+
}
|
|
380
|
+
|
|
381
|
+
if (message.method === 'thread/goal/updated') {
|
|
382
|
+
this.emitAgentRuntime(binding.agentId, {
|
|
383
|
+
goal: normalizeGoal(params.goal, params.threadId),
|
|
384
|
+
});
|
|
385
|
+
return;
|
|
386
|
+
}
|
|
387
|
+
|
|
388
|
+
if (message.method === 'thread/goal/cleared') {
|
|
389
|
+
this.emitAgentRuntime(binding.agentId, {
|
|
390
|
+
goal: null,
|
|
391
|
+
});
|
|
392
|
+
}
|
|
393
|
+
}
|
|
394
|
+
|
|
395
|
+
bindingForThread(threadId, entry) {
|
|
396
|
+
if (typeof threadId === 'string' && threadId) {
|
|
397
|
+
for (const binding of this.bindings.values()) {
|
|
398
|
+
if (binding.threadId === threadId && binding.entry === entry) return binding;
|
|
399
|
+
}
|
|
400
|
+
}
|
|
401
|
+
if (entry.agentIds.size === 1) {
|
|
402
|
+
return this.bindings.get(Array.from(entry.agentIds)[0]) || null;
|
|
403
|
+
}
|
|
404
|
+
return null;
|
|
405
|
+
}
|
|
406
|
+
|
|
407
|
+
emitAgentRuntime(agentId, patch) {
|
|
408
|
+
const binding = this.bindings.get(agentId);
|
|
409
|
+
if (binding) {
|
|
410
|
+
if (Object.prototype.hasOwnProperty.call(patch, 'turnId')) {
|
|
411
|
+
binding.turnId = patch.turnId || '';
|
|
412
|
+
}
|
|
413
|
+
if (Object.prototype.hasOwnProperty.call(patch, 'state')) {
|
|
414
|
+
binding.state = patch.state || binding.state;
|
|
415
|
+
}
|
|
416
|
+
}
|
|
417
|
+
this.emit('agent-runtime', { agentId, ...patch });
|
|
418
|
+
}
|
|
419
|
+
|
|
420
|
+
async connectEntry(entry, options = {}) {
|
|
421
|
+
try {
|
|
422
|
+
await entry.connection.connect();
|
|
423
|
+
entry.lastConnectedAt = new Date().toISOString();
|
|
424
|
+
entry.lastError = '';
|
|
425
|
+
return entry;
|
|
426
|
+
} catch (error) {
|
|
427
|
+
entry.lastError = error && error.message ? error.message : String(error);
|
|
428
|
+
if (options.throwOnFailure === true) throw error;
|
|
429
|
+
return null;
|
|
430
|
+
}
|
|
431
|
+
}
|
|
432
|
+
|
|
433
|
+
async spawnAndConnect(entry, options) {
|
|
434
|
+
const executable = String(options.executable || '').trim();
|
|
435
|
+
if (!executable) throw new Error('Codex executable is required for App Server mode');
|
|
436
|
+
|
|
437
|
+
let child;
|
|
438
|
+
try {
|
|
439
|
+
child = this.spawnAppServer(executable, ['app-server', '--listen', 'unix://'], {
|
|
440
|
+
cwd: options.cwd || process.cwd(),
|
|
441
|
+
env: options.env,
|
|
442
|
+
detached: true,
|
|
443
|
+
stdio: 'ignore',
|
|
444
|
+
});
|
|
445
|
+
if (child && typeof child.unref === 'function') child.unref();
|
|
446
|
+
} catch (error) {
|
|
447
|
+
throw new Error(`Failed to launch Codex App Server: ${error.message || error}`, { cause: error });
|
|
448
|
+
}
|
|
449
|
+
|
|
450
|
+
entry.child = child || null;
|
|
451
|
+
entry.spawnedByFarming = true;
|
|
452
|
+
if (child && typeof child.once === 'function') {
|
|
453
|
+
child.once('error', error => {
|
|
454
|
+
entry.lastError = error && error.message ? error.message : String(error);
|
|
455
|
+
});
|
|
456
|
+
child.once('exit', (code, signal) => {
|
|
457
|
+
entry.child = null;
|
|
458
|
+
// Some package launchers hand the long-lived native binary to a child
|
|
459
|
+
// process and then exit themselves. Once the socket is healthy, that
|
|
460
|
+
// wrapper exit is not an App Server failure.
|
|
461
|
+
const connected = entry.connection && typeof entry.connection.status === 'function'
|
|
462
|
+
&& entry.connection.status().connected;
|
|
463
|
+
if (code !== 0 && signal !== 'SIGTERM' && !connected) {
|
|
464
|
+
entry.lastError = `Codex App Server exited (${signal || code})`;
|
|
465
|
+
}
|
|
466
|
+
});
|
|
467
|
+
}
|
|
468
|
+
|
|
469
|
+
const deadline = Date.now() + this.connectTimeoutMs;
|
|
470
|
+
let lastError = null;
|
|
471
|
+
while (Date.now() < deadline) {
|
|
472
|
+
const connected = await this.connectEntry(entry);
|
|
473
|
+
if (connected) return entry;
|
|
474
|
+
lastError = entry.lastError;
|
|
475
|
+
await sleep(this.retryDelayMs);
|
|
476
|
+
}
|
|
477
|
+
throw new Error(`Timed out waiting for Codex App Server at ${entry.socketPath}${lastError ? `: ${lastError}` : ''}`);
|
|
478
|
+
}
|
|
479
|
+
|
|
480
|
+
async ensure(options = {}) {
|
|
481
|
+
if (this.disposed) throw new Error('Codex App Server runtime is shut down');
|
|
482
|
+
const entry = this.homeEntry(options.codexHome);
|
|
483
|
+
if (entry.connectPromise) return entry.connectPromise;
|
|
484
|
+
|
|
485
|
+
entry.connectPromise = (async () => {
|
|
486
|
+
const existing = await this.connectEntry(entry);
|
|
487
|
+
if (existing) return entry;
|
|
488
|
+
|
|
489
|
+
entry.connection.close();
|
|
490
|
+
entry.connection = this.createRuntimeConnection(entry);
|
|
491
|
+
return this.spawnAndConnect(entry, options);
|
|
492
|
+
})().finally(() => {
|
|
493
|
+
entry.connectPromise = null;
|
|
494
|
+
});
|
|
495
|
+
return entry.connectPromise;
|
|
496
|
+
}
|
|
497
|
+
|
|
498
|
+
bindAgent(agentId, entry, threadId, options = {}) {
|
|
499
|
+
const existing = this.bindings.get(agentId);
|
|
500
|
+
if (existing && existing.entry !== entry) {
|
|
501
|
+
existing.entry.agentIds.delete(agentId);
|
|
502
|
+
}
|
|
503
|
+
const binding = {
|
|
504
|
+
agentId,
|
|
505
|
+
entry,
|
|
506
|
+
threadId,
|
|
507
|
+
turnId: options.turnId || '',
|
|
508
|
+
state: options.state || 'idle',
|
|
509
|
+
options: { ...options },
|
|
510
|
+
};
|
|
511
|
+
this.bindings.set(agentId, binding);
|
|
512
|
+
entry.agentIds.add(agentId);
|
|
513
|
+
this.emitAgentRuntime(agentId, {
|
|
514
|
+
threadId,
|
|
515
|
+
turnId: binding.turnId,
|
|
516
|
+
state: binding.state,
|
|
517
|
+
error: '',
|
|
518
|
+
});
|
|
519
|
+
return binding;
|
|
520
|
+
}
|
|
521
|
+
|
|
522
|
+
appendTranscriptEvent(agentId, message) {
|
|
523
|
+
if (!agentId || !message || typeof message.method !== 'string') return;
|
|
524
|
+
const transcript = this.transcripts.get(agentId) || { events: [], updatedAt: '', sequence: 0, truncated: false };
|
|
525
|
+
transcript.sequence = Number(transcript.sequence || 0) + 1;
|
|
526
|
+
transcript.events.push({
|
|
527
|
+
method: message.method,
|
|
528
|
+
params: message.params && typeof message.params === 'object' ? message.params : {},
|
|
529
|
+
farmingSequence: transcript.sequence,
|
|
530
|
+
});
|
|
531
|
+
transcript.updatedAt = new Date().toISOString();
|
|
532
|
+
this.transcripts.set(agentId, transcript);
|
|
533
|
+
this.emitAgentRuntime(agentId, { transcriptUpdatedAt: transcript.updatedAt });
|
|
534
|
+
if (transcript.events.length > this.maxTranscriptEvents) {
|
|
535
|
+
void this.refreshTranscriptSnapshot(agentId);
|
|
536
|
+
}
|
|
537
|
+
}
|
|
538
|
+
|
|
539
|
+
async refreshTranscriptSnapshot(agentId) {
|
|
540
|
+
const existing = this.transcriptRefreshes.get(agentId);
|
|
541
|
+
if (existing) return existing;
|
|
542
|
+
const binding = this.bindings.get(agentId);
|
|
543
|
+
const transcript = this.transcripts.get(agentId);
|
|
544
|
+
if (!binding || !transcript) return null;
|
|
545
|
+
|
|
546
|
+
const boundarySequence = Number(transcript.sequence || 0);
|
|
547
|
+
const refresh = (async () => {
|
|
548
|
+
let snapshotRefreshed = false;
|
|
549
|
+
try {
|
|
550
|
+
const response = await binding.entry.connection.request('thread/read', {
|
|
551
|
+
threadId: binding.threadId,
|
|
552
|
+
});
|
|
553
|
+
const snapshot = readResult(response, 'thread/read');
|
|
554
|
+
const current = this.transcripts.get(agentId);
|
|
555
|
+
if (!current) return null;
|
|
556
|
+
const trailingEvents = current.events.filter(event => (
|
|
557
|
+
Number(event && event.farmingSequence || 0) > boundarySequence
|
|
558
|
+
));
|
|
559
|
+
current.events = [{ method: 'thread/read', params: snapshot }, ...trailingEvents];
|
|
560
|
+
current.truncated = false;
|
|
561
|
+
snapshotRefreshed = true;
|
|
562
|
+
current.updatedAt = new Date().toISOString();
|
|
563
|
+
this.emitAgentRuntime(agentId, { transcriptUpdatedAt: current.updatedAt });
|
|
564
|
+
return snapshot;
|
|
565
|
+
} catch {
|
|
566
|
+
const current = this.transcripts.get(agentId);
|
|
567
|
+
const fallbackLimit = this.maxTranscriptEvents * 2;
|
|
568
|
+
if (current && current.events.length > fallbackLimit) {
|
|
569
|
+
current.events.splice(0, current.events.length - fallbackLimit);
|
|
570
|
+
current.truncated = true;
|
|
571
|
+
current.updatedAt = new Date().toISOString();
|
|
572
|
+
}
|
|
573
|
+
return null;
|
|
574
|
+
} finally {
|
|
575
|
+
this.transcriptRefreshes.delete(agentId);
|
|
576
|
+
const current = this.transcripts.get(agentId);
|
|
577
|
+
if (snapshotRefreshed && current && current.events.length > this.maxTranscriptEvents) {
|
|
578
|
+
void this.refreshTranscriptSnapshot(agentId);
|
|
579
|
+
}
|
|
580
|
+
}
|
|
581
|
+
})();
|
|
582
|
+
this.transcriptRefreshes.set(agentId, refresh);
|
|
583
|
+
return refresh;
|
|
584
|
+
}
|
|
585
|
+
|
|
586
|
+
appendComposerTranscriptInput(agentId, threadId, turnId, message) {
|
|
587
|
+
this.appendTranscriptEvent(agentId, {
|
|
588
|
+
method: 'item/started',
|
|
589
|
+
params: {
|
|
590
|
+
threadId,
|
|
591
|
+
turnId,
|
|
592
|
+
item: {
|
|
593
|
+
id: `farming-composer-${turnId}-${Date.now()}`,
|
|
594
|
+
type: 'user_message',
|
|
595
|
+
content: [{ type: 'input_text', text: message }],
|
|
596
|
+
status: 'completed',
|
|
597
|
+
},
|
|
598
|
+
},
|
|
599
|
+
});
|
|
600
|
+
}
|
|
601
|
+
|
|
602
|
+
async hydrateTranscript(binding) {
|
|
603
|
+
try {
|
|
604
|
+
const response = await binding.entry.connection.request('thread/read', {
|
|
605
|
+
threadId: binding.threadId,
|
|
606
|
+
});
|
|
607
|
+
const snapshot = readResult(response, 'thread/read');
|
|
608
|
+
const transcript = {
|
|
609
|
+
events: [{ method: 'thread/read', params: snapshot }],
|
|
610
|
+
updatedAt: new Date().toISOString(),
|
|
611
|
+
};
|
|
612
|
+
this.transcripts.set(binding.agentId, transcript);
|
|
613
|
+
this.emitAgentRuntime(binding.agentId, { transcriptUpdatedAt: transcript.updatedAt });
|
|
614
|
+
} catch {
|
|
615
|
+
// New empty threads have no readable history. Their first App Server
|
|
616
|
+
// turn establishes the transcript through notifications instead.
|
|
617
|
+
}
|
|
618
|
+
}
|
|
619
|
+
|
|
620
|
+
async prepareAgent(options = {}) {
|
|
621
|
+
const entry = await this.ensure(options);
|
|
622
|
+
const existingThreadId = options.resumeThreadId && options.resumeThreadId !== options.temporaryThreadId
|
|
623
|
+
? String(options.resumeThreadId)
|
|
624
|
+
: '';
|
|
625
|
+
const params = requestThreadParams(options);
|
|
626
|
+
try {
|
|
627
|
+
const response = existingThreadId
|
|
628
|
+
? await entry.connection.request('thread/resume', { threadId: existingThreadId, ...params })
|
|
629
|
+
: await entry.connection.request('thread/start', params);
|
|
630
|
+
const threadId = readThreadId(response, existingThreadId ? 'thread/resume' : 'thread/start');
|
|
631
|
+
const binding = this.bindAgent(options.agentId, entry, threadId, {
|
|
632
|
+
...options,
|
|
633
|
+
state: 'idle',
|
|
634
|
+
});
|
|
635
|
+
await this.hydrateTranscript(binding);
|
|
636
|
+
return {
|
|
637
|
+
threadId,
|
|
638
|
+
resumed: Boolean(existingThreadId),
|
|
639
|
+
endpoint: entry.endpoint,
|
|
640
|
+
};
|
|
641
|
+
} catch (error) {
|
|
642
|
+
this.releaseUnusedEntry(entry);
|
|
643
|
+
throw error;
|
|
644
|
+
}
|
|
645
|
+
}
|
|
646
|
+
|
|
647
|
+
async reattachAgent(options = {}) {
|
|
648
|
+
const existing = this.bindings.get(options.agentId);
|
|
649
|
+
if (existing) return existing;
|
|
650
|
+
const threadId = String(options.threadId || '').trim();
|
|
651
|
+
if (!threadId) throw new Error('Codex App Server agent is missing its thread id');
|
|
652
|
+
|
|
653
|
+
const entry = await this.ensure(options);
|
|
654
|
+
const response = await entry.connection.request('thread/resume', {
|
|
655
|
+
threadId,
|
|
656
|
+
...requestThreadParams(options),
|
|
657
|
+
});
|
|
658
|
+
const resolvedThreadId = readThreadId(response, 'thread/resume');
|
|
659
|
+
const binding = this.bindAgent(options.agentId, entry, resolvedThreadId, {
|
|
660
|
+
...options,
|
|
661
|
+
state: 'idle',
|
|
662
|
+
});
|
|
663
|
+
await this.hydrateTranscript(binding);
|
|
664
|
+
return binding;
|
|
665
|
+
}
|
|
666
|
+
|
|
667
|
+
async submitComposerMessage(options = {}) {
|
|
668
|
+
const message = String(options.message || '').trim();
|
|
669
|
+
if (!message) throw new Error('Composer message is empty');
|
|
670
|
+
|
|
671
|
+
let binding = this.bindings.get(options.agentId);
|
|
672
|
+
if (!binding) binding = await this.reattachAgent(options);
|
|
673
|
+
const { entry } = binding;
|
|
674
|
+
|
|
675
|
+
if (binding.turnId) {
|
|
676
|
+
const response = await entry.connection.request('turn/steer', {
|
|
677
|
+
threadId: binding.threadId,
|
|
678
|
+
expectedTurnId: binding.turnId,
|
|
679
|
+
input: [{
|
|
680
|
+
type: 'text',
|
|
681
|
+
text: message,
|
|
682
|
+
textElements: [],
|
|
683
|
+
}],
|
|
684
|
+
});
|
|
685
|
+
const turnId = readTurnId(response, 'turn/steer');
|
|
686
|
+
this.appendComposerTranscriptInput(binding.agentId, binding.threadId, turnId, message);
|
|
687
|
+
this.emitAgentRuntime(binding.agentId, {
|
|
688
|
+
turnId,
|
|
689
|
+
state: 'working',
|
|
690
|
+
});
|
|
691
|
+
return { kind: 'steer', threadId: binding.threadId, turnId };
|
|
692
|
+
}
|
|
693
|
+
|
|
694
|
+
const response = await entry.connection.request('turn/start', requestTurnParams({
|
|
695
|
+
...binding.options,
|
|
696
|
+
...options,
|
|
697
|
+
threadId: binding.threadId,
|
|
698
|
+
message,
|
|
699
|
+
}));
|
|
700
|
+
const turnId = readTurnId(response, 'turn/start');
|
|
701
|
+
this.appendComposerTranscriptInput(binding.agentId, binding.threadId, turnId, message);
|
|
702
|
+
this.emitAgentRuntime(binding.agentId, {
|
|
703
|
+
turnId,
|
|
704
|
+
state: 'working',
|
|
705
|
+
});
|
|
706
|
+
return { kind: 'start', threadId: binding.threadId, turnId };
|
|
707
|
+
}
|
|
708
|
+
|
|
709
|
+
async updateAgentPermissionMode(options = {}) {
|
|
710
|
+
const permissions = runtimePermissions(options.approvalMode);
|
|
711
|
+
const sandboxPolicy = threadSettingsSandboxPolicy(permissions.sandbox);
|
|
712
|
+
if (!permissions.approvalPolicy || !sandboxPolicy) {
|
|
713
|
+
throw new Error('Custom App Server permission mode cannot be applied without a named permission profile');
|
|
714
|
+
}
|
|
715
|
+
|
|
716
|
+
let binding = this.bindings.get(options.agentId);
|
|
717
|
+
if (!binding) binding = await this.reattachAgent(options);
|
|
718
|
+
|
|
719
|
+
const response = await binding.entry.connection.request('thread/settings/update', {
|
|
720
|
+
threadId: binding.threadId,
|
|
721
|
+
approvalPolicy: permissions.approvalPolicy,
|
|
722
|
+
sandboxPolicy,
|
|
723
|
+
});
|
|
724
|
+
if (response && response.error) {
|
|
725
|
+
throw new Error(response.error.message || 'thread/settings/update failed');
|
|
726
|
+
}
|
|
727
|
+
|
|
728
|
+
binding.options = { ...binding.options, ...options };
|
|
729
|
+
this.emitAgentRuntime(binding.agentId, {
|
|
730
|
+
permissionMode: options.approvalMode,
|
|
731
|
+
error: '',
|
|
732
|
+
});
|
|
733
|
+
return { threadId: binding.threadId };
|
|
734
|
+
}
|
|
735
|
+
|
|
736
|
+
async interruptAgent(agentId) {
|
|
737
|
+
const binding = this.bindings.get(agentId);
|
|
738
|
+
if (!binding || !binding.turnId) return false;
|
|
739
|
+
|
|
740
|
+
const response = await binding.entry.connection.request('turn/interrupt', {
|
|
741
|
+
threadId: binding.threadId,
|
|
742
|
+
turnId: binding.turnId,
|
|
743
|
+
});
|
|
744
|
+
if (response && response.error) {
|
|
745
|
+
throw new Error(response.error.message || 'turn/interrupt failed');
|
|
746
|
+
}
|
|
747
|
+
this.emitAgentRuntime(agentId, {
|
|
748
|
+
state: 'interrupting',
|
|
749
|
+
});
|
|
750
|
+
return true;
|
|
751
|
+
}
|
|
752
|
+
|
|
753
|
+
async goalBinding(options = {}) {
|
|
754
|
+
let binding = this.bindings.get(options.agentId);
|
|
755
|
+
if (!binding) binding = await this.reattachAgent(options);
|
|
756
|
+
if (!binding.threadId) throw new Error('Codex App Server thread id is required for goal management');
|
|
757
|
+
return binding;
|
|
758
|
+
}
|
|
759
|
+
|
|
760
|
+
async getAgentGoal(options = {}) {
|
|
761
|
+
const binding = await this.goalBinding(options);
|
|
762
|
+
const response = await binding.entry.connection.request('thread/goal/get', {
|
|
763
|
+
threadId: binding.threadId,
|
|
764
|
+
});
|
|
765
|
+
const goal = normalizeGoal(readResult(response, 'thread/goal/get').goal, binding.threadId);
|
|
766
|
+
this.emitAgentRuntime(binding.agentId, { goal });
|
|
767
|
+
return goal;
|
|
768
|
+
}
|
|
769
|
+
|
|
770
|
+
async setAgentGoal(options = {}) {
|
|
771
|
+
const binding = await this.goalBinding(options);
|
|
772
|
+
const params = { threadId: binding.threadId };
|
|
773
|
+
if (typeof options.objective === 'string') params.objective = options.objective;
|
|
774
|
+
if (Object.prototype.hasOwnProperty.call(options, 'status')) {
|
|
775
|
+
const status = normalizeGoalStatus(options.status);
|
|
776
|
+
if (!status) throw new Error('Unsupported Codex goal status');
|
|
777
|
+
params.status = status;
|
|
778
|
+
}
|
|
779
|
+
if (Object.prototype.hasOwnProperty.call(options, 'tokenBudget')) {
|
|
780
|
+
params.tokenBudget = Number.isFinite(Number(options.tokenBudget)) ? Number(options.tokenBudget) : null;
|
|
781
|
+
}
|
|
782
|
+
|
|
783
|
+
const response = await binding.entry.connection.request('thread/goal/set', params);
|
|
784
|
+
const goal = normalizeGoal(readResult(response, 'thread/goal/set').goal, binding.threadId);
|
|
785
|
+
this.emitAgentRuntime(binding.agentId, { goal });
|
|
786
|
+
return goal;
|
|
787
|
+
}
|
|
788
|
+
|
|
789
|
+
async clearAgentGoal(options = {}) {
|
|
790
|
+
const binding = await this.goalBinding(options);
|
|
791
|
+
const response = await binding.entry.connection.request('thread/goal/clear', {
|
|
792
|
+
threadId: binding.threadId,
|
|
793
|
+
});
|
|
794
|
+
readResult(response, 'thread/goal/clear');
|
|
795
|
+
this.emitAgentRuntime(binding.agentId, { goal: null });
|
|
796
|
+
return null;
|
|
797
|
+
}
|
|
798
|
+
|
|
799
|
+
resolveAgentServerRequest(agentId, requestId, result) {
|
|
800
|
+
const binding = this.bindings.get(agentId);
|
|
801
|
+
if (!binding) throw new Error('Codex App Server agent is not connected');
|
|
802
|
+
const response = binding.entry.connection.resolveServerRequest(requestId, result);
|
|
803
|
+
this.emitAgentRuntime(agentId, {
|
|
804
|
+
pendingRequestId: '',
|
|
805
|
+
pendingRequestMethod: '',
|
|
806
|
+
pendingRequest: null,
|
|
807
|
+
state: binding.turnId ? 'working' : 'idle',
|
|
808
|
+
});
|
|
809
|
+
return response;
|
|
810
|
+
}
|
|
811
|
+
|
|
812
|
+
rejectAgentServerRequest(agentId, requestId, error) {
|
|
813
|
+
const binding = this.bindings.get(agentId);
|
|
814
|
+
if (!binding) throw new Error('Codex App Server agent is not connected');
|
|
815
|
+
const response = binding.entry.connection.rejectServerRequest(requestId, error);
|
|
816
|
+
this.emitAgentRuntime(agentId, {
|
|
817
|
+
pendingRequestId: '',
|
|
818
|
+
pendingRequestMethod: '',
|
|
819
|
+
pendingRequest: null,
|
|
820
|
+
state: binding.turnId ? 'working' : 'idle',
|
|
821
|
+
});
|
|
822
|
+
return response;
|
|
823
|
+
}
|
|
824
|
+
|
|
825
|
+
unregisterAgent(agentId) {
|
|
826
|
+
const binding = this.bindings.get(agentId);
|
|
827
|
+
if (!binding) return;
|
|
828
|
+
binding.entry.agentIds.delete(agentId);
|
|
829
|
+
this.bindings.delete(agentId);
|
|
830
|
+
this.transcripts.delete(agentId);
|
|
831
|
+
this.releaseUnusedEntry(binding.entry);
|
|
832
|
+
}
|
|
833
|
+
|
|
834
|
+
releaseUnusedEntry(entry) {
|
|
835
|
+
if (!entry || entry.agentIds.size > 0) return;
|
|
836
|
+
entry.connection.close();
|
|
837
|
+
this.homes.delete(entry.homePath);
|
|
838
|
+
if (!entry.spawnedByFarming || !entry.child || !Number.isInteger(entry.child.pid)) return;
|
|
839
|
+
try {
|
|
840
|
+
if (process.platform !== 'win32') {
|
|
841
|
+
process.kill(-entry.child.pid, 'SIGTERM');
|
|
842
|
+
} else {
|
|
843
|
+
entry.child.kill('SIGTERM');
|
|
844
|
+
}
|
|
845
|
+
} catch (error) {
|
|
846
|
+
if (error && error.code !== 'ESRCH') {
|
|
847
|
+
console.warn('Failed to stop Codex App Server:', error && (error.message || error));
|
|
848
|
+
}
|
|
849
|
+
}
|
|
850
|
+
}
|
|
851
|
+
|
|
852
|
+
statusForAgent(agentId) {
|
|
853
|
+
const binding = this.bindings.get(agentId);
|
|
854
|
+
if (!binding) return null;
|
|
855
|
+
return {
|
|
856
|
+
endpoint: binding.entry.endpoint,
|
|
857
|
+
threadId: binding.threadId,
|
|
858
|
+
turnId: binding.turnId,
|
|
859
|
+
state: binding.state,
|
|
860
|
+
};
|
|
861
|
+
}
|
|
862
|
+
|
|
863
|
+
getAgentTranscript(agentId, options = {}) {
|
|
864
|
+
const binding = this.bindings.get(agentId);
|
|
865
|
+
if (!binding) throw new Error('Codex App Server agent is not connected');
|
|
866
|
+
const transcript = this.transcripts.get(agentId) || { events: [], updatedAt: '' };
|
|
867
|
+
const maxTurns = Number.isFinite(options.maxTurns) ? Math.max(1, Math.floor(options.maxTurns)) : undefined;
|
|
868
|
+
return {
|
|
869
|
+
available: true,
|
|
870
|
+
sessionId: binding.threadId,
|
|
871
|
+
updatedAt: transcript.updatedAt || new Date().toISOString(),
|
|
872
|
+
source: 'codex-app-server',
|
|
873
|
+
hasMoreBefore: false,
|
|
874
|
+
truncated: transcript.truncated === true,
|
|
875
|
+
turnLimit: maxTurns,
|
|
876
|
+
turns: buildTranscriptFromEvents(transcript.events, { maxTurns }),
|
|
877
|
+
};
|
|
878
|
+
}
|
|
879
|
+
|
|
880
|
+
dispose() {
|
|
881
|
+
this.disposed = true;
|
|
882
|
+
for (const entry of this.homes.values()) {
|
|
883
|
+
entry.connection.close();
|
|
884
|
+
}
|
|
885
|
+
this.homes.clear();
|
|
886
|
+
this.bindings.clear();
|
|
887
|
+
this.transcripts.clear();
|
|
888
|
+
this.transcriptRefreshes.clear();
|
|
889
|
+
}
|
|
890
|
+
}
|
|
891
|
+
|
|
892
|
+
module.exports = {
|
|
893
|
+
CodexAppServerRuntime,
|
|
894
|
+
cliResumeArgs,
|
|
895
|
+
endpointForCodexHome,
|
|
896
|
+
normalizeGoal,
|
|
897
|
+
normalizeCodexRuntimeMode,
|
|
898
|
+
requestThreadParams,
|
|
899
|
+
requestTurnParams,
|
|
900
|
+
socketPathForCodexHome,
|
|
901
|
+
};
|