@openchamber/web 1.23.2 → 1.24.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/bin/cli.test.js +7 -6
- package/bin/lib/cli-http.js +5 -1
- package/dist/assets/{CodeMirrorCommentWidgets-DdNGwbBw.js → CodeMirrorCommentWidgets-DvUH815P.js} +1 -1
- package/dist/assets/DiffView-DkC3xlRJ.js +4 -0
- package/dist/assets/FilesView-D0bM9FVB.js +13 -0
- package/dist/assets/GitView-Bxuv3dfP.js +6 -0
- package/dist/assets/GuestAttachDialog-B0u3Q5uO.js +1 -0
- package/dist/assets/{JsonTreeView-Chzx5Y6N.js → JsonTreeView-BBVPFM5K.js} +1 -1
- package/dist/assets/LinearIssuesView-UI1FcSC8.js +1 -0
- package/dist/assets/{MarkdownImageGallery-CugnrZ6f.js → MarkdownImageGallery-CUJxH8Le.js} +1 -1
- package/dist/assets/MarkdownRendererImpl-D5BZOg8X.js +12 -0
- package/dist/assets/{OnboardingScreen-hH9xcTjA.js → OnboardingScreen-5Gou9cGD.js} +1 -1
- package/dist/assets/{PatchDiff-DRgNYc9l.js → PatchDiff-C4rE5k6z.js} +1 -1
- package/dist/assets/{PierreDiffViewer-ZT2CKuzJ.js → PierreDiffViewer-ByRVu6ss.js} +5 -5
- package/dist/assets/PlanView-u2yi5XGJ.js +5 -0
- package/dist/assets/PluginPane-QxjsKYeO.js +3 -0
- package/dist/assets/SettingsView-Fo5ZqMaT.js +29 -0
- package/dist/assets/{SettingsWindow-DisOghhD.js → SettingsWindow-HVDVANjJ.js} +1 -1
- package/dist/assets/SubmoduleDiffSummary-D3hzkybB.js +1 -0
- package/dist/assets/ToolOutputDialog-3J6IRayW.js +15 -0
- package/dist/assets/{ToolPartDiffPreview-oWxWCu-4.js → ToolPartDiffPreview-DarxPjSd.js} +2 -2
- package/dist/assets/{VirtualizedFileDiff-CiyrAq_I.js → VirtualizedFileDiff-CZgXWHjU.js} +4 -4
- package/dist/assets/{WalkthroughView-CKTevaea.js → WalkthroughView-wSpED5L4.js} +2 -2
- package/dist/assets/appThemeRegistry-Cf8KitzT.js +1 -0
- package/dist/assets/commitAndPush-DZnzlhvc.js +1 -0
- package/dist/assets/{computeVirtualFileMetrics-SUWoTyPe.js → computeVirtualFileMetrics-VYnT_A2h.js} +1 -1
- package/dist/assets/de-BM_8EDD3.js +10 -0
- package/dist/assets/es-CxZjlqpo.js +16 -0
- package/dist/assets/fr-VCixCnMW.js +14 -0
- package/dist/assets/{index-C4jJ3Ur5.js → index-3U4CtS9b.js} +1 -1
- package/dist/assets/index-B9Hvzjwl.css +1 -0
- package/dist/assets/index-DLHQogv8.js +40 -0
- package/dist/assets/{isDiffPlainText-DfG0cZxr.js → isDiffPlainText-ImDG3Uhg.js} +1 -1
- package/dist/assets/{isFilePlainText-CyNivOCU.js → isFilePlainText-D_YDVYDb.js} +1 -1
- package/dist/assets/ja-CZ5k_GyD.js +16 -0
- package/dist/assets/ko-7YM3A1Xh.js +16 -0
- package/dist/assets/{main-B8cGozKr.js → main-CycplCph.js} +2 -2
- package/dist/assets/main-DFYTCx5o.js +896 -0
- package/dist/assets/{markdown-shiki.worker-D5fBU-lw.js → markdown-shiki.worker-CahLvHIq.js} +5 -5
- package/dist/assets/markdownCore-DHvqMxPn.js +5 -0
- package/dist/assets/{miniChat-Cay99IxR.js → miniChat-DIQKfY2V.js} +2 -2
- package/dist/assets/{mobile-Zfhix7nz.js → mobile-BMwz5q-m.js} +2 -2
- package/dist/assets/{patchFileDiff-CJ5AN9Ql.js → patchFileDiff-DDQ6Rq5e.js} +3 -3
- package/dist/assets/pl-BcgDO_w5.js +16 -0
- package/dist/assets/{pt-BR-CLosVawq.js → pt-BR-CU2u_1q5.js} +4 -4
- package/dist/assets/renderElectronMiniChatApp-3_d6g6CU.js +2 -0
- package/dist/assets/renderMobileApp-D0Y8DtkA.js +25 -0
- package/dist/assets/runtimeEndpointReset-DhC3REb2.js +25 -0
- package/dist/assets/{scheduledTasksApi-CGFV4Pap.js → scheduledTasksApi-D8pq6gQz.js} +1 -1
- package/dist/assets/shikiHighlight-1imXsir9.js +1 -0
- package/dist/assets/textMateThemeFromAppTheme-Dgqc63LZ.js +1 -0
- package/dist/assets/tr-DuYhOzNe.js +7 -0
- package/dist/assets/uk-Cuk7-uvq.js +16 -0
- package/dist/assets/useAppFontEffects-BItUWdo4.js +7333 -0
- package/dist/assets/useInlineCommentController-CkbKsm7m.js +2 -0
- package/dist/assets/useRootScrollLock-vmzxZjWA.js +2 -0
- package/dist/assets/{vendor-base-ui-BY_5qla_.js → vendor-base-ui-CsXYnR5c.js} +1 -1
- package/dist/assets/{vendor-codemirror-language-data-ES33GhKK.js → vendor-codemirror-language-data-BDyxuqK4.js} +2 -2
- package/dist/assets/vendor-framer-motion-Bq3iTZ6r.js +1 -0
- package/dist/assets/{vendor-motion-dom-D_o3BTI3.js → vendor-motion-dom-DcCgeG69.js} +1 -1
- package/dist/assets/vendor-strip-json-comments-5dJlOkP1.js +4 -0
- package/dist/assets/{vendor-tanstack-react-virtual-g05Cx3z9.js → vendor-tanstack-react-virtual-ClYN8CzB.js} +1 -1
- package/dist/assets/{vendor-tanstack-virtual-core-Dubg10g5.js → vendor-tanstack-virtual-core-BewVQryB.js} +1 -1
- package/dist/assets/{vendor-zod-B6551dwG.js → vendor-zod-fZppILAM.js} +4 -4
- package/dist/assets/{web-components-CJZwV5BE.js → web-components-D7FinaeH.js} +2 -2
- package/dist/assets/zh-CN-CUWoiRHd.js +16 -0
- package/dist/assets/zh-TW-CQ8EBSBN.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 +9 -6
- package/server/built-in-extensions/registry.json +4 -0
- package/server/index.d.ts +2 -0
- package/server/index.js +41 -10
- package/server/lib/changelog/update-notes.js +2 -1
- package/server/lib/changelog/update-notes.test.js +19 -0
- package/server/lib/event-stream/DOCUMENTATION.md +23 -0
- package/server/lib/event-stream/delta-coalescer.js +0 -0
- package/server/lib/event-stream/delta-coalescer.test.js +292 -0
- package/server/lib/event-stream/global-hub.js +53 -23
- package/server/lib/event-stream/global-hub.test.js +160 -0
- package/server/lib/event-stream/global-ws-bridge.js +1 -0
- package/server/lib/event-stream/index.js +4 -0
- package/server/lib/fs/DOCUMENTATION.md +8 -0
- package/server/lib/fs/git-process.test.js +77 -0
- package/server/lib/fs/routes.js +2 -1
- package/server/lib/fs/search.js +2 -1
- package/server/lib/git/DOCUMENTATION.md +19 -4
- package/server/lib/git/routes.js +16 -3
- package/server/lib/git/serial-refresh.js +93 -0
- package/server/lib/git/serial-refresh.test.js +112 -0
- package/server/lib/git/service.js +336 -62
- package/server/lib/git/service.test.js +400 -0
- package/server/lib/github/pr-status.js +5 -5
- package/server/lib/github/pr-status.test.js +1 -1
- package/server/lib/github/routes.js +4 -4
- package/server/lib/guests/DOCUMENTATION.md +68 -0
- package/server/lib/guests/auth-store.js +184 -0
- package/server/lib/guests/auth-store.test.js +112 -0
- package/server/lib/guests/background.test.js +83 -0
- package/server/lib/guests/builtins.js +34 -0
- package/server/lib/guests/builtins.test.js +174 -0
- package/server/lib/guests/catalog.js +477 -0
- package/server/lib/guests/catalog.test.js +390 -0
- package/server/lib/guests/clone.js +297 -0
- package/server/lib/guests/extract-zip.js +136 -0
- package/server/lib/guests/extract-zip.test.js +109 -0
- package/server/lib/guests/files.js +308 -0
- package/server/lib/guests/files.test.js +262 -0
- package/server/lib/guests/grant-scope.js +81 -0
- package/server/lib/guests/grant-scope.test.js +75 -0
- package/server/lib/guests/host-session.js +73 -0
- package/server/lib/guests/host-session.test.js +30 -0
- package/server/lib/guests/html-styles.js +6 -0
- package/server/lib/guests/html-styles.test.js +45 -0
- package/server/lib/guests/html-tokens.js +73 -0
- package/server/lib/guests/html-tokens.test.js +53 -0
- package/server/lib/guests/install.js +406 -0
- package/server/lib/guests/install.test.js +338 -0
- package/server/lib/guests/oauth.js +501 -0
- package/server/lib/guests/oauth.test.js +481 -0
- package/server/lib/guests/persist.js +336 -0
- package/server/lib/guests/persist.test.js +288 -0
- package/server/lib/guests/request.js +112 -0
- package/server/lib/guests/request.test.js +206 -0
- package/server/lib/guests/routes.js +838 -0
- package/server/lib/guests/service.js +538 -0
- package/server/lib/guests/service.test.js +277 -0
- package/server/lib/guests/sockets.js +129 -0
- package/server/lib/guests/sockets.test.js +110 -0
- package/server/lib/guests/ssh-install.test.js +188 -0
- package/server/lib/guests/storage.js +68 -0
- package/server/lib/guests/storage.test.js +59 -0
- package/server/lib/guests/updates.js +294 -0
- package/server/lib/guests/updates.test.js +334 -0
- package/server/lib/guests/upload.js +50 -0
- package/server/lib/guests/upload.test.js +131 -0
- package/server/lib/linear/DOCUMENTATION.md +1 -1
- package/server/lib/message-queue/DOCUMENTATION.md +6 -0
- package/server/lib/message-queue/runtime.js +5 -0
- package/server/lib/message-queue/runtime.test.js +32 -1
- package/server/lib/openchamber-control/DOCUMENTATION.md +6 -0
- package/server/lib/openchamber-sessions/routes.js +44 -11
- package/server/lib/openchamber-sessions/routes.test.js +47 -0
- package/server/lib/opencode/DOCUMENTATION.md +40 -0
- package/server/lib/opencode/core-routes.js +39 -1
- package/server/lib/opencode/feature-routes-runtime.js +15 -0
- package/server/lib/opencode/lifecycle-process.test.js +84 -0
- package/server/lib/opencode/lifecycle.js +54 -67
- package/server/lib/opencode/settings-helpers.js +3 -0
- package/server/lib/opencode/settings-normalization-runtime.js +2 -0
- package/server/lib/opencode/settings-normalization-runtime.test.js +13 -0
- package/server/lib/opencode/settings-registry.json +12 -0
- package/server/lib/opencode/shutdown-runtime.js +3 -0
- package/server/lib/opencode/shutdown-runtime.test.js +24 -0
- package/server/lib/opencode/theme-archive.js +53 -0
- package/server/lib/opencode/theme-catalog.js +171 -0
- package/server/lib/opencode/theme-catalog.test.js +125 -0
- package/server/lib/opencode/theme-import.test.js +144 -0
- package/server/lib/opencode/theme-runtime.js +100 -28
- package/server/lib/opencode/theme-runtime.test.js +15 -0
- package/server/lib/permission-auto-accept/DOCUMENTATION.md +8 -0
- package/server/lib/permission-auto-accept/runtime.js +13 -0
- package/server/lib/permission-auto-accept/runtime.test.js +37 -1
- package/server/lib/quota/DOCUMENTATION.md +0 -1
- package/server/lib/quota/providers/index.js +0 -7
- package/server/lib/routing/DOCUMENTATION.md +81 -0
- package/server/lib/routing/defaults.js +98 -0
- package/server/lib/routing/feature-flag.js +11 -0
- package/server/lib/routing/history.js +34 -0
- package/server/lib/routing/jev.js +98 -0
- package/server/lib/routing/routes.http.test.js +100 -0
- package/server/lib/routing/routes.js +81 -0
- package/server/lib/routing/runtime.js +217 -0
- package/server/lib/routing/runtime.test.js +188 -0
- package/server/lib/routing/store.js +249 -0
- package/server/lib/routing/store.test.js +96 -0
- package/server/lib/security/request-security.js +9 -5
- package/server/lib/security/request-security.test.js +37 -0
- package/server/lib/terminal/DOCUMENTATION.md +2 -0
- package/server/lib/terminal/runtime.js +17 -2
- package/server/lib/terminal/runtime.test.js +45 -0
- package/server/lib/ui-auth/DOCUMENTATION.md +8 -0
- package/server/lib/ui-auth/session-cookie.js +51 -0
- package/server/lib/ui-auth/session-cookie.test.js +46 -0
- package/server/lib/ui-auth/ui-auth.js +56 -17
- package/server/lib/ui-auth/ui-auth.test.js +96 -0
- package/dist/assets/DiffView-GYriC0Wk.js +0 -4
- package/dist/assets/DirtyBranchSwitchDialog-Bv0C99hc.js +0 -1
- package/dist/assets/FilesView-2Lin13wx.js +0 -13
- package/dist/assets/GitView-9wKba3UO.js +0 -6
- package/dist/assets/LinearIssuesView-DXS9QJiR.js +0 -1
- package/dist/assets/MarkdownRendererImpl-CaMyct2Q.js +0 -12
- package/dist/assets/PlanView-DiTBm2BD.js +0 -5
- package/dist/assets/SettingsView-CN8VeM99.js +0 -28
- package/dist/assets/ToolOutputDialog-BqiKydxR.js +0 -15
- package/dist/assets/appThemeRegistry-BK0dHKa6.js +0 -1
- package/dist/assets/de-DQWC94VK.js +0 -10
- package/dist/assets/es-DixFUD3m.js +0 -16
- package/dist/assets/fr-D6u8tvfA.js +0 -14
- package/dist/assets/index-BvpFzhLs.js +0 -40
- package/dist/assets/index-n5p3SnES.css +0 -1
- package/dist/assets/ja-4u4pCorB.js +0 -16
- package/dist/assets/ko-C27-LW_b.js +0 -16
- package/dist/assets/main-tEA-fFPg.js +0 -930
- package/dist/assets/markdownCore-kyGrWGsn.js +0 -5
- package/dist/assets/pl-FtCjsNdW.js +0 -16
- package/dist/assets/registerCustomTheme-BBXUCRnG.js +0 -1
- package/dist/assets/renderElectronMiniChatApp-CuHOGlF4.js +0 -2
- package/dist/assets/renderMobileApp-C4X_KUH8.js +0 -25
- package/dist/assets/runtimeEndpointReset-CMg-KUx3.js +0 -41
- package/dist/assets/shikiHighlight-DdKWYWrV.js +0 -1
- package/dist/assets/tr-D2j6wUez.js +0 -7
- package/dist/assets/uk-C6IzmwM_.js +0 -16
- package/dist/assets/useAppFontEffects-DgCHy6Mr.js +0 -7282
- package/dist/assets/useGitComparison-BIaI0WZI.js +0 -1
- package/dist/assets/useInlineCommentController-2wcCtpM3.js +0 -2
- package/dist/assets/useRootScrollLock-CbWA03xR.js +0 -1
- package/dist/assets/vendor-framer-motion-livSKyyV.js +0 -1
- package/dist/assets/zh-CN-Wl6tIDz1.js +0 -16
- package/dist/assets/zh-TW-hgphoWSN.js +0 -16
- package/server/lib/quota/providers/crof.js +0 -96
- package/server/lib/quota/providers/crof.test.js +0 -98
|
@@ -109,6 +109,7 @@ export const createOpenCodeLifecycleRuntime = (deps) => {
|
|
|
109
109
|
reapManagedOrphanedProcesses = reapOrphanedProcesses,
|
|
110
110
|
getWarmupDirectories = async () => [],
|
|
111
111
|
onOpenCodeRestarted = null,
|
|
112
|
+
managedStartupTimeoutMs = 30_000,
|
|
112
113
|
now = Date.now,
|
|
113
114
|
} = deps;
|
|
114
115
|
|
|
@@ -287,7 +288,7 @@ export const createOpenCodeLifecycleRuntime = (deps) => {
|
|
|
287
288
|
}
|
|
288
289
|
|
|
289
290
|
const pid = child.pid;
|
|
290
|
-
if (!pid || hasChildProcessExited(child)) {
|
|
291
|
+
if (!pid || (process.platform === 'win32' && hasChildProcessExited(child))) {
|
|
291
292
|
await waitForChildProcessClose(child, 250);
|
|
292
293
|
return;
|
|
293
294
|
}
|
|
@@ -301,34 +302,14 @@ export const createOpenCodeLifecycleRuntime = (deps) => {
|
|
|
301
302
|
}
|
|
302
303
|
|
|
303
304
|
try {
|
|
304
|
-
child.kill(signal);
|
|
305
|
+
if (!hasChildProcessExited(child)) child.kill(signal);
|
|
305
306
|
} catch {
|
|
306
307
|
}
|
|
307
308
|
};
|
|
308
309
|
|
|
309
310
|
if (process.platform === 'win32') {
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
} catch {
|
|
313
|
-
}
|
|
314
|
-
|
|
315
|
-
if (await waitForChildProcessClose(child, 800)) {
|
|
316
|
-
return;
|
|
317
|
-
}
|
|
318
|
-
|
|
319
|
-
try {
|
|
320
|
-
spawnSync('taskkill', ['/pid', String(pid), '/t'], {
|
|
321
|
-
stdio: 'ignore',
|
|
322
|
-
timeout: 3000,
|
|
323
|
-
windowsHide: true,
|
|
324
|
-
});
|
|
325
|
-
} catch {
|
|
326
|
-
}
|
|
327
|
-
|
|
328
|
-
if (await waitForChildProcessClose(child, 1500)) {
|
|
329
|
-
return;
|
|
330
|
-
}
|
|
331
|
-
|
|
311
|
+
// Windows child.kill() terminates only the parent. Kill the owned tree
|
|
312
|
+
// while its parent still exists, otherwise /T cannot find its children.
|
|
332
313
|
try {
|
|
333
314
|
spawnSync('taskkill', ['/pid', String(pid), '/f', '/t'], {
|
|
334
315
|
stdio: 'ignore',
|
|
@@ -343,11 +324,9 @@ export const createOpenCodeLifecycleRuntime = (deps) => {
|
|
|
343
324
|
}
|
|
344
325
|
|
|
345
326
|
signalProcessTree('SIGTERM');
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
}
|
|
350
|
-
|
|
327
|
+
await waitForChildProcessClose(child, 2500);
|
|
328
|
+
// Parent exit does not prove group exit. Tools can ignore SIGTERM and keep
|
|
329
|
+
// running after their server has exited and closed its own stdio.
|
|
351
330
|
signalProcessTree('SIGKILL');
|
|
352
331
|
|
|
353
332
|
await waitForChildProcessClose(child, 1000);
|
|
@@ -452,7 +431,29 @@ export const createOpenCodeLifecycleRuntime = (deps) => {
|
|
|
452
431
|
child.on('exit', recordManagedProcessExit);
|
|
453
432
|
child.on('close', recordManagedProcessExit);
|
|
454
433
|
|
|
455
|
-
|
|
434
|
+
// Ownership starts at spawn, including processes that never become ready.
|
|
435
|
+
const registration = registerManagedProcess({
|
|
436
|
+
pid: child.pid,
|
|
437
|
+
ownerPid: process.pid,
|
|
438
|
+
port,
|
|
439
|
+
binary,
|
|
440
|
+
runtime: process.env.OPENCHAMBER_RUNTIME || 'web',
|
|
441
|
+
});
|
|
442
|
+
|
|
443
|
+
let closePromise = null;
|
|
444
|
+
const serverProcess = {
|
|
445
|
+
url: null,
|
|
446
|
+
pid: child.pid || null,
|
|
447
|
+
get exitCode() { return observedExitCode ?? child.exitCode; },
|
|
448
|
+
get signalCode() { return observedSignalCode ?? child.signalCode; },
|
|
449
|
+
get stderrTail() { return getManagedProcessSnapshot().stderrTail; },
|
|
450
|
+
close() {
|
|
451
|
+
if (!closePromise) closePromise = registration.then(() => closeManagedOpenCodeChild(child));
|
|
452
|
+
return closePromise;
|
|
453
|
+
},
|
|
454
|
+
};
|
|
455
|
+
|
|
456
|
+
const readiness = new Promise((resolve, reject) => {
|
|
456
457
|
let stdout = '';
|
|
457
458
|
let stderr = '';
|
|
458
459
|
let done = false;
|
|
@@ -507,37 +508,21 @@ export const createOpenCodeLifecycleRuntime = (deps) => {
|
|
|
507
508
|
child.stderr?.on('data', onStderr);
|
|
508
509
|
child.on('exit', onExit);
|
|
509
510
|
child.on('error', onError);
|
|
511
|
+
}).catch(async (error) => {
|
|
512
|
+
await serverProcess.close();
|
|
513
|
+
if (state.openCodeProcess === serverProcess) {
|
|
514
|
+
state.openCodeProcess = null;
|
|
515
|
+
syncToHmrState();
|
|
516
|
+
}
|
|
517
|
+
throw error;
|
|
510
518
|
});
|
|
511
519
|
|
|
512
|
-
//
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
pid: child.pid,
|
|
519
|
-
ownerPid: process.pid,
|
|
520
|
-
port,
|
|
521
|
-
binary,
|
|
522
|
-
runtime: process.env.OPENCHAMBER_RUNTIME || 'web',
|
|
523
|
-
});
|
|
524
|
-
|
|
525
|
-
return {
|
|
526
|
-
url,
|
|
527
|
-
pid: child.pid || null,
|
|
528
|
-
get exitCode() {
|
|
529
|
-
return observedExitCode ?? child.exitCode;
|
|
530
|
-
},
|
|
531
|
-
get signalCode() {
|
|
532
|
-
return observedSignalCode ?? child.signalCode;
|
|
533
|
-
},
|
|
534
|
-
get stderrTail() {
|
|
535
|
-
return getManagedProcessSnapshot().stderrTail;
|
|
536
|
-
},
|
|
537
|
-
async close() {
|
|
538
|
-
await closeManagedOpenCodeChild(child);
|
|
539
|
-
},
|
|
540
|
-
};
|
|
520
|
+
// Shutdown must be able to close an in-flight startup, not only a ready server.
|
|
521
|
+
state.openCodeProcess = serverProcess;
|
|
522
|
+
syncToHmrState();
|
|
523
|
+
serverProcess.url = await readiness;
|
|
524
|
+
await registration;
|
|
525
|
+
return serverProcess;
|
|
541
526
|
};
|
|
542
527
|
|
|
543
528
|
const resolveManagedOpenCodePort = async (requestedPort, hostname = '127.0.0.1') => {
|
|
@@ -719,12 +704,14 @@ export const createOpenCodeLifecycleRuntime = (deps) => {
|
|
|
719
704
|
});
|
|
720
705
|
phaseStartedAt = performance.now();
|
|
721
706
|
|
|
707
|
+
let serverInstance;
|
|
722
708
|
try {
|
|
723
|
-
|
|
709
|
+
if (state.isShuttingDown) throw new Error('OpenCode startup cancelled during shutdown');
|
|
710
|
+
serverInstance = await createManagedOpenCodeServerProcess({
|
|
724
711
|
resolvedBinary,
|
|
725
712
|
hostname: env.ENV_CONFIGURED_OPENCODE_HOSTNAME,
|
|
726
713
|
port: spawnPort,
|
|
727
|
-
timeout:
|
|
714
|
+
timeout: managedStartupTimeoutMs,
|
|
728
715
|
cwd: state.openCodeWorkingDirectory,
|
|
729
716
|
shellEnvKeysCount: Object.keys(shellEnv).length,
|
|
730
717
|
env: stripAppImageArgv0Leak(applyProviderEnvAliases({
|
|
@@ -750,7 +737,9 @@ export const createOpenCodeLifecycleRuntime = (deps) => {
|
|
|
750
737
|
const port = parseInt(url.port, 10);
|
|
751
738
|
const prefix = normalizeApiPrefix(url.pathname);
|
|
752
739
|
|
|
753
|
-
|
|
740
|
+
const ready = await waitForReady(serverInstance.url, 10000);
|
|
741
|
+
if (state.isShuttingDown) throw new Error('OpenCode startup cancelled during shutdown');
|
|
742
|
+
if (ready) {
|
|
754
743
|
setOpenCodePort(port);
|
|
755
744
|
setDetectedOpenCodeApiPrefix(prefix);
|
|
756
745
|
|
|
@@ -768,12 +757,10 @@ export const createOpenCodeLifecycleRuntime = (deps) => {
|
|
|
768
757
|
return serverInstance;
|
|
769
758
|
}
|
|
770
759
|
|
|
771
|
-
try {
|
|
772
|
-
await serverInstance.close();
|
|
773
|
-
} catch {
|
|
774
|
-
}
|
|
775
760
|
throw new Error('Server started but health check failed (timeout)');
|
|
776
761
|
} catch (error) {
|
|
762
|
+
await serverInstance?.close();
|
|
763
|
+
if (serverInstance && state.openCodeProcess === serverInstance) state.openCodeProcess = null;
|
|
777
764
|
const message = error instanceof Error ? error.message : String(error);
|
|
778
765
|
state.lastOpenCodeError = message;
|
|
779
766
|
state.openCodePort = null;
|
|
@@ -795,7 +782,7 @@ export const createOpenCodeLifecycleRuntime = (deps) => {
|
|
|
795
782
|
return await startOpenCodeOnce(attempt);
|
|
796
783
|
} catch (error) {
|
|
797
784
|
lastError = error;
|
|
798
|
-
if (error?.code === 'OPENCODE_BINARY_INVALID') {
|
|
785
|
+
if (state.isShuttingDown || error?.code === 'OPENCODE_BINARY_INVALID') {
|
|
799
786
|
break;
|
|
800
787
|
}
|
|
801
788
|
if (attempt >= START_OPEN_CODE_MAX_ATTEMPTS) {
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { createRequire } from 'node:module';
|
|
2
2
|
|
|
3
3
|
import { isAgentMemoryFeatureAvailable } from '../agent-memory/feature-flag.js';
|
|
4
|
+
import { isRoutingFeatureAvailable } from '../routing/feature-flag.js';
|
|
4
5
|
|
|
5
6
|
// Generated from packages/ui/src/lib/settings/registry.ts by
|
|
6
7
|
// `bun run settings-registry:generate`; `registry.test.ts` fails when stale.
|
|
@@ -1013,6 +1014,8 @@ export const createSettingsHelpers = (dependencies) => {
|
|
|
1013
1014
|
// Tells the client whether agent memory exists in this build at all, so
|
|
1014
1015
|
// its settings row and panel tab can be absent rather than merely off.
|
|
1015
1016
|
agentMemoryFeatureAvailable: isAgentMemoryFeatureAvailable(),
|
|
1017
|
+
// Same idea for Jev routing: absent from the picker and Settings unless the build has it.
|
|
1018
|
+
routingFeatureAvailable: isRoutingFeatureAvailable(),
|
|
1016
1019
|
...(pwaAppName ? { pwaAppName } : {}),
|
|
1017
1020
|
pwaOrientation,
|
|
1018
1021
|
mobileKeyboardMode,
|
|
@@ -154,6 +154,7 @@ export const createSettingsNormalizationRuntime = (dependencies) => {
|
|
|
154
154
|
: null;
|
|
155
155
|
const iconBackground = normalizeIconBackground(candidate.iconBackground);
|
|
156
156
|
const color = typeof candidate.color === 'string' ? candidate.color.trim() : '';
|
|
157
|
+
const defaultAgent = typeof candidate.defaultAgent === 'string' ? candidate.defaultAgent.trim() : '';
|
|
157
158
|
const defaultModel = typeof candidate.defaultModel === 'string' ? candidate.defaultModel.trim() : '';
|
|
158
159
|
const defaultVariant = typeof candidate.defaultVariant === 'string' ? candidate.defaultVariant.trim() : '';
|
|
159
160
|
const addedAt = Number.isFinite(candidate.addedAt) ? Number(candidate.addedAt) : null;
|
|
@@ -175,6 +176,7 @@ export const createSettingsNormalizationRuntime = (dependencies) => {
|
|
|
175
176
|
...(icon ? { icon } : {}),
|
|
176
177
|
...(iconBackground ? { iconBackground } : {}),
|
|
177
178
|
...(color ? { color } : {}),
|
|
179
|
+
...(defaultAgent ? { defaultAgent } : {}),
|
|
178
180
|
...(defaultModel && defaultModel.includes('/') ? { defaultModel } : {}),
|
|
179
181
|
// A variant is meaningless without the model it belongs to.
|
|
180
182
|
...(defaultModel && defaultModel.includes('/') && defaultVariant ? { defaultVariant } : {}),
|
|
@@ -122,6 +122,19 @@ describe('settings normalization runtime - symlink resolution', () => {
|
|
|
122
122
|
expect(result[1].defaultVariant).toBe(undefined);
|
|
123
123
|
});
|
|
124
124
|
|
|
125
|
+
it('keeps a project default agent', () => {
|
|
126
|
+
const runtime = createTestRuntime({
|
|
127
|
+
realpathSync: (p) => p,
|
|
128
|
+
path: { resolve: (p) => p, sep: '/', dirname: (p) => p.split('/').slice(0, -1).join('/') || '/' },
|
|
129
|
+
});
|
|
130
|
+
|
|
131
|
+
const result = runtime.sanitizeProjects([
|
|
132
|
+
{ id: 'proj1', path: '/a', defaultAgent: 'plan' },
|
|
133
|
+
]);
|
|
134
|
+
|
|
135
|
+
expect(result[0].defaultAgent).toBe('plan');
|
|
136
|
+
});
|
|
137
|
+
|
|
125
138
|
it('deduplicates projects that resolve to the same realpath', () => {
|
|
126
139
|
const runtime = createTestRuntime({
|
|
127
140
|
realpathSync: (p) => p.startsWith('/symlink') ? '/real/project' : p,
|
|
@@ -127,6 +127,10 @@
|
|
|
127
127
|
"scope": "instance",
|
|
128
128
|
"computed": true
|
|
129
129
|
},
|
|
130
|
+
"routingFeatureAvailable": {
|
|
131
|
+
"scope": "instance",
|
|
132
|
+
"computed": true
|
|
133
|
+
},
|
|
130
134
|
"openCodeUpdateToastDismissedVersion": {
|
|
131
135
|
"scope": "instance"
|
|
132
136
|
},
|
|
@@ -608,6 +612,10 @@
|
|
|
608
612
|
"scope": "device",
|
|
609
613
|
"local": true
|
|
610
614
|
},
|
|
615
|
+
"contextEditorVisible": {
|
|
616
|
+
"scope": "device",
|
|
617
|
+
"local": true
|
|
618
|
+
},
|
|
611
619
|
"contextEditorTreeWidth": {
|
|
612
620
|
"scope": "device",
|
|
613
621
|
"local": true
|
|
@@ -620,6 +628,10 @@
|
|
|
620
628
|
"scope": "device",
|
|
621
629
|
"local": true
|
|
622
630
|
},
|
|
631
|
+
"messageQueueExpanded": {
|
|
632
|
+
"scope": "device",
|
|
633
|
+
"local": true
|
|
634
|
+
},
|
|
623
635
|
"workStatusScrollTop": {
|
|
624
636
|
"scope": "device",
|
|
625
637
|
"local": true
|
|
@@ -108,6 +108,9 @@ export const createGracefulShutdownRuntime = (dependencies) => {
|
|
|
108
108
|
console.log('HTTP server closed');
|
|
109
109
|
resolve();
|
|
110
110
|
});
|
|
111
|
+
// The backend has stopped. Active SSE/HTTP clients must not keep
|
|
112
|
+
// Desktop waiting for the outer shutdown deadline.
|
|
113
|
+
server.closeAllConnections?.();
|
|
111
114
|
}),
|
|
112
115
|
new Promise((resolve) => {
|
|
113
116
|
closeTimeout = setTimeout(() => {
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { afterEach, describe, expect, it, vi } from 'vitest';
|
|
2
|
+
import http from 'node:http';
|
|
2
3
|
|
|
3
4
|
import { createGracefulShutdownRuntime } from './shutdown-runtime.js';
|
|
4
5
|
|
|
@@ -55,4 +56,27 @@ describe('graceful shutdown runtime', () => {
|
|
|
55
56
|
expect(warnSpy).not.toHaveBeenCalledWith('Server close timeout reached, forcing shutdown');
|
|
56
57
|
expect(vi.getTimerCount()).toBe(0);
|
|
57
58
|
});
|
|
59
|
+
|
|
60
|
+
it('closes an active HTTP stream instead of waiting for the shutdown deadline', async () => {
|
|
61
|
+
const server = http.createServer((_request, response) => {
|
|
62
|
+
response.writeHead(200, { 'content-type': 'text/event-stream' });
|
|
63
|
+
response.write('data: fixture\n\n');
|
|
64
|
+
});
|
|
65
|
+
await new Promise((resolve) => server.listen(0, '127.0.0.1', resolve));
|
|
66
|
+
const request = http.get(`http://127.0.0.1:${server.address().port}`);
|
|
67
|
+
request.on('error', () => {});
|
|
68
|
+
const response = await new Promise((resolve) => request.once('response', resolve));
|
|
69
|
+
response.resume();
|
|
70
|
+
const closed = new Promise((resolve) => response.once('close', resolve));
|
|
71
|
+
const warning = vi.spyOn(console, 'warn').mockImplementation(() => {});
|
|
72
|
+
try {
|
|
73
|
+
await createRuntime(server).gracefulShutdown({ exitProcess: false });
|
|
74
|
+
expect(warning).not.toHaveBeenCalledWith('Server close timeout reached, forcing shutdown');
|
|
75
|
+
await closed;
|
|
76
|
+
} finally {
|
|
77
|
+
request.destroy();
|
|
78
|
+
server.closeAllConnections();
|
|
79
|
+
await new Promise((resolve) => server.close(resolve));
|
|
80
|
+
}
|
|
81
|
+
});
|
|
58
82
|
});
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { inflateRaw } from 'node:zlib';
|
|
2
|
+
import { promisify } from 'node:util';
|
|
3
|
+
|
|
4
|
+
const inflate = promisify(inflateRaw);
|
|
5
|
+
const MAX_FILE_BYTES = 512 * 1024;
|
|
6
|
+
|
|
7
|
+
// Read only selected JSON entries in memory. Nothing from a VSIX is executed or
|
|
8
|
+
// extracted onto the host filesystem.
|
|
9
|
+
export function openThemeArchive(bytes) {
|
|
10
|
+
let end = bytes.length - 22;
|
|
11
|
+
const lower = Math.max(0, end - 65535);
|
|
12
|
+
while (end >= lower && (bytes.readUInt32LE(end) !== 0x06054b50 || end + 22 + bytes.readUInt16LE(end + 20) !== bytes.length)) end--;
|
|
13
|
+
if (end < lower) throw new Error('Invalid VSIX directory');
|
|
14
|
+
const count = bytes.readUInt16LE(end + 10);
|
|
15
|
+
const directorySize = bytes.readUInt32LE(end + 12);
|
|
16
|
+
let cursor = bytes.readUInt32LE(end + 16);
|
|
17
|
+
if (count > 5000 || bytes.readUInt16LE(end + 4) || bytes.readUInt16LE(end + 6)
|
|
18
|
+
|| bytes.readUInt16LE(end + 8) !== count || cursor + directorySize !== end) throw new Error('Unsupported VSIX directory');
|
|
19
|
+
const entries = new Map();
|
|
20
|
+
let totalSize = 0;
|
|
21
|
+
for (let index = 0; index < count; index++) {
|
|
22
|
+
if (cursor + 46 > end || bytes.readUInt32LE(cursor) !== 0x02014b50) throw new Error('Invalid VSIX entry');
|
|
23
|
+
const flags = bytes.readUInt16LE(cursor + 8);
|
|
24
|
+
const method = bytes.readUInt16LE(cursor + 10);
|
|
25
|
+
const compressed = bytes.readUInt32LE(cursor + 20);
|
|
26
|
+
const size = bytes.readUInt32LE(cursor + 24);
|
|
27
|
+
const nameLength = bytes.readUInt16LE(cursor + 28);
|
|
28
|
+
const next = cursor + 46 + nameLength + bytes.readUInt16LE(cursor + 30) + bytes.readUInt16LE(cursor + 32);
|
|
29
|
+
const offset = bytes.readUInt32LE(cursor + 42);
|
|
30
|
+
if (next > end || nameLength > 1024 || flags & 1 || ![0, 8].includes(method)) throw new Error('Unsupported VSIX entry');
|
|
31
|
+
const name = bytes.toString('utf8', cursor + 46, cursor + 46 + nameLength);
|
|
32
|
+
const parts = name.replace(/\/$/, '').split('/');
|
|
33
|
+
if (parts.some((part) => !part || part === '.' || part === '..') || /[\\\0:]/.test(name) || entries.has(name)) throw new Error('Unsafe VSIX path');
|
|
34
|
+
totalSize += size;
|
|
35
|
+
if (totalSize > 100 * 1024 * 1024) throw new Error('VSIX contents too large');
|
|
36
|
+
entries.set(name, { offset, compressed, size, method });
|
|
37
|
+
cursor = next;
|
|
38
|
+
}
|
|
39
|
+
if (cursor !== end) throw new Error('Invalid VSIX directory size');
|
|
40
|
+
return async (name) => {
|
|
41
|
+
const entry = entries.get(name);
|
|
42
|
+
if (!entry || entry.size > MAX_FILE_BYTES) throw new Error('Theme file missing or too large');
|
|
43
|
+
const { offset, compressed, size, method } = entry;
|
|
44
|
+
if (offset + 30 > bytes.length || bytes.readUInt32LE(offset) !== 0x04034b50 || bytes.readUInt16LE(offset + 8) !== method) throw new Error('Invalid VSIX file');
|
|
45
|
+
const nameLength = bytes.readUInt16LE(offset + 26);
|
|
46
|
+
const start = offset + 30 + nameLength + bytes.readUInt16LE(offset + 28);
|
|
47
|
+
if (start + compressed > bytes.length || bytes.toString('utf8', offset + 30, offset + 30 + nameLength) !== name) throw new Error('Invalid VSIX file bounds');
|
|
48
|
+
const data = bytes.subarray(start, start + compressed);
|
|
49
|
+
const result = method === 0 ? data : await inflate(data, { maxOutputLength: MAX_FILE_BYTES });
|
|
50
|
+
if (result.length !== size) throw new Error('Invalid VSIX file size');
|
|
51
|
+
return result.toString('utf8');
|
|
52
|
+
};
|
|
53
|
+
}
|
|
@@ -0,0 +1,171 @@
|
|
|
1
|
+
import path from 'node:path';
|
|
2
|
+
import { createHash } from 'node:crypto';
|
|
3
|
+
import { parse } from 'jsonc-parser';
|
|
4
|
+
import { z } from 'zod';
|
|
5
|
+
import { openThemeArchive } from './theme-archive.js';
|
|
6
|
+
|
|
7
|
+
const identifier = z.string().min(1).max(160).regex(/^[\w-]+$/);
|
|
8
|
+
const version = z.string().min(1).max(80).regex(/^[\w.+-]+$/);
|
|
9
|
+
const settings = z.object({ foreground: z.string().optional() });
|
|
10
|
+
const tokenRules = z.array(z.object({ scope: z.union([z.string(), z.array(z.string())]).optional(), settings }));
|
|
11
|
+
const sourceSchema = z.object({
|
|
12
|
+
name: z.string().optional(), type: z.string().optional(), include: z.string().optional(),
|
|
13
|
+
colors: z.record(z.string(), z.string().nullable()).default({}),
|
|
14
|
+
tokenColors: z.union([z.string(), tokenRules]).optional(),
|
|
15
|
+
semanticHighlighting: z.boolean().optional(),
|
|
16
|
+
semanticTokenColors: z.record(z.string(), z.union([z.string(), settings])).optional(),
|
|
17
|
+
});
|
|
18
|
+
const extensionSchema = z.object({
|
|
19
|
+
namespace: identifier, name: identifier, version,
|
|
20
|
+
displayName: z.string().optional(), files: z.object({ icon: z.string().optional() }),
|
|
21
|
+
});
|
|
22
|
+
const detailSchema = extensionSchema.extend({ files: z.object({ download: z.string(), sha256: z.string() }) });
|
|
23
|
+
const manifestSchema = z.object({
|
|
24
|
+
publisher: identifier, name: identifier, version,
|
|
25
|
+
contributes: z.object({ themes: z.array(z.object({
|
|
26
|
+
label: z.string().min(1).max(160), path: z.string().min(1).max(1024),
|
|
27
|
+
uiTheme: z.enum(['vs', 'vs-dark', 'hc-black', 'hc-light']).optional(),
|
|
28
|
+
})).min(1).max(40) }),
|
|
29
|
+
});
|
|
30
|
+
const querySchema = z.object({ query: z.string().trim().min(1).max(160) });
|
|
31
|
+
const packageSchema = z.object({ namespace: identifier, name: identifier, version });
|
|
32
|
+
const hosts = new Set(['open-vsx.org', 'openvsx.eclipsecontent.org']);
|
|
33
|
+
|
|
34
|
+
function trustedUrl(value) {
|
|
35
|
+
const url = new URL(value);
|
|
36
|
+
if (url.protocol !== 'https:' || !hosts.has(url.hostname) || url.port || url.username || url.password) throw new Error('Unexpected catalog host');
|
|
37
|
+
return url;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
async function download(url, maxBytes, signal, fetchImpl) {
|
|
41
|
+
for (let redirects = 0; redirects < 4; redirects++) {
|
|
42
|
+
const response = await fetchImpl(trustedUrl(url), { signal, redirect: 'manual' });
|
|
43
|
+
if ([301, 302, 303, 307, 308].includes(response.status)) {
|
|
44
|
+
await response.body?.cancel();
|
|
45
|
+
url = new URL(response.headers.get('location') ?? '', url).href;
|
|
46
|
+
continue;
|
|
47
|
+
}
|
|
48
|
+
if (!response.ok || !response.body || Number(response.headers.get('content-length')) > maxBytes) {
|
|
49
|
+
await response.body?.cancel();
|
|
50
|
+
throw new Error('Catalog request failed');
|
|
51
|
+
}
|
|
52
|
+
const reader = response.body.getReader();
|
|
53
|
+
const chunks = [];
|
|
54
|
+
let length = 0;
|
|
55
|
+
try {
|
|
56
|
+
while (true) {
|
|
57
|
+
const { done, value } = await reader.read();
|
|
58
|
+
if (done) break;
|
|
59
|
+
length += value.byteLength;
|
|
60
|
+
if (length > maxBytes) throw new Error('Catalog response too large');
|
|
61
|
+
chunks.push(value);
|
|
62
|
+
}
|
|
63
|
+
} finally {
|
|
64
|
+
await reader.cancel();
|
|
65
|
+
reader.releaseLock();
|
|
66
|
+
}
|
|
67
|
+
return Buffer.concat(chunks, length);
|
|
68
|
+
}
|
|
69
|
+
throw new Error('Too many catalog redirects');
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
function parseJsonc(text, schema) {
|
|
73
|
+
const errors = [];
|
|
74
|
+
const value = parse(text, errors, { allowTrailingComma: true });
|
|
75
|
+
if (errors.length) throw new Error('Invalid theme JSON');
|
|
76
|
+
return schema.parse(value);
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
function themePath(from, reference) {
|
|
80
|
+
if (/[\\\0:]/.test(reference) || reference.startsWith('/')) throw new Error('Invalid theme reference');
|
|
81
|
+
const resolved = path.posix.normalize(path.posix.join(path.posix.dirname(from), reference));
|
|
82
|
+
if (!resolved.startsWith('extension/')) throw new Error('Theme reference escapes package');
|
|
83
|
+
return resolved;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
export function createThemeCatalog({ fetchImpl = fetch } = {}) {
|
|
87
|
+
const search = async (input, signal = AbortSignal.timeout(15000)) => {
|
|
88
|
+
const { query } = querySchema.parse(input);
|
|
89
|
+
const url = new URL('https://open-vsx.org/api/-/search');
|
|
90
|
+
url.search = new URLSearchParams({ query, category: 'Themes', size: '24', sortBy: 'relevance' }).toString();
|
|
91
|
+
const bytes = await download(url.href, 1024 * 1024, signal, fetchImpl);
|
|
92
|
+
const result = z.object({ extensions: z.array(extensionSchema).max(24) }).parse(JSON.parse(bytes.toString('utf8')));
|
|
93
|
+
return result.extensions.map((extension) => ({
|
|
94
|
+
namespace: extension.namespace, name: extension.name, version: extension.version,
|
|
95
|
+
label: extension.displayName || extension.name,
|
|
96
|
+
icon: extension.files.icon && URL.canParse(extension.files.icon) && hosts.has(new URL(extension.files.icon).hostname)
|
|
97
|
+
? trustedUrl(extension.files.icon).href : null,
|
|
98
|
+
}));
|
|
99
|
+
};
|
|
100
|
+
|
|
101
|
+
const readPackage = async (input, signal = AbortSignal.timeout(45000)) => {
|
|
102
|
+
const requested = packageSchema.parse(input);
|
|
103
|
+
const url = `https://open-vsx.org/api/${requested.namespace}/${requested.name}/${requested.version}`;
|
|
104
|
+
const detail = detailSchema.parse(JSON.parse((await download(url, 512 * 1024, signal, fetchImpl)).toString('utf8')));
|
|
105
|
+
const bytes = await download(detail.files.download, 20 * 1024 * 1024, signal, fetchImpl);
|
|
106
|
+
const checksum = (await download(detail.files.sha256, 256, signal, fetchImpl)).toString('utf8').trim().split(/\s+/)[0];
|
|
107
|
+
if (createHash('sha256').update(bytes).digest('hex') !== checksum?.toLowerCase()) throw new Error('VSIX checksum mismatch');
|
|
108
|
+
const read = openThemeArchive(bytes);
|
|
109
|
+
const manifest = parseJsonc(await read('extension/package.json'), manifestSchema);
|
|
110
|
+
if (manifest.publisher.toLowerCase() !== requested.namespace.toLowerCase() || manifest.name !== requested.name || manifest.version !== requested.version) throw new Error('VSIX identity mismatch');
|
|
111
|
+
let reads = 0;
|
|
112
|
+
const load = async (file, ancestors = []) => {
|
|
113
|
+
signal.throwIfAborted();
|
|
114
|
+
if (ancestors.includes(file) || ancestors.length >= 8 || ++reads > 320) throw new Error('Too many theme references');
|
|
115
|
+
const source = parseJsonc(await read(file), sourceSchema);
|
|
116
|
+
const parent = source.include ? await load(themePath(file, source.include), [...ancestors, file]) : null;
|
|
117
|
+
const reference = z.string().safeParse(source.tokenColors);
|
|
118
|
+
const rules = reference.success
|
|
119
|
+
? parseJsonc(await read(themePath(file, reference.data)), tokenRules) : tokenRules.parse(source.tokenColors ?? []);
|
|
120
|
+
const { include: _include, ...own } = source;
|
|
121
|
+
return {
|
|
122
|
+
...parent, ...own,
|
|
123
|
+
colors: { ...parent?.colors, ...source.colors },
|
|
124
|
+
tokenColors: [...(parent?.tokenColors ?? []), ...(rules ?? [])],
|
|
125
|
+
semanticTokenColors: { ...parent?.semanticTokenColors, ...source.semanticTokenColors },
|
|
126
|
+
};
|
|
127
|
+
};
|
|
128
|
+
const themes = [];
|
|
129
|
+
let totalBytes = 0;
|
|
130
|
+
for (const contribution of manifest.contributes.themes) {
|
|
131
|
+
try {
|
|
132
|
+
const file = themePath('extension/package.json', contribution.path);
|
|
133
|
+
const source = await load(file);
|
|
134
|
+
source.name = contribution.label;
|
|
135
|
+
if (contribution.uiTheme) source.type = contribution.uiTheme === 'vs' ? 'light' : contribution.uiTheme === 'vs-dark' ? 'dark' : contribution.uiTheme;
|
|
136
|
+
const text = JSON.stringify(source);
|
|
137
|
+
totalBytes += Buffer.byteLength(text);
|
|
138
|
+
if (Buffer.byteLength(text) > 512 * 1024 || totalBytes > 10 * 1024 * 1024) throw new Error('Resolved themes too large');
|
|
139
|
+
themes.push({ path: contribution.path, name: contribution.label, text, error: false });
|
|
140
|
+
} catch {
|
|
141
|
+
signal.throwIfAborted();
|
|
142
|
+
themes.push({ path: contribution.path, name: contribution.label, text: '', error: true });
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
return themes;
|
|
146
|
+
};
|
|
147
|
+
return { search, readPackage };
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
export function registerThemeCatalogRoutes(app, catalog = createThemeCatalog()) {
|
|
151
|
+
for (const [route, operation, schema] of [
|
|
152
|
+
['/api/config/themes/catalog/search', catalog.search, querySchema],
|
|
153
|
+
['/api/config/themes/catalog/package', catalog.readPackage, packageSchema],
|
|
154
|
+
]) {
|
|
155
|
+
app.post(route, async (req, res) => {
|
|
156
|
+
const input = schema.safeParse(req.body);
|
|
157
|
+
if (!input.success) return res.status(400).json({ error: 'invalid' });
|
|
158
|
+
const controller = new AbortController();
|
|
159
|
+
const cancel = () => controller.abort();
|
|
160
|
+
res.on('close', cancel);
|
|
161
|
+
try {
|
|
162
|
+
const items = await operation(input.data, AbortSignal.any([controller.signal, AbortSignal.timeout(45000)]));
|
|
163
|
+
res.json({ items });
|
|
164
|
+
} catch {
|
|
165
|
+
if (!res.destroyed) res.status(502).json({ error: 'catalog' });
|
|
166
|
+
} finally {
|
|
167
|
+
res.off('close', cancel);
|
|
168
|
+
}
|
|
169
|
+
});
|
|
170
|
+
}
|
|
171
|
+
}
|