@yuriai/web 0.2.0-beta.1 → 0.2.0-beta.11
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +5 -1
- package/dist/assets/{AgentAvatar-k7s0gPMz.js → AgentAvatar-BeM4lXfE.js} +1 -1
- package/dist/assets/{AssistantView-CKSBN9HQ.js → AssistantView-CuYOySq7.js} +3 -3
- package/dist/assets/DiagramView-Dg3mmHBS.js +1 -0
- package/dist/assets/{FadeInOnReveal-DuelAGXz.js → FadeInOnReveal-B8BCjwPb.js} +1 -1
- package/dist/assets/GuiPluginLoadingNotice-DjO_uy_0.js +1 -0
- package/dist/assets/GuiPluginSurface-yIOzahfo.js +1 -0
- package/dist/assets/GuiPluginWindow-jUuZl9JF.js +1 -0
- package/dist/assets/{Icon-BX4GW-k_.js → Icon-DofI60x2.js} +1 -1
- package/dist/assets/{ImageLoadingPlaceholder-OnlbaJBG.js → ImageLoadingPlaceholder-CZSbfJci.js} +1 -1
- package/dist/assets/{LoadingImage-DDEN3tpH.js → LoadingImage-BA2Cwg_Q.js} +1 -1
- package/dist/assets/MarkdownRenderer-CXQc3p23.js +2 -0
- package/dist/assets/MarkdownRendererImpl-Bik13Wcr.js +10 -0
- package/dist/assets/MarkstreamRendererImpl-DULutx8r.js +3 -0
- package/dist/assets/{MobileDetailNavigation-K8AyOZUE.js → MobileDetailNavigation-C6-wtXZH.js} +1 -1
- package/dist/assets/MobileResizableSheet-CuRgnS-k.js +1 -0
- package/dist/assets/MobileShareBridge-m6bxtE6w.js +4 -0
- package/dist/assets/MobileTabPageHeader-Cm0sKyHi.js +2 -0
- package/dist/assets/{MultiRunWindow-CLGnrnLn.js → MultiRunWindow-uYxVeVne.js} +1 -1
- package/dist/assets/OnboardingScreen-hvLlaoKt.js +1 -0
- package/dist/assets/{OverlayScrollbar-C-Od80p5.js → OverlayScrollbar-Bi17Olmj.js} +1 -1
- package/dist/assets/SettingsView-B2YuF8r0.js +26 -0
- package/dist/assets/{SettingsWindow-B-z25PVS.js → SettingsWindow--qnxFujm.js} +1 -1
- package/dist/assets/TerminalView-6gTVdIYb.js +8 -0
- package/dist/assets/{ToolOutputDialog-CMiPmx7q.js → ToolOutputDialog-C5kcd8b5.js} +3 -3
- package/dist/assets/{YuriLogo-DvKVga_x.js → YuriLogo-D9cfwLdW.js} +1 -1
- package/dist/assets/appThemeRegistry-BnfnOg7_.js +1 -0
- package/dist/assets/{assistant-attachment-cache-BIxi1vPM.js → assistant-attachment-cache-Cqs65voA.js} +1 -1
- package/dist/assets/button-CT7WL0lp.js +1 -0
- package/dist/assets/{capgoAdapter-CEzjhZ15.js → capgoAdapter-BPj5WQuJ.js} +1 -1
- package/dist/assets/clipboard-Bj6jZiuP.js +1 -0
- package/dist/assets/{collapsible-BT03pxhm.js → collapsible-UDWFNcbF.js} +1 -1
- package/dist/assets/desktop-CfMDfs6c.js +1 -0
- package/dist/assets/desktopHosts-BEzVZGiW.js +1 -0
- package/dist/assets/desktopRelayRestore-aNSNYVEB.js +1 -0
- package/dist/assets/device-BDrEmxBm.js +2 -0
- package/dist/assets/{diagram-1AdssMXJ.js → diagram-BxF_wECt.js} +1 -1
- package/dist/assets/dialog-BpsbJk8Y.js +1 -0
- package/dist/assets/download-progress-MobTWf23.js +1 -0
- package/dist/assets/dropdown-menu.styles-D6MTYFvx.js +1 -0
- package/dist/assets/{es-BQC0Cjvs.js → es-iuy57SFI.js} +2 -2
- package/dist/assets/{fileMentionTouchSelection-BCTXha9_.js → fileMentionTouchSelection-mWJrsy1N.js} +2 -2
- package/dist/assets/{path-utils-QNmCUIdP.js → fileQueries-voABZL1r.js} +1 -1
- package/dist/assets/fileReferenceActions-CgsqIeIM.js +1 -0
- package/dist/assets/{fileReferenceParser-D6pFtXag.js → fileReferenceParser-1HHDBUum.js} +1 -1
- package/dist/assets/{fr-BEs3arTt.js → fr-LyrJa2Qb.js} +2 -2
- package/dist/assets/gitApi-_0x9rm4Q.js +10 -0
- package/dist/assets/gitApiHttp-BKM9BbT8.js +7 -0
- package/dist/assets/gui-CTKa6rbU.js +1 -0
- package/dist/assets/host-1RDqqL9w.js +1 -0
- package/dist/assets/{image-loading-ClwkpTt4.js → image-loading-ClQZD7Z9.js} +1 -1
- package/dist/assets/{input-BhopRvzu.js → input-D86Oqf3B.js} +1 -1
- package/dist/assets/insertionBoundaries-DK8Nfduw.js +1 -0
- package/dist/assets/{ja-DwjQqURQ.js → ja-QqNYiTeY.js} +2 -2
- package/dist/assets/{ko-5ebvOeiM.js → ko-CL-s2hwZ.js} +2 -2
- package/dist/assets/main-CtUjac3v.js +169 -0
- package/dist/assets/main-mDmZG5F3.js +2 -0
- package/dist/assets/{markdownHeightCache-Ci4Phpkv.js → markdownHeightCache-DB_NzPGt.js} +1 -1
- package/dist/assets/mcpQueries-CzVXx1pS.js +1 -0
- package/dist/assets/miniChat-B1m57jX8.js +2 -0
- package/dist/assets/mobile-CwqGwE_K.js +2 -0
- package/dist/assets/{mobileBackNavigation-htjL23a2.js → mobileBackNavigation-BGpGSVKE.js} +1 -1
- package/dist/assets/multirun-LSYLvvZF.js +3 -0
- package/dist/assets/native-BMAEg2E6.js +1 -0
- package/dist/assets/native-config-PMhVH43d.js +1 -0
- package/dist/assets/native-errors-06if6eu-.js +1 -0
- package/dist/assets/path-utils-jGozTg9d.js +1 -0
- package/dist/assets/persistence-Ck0wskDR.js +3 -0
- package/dist/assets/{pl-ptv06x7p.js → pl-AKGY_sFU.js} +2 -2
- package/dist/assets/platform-kv0OsX45.js +1 -0
- package/dist/assets/{projectMeta-tXx77gZG.js → projectMeta-Ds630MLq.js} +1 -1
- package/dist/assets/{pt-BR-DREchPJf.js → pt-BR-BFRFGU_b.js} +2 -2
- package/dist/assets/{queryRuntime-BuRnpVtK.js → queryRuntime-CpsVmMzy.js} +1 -1
- package/dist/assets/readiness-79gVgf9B.js +1 -0
- package/dist/assets/reasoning-projection-client-BEhVknv9.js +1 -0
- package/dist/assets/renderElectronMiniChatApp-yEPiD9np.js +2 -0
- package/dist/assets/renderMobileApp-6XHYSl6x.js +28 -0
- package/dist/assets/runtime-fetch-BclMrQHc.js +1 -0
- package/dist/assets/{runtime-file-download-CwMwe_O9.js → runtime-file-download-CZ2qtdn9.js} +1 -1
- package/dist/assets/runtime-file-resource-CEkq2Pj2.js +2 -0
- package/dist/assets/runtime-file-store-BVRgEtI-.js +1 -0
- package/dist/assets/runtime-switch-WzPG6NMR.js +1 -0
- package/dist/assets/runtimeConfig-CNms027t.js +2 -0
- package/dist/assets/runtimeEndpointReset-CiSl3D_G.js +149 -0
- package/dist/assets/{runtimeEndpointReset-DmY_4gYI.css → runtimeEndpointReset-HYSytKO-.css} +1 -1
- package/dist/assets/{scheduledTaskNavigation-B71VHwFK.js → scheduledTaskNavigation-tOa4Azh_.js} +1 -1
- package/dist/assets/scheduling-DCTDfxV-.js +1 -0
- package/dist/assets/sessionChangeSummary-BU-_7fX2.js +1 -0
- package/dist/assets/sessionLookup-B8YOzsKe.js +1 -0
- package/dist/assets/{sortable-tabs-strip-CnaQoAAB.js → sortable-tabs-strip-CSXgXPyP.js} +1 -1
- package/dist/assets/speechSettingsQueries-DXe6PVAa.js +4 -0
- package/dist/assets/src-D3pZqEZM.css +2 -0
- package/dist/assets/{store-Dy_l1m3m.js → store-CGMD02tA.js} +3 -3
- package/dist/assets/terminalApi-DbFIyF-J.js +1 -0
- package/dist/assets/{textarea-CaGuTnhs.js → textarea-CMvxcQhR.js} +1 -1
- package/dist/assets/{tooltip-Bxj4llmx.js → tooltip-CnIKZ6bg.js} +1 -1
- package/dist/assets/types-xdR_RNnd.js +2 -0
- package/dist/assets/{uk-HcldNNPe.js → uk-C21_nQhw.js} +2 -2
- package/dist/assets/{useAppFontEffects-DDdQeaoM.js → useAppFontEffects-BWa0kmau.js} +53 -53
- package/dist/assets/{useAssistantUIStore-D7JZlg_Q.js → useAssistantUIStore-4a569vpy.js} +1 -1
- package/dist/assets/useDesktopWindowControlsLayout-DlxAzo2A.js +1 -0
- package/dist/assets/useEffectiveDirectory-PrUfhsEz.js +1 -0
- package/dist/assets/{useFontPreferences-D-XYUHOV.js → useFontPreferences-Dx-plsme.js} +1 -1
- package/dist/assets/useMobileNavigationStore-_TdcYM33.js +417 -0
- package/dist/assets/useUIStore-DqtgX2FB.js +1 -0
- package/dist/assets/{useWorkerHighlightedLines-OsRfq7LD.js → useWorkerHighlightedLines-CQTgx3GG.js} +1 -1
- package/dist/assets/{vendor-effect-DXlObQuU.js → vendor-effect-DV9F8PTZ.js} +1 -1
- package/dist/assets/vendor-opencode-client-fxfj4IA_.js +12 -0
- package/dist/assets/{vendor-opencode-plugin-DhwD3Tat.js → vendor-opencode-plugin-CQ5ogY33.js} +1 -1
- package/dist/assets/vendor-solid-js-Dmt4_-Zk.js +1 -0
- package/dist/assets/yuri-mark-black-DxEnMyCE.svg +1 -0
- package/dist/assets/{zh-CN-Dg3fYgX1.js → zh-CN-C7PVNr9_.js} +2 -2
- package/dist/assets/{zh-TW-FIWAmsGT.js → zh-TW-DLLoB3-e.js} +2 -2
- package/dist/index.html +27 -23
- package/dist/mini-chat.html +30 -34
- package/dist/mobile.html +33 -23
- package/package.json +3 -3
- package/server/index.d.ts +2 -0
- package/server/index.js +9 -13
- package/server/lib/content-search/DOCUMENTATION.md +33 -13
- package/server/lib/content-search/event-ingest.integration.test.js +52 -0
- package/server/lib/content-search/event-repair.test.js +48 -0
- package/server/lib/content-search/index.js +3 -2
- package/server/lib/content-search/runtime.js +75 -10
- package/server/lib/content-search/runtime.test.js +91 -1
- package/server/lib/content-search/service.js +19 -2
- package/server/lib/fs/DOCUMENTATION.md +1 -0
- package/server/lib/fs/binary-file.d.ts +3 -0
- package/server/lib/fs/binary-file.js +21 -0
- package/server/lib/fs/routes.js +1 -21
- package/server/lib/fs/routes.test.js +43 -0
- package/server/lib/opencode/DOCUMENTATION.md +14 -9
- package/server/lib/opencode/ensure-cli.js +12 -14
- package/server/lib/opencode/ensure-cli.test.js +8 -8
- package/server/lib/opencode/env-runtime.test.js +1 -1
- package/server/lib/opencode/gui-plugin-source.js +14 -0
- package/server/lib/opencode/gui-plugin-source.test.js +28 -0
- package/server/lib/opencode/lifecycle.js +19 -1
- package/server/lib/opencode/opencode2-pin.js +3 -4
- package/server/lib/opencode/opencode2-pin.test.js +5 -4
- package/server/lib/opencode/owned-runtime-upgrade.js +4 -11
- package/server/lib/opencode/owned-runtime-upgrade.test.js +4 -0
- package/server/lib/opencode/plugin-gui-response.d.ts +7 -0
- package/server/lib/opencode/plugin-gui-response.js +62 -0
- package/server/lib/opencode/plugin-gui-response.test.js +89 -0
- package/server/lib/opencode/proxy.js +32 -0
- package/server/lib/opencode/routes.js +2 -1
- package/server/lib/opencode/routes.test.js +1 -1
- package/server/lib/opencode/runtime-contract.js +3 -4
- package/server/lib/opencode/session-directory-runtime.js +2 -13
- package/server/lib/opencode/session-directory-runtime.test.js +69 -4
- package/server/lib/opencode/upgrade-screen.js +9 -5
- package/server/lib/opencode/upgrade-screen.test.js +20 -0
- package/server/lib/opencode/version-alignment.test.js +6 -6
- package/server/lib/question-auto-delegate/DOCUMENTATION.md +5 -1
- package/server/lib/question-auto-delegate/core.d.ts +2 -2
- package/server/lib/question-auto-delegate/runtime.js +11 -27
- package/server/lib/question-auto-delegate/runtime.test.js +25 -0
- package/server/lib/relay/DOCUMENTATION.md +1 -0
- package/server/lib/request-cors.js +2 -2
- package/server/lib/request-cors.test.js +3 -0
- package/server/lib/scheduled-tasks/DOCUMENTATION.md +5 -0
- package/server/lib/scheduled-tasks/runtime.js +16 -0
- package/server/lib/scheduled-tasks/runtime.test.js +33 -0
- package/server/lib/session-index/DOCUMENTATION.md +22 -8
- package/server/lib/session-index/routes.js +3 -1
- package/server/lib/session-index/routes.test.js +2 -0
- package/server/lib/session-index/service.js +23 -0
- package/server/lib/session-index/sync-runtime.js +78 -20
- package/server/lib/session-index/sync-runtime.test.js +23 -5
- package/server/plugin-gui-proxy.test.js +134 -0
- package/dist/assets/DiagramView-RmE0gXVx.js +0 -1
- package/dist/assets/GuiPluginSurface-DWGYdQLr.js +0 -1
- package/dist/assets/GuiPluginWindow-CLgceKTX.js +0 -1
- package/dist/assets/MarkdownRenderer-7zj1J9EY.js +0 -2
- package/dist/assets/MarkdownRendererImpl-lXwdc-kG.js +0 -10
- package/dist/assets/MarkstreamRendererImpl-B5or38qI.js +0 -3
- package/dist/assets/MobileResizableSheet-THVjYOSA.js +0 -1
- package/dist/assets/MobileShareBridge-9RP7ni2F.js +0 -4
- package/dist/assets/MobileTabPageHeader-ZZTO3phT.js +0 -2
- package/dist/assets/OnboardingScreen-BHomvleJ.js +0 -1
- package/dist/assets/SettingsView-BlruenEQ.js +0 -26
- package/dist/assets/TerminalView-CRyh7cpp.js +0 -8
- package/dist/assets/appThemeRegistry-e1zU7R2C.js +0 -1
- package/dist/assets/button-4sNruiRJ.js +0 -1
- package/dist/assets/desktopHosts-DNc_ga0E.js +0 -1
- package/dist/assets/desktopRelayRestore-BWl7Zy8M.js +0 -1
- package/dist/assets/device-CCFr0Aht.js +0 -2
- package/dist/assets/dialog-DLc0nKV7.js +0 -1
- package/dist/assets/dropdown-menu.styles-4tACRbYU.js +0 -1
- package/dist/assets/fileReferenceActions-B0iaTe0c.js +0 -1
- package/dist/assets/gitApi-DIwsfb2k.js +0 -10
- package/dist/assets/gui-CTnzY_cr.js +0 -1
- package/dist/assets/host-CEMl6ZlP.js +0 -1
- package/dist/assets/insertionBoundaries-CFDcBxaK.js +0 -1
- package/dist/assets/main-DBJ19laz.js +0 -169
- package/dist/assets/main-XMhFdW0K.js +0 -2
- package/dist/assets/mcpQueries-f0cDQQKu.js +0 -1
- package/dist/assets/miniChat-BVTtOggs.js +0 -2
- package/dist/assets/mobile-0X6dYZAB.js +0 -2
- package/dist/assets/multirun-mBD1Y3Eb.js +0 -3
- package/dist/assets/native-config-B9V18QgV.js +0 -1
- package/dist/assets/persistence-CcGnI3Ek.js +0 -3
- package/dist/assets/platform-HIkm-CHn.js +0 -7
- package/dist/assets/readiness-Da7jHHss.js +0 -1
- package/dist/assets/renderElectronMiniChatApp-DwIydDUm.js +0 -2
- package/dist/assets/renderMobileApp-TNkNM5Zx.js +0 -28
- package/dist/assets/runtime-fetch-BAN5Gnnp.js +0 -1
- package/dist/assets/runtime-file-resource-yx0xpKe-.js +0 -2
- package/dist/assets/runtime-switch-CAZiOV2G.js +0 -1
- package/dist/assets/runtimeConfig-ChR1FQv1.js +0 -2
- package/dist/assets/runtimeEndpointReset-CxMEqgDx.js +0 -149
- package/dist/assets/sessionChangeSummary-DDbB-N5p.js +0 -1
- package/dist/assets/sessionLookup-CsJ8Vrq8.js +0 -1
- package/dist/assets/speechSettingsQueries-X0jStYkm.js +0 -4
- package/dist/assets/src-CZA3gFyl.css +0 -2
- package/dist/assets/terminalApi-DVZUO2Uv.js +0 -1
- package/dist/assets/types-Dfj_Rn0L.js +0 -2
- package/dist/assets/useDesktopWindowControlsLayout-BFyKfmUX.js +0 -1
- package/dist/assets/useEffectiveDirectory-CST6AXTm.js +0 -1
- package/dist/assets/useMobileNavigationStore-BdWv0Da4.js +0 -417
- package/dist/assets/useUIStore-NMQx_cnG.js +0 -1
- package/dist/assets/vendor-opencode-client-Eb-_7KbZ.js +0 -23
- package/dist/assets/vendor-solid-js-CXSXbuQO.js +0 -1
|
@@ -2,7 +2,7 @@ import fs from 'node:fs';
|
|
|
2
2
|
import os from 'node:os';
|
|
3
3
|
import path from 'node:path';
|
|
4
4
|
import { afterEach, describe, expect, it, vi } from 'vitest';
|
|
5
|
-
|
|
5
|
+
const PINNED_OPENCODE2_VERSION = '2.0.23';
|
|
6
6
|
import { configureOpenCodeTerminalPath } from './terminal-path.js';
|
|
7
7
|
import {
|
|
8
8
|
ensurePinnedOpenCode2Cli,
|
|
@@ -45,11 +45,11 @@ describe('ensurePinnedOpenCode2Cli', () => {
|
|
|
45
45
|
|
|
46
46
|
it.each(['1.18.4', '3.0.0', '2.9.1-beta.1', '2.0.1'])('never chooses an unsuitable fresh-install target %s', async (latest) => {
|
|
47
47
|
const install = vi.fn(async () => '/installed/opencode');
|
|
48
|
-
await ensurePinnedOpenCode2Cli({ dataDir: createTempDir('yuri-invalid-cli-'), install,
|
|
48
|
+
await expect(ensurePinnedOpenCode2Cli({ dataDir: createTempDir('yuri-invalid-cli-'), install,
|
|
49
49
|
resolveLatestVersion: async () => latest,
|
|
50
50
|
readVersion: (file) => file === '/installed/opencode' ? PINNED_OPENCODE2_VERSION : '',
|
|
51
|
-
});
|
|
52
|
-
expect(install).
|
|
51
|
+
})).rejects.toThrow('Invalid stable OpenCode installation target');
|
|
52
|
+
expect(install).not.toHaveBeenCalled();
|
|
53
53
|
});
|
|
54
54
|
|
|
55
55
|
it('reuses the newest verified cache offline instead of reinstalling the pin', async () => {
|
|
@@ -67,14 +67,14 @@ describe('ensurePinnedOpenCode2Cli', () => {
|
|
|
67
67
|
expect(resolveLatestVersion).not.toHaveBeenCalled();
|
|
68
68
|
});
|
|
69
69
|
|
|
70
|
-
it('
|
|
70
|
+
it('reports registry failure without installing an obsolete fallback', async () => {
|
|
71
71
|
const dataDir = createTempDir('yuri-offline-cli-');
|
|
72
72
|
const install = vi.fn(async () => '/installed/opencode');
|
|
73
|
-
await ensurePinnedOpenCode2Cli({ dataDir, install,
|
|
73
|
+
await expect(ensurePinnedOpenCode2Cli({ dataDir, install,
|
|
74
74
|
resolveLatestVersion: async () => { throw new Error('offline'); },
|
|
75
75
|
readVersion: (file) => file === '/installed/opencode' ? PINNED_OPENCODE2_VERSION : '',
|
|
76
|
-
});
|
|
77
|
-
expect(install).
|
|
76
|
+
})).rejects.toThrow('offline');
|
|
77
|
+
expect(install).not.toHaveBeenCalled();
|
|
78
78
|
});
|
|
79
79
|
|
|
80
80
|
it('runs upgrade through the selected launch target and preserves its CLI entry path', async () => {
|
|
@@ -4,7 +4,7 @@ import os from 'node:os';
|
|
|
4
4
|
import path from 'node:path';
|
|
5
5
|
import { afterEach, describe, expect, it } from 'vitest';
|
|
6
6
|
import { createOpenCodeEnvRuntime } from './env-runtime.js';
|
|
7
|
-
|
|
7
|
+
const PINNED_OPENCODE2_VERSION = '2.0.23';
|
|
8
8
|
|
|
9
9
|
const originalOpencodeBinary = process.env.OPENCODE_BINARY;
|
|
10
10
|
const originalComSpec = process.env.ComSpec;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/** A loopback URL alone is not ownership: external services and SSH forwards are excluded. */
|
|
2
|
+
export function trustedGuiPluginClient({ managed, shared, ready, url, client }) {
|
|
3
|
+
let local = false;
|
|
4
|
+
try {
|
|
5
|
+
const parsed = new URL(url);
|
|
6
|
+
local = ['http:', 'https:'].includes(parsed.protocol) && ['127.0.0.1', '[::1]', 'localhost'].includes(parsed.hostname)
|
|
7
|
+
&& !parsed.username && !parsed.password;
|
|
8
|
+
} catch { /* Missing or malformed endpoint is not a trusted source. */ }
|
|
9
|
+
if (!local || (!managed && !shared)) {
|
|
10
|
+
throw Object.assign(new Error('Native GUI source is not locally managed'), { code: 'GUI_PLUGIN_UNTRUSTED_SOURCE' });
|
|
11
|
+
}
|
|
12
|
+
if (!ready) throw Object.assign(new Error('Local GUI service is unavailable'), { code: 'GUI_PLUGIN_UNAVAILABLE' });
|
|
13
|
+
return client();
|
|
14
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { describe, expect, it, vi } from 'vitest';
|
|
2
|
+
import { trustedGuiPluginClient } from './gui-plugin-source.js';
|
|
3
|
+
|
|
4
|
+
describe('desktop native GUI code source', () => {
|
|
5
|
+
it.each([
|
|
6
|
+
{ managed: true, shared: false, url: 'http://127.0.0.1:4096' },
|
|
7
|
+
{ managed: false, shared: true, url: 'http://[::1]:4096' },
|
|
8
|
+
])('accepts authoritative local ownership: %j', (source) => {
|
|
9
|
+
const value = {}; const client = vi.fn(() => value);
|
|
10
|
+
expect(trustedGuiPluginClient({ ...source, ready: true, client })).toBe(value);
|
|
11
|
+
expect(client).toHaveBeenCalledOnce();
|
|
12
|
+
});
|
|
13
|
+
it.each([
|
|
14
|
+
{ managed: false, shared: false, url: 'http://127.0.0.1:4096' },
|
|
15
|
+
{ managed: true, shared: false, url: 'https://remote.example' },
|
|
16
|
+
{ managed: false, shared: true, url: 'https://localhost.remote.example' },
|
|
17
|
+
{ managed: true, shared: false, url: 'file:///plugin.cjs' },
|
|
18
|
+
{ managed: true, shared: false, url: 'http://name:password@localhost:4096' },
|
|
19
|
+
])('rejects external/forwarded or non-local sources before obtaining credentials: %j', (source) => {
|
|
20
|
+
const client = vi.fn();
|
|
21
|
+
expect(() => trustedGuiPluginClient({ ...source, ready: true, client })).toThrow(expect.objectContaining({ code: 'GUI_PLUGIN_UNTRUSTED_SOURCE' }));
|
|
22
|
+
expect(client).not.toHaveBeenCalled();
|
|
23
|
+
});
|
|
24
|
+
it('distinguishes temporarily unavailable local service from an untrusted source', () => {
|
|
25
|
+
expect(() => trustedGuiPluginClient({ managed: true, ready: false, url: 'http://localhost:4096', client: vi.fn() }))
|
|
26
|
+
.toThrow(expect.objectContaining({ code: 'GUI_PLUGIN_UNAVAILABLE' }));
|
|
27
|
+
});
|
|
28
|
+
});
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { spawn, spawnSync } from 'node:child_process';
|
|
2
|
+
import fs from 'node:fs';
|
|
2
3
|
import net from 'node:net';
|
|
3
4
|
import { registerManagedProcess, unregisterManagedProcess, reapOrphanedProcesses } from './managed-process-registry.js';
|
|
4
5
|
import { evaluateOpenCodeHealthBody } from './opencode2-pin.js';
|
|
@@ -592,6 +593,23 @@ export const createOpenCodeLifecycleRuntime = (deps) => {
|
|
|
592
593
|
* @param {object | null | undefined} migrationGate
|
|
593
594
|
* @param {number | null | undefined} expectedGeneration
|
|
594
595
|
*/
|
|
596
|
+
// Health checks run every 15s; spawnSync `--version` blocks the event loop.
|
|
597
|
+
// Re-read only when the binary file is replaced (upgrade changes mtime/size).
|
|
598
|
+
let cliVersionCache = { key: '', version: null };
|
|
599
|
+
const readCliVersionCached = (binaryPath) => {
|
|
600
|
+
let key;
|
|
601
|
+
try {
|
|
602
|
+
const stat = fs.statSync(binaryPath);
|
|
603
|
+
key = `${binaryPath}\0${stat.mtimeMs}\0${stat.size}`;
|
|
604
|
+
} catch {
|
|
605
|
+
return readOpenCode2BinaryVersion(binaryPath) || null;
|
|
606
|
+
}
|
|
607
|
+
if (cliVersionCache.key === key) return cliVersionCache.version;
|
|
608
|
+
const version = readOpenCode2BinaryVersion(binaryPath) || null;
|
|
609
|
+
if (version) cliVersionCache = { key, version };
|
|
610
|
+
return version;
|
|
611
|
+
};
|
|
612
|
+
|
|
595
613
|
const refreshRuntimeContractFromProbe = (
|
|
596
614
|
probe,
|
|
597
615
|
migrationGate = state.v1Migration,
|
|
@@ -608,7 +626,7 @@ export const createOpenCodeLifecycleRuntime = (deps) => {
|
|
|
608
626
|
const binaryPath = typeof process.env.OPENCODE_BINARY === 'string'
|
|
609
627
|
? process.env.OPENCODE_BINARY.trim()
|
|
610
628
|
: '';
|
|
611
|
-
const cliVersion = binaryPath ? (
|
|
629
|
+
const cliVersion = binaryPath ? readCliVersionCached(binaryPath) : null;
|
|
612
630
|
const contract = evaluateRuntimeContract({
|
|
613
631
|
serveVersion: probe?.version ?? null,
|
|
614
632
|
cliVersion,
|
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
//
|
|
2
|
-
export const PINNED_OPENCODE2_VERSION = '2.0.23';
|
|
1
|
+
// Runtime compatibility floor, independent of the latest stable installation target.
|
|
3
2
|
export const MINIMUM_OPENCODE2_VERSION = '2.0.20';
|
|
4
3
|
|
|
5
4
|
// Global npm/bun package that installs the opencode v2 binary (not 1.x opencode-ai).
|
|
@@ -66,7 +65,7 @@ export function resolveOpenCode2UpgradeTarget(target) {
|
|
|
66
65
|
rejectOpenCode1xUpgradeTarget(trimmed);
|
|
67
66
|
return trimmed;
|
|
68
67
|
}
|
|
69
|
-
|
|
68
|
+
throw new Error('Resolve a stable OpenCode 2.x version before upgrading');
|
|
70
69
|
}
|
|
71
70
|
|
|
72
71
|
/**
|
|
@@ -134,7 +133,7 @@ export function compareOpenCode2Versions(left, right) {
|
|
|
134
133
|
return 0;
|
|
135
134
|
}
|
|
136
135
|
|
|
137
|
-
export function isOpenCode2VersionAtLeast(version, minimum =
|
|
136
|
+
export function isOpenCode2VersionAtLeast(version, minimum = MINIMUM_OPENCODE2_VERSION) {
|
|
138
137
|
if (!isAcceptableOpenCode2HealthVersion(version)) return false;
|
|
139
138
|
return compareOpenCode2Versions(version, minimum) >= 0;
|
|
140
139
|
}
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { describe, expect, it } from 'vitest';
|
|
2
2
|
import {
|
|
3
3
|
OPENCODE2_NPM_PACKAGE,
|
|
4
|
-
PINNED_OPENCODE2_VERSION,
|
|
5
4
|
compareOpenCode2Versions,
|
|
6
5
|
evaluateOpenCodeHealthBody,
|
|
7
6
|
isAcceptableOpenCode2HealthVersion,
|
|
@@ -13,6 +12,8 @@ import {
|
|
|
13
12
|
resolveOpenCode2UpgradeTarget,
|
|
14
13
|
} from './opencode2-pin.js';
|
|
15
14
|
|
|
15
|
+
const PINNED_OPENCODE2_VERSION = '2.0.23';
|
|
16
|
+
|
|
16
17
|
describe('opencode2 pin (ticket 12)', () => {
|
|
17
18
|
it('rejects 1.x version strings and accepts the pinned v2', () => {
|
|
18
19
|
expect(isOpenCode1xVersion('1.18.4')).toBe(true);
|
|
@@ -25,11 +26,11 @@ describe('opencode2 pin (ticket 12)', () => {
|
|
|
25
26
|
expect(isOpenCode1xVersion(null)).toBe(false);
|
|
26
27
|
});
|
|
27
28
|
|
|
28
|
-
it('throws on 1.x upgrade targets
|
|
29
|
+
it('throws on 1.x or unresolved upgrade targets', () => {
|
|
29
30
|
expect(() => rejectOpenCode1xUpgradeTarget('1.18.4')).toThrow(/1\.x/);
|
|
30
31
|
expect(() => rejectOpenCode1xUpgradeTarget('1.18.4')).toThrow(expect.objectContaining({ code: 'OPENCODE_UPGRADE_1X_REFUSED' }));
|
|
31
|
-
expect(resolveOpenCode2UpgradeTarget(undefined)).
|
|
32
|
-
expect(resolveOpenCode2UpgradeTarget('')).
|
|
32
|
+
expect(() => resolveOpenCode2UpgradeTarget(undefined)).toThrow('Resolve a stable');
|
|
33
|
+
expect(() => resolveOpenCode2UpgradeTarget('')).toThrow('Resolve a stable');
|
|
33
34
|
expect(resolveOpenCode2UpgradeTarget(PINNED_OPENCODE2_VERSION)).toBe(PINNED_OPENCODE2_VERSION);
|
|
34
35
|
expect(() => resolveOpenCode2UpgradeTarget('1.18.18')).toThrow(/1\.x/);
|
|
35
36
|
});
|
|
@@ -14,7 +14,6 @@
|
|
|
14
14
|
|
|
15
15
|
import path from 'node:path';
|
|
16
16
|
import {
|
|
17
|
-
PINNED_OPENCODE2_VERSION,
|
|
18
17
|
compareOpenCode2Versions,
|
|
19
18
|
isOpenCode1xVersion,
|
|
20
19
|
resolveOpenCode2UpgradeTarget,
|
|
@@ -176,15 +175,9 @@ export function buildUpgradeStatusSnapshot(input) {
|
|
|
176
175
|
const serveVersion = normalizeRuntimeVersion(input.serveVersion);
|
|
177
176
|
const cliVersion = normalizeRuntimeVersion(input.cliVersion);
|
|
178
177
|
const currentVersion = serveVersion || cliVersion;
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
} catch {
|
|
183
|
-
targetVersion = PINNED_OPENCODE2_VERSION;
|
|
184
|
-
}
|
|
185
|
-
if (isOpenCode1xVersion(targetVersion)) {
|
|
186
|
-
targetVersion = PINNED_OPENCODE2_VERSION;
|
|
187
|
-
}
|
|
178
|
+
const targetVersion = input.targetVersion
|
|
179
|
+
? resolveOpenCode2UpgradeTarget(input.targetVersion)
|
|
180
|
+
: null;
|
|
188
181
|
|
|
189
182
|
const contract = input.contract || evaluateRuntimeContract({
|
|
190
183
|
serveVersion,
|
|
@@ -201,7 +194,7 @@ export function buildUpgradeStatusSnapshot(input) {
|
|
|
201
194
|
&& !isOpenCode1xVersion(currentVersion)
|
|
202
195
|
&& compareOpenCode2Versions(targetVersion, currentVersion) > 0,
|
|
203
196
|
);
|
|
204
|
-
const available = canManage &&
|
|
197
|
+
const available = canManage && targetVersion ? newerTarget : null;
|
|
205
198
|
|
|
206
199
|
/** @type {string | null} */
|
|
207
200
|
let reason = ownership.reason;
|
|
@@ -56,6 +56,10 @@ describe('owned runtime upgrade (ticket 12)', () => {
|
|
|
56
56
|
});
|
|
57
57
|
|
|
58
58
|
it('upgrade-status exposes manage rights and manual guidance', () => {
|
|
59
|
+
expect(buildUpgradeStatusSnapshot({
|
|
60
|
+
ownership: classifyRuntimeOwnership({ binarySource: 'installed', binaryPath: ownedBinary, dataDir }),
|
|
61
|
+
serveVersion: '2.2.0',
|
|
62
|
+
})).toMatchObject({ available: null, targetVersion: null });
|
|
59
63
|
const globalStatus = buildUpgradeStatusSnapshot({
|
|
60
64
|
ownership: classifyRuntimeOwnership({ isExternal: false, binarySource: 'path' }),
|
|
61
65
|
serveVersion: '2.0.12',
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export function preparePluginGuiRequest(
|
|
2
|
+
method: string,
|
|
3
|
+
requestPath: string,
|
|
4
|
+
headers: Record<string, string>,
|
|
5
|
+
): { headers: Record<string, string>; revision: string | null } | null;
|
|
6
|
+
|
|
7
|
+
export function projectPluginGuiResponse(response: Response, requestedRevision: string | null): Promise<Response>;
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import { createHash } from 'node:crypto';
|
|
2
|
+
|
|
3
|
+
const REVISION_HEADER = 'x-yuri-gui-revision';
|
|
4
|
+
const CODE_HEADER = 'x-yuri-gui-code';
|
|
5
|
+
const FULL_RESPONSE_HEADERS = new Set([
|
|
6
|
+
REVISION_HEADER, CODE_HEADER, 'if-none-match', 'if-modified-since',
|
|
7
|
+
'if-match', 'if-unmodified-since', 'if-range', 'range',
|
|
8
|
+
]);
|
|
9
|
+
|
|
10
|
+
/** Only the official GUI read opts into Yuri's code-only reuse protocol. */
|
|
11
|
+
export const preparePluginGuiRequest = (method, requestPath, headers) => {
|
|
12
|
+
if (method !== 'GET') return null;
|
|
13
|
+
const url = new URL(requestPath, 'http://yuri.invalid');
|
|
14
|
+
if (url.pathname !== '/api/plugin/gui'
|
|
15
|
+
|| url.searchParams.getAll('id').length !== 1
|
|
16
|
+
|| !url.searchParams.get('id')) return null;
|
|
17
|
+
|
|
18
|
+
let revision = null;
|
|
19
|
+
const forwarded = {};
|
|
20
|
+
for (const [key, value] of Object.entries(headers)) {
|
|
21
|
+
const name = key.toLowerCase();
|
|
22
|
+
if (name === REVISION_HEADER && /^[a-f0-9]{64}$/.test(value)) revision = value;
|
|
23
|
+
if (!FULL_RESPONSE_HEADERS.has(name)) forwarded[key] = value;
|
|
24
|
+
}
|
|
25
|
+
forwarded['accept-encoding'] = 'identity';
|
|
26
|
+
return { headers: forwarded, revision };
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
const isRecord = (value) => value !== null && typeof value === 'object' && !Array.isArray(value);
|
|
30
|
+
|
|
31
|
+
/** No history/cache: only this request's complete, validated upstream 200 can omit code. */
|
|
32
|
+
export const projectPluginGuiResponse = async (response, requestedRevision) => {
|
|
33
|
+
if (response.status !== 200) return response;
|
|
34
|
+
const headers = new Headers(response.headers);
|
|
35
|
+
headers.set('cache-control', 'private, no-store');
|
|
36
|
+
headers.delete(REVISION_HEADER);
|
|
37
|
+
headers.delete(CODE_HEADER);
|
|
38
|
+
headers.delete('etag');
|
|
39
|
+
headers.delete('last-modified');
|
|
40
|
+
headers.delete('content-length');
|
|
41
|
+
headers.delete('content-encoding');
|
|
42
|
+
headers.delete('transfer-encoding');
|
|
43
|
+
|
|
44
|
+
// Fetch has decoded compression. Keep original bytes even for malformed JSON.
|
|
45
|
+
let body = Buffer.from(await response.arrayBuffer());
|
|
46
|
+
if (/^application\/(?:json|[^;]+\+json)(?:\s*;|$)/i.test(headers.get('content-type') || '')) {
|
|
47
|
+
let envelope;
|
|
48
|
+
try { envelope = JSON.parse(body.toString('utf8')); } catch { /* Preserve upstream bytes. */ }
|
|
49
|
+
const bundle = isRecord(envelope) && isRecord(envelope.location) ? envelope.data : null;
|
|
50
|
+
if (isRecord(bundle) && typeof bundle.code === 'string'
|
|
51
|
+
&& typeof bundle.revision === 'string' && bundle.revision.length > 0
|
|
52
|
+
&& isRecord(bundle.options)) {
|
|
53
|
+
const revision = createHash('sha256').update(bundle.revision).digest('hex');
|
|
54
|
+
headers.set(REVISION_HEADER, revision);
|
|
55
|
+
if (requestedRevision === revision) {
|
|
56
|
+
body = Buffer.from(JSON.stringify({ ...envelope, data: { ...bundle, code: '' } }));
|
|
57
|
+
headers.set(CODE_HEADER, 'cached');
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
return new Response(body, { status: response.status, statusText: response.statusText, headers });
|
|
62
|
+
};
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
import { describe, expect, it } from 'vitest';
|
|
2
|
+
import { createHash } from 'node:crypto';
|
|
3
|
+
import { preparePluginGuiRequest, projectPluginGuiResponse } from './plugin-gui-response.js';
|
|
4
|
+
|
|
5
|
+
const revision = 'revision-with-private-path';
|
|
6
|
+
const token = createHash('sha256').update(revision).digest('hex');
|
|
7
|
+
const envelope = { location: { directory: '/workspace' }, data: { code: 'module.exports = {};', revision, options: { key: 'current-value' } } };
|
|
8
|
+
const response = (value, status = 200) => new Response(JSON.stringify(value), {
|
|
9
|
+
status, headers: { 'content-type': 'application/json', 'x-upstream': 'kept', etag: 'upstream-etag' },
|
|
10
|
+
});
|
|
11
|
+
|
|
12
|
+
describe('GUI code-only revision protocol', () => {
|
|
13
|
+
it('is exact GET with one nonempty id and strips only GUI/conditional request controls', () => {
|
|
14
|
+
for (const [method, path] of [
|
|
15
|
+
['POST', '/api/plugin/gui?id=x'], ['HEAD', '/api/plugin/gui?id=x'],
|
|
16
|
+
['GET', '/api/plugin/gui/child?id=x'], ['GET', '/api/plugin/gui/?id=x'],
|
|
17
|
+
['GET', '/api/plugin'], ['GET', '/api/plugin/gui'], ['GET', '/api/plugin/gui?id='],
|
|
18
|
+
['GET', '/api/plugin/gui?id=x&id=y'],
|
|
19
|
+
]) expect(preparePluginGuiRequest(method, path, {})).toBeNull();
|
|
20
|
+
const headers = { 'X-Yuri-Gui-Revision': token, 'If-None-Match': 'old', 'If-Modified-Since': 'yesterday',
|
|
21
|
+
Range: 'bytes=0-20', Authorization: 'upstream-auth', 'x-opencode-directory': '/workspace', accept: 'application/json' };
|
|
22
|
+
expect(preparePluginGuiRequest('GET', '/api/plugin/gui?id=x&location%5Bdirectory%5D=%2Fworkspace', headers)).toEqual({
|
|
23
|
+
revision: token, headers: { Authorization: 'upstream-auth', 'x-opencode-directory': '/workspace', accept: 'application/json', 'accept-encoding': 'identity' },
|
|
24
|
+
});
|
|
25
|
+
expect(headers['If-None-Match']).toBe('old');
|
|
26
|
+
for (const value of ['*', token.toUpperCase(), '"' + token + '"', 'not-a-token']) {
|
|
27
|
+
expect(preparePluginGuiRequest('GET', '/api/plugin/gui?id=x', { 'x-yuri-gui-revision': value }).revision).toBeNull();
|
|
28
|
+
}
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
it('keeps original bytes without opt-in and returns only a hashed revision', async () => {
|
|
32
|
+
const raw = JSON.stringify(envelope, null, 2) + '\n';
|
|
33
|
+
const result = await projectPluginGuiResponse(new Response(raw, { headers: { 'content-type': 'application/json' } }), null);
|
|
34
|
+
expect(await result.text()).toBe(raw);
|
|
35
|
+
expect(result.headers.get('x-yuri-gui-revision')).toBe(token);
|
|
36
|
+
expect(result.headers.get('x-yuri-gui-code')).toBeNull();
|
|
37
|
+
expect(result.headers.get('cache-control')).toBe('private, no-store');
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
it('omits only code on a matching revision, retaining fresh options and all envelope fields', async () => {
|
|
41
|
+
for (const options of [{ key: 'new-value' }, { changed: [1, null] }]) {
|
|
42
|
+
const input = { ...envelope, extra: 1, data: { ...envelope.data, options, extra: true } };
|
|
43
|
+
const result = await projectPluginGuiResponse(response(input), token);
|
|
44
|
+
expect(result.status).toBe(200);
|
|
45
|
+
expect(result.headers.get('x-yuri-gui-code')).toBe('cached');
|
|
46
|
+
expect(result.headers.get('etag')).toBeNull();
|
|
47
|
+
expect(result.headers.get('x-upstream')).toBe('kept');
|
|
48
|
+
expect(await result.json()).toEqual({ ...input, data: { ...input.data, code: '' } });
|
|
49
|
+
}
|
|
50
|
+
const changed = { ...envelope, data: { ...envelope.data, revision: 'new-revision' } };
|
|
51
|
+
const result = await projectPluginGuiResponse(response(changed), token);
|
|
52
|
+
expect(result.headers.get('x-yuri-gui-code')).toBeNull();
|
|
53
|
+
expect(result.headers.get('x-yuri-gui-revision')).not.toBe(token);
|
|
54
|
+
expect(await result.json()).toEqual(changed);
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
it.each([401, 403, 404, 429, 500, 503])('never replaces upstream %i with historical success', async (status) => {
|
|
58
|
+
const upstream = response(envelope, status);
|
|
59
|
+
expect(await projectPluginGuiResponse(upstream, token)).toBe(upstream);
|
|
60
|
+
expect(await upstream.json()).toEqual(envelope);
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
it.each([
|
|
64
|
+
{ ...envelope.data, code: 1 }, { ...envelope.data, revision: '' },
|
|
65
|
+
{ ...envelope.data, revision: null }, { ...envelope.data, options: null },
|
|
66
|
+
{ ...envelope.data, options: [] }, { code: 'x', revision },
|
|
67
|
+
])('does not issue a revision receipt for malformed bundles: %j', async (data) => {
|
|
68
|
+
const input = { ...envelope, data };
|
|
69
|
+
const result = await projectPluginGuiResponse(response(input), token);
|
|
70
|
+
expect(result.headers.get('x-yuri-gui-revision')).toBeNull();
|
|
71
|
+
expect(result.headers.get('x-yuri-gui-code')).toBeNull();
|
|
72
|
+
expect(await result.json()).toEqual(input);
|
|
73
|
+
});
|
|
74
|
+
|
|
75
|
+
it('preserves malformed JSON and non-JSON success bytes without a receipt', async () => {
|
|
76
|
+
for (const [body, contentType] of [['{invalid', 'application/json'], ['<html>not a GUI</html>', 'text/html']]) {
|
|
77
|
+
const result = await projectPluginGuiResponse(new Response(body, { headers: { 'content-type': contentType } }), token);
|
|
78
|
+
expect(await result.text()).toBe(body);
|
|
79
|
+
expect(result.headers.get('x-yuri-gui-code')).toBeNull();
|
|
80
|
+
}
|
|
81
|
+
});
|
|
82
|
+
|
|
83
|
+
it('does not hide a failed body read behind a matching revision', async () => {
|
|
84
|
+
const upstream = new Response(new ReadableStream({
|
|
85
|
+
start(controller) { controller.error(new Error('upstream body failed')); },
|
|
86
|
+
}), { headers: { 'content-type': 'application/json' } });
|
|
87
|
+
await expect(projectPluginGuiResponse(upstream, token)).rejects.toThrow('upstream body failed');
|
|
88
|
+
});
|
|
89
|
+
});
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { createProxyMiddleware } from 'http-proxy-middleware';
|
|
2
2
|
import { isSensitiveCredentialResponse } from './credential-boundary.js';
|
|
3
|
+
import { preparePluginGuiRequest, projectPluginGuiResponse } from './plugin-gui-response.js';
|
|
3
4
|
import { registerSessionDeliveryRoute } from './session-delivery-runtime.js';
|
|
4
5
|
import { stripSessionMessageNativePayload } from '../session-turn-pages/native-payload.js';
|
|
5
6
|
|
|
@@ -1363,5 +1364,36 @@ export const registerOpenCodeProxy = (app, deps) => {
|
|
|
1363
1364
|
});
|
|
1364
1365
|
|
|
1365
1366
|
app.use('/api', applyProxyResponseDeadline);
|
|
1367
|
+
app.use('/api', async (req, res, next) => {
|
|
1368
|
+
if (req.method !== 'GET' || req.path !== '/plugin/gui') return next();
|
|
1369
|
+
const upstreamPath = toUpstreamOpenCodeApiPath(req.url);
|
|
1370
|
+
const gui = preparePluginGuiRequest(req.method, upstreamPath, normalizeForwardedDirectoryHeaders(
|
|
1371
|
+
collectForwardProxyHeaders(req.headers, getOpenCodeAuthHeaders()),
|
|
1372
|
+
));
|
|
1373
|
+
if (!gui) return next();
|
|
1374
|
+
|
|
1375
|
+
const controller = new AbortController();
|
|
1376
|
+
const abort = () => controller.abort();
|
|
1377
|
+
req.once('aborted', abort);
|
|
1378
|
+
res.once('close', abort);
|
|
1379
|
+
try {
|
|
1380
|
+
const upstream = await fetch(buildOpenCodeUrl(upstreamPath, ''), {
|
|
1381
|
+
method: req.method, headers: gui.headers, signal: controller.signal, redirect: 'manual',
|
|
1382
|
+
});
|
|
1383
|
+
const response = await projectPluginGuiResponse(upstream, gui.revision);
|
|
1384
|
+
const body = Buffer.from(await response.arrayBuffer());
|
|
1385
|
+
if (res.writableEnded || res.destroyed) return;
|
|
1386
|
+
res.status(response.status);
|
|
1387
|
+
applyForwardProxyResponseHeaders(response.headers, res);
|
|
1388
|
+
res.end(body);
|
|
1389
|
+
} catch (error) {
|
|
1390
|
+
if (!controller.signal.aborted && !req[PROXY_TIMEOUT_MARKER]) {
|
|
1391
|
+
sendProxyErrorResponse(res, isProxyTimeoutError(error) ? 504 : 503);
|
|
1392
|
+
}
|
|
1393
|
+
} finally {
|
|
1394
|
+
req.off('aborted', abort);
|
|
1395
|
+
res.off('close', abort);
|
|
1396
|
+
}
|
|
1397
|
+
});
|
|
1366
1398
|
app.use('/api', apiProxy);
|
|
1367
1399
|
};
|
|
@@ -285,6 +285,7 @@ export const registerOpenCodeRoutes = (app, dependencies) => {
|
|
|
285
285
|
isSharedService: () => getIsSharedOpenCodeService() === true,
|
|
286
286
|
install: (options) => installPinnedOpenCode2Cli({ ...options, dataDir: resolveDataDir() }),
|
|
287
287
|
upgradeCli: upgradeOpenCodeCli,
|
|
288
|
+
resolveLatestVersion: discoverOpenCodeUpdate,
|
|
288
289
|
readBinaryVersion: readOpenCode2BinaryVersion,
|
|
289
290
|
});
|
|
290
291
|
|
|
@@ -343,7 +344,7 @@ export const registerOpenCodeRoutes = (app, dependencies) => {
|
|
|
343
344
|
if (isOpenCode1xVersion(rawTarget)) {
|
|
344
345
|
return res.status(400).json({
|
|
345
346
|
success: false,
|
|
346
|
-
error: 'OpenCode upgrade refuses 1.x targets. Only
|
|
347
|
+
error: 'OpenCode upgrade refuses 1.x targets. Only OpenCode 2.x is allowed.',
|
|
347
348
|
errorCode: 'OPENCODE_UPGRADE_1X_REFUSED',
|
|
348
349
|
});
|
|
349
350
|
}
|
|
@@ -365,7 +365,7 @@ describe('opencode2 upgrade pin (ticket 12)', () => {
|
|
|
365
365
|
getIsExternalOpenCode: () => true,
|
|
366
366
|
getIsSharedOpenCodeService: () => true,
|
|
367
367
|
getActiveSessionCount: () => 1,
|
|
368
|
-
discoverOpenCodeUpdate: async () =>
|
|
368
|
+
discoverOpenCodeUpdate: async () => '2.0.23',
|
|
369
369
|
upgradeOpenCodeCli,
|
|
370
370
|
forceResolvedOpenCodeBinary: vi.fn(),
|
|
371
371
|
restartOpenCode,
|
|
@@ -13,7 +13,6 @@
|
|
|
13
13
|
*/
|
|
14
14
|
|
|
15
15
|
import {
|
|
16
|
-
PINNED_OPENCODE2_VERSION,
|
|
17
16
|
MINIMUM_OPENCODE2_VERSION,
|
|
18
17
|
compareOpenCode2Versions,
|
|
19
18
|
isAcceptableOpenCode2HealthVersion,
|
|
@@ -239,7 +238,7 @@ export function evaluateRuntimeContract(input = {}) {
|
|
|
239
238
|
versionMismatch,
|
|
240
239
|
minVerifiedVersion: RUNTIME_CONTRACT_MIN_VERIFIED,
|
|
241
240
|
maxVerifiedVersion: null,
|
|
242
|
-
pinnedVersion:
|
|
241
|
+
pinnedVersion: null,
|
|
243
242
|
capabilities,
|
|
244
243
|
reasons,
|
|
245
244
|
};
|
|
@@ -358,7 +357,7 @@ export function shouldBlockRuntimeContractExecution(method, pathWithQuery, contr
|
|
|
358
357
|
export function formatRuntimeContractBlockedError(contract) {
|
|
359
358
|
const serve = contract?.serveVersion ?? null;
|
|
360
359
|
const min = contract?.minVerifiedVersion ?? RUNTIME_CONTRACT_MIN_VERIFIED;
|
|
361
|
-
const pinned =
|
|
360
|
+
const pinned = 'latest stable 2.x';
|
|
362
361
|
const reasons = Array.isArray(contract?.reasons) ? contract.reasons : [];
|
|
363
362
|
|
|
364
363
|
if (reasons.includes('below-min-verified')) {
|
|
@@ -396,7 +395,7 @@ export function runtimeContractExecutionBlockedBody(contract) {
|
|
|
396
395
|
serveVersion: contract?.serveVersion ?? null,
|
|
397
396
|
minVerifiedVersion: contract?.minVerifiedVersion ?? null,
|
|
398
397
|
maxVerifiedVersion: contract?.maxVerifiedVersion ?? null,
|
|
399
|
-
pinnedVersion:
|
|
398
|
+
pinnedVersion: null,
|
|
400
399
|
contract: contract ?? null,
|
|
401
400
|
};
|
|
402
401
|
}
|
|
@@ -79,8 +79,8 @@ export const createSessionDirectoryRuntime = ({
|
|
|
79
79
|
return typeof data.id === 'string' ? { ...event, [field]: projectSession(data) } : event;
|
|
80
80
|
};
|
|
81
81
|
|
|
82
|
-
// v2 directory filters are lexical SQL equality.
|
|
83
|
-
//
|
|
82
|
+
// v2 directory filters are lexical SQL equality. Read session pages without
|
|
83
|
+
// booting a Location, then retain only the same physical directory.
|
|
84
84
|
// This also finds old aliases absent from Yuri's bounded index.
|
|
85
85
|
const fetchSessionList = async (input, init) => {
|
|
86
86
|
const url = new URL(input);
|
|
@@ -90,17 +90,6 @@ export const createSessionDirectoryRuntime = ({
|
|
|
90
90
|
if (!target || url.searchParams.has('project')) {
|
|
91
91
|
return fetchFn(input, init);
|
|
92
92
|
}
|
|
93
|
-
if (!url.searchParams.has('cursor')) {
|
|
94
|
-
const locationUrl = new URL(url);
|
|
95
|
-
locationUrl.pathname = locationUrl.pathname.replace(/\/session\/?$/, '/location');
|
|
96
|
-
locationUrl.search = '';
|
|
97
|
-
locationUrl.searchParams.set('location[directory]', target);
|
|
98
|
-
const response = await fetchFn(locationUrl, init);
|
|
99
|
-
if (!response.ok) return response;
|
|
100
|
-
const location = await response.json();
|
|
101
|
-
if (typeof location?.project?.id !== 'string') throw new Error('Invalid OpenCode location payload');
|
|
102
|
-
url.searchParams.set('project', location.project.id);
|
|
103
|
-
}
|
|
104
93
|
url.searchParams.delete('directory');
|
|
105
94
|
init?.signal?.throwIfAborted();
|
|
106
95
|
const response = await fetchFn(url, init);
|
|
@@ -24,6 +24,71 @@ const session = (id, directory, updated = 1) => ({ id, title: id, location: { di
|
|
|
24
24
|
const json = (value, status = 200) => new Response(JSON.stringify(value), { status, headers: { 'content-type': 'application/json' } });
|
|
25
25
|
|
|
26
26
|
describe('physical session directory identity', () => {
|
|
27
|
+
it('backfills only 30 days once per runtime, resumes failed pages, and never boots locations', async () => {
|
|
28
|
+
const { real } = fixture();
|
|
29
|
+
const dbPath = path.join(real, 'index.sqlite');
|
|
30
|
+
const now = 100 * 24 * 60 * 60 * 1000;
|
|
31
|
+
let fail = true;
|
|
32
|
+
let runtimeKey = 'http://localhost:4000';
|
|
33
|
+
const requests = [];
|
|
34
|
+
const fetchFn = vi.fn(async (input) => {
|
|
35
|
+
const url = new URL(input);
|
|
36
|
+
requests.push(url);
|
|
37
|
+
expect(url.pathname).toBe('/api/session');
|
|
38
|
+
expect(url.searchParams.has('directory')).toBe(false);
|
|
39
|
+
expect(url.searchParams.has('location[directory]')).toBe(false);
|
|
40
|
+
if (!url.searchParams.has('cursor')) return json({ data: [session('recent', real, now)], cursor: { next: 'second' } });
|
|
41
|
+
if (fail) return json({}, 503);
|
|
42
|
+
return json({ data: [session('older', real, now - 31 * 24 * 60 * 60 * 1000)], cursor: { next: 'never-read' } });
|
|
43
|
+
});
|
|
44
|
+
const open = () => {
|
|
45
|
+
const service = createSessionIndexService({ dbPath, getRuntimeConfig: () => ({ apiBaseUrl: runtimeKey }) });
|
|
46
|
+
const sync = createSessionIndexSyncRuntime({ sessionIndexService: service, now: () => now,
|
|
47
|
+
buildOpenCodeUrl: (route) => `http://localhost/api${route}`, getOpenCodeAuthHeaders: () => ({}), fetchFn });
|
|
48
|
+
return { service, sync };
|
|
49
|
+
};
|
|
50
|
+
let { service, sync } = open();
|
|
51
|
+
try {
|
|
52
|
+
sync.enqueue(Array.from({ length: 31 }, (_, i) => `/unused/${i}`), { startup: true });
|
|
53
|
+
sync.enqueue([], { startup: true });
|
|
54
|
+
await vi.waitFor(() => expect(sync.snapshot().sync.active).toBe(false));
|
|
55
|
+
expect(fetchFn).toHaveBeenCalledTimes(2);
|
|
56
|
+
expect(service.getHistoryBackfill()).toMatchObject({ cursor: 'second', complete: false });
|
|
57
|
+
expect(service.findBySessionId('recent')).toBeTruthy();
|
|
58
|
+
sync.stop(); service.close();
|
|
59
|
+
({ service, sync } = open());
|
|
60
|
+
fail = false;
|
|
61
|
+
sync.enqueue([], { startup: true });
|
|
62
|
+
await vi.waitFor(() => expect(sync.snapshot().sync.active).toBe(false));
|
|
63
|
+
expect(fetchFn).toHaveBeenCalledTimes(3);
|
|
64
|
+
expect(requests[2].searchParams.get('cursor')).toBe('second');
|
|
65
|
+
expect(service.getHistoryBackfill().complete).toBe(true);
|
|
66
|
+
expect(service.findBySessionId('older')).toBeNull();
|
|
67
|
+
sync.stop(); service.close();
|
|
68
|
+
({ service, sync } = open());
|
|
69
|
+
sync.enqueue([], { startup: true });
|
|
70
|
+
expect(sync.snapshot().sync.active).toBe(false);
|
|
71
|
+
expect(fetchFn).toHaveBeenCalledTimes(3);
|
|
72
|
+
runtimeKey = 'https://other.example';
|
|
73
|
+
expect(service.getHistoryBackfill()).toBeNull();
|
|
74
|
+
} finally { sync.stop(); service.close(); }
|
|
75
|
+
});
|
|
76
|
+
|
|
77
|
+
it('records an empty backfill as complete and preserves spaces in session directories', async () => {
|
|
78
|
+
const service = createSessionIndexService({ dbPath: ':memory:' });
|
|
79
|
+
const fetchFn = vi.fn(async () => json({ data: [], cursor: {} }));
|
|
80
|
+
const sync = createSessionIndexSyncRuntime({ sessionIndexService: service,
|
|
81
|
+
buildOpenCodeUrl: (route) => `http://localhost/api${route}`, getOpenCodeAuthHeaders: () => ({}), fetchFn });
|
|
82
|
+
try {
|
|
83
|
+
sync.enqueue([], { startup: true });
|
|
84
|
+
await vi.waitFor(() => expect(sync.snapshot().sync.active).toBe(false));
|
|
85
|
+
sync.enqueue([], { startup: true });
|
|
86
|
+
expect(fetchFn).toHaveBeenCalledTimes(1);
|
|
87
|
+
service.upsert(session('spaces', '/home/example/Library/Mobile Documents/project', Date.now()));
|
|
88
|
+
expect(service.findBySessionId('spaces').directory).toBe('/home/example/Library/Mobile Documents/project');
|
|
89
|
+
} finally { sync.stop(); service.close(); }
|
|
90
|
+
});
|
|
91
|
+
|
|
27
92
|
it('checks deletion only on the owning local runtime and preserves uncertain failures', async () => {
|
|
28
93
|
let url = 'http://127.0.0.1:4000';
|
|
29
94
|
const stat = vi.fn(async () => { throw Object.assign(new Error('missing'), { code: 'ENOENT' }); });
|
|
@@ -67,6 +132,7 @@ describe('physical session directory identity', () => {
|
|
|
67
132
|
fetchFn,
|
|
68
133
|
});
|
|
69
134
|
try {
|
|
135
|
+
runtime.enqueue([missing]);
|
|
70
136
|
await vi.waitFor(() => expect(service.snapshot().directories.map(x => x.directory)).not.toContain(missing));
|
|
71
137
|
expect(service.snapshot().directories.map(x => x.directory)).toEqual(expect.arrayContaining([real, history, partial, child]));
|
|
72
138
|
runtime.enqueue([missing, history, partial, child]);
|
|
@@ -95,10 +161,10 @@ describe('physical session directory identity', () => {
|
|
|
95
161
|
requests.push(url);
|
|
96
162
|
expect(init.signal).toBe(controller.signal);
|
|
97
163
|
expect(init.headers).toEqual({ Authorization: 'test-only' });
|
|
98
|
-
|
|
164
|
+
expect(url.pathname).toBe('/api/session');
|
|
99
165
|
expect(url.searchParams.has('directory')).toBe(false);
|
|
100
166
|
if (!url.searchParams.has('cursor')) {
|
|
101
|
-
expect(url.searchParams.
|
|
167
|
+
expect(url.searchParams.has('project')).toBe(false);
|
|
102
168
|
return json({ data: [session('other', other, 30)], cursor: { next: 'page-2' } });
|
|
103
169
|
}
|
|
104
170
|
return json({ data: [session('old-alias', alias, 20), session('real', real, 10)], cursor: { next: 'page-3' } });
|
|
@@ -117,8 +183,7 @@ describe('physical session directory identity', () => {
|
|
|
117
183
|
expect(payload.data.map((row) => row.id)).toEqual(['old-alias', 'real']);
|
|
118
184
|
expect(payload.data.every((row) => row.directory === real && row.location.directory === real)).toBe(true);
|
|
119
185
|
expect(payload.cursor.next).toBe('page-3');
|
|
120
|
-
expect(requests).toHaveLength(
|
|
121
|
-
expect(requests[0].searchParams.get('location[directory]')).toBe(real);
|
|
186
|
+
expect(requests).toHaveLength(2);
|
|
122
187
|
});
|
|
123
188
|
|
|
124
189
|
it('uses the same physical directory for cold sync and later native live events', async () => {
|