@openchamber/web 1.21.0 → 1.22.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.
Files changed (180) hide show
  1. package/bin/cli.test.js +35 -0
  2. package/bin/lib/DOCUMENTATION.md +12 -0
  3. package/bin/lib/cli-settings-accessors.js +111 -0
  4. package/bin/lib/cli-settings-accessors.test.js +189 -0
  5. package/bin/lib/cli-startup.js +29 -9
  6. package/bin/lib/commands-connect-url.js +12 -14
  7. package/dist/assets/{CodeMirrorCommentWidgets-C2BopIs3.js → CodeMirrorCommentWidgets-CPvfxh0N.js} +1 -1
  8. package/dist/assets/CommitSection-CC5mFzO2.js +1 -0
  9. package/dist/assets/DiffView-6xGdyI0n.js +4 -0
  10. package/dist/assets/FilesView-Bm3vT63N.js +17 -0
  11. package/dist/assets/GitView-B6y1Y69c.js +6 -0
  12. package/dist/assets/{JsonTreeView-osju7J70.js → JsonTreeView-rwHz84MX.js} +1 -1
  13. package/dist/assets/LinearIssuesView-B0UM_Rkx.js +1 -0
  14. package/dist/assets/MarkdownImageGallery-sGilV9Hs.js +1 -0
  15. package/dist/assets/MarkdownRendererImpl--4sRsKBn.js +12 -0
  16. package/dist/assets/OnboardingScreen-CECL_Cms.js +1 -0
  17. package/dist/assets/{PatchDiff-Dan3mADn.js → PatchDiff-BGPl1s-U.js} +1 -1
  18. package/dist/assets/{PierreDiffViewer-CGoI2v0q.js → PierreDiffViewer-Cvz9Z-io.js} +2 -2
  19. package/dist/assets/PlanView-BFMsnHk3.js +5 -0
  20. package/dist/assets/SettingsView-_Gtn5SdT.js +28 -0
  21. package/dist/assets/{SettingsWindow-DXF-MTHG.js → SettingsWindow-C1Qa09YO.js} +1 -1
  22. package/dist/assets/{ToolOutputDialog-DrCa1JRk.js → ToolOutputDialog-DzQlzMF4.js} +6 -6
  23. package/dist/assets/{ToolPartDiffPreview-B_tfvlNF.js → ToolPartDiffPreview-DfVOfwHy.js} +2 -2
  24. package/dist/assets/{VirtualizedFileDiff-CN_BctrR.js → VirtualizedFileDiff-DT5MDv-u.js} +1 -1
  25. package/dist/assets/WalkthroughView-D8sLH_M8.js +4 -0
  26. package/dist/assets/{computeVirtualFileMetrics-Gi1d5eU1.js → computeVirtualFileMetrics-DmpLWhll.js} +1 -1
  27. package/dist/assets/{contextPanelEmbeddedChat-CpzVNWAv.js → contextPanelEmbeddedChat-BK78t3M_.js} +1 -1
  28. package/dist/assets/de-C3luvSd_.js +9 -0
  29. package/dist/assets/es-CmU4HLv9.js +15 -0
  30. package/dist/assets/fr-Bgyni40l.js +13 -0
  31. package/dist/assets/index-C57jT0Sa.css +1 -0
  32. package/dist/assets/{index-Brm3X9rs.js → index-CWYs7sMK.js} +1 -1
  33. package/dist/assets/index-b0zDkWyg.js +7 -0
  34. package/dist/assets/{isDiffPlainText-pH9kAJQH.js → isDiffPlainText-BO_q5ezD.js} +1 -1
  35. package/dist/assets/{isFilePlainText-CVKy_dgB.js → isFilePlainText-D8qPqUAf.js} +1 -1
  36. package/dist/assets/ja-C1ImKinT.js +15 -0
  37. package/dist/assets/ko-CP7OdxYH.js +15 -0
  38. package/dist/assets/main-D4rd8Hy5.js +928 -0
  39. package/dist/assets/{main-vUCh0VB0.js → main-D7fwjW2z.js} +2 -2
  40. package/dist/assets/{markdown-shiki.worker-CKGJ1J33.js → markdown-shiki.worker-D5fBU-lw.js} +5 -5
  41. package/dist/assets/markdownCore-BcmkWZPO.js +3 -0
  42. package/dist/assets/{miniChat-BlzGEYgE.js → miniChat-D5rraz-g.js} +2 -2
  43. package/dist/assets/{mobile-CkX6H-IT.js → mobile-Cg_DE3KL.js} +2 -2
  44. package/dist/assets/{patchFileDiff-BCTsE43U.js → patchFileDiff-Bpql0QGw.js} +3 -3
  45. package/dist/assets/pl-DQYSiGYX.js +15 -0
  46. package/dist/assets/pt-BR-DytpsW4M.js +15 -0
  47. package/dist/assets/{renderElectronMiniChatApp-CJYe_KOL.js → renderElectronMiniChatApp-B_Bn7BbN.js} +2 -2
  48. package/dist/assets/renderMobileApp-DLfxMzGJ.js +25 -0
  49. package/dist/assets/runtimeEndpointReset-HlRmXFGW.js +16 -0
  50. package/dist/assets/scheduledTasksApi-BPvxrynl.js +1 -0
  51. package/dist/assets/{shikiHighlight-BgTPSITe.js → shikiHighlight-CFAVs_lu.js} +1 -1
  52. package/dist/assets/tr-aizaUvft.js +6 -0
  53. package/dist/assets/uk-DwnRxJZd.js +15 -0
  54. package/dist/assets/useAppFontEffects-DWXGRUPZ.js +7310 -0
  55. package/dist/assets/{useInlineCommentController-DFFv0hae.js → useInlineCommentController-Cc0OCXr0.js} +2 -2
  56. package/dist/assets/useRootScrollLock-BFZtfciC.js +1 -0
  57. package/dist/assets/{vendor-base-ui-_6j2xOWl.js → vendor-base-ui-BeMD8X_w.js} +1 -1
  58. package/dist/assets/{vendor-codemirror-language-data-DkQX2EBa.js → vendor-codemirror-language-data-BGFszm8n.js} +2 -2
  59. package/dist/assets/{vendor-floating-ui-core-CXmKXOXc.js → vendor-floating-ui-core-PuGzNPnN.js} +1 -1
  60. package/dist/assets/{vendor-floating-ui-dom-WyXykhNi.js → vendor-floating-ui-dom-BTvzWks8.js} +1 -1
  61. package/dist/assets/{vendor-floating-ui-react-dom-DKpLs02S.js → vendor-floating-ui-react-dom-DxYCWdHj.js} +1 -1
  62. package/dist/assets/{vendor-floating-ui-utils-BzXdqYpP.js → vendor-floating-ui-utils-D6FqdtJt.js} +1 -1
  63. package/dist/assets/vendor-linkify-it-DZCzzDkK.js +1 -0
  64. package/dist/assets/vendor-marked-linkify-it-CXI_LHIE.js +1 -0
  65. package/dist/assets/vendor-uc.micro-BAd0H0z4.js +1 -0
  66. package/dist/assets/{web-components-DLnGY4fs.js → web-components-CD-GFayc.js} +4 -4
  67. package/dist/assets/zh-CN-UDNMxm7r.js +15 -0
  68. package/dist/assets/zh-TW-BsswdYL-.js +15 -0
  69. package/dist/index.html +5 -5
  70. package/dist/mini-chat.html +3 -3
  71. package/dist/mobile.html +3 -3
  72. package/dist/site.webmanifest +1 -1
  73. package/dist/sw.js +1 -1
  74. package/package.json +2 -2
  75. package/public/site.webmanifest +1 -1
  76. package/server/index.js +6 -2
  77. package/server/lib/cloudflare-tunnel.js +1 -1
  78. package/server/lib/dictation/DOCUMENTATION.md +19 -6
  79. package/server/lib/dictation/local/model-catalog.js +220 -0
  80. package/server/lib/dictation/local/model-catalog.test.js +42 -0
  81. package/server/lib/dictation/local/sherpa-tts.js +41 -20
  82. package/server/lib/dictation/local/worker-process.js +2 -0
  83. package/server/lib/dictation/runtime.js +4 -0
  84. package/server/lib/dictation/service.js +27 -4
  85. package/server/lib/fs/DOCUMENTATION.md +5 -0
  86. package/server/lib/fs/routes.js +150 -0
  87. package/server/lib/fs/routes.test.js +308 -3
  88. package/server/lib/git/DOCUMENTATION.md +4 -3
  89. package/server/lib/git/service.js +128 -6
  90. package/server/lib/git/service.test.js +191 -1
  91. package/server/lib/linear/DOCUMENTATION.md +97 -0
  92. package/server/lib/linear/OAUTH-BROKER-HANDOFF.md +91 -0
  93. package/server/lib/linear/auth.js +436 -0
  94. package/server/lib/linear/auth.test.js +242 -0
  95. package/server/lib/linear/client.js +191 -0
  96. package/server/lib/linear/index.js +61 -0
  97. package/server/lib/linear/issues.js +499 -0
  98. package/server/lib/linear/issues.test.js +512 -0
  99. package/server/lib/linear/mapping.js +188 -0
  100. package/server/lib/linear/mapping.test.js +147 -0
  101. package/server/lib/linear/oauth.js +345 -0
  102. package/server/lib/linear/oauth.test.js +166 -0
  103. package/server/lib/linear/parse.js +23 -0
  104. package/server/lib/linear/routes.js +432 -0
  105. package/server/lib/linear/routes.test.js +661 -0
  106. package/server/lib/linear/status-runtime.js +64 -0
  107. package/server/lib/linear/status-runtime.test.js +167 -0
  108. package/server/lib/linear/status.js +280 -0
  109. package/server/lib/linear/status.test.js +271 -0
  110. package/server/lib/linear/teams.js +72 -0
  111. package/server/lib/linear/teams.test.js +94 -0
  112. package/server/lib/markdown-image-grants/DOCUMENTATION.md +4 -0
  113. package/server/lib/markdown-image-grants/routes.js +3 -1
  114. package/server/lib/markdown-image-grants/routes.test.js +14 -0
  115. package/server/lib/openchamber-sessions/routes.js +4 -1
  116. package/server/lib/openchamber-sessions/routes.test.js +23 -0
  117. package/server/lib/opencode/env-runtime.js +17 -1
  118. package/server/lib/opencode/env-runtime.test.js +56 -0
  119. package/server/lib/opencode/feature-routes-runtime.js +2 -0
  120. package/server/lib/opencode/lifecycle.js +48 -9
  121. package/server/lib/opencode/lifecycle.test.js +125 -1
  122. package/server/lib/opencode/managed-process-registry.d.ts +13 -0
  123. package/server/lib/opencode/managed-process-registry.js +213 -163
  124. package/server/lib/opencode/managed-process-registry.test.mjs +285 -0
  125. package/server/lib/opencode/project-directory-runtime.js +16 -11
  126. package/server/lib/opencode/project-directory-runtime.test.js +32 -12
  127. package/server/lib/opencode/pwa-manifest-routes.js +1 -1
  128. package/server/lib/opencode/routes-upgrade.test.js +96 -12
  129. package/server/lib/opencode/routes.js +53 -5
  130. package/server/lib/opencode/settings-helpers.js +3 -0
  131. package/server/lib/opencode/settings-helpers.test.js +10 -0
  132. package/server/lib/opencode/static-routes-runtime.js +3 -3
  133. package/server/lib/opencode/theme-runtime.js +1 -1
  134. package/server/lib/opencode/theme-runtime.test.js +129 -0
  135. package/server/lib/projects/project-config.js +33 -5
  136. package/server/lib/projects/project-config.test.js +85 -0
  137. package/server/lib/quota/DOCUMENTATION.md +19 -0
  138. package/server/lib/quota/providers/copilot.js +26 -10
  139. package/server/lib/quota/providers/copilot.test.js +78 -0
  140. package/server/lib/scheduled-tasks/DOCUMENTATION.md +7 -0
  141. package/server/lib/small-model/DOCUMENTATION.md +11 -5
  142. package/server/lib/small-model/call.js +64 -20
  143. package/server/lib/small-model/call.test.js +184 -2
  144. package/server/lib/tts/DOCUMENTATION.md +1 -0
  145. package/server/lib/tts/language-detect.js +210 -0
  146. package/server/lib/tts/language-detect.test.js +76 -0
  147. package/server/lib/tts/routes.js +23 -1
  148. package/server/lib/tts/routes.test.js +26 -0
  149. package/server/lib/tunnels/install-help.js +2 -2
  150. package/server/lib/tunnels/install-help.test.js +9 -0
  151. package/server/lib/walkthrough/languages.js +1 -0
  152. package/dist/assets/CommitSection-HJeMUAWb.js +0 -1
  153. package/dist/assets/DiffView-D5cvbEPb.js +0 -4
  154. package/dist/assets/FilesView-DPU8aNPL.js +0 -17
  155. package/dist/assets/GitView-Ct6xWrVH.js +0 -6
  156. package/dist/assets/MarkdownImageGallery-EujHSZ2M.js +0 -1
  157. package/dist/assets/MarkdownRendererImpl-CPzu4kIr.js +0 -12
  158. package/dist/assets/OnboardingScreen-w2VG4fWY.js +0 -1
  159. package/dist/assets/PlanView-Dgg-WTEc.js +0 -4
  160. package/dist/assets/SessionSwitcherDropdown-CJTrc8K7.js +0 -1
  161. package/dist/assets/SettingsView-D9yRuFZw.js +0 -28
  162. package/dist/assets/WalkthroughView-D9Q4lr5x.js +0 -4
  163. package/dist/assets/de-B_LdJwEM.js +0 -9
  164. package/dist/assets/es-CubfsAYV.js +0 -15
  165. package/dist/assets/fr-5qJM0nFS.js +0 -13
  166. package/dist/assets/index-BW82eK5v.css +0 -1
  167. package/dist/assets/index-rlLjZUM5.js +0 -7
  168. package/dist/assets/ja-DJYIBUlH.js +0 -15
  169. package/dist/assets/ko-DcUBkB7y.js +0 -15
  170. package/dist/assets/main-DLBxKIoX.js +0 -926
  171. package/dist/assets/markdownCore-DG6GHLF4.js +0 -3
  172. package/dist/assets/pl-rB6BLcio.js +0 -15
  173. package/dist/assets/pt-BR-DcwtlO-o.js +0 -15
  174. package/dist/assets/renderMobileApp-hQJTnr8B.js +0 -25
  175. package/dist/assets/runtimeEndpointReset-BDh7r8BL.js +0 -15
  176. package/dist/assets/scheduledTasksApi-CAGPh_gZ.js +0 -1
  177. package/dist/assets/uk-INZlFD9A.js +0 -15
  178. package/dist/assets/useAppFontEffects-Cll4gnsh.js +0 -7268
  179. package/dist/assets/zh-CN-Dzda8xa1.js +0 -15
  180. package/dist/assets/zh-TW-Cwn3rNYZ.js +0 -15
