@openchamber/web 1.23.0 → 1.23.2
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/dist/assets/{CodeMirrorCommentWidgets-DbcnxAfY.js → CodeMirrorCommentWidgets-DdNGwbBw.js} +1 -1
- package/dist/assets/DiffView-GYriC0Wk.js +4 -0
- package/dist/assets/{DirtyBranchSwitchDialog-DE2sKIYv.js → DirtyBranchSwitchDialog-Bv0C99hc.js} +1 -1
- package/dist/assets/FilesView-2Lin13wx.js +13 -0
- package/dist/assets/{GitView-CKgUkb5Z.js → GitView-9wKba3UO.js} +4 -4
- package/dist/assets/{JsonTreeView-Bce2ettZ.js → JsonTreeView-Chzx5Y6N.js} +1 -1
- package/dist/assets/{LinearIssuesView-BZVWM2zw.js → LinearIssuesView-DXS9QJiR.js} +1 -1
- package/dist/assets/{MarkdownImageGallery-DdROVz29.js → MarkdownImageGallery-CugnrZ6f.js} +1 -1
- package/dist/assets/{MarkdownRendererImpl-CenrzmMN.js → MarkdownRendererImpl-CaMyct2Q.js} +4 -4
- package/dist/assets/{OnboardingScreen-DyqYG_NP.js → OnboardingScreen-hH9xcTjA.js} +1 -1
- package/dist/assets/{PatchDiff-CR3RVO5I.js → PatchDiff-DRgNYc9l.js} +1 -1
- package/dist/assets/{PierreDiffViewer-KihzO94X.js → PierreDiffViewer-ZT2CKuzJ.js} +1 -1
- package/dist/assets/PlanView-DiTBm2BD.js +5 -0
- package/dist/assets/SettingsView-CN8VeM99.js +28 -0
- package/dist/assets/{SettingsWindow-CV_hzB5v.js → SettingsWindow-DisOghhD.js} +1 -1
- package/dist/assets/{ToolOutputDialog-llKecK_Z.js → ToolOutputDialog-BqiKydxR.js} +6 -6
- package/dist/assets/{ToolPartDiffPreview-ZDMTdCGn.js → ToolPartDiffPreview-oWxWCu-4.js} +1 -1
- package/dist/assets/{VirtualizedFileDiff-ClvqQ4j0.js → VirtualizedFileDiff-CiyrAq_I.js} +4 -4
- package/dist/assets/WalkthroughView-CKTevaea.js +4 -0
- package/dist/assets/{computeVirtualFileMetrics-Nm5_wabb.js → computeVirtualFileMetrics-SUWoTyPe.js} +2 -2
- package/dist/assets/de-DQWC94VK.js +10 -0
- package/dist/assets/es-DixFUD3m.js +16 -0
- package/dist/assets/{fr-CP6jqIzw.js → fr-D6u8tvfA.js} +4 -4
- package/dist/assets/index-BvpFzhLs.js +40 -0
- package/dist/assets/{index-Du9sZhDb.js → index-C4jJ3Ur5.js} +1 -1
- package/dist/assets/index-n5p3SnES.css +1 -0
- package/dist/assets/{isDiffPlainText-EQERIius.js → isDiffPlainText-DfG0cZxr.js} +1 -1
- package/dist/assets/{isFilePlainText-BCoVpkQy.js → isFilePlainText-CyNivOCU.js} +1 -1
- package/dist/assets/ja-4u4pCorB.js +16 -0
- package/dist/assets/ko-C27-LW_b.js +16 -0
- package/dist/assets/{main-DPf32fO6.js → main-B8cGozKr.js} +2 -2
- package/dist/assets/main-tEA-fFPg.js +930 -0
- package/dist/assets/markdownCore-kyGrWGsn.js +5 -0
- package/dist/assets/{miniChat-CHqVTsgj.js → miniChat-Cay99IxR.js} +2 -2
- package/dist/assets/{mobile-BQmgHA57.js → mobile-Zfhix7nz.js} +2 -2
- package/dist/assets/patchFileDiff-CJ5AN9Ql.js +13 -0
- package/dist/assets/{pl-B215pG1Y.js → pl-FtCjsNdW.js} +4 -4
- package/dist/assets/pt-BR-CLosVawq.js +16 -0
- package/dist/assets/renderElectronMiniChatApp-CuHOGlF4.js +2 -0
- package/dist/assets/renderMobileApp-C4X_KUH8.js +25 -0
- package/dist/assets/runtimeEndpointReset-CMg-KUx3.js +41 -0
- package/dist/assets/scheduledTasksApi-CGFV4Pap.js +1 -0
- package/dist/assets/{shikiHighlight-BTObuQCR.js → shikiHighlight-DdKWYWrV.js} +1 -1
- package/dist/assets/surface-B6n7wJtt.js +1 -0
- package/dist/assets/tr-D2j6wUez.js +7 -0
- package/dist/assets/uk-C6IzmwM_.js +16 -0
- package/dist/assets/{useAppFontEffects-theH_IJL.js → useAppFontEffects-DgCHy6Mr.js} +134 -136
- package/dist/assets/useGitComparison-BIaI0WZI.js +1 -0
- package/dist/assets/{useInlineCommentController-Bs3PgeA8.js → useInlineCommentController-2wcCtpM3.js} +2 -2
- package/dist/assets/{useRootScrollLock-hSYwnxZs.js → useRootScrollLock-CbWA03xR.js} +1 -1
- package/dist/assets/{vendor-base-ui-DdV8vhHn.js → vendor-base-ui-BY_5qla_.js} +1 -1
- package/dist/assets/{vendor-codemirror-language-data-Cxgr01md.js → vendor-codemirror-language-data-ES33GhKK.js} +2 -2
- package/dist/assets/{vendor-remixicon-react-Dil0zKKT.js → vendor-remixicon-react-BDmGmFCA.js} +1 -1
- package/dist/assets/{vendor-zod-BPAANqvH.js → vendor-zod-B6551dwG.js} +2 -2
- package/dist/assets/{web-components-CaS0ksnZ.js → web-components-CJZwV5BE.js} +1 -1
- package/dist/assets/zh-CN-Wl6tIDz1.js +16 -0
- package/dist/assets/zh-TW-hgphoWSN.js +16 -0
- package/dist/index.html +4 -4
- package/dist/mini-chat.html +4 -4
- package/dist/mobile.html +4 -4
- package/package.json +2 -2
- package/server/index.js +3 -13
- package/server/lib/agent-memory/runtime.js +7 -2
- package/server/lib/agent-memory/runtime.test.js +22 -0
- package/server/lib/event-stream/DOCUMENTATION.md +3 -0
- package/server/lib/event-stream/global-hub.js +29 -4
- package/server/lib/event-stream/global-hub.test.js +22 -0
- package/server/lib/event-stream/global-ws-bridge.js +15 -18
- package/server/lib/event-stream/protocol.js +21 -7
- package/server/lib/event-stream/runtime.js +9 -6
- package/server/lib/event-stream/runtime.test.js +60 -0
- package/server/lib/git/DOCUMENTATION.md +10 -1
- package/server/lib/git/routes.js +21 -8
- package/server/lib/git/routes.test.js +78 -0
- package/server/lib/git/service.js +159 -4
- package/server/lib/git/service.test.js +74 -0
- package/server/lib/github/DOCUMENTATION.md +5 -0
- package/server/lib/github/routes.js +2 -2
- package/server/lib/message-queue/DOCUMENTATION.md +7 -0
- package/server/lib/message-queue/runtime.js +13 -0
- package/server/lib/message-queue/runtime.test.js +31 -1
- package/server/lib/notifications/DOCUMENTATION.md +1 -1
- package/server/lib/notifications/emitter-runtime.js +4 -3
- package/server/lib/opencode/DOCUMENTATION.md +32 -4
- package/server/lib/opencode/env-runtime.js +5 -1
- package/server/lib/opencode/env-runtime.test.js +72 -0
- package/server/lib/opencode/feature-routes-runtime.js +15 -1
- package/server/lib/opencode/lifecycle.js +4 -3
- package/server/lib/opencode/lifecycle.test.js +29 -0
- package/server/lib/opencode/managed-plugin-config.js +1 -1
- package/server/lib/opencode/openchamber-routes.js +72 -14
- package/server/lib/opencode/openchamber-routes.test.js +71 -3
- package/server/lib/opencode/proxy.js +33 -0
- package/server/lib/opencode/settings-helpers.js +8 -0
- package/server/lib/opencode/settings-helpers.test.js +24 -2
- package/server/lib/opencode/settings-registry.json +6 -0
- package/server/lib/opencode/settings-runtime.js +36 -9
- package/server/lib/opencode/settings-runtime.test.js +158 -2
- package/server/lib/project-context/DOCUMENTATION.md +13 -3
- package/server/lib/project-context/runtime.js +8 -2
- package/server/lib/project-context/runtime.test.js +54 -0
- package/server/lib/projects/DOCUMENTATION.md +2 -1
- package/server/lib/projects/project-config.js +38 -9
- package/server/lib/projects/project-config.test.js +97 -0
- package/server/lib/projects/project-id.js +26 -0
- package/server/lib/relay/DOCUMENTATION.md +20 -0
- package/server/lib/relay/host-client.js +7 -0
- package/server/lib/relay/host-client.test.js +14 -0
- package/server/lib/scheduled-tasks/DOCUMENTATION.md +9 -1
- package/server/lib/scheduled-tasks/issue-2710-double-execution.test.js +28 -0
- package/server/lib/scheduled-tasks/runtime.js +12 -2
- package/server/lib/scheduled-tasks/runtime.test.js +53 -0
- package/server/lib/session-assist/DOCUMENTATION.md +131 -66
- package/server/lib/session-assist/context.js +127 -0
- package/server/lib/session-assist/context.test.js +132 -0
- package/server/lib/session-assist/prompt.js +54 -0
- package/server/lib/session-assist/runtime.js +111 -257
- package/server/lib/session-assist/runtime.test.js +203 -0
- package/server/lib/walkthrough/DOCUMENTATION.md +15 -5
- package/server/lib/walkthrough/pr-source.test.js +21 -0
- package/server/lib/walkthrough/pull-request.js +7 -4
- package/server/lib/walkthrough/pull-request.test.js +16 -0
- package/server/lib/walkthrough/routes.js +19 -0
- package/server/lib/walkthrough/routes.test.js +26 -0
- package/server/lib/walkthrough/sources.js +13 -2
- package/server/opencode-worktree-readiness.test.js +130 -0
- package/dist/assets/DiffView-Dp1tomqK.js +0 -4
- package/dist/assets/FilesView-C_of2nIT.js +0 -17
- package/dist/assets/PlanView-jcQAfr2A.js +0 -5
- package/dist/assets/SettingsView-Buvom5A2.js +0 -28
- package/dist/assets/WalkthroughView-BgpSnSlU.js +0 -4
- package/dist/assets/de-DTQDjaiv.js +0 -10
- package/dist/assets/es-SOCFd_r-.js +0 -16
- package/dist/assets/index-B68h5S5B.css +0 -1
- package/dist/assets/index-CRf2xk51.js +0 -39
- package/dist/assets/ja-BKfafwsD.js +0 -16
- package/dist/assets/ko-BA5xgCYp.js +0 -16
- package/dist/assets/main-BNiPEont.js +0 -930
- package/dist/assets/markdownCore-CQ7CAuuV.js +0 -5
- package/dist/assets/patchFileDiff-C4X_trug.js +0 -13
- package/dist/assets/pt-BR-Bo2pnlEa.js +0 -16
- package/dist/assets/renderElectronMiniChatApp-BUcHPOXW.js +0 -2
- package/dist/assets/renderMobileApp-BvTmuRE-.js +0 -25
- package/dist/assets/runtimeEndpointReset-C8GAA2kS.js +0 -17
- package/dist/assets/scheduledTasksApi-BAScWwt3.js +0 -1
- package/dist/assets/surface-BvRzS58U.js +0 -1
- package/dist/assets/tr-CUaxHc8X.js +0 -7
- package/dist/assets/uk-YTJgyqAZ.js +0 -16
- package/dist/assets/useGitComparison-B94I6kOI.js +0 -1
- package/dist/assets/zh-CN-CZ2BxZS6.js +0 -16
- package/dist/assets/zh-TW-BsUrPdXz.js +0 -16
- package/server/lib/mcp-reconnect/DOCUMENTATION.md +0 -55
- package/server/lib/mcp-reconnect/runtime.js +0 -122
- package/server/lib/mcp-reconnect/runtime.test.js +0 -140
|
@@ -34,8 +34,7 @@ This module provides OpenCode server integration utilities for the web server ru
|
|
|
34
34
|
- `packages/web/server/lib/opencode/startup-performance.js`: opt-in startup phase diagnostics with fixed labels and numeric metadata allowlists.
|
|
35
35
|
- `packages/web/server/lib/agent-tool/runtime.js`: managed OpenCode custom-tool materialization, environment injection, loopback authentication, and fixed CLI action dispatch.
|
|
36
36
|
- `packages/web/server/lib/system-prompt/runtime.js`: opt-in managed OpenCode system-prompt optimizer materialization and plugin injection.
|
|
37
|
-
- `packages/web/server/lib/
|
|
38
|
-
- `packages/web/server/lib/opencode/managed-plugin-config.js`: the one `OPENCODE_CONFIG_CONTENT` merge every managed plugin (agent tools, system prompt optimizer, MCP reconnect) appends itself through.
|
|
37
|
+
- `packages/web/server/lib/opencode/managed-plugin-config.js`: the one `OPENCODE_CONFIG_CONTENT` merge every managed plugin (agent tools, system prompt optimizer) appends itself through.
|
|
39
38
|
- `packages/web/server/lib/opencode/server-utils-runtime.js`: shared server runtime utilities for OpenCode proxy wiring, OpenCode port/readiness helpers, and snapshot fetchers.
|
|
40
39
|
- `packages/web/server/lib/opencode/openchamber-routes.js`: OpenChamber update and models metadata route registration.
|
|
41
40
|
- `packages/web/server/lib/opencode/pwa-manifest-routes.js`: PWA manifest route registration with recent-session shortcut resolution and short-lived caching.
|
|
@@ -132,8 +131,12 @@ The runtime maintains active-session count incrementally from idempotent activit
|
|
|
132
131
|
- `killProcessOnPort(port)`
|
|
133
132
|
|
|
134
133
|
Managed OpenCode launch also merges the environment returned by the agent-tool
|
|
135
|
-
runtime
|
|
136
|
-
|
|
134
|
+
runtime and the opt-in system prompt optimizer, each appending its `file://`
|
|
135
|
+
entry to the previous one's config. OpenChamber adds no automatic MCP reconnect
|
|
136
|
+
loop; recovery after a failed connection is manual for both local and remote
|
|
137
|
+
servers. Previously generated reconnect plugin files are inert because managed
|
|
138
|
+
launch no longer registers them. User-configured plugins remain user-owned.
|
|
139
|
+
PATH and `OPENCODE_SERVER_PASSWORD` remain lifecycle-owned and cannot
|
|
137
140
|
be replaced by injected values. External OpenCode processes receive no
|
|
138
141
|
OpenChamber tool injection. Managed launch env strips AppImage `ARGV0` before
|
|
139
142
|
spawn so zsh-backed OpenCode tools do not rewrite child argv[0] to the AppImage
|
|
@@ -156,6 +159,7 @@ Managed health failures are classified as `timeout`, `connection_refused`, `conn
|
|
|
156
159
|
## Public exports (env-runtime.js)
|
|
157
160
|
- `createOpenCodeEnvRuntime(dependencies)`: creates runtime that owns OpenCode CLI environment and binary discovery state.
|
|
158
161
|
- OpenCode CLI resolution order is persisted settings, environment overrides, bundled Desktop CLI when available, PATH, known install locations, then platform shell discovery.
|
|
162
|
+
- Automatic bundled resolution under `OPENCHAMBER_RUNTIME=desktop` stays in runtime state and is returned to the managed launch function, including on OpenCode restart. It does not populate `process.env.OPENCODE_BINARY`: AppImage updater relaunch inherits that environment and would mistake the previous bundle path for an explicit override. Explicit settings/env selections and non-desktop or non-bundled resolution retain their existing environment behavior. This prevents future inheritance; it does not reinterpret overrides already inherited from older releases.
|
|
159
163
|
- Returned API:
|
|
160
164
|
- `applyLoginShellEnvSnapshot()`
|
|
161
165
|
- `getLoginShellEnvSnapshot()`
|
|
@@ -385,6 +389,20 @@ within a ten-minute overall deadline.
|
|
|
385
389
|
- Foreground servers running under a systemd user unit queue installation in
|
|
386
390
|
a separate transient unit and restart the configured service afterwards.
|
|
387
391
|
`OPENCHAMBER_SYSTEMD_UNIT` overrides the default `openchamber.service`.
|
|
392
|
+
- On Windows the install-and-restart script is written to
|
|
393
|
+
`<data dir>/update-install.cmd` before the response and run with
|
|
394
|
+
`cmd.exe /c <file>`. A newline ends a `cmd.exe /c` command line, so the
|
|
395
|
+
same script passed as an argument ran nothing and exited 0; the batch
|
|
396
|
+
file keeps every line. The package-manager line is `call`ed because
|
|
397
|
+
npm, pnpm and yarn are `.cmd` shims that would otherwise end the script,
|
|
398
|
+
the pre-install pause is a loopback `ping` because `timeout` rejects a
|
|
399
|
+
detached child's stdin, and the file deletes itself on its last line
|
|
400
|
+
because the restart command carries the server's flags. If the file
|
|
401
|
+
cannot be written the route answers 500 and the server keeps running.
|
|
402
|
+
The listener is closed before the batch is spawned: on Windows the
|
|
403
|
+
detached child inherits the listening socket and would hold the port
|
|
404
|
+
for the whole batch, so the restart inside it failed with "port already
|
|
405
|
+
in use" and the update ended with no server.
|
|
388
406
|
- `GET /api/openchamber/models-metadata`
|
|
389
407
|
- `GET /api/zen/models`
|
|
390
408
|
|
|
@@ -422,6 +440,16 @@ within a ten-minute overall deadline.
|
|
|
422
440
|
- Generic `/api/*` forwarding with hop-by-hop header filtering
|
|
423
441
|
- Windows `/session` merge fallback path behavior
|
|
424
442
|
- OpenCode readiness gate for proxied `/api` requests
|
|
443
|
+
- Worktree checkout gate before directory-scoped upstream reads and writes
|
|
444
|
+
|
|
445
|
+
Git bootstrap must reach `git-ready` before OpenCode can cache a new worktree's
|
|
446
|
+
project identity or config. Setup scripts may still be running; the optional UI
|
|
447
|
+
setup wait remains separate. Failed or timed-out checkout returns 503 without
|
|
448
|
+
forwarding. The shared draft creator keeps the project directory selected until
|
|
449
|
+
creation returns, because preview paths have no bootstrap state.
|
|
450
|
+
|
|
451
|
+
This server gate covers web, Electron, hosted mobile, and Capacitor connections.
|
|
452
|
+
The VS Code extension owns its separate Git and proxy implementation.
|
|
425
453
|
|
|
426
454
|
## Public exports (watcher.js)
|
|
427
455
|
- `createOpenCodeWatcherRuntime(dependencies)`: creates global event watcher runtime backed by the shared upstream SSE reader.
|
|
@@ -1110,7 +1110,11 @@ export const createOpenCodeEnvRuntime = (deps) => {
|
|
|
1110
1110
|
return resolved;
|
|
1111
1111
|
}
|
|
1112
1112
|
|
|
1113
|
-
process.env.
|
|
1113
|
+
// AppImage updates inherit process.env. Keep automatic desktop bundle
|
|
1114
|
+
// selection local so the next app does not treat the old mount as an override.
|
|
1115
|
+
if (process.env.OPENCHAMBER_RUNTIME !== 'desktop' || state.resolvedOpencodeBinarySource !== 'bundled') {
|
|
1116
|
+
process.env.OPENCODE_BINARY = resolved;
|
|
1117
|
+
}
|
|
1114
1118
|
prependToPath(path.dirname(resolved));
|
|
1115
1119
|
ensureOpencodeShimRuntime(resolved);
|
|
1116
1120
|
state.resolvedOpencodeBinary = resolved;
|
|
@@ -14,6 +14,7 @@ const originalResourcesPath = process.resourcesPath;
|
|
|
14
14
|
const originalWslBinary = process.env.WSL_BINARY;
|
|
15
15
|
const originalOpenChamberWslBinary = process.env.OPENCHAMBER_WSL_BINARY;
|
|
16
16
|
const originalPlatform = process.platform;
|
|
17
|
+
const originalRuntime = process.env.OPENCHAMBER_RUNTIME;
|
|
17
18
|
const tempDirs = [];
|
|
18
19
|
const itIf = (condition) => condition ? it : it.skip;
|
|
19
20
|
|
|
@@ -30,6 +31,8 @@ const setPlatform = (platform) => {
|
|
|
30
31
|
};
|
|
31
32
|
|
|
32
33
|
afterEach(() => {
|
|
34
|
+
if (originalRuntime === undefined) delete process.env.OPENCHAMBER_RUNTIME;
|
|
35
|
+
else process.env.OPENCHAMBER_RUNTIME = originalRuntime;
|
|
33
36
|
Object.defineProperty(process, 'platform', {
|
|
34
37
|
value: originalPlatform,
|
|
35
38
|
});
|
|
@@ -117,7 +120,76 @@ const createRuntime = (settings, options = {}) => {
|
|
|
117
120
|
return { runtime, state };
|
|
118
121
|
};
|
|
119
122
|
|
|
123
|
+
const createBundledCli = () => {
|
|
124
|
+
const resourcesPath = createTempDir('openchamber-resources-');
|
|
125
|
+
const directory = path.join(resourcesPath, 'opencode-cli');
|
|
126
|
+
fs.mkdirSync(directory);
|
|
127
|
+
const binary = path.join(directory, process.platform === 'win32' ? 'opencode.exe' : 'opencode');
|
|
128
|
+
fs.writeFileSync(binary, '#!/bin/sh\nexit 0\n', { mode: 0o755 });
|
|
129
|
+
Object.defineProperty(process, 'resourcesPath', { configurable: true, value: resourcesPath });
|
|
130
|
+
return binary;
|
|
131
|
+
};
|
|
132
|
+
|
|
120
133
|
describe('OpenCode env runtime', () => {
|
|
134
|
+
it.each(['linux', 'darwin', 'win32'])('keeps automatic desktop bundled resolution local across relaunch on %s', (platform) => {
|
|
135
|
+
setPlatform(platform);
|
|
136
|
+
process.env.OPENCHAMBER_RUNTIME = 'desktop';
|
|
137
|
+
delete process.env.OPENCODE_BINARY;
|
|
138
|
+
delete process.env.OPENCHAMBER_BUNDLED_OPENCODE_CLI_DIR;
|
|
139
|
+
|
|
140
|
+
const oldBinary = createBundledCli();
|
|
141
|
+
const oldRuntime = createRuntime({});
|
|
142
|
+
expect(oldRuntime.runtime.ensureOpencodeCliEnv()).toBe(oldBinary);
|
|
143
|
+
expect(oldRuntime.runtime.ensureOpencodeCliEnv()).toBe(oldBinary);
|
|
144
|
+
expect(oldRuntime.state.resolvedOpencodeBinarySource).toBe('bundled');
|
|
145
|
+
expect(process.env.OPENCODE_BINARY).toBeUndefined();
|
|
146
|
+
expect(process.env.PATH.split(path.delimiter)[0]).toBe(path.dirname(oldBinary));
|
|
147
|
+
|
|
148
|
+
// The old binary remains executable and its directory is still in PATH.
|
|
149
|
+
const newBinary = createBundledCli();
|
|
150
|
+
const newRuntime = createRuntime({});
|
|
151
|
+
expect(newRuntime.runtime.ensureOpencodeCliEnv()).toBe(newBinary);
|
|
152
|
+
expect(newRuntime.state.resolvedOpencodeBinarySource).toBe('bundled');
|
|
153
|
+
expect(newRuntime.runtime.isBundledOpenCodeCliPath(newBinary)).toBe(true);
|
|
154
|
+
expect(process.env.OPENCODE_BINARY).toBeUndefined();
|
|
155
|
+
});
|
|
156
|
+
|
|
157
|
+
it.each(['web', 'ssh-remote'])('preserves automatic binary export outside desktop in %s', (runtimeName) => {
|
|
158
|
+
process.env.OPENCHAMBER_RUNTIME = runtimeName;
|
|
159
|
+
delete process.env.OPENCODE_BINARY;
|
|
160
|
+
delete process.env.OPENCHAMBER_BUNDLED_OPENCODE_CLI_DIR;
|
|
161
|
+
const binary = createBundledCli();
|
|
162
|
+
const { runtime } = createRuntime({});
|
|
163
|
+
expect(runtime.ensureOpencodeCliEnv()).toBe(binary);
|
|
164
|
+
expect(process.env.OPENCODE_BINARY).toBe(binary);
|
|
165
|
+
});
|
|
166
|
+
|
|
167
|
+
it.each(['env', 'settings'])('preserves explicit desktop %s selection even when it points at a bundled CLI', async (source) => {
|
|
168
|
+
process.env.OPENCHAMBER_RUNTIME = 'desktop';
|
|
169
|
+
delete process.env.OPENCODE_BINARY;
|
|
170
|
+
delete process.env.OPENCHAMBER_BUNDLED_OPENCODE_CLI_DIR;
|
|
171
|
+
const binary = createBundledCli();
|
|
172
|
+
if (source === 'env') process.env.OPENCODE_BINARY = binary;
|
|
173
|
+
const { runtime, state } = createRuntime(source === 'settings' ? { opencodeBinary: binary } : {});
|
|
174
|
+
await runtime.applyOpencodeBinaryFromSettings({ strict: true });
|
|
175
|
+
expect(runtime.ensureOpencodeCliEnv()).toBe(binary);
|
|
176
|
+
expect(state.resolvedOpencodeBinarySource).toBe(source);
|
|
177
|
+
expect(process.env.OPENCODE_BINARY).toBe(binary);
|
|
178
|
+
});
|
|
179
|
+
|
|
180
|
+
it('preserves automatic PATH binary export for desktop without a bundled CLI', () => {
|
|
181
|
+
process.env.OPENCHAMBER_RUNTIME = 'desktop';
|
|
182
|
+
delete process.env.OPENCODE_BINARY;
|
|
183
|
+
delete process.env.OPENCHAMBER_BUNDLED_OPENCODE_CLI_DIR;
|
|
184
|
+
const binary = createBundledCli();
|
|
185
|
+
Object.defineProperty(process, 'resourcesPath', { configurable: true, value: undefined });
|
|
186
|
+
process.env.PATH = path.dirname(binary);
|
|
187
|
+
const { runtime, state } = createRuntime({});
|
|
188
|
+
expect(runtime.ensureOpencodeCliEnv()).toBe(binary);
|
|
189
|
+
expect(state.resolvedOpencodeBinarySource).toBe('path');
|
|
190
|
+
expect(process.env.OPENCODE_BINARY).toBe(binary);
|
|
191
|
+
});
|
|
192
|
+
|
|
121
193
|
it('searches an explicit PATH without mutating the process environment', () => {
|
|
122
194
|
const defaultDir = createTempDir('openchamber-default-path-');
|
|
123
195
|
const explicitDir = createTempDir('openchamber-explicit-path-');
|
|
@@ -307,7 +307,21 @@ export const createFeatureRoutesRuntime = (dependencies) => {
|
|
|
307
307
|
registerSessionGoalRoutes(app);
|
|
308
308
|
registerGitHubRoutes(app);
|
|
309
309
|
registerLinearRoutes(app);
|
|
310
|
-
registerGitRoutes(app
|
|
310
|
+
registerGitRoutes(app, {
|
|
311
|
+
emitWorktreeChanged: ({ directories, at }) => {
|
|
312
|
+
const clients = getOpenChamberEventClients();
|
|
313
|
+
for (const client of clients) {
|
|
314
|
+
try {
|
|
315
|
+
writeSseEvent(client, {
|
|
316
|
+
type: 'openchamber:worktree-changed',
|
|
317
|
+
properties: { directories, at },
|
|
318
|
+
});
|
|
319
|
+
} catch {
|
|
320
|
+
clients.delete(client);
|
|
321
|
+
}
|
|
322
|
+
}
|
|
323
|
+
},
|
|
324
|
+
});
|
|
311
325
|
registerDevServerRoutes(app, { scanner: devServerScanner, getOwnPorts });
|
|
312
326
|
registerMagicPromptRoutes(app, {
|
|
313
327
|
fsPromises,
|
|
@@ -377,8 +377,8 @@ export const createOpenCodeLifecycleRuntime = (deps) => {
|
|
|
377
377
|
return parts.length > 0 ? parts.join('\n\n') : 'No stdout/stderr captured';
|
|
378
378
|
};
|
|
379
379
|
|
|
380
|
-
const createManagedOpenCodeServerProcess = async ({ hostname, port, timeout, cwd, env: processEnv, shellEnvKeysCount = 0 }) => {
|
|
381
|
-
let binary = (process.env.OPENCODE_BINARY || 'opencode').trim() || 'opencode';
|
|
380
|
+
const createManagedOpenCodeServerProcess = async ({ resolvedBinary, hostname, port, timeout, cwd, env: processEnv, shellEnvKeysCount = 0 }) => {
|
|
381
|
+
let binary = (resolvedBinary || process.env.OPENCODE_BINARY || 'opencode').trim() || 'opencode';
|
|
382
382
|
const sourceBinary = binary;
|
|
383
383
|
let args = ['serve', '--hostname', hostname, '--port', String(port)];
|
|
384
384
|
let launchWrapperType = null;
|
|
@@ -694,7 +694,7 @@ export const createOpenCodeLifecycleRuntime = (deps) => {
|
|
|
694
694
|
);
|
|
695
695
|
|
|
696
696
|
await applyOpencodeBinaryFromSettings({ strict: true });
|
|
697
|
-
ensureOpencodeCliEnv();
|
|
697
|
+
const resolvedBinary = ensureOpencodeCliEnv();
|
|
698
698
|
recordStartupPerformance('opencode.binary.ready', {
|
|
699
699
|
attempt,
|
|
700
700
|
durationMs: performance.now() - phaseStartedAt,
|
|
@@ -721,6 +721,7 @@ export const createOpenCodeLifecycleRuntime = (deps) => {
|
|
|
721
721
|
|
|
722
722
|
try {
|
|
723
723
|
const serverInstance = await createManagedOpenCodeServerProcess({
|
|
724
|
+
resolvedBinary,
|
|
724
725
|
hostname: env.ENV_CONFIGURED_OPENCODE_HOSTNAME,
|
|
725
726
|
port: spawnPort,
|
|
726
727
|
timeout: 30000,
|
|
@@ -126,6 +126,35 @@ const createRuntime = (overrides = {}, stateOverrides = {}, envOverrides = {}) =
|
|
|
126
126
|
};
|
|
127
127
|
|
|
128
128
|
describe('OpenCode lifecycle', () => {
|
|
129
|
+
it('uses the resolved binary directly on startup and managed restart without an env override', async () => {
|
|
130
|
+
delete process.env.OPENCODE_BINARY;
|
|
131
|
+
const binaries = ['/bundle one/opencode-cli/opencode', '/bundle two/opencode-cli/opencode'];
|
|
132
|
+
const ensureOpencodeCliEnv = vi.fn()
|
|
133
|
+
.mockReturnValueOnce(binaries[0])
|
|
134
|
+
.mockReturnValueOnce(binaries[1]);
|
|
135
|
+
spawnMock.mockImplementation(() => {
|
|
136
|
+
const child = createMockChild();
|
|
137
|
+
queueMicrotask(() => child.stdout.emit('data', 'opencode server listening on http://127.0.0.1:45678\n'));
|
|
138
|
+
return child;
|
|
139
|
+
});
|
|
140
|
+
globalThis.fetch = vi.fn(async () => ({ ok: false }));
|
|
141
|
+
const runtime = createRuntime({ ensureOpencodeCliEnv });
|
|
142
|
+
const firstServer = await runtime.startOpenCode();
|
|
143
|
+
runtime.testState.openCodeProcess = firstServer;
|
|
144
|
+
try {
|
|
145
|
+
await runtime.restartOpenCode();
|
|
146
|
+
expect(firstServer.signalCode).toBe('SIGTERM');
|
|
147
|
+
expect(spawnMock.mock.calls.map(([binary]) => binary)).toEqual(binaries);
|
|
148
|
+
expect(runtime.testState.lastOpenCodeLaunchDiagnostics.sourceBinary).toBe(binaries[1]);
|
|
149
|
+
expect(process.env.OPENCODE_BINARY).toBeUndefined();
|
|
150
|
+
for (const [, , options] of spawnMock.mock.calls) {
|
|
151
|
+
expect(options.env).not.toHaveProperty('OPENCODE_BINARY');
|
|
152
|
+
}
|
|
153
|
+
} finally {
|
|
154
|
+
await runtime.testState.openCodeProcess.close();
|
|
155
|
+
}
|
|
156
|
+
});
|
|
157
|
+
|
|
129
158
|
it('records an authoritative ready terminal event for external startup', async () => {
|
|
130
159
|
globalThis.fetch = vi.fn(async () => ({
|
|
131
160
|
ok: true,
|
|
@@ -8,7 +8,7 @@ const isJsonObject = (value) => value !== null && value !== undefined && Object.
|
|
|
8
8
|
*
|
|
9
9
|
* Existing entries are preserved; an earlier entry for the same URL is dropped
|
|
10
10
|
* so a restart never registers the same plugin twice. Every managed plugin
|
|
11
|
-
* (agent tools, system prompt optimizer
|
|
11
|
+
* (agent tools, system prompt optimizer) goes through this one
|
|
12
12
|
* merge so they compose in any order.
|
|
13
13
|
*
|
|
14
14
|
* @param {string | undefined} rawConfig the current `OPENCODE_CONFIG_CONTENT`, JSONC or unset
|
|
@@ -16,6 +16,43 @@ function quotePosixShell(value) {
|
|
|
16
16
|
return `'${String(value).replace(/'/g, "'\\''")}'`;
|
|
17
17
|
}
|
|
18
18
|
|
|
19
|
+
/**
|
|
20
|
+
* `echo` in batch treats `& | < > ( ) ^` as syntax and `%var%` as expansion,
|
|
21
|
+
* so a line of the log preamble is escaped before it becomes an `echo`.
|
|
22
|
+
*/
|
|
23
|
+
const escapeBatchEchoLine = (line) => {
|
|
24
|
+
if (!line) return 'echo.';
|
|
25
|
+
return `echo ${line.replace(/%/g, '%%').replace(/[&|<>()^]/g, '^$&')}`;
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* The Windows update runs as a batch file, one command per line, so the
|
|
30
|
+
* `if ... else` block and the multi-line log preamble keep their structure.
|
|
31
|
+
*/
|
|
32
|
+
const buildWindowsUpdateScript = ({ logPreamble, updateCmd, restartCmd }) => [
|
|
33
|
+
'@echo off',
|
|
34
|
+
...logPreamble.split('\n').map(escapeBatchEchoLine),
|
|
35
|
+
// `timeout` refuses redirected stdin, which is what a detached child has;
|
|
36
|
+
// a ping to loopback waits about two seconds without a console.
|
|
37
|
+
'ping -n 3 127.0.0.1 >nul',
|
|
38
|
+
// npm, pnpm and yarn are .cmd shims on Windows. Without `call`, a batch
|
|
39
|
+
// file hands control to them for good and the restart below never runs.
|
|
40
|
+
// Read from a file, cmd expands `%x%` and drops a lone `%`, so a `%` in a
|
|
41
|
+
// host or UI password would change the restart command. Doubling keeps it.
|
|
42
|
+
`call ${updateCmd.replace(/%/g, '%%')}`,
|
|
43
|
+
'if %ERRORLEVEL% EQU 0 (',
|
|
44
|
+
' echo Update successful, restarting OpenChamber...',
|
|
45
|
+
` ${restartCmd ? restartCmd.replace(/%/g, '%%') : 'echo Service manager will restart OpenChamber.'}`,
|
|
46
|
+
') else (',
|
|
47
|
+
' echo Update failed',
|
|
48
|
+
')',
|
|
49
|
+
// The restart command carries the server's own flags, `--ui-password`
|
|
50
|
+
// included, so the file does not outlive the run. Deleting the running
|
|
51
|
+
// batch file on its last line is safe: cmd has already read it.
|
|
52
|
+
'del "%~f0"',
|
|
53
|
+
'',
|
|
54
|
+
].join('\r\n');
|
|
55
|
+
|
|
19
56
|
export const registerOpenChamberRoutes = (app, dependencies) => {
|
|
20
57
|
const {
|
|
21
58
|
fs,
|
|
@@ -300,6 +337,26 @@ export const registerOpenChamberRoutes = (app, dependencies) => {
|
|
|
300
337
|
`logPath=${updateLogPath}`,
|
|
301
338
|
].join('\n');
|
|
302
339
|
|
|
340
|
+
const shell = isWindows ? (process.env.ComSpec || 'cmd.exe') : 'sh';
|
|
341
|
+
const shellFlag = isWindows ? '/c' : '-c';
|
|
342
|
+
// cmd.exe /c takes one command line: a newline inside it ends the
|
|
343
|
+
// command, so a multi-line script passed as the argument ran nothing
|
|
344
|
+
// and exited 0, and the server shut itself down believing the update
|
|
345
|
+
// was under way (#3084). Batch runs from a file instead, written before
|
|
346
|
+
// the client is told to expect a restart.
|
|
347
|
+
const windowsScriptPath = path.join(openchamberDataDir, 'update-install.cmd');
|
|
348
|
+
if (isWindows) {
|
|
349
|
+
try {
|
|
350
|
+
fs.mkdirSync(path.dirname(windowsScriptPath), { recursive: true });
|
|
351
|
+
fs.writeFileSync(windowsScriptPath, buildWindowsUpdateScript({ logPreamble, updateCmd, restartCmd }), 'utf8');
|
|
352
|
+
} catch (scriptError) {
|
|
353
|
+
console.error('Failed to write the update script, update not started:', scriptError);
|
|
354
|
+
return res.status(500).json({
|
|
355
|
+
error: `Could not write the update script at ${windowsScriptPath}: ${scriptError instanceof Error ? scriptError.message : String(scriptError)}`,
|
|
356
|
+
});
|
|
357
|
+
}
|
|
358
|
+
}
|
|
359
|
+
|
|
303
360
|
res.json({
|
|
304
361
|
success: true,
|
|
305
362
|
message: 'Update starting, server will restart shortly',
|
|
@@ -314,21 +371,8 @@ export const registerOpenChamberRoutes = (app, dependencies) => {
|
|
|
314
371
|
console.log(`Running: ${updateCmd}`);
|
|
315
372
|
console.log(logPreamble);
|
|
316
373
|
|
|
317
|
-
const shell = isWindows ? (process.env.ComSpec || 'cmd.exe') : 'sh';
|
|
318
|
-
const shellFlag = isWindows ? '/c' : '-c';
|
|
319
374
|
const script = isWindows
|
|
320
|
-
?
|
|
321
|
-
echo ${quoteCmd(logPreamble)}
|
|
322
|
-
timeout /t 2 /nobreak >nul
|
|
323
|
-
${updateCmd}
|
|
324
|
-
if %ERRORLEVEL% EQU 0 (
|
|
325
|
-
echo Update successful, restarting OpenChamber...
|
|
326
|
-
${restartCmd || 'echo Service manager will restart OpenChamber.'}
|
|
327
|
-
) else (
|
|
328
|
-
echo Update failed
|
|
329
|
-
exit /b 1
|
|
330
|
-
)
|
|
331
|
-
`
|
|
375
|
+
? windowsScriptPath
|
|
332
376
|
: `
|
|
333
377
|
printf '%s\n' ${quotePosix(logPreamble)}
|
|
334
378
|
sleep 2
|
|
@@ -350,10 +394,24 @@ export const registerOpenChamberRoutes = (app, dependencies) => {
|
|
|
350
394
|
console.warn('Failed to open update log file, continuing without log capture:', logError);
|
|
351
395
|
}
|
|
352
396
|
|
|
397
|
+
if (isWindows) {
|
|
398
|
+
// On Windows the detached child inherits this process's listening
|
|
399
|
+
// socket, and keeps the port for as long as the batch runs. The
|
|
400
|
+
// restart inside that batch then fails with "port already in use",
|
|
401
|
+
// and the update ends with no server. Closing the listener first
|
|
402
|
+
// leaves nothing to inherit; the process exits right after anyway.
|
|
403
|
+
try {
|
|
404
|
+
server.close();
|
|
405
|
+
} catch (closeError) {
|
|
406
|
+
console.warn('Failed to close the listener before the update script:', closeError);
|
|
407
|
+
}
|
|
408
|
+
}
|
|
409
|
+
|
|
353
410
|
const child = spawnChild(shell, [shellFlag, script], {
|
|
354
411
|
detached: true,
|
|
355
412
|
stdio: logFd !== null ? ['ignore', logFd, logFd] : 'ignore',
|
|
356
413
|
env: process.env,
|
|
414
|
+
windowsHide: true,
|
|
357
415
|
});
|
|
358
416
|
child.unref();
|
|
359
417
|
|
|
@@ -18,11 +18,15 @@ const childProcess = await import('child_process');
|
|
|
18
18
|
const packageManager = await import('../package-manager.js');
|
|
19
19
|
const { registerOpenChamberRoutes } = await import('./openchamber-routes.js');
|
|
20
20
|
|
|
21
|
-
const createApp = ({ environment = {}, storedOptions = {}, desktopUpdater } = {}) => {
|
|
21
|
+
const createApp = ({ environment = {}, storedOptions = {}, desktopUpdater, platform = 'linux', execPath = '/usr/bin/node' } = {}) => {
|
|
22
22
|
const app = express();
|
|
23
23
|
const dependencies = {
|
|
24
24
|
fs: {
|
|
25
25
|
existsSync: vi.fn(() => false),
|
|
26
|
+
mkdirSync: vi.fn(),
|
|
27
|
+
writeFileSync: vi.fn(),
|
|
28
|
+
openSync: vi.fn(() => 7),
|
|
29
|
+
closeSync: vi.fn(),
|
|
26
30
|
promises: {
|
|
27
31
|
readFile: vi.fn(async () => JSON.stringify({
|
|
28
32
|
launchMode: 'foreground',
|
|
@@ -34,11 +38,13 @@ const createApp = ({ environment = {}, storedOptions = {}, desktopUpdater } = {}
|
|
|
34
38
|
path,
|
|
35
39
|
process: {
|
|
36
40
|
env: environment,
|
|
37
|
-
platform
|
|
38
|
-
execPath
|
|
41
|
+
platform,
|
|
42
|
+
execPath,
|
|
43
|
+
exit: vi.fn(),
|
|
39
44
|
},
|
|
40
45
|
server: {
|
|
41
46
|
address: () => ({ port: 7897 }),
|
|
47
|
+
close: vi.fn(),
|
|
42
48
|
},
|
|
43
49
|
__dirname: '/opt/openchamber/server',
|
|
44
50
|
openchamberDataDir: '/tmp/openchamber',
|
|
@@ -266,3 +272,65 @@ describe('OpenChamber foreground update route', () => {
|
|
|
266
272
|
});
|
|
267
273
|
});
|
|
268
274
|
});
|
|
275
|
+
|
|
276
|
+
describe('OpenChamber web update route on Windows', () => {
|
|
277
|
+
it('runs the install-and-restart script from a batch file instead of a cmd.exe /c argument', async () => {
|
|
278
|
+
const { app, dependencies } = createApp({
|
|
279
|
+
platform: 'win32',
|
|
280
|
+
execPath: 'C:\\Program Files\\nodejs\\node.exe',
|
|
281
|
+
environment: { ComSpec: 'C:\\Windows\\system32\\cmd.exe' },
|
|
282
|
+
storedOptions: { launchMode: 'daemon', port: 7897, uiPassword: 'pa%ss' },
|
|
283
|
+
});
|
|
284
|
+
childProcess.spawn.mockReturnValue({ unref: vi.fn() });
|
|
285
|
+
vi.spyOn(console, 'log').mockImplementation(() => {});
|
|
286
|
+
|
|
287
|
+
await request(app).post('/api/openchamber/update-install').expect(200);
|
|
288
|
+
await new Promise((resolve) => setTimeout(resolve, 1300));
|
|
289
|
+
|
|
290
|
+
const scriptPath = path.join('/tmp/openchamber', 'update-install.cmd');
|
|
291
|
+
expect(dependencies.fs.writeFileSync).toHaveBeenCalledWith(scriptPath, expect.any(String), 'utf8');
|
|
292
|
+
const script = dependencies.fs.writeFileSync.mock.calls[0][1];
|
|
293
|
+
const lines = script.split('\r\n');
|
|
294
|
+
expect(lines[0]).toBe('@echo off');
|
|
295
|
+
// Every preamble line is an echo; none is left to run as a command.
|
|
296
|
+
expect(lines.filter((line) => line.startsWith('currentVersion=') || line.startsWith('restartCommand='))).toEqual([]);
|
|
297
|
+
expect(lines).toContain('echo packageManager=npm');
|
|
298
|
+
expect(lines).toContain('echo restartCommand=^("C:\\Program Files\\nodejs\\node.exe" "/opt/openchamber/bin/cli.js" serve --port 7897 --ui-password "pa%%ss"^) ^|^| ^(openchamber serve --port 7897 --ui-password "pa%%ss"^)');
|
|
299
|
+
// A .cmd shim (npm, pnpm, yarn) must be `call`ed or the script ends there.
|
|
300
|
+
expect(lines).toContain('call npm install -g @openchamber/web@latest');
|
|
301
|
+
expect(lines).toContain('ping -n 3 127.0.0.1 >nul');
|
|
302
|
+
expect(lines.some((line) => line.startsWith('timeout '))).toBe(false);
|
|
303
|
+
expect(lines).toContain('if %ERRORLEVEL% EQU 0 (');
|
|
304
|
+
expect(lines.at(-2)).toBe('del "%~f0"');
|
|
305
|
+
// A `%` in the password survives batch expansion only when doubled.
|
|
306
|
+
expect(lines).toContain(' ("C:\\Program Files\\nodejs\\node.exe" "/opt/openchamber/bin/cli.js" serve --port 7897 --ui-password "pa%%ss") || (openchamber serve --port 7897 --ui-password "pa%%ss")');
|
|
307
|
+
|
|
308
|
+
expect(childProcess.spawn).toHaveBeenCalledWith(
|
|
309
|
+
'C:\\Windows\\system32\\cmd.exe',
|
|
310
|
+
['/c', scriptPath],
|
|
311
|
+
expect.objectContaining({ detached: true, windowsHide: true }),
|
|
312
|
+
);
|
|
313
|
+
// The listener is closed before the batch is spawned, so the detached
|
|
314
|
+
// child cannot inherit the socket and hold the port against the restart.
|
|
315
|
+
expect(dependencies.server.close).toHaveBeenCalledOnce();
|
|
316
|
+
expect(dependencies.server.close.mock.invocationCallOrder[0]).toBeLessThan(childProcess.spawn.mock.invocationCallOrder[0]);
|
|
317
|
+
expect(dependencies.process.exit).toHaveBeenCalledWith(0);
|
|
318
|
+
});
|
|
319
|
+
|
|
320
|
+
it('answers 500 and keeps the server up when the batch file cannot be written', async () => {
|
|
321
|
+
const { app, dependencies } = createApp({ platform: 'win32', storedOptions: { launchMode: 'daemon', port: 7897 } });
|
|
322
|
+
dependencies.fs.writeFileSync.mockImplementation(() => { throw new Error('EACCES'); });
|
|
323
|
+
vi.spyOn(console, 'log').mockImplementation(() => {});
|
|
324
|
+
const logError = vi.spyOn(console, 'error').mockImplementation(() => {});
|
|
325
|
+
|
|
326
|
+
const response = await request(app).post('/api/openchamber/update-install').expect(500);
|
|
327
|
+
await new Promise((resolve) => setTimeout(resolve, 1300));
|
|
328
|
+
|
|
329
|
+
expect(response.body.error).toContain('update-install.cmd');
|
|
330
|
+
expect(response.body.error).toContain('EACCES');
|
|
331
|
+
expect(childProcess.spawn).not.toHaveBeenCalled();
|
|
332
|
+
expect(dependencies.process.exit).not.toHaveBeenCalled();
|
|
333
|
+
expect(logError).toHaveBeenCalledOnce();
|
|
334
|
+
});
|
|
335
|
+
});
|
|
336
|
+
|
|
@@ -11,6 +11,7 @@ import {
|
|
|
11
11
|
import { createRealpathCache } from '../path-realpath-cache.js';
|
|
12
12
|
import { DEFAULT_UPSTREAM_STALL_TIMEOUT_MS } from '../event-stream/upstream-reader.js';
|
|
13
13
|
import { recordStartupPerformance } from './startup-performance.js';
|
|
14
|
+
import { getWorktreeBootstrapStatus } from '../git/service.js';
|
|
14
15
|
|
|
15
16
|
const DEFAULT_SSE_HEARTBEAT_INTERVAL_MS = 20_000;
|
|
16
17
|
|
|
@@ -286,6 +287,8 @@ export const registerOpenCodeProxy = (app, deps) => {
|
|
|
286
287
|
SSE_HEARTBEAT_INTERVAL_MS = DEFAULT_SSE_HEARTBEAT_INTERVAL_MS,
|
|
287
288
|
SSE_UPSTREAM_STALL_TIMEOUT_MS = DEFAULT_UPSTREAM_STALL_TIMEOUT_MS,
|
|
288
289
|
getSseUpstreamStallTimeoutMs = () => SSE_UPSTREAM_STALL_TIMEOUT_MS,
|
|
290
|
+
readWorktreeBootstrapStatus = getWorktreeBootstrapStatus,
|
|
291
|
+
WORKTREE_READY_TIMEOUT_MS = 5 * 60 * 1000,
|
|
289
292
|
} = deps;
|
|
290
293
|
|
|
291
294
|
if (app.get('opencodeProxyConfigured')) {
|
|
@@ -775,6 +778,36 @@ export const registerOpenCodeProxy = (app, deps) => {
|
|
|
775
778
|
}
|
|
776
779
|
});
|
|
777
780
|
|
|
781
|
+
// Any directory-scoped read can initialize OpenCode's cached project/config,
|
|
782
|
+
// before session.create runs. Hold all upstream requests until Git population
|
|
783
|
+
// finishes, independently of the user's optional setup-script wait.
|
|
784
|
+
app.use('/api', async (req, res, next) => {
|
|
785
|
+
normalizeForwardedDirectoryHeaders(req.headers);
|
|
786
|
+
const url = new URL(req.url, 'http://localhost');
|
|
787
|
+
const directory = url.searchParams.get('directory') || req.get('x-opencode-directory');
|
|
788
|
+
if (!directory) return next();
|
|
789
|
+
|
|
790
|
+
const deadline = Date.now() + WORKTREE_READY_TIMEOUT_MS;
|
|
791
|
+
try {
|
|
792
|
+
while (!res.destroyed && !res.writableEnded && !req.aborted) {
|
|
793
|
+
const status = await readWorktreeBootstrapStatus(directory);
|
|
794
|
+
if (res.destroyed || res.writableEnded || req.aborted) return;
|
|
795
|
+
if (status.status === 'failed') {
|
|
796
|
+
return res.status(503).json({ error: status.error || 'Worktree bootstrap failed' });
|
|
797
|
+
}
|
|
798
|
+
if (status.status === 'ready' || status.phase === 'git-ready' || status.phase === 'setup-ready') {
|
|
799
|
+
return next();
|
|
800
|
+
}
|
|
801
|
+
if (Date.now() >= deadline) {
|
|
802
|
+
return res.status(503).json({ error: 'Timed out waiting for worktree checkout' });
|
|
803
|
+
}
|
|
804
|
+
await sleep(75);
|
|
805
|
+
}
|
|
806
|
+
} catch (error) {
|
|
807
|
+
next(error);
|
|
808
|
+
}
|
|
809
|
+
});
|
|
810
|
+
|
|
778
811
|
// Windows: session merge for cross-directory session listing
|
|
779
812
|
if (process.platform === 'win32') {
|
|
780
813
|
app.get('/api/session', async (req, res, next) => {
|
|
@@ -233,6 +233,11 @@ export const createSettingsHelpers = (dependencies) => {
|
|
|
233
233
|
if (typeof candidate.workStatusHiddenSectionsExplicit === 'boolean') {
|
|
234
234
|
result.workStatusHiddenSectionsExplicit = candidate.workStatusHiddenSectionsExplicit;
|
|
235
235
|
}
|
|
236
|
+
if (Array.isArray(candidate.workStatusSectionOrder)) {
|
|
237
|
+
result.workStatusSectionOrder = [
|
|
238
|
+
...new Set(candidate.workStatusSectionOrder.filter((entry) => typeof entry === 'string' && entry.length > 0)),
|
|
239
|
+
];
|
|
240
|
+
}
|
|
236
241
|
if (typeof candidate.desktopLanAccessEnabled === 'boolean') {
|
|
237
242
|
result.desktopLanAccessEnabled = candidate.desktopLanAccessEnabled;
|
|
238
243
|
}
|
|
@@ -473,6 +478,9 @@ export const createSettingsHelpers = (dependencies) => {
|
|
|
473
478
|
if (candidate.sessionRetentionAction === 'archive' || candidate.sessionRetentionAction === 'delete') {
|
|
474
479
|
result.sessionRetentionAction = candidate.sessionRetentionAction;
|
|
475
480
|
}
|
|
481
|
+
if (typeof candidate.sessionRetentionOnlyArchived === 'boolean') {
|
|
482
|
+
result.sessionRetentionOnlyArchived = candidate.sessionRetentionOnlyArchived;
|
|
483
|
+
}
|
|
476
484
|
if (candidate.tunnelBootstrapTtlMs === null) {
|
|
477
485
|
result.tunnelBootstrapTtlMs = null;
|
|
478
486
|
} else if (typeof candidate.tunnelBootstrapTtlMs === 'number' && Number.isFinite(candidate.tunnelBootstrapTtlMs)) {
|
|
@@ -69,6 +69,18 @@ const createTestHelpersWithRealSanitizers = () => {
|
|
|
69
69
|
};
|
|
70
70
|
|
|
71
71
|
describe('settings helpers', () => {
|
|
72
|
+
it('round-trips section order and preserves it across unrelated writes', () => {
|
|
73
|
+
const helpers = createTestHelpers();
|
|
74
|
+
const changes = helpers.sanitizeSettingsUpdate({ workStatusSectionOrder: ['mcp', 'session', 'mcp', null, ''] });
|
|
75
|
+
expect(changes.workStatusSectionOrder).toEqual(['mcp', 'session']);
|
|
76
|
+
const saved = helpers.mergePersistedSettings({}, changes);
|
|
77
|
+
const reloaded = helpers.formatSettingsResponse(JSON.parse(JSON.stringify(saved)));
|
|
78
|
+
expect(reloaded.workStatusSectionOrder).toEqual(['mcp', 'session']);
|
|
79
|
+
const next = helpers.mergePersistedSettings(reloaded, helpers.sanitizeSettingsUpdate({ workStatusPanelEnabled: false }));
|
|
80
|
+
expect(helpers.formatSettingsResponse(next).workStatusSectionOrder).toEqual(['mcp', 'session']);
|
|
81
|
+
expect(helpers.sanitizeSettingsUpdate({ workStatusSectionOrder: 'bad' }).workStatusSectionOrder).toBeUndefined();
|
|
82
|
+
expect(helpers.sanitizeSettingsUpdate({ workStatusSectionOrder: [] }).workStatusSectionOrder).toEqual([]);
|
|
83
|
+
});
|
|
72
84
|
it('round-trips telemetry opt-in with the hidden list and preserves it across unrelated writes', () => {
|
|
73
85
|
const helpers = createTestHelpers();
|
|
74
86
|
const legacy = helpers.sanitizeSettingsUpdate({ workStatusHiddenSections: [] });
|
|
@@ -690,6 +702,14 @@ describe('settings helpers', () => {
|
|
|
690
702
|
});
|
|
691
703
|
|
|
692
704
|
describe('session retention settings persistence', () => {
|
|
705
|
+
it('round-trips archived-only retention and rejects non-boolean values', () => {
|
|
706
|
+
const helpers = createTestHelpersWithRealSanitizers();
|
|
707
|
+
for (const sessionRetentionOnlyArchived of [true, false]) {
|
|
708
|
+
expect(helpers.sanitizeSettingsUpdate({ sessionRetentionOnlyArchived })).toEqual({ sessionRetentionOnlyArchived });
|
|
709
|
+
}
|
|
710
|
+
expect(helpers.sanitizeSettingsUpdate({ sessionRetentionOnlyArchived: 'true' })).toEqual({});
|
|
711
|
+
expect(helpers.sanitizeSettingsUpdate({ sessionRetentionOnlyArchived: null })).toEqual({});
|
|
712
|
+
});
|
|
693
713
|
it('round-trips sessionRetentionAction archive and delete through the sanitizer', () => {
|
|
694
714
|
const helpers = createTestHelpersWithRealSanitizers();
|
|
695
715
|
|
|
@@ -714,6 +734,7 @@ describe('settings helpers', () => {
|
|
|
714
734
|
autoDeleteEnabled: true,
|
|
715
735
|
autoDeleteAfterDays: 60,
|
|
716
736
|
sessionRetentionAction: 'delete',
|
|
737
|
+
sessionRetentionOnlyArchived: true,
|
|
717
738
|
};
|
|
718
739
|
|
|
719
740
|
const sanitized = helpers.sanitizeSettingsUpdate(payload);
|
|
@@ -721,6 +742,7 @@ describe('settings helpers', () => {
|
|
|
721
742
|
expect(sanitized.autoDeleteEnabled).toBe(true);
|
|
722
743
|
expect(sanitized.autoDeleteAfterDays).toBe(60);
|
|
723
744
|
expect(sanitized.sessionRetentionAction).toBe('delete');
|
|
745
|
+
expect(sanitized.sessionRetentionOnlyArchived).toBe(true);
|
|
724
746
|
});
|
|
725
747
|
});
|
|
726
748
|
});
|
|
@@ -746,13 +768,13 @@ describe('settings registry gate', () => {
|
|
|
746
768
|
desktopUiPassword: 'secret', githubClientId: 'client', githubScopes: 'repo', skillCatalogs: [{ id: 'c', label: 'C', source: 'https://x' }],
|
|
747
769
|
defaultGitIdentityId: 'global', permissionAutoAccept: { sessions: { s: true }, revision: 1 },
|
|
748
770
|
agentControlToolEnabled: true, agentWebToolEnabled: true, agentMemoryToolEnabled: true, openCodeUpdateToastDismissedVersion: '1.0.0',
|
|
749
|
-
autoDeleteEnabled: true, autoDeleteAfterDays: 30, sessionRetentionAction: 'archive', terminalShell: 'zsh', terminalLoginShells: ['zsh'],
|
|
771
|
+
autoDeleteEnabled: true, autoDeleteAfterDays: 30, sessionRetentionOnlyArchived: false, sessionRetentionAction: 'archive', terminalShell: 'zsh', terminalLoginShells: ['zsh'],
|
|
750
772
|
openInAppId: 'vscode', dictationEnabled: true, sttProvider: 'local', sttServerUrl: 'http://localhost:8001/v1', sttModel: 'm', sttLocalModel: 'm', sttLanguage: 'en',
|
|
751
773
|
tunnelProvider: 'cloudflare', tunnelMode: 'quick', tunnelBootstrapTtlMs: 600000, tunnelSessionTtlMs: 86400000, managedLocalTunnelConfigPath: '/tmp/x',
|
|
752
774
|
managedRemoteTunnelHostname: 'x.example', managedRemoteTunnelToken: 'token', managedRemoteTunnelPresets: [{ id: 'a', name: 'A', hostname: 'a.example' }],
|
|
753
775
|
managedRemoteTunnelSelectedPresetId: 'a', managedRemoteTunnelPresetTokens: { a: 'token' },
|
|
754
776
|
sidebarProjectDisplayMode: 'all', sidebarSessionGroupingMode: 'flat', sidebarProjectSortOrder: 'manual', sidebarShowRecentSection: true,
|
|
755
|
-
workStatusPanelEnabled: true, workStatusHiddenSections: ['mcp'], workStatusHiddenSectionsExplicit: true,
|
|
777
|
+
workStatusPanelEnabled: true, workStatusHiddenSections: ['mcp'], workStatusHiddenSectionsExplicit: true, workStatusSectionOrder: ['mcp', 'session'],
|
|
756
778
|
showReasoningTraces: true, streamingAutoFollowEnabled: true, collapsibleThinkingBlocks: true, showTextJustificationActivity: true,
|
|
757
779
|
chatRenderMode: 'live', activityRenderMode: 'summary', mermaidRenderingMode: 'svg', userMessageRenderingMode: 'markdown', collapsibleUserMessages: true,
|
|
758
780
|
stickyUserHeader: true, promptNavigatorEnabled: true, wideChatLayoutEnabled: true, showSplitAssistantMessageActions: true, showToolFileIcons: true,
|