@vividcodeai/embeddedcowork 0.0.8 → 0.0.10
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/bin/cli.js +56 -0
- package/package.json +10 -3
- package/dist/api-types.js +0 -1
- package/dist/auth/auth-store.js +0 -134
- package/dist/auth/http-auth.js +0 -37
- package/dist/auth/manager.js +0 -140
- package/dist/auth/password-hash.js +0 -32
- package/dist/auth/session-manager.js +0 -17
- package/dist/auth/token-manager.js +0 -27
- package/dist/background-processes/manager.js +0 -576
- package/dist/bin.js +0 -24
- package/dist/clients/connection-manager.js +0 -93
- package/dist/config/location.js +0 -57
- package/dist/config/schema.js +0 -72
- package/dist/events/bus.js +0 -47
- package/dist/filesystem/__tests__/search-cache.test.js +0 -40
- package/dist/filesystem/browser.js +0 -292
- package/dist/filesystem/search-cache.js +0 -43
- package/dist/filesystem/search.js +0 -135
- package/dist/index.js +0 -496
- package/dist/launcher.js +0 -149
- package/dist/loader.js +0 -21
- package/dist/logger.js +0 -109
- package/dist/opencode-config/README.md +0 -32
- package/dist/opencode-config/opencode.jsonc +0 -35
- package/dist/opencode-config/package.json +0 -9
- package/dist/opencode-config/plugin/embeddedcowork.ts +0 -62
- package/dist/opencode-config/plugin/lib/background-process.ts +0 -265
- package/dist/opencode-config/plugin/lib/client.ts +0 -133
- package/dist/opencode-config/plugin/lib/request.ts +0 -214
- package/dist/opencode-config.js +0 -15
- package/dist/opencode-downloader.js +0 -295
- package/dist/opencode-paths.js +0 -167
- package/dist/plugins/channel.js +0 -40
- package/dist/plugins/handlers.js +0 -17
- package/dist/plugins/voice-mode.js +0 -78
- package/dist/releases/dev-release-monitor.js +0 -75
- package/dist/releases/release-monitor.js +0 -107
- package/dist/runtime-paths.js +0 -67
- package/dist/server/__tests__/network-addresses.test.js +0 -68
- package/dist/server/__tests__/remote-proxy.test.js +0 -204
- package/dist/server/http-server.js +0 -998
- package/dist/server/network-addresses.js +0 -114
- package/dist/server/remote-proxy.js +0 -466
- package/dist/server/routes/auth-pages/login.html +0 -135
- package/dist/server/routes/auth-pages/token.html +0 -93
- package/dist/server/routes/auth.js +0 -149
- package/dist/server/routes/background-processes.js +0 -78
- package/dist/server/routes/events.js +0 -66
- package/dist/server/routes/filesystem.js +0 -43
- package/dist/server/routes/meta.js +0 -44
- package/dist/server/routes/opencode-status.js +0 -10
- package/dist/server/routes/plugin.js +0 -70
- package/dist/server/routes/remote-proxy.js +0 -42
- package/dist/server/routes/remote-servers.js +0 -142
- package/dist/server/routes/settings.js +0 -69
- package/dist/server/routes/sidecars.js +0 -46
- package/dist/server/routes/speech.js +0 -63
- package/dist/server/routes/storage.js +0 -52
- package/dist/server/routes/workspaces.js +0 -221
- package/dist/server/routes/worktrees.js +0 -156
- package/dist/server/tls.js +0 -224
- package/dist/settings/binaries.js +0 -37
- package/dist/settings/merge-patch.js +0 -33
- package/dist/settings/migrate.js +0 -238
- package/dist/settings/public-config.js +0 -33
- package/dist/settings/service.js +0 -101
- package/dist/settings/yaml-doc-store.js +0 -96
- package/dist/sidecars/manager.js +0 -193
- package/dist/speech/providers/openai-compatible.js +0 -189
- package/dist/speech/service.js +0 -58
- package/dist/storage/instance-store.js +0 -56
- package/dist/ui/__tests__/remote-ui.test.js +0 -67
- package/dist/ui/remote-ui.js +0 -462
- package/dist/workspaces/__tests__/spawn.test.js +0 -139
- package/dist/workspaces/git-mutations.js +0 -98
- package/dist/workspaces/git-status.js +0 -323
- package/dist/workspaces/git-worktrees.js +0 -216
- package/dist/workspaces/instance-events.js +0 -180
- package/dist/workspaces/manager.js +0 -432
- package/dist/workspaces/opencode-auth.js +0 -16
- package/dist/workspaces/runtime.js +0 -366
- package/dist/workspaces/spawn.js +0 -219
- package/dist/workspaces/worktree-directory.js +0 -74
- package/dist/workspaces/worktree-map.js +0 -116
- package/public/apple-touch-icon-180x180.png +0 -0
- package/public/assets/ChangesTab-C4_zdV74.js +0 -2
- package/public/assets/DiffToolbar-BsUPigM5.js +0 -1
- package/public/assets/EmbeddedCowork-Icon-DSw5nKk7.png +0 -0
- package/public/assets/FilesTab-Drvo30nM.js +0 -2
- package/public/assets/GitChangesTab-BhV6qTfP.js +0 -2
- package/public/assets/SplitFilePanel-BBrs329I.js +0 -1
- package/public/assets/StatusTab-DfYWlTSX.js +0 -1
- package/public/assets/abap-BdImnpbu.js +0 -1
- package/public/assets/actionscript-3-CfeIJUat.js +0 -1
- package/public/assets/ada-bCR0ucgS.js +0 -1
- package/public/assets/andromeeda-C-Jbm3Hp.js +0 -1
- package/public/assets/angular-html-CU67Zn6k.js +0 -1
- package/public/assets/angular-ts-BwZT4LLn.js +0 -1
- package/public/assets/apache-Pmp26Uib.js +0 -1
- package/public/assets/apex-DhZLUxFE.js +0 -1
- package/public/assets/apl-dKokRX4l.js +0 -1
- package/public/assets/applescript-Co6uUVPk.js +0 -1
- package/public/assets/ara-BRHolxvo.js +0 -1
- package/public/assets/asciidoc-Dv7Oe6Be.js +0 -1
- package/public/assets/asm-D_Q5rh1f.js +0 -1
- package/public/assets/astro-CbQHKStN.js +0 -1
- package/public/assets/aurora-x-D-2ljcwZ.js +0 -1
- package/public/assets/awk-DMzUqQB5.js +0 -1
- package/public/assets/ayu-dark-Cv9koXgw.js +0 -1
- package/public/assets/ballerina-BFfxhgS-.js +0 -1
- package/public/assets/bat-BkioyH1T.js +0 -1
- package/public/assets/beancount-k_qm7-4y.js +0 -1
- package/public/assets/berry-D08WgyRC.js +0 -1
- package/public/assets/bibtex-CHM0blh-.js +0 -1
- package/public/assets/bicep-Bmn6On1c.js +0 -1
- package/public/assets/blade-DVc8C-J4.js +0 -1
- package/public/assets/bsl-BO_Y6i37.js +0 -1
- package/public/assets/bundle-full-CAZqmV2E.js +0 -13
- package/public/assets/c-BIGW1oBm.js +0 -1
- package/public/assets/cadence-Bv_4Rxtq.js +0 -1
- package/public/assets/cairo-KRGpt6FW.js +0 -1
- package/public/assets/catppuccin-frappe-DFWUc33u.js +0 -1
- package/public/assets/catppuccin-latte-C9dUb6Cb.js +0 -1
- package/public/assets/catppuccin-macchiato-DQyhUUbL.js +0 -1
- package/public/assets/catppuccin-mocha-D87Tk5Gz.js +0 -1
- package/public/assets/clarity-D53aC0YG.js +0 -1
- package/public/assets/clojure-P80f7IUj.js +0 -1
- package/public/assets/cmake-D1j8_8rp.js +0 -1
- package/public/assets/cobol-nwyudZeR.js +0 -1
- package/public/assets/codeowners-Bp6g37R7.js +0 -1
- package/public/assets/codeql-DsOJ9woJ.js +0 -1
- package/public/assets/coffee-Ch7k5sss.js +0 -1
- package/public/assets/common-lisp-Cg-RD9OK.js +0 -1
- package/public/assets/coq-DkFqJrB1.js +0 -1
- package/public/assets/core-DhEqZVGG.js +0 -1
- package/public/assets/cpp-CofmeUqb.js +0 -1
- package/public/assets/crystal-tKQVLTB8.js +0 -1
- package/public/assets/csharp-CX12Zw3r.js +0 -1
- package/public/assets/css-DPfMkruS.js +0 -1
- package/public/assets/csv-fuZLfV_i.js +0 -1
- package/public/assets/cue-D82EKSYY.js +0 -1
- package/public/assets/cypher-COkxafJQ.js +0 -1
- package/public/assets/d-85-TOEBH.js +0 -1
- package/public/assets/dark-plus-eOWES_5F.js +0 -1
- package/public/assets/dart-CF10PKvl.js +0 -1
- package/public/assets/dax-CEL-wOlO.js +0 -1
- package/public/assets/desktop-BmXAJ9_W.js +0 -1
- package/public/assets/diff-D97Zzqfu.js +0 -1
- package/public/assets/diff-viewer--UIZ5GEn.js +0 -1
- package/public/assets/docker-BcOcwvcX.js +0 -1
- package/public/assets/dotenv-Da5cRb03.js +0 -1
- package/public/assets/dracula-BzJJZx-M.js +0 -1
- package/public/assets/dracula-soft-BXkSAIEj.js +0 -1
- package/public/assets/dream-maker-BtqSS_iP.js +0 -1
- package/public/assets/edge-BkV0erSs.js +0 -1
- package/public/assets/elixir-CDX3lj18.js +0 -1
- package/public/assets/elm-DbKCFpqz.js +0 -1
- package/public/assets/emacs-lisp-C9XAeP06.js +0 -1
- package/public/assets/erb-BOJIQeun.js +0 -1
- package/public/assets/erlang-DsQrWhSR.js +0 -1
- package/public/assets/event-DjZVAIBO.js +0 -1
- package/public/assets/everforest-dark-BgDCqdQA.js +0 -1
- package/public/assets/everforest-light-C8M2exoo.js +0 -1
- package/public/assets/fast-diff-vendor-DgdwVvTQ.js +0 -1
- package/public/assets/fennel-BYunw83y.js +0 -1
- package/public/assets/fish-BvzEVeQv.js +0 -1
- package/public/assets/fluent-C4IJs8-o.js +0 -1
- package/public/assets/fortran-fixed-form-BZjJHVRy.js +0 -1
- package/public/assets/fortran-free-form-D22FLkUw.js +0 -1
- package/public/assets/fsharp-CXgrBDvD.js +0 -1
- package/public/assets/gdresource-B7Tvp0Sc.js +0 -1
- package/public/assets/gdscript-DTMYz4Jt.js +0 -1
- package/public/assets/gdshader-DkwncUOv.js +0 -1
- package/public/assets/genie-D0YGMca9.js +0 -1
- package/public/assets/gherkin-DyxjwDmM.js +0 -1
- package/public/assets/git-commit-F4YmCXRG.js +0 -1
- package/public/assets/git-diff-vendor-CSgooKT_.js +0 -52
- package/public/assets/git-diff-vendor-HAZkIolJ.css +0 -19
- package/public/assets/git-rebase-r7XF79zn.js +0 -1
- package/public/assets/github-dark-DHJKELXO.js +0 -1
- package/public/assets/github-dark-default-Cuk6v7N8.js +0 -1
- package/public/assets/github-dark-dimmed-DH5Ifo-i.js +0 -1
- package/public/assets/github-dark-high-contrast-E3gJ1_iC.js +0 -1
- package/public/assets/github-light-DAi9KRSo.js +0 -1
- package/public/assets/github-light-default-D7oLnXFd.js +0 -1
- package/public/assets/github-light-high-contrast-BfjtVDDH.js +0 -1
- package/public/assets/gleam-BspZqrRM.js +0 -1
- package/public/assets/glimmer-js-Rg0-pVw9.js +0 -1
- package/public/assets/glimmer-ts-U6CK756n.js +0 -1
- package/public/assets/glsl-DplSGwfg.js +0 -1
- package/public/assets/gnuplot-DdkO51Og.js +0 -1
- package/public/assets/go-Dn2_MT6a.js +0 -1
- package/public/assets/graphql-ChdNCCLP.js +0 -1
- package/public/assets/groovy-gcz8RCvz.js +0 -1
- package/public/assets/gruvbox-dark-hard-CFHQjOhq.js +0 -1
- package/public/assets/gruvbox-dark-medium-GsRaNv29.js +0 -1
- package/public/assets/gruvbox-dark-soft-CVdnzihN.js +0 -1
- package/public/assets/gruvbox-light-hard-CH1njM8p.js +0 -1
- package/public/assets/gruvbox-light-medium-DRw_LuNl.js +0 -1
- package/public/assets/gruvbox-light-soft-hJgmCMqR.js +0 -1
- package/public/assets/hack-CaT9iCJl.js +0 -1
- package/public/assets/haml-B8DHNrY2.js +0 -1
- package/public/assets/handlebars-BL8al0AC.js +0 -1
- package/public/assets/haskell-Df6bDoY_.js +0 -1
- package/public/assets/haxe-CzTSHFRz.js +0 -1
- package/public/assets/hcl-BWvSN4gD.js +0 -1
- package/public/assets/highlight-vendor-8FKMu9os.js +0 -10
- package/public/assets/hjson-D5-asLiD.js +0 -1
- package/public/assets/hlsl-D3lLCCz7.js +0 -1
- package/public/assets/houston-DnULxvSX.js +0 -1
- package/public/assets/html-GMplVEZG.js +0 -1
- package/public/assets/html-derivative-BFtXZ54Q.js +0 -1
- package/public/assets/http-jrhK8wxY.js +0 -1
- package/public/assets/hurl-irOxFIW8.js +0 -1
- package/public/assets/hxml-Bvhsp5Yf.js +0 -1
- package/public/assets/hy-DFXneXwc.js +0 -1
- package/public/assets/imba-DGztddWO.js +0 -1
- package/public/assets/index--0EL0_Tu.js +0 -2
- package/public/assets/index-BKMyzTSR.js +0 -1
- package/public/assets/index-BLouhjer.js +0 -1
- package/public/assets/index-CLSJ4cO9.js +0 -1
- package/public/assets/index-CgjnEdBS.js +0 -1
- package/public/assets/index-ChCPoe9m.js +0 -1
- package/public/assets/index-Co-dJ-Xs.js +0 -1
- package/public/assets/index-Ctcq8Rhl.css +0 -1
- package/public/assets/index-Da0V-sLI.js +0 -1
- package/public/assets/index-hOT6sqTO.js +0 -1
- package/public/assets/ini-BEwlwnbL.js +0 -1
- package/public/assets/java-CylS5w8V.js +0 -1
- package/public/assets/javascript-wDzz0qaB.js +0 -1
- package/public/assets/jinja-4LBKfQ-Z.js +0 -1
- package/public/assets/jison-wvAkD_A8.js +0 -1
- package/public/assets/json-Cp-IABpG.js +0 -1
- package/public/assets/json5-C9tS-k6U.js +0 -1
- package/public/assets/jsonc-Des-eS-w.js +0 -1
- package/public/assets/jsonl-DcaNXYhu.js +0 -1
- package/public/assets/jsonnet-DFQXde-d.js +0 -1
- package/public/assets/jssm-C2t-YnRu.js +0 -1
- package/public/assets/jsx-g9-lgVsj.js +0 -1
- package/public/assets/julia-C8NyazO9.js +0 -1
- package/public/assets/kanagawa-dragon-CkXjmgJE.js +0 -1
- package/public/assets/kanagawa-lotus-CfQXZHmo.js +0 -1
- package/public/assets/kanagawa-wave-DWedfzmr.js +0 -1
- package/public/assets/kdl-DV7GczEv.js +0 -1
- package/public/assets/kotlin-BdnUsdx6.js +0 -1
- package/public/assets/kusto-BvAqAH-y.js +0 -1
- package/public/assets/laserwave-DUszq2jm.js +0 -1
- package/public/assets/latex-BUKiar2Z.js +0 -1
- package/public/assets/lean-DP1Csr6i.js +0 -1
- package/public/assets/less-B1dDrJ26.js +0 -1
- package/public/assets/light-plus-B7mTdjB0.js +0 -1
- package/public/assets/liquid-DYVedYrR.js +0 -1
- package/public/assets/llvm-BtvRca6l.js +0 -1
- package/public/assets/loading-CugGjKDZ.css +0 -1
- package/public/assets/loading-CvW03p4Z.js +0 -2
- package/public/assets/log-2UxHyX5q.js +0 -1
- package/public/assets/logo-BtOb2qkB.js +0 -1
- package/public/assets/lua-BbnMAYS6.js +0 -1
- package/public/assets/luau-CXu1NL6O.js +0 -1
- package/public/assets/main-ByuKWHRz.js +0 -53
- package/public/assets/make-CHLpvVh8.js +0 -1
- package/public/assets/markdown-BBFC6uy4.js +0 -58
- package/public/assets/markdown-Cvjx9yec.js +0 -1
- package/public/assets/marko-CPi9NSCl.js +0 -1
- package/public/assets/material-theme-D5KoaKCx.js +0 -1
- package/public/assets/material-theme-darker-BfHTSMKl.js +0 -1
- package/public/assets/material-theme-lighter-B0m2ddpp.js +0 -1
- package/public/assets/material-theme-ocean-CyktbL80.js +0 -1
- package/public/assets/material-theme-palenight-Csfq5Kiy.js +0 -1
- package/public/assets/matlab-D7o27uSR.js +0 -1
- package/public/assets/mdc-DUICxH0z.js +0 -1
- package/public/assets/mdx-Cmh6b_Ma.js +0 -1
- package/public/assets/mermaid-DKYwYmdq.js +0 -1
- package/public/assets/min-dark-CafNBF8u.js +0 -1
- package/public/assets/min-light-CTRr51gU.js +0 -1
- package/public/assets/mipsasm-CKIfxQSi.js +0 -1
- package/public/assets/mojo-1DNp92w6.js +0 -1
- package/public/assets/monaco-viewer-DnczYBfh.js +0 -26
- package/public/assets/monokai-D4h5O-jR.js +0 -1
- package/public/assets/move-Bu9oaDYs.js +0 -1
- package/public/assets/narrat-DRg8JJMk.js +0 -1
- package/public/assets/nextflow-CUEJCptM.js +0 -1
- package/public/assets/nginx-DknmC5AR.js +0 -1
- package/public/assets/night-owl-C39BiMTA.js +0 -1
- package/public/assets/nim-CVrawwO9.js +0 -1
- package/public/assets/nix-BbRYJGeE.js +0 -1
- package/public/assets/nord-Ddv68eIx.js +0 -1
- package/public/assets/nushell-C-sUppwS.js +0 -1
- package/public/assets/objective-c-DXmwc3jG.js +0 -1
- package/public/assets/objective-cpp-CLxacb5B.js +0 -1
- package/public/assets/ocaml-C0hk2d4L.js +0 -1
- package/public/assets/one-dark-pro-DVMEJ2y_.js +0 -1
- package/public/assets/one-light-PoHY5YXO.js +0 -1
- package/public/assets/pascal-D93ZcfNL.js +0 -1
- package/public/assets/perl-C0TMdlhV.js +0 -1
- package/public/assets/php-CDn_0X-4.js +0 -1
- package/public/assets/pkl-u5AG7uiY.js +0 -1
- package/public/assets/plastic-3e1v2bzS.js +0 -1
- package/public/assets/plsql-ChMvpjG-.js +0 -1
- package/public/assets/po-BTJTHyun.js +0 -1
- package/public/assets/poimandres-CS3Unz2-.js +0 -1
- package/public/assets/polar-C0HS_06l.js +0 -1
- package/public/assets/postcss-CXtECtnM.js +0 -1
- package/public/assets/powerquery-CEu0bR-o.js +0 -1
- package/public/assets/powershell-Dpen1YoG.js +0 -1
- package/public/assets/prisma-Dd19v3D-.js +0 -1
- package/public/assets/prolog-CbFg5uaA.js +0 -1
- package/public/assets/proto-DyJlTyXw.js +0 -1
- package/public/assets/pug-CGlum2m_.js +0 -1
- package/public/assets/puppet-BMWR74SV.js +0 -1
- package/public/assets/purescript-CklMAg4u.js +0 -1
- package/public/assets/python-B6aJPvgy.js +0 -1
- package/public/assets/qml-3beO22l8.js +0 -1
- package/public/assets/qmldir-C8lEn-DE.js +0 -1
- package/public/assets/qss-IeuSbFQv.js +0 -1
- package/public/assets/r-DiinP2Uv.js +0 -1
- package/public/assets/racket-BqYA7rlc.js +0 -1
- package/public/assets/raku-DXvB9xmW.js +0 -1
- package/public/assets/razor-WgofotgN.js +0 -1
- package/public/assets/red-bN70gL4F.js +0 -1
- package/public/assets/reg-C-SQnVFl.js +0 -1
- package/public/assets/regexp-CDVJQ6XC.js +0 -1
- package/public/assets/rel-C3B-1QV4.js +0 -1
- package/public/assets/riscv-BM1_JUlF.js +0 -1
- package/public/assets/rose-pine-BHrmToEH.js +0 -1
- package/public/assets/rose-pine-dawn-CnK8MTSM.js +0 -1
- package/public/assets/rose-pine-moon-NleAzG8P.js +0 -1
- package/public/assets/rosmsg-BJDFO7_C.js +0 -1
- package/public/assets/rst-B0xPkSld.js +0 -1
- package/public/assets/ruby-BvKwtOVI.js +0 -1
- package/public/assets/rust-B1yitclQ.js +0 -1
- package/public/assets/sas-cz2c8ADy.js +0 -1
- package/public/assets/sass-Cj5Yp3dK.js +0 -1
- package/public/assets/scala-C151Ov-r.js +0 -1
- package/public/assets/scheme-C98Dy4si.js +0 -1
- package/public/assets/scss-OYdSNvt2.js +0 -1
- package/public/assets/sdbl-DVxCFoDh.js +0 -1
- package/public/assets/shaderlab-Dg9Lc6iA.js +0 -1
- package/public/assets/shellscript-Yzrsuije.js +0 -1
- package/public/assets/shellsession-BADoaaVG.js +0 -1
- package/public/assets/slack-dark-BthQWCQV.js +0 -1
- package/public/assets/slack-ochin-DqwNpetd.js +0 -1
- package/public/assets/smalltalk-BERRCDM3.js +0 -1
- package/public/assets/snazzy-light-Bw305WKR.js +0 -1
- package/public/assets/solarized-dark-DXbdFlpD.js +0 -1
- package/public/assets/solarized-light-L9t79GZl.js +0 -1
- package/public/assets/solidity-BbcW6ACK.js +0 -1
- package/public/assets/soy-Brmx7dQM.js +0 -1
- package/public/assets/sparql-rVzFXLq3.js +0 -1
- package/public/assets/splunk-BtCnVYZw.js +0 -1
- package/public/assets/sql-BLtJtn59.js +0 -1
- package/public/assets/ssh-config-_ykCGR6B.js +0 -1
- package/public/assets/stata-BH5u7GGu.js +0 -1
- package/public/assets/stylus-BEDo0Tqx.js +0 -1
- package/public/assets/svelte-3Dk4HxPD.js +0 -1
- package/public/assets/swift-Dg5xB15N.js +0 -1
- package/public/assets/synthwave-84-CbfX1IO0.js +0 -1
- package/public/assets/system-verilog-CnnmHF94.js +0 -1
- package/public/assets/systemd-4A_iFExJ.js +0 -1
- package/public/assets/talonscript-CkByrt1z.js +0 -1
- package/public/assets/tasl-QIJgUcNo.js +0 -1
- package/public/assets/tcl-dwOrl1Do.js +0 -1
- package/public/assets/templ-W15q3VgB.js +0 -1
- package/public/assets/terraform-BETggiCN.js +0 -1
- package/public/assets/tex-Cppo0RY3.js +0 -1
- package/public/assets/todo-BLpUqy61.js +0 -1
- package/public/assets/tokyo-night-hegEt444.js +0 -1
- package/public/assets/toml-vGWfd6FD.js +0 -1
- package/public/assets/tool-call-B4Xz6FbC.js +0 -60
- package/public/assets/ts-tags-zn1MmPIZ.js +0 -1
- package/public/assets/tsv-B_m7g4N7.js +0 -1
- package/public/assets/tsx-COt5Ahok.js +0 -1
- package/public/assets/turtle-BsS91CYL.js +0 -1
- package/public/assets/twig-CO9l9SDP.js +0 -1
- package/public/assets/typescript-BPQ3VLAy.js +0 -1
- package/public/assets/typespec-Df68jz8_.js +0 -1
- package/public/assets/typst-DHCkPAjA.js +0 -1
- package/public/assets/unified-picker-BrzM_sH6.js +0 -1
- package/public/assets/v-BcVCzyr7.js +0 -1
- package/public/assets/vala-CsfeWuGM.js +0 -1
- package/public/assets/vb-D17OF-Vu.js +0 -1
- package/public/assets/verilog-BQ8w6xss.js +0 -1
- package/public/assets/vesper-DU1UobuO.js +0 -1
- package/public/assets/vhdl-CeAyd5Ju.js +0 -1
- package/public/assets/viml-CJc9bBzg.js +0 -1
- package/public/assets/vitesse-black-Bkuqu6BP.js +0 -1
- package/public/assets/vitesse-dark-D0r3Knsf.js +0 -1
- package/public/assets/vitesse-light-CVO1_9PV.js +0 -1
- package/public/assets/vue-CCoi5OLL.js +0 -1
- package/public/assets/vue-html-DAAvJJDi.js +0 -1
- package/public/assets/vue-vine-_Ih-lPRR.js +0 -1
- package/public/assets/vyper-CDx5xZoG.js +0 -1
- package/public/assets/wasm-CG6Dc4jp.js +0 -1
- package/public/assets/wasm-MzD3tlZU.js +0 -1
- package/public/assets/wenyan-BV7otONQ.js +0 -1
- package/public/assets/wgsl-Dx-B1_4e.js +0 -1
- package/public/assets/wikitext-BhOHFoWU.js +0 -1
- package/public/assets/wit-5i3qLPDT.js +0 -1
- package/public/assets/wolfram-lXgVvXCa.js +0 -1
- package/public/assets/wrap-text-B1i7zgLk.js +0 -1
- package/public/assets/xml-sdJ4AIDG.js +0 -1
- package/public/assets/xsl-CtQFsRM5.js +0 -1
- package/public/assets/yaml-Buea-lGh.js +0 -1
- package/public/assets/zenscript-DVFEvuxE.js +0 -1
- package/public/assets/zig-VOosw3JB.js +0 -1
- package/public/favicon.ico +0 -0
- package/public/index.html +0 -44
- package/public/loading.html +0 -33
- package/public/logo.png +0 -0
- package/public/manifest.webmanifest +0 -1
- 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 +0 -31
- package/public/monaco/vs/basic-languages/cpp/cpp.js +0 -10
- package/public/monaco/vs/basic-languages/kotlin/kotlin.js +0 -10
- package/public/monaco/vs/basic-languages/markdown/markdown.js +0 -10
- package/public/monaco/vs/basic-languages/python/python.js +0 -10
- package/public/monaco/vs/editor/editor.main.css +0 -8
- package/public/monaco/vs/editor/editor.main.js +0 -798
- package/public/monaco/vs/language/css/cssMode.js +0 -13
- package/public/monaco/vs/language/css/cssWorker.js +0 -77
- package/public/monaco/vs/language/html/htmlMode.js +0 -13
- package/public/monaco/vs/language/html/htmlWorker.js +0 -454
- package/public/monaco/vs/language/json/jsonMode.js +0 -19
- package/public/monaco/vs/language/json/jsonWorker.js +0 -42
- package/public/monaco/vs/language/typescript/tsMode.js +0 -20
- package/public/monaco/vs/language/typescript/tsWorker.js +0 -51328
- package/public/monaco/vs/loader.js +0 -11
- package/public/monaco.worker.js +0 -7
- 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 +0 -1
- package/public/sw.js +0 -1
- package/public/ui-version.json +0 -3
- package/public/workbox-60d14903.js +0 -1
|
@@ -1,576 +0,0 @@
|
|
|
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 = ".embeddedcowork/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
DELETED
|
@@ -1,24 +0,0 @@
|
|
|
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
|
-
});
|
|
@@ -1,93 +0,0 @@
|
|
|
1
|
-
const STALE_CONNECTION_TIMEOUT_MS = 45000;
|
|
2
|
-
const STALE_SWEEP_INTERVAL_MS = 5000;
|
|
3
|
-
export class ClientConnectionManager {
|
|
4
|
-
constructor(logger) {
|
|
5
|
-
this.logger = logger;
|
|
6
|
-
this.connections = new Map();
|
|
7
|
-
this.subscribers = new Set();
|
|
8
|
-
this.sweepTimer = setInterval(() => this.sweepStaleConnections(), STALE_SWEEP_INTERVAL_MS);
|
|
9
|
-
this.sweepTimer.unref?.();
|
|
10
|
-
}
|
|
11
|
-
shutdown() {
|
|
12
|
-
clearInterval(this.sweepTimer);
|
|
13
|
-
for (const connection of Array.from(this.connections.values())) {
|
|
14
|
-
this.disconnect(connection.key, "shutdown", false);
|
|
15
|
-
}
|
|
16
|
-
}
|
|
17
|
-
subscribe(listener) {
|
|
18
|
-
this.subscribers.add(listener);
|
|
19
|
-
return () => this.subscribers.delete(listener);
|
|
20
|
-
}
|
|
21
|
-
register(input) {
|
|
22
|
-
const key = getConnectionKey(input);
|
|
23
|
-
const now = Date.now();
|
|
24
|
-
const existing = this.connections.get(key);
|
|
25
|
-
if (existing) {
|
|
26
|
-
this.logger.debug({ clientId: input.clientId, connectionId: input.connectionId }, "Replacing existing client connection");
|
|
27
|
-
this.disconnect(key, "replaced");
|
|
28
|
-
}
|
|
29
|
-
const connection = {
|
|
30
|
-
key,
|
|
31
|
-
clientId: input.clientId,
|
|
32
|
-
connectionId: input.connectionId,
|
|
33
|
-
connectedAt: now,
|
|
34
|
-
lastSeenAt: now,
|
|
35
|
-
close: input.close,
|
|
36
|
-
};
|
|
37
|
-
this.connections.set(key, connection);
|
|
38
|
-
this.logger.debug({ clientId: input.clientId, connectionId: input.connectionId }, "Client connected");
|
|
39
|
-
this.notify({ type: "connected", connection });
|
|
40
|
-
return () => this.disconnect(key, "closed");
|
|
41
|
-
}
|
|
42
|
-
pong(input) {
|
|
43
|
-
const key = getConnectionKey(input);
|
|
44
|
-
const connection = this.connections.get(key);
|
|
45
|
-
if (!connection) {
|
|
46
|
-
this.logger.debug({ clientId: input.clientId, connectionId: input.connectionId }, "Ignoring pong for unknown client connection");
|
|
47
|
-
return false;
|
|
48
|
-
}
|
|
49
|
-
connection.lastSeenAt = Date.now();
|
|
50
|
-
return true;
|
|
51
|
-
}
|
|
52
|
-
isConnected(input) {
|
|
53
|
-
return this.connections.has(getConnectionKey(input));
|
|
54
|
-
}
|
|
55
|
-
sweepStaleConnections() {
|
|
56
|
-
const cutoff = Date.now() - STALE_CONNECTION_TIMEOUT_MS;
|
|
57
|
-
for (const connection of Array.from(this.connections.values())) {
|
|
58
|
-
if (connection.lastSeenAt > cutoff)
|
|
59
|
-
continue;
|
|
60
|
-
this.logger.debug({ clientId: connection.clientId, connectionId: connection.connectionId }, "Client connection timed out");
|
|
61
|
-
this.disconnect(connection.key, "timeout");
|
|
62
|
-
}
|
|
63
|
-
}
|
|
64
|
-
disconnect(key, reason, invokeClose = true) {
|
|
65
|
-
const connection = this.connections.get(key);
|
|
66
|
-
if (!connection)
|
|
67
|
-
return;
|
|
68
|
-
this.connections.delete(key);
|
|
69
|
-
this.logger.debug({ clientId: connection.clientId, connectionId: connection.connectionId, reason }, "Client disconnected");
|
|
70
|
-
if (invokeClose) {
|
|
71
|
-
try {
|
|
72
|
-
connection.close();
|
|
73
|
-
}
|
|
74
|
-
catch (error) {
|
|
75
|
-
this.logger.warn({ err: error, clientId: connection.clientId, connectionId: connection.connectionId }, "Failed to close stale client connection");
|
|
76
|
-
}
|
|
77
|
-
}
|
|
78
|
-
this.notify({ type: "disconnected", connection, reason });
|
|
79
|
-
}
|
|
80
|
-
notify(event) {
|
|
81
|
-
for (const subscriber of this.subscribers) {
|
|
82
|
-
try {
|
|
83
|
-
subscriber(event);
|
|
84
|
-
}
|
|
85
|
-
catch (error) {
|
|
86
|
-
this.logger.warn({ err: error, eventType: event.type }, "Client connection subscriber failed");
|
|
87
|
-
}
|
|
88
|
-
}
|
|
89
|
-
}
|
|
90
|
-
}
|
|
91
|
-
function getConnectionKey(input) {
|
|
92
|
-
return `${input.clientId}:${input.connectionId}`;
|
|
93
|
-
}
|