@openchambery/web 2.0.0-beta.9 → 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/README.md +14 -0
- package/dist/assets/{AgentAvatar-CzTtVMnI.js → AgentAvatar-C1MGZ7qC.js} +1 -1
- package/dist/assets/AssistantView-vqCFvVo0.js +3 -0
- package/dist/assets/{DiagramView-oeXj4YHn.js → DiagramView-CYO5iVVm.js} +1 -1
- package/dist/assets/{FadeInOnReveal-DCqrQkkz.js → FadeInOnReveal-BMSk_tY-.js} +1 -1
- package/dist/assets/Icon-BdzPRCSy.js +1 -0
- package/dist/assets/MarkdownRenderer-FMynjkGR.js +2 -0
- package/dist/assets/{MarkdownRendererImpl-CahUctxC.js → MarkdownRendererImpl-DoWvw5jj.js} +3 -3
- package/dist/assets/{MarkstreamRendererImpl-5JUaTSdl.js → MarkstreamRendererImpl-DoeYajmw.js} +1 -1
- package/dist/assets/{MobileDetailNavigation-agQ-Yhpd.js → MobileDetailNavigation-BzBz-co_.js} +1 -1
- package/dist/assets/{MobileShareBridge-yCN95dYg.js → MobileShareBridge-D1Uoj6l_.js} +3 -3
- package/dist/assets/MobileSurface-8YpZ51Qo.js +2 -0
- package/dist/assets/{MultiRunWindow-C0HqMFpp.js → MultiRunWindow-BxcYUPta.js} +1 -1
- package/dist/assets/{OnboardingScreen-O4cGdz5p.js → OnboardingScreen-yRdQTR1M.js} +1 -1
- package/dist/assets/{OverlayScrollbar-CRfGtcmG.js → OverlayScrollbar-BUjtqnxn.js} +1 -1
- package/dist/assets/SettingsView-D7KrvqvH.js +25 -0
- package/dist/assets/{SettingsWindow-B_d5Aqq3.js → SettingsWindow-DX2w-cDc.js} +1 -1
- package/dist/assets/{TerminalView-DdNQQb8W.js → TerminalView-CiUcCQPm.js} +1 -1
- package/dist/assets/{ToolOutputDialog-4DC5OE1J.js → ToolOutputDialog-DQvXtK71.js} +1 -1
- package/dist/assets/appThemeRegistry-BXC6cIDE.js +1 -0
- package/dist/assets/{assistant-attachment-cache-DphJleHr.js → assistant-attachment-cache-sG8YQsVs.js} +1 -1
- package/dist/assets/{button-DIIrsMjW.js → button-CUwjpv-i.js} +1 -1
- package/dist/assets/{collapsible-CnvUeYst.js → collapsible-paItOH3A.js} +1 -1
- package/dist/assets/{context-menu-BGBUpZEQ.js → context-menu-K6zNumqN.js} +1 -1
- package/dist/assets/{desktopHosts-JGFqhlaM.js → desktopHosts-DuftEj8B.js} +1 -1
- package/dist/assets/desktopRelayRestore-g378BdZf.js +1 -0
- package/dist/assets/{diagram-rvn7_qBM.js → diagram-D6nY5hbD.js} +1 -1
- package/dist/assets/dialog-PjKWayIU.js +1 -0
- package/dist/assets/dropdown-menu.styles-ayLWk2gf.js +1 -0
- package/dist/assets/{es-Dsmc0A_3.js → es-BBbon7SL.js} +4 -4
- package/dist/assets/fileMentionTouchSelection-78v5mNTE.js +2 -0
- package/dist/assets/{fileQueries-DN6gbLhM.js → fileQueries-DuF89nFO.js} +1 -1
- package/dist/assets/{fr-C_ZlZDI2.js → fr-BsKj2CTi.js} +4 -4
- package/dist/assets/{gitApi-da8etTTe.js → gitApi-eoKSJcvW.js} +4 -4
- package/dist/assets/{imageSource-BMztRu0c.js → imageSource-BpUsiwFd.js} +1 -1
- package/dist/assets/{input-BVu-iykl.js → input-BeVw4D0W.js} +1 -1
- package/dist/assets/insertionBoundaries-BI3RHOpf.js +1 -0
- package/dist/assets/{ja-BqqTaWTi.js → ja-1mgxunoM.js} +4 -4
- package/dist/assets/{ko-DP2XPM37.js → ko-Ra9znPcL.js} +4 -4
- package/dist/assets/main-CQpUPjPK.js +169 -0
- package/dist/assets/{main-KwlAomA8.js → main-MN0YKJ0_.js} +2 -2
- package/dist/assets/main-qSeeJRW1.css +1 -0
- package/dist/assets/{markdownHeightCache-D9-B1wdY.js → markdownHeightCache-CGCWmHgq.js} +1 -1
- package/dist/assets/{mcpQueries-3GTWeMU-.js → mcpQueries-X424Iq2z.js} +1 -1
- package/dist/assets/miniChat-DFIl76ku.js +2 -0
- package/dist/assets/mobile-C3fWXGQJ.js +2 -0
- package/dist/assets/multirun-DuSX3YRs.js +3 -0
- package/dist/assets/persistence-Dnj1QOdX.js +3 -0
- package/dist/assets/pl-B714sdql.js +15 -0
- package/dist/assets/platform-jCZ3KfMQ.js +6 -0
- package/dist/assets/projectMeta-Cn08pTNi.js +1 -0
- package/dist/assets/{pt-BR-W09Q2pvn.js → pt-BR-DVoT_I7_.js} +4 -4
- package/dist/assets/{relay-image-stream-DrdVj99c.js → relay-image-stream-D2XooXKZ.js} +1 -1
- package/dist/assets/renderElectronMiniChatApp-CRPdctIn.js +2 -0
- package/dist/assets/renderMobileApp-CVURQbeh.js +28 -0
- package/dist/assets/{runtime-fetch-Fs9ZV2V8.js → runtime-fetch-CiqQd__Y.js} +1 -1
- package/dist/assets/runtime-switch-BJM2k_uH.js +1 -0
- package/dist/assets/runtimeConfig-xivE1wxC.js +2 -0
- package/dist/assets/runtimeEndpointReset-B8DzKzwg.js +148 -0
- package/dist/assets/runtimeEndpointReset-D_vfNOQz.css +1 -0
- package/dist/assets/sessionChangeSummary-yBsR2pyd.js +2 -0
- package/dist/assets/{sessionLookup-0Z4e-J1g.js → sessionLookup-1Z1FWZRB.js} +1 -1
- package/dist/assets/{sortable-tabs-strip-CE7W7lJ9.js → sortable-tabs-strip-D611LPyd.js} +1 -1
- package/dist/assets/src-TBM7scxy.css +2 -0
- package/dist/assets/{store-jaP79mqI.js → store-l_X_jQNz.js} +4 -4
- package/dist/assets/{terminalApi-mDR2jXTo.js → terminalApi-BZW_rAc3.js} +1 -1
- package/dist/assets/{textarea-XD2oX_Ee.js → textarea-QtZjf4L8.js} +1 -1
- package/dist/assets/{tooltip-DYeQ_Hvy.js → tooltip-DDNnmcXI.js} +1 -1
- package/dist/assets/{uk-BgFzz8m2.js → uk-ChNnTgKP.js} +4 -4
- package/dist/assets/{url-CGbJbiJq.js → url-DNRMq_0R.js} +1 -1
- package/dist/assets/{useAppFontEffects-y_GTVXhJ.js → useAppFontEffects-DJy8P5By.js} +55 -55
- package/dist/assets/{useAssistantUIStore-Bz4tRflF.js → useAssistantUIStore-DBwfg9nX.js} +1 -1
- package/dist/assets/useDesktopWindowControlsLayout-DlwSomVK.js +1 -0
- package/dist/assets/{useEffectiveDirectory-BW9jNyuK.js → useEffectiveDirectory-eJorVTT9.js} +1 -1
- package/dist/assets/{useFontPreferences-Bjx8zkGM.js → useFontPreferences-Bjgt_lzl.js} +1 -1
- package/dist/assets/useMobileNavigationStore-A_ZNTfpl.js +415 -0
- package/dist/assets/useSessionAutoCleanup-CqC3dEou.js +2 -0
- package/dist/assets/{useUIStore-syVmbuDA.js → useUIStore-Dfx6TKvi.js} +1 -1
- package/dist/assets/{useWorkerHighlightedLines-BUcSLKlL.js → useWorkerHighlightedLines-B0vSL6jr.js} +1 -1
- package/dist/assets/vendor-opencode-client-MF2GBrFx.js +12 -0
- package/dist/assets/{vendor-zustand-B4dlGEM2.js → vendor-zustand-DzRqcymP.js} +1 -1
- package/dist/assets/{zh-CN-BhqSLgUY.js → zh-CN-DHEFf4u1.js} +4 -4
- package/dist/assets/{zh-TW-BsaBgY-p.js → zh-TW-rdSa8atW.js} +4 -4
- package/dist/index.html +13 -13
- package/dist/mini-chat.html +13 -13
- package/dist/mobile.html +13 -13
- package/package.json +3 -3
- package/server/index.js +8 -20
- package/server/lib/client-auth/remote-clients.js +15 -0
- package/server/lib/client-auth/remote-clients.test.js +42 -1
- package/server/lib/git/DOCUMENTATION.md +1 -0
- package/server/lib/git/routes.js +7 -4
- package/server/lib/git/routes.test.js +34 -0
- package/server/lib/git/service.js +3 -1
- package/server/lib/llm/DOCUMENTATION.md +6 -4
- package/server/lib/llm/generate.js +8 -9
- package/server/lib/llm/generate.test.js +33 -6
- package/server/lib/message-queue/service.js +1 -1
- package/server/lib/opencode/DOCUMENTATION.md +33 -22
- package/server/lib/opencode/agents.js +13 -22
- package/server/lib/opencode/auth-state-runtime.js +3 -3
- package/server/lib/opencode/auth-state-runtime.test.js +59 -0
- package/server/lib/opencode/auth.d.ts +13 -0
- package/server/lib/opencode/auth.js +74 -64
- package/server/lib/opencode/auth.test.js +57 -0
- package/server/lib/opencode/commands.js +1 -1
- package/server/lib/opencode/config-entities-layering.test.js +72 -0
- package/server/lib/opencode/config-entity-routes.js +10 -123
- package/server/lib/opencode/config-entity-routes.test.js +23 -11
- package/server/lib/opencode/config-files.d.ts +17 -0
- package/server/lib/opencode/config-files.js +187 -0
- package/server/lib/opencode/config-files.test.js +201 -0
- package/server/lib/opencode/core-routes.js +17 -1
- package/server/lib/opencode/core-routes.test.js +43 -15
- package/server/lib/opencode/credential-boundary.d.ts +1 -0
- package/server/lib/opencode/credential-boundary.js +11 -0
- package/server/lib/opencode/ensure-cli.js +4 -1
- package/server/lib/opencode/env-config.js +4 -1
- package/server/lib/opencode/env-config.test.js +28 -0
- package/server/lib/opencode/env-runtime.test.js +18 -1
- package/server/lib/opencode/feature-routes-runtime.js +9 -7
- package/server/lib/opencode/hmr-state-runtime.js +4 -4
- package/server/lib/opencode/lifecycle.js +1 -49
- package/server/lib/opencode/lifecycle.test.js +30 -4
- package/server/lib/opencode/location-release.d.ts +8 -0
- package/server/lib/opencode/location-release.js +32 -0
- package/server/lib/opencode/location-release.test.js +43 -0
- package/server/lib/opencode/mcp.js +1 -1
- package/server/lib/opencode/opencode2-pin.js +2 -1
- package/server/lib/opencode/owned-runtime-upgrade.test.js +5 -5
- package/server/lib/opencode/plugin-routes.test.js +4 -2
- package/server/lib/opencode/plugins.js +12 -60
- package/server/lib/opencode/plugins.test.js +5 -3
- package/server/lib/opencode/providers.js +6 -3
- package/server/lib/opencode/proxy.js +7 -0
- package/server/lib/opencode/proxy.test.js +13 -0
- package/server/lib/opencode/remote-upgrade.integration.test.js +66 -0
- package/server/lib/opencode/routes.js +10 -8
- package/server/lib/opencode/routes.test.js +51 -10
- package/server/lib/opencode/runtime-contract.js +3 -2
- package/server/lib/opencode/runtime-contract.test.js +12 -12
- package/server/lib/opencode/settings-normalization-runtime.js +3 -1
- package/server/lib/opencode/settings-normalization-runtime.test.js +36 -0
- package/server/lib/opencode/settings-runtime.test.js +58 -1
- package/server/lib/opencode/shared.js +6 -175
- package/server/lib/opencode/update-discovery.js +39 -0
- package/server/lib/opencode/update-discovery.test.js +39 -0
- package/server/lib/opencode/upgrade-screen.js +4 -11
- package/server/lib/opencode/upgrade-screen.test.js +25 -25
- package/server/lib/opencode/version-alignment.test.js +40 -0
- package/server/lib/question-auto-delegate/DOCUMENTATION.md +21 -6
- package/server/lib/question-auto-delegate/core.d.ts +5 -1
- package/server/lib/question-auto-delegate/core.js +21 -13
- package/server/lib/question-auto-delegate/form-io.d.ts +6 -0
- package/server/lib/question-auto-delegate/form-io.js +39 -0
- package/server/lib/question-auto-delegate/runtime.js +4 -24
- package/server/lib/question-auto-delegate/runtime.test.js +138 -0
- package/server/lib/quota/DOCUMENTATION.md +9 -0
- package/server/lib/quota/provider-credentials.test.js +29 -0
- package/server/lib/quota/providers/claude.js +4 -4
- package/server/lib/quota/providers/codex.js +4 -4
- package/server/lib/quota/providers/codex.test.js +1 -1
- package/server/lib/quota/providers/copilot.js +5 -5
- package/server/lib/quota/providers/google/auth.js +3 -3
- package/server/lib/quota/providers/google/index.js +2 -2
- package/server/lib/quota/providers/index.js +3 -7
- package/server/lib/quota/providers/index.test.js +2 -2
- package/server/lib/quota/providers/kimi.js +4 -4
- package/server/lib/quota/providers/minimax-shared.js +4 -4
- package/server/lib/quota/providers/nanogpt.js +4 -4
- package/server/lib/quota/providers/openai.js +4 -4
- package/server/lib/quota/providers/openrouter.js +4 -4
- package/server/lib/quota/providers/wafer.js +4 -4
- package/server/lib/quota/providers/zai.js +4 -4
- package/server/lib/quota/providers/zhipuai-coding-plan.js +6 -20
- package/server/lib/quota/routes.js +1 -1
- package/server/lib/relay/DOCUMENTATION.md +3 -1
- package/server/lib/relay/service.js +1 -0
- package/server/lib/relay/service.test.js +13 -0
- package/server/lib/scheduled-tasks/DOCUMENTATION.md +8 -1
- package/server/lib/scheduled-tasks/runtime.js +12 -4
- package/server/lib/scheduled-tasks/runtime.test.js +81 -6
- package/server/lib/session-goal/DOCUMENTATION.md +11 -0
- package/server/lib/session-goal/runtime.js +4 -4
- package/server/lib/session-goal/runtime.test.js +32 -3
- package/server/lib/session-index/DOCUMENTATION.md +7 -0
- package/server/lib/session-index/event-ingest.js +13 -0
- package/server/lib/session-index/event-ingest.test.js +7 -0
- package/server/lib/session-index/service.js +45 -0
- package/server/lib/session-index/service.test.js +47 -0
- package/server/lib/session-metadata/DOCUMENTATION.md +6 -0
- package/server/lib/session-metadata/session-metadata-store.test.js +23 -0
- package/server/lib/session-metadata/session-projection.d.ts +1 -0
- package/server/lib/session-metadata/session-projection.js +23 -0
- package/server/lib/session-metadata/session-projection.test.js +35 -0
- package/server/lib/session-title/DOCUMENTATION.md +52 -14
- package/server/lib/session-title/native-runtime.test.js +59 -5
- package/server/lib/session-title/runtime.js +63 -17
- package/server/lib/session-title/session-access.js +108 -3
- package/server/lib/session-title/session-access.test.js +125 -7
- package/server/lib/tts/DOCUMENTATION.md +7 -5
- package/server/lib/tts/credential-source.test.js +23 -0
- package/server/lib/tts/routes.js +2 -2
- package/server/lib/tts/service.js +16 -37
- package/dist/assets/AssistantView-CLFPj5Ki.js +0 -3
- package/dist/assets/Icon-B8fSTLdP.js +0 -1
- package/dist/assets/MarkdownRenderer-BK69MEHQ.js +0 -2
- package/dist/assets/MobileSurface-D0HP_lTS.js +0 -2
- package/dist/assets/SettingsView-xLYb22wV.js +0 -25
- package/dist/assets/appThemeRegistry-LkVH62uF.js +0 -1
- package/dist/assets/desktopRelayRestore-CHEwrI93.js +0 -1
- package/dist/assets/dialog-CQ63sc9E.js +0 -1
- package/dist/assets/dropdown-menu.styles-Bzo6L3FH.js +0 -1
- package/dist/assets/fileMentionTouchSelection-CBzDuQxP.js +0 -3
- package/dist/assets/insertionBoundaries-DQrE5qG2.js +0 -1
- package/dist/assets/main-D2BzpnUt.css +0 -1
- package/dist/assets/main-DYISNvWY.js +0 -169
- package/dist/assets/miniChat-DYIqdWi7.js +0 -2
- package/dist/assets/mobile-CwiCcmWt.js +0 -2
- package/dist/assets/multirun-C3snjTFs.js +0 -4
- package/dist/assets/persistence-D0y7226-.js +0 -3
- package/dist/assets/pl-BCf5uLlK.js +0 -15
- package/dist/assets/platform-CurqO28D.js +0 -6
- package/dist/assets/projectMeta-BkhYFMaM.js +0 -3
- package/dist/assets/renderElectronMiniChatApp-7iyh_419.js +0 -2
- package/dist/assets/renderMobileApp-y0_NeckR.js +0 -28
- package/dist/assets/runtime-switch-LvWDU-SL.js +0 -1
- package/dist/assets/runtimeConfig-12C5j02f.js +0 -2
- package/dist/assets/runtimeEndpointReset-DTY2ZXXb.js +0 -149
- package/dist/assets/sessionChangeSummary-CwPBIb3Z.js +0 -2
- package/dist/assets/src-lS1keDVV.css +0 -2
- package/dist/assets/useDesktopWindowControlsLayout-CR_DcY77.js +0 -1
- package/dist/assets/useMobileNavigationStore-DwupvLSA.js +0 -414
- package/dist/assets/useSessionAutoCleanup-DkGO_usj.js +0 -2
- package/dist/assets/vendor-opencode-client-C12gfjag.js +0 -12
- package/server/lib/opencode/snippets.js +0 -242
- package/server/lib/opencode/snippets.test.js +0 -97
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
|
|
2
|
+
import fs from 'node:fs';
|
|
3
|
+
import os from 'node:os';
|
|
4
|
+
import path from 'node:path';
|
|
5
|
+
import { readConfigFile, readConfigLayers, getConfigForPath, getJsonEntrySource, getJsonWriteTarget, writeConfig, writeConfigText } from './config-files.js';
|
|
6
|
+
|
|
7
|
+
let root;
|
|
8
|
+
let globalDir;
|
|
9
|
+
const put = (file, text) => {
|
|
10
|
+
fs.mkdirSync(path.dirname(file), { recursive: true });
|
|
11
|
+
fs.writeFileSync(file, text);
|
|
12
|
+
return file;
|
|
13
|
+
};
|
|
14
|
+
beforeEach(() => {
|
|
15
|
+
root = fs.mkdtempSync(path.join(os.tmpdir(), 'openchamber-config-files-'));
|
|
16
|
+
globalDir = path.join(root, 'xdg', 'opencode');
|
|
17
|
+
vi.stubEnv('XDG_CONFIG_HOME', path.dirname(globalDir));
|
|
18
|
+
vi.stubEnv('OPENCODE_CONFIG', '');
|
|
19
|
+
vi.stubEnv('OPENCODE_CONFIG_DIR', '');
|
|
20
|
+
});
|
|
21
|
+
afterEach(() => {
|
|
22
|
+
vi.restoreAllMocks();
|
|
23
|
+
vi.unstubAllEnvs();
|
|
24
|
+
fs.rmSync(root, { recursive: true, force: true });
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
describe('physical configuration layers', () => {
|
|
28
|
+
it('resolves an explicit global directory at call time', () => {
|
|
29
|
+
const customDirectory = path.join(root, 'custom-directory');
|
|
30
|
+
put(path.join(customDirectory, 'opencode.jsonc'), '{"model":"custom-directory"}');
|
|
31
|
+
vi.stubEnv('OPENCODE_CONFIG_DIR', customDirectory);
|
|
32
|
+
expect(readConfigLayers().mergedConfig).toEqual({ model: 'custom-directory' });
|
|
33
|
+
expect(getJsonWriteTarget(readConfigLayers(), 'user').path).toBe(path.join(customDirectory, 'opencode.jsonc'));
|
|
34
|
+
});
|
|
35
|
+
it('merges both global documents and keeps each write target unmerged', () => {
|
|
36
|
+
const json = put(path.join(globalDir, 'opencode.json'), '{"model":"base","agent":{"base":{"model":"a"},"shared":{"model":"base","description":"kept"}}}');
|
|
37
|
+
const jsonc = put(path.join(globalDir, 'opencode.jsonc'), '{ // override\n "model":"override","agent":{"shared":{"model":"override"}},}');
|
|
38
|
+
put(path.join(globalDir, 'config.json'), '{"model":"legacy-not-loaded-by-v2"}');
|
|
39
|
+
const layers = readConfigLayers();
|
|
40
|
+
expect(layers.mergedConfig).toEqual({ model: 'override', agent: { base: { model: 'a' }, shared: { model: 'override', description: 'kept' } } });
|
|
41
|
+
expect(getJsonEntrySource(layers, 'agent', 'base').path).toBe(json);
|
|
42
|
+
expect(getJsonEntrySource(layers, 'agent', 'shared').path).toBe(jsonc);
|
|
43
|
+
expect(getConfigForPath(layers, jsonc)).toEqual({ model: 'override', agent: { shared: { model: 'override' } } });
|
|
44
|
+
expect(getJsonWriteTarget(layers, 'user').path).toBe(jsonc);
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
it('loads explicit config above global and below discovered project documents', () => {
|
|
48
|
+
put(path.join(globalDir, 'opencode.json'), '{"model":"global","global":true}');
|
|
49
|
+
const custom = put(path.join(root, 'custom.jsonc'), '{"model":"explicit","explicit":true}');
|
|
50
|
+
vi.stubEnv('OPENCODE_CONFIG', custom);
|
|
51
|
+
const workspace = path.join(root, 'workspace');
|
|
52
|
+
const nested = path.join(workspace, 'nested');
|
|
53
|
+
put(path.join(workspace, 'opencode.json'), '{"model":"parent","parent":true}');
|
|
54
|
+
put(path.join(nested, 'opencode.jsonc'), '{"model":"child"}');
|
|
55
|
+
put(path.join(workspace, '.opencode', 'opencode.json'), '{"model":"supplementary"}');
|
|
56
|
+
const layers = readConfigLayers(nested);
|
|
57
|
+
expect(layers.mergedConfig).toEqual({ model: 'supplementary', global: true, explicit: true, parent: true });
|
|
58
|
+
expect(getJsonWriteTarget(layers, 'user').path).toBe(custom);
|
|
59
|
+
expect(getJsonWriteTarget(layers, 'project').path).toBe(path.join(workspace, '.opencode', 'opencode.json'));
|
|
60
|
+
vi.stubEnv('OPENCODE_CONFIG', '');
|
|
61
|
+
expect(readConfigLayers().mergedConfig).toEqual({ model: 'global', global: true });
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
it.each(['opencode.json', 'opencode.jsonc'])('reads a single %s and treats missing, blank and comments-only documents explicitly as empty', (name) => {
|
|
65
|
+
expect(readConfigLayers().mergedConfig).toEqual({});
|
|
66
|
+
const file = put(path.join(globalDir, name), ' \n');
|
|
67
|
+
expect(readConfigLayers().mergedConfig).toEqual({});
|
|
68
|
+
put(file, '// empty config\n/* documented */');
|
|
69
|
+
expect(readConfigLayers().mergedConfig).toEqual({});
|
|
70
|
+
put(file, '{"model":"one"}');
|
|
71
|
+
expect(readConfigLayers().mergedConfig).toEqual({ model: 'one' });
|
|
72
|
+
expect(getJsonWriteTarget(readConfigLayers(), 'user').path).toBe(file);
|
|
73
|
+
});
|
|
74
|
+
|
|
75
|
+
it.each(['{"model":', '{"model":"x", broken}', '[]', 'null', 'plain text'])('rejects malformed/non-object content %s without changing it', (text) => {
|
|
76
|
+
const file = put(path.join(globalDir, 'opencode.jsonc'), text);
|
|
77
|
+
expect(() => readConfigLayers()).toThrow('Invalid JSONC');
|
|
78
|
+
expect(() => writeConfig({ model: 'new' }, file)).toThrow('Invalid JSONC');
|
|
79
|
+
expect(() => writeConfigText('{}', file)).toThrow('Invalid JSONC');
|
|
80
|
+
expect(fs.readFileSync(file, 'utf8')).toBe(text);
|
|
81
|
+
expect(fs.existsSync(`${file}.openchamber.backup`)).toBe(false);
|
|
82
|
+
});
|
|
83
|
+
|
|
84
|
+
it('propagates read failures instead of returning empty success', () => {
|
|
85
|
+
const original = fs.readFileSync;
|
|
86
|
+
vi.spyOn(fs, 'readFileSync').mockImplementation((file, ...args) => {
|
|
87
|
+
if (String(file) === path.join(globalDir, 'opencode.json')) throw Object.assign(new Error('denied'), { code: 'EACCES' });
|
|
88
|
+
return original(file, ...args);
|
|
89
|
+
});
|
|
90
|
+
expect(() => readConfigLayers()).toThrow('denied');
|
|
91
|
+
});
|
|
92
|
+
});
|
|
93
|
+
|
|
94
|
+
describe('structural JSONC writes', () => {
|
|
95
|
+
it.each(['absolute', 'relative'])('preserves a %s dotfiles symlink while updating its target, permissions and backup', (kind) => {
|
|
96
|
+
const original = '{ // dotfiles comment\n "model":"old"\n}';
|
|
97
|
+
const target = put(path.join(root, 'dotfiles', 'config.jsonc'), original);
|
|
98
|
+
fs.chmodSync(target, 0o664);
|
|
99
|
+
fs.mkdirSync(globalDir, { recursive: true });
|
|
100
|
+
const file = path.join(globalDir, 'opencode.jsonc');
|
|
101
|
+
const link = kind === 'relative' ? path.relative(globalDir, target) : target;
|
|
102
|
+
fs.symlinkSync(link, file);
|
|
103
|
+
|
|
104
|
+
writeConfig({ model: 'new' }, file);
|
|
105
|
+
expect(fs.lstatSync(file).isSymbolicLink()).toBe(true);
|
|
106
|
+
expect(fs.readlinkSync(file)).toBe(link);
|
|
107
|
+
expect(readConfigFile(target)).toEqual({ model: 'new' });
|
|
108
|
+
expect(fs.readFileSync(target, 'utf8')).toContain('// dotfiles comment');
|
|
109
|
+
expect(fs.statSync(target).mode & 0o777).toBe(0o664);
|
|
110
|
+
expect(fs.readFileSync(`${file}.openchamber.backup`, 'utf8')).toBe(original);
|
|
111
|
+
expect(fs.existsSync(`${target}.openchamber.backup`)).toBe(false);
|
|
112
|
+
|
|
113
|
+
const structured = fs.readFileSync(target, 'utf8');
|
|
114
|
+
writeConfigText('{"model":"raw"}', file);
|
|
115
|
+
expect(fs.readlinkSync(file)).toBe(link);
|
|
116
|
+
expect(readConfigFile(target)).toEqual({ model: 'raw' });
|
|
117
|
+
expect(fs.statSync(target).mode & 0o777).toBe(0o664);
|
|
118
|
+
expect(fs.readFileSync(`${file}.openchamber.backup`, 'utf8')).toBe(structured);
|
|
119
|
+
});
|
|
120
|
+
|
|
121
|
+
it.each(['writeFileSync', 'chmodSync', 'copyFileSync', 'renameSync'])('preserves a symlink and its original target when %s fails', (method) => {
|
|
122
|
+
const original = '{ // retained\n "model":"old"\n}';
|
|
123
|
+
const target = put(path.join(root, 'dotfiles', 'config.jsonc'), original);
|
|
124
|
+
fs.chmodSync(target, 0o640);
|
|
125
|
+
fs.mkdirSync(globalDir, { recursive: true });
|
|
126
|
+
const file = path.join(globalDir, 'opencode.jsonc');
|
|
127
|
+
const link = path.relative(globalDir, target);
|
|
128
|
+
fs.symlinkSync(link, file);
|
|
129
|
+
vi.spyOn(fs, method).mockImplementation(() => { throw new Error('simulated IO failure'); });
|
|
130
|
+
expect(() => writeConfig({ model: 'new' }, file)).toThrow('simulated IO failure');
|
|
131
|
+
expect(fs.readlinkSync(file)).toBe(link);
|
|
132
|
+
expect(fs.readFileSync(target, 'utf8')).toBe(original);
|
|
133
|
+
expect(fs.statSync(target).mode & 0o777).toBe(0o640);
|
|
134
|
+
for (const dir of [globalDir, path.dirname(target)]) {
|
|
135
|
+
expect(fs.readdirSync(dir).some((name) => name.endsWith('.tmp'))).toBe(false);
|
|
136
|
+
}
|
|
137
|
+
});
|
|
138
|
+
|
|
139
|
+
it.each(['structured', 'raw'])('rejects a dangling symlink during a %s write without replacing it', (kind) => {
|
|
140
|
+
fs.mkdirSync(globalDir, { recursive: true });
|
|
141
|
+
const file = path.join(globalDir, 'opencode.jsonc');
|
|
142
|
+
const link = '../../dotfiles/missing.jsonc';
|
|
143
|
+
fs.symlinkSync(link, file);
|
|
144
|
+
const write = () => kind === 'structured' ? writeConfig({ model: 'new' }, file) : writeConfigText('{}', file);
|
|
145
|
+
expect(write).toThrow(expect.objectContaining({ code: 'ENOENT' }));
|
|
146
|
+
expect(fs.readlinkSync(file)).toBe(link);
|
|
147
|
+
expect(fs.existsSync(path.resolve(globalDir, link))).toBe(false);
|
|
148
|
+
expect(fs.readdirSync(globalDir)).toEqual(['opencode.jsonc']);
|
|
149
|
+
});
|
|
150
|
+
|
|
151
|
+
it('edits nested values, adds fields and removes fields without losing surrounding comments or unrelated bytes', () => {
|
|
152
|
+
const original = '\uFEFF{\r\n\t// model comment\r\n\t"model": "old",\r\n\t"agent": {"review": {/* owned */ "model":"old", "remove":true, /* trailing */}},\r\n\t// unrelated field\r\n\t"unrelated" : [ 1, 2 ], // leave alone\r\n}\r\n';
|
|
153
|
+
const file = put(path.join(globalDir, 'opencode.jsonc'), original);
|
|
154
|
+
const config = readConfigFile(file);
|
|
155
|
+
config.model = 'new';
|
|
156
|
+
config.agent.review.model = 'new';
|
|
157
|
+
delete config.agent.review.remove;
|
|
158
|
+
config.agent.review.description = 'added';
|
|
159
|
+
writeConfig(config, file);
|
|
160
|
+
const saved = fs.readFileSync(file, 'utf8');
|
|
161
|
+
expect(readConfigFile(file)).toEqual(config);
|
|
162
|
+
for (const comment of ['// model comment', '/* owned */', '/* trailing */', '// unrelated field', '// leave alone']) expect(saved).toContain(comment);
|
|
163
|
+
expect(saved).toContain('\t"unrelated" : [ 1, 2 ], // leave alone\r\n');
|
|
164
|
+
expect(saved.startsWith('\uFEFF')).toBe(true);
|
|
165
|
+
expect(fs.readFileSync(`${file}.openchamber.backup`, 'utf8')).toBe(original);
|
|
166
|
+
writeConfig(config, file);
|
|
167
|
+
expect(fs.readFileSync(file, 'utf8')).toBe(saved);
|
|
168
|
+
expect(fs.readFileSync(`${file}.openchamber.backup`, 'utf8')).toBe(original);
|
|
169
|
+
});
|
|
170
|
+
|
|
171
|
+
it.each([
|
|
172
|
+
'{/* before */ "only":1, /* after , */}',
|
|
173
|
+
'{"keep":2, /* before */ "only":1 /* after */}',
|
|
174
|
+
'{/* before */ "only":1, /* after */ "keep":2}',
|
|
175
|
+
])('removes a property and its comma from %s', (text) => {
|
|
176
|
+
const file = put(path.join(globalDir, 'opencode.jsonc'), text);
|
|
177
|
+
const desired = readConfigFile(file);
|
|
178
|
+
delete desired.only;
|
|
179
|
+
writeConfig(desired, file);
|
|
180
|
+
expect(readConfigFile(file)).toEqual(desired);
|
|
181
|
+
expect(fs.readFileSync(file, 'utf8')).toContain('/* before */');
|
|
182
|
+
expect(fs.readFileSync(file, 'utf8')).toContain('/* after');
|
|
183
|
+
});
|
|
184
|
+
|
|
185
|
+
it.each(['', '// notes without newline', '{"old":1}'])('supports new/empty/comment-only/JSON files (%s)', (text) => {
|
|
186
|
+
const file = path.join(globalDir, 'opencode.json');
|
|
187
|
+
if (text) put(file, text);
|
|
188
|
+
writeConfig({ model: 'new', nested: { enabled: true } }, file);
|
|
189
|
+
expect(readConfigFile(file)).toEqual({ model: 'new', nested: { enabled: true } });
|
|
190
|
+
if (text.startsWith('//')) expect(fs.readFileSync(file, 'utf8')).toContain(text);
|
|
191
|
+
});
|
|
192
|
+
|
|
193
|
+
it.each(['writeFileSync', 'copyFileSync', 'renameSync'])('keeps original content and cleans temporary files when %s fails', (method) => {
|
|
194
|
+
const original = '{ // retained\n "model":"old"\n}';
|
|
195
|
+
const file = put(path.join(globalDir, 'opencode.jsonc'), original);
|
|
196
|
+
vi.spyOn(fs, method).mockImplementation(() => { throw new Error('simulated IO failure'); });
|
|
197
|
+
expect(() => writeConfig({ model: 'new' }, file)).toThrow('simulated IO failure');
|
|
198
|
+
expect(fs.readFileSync(file, 'utf8')).toBe(original);
|
|
199
|
+
expect(fs.readdirSync(globalDir).some((name) => name.endsWith('.tmp'))).toBe(false);
|
|
200
|
+
});
|
|
201
|
+
});
|
|
@@ -822,6 +822,23 @@ export const registerAuthAndAccessRoutes = (app, dependencies) => {
|
|
|
822
822
|
});
|
|
823
823
|
});
|
|
824
824
|
|
|
825
|
+
app.patch('/api/client-auth/clients/:id', express.json({ limit: '64kb' }), async (req, res, next) => {
|
|
826
|
+
await runWithClientManagementAuth(req, res, next, async (authContext) => {
|
|
827
|
+
if (authContext.type === 'client') {
|
|
828
|
+
const actingClient = await clientRecordFromAuthContext(authContext);
|
|
829
|
+
if (!canManageRemoteClients(actingClient)) {
|
|
830
|
+
const clientId = clientIdFromAuthContext(authContext);
|
|
831
|
+
if (!clientId || clientId !== req.params?.id) {
|
|
832
|
+
return res.status(403).json({ error: 'Client tokens can only rename themselves' });
|
|
833
|
+
}
|
|
834
|
+
}
|
|
835
|
+
}
|
|
836
|
+
const client = await remoteClientAuthRuntime.renameClient(req.params?.id, req.body?.label);
|
|
837
|
+
if (!client) return res.status(404).json({ error: 'Client not found' });
|
|
838
|
+
res.json({ client });
|
|
839
|
+
});
|
|
840
|
+
});
|
|
841
|
+
|
|
825
842
|
app.delete('/api/client-auth/clients/:id', async (req, res, next) => {
|
|
826
843
|
await runWithClientManagementAuth(req, res, next, async (authContext) => {
|
|
827
844
|
if (authContext.type === 'client') {
|
|
@@ -1179,7 +1196,6 @@ export const registerCommonRequestMiddleware = (app, dependencies) => {
|
|
|
1179
1196
|
req.path.startsWith('/api/config/commands') ||
|
|
1180
1197
|
req.path.startsWith('/api/config/global') ||
|
|
1181
1198
|
req.path.startsWith('/api/config/mcp') ||
|
|
1182
|
-
req.path.startsWith('/api/config/snippets') ||
|
|
1183
1199
|
req.path.startsWith('/api/config/settings') ||
|
|
1184
1200
|
req.path.startsWith('/api/config/skills') ||
|
|
1185
1201
|
req.path.startsWith('/api/config/plugins') ||
|
|
@@ -51,6 +51,12 @@ const createClientAuthDependencies = (options = {}) => {
|
|
|
51
51
|
clients.push(client);
|
|
52
52
|
return { client, token: 'oc_client_secret' };
|
|
53
53
|
},
|
|
54
|
+
renameClient: vi.fn(async (id, label) => {
|
|
55
|
+
const client = clients.find((entry) => entry.id === id);
|
|
56
|
+
if (!client) return null;
|
|
57
|
+
client.label = label.trim();
|
|
58
|
+
return client;
|
|
59
|
+
}),
|
|
54
60
|
revokeClient: async (id) => {
|
|
55
61
|
const client = clients.find((entry) => entry.id === id);
|
|
56
62
|
if (!client) return { revoked: false };
|
|
@@ -310,21 +316,6 @@ describe('core-routes', () => {
|
|
|
310
316
|
expect(dependencies.gracefulShutdown).not.toHaveBeenCalled();
|
|
311
317
|
});
|
|
312
318
|
|
|
313
|
-
it('should parse JSON bodies for snippet config routes', async () => {
|
|
314
|
-
const app = express();
|
|
315
|
-
registerCommonRequestMiddleware(app, { express });
|
|
316
|
-
app.post('/api/config/snippets/example', (req, res) => {
|
|
317
|
-
res.json({ body: req.body });
|
|
318
|
-
});
|
|
319
|
-
|
|
320
|
-
const response = await request(app)
|
|
321
|
-
.post('/api/config/snippets/example')
|
|
322
|
-
.send({ content: 'Snippet body' })
|
|
323
|
-
.expect(200);
|
|
324
|
-
|
|
325
|
-
expect(response.body).toEqual({ body: { content: 'Snippet body' } });
|
|
326
|
-
});
|
|
327
|
-
|
|
328
319
|
// Global raw config saves send { content: "<jsonc string>" }. Without this
|
|
329
320
|
// prefix in the JSON middleware allowlist, PUT arrives with an empty body and
|
|
330
321
|
// the handler rejects with "Configuration content must be a string".
|
|
@@ -1349,6 +1340,43 @@ describe('core-routes', () => {
|
|
|
1349
1340
|
describe('client auth routes', () => {
|
|
1350
1341
|
const createDependencies = createClientAuthDependencies;
|
|
1351
1342
|
|
|
1343
|
+
it.each(['session', 'desktop-local', 'desktop', 'mobile'])('scopes device renaming for %s', async (kind) => {
|
|
1344
|
+
const app = express();
|
|
1345
|
+
let authContext = { type: 'session' };
|
|
1346
|
+
const dependencies = createDependencies({ resolveAuthContext: async () => authContext });
|
|
1347
|
+
registerAuthAndAccessRoutes(app, dependencies);
|
|
1348
|
+
const own = (await request(app).post('/api/client-auth/clients').send({ label: 'Own', clientKind: kind })).body.client;
|
|
1349
|
+
const other = (await request(app).post('/api/client-auth/clients').send({ label: 'Other' })).body.client;
|
|
1350
|
+
if (kind !== 'session') authContext = { type: 'client', clientId: own.id, client: own };
|
|
1351
|
+
|
|
1352
|
+
await request(app).patch(`/api/client-auth/clients/${own.id}`).send({ label: 'Renamed own' }).expect(200);
|
|
1353
|
+
dependencies.remoteClientAuthRuntime.renameClient.mockClear();
|
|
1354
|
+
const response = await request(app).patch(`/api/client-auth/clients/${other.id}`).send({ label: 'Renamed other', clientKind: 'desktop-local' });
|
|
1355
|
+
expect(response.status).toBe(kind === 'mobile' ? 403 : 200);
|
|
1356
|
+
if (kind === 'mobile') {
|
|
1357
|
+
expect(dependencies.remoteClientAuthRuntime.renameClient).not.toHaveBeenCalled();
|
|
1358
|
+
} else {
|
|
1359
|
+
expect(response.body.client).toEqual({ ...other, label: 'Renamed other' });
|
|
1360
|
+
expect(dependencies.remoteClientAuthRuntime.renameClient).toHaveBeenCalledWith(other.id, 'Renamed other');
|
|
1361
|
+
await request(app).patch('/api/client-auth/clients/missing').send({ label: 'Name' }).expect(404);
|
|
1362
|
+
}
|
|
1363
|
+
});
|
|
1364
|
+
|
|
1365
|
+
it('requires authentication and propagates rename failures', async () => {
|
|
1366
|
+
const app = express();
|
|
1367
|
+
const dependencies = createDependencies({ resolveAuthContext: async () => null });
|
|
1368
|
+
dependencies.uiAuthController.requireSessionAuth = (_req, res) => res.status(401).json({ error: 'Unauthorized' });
|
|
1369
|
+
registerAuthAndAccessRoutes(app, dependencies);
|
|
1370
|
+
await request(app).patch('/api/client-auth/clients/other').send({ label: 'Name' }).expect(401);
|
|
1371
|
+
expect(dependencies.remoteClientAuthRuntime.renameClient).not.toHaveBeenCalled();
|
|
1372
|
+
|
|
1373
|
+
dependencies.uiAuthController.resolveAuthContext.mockResolvedValue({ type: 'session' });
|
|
1374
|
+
dependencies.remoteClientAuthRuntime.renameClient.mockRejectedValue(Object.assign(new Error('Invalid label'), { status: 400 }));
|
|
1375
|
+
await request(app).patch('/api/client-auth/clients/other').send({ label: '' }).expect(400);
|
|
1376
|
+
dependencies.remoteClientAuthRuntime.renameClient.mockRejectedValue(new Error('Write failed'));
|
|
1377
|
+
await request(app).patch('/api/client-auth/clients/other').send({ label: 'Name' }).expect(500);
|
|
1378
|
+
});
|
|
1379
|
+
|
|
1352
1380
|
it('creates, lists, and revokes remote client tokens', async () => {
|
|
1353
1381
|
const app = express();
|
|
1354
1382
|
const dependencies = createDependencies();
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export function isSensitiveCredentialResponse(method: string, requestPath: string): boolean;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/** Credential list/create replies contain raw keys in v2. Keep them host-only. */
|
|
2
|
+
export function isSensitiveCredentialResponse(method, requestPath) {
|
|
3
|
+
let pathname;
|
|
4
|
+
try {
|
|
5
|
+
pathname = decodeURIComponent(new URL(requestPath, 'http://openchamber.invalid').pathname).replace(/\/+$/, '').toLowerCase();
|
|
6
|
+
} catch {
|
|
7
|
+
return true;
|
|
8
|
+
}
|
|
9
|
+
const root = pathname === '/credential' || pathname === '/api/credential';
|
|
10
|
+
return root && ['GET', 'HEAD', 'POST'].includes(String(method).toUpperCase());
|
|
11
|
+
}
|
|
@@ -233,6 +233,9 @@ export async function ensurePinnedOpenCode2Cli(input = {}) {
|
|
|
233
233
|
}
|
|
234
234
|
|
|
235
235
|
const installedPath = await install({ ...input, version: pin });
|
|
236
|
-
const version = readVersion(installedPath)
|
|
236
|
+
const version = readVersion(installedPath);
|
|
237
|
+
if (version !== pin) {
|
|
238
|
+
throw new Error(`Installed OpenCode version mismatch: expected ${pin}, got ${version || 'unknown'}`);
|
|
239
|
+
}
|
|
237
240
|
return { path: installedPath, version, source: 'installed', installed: true };
|
|
238
241
|
}
|
|
@@ -33,7 +33,10 @@ export const resolveOpenCodeEnvConfig = (options = {}) => {
|
|
|
33
33
|
warnInvalidHost(`must use http or https scheme (got ${JSON.stringify(url.protocol)})`);
|
|
34
34
|
return null;
|
|
35
35
|
}
|
|
36
|
-
|
|
36
|
+
// WHATWG URL removes explicit default ports; inspect the authority before normalization.
|
|
37
|
+
const authority = raw.match(/^https?:\/\/([^/?#]+)/i)?.[1] ?? '';
|
|
38
|
+
const explicitPort = authority.match(/:(\d+)$/)?.[1];
|
|
39
|
+
const port = parseInt(url.port || explicitPort || '', 10);
|
|
37
40
|
if (!Number.isFinite(port) || port <= 0) {
|
|
38
41
|
warnInvalidHost('must include an explicit port (example: http://hostname:4096)');
|
|
39
42
|
return null;
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { describe, expect, it, vi } from 'vitest';
|
|
2
|
+
import { resolveOpenCodeEnvConfig } from './env-config.js';
|
|
3
|
+
|
|
4
|
+
describe('explicit OpenCode host ports', () => {
|
|
5
|
+
it.each([
|
|
6
|
+
['http://example.test:80', 'http://example.test', 80],
|
|
7
|
+
['https://example.test:443/', 'https://example.test', 443],
|
|
8
|
+
['http://[::1]:80', 'http://[::1]', 80],
|
|
9
|
+
['https://[::1]:443', 'https://[::1]', 443],
|
|
10
|
+
['http://[::1]:4096', 'http://[::1]:4096', 4096],
|
|
11
|
+
['https://example.test:80', 'https://example.test:80', 80],
|
|
12
|
+
])('preserves the effective port of %s', (host, origin, port) => {
|
|
13
|
+
const config = resolveOpenCodeEnvConfig({ env: { OPENCODE_HOST: host, OPENCODE_PORT: '1234' } });
|
|
14
|
+
expect(config.configuredOpenCodeHost).toEqual({ origin, port });
|
|
15
|
+
expect(config.effectivePort).toBe(port);
|
|
16
|
+
expect(new URL('/api/info', config.configuredOpenCodeHost.origin).href).toBe(`${origin}/api/info`);
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
it.each(['http://example.test', 'https://example.test', 'http://[::1]', 'http://example.test:',
|
|
20
|
+
'ftp://example.test:80', 'http://example.test:80/path', 'http://example.test:80?q=1',
|
|
21
|
+
'http://example.test:80#hash', 'http://example.test:0', 'http://example.test:65536', 'invalid'])('retains rejection of %s', (host) => {
|
|
22
|
+
const logger = { warn: vi.fn() };
|
|
23
|
+
const config = resolveOpenCodeEnvConfig({ env: { OPENCODE_HOST: host, OPENCODE_PORT: '1234' }, logger });
|
|
24
|
+
expect(config.configuredOpenCodeHost).toBeNull();
|
|
25
|
+
expect(config.effectivePort).toBe(1234);
|
|
26
|
+
expect(logger.warn).toHaveBeenCalledOnce();
|
|
27
|
+
});
|
|
28
|
+
});
|
|
@@ -3,6 +3,7 @@ import os from 'node:os';
|
|
|
3
3
|
import path from 'node:path';
|
|
4
4
|
import { afterEach, describe, expect, it } from 'vitest';
|
|
5
5
|
import { createOpenCodeEnvRuntime } from './env-runtime.js';
|
|
6
|
+
import { PINNED_OPENCODE2_VERSION } from './opencode2-pin.js';
|
|
6
7
|
|
|
7
8
|
const originalOpencodeBinary = process.env.OPENCODE_BINARY;
|
|
8
9
|
const originalComSpec = process.env.ComSpec;
|
|
@@ -243,6 +244,22 @@ describe('OpenCode env runtime', () => {
|
|
|
243
244
|
expect(state.resolvedOpencodeBinarySource).toBe('path');
|
|
244
245
|
});
|
|
245
246
|
|
|
247
|
+
it('uses a newly installed global CLI on a fresh startup with an existing owned cache', async () => {
|
|
248
|
+
const dataDir = createTempDir('openchamber-restart-cache-');
|
|
249
|
+
const cached = path.join(dataDir, 'opencode-cli', '2.0.12', 'opencode');
|
|
250
|
+
const pathDir = createTempDir('openchamber-restart-global-');
|
|
251
|
+
const globalBinary = path.join(pathDir, 'opencode');
|
|
252
|
+
writeVersionBinary(cached, '2.0.12');
|
|
253
|
+
writeVersionBinary(globalBinary, '2.0.15');
|
|
254
|
+
process.env.OPENCHAMBER_DATA_DIR = dataDir;
|
|
255
|
+
process.env.PATH = pathDir;
|
|
256
|
+
delete process.env.OPENCODE_BINARY;
|
|
257
|
+
const { runtime, state } = createRuntime({});
|
|
258
|
+
|
|
259
|
+
await expect(runtime.ensurePinnedOpenCode2CliEnv()).resolves.toBe(globalBinary);
|
|
260
|
+
expect(state.resolvedOpencodeBinarySource).toBe('path');
|
|
261
|
+
});
|
|
262
|
+
|
|
246
263
|
it('keeps explicit OpenCode binary ahead of bundled CLI', () => {
|
|
247
264
|
const bundledDir = createTempDir('openchamber-bundled-opencode-');
|
|
248
265
|
const bundledBinary = path.join(bundledDir, process.platform === 'win32' ? 'opencode.exe' : 'opencode');
|
|
@@ -289,7 +306,7 @@ describe('OpenCode env runtime', () => {
|
|
|
289
306
|
|
|
290
307
|
it('discovers a previously installed pin from the OpenChamber data dir', () => {
|
|
291
308
|
const dataDir = createTempDir('openchamber-installed-cli-');
|
|
292
|
-
const installedDir = path.join(dataDir, 'opencode-cli',
|
|
309
|
+
const installedDir = path.join(dataDir, 'opencode-cli', PINNED_OPENCODE2_VERSION);
|
|
293
310
|
const installedBinary = path.join(installedDir, process.platform === 'win32' ? 'opencode.exe' : 'opencode');
|
|
294
311
|
fs.mkdirSync(installedDir, { recursive: true });
|
|
295
312
|
fs.writeFileSync(installedBinary, '#!/bin/sh\nexit 0\n');
|
|
@@ -5,6 +5,8 @@ import { registerSessionGoalRoutes } from '../session-goal/routes.js';
|
|
|
5
5
|
import { registerSessionMetadataRoutes } from '../session-metadata/routes.js';
|
|
6
6
|
import { registerGitHubRoutes } from '../github/routes.js';
|
|
7
7
|
import { registerGitRoutes } from '../git/routes.js';
|
|
8
|
+
import { makeOpenCodeV2Client } from './v2-client.js';
|
|
9
|
+
import { releaseDeletedWorktreeLocation } from './location-release.js';
|
|
8
10
|
import { registerMagicPromptRoutes } from '../magic-prompts/routes.js';
|
|
9
11
|
import { registerSessionFoldersRoutes } from '../session-folders/routes.js';
|
|
10
12
|
import { registerPermissionAutoAcceptRoutes } from '../permission-auto-accept/runtime.js';
|
|
@@ -31,7 +33,6 @@ import { getProviderSources, removeProviderConfig } from './providers.js';
|
|
|
31
33
|
import { getAgentSources, getAgentConfig, listDisabledAgentOverrides, createAgent, updateAgent, deleteAgent } from './agents.js';
|
|
32
34
|
import { getCommandSources, createCommand, updateCommand, deleteCommand } from './commands.js';
|
|
33
35
|
import { listMcpConfigs, getMcpConfig, createMcpConfig, updateMcpConfig, deleteMcpConfig } from './mcp.js';
|
|
34
|
-
import { listSnippets, getSnippet, createSnippet, updateSnippet, deleteSnippet, expandSnippets } from './snippets.js';
|
|
35
36
|
import {
|
|
36
37
|
listPluginEntries,
|
|
37
38
|
getPluginEntry,
|
|
@@ -359,12 +360,6 @@ export const createFeatureRoutesRuntime = (dependencies) => {
|
|
|
359
360
|
createMcpConfig,
|
|
360
361
|
updateMcpConfig,
|
|
361
362
|
deleteMcpConfig,
|
|
362
|
-
listSnippets,
|
|
363
|
-
getSnippet,
|
|
364
|
-
createSnippet,
|
|
365
|
-
updateSnippet,
|
|
366
|
-
deleteSnippet,
|
|
367
|
-
expandSnippets,
|
|
368
363
|
});
|
|
369
364
|
|
|
370
365
|
registerPluginRoutes(app, {
|
|
@@ -492,6 +487,13 @@ export const createFeatureRoutesRuntime = (dependencies) => {
|
|
|
492
487
|
registerGitRoutes(app, {
|
|
493
488
|
messageQueueService,
|
|
494
489
|
broadcastWorktreeTopologyChanged,
|
|
490
|
+
releaseWorktreeLocation: (directory) => releaseDeletedWorktreeLocation({
|
|
491
|
+
directory,
|
|
492
|
+
getClient: () => makeOpenCodeV2Client({
|
|
493
|
+
baseUrl: buildOpenCodeUrl('/', '').replace(/\/$/, ''),
|
|
494
|
+
authHeaders: getOpenCodeAuthHeaders(),
|
|
495
|
+
}),
|
|
496
|
+
}),
|
|
495
497
|
});
|
|
496
498
|
registerMagicPromptRoutes(app, {
|
|
497
499
|
fsPromises,
|
|
@@ -35,9 +35,9 @@ export const createHmrStateRuntime = (dependencies) => {
|
|
|
35
35
|
if (typeof hmrState.userProvidedOpenCodePassword !== 'undefined') {
|
|
36
36
|
return;
|
|
37
37
|
}
|
|
38
|
-
const initialPassword =
|
|
39
|
-
|
|
40
|
-
|
|
38
|
+
const initialPassword = processLike.env.OPENCODE_PASSWORD?.trim()
|
|
39
|
+
|| processLike.env.OPENCODE_SERVER_PASSWORD?.trim()
|
|
40
|
+
|| '';
|
|
41
41
|
hmrState.userProvidedOpenCodePassword = initialPassword || null;
|
|
42
42
|
};
|
|
43
43
|
|
|
@@ -51,7 +51,7 @@ export const createHmrStateRuntime = (dependencies) => {
|
|
|
51
51
|
openCodeAuthPassword:
|
|
52
52
|
typeof hmrState.openCodeAuthPassword === 'string' && hmrState.openCodeAuthPassword.length > 0
|
|
53
53
|
? hmrState.openCodeAuthPassword
|
|
54
|
-
: userProvidedOpenCodePassword,
|
|
54
|
+
: hmrState.openCodeAuthSource === 'shared-service' ? null : userProvidedOpenCodePassword,
|
|
55
55
|
openCodeAuthSource:
|
|
56
56
|
typeof hmrState.openCodeAuthSource === 'string' && hmrState.openCodeAuthSource.length > 0
|
|
57
57
|
? hmrState.openCodeAuthSource
|
|
@@ -29,8 +29,6 @@ const OPENCODE_CHILD_SIGTERM_GRACE_MS = 2500;
|
|
|
29
29
|
const OPENCODE_CHILD_SIGKILL_WAIT_MS = 1000;
|
|
30
30
|
// Last-used directory plus recently opened projects — deeper tails are unlikely
|
|
31
31
|
// to be the user's first click and just add background work.
|
|
32
|
-
const WARMUP_DIRECTORY_LIMIT = 4;
|
|
33
|
-
const WARMUP_REQUEST_TIMEOUT_MS = 30000;
|
|
34
32
|
|
|
35
33
|
export const createOpenCodeLifecycleRuntime = (deps) => {
|
|
36
34
|
const {
|
|
@@ -57,7 +55,6 @@ export const createOpenCodeLifecycleRuntime = (deps) => {
|
|
|
57
55
|
getManagedOpenCodeShellEnvSnapshot,
|
|
58
56
|
managedCapabilitiesRuntime = null,
|
|
59
57
|
getActiveSessionCount = () => 0,
|
|
60
|
-
getWarmupDirectories = async () => [],
|
|
61
58
|
// Official background service (shared-service.js). null keeps the private
|
|
62
59
|
// managed `opencode serve` path.
|
|
63
60
|
sharedService = null,
|
|
@@ -796,6 +793,7 @@ export const createOpenCodeLifecycleRuntime = (deps) => {
|
|
|
796
793
|
...shellEnv,
|
|
797
794
|
...process.env,
|
|
798
795
|
PATH: envPath,
|
|
796
|
+
OPENCODE_PASSWORD: openCodePassword,
|
|
799
797
|
OPENCODE_SERVER_PASSWORD: openCodePassword,
|
|
800
798
|
};
|
|
801
799
|
const managedEnv = managedCapabilitiesRuntime
|
|
@@ -1253,11 +1251,6 @@ export const createOpenCodeLifecycleRuntime = (deps) => {
|
|
|
1253
1251
|
await waitForOpenCodePort();
|
|
1254
1252
|
try {
|
|
1255
1253
|
await waitForOpenCodeReady();
|
|
1256
|
-
// Warm only after readiness admits; a failed gate must not kick off
|
|
1257
|
-
// directory-scoped traffic against an unready upstream.
|
|
1258
|
-
if (state.isOpenCodeReady) {
|
|
1259
|
-
void warmOpenCodeDirectories();
|
|
1260
|
-
}
|
|
1261
1254
|
} catch (error) {
|
|
1262
1255
|
console.error(`OpenCode readiness check failed: ${error.message}`);
|
|
1263
1256
|
}
|
|
@@ -1268,47 +1261,6 @@ export const createOpenCodeLifecycleRuntime = (deps) => {
|
|
|
1268
1261
|
}
|
|
1269
1262
|
};
|
|
1270
1263
|
|
|
1271
|
-
// OpenCode initializes each project directory lazily on its first
|
|
1272
|
-
// directory-scoped request, and that initialization takes seconds on large
|
|
1273
|
-
// session stores. Without warming, the user's first session open pays it
|
|
1274
|
-
// interactively. Warm the most recently used directories right after
|
|
1275
|
-
// readiness so the work overlaps UI startup instead. Sequential and
|
|
1276
|
-
// best-effort: a failed or slow directory never blocks the others for long,
|
|
1277
|
-
// and a restart invalidates the pass via the port/readiness guard.
|
|
1278
|
-
const warmOpenCodeDirectories = async () => {
|
|
1279
|
-
let directories = [];
|
|
1280
|
-
try {
|
|
1281
|
-
directories = await getWarmupDirectories();
|
|
1282
|
-
} catch {
|
|
1283
|
-
return;
|
|
1284
|
-
}
|
|
1285
|
-
if (!Array.isArray(directories) || directories.length === 0) return;
|
|
1286
|
-
|
|
1287
|
-
const warmedPort = state.openCodePort;
|
|
1288
|
-
for (const directory of directories.slice(0, WARMUP_DIRECTORY_LIMIT)) {
|
|
1289
|
-
if (typeof directory !== 'string' || !directory) continue;
|
|
1290
|
-
if (!state.isOpenCodeReady || state.openCodePort !== warmedPort) return;
|
|
1291
|
-
let timeout = null;
|
|
1292
|
-
try {
|
|
1293
|
-
const controller = new AbortController();
|
|
1294
|
-
timeout = setTimeout(() => controller.abort(), WARMUP_REQUEST_TIMEOUT_MS);
|
|
1295
|
-
// Warming a directory is the point, not the answer: any directory-scoped
|
|
1296
|
-
// read makes OpenCode initialise it. `/api/session` is the cheapest one
|
|
1297
|
-
// that takes a directory.
|
|
1298
|
-
const url = `${buildOpenCodeUrl('/api/session', '')}?directory=${encodeURIComponent(directory)}&limit=1`;
|
|
1299
|
-
await fetch(url, {
|
|
1300
|
-
method: 'GET',
|
|
1301
|
-
headers: { Accept: 'application/json', ...getOpenCodeAuthHeaders() },
|
|
1302
|
-
signal: controller.signal,
|
|
1303
|
-
});
|
|
1304
|
-
} catch {
|
|
1305
|
-
// Best-effort — the directory stays lazy and the UI's own request warms it.
|
|
1306
|
-
} finally {
|
|
1307
|
-
if (timeout) clearTimeout(timeout);
|
|
1308
|
-
}
|
|
1309
|
-
}
|
|
1310
|
-
};
|
|
1311
|
-
|
|
1312
1264
|
const bootstrapOpenCodeAtStartup = () => {
|
|
1313
1265
|
if (!bootstrapOpenCodePromise) {
|
|
1314
1266
|
bootstrapOpenCodePromise = runBootstrapOpenCodeAtStartup().finally(() => {
|