@openchamber/web 1.24.1 → 2.0.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/bin/cli.test.js +22 -0
- package/bin/lib/commands-connect-url.js +3 -8
- package/bin/lib/commands-status.js +5 -0
- package/bin/lib/commands-tunnel.js +3 -0
- package/dist/assets/{CodeMirrorCommentWidgets-DvUH815P.js → CodeMirrorCommentWidgets-hJbl3JX4.js} +1 -1
- package/dist/assets/DiffView-BucGEJYa.js +4 -0
- package/dist/assets/FilesView-CQcaaAVP.js +17 -0
- package/dist/assets/{GitView-Bxuv3dfP.js → GitView-DY4pelsO.js} +4 -4
- package/dist/assets/{GuestAttachDialog-B0u3Q5uO.js → GuestAttachDialog-D6mHDTB2.js} +1 -1
- package/dist/assets/GuestSurfacePane--DJ7rsmY.js +1 -0
- package/dist/assets/{JsonTreeView-BBVPFM5K.js → JsonTreeView-DEXI2NvJ.js} +1 -1
- package/dist/assets/KaTeX_AMS-Regular-BQhdFMY1.woff2 +0 -0
- package/dist/assets/KaTeX_AMS-Regular-DMm9YOAa.woff +0 -0
- package/dist/assets/KaTeX_AMS-Regular-DRggAlZN.ttf +0 -0
- package/dist/assets/KaTeX_Caligraphic-Bold-ATXxdsX0.ttf +0 -0
- package/dist/assets/KaTeX_Caligraphic-Bold-BEiXGLvX.woff +0 -0
- package/dist/assets/KaTeX_Caligraphic-Bold-Dq_IR9rO.woff2 +0 -0
- package/dist/assets/KaTeX_Caligraphic-Regular-CTRA-rTL.woff +0 -0
- package/dist/assets/KaTeX_Caligraphic-Regular-Di6jR-x-.woff2 +0 -0
- package/dist/assets/KaTeX_Caligraphic-Regular-wX97UBjC.ttf +0 -0
- package/dist/assets/KaTeX_Fraktur-Bold-BdnERNNW.ttf +0 -0
- package/dist/assets/KaTeX_Fraktur-Bold-BsDP51OF.woff +0 -0
- package/dist/assets/KaTeX_Fraktur-Bold-CL6g_b3V.woff2 +0 -0
- package/dist/assets/KaTeX_Fraktur-Regular-CB_wures.ttf +0 -0
- package/dist/assets/KaTeX_Fraktur-Regular-CTYiF6lA.woff2 +0 -0
- package/dist/assets/KaTeX_Fraktur-Regular-Dxdc4cR9.woff +0 -0
- package/dist/assets/KaTeX_Main-Bold-Cx986IdX.woff2 +0 -0
- package/dist/assets/KaTeX_Main-Bold-Jm3AIy58.woff +0 -0
- package/dist/assets/KaTeX_Main-Bold-waoOVXN0.ttf +0 -0
- package/dist/assets/KaTeX_Main-BoldItalic-DxDJ3AOS.woff2 +0 -0
- package/dist/assets/KaTeX_Main-BoldItalic-DzxPMmG6.ttf +0 -0
- package/dist/assets/KaTeX_Main-BoldItalic-SpSLRI95.woff +0 -0
- package/dist/assets/KaTeX_Main-Italic-3WenGoN9.ttf +0 -0
- package/dist/assets/KaTeX_Main-Italic-BMLOBm91.woff +0 -0
- package/dist/assets/KaTeX_Main-Italic-NWA7e6Wa.woff2 +0 -0
- package/dist/assets/KaTeX_Main-Regular-B22Nviop.woff2 +0 -0
- package/dist/assets/KaTeX_Main-Regular-Dr94JaBh.woff +0 -0
- package/dist/assets/KaTeX_Main-Regular-ypZvNtVU.ttf +0 -0
- package/dist/assets/KaTeX_Math-BoldItalic-B3XSjfu4.ttf +0 -0
- package/dist/assets/KaTeX_Math-BoldItalic-CZnvNsCZ.woff2 +0 -0
- package/dist/assets/KaTeX_Math-BoldItalic-iY-2wyZ7.woff +0 -0
- package/dist/assets/KaTeX_Math-Italic-DA0__PXp.woff +0 -0
- package/dist/assets/KaTeX_Math-Italic-flOr_0UB.ttf +0 -0
- package/dist/assets/KaTeX_Math-Italic-t53AETM-.woff2 +0 -0
- package/dist/assets/KaTeX_SansSerif-Bold-CFMepnvq.ttf +0 -0
- package/dist/assets/KaTeX_SansSerif-Bold-D1sUS0GD.woff2 +0 -0
- package/dist/assets/KaTeX_SansSerif-Bold-DbIhKOiC.woff +0 -0
- package/dist/assets/KaTeX_SansSerif-Italic-C3H0VqGB.woff2 +0 -0
- package/dist/assets/KaTeX_SansSerif-Italic-DN2j7dab.woff +0 -0
- package/dist/assets/KaTeX_SansSerif-Italic-YYjJ1zSn.ttf +0 -0
- package/dist/assets/KaTeX_SansSerif-Regular-BNo7hRIc.ttf +0 -0
- package/dist/assets/KaTeX_SansSerif-Regular-CS6fqUqJ.woff +0 -0
- package/dist/assets/KaTeX_SansSerif-Regular-DDBCnlJ7.woff2 +0 -0
- package/dist/assets/KaTeX_Script-Regular-C5JkGWo-.ttf +0 -0
- package/dist/assets/KaTeX_Script-Regular-D3wIWfF6.woff2 +0 -0
- package/dist/assets/KaTeX_Script-Regular-D5yQViql.woff +0 -0
- package/dist/assets/KaTeX_Size1-Regular-C195tn64.woff +0 -0
- package/dist/assets/KaTeX_Size1-Regular-Dbsnue_I.ttf +0 -0
- package/dist/assets/KaTeX_Size1-Regular-mCD8mA8B.woff2 +0 -0
- package/dist/assets/KaTeX_Size2-Regular-B7gKUWhC.ttf +0 -0
- package/dist/assets/KaTeX_Size2-Regular-Dy4dx90m.woff2 +0 -0
- package/dist/assets/KaTeX_Size2-Regular-oD1tc_U0.woff +0 -0
- package/dist/assets/KaTeX_Size3-Regular-CTq5MqoE.woff +0 -0
- package/dist/assets/KaTeX_Size3-Regular-DgpXs0kz.ttf +0 -0
- package/dist/assets/KaTeX_Size4-Regular-BF-4gkZK.woff +0 -0
- package/dist/assets/KaTeX_Size4-Regular-DWFBv043.ttf +0 -0
- package/dist/assets/KaTeX_Size4-Regular-Dl5lxZxV.woff2 +0 -0
- package/dist/assets/KaTeX_Typewriter-Regular-C0xS9mPB.woff +0 -0
- package/dist/assets/KaTeX_Typewriter-Regular-CO6r4hn1.woff2 +0 -0
- package/dist/assets/KaTeX_Typewriter-Regular-D3Ib7_Hf.ttf +0 -0
- package/dist/assets/LinearIssuesView-BTNc-4dN.js +1 -0
- package/dist/assets/MarkdownImageGallery-wcUUcf8l.js +1 -0
- package/dist/assets/MarkdownRendererImpl-BPe2TVV2.js +12 -0
- package/dist/assets/OnboardingScreen-FJUreEgI.js +1 -0
- package/dist/assets/{PatchDiff-C4rE5k6z.js → PatchDiff-C0oOkKnO.js} +1 -1
- package/dist/assets/PierreDiffViewer-asuSQAsf.js +210 -0
- package/dist/assets/PlanView-DGbasNHP.js +5 -0
- package/dist/assets/PluginPane-DImv8hV2.js +3 -0
- package/dist/assets/SettingsView-DOjuOljf.js +29 -0
- package/dist/assets/SettingsWindow-By4cqnqy.js +1 -0
- package/dist/assets/SubmoduleDiffSummary-C0P2tXLU.js +1 -0
- package/dist/assets/ToolOutputDialog-Cayc-yIM.js +15 -0
- package/dist/assets/ToolPartDiffPreview-B0jmpPQz.js +8 -0
- package/dist/assets/{VirtualizedFileDiff-CZgXWHjU.js → VirtualizedFileDiff-DsOpvWZD.js} +4 -4
- package/dist/assets/{WalkthroughView-wSpED5L4.js → WalkthroughView-CCakjyn9.js} +2 -2
- package/dist/assets/appThemeRegistry-Bw5oTm41.js +1 -0
- package/dist/assets/{commitAndPush-DZnzlhvc.js → commitAndPush-sGEelpjh.js} +1 -1
- package/dist/assets/{computeVirtualFileMetrics-VYnT_A2h.js → computeVirtualFileMetrics-B-4aLf4A.js} +1 -1
- package/dist/assets/de-CD9utsNj.js +10 -0
- package/dist/assets/es-NNum2rX8.js +16 -0
- package/dist/assets/fr-CJLGmduQ.js +14 -0
- package/dist/assets/index-B6r0Kv-B.js +1 -0
- package/dist/assets/index-DjGPR5vW.js +41 -0
- package/dist/assets/index-fCXJ-8Qt.css +1 -0
- package/dist/assets/{isDiffPlainText-ImDG3Uhg.js → isDiffPlainText-Ok-kgtJA.js} +1 -1
- package/dist/assets/{isFilePlainText-D_YDVYDb.js → isFilePlainText-0dLnkYm8.js} +1 -1
- package/dist/assets/ja-BuddHNi6.js +16 -0
- package/dist/assets/ko-BrwMbHmf.js +16 -0
- package/dist/assets/main-CjXBM_Xe.js +2 -0
- package/dist/assets/main-CxVyUDU_.js +896 -0
- package/dist/assets/markdownCore-B6PpX409.js +5 -0
- package/dist/assets/miniChat-DZ3OAeLN.js +2 -0
- package/dist/assets/mobile-CH0LOIF-.js +2 -0
- package/dist/assets/{patchFileDiff-DDQ6Rq5e.js → patchFileDiff-BFRGKaGH.js} +3 -3
- package/dist/assets/pl-BwN4TNlP.js +16 -0
- package/dist/assets/pt-BR-BhMtownO.js +16 -0
- package/dist/assets/renderElectronMiniChatApp-CB1uLYvh.js +2 -0
- package/dist/assets/renderMobileApp-nQ4sjQtb.js +25 -0
- package/dist/assets/runtimeEndpointReset-9ZGlXU4J.js +27 -0
- package/dist/assets/scheduledTasksApi-6DsL_SwM.js +1 -0
- package/dist/assets/{shikiHighlight-1imXsir9.js → shikiHighlight-CocY80VR.js} +1 -1
- package/dist/assets/{textMateThemeFromAppTheme-Dgqc63LZ.js → textMateThemeFromAppTheme-CF77r8FA.js} +1 -1
- package/dist/assets/tr-DRzvqMdi.js +7 -0
- package/dist/assets/uk-b2aYOSNh.js +16 -0
- package/dist/assets/useAppFontEffects-Dc5nTHi8.js +7337 -0
- package/dist/assets/useInlineCommentController-Dbza5c8l.js +2 -0
- package/dist/assets/useRootScrollLock-CSCLv396.js +2 -0
- package/dist/assets/{vendor-codemirror-language-data-BDyxuqK4.js → vendor-codemirror-language-data-CkmYWcRI.js} +2 -2
- package/dist/assets/vendor-cron-parser-CjvYVigk.js +2 -0
- package/dist/assets/vendor-katex-Cp579UoJ.css +1 -0
- package/dist/assets/vendor-opencode-client-_BAHQo4R.js +12 -0
- package/dist/assets/{vendor-remixicon-react-BDmGmFCA.js → vendor-remixicon-react-D6dZ0UwF.js} +1 -1
- package/dist/assets/{vendor-zod-fZppILAM.js → vendor-zod-Gea9uBlY.js} +4 -4
- package/dist/assets/{web-components-D7FinaeH.js → web-components-nsStrYq9.js} +2 -2
- package/dist/assets/zh-CN-DZeUThm_.js +16 -0
- package/dist/assets/zh-TW-2fRE7uc6.js +16 -0
- package/dist/index.html +15 -7
- package/dist/mini-chat.html +7 -5
- package/dist/mobile.html +7 -5
- package/package.json +8 -7
- package/server/index.d.ts +1 -0
- package/server/index.js +248 -90
- package/server/lib/agent-tool/DOCUMENTATION.md +45 -15
- package/server/lib/agent-tool/runtime.js +189 -61
- package/server/lib/agent-tool/runtime.test.js +229 -75
- package/server/lib/browser-control/DOCUMENTATION.md +37 -2
- package/server/lib/browser-control/provider.js +217 -0
- package/server/lib/browser-control/provider.test.js +251 -0
- package/server/lib/context-obligatory/runtime.js +61 -50
- package/server/lib/context-obligatory/runtime.test.js +62 -162
- package/server/lib/event-stream/DOCUMENTATION.md +12 -1
- package/server/lib/event-stream/delta-coalescer.js +0 -0
- package/server/lib/event-stream/delta-coalescer.test.js +68 -57
- package/server/lib/event-stream/directory-ws-bridge.js +1 -1
- package/server/lib/event-stream/global-hub.js +10 -1
- package/server/lib/event-stream/global-hub.test.js +27 -26
- package/server/lib/event-stream/index.js +6 -0
- package/server/lib/event-stream/protocol.js +26 -19
- package/server/lib/event-stream/protocol.test.js +18 -7
- package/server/lib/event-stream/rebind.test.js +5 -5
- package/server/lib/event-stream/runtime.test.js +17 -15
- package/server/lib/event-stream/translate-v2.js +313 -0
- package/server/lib/event-stream/translate-v2.test.js +209 -0
- package/server/lib/event-stream/upstream-reader.test.js +16 -16
- package/server/lib/fs/DOCUMENTATION.md +6 -3
- package/server/lib/fs/byte-range.js +35 -0
- package/server/lib/fs/byte-range.test.js +31 -0
- package/server/lib/fs/routes.js +103 -46
- package/server/lib/fs/routes.test.js +239 -18
- package/server/lib/git/DOCUMENTATION.md +2 -2
- package/server/lib/git/service.js +106 -9
- package/server/lib/git/service.test.js +18 -0
- package/server/lib/github/DOCUMENTATION.md +1 -1
- package/server/lib/github/pr-status.js +22 -2
- package/server/lib/github/pr-status.test.js +27 -14
- package/server/lib/guests/DOCUMENTATION.md +13 -0
- package/server/lib/guests/catalog.js +12 -0
- package/server/lib/guests/catalog.test.js +33 -0
- package/server/lib/guests/routes.js +10 -1
- package/server/lib/guests/service.js +192 -14
- package/server/lib/guests/service.test.js +201 -1
- package/server/lib/guests/surface.js +630 -0
- package/server/lib/guests/surface.test.js +486 -0
- package/server/lib/markdown-image-grants/routes.js +18 -5
- package/server/lib/markdown-image-grants/routes.test.js +9 -6
- package/server/lib/message-queue/DOCUMENTATION.md +36 -22
- package/server/lib/message-queue/runtime.js +170 -100
- package/server/lib/message-queue/runtime.test.js +184 -82
- package/server/lib/notifications/DOCUMENTATION.md +28 -0
- package/server/lib/notifications/control-stream.http.test.js +68 -0
- package/server/lib/notifications/emitter-runtime.js +15 -0
- package/server/lib/notifications/emitter-runtime.test.js +32 -0
- package/server/lib/notifications/push-runtime.js +5 -1
- package/server/lib/notifications/push-runtime.test.js +2 -2
- package/server/lib/notifications/routes.js +5 -0
- package/server/lib/notifications/runtime.js +115 -26
- package/server/lib/notifications/template-runtime.js +13 -15
- package/server/lib/notifications/template-runtime.test.js +16 -9
- package/server/lib/notifications/trigger-runtime.test.js +187 -0
- package/server/lib/openchamber-control/DOCUMENTATION.md +10 -0
- package/server/lib/openchamber-control/actions.js +3 -2
- package/server/lib/openchamber-control/error.js +1 -1
- package/server/lib/openchamber-control/file-open.js +59 -0
- package/server/lib/openchamber-control/file-open.test.js +57 -0
- package/server/lib/openchamber-control/routes.test.js +12 -0
- package/server/lib/openchamber-control/service.js +102 -49
- package/server/lib/openchamber-control/service.test.js +84 -44
- package/server/lib/openchamber-sessions/archive-store.js +224 -0
- package/server/lib/openchamber-sessions/archive-store.test.js +187 -0
- package/server/lib/openchamber-sessions/opencode-client.js +22 -0
- package/server/lib/openchamber-sessions/routes.js +398 -328
- package/server/lib/openchamber-sessions/routes.test.js +786 -700
- package/server/lib/openchamber-sessions/session-metadata-store.js +285 -0
- package/server/lib/openchamber-sessions/session-metadata-store.test.js +259 -0
- package/server/lib/opencode/DOCUMENTATION.md +450 -30
- package/server/lib/opencode/agents.js +233 -327
- package/server/lib/opencode/auth.js +41 -44
- package/server/lib/opencode/auth.test.js +92 -0
- package/server/lib/opencode/bootstrap-runtime.js +1 -0
- package/server/lib/opencode/cli-upgrade.d.ts +4 -0
- package/server/lib/opencode/cli-upgrade.js +18 -0
- package/server/lib/opencode/cli-upgrade.test.js +36 -0
- package/server/lib/opencode/commands.js +164 -145
- package/server/lib/opencode/compatibility.d.ts +16 -0
- package/server/lib/opencode/compatibility.js +88 -0
- package/server/lib/opencode/compatibility.test.js +62 -0
- package/server/lib/opencode/config-entity-routes.js +58 -29
- package/server/lib/opencode/config-entity-v2.test.js +290 -0
- package/server/lib/opencode/config-mutation-response.js +17 -7
- package/server/lib/opencode/config-mutation-response.test.js +4 -7
- package/server/lib/opencode/config-paths.test.js +2 -2
- package/server/lib/opencode/config-v2.d.ts +183 -0
- package/server/lib/opencode/config-v2.js +801 -0
- package/server/lib/opencode/config-v2.test.js +466 -0
- package/server/lib/opencode/credential-db.js +144 -0
- package/server/lib/opencode/credential-db.test.js +104 -0
- package/server/lib/opencode/env-runtime.js +48 -9
- package/server/lib/opencode/env-runtime.test.js +45 -0
- package/server/lib/opencode/feature-routes-runtime.js +15 -5
- package/server/lib/opencode/lifecycle-process.test.js +7 -4
- package/server/lib/opencode/lifecycle.js +85 -30
- package/server/lib/opencode/lifecycle.test.js +80 -8
- package/server/lib/opencode/login-shell-env.js +27 -0
- package/server/lib/opencode/managed-config-file.js +119 -0
- package/server/lib/opencode/managed-config-file.test.js +152 -0
- package/server/lib/opencode/managed-plugin-config.js +33 -13
- package/server/lib/opencode/mcp.js +43 -149
- package/server/lib/opencode/network-runtime.js +6 -7
- package/server/lib/opencode/openchamber-routes.test.js +0 -1
- package/server/lib/opencode/plugin-routes.js +3 -3
- package/server/lib/opencode/plugin-routes.test.js +6 -24
- package/server/lib/opencode/plugins.js +91 -40
- package/server/lib/opencode/plugins.test.js +28 -15
- package/server/lib/opencode/providers.js +63 -83
- package/server/lib/opencode/providers.test.js +128 -59
- package/server/lib/opencode/proxy-agent-wiring.test.js +4 -2
- package/server/lib/opencode/proxy.js +179 -129
- package/server/lib/opencode/pwa-manifest-routes.js +4 -2
- package/server/lib/opencode/pwa-manifest-routes.test.js +3 -2
- package/server/lib/opencode/response-envelope.js +14 -0
- package/server/lib/opencode/response-envelope.test.js +23 -0
- package/server/lib/opencode/routes-upgrade.test.js +73 -116
- package/server/lib/opencode/routes.js +121 -428
- package/server/lib/opencode/server-utils-runtime.js +10 -4
- package/server/lib/opencode/session-activity.js +78 -0
- package/server/lib/opencode/session-runtime.js +79 -0
- package/server/lib/opencode/session-runtime.test.js +43 -0
- package/server/lib/opencode/settings-helpers.js +9 -9
- package/server/lib/opencode/settings-helpers.test.js +7 -12
- package/server/lib/opencode/settings-registry.json +6 -8
- package/server/lib/opencode/settings-runtime.js +18 -1
- package/server/lib/opencode/settings-runtime.test.js +31 -2
- package/server/lib/opencode/shared.js +54 -22
- package/server/lib/opencode/shared.test.js +8 -4
- package/server/lib/opencode/shutdown-runtime.js +54 -7
- package/server/lib/opencode/shutdown-runtime.test.js +224 -30
- package/server/lib/opencode/skill-routes.js +23 -24
- package/server/lib/opencode/skills.js +7 -5
- package/server/lib/opencode/tunnel-wiring-runtime.js +2 -1
- package/server/lib/opencode/upgrade-capability.test.js +1 -1
- package/server/lib/opencode/v1-migration-topup.js +288 -0
- package/server/lib/opencode/v1-migration-topup.test.js +266 -0
- package/server/lib/opencode/v2-install.d.ts +8 -0
- package/server/lib/opencode/v2-install.js +158 -0
- package/server/lib/opencode/v2-install.test.js +124 -0
- package/server/lib/opencode/watcher.js +10 -3
- package/server/lib/opencode/watcher.test.js +17 -21
- package/server/lib/opencode/websearch-config.js +66 -0
- package/server/lib/permission-auto-accept/runtime.js +38 -22
- package/server/lib/permission-auto-accept/runtime.test.js +39 -17
- package/server/lib/projects/project-config.js +2 -2
- package/server/lib/quota/DOCUMENTATION.md +4 -0
- package/server/lib/quota/providers/xai.js +4 -4
- package/server/lib/realtime-proxy-terminal.test.js +150 -0
- package/server/lib/realtime-proxy.js +2 -0
- package/server/lib/relay/tunnel-host.js +4 -1
- package/server/lib/relay/tunnel-host.test.js +7 -0
- package/server/lib/routing/DOCUMENTATION.md +52 -19
- package/server/lib/routing/defaults.js +23 -6
- package/server/lib/routing/jev.js +17 -7
- package/server/lib/routing/routes.http.test.js +68 -33
- package/server/lib/routing/routes.js +65 -22
- package/server/lib/routing/runtime.js +145 -48
- package/server/lib/routing/runtime.test.js +79 -55
- package/server/lib/scheduled-tasks/DOCUMENTATION.md +4 -0
- package/server/lib/scheduled-tasks/issue-2710-double-execution.test.js +51 -46
- package/server/lib/scheduled-tasks/runtime.js +83 -76
- package/server/lib/scheduled-tasks/runtime.test.js +67 -1
- package/server/lib/session-assist/DOCUMENTATION.md +8 -3
- package/server/lib/session-assist/context.js +122 -46
- package/server/lib/session-assist/context.test.js +117 -49
- package/server/lib/session-assist/runtime.js +52 -22
- package/server/lib/session-assist/runtime.test.js +145 -173
- package/server/lib/session-goal/DOCUMENTATION.md +23 -15
- package/server/lib/session-goal/create.js +9 -12
- package/server/lib/session-goal/create.test.js +27 -28
- package/server/lib/session-goal/runtime.js +164 -77
- package/server/lib/session-goal/runtime.test.js +271 -519
- package/server/lib/session-knowledge/DOCUMENTATION.md +5 -0
- package/server/lib/session-knowledge/runtime.js +59 -41
- package/server/lib/session-knowledge/runtime.test.js +90 -20
- package/server/lib/small-model/DOCUMENTATION.md +154 -196
- package/server/lib/small-model/client.js +113 -0
- package/server/lib/small-model/index.js +296 -158
- package/server/lib/small-model/index.test.js +423 -256
- package/server/lib/small-model/routes.js +1 -1
- package/server/lib/spaces/DOCUMENTATION.md +807 -0
- package/server/lib/spaces/code-in-bait.js +185 -0
- package/server/lib/spaces/code-in.js +641 -0
- package/server/lib/spaces/code-in.test.js +1048 -0
- package/server/lib/spaces/errors.js +8 -0
- package/server/lib/spaces/exec-http.js +94 -0
- package/server/lib/spaces/gatekeeper-channel.js +202 -0
- package/server/lib/spaces/gatekeeper-channel.test.js +215 -0
- package/server/lib/spaces/gatekeeper-program.cjs +914 -0
- package/server/lib/spaces/gatekeeper-program.test.js +1391 -0
- package/server/lib/spaces/hardening.js +457 -0
- package/server/lib/spaces/hardening.test.js +368 -0
- package/server/lib/spaces/host-git.js +127 -0
- package/server/lib/spaces/host-git.test.js +137 -0
- package/server/lib/spaces/labels.js +234 -0
- package/server/lib/spaces/labels.test.js +219 -0
- package/server/lib/spaces/layout.js +184 -0
- package/server/lib/spaces/layout.test.js +30 -0
- package/server/lib/spaces/manager.js +82 -0
- package/server/lib/spaces/manager.test.js +114 -0
- package/server/lib/spaces/places/code-in.docker.live.test.js +216 -0
- package/server/lib/spaces/places/contract-suite.js +156 -0
- package/server/lib/spaces/places/contract.docker.live.test.js +7 -0
- package/server/lib/spaces/places/contract.test.js +6 -0
- package/server/lib/spaces/places/docker-engine.js +126 -0
- package/server/lib/spaces/places/docker-live-support.js +202 -0
- package/server/lib/spaces/places/docker-tools.js +186 -0
- package/server/lib/spaces/places/docker.js +587 -0
- package/server/lib/spaces/places/docker.test.js +1610 -0
- package/server/lib/spaces/places/escape-suite.js +1018 -0
- package/server/lib/spaces/places/escape.docker.live.test.js +7 -0
- package/server/lib/spaces/places/fake-docker.js +375 -0
- package/server/lib/spaces/places/memory-place.js +103 -0
- package/server/lib/spaces/places/packed.docker.live.test.js +77 -0
- package/server/lib/spaces/places/registry.js +43 -0
- package/server/lib/spaces/places/registry.test.js +50 -0
- package/server/lib/spaces/places/server.docker.live.test.js +225 -0
- package/server/lib/spaces/run-command.js +261 -0
- package/server/lib/spaces/run-command.test.js +396 -0
- package/server/lib/spaces/space-server.js +190 -0
- package/server/lib/spaces/space-server.test.js +335 -0
- package/server/lib/spaces/tools-filler.js +82 -0
- package/server/lib/spaces/tools-filler.test.js +148 -0
- package/server/lib/spaces/tools-pack.js +49 -0
- package/server/lib/spaces/tools-pack.test.js +57 -0
- package/server/lib/spaces/tools.js +137 -0
- package/server/lib/spaces/tools.test.js +153 -0
- package/server/lib/terminal/DOCUMENTATION.md +21 -2
- package/server/lib/terminal/runtime.js +10 -3
- package/server/lib/terminal/runtime.test.js +22 -0
- package/server/lib/terminal/shutdown.js +106 -0
- package/server/lib/terminal/shutdown.test.js +84 -0
- package/server/lib/tts/openai-sdk.js +11 -0
- package/server/lib/tts/service.js +7 -5
- package/server/lib/tts/service.test.js +78 -0
- package/server/lib/tts/stt.js +3 -2
- package/server/lib/tunnels/DOCUMENTATION.md +2 -0
- package/server/lib/tunnels/routes.js +7 -0
- package/server/lib/tunnels/routes.test.js +55 -0
- package/server/lib/ui-auth/ui-auth.js +38 -2
- package/server/lib/ui-auth/ui-auth.test.js +42 -0
- package/server/lib/ui-auth/ui-passkeys.js +12 -10
- package/server/lib/walkthrough/DOCUMENTATION.md +10 -1
- package/server/lib/walkthrough/pull-request.js +61 -8
- package/server/lib/walkthrough/pull-request.test.js +54 -1
- package/server/lib/walkthrough/routes.js +20 -0
- package/server/lib/walkthrough/routes.test.js +19 -0
- package/server/opencode-proxy.test.js +190 -166
- package/server/opencode-worktree-readiness.test.js +5 -4
- package/dist/assets/DiffView-DkC3xlRJ.js +0 -4
- package/dist/assets/FilesView-D0bM9FVB.js +0 -13
- package/dist/assets/LinearIssuesView-UI1FcSC8.js +0 -1
- package/dist/assets/MarkdownImageGallery-CUJxH8Le.js +0 -1
- package/dist/assets/MarkdownRendererImpl-D5BZOg8X.js +0 -12
- package/dist/assets/OnboardingScreen-5Gou9cGD.js +0 -1
- package/dist/assets/PierreDiffViewer-ByRVu6ss.js +0 -161
- package/dist/assets/PlanView-u2yi5XGJ.js +0 -5
- package/dist/assets/PluginPane-QxjsKYeO.js +0 -3
- package/dist/assets/SettingsView-Fo5ZqMaT.js +0 -29
- package/dist/assets/SettingsWindow-HVDVANjJ.js +0 -1
- package/dist/assets/SubmoduleDiffSummary-D3hzkybB.js +0 -1
- package/dist/assets/ToolOutputDialog-3J6IRayW.js +0 -15
- package/dist/assets/ToolPartDiffPreview-DarxPjSd.js +0 -8
- package/dist/assets/appThemeRegistry-Cf8KitzT.js +0 -1
- package/dist/assets/de-BM_8EDD3.js +0 -10
- package/dist/assets/es-CxZjlqpo.js +0 -16
- package/dist/assets/fr-VCixCnMW.js +0 -14
- package/dist/assets/index-3U4CtS9b.js +0 -1
- package/dist/assets/index-B9Hvzjwl.css +0 -1
- package/dist/assets/index-DLHQogv8.js +0 -40
- package/dist/assets/ja-CZ5k_GyD.js +0 -16
- package/dist/assets/ko-7YM3A1Xh.js +0 -16
- package/dist/assets/main-CycplCph.js +0 -2
- package/dist/assets/main-DFYTCx5o.js +0 -896
- package/dist/assets/markdownCore-DHvqMxPn.js +0 -5
- package/dist/assets/miniChat-DIQKfY2V.js +0 -2
- package/dist/assets/mobile-BMwz5q-m.js +0 -2
- package/dist/assets/pl-BcgDO_w5.js +0 -16
- package/dist/assets/pt-BR-CU2u_1q5.js +0 -16
- package/dist/assets/renderElectronMiniChatApp-3_d6g6CU.js +0 -2
- package/dist/assets/renderMobileApp-D0Y8DtkA.js +0 -25
- package/dist/assets/runtimeEndpointReset-DhC3REb2.js +0 -25
- package/dist/assets/scheduledTasksApi-D8pq6gQz.js +0 -1
- package/dist/assets/tr-DuYhOzNe.js +0 -7
- package/dist/assets/uk-Cuk7-uvq.js +0 -16
- package/dist/assets/useAppFontEffects-BItUWdo4.js +0 -7333
- package/dist/assets/useInlineCommentController-CkbKsm7m.js +0 -2
- package/dist/assets/useRootScrollLock-vmzxZjWA.js +0 -2
- package/dist/assets/vendor-cron-parser-CUcP7OfX.js +0 -2
- package/dist/assets/vendor-opencode-sdk-BJ73u-bH.js +0 -7
- package/dist/assets/zh-CN-CUWoiRHd.js +0 -16
- package/dist/assets/zh-TW-CQ8EBSBN.js +0 -16
- package/server/lib/opencode/mcp-oauth-callback.test.js +0 -111
- package/server/lib/routing/feature-flag.js +0 -11
- package/server/lib/small-model/call.js +0 -820
- package/server/lib/small-model/call.test.js +0 -1110
- package/server/lib/small-model/catalog.js +0 -13
- package/server/lib/small-model/resolve.js +0 -131
- package/server/lib/small-model/resolve.test.js +0 -197
- package/server/lib/small-model/runtime-providers.js +0 -164
- package/server/lib/small-model/runtime-providers.test.js +0 -118
- package/server/lib/system-prompt/DOCUMENTATION.md +0 -36
- package/server/lib/system-prompt/runtime.js +0 -49
- package/server/lib/system-prompt/runtime.test.js +0 -76
- package/server/lib/walkthrough/reproduce-2607.test.js +0 -148
- /package/dist/assets/{vendor-katex-k3Ppq1Ha.js → vendor-katex-CHD9BdDO.js} +0 -0
|
@@ -1,21 +1,10 @@
|
|
|
1
1
|
import { afterEach, beforeEach, describe, expect, mock, test, vi } from 'bun:test';
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
mock.module('../git/index.js', () => ({
|
|
6
|
-
getRemotes: async () => [],
|
|
7
|
-
getTrackingBranch: async () => null,
|
|
8
|
-
}));
|
|
3
|
+
import { findBranchPrCandidates, invalidateRepoPullsCache, isHistoricalPrOfCheckout } from './pr-status.js';
|
|
9
4
|
|
|
10
|
-
mock
|
|
11
|
-
resolveGitHubRepoFromDirectory: async () => null,
|
|
12
|
-
}));
|
|
13
|
-
|
|
14
|
-
mock.module('./rate-limit.js', () => ({
|
|
15
|
-
noteIfGitHubRateLimit: () => {},
|
|
16
|
-
}));
|
|
5
|
+
const listMock = mock(async () => ({ data: [] }));
|
|
17
6
|
|
|
18
|
-
const
|
|
7
|
+
const isAncestorMock = mock(async () => false);
|
|
19
8
|
|
|
20
9
|
const openPr = {
|
|
21
10
|
number: 15,
|
|
@@ -180,3 +169,27 @@ describe('findBranchPrCandidates', () => {
|
|
|
180
169
|
expect(listMock.mock.calls.length).toBeGreaterThan(callsAfterFirst + 1);
|
|
181
170
|
});
|
|
182
171
|
});
|
|
172
|
+
|
|
173
|
+
describe('isHistoricalPrOfCheckout', () => {
|
|
174
|
+
beforeEach(() => {
|
|
175
|
+
isAncestorMock.mockReset();
|
|
176
|
+
});
|
|
177
|
+
|
|
178
|
+
test('a merged PR whose head commit is in the checkout history belongs to it', async () => {
|
|
179
|
+
isAncestorMock.mockImplementation(async () => true);
|
|
180
|
+
const pr = { ...mergedPr, head: { ...mergedPr.head, sha: 'abc1234' } };
|
|
181
|
+
expect(await isHistoricalPrOfCheckout('/repo', pr, { isAncestor: isAncestorMock })).toBe(true);
|
|
182
|
+
expect(isAncestorMock).toHaveBeenCalledWith('/repo', 'abc1234');
|
|
183
|
+
});
|
|
184
|
+
|
|
185
|
+
test('a reused branch name without the merged commits does not inherit the PR', async () => {
|
|
186
|
+
isAncestorMock.mockImplementation(async () => false);
|
|
187
|
+
const pr = { ...mergedPr, head: { ...mergedPr.head, sha: 'abc1234' } };
|
|
188
|
+
expect(await isHistoricalPrOfCheckout('/repo', pr, { isAncestor: isAncestorMock })).toBe(false);
|
|
189
|
+
});
|
|
190
|
+
|
|
191
|
+
test('a PR without a head sha is never attributed', async () => {
|
|
192
|
+
expect(await isHistoricalPrOfCheckout('/repo', mergedPr, { isAncestor: isAncestorMock })).toBe(false);
|
|
193
|
+
expect(isAncestorMock).not.toHaveBeenCalled();
|
|
194
|
+
});
|
|
195
|
+
});
|
|
@@ -62,7 +62,20 @@ A missing folder is omitted from the list. Other guests stay. A corrupt `extensi
|
|
|
62
62
|
- `contributes.actions`, `contributes.commands`, and `contributes.tools` are validated by the SDK parse at install (`invalid-actions` / `invalid-commands` / `invalid-tools` surface as `invalid-manifest`) and copied to the catalog row unchanged. Tool presentations are applied in the UI only (`packages/ui/src/lib/guests/tool-presentation.ts`); no server route reads them. No server route runs an action or a command: the message or session item is built in the UI from the same records Export as Markdown uses, and a slash command is answered by the guest frame over `postMessage`. The rail badge is UI memory only.
|
|
63
63
|
- `contributes.attach` is copied as `"panel"` or `"dialog"`. The composer + menu and New Worktree read that field. Omitted guests stay off those menus. The object form's `entry` (dialog only) is checked at install like `panel.entry`: missing HTML is `invalid-manifest`, an unbuilt script it loads is `missing-build`; the catalog exposes it as `attachEntry` and the attach window loads that page instead of `panel.entry`. The optional attach `data` payload lives only in the UI's chip, queued context part, and session metadata snapshot; no server route parses it.
|
|
64
64
|
- `request` never leaves the declared `apiOrigin`. A 401 refreshes once. If that fails, tokens for that guest are dropped. Host Linear does not drop Linear auth on a failed GraphQL query. A paused guest never proxies `request` or `serviceRequest`.
|
|
65
|
+
- A service with `provides: ["browser"]` is also driven by the host (`../browser-control/provider.js`), not only by a panel: `proxyGuestServiceRequest` takes `timeoutMs`, `responseMax`, `idleStopMs`, and `signal` for that. A service that never became ready is `SERVICE_FAILED` (nothing was sent); a request that was sent and got no usable answer is `REQUEST_FAILED` (the service may have acted on it), and callers word their errors accordingly. `idleStopMs` arms a per-guest timer re-armed at the end of every request; when it fires with no request in flight the process is discarded (not a Pause: no epoch bump) and the next request respawns it. A user-facing stop clears the timer. Panel requests pass none of these and keep the SDK limits. The guest routes call `onGuestDeactivated({ guestId, guestName })` after a pause, a removal, or a withdrawn approval so a host role the extension held is handed back and the user told.
|
|
66
|
+
- `surface.js` hosts shared surfaces (`contributes.service.surface`). `/api/guests/:id/surface/ws` (URL-token WebSocket, allowlisted in `ui-auth.js` and `relay/tunnel-host.js`; upgrade refused with 404 unless `isSurfaceGuest`: enabled, fully approved, declares the surface) attaches a viewer to the extension's one session. The session holds the service (`holdGuestService`) and runs one pump: `GET /surface/frame?after=<seq>&wait=25000` through `openGuestServiceRequest`, newest frame kept, delivered per viewer only after that viewer acknowledged the previous one (`frame` text message + one binary message). Control is the session's: `none`, `agent` (set by `noteAgentActivity`, expires after `SURFACE_AGENT_HOLD_MS`), or a viewer id; the first deliberate input (anything but a button-less pointer move) from a viewer while nobody or the agent holds it takes it, `release` or the holder's disconnect gives it back, a second viewer's input is refused with a `control` message. Every change is broadcast (`mine` per connection) and posted to `POST /surface/control`. Input, control notices, resizes, and clipboard reads run through one promise chain per session, in socket order; work queued for an ended session is dropped, and an ended session's close handlers never call the service, so closing a panel after a pause, removal, or withdrawn approval cannot restart the process under the session's old authorization. When the last viewer leaves normally the session stays registered until its queue (including the final `none`) has drained, so a deactivation in that window still finds and cancels it; a viewer that reattaches meanwhile restarts the pump. Every hand-off (release, holder disconnect) bumps `session.handoffs`; an input batch remembers the count it arrived under and, if it no longer holds control, may take control only when nothing was handed off since, so a click queued behind a slow request cannot re-take control after the user let go, and a viewer that left (`gone`) never becomes the controller. `userControls` gates the browser provider; `endForGuest` (pause, removal, withdrawn approval) and a failed frame request end the session with an `ended` reason, and `stop()` closes every viewer on shutdown.
|
|
65
67
|
- `serviceRequest` never leaves that guest's loopback port. Auth to the service is `Authorization: Bearer` with a host-minted token. The service env is an allowlist (PATH, HOME, temp, locale, Windows system variables) plus `OPENCHAMBER_SERVICE_*`; host secrets are not inherited. There is no sandbox: an allowed service has the user's full access, and the grant card says so. Ready is `GET /health` → 200. Parallel first requests share one spawn; they must not kill each other mid-start. Host quit stops every service. Disabling a guest stops its service without clearing OAuth or grants.
|
|
66
68
|
- File access is decided in `files.js` on canonical paths, never on the string the guest sent. `matchesFilesystemPattern`, `expandHome`, and `globToRegExp` are pure; `resolveGuestFilePath` and `runGuestFileOperation` take `fsPromises` / `nodePath` so tests can stub the OS. The project directory is whatever `resolveOptionalProjectDirectory` validated for this request, so a guest cannot name a project the UI did not open.
|
|
67
69
|
- Update swap (`updates.js` `updateGuest`): the new clone lands in `{dataDir}/extensions/.tmp-<id>-<random>` and is inspected exactly like an install before anything else moves. Only then: stop the guest's service, rename current → `.old-<id>`, rename temp → final, delete `.old-<id>`. Any failure before the swap deletes the temp dir and leaves the install untouched; a failed second rename moves `.old-<id>` back. The store row is not rewritten (same path, same id), the catalog cache and that guest's update cache entry are dropped.
|
|
68
70
|
- The OAuth callback skips UI auth. Everything else under `/api/guests` stays behind the usual session.
|
|
71
|
+
|
|
72
|
+
## Host shutdown
|
|
73
|
+
|
|
74
|
+
`beginGuestServiceShutdown` closes service admission synchronously. Requests retain
|
|
75
|
+
their host lifecycle across store reads and startup awaits, so a late completion
|
|
76
|
+
cannot spawn a process during shutdown or enter a later host lifecycle.
|
|
77
|
+
`stopAllGuestServices` cancels and drains pending starts as well as running and
|
|
78
|
+
already-stopping children. Per-guest Pause and ordinary cleanup do not close host
|
|
79
|
+
admission. `beginGuestServiceHost` opens a new lifecycle only after that drain.
|
|
80
|
+
The common graceful-shutdown runtime stops surface viewers before the services.
|
|
81
|
+
Crash/SIGKILL recovery remains outside this in-memory registry.
|
|
@@ -197,6 +197,12 @@ export const inspectGuestPackage = async (packageRoot, { openchamberVersion, ski
|
|
|
197
197
|
if (panel.entry) {
|
|
198
198
|
guest.entry = panel.entry;
|
|
199
199
|
}
|
|
200
|
+
if (panel.dock !== undefined) {
|
|
201
|
+
guest.entryDock = panel.dock;
|
|
202
|
+
}
|
|
203
|
+
if (panel.size !== undefined) {
|
|
204
|
+
guest.entrySize = panel.size;
|
|
205
|
+
}
|
|
200
206
|
const backgroundEntry = parsed.manifest.contributes.background?.entry;
|
|
201
207
|
if (backgroundEntry) {
|
|
202
208
|
if (!await resolveGuestAssetPath(packageRoot, backgroundEntry)) {
|
|
@@ -293,6 +299,12 @@ export const toPublicGuest = (guest) => {
|
|
|
293
299
|
if (guest.entry) {
|
|
294
300
|
row.entry = guest.entry;
|
|
295
301
|
}
|
|
302
|
+
if (guest.entryDock) {
|
|
303
|
+
row.entryDock = guest.entryDock;
|
|
304
|
+
}
|
|
305
|
+
if (typeof guest.entrySize === 'number') {
|
|
306
|
+
row.entrySize = guest.entrySize;
|
|
307
|
+
}
|
|
296
308
|
if (guest.backgroundEntry) {
|
|
297
309
|
row.backgroundEntry = guest.backgroundEntry;
|
|
298
310
|
}
|
|
@@ -204,6 +204,39 @@ describe('listInstalledGuests', () => {
|
|
|
204
204
|
|
|
205
205
|
await fs.rm(dir, { recursive: true, force: true });
|
|
206
206
|
});
|
|
207
|
+
|
|
208
|
+
test('a page docked beside a shared surface reaches the public row with its edge and size', async () => {
|
|
209
|
+
const dir = await fs.mkdtemp(path.join(os.tmpdir(), 'oc-guest-'));
|
|
210
|
+
const guestRoot = path.join(dir, 'sim');
|
|
211
|
+
await fs.mkdir(path.join(guestRoot, 'panel'), { recursive: true });
|
|
212
|
+
await fs.writeFile(path.join(guestRoot, 'panel', 'index.html'), '<script src="./main.js"></script>');
|
|
213
|
+
await fs.writeFile(path.join(guestRoot, 'panel', 'main.js'), 'console.log("strip")');
|
|
214
|
+
await fs.writeFile(path.join(guestRoot, 'service.js'), 'console.log("service")');
|
|
215
|
+
await fs.writeFile(path.join(guestRoot, 'package.json'), JSON.stringify({
|
|
216
|
+
name: '@openchamber/sim',
|
|
217
|
+
version: '1.0.0',
|
|
218
|
+
openchamber: {
|
|
219
|
+
apiVersion: 1,
|
|
220
|
+
contributes: {
|
|
221
|
+
panel: { id: 'sim', name: 'Sim', icon: 'window', entry: 'panel/index.html', dock: 'right', size: 240 },
|
|
222
|
+
service: { entry: 'service.js', runtime: 'host', surface: true },
|
|
223
|
+
},
|
|
224
|
+
},
|
|
225
|
+
}));
|
|
226
|
+
|
|
227
|
+
const inspected = await inspectGuestPackage(guestRoot, { openchamberVersion: '1.0.0' });
|
|
228
|
+
expect(inspected.ok).toBe(true);
|
|
229
|
+
if (inspected.ok) {
|
|
230
|
+
expect(toPublicGuest({ ...inspected.guest, source: 'path', path: guestRoot })).toMatchObject({
|
|
231
|
+
entry: 'panel/index.html',
|
|
232
|
+
entryDock: 'right',
|
|
233
|
+
entrySize: 240,
|
|
234
|
+
service: expect.objectContaining({ surface: true }),
|
|
235
|
+
});
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
await fs.rm(dir, { recursive: true, force: true });
|
|
239
|
+
});
|
|
207
240
|
});
|
|
208
241
|
|
|
209
242
|
describe('page-less packages', () => {
|
|
@@ -195,6 +195,7 @@ export const registerGuestRoutes = (app, {
|
|
|
195
195
|
resolveGitBinaryForSpawn,
|
|
196
196
|
resolveOptionalProjectDirectory,
|
|
197
197
|
getSmallModelService,
|
|
198
|
+
onGuestDeactivated = async () => false,
|
|
198
199
|
}) => {
|
|
199
200
|
const persistPath = extensionsPersistPath(openchamberDataDir);
|
|
200
201
|
const authPath = guestAuthPersistPath(openchamberDataDir);
|
|
@@ -309,6 +310,7 @@ export const registerGuestRoutes = (app, {
|
|
|
309
310
|
if (!isGuestPanelId(id)) {
|
|
310
311
|
return res.status(404).json({ error: 'not-found' });
|
|
311
312
|
}
|
|
313
|
+
const removed = await loadGuest(id);
|
|
312
314
|
const result = await uninstallGuest(id, persistPath);
|
|
313
315
|
if (!result.ok) {
|
|
314
316
|
const status = result.code === 'bundled' ? 400 : 404;
|
|
@@ -316,6 +318,9 @@ export const registerGuestRoutes = (app, {
|
|
|
316
318
|
}
|
|
317
319
|
// Remove means forget: tokens, client secret, and settings go with the package.
|
|
318
320
|
await forgetGuestAuth(id, authPath);
|
|
321
|
+
// A role this package stood in for (the agent's browser) goes back to
|
|
322
|
+
// the host's own, and the user is told rather than finding out mid-task.
|
|
323
|
+
await onGuestDeactivated({ guestId: id, guestName: removed?.name ?? id });
|
|
319
324
|
res.status(204).end();
|
|
320
325
|
} catch (error) {
|
|
321
326
|
console.error('Failed to uninstall guest:', error);
|
|
@@ -561,7 +566,7 @@ export const registerGuestRoutes = (app, {
|
|
|
561
566
|
res.json(result);
|
|
562
567
|
} catch (error) {
|
|
563
568
|
if (error instanceof GuestServiceError) {
|
|
564
|
-
const status = error.code === 'SERVICE_FAILED' ? 502 : 400;
|
|
569
|
+
const status = error.code === 'SERVICE_FAILED' || error.code === 'REQUEST_FAILED' ? 502 : 400;
|
|
565
570
|
return res.status(status).json({ error: error.code, message: error.message });
|
|
566
571
|
}
|
|
567
572
|
console.error('Failed to proxy guest service request:', error);
|
|
@@ -716,6 +721,7 @@ export const registerGuestRoutes = (app, {
|
|
|
716
721
|
await setCapabilityGrants(guest.id, persistPath, granted, granted.length > 0 ? scope : null);
|
|
717
722
|
if (granted.length === 0) {
|
|
718
723
|
await stopGuestService(guest.id);
|
|
724
|
+
await onGuestDeactivated({ guestId: guest.id, guestName: guest.name });
|
|
719
725
|
}
|
|
720
726
|
// Credentials were stored for one API origin and one pair of OAuth
|
|
721
727
|
// endpoints. When a newer version points the integration somewhere
|
|
@@ -745,6 +751,9 @@ export const registerGuestRoutes = (app, {
|
|
|
745
751
|
return res.status(400).json({ error: 'invalid-request' });
|
|
746
752
|
}
|
|
747
753
|
await setGuestEnabled(guest.id, persistPath, parsed.data.enabled);
|
|
754
|
+
if (!parsed.data.enabled) {
|
|
755
|
+
await onGuestDeactivated({ guestId: guest.id, guestName: guest.name });
|
|
756
|
+
}
|
|
748
757
|
const next = await loadGuest(guest.id);
|
|
749
758
|
if (!next) {
|
|
750
759
|
return res.status(404).json({ error: 'not-found' });
|
|
@@ -37,10 +37,39 @@ const runtimes = new Map();
|
|
|
37
37
|
/** @type {Map<string, Promise<ServiceRuntime>>} */
|
|
38
38
|
const startingByGuest = new Map();
|
|
39
39
|
|
|
40
|
+
/** @type {Map<string, Promise<void>>} */
|
|
41
|
+
const stoppingByGuest = new Map();
|
|
42
|
+
|
|
43
|
+
// Requests retain their lifecycle object across awaits. A later host start
|
|
44
|
+
// cannot reopen admission for work that belonged to the previous host.
|
|
45
|
+
let hostLifecycle = { accepting: true };
|
|
46
|
+
|
|
47
|
+
export const beginGuestServiceHost = () => {
|
|
48
|
+
if (runtimes.size || startingByGuest.size || stoppingByGuest.size) {
|
|
49
|
+
throw new Error('Guest services must finish stopping before a new host starts.');
|
|
50
|
+
}
|
|
51
|
+
hostLifecycle.accepting = false;
|
|
52
|
+
hostLifecycle = { accepting: true };
|
|
53
|
+
};
|
|
54
|
+
|
|
55
|
+
export const beginGuestServiceShutdown = () => {
|
|
56
|
+
hostLifecycle.accepting = false;
|
|
57
|
+
};
|
|
58
|
+
|
|
59
|
+
const assertGuestHostActive = (lifecycle) => {
|
|
60
|
+
if (!lifecycle.accepting) {
|
|
61
|
+
throw new GuestServiceError('The host is shutting down.', 'NO_SERVICE');
|
|
62
|
+
}
|
|
63
|
+
};
|
|
64
|
+
|
|
40
65
|
export class GuestServiceError extends Error {
|
|
41
66
|
/**
|
|
42
67
|
* @param {string} message
|
|
43
|
-
* @param {'NO_SERVICE' | 'SERVICE_FAILED' | 'BAD_PATH' | 'BAD_METHOD'} code
|
|
68
|
+
* @param {'NO_SERVICE' | 'SERVICE_FAILED' | 'REQUEST_FAILED' | 'BAD_PATH' | 'BAD_METHOD' | 'DISABLED' | 'CANCELLED'} code
|
|
69
|
+
* `SERVICE_FAILED` is a service that never became ready: nothing was sent
|
|
70
|
+
* to it. `REQUEST_FAILED` is a request that was sent and got no usable
|
|
71
|
+
* answer (timeout, dropped connection, unreadable body): the service may
|
|
72
|
+
* have acted on it.
|
|
44
73
|
*/
|
|
45
74
|
constructor(message, code) {
|
|
46
75
|
super(message);
|
|
@@ -175,6 +204,72 @@ const stopEpochs = new Map();
|
|
|
175
204
|
|
|
176
205
|
const stopEpochOf = (guestId) => stopEpochs.get(guestId) ?? 0;
|
|
177
206
|
|
|
207
|
+
/**
|
|
208
|
+
* Services the host starts on its own (a provider role) have no panel whose
|
|
209
|
+
* closing would end them, so they end themselves: a request arms a timer, the
|
|
210
|
+
* next request re-arms it, and when it fires with nothing in flight the
|
|
211
|
+
* process goes away. The next request starts it again. A panel-driven service
|
|
212
|
+
* passes no `idleStopMs` and keeps today's lifetime.
|
|
213
|
+
* @type {Map<string, { timer: ReturnType<typeof setTimeout>, inflight: number, idleMs: number }>}
|
|
214
|
+
*/
|
|
215
|
+
const idleStops = new Map();
|
|
216
|
+
|
|
217
|
+
const clearIdleStop = (guestId) => {
|
|
218
|
+
const entry = idleStops.get(guestId);
|
|
219
|
+
if (!entry) return;
|
|
220
|
+
clearTimeout(entry.timer);
|
|
221
|
+
idleStops.delete(guestId);
|
|
222
|
+
};
|
|
223
|
+
|
|
224
|
+
/** Long-lived consumers (a surface viewer) that keep an idle-stopping service up. */
|
|
225
|
+
const holds = new Map();
|
|
226
|
+
|
|
227
|
+
const armIdleStop = (guestId, idleMs) => {
|
|
228
|
+
const previous = idleStops.get(guestId);
|
|
229
|
+
const inflight = previous?.inflight ?? 0;
|
|
230
|
+
if (previous) clearTimeout(previous.timer);
|
|
231
|
+
const timer = setTimeout(() => {
|
|
232
|
+
const current = idleStops.get(guestId);
|
|
233
|
+
if (!current || current.inflight > 0 || (holds.get(guestId) ?? 0) > 0) {
|
|
234
|
+
// A request is running or a viewer is attached; whichever ends last
|
|
235
|
+
// re-arms the timer.
|
|
236
|
+
return;
|
|
237
|
+
}
|
|
238
|
+
idleStops.delete(guestId);
|
|
239
|
+
void discardRuntime(guestId);
|
|
240
|
+
}, idleMs);
|
|
241
|
+
timer.unref?.();
|
|
242
|
+
idleStops.set(guestId, { timer, inflight, idleMs });
|
|
243
|
+
};
|
|
244
|
+
|
|
245
|
+
/**
|
|
246
|
+
* Keeps an idle-stopping service alive while the returned release function
|
|
247
|
+
* has not been called. Releasing the last hold restarts the idle window.
|
|
248
|
+
* @param {string} guestId
|
|
249
|
+
*/
|
|
250
|
+
export const holdGuestService = (guestId) => {
|
|
251
|
+
holds.set(guestId, (holds.get(guestId) ?? 0) + 1);
|
|
252
|
+
let released = false;
|
|
253
|
+
return () => {
|
|
254
|
+
if (released) return;
|
|
255
|
+
released = true;
|
|
256
|
+
const remaining = (holds.get(guestId) ?? 1) - 1;
|
|
257
|
+
if (remaining > 0) {
|
|
258
|
+
holds.set(guestId, remaining);
|
|
259
|
+
return;
|
|
260
|
+
}
|
|
261
|
+
holds.delete(guestId);
|
|
262
|
+
const entry = idleStops.get(guestId);
|
|
263
|
+
if (entry && runtimes.get(guestId)) armIdleStop(guestId, entry.idleMs);
|
|
264
|
+
};
|
|
265
|
+
};
|
|
266
|
+
|
|
267
|
+
const trackInflight = (guestId, delta) => {
|
|
268
|
+
const entry = idleStops.get(guestId);
|
|
269
|
+
if (!entry) return;
|
|
270
|
+
entry.inflight = Math.max(0, entry.inflight + delta);
|
|
271
|
+
};
|
|
272
|
+
|
|
178
273
|
/**
|
|
179
274
|
* A user-facing stop (Pause, Remove, withdrawn approval, socket change,
|
|
180
275
|
* host quit): ends the process and cancels any request or start in flight.
|
|
@@ -182,6 +277,7 @@ const stopEpochOf = (guestId) => stopEpochs.get(guestId) ?? 0;
|
|
|
182
277
|
*/
|
|
183
278
|
export const stopGuestService = async (guestId) => {
|
|
184
279
|
stopEpochs.set(guestId, stopEpochOf(guestId) + 1);
|
|
280
|
+
clearIdleStop(guestId);
|
|
185
281
|
await discardRuntime(guestId);
|
|
186
282
|
};
|
|
187
283
|
|
|
@@ -192,6 +288,8 @@ export const stopGuestService = async (guestId) => {
|
|
|
192
288
|
* @param {string} guestId
|
|
193
289
|
*/
|
|
194
290
|
const discardRuntime = async (guestId) => {
|
|
291
|
+
const stopping = stoppingByGuest.get(guestId);
|
|
292
|
+
if (stopping) return stopping;
|
|
195
293
|
const runtime = runtimes.get(guestId);
|
|
196
294
|
if (!runtime) {
|
|
197
295
|
return;
|
|
@@ -202,7 +300,7 @@ const discardRuntime = async (guestId) => {
|
|
|
202
300
|
if (child.exitCode !== null || child.signalCode) {
|
|
203
301
|
return;
|
|
204
302
|
}
|
|
205
|
-
|
|
303
|
+
const stopped = new Promise((resolve) => {
|
|
206
304
|
const timer = setTimeout(() => {
|
|
207
305
|
child.kill('SIGKILL');
|
|
208
306
|
resolve(undefined);
|
|
@@ -213,14 +311,24 @@ const discardRuntime = async (guestId) => {
|
|
|
213
311
|
});
|
|
214
312
|
child.kill('SIGTERM');
|
|
215
313
|
});
|
|
314
|
+
stoppingByGuest.set(guestId, stopped);
|
|
315
|
+
try {
|
|
316
|
+
await stopped;
|
|
317
|
+
} finally {
|
|
318
|
+
stoppingByGuest.delete(guestId);
|
|
319
|
+
}
|
|
216
320
|
};
|
|
217
321
|
|
|
218
322
|
/** Test seam: the pid of a guest's running service, or `null`. */
|
|
219
323
|
export const readServicePid = (guestId) => runtimes.get(guestId)?.child.pid ?? null;
|
|
220
324
|
|
|
221
325
|
export const stopAllGuestServices = async () => {
|
|
222
|
-
const
|
|
223
|
-
|
|
326
|
+
const starts = [...startingByGuest.values()];
|
|
327
|
+
const ids = new Set([...runtimes.keys(), ...startingByGuest.keys(), ...stoppingByGuest.keys()]);
|
|
328
|
+
const stops = [...ids].map((id) => stopGuestService(id));
|
|
329
|
+
// Cancelled starts reject normally. Await their cleanup as well as children
|
|
330
|
+
// already registered when shutdown began.
|
|
331
|
+
await Promise.allSettled([...starts, ...stops]);
|
|
224
332
|
};
|
|
225
333
|
|
|
226
334
|
/**
|
|
@@ -266,7 +374,14 @@ const startGuestService = async ({
|
|
|
266
374
|
socketBindings = [],
|
|
267
375
|
socketOverrides = {},
|
|
268
376
|
epoch,
|
|
377
|
+
lifecycle,
|
|
269
378
|
}) => {
|
|
379
|
+
assertGuestHostActive(lifecycle);
|
|
380
|
+
// A replacement must not occupy the same guest slot while its previous
|
|
381
|
+
// child is still stopping; host shutdown must be able to drain both.
|
|
382
|
+
const previousStop = stoppingByGuest.get(guestId);
|
|
383
|
+
if (previousStop) await previousStop;
|
|
384
|
+
assertGuestHostActive(lifecycle);
|
|
270
385
|
const existing = runtimes.get(guestId);
|
|
271
386
|
if (existing?.status === 'ready' && existing.child.exitCode === null && !existing.child.signalCode) {
|
|
272
387
|
return existing;
|
|
@@ -276,7 +391,7 @@ const startGuestService = async ({
|
|
|
276
391
|
}
|
|
277
392
|
// The request's epoch, read before its first store access: a Pause that
|
|
278
393
|
// finished anywhere since then is a cancellation, spawn included.
|
|
279
|
-
const cancelled = () => stopEpochOf(guestId) !== epoch;
|
|
394
|
+
const cancelled = () => !lifecycle.accepting || stopEpochOf(guestId) !== epoch;
|
|
280
395
|
const stoppedError = () => new GuestServiceError('The service was stopped before it became ready.', 'NO_SERVICE');
|
|
281
396
|
|
|
282
397
|
const absoluteEntry = path.resolve(packageRoot, entry);
|
|
@@ -294,6 +409,7 @@ const startGuestService = async ({
|
|
|
294
409
|
throw stoppedError();
|
|
295
410
|
}
|
|
296
411
|
const port = await reserveLoopbackPort();
|
|
412
|
+
if (cancelled()) throw stoppedError();
|
|
297
413
|
const token = crypto.randomBytes(24).toString('hex');
|
|
298
414
|
const socketEnv = socketBindings.length > 0
|
|
299
415
|
? await resolveServiceSocketEnv(socketBindings, socketOverrides)
|
|
@@ -418,8 +534,15 @@ const ensureGuestService = async (params) => {
|
|
|
418
534
|
};
|
|
419
535
|
|
|
420
536
|
/**
|
|
537
|
+
* Starts the guest's service if needed and sends it one HTTP request, giving
|
|
538
|
+
* back the raw `Response`. This is the one place a host-driven caller (a
|
|
539
|
+
* provider role, a shared surface) or a panel proxy talks to the loopback:
|
|
540
|
+
* the enabled check, the grant, the spawn, the epoch, and the bearer live
|
|
541
|
+
* here. The caller reads the body as it needs it (text, JSON, image bytes).
|
|
542
|
+
*
|
|
421
543
|
* @param {{
|
|
422
544
|
* guestId: string,
|
|
545
|
+
* guestName?: string,
|
|
423
546
|
* packageRoot: string,
|
|
424
547
|
* service: { entry: string, permissions?: { sockets?: Array<{ id: string, candidatesByPlatform?: Partial<Record<'linux' | 'darwin' | 'win32', string[]>> }>, exec?: string[] } },
|
|
425
548
|
* granted: string[],
|
|
@@ -428,9 +551,16 @@ const ensureGuestService = async (params) => {
|
|
|
428
551
|
* path: string,
|
|
429
552
|
* query?: Record<string, string>,
|
|
430
553
|
* body?: string,
|
|
431
|
-
*
|
|
554
|
+
* accept?: string,
|
|
555
|
+
* timeoutMs?: number,
|
|
556
|
+
* idleStopMs?: number,
|
|
557
|
+
* signal?: AbortSignal,
|
|
558
|
+
* }} params `timeoutMs` and `idleStopMs` are for host-driven calls; a
|
|
559
|
+
* panel's `serviceRequest` keeps the SDK limits. With `idleStopMs` the
|
|
560
|
+
* service stops itself after that long without a request; `holdGuestService`
|
|
561
|
+
* suspends that while a long-lived consumer (a surface viewer) is attached.
|
|
432
562
|
*/
|
|
433
|
-
export const
|
|
563
|
+
export const openGuestServiceRequest = async ({
|
|
434
564
|
guestId,
|
|
435
565
|
guestName,
|
|
436
566
|
packageRoot,
|
|
@@ -441,7 +571,13 @@ export const proxyGuestServiceRequest = async ({
|
|
|
441
571
|
path: requestPath,
|
|
442
572
|
query,
|
|
443
573
|
body,
|
|
574
|
+
accept = 'application/json',
|
|
575
|
+
timeoutMs = GUEST_REQUEST_TIMEOUT_MS,
|
|
576
|
+
idleStopMs,
|
|
577
|
+
signal,
|
|
444
578
|
}) => {
|
|
579
|
+
const lifecycle = hostLifecycle;
|
|
580
|
+
assertGuestHostActive(lifecycle);
|
|
445
581
|
if (!METHODS.has(method)) {
|
|
446
582
|
throw new GuestServiceError('Unsupported request method.', 'BAD_METHOD');
|
|
447
583
|
}
|
|
@@ -453,6 +589,7 @@ export const proxyGuestServiceRequest = async ({
|
|
|
453
589
|
// enabled flag it read before the pause.
|
|
454
590
|
const epoch = stopEpochOf(guestId);
|
|
455
591
|
const store = await readExtensionStore(persistPath);
|
|
592
|
+
assertGuestHostActive(lifecycle);
|
|
456
593
|
if (store.disabledGuests?.[guestId]) {
|
|
457
594
|
const label = typeof guestName === 'string' && guestName.trim() ? guestName.trim() : 'This extension';
|
|
458
595
|
throw new GuestServiceError(
|
|
@@ -481,9 +618,10 @@ export const proxyGuestServiceRequest = async ({
|
|
|
481
618
|
socketBindings,
|
|
482
619
|
socketOverrides,
|
|
483
620
|
epoch,
|
|
621
|
+
lifecycle,
|
|
484
622
|
});
|
|
485
623
|
}
|
|
486
|
-
if (stopEpochOf(guestId) !== epoch) {
|
|
624
|
+
if (!lifecycle.accepting || stopEpochOf(guestId) !== epoch) {
|
|
487
625
|
if (runtimes.get(guestId) === runtime) {
|
|
488
626
|
await discardRuntime(guestId);
|
|
489
627
|
}
|
|
@@ -507,13 +645,24 @@ export const proxyGuestServiceRequest = async ({
|
|
|
507
645
|
|
|
508
646
|
/** @type {Record<string, string>} */
|
|
509
647
|
const headers = {
|
|
510
|
-
Accept:
|
|
648
|
+
Accept: accept,
|
|
511
649
|
[OPENCHAMBER_SERVICE_AUTH_HEADER]: `Bearer ${runtime.token}`,
|
|
512
650
|
};
|
|
513
651
|
if (body !== undefined && method !== 'GET') {
|
|
514
652
|
headers['Content-Type'] = 'application/json';
|
|
515
653
|
}
|
|
516
654
|
|
|
655
|
+
if (idleStopMs) {
|
|
656
|
+
armIdleStop(guestId, idleStopMs);
|
|
657
|
+
trackInflight(guestId, 1);
|
|
658
|
+
}
|
|
659
|
+
const settleIdle = () => {
|
|
660
|
+
if (!idleStopMs) return;
|
|
661
|
+
trackInflight(guestId, -1);
|
|
662
|
+
// Measured from the end of the last request, not its start: a long
|
|
663
|
+
// action must not be cut short by a timer armed before it began.
|
|
664
|
+
if (runtimes.get(guestId) === runtime) armIdleStop(guestId, idleStopMs);
|
|
665
|
+
};
|
|
517
666
|
let response;
|
|
518
667
|
try {
|
|
519
668
|
response = await fetch(url, {
|
|
@@ -521,18 +670,47 @@ export const proxyGuestServiceRequest = async ({
|
|
|
521
670
|
headers,
|
|
522
671
|
body: method === 'GET' || body === undefined ? undefined : body,
|
|
523
672
|
redirect: 'manual',
|
|
524
|
-
signal: AbortSignal.timeout(
|
|
673
|
+
signal: signal ? AbortSignal.any([signal, AbortSignal.timeout(timeoutMs)]) : AbortSignal.timeout(timeoutMs),
|
|
525
674
|
});
|
|
526
675
|
} catch {
|
|
676
|
+
settleIdle();
|
|
677
|
+
if (signal?.aborted) {
|
|
678
|
+
throw new GuestServiceError('The request was cancelled.', 'CANCELLED');
|
|
679
|
+
}
|
|
527
680
|
runtime.status = 'failed';
|
|
528
|
-
throw new GuestServiceError('Guest service request failed.', '
|
|
681
|
+
throw new GuestServiceError('Guest service request failed.', 'REQUEST_FAILED');
|
|
529
682
|
}
|
|
683
|
+
// The body is still streaming when we return; the idle window starts once
|
|
684
|
+
// the caller has read it (or dropped it), which is what `finished` marks.
|
|
685
|
+
return {
|
|
686
|
+
response,
|
|
687
|
+
finished: settleIdle,
|
|
688
|
+
};
|
|
689
|
+
};
|
|
530
690
|
|
|
531
|
-
|
|
691
|
+
/**
|
|
692
|
+
* Panel-shaped proxy: text answer, capped. Same params as
|
|
693
|
+
* `openGuestServiceRequest` plus `responseMax`.
|
|
694
|
+
*/
|
|
695
|
+
export const proxyGuestServiceRequest = async ({ responseMax = GUEST_REQUEST_RESPONSE_MAX, ...params }) => {
|
|
696
|
+
const { response, finished } = await openGuestServiceRequest(params);
|
|
697
|
+
let text;
|
|
698
|
+
try {
|
|
699
|
+
text = await response.text();
|
|
700
|
+
} catch {
|
|
701
|
+
finished();
|
|
702
|
+
if (params.signal?.aborted) {
|
|
703
|
+
throw new GuestServiceError('The request was cancelled.', 'CANCELLED');
|
|
704
|
+
}
|
|
705
|
+
const runtime = runtimes.get(params.guestId);
|
|
706
|
+
if (runtime) runtime.status = 'failed';
|
|
707
|
+
throw new GuestServiceError('Guest service request failed.', 'REQUEST_FAILED');
|
|
708
|
+
}
|
|
709
|
+
finished();
|
|
532
710
|
return {
|
|
533
711
|
status: response.status,
|
|
534
|
-
body: text.length <=
|
|
712
|
+
body: text.length <= responseMax
|
|
535
713
|
? text
|
|
536
|
-
: text.slice(0,
|
|
714
|
+
: text.slice(0, responseMax),
|
|
537
715
|
};
|
|
538
716
|
};
|