@@ -0,0 +1,285 @@
1
+ import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
2
+
3
+ import { createManagedProcessRegistry } from './managed-process-registry.js';
4
+
5
+ // The registry takes its filesystem and child-process helpers as dependencies,
6
+ // so these tests inject fakes instead of mocking node builtins.
7
+ const readdirMock = vi.fn();
8
+ const readFileMock = vi.fn();
9
+ const rmMock = vi.fn();
10
+ const mkdirMock = vi.fn();
11
+ const writeFileMock = vi.fn();
12
+ const renameMock = vi.fn();
13
+
14
+ // `execFileImpl` is the swappable per-test implementation, called with the same
15
+ // (cmd, args, opts, cb) shape the callback-style `execFile` uses; the injected
16
+ // `execFileAsync` adapts it to the `{ stdout, stderr }` promise the module awaits.
17
+ const execFileImpl = vi.fn();
18
+
19
+ const { registerManagedProcess, unregisterManagedProcess, reapOrphanedProcesses } = createManagedProcessRegistry({
20
+ fs: {
21
+ readdir: readdirMock,
22
+ readFile: readFileMock,
23
+ rm: rmMock,
24
+ mkdir: mkdirMock,
25
+ writeFile: writeFileMock,
26
+ rename: renameMock,
27
+ },
28
+ execFileAsync: (cmd, args, opts) =>
29
+ new Promise((resolve, reject) => {
30
+ execFileImpl(cmd, args, opts, (err, stdout, stderr) =>
31
+ err ? reject(err) : resolve({ stdout: stdout ?? '', stderr: stderr ?? '' }));
32
+ }),
33
+ });
34
+
35
+ const ORIGINAL_PLATFORM = Object.getOwnPropertyDescriptor(process, 'platform');
36
+ const ORIGINAL_KILL = process.kill;
37
+ const killMock = vi.fn();
38
+
39
+ const setPlatform = (platform) => {
40
+ Object.defineProperty(process, 'platform', { value: platform, configurable: true });
41
+ };
42
+
43
+ const restorePlatform = () => {
44
+ if (ORIGINAL_PLATFORM) {
45
+ Object.defineProperty(process, 'platform', ORIGINAL_PLATFORM);
46
+ }
47
+ };
48
+
49
+ const installKillMock = () => {
50
+ Object.defineProperty(process, 'kill', { value: killMock, configurable: true });
51
+ };
52
+
53
+ const restoreKill = () => {
54
+ Object.defineProperty(process, 'kill', { value: ORIGINAL_KILL, configurable: true });
55
+ };
56
+
57
+ // Helper to make given pids look alive on signal-0 (returns true); any other
58
+ // pid throws ESRCH (dead). Non-zero signals always "succeed" so `killOrphan`'s
59
+ // signalTree is inert under test.
60
+ const killAliveFor = (alivePids) =>
61
+ killMock.mockImplementation((pid, signal) => {
62
+ if (signal === 0 || signal === undefined) {
63
+ if (alivePids.includes(pid)) return true;
64
+ const error = new Error('ESRCH');
65
+ error.code = 'ESRCH';
66
+ throw error;
67
+ }
68
+ return true;
69
+ });
70
+
71
+ // Configure `execFileImpl` with a (cmd, args, opts, cb) dispatcher.
72
+ const execFileYields = (dispatch) =>
73
+ execFileImpl.mockImplementation((cmd, args, opts, cb) => dispatch(cmd, args, opts, cb));
74
+
75
+ beforeEach(() => {
76
+ readdirMock.mockReset();
77
+ readFileMock.mockReset();
78
+ rmMock.mockReset();
79
+ mkdirMock.mockReset();
80
+ writeFileMock.mockReset();
81
+ renameMock.mockReset();
82
+ execFileImpl.mockReset();
83
+ killMock.mockReset();
84
+ installKillMock();
85
+ });
86
+
87
+ afterEach(() => {
88
+ restoreKill();
89
+ restorePlatform();
90
+ });
91
+
92
+ describe('reapOrphanedProcesses', () => {
93
+ it('returns zero counts when the registry directory is missing', async () => {
94
+ readdirMock.mockRejectedValue(Object.assign(new Error('ENOENT'), { code: 'ENOENT' }));
95
+
96
+ const result = await reapOrphanedProcesses();
97
+
98
+ expect(result).toEqual({ inspected: 0, reaped: 0 });
99
+ expect(execFileImpl).not.toHaveBeenCalled();
100
+ });
101
+
102
+ it('drops registry entries whose pid is already dead, without spawning anything', async () => {
103
+ readdirMock.mockResolvedValue(['99999.json']);
104
+ readFileMock.mockResolvedValue(
105
+ JSON.stringify({ pid: 99999, ownerPid: 12345, port: 4096, binary: '/opencode', runtime: 'web' }),
106
+ );
107
+ killMock.mockImplementation(() => {
108
+ const error = new Error('ESRCH');
109
+ error.code = 'ESRCH';
110
+ throw error;
111
+ });
112
+ rmMock.mockResolvedValue();
113
+
114
+ const result = await reapOrphanedProcesses();
115
+
116
+ expect(result).toEqual({ inspected: 1, reaped: 0 });
117
+ expect(rmMock).toHaveBeenCalledTimes(1);
118
+ expect(execFileImpl).not.toHaveBeenCalled();
119
+ });
120
+
121
+ describe('on Windows', () => {
122
+ beforeEach(() => setPlatform('win32'));
123
+
124
+ it('reaps an opencode image whose owner is gone', async () => {
125
+ readdirMock.mockResolvedValue(['777.json']);
126
+ readFileMock.mockResolvedValue(
127
+ JSON.stringify({ pid: 777, ownerPid: 12345, port: 4096, binary: 'opencode.exe', runtime: 'desktop' }),
128
+ );
129
+ // pid 777 alive, owner 12345 dead.
130
+ killAliveFor([777]);
131
+ execFileYields((cmd, _args, _opts, cb) => {
132
+ if (cmd === 'tasklist') return cb(null, 'opencode.exe', '');
133
+ if (cmd === 'taskkill') return cb(null, '', '');
134
+ cb(new Error(`unexpected cmd: ${cmd}`));
135
+ });
136
+ rmMock.mockResolvedValue();
137
+
138
+ const result = await reapOrphanedProcesses({ log: () => {} });
139
+
140
+ expect(result).toEqual({ inspected: 1, reaped: 1 });
141
+ expect(execFileImpl).toHaveBeenCalledWith(
142
+ 'tasklist',
143
+ expect.any(Array),
144
+ expect.objectContaining({ windowsHide: true }),
145
+ expect.any(Function),
146
+ );
147
+ expect(execFileImpl).toHaveBeenCalledWith(
148
+ 'taskkill',
149
+ expect.any(Array),
150
+ expect.objectContaining({ windowsHide: true }),
151
+ expect.any(Function),
152
+ );
153
+ });
154
+
155
+ it('leaves a non-opencode image alone even if the owner is gone', async () => {
156
+ readdirMock.mockResolvedValue(['777.json']);
157
+ readFileMock.mockResolvedValue(
158
+ JSON.stringify({ pid: 777, ownerPid: 12345, port: 4096, binary: 'opencode.exe', runtime: 'desktop' }),
159
+ );
160
+ killAliveFor([777]);
161
+ execFileYields((_cmd, _args, _opts, cb) => cb(null, 'notepad.exe', ''));
162
+ rmMock.mockResolvedValue();
163
+
164
+ const result = await reapOrphanedProcesses({ log: () => {} });
165
+
166
+ expect(result).toEqual({ inspected: 1, reaped: 0 });
167
+ const calls = execFileImpl.mock.calls.filter(([cmd]) => cmd === 'taskkill');
168
+ expect(calls).toHaveLength(0);
169
+ });
170
+
171
+ it('leaves an opencode image whose owner is still alive', async () => {
172
+ readdirMock.mockResolvedValue(['777.json']);
173
+ readFileMock.mockResolvedValue(
174
+ JSON.stringify({ pid: 777, ownerPid: 12345, port: 4096, binary: 'opencode.exe', runtime: 'desktop' }),
175
+ );
176
+ // Both alive.
177
+ killAliveFor([777, 12345]);
178
+ execFileYields((_cmd, _args, _opts, cb) => cb(null, 'opencode.exe', ''));
179
+
180
+ const result = await reapOrphanedProcesses({ log: () => {} });
181
+
182
+ expect(result).toEqual({ inspected: 1, reaped: 0 });
183
+ const calls = execFileImpl.mock.calls.filter(([cmd]) => cmd === 'taskkill');
184
+ expect(calls).toHaveLength(0);
185
+ });
186
+ });
187
+
188
+ describe('on Unix', () => {
189
+ beforeEach(() => setPlatform('linux'));
190
+
191
+ it('reaps a reparented opencode serve matching the recorded port', async () => {
192
+ readdirMock.mockResolvedValue(['777.json']);
193
+ readFileMock.mockResolvedValue(
194
+ JSON.stringify({ pid: 777, ownerPid: 12345, port: 4096, binary: '/opencode', runtime: 'web' }),
195
+ );
196
+ // pid 777 stays "alive"; killOrphan's signalTree is inert (mock returns
197
+ // true for non-zero signals), and its wait loop sees isPidAlive true so
198
+ // it exhausts the SIGTERM wait then sends SIGKILL and sleeps 300ms.
199
+ killAliveFor([777]);
200
+ execFileYields((cmd, _args, _opts, cb) => {
201
+ if (cmd === 'ps') return cb(null, '1 /usr/bin/opencode serve --port 4096\n', '');
202
+ cb(new Error(`unexpected cmd: ${cmd}`));
203
+ });
204
+ rmMock.mockResolvedValue();
205
+
206
+ const result = await reapOrphanedProcesses({ log: () => {} });
207
+
208
+ expect(result).toEqual({ inspected: 1, reaped: 1 });
209
+ });
210
+
211
+ it('leaves a process whose command is not our opencode serve', async () => {
212
+ readdirMock.mockResolvedValue(['777.json']);
213
+ readFileMock.mockResolvedValue(
214
+ JSON.stringify({ pid: 777, ownerPid: 12345, port: 4096, binary: '/opencode', runtime: 'web' }),
215
+ );
216
+ killAliveFor([777]);
217
+ execFileYields((cmd, _args, _opts, cb) => {
218
+ if (cmd === 'ps') return cb(null, '1 /some/other/binary serve\n', '');
219
+ cb(new Error(`unexpected cmd: ${cmd}`));
220
+ });
221
+
222
+ const result = await reapOrphanedProcesses({ log: () => {} });
223
+
224
+ expect(result).toEqual({ inspected: 1, reaped: 0 });
225
+ });
226
+
227
+ it('leaves a process still owned by a live owner (not reparented)', async () => {
228
+ readdirMock.mockResolvedValue(['777.json']);
229
+ readFileMock.mockResolvedValue(
230
+ JSON.stringify({ pid: 777, ownerPid: 12345, port: 4096, binary: '/opencode', runtime: 'web' }),
231
+ );
232
+ killAliveFor([777, 12345]);
233
+ execFileYields((cmd, _args, _opts, cb) => {
234
+ if (cmd === 'ps') return cb(null, '12345 /usr/bin/opencode serve --port 4096\n', '');
235
+ cb(new Error(`unexpected cmd: ${cmd}`));
236
+ });
237
+
238
+ const result = await reapOrphanedProcesses({ log: () => {} });
239
+
240
+ expect(result).toEqual({ inspected: 1, reaped: 0 });
241
+ });
242
+ });
243
+ });
244
+
245
+ describe('registerManagedProcess', () => {
246
+ it('writes an entry file atomically via tmp + rename', async () => {
247
+ mkdirMock.mockResolvedValue();
248
+ writeFileMock.mockResolvedValue();
249
+ renameMock.mockResolvedValue();
250
+
251
+ await registerManagedProcess({ pid: 4242, ownerPid: 12345, port: 4096, binary: '/opencode', runtime: 'desktop' });
252
+
253
+ expect(mkdirMock).toHaveBeenCalledWith(expect.any(String), { recursive: true });
254
+ expect(writeFileMock).toHaveBeenCalledWith(
255
+ expect.stringContaining('4242.json.tmp-'),
256
+ expect.any(String),
257
+ );
258
+ expect(renameMock).toHaveBeenCalledWith(
259
+ expect.stringContaining('4242.json.tmp-'),
260
+ expect.stringContaining('4242.json'),
261
+ );
262
+ });
263
+
264
+ it('is a no-op for a non-integer pid', async () => {
265
+ await registerManagedProcess({ pid: 'not-a-pid' });
266
+
267
+ expect(writeFileMock).not.toHaveBeenCalled();
268
+ });
269
+ });
270
+
271
+ describe('unregisterManagedProcess', () => {
272
+ it('removes the entry file', async () => {
273
+ rmMock.mockResolvedValue();
274
+
275
+ await unregisterManagedProcess(4242);
276
+
277
+ expect(rmMock).toHaveBeenCalledWith(expect.stringContaining('4242.json'), { force: true });
278
+ });
279
+
280
+ it('is a no-op for a non-integer pid', async () => {
281
+ await unregisterManagedProcess(undefined);
282
+
283
+ expect(rmMock).not.toHaveBeenCalled();
284
+ });
285
+ });
@@ -44,7 +44,12 @@ export const createProjectDirectoryRuntime = (dependencies) => {
44
44
  return { ok: false, error: 'Specified path is not a directory' };
45
45
  }
