@openchambery/web 1.19.22-beta.1 → 2.0.0-beta.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/README.md +13 -7
- package/bin/cli-opencode.test.js +208 -0
- package/bin/cli.js +62 -9
- package/bin/lib/cli-startup.js +105 -2
- package/bin/lib/cli-startup.test.js +179 -0
- package/dist/assets/{AgentAvatar-CRaBJXKs.js → AgentAvatar-CzTtVMnI.js} +1 -1
- package/dist/assets/AssistantView-Cg1qQvVe.js +3 -0
- package/dist/assets/{DiagramView-D1LGK_s2.js → DiagramView-hOi72Wdx.js} +1 -1
- package/dist/assets/{FadeInOnReveal-B0kJo9Ii.js → FadeInOnReveal-DCqrQkkz.js} +1 -1
- package/dist/assets/Icon-B8fSTLdP.js +1 -0
- package/dist/assets/MarkdownRenderer-Cw74oVxV.js +2 -0
- package/dist/assets/{MarkdownRendererImpl-DfoCJ1Mq.js → MarkdownRendererImpl-YM7iRmzK.js} +3 -3
- package/dist/assets/MarkstreamRendererImpl-BDy_oGJQ.js +3 -0
- package/dist/assets/MobileDetailNavigation-iX_hb_Xt.js +1 -0
- package/dist/assets/{MobileShareBridge-2Yjn6wXg.js → MobileShareBridge-CAMUupwR.js} +2 -2
- package/dist/assets/MobileSurface-CHbdPcLH.js +2 -0
- package/dist/assets/{MultiRunWindow-tTbMFowS.js → MultiRunWindow-Ci1ODFFX.js} +1 -1
- package/dist/assets/{OnboardingScreen-CD2KtlF3.js → OnboardingScreen-O4cGdz5p.js} +1 -1
- package/dist/assets/OverlayScrollbar-CRfGtcmG.js +2 -0
- package/dist/assets/SettingsView-Dg8BtTV1.js +25 -0
- package/dist/assets/{SettingsWindow-zIa76s4t.js → SettingsWindow-B8d8qIQ7.js} +1 -1
- package/dist/assets/TerminalView-CMiw3s_c.js +8 -0
- package/dist/assets/{ToolOutputDialog-DNqA4uBl.js → ToolOutputDialog-ByaQYRTp.js} +2 -2
- package/dist/assets/appThemeRegistry-BGGHio8T.js +1 -0
- package/dist/assets/{assistant-attachment-cache-C0aRnFkj.js → assistant-attachment-cache-DphJleHr.js} +1 -1
- package/dist/assets/{button-CI7Q-Zw_.js → button-DIIrsMjW.js} +1 -1
- package/dist/assets/{collapsible-D5Phaykh.js → collapsible-CnvUeYst.js} +1 -1
- package/dist/assets/{context-menu-CubSDW2g.js → context-menu-BGBUpZEQ.js} +1 -1
- package/dist/assets/{desktopHosts-B1ixEylr.js → desktopHosts-JGFqhlaM.js} +1 -1
- package/dist/assets/{desktopRelayRestore-4JmFUw8r.js → desktopRelayRestore-CHEwrI93.js} +1 -1
- package/dist/assets/{diagram-DdLO8HZ9.js → diagram-rvn7_qBM.js} +1 -1
- package/dist/assets/{dialog-B6pnIYmp.js → dialog-CQ63sc9E.js} +1 -1
- package/dist/assets/es-Dsmc0A_3.js +15 -0
- package/dist/assets/fileMentionTouchSelection-BzzcWJCi.js +3 -0
- package/dist/assets/{fileQueries-DQc8EJUf.js → fileQueries-DN6gbLhM.js} +1 -1
- package/dist/assets/fr-C_ZlZDI2.js +13 -0
- package/dist/assets/gitApi-BF8vuoZc.js +10 -0
- package/dist/assets/{imageSource-BlAJJUEI.js → imageSource-BMztRu0c.js} +1 -1
- package/dist/assets/{input-D-__fwRi.js → input-BVu-iykl.js} +1 -1
- package/dist/assets/insertionBoundaries-EcAfGT2D.js +1 -0
- package/dist/assets/ja-BqqTaWTi.js +15 -0
- package/dist/assets/ko-DP2XPM37.js +15 -0
- package/dist/assets/main-B7t9lavz.js +2 -0
- package/dist/assets/main-D2BzpnUt.css +1 -0
- package/dist/assets/main-DWP-prNB.js +169 -0
- package/dist/assets/markdown-worker-bS5OgGO3.js +2 -0
- package/dist/assets/{markdownHeightCache-BhxqJOvf.js → markdownHeightCache-D9-B1wdY.js} +1 -1
- package/dist/assets/markdownTheme-DM5h1i18.js +1 -0
- package/dist/assets/mcpQueries-CfXrAkuU.js +1 -0
- package/dist/assets/miniChat-DgOrEQbN.js +2 -0
- package/dist/assets/mobile-Co_ZOHkZ.js +2 -0
- package/dist/assets/multirun-DelyUO6k.js +4 -0
- package/dist/assets/persistence-D0y7226-.js +3 -0
- package/dist/assets/pl-BCf5uLlK.js +15 -0
- package/dist/assets/platform-CurqO28D.js +6 -0
- package/dist/assets/{projectMeta-S1hJ7oBp.js → projectMeta-CPElzJ0n.js} +2 -2
- package/dist/assets/pt-BR-W09Q2pvn.js +15 -0
- package/dist/assets/{relay-image-stream-DM7atqJs.js → relay-image-stream-DrdVj99c.js} +1 -1
- package/dist/assets/renderElectronMiniChatApp-pOE93w86.js +2 -0
- package/dist/assets/renderMobileApp-F7ZSLcw8.js +28 -0
- package/dist/assets/runtime-fetch-Fs9ZV2V8.js +1 -0
- package/dist/assets/{runtimeConfig-CMkwoQ_X.js → runtimeConfig-DSS0KxG3.js} +1 -1
- package/dist/assets/runtimeEndpointReset-x2Wgx57R.js +149 -0
- package/dist/assets/sessionChangeSummary-BUGSYcHp.js +2 -0
- package/dist/assets/{sessionLookup-BrU3rFHJ.js → sessionLookup-Bss8M20i.js} +1 -1
- package/dist/assets/{sortable-tabs-strip-Fnfhf3K9.js → sortable-tabs-strip-CE7W7lJ9.js} +1 -1
- package/dist/assets/src-lS1keDVV.css +2 -0
- package/dist/assets/store-jaP79mqI.js +15 -0
- package/dist/assets/{terminalApi-xjqssKke.js → terminalApi-mDR2jXTo.js} +1 -1
- package/dist/assets/textarea-XD2oX_Ee.js +1 -0
- package/dist/assets/{tooltip-0T5jv0cu.js → tooltip-DYeQ_Hvy.js} +1 -1
- package/dist/assets/uk-BgFzz8m2.js +15 -0
- package/dist/assets/{url-_z7evzdK.js → url-CGbJbiJq.js} +1 -1
- package/dist/assets/{useAppFontEffects-C02YFyAv.js → useAppFontEffects-BAWHZ-t0.js} +64 -45
- package/dist/assets/{useAssistantUIStore-CMutVh9B.js → useAssistantUIStore-Bz4tRflF.js} +1 -1
- package/dist/assets/useDesktopWindowControlsLayout-hN_nLb7T.js +1 -0
- package/dist/assets/useEffectiveDirectory-Do9DQ453.js +1 -0
- package/dist/assets/{useFontPreferences-B1JYyzpK.js → useFontPreferences-Bjx8zkGM.js} +1 -1
- package/dist/assets/useMobileNavigationStore-BsY_gi_K.js +414 -0
- package/dist/assets/useSessionAutoCleanup-C4g5KmDf.js +2 -0
- package/dist/assets/useUIStore-syVmbuDA.js +1 -0
- package/dist/assets/{useWorkerHighlightedLines-C9z0ML1z.js → useWorkerHighlightedLines-B5QXxBok.js} +2 -2
- package/dist/assets/vendor-opencode-client-C12gfjag.js +12 -0
- package/dist/assets/{vendor-reactuses-core-BnW6GxJt.js → vendor-reactuses-core-Dq5ocTF8.js} +1 -1
- package/dist/assets/{vendor-yaml-DIcAK3EC.js → vendor-yaml-C9KlJAlj.js} +37 -37
- package/dist/assets/zh-CN-BhqSLgUY.js +15 -0
- package/dist/assets/zh-TW-BsaBgY-p.js +15 -0
- package/dist/index.html +12 -12
- package/dist/mini-chat.html +12 -12
- package/dist/mobile.html +12 -12
- package/package.json +3 -2
- package/server/index.js +423 -20
- package/server/lib/assistants/DOCUMENTATION.md +26 -21
- package/server/lib/assistants/assign.js +2 -1
- package/server/lib/assistants/contact-store.js +37 -19
- package/server/lib/assistants/contracts.js +11 -1
- package/server/lib/assistants/projection-history.test.js +454 -0
- package/server/lib/assistants/routes.js +11 -5
- package/server/lib/assistants/service.js +850 -294
- package/server/lib/assistants/service.test.js +588 -274
- package/server/lib/browser-provider/DOCUMENTATION.md +141 -0
- package/server/lib/browser-provider/contract.js +312 -0
- package/server/lib/browser-provider/host.js +421 -0
- package/server/lib/browser-provider/host.test.js +304 -0
- package/server/lib/browser-provider/routes.js +122 -0
- package/server/lib/browser-provider/routes.test.js +120 -0
- package/server/lib/browser-provider/selection-store.js +43 -0
- package/server/lib/browser-provider/selection-store.test.js +35 -0
- package/server/lib/conversations/DOCUMENTATION.md +5 -5
- package/server/lib/conversations/service.js +87 -57
- package/server/lib/conversations/service.test.js +132 -100
- package/server/lib/conversations/validation.js +11 -1
- package/server/lib/event-stream/DOCUMENTATION.md +3 -1
- package/server/lib/event-stream/directory-ws-bridge.js +13 -2
- package/server/lib/event-stream/global-hub.js +51 -5
- package/server/lib/event-stream/reasoning-projection.js +16 -1
- package/server/lib/event-stream/reasoning-projection.test.js +15 -0
- package/server/lib/event-stream/runtime.js +57 -20
- package/server/lib/event-stream/runtime.test.js +112 -0
- package/server/lib/llm/DOCUMENTATION.md +95 -84
- package/server/lib/llm/catalog.js +111 -45
- package/server/lib/llm/catalog.test.js +121 -59
- package/server/lib/llm/completions.js +41 -12
- package/server/lib/llm/completions.test.js +45 -4
- package/server/lib/llm/generate.js +516 -453
- package/server/lib/llm/generate.test.js +705 -484
- package/server/lib/llm/routes.js +8 -4
- package/server/lib/message-queue/DOCUMENTATION.md +5 -5
- package/server/lib/message-queue/opencode-adapter.js +191 -104
- package/server/lib/message-queue/opencode-adapter.test.js +328 -58
- package/server/lib/message-queue/runtime.js +15 -2
- package/server/lib/message-queue/runtime.test.js +6 -6
- package/server/lib/message-queue/worker.js +7 -1
- package/server/lib/notifications/DOCUMENTATION.md +3 -1
- package/server/lib/notifications/runtime.js +133 -31
- package/server/lib/notifications/runtime.test.js +103 -0
- package/server/lib/notifications/template-runtime.js +130 -38
- package/server/lib/notifications/template-runtime.test.js +96 -0
- package/server/lib/opencode/DOCUMENTATION.md +111 -16
- package/server/lib/opencode/agent-document.d.ts +28 -0
- package/server/lib/opencode/agent-document.js +280 -0
- package/server/lib/opencode/agent-document.test.js +137 -0
- package/server/lib/opencode/agents.js +96 -0
- package/server/lib/opencode/auth-state-runtime.js +5 -0
- package/server/lib/opencode/bootstrap-runtime.js +2 -0
- package/server/lib/opencode/config-entity-routes.js +117 -103
- package/server/lib/opencode/config-entity-routes.test.js +148 -10
- package/server/lib/opencode/config-hot-reload.integration.test.js +105 -0
- package/server/lib/opencode/ensure-cli.d.ts +8 -0
- package/server/lib/opencode/ensure-cli.js +238 -0
- package/server/lib/opencode/ensure-cli.test.js +119 -0
- package/server/lib/opencode/env-runtime.js +208 -111
- package/server/lib/opencode/env-runtime.test.js +211 -14
- package/server/lib/opencode/feature-routes-runtime.js +90 -5
- package/server/lib/opencode/feature-routes-runtime.test.js +25 -0
- package/server/lib/opencode/http-server-connections.js +98 -0
- package/server/lib/opencode/http-server-connections.test.js +321 -0
- package/server/lib/opencode/lifecycle.js +539 -95
- package/server/lib/opencode/lifecycle.test.js +698 -6
- package/server/lib/opencode/managed-capabilities-runtime.js +15 -2
- package/server/lib/opencode/managed-capabilities-runtime.test.js +1 -0
- package/server/lib/opencode/network-runtime.js +28 -16
- package/server/lib/opencode/network-runtime.test.js +68 -4
- package/server/lib/opencode/openchamber-routes.js +7 -1
- package/server/lib/opencode/opencode2-pin.js +139 -0
- package/server/lib/opencode/opencode2-pin.test.js +88 -0
- package/server/lib/opencode/opencode2-sidecar.e2e.test.js +326 -0
- package/server/lib/opencode/owned-runtime-upgrade.js +431 -0
- package/server/lib/opencode/owned-runtime-upgrade.test.js +160 -0
- package/server/lib/opencode/plugin-compatibility.js +15 -0
- package/server/lib/opencode/plugin-compatibility.test.js +21 -0
- package/server/lib/opencode/plugin-routes.js +3 -18
- package/server/lib/opencode/plugin-routes.test.js +9 -9
- package/server/lib/opencode/plugins.js +4 -3
- package/server/lib/opencode/plugins.test.js +12 -0
- package/server/lib/opencode/provider-catalog.js +58 -12
- package/server/lib/opencode/provider-catalog.test.js +48 -0
- package/server/lib/opencode/proxy.js +373 -28
- package/server/lib/opencode/proxy.test.js +353 -0
- package/server/lib/opencode/routes.js +333 -76
- package/server/lib/opencode/routes.test.js +315 -50
- package/server/lib/opencode/runtime-contract.js +401 -0
- package/server/lib/opencode/runtime-contract.test.js +214 -0
- package/server/lib/opencode/server-opencode-fetch.js +242 -0
- package/server/lib/opencode/server-opencode-fetch.test.js +130 -0
- package/server/lib/opencode/server-utils-runtime.js +35 -0
- package/server/lib/opencode/shared-service.integration.test.js +66 -0
- package/server/lib/opencode/shared-service.js +147 -0
- package/server/lib/opencode/shared-service.test.js +93 -0
- package/server/lib/opencode/shared.js +3 -3
- package/server/lib/opencode/shutdown-runtime.js +15 -6
- package/server/lib/opencode/shutdown-runtime.test.js +49 -1
- package/server/lib/opencode/skill-routes.js +26 -40
- package/server/lib/opencode/skill-routes.test.js +71 -7
- package/server/lib/opencode/skills.test.js +15 -0
- package/server/lib/opencode/startup-pipeline-runtime.js +4 -0
- package/server/lib/opencode/static-routes-runtime.js +3 -1
- package/server/lib/opencode/static-routes-runtime.test.js +33 -0
- package/server/lib/opencode/upgrade-screen.d.ts +30 -0
- package/server/lib/opencode/upgrade-screen.js +299 -0
- package/server/lib/opencode/upgrade-screen.test.js +196 -0
- package/server/lib/opencode/v1-migration-gate.js +157 -0
- package/server/lib/opencode/v1-migration-gate.test.js +111 -0
- package/server/lib/opencode/v2-client.js +60 -0
- package/server/lib/opencode/v2-plugin-host-shim/index.mjs +155 -0
- package/server/lib/opencode/v2-plugin-host-shim/package.json +4 -0
- package/server/lib/opencode/watcher.js +2 -1
- package/server/lib/opencode/watcher.test.js +1 -1
- package/server/lib/permission-auto-accept/DOCUMENTATION.md +5 -5
- package/server/lib/permission-auto-accept/runtime.js +14 -7
- package/server/lib/permission-auto-accept/runtime.test.js +27 -12
- package/server/lib/relay/reasoning-projection.e2e.test.ts +22 -7
- package/server/lib/scheduled-tasks/DOCUMENTATION.md +79 -39
- package/server/lib/scheduled-tasks/managed-tool-route.js +31 -1
- package/server/lib/scheduled-tasks/managed-tool-route.test.js +23 -0
- package/server/lib/scheduled-tasks/routes.js +27 -0
- package/server/lib/scheduled-tasks/routes.test.js +94 -0
- package/server/lib/scheduled-tasks/runtime.js +381 -310
- package/server/lib/scheduled-tasks/runtime.test.js +600 -309
- package/server/lib/session-goal/DOCUMENTATION.md +173 -22
- package/server/lib/session-goal/capability.js +57 -0
- package/server/lib/session-goal/capability.test.js +33 -0
- package/server/lib/session-goal/routes.js +240 -2
- package/server/lib/session-goal/routes.test.js +211 -0
- package/server/lib/session-goal/runtime.js +1617 -113
- package/server/lib/session-goal/runtime.test.js +1500 -70
- package/server/lib/session-index/DOCUMENTATION.md +18 -15
- package/server/lib/session-index/event-ingest.js +89 -16
- package/server/lib/session-index/event-ingest.test.js +73 -0
- package/server/lib/session-index/host-authority-snapshot.js +92 -0
- package/server/lib/session-index/routes.host-archive.test.js +201 -0
- package/server/lib/session-index/routes.js +63 -10
- package/server/lib/session-index/routes.test.js +8 -8
- package/server/lib/session-index/service.js +7 -1
- package/server/lib/session-index/sync-runtime.js +171 -41
- package/server/lib/session-index/sync-runtime.test.js +164 -9
- package/server/lib/session-metadata/DOCUMENTATION.md +96 -0
- package/server/lib/session-metadata/opencode-session-record.d.ts +57 -0
- package/server/lib/session-metadata/opencode-session-record.js +316 -0
- package/server/lib/session-metadata/opencode-session-record.test.js +242 -0
- package/server/lib/session-metadata/routes.js +197 -0
- package/server/lib/session-metadata/routes.test.js +156 -0
- package/server/lib/session-metadata/session-archive.d.ts +73 -0
- package/server/lib/session-metadata/session-archive.js +654 -0
- package/server/lib/session-metadata/session-archive.test.js +359 -0
- package/server/lib/session-metadata/session-metadata-store.d.ts +38 -0
- package/server/lib/session-metadata/session-metadata-store.js +422 -0
- package/server/lib/session-metadata/session-metadata-store.test.js +379 -0
- package/server/lib/session-metadata/session-projection.d.ts +41 -0
- package/server/lib/session-metadata/session-projection.js +279 -0
- package/server/lib/session-metadata/session-projection.test.js +64 -0
- package/server/lib/session-metadata/system-session.js +55 -0
- package/server/lib/session-metadata/system-session.test.js +55 -0
- package/server/lib/session-title/DOCUMENTATION.md +40 -7
- package/server/lib/session-title/native-runtime.test.js +167 -0
- package/server/lib/session-title/runtime.js +69 -44
- package/server/lib/session-title/session-access.js +46 -0
- package/server/lib/session-title/session-access.test.js +91 -0
- package/server/lib/session-turn-pages/DOCUMENTATION.md +12 -11
- package/server/lib/session-turn-pages/reconcile.service.js +1 -1
- package/server/lib/session-turn-pages/reconcile.service.test.js +16 -0
- package/server/lib/session-turn-pages/routes.js +123 -75
- package/server/lib/session-turn-pages/routes.test.js +566 -0
- package/server/lib/session-turn-pages/service.js +6 -2
- package/server/lib/session-turn-pages/service.test.js +34 -0
- package/server/lib/session-turn-pages/session-message-projection.d.ts +13 -0
- package/server/lib/session-turn-pages/session-message-projection.js +281 -0
- package/server/lib/small-model/DOCUMENTATION.md +101 -146
- package/server/lib/small-model/catalog.js +84 -54
- package/server/lib/small-model/catalog.test.js +111 -9
- package/server/lib/small-model/custom-api.js +68 -0
- package/server/lib/small-model/custom-api.test.js +64 -0
- package/server/lib/small-model/index.js +125 -241
- package/server/lib/small-model/resolve.js +35 -120
- package/server/lib/small-model/resolve.test.js +20 -110
- package/server/lib/small-model/routes.js +1 -3
- package/server/lib/small-model/summary-settings.test.js +157 -253
- package/server/opencode-proxy.test.js +63 -12
- package/dist/assets/AssistantView-BUveAgc4.js +0 -3
- package/dist/assets/Icon-BgdfPhNs.js +0 -1
- package/dist/assets/MarkdownRenderer-BbrbDH6-.js +0 -2
- package/dist/assets/MarkstreamRendererImpl-D2dsW5Lg.js +0 -3
- package/dist/assets/MobileDetailNavigation-B0aqKXd7.js +0 -1
- package/dist/assets/MobileSurface-DW7WfPsy.js +0 -2
- package/dist/assets/OverlayScrollbar-DrA0Vsg5.js +0 -2
- package/dist/assets/SettingsView-PkXIavr7.js +0 -25
- package/dist/assets/TerminalView-CDdzF4yi.js +0 -8
- package/dist/assets/appThemeRegistry-D5Yxg4YF.js +0 -1
- package/dist/assets/es-DA3MqOo0.js +0 -15
- package/dist/assets/fileMentionTouchSelection-DNeiqns-.js +0 -4
- package/dist/assets/fr-Dbz0CdIA.js +0 -13
- package/dist/assets/gitApi-DXyC4MiV.js +0 -7
- package/dist/assets/insertionBoundaries-KlOVrHHt.js +0 -1
- package/dist/assets/ja-DumanVQA.js +0 -15
- package/dist/assets/ko-C0IkiUjQ.js +0 -15
- package/dist/assets/main-BPS5ylib.js +0 -2
- package/dist/assets/main-Cpd9VWYs.js +0 -169
- package/dist/assets/main-qSeeJRW1.css +0 -1
- package/dist/assets/markdown-worker-CptoICmq.js +0 -2
- package/dist/assets/markdownTheme-DOfGg-A7.js +0 -1
- package/dist/assets/miniChat-B8_KLWiY.js +0 -2
- package/dist/assets/mobile-CtktKrXn.js +0 -2
- package/dist/assets/multirun-CYfP9Cfm.js +0 -4
- package/dist/assets/persistence-Ce3AnpEr.js +0 -3
- package/dist/assets/pl-B9No6MQp.js +0 -15
- package/dist/assets/platform-0w_Q9_ji.js +0 -2
- package/dist/assets/pt-BR-DyQ0WTDh.js +0 -15
- package/dist/assets/renderElectronMiniChatApp-iK14LWm8.js +0 -2
- package/dist/assets/renderMobileApp-DORLPWnb.js +0 -28
- package/dist/assets/runtime-fetch-zIalUnbb.js +0 -1
- package/dist/assets/runtimeEndpointReset-ChOxt-J7.js +0 -147
- package/dist/assets/sessionChangeSummary-NnxcqCTI.js +0 -2
- package/dist/assets/src-rS3zCcsC.css +0 -2
- package/dist/assets/store-5B_LDnLM.js +0 -15
- package/dist/assets/textarea-bHYxZtfH.js +0 -1
- package/dist/assets/uk-C_1KkqyP.js +0 -15
- package/dist/assets/useDesktopWindowControlsLayout-Dnr-jX0C.js +0 -1
- package/dist/assets/useEffectiveDirectory-CZLLyarc.js +0 -1
- package/dist/assets/useMobileNavigationStore-CoCiqNgm.js +0 -413
- package/dist/assets/useSessionAutoCleanup-xQyETQkG.js +0 -2
- package/dist/assets/useUIStore-Bxv3f23A.js +0 -1
- package/dist/assets/vendor-opencode-sdk-C07HQypa.js +0 -7
- package/dist/assets/zh-CN-uWILgBdt.js +0 -15
- package/dist/assets/zh-TW-MYfdvhbD.js +0 -15
- package/server/lib/small-model/call.js +0 -427
- package/server/lib/small-model/call.test.js +0 -382
- package/server/lib/small-model/opencode-session.js +0 -339
- package/server/lib/small-model/opencode-session.test.js +0 -177
|
@@ -0,0 +1,238 @@
|
|
|
1
|
+
import { spawnSync } from 'node:child_process';
|
|
2
|
+
import fs from 'node:fs';
|
|
3
|
+
import os from 'node:os';
|
|
4
|
+
import path from 'node:path';
|
|
5
|
+
import {
|
|
6
|
+
PINNED_OPENCODE2_VERSION,
|
|
7
|
+
isAcceptableOpenCode2HealthVersion,
|
|
8
|
+
isOpenCode2VersionAtLeast,
|
|
9
|
+
npmPackageForOpenCode2,
|
|
10
|
+
openCodeBinaryName,
|
|
11
|
+
parseOpenCode2VersionOutput,
|
|
12
|
+
} from './opencode2-pin.js';
|
|
13
|
+
|
|
14
|
+
const INSTALL_FETCH_TIMEOUT_MS = 30_000;
|
|
15
|
+
|
|
16
|
+
export function isOpenCode2AutoInstallEnabled(env = process.env) {
|
|
17
|
+
const value = typeof env.OPENCHAMBER_OPENCODE2_AUTO_INSTALL === 'string'
|
|
18
|
+
? env.OPENCHAMBER_OPENCODE2_AUTO_INSTALL.trim().toLowerCase()
|
|
19
|
+
: '';
|
|
20
|
+
return value !== '0' && value !== 'false' && value !== 'no';
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export function resolveOpenChamberDataDir(env = process.env, homedir = os.homedir) {
|
|
24
|
+
if (typeof env.OPENCHAMBER_DATA_DIR === 'string' && env.OPENCHAMBER_DATA_DIR.trim()) {
|
|
25
|
+
return path.resolve(env.OPENCHAMBER_DATA_DIR.trim());
|
|
26
|
+
}
|
|
27
|
+
const home = typeof homedir === 'function' ? homedir() : homedir;
|
|
28
|
+
return path.join(home, '.config', 'openchamber');
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export function installedOpenCode2BinaryPath(version = PINNED_OPENCODE2_VERSION, options = {}) {
|
|
32
|
+
const dataDir = options.dataDir || resolveOpenChamberDataDir(options.env, options.homedir);
|
|
33
|
+
return path.join(dataDir, 'opencode-cli', version, openCodeBinaryName(options.platform));
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
export function readOpenCode2BinaryVersion(binaryPath, options = {}) {
|
|
37
|
+
if (typeof binaryPath !== 'string' || !binaryPath.trim()) return '';
|
|
38
|
+
const run = typeof options.spawnSync === 'function' ? options.spawnSync : spawnSync;
|
|
39
|
+
try {
|
|
40
|
+
const result = run(binaryPath, ['--version'], {
|
|
41
|
+
encoding: 'utf8',
|
|
42
|
+
stdio: ['ignore', 'pipe', 'pipe'],
|
|
43
|
+
timeout: 8_000,
|
|
44
|
+
windowsHide: true,
|
|
45
|
+
});
|
|
46
|
+
if (result.status !== 0) return '';
|
|
47
|
+
return parseOpenCode2VersionOutput(`${result.stdout || ''}\n${result.stderr || ''}`);
|
|
48
|
+
} catch {
|
|
49
|
+
return '';
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
const resolveNpmRegistry = (options = {}) => {
|
|
54
|
+
const env = options.env || process.env;
|
|
55
|
+
const electronRoot = options.electronRoot;
|
|
56
|
+
const candidates = [
|
|
57
|
+
env.NPM_CONFIG_REGISTRY,
|
|
58
|
+
options.cwd ? path.join(options.cwd, '.npmrc') : null,
|
|
59
|
+
electronRoot ? path.join(electronRoot, '.npmrc') : null,
|
|
60
|
+
path.join(os.homedir(), '.npmrc'),
|
|
61
|
+
].filter(Boolean);
|
|
62
|
+
for (const candidate of candidates) {
|
|
63
|
+
try {
|
|
64
|
+
if (!String(candidate).endsWith('.npmrc')) {
|
|
65
|
+
if (/^https?:\/\//.test(candidate)) return String(candidate).replace(/\/+$/, '');
|
|
66
|
+
continue;
|
|
67
|
+
}
|
|
68
|
+
if (!fs.existsSync(candidate)) continue;
|
|
69
|
+
const match = fs.readFileSync(candidate, 'utf8').match(/^\s*registry\s*=\s*(\S+)\s*$/m);
|
|
70
|
+
if (match) return match[1].replace(/\/+$/, '');
|
|
71
|
+
} catch {
|
|
72
|
+
// Ignore unreadable npmrc candidates and fall back to the default registry.
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
return 'https://registry.npmjs.org';
|
|
76
|
+
};
|
|
77
|
+
|
|
78
|
+
const downloadBuffer = async (url, fetchImpl, timeoutMs) => {
|
|
79
|
+
const response = await fetchImpl(url, { signal: AbortSignal.timeout(timeoutMs) });
|
|
80
|
+
if (!response.ok) {
|
|
81
|
+
throw new Error(`Failed to download ${url}: ${response.status} ${response.statusText}`);
|
|
82
|
+
}
|
|
83
|
+
return Buffer.from(await response.arrayBuffer());
|
|
84
|
+
};
|
|
85
|
+
|
|
86
|
+
const extractArchive = (archivePath, destination, run) => {
|
|
87
|
+
fs.rmSync(destination, { recursive: true, force: true });
|
|
88
|
+
fs.mkdirSync(destination, { recursive: true });
|
|
89
|
+
if (archivePath.endsWith('.zip')) {
|
|
90
|
+
if (process.platform === 'win32') {
|
|
91
|
+
run('powershell.exe', [
|
|
92
|
+
'-NoLogo',
|
|
93
|
+
'-NoProfile',
|
|
94
|
+
'-NonInteractive',
|
|
95
|
+
'-ExecutionPolicy',
|
|
96
|
+
'Bypass',
|
|
97
|
+
'-Command',
|
|
98
|
+
`Expand-Archive -LiteralPath ${JSON.stringify(archivePath)} -DestinationPath ${JSON.stringify(destination)} -Force`,
|
|
99
|
+
]);
|
|
100
|
+
return;
|
|
101
|
+
}
|
|
102
|
+
run('unzip', ['-q', archivePath, '-d', destination]);
|
|
103
|
+
return;
|
|
104
|
+
}
|
|
105
|
+
if (archivePath.endsWith('.tar.gz') || archivePath.endsWith('.tgz')) {
|
|
106
|
+
run('tar', ['-xzf', archivePath, '-C', destination]);
|
|
107
|
+
return;
|
|
108
|
+
}
|
|
109
|
+
throw new Error(`Unsupported opencode2 CLI archive: ${archivePath}`);
|
|
110
|
+
};
|
|
111
|
+
|
|
112
|
+
const findBinary = (root, binaryName) => {
|
|
113
|
+
const entries = fs.readdirSync(root, { withFileTypes: true });
|
|
114
|
+
for (const entry of entries) {
|
|
115
|
+
const fullPath = path.join(root, entry.name);
|
|
116
|
+
if (entry.isFile() && entry.name.toLowerCase() === binaryName.toLowerCase()) {
|
|
117
|
+
return fullPath;
|
|
118
|
+
}
|
|
119
|
+
if (entry.isDirectory()) {
|
|
120
|
+
const found = findBinary(fullPath, binaryName);
|
|
121
|
+
if (found) return found;
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
return null;
|
|
125
|
+
};
|
|
126
|
+
|
|
127
|
+
export async function installPinnedOpenCode2Cli(options = {}) {
|
|
128
|
+
const version = options.version || PINNED_OPENCODE2_VERSION;
|
|
129
|
+
const platform = options.platform || process.platform;
|
|
130
|
+
const arch = options.arch || process.arch;
|
|
131
|
+
const dataDir = options.dataDir || resolveOpenChamberDataDir(options.env, options.homedir);
|
|
132
|
+
const binaryName = openCodeBinaryName(platform);
|
|
133
|
+
const outputBinary = installedOpenCode2BinaryPath(version, { dataDir, platform });
|
|
134
|
+
const run = typeof options.spawnSync === 'function' ? options.spawnSync : spawnSync;
|
|
135
|
+
const fetchImpl = typeof options.fetch === 'function' ? options.fetch : fetch;
|
|
136
|
+
const timeoutMs = Number.isFinite(options.timeoutMs) ? options.timeoutMs : INSTALL_FETCH_TIMEOUT_MS;
|
|
137
|
+
|
|
138
|
+
const cacheDir = path.join(dataDir, 'opencode-cli', '.cache', version, `${platform}-${arch}`);
|
|
139
|
+
const archivePath = path.join(cacheDir, 'opencode2-cli.tgz');
|
|
140
|
+
const packageName = npmPackageForOpenCode2(platform, arch);
|
|
141
|
+
|
|
142
|
+
if (!fs.existsSync(archivePath)) {
|
|
143
|
+
const registry = resolveNpmRegistry(options);
|
|
144
|
+
const metadataResponse = await fetchImpl(`${registry}/${encodeURIComponent(packageName)}/${version}`, {
|
|
145
|
+
signal: AbortSignal.timeout(timeoutMs),
|
|
146
|
+
});
|
|
147
|
+
if (!metadataResponse.ok) {
|
|
148
|
+
throw new Error(
|
|
149
|
+
`Failed to resolve ${packageName}@${version} on ${registry}: ${metadataResponse.status} ${metadataResponse.statusText}`,
|
|
150
|
+
);
|
|
151
|
+
}
|
|
152
|
+
const metadata = await metadataResponse.json();
|
|
153
|
+
const tarball = metadata?.dist?.tarball;
|
|
154
|
+
if (typeof tarball !== 'string' || !/^https?:\/\//.test(tarball)) {
|
|
155
|
+
throw new Error(`No tarball found for ${packageName}@${version} on ${registry}`);
|
|
156
|
+
}
|
|
157
|
+
const bytes = await downloadBuffer(tarball, fetchImpl, timeoutMs);
|
|
158
|
+
fs.mkdirSync(path.dirname(archivePath), { recursive: true });
|
|
159
|
+
const temp = `${archivePath}.tmp`;
|
|
160
|
+
fs.writeFileSync(temp, bytes);
|
|
161
|
+
fs.renameSync(temp, archivePath);
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
const extractDir = options.extractDir || path.join(cacheDir, 'extract');
|
|
165
|
+
if (typeof options.extract === 'function') {
|
|
166
|
+
await options.extract(archivePath, extractDir);
|
|
167
|
+
} else {
|
|
168
|
+
extractArchive(archivePath, extractDir, (command, args) => {
|
|
169
|
+
const result = run(command, args, {
|
|
170
|
+
encoding: 'utf8',
|
|
171
|
+
stdio: 'pipe',
|
|
172
|
+
windowsHide: true,
|
|
173
|
+
});
|
|
174
|
+
if (result.status !== 0) {
|
|
175
|
+
const stderr = result.stderr ? `\n${result.stderr.trim()}` : '';
|
|
176
|
+
const stdout = result.stdout ? `\n${result.stdout.trim()}` : '';
|
|
177
|
+
throw new Error(`Command failed: ${command} ${args.join(' ')}${stderr}${stdout}`);
|
|
178
|
+
}
|
|
179
|
+
return result;
|
|
180
|
+
});
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
const extractedBinary = findBinary(extractDir, binaryName);
|
|
184
|
+
if (!extractedBinary) {
|
|
185
|
+
throw new Error(`Archive ${archivePath} did not contain ${binaryName} or opencode`);
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
fs.mkdirSync(path.dirname(outputBinary), { recursive: true });
|
|
189
|
+
fs.copyFileSync(extractedBinary, outputBinary);
|
|
190
|
+
if (platform !== 'win32') {
|
|
191
|
+
fs.chmodSync(outputBinary, 0o755);
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
const preparedVersion = readOpenCode2BinaryVersion(outputBinary, options);
|
|
195
|
+
if (preparedVersion !== version) {
|
|
196
|
+
throw new Error(`Installed opencode2 version mismatch: expected ${version}, got ${preparedVersion || 'unknown'}`);
|
|
197
|
+
}
|
|
198
|
+
return outputBinary;
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
/**
|
|
202
|
+
* Reuse any discovered acceptable 2.x CLI. Install the pin only when nothing
|
|
203
|
+
* usable is already installed (global PATH, explicit override, or cache).
|
|
204
|
+
*/
|
|
205
|
+
export async function ensurePinnedOpenCode2Cli(input = {}) {
|
|
206
|
+
const pin = input.pin || PINNED_OPENCODE2_VERSION;
|
|
207
|
+
const discoveredPath = typeof input.discoveredPath === 'string' ? input.discoveredPath.trim() : '';
|
|
208
|
+
const autoInstall = input.autoInstall ?? isOpenCode2AutoInstallEnabled(input.env);
|
|
209
|
+
const readVersion = typeof input.readVersion === 'function'
|
|
210
|
+
? input.readVersion
|
|
211
|
+
: (binaryPath) => readOpenCode2BinaryVersion(binaryPath, input);
|
|
212
|
+
const install = typeof input.install === 'function' ? input.install : installPinnedOpenCode2Cli;
|
|
213
|
+
|
|
214
|
+
if (discoveredPath) {
|
|
215
|
+
const version = readVersion(discoveredPath);
|
|
216
|
+
if (isAcceptableOpenCode2HealthVersion(version)) {
|
|
217
|
+
return { path: discoveredPath, version, source: 'discovered', installed: false };
|
|
218
|
+
}
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
const cached = installedOpenCode2BinaryPath(pin, input);
|
|
222
|
+
const cachedVersion = readVersion(cached);
|
|
223
|
+
if (cachedVersion === pin || isOpenCode2VersionAtLeast(cachedVersion, pin)) {
|
|
224
|
+
return { path: cached, version: cachedVersion, source: 'installed', installed: false };
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
if (!autoInstall) {
|
|
228
|
+
const error = new Error(
|
|
229
|
+
`Unable to locate opencode ${pin}. Set OPENCODE_BINARY or install @opencode/cli@${pin}.`,
|
|
230
|
+
);
|
|
231
|
+
error.code = 'OPENCODE_CLI_MISSING';
|
|
232
|
+
throw error;
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
const installedPath = await install({ ...input, version: pin });
|
|
236
|
+
const version = readVersion(installedPath) || pin;
|
|
237
|
+
return { path: installedPath, version, source: 'installed', installed: true };
|
|
238
|
+
}
|
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
import fs from 'node:fs';
|
|
2
|
+
import os from 'node:os';
|
|
3
|
+
import path from 'node:path';
|
|
4
|
+
import { afterEach, describe, expect, it } from 'vitest';
|
|
5
|
+
import { PINNED_OPENCODE2_VERSION } from './opencode2-pin.js';
|
|
6
|
+
import {
|
|
7
|
+
ensurePinnedOpenCode2Cli,
|
|
8
|
+
installedOpenCode2BinaryPath,
|
|
9
|
+
isOpenCode2AutoInstallEnabled,
|
|
10
|
+
resolveOpenChamberDataDir,
|
|
11
|
+
} from './ensure-cli.js';
|
|
12
|
+
|
|
13
|
+
const tempDirs = [];
|
|
14
|
+
|
|
15
|
+
const createTempDir = (prefix) => {
|
|
16
|
+
const dir = fs.mkdtempSync(path.join(os.tmpdir(), prefix));
|
|
17
|
+
tempDirs.push(dir);
|
|
18
|
+
return dir;
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
afterEach(() => {
|
|
22
|
+
for (const dir of tempDirs.splice(0)) {
|
|
23
|
+
fs.rmSync(dir, { recursive: true, force: true });
|
|
24
|
+
}
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
describe('ensurePinnedOpenCode2Cli', () => {
|
|
28
|
+
it('keeps a discovered binary that already meets the pin', async () => {
|
|
29
|
+
const result = await ensurePinnedOpenCode2Cli({
|
|
30
|
+
discoveredPath: '/opt/opencode2',
|
|
31
|
+
pin: '2.0.12',
|
|
32
|
+
readVersion: () => '2.0.12',
|
|
33
|
+
install: async () => {
|
|
34
|
+
throw new Error('should not install');
|
|
35
|
+
},
|
|
36
|
+
});
|
|
37
|
+
expect(result).toEqual({
|
|
38
|
+
path: '/opt/opencode2',
|
|
39
|
+
version: '2.0.12',
|
|
40
|
+
source: 'discovered',
|
|
41
|
+
installed: false,
|
|
42
|
+
});
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
it('reuses an older global 2.x binary instead of reinstalling the pin', async () => {
|
|
46
|
+
const result = await ensurePinnedOpenCode2Cli({
|
|
47
|
+
discoveredPath: '/opt/old-opencode',
|
|
48
|
+
pin: '2.0.12',
|
|
49
|
+
readVersion: () => '2.0.5',
|
|
50
|
+
install: async () => {
|
|
51
|
+
throw new Error('should not install');
|
|
52
|
+
},
|
|
53
|
+
});
|
|
54
|
+
expect(result.source).toBe('discovered');
|
|
55
|
+
expect(result.path).toBe('/opt/old-opencode');
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
it('installs the pin only when no usable 2.x binary is present', async () => {
|
|
59
|
+
const dataDir = createTempDir('openchamber-ensure-cli-');
|
|
60
|
+
const installed = path.join(dataDir, 'opencode-cli', PINNED_OPENCODE2_VERSION, 'opencode');
|
|
61
|
+
let installedOnce = false;
|
|
62
|
+
const result = await ensurePinnedOpenCode2Cli({
|
|
63
|
+
discoveredPath: '',
|
|
64
|
+
pin: PINNED_OPENCODE2_VERSION,
|
|
65
|
+
dataDir,
|
|
66
|
+
platform: 'linux',
|
|
67
|
+
readVersion: (binaryPath) => {
|
|
68
|
+
if (binaryPath === installed && installedOnce) return PINNED_OPENCODE2_VERSION;
|
|
69
|
+
return '';
|
|
70
|
+
},
|
|
71
|
+
install: async () => {
|
|
72
|
+
installedOnce = true;
|
|
73
|
+
return installed;
|
|
74
|
+
},
|
|
75
|
+
});
|
|
76
|
+
expect(result).toEqual({
|
|
77
|
+
path: installed,
|
|
78
|
+
version: PINNED_OPENCODE2_VERSION,
|
|
79
|
+
source: 'installed',
|
|
80
|
+
installed: true,
|
|
81
|
+
});
|
|
82
|
+
});
|
|
83
|
+
|
|
84
|
+
it('reuses a cached pin without downloading', async () => {
|
|
85
|
+
const dataDir = createTempDir('openchamber-ensure-cached-');
|
|
86
|
+
const cached = installedOpenCode2BinaryPath(PINNED_OPENCODE2_VERSION, { dataDir, platform: 'linux' });
|
|
87
|
+
const result = await ensurePinnedOpenCode2Cli({
|
|
88
|
+
pin: PINNED_OPENCODE2_VERSION,
|
|
89
|
+
dataDir,
|
|
90
|
+
platform: 'linux',
|
|
91
|
+
readVersion: (binaryPath) => (binaryPath === cached ? PINNED_OPENCODE2_VERSION : ''),
|
|
92
|
+
install: async () => {
|
|
93
|
+
throw new Error('should not install');
|
|
94
|
+
},
|
|
95
|
+
});
|
|
96
|
+
expect(result.source).toBe('installed');
|
|
97
|
+
expect(result.installed).toBe(false);
|
|
98
|
+
expect(result.path).toBe(cached);
|
|
99
|
+
});
|
|
100
|
+
|
|
101
|
+
it('fails closed when auto-install is disabled and nothing usable is present', async () => {
|
|
102
|
+
await expect(ensurePinnedOpenCode2Cli({
|
|
103
|
+
pin: PINNED_OPENCODE2_VERSION,
|
|
104
|
+
autoInstall: false,
|
|
105
|
+
dataDir: createTempDir('openchamber-ensure-disabled-'),
|
|
106
|
+
readVersion: () => '',
|
|
107
|
+
})).rejects.toMatchObject({ code: 'OPENCODE_CLI_MISSING' });
|
|
108
|
+
});
|
|
109
|
+
|
|
110
|
+
it('treats OPENCHAMBER_OPENCODE2_AUTO_INSTALL=0 as disabled', () => {
|
|
111
|
+
expect(isOpenCode2AutoInstallEnabled({ OPENCHAMBER_OPENCODE2_AUTO_INSTALL: '0' })).toBe(false);
|
|
112
|
+
expect(isOpenCode2AutoInstallEnabled({})).toBe(true);
|
|
113
|
+
});
|
|
114
|
+
|
|
115
|
+
it('resolves the OpenChamber data dir from OPENCHAMBER_DATA_DIR', () => {
|
|
116
|
+
const dataDir = createTempDir('openchamber-data-dir-');
|
|
117
|
+
expect(resolveOpenChamberDataDir({ OPENCHAMBER_DATA_DIR: dataDir })).toBe(path.resolve(dataDir));
|
|
118
|
+
});
|
|
119
|
+
});
|