@dyyz1993/codenomad 0.15.0
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/README.md +173 -0
- package/dist/api-types.js +1 -0
- package/dist/auth/auth-store.js +134 -0
- package/dist/auth/http-auth.js +37 -0
- package/dist/auth/manager.js +140 -0
- package/dist/auth/password-hash.js +32 -0
- package/dist/auth/session-manager.js +17 -0
- package/dist/auth/token-manager.js +27 -0
- package/dist/background-processes/manager.js +576 -0
- package/dist/bin.js +24 -0
- package/dist/cli-upgrade.js +53 -0
- package/dist/cli-upgrade.test.js +31 -0
- package/dist/clients/connection-manager.js +93 -0
- package/dist/config/location.js +57 -0
- package/dist/config/schema.js +71 -0
- package/dist/events/bus.js +45 -0
- package/dist/filesystem/__tests__/browser.test.js +65 -0
- package/dist/filesystem/__tests__/search-cache.test.js +40 -0
- package/dist/filesystem/browser.js +306 -0
- package/dist/filesystem/search-cache.js +43 -0
- package/dist/filesystem/search.js +135 -0
- package/dist/index.js +477 -0
- package/dist/launcher.js +149 -0
- package/dist/loader.js +21 -0
- package/dist/logger.js +109 -0
- package/dist/opencode-config/README.md +32 -0
- package/dist/opencode-config/opencode.jsonc +3 -0
- package/dist/opencode-config/package-lock.json +380 -0
- package/dist/opencode-config/package.json +9 -0
- package/dist/opencode-config/plugin/codenomad.ts +62 -0
- package/dist/opencode-config/plugin/lib/background-process.ts +265 -0
- package/dist/opencode-config/plugin/lib/client.ts +133 -0
- package/dist/opencode-config/plugin/lib/request.ts +214 -0
- package/dist/opencode-config.js +26 -0
- package/dist/plugins/channel.js +40 -0
- package/dist/plugins/handlers.js +17 -0
- package/dist/plugins/voice-mode.js +78 -0
- package/dist/releases/dev-release-monitor.js +75 -0
- package/dist/releases/release-monitor.js +107 -0
- package/dist/server/__tests__/network-addresses.test.js +68 -0
- package/dist/server/__tests__/remote-proxy.test.js +204 -0
- package/dist/server/http-server.js +926 -0
- package/dist/server/network-addresses.js +114 -0
- package/dist/server/remote-proxy.js +466 -0
- package/dist/server/routes/auth-pages/login.html +135 -0
- package/dist/server/routes/auth-pages/token.html +93 -0
- package/dist/server/routes/auth.js +148 -0
- package/dist/server/routes/background-processes.js +78 -0
- package/dist/server/routes/events.js +66 -0
- package/dist/server/routes/filesystem.js +43 -0
- package/dist/server/routes/meta.js +44 -0
- package/dist/server/routes/plugin.js +70 -0
- package/dist/server/routes/remote-proxy.js +42 -0
- package/dist/server/routes/remote-servers.js +142 -0
- package/dist/server/routes/settings.js +69 -0
- package/dist/server/routes/sidecars.js +46 -0
- package/dist/server/routes/speech.js +63 -0
- package/dist/server/routes/storage.js +52 -0
- package/dist/server/routes/workspaces.js +221 -0
- package/dist/server/routes/worktrees.js +156 -0
- package/dist/server/tls.js +224 -0
- package/dist/settings/binaries.js +37 -0
- package/dist/settings/merge-patch.js +33 -0
- package/dist/settings/migrate.js +238 -0
- package/dist/settings/public-config.js +33 -0
- package/dist/settings/service.js +101 -0
- package/dist/settings/yaml-doc-store.js +96 -0
- package/dist/sidecars/manager.js +193 -0
- package/dist/speech/providers/openai-compatible.js +189 -0
- package/dist/speech/service.js +58 -0
- package/dist/storage/instance-store.js +56 -0
- package/dist/ui/__tests__/remote-ui.test.js +67 -0
- package/dist/ui/remote-ui.js +462 -0
- package/dist/workspaces/__tests__/git-worktrees.test.js +43 -0
- package/dist/workspaces/__tests__/spawn.test.js +140 -0
- package/dist/workspaces/git-mutations.js +98 -0
- package/dist/workspaces/git-status.js +323 -0
- package/dist/workspaces/git-worktrees.js +216 -0
- package/dist/workspaces/instance-events.js +180 -0
- package/dist/workspaces/manager.js +368 -0
- package/dist/workspaces/opencode-auth.js +34 -0
- package/dist/workspaces/opencode-auth.test.js +34 -0
- package/dist/workspaces/runtime.js +366 -0
- package/dist/workspaces/spawn.js +219 -0
- package/dist/workspaces/worktree-directory.js +74 -0
- package/dist/workspaces/worktree-map.js +116 -0
- package/package.json +50 -0
- package/public/apple-touch-icon-180x180.png +0 -0
- package/public/assets/ChangesTab-BRNmSjeC.js +2 -0
- package/public/assets/CodeNomad-Icon-bmTWNPXy.png +0 -0
- package/public/assets/DiffToolbar-DPPgfx42.js +1 -0
- package/public/assets/FilesTab-sEeGPOoz.js +2 -0
- package/public/assets/GitChangesTab-tJ-TCq0c.js +2 -0
- package/public/assets/KaTeX_AMS-Regular-BQhdFMY1.woff2 +0 -0
- package/public/assets/KaTeX_AMS-Regular-DMm9YOAa.woff +0 -0
- package/public/assets/KaTeX_AMS-Regular-DRggAlZN.ttf +0 -0
- package/public/assets/KaTeX_Caligraphic-Bold-ATXxdsX0.ttf +0 -0
- package/public/assets/KaTeX_Caligraphic-Bold-BEiXGLvX.woff +0 -0
- package/public/assets/KaTeX_Caligraphic-Bold-Dq_IR9rO.woff2 +0 -0
- package/public/assets/KaTeX_Caligraphic-Regular-CTRA-rTL.woff +0 -0
- package/public/assets/KaTeX_Caligraphic-Regular-Di6jR-x-.woff2 +0 -0
- package/public/assets/KaTeX_Caligraphic-Regular-wX97UBjC.ttf +0 -0
- package/public/assets/KaTeX_Fraktur-Bold-BdnERNNW.ttf +0 -0
- package/public/assets/KaTeX_Fraktur-Bold-BsDP51OF.woff +0 -0
- package/public/assets/KaTeX_Fraktur-Bold-CL6g_b3V.woff2 +0 -0
- package/public/assets/KaTeX_Fraktur-Regular-CB_wures.ttf +0 -0
- package/public/assets/KaTeX_Fraktur-Regular-CTYiF6lA.woff2 +0 -0
- package/public/assets/KaTeX_Fraktur-Regular-Dxdc4cR9.woff +0 -0
- package/public/assets/KaTeX_Main-Bold-Cx986IdX.woff2 +0 -0
- package/public/assets/KaTeX_Main-Bold-Jm3AIy58.woff +0 -0
- package/public/assets/KaTeX_Main-Bold-waoOVXN0.ttf +0 -0
- package/public/assets/KaTeX_Main-BoldItalic-DxDJ3AOS.woff2 +0 -0
- package/public/assets/KaTeX_Main-BoldItalic-DzxPMmG6.ttf +0 -0
- package/public/assets/KaTeX_Main-BoldItalic-SpSLRI95.woff +0 -0
- package/public/assets/KaTeX_Main-Italic-3WenGoN9.ttf +0 -0
- package/public/assets/KaTeX_Main-Italic-BMLOBm91.woff +0 -0
- package/public/assets/KaTeX_Main-Italic-NWA7e6Wa.woff2 +0 -0
- package/public/assets/KaTeX_Main-Regular-B22Nviop.woff2 +0 -0
- package/public/assets/KaTeX_Main-Regular-Dr94JaBh.woff +0 -0
- package/public/assets/KaTeX_Main-Regular-ypZvNtVU.ttf +0 -0
- package/public/assets/KaTeX_Math-BoldItalic-B3XSjfu4.ttf +0 -0
- package/public/assets/KaTeX_Math-BoldItalic-CZnvNsCZ.woff2 +0 -0
- package/public/assets/KaTeX_Math-BoldItalic-iY-2wyZ7.woff +0 -0
- package/public/assets/KaTeX_Math-Italic-DA0__PXp.woff +0 -0
- package/public/assets/KaTeX_Math-Italic-flOr_0UB.ttf +0 -0
- package/public/assets/KaTeX_Math-Italic-t53AETM-.woff2 +0 -0
- package/public/assets/KaTeX_SansSerif-Bold-CFMepnvq.ttf +0 -0
- package/public/assets/KaTeX_SansSerif-Bold-D1sUS0GD.woff2 +0 -0
- package/public/assets/KaTeX_SansSerif-Bold-DbIhKOiC.woff +0 -0
- package/public/assets/KaTeX_SansSerif-Italic-C3H0VqGB.woff2 +0 -0
- package/public/assets/KaTeX_SansSerif-Italic-DN2j7dab.woff +0 -0
- package/public/assets/KaTeX_SansSerif-Italic-YYjJ1zSn.ttf +0 -0
- package/public/assets/KaTeX_SansSerif-Regular-BNo7hRIc.ttf +0 -0
- package/public/assets/KaTeX_SansSerif-Regular-CS6fqUqJ.woff +0 -0
- package/public/assets/KaTeX_SansSerif-Regular-DDBCnlJ7.woff2 +0 -0
- package/public/assets/KaTeX_Script-Regular-C5JkGWo-.ttf +0 -0
- package/public/assets/KaTeX_Script-Regular-D3wIWfF6.woff2 +0 -0
- package/public/assets/KaTeX_Script-Regular-D5yQViql.woff +0 -0
- package/public/assets/KaTeX_Size1-Regular-C195tn64.woff +0 -0
- package/public/assets/KaTeX_Size1-Regular-Dbsnue_I.ttf +0 -0
- package/public/assets/KaTeX_Size1-Regular-mCD8mA8B.woff2 +0 -0
- package/public/assets/KaTeX_Size2-Regular-B7gKUWhC.ttf +0 -0
- package/public/assets/KaTeX_Size2-Regular-Dy4dx90m.woff2 +0 -0
- package/public/assets/KaTeX_Size2-Regular-oD1tc_U0.woff +0 -0
- package/public/assets/KaTeX_Size3-Regular-CTq5MqoE.woff +0 -0
- package/public/assets/KaTeX_Size3-Regular-DgpXs0kz.ttf +0 -0
- package/public/assets/KaTeX_Size4-Regular-BF-4gkZK.woff +0 -0
- package/public/assets/KaTeX_Size4-Regular-DWFBv043.ttf +0 -0
- package/public/assets/KaTeX_Size4-Regular-Dl5lxZxV.woff2 +0 -0
- package/public/assets/KaTeX_Typewriter-Regular-C0xS9mPB.woff +0 -0
- package/public/assets/KaTeX_Typewriter-Regular-CO6r4hn1.woff2 +0 -0
- package/public/assets/KaTeX_Typewriter-Regular-D3Ib7_Hf.ttf +0 -0
- package/public/assets/SplitFilePanel-CHqNLZvU.js +1 -0
- package/public/assets/StatusTab-DMd0ByCA.js +1 -0
- package/public/assets/abap-BdImnpbu.js +1 -0
- package/public/assets/actionscript-3-CfeIJUat.js +1 -0
- package/public/assets/ada-bCR0ucgS.js +1 -0
- package/public/assets/align-justify-BWapkGTe.js +1 -0
- package/public/assets/andromeeda-C-Jbm3Hp.js +1 -0
- package/public/assets/angular-html-CU67Zn6k.js +1 -0
- package/public/assets/angular-ts-BwZT4LLn.js +1 -0
- package/public/assets/apache-Pmp26Uib.js +1 -0
- package/public/assets/apex-DhZLUxFE.js +1 -0
- package/public/assets/apl-dKokRX4l.js +1 -0
- package/public/assets/applescript-Co6uUVPk.js +1 -0
- package/public/assets/ara-BRHolxvo.js +1 -0
- package/public/assets/asciidoc-Dv7Oe6Be.js +1 -0
- package/public/assets/asm-D_Q5rh1f.js +1 -0
- package/public/assets/astro-CbQHKStN.js +1 -0
- package/public/assets/aurora-x-D-2ljcwZ.js +1 -0
- package/public/assets/awk-DMzUqQB5.js +1 -0
- package/public/assets/ayu-dark-Cv9koXgw.js +1 -0
- package/public/assets/ballerina-BFfxhgS-.js +1 -0
- package/public/assets/bat-BkioyH1T.js +1 -0
- package/public/assets/beancount-k_qm7-4y.js +1 -0
- package/public/assets/berry-D08WgyRC.js +1 -0
- package/public/assets/bibtex-CHM0blh-.js +1 -0
- package/public/assets/bicep-Bmn6On1c.js +1 -0
- package/public/assets/blade-DVc8C-J4.js +1 -0
- package/public/assets/bsl-BO_Y6i37.js +1 -0
- package/public/assets/bundle-full-CXlKQh5B.js +13 -0
- package/public/assets/c-BIGW1oBm.js +1 -0
- package/public/assets/cadence-Bv_4Rxtq.js +1 -0
- package/public/assets/cairo-KRGpt6FW.js +1 -0
- package/public/assets/catppuccin-frappe-DFWUc33u.js +1 -0
- package/public/assets/catppuccin-latte-C9dUb6Cb.js +1 -0
- package/public/assets/catppuccin-macchiato-DQyhUUbL.js +1 -0
- package/public/assets/catppuccin-mocha-D87Tk5Gz.js +1 -0
- package/public/assets/clarity-D53aC0YG.js +1 -0
- package/public/assets/clojure-P80f7IUj.js +1 -0
- package/public/assets/cmake-D1j8_8rp.js +1 -0
- package/public/assets/cobol-nwyudZeR.js +1 -0
- package/public/assets/codeowners-Bp6g37R7.js +1 -0
- package/public/assets/codeql-DsOJ9woJ.js +1 -0
- package/public/assets/coffee-Ch7k5sss.js +1 -0
- package/public/assets/common-lisp-Cg-RD9OK.js +1 -0
- package/public/assets/coq-DkFqJrB1.js +1 -0
- package/public/assets/cpp-CofmeUqb.js +1 -0
- package/public/assets/crystal-tKQVLTB8.js +1 -0
- package/public/assets/csharp-CX12Zw3r.js +1 -0
- package/public/assets/css-DPfMkruS.js +1 -0
- package/public/assets/csv-fuZLfV_i.js +1 -0
- package/public/assets/cue-D82EKSYY.js +1 -0
- package/public/assets/cypher-COkxafJQ.js +1 -0
- package/public/assets/d-85-TOEBH.js +1 -0
- package/public/assets/dark-plus-eOWES_5F.js +1 -0
- package/public/assets/dart-CF10PKvl.js +1 -0
- package/public/assets/dax-CEL-wOlO.js +1 -0
- package/public/assets/desktop-BmXAJ9_W.js +1 -0
- package/public/assets/diff-D97Zzqfu.js +1 -0
- package/public/assets/diff-viewer-BFtW5J8P.js +1 -0
- package/public/assets/docker-BcOcwvcX.js +1 -0
- package/public/assets/dotenv-Da5cRb03.js +1 -0
- package/public/assets/dracula-BzJJZx-M.js +1 -0
- package/public/assets/dracula-soft-BXkSAIEj.js +1 -0
- package/public/assets/dream-maker-BtqSS_iP.js +1 -0
- package/public/assets/edge-BkV0erSs.js +1 -0
- package/public/assets/elixir-CDX3lj18.js +1 -0
- package/public/assets/elm-DbKCFpqz.js +1 -0
- package/public/assets/emacs-lisp-C9XAeP06.js +1 -0
- package/public/assets/erb-BOJIQeun.js +1 -0
- package/public/assets/erlang-DsQrWhSR.js +1 -0
- package/public/assets/everforest-dark-BgDCqdQA.js +1 -0
- package/public/assets/everforest-light-C8M2exoo.js +1 -0
- package/public/assets/fast-diff-vendor-DgdwVvTQ.js +1 -0
- package/public/assets/fennel-BYunw83y.js +1 -0
- package/public/assets/fish-BvzEVeQv.js +1 -0
- package/public/assets/fluent-C4IJs8-o.js +1 -0
- package/public/assets/fortran-fixed-form-BZjJHVRy.js +1 -0
- package/public/assets/fortran-free-form-D22FLkUw.js +1 -0
- package/public/assets/fsharp-CXgrBDvD.js +1 -0
- package/public/assets/gdresource-B7Tvp0Sc.js +1 -0
- package/public/assets/gdscript-DTMYz4Jt.js +1 -0
- package/public/assets/gdshader-DkwncUOv.js +1 -0
- package/public/assets/genie-D0YGMca9.js +1 -0
- package/public/assets/gherkin-DyxjwDmM.js +1 -0
- package/public/assets/git-commit-F4YmCXRG.js +1 -0
- package/public/assets/git-diff-vendor-CSgooKT_.js +52 -0
- package/public/assets/git-diff-vendor-HAZkIolJ.css +19 -0
- package/public/assets/git-rebase-r7XF79zn.js +1 -0
- package/public/assets/github-dark-DHJKELXO.js +1 -0
- package/public/assets/github-dark-default-Cuk6v7N8.js +1 -0
- package/public/assets/github-dark-dimmed-DH5Ifo-i.js +1 -0
- package/public/assets/github-dark-high-contrast-E3gJ1_iC.js +1 -0
- package/public/assets/github-light-DAi9KRSo.js +1 -0
- package/public/assets/github-light-default-D7oLnXFd.js +1 -0
- package/public/assets/github-light-high-contrast-BfjtVDDH.js +1 -0
- package/public/assets/gleam-BspZqrRM.js +1 -0
- package/public/assets/glimmer-js-Rg0-pVw9.js +1 -0
- package/public/assets/glimmer-ts-U6CK756n.js +1 -0
- package/public/assets/glsl-DplSGwfg.js +1 -0
- package/public/assets/gnuplot-DdkO51Og.js +1 -0
- package/public/assets/go-Dn2_MT6a.js +1 -0
- package/public/assets/graphql-ChdNCCLP.js +1 -0
- package/public/assets/groovy-gcz8RCvz.js +1 -0
- package/public/assets/gruvbox-dark-hard-CFHQjOhq.js +1 -0
- package/public/assets/gruvbox-dark-medium-GsRaNv29.js +1 -0
- package/public/assets/gruvbox-dark-soft-CVdnzihN.js +1 -0
- package/public/assets/gruvbox-light-hard-CH1njM8p.js +1 -0
- package/public/assets/gruvbox-light-medium-DRw_LuNl.js +1 -0
- package/public/assets/gruvbox-light-soft-hJgmCMqR.js +1 -0
- package/public/assets/hack-CaT9iCJl.js +1 -0
- package/public/assets/haml-B8DHNrY2.js +1 -0
- package/public/assets/handlebars-BL8al0AC.js +1 -0
- package/public/assets/haskell-Df6bDoY_.js +1 -0
- package/public/assets/haxe-CzTSHFRz.js +1 -0
- package/public/assets/hcl-BWvSN4gD.js +1 -0
- package/public/assets/highlight-vendor-8FKMu9os.js +10 -0
- package/public/assets/hjson-D5-asLiD.js +1 -0
- package/public/assets/hlsl-D3lLCCz7.js +1 -0
- package/public/assets/houston-DnULxvSX.js +1 -0
- package/public/assets/html-GMplVEZG.js +1 -0
- package/public/assets/html-derivative-BFtXZ54Q.js +1 -0
- package/public/assets/http-jrhK8wxY.js +1 -0
- package/public/assets/hurl-irOxFIW8.js +1 -0
- package/public/assets/hxml-Bvhsp5Yf.js +1 -0
- package/public/assets/hy-DFXneXwc.js +1 -0
- package/public/assets/imba-DGztddWO.js +1 -0
- package/public/assets/index-Bdy3MTIn.js +1 -0
- package/public/assets/index-BvRe9GiS.js +1 -0
- package/public/assets/index-Ctq8RqRf.js +1 -0
- package/public/assets/index-D-NvysdX.js +1 -0
- package/public/assets/index-D6RMBXUk.js +2 -0
- package/public/assets/index-DXI9DoVB.css +1 -0
- package/public/assets/index-DYWkPhKo.js +1 -0
- package/public/assets/index-D_FDiI6a.js +1 -0
- package/public/assets/index-Dty5bSHf.js +1 -0
- package/public/assets/index-H16e4Rqc.js +1 -0
- package/public/assets/ini-BEwlwnbL.js +1 -0
- package/public/assets/java-CylS5w8V.js +1 -0
- package/public/assets/javascript-wDzz0qaB.js +1 -0
- package/public/assets/jinja-4LBKfQ-Z.js +1 -0
- package/public/assets/jison-wvAkD_A8.js +1 -0
- package/public/assets/json-Cp-IABpG.js +1 -0
- package/public/assets/json5-C9tS-k6U.js +1 -0
- package/public/assets/jsonc-Des-eS-w.js +1 -0
- package/public/assets/jsonl-DcaNXYhu.js +1 -0
- package/public/assets/jsonnet-DFQXde-d.js +1 -0
- package/public/assets/jssm-C2t-YnRu.js +1 -0
- package/public/assets/jsx-g9-lgVsj.js +1 -0
- package/public/assets/julia-C8NyazO9.js +1 -0
- package/public/assets/kanagawa-dragon-CkXjmgJE.js +1 -0
- package/public/assets/kanagawa-lotus-CfQXZHmo.js +1 -0
- package/public/assets/kanagawa-wave-DWedfzmr.js +1 -0
- package/public/assets/kdl-DV7GczEv.js +1 -0
- package/public/assets/kotlin-BdnUsdx6.js +1 -0
- package/public/assets/kusto-BvAqAH-y.js +1 -0
- package/public/assets/laserwave-DUszq2jm.js +1 -0
- package/public/assets/latex-BUKiar2Z.js +1 -0
- package/public/assets/lean-DP1Csr6i.js +1 -0
- package/public/assets/less-B1dDrJ26.js +1 -0
- package/public/assets/light-plus-B7mTdjB0.js +1 -0
- package/public/assets/liquid-DYVedYrR.js +1 -0
- package/public/assets/llvm-BtvRca6l.js +1 -0
- package/public/assets/loading-CmEVQgyj.css +1 -0
- package/public/assets/loading-W2Y_wR0P.js +1 -0
- package/public/assets/log-2UxHyX5q.js +1 -0
- package/public/assets/logo-BtOb2qkB.js +1 -0
- package/public/assets/lua-BbnMAYS6.js +1 -0
- package/public/assets/luau-CXu1NL6O.js +1 -0
- package/public/assets/main-Bala0YJ4.js +57 -0
- package/public/assets/make-CHLpvVh8.js +1 -0
- package/public/assets/markdown-Cvjx9yec.js +1 -0
- package/public/assets/markdown-Db8cvZ4Z.js +315 -0
- package/public/assets/marko-CPi9NSCl.js +1 -0
- package/public/assets/material-theme-D5KoaKCx.js +1 -0
- package/public/assets/material-theme-darker-BfHTSMKl.js +1 -0
- package/public/assets/material-theme-lighter-B0m2ddpp.js +1 -0
- package/public/assets/material-theme-ocean-CyktbL80.js +1 -0
- package/public/assets/material-theme-palenight-Csfq5Kiy.js +1 -0
- package/public/assets/matlab-D7o27uSR.js +1 -0
- package/public/assets/mdc-DUICxH0z.js +1 -0
- package/public/assets/mdx-Cmh6b_Ma.js +1 -0
- package/public/assets/mermaid-DKYwYmdq.js +1 -0
- package/public/assets/min-dark-CafNBF8u.js +1 -0
- package/public/assets/min-light-CTRr51gU.js +1 -0
- package/public/assets/mipsasm-CKIfxQSi.js +1 -0
- package/public/assets/mojo-1DNp92w6.js +1 -0
- package/public/assets/monaco-viewer-DWQqXKm3.js +26 -0
- package/public/assets/monokai-D4h5O-jR.js +1 -0
- package/public/assets/move-Bu9oaDYs.js +1 -0
- package/public/assets/narrat-DRg8JJMk.js +1 -0
- package/public/assets/nextflow-CUEJCptM.js +1 -0
- package/public/assets/nginx-DknmC5AR.js +1 -0
- package/public/assets/night-owl-C39BiMTA.js +1 -0
- package/public/assets/nim-CVrawwO9.js +1 -0
- package/public/assets/nix-BbRYJGeE.js +1 -0
- package/public/assets/nord-Ddv68eIx.js +1 -0
- package/public/assets/nushell-C-sUppwS.js +1 -0
- package/public/assets/objective-c-DXmwc3jG.js +1 -0
- package/public/assets/objective-cpp-CLxacb5B.js +1 -0
- package/public/assets/ocaml-C0hk2d4L.js +1 -0
- package/public/assets/one-dark-pro-DVMEJ2y_.js +1 -0
- package/public/assets/one-light-PoHY5YXO.js +1 -0
- package/public/assets/pascal-D93ZcfNL.js +1 -0
- package/public/assets/perl-C0TMdlhV.js +1 -0
- package/public/assets/php-CDn_0X-4.js +1 -0
- package/public/assets/pkl-u5AG7uiY.js +1 -0
- package/public/assets/plastic-3e1v2bzS.js +1 -0
- package/public/assets/plsql-ChMvpjG-.js +1 -0
- package/public/assets/po-BTJTHyun.js +1 -0
- package/public/assets/poimandres-CS3Unz2-.js +1 -0
- package/public/assets/polar-C0HS_06l.js +1 -0
- package/public/assets/postcss-CXtECtnM.js +1 -0
- package/public/assets/powerquery-CEu0bR-o.js +1 -0
- package/public/assets/powershell-Dpen1YoG.js +1 -0
- package/public/assets/prisma-Dd19v3D-.js +1 -0
- package/public/assets/prolog-CbFg5uaA.js +1 -0
- package/public/assets/proto-DyJlTyXw.js +1 -0
- package/public/assets/pug-CGlum2m_.js +1 -0
- package/public/assets/puppet-BMWR74SV.js +1 -0
- package/public/assets/purescript-CklMAg4u.js +1 -0
- package/public/assets/python-B6aJPvgy.js +1 -0
- package/public/assets/qml-3beO22l8.js +1 -0
- package/public/assets/qmldir-C8lEn-DE.js +1 -0
- package/public/assets/qss-IeuSbFQv.js +1 -0
- package/public/assets/r-DiinP2Uv.js +1 -0
- package/public/assets/racket-BqYA7rlc.js +1 -0
- package/public/assets/raku-DXvB9xmW.js +1 -0
- package/public/assets/razor-WgofotgN.js +1 -0
- package/public/assets/red-bN70gL4F.js +1 -0
- package/public/assets/reg-C-SQnVFl.js +1 -0
- package/public/assets/regexp-CDVJQ6XC.js +1 -0
- package/public/assets/rel-C3B-1QV4.js +1 -0
- package/public/assets/riscv-BM1_JUlF.js +1 -0
- package/public/assets/rose-pine-BHrmToEH.js +1 -0
- package/public/assets/rose-pine-dawn-CnK8MTSM.js +1 -0
- package/public/assets/rose-pine-moon-NleAzG8P.js +1 -0
- package/public/assets/rosmsg-BJDFO7_C.js +1 -0
- package/public/assets/rst-B0xPkSld.js +1 -0
- package/public/assets/ruby-BvKwtOVI.js +1 -0
- package/public/assets/rust-B1yitclQ.js +1 -0
- package/public/assets/sas-cz2c8ADy.js +1 -0
- package/public/assets/sass-Cj5Yp3dK.js +1 -0
- package/public/assets/scala-C151Ov-r.js +1 -0
- package/public/assets/scheme-C98Dy4si.js +1 -0
- package/public/assets/scss-OYdSNvt2.js +1 -0
- package/public/assets/sdbl-DVxCFoDh.js +1 -0
- package/public/assets/shaderlab-Dg9Lc6iA.js +1 -0
- package/public/assets/shellscript-Yzrsuije.js +1 -0
- package/public/assets/shellsession-BADoaaVG.js +1 -0
- package/public/assets/slack-dark-BthQWCQV.js +1 -0
- package/public/assets/slack-ochin-DqwNpetd.js +1 -0
- package/public/assets/smalltalk-BERRCDM3.js +1 -0
- package/public/assets/snazzy-light-Bw305WKR.js +1 -0
- package/public/assets/solarized-dark-DXbdFlpD.js +1 -0
- package/public/assets/solarized-light-L9t79GZl.js +1 -0
- package/public/assets/solidity-BbcW6ACK.js +1 -0
- package/public/assets/soy-Brmx7dQM.js +1 -0
- package/public/assets/sparql-rVzFXLq3.js +1 -0
- package/public/assets/splunk-BtCnVYZw.js +1 -0
- package/public/assets/sql-BLtJtn59.js +1 -0
- package/public/assets/ssh-config-_ykCGR6B.js +1 -0
- package/public/assets/stata-BH5u7GGu.js +1 -0
- package/public/assets/stylus-BEDo0Tqx.js +1 -0
- package/public/assets/svelte-3Dk4HxPD.js +1 -0
- package/public/assets/swift-Dg5xB15N.js +1 -0
- package/public/assets/synthwave-84-CbfX1IO0.js +1 -0
- package/public/assets/system-verilog-CnnmHF94.js +1 -0
- package/public/assets/systemd-4A_iFExJ.js +1 -0
- package/public/assets/talonscript-CkByrt1z.js +1 -0
- package/public/assets/tasl-QIJgUcNo.js +1 -0
- package/public/assets/tcl-dwOrl1Do.js +1 -0
- package/public/assets/templ-W15q3VgB.js +1 -0
- package/public/assets/terraform-BETggiCN.js +1 -0
- package/public/assets/tex-Cppo0RY3.js +1 -0
- package/public/assets/tokyo-night-hegEt444.js +1 -0
- package/public/assets/toml-vGWfd6FD.js +1 -0
- package/public/assets/tool-call-D0BYXlFe.js +59 -0
- package/public/assets/ts-tags-zn1MmPIZ.js +1 -0
- package/public/assets/tsv-B_m7g4N7.js +1 -0
- package/public/assets/tsx-COt5Ahok.js +1 -0
- package/public/assets/turtle-BsS91CYL.js +1 -0
- package/public/assets/twig-CO9l9SDP.js +1 -0
- package/public/assets/typescript-BPQ3VLAy.js +1 -0
- package/public/assets/typespec-Df68jz8_.js +1 -0
- package/public/assets/typst-DHCkPAjA.js +1 -0
- package/public/assets/unified-picker-QgONWj_1.js +1 -0
- package/public/assets/v-BcVCzyr7.js +1 -0
- package/public/assets/vala-CsfeWuGM.js +1 -0
- package/public/assets/vb-D17OF-Vu.js +1 -0
- package/public/assets/verilog-BQ8w6xss.js +1 -0
- package/public/assets/vesper-DU1UobuO.js +1 -0
- package/public/assets/vhdl-CeAyd5Ju.js +1 -0
- package/public/assets/viml-CJc9bBzg.js +1 -0
- package/public/assets/vitesse-black-Bkuqu6BP.js +1 -0
- package/public/assets/vitesse-dark-D0r3Knsf.js +1 -0
- package/public/assets/vitesse-light-CVO1_9PV.js +1 -0
- package/public/assets/vue-CCoi5OLL.js +1 -0
- package/public/assets/vue-html-DAAvJJDi.js +1 -0
- package/public/assets/vue-vine-_Ih-lPRR.js +1 -0
- package/public/assets/vyper-CDx5xZoG.js +1 -0
- package/public/assets/wasm-CG6Dc4jp.js +1 -0
- package/public/assets/wasm-MzD3tlZU.js +1 -0
- package/public/assets/wenyan-BV7otONQ.js +1 -0
- package/public/assets/wgsl-Dx-B1_4e.js +1 -0
- package/public/assets/wikitext-BhOHFoWU.js +1 -0
- package/public/assets/wit-5i3qLPDT.js +1 -0
- package/public/assets/wolfram-lXgVvXCa.js +1 -0
- package/public/assets/wrap-text-CEH9wOr_.js +1 -0
- package/public/assets/xml-sdJ4AIDG.js +1 -0
- package/public/assets/xsl-CtQFsRM5.js +1 -0
- package/public/assets/yaml-Buea-lGh.js +1 -0
- package/public/assets/zenscript-DVFEvuxE.js +1 -0
- package/public/assets/zig-VOosw3JB.js +1 -0
- package/public/favicon.ico +0 -0
- package/public/index.html +42 -0
- package/public/loading.html +33 -0
- package/public/logo.png +0 -0
- package/public/manifest.webmanifest +1 -0
- package/public/maskable-icon-512x512.png +0 -0
- package/public/monaco/vs/base/browser/ui/codicons/codicon/codicon.ttf +0 -0
- package/public/monaco/vs/base/worker/workerMain.js +31 -0
- package/public/monaco/vs/basic-languages/cpp/cpp.js +10 -0
- package/public/monaco/vs/basic-languages/kotlin/kotlin.js +10 -0
- package/public/monaco/vs/basic-languages/markdown/markdown.js +10 -0
- package/public/monaco/vs/basic-languages/python/python.js +10 -0
- package/public/monaco/vs/editor/editor.main.css +8 -0
- package/public/monaco/vs/editor/editor.main.js +798 -0
- package/public/monaco/vs/language/css/cssMode.js +13 -0
- package/public/monaco/vs/language/css/cssWorker.js +77 -0
- package/public/monaco/vs/language/html/htmlMode.js +13 -0
- package/public/monaco/vs/language/html/htmlWorker.js +454 -0
- package/public/monaco/vs/language/json/jsonMode.js +19 -0
- package/public/monaco/vs/language/json/jsonWorker.js +42 -0
- package/public/monaco/vs/language/typescript/tsMode.js +20 -0
- package/public/monaco/vs/language/typescript/tsWorker.js +51328 -0
- package/public/monaco/vs/loader.js +11 -0
- package/public/monaco.worker.js +7 -0
- package/public/pwa-192x192.png +0 -0
- package/public/pwa-512x512.png +0 -0
- package/public/pwa-64x64.png +0 -0
- package/public/registerSW.js +1 -0
- package/public/sw.js +1 -0
- package/public/ui-version.json +3 -0
- package/public/workbox-60d14903.js +1 -0
|
@@ -0,0 +1,576 @@
|
|
|
1
|
+
import { spawn, spawnSync } from "child_process";
|
|
2
|
+
import { createWriteStream, existsSync, promises as fs } from "fs";
|
|
3
|
+
import path from "path";
|
|
4
|
+
import { randomBytes } from "crypto";
|
|
5
|
+
const ROOT_DIR = ".codenomad/background_processes";
|
|
6
|
+
const INDEX_FILE = "index.json";
|
|
7
|
+
const OUTPUT_FILE = "output.txt";
|
|
8
|
+
const STOP_TIMEOUT_MS = 2000;
|
|
9
|
+
const EXIT_WAIT_TIMEOUT_MS = 5000;
|
|
10
|
+
const MAX_OUTPUT_BYTES = 20 * 1024;
|
|
11
|
+
const OUTPUT_PUBLISH_INTERVAL_MS = 1000;
|
|
12
|
+
export class BackgroundProcessManager {
|
|
13
|
+
constructor(deps) {
|
|
14
|
+
this.deps = deps;
|
|
15
|
+
this.running = new Map();
|
|
16
|
+
this.deps.eventBus.on("workspace.stopped", (event) => this.cleanupWorkspace(event.workspaceId));
|
|
17
|
+
this.deps.eventBus.on("workspace.error", (event) => this.cleanupWorkspace(event.workspace.id));
|
|
18
|
+
}
|
|
19
|
+
async list(workspaceId) {
|
|
20
|
+
const records = await this.readIndex(workspaceId);
|
|
21
|
+
const enriched = await Promise.all(records.map(async (record) => ({
|
|
22
|
+
...this.toPublicProcess(record),
|
|
23
|
+
outputSizeBytes: await this.getOutputSize(workspaceId, record.id),
|
|
24
|
+
})));
|
|
25
|
+
return enriched;
|
|
26
|
+
}
|
|
27
|
+
async start(workspaceId, title, command, options = {}) {
|
|
28
|
+
const workspace = this.deps.workspaceManager.get(workspaceId);
|
|
29
|
+
if (!workspace) {
|
|
30
|
+
throw new Error("Workspace not found");
|
|
31
|
+
}
|
|
32
|
+
const id = this.generateId();
|
|
33
|
+
const processDir = await this.ensureProcessDir(workspaceId, id);
|
|
34
|
+
const outputPath = path.join(processDir, OUTPUT_FILE);
|
|
35
|
+
const outputStream = createWriteStream(outputPath, { flags: "a" });
|
|
36
|
+
const { shellCommand, shellArgs, spawnOptions } = this.buildShellSpawn(command);
|
|
37
|
+
const child = spawn(shellCommand, shellArgs, {
|
|
38
|
+
cwd: workspace.path,
|
|
39
|
+
stdio: ["ignore", "pipe", "pipe"],
|
|
40
|
+
detached: process.platform !== "win32",
|
|
41
|
+
...spawnOptions,
|
|
42
|
+
});
|
|
43
|
+
child.on("exit", () => {
|
|
44
|
+
this.killProcessTree(child, "SIGTERM");
|
|
45
|
+
});
|
|
46
|
+
const record = {
|
|
47
|
+
id,
|
|
48
|
+
workspaceId,
|
|
49
|
+
title,
|
|
50
|
+
command,
|
|
51
|
+
cwd: workspace.path,
|
|
52
|
+
status: "running",
|
|
53
|
+
pid: child.pid,
|
|
54
|
+
startedAt: new Date().toISOString(),
|
|
55
|
+
outputSizeBytes: 0,
|
|
56
|
+
notify: options.notify && options.notification
|
|
57
|
+
? {
|
|
58
|
+
sessionID: options.notification.sessionID,
|
|
59
|
+
directory: options.notification.directory,
|
|
60
|
+
}
|
|
61
|
+
: undefined,
|
|
62
|
+
};
|
|
63
|
+
const runningState = {
|
|
64
|
+
id,
|
|
65
|
+
child,
|
|
66
|
+
outputPath,
|
|
67
|
+
exitPromise: Promise.resolve(),
|
|
68
|
+
workspaceId,
|
|
69
|
+
};
|
|
70
|
+
const exitPromise = new Promise((resolve) => {
|
|
71
|
+
child.on("close", async (code) => {
|
|
72
|
+
await new Promise((resolve) => outputStream.end(resolve));
|
|
73
|
+
this.running.delete(id);
|
|
74
|
+
const completion = runningState.completion ?? this.completionFromExit(code);
|
|
75
|
+
record.terminalReason = completion.reason;
|
|
76
|
+
record.status = this.statusFromReason(completion.reason);
|
|
77
|
+
record.exitCode = code === null ? undefined : code;
|
|
78
|
+
record.stoppedAt = new Date().toISOString();
|
|
79
|
+
await this.finalizeRecord(workspaceId, record, completion);
|
|
80
|
+
resolve();
|
|
81
|
+
});
|
|
82
|
+
});
|
|
83
|
+
runningState.exitPromise = exitPromise;
|
|
84
|
+
this.running.set(id, runningState);
|
|
85
|
+
let lastPublishAt = 0;
|
|
86
|
+
const maybePublishSize = () => {
|
|
87
|
+
const now = Date.now();
|
|
88
|
+
if (now - lastPublishAt < OUTPUT_PUBLISH_INTERVAL_MS) {
|
|
89
|
+
return;
|
|
90
|
+
}
|
|
91
|
+
lastPublishAt = now;
|
|
92
|
+
this.publishUpdate(workspaceId, record);
|
|
93
|
+
};
|
|
94
|
+
child.stdout?.on("data", (data) => {
|
|
95
|
+
outputStream.write(data);
|
|
96
|
+
record.outputSizeBytes = (record.outputSizeBytes ?? 0) + data.length;
|
|
97
|
+
maybePublishSize();
|
|
98
|
+
});
|
|
99
|
+
child.stderr?.on("data", (data) => {
|
|
100
|
+
outputStream.write(data);
|
|
101
|
+
record.outputSizeBytes = (record.outputSizeBytes ?? 0) + data.length;
|
|
102
|
+
maybePublishSize();
|
|
103
|
+
});
|
|
104
|
+
await this.upsertIndex(workspaceId, record);
|
|
105
|
+
record.outputSizeBytes = await this.getOutputSize(workspaceId, record.id);
|
|
106
|
+
this.publishUpdate(workspaceId, record);
|
|
107
|
+
return this.toPublicProcess(record);
|
|
108
|
+
}
|
|
109
|
+
async stop(workspaceId, processId) {
|
|
110
|
+
const record = await this.findProcess(workspaceId, processId);
|
|
111
|
+
if (!record) {
|
|
112
|
+
return null;
|
|
113
|
+
}
|
|
114
|
+
const running = this.running.get(processId);
|
|
115
|
+
if (running?.child && !running.child.killed) {
|
|
116
|
+
running.completion = { reason: "user_stopped", endContext: "normal" };
|
|
117
|
+
this.killProcessTree(running.child, "SIGTERM");
|
|
118
|
+
await this.waitForExit(running);
|
|
119
|
+
const updated = await this.findProcess(workspaceId, processId);
|
|
120
|
+
return updated ? this.toPublicProcess(updated) : this.toPublicProcess(record);
|
|
121
|
+
}
|
|
122
|
+
if (record.status === "running") {
|
|
123
|
+
record.status = "stopped";
|
|
124
|
+
record.terminalReason = "user_stopped";
|
|
125
|
+
record.stoppedAt = new Date().toISOString();
|
|
126
|
+
await this.finalizeRecord(workspaceId, record, { reason: "user_stopped", endContext: "normal" });
|
|
127
|
+
}
|
|
128
|
+
return this.toPublicProcess(record);
|
|
129
|
+
}
|
|
130
|
+
async terminate(workspaceId, processId) {
|
|
131
|
+
const record = await this.findProcess(workspaceId, processId);
|
|
132
|
+
if (!record)
|
|
133
|
+
return;
|
|
134
|
+
const running = this.running.get(processId);
|
|
135
|
+
if (running?.child && !running.child.killed) {
|
|
136
|
+
running.completion = { reason: "user_terminated", endContext: "normal", removeAfterFinalize: true };
|
|
137
|
+
this.killProcessTree(running.child, "SIGTERM");
|
|
138
|
+
await this.waitForExit(running);
|
|
139
|
+
return;
|
|
140
|
+
}
|
|
141
|
+
record.status = "stopped";
|
|
142
|
+
record.terminalReason = "user_terminated";
|
|
143
|
+
record.stoppedAt = new Date().toISOString();
|
|
144
|
+
await this.finalizeRecord(workspaceId, record, {
|
|
145
|
+
reason: "user_terminated",
|
|
146
|
+
endContext: "normal",
|
|
147
|
+
removeAfterFinalize: true,
|
|
148
|
+
});
|
|
149
|
+
}
|
|
150
|
+
async readOutput(workspaceId, processId, options) {
|
|
151
|
+
const outputPath = this.getOutputPath(workspaceId, processId);
|
|
152
|
+
if (!existsSync(outputPath)) {
|
|
153
|
+
return { id: processId, content: "", truncated: false, sizeBytes: 0 };
|
|
154
|
+
}
|
|
155
|
+
const stats = await fs.stat(outputPath);
|
|
156
|
+
const sizeBytes = stats.size;
|
|
157
|
+
const method = options.method ?? "full";
|
|
158
|
+
const lineCount = options.lines ?? 10;
|
|
159
|
+
const raw = await this.readOutputBytes(outputPath, sizeBytes, options.maxBytes);
|
|
160
|
+
let content = raw;
|
|
161
|
+
switch (method) {
|
|
162
|
+
case "head":
|
|
163
|
+
content = this.headLines(raw, lineCount);
|
|
164
|
+
break;
|
|
165
|
+
case "tail":
|
|
166
|
+
content = this.tailLines(raw, lineCount);
|
|
167
|
+
break;
|
|
168
|
+
case "grep":
|
|
169
|
+
if (!options.pattern) {
|
|
170
|
+
throw new Error("Pattern is required for grep output");
|
|
171
|
+
}
|
|
172
|
+
content = this.grepLines(raw, options.pattern);
|
|
173
|
+
break;
|
|
174
|
+
default:
|
|
175
|
+
content = raw;
|
|
176
|
+
}
|
|
177
|
+
const effectiveMaxBytes = options.maxBytes;
|
|
178
|
+
return {
|
|
179
|
+
id: processId,
|
|
180
|
+
content,
|
|
181
|
+
truncated: effectiveMaxBytes !== undefined && sizeBytes > effectiveMaxBytes,
|
|
182
|
+
sizeBytes,
|
|
183
|
+
};
|
|
184
|
+
}
|
|
185
|
+
async streamOutput(workspaceId, processId, reply) {
|
|
186
|
+
const outputPath = this.getOutputPath(workspaceId, processId);
|
|
187
|
+
if (!existsSync(outputPath)) {
|
|
188
|
+
reply.code(404).send({ error: "Output not found" });
|
|
189
|
+
return;
|
|
190
|
+
}
|
|
191
|
+
reply.raw.setHeader("Content-Type", "text/event-stream");
|
|
192
|
+
reply.raw.setHeader("Cache-Control", "no-cache");
|
|
193
|
+
reply.raw.setHeader("Connection", "keep-alive");
|
|
194
|
+
reply.raw.flushHeaders?.();
|
|
195
|
+
reply.hijack();
|
|
196
|
+
const file = await fs.open(outputPath, "r");
|
|
197
|
+
let position = (await file.stat()).size;
|
|
198
|
+
const tick = async () => {
|
|
199
|
+
const stats = await file.stat();
|
|
200
|
+
if (stats.size <= position)
|
|
201
|
+
return;
|
|
202
|
+
const length = stats.size - position;
|
|
203
|
+
const buffer = Buffer.alloc(length);
|
|
204
|
+
await file.read(buffer, 0, length, position);
|
|
205
|
+
position = stats.size;
|
|
206
|
+
const content = buffer.toString("utf-8");
|
|
207
|
+
reply.raw.write(`data: ${JSON.stringify({ type: "chunk", content })}\n\n`);
|
|
208
|
+
};
|
|
209
|
+
const interval = setInterval(() => {
|
|
210
|
+
tick().catch((error) => {
|
|
211
|
+
this.deps.logger.warn({ err: error }, "Failed to stream background process output");
|
|
212
|
+
});
|
|
213
|
+
}, 1000);
|
|
214
|
+
const close = () => {
|
|
215
|
+
clearInterval(interval);
|
|
216
|
+
file.close().catch(() => undefined);
|
|
217
|
+
reply.raw.end?.();
|
|
218
|
+
};
|
|
219
|
+
reply.raw.on("close", close);
|
|
220
|
+
reply.raw.on("error", close);
|
|
221
|
+
}
|
|
222
|
+
async cleanupWorkspace(workspaceId) {
|
|
223
|
+
for (const [, running] of this.running.entries()) {
|
|
224
|
+
if (running.workspaceId !== workspaceId)
|
|
225
|
+
continue;
|
|
226
|
+
running.completion = {
|
|
227
|
+
reason: "user_terminated",
|
|
228
|
+
endContext: "workspace_cleanup",
|
|
229
|
+
removeAfterFinalize: true,
|
|
230
|
+
};
|
|
231
|
+
this.killProcessTree(running.child, "SIGTERM");
|
|
232
|
+
await this.waitForExit(running);
|
|
233
|
+
}
|
|
234
|
+
await this.removeWorkspaceDir(workspaceId);
|
|
235
|
+
}
|
|
236
|
+
killProcessTree(child, signal) {
|
|
237
|
+
const pid = child.pid;
|
|
238
|
+
if (!pid)
|
|
239
|
+
return;
|
|
240
|
+
if (process.platform === "win32") {
|
|
241
|
+
const args = this.buildWindowsTaskkillArgs(pid, signal);
|
|
242
|
+
try {
|
|
243
|
+
spawnSync("taskkill", args, { stdio: "ignore" });
|
|
244
|
+
return;
|
|
245
|
+
}
|
|
246
|
+
catch {
|
|
247
|
+
// Fall back to killing the direct child.
|
|
248
|
+
}
|
|
249
|
+
}
|
|
250
|
+
else {
|
|
251
|
+
try {
|
|
252
|
+
process.kill(-pid, signal);
|
|
253
|
+
return;
|
|
254
|
+
}
|
|
255
|
+
catch {
|
|
256
|
+
// Fall back to killing the direct child.
|
|
257
|
+
}
|
|
258
|
+
}
|
|
259
|
+
try {
|
|
260
|
+
child.kill(signal);
|
|
261
|
+
}
|
|
262
|
+
catch {
|
|
263
|
+
// ignore
|
|
264
|
+
}
|
|
265
|
+
}
|
|
266
|
+
async waitForExit(running) {
|
|
267
|
+
let exited = false;
|
|
268
|
+
const exitPromise = running.exitPromise.finally(() => {
|
|
269
|
+
exited = true;
|
|
270
|
+
});
|
|
271
|
+
const killTimeout = setTimeout(() => {
|
|
272
|
+
if (!exited) {
|
|
273
|
+
this.killProcessTree(running.child, "SIGKILL");
|
|
274
|
+
}
|
|
275
|
+
}, STOP_TIMEOUT_MS);
|
|
276
|
+
try {
|
|
277
|
+
await Promise.race([
|
|
278
|
+
exitPromise,
|
|
279
|
+
new Promise((resolve) => {
|
|
280
|
+
setTimeout(resolve, EXIT_WAIT_TIMEOUT_MS);
|
|
281
|
+
}),
|
|
282
|
+
]);
|
|
283
|
+
if (!exited) {
|
|
284
|
+
this.killProcessTree(running.child, "SIGKILL");
|
|
285
|
+
this.running.delete(running.id);
|
|
286
|
+
this.deps.logger.warn({ pid: running.child.pid }, "Timed out waiting for background process to exit");
|
|
287
|
+
}
|
|
288
|
+
}
|
|
289
|
+
finally {
|
|
290
|
+
clearTimeout(killTimeout);
|
|
291
|
+
}
|
|
292
|
+
}
|
|
293
|
+
buildShellSpawn(command) {
|
|
294
|
+
if (process.platform === "win32") {
|
|
295
|
+
const comspec = process.env.ComSpec || "cmd.exe";
|
|
296
|
+
return {
|
|
297
|
+
shellCommand: comspec,
|
|
298
|
+
shellArgs: ["/d", "/s", "/c", command],
|
|
299
|
+
spawnOptions: { windowsVerbatimArguments: true },
|
|
300
|
+
};
|
|
301
|
+
}
|
|
302
|
+
// Keep bash for macOS/Linux.
|
|
303
|
+
return { shellCommand: "bash", shellArgs: ["-c", command] };
|
|
304
|
+
}
|
|
305
|
+
buildWindowsTaskkillArgs(pid, signal) {
|
|
306
|
+
// Default to graceful termination (no /F), then force kill when we escalate.
|
|
307
|
+
const force = signal === "SIGKILL";
|
|
308
|
+
const args = ["/PID", String(pid), "/T"];
|
|
309
|
+
if (force) {
|
|
310
|
+
args.push("/F");
|
|
311
|
+
}
|
|
312
|
+
return args;
|
|
313
|
+
}
|
|
314
|
+
completionFromExit(code) {
|
|
315
|
+
if (code === 0) {
|
|
316
|
+
return { reason: "finished", endContext: "normal" };
|
|
317
|
+
}
|
|
318
|
+
return { reason: "failed", endContext: "normal" };
|
|
319
|
+
}
|
|
320
|
+
statusFromReason(reason) {
|
|
321
|
+
if (reason === "failed")
|
|
322
|
+
return "error";
|
|
323
|
+
return "stopped";
|
|
324
|
+
}
|
|
325
|
+
async readOutputBytes(outputPath, sizeBytes, maxBytes) {
|
|
326
|
+
if (maxBytes === undefined || sizeBytes <= maxBytes) {
|
|
327
|
+
return await fs.readFile(outputPath, "utf-8");
|
|
328
|
+
}
|
|
329
|
+
const start = Math.max(0, sizeBytes - maxBytes);
|
|
330
|
+
const file = await fs.open(outputPath, "r");
|
|
331
|
+
const buffer = Buffer.alloc(sizeBytes - start);
|
|
332
|
+
await file.read(buffer, 0, buffer.length, start);
|
|
333
|
+
await file.close();
|
|
334
|
+
return buffer.toString("utf-8");
|
|
335
|
+
}
|
|
336
|
+
headLines(input, lines) {
|
|
337
|
+
const parts = input.split(/\r?\n/);
|
|
338
|
+
return parts.slice(0, Math.max(0, lines)).join("\n");
|
|
339
|
+
}
|
|
340
|
+
tailLines(input, lines) {
|
|
341
|
+
const parts = input.split(/\r?\n/);
|
|
342
|
+
return parts.slice(Math.max(0, parts.length - lines)).join("\n");
|
|
343
|
+
}
|
|
344
|
+
grepLines(input, pattern) {
|
|
345
|
+
let matcher;
|
|
346
|
+
try {
|
|
347
|
+
matcher = new RegExp(pattern);
|
|
348
|
+
}
|
|
349
|
+
catch {
|
|
350
|
+
throw new Error("Invalid grep pattern");
|
|
351
|
+
}
|
|
352
|
+
return input
|
|
353
|
+
.split(/\r?\n/)
|
|
354
|
+
.filter((line) => matcher.test(line))
|
|
355
|
+
.join("\n");
|
|
356
|
+
}
|
|
357
|
+
async ensureProcessDir(workspaceId, processId) {
|
|
358
|
+
const root = await this.ensureWorkspaceDir(workspaceId);
|
|
359
|
+
const processDir = path.join(root, processId);
|
|
360
|
+
await fs.mkdir(processDir, { recursive: true });
|
|
361
|
+
return processDir;
|
|
362
|
+
}
|
|
363
|
+
async ensureWorkspaceDir(workspaceId) {
|
|
364
|
+
const workspace = this.deps.workspaceManager.get(workspaceId);
|
|
365
|
+
if (!workspace) {
|
|
366
|
+
throw new Error("Workspace not found");
|
|
367
|
+
}
|
|
368
|
+
const root = path.join(workspace.path, ROOT_DIR, workspaceId);
|
|
369
|
+
await fs.mkdir(root, { recursive: true });
|
|
370
|
+
return root;
|
|
371
|
+
}
|
|
372
|
+
getOutputPath(workspaceId, processId) {
|
|
373
|
+
const workspace = this.deps.workspaceManager.get(workspaceId);
|
|
374
|
+
if (!workspace) {
|
|
375
|
+
throw new Error("Workspace not found");
|
|
376
|
+
}
|
|
377
|
+
return path.join(workspace.path, ROOT_DIR, workspaceId, processId, OUTPUT_FILE);
|
|
378
|
+
}
|
|
379
|
+
async findProcess(workspaceId, processId) {
|
|
380
|
+
const records = await this.readIndex(workspaceId);
|
|
381
|
+
return records.find((entry) => entry.id === processId) ?? null;
|
|
382
|
+
}
|
|
383
|
+
async readIndex(workspaceId) {
|
|
384
|
+
const indexPath = await this.getIndexPath(workspaceId);
|
|
385
|
+
if (!existsSync(indexPath))
|
|
386
|
+
return [];
|
|
387
|
+
try {
|
|
388
|
+
const raw = await fs.readFile(indexPath, "utf-8");
|
|
389
|
+
const parsed = JSON.parse(raw);
|
|
390
|
+
return Array.isArray(parsed) ? parsed : [];
|
|
391
|
+
}
|
|
392
|
+
catch {
|
|
393
|
+
return [];
|
|
394
|
+
}
|
|
395
|
+
}
|
|
396
|
+
async upsertIndex(workspaceId, record) {
|
|
397
|
+
const records = await this.readIndex(workspaceId);
|
|
398
|
+
const index = records.findIndex((entry) => entry.id === record.id);
|
|
399
|
+
if (index >= 0) {
|
|
400
|
+
records[index] = record;
|
|
401
|
+
}
|
|
402
|
+
else {
|
|
403
|
+
records.push(record);
|
|
404
|
+
}
|
|
405
|
+
await this.writeIndex(workspaceId, records);
|
|
406
|
+
}
|
|
407
|
+
async removeFromIndex(workspaceId, processId) {
|
|
408
|
+
const records = await this.readIndex(workspaceId);
|
|
409
|
+
const next = records.filter((entry) => entry.id !== processId);
|
|
410
|
+
await this.writeIndex(workspaceId, next);
|
|
411
|
+
}
|
|
412
|
+
async writeIndex(workspaceId, records) {
|
|
413
|
+
const indexPath = await this.getIndexPath(workspaceId);
|
|
414
|
+
await fs.mkdir(path.dirname(indexPath), { recursive: true });
|
|
415
|
+
await fs.writeFile(indexPath, JSON.stringify(records, null, 2));
|
|
416
|
+
}
|
|
417
|
+
async getIndexPath(workspaceId) {
|
|
418
|
+
const workspace = this.deps.workspaceManager.get(workspaceId);
|
|
419
|
+
if (!workspace) {
|
|
420
|
+
throw new Error("Workspace not found");
|
|
421
|
+
}
|
|
422
|
+
return path.join(workspace.path, ROOT_DIR, workspaceId, INDEX_FILE);
|
|
423
|
+
}
|
|
424
|
+
async removeProcessDir(workspaceId, processId) {
|
|
425
|
+
const workspace = this.deps.workspaceManager.get(workspaceId);
|
|
426
|
+
if (!workspace) {
|
|
427
|
+
return;
|
|
428
|
+
}
|
|
429
|
+
const processDir = path.join(workspace.path, ROOT_DIR, workspaceId, processId);
|
|
430
|
+
await fs.rm(processDir, { recursive: true, force: true });
|
|
431
|
+
}
|
|
432
|
+
async removeWorkspaceDir(workspaceId) {
|
|
433
|
+
const workspace = this.deps.workspaceManager.get(workspaceId);
|
|
434
|
+
if (!workspace) {
|
|
435
|
+
return;
|
|
436
|
+
}
|
|
437
|
+
const workspaceDir = path.join(workspace.path, ROOT_DIR, workspaceId);
|
|
438
|
+
await fs.rm(workspaceDir, { recursive: true, force: true });
|
|
439
|
+
}
|
|
440
|
+
async getOutputSize(workspaceId, processId) {
|
|
441
|
+
const outputPath = this.getOutputPath(workspaceId, processId);
|
|
442
|
+
if (!existsSync(outputPath)) {
|
|
443
|
+
return 0;
|
|
444
|
+
}
|
|
445
|
+
try {
|
|
446
|
+
const stats = await fs.stat(outputPath);
|
|
447
|
+
return stats.size;
|
|
448
|
+
}
|
|
449
|
+
catch {
|
|
450
|
+
return 0;
|
|
451
|
+
}
|
|
452
|
+
}
|
|
453
|
+
publishUpdate(workspaceId, record) {
|
|
454
|
+
this.deps.eventBus.publish({
|
|
455
|
+
type: "instance.event",
|
|
456
|
+
instanceId: workspaceId,
|
|
457
|
+
event: { type: "background.process.updated", properties: { process: this.toPublicProcess(record) } },
|
|
458
|
+
});
|
|
459
|
+
}
|
|
460
|
+
toPublicProcess(record) {
|
|
461
|
+
return {
|
|
462
|
+
id: record.id,
|
|
463
|
+
workspaceId: record.workspaceId,
|
|
464
|
+
title: record.title,
|
|
465
|
+
command: record.command,
|
|
466
|
+
cwd: record.cwd,
|
|
467
|
+
status: record.status,
|
|
468
|
+
pid: record.pid,
|
|
469
|
+
startedAt: record.startedAt,
|
|
470
|
+
stoppedAt: record.stoppedAt,
|
|
471
|
+
exitCode: record.exitCode,
|
|
472
|
+
outputSizeBytes: record.outputSizeBytes,
|
|
473
|
+
terminalReason: record.terminalReason,
|
|
474
|
+
notifyEnabled: Boolean(record.notify),
|
|
475
|
+
};
|
|
476
|
+
}
|
|
477
|
+
async finalizeRecord(workspaceId, record, completion) {
|
|
478
|
+
if (this.shouldSendCompletionPrompt(record, completion)) {
|
|
479
|
+
try {
|
|
480
|
+
await this.sendCompletionPrompt(workspaceId, record);
|
|
481
|
+
if (record.notify) {
|
|
482
|
+
record.notify.sentAt = new Date().toISOString();
|
|
483
|
+
}
|
|
484
|
+
}
|
|
485
|
+
catch (error) {
|
|
486
|
+
this.deps.logger.warn({ err: error, workspaceId, processId: record.id }, "Failed to send background process completion prompt");
|
|
487
|
+
}
|
|
488
|
+
}
|
|
489
|
+
if (completion.removeAfterFinalize) {
|
|
490
|
+
await this.removeFromIndex(workspaceId, record.id);
|
|
491
|
+
await this.removeProcessDir(workspaceId, record.id);
|
|
492
|
+
this.deps.eventBus.publish({
|
|
493
|
+
type: "instance.event",
|
|
494
|
+
instanceId: workspaceId,
|
|
495
|
+
event: { type: "background.process.removed", properties: { processId: record.id } },
|
|
496
|
+
});
|
|
497
|
+
return;
|
|
498
|
+
}
|
|
499
|
+
await this.upsertIndex(workspaceId, record);
|
|
500
|
+
record.outputSizeBytes = await this.getOutputSize(workspaceId, record.id);
|
|
501
|
+
this.publishUpdate(workspaceId, record);
|
|
502
|
+
}
|
|
503
|
+
shouldSendCompletionPrompt(record, completion) {
|
|
504
|
+
if (completion.endContext === "workspace_cleanup")
|
|
505
|
+
return false;
|
|
506
|
+
if (!record.notify)
|
|
507
|
+
return false;
|
|
508
|
+
return !record.notify.sentAt;
|
|
509
|
+
}
|
|
510
|
+
async sendCompletionPrompt(workspaceId, record) {
|
|
511
|
+
const notify = record.notify;
|
|
512
|
+
if (!notify || !record.terminalReason)
|
|
513
|
+
return;
|
|
514
|
+
if (!this.deps.workspaceManager.get(workspaceId)) {
|
|
515
|
+
throw new Error("Workspace not found");
|
|
516
|
+
}
|
|
517
|
+
const port = this.deps.workspaceManager.getInstancePort(workspaceId);
|
|
518
|
+
if (!port) {
|
|
519
|
+
throw new Error("Workspace instance is not ready");
|
|
520
|
+
}
|
|
521
|
+
const targetUrl = `http://127.0.0.1:${port}/session/${encodeURIComponent(notify.sessionID)}/prompt_async`;
|
|
522
|
+
const headers = {
|
|
523
|
+
"content-type": "application/json",
|
|
524
|
+
"x-opencode-directory": /[^\x00-\x7F]/.test(notify.directory) ? encodeURIComponent(notify.directory) : notify.directory,
|
|
525
|
+
};
|
|
526
|
+
const authorization = this.deps.workspaceManager.getInstanceAuthorizationHeader(workspaceId);
|
|
527
|
+
if (authorization) {
|
|
528
|
+
headers.authorization = authorization;
|
|
529
|
+
}
|
|
530
|
+
const response = await fetch(targetUrl, {
|
|
531
|
+
method: "POST",
|
|
532
|
+
headers,
|
|
533
|
+
body: JSON.stringify({
|
|
534
|
+
parts: [
|
|
535
|
+
{
|
|
536
|
+
type: "text",
|
|
537
|
+
text: this.buildSyntheticCompletionPrompt(record),
|
|
538
|
+
synthetic: true,
|
|
539
|
+
},
|
|
540
|
+
],
|
|
541
|
+
}),
|
|
542
|
+
});
|
|
543
|
+
if (!response.ok) {
|
|
544
|
+
const message = await response.text().catch(() => "");
|
|
545
|
+
throw new Error(message || `Prompt request failed with ${response.status}`);
|
|
546
|
+
}
|
|
547
|
+
}
|
|
548
|
+
buildCompletionPrompt(record) {
|
|
549
|
+
const ref = `Background process "${record.title}" (${record.id})`;
|
|
550
|
+
switch (record.terminalReason) {
|
|
551
|
+
case "finished":
|
|
552
|
+
return `${ref} finished successfully.`;
|
|
553
|
+
case "failed":
|
|
554
|
+
return record.exitCode === undefined ? `${ref} failed.` : `${ref} failed with exit code ${record.exitCode}.`;
|
|
555
|
+
case "user_stopped":
|
|
556
|
+
return `${ref} was stopped by user.`;
|
|
557
|
+
case "user_terminated":
|
|
558
|
+
return `${ref} was terminated by user.`;
|
|
559
|
+
}
|
|
560
|
+
return `${ref} ended.`;
|
|
561
|
+
}
|
|
562
|
+
buildSyntheticCompletionPrompt(record) {
|
|
563
|
+
return `<system-message>${this.escapeTaggedText(this.buildCompletionPrompt(record))}</system-message>`;
|
|
564
|
+
}
|
|
565
|
+
escapeTaggedText(input) {
|
|
566
|
+
return input
|
|
567
|
+
.replace(/&/g, "&")
|
|
568
|
+
.replace(/</g, "<")
|
|
569
|
+
.replace(/>/g, ">");
|
|
570
|
+
}
|
|
571
|
+
generateId() {
|
|
572
|
+
const timestamp = new Date().toISOString().replace(/[:.]/g, "").slice(0, 15);
|
|
573
|
+
const random = randomBytes(3).toString("hex");
|
|
574
|
+
return `proc_${timestamp}_${random}`;
|
|
575
|
+
}
|
|
576
|
+
}
|
package/dist/bin.js
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import { spawn } from "child_process";
|
|
3
|
+
import path from "path";
|
|
4
|
+
import { fileURLToPath, pathToFileURL } from "url";
|
|
5
|
+
const __filename = fileURLToPath(import.meta.url);
|
|
6
|
+
const __dirname = path.dirname(__filename);
|
|
7
|
+
const cliEntry = path.join(__dirname, "index.js");
|
|
8
|
+
const loaderFileUrl = pathToFileURL(path.join(__dirname, "loader.js")).href;
|
|
9
|
+
const registerScript = `import { register } from "node:module"; import { pathToFileURL } from "node:url"; register("${encodeURI(loaderFileUrl)}", pathToFileURL("./"));`;
|
|
10
|
+
const loaderArg = `data:text/javascript,${registerScript}`;
|
|
11
|
+
const child = spawn(process.execPath, ["--import", loaderArg, cliEntry, ...process.argv.slice(2)], {
|
|
12
|
+
stdio: "inherit",
|
|
13
|
+
});
|
|
14
|
+
child.on("exit", (code, signal) => {
|
|
15
|
+
if (signal) {
|
|
16
|
+
process.kill(process.pid, signal);
|
|
17
|
+
return;
|
|
18
|
+
}
|
|
19
|
+
process.exit(code ?? 0);
|
|
20
|
+
});
|
|
21
|
+
child.on("error", (error) => {
|
|
22
|
+
console.error("Failed to launch CLI runtime", error);
|
|
23
|
+
process.exit(1);
|
|
24
|
+
});
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { spawn } from "child_process";
|
|
2
|
+
const CODENOMAD_PACKAGE_NAME = "@neuralnomads/codenomad";
|
|
3
|
+
function detectFromText(value) {
|
|
4
|
+
const lower = (value ?? "").toLowerCase();
|
|
5
|
+
if (!lower)
|
|
6
|
+
return null;
|
|
7
|
+
if (lower.includes("pnpm"))
|
|
8
|
+
return "pnpm";
|
|
9
|
+
if (lower.includes("bun"))
|
|
10
|
+
return "bun";
|
|
11
|
+
if (lower.includes("npm"))
|
|
12
|
+
return "npm";
|
|
13
|
+
return null;
|
|
14
|
+
}
|
|
15
|
+
export function detectPackageManager(env = process.env) {
|
|
16
|
+
return detectFromText(env.npm_config_user_agent) ?? detectFromText(env.npm_execpath) ?? "npm";
|
|
17
|
+
}
|
|
18
|
+
export function buildUpgradeCommand(version, packageManager = detectPackageManager()) {
|
|
19
|
+
const targetVersion = (version ?? "").trim() || "latest";
|
|
20
|
+
const packageSpec = `${CODENOMAD_PACKAGE_NAME}@${targetVersion}`;
|
|
21
|
+
const args = packageManager === "bun" ? ["add", "-g", packageSpec] : ["install", "-g", packageSpec];
|
|
22
|
+
return {
|
|
23
|
+
command: packageManager,
|
|
24
|
+
args,
|
|
25
|
+
packageSpec,
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
export function formatUpgradeCommand(command) {
|
|
29
|
+
return [command.command, ...command.args].join(" ");
|
|
30
|
+
}
|
|
31
|
+
export function runCliUpgrade(version, env = process.env) {
|
|
32
|
+
const upgrade = buildUpgradeCommand(version, detectPackageManager(env));
|
|
33
|
+
console.log(`Upgrading CodeNomad with: ${formatUpgradeCommand(upgrade)}`);
|
|
34
|
+
return new Promise((resolve) => {
|
|
35
|
+
const child = spawn(upgrade.command, upgrade.args, {
|
|
36
|
+
env,
|
|
37
|
+
shell: process.platform === "win32",
|
|
38
|
+
stdio: "inherit",
|
|
39
|
+
});
|
|
40
|
+
child.on("exit", (code, signal) => {
|
|
41
|
+
if (signal) {
|
|
42
|
+
console.error(`Upgrade command stopped by signal ${signal}`);
|
|
43
|
+
resolve(1);
|
|
44
|
+
return;
|
|
45
|
+
}
|
|
46
|
+
resolve(code ?? 0);
|
|
47
|
+
});
|
|
48
|
+
child.on("error", (error) => {
|
|
49
|
+
console.error("Failed to launch upgrade command", error);
|
|
50
|
+
resolve(1);
|
|
51
|
+
});
|
|
52
|
+
});
|
|
53
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import assert from "node:assert/strict";
|
|
2
|
+
import { describe, it } from "node:test";
|
|
3
|
+
import { buildUpgradeCommand, detectPackageManager, formatUpgradeCommand } from "./cli-upgrade";
|
|
4
|
+
describe("cli upgrade", () => {
|
|
5
|
+
it("defaults to npm when no package manager can be detected", () => {
|
|
6
|
+
assert.equal(detectPackageManager({}), "npm");
|
|
7
|
+
});
|
|
8
|
+
it("detects package managers from npm user agent", () => {
|
|
9
|
+
assert.equal(detectPackageManager({ npm_config_user_agent: "pnpm/9.0.0 node/v22" }), "pnpm");
|
|
10
|
+
assert.equal(detectPackageManager({ npm_config_user_agent: "bun/1.0.0" }), "bun");
|
|
11
|
+
assert.equal(detectPackageManager({ npm_config_user_agent: "npm/10.0.0 node/v22" }), "npm");
|
|
12
|
+
});
|
|
13
|
+
it("builds latest upgrade command by default", () => {
|
|
14
|
+
const command = buildUpgradeCommand(undefined, "npm");
|
|
15
|
+
assert.equal(command.packageSpec, "@neuralnomads/codenomad@latest");
|
|
16
|
+
assert.deepEqual(command.args, ["install", "-g", "@neuralnomads/codenomad@latest"]);
|
|
17
|
+
assert.equal(formatUpgradeCommand(command), "npm install -g @neuralnomads/codenomad@latest");
|
|
18
|
+
});
|
|
19
|
+
it("builds a versioned upgrade command", () => {
|
|
20
|
+
const command = buildUpgradeCommand("0.10.5", "pnpm");
|
|
21
|
+
assert.equal(command.packageSpec, "@neuralnomads/codenomad@0.10.5");
|
|
22
|
+
assert.deepEqual(command.args, ["install", "-g", "@neuralnomads/codenomad@0.10.5"]);
|
|
23
|
+
assert.equal(formatUpgradeCommand(command), "pnpm install -g @neuralnomads/codenomad@0.10.5");
|
|
24
|
+
});
|
|
25
|
+
it("uses bun add for Bun installs", () => {
|
|
26
|
+
const command = buildUpgradeCommand("0.10.5", "bun");
|
|
27
|
+
assert.equal(command.packageSpec, "@neuralnomads/codenomad@0.10.5");
|
|
28
|
+
assert.deepEqual(command.args, ["add", "-g", "@neuralnomads/codenomad@0.10.5"]);
|
|
29
|
+
assert.equal(formatUpgradeCommand(command), "bun add -g @neuralnomads/codenomad@0.10.5");
|
|
30
|
+
});
|
|
31
|
+
});
|