46
46
  const realPath = await realpathCache.resolve(resolved);
47
- return { ok: true, directory: realPath };
47
+ // `requestedDirectory` is the pre-realpath candidate the caller asked
48
+ // for. Callers that address files in the user-visible path space (the
49
+ // file tree, the read-family FS routes) need it when the project root
50
+ // is itself a symlink and the canonical `directory` no longer contains
51
+ // the paths the client sends.
52
+ return { ok: true, directory: realPath, requestedDirectory: resolved };
48
53
  } catch (error) {
49
54
  const err = error;
50
55
  if (err && typeof err === 'object' && err.code === 'ENOENT') {
@@ -71,11 +76,11 @@ export const createProjectDirectoryRuntime = (dependencies) => {
71
76
  for (const candidate of requested) {
72
77
  const validated = await validateDirectoryPath(candidate);
73
78
  if (validated.ok) {
74
- return { directory: validated.directory, error: null };
79
+ return { directory: validated.directory, requestedDirectory: validated.requestedDirectory, error: null };
75
80
  }
76
81
  lastError = validated.error;
77
82
  }
78
- return { directory: null, error: lastError };
83
+ return { directory: null, requestedDirectory: null, error: lastError };
79
84
  }
80
85
 
81
86
  const readSettings = typeof getReadSettingsFromDiskMigrated === 'function'
@@ -93,27 +98,27 @@ export const createProjectDirectoryRuntime = (dependencies) => {
93
98
  if (typeof settings.lastDirectory === 'string' && settings.lastDirectory.trim()) {
94
99
  const validated = await validateDirectoryPath(settings.lastDirectory);
95
100
  if (validated.ok) {
96
- return { directory: validated.directory, error: null };
101
+ return { directory: validated.directory, requestedDirectory: validated.requestedDirectory, error: null };
97
102
  }
98
103
  }
99
104
 
100
105
  const projects = sanitizeProjects(settings.projects) || [];
101
106
  if (projects.length === 0) {
102
- return { directory: null, error: 'Directory parameter or active project is required' };
107
+ return { directory: null, requestedDirectory: null, error: 'Directory parameter or active project is required' };
103
108
  }
104
109
 
105
110
  const activeId = typeof settings.activeProjectId === 'string' ? settings.activeProjectId : '';
106
111
  const active = projects.find((project) => project.id === activeId) || projects[0];
107
112
  if (!active || !active.path) {
108
- return { directory: null, error: 'Directory parameter or active project is required' };
113
+ return { directory: null, requestedDirectory: null, error: 'Directory parameter or active project is required' };
109
114
  }
110
115
 
111
116
  const validated = await validateDirectoryPath(active.path);
112
117
  if (!validated.ok) {
113
- return { directory: null, error: validated.error };
118
+ return { directory: null, requestedDirectory: null, error: validated.error };
114
119
  }
115
120
 
116
- return { directory: validated.directory, error: null };
121
+ return { directory: validated.directory, requestedDirectory: validated.requestedDirectory, error: null };
117
122
  };
118
123
 
119
124
  const resolveOptionalProjectDirectory = async (req) => {
@@ -126,18 +131,18 @@ export const createProjectDirectoryRuntime = (dependencies) => {
126
131
  const requested = [headerDirectory, queryDirectory].filter(Boolean);
127
132
 
128
133
  if (requested.length === 0) {
129
- return { directory: null, error: null };
134
+ return { directory: null, requestedDirectory: null, error: null };
130
135
  }
131
136
 
132
137
  let lastError = null;
133
138
  for (const candidate of requested) {
134
139
  const validated = await validateDirectoryPath(candidate);
135
140
  if (validated.ok) {
136
- return { directory: validated.directory, error: null };
141
+ return { directory: validated.directory, requestedDirectory: validated.requestedDirectory, error: null };
137
142
  }
138
143
  lastError = validated.error;
139
144
  }
140
- return { directory: null, error: lastError };
145
+ return { directory: null, requestedDirectory: null, error: lastError };
141
146
  };
142
147
 
143
148
  return {
@@ -26,7 +26,7 @@ describe('project directory runtime', () => {
26
26
  const runtime = createTestRuntime();
27
27
  const result = await runtime.validateDirectoryPath('/home/user/project');
28
28
 
29
- expect(result).toEqual({ ok: true, directory: '/home/user/project' });
29
+ expect(result).toEqual({ ok: true, directory: '/home/user/project', requestedDirectory: '/home/user/project' });
30
30
  });
31
31
 
32
32
  it('resolves symlinks via fsPromises.realpath', async () => {
@@ -39,7 +39,7 @@ describe('project directory runtime', () => {
39
39
 
40
40
  const result = await runtime.validateDirectoryPath('/symlink/path/to/project');
41
41
 
42
- expect(result).toEqual({ ok: true, directory: '/real/path/to/project' });
42
+ expect(result).toEqual({ ok: true, directory: '/real/path/to/project', requestedDirectory: '/symlink/path/to/project' });
43
43
  });
44
44
 
45
45
  it('returns error when candidate is empty', async () => {
@@ -125,7 +125,11 @@ describe('project directory runtime', () => {
125
125
 
126
126
  const result = await runtime.resolveProjectDirectory(req);
127
127
 
128
- expect(result).toEqual({ directory: '/real/workspace/project', error: null });
128
+ expect(result).toEqual({
129
+ directory: '/real/workspace/project',
130
+ requestedDirectory: '/home/user/workspace/project',
131
+ error: null,
132
+ });
129
133
  });
130
134
 
131
135
  it('decodes marked x-opencode-directory header values', async () => {
@@ -153,7 +157,7 @@ describe('project directory runtime', () => {
153
157
  const result = await runtime.resolveProjectDirectory(req);
154
158
 
155
159
  expect(validatedPath).toBe(pathWithUnicode);
156
- expect(result).toEqual({ directory: pathWithUnicode, error: null });
160
+ expect(result).toEqual({ directory: pathWithUnicode, requestedDirectory: pathWithUnicode, error: null });
157
161
  });
158
162
 
159
163
  it('preserves raw percent sequences without directory encoding marker', async () => {
@@ -177,7 +181,7 @@ describe('project directory runtime', () => {
177
181
  const result = await runtime.resolveProjectDirectory(req);
178
182
 
179
183
  expect(validatedPath).toBe(rawPath);
180
- expect(result).toEqual({ directory: rawPath, error: null });
184
+ expect(result).toEqual({ directory: rawPath, requestedDirectory: rawPath, error: null });
181
185
  });
182
186
 
183
187
  it('falls back to query directory when an unmarked encoded header is invalid', async () => {
@@ -199,7 +203,7 @@ describe('project directory runtime', () => {
199
203
 
200
204
  const result = await runtime.resolveProjectDirectory(req);
201
205
 
202
- expect(result).toEqual({ directory: validPath, error: null });
206
+ expect(result).toEqual({ directory: validPath, requestedDirectory: validPath, error: null });
203
207
  });
204
208
 
205
209
  it('resolves symlinks in query directory parameter', async () => {
@@ -217,7 +221,11 @@ describe('project directory runtime', () => {
217
221
 
218
222
  const result = await runtime.resolveProjectDirectory(req);
219
223
 
220
- expect(result).toEqual({ directory: '/real/workspace/project', error: null });
224
+ expect(result).toEqual({
225
+ directory: '/real/workspace/project',
226
+ requestedDirectory: '/home/user/workspace/project',
227
+ error: null,
228
+ });
221
229
  });
222
230
 
223
231
  it('resolves symlinks in lastDirectory from settings', async () => {
@@ -238,7 +246,11 @@ describe('project directory runtime', () => {
238
246
 
239
247
  const result = await runtime.resolveProjectDirectory(req);
240
248
 
241
- expect(result).toEqual({ directory: '/real/workspace/project', error: null });
249
+ expect(result).toEqual({
250
+ directory: '/real/workspace/project',
251
+ requestedDirectory: '/home/user/workspace/project',
252
+ error: null,
253
+ });
242
254
  });
243
255
 
244
256
  it('resolves symlinks in active project path from settings', async () => {
@@ -261,7 +273,11 @@ describe('project directory runtime', () => {
261
273
 
262
274
  const result = await runtime.resolveProjectDirectory(req);
263
275
 
264
- expect(result).toEqual({ directory: '/real/workspace/project', error: null });
276
+ expect(result).toEqual({
277
+ directory: '/real/workspace/project',
278
+ requestedDirectory: '/home/user/workspace/project',
279
+ error: null,
280
+ });
265
281
  });
266
282
  });
267
283
 
@@ -276,7 +292,7 @@ describe('project directory runtime', () => {
276
292
 
277
293
  const result = await runtime.resolveOptionalProjectDirectory(req);
278
294
 
279
- expect(result).toEqual({ directory: null, error: null });
295
+ expect(result).toEqual({ directory: null, requestedDirectory: null, error: null });
280
296
  });
281
297
 
282
298
  it('resolves symlinks when directory is provided', async () => {
@@ -294,7 +310,11 @@ describe('project directory runtime', () => {
294
310
 
295
311
  const result = await runtime.resolveOptionalProjectDirectory(req);
296
312
 
297
- expect(result).toEqual({ directory: '/real/workspace/project', error: null });
313
+ expect(result).toEqual({
314
+ directory: '/real/workspace/project',
315
+ requestedDirectory: '/symlink/workspace/project',
316
+ error: null,
317
+ });
298
318
  });
299
319
 
300
320
  it('preserves raw percent sequences without directory encoding marker', async () => {
@@ -318,7 +338,7 @@ describe('project directory runtime', () => {
318
338
  const result = await runtime.resolveOptionalProjectDirectory(req);
319
339
 
320
340
  expect(validatedPath).toBe(rawPath);
321
- expect(result).toEqual({ directory: rawPath, error: null });
341
+ expect(result).toEqual({ directory: rawPath, requestedDirectory: rawPath, error: null });
322
342
  });
323
343
  });
324
344
  });
@@ -1,4 +1,4 @@
1
- const DEFAULT_PWA_APP_NAME = 'OpenChamber - AI Coding Assistant';
1
+ const DEFAULT_PWA_APP_NAME = 'OpenChamber';
2
2
  const mapPwaOrientationToManifest = (value) => {
3
3
  if (value === 'portrait') {
4
4
  return 'portrait-primary';
@@ -9,6 +9,13 @@ afterEach(() => {
9
9
  globalThis.fetch = originalFetch;
10
10
  });
11
11
 
12
+ const jsonResponse = (payload, status = 200) => new Response(JSON.stringify(payload), {
13
+ status,
14
+ headers: { 'Content-Type': 'application/json' },
15
+ });
16
+
17
+ const supportedCapability = { supported: true, manager: 'opencode', reason: null };
18
+
12
19
  const createApp = (overrides = {}) => {
13
20
  const app = express();
14
21
  app.use(express.json());
@@ -67,22 +74,99 @@ describe('OpenCode upgrade routes', () => {
67
74
  });
68
75
  });
69
76
 
77
+ it('names the latest release as the upgrade target when the caller sends none', async () => {
78
+ const requests = [];
79
+ globalThis.fetch = vi.fn(async (url, init) => {
80
+ requests.push({ url: String(url), body: init?.body ? JSON.parse(init.body) : null });
81
+ if (String(url).includes('registry.npmjs.org')) {
82
+ return jsonResponse({ version: '1.18.23' });
83
+ }
84
+ if (String(url).includes('api.github.com')) {
85
+ return jsonResponse({ tag_name: 'v1.18.23' });
86
+ }
87
+ return jsonResponse({ success: true, version: '1.18.23' });
88
+ });
89
+ const { app } = createApp({ getOpenCodeUpgradeCapability: () => supportedCapability });
90
+
91
+ await request(app)
92
+ .post('/api/opencode/upgrade')
93
+ .send({})
94
+ .expect(200, { success: true, version: '1.18.23', restarted: true });
95
+
96
+ const upgradeRequest = requests.find((entry) => entry.url.includes('/global/upgrade'));
97
+ expect(upgradeRequest?.body).toEqual({ target: '1.18.23' });
98
+ });
99
+
100
+ it('keeps an explicitly requested target instead of resolving the latest release', async () => {
101
+ const requests = [];
102
+ globalThis.fetch = vi.fn(async (url, init) => {
103
+ requests.push({ url: String(url), body: init?.body ? JSON.parse(init.body) : null });
104
+ return jsonResponse({ success: true, version: '1.18.20' });
105
+ });
106
+ const { app } = createApp({ getOpenCodeUpgradeCapability: () => supportedCapability });
107
+
108
+ await request(app)
109
+ .post('/api/opencode/upgrade')
110
+ .send({ target: '1.18.20' })
111
+ .expect(200);
112
+
113
+ expect(requests).toHaveLength(1);
114
+ expect(requests[0].url).toContain('/global/upgrade');
115
+ expect(requests[0].body).toEqual({ target: '1.18.20' });
116
+ });
117
+
118
+ it('fails without calling the updater when the latest release cannot be resolved', async () => {
119
+ globalThis.fetch = vi.fn(async (url) => {
120
+ if (String(url).includes('/global/upgrade')) {
121
+ throw new Error('the updater must not be called without a target');
122
+ }
123
+ return new Response('nope', { status: 503 });
124
+ });
125
+ const { app, dependencies } = createApp({ getOpenCodeUpgradeCapability: () => supportedCapability });
126
+
127
+ const response = await request(app)
128
+ .post('/api/opencode/upgrade')
129
+ .send({})
130
+ .expect(502);
131
+
132
+ expect(response.body.success).toBe(false);
133
+ expect(response.body.code).toBe('OPENCODE_UPGRADE_TARGET_UNRESOLVED');
134
+ expect(response.body.error).toContain('Could not determine which OpenCode version to install');
135
+ expect(dependencies.refreshOpenCodeAfterConfigChange).not.toHaveBeenCalled();
136
+ });
137
+
138
+ it('surfaces the rejection OpenCode reported instead of the bare HTTP status', async () => {
139
+ globalThis.fetch = vi.fn(async (url) => {
140
+ if (String(url).includes('/global/upgrade')) {
141
+ return jsonResponse(
142
+ { name: 'BadRequest', data: { message: 'Expected a semantic version', kind: 'Payload' } },
143
+ 400,
144
+ );
145
+ }
146
+ return jsonResponse({ version: '1.18.23' });
147
+ });
148
+ const { app } = createApp({ getOpenCodeUpgradeCapability: () => supportedCapability });
149
+
150
+ await request(app)
151
+ .post('/api/opencode/upgrade')
152
+ .send({})
153
+ .expect(400, { success: false, error: 'Expected a semantic version' });
154
+ });
155
+
70
156
  it('serializes supported upgrades and preserves the in-flight lock', async () => {
71
157
  let releaseUpgrade;
72
158
  const upstreamResponse = new Promise((resolve) => {
73
- releaseUpgrade = () => resolve(new Response(JSON.stringify({ success: true, version: '1.18.9' }), {
74
- status: 200,
75
- headers: { 'Content-Type': 'application/json' },
76
- }));
159
+ releaseUpgrade = () => resolve(jsonResponse({ success: true, version: '1.18.9' }));
77
160
  });
78
- globalThis.fetch = vi.fn(() => upstreamResponse);
79
- const { app, dependencies } = createApp({
80
- getOpenCodeUpgradeCapability: () => ({
81
- supported: true,
82
- manager: 'opencode',
83
- reason: null,
84
- }),
161
+ const upgradeCalls = vi.fn();
162
+ globalThis.fetch = vi.fn((url) => {
163
+ if (String(url).includes('/global/upgrade')) {
164
+ upgradeCalls();
165
+ return upstreamResponse;
166
+ }
167
+ return Promise.resolve(jsonResponse({ version: '1.18.9' }));
85
168
  });
169
+ const { app, dependencies } = createApp({ getOpenCodeUpgradeCapability: () => supportedCapability });
86
170
 
87
171
  const first = request(app)
88
172
  .post('/api/opencode/upgrade')
@@ -94,7 +178,7 @@ describe('OpenCode upgrade routes', () => {
94
178
  })
95
179
  .then((response) => response);
96
180
  await vi.waitFor(() => {
97
- expect(globalThis.fetch).toHaveBeenCalledTimes(1);
181
+ expect(upgradeCalls).toHaveBeenCalledTimes(1);
98
182
  });
99
183
 
100
184
  await request(app)